You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ry...@apache.org on 2018/12/05 12:24:08 UTC

[mynewt-nimble] 03/13: nimble/ll: Improve getting advertising and target address

This is an automated email from the ASF dual-hosted git repository.

rymek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 665f0795d91d4b3db129d1773a5cd5fa0bd2d39b
Author: Ɓukasz Rymanowski <lu...@codecoup.pl>
AuthorDate: Mon Nov 5 15:40:54 2018 +0100

    nimble/ll: Improve getting advertising and target address
    
    aux_data pointer contains valid advertiser and directed address from the
    very beggining if it is available. Later on when getting address let's
    make use of it and do not try to parse packet unless this is empty
    beacon
---
 nimble/controller/src/ble_ll_scan.c | 46 +++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 25 deletions(-)

diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c
index 2dd9caa..ebef10b 100644
--- a/nimble/controller/src/ble_ll_scan.c
+++ b/nimble/controller/src/ble_ll_scan.c
@@ -1922,6 +1922,27 @@ ble_ll_scan_get_addr_from_ext_adv(uint8_t *rxbuf, struct ble_mbuf_hdr *ble_hdr,
         return -1;
     }
 
+    if (aux_data) {
+        /* If address has been provided, we do have it already in aux_data.*/
+        if (aux_data->flags & BLE_LL_AUX_HAS_ADDRA) {
+            *addr = aux_data->addr;
+            *addr_type = aux_data->addr_type;
+        }
+
+        if (!inita) {
+            return 0;
+        }
+
+        if (aux_data->flags & BLE_LL_AUX_HAS_DIR_ADDRA) {
+            *inita = aux_data->dir_addr;
+            *inita_type = aux_data->dir_addr_type;
+        }
+
+        return 0;
+    }
+
+    /* If this is just becon with no aux data, lets get address from the packet */
+
     ext_hdr_len = rxbuf[2] & 0x3F;
 
     ext_hdr_flags = rxbuf[3];
@@ -1937,19 +1958,6 @@ ble_ll_scan_get_addr_from_ext_adv(uint8_t *rxbuf, struct ble_mbuf_hdr *ble_hdr,
         *addr_type =
                 ble_ll_get_addr_type(rxbuf[0] & BLE_ADV_PDU_HDR_TXADD_MASK);
         i += BLE_LL_EXT_ADV_ADVA_SIZE;
-        if (aux_data) {
-            /* Lets copy addr to aux_data. Need it for e.g. chaining */
-            /* XXX add sanity checks */
-            memcpy(aux_data->addr, *addr, 6);
-            aux_data->addr_type = *addr_type;
-            aux_data->flags |= BLE_LL_AUX_HAS_ADDRA;
-        }
-    } else {
-        /* We should have address already in aux_data */
-        if (aux_data->flags & BLE_LL_AUX_HAS_ADDRA) {
-            *addr = aux_data->addr;
-            *addr_type = aux_data->addr_type;
-        }
     }
 
     if (!inita) {
@@ -1961,18 +1969,6 @@ ble_ll_scan_get_addr_from_ext_adv(uint8_t *rxbuf, struct ble_mbuf_hdr *ble_hdr,
         *inita_type =
                 ble_ll_get_addr_type(rxbuf[0] & BLE_ADV_PDU_HDR_RXADD_MASK);
         i += BLE_LL_EXT_ADV_TARGETA_SIZE;
-        if (aux_data) {
-            /* Lets copy addr to aux_data. Need it for e.g. chaining */
-            memcpy(aux_data->dir_addr, *inita, 6);
-            aux_data->dir_addr_type = *inita_type;
-            aux_data->flags |= BLE_LL_AUX_HAS_DIR_ADDRA;
-        }
-    } else {
-        /* We should have address already in aux_data */
-        if (aux_data->flags & BLE_LL_AUX_HAS_DIR_ADDRA) {
-            *inita = aux_data->dir_addr;
-            *inita_type = aux_data->dir_addr_type;
-        }
     }
 
     return 0;