diff --git a/nimble/host/test/src/ble_sm_test.c b/nimble/host/test/src/ble_sm_test.c index 7a2994be7..dcdbaf01e 100644 --- a/nimble/host/test/src/ble_sm_test.c +++ b/nimble/host/test/src/ble_sm_test.c @@ -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 * *****************************************************************************/ @@ -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 diff --git a/nimble/host/test/src/ble_sm_test_util.c b/nimble/host/test/src/ble_sm_test_util.c index e3becdf86..74d40e8b5 100644 --- a/nimble/host/test/src/ble_sm_test_util.c +++ b/nimble/host/test/src/ble_sm_test_util.c @@ -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) { diff --git a/nimble/host/test/src/ble_sm_test_util.h b/nimble/host/test/src/ble_sm_test_util.h index d9aa3805c..3ddc86c1f 100644 --- a/nimble/host/test/src/ble_sm_test_util.h +++ b/nimble/host/test/src/ble_sm_test_util.h @@ -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,