From 09222c1170ca6b0f41d658acf46cb861a273d97d Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Sat, 10 Oct 2015 22:04:39 +0200 Subject: [PATCH] allow to fix local csrk for testing --- ble/sm.c | 13 +++++++++++++ ble/sm.h | 3 +++ test/pts/ble_central_test.c | 1 + 3 files changed, 17 insertions(+) diff --git a/ble/sm.c b/ble/sm.c index 63cd2eefe..f91ee303f 100644 --- a/ble/sm.c +++ b/ble/sm.c @@ -117,6 +117,8 @@ typedef enum { // GLOBAL DATA // +static uint8_t test_use_fixed_local_csrk; + // configuration static uint8_t sm_accepted_stk_generation_methods; static uint8_t sm_max_encryption_key_size; @@ -1505,6 +1507,11 @@ static void sm_run(void){ if (setup->sm_key_distribution_send_set & SM_KEYDIST_FLAG_SIGNING_IDENTIFICATION){ setup->sm_key_distribution_send_set &= ~SM_KEYDIST_FLAG_SIGNING_IDENTIFICATION; + // hack to reproduce test runs + if (test_use_fixed_local_csrk){ + memset(setup->sm_local_csrk, 0xcc, 16); + } + uint8_t buffer[17]; buffer[0] = SM_CODE_SIGNING_INFORMATION; log_info("sm: store local CSRK"); @@ -2280,6 +2287,10 @@ void sm_test_set_irk(sm_key_t irk){ sm_persistent_irk_ready = 1; } +void sm_test_use_fixed_local_csrk(void){ + test_use_fixed_local_csrk = 1; +} + void sm_init(void){ // set some (BTstack default) ER and IR int i; @@ -2311,6 +2322,8 @@ void sm_init(void){ sm_active_connection = 0; + test_use_fixed_local_csrk = 0; + // attach to lower layers l2cap_register_fixed_channel(sm_packet_handler, L2CAP_CID_SECURITY_MANAGER_PROTOCOL); } diff --git a/ble/sm.h b/ble/sm.h index 0e45c2fd5..b603be8ed 100644 --- a/ble/sm.h +++ b/ble/sm.h @@ -279,6 +279,9 @@ int sm_address_resolution_lookup(uint8_t addr_type, bd_addr_t addr); int sm_le_device_index(uint16_t handle ); /* API_END */ +// testing only +void sm_test_use_fixed_local_csrk(void); + #if defined __cplusplus } #endif diff --git a/test/pts/ble_central_test.c b/test/pts/ble_central_test.c index 2a88a737f..68230b5f9 100644 --- a/test/pts/ble_central_test.c +++ b/test/pts/ble_central_test.c @@ -1494,6 +1494,7 @@ int btstack_main(int argc, const char * argv[]){ sm_set_encryption_key_size_range(sm_min_key_size, 16); sm_test_set_irk(test_irk); + sm_test_use_fixed_local_csrk(); // setup GATT Client gatt_client_init();