BLE Host - Don't require key in persist write.

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

Branch: refs/heads/develop
Commit: ddd76b6b3953ba5eab18a39cdcc3d83bf2e3cc5c
Parents: bd4a456
Author: Christopher Collins <[email protected]>
Authored: Fri May 20 18:24:12 2016 -0700
Committer: Christopher Collins <[email protected]>
Committed: Sat May 21 08:57:12 2016 -0700

----------------------------------------------------------------------
 apps/bleprph/src/bleprph.h                   |  7 ++-
 apps/bleprph/src/keystore.c                  | 18 ++++----
 apps/bleprph/src/main.c                      | 21 ++++++---
 apps/bletiny/src/bletiny_priv.h              |  9 ++--
 apps/bletiny/src/keystore.c                  | 18 ++++----
 apps/bletiny/src/main.c                      | 22 ++++-----
 net/nimble/host/include/host/ble_store.h     | 55 ++++++++++++++---------
 net/nimble/host/src/ble_gatts.c              | 34 +++++++++++---
 net/nimble/host/src/ble_l2cap_sm.c           | 18 +++-----
 net/nimble/host/src/ble_store.c              | 31 ++++++++++---
 net/nimble/host/src/test/ble_hs_test.c       |  1 -
 net/nimble/host/src/test/ble_l2cap_sm_test.c |  7 ++-
 12 files changed, 147 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddd76b6b/apps/bleprph/src/bleprph.h
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/bleprph.h b/apps/bleprph/src/bleprph.h
index 1a9b150..873d35b 100644
--- a/apps/bleprph/src/bleprph.h
+++ b/apps/bleprph/src/bleprph.h
@@ -52,9 +52,8 @@ extern const uint8_t gatt_svr_chr_bleprph_write[16];
 void gatt_svr_init(void);
 
 /** Keystore. */
-int keystore_lookup(uint16_t ediv, uint64_t rand_num,
-                    void *out_ltk, int *out_authenticated);
-int keystore_add(uint16_t ediv, uint64_t rand_num, uint8_t *key,
-                 int authenticated);
+int keystore_lookup(struct ble_store_key_ltk *store_key, uint8_t *out_ltk,
+                    int *out_authenticated);
+int keystore_add(struct ble_store_value_ltk *store_value);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddd76b6b/apps/bleprph/src/keystore.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/keystore.c b/apps/bleprph/src/keystore.c
index 5f3ff55..efa17ea 100644
--- a/apps/bleprph/src/keystore.c
+++ b/apps/bleprph/src/keystore.c
@@ -53,8 +53,8 @@ static int keystore_num_entries;
  * @return                      0 if a key was found; else BLE_HS_ENOENT.
  */
 int
-keystore_lookup(uint16_t ediv, uint64_t rand_num,
-                void *out_ltk, int *out_authenticated)
+keystore_lookup(struct ble_store_key_ltk *store_key, uint8_t *out_ltk,
+                int *out_authenticated)
 {
     struct keystore_entry *entry;
     int i;
@@ -62,7 +62,9 @@ keystore_lookup(uint16_t ediv, uint64_t rand_num,
     for (i = 0; i < keystore_num_entries; i++) {
         entry = keystore_entries + i;
 
-        if (entry->ediv == ediv && entry->rand_num == rand_num) {
+        if (entry->ediv == store_key->ediv &&
+            entry->rand_num == store_key->rand_num) {
+
             memcpy(out_ltk, entry->ltk, sizeof entry->ltk);
             *out_authenticated = entry->authenticated;
 
@@ -80,7 +82,7 @@ keystore_lookup(uint16_t ediv, uint64_t rand_num,
  *                                  full.
  */
 int
-keystore_add(uint16_t ediv, uint64_t rand_num, uint8_t *ltk, int authenticated)
+keystore_add(struct ble_store_value_ltk *store_value)
 {
     struct keystore_entry *entry;
 
@@ -91,10 +93,10 @@ keystore_add(uint16_t ediv, uint64_t rand_num, uint8_t 
*ltk, int authenticated)
     entry = keystore_entries + keystore_num_entries;
     keystore_num_entries++;
 
-    entry->ediv = ediv;
-    entry->rand_num = rand_num;
-    memcpy(entry->ltk, ltk, sizeof entry->ltk);
-    entry->authenticated = authenticated;
+    entry->ediv = store_value->ediv;
+    entry->rand_num = store_value->rand_num;
+    memcpy(entry->ltk, store_value->key, sizeof entry->ltk);
+    entry->authenticated = store_value->authenticated;
 
     return 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddd76b6b/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index f48cdbd..96db35b 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -246,8 +246,7 @@ bleprph_store_read(int obj_type, union ble_store_key *key,
          * result.  The nimble stack will use this key if this function returns
          * success.
          */
-        rc = keystore_lookup(key->ltk.ediv, key->ltk.rand_num,
-                             dst->ltk.key, &authenticated);
+        rc = keystore_lookup(&key->ltk, dst->ltk.key, &authenticated);
         if (rc == 0) {
             dst->ltk.authenticated = authenticated;
             BLEPRPH_LOG(INFO, "ltk=");
@@ -269,9 +268,18 @@ bleprph_store_read(int obj_type, union ble_store_key *key,
     }
 }
 
+static void
+bleprph_print_key_exchange_parms(struct ble_store_value_ltk *ltk)
+{
+    BLEPRPH_LOG(INFO, "ediv=%u rand=%llu authenticated=%d ", ltk->ediv,
+                   ltk->rand_num, ltk->authenticated);
+    BLEPRPH_LOG(INFO, "ltk=");
+    bleprph_print_bytes(ltk->key, 16);
+    BLEPRPH_LOG(INFO, "\n");
+}
+
 static int
-bleprph_store_write(int obj_type, union ble_store_key *key,
-                    union ble_store_value *dst)
+bleprph_store_write(int obj_type, union ble_store_value *val)
 {
     int rc;
 
@@ -282,8 +290,9 @@ bleprph_store_write(int obj_type, union ble_store_key *key,
          * to occur on subsequent connections with this peer (as long as
          * bleprph isn't restarted!).
          */
-        rc = keystore_add(key->ltk.ediv, key->ltk.rand_num,
-                          dst->ltk.key, dst->ltk.authenticated);
+        BLEPRPH_LOG(INFO, "persisting our ltk; ");
+        bleprph_print_key_exchange_parms(&val->ltk);
+        rc = keystore_add(&val->ltk);
         if (rc != 0) {
             BLEPRPH_LOG(INFO, "error persisting LTK; status=%d\n", rc);
         }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddd76b6b/apps/bletiny/src/bletiny_priv.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny_priv.h b/apps/bletiny/src/bletiny_priv.h
index 5ecf2e5..df18890 100644
--- a/apps/bletiny/src/bletiny_priv.h
+++ b/apps/bletiny/src/bletiny_priv.h
@@ -33,6 +33,8 @@ struct ble_gap_crt_params;
 struct hci_adv_params;
 struct ble_l2cap_sig_update_req;
 struct ble_l2cap_sig_update_params;
+struct ble_store_key_ltk;
+struct ble_store_value_ltk;
 
 typedef int cmd_fn(int argc, char **argv);
 struct cmd_entry {
@@ -186,9 +188,8 @@ extern const uint8_t gatt_svr_chr_bleprph_write[16];
 void gatt_svr_init(void);
 
 /** Keystore. */
-int keystore_lookup(uint16_t ediv, uint64_t rand_num,
-                    void *out_ltk, int *out_authenticated);
-int keystore_add(uint16_t ediv, uint64_t rand_num, uint8_t *key,
-                 int authenticated);
+int keystore_lookup(struct ble_store_key_ltk *store_key, uint8_t *out_ltk,
+                    int *out_authenticated);
+int keystore_add(struct ble_store_value_ltk *store_value);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddd76b6b/apps/bletiny/src/keystore.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/keystore.c b/apps/bletiny/src/keystore.c
index 5f3ff55..efa17ea 100644
--- a/apps/bletiny/src/keystore.c
+++ b/apps/bletiny/src/keystore.c
@@ -53,8 +53,8 @@ static int keystore_num_entries;
  * @return                      0 if a key was found; else BLE_HS_ENOENT.
  */
 int
-keystore_lookup(uint16_t ediv, uint64_t rand_num,
-                void *out_ltk, int *out_authenticated)
+keystore_lookup(struct ble_store_key_ltk *store_key, uint8_t *out_ltk,
+                int *out_authenticated)
 {
     struct keystore_entry *entry;
     int i;
@@ -62,7 +62,9 @@ keystore_lookup(uint16_t ediv, uint64_t rand_num,
     for (i = 0; i < keystore_num_entries; i++) {
         entry = keystore_entries + i;
 
-        if (entry->ediv == ediv && entry->rand_num == rand_num) {
+        if (entry->ediv == store_key->ediv &&
+            entry->rand_num == store_key->rand_num) {
+
             memcpy(out_ltk, entry->ltk, sizeof entry->ltk);
             *out_authenticated = entry->authenticated;
 
@@ -80,7 +82,7 @@ keystore_lookup(uint16_t ediv, uint64_t rand_num,
  *                                  full.
  */
 int
-keystore_add(uint16_t ediv, uint64_t rand_num, uint8_t *ltk, int authenticated)
+keystore_add(struct ble_store_value_ltk *store_value)
 {
     struct keystore_entry *entry;
 
@@ -91,10 +93,10 @@ keystore_add(uint16_t ediv, uint64_t rand_num, uint8_t 
*ltk, int authenticated)
     entry = keystore_entries + keystore_num_entries;
     keystore_num_entries++;
 
-    entry->ediv = ediv;
-    entry->rand_num = rand_num;
-    memcpy(entry->ltk, ltk, sizeof entry->ltk);
-    entry->authenticated = authenticated;
+    entry->ediv = store_value->ediv;
+    entry->rand_num = store_value->rand_num;
+    memcpy(entry->ltk, store_value->key, sizeof entry->ltk);
+    entry->authenticated = store_value->authenticated;
 
     return 0;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddd76b6b/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index db60ae5..7a5b073 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -41,6 +41,7 @@
 #include "host/ble_att.h"
 #include "host/ble_gap.h"
 #include "host/ble_gatt.h"
+#include "host/ble_store.h"
 #include "controller/ble_ll.h"
 
 /* XXX: An app should not include private headers from a library.  The bletiny
@@ -169,13 +170,12 @@ bletiny_print_conn_desc(struct ble_gap_conn_desc *desc)
 }
 
 static void
-bletiny_print_key_exchange_parms(uint16_t ediv, uint64_t rand_num, void *ltk,
-                                 int authenticated)
+bletiny_print_key_exchange_parms(struct ble_store_value_ltk *ltk)
 {
-    console_printf("ediv=%u rand=%llu authenticated=%d ", ediv, rand_num,
-                   authenticated);
+    console_printf("ediv=%u rand=%llu authenticated=%d ", ltk->ediv,
+                   ltk->rand_num, ltk->authenticated);
     console_printf("ltk=");
-    bletiny_print_bytes(ltk, 16);
+    bletiny_print_bytes(ltk->key, 16);
     console_printf("\n");
 }
 
@@ -888,8 +888,7 @@ bletiny_store_read(int obj_type, union ble_store_key *key,
          * result.  The nimble stack will use this key if this function returns
          * success.
          */
-        rc = keystore_lookup(key->ltk.ediv, key->ltk.rand_num,
-                             dst->ltk.key, &authenticated);
+        rc = keystore_lookup(&key->ltk, dst->ltk.key, &authenticated);
         if (rc == 0) {
             dst->ltk.authenticated = authenticated;
             console_printf("ltk=");
@@ -912,8 +911,7 @@ bletiny_store_read(int obj_type, union ble_store_key *key,
 }
 
 static int
-bletiny_store_write(int obj_type, union ble_store_key *key,
-                    union ble_store_value *val)
+bletiny_store_write(int obj_type, union ble_store_value *val)
 {
     int rc;
 
@@ -924,10 +922,8 @@ bletiny_store_write(int obj_type, union ble_store_key *key,
          * connections with this peer (as long as bletiny isn't restarted!).
          */
         console_printf("persisting our ltk; ");
-        bletiny_print_key_exchange_parms(key->ltk.ediv, key->ltk.rand_num,
-                                         val->ltk.key, val->ltk.authenticated);
-        rc = keystore_add(key->ltk.ediv, key->ltk.rand_num,
-                          val->ltk.key, val->ltk.authenticated);
+        bletiny_print_key_exchange_parms(&val->ltk);
+        rc = keystore_add(&val->ltk);
         if (rc != 0) {
             console_printf("error persisting ltk; status=%d\n", rc);
         }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddd76b6b/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 9334acb..d25c238 100644
--- a/net/nimble/host/include/host/ble_store.h
+++ b/net/nimble/host/include/host/ble_store.h
@@ -26,42 +26,53 @@
 #define BLE_STORE_OBJ_TYPE_PEER_LTK     2
 #define BLE_STORE_OBJ_TYPE_CCCD         3
 
-union ble_store_key {
-    struct {
-        uint16_t ediv;
-        uint64_t rand_num;
-    } ltk;
+struct ble_store_key_ltk {
+    uint16_t ediv;
+    uint64_t rand_num;
+};
 
-    struct {
-        uint8_t peer_addr[6];
-        /* XXX: Peer addr type? */
-    } cccd;
+struct ble_store_value_ltk {
+    uint16_t ediv;
+    uint64_t rand_num;
+    uint8_t key[16];
+    unsigned authenticated:1;
 };
 
-union ble_store_value {
-    struct {
-        uint8_t key[16];
-        unsigned authenticated:1;
-    } ltk;
+struct ble_store_key_cccd {
+    uint8_t peer_addr[6];
+    uint8_t peer_addr_type;
+};
 
-    struct {
-        uint16_t flags;
-        unsigned value_changed:1;
-    } cccd;
+struct ble_store_value_cccd {
+    uint8_t peer_addr[6];
+    uint8_t peer_addr_type;
+    uint16_t flags;
+    unsigned value_changed:1;
+};
+
+union ble_store_key {
+    struct ble_store_key_ltk ltk;
+    struct ble_store_key_cccd cccd;
+};
+
+union ble_store_value {
+    struct ble_store_value_ltk ltk;
+    struct ble_store_value_cccd cccd;
 };
 
 typedef int ble_store_read_fn(int obj_type, union ble_store_key *key,
                               union ble_store_value *dst);
 
-typedef int ble_store_write_fn(int obj_type, union ble_store_key *key,
-                               union ble_store_value *val);
+typedef int ble_store_write_fn(int obj_type, union ble_store_value *val);
 
 typedef int ble_store_delete_fn(int obj_type, union ble_store_key *key);
 
 int ble_store_read(int obj_type, union ble_store_key *key,
                    union ble_store_value *val);
-int ble_store_write(int obj_type, union ble_store_key *key,
-                    union ble_store_value *val);
+int ble_store_write(int obj_type, union ble_store_value *val);
 int ble_store_delete(int obj_type, union ble_store_key *key);
 
+int ble_store_write_cccd(struct ble_store_value_cccd *value);
+int ble_store_delete_cccd(struct ble_store_key_cccd *key);
+
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddd76b6b/net/nimble/host/src/ble_gatts.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gatts.c b/net/nimble/host/src/ble_gatts.c
index b53a139..62cfe80 100644
--- a/net/nimble/host/src/ble_gatts.c
+++ b/net/nimble/host/src/ble_gatts.c
@@ -22,6 +22,7 @@
 #include "console/console.h"
 #include "nimble/ble.h"
 #include "host/ble_uuid.h"
+#include "host/ble_store.h"
 #include "ble_hs_priv.h"
 
 #define BLE_GATTS_INCLUDE_SZ    6
@@ -526,11 +527,17 @@ ble_gatts_clt_cfg_find(struct ble_gatts_clt_cfg *cfgs,
     }
 }
 
+struct ble_gatts_clt_cfg_record {
+    unsigned write:1;
+    struct ble_store_key_cccd key;
+    struct ble_store_value_cccd value;
+};
+
 static int
 ble_gatts_clt_cfg_access_locked(struct ble_hs_conn *conn, uint16_t attr_handle,
                                 uint8_t *uuid128, uint8_t att_op,
                                 struct ble_att_svr_access_ctxt *ctxt,
-                                int *out_persist_flags)
+                                struct ble_gatts_clt_cfg_record *out_record)
 {
     struct ble_gatts_clt_cfg *clt_cfg;
     uint16_t chr_def_handle;
@@ -539,7 +546,8 @@ ble_gatts_clt_cfg_access_locked(struct ble_hs_conn *conn, 
uint16_t attr_handle,
 
     static uint8_t buf[2];
 
-    *out_persist_flags = -1;
+    /* Assume nothing needs to be persisted. */
+    out_record->write = 0;
 
     /* We always register the client characteristics descriptor with handle
      * (chr_def + 2).
@@ -579,7 +587,15 @@ ble_gatts_clt_cfg_access_locked(struct ble_hs_conn *conn, 
uint16_t attr_handle,
         }
 
         clt_cfg->flags = flags;
-        *out_persist_flags = flags;
+
+        /* Successful writes get persisted for bonded connections. */
+        if (conn->bhc_sec_state.bonded) {
+            out_record->key.peer_addr_type = conn->bhc_addr_type;
+            memcpy(out_record->key.peer_addr, conn->bhc_addr, 6);
+            out_record->value.flags = clt_cfg->flags;
+            out_record->value.value_changed = 0;
+            out_record->write = 1;
+        }
         break;
 
     default:
@@ -596,8 +612,8 @@ ble_gatts_clt_cfg_access(uint16_t conn_handle, uint16_t 
attr_handle,
                          struct ble_att_svr_access_ctxt *ctxt,
                          void *arg)
 {
+    struct ble_gatts_clt_cfg_record persist_record;
     struct ble_hs_conn *conn;
-    int persist_flags;
     int rc;
 
     ble_hs_lock();
@@ -607,13 +623,17 @@ ble_gatts_clt_cfg_access(uint16_t conn_handle, uint16_t 
attr_handle,
         rc = BLE_ATT_ERR_UNLIKELY;
     } else {
         rc = ble_gatts_clt_cfg_access_locked(conn, attr_handle, uuid128, op,
-                                             ctxt, &persist_flags);
+                                             ctxt, &persist_record);
     }
 
     ble_hs_unlock();
 
-    if (rc == 0 && persist_flags != -1) {
-        /* XXX: Persist flags. */
+    if (rc == 0 && persist_record.write) {
+        if (persist_record.value.flags == 0) {
+            rc = ble_store_delete_cccd(&persist_record.key);
+        } else {
+            rc = ble_store_write_cccd(&persist_record.value);
+        }
     }
 
     return rc;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddd76b6b/net/nimble/host/src/ble_l2cap_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sm.c 
b/net/nimble/host/src/ble_l2cap_sm.c
index 1c9ed4d..18e6b52 100644
--- a/net/nimble/host/src/ble_l2cap_sm.c
+++ b/net/nimble/host/src/ble_l2cap_sm.c
@@ -482,34 +482,28 @@ static void
 ble_l2cap_sm_key_exchange_events(struct ble_l2cap_sm_proc *proc)
 {
     union ble_store_value store_value;
-    union ble_store_key store_key;
 
     if (proc->our_keys.ediv_rand_valid && proc->our_keys.ltk_valid) {
-        store_key.ltk.ediv = proc->our_keys.ediv;
-        store_key.ltk.rand_num = proc->our_keys.rand_val;
+        store_value.ltk.ediv = proc->our_keys.ediv;
+        store_value.ltk.rand_num = proc->our_keys.rand_val;
         memcpy(store_value.ltk.key, proc->our_keys.ltk,
                sizeof store_value.ltk.key);
         store_value.ltk.authenticated =
             !!(proc->flags & BLE_L2CAP_SM_PROC_F_AUTHENTICATED);
-        ble_store_write(BLE_STORE_OBJ_TYPE_OUR_LTK, &store_key, &store_value);
+        ble_store_write(BLE_STORE_OBJ_TYPE_OUR_LTK, &store_value);
     }
 
     if (proc->peer_keys.ediv_rand_valid && proc->peer_keys.ltk_valid) {
-        store_key.ltk.ediv = proc->peer_keys.ediv;
-        store_key.ltk.rand_num = proc->peer_keys.rand_val;
+        store_value.ltk.ediv = proc->peer_keys.ediv;
+        store_value.ltk.rand_num = proc->peer_keys.rand_val;
         memcpy(store_value.ltk.key, proc->peer_keys.ltk,
                sizeof store_value.ltk.key);
         store_value.ltk.authenticated =
             !!(proc->flags & BLE_L2CAP_SM_PROC_F_AUTHENTICATED);
-        ble_store_write(BLE_STORE_OBJ_TYPE_PEER_LTK, &store_key, &store_value);
+        ble_store_write(BLE_STORE_OBJ_TYPE_PEER_LTK, &store_value);
     }
 
     /* XXX: Persist other key data. */
-
-    //proc->our_keys.is_ours = 1;
-    //proc->peer_keys.is_ours = 0;
-    //ble_gap_key_exchange_event(proc->conn_handle, &proc->our_keys);
-    //ble_gap_key_exchange_event(proc->conn_handle, &proc->peer_keys);
 }
 
 static void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddd76b6b/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 dcd0699..de4cc7a 100644
--- a/net/nimble/host/src/ble_store.c
+++ b/net/nimble/host/src/ble_store.c
@@ -6,7 +6,7 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
@@ -29,22 +29,21 @@ ble_store_read(int obj_type, union ble_store_key *key,
     if (ble_hs_cfg.store_read_cb == NULL) {
         rc = BLE_HS_ENOTSUP;
     } else {
-        rc = ble_hs_cfg.store_read_cb(obj_type, key, val); 
+        rc = ble_hs_cfg.store_read_cb(obj_type, key, val);
     }
 
     return rc;
 }
 
 int
-ble_store_write(int obj_type, union ble_store_key *key,
-                union ble_store_value *val)
+ble_store_write(int obj_type, union ble_store_value *val)
 {
     int rc;
 
     if (ble_hs_cfg.store_write_cb == NULL) {
         rc = BLE_HS_ENOTSUP;
     } else {
-        rc = ble_hs_cfg.store_write_cb(obj_type, key, val); 
+        rc = ble_hs_cfg.store_write_cb(obj_type, val);
     }
 
     return rc;
@@ -63,3 +62,25 @@ ble_store_delete(int obj_type, union ble_store_key *key)
 
     return rc;
 }
+
+int
+ble_store_write_cccd(struct ble_store_value_cccd *value)
+{
+    union ble_store_value *store_value;
+    int rc;
+
+    store_value = (void *)value;
+    rc = ble_store_write(BLE_STORE_OBJ_TYPE_CCCD, store_value);
+    return rc;
+}
+
+int
+ble_store_delete_cccd(struct ble_store_key_cccd *key)
+{
+    union ble_store_key *store_key;
+    int rc;
+
+    store_key = (void *)key;
+    rc = ble_store_delete(BLE_STORE_OBJ_TYPE_CCCD, store_key);
+    return rc;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddd76b6b/net/nimble/host/src/test/ble_hs_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test.c 
b/net/nimble/host/src/test/ble_hs_test.c
index 19d5e38..aaaf19f 100644
--- a/net/nimble/host/src/test/ble_hs_test.c
+++ b/net/nimble/host/src/test/ble_hs_test.c
@@ -47,7 +47,6 @@ int
 main(void)
 {
     tu_config.tc_print_results = 1;
-    tu_config.tc_system_assert = 1;
     tu_init();
 
     ble_att_clt_test_all();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ddd76b6b/net/nimble/host/src/test/ble_l2cap_sm_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_l2cap_sm_test.c 
b/net/nimble/host/src/test/ble_l2cap_sm_test.c
index 111d66e..1159028 100644
--- a/net/nimble/host/src/test/ble_l2cap_sm_test.c
+++ b/net/nimble/host/src/test/ble_l2cap_sm_test.c
@@ -161,15 +161,14 @@ ble_l2cap_sm_test_util_store_read(int obj_type, union 
ble_store_key *key,
 }
 
 static int
-ble_l2cap_sm_test_util_store_write(int obj_type, union ble_store_key *key,
-                                   union ble_store_value *val)
+ble_l2cap_sm_test_util_store_write(int obj_type, union ble_store_value *val)
 {
     ble_l2cap_sm_test_store_obj_type = obj_type;
 
     switch (obj_type) {
     case BLE_STORE_OBJ_TYPE_OUR_LTK:
-        ble_l2cap_sm_test_saved_ediv = key->ltk.ediv;
-        ble_l2cap_sm_test_saved_rand = key->ltk.rand_num;
+        ble_l2cap_sm_test_saved_ediv = val->ltk.ediv;
+        ble_l2cap_sm_test_saved_rand = val->ltk.rand_num;
         memcpy(ble_l2cap_sm_test_saved_ltk, val->ltk.key, sizeof val->ltk.key);
         ble_l2cap_sm_test_saved_authenticated = val->ltk.authenticated;
         ble_l2cap_sm_test_saved_present = 1;

Reply via email to