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/05 11:52:13 UTC
[26/43] incubator-mynewt-core git commit: BLE Host - SC numeric
comparison.
BLE Host - SC numeric comparison.
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/f84a1127
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/f84a1127
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/f84a1127
Branch: refs/heads/develop
Commit: f84a1127bfb59edadfa8f18dcf9efe605d999f05
Parents: 133e060
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Jun 1 18:19:50 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Sun Jun 5 19:15:54 2016 +0800
----------------------------------------------------------------------
apps/bletiny/src/cmd.c | 25 ++-
apps/bletiny/src/main.c | 8 +-
net/nimble/host/src/ble_sm.c | 29 ++--
net/nimble/host/src/ble_sm_alg.c | 2 +-
net/nimble/host/src/ble_sm_priv.h | 4 +-
net/nimble/host/src/ble_sm_sc.c | 27 ++-
net/nimble/host/src/test/ble_sm_test.c | 253 +++++++++++++++++++++++++---
7 files changed, 296 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f84a1127/apps/bletiny/src/cmd.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c
index 8d8b8c9..213e150 100644
--- a/apps/bletiny/src/cmd.c
+++ b/apps/bletiny/src/cmd.c
@@ -1936,6 +1936,7 @@ cmd_passkey(int argc, char **argv)
uint16_t conn_handle;
struct ble_sm_passkey pk;
+ char *yesno;
int rc;
conn_handle = parse_arg_uint16("conn", &rc);
@@ -1948,7 +1949,7 @@ cmd_passkey(int argc, char **argv)
return rc;
}
- switch(pk.action) {
+ switch (pk.action) {
case BLE_SM_PKACT_INPUT:
case BLE_SM_PKACT_DISP:
/* passkey is 6 digit number */
@@ -1964,6 +1965,28 @@ cmd_passkey(int argc, char **argv)
return rc;
}
break;
+
+ case BLE_SM_PKACT_NUMCMP:
+ yesno = parse_arg_find("yesno");
+ if (yesno == NULL) {
+ return EINVAL;
+ }
+
+ switch (yesno[0]) {
+ case 'y':
+ case 'Y':
+ pk.numcmp_accept = 1;
+ break;
+ case 'n':
+ case 'N':
+ pk.numcmp_accept = 0;
+ break;
+
+ default:
+ return EINVAL;
+ }
+ break;
+
default:
console_printf("invalid passkey action action=%d\n", pk.action);
return EINVAL;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f84a1127/apps/bletiny/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c
index c7752bd..bc0736c 100755
--- a/apps/bletiny/src/main.c
+++ b/apps/bletiny/src/main.c
@@ -43,6 +43,7 @@
#include "host/ble_gap.h"
#include "host/ble_gatt.h"
#include "host/ble_store.h"
+#include "host/ble_sm.h"
#include "controller/ble_ll.h"
/* XXX: An app should not include private headers from a library. The bletiny
@@ -854,8 +855,13 @@ bletiny_gap_event(int event, struct ble_gap_conn_ctxt *ctxt, void *arg)
return 0;
case BLE_GAP_EVENT_PASSKEY_ACTION:
- console_printf("passkey action event; action=%d\n",
+ console_printf("passkey action event; action=%d",
ctxt->passkey_action.action);
+ if (ctxt->passkey_action.action == BLE_SM_PKACT_NUMCMP) {
+ console_printf(" numcmp=%lu",
+ (unsigned long)ctxt->passkey_action.numcmp);
+ }
+ console_printf("\n");
return 0;
case BLE_GAP_EVENT_ENC_CHANGE:
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f84a1127/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 e235a18..27d75e3 100644
--- a/net/nimble/host/src/ble_sm.c
+++ b/net/nimble/host/src/ble_sm.c
@@ -1276,7 +1276,7 @@ ble_sm_rx_pair_confirm(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
struct ble_sm_pair_confirm cmd;
struct ble_sm_proc *proc;
struct ble_sm_proc *prev;
- uint8_t passkey_action;
+ uint8_t pkact;
res->app_status = ble_hs_misc_pullup_base(om, BLE_SM_PAIR_CONFIRM_SZ);
if (res->app_status != 0) {
@@ -1301,11 +1301,12 @@ ble_sm_rx_pair_confirm(uint16_t conn_handle, uint8_t op, struct os_mbuf **om,
proc->state = BLE_SM_PROC_STATE_RANDOM;
res->execute = 1;
} else {
- proc->flags |= BLE_SM_PROC_F_RX_CONFIRM;
-
- passkey_action = ble_sm_passkey_action(proc);
- if (passkey_action == BLE_SM_PKACT_NONE ||
- proc->flags & BLE_SM_PROC_F_TK_VALID) {
+ pkact = ble_sm_passkey_action(proc);
+ if (ble_sm_pkact_state(pkact) == proc->state) {
+ proc->flags |= BLE_SM_PROC_F_ADVANCE_ON_IO;
+ }
+ if (pkact == BLE_SM_PKACT_NONE ||
+ proc->flags & BLE_SM_PROC_F_IO_INJECTED) {
res->execute = 1;
}
@@ -2195,7 +2196,7 @@ ble_sm_set_tk(uint16_t conn_handle, struct ble_sm_passkey *pkey)
if (proc == NULL) {
res.app_status = BLE_HS_ENOENT;
- } else if (proc->flags & BLE_SM_PROC_F_TK_VALID) {
+ } else if (proc->flags & BLE_SM_PROC_F_IO_INJECTED) {
res.app_status = BLE_HS_EALREADY;
} else if (pkey->action != ble_sm_passkey_action(proc)) {
/* Response doesn't match what we asked for. */
@@ -2213,10 +2214,10 @@ ble_sm_set_tk(uint16_t conn_handle, struct ble_sm_passkey *pkey)
res.app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_OOB);
res.sm_err = BLE_SM_ERR_OOB;
} else {
- proc->flags |= BLE_SM_PROC_F_TK_VALID;
+ proc->flags |= BLE_SM_PROC_F_IO_INJECTED;
memcpy(proc->tk, pkey->oob, 16);
if ((proc->flags & BLE_SM_PROC_F_INITIATOR) ||
- (proc->flags & BLE_SM_PROC_F_RX_CONFIRM)) {
+ (proc->flags & BLE_SM_PROC_F_ADVANCE_ON_IO)) {
res.execute = 1;
}
@@ -2229,14 +2230,14 @@ ble_sm_set_tk(uint16_t conn_handle, struct ble_sm_passkey *pkey)
res.app_status = BLE_HS_EINVAL;
res.sm_err = BLE_SM_ERR_PASSKEY;
} else {
- proc->flags |= BLE_SM_PROC_F_TK_VALID;
+ proc->flags |= BLE_SM_PROC_F_IO_INJECTED;
memset(proc->tk, 0, 16);
proc->tk[0] = (pkey->passkey >> 0) & 0xff;
proc->tk[1] = (pkey->passkey >> 8) & 0xff;
proc->tk[2] = (pkey->passkey >> 16) & 0xff;
proc->tk[3] = (pkey->passkey >> 24) & 0xff;
if ((proc->flags & BLE_SM_PROC_F_INITIATOR) ||
- (proc->flags & BLE_SM_PROC_F_RX_CONFIRM)) {
+ (proc->flags & BLE_SM_PROC_F_ADVANCE_ON_IO)) {
res.execute = 1;
}
@@ -2248,8 +2249,10 @@ ble_sm_set_tk(uint16_t conn_handle, struct ble_sm_passkey *pkey)
res.app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_NUMCMP);
res.sm_err = BLE_SM_ERR_NUMCMP;
} else {
- proc->flags |= BLE_SM_PROC_F_TK_VALID;
- if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
+ proc->flags |= BLE_SM_PROC_F_IO_INJECTED;
+ if (proc->flags & BLE_SM_PROC_F_INITIATOR ||
+ proc->flags & BLE_SM_PROC_F_ADVANCE_ON_IO) {
+
res.execute = 1;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f84a1127/net/nimble/host/src/ble_sm_alg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_alg.c b/net/nimble/host/src/ble_sm_alg.c
index 53da486..6c322d4 100644
--- a/net/nimble/host/src/ble_sm_alg.c
+++ b/net/nimble/host/src/ble_sm_alg.c
@@ -432,7 +432,7 @@ ble_sm_alg_g2(uint8_t *u, uint8_t *v, uint8_t *x, uint8_t *y, uint32_t *passkey)
ble_sm_alg_log_buf("res", xs, 16);
*passkey = be32toh(xs + 12) % 1000000;
- BLE_HS_LOG(DEBUG, " passkey=%u", *passkey);
+ BLE_HS_LOG(DEBUG, " passkey=%u\n", *passkey);
return 0;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f84a1127/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 6e44e0d..28ef0d6 100644
--- a/net/nimble/host/src/ble_sm_priv.h
+++ b/net/nimble/host/src/ble_sm_priv.h
@@ -214,8 +214,8 @@ struct ble_sm_dhkey_check {
#define BLE_SM_PROC_STATE_CNT 11
#define BLE_SM_PROC_F_INITIATOR 0x01
-#define BLE_SM_PROC_F_TK_VALID 0x02
-#define BLE_SM_PROC_F_RX_CONFIRM 0x04
+#define BLE_SM_PROC_F_IO_INJECTED 0x02
+#define BLE_SM_PROC_F_ADVANCE_ON_IO 0x04
#define BLE_SM_PROC_F_AUTHENTICATED 0x08
#define BLE_SM_PROC_F_KEY_EXCHANGE 0x10
#define BLE_SM_PROC_F_BONDED 0x20
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f84a1127/net/nimble/host/src/ble_sm_sc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_sm_sc.c b/net/nimble/host/src/ble_sm_sc.c
index ce69760..7cf96f5 100644
--- a/net/nimble/host/src/ble_sm_sc.c
+++ b/net/nimble/host/src/ble_sm_sc.c
@@ -40,7 +40,7 @@ static uint8_t ble_sm_sc_keys_generated;
/* This is the initiator passkey action action dpeneding on the io
* capabilties of both parties
*/
-static const uint8_t ble_sm_lgcy_init_pka[5 /*resp*/ ][5 /*init */] =
+static const uint8_t ble_sm_sc_init_pka[5 /*resp*/ ][5 /*init */] =
{
{PKACT_NONE, PKACT_NONE, PKACT_INPUT, PKACT_NONE, PKACT_INPUT},
{PKACT_NONE, PKACT_NUMCMP, PKACT_INPUT, PKACT_NONE, PKACT_INPUT},
@@ -52,7 +52,7 @@ static const uint8_t ble_sm_lgcy_init_pka[5 /*resp*/ ][5 /*init */] =
/* This is the responder passkey action action depending on the io
* capabilities of both parties
*/
-static const uint8_t ble_sm_lgcy_resp_pka[5 /*init*/ ][5 /*resp */] =
+static const uint8_t ble_sm_sc_resp_pka[5 /*init*/ ][5 /*resp */] =
{
{PKACT_NONE, PKACT_NONE, PKACT_DISP, PKACT_NONE, PKACT_DISP},
{PKACT_NONE, PKACT_NUMCMP, PKACT_DISP, PKACT_NONE, PKACT_NUMCMP},
@@ -73,11 +73,11 @@ ble_sm_sc_passkey_action(struct ble_sm_proc *proc)
action = BLE_SM_PKACT_NONE;
} else if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
- action = ble_sm_lgcy_init_pka[proc->pair_rsp.io_cap]
- [proc->pair_req.io_cap];
+ action = ble_sm_sc_init_pka[proc->pair_rsp.io_cap]
+ [proc->pair_req.io_cap];
} else {
- action = ble_sm_lgcy_resp_pka[proc->pair_rsp.io_cap]
- [proc->pair_req.io_cap];
+ action = ble_sm_sc_resp_pka[proc->pair_rsp.io_cap]
+ [proc->pair_req.io_cap];
}
switch (action) {
@@ -453,6 +453,7 @@ ble_sm_dhkey_check_handle(struct ble_sm_proc *proc,
uint8_t iocap[3];
uint8_t *peer_addr;
uint8_t peer_addr_type;
+ uint8_t pkact;
uint8_t zeros[16] = { 0 };
@@ -493,11 +494,19 @@ ble_sm_dhkey_check_handle(struct ble_sm_proc *proc,
return;
}
- if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
- proc->state = BLE_SM_PROC_STATE_ENC_START;
+
+ pkact = ble_sm_sc_passkey_action(proc);
+ if (ble_sm_pkact_state(pkact) == proc->state) {
+ proc->flags |= BLE_SM_PROC_F_ADVANCE_ON_IO;
}
- res->execute = 1;
+ if (pkact == BLE_SM_PKACT_NONE || proc->flags & BLE_SM_PROC_F_IO_INJECTED) {
+ if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
+ proc->state = BLE_SM_PROC_STATE_ENC_START;
+ }
+
+ res->execute = 1;
+ }
}
void
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f84a1127/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 a88ed23..78b46cf 100644
--- a/net/nimble/host/src/test/ble_sm_test.c
+++ b/net/nimble/host/src/test/ble_sm_test.c
@@ -45,6 +45,12 @@ static ble_store_write_fn ble_sm_test_util_store_write;
* $util *
*****************************************************************************/
+struct ble_sm_test_passkey_info {
+ struct ble_sm_passkey passkey;
+ uint32_t exp_numcmp;
+ unsigned io_before_rx:1;
+};
+
struct ble_sm_test_lgcy_params {
uint8_t init_addr[6];
uint8_t rsp_addr[6];
@@ -66,7 +72,7 @@ struct ble_sm_test_lgcy_params {
uint64_t r;
uint16_t ediv;
- struct ble_sm_passkey passkey;
+ struct ble_sm_test_passkey_info passkey_info;
struct ble_sm_pair_fail pair_fail;
unsigned has_sec_req:1;
@@ -95,6 +101,7 @@ struct ble_sm_test_sc_params {
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;
@@ -143,8 +150,7 @@ ble_sm_test_util_init(void)
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);
+ memset(&ble_sm_test_sec_state, 0xff, sizeof ble_sm_test_sec_state);
}
struct ble_sm_test_ltk_info {
@@ -152,11 +158,11 @@ struct ble_sm_test_ltk_info {
unsigned authenticated:1;
};
+struct ble_gap_passkey_action ble_sm_test_pkact;
+
static int
-ble_sm_test_util_conn_cb(int event, struct ble_gap_conn_ctxt *ctxt,
- void *arg)
+ble_sm_test_util_conn_cb(int event, struct ble_gap_conn_ctxt *ctxt, void *arg)
{
- struct ble_sm_passkey *passkey;
int rc;
switch (event) {
@@ -167,10 +173,7 @@ ble_sm_test_util_conn_cb(int event, struct ble_gap_conn_ctxt *ctxt,
break;
case BLE_GAP_EVENT_PASSKEY_ACTION:
- passkey = arg;
- TEST_ASSERT_FATAL(passkey != NULL);
-
- rc = ble_sm_set_tk(ctxt->desc->conn_handle, passkey);
+ ble_sm_test_pkact = ctxt->passkey_action;
break;
default:
@@ -604,9 +607,9 @@ ble_sm_test_util_rx_enc_change(uint16_t conn_handle, uint8_t status,
static void
ble_sm_test_util_verify_tx_start_enc(uint16_t conn_handle,
- uint64_t random_number,
- uint16_t ediv,
- uint8_t *ltk)
+ uint64_t random_number,
+ uint16_t ediv,
+ uint8_t *ltk)
{
uint8_t param_len;
uint8_t *param;
@@ -621,6 +624,58 @@ ble_sm_test_util_verify_tx_start_enc(uint16_t conn_handle,
TEST_ASSERT(memcmp(param + 12, ltk, 16) == 0);
}
+static void
+ble_sm_test_util_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_pkact_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_PKACT_NUMCMP) {
+ TEST_ASSERT(ble_sm_test_pkact.numcmp == passkey_info->exp_numcmp);
+ }
+
+ rc = ble_sm_set_tk(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_pkact_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_PKACT_NUMCMP) {
+ TEST_ASSERT(ble_sm_test_pkact.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_set_tk(2, &passkey_info->passkey);
+ TEST_ASSERT_FATAL(rc == 0);
+}
+
/*****************************************************************************
* $peer *
*****************************************************************************/
@@ -977,8 +1032,7 @@ TEST_CASE(ble_sm_test_case_peer_lgcy_fail_confirm)
}
static void
-ble_sm_test_util_peer_lgcy_good(
- struct ble_sm_test_lgcy_params *params)
+ble_sm_test_util_peer_lgcy_good_once(struct ble_sm_test_lgcy_params *params)
{
struct ble_hs_conn *conn;
int rc;
@@ -1008,7 +1062,7 @@ ble_sm_test_util_peer_lgcy_good(
ble_hs_test_util_create_conn(2, params->init_addr,
ble_sm_test_util_conn_cb,
- ¶ms->passkey);
+ NULL);
/* This test inspects and modifies the connection object without locking
* the host mutex. It is not OK for real code to do this, but this test
@@ -1044,11 +1098,17 @@ ble_sm_test_util_peer_lgcy_good(
TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+ 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.enc_enabled);
TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+ 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);
@@ -1104,6 +1164,16 @@ ble_sm_test_util_peer_lgcy_good(
conn->bhc_sec_state.authenticated);
}
+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);
+}
+
TEST_CASE(ble_sm_test_case_peer_lgcy_jw_good)
{
struct ble_sm_test_lgcy_params params;
@@ -1223,10 +1293,13 @@ TEST_CASE(ble_sm_test_case_peer_lgcy_passkey_good)
.r = 4107344270811490869,
.ediv = 61621,
- .passkey = {
- .action = BLE_SM_PKACT_INPUT,
- .passkey = 884570,
+ .passkey_info = {
+ .passkey = {
+ .action = BLE_SM_PKACT_INPUT,
+ .passkey = 884570,
+ },
},
+
.enc_info_req = {
.ltk = {
0x2b, 0x9c, 0x1e, 0x42, 0xa8, 0xcb, 0xab, 0xd1,
@@ -2009,8 +2082,8 @@ TEST_CASE(ble_sm_test_case_peer_sec_req_pair)
*/
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)
+ int authenticated, uint16_t ediv,
+ uint64_t rand_num)
{
struct ble_sm_sec_req sec_req;
struct ble_store_value_sec value_sec;
@@ -2169,9 +2242,12 @@ TEST_CASE(ble_sm_test_case_us_sec_req_pair)
.r = 4107344270811490869,
.ediv = 61621,
- .passkey = {
- .action = BLE_SM_PKACT_INPUT,
- .passkey = 884570,
+ .passkey_info = {
+ .passkey = {
+ .action = BLE_SM_PKACT_INPUT,
+ .passkey = 884570,
+ },
+ .io_before_rx = 1,
},
.enc_info_req = {
@@ -2199,6 +2275,7 @@ TEST_CASE(ble_sm_test_case_us_sec_req_pair)
},
.has_master_id_rsp = 1,
};
+
ble_sm_test_util_peer_lgcy_good(¶ms);
}
@@ -2218,7 +2295,7 @@ TEST_CASE(ble_sm_test_case_us_sec_req_enc)
}
static void
-ble_sm_test_util_peer_sc_good(struct ble_sm_test_sc_params *params)
+ble_sm_test_util_peer_sc_good_once(struct ble_sm_test_sc_params *params)
{
struct ble_hs_conn *conn;
int rc;
@@ -2315,11 +2392,17 @@ ble_sm_test_util_peer_sc_good(struct ble_sm_test_sc_params *params)
TEST_ASSERT(!conn->bhc_sec_state.enc_enabled);
TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+ 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.enc_enabled);
TEST_ASSERT(ble_sm_dbg_num_procs() == 1);
+ 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);
@@ -2360,6 +2443,16 @@ ble_sm_test_util_peer_sc_good(struct ble_sm_test_sc_params *params)
conn->bhc_sec_state.authenticated);
}
+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);
+}
+
TEST_CASE(ble_sm_test_case_peer_sc_jw_good)
{
struct ble_sm_test_sc_params params;
@@ -2457,6 +2550,115 @@ TEST_CASE(ble_sm_test_case_peer_sc_jw_good)
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;
+
+ params = (struct ble_sm_test_sc_params) {
+ .init_addr = { 0xca, 0x61, 0xa0, 0x67, 0x94, 0xe0 },
+ .rsp_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 = 0x0d,
+ .resp_key_dist = 0x0f,
+ },
+ .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 = {
+ 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,
+ },
+ },
+ .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,
+ },
+
+ .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,
+ },
+ },
+ .confirm_rsp = (struct ble_sm_pair_confirm) {
+ .value = {
+ 0x7c, 0x45, 0xb0, 0x55, 0xce, 0x22, 0x61, 0x57,
+ 0x68, 0x2f, 0x2d, 0x3a, 0xce, 0xf5, 0x80, 0xba,
+ },
+ },
+ .random_req = (struct ble_sm_pair_random) {
+ .value = {
+ 0x4e, 0xfb, 0x89, 0x84, 0xfd, 0xa1, 0xed, 0x65,
+ 0x0e, 0x57, 0x11, 0xe6, 0x94, 0xd5, 0x18, 0x78,
+ },
+ },
+ .random_rsp = (struct ble_sm_pair_random) {
+ .value = {
+ 0x29, 0x06, 0xbc, 0x65, 0x1d, 0xe0, 0x95, 0xde,
+ 0x79, 0xee, 0xd9, 0x41, 0x86, 0x6f, 0x35, 0x75,
+ },
+ },
+ .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,
+ }
+ },
+ .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_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,
+ },
+ .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,
+ },
+
+ .passkey_info = {
+ .passkey = {
+ .action = BLE_SM_PKACT_NUMCMP,
+ .numcmp_accept = 1,
+ },
+
+ .exp_numcmp = 476091,
+ .io_before_rx = 0,
+ },
+ };
+ ble_sm_test_util_peer_sc_good(¶ms);
+}
+
TEST_CASE(ble_sm_test_case_f4)
{
uint8_t u[32] = { 0xe6, 0x9d, 0x35, 0x0e, 0x48, 0x01, 0x03, 0xcc,
@@ -2580,6 +2782,7 @@ TEST_SUITE(ble_sm_test_suite)
ble_sm_test_case_us_sec_req_pair();
ble_sm_test_case_us_sec_req_enc();
ble_sm_test_case_peer_sc_jw_good();
+ ble_sm_test_case_peer_sc_numcmp_good();
}
#endif