예제 #1
0
signed RemoteHosts (struct plc * plc)

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

#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);
	struct __packed vs_sw_ver_confirm
	{
		struct ethernet_hdr ethernet;
		struct qualcomm_hdr qualcomm;
		uint8_t MSTATUS;
		uint32_t NUMDEVICES;
		struct __packed
		{
			uint8_t MACADDRESS [ETHER_ADDR_LEN];
			uint8_t ENUMID;
		}
		DEVICE [1];
	}
	* confirm = (struct vs_sw_ver_confirm *) (message);

#ifndef __GNUC__
#pragma pack (pop)
#endif

	Request (plc, "Request Enumeration ID Table");
	memset (message, 0, sizeof (* message));
	EthernetHeader (&request->ethernet, channel->peer, channel->host, channel->type);
	QualcommHeader (&request->qualcomm, 0, (VS_EM_ID_TABLE | MMTYPE_REQ));
	plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
	if (SendMME (plc) <= 0)
	{
		error (PLC_EXIT (plc), errno, CHANNEL_CANTSEND);
		return (-1);
	}
	while (ReadMME (plc, 0, (VS_EM_ID_TABLE | MMTYPE_CNF)) > 0)
	{
		unsigned count = LE32TOH (confirm->NUMDEVICES);
		if (confirm->MSTATUS)
		{
			Failure (plc, PLC_WONTDOIT);
			continue;
		}
		while (count--)
		{
			hexout (confirm->DEVICE [count].MACADDRESS, ETHER_ADDR_LEN, ':', count? ' ': '\n', stdout);
		}
	}
	return (0);
}
예제 #2
0
			inline std::ostream& operator<<(std::ostream& o, const HexCharStruct<Char>& hs)
			{
				std::ostream hexout(o.rdbuf());

				hexout << std::setw(2*sizeof(Char)) << std::setfill('0') << std::hex << static_cast<long>(hs.c);

				return o;
			}
예제 #3
0
std::string undilate_text()
{
  typedef magnet::math::dilatedinteger::c<i,d> c;
  typedef magnet::math::dilatedinteger::z<i,d> z;

  std::ostringstream os;
  os << "\nUndilate<" << d <<"> round " << i << " ( val * " << hexout(c::result) << ") & " << hexout(z::result);
  return os.str();
}
예제 #4
0
std::string dilate_text_2()
{
  static size_t shiftval = magnet::math::dilatedinteger::dilate<2>::shiftval<i>::result;

  std::ostringstream os;
  os << "Dilate<2> round " << i << " ( val | (val <<  " << shiftval << ")) & " 
     << hexout(magnet::math::dilatedinteger::y<i,2>::result)
     << "\n";
  return os.str();
}
예제 #5
0
std::string dilate_text()
{
  typedef magnet::math::dilatedinteger::b<i,d> b;
  typedef magnet::math::dilatedinteger::y<i,d> y;
 
  std::ostringstream os;
  os << "Dilate<" << d << "> round " << i << " ( val * " << hexout(b::result) << ") & " << hexout(y::result)
     << "\n";
  return os.str();
}
예제 #6
0
static void getmemory(byte const * memory, size_t extent, char const * object, size_t length)

{
	if (length > extent)
	{
		error (1, ECANCELED, "%s exceeds " SIZE_T_SPEC " bytes", object, length);
	}
	hexout (memory, length, ':', 0, stdout);
	return;
}
예제 #7
0
			inline std::ostream& operator<<(std::ostream& o, const HexBufferStruct<Char>& hs)
			{
				std::ostream hexout(o.rdbuf());

				hexout << std::setw(2*sizeof(Char)) << std::setfill('0') << std::hex;
			  
				for(unsigned i=0; i<hs.length;++i)
					hexout << static_cast<long>(hs.buffer[i]);

				return o;
			}
예제 #8
0
파일: hw1.c 프로젝트: jwc012/CSE12
int main (int argc, char *const* argv) {
  writeline ("Hello World", stdout);
  fprintf (stderr, "Zdravei Sviat\n");
  newline(stdout);
  decout (123, stdout);
  newline(stdout); 
  decout (0, stdout);
  newline(stdout);
  hexout (0xFEEDDAD, stdout);
  newline(stdout);
  return 0;
}
void print_CAN_Msg( canmsg_t *pmsg )
{
  int i;

  crlf();

  // flags for packet   
  hexout( ( ( pmsg->flags >> 24 ) & 0xff ) );
  hexout( ( ( pmsg->flags >> 16 ) & 0xff ) );
  hexout( ( ( pmsg->flags >> 8  ) & 0xff ) );
  hexout( ( pmsg->flags & 0xff ) );
  uart0BlockingPutch( 0x20 );

  // id for frame
  hexout( ( ( pmsg->id >> 24 ) & 0xff ) );
  hexout( ( ( pmsg->id >> 16 ) & 0xff ) );
  hexout( ( ( pmsg->id >> 8  ) & 0xff ) );
  hexout( ( pmsg->id & 0xff ) );
  uart0BlockingPutch( 0x20 );

  // timestamp for frame
  hexout( ( ( pmsg->timestamp >> 24 ) & 0xff ) );  
  hexout( ( ( pmsg->timestamp >> 16 ) & 0xff ) );
  hexout( ( ( pmsg->timestamp >> 8  ) & 0xff ) );
  hexout( (   pmsg->timestamp & 0xff ) );
  uart0BlockingPutch( 0x20 );

  // length for data part of frame
  hexout( pmsg->length );
  uart0BlockingPutch( 0x20 );

  // CAN frame data
  for ( i = 0; i<pmsg->length; i++ ) {
    hexout( pmsg->data[ i ] );
  }
}
예제 #10
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);
}
예제 #11
0
static void showlist (struct item list [], unsigned items)

{
	while (items--)
	{
		uint16_t fields = list->NUM_VLANIDS;
		uint16_t * field = list->VLANID;
		hexout (list->MAC_ADDR, sizeof (list->MAC_ADDR), 0, 0, stdout);
		while (fields--)
		{
			printf (", %d", *field);
			field++;
		}
		printf ("\n");
		list++;
	}
	return;
}
예제 #12
0
size_t memdecode(const void * memory, size_t extent, char const * object, char const * string)

{
	size_t length;
	if (! strcmp(object, "byte"))
	{
		uint8_t number;
		if (sizeof(number) > extent)
		{
			error (1, ECANCELED, "%s exceeds " SIZE_T_SPEC " bytes", object, length);
		}
		memcpy (& number, memory, sizeof(byte));
		printf ("%u", number);
		return (sizeof(number));
	}
	else if(! strcmp(object, "word"))
	{
		uint16_t number;
		if (sizeof(number) > extent)
		{
			error (1, ECANCELED, "%s exceeds " SIZE_T_SPEC " bytes", object, length);
		}
		memcpy (& number, memory, sizeof(number));
		printf ("%u", LE16TOH(number));
		return (sizeof(number));
	}
	else if(! strcmp(object, "long"))
	{
		uint32_t number;
		if (sizeof(number) > extent)
		{
			error (1, ECANCELED, "%s exceeds " SIZE_T_SPEC " bytes", object, length);
		}
		memcpy (& number, memory, sizeof(number));
		printf ("%u", LE32TOH(number));
		return (sizeof(number));
	}
	else if(! strcmp(object, "xbyte"))
	{
		uint8_t number;
		if (sizeof(number) > extent)
		{
			error (1, ECANCELED, "%s exceeds " SIZE_T_SPEC " bytes", object, length);
		}
		memcpy (& number, memory, sizeof(number));
		printf ("0x%02X", number);
		return (sizeof(number));
	}
	else if(! strcmp(object, "xword"))
	{
		uint16_t number;
		if (sizeof(number) > extent)
		{
			error (1, ECANCELED, "%s exceeds " SIZE_T_SPEC " bytes", object, length);
		}
		memcpy (& number, memory, sizeof(number));
		printf ("0x%04X", LE16TOH(number));
		return (sizeof(number));
	}
	else if(! strcmp(object, "xlong"))
	{
		uint32_t number;
		if (sizeof(number) > extent)
		{
			error (1, ECANCELED, "%s exceeds " SIZE_T_SPEC " bytes", object, length);
		}
		memcpy (& number, memory, sizeof(number));
		printf ("0x%08X", LE32TOH(number));
		return (sizeof(number));
	}
	else if(! strcmp(object, "data"))
	{
		char const * size = string;
		if (! size)
		{
			error (1, EINVAL, "%s needs a length", object);
		}
		length = (unsigned) (uintspec(size, 1, extent));
		if (length > extent)
		{
			error (1, ECANCELED, "%s exceeds " SIZE_T_SPEC " bytes", object, length);
		}
		hexout (memory, length, 0, 0, stdout);
		return (length);
	}
	else if(! strcmp(object, "text"))
	{
		char const * size = string;
		if (! size)
		{
			error (1, EINVAL, "%s needs a length", object);
		}
		length = (unsigned) (uintspec(size, 1, extent));
		getstring (memory, extent, object, length);
		return (length);
	}
	else if(! strcmp(object, "skip"))
	{
		char const * size = string;
		if (! size)
		{
			error (1, EINVAL, "%s needs a length", object);
		}
		length = (unsigned) (uintspec(size, 1, extent));
		return (length);
	}
	else if(! strcmp(object, "mac"))
	{
		length = ETHER_ADDR_LEN;
		getmemory (memory, extent, object, length);
		return (length);
	}
	else if(! strcmp(object, "url"))
	{
		length = STRINGSIZE;
		getstring (memory, extent, object, length);
		return (length);
	}
	else 
	{
		error (1, ENOTSUP, "%s", object);
	}
	return (0);
}
예제 #13
0
signed GetProperty (struct plc * plc, struct plcproperty * plcproperty) 

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

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

	struct __packed vs_get_property_request 
	{
		struct ethernet_std ethernet;
		struct qualcomm_std qualcomm;
		uint32_t COOKIE;
		uint8_t DATA_FORMAT;
		uint8_t PROP_FORMAT;
		uint8_t RESERVED [2];
		uint32_t PROP_VERSION;
		uint32_t PROP_LENGTH;
		uint8_t PROP_NUMBER;
	}
	* request = (struct vs_get_property_request *) (message);
	struct __packed vs_get_property_confirm 
	{
		struct ethernet_std ethernet;
		struct qualcomm_std qualcomm;
		uint32_t MSTATUS;
		uint32_t COOKIE;
		uint8_t DATA_FORMAT;
		uint8_t RESERVED [3];
		uint32_t DATA_LENGTH;
		uint32_t DATA_BUFFER [1];
	}
	* confirm = (struct vs_get_property_confirm *) (message);

#ifndef __GNUC__
#pragma pack (pop)
#endif

	Request (plc, "Get Property");
	memset (message, 0, sizeof (* message));
	EthernetHeader (&request->ethernet, channel->peer, channel->host, HOMEPLUG_MTYPE);
	QualcommHeader (&request->qualcomm, 0, (VS_GET_PROPERTY | MMTYPE_REQ));
	request->COOKIE = HTOLE32 (plc->cookie);
	request->DATA_FORMAT = plcproperty->DATA_FORMAT;
	request->PROP_FORMAT = plcproperty->PROP_FORMAT;
	request->PROP_VERSION = HTOLE32 (plcproperty->PROP_VERSION);
	request->PROP_LENGTH = HTOLE32 (plcproperty->PROP_LENGTH);
	request->PROP_NUMBER = HTOLE32 (plcproperty->PROP_NUMBER);
	plc->packetsize = (ETHER_MIN_LEN - ETHER_CRC_LEN);
	if (SendMME (plc) <= 0) 
	{
		error ((plc->flags & PLC_BAILOUT), errno, CHANNEL_CANTSEND);
		return (-1);
	}
	while (ReadMME (plc, 0, (VS_GET_PROPERTY | MMTYPE_CNF)) > 0) 
	{
		if (confirm->MSTATUS) 
		{
			Failure (plc, PLC_WONTDOIT);
			continue;
		}
		if (plcproperty->DATA_FORMAT == PLC_FORMAT_BIN) 
		{
			binout (confirm->DATA_BUFFER, confirm->DATA_LENGTH, ' ', '\n', stdout);
			continue;
		}
		if (plcproperty->DATA_FORMAT == PLC_FORMAT_HEX) 
		{
			hexout (confirm->DATA_BUFFER, confirm->DATA_LENGTH, ' ', '\n', stdout);
			continue;
		}
		if (plcproperty->DATA_FORMAT == PLC_FORMAT_DEC) 
		{
			decout (confirm->DATA_BUFFER, confirm->DATA_LENGTH, ' ', '\n', stdout);
			continue;
		}
		if (plcproperty->DATA_FORMAT == PLC_FORMAT_ASC) 
		{
			chrout (confirm->DATA_BUFFER, confirm->DATA_LENGTH, '.', '\n', stdout);
			continue;
		}
	}
	return (0);
}
예제 #14
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;
}