You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ja...@apache.org on 2019/12/20 08:36:50 UTC

[mynewt-nimble] branch master updated (00d95a4 -> d26fd0e)

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

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


    from 00d95a4  nimble/ble_store: Fix assert when BLE_HS_DEBUG is enabled
     new 7b2993f  nimble/ll: Use flags for tracking IRKs presence in RL
     new 9bb8e07  nimble/ll: Use RPA regardless of address resolution state
     new b6f1b7e  nimble/ll: Use RPA regardless of address resolution state when scanning
     new d26fd0e  nimble/ll: Run RPA timer when resolving list is used

The 4 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:
 .../controller/include/controller/ble_ll_resolv.h  |  13 ++-
 nimble/controller/src/ble_ll_adv.c                 |   2 +-
 nimble/controller/src/ble_ll_conn.c                |  19 ++--
 nimble/controller/src/ble_ll_resolv.c              | 110 ++++++++++++---------
 nimble/controller/src/ble_ll_scan.c                |  10 +-
 5 files changed, 87 insertions(+), 67 deletions(-)


[mynewt-nimble] 04/04: nimble/ll: Run RPA timer when resolving list is used

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit d26fd0e43f8b1b302171e57c1859d2366fe6ebba
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Wed Dec 18 11:49:25 2019 +0100

    nimble/ll: Run RPA timer when resolving list is used
    
    This timer is use for RPA generation and is not related to address
    resolution enable state. If there is something on RL we keep timer
    running.
---
 nimble/controller/src/ble_ll_resolv.c | 43 +++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 20 deletions(-)

diff --git a/nimble/controller/src/ble_ll_resolv.c b/nimble/controller/src/ble_ll_resolv.c
index c8d7bfb..02af930 100644
--- a/nimble/controller/src/ble_ll_resolv.c
+++ b/nimble/controller/src/ble_ll_resolv.c
@@ -39,7 +39,7 @@ struct ble_ll_resolv_data
     uint8_t rl_size;
     uint8_t rl_cnt_hw;
     uint8_t rl_cnt;
-    uint32_t rpa_tmo;
+    ble_npl_time_t rpa_tmo;
     struct ble_npl_callout rpa_timer;
 };
 struct ble_ll_resolv_data g_ble_ll_resolv_data;
@@ -151,8 +151,9 @@ ble_ll_resolv_rpa_timer_cb(struct ble_npl_event *ev)
         }
         ++rl;
     }
+
     ble_npl_callout_reset(&g_ble_ll_resolv_data.rpa_timer,
-                     (int32_t)g_ble_ll_resolv_data.rpa_tmo);
+                          g_ble_ll_resolv_data.rpa_tmo);
 
     ble_ll_adv_rpa_timeout();
 }
@@ -200,6 +201,9 @@ ble_ll_resolv_list_clr(void)
     g_ble_ll_resolv_data.rl_cnt = 0;
     ble_hw_resolv_list_clear();
 
+    /* stop RPA timer when clearing RL */
+    ble_npl_callout_stop(&g_ble_ll_resolv_data.rpa_timer);
+
     return BLE_ERR_SUCCESS;
 }
 
@@ -358,6 +362,12 @@ ble_ll_resolv_list_add(const uint8_t *cmdbuf, uint8_t len)
 
     g_ble_ll_resolv_data.rl_cnt++;
 
+    /* start RPA timer if this was first element added to RL */
+    if (g_ble_ll_resolv_data.rl_cnt == 1) {
+        ble_npl_callout_reset(&g_ble_ll_resolv_data.rpa_timer,
+                              g_ble_ll_resolv_data.rpa_tmo);
+    }
+
     return rc;
 }
 
@@ -399,6 +409,12 @@ ble_ll_resolv_list_rmv(const uint8_t *cmdbuf, uint8_t len)
             ble_hw_resolv_list_rmv(position - 1);
             g_ble_ll_resolv_data.rl_cnt_hw--;
         }
+
+        /* stop RPA timer if list is empty */
+        if (g_ble_ll_resolv_data.rl_cnt == 0) {
+            ble_npl_callout_stop(&g_ble_ll_resolv_data.rpa_timer);
+        }
+
         return BLE_ERR_SUCCESS;
     }
 
@@ -416,7 +432,6 @@ int
 ble_ll_resolv_enable_cmd(const uint8_t *cmdbuf, uint8_t len)
 {
     const struct ble_hci_le_set_addr_res_en_cp *cmd = (const void *) cmdbuf;
-    int32_t tmo;
 
     if (len != sizeof(*cmd)) {
         return BLE_ERR_INV_HCI_CMD_PARMS;
@@ -431,16 +446,7 @@ ble_ll_resolv_enable_cmd(const uint8_t *cmdbuf, uint8_t len)
         return BLE_ERR_INV_HCI_CMD_PARMS;
     }
 
-    /* If we change state, we need to disable/enable the RPA timer */
-    if ((cmd->enable ^ g_ble_ll_resolv_data.addr_res_enabled) != 0) {
-        if (cmd->enable) {
-            tmo = (int32_t)g_ble_ll_resolv_data.rpa_tmo;
-            ble_npl_callout_reset(&g_ble_ll_resolv_data.rpa_timer, tmo);
-        } else {
-            ble_npl_callout_stop(&g_ble_ll_resolv_data.rpa_timer);
-        }
-        g_ble_ll_resolv_data.addr_res_enabled = cmd->enable;
-    }
+    g_ble_ll_resolv_data.addr_res_enabled = cmd->enable;
 
     return BLE_ERR_SUCCESS;
 }
@@ -521,15 +527,12 @@ ble_ll_resolv_set_rpa_tmo(const uint8_t *cmdbuf, uint8_t len)
 
     g_ble_ll_resolv_data.rpa_tmo = ble_npl_time_ms_to_ticks32(tmo_secs * 1000);
 
-    /* If resolving is not enabled, we are done here. */
-    if (!ble_ll_resolv_enabled()) {
-        return BLE_ERR_SUCCESS;
+    /* restart timer if there is something on RL */
+    if (g_ble_ll_resolv_data.rl_cnt) {
+        ble_npl_callout_reset(&g_ble_ll_resolv_data.rpa_timer,
+                              g_ble_ll_resolv_data.rpa_tmo);
     }
 
-    /* Reset timeout if resolving is enabled */
-    ble_npl_callout_reset(&g_ble_ll_resolv_data.rpa_timer,
-                     (int32_t)g_ble_ll_resolv_data.rpa_tmo);
-
     return BLE_ERR_SUCCESS;
 }
 


[mynewt-nimble] 03/04: nimble/ll: Use RPA regardless of address resolution state when scanning

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit b6f1b7eef892535144277b69e9e741fea7c51eb9
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Wed Dec 18 11:35:04 2019 +0100

    nimble/ll: Use RPA regardless of address resolution state when scanning
    
    When scanning and local IRK is present we should use RPA regardless
    of address resolution state (as this controls peer's address resolution
    not local RPA generation).
---
 nimble/controller/src/ble_ll_scan.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c
index d0ca915..0330081 100644
--- a/nimble/controller/src/ble_ll_scan.c
+++ b/nimble/controller/src/ble_ll_scan.c
@@ -353,9 +353,11 @@ ble_ll_scan_req_pdu_prepare(struct ble_ll_scan_sm *scansm, uint8_t *adv_addr,
                 rl = &g_ble_ll_resolv_list[rpa_index];
             }
         } else {
-            if (ble_ll_resolv_enabled()) {
-                rl = ble_ll_resolv_list_find(adv_addr, adv_addr_type);
-            }
+            /* we look for RL entry to generate local RPA regardless if
+             * resolving is enabled or not (as this is is for local RPA
+             * not peer RPA)
+             */
+            rl = ble_ll_resolv_list_find(adv_addr, adv_addr_type);
         }
 
         /*


[mynewt-nimble] 01/04: nimble/ll: Use flags for tracking IRKs presence in RL

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 7b2993fd9f3c322f763f9129c151e7756b2a2881
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Wed Dec 18 11:19:27 2019 +0100

    nimble/ll: Use flags for tracking IRKs presence in RL
    
    This makes sure we won't be generating RPAs from all zero IRKs.
---
 .../controller/include/controller/ble_ll_resolv.h  | 13 +++--
 nimble/controller/src/ble_ll_adv.c                 |  2 +-
 nimble/controller/src/ble_ll_conn.c                | 11 ++--
 nimble/controller/src/ble_ll_resolv.c              | 67 +++++++++++++---------
 nimble/controller/src/ble_ll_scan.c                |  2 +-
 5 files changed, 54 insertions(+), 41 deletions(-)

diff --git a/nimble/controller/include/controller/ble_ll_resolv.h b/nimble/controller/include/controller/ble_ll_resolv.h
index f9dc397..228e0a3 100644
--- a/nimble/controller/include/controller/ble_ll_resolv.h
+++ b/nimble/controller/include/controller/ble_ll_resolv.h
@@ -29,13 +29,16 @@ extern "C" {
  *      The identity address is stored in little endian format.
  *      The local rpa is stored in little endian format.
  *      The IRKs are stored in big endian format.
+ *
+ *  Note:
+ *  rl_local_irk and rl_peer_irk need to be word aligned
  */
 struct ble_ll_resolv_entry
 {
     uint8_t rl_addr_type;
-    uint8_t rl_reserved;
     uint8_t rl_priv_mode;
-    uint8_t _pad;
+    uint8_t rl_has_local;
+    uint8_t rl_has_peer;
     uint8_t rl_local_irk[16];
     uint8_t rl_peer_irk[16];
     uint8_t rl_identity_addr[BLE_DEV_ADDR_LEN];
@@ -69,15 +72,15 @@ int ble_ll_resolv_local_addr_rd(const uint8_t *cmdbuf, uint8_t len,
 struct ble_ll_resolv_entry *
 ble_ll_resolv_list_find(const uint8_t *addr, uint8_t addr_type);
 
-/* Called to determine if the IRK is all zero. */
-int ble_ll_resolv_irk_nonzero(const uint8_t *irk);
-
 /* Returns true if address resolution is enabled */
 uint8_t ble_ll_resolv_enabled(void);
 
 /* Reset private address resolution */
 void ble_ll_resolv_list_reset(void);
 
+/* Generate local or peer RPA. It is up to caller to make sure required IRK
+ * is present on RL
+ */
 void ble_ll_resolv_get_priv_addr(struct ble_ll_resolv_entry *rl, int local,
                                  uint8_t *addr);
 
diff --git a/nimble/controller/src/ble_ll_adv.c b/nimble/controller/src/ble_ll_adv.c
index 22cd559..2c8363e 100644
--- a/nimble/controller/src/ble_ll_adv.c
+++ b/nimble/controller/src/ble_ll_adv.c
@@ -4022,7 +4022,7 @@ ble_ll_adv_rx_req(uint8_t pdu_type, struct os_mbuf *rxpdu)
             /* Verify privacy mode */
             rl = ble_ll_resolv_list_find(peer, peer_addr_type);
             if (rl && (rl->rl_priv_mode == BLE_HCI_PRIVACY_NETWORK) &&
-                                ble_ll_resolv_irk_nonzero(rl->rl_peer_irk)) {
+                rl->rl_has_peer) {
                 return -1;
             }
         }
diff --git a/nimble/controller/src/ble_ll_conn.c b/nimble/controller/src/ble_ll_conn.c
index 98fe9b7..b578ab7 100644
--- a/nimble/controller/src/ble_ll_conn.c
+++ b/nimble/controller/src/ble_ll_conn.c
@@ -2579,7 +2579,7 @@ ble_ll_conn_connect_ind_prepare(struct ble_ll_conn_sm *connsm,
              * 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) {
+            if (rl && rl->rl_has_local) {
                 hdr |= BLE_ADV_PDU_HDR_TXADD_RAND;
                 ble_ll_resolv_get_priv_addr(rl, 1, pdu_data->inita);
                 addr = NULL;
@@ -2634,7 +2634,7 @@ ble_ll_conn_is_peer_adv(uint8_t addr_type, uint8_t *adva, int index)
             if (ble_ll_resolv_enabled()) {
                 rl = ble_ll_resolv_list_find(adva, addr_type);
                 if (rl && (rl->rl_priv_mode == BLE_HCI_PRIVACY_NETWORK) &&
-                        ble_ll_resolv_irk_nonzero(rl->rl_peer_irk)) {
+                    rl->rl_has_peer) {
                     return 0;
                 }
             }
@@ -3165,9 +3165,8 @@ ble_ll_init_rx_isr_end(uint8_t *rxbuf, uint8_t crcok,
             resolved = 1;
 
             /* Assure privacy */
-            if ((rl->rl_priv_mode == BLE_HCI_PRIVACY_NETWORK) &&
-                                        init_addr && !inita_is_rpa &&
-                                        ble_ll_resolv_irk_nonzero(rl->rl_local_irk)) {
+            if ((rl->rl_priv_mode == BLE_HCI_PRIVACY_NETWORK) && init_addr &&
+                !inita_is_rpa && rl->rl_has_local) {
                 goto init_rx_isr_exit;
             }
 
@@ -3216,7 +3215,7 @@ ble_ll_init_rx_isr_end(uint8_t *rxbuf, uint8_t crcok,
          */
         if (rl && !inita_is_rpa &&
            (rl->rl_priv_mode == BLE_HCI_PRIVACY_NETWORK) &&
-            ble_ll_resolv_irk_nonzero(rl->rl_local_irk)) {
+           rl->rl_has_local) {
             goto init_rx_isr_exit;
         }
 
diff --git a/nimble/controller/src/ble_ll_resolv.c b/nimble/controller/src/ble_ll_resolv.c
index c35cc33..c8d7bfb 100644
--- a/nimble/controller/src/ble_ll_resolv.c
+++ b/nimble/controller/src/ble_ll_resolv.c
@@ -138,13 +138,17 @@ ble_ll_resolv_rpa_timer_cb(struct ble_npl_event *ev)
 
     rl = &g_ble_ll_resolv_list[0];
     for (i = 0; i < g_ble_ll_resolv_data.rl_cnt; ++i) {
-        OS_ENTER_CRITICAL(sr);
-        ble_ll_resolv_gen_priv_addr(rl, 1);
-        OS_EXIT_CRITICAL(sr);
+        if (rl->rl_has_local) {
+            OS_ENTER_CRITICAL(sr);
+            ble_ll_resolv_gen_priv_addr(rl, 1);
+            OS_EXIT_CRITICAL(sr);
+        }
 
-        OS_ENTER_CRITICAL(sr);
-        ble_ll_resolv_gen_priv_addr(rl, 0);
-        OS_EXIT_CRITICAL(sr);
+        if (rl->rl_has_peer) {
+            OS_ENTER_CRITICAL(sr);
+            ble_ll_resolv_gen_priv_addr(rl, 0);
+            OS_EXIT_CRITICAL(sr);
+        }
         ++rl;
     }
     ble_npl_callout_reset(&g_ble_ll_resolv_data.rpa_timer,
@@ -160,7 +164,7 @@ ble_ll_resolv_rpa_timer_cb(struct ble_npl_event *ev)
  *
  * @return int 0: IRK is zero . 1: IRK has non-zero value.
  */
-int
+static int
 ble_ll_resolv_irk_nonzero(const uint8_t *irk)
 {
     int i;
@@ -319,28 +323,41 @@ ble_ll_resolv_list_add(const uint8_t *cmdbuf, uint8_t len)
     memset (rl, 0, sizeof(*rl));
     rl->rl_addr_type = cmd->peer_addr_type;
     memcpy(rl->rl_identity_addr, cmd->peer_id_addr, BLE_DEV_ADDR_LEN);
-    swap_buf(rl->rl_peer_irk, cmd->peer_irk, 16);
-    swap_buf(rl->rl_local_irk, cmd->local_irk, 16);
+
+    if (ble_ll_resolv_irk_nonzero(cmd->peer_irk)) {
+        swap_buf(rl->rl_peer_irk, cmd->peer_irk, 16);
+        rl->rl_has_peer = 1;
+
+        /* generate peer RPA now, those will be updated by timer when
+         * resolution is enabled
+         */
+        ble_ll_resolv_gen_priv_addr(rl, 0);
+    }
+
+    if (ble_ll_resolv_irk_nonzero(cmd->local_irk)) {
+        swap_buf(rl->rl_local_irk, cmd->local_irk, 16);
+        rl->rl_has_local = 1;
+
+        /* generate local RPA now, those will be updated by timer when
+         * resolution is enabled
+         */
+        ble_ll_resolv_gen_priv_addr(rl, 1);
+    }
 
     /* By default use privacy network mode */
     rl->rl_priv_mode = BLE_HCI_PRIVACY_NETWORK;
 
-    /* generate a local and peer RPAs now, those will be updated by timer
-     * when resolution is enabled
-     */
-    ble_ll_resolv_gen_priv_addr(rl, 1);
-    ble_ll_resolv_gen_priv_addr(rl, 0);
-    g_ble_ll_resolv_data.rl_cnt++;
-
     /* Add peers IRKs to HW resolving list. Should always succeed since we
      * already checked if there is room for it.
      */
-    if (ble_ll_resolv_irk_nonzero(cmd->peer_irk)) {
+    if (rl->rl_has_peer) {
         rc = ble_hw_resolv_list_add(rl->rl_peer_irk);
         BLE_LL_ASSERT(rc == BLE_ERR_SUCCESS);
         g_ble_ll_resolv_data.rl_cnt_hw++;
     }
 
+    g_ble_ll_resolv_data.rl_cnt++;
+
     return rc;
 }
 
@@ -567,8 +584,10 @@ ble_ll_resolv_get_priv_addr(struct ble_ll_resolv_entry *rl, int local,
 
     OS_ENTER_CRITICAL(sr);
     if (local) {
+        BLE_LL_ASSERT(rl->rl_has_local);
         memcpy(addr, rl->rl_local_rpa, BLE_DEV_ADDR_LEN);
     } else {
+        BLE_LL_ASSERT(rl->rl_has_peer);
         memcpy(addr, rl->rl_peer_rpa, BLE_DEV_ADDR_LEN);
     }
 
@@ -611,25 +630,17 @@ ble_ll_resolv_set_local_rpa(int index, uint8_t *rpa)
 int
 ble_ll_resolv_gen_rpa(uint8_t *addr, uint8_t addr_type, uint8_t *rpa, int local)
 {
-    int rc;
-    uint8_t *irk;
     struct ble_ll_resolv_entry *rl;
 
-    rc = 0;
     rl = ble_ll_resolv_list_find(addr, addr_type);
     if (rl) {
-        if (local) {
-            irk = rl->rl_local_irk;
-        } else {
-            irk = rl->rl_peer_irk;
-        }
-        if (ble_ll_resolv_irk_nonzero(irk)) {
+        if ((local && rl->rl_has_local) || (!local && rl->rl_has_peer)) {
             ble_ll_resolv_get_priv_addr(rl, local, rpa);
-            rc = 1;
+            return 1;
         }
     }
 
-    return rc;
+    return 0;
 }
 
 /**
diff --git a/nimble/controller/src/ble_ll_scan.c b/nimble/controller/src/ble_ll_scan.c
index 150ac33..d0ca915 100644
--- a/nimble/controller/src/ble_ll_scan.c
+++ b/nimble/controller/src/ble_ll_scan.c
@@ -365,7 +365,7 @@ ble_ll_scan_req_pdu_prepare(struct ble_ll_scan_sm *scansm, uint8_t *adv_addr,
          * being tracked when doing an active scan (see Core 5.0, Vol 6, Part B,
          * section 6.3).
          */
-        if (rl) {
+        if (rl && rl->rl_has_local) {
             ble_ll_resolv_get_priv_addr(rl, 1, rpa);
             scana = rpa;
         } else {


[mynewt-nimble] 02/04: nimble/ll: Use RPA regardless of address resolution state

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 9bb8e07b130897b6b68f6e36a8d246cff1bda908
Author: Szymon Janc <sz...@codecoup.pl>
AuthorDate: Wed Dec 18 11:23:29 2019 +0100

    nimble/ll: Use RPA regardless of address resolution state
    
    When initiating and local IRK is present we should use RPA regardless
    of address resolution state (as this controls peer's address resolution
    not local RPA generation).
    
    This was affecting LL/CON/INI/BV-23-C qualification testcase.
---
 nimble/controller/src/ble_ll_conn.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/nimble/controller/src/ble_ll_conn.c b/nimble/controller/src/ble_ll_conn.c
index b578ab7..fab8495 100644
--- a/nimble/controller/src/ble_ll_conn.c
+++ b/nimble/controller/src/ble_ll_conn.c
@@ -2569,9 +2569,11 @@ ble_ll_conn_connect_ind_prepare(struct ble_ll_conn_sm *connsm,
                     rl = &g_ble_ll_resolv_list[rpa_index];
                 }
             } else {
-                if (ble_ll_resolv_enabled()) {
-                    rl = ble_ll_resolv_list_find(adva, adva_type);
-                }
+                /* we look for RL entry to generate local RPA regardless if
+                 * resolving is enabled or not (as this is is for local RPA
+                 * not peer RPA)
+                 */
+                 rl = ble_ll_resolv_list_find(adva, adva_type);
             }
 
             /*