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 291d1b4b626a91828893e1b499085428966c5dc4
Author: Ɓukasz Rymanowski <lukasz.rymanow...@codecoup.pl>
AuthorDate: Fri Jan 11 13:26:59 2019 +0100

    nimble/ll: Fix address types in the advertising report
    
    This patch makes sure that corret address type is used in the
    advertising report when RPA addresses has been used over the air.
    
    This fixes LL/DDI/SCN/BV-33-C
---
 nimble/controller/src/ble_ll_scan.c | 41 ++++++++++++++++++++++++++++---------
 nimble/include/nimble/ble.h         |  4 ++++
 2 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/nimble/controller/src/ble_ll_scan.c 
b/nimble/controller/src/ble_ll_scan.c
index 4f25bd7..dca7031 100644
--- a/nimble/controller/src/ble_ll_scan.c
+++ b/nimble/controller/src/ble_ll_scan.c
@@ -929,14 +929,15 @@ ble_ll_scan_send_adv_report(uint8_t pdu_type, uint8_t 
*adva, uint8_t adva_type,
     }
 
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY)
+    /* If RPA has been used, make sure we use correct address types
+     * in the advertising report.
+     */
     if (BLE_MBUF_HDR_RESOLVED(hdr)) {
-        /*
-         * NOTE: this looks a bit odd, but the resolved address types
-         * are 2 greater than the unresolved ones in the spec, so
-         * we just add 2 here.
-         */
         adva_type += 2;
     }
+    if (BLE_MBUF_HDR_INITA_RESOLVED(hdr)) {
+        inita_type += 2;
+    }
 #endif
 
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
@@ -2412,9 +2413,11 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t 
crcok)
                 peer = g_ble_ll_resolv_list[index].rl_identity_addr;
                 peer_addr_type = g_ble_ll_resolv_list[index].rl_addr_type;
                 resolved = 1;
-                if (ble_ll_is_rpa(inita, inita_type) &&
-                    !ble_ll_resolv_rpa(inita, 
g_ble_ll_resolv_list[index].rl_local_irk)) {
-                    goto scan_rx_isr_exit;
+                if (ble_ll_is_rpa(inita, inita_type)) {
+                    if (!ble_ll_resolv_rpa(inita, 
g_ble_ll_resolv_list[index].rl_local_irk)) {
+                        goto scan_rx_isr_exit;
+                    }
+                    ble_hdr->rxinfo.flags |= BLE_MBUF_HDR_F_INITA_RESOLVED;
                 }
             } else {
                 if (chk_wl) {
@@ -2426,13 +2429,19 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t 
crcok)
                 }
             }
         } else if (chk_send_req && inita && ble_ll_is_rpa(inita, inita_type)) {
-            /* If remove is identity address but InitA is RPA, make sure we 
can resolve it.
+            /* If remote is identity address but InitA is RPA, make sure we 
can resolve it.
              * If not, nothing more to do here
              */
             rl = ble_ll_resolv_list_find(peer, peer_addr_type);
-            if (!rl || !ble_ll_resolv_rpa(inita, rl->rl_local_irk)) {
+            if (!rl) {
+                goto scan_rx_isr_exit;
+            }
+
+            if (!ble_ll_resolv_rpa(inita, rl->rl_local_irk)) {
                 goto scan_rx_isr_exit;
             }
+
+            ble_hdr->rxinfo.flags |= BLE_MBUF_HDR_F_INITA_RESOLVED;
         }
     }
 #else
@@ -2658,6 +2667,18 @@ ble_ll_hci_send_ext_adv_report(uint8_t ptype, uint8_t 
*adva, uint8_t adva_type,
         }
     }
 
+#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY)
+    /* If RPA has been used, make sure we use correct address types
+     * in the advertising report.
+     */
+    if (BLE_MBUF_HDR_RESOLVED(hdr)) {
+        adva_type += 2;
+    }
+    if (BLE_MBUF_HDR_INITA_RESOLVED(hdr)) {
+        inita_type += 2;
+    }
+#endif
+
     datalen = ble_ll_scan_parse_ext_hdr(om, adva, adva_type, inita, 
inita_type, hdr, evt);
     if (datalen < 0) {
         /* XXX what should we do here? send some trimmed event? */
diff --git a/nimble/include/nimble/ble.h b/nimble/include/nimble/ble.h
index d76603b..703c6dc 100644
--- a/nimble/include/nimble/ble.h
+++ b/nimble/include/nimble/ble.h
@@ -76,6 +76,7 @@ struct ble_mbuf_hdr_rxinfo
 };
 
 /* Flag definitions for rxinfo  */
+#define BLE_MBUF_HDR_F_INITA_RESOLVED   (0x2000)
 #define BLE_MBUF_HDR_F_EXT_ADV_SEC      (0x1000)
 #define BLE_MBUF_HDR_F_EXT_ADV          (0x0800)
 #define BLE_MBUF_HDR_F_RESOLVED         (0x0400)
@@ -134,6 +135,9 @@ struct ble_mbuf_hdr
 #define BLE_MBUF_HDR_RESOLVED(hdr)      \
     (!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_RESOLVED))
 
+#define BLE_MBUF_HDR_INITA_RESOLVED(hdr)      \
+    (!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_INITA_RESOLVED))
+
 #define BLE_MBUF_HDR_RX_STATE(hdr)      \
     ((uint8_t)((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_RXSTATE_MASK))
 

Reply via email to