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

[mynewt-nimble] branch master updated (eb6cdbc -> f0e8581)

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

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


    from eb6cdbc  nimble/ll: Fix handling LL_PHY_UPDATE_IND as a master
     new ad9914e  nimble/ll: Fix Connect Ind send on directed advertising
     new f0e8581  nimble/ll: Fix RPA address in the LE Enhanced Connection Complete

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 nimble/controller/include/controller/ble_ll_conn.h |  6 ++
 nimble/controller/src/ble_ll_conn.c                | 84 ++++++++++++++--------
 nimble/controller/src/ble_ll_conn_hci.c            |  8 ++-
 3 files changed, 66 insertions(+), 32 deletions(-)


[mynewt-nimble] 01/02: nimble/ll: Fix Connect Ind send on directed advertising

Posted by ry...@apache.org.
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 ad9914ed4952ffa34f7bd681cf6176b4aec0d1f4
Author: Łukasz Rymanowski <lu...@codecoup.pl>
AuthorDate: Fri Nov 30 16:06:38 2018 +0100

    nimble/ll: Fix Connect Ind send on directed advertising
    
    It solves following issue:
    
    Scenario:
    1. Nimble has peer device in the resolving list.
    2. Peer device is in Device Privacy Mode
    3. Peer device is using its RPA and our identity address as InitA in
    directed advertising
    
    Issue:
    Nimble send Connect Ind with its RPA instead of InitA
    
    This should fix: LL/CON/INI/BV-10-C and LL/CON/INI/BV-21-C
---
 nimble/controller/src/ble_ll_conn.c | 78 ++++++++++++++++++++++---------------
 1 file changed, 47 insertions(+), 31 deletions(-)

diff --git a/nimble/controller/src/ble_ll_conn.c b/nimble/controller/src/ble_ll_conn.c
index c960e72..a528b7b 100644
--- a/nimble/controller/src/ble_ll_conn.c
+++ b/nimble/controller/src/ble_ll_conn.c
@@ -2684,10 +2684,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 +2719,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 +2887,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 +2897,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 +3448,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) {


[mynewt-nimble] 02/02: nimble/ll: Fix RPA address in the LE Enhanced Connection Complete

Posted by ry...@apache.org.
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 f0e85818f503f6fc680949721e35dc31b8ea0d4f
Author: Łukasz Rymanowski <lu...@codecoup.pl>
AuthorDate: Wed Dec 5 10:57:02 2018 +0100

    nimble/ll: Fix RPA address in the LE Enhanced Connection Complete
    
    It solves following issue:
    
    Scenario:
    1. Nimble has peer device in the resolving list.
    2. Peer device is in Device Privacy Mode
    3. Peer device is using its RPA and our identity address as InitA in
    directed advertising on which Nimble send Connect Ind with its identity address
    
    Issue:
    Nimble incorretly set Local RPA address in the LE Enhanced Connect Completed event.
    
    This should fix: LL/CON/INI/BV-10-C and LL/CON/INI/BV-21-C
---
 nimble/controller/include/controller/ble_ll_conn.h | 6 ++++++
 nimble/controller/src/ble_ll_conn.c                | 6 ++++++
 nimble/controller/src/ble_ll_conn_hci.c            | 8 +++++++-
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/nimble/controller/include/controller/ble_ll_conn.h b/nimble/controller/include/controller/ble_ll_conn.h
index 5d13b8d..38289a0 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 a528b7b..abdd90c 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
 }
 /**
@@ -3456,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 526bad0..7402895 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;