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 2018/12/11 12:17:45 UTC

[GitHub] rymanluk closed pull request #261: nimble/ll: Qualification fixes related to privacy and directed advertising

rymanluk closed pull request #261: nimble/ll: Qualification fixes related to privacy and directed advertising
URL: https://github.com/apache/mynewt-nimble/pull/261
 
 
   

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/include/controller/ble_ll_conn.h b/nimble/controller/include/controller/ble_ll_conn.h
index 5d13b8d5..38289a0b 100644
--- a/nimble/controller/include/controller/ble_ll_conn.h
+++ b/nimble/controller/include/controller/ble_ll_conn.h
@@ -269,6 +269,12 @@ struct ble_ll_conn_sm
     uint32_t slave_cur_window_widening;
     uint32_t last_rxd_pdu_cputime;  /* Used exclusively for supervision timer */
 
+    /*
+     * Used to mark that direct advertising from the peer was using
+     * identity address as InitA
+     */
+    uint8_t inita_identity_used;
+
     /* address information */
     uint8_t own_addr_type;
     uint8_t peer_addr_type;
diff --git a/nimble/controller/src/ble_ll_conn.c b/nimble/controller/src/ble_ll_conn.c
index c960e729..abdd90c3 100644
--- a/nimble/controller/src/ble_ll_conn.c
+++ b/nimble/controller/src/ble_ll_conn.c
@@ -849,6 +849,8 @@ ble_ll_conn_init_wfr_timer_exp(void)
         STATS_INC(ble_ll_stats, aux_missed_adv);
         ble_ll_event_send(&scansm->scan_sched_ev);
     }
+
+    connsm->inita_identity_used = 0;
 #endif
 }
 /**
@@ -2684,10 +2686,14 @@ ble_ll_conn_event_end(struct ble_npl_event *ev)
  * @param m
  * @param adva
  * @param addr_type     Address type of ADVA from received advertisement.
+ * @param inita
+ * @param inita_type     Address type of INITA from received advertisement.
+
  * @param txoffset      The tx window offset for this connection
  */
 static void
 ble_ll_conn_req_pdu_update(struct os_mbuf *m, uint8_t *adva, uint8_t addr_type,
+                           uint8_t *inita, uint8_t inita_type,
                            uint16_t txoffset, int rpa_index)
 {
     uint8_t hdr;
@@ -2715,46 +2721,54 @@ ble_ll_conn_req_pdu_update(struct os_mbuf *m, uint8_t *adva, uint8_t addr_type,
 
     dptr = m->om_data;
 
-    /* Get pointer to our device address */
-    connsm = g_ble_ll_conn_create_sm;
-    if ((connsm->own_addr_type & 1) == 0) {
-        addr = g_dev_addr;
+    if (inita) {
+        memcpy(dptr, inita, BLE_DEV_ADDR_LEN);
+        if (inita_type) {
+            hdr |= BLE_ADV_PDU_HDR_TXADD_RAND;
+        }
     } else {
-        hdr |= BLE_ADV_PDU_HDR_TXADD_RAND;
-        addr = g_random_addr;
-    }
+        /* Get pointer to our device address */
+        connsm = g_ble_ll_conn_create_sm;
+        if ((connsm->own_addr_type & 1) == 0) {
+            addr = g_dev_addr;
+        } else {
+            hdr |= BLE_ADV_PDU_HDR_TXADD_RAND;
+            addr = g_random_addr;
+        }
 
     /* XXX: do this ahead of time? Calculate the local rpa I mean */
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY)
-    if (connsm->own_addr_type > BLE_HCI_ADV_OWN_ADDR_RANDOM) {
-        rl = NULL;
-        is_rpa = ble_ll_is_rpa(adva, addr_type);
-        if (is_rpa) {
-            if (rpa_index >= 0) {
-                rl = &g_ble_ll_resolv_list[rpa_index];
+        if (connsm->own_addr_type > BLE_HCI_ADV_OWN_ADDR_RANDOM) {
+            rl = NULL;
+            is_rpa = ble_ll_is_rpa(adva, addr_type);
+            if (is_rpa) {
+                if (rpa_index >= 0) {
+                    rl = &g_ble_ll_resolv_list[rpa_index];
+                }
+            } else {
+                if (ble_ll_resolv_enabled()) {
+                    rl = ble_ll_resolv_list_find(adva, addr_type);
+                }
             }
-        } else {
-            if (ble_ll_resolv_enabled()) {
-                rl = ble_ll_resolv_list_find(adva, addr_type);
+
+            /*
+             * If peer in on resolving list, we use RPA generated with Local IRK
+             * from resolving list entry. In other case, we need to use our identity
+             * address (see  Core 5.0, Vol 6, Part B, section 6.4).
+             */
+            if (rl) {
+                hdr |= BLE_ADV_PDU_HDR_TXADD_RAND;
+                ble_ll_resolv_get_priv_addr(rl, 1, dptr);
+                addr = NULL;
             }
         }
+#endif
 
-        /*
-         * If peer in on resolving list, we use RPA generated with Local IRK
-         * from resolving list entry. In other case, we need to use our identity
-         * address (see  Core 5.0, Vol 6, Part B, section 6.4).
-         */
-        if (rl) {
-            hdr |= BLE_ADV_PDU_HDR_TXADD_RAND;
-            ble_ll_resolv_get_priv_addr(rl, 1, dptr);
-            addr = NULL;
+        if (addr) {
+            memcpy(dptr, addr, BLE_DEV_ADDR_LEN);
         }
     }
-#endif
 
-    if (addr) {
-        memcpy(dptr, addr, BLE_DEV_ADDR_LEN);
-    }
     memcpy(dptr + BLE_DEV_ADDR_LEN, adva, BLE_DEV_ADDR_LEN);
     put_le16(dptr + 20, txoffset);
 
@@ -2875,7 +2889,9 @@ ble_ll_conn_req_txend_init(void *arg)
  * @param adva Address of advertiser
  */
 int
-ble_ll_conn_request_send(uint8_t addr_type, uint8_t *adva, uint16_t txoffset,
+ble_ll_conn_request_send(uint8_t addr_type, uint8_t *adva,
+                         uint8_t inita_type, uint8_t *inita,
+                         uint16_t txoffset,
                          int rpa_index, uint8_t end_trans)
 {
     struct os_mbuf *m;
@@ -2883,7 +2899,8 @@ ble_ll_conn_request_send(uint8_t addr_type, uint8_t *adva, uint16_t txoffset,
 
     /* XXX: TODO: assume we are already on correct phy */
     m = ble_ll_scan_get_pdu();
-    ble_ll_conn_req_pdu_update(m, adva, addr_type, txoffset, rpa_index);
+    ble_ll_conn_req_pdu_update(m, adva, addr_type, inita, inita_type,
+                               txoffset, rpa_index);
     if (end_trans == BLE_PHY_TRANSITION_NONE) {
         ble_phy_set_txend_cb(ble_ll_conn_req_txend, NULL);
     } else {
@@ -3433,6 +3450,7 @@ ble_ll_init_rx_isr_end(uint8_t *rxbuf, uint8_t crcok,
 
     /* Setup to transmit the connect request */
     rc = ble_ll_conn_request_send(addr_type, adv_addr,
+                                  init_addr_type, init_addr,
                                   connsm->tx_win_off, index,
                                   conn_req_end_trans);
     if (rc) {
@@ -3440,6 +3458,10 @@ ble_ll_init_rx_isr_end(uint8_t *rxbuf, uint8_t crcok,
         goto init_rx_isr_exit;
     }
 
+    if (init_addr && !inita_is_rpa) {
+        connsm->inita_identity_used = 1;
+    }
+
     CONN_F_CONN_REQ_TXD(connsm) = 1;
 
 #if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
diff --git a/nimble/controller/src/ble_ll_conn_hci.c b/nimble/controller/src/ble_ll_conn_hci.c
index 526bad00..7402895c 100644
--- a/nimble/controller/src/ble_ll_conn_hci.c
+++ b/nimble/controller/src/ble_ll_conn_hci.c
@@ -163,7 +163,13 @@ ble_ll_conn_comp_event_send(struct ble_ll_conn_sm *connsm, uint8_t status,
             if (enh_enabled) {
                 memset(evdata, 0, 2 * BLE_DEV_ADDR_LEN);
                 if (connsm->conn_role == BLE_LL_CONN_ROLE_MASTER) {
-                    if (connsm->own_addr_type > BLE_HCI_ADV_OWN_ADDR_RANDOM) {
+                    if (connsm->inita_identity_used) {
+                        /* If it was direct advertising we were replying to and we used
+                         * identity address there (which might be just fine), we should
+                         * we should take it into account here in this event.
+                         */
+                        rpa = NULL;
+                    } else  if (connsm->own_addr_type > BLE_HCI_ADV_OWN_ADDR_RANDOM) {
                         rpa = ble_ll_scan_get_local_rpa();
                     } else {
                         rpa = NULL;


 

----------------------------------------------------------------
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