You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by an...@apache.org on 2017/04/07 08:49:31 UTC

[2/6] incubator-mynewt-core git commit: nimble/controller: Add support for handling privacy modes

nimble/controller: Add support for handling privacy modes

With this patch nimble controller supports network and device
privacy mode as per Bluetooth 5.0 Vol 6, Part B, chapter 4.7

Host can set privacy mode using LE set privacy mode command.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/ac7b489a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ac7b489a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ac7b489a

Branch: refs/heads/bluetooth5
Commit: ac7b489a693accf3abe98628a9395e13f69f2c71
Parents: 0c627e2
Author: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Authored: Wed Apr 5 15:33:30 2017 +0200
Committer: \u0141ukasz Rymanowski <lu...@codecoup.pl>
Committed: Thu Apr 6 09:42:07 2017 +0200

----------------------------------------------------------------------
 .../include/controller/ble_ll_resolv.h          |  6 +++-
 net/nimble/controller/src/ble_ll_conn.c         | 25 ++++++++++++++--
 net/nimble/controller/src/ble_ll_hci.c          |  3 ++
 net/nimble/controller/src/ble_ll_resolv.c       | 31 ++++++++++++++++++++
 net/nimble/include/nimble/hci_common.h          |  2 ++
 5 files changed, 63 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac7b489a/net/nimble/controller/include/controller/ble_ll_resolv.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_resolv.h b/net/nimble/controller/include/controller/ble_ll_resolv.h
index e06c7db..6c09bee 100644
--- a/net/nimble/controller/include/controller/ble_ll_resolv.h
+++ b/net/nimble/controller/include/controller/ble_ll_resolv.h
@@ -34,7 +34,8 @@ struct ble_ll_resolv_entry
 {
     uint8_t rl_addr_type;
     uint8_t rl_local_rpa_set;
-    uint16_t rl_reserved;
+    uint8_t rl_reserved;
+    uint8_t rl_priv_mode;
     uint8_t rl_local_irk[16];
     uint8_t rl_peer_irk[16];
     uint8_t rl_identity_addr[BLE_DEV_ADDR_LEN];
@@ -85,6 +86,9 @@ int ble_ll_resolv_gen_rpa(uint8_t *addr, uint8_t addr_type, uint8_t *rpa,
 /* Set the resolvable private address timeout */
 int ble_ll_resolv_set_rpa_tmo(uint8_t *cmdbuf);
 
+/* Set the privacy mode */
+int ble_ll_resolve_set_priv_mode(uint8_t *cmdbuf);
+
 /* Get the RPA timeout, in seconds */
 uint32_t ble_ll_resolv_get_rpa_tmo(void);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac7b489a/net/nimble/controller/src/ble_ll_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn.c b/net/nimble/controller/src/ble_ll_conn.c
index 8d3173b..2d4c099 100644
--- a/net/nimble/controller/src/ble_ll_conn.c
+++ b/net/nimble/controller/src/ble_ll_conn.c
@@ -2446,6 +2446,9 @@ ble_ll_init_rx_isr_end(uint8_t *rxbuf, uint8_t crcok,
     uint8_t inita_is_rpa;
     struct os_mbuf *rxpdu;
     struct ble_ll_conn_sm *connsm;
+#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY)
+    struct ble_ll_resolv_entry *rl;
+#endif
 
     /* Get connection state machine to use if connection to be established */
     connsm = g_ble_ll_conn_create_sm;
@@ -2469,7 +2472,6 @@ ble_ll_init_rx_isr_end(uint8_t *rxbuf, uint8_t crcok,
         chk_send_req = 1;
         break;
     case BLE_ADV_PDU_TYPE_ADV_DIRECT_IND:
-        /* XXX: needs to be fixed for privacy */
         chk_send_req = 0;
         init_addr = rxbuf + BLE_LL_PDU_HDR_LEN + BLE_DEV_ADDR_LEN;
         addr_type = rxbuf[0] & BLE_ADV_PDU_HDR_RXADD_MASK;
@@ -2519,16 +2521,33 @@ ble_ll_init_rx_isr_end(uint8_t *rxbuf, uint8_t crcok,
         if (ble_ll_is_rpa(adv_addr, addr_type) && ble_ll_resolv_enabled()) {
             index = ble_hw_resolv_list_match();
             if (index >= 0) {
+                rl = &g_ble_ll_resolv_list[index];
+
                 ble_hdr->rxinfo.flags |= BLE_MBUF_HDR_F_RESOLVED;
                 connsm->rpa_index = index;
-                peer = g_ble_ll_resolv_list[index].rl_identity_addr;
-                peer_addr_type = g_ble_ll_resolv_list[index].rl_addr_type;
+                peer = rl->rl_identity_addr;
+                peer_addr_type = rl->rl_addr_type;
                 resolved = 1;
+
+                /* Assure privacy */
+                if ((rl->rl_priv_mode == BLE_HCI_PRIVACY_NETWORK) &&
+                    !inita_is_rpa) {
+                    goto init_rx_isr_exit;
+                }
             } else {
                 if (chk_wl) {
                     goto init_rx_isr_exit;
                 }
             }
+        } else if (ble_ll_resolv_enabled()) {
+            /* Let's see if we have IRK with that peer. If so lets make sure
+             * privacy mode is correct together with initA
+             */
+            rl = ble_ll_resolv_list_find(adv_addr, addr_type);
+            if (rl && !inita_is_rpa &&
+               (rl->rl_priv_mode == BLE_HCI_PRIVACY_NETWORK)) {
+                goto init_rx_isr_exit;
+            }
         }
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac7b489a/net/nimble/controller/src/ble_ll_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_hci.c b/net/nimble/controller/src/ble_ll_hci.c
index 844060a..ca5996d 100644
--- a/net/nimble/controller/src/ble_ll_hci.c
+++ b/net/nimble/controller/src/ble_ll_hci.c
@@ -760,6 +760,9 @@ ble_ll_hci_le_cmd_proc(uint8_t *cmdbuf, uint16_t ocf, uint8_t *rsplen)
     case BLE_HCI_OCF_LE_SET_RPA_TMO:
         rc = ble_ll_resolv_set_rpa_tmo(cmdbuf);
         break;
+    case BLE_HCI_OCF_LE_SET_PRIVACY_MODE:
+        rc = ble_ll_resolve_set_priv_mode(cmdbuf);
+        break;
 #endif
     case BLE_HCI_OCF_LE_RD_MAX_DATA_LEN:
         rc = ble_ll_hci_le_rd_max_data_len(rspbuf, rsplen);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac7b489a/net/nimble/controller/src/ble_ll_resolv.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_resolv.c b/net/nimble/controller/src/ble_ll_resolv.c
index 012afc5..c38a5bc 100644
--- a/net/nimble/controller/src/ble_ll_resolv.c
+++ b/net/nimble/controller/src/ble_ll_resolv.c
@@ -241,6 +241,9 @@ ble_ll_resolv_list_add(uint8_t *cmdbuf)
         swap_buf(rl->rl_peer_irk, cmdbuf + 7, 16);
         swap_buf(rl->rl_local_irk, cmdbuf + 23, 16);
 
+        /* By default use ptivacy network mode */
+        rl->rl_priv_mode = BLE_HCI_PRIVACY_NETWORK;
+
         /*
          * Add peer IRK to HW resolving list. If we can add it, also
          * generate a local RPA now to save time later.
@@ -370,6 +373,34 @@ ble_ll_resolv_set_rpa_tmo(uint8_t *cmdbuf)
                             (int32_t)g_ble_ll_resolv_data.rpa_tmo);
 }
 
+int
+ble_ll_resolve_set_priv_mode(uint8_t *cmdbuf)
+{
+    struct ble_ll_resolv_entry *rl;
+
+    if (ble_ll_adv_enabled() || ble_ll_scan_enabled() ||
+        g_ble_ll_conn_create_sm) {
+        return BLE_ERR_CMD_DISALLOWED;
+    }
+
+    if (!ble_ll_resolv_enabled()) {
+        return BLE_ERR_CMD_DISALLOWED;
+    }
+
+    /* cmdbuf = addr_type(0) | addr(6) | priv_mode(1) */
+    rl = ble_ll_resolv_list_find(&cmdbuf[1], cmdbuf[0]);
+    if (!rl) {
+        return BLE_ERR_UNK_CONN_ID;
+    }
+
+    if (cmdbuf[7] > BLE_HCI_PRIVACY_DEVICE) {
+        return BLE_ERR_INV_HCI_CMD_PARMS;
+    }
+
+    rl->rl_priv_mode = cmdbuf[7];
+    return 0;
+}
+
 /**
  * Returns the Resolvable Private address timeout, in os ticks
  *

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ac7b489a/net/nimble/include/nimble/hci_common.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/hci_common.h b/net/nimble/include/nimble/hci_common.h
index d565a74..e9b520b 100644
--- a/net/nimble/include/nimble/hci_common.h
+++ b/net/nimble/include/nimble/hci_common.h
@@ -485,6 +485,8 @@ extern "C" {
 
 /* --- LE set privacy mode (OCF 0x004E) */
 #define BLE_HCI_LE_SET_PRIVACY_MODE_LEN             (8)
+#define BLE_HCI_PRIVACY_NETWORK                     (0)
+#define BLE_HCI_PRIVACY_DEVICE                      (1)
 
 /* Event Codes */
 #define BLE_HCI_EVCODE_INQUIRY_CMP          (0x01)