Merged in antmerlino/nuttx/sixlowpan-ul-bit (pull request #787)

sixlowpan: Fixes logic surrounding the Universal/Local bit. This bit represents whether the IID is locally/globally administered. The U/L bit is bit 1 of the MSB of the EUI-64. It should only be inverted in cases where there is a full EUI-64. In cases whe

* sixlowpan: Fixes logic surrounding the Universal/Local bit. This bit represents whether the IID is locally/globally administered. The U/L bit is bit 1 of the MSB of the EUI-64. It should only be inverted in cases where there is a full EUI-64. In cases where the IID is derived from say, a short address, this bit should be forced to 0, indicating that it is locally administered.

    See:

    https://tools.ietf.org/html/rfc4291#section-2.5.1
    https://tools.ietf.org/html/rfc4944#section-6
    https://tools.ietf.org/html/rfc2464#section-4

* sixlowpan: Account for endianness with U/L bit.

Approved-by: GregoryN <gnutt@nuttx.org>
This commit is contained in:
Anthony Merlino
2018-12-18 13:34:41 +00:00
committed by GregoryN
parent 0d20c39250
commit b48a62a7d4
9 changed files with 30 additions and 31 deletions
@@ -296,7 +296,10 @@ static int xbeenet_set_ipaddress(FAR struct net_driver_s *dev)
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[7] = (uint16_t)eaddr[6] << 8 | (uint16_t)eaddr[7];
dev->d_ipv6addr[4] ^= 0x200;
/* Invert the U/L bit */
dev->d_ipv6addr[4] ^= HTONS(0x0200);
return OK;
}
@@ -334,7 +337,6 @@ static int xbeenet_set_ipaddress(FAR struct net_driver_s *dev)
dev->d_ipv6addr[5] = HTONS(0x00ff);
dev->d_ipv6addr[6] = HTONS(0xfe00);
dev->d_ipv6addr[7] = (uint16_t)saddr[0] << 8 | (uint16_t)saddr[1];
dev->d_ipv6addr[7] ^= 0x200;
return OK;
}
#endif
@@ -620,7 +620,7 @@ static void spirit_set_ipaddress(FAR struct net_driver_s *dev)
dev->d_ipv6addr[4] = 0;
dev->d_ipv6addr[5] = HTONS(0x00ff);
dev->d_ipv6addr[6] = HTONS(0xfe00);
dev->d_ipv6addr[7] = (uint16_t)addr->nv_addr[0] << 8 ^ 0x0200;
dev->d_ipv6addr[7] = (uint16_t)addr->nv_addr[0] << 8;
}
/****************************************************************************
+1 -1
View File
@@ -216,7 +216,7 @@ int sixlowpan_meta_data(FAR struct radio_driver_s *radio,
sixlowpan_saddrcopy(&meta->destaddr.saddr, pktmeta->dest.nm_addr);
}
IEEE802154_SADDRCOPY(meta->destaddr.panid, pktmeta->dpanid);
IEEE802154_PANIDCOPY(meta->destaddr.panid, pktmeta->dpanid);
/* Handle associated with MSDU. Will increment once per packet, not
* necesarily per frame: The same MSDU handle will be used for each
+5 -9
View File
@@ -447,12 +447,6 @@ static void uncompress_addr(FAR const struct netdev_varaddr_s *addr,
{
postcount = addr->nv_addrlen;
}
/* If we are converting the entire MAC address, then we need to some some
* special bit operations.
*/
fullmac = (postcount == addr->nv_addrlen);
}
/* Copy any prefix */
@@ -532,11 +526,13 @@ static void uncompress_addr(FAR const struct netdev_varaddr_s *addr,
srcptr += 2;
}
/* If the was a standard MAC based address then toggle */
/* If the IP is dervied from a MAC address big enough to include the U/L bit,
* invert it.
*/
if (fullmac)
if (usemac && postcount == 8)
{
ipaddr[7] ^= 0x0200;
ipaddr[4] ^= HTONS(0x0200);
}
/* If we took the data from packet, then update the packet pointer */
+1 -1
View File
@@ -101,7 +101,7 @@
#define GETUINT16(ptr,index) \
((((uint16_t)((ptr)[index])) << 8) | ((uint16_t)(((ptr)[(index) + 1]))))
/* PUT 16-bit data: source in host order, result in newtwork order */
/* PUT 16-bit data: source in host order, result in network order */
#define PUTHOST16(ptr,index,value) \
do \
+9 -10
View File
@@ -127,7 +127,7 @@ static void sixlowpan_baddrfromip(const net_ipv6addr_t ipaddr, FAR uint8_t *badd
{
/* Big-endian uint16_t to byte order */
baddr[0] = ipaddr[7] >> 8 ^ 0x02;
baddr[0] = ipaddr[7] >> 8;
}
#endif
@@ -138,7 +138,6 @@ static void sixlowpan_saddrfromip(const net_ipv6addr_t ipaddr, FAR uint8_t *sadd
saddr[0] = ipaddr[7] >> 8;
saddr[1] = ipaddr[7] & 0xff;
saddr[0] ^= 0x02;
}
#endif
@@ -148,8 +147,6 @@ static void sixlowpan_eaddrfromip(const net_ipv6addr_t ipaddr, FAR uint8_t *eadd
FAR uint8_t *eptr = eaddr;
int i;
DEBUGASSERT(ipaddr[0] == HTONS(0xfe80));
for (i = 4; i < 8; i++)
{
/* Big-endian uint16_t to byte order */
@@ -436,7 +433,7 @@ static inline void sixlowpan_ipfrombyte(FAR const uint8_t *byte,
ipaddr[4] = 0;
ipaddr[5] = HTONS(0x00ff);
ipaddr[6] = HTONS(0xfe00);
ipaddr[7] = (uint16_t)byte[0] << 8 ^ 0x0200;
ipaddr[7] = (uint16_t)byte[0] << 8;
}
#endif
@@ -452,7 +449,6 @@ static inline void sixlowpan_ipfromsaddr(FAR const uint8_t *saddr,
ipaddr[5] = HTONS(0x00ff);
ipaddr[6] = HTONS(0xfe00);
ipaddr[7] = (uint16_t)saddr[0] << 8 | (uint16_t)saddr[1];
ipaddr[7] ^= 0x0200;
}
#endif
@@ -468,7 +464,10 @@ static inline void sixlowpan_ipfromeaddr(FAR const uint8_t *eaddr,
ipaddr[5] = (uint16_t)eaddr[2] << 8 | (uint16_t)eaddr[3];
ipaddr[6] = (uint16_t)eaddr[4] << 8 | (uint16_t)eaddr[5];
ipaddr[7] = (uint16_t)eaddr[6] << 8 | (uint16_t)eaddr[7];
ipaddr[4] ^= 0x0200;
/* Invert the U/L bit */
ipaddr[4] ^= HTONS(0x0200);
}
#endif
@@ -523,7 +522,7 @@ static inline bool sixlowpan_isbytebased(const net_ipv6addr_t ipaddr,
{
return (ipaddr[5] == HTONS(0x00ff) &&
ipaddr[6] == HTONS(0xfe00) &&
ipaddr[7] == (((uint16_t)byte << 8) ^ 0x0200));
ipaddr[7] == ((uint16_t)byte << 8));
}
#endif
@@ -532,13 +531,13 @@ static inline bool sixlowpan_issaddrbased(const net_ipv6addr_t ipaddr,
{
return (ipaddr[5] == HTONS(0x00ff) &&
ipaddr[6] == HTONS(0xfe00) &&
ipaddr[7] == (GETUINT16(saddr, 0) ^ 0x0200));
ipaddr[7] == (GETUINT16(saddr, 0)));
}
static inline bool sixlowpan_iseaddrbased(const net_ipv6addr_t ipaddr,
FAR const uint8_t *eaddr)
{
return (ipaddr[4] == (GETUINT16(eaddr, 0) ^ 0x0200) &&
return (ipaddr[4] == (GETUINT16(eaddr, 0) ^ HTONS(0x0200)) &&
ipaddr[5] == GETUINT16(eaddr, 2) &&
ipaddr[6] == GETUINT16(eaddr, 4) &&
ipaddr[7] == GETUINT16(eaddr, 6));
+4 -2
View File
@@ -229,7 +229,10 @@ static void lo_addr2ip(FAR struct net_driver_s *dev)
dev->d_ipv6addr[5] = (uint16_t)g_eaddr[2] << 8 | (uint16_t)g_eaddr[3];
dev->d_ipv6addr[6] = (uint16_t)g_eaddr[4] << 8 | (uint16_t)g_eaddr[5];
dev->d_ipv6addr[7] = (uint16_t)g_eaddr[6] << 8 | (uint16_t)g_eaddr[7];
dev->d_ipv6addr[4] ^= 0x200;
/* Invert the U/L bit */
dev->d_ipv6addr[4] ^= HTONS(0x0200);
}
#endif
#else
@@ -251,7 +254,6 @@ static void lo_addr2ip(FAR struct net_driver_s *dev)
dev->d_ipv6addr[5] = HTONS(0x00ff);
dev->d_ipv6addr[6] = HTONS(0xfe00);
dev->d_ipv6addr[7] = (uint16_t)g_saddr[0] << 8 | (uint16_t)g_saddr[1];
dev->d_ipv6addr[7] ^= 0x200;
#endif
}
#endif
+4 -2
View File
@@ -296,7 +296,10 @@ static int macnet_advertise(FAR struct net_driver_s *dev)
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[7] = (uint16_t)eaddr[6] << 8 | (uint16_t)eaddr[7];
dev->d_ipv6addr[4] ^= 0x200;
/* Invert the U/L bit */
dev->d_ipv6addr[4] ^= HTONS(0x0200);
return OK;
}
@@ -334,7 +337,6 @@ static int macnet_advertise(FAR struct net_driver_s *dev)
dev->d_ipv6addr[5] = HTONS(0x00ff);
dev->d_ipv6addr[6] = HTONS(0xfe00);
dev->d_ipv6addr[7] = (uint16_t)saddr[0] << 8 | (uint16_t)saddr[1];
dev->d_ipv6addr[7] ^= 0x200;
return OK;
}
#endif
+1 -3
View File
@@ -221,7 +221,7 @@ static void lo_addr2ip(FAR struct net_driver_s *dev)
dev->d_ipv6addr[4] = 0;
dev->d_ipv6addr[5] = HTONS(0x00ff);
dev->d_ipv6addr[6] = HTONS(0xfe00);
dev->d_ipv6addr[7] = (uint16_t)g_mac_addr[0] << 8 ^ 0x0200;
dev->d_ipv6addr[7] = (uint16_t)g_mac_addr[0] << 8;
#elif CONFIG_PKTRADIO_ADDRLEN == 2
/* Set the IP address based on the 2 byte address */
@@ -230,7 +230,6 @@ static void lo_addr2ip(FAR struct net_driver_s *dev)
dev->d_ipv6addr[5] = HTONS(0x00ff);
dev->d_ipv6addr[6] = HTONS(0xfe00);
dev->d_ipv6addr[7] = (uint16_t)g_mac_addr[0] << 8 | (uint16_t)g_mac_addr[1];
dev->d_ipv6addr[7] ^= 0x0200;
#elif CONFIG_PKTRADIO_ADDRLEN == 8
/* Set the IP address based on the 8-byte address */
@@ -239,7 +238,6 @@ static void lo_addr2ip(FAR struct net_driver_s *dev)
dev->d_ipv6addr[5] = (uint16_t)g_mac_addr[2] << 8 | (uint16_t)g_mac_addr[3];
dev->d_ipv6addr[6] = (uint16_t)g_mac_addr[4] << 8 | (uint16_t)g_mac_addr[5];
dev->d_ipv6addr[7] = (uint16_t)g_mac_addr[6] << 8 | (uint16_t)g_mac_addr[7];
dev->d_ipv6addr[4] ^= 0x0200;
#endif
}