1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

sixlowpan: Decode 16-bit addresses correctly

10:  16 bits.  The first 112 bits of the address are elided.
The value of the first 64 bits is the link-local prefix padded with zeros.
The following 64 bits are 0000:00ff:fe00:XXXX, where XXXX are the 16 bits carried in-line.

See https://tools.ietf.org/html/rfc6282
This commit is contained in:
Joakim Gebart 2015-02-26 12:30:29 +01:00
parent 985a6525cc
commit 39c7566e11

View File

@ -1271,6 +1271,7 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length, net_if_eui64_t *s_addr,
/* Generate IPv6 address from stateless information, if SAC=1 we will use /* Generate IPv6 address from stateless information, if SAC=1 we will use
* this stateless information as a starting point for the stateful * this stateless information as a starting point for the stateful
* information. */ * information. */
/* RFC 6282 describes each of the following address compression methods */
switch (((lowpan_iphc[1] & SIXLOWPAN_IPHC2_SAM) >> 4) & 0x03) { switch (((lowpan_iphc[1] & SIXLOWPAN_IPHC2_SAM) >> 4) & 0x03) {
case (0x01): { case (0x01): {
/* 64-bits */ /* 64-bits */
@ -1284,7 +1285,10 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length, net_if_eui64_t *s_addr,
case (0x02): { case (0x02): {
/* 16-bits */ /* 16-bits */
memcpy(&(ipv6_buf->srcaddr.uint8[0]), &ll_prefix[0], 2); memcpy(&(ipv6_buf->srcaddr.uint8[0]), &ll_prefix[0], 2);
memset(&(ipv6_buf->srcaddr.uint8[2]), 0, 12); ipv6_buf->srcaddr.uint16[1] = HTONS(0x0000u);
ipv6_buf->srcaddr.uint32[1] = HTONL(0x00000000u);
ipv6_buf->srcaddr.uint32[2] = HTONL(0x000000ffu);
ipv6_buf->srcaddr.uint16[6] = HTONS(0xfe00u);
memcpy(&(ipv6_buf->srcaddr.uint8[14]), &ipv6_hdr_fields[hdr_pos], 2); memcpy(&(ipv6_buf->srcaddr.uint8[14]), &ipv6_hdr_fields[hdr_pos], 2);
hdr_pos += 2; hdr_pos += 2;
break; break;
@ -1418,7 +1422,10 @@ void lowpan_iphc_decoding(uint8_t *data, uint8_t length, net_if_eui64_t *s_addr,
case (0x02): { case (0x02): {
/* 16-bits */ /* 16-bits */
memcpy(&(ipv6_buf->destaddr.uint8[0]), &ll_prefix[0], 2); memcpy(&(ipv6_buf->destaddr.uint8[0]), &ll_prefix[0], 2);
memset(&(ipv6_buf->destaddr.uint8[2]), 0, 12); ipv6_buf->destaddr.uint16[1] = HTONS(0x0000u);
ipv6_buf->destaddr.uint32[1] = HTONL(0x00000000u);
ipv6_buf->destaddr.uint32[2] = HTONL(0x000000ffu);
ipv6_buf->destaddr.uint16[6] = HTONS(0xfe00u);
memcpy(&(ipv6_buf->destaddr.uint8[14]), &ipv6_hdr_fields[hdr_pos], 2); memcpy(&(ipv6_buf->destaddr.uint8[14]), &ipv6_hdr_fields[hdr_pos], 2);
hdr_pos += 2; hdr_pos += 2;
break; break;