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/17 04:04:01 UTC
[1/9] incubator-mynewt-core git commit: BLE Host - SM: remove
obsolete ediv, rand field
Repository: incubator-mynewt-core
Updated Branches:
refs/heads/develop daab0741c -> 39dd36c86
BLE Host - SM: remove obsolete ediv,rand field
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/06e134c7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/06e134c7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/06e134c7
Branch: refs/heads/develop
Commit: 06e134c7c545c5112ad8ae39ce3a04da8978a0ef
Parents: daab074
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 15 20:46:29 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed Jun 15 20:46:29 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/ble_sm_lgcy.c | 4 ++--
net/nimble/host/src/ble_sm_priv.h | 8 ++++----
2 files changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/06e134c7/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 a93622e..d844a6f 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_ioa[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_ioa[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_ioa[5 /*resp*/ ][5 /*init*/] =
+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},
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/06e134c7/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 9d1ecac..57c8e19 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -263,10 +263,6 @@ struct ble_sm_proc {
struct ble_sm_keys our_keys;
struct ble_sm_keys peer_keys;
- /* Legacy. */
- uint16_t ediv;
- uint64_t rand_num;
-
#if NIMBLE_OPT(SM_SC)
/* Secure connections. */
uint8_t passkey_bits_exchanged;
@@ -332,10 +328,14 @@ int ble_sm_pair_fail_tx(uint16_t conn_handle, uint8_t reason);
void 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);
+void ble_sm_enc_info_write(void *payload, int len,
+ struct ble_sm_enc_info *cmd);
int ble_sm_enc_info_tx(uint16_t conn_handle, struct ble_sm_enc_info *cmd);
void ble_sm_enc_info_log(struct ble_sm_enc_info *cmd);
void ble_sm_master_id_parse(void *payload, int len,
struct ble_sm_master_id *cmd);
+void ble_sm_master_id_write(void *payload, int len,
+ struct ble_sm_master_id *cmd);
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);
[4/9] incubator-mynewt-core git commit: BLE Host - Don't restore
bonding on enc. fail.
Posted by cc...@apache.org.
BLE Host - Don't restore bonding on enc. 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/8b26f565
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/8b26f565
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/8b26f565
Branch: refs/heads/develop
Commit: 8b26f565f7f3b12b84b18f47b161ca0a2ababd96
Parents: 06e134c
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jun 16 20:45:34 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Jun 16 20:49:26 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/ble_gap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/8b26f565/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 25b043d..7c7ba7f 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -2254,7 +2254,7 @@ ble_gap_enc_event(uint16_t conn_handle, int status, int security_restored)
ble_gap_call_event_cb(BLE_GAP_EVENT_ENC_CHANGE, &ctxt,
snap.cb, snap.cb_arg);
- if (security_restored) {
+ if (status == 0 && security_restored) {
BLE_HS_DBG_ASSERT(snap.desc.sec_state.bonded);
ble_gatts_bonding_restored(conn_handle);
}
[2/9] incubator-mynewt-core git commit: BLE Host - Rename start_rand
to master_id_rand.
Posted by cc...@apache.org.
BLE Host - Rename start_rand to master_id_rand.
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/e347a0d6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/e347a0d6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/e347a0d6
Branch: refs/heads/develop
Commit: e347a0d6832540fdd8c01ddfcd73a5aa164b9d7b
Parents: cda2363
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jun 16 20:48:15 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Jun 16 20:49:26 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/ble_sm.c | 22 +++++++++++-----------
net/nimble/host/src/ble_sm_priv.h | 2 +-
2 files changed, 12 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e347a0d6/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 bd435a5..76cbbd0 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -146,8 +146,8 @@ static uint8_t ble_sm_dbg_next_pair_rand[16];
static uint8_t ble_sm_dbg_next_pair_rand_set;
static uint16_t ble_sm_dbg_next_ediv;
static uint8_t ble_sm_dbg_next_ediv_set;
-static uint64_t ble_sm_dbg_next_start_rand;
-static uint8_t ble_sm_dbg_next_start_rand_set;
+static uint64_t ble_sm_dbg_next_master_id_rand;
+static uint8_t ble_sm_dbg_next_master_id_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_csrk[16];
@@ -172,10 +172,10 @@ ble_sm_dbg_set_next_ediv(uint16_t next_ediv)
}
void
-ble_sm_dbg_set_next_start_rand(uint64_t next_start_rand)
+ble_sm_dbg_set_next_master_id_rand(uint64_t next_master_id_rand)
{
- ble_sm_dbg_next_start_rand = next_start_rand;
- ble_sm_dbg_next_start_rand_set = 1;
+ ble_sm_dbg_next_master_id_rand = next_master_id_rand;
+ ble_sm_dbg_next_master_id_rand_set = 1;
}
void
@@ -289,19 +289,19 @@ ble_sm_gen_ediv(uint16_t *ediv)
}
static int
-ble_sm_gen_start_rand(uint64_t *start_rand)
+ble_sm_gen_master_id_rand(uint64_t *master_id_rand)
{
int rc;
#ifdef BLE_HS_DEBUG
- if (ble_sm_dbg_next_start_rand_set) {
- ble_sm_dbg_next_start_rand_set = 0;
- *start_rand = ble_sm_dbg_next_start_rand;
+ if (ble_sm_dbg_next_master_id_rand_set) {
+ ble_sm_dbg_next_master_id_rand_set = 0;
+ *master_id_rand = ble_sm_dbg_next_master_id_rand;
return 0;
}
#endif
- rc = ble_hci_util_rand(start_rand, sizeof *start_rand);
+ rc = ble_hci_util_rand(master_id_rand, sizeof *master_id_rand);
if (rc != 0) {
return rc;
}
@@ -1737,7 +1737,7 @@ ble_sm_key_exch_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
if (rc != 0) {
goto err;
}
- rc = ble_sm_gen_start_rand(&master_id.rand_val);
+ rc = ble_sm_gen_master_id_rand(&master_id.rand_val);
if (rc != 0) {
goto err;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/e347a0d6/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 57c8e19..9ba2fad 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -287,7 +287,7 @@ struct ble_sm_result {
#ifdef BLE_HS_DEBUG
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_master_id_rand(uint64_t next_master_id_rand);
void ble_sm_dbg_set_next_ltk(uint8_t *next_ltk);
void ble_sm_dbg_set_next_csrk(uint8_t *next_csrk);
void ble_sm_dbg_set_sc_keys(uint8_t *pubkey, uint8_t *privkey);
[7/9] incubator-mynewt-core git commit: BLE Host - More SM unit tests.
Posted by cc...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/39dd36c8/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 7d51e7e..48a8677 100644
--- a/net/nimble/host/src/test/ble_sm_test_util.c
+++ b/net/nimble/host/src/test/ble_sm_test_util.c
@@ -40,6 +40,33 @@ 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;
+struct ble_sm_test_util_entity {
+ uint8_t addr_type;
+ uint8_t id_addr_type;
+ uint8_t *id_addr;
+ uint8_t *rpa;
+
+ struct ble_sm_pair_cmd *pair_cmd;
+ struct ble_sm_pair_confirm *confirms;
+ struct ble_sm_pair_random *randoms;
+ struct ble_sm_id_info *id_info;
+ struct ble_sm_id_addr_info *id_addr_info;
+ struct ble_sm_sign_info *sign_info;
+ uint8_t *ltk;
+
+ uint8_t key_dist;
+
+ /*** Secure connections fields. */
+ struct ble_sm_public_key *public_key;
+ struct ble_sm_dhkey_check *dhkey_check;
+
+ /*** Legacy fields. */
+ struct ble_sm_enc_info *enc_info;
+ struct ble_sm_master_id *master_id;
+ uint64_t rand_num;
+ uint16_t ediv;
+};
+
#define BLE_SM_TEST_UTIL_HCI_HDR(handle, pb, len) \
((struct hci_data_hdr) { \
.hdh_handle_pb_bc = ((handle) << 0) | \
@@ -81,10 +108,157 @@ ble_sm_test_util_init(void)
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;
-};
+static void
+ble_sm_test_util_params_to_entity(struct ble_sm_test_params *params,
+ int initiator,
+ struct ble_sm_test_util_entity *out_entity)
+{
+ int sc;
+
+ memset(out_entity, 0, sizeof *out_entity);
+
+ sc = params->pair_req.authreq & BLE_SM_PAIR_AUTHREQ_SC &&
+ params->pair_rsp.authreq & BLE_SM_PAIR_AUTHREQ_SC;
+
+ if (initiator) {
+ out_entity->key_dist = params->pair_rsp.init_key_dist;
+
+ out_entity->addr_type = params->init_addr_type;
+ out_entity->id_addr = params->init_id_addr;
+ out_entity->rpa = params->init_rpa;
+
+ out_entity->pair_cmd = ¶ms->pair_req;
+ out_entity->confirms = params->confirm_req;
+ out_entity->randoms = params->random_req;
+ out_entity->id_info = ¶ms->id_info_rsp;
+ out_entity->id_addr_info = ¶ms->id_addr_info_rsp;
+ out_entity->sign_info = ¶ms->sign_info_rsp;
+
+ if (sc) {
+ out_entity->ltk = params->ltk;
+ out_entity->public_key = ¶ms->public_key_req;
+ out_entity->dhkey_check = ¶ms->dhkey_check_req;
+ } else {
+ out_entity->enc_info = ¶ms->enc_info_rsp;
+ out_entity->master_id = ¶ms->master_id_rsp;
+ if (out_entity->key_dist & BLE_SM_PAIR_KEY_DIST_ENC) {
+ out_entity->rand_num = params->master_id_rsp.rand_val;
+ out_entity->ediv = params->master_id_rsp.ediv;
+ out_entity->ltk = params->enc_info_rsp.ltk;
+ }
+ }
+ } else {
+ out_entity->key_dist = params->pair_rsp.resp_key_dist;
+
+ out_entity->addr_type = params->resp_addr_type;
+ out_entity->id_addr = params->resp_id_addr;
+ out_entity->rpa = params->resp_rpa;
+
+ out_entity->pair_cmd = ¶ms->pair_rsp;
+ out_entity->confirms = params->confirm_rsp;
+ out_entity->randoms = params->random_rsp;
+ out_entity->id_info = ¶ms->id_info_req;
+ out_entity->id_addr_info = ¶ms->id_addr_info_req;
+ out_entity->sign_info = ¶ms->sign_info_req;
+
+ if (sc) {
+ out_entity->ltk = params->ltk;
+ out_entity->public_key = ¶ms->public_key_rsp;
+ out_entity->dhkey_check = ¶ms->dhkey_check_rsp;
+ } else {
+ out_entity->enc_info = ¶ms->enc_info_req;
+ out_entity->master_id = ¶ms->master_id_req;
+ if (out_entity->key_dist & BLE_SM_PAIR_KEY_DIST_ENC) {
+ out_entity->rand_num = params->master_id_req.rand_val;
+ out_entity->ediv = params->master_id_req.ediv;
+ out_entity->ltk = params->enc_info_req.ltk;
+ }
+ }
+ }
+
+ out_entity->id_addr_type =
+ ble_hs_misc_addr_type_to_id(out_entity->addr_type);
+}
+
+static void
+ble_sm_test_util_params_to_entities(struct ble_sm_test_params *params,
+ int we_are_initiator,
+ struct ble_sm_test_util_entity *out_us,
+ struct ble_sm_test_util_entity *out_peer)
+{
+ ble_sm_test_util_params_to_entity(params, we_are_initiator, out_us);
+ ble_sm_test_util_params_to_entity(params, !we_are_initiator, out_peer);
+}
+
+static void
+ble_sm_test_util_init_good(struct ble_sm_test_params *params,
+ int we_are_initiator,
+ struct ble_hs_conn **out_conn,
+ struct ble_sm_test_util_entity *out_us,
+ struct ble_sm_test_util_entity *out_peer)
+{
+ struct ble_hs_conn *conn;
+
+ ble_sm_test_util_init();
+
+ ble_sm_test_util_params_to_entities(params, we_are_initiator,
+ out_us, out_peer);
+
+ ble_hs_cfg.sm_io_cap = out_us->pair_cmd->io_cap;
+ ble_hs_cfg.sm_oob_data_flag = out_us->pair_cmd->oob_data_flag;
+ ble_hs_cfg.sm_bonding = !!(out_us->pair_cmd->authreq &
+ BLE_SM_PAIR_AUTHREQ_BOND);
+ ble_hs_cfg.sm_mitm = !!(out_us->pair_cmd->authreq &
+ BLE_SM_PAIR_AUTHREQ_MITM);
+ ble_hs_cfg.sm_sc = !!(out_us->pair_cmd->authreq &
+ BLE_SM_PAIR_AUTHREQ_SC);
+ ble_hs_cfg.sm_keypress = !!(out_us->pair_cmd->authreq &
+ BLE_SM_PAIR_AUTHREQ_KEYPRESS);
+
+ if (we_are_initiator) {
+ ble_hs_cfg.sm_our_key_dist = out_us->pair_cmd->init_key_dist;
+ ble_hs_cfg.sm_their_key_dist = out_us->pair_cmd->resp_key_dist;
+ } else {
+ ble_hs_cfg.sm_our_key_dist = out_us->pair_cmd->resp_key_dist;
+ ble_hs_cfg.sm_their_key_dist = out_us->pair_cmd->init_key_dist;
+ }
+
+ ble_hs_test_util_set_public_addr(out_us->id_addr);
+ ble_sm_dbg_set_next_pair_rand(out_us->randoms[0].value);
+ ble_sm_dbg_set_next_ediv(out_us->ediv);
+ ble_sm_dbg_set_next_master_id_rand(out_us->rand_num);
+ ble_sm_dbg_set_next_ltk(out_us->ltk);
+ ble_hs_priv_update_irk(out_us->id_info->irk);
+ ble_sm_dbg_set_next_csrk(out_us->sign_info->sig_key);
+
+ if (out_us->public_key != NULL) {
+ ble_sm_dbg_set_sc_keys(out_us->public_key->x, params->our_priv_key);
+ }
+
+ ble_hs_test_util_create_rpa_conn(2, out_us->rpa,
+ out_peer->addr_type,
+ out_peer->id_addr, out_peer->rpa,
+ ble_sm_test_util_conn_cb,
+ NULL);
+
+ /* This test code 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_initiator) {
+ /* Peer is the initiator so we must be the slave. */
+ conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
+ }
+
+ if (out_conn != NULL) {
+ *out_conn = conn;
+ }
+}
struct ble_gap_passkey_action ble_sm_test_ioact;
@@ -309,6 +483,66 @@ ble_sm_test_util_rx_dhkey_check(uint16_t conn_handle,
}
static void
+ble_sm_test_util_rx_enc_info(uint16_t conn_handle,
+ struct ble_sm_enc_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_ENC_INFO_SZ);
+
+ om = ble_hs_misc_pkthdr();
+ TEST_ASSERT_FATAL(om != NULL);
+
+ payload_len = BLE_SM_HDR_SZ + BLE_SM_ENC_INFO_SZ;
+
+ v = os_mbuf_extend(om, payload_len);
+ TEST_ASSERT_FATAL(v != NULL);
+
+ ble_sm_enc_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_master_id(uint16_t conn_handle,
+ struct ble_sm_master_id *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_MASTER_ID_SZ);
+
+ om = ble_hs_misc_pkthdr();
+ TEST_ASSERT_FATAL(om != NULL);
+
+ payload_len = BLE_SM_HDR_SZ + BLE_SM_MASTER_ID_SZ;
+
+ v = os_mbuf_extend(om, payload_len);
+ TEST_ASSERT_FATAL(v != NULL);
+
+ ble_sm_master_id_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)
@@ -510,6 +744,38 @@ ble_sm_test_util_verify_tx_dhkey_check(
}
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;
+
+ ble_hs_test_util_tx_all();
+ 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, 16) == 0);
+
+ /* Ensure LTK is sent in little endian. */
+ TEST_ASSERT(memcmp(om->om_data, cmd.ltk, 16) == 0);
+}
+
+static void
+ble_sm_test_util_verify_tx_master_id(struct ble_sm_master_id *exp_cmd)
+{
+ struct ble_sm_master_id cmd;
+ struct os_mbuf *om;
+
+ ble_hs_test_util_tx_all();
+ om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_MASTER_ID,
+ BLE_SM_MASTER_ID_SZ);
+ ble_sm_master_id_parse(om->om_data, om->om_len, &cmd);
+
+ TEST_ASSERT(cmd.ediv == exp_cmd->ediv);
+ TEST_ASSERT(cmd.rand_val == exp_cmd->rand_val);
+}
+
+static void
ble_sm_test_util_verify_tx_id_info(struct ble_sm_id_info *exp_cmd)
{
struct ble_sm_id_info cmd;
@@ -566,20 +832,6 @@ ble_sm_test_util_verify_tx_sign_info(struct ble_sm_sign_info *exp_cmd)
}
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;
@@ -587,8 +839,7 @@ ble_sm_test_util_verify_tx_sec_req(struct ble_sm_sec_req *exp_cmd)
ble_hs_test_util_tx_all();
- om = ble_sm_test_util_verify_tx_hdr(BLE_SM_OP_SEC_REQ,
- BLE_SM_SEC_REQ_SZ);
+ 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);
@@ -602,7 +853,7 @@ ble_sm_test_util_verify_tx_pair_fail(
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_SZ);
ble_sm_pair_fail_parse(om->om_data, om->om_len, &cmd);
TEST_ASSERT(cmd.reason == exp_cmd->reason);
@@ -826,115 +1077,33 @@ ble_sm_test_util_io_check_post(struct ble_sm_test_passkey_info *passkey_info,
}
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_our_sec(&key_sec, &value_sec);
- TEST_ASSERT(rc == BLE_HS_ENOENT);
- } else {
- 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_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);
- 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_peer_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_our_sec(&key_sec, &value_sec);
- TEST_ASSERT(rc == BLE_HS_ENOENT);
- } else {
- 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_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);
- 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_our_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)
+ble_sm_test_util_verify_persist(struct ble_sm_test_params *params,
+ int we_are_initiator)
{
+ struct ble_sm_test_util_entity peer_entity;
+ struct ble_sm_test_util_entity our_entity;
struct ble_store_value_sec value_sec;
struct ble_store_key_sec key_sec;
- 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 ltk_expected;
int peer_irk_expected;
int our_irk_expected;
int bonding;
+ int sc;
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 = params->resp_addr_type;
- peer_id_addr = params->resp_id_addr;
-
- 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;
+ ble_sm_test_util_params_to_entities(params, we_are_initiator,
+ &our_entity, &peer_entity);
- peer_addr_type = params->init_addr_type;
- peer_id_addr = params->init_id_addr;
+ sc = params->pair_req.authreq & BLE_SM_PAIR_AUTHREQ_SC &&
+ params->pair_rsp.authreq & BLE_SM_PAIR_AUTHREQ_SC;
- 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);
+ bonding = params->pair_req.authreq & BLE_SM_PAIR_AUTHREQ_BOND &&
+ params->pair_rsp.authreq & BLE_SM_PAIR_AUTHREQ_BOND;
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_peer_sec(&key_sec, &value_sec);
if (!bonding) {
TEST_ASSERT(rc == BLE_HS_ENOENT);
@@ -942,26 +1111,32 @@ ble_sm_test_util_verify_sc_persist(struct ble_sm_test_sc_params *params,
} else {
TEST_ASSERT_FATAL(rc == 0);
- 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_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);
+ ltk_expected =
+ sc || !!(peer_entity.key_dist & BLE_SM_PAIR_KEY_DIST_ENC);
+ peer_irk_expected =
+ !!(peer_entity.key_dist & BLE_SM_PAIR_KEY_DIST_ID);
+ csrk_expected =
+ !!(peer_entity.key_dist & BLE_SM_PAIR_KEY_DIST_SIGN);
+
+ TEST_ASSERT(value_sec.peer_addr_type == peer_entity.id_addr_type);
+ TEST_ASSERT(memcmp(value_sec.peer_addr, peer_entity.id_addr, 6) == 0);
+ TEST_ASSERT(value_sec.ediv == peer_entity.ediv);
+ TEST_ASSERT(value_sec.rand_num == peer_entity.rand_num);
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.ltk_present == ltk_expected);
+ TEST_ASSERT(memcmp(value_sec.ltk, peer_entity.ltk, 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(memcmp(value_sec.irk,
+ peer_entity.id_info->irk, 16) == 0);
}
TEST_ASSERT(value_sec.csrk_present == csrk_expected);
if (csrk_expected) {
- TEST_ASSERT(memcmp(value_sec.csrk, peer_csrk, 16) == 0);
+ TEST_ASSERT(memcmp(value_sec.csrk,
+ peer_entity.sign_info->sig_key, 16) == 0);
}
}
@@ -971,26 +1146,32 @@ ble_sm_test_util_verify_sc_persist(struct ble_sm_test_sc_params *params,
} else {
TEST_ASSERT_FATAL(rc == 0);
- 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_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);
+ ltk_expected =
+ sc || !!(our_entity.key_dist & BLE_SM_PAIR_KEY_DIST_ENC);
+ our_irk_expected =
+ !!(our_entity.key_dist & BLE_SM_PAIR_KEY_DIST_ID);
+ csrk_expected =
+ !!(our_entity.key_dist & BLE_SM_PAIR_KEY_DIST_SIGN);
+
+ TEST_ASSERT(value_sec.peer_addr_type == peer_entity.id_addr_type);
+ TEST_ASSERT(memcmp(value_sec.peer_addr, peer_entity.id_addr, 6) == 0);
+ TEST_ASSERT(value_sec.ediv == our_entity.ediv);
+ TEST_ASSERT(value_sec.rand_num == our_entity.rand_num);
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.ltk_present == ltk_expected);
+ TEST_ASSERT(memcmp(value_sec.ltk, our_entity.ltk, 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(memcmp(value_sec.irk,
+ our_entity.id_info->irk, 16) == 0);
}
TEST_ASSERT(value_sec.csrk_present == csrk_expected);
if (csrk_expected) {
- TEST_ASSERT(memcmp(value_sec.csrk, our_csrk, 16) == 0);
+ TEST_ASSERT(memcmp(value_sec.csrk,
+ our_entity.sign_info->sig_key, 16) == 0);
}
}
@@ -1003,32 +1184,27 @@ ble_sm_test_util_verify_sc_persist(struct ble_sm_test_sc_params *params,
/* 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);
+ ble_sm_test_util_verify_tx_add_resolve_list(peer_entity.id_addr_type,
+ peer_entity.id_addr,
+ peer_entity.id_info->irk,
+ our_entity.id_info->irk);
}
}
-void
-ble_sm_test_util_us_lgcy_good(
- struct ble_sm_test_lgcy_params *params)
+static void
+ble_sm_test_util_peer_bonding_good(int send_enc_req,
+ uint8_t *our_rpa,
+ uint8_t peer_addr_type,
+ uint8_t *peer_id_addr,
+ uint8_t *peer_rpa,
+ uint8_t *ltk, int authenticated,
+ uint16_t ediv, uint64_t rand_num)
{
struct ble_hs_conn *conn;
int rc;
- ble_sm_test_util_init();
- 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);
-
- 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_id_addr,
- ble_sm_test_util_conn_cb,
- NULL);
+ ble_hs_test_util_create_rpa_conn(2, our_rpa, peer_addr_type, peer_id_addr,
+ peer_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
@@ -1037,72 +1213,40 @@ ble_sm_test_util_us_lgcy_good(
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);
- 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, ¶ms->sec_req, 0);
- } else {
- /* Initiate the pairing procedure. */
- rc = ble_gap_security_initiate(2);
- TEST_ASSERT_FATAL(rc == 0);
+ if (send_enc_req) {
+ rc = ble_sm_slave_initiate(2);
+ TEST_ASSERT(rc == 0);
}
- /* Ensure we sent the expected pair request. */
- ble_hs_test_util_tx_all();
- ble_sm_test_util_verify_tx_pair_req(¶ms->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, ¶ms->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(¶ms->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, ¶ms->confirm_rsp);
+ /* 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);
- 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(¶ms->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);
+ /* Ensure the LTK request event got sent to the application. */
+ TEST_ASSERT(ble_sm_test_store_obj_type ==
+ BLE_STORE_OBJ_TYPE_OUR_SEC);
+ TEST_ASSERT(ble_sm_test_store_key.sec.peer_addr_type ==
+ ble_hs_misc_addr_type_to_id(peer_addr_type));
+ 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);
- /* Receive a pair random from the peer. */
- ble_sm_test_util_rx_random(2, ¶ms->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(¶ms->enc_info_req);
- }
+ ble_sm_test_util_io_inject_bad(2, BLE_SM_IOACT_NONE);
- /* 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);
+ /* Ensure we sent the expected long term key request reply command. */
+ 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, params->passkey_info.passkey.action);
+ 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);
@@ -1114,20 +1258,140 @@ ble_sm_test_util_us_lgcy_good(
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);
+ TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
+ 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.encrypted);
TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
- conn->bhc_sec_state.authenticated);
+ authenticated);
- /* Verify the appropriate security material was persisted. */
- ble_sm_test_util_verify_lgcy_persist(params);
+ ble_hs_test_util_conn_disconnect(2);
}
void
-ble_sm_test_util_peer_fail_inval(
+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_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);
+
+ 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);
+}
+
+/**
+ * @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 *our_rpa,
+ uint8_t peer_addr_type,
+ uint8_t *peer_id_addr, uint8_t *peer_rpa,
+ 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_rpa_conn(2, our_rpa, peer_addr_type, peer_id_addr,
+ peer_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
+ * 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);
+}
+
+void
+ble_sm_test_util_peer_fail_inval(
int we_are_master,
uint8_t *init_id_addr,
uint8_t *resp_addr,
@@ -1262,115 +1526,231 @@ ble_sm_test_util_peer_lgcy_fail_confirm(
}
static void
-ble_sm_test_util_peer_lgcy_good_once(struct ble_sm_test_lgcy_params *params)
+ble_sm_test_util_bonding_all(struct ble_sm_test_params *params,
+ int we_are_original_initiator)
{
- struct ble_hs_conn *conn;
- int rc;
+ struct ble_sm_test_util_entity peer_entity;
+ struct ble_sm_test_util_entity our_entity;
+ int sc;
- ble_sm_test_util_init();
+ if (!(params->pair_req.authreq & BLE_SM_PAIR_AUTHREQ_BOND) ||
+ !(params->pair_rsp.authreq & BLE_SM_PAIR_AUTHREQ_BOND)) {
- 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;
+ /* Bonding not performed. */
+ return;
+ }
- 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);
+ sc = params->pair_req.authreq & BLE_SM_PAIR_AUTHREQ_SC &&
+ params->pair_rsp.authreq & BLE_SM_PAIR_AUTHREQ_SC;
+
+ ble_sm_test_util_params_to_entities(params, we_are_original_initiator,
+ &our_entity, &peer_entity);
+
+ if (sc || peer_entity.key_dist & BLE_SM_PAIR_KEY_DIST_ENC) {
+ /* We are master; we initiate procedure. */
+ ble_sm_test_util_us_bonding_good(0, our_entity.rpa,
+ peer_entity.addr_type,
+ peer_entity.id_addr,
+ peer_entity.rpa,
+ peer_entity.ltk,
+ params->authenticated,
+ peer_entity.ediv,
+ peer_entity.rand_num);
+
+ /* We are master; peer initiates procedure via security request. */
+ ble_sm_test_util_us_bonding_good(1, our_entity.rpa,
+ peer_entity.addr_type,
+ peer_entity.id_addr,
+ peer_entity.rpa,
+ peer_entity.ltk,
+ params->authenticated,
+ peer_entity.ediv,
+ peer_entity.rand_num);
+ }
+
+ if (sc || our_entity.key_dist & BLE_SM_PAIR_KEY_DIST_ENC) {
+ /* Peer is master; peer initiates procedure. */
+ ble_sm_test_util_peer_bonding_good(0, our_entity.rpa,
+ peer_entity.addr_type,
+ peer_entity.id_addr,
+ peer_entity.rpa,
+ our_entity.ltk,
+ params->authenticated,
+ our_entity.ediv,
+ our_entity.rand_num);
+
+ /* Peer is master; we initiate procedure via security request. */
+ ble_sm_test_util_peer_bonding_good(1, our_entity.rpa,
+ peer_entity.addr_type,
+ peer_entity.id_addr,
+ peer_entity.rpa,
+ our_entity.ltk,
+ params->authenticated,
+ our_entity.ediv,
+ our_entity.rand_num);
+ }
+}
+
+static void
+ble_sm_test_util_rx_keys(struct ble_sm_test_params *params,
+ int we_are_initiator)
+{
+ struct ble_sm_id_addr_info *peer_id_addr_info;
+ struct ble_sm_sign_info *peer_sign_info;
+ struct ble_sm_master_id *peer_master_id;
+ struct ble_sm_enc_info *peer_enc_info;
+ struct ble_sm_id_info *peer_id_info;
+ uint8_t peer_key_dist;
+ int sc;
- if (params->has_enc_info_req) {
- ble_sm_dbg_set_next_ltk(params->enc_info_req.ltk);
+ if (we_are_initiator) {
+ peer_key_dist = params->pair_rsp.resp_key_dist;
+ peer_id_addr_info = ¶ms->id_addr_info_req;
+ peer_sign_info = ¶ms->sign_info_req;
+ peer_master_id = ¶ms->master_id_req;
+ peer_enc_info = ¶ms->enc_info_req;
+ peer_id_info = ¶ms->id_info_req;
+ } else {
+ peer_key_dist = params->pair_rsp.init_key_dist;
+ peer_id_addr_info = ¶ms->id_addr_info_rsp;
+ peer_sign_info = ¶ms->sign_info_rsp;
+ peer_master_id = ¶ms->master_id_rsp;
+ peer_enc_info = ¶ms->enc_info_rsp;
+ peer_id_info = ¶ms->id_info_rsp;
}
- ble_hs_test_util_create_conn(2, params->init_id_addr,
- ble_sm_test_util_conn_cb,
- NULL);
+ sc = params->pair_req.authreq & BLE_SM_PAIR_AUTHREQ_SC &&
+ params->pair_rsp.authreq & BLE_SM_PAIR_AUTHREQ_SC;
- /* 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();
+ /* Receive key material from peer. */
+ if (!sc && (peer_key_dist & BLE_SM_PAIR_KEY_DIST_ENC)) {
+ ble_sm_test_util_rx_enc_info(2, peer_enc_info, 0);
+ ble_sm_test_util_rx_master_id(2, peer_master_id, 0);
+ }
+ if (peer_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, peer_id_info, 0);
+ ble_sm_test_util_rx_id_addr_info(2, peer_id_addr_info, 0);
+ }
+ if (peer_key_dist & BLE_SM_PAIR_KEY_DIST_SIGN) {
+ ble_sm_test_util_rx_sign_info(2, peer_sign_info, 0);
+ }
+}
- /* Peer is the initiator so we must be the slave. */
- conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
+static void
+ble_sm_test_util_verify_tx_keys(struct ble_sm_test_params *params,
+ int we_are_initiator)
+{
+ struct ble_sm_id_addr_info *our_id_addr_info;
+ struct ble_sm_sign_info *our_sign_info;
+ struct ble_sm_master_id *our_master_id;
+ struct ble_sm_enc_info *our_enc_info;
+ struct ble_sm_id_info *our_id_info;
+ uint8_t our_key_dist;
+ int sc;
- TEST_ASSERT(!conn->bhc_sec_state.encrypted);
- TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+ if (we_are_initiator) {
+ our_key_dist = params->pair_rsp.init_key_dist;
+ our_id_addr_info = ¶ms->id_addr_info_rsp;
+ our_sign_info = ¶ms->sign_info_rsp;
+ our_master_id = ¶ms->master_id_rsp;
+ our_enc_info = ¶ms->enc_info_rsp;
+ our_id_info = ¶ms->id_info_rsp;
+ } else {
+ our_key_dist = params->pair_rsp.resp_key_dist;
+ our_id_addr_info = ¶ms->id_addr_info_req;
+ our_sign_info = ¶ms->sign_info_req;
+ our_master_id = ¶ms->master_id_req;
+ our_enc_info = ¶ms->enc_info_req;
+ our_id_info = ¶ms->id_info_req;
+ }
- if (params->has_sec_req) {
- rc = ble_sm_slave_initiate(2);
- TEST_ASSERT(rc == 0);
+ sc = params->pair_req.authreq & BLE_SM_PAIR_AUTHREQ_SC &&
+ params->pair_rsp.authreq & BLE_SM_PAIR_AUTHREQ_SC;
- /* Ensure we sent the expected security request. */
- ble_sm_test_util_verify_tx_sec_req(¶ms->sec_req);
+ if (!sc && our_key_dist & BLE_SM_PAIR_KEY_DIST_ENC) {
+ ble_sm_test_util_verify_tx_enc_info(our_enc_info);
+ ble_sm_test_util_verify_tx_master_id(our_master_id);
+ }
+ if (our_key_dist & BLE_SM_PAIR_KEY_DIST_ID) {
+ ble_sm_test_util_verify_tx_id_info(our_id_info);
+ ble_sm_test_util_verify_tx_id_addr_info(our_id_addr_info);
}
+ if (our_key_dist & BLE_SM_PAIR_KEY_DIST_SIGN) {
+ ble_sm_test_util_verify_tx_sign_info(our_sign_info);
+ }
+}
+
+static void
+ble_sm_test_util_us_lgcy_good_once(struct ble_sm_test_params *params)
+{
+ struct ble_sm_test_util_entity peer_entity;
+ struct ble_sm_test_util_entity our_entity;
+ struct ble_hs_conn *conn;
+ int rc;
+
+ ble_sm_test_util_init_good(params, 1, &conn, &our_entity, &peer_entity);
- /* Receive a pair request from the peer. */
- ble_sm_test_util_rx_pair_req(2, ¶ms->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);
+ TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
- /* Ensure we sent the expected pair response. */
+ ble_hs_test_util_set_ack(
+ host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_START_ENCRYPT), 0);
+ if (params->sec_req.authreq != 0) {
+ ble_sm_test_util_rx_sec_req(2, ¶ms->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_rsp(¶ms->pair_rsp);
+ ble_sm_test_util_verify_tx_pair_req(our_entity.pair_cmd);
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(¶ms->passkey_info,
- BLE_SM_PROC_STATE_CONFIRM);
-
- /* Receive a pair confirm from the peer. */
- ble_sm_test_util_rx_confirm(2, ¶ms->confirm_req);
+ /* Receive a pair response from the peer. */
+ ble_sm_test_util_rx_pair_rsp(2, peer_entity.pair_cmd, 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(¶ms->passkey_info,
- BLE_SM_PROC_STATE_CONFIRM);
+ ble_sm_test_util_io_inject(¶ms->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(¶ms->confirm_rsp);
+ ble_sm_test_util_verify_tx_pair_confirm(our_entity.confirms);
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, ¶ms->random_req, 0);
+ /* Receive a pair confirm from the peer. */
+ ble_sm_test_util_rx_confirm(2, peer_entity.confirms);
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(¶ms->random_rsp);
+ ble_sm_test_util_verify_tx_pair_random(our_entity.randoms);
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);
+ /* Receive a pair random from the peer. */
+ ble_sm_test_util_rx_random(2, peer_entity.randoms, 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->stk);
+ /* 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->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);
@@ -1378,9 +1758,11 @@ ble_sm_test_util_peer_lgcy_good_once(struct ble_sm_test_lgcy_params *params)
/* Receive an encryption changed event. */
ble_sm_test_util_rx_enc_change(2, 0, 1);
- if (params->has_enc_info_req) {
- return; // XXX
- }
+ /* Receive key material from peer. */
+ ble_sm_test_util_rx_keys(params, 1);
+
+ /* Verify key material gets sent to peer. */
+ ble_sm_test_util_verify_tx_keys(params, 1);
/* Pairing should now be complete. */
TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
@@ -1389,8 +1771,7 @@ ble_sm_test_util_peer_lgcy_good_once(struct ble_sm_test_lgcy_params *params)
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);
+ 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 ==
@@ -1399,199 +1780,116 @@ ble_sm_test_util_peer_lgcy_good_once(struct ble_sm_test_lgcy_params *params)
conn->bhc_sec_state.authenticated);
/* Verify the appropriate security material was persisted. */
- ble_sm_test_util_verify_lgcy_persist(params);
+ ble_sm_test_util_verify_persist(params, 1);
+
+ ble_hs_test_util_conn_disconnect(2);
}
void
-ble_sm_test_util_peer_lgcy_good(struct ble_sm_test_lgcy_params *params)
+ble_sm_test_util_us_lgcy_good(struct ble_sm_test_params *params)
{
- params->passkey_info.io_before_rx = 0;
- ble_sm_test_util_peer_lgcy_good_once(params);
+ /*** We are master. */
- params->passkey_info.io_before_rx = 1;
- ble_sm_test_util_peer_lgcy_good_once(params);
+ /* We initiate pairing. */
+ params->sec_req.authreq = 0;
+ ble_sm_test_util_us_lgcy_good_once(params);
+
+ /* Peer initiates with security request. */
+ params->sec_req.authreq = params->pair_rsp.authreq;
+ ble_sm_test_util_us_lgcy_good_once(params);
+
+ /* Verify link can be restored via the encryption procedure. */
+ ble_sm_test_util_bonding_all(params, 1);
}
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)
+ble_sm_test_util_peer_lgcy_good_once(struct ble_sm_test_params *params)
{
+ struct ble_sm_test_util_entity peer_entity;
+ struct ble_sm_test_util_entity our_entity;
struct ble_hs_conn *conn;
int rc;
- 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);
- conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
- ble_hs_unlock();
+ ble_sm_test_util_init_good(params, 0, &conn, &our_entity, &peer_entity);
TEST_ASSERT(!conn->bhc_sec_state.encrypted);
TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
- if (send_enc_req) {
+ if (params->sec_req.authreq != 0) {
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(¶ms->sec_req);
}
- /* 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);
+ /* Receive a pair request from the peer. */
+ ble_sm_test_util_rx_pair_req(2, peer_entity.pair_cmd, 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 the LTK request event got sent to the application. */
- TEST_ASSERT(ble_sm_test_store_obj_type ==
- 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);
- TEST_ASSERT(ble_sm_test_store_key.sec.ediv == ediv);
- TEST_ASSERT(ble_sm_test_store_key.sec.rand_num == rand_num);
-
+ /* Ensure we sent the expected pair response. */
+ ble_hs_test_util_tx_all();
+ ble_sm_test_util_verify_tx_pair_rsp(our_entity.pair_cmd);
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);
+ 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, ltk);
+ ble_sm_test_util_io_check_pre(¶ms->passkey_info,
+ BLE_SM_PROC_STATE_CONFIRM);
+
+ /* Receive a pair confirm from the peer. */
+ ble_sm_test_util_rx_confirm(2, peer_entity.confirms);
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);
-}
-
-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();
+ ble_sm_test_util_io_inject_bad(2, params->passkey_info.passkey.action);
- TEST_ASSERT(!conn->bhc_sec_state.encrypted);
- TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
+ ble_sm_test_util_io_check_post(¶ms->passkey_info,
+ BLE_SM_PROC_STATE_CONFIRM);
- /* 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);
+ /* Ensure we sent the expected pair confirm. */
+ ble_hs_test_util_tx_all();
+ ble_sm_test_util_verify_tx_pair_confirm(our_entity.confirms);
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 the LTK request event got sent to the application. */
- TEST_ASSERT(ble_sm_test_store_obj_type ==
- 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);
-
+ /* Receive a pair random from the peer. */
+ ble_sm_test_util_rx_random(2, peer_entity.randoms, 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 neg reply command. */
- ble_sm_test_util_verify_tx_lt_key_req_neg_reply(2);
-
- /* Ensure the security procedure was aborted. */
+ /* Ensure we sent the expected pair random. */
+ ble_hs_test_util_tx_all();
+ ble_sm_test_util_verify_tx_pair_random(our_entity.randoms);
TEST_ASSERT(!conn->bhc_sec_state.encrypted);
- TEST_ASSERT(!conn->bhc_sec_state.authenticated);
- 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(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() == 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);
- }
+ 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, rand_num, ediv, ltk);
+ /* 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, BLE_SM_IOACT_NONE);
+ 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. */
+ ble_sm_test_util_verify_tx_keys(params, 0);
+
+ /* Receive key material from peer. */
+ ble_sm_test_util_rx_keys(params, 0);
+
/* Pairing should now be complete. */
TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
@@ -1600,100 +1898,96 @@ ble_sm_test_util_us_bonding_good(int send_enc_req,
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);
+ params->authenticated);
/* Verify that connection has correct security state. */
- TEST_ASSERT(ble_sm_test_sec_state.encrypted);
+ TEST_ASSERT(ble_sm_test_sec_state.encrypted ==
+ conn->bhc_sec_state.encrypted);
TEST_ASSERT(ble_sm_test_sec_state.authenticated ==
- authenticated);
+ conn->bhc_sec_state.authenticated);
+
+ /* Verify the appropriate security material was persisted. */
+ ble_sm_test_util_verify_persist(params, 0);
ble_hs_test_util_conn_disconnect(2);
}
-static void
-ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
+void
+ble_sm_test_util_peer_lgcy_good(struct ble_sm_test_params *params)
{
- struct ble_hs_conn *conn;
- int num_iters;
- int rc;
- int i;
+ /*** Peer is master. */
- 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;
+ /* Peer performs IO first; peer initiates pairing. */
+ params->passkey_info.io_before_rx = 0;
+ params->sec_req.authreq = 0;
+ ble_sm_test_util_peer_lgcy_good_once(params);
- ble_hs_test_util_set_public_addr(params->resp_id_addr);
- ble_sm_dbg_set_next_pair_rand(params->random_rsp[0].value);
+ /* Peer performs IO first; we initiate with security request. */
+ params->passkey_info.io_before_rx = 0;
+ params->sec_req.authreq = params->pair_rsp.authreq;
+ ble_sm_test_util_peer_lgcy_good_once(params);
- ble_sm_dbg_set_sc_keys(params->public_key_rsp.x, params->our_priv_key);
+ /* We perform IO first; peer initiates pairing. */
+ params->passkey_info.io_before_rx = 1;
+ params->sec_req.authreq = 0;
+ ble_sm_test_util_peer_lgcy_good_once(params);
- 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);
- }
+ /* We perform IO first; we initiate with security request. */
+ params->passkey_info.io_before_rx = 1;
+ params->sec_req.authreq = params->pair_rsp.authreq;
+ ble_sm_test_util_peer_lgcy_good_once(params);
- 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);
+ /* Verify link can be restored via the encryption procedure. */
+ ble_sm_test_util_bonding_all(params, 0);
+}
- /* 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();
+static void
+ble_sm_test_util_us_sc_good_once(struct ble_sm_test_params *params)
+{
+ struct ble_sm_test_util_entity peer_entity;
+ struct ble_sm_test_util_entity our_entity;
+ struct ble_hs_conn *conn;
+ int num_iters;
+ int rc;
+ int i;
- /* Peer is the initiator so we must be the slave. */
- conn->bhc_flags &= ~BLE_HS_CONN_F_MASTER;
+ ble_sm_test_util_init_good(params, 1, &conn, &our_entity, &peer_entity);
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(¶ms->sec_req);
+ ble_hs_test_util_set_ack(
+ host_hci_opcode_join(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_START_ENCRYPT), 0);
+ if (params->sec_req.authreq != 0) {
+ ble_sm_test_util_rx_sec_req(2, ¶ms->sec_req, 0);
+ } else {
+ /* Initiate the pairing procedure. */
+ rc = ble_gap_security_initiate(2);
+ TEST_ASSERT_FATAL(rc == 0);
}
- /* Receive a pair request from the peer. */
- ble_sm_test_util_rx_pair_req(2, ¶ms->pair_req, 0);
+ /* Ensure we sent the expected pair request. */
+ ble_hs_test_util_tx_all();
+ ble_sm_test_util_verify_tx_pair_req(our_entity.pair_cmd);
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(¶ms->pair_rsp);
+ /* Receive a pair response from the peer. */
+ ble_sm_test_util_rx_pair_rsp(2, peer_entity.pair_cmd, 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);
- /* Receive a public key from the peer. */
- ble_sm_test_util_rx_public_key(2, ¶ms->public_key_req);
+ /* Ensure we sent the expected public key. */
+ ble_hs_test_util_tx_all();
+ ble_sm_test_util_verify_tx_public_key(our_entity.public_key);
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(¶ms->public_key_rsp);
+ /* Receive a public key from the peer. */
+ ble_sm_test_util_rx_public_key(2, peer_entity.public_key);
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);
@@ -1708,81 +2002,66 @@ ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
break;
}
- ble_sm_test_util_io_check_pre(¶ms->passkey_info,
- BLE_SM_PROC_STATE_CONFIRM);
+ ble_sm_test_util_io_inject(¶ms->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);
+ our_entity.randoms[i + 1].value);
}
- }
- if (i == 0) {
- ble_sm_test_util_io_check_post(¶ms->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(our_entity.confirms + 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 confirm. */
- ble_hs_test_util_tx_all();
- ble_sm_test_util_verify_tx_pair_confirm(params->confirm_rsp + i);
+ /* Receive a pair confirm from the peer. */
+ ble_sm_test_util_rx_confirm(2, peer_entity.confirms + 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);
+ /* Ensure we sent the expected pair random. */
+ ble_hs_test_util_tx_all();
+ ble_sm_test_util_verify_tx_pair_random(our_entity.randoms + 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_rsp + i);
+ /* Receive a pair random from the peer. */
+ ble_sm_test_util_rx_random(2, peer_entity.randoms + 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_check_pre(¶ms->passkey_info,
- BLE_SM_PROC_STATE_DHKEY_CHECK);
-
- /* Receive a dhkey check from the peer. */
- ble_sm_test_util_rx_dhkey_check(2, ¶ms->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(¶ms->passkey_info,
- BLE_SM_PROC_STATE_DHKEY_CHECK);
+ ble_sm_test_util_io_inject(¶ms->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(¶ms->dhkey_check_rsp);
+ ble_sm_test_util_verify_tx_dhkey_check(our_entity.dhkey_check);
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);
+ /* Receive a dhkey check from the peer. */
+ ble_sm_test_util_rx_dhkey_check(2, peer_entity.dhkey_check, 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);
+ /* 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);
@@ -1790,26 +2069,11 @@ ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
/* 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(¶ms->id_info_req);
- ble_sm_test_util_verify_tx_id_addr_info(¶ms->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(¶ms->sign_info_req);
- }
-
/* 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, ¶ms->id_info_rsp, 0);
- ble_sm_test_util_rx_id_addr_info(2, ¶ms->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, ¶ms->sign_info_rsp, 0);
- }
+ ble_sm_test_util_rx_keys(params, 1);
+
+ /* Verify key material gets sent to peer. */
+ ble_sm_test_util_verify_tx_keys(params, 1);
/* Pairing should now be complete. */
TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
@@ -1828,130 +2092,75 @@ ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
conn->bhc_sec_state.authenticated);
/* Verify the appropriate security material was persisted. */
- ble_sm_test_util_verify_sc_persist(params, 0);
+ ble_sm_test_util_verify_persist(params, 1);
ble_hs_test_util_conn_disconnect(2);
}
void
-ble_sm_test_util_peer_sc_good(struct ble_sm_test_sc_params *params)
+ble_sm_test_util_us_sc_good(struct ble_sm_test_params *params)
{
- /*** Peer is master; peer initiates pairing. */
+ /*** We are master. */
- /* Peer performs IO first. */
+ /* We initiate pairing. */
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);
+ params->sec_req.authreq = 0;
+ ble_sm_test_util_us_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_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_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_id_addr,
- params->ltk, params->authenticated,
- 0, 0);
+ /* Peer initiates with security request. */
+ params->passkey_info.io_before_rx = 0;
+ params->sec_req.authreq = params->pair_rsp.authreq;
+ ble_sm_test_util_us_sc_good_once(params);
- /* We are master; peer initiates procedure via security request. */
- ble_sm_test_util_us_bonding_good(1, 0, params->init_id_addr,
- params->ltk, params->authenticated,
- 0, 0);
+ /* Verify link can be restored via the encryption procedure. */
+ ble_sm_test_util_bonding_all(params, 1);
}
-void
-ble_sm_test_util_us_sc_good(struct ble_sm_test_sc_params *params)
+static void
+ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_params *params)
{
+ struct ble_sm_test_util_entity peer_entity;
+ struct ble_sm_test_util_entity our_entity;
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_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);
-
- 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_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
- * can assume the connection list is unchanging.
- */
- ble_hs_lock();
- conn = ble_hs_conn_find(2);
- TEST_ASSERT_FATAL(conn != NULL);
- ble_hs_unlock();
+ ble_sm_test_util_init_good(params, 0, &conn, &our_entity, &peer_entity);
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, ¶ms->sec_req, 0);
- } else {
- /* Initiate the pairing procedure. */
- rc = ble_gap_security_initiate(2);
- TEST_ASSERT_FATAL(rc == 0);
+ if (params->sec_req.authreq != 0) {
+ 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(¶ms->sec_req);
}
- /* Ensure we sent the expected pair request. */
- ble_hs_test_util_tx_all();
- ble_sm_test_util_verify_tx_pair_req(¶ms->pair_req);
+ /* Receive a pair request from the peer. */
+ ble_sm_test_util_rx_pair_req(2, peer_entity.pair_cmd, 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);
- /* Receive a pair response from the peer. */
- ble_sm_test_util_rx_pair_rsp(2, ¶ms->pair_rsp, 0);
+ /* Ensure we sent the expected pair response. */
+ ble_hs_test_util_tx_all();
+ ble_sm_test_util_verify_tx_pair_rsp(our_entity.pair_cmd);
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(¶ms->public_key_req);
+ /* Receive a public key from the peer. */
+ ble_sm_test_util_rx_public_key(2, peer_entity.public_key);
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, ¶ms->public_key_rsp);
+ /* Ensure we sent the expected public key. */
+ ble_hs_test_util_tx_all();
+ ble_sm_test_util_verify_tx_public_key(our_entity.public_key);
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);
@@ -1966,66 +2175,81 @@ ble_sm_test_util_us_sc_good(struct ble_sm_test_sc_params *params)
break;
}
- ble_sm_test_util_io_inject(¶ms->passkey_info,
- BLE_SM_PROC_STATE_CONFIRM);
+ ble_sm_test_util_io_check_pre(¶ms->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);
+ /* Receive a pair confirm from the peer. */
+ ble_sm_test_util_rx_confirm(2, peer_entity.confirms + 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(
+ our_entity.randoms[i + 1].value);
+ }
}
- /* Receive a pair confirm from the peer. */
- ble_sm_test_util_rx_confirm(2, params->confirm_rsp + i);
+ if (i == 0) {
+ ble_sm_test_util_io_check_post(¶ms->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(our_entity.confirms + 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);
+ /* Receive a pair random from the peer. */
+ ble_sm_test_util_rx_random(2, peer_entity.randoms + 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);
- /* Receive a pair random from the peer. */
- ble_sm_test_util_rx_random(2, params->random_rsp + i, 0);
+ /* Ensure we sent the expected pair random. */
+ ble_hs_test_util_tx_all();
+ ble_sm_test_util_verify_tx_pair_random(our_entity.randoms + 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_inject(¶ms->passkey_info,
- BLE_SM_PROC_STATE_DHKEY_CHECK);
+ ble_sm_test_util_io_check_pre(¶ms->passkey_info,
+ BLE_SM_PROC_STATE_DHKEY_CHECK);
+
+ /* Receive a dhkey check from the peer. */
+ ble_sm_test_util_rx_dhkey_check(2, peer_entity.dhkey_check, 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(¶ms->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(¶ms->dhkey_check_req);
+ ble_sm_test_util_verify_tx_dhkey_check(our_entity.dhkey_check);
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, ¶ms->dhkey_check_rsp, 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, 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 start encryption command. */
- ble_hs_test_util_tx_all();
- ble_sm_test_util_verify_tx_start_enc(2, 0, 0, params->ltk);
+ /* 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);
@@ -2033,23 +2257,11 @@ ble_sm_test_util_us_sc_good(struct ble_sm_test_sc_params *params)
/* 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, ¶ms->id_info_req, 0);
- ble_sm_test_util_rx_id_addr_info(2, ¶ms->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, ¶ms->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(¶ms->id_info_rsp);
- ble_sm_test_util_verify_tx_id_addr_info(¶ms->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(¶ms->sign_info_rsp);
- }
+ ble_sm_test_util_verify_tx_keys(params, 0);
+
+ /* Receive key material from peer. */
+ ble_sm_test_util_rx_keys(params, 0);
/* Pairing should now be complete. */
TEST_ASSERT(ble_sm_dbg_num_procs() == 0);
@@ -2068,12 +2280,42 @@ ble_sm_test_util_us_sc_good(struct ble_sm_test_sc_params *params)
conn->bhc_sec_state.authenticated);
/* Verify the appropriate security material was persisted. */
- ble_sm_test_util_verify_sc_persist(params, 1);
+ ble_sm_test_util_verify_persist(params, 0);
+
+ ble_hs_test_util_conn_disconnect(2);
+}
+
+void
+ble_sm_test_util_peer_sc_good(struct ble_sm_test_params *params)
+{
+ /*** Peer is master. */
+
+ /* Peer performs IO first; peer initiates pairing. */
+ params->passkey_info.io_before_rx = 0;
+ params->sec_req.authreq = 0;
+ ble_sm_test_util_peer_sc_good_once(params);
+
+ /* Peer performs IO first; we initiate with security request. */
+ params->passkey_info.io_before_rx = 0;
+ params->sec_req.authreq = params->pair_req.authreq;
+ ble_sm_test_util_peer_sc_good_once(params);
+
+ /* We perform IO first; peer initiates pairing. */
+ params->passkey_info.io_before_rx = 1;
+ params->sec_req.authreq = 0;
+ ble_sm_test_util_peer_sc_good_once(params);
+
+ /* We perform IO first; we initiate with security request. */
+ params->passkey_info.io_before_rx = 1;
+ params->sec_req.authreq = params->pair_req.authreq;
+ ble_sm_test_util_peer_sc_good_once(params);
+
+ /* Verify link can be restored via the encryption procedure. */
+ ble_sm_test_util_bonding_all(params, 0);
}
void
-ble_sm_test_util_us_fail_inval(
- struct ble_sm_test_lgcy_params *params)
+ble_sm_test_util_us_fail_inval(struct ble_sm_test_params *params)
{
struct ble_hs_conn *conn;
int rc;
[3/9] incubator-mynewt-core git commit: BLE Host - Deal with va_args
bug for master_id log
Posted by cc...@apache.org.
BLE Host - Deal with va_args bug for master_id log
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/cda2363f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/cda2363f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/cda2363f
Branch: refs/heads/develop
Commit: cda2363f16535c903c15063bd33006a247e1c61a
Parents: 24c093c
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jun 16 20:47:32 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Jun 16 20:49:26 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/ble_sm_cmd.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/cda2363f/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 6ff4806..ebb1e54 100644
--- a/net/nimble/host/src/ble_sm_cmd.c
+++ b/net/nimble/host/src/ble_sm_cmd.c
@@ -416,7 +416,11 @@ done:
void
ble_sm_master_id_log(struct ble_sm_master_id *cmd)
{
- BLE_HS_LOG(DEBUG, "ediv=0x%04x rand=0x%016llx", cmd->ediv, cmd->rand_val);
+ /* These get logged separately to accommodate a bug in the va_args
+ * implementation related to 64-bit integers.
+ */
+ BLE_HS_LOG(DEBUG, "ediv=0x%04x ", cmd->ediv);
+ BLE_HS_LOG(DEBUG, "rand=0x%016llx", cmd->rand_val);
}
void
[8/9] incubator-mynewt-core git commit: BLE Host - More SM unit tests.
Posted by cc...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/39dd36c8/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 4f732bd..d890996 100644
--- a/net/nimble/host/src/test/ble_sm_test.c
+++ b/net/nimble/host/src/test/ble_sm_test.c
@@ -385,160 +385,6 @@ TEST_CASE(ble_sm_test_case_peer_lgcy_fail_confirm)
);
}
-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_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,
- .authreq = 0x05,
- .max_enc_key_size = 16,
- .init_key_dist = 0x07,
- .resp_key_dist = 0x07,
- },
- .pair_rsp = (struct ble_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,
- },
- .confirm_req = (struct ble_sm_pair_confirm) {
- .value = {
- 0x0a, 0xac, 0xa2, 0xae, 0xa6, 0x98, 0xdc, 0x6d,
- 0x65, 0x84, 0x11, 0x69, 0x47, 0x36, 0x8d, 0xa0,
- },
- },
- .confirm_rsp = (struct ble_sm_pair_confirm) {
- .value = {
- 0x45, 0xd2, 0x2c, 0x38, 0xd8, 0x91, 0x4f, 0x19,
- 0xa2, 0xd4, 0xfc, 0x7d, 0xad, 0x37, 0x79, 0xe0
- },
- },
- .random_req = (struct ble_sm_pair_random) {
- .value = {
- 0x2b, 0x3b, 0x69, 0xe4, 0xef, 0xab, 0xcc, 0x48,
- 0x78, 0x20, 0x1a, 0x54, 0x7a, 0x91, 0x5d, 0xfb,
- },
- },
- .random_rsp = (struct ble_sm_pair_random) {
- .value = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- },
- },
- .pair_alg = BLE_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,
- },
- .r = 0,
- .ediv = 0,
- };
- ble_sm_test_util_peer_lgcy_good(¶ms);
-}
-
-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_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,
- .max_enc_key_size = 16,
- .init_key_dist = 0x07,
- .resp_key_dist = 0x07,
- },
- .pair_rsp = (struct ble_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_sm_pair_confirm) {
- .value = {
- 0x54, 0xed, 0x7c, 0x65, 0xc5, 0x3a, 0xee, 0x87,
- 0x8e, 0xf8, 0x04, 0xd8, 0x93, 0xb0, 0xfa, 0xa4,
- },
- },
- .confirm_rsp = (struct ble_sm_pair_confirm) {
- .value = {
- 0xdf, 0x96, 0x88, 0x73, 0x49, 0x24, 0x3f, 0xe8,
- 0xb0, 0xaf, 0xb3, 0xf6, 0xc8, 0xf4, 0xe2, 0x36,
- },
- },
- .random_req = (struct ble_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_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_info = {
- .passkey = {
- .action = BLE_SM_IOACT_INPUT,
- .passkey = 884570,
- },
- },
-
- .enc_info_req = {
- .ltk = {
- 0x2b, 0x9c, 0x1e, 0x42, 0xa8, 0xcb, 0xab, 0xd1,
- 0x4b, 0xde, 0x50, 0x05, 0x50, 0xd9, 0x95, 0xc6
- },
- },
- .has_enc_info_req = 1,
-
- .master_id_req = {
- .ediv = 61621,
- .rand_val = 4107344270811490869,
- },
- .has_master_id_req = 1,
-
- .enc_info_rsp = {
- .ltk = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 }
- },
- .has_enc_info_rsp = 1,
-
- .master_id_rsp = {
- .ediv = 61621,
- .rand_val = 4107344270811490869,
- },
- .has_master_id_rsp = 1,
- };
- ble_sm_test_util_peer_lgcy_good(¶ms);
-}
-
TEST_CASE(ble_sm_test_case_peer_bonding_bad)
{
ble_sm_test_util_peer_bonding_bad(0x5684, 32);
@@ -583,22 +429,18 @@ TEST_CASE(ble_sm_test_case_peer_sec_req_inval)
TEST_ASSERT(ble_hs_test_util_prev_tx_queue_sz() == 0);
}
-/**
- * Master: us.
- * Peer sends a security request.
- * We respond by initiating the pairing procedure.
- */
-TEST_CASE(ble_sm_test_case_peer_sec_req_pair)
+/*****************************************************************************
+ * $us *
+ *****************************************************************************/
+
+TEST_CASE(ble_sm_test_case_us_fail_inval)
{
- struct ble_sm_test_lgcy_params params;
+ struct ble_sm_test_params params;
- params = (struct ble_sm_test_lgcy_params) {
- .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,
- },
- .has_sec_req = 1,
+ /* Invalid IO capabiltiies. */
+ params = (struct ble_sm_test_params) {
+ .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,
@@ -608,6 +450,24 @@ TEST_CASE(ble_sm_test_case_peer_sec_req_pair)
.resp_key_dist = 0,
},
.pair_rsp = (struct ble_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,
+ },
+ .pair_fail = (struct ble_sm_pair_fail) {
+ .reason = BLE_SM_ERR_INVAL,
+ },
+ };
+ ble_sm_test_util_us_fail_inval(¶ms);
+
+ /* Invalid OOB flag. */
+ params = (struct ble_sm_test_params) {
+ .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,
.authreq = 0,
@@ -615,1938 +475,178 @@ TEST_CASE(ble_sm_test_case_peer_sec_req_pair)
.init_key_dist = 0,
.resp_key_dist = 0,
},
- .confirm_req = (struct ble_sm_pair_confirm) {
- .value = {
- 0x04, 0x4e, 0xaf, 0xce, 0x30, 0x79, 0x2c, 0x9e,
- 0xa2, 0xeb, 0x53, 0x6a, 0xdf, 0xf7, 0x99, 0xb2,
- },
- },
- .confirm_rsp = (struct ble_sm_pair_confirm) {
- .value = {
- 0x04, 0x4e, 0xaf, 0xce, 0x30, 0x79, 0x2c, 0x9e,
- 0xa2, 0xeb, 0x53, 0x6a, 0xdf, 0xf7, 0x99, 0xb2,
- },
- },
- .random_req = (struct ble_sm_pair_random) {
- .value = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- },
- },
- .random_rsp = (struct ble_sm_pair_random) {
- .value = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- },
+ .pair_rsp = (struct ble_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,
},
- .pair_alg = BLE_SM_PAIR_ALG_JW,
- .tk = { 0 },
- .stk = {
- 0x2e, 0x2b, 0x34, 0xca, 0x59, 0xfa, 0x4c, 0x88,
- 0x3b, 0x2c, 0x8a, 0xef, 0xd4, 0x4b, 0xe9, 0x66,
+ .pair_fail = (struct ble_sm_pair_fail) {
+ .reason = BLE_SM_ERR_INVAL,
},
- .r = 0,
- .ediv = 0,
};
+ ble_sm_test_util_us_fail_inval(¶ms);
- ble_sm_test_util_us_lgcy_good(¶ms);
-}
-
-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_id_addr = { 0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0 },
- .resp_id_addr = { 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07 },
+ /* Invalid authreq - reserved bonding flag. */
+ params = (struct ble_sm_test_params) {
+ .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 = 0x01,
- .oob_data_flag = 0x00,
- .authreq = 0x0d,
+ .io_cap = 3,
+ .oob_data_flag = 0,
+ .authreq = 0,
.max_enc_key_size = 16,
- .init_key_dist = 0x0d,
- .resp_key_dist = 0x0f,
+ .init_key_dist = 0,
+ .resp_key_dist = 0,
},
.pair_rsp = (struct ble_sm_pair_cmd) {
- .io_cap = 0x01,
- .oob_data_flag = 0x00,
- .authreq = 0x0d,
+ .io_cap = 0x04,
+ .oob_data_flag = 0,
+ .authreq = 0x02,
.max_enc_key_size = 16,
- .init_key_dist = 0x01,
- .resp_key_dist = 0x01,
+ .init_key_dist = 0x07,
+ .resp_key_dist = 0x07,
},
- .public_key_req = (struct ble_sm_public_key) {
- .x = {
- 0xbf, 0x85, 0xf4, 0x0b, 0xf2, 0x93, 0x05, 0x38,
- 0xfd, 0x09, 0xf3, 0x80, 0xc1, 0x9c, 0x07, 0xee,
- 0x4b, 0x48, 0x28, 0x17, 0x18, 0x03, 0xc8, 0x8f,
- 0x5d, 0xdc, 0x7e, 0xa1, 0xf5, 0x06, 0x17, 0x12,
- },
-
- .y = {
- 0xee, 0x63, 0x19, 0x9e, 0x9e, 0x66, 0xd2, 0xee,
- 0x8a, 0xf9, 0xc7, 0xf6, 0x2b, 0x56, 0xec, 0xda,
- 0x8a, 0x18, 0xdb, 0x49, 0x55, 0x8d, 0x05, 0x08,
- 0x9a, 0x9c, 0xe3, 0xf4, 0xe8, 0x31, 0x4c, 0x1d,
- },
+ .pair_fail = (struct ble_sm_pair_fail) {
+ .reason = BLE_SM_ERR_INVAL,
},
- .public_key_rsp = (struct ble_sm_public_key) {
- .x = {
- 0x15, 0x88, 0xed, 0xe4, 0xa4, 0x81, 0xa7, 0xed,
- 0x1a, 0xff, 0x69, 0x66, 0x3d, 0x4d, 0xf1, 0x27,
- 0xc2, 0xb9, 0x03, 0xaf, 0x65, 0x9e, 0x45, 0x86,
- 0x80, 0xba, 0xc8, 0x4a, 0x7d, 0xbc, 0x17, 0x6e,
- },
+ };
+ ble_sm_test_util_us_fail_inval(¶ms);
- .y = {
- 0xb3, 0x34, 0x36, 0x36, 0x77, 0x5c, 0x28, 0xaf,
- 0x73, 0x25, 0x0e, 0xff, 0x29, 0xc4, 0xe8, 0x23,
- 0xeb, 0x35, 0xa7, 0x47, 0x29, 0x6e, 0xbd, 0x29,
- 0x93, 0x26, 0x07, 0xfd, 0x9c, 0x93, 0xf3, 0xd6,
- },
+ /* Invalid authreq - reserved other flag. */
+ params = (struct ble_sm_test_params) {
+ .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,
+ .authreq = 0,
+ .max_enc_key_size = 16,
+ .init_key_dist = 0,
+ .resp_key_dist = 0,
},
- .confirm_rsp[0] = (struct ble_sm_pair_confirm) {
- .value = {
- 0x7c, 0x45, 0xb0, 0x55, 0xce, 0x22, 0x61, 0x57,
- 0x68, 0x2f, 0x2d, 0x3a, 0xce, 0xf5, 0x80, 0xba,
- },
+ .pair_rsp = (struct ble_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,
},
- .random_req[0] = (struct ble_sm_pair_random) {
- .value = {
- 0x4e, 0xfb, 0x89, 0x84, 0xfd, 0xa1, 0xed, 0x65,
- 0x0e, 0x57, 0x11, 0xe6, 0x94, 0xd5, 0x18, 0x78,
- },
+ .pair_fail = (struct ble_sm_pair_fail) {
+ .reason = BLE_SM_ERR_INVAL,
},
- .random_rsp[0] = (struct ble_sm_pair_random) {
- .value = {
- 0x29, 0x06, 0xbc, 0x65, 0x1d, 0xe0, 0x95, 0xde,
- 0x79, 0xee, 0xd9, 0x41, 0x86, 0x6f, 0x35, 0x75,
- },
+ };
+ ble_sm_test_util_us_fail_inval(¶ms);
+
+ /* Invalid key size - too small. */
+ params = (struct ble_sm_test_params) {
+ .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,
+ .authreq = 0,
+ .max_enc_key_size = 16,
+ .init_key_dist = 0,
+ .resp_key_dist = 0,
},
- .dhkey_check_req = (struct ble_sm_dhkey_check) {
- .value = {
- 0xbc, 0x85, 0xc2, 0x2e, 0xe5, 0x19, 0xb0, 0xdd,
- 0xf7, 0xed, 0x5d, 0xdd, 0xa7, 0xa7, 0xc0, 0x54,
- }
+ .pair_rsp = (struct ble_sm_pair_cmd) {
+ .io_cap = 0x04,
+ .oob_data_flag = 0,
+ .authreq = 0x05,
+ .max_enc_key_size = 6,
+ .init_key_dist = 0x07,
+ .resp_key_dist = 0x07,
},
- .dhkey_check_rsp = (struct ble_sm_dhkey_check) {
- .value = {
- 0x65, 0x82, 0x74, 0xd0, 0x29, 0xcb, 0xe9, 0x9a,
- 0xed, 0x9c, 0xa4, 0xbb, 0x39, 0x5c, 0xef, 0xfd,
- }
+ .pair_fail = (struct ble_sm_pair_fail) {
+ .reason = BLE_SM_ERR_INVAL,
},
- .pair_alg = BLE_SM_PAIR_ALG_NUMCMP,
- .authenticated = 1,
- .ltk = {
- 0xb0, 0x43, 0x9c, 0xed, 0x93, 0x73, 0x5c, 0xfb,
- 0x7f, 0xfd, 0xd9, 0x06, 0xad, 0xbc, 0x7c, 0xd0,
+ };
+ ble_sm_test_util_us_fail_inval(¶ms);
+
+ /* Invalid key size - too large. */
+ params = (struct ble_sm_test_params) {
+ .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,
+ .authreq = 0,
+ .max_enc_key_size = 16,
+ .init_key_dist = 0,
+ .resp_key_dist = 0,
},
- .our_priv_key = {
- 0x8c, 0x7a, 0x1a, 0x8e, 0x8e, 0xfa, 0x2d, 0x2e,
- 0xa6, 0xd5, 0xa2, 0x51, 0x86, 0xe4, 0x31, 0x1c,
- 0x1e, 0xf8, 0x13, 0x33, 0x08, 0x76, 0x38, 0x6e,
- 0xa0, 0x06, 0x88, 0x6d, 0x9d, 0x96, 0x43, 0x4e,
+ .pair_rsp = (struct ble_sm_pair_cmd) {
+ .io_cap = 0x04,
+ .oob_data_flag = 0,
+ .authreq = 0x05,
+ .max_enc_key_size = 17,
+ .init_key_dist = 0x07,
+ .resp_key_dist = 0x07,
},
-
- .passkey_info = {
- .passkey = {
- .action = BLE_SM_IOACT_NUMCMP,
- .numcmp_accept = 1,
- },
-
- .exp_numcmp = 476091,
- .io_before_rx = 0,
+ .pair_fail = (struct ble_sm_pair_fail) {
+ .reason = BLE_SM_ERR_INVAL,
},
};
- ble_sm_test_util_peer_sc_good(¶ms);
-}
-
-TEST_CASE(ble_sm_test_case_peer_sc_passkey_good)
-{
- struct ble_sm_test_sc_params params;
+ ble_sm_test_util_us_fail_inval(¶ms);
- params = (struct ble_sm_test_sc_params) {
- .init_id_addr = { 0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0 },
- .resp_id_addr = { 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07 },
+ /* Invalid init key dist. */
+ params = (struct ble_sm_test_params) {
+ .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 = 0x00,
- .authreq = 0x0d,
+ .io_cap = 3,
+ .oob_data_flag = 0,
+ .authreq = 0,
.max_enc_key_size = 16,
- .init_key_dist = 0x0d,
- .resp_key_dist = 0x0f,
+ .init_key_dist = 0,
+ .resp_key_dist = 0,
},
.pair_rsp = (struct ble_sm_pair_cmd) {
- .io_cap = 0x02,
- .oob_data_flag = 0x00,
- .authreq = 0x0d,
- .max_enc_key_size = 16,
- .init_key_dist = 0x01,
- .resp_key_dist = 0x01,
- },
- .public_key_req = (struct ble_sm_public_key) {
- .x = {
- 0x82,0xcf, 0x99, 0xe1, 0x56, 0xe5, 0xa3, 0xbc,
- 0x1d,0xd5, 0xab, 0x32, 0x90, 0x65, 0x9a, 0x6c,
- 0x15,0x34, 0xcf, 0xa3, 0xb1, 0xa3, 0x88, 0x9f,
- 0xb0,0x86, 0xc7, 0x17, 0xd4, 0x1a, 0x88, 0x8d,
- },
- .y = {
- 0x09,0xfb, 0x98, 0xd2, 0xf8, 0x94, 0x73, 0xed,
- 0x81,0x09, 0x08, 0x00, 0x3f, 0x14, 0x87, 0x6c,
- 0xc6,0x83, 0x36, 0xc1, 0x9d, 0x8e, 0x39, 0xea,
- 0x3d,0x79, 0x9d, 0x8c, 0x7f, 0xcf, 0x00, 0xbd,
- },
- },
- .public_key_rsp = (struct ble_sm_public_key) {
- .x = {
- 0x9e,0x05, 0x7b, 0x5b, 0x61, 0xf2, 0x57, 0xbe,
- 0xb7,0x73, 0x3f, 0x72, 0x03, 0xc9, 0x51, 0x44,
- 0x9e,0xe1, 0xef, 0xe8, 0x28, 0x67, 0xcc, 0xbe,
- 0x20,0x13, 0xb5, 0xcc, 0x71, 0x39, 0x85, 0xaf,
- },
- .y = {
- 0xff,0xac, 0x2c, 0x48, 0x57, 0xd9, 0x49, 0x9d,
- 0x27,0x8d, 0x99, 0x30, 0x01, 0xe3, 0x30, 0x72,
- 0xd4,0x7b, 0x5c, 0x64, 0x7e, 0x80, 0xd5, 0x09,
- 0x3a,0x70, 0x44, 0x61, 0xc9, 0x36, 0x50, 0x6b,
- },
- },
- .confirm_req[0] = {
- .value = {
- 0x2f,0xa2, 0x10, 0xff, 0xd8, 0x1c, 0x5c, 0x93,
- 0xd9,0x96, 0xf2, 0x8d, 0x7a, 0x34, 0xef, 0xbc,
- },
- },
- .confirm_rsp[0] = {
- .value = {
- 0xe7,0xd6, 0x11, 0xd9, 0xb1, 0x69, 0xe1, 0x0b,
- 0xbb,0x07, 0x63, 0x38, 0x62, 0x75, 0x5f, 0x2b,
- },
- },
- .random_req[0] = {
- .value = {
- 0xfa,0x4c, 0xa5, 0x7e, 0xfd, 0x11, 0x68, 0xeb,
- 0xf2,0x6a, 0xcd, 0x50, 0x7a, 0x92, 0x36, 0xf1,
- },
- },
- .random_rsp[0] = {
- .value = {
- 0xa5,0xec, 0xc8, 0x7f, 0xe2, 0x19, 0x05, 0x5e,
- 0x2e,0x0d, 0x12, 0x65, 0xd5, 0x11, 0x98, 0x7e,
- },
- },
- .confirm_req[1] = {
- .value = {
- 0x5b,0xff, 0xad, 0x40, 0x98, 0xb8, 0xc8, 0xd9,
- 0x1e,0xde, 0x11, 0x17, 0xcc, 0x16, 0x09, 0x08,
- },
- },
- .confirm_rsp[1] = {
- .value = {
- 0xe1,0xd7, 0xb3, 0x1b, 0x2b, 0xa8, 0x38, 0x29,
- 0xa4,0xd7, 0x62, 0x4b, 0xf2, 0x59, 0x51, 0xdc,
- },
- },
- .random_req[1] = {
- .value = {
- 0xac,0x6b, 0xc5, 0x83, 0x9f, 0x08, 0x05, 0xed,
- 0x0e,0x76, 0x14, 0xce, 0x57, 0x07, 0x6e, 0x0b,
- },
- },
- .random_rsp[1] = {
- .value = {
- 0x6d,0x7d, 0x10, 0x78, 0x76, 0x09, 0x34, 0xca,
- 0xa9,0x70, 0x5b, 0x59, 0xfb, 0xfd, 0x15, 0x17,
- },
- },
- .confirm_req[2] = {
- .value = {
- 0x5c,0xb7, 0x96, 0x9a, 0x5b, 0x8a, 0x8f, 0x00,
- 0xae,0x84, 0xa1, 0x72, 0xc8, 0x4d, 0xd0, 0x85,
- },
- },
- .confirm_rsp[2] = {
- .value = {
- 0xe7,0x0e, 0x80, 0x89, 0xf7, 0x04, 0x48, 0x02,
- 0x06,0xd3, 0xd2, 0x09, 0x88, 0x73, 0x44, 0x3c,
- },
- },
- .random_req[2] = {
- .value = {
- 0xc7,0x83, 0xec, 0x81, 0xf4, 0xe0, 0xdd, 0x41,
- 0xaf,0x28, 0x6f, 0xbe, 0xb4, 0x92, 0x30, 0xf7,
- },
- },
- .random_rsp[2] = {
- .value = {
- 0x38,0x95, 0xbb, 0x5f, 0x8a, 0x67, 0xb7, 0x8f,
- 0x95,0x2a, 0x7e, 0x3b, 0xac, 0x27, 0xf7, 0x86,
- },
- },
- .confirm_req[3] = {
- .value = {
- 0x01,0x3d, 0xee, 0x42, 0xb7, 0xfa, 0xc1, 0x82,
- 0x51,0x02, 0x42, 0x51, 0xa2, 0xbb, 0x20, 0x0e,
- },
- },
- .confirm_rsp[3] = {
- .value = {
- 0x99,0x01, 0x88, 0x1c, 0x45, 0x2c, 0xa6, 0x6f,
- 0x6b,0xca, 0x9d, 0x8d, 0x32, 0xfe, 0x2f, 0x02,
- },
- },
- .random_req[3] = {
- .value = {
- 0x5e,0x39, 0x5f, 0x91, 0x9d, 0xed, 0xf9, 0x93,
- 0xec,0xd5, 0x6b, 0x39, 0xb6, 0x77, 0x3a, 0x94,
- },
- },
- .random_rsp[3] = {
- .value = {
- 0xe1,0x06, 0x02, 0xcc, 0x80, 0x9d, 0xd1, 0x47,
- 0x42,0xa6, 0xca, 0x52, 0x6a, 0x1b, 0x9e, 0x7a,
- },
- },
- .confirm_req[4] = {
- .value = {
- 0x2e,0xcd, 0x64, 0x01, 0x39, 0x74, 0x59, 0xfc,
- 0x78,0xeb, 0x48, 0x4f, 0xa3, 0x8a, 0x6e, 0x2f,
- },
- },
- .confirm_rsp[4] = {
- .value = {
- 0x9e,0x27, 0x31, 0x14, 0x35, 0x95, 0x0a, 0x3d,
- 0x0b,0x60, 0xd9, 0x78, 0xd9, 0xfc, 0x5d, 0xc4,
- },
- },
- .random_req[4] = {
- .value = {
- 0x3f,0x35, 0xa0, 0x90, 0xbf, 0x5a, 0x16, 0xcd,
- 0x32,0x0c, 0x88, 0x3a, 0x3c, 0x28, 0x89, 0x29,
- },
- },
- .random_rsp[4] = {
- .value = {
- 0xde,0xb9, 0x95, 0x46, 0x55, 0xed, 0xaa, 0x76,
- 0xb3,0xae, 0x59, 0x92, 0xec, 0x3e, 0xe6, 0x17,
- },
- },
- .confirm_req[5] = {
- .value = {
- 0x61,0x65, 0x44, 0xa6, 0x35, 0x88, 0x34, 0x80,
- 0xeb,0xce, 0xc4, 0xc3, 0xa0, 0xf4, 0xc4, 0xdb,
- },
- },
- .confirm_rsp[5] = {
- .value = {
- 0xc5,0xdd, 0x46, 0x1c, 0x42, 0x8a, 0xe9, 0x5c,
- 0x71,0xb3, 0x55, 0x5f, 0x35, 0xdd, 0xb3, 0x79,
- },
- },
- .random_req[5] = {
- .value = {
- 0xfa,0xae, 0x45, 0x2a, 0x17, 0xff, 0xfe, 0xe1,
- 0x05,0x58, 0xa4, 0xbd, 0x40, 0x9e, 0x05, 0x0c,
- },
- },
- .random_rsp[5] = {
- .value = {
- 0x7b,0xef, 0xca, 0x4e, 0x87, 0x80, 0xef, 0xd9,
- 0x8f,0xa5, 0x61, 0x8d, 0x73, 0xb2, 0x38, 0xcd,
- },
- },
- .confirm_req[6] = {
- .value = {
- 0x38,0xfb, 0x19, 0x1e, 0xc7, 0xec, 0x11, 0xed,
- 0xaa,0xc0, 0xa5, 0xaf, 0x79, 0x8f, 0x96, 0x82,
- },
- },
- .confirm_rsp[6] = {
- .value = {
- 0x9d,0x0f, 0x44, 0x66, 0xd7, 0x05, 0x24, 0x81,
- 0xff,0x32, 0x5c, 0xda, 0x25, 0x2c, 0x92, 0xec,
- },
- },
- .random_req[6] = {
- .value = {
- 0x77,0xc3, 0x35, 0x7b, 0x78, 0xbc, 0xe4, 0xc1,
- 0x9c,0x13, 0xbd, 0xd2, 0xd2, 0xc6, 0x1e, 0x50,
- },
- },
- .random_rsp[6] = {
- .value = {
- 0x5d,0xd5, 0x12, 0x06, 0x66, 0xd1, 0x74, 0x3a,
- 0xb7,0x5e, 0x54, 0x0d, 0xa2, 0x0f, 0xa4, 0x7c,
- },
- },
- .confirm_req[7] = {
- .value = {
- 0x32,0xe8, 0xf4, 0xc9, 0xed, 0xa7, 0xd3, 0x95,
- 0x94,0x0f, 0x08, 0xfb, 0xaa, 0xce, 0x84, 0x06,
- },
- },
- .confirm_rsp[7] = {
- .value = {
- 0x5a,0x59, 0xb8, 0xbe, 0x70, 0x33, 0x99, 0xf9,
- 0x07,0xff, 0x70, 0xe2, 0x10, 0x53, 0xf6, 0xf1,
- },
- },
- .random_req[7] = {
- .value = {
- 0x2f,0x07, 0x42, 0x95, 0xb2, 0x97, 0xcf, 0xa4,
- 0xde,0x2e, 0x88, 0xa1, 0x2a, 0x3c, 0x89, 0x6e,
- },
- },
- .random_rsp[7] = {
- .value = {
- 0x23,0x21, 0x9f, 0x2f, 0xfc, 0xb1, 0x80, 0xce,
- 0x0f,0x3d, 0xe6, 0xee, 0xbe, 0xab, 0x28, 0xe2,
- },
- },
- .confirm_req[8] = {
- .value = {
- 0x20,0xc3, 0x49, 0x90, 0x13, 0xad, 0x99, 0x69,
- 0xf1,0xd3, 0x71, 0x95, 0xb0, 0x54, 0xc4, 0xce,
- },
- },
- .confirm_rsp[8] = {
- .value = {
- 0x02,0x50, 0x29, 0x57, 0xc5, 0x26, 0x1f, 0x90,
- 0x05,0x8b, 0x8c, 0x20, 0xe9, 0xf7, 0xdd, 0x03,
- },
- },
- .random_req[8] = {
- .value = {
- 0xfd,0x09, 0x39, 0xc8, 0xc6, 0x57, 0xcf, 0x09,
- 0xc7,0x89, 0xab, 0xcc, 0x05, 0xda, 0xb7, 0x05,
- },
- },
- .random_rsp[8] = {
- .value = {
- 0x0d,0xed, 0xfd, 0x38, 0x76, 0x56, 0xa0, 0xcc,
- 0xf4,0x66, 0x09, 0xcb, 0x0f, 0x8c, 0xa5, 0x6a,
- },
- },
- .confirm_req[9] = {
- .value = {
- 0xce,0x50, 0x75, 0xda, 0x6a, 0x88, 0x98, 0x00,
- 0xe5,0x4d, 0x7d, 0xcf, 0xde, 0x00, 0xc5, 0x18,
- },
- },
- .confirm_rsp[9] = {
- .value = {
- 0x0b,0xd4, 0x0c, 0xba, 0xfe, 0x9a, 0xf0, 0x31,
- 0x13,0x21, 0x70, 0x11, 0x7c, 0xde, 0x26, 0x75,
- },
- },
- .random_req[9] = {
- .value = {
- 0x24,0x85, 0x91, 0xef, 0x4b, 0x8e, 0x2b, 0x67,
- 0x39,0x93, 0x7c, 0x7e, 0x4b, 0x76, 0x10, 0x44,
- },
- },
- .random_rsp[9] = {
- .value = {
- 0x2d,0xa3, 0x52, 0xc7, 0x09, 0x0b, 0xda, 0x81,
- 0xbd,0x10, 0x30, 0x57, 0x20, 0x2c, 0x5b, 0x90,
- },
- },
- .confirm_req[10] = {
- .value = {
- 0x7a,0x3e, 0x5b, 0x55, 0x08, 0x63, 0x32, 0x65,
- 0xaa,0xf8, 0xc1, 0xd2, 0xd6, 0x01, 0x1a, 0x7e,
- },
- },
- .confirm_rsp[10] = {
- .value = {
- 0x46,0xdd, 0x55, 0x46, 0x90, 0x55, 0xc8, 0x0b,
- 0x9e,0x7b, 0x81, 0xbb, 0x71, 0x11, 0x7f, 0x58,
- },
- },
- .random_req[10] = {
- .value = {
- 0xc0,0xe0, 0xa0, 0x10, 0xfc, 0xbc, 0xd9, 0x54,
- 0x48,0xdc, 0xcf, 0x8f, 0xda, 0xe6, 0x6a, 0x5f,
- },
- },
- .random_rsp[10] = {
- .value = {
- 0x22,0x3c, 0xd5, 0x79, 0x3e, 0xb3, 0x64, 0x3c,
- 0x46,0xba, 0xbc, 0x74, 0x4a, 0xc0, 0x5c, 0x18,
- },
- },
- .confirm_req[11] = {
- .value = {
- 0x29,0x6e, 0x96, 0xb8, 0xc1, 0x74, 0x27, 0x4c,
- 0x56,0xe0, 0x3e, 0x33, 0x3a, 0xca, 0xf9, 0x68,
- },
- },
- .confirm_rsp[11] = {
- .value = {
- 0xf0,0xe5, 0x3e, 0x5b, 0x68, 0x82, 0x40, 0x53,
- 0x98,0x1b, 0x57, 0xdd, 0x4f, 0x40, 0x23, 0xa2,
- },
- },
- .random_req[11] = {
- .value = {
- 0xb8,0xd9, 0x75, 0x53, 0x65, 0x42, 0x5a, 0x0c,
- 0x82,0x74, 0x55, 0x2c, 0x40, 0x5b, 0x02, 0xed,
- },
- },
- .random_rsp[11] = {
- .value = {
- 0x3f,0x88, 0x97, 0x63, 0x72, 0xe7, 0x84, 0x29,
- 0x2d,0xcc, 0xd3, 0xc6, 0xbb, 0xa8, 0x6a, 0xb8,
- },
- },
- .confirm_req[12] = {
- .value = {
- 0x6c,0x1f, 0x97, 0xda, 0x08, 0x2c, 0x9b, 0x8b,
- 0xf2,0xb0, 0x7a, 0x3e, 0xdf, 0xbf, 0x1e, 0x70,
- },
- },
- .confirm_rsp[12] = {
- .value = {
- 0x18,0xfe, 0x73, 0x49, 0xe0, 0x7a, 0x75, 0xd3,
- 0x68,0x52, 0x2d, 0xae, 0x76, 0xf5, 0xc1, 0x4f,
- },
- },
- .random_req[12] = {
- .value = {
- 0xb3,0xf1, 0xd0, 0xa9, 0x5a, 0x69, 0xa7, 0x33,
- 0xb9,0xdd, 0x04, 0x7d, 0x19, 0xc9, 0x0e, 0xdc,
- },
- },
- .random_rsp[12] = {
- .value = {
- 0x62,0x10, 0x99, 0xae, 0xc0, 0x5c, 0x00, 0x59,
- 0xda,0x14, 0x38, 0x41, 0x8e, 0x70, 0xd9, 0x51,
- },
- },
- .confirm_req[13] = {
- .value = {
- 0x3f,0x62, 0xd8, 0x3c, 0x29, 0x25, 0xf7, 0x96,
- 0x1c,0x01, 0x4f, 0x27, 0x19, 0x89, 0x51, 0xaf,
- },
- },
- .confirm_rsp[13] = {
- .value = {
- 0x4c,0x9f, 0xff, 0xef, 0x9c, 0x04, 0x4f, 0xa7,
- 0xb9,0x8f, 0x9b, 0x4c, 0xbb, 0xaa, 0x8c, 0x44,
- },
- },
- .random_req[13] = {
- .value = {
- 0x73,0x5e, 0xef, 0x3b, 0x9b, 0x45, 0xf1, 0x31,
- 0xcd,0x0c, 0x26, 0x7c, 0xe9, 0xfc, 0x04, 0x5d,
- },
- },
- .random_rsp[13] = {
- .value = {
- 0x38,0x53, 0x68, 0xaa, 0xdf, 0x20, 0xd4, 0xef,
- 0x11,0x2b, 0xac, 0xe2, 0x7c, 0x11, 0x00, 0x10,
- },
- },
- .confirm_req[14] = {
- .value = {
- 0x13,0x1d, 0xc2, 0x1a, 0x39, 0x01, 0xbf, 0xf9,
- 0x87,0xdd, 0xb4, 0xd3, 0xe5, 0xe8, 0x8c, 0x42,
- },
- },
- .confirm_rsp[14] = {
- .value = {
- 0x34,0xc5, 0xda, 0xc1, 0x4c, 0xa8, 0x47, 0x31,
- 0x76,0x5e, 0x4f, 0xcd, 0x37, 0x77, 0x04, 0x10,
- },
- },
- .random_req[14] = {
- .value = {
- 0x59,0x02, 0xa1, 0x35, 0xd7, 0x12, 0x9a, 0x51,
- 0xf4,0xad, 0x32, 0xdf, 0x3b, 0xa4, 0x3a, 0xae,
- },
- },
- .random_rsp[14] = {
- .value = {
- 0x47,0x9e, 0x47, 0x0f, 0x53, 0xad, 0x74, 0x57,
- 0x1a,0xdc, 0x1b, 0x5f, 0xc0, 0xf0, 0x00, 0x1a,
- },
- },
- .confirm_req[15] = {
- .value = {
- 0x4c,0xa7, 0x4f, 0x64, 0xc1, 0xb7, 0xfe, 0xa9,
- 0xcb,0x94, 0x5f, 0x39, 0x9a, 0x1e, 0xbf, 0xb4,
- },
- },
- .confirm_rsp[15] = {
- .value = {
- 0xed,0x61, 0x96, 0xaa, 0xd5, 0x27, 0x23, 0x32,
- 0xc4,0x80, 0x52, 0x3c, 0x81, 0x45, 0x37, 0xc3,
- },
- },
- .random_req[15] = {
- .value = {
- 0xe4,0x2e, 0x04, 0xce, 0x7d, 0xbe, 0xb5, 0x5b,
- 0xb5,0xd5, 0xba, 0x60, 0x3f, 0x88, 0x05, 0xf1,
- },
- },
- .random_rsp[15] = {
- .value = {
- 0x64,0xa0, 0x95, 0x1f, 0x01, 0x7e, 0x00, 0x8d,
- 0x00,0x40, 0xa1, 0x2f, 0x90, 0x42, 0xcb, 0x15,
- },
- },
- .confirm_req[16] = {
- .value = {
- 0xce,0x32, 0x34, 0x33, 0x44, 0xbc, 0xb2, 0x8e,
- 0x64,0xfd, 0x8a, 0xeb, 0x41, 0xf9, 0x4d, 0xd7,
- },
- },
- .confirm_rsp[16] = {
- .value = {
- 0xb4,0x69, 0x44, 0xa5, 0x0a, 0x88, 0xfe, 0x39,
- 0x0c,0x7f, 0xc9, 0x8b, 0x7f, 0x7e, 0x6e, 0x45,
- },
- },
- .random_req[16] = {
- .value = {
- 0xff,0x56, 0x8f, 0x97, 0x85, 0x6e, 0xac, 0xd1,
- 0x00,0x0e, 0x8d, 0x2f, 0xf1, 0x68, 0xf9, 0xf2,
- },
- },
- .random_rsp[16] = {
- .value = {
- 0xc0,0x84, 0x5c, 0x92, 0x0d, 0x71, 0xdd, 0x88,
- 0xab,0x13, 0xa4, 0xf4, 0x06, 0x54, 0x4f, 0x1b,
- },
- },
- .confirm_req[17] = {
- .value = {
- 0x59,0xe5, 0x79, 0xdd, 0x1d, 0xd3, 0xa5, 0xf8,
- 0xba,0x7f, 0xf6, 0xc9, 0xaf, 0xca, 0xe8, 0xbc,
- },
- },
- .confirm_rsp[17] = {
- .value = {
- 0x39,0xd4, 0xc3, 0x39, 0xd9, 0x0b, 0x07, 0xe1,
- 0x6c,0x68, 0x6b, 0xef, 0xc8, 0x87, 0x93, 0x4f,
- },
- },
- .random_req[17] = {
- .value = {
- 0xaa,0xf9, 0xa4, 0xc9, 0xe0, 0x6f, 0xfc, 0x7b,
- 0x22,0x5a, 0xb6, 0x3d, 0x50, 0x3e, 0xd1, 0x02,
- },
- },
- .random_rsp[17] = {
- .value = {
- 0x22,0x90, 0x0e, 0xd4, 0x92, 0xb7, 0xa9, 0x16,
- 0x39,0x2a, 0x1c, 0xd2, 0x8b, 0xbf, 0xf7, 0x43,
- },
- },
- .confirm_req[18] = {
- .value = {
- 0x69,0xb9, 0x75, 0x4b, 0x80, 0xe8, 0x93, 0xbb,
- 0x57,0xe8, 0x37, 0x3c, 0x69, 0x47, 0x40, 0xb7,
- },
- },
- .confirm_rsp[18] = {
- .value = {
- 0xd8,0x69, 0x55, 0xf4, 0x84, 0x54, 0x95, 0x98,
- 0xdf,0x13, 0x69, 0x62, 0xbc, 0xea, 0x46, 0x16,
- },
- },
- .random_req[18] = {
- .value = {
- 0xf6,0x26, 0xc3, 0xec, 0xdc, 0xc8, 0x85, 0x78,
- 0xd4,0xe4, 0x0e, 0x1b, 0x05, 0x6d, 0x33, 0x20,
- },
- },
- .random_rsp[18] = {
- .value = {
- 0xf7,0xb6, 0x8a, 0xdc, 0xd5, 0xdd, 0x0f, 0x2f,
- 0x6a,0xab, 0x94, 0xcd, 0x68, 0xf4, 0x2d, 0xda,
- },
- },
- .confirm_req[19] = {
- .value = {
- 0x07,0xea, 0xe0, 0x61, 0x90, 0x23, 0x52, 0xd8,
- 0x90,0x50, 0xe1, 0x7c, 0x10, 0x1e, 0x41, 0xf0,
- },
- },
- .confirm_rsp[19] = {
- .value = {
- 0xed,0xd9, 0x02, 0xb7, 0x03, 0xd9, 0xe8, 0x87,
- 0x4a,0x48, 0x43, 0x96, 0xa0, 0x59, 0xb1, 0xa8,
- },
- },
- .random_req[19] = {
- .value = {
- 0x88,0x00, 0xe6, 0xfc, 0x1f, 0x6f, 0x92, 0x0e,
- 0x33,0xeb, 0x18, 0xc3, 0x5d, 0x7e, 0x37, 0x0e,
- },
- },
- .random_rsp[19] = {
- .value = {
- 0xfb,0xcf, 0x24, 0x02, 0x4a, 0xe4, 0x92, 0x47,
- 0xa9,0x67, 0x43, 0x33, 0x22, 0x95, 0x0a, 0xd3,
- },
- },
- .dhkey_check_req = (struct ble_sm_dhkey_check) {
- .value = {
- 0xcb, 0xb5, 0x5f, 0x62, 0xde, 0x14, 0xc7, 0x30,
- 0xaa, 0x58, 0x23, 0x3c, 0xdb, 0x39, 0xc1, 0xb9,
- }
- },
- .dhkey_check_rsp = (struct ble_sm_dhkey_check) {
- .value = {
- 0x52, 0x00, 0xeb, 0xe5, 0xd7, 0xa6, 0x5c, 0xc4,
- 0xf6, 0x6d, 0xa5, 0x7c, 0xff, 0xa8, 0x7c, 0x3f,
- }
- },
- .pair_alg = BLE_SM_PAIR_ALG_PASSKEY,
- .authenticated = 1,
- .ltk = {
- 0x45, 0x8a, 0x1b, 0x92, 0x1c, 0x2b, 0xdf, 0x3e,
- 0xda, 0xf9, 0x5c, 0xdf, 0x96, 0x59, 0xb7, 0x13,
- },
- .our_priv_key = {
- 0x20, 0x62, 0xba, 0x77, 0xfe, 0xdd, 0x34, 0xf7,
- 0x30, 0xcc, 0x35, 0x3f, 0xa3, 0x35, 0x02, 0x95,
- 0x2d, 0x03, 0x78, 0x4e, 0xe8, 0x80, 0xaa, 0x4d,
- 0x8c, 0xec, 0x93, 0x02, 0x28, 0x55, 0x2f, 0xf8,
- },
-
- .passkey_info = {
- .passkey = {
- .action = BLE_SM_IOACT_INPUT,
- .passkey = 873559,
- },
-
- .io_before_rx = 0,
- },
- };
- ble_sm_test_util_peer_sc_good(¶ms);
-}
-
-/*****************************************************************************
- * $us *
- *****************************************************************************/
-
-TEST_CASE(ble_sm_test_case_us_fail_inval)
-{
- struct ble_sm_test_lgcy_params params;
-
- /* Invalid IO capabiltiies. */
- params = (struct ble_sm_test_lgcy_params) {
- .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,
- .authreq = 0,
- .max_enc_key_size = 16,
- .init_key_dist = 0,
- .resp_key_dist = 0,
- },
- .pair_rsp = (struct ble_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,
- },
- .pair_fail = (struct ble_sm_pair_fail) {
- .reason = BLE_SM_ERR_INVAL,
- },
- };
- ble_sm_test_util_us_fail_inval(¶ms);
-
- /* Invalid OOB flag. */
- params = (struct ble_sm_test_lgcy_params) {
- .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,
- .authreq = 0,
- .max_enc_key_size = 16,
- .init_key_dist = 0,
- .resp_key_dist = 0,
- },
- .pair_rsp = (struct ble_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,
- },
- .pair_fail = (struct ble_sm_pair_fail) {
- .reason = BLE_SM_ERR_INVAL,
- },
- };
- ble_sm_test_util_us_fail_inval(¶ms);
-
- /* Invalid authreq - reserved bonding flag. */
- params = (struct ble_sm_test_lgcy_params) {
- .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,
- .authreq = 0,
- .max_enc_key_size = 16,
- .init_key_dist = 0,
- .resp_key_dist = 0,
- },
- .pair_rsp = (struct ble_sm_pair_cmd) {
- .io_cap = 0x04,
- .oob_data_flag = 0,
- .authreq = 0x02,
- .max_enc_key_size = 16,
- .init_key_dist = 0x07,
- .resp_key_dist = 0x07,
- },
- .pair_fail = (struct ble_sm_pair_fail) {
- .reason = BLE_SM_ERR_INVAL,
- },
- };
- ble_sm_test_util_us_fail_inval(¶ms);
-
- /* Invalid authreq - reserved other flag. */
- params = (struct ble_sm_test_lgcy_params) {
- .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,
- .authreq = 0,
- .max_enc_key_size = 16,
- .init_key_dist = 0,
- .resp_key_dist = 0,
- },
- .pair_rsp = (struct ble_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,
- },
- .pair_fail = (struct ble_sm_pair_fail) {
- .reason = BLE_SM_ERR_INVAL,
- },
- };
- ble_sm_test_util_us_fail_inval(¶ms);
-
- /* Invalid key size - too small. */
- params = (struct ble_sm_test_lgcy_params) {
- .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,
- .authreq = 0,
- .max_enc_key_size = 16,
- .init_key_dist = 0,
- .resp_key_dist = 0,
- },
- .pair_rsp = (struct ble_sm_pair_cmd) {
- .io_cap = 0x04,
- .oob_data_flag = 0,
- .authreq = 0x05,
- .max_enc_key_size = 6,
- .init_key_dist = 0x07,
- .resp_key_dist = 0x07,
- },
- .pair_fail = (struct ble_sm_pair_fail) {
- .reason = BLE_SM_ERR_INVAL,
- },
- };
- ble_sm_test_util_us_fail_inval(¶ms);
-
- /* Invalid key size - too large. */
- params = (struct ble_sm_test_lgcy_params) {
- .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,
- .authreq = 0,
- .max_enc_key_size = 16,
- .init_key_dist = 0,
- .resp_key_dist = 0,
- },
- .pair_rsp = (struct ble_sm_pair_cmd) {
- .io_cap = 0x04,
- .oob_data_flag = 0,
- .authreq = 0x05,
- .max_enc_key_size = 17,
- .init_key_dist = 0x07,
- .resp_key_dist = 0x07,
- },
- .pair_fail = (struct ble_sm_pair_fail) {
- .reason = BLE_SM_ERR_INVAL,
- },
- };
- ble_sm_test_util_us_fail_inval(¶ms);
-
- /* Invalid init key dist. */
- params = (struct ble_sm_test_lgcy_params) {
- .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,
- .authreq = 0,
- .max_enc_key_size = 16,
- .init_key_dist = 0,
- .resp_key_dist = 0,
- },
- .pair_rsp = (struct ble_sm_pair_cmd) {
- .io_cap = 0x04,
- .oob_data_flag = 0,
- .authreq = 0x05,
- .max_enc_key_size = 17,
- .init_key_dist = 0x10,
- .resp_key_dist = 0x07,
- },
- .pair_fail = (struct ble_sm_pair_fail) {
- .reason = BLE_SM_ERR_INVAL,
- },
- };
- ble_sm_test_util_us_fail_inval(¶ms);
-
- /* Invalid resp key dist. */
- params = (struct ble_sm_test_lgcy_params) {
- .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,
- .authreq = 0,
- .max_enc_key_size = 16,
- .init_key_dist = 0,
- .resp_key_dist = 0,
- },
- .pair_rsp = (struct ble_sm_pair_cmd) {
- .io_cap = 0x04,
- .oob_data_flag = 0,
- .authreq = 0x05,
- .max_enc_key_size = 17,
- .init_key_dist = 0x07,
- .resp_key_dist = 0x10,
- },
- .pair_fail = (struct ble_sm_pair_fail) {
- .reason = BLE_SM_ERR_INVAL,
- },
- };
- ble_sm_test_util_us_fail_inval(¶ms);
-}
-
-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_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,
- .authreq = 0,
- .max_enc_key_size = 16,
- .init_key_dist = 0,
- .resp_key_dist = 0,
- },
- .pair_rsp = (struct ble_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,
- },
- .confirm_req = (struct ble_sm_pair_confirm) {
- .value = {
- 0x04, 0x4e, 0xaf, 0xce, 0x30, 0x79, 0x2c, 0x9e,
- 0xa2, 0xeb, 0x53, 0x6a, 0xdf, 0xf7, 0x99, 0xb2,
- },
- },
- .confirm_rsp = (struct ble_sm_pair_confirm) {
- .value = {
- 0x04, 0x4e, 0xaf, 0xce, 0x30, 0x79, 0x2c, 0x9e,
- 0xa2, 0xeb, 0x53, 0x6a, 0xdf, 0xf7, 0x99, 0xb2,
- },
- },
- .random_req = (struct ble_sm_pair_random) {
- .value = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- },
- },
- .random_rsp = (struct ble_sm_pair_random) {
- .value = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- },
- },
- .pair_alg = BLE_SM_PAIR_ALG_JW,
- .tk = { 0 },
- .stk = {
- 0x2e, 0x2b, 0x34, 0xca, 0x59, 0xfa, 0x4c, 0x88,
- 0x3b, 0x2c, 0x8a, 0xef, 0xd4, 0x4b, 0xe9, 0x66,
- },
- .r = 0,
- .ediv = 0,
- };
-
- ble_sm_test_util_us_lgcy_good(¶ms);
-}
-
-/**
- * Master: peer.
- * We send a security request.
- * We accept pairing request sent in response.
- */
-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_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,
- },
- .has_sec_req = 1,
- .pair_req = (struct ble_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_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_sm_pair_confirm) {
- .value = {
- 0x54, 0xed, 0x7c, 0x65, 0xc5, 0x3a, 0xee, 0x87,
- 0x8e, 0xf8, 0x04, 0xd8, 0x93, 0xb0, 0xfa, 0xa4,
- },
- },
- .confirm_rsp = (struct ble_sm_pair_confirm) {
- .value = {
- 0xdf, 0x96, 0x88, 0x73, 0x49, 0x24, 0x3f, 0xe8,
- 0xb0, 0xaf, 0xb3, 0xf6, 0xc8, 0xf4, 0xe2, 0x36,
- },
- },
- .random_req = (struct ble_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_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_info = {
- .passkey = {
- .action = BLE_SM_IOACT_INPUT,
- .passkey = 884570,
- },
- .io_before_rx = 1,
- },
-
- .enc_info_req = {
- .ltk = {
- 0x2b, 0x9c, 0x1e, 0x42, 0xa8, 0xcb, 0xab, 0xd1,
- 0x4b, 0xde, 0x50, 0x05, 0x50, 0xd9, 0x95, 0xc6
- },
- },
- .has_enc_info_req = 1,
-
- .master_id_req = {
- .ediv = 61621,
- .rand_val = 4107344270811490869,
- },
- .has_master_id_req = 1,
-
- .enc_info_rsp = {
- .ltk = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 }
- },
- .has_enc_info_rsp = 1,
-
- .master_id_rsp = {
- .ediv = 61621,
- .rand_val = 4107344270811490869,
- },
- .has_master_id_rsp = 1,
- };
-
- ble_sm_test_util_peer_lgcy_good(¶ms);
-}
-
-/**
- * Master: peer
- * Secure connections
- * Pair algorithm: just works
- */
-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_id_addr = {
- 0xd9, 0x38, 0x0c, 0x57, 0x0b, 0x00,
- },
- .resp_id_addr = {
- 0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
- },
- .pair_req = {
- .io_cap = 0x03,
- .oob_data_flag = 0x00,
- .authreq = 0x08,
- .max_enc_key_size = 0x10,
- .init_key_dist = 0x00,
- .resp_key_dist = 0x00,
- },
- .pair_rsp = {
- .io_cap = 0x03,
- .oob_data_flag = 0x00,
- .authreq = 0x09,
- .max_enc_key_size = 0x10,
- .init_key_dist = 0x00,
- .resp_key_dist = 0x00,
- },
- .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 = {
- 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 = {
- 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 = {
- .x = {
- 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 = {
- 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 = {
- 0xd6, 0x8c, 0x6e, 0x03, 0x9d, 0x29, 0xdc, 0xb1,
- 0xa5, 0x16, 0x4c, 0xf3, 0x6f, 0x32, 0xd3, 0x6c,
- },
- },
- .random_req[0] = {
- .value = {
- 0x15, 0x63, 0xb7, 0xf3, 0xda, 0xd4, 0xec, 0xe3,
- 0xd7, 0x28, 0xb4, 0xf0, 0xf5, 0xac, 0xfb, 0x9a,
- },
- },
- .random_rsp[0] = {
- .value = {
- 0x83, 0xa9, 0x2a, 0xa7, 0xfb, 0xcc, 0xcd, 0x3a,
- 0xaa, 0xd2, 0x08, 0xd8, 0x23, 0x21, 0xc8, 0x03,
- },
- },
- .dhkey_check_req = {
- .value = {
- 0x16, 0xd7, 0x43, 0x3e, 0xfd, 0x89, 0x36, 0x7d,
- 0x18, 0xad, 0x4d, 0xda, 0xa5, 0x48, 0x90, 0xdd,
- },
- },
- .dhkey_check_rsp = {
- .value = {
- 0xbe, 0xa9, 0x51, 0x38, 0x56, 0x82, 0x24, 0x42,
- 0xca, 0x3f, 0x66, 0xf4, 0xb8, 0x4e, 0xdb, 0x0e,
- },
- },
- .ltk = {
- 0xf3, 0x18, 0x03, 0x68, 0x79, 0x56, 0x75, 0x43,
- 0xcf, 0xaa, 0x80, 0x2d, 0xbc, 0x3a, 0x6b, 0x64,
- },
- .pair_alg = BLE_SM_PAIR_ALG_JW,
- .authenticated = 0,
- .passkey_info = {
- .passkey = {
- .action = BLE_SM_IOACT_NONE,
- },
- },
- };
- ble_sm_test_util_peer_sc_good(¶ms);
-}
-
-/**
- * Master: us
- * Secure connections
- * Pair algorithm: numeric comparison
- */
-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_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,
- .authreq = 0x0d,
- .max_enc_key_size = 16,
- .init_key_dist = 0x01,
- .resp_key_dist = 0x01,
- },
- .pair_rsp = (struct ble_sm_pair_cmd) {
- .io_cap = 0x01,
- .oob_data_flag = 0x00,
- .authreq = 0x0d,
- .max_enc_key_size = 16,
- .init_key_dist = 0x01,
- .resp_key_dist = 0x01,
- },
- .public_key_req = (struct ble_sm_public_key) {
- .x = {
- 0xb5, 0x48, 0x49, 0x35, 0xe6, 0xc4, 0x91, 0x6c,
- 0x65, 0x39, 0xd3, 0x51, 0x1d, 0x8c, 0xc5, 0x62,
- 0x87, 0xc9, 0x1b, 0x06, 0x96, 0x78, 0x4a, 0xaa,
- 0x18, 0x70, 0x85, 0x99, 0xfc, 0x01, 0xf4, 0xba
- },
- .y= {
- 0xe0, 0x9f, 0x1b, 0x49, 0x31, 0x43, 0xf8, 0xae,
- 0xff, 0xd1, 0x8f, 0x19, 0xc0, 0x1a, 0x44, 0x8f,
- 0x0c, 0xc6, 0xc4, 0x7f, 0x2e, 0xf0, 0xb4, 0x31,
- 0x1b, 0x75, 0xa9, 0x0a, 0xa1, 0x28, 0xb1, 0xbc
- },
- },
- .public_key_rsp = (struct ble_sm_public_key) {
- .x = {
- 0x04, 0xf7, 0x4b, 0x20, 0x94, 0x55, 0xd4, 0x95,
- 0xff, 0x04, 0x71, 0xa9, 0xe6, 0x36, 0x09, 0x9a,
- 0xd8, 0x55, 0xb3, 0x56, 0xcc, 0x59, 0x1d, 0xab,
- 0x7d, 0x0a, 0x21, 0x95, 0xc4, 0xdb, 0x8a, 0x8a
- },
- .y = {
- 0x08, 0xc9, 0xe7, 0x6b, 0x50, 0x3d, 0x25, 0x44,
- 0x32, 0xce, 0xa6, 0x07, 0xfc, 0x76, 0x78, 0xb7,
- 0xa4, 0x8a, 0xdc, 0xf8, 0x9c, 0x85, 0x61, 0x7f,
- 0x7f, 0x4f, 0x9e, 0xcd, 0xe3, 0xac, 0x78, 0x65
- },
-
- },
- .confirm_rsp[0] = {
- .value = {
- 0x36, 0xb4, 0x46, 0x1f, 0xc0, 0x6f, 0xd3, 0x5b,
- 0x18, 0x81, 0xbd, 0xe7, 0x05, 0xa2, 0x72, 0x75
- },
- },
- .random_req[0] = {
- .value = {
- 0x1e, 0xc6, 0x28, 0xd7, 0x7e, 0xb7, 0x4c, 0xe7,
- 0xbc, 0xac, 0x50, 0x67, 0xd1, 0x1c, 0xd9, 0xd8
- },
- },
- .random_rsp[0] = {
- .value = {
- 0x6b, 0x06, 0x4c, 0xdc, 0x02, 0x05, 0xcd, 0x34,
- 0xde, 0x0b, 0x4d, 0x37, 0x7f, 0x2c, 0x26, 0xef
- },
- },
- .dhkey_check_req = (struct ble_sm_dhkey_check) {
- .value = {
- 0xd5, 0x2d, 0x3e, 0x0b, 0x63, 0x4d, 0xea, 0xe8,
- 0x77, 0x10, 0x9c, 0x9a, 0xc5, 0x61, 0x89, 0x24
- }
- },
- .dhkey_check_rsp = (struct ble_sm_dhkey_check) {
- .value = {
- 0x2d, 0x1f, 0x24, 0x2e, 0x80, 0x0e, 0xc3, 0x74,
- 0xe3, 0x3f, 0xdb, 0xb6, 0x3e, 0x3d, 0x24, 0x08
- }
- },
- .pair_alg = BLE_SM_PAIR_ALG_NUMCMP,
- .authenticated = 1,
- .ltk = {
- 0x38, 0xfd, 0x2a, 0x71, 0xfd, 0xd0, 0x03, 0xc0,
- 0x2e, 0xb0, 0xa3, 0xc3, 0x01, 0xf7, 0x4e, 0x41
- },
- .our_priv_key = {
- 0x90, 0x79, 0x54, 0xed, 0xed, 0x5f, 0x0c, 0x86,
- 0x98, 0x41, 0x6d, 0xec, 0xde, 0xd0, 0x4b, 0x5a,
- 0x52, 0xca, 0x04, 0x04, 0x76, 0x73, 0x0f, 0x79,
- 0xd0, 0xf8, 0xff, 0x33, 0xd2, 0x36, 0x77, 0x1e
- },
-
- .passkey_info = {
- .passkey = {
- .action = BLE_SM_IOACT_NUMCMP,
- .numcmp_accept = 1,
- },
-
- .exp_numcmp = 9737,
- .io_before_rx = 0,
- },
- };
- ble_sm_test_util_us_sc_good(¶ms);
-}
-
-/**
- * Master: us
- * Secure connections
- * 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_id_addr = {
- 0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
- },
- .resp_id_addr = {
- 0x5d, 0xab, 0xaa, 0x67, 0x11, 0x00,
- },
- .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 = 0x02,
- .oob_data_flag = 0x00,
- .authreq = 0x0d,
- .max_enc_key_size = 0x10,
- .init_key_dist = 0x06,
- .resp_key_dist = 0x06,
- },
- .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 = {
- 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 = {
- 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 = {
- .x = {
- 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 = {
- 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 = {
- 0xf8, 0xd7, 0x8b, 0xd1, 0xc3, 0x8e, 0xda, 0xb1,
- 0xbd, 0x0a, 0xa8, 0x2f, 0xa5, 0x0e, 0x31, 0x1e,
- },
- },
- .confirm_rsp[0] = {
- .value = {
- 0x62, 0x90, 0x2e, 0x53, 0x50, 0x49, 0xdc, 0x15,
- 0x23, 0x32, 0x94, 0xaa, 0x1d, 0x47, 0x92, 0x1b,
- },
- },
- .random_req[0] = {
- .value = {
- 0xa9, 0x17, 0xb6, 0x2c, 0xa9, 0x60, 0x57, 0x95,
- 0x00, 0x9d, 0x91, 0x60, 0xb3, 0x3d, 0x66, 0x8a,
- },
- },
- .random_rsp[0] = {
- .value = {
- 0x29, 0xf4, 0x38, 0xc7, 0x15, 0xf1, 0x2c, 0x93,
- 0x3b, 0x62, 0x1a, 0xd3, 0x02, 0xdc, 0xa0, 0x16,
- },
- },
- .confirm_req[1] = {
- .value = {
- 0xda, 0xd4, 0xe3, 0xd6, 0x05, 0x04, 0xce, 0x13,
- 0xec, 0x45, 0xc5, 0x07, 0x76, 0xaf, 0x99, 0x6a,
- },
- },
- .confirm_rsp[1] = {
- .value = {
- 0xb8, 0x30, 0x8f, 0x9b, 0xda, 0xb0, 0x83, 0x0e,
- 0x9d, 0x51, 0xd0, 0xd2, 0x01, 0xf8, 0xca, 0xee,
- },
- },
- .random_req[1] = {
- .value = {
- 0xf9, 0x53, 0xa9, 0xa8, 0xf5, 0x3c, 0x82, 0x4d,
- 0x20, 0x0f, 0x4a, 0xa9, 0x93, 0xcf, 0xeb, 0x53,
- },
- },
- .random_rsp[1] = {
- .value = {
- 0xa3, 0xe1, 0x17, 0x79, 0x15, 0x46, 0x76, 0x2d,
- 0x08, 0xf5, 0x87, 0x23, 0x01, 0xe8, 0x17, 0xf7,
- },
- },
- .confirm_req[2] = {
- .value = {
- 0xf0, 0x60, 0x26, 0x3c, 0x9f, 0x1a, 0x47, 0xa8,
- 0xf5, 0xbd, 0x6d, 0xae, 0x82, 0xa4, 0x69, 0xe5,
- },
- },
- .confirm_rsp[2] = {
- .value = {
- 0x53, 0xda, 0xca, 0xcd, 0x4d, 0x4d, 0x79, 0x23,
- 0x3d, 0xa5, 0xcb, 0x22, 0x92, 0x91, 0xe4, 0x71,
- },
- },
- .random_req[2] = {
- .value = {
- 0xfd, 0xc6, 0x66, 0x9d, 0x46, 0x0d, 0xa8, 0x6c,
- 0x0a, 0xe8, 0x0b, 0xf7, 0x43, 0x22, 0x8e, 0x0d,
- },
- },
- .random_rsp[2] = {
- .value = {
- 0x1a, 0xcf, 0x1e, 0x2c, 0x2b, 0x5e, 0xc4, 0x70,
- 0x93, 0xde, 0x49, 0x2b, 0x0b, 0x9c, 0x59, 0x6f,
- },
- },
- .confirm_req[3] = {
- .value = {
- 0x28, 0x07, 0x48, 0x38, 0xc5, 0x10, 0x04, 0x07,
- 0x29, 0xad, 0x46, 0x9a, 0xd0, 0x40, 0xff, 0xa3,
- },
- },
- .confirm_rsp[3] = {
- .value = {
- 0xc3, 0x05, 0x43, 0xa6, 0x1e, 0xf7, 0xec, 0x2b,
- 0xa3, 0x78, 0x28, 0x7f, 0x00, 0x8b, 0x0e, 0x93,
- },
- },
- .random_req[3] = {
- .value = {
- 0xd3, 0x47, 0x73, 0xb0, 0x3b, 0x14, 0x5d, 0x02,
- 0x8e, 0xa2, 0xdd, 0x73, 0x9c, 0x61, 0xde, 0x39,
- },
- },
- .random_rsp[3] = {
- .value = {
- 0x38, 0x73, 0x05, 0x1b, 0x88, 0xf0, 0x08, 0x43,
- 0xac, 0x11, 0x00, 0x93, 0x40, 0x44, 0xa1, 0xa5,
- },
- },
- .confirm_req[4] = {
- .value = {
- 0x5c, 0x8b, 0x2d, 0x5d, 0xb3, 0x09, 0xd9, 0x70,
- 0x2f, 0x30, 0x89, 0x7a, 0xfd, 0xe9, 0x25, 0x41,
- },
- },
- .confirm_rsp[4] = {
- .value = {
- 0xf2, 0x3d, 0x0d, 0x14, 0x8f, 0x0a, 0xed, 0x83,
- 0x87, 0xcf, 0x1b, 0xda, 0x57, 0x91, 0x45, 0xb0,
- },
- },
- .random_req[4] = {
- .value = {
- 0xae, 0xc4, 0x19, 0x5e, 0xd3, 0xae, 0x04, 0x4a,
- 0xf1, 0xdd, 0x6b, 0x93, 0xa3, 0x30, 0x39, 0x15,
- },
- },
- .random_rsp[4] = {
- .value = {
- 0x2a, 0xa8, 0xa7, 0x97, 0x07, 0x24, 0x31, 0x11,
- 0x06, 0x2a, 0x06, 0xba, 0x08, 0x5d, 0x79, 0x1c,
- },
- },
- .confirm_req[5] = {
- .value = {
- 0xee, 0xe5, 0x6e, 0x53, 0xd9, 0x2d, 0x08, 0x16,
- 0x71, 0x1f, 0xfd, 0xd6, 0x06, 0x81, 0x28, 0x44,
- },
- },
- .confirm_rsp[5] = {
- .value = {
- 0x7f, 0xe3, 0x43, 0x09, 0x51, 0x03, 0x9e, 0xe2,
- 0x6a, 0x6c, 0x98, 0xed, 0x0b, 0x87, 0x60, 0x0f,
- },
- },
- .random_req[5] = {
- .value = {
- 0x65, 0x31, 0xca, 0xfa, 0xb4, 0xa5, 0x7e, 0xac,
- 0xb2, 0xb0, 0xe5, 0x18, 0xab, 0x4d, 0xfa, 0x6f,
- },
- },
- .random_rsp[5] = {
- .value = {
- 0xa1, 0x20, 0x17, 0x37, 0x14, 0x41, 0x73, 0x60,
- 0x1e, 0x95, 0x0f, 0x59, 0xca, 0x13, 0x01, 0x70,
- },
- },
- .confirm_req[6] = {
- .value = {
- 0xdc, 0x24, 0x50, 0x40, 0x24, 0x59, 0x92, 0xa5,
- 0x48, 0x1a, 0x51, 0x28, 0x10, 0xf8, 0x03, 0x6f,
- },
- },
- .confirm_rsp[6] = {
- .value = {
- 0xf1, 0xc4, 0x5e, 0x43, 0xfc, 0x50, 0xe7, 0x7b,
- 0x54, 0x84, 0xb5, 0xb1, 0xd6, 0x6c, 0x8e, 0xab,
- },
- },
- .random_req[6] = {
- .value = {
- 0xff, 0xa6, 0x57, 0x88, 0x15, 0xb6, 0xf3, 0x2f,
- 0x44, 0x8b, 0x1b, 0xf5, 0x82, 0xf7, 0x8f, 0x8b,
- },
- },
- .random_rsp[6] = {
- .value = {
- 0x11, 0x53, 0x47, 0xdc, 0x8a, 0xc8, 0x85, 0xe8,
- 0x13, 0x35, 0xc9, 0x23, 0x04, 0x68, 0x57, 0x77,
- },
- },
- .confirm_req[7] = {
- .value = {
- 0xab, 0x1e, 0x35, 0xf5, 0xe2, 0x05, 0xba, 0xab,
- 0x66, 0x05, 0x71, 0x3b, 0x6d, 0x89, 0x96, 0x6f,
- },
- },
- .confirm_rsp[7] = {
- .value = {
- 0xa5, 0xf5, 0xe9, 0xf2, 0x56, 0xdd, 0xd4, 0x9c,
- 0x21, 0x71, 0x6c, 0xd0, 0x9d, 0x74, 0x9d, 0x1f,
- },
- },
- .random_req[7] = {
- .value = {
- 0x7f, 0xc6, 0x91, 0x00, 0xac, 0x8c, 0x0b, 0x56,
- 0x32, 0xd0, 0x96, 0xdd, 0xa6, 0x6a, 0xc7, 0xcd,
- },
- },
- .random_rsp[7] = {
- .value = {
- 0x38, 0x73, 0x05, 0x1b, 0x88, 0xf0, 0x08, 0x43,
- 0xac, 0x11, 0x00, 0x93, 0x40, 0x44, 0xa1, 0xa5,
- },
- },
- .confirm_req[8] = {
- .value = {
- 0x48, 0x9b, 0xbe, 0xc5, 0x33, 0xec, 0xe4, 0x53,
- 0xad, 0x78, 0x2f, 0x5f, 0x5a, 0xd0, 0x1d, 0x23,
- },
- },
- .confirm_rsp[8] = {
- .value = {
- 0x5a, 0x3c, 0x74, 0x5c, 0xa0, 0xbe, 0xe2, 0x55,
- 0x15, 0x1c, 0x36, 0x5c, 0xdc, 0x73, 0x15, 0x8f,
- },
- },
- .random_req[8] = {
- .value = {
- 0xfb, 0xed, 0xa1, 0x86, 0xc9, 0x9b, 0xa1, 0x78,
- 0xdc, 0x4a, 0x2e, 0x7b, 0x3d, 0x13, 0xff, 0xe2,
- },
- },
- .random_rsp[8] = {
- .value = {
- 0x0c, 0xf2, 0x3e, 0x12, 0xe7, 0x14, 0x05, 0x37,
- 0x00, 0x6c, 0x2d, 0x12, 0x86, 0xc0, 0x44, 0xae,
- },
- },
- .confirm_req[9] = {
- .value = {
- 0xd2, 0xfa, 0x02, 0x65, 0xde, 0xce, 0x27, 0x0f,
- 0xc9, 0x6e, 0x67, 0xba, 0x0a, 0x6e, 0x5a, 0x46,
- },
- },
- .confirm_rsp[9] = {
- .value = {
- 0xca, 0x65, 0x4d, 0xb8, 0x03, 0x29, 0x81, 0xe7,
- 0x2c, 0x53, 0x54, 0x44, 0xee, 0xe7, 0x63, 0xc3,
- },
- },
- .random_req[9] = {
- .value = {
- 0xa8, 0x82, 0xe0, 0xba, 0xe9, 0x10, 0xd5, 0x18,
- 0x59, 0xb0, 0xea, 0xf9, 0xcb, 0x8b, 0x1f, 0x92,
- },
- },
- .random_rsp[9] = {
- .value = {
- 0x05, 0xe8, 0xd7, 0x54, 0x08, 0x3c, 0x2c, 0x61,
- 0x1e, 0x2d, 0x0f, 0x58, 0xc9, 0x18, 0x01, 0x6f,
- },
- },
- .confirm_req[10] = {
- .value = {
- 0xc7, 0xf9, 0xbc, 0x6c, 0xb8, 0x65, 0x58, 0xdd,
- 0xf7, 0x41, 0xbe, 0x82, 0x9f, 0xf3, 0x5f, 0x7c,
- },
- },
- .confirm_rsp[10] = {
- .value = {
- 0x8d, 0xcb, 0x7a, 0x4b, 0x16, 0x36, 0x3f, 0x27,
- 0xd2, 0xf0, 0x47, 0xad, 0x06, 0x3c, 0xd5, 0x2d,
- },
- },
- .random_req[10] = {
- .value = {
- 0x14, 0x76, 0x2a, 0xd4, 0xa3, 0xf3, 0xe7, 0x17,
- 0x29, 0x1c, 0x4f, 0x95, 0x53, 0xa2, 0xd4, 0xc8,
- },
- },
- .random_rsp[10] = {
- .value = {
- 0xc7, 0x18, 0x04, 0xcf, 0x64, 0xab, 0x0e, 0x9b,
- 0x49, 0x74, 0x4f, 0x07, 0x02, 0x13, 0x4f, 0x0b,
- },
- },
- .confirm_req[11] = {
- .value = {
- 0x48, 0xa7, 0x32, 0xe3, 0xa4, 0x90, 0xc1, 0x5e,
- 0x36, 0x44, 0x3e, 0x21, 0xdd, 0x3e, 0x1b, 0x85,
- },
- },
- .confirm_rsp[11] = {
- .value = {
- 0xd7, 0x2f, 0x35, 0xa2, 0x2e, 0xc7, 0x68, 0xa1,
- 0xc4, 0x81, 0xeb, 0xb6, 0xbc, 0x4c, 0xcb, 0xc1,
- },
- },
- .random_req[11] = {
- .value = {
- 0xee, 0x15, 0xfe, 0x73, 0x1e, 0xa2, 0xe1, 0x0b,
- 0x19, 0xe1, 0x39, 0x32, 0xb1, 0xc6, 0x82, 0x21,
- },
- },
- .random_rsp[11] = {
- .value = {
- 0x15, 0x3f, 0x6c, 0xc6, 0x06, 0x28, 0x04, 0x47,
- 0x3c, 0xdc, 0x0d, 0x5a, 0x01, 0x9f, 0x6f, 0xe6,
- },
- },
- .confirm_req[12] = {
- .value = {
- 0x5a, 0x8f, 0xd9, 0xb9, 0xc8, 0x8c, 0x2f, 0xf9,
- 0x55, 0xa2, 0x2f, 0xf5, 0xca, 0x67, 0xe9, 0x36,
- },
- },
- .confirm_rsp[12] = {
- .value = {
- 0xa2, 0x71, 0xae, 0xf7, 0xec, 0xf4, 0x91, 0x5d,
- 0x5f, 0x50, 0xf6, 0x85, 0xab, 0x64, 0x84, 0x7d,
- },
- },
- .random_req[12] = {
- .value = {
- 0x2d, 0x52, 0x5c, 0x7c, 0x6b, 0xfb, 0x01, 0x9d,
- 0x1e, 0x8e, 0xbe, 0x14, 0xe6, 0x42, 0xc8, 0x7a,
- },
- },
- .random_rsp[12] = {
- .value = {
- 0x0c, 0xdc, 0x3d, 0xbb, 0xe6, 0x25, 0x05, 0x33,
- 0x0d, 0x42, 0x01, 0x40, 0x5f, 0x8b, 0xcc, 0x7b,
- },
- },
- .confirm_req[13] = {
- .value = {
- 0x3e, 0x56, 0xa1, 0x59, 0x3d, 0x68, 0x57, 0x12,
- 0xf2, 0xe1, 0x56, 0x31, 0xd7, 0x1e, 0xaa, 0x94,
- },
- },
- .confirm_rsp[13] = {
- .value = {
- 0xcb, 0x6f, 0x5b, 0x5a, 0x5e, 0xae, 0x6e, 0x20,
- 0x4f, 0xe8, 0xb0, 0xbb, 0xfb, 0xcd, 0xed, 0x7c,
- },
- },
- .random_req[13] = {
- .value = {
- 0xff, 0x99, 0x8e, 0xe5, 0x47, 0xaf, 0xcf, 0xb0,
- 0x0e, 0x36, 0x29, 0x8a, 0x1c, 0x5f, 0x84, 0xf2,
- },
- },
- .random_rsp[13] = {
- .value = {
- 0x4a, 0x13, 0x08, 0xd3, 0x54, 0xe1, 0x04, 0xe8,
- 0x22, 0x13, 0x2b, 0x53, 0xc2, 0xe1, 0x04, 0xe8,
- },
- },
- .confirm_req[14] = {
- .value = {
- 0xee, 0xa3, 0xd0, 0x41, 0xa1, 0x22, 0x70, 0x09,
- 0xef, 0xd7, 0x53, 0xa2, 0x50, 0xba, 0x0d, 0xda,
- },
- },
- .confirm_rsp[14] = {
- .value = {
- 0xbb, 0x54, 0x96, 0xba, 0x65, 0x0d, 0xef, 0xf4,
- 0x07, 0xf1, 0x8c, 0x2e, 0x96, 0x68, 0xf6, 0x2a,
- },
- },
- .random_req[14] = {
- .value = {
- 0x2d, 0x90, 0xf1, 0xc0, 0x3f, 0xdc, 0xf5, 0x04,
- 0x9b, 0x44, 0x47, 0xca, 0x79, 0x30, 0xce, 0xf1,
- },
- },
- .random_rsp[14] = {
- .value = {
- 0x3e, 0x62, 0x1d, 0xd3, 0x05, 0xdc, 0x9e, 0x34,
- 0x69, 0xbc, 0x68, 0x8f, 0x02, 0x83, 0x09, 0xc6,
- },
- },
- .confirm_req[15] = {
- .value = {
- 0x7a, 0x04, 0x8d, 0x33, 0x17, 0xf3, 0xd3, 0x4b,
- 0xbb, 0xee, 0x9f, 0xd4, 0xf7, 0x57, 0xd0, 0xbf,
- },
- },
- .confirm_rsp[15] = {
- .value = {
- 0x5c, 0xd8, 0x9c, 0x76, 0xb1, 0x15, 0x86, 0x5a,
- 0x97, 0xec, 0x4f, 0xee, 0x05, 0xa9, 0x6e, 0x70,
- },
- },
- .random_req[15] = {
- .value = {
- 0xb5, 0x3f, 0xf9, 0x77, 0x4b, 0x1a, 0x48, 0x1b,
- 0xdc, 0x5a, 0x77, 0x33, 0x9f, 0x8a, 0x5e, 0x90,
- },
- },
- .random_rsp[15] = {
- .value = {
- 0x15, 0x3f, 0x6c, 0xc6, 0x06, 0x28, 0x04, 0x47,
- 0x3c, 0xdd, 0x0e, 0x48, 0x01, 0xa0, 0x70, 0x9b,
- },
- },
- .confirm_req[16] = {
- .value = {
- 0x3b, 0xc6, 0x0a, 0xd5, 0x5a, 0xb1, 0x61, 0xaf,
- 0x5b, 0x8b, 0x58, 0x3b, 0x23, 0xea, 0xed, 0x81,
- },
- },
- .confirm_rsp[16] = {
- .value = {
- 0x54, 0xaf, 0xe2, 0x69, 0xaa, 0xaf, 0x5d, 0xd6,
- 0x21, 0x75, 0x09, 0x13, 0x0a, 0x41, 0x7a, 0x10,
- },
- },
- .random_req[16] = {
- .value = {
- 0xff, 0x0f, 0x22, 0x7f, 0x03, 0xd4, 0x80, 0x85,
- 0xd8, 0x0a, 0x66, 0xb2, 0x8d, 0x6a, 0x65, 0x00,
- },
- },
- .random_rsp[16] = {
- .value = {
- 0x0c, 0xdc, 0x3d, 0xbb, 0xe6, 0x25, 0x05, 0x33,
- 0x0d, 0x42, 0x01, 0x40, 0x5f, 0x8b, 0xcc, 0x7b,
- },
- },
- .confirm_req[17] = {
- .value = {
- 0x2d, 0xc8, 0x19, 0x6a, 0xfe, 0x40, 0x57, 0x4f,
- 0xa8, 0xbe, 0x58, 0xd9, 0x8e, 0x32, 0x96, 0xe2,
- },
- },
- .confirm_rsp[17] = {
- .value = {
- 0x94, 0xff, 0x0b, 0x01, 0x11, 0xe3, 0x97, 0xdb,
- 0xba, 0x0f, 0x75, 0x25, 0x39, 0xe6, 0xa2, 0x49,
- },
- },
- .random_req[17] = {
- .value = {
- 0xe2, 0x7f, 0x62, 0xfe, 0x5f, 0xe8, 0x80, 0x78,
- 0x16, 0x7d, 0x9d, 0x70, 0x7c, 0x5c, 0x74, 0xe7,
- },
- },
- .random_rsp[17] = {
- .value = {
- 0xd0, 0x41, 0x09, 0x80, 0x1a, 0xe1, 0x8e, 0xca,
- 0x58, 0x50, 0x34, 0x7f, 0x3d, 0x1f, 0x23, 0xc9,
- },
- },
- .confirm_req[18] = {
- .value = {
- 0x84, 0xcf, 0xe3, 0x8e, 0xfe, 0x08, 0xca, 0x37,
- 0x22, 0x51, 0x33, 0xdc, 0x8c, 0xc6, 0x1c, 0x42,
- },
- },
- .confirm_rsp[18] = {
- .value = {
- 0xf0, 0xbf, 0xff, 0xfe, 0x8c, 0xf3, 0x86, 0x08,
- 0x33, 0x78, 0x04, 0x2d, 0x10, 0x4f, 0xb7, 0x0a,
- },
- },
- .random_req[18] = {
- .value = {
- 0xaa, 0x15, 0x3c, 0xa2, 0x00, 0x85, 0x2b, 0x22,
- 0x55, 0x3a, 0xc3, 0x57, 0x1c, 0x8f, 0x12, 0xc4,
- },
- },
- .random_rsp[18] = {
- .value = {
- 0x0b, 0xc0, 0x19, 0x92, 0x8a, 0x88, 0x05, 0xe7,
- 0x36, 0xbf, 0x3b, 0xd0, 0x1f, 0x87, 0x05, 0xe4,
- },
- },
- .confirm_req[19] = {
- .value = {
- 0xcc, 0x43, 0xbe, 0x75, 0x4d, 0x37, 0x49, 0x17,
- 0x6e, 0x19, 0x19, 0xf5, 0xbc, 0xcb, 0xf7, 0xdf,
- },
- },
- .confirm_rsp[19] = {
- .value = {
- 0x40, 0x69, 0x4e, 0x28, 0xfd, 0x0e, 0xc9, 0x89,
- 0x1d, 0x68, 0x40, 0xfd, 0xdc, 0x5c, 0xed, 0x1e,
- },
- },
- .random_req[19] = {
- .value = {
- 0xa4, 0xc6, 0x1f, 0xa7, 0x88, 0xd4, 0x5e, 0x0b,
- 0xe1, 0x43, 0xd4, 0x83, 0x52, 0xbd, 0xd4, 0x47,
- },
- },
- .random_rsp[19] = {
- .value = {
- 0x15, 0x3f, 0x6c, 0xc6, 0x06, 0x28, 0x04, 0x47,
- 0x3c, 0xdd, 0x0e, 0x48, 0x01, 0xa0, 0x70, 0x9b,
- },
- },
- .dhkey_check_req = {
- .value = {
- 0x7f, 0x11, 0x0f, 0x4a, 0xc8, 0xfc, 0x50, 0x3c,
- 0xd6, 0x4d, 0xa6, 0x8e, 0xc3, 0x05, 0x38, 0x68,
- },
- },
- .dhkey_check_rsp = {
- .value = {
- 0x01, 0x82, 0xdb, 0xcf, 0x45, 0x4f, 0xd9, 0xa9,
- 0x84, 0x0a, 0xbb, 0xba, 0x10, 0xd5, 0xa2, 0x8d,
- },
- },
- .id_info_req = {
- .irk = {
- 0xe6, 0x76, 0xc3, 0x82, 0x96, 0xea, 0xbc, 0x0f,
- 0x26, 0xcc, 0xdc, 0xf8, 0x03, 0xae, 0x2e, 0xca,
- },
- },
- .id_addr_info_req = {
- .addr_type = 0,
- .bd_addr = {
- 0x5d, 0xab, 0xaa, 0x67, 0x11, 0x00,
- },
- },
- .sign_info_req = {
- .sig_key = {
- 0xec, 0xa4, 0xbf, 0x6c, 0x58, 0xa3, 0xa7, 0x5c,
- 0x5b, 0xfa, 0x55, 0x41, 0xf0, 0xa0, 0x55, 0xba,
- },
- },
- .id_info_rsp = {
- .irk = {
- 0xef, 0x8d, 0xe2, 0x16, 0x4f, 0xec, 0x43, 0x0d,
- 0xbf, 0x5b, 0xdd, 0x34, 0xc0, 0x53, 0x1e, 0xb8,
- },
+ .io_cap = 0x04,
+ .oob_data_flag = 0,
+ .authreq = 0x05,
+ .max_enc_key_size = 17,
+ .init_key_dist = 0x10,
+ .resp_key_dist = 0x07,
},
- .id_addr_info_rsp = {
- .addr_type = 0,
- .bd_addr = {
- 0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
- },
+ .pair_fail = (struct ble_sm_pair_fail) {
+ .reason = BLE_SM_ERR_INVAL,
},
- .sign_info_rsp = {
- .sig_key = {
- 0x6c, 0xaa, 0x89, 0xe1, 0xbc, 0x98, 0x0d, 0x5f,
- 0x0d, 0x07, 0x5f, 0x81, 0x69, 0xdb, 0x75, 0x72,
- },
+ };
+ ble_sm_test_util_us_fail_inval(¶ms);
+
+ /* Invalid resp key dist. */
+ params = (struct ble_sm_test_params) {
+ .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,
+ .authreq = 0,
+ .max_enc_key_size = 16,
+ .init_key_dist = 0,
+ .resp_key_dist = 0,
},
- .ltk = {
- 0x0a, 0xad, 0xb7, 0x13, 0x4d, 0x9a, 0xed, 0xa9,
- 0x12, 0xbd, 0xde, 0xa0, 0x51, 0x9e, 0x67, 0x26,
+ .pair_rsp = (struct ble_sm_pair_cmd) {
+ .io_cap = 0x04,
+ .oob_data_flag = 0,
+ .authreq = 0x05,
+ .max_enc_key_size = 17,
+ .init_key_dist = 0x07,
+ .resp_key_dist = 0x10,
},
- .pair_alg = BLE_SM_PAIR_ALG_PASSKEY,
- .authenticated = 1,
- .passkey_info = {
- .passkey = {
- .action = BLE_SM_IOACT_DISP,
- .passkey = 946612,
- },
+ .pair_fail = (struct ble_sm_pair_fail) {
+ .reason = BLE_SM_ERR_INVAL,
},
};
- ble_sm_test_util_us_sc_good(¶ms);
+ ble_sm_test_util_us_fail_inval(¶ms);
}
-TEST_SUITE(ble_sm_test_suite)
+TEST_SUITE(ble_sm_gen_test_suite)
{
ble_sm_test_case_f4();
ble_sm_test_case_f5();
@@ -2555,15 +655,10 @@ TEST_SUITE(ble_sm_test_suite)
ble_sm_test_case_peer_fail_inval();
ble_sm_test_case_peer_lgcy_fail_confirm();
- ble_sm_test_case_peer_lgcy_jw_good();
- 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_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_us_sec_req_pair();
}
#endif
@@ -2573,7 +668,9 @@ ble_sm_test_all(void)
#if !NIMBLE_OPT(SM)
return 0;
#else
- ble_sm_test_suite();
+ ble_sm_gen_test_suite();
+ ble_sm_lgcy_test_suite();
+ ble_sm_sc_test_suite();
return tu_any_failed;
#endif
[9/9] incubator-mynewt-core git commit: BLE Host - More SM unit tests.
Posted by cc...@apache.org.
BLE Host - More SM 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/39dd36c8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/39dd36c8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/39dd36c8
Branch: refs/heads/develop
Commit: 39dd36c86734aa438fd6a4b583007c612e0ca420
Parents: e347a0d
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 15 20:47:20 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Jun 16 21:01:34 2016 -0700
----------------------------------------------------------------------
net/nimble/host/include/host/ble_hs_test.h | 4 +-
net/nimble/host/src/ble_sm.c | 5 +-
net/nimble/host/src/ble_sm_cmd.c | 35 +-
net/nimble/host/src/test/ble_hs_test.c | 3 +-
net/nimble/host/src/test/ble_sm_lgcy_test.c | 702 +++++++
net/nimble/host/src/test/ble_sm_sc_test.c | 68 +-
net/nimble/host/src/test/ble_sm_test.c | 2239 ++--------------------
net/nimble/host/src/test/ble_sm_test_util.c | 1610 +++++++++-------
net/nimble/host/src/test/ble_sm_test_util.h | 67 +-
9 files changed, 1883 insertions(+), 2850 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/39dd36c8/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 375a85e..787ec41 100644
--- a/net/nimble/host/include/host/ble_hs_test.h
+++ b/net/nimble/host/include/host/ble_hs_test.h
@@ -43,8 +43,10 @@ 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);
+int ble_sm_lgcy_test_suite(void);
+int ble_sm_sc_test_suite(void);
+
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/39dd36c8/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 76cbbd0..62e2501 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -1572,11 +1572,12 @@ ble_sm_pair_rsp_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
} else {
ble_sm_pair_cfg(proc);
+ proc->state = ble_sm_state_after_pair(proc);
ioact = ble_sm_io_action(proc);
if (ble_sm_ioact_state(ioact) == proc->state) {
res->passkey_action.action = ioact;
- } else {
- proc->state = ble_sm_state_after_pair(proc);
+ }
+ if (ble_sm_proc_can_advance(proc)) {
res->execute = 1;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/39dd36c8/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 ebb1e54..4151856 100644
--- a/net/nimble/host/src/ble_sm_cmd.c
+++ b/net/nimble/host/src/ble_sm_cmd.c
@@ -347,6 +347,19 @@ ble_sm_enc_info_parse(void *payload, int len, struct ble_sm_enc_info *cmd)
memcpy(cmd->ltk, payload, sizeof cmd->ltk);
}
+void
+ble_sm_enc_info_write(void *payload, int len, struct ble_sm_enc_info *cmd)
+{
+ uint8_t *u8ptr;
+
+ BLE_HS_DBG_ASSERT(len >= BLE_SM_HDR_SZ + BLE_SM_ENC_INFO_SZ);
+
+ u8ptr = payload;
+
+ u8ptr[0] = BLE_SM_OP_ENC_INFO;
+ memcpy(u8ptr + 1, cmd->ltk, sizeof cmd->ltk);
+}
+
int
ble_sm_enc_info_tx(uint16_t conn_handle, struct ble_sm_enc_info *cmd)
{
@@ -359,8 +372,7 @@ ble_sm_enc_info_tx(uint16_t conn_handle, struct ble_sm_enc_info *cmd)
goto done;
}
- txom->om_data[0] = BLE_SM_OP_ENC_INFO;
- memcpy(txom->om_data + 1, cmd->ltk, sizeof cmd->ltk);
+ ble_sm_enc_info_write(txom->om_data, txom->om_len, cmd);
BLE_SM_LOG_CMD(1, "enc info", conn_handle, ble_sm_enc_info_log, cmd);
@@ -382,11 +394,28 @@ ble_sm_enc_info_log(struct ble_sm_enc_info *cmd)
void
ble_sm_master_id_parse(void *payload, int len, struct ble_sm_master_id *cmd)
{
- uint8_t *u8ptr = payload;
+ uint8_t *u8ptr;
+
+ u8ptr = payload;
+
cmd->ediv = le16toh(u8ptr);
cmd->rand_val = le64toh(u8ptr + 2);
}
+void
+ble_sm_master_id_write(void *payload, int len, struct ble_sm_master_id *cmd)
+{
+ uint8_t *u8ptr;
+
+ BLE_HS_DBG_ASSERT(len >= BLE_SM_HDR_SZ + BLE_SM_MASTER_ID_SZ);
+
+ u8ptr = payload;
+
+ u8ptr[0] = BLE_SM_OP_MASTER_ID;
+ htole16(u8ptr + 1, cmd->ediv);
+ htole64(u8ptr + 3, cmd->rand_val);
+}
+
int
ble_sm_master_id_tx(uint16_t conn_handle, struct ble_sm_master_id *cmd)
{
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/39dd36c8/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 f6a139b..88a2c0c 100644
--- a/net/nimble/host/src/test/ble_hs_test.c
+++ b/net/nimble/host/src/test/ble_hs_test.c
@@ -66,10 +66,9 @@ main(int argc, char **argv)
ble_host_hci_test_all();
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_sm_test_all();
ble_uuid_test_all();
return tu_any_failed;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/39dd36c8/net/nimble/host/src/test/ble_sm_lgcy_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_sm_lgcy_test.c b/net/nimble/host/src/test/ble_sm_lgcy_test.c
new file mode 100644
index 0000000..09a7756
--- /dev/null
+++ b/net/nimble/host/src/test/ble_sm_lgcy_test.c
@@ -0,0 +1,702 @@
+/**
+ * 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)
+
+/**
+ * Legacy pairing
+ * Master: peer
+ * Pair algorithm: just works
+ * Initiator IO capabilities: 4
+ * Responder IO capabilities: 3
+ * Bonding: true
+ * Initiator address type: BLE_ADDR_TYPE_PUBLIC
+ * Responder address type: BLE_ADDR_TYPE_PUBLIC
+ * Initiator key distribution: 7
+ * Responder key distribution: 7
+ */
+TEST_CASE(ble_sm_lgcy_peer_jw_iio4_rio3_b1_iat0_rat0_ik7_rk7)
+{
+ struct ble_sm_test_params params;
+
+ params = (struct ble_sm_test_params) {
+ .init_id_addr = {
+ 0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c,
+ },
+ .resp_id_addr = {
+ 0x33, 0x22, 0x11, 0x00, 0x45, 0x0a,
+ },
+ .pair_req = {
+ .io_cap = 0x04,
+ .oob_data_flag = 0x00,
+ .authreq = 0x05,
+ .max_enc_key_size = 0x10,
+ .init_key_dist = 0x07,
+ .resp_key_dist = 0x07,
+ },
+ .pair_rsp = {
+ .io_cap = 0x03,
+ .oob_data_flag = 0x00,
+ .authreq = 0x09,
+ .max_enc_key_size = 0x10,
+ .init_key_dist = 0x07,
+ .resp_key_dist = 0x07,
+ },
+ .confirm_req[0] = {
+ .value = {
+ 0xcd, 0x5b, 0x79, 0x29, 0x53, 0x31, 0x56, 0x23,
+ 0x2c, 0x08, 0xed, 0x81, 0x16, 0x55, 0x8e, 0x01,
+ },
+ },
+ .confirm_rsp[0] = {
+ .value = {
+ 0x49, 0x39, 0x22, 0x0f, 0x7b, 0x1b, 0x80, 0xcd,
+ 0xbe, 0x89, 0xd1, 0x4c, 0xbd, 0x6f, 0xda, 0x2c,
+ },
+ },
+ .random_req[0] = {
+ .value = {
+ 0x7f, 0x42, 0xc0, 0x2f, 0x1d, 0x07, 0x37, 0xfc,
+ 0x04, 0x5b, 0x05, 0x9a, 0xed, 0x67, 0xa5, 0x68,
+ },
+ },
+ .random_rsp[0] = {
+ .value = {
+ 0x42, 0x1a, 0x58, 0xa2, 0x3b, 0x80, 0xde, 0xef,
+ 0x95, 0x0d, 0xf7, 0xca, 0x06, 0x05, 0x01, 0x3c,
+ },
+ },
+ .enc_info_req = {
+ .ltk = {
+ 0x2f, 0x9b, 0x16, 0xff, 0xf3, 0x73, 0x30, 0x08,
+ 0xa8, 0xe5, 0x01, 0xb1, 0x3b, 0xe1, 0x87, 0x00,
+ },
+ },
+ .master_id_req = {
+ .ediv = 0xf8e0,
+ .rand_val = 0xef7c818b00000000,
+ },
+ .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 = {
+ 0xc6, 0x17, 0xc0, 0x02, 0x40, 0x0d, 0x27, 0x51,
+ 0x8a, 0x77, 0xb5, 0xae, 0xd8, 0xa9, 0x7a, 0x7a,
+ },
+ },
+ .enc_info_rsp = {
+ .ltk = {
+ 0xd7, 0x07, 0x22, 0x79, 0x24, 0xc6, 0xcb, 0x4d,
+ 0xa3, 0xdd, 0x01, 0xfb, 0x48, 0x87, 0xd4, 0xcf,
+ },
+ },
+ .master_id_rsp = {
+ .ediv = 0x9a39,
+ .rand_val = 0x8e76d9b00000000,
+ },
+ .id_info_rsp = {
+ .irk = {
+ 0xeb, 0x8a, 0x06, 0xc4, 0x93, 0x51, 0x04, 0xb3,
+ 0x8b, 0xbf, 0xe8, 0x1f, 0x0e, 0x96, 0x2a, 0x54,
+ },
+ },
+ .id_addr_info_rsp = {
+ .addr_type = 0,
+ .bd_addr = {
+ 0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c,
+ },
+ },
+ .sign_info_rsp = {
+ .sig_key = {
+ 0x14, 0x55, 0x93, 0xe1, 0xd1, 0xe7, 0xc4, 0x5d,
+ 0x35, 0x97, 0xd3, 0x05, 0x30, 0xc8, 0x9d, 0x83,
+ },
+ },
+ .stk = {
+ 0x1c, 0xd7, 0xb6, 0x35, 0x48, 0xfc, 0x9f, 0xef,
+ 0x0e, 0x2f, 0x51, 0x77, 0xed, 0xdd, 0xbc, 0xaf,
+ },
+ .pair_alg = 0,
+ .authenticated = false,
+ .passkey_info = {
+ .passkey = {
+ .action = BLE_SM_IOACT_NONE,
+ },
+ },
+ };
+ ble_sm_test_util_peer_lgcy_good(¶ms);
+}
+
+/**
+ * Legacy pairing
+ * Master: peer
+ * Pair algorithm: passkey entry
+ * Initiator IO capabilities: 4
+ * Responder IO capabilities: 0
+ * Bonding: true
+ * Initiator address type: BLE_ADDR_TYPE_PUBLIC
+ * Responder address type: BLE_ADDR_TYPE_PUBLIC
+ * Initiator key distribution: 7
+ * Responder key distribution: 7
+ */
+TEST_CASE(ble_sm_lgcy_peer_pk_iio4_rio0_b1_iat0_rat0_ik7_rk7)
+{
+ struct ble_sm_test_params params;
+
+ params = (struct ble_sm_test_params) {
+ .init_id_addr = {
+ 0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c,
+ },
+ .resp_id_addr = {
+ 0x33, 0x22, 0x11, 0x00, 0x45, 0x0a,
+ },
+ .pair_req = {
+ .io_cap = 0x04,
+ .oob_data_flag = 0x00,
+ .authreq = 0x05,
+ .max_enc_key_size = 0x10,
+ .init_key_dist = 0x07,
+ .resp_key_dist = 0x07,
+ },
+ .pair_rsp = {
+ .io_cap = 0x00,
+ .oob_data_flag = 0x00,
+ .authreq = 0x09,
+ .max_enc_key_size = 0x10,
+ .init_key_dist = 0x07,
+ .resp_key_dist = 0x07,
+ },
+ .confirm_req[0] = {
+ .value = {
+ 0xa0, 0x10, 0x4a, 0xaa, 0x8b, 0x53, 0x78, 0xbb,
+ 0xd2, 0xae, 0x71, 0x1f, 0x4e, 0x00, 0x70, 0x8b,
+ },
+ },
+ .confirm_rsp[0] = {
+ .value = {
+ 0x62, 0xf3, 0xba, 0x0e, 0xe5, 0xbe, 0x2e, 0xd8,
+ 0x25, 0xb2, 0xec, 0x4c, 0x28, 0x77, 0x28, 0x60,
+ },
+ },
+ .random_req[0] = {
+ .value = {
+ 0x84, 0xcf, 0xe4, 0x04, 0x7d, 0xf3, 0xfc, 0xa1,
+ 0x3f, 0x75, 0xd6, 0x5a, 0x7c, 0xb7, 0xa4, 0x39,
+ },
+ },
+ .random_rsp[0] = {
+ .value = {
+ 0xef, 0x6a, 0x61, 0x6e, 0x02, 0x60, 0x7f, 0x5d,
+ 0x7f, 0x0d, 0xa6, 0x3c, 0x06, 0x1a, 0x5d, 0xd6,
+ },
+ },
+ .enc_info_req = {
+ .ltk = {
+ 0xad, 0x01, 0x6d, 0x76, 0xa9, 0xd0, 0x23, 0xc9,
+ 0x40, 0x0c, 0xbf, 0x2a, 0x4c, 0x23, 0x31, 0xc5,
+ },
+ },
+ .master_id_req = {
+ .ediv = 0xa74f,
+ .rand_val = 0x81cab3fd00000000,
+ },
+ .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 = {
+ 0x60, 0x08, 0x49, 0x00, 0x6d, 0x76, 0x98, 0x73,
+ 0x9c, 0x95, 0xc4, 0xd9, 0xe8, 0x3a, 0x69, 0xbb,
+ },
+ },
+ .enc_info_rsp = {
+ .ltk = {
+ 0x5b, 0x73, 0x39, 0xd9, 0x51, 0x3d, 0x92, 0xa4,
+ 0x34, 0x65, 0xa5, 0x70, 0x49, 0xbe, 0x11, 0x28,
+ },
+ },
+ .master_id_rsp = {
+ .ediv = 0x9705,
+ .rand_val = 0x592f1e8d00000000,
+ },
+ .id_info_rsp = {
+ .irk = {
+ 0xeb, 0x8a, 0x06, 0xc4, 0x93, 0x51, 0x04, 0xb3,
+ 0x8b, 0xbf, 0xe8, 0x1f, 0x0e, 0x96, 0x2a, 0x54,
+ },
+ },
+ .id_addr_info_rsp = {
+ .addr_type = 0,
+ .bd_addr = {
+ 0xe1, 0xfc, 0xda, 0xf4, 0xb7, 0x6c,
+ },
+ },
+ .sign_info_rsp = {
+ .sig_key = {
+ 0xc9, 0x9b, 0xf2, 0x75, 0xb7, 0x0d, 0xe8, 0x60,
+ 0x3d, 0xf0, 0xd6, 0xa8, 0x16, 0xc5, 0x6c, 0x2a,
+ },
+ },
+ .stk = {
+ 0xf2, 0x3c, 0x36, 0xc4, 0xa1, 0xfb, 0x5a, 0xa7,
+ 0x96, 0x20, 0xe4, 0x29, 0xb7, 0x58, 0x22, 0x7a,
+ },
+ .pair_alg = 1,
+ .authenticated = true,
+ .passkey_info = {
+ .passkey = {
+ .action = BLE_SM_IOACT_DISP,
+ .passkey = 46128,
+ },
+ },
+ };
+ ble_sm_test_util_peer_lgcy_good(¶ms);
+}
+
+/**
+ * Legacy pairing
+ * Master: us
+ * Pair algorithm: just works
+ * Initiator IO capabilities: 3
+ * Responder IO capabilities: 3
+ * Bonding: true
+ * Initiator address type: BLE_ADDR_TYPE_PUBLIC
+ * Responder address type: BLE_ADDR_TYPE_RANDOM
+ * Initiator key distribution: 7
+ * Responder key distribution: 5
+ */
+TEST_CASE(ble_sm_lgcy_us_jw_iio3_rio3_b1_iat0_rat1_ik7_rk5)
+{
+ struct ble_sm_test_params params;
+
+ params = (struct ble_sm_test_params) {
+ .init_id_addr = {
+ 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a,
+ },
+ .resp_addr_type = BLE_ADDR_TYPE_RANDOM,
+ .resp_id_addr = {
+ 0x11, 0x22, 0x11, 0x22, 0x11, 0xcc,
+ },
+ .pair_req = {
+ .io_cap = 0x03,
+ .oob_data_flag = 0x00,
+ .authreq = 0x01,
+ .max_enc_key_size = 0x10,
+ .init_key_dist = 0x07,
+ .resp_key_dist = 0x07,
+ },
+ .pair_rsp = {
+ .io_cap = 0x03,
+ .oob_data_flag = 0x00,
+ .authreq = 0x01,
+ .max_enc_key_size = 0x10,
+ .init_key_dist = 0x07,
+ .resp_key_dist = 0x05,
+ },
+ .confirm_req[0] = {
+ .value = {
+ 0x1c, 0xb6, 0x10, 0xea, 0x02, 0x08, 0x90, 0x64,
+ 0xc7, 0xf8, 0xe5, 0x9c, 0xb4, 0x3a, 0x18, 0xca,
+ },
+ },
+ .confirm_rsp[0] = {
+ .value = {
+ 0xb8, 0x6f, 0xd1, 0xc6, 0x74, 0x35, 0xa3, 0x94,
+ 0x68, 0x2f, 0xf1, 0x4c, 0x78, 0x44, 0xe8, 0x0d,
+ },
+ },
+ .random_req[0] = {
+ .value = {
+ 0x40, 0x48, 0x17, 0x4d, 0x42, 0xa0, 0xf8, 0xd5,
+ 0xbf, 0x65, 0x67, 0xb8, 0x5e, 0x57, 0x38, 0xac,
+ },
+ },
+ .random_rsp[0] = {
+ .value = {
+ 0x2c, 0xa1, 0xb1, 0xf5, 0x54, 0x9b, 0x43, 0xe9,
+ 0xb0, 0x62, 0x6a, 0xb0, 0x02, 0xb8, 0x6c, 0xca,
+ },
+ },
+ .enc_info_req = {
+ .ltk = {
+ 0x01, 0x15, 0xb6, 0x93, 0xc9, 0xff, 0xfe, 0x27,
+ 0x02, 0x41, 0xfd, 0x7b, 0x0e, 0x31, 0xd4, 0xa6,
+ },
+ },
+ .master_id_req = {
+ .ediv = 0xe4fb,
+ .rand_val = 0x8eee76b100000000,
+ },
+ .sign_info_req = {
+ .sig_key = {
+ 0x00, 0x2d, 0xf6, 0x3e, 0x5e, 0x0f, 0xd1, 0xe8,
+ 0x4e, 0x5f, 0x61, 0x1c, 0x2c, 0x0b, 0xa5, 0x51,
+ },
+ },
+ .enc_info_rsp = {
+ .ltk = {
+ 0x88, 0xbc, 0x95, 0x8d, 0xaa, 0x26, 0x8d, 0xd5,
+ 0x18, 0xc9, 0x06, 0x70, 0xc2, 0x30, 0x56, 0x4c,
+ },
+ },
+ .master_id_rsp = {
+ .ediv = 0x4413,
+ .rand_val = 0xfad1c27300000000,
+ },
+ .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 = {
+ 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a,
+ },
+ },
+ .sign_info_rsp = {
+ .sig_key = {
+ 0x03, 0xad, 0xa4, 0xe1, 0x34, 0x76, 0x95, 0x54,
+ 0xe5, 0x8f, 0xa4, 0x06, 0x72, 0xe6, 0xfc, 0x65,
+ },
+ },
+ .stk = {
+ 0x31, 0x54, 0x42, 0x6c, 0x1c, 0x03, 0x36, 0x44,
+ 0x0b, 0x72, 0x90, 0xa5, 0x1f, 0x79, 0x5b, 0xe9,
+ },
+ .pair_alg = 0,
+ .authenticated = false,
+ .passkey_info = {
+ .passkey = {
+ .action = BLE_SM_IOACT_NONE,
+ },
+ },
+ };
+ ble_sm_test_util_us_lgcy_good(¶ms);
+}
+
+/**
+ * Legacy pairing
+ * Master: us
+ * Pair algorithm: passkey entry
+ * Initiator IO capabilities: 4
+ * Responder IO capabilities: 2
+ * Bonding: true
+ * Initiator address type: BLE_ADDR_TYPE_PUBLIC
+ * Responder address type: BLE_ADDR_TYPE_RANDOM
+ * Initiator key distribution: 7
+ * Responder key distribution: 5
+ */
+TEST_CASE(ble_sm_lgcy_us_pk_iio4_rio2_b1_iat0_rat1_ik7_rk5)
+{
+ struct ble_sm_test_params params;
+
+ params = (struct ble_sm_test_params) {
+ .init_id_addr = {
+ 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a,
+ },
+ .resp_addr_type = BLE_ADDR_TYPE_RANDOM,
+ .resp_id_addr = {
+ 0x11, 0x22, 0x11, 0x22, 0x11, 0xcc,
+ },
+ .pair_req = {
+ .io_cap = 0x04,
+ .oob_data_flag = 0x00,
+ .authreq = 0x0d,
+ .max_enc_key_size = 0x10,
+ .init_key_dist = 0x07,
+ .resp_key_dist = 0x07,
+ },
+ .pair_rsp = {
+ .io_cap = 0x02,
+ .oob_data_flag = 0x00,
+ .authreq = 0x05,
+ .max_enc_key_size = 0x10,
+ .init_key_dist = 0x07,
+ .resp_key_dist = 0x05,
+ },
+ .confirm_req[0] = {
+ .value = {
+ 0xb5, 0xd4, 0xc5, 0xe8, 0xef, 0xef, 0xd8, 0xd7,
+ 0x2b, 0x14, 0x34, 0x35, 0x29, 0x18, 0xda, 0x12,
+ },
+ },
+ .confirm_rsp[0] = {
+ .value = {
+ 0x1a, 0x03, 0x20, 0xda, 0x60, 0x21, 0x9b, 0x4b,
+ 0x5d, 0x45, 0x90, 0x64, 0xe1, 0x24, 0x2c, 0xb6,
+ },
+ },
+ .random_req[0] = {
+ .value = {
+ 0x45, 0xa3, 0x1a, 0x0b, 0xf6, 0x0f, 0x7c, 0xcf,
+ 0x1a, 0xfb, 0xfc, 0x1a, 0xad, 0x62, 0x0e, 0x76,
+ },
+ },
+ .random_rsp[0] = {
+ .value = {
+ 0x82, 0xbb, 0x9f, 0x67, 0xc4, 0x88, 0xcb, 0x58,
+ 0xee, 0xf9, 0x34, 0x35, 0x23, 0xa3, 0xd0, 0x22,
+ },
+ },
+ .enc_info_req = {
+ .ltk = {
+ 0xfa, 0x43, 0x8f, 0x1f, 0xe6, 0x2a, 0x94, 0x5b,
+ 0x54, 0x89, 0x2b, 0x0f, 0xd7, 0x23, 0x77, 0x9e,
+ },
+ },
+ .master_id_req = {
+ .ediv = 0x88b3,
+ .rand_val = 0x7c970e18dec74560,
+ },
+ .sign_info_req = {
+ .sig_key = {
+ 0x2e, 0x70, 0x3c, 0xbf, 0x20, 0xbe, 0x7d, 0x2d,
+ 0xb3, 0x50, 0x46, 0x33, 0x4c, 0x20, 0x0e, 0xc8,
+ },
+ },
+ .enc_info_rsp = {
+ .ltk = {
+ 0xc1, 0x64, 0x33, 0x10, 0x0f, 0x70, 0x2f, 0x9c,
+ 0xe7, 0x31, 0xc5, 0x32, 0xdd, 0x98, 0x16, 0x75,
+ },
+ },
+ .master_id_rsp = {
+ .ediv = 0x1c19,
+ .rand_val = 0xef308872dc2a4cc2,
+ },
+ .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 = {
+ 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a,
+ },
+ },
+ .sign_info_rsp = {
+ .sig_key = {
+ 0xd7, 0x75, 0xfa, 0xed, 0xd7, 0xdd, 0x7b, 0xb3,
+ 0xa4, 0x20, 0xea, 0x2f, 0x75, 0x60, 0xb1, 0x84,
+ },
+ },
+ .stk = {
+ 0x9e, 0xe8, 0x35, 0x22, 0xb6, 0xbb, 0x54, 0x0d,
+ 0x48, 0x1b, 0x25, 0xa0, 0xd8, 0xe2, 0xa5, 0x08,
+ },
+ .pair_alg = 1,
+ .authenticated = true,
+ .passkey_info = {
+ .passkey = {
+ .action = BLE_SM_IOACT_DISP,
+ .passkey = 46128,
+ },
+ },
+ };
+ ble_sm_test_util_us_lgcy_good(¶ms);
+}
+
+/**
+ * Legacy pairing
+ * Master: us
+ * Pair algorithm: out of band
+ * Initiator IO capabilities: 3
+ * Responder IO capabilities: 3
+ * Bonding: true
+ * Initiator address type: BLE_ADDR_TYPE_PUBLIC
+ * Responder address type: BLE_ADDR_TYPE_PUBLIC
+ * Initiator key distribution: 7
+ * Responder key distribution: 7
+ */
+TEST_CASE(ble_sm_lgcy_us_ob_iio3_rio3_b1_iat0_rat0_ik7_rk7)
+{
+ struct ble_sm_test_params params;
+
+ params = (struct ble_sm_test_params) {
+ .init_id_addr = {
+ 0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
+ },
+ .resp_id_addr = {
+ 0x66, 0x33, 0x22, 0x66, 0x55, 0x11,
+ },
+ .pair_req = {
+ .io_cap = 0x03,
+ .oob_data_flag = 0x01,
+ .authreq = 0x05,
+ .max_enc_key_size = 0x10,
+ .init_key_dist = 0x07,
+ .resp_key_dist = 0x07,
+ },
+ .pair_rsp = {
+ .io_cap = 0x03,
+ .oob_data_flag = 0x01,
+ .authreq = 0x05,
+ .max_enc_key_size = 0x10,
+ .init_key_dist = 0x07,
+ .resp_key_dist = 0x07,
+ },
+ .confirm_req[0] = {
+ .value = {
+ 0x2c, 0x3f, 0x3e, 0xf5, 0x39, 0x50, 0x78, 0x4a,
+ 0x3e, 0x14, 0x1a, 0x51, 0xfb, 0x8d, 0x6c, 0x10,
+ },
+ },
+ .confirm_rsp[0] = {
+ .value = {
+ 0xa9, 0x5c, 0x18, 0xb1, 0xdb, 0x51, 0x53, 0xa5,
+ 0xd3, 0xe7, 0x72, 0x17, 0xfb, 0xa8, 0xfb, 0xeb,
+ },
+ },
+ .random_req[0] = {
+ .value = {
+ 0x40, 0x2f, 0x42, 0xba, 0x10, 0x7b, 0x22, 0x65,
+ 0x84, 0xef, 0x63, 0xdf, 0x84, 0x7b, 0x04, 0xef,
+ },
+ },
+ .random_rsp[0] = {
+ .value = {
+ 0x94, 0xdc, 0x3c, 0xef, 0x65, 0xf7, 0x99, 0x2e,
+ 0x50, 0x29, 0x97, 0x2a, 0x57, 0xfd, 0xe6, 0x6a,
+ },
+ },
+ .enc_info_req = {
+ .ltk = {
+ 0x8c, 0x8e, 0x57, 0xba, 0x17, 0xbb, 0x04, 0xb5,
+ 0x16, 0xad, 0x31, 0x37, 0xf8, 0x3e, 0x4f, 0x21,
+ },
+ },
+ .master_id_req = {
+ .ediv = 0xaaa4,
+ .rand_val = 0xc0c830e300000000,
+ },
+ .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 = {
+ 0x66, 0x33, 0x22, 0x66, 0x55, 0x11,
+ },
+ },
+ .sign_info_req = {
+ .sig_key = {
+ 0x5a, 0xe4, 0x2b, 0x40, 0x3a, 0x34, 0x1d, 0x94,
+ 0x56, 0x7d, 0xf4, 0x41, 0x23, 0x81, 0xc4, 0x11,
+ },
+ },
+ .enc_info_rsp = {
+ .ltk = {
+ 0xa6, 0x8e, 0xa0, 0xa4, 0x02, 0x64, 0x4c, 0x09,
+ 0x31, 0x25, 0x8a, 0x4f, 0x49, 0x35, 0xb0, 0x1f,
+ },
+ },
+ .master_id_rsp = {
+ .ediv = 0x57a3,
+ .rand_val = 0x8276af9000000000,
+ },
+ .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 = {
+ 0x8e, 0xef, 0x53, 0x5c, 0x1b, 0x21, 0x67, 0x8d,
+ 0x07, 0x5e, 0xaa, 0xe8, 0x41, 0xa9, 0x36, 0xcf,
+ },
+ },
+ .stk = {
+ 0x4c, 0xd4, 0xa7, 0xee, 0x83, 0xcd, 0xd1, 0x9e,
+ 0x84, 0xeb, 0xb8, 0xd2, 0xaf, 0x4a, 0x71, 0x2e,
+ },
+ .pair_alg = 2,
+ .authenticated = 1,
+ .passkey_info = {
+ .passkey = {
+ .action = BLE_SM_IOACT_OOB,
+ .oob = {
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
+ },
+ },
+ },
+ };
+ ble_sm_test_util_us_lgcy_good(¶ms);
+}
+
+TEST_SUITE(ble_sm_lgcy_test_suite)
+{
+ /*** No privacy. */
+
+ /* Peer as initiator. */
+ ble_sm_lgcy_peer_jw_iio4_rio3_b1_iat0_rat0_ik7_rk7();
+ ble_sm_lgcy_peer_pk_iio4_rio0_b1_iat0_rat0_ik7_rk7();
+
+ /* Us as initiator. */
+ ble_sm_lgcy_us_jw_iio3_rio3_b1_iat0_rat1_ik7_rk5();
+ ble_sm_lgcy_us_pk_iio4_rio2_b1_iat0_rat1_ik7_rk5();
+ ble_sm_lgcy_us_ob_iio3_rio3_b1_iat0_rat0_ik7_rk7();
+}
+
+#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/39dd36c8/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 a237510..4d60f0c 100644
--- a/net/nimble/host/src/test/ble_sm_sc_test.c
+++ b/net/nimble/host/src/test/ble_sm_sc_test.c
@@ -45,9 +45,9 @@
*/
TEST_CASE(ble_sm_sc_peer_jw_iio3_rio3_b1_iat0_rat0_ik5_rk7)
{
- struct ble_sm_test_sc_params params;
+ struct ble_sm_test_params params;
- params = (struct ble_sm_test_sc_params) {
+ params = (struct ble_sm_test_params) {
.init_id_addr = {
0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
},
@@ -187,9 +187,9 @@ TEST_CASE(ble_sm_sc_peer_jw_iio3_rio3_b1_iat0_rat0_ik5_rk7)
*/
TEST_CASE(ble_sm_sc_peer_pk_iio0_rio2_b1_iat0_rat0_ik5_rk7)
{
- struct ble_sm_test_sc_params params;
+ struct ble_sm_test_params params;
- params = (struct ble_sm_test_sc_params) {
+ params = (struct ble_sm_test_params) {
.init_id_addr = {
0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
},
@@ -792,9 +792,9 @@ TEST_CASE(ble_sm_sc_peer_pk_iio0_rio2_b1_iat0_rat0_ik5_rk7)
*/
TEST_CASE(ble_sm_sc_peer_pk_iio2_rio0_b1_iat0_rat0_ik5_rk7)
{
- struct ble_sm_test_sc_params params;
+ struct ble_sm_test_params params;
- params = (struct ble_sm_test_sc_params) {
+ params = (struct ble_sm_test_params) {
.init_id_addr = {
0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
},
@@ -1397,9 +1397,9 @@ TEST_CASE(ble_sm_sc_peer_pk_iio2_rio0_b1_iat0_rat0_ik5_rk7)
*/
TEST_CASE(ble_sm_sc_peer_nc_iio1_rio1_b1_iat0_rat0_ik5_rk7)
{
- struct ble_sm_test_sc_params params;
+ struct ble_sm_test_params params;
- params = (struct ble_sm_test_sc_params) {
+ params = (struct ble_sm_test_params) {
.init_id_addr = {
0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0,
},
@@ -1541,9 +1541,9 @@ TEST_CASE(ble_sm_sc_peer_nc_iio1_rio1_b1_iat0_rat0_ik5_rk7)
*/
TEST_CASE(ble_sm_sc_us_jw_iio3_rio4_b1_iat0_rat0_ik7_rk5)
{
- struct ble_sm_test_sc_params params;
+ struct ble_sm_test_params params;
- params = (struct ble_sm_test_sc_params) {
+ params = (struct ble_sm_test_params) {
.init_id_addr = {
0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
},
@@ -1683,9 +1683,9 @@ TEST_CASE(ble_sm_sc_us_jw_iio3_rio4_b1_iat0_rat0_ik7_rk5)
*/
TEST_CASE(ble_sm_sc_us_pk_iio2_rio4_b1_iat0_rat0_ik7_rk5)
{
- struct ble_sm_test_sc_params params;
+ struct ble_sm_test_params params;
- params = (struct ble_sm_test_sc_params) {
+ params = (struct ble_sm_test_params) {
.init_id_addr = {
0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
},
@@ -2288,9 +2288,9 @@ TEST_CASE(ble_sm_sc_us_pk_iio2_rio4_b1_iat0_rat0_ik7_rk5)
*/
TEST_CASE(ble_sm_sc_us_pk_iio0_rio4_b1_iat0_rat0_ik7_rk5)
{
- struct ble_sm_test_sc_params params;
+ struct ble_sm_test_params params;
- params = (struct ble_sm_test_sc_params) {
+ params = (struct ble_sm_test_params) {
.init_id_addr = {
0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
},
@@ -2893,9 +2893,9 @@ TEST_CASE(ble_sm_sc_us_pk_iio0_rio4_b1_iat0_rat0_ik7_rk5)
*/
TEST_CASE(ble_sm_sc_us_nc_iio1_rio4_b1_iat0_rat0_ik7_rk5)
{
- struct ble_sm_test_sc_params params;
+ struct ble_sm_test_params params;
- params = (struct ble_sm_test_sc_params) {
+ params = (struct ble_sm_test_params) {
.init_id_addr = {
0x01, 0x01, 0x01, 0x07, 0x08, 0x01,
},
@@ -3037,9 +3037,9 @@ TEST_CASE(ble_sm_sc_us_nc_iio1_rio4_b1_iat0_rat0_ik7_rk5)
*/
TEST_CASE(ble_sm_sc_peer_jw_iio3_rio3_b1_iat2_rat2_ik7_rk7)
{
- struct ble_sm_test_sc_params params;
+ struct ble_sm_test_params params;
- params = (struct ble_sm_test_sc_params) {
+ params = (struct ble_sm_test_params) {
.init_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT,
.init_id_addr = {
0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
@@ -3199,9 +3199,9 @@ TEST_CASE(ble_sm_sc_peer_jw_iio3_rio3_b1_iat2_rat2_ik7_rk7)
*/
TEST_CASE(ble_sm_sc_peer_nc_iio1_rio1_b1_iat2_rat2_ik3_rk3)
{
- struct ble_sm_test_sc_params params;
+ struct ble_sm_test_params params;
- params = (struct ble_sm_test_sc_params) {
+ params = (struct ble_sm_test_params) {
.init_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT,
.init_id_addr = {
0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
@@ -3351,9 +3351,9 @@ TEST_CASE(ble_sm_sc_peer_nc_iio1_rio1_b1_iat2_rat2_ik3_rk3)
*/
TEST_CASE(ble_sm_sc_peer_pk_iio2_rio0_b1_iat2_rat2_ik7_rk3)
{
- struct ble_sm_test_sc_params params;
+ struct ble_sm_test_params params;
- params = (struct ble_sm_test_sc_params) {
+ params = (struct ble_sm_test_params) {
.init_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT,
.init_id_addr = {
0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
@@ -3970,9 +3970,9 @@ TEST_CASE(ble_sm_sc_peer_pk_iio2_rio0_b1_iat2_rat2_ik7_rk3)
*/
TEST_CASE(ble_sm_sc_us_jw_iio3_rio3_b1_iat2_rat2_ik3_rk3)
{
- struct ble_sm_test_sc_params params;
+ struct ble_sm_test_params params;
- params = (struct ble_sm_test_sc_params) {
+ params = (struct ble_sm_test_params) {
.init_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT,
.init_id_addr = {
0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
@@ -4120,9 +4120,9 @@ TEST_CASE(ble_sm_sc_us_jw_iio3_rio3_b1_iat2_rat2_ik3_rk3)
*/
TEST_CASE(ble_sm_sc_us_nc_iio1_rio1_b1_iat2_rat2_ik3_rk3)
{
- struct ble_sm_test_sc_params params;
+ struct ble_sm_test_params params;
- params = (struct ble_sm_test_sc_params) {
+ params = (struct ble_sm_test_params) {
.init_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT,
.init_id_addr = {
0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
@@ -4272,9 +4272,9 @@ TEST_CASE(ble_sm_sc_us_nc_iio1_rio1_b1_iat2_rat2_ik3_rk3)
*/
TEST_CASE(ble_sm_sc_us_pk_iio2_rio0_b1_iat2_rat2_ik7_rk3)
{
- struct ble_sm_test_sc_params params;
+ struct ble_sm_test_params params;
- params = (struct ble_sm_test_sc_params) {
+ params = (struct ble_sm_test_params) {
.init_addr_type = BLE_ADDR_TYPE_RPA_PUB_DEFAULT,
.init_id_addr = {
0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
@@ -4907,15 +4907,3 @@ TEST_SUITE(ble_sm_sc_test_suite)
}
#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
-}
[5/9] incubator-mynewt-core git commit: BLE Host - Consider bonding
flag in rxed sec req.
Posted by cc...@apache.org.
BLE Host - Consider bonding flag in rxed sec req.
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/24c093c6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/24c093c6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/24c093c6
Branch: refs/heads/develop
Commit: 24c093c67e1e7d24f00efc261db3387c71566c55
Parents: 8b26f56
Author: Christopher Collins <cc...@apache.org>
Authored: Thu Jun 16 20:46:39 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Thu Jun 16 20:49:26 2016 -0700
----------------------------------------------------------------------
net/nimble/host/src/ble_sm.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/24c093c6/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 083a1ae..bd435a5 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -1624,7 +1624,6 @@ ble_sm_sec_req_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
BLE_SM_LOG_CMD(0, "sec req", conn_handle, ble_sm_sec_req_log, &cmd);
/* XXX: Reject if:
- * o authreq-bonded flag not set?
* o authreq-reserved flags set?
*/
@@ -1650,10 +1649,14 @@ ble_sm_sec_req_rx(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
ble_hs_unlock();
if (res->app_status == 0) {
- /* Query database for an LTK corresponding to the sender. We are the
- * master, so retrieve a master key.
+ /* If the peer is requesting a bonded connection, query database for an
+ * LTK corresponding to the sender.
*/
- res->app_status = ble_store_read_peer_sec(&key_sec, &value_sec);
+ if (cmd.authreq & BLE_SM_PAIR_AUTHREQ_BOND) {
+ res->app_status = ble_store_read_peer_sec(&key_sec, &value_sec);
+ } else {
+ res->app_status = BLE_HS_ENOENT;
+ }
if (res->app_status == 0) {
/* Found a key corresponding to this peer. Make sure it meets the
* requested minimum authreq.
[6/9] incubator-mynewt-core git commit: BLE Host - More SM unit tests.
Posted by cc...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/39dd36c8/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 9d95c92..3b0688b 100644
--- a/net/nimble/host/src/test/ble_sm_test_util.h
+++ b/net/nimble/host/src/test/ble_sm_test_util.h
@@ -26,48 +26,15 @@ struct ble_sm_test_passkey_info {
unsigned io_before_rx:1;
};
-struct ble_sm_test_lgcy_params {
+struct ble_sm_test_params {
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;
- 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_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;
@@ -75,25 +42,31 @@ struct ble_sm_test_sc_params {
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;
+ struct ble_sm_pair_fail pair_fail;
+
int pair_alg;
unsigned authenticated:1;
+
+ /*** Secure connections fields. */
uint8_t ltk[16];
uint8_t our_priv_key[32];
+ 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_test_passkey_info passkey_info;
- struct ble_sm_pair_fail pair_fail;
-
- unsigned has_sec_req:1;
+ /*** Legacy fields. */
+ uint8_t stk[16];
+ struct ble_sm_enc_info enc_info_req;
+ struct ble_sm_enc_info enc_info_rsp;
+ struct ble_sm_master_id master_id_req;
+ struct ble_sm_master_id master_id_rsp;
};
extern int ble_sm_test_gap_event;
@@ -121,7 +94,7 @@ 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_us_lgcy_good(struct ble_sm_test_params *params);
void ble_sm_test_util_peer_fail_inval(int we_are_master,
uint8_t *init_addr,
uint8_t *resp_addr,
@@ -138,10 +111,10 @@ void ble_sm_test_util_peer_lgcy_fail_confirm(
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_lgcy_good(struct ble_sm_test_params *params);
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_peer_sc_good(struct ble_sm_test_params *params);
+void ble_sm_test_util_us_sc_good(struct ble_sm_test_params *params);
+void ble_sm_test_util_us_fail_inval(struct ble_sm_test_params *params);
#endif