From 33a4ec969a98185be4cca8c072b9d6b882edd3d0 Mon Sep 17 00:00:00 2001 From: Anthony Merlino Date: Wed, 19 Dec 2018 18:41:27 +0000 Subject: [PATCH] Merged in antmerlino/nuttx/avoid-double-context-lookup (pull request #788) sixlowpan: Address comment regarding avoiding double lookup of address context. Approved-by: GregoryN --- net/sixlowpan/sixlowpan_hc06.c | 41 ++++++++++++++++------------ wireless/ieee802154/mac802154_data.c | 8 +++--- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/net/sixlowpan/sixlowpan_hc06.c b/net/sixlowpan/sixlowpan_hc06.c index 2ef0e2b1aa..e4e872a71f 100644 --- a/net/sixlowpan/sixlowpan_hc06.c +++ b/net/sixlowpan/sixlowpan_hc06.c @@ -131,7 +131,7 @@ static FAR uint8_t *g_hc06ptr; * 2 -> 2 bytes from prefix - 0000::00ff:fe00:XXXX and 2 bytes from packet * 3 -> 2 bytes from prefix - Infer 2 or 8 bytes from MAC address * - * NOTE: ipaddr=the uncompress function does change 0xf to 0x10 + * NOTE: ipaddr=the uncompress function does change 0xf to 0x100 * NOTE: 0x00 ipaddr=no-autoconfig ipaddr=unspecified */ @@ -238,6 +238,11 @@ static FAR struct sixlowpan_addrcontext_s * if ((g_hc06_addrcontexts[i].used == 1) && net_ipv6addr_prefixcmp(&g_hc06_addrcontexts[i].prefix, ipaddr, 64)) { + ninfo("Context found for ipaddr=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x Context: %d\n", + ntohs(ipaddr[0]), ntohs(ipaddr[1]), ntohs(ipaddr[2]), ntohs(ipaddr[3]), + ntohs(ipaddr[4]), ntohs(ipaddr[5]), ntohs(ipaddr[6]), ntohs(ipaddr[7]), + g_hc06_addrcontexts[i].number); + return &g_hc06_addrcontexts[i]; } } @@ -700,7 +705,8 @@ int sixlowpan_compresshdr_hc06(FAR struct radio_driver_s *radio, FAR uint8_t *fptr) { FAR uint8_t *iphc = fptr + g_frame_hdrlen; - FAR struct sixlowpan_addrcontext_s *addrcontext; + FAR struct sixlowpan_addrcontext_s *saddrcontext; + FAR struct sixlowpan_addrcontext_s *daddrcontext; uint8_t iphc0; uint8_t iphc1; uint8_t tmp; @@ -726,18 +732,16 @@ int sixlowpan_compresshdr_hc06(FAR struct radio_driver_s *radio, * byte with [ SCI | DCI ] */ - /* Check if dest address context exists (for allocating third byte) - * - * TODO: fix this so that it remembers the looked up values for avoiding two - * lookups - or set the lookup values immediately - */ + /* Check if dest address context exists (for allocating third byte) */ - if (find_addrcontext_byprefix(ipv6->destipaddr) != NULL || - find_addrcontext_byprefix(ipv6->srcipaddr) != NULL) + daddrcontext = find_addrcontext_byprefix(ipv6->destipaddr); + saddrcontext = find_addrcontext_byprefix(ipv6->srcipaddr); + + if (daddrcontext != NULL || saddrcontext != NULL) { /* set address context flag and increase g_hc06ptr */ - ninfo("Decompressing dest or src ipaddr. Setting CID\n"); + ninfo("Compressing dest or src ipaddr. Setting CID\n"); iphc1 |= SIXLOWPAN_IPHC_CID; g_hc06ptr++; } @@ -852,15 +856,15 @@ int sixlowpan_compresshdr_hc06(FAR struct radio_driver_s *radio, iphc1 |= SIXLOWPAN_IPHC_SAC; iphc1 |= SIXLOWPAN_IPHC_SAM_128; } - else if ((addrcontext = find_addrcontext_byprefix(ipv6->srcipaddr)) != NULL) + else if (saddrcontext != NULL) { /* Elide the prefix - indicate by CID and set address context + SAC */ - ninfo("Compressing src with address context. Setting CID and SAC context: %d\n", - addrcontext->number); + ninfo("Compressing src with address context. Setting SAC. Context: %d\n", + saddrcontext->number); - iphc1 |= SIXLOWPAN_IPHC_CID | SIXLOWPAN_IPHC_SAC; - iphc[2] |= addrcontext->number << 4; + iphc1 |= SIXLOWPAN_IPHC_SAC; + iphc[2] |= saddrcontext->number << 4; /* Compression compare with this nodes address (source) */ @@ -954,12 +958,15 @@ int sixlowpan_compresshdr_hc06(FAR struct radio_driver_s *radio, { /* Address is unicast, try to compress */ - if ((addrcontext = find_addrcontext_byprefix(ipv6->destipaddr)) != NULL) + if (daddrcontext != NULL) { /* Elide the prefix */ + ninfo("Compressing dest with address context. Setting DAC. Context: %d\n", + daddrcontext->number); + iphc1 |= SIXLOWPAN_IPHC_DAC; - iphc[2] |= addrcontext->number; + iphc[2] |= daddrcontext->number; /* Compession compare with link adress (destination) */ diff --git a/wireless/ieee802154/mac802154_data.c b/wireless/ieee802154/mac802154_data.c index 86e9e1ea3f..f8acb6e05c 100644 --- a/wireless/ieee802154/mac802154_data.c +++ b/wireless/ieee802154/mac802154_data.c @@ -127,12 +127,12 @@ int mac802154_req_data(MACHANDLE mac, if (meta->destaddr.mode != IEEE802154_ADDRMODE_NONE) { IEEE802154_PANIDCOPY(&frame->io_data[mhr_len], meta->destaddr.panid); - mhr_len += 2; + mhr_len += IEEE802154_PANIDSIZE; if (meta->destaddr.mode == IEEE802154_ADDRMODE_SHORT) { IEEE802154_SADDRCOPY(&frame->io_data[mhr_len], meta->destaddr.saddr); - mhr_len += 2; + mhr_len += IEEE802154_SADDRSIZE; } else if (meta->destaddr.mode == IEEE802154_ADDRMODE_EXTENDED) { @@ -185,13 +185,13 @@ int mac802154_req_data(MACHANDLE mac, (!(*frame_ctrl & IEEE802154_FRAMECTRL_PANIDCOMP))) { IEEE802154_PANIDCOPY(&frame->io_data[mhr_len], priv->addr.panid); - mhr_len += 2; + mhr_len += IEEE802154_PANIDSIZE; } if (meta->srcmode == IEEE802154_ADDRMODE_SHORT) { IEEE802154_SADDRCOPY(&frame->io_data[mhr_len], priv->addr.saddr); - mhr_len += 2; + mhr_len += IEEE802154_SADDRSIZE; } else if (meta->srcmode == IEEE802154_ADDRMODE_EXTENDED) {