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