Example #1
0
signed ReadMME (struct plc * plc, uint8_t MMV, uint16_t MMTYPE) 

{
	struct channel * channel = (struct channel *)(plc->channel);
	struct message * message = (struct message *)(plc->message);
	struct timeval ts;
	struct timeval tc;
	if (gettimeofday (&ts, NULL) == -1) 
	{
		error (1, errno, CANT_START_TIMER);
	}
	while ((plc->packetsize = readpacket (channel, message, sizeof (* message))) >= 0) 
	{
		if (UnwantedMessage (message, plc->packetsize, MMV, MMTYPE)) 
		{
			if (gettimeofday (&tc, NULL) == -1) 
			{
				error (1, errno, CANT_RESET_TIMER);
			}
			if (channel->timeout < 0) 
			{
				continue;
			}
			if (channel->timeout > MILLISECONDS (ts, tc))
			{
				continue;
			}
			plc->packetsize = 0;
		}
		break;
	}
	return (plc->packetsize);
}
Example #2
0
signed Platform (struct channel * channel, const uint8_t device []) 

{
	struct message message;
	ssize_t packetsize;

#ifndef __GNUC__
#pragma pack (push,1)
#endif

	struct __packed vs_sw_ver_request 
	{
		struct ethernet_std ethernet;
		struct qualcomm_std qualcomm;
	}
	* request = (struct vs_sw_ver_request *) (&message);
	struct __packed vs_sw_ver_confirm 
	{
		struct ethernet_std ethernet;
		struct qualcomm_std qualcomm;
		uint8_t MSTATUS;
		uint8_t MDEVICEID;
		uint8_t MVERLENGTH;
		char MVERSION [PLC_VERSION_STRING];
	}
	* confirm = (struct vs_sw_ver_confirm *) (&message);

#ifndef __GNUC__
#pragma pack (pop)
#endif

	memset (&message, 0, sizeof (message));
	EthernetHeader (&request->ethernet, device, channel->host, channel->type);
	QualcommHeader (&request->qualcomm, 0, (VS_SW_VER | MMTYPE_REQ));
	if (sendpacket (channel, &message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) > 0) 
	{
		while ((packetsize = readpacket (channel, &message, sizeof (message))) > 0) 
		{
			if (!UnwantedMessage (&message, packetsize, 0, (VS_SW_VER | MMTYPE_CNF))) 
			{
				chipset (confirm);
				printf (" %s", chipsetname (confirm->MDEVICEID));
				printf (" %s", confirm->MVERSION);
				return (0);
			}
		}
	}
	return (-1);
}
Example #3
0
signed ListLocalDevices (struct plc * plc, char const * space, char const * comma)

{
	struct channel * channel = (struct channel *)(plc->channel);
	struct message * message = (struct message *)(plc->message);
	ssize_t packetsize;

#ifndef __GNUC__
#pragma pack (push,1)
#endif

	struct __packed vs_sw_ver_request
	{
		struct ethernet_hdr ethernet;
		struct qualcomm_hdr qualcomm;
	}
	* request = (struct vs_sw_ver_request *) (message);

#ifndef __GNUC__
#pragma pack (pop)
#endif

	memset (message, 0, sizeof (* message));
	EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
	QualcommHeader (&request->qualcomm, 0, (VS_SW_VER | MMTYPE_REQ));
	if (sendpacket (channel, message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) <= 0)
	{
		return (-1);
	}
	while ((packetsize = readpacket (channel, message, sizeof (* message))) > 0)
	{
		if (UnwantedMessage (message, packetsize, 0, (VS_SW_VER | MMTYPE_CNF)))
		{
			continue;
		}
		hexout (request->ethernet.OSA, sizeof (request->ethernet.OSA), HEX_EXTENDER, 0, stdout);
		if ((space) && (*space))
		{
			printf ("%s", space);
		}
	}
	if ((comma) && (* comma))
	{
		printf ("%s", comma);
	}
	return (0);
}
Example #4
0
signed ReadMME (struct plc * plc, uint8_t MMV, uint16_t MMTYPE) 

{
	struct channel * channel = (struct channel *)(plc->channel);
	struct message * message = (struct message *)(plc->message);
	while ((plc->packetsize = readpacket (channel, message, sizeof (* message))) > 0) 
	{
		if (FirmwareMessage (message)) 
		{
			continue;
		}
		if (UnwantedMessage (message, plc->packetsize, MMV, MMTYPE)) 
		{
			continue;
		}
		break;
	}
	return (plc->packetsize);
}
unsigned LocalDevices (struct channel const * channel, struct message * message, void * memory, size_t extent)

{
	extern const byte localcast [ETHER_ADDR_LEN];
	struct vs_sw_ver_request
	{
		struct ethernet_hdr ethernet;
		struct qualcomm_hdr qualcomm;
	}
	* request = (struct vs_sw_ver_request *)(message);
	uint8_t * origin = (uint8_t *)(memory);
	uint8_t * offset = (uint8_t *)(memory);
	ssize_t packetsize;
	memset (memory, 0, extent);
	memset (message, 0, sizeof (* message));
	EthernetHeader (&request->ethernet, localcast, channel->host, channel->type);
	QualcommHeader (&request->qualcomm, 0, (VS_SW_VER | MMTYPE_REQ));
	if (sendpacket (channel, message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) <= 0)
	{
		return (0);
	}
	while ((packetsize = readpacket (channel, message, sizeof (* message))) > 0)
	{
		if (UnwantedMessage (message, packetsize, 0, (VS_SW_VER | MMTYPE_CNF)))
		{
			continue;
		}
		if (extent >= sizeof (message->ethernet.OSA))
		{
			memcpy (offset, message->ethernet.OSA, sizeof (message->ethernet.OSA));
			offset += sizeof (message->ethernet.OSA);
			extent -= sizeof (message->ethernet.OSA);
		}
	}
	return ((unsigned)(offset - origin) / ETHER_ADDR_LEN);
}
Example #6
0
static signed mdio (struct channel * channel, uint8_t mode, uint8_t phy, uint8_t reg, uint16_t * data)

{
	struct message message;
	signed packetsize;

#ifndef __GNUC__
#pragma pack (push,1)
#endif

	struct __packed vs_mdio_command_request
	{
		struct ethernet_hdr ethernet;
		struct qualcomm_hdr qualcomm;
		uint8_t OPERATION;
		uint8_t PHY;
		uint8_t REG;
		uint16_t DATA;
	}
	* request = (struct vs_mdio_command_request *)(&message);
	struct __packed vs_mdio_command_confirm
	{
		struct ethernet_hdr ethernet;
		struct qualcomm_hdr qualcomm;
		uint8_t MSTATUS;
		uint16_t DATA;
		uint8_t PHY;
		uint8_t REG;
	}
	* confirm = (struct vs_mdio_command_confirm *)(&message);

#ifndef __GNUC__
#pragma pack (pop)
#endif

	memset (&message, 0, sizeof (message));
	EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
	QualcommHeader (&request->qualcomm, 0, (VS_MDIO_COMMAND | MMTYPE_REQ));
	request->OPERATION = mode;
	request->PHY = phy;
	request->REG = reg;
	request->DATA = HTOLE16 (*data);

#if 1

	printf (" phy 0x%02X", phy);
	printf (" reg 0x%02X", reg);
	printf (" data 0x%04X", * data);
	printf ("\n");

#endif

	if (sendpacket (channel, &message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) == -1)
	{
		error (1, errno, CHANNEL_CANTSEND);
	}
	while ((packetsize = readpacket (channel, &message, sizeof (message))) > 0)
	{
		if (UnwantedMessage (&message, packetsize, 0, (VS_MDIO_COMMAND | MMTYPE_CNF)))
		{
			continue;
		}
		if (confirm->MSTATUS)
		{
			error (0, 0, "%s (%0X): %s", MMECode (confirm->qualcomm.MMTYPE, confirm->MSTATUS), confirm->MSTATUS, PLC_WONTDOIT);
			continue;
		}
		*data = confirm->DATA;
		return (0);
	}
	return (-1);
}
Example #7
0
signed PHYSettings (struct channel * channel, struct phy_settings * settings, flag_t flags)

{
	struct message message;
	signed packetsize;

#ifndef __GNUC__
#pragma pack (push,1)
#endif

	struct __packed vs_enet_settings_request
	{
		struct ethernet_hdr ethernet;
		struct qualcomm_hdr qualcomm;
		uint8_t MCONTROL;
		uint8_t AUTONEGOTIATE;
		uint8_t ADVCAPS;
		uint8_t ESPEED;
		uint8_t EDUPLEX;
		uint8_t EFLOWCONTROL;
	}
	* request = (struct vs_enet_settings_request *) (&message);
	struct __packed vs_enet_settings_confirm
	{
		struct ethernet_hdr ethernet;
		struct qualcomm_hdr qualcomm;
		uint8_t MSTATUS;
		uint8_t ESPEED;
		uint8_t EDUPLEX;
		uint8_t ELINKSTATUS;
		uint8_t EFLOWCONTROL;
	}
	* confirm = (struct vs_enet_settings_confirm *) (&message);

#ifndef __GNUC__
#pragma pack (pop)
#endif

	char address [ETHER_ADDR_LEN * 3];
	memset (&message, 0, sizeof (message));
	EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
	QualcommHeader (&request->qualcomm, 0, (VS_ENET_SETTINGS | MMTYPE_REQ));
	request->MCONTROL = settings->MCONTROL;
	request->AUTONEGOTIATE = settings->AUTONEGOTIATE;
	request->ADVCAPS = settings->ADVCAPS;
	request->ESPEED = settings->ESPEED;
	request->EDUPLEX = settings->EDUPLEX;
	request->EFLOWCONTROL = settings->EFLOWCONTROL;
	if (sendpacket (channel, &message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) < 0)
	{
		error (1, errno, CHANNEL_CANTSEND);
	}
	while ((packetsize = readpacket (channel, &message, sizeof (message))) > 0)
	{
		if (UnwantedMessage (&message, packetsize, 0, (VS_ENET_SETTINGS | MMTYPE_CNF)))
		{
			continue;
		}
		if ((confirm->MSTATUS == 1) || (confirm->MSTATUS == 3))
		{
			error (0, 0, "%s: %s (0x%0X): ", PLC_WONTDOIT, MMECode (confirm->qualcomm.MMTYPE, confirm->MSTATUS), confirm->MSTATUS);
			continue;
		}
		if (_anyset (flags, PLC_ANALYSE))
		{
			printf ("Bits Mode Link Flow\n");
			printf ("%4d ", confirm->ESPEED);
			printf ("%4d ", confirm->EDUPLEX);
			printf ("%4d ", confirm->ELINKSTATUS);
			printf ("%4d\n", confirm->EFLOWCONTROL);
		}
		else
		{
			printf ("%s %s ", channel->ifname, hexstring (address, sizeof (address), channel->host, sizeof (channel->host)));
			printf ("Speed=%s ", rates [confirm->ESPEED]);
			printf ("Duplex=%s ", modes [confirm->EDUPLEX]);
			printf ("LinkStatus=%s ", links [confirm->ELINKSTATUS]);
			printf ("FlowControl=%s\n", flows [confirm->EFLOWCONTROL]);
		}
	}
	if (packetsize < 0)
	{
		error (1, errno, CHANNEL_CANTREAD);
	}
	return (0);
}
signed PLCReadParameterBlock (struct channel * channel, struct message * message, void * memory, size_t extent) 

{
	uint8_t * buffer = (uint8_t *)(memory);

#ifndef __GNUC__
#pragma pack (push,1)
#endif

	struct __packed vs_rd_mod_request 
	{
		struct ethernet_std ethernet;
		struct qualcomm_std qualcomm;
		uint8_t MODULEID;
		uint8_t MACCESS;
		uint16_t MLENGTH;
		uint32_t MOFFSET;
		uint8_t MSECRET [16];
	}
	* request = (struct vs_rd_mod_request *) (message);
	struct __packed vs_rd_mod_confirm 
	{
		struct ethernet_std ethernet;
		struct qualcomm_std qualcomm;
		uint8_t MSTATUS;
		uint8_t RESERVED1 [3];
		uint8_t MODULEID;
		uint8_t RESERVED;
		uint16_t MLENGTH;
		uint32_t MOFFSET;
		uint32_t CHKSUM;
		uint8_t BUFFER [PLC_RECORD_SIZE];
	}
	* confirm = (struct vs_rd_mod_confirm *) (message);

#ifndef __GNUC__
#pragma pack (pop)
#endif

	uint16_t length = 0;
	uint32_t offset = 0;
	signed actual = PLC_RECORD_SIZE;
	do 
	{
		memset (message, 0, sizeof (* message));
		EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
		QualcommHeader (&request->qualcomm, 0, (VS_RD_MOD | MMTYPE_REQ));
		request->MODULEID = VS_MODULE_PIB;
		request->MLENGTH = HTOLE16 (actual);
		request->MOFFSET = HTOLE32 (offset);
		if (sendpacket (channel, message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) <= 0) 
		{
			error (1, errno, CHANNEL_CANTSEND);
		}
		if (readpacket (channel, message, sizeof (* message)) <= 0) 
		{
			error (1, errno, CHANNEL_CANTREAD);
		}
		if (UnwantedMessage (message, sizeof (* confirm), 0, (VS_RD_MOD | MMTYPE_CNF))) 
		{
			actual = PLC_RECORD_SIZE;
			offset = 0;
			continue;
		}
		if (confirm->MSTATUS) 
		{
			error (1, ECANCELED, PLC_WONTDOIT);
		}
		if (LE16TOH (confirm->MLENGTH) != actual) 
		{
			error (1, ECANCELED, PLC_ERR_LENGTH);
		}
		if (LE32TOH (confirm->MOFFSET) != offset) 
		{
			error (1, ECANCELED, PLC_ERR_OFFSET);
		}
		actual = LE16TOH (confirm->MLENGTH);
		offset = LE32TOH (confirm->MOFFSET);
		if (checksum32 (confirm->BUFFER, actual, confirm->CHKSUM)) 
		{
			error (1, ECANCELED, "Bad Packet Checksum");
		}
		if (offset == length) 
		{
			struct pib_header * pib_header = (struct pib_header *) (confirm->BUFFER);
			length = LE16TOH (pib_header->PIBLENGTH);
		}
		if ((offset + actual) > length) 
		{
			actual = length - offset;
		}
		memcpy (buffer + offset, confirm->BUFFER, actual);
		offset += actual;
		extent -= actual;
	}
	while (offset < length);
	return (offset);
}
Example #9
0
static void ReadKey1 (struct channel * channel, unsigned c, int key)

{
	struct message message;
	static signed count = 0;
	signed packetsize;

#ifndef __GNUC__
#pragma pack (push,1)
#endif

	struct __packed vs_rd_mod_request
	{
		struct ethernet_hdr ethernet;
		struct qualcomm_hdr qualcomm;
		uint8_t MODULEID;
		uint8_t RESERVED;
		uint16_t MLENGTH;
		uint32_t MOFFSET;
		uint8_t DAK [16];
	}
	* request = (struct vs_rd_mod_request *)(&message);
	struct __packed vs_rd_mod_confirm
	{
		struct ethernet_hdr ethernet;
		struct qualcomm_hdr qualcomm;
		uint8_t MSTATUS;
		uint8_t RESERVED1 [3];
		uint8_t MODULEID;
		uint8_t RESERVED2;
		uint16_t MLENGTH;
		uint32_t MOFFSET;
		uint32_t MCHKSUM;
		struct simple_pib pib;
	}
	* confirm = (struct vs_rd_mod_confirm *)(&message);

#ifndef __GNUC__
#pragma pack (pop)
#endif

	memset (&message, 0, sizeof (message));
	EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
	QualcommHeader (&request->qualcomm, 0, (VS_RD_MOD | MMTYPE_REQ));
	request->MODULEID = VS_MODULE_PIB;
	request->MLENGTH = HTOLE16 (PLC_RECORD_SIZE);
	request->MOFFSET = HTOLE32 (0);
	if (sendpacket (channel, &message, (ETHER_MIN_LEN - ETHER_CRC_LEN)) < 0)
	{
		error (1, errno, CHANNEL_CANTSEND);
	}
	while ((packetsize = readpacket (channel, &message, sizeof (message))) > 0)
	{
		if (UnwantedMessage (&message, packetsize, 0, (VS_RD_MOD | MMTYPE_CNF)))
		{
			continue;
		}
		if (confirm->MSTATUS)
		{
			error (0, 0, "%s (%0X): ", MMECode (confirm->qualcomm.MMTYPE, confirm->MSTATUS), confirm->MSTATUS);
			continue;
		}
		if (count++ > 0)
		{
			putc (c, stdout);
		}
		if (key == INT6KID_MAC)
		{
			hexout (confirm->pib.MAC, sizeof (confirm->pib.MAC), HEX_EXTENDER, 0, stdout);
			continue;
		}
		if (key == INT6KID_DAK)
		{
			hexout (confirm->pib.DAK, sizeof (confirm->pib.DAK), HEX_EXTENDER, 0, stdout);
			continue;
		}
		if (key == INT6KID_NMK)
		{
			hexout (confirm->pib.NMK, sizeof (confirm->pib.NMK), HEX_EXTENDER, 0, stdout);
			continue;
		}
		if (key == INT6KID_MFG)
		{
			confirm->pib.MFG [PIB_HFID_LEN - 1] = (char)(0);
			printf ("%s", confirm->pib.MFG);
			continue;
		}
		if (key == INT6KID_USR)
		{
			confirm->pib.USR [PIB_HFID_LEN - 1] = (char)(0);
			printf ("%s", confirm->pib.USR);
			continue;
		}
		if (key == INT6KID_NET)
		{
			confirm->pib.NET [PIB_HFID_LEN - 1] = (char)(0);
			printf ("%s", confirm->pib.NET);
			continue;
		}
	}
	if (packetsize < 0)
	{
		error (1, errno, CHANNEL_CANTREAD);
	}
	return;
}