You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2019/01/08 13:11:20 UTC

[GitHub] rymanluk closed pull request #281: nimble/ll: Couple of extended scanner fixes

rymanluk closed pull request #281: nimble/ll: Couple of extended scanner fixes
URL: https://github.com/apache/mynewt-nimble/pull/281
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c
index 87493049..ad5f2038 100644
--- a/nimble/controller/src/ble_ll_scan.c
+++ b/nimble/controller/src/ble_ll_scan.c
@@ -471,7 +471,7 @@ ble_ll_scan_send_truncated_if_chained(struct ble_ll_aux_data *aux_data)
         }
     }
 
-    evt->event_len = sizeof(*evt);
+    evt->event_len = sizeof(*evt) - BLE_HCI_EVENT_HDR_LEN;
     evt->evt_type = aux_data->evt_type;
     evt->evt_type |= (BLE_HCI_ADV_DATA_STATUS_TRUNCATED);
     BLE_LL_SET_AUX_FLAG(aux_data, BLE_LL_AUX_TRUNCATED_SENT);
@@ -748,13 +748,11 @@ ble_ll_hci_send_legacy_ext_adv_report(uint8_t evtype,
     evt->addr_type = addr_type;
     memcpy(evt->addr, addr, BLE_DEV_ADDR_LEN);
 
-    evt->event_len = sizeof(*evt);
+    evt->event_len = sizeof(*evt) - BLE_HCI_EVENT_HDR_LEN;
 
     if (inita) {
-        /* TODO Really ?? */
         evt->dir_addr_type = inita_type;
         memcpy(evt->dir_addr, inita, BLE_DEV_ADDR_LEN);
-        evt->event_len += BLE_DEV_ADDR_LEN  + 1;
     } else if (adv_data_len <= (MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE) - sizeof(*evt))) {
         evt->adv_data_len = adv_data_len;
         os_mbuf_copydata(adv_data, 0, adv_data_len, evt->adv_data);
@@ -2206,6 +2204,8 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok)
     uint8_t peer_addr_type = 0;
     uint8_t *adv_addr = NULL;
     uint8_t *peer = NULL;
+    uint8_t *inita = NULL;
+    uint8_t inita_type = 0;
     uint8_t *rxbuf;
     struct ble_mbuf_hdr *ble_hdr;
     struct ble_ll_scan_sm *scansm;
@@ -2215,6 +2215,9 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok)
     uint8_t phy_mode;
     uint16_t adi;
 #endif
+#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY)
+    struct ble_ll_resolv_entry *rl = NULL;
+#endif
 
     /* Get scanning state machine */
     scansm = &g_ble_ll_scan_sm;
@@ -2290,7 +2293,7 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok)
     /* Lets get addresses from advertising report*/
     if (ble_ll_scan_adv_decode_addr(pdu_type, rxbuf, ble_hdr,
                                     &peer, &peer_addr_type,
-                                    NULL, NULL, &ext_adv_mode)) {
+                                    &inita, &inita_type, &ext_adv_mode)) {
         goto scan_rx_isr_exit;
     }
 
@@ -2340,19 +2343,41 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok)
 
     index = -1;
 #if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1)
-    if (ble_ll_is_rpa(peer, peer_addr_type) && ble_ll_resolv_enabled()) {
-        index = ble_hw_resolv_list_match();
-        if (index >= 0) {
-            ble_hdr->rxinfo.flags |= BLE_MBUF_HDR_F_RESOLVED;
-            peer = g_ble_ll_resolv_list[index].rl_identity_addr;
-            peer_addr_type = g_ble_ll_resolv_list[index].rl_addr_type;
-            resolved = 1;
-        } else {
-            if (chk_wl) {
+    if (ble_ll_resolv_enabled()) {
+        if (ble_ll_is_rpa(peer, peer_addr_type)) {
+            index = ble_hw_resolv_list_match();
+            if (index >= 0) {
+                ble_hdr->rxinfo.flags |= BLE_MBUF_HDR_F_RESOLVED;
+                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;
+                }
+            } else {
+                if (chk_wl) {
+                    goto scan_rx_isr_exit;
+                }
+                /* We don't know peer and InitA is RPA so nothing to do more here */
+                if (chk_send_req && inita && ble_ll_is_rpa(inita, inita_type)) {
+                    goto scan_rx_isr_exit;
+                }
+            }
+        } 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 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)) {
                 goto scan_rx_isr_exit;
             }
         }
     }
+#else
+    if (chk_send_req && inita && ble_ll_is_rpa(inita, inita_type)) {
+        goto scan_rx_isr_exit;
+    }
 #endif
     scansm->scan_rpa_index = index;
 
@@ -2366,6 +2391,14 @@ ble_ll_scan_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok)
     if (chk_send_req) {
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
         if (pdu_type == BLE_ADV_PDU_TYPE_ADV_EXT_IND) {
+            /* Let us check if InitA is our device.
+             * Note that InitA RPA is handled above where privacy is handled
+             */
+            if (inita && !ble_ll_is_rpa(inita, inita_type) &&
+                         !ble_ll_is_our_devaddr(inita, inita_type)) {
+                goto scan_rx_isr_exit;
+            }
+
             if (ble_ll_scan_get_adi(ble_hdr->rxinfo.user_data, &adi) < 0) {
                 /* There is not ADI in scannable packet? This must be some trash,
                  * ignore it
@@ -2541,7 +2574,7 @@ ble_ll_hci_send_ext_adv_report(uint8_t ptype, uint8_t *adva, uint8_t adva_type,
     int datalen;
     int rc;
     bool need_event;
-    uint8_t max_event_len;
+    uint16_t max_event_len;
 
     if (!ble_ll_hci_is_le_event_enabled(BLE_HCI_LE_SUBEV_EXT_ADV_RPT)) {
         rc = -1;
@@ -2572,8 +2605,11 @@ ble_ll_hci_send_ext_adv_report(uint8_t ptype, uint8_t *adva, uint8_t adva_type,
         goto done;
     }
 
+    /* Max_event_len contains advertising data and BLE_HCI_EVENT_HDR_LEN as this is related
+     * to the buffer available for the event. The maximum is 255 + 2
+     */
     offset = 0;
-    max_event_len = min(UINT8_MAX, BLE_LL_MAX_EVT_LEN);
+    max_event_len = min(UINT8_MAX + BLE_HCI_EVENT_HDR_LEN, BLE_LL_MAX_EVT_LEN);
 
     do {
         need_event = false;
@@ -2734,7 +2770,7 @@ ble_ll_scan_rx_pkt_in(uint8_t ptype, struct os_mbuf *om, struct ble_mbuf_hdr *hd
            /* Let's try resolve InitA. */
            if (ble_ll_resolv_rpa(init_addr, g_ble_ll_resolv_list[index].rl_local_irk)) {
                init_addr = ble_ll_get_our_devaddr(scansm->own_addr_type & 1);
-               init_addr_type = scansm->own_addr_type;
+               init_addr_type = scansm->own_addr_type & 1;
            }
        }
     } else if (init_addr && ble_ll_resolv_enabled() && ble_ll_is_rpa(init_addr, init_addr_type)) {
@@ -2742,7 +2778,7 @@ ble_ll_scan_rx_pkt_in(uint8_t ptype, struct os_mbuf *om, struct ble_mbuf_hdr *hd
         rl = ble_ll_resolv_list_find(ident_addr, ident_addr_type);
         if (rl && ble_ll_resolv_rpa(init_addr, rl->rl_local_irk)) {
             init_addr = ble_ll_get_our_devaddr(scansm->own_addr_type & 1);
-            init_addr_type = scansm->own_addr_type;
+            init_addr_type = scansm->own_addr_type & 1;
         }
     }
 #endif


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services