mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-02 16:20:31 +00:00
sm: fix sending of negative ltk reply
This commit is contained in:
parent
ff964d8e0b
commit
41d322973c
41
src/ble/sm.c
41
src/ble/sm.c
@ -1908,6 +1908,21 @@ static void sm_run(void){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle basic actions that don't requires the full context
|
||||||
|
hci_connections_get_iterator(&it);
|
||||||
|
while(!sm_active_connection && btstack_linked_list_iterator_has_next(&it)){
|
||||||
|
hci_connection_t * hci_connection = (hci_connection_t *) btstack_linked_list_iterator_next(&it);
|
||||||
|
sm_connection_t * sm_connection = &hci_connection->sm_connection;
|
||||||
|
switch(sm_connection->sm_engine_state){
|
||||||
|
// responder side
|
||||||
|
case SM_RESPONDER_PH0_SEND_LTK_REQUESTED_NEGATIVE_REPLY:
|
||||||
|
sm_connection->sm_engine_state = SM_RESPONDER_IDLE;
|
||||||
|
hci_send_cmd(&hci_le_long_term_key_negative_reply, sm_connection->sm_handle);
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// active connection handling
|
// active connection handling
|
||||||
@ -1976,6 +1991,7 @@ static void sm_run(void){
|
|||||||
switch (sm_connection->sm_irk_lookup_state){
|
switch (sm_connection->sm_irk_lookup_state){
|
||||||
case IRK_LOOKUP_SUCCEEDED:
|
case IRK_LOOKUP_SUCCEEDED:
|
||||||
// assuming Secure Connection, we have a stored LTK and the EDIV/RAND are null
|
// assuming Secure Connection, we have a stored LTK and the EDIV/RAND are null
|
||||||
|
// start using context by loading security info
|
||||||
sm_reset_setup();
|
sm_reset_setup();
|
||||||
sm_load_security_info(sm_connection);
|
sm_load_security_info(sm_connection);
|
||||||
if (setup->sm_peer_ediv == 0 && sm_is_null_random(setup->sm_peer_rand) && !sm_is_null_key(setup->sm_peer_ltk)){
|
if (setup->sm_peer_ediv == 0 && sm_is_null_random(setup->sm_peer_rand) && !sm_is_null_key(setup->sm_peer_ltk)){
|
||||||
@ -1984,15 +2000,11 @@ static void sm_run(void){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
log_info("LTK Request: ediv & random are empty, but no stored LTK (IRK Lookup Succeeded)");
|
log_info("LTK Request: ediv & random are empty, but no stored LTK (IRK Lookup Succeeded)");
|
||||||
sm_connection->sm_engine_state = SM_RESPONDER_PH0_SEND_LTK_REQUESTED_NEGATIVE_REPLY;
|
sm_connection->sm_engine_state = SM_SC_SEND_LTK_REQUESTED_NEGATIVE_REPLY;
|
||||||
// don't lock setup context yet
|
|
||||||
done = 0;
|
|
||||||
break;
|
break;
|
||||||
case IRK_LOOKUP_FAILED:
|
case IRK_LOOKUP_FAILED:
|
||||||
log_info("LTK Request: ediv & random are empty, but no stored LTK (IRK Lookup Failed)");
|
log_info("LTK Request: ediv & random are empty, but no stored LTK (IRK Lookup Failed)");
|
||||||
sm_connection->sm_engine_state = SM_RESPONDER_PH0_SEND_LTK_REQUESTED_NEGATIVE_REPLY;
|
sm_connection->sm_engine_state = SM_SC_SEND_LTK_REQUESTED_NEGATIVE_REPLY;
|
||||||
// don't lock setup context yet
|
|
||||||
done = 0;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// just wait until IRK lookup is completed
|
// just wait until IRK lookup is completed
|
||||||
@ -2042,7 +2054,6 @@ static void sm_run(void){
|
|||||||
|
|
||||||
log_info("sm_run: state %u", connection->sm_engine_state);
|
log_info("sm_run: state %u", connection->sm_engine_state);
|
||||||
|
|
||||||
// responding state
|
|
||||||
switch (connection->sm_engine_state){
|
switch (connection->sm_engine_state){
|
||||||
|
|
||||||
// general
|
// general
|
||||||
@ -2056,7 +2067,13 @@ static void sm_run(void){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// responding state
|
||||||
#ifdef ENABLE_LE_SECURE_CONNECTIONS
|
#ifdef ENABLE_LE_SECURE_CONNECTIONS
|
||||||
|
case SM_SC_SEND_LTK_REQUESTED_NEGATIVE_REPLY:
|
||||||
|
connection->sm_engine_state = SM_RESPONDER_IDLE;
|
||||||
|
hci_send_cmd(&hci_le_long_term_key_negative_reply, connection->sm_handle);
|
||||||
|
sm_done_for_handle(connection->sm_handle);
|
||||||
|
return;
|
||||||
case SM_SC_W2_GET_RANDOM_A:
|
case SM_SC_W2_GET_RANDOM_A:
|
||||||
sm_random_start(connection);
|
sm_random_start(connection);
|
||||||
connection->sm_engine_state = SM_SC_W4_GET_RANDOM_A;
|
connection->sm_engine_state = SM_SC_W4_GET_RANDOM_A;
|
||||||
@ -2115,8 +2132,8 @@ static void sm_run(void){
|
|||||||
connection->sm_engine_state = SM_SC_W4_CALCULATE_H6_BR_EDR_LINK_KEY;
|
connection->sm_engine_state = SM_SC_W4_CALCULATE_H6_BR_EDR_LINK_KEY;
|
||||||
h6_calculate_br_edr_link_key(connection);
|
h6_calculate_br_edr_link_key(connection);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// initiator side
|
// initiator side
|
||||||
case SM_INITIATOR_PH0_SEND_START_ENCRYPTION: {
|
case SM_INITIATOR_PH0_SEND_START_ENCRYPTION: {
|
||||||
sm_key_t peer_ltk_flipped;
|
sm_key_t peer_ltk_flipped;
|
||||||
@ -2136,14 +2153,8 @@ static void sm_run(void){
|
|||||||
sm_timeout_reset(connection);
|
sm_timeout_reset(connection);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// responder side
|
|
||||||
case SM_RESPONDER_PH0_SEND_LTK_REQUESTED_NEGATIVE_REPLY:
|
|
||||||
connection->sm_engine_state = SM_RESPONDER_IDLE;
|
|
||||||
hci_send_cmd(&hci_le_long_term_key_negative_reply, connection->sm_handle);
|
|
||||||
sm_done_for_handle(connection->sm_handle);
|
|
||||||
return;
|
|
||||||
|
|
||||||
#ifdef ENABLE_LE_SECURE_CONNECTIONS
|
#ifdef ENABLE_LE_SECURE_CONNECTIONS
|
||||||
|
|
||||||
case SM_SC_SEND_PUBLIC_KEY_COMMAND: {
|
case SM_SC_SEND_PUBLIC_KEY_COMMAND: {
|
||||||
uint8_t buffer[65];
|
uint8_t buffer[65];
|
||||||
buffer[0] = SM_CODE_PAIRING_PUBLIC_KEY;
|
buffer[0] = SM_CODE_PAIRING_PUBLIC_KEY;
|
||||||
|
@ -304,6 +304,7 @@ typedef enum {
|
|||||||
|
|
||||||
// LE Secure Connections
|
// LE Secure Connections
|
||||||
SM_SC_RECEIVED_LTK_REQUEST,
|
SM_SC_RECEIVED_LTK_REQUEST,
|
||||||
|
SM_SC_SEND_LTK_REQUESTED_NEGATIVE_REPLY,
|
||||||
SM_SC_SEND_PUBLIC_KEY_COMMAND,
|
SM_SC_SEND_PUBLIC_KEY_COMMAND,
|
||||||
SM_SC_W4_PUBLIC_KEY_COMMAND,
|
SM_SC_W4_PUBLIC_KEY_COMMAND,
|
||||||
SM_SC_W2_GET_RANDOM_A,
|
SM_SC_W2_GET_RANDOM_A,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user