mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-26 12:35:25 +00:00
sm: wait for ec key before pairing
This commit is contained in:
parent
674e5b4ae9
commit
34b6528f7c
19
src/ble/sm.c
19
src/ble/sm.c
@ -146,6 +146,7 @@ typedef enum {
|
|||||||
} address_resolution_event_t;
|
} address_resolution_event_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
EC_KEY_GENERATION_IDLE,
|
||||||
EC_KEY_GENERATION_ACTIVE,
|
EC_KEY_GENERATION_ACTIVE,
|
||||||
EC_KEY_GENERATION_DONE,
|
EC_KEY_GENERATION_DONE,
|
||||||
} ec_key_generation_state_t;
|
} ec_key_generation_state_t;
|
||||||
@ -412,6 +413,7 @@ static void sm_handle_encryption_result_rau(void *arg);
|
|||||||
static void sm_handle_random_result_ph2_tk(void * arg);
|
static void sm_handle_random_result_ph2_tk(void * arg);
|
||||||
static void sm_handle_random_result_rau(void * arg);
|
static void sm_handle_random_result_rau(void * arg);
|
||||||
#ifdef ENABLE_LE_SECURE_CONNECTIONS
|
#ifdef ENABLE_LE_SECURE_CONNECTIONS
|
||||||
|
static void sm_ec_generate_new_key(void);
|
||||||
static void sm_handle_random_result_sc_get_random(void * arg);
|
static void sm_handle_random_result_sc_get_random(void * arg);
|
||||||
static int sm_passkey_entry(stk_generation_method_t method);
|
static int sm_passkey_entry(stk_generation_method_t method);
|
||||||
#endif
|
#endif
|
||||||
@ -1946,6 +1948,20 @@ static void sm_run(void){
|
|||||||
int done = 1;
|
int done = 1;
|
||||||
int err;
|
int err;
|
||||||
UNUSED(err);
|
UNUSED(err);
|
||||||
|
|
||||||
|
#ifdef ENABLE_LE_SECURE_CONNECTIONS
|
||||||
|
// assert ec key is ready
|
||||||
|
if (sm_connection->sm_engine_state == SM_RESPONDER_PH1_PAIRING_REQUEST_RECEIVED
|
||||||
|
|| sm_connection->sm_engine_state == SM_INITIATOR_PH1_W2_SEND_PAIRING_REQUEST){
|
||||||
|
if (ec_key_generation_state == EC_KEY_GENERATION_IDLE){
|
||||||
|
sm_ec_generate_new_key();
|
||||||
|
}
|
||||||
|
if (ec_key_generation_state != EC_KEY_GENERATION_DONE){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
switch (sm_connection->sm_engine_state) {
|
switch (sm_connection->sm_engine_state) {
|
||||||
#ifdef ENABLE_LE_PERIPHERAL
|
#ifdef ENABLE_LE_PERIPHERAL
|
||||||
case SM_RESPONDER_SEND_SECURITY_REQUEST:
|
case SM_RESPONDER_SEND_SECURITY_REQUEST:
|
||||||
@ -3687,8 +3703,11 @@ void sm_test_use_fixed_local_csrk(void){
|
|||||||
static void sm_ec_generated(void * arg){
|
static void sm_ec_generated(void * arg){
|
||||||
UNUSED(arg);
|
UNUSED(arg);
|
||||||
ec_key_generation_state = EC_KEY_GENERATION_DONE;
|
ec_key_generation_state = EC_KEY_GENERATION_DONE;
|
||||||
|
// trigger pairing if pending for ec key
|
||||||
|
sm_run();
|
||||||
}
|
}
|
||||||
static void sm_ec_generate_new_key(void){
|
static void sm_ec_generate_new_key(void){
|
||||||
|
log_info("sm: generate new ec key");
|
||||||
ec_key_generation_state = EC_KEY_GENERATION_ACTIVE;
|
ec_key_generation_state = EC_KEY_GENERATION_ACTIVE;
|
||||||
btstack_crypto_ecc_p256_generate_key(&sm_crypto_ecc_p256_request, ec_q, &sm_ec_generated, NULL);
|
btstack_crypto_ecc_p256_generate_key(&sm_crypto_ecc_p256_request, ec_q, &sm_ec_generated, NULL);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user