You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/06/15 02:27:23 UTC

[01/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Don't change enc status on SMP timeout.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop dba2288bb -> 4739392c0


BLE Host - Don't change enc status on SMP timeout.


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

Branch: refs/heads/develop
Commit: 3550530574c04da35d028641ec20c1e2f9c78ae3
Parents: 466a619
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 7 08:07:48 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:33 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/35505305/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 f4b384b..32c2583 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -2034,9 +2034,11 @@ ble_sm_heartbeat(void)
 
     /* Notify application of each failure and free the corresponding procedure
      * object.
+     * XXX: Mark connection as tainted; don't allow any subsequent SMP
+     * procedures without reconnect.
      */
     while ((proc = STAILQ_FIRST(&exp_list)) != NULL) {
-        ble_sm_enc_event(proc, BLE_HS_ETIMEOUT, 0);
+        ble_sm_enc_event(proc, BLE_HS_ETIMEOUT, BLE_SM_ENC_STATE_NO_CHANGE);
 
         STAILQ_REMOVE_HEAD(&exp_list, next);
         ble_sm_proc_free(proc);


[27/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Don't kill SM proc when bad io injected

Posted by cc...@apache.org.
BLE Host - Don't kill SM proc when bad io injected


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

Branch: refs/heads/develop
Commit: d43cb528518d8a473ad395f0b9f19abf44dd8ce2
Parents: 1fd06b5
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 8 19:19:28 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:36 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_sm.h  |  1 +
 net/nimble/host/src/ble_sm.c           | 32 +++++++----
 net/nimble/host/src/test/ble_sm_test.c | 86 ++++++++++++++++++++++++++++-
 3 files changed, 106 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d43cb528/net/nimble/host/include/host/ble_sm.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_sm.h b/net/nimble/host/include/host/ble_sm.h
index cc3b779..51052ea 100644
--- a/net/nimble/host/include/host/ble_sm.h
+++ b/net/nimble/host/include/host/ble_sm.h
@@ -80,6 +80,7 @@
 #define BLE_SM_IOACT_INPUT                      2
 #define BLE_SM_IOACT_DISP                       3
 #define BLE_SM_IOACT_NUMCMP                     4
+#define BLE_SM_IOACT_MAX_PLUS_ONE               5
 
 struct ble_sm_io {
     uint8_t action;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d43cb528/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 49e7d53..4c93110 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -2264,6 +2264,7 @@ ble_sm_inject_io(uint16_t conn_handle, struct ble_sm_io *pkey)
     struct ble_sm_result res;
     struct ble_sm_proc *proc;
     struct ble_sm_proc *prev;
+    int rc;
 
     memset(&res, 0, sizeof res);
 
@@ -2272,19 +2273,19 @@ ble_sm_inject_io(uint16_t conn_handle, struct ble_sm_io *pkey)
     proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_NONE, -1, &prev);
 
     if (proc == NULL) {
-        res.app_status = BLE_HS_ENOENT;
+        rc = BLE_HS_ENOENT;
     } else if (proc->flags & BLE_SM_PROC_F_IO_INJECTED) {
-        res.app_status = BLE_HS_EALREADY;
+        rc = BLE_HS_EALREADY;
     } else if (pkey->action != ble_sm_io_action(proc)) {
-        /* Response doesn't match what we asked for. */
-        res.app_status = BLE_HS_EINVAL;
-        res.sm_err = BLE_SM_ERR_PASSKEY;
+        /* Application provided incorrect IO type. */
+        rc = BLE_HS_EINVAL;
     } else if (ble_sm_ioact_state(pkey->action) != proc->state) {
         /* Procedure is not ready for user input. */
-        res.app_status = BLE_HS_EINVAL;
-        res.sm_err = BLE_SM_ERR_UNSPECIFIED;
+        rc = BLE_HS_EINVAL;
     } else {
-        /* Add the passkey range. */
+        /* Assume valid input. */
+        rc = 0;
+
         switch (pkey->action) {
         case BLE_SM_IOACT_OOB:
             if (pkey->oob == NULL) {
@@ -2304,8 +2305,7 @@ ble_sm_inject_io(uint16_t conn_handle, struct ble_sm_io *pkey)
         case BLE_SM_IOACT_INPUT:
         case BLE_SM_IOACT_DISP:
             if (pkey->passkey > 999999) {
-                res.app_status = BLE_HS_EINVAL;
-                res.sm_err = BLE_SM_ERR_PASSKEY;
+                rc = BLE_HS_EINVAL;
             } else {
                 proc->flags |= BLE_SM_PROC_F_IO_INJECTED;
                 memset(proc->tk, 0, 16);
@@ -2336,13 +2336,21 @@ ble_sm_inject_io(uint16_t conn_handle, struct ble_sm_io *pkey)
             break;
 
         default:
-            res.sm_err = BLE_SM_ERR_UNSPECIFIED;
-            res.app_status = BLE_HS_EINVAL;
+            BLE_HS_DBG_ASSERT(0);
+            rc = BLE_HS_EINVAL;
+            break;
         }
     }
 
     ble_hs_unlock();
 
+    /* If application provided invalid input, return error without modifying
+     * SMP state.
+     */
+    if (rc != 0) {
+        return rc;
+    }
+
     ble_sm_process_result(conn_handle, &res);
     return res.app_status;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d43cb528/net/nimble/host/src/test/ble_sm_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test.c b/net/nimble/host/src/test/ble_sm_test.c
index 4c497db..e7496d2 100644
--- a/net/nimble/host/src/test/ble_sm_test.c
+++ b/net/nimble/host/src/test/ble_sm_test.c
@@ -642,6 +642,41 @@ ble_sm_test_util_io_inject(struct ble_sm_test_passkey_info *passkey_info,
 }
 
 static void
+ble_sm_test_util_io_inject_bad(uint16_t conn_handle, uint8_t correct_io_act)
+{
+    struct ble_sm_proc *proc;
+    struct ble_sm_io io;
+    uint8_t io_sm_state;
+    int rc;
+    int i;
+
+    /* Lock mutex to prevent thread-safety assert from failing. */
+    ble_hs_lock();
+    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_NONE, -1, NULL);
+    ble_hs_unlock();
+
+    TEST_ASSERT_FATAL(proc != NULL);
+
+    io_sm_state = ble_sm_ioact_state(correct_io_act);
+
+    for (i = 1; i < BLE_SM_IOACT_MAX_PLUS_ONE; i++) {
+        if (io_sm_state != proc->state  ||
+            i != correct_io_act         ||
+            proc->flags & BLE_SM_PROC_F_IO_INJECTED) {
+
+            io.action = i;
+            rc = ble_sm_inject_io(conn_handle, &io);
+
+            if (proc->flags & BLE_SM_PROC_F_IO_INJECTED) {
+                TEST_ASSERT(rc == BLE_HS_EALREADY);
+            } else {
+                TEST_ASSERT(rc == BLE_HS_EINVAL);
+            }
+        }
+    }
+}
+
+static void
 ble_sm_test_util_io_check_pre(struct ble_sm_test_passkey_info *passkey_info,
                               uint8_t cur_sm_state)
 {
@@ -852,33 +887,39 @@ ble_sm_test_util_us_lgcy_good(
     ble_sm_test_util_verify_tx_pair_req(&params->pair_req);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Receive a pair response from the peer. */
     ble_sm_test_util_rx_pair_rsp(2, &params->pair_rsp, 0);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Ensure we sent the expected pair confirm. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_pair_confirm(&params->confirm_req);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Receive a pair confirm from the peer. */
     ble_sm_test_util_rx_confirm(2, &params->confirm_rsp);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Ensure we sent the expected pair random. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_pair_random(&params->random_req);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Receive a pair random from the peer. */
     ble_sm_test_util_rx_random(2, &params->random_rsp, 0);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Ensure keys are distributed, if necessary. */
     if (params->has_enc_info_req) {
@@ -888,9 +929,10 @@ ble_sm_test_util_us_lgcy_good(
     /* Ensure we sent the expected start encryption command. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_start_enc(2, params->r, params->ediv,
-                                               params->stk);
+                                         params->stk);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Receive an encryption changed event. */
     ble_sm_test_util_rx_enc_change(2, 0, 1);
@@ -1005,20 +1047,24 @@ ble_sm_test_util_peer_lgcy_fail_confirm(
     /* Receive a pair request from the peer. */
     ble_sm_test_util_rx_pair_req(2, pair_req, 0);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
 
     /* Ensure we sent the expected pair response. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_pair_rsp(pair_rsp);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
 
     /* Receive a pair confirm from the peer. */
     ble_sm_test_util_rx_confirm(2, confirm_req);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
 
     /* Ensure we sent the expected pair confirm. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_pair_confirm(confirm_rsp);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
 
     /* Receive a pair random from the peer. */
     ble_sm_test_util_rx_random(
@@ -1105,12 +1151,14 @@ ble_sm_test_util_peer_lgcy_good_once(struct ble_sm_test_lgcy_params *params)
     ble_sm_test_util_rx_pair_req(2, &params->pair_req, 0);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Ensure we sent the expected pair response. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_pair_rsp(&params->pair_rsp);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     ble_sm_test_util_io_check_pre(&params->passkey_info,
                                   BLE_SM_PROC_STATE_CONFIRM);
@@ -1119,6 +1167,7 @@ ble_sm_test_util_peer_lgcy_good_once(struct ble_sm_test_lgcy_params *params)
     ble_sm_test_util_rx_confirm(2, &params->confirm_req);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     ble_sm_test_util_io_check_post(&params->passkey_info,
                                    BLE_SM_PROC_STATE_CONFIRM);
@@ -1128,28 +1177,33 @@ ble_sm_test_util_peer_lgcy_good_once(struct ble_sm_test_lgcy_params *params)
     ble_sm_test_util_verify_tx_pair_confirm(&params->confirm_rsp);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Receive a pair random from the peer. */
     ble_sm_test_util_rx_random(2, &params->random_req, 0);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Ensure we sent the expected pair random. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_pair_random(&params->random_rsp);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Receive a long term key request from the controller. */
     ble_sm_test_util_set_lt_key_req_reply_ack(0, 2);
     ble_sm_test_util_rx_lt_key_req(2, params->r, params->ediv);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Ensure we sent the expected long term key request reply command. */
     ble_sm_test_util_verify_tx_lt_key_req_reply(2, params->stk);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Receive an encryption changed event. */
     ble_sm_test_util_rx_enc_change(2, 0, 1);
@@ -1256,11 +1310,13 @@ ble_sm_test_util_peer_bonding_good(int send_enc_req, uint8_t *ltk,
 
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
 
     /* Ensure we sent the expected long term key request reply command. */
     ble_sm_test_util_verify_tx_lt_key_req_reply(2, value_sec.ltk);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
 
     /* Receive an encryption changed event. */
     ble_sm_test_util_rx_enc_change(2, 0, 1);
@@ -1386,23 +1442,27 @@ ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
     ble_sm_test_util_rx_pair_req(2, &params->pair_req, 0);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Ensure we sent the expected pair response. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_pair_rsp(&params->pair_rsp);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Receive a public key from the peer. */
     ble_sm_test_util_rx_public_key(2, &params->public_key_req);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Ensure we sent the expected public key. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_public_key(&params->public_key_rsp);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     switch (params->pair_alg) {
     case BLE_SM_PAIR_ALG_PASSKEY:
@@ -1425,6 +1485,8 @@ ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
             ble_sm_test_util_rx_confirm(2, params->confirm_req + i);
             TEST_ASSERT(!conn->bhc_sec_state.encrypted);
             TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+            ble_sm_test_util_io_inject_bad(
+                2, params->passkey_info.passkey.action);
 
             if (i < num_iters - 1) {
                 ble_sm_dbg_set_next_pair_rand(
@@ -1442,17 +1504,20 @@ ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
         ble_sm_test_util_verify_tx_pair_confirm(params->confirm_rsp + i);
         TEST_ASSERT(!conn->bhc_sec_state.encrypted);
         TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+        ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
         /* Receive a pair random from the peer. */
         ble_sm_test_util_rx_random(2, params->random_req + i, 0);
         TEST_ASSERT(!conn->bhc_sec_state.encrypted);
         TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+        ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
         /* Ensure we sent the expected pair random. */
         ble_hs_test_util_tx_all();
         ble_sm_test_util_verify_tx_pair_random(params->random_rsp + i);
         TEST_ASSERT(!conn->bhc_sec_state.encrypted);
         TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+        ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     }
 
@@ -1463,6 +1528,7 @@ ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
     ble_sm_test_util_rx_dhkey_check(2, &params->dhkey_check_req, 0);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     ble_sm_test_util_io_check_post(&params->passkey_info,
                                    BLE_SM_PROC_STATE_DHKEY_CHECK);
@@ -1472,17 +1538,20 @@ ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
     ble_sm_test_util_verify_tx_dhkey_check(&params->dhkey_check_rsp);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Receive a long term key request from the controller. */
     ble_sm_test_util_set_lt_key_req_reply_ack(0, 2);
     ble_sm_test_util_rx_lt_key_req(2, 0, 0);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Ensure we sent the expected long term key request reply command. */
     ble_sm_test_util_verify_tx_lt_key_req_reply(2, params->ltk);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Receive an encryption changed event. */
     ble_sm_test_util_rx_enc_change(2, 0, 1);
@@ -1576,22 +1645,26 @@ ble_sm_test_util_us_sc_good(struct ble_sm_test_sc_params *params)
     ble_sm_test_util_verify_tx_pair_req(&params->pair_req);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Receive a pair response from the peer. */
     ble_sm_test_util_rx_pair_rsp(2, &params->pair_rsp, 0);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Ensure we sent the expected public key. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_public_key(&params->public_key_req);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Receive a public key from the peer. */
     ble_sm_test_util_rx_public_key(2, &params->public_key_rsp);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     switch (params->pair_alg) {
     case BLE_SM_PAIR_ALG_PASSKEY:
@@ -1620,23 +1693,28 @@ ble_sm_test_util_us_sc_good(struct ble_sm_test_sc_params *params)
             ble_sm_test_util_verify_tx_pair_confirm(params->confirm_req + i);
             TEST_ASSERT(!conn->bhc_sec_state.encrypted);
             TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+            ble_sm_test_util_io_inject_bad(
+                2, params->passkey_info.passkey.action);
         }
 
         /* Receive a pair confirm from the peer. */
         ble_sm_test_util_rx_confirm(2, params->confirm_rsp + i);
         TEST_ASSERT(!conn->bhc_sec_state.encrypted);
         TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+        ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
         /* Ensure we sent the expected pair random. */
         ble_hs_test_util_tx_all();
         ble_sm_test_util_verify_tx_pair_random(params->random_req + i);
         TEST_ASSERT(!conn->bhc_sec_state.encrypted);
         TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+        ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
         /* Receive a pair random from the peer. */
         ble_sm_test_util_rx_random(2, params->random_rsp + i, 0);
         TEST_ASSERT(!conn->bhc_sec_state.encrypted);
         TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+        ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
     }
 
     ble_sm_test_util_io_inject(&params->passkey_info,
@@ -1647,17 +1725,20 @@ ble_sm_test_util_us_sc_good(struct ble_sm_test_sc_params *params)
     ble_sm_test_util_verify_tx_dhkey_check(&params->dhkey_check_req);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Receive a dhkey check from the peer. */
     ble_sm_test_util_rx_dhkey_check(2, &params->dhkey_check_rsp, 0);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Ensure we sent the expected start encryption command. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_start_enc(2, 0, 0, params->ltk);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Receive an encryption changed event. */
     ble_sm_test_util_rx_enc_change(2, 0, 1);
@@ -1719,6 +1800,7 @@ ble_sm_test_util_us_fail_inval(
     ble_sm_test_util_verify_tx_pair_req(&params->pair_req);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
 
     /* Receive a pair response from the peer. */
     ble_sm_test_util_rx_pair_rsp(
@@ -1806,6 +1888,7 @@ ble_sm_test_util_us_bonding_good(int send_enc_req, uint8_t *ltk,
     ble_sm_test_util_verify_tx_start_enc(2, rand_num, ediv, ltk);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
 
     /* Receive an encryption changed event. */
     ble_sm_test_util_rx_enc_change(2, 0, 1);
@@ -1946,6 +2029,7 @@ TEST_CASE(ble_sm_test_case_conn_broken)
     rc = ble_hs_test_util_security_initiate(2, 0);
     TEST_ASSERT_FATAL(rc == 0);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
 
     /* Terminate the connection. */
     disconn_evt.connection_handle = 2;


[34/50] [abbrv] incubator-mynewt-core git commit: bletiny - print xchgd keys in big endian.

Posted by cc...@apache.org.
bletiny - print xchgd keys in big endian.


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

Branch: refs/heads/develop
Commit: ca2804185e6a936e57016e31c61e0993b56d3d51
Parents: 89d36b5
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jun 10 09:59:22 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:39 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/cmd.c | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ca280418/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 4dbdcc5..88de789 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -1822,6 +1822,7 @@ cmd_keystore_parse_valuedata(int argc, char **argv,
             rc = parse_arg_byte_stream_exact_length("ltk", out->sec.ltk, 16);
             if (rc == 0) {
                 out->sec.ltk_present = 1;
+                swap_in_place(out->sec.ltk, 16);
                 valcnt++;
             } else if (rc != ENOENT) {
                 return rc;
@@ -1829,6 +1830,7 @@ cmd_keystore_parse_valuedata(int argc, char **argv,
             rc = parse_arg_byte_stream_exact_length("irk", out->sec.irk, 16);
             if (rc == 0) {
                 out->sec.irk_present = 1;
+                swap_in_place(out->sec.irk, 16);
                 valcnt++;
             } else if (rc != ENOENT) {
                 return rc;
@@ -1836,6 +1838,7 @@ cmd_keystore_parse_valuedata(int argc, char **argv,
             rc = parse_arg_byte_stream_exact_length("csrk", out->sec.csrk, 16);
             if (rc == 0) {
                 out->sec.csrk_present = 1;
+                swap_in_place(out->sec.csrk, 16);
                 valcnt++;
             } else if (rc != ENOENT) {
                 return rc;


[25/50] [abbrv] incubator-mynewt-core git commit: BLE Host - always honor ctlr encryption events.

Posted by cc...@apache.org.
BLE Host - always honor ctlr encryption events.

Update a connection's encryption state according to the incoming event,
even if the event is unexpected.


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

Branch: refs/heads/develop
Commit: 7a751686239704027a8eb88783296d6907b5c478
Parents: 4fe1ee7
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 8 18:19:45 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:36 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/misc.c                |   3 +-
 net/nimble/host/include/host/ble_gap.h |   1 -
 net/nimble/host/src/ble_gap.c          |  21 +--
 net/nimble/host/src/ble_gap_priv.h     |   2 +-
 net/nimble/host/src/ble_sm.c           | 228 ++++++++++++++--------------
 net/nimble/host/src/ble_sm_priv.h      |   7 +-
 net/nimble/host/src/test/ble_sm_test.c |  16 --
 7 files changed, 120 insertions(+), 158 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7a751686/apps/bletiny/src/misc.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/misc.c b/apps/bletiny/src/misc.c
index 83c28cd..4e7c97d 100644
--- a/apps/bletiny/src/misc.c
+++ b/apps/bletiny/src/misc.c
@@ -106,10 +106,9 @@ print_conn_desc(struct ble_gap_conn_desc *desc)
                    desc->peer_id_addr_type);
     print_addr(desc->peer_id_addr);
     console_printf(" conn_itvl=%d conn_latency=%d supervision_timeout=%d "
-                   "pair_alg=%d enc_enabled=%d authenticated=%d bonded=%d\n",
+                   "enc_enabled=%d authenticated=%d bonded=%d\n",
                    desc->conn_itvl, desc->conn_latency,
                    desc->supervision_timeout,
-                   desc->sec_state.pair_alg,
                    desc->sec_state.enc_enabled,
                    desc->sec_state.authenticated,
                    desc->sec_state.bonded);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7a751686/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index 4542cdb..5e0bda2 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -102,7 +102,6 @@ struct hci_adv_params;
 #define BLE_GAP_EVENT_NOTIFY                12
 
 struct ble_gap_sec_state {
-    uint8_t pair_alg;
     unsigned enc_enabled:1;
     unsigned authenticated:1;
     unsigned bonded:1;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7a751686/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 d3a07e1..9afe8ee 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -2200,8 +2200,7 @@ ble_gap_passkey_event(uint16_t conn_handle,
 }
 
 void
-ble_gap_enc_event(uint16_t conn_handle, int status,
-                    struct ble_gap_sec_state *sec_state)
+ble_gap_enc_event(uint16_t conn_handle, int status, int security_restored)
 {
 #if !NIMBLE_OPT(SM)
     return;
@@ -2209,19 +2208,10 @@ ble_gap_enc_event(uint16_t conn_handle, int status,
 
     struct ble_gap_conn_ctxt ctxt;
     struct ble_gap_snapshot snap;
-    struct ble_hs_conn *conn;
-
-    ble_hs_lock();
-
-    conn = ble_hs_conn_find(conn_handle);
-    if (conn != NULL) {
-        conn->bhc_sec_state = *sec_state;
-        ble_gap_conn_to_snapshot(conn, &snap);
-    }
-
-    ble_hs_unlock();
+    int rc;
 
-    if (conn == NULL) {
+    rc = ble_gap_find_snapshot(conn_handle, &snap);
+    if (rc != 0) {
         /* No longer connected. */
         return;
     }
@@ -2232,7 +2222,8 @@ ble_gap_enc_event(uint16_t conn_handle, int status,
     ble_gap_call_event_cb(BLE_GAP_EVENT_ENC_CHANGE, &ctxt,
                           snap.cb, snap.cb_arg);
 
-    if (sec_state->bonded) {
+    if (security_restored) {
+        BLE_HS_DBG_ASSERT(snap.desc.sec_state.bonded);
         ble_gatts_bonding_restored(conn_handle);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7a751686/net/nimble/host/src/ble_gap_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap_priv.h b/net/nimble/host/src/ble_gap_priv.h
index 16d42d7..590b0fb 100644
--- a/net/nimble/host/src/ble_gap_priv.h
+++ b/net/nimble/host/src/ble_gap_priv.h
@@ -75,7 +75,7 @@ void ble_gap_rx_param_req(struct hci_le_conn_param_req *evt);
 int ble_gap_rx_l2cap_update_req(uint16_t conn_handle,
                                 struct ble_gap_upd_params *params);
 void ble_gap_enc_event(uint16_t conn_handle, int status,
-                            struct ble_gap_sec_state *sec_state);
+                       int security_restored);
 void ble_gap_passkey_event(uint16_t conn_handle,
                            struct ble_gap_passkey_action *passkey_action);
 void ble_gap_notify_event(uint16_t conn_handle, uint16_t attr_handle,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7a751686/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 97ff226..2bed018 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -54,8 +54,6 @@
 /** Procedure timeout; 30 seconds. */
 #define BLE_SM_TIMEOUT_OS_TICKS             (30 * OS_TICKS_PER_SEC)
 
-#define BLE_SM_ENC_STATE_NO_CHANGE          (-1)
-
 STAILQ_HEAD(ble_sm_proc_list, ble_sm_proc);
 
 typedef void ble_sm_rx_fn(uint16_t conn_handle, uint8_t op,
@@ -454,20 +452,22 @@ ble_sm_proc_remove(struct ble_sm_proc *proc,
 }
 
 static void
-ble_sm_sec_state(struct ble_sm_proc *proc,
-                 struct ble_gap_sec_state *out_sec_state,
-                 int enc_enabled)
+ble_sm_update_sec_state(uint16_t conn_handle, int encrypted,
+                        int authenticated, int bonded)
 {
-    out_sec_state->pair_alg = proc->pair_alg;
-    out_sec_state->enc_enabled = enc_enabled;
+    struct ble_hs_conn *conn;
 
-    if (enc_enabled) {
-        out_sec_state->authenticated =
-                (proc->flags & BLE_SM_PROC_F_AUTHENTICATED) ? 1 : 0;
-        out_sec_state->bonded = (proc->flags & BLE_SM_PROC_F_BONDED) ? 1 : 0;
-    } else {
-        out_sec_state->authenticated = 0;
-        out_sec_state->bonded = 0;
+    conn = ble_hs_conn_find(conn_handle);
+    if (conn != NULL) {
+        conn->bhc_sec_state.enc_enabled = encrypted;
+
+        /* Authentication and bonding are never revoked from a secure link */
+        if (authenticated) {
+            conn->bhc_sec_state.authenticated = 1;
+        }
+        if (bonded) {
+            conn->bhc_sec_state.bonded = 1;
+        }
     }
 }
 
@@ -597,18 +597,9 @@ ble_sm_persist_keys(struct ble_sm_proc *proc)
     ble_store_write_mst_sec(&value_sec);
 }
 
-static void
-ble_sm_enc_event(struct ble_sm_proc *proc, int status, int enc_state)
-{
-    struct ble_gap_sec_state sec_state;
-
-    ble_sm_sec_state(proc, &sec_state, enc_state);
-    ble_gap_enc_event(proc->conn_handle, status, &sec_state);
-}
-
 static int
 ble_sm_proc_matches(struct ble_sm_proc *proc, uint16_t conn_handle,
-                          uint8_t state, int is_initiator)
+                    uint8_t state, int is_initiator)
 {
     int proc_is_initiator;
 
@@ -646,7 +637,7 @@ ble_sm_proc_matches(struct ble_sm_proc *proc, uint16_t conn_handle,
  */
 struct ble_sm_proc *
 ble_sm_proc_find(uint16_t conn_handle, uint8_t state, int is_initiator,
-                       struct ble_sm_proc **out_prev)
+                 struct ble_sm_proc **out_prev)
 {
     struct ble_sm_proc *proc;
     struct ble_sm_proc *prev;
@@ -655,8 +646,7 @@ ble_sm_proc_find(uint16_t conn_handle, uint8_t state, int is_initiator,
 
     prev = NULL;
     STAILQ_FOREACH(proc, &ble_sm_procs, next) {
-        if (ble_sm_proc_matches(proc, conn_handle, state,
-                                      is_initiator)) {
+        if (ble_sm_proc_matches(proc, conn_handle, state, is_initiator)) {
             if (out_prev != NULL) {
                 *out_prev = prev;
             }
@@ -807,7 +797,6 @@ ble_sm_process_result(uint16_t conn_handle, struct ble_sm_result *res)
 {
     struct ble_sm_proc *prev;
     struct ble_sm_proc *proc;
-    struct ble_hs_conn *conn;
     int rm;
 
     rm = 0;
@@ -835,15 +824,6 @@ ble_sm_process_result(uint16_t conn_handle, struct ble_sm_result *res)
             } else {
                 ble_sm_proc_set_timer(proc);
             }
-
-            if (res->enc_cb && res->enc_state == BLE_SM_ENC_STATE_NO_CHANGE) {
-                conn = ble_hs_conn_find(conn_handle);
-                if (conn != NULL) {
-                    res->enc_state = conn->bhc_sec_state.enc_enabled;
-                } else {
-                    res->enc_state = 0;
-                }
-            }
         }
 
         if (res->sm_err != 0) {
@@ -857,8 +837,8 @@ ble_sm_process_result(uint16_t conn_handle, struct ble_sm_result *res)
         }
 
         if (res->enc_cb) {
-            BLE_HS_DBG_ASSERT(rm);
-            ble_sm_enc_event(proc, res->app_status, res->enc_state);
+            BLE_HS_DBG_ASSERT(proc == NULL || rm);
+            ble_gap_enc_event(conn_handle, res->app_status, res->restore);
         }
 
         if (res->app_status == 0 &&
@@ -956,100 +936,108 @@ ble_sm_enc_restore_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
     res->app_status = ble_sm_start_encrypt_tx(cmd);
 }
 
-void
-ble_sm_enc_change_rx(struct hci_encrypt_change *evt)
+static void
+ble_sm_enc_event_rx(uint16_t conn_handle, uint8_t evt_status, int encrypted)
 {
     struct ble_sm_result res;
     struct ble_sm_proc *proc;
-    int do_key_exchange = 0;
+    int authenticated;
+    int bonded;
 
     memset(&res, 0, sizeof res);
 
+    /* Assume no change in authenticated and bonded statuses. */
+    authenticated = 0;
+    bonded = 0;
+
     ble_hs_lock();
-    proc = ble_sm_proc_find(evt->connection_handle, BLE_SM_PROC_STATE_NONE, -1,
-                            NULL);
-    if (proc == NULL) {
-        res.app_status = BLE_HS_ENOENT;
-    } else if (proc->state == BLE_SM_PROC_STATE_ENC_START) {
-        res.enc_state = evt->encryption_enabled & 0x01; /* LE bit. */
-        do_key_exchange = proc->flags & BLE_SM_PROC_F_KEY_EXCHANGE;
-        res.app_status = 0;
-    } else if (proc->state == BLE_SM_PROC_STATE_ENC_RESTORE) {
-        res.enc_state = evt->encryption_enabled & 0x01; /* LE bit. */
-        do_key_exchange = 0;
-        res.app_status = 0;
-    } else {
-        proc = NULL;
-        res.app_status = BLE_HS_ENOENT;
-    }
 
-    if (res.app_status == 0) {
-        if (evt->status != 0) {
-            res.app_status = BLE_HS_HCI_ERR(evt->status);
-            res.enc_cb = 1;
-        } else {
-            if (res.enc_state == 1 && do_key_exchange) {
+    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_NONE, -1, NULL);
+    if (proc != NULL) {
+        switch (proc->state) {
+        case BLE_SM_PROC_STATE_ENC_START:
+            /* We are completing a pairing procedure; keys may need to be
+             * exchanged.
+             */
+            if (evt_status == 0 && proc->flags & BLE_SM_PROC_F_KEY_EXCHANGE) {
+                /* If the responder has any keys to send, it sends them
+                 * first.
+                 */
                 proc->state = BLE_SM_PROC_STATE_KEY_EXCH;
-
-                /* The responder sends its keys first. */
                 if (!(proc->flags & BLE_SM_PROC_F_INITIATOR) ||
                     proc->rx_key_flags == 0) {
 
                     res.execute = 1;
                 }
             } else {
+                /* Failure or no keys to exchange; procedure is complete. */
                 proc->state = BLE_SM_PROC_STATE_NONE;
-                res.enc_cb = 1;
             }
+            if (proc->flags & BLE_SM_PROC_F_AUTHENTICATED) {
+                authenticated = 1;
+            }
+            break;
+
+        case BLE_SM_PROC_STATE_ENC_RESTORE:
+            /* A secure link is being restored via the encryption
+             * procedure.  Keys were exchanged during pairing; they don't
+             * get exchanged again now.  Procedure is complete.
+             */
+            BLE_HS_DBG_ASSERT(!(proc->flags & BLE_SM_PROC_F_KEY_EXCHANGE));
+            proc->state = BLE_SM_PROC_STATE_NONE;
+            if (proc->flags & BLE_SM_PROC_F_AUTHENTICATED) {
+                authenticated = 1;
+            }
+            bonded = 1;
+            res.restore = 1;
+            break;
+
+        default:
+            /* The encryption change event is unexpected.  We take the
+             * controller at its word that the state has changed and we
+             * terminate the procedure.
+             */
+            proc->state = BLE_SM_PROC_STATE_NONE;
+            res.sm_err = BLE_SM_ERR_UNSPECIFIED;
+            break;
         }
     }
 
+    if (evt_status == 0) {
+        /* Set the encrypted state of the connection as indicated in the
+         * event.
+         */
+        ble_sm_update_sec_state(conn_handle, encrypted, authenticated, bonded);
+    }
+
+    /* Unless keys need to be exchanged, notify the application of the security
+     * change.  If key exchange is pending, the application callback is
+     * triggered after exchange completes.
+     */
+    if (proc == NULL || proc->state == BLE_SM_PROC_STATE_NONE) {
+        res.enc_cb = 1;
+        res.app_status = BLE_HS_HCI_ERR(evt_status);
+    }
+
     ble_hs_unlock();
 
-    ble_sm_process_result(evt->connection_handle, &res);
+    ble_sm_process_result(conn_handle, &res);
 }
 
 void
-ble_sm_enc_key_refresh_rx(struct hci_encrypt_key_refresh *evt)
+ble_sm_enc_change_rx(struct hci_encrypt_change *evt)
 {
-    struct ble_sm_result res;
-    struct ble_sm_proc *proc;
-    int do_key_exchange;
-
-    memset(&res, 0, sizeof res);
-
-    ble_hs_lock();
-    proc = ble_sm_proc_find(evt->connection_handle,
-                            BLE_SM_PROC_STATE_ENC_START, -1, NULL);
-    if (proc == NULL) {
-        res.app_status = BLE_HS_ENOENT;
-        do_key_exchange = 0;
-    } else {
-        res.app_status = 0;
-        do_key_exchange = proc->flags & BLE_SM_PROC_F_KEY_EXCHANGE;
-    }
-
-    if (res.app_status == 0) {
-        res.enc_state = BLE_SM_ENC_STATE_NO_CHANGE;
-        if (evt->status != 0) {
-            res.app_status = BLE_HS_HCI_ERR(evt->status);
-            res.enc_cb = 1;
-        } else if (do_key_exchange) {
-            proc->state = BLE_SM_PROC_STATE_KEY_EXCH;
-
-            /* The responder sends its keys first. */
-            if (!(proc->flags & BLE_SM_PROC_F_INITIATOR)) {
-                res.execute = 1;
-            }
-        } else {
-            proc->state = BLE_SM_PROC_STATE_NONE;
-            res.enc_cb = 1;
-        }
-    }
-
-    ble_hs_unlock();
+    /* For encrypted state: read LE-encryption bit; ignore BR/EDR and reserved
+     * bits.
+     */
+    ble_sm_enc_event_rx(evt->connection_handle, evt->status,
+                        evt->encryption_enabled & 0x01);
+}
 
-    ble_sm_process_result(evt->connection_handle, &res);
+void
+ble_sm_enc_key_refresh_rx(struct hci_encrypt_key_refresh *evt)
+{
+    ble_sm_enc_event_rx(evt->connection_handle, evt->status, 1);
 }
 
 /*****************************************************************************
@@ -1176,7 +1164,6 @@ ble_sm_ltk_restore_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
         res->app_status = BLE_HS_ENOENT;
     }
 
-
     if (res->app_status == 0) {
         proc->state = BLE_SM_PROC_STATE_ENC_RESTORE;
     }
@@ -1216,7 +1203,6 @@ ble_sm_ltk_req_rx(struct hci_le_lt_key_req *evt)
         } else {
             proc->conn_handle = evt->connection_handle;
             proc->state = BLE_SM_PROC_STATE_LTK_RESTORE;
-            proc->flags |= BLE_SM_PROC_F_BONDED;
             ble_sm_insert(proc);
         }
     } else if (proc->state == BLE_SM_PROC_STATE_SEC_REQ) {
@@ -1225,7 +1211,6 @@ ble_sm_ltk_req_rx(struct hci_le_lt_key_req *evt)
          */
         bonding = 1;
         proc->state = BLE_SM_PROC_STATE_LTK_RESTORE;
-        proc->flags |= BLE_SM_PROC_F_BONDED;
     } else if (proc->state == BLE_SM_PROC_STATE_LTK_START) {
         /* Short-term key pairing just completed.  Send the short term key to
          * the controller.
@@ -1715,6 +1700,19 @@ ble_sm_sec_req_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
  *****************************************************************************/
 
 static void
+ble_sm_key_exch_success(struct ble_sm_proc *proc, struct ble_sm_result *res)
+{
+    /* The procedure is now complete.  Update connection bonded state and
+     * terminate procedure.
+     */
+    ble_sm_update_sec_state(proc->conn_handle, 1, 0, 1);
+    proc->state = BLE_SM_PROC_STATE_NONE;
+
+    res->app_status = 0;
+    res->enc_cb = 1;
+}
+
+static void
 ble_sm_key_exch_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
                      void *arg)
 {
@@ -1812,10 +1810,7 @@ ble_sm_key_exch_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
 
     if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
         /* The procedure is now complete. */
-        proc->flags |= BLE_SM_PROC_F_BONDED;
-        proc->state = BLE_SM_PROC_STATE_NONE;
-        res->enc_state = 1;
-        res->enc_cb = 1;
+        ble_sm_key_exch_success(proc, res);
     }
 
     return;
@@ -1838,10 +1833,7 @@ ble_sm_key_rxed(struct ble_sm_proc *proc, struct ble_sm_result *res)
         if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
             res->execute = 1;
         } else {
-            proc->flags |= BLE_SM_PROC_F_BONDED;
-            proc->state = BLE_SM_PROC_STATE_NONE;
-            res->enc_state = 1;
-            res->enc_cb = 1;
+            ble_sm_key_exch_success(proc, res);
         }
     }
 }
@@ -2071,7 +2063,7 @@ ble_sm_heartbeat(void)
      * procedures without reconnect.
      */
     while ((proc = STAILQ_FIRST(&exp_list)) != NULL) {
-        ble_sm_enc_event(proc, BLE_HS_ETIMEOUT, BLE_SM_ENC_STATE_NO_CHANGE);
+        ble_gap_enc_event(proc->conn_handle, BLE_HS_ETIMEOUT, 0);
 
         STAILQ_REMOVE_HEAD(&exp_list, next);
         ble_sm_proc_free(proc);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7a751686/net/nimble/host/src/ble_sm_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_priv.h b/net/nimble/host/src/ble_sm_priv.h
index 5b6e157..fe5308e 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -218,8 +218,7 @@ struct ble_sm_dhkey_check {
 #define BLE_SM_PROC_F_ADVANCE_ON_IO         0x04
 #define BLE_SM_PROC_F_AUTHENTICATED         0x08
 #define BLE_SM_PROC_F_KEY_EXCHANGE          0x10
-#define BLE_SM_PROC_F_BONDED                0x20
-#define BLE_SM_PROC_F_SC                    0x40
+#define BLE_SM_PROC_F_SC                    0x20
 
 #define BLE_SM_KE_F_ENC_INFO                0x01
 #define BLE_SM_KE_F_MASTER_ID               0x02
@@ -286,9 +285,7 @@ struct ble_sm_result {
     unsigned execute:1;
     unsigned enc_cb:1;
     unsigned persist_keys:1;
-
-    /* 0=disabled; 1=enabled; -1=no-change. */
-    uint8_t enc_state;
+    unsigned restore:1;
 };
 
 #ifdef BLE_HS_DEBUG

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7a751686/net/nimble/host/src/test/ble_sm_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test.c b/net/nimble/host/src/test/ble_sm_test.c
index 50900d3..7e7fd96 100644
--- a/net/nimble/host/src/test/ble_sm_test.c
+++ b/net/nimble/host/src/test/ble_sm_test.c
@@ -901,13 +901,10 @@ ble_sm_test_util_us_lgcy_good(
     /* Verify that security callback was executed. */
     TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
     TEST_ASSERT(ble_sm_test_gap_status == 0);
-    TEST_ASSERT(ble_sm_test_sec_state.pair_alg == params->pair_alg);
     TEST_ASSERT(ble_sm_test_sec_state.enc_enabled);
     TEST_ASSERT(!ble_sm_test_sec_state.authenticated);
 
     /* Verify that connection has correct security state. */
-    TEST_ASSERT(ble_sm_test_sec_state.pair_alg ==
-                conn->bhc_sec_state.pair_alg);
     TEST_ASSERT(ble_sm_test_sec_state.enc_enabled ==
                 conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
@@ -1038,14 +1035,10 @@ ble_sm_test_util_peer_lgcy_fail_confirm(
     TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
     TEST_ASSERT(ble_sm_test_gap_status ==
                 BLE_HS_SM_US_ERR(BLE_SM_ERR_CONFIRM_MISMATCH));
-    TEST_ASSERT(ble_sm_test_sec_state.pair_alg ==
-                BLE_SM_PAIR_ALG_JW);
     TEST_ASSERT(!ble_sm_test_sec_state.enc_enabled);
     TEST_ASSERT(!ble_sm_test_sec_state.authenticated);
 
     /* Verify that connection has correct security state. */
-    TEST_ASSERT(ble_sm_test_sec_state.pair_alg ==
-                conn->bhc_sec_state.pair_alg);
     TEST_ASSERT(ble_sm_test_sec_state.enc_enabled ==
                 conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
@@ -1171,14 +1164,11 @@ ble_sm_test_util_peer_lgcy_good_once(struct ble_sm_test_lgcy_params *params)
     /* Verify that security callback was executed. */
     TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
     TEST_ASSERT(ble_sm_test_gap_status == 0);
-    TEST_ASSERT(ble_sm_test_sec_state.pair_alg == params->pair_alg);
     TEST_ASSERT(ble_sm_test_sec_state.enc_enabled);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
                 params->authenticated);
 
     /* Verify that connection has correct security state. */
-    TEST_ASSERT(ble_sm_test_sec_state.pair_alg ==
-                conn->bhc_sec_state.pair_alg);
     TEST_ASSERT(ble_sm_test_sec_state.enc_enabled ==
                 conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
@@ -1503,14 +1493,11 @@ ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
     /* Verify that security callback was executed. */
     TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
     TEST_ASSERT(ble_sm_test_gap_status == 0);
-    TEST_ASSERT(ble_sm_test_sec_state.pair_alg == params->pair_alg);
     TEST_ASSERT(ble_sm_test_sec_state.enc_enabled);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
                 params->authenticated);
 
     /* Verify that connection has correct security state. */
-    TEST_ASSERT(ble_sm_test_sec_state.pair_alg ==
-                conn->bhc_sec_state.pair_alg);
     TEST_ASSERT(ble_sm_test_sec_state.enc_enabled ==
                 conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
@@ -1681,14 +1668,11 @@ ble_sm_test_util_us_sc_good(struct ble_sm_test_sc_params *params)
     /* Verify that security callback was executed. */
     TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
     TEST_ASSERT(ble_sm_test_gap_status == 0);
-    TEST_ASSERT(ble_sm_test_sec_state.pair_alg == params->pair_alg);
     TEST_ASSERT(ble_sm_test_sec_state.enc_enabled);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
                 params->authenticated);
 
     /* Verify that connection has correct security state. */
-    TEST_ASSERT(ble_sm_test_sec_state.pair_alg ==
-                conn->bhc_sec_state.pair_alg);
     TEST_ASSERT(ble_sm_test_sec_state.enc_enabled ==
                 conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==


[22/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Don't print status for no-op event.

Posted by cc...@apache.org.
BLE Host - Don't print status for no-op event.


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

Branch: refs/heads/develop
Commit: 1fd06b576827f23f2070d736c2d59ca68c60403c
Parents: a5f37f2
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 8 18:46:27 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:36 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/host_dbg.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1fd06b57/net/nimble/host/src/host_dbg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_dbg.c b/net/nimble/host/src/host_dbg.c
index 6303f62..d7a31e3 100644
--- a/net/nimble/host/src/host_dbg.c
+++ b/net/nimble/host/src/host_dbg.c
@@ -325,18 +325,30 @@ host_hci_dbg_cmd_complete_disp(uint8_t *evdata, uint8_t len)
     uint8_t status;
     uint16_t opcode;
 
+    if (len < 3) {
+        BLE_HS_LOG(DEBUG, "Invalid command complete: len=%d "
+                          "(expected >= 3)", len);
+        goto done;
+    }
+
     cmd_pkts = evdata[0];
     opcode = le16toh(evdata + 1);
     ogf = BLE_HCI_OGF(opcode);
     ocf = BLE_HCI_OCF(opcode);
+
+    BLE_HS_LOG(DEBUG, "Command complete: cmd_pkts=%u ogf=0x%x ocf=0x%x",
+               cmd_pkts, ogf, ocf);
+
+    if (len == 3) {
+        goto done;
+    }
+
     status = evdata[3];
+    BLE_HS_LOG(DEBUG, " status=%u ", status);
 
     /* Move past header and status */
     evdata += 4;
 
-    BLE_HS_LOG(DEBUG, "Command Complete: cmd_pkts=%u ogf=0x%x ocf=0x%x "
-                      "status=%u ", cmd_pkts, ogf, ocf, status);
-
     /* Display parameters based on command. */
     switch (ogf) {
     case BLE_HCI_OGF_INFO_PARAMS:
@@ -398,6 +410,8 @@ host_hci_dbg_cmd_complete_disp(uint8_t *evdata, uint8_t len)
     default:
         break;
     }
+
+done:
     BLE_HS_LOG(DEBUG, "\n");
 }
 


[15/50] [abbrv] incubator-mynewt-core git commit: BLE Host - SM SC: Log public / private keys.

Posted by cc...@apache.org.
BLE Host - SM SC: Log public / private keys.


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

Branch: refs/heads/develop
Commit: 4fe1ee7aded29053554b28b480d57971065c3a5c
Parents: ef29171
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 8 15:06:07 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:35 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm_alg.c | 7 +++++++
 1 file changed, 7 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4fe1ee7a/net/nimble/host/src/ble_sm_alg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_alg.c b/net/nimble/host/src/ble_sm_alg.c
index 1885d09..89d735a 100644
--- a/net/nimble/host/src/ble_sm_alg.c
+++ b/net/nimble/host/src/ble_sm_alg.c
@@ -491,6 +491,13 @@ ble_sm_alg_gen_key_pair(void *pub, uint32_t *priv)
     memcpy(pub + 0, pkey.x, 32);
     memcpy(pub + 32, pkey.y, 32);
 
+    BLE_HS_LOG(DEBUG, "our pubkey=");
+    ble_hs_misc_log_flat_buf(pub, 64);
+    BLE_HS_LOG(DEBUG, "\n");
+    BLE_HS_LOG(DEBUG, "our privkey=");
+    ble_hs_misc_log_flat_buf(priv, 32);
+    BLE_HS_LOG(DEBUG, "\n");
+
     return 0;
 }
 


[08/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Always use effective addrs during SMP.

Posted by cc...@apache.org.
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 <cc...@apache.org>
Authored: Tue Jun 7 22:38:48 2016 +0800
Committer: Christopher Collins <cc...@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);


[44/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Search DB when initiating security.

Posted by cc...@apache.org.
BLE Host - Search DB when initiating security.


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

Branch: refs/heads/develop
Commit: 7792ec58b93c914698df77c9f2db3d848e844b13
Parents: ad243cf
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 14 12:36:57 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:24:36 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/bletiny.h    |  1 +
 apps/bletiny/src/cmd.c        | 27 ++++++++++++++++++++++++---
 apps/bletiny/src/main.c       | 13 +++++++++++++
 net/nimble/host/src/ble_gap.c | 32 +++++++++++++++++++++++++++-----
 4 files changed, 65 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7792ec58/apps/bletiny/src/bletiny.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny.h b/apps/bletiny/src/bletiny.h
index b66a301..60c80c7 100644
--- a/apps/bletiny/src/bletiny.h
+++ b/apps/bletiny/src/bletiny.h
@@ -172,6 +172,7 @@ int bletiny_datalen(uint16_t conn_handle, uint16_t tx_octets,
 int bletiny_l2cap_update(uint16_t conn_handle,
                           struct ble_l2cap_sig_update_params *params);
 int bletiny_sec_start(uint16_t conn_handle);
+int bletiny_sec_pair(uint16_t conn_handle);
 int bletiny_sec_restart(uint16_t conn_handle, uint8_t *ltk, uint16_t ediv,
                         uint64_t rand_val, int auth);
 int bletiny_tx_start(uint16_t handle, uint16_t len, uint16_t rate,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7792ec58/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 3598bb3..3ac8592 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -1022,6 +1022,26 @@ cmd_show(int argc, char **argv)
  *****************************************************************************/
 
 static int
+cmd_sec_pair(int argc, char **argv)
+{
+    uint16_t conn_handle;
+    int rc;
+
+    conn_handle = parse_arg_uint16("conn", &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    rc = bletiny_sec_pair(conn_handle);
+    if (rc != 0) {
+        console_printf("error initiating pairing; rc=%d\n", rc);
+        return rc;
+    }
+
+    return 0;
+}
+
+static int
 cmd_sec_start(int argc, char **argv)
 {
     uint16_t conn_handle;
@@ -1042,7 +1062,7 @@ cmd_sec_start(int argc, char **argv)
 }
 
 static int
-cmd_sec_restart(int argc, char **argv)
+cmd_sec_enc(int argc, char **argv)
 {
     uint16_t conn_handle;
     uint16_t ediv;
@@ -1079,7 +1099,7 @@ cmd_sec_restart(int argc, char **argv)
     }
 
     if (rc != 0) {
-        console_printf("error starting encryption; rc=%d\n", rc);
+        console_printf("error initiating encryption; rc=%d\n", rc);
         return rc;
     }
 
@@ -1087,8 +1107,9 @@ cmd_sec_restart(int argc, char **argv)
 }
 
 static struct cmd_entry cmd_sec_entries[] = {
+    { "pair", cmd_sec_pair },
     { "start", cmd_sec_start },
-    { "restart", cmd_sec_restart },
+    { "enc", cmd_sec_enc },
 };
 
 static int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7792ec58/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index c8a4840..ad55e68 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1351,6 +1351,19 @@ bletiny_l2cap_update(uint16_t conn_handle,
 }
 
 int
+bletiny_sec_pair(uint16_t conn_handle)
+{
+#if !NIMBLE_OPT(SM)
+    return BLE_HS_ENOTSUP;
+#endif
+
+    int rc;
+
+    rc = ble_sm_pair_initiate(conn_handle);
+    return rc;
+}
+
+int
 bletiny_sec_start(uint16_t conn_handle)
 {
 #if !NIMBLE_OPT(SM)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/7792ec58/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 a7ba2e4..a0fb13c 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -2113,20 +2113,42 @@ ble_gap_security_initiate(uint16_t conn_handle)
     return BLE_HS_ENOTSUP;
 #endif
 
+    struct ble_store_value_sec value_sec;
+    struct ble_store_key_sec key_sec;
+    struct ble_hs_conn_addrs addrs;
     ble_hs_conn_flags_t conn_flags;
+    struct ble_hs_conn *conn;
     int rc;
 
-    rc = ble_hs_atomic_conn_flags(conn_handle, &conn_flags);
-    if (rc != 0) {
-        return rc;
+    ble_hs_lock();
+    conn = ble_hs_conn_find(conn_handle);
+    if (conn != NULL) {
+        conn_flags = conn->bhc_flags;
+        ble_hs_conn_addrs(conn, &addrs);
+
+        memset(&key_sec, 0, sizeof key_sec);
+        key_sec.peer_addr_type = addrs.peer_id_addr_type;
+        memcpy(key_sec.peer_addr, addrs.peer_id_addr, 6);
+    }
+    ble_hs_unlock();
+
+    if (conn == NULL) {
+        return BLE_HS_ENOTCONN;
     }
 
     if (conn_flags & BLE_HS_CONN_F_MASTER) {
-        /* XXX: Search the security database for an LTK for this peer.  If one
+        /* Search the security database for an LTK for this peer.  If one
          * is found, perform the encryption procedure rather than the pairing
          * procedure.
          */
-        rc = ble_sm_pair_initiate(conn_handle);
+        rc = ble_store_read_peer_sec(&key_sec, &value_sec);
+        if (rc == 0 && value_sec.ltk_present) {
+            rc = ble_sm_enc_initiate(conn_handle, value_sec.ltk,
+                                     value_sec.ediv, value_sec.rand_num,
+                                     value_sec.authenticated);
+        } else {
+            rc = ble_sm_pair_initiate(conn_handle);
+        }
     } else {
         rc = ble_sm_slave_initiate(conn_handle);
     }


[17/50] [abbrv] incubator-mynewt-core git commit: Fix resolving INITA in directed advertisement when initiating

Posted by cc...@apache.org.
Fix resolving INITA in directed advertisement when initiating

The code was not correctly handling the resolving of the INITA
when we were the initiator and ther advertiser was sending a
resolvable private address. The code needs to resolve the INITA
and then make sure it is our device address.


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

Branch: refs/heads/develop
Commit: af67329dfbc00d551d4905c42de75a4d5acfa8a0
Parents: 6695d0c
Author: William San Filippo <wi...@runtime.io>
Authored: Tue Jun 7 23:26:13 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:35 2016 -0700

----------------------------------------------------------------------
 net/nimble/controller/src/ble_ll_conn.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/af67329d/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 77d2452..7b69a65 100644
--- a/net/nimble/controller/src/ble_ll_conn.c
+++ b/net/nimble/controller/src/ble_ll_conn.c
@@ -2188,9 +2188,18 @@ ble_ll_init_rx_isr_end(struct os_mbuf *rxpdu, uint8_t crcok)
             inita_is_rpa = (uint8_t)ble_ll_is_rpa(init_addr, addr_type);
         }
 
-        if (!inita_is_rpa && ble_ll_is_our_devaddr(init_addr, addr_type)) {
-            /* We should not respond if we expect the device to be private */
-            if (connsm->own_addr_type <= BLE_HCI_ADV_OWN_ADDR_RANDOM) {
+        /*
+         * If we expect our address to be private and the INITA is not,
+         * we dont respond!
+         */
+        if (connsm->own_addr_type > BLE_HCI_ADV_OWN_ADDR_RANDOM) {
+            if (!inita_is_rpa) {
+                goto init_rx_isr_exit;
+            } else {
+                chk_send_req = 1;
+            }
+        } else {
+            if (ble_ll_is_our_devaddr(init_addr, addr_type)) {
                 chk_send_req = 1;
             }
         }


[45/50] [abbrv] incubator-mynewt-core git commit: BLE Host - unit tests: restore via enc in sc tests

Posted by cc...@apache.org.
BLE Host - unit tests: restore via enc in sc tests


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

Branch: refs/heads/develop
Commit: 67f01929acc32b3efc85264617cf169ffe33b4bb
Parents: 7792ec5
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 14 12:37:24 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:24:37 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/test/ble_sm_test.c      |  58 ------
 net/nimble/host/src/test/ble_sm_test_util.c | 222 +++++++++++------------
 net/nimble/host/src/test/ble_sm_test_util.h |   6 -
 3 files changed, 110 insertions(+), 176 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/67f01929/net/nimble/host/src/test/ble_sm_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test.c b/net/nimble/host/src/test/ble_sm_test.c
index 1252990..12327db 100644
--- a/net/nimble/host/src/test/ble_sm_test.c
+++ b/net/nimble/host/src/test/ble_sm_test.c
@@ -539,25 +539,6 @@ TEST_CASE(ble_sm_test_case_peer_lgcy_passkey_good)
     ble_sm_test_util_peer_lgcy_good(&params);
 }
 
-TEST_CASE(ble_sm_test_case_peer_bonding_good)
-{
-    /* Unauthenticated. */
-    ble_sm_test_util_peer_bonding_good(
-        0,
-        ((uint8_t[16]){ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 }),
-        0,
-        0x1234,
-        0x5678);
-
-    /* Authenticated. */
-    ble_sm_test_util_peer_bonding_good(
-        0,
-        ((uint8_t[16]){ 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 }),
-        1,
-        0x4325,
-        0x543892375);
-}
-
 TEST_CASE(ble_sm_test_case_peer_bonding_bad)
 {
     ble_sm_test_util_peer_bonding_bad(0x5684, 32);
@@ -671,22 +652,6 @@ TEST_CASE(ble_sm_test_case_peer_sec_req_pair)
     ble_sm_test_util_us_lgcy_good(&params);
 }
 
-/**
- * Master: us.
- * Peer sends a security request.
- * We respond by initiating the encryption procedure.
- */
-TEST_CASE(ble_sm_test_case_peer_sec_req_enc)
-{
-    /* Unauthenticated. */
-    ble_sm_test_util_us_bonding_good(
-        1,
-        ((uint8_t[16]){ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 }),
-        0,
-        0x1234,
-        0x5678);
-}
-
 TEST_CASE(ble_sm_test_case_peer_sc_numcmp_good)
 {
     struct ble_sm_test_sc_params params;
@@ -2581,21 +2546,6 @@ TEST_CASE(ble_sm_test_case_us_sc_passkey_good)
     ble_sm_test_util_us_sc_good(&params);
 }
 
-/**
- * Master: peer.
- * We send a security request.
- * We accept an encryption-changed event in response.
- */
-TEST_CASE(ble_sm_test_case_us_sec_req_enc)
-{
-    ble_sm_test_util_peer_bonding_good(
-        1,
-        ((uint8_t[16]){ 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 }),
-        1,
-        0x4325,
-        0x543892375);
-}
-
 TEST_SUITE(ble_sm_test_suite)
 {
     ble_sm_test_case_f4();
@@ -2609,19 +2559,11 @@ TEST_SUITE(ble_sm_test_suite)
     ble_sm_test_case_peer_lgcy_passkey_good();
     ble_sm_test_case_us_fail_inval();
     ble_sm_test_case_us_lgcy_jw_good();
-    ble_sm_test_case_peer_bonding_good();
     ble_sm_test_case_peer_bonding_bad();
     ble_sm_test_case_conn_broken();
     ble_sm_test_case_peer_sec_req_inval();
     ble_sm_test_case_peer_sec_req_pair();
-    ble_sm_test_case_peer_sec_req_enc();
     ble_sm_test_case_us_sec_req_pair();
-    ble_sm_test_case_us_sec_req_enc();
-    ble_sm_test_case_peer_sc_numcmp_good();
-    ble_sm_test_case_peer_sc_passkey_good();
-    ble_sm_test_case_us_sc_jw_good();
-    ble_sm_test_case_us_sc_numcmp_good();
-    ble_sm_test_case_us_sc_passkey_good();
 }
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/67f01929/net/nimble/host/src/test/ble_sm_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test_util.c b/net/nimble/host/src/test/ble_sm_test_util.c
index 45fd5a0..28c2a2a 100644
--- a/net/nimble/host/src/test/ble_sm_test_util.c
+++ b/net/nimble/host/src/test/ble_sm_test_util.c
@@ -1379,24 +1379,17 @@ ble_sm_test_util_peer_lgcy_good(struct ble_sm_test_lgcy_params *params)
     ble_sm_test_util_peer_lgcy_good_once(params);
 }
 
-/**
- * @param send_enc_req          Whether this procedure is initiated by a slave
- *                                  security request;
- *                                  1: We send a security request at start.
- *                                  0: No security request; peer initiates.
- */
-void
-ble_sm_test_util_peer_bonding_good(int send_enc_req, uint8_t *ltk,
-                                   int authenticated,
+static void
+ble_sm_test_util_peer_bonding_good(int send_enc_req,
+                                   uint8_t peer_addr_type,
+                                   uint8_t *peer_addr,
+                                   uint8_t *ltk, int authenticated,
                                    uint16_t ediv, uint64_t rand_num)
 {
-    struct ble_store_value_sec value_sec;
     struct ble_hs_conn *conn;
     int rc;
 
-    ble_sm_test_util_init();
-
-    ble_hs_test_util_create_conn(2, ((uint8_t[6]){1,2,3,4,5,6}),
+    ble_hs_test_util_create_conn(2, peer_addr,
                                  ble_sm_test_util_conn_cb,
                                  NULL);
 
@@ -1413,19 +1406,6 @@ ble_sm_test_util_peer_bonding_good(int send_enc_req, uint8_t *ltk,
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
-    /* Populate the SM database with an LTK for this peer. */
-    value_sec.peer_addr_type = conn->bhc_addr_type;
-    memcpy(value_sec.peer_addr, conn->bhc_addr, sizeof value_sec.peer_addr);
-    value_sec.ediv = ediv;
-    value_sec.rand_num = rand_num;
-    memcpy(value_sec.ltk, ltk, sizeof value_sec.ltk);
-    value_sec.ltk_present = 1;
-    value_sec.authenticated = authenticated;
-    value_sec.sc = 0;
-
-    rc = ble_store_write_our_sec(&value_sec);
-    TEST_ASSERT_FATAL(rc == 0);
-
     if (send_enc_req) {
         rc = ble_sm_slave_initiate(2);
         TEST_ASSERT(rc == 0);
@@ -1450,7 +1430,7 @@ ble_sm_test_util_peer_bonding_good(int send_enc_req, uint8_t *ltk,
     ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
 
     /* Ensure we sent the expected long term key request reply command. */
-    ble_sm_test_util_verify_tx_lt_key_req_reply(2, value_sec.ltk);
+    ble_sm_test_util_verify_tx_lt_key_req_reply(2, ltk);
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
     ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
@@ -1472,6 +1452,8 @@ ble_sm_test_util_peer_bonding_good(int send_enc_req, uint8_t *ltk,
     TEST_ASSERT(ble_sm_test_sec_state.encrypted);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
                 authenticated);
+
+    ble_hs_test_util_conn_disconnect(2);
 }
 
 void
@@ -1521,6 +1503,80 @@ ble_sm_test_util_peer_bonding_bad(uint16_t ediv, uint64_t rand_num)
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 }
 
+/**
+ * @param send_enc_req          Whether this procedure is initiated by a slave
+ *                                  security request;
+ *                                  1: Peer sends a security request at start.
+ *                                  0: No security request; we initiate.
+ */
+static void
+ble_sm_test_util_us_bonding_good(int send_enc_req,
+                                 uint8_t peer_addr_type, uint8_t *peer_addr,
+                                 uint8_t *ltk, int authenticated,
+                                 uint16_t ediv, uint64_t rand_num)
+{
+    struct ble_sm_sec_req sec_req;
+    struct ble_hs_conn *conn;
+
+    ble_hs_test_util_create_conn(2, peer_addr,
+                                 ble_sm_test_util_conn_cb,
+                                 NULL);
+
+    /* This test inspects and modifies the connection object after unlocking
+     * the host mutex.  It is not OK for real code to do this, but this test
+     * can assume the connection list is unchanging.
+     */
+    ble_hs_lock();
+    conn = ble_hs_conn_find(2);
+    TEST_ASSERT_FATAL(conn != NULL);
+    ble_hs_unlock();
+
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    ble_hs_test_util_set_ack(
+        host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_START_ENCRYPT),
+        0);
+
+    if (send_enc_req) {
+        sec_req.authreq = 0;
+        sec_req.authreq |= BLE_SM_PAIR_AUTHREQ_BOND;
+        if (authenticated) {
+            sec_req.authreq |= BLE_SM_PAIR_AUTHREQ_MITM;
+        }
+        ble_sm_test_util_rx_sec_req(2, &sec_req, 0);
+    } else {
+        ble_gap_security_initiate(2);
+    }
+
+    /* Ensure we sent the expected start encryption command. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_start_enc(2, rand_num, ediv, ltk);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
+
+    /* Receive an encryption changed event. */
+    ble_sm_test_util_rx_enc_change(2, 0, 1);
+
+    /* Pairing should now be complete. */
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    /* Verify that security callback was executed. */
+    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
+    TEST_ASSERT(ble_sm_test_gap_status == 0);
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
+                authenticated);
+
+    /* Verify that connection has correct security state. */
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
+                authenticated);
+
+    ble_hs_test_util_conn_disconnect(2);
+}
+
 static void
 ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
 {
@@ -1734,17 +1790,44 @@ ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
 
     /* Verify the appropriate security material was persisted. */
     ble_sm_test_util_verify_sc_persist(params, 0);
+
+    ble_hs_test_util_conn_disconnect(2);
 }
 
 void
 ble_sm_test_util_peer_sc_good(struct ble_sm_test_sc_params *params)
 {
+    /*** Peer is master; peer initiates pairing. */
+
+    /* Peer performs IO first. */
     params->passkey_info.io_before_rx = 0;
     ble_sm_test_util_peer_sc_good_once(params);
 
+    /* We perform IO first. */
     params->passkey_info.io_before_rx = 1;
     ble_sm_test_util_peer_sc_good_once(params);
 
+    /*** Verify link can be restored via the encryption procedure. */
+
+    /* Peer is master; peer initiates procedure. */
+    ble_sm_test_util_peer_bonding_good(0, 0, params->init_addr,
+                                       params->ltk, params->authenticated,
+                                       0, 0);
+
+    /* Peer is master; we initiate procedure via security request. */
+    ble_sm_test_util_peer_bonding_good(1, 0, params->init_addr,
+                                       params->ltk, params->authenticated,
+                                       0, 0);
+
+    /* We are master; we initiate procedure. */
+    ble_sm_test_util_us_bonding_good(0, 0, params->init_addr,
+                                     params->ltk, params->authenticated,
+                                     0, 0);
+
+    /* We are master; peer initiates procedure via security request. */
+    ble_sm_test_util_us_bonding_good(1, 0, params->init_addr,
+                                     params->ltk, params->authenticated,
+                                     0, 0);
 }
 
 void
@@ -2005,88 +2088,3 @@ ble_sm_test_util_us_fail_inval(
     TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(!conn->bhc_sec_state.authenticated);
 }
-
-/**
- * @param send_enc_req          Whether this procedure is initiated by a slave
- *                                  security request;
- *                                  1: Peer sends a security request at start.
- *                                  0: No security request; we initiate.
- */
-void
-ble_sm_test_util_us_bonding_good(int send_enc_req, uint8_t *ltk,
-                                 int authenticated, uint16_t ediv,
-                                 uint64_t rand_num)
-{
-    struct ble_sm_sec_req sec_req;
-    struct ble_store_value_sec value_sec;
-    struct ble_hs_conn *conn;
-    int rc;
-
-    ble_sm_test_util_init();
-
-    ble_hs_test_util_create_conn(2, ((uint8_t[6]){1,2,3,4,5,6}),
-                                 ble_sm_test_util_conn_cb,
-                                 NULL);
-
-    /* This test inspects and modifies the connection object after unlocking
-     * the host mutex.  It is not OK for real code to do this, but this test
-     * can assume the connection list is unchanging.
-     */
-    ble_hs_lock();
-    conn = ble_hs_conn_find(2);
-    TEST_ASSERT_FATAL(conn != NULL);
-    ble_hs_unlock();
-
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    /* Populate the SM database with an LTK for this peer. */
-    value_sec.peer_addr_type = conn->bhc_addr_type;
-    memcpy(value_sec.peer_addr, conn->bhc_addr, sizeof value_sec.peer_addr);
-    value_sec.ediv = ediv;
-    value_sec.rand_num = rand_num;
-    memcpy(value_sec.ltk, ltk, sizeof value_sec.ltk);
-    value_sec.ltk_present = 1;
-    value_sec.authenticated = authenticated;
-    value_sec.sc = 0;
-
-    rc = ble_store_write_peer_sec(&value_sec);
-    TEST_ASSERT_FATAL(rc == 0);
-
-    if (send_enc_req) {
-        sec_req.authreq = 0;
-        sec_req.authreq |= BLE_SM_PAIR_AUTHREQ_BOND;
-        if (authenticated) {
-            sec_req.authreq |= BLE_SM_PAIR_AUTHREQ_MITM;
-        }
-        ble_hs_test_util_set_ack(
-            host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_START_ENCRYPT),
-            0);
-        ble_sm_test_util_rx_sec_req(2, &sec_req, 0);
-    }
-
-    /* Ensure we sent the expected start encryption command. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_start_enc(2, rand_num, ediv, ltk);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
-
-    /* Receive an encryption changed event. */
-    ble_sm_test_util_rx_enc_change(2, 0, 1);
-
-    /* Pairing should now be complete. */
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    /* Verify that security callback was executed. */
-    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
-    TEST_ASSERT(ble_sm_test_gap_status == 0);
-    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
-                authenticated);
-
-    /* Verify that connection has correct security state. */
-    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
-                authenticated);
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/67f01929/net/nimble/host/src/test/ble_sm_test_util.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test_util.h b/net/nimble/host/src/test/ble_sm_test_util.h
index e71aba1..b9dac79 100644
--- a/net/nimble/host/src/test/ble_sm_test_util.h
+++ b/net/nimble/host/src/test/ble_sm_test_util.h
@@ -131,15 +131,9 @@ void ble_sm_test_util_peer_lgcy_fail_confirm(
     struct ble_sm_pair_fail *fail_rsp);
 
 void ble_sm_test_util_peer_lgcy_good(struct ble_sm_test_lgcy_params *params);
-void ble_sm_test_util_peer_bonding_good(int send_enc_req, uint8_t *ltk,
-                                        int authenticated,
-                                        uint16_t ediv, uint64_t rand_num);
 void ble_sm_test_util_peer_bonding_bad(uint16_t ediv, uint64_t rand_num);
 void ble_sm_test_util_peer_sc_good(struct ble_sm_test_sc_params *params);
 void ble_sm_test_util_us_sc_good(struct ble_sm_test_sc_params *params);
 void ble_sm_test_util_us_fail_inval(struct ble_sm_test_lgcy_params *params);
-void ble_sm_test_util_us_bonding_good(int send_enc_req, uint8_t *ltk,
-                                      int authenticated, uint16_t ediv,
-                                      uint64_t rand_num);
 
 #endif


[36/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Add write functions for key exch msgs.

Posted by cc...@apache.org.
BLE Host - Add write functions for key exch msgs.


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

Branch: refs/heads/develop
Commit: 8d06088276ca8500c56185fbc54b0243b02b6c12
Parents: fb4b6cd
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Jun 13 16:22:50 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:40 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm_cmd.c | 66 ++++++++++++++++++++++++++---------
 1 file changed, 50 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8d060882/net/nimble/host/src/ble_sm_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_cmd.c b/net/nimble/host/src/ble_sm_cmd.c
index 40dfc79..4169982 100644
--- a/net/nimble/host/src/ble_sm_cmd.c
+++ b/net/nimble/host/src/ble_sm_cmd.c
@@ -427,22 +427,34 @@ ble_sm_id_info_parse(void *payload, int len, struct ble_sm_id_info *cmd)
     memcpy(cmd->irk, u8ptr, 16);
 }
 
+void
+ble_sm_id_info_write(void *payload, int len, struct ble_sm_id_info *cmd)
+{
+    uint8_t *u8ptr;
+
+    BLE_HS_DBG_ASSERT(len >= BLE_SM_HDR_SZ + BLE_SM_ID_INFO_SZ);
+
+    u8ptr = payload;
+
+    u8ptr[0] = BLE_SM_OP_IDENTITY_INFO;
+    memcpy(u8ptr + BLE_SM_HDR_SZ, cmd->irk, sizeof cmd->irk);
+}
+
 int
 ble_sm_id_info_tx(uint16_t conn_handle, struct ble_sm_id_info *cmd)
 {
     struct os_mbuf *txom;
     int rc;
 
+    BLE_SM_LOG_CMD(1, "id info", conn_handle, ble_sm_id_info_log, cmd);
+
     rc = ble_sm_init_req(BLE_SM_ID_INFO_SZ, &txom);
     if (rc != 0) {
         rc = BLE_HS_ENOMEM;
         goto done;
     }
 
-    txom->om_data[0] = BLE_SM_OP_IDENTITY_INFO;
-    swap_buf(txom->om_data + 1, cmd->irk, sizeof cmd->irk);
-
-    BLE_SM_LOG_CMD(1, "id info", conn_handle, ble_sm_id_info_log, cmd);
+    ble_sm_id_info_write(txom->om_data, txom->om_len, cmd);
 
     rc = ble_sm_tx(conn_handle, txom);
     txom = NULL;
@@ -468,24 +480,37 @@ ble_sm_id_addr_info_parse(void *payload, int len,
     memcpy(cmd->bd_addr, u8ptr + 1, 6);
 }
 
+void
+ble_sm_id_addr_info_write(void *payload, int len,
+                          struct ble_sm_id_addr_info *cmd)
+{
+    uint8_t *u8ptr;
+
+    BLE_HS_DBG_ASSERT(len >= BLE_SM_HDR_SZ + BLE_SM_ID_ADDR_INFO_SZ);
+
+    u8ptr = payload;
+
+    u8ptr[0] = BLE_SM_OP_IDENTITY_ADDR_INFO;
+    u8ptr[1] = cmd->addr_type;
+    memcpy(u8ptr + 2, cmd->bd_addr, sizeof cmd->bd_addr);
+}
+
 int
 ble_sm_id_addr_info_tx(uint16_t conn_handle, struct ble_sm_id_addr_info *cmd)
 {
     struct os_mbuf *txom;
     int rc;
 
+    BLE_SM_LOG_CMD(1, "id addr info", conn_handle, ble_sm_id_addr_info_log,
+                   cmd);
+
     rc = ble_sm_init_req(BLE_SM_ID_ADDR_INFO_SZ, &txom);
     if (rc != 0) {
         rc = BLE_HS_ENOMEM;
         goto done;
     }
 
-    txom->om_data[0] = BLE_SM_OP_IDENTITY_ADDR_INFO;
-    txom->om_data[1] = cmd->addr_type;
-    memcpy(txom->om_data + 2, cmd->bd_addr, sizeof cmd->bd_addr);
-
-    BLE_SM_LOG_CMD(1, "id addr info", conn_handle, ble_sm_id_addr_info_log,
-                   cmd);
+    ble_sm_id_addr_info_write(txom->om_data, txom->om_len, cmd);
 
     rc = ble_sm_tx(conn_handle, txom);
     txom = NULL;
@@ -509,14 +534,26 @@ ble_sm_sign_info_parse(void *payload, int len, struct ble_sm_sign_info *cmd)
     memcpy(cmd->sig_key, u8ptr, 16);
 }
 
+void
+ble_sm_sign_info_write(void *payload, int len, struct ble_sm_sign_info *cmd)
+{
+    uint8_t *u8ptr;
+
+    BLE_HS_DBG_ASSERT(len >= BLE_SM_HDR_SZ + BLE_SM_SIGN_INFO_SZ);
+
+    u8ptr = payload;
+
+    u8ptr[0] = BLE_SM_OP_SIGN_INFO;
+    memcpy(u8ptr + BLE_SM_HDR_SZ, cmd->sig_key, sizeof cmd->sig_key);
+}
+
 int
 ble_sm_sign_info_tx(uint16_t conn_handle, struct ble_sm_sign_info *cmd)
 {
     struct os_mbuf *txom;
     int rc;
 
-    BLE_HS_LOG(DEBUG, "ble_sm_sign_info_tx(); conn_handle=%d irk=");
-    ble_hs_misc_log_flat_buf(cmd->sig_key, sizeof cmd->sig_key);
+    BLE_SM_LOG_CMD(1, "sign info", conn_handle, ble_sm_sign_info_log, cmd);
 
     rc = ble_sm_init_req(BLE_SM_SIGN_INFO_SZ, &txom);
     if (rc != 0) {
@@ -524,10 +561,7 @@ ble_sm_sign_info_tx(uint16_t conn_handle, struct ble_sm_sign_info *cmd)
         goto done;
     }
 
-    txom->om_data[0] = BLE_SM_OP_SIGN_INFO;
-    memcpy(txom->om_data + 1, cmd->sig_key, sizeof cmd->sig_key);
-
-    BLE_SM_LOG_CMD(1, "sign info", conn_handle, ble_sm_sign_info_log, cmd);
+    ble_sm_sign_info_write(txom->om_data, txom->om_len, cmd);
 
     rc = ble_sm_tx(conn_handle, txom);
     txom = NULL;


[37/50] [abbrv] incubator-mynewt-core git commit: BLE Host - ble_hs_addrs() function.

Posted by cc...@apache.org.
BLE Host - ble_hs_addrs() function.


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

Branch: refs/heads/develop
Commit: 80fbd38b8258fd4c4c2f42644a056ee72b86fba1
Parents: 8d06088
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Jun 13 16:23:39 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:40 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_gap.c          | 20 ++++----
 net/nimble/host/src/ble_hs_conn.c      | 79 +++++++----------------------
 net/nimble/host/src/ble_hs_conn_priv.h | 20 +++++---
 net/nimble/host/src/ble_sm.c           | 66 ++++++++----------------
 net/nimble/host/src/ble_sm_priv.h      |  6 ++-
 net/nimble/host/src/ble_sm_sc.c        | 11 ++--
 6 files changed, 71 insertions(+), 131 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/80fbd38b/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 9afe8ee..a7ba2e4 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -273,20 +273,18 @@ static void
 ble_gap_fill_conn_desc(struct ble_hs_conn *conn,
                        struct ble_gap_conn_desc *desc)
 {
-    uint8_t *peer_ota_addr;
-    uint8_t *peer_id_addr;
-    uint8_t *our_ota_addr;
+    struct ble_hs_conn_addrs addrs;
 
-    ble_hs_conn_addrs(conn,
-                      &desc->our_ota_addr_type, &our_ota_addr,
-                      NULL, NULL,
-                      &desc->peer_ota_addr_type, &peer_ota_addr,
-                      &desc->peer_id_addr_type, &peer_id_addr);
+    ble_hs_conn_addrs(conn, &addrs);
+
+    desc->our_ota_addr_type = addrs.our_ota_addr_type;
+    memcpy(desc->our_ota_addr, addrs.our_ota_addr, 6);
+    desc->peer_ota_addr_type = addrs.peer_ota_addr_type;
+    memcpy(desc->peer_ota_addr, addrs.peer_ota_addr, 6);
+    desc->peer_id_addr_type = addrs.peer_id_addr_type;
+    memcpy(desc->peer_id_addr, addrs.peer_id_addr, 6);
 
     desc->conn_handle = conn->bhc_handle;
-    memcpy(desc->peer_ota_addr, peer_ota_addr, 6);
-    memcpy(desc->peer_id_addr, peer_id_addr, 6);
-    memcpy(desc->our_ota_addr, our_ota_addr, 6);
     desc->conn_itvl = conn->bhc_itvl;
     desc->conn_latency = conn->bhc_latency;
     desc->supervision_timeout = conn->bhc_supervision_timeout;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/80fbd38b/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 87374e1..faab9dc 100644
--- a/net/nimble/host/src/ble_hs_conn.c
+++ b/net/nimble/host/src/ble_hs_conn.c
@@ -317,101 +317,58 @@ ble_hs_conn_first(void)
 
 void
 ble_hs_conn_addrs(struct ble_hs_conn *conn,
-                  uint8_t *out_our_ota_addr_type,
-                  uint8_t **out_our_ota_addr,
-                  uint8_t *out_our_id_addr_type,
-                  uint8_t **out_our_id_addr,
-                  uint8_t *out_peer_ota_addr_type,
-                  uint8_t **out_peer_ota_addr,
-                  uint8_t *out_peer_id_addr_type,
-                  uint8_t **out_peer_id_addr)
+                  struct ble_hs_conn_addrs *addrs)
 {
-
-    uint8_t peer_ota_addr_type;
-    uint8_t peer_id_addr_type;
-    uint8_t our_ota_addr_type;
-    uint8_t our_id_addr_type;
-    uint8_t *peer_ota_addr;
-    uint8_t *peer_id_addr;
-    uint8_t *our_ota_addr;
-    uint8_t *our_id_addr;
-
     /* Determine our address information. */
-    our_id_addr =
-        bls_hs_priv_get_local_identity_addr(&our_id_addr_type);
+    addrs->our_id_addr =
+        bls_hs_priv_get_local_identity_addr(&addrs->our_id_addr_type);
     if (memcmp(conn->our_rpa_addr, ble_hs_conn_null_addr, 6) == 0) {
-        our_ota_addr_type = our_id_addr_type;
-        our_ota_addr = our_id_addr;
+        addrs->our_ota_addr = addrs->our_id_addr;
     } else {
-        switch (our_id_addr_type) {
+        switch (addrs->our_id_addr_type) {
         case BLE_ADDR_TYPE_PUBLIC:
-            our_ota_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT;
+            addrs->our_ota_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT;
             break;
 
         case BLE_ADDR_TYPE_RANDOM:
-            our_ota_addr_type = BLE_ADDR_TYPE_RPA_RND_DEFAULT;
+            addrs->our_ota_addr_type = BLE_ADDR_TYPE_RPA_RND_DEFAULT;
             break;
 
         default:
             BLE_HS_DBG_ASSERT(0);
         }
 
-        our_ota_addr = conn->our_rpa_addr;
+        addrs->our_ota_addr = conn->our_rpa_addr;
     }
 
     /* Determine peer address information. */
-    peer_ota_addr_type = conn->bhc_addr_type;
-    peer_id_addr = conn->bhc_addr;
+    addrs->peer_ota_addr_type = conn->bhc_addr_type;
+    addrs->peer_id_addr = conn->bhc_addr;
     switch (conn->bhc_addr_type) {
     case BLE_ADDR_TYPE_PUBLIC:
-        peer_id_addr_type = BLE_ADDR_TYPE_PUBLIC;
-        peer_ota_addr = conn->bhc_addr;
+        addrs->peer_id_addr_type = BLE_ADDR_TYPE_PUBLIC;
+        addrs->peer_ota_addr = conn->bhc_addr;
         break;
 
     case BLE_ADDR_TYPE_RANDOM:
-        peer_id_addr_type = BLE_ADDR_TYPE_RANDOM;
-        peer_ota_addr = conn->bhc_addr;
+        addrs->peer_id_addr_type = BLE_ADDR_TYPE_RANDOM;
+        addrs->peer_ota_addr = conn->bhc_addr;
         break;
 
     case BLE_ADDR_TYPE_RPA_PUB_DEFAULT:
-        peer_id_addr_type = BLE_ADDR_TYPE_PUBLIC;
-        peer_ota_addr = conn->peer_rpa_addr;
+        addrs->peer_id_addr_type = BLE_ADDR_TYPE_PUBLIC;
+        addrs->peer_ota_addr = conn->peer_rpa_addr;
         break;
 
     case BLE_ADDR_TYPE_RPA_RND_DEFAULT:
-        peer_id_addr_type = BLE_ADDR_TYPE_RANDOM;
-        peer_ota_addr = conn->peer_rpa_addr;
+        addrs->peer_id_addr_type = BLE_ADDR_TYPE_RANDOM;
+        addrs->peer_ota_addr = conn->peer_rpa_addr;
         break;
 
     default:
         BLE_HS_DBG_ASSERT(0);
         return;
     }
-
-    if (out_our_ota_addr_type != NULL) {
-        *out_our_ota_addr_type = our_ota_addr_type;
-    }
-    if (out_our_ota_addr != NULL) {
-        *out_our_ota_addr = our_ota_addr;
-    }
-    if (out_our_id_addr_type != NULL) {
-        *out_our_id_addr_type = our_id_addr_type;
-    }
-    if (out_our_id_addr != NULL) {
-        *out_our_id_addr = our_id_addr;
-    }
-    if (out_peer_ota_addr_type != NULL) {
-        *out_peer_ota_addr_type = peer_ota_addr_type;
-    }
-    if (out_peer_ota_addr != NULL) {
-        *out_peer_ota_addr = peer_ota_addr;
-    }
-    if (out_peer_id_addr_type != NULL) {
-        *out_peer_id_addr_type = peer_id_addr_type;
-    }
-    if (out_peer_id_addr != NULL) {
-        *out_peer_id_addr = peer_id_addr;
-    }
 }
 
 static void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/80fbd38b/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 e6d940e..36b483d 100644
--- a/net/nimble/host/src/ble_hs_conn_priv.h
+++ b/net/nimble/host/src/ble_hs_conn_priv.h
@@ -61,6 +61,17 @@ struct ble_hs_conn {
     void *bhc_cb_arg;
 };
 
+struct ble_hs_conn_addrs {
+    uint8_t our_ota_addr_type;
+    uint8_t our_id_addr_type;
+    uint8_t peer_ota_addr_type;
+    uint8_t peer_id_addr_type;
+    uint8_t *our_ota_addr;
+    uint8_t *our_id_addr;
+    uint8_t *peer_ota_addr;
+    uint8_t *peer_id_addr;
+};
+
 int ble_hs_conn_can_alloc(void);
 struct ble_hs_conn *ble_hs_conn_alloc(void);
 void ble_hs_conn_free(struct ble_hs_conn *conn);
@@ -76,14 +87,7 @@ struct ble_l2cap_chan *ble_hs_conn_chan_find(struct ble_hs_conn *conn,
 int ble_hs_conn_chan_insert(struct ble_hs_conn *conn,
                             struct ble_l2cap_chan *chan);
 void ble_hs_conn_addrs(struct ble_hs_conn *conn,
-                       uint8_t *our_ota_addr_type,
-                       uint8_t **our_ota_addr,
-                       uint8_t *our_id_addr_type,
-                       uint8_t **our_id_addr,
-                       uint8_t *peer_ota_addr_type,
-                       uint8_t **peer_ota_addr,
-                       uint8_t *peer_id_addr_type,
-                       uint8_t **peer_id_addr);
+                       struct ble_hs_conn_addrs *addrs);
 
 int ble_hs_conn_init(void);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/80fbd38b/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 6027f50..5dedf98 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -150,8 +150,6 @@ static uint64_t ble_sm_dbg_next_start_rand;
 static uint8_t ble_sm_dbg_next_start_rand_set;
 static uint8_t ble_sm_dbg_next_ltk[16];
 static uint8_t ble_sm_dbg_next_ltk_set;
-static uint8_t ble_sm_dbg_next_irk[16];
-static uint8_t ble_sm_dbg_next_irk_set;
 static uint8_t ble_sm_dbg_next_csrk[16];
 static uint8_t ble_sm_dbg_next_csrk_set;
 static uint8_t ble_sm_dbg_sc_pub_key[64];
@@ -189,14 +187,6 @@ ble_sm_dbg_set_next_ltk(uint8_t *next_ltk)
 }
 
 void
-ble_sm_dbg_set_next_irk(uint8_t *next_irk)
-{
-    memcpy(ble_sm_dbg_next_irk, next_irk,
-           sizeof ble_sm_dbg_next_irk);
-    ble_sm_dbg_next_irk_set = 1;
-}
-
-void
 ble_sm_dbg_set_next_csrk(uint8_t *next_csrk)
 {
     memcpy(ble_sm_dbg_next_csrk, next_csrk,
@@ -526,35 +516,28 @@ ble_sm_ia_ra(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_addrs addrs;
     struct ble_hs_conn *conn;
-    uint8_t *peer_ota_addr;
-    uint8_t *our_ota_addr;
-    uint8_t peer_id_addr_type;
-    uint8_t our_id_addr_type;
 
     conn = ble_hs_conn_find(proc->conn_handle);
     if (conn == NULL) {
         return BLE_HS_ENOTCONN;
     }
 
-    ble_hs_conn_addrs(conn,
-                      NULL, &our_ota_addr,
-                      &our_id_addr_type, NULL,
-                      NULL, &peer_ota_addr,
-                      &peer_id_addr_type, NULL);
+    ble_hs_conn_addrs(conn, &addrs);
 
     if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
-        *out_iat = our_id_addr_type;
-        memcpy(out_ia, our_ota_addr, 6);
+        *out_iat = addrs.our_id_addr_type;
+        memcpy(out_ia, addrs.our_ota_addr, 6);
 
-        *out_rat = peer_id_addr_type;
-        memcpy(out_ra, peer_ota_addr, 6);
+        *out_rat = addrs.peer_id_addr_type;
+        memcpy(out_ra, addrs.peer_ota_addr, 6);
     } else {
-        *out_iat = peer_id_addr_type;
-        memcpy(out_ia, peer_ota_addr, 6);
+        *out_iat = addrs.peer_id_addr_type;
+        memcpy(out_ia, addrs.peer_ota_addr, 6);
 
-        *out_rat = our_id_addr_type;
-        memcpy(out_ra, our_ota_addr, 6);
+        *out_rat = addrs.our_id_addr_type;
+        memcpy(out_ra, addrs.our_ota_addr, 6);
     }
 
     return 0;
@@ -1174,18 +1157,14 @@ int
 ble_sm_ltk_req_rx(struct hci_le_lt_key_req *evt)
 {
     struct ble_store_value_sec value_sec;
+    struct ble_hs_conn_addrs addrs;
     struct ble_sm_result res;
     struct ble_sm_proc *proc;
     struct ble_hs_conn *conn;
-    uint8_t peer_addr[6];
-    uint8_t *peer_id_addr;
-    uint8_t peer_addr_type;
+    uint8_t peer_id_addr[6];
     int store_rc;
     int restore;
 
-    /* Silence gcc warning. */
-    peer_addr_type = BLE_STORE_ADDR_TYPE_NONE;
-
     memset(&res, 0, sizeof res);
 
     ble_hs_lock();
@@ -1233,10 +1212,8 @@ ble_sm_ltk_req_rx(struct hci_le_lt_key_req *evt)
         if (conn == NULL) {
             res.app_status = BLE_HS_ENOTCONN;
         } else {
-            ble_hs_conn_addrs(conn,
-                              NULL, NULL, NULL, NULL,
-                              NULL, NULL, &peer_addr_type, &peer_id_addr);
-            memcpy(peer_addr, peer_id_addr, 6);
+            ble_hs_conn_addrs(conn, &addrs);
+            memcpy(peer_id_addr, addrs.peer_id_addr, 6);
         }
     }
 
@@ -1248,8 +1225,8 @@ ble_sm_ltk_req_rx(struct hci_le_lt_key_req *evt)
 
     if (res.app_status == 0) {
         if (restore) {
-            store_rc = ble_sm_retrieve_ltk(evt, peer_addr_type, peer_addr,
-                                           &value_sec);
+            store_rc = ble_sm_retrieve_ltk(evt, addrs.peer_id_addr_type,
+                                           peer_id_addr, &value_sec);
             if (store_rc == 0) {
                 /* Send the key to the controller. */
                 res.state_arg = &value_sec;
@@ -1631,11 +1608,11 @@ static void
 ble_sm_sec_req_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
                   struct ble_sm_result *res)
 {
-    struct ble_sm_sec_req cmd;
     struct ble_store_value_sec value_sec;
     struct ble_store_key_sec key_sec;
+    struct ble_hs_conn_addrs addrs;
+    struct ble_sm_sec_req cmd;
     struct ble_hs_conn *conn;
-    uint8_t *peer_id_addr;
     int authreq_mitm;
 
     res->app_status = ble_hs_misc_pullup_base(om, BLE_SM_SEC_REQ_SZ);
@@ -1664,11 +1641,10 @@ ble_sm_sec_req_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
          * sender; remember the sender's address while the connection list is
          * locked.
          */
-        ble_hs_conn_addrs(conn,
-                          NULL, NULL, NULL, NULL,
-                          NULL, NULL, &key_sec.peer_addr_type, &peer_id_addr);
+        ble_hs_conn_addrs(conn, &addrs);
         memset(&key_sec, 0, sizeof key_sec);
-        memcpy(key_sec.peer_addr, peer_id_addr, 6);
+        key_sec.peer_addr_type = addrs.peer_id_addr_type;
+        memcpy(key_sec.peer_addr, addrs.peer_id_addr, 6);
     }
 
     ble_hs_unlock();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/80fbd38b/net/nimble/host/src/ble_sm_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_priv.h b/net/nimble/host/src/ble_sm_priv.h
index cda5cce..1af1d66 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -293,7 +293,6 @@ void ble_sm_dbg_set_next_pair_rand(uint8_t *next_pair_rand);
 void ble_sm_dbg_set_next_ediv(uint16_t next_ediv);
 void ble_sm_dbg_set_next_start_rand(uint64_t next_start_rand);
 void ble_sm_dbg_set_next_ltk(uint8_t *next_ltk);
-void ble_sm_dbg_set_next_irk(uint8_t *next_irk);
 void ble_sm_dbg_set_next_csrk(uint8_t *next_csrk);
 void ble_sm_dbg_set_sc_keys(uint8_t *pubkey, uint8_t *privkey);
 int ble_sm_dbg_num_procs(void);
@@ -341,15 +340,20 @@ int ble_sm_master_id_tx(uint16_t conn_handle, struct ble_sm_master_id *cmd);
 void ble_sm_master_id_log(struct ble_sm_master_id *cmd);
 void ble_sm_id_info_parse(void *payload, int len, struct ble_sm_id_info *cmd);
 int ble_sm_id_info_tx(uint16_t conn_handle, struct ble_sm_id_info *cmd);
+void ble_sm_id_info_write(void *payload, int len, struct ble_sm_id_info *cmd);
 void ble_sm_id_info_log(struct ble_sm_id_info *cmd);
 void ble_sm_id_addr_info_parse(void *payload, int len,
                             struct ble_sm_id_addr_info *cmd);
 int ble_sm_id_addr_info_tx(uint16_t conn_handle,
                            struct ble_sm_id_addr_info *cmd);
+void ble_sm_id_addr_info_write(void *payload, int len,
+                               struct ble_sm_id_addr_info *cmd);
 void ble_sm_id_addr_info_log(struct ble_sm_id_addr_info *cmd);
 void ble_sm_sign_info_parse(void *payload, int len,
                             struct ble_sm_sign_info *cmd);
 int ble_sm_sign_info_tx(uint16_t conn_handle, struct ble_sm_sign_info *cmd);
+void ble_sm_sign_info_write(void *payload, int len,
+                            struct ble_sm_sign_info *cmd);
 void ble_sm_sign_info_log(struct ble_sm_sign_info *cmd);
 void ble_sm_sec_req_parse(void *payload, int len, struct ble_sm_sec_req *cmd);
 void ble_sm_sec_req_write(void *payload, int len, struct ble_sm_sec_req *cmd);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/80fbd38b/net/nimble/host/src/ble_sm_sc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_sc.c b/net/nimble/host/src/ble_sm_sc.c
index c3a2666..acc91eb 100644
--- a/net/nimble/host/src/ble_sm_sc.c
+++ b/net/nimble/host/src/ble_sm_sc.c
@@ -531,6 +531,7 @@ ble_sm_sc_dhkey_addrs(struct ble_sm_proc *proc,
                       uint8_t *out_peer_id_addr_type,
                       uint8_t **out_peer_ota_addr)
 {
+    struct ble_hs_conn_addrs addrs;
     struct ble_hs_conn *conn;
 
     conn = ble_hs_conn_find(proc->conn_handle);
@@ -538,11 +539,11 @@ ble_sm_sc_dhkey_addrs(struct ble_sm_proc *proc,
         return BLE_HS_ENOTCONN;
     }
 
-    ble_hs_conn_addrs(conn,
-                      NULL, out_our_ota_addr,
-                      out_our_id_addr_type, NULL,
-                      NULL, out_peer_ota_addr,
-                      out_peer_id_addr_type, NULL);
+    ble_hs_conn_addrs(conn, &addrs);
+    *out_our_id_addr_type = addrs.our_id_addr_type;
+    *out_our_ota_addr = addrs.our_ota_addr;
+    *out_peer_id_addr_type = addrs.peer_id_addr_type;
+    *out_peer_ota_addr = addrs.peer_ota_addr;
 
     return 0;
 }


[04/50] [abbrv] incubator-mynewt-core git commit: BLE Host - SM: correctly report encrypted state.

Posted by cc...@apache.org.
BLE Host - SM: correctly report encrypted state.

Prior to this change, encryption was always reported as disabled.


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

Branch: refs/heads/develop
Commit: fbc2b6093acaf98b124a001e2e9cf3a52f76e0b1
Parents: c589590
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 8 08:19:29 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:34 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fbc2b609/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 0f179d2..1189bb5 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -460,9 +460,15 @@ ble_sm_sec_state(struct ble_sm_proc *proc,
 {
     out_sec_state->pair_alg = proc->pair_alg;
     out_sec_state->enc_enabled = enc_enabled;
-    out_sec_state->authenticated =
-            (proc->flags & BLE_SM_PROC_F_AUTHENTICATED) ? 1 : 0;
-    out_sec_state->bonded = (proc->flags & BLE_SM_PROC_F_BONDED) ? 1 : 0;
+
+    if (enc_enabled) {
+        out_sec_state->authenticated =
+                (proc->flags & BLE_SM_PROC_F_AUTHENTICATED) ? 1 : 0;
+        out_sec_state->bonded = (proc->flags & BLE_SM_PROC_F_BONDED) ? 1 : 0;
+    } else {
+        out_sec_state->authenticated = 0;
+        out_sec_state->bonded = 0;
+    }
 }
 
 static void
@@ -1799,6 +1805,7 @@ ble_sm_key_exch_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
         /* The procedure is now complete. */
         proc->flags |= BLE_SM_PROC_F_BONDED;
         proc->state = BLE_SM_PROC_STATE_NONE;
+        res->enc_state = 1;
         res->enc_cb = 1;
     }
 
@@ -1824,6 +1831,7 @@ ble_sm_key_rxed(struct ble_sm_proc *proc, struct ble_sm_result *res)
         } else {
             proc->flags |= BLE_SM_PROC_F_BONDED;
             proc->state = BLE_SM_PROC_STATE_NONE;
+            res->enc_state = 1;
             res->enc_cb = 1;
         }
     }


[19/50] [abbrv] incubator-mynewt-core git commit: BLE Host - SM: Remove accidental assignment.

Posted by cc...@apache.org.
BLE Host - SM: Remove accidental assignment.


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

Branch: refs/heads/develop
Commit: 6695d0c3810191c7f25314ab566a59ba2128d0ca
Parents: d986a27
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 8 09:55:36 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:35 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm.c | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/6695d0c3/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 3c8f1b3..aecf98a 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -1674,7 +1674,6 @@ ble_sm_sec_req_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
                           NULL, NULL, NULL, NULL,
                           NULL, NULL, &key_sec.peer_addr_type, &peer_id_addr);
         memset(&key_sec, 0, sizeof key_sec);
-        key_sec.peer_addr_type = conn->bhc_addr_type;
         memcpy(key_sec.peer_addr, peer_id_addr, 6);
     }
 


[16/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Reject SMP opcode 15.

Posted by cc...@apache.org.
BLE Host - Reject SMP opcode 15.


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

Branch: refs/heads/develop
Commit: a481a840bb8efca9abc5f3472b6835e7afa8464e
Parents: af67329
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 8 15:02:49 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:35 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a481a840/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 aecf98a..d15960c 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -397,7 +397,7 @@ ble_sm_proc_set_timer(struct ble_sm_proc *proc)
 static ble_sm_rx_fn *
 ble_sm_dispatch_get(uint8_t op)
 {
-    if (op > sizeof ble_sm_dispatch / sizeof ble_sm_dispatch[0]) {
+    if (op >= sizeof ble_sm_dispatch / sizeof ble_sm_dispatch[0]) {
         return NULL;
     }
 


[06/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Fix privacy+pairing bug.

Posted by cc...@apache.org.
BLE Host - Fix privacy+pairing bug.

We were still not using the correct address types and adresses in the
cryptographic functions when privacy was in effect.  All crypto
functions now use:
    * identity address type
    * effective address (RPA if privacy in use; else identity addr).


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

Branch: refs/heads/develop
Commit: eb177946f0fa7b80eaf67fda60639c1fe88a1efd
Parents: be5a985
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 8 05:50:16 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:34 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_gap.c          |   2 +-
 net/nimble/host/src/ble_hs_conn.c      | 111 ++++++++++++++++++++--------
 net/nimble/host/src/ble_hs_conn_priv.h |  14 +++-
 net/nimble/host/src/ble_sm.c           |  30 +++++---
 net/nimble/host/src/ble_sm_alg.c       |   3 +
 net/nimble/host/src/ble_sm_lgcy.c      |   2 +-
 net/nimble/host/src/ble_sm_priv.h      |   3 +-
 net/nimble/host/src/ble_sm_sc.c        |  66 ++++++++++++-----
 8 files changed, 164 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/eb177946/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 795b2ec..a54042f 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -917,7 +917,7 @@ ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt)
     }
 
     memcpy(conn->our_rpa_addr, evt->local_rpa, 6);
-    memcpy(conn->peer_rpa_addr, evt->local_rpa, 6);
+    memcpy(conn->peer_rpa_addr, evt->peer_rpa, 6);
 
     ble_gap_conn_to_snapshot(conn, &snap);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/eb177946/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 84081b4..07550ec 100644
--- a/net/nimble/host/src/ble_hs_conn.c
+++ b/net/nimble/host/src/ble_hs_conn.c
@@ -316,52 +316,101 @@ ble_hs_conn_first(void)
 }
 
 void
-ble_hs_conn_peer_effective_addr(struct ble_hs_conn *conn, uint8_t *out_addr)
+ble_hs_conn_addrs(struct ble_hs_conn *conn,
+                  uint8_t *out_our_effective_addr_type,
+                  uint8_t **out_our_effective_addr,
+                  uint8_t *out_our_identity_addr_type,
+                  uint8_t **out_our_identity_addr,
+                  uint8_t *out_peer_effective_addr_type,
+                  uint8_t **out_peer_effective_addr,
+                  uint8_t *out_peer_identity_addr_type,
+                  uint8_t **out_peer_identity_addr)
 {
+
+    uint8_t peer_effective_addr_type;
+    uint8_t peer_identity_addr_type;
+    uint8_t our_effective_addr_type;
+    uint8_t our_identity_addr_type;
+    uint8_t *peer_effective_addr;
+    uint8_t *peer_identity_addr;
+    uint8_t *our_effective_addr;
+    uint8_t *our_identity_addr;
+
+    /* Determine our address information. */
+    our_identity_addr =
+        bls_hs_priv_get_local_identity_addr(&our_identity_addr_type);
+    if (memcmp(conn->our_rpa_addr, ble_hs_conn_null_addr, 6) == 0) {
+        our_effective_addr_type = our_identity_addr_type;
+        our_effective_addr = our_identity_addr;
+    } else {
+        switch (our_identity_addr_type) {
+        case BLE_ADDR_TYPE_PUBLIC:
+            our_effective_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT;
+            break;
+
+        case BLE_ADDR_TYPE_RANDOM:
+            our_effective_addr_type = BLE_ADDR_TYPE_RPA_RND_DEFAULT;
+            break;
+
+        default:
+            BLE_HS_DBG_ASSERT(0);
+        }
+
+        our_effective_addr = conn->our_rpa_addr;
+    }
+
+    /* Determine peer address information. */
+    peer_effective_addr_type = conn->bhc_addr_type;
+    peer_identity_addr = conn->bhc_addr;
     switch (conn->bhc_addr_type) {
     case BLE_ADDR_TYPE_PUBLIC:
+        peer_identity_addr_type = BLE_ADDR_TYPE_PUBLIC;
+        peer_effective_addr = conn->bhc_addr;
+        break;
+
     case BLE_ADDR_TYPE_RANDOM:
-        memcpy(out_addr, conn->bhc_addr, 6);
+        peer_identity_addr_type = BLE_ADDR_TYPE_RANDOM;
+        peer_effective_addr = conn->bhc_addr;
         break;
 
     case BLE_ADDR_TYPE_RPA_PUB_DEFAULT:
+        peer_identity_addr_type = BLE_ADDR_TYPE_PUBLIC;
+        peer_effective_addr = conn->peer_rpa_addr;
+        break;
+
     case BLE_ADDR_TYPE_RPA_RND_DEFAULT:
-        memcpy(out_addr, conn->peer_rpa_addr, 6);
+        peer_identity_addr_type = BLE_ADDR_TYPE_RANDOM;
+        peer_effective_addr = conn->peer_rpa_addr;
         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);
+    if (out_our_effective_addr_type != NULL) {
+        *out_our_effective_addr_type = our_effective_addr_type;
+    }
+    if (out_our_effective_addr != NULL) {
+        *out_our_effective_addr = our_effective_addr;
+    }
+    if (out_our_identity_addr_type != NULL) {
+        *out_our_identity_addr_type = our_identity_addr_type;
+    }
+    if (out_our_identity_addr != NULL) {
+        *out_our_identity_addr = our_identity_addr;
+    }
+    if (out_peer_effective_addr_type != NULL) {
+        *out_peer_effective_addr_type = peer_effective_addr_type;
+    }
+    if (out_peer_effective_addr != NULL) {
+        *out_peer_effective_addr = peer_effective_addr;
+    }
+    if (out_peer_identity_addr_type != NULL) {
+        *out_peer_identity_addr_type = peer_identity_addr_type;
+    }
+    if (out_peer_identity_addr != NULL) {
+        *out_peer_identity_addr = peer_identity_addr;
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/eb177946/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 9e3fbf2..1ef4829 100644
--- a/net/nimble/host/src/ble_hs_conn_priv.h
+++ b/net/nimble/host/src/ble_hs_conn_priv.h
@@ -75,10 +75,16 @@ 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);
+void ble_hs_conn_addrs(struct ble_hs_conn *conn,
+                       uint8_t *our_effective_addr_type,
+                       uint8_t **our_effective_addr,
+                       uint8_t *our_identity_addr_type,
+                       uint8_t **our_identity_addr,
+                       uint8_t *peer_effective_addr_type,
+                       uint8_t **peer_effective_addr,
+                       uint8_t *peer_identity_addr_type,
+                       uint8_t **peer_identity_addr);
+
 int ble_hs_conn_init(void);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/eb177946/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 58cd22a..0f179d2 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -516,29 +516,39 @@ ble_sm_peer_addr(struct ble_sm_proc *proc,
 }
 
 int
-ble_sm_addrs(struct ble_sm_proc *proc, uint8_t *out_iat, uint8_t *out_ia,
+ble_sm_ia_ra(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;
+    uint8_t *peer_effective_addr;
+    uint8_t *our_effective_addr;
+    uint8_t peer_id_addr_type;
+    uint8_t our_id_addr_type;
 
     conn = ble_hs_conn_find(proc->conn_handle);
     if (conn == NULL) {
         return BLE_HS_ENOTCONN;
     }
 
+    ble_hs_conn_addrs(conn,
+                      NULL, &our_effective_addr,
+                      &our_id_addr_type, NULL,
+                      NULL, &peer_effective_addr,
+                      &peer_id_addr_type, NULL);
+
     if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
-        ble_hs_conn_our_effective_addr(conn, &our_addr_type, out_ia);
-        *out_iat = ble_hs_misc_addr_type_to_ident(our_addr_type);
+        *out_iat = our_id_addr_type;
+        memcpy(out_ia, our_effective_addr, 6);
 
-        ble_hs_conn_peer_effective_addr(conn, out_ra);
-        *out_rat = ble_hs_misc_addr_type_to_ident(conn->bhc_addr_type);
+        *out_rat = peer_id_addr_type;
+        memcpy(out_ra, peer_effective_addr, 6);
     } else {
-        ble_hs_conn_our_effective_addr(conn, &our_addr_type, out_ra);
-        *out_rat = ble_hs_misc_addr_type_to_ident(our_addr_type);
+        *out_iat = peer_id_addr_type;
+        memcpy(out_ia, peer_effective_addr, 6);
 
-        ble_hs_conn_peer_effective_addr(conn, out_ia);
-        *out_iat = ble_hs_misc_addr_type_to_ident(conn->bhc_addr_type);
+        *out_rat = our_id_addr_type;
+        memcpy(out_ra, our_effective_addr, 6);
     }
 
     return 0;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/eb177946/net/nimble/host/src/ble_sm_alg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_alg.c b/net/nimble/host/src/ble_sm_alg.c
index b59ff99..1885d09 100644
--- a/net/nimble/host/src/ble_sm_alg.c
+++ b/net/nimble/host/src/ble_sm_alg.c
@@ -316,6 +316,7 @@ ble_sm_alg_f5(uint8_t *w, uint8_t *n1, uint8_t *n2, uint8_t a1t,
     uint8_t t[16];
     int rc;
 
+    BLE_HS_LOG(DEBUG, "ble_sm_alg_f5()\n");
     ble_sm_alg_log_buf("w", w, 32);
     ble_sm_alg_log_buf("n1", n1, 16);
     ble_sm_alg_log_buf("n2", n2, 16);
@@ -369,6 +370,7 @@ ble_sm_alg_f6(uint8_t *w, uint8_t *n1, uint8_t *n2, uint8_t *r,
     uint8_t m[65];
     int rc;
 
+    BLE_HS_LOG(DEBUG, "ble_sm_alg_f6()\n");
     ble_sm_alg_log_buf("w", w, 16);
     ble_sm_alg_log_buf("n1", n1, 16);
     ble_sm_alg_log_buf("n2", n2, 16);
@@ -412,6 +414,7 @@ ble_sm_alg_g2(uint8_t *u, uint8_t *v, uint8_t *x, uint8_t *y, uint32_t *passkey)
     uint8_t m[80], xs[16];
     int rc;
 
+    BLE_HS_LOG(DEBUG, "ble_sm_alg_g2()\n");
     ble_sm_alg_log_buf("u", u, 32);
     ble_sm_alg_log_buf("v", v, 32);
     ble_sm_alg_log_buf("x", x, 16);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/eb177946/net/nimble/host/src/ble_sm_lgcy.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_lgcy.c b/net/nimble/host/src/ble_sm_lgcy.c
index b95a7a2..4696a07 100644
--- a/net/nimble/host/src/ble_sm_lgcy.c
+++ b/net/nimble/host/src/ble_sm_lgcy.c
@@ -111,7 +111,7 @@ ble_sm_lgcy_confirm_prepare_args(struct ble_sm_proc *proc,
 {
     int rc;
 
-    rc = ble_sm_addrs(proc, iat, ia, rat, ra);
+    rc = ble_sm_ia_ra(proc, iat, ia, rat, ra);
     if (rc != 0) {
         return rc;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/eb177946/net/nimble/host/src/ble_sm_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_priv.h b/net/nimble/host/src/ble_sm_priv.h
index c710823..5b6e157 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -447,7 +447,8 @@ void ble_sm_process_result(uint16_t conn_handle, struct ble_sm_result *res);
 void ble_sm_confirm_advance(struct ble_sm_proc *proc);
 int ble_sm_peer_addr(struct ble_sm_proc *proc,
                      uint8_t *out_type, uint8_t **out_addr);
-int ble_sm_addrs(struct ble_sm_proc *proc, uint8_t *out_iat, uint8_t *out_ia,
+int ble_sm_ia_ra(struct ble_sm_proc *proc,
+                 uint8_t *out_iat, uint8_t *out_ia,
                  uint8_t *out_rat, uint8_t *out_ra);
 
 void ble_sm_heartbeat(void);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/eb177946/net/nimble/host/src/ble_sm_sc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_sc.c b/net/nimble/host/src/ble_sm_sc.c
index 7163b8d..5939916 100644
--- a/net/nimble/host/src/ble_sm_sc.c
+++ b/net/nimble/host/src/ble_sm_sc.c
@@ -375,7 +375,7 @@ ble_sm_sc_random_rx(struct ble_sm_proc *proc, struct ble_sm_result *res)
     }
 
     /* Calculate the mac key and ltk. */
-    rc = ble_sm_addrs(proc, &iat, ia, &rat, ra);
+    rc = ble_sm_ia_ra(proc, &iat, ia, &rat, ra);
     if (rc != 0) {
         res->app_status = rc;
         res->sm_err = BLE_SM_ERR_UNSPECIFIED;
@@ -520,6 +520,29 @@ ble_sm_sc_public_key_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
     ble_hs_unlock();
 }
 
+static int
+ble_sm_sc_dhkey_addrs(struct ble_sm_proc *proc,
+                      uint8_t *out_our_id_addr_type,
+                      uint8_t **out_our_effective_addr,
+                      uint8_t *out_peer_id_addr_type,
+                      uint8_t **out_peer_effective_addr)
+{
+    struct ble_hs_conn *conn;
+
+    conn = ble_hs_conn_find(proc->conn_handle);
+    if (conn == NULL) {
+        return BLE_HS_ENOTCONN;
+    }
+
+    ble_hs_conn_addrs(conn,
+                      NULL, out_our_effective_addr,
+                      out_our_id_addr_type, NULL,
+                      NULL, out_peer_effective_addr,
+                      out_peer_id_addr_type, NULL);
+
+    return 0;
+}
+
 static void
 ble_sm_sc_dhkey_check_iocap(struct ble_sm_pair_cmd *pair_cmd,
                             uint8_t *out_iocap)
@@ -534,11 +557,11 @@ ble_sm_sc_dhkey_check_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
                            void *arg)
 {
     struct ble_sm_dhkey_check cmd;
-    uint8_t our_addr[6];
+    uint8_t *our_effective_addr;
+    uint8_t *peer_effective_addr;
+    uint8_t peer_id_addr_type;
+    uint8_t our_id_addr_type;
     uint8_t iocap[3];
-    uint8_t *peer_addr;
-    uint8_t peer_addr_type;
-    uint8_t our_addr_type;
     int rc;
 
     if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
@@ -547,16 +570,17 @@ ble_sm_sc_dhkey_check_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
         ble_sm_sc_dhkey_check_iocap(&proc->pair_rsp, iocap);
     }
 
-    bls_hs_priv_copy_local_identity_addr(our_addr, &our_addr_type);
-
-    rc = ble_sm_peer_addr(proc, &peer_addr_type, &peer_addr);
+    rc = ble_sm_sc_dhkey_addrs(proc,
+                               &our_id_addr_type, &our_effective_addr,
+                               &peer_id_addr_type, &peer_effective_addr);
     if (rc != 0) {
         goto err;
     }
 
     rc = ble_sm_alg_f6(proc->mackey, ble_sm_our_pair_rand(proc),
                        ble_sm_peer_pair_rand(proc), proc->tk, iocap,
-                       our_addr_type, our_addr, peer_addr_type, peer_addr,
+                       our_id_addr_type, our_effective_addr,
+                       peer_id_addr_type, peer_effective_addr,
                        cmd.value);
     if (rc != 0) {
         goto err;
@@ -585,11 +609,11 @@ ble_sm_dhkey_check_process(struct ble_sm_proc *proc,
                            struct ble_sm_result *res)
 {
     uint8_t exp_value[16];
-    uint8_t our_addr[6];
+    uint8_t *peer_effective_addr;
+    uint8_t *our_effective_addr;
+    uint8_t peer_id_addr_type;
+    uint8_t our_id_addr_type;
     uint8_t iocap[3];
-    uint8_t *peer_addr;
-    uint8_t peer_addr_type;
-    uint8_t our_addr_type;
     uint8_t ioact;
 
     if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
@@ -598,9 +622,11 @@ ble_sm_dhkey_check_process(struct ble_sm_proc *proc,
         ble_sm_sc_dhkey_check_iocap(&proc->pair_req, iocap);
     }
 
-    bls_hs_priv_copy_local_identity_addr(our_addr, &our_addr_type);
-
-    res->app_status = ble_sm_peer_addr(proc, &peer_addr_type, &peer_addr);
+    res->app_status = ble_sm_sc_dhkey_addrs(proc,
+                                            &our_id_addr_type,
+                                            &our_effective_addr,
+                                            &peer_id_addr_type,
+                                            &peer_effective_addr);
     if (res->app_status != 0) {
         res->sm_err = BLE_SM_ERR_UNSPECIFIED;
         res->enc_cb = 1;
@@ -613,9 +639,11 @@ ble_sm_dhkey_check_process(struct ble_sm_proc *proc,
 
     res->app_status = ble_sm_alg_f6(proc->mackey,
                                     ble_sm_peer_pair_rand(proc),
-                                    ble_sm_our_pair_rand(proc), proc->tk,
-                                    iocap, peer_addr_type, peer_addr,
-                                    our_addr_type, our_addr, exp_value);
+                                    ble_sm_our_pair_rand(proc),
+                                    proc->tk, iocap,
+                                    peer_id_addr_type, peer_effective_addr,
+                                    our_id_addr_type, our_effective_addr,
+                                    exp_value);
     if (res->app_status != 0) {
         res->sm_err = BLE_SM_ERR_UNSPECIFIED;
         res->enc_cb = 1;


[10/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Enable data-length-change event by dflt

Posted by cc...@apache.org.
BLE Host - Enable data-length-change event by dflt


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

Branch: refs/heads/develop
Commit: a96152c317148be63c4e0f36d259841716ebe67c
Parents: 069dae2
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 7 18:43:57 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:34 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_hs_startup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a96152c3/net/nimble/host/src/ble_hs_startup.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_startup.c b/net/nimble/host/src/ble_hs_startup.c
index a517f03..310c5b8 100644
--- a/net/nimble/host/src/ble_hs_startup.c
+++ b/net/nimble/host/src/ble_hs_startup.c
@@ -91,9 +91,10 @@ ble_hs_startup_le_set_evmask_tx(void)
      *     0x0000000000000008 LE Read Remote Used Features Complete Event
      *     0x0000000000000010 LE Long Term Key Request Event
      *     0x0000000000000020 LE Remote Connection Parameter Request Event
+     *     0x0000000000000040 LE Data Length Change Event
      *     0x0000000000000200 LE Enhanced Connection Complete Event
      */
-    host_hci_cmd_build_le_set_event_mask(0x000000000000023f, buf, sizeof buf);
+    host_hci_cmd_build_le_set_event_mask(0x000000000000027f, buf, sizeof buf);
     rc = ble_hci_cmd_tx_empty_ack(buf);
     if (rc != 0) {
         return rc;


[24/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Rename sec_state.enc_enabled->encrypted

Posted by cc...@apache.org.
BLE Host - Rename sec_state.enc_enabled->encrypted


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

Branch: refs/heads/develop
Commit: 5bbe2672dd41305e25d4e6bc8313297a6acdbcf3
Parents: 7a75168
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 8 18:21:30 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:36 2016 -0700

----------------------------------------------------------------------
 apps/bleprph/src/main.c                         |   2 +-
 apps/bletiny/src/misc.c                         |   4 +-
 net/nimble/host/include/host/ble_gap.h          |   2 +-
 net/nimble/host/src/ble_att_svr.c               |   2 +-
 net/nimble/host/src/ble_sm.c                    |   2 +-
 .../host/src/test/ble_gatts_notify_test.c       |   4 +-
 net/nimble/host/src/test/ble_sm_test.c          | 162 +++++++++----------
 7 files changed, 89 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5bbe2672/apps/bleprph/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/main.c b/apps/bleprph/src/main.c
index e44e58a..f2d0c09 100755
--- a/apps/bleprph/src/main.c
+++ b/apps/bleprph/src/main.c
@@ -104,7 +104,7 @@ bleprph_print_conn_desc(struct ble_gap_conn_desc *desc)
                 desc->conn_itvl,
                 desc->conn_latency,
                 desc->supervision_timeout,
-                desc->sec_state.enc_enabled,
+                desc->sec_state.encrypted,
                 desc->sec_state.authenticated);
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5bbe2672/apps/bletiny/src/misc.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/misc.c b/apps/bletiny/src/misc.c
index 4e7c97d..b0c3ddb 100644
--- a/apps/bletiny/src/misc.c
+++ b/apps/bletiny/src/misc.c
@@ -106,10 +106,10 @@ print_conn_desc(struct ble_gap_conn_desc *desc)
                    desc->peer_id_addr_type);
     print_addr(desc->peer_id_addr);
     console_printf(" conn_itvl=%d conn_latency=%d supervision_timeout=%d "
-                   "enc_enabled=%d authenticated=%d bonded=%d\n",
+                   "encrypted=%d authenticated=%d bonded=%d\n",
                    desc->conn_itvl, desc->conn_latency,
                    desc->supervision_timeout,
-                   desc->sec_state.enc_enabled,
+                   desc->sec_state.encrypted,
                    desc->sec_state.authenticated,
                    desc->sec_state.bonded);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5bbe2672/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index 5e0bda2..0b150dd 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -102,7 +102,7 @@ struct hci_adv_params;
 #define BLE_GAP_EVENT_NOTIFY                12
 
 struct ble_gap_sec_state {
-    unsigned enc_enabled:1;
+    unsigned encrypted:1;
     unsigned authenticated:1;
     unsigned bonded:1;
 };

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5bbe2672/net/nimble/host/src/ble_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
index 8508240..2e4e137 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -261,7 +261,7 @@ ble_att_svr_check_security(uint16_t conn_handle, int is_read,
         return rc;
     }
 
-    if (enc && !sec_state.enc_enabled) {
+    if (enc && !sec_state.encrypted) {
         /* XXX: Check security database; if required key present, respond with
          * insufficient encryption error code.
          */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5bbe2672/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 2bed018..d9c4fd5 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -459,7 +459,7 @@ ble_sm_update_sec_state(uint16_t conn_handle, int encrypted,
 
     conn = ble_hs_conn_find(conn_handle);
     if (conn != NULL) {
-        conn->bhc_sec_state.enc_enabled = encrypted;
+        conn->bhc_sec_state.encrypted = encrypted;
 
         /* Authentication and bonding are never revoked from a secure link */
         if (authenticated) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5bbe2672/net/nimble/host/src/test/ble_gatts_notify_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatts_notify_test.c b/net/nimble/host/src/test/ble_gatts_notify_test.c
index 8c74024..6a0f218 100644
--- a/net/nimble/host/src/test/ble_gatts_notify_test.c
+++ b/net/nimble/host/src/test/ble_gatts_notify_test.c
@@ -149,7 +149,7 @@ ble_gatts_notify_test_misc_init(uint16_t *out_conn_handle, int bonding,
         ble_hs_lock();
         conn = ble_hs_conn_find(2);
         TEST_ASSERT_FATAL(conn != NULL);
-        conn->bhc_sec_state.enc_enabled = 1;
+        conn->bhc_sec_state.encrypted = 1;
         conn->bhc_sec_state.authenticated = 1;
         conn->bhc_sec_state.bonded = 1;
         ble_hs_unlock();
@@ -197,7 +197,7 @@ ble_gatts_restore_bonding(uint16_t conn_handle)
     ble_hs_lock();
     conn = ble_hs_conn_find(conn_handle);
     TEST_ASSERT_FATAL(conn != NULL);
-    conn->bhc_sec_state.enc_enabled = 1;
+    conn->bhc_sec_state.encrypted = 1;
     conn->bhc_sec_state.authenticated = 1;
     conn->bhc_sec_state.bonded = 1;
     ble_hs_unlock();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/5bbe2672/net/nimble/host/src/test/ble_sm_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test.c b/net/nimble/host/src/test/ble_sm_test.c
index 7e7fd96..4c497db 100644
--- a/net/nimble/host/src/test/ble_sm_test.c
+++ b/net/nimble/host/src/test/ble_sm_test.c
@@ -834,7 +834,7 @@ ble_sm_test_util_us_lgcy_good(
     TEST_ASSERT_FATAL(conn != NULL);
     ble_hs_unlock();
 
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     ble_hs_test_util_set_ack(
@@ -850,34 +850,34 @@ ble_sm_test_util_us_lgcy_good(
     /* Ensure we sent the expected pair request. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_pair_req(&params->pair_req);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Receive a pair response from the peer. */
     ble_sm_test_util_rx_pair_rsp(2, &params->pair_rsp, 0);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Ensure we sent the expected pair confirm. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_pair_confirm(&params->confirm_req);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Receive a pair confirm from the peer. */
     ble_sm_test_util_rx_confirm(2, &params->confirm_rsp);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Ensure we sent the expected pair random. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_pair_random(&params->random_req);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Receive a pair random from the peer. */
     ble_sm_test_util_rx_random(2, &params->random_rsp, 0);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Ensure keys are distributed, if necessary. */
@@ -889,7 +889,7 @@ ble_sm_test_util_us_lgcy_good(
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_start_enc(2, params->r, params->ediv,
                                                params->stk);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Receive an encryption changed event. */
@@ -901,12 +901,12 @@ ble_sm_test_util_us_lgcy_good(
     /* Verify that security callback was executed. */
     TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
     TEST_ASSERT(ble_sm_test_gap_status == 0);
-    TEST_ASSERT(ble_sm_test_sec_state.enc_enabled);
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
     TEST_ASSERT(!ble_sm_test_sec_state.authenticated);
 
     /* Verify that connection has correct security state. */
-    TEST_ASSERT(ble_sm_test_sec_state.enc_enabled ==
-                conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted ==
+                conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
                 conn->bhc_sec_state.authenticated);
 
@@ -943,19 +943,19 @@ ble_sm_test_util_peer_fail_inval(
         conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
     }
 
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     /* Receive a pair request from the peer. */
     ble_sm_test_util_rx_pair_req(2, pair_req,
                                  BLE_HS_SM_US_ERR(pair_fail->reason));
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     /* Ensure we sent the expected pair fail. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_pair_fail(pair_fail);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     /* Verify that security callback was not executed. */
@@ -963,7 +963,7 @@ ble_sm_test_util_peer_fail_inval(
     TEST_ASSERT(ble_sm_test_gap_status == -1);
 
     /* Verify that connection has correct security state. */
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(!conn->bhc_sec_state.authenticated);
 }
 
@@ -1035,12 +1035,12 @@ ble_sm_test_util_peer_lgcy_fail_confirm(
     TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
     TEST_ASSERT(ble_sm_test_gap_status ==
                 BLE_HS_SM_US_ERR(BLE_SM_ERR_CONFIRM_MISMATCH));
-    TEST_ASSERT(!ble_sm_test_sec_state.enc_enabled);
+    TEST_ASSERT(!ble_sm_test_sec_state.encrypted);
     TEST_ASSERT(!ble_sm_test_sec_state.authenticated);
 
     /* Verify that connection has correct security state. */
-    TEST_ASSERT(ble_sm_test_sec_state.enc_enabled ==
-                conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted ==
+                conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
                 conn->bhc_sec_state.authenticated);
 }
@@ -1090,7 +1090,7 @@ ble_sm_test_util_peer_lgcy_good_once(struct ble_sm_test_lgcy_params *params)
     /* Peer is the initiator so we must be the slave. */
     conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
 
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     if (params->has_sec_req) {
@@ -1103,13 +1103,13 @@ ble_sm_test_util_peer_lgcy_good_once(struct ble_sm_test_lgcy_params *params)
 
     /* Receive a pair request from the peer. */
     ble_sm_test_util_rx_pair_req(2, &params->pair_req, 0);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Ensure we sent the expected pair response. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_pair_rsp(&params->pair_rsp);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     ble_sm_test_util_io_check_pre(&params->passkey_info,
@@ -1117,7 +1117,7 @@ ble_sm_test_util_peer_lgcy_good_once(struct ble_sm_test_lgcy_params *params)
 
     /* Receive a pair confirm from the peer. */
     ble_sm_test_util_rx_confirm(2, &params->confirm_req);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     ble_sm_test_util_io_check_post(&params->passkey_info,
@@ -1126,29 +1126,29 @@ ble_sm_test_util_peer_lgcy_good_once(struct ble_sm_test_lgcy_params *params)
     /* Ensure we sent the expected pair confirm. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_pair_confirm(&params->confirm_rsp);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Receive a pair random from the peer. */
     ble_sm_test_util_rx_random(2, &params->random_req, 0);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Ensure we sent the expected pair random. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_pair_random(&params->random_rsp);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Receive a long term key request from the controller. */
     ble_sm_test_util_set_lt_key_req_reply_ack(0, 2);
     ble_sm_test_util_rx_lt_key_req(2, params->r, params->ediv);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Ensure we sent the expected long term key request reply command. */
     ble_sm_test_util_verify_tx_lt_key_req_reply(2, params->stk);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Receive an encryption changed event. */
@@ -1164,13 +1164,13 @@ ble_sm_test_util_peer_lgcy_good_once(struct ble_sm_test_lgcy_params *params)
     /* Verify that security callback was executed. */
     TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
     TEST_ASSERT(ble_sm_test_gap_status == 0);
-    TEST_ASSERT(ble_sm_test_sec_state.enc_enabled);
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
                 params->authenticated);
 
     /* Verify that connection has correct security state. */
-    TEST_ASSERT(ble_sm_test_sec_state.enc_enabled ==
-                conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted ==
+                conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
                 conn->bhc_sec_state.authenticated);
 
@@ -1219,7 +1219,7 @@ ble_sm_test_util_peer_bonding_good(int send_enc_req, uint8_t *ltk,
     conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
     ble_hs_unlock();
 
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     /* Populate the SM database with an LTK for this peer. */
@@ -1243,7 +1243,7 @@ ble_sm_test_util_peer_bonding_good(int send_enc_req, uint8_t *ltk,
     /* Receive a long term key request from the controller. */
     ble_sm_test_util_set_lt_key_req_reply_ack(0, 2);
     ble_sm_test_util_rx_lt_key_req(2, rand_num, ediv);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
 
     /* Ensure the LTK request event got sent to the application. */
     TEST_ASSERT(ble_sm_test_store_obj_type ==
@@ -1254,12 +1254,12 @@ ble_sm_test_util_peer_bonding_good(int send_enc_req, uint8_t *ltk,
     TEST_ASSERT(ble_sm_test_store_key.sec.ediv == ediv);
     TEST_ASSERT(ble_sm_test_store_key.sec.rand_num == rand_num);
 
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Ensure we sent the expected long term key request reply command. */
     ble_sm_test_util_verify_tx_lt_key_req_reply(2, value_sec.ltk);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Receive an encryption changed event. */
@@ -1271,12 +1271,12 @@ ble_sm_test_util_peer_bonding_good(int send_enc_req, uint8_t *ltk,
     /* Verify that security callback was executed. */
     TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
     TEST_ASSERT(ble_sm_test_gap_status == 0);
-    TEST_ASSERT(ble_sm_test_sec_state.enc_enabled);
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
                 authenticated);
 
     /* Verify that connection has correct security state. */
-    TEST_ASSERT(ble_sm_test_sec_state.enc_enabled);
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
                 authenticated);
 }
@@ -1302,13 +1302,13 @@ ble_sm_test_util_peer_bonding_bad(uint16_t ediv, uint64_t rand_num)
     conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
     ble_hs_unlock();
 
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     /* Receive a long term key request from the controller. */
     ble_sm_test_util_set_lt_key_req_reply_ack(0, 2);
     ble_sm_test_util_rx_lt_key_req(2, rand_num, ediv);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
 
     /* Ensure the LTK request event got sent to the application. */
     TEST_ASSERT(ble_sm_test_store_obj_type ==
@@ -1317,13 +1317,13 @@ ble_sm_test_util_peer_bonding_bad(uint16_t ediv, uint64_t rand_num)
     TEST_ASSERT(ble_sm_test_store_key.sec.ediv == ediv);
     TEST_ASSERT(ble_sm_test_store_key.sec.rand_num == rand_num);
 
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
 
     /* Ensure we sent the expected long term key request neg reply command. */
     ble_sm_test_util_verify_tx_lt_key_req_neg_reply(2);
 
     /* Ensure the security procedure was aborted. */
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(!conn->bhc_sec_state.authenticated);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 }
@@ -1371,7 +1371,7 @@ ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
     /* Peer is the initiator so we must be the slave. */
     conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
 
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     if (params->has_sec_req) {
@@ -1384,24 +1384,24 @@ ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
 
     /* Receive a pair request from the peer. */
     ble_sm_test_util_rx_pair_req(2, &params->pair_req, 0);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Ensure we sent the expected pair response. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_pair_rsp(&params->pair_rsp);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Receive a public key from the peer. */
     ble_sm_test_util_rx_public_key(2, &params->public_key_req);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Ensure we sent the expected public key. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_public_key(&params->public_key_rsp);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     switch (params->pair_alg) {
@@ -1423,7 +1423,7 @@ ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
 
             /* Receive a pair confirm from the peer. */
             ble_sm_test_util_rx_confirm(2, params->confirm_req + i);
-            TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+            TEST_ASSERT(!conn->bhc_sec_state.encrypted);
             TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
             if (i < num_iters - 1) {
@@ -1440,18 +1440,18 @@ ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
         /* Ensure we sent the expected pair confirm. */
         ble_hs_test_util_tx_all();
         ble_sm_test_util_verify_tx_pair_confirm(params->confirm_rsp + i);
-        TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+        TEST_ASSERT(!conn->bhc_sec_state.encrypted);
         TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
         /* Receive a pair random from the peer. */
         ble_sm_test_util_rx_random(2, params->random_req + i, 0);
-        TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+        TEST_ASSERT(!conn->bhc_sec_state.encrypted);
         TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
         /* Ensure we sent the expected pair random. */
         ble_hs_test_util_tx_all();
         ble_sm_test_util_verify_tx_pair_random(params->random_rsp + i);
-        TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+        TEST_ASSERT(!conn->bhc_sec_state.encrypted);
         TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     }
@@ -1461,7 +1461,7 @@ ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
 
     /* Receive a dhkey check from the peer. */
     ble_sm_test_util_rx_dhkey_check(2, &params->dhkey_check_req, 0);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     ble_sm_test_util_io_check_post(&params->passkey_info,
@@ -1470,18 +1470,18 @@ ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
     /* Ensure we sent the expected dhkey check. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_dhkey_check(&params->dhkey_check_rsp);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Receive a long term key request from the controller. */
     ble_sm_test_util_set_lt_key_req_reply_ack(0, 2);
     ble_sm_test_util_rx_lt_key_req(2, 0, 0);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Ensure we sent the expected long term key request reply command. */
     ble_sm_test_util_verify_tx_lt_key_req_reply(2, params->ltk);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Receive an encryption changed event. */
@@ -1493,13 +1493,13 @@ ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
     /* Verify that security callback was executed. */
     TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
     TEST_ASSERT(ble_sm_test_gap_status == 0);
-    TEST_ASSERT(ble_sm_test_sec_state.enc_enabled);
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
                 params->authenticated);
 
     /* Verify that connection has correct security state. */
-    TEST_ASSERT(ble_sm_test_sec_state.enc_enabled ==
-                conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted ==
+                conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
                 conn->bhc_sec_state.authenticated);
 
@@ -1558,7 +1558,7 @@ ble_sm_test_util_us_sc_good(struct ble_sm_test_sc_params *params)
     TEST_ASSERT_FATAL(conn != NULL);
     ble_hs_unlock();
 
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     ble_hs_test_util_set_ack(
@@ -1574,23 +1574,23 @@ ble_sm_test_util_us_sc_good(struct ble_sm_test_sc_params *params)
     /* Ensure we sent the expected pair request. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_pair_req(&params->pair_req);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Receive a pair response from the peer. */
     ble_sm_test_util_rx_pair_rsp(2, &params->pair_rsp, 0);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Ensure we sent the expected public key. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_public_key(&params->public_key_req);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Receive a public key from the peer. */
     ble_sm_test_util_rx_public_key(2, &params->public_key_rsp);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     switch (params->pair_alg) {
@@ -1618,24 +1618,24 @@ ble_sm_test_util_us_sc_good(struct ble_sm_test_sc_params *params)
             /* Ensure we sent the expected pair confirm. */
             ble_hs_test_util_tx_all();
             ble_sm_test_util_verify_tx_pair_confirm(params->confirm_req + i);
-            TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+            TEST_ASSERT(!conn->bhc_sec_state.encrypted);
             TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
         }
 
         /* Receive a pair confirm from the peer. */
         ble_sm_test_util_rx_confirm(2, params->confirm_rsp + i);
-        TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+        TEST_ASSERT(!conn->bhc_sec_state.encrypted);
         TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
         /* Ensure we sent the expected pair random. */
         ble_hs_test_util_tx_all();
         ble_sm_test_util_verify_tx_pair_random(params->random_req + i);
-        TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+        TEST_ASSERT(!conn->bhc_sec_state.encrypted);
         TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
         /* Receive a pair random from the peer. */
         ble_sm_test_util_rx_random(2, params->random_rsp + i, 0);
-        TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+        TEST_ASSERT(!conn->bhc_sec_state.encrypted);
         TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
     }
 
@@ -1645,18 +1645,18 @@ ble_sm_test_util_us_sc_good(struct ble_sm_test_sc_params *params)
     /* Ensure we sent the expected dhkey check. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_dhkey_check(&params->dhkey_check_req);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Receive a dhkey check from the peer. */
     ble_sm_test_util_rx_dhkey_check(2, &params->dhkey_check_rsp, 0);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Ensure we sent the expected start encryption command. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_start_enc(2, 0, 0, params->ltk);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Receive an encryption changed event. */
@@ -1668,13 +1668,13 @@ ble_sm_test_util_us_sc_good(struct ble_sm_test_sc_params *params)
     /* Verify that security callback was executed. */
     TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
     TEST_ASSERT(ble_sm_test_gap_status == 0);
-    TEST_ASSERT(ble_sm_test_sec_state.enc_enabled);
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
                 params->authenticated);
 
     /* Verify that connection has correct security state. */
-    TEST_ASSERT(ble_sm_test_sec_state.enc_enabled ==
-                conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted ==
+                conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
                 conn->bhc_sec_state.authenticated);
 
@@ -1707,7 +1707,7 @@ ble_sm_test_util_us_fail_inval(
     TEST_ASSERT_FATAL(conn != NULL);
     ble_hs_unlock();
 
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     /* Initiate the pairing procedure. */
@@ -1717,19 +1717,19 @@ ble_sm_test_util_us_fail_inval(
     /* Ensure we sent the expected pair request. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_pair_req(&params->pair_req);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Receive a pair response from the peer. */
     ble_sm_test_util_rx_pair_rsp(
         2, &params->pair_rsp, BLE_HS_SM_US_ERR(BLE_SM_ERR_INVAL));
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     /* Ensure we sent the expected pair fail. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_pair_fail(&params->pair_fail);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     /* Verify that security callback was not executed. */
@@ -1737,7 +1737,7 @@ ble_sm_test_util_us_fail_inval(
     TEST_ASSERT(ble_sm_test_gap_status == -1);
 
     /* Verify that connection has correct security state. */
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(!conn->bhc_sec_state.authenticated);
 }
 
@@ -1772,7 +1772,7 @@ ble_sm_test_util_us_bonding_good(int send_enc_req, uint8_t *ltk,
     TEST_ASSERT_FATAL(conn != NULL);
     ble_hs_unlock();
 
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
 
     /* Populate the SM database with an LTK for this peer. */
@@ -1804,7 +1804,7 @@ ble_sm_test_util_us_bonding_good(int send_enc_req, uint8_t *ltk,
     /* Ensure we sent the expected start encryption command. */
     ble_hs_test_util_tx_all();
     ble_sm_test_util_verify_tx_start_enc(2, rand_num, ediv, ltk);
-    TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
     TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
 
     /* Receive an encryption changed event. */
@@ -1816,12 +1816,12 @@ ble_sm_test_util_us_bonding_good(int send_enc_req, uint8_t *ltk,
     /* Verify that security callback was executed. */
     TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
     TEST_ASSERT(ble_sm_test_gap_status == 0);
-    TEST_ASSERT(ble_sm_test_sec_state.enc_enabled);
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
                 authenticated);
 
     /* Verify that connection has correct security state. */
-    TEST_ASSERT(ble_sm_test_sec_state.enc_enabled);
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
     TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
                 authenticated);
 }
@@ -1955,7 +1955,7 @@ TEST_CASE(ble_sm_test_case_conn_broken)
 
     /* Verify security callback got called. */
     TEST_ASSERT(ble_sm_test_gap_status == BLE_HS_ENOTCONN);
-    TEST_ASSERT(!ble_sm_test_sec_state.enc_enabled);
+    TEST_ASSERT(!ble_sm_test_sec_state.encrypted);
     TEST_ASSERT(!ble_sm_test_sec_state.authenticated);
 }
 


[35/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Log addresses in big endian.

Posted by cc...@apache.org.
BLE Host - Log addresses in big endian.


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

Branch: refs/heads/develop
Commit: 18bd234f58f1b27b364a7933a367d5ed28d1fd1b
Parents: 91a1b0f
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jun 10 10:00:24 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:39 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_hs_priv.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/18bd234f/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 c8462bf..11a34b6 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -124,8 +124,8 @@ void ble_hci_set_phony_ack_cb(ble_hci_cmd_phony_ack_fn *cb);
 
 #define BLE_HS_LOG_ADDR(lvl, addr)                      \
     BLE_HS_LOG(lvl, "%02x:%02x:%02x:%02x:%02x:%02x",    \
-               (addr)[0], (addr)[1], (addr)[2],         \
-               (addr)[3], (addr)[4], (addr)[5])
+               (addr)[5], (addr)[4], (addr)[3],         \
+               (addr)[2], (addr)[1], (addr)[0])
 
 #if LOG_LEVEL <= LOG_LEVEL_DEBUG
 


[21/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Clear queue on gatt-reliable-write fail

Posted by cc...@apache.org.
BLE Host - Clear queue on gatt-reliable-write fail


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

Branch: refs/heads/develop
Commit: af8610ac9c5c843f9ed786d6c5e5d2a71053846a
Parents: 1a7949f
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 8 19:50:20 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:36 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_gattc.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/af8610ac/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index 1796bcc..db5ab5f 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -3398,7 +3398,21 @@ static void
 ble_gattc_write_reliable_err(struct ble_gattc_proc *proc, int status,
                              uint16_t att_handle)
 {
+    struct ble_att_exec_write_req exec_req;
+
+    ble_gattc_dbg_assert_proc_not_inserted(proc);
     ble_gattc_write_reliable_cb(proc, status, att_handle);
+
+    /* If we have successfully queued any data, and the failure occurred before
+     * we could send the execute write command, then erase all queued data.
+     */
+    if (proc->write_reliable.attr.offset > 0 &&
+        proc->write_reliable.attr.offset <
+            proc->write_reliable.attr.value_len) {
+
+        exec_req.baeq_flags = 0;
+        ble_att_clt_tx_exec_write(proc->conn_handle, &exec_req);
+    }
 }
 
 /**


[23/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Clear queue on gatt-long-write failure.

Posted by cc...@apache.org.
BLE Host - Clear queue on gatt-long-write failure.


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

Branch: refs/heads/develop
Commit: 1a7949f8f805a81c349bf0a1ebd0dda6ffa9314e
Parents: d43cb52
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 8 19:48:22 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:36 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_gattc.c                | 12 +++++
 net/nimble/host/src/test/ble_gatt_write_test.c | 53 +++++++++++++++++++++
 net/nimble/host/src/test/ble_hs_test_util.c    | 14 ++++++
 net/nimble/host/src/test/ble_hs_test_util.h    |  1 +
 4 files changed, 80 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a7949f8/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index 876abf5..1796bcc 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -3175,8 +3175,20 @@ static void
 ble_gattc_write_long_err(struct ble_gattc_proc *proc, int status,
                          uint16_t att_handle)
 {
+    struct ble_att_exec_write_req exec_req;
+
     ble_gattc_dbg_assert_proc_not_inserted(proc);
     ble_gattc_write_long_cb(proc, status, att_handle);
+
+    /* If we have successfully queued any data, and the failure occurred before
+     * we could send the execute write command, then erase all queued data.
+     */
+    if (proc->write_long.attr.offset > 0 &&
+        proc->write_long.attr.offset < proc->write_long.attr.value_len) {
+
+        exec_req.baeq_flags = 0;
+        ble_att_clt_tx_exec_write(proc->conn_handle, &exec_req);
+    }
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a7949f8/net/nimble/host/src/test/ble_gatt_write_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_write_test.c b/net/nimble/host/src/test/ble_gatt_write_test.c
index f12ea77..56e88d3 100644
--- a/net/nimble/host/src/test/ble_gatt_write_test.c
+++ b/net/nimble/host/src/test/ble_gatt_write_test.c
@@ -189,6 +189,7 @@ ble_gatt_write_test_misc_long_bad(int attr_len,
     while (off < attr_len) {
         /* Send the pending ATT Prep Write Command. */
         ble_hs_test_util_tx_all();
+        TEST_ASSERT(ble_hs_test_util_prev_tx_dequeue() != NULL);
 
         /* Receive Prep Write response. */
         len = BLE_ATT_MTU_DFLT - BLE_ATT_PREP_WRITE_CMD_BASE_SZ;
@@ -498,6 +499,57 @@ TEST_CASE(ble_gatt_write_test_reliable_good)
         } }));
 }
 
+TEST_CASE(ble_gatt_write_test_long_queue_full)
+{
+    int off;
+    int len;
+    int rc;
+    int i;
+
+    ble_gatt_write_test_init();
+
+    ble_hs_test_util_create_conn(2, ((uint8_t[]){2,3,4,5,6,7,8,9}),
+                                 NULL, NULL);
+
+    rc = ble_gattc_write_long(2, 100, ble_gatt_write_test_attr_value,
+                              128, ble_gatt_write_test_cb_good, NULL);
+    TEST_ASSERT(rc == 0);
+
+    off = 0;
+    for (i = 0; i < 2; i++) {
+        /* Verify prep write request was sent. */
+        ble_hs_test_util_tx_all();
+        TEST_ASSERT(ble_hs_test_util_prev_tx_dequeue() != NULL);
+
+        /* Receive Prep Write response. */
+        len = BLE_ATT_MTU_DFLT - BLE_ATT_PREP_WRITE_CMD_BASE_SZ;
+        ble_gatt_write_test_rx_prep_rsp(
+            2, 100, off, ble_gatt_write_test_attr_value + off, len);
+
+        /* Verify callback hasn't gotten called. */
+        TEST_ASSERT(!ble_gatt_write_test_cb_called);
+
+        off += len;
+    }
+
+    /* Verify prep write request was sent. */
+    ble_hs_test_util_tx_all();
+    TEST_ASSERT(ble_hs_test_util_prev_tx_dequeue() != NULL);
+
+    /* Receive queue full error. */
+    ble_hs_test_util_rx_att_err_rsp(2, BLE_ATT_OP_PREP_WRITE_REQ,
+                                    BLE_ATT_ERR_PREPARE_QUEUE_FULL, 100);
+
+    /* Verify callback was called. */
+    TEST_ASSERT(ble_gatt_write_test_cb_called);
+    TEST_ASSERT(ble_gatt_write_test_error.status ==
+                BLE_HS_ATT_ERR(BLE_ATT_ERR_PREPARE_QUEUE_FULL));
+    TEST_ASSERT(ble_gatt_write_test_error.att_handle == 100);
+
+    /* Verify clear queue command got sent. */
+    ble_hs_test_util_verify_tx_exec_write(0);
+}
+
 TEST_SUITE(ble_gatt_write_test_suite)
 {
     ble_gatt_write_test_no_rsp();
@@ -507,6 +559,7 @@ TEST_SUITE(ble_gatt_write_test_suite)
     ble_gatt_write_test_long_bad_offset();
     ble_gatt_write_test_long_bad_value();
     ble_gatt_write_test_long_bad_length();
+    ble_gatt_write_test_long_queue_full();
     ble_gatt_write_test_reliable_good();
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a7949f8/net/nimble/host/src/test/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.c b/net/nimble/host/src/test/ble_hs_test_util.c
index 5a8cac1..8f99ddd 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -776,6 +776,20 @@ ble_hs_test_util_set_public_addr(uint8_t *addr)
     ble_hs_priv_update_identity(addr);
 }
 
+void
+ble_hs_test_util_verify_tx_exec_write(uint8_t expected_flags)
+{
+    struct ble_att_exec_write_req req;
+    struct os_mbuf *om;
+
+    ble_hs_test_util_tx_all();
+    om = ble_hs_test_util_prev_tx_dequeue_pullup();
+    TEST_ASSERT_FATAL(om != NULL);
+    TEST_ASSERT(om->om_len == BLE_ATT_EXEC_WRITE_REQ_SZ);
+
+    ble_att_exec_write_req_parse(om->om_data, om->om_len, &req);
+    TEST_ASSERT(req.baeq_flags == expected_flags);
+}
 
 void
 ble_hs_test_util_init(void)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/1a7949f8/net/nimble/host/src/test/ble_hs_test_util.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.h b/net/nimble/host/src/test/ble_hs_test_util.h
index d53a7ea..55dcb21 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.h
+++ b/net/nimble/host/src/test/ble_hs_test_util.h
@@ -102,6 +102,7 @@ uint8_t *ble_hs_test_util_verify_tx_hci(uint8_t ogf, uint16_t ocf,
                                         uint8_t *out_param_len);
 void ble_hs_test_util_tx_all(void);
 void ble_hs_test_util_set_public_addr(uint8_t *addr);
+void ble_hs_test_util_verify_tx_exec_write(uint8_t expected_flags);
 void ble_hs_test_util_init(void);
 
 #endif


[26/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Nack unexpected LTK reqs from ctlr.

Posted by cc...@apache.org.
BLE Host - Nack unexpected LTK reqs from ctlr.


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

Branch: refs/heads/develop
Commit: a5f37f296655c4022cd29118b800198ec2f8231a
Parents: 5bbe267
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 8 18:36:44 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:36 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm.c | 39 +++++++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a5f37f29/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 d9c4fd5..49e7d53 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -1176,11 +1176,11 @@ ble_sm_ltk_req_rx(struct hci_le_lt_key_req *evt)
     struct ble_sm_result res;
     struct ble_sm_proc *proc;
     struct ble_hs_conn *conn;
-    int store_rc;
-    int bonding;
     uint8_t peer_addr[6];
     uint8_t *peer_id_addr;
     uint8_t peer_addr_type;
+    int store_rc;
+    int restore;
 
     /* Silence gcc warning. */
     peer_addr_type = BLE_STORE_ADDR_TYPE_NONE;
@@ -1192,11 +1192,11 @@ ble_sm_ltk_req_rx(struct hci_le_lt_key_req *evt)
                             0, NULL);
     if (proc == NULL) {
         /* The peer is attempting to restore a encrypted connection via the
-         * encryption procedure (bonding).  Create a proc entry to indicate
-         * that security establishment is in progress and execute the procedure
-         * after the mutex gets unlocked.
+         * encryption procedure.  Create a proc entry to indicate that security
+         * establishment is in progress and execute the procedure after the
+         * mutex gets unlocked.
          */
-        bonding = 1;
+        restore = 1;
         proc = ble_sm_proc_alloc();
         if (proc == NULL) {
             res.app_status = BLE_HS_ENOMEM;
@@ -1204,25 +1204,30 @@ ble_sm_ltk_req_rx(struct hci_le_lt_key_req *evt)
             proc->conn_handle = evt->connection_handle;
             proc->state = BLE_SM_PROC_STATE_LTK_RESTORE;
             ble_sm_insert(proc);
+
+            res.execute = 1;
         }
     } else if (proc->state == BLE_SM_PROC_STATE_SEC_REQ) {
         /* Same as above, except we solicited the encryption procedure by
          * sending a security request.
          */
-        bonding = 1;
+        restore = 1;
         proc->state = BLE_SM_PROC_STATE_LTK_RESTORE;
+        res.execute = 1;
     } else if (proc->state == BLE_SM_PROC_STATE_LTK_START) {
-        /* Short-term key pairing just completed.  Send the short term key to
-         * the controller.
+        /* Legacy pairing just completed.  Send the short term key to the
+         * controller.
          */
-        bonding = 0;
+        restore = 0;
+        res.execute = 1;
     } else {
-        /* The request is unexpected.  Quietly ignore it. */
+        /* The request is unexpected; nack and forget. */
+        restore = 0;
+        ble_sm_ltk_req_neg_reply_tx(evt->connection_handle);
         proc = NULL;
-        bonding = 0;
     }
 
-    if (bonding) {
+    if (restore) {
         conn = ble_hs_conn_find(evt->connection_handle);
         if (conn == NULL) {
             res.app_status = BLE_HS_ENOTCONN;
@@ -1241,15 +1246,17 @@ ble_sm_ltk_req_rx(struct hci_le_lt_key_req *evt)
     }
 
     if (res.app_status == 0) {
-        if (bonding) {
+        if (restore) {
             store_rc = ble_sm_retrieve_ltk(evt, peer_addr_type, peer_addr,
                                            &value_sec);
             if (store_rc == 0) {
+                /* Send the key to the controller. */
                 res.state_arg = &value_sec;
+            } else {
+                /* Send a nack to the controller. */
+                res.state_arg = NULL;
             }
         }
-
-        res.execute = 1;
     }
 
     ble_sm_process_result(evt->connection_handle, &res);


[03/50] [abbrv] incubator-mynewt-core git commit: bletiny - allow peer addr in undirected adv.

Posted by cc...@apache.org.
bletiny - allow peer addr in undirected adv.


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

Branch: refs/heads/develop
Commit: c312da67c2781e85e76b928e3dd99a56214ec0ed
Parents: 3550530
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 7 18:23:18 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:33 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/cmd.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c312da67/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index c9e38a9..178aeca 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -297,20 +297,17 @@ cmd_adv(int argc, char **argv)
         return -1;
     }
 
-    if (conn == BLE_GAP_CONN_MODE_DIR) {
-        addr_type = parse_arg_kv_default
-                ("peer_addr_type", cmd_adv_addr_types, BLE_ADDR_TYPE_PUBLIC);
-        if (addr_type == -1) {
-            return -1;
-        }
+    addr_type = parse_arg_kv_default
+            ("peer_addr_type", cmd_adv_addr_types, BLE_ADDR_TYPE_PUBLIC);
+    if (addr_type == -1) {
+        return -1;
+    }
 
-        rc = parse_arg_mac("addr", peer_addr);
-        if (rc != 0) {
-            return rc;
-        }
-    } else {
-        addr_type = BLE_ADDR_TYPE_PUBLIC;
+    rc = parse_arg_mac("peer_addr", peer_addr);
+    if (rc == ENOENT) {
         memset(peer_addr, 0, sizeof peer_addr);
+    } else if (rc != 0) {
+        return rc;
     }
 
     peer_addr_type = addr_type;


[07/50] [abbrv] incubator-mynewt-core git commit: bletiny - Read correct mst/slv ltk for sec restart

Posted by cc...@apache.org.
bletiny - Read correct mst/slv ltk for sec restart


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

Branch: refs/heads/develop
Commit: 069dae25bf426cea6fce73005db5d67332d20ea7
Parents: 3390ece
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 7 18:42:48 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:34 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/main.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/069dae25/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 4ed9858..f2cb04e 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -52,6 +52,7 @@
  */
 #include "../src/ble_hs_conn_priv.h"
 #include "../src/ble_hci_util_priv.h"
+#include "../src/ble_hs_atomic_priv.h"
 
 #define BSWAP16(x)  ((uint16_t)(((x) << 8) | (((x) & 0xff00) >> 8)))
 
@@ -1417,6 +1418,7 @@ bletiny_sec_restart(uint16_t conn_handle,
     struct ble_store_value_sec value_sec;
     struct ble_store_key_sec key_sec;
     struct ble_gap_conn_desc desc;
+    ble_hs_conn_flags_t conn_flags;
     int rc;
 
     if (ltk == NULL) {
@@ -1430,7 +1432,15 @@ bletiny_sec_restart(uint16_t conn_handle,
         key_sec.peer_addr_type = desc.peer_addr_type;
         memcpy(key_sec.peer_addr, desc.peer_addr, 6);
 
-        rc = ble_store_read_mst_sec(&key_sec, &value_sec);
+        rc = ble_hs_atomic_conn_flags(conn_handle, &conn_flags);
+        if (rc != 0) {
+            return rc;
+        }
+        if (conn_flags & BLE_HS_CONN_F_MASTER) {
+            rc = ble_store_read_mst_sec(&key_sec, &value_sec);
+        } else {
+            rc = ble_store_read_slv_sec(&key_sec, &value_sec);
+        }
         if (rc != 0) {
             return rc;
         }


[41/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Persist our IRK.

Posted by cc...@apache.org.
BLE Host - Persist our IRK.


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

Branch: refs/heads/develop
Commit: c684288390b808827f08fa7c62b3ad50522f2efd
Parents: 4f9739f
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 14 09:19:54 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:24:20 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm.c | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c6842883/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 751a062..0ffa066 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -1757,6 +1757,7 @@ ble_sm_key_exch_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
         if (rc != 0) {
             goto err;
         }
+        proc->our_keys.irk_valid = 1;
 
         /* Send identity address information. */
         bls_hs_priv_copy_local_identity_addr(addr_info.bd_addr,


[12/50] [abbrv] incubator-mynewt-core git commit: BLE Host - initiator tx key exch if no keys rx.

Posted by cc...@apache.org.
BLE Host - initiator tx key exch if no keys rx.


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

Branch: refs/heads/develop
Commit: 0fea97810e84002b1ee1ec5b31cdbd88ac3e6e97
Parents: 830149e
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 8 15:04:26 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:35 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/0fea9781/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 ade4702..27863a1 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -992,7 +992,9 @@ ble_sm_enc_change_rx(struct hci_encrypt_change *evt)
                 proc->state = BLE_SM_PROC_STATE_KEY_EXCH;
 
                 /* The responder sends its keys first. */
-                if (!(proc->flags & BLE_SM_PROC_F_INITIATOR)) {
+                if (!(proc->flags & BLE_SM_PROC_F_INITIATOR) ||
+                    proc->rx_key_flags == 0) {
+
                     res.execute = 1;
                 }
             } else {
@@ -1174,7 +1176,7 @@ ble_sm_ltk_restore_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
         res->app_status = BLE_HS_ENOENT;
     }
 
-    
+
     if (res->app_status == 0) {
         proc->state = BLE_SM_PROC_STATE_ENC_RESTORE;
     }


[02/50] [abbrv] incubator-mynewt-core git commit: bletiny - add "datalen" command.

Posted by cc...@apache.org.
bletiny - add "datalen" 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/4f891353
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4f891353
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4f891353

Branch: refs/heads/develop
Commit: 4f891353c6a674ab552db419c586392ba7e8e80c
Parents: c312da6
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 7 18:27:47 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:33 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/bletiny.h |  2 ++
 apps/bletiny/src/cmd.c     | 39 ++++++++++++++++++++++++++++++++++++++-
 apps/bletiny/src/main.c    |  9 +++++++++
 3 files changed, 49 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4f891353/apps/bletiny/src/bletiny.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny.h b/apps/bletiny/src/bletiny.h
index c5c5921..6ca6d77 100644
--- a/apps/bletiny/src/bletiny.h
+++ b/apps/bletiny/src/bletiny.h
@@ -169,6 +169,8 @@ int bletiny_set_adv_data(struct ble_hs_adv_fields *adv_fields);
 int bletiny_update_conn(uint16_t conn_handle,
                          struct ble_gap_upd_params *params);
 void bletiny_chrup(uint16_t attr_handle);
+int bletiny_datalen(uint16_t conn_handle, uint16_t tx_octets,
+                    uint16_t tx_time);
 int bletiny_l2cap_update(uint16_t conn_handle,
                           struct ble_l2cap_sig_update_params *params);
 int bletiny_sec_start(uint16_t conn_handle);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4f891353/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 178aeca..9a3fe14 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -454,7 +454,7 @@ cmd_conn(int argc, char **argv)
 }
 
 /*****************************************************************************
- * $connect                                                                  *
+ * $chrup                                                                    *
  *****************************************************************************/
 
 static int
@@ -474,6 +474,42 @@ cmd_chrup(int argc, char **argv)
 }
 
 /*****************************************************************************
+ * $datalen                                                                  *
+ *****************************************************************************/
+
+static int
+cmd_datalen(int argc, char **argv)
+{
+    uint16_t conn_handle;
+    uint16_t tx_octets;
+    uint16_t tx_time;
+    int rc;
+
+    conn_handle = parse_arg_uint16("conn", &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    tx_octets = parse_arg_long("octets", &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    tx_time = parse_arg_long("time", &rc);
+    if (rc != 0) {
+        return rc;
+    }
+
+    rc = bletiny_datalen(conn_handle, tx_octets, tx_time);
+    if (rc != 0) {
+        console_printf("error setting data length; rc=%d\n", rc);
+        return rc;
+    }
+
+    return 0;
+}
+
+/*****************************************************************************
  * $discover                                                                 *
  *****************************************************************************/
 
@@ -2064,6 +2100,7 @@ static struct cmd_entry cmd_b_entries[] = {
     { "adv",        cmd_adv },
     { "conn",       cmd_conn },
     { "chrup",      cmd_chrup },
+    { "datalen",    cmd_datalen },
     { "disc",       cmd_disc },
     { "find",       cmd_find },
     { "l2cap",      cmd_l2cap },

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4f891353/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 6e97f84..4ed9858 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1371,6 +1371,15 @@ bletiny_chrup(uint16_t attr_handle)
 }
 
 int
+bletiny_datalen(uint16_t conn_handle, uint16_t tx_octets, uint16_t tx_time)
+{
+    int rc;
+
+    rc = ble_hci_util_set_data_len(conn_handle, tx_octets, tx_time);
+    return rc;
+}
+
+int
 bletiny_l2cap_update(uint16_t conn_handle,
                      struct ble_l2cap_sig_update_params *params)
 {


[48/50] [abbrv] incubator-mynewt-core git commit: BLE Host - unit tests for combined priv/sc.

Posted by cc...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b4c34462/net/nimble/host/src/test/ble_sm_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test_util.c b/net/nimble/host/src/test/ble_sm_test_util.c
index 28c2a2a..0dcd8af 100644
--- a/net/nimble/host/src/test/ble_sm_test_util.c
+++ b/net/nimble/host/src/test/ble_sm_test_util.c
@@ -533,6 +533,10 @@ ble_sm_test_util_verify_tx_id_addr_info(struct ble_sm_id_addr_info *exp_cmd)
 {
     struct ble_sm_id_addr_info cmd;
     struct os_mbuf *om;
+    uint8_t *our_id_addr;
+    uint8_t our_id_addr_type;
+
+    our_id_addr = bls_hs_priv_get_local_identity_addr(&our_id_addr_type);
 
     ble_hs_test_util_tx_all();
     om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_IDENTITY_ADDR_INFO,
@@ -541,6 +545,9 @@ ble_sm_test_util_verify_tx_id_addr_info(struct ble_sm_id_addr_info *exp_cmd)
 
     TEST_ASSERT(cmd.addr_type == exp_cmd->addr_type);
     TEST_ASSERT(memcmp(cmd.bd_addr, exp_cmd->bd_addr, 6) == 0);
+
+    TEST_ASSERT(cmd.addr_type == our_id_addr_type);
+    TEST_ASSERT(memcmp(cmd.bd_addr, our_id_addr, 6) == 0);
 }
 
 static void
@@ -691,6 +698,30 @@ ble_sm_test_util_verify_tx_start_enc(uint16_t conn_handle,
     TEST_ASSERT(memcmp(param + 12, ltk, 16) == 0);
 }
 
+static void
+ble_sm_test_util_verify_tx_add_resolve_list(uint8_t peer_id_addr_type,
+                                            uint8_t *peer_id_addr,
+                                            uint8_t *peer_irk,
+                                            uint8_t *our_irk)
+{
+    uint8_t buf[16];
+    uint8_t param_len;
+    uint8_t *param;
+
+    param = ble_hs_test_util_verify_tx_hci(BLE_HCI_OGF_LE,
+                                           BLE_HCI_OCF_LE_ADD_RESOLV_LIST,
+                                           &param_len);
+    TEST_ASSERT(param_len == BLE_HCI_ADD_TO_RESOLV_LIST_LEN);
+    TEST_ASSERT(param[0] == peer_id_addr_type);
+    TEST_ASSERT(memcmp(param + 1, peer_id_addr, 6) == 0);
+
+    /* Ensure IRKs are sent in little endian. */
+    memcpy(buf, peer_irk, 16);
+    TEST_ASSERT(memcmp(param + 7, buf, 16) == 0);
+    memcpy(buf, our_irk, 16);
+    TEST_ASSERT(memcmp(param + 23, buf, 16) == 0);
+}
+
 void
 ble_sm_test_util_io_inject(struct ble_sm_test_passkey_info *passkey_info,
                            uint8_t cur_sm_state)
@@ -818,7 +849,7 @@ ble_sm_test_util_verify_lgcy_persist(struct ble_sm_test_lgcy_params *params)
         rc = ble_store_read_peer_sec(&key_sec, &value_sec);
         TEST_ASSERT_FATAL(rc == 0);
         TEST_ASSERT(value_sec.peer_addr_type == 0);
-        TEST_ASSERT(memcmp(value_sec.peer_addr, params->init_addr, 6) == 0);
+        TEST_ASSERT(memcmp(value_sec.peer_addr, params->init_id_addr, 6) == 0);
         TEST_ASSERT(value_sec.ediv == params->ediv);
         TEST_ASSERT(value_sec.rand_num == params->r);
         TEST_ASSERT(value_sec.authenticated == params->authenticated);
@@ -843,7 +874,7 @@ ble_sm_test_util_verify_lgcy_persist(struct ble_sm_test_lgcy_params *params)
         rc = ble_store_read_our_sec(&key_sec, &value_sec);
         TEST_ASSERT_FATAL(rc == 0);
         TEST_ASSERT(value_sec.peer_addr_type == 0);
-        TEST_ASSERT(memcmp(value_sec.peer_addr, params->init_addr, 6) == 0);
+        TEST_ASSERT(memcmp(value_sec.peer_addr, params->init_id_addr, 6) == 0);
         TEST_ASSERT(value_sec.ediv == params->ediv);
         TEST_ASSERT(value_sec.rand_num == params->r);
         TEST_ASSERT(value_sec.authenticated == params->authenticated);
@@ -865,16 +896,18 @@ ble_sm_test_util_verify_sc_persist(struct ble_sm_test_sc_params *params,
 {
     struct ble_store_value_sec value_sec;
     struct ble_store_key_sec key_sec;
-    uint8_t *peer_addr;
-    uint8_t *mst_csrk;
-    uint8_t *slv_csrk;
-    uint8_t *mst_irk;
-    uint8_t *slv_irk;
+    uint8_t *peer_id_addr;
+    uint8_t *peer_csrk;
+    uint8_t *our_csrk;
+    uint8_t *peer_irk;
+    uint8_t *our_irk;
+    uint8_t peer_id_addr_type;
     uint8_t peer_addr_type;
     uint8_t peer_key_dist;
     uint8_t our_key_dist;
     int csrk_expected;
-    int irk_expected;
+    int peer_irk_expected;
+    int our_irk_expected;
     int bonding;
     int rc;
 
@@ -882,25 +915,26 @@ ble_sm_test_util_verify_sc_persist(struct ble_sm_test_sc_params *params,
         our_key_dist = params->pair_rsp.init_key_dist;
         peer_key_dist = params->pair_rsp.resp_key_dist;
 
-        peer_addr_type = 0;
-        peer_addr = params->resp_addr;
+        peer_addr_type = params->resp_addr_type;
+        peer_id_addr = params->resp_id_addr;
 
-        mst_irk = params->id_info_req.irk;
-        mst_csrk = params->sign_info_req.sig_key;
-        slv_irk = params->id_info_rsp.irk;
-        slv_csrk = params->sign_info_rsp.sig_key;
+        peer_irk = params->id_info_req.irk;
+        peer_csrk = params->sign_info_req.sig_key;
+        our_irk = params->id_info_rsp.irk;
+        our_csrk = params->sign_info_rsp.sig_key;
     } else {
         our_key_dist = params->pair_rsp.resp_key_dist;
         peer_key_dist = params->pair_rsp.init_key_dist;
 
-        peer_addr_type = 0;
-        peer_addr = params->init_addr;
+        peer_addr_type = params->init_addr_type;
+        peer_id_addr = params->init_id_addr;
 
-        mst_irk = params->id_info_rsp.irk;
-        mst_csrk = params->sign_info_rsp.sig_key;
-        slv_irk = params->id_info_req.irk;
-        slv_csrk = params->sign_info_req.sig_key;
+        peer_irk = params->id_info_rsp.irk;
+        peer_csrk = params->sign_info_rsp.sig_key;
+        our_irk = params->id_info_req.irk;
+        our_csrk = params->sign_info_req.sig_key;
     }
+    peer_id_addr_type = ble_hs_misc_addr_type_to_id(peer_addr_type);
 
     memset(&key_sec, 0, sizeof key_sec);
     key_sec.peer_addr_type = BLE_STORE_ADDR_TYPE_NONE;
@@ -911,14 +945,15 @@ ble_sm_test_util_verify_sc_persist(struct ble_sm_test_sc_params *params,
     rc = ble_store_read_peer_sec(&key_sec, &value_sec);
     if (!bonding) {
         TEST_ASSERT(rc == BLE_HS_ENOENT);
+        peer_irk_expected = 0;
     } else {
         TEST_ASSERT_FATAL(rc == 0);
 
-        irk_expected = !!(peer_key_dist & BLE_SM_PAIR_KEY_DIST_ID);
+        peer_irk_expected = !!(peer_key_dist & BLE_SM_PAIR_KEY_DIST_ID);
         csrk_expected = !!(peer_key_dist & BLE_SM_PAIR_KEY_DIST_SIGN);
 
-        TEST_ASSERT(value_sec.peer_addr_type == peer_addr_type);
-        TEST_ASSERT(memcmp(value_sec.peer_addr, peer_addr, 6) == 0);
+        TEST_ASSERT(value_sec.peer_addr_type == peer_id_addr_type);
+        TEST_ASSERT(memcmp(value_sec.peer_addr, peer_id_addr, 6) == 0);
         TEST_ASSERT(value_sec.ediv == 0);
         TEST_ASSERT(value_sec.rand_num == 0);
         TEST_ASSERT(value_sec.authenticated == params->authenticated);
@@ -928,14 +963,14 @@ ble_sm_test_util_verify_sc_persist(struct ble_sm_test_sc_params *params,
         TEST_ASSERT(value_sec.ltk_present == 1);
         TEST_ASSERT(memcmp(value_sec.ltk, params->ltk, 16) == 0);
 
-        TEST_ASSERT(value_sec.irk_present == irk_expected);
-        if (irk_expected) {
-            TEST_ASSERT(memcmp(value_sec.irk, mst_irk, 16) == 0);
+        TEST_ASSERT(value_sec.irk_present == peer_irk_expected);
+        if (peer_irk_expected) {
+            TEST_ASSERT(memcmp(value_sec.irk, peer_irk, 16) == 0);
         }
 
         TEST_ASSERT(value_sec.csrk_present == csrk_expected);
         if (csrk_expected) {
-            TEST_ASSERT(memcmp(value_sec.csrk, mst_csrk, 16) == 0);
+            TEST_ASSERT(memcmp(value_sec.csrk, peer_csrk, 16) == 0);
         }
     }
 
@@ -945,11 +980,11 @@ ble_sm_test_util_verify_sc_persist(struct ble_sm_test_sc_params *params,
     } else {
         TEST_ASSERT_FATAL(rc == 0);
 
-        irk_expected = !!(our_key_dist & BLE_SM_PAIR_KEY_DIST_ID);
+        our_irk_expected = !!(our_key_dist & BLE_SM_PAIR_KEY_DIST_ID);
         csrk_expected = !!(our_key_dist & BLE_SM_PAIR_KEY_DIST_SIGN);
 
-        TEST_ASSERT(value_sec.peer_addr_type == peer_addr_type);
-        TEST_ASSERT(memcmp(value_sec.peer_addr, peer_addr, 6) == 0);
+        TEST_ASSERT(value_sec.peer_addr_type == peer_id_addr_type);
+        TEST_ASSERT(memcmp(value_sec.peer_addr, peer_id_addr, 6) == 0);
         TEST_ASSERT(value_sec.ediv == 0);
         TEST_ASSERT(value_sec.rand_num == 0);
         TEST_ASSERT(value_sec.authenticated == params->authenticated);
@@ -957,14 +992,14 @@ ble_sm_test_util_verify_sc_persist(struct ble_sm_test_sc_params *params,
         TEST_ASSERT(value_sec.ltk_present == 1);
         TEST_ASSERT(memcmp(value_sec.ltk, params->ltk, 16) == 0);
 
-        TEST_ASSERT(value_sec.irk_present == irk_expected);
-        if (irk_expected) {
-            TEST_ASSERT(memcmp(value_sec.irk, slv_irk, 16) == 0);
+        TEST_ASSERT(value_sec.irk_present == our_irk_expected);
+        if (our_irk_expected) {
+            TEST_ASSERT(memcmp(value_sec.irk, our_irk, 16) == 0);
         }
 
         TEST_ASSERT(value_sec.csrk_present == csrk_expected);
         if (csrk_expected) {
-            TEST_ASSERT(memcmp(value_sec.csrk, slv_csrk, 16) == 0);
+            TEST_ASSERT(memcmp(value_sec.csrk, our_csrk, 16) == 0);
         }
     }
 
@@ -974,6 +1009,13 @@ ble_sm_test_util_verify_sc_persist(struct ble_sm_test_sc_params *params,
     TEST_ASSERT_FATAL(rc == BLE_HS_ENOENT);
     rc = ble_store_read_peer_sec(&key_sec, &value_sec);
     TEST_ASSERT_FATAL(rc == BLE_HS_ENOENT);
+
+    /* Verify we sent the peer's IRK to the controller. */
+    if (peer_irk_expected) {
+        ble_sm_test_util_verify_tx_add_resolve_list(peer_id_addr_type,
+                                                    peer_id_addr,
+                                                    peer_irk, our_irk);
+    }
 }
 
 void
@@ -984,7 +1026,7 @@ ble_sm_test_util_us_lgcy_good(
     int rc;
 
     ble_sm_test_util_init();
-    ble_hs_test_util_set_public_addr(params->init_addr);
+    ble_hs_test_util_set_public_addr(params->init_id_addr);
     ble_sm_dbg_set_next_pair_rand(params->random_req.value);
     ble_sm_dbg_set_next_ediv(params->ediv);
     ble_sm_dbg_set_next_start_rand(params->r);
@@ -993,7 +1035,7 @@ ble_sm_test_util_us_lgcy_good(
         ble_sm_dbg_set_next_ltk(params->enc_info_req.ltk);
     }
 
-    ble_hs_test_util_create_conn(2, params->resp_addr,
+    ble_hs_test_util_create_conn(2, params->resp_id_addr,
                                  ble_sm_test_util_conn_cb,
                                  NULL);
 
@@ -1096,7 +1138,7 @@ ble_sm_test_util_us_lgcy_good(
 void
 ble_sm_test_util_peer_fail_inval(
     int we_are_master,
-    uint8_t *init_addr,
+    uint8_t *init_id_addr,
     uint8_t *resp_addr,
     struct ble_sm_pair_cmd *pair_req,
     struct ble_sm_pair_fail *pair_fail)
@@ -1106,7 +1148,7 @@ ble_sm_test_util_peer_fail_inval(
     ble_sm_test_util_init();
     ble_hs_test_util_set_public_addr(resp_addr);
 
-    ble_hs_test_util_create_conn(2, init_addr, ble_sm_test_util_conn_cb,
+    ble_hs_test_util_create_conn(2, init_id_addr, ble_sm_test_util_conn_cb,
                                  NULL);
 
     /* This test inspects and modifies the connection object after unlocking
@@ -1148,7 +1190,7 @@ ble_sm_test_util_peer_fail_inval(
 
 void
 ble_sm_test_util_peer_lgcy_fail_confirm(
-    uint8_t *init_addr,
+    uint8_t *init_id_addr,
     uint8_t *resp_addr,
     struct ble_sm_pair_cmd *pair_req,
     struct ble_sm_pair_cmd *pair_rsp,
@@ -1164,7 +1206,7 @@ ble_sm_test_util_peer_lgcy_fail_confirm(
     ble_hs_test_util_set_public_addr(resp_addr);
     ble_sm_dbg_set_next_pair_rand(random_rsp->value);
 
-    ble_hs_test_util_create_conn(2, init_addr, ble_sm_test_util_conn_cb,
+    ble_hs_test_util_create_conn(2, init_id_addr, ble_sm_test_util_conn_cb,
                                  NULL);
 
     /* This test inspects and modifies the connection object after unlocking
@@ -1248,7 +1290,7 @@ ble_sm_test_util_peer_lgcy_good_once(struct ble_sm_test_lgcy_params *params)
     ble_hs_cfg.sm_our_key_dist = params->pair_rsp.resp_key_dist;
     ble_hs_cfg.sm_their_key_dist = params->pair_rsp.init_key_dist;
 
-    ble_hs_test_util_set_public_addr(params->resp_addr);
+    ble_hs_test_util_set_public_addr(params->resp_id_addr);
     ble_sm_dbg_set_next_pair_rand(params->random_rsp.value);
     ble_sm_dbg_set_next_ediv(params->ediv);
     ble_sm_dbg_set_next_start_rand(params->r);
@@ -1257,7 +1299,7 @@ ble_sm_test_util_peer_lgcy_good_once(struct ble_sm_test_lgcy_params *params)
         ble_sm_dbg_set_next_ltk(params->enc_info_req.ltk);
     }
 
-    ble_hs_test_util_create_conn(2, params->init_addr,
+    ble_hs_test_util_create_conn(2, params->init_id_addr,
                                  ble_sm_test_util_conn_cb,
                                  NULL);
 
@@ -1599,7 +1641,7 @@ ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
     ble_hs_cfg.sm_our_key_dist = params->pair_rsp.resp_key_dist;
     ble_hs_cfg.sm_their_key_dist = params->pair_rsp.init_key_dist;
 
-    ble_hs_test_util_set_public_addr(params->resp_addr);
+    ble_hs_test_util_set_public_addr(params->resp_id_addr);
     ble_sm_dbg_set_next_pair_rand(params->random_rsp[0].value);
 
     ble_sm_dbg_set_sc_keys(params->public_key_rsp.x, params->our_priv_key);
@@ -1609,9 +1651,12 @@ ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
         ble_sm_dbg_set_next_csrk(params->sign_info_req.sig_key);
     }
 
-    ble_hs_test_util_create_conn(2, params->init_addr,
-                                 ble_sm_test_util_conn_cb,
-                                 NULL);
+    ble_hs_test_util_create_rpa_conn(2, params->resp_rpa,
+                                     params->init_addr_type,
+                                     params->init_id_addr,
+                                     params->init_rpa,
+                                     ble_sm_test_util_conn_cb,
+                                     NULL);
 
     /* This test inspects and modifies the connection object after unlocking
      * the host mutex.  It is not OK for real code to do this, but this test
@@ -1765,6 +1810,9 @@ ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
 
     /* Receive key material from peer. */
     if (params->pair_rsp.init_key_dist & BLE_SM_PAIR_KEY_DIST_ID) {
+        ble_hs_test_util_set_ack(
+            host_hci_opcode_join(BLE_HCI_OGF_LE,
+                                 BLE_HCI_OCF_LE_ADD_RESOLV_LIST), 0);
         ble_sm_test_util_rx_id_info(2, &params->id_info_rsp, 0);
         ble_sm_test_util_rx_id_addr_info(2, &params->id_addr_info_rsp, 0);
     }
@@ -1810,22 +1858,22 @@ ble_sm_test_util_peer_sc_good(struct ble_sm_test_sc_params *params)
     /*** Verify link can be restored via the encryption procedure. */
 
     /* Peer is master; peer initiates procedure. */
-    ble_sm_test_util_peer_bonding_good(0, 0, params->init_addr,
+    ble_sm_test_util_peer_bonding_good(0, 0, params->init_id_addr,
                                        params->ltk, params->authenticated,
                                        0, 0);
 
     /* Peer is master; we initiate procedure via security request. */
-    ble_sm_test_util_peer_bonding_good(1, 0, params->init_addr,
+    ble_sm_test_util_peer_bonding_good(1, 0, params->init_id_addr,
                                        params->ltk, params->authenticated,
                                        0, 0);
 
     /* We are master; we initiate procedure. */
-    ble_sm_test_util_us_bonding_good(0, 0, params->init_addr,
+    ble_sm_test_util_us_bonding_good(0, 0, params->init_id_addr,
                                      params->ltk, params->authenticated,
                                      0, 0);
 
     /* We are master; peer initiates procedure via security request. */
-    ble_sm_test_util_us_bonding_good(1, 0, params->init_addr,
+    ble_sm_test_util_us_bonding_good(1, 0, params->init_id_addr,
                                      params->ltk, params->authenticated,
                                      0, 0);
 }
@@ -1852,7 +1900,7 @@ ble_sm_test_util_us_sc_good(struct ble_sm_test_sc_params *params)
     ble_hs_cfg.sm_our_key_dist = params->pair_req.init_key_dist;
     ble_hs_cfg.sm_their_key_dist = params->pair_req.resp_key_dist;
 
-    ble_hs_test_util_set_public_addr(params->init_addr);
+    ble_hs_test_util_set_public_addr(params->init_id_addr);
     ble_sm_dbg_set_next_pair_rand(params->random_req[0].value);
 
     ble_sm_dbg_set_sc_keys(params->public_key_req.x, params->our_priv_key);
@@ -1862,9 +1910,12 @@ ble_sm_test_util_us_sc_good(struct ble_sm_test_sc_params *params)
         ble_sm_dbg_set_next_csrk(params->sign_info_rsp.sig_key);
     }
 
-    ble_hs_test_util_create_conn(2, params->resp_addr,
-                                 ble_sm_test_util_conn_cb,
-                                 NULL);
+    ble_hs_test_util_create_rpa_conn(2, params->init_rpa,
+                                     params->resp_addr_type,
+                                     params->resp_id_addr,
+                                     params->resp_rpa,
+                                     ble_sm_test_util_conn_cb,
+                                     NULL);
 
     /* This test inspects and modifies the connection object after unlocking
      * the host mutex.  It is not OK for real code to do this, but this test
@@ -2037,11 +2088,11 @@ ble_sm_test_util_us_fail_inval(
     int rc;
 
     ble_sm_test_util_init();
-    ble_hs_test_util_set_public_addr(params->resp_addr);
+    ble_hs_test_util_set_public_addr(params->resp_id_addr);
 
     ble_sm_dbg_set_next_pair_rand(((uint8_t[16]){0}));
 
-    ble_hs_test_util_create_conn(2, params->init_addr,
+    ble_hs_test_util_create_conn(2, params->init_id_addr,
                                  ble_sm_test_util_conn_cb,
                                  NULL);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b4c34462/net/nimble/host/src/test/ble_sm_test_util.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test_util.h b/net/nimble/host/src/test/ble_sm_test_util.h
index b9dac79..9d95c92 100644
--- a/net/nimble/host/src/test/ble_sm_test_util.h
+++ b/net/nimble/host/src/test/ble_sm_test_util.h
@@ -27,8 +27,12 @@ struct ble_sm_test_passkey_info {
 };
 
 struct ble_sm_test_lgcy_params {
-    uint8_t init_addr[6];
-    uint8_t resp_addr[6];
+    uint8_t init_addr_type;
+    uint8_t init_id_addr[6];
+    uint8_t init_rpa[6];
+    uint8_t resp_addr_type;
+    uint8_t resp_id_addr[6];
+    uint8_t resp_rpa[6];
     struct ble_sm_sec_req sec_req;
     struct ble_sm_pair_cmd pair_req;
     struct ble_sm_pair_cmd pair_rsp;
@@ -58,8 +62,12 @@ struct ble_sm_test_lgcy_params {
 };
 
 struct ble_sm_test_sc_params {
-    uint8_t init_addr[6];
-    uint8_t resp_addr[6];
+    uint8_t init_addr_type;
+    uint8_t init_id_addr[6];
+    uint8_t init_rpa[6];
+    uint8_t resp_addr_type;
+    uint8_t resp_id_addr[6];
+    uint8_t resp_rpa[6];
     struct ble_sm_sec_req sec_req;
     struct ble_sm_pair_cmd pair_req;
     struct ble_sm_pair_cmd pair_rsp;


[30/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Fix mistakes in IO capabilities tables.

Posted by cc...@apache.org.
BLE Host - Fix mistakes in IO capabilities tables.


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

Branch: refs/heads/develop
Commit: 84519461a1d2c1ea50d89168d832d55f43de0dee
Parents: 24cd9ab
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jun 10 10:08:44 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:39 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm_lgcy.c |  8 ++++----
 net/nimble/host/src/ble_sm_sc.c   | 36 +++++++++++++++++++---------------
 2 files changed, 24 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/84519461/net/nimble/host/src/ble_sm_lgcy.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_lgcy.c b/net/nimble/host/src/ble_sm_lgcy.c
index 4696a07..a93622e 100644
--- a/net/nimble/host/src/ble_sm_lgcy.c
+++ b/net/nimble/host/src/ble_sm_lgcy.c
@@ -39,7 +39,7 @@
 /* This is the initiator passkey action action dpeneding on the io
  * capabilties of both parties
  */
-static const uint8_t ble_sm_lgcy_init_pka[5 /*resp*/ ][5 /*init */] =
+static const uint8_t ble_sm_lgcy_init_ioa[5 /*resp*/ ][5 /*init*/] =
 {
     {IOACT_NONE,    IOACT_NONE,   IOACT_INPUT, IOACT_NONE, IOACT_INPUT},
     {IOACT_NONE,    IOACT_NONE,   IOACT_INPUT, IOACT_NONE, IOACT_INPUT},
@@ -51,7 +51,7 @@ static const uint8_t ble_sm_lgcy_init_pka[5 /*resp*/ ][5 /*init */] =
 /* This is the responder passkey action action depending on the io
  * capabilities of both parties
  */
-static const uint8_t ble_sm_lgcy_resp_pka[5 /*init*/ ][5 /*resp */] =
+static const uint8_t ble_sm_lgcy_resp_ioa[5 /*resp*/ ][5 /*init*/] =
 {
     {IOACT_NONE,    IOACT_NONE,   IOACT_DISP,  IOACT_NONE, IOACT_DISP},
     {IOACT_NONE,    IOACT_NONE,   IOACT_DISP,  IOACT_NONE, IOACT_DISP},
@@ -72,10 +72,10 @@ ble_sm_lgcy_io_action(struct ble_sm_proc *proc)
 
         action = BLE_SM_IOACT_NONE;
     } else if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
-        action = ble_sm_lgcy_init_pka[proc->pair_rsp.io_cap]
+        action = ble_sm_lgcy_init_ioa[proc->pair_rsp.io_cap]
                                      [proc->pair_req.io_cap];
     } else {
-        action = ble_sm_lgcy_resp_pka[proc->pair_rsp.io_cap]
+        action = ble_sm_lgcy_resp_ioa[proc->pair_rsp.io_cap]
                                      [proc->pair_req.io_cap];
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/84519461/net/nimble/host/src/ble_sm_sc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_sc.c b/net/nimble/host/src/ble_sm_sc.c
index 5405eaa..c16d20d 100644
--- a/net/nimble/host/src/ble_sm_sc.c
+++ b/net/nimble/host/src/ble_sm_sc.c
@@ -60,29 +60,33 @@ static uint8_t ble_sm_sc_keys_generated;
 #define IOACT_NUMCMP    BLE_SM_IOACT_NUMCMP
 
 /**
- * This is the initiator passkey action action dpeneding on the io
- * capabilties of both parties
+ * This table expresses the required initiator IO action.  Inputs are:
+ *     o Responder IO capabilities (from pair response).
+ *     o Initiator IO capabilities (from pair request).
  */
-static const uint8_t ble_sm_sc_init_ioa[5 /*resp*/ ][5 /*init */] =
+static const uint8_t ble_sm_sc_init_ioa[5 /*resp*/ ][5 /*init*/ ] =
 {
-    {IOACT_NONE,    IOACT_NONE,   IOACT_INPUT, IOACT_NONE, IOACT_INPUT},
-    {IOACT_NONE,    IOACT_NUMCMP, IOACT_INPUT, IOACT_NONE, IOACT_INPUT},
-    {IOACT_DISP,    IOACT_DISP,   IOACT_INPUT, IOACT_NONE, IOACT_DISP},
-    {IOACT_NONE,    IOACT_NONE,   IOACT_NONE,  IOACT_NONE, IOACT_NONE},
-    {IOACT_DISP,    IOACT_NUMCMP, IOACT_INPUT, IOACT_NONE, IOACT_NUMCMP},
+      /* init */
+/*r*/ {IOACT_NONE,    IOACT_NONE,   IOACT_INPUT, IOACT_NONE, IOACT_INPUT},
+/*e*/ {IOACT_NONE,    IOACT_NUMCMP, IOACT_INPUT, IOACT_NONE, IOACT_NUMCMP},
+/*s*/ {IOACT_DISP,    IOACT_DISP,   IOACT_INPUT, IOACT_NONE, IOACT_DISP},
+/*p*/ {IOACT_NONE,    IOACT_NONE,   IOACT_NONE,  IOACT_NONE, IOACT_NONE},
+      {IOACT_DISP,    IOACT_NUMCMP, IOACT_INPUT, IOACT_NONE, IOACT_NUMCMP},
 };
 
 /**
- * This is the responder passkey action action depending on the io
- * capabilities of both parties
+ * This table expresses the required responder IO action.  Inputs are:
+ *     o Responder IO capabilities (from pair response).
+ *     o Initiator IO capabilities (from pair request).
  */
-static const uint8_t ble_sm_sc_resp_ioa[5 /*init*/ ][5 /*resp */] =
+static const uint8_t ble_sm_sc_resp_ioa[5 /*resp*/ ][5 /*init*/ ] =
 {
-    {IOACT_NONE,    IOACT_NONE,   IOACT_DISP,  IOACT_NONE, IOACT_DISP},
-    {IOACT_NONE,    IOACT_NUMCMP, IOACT_DISP,  IOACT_NONE, IOACT_NUMCMP},
-    {IOACT_INPUT,   IOACT_INPUT,  IOACT_INPUT, IOACT_NONE, IOACT_INPUT},
-    {IOACT_NONE,    IOACT_NONE,   IOACT_NONE,  IOACT_NONE, IOACT_NONE},
-    {IOACT_INPUT,   IOACT_NUMCMP, IOACT_DISP,  IOACT_NONE, IOACT_NUMCMP},
+      /* init */
+/*r*/ {IOACT_NONE,    IOACT_NONE,   IOACT_DISP,  IOACT_NONE, IOACT_DISP},
+/*e*/ {IOACT_NONE,    IOACT_NUMCMP, IOACT_DISP,  IOACT_NONE, IOACT_NUMCMP},
+/*s*/ {IOACT_INPUT,   IOACT_INPUT,  IOACT_INPUT, IOACT_NONE, IOACT_INPUT},
+/*p*/ {IOACT_NONE,    IOACT_NONE,   IOACT_NONE,  IOACT_NONE, IOACT_NONE},
+      {IOACT_INPUT,   IOACT_NUMCMP, IOACT_DISP,  IOACT_NONE, IOACT_NUMCMP},
 };
 
 int


[42/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Rename mst/slv sec -> peer/our

Posted by cc...@apache.org.
BLE Host - Rename mst/slv sec -> peer/our

The "master security" and "slave security" nomenclature was misguided.
It only made sense for the LTK persisted during legacy pairing.


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

Branch: refs/heads/develop
Commit: d47d308a6ec1c0eaced171a805c05c1f5f353caa
Parents: c684288
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 14 09:25:02 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:24:20 2016 -0700

----------------------------------------------------------------------
 apps/bleprph/src/store.c                        | 76 +++++++++---------
 apps/bletiny/src/cmd.c                          | 24 +++---
 apps/bletiny/src/main.c                         |  4 +-
 apps/bletiny/src/store.c                        | 84 ++++++++++----------
 net/nimble/host/include/host/ble_store.h        | 20 ++---
 net/nimble/host/src/ble_sm.c                    |  8 +-
 net/nimble/host/src/ble_store.c                 | 26 +++---
 .../host/src/test/ble_hs_test_util_store.c      | 70 ++++++++--------
 net/nimble/host/src/test/ble_sm_test_util.c     | 28 +++----
 9 files changed, 167 insertions(+), 173 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d47d308a/apps/bleprph/src/store.c
----------------------------------------------------------------------
diff --git a/apps/bleprph/src/store.c b/apps/bleprph/src/store.c
index d3d7262..5b3ae13 100644
--- a/apps/bleprph/src/store.c
+++ b/apps/bleprph/src/store.c
@@ -39,11 +39,11 @@
 #define STORE_MAX_MST_LTKS   4
 #define STORE_MAX_CCCDS      16
 
-static struct ble_store_value_sec store_slv_secs[STORE_MAX_SLV_LTKS];
-static int store_num_slv_secs;
+static struct ble_store_value_sec store_our_secs[STORE_MAX_SLV_LTKS];
+static int store_num_our_secs;
 
-static struct ble_store_value_sec store_mst_secs[STORE_MAX_MST_LTKS];
-static int store_num_mst_secs;
+static struct ble_store_value_sec store_peer_secs[STORE_MAX_MST_LTKS];
+static int store_num_peer_secs;
 
 static struct ble_store_value_cccd store_cccds[STORE_MAX_CCCDS];
 static int store_num_cccds;
@@ -136,84 +136,84 @@ store_find_sec(struct ble_store_key_sec *key_sec,
 }
 
 static int
-store_read_slv_sec(struct ble_store_key_sec *key_sec,
+store_read_our_sec(struct ble_store_key_sec *key_sec,
                    struct ble_store_value_sec *value_sec)
 {
     int idx;
 
-    idx = store_find_sec(key_sec, store_slv_secs, store_num_slv_secs);
+    idx = store_find_sec(key_sec, store_our_secs, store_num_our_secs);
     if (idx == -1) {
         return BLE_HS_ENOENT;
     }
 
-    *value_sec = store_slv_secs[idx];
+    *value_sec = store_our_secs[idx];
     return 0;
 }
 
 static int
-store_write_slv_sec(struct ble_store_value_sec *value_sec)
+store_write_our_sec(struct ble_store_value_sec *value_sec)
 {
     struct ble_store_key_sec key_sec;
     int idx;
 
-    BLEPRPH_LOG(INFO, "persisting slv sec; ");
+    BLEPRPH_LOG(INFO, "persisting our sec; ");
     store_print_value_sec(value_sec);
 
     ble_store_key_from_value_sec(&key_sec, value_sec);
-    idx = store_find_sec(&key_sec, store_slv_secs, store_num_slv_secs);
+    idx = store_find_sec(&key_sec, store_our_secs, store_num_our_secs);
     if (idx == -1) {
-        if (store_num_slv_secs >= STORE_MAX_SLV_LTKS) {
-            BLEPRPH_LOG(INFO, "error persisting slv sec; too many entries "
-                              "(%d)\n", store_num_slv_secs);
+        if (store_num_our_secs >= STORE_MAX_SLV_LTKS) {
+            BLEPRPH_LOG(INFO, "error persisting our sec; too many entries "
+                              "(%d)\n", store_num_our_secs);
             return BLE_HS_ENOMEM;
         }
 
-        idx = store_num_slv_secs;
-        store_num_slv_secs++;
+        idx = store_num_our_secs;
+        store_num_our_secs++;
     }
 
-    store_slv_secs[idx] = *value_sec;
+    store_our_secs[idx] = *value_sec;
     return 0;
 }
 
 static int
-store_read_mst_sec(struct ble_store_key_sec *key_sec,
+store_read_peer_sec(struct ble_store_key_sec *key_sec,
                    struct ble_store_value_sec *value_sec)
 {
     int idx;
 
-    idx = store_find_sec(key_sec, store_mst_secs, store_num_mst_secs);
+    idx = store_find_sec(key_sec, store_peer_secs, store_num_peer_secs);
     if (idx == -1) {
         return BLE_HS_ENOENT;
     }
 
-    *value_sec = store_mst_secs[idx];
+    *value_sec = store_peer_secs[idx];
     return 0;
 }
 
 static int
-store_write_mst_sec(struct ble_store_value_sec *value_sec)
+store_write_peer_sec(struct ble_store_value_sec *value_sec)
 {
     struct ble_store_key_sec key_sec;
     int idx;
 
-    BLEPRPH_LOG(INFO, "persisting mst sec; ");
+    BLEPRPH_LOG(INFO, "persisting peer sec; ");
     store_print_value_sec(value_sec);
 
     ble_store_key_from_value_sec(&key_sec, value_sec);
-    idx = store_find_sec(&key_sec, store_mst_secs, store_num_mst_secs);
+    idx = store_find_sec(&key_sec, store_peer_secs, store_num_peer_secs);
     if (idx == -1) {
-        if (store_num_mst_secs >= STORE_MAX_MST_LTKS) {
-            BLEPRPH_LOG(INFO, "error persisting mst sec; too many entries "
-                           "(%d)\n", store_num_mst_secs);
+        if (store_num_peer_secs >= STORE_MAX_MST_LTKS) {
+            BLEPRPH_LOG(INFO, "error persisting peer sec; too many entries "
+                           "(%d)\n", store_num_peer_secs);
             return BLE_HS_ENOMEM;
         }
 
-        idx = store_num_mst_secs;
-        store_num_mst_secs++;
+        idx = store_num_peer_secs;
+        store_num_peer_secs++;
     }
 
-    store_mst_secs[idx] = *value_sec;
+    store_peer_secs[idx] = *value_sec;
     return 0;
 }
 
@@ -313,7 +313,7 @@ store_read(int obj_type, union ble_store_key *key,
     int rc;
 
     switch (obj_type) {
-    case BLE_STORE_OBJ_TYPE_MST_SEC:
+    case BLE_STORE_OBJ_TYPE_PEER_SEC:
         /* An encryption procedure (bonding) is being attempted.  The nimble
          * stack is asking us to look in our key database for a long-term key
          * corresponding to the specified ediv and random number.
@@ -322,17 +322,17 @@ store_read(int obj_type, union ble_store_key *key,
          * result.  The nimble stack will use this key if this function returns
          * success.
          */
-        BLEPRPH_LOG(INFO, "looking up mst sec; ");
+        BLEPRPH_LOG(INFO, "looking up peer sec; ");
         store_print_key_sec(&key->sec);
         BLEPRPH_LOG(INFO, "\n");
-        rc = store_read_mst_sec(&key->sec, &value->sec);
+        rc = store_read_peer_sec(&key->sec, &value->sec);
         return rc;
 
-    case BLE_STORE_OBJ_TYPE_SLV_SEC:
-        BLEPRPH_LOG(INFO, "looking up slv sec; ");
+    case BLE_STORE_OBJ_TYPE_OUR_SEC:
+        BLEPRPH_LOG(INFO, "looking up our sec; ");
         store_print_key_sec(&key->sec);
         BLEPRPH_LOG(INFO, "\n");
-        rc = store_read_slv_sec(&key->sec, &value->sec);
+        rc = store_read_our_sec(&key->sec, &value->sec);
         return rc;
 
     case BLE_STORE_OBJ_TYPE_CCCD:
@@ -356,12 +356,12 @@ store_write(int obj_type, union ble_store_value *val)
     int rc;
 
     switch (obj_type) {
-    case BLE_STORE_OBJ_TYPE_MST_SEC:
-        rc = store_write_mst_sec(&val->sec);
+    case BLE_STORE_OBJ_TYPE_PEER_SEC:
+        rc = store_write_peer_sec(&val->sec);
         return rc;
 
-    case BLE_STORE_OBJ_TYPE_SLV_SEC:
-        rc = store_write_slv_sec(&val->sec);
+    case BLE_STORE_OBJ_TYPE_OUR_SEC:
+        rc = store_write_our_sec(&val->sec);
         return rc;
 
     case BLE_STORE_OBJ_TYPE_CCCD:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d47d308a/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 88de789..3598bb3 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -1756,8 +1756,8 @@ cmd_write(int argc, char **argv)
  *****************************************************************************/
 
 static struct kv_pair cmd_keystore_entry_type[] = {
-    { "msec",       BLE_STORE_OBJ_TYPE_MST_SEC },
-    { "ssec",       BLE_STORE_OBJ_TYPE_SLV_SEC },
+    { "msec",       BLE_STORE_OBJ_TYPE_PEER_SEC },
+    { "ssec",       BLE_STORE_OBJ_TYPE_OUR_SEC },
     { "cccd",       BLE_STORE_OBJ_TYPE_CCCD },
     { NULL }
 };
@@ -1778,8 +1778,8 @@ cmd_keystore_parse_keydata(int argc, char **argv, union ble_store_key *out,
     *obj_type = parse_arg_kv("type", cmd_keystore_entry_type);
 
     switch (*obj_type) {
-    case BLE_STORE_OBJ_TYPE_MST_SEC:
-    case BLE_STORE_OBJ_TYPE_SLV_SEC:
+    case BLE_STORE_OBJ_TYPE_PEER_SEC:
+    case BLE_STORE_OBJ_TYPE_OUR_SEC:
         rc = parse_arg_kv("addr_type", cmd_keystore_addr_type);
         if (rc < 0) {
             return EINVAL;
@@ -1817,8 +1817,8 @@ cmd_keystore_parse_valuedata(int argc, char **argv,
     memset(out, 0, sizeof(*out));
 
     switch (obj_type) {
-        case BLE_STORE_OBJ_TYPE_MST_SEC:
-        case BLE_STORE_OBJ_TYPE_SLV_SEC:
+        case BLE_STORE_OBJ_TYPE_PEER_SEC:
+        case BLE_STORE_OBJ_TYPE_OUR_SEC:
             rc = parse_arg_byte_stream_exact_length("ltk", out->sec.ltk, 16);
             if (rc == 0) {
                 out->sec.ltk_present = 1;
@@ -1877,11 +1877,11 @@ cmd_keystore_add(int argc, char **argv)
     }
 
     switch(obj_type) {
-        case BLE_STORE_OBJ_TYPE_MST_SEC:
-            rc = ble_store_write_mst_sec(&value.sec);
+        case BLE_STORE_OBJ_TYPE_PEER_SEC:
+            rc = ble_store_write_peer_sec(&value.sec);
             break;
-        case BLE_STORE_OBJ_TYPE_SLV_SEC:
-            rc = ble_store_write_slv_sec(&value.sec);
+        case BLE_STORE_OBJ_TYPE_OUR_SEC:
+            rc = ble_store_write_our_sec(&value.sec);
             break;
         case BLE_STORE_OBJ_TYPE_CCCD:
             rc = ble_store_write_cccd(&value.cccd);
@@ -1914,8 +1914,8 @@ cmd_keystore_iterator(int obj_type,
                       void *cookie) {
 
     switch (obj_type) {
-        case BLE_STORE_OBJ_TYPE_MST_SEC:
-        case BLE_STORE_OBJ_TYPE_SLV_SEC:
+        case BLE_STORE_OBJ_TYPE_PEER_SEC:
+        case BLE_STORE_OBJ_TYPE_OUR_SEC:
             console_printf("Key: ");
             if (val->sec.peer_addr_type == BLE_STORE_ADDR_TYPE_NONE) {
                 console_printf("ediv=%u ", val->sec.ediv);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d47d308a/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 6e09b88..c8a4840 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1396,9 +1396,9 @@ bletiny_sec_restart(uint16_t conn_handle,
             return rc;
         }
         if (conn_flags & BLE_HS_CONN_F_MASTER) {
-            rc = ble_store_read_mst_sec(&key_sec, &value_sec);
+            rc = ble_store_read_peer_sec(&key_sec, &value_sec);
         } else {
-            rc = ble_store_read_slv_sec(&key_sec, &value_sec);
+            rc = ble_store_read_our_sec(&key_sec, &value_sec);
         }
         if (rc != 0) {
             return rc;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d47d308a/apps/bletiny/src/store.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/store.c b/apps/bletiny/src/store.c
index c01ce06..2cf4682 100644
--- a/apps/bletiny/src/store.c
+++ b/apps/bletiny/src/store.c
@@ -40,11 +40,11 @@
 #define STORE_MAX_MST_LTKS   4
 #define STORE_MAX_CCCDS      16
 
-static struct ble_store_value_sec store_slv_secs[STORE_MAX_SLV_LTKS];
-static int store_num_slv_secs;
+static struct ble_store_value_sec store_our_secs[STORE_MAX_SLV_LTKS];
+static int store_num_our_secs;
 
-static struct ble_store_value_sec store_mst_secs[STORE_MAX_MST_LTKS];
-static int store_num_mst_secs;
+static struct ble_store_value_sec store_peer_secs[STORE_MAX_MST_LTKS];
+static int store_num_peer_secs;
 
 static struct ble_store_value_cccd store_cccds[STORE_MAX_CCCDS];
 static int store_num_cccds;
@@ -103,11 +103,11 @@ store_log_sec_lookup(int obj_type, struct ble_store_key_sec *key_sec)
     }
 
     switch (obj_type) {
-    case BLE_STORE_OBJ_TYPE_MST_SEC:
-        obj_name = "mst sec";
+    case BLE_STORE_OBJ_TYPE_PEER_SEC:
+        obj_name = "peer sec";
         break;
-    case BLE_STORE_OBJ_TYPE_SLV_SEC:
-        obj_name = "slv sec";
+    case BLE_STORE_OBJ_TYPE_OUR_SEC:
+        obj_name = "our sec";
         break;
     default:
         assert(0);
@@ -165,84 +165,84 @@ store_find_sec(struct ble_store_key_sec *key_sec,
 }
 
 static int
-store_read_slv_sec(struct ble_store_key_sec *key_sec,
+store_read_our_sec(struct ble_store_key_sec *key_sec,
                    struct ble_store_value_sec *value_sec)
 {
     int idx;
 
-    idx = store_find_sec(key_sec, store_slv_secs, store_num_slv_secs);
+    idx = store_find_sec(key_sec, store_our_secs, store_num_our_secs);
     if (idx == -1) {
         return BLE_HS_ENOENT;
     }
 
-    *value_sec = store_slv_secs[idx];
+    *value_sec = store_our_secs[idx];
     return 0;
 }
 
 static int
-store_write_slv_sec(struct ble_store_value_sec *value_sec)
+store_write_our_sec(struct ble_store_value_sec *value_sec)
 {
     struct ble_store_key_sec key_sec;
     int idx;
 
-    console_printf("persisting slv sec; ");
+    console_printf("persisting our sec; ");
     store_print_value_sec(value_sec);
 
     ble_store_key_from_value_sec(&key_sec, value_sec);
-    idx = store_find_sec(&key_sec, store_slv_secs, store_num_slv_secs);
+    idx = store_find_sec(&key_sec, store_our_secs, store_num_our_secs);
     if (idx == -1) {
-        if (store_num_slv_secs >= STORE_MAX_SLV_LTKS) {
-            console_printf("error persisting slv sec; too many entries (%d)\n",
-                           store_num_slv_secs);
+        if (store_num_our_secs >= STORE_MAX_SLV_LTKS) {
+            console_printf("error persisting our sec; too many entries (%d)\n",
+                           store_num_our_secs);
             return BLE_HS_ENOMEM;
         }
 
-        idx = store_num_slv_secs;
-        store_num_slv_secs++;
+        idx = store_num_our_secs;
+        store_num_our_secs++;
     }
 
-    store_slv_secs[idx] = *value_sec;
+    store_our_secs[idx] = *value_sec;
     return 0;
 }
 
 static int
-store_read_mst_sec(struct ble_store_key_sec *key_sec,
+store_read_peer_sec(struct ble_store_key_sec *key_sec,
                    struct ble_store_value_sec *value_sec)
 {
     int idx;
 
-    idx = store_find_sec(key_sec, store_mst_secs, store_num_mst_secs);
+    idx = store_find_sec(key_sec, store_peer_secs, store_num_peer_secs);
     if (idx == -1) {
         return BLE_HS_ENOENT;
     }
 
-    *value_sec = store_mst_secs[idx];
+    *value_sec = store_peer_secs[idx];
     return 0;
 }
 
 static int
-store_write_mst_sec(struct ble_store_value_sec *value_sec)
+store_write_peer_sec(struct ble_store_value_sec *value_sec)
 {
     struct ble_store_key_sec key_sec;
     int idx;
 
-    console_printf("persisting mst sec; ");
+    console_printf("persisting peer sec; ");
     store_print_value_sec(value_sec);
 
     ble_store_key_from_value_sec(&key_sec, value_sec);
-    idx = store_find_sec(&key_sec, store_mst_secs, store_num_mst_secs);
+    idx = store_find_sec(&key_sec, store_peer_secs, store_num_peer_secs);
     if (idx == -1) {
-        if (store_num_mst_secs >= STORE_MAX_MST_LTKS) {
-            console_printf("error persisting mst sec; too many entries "
-                           "(%d)\n", store_num_mst_secs);
+        if (store_num_peer_secs >= STORE_MAX_MST_LTKS) {
+            console_printf("error persisting peer sec; too many entries "
+                           "(%d)\n", store_num_peer_secs);
             return BLE_HS_ENOMEM;
         }
 
-        idx = store_num_mst_secs;
-        store_num_mst_secs++;
+        idx = store_num_peer_secs;
+        store_num_peer_secs++;
     }
 
-    store_mst_secs[idx] = *value_sec;
+    store_peer_secs[idx] = *value_sec;
     return 0;
 }
 
@@ -342,7 +342,7 @@ store_read(int obj_type, union ble_store_key *key,
     int rc;
 
     switch (obj_type) {
-    case BLE_STORE_OBJ_TYPE_MST_SEC:
+    case BLE_STORE_OBJ_TYPE_PEER_SEC:
         /* An encryption procedure (bonding) is being attempted.  The nimble
          * stack is asking us to look in our key database for a long-term key
          * corresponding to the specified ediv and random number.
@@ -351,13 +351,13 @@ store_read(int obj_type, union ble_store_key *key,
          * result.  The nimble stack will use this key if this function returns
          * success.
          */
-        store_log_sec_lookup(BLE_STORE_OBJ_TYPE_MST_SEC, &key->sec);
-        rc = store_read_mst_sec(&key->sec, &value->sec);
+        store_log_sec_lookup(BLE_STORE_OBJ_TYPE_PEER_SEC, &key->sec);
+        rc = store_read_peer_sec(&key->sec, &value->sec);
         return rc;
 
-    case BLE_STORE_OBJ_TYPE_SLV_SEC:
-        store_log_sec_lookup(BLE_STORE_OBJ_TYPE_SLV_SEC, &key->sec);
-        rc = store_read_slv_sec(&key->sec, &value->sec);
+    case BLE_STORE_OBJ_TYPE_OUR_SEC:
+        store_log_sec_lookup(BLE_STORE_OBJ_TYPE_OUR_SEC, &key->sec);
+        rc = store_read_our_sec(&key->sec, &value->sec);
         return rc;
 
     case BLE_STORE_OBJ_TYPE_CCCD:
@@ -381,12 +381,12 @@ store_write(int obj_type, union ble_store_value *val)
     int rc;
 
     switch (obj_type) {
-    case BLE_STORE_OBJ_TYPE_MST_SEC:
-        rc = store_write_mst_sec(&val->sec);
+    case BLE_STORE_OBJ_TYPE_PEER_SEC:
+        rc = store_write_peer_sec(&val->sec);
         return rc;
 
-    case BLE_STORE_OBJ_TYPE_SLV_SEC:
-        rc = store_write_slv_sec(&val->sec);
+    case BLE_STORE_OBJ_TYPE_OUR_SEC:
+        rc = store_write_our_sec(&val->sec);
         return rc;
 
     case BLE_STORE_OBJ_TYPE_CCCD:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d47d308a/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 e5b51aa..9a7efab 100644
--- a/net/nimble/host/include/host/ble_store.h
+++ b/net/nimble/host/include/host/ble_store.h
@@ -22,14 +22,8 @@
 
 #include <inttypes.h>
 
-/* XXX: It probably doesn't make sense to persist all security material as a
- * single record.  We may need to separate IRK from LTK and CSRK.
- *
- * Also, the master / slave distinction is not right.  It makes sense for the
- * LTK in legacy pairing, but not for other security operations.
- */
-#define BLE_STORE_OBJ_TYPE_MST_SEC      1
-#define BLE_STORE_OBJ_TYPE_SLV_SEC      2
+#define BLE_STORE_OBJ_TYPE_OUR_SEC      1
+#define BLE_STORE_OBJ_TYPE_PEER_SEC     2
 #define BLE_STORE_OBJ_TYPE_CCCD         3
 
 #define BLE_STORE_ADDR_TYPE_NONE        0xff
@@ -125,12 +119,12 @@ int ble_store_read(int obj_type, union ble_store_key *key,
 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_read_slv_sec(struct ble_store_key_sec *key_sec,
-                           struct ble_store_value_sec *value_sec);
-int ble_store_write_slv_sec(struct ble_store_value_sec *value_sec);
-int ble_store_read_mst_sec(struct ble_store_key_sec *key_sec,
+int ble_store_read_our_sec(struct ble_store_key_sec *key_sec,
                            struct ble_store_value_sec *value_sec);
-int ble_store_write_mst_sec(struct ble_store_value_sec *value_sec);
+int ble_store_write_our_sec(struct ble_store_value_sec *value_sec);
+int ble_store_read_peer_sec(struct ble_store_key_sec *key_sec,
+                            struct ble_store_value_sec *value_sec);
+int ble_store_write_peer_sec(struct ble_store_value_sec *value_sec);
 
 int ble_store_read_cccd(struct ble_store_key_cccd *key,
                         struct ble_store_value_cccd *out_value);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d47d308a/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 0ffa066..ceed1cd 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -572,11 +572,11 @@ ble_sm_persist_keys(struct ble_sm_proc *proc)
 
     ble_sm_fill_store_value(peer_addr_type, peer_addr, authenticated,
                             &proc->our_keys, &value_sec);
-    ble_store_write_slv_sec(&value_sec);
+    ble_store_write_our_sec(&value_sec);
 
     ble_sm_fill_store_value(peer_addr_type, peer_addr, authenticated,
                             &proc->peer_keys, &value_sec);
-    ble_store_write_mst_sec(&value_sec);
+    ble_store_write_peer_sec(&value_sec);
 }
 
 static int
@@ -1043,7 +1043,7 @@ ble_sm_retrieve_ltk(struct hci_le_lt_key_req *evt, uint8_t peer_addr_type,
     key_sec.rand_num = evt->random_number;
     key_sec.ediv_rand_present = 1;
 
-    rc = ble_store_read_slv_sec(&key_sec, value_sec);
+    rc = ble_store_read_our_sec(&key_sec, value_sec);
     return rc;
 }
 
@@ -1653,7 +1653,7 @@ ble_sm_sec_req_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
         /* Query database for an LTK corresponding to the sender.  We are the
          * master, so retrieve a master key.
          */
-        res->app_status = ble_store_read_mst_sec(&key_sec, &value_sec);
+        res->app_status = ble_store_read_peer_sec(&key_sec, &value_sec);
         if (res->app_status == 0) {
             /* Found a key corresponding to this peer.  Make sure it meets the
              * requested minimum authreq.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d47d308a/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 a2de0ea..fbc8c1e 100644
--- a/net/nimble/host/src/ble_store.c
+++ b/net/nimble/host/src/ble_store.c
@@ -66,7 +66,7 @@ ble_store_delete(int obj_type, union ble_store_key *key)
 }
 
 int
-ble_store_read_slv_sec(struct ble_store_key_sec *key_sec,
+ble_store_read_our_sec(struct ble_store_key_sec *key_sec,
                        struct ble_store_value_sec *value_sec)
 {
     union ble_store_value *store_value;
@@ -79,7 +79,7 @@ ble_store_read_slv_sec(struct ble_store_key_sec *key_sec,
 
     store_key = (void *)key_sec;
     store_value = (void *)value_sec;
-    rc = ble_store_read(BLE_STORE_OBJ_TYPE_SLV_SEC, store_key, store_value);
+    rc = ble_store_read(BLE_STORE_OBJ_TYPE_OUR_SEC, store_key, store_value);
     return rc;
 }
 
@@ -113,17 +113,17 @@ ble_store_persist_sec(int obj_type, struct ble_store_value_sec *value_sec)
 }
 
 int
-ble_store_write_slv_sec(struct ble_store_value_sec *value_sec)
+ble_store_write_our_sec(struct ble_store_value_sec *value_sec)
 {
     int rc;
 
-    rc = ble_store_persist_sec(BLE_STORE_OBJ_TYPE_SLV_SEC, value_sec);
+    rc = ble_store_persist_sec(BLE_STORE_OBJ_TYPE_OUR_SEC, value_sec);
     return rc;
 }
 
 int
-ble_store_read_mst_sec(struct ble_store_key_sec *key_sec,
-                       struct ble_store_value_sec *value_sec)
+ble_store_read_peer_sec(struct ble_store_key_sec *key_sec,
+                        struct ble_store_value_sec *value_sec)
 {
     union ble_store_value *store_value;
     union ble_store_key *store_key;
@@ -135,7 +135,7 @@ ble_store_read_mst_sec(struct ble_store_key_sec *key_sec,
 
     store_key = (void *)key_sec;
     store_value = (void *)value_sec;
-    rc = ble_store_read(BLE_STORE_OBJ_TYPE_MST_SEC, store_key, store_value);
+    rc = ble_store_read(BLE_STORE_OBJ_TYPE_PEER_SEC, store_key, store_value);
 
     if (rc != 0) {
         return rc;
@@ -145,11 +145,11 @@ ble_store_read_mst_sec(struct ble_store_key_sec *key_sec,
 }
 
 int
-ble_store_write_mst_sec(struct ble_store_value_sec *value_sec)
+ble_store_write_peer_sec(struct ble_store_value_sec *value_sec)
 {
     int rc;
 
-    rc = ble_store_persist_sec(BLE_STORE_OBJ_TYPE_MST_SEC, value_sec);
+    rc = ble_store_persist_sec(BLE_STORE_OBJ_TYPE_PEER_SEC, value_sec);
     if (rc != 0) {
         return rc;
     }
@@ -171,13 +171,13 @@ ble_store_write_mst_sec(struct ble_store_value_sec *value_sec)
 }
 
 int
-ble_store_delete_mst_sec(struct ble_store_key_sec *key_sec)
+ble_store_delete_peer_sec(struct ble_store_key_sec *key_sec)
 {
     union ble_store_key *store_key;
     int rc;
 
     store_key = (void *)key_sec;
-    rc = ble_store_delete(BLE_STORE_OBJ_TYPE_MST_SEC, store_key);
+    rc = ble_store_delete(BLE_STORE_OBJ_TYPE_PEER_SEC, store_key);
 
     if(key_sec->peer_addr_type == BLE_STORE_ADDR_TYPE_NONE) {
         /* don't error check this since we don't know without looking up
@@ -260,8 +260,8 @@ void ble_store_iterate(int obj_type,
     /* a magic value to retrieve anything */
     memset(&key, 0, sizeof(key));
     switch(obj_type) {
-        case BLE_STORE_OBJ_TYPE_MST_SEC:
-        case BLE_STORE_OBJ_TYPE_SLV_SEC:
+        case BLE_STORE_OBJ_TYPE_PEER_SEC:
+        case BLE_STORE_OBJ_TYPE_OUR_SEC:
             key.sec.peer_addr_type = BLE_STORE_ADDR_TYPE_NONE;
             pidx = &key.sec.idx;
             break;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d47d308a/net/nimble/host/src/test/ble_hs_test_util_store.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util_store.c b/net/nimble/host/src/test/ble_hs_test_util_store.c
index fe3138c..f888753 100644
--- a/net/nimble/host/src/test/ble_hs_test_util_store.c
+++ b/net/nimble/host/src/test/ble_hs_test_util_store.c
@@ -23,15 +23,15 @@
 #include "ble_hs_test_util.h"
 #include "ble_hs_test_util_store.h"
 
-static int ble_hs_test_util_store_max_slv_secs;
-static int ble_hs_test_util_store_max_mst_secs;
+static int ble_hs_test_util_store_max_our_secs;
+static int ble_hs_test_util_store_max_peer_secs;
 static int ble_hs_test_util_store_max_cccds;
 
-static struct ble_store_value_sec *ble_hs_test_util_store_slv_secs;
-static struct ble_store_value_sec *ble_hs_test_util_store_mst_secs;
+static struct ble_store_value_sec *ble_hs_test_util_store_our_secs;
+static struct ble_store_value_sec *ble_hs_test_util_store_peer_secs;
 static struct ble_store_value_cccd *ble_hs_test_util_store_cccds;
-int ble_hs_test_util_store_num_slv_secs;
-int ble_hs_test_util_store_num_mst_secs;
+int ble_hs_test_util_store_num_our_secs;
+int ble_hs_test_util_store_num_peer_secs;
 int ble_hs_test_util_store_num_cccds;
 
 
@@ -51,32 +51,32 @@ int ble_hs_test_util_store_num_cccds;
 } while (0) 
 
 void
-ble_hs_test_util_store_init(int max_slv_secs, int max_mst_secs, int max_cccds)
+ble_hs_test_util_store_init(int max_our_secs, int max_peer_secs, int max_cccds)
 {
-    free(ble_hs_test_util_store_slv_secs);
-    free(ble_hs_test_util_store_mst_secs);
+    free(ble_hs_test_util_store_our_secs);
+    free(ble_hs_test_util_store_peer_secs);
     free(ble_hs_test_util_store_cccds);
 
-    ble_hs_test_util_store_slv_secs = malloc(
-        ble_hs_test_util_store_max_slv_secs *
-        sizeof *ble_hs_test_util_store_slv_secs);
-    TEST_ASSERT_FATAL(ble_hs_test_util_store_slv_secs != NULL);
+    ble_hs_test_util_store_our_secs = malloc(
+        ble_hs_test_util_store_max_our_secs *
+        sizeof *ble_hs_test_util_store_our_secs);
+    TEST_ASSERT_FATAL(ble_hs_test_util_store_our_secs != NULL);
 
-    ble_hs_test_util_store_mst_secs = malloc(
-        ble_hs_test_util_store_max_mst_secs *
-        sizeof *ble_hs_test_util_store_mst_secs);
-    TEST_ASSERT_FATAL(ble_hs_test_util_store_mst_secs != NULL);
+    ble_hs_test_util_store_peer_secs = malloc(
+        ble_hs_test_util_store_max_peer_secs *
+        sizeof *ble_hs_test_util_store_peer_secs);
+    TEST_ASSERT_FATAL(ble_hs_test_util_store_peer_secs != NULL);
 
     ble_hs_test_util_store_cccds = malloc(
         ble_hs_test_util_store_max_cccds *
         sizeof *ble_hs_test_util_store_cccds);
     TEST_ASSERT_FATAL(ble_hs_test_util_store_cccds != NULL);
 
-    ble_hs_test_util_store_max_slv_secs = max_slv_secs;
-    ble_hs_test_util_store_max_mst_secs = max_mst_secs;
+    ble_hs_test_util_store_max_our_secs = max_our_secs;
+    ble_hs_test_util_store_max_peer_secs = max_peer_secs;
     ble_hs_test_util_store_max_cccds = max_cccds;
-    ble_hs_test_util_store_num_slv_secs = 0;
-    ble_hs_test_util_store_num_mst_secs = 0;
+    ble_hs_test_util_store_num_our_secs = 0;
+    ble_hs_test_util_store_num_peer_secs = 0;
     ble_hs_test_util_store_num_cccds = 0;
 }
 
@@ -186,17 +186,17 @@ ble_hs_test_util_store_read(int obj_type, union ble_store_key *key,
                             union ble_store_value *dst)
 {
     switch (obj_type) {
-    case BLE_STORE_OBJ_TYPE_MST_SEC:
+    case BLE_STORE_OBJ_TYPE_PEER_SEC:
         return ble_hs_test_util_store_read_sec(
-            ble_hs_test_util_store_mst_secs,
-            ble_hs_test_util_store_num_mst_secs,
+            ble_hs_test_util_store_peer_secs,
+            ble_hs_test_util_store_num_peer_secs,
             &key->sec,
             &dst->sec);
 
-    case BLE_STORE_OBJ_TYPE_SLV_SEC:
+    case BLE_STORE_OBJ_TYPE_OUR_SEC:
         return ble_hs_test_util_store_read_sec(
-            ble_hs_test_util_store_slv_secs,
-            ble_hs_test_util_store_num_slv_secs,
+            ble_hs_test_util_store_our_secs,
+            ble_hs_test_util_store_num_our_secs,
             &key->sec,
             &dst->sec);
 
@@ -216,18 +216,18 @@ ble_hs_test_util_store_write(int obj_type, union ble_store_value *value)
     int idx;
 
     switch (obj_type) {
-    case BLE_STORE_OBJ_TYPE_MST_SEC:
+    case BLE_STORE_OBJ_TYPE_PEER_SEC:
         BLE_HS_TEST_UTIL_STORE_WRITE_GEN(
-            ble_hs_test_util_store_mst_secs,
-            ble_hs_test_util_store_num_mst_secs,
-            ble_hs_test_util_store_max_mst_secs,
+            ble_hs_test_util_store_peer_secs,
+            ble_hs_test_util_store_num_peer_secs,
+            ble_hs_test_util_store_max_peer_secs,
             value->sec, -1);
 
-    case BLE_STORE_OBJ_TYPE_SLV_SEC:
+    case BLE_STORE_OBJ_TYPE_OUR_SEC:
         BLE_HS_TEST_UTIL_STORE_WRITE_GEN(
-            ble_hs_test_util_store_slv_secs,
-            ble_hs_test_util_store_num_slv_secs,
-            ble_hs_test_util_store_max_slv_secs,
+            ble_hs_test_util_store_our_secs,
+            ble_hs_test_util_store_num_our_secs,
+            ble_hs_test_util_store_max_our_secs,
             value->sec, -1);
 
     case BLE_STORE_OBJ_TYPE_CCCD:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d47d308a/net/nimble/host/src/test/ble_sm_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test_util.c b/net/nimble/host/src/test/ble_sm_test_util.c
index ad21a06..45fd5a0 100644
--- a/net/nimble/host/src/test/ble_sm_test_util.c
+++ b/net/nimble/host/src/test/ble_sm_test_util.c
@@ -812,10 +812,10 @@ ble_sm_test_util_verify_lgcy_persist(struct ble_sm_test_lgcy_params *params)
     key_sec.peer_addr_type = BLE_STORE_ADDR_TYPE_NONE;
 
     if (params->pair_rsp.init_key_dist == 0) {
-        rc = ble_store_read_slv_sec(&key_sec, &value_sec);
+        rc = ble_store_read_our_sec(&key_sec, &value_sec);
         TEST_ASSERT(rc == BLE_HS_ENOENT);
     } else {
-        rc = ble_store_read_mst_sec(&key_sec, &value_sec);
+        rc = ble_store_read_peer_sec(&key_sec, &value_sec);
         TEST_ASSERT_FATAL(rc == 0);
         TEST_ASSERT(value_sec.peer_addr_type == 0);
         TEST_ASSERT(memcmp(value_sec.peer_addr, params->init_addr, 6) == 0);
@@ -829,7 +829,7 @@ ble_sm_test_util_verify_lgcy_persist(struct ble_sm_test_lgcy_params *params)
 
         /* Verify no other keys were persisted. */
         key_sec.idx++;
-        rc = ble_store_read_mst_sec(&key_sec, &value_sec);
+        rc = ble_store_read_peer_sec(&key_sec, &value_sec);
         TEST_ASSERT_FATAL(rc == BLE_HS_ENOENT);
     }
 
@@ -837,10 +837,10 @@ ble_sm_test_util_verify_lgcy_persist(struct ble_sm_test_lgcy_params *params)
     key_sec.peer_addr_type = BLE_STORE_ADDR_TYPE_NONE;
 
     if (params->pair_rsp.resp_key_dist == 0) {
-        rc = ble_store_read_slv_sec(&key_sec, &value_sec);
+        rc = ble_store_read_our_sec(&key_sec, &value_sec);
         TEST_ASSERT(rc == BLE_HS_ENOENT);
     } else {
-        rc = ble_store_read_slv_sec(&key_sec, &value_sec);
+        rc = ble_store_read_our_sec(&key_sec, &value_sec);
         TEST_ASSERT_FATAL(rc == 0);
         TEST_ASSERT(value_sec.peer_addr_type == 0);
         TEST_ASSERT(memcmp(value_sec.peer_addr, params->init_addr, 6) == 0);
@@ -854,7 +854,7 @@ ble_sm_test_util_verify_lgcy_persist(struct ble_sm_test_lgcy_params *params)
 
         /* Verify no other keys were persisted. */
         key_sec.idx++;
-        rc = ble_store_read_slv_sec(&key_sec, &value_sec);
+        rc = ble_store_read_our_sec(&key_sec, &value_sec);
         TEST_ASSERT_FATAL(rc == BLE_HS_ENOENT);
     }
 }
@@ -908,7 +908,7 @@ ble_sm_test_util_verify_sc_persist(struct ble_sm_test_sc_params *params,
     bonding = params->pair_req.authreq & BLE_SM_PAIR_AUTHREQ_BOND &&
               params->pair_rsp.authreq & BLE_SM_PAIR_AUTHREQ_BOND;
 
-    rc = ble_store_read_mst_sec(&key_sec, &value_sec);
+    rc = ble_store_read_peer_sec(&key_sec, &value_sec);
     if (!bonding) {
         TEST_ASSERT(rc == BLE_HS_ENOENT);
     } else {
@@ -939,7 +939,7 @@ ble_sm_test_util_verify_sc_persist(struct ble_sm_test_sc_params *params,
         }
     }
 
-    rc = ble_store_read_slv_sec(&key_sec, &value_sec);
+    rc = ble_store_read_our_sec(&key_sec, &value_sec);
     if (!bonding) {
         TEST_ASSERT(rc == BLE_HS_ENOENT);
     } else {
@@ -970,9 +970,9 @@ ble_sm_test_util_verify_sc_persist(struct ble_sm_test_sc_params *params,
 
     /* Verify no other keys were persisted. */
     key_sec.idx++;
-    rc = ble_store_read_slv_sec(&key_sec, &value_sec);
+    rc = ble_store_read_our_sec(&key_sec, &value_sec);
     TEST_ASSERT_FATAL(rc == BLE_HS_ENOENT);
-    rc = ble_store_read_mst_sec(&key_sec, &value_sec);
+    rc = ble_store_read_peer_sec(&key_sec, &value_sec);
     TEST_ASSERT_FATAL(rc == BLE_HS_ENOENT);
 }
 
@@ -1423,7 +1423,7 @@ ble_sm_test_util_peer_bonding_good(int send_enc_req, uint8_t *ltk,
     value_sec.authenticated = authenticated;
     value_sec.sc = 0;
 
-    rc = ble_store_write_slv_sec(&value_sec);
+    rc = ble_store_write_our_sec(&value_sec);
     TEST_ASSERT_FATAL(rc == 0);
 
     if (send_enc_req) {
@@ -1438,7 +1438,7 @@ ble_sm_test_util_peer_bonding_good(int send_enc_req, uint8_t *ltk,
 
     /* Ensure the LTK request event got sent to the application. */
     TEST_ASSERT(ble_sm_test_store_obj_type ==
-                BLE_STORE_OBJ_TYPE_SLV_SEC);
+                BLE_STORE_OBJ_TYPE_OUR_SEC);
     TEST_ASSERT(ble_sm_test_store_key.sec.peer_addr_type ==
                 BLE_ADDR_TYPE_PUBLIC);
     TEST_ASSERT(ble_sm_test_store_key.sec.ediv_rand_present);
@@ -1505,7 +1505,7 @@ ble_sm_test_util_peer_bonding_bad(uint16_t ediv, uint64_t rand_num)
 
     /* Ensure the LTK request event got sent to the application. */
     TEST_ASSERT(ble_sm_test_store_obj_type ==
-                BLE_STORE_OBJ_TYPE_SLV_SEC);
+                BLE_STORE_OBJ_TYPE_OUR_SEC);
     TEST_ASSERT(ble_sm_test_store_key.sec.ediv_rand_present);
     TEST_ASSERT(ble_sm_test_store_key.sec.ediv == ediv);
     TEST_ASSERT(ble_sm_test_store_key.sec.rand_num == rand_num);
@@ -2050,7 +2050,7 @@ ble_sm_test_util_us_bonding_good(int send_enc_req, uint8_t *ltk,
     value_sec.authenticated = authenticated;
     value_sec.sc = 0;
 
-    rc = ble_store_write_mst_sec(&value_sec);
+    rc = ble_store_write_peer_sec(&value_sec);
     TEST_ASSERT_FATAL(rc == 0);
 
     if (send_enc_req) {


[14/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Do key exchange if only one side txes.

Posted by cc...@apache.org.
BLE Host - Do key exchange if only one side txes.


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

Branch: refs/heads/develop
Commit: ef291718a9c1ac4beabc286c15b8864836d85728
Parents: 0fea978
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 8 15:05:28 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:35 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ef291718/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 27863a1..97ff226 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -1428,7 +1428,7 @@ ble_sm_pair_cfg(struct ble_sm_proc *proc)
     ble_sm_key_dist(proc, &init_key_dist, &resp_key_dist);
     if (proc->pair_req.authreq & BLE_SM_PAIR_AUTHREQ_BOND &&
         proc->pair_rsp.authreq & BLE_SM_PAIR_AUTHREQ_BOND &&
-        init_key_dist != 0 && resp_key_dist != 0) {
+        (init_key_dist != 0 || resp_key_dist != 0)) {
 
         proc->flags |= BLE_SM_PROC_F_KEY_EXCHANGE;
     }
@@ -2201,7 +2201,7 @@ ble_sm_enc_initiate(uint16_t conn_handle, uint8_t *ltk, uint16_t ediv,
             res.state_arg = &cmd;
         }
     }
-    
+
     ble_hs_unlock();
 
     ble_sm_process_result(conn_handle, &res);


[31/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Send correct SM err on confirm mismatch.

Posted by cc...@apache.org.
BLE Host - Send correct SM err on confirm mismatch.


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

Branch: refs/heads/develop
Commit: c72b6b4c04aa9437230e825df30622e8814d2236
Parents: 8451946
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jun 10 10:09:15 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:39 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm_sc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c72b6b4c/net/nimble/host/src/ble_sm_sc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_sc.c b/net/nimble/host/src/ble_sm_sc.c
index c16d20d..c3a2666 100644
--- a/net/nimble/host/src/ble_sm_sc.c
+++ b/net/nimble/host/src/ble_sm_sc.c
@@ -372,7 +372,7 @@ ble_sm_sc_random_rx(struct ble_sm_proc *proc, struct ble_sm_result *res)
         if (memcmp(proc->confirm_peer, confirm_val, 16) != 0) {
             /* Random number mismatch. */
             res->app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_CONFIRM_MISMATCH);
-            res->sm_err = BLE_SM_ERR_UNSPECIFIED;
+            res->sm_err = BLE_SM_ERR_CONFIRM_MISMATCH;
             res->enc_cb = 1;
             return;
         }


[39/50] [abbrv] incubator-mynewt-core git commit: BLE Host - SM SC unit tests.

Posted by cc...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4f9739f7/net/nimble/host/src/test/ble_sm_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test.c b/net/nimble/host/src/test/ble_sm_test.c
index e7496d2..1252990 100644
--- a/net/nimble/host/src/test/ble_sm_test.c
+++ b/net/nimble/host/src/test/ble_sm_test.c
@@ -27,1888 +27,10 @@
 #include "host/ble_sm.h"
 #include "host/ble_hs_test.h"
 #include "ble_hs_test_util.h"
+#include "ble_sm_test_util.h"
 
 #if NIMBLE_OPT(SM)
 
-int ble_sm_test_gap_event;
-int ble_sm_test_gap_status;
-struct ble_gap_sec_state ble_sm_test_sec_state;
-
-int ble_sm_test_store_obj_type;
-union ble_store_key ble_sm_test_store_key;
-union ble_store_value ble_sm_test_store_value;
-
-static ble_store_read_fn ble_sm_test_util_store_read;
-static ble_store_write_fn ble_sm_test_util_store_write;
-
-/*****************************************************************************
- * $util                                                                     *
- *****************************************************************************/
-
-struct ble_sm_test_passkey_info {
-    struct ble_sm_io passkey;
-    uint32_t exp_numcmp;
-    unsigned io_before_rx:1;
-};
-
-struct ble_sm_test_lgcy_params {
-    uint8_t init_addr[6];
-    uint8_t resp_addr[6];
-    struct ble_sm_sec_req sec_req;
-    struct ble_sm_pair_cmd pair_req;
-    struct ble_sm_pair_cmd pair_rsp;
-    struct ble_sm_pair_confirm confirm_req;
-    struct ble_sm_pair_confirm confirm_rsp;
-    struct ble_sm_pair_random random_req;
-    struct ble_sm_pair_random random_rsp;
-    struct ble_sm_enc_info enc_info_req;
-    struct ble_sm_master_id master_id_req;
-    struct ble_sm_enc_info enc_info_rsp;
-    struct ble_sm_master_id master_id_rsp;
-    int pair_alg;
-    unsigned authenticated:1;
-    uint8_t tk[16];
-    uint8_t stk[16];
-    uint64_t r;
-    uint16_t ediv;
-
-    struct ble_sm_test_passkey_info passkey_info;
-    struct ble_sm_pair_fail pair_fail;
-
-    unsigned has_sec_req:1;
-    unsigned has_enc_info_req:1;
-    unsigned has_enc_info_rsp:1;
-    unsigned has_master_id_req:1;
-    unsigned has_master_id_rsp:1;
-};
-
-struct ble_sm_test_sc_params {
-    uint8_t init_addr[6];
-    uint8_t resp_addr[6];
-    struct ble_sm_sec_req sec_req;
-    struct ble_sm_pair_cmd pair_req;
-    struct ble_sm_pair_cmd pair_rsp;
-    struct ble_sm_pair_confirm confirm_req[20];
-    struct ble_sm_pair_confirm confirm_rsp[20];
-    struct ble_sm_pair_random random_req[20];
-    struct ble_sm_pair_random random_rsp[20];
-    struct ble_sm_public_key public_key_req;
-    struct ble_sm_public_key public_key_rsp;
-    struct ble_sm_dhkey_check dhkey_check_req;
-    struct ble_sm_dhkey_check dhkey_check_rsp;
-    int pair_alg;
-    unsigned authenticated:1;
-    uint8_t ltk[16];
-    uint8_t our_priv_key[32];
-
-    struct ble_sm_test_passkey_info passkey_info;
-    struct ble_sm_pair_fail pair_fail;
-
-    unsigned has_sec_req:1;
-    unsigned has_enc_info_req:1;
-    unsigned has_enc_info_rsp:1;
-    unsigned has_master_id_req:1;
-    unsigned has_master_id_rsp:1;
-};
-
-#define BLE_SM_TEST_UTIL_HCI_HDR(handle, pb, len) \
-    ((struct hci_data_hdr) {                            \
-        .hdh_handle_pb_bc = ((handle)  << 0) |          \
-                            ((pb)      << 12),          \
-        .hdh_len = (len)                                \
-    })
-
-static int
-ble_sm_test_util_store_read(int obj_type, union ble_store_key *key,
-                                  union ble_store_value *val)
-{
-    ble_sm_test_store_obj_type = obj_type;
-    ble_sm_test_store_key = *key;
-
-    return ble_hs_test_util_store_read(obj_type, key, val);
-}
-
-static int
-ble_sm_test_util_store_write(int obj_type, union ble_store_value *val)
-{
-    ble_sm_test_store_obj_type = obj_type;
-    ble_sm_test_store_value = *val;
-
-    return ble_hs_test_util_store_write(obj_type, val);
-}
-
-static void
-ble_sm_test_util_init(void)
-{
-    ble_hs_test_util_init();
-    ble_hs_test_util_store_init(10, 10, 10);
-    ble_hs_cfg.store_read_cb = ble_sm_test_util_store_read;
-    ble_hs_cfg.store_write_cb = ble_sm_test_util_store_write;
-
-    ble_sm_test_store_obj_type = -1;
-    ble_sm_test_gap_event = -1;
-    ble_sm_test_gap_status = -1;
-
-    memset(&ble_sm_test_sec_state, 0xff, sizeof ble_sm_test_sec_state);
-}
-
-struct ble_sm_test_ltk_info {
-    uint8_t ltk[16];
-    unsigned authenticated:1;
-};
-
-struct ble_gap_passkey_action ble_sm_test_ioact;
-
-static int
-ble_sm_test_util_conn_cb(int event, struct ble_gap_conn_ctxt *ctxt, void *arg)
-{
-    int rc;
-
-    switch (event) {
-    case BLE_GAP_EVENT_ENC_CHANGE:
-        ble_sm_test_gap_status = ctxt->enc_change.status;
-        ble_sm_test_sec_state = ctxt->desc->sec_state;
-        rc = 0;
-        break;
-
-    case BLE_GAP_EVENT_PASSKEY_ACTION:
-        ble_sm_test_ioact = ctxt->passkey_action;
-        break;
-
-    default:
-        return 0;
-    }
-
-    ble_sm_test_gap_event = event;
-
-    return rc;
-}
-
-static void
-ble_sm_test_util_rx_pair_cmd(uint16_t conn_handle, uint8_t op,
-                                   struct ble_sm_pair_cmd *cmd,
-                                   int rx_status)
-{
-    struct hci_data_hdr hci_hdr;
-    struct os_mbuf *om;
-    void *v;
-    int payload_len;
-    int rc;
-
-    hci_hdr = BLE_SM_TEST_UTIL_HCI_HDR(
-        2, BLE_HCI_PB_FIRST_FLUSH,
-        BLE_L2CAP_HDR_SZ + BLE_SM_HDR_SZ + BLE_SM_PAIR_CMD_SZ);
-
-    om = ble_hs_misc_pkthdr();
-    TEST_ASSERT_FATAL(om != NULL);
-
-    payload_len = BLE_SM_HDR_SZ + BLE_SM_PAIR_CMD_SZ;
-
-    v = os_mbuf_extend(om, payload_len);
-    TEST_ASSERT_FATAL(v != NULL);
-
-    ble_sm_pair_cmd_write(v, payload_len, op == BLE_SM_OP_PAIR_REQ,
-                                cmd);
-
-    rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SM,
-                                              &hci_hdr, om);
-    TEST_ASSERT(rc == rx_status);
-}
-
-static void
-ble_sm_test_util_rx_pair_req(uint16_t conn_handle,
-                                   struct ble_sm_pair_cmd *req,
-                                   int rx_status)
-{
-    ble_sm_test_util_rx_pair_cmd(conn_handle, BLE_SM_OP_PAIR_REQ,
-                                       req, rx_status);
-}
-
-static void
-ble_sm_test_util_rx_pair_rsp(uint16_t conn_handle, struct ble_sm_pair_cmd *rsp,
-                             int rx_status)
-{
-    ble_sm_test_util_rx_pair_cmd(conn_handle, BLE_SM_OP_PAIR_RSP,
-                                       rsp, rx_status);
-}
-
-static void
-ble_sm_test_util_rx_confirm(uint16_t conn_handle,
-                            struct ble_sm_pair_confirm *cmd)
-{
-    struct hci_data_hdr hci_hdr;
-    struct os_mbuf *om;
-    void *v;
-    int payload_len;
-    int rc;
-
-    hci_hdr = BLE_SM_TEST_UTIL_HCI_HDR(
-        2, BLE_HCI_PB_FIRST_FLUSH,
-        BLE_L2CAP_HDR_SZ + BLE_SM_HDR_SZ + BLE_SM_PAIR_CONFIRM_SZ);
-
-    om = ble_hs_misc_pkthdr();
-    TEST_ASSERT_FATAL(om != NULL);
-
-    payload_len = BLE_SM_HDR_SZ + BLE_SM_PAIR_CONFIRM_SZ;
-
-    v = os_mbuf_extend(om, payload_len);
-    TEST_ASSERT_FATAL(v != NULL);
-
-    ble_sm_pair_confirm_write(v, payload_len, cmd);
-
-    rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SM,
-                                              &hci_hdr, om);
-    TEST_ASSERT_FATAL(rc == 0);
-}
-
-static void
-ble_sm_test_util_rx_random(uint16_t conn_handle,
-                           struct ble_sm_pair_random *cmd,
-                           int exp_status)
-{
-    struct hci_data_hdr hci_hdr;
-    struct os_mbuf *om;
-    void *v;
-    int payload_len;
-    int rc;
-
-    hci_hdr = BLE_SM_TEST_UTIL_HCI_HDR(
-        2, BLE_HCI_PB_FIRST_FLUSH,
-        BLE_L2CAP_HDR_SZ + BLE_SM_HDR_SZ + BLE_SM_PAIR_RANDOM_SZ);
-
-    om = ble_hs_misc_pkthdr();
-    TEST_ASSERT_FATAL(om != NULL);
-
-    payload_len = BLE_SM_HDR_SZ + BLE_SM_PAIR_RANDOM_SZ;
-
-    v = os_mbuf_extend(om, payload_len);
-    TEST_ASSERT_FATAL(v != NULL);
-
-    ble_sm_pair_random_write(v, payload_len, cmd);
-
-    rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SM,
-                                              &hci_hdr, om);
-    TEST_ASSERT_FATAL(rc == exp_status);
-}
-
-static void
-ble_sm_test_util_rx_sec_req(uint16_t conn_handle, struct ble_sm_sec_req *cmd,
-                            int exp_status)
-{
-    struct hci_data_hdr hci_hdr;
-    struct os_mbuf *om;
-    void *v;
-    int payload_len;
-    int rc;
-
-    hci_hdr = BLE_SM_TEST_UTIL_HCI_HDR(
-        2, BLE_HCI_PB_FIRST_FLUSH,
-        BLE_L2CAP_HDR_SZ + BLE_SM_HDR_SZ + BLE_SM_SEC_REQ_SZ);
-
-    om = ble_hs_misc_pkthdr();
-    TEST_ASSERT_FATAL(om != NULL);
-
-    payload_len = BLE_SM_HDR_SZ + BLE_SM_SEC_REQ_SZ;
-
-    v = os_mbuf_extend(om, payload_len);
-    TEST_ASSERT_FATAL(v != NULL);
-
-    ble_sm_sec_req_write(v, payload_len, cmd);
-
-    rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SM,
-                                              &hci_hdr, om);
-    TEST_ASSERT_FATAL(rc == exp_status);
-}
-
-static void
-ble_sm_test_util_rx_public_key(uint16_t conn_handle,
-                               struct ble_sm_public_key *cmd)
-{
-    struct hci_data_hdr hci_hdr;
-    struct os_mbuf *om;
-    void *v;
-    int payload_len;
-    int rc;
-
-    hci_hdr = BLE_SM_TEST_UTIL_HCI_HDR(
-        2, BLE_HCI_PB_FIRST_FLUSH,
-        BLE_L2CAP_HDR_SZ + BLE_SM_HDR_SZ + BLE_SM_PUBLIC_KEY_SZ);
-
-    om = ble_hs_misc_pkthdr();
-    TEST_ASSERT_FATAL(om != NULL);
-
-    payload_len = BLE_SM_HDR_SZ + BLE_SM_PUBLIC_KEY_SZ;
-
-    v = os_mbuf_extend(om, payload_len);
-    TEST_ASSERT_FATAL(v != NULL);
-
-    ble_sm_public_key_write(v, payload_len, cmd);
-
-    rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SM,
-                                              &hci_hdr, om);
-    TEST_ASSERT_FATAL(rc == 0);
-}
-
-static void
-ble_sm_test_util_rx_dhkey_check(uint16_t conn_handle,
-                                struct ble_sm_dhkey_check *cmd,
-                                int exp_status)
-{
-    struct hci_data_hdr hci_hdr;
-    struct os_mbuf *om;
-    void *v;
-    int payload_len;
-    int rc;
-
-    hci_hdr = BLE_SM_TEST_UTIL_HCI_HDR(
-        2, BLE_HCI_PB_FIRST_FLUSH,
-        BLE_L2CAP_HDR_SZ + BLE_SM_HDR_SZ + BLE_SM_DHKEY_CHECK_SZ);
-
-    om = ble_hs_misc_pkthdr();
-    TEST_ASSERT_FATAL(om != NULL);
-
-    payload_len = BLE_SM_HDR_SZ + BLE_SM_DHKEY_CHECK_SZ;
-
-    v = os_mbuf_extend(om, payload_len);
-    TEST_ASSERT_FATAL(v != NULL);
-
-    ble_sm_dhkey_check_write(v, payload_len, cmd);
-
-    rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SM,
-                                              &hci_hdr, om);
-    TEST_ASSERT_FATAL(rc == exp_status);
-}
-
-static struct os_mbuf *
-ble_sm_test_util_verify_tx_hdr(uint8_t sm_op, uint16_t payload_len)
-{
-    struct os_mbuf *om;
-
-    om = ble_hs_test_util_prev_tx_dequeue();
-    TEST_ASSERT_FATAL(om != NULL);
-
-    TEST_ASSERT(OS_MBUF_PKTLEN(om) == BLE_SM_HDR_SZ + payload_len);
-    TEST_ASSERT_FATAL(om->om_data[0] == sm_op);
-
-    om->om_data += BLE_SM_HDR_SZ;
-    om->om_len -= BLE_SM_HDR_SZ;
-
-    return om;
-}
-
-static void
-ble_sm_test_util_verify_tx_pair_cmd(
-    uint8_t op,
-    struct ble_sm_pair_cmd *exp_cmd)
-{
-    struct ble_sm_pair_cmd cmd;
-    struct os_mbuf *om;
-
-    om = ble_sm_test_util_verify_tx_hdr(op, BLE_SM_PAIR_CMD_SZ);
-    ble_sm_pair_cmd_parse(om->om_data, om->om_len, &cmd);
-
-    TEST_ASSERT(cmd.io_cap == exp_cmd->io_cap);
-    TEST_ASSERT(cmd.oob_data_flag == exp_cmd->oob_data_flag);
-    TEST_ASSERT(cmd.authreq == exp_cmd->authreq);
-    TEST_ASSERT(cmd.max_enc_key_size == exp_cmd->max_enc_key_size);
-    TEST_ASSERT(cmd.init_key_dist == exp_cmd->init_key_dist);
-    TEST_ASSERT(cmd.resp_key_dist == exp_cmd->resp_key_dist);
-}
-
-static void
-ble_sm_test_util_verify_tx_pair_req(
-    struct ble_sm_pair_cmd *exp_req)
-{
-    ble_sm_test_util_verify_tx_pair_cmd(BLE_SM_OP_PAIR_REQ,
-                                              exp_req);
-}
-
-static void
-ble_sm_test_util_verify_tx_pair_rsp(
-    struct ble_sm_pair_cmd *exp_rsp)
-{
-    ble_sm_test_util_verify_tx_pair_cmd(BLE_SM_OP_PAIR_RSP,
-                                              exp_rsp);
-}
-
-static void
-ble_sm_test_util_verify_tx_pair_confirm(
-    struct ble_sm_pair_confirm *exp_cmd)
-{
-    struct ble_sm_pair_confirm cmd;
-    struct os_mbuf *om;
-
-    om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_PAIR_CONFIRM,
-                                        BLE_SM_PAIR_CONFIRM_SZ);
-    ble_sm_pair_confirm_parse(om->om_data, om->om_len, &cmd);
-
-    TEST_ASSERT(memcmp(cmd.value, exp_cmd->value, 16) == 0);
-}
-
-static void
-ble_sm_test_util_verify_tx_pair_random(
-    struct ble_sm_pair_random *exp_cmd)
-{
-    struct ble_sm_pair_random cmd;
-    struct os_mbuf *om;
-
-    om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_PAIR_RANDOM,
-                                        BLE_SM_PAIR_RANDOM_SZ);
-    ble_sm_pair_random_parse(om->om_data, om->om_len, &cmd);
-
-    TEST_ASSERT(memcmp(cmd.value, exp_cmd->value, 16) == 0);
-}
-
-static void
-ble_sm_test_util_verify_tx_public_key(
-    struct ble_sm_public_key *exp_cmd)
-{
-    struct ble_sm_public_key cmd;
-    struct os_mbuf *om;
-
-    ble_hs_test_util_tx_all();
-
-    om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_PAIR_PUBLIC_KEY,
-                                              BLE_SM_PUBLIC_KEY_SZ);
-    ble_sm_public_key_parse(om->om_data, om->om_len, &cmd);
-
-    TEST_ASSERT(memcmp(cmd.x, exp_cmd->x, sizeof cmd.x) == 0);
-    TEST_ASSERT(memcmp(cmd.y, exp_cmd->y, sizeof cmd.y) == 0);
-}
-
-static void
-ble_sm_test_util_verify_tx_dhkey_check(
-    struct ble_sm_dhkey_check *exp_cmd)
-{
-    struct ble_sm_dhkey_check cmd;
-    struct os_mbuf *om;
-
-    om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_PAIR_DHKEY_CHECK,
-                                              BLE_SM_DHKEY_CHECK_SZ);
-    ble_sm_dhkey_check_parse(om->om_data, om->om_len, &cmd);
-
-    TEST_ASSERT(memcmp(cmd.value, exp_cmd->value, 16) == 0);
-}
-
-static void
-ble_sm_test_util_verify_tx_enc_info(
-    struct ble_sm_enc_info *exp_cmd)
-{
-    struct ble_sm_enc_info cmd;
-    struct os_mbuf *om;
-
-    om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_ENC_INFO,
-                                              BLE_SM_ENC_INFO_SZ);
-    ble_sm_enc_info_parse(om->om_data, om->om_len, &cmd);
-
-    TEST_ASSERT(memcmp(cmd.ltk, exp_cmd->ltk, sizeof cmd.ltk) == 0);
-}
-
-static void
-ble_sm_test_util_verify_tx_sec_req(struct ble_sm_sec_req *exp_cmd)
-{
-    struct ble_sm_sec_req cmd;
-    struct os_mbuf *om;
-
-    ble_hs_test_util_tx_all();
-
-    om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_SEC_REQ,
-                                              BLE_SM_SEC_REQ_SZ);
-    ble_sm_sec_req_parse(om->om_data, om->om_len, &cmd);
-
-    TEST_ASSERT(cmd.authreq == exp_cmd->authreq);
-}
-
-static void
-ble_sm_test_util_verify_tx_pair_fail(
-    struct ble_sm_pair_fail *exp_cmd)
-{
-    struct ble_sm_pair_fail cmd;
-    struct os_mbuf *om;
-
-    om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_PAIR_FAIL,
-                                              BLE_SM_PAIR_FAIL_SZ);
-    ble_sm_pair_fail_parse(om->om_data, om->om_len, &cmd);
-
-    TEST_ASSERT(cmd.reason == exp_cmd->reason);
-}
-
-static void
-ble_sm_test_util_rx_lt_key_req(uint16_t conn_handle, uint64_t r,
-                                     uint16_t ediv)
-{
-    struct hci_le_lt_key_req evt;
-    int rc;
-
-    evt.subevent_code = BLE_HCI_LE_SUBEV_LT_KEY_REQ;
-    evt.connection_handle = conn_handle;
-    evt.random_number = r;
-    evt.encrypted_diversifier = ediv;
-
-    rc = ble_sm_ltk_req_rx(&evt);
-    TEST_ASSERT_FATAL(rc == 0);
-}
-
-static void
-ble_sm_test_util_verify_tx_lt_key_req_reply(uint16_t conn_handle,
-                                                  uint8_t *stk)
-{
-    uint8_t param_len;
-    uint8_t *param;
-
-    param = ble_hs_test_util_verify_tx_hci(BLE_HCI_OGF_LE,
-                                           BLE_HCI_OCF_LE_LT_KEY_REQ_REPLY,
-                                           &param_len);
-    TEST_ASSERT(param_len == BLE_HCI_LT_KEY_REQ_REPLY_LEN);
-    TEST_ASSERT(le16toh(param + 0) == conn_handle);
-    TEST_ASSERT(memcmp(param + 2, stk, 16) == 0);
-}
-
-static void
-ble_sm_test_util_verify_tx_lt_key_req_neg_reply(uint16_t conn_handle)
-{
-    uint8_t param_len;
-    uint8_t *param;
-
-    param = ble_hs_test_util_verify_tx_hci(BLE_HCI_OGF_LE,
-                                           BLE_HCI_OCF_LE_LT_KEY_REQ_NEG_REPLY,
-                                           &param_len);
-    TEST_ASSERT(param_len == BLE_HCI_LT_KEY_REQ_NEG_REPLY_LEN);
-    TEST_ASSERT(le16toh(param + 0) == conn_handle);
-}
-
-static void
-ble_sm_test_util_set_lt_key_req_reply_ack(uint8_t status,
-                                                uint16_t conn_handle)
-{
-    static uint8_t params[BLE_HCI_LT_KEY_REQ_REPLY_ACK_PARAM_LEN];
-
-    htole16(params, conn_handle);
-    ble_hs_test_util_set_ack_params(
-        host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_LT_KEY_REQ_REPLY),
-        status, params, sizeof params);
-}
-
-static void
-ble_sm_test_util_rx_enc_change(uint16_t conn_handle, uint8_t status,
-                                     uint8_t encryption_enabled)
-{
-    struct hci_encrypt_change evt;
-
-    evt.status = status;
-    evt.encryption_enabled = encryption_enabled;
-    evt.connection_handle = conn_handle;
-
-    ble_sm_enc_change_rx(&evt);
-}
-
-static void
-ble_sm_test_util_verify_tx_start_enc(uint16_t conn_handle,
-                                     uint64_t random_number,
-                                     uint16_t ediv,
-                                     uint8_t *ltk)
-{
-    uint8_t param_len;
-    uint8_t *param;
-
-    param = ble_hs_test_util_verify_tx_hci(BLE_HCI_OGF_LE,
-                                           BLE_HCI_OCF_LE_START_ENCRYPT,
-                                           &param_len);
-    TEST_ASSERT(param_len == BLE_HCI_LE_START_ENCRYPT_LEN);
-    TEST_ASSERT(le16toh(param + 0) == conn_handle);
-    TEST_ASSERT(le64toh(param + 2) == random_number);
-    TEST_ASSERT(le16toh(param + 10) == ediv);
-    TEST_ASSERT(memcmp(param + 12, ltk, 16) == 0);
-}
-
-static void
-ble_sm_test_util_io_inject(struct ble_sm_test_passkey_info *passkey_info,
-                           uint8_t cur_sm_state)
-{
-    uint8_t io_sm_state;
-    int rc;
-
-    io_sm_state = ble_sm_ioact_state(passkey_info->passkey.action);
-    if (io_sm_state != cur_sm_state) {
-        return;
-    }
-
-    if (passkey_info->passkey.action == BLE_SM_IOACT_NUMCMP) {
-        TEST_ASSERT(ble_sm_test_ioact.numcmp == passkey_info->exp_numcmp);
-    }
-
-    rc = ble_sm_inject_io(2, &passkey_info->passkey);
-    TEST_ASSERT(rc == 0);
-}
-
-static void
-ble_sm_test_util_io_inject_bad(uint16_t conn_handle, uint8_t correct_io_act)
-{
-    struct ble_sm_proc *proc;
-    struct ble_sm_io io;
-    uint8_t io_sm_state;
-    int rc;
-    int i;
-
-    /* Lock mutex to prevent thread-safety assert from failing. */
-    ble_hs_lock();
-    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_NONE, -1, NULL);
-    ble_hs_unlock();
-
-    TEST_ASSERT_FATAL(proc != NULL);
-
-    io_sm_state = ble_sm_ioact_state(correct_io_act);
-
-    for (i = 1; i < BLE_SM_IOACT_MAX_PLUS_ONE; i++) {
-        if (io_sm_state != proc->state  ||
-            i != correct_io_act         ||
-            proc->flags & BLE_SM_PROC_F_IO_INJECTED) {
-
-            io.action = i;
-            rc = ble_sm_inject_io(conn_handle, &io);
-
-            if (proc->flags & BLE_SM_PROC_F_IO_INJECTED) {
-                TEST_ASSERT(rc == BLE_HS_EALREADY);
-            } else {
-                TEST_ASSERT(rc == BLE_HS_EINVAL);
-            }
-        }
-    }
-}
-
-static void
-ble_sm_test_util_io_check_pre(struct ble_sm_test_passkey_info *passkey_info,
-                              uint8_t cur_sm_state)
-{
-    uint8_t io_sm_state;
-    int rc;
-
-    io_sm_state = ble_sm_ioact_state(passkey_info->passkey.action);
-    if (io_sm_state != cur_sm_state) {
-        return;
-    }
-
-    if (!passkey_info->io_before_rx) {
-        return;
-    }
-
-    if (passkey_info->passkey.action == BLE_SM_IOACT_NUMCMP) {
-        TEST_ASSERT(ble_sm_test_ioact.numcmp == passkey_info->exp_numcmp);
-    }
-
-    rc = ble_sm_inject_io(2, &passkey_info->passkey);
-    TEST_ASSERT(rc == 0);
-}
-
-static void
-ble_sm_test_util_io_check_post(struct ble_sm_test_passkey_info *passkey_info,
-                               uint8_t cur_sm_state)
-{
-    uint8_t io_sm_state;
-    int rc;
-
-    io_sm_state = ble_sm_ioact_state(passkey_info->passkey.action);
-    if (io_sm_state != cur_sm_state) {
-        return;
-    }
-
-    if (passkey_info->io_before_rx) {
-        return;
-    }
-
-    if (passkey_info->passkey.action == BLE_SM_IOACT_NUMCMP) {
-        TEST_ASSERT(ble_sm_test_ioact.numcmp == passkey_info->exp_numcmp);
-    }
-
-    /* Ensure response not sent until user performs IO. */
-    ble_hs_test_util_tx_all();
-    TEST_ASSERT(ble_hs_test_util_prev_tx_queue_sz() == 0);
-
-    rc = ble_sm_inject_io(2, &passkey_info->passkey);
-    TEST_ASSERT_FATAL(rc == 0);
-}
-
-static void
-ble_sm_test_util_verify_lgcy_persist(struct ble_sm_test_lgcy_params *params)
-{
-    struct ble_store_value_sec value_sec;
-    struct ble_store_key_sec key_sec;
-    int rc;
-
-    memset(&key_sec, 0, sizeof key_sec);
-    key_sec.peer_addr_type = BLE_STORE_ADDR_TYPE_NONE;
-
-    if (params->pair_rsp.init_key_dist == 0) {
-        rc = ble_store_read_slv_sec(&key_sec, &value_sec);
-        TEST_ASSERT(rc == BLE_HS_ENOENT);
-    } else {
-        rc = ble_store_read_mst_sec(&key_sec, &value_sec);
-        TEST_ASSERT_FATAL(rc == 0);
-        TEST_ASSERT(value_sec.peer_addr_type == 0);
-        TEST_ASSERT(memcmp(value_sec.peer_addr, params->init_addr, 6) == 0);
-        TEST_ASSERT(value_sec.ediv == params->ediv);
-        TEST_ASSERT(value_sec.rand_num == params->r);
-        TEST_ASSERT(value_sec.authenticated == params->authenticated);
-        TEST_ASSERT(value_sec.ltk_present == 1);
-        TEST_ASSERT(memcmp(value_sec.ltk, params->enc_info_req.ltk, 16) == 0);
-        TEST_ASSERT(value_sec.irk_present == 0);
-        TEST_ASSERT(value_sec.csrk_present == 0);
-
-        /* Verify no other keys were persisted. */
-        key_sec.idx++;
-        rc = ble_store_read_mst_sec(&key_sec, &value_sec);
-        TEST_ASSERT_FATAL(rc == BLE_HS_ENOENT);
-    }
-
-    memset(&key_sec, 0, sizeof key_sec);
-    key_sec.peer_addr_type = BLE_STORE_ADDR_TYPE_NONE;
-
-    if (params->pair_rsp.resp_key_dist == 0) {
-        rc = ble_store_read_slv_sec(&key_sec, &value_sec);
-        TEST_ASSERT(rc == BLE_HS_ENOENT);
-    } else {
-        rc = ble_store_read_slv_sec(&key_sec, &value_sec);
-        TEST_ASSERT_FATAL(rc == 0);
-        TEST_ASSERT(value_sec.peer_addr_type == 0);
-        TEST_ASSERT(memcmp(value_sec.peer_addr, params->init_addr, 6) == 0);
-        TEST_ASSERT(value_sec.ediv == params->ediv);
-        TEST_ASSERT(value_sec.rand_num == params->r);
-        TEST_ASSERT(value_sec.authenticated == params->authenticated);
-        TEST_ASSERT(value_sec.ltk_present == 1);
-        TEST_ASSERT(memcmp(value_sec.ltk, params->enc_info_req.ltk, 16) == 0);
-        TEST_ASSERT(value_sec.irk_present == 0);
-        TEST_ASSERT(value_sec.csrk_present == 0);
-
-        /* Verify no other keys were persisted. */
-        key_sec.idx++;
-        rc = ble_store_read_slv_sec(&key_sec, &value_sec);
-        TEST_ASSERT_FATAL(rc == BLE_HS_ENOENT);
-    }
-}
-
-static void
-ble_sm_test_util_verify_sc_persist(struct ble_sm_test_sc_params *params,
-                                   int we_are_initiator)
-{
-    struct ble_store_value_sec value_sec;
-    struct ble_store_key_sec key_sec;
-    uint8_t *peer_addr;
-    uint8_t peer_addr_type;
-    int rc;
-
-    if (we_are_initiator) {
-        peer_addr_type = 0;
-        peer_addr = params->resp_addr;
-    } else {
-        peer_addr_type = 0;
-        peer_addr = params->init_addr;
-    }
-
-    memset(&key_sec, 0, sizeof key_sec);
-    key_sec.peer_addr_type = BLE_STORE_ADDR_TYPE_NONE;
-
-    rc = ble_store_read_mst_sec(&key_sec, &value_sec);
-    TEST_ASSERT_FATAL(rc == 0);
-    TEST_ASSERT(value_sec.peer_addr_type == peer_addr_type);
-    TEST_ASSERT(memcmp(value_sec.peer_addr, peer_addr, 6) == 0);
-    TEST_ASSERT(value_sec.ediv == 0);
-    TEST_ASSERT(value_sec.rand_num == 0);
-    TEST_ASSERT(value_sec.authenticated == params->authenticated);
-    TEST_ASSERT(value_sec.ltk_present == 1);
-    TEST_ASSERT(memcmp(value_sec.ltk, params->ltk, 16) == 0);
-    TEST_ASSERT(value_sec.irk_present == 0);
-    TEST_ASSERT(value_sec.csrk_present == 0);
-
-    rc = ble_store_read_slv_sec(&key_sec, &value_sec);
-    TEST_ASSERT_FATAL(rc == 0);
-    TEST_ASSERT(value_sec.peer_addr_type == peer_addr_type);
-    TEST_ASSERT(memcmp(value_sec.peer_addr, peer_addr, 6) == 0);
-    TEST_ASSERT(value_sec.ediv == 0);
-    TEST_ASSERT(value_sec.rand_num == 0);
-    TEST_ASSERT(value_sec.authenticated == params->authenticated);
-    TEST_ASSERT(value_sec.ltk_present == 1);
-    TEST_ASSERT(memcmp(value_sec.ltk, params->ltk, 16) == 0);
-    TEST_ASSERT(value_sec.irk_present == 0);
-    TEST_ASSERT(value_sec.csrk_present == 0);
-
-    /* Verify no other keys were persisted. */
-    key_sec.idx++;
-    rc = ble_store_read_slv_sec(&key_sec, &value_sec);
-    TEST_ASSERT_FATAL(rc == BLE_HS_ENOENT);
-    rc = ble_store_read_mst_sec(&key_sec, &value_sec);
-    TEST_ASSERT_FATAL(rc == BLE_HS_ENOENT);
-}
-
-static void
-ble_sm_test_util_us_lgcy_good(
-    struct ble_sm_test_lgcy_params *params)
-{
-    struct ble_hs_conn *conn;
-    int rc;
-
-    ble_sm_test_util_init();
-    ble_hs_test_util_set_public_addr(params->init_addr);
-    ble_sm_dbg_set_next_pair_rand(params->random_req.value);
-    ble_sm_dbg_set_next_ediv(params->ediv);
-    ble_sm_dbg_set_next_start_rand(params->r);
-
-    if (params->has_enc_info_req) {
-        ble_sm_dbg_set_next_ltk(params->enc_info_req.ltk);
-    }
-
-    ble_hs_test_util_create_conn(2, params->resp_addr,
-                                 ble_sm_test_util_conn_cb,
-                                 NULL);
-
-    /* This test inspects and modifies the connection object after unlocking
-     * the host mutex.  It is not OK for real code to do this, but this test
-     * can assume the connection list is unchanging.
-     */
-    ble_hs_lock();
-    conn = ble_hs_conn_find(2);
-    TEST_ASSERT_FATAL(conn != NULL);
-    ble_hs_unlock();
-
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    ble_hs_test_util_set_ack(
-        host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_START_ENCRYPT), 0);
-    if (params->has_sec_req) {
-        ble_sm_test_util_rx_sec_req(2, &params->sec_req, 0);
-    } else {
-        /* Initiate the pairing procedure. */
-        rc = ble_gap_security_initiate(2);
-        TEST_ASSERT_FATAL(rc == 0);
-    }
-
-    /* Ensure we sent the expected pair request. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_pair_req(&params->pair_req);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Receive a pair response from the peer. */
-    ble_sm_test_util_rx_pair_rsp(2, &params->pair_rsp, 0);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Ensure we sent the expected pair confirm. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_pair_confirm(&params->confirm_req);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Receive a pair confirm from the peer. */
-    ble_sm_test_util_rx_confirm(2, &params->confirm_rsp);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Ensure we sent the expected pair random. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_pair_random(&params->random_req);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Receive a pair random from the peer. */
-    ble_sm_test_util_rx_random(2, &params->random_rsp, 0);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Ensure keys are distributed, if necessary. */
-    if (params->has_enc_info_req) {
-        ble_sm_test_util_verify_tx_enc_info(&params->enc_info_req);
-    }
-
-    /* Ensure we sent the expected start encryption command. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_start_enc(2, params->r, params->ediv,
-                                         params->stk);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Receive an encryption changed event. */
-    ble_sm_test_util_rx_enc_change(2, 0, 1);
-
-    /* Pairing should now be complete. */
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    /* Verify that security callback was executed. */
-    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
-    TEST_ASSERT(ble_sm_test_gap_status == 0);
-    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
-    TEST_ASSERT(!ble_sm_test_sec_state.authenticated);
-
-    /* Verify that connection has correct security state. */
-    TEST_ASSERT(ble_sm_test_sec_state.encrypted ==
-                conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
-                conn->bhc_sec_state.authenticated);
-
-    /* Verify the appropriate security material was persisted. */
-    ble_sm_test_util_verify_lgcy_persist(params);
-}
-
-static void
-ble_sm_test_util_peer_fail_inval(
-    int we_are_master,
-    uint8_t *init_addr,
-    uint8_t *resp_addr,
-    struct ble_sm_pair_cmd *pair_req,
-    struct ble_sm_pair_fail *pair_fail)
-{
-    struct ble_hs_conn *conn;
-
-    ble_sm_test_util_init();
-    ble_hs_test_util_set_public_addr(resp_addr);
-
-    ble_hs_test_util_create_conn(2, init_addr, ble_sm_test_util_conn_cb,
-                                 NULL);
-
-    /* This test inspects and modifies the connection object after unlocking
-     * the host mutex.  It is not OK for real code to do this, but this test
-     * can assume the connection list is unchanging.
-     */
-    ble_hs_lock();
-    conn = ble_hs_conn_find(2);
-    TEST_ASSERT_FATAL(conn != NULL);
-    ble_hs_unlock();
-
-    if (!we_are_master) {
-        conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
-    }
-
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    /* Receive a pair request from the peer. */
-    ble_sm_test_util_rx_pair_req(2, pair_req,
-                                 BLE_HS_SM_US_ERR(pair_fail->reason));
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    /* Ensure we sent the expected pair fail. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_pair_fail(pair_fail);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    /* Verify that security callback was not executed. */
-    TEST_ASSERT(ble_sm_test_gap_event == -1);
-    TEST_ASSERT(ble_sm_test_gap_status == -1);
-
-    /* Verify that connection has correct security state. */
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(!conn->bhc_sec_state.authenticated);
-}
-
-static void
-ble_sm_test_util_peer_lgcy_fail_confirm(
-    uint8_t *init_addr,
-    uint8_t *resp_addr,
-    struct ble_sm_pair_cmd *pair_req,
-    struct ble_sm_pair_cmd *pair_rsp,
-    struct ble_sm_pair_confirm *confirm_req,
-    struct ble_sm_pair_confirm *confirm_rsp,
-    struct ble_sm_pair_random *random_req,
-    struct ble_sm_pair_random *random_rsp,
-    struct ble_sm_pair_fail *fail_rsp)
-{
-    struct ble_hs_conn *conn;
-
-    ble_sm_test_util_init();
-    ble_hs_test_util_set_public_addr(resp_addr);
-    ble_sm_dbg_set_next_pair_rand(random_rsp->value);
-
-    ble_hs_test_util_create_conn(2, init_addr, ble_sm_test_util_conn_cb,
-                                 NULL);
-
-    /* This test inspects and modifies the connection object after unlocking
-     * the host mutex.  It is not OK for real code to do this, but this test
-     * can assume the connection list is unchanging.
-     */
-    ble_hs_lock();
-    conn = ble_hs_conn_find(2);
-    TEST_ASSERT_FATAL(conn != NULL);
-    ble_hs_unlock();
-
-    /* Peer is the initiator so we must be the slave. */
-    conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
-
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    /* Receive a pair request from the peer. */
-    ble_sm_test_util_rx_pair_req(2, pair_req, 0);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
-
-    /* Ensure we sent the expected pair response. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_pair_rsp(pair_rsp);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
-
-    /* Receive a pair confirm from the peer. */
-    ble_sm_test_util_rx_confirm(2, confirm_req);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
-
-    /* Ensure we sent the expected pair confirm. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_pair_confirm(confirm_rsp);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
-
-    /* Receive a pair random from the peer. */
-    ble_sm_test_util_rx_random(
-        2, random_req, BLE_HS_SM_US_ERR(BLE_SM_ERR_CONFIRM_MISMATCH));
-
-    /* Ensure we sent the expected pair fail. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_pair_fail(fail_rsp);
-
-    /* The proc should now be freed. */
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    /* Verify that security callback was executed. */
-    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
-    TEST_ASSERT(ble_sm_test_gap_status ==
-                BLE_HS_SM_US_ERR(BLE_SM_ERR_CONFIRM_MISMATCH));
-    TEST_ASSERT(!ble_sm_test_sec_state.encrypted);
-    TEST_ASSERT(!ble_sm_test_sec_state.authenticated);
-
-    /* Verify that connection has correct security state. */
-    TEST_ASSERT(ble_sm_test_sec_state.encrypted ==
-                conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
-                conn->bhc_sec_state.authenticated);
-}
-
-static void
-ble_sm_test_util_peer_lgcy_good_once(struct ble_sm_test_lgcy_params *params)
-{
-    struct ble_hs_conn *conn;
-    int rc;
-
-    ble_sm_test_util_init();
-
-    ble_hs_cfg.sm_io_cap = params->pair_rsp.io_cap;
-    ble_hs_cfg.sm_oob_data_flag = params->pair_rsp.oob_data_flag;
-    ble_hs_cfg.sm_bonding = !!(params->pair_rsp.authreq &
-                               BLE_SM_PAIR_AUTHREQ_BOND);
-    ble_hs_cfg.sm_mitm = !!(params->pair_rsp.authreq &
-                            BLE_SM_PAIR_AUTHREQ_MITM);
-    ble_hs_cfg.sm_sc = 0;
-    ble_hs_cfg.sm_keypress = !!(params->pair_rsp.authreq &
-                                BLE_SM_PAIR_AUTHREQ_KEYPRESS);
-    ble_hs_cfg.sm_our_key_dist = params->pair_rsp.resp_key_dist;
-    ble_hs_cfg.sm_their_key_dist = params->pair_rsp.init_key_dist;
-
-    ble_hs_test_util_set_public_addr(params->resp_addr);
-    ble_sm_dbg_set_next_pair_rand(params->random_rsp.value);
-    ble_sm_dbg_set_next_ediv(params->ediv);
-    ble_sm_dbg_set_next_start_rand(params->r);
-
-    if (params->has_enc_info_req) {
-        ble_sm_dbg_set_next_ltk(params->enc_info_req.ltk);
-    }
-
-    ble_hs_test_util_create_conn(2, params->init_addr,
-                                 ble_sm_test_util_conn_cb,
-                                 NULL);
-
-    /* This test inspects and modifies the connection object after unlocking
-     * the host mutex.  It is not OK for real code to do this, but this test
-     * can assume the connection list is unchanging.
-     */
-    ble_hs_lock();
-    conn = ble_hs_conn_find(2);
-    TEST_ASSERT_FATAL(conn != NULL);
-    ble_hs_unlock();
-
-    /* Peer is the initiator so we must be the slave. */
-    conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
-
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    if (params->has_sec_req) {
-        rc = ble_sm_slave_initiate(2);
-        TEST_ASSERT(rc == 0);
-
-        /* Ensure we sent the expected security request. */
-        ble_sm_test_util_verify_tx_sec_req(&params->sec_req);
-    }
-
-    /* Receive a pair request from the peer. */
-    ble_sm_test_util_rx_pair_req(2, &params->pair_req, 0);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Ensure we sent the expected pair response. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_pair_rsp(&params->pair_rsp);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    ble_sm_test_util_io_check_pre(&params->passkey_info,
-                                  BLE_SM_PROC_STATE_CONFIRM);
-
-    /* Receive a pair confirm from the peer. */
-    ble_sm_test_util_rx_confirm(2, &params->confirm_req);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    ble_sm_test_util_io_check_post(&params->passkey_info,
-                                   BLE_SM_PROC_STATE_CONFIRM);
-
-    /* Ensure we sent the expected pair confirm. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_pair_confirm(&params->confirm_rsp);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Receive a pair random from the peer. */
-    ble_sm_test_util_rx_random(2, &params->random_req, 0);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Ensure we sent the expected pair random. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_pair_random(&params->random_rsp);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Receive a long term key request from the controller. */
-    ble_sm_test_util_set_lt_key_req_reply_ack(0, 2);
-    ble_sm_test_util_rx_lt_key_req(2, params->r, params->ediv);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Ensure we sent the expected long term key request reply command. */
-    ble_sm_test_util_verify_tx_lt_key_req_reply(2, params->stk);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Receive an encryption changed event. */
-    ble_sm_test_util_rx_enc_change(2, 0, 1);
-
-    if (params->has_enc_info_req) {
-        return; // XXX
-    }
-
-    /* Pairing should now be complete. */
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    /* Verify that security callback was executed. */
-    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
-    TEST_ASSERT(ble_sm_test_gap_status == 0);
-    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
-                params->authenticated);
-
-    /* Verify that connection has correct security state. */
-    TEST_ASSERT(ble_sm_test_sec_state.encrypted ==
-                conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
-                conn->bhc_sec_state.authenticated);
-
-    /* Verify the appropriate security material was persisted. */
-    ble_sm_test_util_verify_lgcy_persist(params);
-}
-
-static void
-ble_sm_test_util_peer_lgcy_good(struct ble_sm_test_lgcy_params *params)
-{
-    params->passkey_info.io_before_rx = 0;
-    ble_sm_test_util_peer_lgcy_good_once(params);
-
-    params->passkey_info.io_before_rx = 1;
-    ble_sm_test_util_peer_lgcy_good_once(params);
-}
-
-/**
- * @param send_enc_req          Whether this procedure is initiated by a slave
- *                                  security request;
- *                                  1: We send a security request at start.
- *                                  0: No security request; peer initiates.
- */
-static void
-ble_sm_test_util_peer_bonding_good(int send_enc_req, uint8_t *ltk,
-                                         int authenticated,
-                                         uint16_t ediv, uint64_t rand_num)
-{
-    struct ble_store_value_sec value_sec;
-    struct ble_hs_conn *conn;
-    int rc;
-
-    ble_sm_test_util_init();
-
-    ble_hs_test_util_create_conn(2, ((uint8_t[6]){1,2,3,4,5,6}),
-                                 ble_sm_test_util_conn_cb,
-                                 NULL);
-
-    /* This test inspects and modifies the connection object after unlocking
-     * the host mutex.  It is not OK for real code to do this, but this test
-     * can assume the connection list is unchanging.
-     */
-    ble_hs_lock();
-    conn = ble_hs_conn_find(2);
-    TEST_ASSERT_FATAL(conn != NULL);
-    conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
-    ble_hs_unlock();
-
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    /* Populate the SM database with an LTK for this peer. */
-    value_sec.peer_addr_type = conn->bhc_addr_type;
-    memcpy(value_sec.peer_addr, conn->bhc_addr, sizeof value_sec.peer_addr);
-    value_sec.ediv = ediv;
-    value_sec.rand_num = rand_num;
-    memcpy(value_sec.ltk, ltk, sizeof value_sec.ltk);
-    value_sec.ltk_present = 1;
-    value_sec.authenticated = authenticated;
-    value_sec.sc = 0;
-
-    rc = ble_store_write_slv_sec(&value_sec);
-    TEST_ASSERT_FATAL(rc == 0);
-
-    if (send_enc_req) {
-        rc = ble_sm_slave_initiate(2);
-        TEST_ASSERT(rc == 0);
-    }
-
-    /* Receive a long term key request from the controller. */
-    ble_sm_test_util_set_lt_key_req_reply_ack(0, 2);
-    ble_sm_test_util_rx_lt_key_req(2, rand_num, ediv);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-
-    /* Ensure the LTK request event got sent to the application. */
-    TEST_ASSERT(ble_sm_test_store_obj_type ==
-                BLE_STORE_OBJ_TYPE_SLV_SEC);
-    TEST_ASSERT(ble_sm_test_store_key.sec.peer_addr_type ==
-                BLE_ADDR_TYPE_PUBLIC);
-    TEST_ASSERT(ble_sm_test_store_key.sec.ediv_rand_present);
-    TEST_ASSERT(ble_sm_test_store_key.sec.ediv == ediv);
-    TEST_ASSERT(ble_sm_test_store_key.sec.rand_num == rand_num);
-
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
-
-    /* Ensure we sent the expected long term key request reply command. */
-    ble_sm_test_util_verify_tx_lt_key_req_reply(2, value_sec.ltk);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
-
-    /* Receive an encryption changed event. */
-    ble_sm_test_util_rx_enc_change(2, 0, 1);
-
-    /* Pairing should now be complete. */
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    /* Verify that security callback was executed. */
-    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
-    TEST_ASSERT(ble_sm_test_gap_status == 0);
-    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
-                authenticated);
-
-    /* Verify that connection has correct security state. */
-    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
-                authenticated);
-}
-
-static void
-ble_sm_test_util_peer_bonding_bad(uint16_t ediv, uint64_t rand_num)
-{
-    struct ble_hs_conn *conn;
-
-    ble_sm_test_util_init();
-
-    ble_hs_test_util_create_conn(2, ((uint8_t[6]){1,2,3,4,5,6}),
-                                 ble_sm_test_util_conn_cb,
-                                 NULL);
-
-    /* This test inspects and modifies the connection object after unlocking
-     * the host mutex.  It is not OK for real code to do this, but this test
-     * can assume the connection list is unchanging.
-     */
-    ble_hs_lock();
-    conn = ble_hs_conn_find(2);
-    TEST_ASSERT_FATAL(conn != NULL);
-    conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
-    ble_hs_unlock();
-
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    /* Receive a long term key request from the controller. */
-    ble_sm_test_util_set_lt_key_req_reply_ack(0, 2);
-    ble_sm_test_util_rx_lt_key_req(2, rand_num, ediv);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-
-    /* Ensure the LTK request event got sent to the application. */
-    TEST_ASSERT(ble_sm_test_store_obj_type ==
-                BLE_STORE_OBJ_TYPE_SLV_SEC);
-    TEST_ASSERT(ble_sm_test_store_key.sec.ediv_rand_present);
-    TEST_ASSERT(ble_sm_test_store_key.sec.ediv == ediv);
-    TEST_ASSERT(ble_sm_test_store_key.sec.rand_num == rand_num);
-
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-
-    /* Ensure we sent the expected long term key request neg reply command. */
-    ble_sm_test_util_verify_tx_lt_key_req_neg_reply(2);
-
-    /* Ensure the security procedure was aborted. */
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(!conn->bhc_sec_state.authenticated);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-}
-
-static void
-ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
-{
-    struct ble_hs_conn *conn;
-    int num_iters;
-    int rc;
-    int i;
-
-    ble_sm_test_util_init();
-
-    ble_hs_cfg.sm_io_cap = params->pair_rsp.io_cap;
-    ble_hs_cfg.sm_oob_data_flag = params->pair_rsp.oob_data_flag;
-    ble_hs_cfg.sm_bonding = !!(params->pair_rsp.authreq &
-                               BLE_SM_PAIR_AUTHREQ_BOND);
-    ble_hs_cfg.sm_mitm = !!(params->pair_rsp.authreq &
-                            BLE_SM_PAIR_AUTHREQ_MITM);
-    ble_hs_cfg.sm_sc = 1;
-    ble_hs_cfg.sm_keypress = !!(params->pair_rsp.authreq &
-                                BLE_SM_PAIR_AUTHREQ_KEYPRESS);
-    ble_hs_cfg.sm_our_key_dist = params->pair_rsp.resp_key_dist;
-    ble_hs_cfg.sm_their_key_dist = params->pair_rsp.init_key_dist;
-
-    ble_hs_test_util_set_public_addr(params->resp_addr);
-    ble_sm_dbg_set_next_pair_rand(params->random_rsp[0].value);
-
-    ble_sm_dbg_set_sc_keys(params->public_key_rsp.x, params->our_priv_key);
-
-    ble_hs_test_util_create_conn(2, params->init_addr,
-                                 ble_sm_test_util_conn_cb,
-                                 NULL);
-
-    /* This test inspects and modifies the connection object after unlocking
-     * the host mutex.  It is not OK for real code to do this, but this test
-     * can assume the connection list is unchanging.
-     */
-    ble_hs_lock();
-    conn = ble_hs_conn_find(2);
-    TEST_ASSERT_FATAL(conn != NULL);
-    ble_hs_unlock();
-
-    /* Peer is the initiator so we must be the slave. */
-    conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
-
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    if (params->has_sec_req) {
-        rc = ble_sm_slave_initiate(2);
-        TEST_ASSERT(rc == 0);
-
-        /* Ensure we sent the expected security request. */
-        ble_sm_test_util_verify_tx_sec_req(&params->sec_req);
-    }
-
-    /* Receive a pair request from the peer. */
-    ble_sm_test_util_rx_pair_req(2, &params->pair_req, 0);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Ensure we sent the expected pair response. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_pair_rsp(&params->pair_rsp);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Receive a public key from the peer. */
-    ble_sm_test_util_rx_public_key(2, &params->public_key_req);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Ensure we sent the expected public key. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_public_key(&params->public_key_rsp);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    switch (params->pair_alg) {
-    case BLE_SM_PAIR_ALG_PASSKEY:
-        num_iters = 20;
-        break;
-
-    default:
-        num_iters = 1;
-        break;
-    }
-
-    ble_sm_test_util_io_check_pre(&params->passkey_info,
-                                  BLE_SM_PROC_STATE_CONFIRM);
-
-    for (i = 0; i < num_iters; i++) {
-        if (params->pair_alg != BLE_SM_PAIR_ALG_JW      &&
-            params->pair_alg != BLE_SM_PAIR_ALG_NUMCMP) {
-
-            /* Receive a pair confirm from the peer. */
-            ble_sm_test_util_rx_confirm(2, params->confirm_req + i);
-            TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-            TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-            ble_sm_test_util_io_inject_bad(
-                2, params->passkey_info.passkey.action);
-
-            if (i < num_iters - 1) {
-                ble_sm_dbg_set_next_pair_rand(
-                    params->random_rsp[i + 1].value);
-            }
-        }
-
-        if (i == 0) {
-            ble_sm_test_util_io_check_post(&params->passkey_info,
-                                           BLE_SM_PROC_STATE_CONFIRM);
-        }
-
-        /* Ensure we sent the expected pair confirm. */
-        ble_hs_test_util_tx_all();
-        ble_sm_test_util_verify_tx_pair_confirm(params->confirm_rsp + i);
-        TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-        TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-        ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-        /* Receive a pair random from the peer. */
-        ble_sm_test_util_rx_random(2, params->random_req + i, 0);
-        TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-        TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-        ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-        /* Ensure we sent the expected pair random. */
-        ble_hs_test_util_tx_all();
-        ble_sm_test_util_verify_tx_pair_random(params->random_rsp + i);
-        TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-        TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-        ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    }
-
-    ble_sm_test_util_io_check_pre(&params->passkey_info,
-                                  BLE_SM_PROC_STATE_DHKEY_CHECK);
-
-    /* Receive a dhkey check from the peer. */
-    ble_sm_test_util_rx_dhkey_check(2, &params->dhkey_check_req, 0);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    ble_sm_test_util_io_check_post(&params->passkey_info,
-                                   BLE_SM_PROC_STATE_DHKEY_CHECK);
-
-    /* Ensure we sent the expected dhkey check. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_dhkey_check(&params->dhkey_check_rsp);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Receive a long term key request from the controller. */
-    ble_sm_test_util_set_lt_key_req_reply_ack(0, 2);
-    ble_sm_test_util_rx_lt_key_req(2, 0, 0);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Ensure we sent the expected long term key request reply command. */
-    ble_sm_test_util_verify_tx_lt_key_req_reply(2, params->ltk);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Receive an encryption changed event. */
-    ble_sm_test_util_rx_enc_change(2, 0, 1);
-
-    /* Pairing should now be complete. */
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    /* Verify that security callback was executed. */
-    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
-    TEST_ASSERT(ble_sm_test_gap_status == 0);
-    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
-                params->authenticated);
-
-    /* Verify that connection has correct security state. */
-    TEST_ASSERT(ble_sm_test_sec_state.encrypted ==
-                conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
-                conn->bhc_sec_state.authenticated);
-
-    /* Verify the appropriate security material was persisted. */
-    ble_sm_test_util_verify_sc_persist(params, 0);
-}
-
-static void
-ble_sm_test_util_peer_sc_good(struct ble_sm_test_sc_params *params)
-{
-    params->passkey_info.io_before_rx = 0;
-    ble_sm_test_util_peer_sc_good_once(params);
-
-    params->passkey_info.io_before_rx = 1;
-    ble_sm_test_util_peer_sc_good_once(params);
-
-}
-
-static void
-ble_sm_test_util_us_sc_good(struct ble_sm_test_sc_params *params)
-{
-    struct ble_hs_conn *conn;
-    int num_iters;
-    int rc;
-    int i;
-
-    ble_sm_test_util_init();
-
-    ble_hs_cfg.sm_io_cap = params->pair_req.io_cap;
-    ble_hs_cfg.sm_oob_data_flag = params->pair_req.oob_data_flag;
-    ble_hs_cfg.sm_bonding = !!(params->pair_req.authreq &
-                               BLE_SM_PAIR_AUTHREQ_BOND);
-    ble_hs_cfg.sm_mitm = !!(params->pair_req.authreq &
-                            BLE_SM_PAIR_AUTHREQ_MITM);
-    ble_hs_cfg.sm_sc = 1;
-    ble_hs_cfg.sm_keypress = !!(params->pair_req.authreq &
-                                BLE_SM_PAIR_AUTHREQ_KEYPRESS);
-    ble_hs_cfg.sm_our_key_dist = params->pair_req.init_key_dist;
-    ble_hs_cfg.sm_their_key_dist = params->pair_req.resp_key_dist;
-
-    ble_hs_test_util_set_public_addr(params->init_addr);
-    ble_sm_dbg_set_next_pair_rand(params->random_req[0].value);
-
-    ble_sm_dbg_set_sc_keys(params->public_key_req.x, params->our_priv_key);
-
-    ble_hs_test_util_create_conn(2, params->resp_addr,
-                                 ble_sm_test_util_conn_cb,
-                                 NULL);
-
-    /* This test inspects and modifies the connection object after unlocking
-     * the host mutex.  It is not OK for real code to do this, but this test
-     * can assume the connection list is unchanging.
-     */
-    ble_hs_lock();
-    conn = ble_hs_conn_find(2);
-    TEST_ASSERT_FATAL(conn != NULL);
-    ble_hs_unlock();
-
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    ble_hs_test_util_set_ack(
-        host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_START_ENCRYPT), 0);
-    if (params->has_sec_req) {
-        ble_sm_test_util_rx_sec_req(2, &params->sec_req, 0);
-    } else {
-        /* Initiate the pairing procedure. */
-        rc = ble_gap_security_initiate(2);
-        TEST_ASSERT_FATAL(rc == 0);
-    }
-
-    /* Ensure we sent the expected pair request. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_pair_req(&params->pair_req);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Receive a pair response from the peer. */
-    ble_sm_test_util_rx_pair_rsp(2, &params->pair_rsp, 0);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Ensure we sent the expected public key. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_public_key(&params->public_key_req);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Receive a public key from the peer. */
-    ble_sm_test_util_rx_public_key(2, &params->public_key_rsp);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    switch (params->pair_alg) {
-    case BLE_SM_PAIR_ALG_PASSKEY:
-        num_iters = 20;
-        break;
-
-    default:
-        num_iters = 1;
-        break;
-    }
-
-    ble_sm_test_util_io_inject(&params->passkey_info,
-                               BLE_SM_PROC_STATE_CONFIRM);
-
-    for (i = 0; i < num_iters; i++) {
-        if (params->pair_alg != BLE_SM_PAIR_ALG_JW      &&
-            params->pair_alg != BLE_SM_PAIR_ALG_NUMCMP) {
-
-            if (i < num_iters - 1) {
-                ble_sm_dbg_set_next_pair_rand(
-                    params->random_req[i + 1].value);
-            }
-
-            /* Ensure we sent the expected pair confirm. */
-            ble_hs_test_util_tx_all();
-            ble_sm_test_util_verify_tx_pair_confirm(params->confirm_req + i);
-            TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-            TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-            ble_sm_test_util_io_inject_bad(
-                2, params->passkey_info.passkey.action);
-        }
-
-        /* Receive a pair confirm from the peer. */
-        ble_sm_test_util_rx_confirm(2, params->confirm_rsp + i);
-        TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-        TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-        ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-        /* Ensure we sent the expected pair random. */
-        ble_hs_test_util_tx_all();
-        ble_sm_test_util_verify_tx_pair_random(params->random_req + i);
-        TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-        TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-        ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-        /* Receive a pair random from the peer. */
-        ble_sm_test_util_rx_random(2, params->random_rsp + i, 0);
-        TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-        TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-        ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-    }
-
-    ble_sm_test_util_io_inject(&params->passkey_info,
-                               BLE_SM_PROC_STATE_DHKEY_CHECK);
-
-    /* Ensure we sent the expected dhkey check. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_dhkey_check(&params->dhkey_check_req);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Receive a dhkey check from the peer. */
-    ble_sm_test_util_rx_dhkey_check(2, &params->dhkey_check_rsp, 0);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Ensure we sent the expected start encryption command. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_start_enc(2, 0, 0, params->ltk);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Receive an encryption changed event. */
-    ble_sm_test_util_rx_enc_change(2, 0, 1);
-
-    /* Pairing should now be complete. */
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    /* Verify that security callback was executed. */
-    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
-    TEST_ASSERT(ble_sm_test_gap_status == 0);
-    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
-                params->authenticated);
-
-    /* Verify that connection has correct security state. */
-    TEST_ASSERT(ble_sm_test_sec_state.encrypted ==
-                conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
-                conn->bhc_sec_state.authenticated);
-
-    /* Verify the appropriate security material was persisted. */
-    ble_sm_test_util_verify_sc_persist(params, 1);
-}
-
-static void
-ble_sm_test_util_us_fail_inval(
-    struct ble_sm_test_lgcy_params *params)
-{
-    struct ble_hs_conn *conn;
-    int rc;
-
-    ble_sm_test_util_init();
-    ble_hs_test_util_set_public_addr(params->resp_addr);
-
-    ble_sm_dbg_set_next_pair_rand(((uint8_t[16]){0}));
-
-    ble_hs_test_util_create_conn(2, params->init_addr,
-                                 ble_sm_test_util_conn_cb,
-                                 NULL);
-
-    /* This test inspects and modifies the connection object after unlocking
-     * the host mutex.  It is not OK for real code to do this, but this test
-     * can assume the connection list is unchanging.
-     */
-    ble_hs_lock();
-    conn = ble_hs_conn_find(2);
-    TEST_ASSERT_FATAL(conn != NULL);
-    ble_hs_unlock();
-
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    /* Initiate the pairing procedure. */
-    rc = ble_hs_test_util_security_initiate(2, 0);
-    TEST_ASSERT_FATAL(rc == 0);
-
-    /* Ensure we sent the expected pair request. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_pair_req(&params->pair_req);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
-
-    /* Receive a pair response from the peer. */
-    ble_sm_test_util_rx_pair_rsp(
-        2, &params->pair_rsp, BLE_HS_SM_US_ERR(BLE_SM_ERR_INVAL));
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    /* Ensure we sent the expected pair fail. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_pair_fail(&params->pair_fail);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    /* Verify that security callback was not executed. */
-    TEST_ASSERT(ble_sm_test_gap_event == -1);
-    TEST_ASSERT(ble_sm_test_gap_status == -1);
-
-    /* Verify that connection has correct security state. */
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(!conn->bhc_sec_state.authenticated);
-}
-
-/**
- * @param send_enc_req          Whether this procedure is initiated by a slave
- *                                  security request;
- *                                  1: Peer sends a security request at start.
- *                                  0: No security request; we initiate.
- */
-static void
-ble_sm_test_util_us_bonding_good(int send_enc_req, uint8_t *ltk,
-                                 int authenticated, uint16_t ediv,
-                                 uint64_t rand_num)
-{
-    struct ble_sm_sec_req sec_req;
-    struct ble_store_value_sec value_sec;
-    struct ble_hs_conn *conn;
-    int rc;
-
-    ble_sm_test_util_init();
-
-    ble_hs_test_util_create_conn(2, ((uint8_t[6]){1,2,3,4,5,6}),
-                                 ble_sm_test_util_conn_cb,
-                                 NULL);
-
-    /* This test inspects and modifies the connection object after unlocking
-     * the host mutex.  It is not OK for real code to do this, but this test
-     * can assume the connection list is unchanging.
-     */
-    ble_hs_lock();
-    conn = ble_hs_conn_find(2);
-    TEST_ASSERT_FATAL(conn != NULL);
-    ble_hs_unlock();
-
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    /* Populate the SM database with an LTK for this peer. */
-    value_sec.peer_addr_type = conn->bhc_addr_type;
-    memcpy(value_sec.peer_addr, conn->bhc_addr, sizeof value_sec.peer_addr);
-    value_sec.ediv = ediv;
-    value_sec.rand_num = rand_num;
-    memcpy(value_sec.ltk, ltk, sizeof value_sec.ltk);
-    value_sec.ltk_present = 1;
-    value_sec.irk_present = 0;
-    value_sec.authenticated = authenticated;
-    value_sec.sc = 0;
-
-    rc = ble_store_write_mst_sec(&value_sec);
-    TEST_ASSERT_FATAL(rc == 0);
-
-    if (send_enc_req) {
-        sec_req.authreq = 0;
-        sec_req.authreq |= BLE_SM_PAIR_AUTHREQ_BOND;
-        if (authenticated) {
-            sec_req.authreq |= BLE_SM_PAIR_AUTHREQ_MITM;
-        }
-        ble_hs_test_util_set_ack(
-            host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_START_ENCRYPT),
-            0);
-        ble_sm_test_util_rx_sec_req(2, &sec_req, 0);
-    }
-
-    /* Ensure we sent the expected start encryption command. */
-    ble_hs_test_util_tx_all();
-    ble_sm_test_util_verify_tx_start_enc(2, rand_num, ediv, ltk);
-    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
-    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
-
-    /* Receive an encryption changed event. */
-    ble_sm_test_util_rx_enc_change(2, 0, 1);
-
-    /* Pairing should now be complete. */
-    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
-
-    /* Verify that security callback was executed. */
-    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
-    TEST_ASSERT(ble_sm_test_gap_status == 0);
-    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
-                authenticated);
-
-    /* Verify that connection has correct security state. */
-    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
-    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
-                authenticated);
-}
-
 /*****************************************************************************
  * $misc                                                                     *
  *****************************************************************************/
@@ -2565,103 +687,6 @@ TEST_CASE(ble_sm_test_case_peer_sec_req_enc)
         0x5678);
 }
 
-TEST_CASE(ble_sm_test_case_peer_sc_jw_good)
-{
-    struct ble_sm_test_sc_params params;
-
-    params = (struct ble_sm_test_sc_params) {
-        .init_addr = { 0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0 },
-        .resp_addr = { 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07 },
-        .pair_req = (struct ble_sm_pair_cmd) {
-            .io_cap = 0x03,
-            .oob_data_flag = 0x00,
-            .authreq = 0x09,
-            .max_enc_key_size = 16,
-            .init_key_dist = 0x0d,
-            .resp_key_dist = 0x0f,
-        },
-        .pair_rsp = (struct ble_sm_pair_cmd) {
-            .io_cap = 0x03,
-            .oob_data_flag = 0x00,
-            .authreq = 0x09,
-            .max_enc_key_size = 16,
-            .init_key_dist = 0x01,
-            .resp_key_dist = 0x01,
-        },
-        .public_key_req = (struct ble_sm_public_key) {
-            .x = {
-                0x8b, 0xc6, 0x16, 0xc4, 0xcb, 0xd4, 0xb6, 0xad,
-                0x51, 0x8a, 0x21, 0x9a, 0x17, 0xf0, 0x3d, 0xab,
-                0xdb, 0x4c, 0xfb, 0x70, 0xac, 0x6c, 0xa1, 0x33,
-                0x6c, 0xa5, 0xa0, 0x56, 0x9b, 0x5f, 0xa7, 0xaa,
-            },
-            .y = {
-                0xd1, 0x8c, 0xd1, 0x86, 0x79, 0x46, 0x6b, 0x42,
-                0x28, 0x94, 0xf3, 0x80, 0x60, 0x43, 0xeb, 0x02,
-                0x3f, 0xb9, 0xa3, 0xb4, 0x8a, 0x60, 0x98, 0x17,
-                0xb5, 0x77, 0xc5, 0xc9, 0xf7, 0xae, 0x8d, 0xfc,
-            },
-        },
-        .public_key_rsp = (struct ble_sm_public_key) {
-            .x = {
-                0x48, 0x26, 0x4c, 0xff, 0xe7, 0xa9, 0xa1, 0x82,
-                0x4c, 0xc1, 0xdd, 0x34, 0x4a, 0x90, 0x9a, 0x7e,
-                0xda, 0x1f, 0x8a, 0x61, 0x30, 0xb7, 0xe5, 0xf1,
-                0x3c, 0x38, 0xc2, 0x61, 0xf7, 0x5f, 0x51, 0xdf,
-            },
-            .y = {
-                0xd4, 0xf5, 0xd9, 0x45, 0x92, 0x54, 0x53, 0xec,
-                0xe3, 0x08, 0x38, 0x3a, 0x33, 0x68, 0xab, 0x6b,
-                0x59, 0xb0, 0x79, 0xec, 0x6f, 0x8e, 0xc7, 0x1a,
-                0xe4, 0x72, 0x5d, 0x8c, 0x7a, 0xb9, 0x06, 0x2a,
-            },
-        },
-        .confirm_rsp[0] = {
-            .value = {
-                0x03, 0x8d, 0xc2, 0x76, 0xe8, 0xcb, 0xef, 0x88,
-                0x7d, 0x1f, 0xde, 0xf9, 0x8d, 0x1c, 0x7d, 0xc3,
-            },
-        },
-        .random_req[0] = {
-            .value = {
-                0xb9, 0x6c, 0xe1, 0xbb, 0x14, 0xec, 0x6f, 0x18,
-                0x2a, 0x5e, 0xae, 0xe3, 0x23, 0x91, 0x83, 0x3b,
-            },
-        },
-        .random_rsp[0] = {
-            .value = {
-                0x73, 0x7c, 0xc6, 0xc8, 0xbd, 0x64, 0xa5, 0xab,
-                0xf2, 0xd6, 0xbb, 0x82, 0x68, 0x8e, 0x1b, 0xc2,
-            },
-        },
-        .dhkey_check_req = (struct ble_sm_dhkey_check) {
-            .value = {
-                0x99, 0x75, 0xfb, 0x6f, 0xf0, 0xcd, 0x27, 0x83,
-                0x83, 0xf0, 0x0d, 0x6f, 0x54, 0xa1, 0x8a, 0xf0,
-            }
-        },
-        .dhkey_check_rsp = (struct ble_sm_dhkey_check) {
-            .value = {
-                0x4e, 0x78, 0x60, 0xcd, 0x2b, 0xdd, 0xa3, 0x03,
-                0x02, 0x3f, 0x9a, 0x05, 0x1d, 0xcb, 0x93, 0xd9,
-            }
-        },
-        .pair_alg = BLE_SM_PAIR_ALG_JW,
-        .authenticated = 0,
-        .ltk = {
-            0xdd, 0x81, 0x53, 0x79, 0x75, 0x63, 0x50, 0x79,
-            0x72, 0xa7, 0x2e, 0x96, 0xd6, 0x7b, 0x2b, 0xdd,
-        },
-        .our_priv_key = {
-            0x25, 0xd6, 0x7f, 0x0d, 0xf2, 0x89, 0x04, 0x05,
-            0xe2, 0xd3, 0x62, 0xb1, 0x64, 0xee, 0x01, 0xad,
-            0x1c, 0xa2, 0x54, 0xae, 0x43, 0x4e, 0xa9, 0x09,
-            0x67, 0xdc, 0xc1, 0x7c, 0x98, 0x63, 0x80, 0xd2
-        }
-    };
-    ble_sm_test_util_peer_sc_good(&params);
-}
-
 TEST_CASE(ble_sm_test_case_peer_sc_numcmp_good)
 {
     struct ble_sm_test_sc_params params;
@@ -3723,7 +1748,7 @@ TEST_CASE(ble_sm_test_case_us_sec_req_pair)
 }
 
 /**
- * Master: us
+ * Master: peer
  * Secure connections
  * Pair algorithm: just works
  */
@@ -3732,96 +1757,105 @@ TEST_CASE(ble_sm_test_case_us_sc_jw_good)
     struct ble_sm_test_sc_params params;
 
     params = (struct ble_sm_test_sc_params) {
-        .init_addr = { 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 },
-        .resp_addr = { 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07 },
-        .pair_req = (struct ble_sm_pair_cmd) {
+        .init_addr = {
+            0xd9, 0x38, 0x0c, 0x57, 0x0b, 0x00,
+        },
+        .resp_addr = {
+            0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
+        },
+        .pair_req = {
             .io_cap = 0x03,
             .oob_data_flag = 0x00,
-            .authreq = 0x09,
-            .max_enc_key_size = 16,
-            .init_key_dist = 0x01,
-            .resp_key_dist = 0x01,
+            .authreq = 0x08,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x00,
+            .resp_key_dist = 0x00,
         },
-        .pair_rsp = (struct ble_sm_pair_cmd) {
+        .pair_rsp = {
             .io_cap = 0x03,
             .oob_data_flag = 0x00,
             .authreq = 0x09,
-            .max_enc_key_size = 16,
-            .init_key_dist = 0x01,
-            .resp_key_dist = 0x01,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x00,
+            .resp_key_dist = 0x00,
         },
-        .public_key_req = (struct ble_sm_public_key) {
+        .our_priv_key = {
+            0xad, 0xa6, 0xe6, 0x21, 0xca, 0x43, 0x4b, 0x56,
+            0xfd, 0xf7, 0x87, 0xe9, 0x2d, 0x0b, 0x04, 0x37,
+            0xf9, 0xb4, 0x34, 0xc9, 0x10, 0x54, 0xa1, 0xbd,
+            0xe7, 0x9f, 0x74, 0x76, 0xd0, 0x28, 0x59, 0x2e,
+        },
+        .public_key_req = {
             .x = {
-                0x3b, 0x55, 0x78, 0xad, 0xa1, 0xda, 0xec, 0x54,
-                0x10, 0x57, 0x35, 0x5f, 0x63, 0xb0, 0xec, 0xdb,
-                0xdf, 0xb2, 0x31, 0x0d, 0xca, 0xf6, 0x3a, 0xa8,
-                0x82, 0xbd, 0xe3, 0x27, 0x12, 0xa5, 0xbe, 0x81
+                0xce, 0x69, 0xfe, 0xff, 0xde, 0x17, 0x7d, 0x2a,
+                0xfb, 0x0b, 0x66, 0xec, 0x4a, 0xf3, 0xef, 0x62,
+                0x64, 0xb9, 0xbe, 0x3c, 0x03, 0x8d, 0xa3, 0xff,
+                0x27, 0xd1, 0xc0, 0x6e, 0xa3, 0x58, 0x4f, 0x4f,
             },
             .y = {
-                0x07, 0x32, 0x82, 0x00, 0xbe, 0xc1, 0x39, 0xb5,
-                0x16, 0x7f, 0xbb, 0x7a, 0x79, 0xb8, 0xba, 0xf4,
-                0x45, 0x02, 0xa7, 0xe6, 0xeb, 0x58, 0xa4, 0x4e,
-                0xff, 0xd3, 0x55, 0x55, 0xd4, 0xb5, 0x21, 0x01
-            }
+                0x94, 0xa0, 0x8a, 0xa4, 0xc6, 0xf2, 0xd5, 0x28,
+                0xd3, 0x83, 0xb0, 0x1b, 0x4d, 0xc4, 0x31, 0x48,
+                0x87, 0x03, 0x05, 0x24, 0xdb, 0x62, 0x64, 0x98,
+                0xf2, 0xb5, 0xd6, 0x48, 0x9f, 0x58, 0x20, 0xd2,
+            },
         },
-        .public_key_rsp = (struct ble_sm_public_key) {
+        .public_key_rsp = {
             .x = {
-                0x05, 0xc5, 0x2e, 0x5e, 0x47, 0xcf, 0xd1, 0x1c,
-                0x88, 0x47, 0xbb, 0x96, 0x8f, 0x3a, 0xd9, 0xf3,
-                0xce, 0x48, 0x49, 0xa4, 0xef, 0x08, 0x95, 0xb3,
-                0xcc, 0x52, 0x75, 0xad, 0x3e, 0xb3, 0xce, 0x9d
+                0xb8, 0x74, 0x84, 0x87, 0x6c, 0xbb, 0x17, 0x94,
+                0x84, 0x4f, 0x55, 0xbf, 0x12, 0x68, 0x19, 0xb5,
+                0x0e, 0x7d, 0x6a, 0x80, 0xd9, 0x0a, 0x3f, 0x49,
+                0xbb, 0xe9, 0x76, 0x54, 0x81, 0xf7, 0x11, 0x8b,
             },
             .y = {
-                0x11, 0x68, 0x8e, 0x4e, 0x97, 0xae, 0x1b, 0x7e,
-                0x20, 0x57, 0x46, 0x0c, 0xc5, 0x9f, 0xf7, 0x1a,
-                0x9b, 0x73, 0x23, 0x1e, 0x56, 0x45, 0x2f, 0x6a,
-                0xb5, 0xf4, 0x62, 0x0e, 0xca, 0xcd, 0x57, 0x23
+                0x25, 0x51, 0x05, 0x3c, 0xa0, 0x3b, 0xab, 0xaa,
+                0xee, 0x51, 0x99, 0xc1, 0x48, 0xe9, 0x4b, 0xfd,
+                0xc3, 0xf7, 0x45, 0xd0, 0xfd, 0xd1, 0xab, 0x9f,
+                0x75, 0x2e, 0x3e, 0x7f, 0xd9, 0x2d, 0x30, 0xda,
             },
         },
         .confirm_rsp[0] = {
             .value = {
-                0x7a, 0x1b, 0xd1, 0x71, 0x29, 0x20, 0x31, 0x47,
-                0x67, 0x3c, 0x72, 0x4a, 0xa6, 0xad, 0x8a, 0x16
+                0xd6, 0x8c, 0x6e, 0x03, 0x9d, 0x29, 0xdc, 0xb1,
+                0xa5, 0x16, 0x4c, 0xf3, 0x6f, 0x32, 0xd3, 0x6c,
             },
         },
         .random_req[0] = {
             .value = {
-                0xa1, 0x7a, 0x73, 0x52, 0xc0, 0x5f, 0x97, 0xd5,
-                0x9b, 0x37, 0xcb, 0x50, 0x6b, 0x2e, 0x4f, 0xe8
+                0x15, 0x63, 0xb7, 0xf3, 0xda, 0xd4, 0xec, 0xe3,
+                0xd7, 0x28, 0xb4, 0xf0, 0xf5, 0xac, 0xfb, 0x9a,
             },
         },
         .random_rsp[0] = {
             .value = {
-                0x58, 0xec, 0x42, 0xef, 0xe5, 0x19, 0x54, 0xa5,
-                0x7a, 0xa2, 0x7f, 0xae, 0x45, 0x49, 0x08, 0x44
+                0x83, 0xa9, 0x2a, 0xa7, 0xfb, 0xcc, 0xcd, 0x3a,
+                0xaa, 0xd2, 0x08, 0xd8, 0x23, 0x21, 0xc8, 0x03,
             },
         },
-        .dhkey_check_req = (struct ble_sm_dhkey_check) {
+        .dhkey_check_req = {
             .value = {
-                0xfe, 0x60, 0x72, 0x4f, 0x17, 0x5b, 0x45, 0xde,
-                0xdc, 0x3d, 0x79, 0x71, 0x35, 0xc7, 0x14, 0x65
-            }
+                0x16, 0xd7, 0x43, 0x3e, 0xfd, 0x89, 0x36, 0x7d,
+                0x18, 0xad, 0x4d, 0xda, 0xa5, 0x48, 0x90, 0xdd,
+            },
         },
-        .dhkey_check_rsp = (struct ble_sm_dhkey_check) {
+        .dhkey_check_rsp = {
             .value = {
-                0x63, 0x11, 0xd1, 0xbf, 0xff, 0x86, 0x6d, 0xbf,
-                0xad, 0xf0, 0x08, 0x8c, 0x4d, 0x6e, 0x27, 0xa8
-            }
+                0xbe, 0xa9, 0x51, 0x38, 0x56, 0x82, 0x24, 0x42,
+                0xca, 0x3f, 0x66, 0xf4, 0xb8, 0x4e, 0xdb, 0x0e,
+            },
         },
-        .pair_alg = BLE_SM_PAIR_ALG_JW,
-        .authenticated = 0,
         .ltk = {
-            0xb2, 0x62, 0xbf, 0xf5, 0x57, 0x6b, 0x78, 0x09,
-            0x0c, 0xab, 0xde, 0x8a, 0x62, 0xae, 0xc1, 0xc3
+            0xf3, 0x18, 0x03, 0x68, 0x79, 0x56, 0x75, 0x43,
+            0xcf, 0xaa, 0x80, 0x2d, 0xbc, 0x3a, 0x6b, 0x64,
         },
-        .our_priv_key = {
-            0x87, 0x5d, 0x24, 0x79, 0x43, 0x29, 0x26, 0x84,
-            0x73, 0x64, 0xb1, 0x32, 0x30, 0x42, 0xab, 0x79,
-            0x55, 0x7b, 0x6d, 0xaa, 0xc2, 0x1e, 0x3e, 0xa6,
-            0xbe, 0x5b, 0x9e, 0x61, 0xb, 0x90, 0x3a, 0x95
+        .pair_alg = BLE_SM_PAIR_ALG_JW,
+        .authenticated = 0,
+        .passkey_info = {
+            .passkey = {
+                .action = BLE_SM_IOACT_NONE,
+            },
         },
     };
-    ble_sm_test_util_us_sc_good(&params);
+    ble_sm_test_util_peer_sc_good(&params);
 }
 
 /**
@@ -3940,569 +1974,607 @@ TEST_CASE(ble_sm_test_case_us_sc_numcmp_good)
 /**
  * Master: us
  * Secure connections
- * Pair algorithm: passkey
+ * Pair algorithm: passkey entry
  */
 TEST_CASE(ble_sm_test_case_us_sc_passkey_good)
 {
     struct ble_sm_test_sc_params params;
 
     params = (struct ble_sm_test_sc_params) {
-        .init_addr = { 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 },
-        .resp_addr = { 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07 },
-        .pair_req = (struct ble_sm_pair_cmd) {
-            .io_cap = 0x04,
+        .init_addr = {
+            0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
+        },
+        .resp_addr = {
+            0x5d, 0xab, 0xaa, 0x67, 0x11, 0x00,
+        },
+        .pair_req = {
+            .io_cap = 0x00,
             .oob_data_flag = 0x00,
             .authreq = 0x0d,
-            .max_enc_key_size = 16,
-            .init_key_dist = 0x01,
-            .resp_key_dist = 0x01,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x07,
+            .resp_key_dist = 0x07,
         },
-        .pair_rsp = (struct ble_sm_pair_cmd) {
+        .pair_rsp = {
             .io_cap = 0x02,
             .oob_data_flag = 0x00,
             .authreq = 0x0d,
-            .max_enc_key_size = 16,
-            .init_key_dist = 0x01,
-            .resp_key_dist = 0x01,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x06,
+            .resp_key_dist = 0x06,
         },
-        .public_key_req = (struct ble_sm_public_key) {
+        .our_priv_key = {
+            0xa2, 0x9d, 0x42, 0x60, 0xb0, 0xe2, 0x7c, 0x32,
+            0xfc, 0x7f, 0xc3, 0x42, 0xa2, 0x67, 0xfd, 0x39,
+            0x67, 0xb5, 0x8e, 0x37, 0xde, 0x6e, 0xd7, 0xda,
+            0x04, 0xed, 0x22, 0xf1, 0x5d, 0xa1, 0xd4, 0x1c,
+        },
+        .public_key_req = {
             .x = {
-                0x68, 0x71, 0x95, 0xf3, 0xca, 0xbe, 0x0d, 0x5c,
-                0xc2, 0x04, 0x7c, 0xb3, 0x2f, 0x57, 0xa5, 0x0a,
-                0xc0, 0x48, 0xbc, 0xd6, 0xe0, 0x86, 0x42, 0x6f,
-                0x0e, 0x71, 0x39, 0xe1, 0xed, 0x75, 0xa3, 0x0c
+                0xd2, 0x95, 0x3e, 0x65, 0x4f, 0x62, 0xea, 0x87,
+                0x4c, 0x5c, 0xef, 0xcc, 0x5e, 0x6d, 0xb6, 0xc4,
+                0x30, 0xd9, 0x09, 0x25, 0xca, 0xba, 0xd1, 0x61,
+                0x5b, 0x9c, 0x8a, 0xe3, 0x29, 0xcd, 0xf4, 0x46,
             },
             .y = {
-                0xee, 0x6a, 0x72, 0xb0, 0xb0, 0xa7, 0xb4, 0xc3,
-                0x64, 0x74, 0xb8, 0xef, 0x7e, 0x78, 0x1c, 0x00,
-                0x8f, 0x87, 0x34, 0x0c, 0x8d, 0xf6, 0x1b, 0x4f,
-                0xde, 0x35, 0xf3, 0x38, 0x9b, 0x42, 0xcd, 0x90
+                0x40, 0xda, 0x39, 0xec, 0xd0, 0xd9, 0x13, 0x2f,
+                0x22, 0xc9, 0xc4, 0x6e, 0x67, 0x58, 0xb0, 0xde,
+                0xb3, 0x24, 0xfd, 0x9a, 0x13, 0x32, 0x38, 0x83,
+                0x71, 0x80, 0x20, 0xc3, 0x69, 0xbf, 0x18, 0x2c,
             },
         },
-        .public_key_rsp = (struct ble_sm_public_key) {
+        .public_key_rsp = {
             .x = {
-                0x73, 0xc8, 0x44, 0x6e, 0x5b, 0x5e, 0xd4, 0xcf,
-                0x78, 0x2e, 0xba, 0xb8, 0x32, 0xc5, 0x07, 0xc8,
-                0xec, 0xf9, 0xcf, 0x05, 0xde, 0xa3, 0xe3, 0x32,
-                0x57, 0x5e, 0xb8, 0x69, 0x8a, 0x49, 0xe3, 0x0b
+                0xb9, 0x1d, 0xc1, 0xe5, 0x64, 0x0c, 0xcb, 0xdb,
+                0xc8, 0xbd, 0x00, 0x60, 0xca, 0x08, 0x80, 0x20,
+                0xb6, 0x22, 0x04, 0xb8, 0xd6, 0x33, 0x80, 0x8a,
+                0xda, 0x9a, 0x65, 0x98, 0x27, 0x59, 0x48, 0x56,
             },
             .y = {
-                0x71, 0x54, 0xa0, 0x0c, 0x18, 0x03, 0x4b, 0x11,
-                0x0b, 0xdc, 0xdf, 0x89, 0x9a, 0x24, 0x9e, 0x75,
-                0xbf, 0xff, 0xd7, 0xf8, 0x45, 0xcb, 0x3c, 0xdc,
-                0xfc, 0x2d, 0x3c, 0x54, 0x36, 0x29, 0x04, 0xc4
+                0x24, 0xfc, 0x92, 0x11, 0x14, 0xee, 0x44, 0x2a,
+                0x91, 0x11, 0x18, 0x13, 0xed, 0xf2, 0x83, 0xd0,
+                0x81, 0x1a, 0xaa, 0x23, 0x0c, 0x12, 0x80, 0x96,
+                0xb6, 0x32, 0x1a, 0x56, 0xd5, 0x86, 0x8e, 0x20,
             },
         },
-
         .confirm_req[0] = {
             .value = {
-                0x5f, 0x5b, 0x6a, 0x61, 0x93, 0xc3, 0x28, 0x09,
-                0x82, 0x4d, 0xb8, 0x43, 0x23, 0x1a, 0x06, 0x5d,
+                0xf8, 0xd7, 0x8b, 0xd1, 0xc3, 0x8e, 0xda, 0xb1,
+                0xbd, 0x0a, 0xa8, 0x2f, 0xa5, 0x0e, 0x31, 0x1e,
             },
         },
         .confirm_rsp[0] = {
             .value = {
-                0xcc, 0xc0, 0xe7, 0x5b, 0x67, 0x4b, 0xca, 0x19,
-                0xa6, 0xa2, 0x88, 0x8b, 0xc0, 0x16, 0x28, 0x6b,
+                0x62, 0x90, 0x2e, 0x53, 0x50, 0x49, 0xdc, 0x15,
+                0x23, 0x32, 0x94, 0xaa, 0x1d, 0x47, 0x92, 0x1b,
             },
         },
         .random_req[0] = {
             .value = {
-                0xf6, 0x6c, 0xba, 0x43, 0x1e, 0xfd, 0xed, 0x6d,
-                0x11, 0xa3, 0xd5, 0x94, 0xeb, 0x69, 0xe6, 0x4a,
+                0xa9, 0x17, 0xb6, 0x2c, 0xa9, 0x60, 0x57, 0x95,
+                0x00, 0x9d, 0x91, 0x60, 0xb3, 0x3d, 0x66, 0x8a,
             },
         },
         .random_rsp[0] = {
             .value = {
-                0x57, 0xe2, 0x16, 0x9d, 0x9a, 0xec, 0x96, 0xa4,
-                0xfc, 0xd0, 0x5b, 0xc1, 0x3d, 0xc8, 0x69, 0x08,
+                0x29, 0xf4, 0x38, 0xc7, 0x15, 0xf1, 0x2c, 0x93,
+                0x3b, 0x62, 0x1a, 0xd3, 0x02, 0xdc, 0xa0, 0x16,
             },
         },
         .confirm_req[1] = {
             .value = {
-                0xb9, 0x58, 0x47, 0xc2, 0xf9, 0xf4, 0x1a, 0xb3,
-                0x4d, 0xd9, 0x0d, 0x98, 0x26, 0x51, 0xa6, 0x08,
+                0xda, 0xd4, 0xe3, 0xd6, 0x05, 0x04, 0xce, 0x13,
+                0xec, 0x45, 0xc5, 0x07, 0x76, 0xaf, 0x99, 0x6a,
             },
         },
         .confirm_rsp[1] = {
             .value = {
-                0xbb, 0x93, 0x6e, 0xbb, 0x82, 0xb2, 0x9f, 0x20,
-                0x56, 0x66, 0xd5, 0x12, 0xa2, 0x4c, 0x14, 0x4f,
+                0xb8, 0x30, 0x8f, 0x9b, 0xda, 0xb0, 0x83, 0x0e,
+                0x9d, 0x51, 0xd0, 0xd2, 0x01, 0xf8, 0xca, 0xee,
             },
         },
         .random_req[1] = {
             .value = {
-                0x8e, 0xeb, 0x53, 0xf5, 0x7b, 0x80, 0x4e, 0x54,
-                0xbe, 0x54, 0xa1, 0xca, 0x3a, 0x3b, 0xec, 0xdb,
+                0xf9, 0x53, 0xa9, 0xa8, 0xf5, 0x3c, 0x82, 0x4d,
+                0x20, 0x0f, 0x4a, 0xa9, 0x93, 0xcf, 0xeb, 0x53,
             },
         },
         .random_rsp[1] = {
             .value = {
-                0xc5, 0xb3, 0xbf, 0x5d, 0x5a, 0xd0, 0xb9, 0xe3,
-                0x3d, 0xc4, 0x20, 0x9b, 0x51, 0x2a, 0x66, 0xcc,
+                0xa3, 0xe1, 0x17, 0x79, 0x15, 0x46, 0x76, 0x2d,
+                0x08, 0xf5, 0x87, 0x23, 0x01, 0xe8, 0x17, 0xf7,
             },
         },
         .confirm_req[2] = {
             .value = {
-                0x8c, 0xf2, 0x30, 0xb1, 0x36, 0x09, 0xa6, 0x97,
-                0xea, 0xd1, 0x62, 0x26, 0x6c, 0xce, 0x11, 0xee,
+                0xf0, 0x60, 0x26, 0x3c, 0x9f, 0x1a, 0x47, 0xa8,
+                0xf5, 0xbd, 0x6d, 0xae, 0x82, 0xa4, 0x69, 0xe5,
             },
         },
         .confirm_rsp[2] = {
             .value = {
-                0x23, 0x4b, 0xb6, 0x4a, 0x96, 0xea, 0x19, 0xdd,
-                0xff, 0xe2, 0xad, 0x19, 0x39, 0x64, 0x4c, 0xe8,
+                0x53, 0xda, 0xca, 0xcd, 0x4d, 0x4d, 0x79, 0x23,
+                0x3d, 0xa5, 0xcb, 0x22, 0x92, 0x91, 0xe4, 0x71,
             },
         },
         .random_req[2] = {
             .value = {
-                0x27, 0x7e, 0xe8, 0x09, 0x66, 0x0a, 0xef, 0xf0,
-                0x46, 0x24, 0x81, 0xd4, 0x03, 0x9d, 0x31, 0x92,
+                0xfd, 0xc6, 0x66, 0x9d, 0x46, 0x0d, 0xa8, 0x6c,
+                0x0a, 0xe8, 0x0b, 0xf7, 0x43, 0x22, 0x8e, 0x0d,
             },
         },
         .random_rsp[2] = {
             .value = {
-                0x56, 0xa8, 0x6c, 0x25, 0xfb, 0xab, 0xc4, 0x14,
-                0xdb, 0xd6, 0x85, 0x41, 0x73, 0x49, 0xc7, 0x0c,
+                0x1a, 0xcf, 0x1e, 0x2c, 0x2b, 0x5e, 0xc4, 0x70,
+                0x93, 0xde, 0x49, 0x2b, 0x0b, 0x9c, 0x59, 0x6f,
             },
         },
         .confirm_req[3] = {
             .value = {
-                0x3d, 0xda, 0xaa, 0xed, 0x76, 0xaf, 0xb2, 0xbd,
-                0x58, 0x6b, 0x1a, 0xe7, 0x3a, 0x3d, 0xc1, 0x74,
+                0x28, 0x07, 0x48, 0x38, 0xc5, 0x10, 0x04, 0x07,
+                0x29, 0xad, 0x46, 0x9a, 0xd0, 0x40, 0xff, 0xa3,
             },
         },
         .confirm_rsp[3] = {
             .value = {
-                0x99, 0xcd, 0xfe, 0xb6, 0x8f, 0xc5, 0x94, 0x6d,
-                0x94, 0xdb, 0x69, 0x2a, 0x2b, 0xa5, 0x31, 0xea,
+                0xc3, 0x05, 0x43, 0xa6, 0x1e, 0xf7, 0xec, 0x2b,
+                0xa3, 0x78, 0x28, 0x7f, 0x00, 0x8b, 0x0e, 0x93,
             },
         },
         .random_req[3] = {
             .value = {
-                0xa9, 0xf6, 0x19, 0xe0, 0xbc, 0xbd, 0xf7, 0x74,
-                0x2c, 0x37, 0x69, 0x43, 0x20, 0x5e, 0xe7, 0xd1,
+                0xd3, 0x47, 0x73, 0xb0, 0x3b, 0x14, 0x5d, 0x02,
+                0x8e, 0xa2, 0xdd, 0x73, 0x9c, 0x61, 0xde, 0x39,
             },
         },
         .random_rsp[3] = {
             .value = {
-                0x2a, 0xd0, 0x4c, 0x99, 0xf8, 0xa7, 0x0a, 0x57,
-                0xa2, 0xb6, 0x6f, 0x48, 0x59, 0xc1, 0x8f, 0xec,
+                0x38, 0x73, 0x05, 0x1b, 0x88, 0xf0, 0x08, 0x43,
+                0xac, 0x11, 0x00, 0x93, 0x40, 0x44, 0xa1, 0xa5,
             },
         },
         .confirm_req[4] = {
             .value = {
-                0xd4, 0x5d, 0xfa, 0xda, 0xc6, 0x48, 0x43, 0x54,
-                0x0f, 0x7b, 0xfa, 0x83, 0x56, 0x8d, 0x92, 0xff,
+                0x5c, 0x8b, 0x2d, 0x5d, 0xb3, 0x09, 0xd9, 0x70,
+                0x2f, 0x30, 0x89, 0x7a, 0xfd, 0xe9, 0x25, 0x41,
             },
         },
         .confirm_rsp[4] = {
             .value = {
-                0xb4, 0xc1, 0x32, 0x08, 0x28, 0xd4, 0x39, 0xef,
-                0x83, 0x20, 0x7c, 0xa6, 0x9d, 0x2a, 0x40, 0x98,
+                0xf2, 0x3d, 0x0d, 0x14, 0x8f, 0x0a, 0xed, 0x83,
+                0x87, 0xcf, 0x1b, 0xda, 0x57, 0x91, 0x45, 0xb0,
             },
         },
         .random_req[4] = {
             .value = {
-                0x7b, 0x5d, 0x1b, 0x08, 0x3b, 0xef, 0x26, 0x05,
-                0x74, 0x86, 0x83, 0x71, 0x2e, 0x09, 0x70, 0x15,
+                0xae, 0xc4, 0x19, 0x5e, 0xd3, 0xae, 0x04, 0x4a,
+                0xf1, 0xdd, 0x6b, 0x93, 0xa3, 0x30, 0x39, 0x15,
             },
         },
         .random_rsp[4] = {
             .value = {
-                0x14, 0x63, 0x16, 0xbb, 0x62, 0x0d, 0x34, 0xaa,
-       

<TRUNCATED>


[11/50] [abbrv] incubator-mynewt-core git commit: Forget to initialize rxadd properly if directed advertising

Posted by cc...@apache.org.
Forget to initialize rxadd properly if directed advertising


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

Branch: refs/heads/develop
Commit: e03ce5ed696853e76205d4d1190e36fbbe3f9cc1
Parents: eb17794
Author: William San Filippo <wi...@runtime.io>
Authored: Tue Jun 7 17:38:10 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:34 2016 -0700

----------------------------------------------------------------------
 net/nimble/controller/src/ble_ll_adv.c | 5 +++++
 1 file changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e03ce5ed/net/nimble/controller/src/ble_ll_adv.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_adv.c b/net/nimble/controller/src/ble_ll_adv.c
index 6b92572..1f43a5d 100644
--- a/net/nimble/controller/src/ble_ll_adv.c
+++ b/net/nimble/controller/src/ble_ll_adv.c
@@ -688,6 +688,11 @@ ble_ll_adv_sm_start(struct ble_ll_adv_sm *advsm)
 
     if (advsm->adv_directed) {
         memcpy(advsm->initiator_addr, advsm->peer_addr, BLE_DEV_ADDR_LEN);
+        if (advsm->peer_addr_type & 1) {
+            advsm->adv_rxadd = 1;
+        } else {
+            advsm->adv_rxadd = 0;
+        }
     }
 
     /* This will generate an RPA for both initiator addr and adva */


[46/50] [abbrv] incubator-mynewt-core git commit: bletiny - Separate pairing from encryption.

Posted by cc...@apache.org.
bletiny - Separate pairing from encryption.


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

Branch: refs/heads/develop
Commit: ed9fea61fcaea134383aa3a76b48a19f1804a90d
Parents: 67f0192
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 14 16:19:39 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:24:38 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/cmd.c                 |  7 ++++++-
 apps/bletiny/src/main.c                |  2 +-
 net/nimble/host/include/host/ble_gap.h |  6 +++---
 net/nimble/host/src/ble_gap.c          | 10 ++++++++++
 4 files changed, 20 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ed9fea61/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 3ac8592..fc05aa2 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -388,7 +388,12 @@ cmd_conn(int argc, char **argv)
     }
 
     if (addr_type != BLE_GAP_ADDR_TYPE_WL) {
-        rc = parse_arg_mac("addr", peer_addr);
+        rc = parse_arg_mac("peer_addr", peer_addr);
+        if (rc == ENOENT) {
+            /* Allow "addr" for backwards compatibility. */
+            rc = parse_arg_mac("addr", peer_addr);
+        }
+
         if (rc != 0) {
             return rc;
         }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ed9fea61/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index ad55e68..5b71700 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -1359,7 +1359,7 @@ bletiny_sec_pair(uint16_t conn_handle)
 
     int rc;
 
-    rc = ble_sm_pair_initiate(conn_handle);
+    rc = ble_gap_pair_initiate(conn_handle);
     return rc;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ed9fea61/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index 0b150dd..ba442d1 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -268,9 +268,9 @@ int ble_gap_wl_set(struct ble_gap_white_entry *white_list,
 int ble_gap_update_params(uint16_t conn_handle,
                           struct ble_gap_upd_params *params);
 int ble_gap_security_initiate(uint16_t conn_handle);
-int
-ble_gap_encryption_initiate(uint16_t conn_handle, uint8_t *ltk,
-                            uint16_t ediv, uint64_t rand_val, int auth);
+int ble_gap_pair_initiate(uint16_t conn_handle);
+int ble_gap_encryption_initiate(uint16_t conn_handle, uint8_t *ltk,
+                                uint16_t ediv, uint64_t rand_val, int auth);
 int ble_gap_provide_ltk(uint16_t conn_handle, uint8_t *ltk);
 void ble_gap_init_identity_addr(uint8_t *addr);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ed9fea61/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 a0fb13c..3e9a0de 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -2157,6 +2157,16 @@ ble_gap_security_initiate(uint16_t conn_handle)
 }
 
 int
+ble_gap_pair_initiate(uint16_t conn_handle)
+{
+    int rc;
+
+    rc = ble_sm_pair_initiate(conn_handle);
+
+    return rc;
+}
+
+int
 ble_gap_encryption_initiate(uint16_t conn_handle,
                             uint8_t *ltk,
                             uint16_t ediv,


[29/50] [abbrv] incubator-mynewt-core git commit: bletiny - Remove extraneous newlines in logs.

Posted by cc...@apache.org.
bletiny - Remove extraneous newlines in logs.


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

Branch: refs/heads/develop
Commit: 91a1b0f6f73c7a35e62455137b0d6c05fb80dc16
Parents: ca28041
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jun 10 09:59:55 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:39 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/main.c | 3 ---
 1 file changed, 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/91a1b0f6/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index 9fdf9bf..6e09b88 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -905,7 +905,6 @@ bletiny_gap_event(int event, struct ble_gap_conn_ctxt *ctxt, void *arg)
     case BLE_GAP_EVENT_DISCONNECT:
         console_printf("disconnect; reason=%d ", ctxt->disconnect.reason);
         print_conn_desc(ctxt->desc);
-        console_printf("\n");
 
         conn_idx = bletiny_conn_find_idx(ctxt->desc->conn_handle);
         if (conn_idx != -1) {
@@ -921,7 +920,6 @@ bletiny_gap_event(int event, struct ble_gap_conn_ctxt *ctxt, void *arg)
         console_printf("connection updated; status=%d ",
                        ctxt->conn_update.status);
         print_conn_desc(ctxt->desc);
-        console_printf("\n");
         return 0;
 
     case BLE_GAP_EVENT_CONN_UPDATE_REQ:
@@ -944,7 +942,6 @@ bletiny_gap_event(int event, struct ble_gap_conn_ctxt *ctxt, void *arg)
         console_printf("encryption change event; status=%d ",
                        ctxt->enc_change.status);
         print_conn_desc(ctxt->desc);
-        console_printf("\n");
         return 0;
 
     case BLE_GAP_EVENT_NOTIFY:


[20/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Fix wrong peer addr type in ltk req rx.

Posted by cc...@apache.org.
BLE Host - Fix wrong peer addr type in ltk req rx.


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

Branch: refs/heads/develop
Commit: d986a276f6210700ba96c6a426a5a7e767e0dcb1
Parents: 60e0453
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 8 09:36:27 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:35 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/misc.c                |  8 +++++---
 net/nimble/host/include/host/ble_gap.h |  2 ++
 net/nimble/host/src/ble_gap.c          |  3 ++-
 net/nimble/host/src/ble_sm.c           | 13 ++++++++++---
 4 files changed, 19 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d986a276/apps/bletiny/src/misc.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/misc.c b/apps/bletiny/src/misc.c
index ecfcd9a..83c28cd 100644
--- a/apps/bletiny/src/misc.c
+++ b/apps/bletiny/src/misc.c
@@ -96,9 +96,11 @@ chr_is_empty(struct bletiny_svc *svc, struct bletiny_chr *chr)
 void
 print_conn_desc(struct ble_gap_conn_desc *desc)
 {
-    console_printf("handle=%d peer_ota_addr_type=%d "
-                   "peer_ota_addr=",
-                   desc->conn_handle, desc->peer_ota_addr_type);
+    console_printf("handle=%d our_ota_addr_type=%d our_ota_addr=",
+                   desc->conn_handle, desc->our_ota_addr_type);
+    print_addr(desc->our_ota_addr);
+    console_printf(" peer_ota_addr_type=%d peer_ota_addr=",
+                   desc->peer_ota_addr_type);
     print_addr(desc->peer_ota_addr);
     console_printf(" peer_id_addr_type=%d peer_id_addr=",
                    desc->peer_id_addr_type);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d986a276/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index faa8f92..4542cdb 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -121,12 +121,14 @@ struct ble_gap_conn_desc {
     struct ble_gap_sec_state sec_state;
     uint8_t peer_ota_addr[6];
     uint8_t peer_id_addr[6];
+    uint8_t our_ota_addr[6];
     uint16_t conn_handle;
     uint16_t conn_itvl;
     uint16_t conn_latency;
     uint16_t supervision_timeout;
     uint8_t peer_ota_addr_type;
     uint8_t peer_id_addr_type;
+    uint8_t our_ota_addr_type;
 };
 
 struct ble_gap_crt_params {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d986a276/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 a2c007a..d3a07e1 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -278,7 +278,7 @@ ble_gap_fill_conn_desc(struct ble_hs_conn *conn,
     uint8_t *our_ota_addr;
 
     ble_hs_conn_addrs(conn,
-                      NULL, &our_ota_addr,
+                      &desc->our_ota_addr_type, &our_ota_addr,
                       NULL, NULL,
                       &desc->peer_ota_addr_type, &peer_ota_addr,
                       &desc->peer_id_addr_type, &peer_id_addr);
@@ -286,6 +286,7 @@ ble_gap_fill_conn_desc(struct ble_hs_conn *conn,
     desc->conn_handle = conn->bhc_handle;
     memcpy(desc->peer_ota_addr, peer_ota_addr, 6);
     memcpy(desc->peer_id_addr, peer_id_addr, 6);
+    memcpy(desc->our_ota_addr, our_ota_addr, 6);
     desc->conn_itvl = conn->bhc_itvl;
     desc->conn_latency = conn->bhc_latency;
     desc->supervision_timeout = conn->bhc_supervision_timeout;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d986a276/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 68c0c0d..3c8f1b3 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -1189,6 +1189,7 @@ ble_sm_ltk_req_rx(struct hci_le_lt_key_req *evt)
     int store_rc;
     int bonding;
     uint8_t peer_addr[6];
+    uint8_t *peer_id_addr;
     uint8_t peer_addr_type;
 
     /* Silence gcc warning. */
@@ -1238,8 +1239,10 @@ ble_sm_ltk_req_rx(struct hci_le_lt_key_req *evt)
         if (conn == NULL) {
             res.app_status = BLE_HS_ENOTCONN;
         } else {
-            peer_addr_type = conn->bhc_addr_type;
-            memcpy(peer_addr, conn->bhc_addr, 6);
+            ble_hs_conn_addrs(conn,
+                              NULL, NULL, NULL, NULL,
+                              NULL, NULL, &peer_addr_type, &peer_id_addr);
+            memcpy(peer_addr, peer_id_addr, 6);
         }
     }
 
@@ -1638,6 +1641,7 @@ ble_sm_sec_req_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
     struct ble_store_value_sec value_sec;
     struct ble_store_key_sec key_sec;
     struct ble_hs_conn *conn;
+    uint8_t *peer_id_addr;
     int authreq_mitm;
 
     res->app_status = ble_hs_misc_pullup_base(om, BLE_SM_SEC_REQ_SZ);
@@ -1666,9 +1670,12 @@ ble_sm_sec_req_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
          * sender; remember the sender's address while the connection list is
          * locked.
          */
+        ble_hs_conn_addrs(conn,
+                          NULL, NULL, NULL, NULL,
+                          NULL, NULL, &key_sec.peer_addr_type, &peer_id_addr);
         memset(&key_sec, 0, sizeof key_sec);
         key_sec.peer_addr_type = conn->bhc_addr_type;
-        memcpy(key_sec.peer_addr, conn->bhc_addr, 6);
+        memcpy(key_sec.peer_addr, peer_id_addr, 6);
     }
 
     ble_hs_unlock();


[33/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Persist keys if both sides want bonding

Posted by cc...@apache.org.
BLE Host - Persist keys if both sides want bonding


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

Branch: refs/heads/develop
Commit: 24cd9ab92ea33cfcf87df2ac35580d85be09dd60
Parents: 18bd234
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Jun 10 10:06:08 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:39 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm.c      | 23 ++++++++++++++---------
 net/nimble/host/src/ble_sm_priv.h |  5 +++--
 2 files changed, 17 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24cd9ab9/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 4c93110..8c57c3d 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -587,7 +587,6 @@ ble_sm_persist_keys(struct ble_sm_proc *proc)
 
     authenticated = proc->flags & BLE_SM_PROC_F_AUTHENTICATED;
 
-    proc->our_keys.irk_valid = 0;
     ble_sm_fill_store_value(peer_addr_type, peer_addr, authenticated,
                             &proc->our_keys, &value_sec);
     ble_store_write_slv_sec(&value_sec);
@@ -847,9 +846,11 @@ ble_sm_process_result(uint16_t conn_handle, struct ble_sm_result *res)
             ble_gap_passkey_event(conn_handle, &res->passkey_action);
         }
 
-        /* Persist keys if pairing has successfully completed. */
-        if (res->app_status == 0 && rm) {
-            BLE_HS_DBG_ASSERT(rm);
+        /* Persist keys if bonding has successfully completed. */
+        if (res->app_status == 0    &&
+            rm                      &&
+            proc->flags & BLE_SM_PROC_F_BONDING) {
+
             ble_sm_persist_keys(proc);
         }
 
@@ -1417,11 +1418,14 @@ ble_sm_pair_cfg(struct ble_sm_proc *proc)
         proc->flags |= BLE_SM_PROC_F_SC;
     }
 
-    ble_sm_key_dist(proc, &init_key_dist, &resp_key_dist);
     if (proc->pair_req.authreq & BLE_SM_PAIR_AUTHREQ_BOND &&
-        proc->pair_rsp.authreq & BLE_SM_PAIR_AUTHREQ_BOND &&
-        (init_key_dist != 0 || resp_key_dist != 0)) {
+        proc->pair_rsp.authreq & BLE_SM_PAIR_AUTHREQ_BOND) {
+
+        proc->flags |= BLE_SM_PROC_F_BONDING;
+    }
 
+    ble_sm_key_dist(proc, &init_key_dist, &resp_key_dist);
+    if (init_key_dist != 0 || resp_key_dist != 0) {
         proc->flags |= BLE_SM_PROC_F_KEY_EXCHANGE;
     }
 
@@ -1794,7 +1798,6 @@ ble_sm_key_exch_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
         }
 
         /* copy data to pass to application */
-        proc->our_keys.irk_valid = 1;
         proc->our_keys.addr_valid = 1;
         memcpy(proc->our_keys.irk, irk, 16);
         proc->our_keys.addr_type = addr_info.addr_type;
@@ -1946,7 +1949,9 @@ ble_sm_id_info_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
     } else {
         proc->rx_key_flags &= ~BLE_SM_KE_F_ID_INFO;
         proc->peer_keys.irk_valid = 1;
-        memcpy(proc->peer_keys.irk, cmd.irk, 16);
+
+        /* Store IRK in little endian. */
+        swap_buf(proc->peer_keys.irk, cmd.irk, 16);
 
         ble_sm_key_rxed(proc, res);
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24cd9ab9/net/nimble/host/src/ble_sm_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_priv.h b/net/nimble/host/src/ble_sm_priv.h
index fe5308e..d19f43f 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -219,6 +219,7 @@ struct ble_sm_dhkey_check {
 #define BLE_SM_PROC_F_AUTHENTICATED         0x08
 #define BLE_SM_PROC_F_KEY_EXCHANGE          0x10
 #define BLE_SM_PROC_F_SC                    0x20
+#define BLE_SM_PROC_F_BONDING               0x40
 
 #define BLE_SM_KE_F_ENC_INFO                0x01
 #define BLE_SM_KE_F_MASTER_ID               0x02
@@ -237,8 +238,8 @@ struct ble_sm_keys {
     uint16_t ediv;
     uint64_t rand_val;
     uint8_t addr_type;
-    uint8_t ltk[16];
-    uint8_t irk[16];
+    uint8_t ltk[16];    /* Little endian. */
+    uint8_t irk[16];    /* Little endian. */
     uint8_t csrk[16];
     uint8_t addr[6];
 };


[32/50] [abbrv] incubator-mynewt-core git commit: BLE Host - SM; remove obsolete KEY_EXCH flag.

Posted by cc...@apache.org.
BLE Host - SM; remove obsolete KEY_EXCH flag.


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

Branch: refs/heads/develop
Commit: fb4b6cdaa1b4099089fc53d5cfa8d3968456bec6
Parents: c72b6b4
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jun 9 19:56:00 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:39 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm.c      | 20 ++++++--------------
 net/nimble/host/src/ble_sm_cmd.c  |  4 ++--
 net/nimble/host/src/ble_sm_priv.h |  5 ++---
 3 files changed, 10 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fb4b6cda/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 8c57c3d..6027f50 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -960,7 +960,7 @@ ble_sm_enc_event_rx(uint16_t conn_handle, uint8_t evt_status, int encrypted)
             /* We are completing a pairing procedure; keys may need to be
              * exchanged.
              */
-            if (evt_status == 0 && proc->flags & BLE_SM_PROC_F_KEY_EXCHANGE) {
+            if (evt_status == 0) {
                 /* If the responder has any keys to send, it sends them
                  * first.
                  */
@@ -984,7 +984,7 @@ ble_sm_enc_event_rx(uint16_t conn_handle, uint8_t evt_status, int encrypted)
              * procedure.  Keys were exchanged during pairing; they don't
              * get exchanged again now.  Procedure is complete.
              */
-            BLE_HS_DBG_ASSERT(!(proc->flags & BLE_SM_PROC_F_KEY_EXCHANGE));
+            BLE_HS_DBG_ASSERT(proc->rx_key_flags == 0);
             proc->state = BLE_SM_PROC_STATE_NONE;
             if (proc->flags & BLE_SM_PROC_F_AUTHENTICATED) {
                 authenticated = 1;
@@ -1425,10 +1425,6 @@ ble_sm_pair_cfg(struct ble_sm_proc *proc)
     }
 
     ble_sm_key_dist(proc, &init_key_dist, &resp_key_dist);
-    if (init_key_dist != 0 || resp_key_dist != 0) {
-        proc->flags |= BLE_SM_PROC_F_KEY_EXCHANGE;
-    }
-
     if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
         rx_key_dist = resp_key_dist;
     } else {
@@ -1436,7 +1432,6 @@ ble_sm_pair_cfg(struct ble_sm_proc *proc)
     }
 
     proc->rx_key_flags = 0;
-
     if (rx_key_dist & BLE_SM_PAIR_KEY_DIST_ENC) {
         proc->rx_key_flags |= BLE_SM_KE_F_ENC_INFO |
                               BLE_SM_KE_F_MASTER_ID;
@@ -1735,6 +1730,7 @@ ble_sm_key_exch_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
     uint8_t init_key_dist;
     uint8_t resp_key_dist;
     uint8_t our_key_dist;
+    uint8_t *irk;
     int rc;
 
     ble_sm_key_dist(proc, &init_key_dist, &resp_key_dist);
@@ -1744,10 +1740,6 @@ ble_sm_key_exch_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
         our_key_dist = resp_key_dist;
     }
 
-    if (our_key_dist == 0) {
-        return;
-    }
-
     if (our_key_dist & BLE_SM_PAIR_KEY_DIST_ENC) {
         /* Send encryption information. */
         rc = ble_sm_gen_ltk(proc, enc_info.ltk);
@@ -1781,7 +1773,7 @@ ble_sm_key_exch_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
 
     if (our_key_dist & BLE_SM_PAIR_KEY_DIST_ID) {
         /* Send identity information. */
-        uint8_t *irk = ble_hs_priv_get_local_irk();
+        irk = ble_hs_priv_get_local_irk();
 
         memcpy(iden_info.irk, irk, 16);
 
@@ -1790,6 +1782,7 @@ ble_sm_key_exch_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
             goto err;
         }
 
+        /* Send identity address information. */
         bls_hs_priv_copy_local_identity_addr(addr_info.bd_addr,
                                              &addr_info.addr_type);
         rc = ble_sm_id_addr_info_tx(proc->conn_handle, &addr_info);
@@ -1797,7 +1790,6 @@ ble_sm_key_exch_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
             goto err;
         }
 
-        /* copy data to pass to application */
         proc->our_keys.addr_valid = 1;
         memcpy(proc->our_keys.irk, irk, 16);
         proc->our_keys.addr_type = addr_info.addr_type;
@@ -1818,7 +1810,7 @@ ble_sm_key_exch_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
         memcpy(proc->our_keys.csrk, sign_info.sig_key, 16);
     }
 
-    if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
+    if (proc->flags & BLE_SM_PROC_F_INITIATOR || proc->rx_key_flags == 0) {
         /* The procedure is now complete. */
         ble_sm_key_exch_success(proc, res);
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fb4b6cda/net/nimble/host/src/ble_sm_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_cmd.c b/net/nimble/host/src/ble_sm_cmd.c
index 1d6ce31..40dfc79 100644
--- a/net/nimble/host/src/ble_sm_cmd.c
+++ b/net/nimble/host/src/ble_sm_cmd.c
@@ -440,7 +440,7 @@ ble_sm_id_info_tx(uint16_t conn_handle, struct ble_sm_id_info *cmd)
     }
 
     txom->om_data[0] = BLE_SM_OP_IDENTITY_INFO;
-    memcpy(txom->om_data + 1, cmd->irk, sizeof cmd->irk);
+    swap_buf(txom->om_data + 1, cmd->irk, sizeof cmd->irk);
 
     BLE_SM_LOG_CMD(1, "id info", conn_handle, ble_sm_id_info_log, cmd);
 
@@ -461,7 +461,7 @@ ble_sm_id_info_log(struct ble_sm_id_info *cmd)
 
 void
 ble_sm_id_addr_info_parse(void *payload, int len,
-                       struct ble_sm_id_addr_info *cmd)
+                          struct ble_sm_id_addr_info *cmd)
 {
     uint8_t *u8ptr = payload;
     cmd->addr_type = *u8ptr;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/fb4b6cda/net/nimble/host/src/ble_sm_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_priv.h b/net/nimble/host/src/ble_sm_priv.h
index d19f43f..cda5cce 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -217,9 +217,8 @@ struct ble_sm_dhkey_check {
 #define BLE_SM_PROC_F_IO_INJECTED           0x02
 #define BLE_SM_PROC_F_ADVANCE_ON_IO         0x04
 #define BLE_SM_PROC_F_AUTHENTICATED         0x08
-#define BLE_SM_PROC_F_KEY_EXCHANGE          0x10
-#define BLE_SM_PROC_F_SC                    0x20
-#define BLE_SM_PROC_F_BONDING               0x40
+#define BLE_SM_PROC_F_SC                    0x10
+#define BLE_SM_PROC_F_BONDING               0x20
 
 #define BLE_SM_KE_F_ENC_INFO                0x01
 #define BLE_SM_KE_F_MASTER_ID               0x02


[05/50] [abbrv] incubator-mynewt-core git commit: BLE Host - include both addresses in conn desc.

Posted by cc...@apache.org.
BLE Host - include both addresses in conn desc.

Previous to this change, the connection descriptor returned by the GAP
only contained the peer identity address.  Now it contains both the
peer's effective address and identity address, as well as the local
effective address.


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

Branch: refs/heads/develop
Commit: c589590065e8f04ca75f4a0503642ee61f798a17
Parents: e03ce5e
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 8 08:18:23 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:34 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/bletiny.h                  |  5 +--
 apps/bletiny/src/cmd.c                      | 21 ++++++---
 apps/bletiny/src/main.c                     | 56 ++++--------------------
 apps/bletiny/src/misc.c                     | 21 +++++++++
 net/nimble/host/include/host/ble_gap.h      |  6 ++-
 net/nimble/host/src/ble_gap.c               | 14 +++++-
 net/nimble/host/src/test/ble_gap_test.c     | 30 ++++++-------
 net/nimble/host/src/test/ble_hs_test_util.c |  2 +
 net/nimble/host/src/test/ble_os_test.c      |  4 +-
 9 files changed, 81 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c5895900/apps/bletiny/src/bletiny.h
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/bletiny.h b/apps/bletiny/src/bletiny.h
index 6ca6d77..b66a301 100644
--- a/apps/bletiny/src/bletiny.h
+++ b/apps/bletiny/src/bletiny.h
@@ -36,6 +36,7 @@ struct ble_l2cap_sig_update_params;
 union ble_store_value;
 union ble_store_key;
 struct ble_gap_adv_params;
+struct ble_gap_conn_desc;
 
 typedef int cmd_fn(int argc, char **argv);
 struct cmd_entry {
@@ -73,9 +74,6 @@ SLIST_HEAD(bletiny_svc_list, bletiny_svc);
 
 struct bletiny_conn {
     uint16_t handle;
-    uint8_t addr_type;
-    uint8_t addr[6];
-
     struct bletiny_svc_list svcs;
 };
 
@@ -206,5 +204,6 @@ void print_bytes(uint8_t *bytes, int len);
 int svc_is_empty(struct bletiny_svc *svc);
 uint16_t chr_end_handle(struct bletiny_svc *svc, struct bletiny_chr *chr);
 int chr_is_empty(struct bletiny_svc *svc, struct bletiny_chr *chr);
+void print_conn_desc(struct ble_gap_conn_desc *desc);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c5895900/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 9a3fe14..4dbdcc5 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -945,7 +945,13 @@ cmd_scan(int argc, char **argv)
 static int
 cmd_show_addr(int argc, char **argv)
 {
-    print_addr(g_dev_addr);
+    uint8_t *id_addr;
+    uint8_t id_addr_type;
+
+    id_addr = bls_hs_priv_get_local_identity_addr(&id_addr_type);
+
+    console_printf("id_addr_type=%d id_addr=", id_addr_type);
+    print_addr(id_addr);
     console_printf("\n");
 
     return 0;
@@ -961,9 +967,7 @@ cmd_show_chr(int argc, char **argv)
     for (i = 0; i < bletiny_num_conns; i++) {
         conn = bletiny_conns + i;
 
-        console_printf("CONNECTION: handle=%d addr=", conn->handle);
-        print_addr(conn->addr);
-        console_printf("\n");
+        console_printf("CONNECTION: handle=%d\n", conn->handle);
 
         SLIST_FOREACH(svc, &conn->svcs, next) {
             cmd_print_svc(svc);
@@ -976,15 +980,18 @@ cmd_show_chr(int argc, char **argv)
 static int
 cmd_show_conn(int argc, char **argv)
 {
+    struct ble_gap_conn_desc conn_desc;
     struct bletiny_conn *conn;
+    int rc;
     int i;
 
     for (i = 0; i < bletiny_num_conns; i++) {
         conn = bletiny_conns + i;
 
-        console_printf("handle=%d addr=", conn->handle);
-        print_addr(conn->addr);
-        console_printf(" addr_type=%d\n", conn->addr_type);
+        rc = ble_gap_find_conn(conn->handle, &conn_desc);
+        if (rc == 0) {
+            print_conn_desc(&conn_desc);
+        }
     }
 
     return 0;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c5895900/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index f2cb04e..9fdf9bf 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -160,38 +160,6 @@ bletiny_print_error(char *msg, uint16_t conn_handle,
 }
 
 static void
-bletiny_print_mac(uint8_t *mac) {
-    int i;
-    for (i = 5; i >= 0; i--) {
-        console_printf("%s0x%02x", i != 5 ? ":" : "", mac[i]);
-    }
-}
-
-static void
-bletiny_print_conn_desc(struct ble_gap_conn_desc *desc)
-{
-    console_printf("handle=%d peer_addr_type=%d peer_addr=",
-                   desc->conn_handle, desc->peer_addr_type);
-    bletiny_print_mac(desc->peer_addr);
-    console_printf(" conn_itvl=%d conn_latency=%d supervision_timeout=%d "
-                   "pair_alg=%d enc_enabled=%d authenticated=%d",
-                   desc->conn_itvl, desc->conn_latency,
-                   desc->supervision_timeout,
-                   desc->sec_state.pair_alg,
-                   desc->sec_state.enc_enabled,
-                   desc->sec_state.authenticated);
-}
-
-static void
-bletiny_print_enh_conn_info(struct ble_gap_enhanced_conn *penh)
-{
-    console_printf(" local_rpa ");
-    bletiny_print_mac(penh->local_rpa);
-    console_printf(" peer_rpa ");
-    bletiny_print_mac(penh->peer_rpa);
-}
-
-static void
 bletiny_print_adv_fields(struct ble_hs_adv_fields *fields)
 {
     uint32_t u32;
@@ -288,7 +256,7 @@ bletiny_print_adv_fields(struct ble_hs_adv_fields *fields)
 
     if (fields->le_addr != NULL) {
         console_printf("    le_addr=");
-        bletiny_print_mac(fields->le_addr);
+        print_addr(fields->le_addr);
         console_printf("\n");
     }
 
@@ -675,8 +643,6 @@ bletiny_conn_add(struct ble_gap_conn_desc *desc)
     bletiny_num_conns++;
 
     conn->handle = desc->conn_handle;
-    conn->addr_type = desc->peer_addr_type;
-    memcpy(conn->addr, desc->peer_addr, 6);
     SLIST_INIT(&conn->svcs);
 
     return conn;
@@ -925,15 +891,11 @@ bletiny_gap_event(int event, struct ble_gap_conn_ctxt *ctxt, void *arg)
 
     switch (event) {
     case BLE_GAP_EVENT_CONNECT:
+        
         console_printf("connection %s; status=%d ",
                        ctxt->connect.status == 0 ? "established" : "failed",
                        ctxt->connect.status);
-        bletiny_print_conn_desc(ctxt->desc);
-
-        if (ctxt->connect.status  == 0) {
-            bletiny_print_enh_conn_info(ctxt->connect.enhanced_conn);
-        }
-        console_printf("\n");
+        print_conn_desc(ctxt->desc);
 
         if (ctxt->connect.status == 0) {
             bletiny_conn_add(ctxt->desc);
@@ -942,7 +904,7 @@ bletiny_gap_event(int event, struct ble_gap_conn_ctxt *ctxt, void *arg)
 
     case BLE_GAP_EVENT_DISCONNECT:
         console_printf("disconnect; reason=%d ", ctxt->disconnect.reason);
-        bletiny_print_conn_desc(ctxt->desc);
+        print_conn_desc(ctxt->desc);
         console_printf("\n");
 
         conn_idx = bletiny_conn_find_idx(ctxt->desc->conn_handle);
@@ -958,7 +920,7 @@ bletiny_gap_event(int event, struct ble_gap_conn_ctxt *ctxt, void *arg)
     case BLE_GAP_EVENT_CONN_UPDATE:
         console_printf("connection updated; status=%d ",
                        ctxt->conn_update.status);
-        bletiny_print_conn_desc(ctxt->desc);
+        print_conn_desc(ctxt->desc);
         console_printf("\n");
         return 0;
 
@@ -981,7 +943,7 @@ bletiny_gap_event(int event, struct ble_gap_conn_ctxt *ctxt, void *arg)
     case BLE_GAP_EVENT_ENC_CHANGE:
         console_printf("encryption change event; status=%d ",
                        ctxt->enc_change.status);
-        bletiny_print_conn_desc(ctxt->desc);
+        print_conn_desc(ctxt->desc);
         console_printf("\n");
         return 0;
 
@@ -1013,7 +975,7 @@ bletiny_on_scan(int event, int status, struct ble_gap_disc_desc *desc,
     case BLE_GAP_EVENT_DISC_SUCCESS:
         console_printf("received advertisement; event_type=%d addr_type=%d "
                        "addr=", desc->event_type, desc->addr_type);
-        bletiny_print_mac(desc->addr);
+        print_addr(desc->addr);
         console_printf(" length_data=%d rssi=%d data=", desc->length_data,
                        desc->rssi);
         print_bytes(desc->data, desc->length_data);
@@ -1429,8 +1391,8 @@ bletiny_sec_restart(uint16_t conn_handle,
         }
 
         memset(&key_sec, 0, sizeof key_sec);
-        key_sec.peer_addr_type = desc.peer_addr_type;
-        memcpy(key_sec.peer_addr, desc.peer_addr, 6);
+        key_sec.peer_addr_type = desc.peer_id_addr_type;
+        memcpy(key_sec.peer_addr, desc.peer_id_addr, 6);
 
         rc = ble_hs_atomic_conn_flags(conn_handle, &conn_flags);
         if (rc != 0) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c5895900/apps/bletiny/src/misc.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/misc.c b/apps/bletiny/src/misc.c
index 179c9a7..a96a388 100644
--- a/apps/bletiny/src/misc.c
+++ b/apps/bletiny/src/misc.c
@@ -19,6 +19,7 @@
 
 #include "console/console.h"
 #include "host/ble_uuid.h"
+#include "host/ble_gap.h"
 
 #include "bletiny.h"
 
@@ -91,3 +92,23 @@ chr_is_empty(struct bletiny_svc *svc, struct bletiny_chr *chr)
 {
     return chr_end_handle(svc, chr) <= chr->chr.val_handle;
 }
+
+void
+print_conn_desc(struct ble_gap_conn_desc *desc)
+{
+    console_printf("handle=%d peer_effective_addr_type=%d "
+                   "peer_effective_addr=",
+                   desc->conn_handle, desc->peer_effective_addr_type);
+    print_addr(desc->peer_effective_addr);
+    console_printf(" peer_identity_addr_type=%d peer_identity_addr=",
+                   desc->peer_id_addr_type);
+    print_addr(desc->peer_id_addr);
+    console_printf(" conn_itvl=%d conn_latency=%d supervision_timeout=%d "
+                   "pair_alg=%d enc_enabled=%d authenticated=%d bonded=%d\n",
+                   desc->conn_itvl, desc->conn_latency,
+                   desc->supervision_timeout,
+                   desc->sec_state.pair_alg,
+                   desc->sec_state.enc_enabled,
+                   desc->sec_state.authenticated,
+                   desc->sec_state.bonded);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c5895900/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index c68a957..03f4dcd 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -119,12 +119,14 @@ struct ble_gap_adv_params {
 
 struct ble_gap_conn_desc {
     struct ble_gap_sec_state sec_state;
-    uint8_t peer_addr[6];
+    uint8_t peer_effective_addr[6];
+    uint8_t peer_id_addr[6];
     uint16_t conn_handle;
     uint16_t conn_itvl;
     uint16_t conn_latency;
     uint16_t supervision_timeout;
-    uint8_t peer_addr_type;
+    uint8_t peer_effective_addr_type;
+    uint8_t peer_id_addr_type;
 };
 
 struct ble_gap_crt_params {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c5895900/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 a54042f..dec124a 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -273,9 +273,19 @@ static void
 ble_gap_fill_conn_desc(struct ble_hs_conn *conn,
                        struct ble_gap_conn_desc *desc)
 {
+    uint8_t *peer_effective_addr;
+    uint8_t *peer_id_addr;
+    uint8_t *our_effective_addr;
+
+    ble_hs_conn_addrs(conn,
+                      NULL, &our_effective_addr,
+                      NULL, NULL,
+                      &desc->peer_effective_addr_type, &peer_effective_addr,
+                      &desc->peer_id_addr_type, &peer_id_addr);
+
     desc->conn_handle = conn->bhc_handle;
-    desc->peer_addr_type = conn->bhc_addr_type;
-    memcpy(desc->peer_addr, conn->bhc_addr, sizeof desc->peer_addr);
+    memcpy(desc->peer_effective_addr, peer_effective_addr, 6);
+    memcpy(desc->peer_id_addr, peer_id_addr, 6);
     desc->conn_itvl = conn->bhc_itvl;
     desc->conn_latency = conn->bhc_latency;
     desc->supervision_timeout = conn->bhc_supervision_timeout;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c5895900/net/nimble/host/src/test/ble_gap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gap_test.c b/net/nimble/host/src/test/ble_gap_test.c
index 620c067..7868f2a 100644
--- a/net/nimble/host/src/test/ble_gap_test.c
+++ b/net/nimble/host/src/test/ble_gap_test.c
@@ -706,7 +706,7 @@ TEST_CASE(ble_gap_test_case_conn_dir_good)
 
     TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONNECT);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
-    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr, peer_addr, 6) == 0);
+    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
 
     TEST_ASSERT(ble_hs_atomic_conn_flags(2, NULL) == 0);
 }
@@ -838,7 +838,7 @@ TEST_CASE(ble_gap_test_case_conn_cancel_ctlr_fail)
 
     TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONNECT);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
-    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr,
+    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
                        peer_addr, 6) == 0);
 
     TEST_ASSERT(ble_hs_atomic_conn_flags(2, NULL) == 0);
@@ -909,8 +909,8 @@ TEST_CASE(ble_gap_test_case_conn_terminate_good)
     TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_DISCONNECT);
     TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_ENOTCONN);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
-    TEST_ASSERT(ble_gap_test_conn_desc.peer_addr_type == BLE_ADDR_TYPE_PUBLIC);
-    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr, peer_addr, 6) == 0);
+    TEST_ASSERT(ble_gap_test_conn_desc.peer_id_addr_type == BLE_ADDR_TYPE_PUBLIC);
+    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
     TEST_ASSERT(ble_gap_test_conn_arg == NULL);
 
     TEST_ASSERT(ble_hs_atomic_conn_flags(2, NULL) == BLE_HS_ENOTCONN);
@@ -948,8 +948,8 @@ TEST_CASE(ble_gap_test_case_conn_terminate_ctlr_fail)
     TEST_ASSERT(ble_gap_test_conn_status ==
                 BLE_HS_HCI_ERR(BLE_ERR_UNSUPPORTED));
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
-    TEST_ASSERT(ble_gap_test_conn_desc.peer_addr_type == BLE_ADDR_TYPE_PUBLIC);
-    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr, peer_addr, 6) == 0);
+    TEST_ASSERT(ble_gap_test_conn_desc.peer_id_addr_type == BLE_ADDR_TYPE_PUBLIC);
+    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
     TEST_ASSERT(ble_gap_test_conn_arg == NULL);
 
     TEST_ASSERT(ble_hs_atomic_conn_flags(2, NULL) == 0);
@@ -1128,7 +1128,7 @@ TEST_CASE(ble_gap_test_case_conn_adv_good)
                             BLE_GAP_EVENT_CONNECT);
                 TEST_ASSERT(ble_gap_test_conn_status == 0);
                 TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
-                TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr,
+                TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
                                    peer_addr, 6) == 0);
                 TEST_ASSERT(ble_gap_test_conn_arg == NULL);
             }
@@ -1318,7 +1318,7 @@ ble_gap_test_util_update(struct ble_gap_upd_params *params,
     TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == 0);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
-    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr, peer_addr, 6) == 0);
+    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_itvl == params->itvl_max);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_latency == params->latency);
     TEST_ASSERT(ble_gap_test_conn_desc.supervision_timeout ==
@@ -1332,7 +1332,7 @@ fail:
     TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == status);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
-    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr, peer_addr, 6) == 0);
+    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_itvl ==
                 BLE_GAP_INITIAL_CONN_ITVL_MAX);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_latency ==
@@ -1363,7 +1363,7 @@ ble_gap_test_util_update_peer(uint8_t status,
     TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(status));
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
-    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr,
+    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr,
                        peer_addr, 6) == 0);
 
     if (status == 0) {
@@ -1418,7 +1418,7 @@ ble_gap_test_util_update_req_pos(struct ble_gap_upd_params *peer_params,
     TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == 0);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
-    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr, peer_addr, 6) == 0);
+    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_itvl == self_params->itvl_max);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_latency == self_params->latency);
     TEST_ASSERT(ble_gap_test_conn_desc.supervision_timeout ==
@@ -1430,7 +1430,7 @@ hci_fail:
     TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(hci_status));
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
-    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr, peer_addr, 6) == 0);
+    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_itvl ==
                 BLE_GAP_INITIAL_CONN_ITVL_MAX);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_latency ==
@@ -1479,7 +1479,7 @@ hci_fail:
     TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(hci_status));
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
-    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr, peer_addr, 6) == 0);
+    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_itvl ==
                 BLE_GAP_INITIAL_CONN_ITVL_MAX);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_latency ==
@@ -1554,7 +1554,7 @@ ble_gap_test_util_update_req_concurrent(
     TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == 0);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
-    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr, peer_addr, 6) == 0);
+    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_itvl == self_params->itvl_max);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_latency == self_params->latency);
     TEST_ASSERT(ble_gap_test_conn_desc.supervision_timeout ==
@@ -1566,7 +1566,7 @@ hci_fail:
     TEST_ASSERT(ble_gap_test_conn_event == BLE_GAP_EVENT_CONN_UPDATE);
     TEST_ASSERT(ble_gap_test_conn_status == BLE_HS_HCI_ERR(fail_status));
     TEST_ASSERT(ble_gap_test_conn_desc.conn_handle == 2);
-    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_addr, peer_addr, 6) == 0);
+    TEST_ASSERT(memcmp(ble_gap_test_conn_desc.peer_id_addr, peer_addr, 6) == 0);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_itvl ==
                 BLE_GAP_INITIAL_CONN_ITVL_MAX);
     TEST_ASSERT(ble_gap_test_conn_desc.conn_latency ==

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c5895900/net/nimble/host/src/test/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.c b/net/nimble/host/src/test/ble_hs_test_util.c
index bb7ea89..5a8cac1 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -819,4 +819,6 @@ ble_hs_test_util_init(void)
     ble_hs_cfg.max_outstanding_pkts_per_conn = 0;
 
     ble_hs_test_util_prev_hci_tx_clear();
+
+    ble_hs_test_util_set_public_addr(g_dev_addr);
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c5895900/net/nimble/host/src/test/ble_os_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_os_test.c b/net/nimble/host/src/test/ble_os_test.c
index 587bd11..ee7ffd6 100644
--- a/net/nimble/host/src/test/ble_os_test.c
+++ b/net/nimble/host/src/test/ble_os_test.c
@@ -108,8 +108,8 @@ ble_gap_direct_connect_test_connect_cb(int event,
     TEST_ASSERT(event == BLE_GAP_EVENT_CONNECT);
     TEST_ASSERT(ctxt->connect.status == 0);
     TEST_ASSERT(ctxt->desc->conn_handle == 2);
-    TEST_ASSERT(ctxt->desc->peer_addr_type == BLE_ADDR_TYPE_PUBLIC);
-    TEST_ASSERT(memcmp(ctxt->desc->peer_addr, ble_os_test_peer_addr, 6) == 0);
+    TEST_ASSERT(ctxt->desc->peer_id_addr_type == BLE_ADDR_TYPE_PUBLIC);
+    TEST_ASSERT(memcmp(ctxt->desc->peer_id_addr, ble_os_test_peer_addr, 6) == 0);
 
     return 0;
 }


[50/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Clean up endianness confusion.

Posted by cc...@apache.org.
BLE Host - Clean up endianness confusion.


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

Branch: refs/heads/develop
Commit: 4739392c098215e96bd628a4ca132c489b48dbf5
Parents: b4c3446
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 14 19:02:54 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:24:38 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm.c                | 24 ++++++++++++------------
 net/nimble/host/src/ble_sm_cmd.c            | 11 +++++------
 net/nimble/host/src/ble_sm_priv.h           |  2 +-
 net/nimble/host/src/test/ble_sm_test_util.c | 21 ++++++---------------
 4 files changed, 24 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4739392c/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 601611e..083a1ae 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -1700,9 +1700,9 @@ ble_sm_key_exch_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
 {
     struct ble_sm_id_addr_info addr_info;
     struct ble_sm_sign_info sign_info;
-    struct ble_sm_master_id master_iden;
-    struct ble_sm_id_info iden_info;
+    struct ble_sm_master_id master_id;
     struct ble_sm_enc_info enc_info;
+    struct ble_sm_id_info id_info;
     uint8_t init_key_dist;
     uint8_t resp_key_dist;
     uint8_t our_key_dist;
@@ -1730,30 +1730,30 @@ ble_sm_key_exch_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
         memcpy(proc->our_keys.ltk, enc_info.ltk, 16);
 
         /* Send master identification. */
-        rc = ble_sm_gen_ediv(&master_iden.ediv);
+        rc = ble_sm_gen_ediv(&master_id.ediv);
         if (rc != 0) {
             goto err;
         }
-        rc = ble_sm_gen_start_rand(&master_iden.rand_val);
+        rc = ble_sm_gen_start_rand(&master_id.rand_val);
         if (rc != 0) {
             goto err;
         }
-        rc = ble_sm_master_id_tx(proc->conn_handle, &master_iden);
+        rc = ble_sm_master_id_tx(proc->conn_handle, &master_id);
         if (rc != 0) {
             goto err;
         }
         proc->our_keys.ediv_rand_valid = 1;
-        proc->our_keys.rand_val = master_iden.rand_val;
-        proc->our_keys.ediv = master_iden.ediv;
+        proc->our_keys.rand_val = master_id.rand_val;
+        proc->our_keys.ediv = master_id.ediv;
     }
 
     if (our_key_dist & BLE_SM_PAIR_KEY_DIST_ID) {
         /* Send identity information. */
         irk = ble_hs_priv_get_local_irk();
 
-        memcpy(iden_info.irk, irk, 16);
+        memcpy(id_info.irk, irk, 16);
 
-        rc = ble_sm_id_info_tx(proc->conn_handle, &iden_info);
+        rc = ble_sm_id_info_tx(proc->conn_handle, &id_info);
         if (rc != 0) {
             goto err;
         }
@@ -1917,10 +1917,9 @@ ble_sm_id_info_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
         res->sm_err = BLE_SM_ERR_UNSPECIFIED;
     } else {
         proc->rx_key_flags &= ~BLE_SM_KE_F_ID_INFO;
-        proc->peer_keys.irk_valid = 1;
 
-        /* Store IRK in big endian. */
         memcpy(proc->peer_keys.irk, cmd.irk, 16);
+        proc->peer_keys.irk_valid = 1;
 
         ble_sm_key_rxed(proc, res);
     }
@@ -1993,8 +1992,9 @@ ble_sm_sign_info_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
         res->sm_err = BLE_SM_ERR_UNSPECIFIED;
     } else {
         proc->rx_key_flags &= ~BLE_SM_KE_F_SIGN_INFO;
-        proc->peer_keys.csrk_valid = 1;
+
         memcpy(proc->peer_keys.csrk, cmd.sig_key, 16);
+        proc->peer_keys.csrk_valid = 1;
 
         ble_sm_key_rxed(proc, res);
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4739392c/net/nimble/host/src/ble_sm_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_cmd.c b/net/nimble/host/src/ble_sm_cmd.c
index f3a6f13..6ff4806 100644
--- a/net/nimble/host/src/ble_sm_cmd.c
+++ b/net/nimble/host/src/ble_sm_cmd.c
@@ -344,8 +344,7 @@ ble_sm_pair_fail_log(struct ble_sm_pair_fail *cmd)
 void
 ble_sm_enc_info_parse(void *payload, int len, struct ble_sm_enc_info *cmd)
 {
-    uint8_t *u8ptr = payload;
-    memcpy(cmd->ltk, u8ptr, 16);
+    memcpy(cmd->ltk, payload, sizeof cmd->ltk);
 }
 
 int
@@ -423,7 +422,7 @@ ble_sm_master_id_log(struct ble_sm_master_id *cmd)
 void
 ble_sm_id_info_parse(void *payload, int len, struct ble_sm_id_info *cmd)
 {
-    swap_buf(cmd->irk, payload, 16);
+    memcpy(cmd->irk, payload, 16);
 }
 
 void
@@ -436,7 +435,7 @@ ble_sm_id_info_write(void *payload, int len, struct ble_sm_id_info *cmd)
     u8ptr = payload;
 
     u8ptr[0] = BLE_SM_OP_IDENTITY_INFO;
-    swap_buf(u8ptr + BLE_SM_HDR_SZ, cmd->irk, sizeof cmd->irk);
+    memcpy(u8ptr + BLE_SM_HDR_SZ, cmd->irk, sizeof cmd->irk);
 }
 
 int
@@ -529,7 +528,7 @@ ble_sm_id_addr_info_log(struct ble_sm_id_addr_info *cmd)
 void
 ble_sm_sign_info_parse(void *payload, int len, struct ble_sm_sign_info *cmd)
 {
-    swap_buf(cmd->sig_key, payload, 16);
+    memcpy(cmd->sig_key, payload, 16);
 }
 
 void
@@ -542,7 +541,7 @@ ble_sm_sign_info_write(void *payload, int len, struct ble_sm_sign_info *cmd)
     u8ptr = payload;
 
     u8ptr[0] = BLE_SM_OP_SIGN_INFO;
-    swap_buf(u8ptr + BLE_SM_HDR_SZ, cmd->sig_key, sizeof cmd->sig_key);
+    memcpy(u8ptr + BLE_SM_HDR_SZ, cmd->sig_key, sizeof cmd->sig_key);
 }
 
 int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4739392c/net/nimble/host/src/ble_sm_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_priv.h b/net/nimble/host/src/ble_sm_priv.h
index 5fc5f28..aed9633 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -133,7 +133,7 @@ struct ble_sm_master_id {
  */
 #define BLE_SM_ID_INFO_SZ           16
 struct ble_sm_id_info {
-    /* Stored in little-endian. */
+    /* Sent and stored in little-endian. */
     uint8_t irk[16];
 };
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4739392c/net/nimble/host/src/test/ble_sm_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test_util.c b/net/nimble/host/src/test/ble_sm_test_util.c
index 0dcd8af..7d51e7e 100644
--- a/net/nimble/host/src/test/ble_sm_test_util.c
+++ b/net/nimble/host/src/test/ble_sm_test_util.c
@@ -514,7 +514,6 @@ ble_sm_test_util_verify_tx_id_info(struct ble_sm_id_info *exp_cmd)
 {
     struct ble_sm_id_info cmd;
     struct os_mbuf *om;
-    uint8_t irk[16];
 
     ble_hs_test_util_tx_all();
     om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_IDENTITY_INFO,
@@ -523,9 +522,8 @@ ble_sm_test_util_verify_tx_id_info(struct ble_sm_id_info *exp_cmd)
 
     TEST_ASSERT(memcmp(cmd.irk, exp_cmd->irk, 16) == 0);
 
-    /* Ensure IRK is sent in big endian. */
-    swap_buf(irk, om->om_data, 16);
-    TEST_ASSERT(memcmp(irk, cmd.irk, 16) == 0);
+    /* Ensure IRK is sent in little endian. */
+    TEST_ASSERT(memcmp(om->om_data, cmd.irk, 16) == 0);
 }
 
 static void
@@ -555,7 +553,6 @@ ble_sm_test_util_verify_tx_sign_info(struct ble_sm_sign_info *exp_cmd)
 {
     struct ble_sm_sign_info cmd;
     struct os_mbuf *om;
-    uint8_t csrk[16];
 
     ble_hs_test_util_tx_all();
     om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_SIGN_INFO,
@@ -564,9 +561,8 @@ ble_sm_test_util_verify_tx_sign_info(struct ble_sm_sign_info *exp_cmd)
 
     TEST_ASSERT(memcmp(cmd.sig_key, exp_cmd->sig_key, 16) == 0);
 
-    /* Ensure CSRK is sent in big endian. */
-    swap_buf(csrk, om->om_data, 16);
-    TEST_ASSERT(memcmp(csrk, cmd.sig_key, 16) == 0);
+    /* Ensure CSRK is sent in little endian. */
+    TEST_ASSERT(memcmp(om->om_data, cmd.sig_key, 16) == 0);
 }
 
 static void
@@ -704,7 +700,6 @@ ble_sm_test_util_verify_tx_add_resolve_list(uint8_t peer_id_addr_type,
                                             uint8_t *peer_irk,
                                             uint8_t *our_irk)
 {
-    uint8_t buf[16];
     uint8_t param_len;
     uint8_t *param;
 
@@ -716,10 +711,8 @@ ble_sm_test_util_verify_tx_add_resolve_list(uint8_t peer_id_addr_type,
     TEST_ASSERT(memcmp(param + 1, peer_id_addr, 6) == 0);
 
     /* Ensure IRKs are sent in little endian. */
-    memcpy(buf, peer_irk, 16);
-    TEST_ASSERT(memcmp(param + 7, buf, 16) == 0);
-    memcpy(buf, our_irk, 16);
-    TEST_ASSERT(memcmp(param + 23, buf, 16) == 0);
+    TEST_ASSERT(memcmp(param + 7, peer_irk, 16) == 0);
+    TEST_ASSERT(memcmp(param + 23, our_irk, 16) == 0);
 }
 
 void
@@ -958,8 +951,6 @@ ble_sm_test_util_verify_sc_persist(struct ble_sm_test_sc_params *params,
         TEST_ASSERT(value_sec.rand_num == 0);
         TEST_ASSERT(value_sec.authenticated == params->authenticated);
 
-        /*** All keys get persisted in big endian. */
-
         TEST_ASSERT(value_sec.ltk_present == 1);
         TEST_ASSERT(memcmp(value_sec.ltk, params->ltk, 16) == 0);
 


[13/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Never persist our own IRK in keystore.

Posted by cc...@apache.org.
BLE Host - Never persist our own IRK in keystore.


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

Branch: refs/heads/develop
Commit: 830149ea66137b43d72efc31f05dc3d48abf810f
Parents: a481a84
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 8 15:03:18 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:35 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm.c | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/830149ea/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 d15960c..ade4702 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -587,6 +587,7 @@ ble_sm_persist_keys(struct ble_sm_proc *proc)
 
     authenticated = proc->flags & BLE_SM_PROC_F_AUTHENTICATED;
 
+    proc->our_keys.irk_valid = 0;
     ble_sm_fill_store_value(peer_addr_type, peer_addr, authenticated,
                             &proc->our_keys, &value_sec);
     ble_store_write_slv_sec(&value_sec);


[18/50] [abbrv] incubator-mynewt-core git commit: BLE Host - rename effective->ota; identity->id

Posted by cc...@apache.org.
BLE Host - rename effective->ota; identity->id


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

Branch: refs/heads/develop
Commit: 60e0453108d5a933f100e0d0c18797d107027e48
Parents: fbc2b60
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 8 08:45:23 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:35 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/misc.c                |  10 +--
 net/nimble/host/include/host/ble_gap.h |   4 +-
 net/nimble/host/src/ble_gap.c          |  10 +--
 net/nimble/host/src/ble_hs_conn.c      | 100 ++++++++++++++--------------
 net/nimble/host/src/ble_hs_conn_priv.h |  16 ++---
 net/nimble/host/src/ble_sm.c           |  16 ++---
 net/nimble/host/src/ble_sm_sc.c        |  32 ++++-----
 7 files changed, 94 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/60e04531/apps/bletiny/src/misc.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/misc.c b/apps/bletiny/src/misc.c
index a96a388..ecfcd9a 100644
--- a/apps/bletiny/src/misc.c
+++ b/apps/bletiny/src/misc.c
@@ -96,11 +96,11 @@ chr_is_empty(struct bletiny_svc *svc, struct bletiny_chr *chr)
 void
 print_conn_desc(struct ble_gap_conn_desc *desc)
 {
-    console_printf("handle=%d peer_effective_addr_type=%d "
-                   "peer_effective_addr=",
-                   desc->conn_handle, desc->peer_effective_addr_type);
-    print_addr(desc->peer_effective_addr);
-    console_printf(" peer_identity_addr_type=%d peer_identity_addr=",
+    console_printf("handle=%d peer_ota_addr_type=%d "
+                   "peer_ota_addr=",
+                   desc->conn_handle, desc->peer_ota_addr_type);
+    print_addr(desc->peer_ota_addr);
+    console_printf(" peer_id_addr_type=%d peer_id_addr=",
                    desc->peer_id_addr_type);
     print_addr(desc->peer_id_addr);
     console_printf(" conn_itvl=%d conn_latency=%d supervision_timeout=%d "

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/60e04531/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index 03f4dcd..faa8f92 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -119,13 +119,13 @@ struct ble_gap_adv_params {
 
 struct ble_gap_conn_desc {
     struct ble_gap_sec_state sec_state;
-    uint8_t peer_effective_addr[6];
+    uint8_t peer_ota_addr[6];
     uint8_t peer_id_addr[6];
     uint16_t conn_handle;
     uint16_t conn_itvl;
     uint16_t conn_latency;
     uint16_t supervision_timeout;
-    uint8_t peer_effective_addr_type;
+    uint8_t peer_ota_addr_type;
     uint8_t peer_id_addr_type;
 };
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/60e04531/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 dec124a..a2c007a 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -273,18 +273,18 @@ static void
 ble_gap_fill_conn_desc(struct ble_hs_conn *conn,
                        struct ble_gap_conn_desc *desc)
 {
-    uint8_t *peer_effective_addr;
+    uint8_t *peer_ota_addr;
     uint8_t *peer_id_addr;
-    uint8_t *our_effective_addr;
+    uint8_t *our_ota_addr;
 
     ble_hs_conn_addrs(conn,
-                      NULL, &our_effective_addr,
+                      NULL, &our_ota_addr,
                       NULL, NULL,
-                      &desc->peer_effective_addr_type, &peer_effective_addr,
+                      &desc->peer_ota_addr_type, &peer_ota_addr,
                       &desc->peer_id_addr_type, &peer_id_addr);
 
     desc->conn_handle = conn->bhc_handle;
-    memcpy(desc->peer_effective_addr, peer_effective_addr, 6);
+    memcpy(desc->peer_ota_addr, peer_ota_addr, 6);
     memcpy(desc->peer_id_addr, peer_id_addr, 6);
     desc->conn_itvl = conn->bhc_itvl;
     desc->conn_latency = conn->bhc_latency;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/60e04531/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 07550ec..967e8b3 100644
--- a/net/nimble/host/src/ble_hs_conn.c
+++ b/net/nimble/host/src/ble_hs_conn.c
@@ -317,70 +317,70 @@ ble_hs_conn_first(void)
 
 void
 ble_hs_conn_addrs(struct ble_hs_conn *conn,
-                  uint8_t *out_our_effective_addr_type,
-                  uint8_t **out_our_effective_addr,
-                  uint8_t *out_our_identity_addr_type,
-                  uint8_t **out_our_identity_addr,
-                  uint8_t *out_peer_effective_addr_type,
-                  uint8_t **out_peer_effective_addr,
-                  uint8_t *out_peer_identity_addr_type,
-                  uint8_t **out_peer_identity_addr)
+                  uint8_t *out_our_ota_addr_type,
+                  uint8_t **out_our_ota_addr,
+                  uint8_t *out_our_id_addr_type,
+                  uint8_t **out_our_id_addr,
+                  uint8_t *out_peer_ota_addr_type,
+                  uint8_t **out_peer_ota_addr,
+                  uint8_t *out_peer_id_addr_type,
+                  uint8_t **out_peer_id_addr)
 {
 
-    uint8_t peer_effective_addr_type;
-    uint8_t peer_identity_addr_type;
-    uint8_t our_effective_addr_type;
-    uint8_t our_identity_addr_type;
-    uint8_t *peer_effective_addr;
-    uint8_t *peer_identity_addr;
-    uint8_t *our_effective_addr;
-    uint8_t *our_identity_addr;
+    uint8_t peer_ota_addr_type;
+    uint8_t peer_id_addr_type;
+    uint8_t our_ota_addr_type;
+    uint8_t our_id_addr_type;
+    uint8_t *peer_ota_addr;
+    uint8_t *peer_id_addr;
+    uint8_t *our_ota_addr;
+    uint8_t *our_id_addr;
 
     /* Determine our address information. */
-    our_identity_addr =
-        bls_hs_priv_get_local_identity_addr(&our_identity_addr_type);
+    our_id_addr =
+        bls_hs_priv_get_local_identity_addr(&our_id_addr_type);
     if (memcmp(conn->our_rpa_addr, ble_hs_conn_null_addr, 6) == 0) {
-        our_effective_addr_type = our_identity_addr_type;
-        our_effective_addr = our_identity_addr;
+        our_ota_addr_type = our_id_addr_type;
+        our_ota_addr = our_id_addr;
     } else {
-        switch (our_identity_addr_type) {
+        switch (our_id_addr_type) {
         case BLE_ADDR_TYPE_PUBLIC:
-            our_effective_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT;
+            our_ota_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT;
             break;
 
         case BLE_ADDR_TYPE_RANDOM:
-            our_effective_addr_type = BLE_ADDR_TYPE_RPA_RND_DEFAULT;
+            our_ota_addr_type = BLE_ADDR_TYPE_RPA_RND_DEFAULT;
             break;
 
         default:
             BLE_HS_DBG_ASSERT(0);
         }
 
-        our_effective_addr = conn->our_rpa_addr;
+        our_ota_addr = conn->our_rpa_addr;
     }
 
     /* Determine peer address information. */
-    peer_effective_addr_type = conn->bhc_addr_type;
-    peer_identity_addr = conn->bhc_addr;
+    peer_ota_addr_type = conn->bhc_addr_type;
+    peer_id_addr = conn->bhc_addr;
     switch (conn->bhc_addr_type) {
     case BLE_ADDR_TYPE_PUBLIC:
-        peer_identity_addr_type = BLE_ADDR_TYPE_PUBLIC;
-        peer_effective_addr = conn->bhc_addr;
+        peer_id_addr_type = BLE_ADDR_TYPE_PUBLIC;
+        peer_ota_addr = conn->bhc_addr;
         break;
 
     case BLE_ADDR_TYPE_RANDOM:
-        peer_identity_addr_type = BLE_ADDR_TYPE_RANDOM;
-        peer_effective_addr = conn->bhc_addr;
+        peer_id_addr_type = BLE_ADDR_TYPE_RANDOM;
+        peer_ota_addr = conn->bhc_addr;
         break;
 
     case BLE_ADDR_TYPE_RPA_PUB_DEFAULT:
-        peer_identity_addr_type = BLE_ADDR_TYPE_PUBLIC;
-        peer_effective_addr = conn->peer_rpa_addr;
+        peer_id_addr_type = BLE_ADDR_TYPE_PUBLIC;
+        peer_ota_addr = conn->peer_rpa_addr;
         break;
 
     case BLE_ADDR_TYPE_RPA_RND_DEFAULT:
-        peer_identity_addr_type = BLE_ADDR_TYPE_RANDOM;
-        peer_effective_addr = conn->peer_rpa_addr;
+        peer_id_addr_type = BLE_ADDR_TYPE_RANDOM;
+        peer_ota_addr = conn->peer_rpa_addr;
         break;
 
     default:
@@ -388,29 +388,29 @@ ble_hs_conn_addrs(struct ble_hs_conn *conn,
         break;
     }
 
-    if (out_our_effective_addr_type != NULL) {
-        *out_our_effective_addr_type = our_effective_addr_type;
+    if (out_our_ota_addr_type != NULL) {
+        *out_our_ota_addr_type = our_ota_addr_type;
     }
-    if (out_our_effective_addr != NULL) {
-        *out_our_effective_addr = our_effective_addr;
+    if (out_our_ota_addr != NULL) {
+        *out_our_ota_addr = our_ota_addr;
     }
-    if (out_our_identity_addr_type != NULL) {
-        *out_our_identity_addr_type = our_identity_addr_type;
+    if (out_our_id_addr_type != NULL) {
+        *out_our_id_addr_type = our_id_addr_type;
     }
-    if (out_our_identity_addr != NULL) {
-        *out_our_identity_addr = our_identity_addr;
+    if (out_our_id_addr != NULL) {
+        *out_our_id_addr = our_id_addr;
     }
-    if (out_peer_effective_addr_type != NULL) {
-        *out_peer_effective_addr_type = peer_effective_addr_type;
+    if (out_peer_ota_addr_type != NULL) {
+        *out_peer_ota_addr_type = peer_ota_addr_type;
     }
-    if (out_peer_effective_addr != NULL) {
-        *out_peer_effective_addr = peer_effective_addr;
+    if (out_peer_ota_addr != NULL) {
+        *out_peer_ota_addr = peer_ota_addr;
     }
-    if (out_peer_identity_addr_type != NULL) {
-        *out_peer_identity_addr_type = peer_identity_addr_type;
+    if (out_peer_id_addr_type != NULL) {
+        *out_peer_id_addr_type = peer_id_addr_type;
     }
-    if (out_peer_identity_addr != NULL) {
-        *out_peer_identity_addr = peer_identity_addr;
+    if (out_peer_id_addr != NULL) {
+        *out_peer_id_addr = peer_id_addr;
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/60e04531/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 1ef4829..e6d940e 100644
--- a/net/nimble/host/src/ble_hs_conn_priv.h
+++ b/net/nimble/host/src/ble_hs_conn_priv.h
@@ -76,14 +76,14 @@ struct ble_l2cap_chan *ble_hs_conn_chan_find(struct ble_hs_conn *conn,
 int ble_hs_conn_chan_insert(struct ble_hs_conn *conn,
                             struct ble_l2cap_chan *chan);
 void ble_hs_conn_addrs(struct ble_hs_conn *conn,
-                       uint8_t *our_effective_addr_type,
-                       uint8_t **our_effective_addr,
-                       uint8_t *our_identity_addr_type,
-                       uint8_t **our_identity_addr,
-                       uint8_t *peer_effective_addr_type,
-                       uint8_t **peer_effective_addr,
-                       uint8_t *peer_identity_addr_type,
-                       uint8_t **peer_identity_addr);
+                       uint8_t *our_ota_addr_type,
+                       uint8_t **our_ota_addr,
+                       uint8_t *our_id_addr_type,
+                       uint8_t **our_id_addr,
+                       uint8_t *peer_ota_addr_type,
+                       uint8_t **peer_ota_addr,
+                       uint8_t *peer_id_addr_type,
+                       uint8_t **peer_id_addr);
 
 int ble_hs_conn_init(void);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/60e04531/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 1189bb5..68c0c0d 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -527,8 +527,8 @@ ble_sm_ia_ra(struct ble_sm_proc *proc,
              uint8_t *out_rat, uint8_t *out_ra)
 {
     struct ble_hs_conn *conn;
-    uint8_t *peer_effective_addr;
-    uint8_t *our_effective_addr;
+    uint8_t *peer_ota_addr;
+    uint8_t *our_ota_addr;
     uint8_t peer_id_addr_type;
     uint8_t our_id_addr_type;
 
@@ -538,23 +538,23 @@ ble_sm_ia_ra(struct ble_sm_proc *proc,
     }
 
     ble_hs_conn_addrs(conn,
-                      NULL, &our_effective_addr,
+                      NULL, &our_ota_addr,
                       &our_id_addr_type, NULL,
-                      NULL, &peer_effective_addr,
+                      NULL, &peer_ota_addr,
                       &peer_id_addr_type, NULL);
 
     if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
         *out_iat = our_id_addr_type;
-        memcpy(out_ia, our_effective_addr, 6);
+        memcpy(out_ia, our_ota_addr, 6);
 
         *out_rat = peer_id_addr_type;
-        memcpy(out_ra, peer_effective_addr, 6);
+        memcpy(out_ra, peer_ota_addr, 6);
     } else {
         *out_iat = peer_id_addr_type;
-        memcpy(out_ia, peer_effective_addr, 6);
+        memcpy(out_ia, peer_ota_addr, 6);
 
         *out_rat = our_id_addr_type;
-        memcpy(out_ra, our_effective_addr, 6);
+        memcpy(out_ra, our_ota_addr, 6);
     }
 
     return 0;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/60e04531/net/nimble/host/src/ble_sm_sc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_sc.c b/net/nimble/host/src/ble_sm_sc.c
index 5939916..5405eaa 100644
--- a/net/nimble/host/src/ble_sm_sc.c
+++ b/net/nimble/host/src/ble_sm_sc.c
@@ -523,9 +523,9 @@ ble_sm_sc_public_key_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
 static int
 ble_sm_sc_dhkey_addrs(struct ble_sm_proc *proc,
                       uint8_t *out_our_id_addr_type,
-                      uint8_t **out_our_effective_addr,
+                      uint8_t **out_our_ota_addr,
                       uint8_t *out_peer_id_addr_type,
-                      uint8_t **out_peer_effective_addr)
+                      uint8_t **out_peer_ota_addr)
 {
     struct ble_hs_conn *conn;
 
@@ -535,9 +535,9 @@ ble_sm_sc_dhkey_addrs(struct ble_sm_proc *proc,
     }
 
     ble_hs_conn_addrs(conn,
-                      NULL, out_our_effective_addr,
+                      NULL, out_our_ota_addr,
                       out_our_id_addr_type, NULL,
-                      NULL, out_peer_effective_addr,
+                      NULL, out_peer_ota_addr,
                       out_peer_id_addr_type, NULL);
 
     return 0;
@@ -557,8 +557,8 @@ ble_sm_sc_dhkey_check_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
                            void *arg)
 {
     struct ble_sm_dhkey_check cmd;
-    uint8_t *our_effective_addr;
-    uint8_t *peer_effective_addr;
+    uint8_t *our_ota_addr;
+    uint8_t *peer_ota_addr;
     uint8_t peer_id_addr_type;
     uint8_t our_id_addr_type;
     uint8_t iocap[3];
@@ -571,16 +571,16 @@ ble_sm_sc_dhkey_check_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
     }
 
     rc = ble_sm_sc_dhkey_addrs(proc,
-                               &our_id_addr_type, &our_effective_addr,
-                               &peer_id_addr_type, &peer_effective_addr);
+                               &our_id_addr_type, &our_ota_addr,
+                               &peer_id_addr_type, &peer_ota_addr);
     if (rc != 0) {
         goto err;
     }
 
     rc = ble_sm_alg_f6(proc->mackey, ble_sm_our_pair_rand(proc),
                        ble_sm_peer_pair_rand(proc), proc->tk, iocap,
-                       our_id_addr_type, our_effective_addr,
-                       peer_id_addr_type, peer_effective_addr,
+                       our_id_addr_type, our_ota_addr,
+                       peer_id_addr_type, peer_ota_addr,
                        cmd.value);
     if (rc != 0) {
         goto err;
@@ -609,8 +609,8 @@ ble_sm_dhkey_check_process(struct ble_sm_proc *proc,
                            struct ble_sm_result *res)
 {
     uint8_t exp_value[16];
-    uint8_t *peer_effective_addr;
-    uint8_t *our_effective_addr;
+    uint8_t *peer_ota_addr;
+    uint8_t *our_ota_addr;
     uint8_t peer_id_addr_type;
     uint8_t our_id_addr_type;
     uint8_t iocap[3];
@@ -624,9 +624,9 @@ ble_sm_dhkey_check_process(struct ble_sm_proc *proc,
 
     res->app_status = ble_sm_sc_dhkey_addrs(proc,
                                             &our_id_addr_type,
-                                            &our_effective_addr,
+                                            &our_ota_addr,
                                             &peer_id_addr_type,
-                                            &peer_effective_addr);
+                                            &peer_ota_addr);
     if (res->app_status != 0) {
         res->sm_err = BLE_SM_ERR_UNSPECIFIED;
         res->enc_cb = 1;
@@ -641,8 +641,8 @@ ble_sm_dhkey_check_process(struct ble_sm_proc *proc,
                                     ble_sm_peer_pair_rand(proc),
                                     ble_sm_our_pair_rand(proc),
                                     proc->tk, iocap,
-                                    peer_id_addr_type, peer_effective_addr,
-                                    our_id_addr_type, our_effective_addr,
+                                    peer_id_addr_type, peer_ota_addr,
+                                    our_id_addr_type, our_ota_addr,
                                     exp_value);
     if (res->app_status != 0) {
         res->sm_err = BLE_SM_ERR_UNSPECIFIED;


[28/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Fix compiler errors!

Posted by cc...@apache.org.
BLE Host - Fix compiler errors!


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

Branch: refs/heads/develop
Commit: 89d36b5cd24490a142bf5d371a9111dce1614712
Parents: af8610a
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jun 9 08:00:54 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:37 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_gattc.c   | 5 ++---
 net/nimble/host/src/ble_hs_conn.c | 2 +-
 2 files changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/89d36b5c/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index db5ab5f..fb7e26d 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -3406,9 +3406,8 @@ ble_gattc_write_reliable_err(struct ble_gattc_proc *proc, int status,
     /* If we have successfully queued any data, and the failure occurred before
      * we could send the execute write command, then erase all queued data.
      */
-    if (proc->write_reliable.attr.offset > 0 &&
-        proc->write_reliable.attr.offset <
-            proc->write_reliable.attr.value_len) {
+    if (proc->write_reliable.cur_attr > 0 &&
+        proc->write_reliable.cur_attr < proc->write_reliable.num_attrs) {
 
         exec_req.baeq_flags = 0;
         ble_att_clt_tx_exec_write(proc->conn_handle, &exec_req);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/89d36b5c/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 967e8b3..87374e1 100644
--- a/net/nimble/host/src/ble_hs_conn.c
+++ b/net/nimble/host/src/ble_hs_conn.c
@@ -385,7 +385,7 @@ ble_hs_conn_addrs(struct ble_hs_conn *conn,
 
     default:
         BLE_HS_DBG_ASSERT(0);
-        break;
+        return;
     }
 
     if (out_our_ota_addr_type != NULL) {


[40/50] [abbrv] incubator-mynewt-core git commit: BLE Host - SM SC unit tests.

Posted by cc...@apache.org.
BLE Host - SM SC unit tests.


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

Branch: refs/heads/develop
Commit: 4f9739f74ec89743316bb0792c757bfbbb3153d4
Parents: 80fbd38
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Jun 13 16:23:29 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:24:18 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_hs_test.h  |   27 +-
 net/nimble/host/src/ble_hs_conn.c           |    1 +
 net/nimble/host/src/ble_sm.c                |    4 +-
 net/nimble/host/src/ble_sm_alg.c            |    7 -
 net/nimble/host/src/ble_sm_cmd.c            |   10 +-
 net/nimble/host/src/ble_sm_priv.h           |    4 +-
 net/nimble/host/src/ble_sm_sc.c             |    7 +
 net/nimble/host/src/host_hci_cmd.c          |   15 +-
 net/nimble/host/src/test/ble_hs_test.c      |    1 +
 net/nimble/host/src/test/ble_sm_sc_test.c   | 1696 ++++++++++++++
 net/nimble/host/src/test/ble_sm_test.c      | 2557 +++-------------------
 net/nimble/host/src/test/ble_sm_test_util.c | 2092 ++++++++++++++++++
 net/nimble/host/src/test/ble_sm_test_util.h |  145 ++
 13 files changed, 4287 insertions(+), 2279 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4f9739f7/net/nimble/host/include/host/ble_hs_test.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs_test.h b/net/nimble/host/include/host/ble_hs_test.h
index 3ca3d28..375a85e 100644
--- a/net/nimble/host/include/host/ble_hs_test.h
+++ b/net/nimble/host/include/host/ble_hs_test.h
@@ -26,24 +26,25 @@ struct os_mbuf;
 void ble_hs_test_pkt_txed(struct os_mbuf *om);
 void ble_hs_test_hci_txed(uint8_t *cmdbuf);
 
-int ble_l2cap_test_all(void);
-int ble_sm_test_all(void);
-int ble_att_svr_test_all(void);
 int ble_att_clt_test_all(void);
-int ble_host_hci_test_all(void);
-int ble_hs_conn_test_all(void);
-int ble_os_test_all(void);
-int ble_uuid_test_all(void);
-int ble_gatt_disc_s_test_all(void);
+int ble_att_svr_test_all(void);
+int ble_gap_test_all(void);
+int ble_gatt_conn_test_all(void);
 int ble_gatt_disc_c_test_all(void);
 int ble_gatt_disc_d_test_all(void);
+int ble_gatt_disc_s_test_all(void);
+int ble_gatt_find_s_test_all(void);
 int ble_gatt_read_test_all(void);
 int ble_gatt_write_test_all(void);
-int ble_gatt_conn_test_all(void);
-int ble_hs_adv_test_all(void);
-int ble_gatts_reg_test_all(void);
 int ble_gatts_notify_test_all(void);
-int ble_gatt_find_s_test_all(void);
-int ble_gap_test_all(void);
+int ble_gatts_reg_test_all(void);
+int ble_host_hci_test_all(void);
+int ble_hs_adv_test_all(void);
+int ble_hs_conn_test_all(void);
+int ble_l2cap_test_all(void);
+int ble_os_test_all(void);
+int ble_sm_sc_test_all(void);
+int ble_sm_test_all(void);
+int ble_uuid_test_all(void);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4f9739f7/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 faab9dc..3e0dd19 100644
--- a/net/nimble/host/src/ble_hs_conn.c
+++ b/net/nimble/host/src/ble_hs_conn.c
@@ -323,6 +323,7 @@ ble_hs_conn_addrs(struct ble_hs_conn *conn,
     addrs->our_id_addr =
         bls_hs_priv_get_local_identity_addr(&addrs->our_id_addr_type);
     if (memcmp(conn->our_rpa_addr, ble_hs_conn_null_addr, 6) == 0) {
+        addrs->our_ota_addr_type = addrs->our_id_addr_type;
         addrs->our_ota_addr = addrs->our_id_addr;
     } else {
         switch (addrs->our_id_addr_type) {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4f9739f7/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 5dedf98..751a062 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -1918,8 +1918,8 @@ ble_sm_id_info_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
         proc->rx_key_flags &= ~BLE_SM_KE_F_ID_INFO;
         proc->peer_keys.irk_valid = 1;
 
-        /* Store IRK in little endian. */
-        swap_buf(proc->peer_keys.irk, cmd.irk, 16);
+        /* Store IRK in big endian. */
+        memcpy(proc->peer_keys.irk, cmd.irk, 16);
 
         ble_sm_key_rxed(proc, res);
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4f9739f7/net/nimble/host/src/ble_sm_alg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_alg.c b/net/nimble/host/src/ble_sm_alg.c
index 89d735a..1885d09 100644
--- a/net/nimble/host/src/ble_sm_alg.c
+++ b/net/nimble/host/src/ble_sm_alg.c
@@ -491,13 +491,6 @@ ble_sm_alg_gen_key_pair(void *pub, uint32_t *priv)
     memcpy(pub + 0, pkey.x, 32);
     memcpy(pub + 32, pkey.y, 32);
 
-    BLE_HS_LOG(DEBUG, "our pubkey=");
-    ble_hs_misc_log_flat_buf(pub, 64);
-    BLE_HS_LOG(DEBUG, "\n");
-    BLE_HS_LOG(DEBUG, "our privkey=");
-    ble_hs_misc_log_flat_buf(priv, 32);
-    BLE_HS_LOG(DEBUG, "\n");
-
     return 0;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4f9739f7/net/nimble/host/src/ble_sm_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_cmd.c b/net/nimble/host/src/ble_sm_cmd.c
index 4169982..f3a6f13 100644
--- a/net/nimble/host/src/ble_sm_cmd.c
+++ b/net/nimble/host/src/ble_sm_cmd.c
@@ -423,8 +423,7 @@ ble_sm_master_id_log(struct ble_sm_master_id *cmd)
 void
 ble_sm_id_info_parse(void *payload, int len, struct ble_sm_id_info *cmd)
 {
-    uint8_t *u8ptr = payload;
-    memcpy(cmd->irk, u8ptr, 16);
+    swap_buf(cmd->irk, payload, 16);
 }
 
 void
@@ -437,7 +436,7 @@ ble_sm_id_info_write(void *payload, int len, struct ble_sm_id_info *cmd)
     u8ptr = payload;
 
     u8ptr[0] = BLE_SM_OP_IDENTITY_INFO;
-    memcpy(u8ptr + BLE_SM_HDR_SZ, cmd->irk, sizeof cmd->irk);
+    swap_buf(u8ptr + BLE_SM_HDR_SZ, cmd->irk, sizeof cmd->irk);
 }
 
 int
@@ -530,8 +529,7 @@ ble_sm_id_addr_info_log(struct ble_sm_id_addr_info *cmd)
 void
 ble_sm_sign_info_parse(void *payload, int len, struct ble_sm_sign_info *cmd)
 {
-    uint8_t *u8ptr = payload;
-    memcpy(cmd->sig_key, u8ptr, 16);
+    swap_buf(cmd->sig_key, payload, 16);
 }
 
 void
@@ -544,7 +542,7 @@ ble_sm_sign_info_write(void *payload, int len, struct ble_sm_sign_info *cmd)
     u8ptr = payload;
 
     u8ptr[0] = BLE_SM_OP_SIGN_INFO;
-    memcpy(u8ptr + BLE_SM_HDR_SZ, cmd->sig_key, sizeof cmd->sig_key);
+    swap_buf(u8ptr + BLE_SM_HDR_SZ, cmd->sig_key, sizeof cmd->sig_key);
 }
 
 int

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4f9739f7/net/nimble/host/src/ble_sm_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_priv.h b/net/nimble/host/src/ble_sm_priv.h
index 1af1d66..5fc5f28 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -239,8 +239,8 @@ struct ble_sm_keys {
     uint8_t addr_type;
     uint8_t ltk[16];    /* Little endian. */
     uint8_t irk[16];    /* Little endian. */
-    uint8_t csrk[16];
-    uint8_t addr[6];
+    uint8_t csrk[16];   /* Little endian. */
+    uint8_t addr[6];    /* Little endian. */
 };
 
 struct ble_sm_proc {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4f9739f7/net/nimble/host/src/ble_sm_sc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_sc.c b/net/nimble/host/src/ble_sm_sc.c
index acc91eb..fc56804 100644
--- a/net/nimble/host/src/ble_sm_sc.c
+++ b/net/nimble/host/src/ble_sm_sc.c
@@ -152,6 +152,13 @@ ble_sm_sc_ensure_keys_generated(void)
         ble_sm_sc_keys_generated = 1;
     }
 
+    BLE_HS_LOG(DEBUG, "our pubkey=");
+    ble_hs_misc_log_flat_buf(&ble_sm_sc_pub_key, 64);
+    BLE_HS_LOG(DEBUG, "\n");
+    BLE_HS_LOG(DEBUG, "our privkey=");
+    ble_hs_misc_log_flat_buf(&ble_sm_sc_priv_key, 32);
+    BLE_HS_LOG(DEBUG, "\n");
+
     return 0;
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4f9739f7/net/nimble/host/src/host_hci_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/host_hci_cmd.c b/net/nimble/host/src/host_hci_cmd.c
index 06b5c01..887ddfb 100644
--- a/net/nimble/host/src/host_hci_cmd.c
+++ b/net/nimble/host/src/host_hci_cmd.c
@@ -1024,6 +1024,9 @@ host_hci_cmd_build_set_data_len(uint16_t connection_handle,
     return 0;
 }
 
+/**
+ * IRKs are in little endian.
+ */
 static int
 host_hci_cmd_body_add_device_to_resolving_list(uint8_t addr_type,
                                                uint8_t *addr,
@@ -1043,8 +1046,10 @@ host_hci_cmd_body_add_device_to_resolving_list(uint8_t addr_type,
     return 0;
 }
 
-/*
+/**
  * OGF=0x08 OCF=0x0027
+ *
+ * IRKs are in little endian.
  */
 int
 host_hci_cmd_add_device_to_resolving_list(
@@ -1060,11 +1065,9 @@ host_hci_cmd_add_device_to_resolving_list(
     host_hci_write_hdr(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_ADD_RESOLV_LIST,
                        BLE_HCI_ADD_TO_RESOLV_LIST_LEN, dst);
 
-    rc = host_hci_cmd_body_add_device_to_resolving_list(padd->addr_type,
-                                                padd->addr,
-                                                padd->peer_irk,
-                                                padd->local_irk,
-                                                dst + BLE_HCI_CMD_HDR_LEN);
+    rc = host_hci_cmd_body_add_device_to_resolving_list(
+        padd->addr_type, padd->addr, padd->peer_irk, padd->local_irk,
+        dst + BLE_HCI_CMD_HDR_LEN);
     if (rc != 0) {
         return rc;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4f9739f7/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 23f8326..f6a139b 100644
--- a/net/nimble/host/src/test/ble_hs_test.c
+++ b/net/nimble/host/src/test/ble_hs_test.c
@@ -67,6 +67,7 @@ main(int argc, char **argv)
     ble_hs_adv_test_all();
     ble_hs_conn_test_all();
     ble_sm_test_all();
+    ble_sm_sc_test_all();
     ble_l2cap_test_all();
     ble_os_test_all();
     ble_uuid_test_all();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4f9739f7/net/nimble/host/src/test/ble_sm_sc_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_sc_test.c b/net/nimble/host/src/test/ble_sm_sc_test.c
new file mode 100644
index 0000000..36597ce
--- /dev/null
+++ b/net/nimble/host/src/test/ble_sm_sc_test.c
@@ -0,0 +1,1696 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <stddef.h>
+#include <string.h>
+#include <errno.h>
+#include "testutil/testutil.h"
+#include "nimble/hci_common.h"
+#include "nimble/nimble_opt.h"
+#include "host/host_hci.h"
+#include "host/ble_sm.h"
+#include "host/ble_hs_test.h"
+#include "ble_hs_test_util.h"
+#include "ble_sm_test_util.h"
+
+#if NIMBLE_OPT(SM)
+
+/**
+ * Secure connections pairing
+ * Master: peer
+ * Pair algorithm: just works
+ * Initiator IO capabilities: 3
+ * Responder IO capabilities: 3
+ * Bonding: true
+ * Initiator address type: 0
+ * Responder address type: 0
+ * Initiator key distribution: 5
+ * Responder key distribution: 7
+ */
+TEST_CASE(ble_sm_sc_peer_jw_iio3_rio3_b1_iat0_rat0_ik5_rk7)
+{
+    struct ble_sm_test_sc_params params;
+
+    params = (struct ble_sm_test_sc_params) {
+        .init_addr = {
+            0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
+        },
+        .resp_addr = {
+            0x33, 0x22, 0x11, 0x00, 0x45, 0x0a,
+        },
+        .pair_req = {
+            .io_cap = 0x03,
+            .oob_data_flag = 0x00,
+            .authreq = 0x09,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x0d,
+            .resp_key_dist = 0x0f,
+        },
+        .pair_rsp = {
+            .io_cap = 0x03,
+            .oob_data_flag = 0x00,
+            .authreq = 0x09,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x05,
+            .resp_key_dist = 0x07,
+        },
+        .our_priv_key = {
+            0x54, 0x8d, 0x20, 0xb8, 0x97, 0x0b, 0xbc, 0x43,
+            0x9a, 0xad, 0x10, 0x6f, 0x60, 0x74, 0xd4, 0x6a,
+            0x55, 0xc1, 0x7a, 0x17, 0x8b, 0x60, 0xe0, 0xb4,
+            0x5a, 0xe6, 0x58, 0xf1, 0xea, 0x12, 0xd9, 0xfb,
+        },
+        .public_key_req = {
+            .x = {
+                0xbc, 0xf2, 0xd8, 0xa5, 0xdb, 0xa3, 0x95, 0x6c,
+                0x99, 0xf9, 0x11, 0x0d, 0x4d, 0x2e, 0xf0, 0xbd,
+                0xee, 0x9b, 0x69, 0xb6, 0xcd, 0x88, 0x74, 0xbe,
+                0x40, 0xe8, 0xe5, 0xcc, 0xdc, 0x88, 0x44, 0x53,
+            },
+            .y = {
+                0xbf, 0xa9, 0x82, 0x0e, 0x18, 0x7a, 0x14, 0xf8,
+                0x77, 0xfd, 0x8e, 0x92, 0x2a, 0xf8, 0x5d, 0x39,
+                0xd1, 0x6d, 0x92, 0x1f, 0x38, 0x74, 0x99, 0xdc,
+                0x6c, 0x2c, 0x94, 0x23, 0xf9, 0x72, 0x56, 0xab,
+            },
+        },
+        .public_key_rsp = {
+            .x = {
+                0x72, 0x8c, 0xd1, 0x88, 0xd7, 0xbe, 0x49, 0xb2,
+                0xc5, 0x5c, 0x95, 0xb3, 0x64, 0xe0, 0x12, 0x32,
+                0xb6, 0xc9, 0x47, 0x63, 0x37, 0x38, 0x5b, 0x9c,
+                0x1e, 0x1b, 0x1a, 0x06, 0x09, 0xe2, 0x31, 0x85,
+            },
+            .y = {
+                0x19, 0x3a, 0x29, 0x69, 0x62, 0xd6, 0x30, 0xe7,
+                0xe8, 0x48, 0x63, 0xdc, 0x00, 0x73, 0x0a, 0x70,
+                0x7d, 0x2e, 0x29, 0xcc, 0x91, 0x77, 0x71, 0xb1,
+                0x75, 0xb8, 0xf7, 0xdc, 0xb0, 0xe2, 0x91, 0x10,
+            },
+        },
+        .confirm_rsp[0] = {
+            .value = {
+                0x82, 0xed, 0xd0, 0x62, 0x91, 0x3d, 0x96, 0x7f,
+                0x13, 0xc5, 0x0d, 0x02, 0x2b, 0x5e, 0x43, 0x16,
+            },
+        },
+        .random_req[0] = {
+            .value = {
+                0xa4, 0x34, 0x5f, 0xb3, 0xaf, 0x73, 0x43, 0x64,
+                0xcd, 0x19, 0x1b, 0x5b, 0x87, 0x58, 0x31, 0x66,
+            },
+        },
+        .random_rsp[0] = {
+            .value = {
+                0xc0, 0x91, 0xfb, 0xb3, 0x77, 0xa2, 0x02, 0x0b,
+                0xc6, 0xcd, 0x6c, 0x04, 0x51, 0x45, 0x45, 0x39,
+            },
+        },
+        .dhkey_check_req = {
+            .value = {
+                0x82, 0x65, 0x1d, 0x02, 0xed, 0x89, 0x13, 0x44,
+                0x04, 0x1a, 0x14, 0x7c, 0x32, 0x9a, 0x1e, 0x7d,
+            },
+        },
+        .dhkey_check_rsp = {
+            .value = {
+                0x06, 0x3c, 0x28, 0x4a, 0xe5, 0x48, 0x4b, 0x51,
+                0x65, 0x4e, 0x14, 0x5e, 0x2f, 0xdd, 0xfa, 0x22,
+            },
+        },
+        .id_info_req = {
+            .irk = {
+                0xef, 0x8d, 0xe2, 0x16, 0x4f, 0xec, 0x43, 0x0d,
+                0xbf, 0x5b, 0xdd, 0x34, 0xc0, 0x53, 0x1e, 0xb8,
+            },
+        },
+        .id_addr_info_req = {
+            .addr_type = 0,
+            .bd_addr = {
+                0x33, 0x22, 0x11, 0x00, 0x45, 0x0a,
+            },
+        },
+        .sign_info_req = {
+            .sig_key = {
+                0x40, 0x53, 0xeb, 0x7a, 0x4d, 0x8e, 0xa2, 0xb5,
+                0xca, 0xa1, 0xb6, 0xae, 0x7e, 0x6a, 0x4d, 0xd9,
+            },
+        },
+        .sign_info_rsp = {
+            .sig_key = {
+                0xbc, 0x13, 0x4b, 0x45, 0xda, 0x76, 0x5b, 0xcd,
+                0xc2, 0x43, 0x81, 0xb8, 0xc3, 0x68, 0x12, 0xbb,
+            },
+        },
+        .ltk = {
+            0x63, 0x59, 0x8a, 0x14, 0x09, 0x4b, 0x94, 0x6e,
+            0xff, 0xae, 0x5e, 0x53, 0x86, 0x02, 0xa3, 0x6c,
+        },
+        .pair_alg = BLE_SM_PAIR_ALG_JW,
+        .authenticated = 0,
+        .passkey_info = {
+            .passkey = {
+                .action = BLE_SM_IOACT_NONE,
+            },
+        },
+    };
+    ble_sm_test_util_peer_sc_good(&params);
+}
+
+/**
+ * Secure connections pairing
+ * Master: peer
+ * Pair algorithm: passkey entry
+ * Initiator IO capabilities: 0
+ * Responder IO capabilities: 2
+ * Bonding: true
+ * Initiator address type: 0
+ * Responder address type: 0
+ * Initiator key distribution: 5
+ * Responder key distribution: 7
+ */
+TEST_CASE(ble_sm_sc_peer_pk_iio0_rio2_b1_iat0_rat0_ik5_rk7)
+{
+    struct ble_sm_test_sc_params params;
+
+    params = (struct ble_sm_test_sc_params) {
+        .init_addr = {
+            0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
+        },
+        .resp_addr = {
+            0x33, 0x22, 0x11, 0x00, 0x45, 0x0a,
+        },
+        .pair_req = {
+            .io_cap = 0x00,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x0d,
+            .resp_key_dist = 0x0f,
+        },
+        .pair_rsp = {
+            .io_cap = 0x02,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x05,
+            .resp_key_dist = 0x07,
+        },
+        .our_priv_key = {
+            0x54, 0x8d, 0x20, 0xb8, 0x97, 0x0b, 0xbc, 0x43,
+            0x9a, 0xad, 0x10, 0x6f, 0x60, 0x74, 0xd4, 0x6a,
+            0x55, 0xc1, 0x7a, 0x17, 0x8b, 0x60, 0xe0, 0xb4,
+            0x5a, 0xe6, 0x58, 0xf1, 0xea, 0x12, 0xd9, 0xfb,
+        },
+        .public_key_req = {
+            .x = {
+                0x22, 0x26, 0xcc, 0x64, 0x4d, 0xc1, 0x01, 0xd1,
+                0xb9, 0x8d, 0xe2, 0xd4, 0xbc, 0x55, 0x37, 0x4c,
+                0x12, 0x81, 0x14, 0x83, 0x81, 0xe8, 0x36, 0x1b,
+                0x78, 0xff, 0x49, 0xfc, 0xe9, 0x2e, 0x56, 0xc0,
+            },
+            .y = {
+                0xd9, 0x31, 0xa5, 0x8d, 0x02, 0xf1, 0x94, 0xb6,
+                0x83, 0x97, 0xd1, 0xfb, 0x01, 0x97, 0x4d, 0x06,
+                0xec, 0x18, 0x8d, 0x4a, 0xd2, 0x14, 0x12, 0x95,
+                0x2d, 0x4d, 0x18, 0xde, 0x4d, 0xaa, 0x91, 0x25,
+            },
+        },
+        .public_key_rsp = {
+            .x = {
+                0x72, 0x8c, 0xd1, 0x88, 0xd7, 0xbe, 0x49, 0xb2,
+                0xc5, 0x5c, 0x95, 0xb3, 0x64, 0xe0, 0x12, 0x32,
+                0xb6, 0xc9, 0x47, 0x63, 0x37, 0x38, 0x5b, 0x9c,
+                0x1e, 0x1b, 0x1a, 0x06, 0x09, 0xe2, 0x31, 0x85,
+            },
+            .y = {
+                0x19, 0x3a, 0x29, 0x69, 0x62, 0xd6, 0x30, 0xe7,
+                0xe8, 0x48, 0x63, 0xdc, 0x00, 0x73, 0x0a, 0x70,
+                0x7d, 0x2e, 0x29, 0xcc, 0x91, 0x77, 0x71, 0xb1,
+                0x75, 0xb8, 0xf7, 0xdc, 0xb0, 0xe2, 0x91, 0x10,
+            },
+        },
+        .confirm_req[0] = {
+            .value = {
+                0x2c, 0x16, 0x15, 0x0d, 0xe8, 0x18, 0x50, 0xd8,
+                0xae, 0x04, 0x6c, 0xa8, 0x50, 0xb8, 0xe5, 0x85,
+            },
+        },
+        .confirm_rsp[0] = {
+            .value = {
+                0x62, 0x53, 0xfb, 0x69, 0x94, 0x33, 0x11, 0xd3,
+                0x8e, 0x03, 0xd5, 0x05, 0xd7, 0x68, 0x33, 0x16,
+            },
+        },
+        .random_req[0] = {
+            .value = {
+                0xd5, 0x0e, 0x27, 0xcf, 0xa4, 0xc1, 0x52, 0x1b,
+                0xf1, 0x9d, 0x5f, 0xbe, 0xe2, 0xc0, 0x48, 0x38,
+            },
+        },
+        .random_rsp[0] = {
+            .value = {
+                0x94, 0x31, 0x95, 0x44, 0x6c, 0xc5, 0x73, 0xc8,
+                0x8d, 0x72, 0x06, 0xe7, 0xfd, 0x16, 0x70, 0x5d,
+            },
+        },
+        .confirm_req[1] = {
+            .value = {
+                0x80, 0xae, 0x74, 0xaa, 0x9a, 0xfc, 0x09, 0x97,
+                0x10, 0x01, 0x4e, 0xbb, 0x16, 0x36, 0x6b, 0xc7,
+            },
+        },
+        .confirm_rsp[1] = {
+            .value = {
+                0x5a, 0xb1, 0xe5, 0x81, 0x5a, 0x1b, 0xef, 0xf4,
+                0xa8, 0x3d, 0xaa, 0x3f, 0x02, 0x1f, 0x78, 0x55,
+            },
+        },
+        .random_req[1] = {
+            .value = {
+                0x04, 0x4a, 0xf4, 0xd5, 0x4b, 0x4f, 0x77, 0x37,
+                0x2a, 0x3c, 0xfe, 0x83, 0x34, 0x6b, 0x38, 0x1a,
+            },
+        },
+        .random_rsp[1] = {
+            .value = {
+                0x24, 0xb3, 0x47, 0xc8, 0xb0, 0xa2, 0xa3, 0xd8,
+                0x78, 0x3d, 0x09, 0x8d, 0xea, 0x49, 0xf6, 0x22,
+            },
+        },
+        .confirm_req[2] = {
+            .value = {
+                0x56, 0x5f, 0x07, 0x30, 0x3a, 0xc1, 0x44, 0xf9,
+                0x00, 0x03, 0xb3, 0x93, 0x58, 0xb4, 0x2c, 0x85,
+            },
+        },
+        .confirm_rsp[2] = {
+            .value = {
+                0x50, 0x8a, 0xb3, 0x0b, 0xe4, 0x2e, 0xd3, 0x49,
+                0x59, 0x40, 0xb2, 0x71, 0xc9, 0x49, 0x29, 0x19,
+            },
+        },
+        .random_req[2] = {
+            .value = {
+                0x32, 0x37, 0x8e, 0x63, 0x6d, 0xbd, 0xd6, 0x18,
+                0xee, 0xa7, 0x0e, 0xe5, 0x7e, 0x5f, 0xe1, 0x80,
+            },
+        },
+        .random_rsp[2] = {
+            .value = {
+                0xa2, 0x1a, 0x92, 0xcd, 0xc0, 0x8f, 0x92, 0xb0,
+                0xe6, 0xbe, 0x43, 0x55, 0xc8, 0x47, 0x56, 0x4b,
+            },
+        },
+        .confirm_req[3] = {
+            .value = {
+                0x1b, 0xa0, 0x82, 0xda, 0xfc, 0xaf, 0x3f, 0x9c,
+                0xdf, 0xff, 0xa2, 0x18, 0xba, 0xbd, 0x9b, 0x48,
+            },
+        },
+        .confirm_rsp[3] = {
+            .value = {
+                0x6a, 0x90, 0xb7, 0x1c, 0x93, 0x4e, 0x4a, 0x8b,
+                0xda, 0xe8, 0x13, 0x6e, 0x01, 0x91, 0x74, 0xb1,
+            },
+        },
+        .random_req[3] = {
+            .value = {
+                0x41, 0xbf, 0x60, 0x64, 0x1d, 0xfc, 0xe2, 0xee,
+                0x00, 0xa3, 0x2a, 0xb1, 0xf8, 0x34, 0x6b, 0xeb,
+            },
+        },
+        .random_rsp[3] = {
+            .value = {
+                0xeb, 0x9c, 0xaf, 0x20, 0x14, 0x0f, 0xf2, 0x3e,
+                0xee, 0x45, 0xca, 0xe8, 0xdc, 0x17, 0xab, 0x22,
+            },
+        },
+        .confirm_req[4] = {
+            .value = {
+                0x75, 0x8f, 0x97, 0xbb, 0x87, 0xa8, 0x70, 0xda,
+                0x94, 0x5a, 0xd6, 0x09, 0x78, 0xe3, 0xdd, 0x43,
+            },
+        },
+        .confirm_rsp[4] = {
+            .value = {
+                0x8c, 0x2d, 0xa7, 0x44, 0xd9, 0x15, 0xa8, 0x9e,
+                0xdf, 0x3a, 0x59, 0xa5, 0xee, 0x92, 0x24, 0x3c,
+            },
+        },
+        .random_req[4] = {
+            .value = {
+                0xb9, 0xe0, 0xf3, 0xf6, 0x6f, 0xbd, 0xa0, 0x7a,
+                0x82, 0x20, 0x61, 0xbe, 0xf3, 0xe6, 0x4e, 0xac,
+            },
+        },
+        .random_rsp[4] = {
+            .value = {
+                0xdd, 0x9b, 0xd3, 0x10, 0xed, 0x12, 0xe8, 0xb5,
+                0xa2, 0x59, 0xe1, 0xdc, 0x5c, 0xd8, 0x6e, 0x96,
+            },
+        },
+        .confirm_req[5] = {
+            .value = {
+                0x9d, 0xc7, 0x97, 0x67, 0x8d, 0xd0, 0xd6, 0x1a,
+                0x4d, 0x52, 0xc0, 0x8d, 0x87, 0xa9, 0x75, 0xf5,
+            },
+        },
+        .confirm_rsp[5] = {
+            .value = {
+                0xd4, 0x5d, 0x61, 0x76, 0x38, 0xe3, 0x81, 0x85,
+                0x18, 0x5f, 0xac, 0xde, 0x49, 0x57, 0xf6, 0x9b,
+            },
+        },
+        .random_req[5] = {
+            .value = {
+                0xfe, 0x83, 0xe9, 0xc6, 0xe9, 0xa4, 0x83, 0x0d,
+                0xaf, 0x27, 0x6f, 0x79, 0x7a, 0x2b, 0x2d, 0x1f,
+            },
+        },
+        .random_rsp[5] = {
+            .value = {
+                0xf2, 0x0c, 0x9e, 0x75, 0x5b, 0xb1, 0x8c, 0xf1,
+                0x46, 0x4f, 0x68, 0xe8, 0x0a, 0x65, 0xd5, 0x81,
+            },
+        },
+        .confirm_req[6] = {
+            .value = {
+                0x15, 0x2b, 0x2e, 0x14, 0xf7, 0x31, 0xa2, 0xff,
+                0x93, 0xa7, 0x28, 0x65, 0xb1, 0x68, 0x96, 0xc6,
+            },
+        },
+        .confirm_rsp[6] = {
+            .value = {
+                0x6f, 0x01, 0x22, 0x14, 0x78, 0xfb, 0x93, 0xf4,
+                0xfa, 0xf1, 0x6d, 0x33, 0x49, 0x0e, 0x7d, 0x56,
+            },
+        },
+        .random_req[6] = {
+            .value = {
+                0x05, 0xe5, 0xed, 0x99, 0x63, 0x05, 0x29, 0xb1,
+                0xbd, 0xf7, 0x2b, 0xa6, 0x94, 0xfe, 0x45, 0xb2,
+            },
+        },
+        .random_rsp[6] = {
+            .value = {
+                0x51, 0xf1, 0x2a, 0xa6, 0x7b, 0xe0, 0xb3, 0x20,
+                0x7d, 0x7e, 0xd3, 0x47, 0xfb, 0x83, 0xe1, 0xc6,
+            },
+        },
+        .confirm_req[7] = {
+            .value = {
+                0x9e, 0x7a, 0x3d, 0x12, 0x3b, 0x30, 0x81, 0x23,
+                0x1c, 0x94, 0x42, 0x73, 0x41, 0x68, 0xc6, 0x17,
+            },
+        },
+        .confirm_rsp[7] = {
+            .value = {
+                0x55, 0x31, 0x41, 0xe8, 0x1f, 0x11, 0xa6, 0x06,
+                0x7a, 0x7c, 0x84, 0x10, 0xad, 0xd3, 0x73, 0xcf,
+            },
+        },
+        .random_req[7] = {
+            .value = {
+                0xcb, 0x92, 0x18, 0xf6, 0x59, 0x6a, 0x1b, 0x18,
+                0x63, 0x72, 0x54, 0xc2, 0x1a, 0x3d, 0x09, 0x67,
+            },
+        },
+        .random_rsp[7] = {
+            .value = {
+                0xae, 0xf2, 0x96, 0xfd, 0xff, 0xd7, 0x18, 0xac,
+                0x5d, 0xb2, 0x9d, 0x89, 0x56, 0x2a, 0x19, 0xae,
+            },
+        },
+        .confirm_req[8] = {
+            .value = {
+                0x06, 0x8d, 0x5d, 0x19, 0xb3, 0x27, 0xc9, 0x6a,
+                0xe8, 0x58, 0xe7, 0x17, 0x10, 0x6a, 0xf9, 0xf7,
+            },
+        },
+        .confirm_rsp[8] = {
+            .value = {
+                0xf0, 0xbc, 0x2a, 0x03, 0x1f, 0x9b, 0x7b, 0x58,
+                0x43, 0x0f, 0xf5, 0x17, 0xc4, 0xbd, 0xec, 0x23,
+            },
+        },
+        .random_req[8] = {
+            .value = {
+                0xbe, 0x78, 0xcd, 0x84, 0x91, 0x4a, 0x1b, 0xdd,
+                0x6a, 0x0d, 0x88, 0x72, 0x9e, 0xc2, 0x4f, 0x5a,
+            },
+        },
+        .random_rsp[8] = {
+            .value = {
+                0xff, 0xac, 0xfe, 0x71, 0x2f, 0x6a, 0x13, 0xdc,
+                0xd3, 0x02, 0x81, 0x88, 0xbf, 0xc9, 0x9c, 0xd6,
+            },
+        },
+        .confirm_req[9] = {
+            .value = {
+                0xb0, 0x8d, 0x47, 0x23, 0x7e, 0xdb, 0xf5, 0x64,
+                0x5e, 0x83, 0x52, 0x9f, 0x06, 0x65, 0x84, 0x10,
+            },
+        },
+        .confirm_rsp[9] = {
+            .value = {
+                0x4d, 0x3f, 0xd4, 0x5a, 0x45, 0x57, 0xe9, 0xd7,
+                0x1e, 0x65, 0x7a, 0xa0, 0xd8, 0x5a, 0xa8, 0x29,
+            },
+        },
+        .random_req[9] = {
+            .value = {
+                0xb0, 0xcd, 0xfa, 0x39, 0x0d, 0x2e, 0x07, 0xfe,
+                0x36, 0x47, 0x8d, 0x8e, 0x1a, 0x47, 0x67, 0xf2,
+            },
+        },
+        .random_rsp[9] = {
+            .value = {
+                0xb4, 0xf5, 0x12, 0x64, 0xf4, 0xf6, 0xd7, 0x6e,
+                0xeb, 0x1e, 0x9a, 0x3f, 0x18, 0xba, 0xfb, 0x99,
+            },
+        },
+        .confirm_req[10] = {
+            .value = {
+                0xc9, 0x76, 0xb3, 0x3f, 0x80, 0xd9, 0x0c, 0xfb,
+                0xe3, 0x90, 0x1b, 0x7a, 0xbc, 0xe1, 0x7c, 0xde,
+            },
+        },
+        .confirm_rsp[10] = {
+            .value = {
+                0x21, 0x6a, 0x45, 0x6e, 0x6a, 0xac, 0xba, 0x9e,
+                0x66, 0x39, 0x5b, 0xb6, 0x74, 0xfe, 0x2b, 0x28,
+            },
+        },
+        .random_req[10] = {
+            .value = {
+                0xc0, 0xd4, 0xdf, 0x7b, 0x0f, 0x2f, 0xaa, 0x68,
+                0x4e, 0x3d, 0xa4, 0x59, 0x6f, 0x24, 0xe6, 0x7e,
+            },
+        },
+        .random_rsp[10] = {
+            .value = {
+                0xdf, 0x89, 0x49, 0xe7, 0x9f, 0x60, 0xdd, 0xf6,
+                0x44, 0x97, 0xe3, 0x15, 0x52, 0x65, 0x67, 0x3e,
+            },
+        },
+        .confirm_req[11] = {
+            .value = {
+                0xb0, 0x3f, 0x34, 0xce, 0x7d, 0x2e, 0xf1, 0xab,
+                0x23, 0xd5, 0x89, 0xf5, 0xaa, 0xa8, 0x59, 0x9f,
+            },
+        },
+        .confirm_rsp[11] = {
+            .value = {
+                0xb1, 0x33, 0x6a, 0x64, 0xd8, 0xeb, 0x8b, 0xa0,
+                0xf4, 0x1a, 0x15, 0x28, 0xb9, 0xe4, 0xa1, 0x31,
+            },
+        },
+        .random_req[11] = {
+            .value = {
+                0xd2, 0x88, 0x24, 0xfe, 0x95, 0x11, 0xc5, 0x0a,
+                0x21, 0xfb, 0x96, 0xea, 0x61, 0xb9, 0x8b, 0x26,
+            },
+        },
+        .random_rsp[11] = {
+            .value = {
+                0x8f, 0x22, 0x66, 0x8e, 0x7e, 0x62, 0x34, 0x37,
+                0xfc, 0x4a, 0x48, 0x1f, 0xf7, 0x38, 0x3b, 0x4e,
+            },
+        },
+        .confirm_req[12] = {
+            .value = {
+                0xc4, 0x50, 0xc8, 0x53, 0x58, 0xfb, 0xea, 0x9a,
+                0xdc, 0x35, 0xc7, 0xf3, 0x5b, 0x7c, 0xfb, 0xe4,
+            },
+        },
+        .confirm_rsp[12] = {
+            .value = {
+                0x27, 0xd9, 0x32, 0xd6, 0x43, 0xbf, 0x57, 0x3f,
+                0x35, 0x73, 0x3c, 0x3e, 0xbe, 0x53, 0x19, 0xff,
+            },
+        },
+        .random_req[12] = {
+            .value = {
+                0x99, 0xa1, 0x7a, 0x5f, 0xe0, 0x48, 0x1c, 0x6c,
+                0x84, 0xac, 0xab, 0xed, 0x69, 0x55, 0x1e, 0x66,
+            },
+        },
+        .random_rsp[12] = {
+            .value = {
+                0x37, 0x50, 0x90, 0x35, 0xef, 0x84, 0x06, 0x18,
+                0xfd, 0x3b, 0xc1, 0x8a, 0x46, 0x91, 0xb8, 0x21,
+            },
+        },
+        .confirm_req[13] = {
+            .value = {
+                0x2f, 0xcb, 0x3e, 0xc3, 0xce, 0x82, 0x0b, 0x5c,
+                0xdc, 0x9c, 0xbd, 0x44, 0xf9, 0x04, 0x22, 0x8c,
+            },
+        },
+        .confirm_rsp[13] = {
+            .value = {
+                0xab, 0xf2, 0x2e, 0x40, 0xd0, 0x74, 0x4f, 0xd4,
+                0x26, 0x9c, 0x89, 0x9e, 0x38, 0x77, 0xac, 0x9d,
+            },
+        },
+        .random_req[13] = {
+            .value = {
+                0xbc, 0xda, 0x58, 0xa2, 0x98, 0x88, 0xfe, 0x9f,
+                0x95, 0x0e, 0x3a, 0x91, 0xba, 0xe9, 0xbf, 0x02,
+            },
+        },
+        .random_rsp[13] = {
+            .value = {
+                0x04, 0xb9, 0x4c, 0x26, 0xce, 0x87, 0x8f, 0x17,
+                0xdc, 0xbc, 0x36, 0x94, 0x47, 0x67, 0x9f, 0xde,
+            },
+        },
+        .confirm_req[14] = {
+            .value = {
+                0xbd, 0xb6, 0x54, 0xc8, 0x1f, 0x51, 0x23, 0x98,
+                0x48, 0x3d, 0x47, 0x9d, 0xa3, 0xb8, 0xe7, 0x55,
+            },
+        },
+        .confirm_rsp[14] = {
+            .value = {
+                0x06, 0xc2, 0x7b, 0x80, 0x76, 0x9c, 0x37, 0x78,
+                0x46, 0xc5, 0x45, 0x43, 0x5d, 0x8d, 0x5b, 0x3e,
+            },
+        },
+        .random_req[14] = {
+            .value = {
+                0xef, 0x9e, 0x8a, 0x3a, 0xb7, 0xde, 0xa8, 0x07,
+                0x58, 0x73, 0xe0, 0x07, 0xfc, 0x62, 0xdb, 0x62,
+            },
+        },
+        .random_rsp[14] = {
+            .value = {
+                0xfa, 0xd5, 0xb2, 0x4e, 0x20, 0x01, 0x93, 0xc0,
+                0xb3, 0x76, 0xa5, 0x7a, 0x92, 0x8f, 0xb9, 0x6d,
+            },
+        },
+        .confirm_req[15] = {
+            .value = {
+                0x76, 0x2e, 0xc6, 0x64, 0x6c, 0x13, 0x01, 0x7e,
+                0x34, 0x78, 0x12, 0xb8, 0x1a, 0xb7, 0xf7, 0x39,
+            },
+        },
+        .confirm_rsp[15] = {
+            .value = {
+                0xbd, 0xae, 0x10, 0x32, 0xdb, 0x63, 0x30, 0x6f,
+                0x68, 0x19, 0x49, 0x5e, 0x34, 0x4f, 0x13, 0xc6,
+            },
+        },
+        .random_req[15] = {
+            .value = {
+                0x95, 0x2e, 0xe4, 0xe3, 0xb2, 0xdc, 0x79, 0xad,
+                0x5f, 0x0c, 0x19, 0x9c, 0x47, 0x9c, 0x79, 0x17,
+            },
+        },
+        .random_rsp[15] = {
+            .value = {
+                0x9e, 0x3d, 0x7f, 0xcd, 0x18, 0x40, 0xd7, 0xac,
+                0xa1, 0x45, 0x5f, 0xcb, 0x29, 0x57, 0x2b, 0x63,
+            },
+        },
+        .confirm_req[16] = {
+            .value = {
+                0x10, 0x18, 0x9d, 0xf2, 0xed, 0x76, 0x5c, 0x5f,
+                0x32, 0xa6, 0x29, 0x61, 0x12, 0xb2, 0xb8, 0xa2,
+            },
+        },
+        .confirm_rsp[16] = {
+            .value = {
+                0x3c, 0xd4, 0xbd, 0xe9, 0xd3, 0x29, 0xac, 0xf7,
+                0xfc, 0x04, 0xd3, 0xe4, 0x46, 0x14, 0x28, 0x2c,
+            },
+        },
+        .random_req[16] = {
+            .value = {
+                0x6d, 0xe8, 0x77, 0xc3, 0xab, 0x49, 0x6b, 0x79,
+                0x4f, 0x0f, 0x4c, 0x65, 0xc5, 0x77, 0x68, 0xd9,
+            },
+        },
+        .random_rsp[16] = {
+            .value = {
+                0xd0, 0x59, 0xf3, 0x53, 0xb1, 0x14, 0x81, 0x88,
+                0x26, 0x88, 0xef, 0x4b, 0xa4, 0x7d, 0x0a, 0x84,
+            },
+        },
+        .confirm_req[17] = {
+            .value = {
+                0xa3, 0x96, 0x9f, 0x96, 0x53, 0x0e, 0x38, 0x78,
+                0x9e, 0xbd, 0xf7, 0x65, 0x23, 0x73, 0x99, 0xa7,
+            },
+        },
+        .confirm_rsp[17] = {
+            .value = {
+                0x6b, 0x25, 0x8d, 0x51, 0xd8, 0xc4, 0xd9, 0xbf,
+                0xa6, 0x4f, 0xa3, 0x25, 0x28, 0xb5, 0x7c, 0x05,
+            },
+        },
+        .random_req[17] = {
+            .value = {
+                0xa5, 0xac, 0xd9, 0xb6, 0x9e, 0x98, 0x75, 0xae,
+                0x9b, 0x16, 0xe1, 0x60, 0xc6, 0xa5, 0x07, 0xf2,
+            },
+        },
+        .random_rsp[17] = {
+            .value = {
+                0x65, 0x53, 0x56, 0xe6, 0x2c, 0x22, 0x68, 0xc9,
+                0xb8, 0xbe, 0xb1, 0x40, 0x08, 0xe2, 0xb6, 0xb9,
+            },
+        },
+        .confirm_req[18] = {
+            .value = {
+                0x67, 0xcd, 0x0e, 0x4f, 0xfc, 0x38, 0x7f, 0x8a,
+                0x3b, 0xea, 0xff, 0x86, 0xf3, 0x8a, 0x92, 0xcb,
+            },
+        },
+        .confirm_rsp[18] = {
+            .value = {
+                0x22, 0x95, 0x1f, 0x20, 0xc9, 0x5c, 0x73, 0x39,
+                0xa4, 0xd9, 0xc1, 0x37, 0x9d, 0x94, 0xb2, 0xfd,
+            },
+        },
+        .random_req[18] = {
+            .value = {
+                0xe1, 0x80, 0x82, 0xdd, 0x21, 0x6c, 0xe4, 0x93,
+                0xa3, 0x41, 0x0f, 0xfc, 0x96, 0x42, 0x8b, 0xde,
+            },
+        },
+        .random_rsp[18] = {
+            .value = {
+                0x11, 0x1c, 0xd7, 0x7a, 0xe7, 0x1a, 0x88, 0xdd,
+                0x2a, 0xdf, 0xe5, 0x30, 0xca, 0x0b, 0x9f, 0xb6,
+            },
+        },
+        .confirm_req[19] = {
+            .value = {
+                0x45, 0x9b, 0x36, 0x3d, 0xf8, 0xc0, 0x43, 0x6d,
+                0x94, 0xcf, 0xbd, 0x5f, 0xfe, 0xec, 0xd7, 0x4b,
+            },
+        },
+        .confirm_rsp[19] = {
+            .value = {
+                0xf0, 0xaa, 0xfd, 0xae, 0xb7, 0x73, 0x3c, 0x9d,
+                0x93, 0xd4, 0x00, 0xea, 0x81, 0x31, 0xde, 0x41,
+            },
+        },
+        .random_req[19] = {
+            .value = {
+                0x1a, 0xaa, 0xff, 0x2a, 0xdc, 0xcc, 0x89, 0xbc,
+                0xcf, 0x48, 0x5c, 0x1e, 0x4d, 0x69, 0x85, 0x39,
+            },
+        },
+        .random_rsp[19] = {
+            .value = {
+                0xe7, 0xd0, 0xcb, 0x9a, 0xb5, 0x76, 0xec, 0xfc,
+                0x48, 0xa3, 0x41, 0x48, 0x4c, 0xa7, 0xec, 0xb7,
+            },
+        },
+        .dhkey_check_req = {
+            .value = {
+                0xe3, 0x4e, 0x42, 0xb5, 0xe3, 0x63, 0x4b, 0x7c,
+                0xf0, 0x9f, 0xef, 0x6e, 0x97, 0xe2, 0x86, 0xc0,
+            },
+        },
+        .dhkey_check_rsp = {
+            .value = {
+                0xea, 0x8a, 0xab, 0x7f, 0x15, 0x21, 0x5a, 0x36,
+                0x9b, 0x56, 0xee, 0x51, 0x61, 0x97, 0xe2, 0x0a,
+            },
+        },
+        .id_info_req = {
+            .irk = {
+                0xef, 0x8d, 0xe2, 0x16, 0x4f, 0xec, 0x43, 0x0d,
+                0xbf, 0x5b, 0xdd, 0x34, 0xc0, 0x53, 0x1e, 0xb8,
+            },
+        },
+        .id_addr_info_req = {
+            .addr_type = 0,
+            .bd_addr = {
+                0x33, 0x22, 0x11, 0x00, 0x45, 0x0a,
+            },
+        },
+        .sign_info_req = {
+            .sig_key = {
+                0x85, 0x54, 0x52, 0xe3, 0xb4, 0xe8, 0x26, 0xa4,
+                0x38, 0xb0, 0x4c, 0xa0, 0x41, 0xf5, 0x30, 0x6e,
+            },
+        },
+        .sign_info_rsp = {
+            .sig_key = {
+                0x6f, 0x93, 0xb8, 0x9c, 0x26, 0x88, 0xb4, 0x20,
+                0x87, 0x95, 0xf2, 0xf4, 0x3a, 0xbe, 0x92, 0xb7,
+            },
+        },
+        .ltk = {
+            0x30, 0xf6, 0xd3, 0x2e, 0x1c, 0x81, 0x2c, 0x96,
+            0x56, 0x30, 0x55, 0xec, 0x9b, 0x72, 0xf4, 0x83,
+        },
+        .pair_alg = BLE_SM_PAIR_ALG_PASSKEY,
+        .authenticated = 1,
+        .passkey_info = {
+            .passkey = {
+                .action = BLE_SM_IOACT_INPUT,
+                .passkey = 879894,
+            },
+        },
+    };
+    ble_sm_test_util_peer_sc_good(&params);
+}
+
+/**
+ * Secure connections pairing
+ * Master: peer
+ * Pair algorithm: passkey entry
+ * Initiator IO capabilities: 2
+ * Responder IO capabilities: 0
+ * Bonding: true
+ * Initiator address type: 0
+ * Responder address type: 0
+ * Initiator key distribution: 5
+ * Responder key distribution: 7
+ */
+TEST_CASE(ble_sm_sc_peer_pk_iio2_rio0_b1_iat0_rat0_ik5_rk7)
+{
+    struct ble_sm_test_sc_params params;
+
+    params = (struct ble_sm_test_sc_params) {
+        .init_addr = {
+            0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
+        },
+        .resp_addr = {
+            0x33, 0x22, 0x11, 0x00, 0x45, 0x0a,
+        },
+        .pair_req = {
+            .io_cap = 0x02,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x0d,
+            .resp_key_dist = 0x0f,
+        },
+        .pair_rsp = {
+            .io_cap = 0x00,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x05,
+            .resp_key_dist = 0x07,
+        },
+        .our_priv_key = {
+            0xd6, 0x2f, 0x4f, 0x6b, 0xeb, 0xfc, 0xbd, 0xee,
+            0x9b, 0x94, 0xd7, 0x15, 0x98, 0xc6, 0x0c, 0x83,
+            0x9b, 0xc7, 0xa2, 0x45, 0xfd, 0x00, 0xe8, 0xa4,
+            0x52, 0xe9, 0x70, 0x2f, 0xd7, 0x62, 0xf1, 0xa4,
+        },
+        .public_key_req = {
+            .x = {
+                0xd6, 0xa7, 0xaf, 0xc1, 0x18, 0x8b, 0x92, 0x2f,
+                0xbc, 0xbc, 0x4d, 0xb8, 0x5c, 0xfb, 0x39, 0x7c,
+                0x1e, 0x90, 0x7e, 0xfa, 0xa2, 0x0d, 0xee, 0x9e,
+                0xb4, 0x9e, 0xbe, 0x50, 0xf0, 0xbc, 0x2c, 0x10,
+            },
+            .y = {
+                0xa4, 0x25, 0xad, 0x75, 0xbe, 0xab, 0x1e, 0xcf,
+                0x4e, 0xc8, 0x19, 0xab, 0x6c, 0x68, 0x38, 0xa4,
+                0xe7, 0x43, 0x7b, 0x19, 0xef, 0x28, 0xd5, 0x93,
+                0x52, 0xe9, 0xb9, 0x31, 0x68, 0x60, 0x19, 0x71,
+            },
+        },
+        .public_key_rsp = {
+            .x = {
+                0xbc, 0x6a, 0xcf, 0xc6, 0x8a, 0x3a, 0xdc, 0x89,
+                0xdd, 0xa9, 0xaf, 0x29, 0xc7, 0xaf, 0xe2, 0x8b,
+                0x25, 0xee, 0xce, 0xa6, 0x10, 0x1d, 0x33, 0x2f,
+                0xd5, 0xfc, 0x30, 0xb8, 0xb1, 0x7b, 0xb1, 0x6e,
+            },
+            .y = {
+                0x1a, 0xc6, 0x42, 0x36, 0x98, 0x40, 0x4f, 0x90,
+                0x82, 0xa0, 0x10, 0x3a, 0xa5, 0x0f, 0xcf, 0x57,
+                0xd2, 0x2e, 0x80, 0x9d, 0x61, 0xc7, 0x21, 0xac,
+                0x47, 0x5b, 0x93, 0x75, 0x02, 0x30, 0x40, 0x14,
+            },
+        },
+        .confirm_req[0] = {
+            .value = {
+                0xd1, 0x64, 0x49, 0xa0, 0xc4, 0x28, 0x81, 0x57,
+                0x0c, 0x25, 0x62, 0xfb, 0x2c, 0xa2, 0xb0, 0xc7,
+            },
+        },
+        .confirm_rsp[0] = {
+            .value = {
+                0xea, 0xae, 0x4e, 0x03, 0x00, 0xf9, 0xd1, 0x65,
+                0xc7, 0x6a, 0x0d, 0x74, 0x4f, 0x02, 0x0b, 0x94,
+            },
+        },
+        .random_req[0] = {
+            .value = {
+                0x05, 0xb2, 0x09, 0x9b, 0x36, 0x23, 0x4f, 0x74,
+                0x4e, 0xc9, 0x7a, 0x2c, 0x65, 0x3a, 0xd1, 0xf6,
+            },
+        },
+        .random_rsp[0] = {
+            .value = {
+                0x50, 0xd8, 0x88, 0xd4, 0x7e, 0xc1, 0x36, 0x92,
+                0x0f, 0xa7, 0x17, 0x3c, 0xb4, 0xeb, 0xee, 0xa6,
+            },
+        },
+        .confirm_req[1] = {
+            .value = {
+                0xab, 0xa2, 0xd0, 0xec, 0xdd, 0xf3, 0xd2, 0xa9,
+                0x2d, 0xde, 0x4b, 0x02, 0x66, 0x45, 0x2f, 0xc0,
+            },
+        },
+        .confirm_rsp[1] = {
+            .value = {
+                0xa9, 0xc1, 0x9d, 0x75, 0xd0, 0xb6, 0xec, 0x06,
+                0x31, 0x87, 0xb6, 0x9d, 0x31, 0xdc, 0x92, 0x7c,
+            },
+        },
+        .random_req[1] = {
+            .value = {
+                0xb9, 0x5b, 0xe0, 0x0f, 0x83, 0xe7, 0x2d, 0x77,
+                0x2f, 0x55, 0x0a, 0x2c, 0xd9, 0xc1, 0x46, 0xcd,
+            },
+        },
+        .random_rsp[1] = {
+            .value = {
+                0xa2, 0x9a, 0x5b, 0x99, 0xb1, 0xc0, 0xc5, 0xd6,
+                0xf1, 0x87, 0x0b, 0x49, 0x9c, 0xfd, 0xfe, 0xd5,
+            },
+        },
+        .confirm_req[2] = {
+            .value = {
+                0x3a, 0x9d, 0x58, 0xe5, 0xb0, 0x31, 0xd9, 0xde,
+                0xac, 0xd2, 0x44, 0xb7, 0xe1, 0xe5, 0x89, 0x50,
+            },
+        },
+        .confirm_rsp[2] = {
+            .value = {
+                0xae, 0x4e, 0x4f, 0x84, 0x5f, 0x4c, 0xd1, 0x9b,
+                0x81, 0x22, 0x9c, 0x68, 0x52, 0xe0, 0x9a, 0xfc,
+            },
+        },
+        .random_req[2] = {
+            .value = {
+                0xa5, 0xbb, 0x5f, 0x9a, 0xa2, 0x97, 0xdb, 0xcd,
+                0x3d, 0xfe, 0xd9, 0x58, 0x21, 0x52, 0x99, 0xb7,
+            },
+        },
+        .random_rsp[2] = {
+            .value = {
+                0xea, 0x44, 0xdd, 0x0c, 0xbf, 0xb5, 0x6b, 0xc7,
+                0xe1, 0x19, 0xe8, 0x0b, 0xc2, 0x15, 0x04, 0x37,
+            },
+        },
+        .confirm_req[3] = {
+            .value = {
+                0xa8, 0xa3, 0xdb, 0x08, 0xca, 0x31, 0xd5, 0xef,
+                0x17, 0x37, 0x77, 0xd0, 0x64, 0x2e, 0x2f, 0x2f,
+            },
+        },
+        .confirm_rsp[3] = {
+            .value = {
+                0xe4, 0xf6, 0xa5, 0x94, 0x1a, 0x09, 0x4b, 0x75,
+                0x79, 0xb8, 0x0c, 0xe6, 0xe2, 0x28, 0x5a, 0x2c,
+            },
+        },
+        .random_req[3] = {
+            .value = {
+                0x1a, 0x3f, 0x80, 0x6f, 0xd3, 0xe8, 0xc5, 0xfb,
+                0x9b, 0xda, 0xa1, 0x07, 0x68, 0x1a, 0x54, 0xbc,
+            },
+        },
+        .random_rsp[3] = {
+            .value = {
+                0x1b, 0x48, 0x22, 0x87, 0x04, 0x24, 0x87, 0xba,
+                0x14, 0xb9, 0x85, 0xb2, 0xa6, 0xf5, 0xea, 0x89,
+            },
+        },
+        .confirm_req[4] = {
+            .value = {
+                0x31, 0xcb, 0xc4, 0x0c, 0x36, 0xb5, 0xe2, 0x32,
+                0xd8, 0x0e, 0xd3, 0x86, 0x96, 0xe3, 0x8c, 0x84,
+            },
+        },
+        .confirm_rsp[4] = {
+            .value = {
+                0x90, 0x11, 0x30, 0x35, 0x5f, 0xe5, 0x45, 0xff,
+                0xab, 0xd3, 0xe0, 0xbe, 0x1c, 0x20, 0x23, 0xb8,
+            },
+        },
+        .random_req[4] = {
+            .value = {
+                0xa0, 0xc7, 0x79, 0x28, 0x87, 0x19, 0xa3, 0x78,
+                0x33, 0xe5, 0x1a, 0x81, 0xba, 0x9b, 0xe3, 0x5c,
+            },
+        },
+        .random_rsp[4] = {
+            .value = {
+                0x43, 0xcf, 0x20, 0x1b, 0x39, 0x3f, 0xdf, 0x73,
+                0x58, 0xd2, 0x0d, 0xc7, 0x41, 0xd7, 0x58, 0xea,
+            },
+        },
+        .confirm_req[5] = {
+            .value = {
+                0x59, 0xda, 0x78, 0xeb, 0xd5, 0xcd, 0x8e, 0x23,
+                0xe5, 0x5e, 0xa7, 0xa5, 0xba, 0x13, 0x00, 0xff,
+            },
+        },
+        .confirm_rsp[5] = {
+            .value = {
+                0x31, 0x7a, 0xf0, 0x56, 0x82, 0x69, 0xdb, 0xcd,
+                0x27, 0x5a, 0x11, 0xd3, 0x65, 0x82, 0x0d, 0xda,
+            },
+        },
+        .random_req[5] = {
+            .value = {
+                0x2e, 0xe8, 0x76, 0x40, 0x9c, 0x49, 0x07, 0x42,
+                0x1e, 0x45, 0x7b, 0x1e, 0x73, 0xa3, 0x71, 0x05,
+            },
+        },
+        .random_rsp[5] = {
+            .value = {
+                0x64, 0x99, 0x42, 0x5d, 0x05, 0xd6, 0x12, 0x41,
+                0x2a, 0x44, 0x55, 0x26, 0xe7, 0x08, 0x5e, 0xfb,
+            },
+        },
+        .confirm_req[6] = {
+            .value = {
+                0x1c, 0x55, 0xe1, 0x75, 0x4f, 0x6e, 0xdd, 0x7e,
+                0xc8, 0xff, 0x76, 0x25, 0xdb, 0x2a, 0x6d, 0xe3,
+            },
+        },
+        .confirm_rsp[6] = {
+            .value = {
+                0xf6, 0x36, 0x78, 0x88, 0x62, 0xa8, 0x78, 0xe6,
+                0xf9, 0xa1, 0x17, 0x63, 0x86, 0xd3, 0xae, 0x60,
+            },
+        },
+        .random_req[6] = {
+            .value = {
+                0x96, 0x9a, 0x1c, 0xbe, 0x82, 0x82, 0xc2, 0xa7,
+                0x18, 0xc3, 0x7b, 0x40, 0x5d, 0x6c, 0x4e, 0xe3,
+            },
+        },
+        .random_rsp[6] = {
+            .value = {
+                0x2b, 0x7d, 0x36, 0xc3, 0xf7, 0x59, 0x63, 0x40,
+                0x6f, 0xc0, 0x2a, 0x2b, 0x1b, 0xd7, 0x41, 0x38,
+            },
+        },
+        .confirm_req[7] = {
+            .value = {
+                0x88, 0x99, 0x53, 0xae, 0x2a, 0xaf, 0x97, 0x5a,
+                0xcc, 0x9f, 0xfd, 0xe2, 0x1d, 0xd3, 0x27, 0x66,
+            },
+        },
+        .confirm_rsp[7] = {
+            .value = {
+                0xdb, 0xae, 0xfb, 0xf7, 0x33, 0xd4, 0xd1, 0xcb,
+                0xfe, 0x75, 0x8e, 0x81, 0x16, 0xd1, 0x49, 0xeb,
+            },
+        },
+        .random_req[7] = {
+            .value = {
+                0x13, 0x5c, 0x00, 0x34, 0xe5, 0x96, 0xd0, 0x97,
+                0xb1, 0x84, 0x3d, 0x00, 0xb4, 0x2a, 0x4a, 0x12,
+            },
+        },
+        .random_rsp[7] = {
+            .value = {
+                0xed, 0x94, 0x1f, 0x41, 0x12, 0xe5, 0x35, 0x5b,
+                0xa6, 0x6a, 0x72, 0x1e, 0xa2, 0x7c, 0xe1, 0x6c,
+            },
+        },
+        .confirm_req[8] = {
+            .value = {
+                0xa3, 0xc7, 0x17, 0xad, 0xb6, 0xe6, 0xaa, 0x16,
+                0x8d, 0x4b, 0x70, 0x5f, 0x49, 0x73, 0xa7, 0x19,
+            },
+        },
+        .confirm_rsp[8] = {
+            .value = {
+                0x10, 0xb0, 0x31, 0xa7, 0x16, 0x61, 0xf7, 0xd6,
+                0xe6, 0x16, 0x9e, 0xb1, 0x9e, 0xb5, 0x5e, 0x94,
+            },
+        },
+        .random_req[8] = {
+            .value = {
+                0x6f, 0xe7, 0x62, 0x73, 0xfb, 0xbf, 0xf1, 0x4a,
+                0x14, 0xa1, 0x09, 0x45, 0xd4, 0xde, 0x26, 0xad,
+            },
+        },
+        .random_rsp[8] = {
+            .value = {
+                0x3f, 0x48, 0xa7, 0xdf, 0x4a, 0xd5, 0x55, 0x26,
+                0xd3, 0x32, 0xbf, 0x98, 0x4a, 0x20, 0xad, 0xb0,
+            },
+        },
+        .confirm_req[9] = {
+            .value = {
+                0x88, 0x1c, 0xef, 0xfe, 0x4e, 0x68, 0x41, 0x7c,
+                0xe8, 0xe8, 0x81, 0x1a, 0xb9, 0x9e, 0xaf, 0xc6,
+            },
+        },
+        .confirm_rsp[9] = {
+            .value = {
+                0xa3, 0x53, 0x2a, 0xe1, 0xbd, 0x9d, 0xbe, 0x89,
+                0xf8, 0xc7, 0x70, 0x6e, 0xa9, 0x12, 0x07, 0x0d,
+            },
+        },
+        .random_req[9] = {
+            .value = {
+                0x52, 0x06, 0x56, 0x09, 0xf4, 0xb2, 0xb9, 0x63,
+                0x3f, 0x2e, 0x59, 0x6c, 0x6b, 0x43, 0xb6, 0xc0,
+            },
+        },
+        .random_rsp[9] = {
+            .value = {
+                0x36, 0xb0, 0x33, 0x84, 0x52, 0xd1, 0x60, 0xac,
+                0x37, 0x81, 0x6b, 0x18, 0x5f, 0xfc, 0x61, 0xb1,
+            },
+        },
+        .confirm_req[10] = {
+            .value = {
+                0xc8, 0x55, 0xb7, 0x9e, 0x3e, 0xf0, 0x26, 0xa4,
+                0x55, 0xb3, 0x1d, 0x4d, 0xa1, 0x5d, 0xa9, 0xaf,
+            },
+        },
+        .confirm_rsp[10] = {
+            .value = {
+                0xb7, 0xb9, 0x6b, 0x8e, 0xef, 0xd3, 0xbc, 0x58,
+                0x10, 0xbe, 0x5a, 0x9a, 0x4d, 0xbc, 0xec, 0xe3,
+            },
+        },
+        .random_req[10] = {
+            .value = {
+                0x55, 0xa1, 0xf4, 0xd7, 0xfa, 0xe1, 0x84, 0x03,
+                0xed, 0xb6, 0x95, 0x63, 0x4b, 0x93, 0x93, 0xc2,
+            },
+        },
+        .random_rsp[10] = {
+            .value = {
+                0x72, 0xa9, 0xe5, 0xf7, 0x48, 0x1f, 0x64, 0x71,
+                0xd9, 0x81, 0xf0, 0xc5, 0x4d, 0x38, 0xac, 0x9a,
+            },
+        },
+        .confirm_req[11] = {
+            .value = {
+                0x12, 0x37, 0x56, 0xa6, 0x66, 0xa1, 0x23, 0xee,
+                0xe3, 0x1e, 0x20, 0x66, 0x66, 0x85, 0x7c, 0xa8,
+            },
+        },
+        .confirm_rsp[11] = {
+            .value = {
+                0x74, 0xaa, 0xbb, 0x5a, 0xdf, 0xd9, 0xc4, 0xaf,
+                0xe4, 0xa7, 0xe6, 0x4b, 0x45, 0x97, 0xf8, 0x7d,
+            },
+        },
+        .random_req[11] = {
+            .value = {
+                0x29, 0xce, 0xcc, 0xb7, 0xb2, 0x1e, 0x0e, 0xa8,
+                0x48, 0x90, 0x43, 0x6d, 0x34, 0xa4, 0xa3, 0x12,
+            },
+        },
+        .random_rsp[11] = {
+            .value = {
+                0x2e, 0xaf, 0x4c, 0x63, 0x84, 0x2c, 0x62, 0x67,
+                0x68, 0x8f, 0x0b, 0xfd, 0xff, 0xef, 0x15, 0x26,
+            },
+        },
+        .confirm_req[12] = {
+            .value = {
+                0xec, 0xcf, 0x6a, 0x60, 0x77, 0x04, 0x2c, 0x62,
+                0x42, 0xf0, 0x21, 0xfd, 0x53, 0xd6, 0x8a, 0xe8,
+            },
+        },
+        .confirm_rsp[12] = {
+            .value = {
+                0x2c, 0x13, 0x65, 0x69, 0xd7, 0x66, 0x04, 0x13,
+                0x3c, 0xa8, 0xfb, 0xe5, 0x76, 0xbb, 0x4f, 0x48,
+            },
+        },
+        .random_req[12] = {
+            .value = {
+                0x0d, 0x93, 0x30, 0xe2, 0x76, 0xf1, 0xbc, 0x24,
+                0x61, 0x0d, 0xcd, 0xef, 0x33, 0x98, 0xe2, 0x3b,
+            },
+        },
+        .random_rsp[12] = {
+            .value = {
+                0xb6, 0x32, 0x69, 0x81, 0xc0, 0x81, 0x46, 0xae,
+                0x8d, 0x5a, 0x17, 0xb5, 0xc0, 0x0f, 0x9f, 0x4e,
+            },
+        },
+        .confirm_req[13] = {
+            .value = {
+                0x89, 0x96, 0x22, 0x0c, 0x76, 0xdf, 0x27, 0x13,
+                0x96, 0x5a, 0x0c, 0x88, 0x65, 0x18, 0x74, 0x52,
+            },
+        },
+        .confirm_rsp[13] = {
+            .value = {
+                0x1c, 0x77, 0x25, 0x22, 0xc0, 0x28, 0x88, 0x45,
+                0x29, 0x62, 0x7a, 0x8e, 0xc0, 0x2a, 0x5c, 0xd8,
+            },
+        },
+        .random_req[13] = {
+            .value = {
+                0xcc, 0x84, 0xb6, 0x98, 0x3e, 0xf9, 0x09, 0xd2,
+                0x71, 0x47, 0x56, 0xb1, 0x09, 0xf5, 0xd2, 0x0b,
+            },
+        },
+        .random_rsp[13] = {
+            .value = {
+                0xf0, 0xcf, 0x1c, 0xa6, 0x24, 0xcd, 0xfa, 0x42,
+                0xa4, 0x93, 0x8b, 0xa0, 0xe3, 0x42, 0x72, 0x51,
+            },
+        },
+        .confirm_req[14] = {
+            .value = {
+                0xab, 0xb0, 0xa3, 0x80, 0x0d, 0xcb, 0x8e, 0xf6,
+                0x6c, 0x07, 0x50, 0xe9, 0x8a, 0x85, 0x02, 0xae,
+            },
+        },
+        .confirm_rsp[14] = {
+            .value = {
+                0xf6, 0x52, 0xd8, 0x34, 0x15, 0x62, 0x9f, 0x6e,
+                0x2b, 0x52, 0xdc, 0x1c, 0x70, 0x17, 0x0a, 0x31,
+            },
+        },
+        .random_req[14] = {
+            .value = {
+                0x8d, 0xc9, 0x0a, 0x45, 0xe9, 0x81, 0x0d, 0x5e,
+                0xbb, 0xd8, 0x94, 0x29, 0x68, 0x42, 0x44, 0xe2,
+            },
+        },
+        .random_rsp[14] = {
+            .value = {
+                0x96, 0x2a, 0x35, 0x39, 0x09, 0xf7, 0x66, 0x5a,
+                0xb6, 0x33, 0x77, 0x6d, 0xba, 0xd3, 0x8a, 0xfb,
+            },
+        },
+        .confirm_req[15] = {
+            .value = {
+                0x53, 0x08, 0x9b, 0x37, 0xc3, 0x79, 0xe6, 0x8c,
+                0x42, 0x30, 0x94, 0x73, 0x6f, 0x39, 0x64, 0x20,
+            },
+        },
+        .confirm_rsp[15] = {
+            .value = {
+                0x4d, 0xb7, 0xe9, 0x50, 0x8e, 0x0f, 0xe0, 0xd5,
+                0x3e, 0xf6, 0x32, 0xdd, 0xb8, 0x18, 0x77, 0xd3,
+            },
+        },
+        .random_req[15] = {
+            .value = {
+                0x8d, 0x49, 0x14, 0xdd, 0x95, 0x57, 0x55, 0x14,
+                0x48, 0x97, 0xd3, 0x73, 0x29, 0xa0, 0xb9, 0x2b,
+            },
+        },
+        .random_rsp[15] = {
+            .value = {
+                0xcf, 0x38, 0x8b, 0xab, 0xe4, 0x2b, 0x3f, 0x13,
+                0xc3, 0xfb, 0x07, 0xee, 0x0e, 0x33, 0x2f, 0x04,
+            },
+        },
+        .confirm_req[16] = {
+            .value = {
+                0xc6, 0x58, 0x13, 0x19, 0x56, 0x06, 0x52, 0x4b,
+                0x3d, 0x5e, 0x9d, 0xa8, 0x48, 0xf2, 0x40, 0xf3,
+            },
+        },
+        .confirm_rsp[16] = {
+            .value = {
+                0xbb, 0x93, 0xd2, 0xed, 0x89, 0x66, 0xa5, 0x1c,
+                0xc9, 0x2a, 0x42, 0x2c, 0xff, 0x4a, 0x80, 0x84,
+            },
+        },
+        .random_req[16] = {
+            .value = {
+                0x3d, 0x9c, 0x11, 0x2a, 0xd3, 0xce, 0x4b, 0x20,
+                0xf2, 0xfb, 0xdd, 0x18, 0x4d, 0x7c, 0x58, 0xb6,
+            },
+        },
+        .random_rsp[16] = {
+            .value = {
+                0xda, 0x80, 0x63, 0x9d, 0xa2, 0x73, 0x61, 0xdd,
+                0x9a, 0x45, 0x91, 0x4d, 0x78, 0x39, 0x54, 0x75,
+            },
+        },
+        .confirm_req[17] = {
+            .value = {
+                0x2e, 0xe4, 0x44, 0xe8, 0xdb, 0xc2, 0xbd, 0x62,
+                0xd1, 0xc4, 0x23, 0x4e, 0x5f, 0x65, 0xb6, 0x3b,
+            },
+        },
+        .confirm_rsp[17] = {
+            .value = {
+                0x19, 0x91, 0xa3, 0xc7, 0x3b, 0x68, 0x12, 0x24,
+                0xcd, 0xd6, 0x02, 0xf5, 0xcd, 0x19, 0x6c, 0x88,
+            },
+        },
+        .random_req[17] = {
+            .value = {
+                0xf0, 0x28, 0x18, 0xe8, 0xa7, 0x3e, 0xd8, 0x21,
+                0x42, 0x58, 0xb3, 0x72, 0xa0, 0x34, 0x89, 0x04,
+            },
+        },
+        .random_rsp[17] = {
+            .value = {
+                0xe9, 0xff, 0x0b, 0x9a, 0xfd, 0x29, 0x95, 0x37,
+                0x89, 0x2c, 0x84, 0xfa, 0x02, 0xa0, 0xb6, 0xeb,
+            },
+        },
+        .confirm_req[18] = {
+            .value = {
+                0x4f, 0x90, 0x70, 0xbe, 0xc4, 0x81, 0x9f, 0xc1,
+                0x74, 0xa3, 0x01, 0x2e, 0x78, 0x7a, 0xe2, 0x61,
+            },
+        },
+        .confirm_rsp[18] = {
+            .value = {
+                0xbb, 0xd5, 0x91, 0xec, 0x81, 0xe0, 0x9b, 0x5e,
+                0xe9, 0xd2, 0x93, 0x57, 0xa8, 0x27, 0xdd, 0x9b,
+            },
+        },
+        .random_req[18] = {
+            .value = {
+                0x78, 0xa4, 0x35, 0x1a, 0xbc, 0xa7, 0x19, 0x8c,
+                0x96, 0x8f, 0x63, 0x9d, 0x11, 0xee, 0x27, 0x44,
+            },
+        },
+        .random_rsp[18] = {
+            .value = {
+                0x39, 0x5b, 0x71, 0xfd, 0x7e, 0x39, 0x6b, 0xbe,
+                0xaf, 0xe1, 0x55, 0x90, 0xa6, 0x58, 0xec, 0xc5,
+            },
+        },
+        .confirm_req[19] = {
+            .value = {
+                0x91, 0x43, 0xe5, 0xc8, 0x26, 0x0c, 0x8c, 0x6c,
+                0xf3, 0xd1, 0x30, 0xb3, 0x22, 0x94, 0x4c, 0x67,
+            },
+        },
+        .confirm_rsp[19] = {
+            .value = {
+                0x51, 0xc4, 0x3e, 0x09, 0xca, 0x03, 0xbe, 0x2c,
+                0xe8, 0x1a, 0x5d, 0x07, 0x12, 0x14, 0x2d, 0x43,
+            },
+        },
+        .random_req[19] = {
+            .value = {
+                0x2f, 0xa1, 0x20, 0xde, 0xf5, 0xb4, 0xa6, 0x92,
+                0x31, 0xe9, 0x86, 0x63, 0xef, 0xc1, 0x85, 0x3b,
+            },
+        },
+        .random_rsp[19] = {
+            .value = {
+                0x41, 0xd0, 0xd0, 0x96, 0x93, 0xd1, 0xcb, 0xed,
+                0xab, 0x27, 0xd5, 0x88, 0x5e, 0xe6, 0x5e, 0x5c,
+            },
+        },
+        .dhkey_check_req = {
+            .value = {
+                0xec, 0xc5, 0x5f, 0xf3, 0xae, 0xfe, 0x79, 0x65,
+                0x17, 0x5a, 0x60, 0xf7, 0x36, 0x4f, 0x90, 0x45,
+            },
+        },
+        .dhkey_check_rsp = {
+            .value = {
+                0xa7, 0x45, 0x7a, 0x54, 0x1b, 0x64, 0x08, 0x60,
+                0x51, 0x7d, 0x74, 0x27, 0x48, 0xa2, 0xf1, 0x0f,
+            },
+        },
+        .id_info_req = {
+            .irk = {
+                0xef, 0x8d, 0xe2, 0x16, 0x4f, 0xec, 0x43, 0x0d,
+                0xbf, 0x5b, 0xdd, 0x34, 0xc0, 0x53, 0x1e, 0xb8,
+            },
+        },
+        .id_addr_info_req = {
+            .addr_type = 0,
+            .bd_addr = {
+                0x33, 0x22, 0x11, 0x00, 0x45, 0x0a,
+            },
+        },
+        .sign_info_req = {
+            .sig_key = {
+                0x36, 0x9a, 0xd9, 0x25, 0x5c, 0xdb, 0x78, 0xdc,
+                0x1d, 0x2c, 0x83, 0xf7, 0xde, 0x99, 0xa0, 0x66,
+            },
+        },
+        .sign_info_rsp = {
+            .sig_key = {
+                0x61, 0x6e, 0x9a, 0x26, 0xc5, 0xd0, 0x85, 0xdc,
+                0xea, 0x9d, 0xca, 0x3b, 0x17, 0xd7, 0x43, 0x80,
+            },
+        },
+        .ltk = {
+            0xd6, 0x02, 0xba, 0x3d, 0xa2, 0xce, 0x93, 0x1a,
+            0xfd, 0xd6, 0xb5, 0x54, 0x90, 0xc4, 0x2a, 0x8f,
+        },
+        .pair_alg = BLE_SM_PAIR_ALG_PASSKEY,
+        .authenticated = 1,
+        .passkey_info = {
+            .passkey = {
+                .action = BLE_SM_IOACT_DISP,
+                .passkey = 222333,
+            },
+        },
+    };
+    ble_sm_test_util_peer_sc_good(&params);
+}
+
+/**
+ * Secure connections pairing
+ * Master: peer
+ * Pair algorithm: numeric comparison
+ * Initiator IO capabilities: 1
+ * Responder IO capabilities: 1
+ * Bonding: true
+ * Initiator address type: 0
+ * Responder address type: 0
+ * Initiator key distribution: 5
+ * Responder key distribution: 7
+ */
+TEST_CASE(ble_sm_sc_peer_nc_iio1_rio1_b1_iat0_rat0_ik5_rk7)
+{
+    struct ble_sm_test_sc_params params;
+
+    params = (struct ble_sm_test_sc_params) {
+        .init_addr = {
+            0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
+        },
+        .resp_addr = {
+            0x33, 0x22, 0x11, 0x00, 0x45, 0x0a,
+        },
+        .pair_req = {
+            .io_cap = 0x01,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x0d,
+            .resp_key_dist = 0x0f,
+        },
+        .pair_rsp = {
+            .io_cap = 0x01,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x05,
+            .resp_key_dist = 0x07,
+        },
+        .our_priv_key = {
+            0xd6, 0x2f, 0x4f, 0x6b, 0xeb, 0xfc, 0xbd, 0xee,
+            0x9b, 0x94, 0xd7, 0x15, 0x98, 0xc6, 0x0c, 0x83,
+            0x9b, 0xc7, 0xa2, 0x45, 0xfd, 0x00, 0xe8, 0xa4,
+            0x52, 0xe9, 0x70, 0x2f, 0xd7, 0x62, 0xf1, 0xa4,
+        },
+        .public_key_req = {
+            .x = {
+                0x41, 0x0d, 0x95, 0x8a, 0x68, 0xb8, 0xcf, 0x07,
+                0x58, 0x25, 0x5f, 0x97, 0xd2, 0x99, 0x71, 0x44,
+                0x06, 0xfc, 0x9c, 0x4d, 0xd1, 0x74, 0x80, 0xed,
+                0x49, 0xd1, 0x36, 0x6b, 0x55, 0x8b, 0x54, 0x3b,
+            },
+            .y = {
+                0x0f, 0x1a, 0x61, 0x45, 0xe5, 0x4b, 0x11, 0x13,
+                0xb3, 0x15, 0x87, 0x09, 0xec, 0x16, 0xf8, 0x41,
+                0x2e, 0xe2, 0x15, 0x93, 0x14, 0x56, 0x9f, 0xcd,
+                0x60, 0x7d, 0x92, 0xec, 0xd3, 0xb5, 0x85, 0xc5,
+            },
+        },
+        .public_key_rsp = {
+            .x = {
+                0xbc, 0x6a, 0xcf, 0xc6, 0x8a, 0x3a, 0xdc, 0x89,
+                0xdd, 0xa9, 0xaf, 0x29, 0xc7, 0xaf, 0xe2, 0x8b,
+                0x25, 0xee, 0xce, 0xa6, 0x10, 0x1d, 0x33, 0x2f,
+                0xd5, 0xfc, 0x30, 0xb8, 0xb1, 0x7b, 0xb1, 0x6e,
+            },
+            .y = {
+                0x1a, 0xc6, 0x42, 0x36, 0x98, 0x40, 0x4f, 0x90,
+                0x82, 0xa0, 0x10, 0x3a, 0xa5, 0x0f, 0xcf, 0x57,
+                0xd2, 0x2e, 0x80, 0x9d, 0x61, 0xc7, 0x21, 0xac,
+                0x47, 0x5b, 0x93, 0x75, 0x02, 0x30, 0x40, 0x14,
+            },
+        },
+        .confirm_rsp[0] = {
+            .value = {
+                0x73, 0xc8, 0x56, 0x5e, 0x33, 0x37, 0x26, 0xb6,
+                0x00, 0x65, 0x9c, 0xa1, 0xee, 0xbf, 0x61, 0xf6,
+            },
+        },
+        .random_req[0] = {
+            .value = {
+                0x7c, 0x23, 0x03, 0x70, 0x54, 0xa2, 0x70, 0xe4,
+                0x2d, 0xe9, 0x88, 0x6f, 0x40, 0xd6, 0x2f, 0xb2,
+            },
+        },
+        .random_rsp[0] = {
+            .value = {
+                0x2d, 0x9f, 0xe8, 0x1d, 0xf2, 0x4e, 0x2e, 0x58,
+                0x16, 0x8c, 0x83, 0x89, 0x92, 0x70, 0xa2, 0xba,
+            },
+        },
+        .dhkey_check_req = {
+            .value = {
+                0xc0, 0x8a, 0x1c, 0xff, 0x7f, 0xd6, 0xbc, 0xee,
+                0x19, 0xa5, 0xc6, 0x3a, 0xbd, 0x48, 0x4b, 0xc3,
+            },
+        },
+        .dhkey_check_rsp = {
+            .value = {
+                0x38, 0x36, 0x83, 0xd5, 0x1a, 0xfb, 0xe6, 0x3c,
+                0x80, 0x0c, 0x81, 0x81, 0x78, 0x12, 0x41, 0x38,
+            },
+        },
+        .id_info_req = {
+            .irk = {
+                0xef, 0x8d, 0xe2, 0x16, 0x4f, 0xec, 0x43, 0x0d,
+                0xbf, 0x5b, 0xdd, 0x34, 0xc0, 0x53, 0x1e, 0xb8,
+            },
+        },
+        .id_addr_info_req = {
+            .addr_type = 0,
+            .bd_addr = {
+                0x33, 0x22, 0x11, 0x00, 0x45, 0x0a,
+            },
+        },
+        .sign_info_req = {
+            .sig_key = {
+                0x52, 0xf4, 0xcc, 0x2f, 0xc6, 0xc1, 0xdb, 0x07,
+                0xa5, 0x38, 0xc1, 0x09, 0x82, 0x2e, 0xa3, 0x53,
+            },
+        },
+        .sign_info_rsp = {
+            .sig_key = {
+                0xc1, 0xa3, 0x62, 0x6a, 0x9e, 0xaa, 0x37, 0xd9,
+                0x65, 0x9f, 0x7f, 0x5d, 0x62, 0x0c, 0x1c, 0x6c,
+            },
+        },
+        .ltk = {
+            0xd8, 0x7f, 0x0a, 0x94, 0x41, 0xa5, 0xfd, 0x84,
+            0x15, 0x01, 0xb7, 0x2a, 0x7a, 0xe4, 0xfd, 0xfb,
+        },
+        .pair_alg = BLE_SM_PAIR_ALG_NUMCMP,
+        .authenticated = 1,
+        .passkey_info = {
+            .passkey = {
+                .action = BLE_SM_IOACT_NUMCMP,
+                .numcmp_accept = 1,
+            },
+            .exp_numcmp = 516214,
+        },
+    };
+    ble_sm_test_util_peer_sc_good(&params);
+}
+
+/**
+ * Secure connections pairing
+ * Master: us
+ * Pair algorithm: just works
+ * Initiator IO capabilities: 3
+ * Responder IO capabilities: 4
+ * Bonding: true
+ * Initiator address type: 0
+ * Responder address type: 0
+ * Initiator key distribution: 7
+ * Responder key distribution: 5
+ */
+TEST_CASE(ble_sm_sc_us_jw_iio3_rio4_b1_iat0_rat0_ik7_rk5)
+{
+    struct ble_sm_test_sc_params params;
+
+    params = (struct ble_sm_test_sc_params) {
+        .init_addr = {
+            0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
+        },
+        .resp_addr = {
+            0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
+        },
+        .pair_req = {
+            .io_cap = 0x03,
+            .oob_data_flag = 0x00,
+            .authreq = 0x09,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x07,
+            .resp_key_dist = 0x07,
+        },
+        .pair_rsp = {
+            .io_cap = 0x04,
+            .oob_data_flag = 0x00,
+            .authreq = 0x09,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x07,
+            .resp_key_dist = 0x05,
+        },
+        .our_priv_key = {
+            0xaf, 0xce, 0x12, 0x45, 0xa8, 0xe0, 0xa9, 0x45,
+            0x8a, 0x56, 0xc5, 0xbf, 0x3b, 0xf9, 0x04, 0x69,
+            0xf2, 0xf9, 0xe4, 0xd4, 0x7e, 0xb7, 0xc9, 0x65,
+            0xb1, 0x68, 0x3e, 0xab, 0xcd, 0x8e, 0x6f, 0x1f,
+        },
+        .public_key_req = {
+            .x = {
+                0x45, 0xca, 0xda, 0xe3, 0x65, 0x7c, 0xf5, 0x37,
+                0x36, 0x66, 0x8b, 0x3b, 0x54, 0xb9, 0x2b, 0xb2,
+                0x09, 0xd5, 0x6e, 0xe0, 0x04, 0x1d, 0xd6, 0x49,
+                0xff, 0x55, 0x41, 0x35, 0xa0, 0x2f, 0x12, 0xee,
+            },
+            .y = {
+                0x65, 0x41, 0xd3, 0x7b, 0x59, 0xf2, 0xaf, 0x94,
+                0x78, 0xd8, 0x63, 0xc4, 0x9b, 0x9a, 0x9a, 0x92,
+                0x33, 0x0f, 0x14, 0x67, 0x98, 0x51, 0x9d, 0xff,
+                0xef, 0x59, 0xb7, 0x17, 0xc2, 0x16, 0x72, 0x18,
+            },
+        },
+        .public_key_rsp = {
+            .x = {
+                0x9e, 0x44, 0x09, 0x57, 0xb7, 0x01, 0x78, 0x5b,
+                0x4e, 0x50, 0x0d, 0x99, 0x0d, 0x52, 0x88, 0x24,
+                0x19, 0xf5, 0x40, 0x53, 0x06, 0x1e, 0x68, 0xd0,
+                0xfd, 0xd2, 0x84, 0x8b, 0xae, 0x9d, 0xf7, 0xd9,
+            },
+            .y = {
+                0xc2, 0xe7, 0xe0, 0x01, 0xb3, 0x2a, 0x1b, 0x01,
+                0x19, 0xd1, 0x14, 0xb5, 0xc8, 0x98, 0x02, 0x2a,
+                0xbe, 0x6b, 0x33, 0x1a, 0x99, 0x18, 0x77, 0x23,
+                0xd4, 0x8b, 0x8c, 0x09, 0xf5, 0x77, 0x20, 0xa0,
+            },
+        },
+        .confirm_rsp[0] = {
+            .value = {
+                0xbd, 0x85, 0xbe, 0x80, 0xd9, 0x77, 0x16, 0xa3,
+                0x65, 0x1a, 0xdf, 0xff, 0x5a, 0x6f, 0x8b, 0x37,
+            },
+        },
+        .random_req[0] = {
+            .value = {
+                0xb5, 0x59, 0x7c, 0x8e, 0x7b, 0x01, 0xac, 0x09,
+                0x8f, 0xe8, 0x97, 0x98, 0x8d, 0x3f, 0xb7, 0x63,
+            },
+        },
+        .random_rsp[0] = {
+            .value = {
+                0x86, 0x1f, 0x76, 0x11, 0x2e, 0x83, 0xed, 0x99,
+                0x9b, 0xc0, 0x9a, 0xab, 0x7f, 0x94, 0x20, 0xcb,
+            },
+        },
+        .dhkey_check_req = {
+            .value = {
+                0xe0, 0x9f, 0x87, 0x87, 0x9f, 0x82, 0xc5, 0x06,
+                0x5f, 0x11, 0xfa, 0xa0, 0xe3, 0xbf, 0x72, 0xf2,
+            },
+        },
+        .dhkey_check_rsp = {
+            .value = {
+                0x26, 0xc2, 0xf1, 0xb9, 0xf1, 0xc2, 0xbd, 0xcb,
+                0xdb, 0x94, 0x96, 0x8e, 0x08, 0xcc, 0x53, 0xd4,
+            },
+        },
+        .sign_info_req = {
+            .sig_key = {
+                0x74, 0x14, 0xcd, 0x5a, 0x49, 0x2e, 0xb6, 0x0d,
+                0xc6, 0x82, 0xb0, 0x0f, 0x9c, 0xe6, 0xe5, 0x41,
+            },
+        },
+        .id_info_rsp = {
+            .irk = {
+                0xef, 0x8d, 0xe2, 0x16, 0x4f, 0xec, 0x43, 0x0d,
+                0xbf, 0x5b, 0xdd, 0x34, 0xc0, 0x53, 0x1e, 0xb8,
+            },
+        },
+        .id_addr_info_rsp = {
+            .addr_type = 0,
+            .bd_addr = {
+                0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
+            },
+        },
+        .sign_info_rsp = {
+            .sig_key = {
+                0xfb, 0x93, 0xa2, 0xb7, 0x4d, 0x0e, 0xcc, 0x92,
+                0xe4, 0xbf, 0x5b, 0x3c, 0x6d, 0x87, 0x5b, 0x2d,
+            },
+        },
+        .ltk = {
+            0x2e, 0x6c, 0x8b, 0xdb, 0x9e, 0x19, 0x3e, 0x3d,
+            0x4d, 0x6d, 0x29, 0xbc, 0x89, 0xca, 0x57, 0xed,
+        },
+        .pair_alg = BLE_SM_PAIR_ALG_JW,
+        .authenticated = 0,
+        .passkey_info = {
+            .passkey = {
+                .action = BLE_SM_IOACT_NONE,
+            },
+        },
+    };
+    ble_sm_test_util_us_sc_good(&params);
+}
+
+TEST_SUITE(ble_sm_sc_test_suite)
+{
+    /* Peer as initiator. */
+    ble_sm_sc_peer_jw_iio3_rio3_b1_iat0_rat0_ik5_rk7();
+    ble_sm_sc_peer_pk_iio0_rio2_b1_iat0_rat0_ik5_rk7();
+    ble_sm_sc_peer_pk_iio2_rio0_b1_iat0_rat0_ik5_rk7();
+    ble_sm_sc_peer_nc_iio1_rio1_b1_iat0_rat0_ik5_rk7();
+
+    /* Us as initiator. */
+    ble_sm_sc_us_jw_iio3_rio4_b1_iat0_rat0_ik7_rk5();
+}
+
+#endif /* NIMBLE_OPT_SM */
+
+int
+ble_sm_sc_test_all(void)
+{
+#if !NIMBLE_OPT(SM_SC)
+    return 0;
+#else
+    ble_sm_sc_test_suite();
+
+    return tu_any_failed;
+#endif
+}


[49/50] [abbrv] incubator-mynewt-core git commit: BLE Host - unit tests for combined priv/sc.

Posted by cc...@apache.org.
BLE Host - unit tests for combined priv/sc.


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

Branch: refs/heads/develop
Commit: b4c34462bcda85dd7630207874c9e9f6f7ea8b7c
Parents: ad94ca6
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 14 18:33:23 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:24:38 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/test/ble_hs_test_util.c |   25 +-
 net/nimble/host/src/test/ble_hs_test_util.h |    5 +
 net/nimble/host/src/test/ble_sm_sc_test.c   | 1900 +++++++++++++++++++++-
 net/nimble/host/src/test/ble_sm_test.c      |   72 +-
 net/nimble/host/src/test/ble_sm_test_util.c |  163 +-
 net/nimble/host/src/test/ble_sm_test_util.h |   16 +-
 6 files changed, 2064 insertions(+), 117 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b4c34462/net/nimble/host/src/test/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.c b/net/nimble/host/src/test/ble_hs_test_util.c
index 8f99ddd..957ad91 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -307,15 +307,17 @@ ble_hs_test_util_set_ack_seq(struct ble_hs_test_util_phony_ack *acks)
 }
 
 void
-ble_hs_test_util_create_conn(uint16_t handle, uint8_t *addr,
-                             ble_gap_event_fn *cb, void *cb_arg)
+ble_hs_test_util_create_rpa_conn(uint16_t handle, uint8_t *our_rpa,
+                                 uint8_t peer_addr_type, uint8_t *peer_id_addr,
+                                 uint8_t *peer_rpa,
+                                 ble_gap_event_fn *cb, void *cb_arg)
 {
     struct hci_le_conn_complete evt;
     int rc;
 
     ble_hs_test_util_set_ack(
         BLE_HS_TEST_UTIL_LE_OPCODE(BLE_HCI_OCF_LE_CREATE_CONN), 0);
-    rc = ble_gap_conn_initiate(0, addr, NULL, cb, cb_arg);
+    rc = ble_gap_conn_initiate(peer_addr_type, peer_id_addr, NULL, cb, cb_arg);
     TEST_ASSERT(rc == 0);
 
     memset(&evt, 0, sizeof evt);
@@ -323,17 +325,30 @@ ble_hs_test_util_create_conn(uint16_t handle, uint8_t *addr,
     evt.status = BLE_ERR_SUCCESS;
     evt.connection_handle = handle;
     evt.role = BLE_HCI_LE_CONN_COMPLETE_ROLE_MASTER;
-    evt.peer_addr_type = BLE_ADDR_TYPE_PUBLIC;
-    memcpy(evt.peer_addr, addr, 6);
+    evt.peer_addr_type = peer_addr_type;
+    memcpy(evt.peer_addr, peer_id_addr, 6);
     evt.conn_itvl = BLE_GAP_INITIAL_CONN_ITVL_MAX;
     evt.conn_latency = BLE_GAP_INITIAL_CONN_LATENCY;
     evt.supervision_timeout = BLE_GAP_INITIAL_SUPERVISION_TIMEOUT;
+    memcpy(evt.local_rpa, our_rpa, 6);
+    memcpy(evt.peer_rpa, peer_rpa, 6);
+
     rc = ble_gap_rx_conn_complete(&evt);
     TEST_ASSERT(rc == 0);
 
     ble_hs_test_util_prev_hci_tx_clear();
 }
 
+void
+ble_hs_test_util_create_conn(uint16_t handle, uint8_t *peer_id_addr,
+                             ble_gap_event_fn *cb, void *cb_arg)
+{
+    static uint8_t null_addr[6];
+
+    ble_hs_test_util_create_rpa_conn(handle, null_addr, BLE_ADDR_TYPE_PUBLIC,
+                                     peer_id_addr, null_addr, cb, cb_arg);
+}
+
 int
 ble_hs_test_util_conn_initiate(int addr_type, uint8_t *addr,
                                struct ble_gap_crt_params *params,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b4c34462/net/nimble/host/src/test/ble_hs_test_util.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.h b/net/nimble/host/src/test/ble_hs_test_util.h
index 55dcb21..9203252 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.h
+++ b/net/nimble/host/src/test/ble_hs_test_util.h
@@ -54,6 +54,11 @@ void ble_hs_test_util_build_cmd_complete(uint8_t *dst, int len,
 void ble_hs_test_util_build_cmd_status(uint8_t *dst, int len,
                                        uint8_t status, uint8_t num_pkts,
                                        uint16_t opcode);
+void ble_hs_test_util_create_rpa_conn(uint16_t handle, uint8_t *our_rpa,
+                                      uint8_t peer_addr_type,
+                                      uint8_t *peer_id_addr,
+                                      uint8_t *peer_rpa,
+                                      ble_gap_event_fn *cb, void *cb_arg);
 void ble_hs_test_util_create_conn(uint16_t handle, uint8_t *addr,
                                   ble_gap_event_fn *cb, void *cb_arg);
 int ble_hs_test_util_conn_initiate(int addr_type, uint8_t *addr,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b4c34462/net/nimble/host/src/test/ble_sm_sc_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_sc_test.c b/net/nimble/host/src/test/ble_sm_sc_test.c
index 7d8cd77..a237510 100644
--- a/net/nimble/host/src/test/ble_sm_sc_test.c
+++ b/net/nimble/host/src/test/ble_sm_sc_test.c
@@ -48,10 +48,10 @@ TEST_CASE(ble_sm_sc_peer_jw_iio3_rio3_b1_iat0_rat0_ik5_rk7)
     struct ble_sm_test_sc_params params;
 
     params = (struct ble_sm_test_sc_params) {
-        .init_addr = {
+        .init_id_addr = {
             0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
         },
-        .resp_addr = {
+        .resp_id_addr = {
             0x33, 0x22, 0x11, 0x00, 0x45, 0x0a,
         },
         .pair_req = {
@@ -190,10 +190,10 @@ TEST_CASE(ble_sm_sc_peer_pk_iio0_rio2_b1_iat0_rat0_ik5_rk7)
     struct ble_sm_test_sc_params params;
 
     params = (struct ble_sm_test_sc_params) {
-        .init_addr = {
+        .init_id_addr = {
             0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
         },
-        .resp_addr = {
+        .resp_id_addr = {
             0x33, 0x22, 0x11, 0x00, 0x45, 0x0a,
         },
         .pair_req = {
@@ -795,10 +795,10 @@ TEST_CASE(ble_sm_sc_peer_pk_iio2_rio0_b1_iat0_rat0_ik5_rk7)
     struct ble_sm_test_sc_params params;
 
     params = (struct ble_sm_test_sc_params) {
-        .init_addr = {
+        .init_id_addr = {
             0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
         },
-        .resp_addr = {
+        .resp_id_addr = {
             0x33, 0x22, 0x11, 0x00, 0x45, 0x0a,
         },
         .pair_req = {
@@ -1400,10 +1400,10 @@ TEST_CASE(ble_sm_sc_peer_nc_iio1_rio1_b1_iat0_rat0_ik5_rk7)
     struct ble_sm_test_sc_params params;
 
     params = (struct ble_sm_test_sc_params) {
-        .init_addr = {
+        .init_id_addr = {
             0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
         },
-        .resp_addr = {
+        .resp_id_addr = {
             0x33, 0x22, 0x11, 0x00, 0x45, 0x0a,
         },
         .pair_req = {
@@ -1544,10 +1544,10 @@ TEST_CASE(ble_sm_sc_us_jw_iio3_rio4_b1_iat0_rat0_ik7_rk5)
     struct ble_sm_test_sc_params params;
 
     params = (struct ble_sm_test_sc_params) {
-        .init_addr = {
+        .init_id_addr = {
             0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
         },
-        .resp_addr = {
+        .resp_id_addr = {
             0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
         },
         .pair_req = {
@@ -1686,10 +1686,10 @@ TEST_CASE(ble_sm_sc_us_pk_iio2_rio4_b1_iat0_rat0_ik7_rk5)
     struct ble_sm_test_sc_params params;
 
     params = (struct ble_sm_test_sc_params) {
-        .init_addr = {
+        .init_id_addr = {
             0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
         },
-        .resp_addr = {
+        .resp_id_addr = {
             0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
         },
         .pair_req = {
@@ -2291,10 +2291,10 @@ TEST_CASE(ble_sm_sc_us_pk_iio0_rio4_b1_iat0_rat0_ik7_rk5)
     struct ble_sm_test_sc_params params;
 
     params = (struct ble_sm_test_sc_params) {
-        .init_addr = {
+        .init_id_addr = {
             0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
         },
-        .resp_addr = {
+        .resp_id_addr = {
             0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
         },
         .pair_req = {
@@ -2896,10 +2896,10 @@ TEST_CASE(ble_sm_sc_us_nc_iio1_rio4_b1_iat0_rat0_ik7_rk5)
     struct ble_sm_test_sc_params params;
 
     params = (struct ble_sm_test_sc_params) {
-        .init_addr = {
+        .init_id_addr = {
             0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
         },
-        .resp_addr = {
+        .resp_id_addr = {
             0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
         },
         .pair_req = {
@@ -3023,8 +3023,1864 @@ TEST_CASE(ble_sm_sc_us_nc_iio1_rio4_b1_iat0_rat0_ik7_rk5)
     ble_sm_test_util_us_sc_good(&params);
 }
 
+/**
+ * Secure connections pairing
+ * Master: peer
+ * Pair algorithm: just works
+ * Initiator IO capabilities: 3
+ * Responder IO capabilities: 3
+ * Bonding: true
+ * Initiator address type: BLE_ADDR_TYPE_RPA_PUB_DEFAULT
+ * Responder address type: BLE_ADDR_TYPE_RPA_PUB_DEFAULT
+ * Initiator key distribution: 7
+ * Responder key distribution: 7
+ */
+TEST_CASE(ble_sm_sc_peer_jw_iio3_rio3_b1_iat2_rat2_ik7_rk7)
+{
+    struct ble_sm_test_sc_params params;
+
+    params = (struct ble_sm_test_sc_params) {
+        .init_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT,
+        .init_id_addr = {
+            0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
+        },
+        .init_rpa = {
+            0xd0, 0x8e, 0xf7, 0x42, 0x8c, 0x69,
+        },
+        .resp_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT,
+        .resp_id_addr = {
+            0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07,
+        },
+        .resp_rpa = {
+            0x1a, 0x6e, 0x83, 0x55, 0x5b, 0x5a,
+        },
+        .pair_req = {
+            .io_cap = 0x03,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x07,
+            .resp_key_dist = 0x07,
+        },
+        .pair_rsp = {
+            .io_cap = 0x03,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x07,
+            .resp_key_dist = 0x07,
+        },
+        .our_priv_key = {
+            0xc5, 0x04, 0xc5, 0xf9, 0x28, 0x95, 0x78, 0x17,
+            0xd5, 0x97, 0x1d, 0x01, 0xbb, 0x2c, 0xcf, 0x77,
+            0x5c, 0x70, 0x52, 0xc6, 0x5e, 0x33, 0x2e, 0xe7,
+            0x79, 0x58, 0xc8, 0xf1, 0xc2, 0x2d, 0xb0, 0x61,
+        },
+        .public_key_req = {
+            .x = {
+                0x54, 0xd9, 0x8f, 0xeb, 0xc1, 0xbb, 0xe6, 0x74,
+                0x8a, 0x55, 0x3a, 0x80, 0x0e, 0xef, 0x90, 0xc9,
+                0xab, 0x79, 0x12, 0x88, 0x97, 0xd9, 0x1c, 0x62,
+                0x0d, 0x26, 0x43, 0x7d, 0x25, 0x86, 0x79, 0xc7,
+            },
+            .y = {
+                0x07, 0x33, 0x91, 0x40, 0xde, 0x25, 0xb4, 0x3d,
+                0x81, 0x2f, 0xd2, 0x41, 0x98, 0xe7, 0xaf, 0x0f,
+                0x5f, 0x17, 0x85, 0x1f, 0x75, 0x6e, 0xf4, 0x0e,
+                0x05, 0x19, 0x7f, 0x03, 0x9b, 0xf4, 0x41, 0x23,
+            },
+        },
+        .public_key_rsp = {
+            .x = {
+                0x1d, 0x44, 0x66, 0x0d, 0x3a, 0x03, 0x71, 0x17,
+                0xb3, 0x10, 0x2e, 0xf0, 0xd3, 0xf8, 0xa2, 0x6c,
+                0x1f, 0xfc, 0xbf, 0x02, 0x62, 0x6b, 0x11, 0x5a,
+                0x76, 0x5b, 0x30, 0x20, 0xb1, 0xef, 0xb3, 0x76,
+            },
+            .y = {
+                0xf1, 0x23, 0x63, 0x75, 0xfc, 0xb6, 0xc9, 0x32,
+                0xa4, 0x36, 0xbe, 0x18, 0xa0, 0x7d, 0x0b, 0x16,
+                0x65, 0x24, 0xd0, 0xe3, 0x74, 0x1b, 0x34, 0x1a,
+                0xf9, 0xe2, 0xcb, 0x30, 0x93, 0x88, 0xd7, 0xfa,
+            },
+        },
+        .confirm_rsp[0] = {
+            .value = {
+                0x1e, 0x07, 0x87, 0xb2, 0x54, 0x3a, 0x44, 0x6b,
+                0x97, 0x45, 0xa7, 0xa2, 0x36, 0xf4, 0x10, 0x42,
+            },
+        },
+        .random_req[0] = {
+            .value = {
+                0x99, 0xc4, 0xdf, 0x4a, 0x2f, 0x14, 0xd8, 0x11,
+                0xd3, 0x93, 0x53, 0xac, 0x64, 0xc8, 0x67, 0xe6,
+            },
+        },
+        .random_rsp[0] = {
+            .value = {
+                0xc5, 0xb0, 0xf5, 0x2a, 0x65, 0x77, 0x05, 0xb8,
+                0xf7, 0x5b, 0xad, 0x4e, 0xa9, 0x9e, 0x79, 0x98,
+            },
+        },
+        .dhkey_check_req = {
+            .value = {
+                0xbb, 0x44, 0x9b, 0x1b, 0xcd, 0xfc, 0xdf, 0xff,
+                0xbb, 0x34, 0xb7, 0x3b, 0x3e, 0x30, 0xa1, 0x6e,
+            },
+        },
+        .dhkey_check_rsp = {
+            .value = {
+                0x58, 0x8f, 0xbe, 0xa2, 0x5f, 0xe3, 0x0a, 0xbc,
+                0x17, 0x0f, 0x3b, 0x23, 0x27, 0xa5, 0xfb, 0x25,
+            },
+        },
+        .id_info_req = {
+            .irk = {
+                0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+                0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
+            },
+        },
+        .id_addr_info_req = {
+            .addr_type = 0,
+            .bd_addr = {
+                0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07,
+            },
+        },
+        .sign_info_req = {
+            .sig_key = {
+                0xd3, 0x46, 0x86, 0xf7, 0xeb, 0x19, 0x0a, 0x18,
+                0x5a, 0xb2, 0xd0, 0x5b, 0x0f, 0x03, 0x64, 0x01,
+            },
+        },
+        .id_info_rsp = {
+            .irk = {
+                0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+                0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+            },
+        },
+        .id_addr_info_rsp = {
+            .addr_type = 0,
+            .bd_addr = {
+                0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
+            },
+        },
+        .sign_info_rsp = {
+            .sig_key = {
+                0x84, 0x91, 0x5d, 0x89, 0xf6, 0xf0, 0x01, 0x65,
+                0xed, 0xa9, 0xcc, 0x9b, 0xa4, 0xd4, 0x97, 0x86,
+            },
+        },
+        .ltk = {
+            0x4b, 0xb6, 0x1d, 0xd2, 0xba, 0xa4, 0x94, 0xe5,
+            0x78, 0xde, 0xee, 0x47, 0x7a, 0x95, 0x91, 0x1c,
+        },
+        .pair_alg = BLE_SM_PAIR_ALG_JW,
+        .authenticated = 0,
+        .passkey_info = {
+            .passkey = {
+                .action = BLE_SM_IOACT_NONE,
+            },
+        },
+    };
+    ble_sm_test_util_peer_sc_good(&params);
+}
+
+/**
+ * Secure connections pairing
+ * Master: peer
+ * Pair algorithm: numeric comparison
+ * Initiator IO capabilities: 1
+ * Responder IO capabilities: 1
+ * Bonding: true
+ * Initiator address type: BLE_ADDR_TYPE_RPA_PUB_DEFAULT
+ * Responder address type: BLE_ADDR_TYPE_RPA_PUB_DEFAULT
+ * Initiator key distribution: 3
+ * Responder key distribution: 3
+ */
+TEST_CASE(ble_sm_sc_peer_nc_iio1_rio1_b1_iat2_rat2_ik3_rk3)
+{
+    struct ble_sm_test_sc_params params;
+
+    params = (struct ble_sm_test_sc_params) {
+        .init_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT,
+        .init_id_addr = {
+            0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
+        },
+        .init_rpa = {
+            0xc5, 0xf3, 0x5d, 0x83, 0xcd, 0x4a,
+        },
+        .resp_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT,
+        .resp_id_addr = {
+            0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07,
+        },
+        .resp_rpa = {
+            0x9f, 0x56, 0x57, 0x5e, 0x12, 0x65,
+        },
+        .pair_req = {
+            .io_cap = 0x01,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x03,
+            .resp_key_dist = 0x03,
+        },
+        .pair_rsp = {
+            .io_cap = 0x01,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x03,
+            .resp_key_dist = 0x03,
+        },
+        .our_priv_key = {
+            0xc5, 0x04, 0xc5, 0xf9, 0x28, 0x95, 0x78, 0x17,
+            0xd5, 0x97, 0x1d, 0x01, 0xbb, 0x2c, 0xcf, 0x77,
+            0x5c, 0x70, 0x52, 0xc6, 0x5e, 0x33, 0x2e, 0xe7,
+            0x79, 0x58, 0xc8, 0xf1, 0xc2, 0x2d, 0xb0, 0x61,
+        },
+        .public_key_req = {
+            .x = {
+                0x54, 0xd9, 0x8f, 0xeb, 0xc1, 0xbb, 0xe6, 0x74,
+                0x8a, 0x55, 0x3a, 0x80, 0x0e, 0xef, 0x90, 0xc9,
+                0xab, 0x79, 0x12, 0x88, 0x97, 0xd9, 0x1c, 0x62,
+                0x0d, 0x26, 0x43, 0x7d, 0x25, 0x86, 0x79, 0xc7,
+            },
+            .y = {
+                0x07, 0x33, 0x91, 0x40, 0xde, 0x25, 0xb4, 0x3d,
+                0x81, 0x2f, 0xd2, 0x41, 0x98, 0xe7, 0xaf, 0x0f,
+                0x5f, 0x17, 0x85, 0x1f, 0x75, 0x6e, 0xf4, 0x0e,
+                0x05, 0x19, 0x7f, 0x03, 0x9b, 0xf4, 0x41, 0x23,
+            },
+        },
+        .public_key_rsp = {
+            .x = {
+                0x1d, 0x44, 0x66, 0x0d, 0x3a, 0x03, 0x71, 0x17,
+                0xb3, 0x10, 0x2e, 0xf0, 0xd3, 0xf8, 0xa2, 0x6c,
+                0x1f, 0xfc, 0xbf, 0x02, 0x62, 0x6b, 0x11, 0x5a,
+                0x76, 0x5b, 0x30, 0x20, 0xb1, 0xef, 0xb3, 0x76,
+            },
+            .y = {
+                0xf1, 0x23, 0x63, 0x75, 0xfc, 0xb6, 0xc9, 0x32,
+                0xa4, 0x36, 0xbe, 0x18, 0xa0, 0x7d, 0x0b, 0x16,
+                0x65, 0x24, 0xd0, 0xe3, 0x74, 0x1b, 0x34, 0x1a,
+                0xf9, 0xe2, 0xcb, 0x30, 0x93, 0x88, 0xd7, 0xfa,
+            },
+        },
+        .confirm_rsp[0] = {
+            .value = {
+                0x39, 0xba, 0x86, 0x47, 0x06, 0x87, 0x14, 0xe4,
+                0x5c, 0x82, 0xe9, 0x6a, 0x80, 0xca, 0x87, 0xcd,
+            },
+        },
+        .random_req[0] = {
+            .value = {
+                0xce, 0xe2, 0xa3, 0x29, 0x8a, 0xc6, 0x76, 0x1d,
+                0xa2, 0xfd, 0xe0, 0x7f, 0x8c, 0xbe, 0xf8, 0x1d,
+            },
+        },
+        .random_rsp[0] = {
+            .value = {
+                0x3d, 0xac, 0xf0, 0xfe, 0x7c, 0x78, 0x73, 0x03,
+                0xe2, 0xb6, 0x59, 0x7e, 0x80, 0xb4, 0x69, 0x07,
+            },
+        },
+        .dhkey_check_req = {
+            .value = {
+                0xaa, 0x95, 0x9f, 0x33, 0x32, 0xa1, 0xbd, 0xf9,
+                0xef, 0xb9, 0x3d, 0xfb, 0x08, 0xd1, 0x28, 0xa0,
+            },
+        },
+        .dhkey_check_rsp = {
+            .value = {
+                0x3c, 0x10, 0x17, 0x76, 0x55, 0x65, 0x6f, 0x14,
+                0xfa, 0x80, 0xd3, 0x52, 0x04, 0x82, 0xe2, 0xf7,
+            },
+        },
+        .id_info_req = {
+            .irk = {
+                0xd4, 0x66, 0x94, 0xc9, 0x96, 0xd0, 0x28, 0x96,
+                0x1c, 0xa1, 0x3b, 0xf7, 0x15, 0x95, 0x95, 0x43,
+            },
+        },
+        .id_addr_info_req = {
+            .addr_type = 0,
+            .bd_addr = {
+                0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07,
+            },
+        },
+        .id_info_rsp = {
+            .irk = {
+                0xb7, 0x98, 0xac, 0x85, 0xc4, 0x0a, 0x69, 0x8d,
+                0xa6, 0xaf, 0xf3, 0x1f, 0x63, 0x3c, 0xf2, 0x33,
+            },
+        },
+        .id_addr_info_rsp = {
+            .addr_type = 0,
+            .bd_addr = {
+                0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
+            },
+        },
+        .ltk = {
+            0x95, 0x46, 0xe6, 0x8e, 0x52, 0xcc, 0x05, 0xca,
+            0xf4, 0x59, 0x57, 0x54, 0x8c, 0x0d, 0x51, 0xfc,
+        },
+        .pair_alg = BLE_SM_PAIR_ALG_NUMCMP,
+        .authenticated = 1,
+        .passkey_info = {
+            .passkey = {
+                .action = BLE_SM_IOACT_NUMCMP,
+                .numcmp_accept = 1,
+            },
+            .exp_numcmp = 70210,
+        },
+    };
+    ble_sm_test_util_peer_sc_good(&params);
+}
+
+/**
+ * Secure connections pairing
+ * Master: peer
+ * Pair algorithm: passkey entry
+ * Initiator IO capabilities: 2
+ * Responder IO capabilities: 0
+ * Bonding: true
+ * Initiator address type: BLE_ADDR_TYPE_RPA_PUB_DEFAULT
+ * Responder address type: BLE_ADDR_TYPE_RPA_PUB_DEFAULT
+ * Initiator key distribution: 7
+ * Responder key distribution: 3
+ */
+TEST_CASE(ble_sm_sc_peer_pk_iio2_rio0_b1_iat2_rat2_ik7_rk3)
+{
+    struct ble_sm_test_sc_params params;
+
+    params = (struct ble_sm_test_sc_params) {
+        .init_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT,
+        .init_id_addr = {
+            0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
+        },
+        .init_rpa = {
+            0x6e, 0x56, 0x09, 0xef, 0x1e, 0x76,
+        },
+        .resp_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT,
+        .resp_id_addr = {
+            0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07,
+        },
+        .resp_rpa = {
+            0xb5, 0x29, 0xdf, 0xb4, 0x9b, 0x62,
+        },
+        .pair_req = {
+            .io_cap = 0x02,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x07,
+            .resp_key_dist = 0x03,
+        },
+        .pair_rsp = {
+            .io_cap = 0x00,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x07,
+            .resp_key_dist = 0x03,
+        },
+        .our_priv_key = {
+            0xc5, 0x04, 0xc5, 0xf9, 0x28, 0x95, 0x78, 0x17,
+            0xd5, 0x97, 0x1d, 0x01, 0xbb, 0x2c, 0xcf, 0x77,
+            0x5c, 0x70, 0x52, 0xc6, 0x5e, 0x33, 0x2e, 0xe7,
+            0x79, 0x58, 0xc8, 0xf1, 0xc2, 0x2d, 0xb0, 0x61,
+        },
+        .public_key_req = {
+            .x = {
+                0x54, 0xd9, 0x8f, 0xeb, 0xc1, 0xbb, 0xe6, 0x74,
+                0x8a, 0x55, 0x3a, 0x80, 0x0e, 0xef, 0x90, 0xc9,
+                0xab, 0x79, 0x12, 0x88, 0x97, 0xd9, 0x1c, 0x62,
+                0x0d, 0x26, 0x43, 0x7d, 0x25, 0x86, 0x79, 0xc7,
+            },
+            .y = {
+                0x07, 0x33, 0x91, 0x40, 0xde, 0x25, 0xb4, 0x3d,
+                0x81, 0x2f, 0xd2, 0x41, 0x98, 0xe7, 0xaf, 0x0f,
+                0x5f, 0x17, 0x85, 0x1f, 0x75, 0x6e, 0xf4, 0x0e,
+                0x05, 0x19, 0x7f, 0x03, 0x9b, 0xf4, 0x41, 0x23,
+            },
+        },
+        .public_key_rsp = {
+            .x = {
+                0x1d, 0x44, 0x66, 0x0d, 0x3a, 0x03, 0x71, 0x17,
+                0xb3, 0x10, 0x2e, 0xf0, 0xd3, 0xf8, 0xa2, 0x6c,
+                0x1f, 0xfc, 0xbf, 0x02, 0x62, 0x6b, 0x11, 0x5a,
+                0x76, 0x5b, 0x30, 0x20, 0xb1, 0xef, 0xb3, 0x76,
+            },
+            .y = {
+                0xf1, 0x23, 0x63, 0x75, 0xfc, 0xb6, 0xc9, 0x32,
+                0xa4, 0x36, 0xbe, 0x18, 0xa0, 0x7d, 0x0b, 0x16,
+                0x65, 0x24, 0xd0, 0xe3, 0x74, 0x1b, 0x34, 0x1a,
+                0xf9, 0xe2, 0xcb, 0x30, 0x93, 0x88, 0xd7, 0xfa,
+            },
+        },
+        .confirm_req[0] = {
+            .value = {
+                0x12, 0xe3, 0x01, 0xd0, 0x30, 0x59, 0xca, 0xd9,
+                0x78, 0x0b, 0x45, 0x73, 0xb1, 0x7a, 0x4d, 0xca,
+            },
+        },
+        .confirm_rsp[0] = {
+            .value = {
+                0x47, 0x68, 0x16, 0x24, 0xd4, 0x07, 0x60, 0x6c,
+                0xa5, 0x47, 0x6f, 0x05, 0x78, 0x71, 0x3e, 0xa8,
+            },
+        },
+        .random_req[0] = {
+            .value = {
+                0x2a, 0x29, 0xa8, 0xef, 0x0b, 0x70, 0x5f, 0x1b,
+                0x81, 0x4d, 0x97, 0xff, 0xfb, 0x7f, 0x30, 0x90,
+            },
+        },
+        .random_rsp[0] = {
+            .value = {
+                0x12, 0x9e, 0x1d, 0x12, 0x11, 0x44, 0x36, 0x74,
+                0xa3, 0x0c, 0xea, 0x36, 0x4d, 0xdf, 0x2d, 0x5d,
+            },
+        },
+        .confirm_req[1] = {
+            .value = {
+                0x4d, 0x6a, 0x32, 0xfe, 0xe2, 0xa0, 0xdd, 0x92,
+                0x60, 0x5c, 0x82, 0x7f, 0xa6, 0xa6, 0x24, 0xd6,
+            },
+        },
+        .confirm_rsp[1] = {
+            .value = {
+                0xd5, 0x3e, 0xa7, 0xa0, 0xbf, 0x39, 0x8e, 0xfe,
+                0xfd, 0x73, 0x47, 0x4c, 0x92, 0x8b, 0x74, 0x06,
+            },
+        },
+        .random_req[1] = {
+            .value = {
+                0xc1, 0x88, 0xdf, 0xb0, 0x99, 0xbb, 0xbf, 0xed,
+                0xdc, 0x40, 0x66, 0x55, 0xbe, 0x91, 0x56, 0x9a,
+            },
+        },
+        .random_rsp[1] = {
+            .value = {
+                0xed, 0xed, 0x9a, 0x61, 0xb8, 0x21, 0x03, 0x77,
+                0xa6, 0xcf, 0x34, 0x65, 0x8c, 0x18, 0x82, 0x9f,
+            },
+        },
+        .confirm_req[2] = {
+            .value = {
+                0xdb, 0xea, 0x94, 0x29, 0xe4, 0x44, 0x7d, 0x7b,
+                0xd3, 0x16, 0x81, 0x8e, 0xaf, 0xe6, 0x9c, 0x85,
+            },
+        },
+        .confirm_rsp[2] = {
+            .value = {
+                0x3f, 0xdd, 0x54, 0x76, 0xab, 0x45, 0x7f, 0x53,
+                0x64, 0x6b, 0x37, 0xa6, 0xc7, 0xc6, 0x4a, 0x73,
+            },
+        },
+        .random_req[2] = {
+            .value = {
+                0x5a, 0xf1, 0xfb, 0xde, 0xb3, 0xbe, 0x6e, 0xac,
+                0x68, 0x51, 0x47, 0x8e, 0x0b, 0xcd, 0xc1, 0xa0,
+            },
+        },
+        .random_rsp[2] = {
+            .value = {
+                0x29, 0x0f, 0x5e, 0x83, 0x87, 0xca, 0xd3, 0x21,
+                0xa7, 0x7e, 0x3d, 0x78, 0x47, 0x54, 0xf8, 0xe4,
+            },
+        },
+        .confirm_req[3] = {
+            .value = {
+                0xca, 0x3e, 0xd5, 0xe3, 0x59, 0xb0, 0x5d, 0x1e,
+                0x0f, 0x4c, 0x95, 0x0f, 0x6a, 0x72, 0xcf, 0x25,
+            },
+        },
+        .confirm_rsp[3] = {
+            .value = {
+                0x2f, 0x4d, 0x06, 0x40, 0x09, 0x68, 0x68, 0x45,
+                0x87, 0x79, 0x78, 0x48, 0xda, 0xe4, 0xf5, 0xae,
+            },
+        },
+        .random_req[3] = {
+            .value = {
+                0x63, 0x5a, 0xee, 0x91, 0xe4, 0xf8, 0xe8, 0x69,
+                0xd1, 0x46, 0x18, 0x0d, 0xd2, 0x94, 0xd8, 0x20,
+            },
+        },
+        .random_rsp[3] = {
+            .value = {
+                0x76, 0x36, 0xf5, 0xc2, 0x41, 0xb6, 0x3c, 0x1f,
+                0x36, 0x19, 0x58, 0xce, 0x8f, 0x41, 0xeb, 0x8c,
+            },
+        },
+        .confirm_req[4] = {
+            .value = {
+                0x76, 0xfd, 0x84, 0x0f, 0x0f, 0x58, 0x70, 0x45,
+                0x41, 0x33, 0x5d, 0xce, 0xe5, 0xe2, 0x2f, 0x83,
+            },
+        },
+        .confirm_rsp[4] = {
+            .value = {
+                0x87, 0xcf, 0xdf, 0xa5, 0x60, 0x82, 0x4f, 0x09,
+                0x4c, 0x50, 0x24, 0xba, 0x91, 0x96, 0x0d, 0x65,
+            },
+        },
+        .random_req[4] = {
+            .value = {
+                0x67, 0xdb, 0x73, 0x1e, 0x57, 0x5c, 0xb7, 0x86,
+                0xf8, 0xaf, 0x58, 0xd8, 0x0f, 0x97, 0x47, 0xce,
+            },
+        },
+        .random_rsp[4] = {
+            .value = {
+                0xaa, 0x99, 0x90, 0x05, 0x11, 0xfc, 0xc2, 0xd9,
+                0xb8, 0xd6, 0x9d, 0xef, 0x86, 0x10, 0xcf, 0x26,
+            },
+        },
+        .confirm_req[5] = {
+            .value = {
+                0xfc, 0x22, 0xd9, 0x1f, 0x5f, 0x86, 0x25, 0xe7,
+                0x5e, 0x55, 0x48, 0x35, 0xec, 0x32, 0x37, 0x6d,
+            },
+        },
+        .confirm_rsp[5] = {
+            .value = {
+                0x98, 0xbc, 0x07, 0x72, 0xa2, 0xe7, 0xa7, 0x66,
+                0x64, 0xf7, 0x29, 0x3a, 0xaf, 0x52, 0x18, 0x04,
+            },
+        },
+        .random_req[5] = {
+            .value = {
+                0xd3, 0x36, 0xb9, 0x69, 0x6a, 0x6d, 0x55, 0xbc,
+                0x82, 0xdf, 0x1c, 0x04, 0xa7, 0xd5, 0x00, 0x68,
+            },
+        },
+        .random_rsp[5] = {
+            .value = {
+                0xb9, 0x03, 0xbf, 0xd9, 0x86, 0x5a, 0x1a, 0xb4,
+                0xdc, 0xe6, 0x8f, 0x9b, 0xa4, 0xa8, 0x2a, 0x12,
+            },
+        },
+        .confirm_req[6] = {
+            .value = {
+                0xfe, 0x14, 0xab, 0x1c, 0xfd, 0x36, 0x64, 0x38,
+                0xc1, 0xf8, 0xdd, 0xcd, 0xf4, 0x77, 0xa1, 0xb8,
+            },
+        },
+        .confirm_rsp[6] = {
+            .value = {
+                0x2e, 0x70, 0x54, 0xdc, 0xa6, 0xae, 0xb2, 0xcd,
+                0x4a, 0x26, 0x97, 0xf8, 0xbf, 0xb4, 0xb4, 0x52,
+            },
+        },
+        .random_req[6] = {
+            .value = {
+                0x1e, 0x27, 0x73, 0x94, 0x44, 0xfc, 0xd4, 0x44,
+                0xbf, 0x5b, 0x7d, 0x5d, 0x6d, 0x13, 0x68, 0xb1,
+            },
+        },
+        .random_rsp[6] = {
+            .value = {
+                0xeb, 0xfd, 0x0b, 0xa1, 0x7b, 0xda, 0x61, 0xdc,
+                0x6d, 0xe4, 0x3b, 0x51, 0xa7, 0x09, 0x29, 0x6d,
+            },
+        },
+        .confirm_req[7] = {
+            .value = {
+                0x38, 0x2b, 0x23, 0xb9, 0x18, 0x2d, 0xb9, 0x0b,
+                0xe7, 0x4d, 0x20, 0x83, 0xab, 0x17, 0xfd, 0x88,
+            },
+        },
+        .confirm_rsp[7] = {
+            .value = {
+                0x65, 0x60, 0x85, 0xef, 0x0e, 0x9a, 0x23, 0x96,
+                0xe7, 0xa9, 0xee, 0xba, 0x9e, 0x48, 0xb9, 0x1c,
+            },
+        },
+        .random_req[7] = {
+            .value = {
+                0x8b, 0xa8, 0x7a, 0x33, 0x15, 0x1e, 0xa7, 0x78,
+                0x27, 0x01, 0x3e, 0x90, 0x43, 0x47, 0x5a, 0x9d,
+            },
+        },
+        .random_rsp[7] = {
+            .value = {
+                0x76, 0xf1, 0x21, 0x67, 0x94, 0x20, 0x6f, 0xc7,
+                0x84, 0xc8, 0xdb, 0x07, 0xdb, 0x77, 0xdd, 0x50,
+            },
+        },
+        .confirm_req[8] = {
+            .value = {
+                0x4e, 0x7f, 0x83, 0x8e, 0xa6, 0x28, 0xaa, 0x46,
+                0xa2, 0x69, 0x95, 0x3b, 0xf0, 0x71, 0x14, 0x24,
+            },
+        },
+        .confirm_rsp[8] = {
+            .value = {
+                0x93, 0x0b, 0x4d, 0xbe, 0x49, 0x36, 0xa0, 0x26,
+                0xe9, 0x18, 0x4e, 0xc8, 0x19, 0x59, 0xc1, 0x7d,
+            },
+        },
+        .random_req[8] = {
+            .value = {
+                0x11, 0xa9, 0xce, 0x26, 0x0e, 0x2f, 0x11, 0x0e,
+                0xc1, 0xbd, 0x68, 0x80, 0xc8, 0xf8, 0x41, 0x65,
+            },
+        },
+        .random_rsp[8] = {
+            .value = {
+                0xb6, 0x3d, 0x6b, 0x62, 0xb5, 0x37, 0x31, 0x28,
+                0x79, 0xc4, 0xe2, 0x62, 0xbb, 0x63, 0xf9, 0x91,
+            },
+        },
+        .confirm_req[9] = {
+            .value = {
+                0x5f, 0x55, 0xb5, 0xa4, 0x80, 0xa8, 0x54, 0x47,
+                0xa7, 0x79, 0x87, 0x12, 0x2e, 0x44, 0x92, 0x42,
+            },
+        },
+        .confirm_rsp[9] = {
+            .value = {
+                0x01, 0x69, 0xa2, 0xac, 0xd6, 0x62, 0x8a, 0x64,
+                0xa2, 0x0b, 0xd0, 0xb4, 0x0e, 0x68, 0xe0, 0x88,
+            },
+        },
+        .random_req[9] = {
+            .value = {
+                0x75, 0x1e, 0x56, 0xd0, 0xcb, 0x06, 0xfd, 0x51,
+                0x55, 0xae, 0x77, 0xa4, 0xf2, 0xe7, 0x86, 0x3c,
+            },
+        },
+        .random_rsp[9] = {
+            .value = {
+                0xff, 0xab, 0x8a, 0x7d, 0xb7, 0x40, 0xe5, 0x07,
+                0xfe, 0x8f, 0x74, 0xdb, 0x2c, 0x35, 0x35, 0x12,
+            },
+        },
+        .confirm_req[10] = {
+            .value = {
+                0x1f, 0x2a, 0xed, 0xcd, 0x6b, 0x87, 0xea, 0xa2,
+                0xf8, 0xd8, 0xad, 0x04, 0x23, 0xc7, 0x5d, 0x47,
+            },
+        },
+        .confirm_rsp[10] = {
+            .value = {
+                0x5b, 0x18, 0x2d, 0x96, 0x3b, 0xf6, 0xdc, 0x82,
+                0x3b, 0xfa, 0xc9, 0x81, 0xc7, 0x33, 0xa0, 0x07,
+            },
+        },
+        .random_req[10] = {
+            .value = {
+                0xd1, 0x3a, 0x82, 0xce, 0x31, 0x75, 0xa2, 0xbf,
+                0x6f, 0x12, 0xf2, 0xac, 0xf6, 0xcc, 0xea, 0x34,
+            },
+        },
+        .random_rsp[10] = {
+            .value = {
+                0xcf, 0x11, 0x3d, 0x44, 0x10, 0x0d, 0x26, 0x32,
+                0xa5, 0x61, 0x13, 0xfd, 0xb8, 0xed, 0x31, 0x53,
+            },
+        },
+        .confirm_req[11] = {
+            .value = {
+                0x67, 0x14, 0x8a, 0xf6, 0xc8, 0xb8, 0x73, 0x6b,
+                0xb2, 0xec, 0xa9, 0x61, 0xaa, 0xc0, 0xc9, 0x28,
+            },
+        },
+        .confirm_rsp[11] = {
+            .value = {
+                0xa5, 0xbf, 0x00, 0x07, 0x48, 0xff, 0x30, 0x36,
+                0x20, 0x83, 0xd7, 0xd6, 0xd0, 0x90, 0x46, 0x03,
+            },
+        },
+        .random_req[11] = {
+            .value = {
+                0x75, 0x99, 0x9a, 0xa3, 0xad, 0x9a, 0xe5, 0x9d,
+                0x2f, 0x21, 0xdb, 0x72, 0x2f, 0xaf, 0xb8, 0x79,
+            },
+        },
+        .random_rsp[11] = {
+            .value = {
+                0xa3, 0xb7, 0xb7, 0x46, 0x39, 0x99, 0xc2, 0x82,
+                0xe9, 0x31, 0x8d, 0xc2, 0x28, 0x1b, 0x86, 0x91,
+            },
+        },
+        .confirm_req[12] = {
+            .value = {
+                0x46, 0x2f, 0xc8, 0x0e, 0x2c, 0x70, 0x3a, 0xdb,
+                0x25, 0x2f, 0xce, 0xe6, 0x15, 0x1f, 0x9a, 0x06,
+            },
+        },
+        .confirm_rsp[12] = {
+            .value = {
+                0x9a, 0xa4, 0xe0, 0x03, 0x3a, 0xb5, 0x43, 0x75,
+                0x8e, 0x93, 0x35, 0x25, 0xe6, 0x5e, 0x9d, 0x7f,
+            },
+        },
+        .random_req[12] = {
+            .value = {
+                0x1f, 0x01, 0x32, 0x56, 0x64, 0x45, 0xc5, 0x20,
+                0xd4, 0xad, 0x13, 0x8f, 0xbe, 0x82, 0xc8, 0x01,
+            },
+        },
+        .random_rsp[12] = {
+            .value = {
+                0xd4, 0x3f, 0xa4, 0xc9, 0xe9, 0x2e, 0x62, 0x77,
+                0x4e, 0x21, 0x55, 0xd8, 0xde, 0x31, 0xf5, 0xea,
+            },
+        },
+        .confirm_req[13] = {
+            .value = {
+                0x4e, 0x48, 0x88, 0x4e, 0x4f, 0x74, 0x7e, 0xec,
+                0x99, 0x5d, 0xb1, 0xcb, 0x84, 0x88, 0x80, 0xe9,
+            },
+        },
+        .confirm_rsp[13] = {
+            .value = {
+                0x1a, 0x84, 0xfa, 0x2f, 0xd7, 0x3c, 0x5f, 0xee,
+                0x3e, 0x81, 0xc0, 0x4b, 0x35, 0x4b, 0x7e, 0x98,
+            },
+        },
+        .random_req[13] = {
+            .value = {
+                0xe3, 0x3a, 0xc5, 0x2f, 0x9f, 0x91, 0x93, 0xfb,
+                0xcb, 0xd8, 0x53, 0x63, 0xab, 0xc4, 0xa5, 0x85,
+            },
+        },
+        .random_rsp[13] = {
+            .value = {
+                0xa0, 0xcf, 0xad, 0x30, 0x2d, 0xec, 0xea, 0x81,
+                0xfd, 0x7f, 0xcf, 0x7c, 0x70, 0xc9, 0x89, 0x7b,
+            },
+        },
+        .confirm_req[14] = {
+            .value = {
+                0xe1, 0x64, 0x22, 0x19, 0x41, 0x44, 0x37, 0x2b,
+                0x92, 0x60, 0xa4, 0x1f, 0xd6, 0x53, 0xe0, 0xa0,
+            },
+        },
+        .confirm_rsp[14] = {
+            .value = {
+                0x08, 0xfa, 0xa4, 0xf8, 0x04, 0x08, 0xb8, 0x9f,
+                0x61, 0xb5, 0x68, 0xaf, 0x31, 0x12, 0x8d, 0x3f,
+            },
+        },
+        .random_req[14] = {
+            .value = {
+                0xad, 0x76, 0xc3, 0x1a, 0x4c, 0x64, 0x2c, 0x11,
+                0x5e, 0x48, 0x6d, 0x41, 0xf5, 0x77, 0xc2, 0x40,
+            },
+        },
+        .random_rsp[14] = {
+            .value = {
+                0x1b, 0xec, 0x78, 0x2b, 0xd9, 0xbe, 0x93, 0xbd,
+                0x0b, 0x03, 0xf1, 0xd8, 0x31, 0xe8, 0x60, 0x67,
+            },
+        },
+        .confirm_req[15] = {
+            .value = {
+                0x5e, 0x22, 0x44, 0x09, 0x97, 0xf9, 0xc5, 0xc7,
+                0x23, 0xc7, 0x74, 0x51, 0xe5, 0x9d, 0x5c, 0xed,
+            },
+        },
+        .confirm_rsp[15] = {
+            .value = {
+                0xfe, 0xb2, 0x90, 0xa7, 0x06, 0xaf, 0xdd, 0x6a,
+                0x83, 0x26, 0x3c, 0x78, 0x66, 0xe0, 0x9d, 0xd9,
+            },
+        },
+        .random_req[15] = {
+            .value = {
+                0xb2, 0xa0, 0x75, 0x6f, 0x77, 0xc1, 0x0b, 0x4e,
+                0x99, 0xfa, 0x9a, 0x02, 0xf6, 0xe4, 0x66, 0x27,
+            },
+        },
+        .random_rsp[15] = {
+            .value = {
+                0xf9, 0xdd, 0x69, 0xae, 0xc8, 0x66, 0xa9, 0xab,
+                0xb8, 0x01, 0x38, 0xc3, 0x2a, 0x6b, 0x94, 0x66,
+            },
+        },
+        .confirm_req[16] = {
+            .value = {
+                0x17, 0xc9, 0xf7, 0x2d, 0xe6, 0xb7, 0x99, 0x77,
+                0x65, 0xf7, 0x62, 0xc8, 0x0d, 0x7d, 0xbd, 0x81,
+            },
+        },
+        .confirm_rsp[16] = {
+            .value = {
+                0x39, 0xef, 0xbf, 0x39, 0xfa, 0x79, 0xc3, 0x7b,
+                0x71, 0x40, 0x3c, 0x1f, 0x67, 0xe5, 0x60, 0xe5,
+            },
+        },
+        .random_req[16] = {
+            .value = {
+                0x32, 0xab, 0x8b, 0xed, 0x90, 0x04, 0x5e, 0x17,
+                0xd2, 0x5e, 0xa8, 0x91, 0xf7, 0x77, 0xe3, 0xd7,
+            },
+        },
+        .random_rsp[16] = {
+            .value = {
+                0x6c, 0xc7, 0x14, 0x13, 0xdf, 0xfb, 0xc6, 0xed,
+                0xa3, 0x9c, 0xa7, 0x90, 0xae, 0x4c, 0x61, 0x47,
+            },
+        },
+        .confirm_req[17] = {
+            .value = {
+                0xc5, 0x17, 0x07, 0x35, 0x34, 0xbf, 0xc1, 0x4d,
+                0xc4, 0x57, 0xc0, 0xd9, 0xfd, 0xe9, 0x10, 0x08,
+            },
+        },
+        .confirm_rsp[17] = {
+            .value = {
+                0xbb, 0xcf, 0x41, 0xd2, 0x94, 0xea, 0xbe, 0x2f,
+                0xde, 0xb2, 0xb4, 0x20, 0x72, 0x1c, 0xf8, 0x35,
+            },
+        },
+        .random_req[17] = {
+            .value = {
+                0x59, 0x20, 0xb5, 0xdc, 0xaf, 0xc3, 0x8b, 0x32,
+                0xe6, 0x40, 0x0f, 0x02, 0x67, 0x45, 0x49, 0x1f,
+            },
+        },
+        .random_rsp[17] = {
+            .value = {
+                0xf5, 0x95, 0x60, 0x4c, 0x5f, 0x39, 0x54, 0xbf,
+                0x62, 0x9e, 0x85, 0xca, 0x31, 0x9a, 0x95, 0xee,
+            },
+        },
+        .confirm_req[18] = {
+            .value = {
+                0x36, 0x50, 0x78, 0x6b, 0x0f, 0x11, 0xe3, 0xa9,
+                0x79, 0x3a, 0xa6, 0x9d, 0xd4, 0x8b, 0x13, 0x3f,
+            },
+        },
+        .confirm_rsp[18] = {
+            .value = {
+                0xa5, 0x34, 0x5d, 0x5e, 0x43, 0x01, 0xf2, 0xe1,
+                0x3f, 0xf2, 0x1c, 0x8b, 0x13, 0xf7, 0x17, 0x3e,
+            },
+        },
+        .random_req[18] = {
+            .value = {
+                0x77, 0xa1, 0xbe, 0xbf, 0x49, 0xb8, 0x74, 0x73,
+                0x47, 0x78, 0x2a, 0xf8, 0x66, 0x6b, 0xff, 0xd2,
+            },
+        },
+        .random_rsp[18] = {
+            .value = {
+                0xa2, 0x05, 0x69, 0x65, 0x3f, 0xd4, 0xb4, 0xcd,
+                0xed, 0x8c, 0x36, 0x6d, 0x51, 0x6a, 0xbb, 0xef,
+            },
+        },
+        .confirm_req[19] = {
+            .value = {
+                0xda, 0xd8, 0x96, 0xfd, 0x1c, 0x0d, 0x1e, 0x56,
+                0xe2, 0x62, 0xed, 0x18, 0x4b, 0xd3, 0x46, 0x48,
+            },
+        },
+        .confirm_rsp[19] = {
+            .value = {
+                0xeb, 0x79, 0x5e, 0x52, 0x70, 0x25, 0xa7, 0x41,
+                0x33, 0xfa, 0xac, 0xd3, 0x27, 0x35, 0xfc, 0x5f,
+            },
+        },
+        .random_req[19] = {
+            .value = {
+                0xa8, 0x9c, 0xb9, 0xcd, 0x13, 0xb8, 0xdd, 0xd2,
+                0x09, 0xd6, 0xc8, 0x12, 0xc3, 0x69, 0x9a, 0x64,
+            },
+        },
+        .random_rsp[19] = {
+            .value = {
+                0x06, 0xe3, 0x8a, 0xef, 0xe4, 0x42, 0xae, 0x86,
+                0xef, 0x58, 0x80, 0xe8, 0xe3, 0xa2, 0x09, 0x44,
+            },
+        },
+        .dhkey_check_req = {
+            .value = {
+                0x6f, 0xa5, 0x37, 0x06, 0x4a, 0x89, 0x98, 0x39,
+                0xf6, 0x69, 0x48, 0x56, 0x17, 0x6d, 0x44, 0x7c,
+            },
+        },
+        .dhkey_check_rsp = {
+            .value = {
+                0x82, 0x48, 0xd4, 0x9e, 0xb8, 0x3c, 0xb4, 0xdc,
+                0x44, 0xcb, 0x19, 0xdb, 0xcb, 0xa2, 0x00, 0x5d,
+            },
+        },
+        .id_info_req = {
+            .irk = {
+                0x79, 0x12, 0x88, 0x97, 0xd9, 0x1c, 0x62, 0x0d,
+                0x26, 0x43, 0x7d, 0x25, 0x86, 0x79, 0xc7, 0x07,
+            },
+        },
+        .id_addr_info_req = {
+            .addr_type = 0,
+            .bd_addr = {
+                0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07,
+            },
+        },
+        .id_info_rsp = {
+            .irk = {
+                0xda, 0x6b, 0x27, 0xa0, 0xac, 0x71, 0xf0, 0xc3,
+                0x75, 0x51, 0xf6, 0x21, 0x94, 0xec, 0x81, 0x92,
+            },
+        },
+        .id_addr_info_rsp = {
+            .addr_type = 0,
+            .bd_addr = {
+                0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
+            },
+        },
+        .sign_info_rsp = {
+            .sig_key = {
+                0x49, 0x5b, 0x11, 0xb3, 0x4c, 0x1a, 0x23, 0x5c,
+                0x61, 0x4f, 0xe3, 0x08, 0xf9, 0x47, 0x8b, 0xdc,
+            },
+        },
+        .ltk = {
+            0x5a, 0x49, 0x28, 0xf0, 0x11, 0x3b, 0x6f, 0x6b,
+            0x3a, 0x69, 0x6d, 0xdd, 0xb2, 0xe5, 0xa8, 0x97,
+        },
+        .pair_alg = BLE_SM_PAIR_ALG_PASSKEY,
+        .authenticated = 1,
+        .passkey_info = {
+            .passkey = {
+                .action = BLE_SM_IOACT_DISP,
+                .passkey = 4915,
+            },
+        },
+    };
+    ble_sm_test_util_peer_sc_good(&params);
+}
+
+/**
+ * Secure connections pairing
+ * Master: us
+ * Pair algorithm: just works
+ * Initiator IO capabilities: 3
+ * Responder IO capabilities: 3
+ * Bonding: true
+ * Initiator address type: BLE_ADDR_TYPE_RPA_PUB_DEFAULT
+ * Responder address type: BLE_ADDR_TYPE_RPA_PUB_DEFAULT
+ * Initiator key distribution: 3
+ * Responder key distribution: 3
+ */
+TEST_CASE(ble_sm_sc_us_jw_iio3_rio3_b1_iat2_rat2_ik3_rk3)
+{
+    struct ble_sm_test_sc_params params;
+
+    params = (struct ble_sm_test_sc_params) {
+        .init_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT,
+        .init_id_addr = {
+            0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
+        },
+        .init_rpa = {
+            0x46, 0x85, 0x37, 0x90, 0x86, 0x58,
+        },
+        .resp_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT,
+        .resp_id_addr = {
+            0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07,
+        },
+        .resp_rpa = {
+            0x6d, 0x59, 0x7d, 0xa9, 0x87, 0x74,
+        },
+        .pair_req = {
+            .io_cap = 0x03,
+            .oob_data_flag = 0x00,
+            .authreq = 0x09,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x03,
+            .resp_key_dist = 0x03,
+        },
+        .pair_rsp = {
+            .io_cap = 0x03,
+            .oob_data_flag = 0x00,
+            .authreq = 0x09,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x03,
+            .resp_key_dist = 0x03,
+        },
+        .our_priv_key = {
+            0xdb, 0x24, 0x2e, 0x91, 0xda, 0xaa, 0x33, 0x33,
+            0x23, 0xa2, 0x1e, 0xbe, 0x06, 0x69, 0xdb, 0xad,
+            0xa9, 0x2a, 0x91, 0xb1, 0x24, 0x0a, 0xc7, 0xaf,
+            0x50, 0x0c, 0x65, 0x5b, 0x97, 0x1e, 0x12, 0x10,
+        },
+        .public_key_req = {
+            .x = {
+                0x54, 0xd9, 0x8f, 0xeb, 0xc1, 0xbb, 0xe6, 0x74,
+                0x8a, 0x55, 0x3a, 0x80, 0x0e, 0xef, 0x90, 0xc9,
+                0xab, 0x79, 0x12, 0x88, 0x97, 0xd9, 0x1c, 0x62,
+                0x0d, 0x26, 0x43, 0x7d, 0x25, 0x86, 0x79, 0xc7,
+            },
+            .y = {
+                0x07, 0x33, 0x91, 0x40, 0xde, 0x25, 0xb4, 0x3d,
+                0x81, 0x2f, 0xd2, 0x41, 0x98, 0xe7, 0xaf, 0x0f,
+                0x5f, 0x17, 0x85, 0x1f, 0x75, 0x6e, 0xf4, 0x0e,
+                0x05, 0x19, 0x7f, 0x03, 0x9b, 0xf4, 0x41, 0x23,
+            },
+        },
+        .public_key_rsp = {
+            .x = {
+                0x1d, 0x44, 0x66, 0x0d, 0x3a, 0x03, 0x71, 0x17,
+                0xb3, 0x10, 0x2e, 0xf0, 0xd3, 0xf8, 0xa2, 0x6c,
+                0x1f, 0xfc, 0xbf, 0x02, 0x62, 0x6b, 0x11, 0x5a,
+                0x76, 0x5b, 0x30, 0x20, 0xb1, 0xef, 0xb3, 0x76,
+            },
+            .y = {
+                0xf1, 0x23, 0x63, 0x75, 0xfc, 0xb6, 0xc9, 0x32,
+                0xa4, 0x36, 0xbe, 0x18, 0xa0, 0x7d, 0x0b, 0x16,
+                0x65, 0x24, 0xd0, 0xe3, 0x74, 0x1b, 0x34, 0x1a,
+                0xf9, 0xe2, 0xcb, 0x30, 0x93, 0x88, 0xd7, 0xfa,
+            },
+        },
+        .confirm_rsp[0] = {
+            .value = {
+                0x32, 0x5b, 0xee, 0x46, 0x42, 0x63, 0xca, 0x86,
+                0x2d, 0xe7, 0xd2, 0x75, 0x23, 0x7b, 0x4d, 0x59,
+            },
+        },
+        .random_req[0] = {
+            .value = {
+                0xd4, 0x66, 0x94, 0xc9, 0x96, 0xd0, 0x28, 0x96,
+                0x1c, 0xa1, 0x3b, 0xf7, 0x15, 0x95, 0x95, 0x43,
+            },
+        },
+        .random_rsp[0] = {
+            .value = {
+                0xb7, 0x98, 0xac, 0x85, 0xc4, 0x0a, 0x69, 0x8d,
+                0xa6, 0xaf, 0xf3, 0x1f, 0x63, 0x3c, 0xf2, 0x33,
+            },
+        },
+        .dhkey_check_req = {
+            .value = {
+                0x1a, 0xc7, 0x0b, 0xfe, 0xc0, 0x55, 0xc3, 0xdb,
+                0x94, 0x00, 0x89, 0x4f, 0x0e, 0x64, 0x05, 0xcd,
+            },
+        },
+        .dhkey_check_rsp = {
+            .value = {
+                0xf2, 0x45, 0x41, 0xc0, 0xba, 0x8d, 0x58, 0xec,
+                0x61, 0xfb, 0x48, 0x71, 0xb4, 0x0e, 0x7b, 0x19,
+            },
+        },
+        .id_info_req = {
+            .irk = {
+                0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+                0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
+            },
+        },
+        .id_addr_info_req = {
+            .addr_type = 0,
+            .bd_addr = {
+                0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07,
+            },
+        },
+        .id_info_rsp = {
+            .irk = {
+                0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+                0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+            },
+        },
+        .id_addr_info_rsp = {
+            .addr_type = 0,
+            .bd_addr = {
+                0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
+            },
+        },
+        .ltk = {
+            0x8b, 0xb6, 0xf6, 0x5a, 0x52, 0x7b, 0xb8, 0xf4,
+            0xb8, 0x4c, 0xe7, 0x60, 0x4f, 0x0b, 0x88, 0xfe,
+        },
+        .pair_alg = BLE_SM_PAIR_ALG_JW,
+        .authenticated = 0,
+        .passkey_info = {
+            .passkey = {
+                .action = BLE_SM_IOACT_NONE,
+            },
+        },
+    };
+    ble_sm_test_util_us_sc_good(&params);
+}
+
+/**
+ * Secure connections pairing
+ * Master: us
+ * Pair algorithm: numeric comparison
+ * Initiator IO capabilities: 1
+ * Responder IO capabilities: 1
+ * Bonding: true
+ * Initiator address type: BLE_ADDR_TYPE_RPA_PUB_DEFAULT
+ * Responder address type: BLE_ADDR_TYPE_RPA_PUB_DEFAULT
+ * Initiator key distribution: 3
+ * Responder key distribution: 3
+ */
+TEST_CASE(ble_sm_sc_us_nc_iio1_rio1_b1_iat2_rat2_ik3_rk3)
+{
+    struct ble_sm_test_sc_params params;
+
+    params = (struct ble_sm_test_sc_params) {
+        .init_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT,
+        .init_id_addr = {
+            0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
+        },
+        .init_rpa = {
+            0xc5, 0xf3, 0x5d, 0x83, 0xcd, 0x4a,
+        },
+        .resp_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT,
+        .resp_id_addr = {
+            0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07,
+        },
+        .resp_rpa = {
+            0x9f, 0x56, 0x57, 0x5e, 0x12, 0x65,
+        },
+        .pair_req = {
+            .io_cap = 0x01,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x03,
+            .resp_key_dist = 0x03,
+        },
+        .pair_rsp = {
+            .io_cap = 0x01,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x03,
+            .resp_key_dist = 0x03,
+        },
+        .our_priv_key = {
+            0xdb, 0x24, 0x2e, 0x91, 0xda, 0xaa, 0x33, 0x33,
+            0x23, 0xa2, 0x1e, 0xbe, 0x06, 0x69, 0xdb, 0xad,
+            0xa9, 0x2a, 0x91, 0xb1, 0x24, 0x0a, 0xc7, 0xaf,
+            0x50, 0x0c, 0x65, 0x5b, 0x97, 0x1e, 0x12, 0x10,
+        },
+        .public_key_req = {
+            .x = {
+                0x54, 0xd9, 0x8f, 0xeb, 0xc1, 0xbb, 0xe6, 0x74,
+                0x8a, 0x55, 0x3a, 0x80, 0x0e, 0xef, 0x90, 0xc9,
+                0xab, 0x79, 0x12, 0x88, 0x97, 0xd9, 0x1c, 0x62,
+                0x0d, 0x26, 0x43, 0x7d, 0x25, 0x86, 0x79, 0xc7,
+            },
+            .y = {
+                0x07, 0x33, 0x91, 0x40, 0xde, 0x25, 0xb4, 0x3d,
+                0x81, 0x2f, 0xd2, 0x41, 0x98, 0xe7, 0xaf, 0x0f,
+                0x5f, 0x17, 0x85, 0x1f, 0x75, 0x6e, 0xf4, 0x0e,
+                0x05, 0x19, 0x7f, 0x03, 0x9b, 0xf4, 0x41, 0x23,
+            },
+        },
+        .public_key_rsp = {
+            .x = {
+                0x1d, 0x44, 0x66, 0x0d, 0x3a, 0x03, 0x71, 0x17,
+                0xb3, 0x10, 0x2e, 0xf0, 0xd3, 0xf8, 0xa2, 0x6c,
+                0x1f, 0xfc, 0xbf, 0x02, 0x62, 0x6b, 0x11, 0x5a,
+                0x76, 0x5b, 0x30, 0x20, 0xb1, 0xef, 0xb3, 0x76,
+            },
+            .y = {
+                0xf1, 0x23, 0x63, 0x75, 0xfc, 0xb6, 0xc9, 0x32,
+                0xa4, 0x36, 0xbe, 0x18, 0xa0, 0x7d, 0x0b, 0x16,
+                0x65, 0x24, 0xd0, 0xe3, 0x74, 0x1b, 0x34, 0x1a,
+                0xf9, 0xe2, 0xcb, 0x30, 0x93, 0x88, 0xd7, 0xfa,
+            },
+        },
+        .confirm_rsp[0] = {
+            .value = {
+                0x39, 0xba, 0x86, 0x47, 0x06, 0x87, 0x14, 0xe4,
+                0x5c, 0x82, 0xe9, 0x6a, 0x80, 0xca, 0x87, 0xcd,
+            },
+        },
+        .random_req[0] = {
+            .value = {
+                0xce, 0xe2, 0xa3, 0x29, 0x8a, 0xc6, 0x76, 0x1d,
+                0xa2, 0xfd, 0xe0, 0x7f, 0x8c, 0xbe, 0xf8, 0x1d,
+            },
+        },
+        .random_rsp[0] = {
+            .value = {
+                0x3d, 0xac, 0xf0, 0xfe, 0x7c, 0x78, 0x73, 0x03,
+                0xe2, 0xb6, 0x59, 0x7e, 0x80, 0xb4, 0x69, 0x07,
+            },
+        },
+        .dhkey_check_req = {
+            .value = {
+                0xaa, 0x95, 0x9f, 0x33, 0x32, 0xa1, 0xbd, 0xf9,
+                0xef, 0xb9, 0x3d, 0xfb, 0x08, 0xd1, 0x28, 0xa0,
+            },
+        },
+        .dhkey_check_rsp = {
+            .value = {
+                0x3c, 0x10, 0x17, 0x76, 0x55, 0x65, 0x6f, 0x14,
+                0xfa, 0x80, 0xd3, 0x52, 0x04, 0x82, 0xe2, 0xf7,
+            },
+        },
+        .id_info_req = {
+            .irk = {
+                0xd4, 0x66, 0x94, 0xc9, 0x96, 0xd0, 0x28, 0x96,
+                0x1c, 0xa1, 0x3b, 0xf7, 0x15, 0x95, 0x95, 0x43,
+            },
+        },
+        .id_addr_info_req = {
+            .addr_type = 0,
+            .bd_addr = {
+                0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07,
+            },
+        },
+        .id_info_rsp = {
+            .irk = {
+                0xb7, 0x98, 0xac, 0x85, 0xc4, 0x0a, 0x69, 0x8d,
+                0xa6, 0xaf, 0xf3, 0x1f, 0x63, 0x3c, 0xf2, 0x33,
+            },
+        },
+        .id_addr_info_rsp = {
+            .addr_type = 0,
+            .bd_addr = {
+                0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
+            },
+        },
+        .ltk = {
+            0x95, 0x46, 0xe6, 0x8e, 0x52, 0xcc, 0x05, 0xca,
+            0xf4, 0x59, 0x57, 0x54, 0x8c, 0x0d, 0x51, 0xfc,
+        },
+        .pair_alg = BLE_SM_PAIR_ALG_NUMCMP,
+        .authenticated = 1,
+        .passkey_info = {
+            .passkey = {
+                .action = BLE_SM_IOACT_NUMCMP,
+                .numcmp_accept = 1,
+            },
+            .exp_numcmp = 70210,
+        },
+    };
+    ble_sm_test_util_us_sc_good(&params);
+}
+
+/**
+ * Secure connections pairing
+ * Master: us
+ * Pair algorithm: passkey entry
+ * Initiator IO capabilities: 2
+ * Responder IO capabilities: 0
+ * Bonding: true
+ * Initiator address type: BLE_ADDR_TYPE_RPA_PUB_DEFAULT
+ * Responder address type: BLE_ADDR_TYPE_RPA_PUB_DEFAULT
+ * Initiator key distribution: 7
+ * Responder key distribution: 3
+ */
+TEST_CASE(ble_sm_sc_us_pk_iio2_rio0_b1_iat2_rat2_ik7_rk3)
+{
+    struct ble_sm_test_sc_params params;
+
+    params = (struct ble_sm_test_sc_params) {
+        .init_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT,
+        .init_id_addr = {
+            0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
+        },
+        .init_rpa = {
+            0x6e, 0x56, 0x09, 0xef, 0x1e, 0x76,
+        },
+        .resp_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT,
+        .resp_id_addr = {
+            0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07,
+        },
+        .resp_rpa = {
+            0xb5, 0x29, 0xdf, 0xb4, 0x9b, 0x62,
+        },
+        .pair_req = {
+            .io_cap = 0x02,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x07,
+            .resp_key_dist = 0x03,
+        },
+        .pair_rsp = {
+            .io_cap = 0x00,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x07,
+            .resp_key_dist = 0x03,
+        },
+        .our_priv_key = {
+            0xdb, 0x24, 0x2e, 0x91, 0xda, 0xaa, 0x33, 0x33,
+            0x23, 0xa2, 0x1e, 0xbe, 0x06, 0x69, 0xdb, 0xad,
+            0xa9, 0x2a, 0x91, 0xb1, 0x24, 0x0a, 0xc7, 0xaf,
+            0x50, 0x0c, 0x65, 0x5b, 0x97, 0x1e, 0x12, 0x10,
+        },
+        .public_key_req = {
+            .x = {
+                0x54, 0xd9, 0x8f, 0xeb, 0xc1, 0xbb, 0xe6, 0x74,
+                0x8a, 0x55, 0x3a, 0x80, 0x0e, 0xef, 0x90, 0xc9,
+                0xab, 0x79, 0x12, 0x88, 0x97, 0xd9, 0x1c, 0x62,
+                0x0d, 0x26, 0x43, 0x7d, 0x25, 0x86, 0x79, 0xc7,
+            },
+            .y = {
+                0x07, 0x33, 0x91, 0x40, 0xde, 0x25, 0xb4, 0x3d,
+                0x81, 0x2f, 0xd2, 0x41, 0x98, 0xe7, 0xaf, 0x0f,
+                0x5f, 0x17, 0x85, 0x1f, 0x75, 0x6e, 0xf4, 0x0e,
+                0x05, 0x19, 0x7f, 0x03, 0x9b, 0xf4, 0x41, 0x23,
+            },
+        },
+        .public_key_rsp = {
+            .x = {
+                0x1d, 0x44, 0x66, 0x0d, 0x3a, 0x03, 0x71, 0x17,
+                0xb3, 0x10, 0x2e, 0xf0, 0xd3, 0xf8, 0xa2, 0x6c,
+                0x1f, 0xfc, 0xbf, 0x02, 0x62, 0x6b, 0x11, 0x5a,
+                0x76, 0x5b, 0x30, 0x20, 0xb1, 0xef, 0xb3, 0x76,
+            },
+            .y = {
+                0xf1, 0x23, 0x63, 0x75, 0xfc, 0xb6, 0xc9, 0x32,
+                0xa4, 0x36, 0xbe, 0x18, 0xa0, 0x7d, 0x0b, 0x16,
+                0x65, 0x24, 0xd0, 0xe3, 0x74, 0x1b, 0x34, 0x1a,
+                0xf9, 0xe2, 0xcb, 0x30, 0x93, 0x88, 0xd7, 0xfa,
+            },
+        },
+        .confirm_req[0] = {
+            .value = {
+                0x12, 0xe3, 0x01, 0xd0, 0x30, 0x59, 0xca, 0xd9,
+                0x78, 0x0b, 0x45, 0x73, 0xb1, 0x7a, 0x4d, 0xca,
+            },
+        },
+        .confirm_rsp[0] = {
+            .value = {
+                0x47, 0x68, 0x16, 0x24, 0xd4, 0x07, 0x60, 0x6c,
+                0xa5, 0x47, 0x6f, 0x05, 0x78, 0x71, 0x3e, 0xa8,
+            },
+        },
+        .random_req[0] = {
+            .value = {
+                0x2a, 0x29, 0xa8, 0xef, 0x0b, 0x70, 0x5f, 0x1b,
+                0x81, 0x4d, 0x97, 0xff, 0xfb, 0x7f, 0x30, 0x90,
+            },
+        },
+        .random_rsp[0] = {
+            .value = {
+                0x12, 0x9e, 0x1d, 0x12, 0x11, 0x44, 0x36, 0x74,
+                0xa3, 0x0c, 0xea, 0x36, 0x4d, 0xdf, 0x2d, 0x5d,
+            },
+        },
+        .confirm_req[1] = {
+            .value = {
+                0x4d, 0x6a, 0x32, 0xfe, 0xe2, 0xa0, 0xdd, 0x92,
+                0x60, 0x5c, 0x82, 0x7f, 0xa6, 0xa6, 0x24, 0xd6,
+            },
+        },
+        .confirm_rsp[1] = {
+            .value = {
+                0xd5, 0x3e, 0xa7, 0xa0, 0xbf, 0x39, 0x8e, 0xfe,
+                0xfd, 0x73, 0x47, 0x4c, 0x92, 0x8b, 0x74, 0x06,
+            },
+        },
+        .random_req[1] = {
+            .value = {
+                0xc1, 0x88, 0xdf, 0xb0, 0x99, 0xbb, 0xbf, 0xed,
+                0xdc, 0x40, 0x66, 0x55, 0xbe, 0x91, 0x56, 0x9a,
+            },
+        },
+        .random_rsp[1] = {
+            .value = {
+                0xed, 0xed, 0x9a, 0x61, 0xb8, 0x21, 0x03, 0x77,
+                0xa6, 0xcf, 0x34, 0x65, 0x8c, 0x18, 0x82, 0x9f,
+            },
+        },
+        .confirm_req[2] = {
+            .value = {
+                0xdb, 0xea, 0x94, 0x29, 0xe4, 0x44, 0x7d, 0x7b,
+                0xd3, 0x16, 0x81, 0x8e, 0xaf, 0xe6, 0x9c, 0x85,
+            },
+        },
+        .confirm_rsp[2] = {
+            .value = {
+                0x3f, 0xdd, 0x54, 0x76, 0xab, 0x45, 0x7f, 0x53,
+                0x64, 0x6b, 0x37, 0xa6, 0xc7, 0xc6, 0x4a, 0x73,
+            },
+        },
+        .random_req[2] = {
+            .value = {
+                0x5a, 0xf1, 0xfb, 0xde, 0xb3, 0xbe, 0x6e, 0xac,
+                0x68, 0x51, 0x47, 0x8e, 0x0b, 0xcd, 0xc1, 0xa0,
+            },
+        },
+        .random_rsp[2] = {
+            .value = {
+                0x29, 0x0f, 0x5e, 0x83, 0x87, 0xca, 0xd3, 0x21,
+                0xa7, 0x7e, 0x3d, 0x78, 0x47, 0x54, 0xf8, 0xe4,
+            },
+        },
+        .confirm_req[3] = {
+            .value = {
+                0xca, 0x3e, 0xd5, 0xe3, 0x59, 0xb0, 0x5d, 0x1e,
+                0x0f, 0x4c, 0x95, 0x0f, 0x6a, 0x72, 0xcf, 0x25,
+            },
+        },
+        .confirm_rsp[3] = {
+            .value = {
+                0x2f, 0x4d, 0x06, 0x40, 0x09, 0x68, 0x68, 0x45,
+                0x87, 0x79, 0x78, 0x48, 0xda, 0xe4, 0xf5, 0xae,
+            },
+        },
+        .random_req[3] = {
+            .value = {
+                0x63, 0x5a, 0xee, 0x91, 0xe4, 0xf8, 0xe8, 0x69,
+                0xd1, 0x46, 0x18, 0x0d, 0xd2, 0x94, 0xd8, 0x20,
+            },
+        },
+        .random_rsp[3] = {
+            .value = {
+                0x76, 0x36, 0xf5, 0xc2, 0x41, 0xb6, 0x3c, 0x1f,
+                0x36, 0x19, 0x58, 0xce, 0x8f, 0x41, 0xeb, 0x8c,
+            },
+        },
+        .confirm_req[4] = {
+            .value = {
+                0x76, 0xfd, 0x84, 0x0f, 0x0f, 0x58, 0x70, 0x45,
+                0x41, 0x33, 0x5d, 0xce, 0xe5, 0xe2, 0x2f, 0x83,
+            },
+        },
+        .confirm_rsp[4] = {
+            .value = {
+                0x87, 0xcf, 0xdf, 0xa5, 0x60, 0x82, 0x4f, 0x09,
+                0x4c, 0x50, 0x24, 0xba, 0x91, 0x96, 0x0d, 0x65,
+            },
+        },
+        .random_req[4] = {
+            .value = {
+                0x67, 0xdb, 0x73, 0x1e, 0x57, 0x5c, 0xb7, 0x86,
+                0xf8, 0xaf, 0x58, 0xd8, 0x0f, 0x97, 0x47, 0xce,
+            },
+        },
+        .random_rsp[4] = {
+            .value = {
+                0xaa, 0x99, 0x90, 0x05, 0x11, 0xfc, 0xc2, 0xd9,
+                0xb8, 0xd6, 0x9d, 0xef, 0x86, 0x10, 0xcf, 0x26,
+            },
+        },
+        .confirm_req[5] = {
+            .value = {
+                0xfc, 0x22, 0xd9, 0x1f, 0x5f, 0x86, 0x25, 0xe7,
+                0x5e, 0x55, 0x48, 0x35, 0xec, 0x32, 0x37, 0x6d,
+            },
+        },
+        .confirm_rsp[5] = {
+            .value = {
+                0x98, 0xbc, 0x07, 0x72, 0xa2, 0xe7, 0xa7, 0x66,
+                0x64, 0xf7, 0x29, 0x3a, 0xaf, 0x52, 0x18, 0x04,
+            },
+        },
+        .random_req[5] = {
+            .value = {
+                0xd3, 0x36, 0xb9, 0x69, 0x6a, 0x6d, 0x55, 0xbc,
+                0x82, 0xdf, 0x1c, 0x04, 0xa7, 0xd5, 0x00, 0x68,
+            },
+        },
+        .random_rsp[5] = {
+            .value = {
+                0xb9, 0x03, 0xbf, 0xd9, 0x86, 0x5a, 0x1a, 0xb4,
+                0xdc, 0xe6, 0x8f, 0x9b, 0xa4, 0xa8, 0x2a, 0x12,
+            },
+        },
+        .confirm_req[6] = {
+            .value = {
+                0xfe, 0x14, 0xab, 0x1c, 0xfd, 0x36, 0x64, 0x38,
+                0xc1, 0xf8, 0xdd, 0xcd, 0xf4, 0x77, 0xa1, 0xb8,
+            },
+        },
+        .confirm_rsp[6] = {
+            .value = {
+                0x2e, 0x70, 0x54, 0xdc, 0xa6, 0xae, 0xb2, 0xcd,
+                0x4a, 0x26, 0x97, 0xf8, 0xbf, 0xb4, 0xb4, 0x52,
+            },
+        },
+        .random_req[6] = {
+            .value = {
+                0x1e, 0x27, 0x73, 0x94, 0x44, 0xfc, 0xd4, 0x44,
+                0xbf, 0x5b, 0x7d, 0x5d, 0x6d, 0x13, 0x68, 0xb1,
+            },
+        },
+        .random_rsp[6] = {
+            .value = {
+                0xeb, 0xfd, 0x0b, 0xa1, 0x7b, 0xda, 0x61, 0xdc,
+                0x6d, 0xe4, 0x3b, 0x51, 0xa7, 0x09, 0x29, 0x6d,
+            },
+        },
+        .confirm_req[7] = {
+            .value = {
+                0x38, 0x2b, 0x23, 0xb9, 0x18, 0x2d, 0xb9, 0x0b,
+                0xe7, 0x4d, 0x20, 0x83, 0xab, 0x17, 0xfd, 0x88,
+            },
+        },
+        .confirm_rsp[7] = {
+            .value = {
+                0x65, 0x60, 0x85, 0xef, 0x0e, 0x9a, 0x23, 0x96,
+                0xe7, 0xa9, 0xee, 0xba, 0x9e, 0x48, 0xb9, 0x1c,
+            },
+        },
+        .random_req[7] = {
+            .value = {
+                0x8b, 0xa8, 0x7a, 0x33, 0x15, 0x1e, 0xa7, 0x78,
+                0x27, 0x01, 0x3e, 0x90, 0x43, 0x47, 0x5a, 0x9d,
+            },
+        },
+        .random_rsp[7] = {
+            .value = {
+                0x76, 0xf1, 0x21, 0x67, 0x94, 0x20, 0x6f, 0xc7,
+                0x84, 0xc8, 0xdb, 0x07, 0xdb, 0x77, 0xdd, 0x50,
+            },
+        },
+        .confirm_req[8] = {
+            .value = {
+                0x4e, 0x7f, 0x83, 0x8e, 0xa6, 0x28, 0xaa, 0x46,
+                0xa2, 0x69, 0x95, 0x3b, 0xf0, 0x71, 0x14, 0x24,
+            },
+        },
+        .confirm_rsp[8] = {
+            .value = {
+                0x93, 0x0b, 0x4d, 0xbe, 0x49, 0x36, 0xa0, 0x26,
+                0xe9, 0x18, 0x4e, 0xc8, 0x19, 0x59, 0xc1, 0x7d,
+            },
+        },
+        .random_req[8] = {
+            .value = {
+                0x11, 0xa9, 0xce, 0x26, 0x0e, 0x2f, 0x11, 0x0e,
+                0xc1, 0xbd, 0x68, 0x80, 0xc8, 0xf8, 0x41, 0x65,
+            },
+        },
+        .random_rsp[8] = {
+            .value = {
+                0xb6, 0x3d, 0x6b, 0x62, 0xb5, 0x37, 0x31, 0x28,
+                0x79, 0xc4, 0xe2, 0x62, 0xbb, 0x63, 0xf9, 0x91,
+            },
+        },
+        .confirm_req[9] = {
+            .value = {
+                0x5f, 0x55, 0xb5, 0xa4, 0x80, 0xa8, 0x54, 0x47,
+                0xa7, 0x79, 0x87, 0x12, 0x2e, 0x44, 0x92, 0x42,
+            },
+        },
+        .confirm_rsp[9] = {
+            .value = {
+                0x01, 0x69, 0xa2, 0xac, 0xd6, 0x62, 0x8a, 0x64,
+                0xa2, 0x0b, 0xd0, 0xb4, 0x0e, 0x68, 0xe0, 0x88,
+            },
+        },
+        .random_req[9] = {
+            .value = {
+                0x75, 0x1e, 0x56, 0xd0, 0xcb, 0x06, 0xfd, 0x51,
+                0x55, 0xae, 0x77, 0xa4, 0xf2, 0xe7, 0x86, 0x3c,
+            },
+        },
+        .random_rsp[9] = {
+            .value = {
+                0xff, 0xab, 0x8a, 0x7d, 0xb7, 0x40, 0xe5, 0x07,
+                0xfe, 0x8f, 0x74, 0xdb, 0x2c, 0x35, 0x35, 0x12,
+            },
+        },
+        .confirm_req[10] = {
+            .value = {
+                0x1f, 0x2a, 0xed, 0xcd, 0x6b, 0x87, 0xea, 0xa2,
+                0xf8, 0xd8, 0xad, 0x04, 0x23, 0xc7, 0x5d, 0x47,
+            },
+        },
+        .confirm_rsp[10] = {
+            .value = {
+                0x5b, 0x18, 0x2d, 0x96, 0x3b, 0xf6, 0xdc, 0x82,
+                0x3b, 0xfa, 0xc9, 0x81, 0xc7, 0x33, 0xa0, 0x07,
+            },
+        },
+        .random_req[10] = {
+            .value = {
+                0xd1, 0x3a, 0x82, 0xce, 0x31, 0x75, 0xa2, 0xbf,
+                0x6f, 0x12, 0xf2, 0xac, 0xf6, 0xcc, 0xea, 0x34,
+            },
+        },
+        .random_rsp[10] = {
+            .value = {
+                0xcf, 0x11, 0x3d, 0x44, 0x10, 0x0d, 0x26, 0x32,
+                0xa5, 0x61, 0x13, 0xfd, 0xb8, 0xed, 0x31, 0x53,
+            },
+        },
+        .confirm_req[11] = {
+            .value = {
+                0x67, 0x14, 0x8a, 0xf6, 0xc8, 0xb8, 0x73, 0x6b,
+                0xb2, 0xec, 0xa9, 0x61, 0xaa, 0xc0, 0xc9, 0x28,
+            },
+        },
+        .confirm_rsp[11] = {
+            .value = {
+                0xa5, 0xbf, 0x00, 0x07, 0x48, 0xff, 0x30, 0x36,
+                0x20, 0x83, 0xd7, 0xd6, 0xd0, 0x90, 0x46, 0x03,
+            },
+        },
+        .random_req[11] = {
+            .value = {
+                0x75, 0x99, 0x9a, 0xa3, 0xad, 0x9a, 0xe5, 0x9d,
+                0x2f, 0x21, 0xdb, 0x72, 0x2f, 0xaf, 0xb8, 0x79,
+            },
+        },
+        .random_rsp[11] = {
+            .value = {
+                0xa3, 0xb7, 0xb7, 0x46, 0x39, 0x99, 0xc2, 0x82,
+                0xe9, 0x31, 0x8d, 0xc2, 0x28, 0x1b, 0x86, 0x91,
+            },
+        },
+        .confirm_req[12] = {
+            .value = {
+                0x46, 0x2f, 0xc8, 0x0e, 0x2c, 0x70, 0x3a, 0xdb,
+                0x25, 0x2f, 0xce, 0xe6, 0x15, 0x1f, 0x9a, 0x06,
+            },
+        },
+        .confirm_rsp[12] = {
+            .value = {
+                0x9a, 0xa4, 0xe0, 0x03, 0x3a, 0xb5, 0x43, 0x75,
+                0x8e, 0x93, 0x35, 0x25, 0xe6, 0x5e, 0x9d, 0x7f,
+            },
+        },
+        .random_req[12] = {
+            .value = {
+                0x1f, 0x01, 0x32, 0x56, 0x64, 0x45, 0xc5, 0x20,
+                0xd4, 0xad, 0x13, 0x8f, 0xbe, 0x82, 0xc8, 0x01,
+            },
+        },
+        .random_rsp[12] = {
+            .value = {
+                0xd4, 0x3f, 0xa4, 0xc9, 0xe9, 0x2e, 0x62, 0x77,
+                0x4e, 0x21, 0x55, 0xd8, 0xde, 0x31, 0xf5, 0xea,
+            },
+        },
+        .confirm_req[13] = {
+            .value = {
+                0x4e, 0x48, 0x88, 0x4e, 0x4f, 0x74, 0x7e, 0xec,
+                0x99, 0x5d, 0xb1, 0xcb, 0x84, 0x88, 0x80, 0xe9,
+            },
+        },
+        .confirm_rsp[13] = {
+            .value = {
+                0x1a, 0x84, 0xfa, 0x2f, 0xd7, 0x3c, 0x5f, 0xee,
+                0x3e, 0x81, 0xc0, 0x4b, 0x35, 0x4b, 0x7e, 0x98,
+            },
+        },
+        .random_req[13] = {
+            .value = {
+                0xe3, 0x3a, 0xc5, 0x2f, 0x9f, 0x91, 0x93, 0xfb,
+                0xcb, 0xd8, 0x53, 0x63, 0xab, 0xc4, 0xa5, 0x85,
+            },
+        },
+        .random_rsp[13] = {
+            .value = {
+                0xa0, 0xcf, 0xad, 0x30, 0x2d, 0xec, 0xea, 0x81,
+                0xfd, 0x7f, 0xcf, 0x7c, 0x70, 0xc9, 0x89, 0x7b,
+            },
+        },
+        .confirm_req[14] = {
+            .value = {
+                0xe1, 0x64, 0x22, 0x19, 0x41, 0x44, 0x37, 0x2b,
+                0x92, 0x60, 0xa4, 0x1f, 0xd6, 0x53, 0xe0, 0xa0,
+            },
+        },
+        .confirm_rsp[14] = {
+            .value = {
+                0x08, 0xfa, 0xa4, 0xf8, 0x04, 0x08, 0xb8, 0x9f,
+                0x61, 0xb5, 0x68, 0xaf, 0x31, 0x12, 0x8d, 0x3f,
+            },
+        },
+        .random_req[14] = {
+            .value = {
+                0xad, 0x76, 0xc3, 0x1a, 0x4c, 0x64, 0x2c, 0x11,
+                0x5e, 0x48, 0x6d, 0x41, 0xf5, 0x77, 0xc2, 0x40,
+            },
+        },
+        .random_rsp[14] = {
+            .value = {
+                0x1b, 0xec, 0x78, 0x2b, 0xd9, 0xbe, 0x93, 0xbd,
+                0x0b, 0x03, 0xf1, 0xd8, 0x31, 0xe8, 0x60, 0x67,
+            },
+        },
+        .confirm_req[15] = {
+            .value = {
+                0x5e, 0x22, 0x44, 0x09, 0x97, 0xf9, 0xc5, 0xc7,
+                0x23, 0xc7, 0x74, 0x51, 0xe5, 0x9d, 0x5c, 0xed,
+            },
+        },
+        .confirm_rsp[15] = {
+            .value = {
+                0xfe, 0xb2, 0x90, 0xa7, 0x06, 0xaf, 0xdd, 0x6a,
+                0x83, 0x26, 0x3c, 0x78, 0x66, 0xe0, 0x9d, 0xd9,
+            },
+        },
+        .random_req[15] = {
+            .value = {
+                0xb2, 0xa0, 0x75, 0x6f, 0x77, 0xc1, 0x0b, 0x4e,
+                0x99, 0xfa, 0x9a, 0x02, 0xf6, 0xe4, 0x66, 0x27,
+            },
+        },
+        .random_rsp[15] = {
+            .value = {
+                0xf9, 0xdd, 0x69, 0xae, 0xc8, 0x66, 0xa9, 0xab,
+                0xb8, 0x01, 0x38, 0xc3, 0x2a, 0x6b, 0x94, 0x66,
+            },
+        },
+        .confirm_req[16] = {
+            .value = {
+                0x17, 0xc9, 0xf7, 0x2d, 0xe6, 0xb7, 0x99, 0x77,
+                0x65, 0xf7, 0x62, 0xc8, 0x0d, 0x7d, 0xbd, 0x81,
+            },
+        },
+        .confirm_rsp[16] = {
+            .value = {
+                0x39, 0xef, 0xbf, 0x39, 0xfa, 0x79, 0xc3, 0x7b,
+                0x71, 0x40, 0x3c, 0x1f, 0x67, 0xe5, 0x60, 0xe5,
+            },
+        },
+        .random_req[16] = {
+            .value = {
+                0x32, 0xab, 0x8b, 0xed, 0x90, 0x04, 0x5e, 0x17,
+                0xd2, 0x5e, 0xa8, 0x91, 0xf7, 0x77, 0xe3, 0xd7,
+            },
+        },
+        .random_rsp[16] = {
+            .value = {
+                0x6c, 0xc7, 0x14, 0x13, 0xdf, 0xfb, 0xc6, 0xed,
+                0xa3, 0x9c, 0xa7, 0x90, 0xae, 0x4c, 0x61, 0x47,
+            },
+        },
+        .confirm_req[17] = {
+            .value = {
+                0xc5, 0x17, 0x07, 0x35, 0x34, 0xbf, 0xc1, 0x4d,
+                0xc4, 0x57, 0xc0, 0xd9, 0xfd, 0xe9, 0x10, 0x08,
+            },
+        },
+        .confirm_rsp[17] = {
+            .value = {
+                0xbb, 0xcf, 0x41, 0xd2, 0x94, 0xea, 0xbe, 0x2f,
+                0xde, 0xb2, 0xb4, 0x20, 0x72, 0x1c, 0xf8, 0x35,
+            },
+        },
+        .random_req[17] = {
+            .value = {
+                0x59, 0x20, 0xb5, 0xdc, 0xaf, 0xc3, 0x8b, 0x32,
+                0xe6, 0x40, 0x0f, 0x02, 0x67, 0x45, 0x49, 0x1f,
+            },
+        },
+        .random_rsp[17] = {
+            .value = {
+                0xf5, 0x95, 0x60, 0x4c, 0x5f, 0x39, 0x54, 0xbf,
+                0x62, 0x9e, 0x85, 0xca, 0x31, 0x9a, 0x95, 0xee,
+            },
+        },
+        .confirm_req[18] = {
+            .value = {
+                0x36, 0x50, 0x78, 0x6b, 0x0f, 0x11, 0xe3, 0xa9,
+                0x79, 0x3a, 0xa6, 0x9d, 0xd4, 0x8b, 0x13, 0x3f,
+            },
+        },
+        .confirm_rsp[18] = {
+            .value = {
+                0xa5, 0x34, 0x5d, 0x5e, 0x43, 0x01, 0xf2, 0xe1,
+                0x3f, 0xf2, 0x1c, 0x8b, 0x13, 0xf7, 0x17, 0x3e,
+            },
+        },
+        .random_req[18] = {
+            .value = {
+                0x77, 0xa1, 0xbe, 0xbf, 0x49, 0xb8, 0x74, 0x73,
+                0x47, 0x78, 0x2a, 0xf8, 0x66, 0x6b, 0xff, 0xd2,
+            },
+        },
+        .random_rsp[18] = {
+            .value = {
+                0xa2, 0x05, 0x69, 0x65, 0x3f, 0xd4, 0xb4, 0xcd,
+                0xed, 0x8c, 0x36, 0x6d, 0x51, 0x6a, 0xbb, 0xef,
+            },
+        },
+        .confirm_req[19] = {
+            .value = {
+                0xda, 0xd8, 0x96, 0xfd, 0x1c, 0x0d, 0x1e, 0x56,
+                0xe2, 0x62, 0xed, 0x18, 0x4b, 0xd3, 0x46, 0x48,
+            },
+        },
+        .confirm_rsp[19] = {
+            .value = {
+                0xeb, 0x79, 0x5e, 0x52, 0x70, 0x25, 0xa7, 0x41,
+                0x33, 0xfa, 0xac, 0xd3, 0x27, 0x35, 0xfc, 0x5f,
+            },
+        },
+        .random_req[19] = {
+            .value = {
+                0xa8, 0x9c, 0xb9, 0xcd, 0x13, 0xb8, 0xdd, 0xd2,
+                0x09, 0xd6, 0xc8, 0x12, 0xc3, 0x69, 0x9a, 0x64,
+            },
+        },
+        .random_rsp[19] = {
+            .value = {
+                0x06, 0xe3, 0x8a, 0xef, 0xe4, 0x42, 0xae, 0x86,
+                0xef, 0x58, 0x80, 0xe8, 0xe3, 0xa2, 0x09, 0x44,
+            },
+        },
+        .dhkey_check_req = {
+            .value = {
+                0x6f, 0xa5, 0x37, 0x06, 0x4a, 0x89, 0x98, 0x39,
+                0xf6, 0x69, 0x48, 0x56, 0x17, 0x6d, 0x44, 0x7c,
+            },
+        },
+        .dhkey_check_rsp = {
+            .value = {
+                0x82, 0x48, 0xd4, 0x9e, 0xb8, 0x3c, 0xb4, 0xdc,
+                0x44, 0xcb, 0x19, 0xdb, 0xcb, 0xa2, 0x00, 0x5d,
+            },
+        },
+        .id_info_req = {
+            .irk = {
+                0x79, 0x12, 0x88, 0x97, 0xd9, 0x1c, 0x62, 0x0d,
+                0x26, 0x43, 0x7d, 0x25, 0x86, 0x79, 0xc7, 0x07,
+            },
+        },
+        .id_addr_info_req = {
+            .addr_type = 0,
+            .bd_addr = {
+                0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07,
+            },
+        },
+        .id_info_rsp = {
+            .irk = {
+                0xda, 0x6b, 0x27, 0xa0, 0xac, 0x71, 0xf0, 0xc3,
+                0x75, 0x51, 0xf6, 0x21, 0x94, 0xec, 0x81, 0x92,
+            },
+        },
+        .id_addr_info_rsp = {
+            .addr_type = 0,
+            .bd_addr = {
+                0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
+            },
+        },
+        .sign_info_rsp = {
+            .sig_key = {
+                0x49, 0x5b, 0x11, 0xb3, 0x4c, 0x1a, 0x23, 0x5c,
+                0x61, 0x4f, 0xe3, 0x08, 0xf9, 0x47, 0x8b, 0xdc,
+            },
+        },
+        .ltk = {
+            0x5a, 0x49, 0x28, 0xf0, 0x11, 0x3b, 0x6f, 0x6b,
+            0x3a, 0x69, 0x6d, 0xdd, 0xb2, 0xe5, 0xa8, 0x97,
+        },
+        .pair_alg = BLE_SM_PAIR_ALG_PASSKEY,
+        .authenticated = 1,
+        .passkey_info = {
+            .passkey = {
+                .action = BLE_SM_IOACT_INPUT,
+                .passkey = 4915,
+            },
+        },
+    };
+    ble_sm_test_util_us_sc_good(&params);
+}
+
 TEST_SUITE(ble_sm_sc_test_suite)
 {
+    /*** No privacy. */
+
     /* Peer as initiator. */
     ble_sm_sc_peer_jw_iio3_rio3_b1_iat0_rat0_ik5_rk7();
     ble_sm_sc_peer_pk_iio0_rio2_b1_iat0_rat0_ik5_rk7();
@@ -3036,6 +4892,18 @@ TEST_SUITE(ble_sm_sc_test_suite)
     ble_sm_sc_us_pk_iio2_rio4_b1_iat0_rat0_ik7_rk5();
     ble_sm_sc_us_pk_iio0_rio4_b1_iat0_rat0_ik7_rk5();
     ble_sm_sc_us_nc_iio1_rio4_b1_iat0_rat0_ik7_rk5();
+
+    /*** Privacy (id = public). */
+
+    /* Peer as initiator. */
+    ble_sm_sc_peer_jw_iio3_rio3_b1_iat2_rat2_ik7_rk7();
+    ble_sm_sc_peer_nc_iio1_rio1_b1_iat2_rat2_ik3_rk3();
+    ble_sm_sc_peer_pk_iio2_rio0_b1_iat2_rat2_ik7_rk3();
+
+    /* Us as initiator. */
+    ble_sm_sc_us_jw_iio3_rio3_b1_iat2_rat2_ik3_rk3();
+    ble_sm_sc_us_nc_iio1_rio1_b1_iat2_rat2_ik3_rk3();
+    ble_sm_sc_us_pk_iio2_rio0_b1_iat2_rat2_ik7_rk3();
 }
 
 #endif /* NIMBLE_OPT_SM */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b4c34462/net/nimble/host/src/test/ble_sm_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test.c b/net/nimble/host/src/test/ble_sm_test.c
index 12327db..4f732bd 100644
--- a/net/nimble/host/src/test/ble_sm_test.c
+++ b/net/nimble/host/src/test/ble_sm_test.c
@@ -390,8 +390,8 @@ TEST_CASE(ble_sm_test_case_peer_lgcy_jw_good)
     struct ble_sm_test_lgcy_params params;
 
     params = (struct ble_sm_test_lgcy_params) {
-        .init_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
-        .resp_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
+        .init_id_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
+        .resp_id_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
         .pair_req = (struct ble_sm_pair_cmd) {
             .io_cap = 0x04,
             .oob_data_flag = 0,
@@ -450,8 +450,8 @@ TEST_CASE(ble_sm_test_case_peer_lgcy_passkey_good)
     struct ble_sm_test_lgcy_params params;
 
     params = (struct ble_sm_test_lgcy_params) {
-        .init_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
-        .resp_addr = {0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07},
+        .init_id_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
+        .resp_id_addr = {0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07},
         .pair_req = (struct ble_sm_pair_cmd) {
             .io_cap = 0x04,
             .oob_data_flag = 0, .authreq = 0x05,
@@ -593,8 +593,8 @@ TEST_CASE(ble_sm_test_case_peer_sec_req_pair)
     struct ble_sm_test_lgcy_params params;
 
     params = (struct ble_sm_test_lgcy_params) {
-        .init_addr = {0x06, 0x05, 0x04, 0x03, 0x02, 0x01},
-        .resp_addr = {0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a},
+        .init_id_addr = {0x06, 0x05, 0x04, 0x03, 0x02, 0x01},
+        .resp_id_addr = {0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a},
         .sec_req = (struct ble_sm_sec_req) {
             .authreq = 0,
         },
@@ -657,8 +657,8 @@ TEST_CASE(ble_sm_test_case_peer_sc_numcmp_good)
     struct ble_sm_test_sc_params params;
 
     params = (struct ble_sm_test_sc_params) {
-        .init_addr = { 0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0 },
-        .resp_addr = { 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07 },
+        .init_id_addr = { 0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0 },
+        .resp_id_addr = { 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07 },
         .pair_req = (struct ble_sm_pair_cmd) {
             .io_cap = 0x01,
             .oob_data_flag = 0x00,
@@ -766,8 +766,8 @@ TEST_CASE(ble_sm_test_case_peer_sc_passkey_good)
     struct ble_sm_test_sc_params params;
 
     params = (struct ble_sm_test_sc_params) {
-        .init_addr = { 0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0 },
-        .resp_addr = { 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07 },
+        .init_id_addr = { 0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0 },
+        .resp_id_addr = { 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07 },
         .pair_req = (struct ble_sm_pair_cmd) {
             .io_cap = 0x04,
             .oob_data_flag = 0x00,
@@ -1339,8 +1339,8 @@ TEST_CASE(ble_sm_test_case_us_fail_inval)
 
     /* Invalid IO capabiltiies. */
     params = (struct ble_sm_test_lgcy_params) {
-        .init_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
-        .resp_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
+        .init_id_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
+        .resp_id_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
         .pair_req = (struct ble_sm_pair_cmd) {
             .io_cap = 3,
             .oob_data_flag = 0,
@@ -1365,8 +1365,8 @@ TEST_CASE(ble_sm_test_case_us_fail_inval)
 
     /* Invalid OOB flag. */
     params = (struct ble_sm_test_lgcy_params) {
-        .init_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
-        .resp_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
+        .init_id_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
+        .resp_id_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
         .pair_req = (struct ble_sm_pair_cmd) {
             .io_cap = 3,
             .oob_data_flag = 0,
@@ -1391,8 +1391,8 @@ TEST_CASE(ble_sm_test_case_us_fail_inval)
 
     /* Invalid authreq - reserved bonding flag. */
     params = (struct ble_sm_test_lgcy_params) {
-        .init_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
-        .resp_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
+        .init_id_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
+        .resp_id_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
         .pair_req = (struct ble_sm_pair_cmd) {
             .io_cap = 3,
             .oob_data_flag = 0,
@@ -1417,8 +1417,8 @@ TEST_CASE(ble_sm_test_case_us_fail_inval)
 
     /* Invalid authreq - reserved other flag. */
     params = (struct ble_sm_test_lgcy_params) {
-        .init_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
-        .resp_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
+        .init_id_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
+        .resp_id_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
         .pair_req = (struct ble_sm_pair_cmd) {
             .io_cap = 3,
             .oob_data_flag = 0,
@@ -1443,8 +1443,8 @@ TEST_CASE(ble_sm_test_case_us_fail_inval)
 
     /* Invalid key size - too small. */
     params = (struct ble_sm_test_lgcy_params) {
-        .init_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
-        .resp_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
+        .init_id_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
+        .resp_id_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
         .pair_req = (struct ble_sm_pair_cmd) {
             .io_cap = 3,
             .oob_data_flag = 0,
@@ -1469,8 +1469,8 @@ TEST_CASE(ble_sm_test_case_us_fail_inval)
 
     /* Invalid key size - too large. */
     params = (struct ble_sm_test_lgcy_params) {
-        .init_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
-        .resp_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
+        .init_id_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
+        .resp_id_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
         .pair_req = (struct ble_sm_pair_cmd) {
             .io_cap = 3,
             .oob_data_flag = 0,
@@ -1495,8 +1495,8 @@ TEST_CASE(ble_sm_test_case_us_fail_inval)
 
     /* Invalid init key dist. */
     params = (struct ble_sm_test_lgcy_params) {
-        .init_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
-        .resp_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
+        .init_id_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
+        .resp_id_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
         .pair_req = (struct ble_sm_pair_cmd) {
             .io_cap = 3,
             .oob_data_flag = 0,
@@ -1521,8 +1521,8 @@ TEST_CASE(ble_sm_test_case_us_fail_inval)
 
     /* Invalid resp key dist. */
     params = (struct ble_sm_test_lgcy_params) {
-        .init_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
-        .resp_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
+        .init_id_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
+        .resp_id_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
         .pair_req = (struct ble_sm_pair_cmd) {
             .io_cap = 3,
             .oob_data_flag = 0,
@@ -1551,8 +1551,8 @@ TEST_CASE(ble_sm_test_case_us_lgcy_jw_good)
     struct ble_sm_test_lgcy_params params;
 
     params = (struct ble_sm_test_lgcy_params) {
-        .init_addr = {0x06, 0x05, 0x04, 0x03, 0x02, 0x01},
-        .resp_addr = {0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a},
+        .init_id_addr = {0x06, 0x05, 0x04, 0x03, 0x02, 0x01},
+        .resp_id_addr = {0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a},
         .pair_req = (struct ble_sm_pair_cmd) {
             .io_cap = 3,
             .oob_data_flag = 0,
@@ -1616,8 +1616,8 @@ TEST_CASE(ble_sm_test_case_us_sec_req_pair)
     struct ble_sm_test_lgcy_params params;
 
     params = (struct ble_sm_test_lgcy_params) {
-        .init_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
-        .resp_addr = {0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07},
+        .init_id_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
+        .resp_id_addr = {0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07},
         .sec_req = (struct ble_sm_sec_req) {
             .authreq = 0x05,
         },
@@ -1722,10 +1722,10 @@ TEST_CASE(ble_sm_test_case_us_sc_jw_good)
     struct ble_sm_test_sc_params params;
 
     params = (struct ble_sm_test_sc_params) {
-        .init_addr = {
+        .init_id_addr = {
             0xd9, 0x38, 0x0c, 0x57, 0x0b, 0x00,
         },
-        .resp_addr = {
+        .resp_id_addr = {
             0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
         },
         .pair_req = {
@@ -1833,8 +1833,8 @@ TEST_CASE(ble_sm_test_case_us_sc_numcmp_good)
     struct ble_sm_test_sc_params params;
 
     params = (struct ble_sm_test_sc_params) {
-        .init_addr = { 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 },
-        .resp_addr = { 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07 },
+        .init_id_addr = { 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 },
+        .resp_id_addr = { 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07 },
         .pair_req = (struct ble_sm_pair_cmd) {
             .io_cap = 0x01,
             .oob_data_flag = 0x00,
@@ -1946,10 +1946,10 @@ TEST_CASE(ble_sm_test_case_us_sc_passkey_good)
     struct ble_sm_test_sc_params params;
 
     params = (struct ble_sm_test_sc_params) {
-        .init_addr = {
+        .init_id_addr = {
             0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
         },
-        .resp_addr = {
+        .resp_id_addr = {
             0x5d, 0xab, 0xaa, 0x67, 0x11, 0x00,
         },
         .pair_req = {


[47/50] [abbrv] incubator-mynewt-core git commit: BLE Host - Include our_id_addr/type in conn desc.

Posted by cc...@apache.org.
BLE Host - Include our_id_addr/type in conn desc.


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

Branch: refs/heads/develop
Commit: ad94ca6a9f14ea452056898567f3d1c296bb0b0c
Parents: ed9fea6
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 14 18:32:55 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:24:38 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/misc.c                | 3 +++
 net/nimble/host/include/host/ble_gap.h | 2 ++
 net/nimble/host/src/ble_gap.c          | 2 ++
 net/nimble/host/src/ble_hs_misc.c      | 2 +-
 net/nimble/host/src/ble_hs_priv.h      | 2 +-
 net/nimble/host/src/ble_sm.c           | 2 +-
 6 files changed, 10 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ad94ca6a/apps/bletiny/src/misc.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/misc.c b/apps/bletiny/src/misc.c
index b0c3ddb..e9f8eee 100644
--- a/apps/bletiny/src/misc.c
+++ b/apps/bletiny/src/misc.c
@@ -99,6 +99,9 @@ print_conn_desc(struct ble_gap_conn_desc *desc)
     console_printf("handle=%d our_ota_addr_type=%d our_ota_addr=",
                    desc->conn_handle, desc->our_ota_addr_type);
     print_addr(desc->our_ota_addr);
+    console_printf(" our_id_addr_type=%d our_id_addr=",
+                   desc->our_id_addr_type);
+    print_addr(desc->our_id_addr);
     console_printf(" peer_ota_addr_type=%d peer_ota_addr=",
                    desc->peer_ota_addr_type);
     print_addr(desc->peer_ota_addr);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ad94ca6a/net/nimble/host/include/host/ble_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gap.h b/net/nimble/host/include/host/ble_gap.h
index ba442d1..b7d2878 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -120,6 +120,7 @@ struct ble_gap_conn_desc {
     struct ble_gap_sec_state sec_state;
     uint8_t peer_ota_addr[6];
     uint8_t peer_id_addr[6];
+    uint8_t our_id_addr[6];
     uint8_t our_ota_addr[6];
     uint16_t conn_handle;
     uint16_t conn_itvl;
@@ -127,6 +128,7 @@ struct ble_gap_conn_desc {
     uint16_t supervision_timeout;
     uint8_t peer_ota_addr_type;
     uint8_t peer_id_addr_type;
+    uint8_t our_id_addr_type;
     uint8_t our_ota_addr_type;
 };
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ad94ca6a/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 3e9a0de..25b043d 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -279,6 +279,8 @@ ble_gap_fill_conn_desc(struct ble_hs_conn *conn,
 
     desc->our_ota_addr_type = addrs.our_ota_addr_type;
     memcpy(desc->our_ota_addr, addrs.our_ota_addr, 6);
+    desc->our_id_addr_type = addrs.our_id_addr_type;
+    memcpy(desc->our_id_addr, addrs.our_id_addr, 6);
     desc->peer_ota_addr_type = addrs.peer_ota_addr_type;
     memcpy(desc->peer_ota_addr, addrs.peer_ota_addr, 6);
     desc->peer_id_addr_type = addrs.peer_id_addr_type;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ad94ca6a/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 29438ea..9575ae3 100644
--- a/net/nimble/host/src/ble_hs_misc.c
+++ b/net/nimble/host/src/ble_hs_misc.c
@@ -163,7 +163,7 @@ ble_hs_misc_conn_chan_find_reqd(uint16_t conn_handle, uint16_t cid,
 }
 
 uint8_t
-ble_hs_misc_addr_type_to_ident(uint8_t addr_type)
+ble_hs_misc_addr_type_to_id(uint8_t addr_type)
 {
     switch (addr_type) {
     case BLE_ADDR_TYPE_PUBLIC:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ad94ca6a/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 11a34b6..d8e99f2 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -85,7 +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);
+uint8_t ble_hs_misc_addr_type_to_id(uint8_t addr_type);
 
 void ble_hs_cfg_init(struct ble_hs_cfg *cfg);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ad94ca6a/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 ceed1cd..601611e 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -562,7 +562,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 = ble_hs_misc_addr_type_to_ident(conn->bhc_addr_type);
+        peer_addr_type = ble_hs_misc_addr_type_to_id(conn->bhc_addr_type);
         memcpy(peer_addr, conn->bhc_addr, sizeof peer_addr);
     }
 


[38/50] [abbrv] incubator-mynewt-core git commit: BLE Host - SM SC unit tests.

Posted by cc...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4f9739f7/net/nimble/host/src/test/ble_sm_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test_util.c b/net/nimble/host/src/test/ble_sm_test_util.c
new file mode 100644
index 0000000..ad21a06
--- /dev/null
+++ b/net/nimble/host/src/test/ble_sm_test_util.c
@@ -0,0 +1,2092 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <stddef.h>
+#include <string.h>
+#include <errno.h>
+#include "testutil/testutil.h"
+#include "nimble/hci_common.h"
+#include "nimble/nimble_opt.h"
+#include "host/host_hci.h"
+#include "host/ble_sm.h"
+#include "host/ble_hs_test.h"
+#include "ble_hs_test_util.h"
+#include "ble_sm_test_util.h"
+
+int ble_sm_test_gap_event;
+int ble_sm_test_gap_status;
+struct ble_gap_sec_state ble_sm_test_sec_state;
+
+int ble_sm_test_store_obj_type;
+union ble_store_key ble_sm_test_store_key;
+union ble_store_value ble_sm_test_store_value;
+
+static ble_store_read_fn ble_sm_test_util_store_read;
+static ble_store_write_fn ble_sm_test_util_store_write;
+
+#define BLE_SM_TEST_UTIL_HCI_HDR(handle, pb, len) \
+    ((struct hci_data_hdr) {                            \
+        .hdh_handle_pb_bc = ((handle)  << 0) |          \
+                            ((pb)      << 12),          \
+        .hdh_len = (len)                                \
+    })
+
+static int
+ble_sm_test_util_store_read(int obj_type, union ble_store_key *key,
+                                  union ble_store_value *val)
+{
+    ble_sm_test_store_obj_type = obj_type;
+    ble_sm_test_store_key = *key;
+
+    return ble_hs_test_util_store_read(obj_type, key, val);
+}
+
+static int
+ble_sm_test_util_store_write(int obj_type, union ble_store_value *val)
+{
+    ble_sm_test_store_obj_type = obj_type;
+    ble_sm_test_store_value = *val;
+
+    return ble_hs_test_util_store_write(obj_type, val);
+}
+
+void
+ble_sm_test_util_init(void)
+{
+    ble_hs_test_util_init();
+    ble_hs_test_util_store_init(10, 10, 10);
+    ble_hs_cfg.store_read_cb = ble_sm_test_util_store_read;
+    ble_hs_cfg.store_write_cb = ble_sm_test_util_store_write;
+
+    ble_sm_test_store_obj_type = -1;
+    ble_sm_test_gap_event = -1;
+    ble_sm_test_gap_status = -1;
+
+    memset(&ble_sm_test_sec_state, 0xff, sizeof ble_sm_test_sec_state);
+}
+
+struct ble_sm_test_ltk_info {
+    uint8_t ltk[16];
+    unsigned authenticated:1;
+};
+
+struct ble_gap_passkey_action ble_sm_test_ioact;
+
+int
+ble_sm_test_util_conn_cb(int event, struct ble_gap_conn_ctxt *ctxt, void *arg)
+{
+    int rc;
+
+    switch (event) {
+    case BLE_GAP_EVENT_ENC_CHANGE:
+        ble_sm_test_gap_status = ctxt->enc_change.status;
+        ble_sm_test_sec_state = ctxt->desc->sec_state;
+        rc = 0;
+        break;
+
+    case BLE_GAP_EVENT_PASSKEY_ACTION:
+        ble_sm_test_ioact = ctxt->passkey_action;
+        break;
+
+    default:
+        return 0;
+    }
+
+    ble_sm_test_gap_event = event;
+
+    return rc;
+}
+
+static void
+ble_sm_test_util_rx_pair_cmd(uint16_t conn_handle, uint8_t op,
+                                   struct ble_sm_pair_cmd *cmd,
+                                   int rx_status)
+{
+    struct hci_data_hdr hci_hdr;
+    struct os_mbuf *om;
+    void *v;
+    int payload_len;
+    int rc;
+
+    hci_hdr = BLE_SM_TEST_UTIL_HCI_HDR(
+        2, BLE_HCI_PB_FIRST_FLUSH,
+        BLE_L2CAP_HDR_SZ + BLE_SM_HDR_SZ + BLE_SM_PAIR_CMD_SZ);
+
+    om = ble_hs_misc_pkthdr();
+    TEST_ASSERT_FATAL(om != NULL);
+
+    payload_len = BLE_SM_HDR_SZ + BLE_SM_PAIR_CMD_SZ;
+
+    v = os_mbuf_extend(om, payload_len);
+    TEST_ASSERT_FATAL(v != NULL);
+
+    ble_sm_pair_cmd_write(v, payload_len, op == BLE_SM_OP_PAIR_REQ,
+                                cmd);
+
+    rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SM,
+                                              &hci_hdr, om);
+    TEST_ASSERT(rc == rx_status);
+}
+
+static void
+ble_sm_test_util_rx_pair_req(uint16_t conn_handle,
+                                   struct ble_sm_pair_cmd *req,
+                                   int rx_status)
+{
+    ble_sm_test_util_rx_pair_cmd(conn_handle, BLE_SM_OP_PAIR_REQ,
+                                       req, rx_status);
+}
+
+static void
+ble_sm_test_util_rx_pair_rsp(uint16_t conn_handle, struct ble_sm_pair_cmd *rsp,
+                             int rx_status)
+{
+    ble_sm_test_util_rx_pair_cmd(conn_handle, BLE_SM_OP_PAIR_RSP,
+                                       rsp, rx_status);
+}
+
+static void
+ble_sm_test_util_rx_confirm(uint16_t conn_handle,
+                            struct ble_sm_pair_confirm *cmd)
+{
+    struct hci_data_hdr hci_hdr;
+    struct os_mbuf *om;
+    void *v;
+    int payload_len;
+    int rc;
+
+    hci_hdr = BLE_SM_TEST_UTIL_HCI_HDR(
+        2, BLE_HCI_PB_FIRST_FLUSH,
+        BLE_L2CAP_HDR_SZ + BLE_SM_HDR_SZ + BLE_SM_PAIR_CONFIRM_SZ);
+
+    om = ble_hs_misc_pkthdr();
+    TEST_ASSERT_FATAL(om != NULL);
+
+    payload_len = BLE_SM_HDR_SZ + BLE_SM_PAIR_CONFIRM_SZ;
+
+    v = os_mbuf_extend(om, payload_len);
+    TEST_ASSERT_FATAL(v != NULL);
+
+    ble_sm_pair_confirm_write(v, payload_len, cmd);
+
+    rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SM,
+                                              &hci_hdr, om);
+    TEST_ASSERT_FATAL(rc == 0);
+}
+
+static void
+ble_sm_test_util_rx_random(uint16_t conn_handle,
+                           struct ble_sm_pair_random *cmd,
+                           int exp_status)
+{
+    struct hci_data_hdr hci_hdr;
+    struct os_mbuf *om;
+    void *v;
+    int payload_len;
+    int rc;
+
+    hci_hdr = BLE_SM_TEST_UTIL_HCI_HDR(
+        2, BLE_HCI_PB_FIRST_FLUSH,
+        BLE_L2CAP_HDR_SZ + BLE_SM_HDR_SZ + BLE_SM_PAIR_RANDOM_SZ);
+
+    om = ble_hs_misc_pkthdr();
+    TEST_ASSERT_FATAL(om != NULL);
+
+    payload_len = BLE_SM_HDR_SZ + BLE_SM_PAIR_RANDOM_SZ;
+
+    v = os_mbuf_extend(om, payload_len);
+    TEST_ASSERT_FATAL(v != NULL);
+
+    ble_sm_pair_random_write(v, payload_len, cmd);
+
+    rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SM,
+                                              &hci_hdr, om);
+    TEST_ASSERT_FATAL(rc == exp_status);
+}
+
+void
+ble_sm_test_util_rx_sec_req(uint16_t conn_handle, struct ble_sm_sec_req *cmd,
+                            int exp_status)
+{
+    struct hci_data_hdr hci_hdr;
+    struct os_mbuf *om;
+    void *v;
+    int payload_len;
+    int rc;
+
+    hci_hdr = BLE_SM_TEST_UTIL_HCI_HDR(
+        2, BLE_HCI_PB_FIRST_FLUSH,
+        BLE_L2CAP_HDR_SZ + BLE_SM_HDR_SZ + BLE_SM_SEC_REQ_SZ);
+
+    om = ble_hs_misc_pkthdr();
+    TEST_ASSERT_FATAL(om != NULL);
+
+    payload_len = BLE_SM_HDR_SZ + BLE_SM_SEC_REQ_SZ;
+
+    v = os_mbuf_extend(om, payload_len);
+    TEST_ASSERT_FATAL(v != NULL);
+
+    ble_sm_sec_req_write(v, payload_len, cmd);
+
+    rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SM,
+                                              &hci_hdr, om);
+    TEST_ASSERT_FATAL(rc == exp_status);
+}
+
+static void
+ble_sm_test_util_rx_public_key(uint16_t conn_handle,
+                               struct ble_sm_public_key *cmd)
+{
+    struct hci_data_hdr hci_hdr;
+    struct os_mbuf *om;
+    void *v;
+    int payload_len;
+    int rc;
+
+    hci_hdr = BLE_SM_TEST_UTIL_HCI_HDR(
+        2, BLE_HCI_PB_FIRST_FLUSH,
+        BLE_L2CAP_HDR_SZ + BLE_SM_HDR_SZ + BLE_SM_PUBLIC_KEY_SZ);
+
+    om = ble_hs_misc_pkthdr();
+    TEST_ASSERT_FATAL(om != NULL);
+
+    payload_len = BLE_SM_HDR_SZ + BLE_SM_PUBLIC_KEY_SZ;
+
+    v = os_mbuf_extend(om, payload_len);
+    TEST_ASSERT_FATAL(v != NULL);
+
+    ble_sm_public_key_write(v, payload_len, cmd);
+
+    rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SM,
+                                              &hci_hdr, om);
+    TEST_ASSERT_FATAL(rc == 0);
+}
+
+static void
+ble_sm_test_util_rx_dhkey_check(uint16_t conn_handle,
+                                struct ble_sm_dhkey_check *cmd,
+                                int exp_status)
+{
+    struct hci_data_hdr hci_hdr;
+    struct os_mbuf *om;
+    void *v;
+    int payload_len;
+    int rc;
+
+    hci_hdr = BLE_SM_TEST_UTIL_HCI_HDR(
+        2, BLE_HCI_PB_FIRST_FLUSH,
+        BLE_L2CAP_HDR_SZ + BLE_SM_HDR_SZ + BLE_SM_DHKEY_CHECK_SZ);
+
+    om = ble_hs_misc_pkthdr();
+    TEST_ASSERT_FATAL(om != NULL);
+
+    payload_len = BLE_SM_HDR_SZ + BLE_SM_DHKEY_CHECK_SZ;
+
+    v = os_mbuf_extend(om, payload_len);
+    TEST_ASSERT_FATAL(v != NULL);
+
+    ble_sm_dhkey_check_write(v, payload_len, cmd);
+
+    rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SM,
+                                              &hci_hdr, om);
+    TEST_ASSERT_FATAL(rc == exp_status);
+}
+
+static void
+ble_sm_test_util_rx_id_info(uint16_t conn_handle,
+                            struct ble_sm_id_info *cmd,
+                            int exp_status)
+{
+    struct hci_data_hdr hci_hdr;
+    struct os_mbuf *om;
+    void *v;
+    int payload_len;
+    int rc;
+
+    hci_hdr = BLE_SM_TEST_UTIL_HCI_HDR(
+        2, BLE_HCI_PB_FIRST_FLUSH,
+        BLE_L2CAP_HDR_SZ + BLE_SM_HDR_SZ + BLE_SM_ID_INFO_SZ);
+
+    om = ble_hs_misc_pkthdr();
+    TEST_ASSERT_FATAL(om != NULL);
+
+    payload_len = BLE_SM_HDR_SZ + BLE_SM_ID_INFO_SZ;
+
+    v = os_mbuf_extend(om, payload_len);
+    TEST_ASSERT_FATAL(v != NULL);
+
+    ble_sm_id_info_write(v, payload_len, cmd);
+
+    rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SM,
+                                              &hci_hdr, om);
+    TEST_ASSERT_FATAL(rc == exp_status);
+}
+
+static void
+ble_sm_test_util_rx_id_addr_info(uint16_t conn_handle,
+                                 struct ble_sm_id_addr_info *cmd,
+                                 int exp_status)
+{
+    struct hci_data_hdr hci_hdr;
+    struct os_mbuf *om;
+    void *v;
+    int payload_len;
+    int rc;
+
+    hci_hdr = BLE_SM_TEST_UTIL_HCI_HDR(
+        2, BLE_HCI_PB_FIRST_FLUSH,
+        BLE_L2CAP_HDR_SZ + BLE_SM_HDR_SZ + BLE_SM_ID_ADDR_INFO_SZ);
+
+    om = ble_hs_misc_pkthdr();
+    TEST_ASSERT_FATAL(om != NULL);
+
+    payload_len = BLE_SM_HDR_SZ + BLE_SM_ID_ADDR_INFO_SZ;
+
+    v = os_mbuf_extend(om, payload_len);
+    TEST_ASSERT_FATAL(v != NULL);
+
+    ble_sm_id_addr_info_write(v, payload_len, cmd);
+
+    rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SM,
+                                              &hci_hdr, om);
+    TEST_ASSERT_FATAL(rc == exp_status);
+}
+
+static void
+ble_sm_test_util_rx_sign_info(uint16_t conn_handle,
+                              struct ble_sm_sign_info *cmd,
+                              int exp_status)
+{
+    struct hci_data_hdr hci_hdr;
+    struct os_mbuf *om;
+    void *v;
+    int payload_len;
+    int rc;
+
+    hci_hdr = BLE_SM_TEST_UTIL_HCI_HDR(
+        2, BLE_HCI_PB_FIRST_FLUSH,
+        BLE_L2CAP_HDR_SZ + BLE_SM_HDR_SZ + BLE_SM_SIGN_INFO_SZ);
+
+    om = ble_hs_misc_pkthdr();
+    TEST_ASSERT_FATAL(om != NULL);
+
+    payload_len = BLE_SM_HDR_SZ + BLE_SM_SIGN_INFO_SZ;
+
+    v = os_mbuf_extend(om, payload_len);
+    TEST_ASSERT_FATAL(v != NULL);
+
+    ble_sm_sign_info_write(v, payload_len, cmd);
+
+    rc = ble_hs_test_util_l2cap_rx_first_frag(conn_handle, BLE_L2CAP_CID_SM,
+                                              &hci_hdr, om);
+    TEST_ASSERT_FATAL(rc == exp_status);
+}
+
+static struct os_mbuf *
+ble_sm_test_util_verify_tx_hdr(uint8_t sm_op, uint16_t payload_len)
+{
+    struct os_mbuf *om;
+
+    om = ble_hs_test_util_prev_tx_dequeue();
+    TEST_ASSERT_FATAL(om != NULL);
+
+    TEST_ASSERT(OS_MBUF_PKTLEN(om) == BLE_SM_HDR_SZ + payload_len);
+    TEST_ASSERT_FATAL(om->om_data[0] == sm_op);
+
+    om->om_data += BLE_SM_HDR_SZ;
+    om->om_len -= BLE_SM_HDR_SZ;
+
+    return om;
+}
+
+static void
+ble_sm_test_util_verify_tx_pair_cmd(
+    uint8_t op,
+    struct ble_sm_pair_cmd *exp_cmd)
+{
+    struct ble_sm_pair_cmd cmd;
+    struct os_mbuf *om;
+
+    om = ble_sm_test_util_verify_tx_hdr(op, BLE_SM_PAIR_CMD_SZ);
+    ble_sm_pair_cmd_parse(om->om_data, om->om_len, &cmd);
+
+    TEST_ASSERT(cmd.io_cap == exp_cmd->io_cap);
+    TEST_ASSERT(cmd.oob_data_flag == exp_cmd->oob_data_flag);
+    TEST_ASSERT(cmd.authreq == exp_cmd->authreq);
+    TEST_ASSERT(cmd.max_enc_key_size == exp_cmd->max_enc_key_size);
+    TEST_ASSERT(cmd.init_key_dist == exp_cmd->init_key_dist);
+    TEST_ASSERT(cmd.resp_key_dist == exp_cmd->resp_key_dist);
+}
+
+static void
+ble_sm_test_util_verify_tx_pair_req(
+    struct ble_sm_pair_cmd *exp_req)
+{
+    ble_sm_test_util_verify_tx_pair_cmd(BLE_SM_OP_PAIR_REQ,
+                                              exp_req);
+}
+
+static void
+ble_sm_test_util_verify_tx_pair_rsp(
+    struct ble_sm_pair_cmd *exp_rsp)
+{
+    ble_sm_test_util_verify_tx_pair_cmd(BLE_SM_OP_PAIR_RSP,
+                                              exp_rsp);
+}
+
+static void
+ble_sm_test_util_verify_tx_pair_confirm(
+    struct ble_sm_pair_confirm *exp_cmd)
+{
+    struct ble_sm_pair_confirm cmd;
+    struct os_mbuf *om;
+
+    om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_PAIR_CONFIRM,
+                                        BLE_SM_PAIR_CONFIRM_SZ);
+    ble_sm_pair_confirm_parse(om->om_data, om->om_len, &cmd);
+
+    TEST_ASSERT(memcmp(cmd.value, exp_cmd->value, 16) == 0);
+}
+
+static void
+ble_sm_test_util_verify_tx_pair_random(
+    struct ble_sm_pair_random *exp_cmd)
+{
+    struct ble_sm_pair_random cmd;
+    struct os_mbuf *om;
+
+    om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_PAIR_RANDOM,
+                                        BLE_SM_PAIR_RANDOM_SZ);
+    ble_sm_pair_random_parse(om->om_data, om->om_len, &cmd);
+
+    TEST_ASSERT(memcmp(cmd.value, exp_cmd->value, 16) == 0);
+}
+
+static void
+ble_sm_test_util_verify_tx_public_key(
+    struct ble_sm_public_key *exp_cmd)
+{
+    struct ble_sm_public_key cmd;
+    struct os_mbuf *om;
+
+    ble_hs_test_util_tx_all();
+
+    om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_PAIR_PUBLIC_KEY,
+                                              BLE_SM_PUBLIC_KEY_SZ);
+    ble_sm_public_key_parse(om->om_data, om->om_len, &cmd);
+
+    TEST_ASSERT(memcmp(cmd.x, exp_cmd->x, sizeof cmd.x) == 0);
+    TEST_ASSERT(memcmp(cmd.y, exp_cmd->y, sizeof cmd.y) == 0);
+}
+
+static void
+ble_sm_test_util_verify_tx_dhkey_check(
+    struct ble_sm_dhkey_check *exp_cmd)
+{
+    struct ble_sm_dhkey_check cmd;
+    struct os_mbuf *om;
+
+    om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_PAIR_DHKEY_CHECK,
+                                              BLE_SM_DHKEY_CHECK_SZ);
+    ble_sm_dhkey_check_parse(om->om_data, om->om_len, &cmd);
+
+    TEST_ASSERT(memcmp(cmd.value, exp_cmd->value, 16) == 0);
+}
+
+static void
+ble_sm_test_util_verify_tx_id_info(struct ble_sm_id_info *exp_cmd)
+{
+    struct ble_sm_id_info cmd;
+    struct os_mbuf *om;
+    uint8_t irk[16];
+
+    ble_hs_test_util_tx_all();
+    om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_IDENTITY_INFO,
+                                        BLE_SM_ID_INFO_SZ);
+    ble_sm_id_info_parse(om->om_data, om->om_len, &cmd);
+
+    TEST_ASSERT(memcmp(cmd.irk, exp_cmd->irk, 16) == 0);
+
+    /* Ensure IRK is sent in big endian. */
+    swap_buf(irk, om->om_data, 16);
+    TEST_ASSERT(memcmp(irk, cmd.irk, 16) == 0);
+}
+
+static void
+ble_sm_test_util_verify_tx_id_addr_info(struct ble_sm_id_addr_info *exp_cmd)
+{
+    struct ble_sm_id_addr_info cmd;
+    struct os_mbuf *om;
+
+    ble_hs_test_util_tx_all();
+    om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_IDENTITY_ADDR_INFO,
+                                        BLE_SM_ID_ADDR_INFO_SZ);
+    ble_sm_id_addr_info_parse(om->om_data, om->om_len, &cmd);
+
+    TEST_ASSERT(cmd.addr_type == exp_cmd->addr_type);
+    TEST_ASSERT(memcmp(cmd.bd_addr, exp_cmd->bd_addr, 6) == 0);
+}
+
+static void
+ble_sm_test_util_verify_tx_sign_info(struct ble_sm_sign_info *exp_cmd)
+{
+    struct ble_sm_sign_info cmd;
+    struct os_mbuf *om;
+    uint8_t csrk[16];
+
+    ble_hs_test_util_tx_all();
+    om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_SIGN_INFO,
+                                        BLE_SM_ID_INFO_SZ);
+    ble_sm_sign_info_parse(om->om_data, om->om_len, &cmd);
+
+    TEST_ASSERT(memcmp(cmd.sig_key, exp_cmd->sig_key, 16) == 0);
+
+    /* Ensure CSRK is sent in big endian. */
+    swap_buf(csrk, om->om_data, 16);
+    TEST_ASSERT(memcmp(csrk, cmd.sig_key, 16) == 0);
+}
+
+static void
+ble_sm_test_util_verify_tx_enc_info(
+    struct ble_sm_enc_info *exp_cmd)
+{
+    struct ble_sm_enc_info cmd;
+    struct os_mbuf *om;
+
+    om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_ENC_INFO,
+                                        BLE_SM_ENC_INFO_SZ);
+    ble_sm_enc_info_parse(om->om_data, om->om_len, &cmd);
+
+    TEST_ASSERT(memcmp(cmd.ltk, exp_cmd->ltk, sizeof cmd.ltk) == 0);
+}
+
+static void
+ble_sm_test_util_verify_tx_sec_req(struct ble_sm_sec_req *exp_cmd)
+{
+    struct ble_sm_sec_req cmd;
+    struct os_mbuf *om;
+
+    ble_hs_test_util_tx_all();
+
+    om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_SEC_REQ,
+                                              BLE_SM_SEC_REQ_SZ);
+    ble_sm_sec_req_parse(om->om_data, om->om_len, &cmd);
+
+    TEST_ASSERT(cmd.authreq == exp_cmd->authreq);
+}
+
+void
+ble_sm_test_util_verify_tx_pair_fail(
+    struct ble_sm_pair_fail *exp_cmd)
+{
+    struct ble_sm_pair_fail cmd;
+    struct os_mbuf *om;
+
+    om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_PAIR_FAIL,
+                                              BLE_SM_PAIR_FAIL_SZ);
+    ble_sm_pair_fail_parse(om->om_data, om->om_len, &cmd);
+
+    TEST_ASSERT(cmd.reason == exp_cmd->reason);
+}
+
+static void
+ble_sm_test_util_rx_lt_key_req(uint16_t conn_handle, uint64_t r, uint16_t ediv)
+{
+    struct hci_le_lt_key_req evt;
+    int rc;
+
+    evt.subevent_code = BLE_HCI_LE_SUBEV_LT_KEY_REQ;
+    evt.connection_handle = conn_handle;
+    evt.random_number = r;
+    evt.encrypted_diversifier = ediv;
+
+    rc = ble_sm_ltk_req_rx(&evt);
+    TEST_ASSERT_FATAL(rc == 0);
+}
+
+static void
+ble_sm_test_util_verify_tx_lt_key_req_reply(uint16_t conn_handle, uint8_t *stk)
+{
+    uint8_t param_len;
+    uint8_t *param;
+
+    param = ble_hs_test_util_verify_tx_hci(BLE_HCI_OGF_LE,
+                                           BLE_HCI_OCF_LE_LT_KEY_REQ_REPLY,
+                                           &param_len);
+    TEST_ASSERT(param_len == BLE_HCI_LT_KEY_REQ_REPLY_LEN);
+    TEST_ASSERT(le16toh(param + 0) == conn_handle);
+    TEST_ASSERT(memcmp(param + 2, stk, 16) == 0);
+}
+
+static void
+ble_sm_test_util_verify_tx_lt_key_req_neg_reply(uint16_t conn_handle)
+{
+    uint8_t param_len;
+    uint8_t *param;
+
+    param = ble_hs_test_util_verify_tx_hci(BLE_HCI_OGF_LE,
+                                           BLE_HCI_OCF_LE_LT_KEY_REQ_NEG_REPLY,
+                                           &param_len);
+    TEST_ASSERT(param_len == BLE_HCI_LT_KEY_REQ_NEG_REPLY_LEN);
+    TEST_ASSERT(le16toh(param + 0) == conn_handle);
+}
+
+static void
+ble_sm_test_util_set_lt_key_req_reply_ack(uint8_t status,
+                                                uint16_t conn_handle)
+{
+    static uint8_t params[BLE_HCI_LT_KEY_REQ_REPLY_ACK_PARAM_LEN];
+
+    htole16(params, conn_handle);
+    ble_hs_test_util_set_ack_params(
+        host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_LT_KEY_REQ_REPLY),
+        status, params, sizeof params);
+}
+
+static void
+ble_sm_test_util_rx_enc_change(uint16_t conn_handle, uint8_t status,
+                                     uint8_t encryption_enabled)
+{
+    struct hci_encrypt_change evt;
+
+    evt.status = status;
+    evt.encryption_enabled = encryption_enabled;
+    evt.connection_handle = conn_handle;
+
+    ble_sm_enc_change_rx(&evt);
+}
+
+static void
+ble_sm_test_util_verify_tx_start_enc(uint16_t conn_handle,
+                                     uint64_t random_number,
+                                     uint16_t ediv,
+                                     uint8_t *ltk)
+{
+    uint8_t param_len;
+    uint8_t *param;
+
+    param = ble_hs_test_util_verify_tx_hci(BLE_HCI_OGF_LE,
+                                           BLE_HCI_OCF_LE_START_ENCRYPT,
+                                           &param_len);
+    TEST_ASSERT(param_len == BLE_HCI_LE_START_ENCRYPT_LEN);
+    TEST_ASSERT(le16toh(param + 0) == conn_handle);
+    TEST_ASSERT(le64toh(param + 2) == random_number);
+    TEST_ASSERT(le16toh(param + 10) == ediv);
+    TEST_ASSERT(memcmp(param + 12, ltk, 16) == 0);
+}
+
+void
+ble_sm_test_util_io_inject(struct ble_sm_test_passkey_info *passkey_info,
+                           uint8_t cur_sm_state)
+{
+    uint8_t io_sm_state;
+    int rc;
+
+    io_sm_state = ble_sm_ioact_state(passkey_info->passkey.action);
+    if (io_sm_state != cur_sm_state) {
+        return;
+    }
+
+    if (passkey_info->passkey.action == BLE_SM_IOACT_NUMCMP) {
+        TEST_ASSERT(ble_sm_test_ioact.numcmp == passkey_info->exp_numcmp);
+    }
+
+    rc = ble_sm_inject_io(2, &passkey_info->passkey);
+    TEST_ASSERT(rc == 0);
+}
+
+void
+ble_sm_test_util_io_inject_bad(uint16_t conn_handle, uint8_t correct_io_act)
+{
+    struct ble_sm_proc *proc;
+    struct ble_sm_io io;
+    uint8_t io_sm_state;
+    int already_injected;
+    int rc;
+    int i;
+
+    /* Lock mutex to prevent thread-safety assert from failing. */
+    ble_hs_lock();
+    proc = ble_sm_proc_find(conn_handle, BLE_SM_PROC_STATE_NONE, -1, NULL);
+    ble_hs_unlock();
+
+    TEST_ASSERT_FATAL(proc != NULL);
+
+    io_sm_state = ble_sm_ioact_state(correct_io_act);
+
+    for (i = 1; i < BLE_SM_IOACT_MAX_PLUS_ONE; i++) {
+        if (io_sm_state != proc->state  ||
+            i != correct_io_act         ||
+            proc->flags & BLE_SM_PROC_F_IO_INJECTED) {
+
+            already_injected = proc->flags & BLE_SM_PROC_F_IO_INJECTED;
+
+            io.action = i;
+            rc = ble_sm_inject_io(conn_handle, &io);
+
+            if (already_injected) {
+                TEST_ASSERT(rc == BLE_HS_EALREADY);
+            } else {
+                TEST_ASSERT(rc == BLE_HS_EINVAL);
+            }
+        }
+    }
+}
+
+void
+ble_sm_test_util_io_check_pre(struct ble_sm_test_passkey_info *passkey_info,
+                              uint8_t cur_sm_state)
+{
+    uint8_t io_sm_state;
+    int rc;
+
+    io_sm_state = ble_sm_ioact_state(passkey_info->passkey.action);
+    if (io_sm_state != cur_sm_state) {
+        return;
+    }
+
+    if (!passkey_info->io_before_rx) {
+        return;
+    }
+
+    if (passkey_info->passkey.action == BLE_SM_IOACT_NUMCMP) {
+        TEST_ASSERT(ble_sm_test_ioact.numcmp == passkey_info->exp_numcmp);
+    }
+
+    rc = ble_sm_inject_io(2, &passkey_info->passkey);
+    TEST_ASSERT(rc == 0);
+}
+
+void
+ble_sm_test_util_io_check_post(struct ble_sm_test_passkey_info *passkey_info,
+                               uint8_t cur_sm_state)
+{
+    uint8_t io_sm_state;
+    int rc;
+
+    io_sm_state = ble_sm_ioact_state(passkey_info->passkey.action);
+    if (io_sm_state != cur_sm_state) {
+        return;
+    }
+
+    if (passkey_info->io_before_rx) {
+        return;
+    }
+
+    if (passkey_info->passkey.action == BLE_SM_IOACT_NUMCMP) {
+        TEST_ASSERT(ble_sm_test_ioact.numcmp == passkey_info->exp_numcmp);
+    }
+
+    /* Ensure response not sent until user performs IO. */
+    ble_hs_test_util_tx_all();
+    TEST_ASSERT(ble_hs_test_util_prev_tx_queue_sz() == 0);
+
+    rc = ble_sm_inject_io(2, &passkey_info->passkey);
+    TEST_ASSERT_FATAL(rc == 0);
+}
+
+static void
+ble_sm_test_util_verify_lgcy_persist(struct ble_sm_test_lgcy_params *params)
+{
+    struct ble_store_value_sec value_sec;
+    struct ble_store_key_sec key_sec;
+    int rc;
+
+    memset(&key_sec, 0, sizeof key_sec);
+    key_sec.peer_addr_type = BLE_STORE_ADDR_TYPE_NONE;
+
+    if (params->pair_rsp.init_key_dist == 0) {
+        rc = ble_store_read_slv_sec(&key_sec, &value_sec);
+        TEST_ASSERT(rc == BLE_HS_ENOENT);
+    } else {
+        rc = ble_store_read_mst_sec(&key_sec, &value_sec);
+        TEST_ASSERT_FATAL(rc == 0);
+        TEST_ASSERT(value_sec.peer_addr_type == 0);
+        TEST_ASSERT(memcmp(value_sec.peer_addr, params->init_addr, 6) == 0);
+        TEST_ASSERT(value_sec.ediv == params->ediv);
+        TEST_ASSERT(value_sec.rand_num == params->r);
+        TEST_ASSERT(value_sec.authenticated == params->authenticated);
+        TEST_ASSERT(value_sec.ltk_present == 1);
+        TEST_ASSERT(memcmp(value_sec.ltk, params->enc_info_req.ltk, 16) == 0);
+        TEST_ASSERT(value_sec.irk_present == 0);
+        TEST_ASSERT(value_sec.csrk_present == 0);
+
+        /* Verify no other keys were persisted. */
+        key_sec.idx++;
+        rc = ble_store_read_mst_sec(&key_sec, &value_sec);
+        TEST_ASSERT_FATAL(rc == BLE_HS_ENOENT);
+    }
+
+    memset(&key_sec, 0, sizeof key_sec);
+    key_sec.peer_addr_type = BLE_STORE_ADDR_TYPE_NONE;
+
+    if (params->pair_rsp.resp_key_dist == 0) {
+        rc = ble_store_read_slv_sec(&key_sec, &value_sec);
+        TEST_ASSERT(rc == BLE_HS_ENOENT);
+    } else {
+        rc = ble_store_read_slv_sec(&key_sec, &value_sec);
+        TEST_ASSERT_FATAL(rc == 0);
+        TEST_ASSERT(value_sec.peer_addr_type == 0);
+        TEST_ASSERT(memcmp(value_sec.peer_addr, params->init_addr, 6) == 0);
+        TEST_ASSERT(value_sec.ediv == params->ediv);
+        TEST_ASSERT(value_sec.rand_num == params->r);
+        TEST_ASSERT(value_sec.authenticated == params->authenticated);
+        TEST_ASSERT(value_sec.ltk_present == 1);
+        TEST_ASSERT(memcmp(value_sec.ltk, params->enc_info_req.ltk, 16) == 0);
+        TEST_ASSERT(value_sec.irk_present == 0);
+        TEST_ASSERT(value_sec.csrk_present == 0);
+
+        /* Verify no other keys were persisted. */
+        key_sec.idx++;
+        rc = ble_store_read_slv_sec(&key_sec, &value_sec);
+        TEST_ASSERT_FATAL(rc == BLE_HS_ENOENT);
+    }
+}
+
+static void
+ble_sm_test_util_verify_sc_persist(struct ble_sm_test_sc_params *params,
+                                   int we_are_initiator)
+{
+    struct ble_store_value_sec value_sec;
+    struct ble_store_key_sec key_sec;
+    uint8_t *peer_addr;
+    uint8_t *mst_csrk;
+    uint8_t *slv_csrk;
+    uint8_t *mst_irk;
+    uint8_t *slv_irk;
+    uint8_t peer_addr_type;
+    uint8_t peer_key_dist;
+    uint8_t our_key_dist;
+    int csrk_expected;
+    int irk_expected;
+    int bonding;
+    int rc;
+
+    if (we_are_initiator) {
+        our_key_dist = params->pair_rsp.init_key_dist;
+        peer_key_dist = params->pair_rsp.resp_key_dist;
+
+        peer_addr_type = 0;
+        peer_addr = params->resp_addr;
+
+        mst_irk = params->id_info_req.irk;
+        mst_csrk = params->sign_info_req.sig_key;
+        slv_irk = params->id_info_rsp.irk;
+        slv_csrk = params->sign_info_rsp.sig_key;
+    } else {
+        our_key_dist = params->pair_rsp.resp_key_dist;
+        peer_key_dist = params->pair_rsp.init_key_dist;
+
+        peer_addr_type = 0;
+        peer_addr = params->init_addr;
+
+        mst_irk = params->id_info_rsp.irk;
+        mst_csrk = params->sign_info_rsp.sig_key;
+        slv_irk = params->id_info_req.irk;
+        slv_csrk = params->sign_info_req.sig_key;
+    }
+
+    memset(&key_sec, 0, sizeof key_sec);
+    key_sec.peer_addr_type = BLE_STORE_ADDR_TYPE_NONE;
+
+    bonding = params->pair_req.authreq & BLE_SM_PAIR_AUTHREQ_BOND &&
+              params->pair_rsp.authreq & BLE_SM_PAIR_AUTHREQ_BOND;
+
+    rc = ble_store_read_mst_sec(&key_sec, &value_sec);
+    if (!bonding) {
+        TEST_ASSERT(rc == BLE_HS_ENOENT);
+    } else {
+        TEST_ASSERT_FATAL(rc == 0);
+
+        irk_expected = !!(peer_key_dist & BLE_SM_PAIR_KEY_DIST_ID);
+        csrk_expected = !!(peer_key_dist & BLE_SM_PAIR_KEY_DIST_SIGN);
+
+        TEST_ASSERT(value_sec.peer_addr_type == peer_addr_type);
+        TEST_ASSERT(memcmp(value_sec.peer_addr, peer_addr, 6) == 0);
+        TEST_ASSERT(value_sec.ediv == 0);
+        TEST_ASSERT(value_sec.rand_num == 0);
+        TEST_ASSERT(value_sec.authenticated == params->authenticated);
+
+        /*** All keys get persisted in big endian. */
+
+        TEST_ASSERT(value_sec.ltk_present == 1);
+        TEST_ASSERT(memcmp(value_sec.ltk, params->ltk, 16) == 0);
+
+        TEST_ASSERT(value_sec.irk_present == irk_expected);
+        if (irk_expected) {
+            TEST_ASSERT(memcmp(value_sec.irk, mst_irk, 16) == 0);
+        }
+
+        TEST_ASSERT(value_sec.csrk_present == csrk_expected);
+        if (csrk_expected) {
+            TEST_ASSERT(memcmp(value_sec.csrk, mst_csrk, 16) == 0);
+        }
+    }
+
+    rc = ble_store_read_slv_sec(&key_sec, &value_sec);
+    if (!bonding) {
+        TEST_ASSERT(rc == BLE_HS_ENOENT);
+    } else {
+        TEST_ASSERT_FATAL(rc == 0);
+
+        irk_expected = !!(our_key_dist & BLE_SM_PAIR_KEY_DIST_ID);
+        csrk_expected = !!(our_key_dist & BLE_SM_PAIR_KEY_DIST_SIGN);
+
+        TEST_ASSERT(value_sec.peer_addr_type == peer_addr_type);
+        TEST_ASSERT(memcmp(value_sec.peer_addr, peer_addr, 6) == 0);
+        TEST_ASSERT(value_sec.ediv == 0);
+        TEST_ASSERT(value_sec.rand_num == 0);
+        TEST_ASSERT(value_sec.authenticated == params->authenticated);
+
+        TEST_ASSERT(value_sec.ltk_present == 1);
+        TEST_ASSERT(memcmp(value_sec.ltk, params->ltk, 16) == 0);
+
+        TEST_ASSERT(value_sec.irk_present == irk_expected);
+        if (irk_expected) {
+            TEST_ASSERT(memcmp(value_sec.irk, slv_irk, 16) == 0);
+        }
+
+        TEST_ASSERT(value_sec.csrk_present == csrk_expected);
+        if (csrk_expected) {
+            TEST_ASSERT(memcmp(value_sec.csrk, slv_csrk, 16) == 0);
+        }
+    }
+
+    /* Verify no other keys were persisted. */
+    key_sec.idx++;
+    rc = ble_store_read_slv_sec(&key_sec, &value_sec);
+    TEST_ASSERT_FATAL(rc == BLE_HS_ENOENT);
+    rc = ble_store_read_mst_sec(&key_sec, &value_sec);
+    TEST_ASSERT_FATAL(rc == BLE_HS_ENOENT);
+}
+
+void
+ble_sm_test_util_us_lgcy_good(
+    struct ble_sm_test_lgcy_params *params)
+{
+    struct ble_hs_conn *conn;
+    int rc;
+
+    ble_sm_test_util_init();
+    ble_hs_test_util_set_public_addr(params->init_addr);
+    ble_sm_dbg_set_next_pair_rand(params->random_req.value);
+    ble_sm_dbg_set_next_ediv(params->ediv);
+    ble_sm_dbg_set_next_start_rand(params->r);
+
+    if (params->has_enc_info_req) {
+        ble_sm_dbg_set_next_ltk(params->enc_info_req.ltk);
+    }
+
+    ble_hs_test_util_create_conn(2, params->resp_addr,
+                                 ble_sm_test_util_conn_cb,
+                                 NULL);
+
+    /* This test inspects and modifies the connection object after unlocking
+     * the host mutex.  It is not OK for real code to do this, but this test
+     * can assume the connection list is unchanging.
+     */
+    ble_hs_lock();
+    conn = ble_hs_conn_find(2);
+    TEST_ASSERT_FATAL(conn != NULL);
+    ble_hs_unlock();
+
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    ble_hs_test_util_set_ack(
+        host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_START_ENCRYPT), 0);
+    if (params->has_sec_req) {
+        ble_sm_test_util_rx_sec_req(2, &params->sec_req, 0);
+    } else {
+        /* Initiate the pairing procedure. */
+        rc = ble_gap_security_initiate(2);
+        TEST_ASSERT_FATAL(rc == 0);
+    }
+
+    /* Ensure we sent the expected pair request. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_pair_req(&params->pair_req);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Receive a pair response from the peer. */
+    ble_sm_test_util_rx_pair_rsp(2, &params->pair_rsp, 0);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Ensure we sent the expected pair confirm. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_pair_confirm(&params->confirm_req);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Receive a pair confirm from the peer. */
+    ble_sm_test_util_rx_confirm(2, &params->confirm_rsp);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Ensure we sent the expected pair random. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_pair_random(&params->random_req);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Receive a pair random from the peer. */
+    ble_sm_test_util_rx_random(2, &params->random_rsp, 0);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Ensure keys are distributed, if necessary. */
+    if (params->has_enc_info_req) {
+        ble_sm_test_util_verify_tx_enc_info(&params->enc_info_req);
+    }
+
+    /* Ensure we sent the expected start encryption command. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_start_enc(2, params->r, params->ediv,
+                                         params->stk);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Receive an encryption changed event. */
+    ble_sm_test_util_rx_enc_change(2, 0, 1);
+
+    /* Pairing should now be complete. */
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    /* Verify that security callback was executed. */
+    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
+    TEST_ASSERT(ble_sm_test_gap_status == 0);
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
+    TEST_ASSERT(!ble_sm_test_sec_state.authenticated);
+
+    /* Verify that connection has correct security state. */
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted ==
+                conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
+                conn->bhc_sec_state.authenticated);
+
+    /* Verify the appropriate security material was persisted. */
+    ble_sm_test_util_verify_lgcy_persist(params);
+}
+
+void
+ble_sm_test_util_peer_fail_inval(
+    int we_are_master,
+    uint8_t *init_addr,
+    uint8_t *resp_addr,
+    struct ble_sm_pair_cmd *pair_req,
+    struct ble_sm_pair_fail *pair_fail)
+{
+    struct ble_hs_conn *conn;
+
+    ble_sm_test_util_init();
+    ble_hs_test_util_set_public_addr(resp_addr);
+
+    ble_hs_test_util_create_conn(2, init_addr, ble_sm_test_util_conn_cb,
+                                 NULL);
+
+    /* This test inspects and modifies the connection object after unlocking
+     * the host mutex.  It is not OK for real code to do this, but this test
+     * can assume the connection list is unchanging.
+     */
+    ble_hs_lock();
+    conn = ble_hs_conn_find(2);
+    TEST_ASSERT_FATAL(conn != NULL);
+    ble_hs_unlock();
+
+    if (!we_are_master) {
+        conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
+    }
+
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    /* Receive a pair request from the peer. */
+    ble_sm_test_util_rx_pair_req(2, pair_req,
+                                 BLE_HS_SM_US_ERR(pair_fail->reason));
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    /* Ensure we sent the expected pair fail. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_pair_fail(pair_fail);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    /* Verify that security callback was not executed. */
+    TEST_ASSERT(ble_sm_test_gap_event == -1);
+    TEST_ASSERT(ble_sm_test_gap_status == -1);
+
+    /* Verify that connection has correct security state. */
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(!conn->bhc_sec_state.authenticated);
+}
+
+void
+ble_sm_test_util_peer_lgcy_fail_confirm(
+    uint8_t *init_addr,
+    uint8_t *resp_addr,
+    struct ble_sm_pair_cmd *pair_req,
+    struct ble_sm_pair_cmd *pair_rsp,
+    struct ble_sm_pair_confirm *confirm_req,
+    struct ble_sm_pair_confirm *confirm_rsp,
+    struct ble_sm_pair_random *random_req,
+    struct ble_sm_pair_random *random_rsp,
+    struct ble_sm_pair_fail *fail_rsp)
+{
+    struct ble_hs_conn *conn;
+
+    ble_sm_test_util_init();
+    ble_hs_test_util_set_public_addr(resp_addr);
+    ble_sm_dbg_set_next_pair_rand(random_rsp->value);
+
+    ble_hs_test_util_create_conn(2, init_addr, ble_sm_test_util_conn_cb,
+                                 NULL);
+
+    /* This test inspects and modifies the connection object after unlocking
+     * the host mutex.  It is not OK for real code to do this, but this test
+     * can assume the connection list is unchanging.
+     */
+    ble_hs_lock();
+    conn = ble_hs_conn_find(2);
+    TEST_ASSERT_FATAL(conn != NULL);
+    ble_hs_unlock();
+
+    /* Peer is the initiator so we must be the slave. */
+    conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
+
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    /* Receive a pair request from the peer. */
+    ble_sm_test_util_rx_pair_req(2, pair_req, 0);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
+
+    /* Ensure we sent the expected pair response. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_pair_rsp(pair_rsp);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
+
+    /* Receive a pair confirm from the peer. */
+    ble_sm_test_util_rx_confirm(2, confirm_req);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
+
+    /* Ensure we sent the expected pair confirm. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_pair_confirm(confirm_rsp);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
+
+    /* Receive a pair random from the peer. */
+    ble_sm_test_util_rx_random(
+        2, random_req, BLE_HS_SM_US_ERR(BLE_SM_ERR_CONFIRM_MISMATCH));
+
+    /* Ensure we sent the expected pair fail. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_pair_fail(fail_rsp);
+
+    /* The proc should now be freed. */
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    /* Verify that security callback was executed. */
+    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
+    TEST_ASSERT(ble_sm_test_gap_status ==
+                BLE_HS_SM_US_ERR(BLE_SM_ERR_CONFIRM_MISMATCH));
+    TEST_ASSERT(!ble_sm_test_sec_state.encrypted);
+    TEST_ASSERT(!ble_sm_test_sec_state.authenticated);
+
+    /* Verify that connection has correct security state. */
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted ==
+                conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
+                conn->bhc_sec_state.authenticated);
+}
+
+static void
+ble_sm_test_util_peer_lgcy_good_once(struct ble_sm_test_lgcy_params *params)
+{
+    struct ble_hs_conn *conn;
+    int rc;
+
+    ble_sm_test_util_init();
+
+    ble_hs_cfg.sm_io_cap = params->pair_rsp.io_cap;
+    ble_hs_cfg.sm_oob_data_flag = params->pair_rsp.oob_data_flag;
+    ble_hs_cfg.sm_bonding = !!(params->pair_rsp.authreq &
+                               BLE_SM_PAIR_AUTHREQ_BOND);
+    ble_hs_cfg.sm_mitm = !!(params->pair_rsp.authreq &
+                            BLE_SM_PAIR_AUTHREQ_MITM);
+    ble_hs_cfg.sm_sc = 0;
+    ble_hs_cfg.sm_keypress = !!(params->pair_rsp.authreq &
+                                BLE_SM_PAIR_AUTHREQ_KEYPRESS);
+    ble_hs_cfg.sm_our_key_dist = params->pair_rsp.resp_key_dist;
+    ble_hs_cfg.sm_their_key_dist = params->pair_rsp.init_key_dist;
+
+    ble_hs_test_util_set_public_addr(params->resp_addr);
+    ble_sm_dbg_set_next_pair_rand(params->random_rsp.value);
+    ble_sm_dbg_set_next_ediv(params->ediv);
+    ble_sm_dbg_set_next_start_rand(params->r);
+
+    if (params->has_enc_info_req) {
+        ble_sm_dbg_set_next_ltk(params->enc_info_req.ltk);
+    }
+
+    ble_hs_test_util_create_conn(2, params->init_addr,
+                                 ble_sm_test_util_conn_cb,
+                                 NULL);
+
+    /* This test inspects and modifies the connection object after unlocking
+     * the host mutex.  It is not OK for real code to do this, but this test
+     * can assume the connection list is unchanging.
+     */
+    ble_hs_lock();
+    conn = ble_hs_conn_find(2);
+    TEST_ASSERT_FATAL(conn != NULL);
+    ble_hs_unlock();
+
+    /* Peer is the initiator so we must be the slave. */
+    conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
+
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    if (params->has_sec_req) {
+        rc = ble_sm_slave_initiate(2);
+        TEST_ASSERT(rc == 0);
+
+        /* Ensure we sent the expected security request. */
+        ble_sm_test_util_verify_tx_sec_req(&params->sec_req);
+    }
+
+    /* Receive a pair request from the peer. */
+    ble_sm_test_util_rx_pair_req(2, &params->pair_req, 0);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Ensure we sent the expected pair response. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_pair_rsp(&params->pair_rsp);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    ble_sm_test_util_io_check_pre(&params->passkey_info,
+                                  BLE_SM_PROC_STATE_CONFIRM);
+
+    /* Receive a pair confirm from the peer. */
+    ble_sm_test_util_rx_confirm(2, &params->confirm_req);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    ble_sm_test_util_io_check_post(&params->passkey_info,
+                                   BLE_SM_PROC_STATE_CONFIRM);
+
+    /* Ensure we sent the expected pair confirm. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_pair_confirm(&params->confirm_rsp);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Receive a pair random from the peer. */
+    ble_sm_test_util_rx_random(2, &params->random_req, 0);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Ensure we sent the expected pair random. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_pair_random(&params->random_rsp);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Receive a long term key request from the controller. */
+    ble_sm_test_util_set_lt_key_req_reply_ack(0, 2);
+    ble_sm_test_util_rx_lt_key_req(2, params->r, params->ediv);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Ensure we sent the expected long term key request reply command. */
+    ble_sm_test_util_verify_tx_lt_key_req_reply(2, params->stk);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Receive an encryption changed event. */
+    ble_sm_test_util_rx_enc_change(2, 0, 1);
+
+    if (params->has_enc_info_req) {
+        return; // XXX
+    }
+
+    /* Pairing should now be complete. */
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    /* Verify that security callback was executed. */
+    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
+    TEST_ASSERT(ble_sm_test_gap_status == 0);
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
+                params->authenticated);
+
+    /* Verify that connection has correct security state. */
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted ==
+                conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
+                conn->bhc_sec_state.authenticated);
+
+    /* Verify the appropriate security material was persisted. */
+    ble_sm_test_util_verify_lgcy_persist(params);
+}
+
+void
+ble_sm_test_util_peer_lgcy_good(struct ble_sm_test_lgcy_params *params)
+{
+    params->passkey_info.io_before_rx = 0;
+    ble_sm_test_util_peer_lgcy_good_once(params);
+
+    params->passkey_info.io_before_rx = 1;
+    ble_sm_test_util_peer_lgcy_good_once(params);
+}
+
+/**
+ * @param send_enc_req          Whether this procedure is initiated by a slave
+ *                                  security request;
+ *                                  1: We send a security request at start.
+ *                                  0: No security request; peer initiates.
+ */
+void
+ble_sm_test_util_peer_bonding_good(int send_enc_req, uint8_t *ltk,
+                                   int authenticated,
+                                   uint16_t ediv, uint64_t rand_num)
+{
+    struct ble_store_value_sec value_sec;
+    struct ble_hs_conn *conn;
+    int rc;
+
+    ble_sm_test_util_init();
+
+    ble_hs_test_util_create_conn(2, ((uint8_t[6]){1,2,3,4,5,6}),
+                                 ble_sm_test_util_conn_cb,
+                                 NULL);
+
+    /* This test inspects and modifies the connection object after unlocking
+     * the host mutex.  It is not OK for real code to do this, but this test
+     * can assume the connection list is unchanging.
+     */
+    ble_hs_lock();
+    conn = ble_hs_conn_find(2);
+    TEST_ASSERT_FATAL(conn != NULL);
+    conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
+    ble_hs_unlock();
+
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    /* Populate the SM database with an LTK for this peer. */
+    value_sec.peer_addr_type = conn->bhc_addr_type;
+    memcpy(value_sec.peer_addr, conn->bhc_addr, sizeof value_sec.peer_addr);
+    value_sec.ediv = ediv;
+    value_sec.rand_num = rand_num;
+    memcpy(value_sec.ltk, ltk, sizeof value_sec.ltk);
+    value_sec.ltk_present = 1;
+    value_sec.authenticated = authenticated;
+    value_sec.sc = 0;
+
+    rc = ble_store_write_slv_sec(&value_sec);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    if (send_enc_req) {
+        rc = ble_sm_slave_initiate(2);
+        TEST_ASSERT(rc == 0);
+    }
+
+    /* Receive a long term key request from the controller. */
+    ble_sm_test_util_set_lt_key_req_reply_ack(0, 2);
+    ble_sm_test_util_rx_lt_key_req(2, rand_num, ediv);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+
+    /* Ensure the LTK request event got sent to the application. */
+    TEST_ASSERT(ble_sm_test_store_obj_type ==
+                BLE_STORE_OBJ_TYPE_SLV_SEC);
+    TEST_ASSERT(ble_sm_test_store_key.sec.peer_addr_type ==
+                BLE_ADDR_TYPE_PUBLIC);
+    TEST_ASSERT(ble_sm_test_store_key.sec.ediv_rand_present);
+    TEST_ASSERT(ble_sm_test_store_key.sec.ediv == ediv);
+    TEST_ASSERT(ble_sm_test_store_key.sec.rand_num == rand_num);
+
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
+
+    /* Ensure we sent the expected long term key request reply command. */
+    ble_sm_test_util_verify_tx_lt_key_req_reply(2, value_sec.ltk);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
+
+    /* Receive an encryption changed event. */
+    ble_sm_test_util_rx_enc_change(2, 0, 1);
+
+    /* Pairing should now be complete. */
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    /* Verify that security callback was executed. */
+    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
+    TEST_ASSERT(ble_sm_test_gap_status == 0);
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
+                authenticated);
+
+    /* Verify that connection has correct security state. */
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
+                authenticated);
+}
+
+void
+ble_sm_test_util_peer_bonding_bad(uint16_t ediv, uint64_t rand_num)
+{
+    struct ble_hs_conn *conn;
+
+    ble_sm_test_util_init();
+
+    ble_hs_test_util_create_conn(2, ((uint8_t[6]){1,2,3,4,5,6}),
+                                 ble_sm_test_util_conn_cb,
+                                 NULL);
+
+    /* This test inspects and modifies the connection object after unlocking
+     * the host mutex.  It is not OK for real code to do this, but this test
+     * can assume the connection list is unchanging.
+     */
+    ble_hs_lock();
+    conn = ble_hs_conn_find(2);
+    TEST_ASSERT_FATAL(conn != NULL);
+    conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
+    ble_hs_unlock();
+
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    /* Receive a long term key request from the controller. */
+    ble_sm_test_util_set_lt_key_req_reply_ack(0, 2);
+    ble_sm_test_util_rx_lt_key_req(2, rand_num, ediv);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+
+    /* Ensure the LTK request event got sent to the application. */
+    TEST_ASSERT(ble_sm_test_store_obj_type ==
+                BLE_STORE_OBJ_TYPE_SLV_SEC);
+    TEST_ASSERT(ble_sm_test_store_key.sec.ediv_rand_present);
+    TEST_ASSERT(ble_sm_test_store_key.sec.ediv == ediv);
+    TEST_ASSERT(ble_sm_test_store_key.sec.rand_num == rand_num);
+
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+
+    /* Ensure we sent the expected long term key request neg reply command. */
+    ble_sm_test_util_verify_tx_lt_key_req_neg_reply(2);
+
+    /* Ensure the security procedure was aborted. */
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(!conn->bhc_sec_state.authenticated);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+}
+
+static void
+ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
+{
+    struct ble_hs_conn *conn;
+    int num_iters;
+    int rc;
+    int i;
+
+    ble_sm_test_util_init();
+
+    ble_hs_cfg.sm_io_cap = params->pair_rsp.io_cap;
+    ble_hs_cfg.sm_oob_data_flag = params->pair_rsp.oob_data_flag;
+    ble_hs_cfg.sm_bonding = !!(params->pair_rsp.authreq &
+                               BLE_SM_PAIR_AUTHREQ_BOND);
+    ble_hs_cfg.sm_mitm = !!(params->pair_rsp.authreq &
+                            BLE_SM_PAIR_AUTHREQ_MITM);
+    ble_hs_cfg.sm_sc = 1;
+    ble_hs_cfg.sm_keypress = !!(params->pair_rsp.authreq &
+                                BLE_SM_PAIR_AUTHREQ_KEYPRESS);
+    ble_hs_cfg.sm_our_key_dist = params->pair_rsp.resp_key_dist;
+    ble_hs_cfg.sm_their_key_dist = params->pair_rsp.init_key_dist;
+
+    ble_hs_test_util_set_public_addr(params->resp_addr);
+    ble_sm_dbg_set_next_pair_rand(params->random_rsp[0].value);
+
+    ble_sm_dbg_set_sc_keys(params->public_key_rsp.x, params->our_priv_key);
+
+    ble_hs_priv_update_irk(params->id_info_req.irk);
+    if (params->pair_rsp.resp_key_dist & BLE_SM_PAIR_KEY_DIST_SIGN) {
+        ble_sm_dbg_set_next_csrk(params->sign_info_req.sig_key);
+    }
+
+    ble_hs_test_util_create_conn(2, params->init_addr,
+                                 ble_sm_test_util_conn_cb,
+                                 NULL);
+
+    /* This test inspects and modifies the connection object after unlocking
+     * the host mutex.  It is not OK for real code to do this, but this test
+     * can assume the connection list is unchanging.
+     */
+    ble_hs_lock();
+    conn = ble_hs_conn_find(2);
+    TEST_ASSERT_FATAL(conn != NULL);
+    ble_hs_unlock();
+
+    /* Peer is the initiator so we must be the slave. */
+    conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
+
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    if (params->has_sec_req) {
+        rc = ble_sm_slave_initiate(2);
+        TEST_ASSERT(rc == 0);
+
+        /* Ensure we sent the expected security request. */
+        ble_sm_test_util_verify_tx_sec_req(&params->sec_req);
+    }
+
+    /* Receive a pair request from the peer. */
+    ble_sm_test_util_rx_pair_req(2, &params->pair_req, 0);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Ensure we sent the expected pair response. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_pair_rsp(&params->pair_rsp);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Receive a public key from the peer. */
+    ble_sm_test_util_rx_public_key(2, &params->public_key_req);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Ensure we sent the expected public key. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_public_key(&params->public_key_rsp);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    switch (params->pair_alg) {
+    case BLE_SM_PAIR_ALG_PASSKEY:
+        num_iters = 20;
+        break;
+
+    default:
+        num_iters = 1;
+        break;
+    }
+
+    ble_sm_test_util_io_check_pre(&params->passkey_info,
+                                  BLE_SM_PROC_STATE_CONFIRM);
+
+    for (i = 0; i < num_iters; i++) {
+        if (params->pair_alg != BLE_SM_PAIR_ALG_JW      &&
+            params->pair_alg != BLE_SM_PAIR_ALG_NUMCMP) {
+
+            /* Receive a pair confirm from the peer. */
+            ble_sm_test_util_rx_confirm(2, params->confirm_req + i);
+            TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+            TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+            ble_sm_test_util_io_inject_bad(
+                2, params->passkey_info.passkey.action);
+
+            if (i < num_iters - 1) {
+                ble_sm_dbg_set_next_pair_rand(
+                    params->random_rsp[i + 1].value);
+            }
+        }
+
+        if (i == 0) {
+            ble_sm_test_util_io_check_post(&params->passkey_info,
+                                           BLE_SM_PROC_STATE_CONFIRM);
+        }
+
+        /* Ensure we sent the expected pair confirm. */
+        ble_hs_test_util_tx_all();
+        ble_sm_test_util_verify_tx_pair_confirm(params->confirm_rsp + i);
+        TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+        TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+        ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+        /* Receive a pair random from the peer. */
+        ble_sm_test_util_rx_random(2, params->random_req + i, 0);
+        TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+        TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+        ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+        /* Ensure we sent the expected pair random. */
+        ble_hs_test_util_tx_all();
+        ble_sm_test_util_verify_tx_pair_random(params->random_rsp + i);
+        TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+        TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+        ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    }
+
+    ble_sm_test_util_io_check_pre(&params->passkey_info,
+                                  BLE_SM_PROC_STATE_DHKEY_CHECK);
+
+    /* Receive a dhkey check from the peer. */
+    ble_sm_test_util_rx_dhkey_check(2, &params->dhkey_check_req, 0);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    ble_sm_test_util_io_check_post(&params->passkey_info,
+                                   BLE_SM_PROC_STATE_DHKEY_CHECK);
+
+    /* Ensure we sent the expected dhkey check. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_dhkey_check(&params->dhkey_check_rsp);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Receive a long term key request from the controller. */
+    ble_sm_test_util_set_lt_key_req_reply_ack(0, 2);
+    ble_sm_test_util_rx_lt_key_req(2, 0, 0);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Ensure we sent the expected long term key request reply command. */
+    ble_sm_test_util_verify_tx_lt_key_req_reply(2, params->ltk);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Receive an encryption changed event. */
+    ble_sm_test_util_rx_enc_change(2, 0, 1);
+
+    /* Verify key material gets sent to peer. */
+    if (params->pair_rsp.resp_key_dist & BLE_SM_PAIR_KEY_DIST_ID) {
+        ble_sm_test_util_verify_tx_id_info(&params->id_info_req);
+        ble_sm_test_util_verify_tx_id_addr_info(&params->id_addr_info_req);
+    }
+    if (params->pair_rsp.resp_key_dist & BLE_SM_PAIR_KEY_DIST_SIGN) {
+        ble_sm_test_util_verify_tx_sign_info(&params->sign_info_req);
+    }
+
+    /* Receive key material from peer. */
+    if (params->pair_rsp.init_key_dist & BLE_SM_PAIR_KEY_DIST_ID) {
+        ble_sm_test_util_rx_id_info(2, &params->id_info_rsp, 0);
+        ble_sm_test_util_rx_id_addr_info(2, &params->id_addr_info_rsp, 0);
+    }
+    if (params->pair_rsp.init_key_dist & BLE_SM_PAIR_KEY_DIST_SIGN) {
+        ble_sm_test_util_rx_sign_info(2, &params->sign_info_rsp, 0);
+    }
+
+    /* Pairing should now be complete. */
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    /* Verify that security callback was executed. */
+    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
+    TEST_ASSERT(ble_sm_test_gap_status == 0);
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
+                params->authenticated);
+
+    /* Verify that connection has correct security state. */
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted ==
+                conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
+                conn->bhc_sec_state.authenticated);
+
+    /* Verify the appropriate security material was persisted. */
+    ble_sm_test_util_verify_sc_persist(params, 0);
+}
+
+void
+ble_sm_test_util_peer_sc_good(struct ble_sm_test_sc_params *params)
+{
+    params->passkey_info.io_before_rx = 0;
+    ble_sm_test_util_peer_sc_good_once(params);
+
+    params->passkey_info.io_before_rx = 1;
+    ble_sm_test_util_peer_sc_good_once(params);
+
+}
+
+void
+ble_sm_test_util_us_sc_good(struct ble_sm_test_sc_params *params)
+{
+    struct ble_hs_conn *conn;
+    int num_iters;
+    int rc;
+    int i;
+
+    ble_sm_test_util_init();
+
+    ble_hs_cfg.sm_io_cap = params->pair_req.io_cap;
+    ble_hs_cfg.sm_oob_data_flag = params->pair_req.oob_data_flag;
+    ble_hs_cfg.sm_bonding = !!(params->pair_req.authreq &
+                               BLE_SM_PAIR_AUTHREQ_BOND);
+    ble_hs_cfg.sm_mitm = !!(params->pair_req.authreq &
+                            BLE_SM_PAIR_AUTHREQ_MITM);
+    ble_hs_cfg.sm_sc = 1;
+    ble_hs_cfg.sm_keypress = !!(params->pair_req.authreq &
+                                BLE_SM_PAIR_AUTHREQ_KEYPRESS);
+    ble_hs_cfg.sm_our_key_dist = params->pair_req.init_key_dist;
+    ble_hs_cfg.sm_their_key_dist = params->pair_req.resp_key_dist;
+
+    ble_hs_test_util_set_public_addr(params->init_addr);
+    ble_sm_dbg_set_next_pair_rand(params->random_req[0].value);
+
+    ble_sm_dbg_set_sc_keys(params->public_key_req.x, params->our_priv_key);
+
+    ble_hs_priv_update_irk(params->id_info_rsp.irk);
+    if (params->pair_rsp.init_key_dist & BLE_SM_PAIR_KEY_DIST_SIGN) {
+        ble_sm_dbg_set_next_csrk(params->sign_info_rsp.sig_key);
+    }
+
+    ble_hs_test_util_create_conn(2, params->resp_addr,
+                                 ble_sm_test_util_conn_cb,
+                                 NULL);
+
+    /* This test inspects and modifies the connection object after unlocking
+     * the host mutex.  It is not OK for real code to do this, but this test
+     * can assume the connection list is unchanging.
+     */
+    ble_hs_lock();
+    conn = ble_hs_conn_find(2);
+    TEST_ASSERT_FATAL(conn != NULL);
+    ble_hs_unlock();
+
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    ble_hs_test_util_set_ack(
+        host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_START_ENCRYPT), 0);
+    if (params->has_sec_req) {
+        ble_sm_test_util_rx_sec_req(2, &params->sec_req, 0);
+    } else {
+        /* Initiate the pairing procedure. */
+        rc = ble_gap_security_initiate(2);
+        TEST_ASSERT_FATAL(rc == 0);
+    }
+
+    /* Ensure we sent the expected pair request. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_pair_req(&params->pair_req);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Receive a pair response from the peer. */
+    ble_sm_test_util_rx_pair_rsp(2, &params->pair_rsp, 0);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Ensure we sent the expected public key. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_public_key(&params->public_key_req);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Receive a public key from the peer. */
+    ble_sm_test_util_rx_public_key(2, &params->public_key_rsp);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    switch (params->pair_alg) {
+    case BLE_SM_PAIR_ALG_PASSKEY:
+        num_iters = 20;
+        break;
+
+    default:
+        num_iters = 1;
+        break;
+    }
+
+    ble_sm_test_util_io_inject(&params->passkey_info,
+                               BLE_SM_PROC_STATE_CONFIRM);
+
+    for (i = 0; i < num_iters; i++) {
+        if (params->pair_alg != BLE_SM_PAIR_ALG_JW      &&
+            params->pair_alg != BLE_SM_PAIR_ALG_NUMCMP) {
+
+            if (i < num_iters - 1) {
+                ble_sm_dbg_set_next_pair_rand(
+                    params->random_req[i + 1].value);
+            }
+
+            /* Ensure we sent the expected pair confirm. */
+            ble_hs_test_util_tx_all();
+            ble_sm_test_util_verify_tx_pair_confirm(params->confirm_req + i);
+            TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+            TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+            ble_sm_test_util_io_inject_bad(
+                2, params->passkey_info.passkey.action);
+        }
+
+        /* Receive a pair confirm from the peer. */
+        ble_sm_test_util_rx_confirm(2, params->confirm_rsp + i);
+        TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+        TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+        ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+        /* Ensure we sent the expected pair random. */
+        ble_hs_test_util_tx_all();
+        ble_sm_test_util_verify_tx_pair_random(params->random_req + i);
+        TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+        TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+        ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+        /* Receive a pair random from the peer. */
+        ble_sm_test_util_rx_random(2, params->random_rsp + i, 0);
+        TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+        TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+        ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+    }
+
+    ble_sm_test_util_io_inject(&params->passkey_info,
+                               BLE_SM_PROC_STATE_DHKEY_CHECK);
+
+    /* Ensure we sent the expected dhkey check. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_dhkey_check(&params->dhkey_check_req);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Receive a dhkey check from the peer. */
+    ble_sm_test_util_rx_dhkey_check(2, &params->dhkey_check_rsp, 0);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Ensure we sent the expected start encryption command. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_start_enc(2, 0, 0, params->ltk);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Receive an encryption changed event. */
+    ble_sm_test_util_rx_enc_change(2, 0, 1);
+
+    /* Receive key material from peer. */
+    if (params->pair_rsp.resp_key_dist & BLE_SM_PAIR_KEY_DIST_ID) {
+        ble_sm_test_util_rx_id_info(2, &params->id_info_req, 0);
+        ble_sm_test_util_rx_id_addr_info(2, &params->id_addr_info_req, 0);
+    }
+    if (params->pair_rsp.resp_key_dist & BLE_SM_PAIR_KEY_DIST_SIGN) {
+        ble_sm_test_util_rx_sign_info(2, &params->sign_info_req, 0);
+    }
+
+    /* Verify key material gets sent to peer. */
+    if (params->pair_rsp.init_key_dist & BLE_SM_PAIR_KEY_DIST_ID) {
+        ble_sm_test_util_verify_tx_id_info(&params->id_info_rsp);
+        ble_sm_test_util_verify_tx_id_addr_info(&params->id_addr_info_rsp);
+    }
+    if (params->pair_rsp.init_key_dist & BLE_SM_PAIR_KEY_DIST_SIGN) {
+        ble_sm_test_util_verify_tx_sign_info(&params->sign_info_rsp);
+    }
+
+    /* Pairing should now be complete. */
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    /* Verify that security callback was executed. */
+    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
+    TEST_ASSERT(ble_sm_test_gap_status == 0);
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
+                params->authenticated);
+
+    /* Verify that connection has correct security state. */
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted ==
+                conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
+                conn->bhc_sec_state.authenticated);
+
+    /* Verify the appropriate security material was persisted. */
+    ble_sm_test_util_verify_sc_persist(params, 1);
+}
+
+void
+ble_sm_test_util_us_fail_inval(
+    struct ble_sm_test_lgcy_params *params)
+{
+    struct ble_hs_conn *conn;
+    int rc;
+
+    ble_sm_test_util_init();
+    ble_hs_test_util_set_public_addr(params->resp_addr);
+
+    ble_sm_dbg_set_next_pair_rand(((uint8_t[16]){0}));
+
+    ble_hs_test_util_create_conn(2, params->init_addr,
+                                 ble_sm_test_util_conn_cb,
+                                 NULL);
+
+    /* This test inspects and modifies the connection object after unlocking
+     * the host mutex.  It is not OK for real code to do this, but this test
+     * can assume the connection list is unchanging.
+     */
+    ble_hs_lock();
+    conn = ble_hs_conn_find(2);
+    TEST_ASSERT_FATAL(conn != NULL);
+    ble_hs_unlock();
+
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    /* Initiate the pairing procedure. */
+    rc = ble_hs_test_util_security_initiate(2, 0);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    /* Ensure we sent the expected pair request. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_pair_req(&params->pair_req);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
+
+    /* Receive a pair response from the peer. */
+    ble_sm_test_util_rx_pair_rsp(
+        2, &params->pair_rsp, BLE_HS_SM_US_ERR(BLE_SM_ERR_INVAL));
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    /* Ensure we sent the expected pair fail. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_pair_fail(&params->pair_fail);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    /* Verify that security callback was not executed. */
+    TEST_ASSERT(ble_sm_test_gap_event == -1);
+    TEST_ASSERT(ble_sm_test_gap_status == -1);
+
+    /* Verify that connection has correct security state. */
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(!conn->bhc_sec_state.authenticated);
+}
+
+/**
+ * @param send_enc_req          Whether this procedure is initiated by a slave
+ *                                  security request;
+ *                                  1: Peer sends a security request at start.
+ *                                  0: No security request; we initiate.
+ */
+void
+ble_sm_test_util_us_bonding_good(int send_enc_req, uint8_t *ltk,
+                                 int authenticated, uint16_t ediv,
+                                 uint64_t rand_num)
+{
+    struct ble_sm_sec_req sec_req;
+    struct ble_store_value_sec value_sec;
+    struct ble_hs_conn *conn;
+    int rc;
+
+    ble_sm_test_util_init();
+
+    ble_hs_test_util_create_conn(2, ((uint8_t[6]){1,2,3,4,5,6}),
+                                 ble_sm_test_util_conn_cb,
+                                 NULL);
+
+    /* This test inspects and modifies the connection object after unlocking
+     * the host mutex.  It is not OK for real code to do this, but this test
+     * can assume the connection list is unchanging.
+     */
+    ble_hs_lock();
+    conn = ble_hs_conn_find(2);
+    TEST_ASSERT_FATAL(conn != NULL);
+    ble_hs_unlock();
+
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    /* Populate the SM database with an LTK for this peer. */
+    value_sec.peer_addr_type = conn->bhc_addr_type;
+    memcpy(value_sec.peer_addr, conn->bhc_addr, sizeof value_sec.peer_addr);
+    value_sec.ediv = ediv;
+    value_sec.rand_num = rand_num;
+    memcpy(value_sec.ltk, ltk, sizeof value_sec.ltk);
+    value_sec.ltk_present = 1;
+    value_sec.authenticated = authenticated;
+    value_sec.sc = 0;
+
+    rc = ble_store_write_mst_sec(&value_sec);
+    TEST_ASSERT_FATAL(rc == 0);
+
+    if (send_enc_req) {
+        sec_req.authreq = 0;
+        sec_req.authreq |= BLE_SM_PAIR_AUTHREQ_BOND;
+        if (authenticated) {
+            sec_req.authreq |= BLE_SM_PAIR_AUTHREQ_MITM;
+        }
+        ble_hs_test_util_set_ack(
+            host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_START_ENCRYPT),
+            0);
+        ble_sm_test_util_rx_sec_req(2, &sec_req, 0);
+    }
+
+    /* Ensure we sent the expected start encryption command. */
+    ble_hs_test_util_tx_all();
+    ble_sm_test_util_verify_tx_start_enc(2, rand_num, ediv, ltk);
+    TEST_ASSERT(!conn->bhc_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+    ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
+
+    /* Receive an encryption changed event. */
+    ble_sm_test_util_rx_enc_change(2, 0, 1);
+
+    /* Pairing should now be complete. */
+    TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+
+    /* Verify that security callback was executed. */
+    TEST_ASSERT(ble_sm_test_gap_event == BLE_GAP_EVENT_ENC_CHANGE);
+    TEST_ASSERT(ble_sm_test_gap_status == 0);
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
+                authenticated);
+
+    /* Verify that connection has correct security state. */
+    TEST_ASSERT(ble_sm_test_sec_state.encrypted);
+    TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
+                authenticated);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4f9739f7/net/nimble/host/src/test/ble_sm_test_util.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_test_util.h b/net/nimble/host/src/test/ble_sm_test_util.h
new file mode 100644
index 0000000..e71aba1
--- /dev/null
+++ b/net/nimble/host/src/test/ble_sm_test_util.h
@@ -0,0 +1,145 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * 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,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef H_BLE_SM_TEST_UTIL_
+#define H_BLE_SM_TEST_UTIL_
+
+struct ble_sm_test_passkey_info {
+    struct ble_sm_io passkey;
+    uint32_t exp_numcmp;
+    unsigned io_before_rx:1;
+};
+
+struct ble_sm_test_lgcy_params {
+    uint8_t init_addr[6];
+    uint8_t resp_addr[6];
+    struct ble_sm_sec_req sec_req;
+    struct ble_sm_pair_cmd pair_req;
+    struct ble_sm_pair_cmd pair_rsp;
+    struct ble_sm_pair_confirm confirm_req;
+    struct ble_sm_pair_confirm confirm_rsp;
+    struct ble_sm_pair_random random_req;
+    struct ble_sm_pair_random random_rsp;
+    struct ble_sm_enc_info enc_info_req;
+    struct ble_sm_master_id master_id_req;
+    struct ble_sm_enc_info enc_info_rsp;
+    struct ble_sm_master_id master_id_rsp;
+    int pair_alg;
+    unsigned authenticated:1;
+    uint8_t tk[16];
+    uint8_t stk[16];
+    uint64_t r;
+    uint16_t ediv;
+
+    struct ble_sm_test_passkey_info passkey_info;
+    struct ble_sm_pair_fail pair_fail;
+
+    unsigned has_sec_req:1;
+    unsigned has_enc_info_req:1;
+    unsigned has_enc_info_rsp:1;
+    unsigned has_master_id_req:1;
+    unsigned has_master_id_rsp:1;
+};
+
+struct ble_sm_test_sc_params {
+    uint8_t init_addr[6];
+    uint8_t resp_addr[6];
+    struct ble_sm_sec_req sec_req;
+    struct ble_sm_pair_cmd pair_req;
+    struct ble_sm_pair_cmd pair_rsp;
+    struct ble_sm_pair_confirm confirm_req[20];
+    struct ble_sm_pair_confirm confirm_rsp[20];
+    struct ble_sm_pair_random random_req[20];
+    struct ble_sm_pair_random random_rsp[20];
+    struct ble_sm_public_key public_key_req;
+    struct ble_sm_public_key public_key_rsp;
+    struct ble_sm_dhkey_check dhkey_check_req;
+    struct ble_sm_dhkey_check dhkey_check_rsp;
+    struct ble_sm_id_info id_info_req;
+    struct ble_sm_id_info id_info_rsp;
+    struct ble_sm_id_addr_info id_addr_info_req;
+    struct ble_sm_id_addr_info id_addr_info_rsp;
+    struct ble_sm_sign_info sign_info_req;
+    struct ble_sm_sign_info sign_info_rsp;
+    int pair_alg;
+    unsigned authenticated:1;
+    uint8_t ltk[16];
+    uint8_t our_priv_key[32];
+
+    struct ble_sm_test_passkey_info passkey_info;
+    struct ble_sm_pair_fail pair_fail;
+
+    unsigned has_sec_req:1;
+};
+
+extern int ble_sm_test_gap_event;
+extern int ble_sm_test_gap_status;
+extern struct ble_gap_sec_state ble_sm_test_sec_state;
+
+extern int ble_sm_test_store_obj_type;
+extern union ble_store_key ble_sm_test_store_key;
+extern union ble_store_value ble_sm_test_store_value;
+
+void ble_sm_test_util_init(void);
+int ble_sm_test_util_conn_cb(int event, struct ble_gap_conn_ctxt *ctxt,
+                             void *arg);
+void ble_sm_test_util_io_inject(struct ble_sm_test_passkey_info *passkey_info,
+                                uint8_t cur_sm_state);
+void ble_sm_test_util_io_inject_bad(uint16_t conn_handle,
+                                    uint8_t correct_io_act);
+void ble_sm_test_util_io_check_pre(
+    struct ble_sm_test_passkey_info *passkey_info,
+    uint8_t cur_sm_state);
+void ble_sm_test_util_io_check_post(
+    struct ble_sm_test_passkey_info *passkey_info,
+    uint8_t cur_sm_state);
+void ble_sm_test_util_rx_sec_req(uint16_t conn_handle,
+                                 struct ble_sm_sec_req *cmd,
+                                 int exp_status);
+void ble_sm_test_util_verify_tx_pair_fail(struct ble_sm_pair_fail *exp_cmd);
+void ble_sm_test_util_us_lgcy_good(struct ble_sm_test_lgcy_params *params);
+void ble_sm_test_util_peer_fail_inval(int we_are_master,
+                                      uint8_t *init_addr,
+                                      uint8_t *resp_addr,
+                                      struct ble_sm_pair_cmd *pair_req,
+                                      struct ble_sm_pair_fail *pair_fail);
+void ble_sm_test_util_peer_lgcy_fail_confirm(
+    uint8_t *init_addr,
+    uint8_t *resp_addr,
+    struct ble_sm_pair_cmd *pair_req,
+    struct ble_sm_pair_cmd *pair_rsp,
+    struct ble_sm_pair_confirm *confirm_req,
+    struct ble_sm_pair_confirm *confirm_rsp,
+    struct ble_sm_pair_random *random_req,
+    struct ble_sm_pair_random *random_rsp,
+    struct ble_sm_pair_fail *fail_rsp);
+
+void ble_sm_test_util_peer_lgcy_good(struct ble_sm_test_lgcy_params *params);
+void ble_sm_test_util_peer_bonding_good(int send_enc_req, uint8_t *ltk,
+                                        int authenticated,
+                                        uint16_t ediv, uint64_t rand_num);
+void ble_sm_test_util_peer_bonding_bad(uint16_t ediv, uint64_t rand_num);
+void ble_sm_test_util_peer_sc_good(struct ble_sm_test_sc_params *params);
+void ble_sm_test_util_us_sc_good(struct ble_sm_test_sc_params *params);
+void ble_sm_test_util_us_fail_inval(struct ble_sm_test_lgcy_params *params);
+void ble_sm_test_util_us_bonding_good(int send_enc_req, uint8_t *ltk,
+                                      int authenticated, uint16_t ediv,
+                                      uint64_t rand_num);
+
+#endif


[43/50] [abbrv] incubator-mynewt-core git commit: BLE Host - More SM SC unit tests.

Posted by cc...@apache.org.
BLE Host - More SM SC unit tests.


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

Branch: refs/heads/develop
Commit: ad243cff72d4809faf22753bded194314dcc996a
Parents: d47d308
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 14 11:27:38 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:24:21 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/test/ble_sm_sc_test.c | 1357 ++++++++++++++++++++++++
 1 file changed, 1357 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ad243cff/net/nimble/host/src/test/ble_sm_sc_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_sc_test.c b/net/nimble/host/src/test/ble_sm_sc_test.c
index 36597ce..7d8cd77 100644
--- a/net/nimble/host/src/test/ble_sm_sc_test.c
+++ b/net/nimble/host/src/test/ble_sm_sc_test.c
@@ -1669,6 +1669,1360 @@ TEST_CASE(ble_sm_sc_us_jw_iio3_rio4_b1_iat0_rat0_ik7_rk5)
     ble_sm_test_util_us_sc_good(&params);
 }
 
+/**
+ * Secure connections pairing
+ * Master: us
+ * Pair algorithm: passkey entry
+ * Initiator IO capabilities: 2
+ * Responder IO capabilities: 4
+ * Bonding: true
+ * Initiator address type: 0
+ * Responder address type: 0
+ * Initiator key distribution: 7
+ * Responder key distribution: 5
+ */
+TEST_CASE(ble_sm_sc_us_pk_iio2_rio4_b1_iat0_rat0_ik7_rk5)
+{
+    struct ble_sm_test_sc_params params;
+
+    params = (struct ble_sm_test_sc_params) {
+        .init_addr = {
+            0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
+        },
+        .resp_addr = {
+            0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
+        },
+        .pair_req = {
+            .io_cap = 0x02,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x07,
+            .resp_key_dist = 0x07,
+        },
+        .pair_rsp = {
+            .io_cap = 0x04,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x07,
+            .resp_key_dist = 0x05,
+        },
+        .our_priv_key = {
+            0xb1, 0x6b, 0x4f, 0x81, 0xbc, 0xe3, 0x60, 0x9e,
+            0x00, 0x20, 0xf1, 0x73, 0x3e, 0xfb, 0xcc, 0x6e,
+            0x8c, 0xb6, 0xd2, 0x51, 0xd9, 0x36, 0x8a, 0x6d,
+            0xca, 0x8c, 0xd7, 0xbe, 0x96, 0x03, 0xdf, 0xd6,
+        },
+        .public_key_req = {
+            .x = {
+                0xe5, 0x0f, 0x02, 0x0a, 0x37, 0x90, 0x94, 0x5a,
+                0x06, 0x21, 0xf7, 0xbc, 0xd5, 0xbe, 0xb9, 0x24,
+                0x8a, 0x35, 0xfd, 0xf8, 0x5e, 0xe2, 0x70, 0xd5,
+                0x5a, 0xe8, 0xe7, 0xdd, 0x13, 0x90, 0xeb, 0xd4,
+            },
+            .y = {
+                0x41, 0xc8, 0x51, 0x1a, 0x25, 0x44, 0x01, 0x53,
+                0x42, 0x74, 0x07, 0x9c, 0x18, 0xe6, 0x3b, 0x8a,
+                0xce, 0x7a, 0x37, 0x1f, 0x18, 0x5c, 0x02, 0x7c,
+                0x67, 0x16, 0xf5, 0x30, 0x2b, 0x31, 0xa9, 0xc7,
+            },
+        },
+        .public_key_rsp = {
+            .x = {
+                0x1b, 0xd2, 0x03, 0x79, 0xb4, 0x9b, 0x0a, 0xd7,
+                0x1b, 0x28, 0x73, 0x2a, 0xd7, 0xe6, 0xa0, 0xd4,
+                0x2d, 0x95, 0x8d, 0x29, 0xaf, 0x6a, 0xab, 0xee,
+                0xa0, 0x0d, 0x13, 0x4d, 0xe7, 0x16, 0x76, 0x91,
+            },
+            .y = {
+                0x2a, 0x26, 0x2c, 0x50, 0x55, 0xd1, 0x2b, 0x83,
+                0xf6, 0x5f, 0xdb, 0x99, 0x5f, 0x85, 0xf6, 0x78,
+                0x1c, 0x14, 0xed, 0xd3, 0x70, 0x5e, 0xe5, 0x2c,
+                0x05, 0x1e, 0x5c, 0xec, 0xf8, 0x65, 0x43, 0x49,
+            },
+        },
+        .confirm_req[0] = {
+            .value = {
+                0x55, 0x2c, 0xaa, 0x41, 0x59, 0x42, 0x4d, 0xfe,
+                0x47, 0x74, 0xcd, 0x2b, 0x11, 0xab, 0x21, 0xe6,
+            },
+        },
+        .confirm_rsp[0] = {
+            .value = {
+                0x6a, 0x3c, 0x45, 0xf5, 0xb2, 0xe2, 0x04, 0x30,
+                0xde, 0xd6, 0x3c, 0x6d, 0x85, 0x00, 0x00, 0x2c,
+            },
+        },
+        .random_req[0] = {
+            .value = {
+                0x78, 0x06, 0x04, 0x60, 0x76, 0xe9, 0xc4, 0x5a,
+                0xfb, 0x34, 0x44, 0xae, 0x45, 0xa0, 0x84, 0xde,
+            },
+        },
+        .random_rsp[0] = {
+            .value = {
+                0x91, 0xc8, 0xfd, 0x1b, 0xb2, 0x85, 0x08, 0x76,
+                0xd3, 0xf1, 0xc4, 0xa0, 0xfa, 0x92, 0x8c, 0x94,
+            },
+        },
+        .confirm_req[1] = {
+            .value = {
+                0xb1, 0x2f, 0x68, 0x35, 0xa1, 0xa5, 0x84, 0xb1,
+                0x4f, 0x1a, 0xb1, 0xb5, 0xf0, 0xb2, 0xbe, 0x61,
+            },
+        },
+        .confirm_rsp[1] = {
+            .value = {
+                0x07, 0xd8, 0x43, 0x74, 0xe8, 0x42, 0xf3, 0xf1,
+                0x87, 0x3d, 0x9e, 0x92, 0xea, 0x33, 0xe8, 0x54,
+            },
+        },
+        .random_req[1] = {
+            .value = {
+                0x4c, 0xb7, 0xcc, 0x6d, 0x90, 0x9f, 0x1e, 0x2d,
+                0x9d, 0x1e, 0x52, 0xa7, 0xe0, 0x0c, 0x7b, 0xf7,
+            },
+        },
+        .random_rsp[1] = {
+            .value = {
+                0x5c, 0x32, 0x82, 0xc8, 0x76, 0x17, 0x3b, 0x18,
+                0x66, 0xda, 0xbf, 0xc3, 0x13, 0x49, 0x05, 0xfb,
+            },
+        },
+        .confirm_req[2] = {
+            .value = {
+                0x27, 0x61, 0x4d, 0x04, 0x64, 0xa9, 0x58, 0xf1,
+                0xe0, 0xf9, 0xe5, 0x78, 0x0b, 0x54, 0x89, 0x0a,
+            },
+        },
+        .confirm_rsp[2] = {
+            .value = {
+                0xe4, 0x8f, 0xdb, 0xc8, 0x35, 0xed, 0x4e, 0x7d,
+                0xbc, 0x92, 0x7f, 0x58, 0x02, 0xaa, 0xbf, 0x6b,
+            },
+        },
+        .random_req[2] = {
+            .value = {
+                0xfe, 0x85, 0x08, 0xe0, 0x35, 0x90, 0x13, 0xa9,
+                0xd3, 0xcf, 0xb6, 0x6d, 0x36, 0xaf, 0xbd, 0x59,
+            },
+        },
+        .random_rsp[2] = {
+            .value = {
+                0x47, 0x40, 0x8e, 0x97, 0xe3, 0xfe, 0x8f, 0x52,
+                0x29, 0x5e, 0x6b, 0x44, 0xdf, 0x0d, 0x60, 0xf4,
+            },
+        },
+        .confirm_req[3] = {
+            .value = {
+                0xac, 0xab, 0x13, 0x7c, 0x1a, 0x6e, 0x7a, 0xdb,
+                0xf6, 0xe8, 0x72, 0x9f, 0xc5, 0xc3, 0x99, 0x1b,
+            },
+        },
+        .confirm_rsp[3] = {
+            .value = {
+                0x79, 0xf2, 0xd1, 0x89, 0x5e, 0xa5, 0xa2, 0x90,
+                0xee, 0x25, 0x36, 0x81, 0x5a, 0x87, 0x20, 0x82,
+            },
+        },
+        .random_req[3] = {
+            .value = {
+                0xd4, 0x46, 0xa0, 0xc4, 0x3d, 0xae, 0x22, 0x06,
+                0xaf, 0x5d, 0x93, 0x96, 0xb7, 0x06, 0xc3, 0x61,
+            },
+        },
+        .random_rsp[3] = {
+            .value = {
+                0x5f, 0x81, 0x97, 0x8b, 0x52, 0x87, 0x1c, 0x67,
+                0xe0, 0x04, 0xcc, 0x50, 0xd9, 0x2b, 0x16, 0xb5,
+            },
+        },
+        .confirm_req[4] = {
+            .value = {
+                0x6c, 0x51, 0xc3, 0x61, 0x77, 0x7f, 0xf1, 0x05,
+                0x9e, 0x0f, 0xba, 0xfd, 0x32, 0x02, 0x09, 0x45,
+            },
+        },
+        .confirm_rsp[4] = {
+            .value = {
+                0x54, 0xe5, 0x24, 0x81, 0x62, 0x68, 0xe2, 0x45,
+                0x86, 0x2c, 0x11, 0x28, 0x15, 0xa8, 0x8e, 0x5b,
+            },
+        },
+        .random_req[4] = {
+            .value = {
+                0xbb, 0x29, 0x3a, 0xba, 0xe6, 0x4f, 0x06, 0xcf,
+                0xa3, 0x13, 0x27, 0xf2, 0xcb, 0xe4, 0xd2, 0xe6,
+            },
+        },
+        .random_rsp[4] = {
+            .value = {
+                0x50, 0xba, 0xd0, 0x0e, 0x26, 0xab, 0x04, 0xf8,
+                0xa2, 0x03, 0x1e, 0x63, 0x9a, 0xf7, 0x15, 0xdc,
+            },
+        },
+        .confirm_req[5] = {
+            .value = {
+                0x12, 0x3e, 0xfe, 0x5a, 0xb1, 0x09, 0x6f, 0x17,
+                0xb7, 0x77, 0x7e, 0x65, 0x88, 0xd4, 0x95, 0x56,
+            },
+        },
+        .confirm_rsp[5] = {
+            .value = {
+                0xc6, 0x9b, 0xac, 0xde, 0x7e, 0x03, 0x7a, 0xd3,
+                0xf1, 0xff, 0x3c, 0x4f, 0x4a, 0x85, 0xba, 0x73,
+            },
+        },
+        .random_req[5] = {
+            .value = {
+                0x17, 0xd5, 0x5e, 0x69, 0x30, 0x2c, 0x1f, 0x01,
+                0x87, 0x9c, 0xd6, 0xd2, 0xe4, 0x48, 0x8c, 0x84,
+            },
+        },
+        .random_rsp[5] = {
+            .value = {
+                0x9d, 0x54, 0x83, 0x4a, 0xcd, 0x93, 0x7c, 0x1e,
+                0x5b, 0xaf, 0xd2, 0x66, 0x8c, 0x2d, 0xaa, 0xc3,
+            },
+        },
+        .confirm_req[6] = {
+            .value = {
+                0xdc, 0x24, 0x69, 0xa8, 0xd3, 0xa9, 0x17, 0x11,
+                0x08, 0x37, 0x1a, 0x1e, 0x92, 0x03, 0xee, 0x36,
+            },
+        },
+        .confirm_rsp[6] = {
+            .value = {
+                0x98, 0xf8, 0x72, 0x71, 0x99, 0xa0, 0xbd, 0xcd,
+                0xb1, 0x97, 0x4c, 0x8a, 0xb8, 0xa8, 0x1a, 0x52,
+            },
+        },
+        .random_req[6] = {
+            .value = {
+                0xbf, 0xb1, 0x8e, 0xa5, 0x14, 0xe3, 0xeb, 0x9e,
+                0x29, 0x27, 0xe0, 0x19, 0xb1, 0xb2, 0x5c, 0xfe,
+            },
+        },
+        .random_rsp[6] = {
+            .value = {
+                0xae, 0x8a, 0x92, 0x78, 0x53, 0x7b, 0xdb, 0x8c,
+                0xec, 0x3a, 0x99, 0x2b, 0x94, 0xf1, 0x17, 0xfe,
+            },
+        },
+        .confirm_req[7] = {
+            .value = {
+                0xcf, 0xaf, 0x70, 0x73, 0x53, 0x65, 0x89, 0x57,
+                0x36, 0x98, 0xd2, 0x28, 0x86, 0x79, 0xfe, 0x85,
+            },
+        },
+        .confirm_rsp[7] = {
+            .value = {
+                0x0d, 0x2d, 0x77, 0x8a, 0x21, 0x11, 0xd9, 0x61,
+                0x9f, 0x80, 0x32, 0x8a, 0x32, 0x09, 0x42, 0x42,
+            },
+        },
+        .random_req[7] = {
+            .value = {
+                0x8b, 0xd2, 0x53, 0xcd, 0x96, 0xd1, 0x14, 0xb5,
+                0xea, 0x17, 0xb1, 0xa3, 0xa8, 0xfc, 0x3c, 0x2b,
+            },
+        },
+        .random_rsp[7] = {
+            .value = {
+                0xc2, 0x4f, 0x84, 0x60, 0x54, 0x79, 0x16, 0xed,
+                0x1a, 0x6e, 0x78, 0xa0, 0x99, 0x58, 0xf2, 0x94,
+            },
+        },
+        .confirm_req[8] = {
+            .value = {
+                0x9a, 0x4c, 0xbc, 0x9c, 0x55, 0x15, 0xa2, 0x4f,
+                0xa2, 0x5d, 0x3b, 0xa7, 0x43, 0xb3, 0x9c, 0x63,
+            },
+        },
+        .confirm_rsp[8] = {
+            .value = {
+                0xa3, 0xb1, 0x88, 0xa5, 0x70, 0xca, 0xa3, 0xa9,
+                0x67, 0x2a, 0xac, 0x99, 0x5e, 0x61, 0x68, 0xa0,
+            },
+        },
+        .random_req[8] = {
+            .value = {
+                0xcf, 0xcf, 0x5b, 0x94, 0xe0, 0xb2, 0x9d, 0x5a,
+                0x86, 0x71, 0x45, 0xce, 0xd9, 0xce, 0x13, 0xba,
+            },
+        },
+        .random_rsp[8] = {
+            .value = {
+                0x10, 0x96, 0x8a, 0x50, 0xa4, 0xd0, 0xaa, 0x5f,
+                0xd6, 0x32, 0xdb, 0x09, 0x7e, 0x22, 0x96, 0x42,
+            },
+        },
+        .confirm_req[9] = {
+            .value = {
+                0xf0, 0x90, 0x61, 0x25, 0x04, 0x29, 0x4f, 0xb6,
+                0x8b, 0xd5, 0x73, 0x49, 0xbd, 0xf7, 0x9b, 0xe7,
+            },
+        },
+        .confirm_rsp[9] = {
+            .value = {
+                0x5b, 0xe6, 0xb4, 0x3f, 0x1b, 0x77, 0x12, 0x75,
+                0x84, 0x94, 0xc6, 0x07, 0xfa, 0xa1, 0x41, 0x94,
+            },
+        },
+        .random_req[9] = {
+            .value = {
+                0x3d, 0x1a, 0xa3, 0x95, 0xec, 0x72, 0x84, 0xf4,
+                0xc5, 0xcd, 0xaa, 0x48, 0xe9, 0x0c, 0x0f, 0xe3,
+            },
+        },
+        .random_rsp[9] = {
+            .value = {
+                0x8a, 0x5a, 0x53, 0xfc, 0x07, 0x52, 0x01, 0xb9,
+                0xe9, 0x2d, 0xe7, 0x9d, 0x8c, 0x7c, 0xc7, 0xb3,
+            },
+        },
+        .confirm_req[10] = {
+            .value = {
+                0xe7, 0x8e, 0xc5, 0x08, 0x7f, 0x7e, 0xb8, 0xdc,
+                0x05, 0x88, 0x3a, 0x92, 0x5a, 0xf5, 0x9b, 0xa9,
+            },
+        },
+        .confirm_rsp[10] = {
+            .value = {
+                0xf7, 0xa2, 0xb6, 0xec, 0xcd, 0xef, 0xcb, 0xb7,
+                0x6f, 0xc3, 0xac, 0x17, 0xe2, 0xfd, 0xfa, 0x42,
+            },
+        },
+        .random_req[10] = {
+            .value = {
+                0x0d, 0xd1, 0xa2, 0x1d, 0xff, 0x74, 0xc5, 0x99,
+                0xe0, 0x67, 0x07, 0x99, 0x95, 0x75, 0x39, 0x76,
+            },
+        },
+        .random_rsp[10] = {
+            .value = {
+                0x2f, 0x13, 0xd1, 0x59, 0xfe, 0x20, 0x60, 0xf0,
+                0x02, 0x0c, 0xea, 0x79, 0xd7, 0x40, 0x86, 0x85,
+            },
+        },
+        .confirm_req[11] = {
+            .value = {
+                0x8b, 0x57, 0x87, 0xdd, 0xb1, 0xcc, 0x2d, 0x65,
+                0xc1, 0xba, 0xac, 0x88, 0x48, 0x23, 0xda, 0xe7,
+            },
+        },
+        .confirm_rsp[11] = {
+            .value = {
+                0xb3, 0xc4, 0x2e, 0xea, 0x33, 0xaf, 0x12, 0x9c,
+                0xb5, 0xab, 0xa1, 0x95, 0x30, 0xca, 0x46, 0x48,
+            },
+        },
+        .random_req[11] = {
+            .value = {
+                0x35, 0x57, 0xcd, 0xd5, 0xd2, 0xf8, 0xd7, 0xf2,
+                0x7b, 0xe3, 0xd7, 0xba, 0x31, 0xa5, 0xca, 0xfd,
+            },
+        },
+        .random_rsp[11] = {
+            .value = {
+                0xe2, 0x3b, 0x20, 0xbe, 0xec, 0xa5, 0x34, 0x3b,
+                0x76, 0x23, 0x53, 0x28, 0x36, 0xc4, 0x60, 0x13,
+            },
+        },
+        .confirm_req[12] = {
+            .value = {
+                0xc9, 0xfe, 0x03, 0x49, 0xe4, 0xff, 0x7e, 0xf7,
+                0x00, 0xd1, 0x2b, 0x13, 0xb1, 0x15, 0x6e, 0x92,
+            },
+        },
+        .confirm_rsp[12] = {
+            .value = {
+                0xbc, 0xa2, 0xf2, 0x03, 0x5c, 0xfd, 0x20, 0x7b,
+                0xd0, 0x1f, 0xd6, 0x50, 0xec, 0xc6, 0x7b, 0x31,
+            },
+        },
+        .random_req[12] = {
+            .value = {
+                0x04, 0x50, 0xea, 0xb8, 0xca, 0x36, 0x1a, 0x61,
+                0x92, 0xed, 0xa0, 0x67, 0x78, 0x15, 0x10, 0xb5,
+            },
+        },
+        .random_rsp[12] = {
+            .value = {
+                0x0c, 0x8e, 0x9d, 0x7b, 0x9d, 0x7e, 0xda, 0x23,
+                0xbb, 0x61, 0xd9, 0xff, 0x46, 0x77, 0x33, 0x1b,
+            },
+        },
+        .confirm_req[13] = {
+            .value = {
+                0x9a, 0xff, 0xd6, 0xe5, 0x1a, 0xc3, 0xd3, 0x37,
+                0x34, 0xeb, 0x3e, 0x3a, 0x8e, 0x0b, 0x86, 0xb4,
+            },
+        },
+        .confirm_rsp[13] = {
+            .value = {
+                0xf6, 0x32, 0x19, 0xb4, 0x08, 0x6b, 0x8a, 0x0f,
+                0xc9, 0x9c, 0x1b, 0x68, 0xb8, 0xa0, 0xd0, 0xc9,
+            },
+        },
+        .random_req[13] = {
+            .value = {
+                0x86, 0xeb, 0x5c, 0xf9, 0x33, 0x54, 0x7d, 0xe4,
+                0xa4, 0xe2, 0xe1, 0xf6, 0x6b, 0xea, 0x34, 0xed,
+            },
+        },
+        .random_rsp[13] = {
+            .value = {
+                0xad, 0x53, 0xa0, 0x6e, 0xde, 0x1d, 0xda, 0x99,
+                0x31, 0x45, 0xe5, 0x3a, 0x73, 0xa1, 0x5e, 0xe1,
+            },
+        },
+        .confirm_req[14] = {
+            .value = {
+                0x93, 0xd4, 0xe0, 0xaa, 0x0c, 0x91, 0xba, 0xde,
+                0xc9, 0x5c, 0x68, 0xb0, 0xce, 0xb6, 0x84, 0xcd,
+            },
+        },
+        .confirm_rsp[14] = {
+            .value = {
+                0x85, 0xc7, 0x05, 0x02, 0x21, 0x9d, 0x4c, 0x4c,
+                0x16, 0xf7, 0x8f, 0x7b, 0xaa, 0xb4, 0x8f, 0x37,
+            },
+        },
+        .random_req[14] = {
+            .value = {
+                0x84, 0xfd, 0xf1, 0x39, 0x1a, 0x9a, 0xa5, 0xb8,
+                0x49, 0xc0, 0x66, 0xdc, 0x33, 0x71, 0x32, 0x87,
+            },
+        },
+        .random_rsp[14] = {
+            .value = {
+                0x5d, 0xaf, 0x38, 0xcd, 0xb5, 0x83, 0xaa, 0xa0,
+                0xab, 0x30, 0x82, 0xed, 0x6f, 0xd2, 0x75, 0xe7,
+            },
+        },
+        .confirm_req[15] = {
+            .value = {
+                0x88, 0x12, 0xe8, 0x89, 0xd4, 0x52, 0x6d, 0xac,
+                0x61, 0x2a, 0x85, 0x85, 0x1e, 0x9c, 0x82, 0x21,
+            },
+        },
+        .confirm_rsp[15] = {
+            .value = {
+                0xc1, 0xe9, 0xcd, 0x21, 0x29, 0x6a, 0x78, 0xe4,
+                0x7b, 0x7d, 0x73, 0x25, 0x9e, 0x9b, 0x95, 0x8b,
+            },
+        },
+        .random_req[15] = {
+            .value = {
+                0x95, 0x87, 0x9d, 0x5a, 0x10, 0x14, 0xa0, 0xdf,
+                0x5e, 0x02, 0x22, 0x39, 0x23, 0xc9, 0xbc, 0xba,
+            },
+        },
+        .random_rsp[15] = {
+            .value = {
+                0x1b, 0x91, 0xe2, 0xdf, 0xca, 0xfe, 0x2b, 0x61,
+                0x33, 0x8c, 0x83, 0xbf, 0xcf, 0xc3, 0x72, 0xcc,
+            },
+        },
+        .confirm_req[16] = {
+            .value = {
+                0xce, 0xc9, 0x68, 0xf7, 0xea, 0x41, 0x18, 0x5c,
+                0x16, 0x6a, 0x98, 0x13, 0x0c, 0x10, 0xc2, 0xa3,
+            },
+        },
+        .confirm_rsp[16] = {
+            .value = {
+                0x97, 0x73, 0xc9, 0x72, 0x68, 0x99, 0x63, 0xed,
+                0x81, 0x3b, 0x5c, 0xee, 0x37, 0xfc, 0xca, 0xae,
+            },
+        },
+        .random_req[16] = {
+            .value = {
+                0x5b, 0x85, 0xb0, 0x1b, 0xc3, 0xde, 0x18, 0xba,
+                0xc1, 0xc7, 0x89, 0x99, 0xfe, 0xcd, 0xdb, 0x6a,
+            },
+        },
+        .random_rsp[16] = {
+            .value = {
+                0x5e, 0x1a, 0xcb, 0xbc, 0xda, 0x41, 0x06, 0x5a,
+                0x14, 0x34, 0x3a, 0xb1, 0xa1, 0x6f, 0xb2, 0xd8,
+            },
+        },
+        .confirm_req[17] = {
+            .value = {
+                0x1d, 0x59, 0x8a, 0xb0, 0x19, 0xe5, 0xff, 0x45,
+                0xb6, 0xc3, 0x33, 0x64, 0xd1, 0x6e, 0xee, 0xdd,
+            },
+        },
+        .confirm_rsp[17] = {
+            .value = {
+                0x4c, 0x9b, 0xe8, 0x68, 0x52, 0x34, 0xef, 0xe1,
+                0x84, 0xbd, 0x37, 0x85, 0x53, 0x0d, 0xd5, 0xc1,
+            },
+        },
+        .random_req[17] = {
+            .value = {
+                0xa6, 0xf7, 0x97, 0x18, 0x9a, 0x3e, 0x9d, 0xcf,
+                0x91, 0xa3, 0xa3, 0x8e, 0xda, 0x8f, 0x8f, 0x90,
+            },
+        },
+        .random_rsp[17] = {
+            .value = {
+                0x94, 0x10, 0x19, 0x17, 0x8d, 0x0a, 0x72, 0xfd,
+                0x24, 0x9d, 0xfd, 0x37, 0x4e, 0xdf, 0x4c, 0x30,
+            },
+        },
+        .confirm_req[18] = {
+            .value = {
+                0xfc, 0x64, 0x8a, 0x8b, 0x37, 0x17, 0x90, 0x6d,
+                0x25, 0x0e, 0xc6, 0x18, 0xc9, 0xc9, 0xc2, 0x2a,
+            },
+        },
+        .confirm_rsp[18] = {
+            .value = {
+                0x50, 0x98, 0x86, 0xf5, 0xc0, 0xda, 0x45, 0x2d,
+                0xea, 0xc8, 0x9d, 0x28, 0x04, 0xd8, 0x73, 0x6f,
+            },
+        },
+        .random_req[18] = {
+            .value = {
+                0x13, 0x10, 0x38, 0xe8, 0x17, 0x6d, 0x72, 0xd5,
+                0x94, 0xaf, 0xed, 0x4f, 0x23, 0xa0, 0x41, 0xfc,
+            },
+        },
+        .random_rsp[18] = {
+            .value = {
+                0xdf, 0xed, 0xf7, 0x08, 0xce, 0x64, 0xbc, 0x11,
+                0x41, 0x7a, 0xd9, 0xf7, 0x4a, 0xd9, 0x4a, 0x15,
+            },
+        },
+        .confirm_req[19] = {
+            .value = {
+                0xae, 0x24, 0x8f, 0xdf, 0xb0, 0x57, 0xc4, 0x9c,
+                0xe6, 0xae, 0x9b, 0xc2, 0x4d, 0x3d, 0x1c, 0xcb,
+            },
+        },
+        .confirm_rsp[19] = {
+            .value = {
+                0xcc, 0x5c, 0xa3, 0xbe, 0xd7, 0x83, 0xee, 0x60,
+                0x80, 0xff, 0x5f, 0x1a, 0x07, 0xbf, 0x4c, 0x33,
+            },
+        },
+        .random_req[19] = {
+            .value = {
+                0x93, 0xc3, 0x62, 0x06, 0xcb, 0xe5, 0xb0, 0x01,
+                0x02, 0x18, 0xa2, 0x50, 0x4c, 0x73, 0xa2, 0x27,
+            },
+        },
+        .random_rsp[19] = {
+            .value = {
+                0x11, 0x2a, 0xd3, 0x06, 0x28, 0x9c, 0xdf, 0x73,
+                0xa5, 0xa4, 0xe5, 0x1e, 0x07, 0xcf, 0xee, 0x71,
+            },
+        },
+        .dhkey_check_req = {
+            .value = {
+                0x73, 0xa0, 0x40, 0x58, 0x78, 0x20, 0x5f, 0x2c,
+                0xf4, 0x19, 0x23, 0xa8, 0x74, 0xbd, 0xc2, 0x3e,
+            },
+        },
+        .dhkey_check_rsp = {
+            .value = {
+                0x5a, 0x30, 0xbc, 0xce, 0xec, 0xdf, 0xf0, 0x32,
+                0x3c, 0x18, 0xa3, 0xd3, 0x3f, 0x20, 0x87, 0x10,
+            },
+        },
+        .sign_info_req = {
+            .sig_key = {
+                0x2e, 0x81, 0x09, 0xde, 0x32, 0xc5, 0x28, 0x34,
+                0xe1, 0x45, 0x4a, 0x35, 0x49, 0xef, 0xa2, 0xed,
+            },
+        },
+        .id_info_rsp = {
+            .irk = {
+                0xef, 0x8d, 0xe2, 0x16, 0x4f, 0xec, 0x43, 0x0d,
+                0xbf, 0x5b, 0xdd, 0x34, 0xc0, 0x53, 0x1e, 0xb8,
+            },
+        },
+        .id_addr_info_rsp = {
+            .addr_type = 0,
+            .bd_addr = {
+                0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
+            },
+        },
+        .sign_info_rsp = {
+            .sig_key = {
+                0x90, 0x3d, 0x26, 0x65, 0xc1, 0xd1, 0x5a, 0x9d,
+                0xda, 0xab, 0x0d, 0x00, 0x05, 0x0e, 0x6c, 0x5d,
+            },
+        },
+        .ltk = {
+            0xf1, 0x41, 0x1a, 0x5b, 0x60, 0xc1, 0x43, 0xc6,
+            0x80, 0x34, 0x5e, 0x7f, 0xd8, 0x0c, 0x75, 0xdc,
+        },
+        .pair_alg = BLE_SM_PAIR_ALG_PASSKEY,
+        .authenticated = 1,
+        .passkey_info = {
+            .passkey = {
+                .action = BLE_SM_IOACT_INPUT,
+                .passkey = 516645,
+            },
+        },
+    };
+    ble_sm_test_util_us_sc_good(&params);
+}
+
+/**
+ * Secure connections pairing
+ * Master: us
+ * Pair algorithm: passkey entry
+ * Initiator IO capabilities: 0
+ * Responder IO capabilities: 4
+ * Bonding: true
+ * Initiator address type: 0
+ * Responder address type: 0
+ * Initiator key distribution: 7
+ * Responder key distribution: 5
+ */
+TEST_CASE(ble_sm_sc_us_pk_iio0_rio4_b1_iat0_rat0_ik7_rk5)
+{
+    struct ble_sm_test_sc_params params;
+
+    params = (struct ble_sm_test_sc_params) {
+        .init_addr = {
+            0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
+        },
+        .resp_addr = {
+            0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
+        },
+        .pair_req = {
+            .io_cap = 0x00,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x07,
+            .resp_key_dist = 0x07,
+        },
+        .pair_rsp = {
+            .io_cap = 0x04,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x07,
+            .resp_key_dist = 0x05,
+        },
+        .our_priv_key = {
+            0xb1, 0x6b, 0x4f, 0x81, 0xbc, 0xe3, 0x60, 0x9e,
+            0x00, 0x20, 0xf1, 0x73, 0x3e, 0xfb, 0xcc, 0x6e,
+            0x8c, 0xb6, 0xd2, 0x51, 0xd9, 0x36, 0x8a, 0x6d,
+            0xca, 0x8c, 0xd7, 0xbe, 0x96, 0x03, 0xdf, 0xd6,
+        },
+        .public_key_req = {
+            .x = {
+                0xe5, 0x0f, 0x02, 0x0a, 0x37, 0x90, 0x94, 0x5a,
+                0x06, 0x21, 0xf7, 0xbc, 0xd5, 0xbe, 0xb9, 0x24,
+                0x8a, 0x35, 0xfd, 0xf8, 0x5e, 0xe2, 0x70, 0xd5,
+                0x5a, 0xe8, 0xe7, 0xdd, 0x13, 0x90, 0xeb, 0xd4,
+            },
+            .y = {
+                0x41, 0xc8, 0x51, 0x1a, 0x25, 0x44, 0x01, 0x53,
+                0x42, 0x74, 0x07, 0x9c, 0x18, 0xe6, 0x3b, 0x8a,
+                0xce, 0x7a, 0x37, 0x1f, 0x18, 0x5c, 0x02, 0x7c,
+                0x67, 0x16, 0xf5, 0x30, 0x2b, 0x31, 0xa9, 0xc7,
+            },
+        },
+        .public_key_rsp = {
+            .x = {
+                0x03, 0x0d, 0x13, 0x55, 0xd9, 0xee, 0x3f, 0xac,
+                0x8e, 0x8a, 0xa6, 0x2a, 0xcb, 0x60, 0x35, 0xb9,
+                0xb2, 0x4d, 0x63, 0x91, 0x5e, 0xa1, 0xdd, 0xdf,
+                0x60, 0xdc, 0x6e, 0x09, 0xb9, 0x9e, 0xf1, 0x4d,
+            },
+            .y = {
+                0xa8, 0x09, 0x31, 0x1e, 0x39, 0x96, 0x74, 0x41,
+                0xea, 0x19, 0x4f, 0x24, 0x36, 0x57, 0x7c, 0x9f,
+                0x21, 0xa3, 0xad, 0xa1, 0x3d, 0xe2, 0x1c, 0x6a,
+                0xd6, 0xc9, 0xdb, 0xff, 0xce, 0x0a, 0x94, 0x12,
+            },
+        },
+        .confirm_req[0] = {
+            .value = {
+                0x3b, 0x3d, 0xb2, 0x2f, 0x72, 0x0f, 0x93, 0x19,
+                0x95, 0xdb, 0x88, 0xdf, 0x5d, 0x58, 0x95, 0x37,
+            },
+        },
+        .confirm_rsp[0] = {
+            .value = {
+                0x98, 0xab, 0x20, 0x8d, 0x51, 0x3b, 0x6c, 0x29,
+                0x2d, 0x73, 0x15, 0xf6, 0x6d, 0x6d, 0xb9, 0xb3,
+            },
+        },
+        .random_req[0] = {
+            .value = {
+                0xc1, 0xdf, 0x20, 0x3d, 0x7b, 0xcb, 0x5f, 0xe2,
+                0x9a, 0x23, 0x9c, 0xba, 0x2f, 0x42, 0x3c, 0xb8,
+            },
+        },
+        .random_rsp[0] = {
+            .value = {
+                0x7d, 0x82, 0xb4, 0xae, 0x41, 0xdb, 0x67, 0x8f,
+                0x54, 0x01, 0x21, 0x64, 0x31, 0xd4, 0xfc, 0xb5,
+            },
+        },
+        .confirm_req[1] = {
+            .value = {
+                0xc3, 0xa5, 0xd0, 0xdd, 0xd5, 0xec, 0x1d, 0xc3,
+                0x14, 0x95, 0x79, 0xb2, 0x61, 0x4d, 0x4f, 0x36,
+            },
+        },
+        .confirm_rsp[1] = {
+            .value = {
+                0xe2, 0x20, 0xf4, 0x4d, 0xa1, 0x9c, 0x83, 0x51,
+                0x18, 0xf9, 0x35, 0x2a, 0x51, 0x50, 0xdf, 0xe7,
+            },
+        },
+        .random_req[1] = {
+            .value = {
+                0x71, 0xcb, 0x01, 0xb4, 0x83, 0xdc, 0xd8, 0x54,
+                0x0f, 0xe5, 0xd5, 0x6b, 0x6a, 0x0d, 0x98, 0xb6,
+            },
+        },
+        .random_rsp[1] = {
+            .value = {
+                0x30, 0xbf, 0xd3, 0xfd, 0xf4, 0xc2, 0xa1, 0xd0,
+                0xba, 0x4b, 0x27, 0x7c, 0x29, 0x98, 0x54, 0xa2,
+            },
+        },
+        .confirm_req[2] = {
+            .value = {
+                0xf0, 0x92, 0xc4, 0xda, 0x8a, 0x17, 0x7c, 0xc6,
+                0x14, 0x05, 0x7d, 0xbb, 0xfc, 0x7c, 0xcd, 0x0a,
+            },
+        },
+        .confirm_rsp[2] = {
+            .value = {
+                0xf3, 0x89, 0xca, 0xe0, 0xfb, 0xbe, 0x8c, 0xc3,
+                0x4c, 0x6c, 0x6e, 0x11, 0x36, 0x4e, 0xaa, 0x25,
+            },
+        },
+        .random_req[2] = {
+            .value = {
+                0x78, 0x5a, 0xf0, 0x1e, 0x2a, 0x0d, 0x16, 0xb3,
+                0x03, 0x4b, 0x4b, 0x68, 0x17, 0xe0, 0xf0, 0x82,
+            },
+        },
+        .random_rsp[2] = {
+            .value = {
+                0xbf, 0x96, 0xdd, 0xf5, 0x30, 0x2a, 0xe9, 0x8c,
+                0xb9, 0x13, 0xc5, 0xb7, 0x15, 0x1f, 0xa3, 0x9b,
+            },
+        },
+        .confirm_req[3] = {
+            .value = {
+                0x36, 0xe4, 0x4c, 0x00, 0xe7, 0x0d, 0xee, 0xe4,
+                0x95, 0xb8, 0x6a, 0xf9, 0xf7, 0x24, 0xef, 0xea,
+            },
+        },
+        .confirm_rsp[3] = {
+            .value = {
+                0x2e, 0x90, 0x87, 0x85, 0xb8, 0x29, 0x93, 0x9e,
+                0x38, 0xa6, 0xdb, 0x17, 0xb2, 0xa8, 0x32, 0x65,
+            },
+        },
+        .random_req[3] = {
+            .value = {
+                0x0a, 0xee, 0x93, 0xf6, 0x56, 0x35, 0x8e, 0xed,
+                0x3f, 0x45, 0xa5, 0x01, 0x59, 0xeb, 0xea, 0xa8,
+            },
+        },
+        .random_rsp[3] = {
+            .value = {
+                0x38, 0xd0, 0xf8, 0x11, 0x5e, 0x47, 0x72, 0x66,
+                0xce, 0x56, 0x9c, 0x81, 0x5f, 0x52, 0xd4, 0x9a,
+            },
+        },
+        .confirm_req[4] = {
+            .value = {
+                0x2c, 0x98, 0x9b, 0x71, 0xe4, 0xde, 0x6d, 0x20,
+                0x84, 0x30, 0xab, 0x7a, 0xfc, 0x43, 0x82, 0xc6,
+            },
+        },
+        .confirm_rsp[4] = {
+            .value = {
+                0x76, 0xfe, 0x1f, 0x78, 0xaa, 0x42, 0xd5, 0xc6,
+                0x9f, 0xe4, 0xa7, 0xc7, 0xb8, 0xd2, 0x1e, 0x59,
+            },
+        },
+        .random_req[4] = {
+            .value = {
+                0x61, 0x5e, 0x47, 0xb1, 0x77, 0x6f, 0x04, 0xee,
+                0x94, 0xc4, 0x6c, 0xa9, 0xf5, 0xf8, 0x11, 0x6e,
+            },
+        },
+        .random_rsp[4] = {
+            .value = {
+                0xa5, 0xad, 0x98, 0x65, 0x28, 0xfc, 0x6b, 0x02,
+                0x6d, 0x9a, 0x29, 0x61, 0x1c, 0x02, 0x0a, 0x6b,
+            },
+        },
+        .confirm_req[5] = {
+            .value = {
+                0x4d, 0x55, 0x3e, 0x1f, 0x87, 0x12, 0xc7, 0x6c,
+                0xd7, 0x9a, 0xa6, 0xf1, 0x6e, 0x48, 0xd3, 0x7d,
+            },
+        },
+        .confirm_rsp[5] = {
+            .value = {
+                0xff, 0x77, 0x6e, 0xba, 0x1f, 0xb7, 0xbd, 0x0b,
+                0x3f, 0xce, 0xd5, 0x39, 0x81, 0x17, 0x51, 0xfc,
+            },
+        },
+        .random_req[5] = {
+            .value = {
+                0xf9, 0x2c, 0x77, 0x41, 0xcd, 0x9a, 0x10, 0x99,
+                0xc6, 0x70, 0x5a, 0xc8, 0x24, 0x26, 0xb2, 0xc8,
+            },
+        },
+        .random_rsp[5] = {
+            .value = {
+                0xa0, 0x44, 0x0a, 0x8b, 0xda, 0x6a, 0x74, 0x90,
+                0x5f, 0x89, 0x44, 0xa5, 0x9a, 0x58, 0xd5, 0x08,
+            },
+        },
+        .confirm_req[6] = {
+            .value = {
+                0x7e, 0x6e, 0x89, 0xc8, 0xbe, 0xde, 0x1c, 0xc3,
+                0x45, 0xb6, 0x4c, 0x83, 0x71, 0xe2, 0xd6, 0xda,
+            },
+        },
+        .confirm_rsp[6] = {
+            .value = {
+                0x4a, 0x29, 0x7b, 0x88, 0x97, 0xc1, 0x60, 0x85,
+                0x32, 0x7d, 0xf1, 0xaa, 0x04, 0x13, 0x89, 0x11,
+            },
+        },
+        .random_req[6] = {
+            .value = {
+                0x2a, 0xaf, 0x7d, 0x21, 0x4e, 0x14, 0xf5, 0x7e,
+                0xcc, 0x39, 0xf7, 0x56, 0x45, 0x87, 0x23, 0x64,
+            },
+        },
+        .random_rsp[6] = {
+            .value = {
+                0x74, 0xd2, 0xff, 0xf0, 0x19, 0xf7, 0x87, 0xe7,
+                0x0d, 0x65, 0x27, 0x61, 0xea, 0x9e, 0x05, 0x3d,
+            },
+        },
+        .confirm_req[7] = {
+            .value = {
+                0x4f, 0x77, 0x22, 0x08, 0x58, 0xed, 0x8c, 0x60,
+                0xbf, 0xbc, 0x78, 0x0c, 0x80, 0xc9, 0xb7, 0x60,
+            },
+        },
+        .confirm_rsp[7] = {
+            .value = {
+                0xd2, 0x47, 0xfd, 0xea, 0xa3, 0x32, 0x53, 0xc1,
+                0x06, 0xcd, 0x64, 0xeb, 0x88, 0x64, 0x0e, 0xe5,
+            },
+        },
+        .random_req[7] = {
+            .value = {
+                0xc8, 0xd0, 0x45, 0xa8, 0x29, 0xdb, 0x5a, 0x42,
+                0xfe, 0x68, 0xa8, 0x7a, 0x0a, 0x13, 0x22, 0xa4,
+            },
+        },
+        .random_rsp[7] = {
+            .value = {
+                0x78, 0x14, 0x46, 0xe2, 0x47, 0x0e, 0xd4, 0xb4,
+                0xde, 0x35, 0x4a, 0x82, 0x4b, 0x32, 0x9b, 0x46,
+            },
+        },
+        .confirm_req[8] = {
+            .value = {
+                0x24, 0x96, 0xe5, 0x50, 0xfa, 0xff, 0xba, 0xdf,
+                0x6b, 0x76, 0x40, 0x60, 0x56, 0x5e, 0x5a, 0x66,
+            },
+        },
+        .confirm_rsp[8] = {
+            .value = {
+                0x09, 0xfe, 0x15, 0x3e, 0x55, 0xe5, 0xbe, 0xb7,
+                0x8d, 0xaa, 0x04, 0x59, 0xe6, 0x8b, 0x2c, 0x4e,
+            },
+        },
+        .random_req[8] = {
+            .value = {
+                0x02, 0x25, 0xbe, 0x88, 0x37, 0xb4, 0x6e, 0xcb,
+                0xbc, 0xa9, 0xef, 0x5a, 0xfd, 0x1a, 0x5f, 0x5f,
+            },
+        },
+        .random_rsp[8] = {
+            .value = {
+                0x0b, 0x35, 0xdc, 0x9b, 0x3d, 0xf7, 0xa6, 0x99,
+                0xf3, 0xb9, 0x3c, 0x73, 0x67, 0x0e, 0xcc, 0x12,
+            },
+        },
+        .confirm_req[9] = {
+            .value = {
+                0x38, 0x1c, 0xf7, 0xf0, 0x31, 0xb1, 0x20, 0xa0,
+                0x51, 0x1c, 0xf1, 0xbd, 0x67, 0xfa, 0x84, 0xb4,
+            },
+        },
+        .confirm_rsp[9] = {
+            .value = {
+                0x8e, 0xa1, 0xc1, 0xf5, 0x39, 0xf0, 0x00, 0x49,
+                0xfb, 0xfc, 0xdc, 0xdf, 0x87, 0x0e, 0x96, 0x7e,
+            },
+        },
+        .random_req[9] = {
+            .value = {
+                0xd0, 0xed, 0x6c, 0x52, 0x20, 0x4b, 0x7b, 0x24,
+                0xdd, 0x28, 0x53, 0x2d, 0x71, 0x76, 0xfb, 0x8f,
+            },
+        },
+        .random_rsp[9] = {
+            .value = {
+                0xac, 0xd7, 0x34, 0x6b, 0x7b, 0x59, 0x9e, 0x9b,
+                0x5b, 0x37, 0xc6, 0x5c, 0x3e, 0x9d, 0xe2, 0x13,
+            },
+        },
+        .confirm_req[10] = {
+            .value = {
+                0xa6, 0xd7, 0xb6, 0xd6, 0xb5, 0x01, 0x4a, 0x02,
+                0x0d, 0xf0, 0x22, 0xcb, 0x68, 0xad, 0x7d, 0x73,
+            },
+        },
+        .confirm_rsp[10] = {
+            .value = {
+                0x01, 0xcc, 0x5f, 0xbc, 0xd0, 0x22, 0xa1, 0xb2,
+                0x71, 0x9d, 0x5c, 0x97, 0xfa, 0xd3, 0x6a, 0xc7,
+            },
+        },
+        .random_req[10] = {
+            .value = {
+                0x9f, 0x3a, 0x25, 0xc7, 0x9b, 0xb7, 0xb3, 0x51,
+                0xff, 0xde, 0x3b, 0x1c, 0xdd, 0xf5, 0x08, 0x21,
+            },
+        },
+        .random_rsp[10] = {
+            .value = {
+                0x75, 0x1e, 0x8d, 0xa4, 0x5b, 0x35, 0xec, 0xae,
+                0x17, 0xda, 0xa5, 0x43, 0x76, 0x3c, 0x6a, 0x67,
+            },
+        },
+        .confirm_req[11] = {
+            .value = {
+                0xfc, 0x0c, 0x3f, 0x86, 0xbf, 0xbe, 0x96, 0x0f,
+                0x99, 0x11, 0xa5, 0x36, 0x03, 0xcd, 0xbd, 0x7f,
+            },
+        },
+        .confirm_rsp[11] = {
+            .value = {
+                0x48, 0xcd, 0xc8, 0x89, 0xd6, 0x1c, 0x0d, 0xb1,
+                0x90, 0x01, 0x0e, 0xea, 0x80, 0xbc, 0xff, 0xb3,
+            },
+        },
+        .random_req[11] = {
+            .value = {
+                0xec, 0xfc, 0xe3, 0x0a, 0x97, 0xed, 0xe8, 0x51,
+                0x5d, 0x64, 0x3c, 0x73, 0x59, 0x2e, 0x62, 0xac,
+            },
+        },
+        .random_rsp[11] = {
+            .value = {
+                0x81, 0x74, 0x44, 0xca, 0xec, 0x38, 0x20, 0x6d,
+                0x52, 0x27, 0x49, 0x55, 0x61, 0x97, 0x01, 0x34,
+            },
+        },
+        .confirm_req[12] = {
+            .value = {
+                0x27, 0x8c, 0x88, 0x09, 0xcb, 0xd6, 0x45, 0xb7,
+                0x30, 0x4b, 0x1b, 0xcd, 0xc3, 0xac, 0x83, 0xd6,
+            },
+        },
+        .confirm_rsp[12] = {
+            .value = {
+                0xea, 0xbc, 0xe2, 0x43, 0xc8, 0xe0, 0x06, 0xd8,
+                0x7b, 0x3e, 0xa4, 0x55, 0x95, 0xa2, 0x23, 0x9b,
+            },
+        },
+        .random_req[12] = {
+            .value = {
+                0x68, 0x8f, 0xb6, 0x7b, 0x91, 0x0d, 0xc9, 0x30,
+                0xe7, 0xb7, 0xb7, 0x7a, 0x79, 0x29, 0x59, 0x7d,
+            },
+        },
+        .random_rsp[12] = {
+            .value = {
+                0xfd, 0xa1, 0x3d, 0xaf, 0x8d, 0xd2, 0xa0, 0x02,
+                0x82, 0x92, 0xeb, 0x2e, 0x4d, 0x6c, 0x8d, 0x69,
+            },
+        },
+        .confirm_req[13] = {
+            .value = {
+                0x6f, 0xa8, 0x20, 0x81, 0x1c, 0x4b, 0xe8, 0xe3,
+                0xdc, 0xea, 0x39, 0xbd, 0xfb, 0xbf, 0x79, 0xc4,
+            },
+        },
+        .confirm_rsp[13] = {
+            .value = {
+                0x2a, 0x09, 0xec, 0x32, 0x63, 0x3d, 0x38, 0x5d,
+                0x28, 0xb2, 0xb1, 0x62, 0xee, 0x6c, 0x0a, 0x6c,
+            },
+        },
+        .random_req[13] = {
+            .value = {
+                0x35, 0xb5, 0xc5, 0xc0, 0x74, 0x1f, 0x40, 0xac,
+                0x23, 0x52, 0x02, 0x68, 0xdf, 0x62, 0x73, 0xca,
+            },
+        },
+        .random_rsp[13] = {
+            .value = {
+                0xb8, 0xe2, 0x65, 0xdc, 0x22, 0xcb, 0xc2, 0xdb,
+                0x00, 0x60, 0x37, 0xe2, 0xcc, 0xc0, 0x41, 0x72,
+            },
+        },
+        .confirm_req[14] = {
+            .value = {
+                0x05, 0x0b, 0x5c, 0xa7, 0x58, 0x9c, 0x08, 0x81,
+                0x4a, 0x6b, 0x12, 0xae, 0xaa, 0xe5, 0x81, 0xf3,
+            },
+        },
+        .confirm_rsp[14] = {
+            .value = {
+                0xdd, 0x2b, 0xd1, 0xdd, 0x49, 0x92, 0xf3, 0xe1,
+                0xae, 0xf3, 0x6d, 0x89, 0xfd, 0x77, 0xf9, 0xaa,
+            },
+        },
+        .random_req[14] = {
+            .value = {
+                0xbc, 0x27, 0x29, 0x1b, 0xc4, 0xbc, 0x0e, 0x88,
+                0x95, 0x50, 0xf7, 0x92, 0xe6, 0xf7, 0x29, 0xe8,
+            },
+        },
+        .random_rsp[14] = {
+            .value = {
+                0xe7, 0x15, 0xfe, 0x53, 0x77, 0xd9, 0x98, 0x1d,
+                0x5b, 0x4e, 0x37, 0xa3, 0x1f, 0xc9, 0x47, 0x5d,
+            },
+        },
+        .confirm_req[15] = {
+            .value = {
+                0x75, 0x70, 0x9f, 0x84, 0x3e, 0x6b, 0x88, 0xcb,
+                0x66, 0xda, 0x8f, 0x79, 0xbc, 0xf8, 0x44, 0x99,
+            },
+        },
+        .confirm_rsp[15] = {
+            .value = {
+                0x13, 0xe4, 0x43, 0xb2, 0x61, 0x72, 0xfd, 0x33,
+                0xba, 0x87, 0x44, 0x27, 0x6f, 0x9a, 0xea, 0x19,
+            },
+        },
+        .random_req[15] = {
+            .value = {
+                0xda, 0x90, 0x59, 0x72, 0xed, 0x67, 0xde, 0x65,
+                0x21, 0xab, 0x7d, 0x9d, 0x72, 0x8c, 0x88, 0x8e,
+            },
+        },
+        .random_rsp[15] = {
+            .value = {
+                0x94, 0x92, 0x0f, 0x6c, 0x08, 0xde, 0xae, 0xa7,
+                0xfd, 0x36, 0xe0, 0x02, 0xc8, 0xfd, 0xdd, 0x69,
+            },
+        },
+        .confirm_req[16] = {
+            .value = {
+                0x35, 0x68, 0x1e, 0x80, 0x37, 0xc4, 0x91, 0xe8,
+                0xbf, 0x5e, 0x27, 0x0c, 0xaa, 0x8e, 0x85, 0x7b,
+            },
+        },
+        .confirm_rsp[16] = {
+            .value = {
+                0x1e, 0x42, 0x47, 0x29, 0x06, 0xdc, 0x2b, 0x45,
+                0xec, 0x95, 0x23, 0x31, 0x29, 0x24, 0x95, 0xf0,
+            },
+        },
+        .random_req[16] = {
+            .value = {
+                0x4e, 0x9f, 0x5d, 0x5a, 0x8f, 0xf7, 0x28, 0xc9,
+                0x29, 0x62, 0x0a, 0x67, 0x19, 0x17, 0x5e, 0xa7,
+            },
+        },
+        .random_rsp[16] = {
+            .value = {
+                0x7c, 0xd4, 0x13, 0xba, 0x27, 0x16, 0x39, 0xe7,
+                0xf0, 0xbf, 0xec, 0x1e, 0xe5, 0xcc, 0x20, 0x0b,
+            },
+        },
+        .confirm_req[17] = {
+            .value = {
+                0xb9, 0xcd, 0xf5, 0xf9, 0x2b, 0x4f, 0x6d, 0x08,
+                0x51, 0xe0, 0x92, 0x99, 0x15, 0xca, 0x15, 0x2a,
+            },
+        },
+        .confirm_rsp[17] = {
+            .value = {
+                0xb8, 0xf2, 0xf9, 0x61, 0x4f, 0x0e, 0xfd, 0x19,
+                0xcb, 0x5d, 0x7e, 0x93, 0x87, 0x7a, 0x0a, 0x6e,
+            },
+        },
+        .random_req[17] = {
+            .value = {
+                0x8b, 0xf8, 0xc8, 0xeb, 0xe5, 0xdb, 0xcf, 0xfe,
+                0x68, 0x70, 0x1f, 0xbe, 0x1e, 0x3c, 0x94, 0x7d,
+            },
+        },
+        .random_rsp[17] = {
+            .value = {
+                0x0d, 0xfc, 0x68, 0x2e, 0x50, 0x31, 0x9f, 0x60,
+                0xe6, 0x12, 0x72, 0x24, 0x7c, 0xad, 0xf7, 0x48,
+            },
+        },
+        .confirm_req[18] = {
+            .value = {
+                0x27, 0x68, 0x07, 0xaa, 0xa6, 0x33, 0x13, 0x49,
+                0x65, 0x4c, 0x80, 0x54, 0xfb, 0x69, 0xcb, 0x0e,
+            },
+        },
+        .confirm_rsp[18] = {
+            .value = {
+                0xc5, 0x8d, 0x45, 0x81, 0xb0, 0x5a, 0x69, 0x0f,
+                0x6c, 0x89, 0x0b, 0x60, 0x1e, 0x27, 0x9b, 0x9e,
+            },
+        },
+        .random_req[18] = {
+            .value = {
+                0x97, 0x46, 0x95, 0xb5, 0x86, 0xa1, 0xc1, 0x86,
+                0x3a, 0x8a, 0x1f, 0x29, 0x38, 0xe0, 0x69, 0x7f,
+            },
+        },
+        .random_rsp[18] = {
+            .value = {
+                0x8f, 0x0e, 0x56, 0x17, 0x1c, 0x4b, 0x78, 0x1f,
+                0xd1, 0x8a, 0x69, 0xbd, 0x65, 0xe3, 0xde, 0x3c,
+            },
+        },
+        .confirm_req[19] = {
+            .value = {
+                0xd2, 0xa5, 0x4e, 0x31, 0x34, 0xde, 0x68, 0xf0,
+                0x69, 0x88, 0x6f, 0x28, 0xa2, 0xdd, 0xba, 0xe1,
+            },
+        },
+        .confirm_rsp[19] = {
+            .value = {
+                0xf8, 0x5e, 0x4f, 0x4d, 0x56, 0xf6, 0x22, 0xc0,
+                0x57, 0x04, 0x04, 0x45, 0x24, 0x83, 0x09, 0x80,
+            },
+        },
+        .random_req[19] = {
+            .value = {
+                0x64, 0xe1, 0x5a, 0x76, 0x71, 0x94, 0xc0, 0x64,
+                0x2b, 0xea, 0x9d, 0xaf, 0xbd, 0x10, 0x25, 0x9b,
+            },
+        },
+        .random_rsp[19] = {
+            .value = {
+                0x1e, 0x38, 0x6e, 0x66, 0x55, 0xf1, 0x7f, 0x55,
+                0x7c, 0x00, 0xff, 0xad, 0x07, 0x13, 0x25, 0x97,
+            },
+        },
+        .dhkey_check_req = {
+            .value = {
+                0x98, 0xf1, 0x5a, 0x24, 0x81, 0x5d, 0xb5, 0xac,
+                0x04, 0x4e, 0x3a, 0x31, 0x8b, 0x7d, 0xf6, 0x09,
+            },
+        },
+        .dhkey_check_rsp = {
+            .value = {
+                0x1a, 0xb4, 0xf4, 0xf3, 0xc0, 0x5a, 0xf3, 0x13,
+                0x8d, 0x6e, 0x01, 0x16, 0x1e, 0x54, 0xf3, 0xe1,
+            },
+        },
+        .sign_info_req = {
+            .sig_key = {
+                0x4b, 0x01, 0x33, 0x5f, 0x4b, 0xfe, 0x12, 0x8b,
+                0x9f, 0x81, 0x44, 0x78, 0x90, 0x03, 0x9e, 0x53,
+            },
+        },
+        .id_info_rsp = {
+            .irk = {
+                0xef, 0x8d, 0xe2, 0x16, 0x4f, 0xec, 0x43, 0x0d,
+                0xbf, 0x5b, 0xdd, 0x34, 0xc0, 0x53, 0x1e, 0xb8,
+            },
+        },
+        .id_addr_info_rsp = {
+            .addr_type = 0,
+            .bd_addr = {
+                0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
+            },
+        },
+        .sign_info_rsp = {
+            .sig_key = {
+                0xd2, 0xa1, 0x2c, 0xf0, 0xa6, 0xeb, 0x97, 0x5e,
+                0xac, 0x53, 0xa1, 0x3d, 0x41, 0x40, 0x36, 0x2f,
+            },
+        },
+        .ltk = {
+            0xce, 0x28, 0x91, 0xa9, 0x36, 0xb7, 0xe1, 0xda,
+            0x3c, 0x66, 0xd9, 0x33, 0x3d, 0x03, 0x8e, 0x31,
+        },
+        .pair_alg = BLE_SM_PAIR_ALG_PASSKEY,
+        .authenticated = 1,
+        .passkey_info = {
+            .passkey = {
+                .action = BLE_SM_IOACT_DISP,
+                .passkey = 866744,
+            },
+        },
+    };
+    ble_sm_test_util_us_sc_good(&params);
+}
+
+/**
+ * Secure connections pairing
+ * Master: us
+ * Pair algorithm: numeric comparison
+ * Initiator IO capabilities: 1
+ * Responder IO capabilities: 4
+ * Bonding: true
+ * Initiator address type: 0
+ * Responder address type: 0
+ * Initiator key distribution: 7
+ * Responder key distribution: 5
+ */
+TEST_CASE(ble_sm_sc_us_nc_iio1_rio4_b1_iat0_rat0_ik7_rk5)
+{
+    struct ble_sm_test_sc_params params;
+
+    params = (struct ble_sm_test_sc_params) {
+        .init_addr = {
+            0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
+        },
+        .resp_addr = {
+            0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
+        },
+        .pair_req = {
+            .io_cap = 0x01,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x07,
+            .resp_key_dist = 0x07,
+        },
+        .pair_rsp = {
+            .io_cap = 0x04,
+            .oob_data_flag = 0x00,
+            .authreq = 0x0d,
+            .max_enc_key_size = 0x10,
+            .init_key_dist = 0x07,
+            .resp_key_dist = 0x05,
+        },
+        .our_priv_key = {
+            0xb1, 0x6b, 0x4f, 0x81, 0xbc, 0xe3, 0x60, 0x9e,
+            0x00, 0x20, 0xf1, 0x73, 0x3e, 0xfb, 0xcc, 0x6e,
+            0x8c, 0xb6, 0xd2, 0x51, 0xd9, 0x36, 0x8a, 0x6d,
+            0xca, 0x8c, 0xd7, 0xbe, 0x96, 0x03, 0xdf, 0xd6,
+        },
+        .public_key_req = {
+            .x = {
+                0xe5, 0x0f, 0x02, 0x0a, 0x37, 0x90, 0x94, 0x5a,
+                0x06, 0x21, 0xf7, 0xbc, 0xd5, 0xbe, 0xb9, 0x24,
+                0x8a, 0x35, 0xfd, 0xf8, 0x5e, 0xe2, 0x70, 0xd5,
+                0x5a, 0xe8, 0xe7, 0xdd, 0x13, 0x90, 0xeb, 0xd4,
+            },
+            .y = {
+                0x41, 0xc8, 0x51, 0x1a, 0x25, 0x44, 0x01, 0x53,
+                0x42, 0x74, 0x07, 0x9c, 0x18, 0xe6, 0x3b, 0x8a,
+                0xce, 0x7a, 0x37, 0x1f, 0x18, 0x5c, 0x02, 0x7c,
+                0x67, 0x16, 0xf5, 0x30, 0x2b, 0x31, 0xa9, 0xc7,
+            },
+        },
+        .public_key_rsp = {
+            .x = {
+                0x7c, 0x27, 0x39, 0xdc, 0x10, 0xfa, 0x57, 0x97,
+                0x4a, 0x18, 0xdc, 0x0e, 0xfc, 0x4b, 0xd0, 0xac,
+                0x3a, 0xa4, 0x4c, 0x65, 0xb5, 0xbe, 0x7b, 0xd8,
+                0xd1, 0xfd, 0x9d, 0xf8, 0xe3, 0x00, 0x4e, 0xf3,
+            },
+            .y = {
+                0xae, 0xfd, 0x8e, 0x93, 0xb4, 0xa9, 0x4d, 0xd3,
+                0xb6, 0xbd, 0x4c, 0x1d, 0xc1, 0x7e, 0x67, 0x57,
+                0x07, 0x10, 0x4e, 0xd0, 0x0f, 0x23, 0x23, 0xab,
+                0x09, 0x86, 0xc3, 0xb9, 0x63, 0x14, 0xe4, 0xe5,
+            },
+        },
+        .confirm_rsp[0] = {
+            .value = {
+                0x40, 0x35, 0x6d, 0xa1, 0x19, 0xa6, 0x8b, 0xff,
+                0x4f, 0x0c, 0x86, 0x7e, 0x95, 0x7c, 0xb8, 0xc1,
+            },
+        },
+        .random_req[0] = {
+            .value = {
+                0x95, 0x84, 0x0d, 0x2d, 0x7a, 0xfd, 0x5a, 0xa6,
+                0xea, 0xfd, 0x7b, 0xf0, 0x68, 0x95, 0xeb, 0x77,
+            },
+        },
+        .random_rsp[0] = {
+            .value = {
+                0x25, 0x41, 0xda, 0xdf, 0xdd, 0xca, 0xcd, 0x2e,
+                0x49, 0x79, 0xb0, 0xaa, 0x7a, 0x23, 0x28, 0x7f,
+            },
+        },
+        .dhkey_check_req = {
+            .value = {
+                0x49, 0xbb, 0x89, 0x9e, 0xa1, 0x10, 0x26, 0x7a,
+                0xe7, 0x42, 0x51, 0xcd, 0x1f, 0x3b, 0x22, 0x1d,
+            },
+        },
+        .dhkey_check_rsp = {
+            .value = {
+                0x59, 0x51, 0xc8, 0x7b, 0x4f, 0xae, 0xfe, 0xb8,
+                0x0c, 0x41, 0xe8, 0xe0, 0xf9, 0x4c, 0x2b, 0xc7,
+            },
+        },
+        .sign_info_req = {
+            .sig_key = {
+                0x37, 0x26, 0xc0, 0x79, 0x59, 0xcd, 0xb7, 0x0f,
+                0xa6, 0xd8, 0xe4, 0x02, 0xc9, 0xe6, 0x02, 0x71,
+            },
+        },
+        .id_info_rsp = {
+            .irk = {
+                0xef, 0x8d, 0xe2, 0x16, 0x4f, 0xec, 0x43, 0x0d,
+                0xbf, 0x5b, 0xdd, 0x34, 0xc0, 0x53, 0x1e, 0xb8,
+            },
+        },
+        .id_addr_info_rsp = {
+            .addr_type = 0,
+            .bd_addr = {
+                0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
+            },
+        },
+        .sign_info_rsp = {
+            .sig_key = {
+                0x45, 0x69, 0x05, 0xe3, 0x0c, 0x9e, 0x01, 0xb3,
+                0xe8, 0xea, 0xa0, 0x5b, 0x70, 0xd9, 0x62, 0x0e,
+            },
+        },
+        .ltk = {
+            0xf5, 0x60, 0x02, 0x97, 0x2f, 0xbb, 0x3c, 0xe9,
+            0x97, 0xd7, 0xd5, 0x58, 0x04, 0x96, 0xa6, 0xe7,
+        },
+        .pair_alg = BLE_SM_PAIR_ALG_NUMCMP,
+        .authenticated = 1,
+        .passkey_info = {
+            .passkey = {
+                .action = BLE_SM_IOACT_NUMCMP,
+                .numcmp_accept = 1,
+            },
+            .exp_numcmp = 344302,
+        },
+    };
+    ble_sm_test_util_us_sc_good(&params);
+}
+
 TEST_SUITE(ble_sm_sc_test_suite)
 {
     /* Peer as initiator. */
@@ -1679,6 +3033,9 @@ TEST_SUITE(ble_sm_sc_test_suite)
 
     /* Us as initiator. */
     ble_sm_sc_us_jw_iio3_rio4_b1_iat0_rat0_ik7_rk5();
+    ble_sm_sc_us_pk_iio2_rio4_b1_iat0_rat0_ik7_rk5();
+    ble_sm_sc_us_pk_iio0_rio4_b1_iat0_rat0_ik7_rk5();
+    ble_sm_sc_us_nc_iio1_rio4_b1_iat0_rat0_ik7_rk5();
 }
 
 #endif /* NIMBLE_OPT_SM */


[09/50] [abbrv] incubator-mynewt-core git commit: BLE Host - persist irk properly when ltk not xchgd

Posted by cc...@apache.org.
BLE Host - persist irk properly when ltk not xchgd

This change addresses a bug that occurred when IRKs are exchanged during
SM key exchange, but LTKs are not exchanged.  Under these conditions,
the peer's address was not correctly associated with the persisted IRK.
The result was that subsequent IRK lookups would fail.


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

Branch: refs/heads/develop
Commit: 32afd9cacd7844f64545f6f4007967cec9fd7baf
Parents: a96152c
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Jun 7 22:34:07 2016 +0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Jun 14 19:23:34 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_sm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/32afd9ca/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 32c2583..7e6ed1f 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -473,9 +473,10 @@ ble_sm_fill_store_value(uint8_t peer_addr_type, uint8_t *peer_addr,
 {
     memset(value_sec, 0, sizeof *value_sec);
 
+    value_sec->peer_addr_type = peer_addr_type;
+    memcpy(value_sec->peer_addr, peer_addr, sizeof value_sec->peer_addr);
+
     if (keys->ediv_rand_valid && keys->ltk_valid) {
-        value_sec->peer_addr_type = peer_addr_type;
-        memcpy(value_sec->peer_addr, peer_addr, sizeof value_sec->peer_addr);
         value_sec->ediv = keys->ediv;
         value_sec->rand_num = keys->rand_val;