6LoWPAN: Fixes needed when extended addressing is enabled. Currently breaks short addressing.

This commit is contained in:
Gregory Nutt
2017-06-22 09:28:25 -06:00
parent 6903e5895c
commit b5994560cc
4 changed files with 26 additions and 19 deletions
+5 -5
View File
@@ -343,7 +343,7 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
*/ */
fragptr = fptr + hdrsize; fragptr = fptr + hdrsize;
switch ((GETHOST16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE) & 0xf800) >> 8) switch ((GETUINT16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE) & 0xf800) >> 8)
{ {
/* First fragment of new reassembly */ /* First fragment of new reassembly */
@@ -351,8 +351,8 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
{ {
/* Set up for the reassembly */ /* Set up for the reassembly */
fragsize = GETHOST16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE) & 0x07ff; fragsize = GETUINT16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE) & 0x07ff;
fragtag = GETHOST16(fragptr, SIXLOWPAN_FRAG_TAG); fragtag = GETUINT16(fragptr, SIXLOWPAN_FRAG_TAG);
g_frame_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN; g_frame_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN;
ninfo("FRAG1: fragsize=%d fragtag=%d fragoffset=%d\n", ninfo("FRAG1: fragsize=%d fragtag=%d fragoffset=%d\n",
@@ -370,8 +370,8 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
/* Set offset, tag, size. Offset is in units of 8 bytes. */ /* Set offset, tag, size. Offset is in units of 8 bytes. */
fragoffset = fragptr[SIXLOWPAN_FRAG_OFFSET]; fragoffset = fragptr[SIXLOWPAN_FRAG_OFFSET];
fragtag = GETHOST16(fragptr, SIXLOWPAN_FRAG_TAG); fragtag = GETUINT16(fragptr, SIXLOWPAN_FRAG_TAG);
fragsize = GETHOST16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE) & 0x07ff; fragsize = GETUINT16(fragptr, SIXLOWPAN_FRAG_DISPATCH_SIZE) & 0x07ff;
g_frame_hdrlen += SIXLOWPAN_FRAGN_HDR_LEN; g_frame_hdrlen += SIXLOWPAN_FRAGN_HDR_LEN;
ninfo("FRAGN: fragsize=%d fragtag=%d fragoffset=%d\n", ninfo("FRAGN: fragsize=%d fragtag=%d fragoffset=%d\n",
+2 -7
View File
@@ -102,16 +102,11 @@
/* General helper macros ****************************************************/ /* General helper macros ****************************************************/
/* GET 16-bit data: source in network order, result in host order */ /* GET 16-bit data: source in network order */
#define GETHOST16(ptr,index) \ #define GETUINT16(ptr,index) \
((((uint16_t)((ptr)[index])) << 8) | ((uint16_t)(((ptr)[(index) + 1])))) ((((uint16_t)((ptr)[index])) << 8) | ((uint16_t)(((ptr)[(index) + 1]))))
/* GET 16-bit data: source in network order, result in network order */
#define GETNET16(ptr,index) \
((((uint16_t)((ptr)[(index) + 1])) << 8) | ((uint16_t)(((ptr)[index]))))
/* PUT 16-bit data: source in host order, result in newtwork order */ /* PUT 16-bit data: source in host order, result in newtwork order */
#define PUTHOST16(ptr,index,value) \ #define PUTHOST16(ptr,index,value) \
+18 -6
View File
@@ -89,6 +89,8 @@ void sixlowpan_saddrfromip(const net_ipv6addr_t ipaddr,
{ {
DEBUGASSERT(ipaddr[0] == HTONS(0xfe80)); DEBUGASSERT(ipaddr[0] == HTONS(0xfe80));
/* Big-endian uint16_t to byte order */
saddr->u8[0] = ipaddr[7] >> 8; saddr->u8[0] = ipaddr[7] >> 8;
saddr->u8[1] = ipaddr[7] & 0xff; saddr->u8[1] = ipaddr[7] & 0xff;
saddr->u8[0] ^= 0x02; saddr->u8[0] ^= 0x02;
@@ -97,9 +99,19 @@ void sixlowpan_saddrfromip(const net_ipv6addr_t ipaddr,
void sixlowpan_eaddrfromip(const net_ipv6addr_t ipaddr, void sixlowpan_eaddrfromip(const net_ipv6addr_t ipaddr,
FAR struct sixlowpan_eaddr_s *eaddr) FAR struct sixlowpan_eaddr_s *eaddr)
{ {
FAR uint8_t *eptr = eaddr->u8;
int i;
DEBUGASSERT(ipaddr[0] == HTONS(0xfe80)); DEBUGASSERT(ipaddr[0] == HTONS(0xfe80));
memcpy(eaddr, &ipaddr[4], NET_6LOWPAN_EADDRSIZE); for (i = 4; i < 8; i++)
{
/* Big-endian uint16_t to byte order */
*eptr++ = ipaddr[i] >> 8;
*eptr++ = ipaddr[i] & 0xff;
}
eaddr->u8[0] ^= 0x02; eaddr->u8[0] ^= 0x02;
} }
@@ -145,7 +157,7 @@ bool sixlowpan_issaddrbased(const net_ipv6addr_t ipaddr,
FAR const uint8_t *byteptr = saddr->u8; FAR const uint8_t *byteptr = saddr->u8;
return (ipaddr[5] == HTONS(0x00ff) && ipaddr[6] == HTONS(0xfe00) && return (ipaddr[5] == HTONS(0x00ff) && ipaddr[6] == HTONS(0xfe00) &&
ipaddr[7] == (GETNET16(byteptr, 0) ^ HTONS(0x0200))); ipaddr[7] == (GETUINT16(byteptr, 0) ^ 0x0200));
} }
bool sixlowpan_iseaddrbased(const net_ipv6addr_t ipaddr, bool sixlowpan_iseaddrbased(const net_ipv6addr_t ipaddr,
@@ -153,10 +165,10 @@ bool sixlowpan_iseaddrbased(const net_ipv6addr_t ipaddr,
{ {
FAR const uint8_t *byteptr = eaddr->u8; FAR const uint8_t *byteptr = eaddr->u8;
return (ipaddr[4] == (GETNET16(byteptr, 0) ^ HTONS(0x0200)) && return (ipaddr[4] == (GETUINT16(byteptr, 0) ^ 0x0200) &&
ipaddr[5] == GETNET16(byteptr, 2) && ipaddr[5] == GETUINT16(byteptr, 2) &&
ipaddr[6] == GETNET16(byteptr, 4) && ipaddr[6] == GETUINT16(byteptr, 4) &&
ipaddr[7] == GETNET16(byteptr, 6)); ipaddr[7] == GETUINT16(byteptr, 6));
} }
bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr, bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr,
+1 -1
View File
@@ -270,7 +270,7 @@ static int macnet_advertise(FAR struct net_driver_s *dev)
dev->d_ipv6addr[4] = (uint16_t)eaddr[0] << 8 | (uint16_t)eaddr[1]; dev->d_ipv6addr[4] = (uint16_t)eaddr[0] << 8 | (uint16_t)eaddr[1];
dev->d_ipv6addr[5] = (uint16_t)eaddr[2] << 8 | (uint16_t)eaddr[3]; dev->d_ipv6addr[5] = (uint16_t)eaddr[2] << 8 | (uint16_t)eaddr[3];
dev->d_ipv6addr[6] = (uint16_t)eaddr[4] << 8 | (uint16_t)eaddr[5]; dev->d_ipv6addr[6] = (uint16_t)eaddr[4] << 8 | (uint16_t)eaddr[5];
dev->d_ipv6addr[7] = (uint16_t)eaddr[6] << 8 | (uint16_t)eaddr[6]; dev->d_ipv6addr[7] = (uint16_t)eaddr[6] << 8 | (uint16_t)eaddr[7];
dev->d_ipv6addr[4] ^= 0x200; dev->d_ipv6addr[4] ^= 0x200;
return OK; return OK;
} }