| | |
| | | |
| | | #define PACK_HEADER 0xFD |
| | | |
| | | /* Tag definition */ |
| | | enum |
| | | { |
| | | TAG_LOGON=1, |
| | |
| | | |
| | | bytes = packtlv_led(buf, sizeof(buf), ON); |
| | | |
| | | /* print every byte in the buffer as HEX and corresponding charactor, |
| | | which is not printable charactor will be instead as '?' */ |
| | | dump_buf(buf, bytes); |
| | | |
| | | bytes = packtlv_logon(buf, sizeof(buf), "iot@yun"); |
| | |
| | | unsigned short crc16 = 0; |
| | | int pack_len = 0; |
| | | int data_len = 0; |
| | | int ofset = 0; |
| | | int ofset = 0; /* index position for the buf */ |
| | | |
| | | if(!buf || !pwd || size<TLV_MIN_SIZE ) |
| | | { |
| | |
| | | buf[ofset] = TAG_LOGON; |
| | | ofset += 1; |
| | | |
| | | /* $pwd too long maybe result buffer overflow, if it's too long then truncate it */ |
| | | /* $pwd too long maybe result buffer overflow, so we need check the buffer |
| | | * is large enuf or not. If buf size is not enuf we will truncate $pwd string */ |
| | | if( strlen(pwd) <= size-TLV_FIXED_SIZE ) |
| | | data_len = strlen(pwd); |
| | | else |
| | |
| | | memcpy(&buf[ofset], pwd, data_len); |
| | | ofset += data_len; |
| | | |
| | | /* Calc CRC16 value from Packet Head(buf[0])~ Packet Value(buf[ofset]) */ |
| | | crc16 = crc_itu_t(IoT_MAGIC_CRC, buf, ofset); |
| | | /* Calc CRC16 checksum value from Packet Head(buf[0])~ Value(buf[ofset]) */ |
| | | crc16 = crc_itu_t(MAGIC_CRC, buf, ofset); |
| | | |
| | | /* Append the 2 Bytes CRC16 checksum value into the last two bytes in packet buffer */ |
| | | ushort_to_bytes(&buf[ofset], crc16); |
| | | ofset += 2; |
| | | |
| | |
| | | /* Value */ |
| | | buf[3] = (OFF==cmd) ? 0x00 : 0x01; |
| | | |
| | | /* Calc CRC16 value from Packet Head(buf[0])~ Packet Value(buf[3]) */ |
| | | crc16 = crc_itu_t(IoT_MAGIC_CRC, buf, 4); |
| | | /* Calc CRC16 checksum value from Packet Head(buf[0])~ Packet Value(buf[3]) */ |
| | | crc16 = crc_itu_t(MAGIC_CRC, buf, 4); |
| | | |
| | | /* Append the 2 Bytes CRC16 value into the packet buffer */ |
| | | /* Append the 2 Bytes CRC16 checksum value into the last two bytes in packet buffer */ |
| | | ushort_to_bytes(&buf[4], crc16); |
| | | |
| | | return pack_len; |
| | |
| | | "????????????????" |
| | | "????????????????"; |
| | | |
| | | /* print every byte in the buffer as HEX and corresponding charactor, which is not printable charactor will be instead as '?' */ |
| | | void dump_buf(char *data, int len) |
| | | { |
| | | int rc; |