mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccoll...@apache.org
Subject [08/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Always use effective addrs during SMP.
Date Wed, 15 Jun 2016 02:27:30 GMT
BLE Host - Always use effective addrs during SMP.

Prior to this change, SM procedures used identity addresses as inputs
into the crypto functions.  Now we always use the effective address (RPA
is one is being used, else public or random static).


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/be5a9850
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/be5a9850
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/be5a9850

Branch: refs/heads/develop
Commit: be5a98505e12d24b66eedb96b0580790ea0a6680
Parents: 32afd9c
Author: Christopher Collins <ccollins@apache.org>
Authored: Tue Jun 7 22:38:48 2016 +0800
Committer: Christopher Collins <ccollins@apache.org>
Committed: Tue Jun 14 19:23:34 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_store.h |  4 +++
 net/nimble/host/src/ble_gap.c            |  3 ++
 net/nimble/host/src/ble_hs_conn.c        | 52 +++++++++++++++++++++++++++
 net/nimble/host/src/ble_hs_conn_priv.h   |  4 +++
 net/nimble/host/src/ble_hs_misc.c        | 18 ++++++++++
 net/nimble/host/src/ble_hs_priv.h        |  2 ++
 net/nimble/host/src/ble_sm.c             | 21 ++++++-----
 net/nimble/host/src/ble_store.c          | 11 ++++++
 8 files changed, 107 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/be5a9850/net/nimble/host/include/host/ble_store.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_store.h b/net/nimble/host/include/host/ble_store.h
index 8af689c..e5b51aa 100644
--- a/net/nimble/host/include/host/ble_store.h
+++ b/net/nimble/host/include/host/ble_store.h
@@ -37,6 +37,10 @@
 struct ble_store_key_sec {
     /**
      * Key by peer identity address;
+     * Valid peer_addr_type values;
+     *    o BLE_ADDR_TYPE_PUBLIC
+     *    o BLE_ADDR_TYPE_RANDOM
+     *    o BLE_STORE_ADDR_TYPE_NONE
      * peer_addr_type=BLE_STORE_ADDR_TYPE_NONE means don't key off peer.
      */
     uint8_t peer_addr[6];

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/be5a9850/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index c7020f7..795b2ec 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -916,6 +916,9 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt)
         ble_gap_slave.op = BLE_GAP_OP_NULL;
     }
 
+    memcpy(conn->our_rpa_addr, evt->local_rpa, 6);
+    memcpy(conn->peer_rpa_addr, evt->local_rpa, 6);
+
     ble_gap_conn_to_snapshot(conn, &snap);
 
     ble_hs_atomic_conn_insert(conn);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/be5a9850/net/nimble/host/src/ble_hs_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn.c b/net/nimble/host/src/ble_hs_conn.c
index 2883f30..84081b4 100644
--- a/net/nimble/host/src/ble_hs_conn.c
+++ b/net/nimble/host/src/ble_hs_conn.c
@@ -31,6 +31,8 @@ static struct os_mempool ble_hs_conn_pool;
 
 static os_membuf_t *ble_hs_conn_elem_mem;
 
+static const uint8_t ble_hs_conn_null_addr[6];
+
 int
 ble_hs_conn_can_alloc(void)
 {
@@ -313,6 +315,56 @@ ble_hs_conn_first(void)
     return SLIST_FIRST(&ble_hs_conns);
 }
 
+void
+ble_hs_conn_peer_effective_addr(struct ble_hs_conn *conn, uint8_t *out_addr)
+{
+    switch (conn->bhc_addr_type) {
+    case BLE_ADDR_TYPE_PUBLIC:
+    case BLE_ADDR_TYPE_RANDOM:
+        memcpy(out_addr, conn->bhc_addr, 6);
+        break;
+
+    case BLE_ADDR_TYPE_RPA_PUB_DEFAULT:
+    case BLE_ADDR_TYPE_RPA_RND_DEFAULT:
+        memcpy(out_addr, conn->peer_rpa_addr, 6);
+        break;
+
+    default:
+        BLE_HS_DBG_ASSERT(0);
+        break;
+    }
+}
+
+void
+ble_hs_conn_our_effective_addr(struct ble_hs_conn *conn,
+                               uint8_t *out_addr_type, uint8_t *out_addr)
+{
+    uint8_t ident_addr_type;
+    uint8_t *ident_addr;
+
+    ident_addr = bls_hs_priv_get_local_identity_addr(&ident_addr_type);
+
+    if (memcmp(conn->our_rpa_addr, ble_hs_conn_null_addr, 6) == 0) {
+        *out_addr_type = ident_addr_type;
+        memcpy(out_addr, ident_addr, 6);
+    } else {
+        switch (ident_addr_type) {
+        case BLE_ADDR_TYPE_PUBLIC:
+            *out_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT;
+            break;
+
+        case BLE_ADDR_TYPE_RANDOM:
+            *out_addr_type = BLE_ADDR_TYPE_RPA_RND_DEFAULT;
+            break;
+
+        default:
+            BLE_HS_DBG_ASSERT(0);
+        }
+
+        memcpy(out_addr, conn->our_rpa_addr, 6);
+    }
+}
+
 static void
 ble_hs_conn_free_mem(void)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/be5a9850/net/nimble/host/src/ble_hs_conn_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn_priv.h b/net/nimble/host/src/ble_hs_conn_priv.h
index 963b200..9e3fbf2 100644
--- a/net/nimble/host/src/ble_hs_conn_priv.h
+++ b/net/nimble/host/src/ble_hs_conn_priv.h
@@ -75,6 +75,10 @@ struct ble_l2cap_chan *ble_hs_conn_chan_find(struct ble_hs_conn *conn,
                                              uint16_t cid);
 int ble_hs_conn_chan_insert(struct ble_hs_conn *conn,
                             struct ble_l2cap_chan *chan);
+void ble_hs_conn_peer_effective_addr(struct ble_hs_conn *conn,
+                                     uint8_t *out_addr);
+void ble_hs_conn_our_effective_addr(struct ble_hs_conn *conn,
+                                    uint8_t *out_addr_type, uint8_t *out_addr);
 int ble_hs_conn_init(void);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/be5a9850/net/nimble/host/src/ble_hs_misc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_misc.c b/net/nimble/host/src/ble_hs_misc.c
index 82941d6..29438ea 100644
--- a/net/nimble/host/src/ble_hs_misc.c
+++ b/net/nimble/host/src/ble_hs_misc.c
@@ -161,3 +161,21 @@ ble_hs_misc_conn_chan_find_reqd(uint16_t conn_handle, uint16_t cid,
 
     return rc;
 }
+
+uint8_t
+ble_hs_misc_addr_type_to_ident(uint8_t addr_type)
+{
+    switch (addr_type) {
+    case BLE_ADDR_TYPE_PUBLIC:
+    case BLE_ADDR_TYPE_RPA_PUB_DEFAULT:
+         return BLE_ADDR_TYPE_PUBLIC;
+
+    case BLE_ADDR_TYPE_RANDOM:
+    case BLE_ADDR_TYPE_RPA_RND_DEFAULT:
+         return BLE_ADDR_TYPE_RANDOM;
+
+    default:
+        BLE_HS_DBG_ASSERT(0);
+        return BLE_ADDR_TYPE_PUBLIC;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/be5a9850/net/nimble/host/src/ble_hs_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_priv.h b/net/nimble/host/src/ble_hs_priv.h
index 877ceec..c8462bf 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -85,6 +85,7 @@ int ble_hs_misc_conn_chan_find(uint16_t conn_handle, uint16_t cid,
 int ble_hs_misc_conn_chan_find_reqd(uint16_t conn_handle, uint16_t cid,
                                     struct ble_hs_conn **out_conn,
                                     struct ble_l2cap_chan **out_chan);
+uint8_t ble_hs_misc_addr_type_to_ident(uint8_t addr_type);
 
 void ble_hs_cfg_init(struct ble_hs_cfg *cfg);
 
@@ -107,6 +108,7 @@ int ble_hs_priv_set_nrpa(void);
 void ble_hs_priv_get_nrpa(uint8_t *addr);
 void ble_hs_priv_update_identity(uint8_t *addr);
 void ble_hs_priv_update_irk(uint8_t *irk);
+uint8_t *bls_hs_priv_get_local_identity_addr(uint8_t *type);
 void bls_hs_priv_copy_local_identity_addr(uint8_t *pdst, uint8_t* addr_type);
 uint8_t *ble_hs_priv_get_local_irk(void);
 int ble_keycache_remove_irk_entry(uint8_t addr_type, uint8_t *addr);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/be5a9850/net/nimble/host/src/ble_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm.c b/net/nimble/host/src/ble_sm.c
index 7e6ed1f..58cd22a 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -520,6 +520,7 @@ ble_sm_addrs(struct ble_sm_proc *proc, uint8_t *out_iat, uint8_t *out_ia,
              uint8_t *out_rat, uint8_t *out_ra)
 {
     struct ble_hs_conn *conn;
+    uint8_t our_addr_type;
 
     conn = ble_hs_conn_find(proc->conn_handle);
     if (conn == NULL) {
@@ -527,13 +528,17 @@ ble_sm_addrs(struct ble_sm_proc *proc, uint8_t *out_iat, uint8_t *out_ia,
     }
 
     if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
-        bls_hs_priv_copy_local_identity_addr(out_ia, out_iat);
-        *out_rat = conn->bhc_addr_type;
-        memcpy(out_ra, conn->bhc_addr, 6);
+        ble_hs_conn_our_effective_addr(conn, &our_addr_type, out_ia);
+        *out_iat = ble_hs_misc_addr_type_to_ident(our_addr_type);
+
+        ble_hs_conn_peer_effective_addr(conn, out_ra);
+        *out_rat = ble_hs_misc_addr_type_to_ident(conn->bhc_addr_type);
     } else {
-        bls_hs_priv_copy_local_identity_addr(out_ra, out_rat);
-        *out_iat = conn->bhc_addr_type;
-        memcpy(out_ia, conn->bhc_addr, 6);
+        ble_hs_conn_our_effective_addr(conn, &our_addr_type, out_ra);
+        *out_rat = ble_hs_misc_addr_type_to_ident(our_addr_type);
+
+        ble_hs_conn_peer_effective_addr(conn, out_ia);
+        *out_iat = ble_hs_misc_addr_type_to_ident(conn->bhc_addr_type);
     }
 
     return 0;
@@ -558,7 +563,7 @@ ble_sm_persist_keys(struct ble_sm_proc *proc)
         peer_addr_type = proc->peer_keys.addr_type;
         memcpy(peer_addr, proc->peer_keys.addr, sizeof peer_addr);
     } else {
-        peer_addr_type = conn->bhc_addr_type;
+        peer_addr_type = ble_hs_misc_addr_type_to_ident(conn->bhc_addr_type);
         memcpy(peer_addr, conn->bhc_addr, sizeof peer_addr);
     }
 
@@ -2141,7 +2146,7 @@ ble_sm_enc_initiate(uint16_t conn_handle, uint8_t *ltk, uint16_t ediv,
     /* Make sure a procedure isn't already in progress for this connection. */
     ble_hs_lock();
     proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_NONE,
-                                  -1, NULL);
+                            -1, NULL);
     if (proc != NULL) {
         res.app_status = BLE_HS_EALREADY;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/be5a9850/net/nimble/host/src/ble_store.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_store.c b/net/nimble/host/src/ble_store.c
index 7db7b4a..a2de0ea 100644
--- a/net/nimble/host/src/ble_store.c
+++ b/net/nimble/host/src/ble_store.c
@@ -73,6 +73,10 @@ ble_store_read_slv_sec(struct ble_store_key_sec *key_sec,
     union ble_store_key *store_key;
     int rc;
 
+    BLE_HS_DBG_ASSERT(key_sec->peer_addr_type == BLE_ADDR_TYPE_PUBLIC ||
+                      key_sec->peer_addr_type == BLE_ADDR_TYPE_RANDOM ||
+                      key_sec->peer_addr_type == BLE_STORE_ADDR_TYPE_NONE);
+
     store_key = (void *)key_sec;
     store_value = (void *)value_sec;
     rc = ble_store_read(BLE_STORE_OBJ_TYPE_SLV_SEC, store_key, store_value);
@@ -87,6 +91,9 @@ ble_store_persist_sec(int obj_type, struct ble_store_value_sec *value_sec)
     union ble_store_key *store_key;
     int rc;
 
+    BLE_HS_DBG_ASSERT(value_sec->peer_addr_type == BLE_ADDR_TYPE_PUBLIC ||
+                      value_sec->peer_addr_type == BLE_ADDR_TYPE_RANDOM);
+
     /* If the value contains no keys, delete the corresponding entry.
      * Otherwise, write it.
      */
@@ -122,6 +129,10 @@ ble_store_read_mst_sec(struct ble_store_key_sec *key_sec,
     union ble_store_key *store_key;
     int rc;
 
+    BLE_HS_DBG_ASSERT(key_sec->peer_addr_type == BLE_ADDR_TYPE_PUBLIC ||
+                      key_sec->peer_addr_type == BLE_ADDR_TYPE_RANDOM ||
+                      key_sec->peer_addr_type == BLE_STORE_ADDR_TYPE_NONE);
+
     store_key = (void *)key_sec;
     store_value = (void *)value_sec;
     rc = ble_store_read(BLE_STORE_OBJ_TYPE_MST_SEC, store_key, store_value);


Mime
View raw message