6loWPAN: Correct some IPv6 addresses and operations on IPv6 addresses.

This commit is contained in:
Gregory Nutt 2017-04-05 12:11:09 -06:00
parent e61fd2d45b
commit cb70ce7d3c
4 changed files with 52 additions and 38 deletions

View File

@ -889,10 +889,10 @@ CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_1=0xfe80
CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_2=0x0000
CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_3=0x0000
CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_4=0x0000
CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_5=0x1234
CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_6=0x0000
CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_7=0x0000
CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_8=0x0000
CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_5=0x0000
CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_6=0x00ff
CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_7=0xfe00
CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_8=0x3234
CONFIG_EXAMPLES_NSH=y
# CONFIG_EXAMPLES_NULL is not set
# CONFIG_EXAMPLES_NX is not set
@ -1097,10 +1097,10 @@ CONFIG_NSH_IPv6ADDR_1=0xfe80
CONFIG_NSH_IPv6ADDR_2=0x0000
CONFIG_NSH_IPv6ADDR_3=0x0000
CONFIG_NSH_IPv6ADDR_4=0x0000
CONFIG_NSH_IPv6ADDR_5=0xabcd
CONFIG_NSH_IPv6ADDR_6=0x0000
CONFIG_NSH_IPv6ADDR_7=0x0000
CONFIG_NSH_IPv6ADDR_8=0x0000
CONFIG_NSH_IPv6ADDR_5=0x0000
CONFIG_NSH_IPv6ADDR_6=0x00ff
CONFIG_NSH_IPv6ADDR_7=0xfe00
CONFIG_NSH_IPv6ADDR_8=0x8bcd
#
# Router IPv6 address
@ -1109,10 +1109,10 @@ CONFIG_NSH_DRIPv6ADDR_1=0xfe80
CONFIG_NSH_DRIPv6ADDR_2=0x0000
CONFIG_NSH_DRIPv6ADDR_3=0x0000
CONFIG_NSH_DRIPv6ADDR_4=0x0000
CONFIG_NSH_DRIPv6ADDR_5=0x1234
CONFIG_NSH_DRIPv6ADDR_6=0x0000
CONFIG_NSH_DRIPv6ADDR_7=0x0000
CONFIG_NSH_DRIPv6ADDR_8=0x0000
CONFIG_NSH_DRIPv6ADDR_5=0x0000
CONFIG_NSH_DRIPv6ADDR_6=0x00ff
CONFIG_NSH_DRIPv6ADDR_7=0xfe00
CONFIG_NSH_DRIPv6ADDR_8=0x3234
#
# IPv6 Network mask
@ -1121,9 +1121,9 @@ CONFIG_NSH_IPv6NETMASK_1=0xffff
CONFIG_NSH_IPv6NETMASK_2=0xffff
CONFIG_NSH_IPv6NETMASK_3=0xffff
CONFIG_NSH_IPv6NETMASK_4=0xffff
CONFIG_NSH_IPv6NETMASK_5=0x0000
CONFIG_NSH_IPv6NETMASK_6=0x0000
CONFIG_NSH_IPv6NETMASK_7=0x0000
CONFIG_NSH_IPv6NETMASK_5=0xffff
CONFIG_NSH_IPv6NETMASK_6=0xffff
CONFIG_NSH_IPv6NETMASK_7=0xffff
CONFIG_NSH_IPv6NETMASK_8=0x0000
# CONFIG_NSH_DNS is not set
CONFIG_NSH_NOMAC=y

View File

@ -158,8 +158,8 @@ static const struct file_operations btn_fops =
btn_open, /* open */
btn_close, /* close */
btn_read, /* read */
0, /* write */
0, /* seek */
NULL, /* write */
NULL, /* seek */
btn_ioctl /* ioctl */
#ifndef CONFIG_DISABLE_POLL
, btn_poll /* poll */

View File

@ -239,13 +239,16 @@ static uint8_t compress_addr_64(FAR const net_ipv6addr_t ipaddr,
FAR const struct rimeaddr_s *macaddr,
uint8_t bitpos)
{
ninfo("ipaddr=%p macaddr=%p bitpos=%u g_hc06ptr=%p\n",
ipaddr, macaddr, bitpos, g_hc06ptr);
if (sixlowpan_ismacbased(ipaddr, macaddr))
{
return 3 << bitpos; /* 0-bits */
}
else if (SIXLOWPAN_IS_IID_16BIT_COMPRESSABLE(ipaddr))
{
/* Compress IID to 16 bits xxxx::0000:00ff:fe00:XXXX */
/* Compress IID to 16 bits: xxxx:xxxx:xxxx:xxxx:0000:00ff:fe00:XXXX */
memcpy(g_hc06ptr, &ipaddr[7], 2);
g_hc06ptr += 2;
@ -253,7 +256,7 @@ static uint8_t compress_addr_64(FAR const net_ipv6addr_t ipaddr,
}
else
{
/* Do not compress IID => xxxx::IID */
/* Do not compress IID: xxxx:xxxx:xxxx:xxxx:IID:IID:IID:IID */
memcpy(g_hc06ptr, &ipaddr[4], 8);
g_hc06ptr += 8;
@ -455,11 +458,9 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
uint8_t iphc1;
uint8_t tmp;
sixlowpan_dumpbuffer("IPv6 before compression",
(FAR const uint8_t *)ipv6,
sizeof(struct ipv6_hdr_s));
g_hc06ptr = fptr + 2;
ninfo("fptr=%p g_frame_hdrlen=%u iphc=%p g_hc06ptr=%p\n",
fptr, g_frame_hdrlen, iphc, g_hc06ptr);
/* As we copy some bit-length fields, in the IPHC encoding bytes,
* we sometimes use |=
@ -516,7 +517,7 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
}
else
{
/* Sompress only the flow label */
/* Compress only the flow label */
*g_hc06ptr = tmp;
g_hc06ptr += 1;
@ -810,6 +811,10 @@ void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
iphc[1] = iphc1;
g_frame_hdrlen = g_hc06ptr - fptr;
ninfo("fptr=%p g_frame_hdrlen=%u iphc=%02x:%02x:%02x g_hc06ptr=%p\n",
fptr, g_frame_hdrlen, iphc[0], iphc[1], iphc[2], g_hc06ptr);
return;
}
@ -856,11 +861,14 @@ void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
iphc0 = iphc[0];
iphc1 = iphc[1];
ninfo("payptr=%p g_frame_hdrlen=%u iphc[%p]=%02x:%02x:%02x g_hc06ptr=%p\n",
payptr, g_frame_hdrlen, iphc, iphc[0], iphc[1], iphc[2], g_hc06ptr);
/* Another if the CID flag is set */
if (iphc1 & SIXLOWPAN_IPHC_CID)
{
ninfo("IPHC: CID flag set - increase header with one\n");
ninfo("IPHC: CID flag set. Increase header by one\n");
g_hc06ptr++;
}

View File

@ -73,7 +73,7 @@
*
* 128 112 96 80 64 48 32 16
* ---- ---- ---- ---- ---- ---- ---- ----
* fe80 0000 0000 0000 xxxx xxxx 0000 0000 2-byte Rime address (VALID?)
* fe80 0000 0000 0000 0000 00ff fe00 xxxx 2-byte Rime address
* fe80 0000 0000 0000 xxxx xxxx xxxx xxxx 8-byte Rime address
*
****************************************************************************/
@ -81,20 +81,22 @@
void sixlowpan_ipfromrime(FAR const struct rimeaddr_s *rime,
net_ipv6addr_t ipaddr)
{
/* We consider only links with IEEE EUI-64 identifier or IEEE 48-bit MAC
* addresses.
*/
memset(ipaddr, 0, sizeof(net_ipv6addr_t));
ipaddr[0] = HTONS(0xfe80);
/* We consider only links with IEEE EUI-64 identifier or IEEE 48-bit MAC
* addresses. NOTE: that CONFIG_NET_6LOWPAN_RIMEADDR_SIZE may be 2 or
* 8. In the case of 2, we treat the address like an 8 byte address with
* the lower bytes set to zero.
*
* REVISIT: This is just a guess so that I can continue making forward
* progress. What is the correct policy?
*/
#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2
ipaddr[5] = HTONS(0x00ff);
ipaddr[6] = HTONS(0xfe00);
memcpy(&ipaddr[7], rime, CONFIG_NET_6LOWPAN_RIMEADDR_SIZE);
ipaddr[7] ^= HTONS(0x0200);
#else
memcpy(&ipaddr[4], rime, CONFIG_NET_6LOWPAN_RIMEADDR_SIZE);
ipaddr[4] ^= HTONS(0x0200);
#endif
}
/****************************************************************************
@ -105,7 +107,7 @@ void sixlowpan_ipfromrime(FAR const struct rimeaddr_s *rime,
*
* 128 112 96 80 64 48 32 16
* ---- ---- ---- ---- ---- ---- ---- ----
* fe80 0000 0000 0000 xxxx 0000 0000 0000 2-byte Rime address (VALID?)
* fe80 0000 0000 0000 0000 00ff fe00 xxxx 2-byte Rime address
* fe80 0000 0000 0000 xxxx xxxx xxxx xxxx 8-byte Rime address
*
****************************************************************************/
@ -117,7 +119,11 @@ void sixlowpan_rimefromip(const net_ipv6addr_t ipaddr,
DEBUGASSERT(ipaddr[0] == HTONS(0xfe80));
#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2
memcpy(rime, &ipaddr[7], CONFIG_NET_6LOWPAN_RIMEADDR_SIZE);
#else
memcpy(rime, &ipaddr[4], CONFIG_NET_6LOWPAN_RIMEADDR_SIZE);
#endif
rime->u8[0] ^= 0x02;
}
@ -125,11 +131,11 @@ void sixlowpan_rimefromip(const net_ipv6addr_t ipaddr,
* Name: sixlowpan_ismacbased
*
* Description:
* Extract the rime address from a link local IPv6 address:
* Check if the MAC address is encoded in the IP address:
*
* 128 112 96 80 64 48 32 16
* ---- ---- ---- ---- ---- ---- ---- ----
* fe80 0000 0000 0000 xxxx 0000 0000 0000 2-byte Rime address (VALID?)
* fe80 0000 0000 0000 0000 00ff fe00 xxxx 2-byte Rime address
* fe80 0000 0000 0000 xxxx xxxx xxxx xxxx 8-byte Rime address
*
****************************************************************************/