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/05/12 03:39:39 UTC

[1/3] incubator-mynewt-core git commit: BLE Host unit tests - queue of previous data txes.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 1c34cd527 -> 9eeec05f0


BLE Host unit tests - queue of previous data 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/65d9dc46
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/65d9dc46
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/65d9dc46

Branch: refs/heads/develop
Commit: 65d9dc4689fd6ab5a709ffc26016462b3e5ddf99
Parents: 1c34cd5
Author: Christopher Collins <cc...@apache.org>
Authored: Wed May 11 18:46:33 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed May 11 18:46:33 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/test/ble_att_clt_test.c     |  20 +---
 net/nimble/host/src/test/ble_att_svr_test.c     | 117 +++++++++----------
 net/nimble/host/src/test/ble_gatt_find_s_test.c |  10 +-
 .../host/src/test/ble_gatts_notify_test.c       |  40 +++----
 net/nimble/host/src/test/ble_hs_test.c          |   4 +-
 net/nimble/host/src/test/ble_hs_test_util.c     |  75 +++++++++++-
 net/nimble/host/src/test/ble_hs_test_util.h     |   6 +-
 net/nimble/host/src/test/ble_l2cap_sm_test.c    |  58 +++++----
 net/nimble/host/src/test/ble_l2cap_test.c       |  74 +++++++-----
 9 files changed, 231 insertions(+), 173 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/65d9dc46/net/nimble/host/src/test/ble_att_clt_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_att_clt_test.c b/net/nimble/host/src/test/ble_att_clt_test.c
index 54ddb27..cd19431 100644
--- a/net/nimble/host/src/test/ble_att_clt_test.c
+++ b/net/nimble/host/src/test/ble_att_clt_test.c
@@ -43,10 +43,7 @@ ble_att_clt_test_misc_verify_tx_write(uint16_t handle_id, void *value,
     struct ble_att_write_req req;
     struct os_mbuf *om;
 
-    TEST_ASSERT_FATAL(ble_hs_test_util_prev_tx != NULL);
-
-    om = os_mbuf_pullup(ble_hs_test_util_prev_tx,
-                        OS_MBUF_PKTLEN(ble_hs_test_util_prev_tx));
+    om = ble_hs_test_util_prev_tx_dequeue_pullup();
     TEST_ASSERT_FATAL(om != NULL);
 
     if (is_req) {
@@ -221,10 +218,7 @@ ble_att_clt_test_misc_prep_good(uint16_t handle, uint16_t offset,
     TEST_ASSERT(rc == 0);
 
     ble_hs_test_util_tx_all();
-    TEST_ASSERT_FATAL(ble_hs_test_util_prev_tx != NULL);
-
-    om = os_mbuf_pullup(ble_hs_test_util_prev_tx,
-                        OS_MBUF_PKTLEN(ble_hs_test_util_prev_tx));
+    om = ble_hs_test_util_prev_tx_dequeue_pullup();
     TEST_ASSERT_FATAL(om != NULL);
     TEST_ASSERT(om->om_len == BLE_ATT_PREP_WRITE_CMD_BASE_SZ + attr_data_len);
 
@@ -253,10 +247,7 @@ ble_att_clt_test_misc_exec_good(uint8_t flags)
     TEST_ASSERT(rc == 0);
 
     ble_hs_test_util_tx_all();
-    TEST_ASSERT_FATAL(ble_hs_test_util_prev_tx != NULL);
-
-    om = os_mbuf_pullup(ble_hs_test_util_prev_tx,
-                        OS_MBUF_PKTLEN(ble_hs_test_util_prev_tx));
+    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);
 
@@ -393,10 +384,7 @@ TEST_CASE(ble_att_clt_test_tx_read_mult)
     TEST_ASSERT(rc == 0);
 
     ble_hs_test_util_tx_all();
-    TEST_ASSERT_FATAL(ble_hs_test_util_prev_tx != NULL);
-
-    om = os_mbuf_pullup(ble_hs_test_util_prev_tx,
-                        OS_MBUF_PKTLEN(ble_hs_test_util_prev_tx));
+    om = ble_hs_test_util_prev_tx_dequeue_pullup();
     TEST_ASSERT_FATAL(om != NULL);
     TEST_ASSERT(om->om_len == BLE_ATT_READ_MULT_REQ_BASE_SZ + 4);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/65d9dc46/net/nimble/host/src/test/ble_att_svr_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_att_svr_test.c b/net/nimble/host/src/test/ble_att_svr_test.c
index 8ce414d..770dcb9 100644
--- a/net/nimble/host/src/test/ble_att_svr_test.c
+++ b/net/nimble/host/src/test/ble_att_svr_test.c
@@ -302,12 +302,15 @@ ble_att_svr_test_misc_verify_tx_err_rsp(struct ble_l2cap_chan *chan,
                                         uint8_t error_code)
 {
     struct ble_att_error_rsp rsp;
+    struct os_mbuf *om;
     uint8_t buf[BLE_ATT_ERROR_RSP_SZ];
     int rc;
 
     ble_hs_test_util_tx_all();
 
-    rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, 0, sizeof buf, buf);
+    om = ble_hs_test_util_prev_tx_dequeue();
+
+    rc = os_mbuf_copydata(om, 0, sizeof buf, buf);
     TEST_ASSERT(rc == 0);
 
     ble_att_error_rsp_parse(buf, sizeof buf, &rsp);
@@ -315,63 +318,60 @@ ble_att_svr_test_misc_verify_tx_err_rsp(struct ble_l2cap_chan *chan,
     TEST_ASSERT(rsp.baep_req_op == req_op);
     TEST_ASSERT(rsp.baep_handle == handle);
     TEST_ASSERT(rsp.baep_error_code == error_code);
-
-    /* Remove the error response from the buffer. */
-    os_mbuf_adj(ble_hs_test_util_prev_tx, BLE_ATT_ERROR_RSP_SZ);
 }
 
 static void
 ble_att_svr_test_misc_verify_tx_read_rsp(struct ble_l2cap_chan *chan,
                                          uint8_t *attr_data, int attr_len)
 {
+    struct os_mbuf *om;
     uint8_t u8;
     int rc;
     int i;
 
     ble_hs_test_util_tx_all();
 
-    rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, 0, 1, &u8);
+    om = ble_hs_test_util_prev_tx_dequeue();
+
+    rc = os_mbuf_copydata(om, 0, 1, &u8);
     TEST_ASSERT(rc == 0);
     TEST_ASSERT(u8 == BLE_ATT_OP_READ_RSP);
 
     for (i = 0; i < attr_len; i++) {
-        rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, i + 1, 1, &u8);
+        rc = os_mbuf_copydata(om, i + 1, 1, &u8);
         TEST_ASSERT(rc == 0);
         TEST_ASSERT(u8 == attr_data[i]);
     }
 
-    rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, i + 1, 1, &u8);
+    rc = os_mbuf_copydata(om, i + 1, 1, &u8);
     TEST_ASSERT(rc != 0);
-
-    /* Remove the read response from the buffer. */
-    os_mbuf_adj(ble_hs_test_util_prev_tx, attr_len + 1);
 }
 
 static void
 ble_att_svr_test_misc_verify_tx_read_blob_rsp(struct ble_l2cap_chan *chan,
                                               uint8_t *attr_data, int attr_len)
 {
+    struct os_mbuf *om;
     uint8_t u8;
     int rc;
     int i;
 
     ble_hs_test_util_tx_all();
 
-    rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, 0, 1, &u8);
+    om = ble_hs_test_util_prev_tx_dequeue();
+
+    rc = os_mbuf_copydata(om, 0, 1, &u8);
     TEST_ASSERT(rc == 0);
     TEST_ASSERT(u8 == BLE_ATT_OP_READ_BLOB_RSP);
 
     for (i = 0; i < attr_len; i++) {
-        rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, i + 1, 1, &u8);
+        rc = os_mbuf_copydata(om, i + 1, 1, &u8);
         TEST_ASSERT(rc == 0);
         TEST_ASSERT(u8 == attr_data[i]);
     }
 
-    rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, i + 1, 1, &u8);
+    rc = os_mbuf_copydata(om, i + 1, 1, &u8);
     TEST_ASSERT(rc != 0);
-
-    /* Remove the read response from the buffer. */
-    os_mbuf_adj(ble_hs_test_util_prev_tx, attr_len + 1);
 }
 
 static void
@@ -406,6 +406,7 @@ ble_att_svr_test_misc_verify_tx_read_mult_rsp(struct ble_l2cap_chan *chan,
                                               struct ble_gatt_attr *attrs,
                                               int num_attrs)
 {
+    struct os_mbuf *om;
     uint8_t *attr_value;
     uint8_t u8;
     int rc;
@@ -415,7 +416,9 @@ ble_att_svr_test_misc_verify_tx_read_mult_rsp(struct ble_l2cap_chan *chan,
 
     ble_hs_test_util_tx_all();
 
-    rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, 0, 1, &u8);
+    om = ble_hs_test_util_prev_tx_dequeue();
+
+    rc = os_mbuf_copydata(om, 0, 1, &u8);
     TEST_ASSERT(rc == 0);
     TEST_ASSERT(u8 == BLE_ATT_OP_READ_MULT_RSP);
 
@@ -427,7 +430,7 @@ ble_att_svr_test_misc_verify_tx_read_mult_rsp(struct ble_l2cap_chan *chan,
              ii < attrs[i].value_len && off < ble_l2cap_chan_mtu(chan);
              ii++) {
 
-            rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, off, 1, &u8);
+            rc = os_mbuf_copydata(om, off, 1, &u8);
             TEST_ASSERT(rc == 0);
             TEST_ASSERT(u8 == attr_value[ii]);
 
@@ -435,7 +438,7 @@ ble_att_svr_test_misc_verify_tx_read_mult_rsp(struct ble_l2cap_chan *chan,
         }
     }
 
-    rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, off, 1, &u8);
+    rc = os_mbuf_copydata(om, off, 1, &u8);
     TEST_ASSERT(rc != 0);
 }
 
@@ -462,39 +465,37 @@ ble_att_svr_test_misc_verify_all_read_mult(struct ble_hs_conn *conn,
 static void
 ble_att_svr_test_misc_verify_tx_write_rsp(struct ble_l2cap_chan *chan)
 {
+    struct os_mbuf *om;
     uint8_t u8;
     int rc;
 
     ble_hs_test_util_tx_all();
 
-    rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, 0, 1, &u8);
+    om = ble_hs_test_util_prev_tx_dequeue();
+
+    rc = os_mbuf_copydata(om, 0, 1, &u8);
     TEST_ASSERT(rc == 0);
     TEST_ASSERT(u8 == BLE_ATT_OP_WRITE_RSP);
-
-    /* Remove the write response from the buffer. */
-    os_mbuf_adj(ble_hs_test_util_prev_tx,
-                BLE_ATT_WRITE_RSP_SZ);
 }
 
 static void
 ble_att_svr_test_misc_verify_tx_mtu_rsp(struct ble_l2cap_chan *chan)
 {
     struct ble_att_mtu_cmd rsp;
+    struct os_mbuf *om;
     uint8_t buf[BLE_ATT_MTU_CMD_SZ];
     int rc;
 
     ble_hs_test_util_tx_all();
 
-    rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, 0, sizeof buf, buf);
+    om = ble_hs_test_util_prev_tx_dequeue();
+
+    rc = os_mbuf_copydata(om, 0, sizeof buf, buf);
     TEST_ASSERT(rc == 0);
 
     ble_att_mtu_cmd_parse(buf, sizeof buf, &rsp);
 
     TEST_ASSERT(rsp.bamc_mtu == chan->blc_my_mtu);
-
-    /* Remove the write response from the buffer. */
-    os_mbuf_adj(ble_hs_test_util_prev_tx,
-                BLE_ATT_MTU_CMD_SZ);
 }
 
 struct ble_att_svr_test_info_entry {
@@ -510,6 +511,7 @@ ble_att_svr_test_misc_verify_tx_find_info_rsp(
 {
     struct ble_att_svr_test_info_entry *entry;
     struct ble_att_find_info_rsp rsp;
+    struct os_mbuf *om;
     uint16_t handle;
     uint16_t uuid16;
     uint8_t buf[BLE_ATT_FIND_INFO_RSP_BASE_SZ];
@@ -521,14 +523,16 @@ ble_att_svr_test_misc_verify_tx_find_info_rsp(
 
     off = 0;
 
-    rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, off, sizeof buf, buf);
+    om = ble_hs_test_util_prev_tx_dequeue_pullup();
+
+    rc = os_mbuf_copydata(om, off, sizeof buf, buf);
     TEST_ASSERT(rc == 0);
     off += sizeof buf;
 
     ble_att_find_info_rsp_parse(buf, sizeof buf, &rsp);
 
     for (entry = entries; entry->handle != 0; entry++) {
-        rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, off, 2, &handle);
+        rc = os_mbuf_copydata(om, off, 2, &handle);
         TEST_ASSERT(rc == 0);
         off += 2;
 
@@ -538,7 +542,7 @@ ble_att_svr_test_misc_verify_tx_find_info_rsp(
         if (entry->uuid16 != 0) {
             TEST_ASSERT(rsp.bafp_format ==
                         BLE_ATT_FIND_INFO_RSP_FORMAT_16BIT);
-            rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, off, 2, &uuid16);
+            rc = os_mbuf_copydata(om, off, 2, &uuid16);
             TEST_ASSERT(rc == 0);
             off += 2;
 
@@ -547,7 +551,7 @@ ble_att_svr_test_misc_verify_tx_find_info_rsp(
         } else {
             TEST_ASSERT(rsp.bafp_format ==
                         BLE_ATT_FIND_INFO_RSP_FORMAT_128BIT);
-            rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, off, 16, uuid128);
+            rc = os_mbuf_copydata(om, off, 16, uuid128);
             TEST_ASSERT(rc == 0);
             off += 16;
 
@@ -556,10 +560,7 @@ ble_att_svr_test_misc_verify_tx_find_info_rsp(
     }
 
     /* Ensure there is no extra data in the response. */
-    TEST_ASSERT(off == OS_MBUF_PKTHDR(ble_hs_test_util_prev_tx)->omp_len);
-
-    /* Remove the response from the buffer. */
-    os_mbuf_adj(ble_hs_test_util_prev_tx, off);
+    TEST_ASSERT(off == OS_MBUF_PKTHDR(om)->omp_len);
 }
 
 struct ble_att_svr_test_type_value_entry {
@@ -573,6 +574,7 @@ ble_att_svr_test_misc_verify_tx_find_type_value_rsp(
     struct ble_att_svr_test_type_value_entry *entries)
 {
     struct ble_att_svr_test_type_value_entry *entry;
+    struct os_mbuf *om;
     uint16_t u16;
     uint8_t op;
     int off;
@@ -582,20 +584,22 @@ ble_att_svr_test_misc_verify_tx_find_type_value_rsp(
 
     off = 0;
 
-    rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, off, 1, &op);
+    om = ble_hs_test_util_prev_tx_dequeue_pullup();
+
+    rc = os_mbuf_copydata(om, off, 1, &op);
     TEST_ASSERT(rc == 0);
     off += 1;
 
     TEST_ASSERT(op == BLE_ATT_OP_FIND_TYPE_VALUE_RSP);
 
     for (entry = entries; entry->first != 0; entry++) {
-        rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, off, 2, &u16);
+        rc = os_mbuf_copydata(om, off, 2, &u16);
         TEST_ASSERT(rc == 0);
         htole16(&u16, u16);
         TEST_ASSERT(u16 == entry->first);
         off += 2;
 
-        rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, off, 2, &u16);
+        rc = os_mbuf_copydata(om, off, 2, &u16);
         TEST_ASSERT(rc == 0);
         htole16(&u16, u16);
         TEST_ASSERT(u16 == entry->last);
@@ -603,10 +607,7 @@ ble_att_svr_test_misc_verify_tx_find_type_value_rsp(
     }
 
     /* Ensure there is no extra data in the response. */
-    TEST_ASSERT(off == OS_MBUF_PKTHDR(ble_hs_test_util_prev_tx)->omp_len);
-
-    /* Remove the response from the buffer. */
-    os_mbuf_adj(ble_hs_test_util_prev_tx, off);
+    TEST_ASSERT(off == OS_MBUF_PKTHDR(om)->omp_len);
 }
 
 struct ble_att_svr_test_group_type_entry {
@@ -632,9 +633,7 @@ ble_att_svr_test_misc_verify_tx_read_group_type_rsp(
 
     ble_hs_test_util_tx_all();
 
-    om = os_mbuf_pullup(ble_hs_test_util_prev_tx,
-                        BLE_ATT_READ_GROUP_TYPE_RSP_BASE_SZ);
-    TEST_ASSERT_FATAL(om != NULL);
+    om = ble_hs_test_util_prev_tx_dequeue_pullup();
 
     ble_att_read_group_type_rsp_parse(om->om_data, om->om_len, &rsp);
 
@@ -704,9 +703,7 @@ ble_att_svr_test_misc_verify_tx_read_type_rsp(
 
     ble_hs_test_util_tx_all();
 
-    om = os_mbuf_pullup(ble_hs_test_util_prev_tx,
-                        BLE_ATT_READ_TYPE_RSP_BASE_SZ);
-    TEST_ASSERT_FATAL(om != NULL);
+    om = ble_hs_test_util_prev_tx_dequeue_pullup();
 
     ble_att_read_type_rsp_parse(om->om_data, om->om_len, &rsp);
 
@@ -738,13 +735,15 @@ ble_att_svr_test_misc_verify_tx_prep_write_rsp(struct ble_l2cap_chan *chan,
                                                void *data, int data_len)
 {
     struct ble_att_prep_write_cmd rsp;
+    struct os_mbuf *om;
     uint8_t buf[1024];
     int rc;
 
     ble_hs_test_util_tx_all();
 
-    rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, 0,
-                          OS_MBUF_PKTLEN(ble_hs_test_util_prev_tx), buf);
+    om = ble_hs_test_util_prev_tx_dequeue();
+
+    rc = os_mbuf_copydata(om, 0, OS_MBUF_PKTLEN(om), buf);
     TEST_ASSERT_FATAL(rc == 0);
 
     ble_att_prep_write_rsp_parse(buf, sizeof buf, &rsp);
@@ -754,7 +753,7 @@ ble_att_svr_test_misc_verify_tx_prep_write_rsp(struct ble_l2cap_chan *chan,
     TEST_ASSERT(memcmp(buf + BLE_ATT_PREP_WRITE_CMD_BASE_SZ, data,
                        data_len) == 0);
 
-    TEST_ASSERT(OS_MBUF_PKTLEN(ble_hs_test_util_prev_tx) ==
+    TEST_ASSERT(OS_MBUF_PKTLEN(om) ==
                 BLE_ATT_PREP_WRITE_CMD_BASE_SZ + data_len);
 }
 
@@ -765,9 +764,7 @@ ble_att_svr_test_misc_verify_tx_exec_write_rsp(struct ble_l2cap_chan *chan)
 
     ble_hs_test_util_tx_all();
 
-    om = os_mbuf_pullup(ble_hs_test_util_prev_tx, BLE_ATT_EXEC_WRITE_RSP_SZ);
-    TEST_ASSERT_FATAL(om != NULL);
-
+    om = ble_hs_test_util_prev_tx_dequeue_pullup();
     ble_att_exec_write_rsp_parse(om->om_data, om->om_len);
 }
 
@@ -934,8 +931,7 @@ ble_att_svr_test_misc_verify_tx_indicate_rsp(struct ble_l2cap_chan *chan)
 
     ble_hs_test_util_tx_all();
 
-    om = os_mbuf_pullup(ble_hs_test_util_prev_tx, BLE_ATT_INDICATE_RSP_SZ);
-    TEST_ASSERT_FATAL(om != NULL);
+    om = ble_hs_test_util_prev_tx_dequeue_pullup();
 
     ble_att_indicate_rsp_parse(om->om_data, om->om_len);
 }
@@ -988,13 +984,14 @@ ble_att_svr_test_misc_verify_indicate(struct ble_hs_conn *conn,
         TEST_ASSERT(ble_att_svr_test_n_attr_handle == attr_handle);
         TEST_ASSERT(ble_att_svr_test_attr_n_len == attr_len);
         TEST_ASSERT(memcmp(ble_att_svr_test_attr_n, attr_val, attr_len) == 0);
+        ble_att_svr_test_misc_verify_tx_indicate_rsp(chan);
     } else {
         TEST_ASSERT(ble_att_svr_test_n_conn_handle == 0xffff);
         TEST_ASSERT(ble_att_svr_test_n_attr_handle == 0);
         TEST_ASSERT(ble_att_svr_test_attr_n_len == 0);
+        ble_hs_test_util_tx_all();
+        TEST_ASSERT(ble_hs_test_util_prev_tx_queue_sz() == 0);
     }
-
-    ble_att_svr_test_misc_verify_tx_indicate_rsp(chan);
 }
 
 TEST_CASE(ble_att_svr_test_mtu)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/65d9dc46/net/nimble/host/src/test/ble_gatt_find_s_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_gatt_find_s_test.c b/net/nimble/host/src/test/ble_gatt_find_s_test.c
index 24b2dcc..6b360c6 100644
--- a/net/nimble/host/src/test/ble_gatt_find_s_test.c
+++ b/net/nimble/host/src/test/ble_gatt_find_s_test.c
@@ -152,10 +152,7 @@ ble_gatt_find_s_test_misc_verify_tx_read_type(uint16_t start_handle,
 
     ble_hs_test_util_tx_all();
 
-    TEST_ASSERT_FATAL(ble_hs_test_util_prev_tx != NULL);
-
-    om = os_mbuf_pullup(ble_hs_test_util_prev_tx,
-                        OS_MBUF_PKTLEN(ble_hs_test_util_prev_tx));
+    om = ble_hs_test_util_prev_tx_dequeue_pullup();
     TEST_ASSERT_FATAL(om != NULL);
 
     ble_att_read_type_req_parse(om->om_data, om->om_len, &req);
@@ -175,10 +172,7 @@ ble_gatt_find_s_test_misc_verify_tx_read(uint16_t handle)
 
     ble_hs_test_util_tx_all();
 
-    TEST_ASSERT_FATAL(ble_hs_test_util_prev_tx != NULL);
-
-    om = os_mbuf_pullup(ble_hs_test_util_prev_tx,
-                        OS_MBUF_PKTLEN(ble_hs_test_util_prev_tx));
+    om = ble_hs_test_util_prev_tx_dequeue_pullup();
     TEST_ASSERT_FATAL(om != NULL);
 
     ble_att_read_req_parse(om->om_data, om->om_len, &req);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/65d9dc46/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 a1b9e57..b0e079b 100644
--- a/net/nimble/host/src/test/ble_gatts_notify_test.c
+++ b/net/nimble/host/src/test/ble_gatts_notify_test.c
@@ -178,22 +178,20 @@ static void
 ble_gatts_notify_test_misc_verify_tx_n(struct ble_l2cap_chan *chan,
                                        uint8_t *attr_data, int attr_len)
 {
-    uint8_t buf[1024];
     struct ble_att_notify_req req;
-    int req_len;
-    int rc;
+    struct os_mbuf *om;
     int i;
 
     ble_hs_test_util_tx_all();
 
-    req_len = OS_MBUF_PKTLEN(ble_hs_test_util_prev_tx);
-    rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, 0, req_len, buf);
-    TEST_ASSERT_FATAL(rc == 0);
+    om = ble_hs_test_util_prev_tx_dequeue_pullup();
+    TEST_ASSERT_FATAL(om != NULL);
 
-    ble_att_notify_req_parse(buf, req_len, &req);
+    ble_att_notify_req_parse(om->om_data, om->om_len, &req);
 
     for (i = 0; i < attr_len; i++) {
-        TEST_ASSERT(buf[BLE_ATT_NOTIFY_REQ_BASE_SZ + i] == attr_data[i]);
+        TEST_ASSERT(om->om_data[BLE_ATT_NOTIFY_REQ_BASE_SZ + i] ==
+                    attr_data[i]);
     }
 }
 
@@ -201,22 +199,20 @@ static void
 ble_gatts_notify_test_misc_verify_tx_i(struct ble_l2cap_chan *chan,
                                        uint8_t *attr_data, int attr_len)
 {
-    uint8_t buf[1024];
     struct ble_att_indicate_req req;
-    int req_len;
-    int rc;
+    struct os_mbuf *om;
     int i;
 
     ble_hs_test_util_tx_all();
 
-    req_len = OS_MBUF_PKTLEN(ble_hs_test_util_prev_tx);
-    rc = os_mbuf_copydata(ble_hs_test_util_prev_tx, 0, req_len, buf);
-    TEST_ASSERT_FATAL(rc == 0);
+    om = ble_hs_test_util_prev_tx_dequeue_pullup();
+    TEST_ASSERT_FATAL(om != NULL);
 
-    ble_att_indicate_req_parse(buf, req_len, &req);
+    ble_att_indicate_req_parse(om->om_data, om->om_len, &req);
 
     for (i = 0; i < attr_len; i++) {
-        TEST_ASSERT(buf[BLE_ATT_INDICATE_REQ_BASE_SZ + i] == attr_data[i]);
+        TEST_ASSERT(om->om_data[BLE_ATT_INDICATE_REQ_BASE_SZ + i] ==
+                    attr_data[i]);
     }
 }
 
@@ -272,6 +268,11 @@ TEST_CASE(ble_gatts_notify_test_i)
         conn, chan, ble_gatts_notify_test_chr_2_def_handle,
         BLE_GATTS_CLT_CFG_F_INDICATE);
 
+    /* Toss both write responses. */
+    ble_hs_test_util_tx_all();
+    ble_hs_test_util_prev_tx_dequeue();
+    ble_hs_test_util_prev_tx_dequeue();
+
     /* Update characteristic 1's value. */
     ble_gatts_notify_test_chr_1_len = 1;
     ble_gatts_notify_test_chr_1_val[0] = 0xab;
@@ -283,9 +284,6 @@ TEST_CASE(ble_gatts_notify_test_i)
         ble_gatts_notify_test_chr_1_val,
         ble_gatts_notify_test_chr_1_len);
 
-    os_mbuf_free_chain(ble_hs_test_util_prev_tx);
-    ble_hs_test_util_prev_tx = NULL;
-
     /* Update characteristic 2's value. */
     ble_gatts_notify_test_chr_2_len = 16;
     memcpy(ble_gatts_notify_test_chr_2_val,
@@ -295,12 +293,14 @@ TEST_CASE(ble_gatts_notify_test_i)
     /* Verify the second indication doesn't get sent until the first is
      * confirmed.
      */
-    TEST_ASSERT(ble_hs_test_util_prev_tx == NULL);
+    ble_hs_test_util_tx_all();
+    TEST_ASSERT(ble_hs_test_util_prev_tx_queue_sz() == 0);
 
     /* Receive the confirmation for the first indication. */
     ble_gatts_notify_test_misc_rx_indicate_rsp(conn, chan);
 
     /* Verify indication sent properly. */
+    ble_hs_test_util_tx_all();
     ble_gatts_notify_test_misc_verify_tx_i(
         chan,
         ble_gatts_notify_test_chr_2_val,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/65d9dc46/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 183774e..aaaf19f 100644
--- a/net/nimble/host/src/test/ble_hs_test.c
+++ b/net/nimble/host/src/test/ble_hs_test.c
@@ -29,11 +29,9 @@ uint8_t g_dev_addr[BLE_DEV_ADDR_LEN];
 void
 ble_hs_test_pkt_txed(struct os_mbuf *om)
 {
-    os_mbuf_free_chain(ble_hs_test_util_prev_tx);
-    ble_hs_test_util_prev_tx = om;
-
     /* XXX: For now, just strip the HCI ACL data and L2CAP headers. */
     os_mbuf_adj(om, BLE_HCI_DATA_HDR_SZ + BLE_L2CAP_HDR_SZ);
+    ble_hs_test_util_prev_tx_enqueue(om);
 }
 
 void

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/65d9dc46/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 d8c9dab..87774cb 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -43,15 +43,79 @@ os_membuf_t ble_hs_test_util_mbuf_mpool_data[BLE_HS_TEST_UTIL_MEMPOOL_SIZE];
 struct os_mbuf_pool ble_hs_test_util_mbuf_pool;
 struct os_mempool ble_hs_test_util_mbuf_mpool;
 
-struct os_mbuf *ble_hs_test_util_prev_tx;
+static STAILQ_HEAD(, os_mbuf_pkthdr) ble_hs_test_util_prev_tx_queue;
+struct os_mbuf *ble_hs_test_util_prev_tx_cur;
 
-#define BLE_HS_TEST_UTIL_MAX_PREV_HCI_TXES      64
+#define BLE_HS_TEST_UTIL_PREV_HCI_TX_CNT      64
 static uint8_t
-ble_hs_test_util_prev_hci_tx[BLE_HS_TEST_UTIL_MAX_PREV_HCI_TXES][260];
+ble_hs_test_util_prev_hci_tx[BLE_HS_TEST_UTIL_PREV_HCI_TX_CNT][260];
 int ble_hs_test_util_num_prev_hci_txes;
 
 uint8_t ble_hs_test_util_cur_hci_tx[260];
 
+void
+ble_hs_test_util_prev_tx_enqueue(struct os_mbuf *om)
+{
+    struct os_mbuf_pkthdr *omp;
+
+    assert(OS_MBUF_IS_PKTHDR(om));
+
+    omp = OS_MBUF_PKTHDR(om);
+    if (STAILQ_EMPTY(&ble_hs_test_util_prev_tx_queue)) {
+        STAILQ_INSERT_HEAD(&ble_hs_test_util_prev_tx_queue, omp, omp_next);
+    } else {
+        STAILQ_INSERT_TAIL(&ble_hs_test_util_prev_tx_queue, omp, omp_next);
+    }
+}
+
+struct os_mbuf *
+ble_hs_test_util_prev_tx_dequeue(void)
+{
+    struct os_mbuf_pkthdr *omp;
+
+    os_mbuf_free_chain(ble_hs_test_util_prev_tx_cur);
+
+    omp = STAILQ_LAST(&ble_hs_test_util_prev_tx_queue, os_mbuf_pkthdr,
+                      omp_next);
+    if (omp != NULL) {
+        STAILQ_REMOVE(&ble_hs_test_util_prev_tx_queue, omp, os_mbuf_pkthdr,
+                      omp_next);
+        ble_hs_test_util_prev_tx_cur = OS_MBUF_PKTHDR_TO_MBUF(omp);
+    } else {
+        ble_hs_test_util_prev_tx_cur = NULL;
+    }
+    return ble_hs_test_util_prev_tx_cur;
+}
+
+struct os_mbuf *
+ble_hs_test_util_prev_tx_dequeue_pullup(void)
+{
+    struct os_mbuf *om;
+
+    om = ble_hs_test_util_prev_tx_dequeue();
+    if (om != NULL) {
+        om = os_mbuf_pullup(om, OS_MBUF_PKTLEN(om));
+        TEST_ASSERT_FATAL(om != NULL);
+        ble_hs_test_util_prev_tx_cur = om;
+    }
+
+    return om;
+}
+
+int
+ble_hs_test_util_prev_tx_queue_sz(void)
+{
+    struct os_mbuf_pkthdr *omp;
+    int cnt;
+
+    cnt = 0;
+    STAILQ_FOREACH(omp, &ble_hs_test_util_prev_tx_queue, omp_next) {
+        cnt++;
+    }
+
+    return cnt;
+}
+
 void *
 ble_hs_test_util_get_first_hci_tx(void)
 {
@@ -92,7 +156,7 @@ void
 ble_hs_test_util_enqueue_hci_tx(void *cmd)
 {
     TEST_ASSERT_FATAL(ble_hs_test_util_num_prev_hci_txes <
-                      BLE_HS_TEST_UTIL_MAX_PREV_HCI_TXES);
+                      BLE_HS_TEST_UTIL_PREV_HCI_TX_CNT);
     memcpy(ble_hs_test_util_prev_hci_tx + ble_hs_test_util_num_prev_hci_txes,
            cmd, 260);
 
@@ -644,6 +708,8 @@ ble_hs_test_util_init(void)
     tu_init();
 
     os_eventq_init(&ble_hs_test_util_evq);
+    STAILQ_INIT(&ble_hs_test_util_prev_tx_queue);
+    ble_hs_test_util_prev_tx_cur = NULL;
 
     os_msys_reset();
     stats_module_reset();
@@ -674,6 +740,5 @@ ble_hs_test_util_init(void)
     /* Don't limit a connection's ability to transmit; simplify tests. */
     ble_hs_cfg.max_outstanding_pkts_per_conn = 0;
 
-    ble_hs_test_util_prev_tx = NULL;
     ble_hs_test_util_prev_hci_tx_clear();
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/65d9dc46/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 aea5f08..0dc5caf 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.h
+++ b/net/nimble/host/src/test/ble_hs_test_util.h
@@ -27,13 +27,17 @@ struct ble_hs_conn;
 struct ble_l2cap_chan;
 
 struct os_eventq ble_hs_test_util_evq;
-extern struct os_mbuf *ble_hs_test_util_prev_tx;
 
 struct ble_hs_test_util_num_completed_pkts_entry {
     uint16_t handle_id; /* 0 for terminating entry in array. */
     uint16_t num_pkts;
 };
 
+void ble_hs_test_util_prev_tx_enqueue(struct os_mbuf *om);
+struct os_mbuf *ble_hs_test_util_prev_tx_dequeue(void);
+struct os_mbuf *ble_hs_test_util_prev_tx_dequeue_pullup(void);
+int ble_hs_test_util_prev_tx_queue_sz(void);
+
 void ble_hs_test_util_set_ack_params(uint16_t opcode, uint8_t status,
                                      void *params, uint8_t params_len);
 void ble_hs_test_util_set_ack(uint16_t opcode, uint8_t status);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/65d9dc46/net/nimble/host/src/test/ble_l2cap_sm_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_l2cap_sm_test.c b/net/nimble/host/src/test/ble_l2cap_sm_test.c
index ad39ab0..a0a2f19 100644
--- a/net/nimble/host/src/test/ble_l2cap_sm_test.c
+++ b/net/nimble/host/src/test/ble_l2cap_sm_test.c
@@ -211,17 +211,21 @@ ble_l2cap_sm_test_util_rx_random(struct ble_hs_conn *conn,
     TEST_ASSERT_FATAL(rc == exp_status);
 }
 
-static void
+static struct os_mbuf *
 ble_l2cap_sm_test_util_verify_tx_hdr(uint8_t sm_op, uint16_t payload_len)
 {
-    TEST_ASSERT_FATAL(ble_hs_test_util_prev_tx != NULL);
-    TEST_ASSERT(OS_MBUF_PKTLEN(ble_hs_test_util_prev_tx) ==
-                BLE_L2CAP_SM_HDR_SZ + payload_len);
+    struct os_mbuf *om;
+
+    om = ble_hs_test_util_prev_tx_dequeue();
+    TEST_ASSERT_FATAL(om != NULL);
 
-    TEST_ASSERT_FATAL(ble_hs_test_util_prev_tx->om_data[0] == sm_op);
+    TEST_ASSERT(OS_MBUF_PKTLEN(om) == BLE_L2CAP_SM_HDR_SZ + payload_len);
+    TEST_ASSERT_FATAL(om->om_data[0] == sm_op);
 
-    ble_hs_test_util_prev_tx->om_data += BLE_L2CAP_SM_HDR_SZ;
-    ble_hs_test_util_prev_tx->om_len -= BLE_L2CAP_SM_HDR_SZ;
+    om->om_data += BLE_L2CAP_SM_HDR_SZ;
+    om->om_len -= BLE_L2CAP_SM_HDR_SZ;
+
+    return om;
 }
 
 static void
@@ -230,12 +234,10 @@ ble_l2cap_sm_test_util_verify_tx_pair_cmd(
     struct ble_l2cap_sm_pair_cmd *exp_cmd)
 {
     struct ble_l2cap_sm_pair_cmd cmd;
+    struct os_mbuf *om;
 
-    ble_l2cap_sm_test_util_verify_tx_hdr(op, BLE_L2CAP_SM_PAIR_CMD_SZ);
-
-    ble_l2cap_sm_pair_cmd_parse(ble_hs_test_util_prev_tx->om_data,
-                                ble_hs_test_util_prev_tx->om_len,
-                                &cmd);
+    om = ble_l2cap_sm_test_util_verify_tx_hdr(op, BLE_L2CAP_SM_PAIR_CMD_SZ);
+    ble_l2cap_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);
@@ -266,13 +268,11 @@ ble_l2cap_sm_test_util_verify_tx_pair_confirm(
     struct ble_l2cap_sm_pair_confirm *exp_cmd)
 {
     struct ble_l2cap_sm_pair_confirm cmd;
+    struct os_mbuf *om;
 
-    ble_l2cap_sm_test_util_verify_tx_hdr(BLE_L2CAP_SM_OP_PAIR_CONFIRM,
-                                         BLE_L2CAP_SM_PAIR_CONFIRM_SZ);
-
-    ble_l2cap_sm_pair_confirm_parse(ble_hs_test_util_prev_tx->om_data,
-                                    ble_hs_test_util_prev_tx->om_len,
-                                    &cmd);
+    om = ble_l2cap_sm_test_util_verify_tx_hdr(BLE_L2CAP_SM_OP_PAIR_CONFIRM,
+                                              BLE_L2CAP_SM_PAIR_CONFIRM_SZ);
+    ble_l2cap_sm_pair_confirm_parse(om->om_data, om->om_len, &cmd);
 
     TEST_ASSERT(memcmp(cmd.value, exp_cmd->value, 16) == 0);
 }
@@ -282,13 +282,11 @@ ble_l2cap_sm_test_util_verify_tx_pair_random(
     struct ble_l2cap_sm_pair_random *exp_cmd)
 {
     struct ble_l2cap_sm_pair_random cmd;
+    struct os_mbuf *om;
 
-    ble_l2cap_sm_test_util_verify_tx_hdr(BLE_L2CAP_SM_OP_PAIR_RANDOM,
-                                         BLE_L2CAP_SM_PAIR_RANDOM_SZ);
-
-    ble_l2cap_sm_pair_random_parse(ble_hs_test_util_prev_tx->om_data,
-                                   ble_hs_test_util_prev_tx->om_len,
-                                   &cmd);
+    om = ble_l2cap_sm_test_util_verify_tx_hdr(BLE_L2CAP_SM_OP_PAIR_RANDOM,
+                                              BLE_L2CAP_SM_PAIR_RANDOM_SZ);
+    ble_l2cap_sm_pair_random_parse(om->om_data, om->om_len, &cmd);
 
     TEST_ASSERT(memcmp(cmd.value, exp_cmd->value, 16) == 0);
 }
@@ -298,13 +296,11 @@ ble_l2cap_sm_test_util_verify_tx_pair_fail(
     struct ble_l2cap_sm_pair_fail *exp_cmd)
 {
     struct ble_l2cap_sm_pair_fail cmd;
+    struct os_mbuf *om;
 
-    ble_l2cap_sm_test_util_verify_tx_hdr(BLE_L2CAP_SM_OP_PAIR_FAIL,
-                                         BLE_L2CAP_SM_PAIR_FAIL_SZ);
-
-    ble_l2cap_sm_pair_fail_parse(ble_hs_test_util_prev_tx->om_data,
-                                 ble_hs_test_util_prev_tx->om_len,
-                                 &cmd);
+    om = ble_l2cap_sm_test_util_verify_tx_hdr(BLE_L2CAP_SM_OP_PAIR_FAIL,
+                                              BLE_L2CAP_SM_PAIR_FAIL_SZ);
+    ble_l2cap_sm_pair_fail_parse(om->om_data, om->om_len, &cmd);
 
     TEST_ASSERT(cmd.reason == exp_cmd->reason);
 }
@@ -1337,6 +1333,8 @@ ble_l2cap_sm_test_util_us_lgcy_good(
     TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
 
+    /* Ensure keys are distributed, if necessary. */
+
     /* Ensure we sent the expected start encryption command. */
     ble_hs_test_util_tx_all();
     ble_l2cap_sm_test_util_verify_tx_start_enc(2, r, ediv, stk);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/65d9dc46/net/nimble/host/src/test/ble_l2cap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_l2cap_test.c b/net/nimble/host/src/test/ble_l2cap_test.c
index 9cde642..0229a54 100644
--- a/net/nimble/host/src/test/ble_l2cap_test.c
+++ b/net/nimble/host/src/test/ble_l2cap_test.c
@@ -106,6 +106,36 @@ ble_l2cap_test_util_rx_update_rsp(struct ble_hs_conn *conn,
     return rc;
 }
 
+
+static struct os_mbuf *
+ble_l2cap_test_util_verify_tx_sig_hdr(uint8_t op, uint8_t id,
+                                      uint16_t payload_len,
+                                      struct ble_l2cap_sig_hdr *out_hdr)
+{
+    struct ble_l2cap_sig_hdr hdr;
+    struct os_mbuf *om;
+
+    om = ble_hs_test_util_prev_tx_dequeue();
+    TEST_ASSERT_FATAL(om != NULL);
+
+    TEST_ASSERT(OS_MBUF_PKTLEN(om) == BLE_L2CAP_SIG_HDR_SZ + payload_len);
+    ble_l2cap_sig_hdr_parse(om->om_data, om->om_len, &hdr);
+    TEST_ASSERT(hdr.op == op);
+    if (id != 0) {
+        TEST_ASSERT(hdr.identifier == id);
+    }
+    TEST_ASSERT(hdr.length == payload_len);
+
+    om->om_data += BLE_L2CAP_SIG_HDR_SZ;
+    om->om_len -= BLE_L2CAP_SIG_HDR_SZ;
+
+    if (out_hdr != NULL) {
+        *out_hdr = hdr;
+    }
+
+    return om;
+}
+
 /**
  * @return                      The L2CAP sig identifier in the request.
  */
@@ -115,21 +145,14 @@ ble_l2cap_test_util_verify_tx_update_req(
 {
     struct ble_l2cap_sig_update_req req;
     struct ble_l2cap_sig_hdr hdr;
+    struct os_mbuf *om;
 
-    TEST_ASSERT_FATAL(ble_hs_test_util_prev_tx != NULL);
-    TEST_ASSERT(OS_MBUF_PKTLEN(ble_hs_test_util_prev_tx) ==
-                BLE_L2CAP_SIG_HDR_SZ + BLE_L2CAP_SIG_UPDATE_REQ_SZ);
-    ble_l2cap_sig_hdr_parse(ble_hs_test_util_prev_tx->om_data,
-                            ble_hs_test_util_prev_tx->om_len, &hdr);
-
-    ble_hs_test_util_prev_tx->om_data += BLE_L2CAP_SIG_HDR_SZ;
-    ble_hs_test_util_prev_tx->om_len -= BLE_L2CAP_SIG_HDR_SZ;
+    om = ble_l2cap_test_util_verify_tx_sig_hdr(BLE_L2CAP_SIG_OP_UPDATE_REQ, 0,
+                                               BLE_L2CAP_SIG_UPDATE_REQ_SZ,
+                                               &hdr);
 
-    ble_l2cap_sig_update_req_parse(ble_hs_test_util_prev_tx->om_data,
-                                   ble_hs_test_util_prev_tx->om_len,
-                                   &req);
-    TEST_ASSERT(hdr.op == BLE_L2CAP_SIG_OP_UPDATE_REQ);
-    TEST_ASSERT(hdr.length == BLE_L2CAP_SIG_UPDATE_REQ_SZ);
+    /* Verify payload. */
+    ble_l2cap_sig_update_req_parse(om->om_data, om->om_len, &req);
     TEST_ASSERT(req.itvl_min == params->itvl_min);
     TEST_ASSERT(req.itvl_max == params->itvl_max);
     TEST_ASSERT(req.slave_latency == params->slave_latency);
@@ -142,23 +165,14 @@ static void
 ble_l2cap_test_util_verify_tx_update_rsp(uint8_t exp_id, uint16_t exp_result)
 {
     struct ble_l2cap_sig_update_rsp rsp;
-    struct ble_l2cap_sig_hdr hdr;
+    struct os_mbuf *om;
+
+    om = ble_l2cap_test_util_verify_tx_sig_hdr(BLE_L2CAP_SIG_OP_UPDATE_RSP,
+                                               exp_id,
+                                               BLE_L2CAP_SIG_UPDATE_RSP_SZ,
+                                               NULL);
 
-    TEST_ASSERT_FATAL(ble_hs_test_util_prev_tx != NULL);
-    TEST_ASSERT(OS_MBUF_PKTLEN(ble_hs_test_util_prev_tx) ==
-                BLE_L2CAP_SIG_HDR_SZ + BLE_L2CAP_SIG_UPDATE_RSP_SZ);
-    ble_l2cap_sig_hdr_parse(ble_hs_test_util_prev_tx->om_data,
-                            ble_hs_test_util_prev_tx->om_len, &hdr);
-
-    ble_hs_test_util_prev_tx->om_data += BLE_L2CAP_SIG_HDR_SZ;
-    ble_hs_test_util_prev_tx->om_len -= BLE_L2CAP_SIG_HDR_SZ;
-
-    ble_l2cap_sig_update_rsp_parse(ble_hs_test_util_prev_tx->om_data,
-                                   ble_hs_test_util_prev_tx->om_len,
-                                   &rsp);
-    TEST_ASSERT(hdr.op == BLE_L2CAP_SIG_OP_UPDATE_RSP);
-    TEST_ASSERT(hdr.identifier == exp_id);
-    TEST_ASSERT(hdr.length == BLE_L2CAP_SIG_UPDATE_RSP_SZ);
+    ble_l2cap_sig_update_rsp_parse(om->om_data, om->om_len, &rsp);
     TEST_ASSERT(rsp.result == exp_result);
 }
 
@@ -424,7 +438,7 @@ TEST_CASE(ble_l2cap_test_case_sig_unsol_rsp)
 
     /* Ensure we did not send anything in return. */
     ble_hs_test_util_tx_all();
-    TEST_ASSERT_FATAL(ble_hs_test_util_prev_tx == NULL);
+    TEST_ASSERT_FATAL(ble_hs_test_util_prev_tx_dequeue() == NULL);
 }
 
 /*****************************************************************************


[2/3] incubator-mynewt-core git commit: BLE Host - SM passkey unit tests.

Posted by cc...@apache.org.
BLE Host - SM passkey 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/ffd58caf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ffd58caf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ffd58caf

Branch: refs/heads/develop
Commit: ffd58caf2f6c61ff7ed6b3146ff8902261fc9237
Parents: 65d9dc4
Author: Christopher Collins <cc...@apache.org>
Authored: Wed May 11 20:36:01 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed May 11 20:36:01 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/include/host/ble_gap.h       |   2 +-
 net/nimble/host/src/ble_hci_cmd.c            |   2 +
 net/nimble/host/src/ble_l2cap_sm.c           |  60 ++-
 net/nimble/host/src/ble_l2cap_sm_priv.h      |   1 +
 net/nimble/host/src/test/ble_l2cap_sm_test.c | 522 ++++++++++++++--------
 5 files changed, 376 insertions(+), 211 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ffd58caf/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 6cbe2b4..ef9a478 100644
--- a/net/nimble/host/include/host/ble_gap.h
+++ b/net/nimble/host/include/host/ble_gap.h
@@ -175,7 +175,7 @@ struct ble_gap_ltk_params {
 #define BLE_GAP_PKACT_DISP          3
 
 struct ble_gap_passkey_action {
-    uint8_t  action;
+    uint8_t action;
 };
 
 struct ble_gap_conn_ctxt {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ffd58caf/net/nimble/host/src/ble_hci_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hci_cmd.c b/net/nimble/host/src/ble_hci_cmd.c
index f47e9f2..8580673 100644
--- a/net/nimble/host/src/ble_hci_cmd.c
+++ b/net/nimble/host/src/ble_hci_cmd.c
@@ -290,4 +290,6 @@ ble_hci_cmd_init(void)
 
     rc = os_mutex_init(&ble_hci_cmd_mutex);
     BLE_HS_DBG_ASSERT_EVAL(rc == 0);
+
+    ble_hci_cmd_ack_ev = NULL;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ffd58caf/net/nimble/host/src/ble_l2cap_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sm.c b/net/nimble/host/src/ble_l2cap_sm.c
index 551cc3b..fd9ba5d 100644
--- a/net/nimble/host/src/ble_l2cap_sm.c
+++ b/net/nimble/host/src/ble_l2cap_sm.c
@@ -197,6 +197,7 @@ ble_l2cap_sm_dbg_num_procs(void)
 
     cnt = 0;
     STAILQ_FOREACH(proc, &ble_l2cap_sm_procs, next) {
+        BLE_HS_DBG_ASSERT(cnt < ble_hs_cfg.max_l2cap_sm_procs);
         cnt++;
     }
 
@@ -205,6 +206,14 @@ ble_l2cap_sm_dbg_num_procs(void)
 
 #endif
 
+static void
+ble_l2cap_sm_dbg_assert_no_cycles(void)
+{
+#if BLE_HS_DEBUG
+    ble_l2cap_sm_dbg_num_procs();
+#endif
+}
+
 /*****************************************************************************
  * $misc                                                                     *
  *****************************************************************************/
@@ -371,6 +380,8 @@ ble_l2cap_sm_proc_remove(struct ble_l2cap_sm_proc *proc,
         BLE_HS_DBG_ASSERT(STAILQ_NEXT(prev, next) == proc);
         STAILQ_REMOVE_AFTER(&ble_l2cap_sm_procs, prev, next);
     }
+
+    ble_l2cap_sm_dbg_assert_no_cycles();
 }
 
 static void
@@ -467,6 +478,20 @@ ble_l2cap_sm_proc_find(uint16_t conn_handle, uint8_t state, int is_initiator,
 }
 
 static void
+ble_l2cap_sm_insert(struct ble_l2cap_sm_proc *proc)
+{
+#ifdef BLE_HS_DEBUG
+    struct ble_l2cap_sm_proc *cur;
+
+    STAILQ_FOREACH(cur, &ble_l2cap_sm_procs, next) {
+        BLE_HS_DBG_ASSERT(cur != proc);
+    }
+#endif
+
+    STAILQ_INSERT_HEAD(&ble_l2cap_sm_procs, proc, next);
+}
+
+static void
 ble_l2cap_sm_extract_expired(struct ble_l2cap_sm_proc_list *dst_list)
 {
     struct ble_l2cap_sm_proc *proc;
@@ -499,6 +524,8 @@ ble_l2cap_sm_extract_expired(struct ble_l2cap_sm_proc_list *dst_list)
         proc = next;
     }
 
+    ble_l2cap_sm_dbg_assert_no_cycles();
+
     ble_hs_unlock();
 }
 
@@ -1375,7 +1402,7 @@ ble_l2cap_sm_rx_pair_req(uint16_t conn_handle, uint8_t op,
         rc = ble_l2cap_sm_pair_req_handle(proc, &req, &sm_status,
                                           &passkey_action);
         if (rc == 0) {
-            STAILQ_INSERT_HEAD(&ble_l2cap_sm_procs, proc, next);
+            ble_l2cap_sm_insert(proc);
         }
     }
 
@@ -1639,7 +1666,7 @@ ble_l2cap_sm_rx_lt_key_req(struct hci_le_lt_key_req *evt)
         if (proc != NULL) {
             proc->conn_handle = evt->connection_handle;
             proc->state = BLE_L2CAP_SM_PROC_STATE_LTK;
-            STAILQ_INSERT_HEAD(&ble_l2cap_sm_procs, proc, next);
+            ble_l2cap_sm_insert(proc);
         }
     } else if (proc->state == BLE_L2CAP_SM_PROC_STATE_LTK) {
         /* Short-term key pairing just completed.  Send the short term key to
@@ -1685,36 +1712,39 @@ ble_l2cap_sm_rx_encryption_change(struct hci_encrypt_change *evt)
     struct ble_l2cap_sm_proc *prev;
     int enc_enabled = 0;
     int do_key_exchange = 0;
-    int rc = 0;
+    int rc;
     uint8_t sm_status = BLE_L2CAP_SM_ERR_UNSPECIFIED;
+    int complete;
 
     ble_hs_lock();
     proc = ble_l2cap_sm_proc_find(evt->connection_handle,
                                   BLE_L2CAP_SM_PROC_STATE_ENC_CHANGE, -1,
                                   &prev);
-
-    if (proc != NULL) {
+    if (proc == NULL) {
+        rc = BLE_HS_ENOENT;
+    } else {
         enc_enabled = evt->encryption_enabled & 0x01; /* LE bit. */
         do_key_exchange = (proc->flags & BLE_L2CAP_SM_PROC_F_KEY_EXCHANGE);
+        rc = 0;
     }
 
-    /* do we do a key exchange. Must be secure also */
     if (do_key_exchange && enc_enabled) {
         proc->state = BLE_L2CAP_SM_PROC_STATE_KEY_EXCH;
-        /* the slave starts first */
+
+        /* The responder sends its keys first. */
         if (!(proc->flags & BLE_L2CAP_SM_PROC_F_INITIATOR)) {
             rc = ble_l2cap_sm_key_exchange_go(proc, &sm_status);
         }
-    } else {
-        if (proc != NULL) {
-            ble_l2cap_sm_proc_remove(proc, prev);
-        }
+    }
+
+    complete = proc != NULL && (rc != 0 || !do_key_exchange || !enc_enabled);
+    if (complete) {
+        ble_l2cap_sm_proc_remove(proc, prev);
     }
 
     ble_hs_unlock();
 
-    if (rc != 0 || (proc != NULL && do_key_exchange == 0)) {
-        /* The pairing procedure is now complete. */
+    if (complete) {
         ble_l2cap_sm_gap_event(proc, BLE_HS_HCI_ERR(evt->status), enc_enabled);
         ble_l2cap_sm_proc_free(proc);
     }
@@ -1808,7 +1838,7 @@ ble_l2cap_sm_initiate(uint16_t conn_handle)
         goto done;
     }
 
-    STAILQ_INSERT_HEAD(&ble_l2cap_sm_procs, proc, next);
+    ble_l2cap_sm_insert(proc);
 
 done:
     ble_hs_unlock();
@@ -1856,7 +1886,7 @@ ble_l2cap_sm_sec_initiate(uint16_t conn_handle,
         goto sec_initiate_done;
     }
 
-    STAILQ_INSERT_HEAD(&ble_l2cap_sm_procs, proc, next);
+    ble_l2cap_sm_insert(proc);
 
 sec_initiate_done:
     ble_hs_unlock();

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ffd58caf/net/nimble/host/src/ble_l2cap_sm_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sm_priv.h b/net/nimble/host/src/ble_l2cap_sm_priv.h
index 2e3b98b..0ed311d 100644
--- a/net/nimble/host/src/ble_l2cap_sm_priv.h
+++ b/net/nimble/host/src/ble_l2cap_sm_priv.h
@@ -148,6 +148,7 @@ struct ble_l2cap_sm_signing_info {
 void ble_l2cap_sm_dbg_set_next_pair_rand(uint8_t *next_pair_rand);
 void ble_l2cap_sm_dbg_set_next_ediv(uint16_t next_ediv);
 void ble_l2cap_sm_dbg_set_next_start_rand(uint64_t next_start_rand);
+void ble_l2cap_sm_dbg_set_next_ltk(uint8_t *next_ltk);
 int ble_l2cap_sm_dbg_num_procs(void);
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ffd58caf/net/nimble/host/src/test/ble_l2cap_sm_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_l2cap_sm_test.c b/net/nimble/host/src/test/ble_l2cap_sm_test.c
index a0a2f19..f5553f1 100644
--- a/net/nimble/host/src/test/ble_l2cap_sm_test.c
+++ b/net/nimble/host/src/test/ble_l2cap_sm_test.c
@@ -38,6 +38,35 @@ struct ble_gap_ltk_params ble_l2cap_sm_test_ltk_params;
  * $util                                                                     *
  *****************************************************************************/
 
+struct ble_l2cap_sm_test_pair_params {
+    uint8_t init_addr[6];
+    uint8_t rsp_addr[6];
+    struct ble_l2cap_sm_pair_cmd pair_req;
+    struct ble_l2cap_sm_pair_cmd pair_rsp;
+    struct ble_l2cap_sm_pair_confirm confirm_req;
+    struct ble_l2cap_sm_pair_confirm confirm_rsp;
+    struct ble_l2cap_sm_pair_random random_req;
+    struct ble_l2cap_sm_pair_random random_rsp;
+    struct ble_l2cap_sm_enc_info enc_info_req;
+    struct ble_l2cap_sm_master_iden master_id_req;
+    struct ble_l2cap_sm_enc_info enc_info_rsp;
+    struct ble_l2cap_sm_master_iden master_id_rsp;
+    int pair_alg;
+    unsigned authenticated:1;
+    uint8_t tk[16];
+    uint8_t stk[16];
+    uint64_t r;
+    uint16_t ediv;
+
+    struct passkey_action passkey;
+    struct ble_l2cap_sm_pair_fail pair_fail;
+
+    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_L2CAP_SM_TEST_UTIL_HCI_HDR(handle, pb, len) \
     ((struct hci_data_hdr) {                            \
         .hdh_handle_pb_bc = ((handle)  << 0) |          \
@@ -65,6 +94,7 @@ static int
 ble_l2cap_sm_test_util_conn_cb(int event, int status,
                                struct ble_gap_conn_ctxt *ctxt, void *arg)
 {
+    struct passkey_action *passkey;
     struct ble_l2cap_sm_test_ltk_info *ltk_info;
     int rc;
 
@@ -74,6 +104,13 @@ ble_l2cap_sm_test_util_conn_cb(int event, int status,
         rc = 0;
         break;
 
+    case BLE_GAP_EVENT_PASSKEY_ACTION:
+        passkey = arg;
+        TEST_ASSERT_FATAL(passkey != NULL);
+
+        rc = ble_l2cap_sm_set_tk(ctxt->desc->conn_handle, passkey);
+        break;
+
     case BLE_GAP_EVENT_LTK_REQUEST:
         ltk_info = arg;
         if (ltk_info == NULL) {
@@ -292,6 +329,20 @@ ble_l2cap_sm_test_util_verify_tx_pair_random(
 }
 
 static void
+ble_l2cap_sm_test_util_verify_tx_enc_info(
+    struct ble_l2cap_sm_enc_info *exp_cmd)
+{
+    struct ble_l2cap_sm_enc_info cmd;
+    struct os_mbuf *om;
+
+    om = ble_l2cap_sm_test_util_verify_tx_hdr(BLE_L2CAP_SM_OP_ENC_INFO,
+                                              BLE_L2CAP_SM_ENC_INFO_SZ);
+    ble_l2cap_sm_enc_info_parse(om->om_data, om->om_len, &cmd);
+
+    TEST_ASSERT(memcmp(cmd.ltk_le, exp_cmd->ltk_le, sizeof cmd.ltk_le) == 0);
+}
+
+static void
 ble_l2cap_sm_test_util_verify_tx_pair_fail(
     struct ble_l2cap_sm_pair_fail *exp_cmd)
 {
@@ -734,29 +785,30 @@ TEST_CASE(ble_l2cap_sm_test_case_peer_lgcy_fail_confirm)
 
 static void
 ble_l2cap_sm_test_util_peer_lgcy_good(
-    uint8_t *init_addr,
-    uint8_t *rsp_addr,
-    struct ble_l2cap_sm_pair_cmd *pair_req,
-    struct ble_l2cap_sm_pair_cmd *pair_rsp,
-    struct ble_l2cap_sm_pair_confirm *confirm_req,
-    struct ble_l2cap_sm_pair_confirm *confirm_rsp,
-    struct ble_l2cap_sm_pair_random *random_req,
-    struct ble_l2cap_sm_pair_random *random_rsp,
-    int pair_alg,
-    uint8_t *tk,
-    uint8_t *stk,
-    uint64_t r,
-    uint16_t ediv)
+    struct ble_l2cap_sm_test_pair_params *params)
 {
     struct ble_hs_conn *conn;
 
     ble_l2cap_sm_test_util_init();
-    ble_hs_test_util_set_public_addr(rsp_addr);
-    ble_l2cap_sm_dbg_set_next_pair_rand(random_rsp->value);
 
-    conn = ble_hs_test_util_create_conn(2, init_addr,
+    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_L2CAP_SM_PAIR_AUTHREQ_BOND);
+    ble_hs_cfg.sm_mitm = !!(params->pair_rsp.authreq &
+                            BLE_L2CAP_SM_PAIR_AUTHREQ_MITM);
+    ble_hs_cfg.sm_sc = 0;
+    ble_hs_cfg.sm_keypress = !!(params->pair_rsp.authreq &
+                                BLE_L2CAP_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->rsp_addr);
+    ble_l2cap_sm_dbg_set_next_pair_rand(params->random_rsp.value);
+
+    conn = ble_hs_test_util_create_conn(2, params->init_addr,
                                         ble_l2cap_sm_test_util_conn_cb,
-                                        NULL);
+                                        &params->passkey);
 
     /* Peer is the initiator so we must be the slave. */
     conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
@@ -765,46 +817,46 @@ ble_l2cap_sm_test_util_peer_lgcy_good(
     TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 0);
 
     /* Receive a pair request from the peer. */
-    ble_l2cap_sm_test_util_rx_pair_req(conn, pair_req, 0);
+    ble_l2cap_sm_test_util_rx_pair_req(conn, &params->pair_req, 0);
     TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
 
     /* Ensure we sent the expected pair response. */
     ble_hs_test_util_tx_all();
-    ble_l2cap_sm_test_util_verify_tx_pair_rsp(pair_rsp);
+    ble_l2cap_sm_test_util_verify_tx_pair_rsp(&params->pair_rsp);
     TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
 
     /* Receive a pair confirm from the peer. */
-    ble_l2cap_sm_test_util_rx_confirm(conn, confirm_req);
+    ble_l2cap_sm_test_util_rx_confirm(conn, &params->confirm_req);
     TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
 
     /* Ensure we sent the expected pair confirm. */
     ble_hs_test_util_tx_all();
-    ble_l2cap_sm_test_util_verify_tx_pair_confirm(confirm_rsp);
+    ble_l2cap_sm_test_util_verify_tx_pair_confirm(&params->confirm_rsp);
     TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
 
     /* Receive a pair random from the peer. */
-    ble_l2cap_sm_test_util_rx_random(conn, random_req, 0);
+    ble_l2cap_sm_test_util_rx_random(conn, &params->random_req, 0);
     TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
 
     /* Ensure we sent the expected pair random. */
     ble_hs_test_util_tx_all();
-    ble_l2cap_sm_test_util_verify_tx_pair_random(random_rsp);
+    ble_l2cap_sm_test_util_verify_tx_pair_random(&params->random_rsp);
     TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
 
     /* Receive a long term key request from the controller. */
     ble_l2cap_sm_test_util_set_lt_key_req_reply_ack(0, 2);
-    ble_l2cap_sm_test_util_rx_lt_key_req(2, r, ediv);
+    ble_l2cap_sm_test_util_rx_lt_key_req(2, params->r, params->ediv);
     TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
 
     /* Ensure we sent the expected long term key request reply command. */
-    ble_l2cap_sm_test_util_verify_tx_lt_key_req_reply(2, stk);
+    ble_l2cap_sm_test_util_verify_tx_lt_key_req_reply(2, params->stk);
     TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
 
@@ -817,9 +869,10 @@ ble_l2cap_sm_test_util_peer_lgcy_good(
     /* Verify that security callback was executed. */
     TEST_ASSERT(ble_l2cap_sm_test_gap_event == BLE_GAP_EVENT_SECURITY);
     TEST_ASSERT(ble_l2cap_sm_test_gap_status == 0);
-    TEST_ASSERT(ble_l2cap_sm_test_sec_state.pair_alg == pair_alg);
+    TEST_ASSERT(ble_l2cap_sm_test_sec_state.pair_alg == params->pair_alg);
     TEST_ASSERT(ble_l2cap_sm_test_sec_state.enc_enabled);
-    TEST_ASSERT(!ble_l2cap_sm_test_sec_state.authenticated);
+    TEST_ASSERT(ble_l2cap_sm_test_sec_state.authenticated ==
+                params->authenticated);
 
     /* Verify that connection has correct security state. */
     TEST_ASSERT(ble_l2cap_sm_test_sec_state.pair_alg ==
@@ -832,58 +885,130 @@ ble_l2cap_sm_test_util_peer_lgcy_good(
 
 TEST_CASE(ble_l2cap_sm_test_case_peer_lgcy_jw_good)
 {
-    ble_l2cap_sm_test_util_peer_lgcy_good(
-        ((uint8_t[]){0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c}),
-        ((uint8_t[]){0x03, 0x02, 0x01, 0x50, 0x13, 0x00}),
-        ((struct ble_l2cap_sm_pair_cmd[1]) { {
+    struct ble_l2cap_sm_test_pair_params params;
+
+    params = (struct ble_l2cap_sm_test_pair_params) {
+        .init_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
+        .rsp_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
+        .pair_req = (struct ble_l2cap_sm_pair_cmd) {
             .io_cap = 0x04,
             .oob_data_flag = 0,
             .authreq = 0x05,
             .max_enc_key_size = 16,
             .init_key_dist = 0x07,
             .resp_key_dist = 0x07,
-        } }),
-        ((struct ble_l2cap_sm_pair_cmd[1]) { {
+        },
+        .pair_rsp = (struct ble_l2cap_sm_pair_cmd) {
             .io_cap = 3,
             .oob_data_flag = 0,
             .authreq = 0,
             .max_enc_key_size = 16,
             .init_key_dist = 0,
             .resp_key_dist = 0,
-        } }),
-        ((struct ble_l2cap_sm_pair_confirm[1]) { {
+        },
+        .confirm_req = (struct ble_l2cap_sm_pair_confirm) {
             .value = {
                 0x0a, 0xac, 0xa2, 0xae, 0xa6, 0x98, 0xdc, 0x6d,
                 0x65, 0x84, 0x11, 0x69, 0x47, 0x36, 0x8d, 0xa0,
             },
-        } }),
-        ((struct ble_l2cap_sm_pair_confirm[1]) { {
+        },
+        .confirm_rsp = (struct ble_l2cap_sm_pair_confirm) {
             .value = {
                 0x45, 0xd2, 0x2c, 0x38, 0xd8, 0x91, 0x4f, 0x19,
                 0xa2, 0xd4, 0xfc, 0x7d, 0xad, 0x37, 0x79, 0xe0
             },
-        } }),
-        ((struct ble_l2cap_sm_pair_random[1]) { {
+        },
+        .random_req = (struct ble_l2cap_sm_pair_random) {
             .value = {
                 0x2b, 0x3b, 0x69, 0xe4, 0xef, 0xab, 0xcc, 0x48,
                 0x78, 0x20, 0x1a, 0x54, 0x7a, 0x91, 0x5d, 0xfb,
             },
-        } }),
-        ((struct ble_l2cap_sm_pair_random[1]) { {
+        },
+        .random_rsp = (struct ble_l2cap_sm_pair_random) {
             .value = {
                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
             },
-        } }),
-        BLE_L2CAP_SM_PAIR_ALG_JW,
-        NULL,
-        ((uint8_t[16]) {
+        },
+        .pair_alg = BLE_L2CAP_SM_PAIR_ALG_JW,
+        .authenticated = 0,
+        .tk = { 0 },
+        .stk = {
             0xa4, 0x8e, 0x51, 0x0d, 0x33, 0xe7, 0x8f, 0x38,
             0x45, 0xf0, 0x67, 0xc3, 0xd4, 0x05, 0xb3, 0xe6,
-        }),
-        0,
-        0
-    );
+        },
+        .r = 0,
+        .ediv = 0,
+    };
+    ble_l2cap_sm_test_util_peer_lgcy_good(&params);
+}
+
+TEST_CASE(ble_l2cap_sm_test_case_peer_lgcy_passkey_good)
+{
+    struct ble_l2cap_sm_test_pair_params params;
+
+    params = (struct ble_l2cap_sm_test_pair_params) {
+        .init_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
+        .rsp_addr = {0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07},
+        .pair_req = (struct ble_l2cap_sm_pair_cmd) {
+            .io_cap = 0x04,
+            .oob_data_flag = 0,
+            .authreq = 0x05,
+            .max_enc_key_size = 16,
+            .init_key_dist = 0x07,
+            .resp_key_dist = 0x07,
+        },
+        .pair_rsp = (struct ble_l2cap_sm_pair_cmd) {
+            .io_cap = 0x02,
+            .oob_data_flag = 0,
+            .authreq = 0x05,
+            .max_enc_key_size = 16,
+            .init_key_dist = 0x01,
+            .resp_key_dist = 0x01,
+        },
+        .confirm_req = (struct ble_l2cap_sm_pair_confirm) {
+            .value = {
+                0x54, 0xed, 0x7c, 0x65, 0xc5, 0x3a, 0xee, 0x87,
+                0x8e, 0xf8, 0x04, 0xd8, 0x93, 0xb0, 0xfa, 0xa4,
+            },
+        },
+        .confirm_rsp = (struct ble_l2cap_sm_pair_confirm) {
+            .value = {
+                0xdf, 0x96, 0x88, 0x73, 0x49, 0x24, 0x3f, 0xe8,
+                0xb0, 0xaf, 0xb3, 0xf6, 0xc8, 0xf4, 0xe2, 0x36,
+            },
+        },
+        .random_req = (struct ble_l2cap_sm_pair_random) {
+            .value = {
+                0x4d, 0x2c, 0xf2, 0xb7, 0x11, 0x56, 0xbd, 0x4f,
+                0xfc, 0xde, 0xa9, 0x86, 0x4d, 0xfd, 0x77, 0x03,
+            },
+        },
+        .random_rsp = {
+            .value = {
+                0x12, 0x45, 0x65, 0x2c, 0x85, 0x56, 0x32, 0x8f,
+                0xf4, 0x7f, 0x44, 0xd0, 0x17, 0x35, 0x41, 0xed
+            },
+        },
+        .pair_alg = BLE_L2CAP_SM_PAIR_ALG_PASSKEY,
+        .authenticated = 1,
+        .tk = {
+            0x5a, 0x7f, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
+            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+        },
+        .stk = {
+            0x2b, 0x9c, 0x1e, 0x42, 0xa8, 0xcb, 0xab, 0xd1,
+            0x4b, 0xde, 0x50, 0x05, 0x50, 0xd9, 0x95, 0xc6
+        },
+        .r = 4107344270811490869,
+        .ediv = 61621,
+
+        .passkey = {
+            .action = BLE_GAP_PKACT_INPUT,
+            .passkey = 884570,
+        }
+    };
+    ble_l2cap_sm_test_util_peer_lgcy_good(&params);
 }
 
 static void
@@ -1011,19 +1136,15 @@ TEST_CASE(ble_l2cap_sm_test_case_peer_bonding_bad)
 
 static void
 ble_l2cap_sm_test_util_us_fail_inval(
-    uint8_t *init_addr,
-    uint8_t *rsp_addr,
-    struct ble_l2cap_sm_pair_cmd *pair_req,
-    struct ble_l2cap_sm_pair_cmd *pair_rsp,
-    struct ble_l2cap_sm_pair_fail *pair_fail)
+    struct ble_l2cap_sm_test_pair_params *params)
 {
     struct ble_hs_conn *conn;
     int rc;
 
     ble_l2cap_sm_test_util_init();
-    ble_hs_test_util_set_public_addr(rsp_addr);
+    ble_hs_test_util_set_public_addr(params->rsp_addr);
 
-    conn = ble_hs_test_util_create_conn(2, init_addr,
+    conn = ble_hs_test_util_create_conn(2, params->init_addr,
                                         ble_l2cap_sm_test_util_conn_cb,
                                         NULL);
 
@@ -1036,19 +1157,19 @@ ble_l2cap_sm_test_util_us_fail_inval(
 
     /* Ensure we sent the expected pair request. */
     ble_hs_test_util_tx_all();
-    ble_l2cap_sm_test_util_verify_tx_pair_req(pair_req);
+    ble_l2cap_sm_test_util_verify_tx_pair_req(&params->pair_req);
     TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
 
     /* Receive a pair response from the peer. */
     ble_l2cap_sm_test_util_rx_pair_rsp(
-        conn, pair_rsp, BLE_HS_SM_US_ERR(BLE_L2CAP_SM_ERR_INVAL));
+        conn, &params->pair_rsp, BLE_HS_SM_US_ERR(BLE_L2CAP_SM_ERR_INVAL));
     TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 0);
 
     /* Ensure we sent the expected pair fail. */
     ble_hs_test_util_tx_all();
-    ble_l2cap_sm_test_util_verify_tx_pair_fail(pair_fail);
+    ble_l2cap_sm_test_util_verify_tx_pair_fail(&params->pair_fail);
     TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 0);
 
@@ -1063,233 +1184,235 @@ ble_l2cap_sm_test_util_us_fail_inval(
 
 TEST_CASE(ble_l2cap_sm_test_case_us_fail_inval)
 {
+    struct ble_l2cap_sm_test_pair_params params;
+
     /* Invalid IO capabiltiies. */
-    ble_l2cap_sm_test_util_us_fail_inval(
-        ((uint8_t[]){0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c}),
-        ((uint8_t[]){0x03, 0x02, 0x01, 0x50, 0x13, 0x00}),
-        ((struct ble_l2cap_sm_pair_cmd[1]) { {
+    params = (struct ble_l2cap_sm_test_pair_params) {
+        .init_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
+        .rsp_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
+        .pair_req = (struct ble_l2cap_sm_pair_cmd) {
             .io_cap = 3,
             .oob_data_flag = 0,
             .authreq = 0,
             .max_enc_key_size = 16,
             .init_key_dist = 0,
             .resp_key_dist = 0,
-        } }),
-        ((struct ble_l2cap_sm_pair_cmd[1]) { {
+        },
+        .pair_rsp = (struct ble_l2cap_sm_pair_cmd) {
             .io_cap = 0x14,
             .oob_data_flag = 0,
             .authreq = 0x05,
             .max_enc_key_size = 16,
             .init_key_dist = 0x07,
             .resp_key_dist = 0x07,
-        } }),
-        ((struct ble_l2cap_sm_pair_fail[1]) { {
+        },
+        .pair_fail = (struct ble_l2cap_sm_pair_fail) {
             .reason = BLE_L2CAP_SM_ERR_INVAL,
-        } })
-    );
+        },
+    };
+    ble_l2cap_sm_test_util_us_fail_inval(&params);
 
     /* Invalid OOB flag. */
-    ble_l2cap_sm_test_util_us_fail_inval(
-        ((uint8_t[]){0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c}),
-        ((uint8_t[]){0x03, 0x02, 0x01, 0x50, 0x13, 0x00}),
-        ((struct ble_l2cap_sm_pair_cmd[1]) { {
+    params = (struct ble_l2cap_sm_test_pair_params) {
+        .init_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
+        .rsp_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
+        .pair_req = (struct ble_l2cap_sm_pair_cmd) {
             .io_cap = 3,
             .oob_data_flag = 0,
             .authreq = 0,
             .max_enc_key_size = 16,
             .init_key_dist = 0,
             .resp_key_dist = 0,
-        } }),
-        ((struct ble_l2cap_sm_pair_cmd[1]) { {
-            .io_cap = 0x04,
+        },
+        .pair_rsp = (struct ble_l2cap_sm_pair_cmd) {
+            .io_cap = 0x14,
             .oob_data_flag = 2,
             .authreq = 0x05,
             .max_enc_key_size = 16,
             .init_key_dist = 0x07,
             .resp_key_dist = 0x07,
-        } }),
-        ((struct ble_l2cap_sm_pair_fail[1]) { {
+        },
+        .pair_fail = (struct ble_l2cap_sm_pair_fail) {
             .reason = BLE_L2CAP_SM_ERR_INVAL,
-        } })
-    );
+        },
+    };
+    ble_l2cap_sm_test_util_us_fail_inval(&params);
 
     /* Invalid authreq - reserved bonding flag. */
-    ble_l2cap_sm_test_util_us_fail_inval(
-        ((uint8_t[]){0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c}),
-        ((uint8_t[]){0x03, 0x02, 0x01, 0x50, 0x13, 0x00}),
-        ((struct ble_l2cap_sm_pair_cmd[1]) { {
+    params = (struct ble_l2cap_sm_test_pair_params) {
+        .init_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
+        .rsp_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
+        .pair_req = (struct ble_l2cap_sm_pair_cmd) {
             .io_cap = 3,
             .oob_data_flag = 0,
             .authreq = 0,
             .max_enc_key_size = 16,
             .init_key_dist = 0,
             .resp_key_dist = 0,
-        } }),
-        ((struct ble_l2cap_sm_pair_cmd[1]) { {
+        },
+        .pair_rsp = (struct ble_l2cap_sm_pair_cmd) {
             .io_cap = 0x04,
             .oob_data_flag = 0,
-            .authreq = 0x2,
+            .authreq = 0x02,
             .max_enc_key_size = 16,
             .init_key_dist = 0x07,
             .resp_key_dist = 0x07,
-        } }),
-        ((struct ble_l2cap_sm_pair_fail[1]) { {
+        },
+        .pair_fail = (struct ble_l2cap_sm_pair_fail) {
             .reason = BLE_L2CAP_SM_ERR_INVAL,
-        } })
-    );
+        },
+    };
+    ble_l2cap_sm_test_util_us_fail_inval(&params);
 
     /* Invalid authreq - reserved other flag. */
-    ble_l2cap_sm_test_util_us_fail_inval(
-        ((uint8_t[]){0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c}),
-        ((uint8_t[]){0x03, 0x02, 0x01, 0x50, 0x13, 0x00}),
-        ((struct ble_l2cap_sm_pair_cmd[1]) { {
+    params = (struct ble_l2cap_sm_test_pair_params) {
+        .init_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
+        .rsp_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
+        .pair_req = (struct ble_l2cap_sm_pair_cmd) {
             .io_cap = 3,
             .oob_data_flag = 0,
             .authreq = 0,
             .max_enc_key_size = 16,
             .init_key_dist = 0,
             .resp_key_dist = 0,
-        } }),
-        ((struct ble_l2cap_sm_pair_cmd[1]) { {
+        },
+        .pair_rsp = (struct ble_l2cap_sm_pair_cmd) {
             .io_cap = 0x04,
             .oob_data_flag = 0,
             .authreq = 0x20,
             .max_enc_key_size = 16,
             .init_key_dist = 0x07,
             .resp_key_dist = 0x07,
-        } }),
-        ((struct ble_l2cap_sm_pair_fail[1]) { {
+        },
+        .pair_fail = (struct ble_l2cap_sm_pair_fail) {
             .reason = BLE_L2CAP_SM_ERR_INVAL,
-        } })
-    );
+        },
+    };
+    ble_l2cap_sm_test_util_us_fail_inval(&params);
 
     /* Invalid key size - too small. */
-    ble_l2cap_sm_test_util_us_fail_inval(
-        ((uint8_t[]){0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c}),
-        ((uint8_t[]){0x03, 0x02, 0x01, 0x50, 0x13, 0x00}),
-        ((struct ble_l2cap_sm_pair_cmd[1]) { {
+    params = (struct ble_l2cap_sm_test_pair_params) {
+        .init_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
+        .rsp_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
+        .pair_req = (struct ble_l2cap_sm_pair_cmd) {
             .io_cap = 3,
             .oob_data_flag = 0,
             .authreq = 0,
             .max_enc_key_size = 16,
             .init_key_dist = 0,
             .resp_key_dist = 0,
-        } }),
-        ((struct ble_l2cap_sm_pair_cmd[1]) { {
+        },
+        .pair_rsp = (struct ble_l2cap_sm_pair_cmd) {
             .io_cap = 0x04,
             .oob_data_flag = 0,
-            .authreq = 0x5,
+            .authreq = 0x05,
             .max_enc_key_size = 6,
             .init_key_dist = 0x07,
             .resp_key_dist = 0x07,
-        } }),
-        ((struct ble_l2cap_sm_pair_fail[1]) { {
+        },
+        .pair_fail = (struct ble_l2cap_sm_pair_fail) {
             .reason = BLE_L2CAP_SM_ERR_INVAL,
-        } })
-    );
+        },
+    };
+    ble_l2cap_sm_test_util_us_fail_inval(&params);
 
     /* Invalid key size - too large. */
-    ble_l2cap_sm_test_util_us_fail_inval(
-        ((uint8_t[]){0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c}),
-        ((uint8_t[]){0x03, 0x02, 0x01, 0x50, 0x13, 0x00}),
-        ((struct ble_l2cap_sm_pair_cmd[1]) { {
+    params = (struct ble_l2cap_sm_test_pair_params) {
+        .init_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
+        .rsp_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
+        .pair_req = (struct ble_l2cap_sm_pair_cmd) {
             .io_cap = 3,
             .oob_data_flag = 0,
             .authreq = 0,
             .max_enc_key_size = 16,
             .init_key_dist = 0,
             .resp_key_dist = 0,
-        } }),
-        ((struct ble_l2cap_sm_pair_cmd[1]) { {
+        },
+        .pair_rsp = (struct ble_l2cap_sm_pair_cmd) {
             .io_cap = 0x04,
             .oob_data_flag = 0,
-            .authreq = 0x5,
+            .authreq = 0x05,
             .max_enc_key_size = 17,
             .init_key_dist = 0x07,
             .resp_key_dist = 0x07,
-        } }),
-        ((struct ble_l2cap_sm_pair_fail[1]) { {
+        },
+        .pair_fail = (struct ble_l2cap_sm_pair_fail) {
             .reason = BLE_L2CAP_SM_ERR_INVAL,
-        } })
-    );
+        },
+    };
+    ble_l2cap_sm_test_util_us_fail_inval(&params);
 
     /* Invalid init key dist. */
-    ble_l2cap_sm_test_util_us_fail_inval(
-        ((uint8_t[]){0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c}),
-        ((uint8_t[]){0x03, 0x02, 0x01, 0x50, 0x13, 0x00}),
-        ((struct ble_l2cap_sm_pair_cmd[1]) { {
+    params = (struct ble_l2cap_sm_test_pair_params) {
+        .init_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
+        .rsp_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
+        .pair_req = (struct ble_l2cap_sm_pair_cmd) {
             .io_cap = 3,
             .oob_data_flag = 0,
             .authreq = 0,
             .max_enc_key_size = 16,
             .init_key_dist = 0,
             .resp_key_dist = 0,
-        } }),
-        ((struct ble_l2cap_sm_pair_cmd[1]) { {
+        },
+        .pair_rsp = (struct ble_l2cap_sm_pair_cmd) {
             .io_cap = 0x04,
             .oob_data_flag = 0,
-            .authreq = 0x5,
-            .max_enc_key_size = 16,
+            .authreq = 0x05,
+            .max_enc_key_size = 17,
             .init_key_dist = 0x10,
             .resp_key_dist = 0x07,
-        } }),
-        ((struct ble_l2cap_sm_pair_fail[1]) { {
+        },
+        .pair_fail = (struct ble_l2cap_sm_pair_fail) {
             .reason = BLE_L2CAP_SM_ERR_INVAL,
-        } })
-    );
+        },
+    };
+    ble_l2cap_sm_test_util_us_fail_inval(&params);
 
     /* Invalid resp key dist. */
-    ble_l2cap_sm_test_util_us_fail_inval(
-        ((uint8_t[]){0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c}),
-        ((uint8_t[]){0x03, 0x02, 0x01, 0x50, 0x13, 0x00}),
-        ((struct ble_l2cap_sm_pair_cmd[1]) { {
+    params = (struct ble_l2cap_sm_test_pair_params) {
+        .init_addr = {0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c},
+        .rsp_addr = {0x03, 0x02, 0x01, 0x50, 0x13, 0x00},
+        .pair_req = (struct ble_l2cap_sm_pair_cmd) {
             .io_cap = 3,
             .oob_data_flag = 0,
             .authreq = 0,
             .max_enc_key_size = 16,
             .init_key_dist = 0,
             .resp_key_dist = 0,
-        } }),
-        ((struct ble_l2cap_sm_pair_cmd[1]) { {
+        },
+        .pair_rsp = (struct ble_l2cap_sm_pair_cmd) {
             .io_cap = 0x04,
             .oob_data_flag = 0,
-            .authreq = 0x5,
-            .max_enc_key_size = 16,
+            .authreq = 0x05,
+            .max_enc_key_size = 17,
             .init_key_dist = 0x07,
             .resp_key_dist = 0x10,
-        } }),
-        ((struct ble_l2cap_sm_pair_fail[1]) { {
+        },
+        .pair_fail = (struct ble_l2cap_sm_pair_fail) {
             .reason = BLE_L2CAP_SM_ERR_INVAL,
-        } })
-    );
+        },
+    };
+    ble_l2cap_sm_test_util_us_fail_inval(&params);
 }
 
 static void
 ble_l2cap_sm_test_util_us_lgcy_good(
-    uint8_t *init_addr,
-    uint8_t *rsp_addr,
-    struct ble_l2cap_sm_pair_cmd *pair_req,
-    struct ble_l2cap_sm_pair_cmd *pair_rsp,
-    struct ble_l2cap_sm_pair_confirm *confirm_req,
-    struct ble_l2cap_sm_pair_confirm *confirm_rsp,
-    struct ble_l2cap_sm_pair_random *random_req,
-    struct ble_l2cap_sm_pair_random *random_rsp,
-    int pair_alg,
-    uint8_t *tk,
-    uint8_t *stk,
-    uint64_t r,
-    uint16_t ediv)
+    struct ble_l2cap_sm_test_pair_params *params)
 {
     struct ble_hs_conn *conn;
     int rc;
 
     ble_l2cap_sm_test_util_init();
-    ble_hs_test_util_set_public_addr(init_addr);
-    ble_l2cap_sm_dbg_set_next_pair_rand(random_req->value);
-    ble_l2cap_sm_dbg_set_next_ediv(ediv);
-    ble_l2cap_sm_dbg_set_next_start_rand(r);
+    ble_hs_test_util_set_public_addr(params->init_addr);
+    ble_l2cap_sm_dbg_set_next_pair_rand(params->random_req.value);
+    ble_l2cap_sm_dbg_set_next_ediv(params->ediv);
+    ble_l2cap_sm_dbg_set_next_start_rand(params->r);
+
+    if (params->has_enc_info_req) {
+        ble_l2cap_sm_dbg_set_next_ltk(params->enc_info_req.ltk_le);
+    }
 
-    conn = ble_hs_test_util_create_conn(2, rsp_addr,
+    conn = ble_hs_test_util_create_conn(2, params->rsp_addr,
                                         ble_l2cap_sm_test_util_conn_cb,
                                         NULL);
 
@@ -1302,42 +1425,46 @@ ble_l2cap_sm_test_util_us_lgcy_good(
 
     /* Ensure we sent the expected pair request. */
     ble_hs_test_util_tx_all();
-    ble_l2cap_sm_test_util_verify_tx_pair_req(pair_req);
+    ble_l2cap_sm_test_util_verify_tx_pair_req(&params->pair_req);
     TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
 
     /* Receive a pair response from the peer. */
-    ble_l2cap_sm_test_util_rx_pair_rsp(conn, pair_rsp, 0);
+    ble_l2cap_sm_test_util_rx_pair_rsp(conn, &params->pair_rsp, 0);
     TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
 
     /* Ensure we sent the expected pair confirm. */
     ble_hs_test_util_tx_all();
-    ble_l2cap_sm_test_util_verify_tx_pair_confirm(confirm_req);
+    ble_l2cap_sm_test_util_verify_tx_pair_confirm(&params->confirm_req);
     TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
 
     /* Receive a pair confirm from the peer. */
-    ble_l2cap_sm_test_util_rx_confirm(conn, confirm_rsp);
+    ble_l2cap_sm_test_util_rx_confirm(conn, &params->confirm_rsp);
     TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
 
     /* Ensure we sent the expected pair random. */
     ble_hs_test_util_tx_all();
-    ble_l2cap_sm_test_util_verify_tx_pair_random(random_req);
+    ble_l2cap_sm_test_util_verify_tx_pair_random(&params->random_req);
     TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
 
     /* Receive a pair random from the peer. */
-    ble_l2cap_sm_test_util_rx_random(conn, random_rsp, 0);
+    ble_l2cap_sm_test_util_rx_random(conn, &params->random_rsp, 0);
     TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
 
     /* Ensure keys are distributed, if necessary. */
+    if (params->has_enc_info_req) {
+        ble_l2cap_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_l2cap_sm_test_util_verify_tx_start_enc(2, r, ediv, stk);
+    ble_l2cap_sm_test_util_verify_tx_start_enc(2, params->r, params->ediv,
+                                               params->stk);
     TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
     TEST_ASSERT(ble_l2cap_sm_dbg_num_procs() == 1);
 
@@ -1350,7 +1477,7 @@ ble_l2cap_sm_test_util_us_lgcy_good(
     /* Verify that security callback was executed. */
     TEST_ASSERT(ble_l2cap_sm_test_gap_event == BLE_GAP_EVENT_SECURITY);
     TEST_ASSERT(ble_l2cap_sm_test_gap_status == 0);
-    TEST_ASSERT(ble_l2cap_sm_test_sec_state.pair_alg == pair_alg);
+    TEST_ASSERT(ble_l2cap_sm_test_sec_state.pair_alg == params->pair_alg);
     TEST_ASSERT(ble_l2cap_sm_test_sec_state.enc_enabled);
     TEST_ASSERT(!ble_l2cap_sm_test_sec_state.authenticated);
 
@@ -1365,58 +1492,62 @@ ble_l2cap_sm_test_util_us_lgcy_good(
 
 TEST_CASE(ble_l2cap_sm_test_case_us_lgcy_jw_good)
 {
-    ble_l2cap_sm_test_util_us_lgcy_good(
-        ((uint8_t[]){0x06, 0x05, 0x04, 0x03, 0x02, 0x01}),
-        ((uint8_t[]){0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a}),
-        ((struct ble_l2cap_sm_pair_cmd[1]) { {
+    struct ble_l2cap_sm_test_pair_params params;
+
+    params = (struct ble_l2cap_sm_test_pair_params) {
+        .init_addr = {0x06, 0x05, 0x04, 0x03, 0x02, 0x01}, 
+        .rsp_addr = {0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a},
+        .pair_req = (struct ble_l2cap_sm_pair_cmd) {
             .io_cap = 3,
             .oob_data_flag = 0,
             .authreq = 0,
             .max_enc_key_size = 16,
             .init_key_dist = 0,
             .resp_key_dist = 0,
-        } }),
-        ((struct ble_l2cap_sm_pair_cmd[1]) { {
+        },
+        .pair_rsp = (struct ble_l2cap_sm_pair_cmd) {
             .io_cap = 3,
             .oob_data_flag = 0,
             .authreq = 0,
             .max_enc_key_size = 16,
             .init_key_dist = 0,
             .resp_key_dist = 0,
-        } }),
-        ((struct ble_l2cap_sm_pair_confirm[1]) { {
+        },
+        .confirm_req = (struct ble_l2cap_sm_pair_confirm) {
             .value = {
                 0x04, 0x4e, 0xaf, 0xce, 0x30, 0x79, 0x2c, 0x9e,
                 0xa2, 0xeb, 0x53, 0x6a, 0xdf, 0xf7, 0x99, 0xb2,
             },
-        } }),
-        ((struct ble_l2cap_sm_pair_confirm[1]) { {
+        },
+        .confirm_rsp = (struct ble_l2cap_sm_pair_confirm) {
             .value = {
                 0x04, 0x4e, 0xaf, 0xce, 0x30, 0x79, 0x2c, 0x9e,
                 0xa2, 0xeb, 0x53, 0x6a, 0xdf, 0xf7, 0x99, 0xb2,
             },
-        } }),
-        ((struct ble_l2cap_sm_pair_random[1]) { {
+        },
+        .random_req = (struct ble_l2cap_sm_pair_random) {
             .value = {
                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
             },
-        } }),
-        ((struct ble_l2cap_sm_pair_random[1]) { {
+        },
+        .random_rsp = (struct ble_l2cap_sm_pair_random) {
             .value = {
                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
             },
-        } }),
-        BLE_L2CAP_SM_PAIR_ALG_JW,
-        NULL,
-        ((uint8_t[16]) {
+        },
+        .pair_alg = BLE_L2CAP_SM_PAIR_ALG_JW,
+        .tk = { 0 },
+        .stk = {
             0x2e, 0x2b, 0x34, 0xca, 0x59, 0xfa, 0x4c, 0x88,
             0x3b, 0x2c, 0x8a, 0xef, 0xd4, 0x4b, 0xe9, 0x66,
-        }),
-        0,
-        0
-    );
+        },
+        .r = 0,
+        .ediv = 0,
+    };
+
+    ble_l2cap_sm_test_util_us_lgcy_good(&params);
 }
 
 TEST_CASE(ble_l2cap_sm_test_case_conn_broken)
@@ -1451,6 +1582,7 @@ TEST_SUITE(ble_l2cap_sm_test_suite)
     ble_l2cap_sm_test_case_peer_fail_inval();
     ble_l2cap_sm_test_case_peer_lgcy_fail_confirm();
     ble_l2cap_sm_test_case_peer_lgcy_jw_good();
+    ble_l2cap_sm_test_case_peer_lgcy_passkey_good();
     ble_l2cap_sm_test_case_us_fail_inval();
     ble_l2cap_sm_test_case_us_lgcy_jw_good();
     ble_l2cap_sm_test_case_peer_bonding_good();



[3/3] incubator-mynewt-core git commit: BLE host - rename struct with appropriate prefix.

Posted by cc...@apache.org.
BLE host - rename struct with appropriate prefix.


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

Branch: refs/heads/develop
Commit: 9eeec05f0dd52219bf46a2a031d1e5d1fae1da0f
Parents: ffd58ca
Author: Christopher Collins <cc...@apache.org>
Authored: Wed May 11 20:39:07 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed May 11 20:39:07 2016 -0700

----------------------------------------------------------------------
 apps/bletiny/src/cmd.c                       | 2 +-
 net/nimble/host/include/host/ble_l2cap.h     | 5 +++--
 net/nimble/host/src/ble_l2cap_sm.c           | 2 +-
 net/nimble/host/src/test/ble_l2cap_sm_test.c | 4 ++--
 4 files changed, 7 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9eeec05f/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 8c96bd1..4510c3e 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -1703,7 +1703,7 @@ cmd_passkey(int argc, char **argv)
 #endif
 
     uint16_t conn_handle;
-    struct passkey_action pk;
+    struct ble_l2cap_sm_passkey pk;
     int rc;
 
     conn_handle = parse_arg_uint16("conn", &rc);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9eeec05f/net/nimble/host/include/host/ble_l2cap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_l2cap.h b/net/nimble/host/include/host/ble_l2cap.h
index 26666b2..a50138a 100644
--- a/net/nimble/host/include/host/ble_l2cap.h
+++ b/net/nimble/host/include/host/ble_l2cap.h
@@ -126,7 +126,7 @@ int ble_l2cap_sig_update(uint16_t conn_handle,
                          ble_l2cap_sig_update_fn *cb, void *cb_arg);
 
 /* Strucure to pass the passkey info back to the l2cap */
-struct passkey_action
+struct ble_l2cap_sm_passkey
 {
     uint8_t action;
     union
@@ -140,7 +140,8 @@ struct passkey_action
  * and then call this function to notify the host that the action is
  * complete
  */
-int ble_l2cap_sm_set_tk(uint16_t conn_handle, struct passkey_action *pkey);
+int ble_l2cap_sm_set_tk(uint16_t conn_handle,
+                        struct ble_l2cap_sm_passkey *pkey);
 
 void ble_l2cap_sm_connection_broken(uint16_t conn_handle);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9eeec05f/net/nimble/host/src/ble_l2cap_sm.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sm.c b/net/nimble/host/src/ble_l2cap_sm.c
index fd9ba5d..81b5996 100644
--- a/net/nimble/host/src/ble_l2cap_sm.c
+++ b/net/nimble/host/src/ble_l2cap_sm.c
@@ -1912,7 +1912,7 @@ ble_l2cap_sm_create_chan(void)
 }
 
 int
-ble_l2cap_sm_set_tk(uint16_t conn_handle, struct passkey_action *pkey)
+ble_l2cap_sm_set_tk(uint16_t conn_handle, struct ble_l2cap_sm_passkey *pkey)
 {
     struct ble_l2cap_sm_proc *proc;
     struct ble_l2cap_sm_proc *prev;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/9eeec05f/net/nimble/host/src/test/ble_l2cap_sm_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_l2cap_sm_test.c b/net/nimble/host/src/test/ble_l2cap_sm_test.c
index f5553f1..e6adb05 100644
--- a/net/nimble/host/src/test/ble_l2cap_sm_test.c
+++ b/net/nimble/host/src/test/ble_l2cap_sm_test.c
@@ -58,7 +58,7 @@ struct ble_l2cap_sm_test_pair_params {
     uint64_t r;
     uint16_t ediv;
 
-    struct passkey_action passkey;
+    struct ble_l2cap_sm_passkey passkey;
     struct ble_l2cap_sm_pair_fail pair_fail;
 
     unsigned has_enc_info_req:1;
@@ -94,7 +94,7 @@ static int
 ble_l2cap_sm_test_util_conn_cb(int event, int status,
                                struct ble_gap_conn_ctxt *ctxt, void *arg)
 {
-    struct passkey_action *passkey;
+    struct ble_l2cap_sm_passkey *passkey;
     struct ble_l2cap_sm_test_ltk_info *ltk_info;
     int rc;