Skip to content

Commit

Permalink
host: tests: add SM test case
Browse files Browse the repository at this point in the history
This covers the case where security request sent from peer should be rejected
after pairing response was received.
Move ble_sm_test_util_rx_pair_rsp() declaration.
  • Loading branch information
piotrnarajowski authored and sjanc committed Sep 2, 2024
1 parent 2ed13eb commit baf2930
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
31 changes: 31 additions & 0 deletions nimble/host/test/src/ble_sm_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,36 @@ TEST_CASE_SELF(ble_sm_test_case_peer_sec_req_inval)
ble_hs_test_util_assert_mbufs_freed(NULL);
}

TEST_CASE_SELF(ble_sm_test_case_peer_sec_req_reject)
{
struct ble_sm_sec_req sec_req;
int rc;

struct ble_sm_pair_cmd pair_rsp = {0x04, 0, 0x0D, 10, 0x02, 0x02};

ble_sm_test_util_init();

ble_sm_dbg_set_next_pair_rand(((uint8_t[16]) {0}));

ble_hs_test_util_create_conn(2, ((uint8_t[6]) {1,2,3,5,6,7}),
ble_sm_test_util_conn_cb,
NULL);

/*** Pairing already in progress; reject security request after pairing
* response was received. */

ble_hs_atomic_conn_set_flags(2, BLE_HS_CONN_F_MASTER, 1);
rc = ble_sm_pair_initiate(2);
TEST_ASSERT_FATAL(rc == 0);
ble_hs_test_util_prev_tx_queue_clear();

ble_sm_test_util_rx_pair_rsp(2, &pair_rsp, 0);
ble_sm_test_util_rx_sec_req(2, &sec_req, BLE_HS_EALREADY);
TEST_ASSERT(ble_hs_test_util_prev_tx_queue_sz() != 0);

ble_hs_test_util_assert_mbufs_freed(NULL);
}

/*****************************************************************************
* $us *
*****************************************************************************/
Expand Down Expand Up @@ -509,5 +539,6 @@ TEST_SUITE(ble_sm_gen_test_suite)
ble_sm_test_case_peer_bonding_bad();
ble_sm_test_case_conn_broken();
ble_sm_test_case_peer_sec_req_inval();
ble_sm_test_case_peer_sec_req_reject();
}
#endif
2 changes: 1 addition & 1 deletion nimble/host/test/src/ble_sm_test_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ ble_sm_test_util_rx_pair_req(uint16_t conn_handle,
req, rx_status);
}

static void
void
ble_sm_test_util_rx_pair_rsp(uint16_t conn_handle, struct ble_sm_pair_cmd *rsp,
int rx_status)
{
Expand Down
3 changes: 3 additions & 0 deletions nimble/host/test/src/ble_sm_test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ void ble_sm_test_util_io_check_post(
void ble_sm_test_util_rx_sec_req(uint16_t conn_handle,
struct ble_sm_sec_req *cmd,
int exp_status);
void ble_sm_test_util_rx_pair_rsp(uint16_t conn_handle,
struct ble_sm_pair_cmd *rsp,
int rx_status);
void ble_sm_test_util_verify_tx_pair_fail(struct ble_sm_pair_fail *exp_cmd);
void ble_sm_test_util_us_lgcy_good(struct ble_sm_test_params *params);
void ble_sm_test_util_peer_fail_inval(int we_are_master,
Expand Down

0 comments on commit baf2930

Please sign in to comment.