mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-29 22:20:37 +00:00
hci: read encryption key size for classic connections after encryption got enabled
This commit is contained in:
parent
97abfa24e8
commit
573897a04e
33
src/hci.c
33
src/hci.c
@ -2008,6 +2008,19 @@ static void event_handler(uint8_t *packet, int size){
|
||||
hci_stack->synchronous_flow_control_enabled = 1;
|
||||
}
|
||||
}
|
||||
if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_encryption_key_size)){
|
||||
uint8_t status = packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE];
|
||||
handle = little_endian_read_16(packet, OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1);
|
||||
conn = hci_connection_for_handle(handle);
|
||||
if (!conn) break;
|
||||
if (status == 0){
|
||||
uint8_t key_size = packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+3];
|
||||
log_info("Handle %x04x key Size: %u", handle, key_size);
|
||||
conn->encryption_key_size = key_size;
|
||||
}
|
||||
conn->authentication_flags |= CONNECTION_ENCRYPTED;
|
||||
hci_emit_security_level(handle, gap_security_level_for_connection(conn));
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
@ -2256,14 +2269,21 @@ static void event_handler(uint8_t *packet, int size){
|
||||
if (!conn) break;
|
||||
if (packet[2] == 0) {
|
||||
if (packet[5]){
|
||||
conn->authentication_flags |= CONNECTION_ENCRYPTED;
|
||||
if (hci_is_le_connection(conn)){
|
||||
// For LE, we accept connection as encrypted
|
||||
conn->authentication_flags |= CONNECTION_ENCRYPTED;
|
||||
}
|
||||
#ifdef ENABLE_CLASSIC
|
||||
else {
|
||||
// For Classic, we need to validate encryption key size first
|
||||
conn->bonding_flags |= BONDING_SEND_READ_ENCRYPTION_KEY_SIZE;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
conn->authentication_flags &= ~CONNECTION_ENCRYPTED;
|
||||
}
|
||||
}
|
||||
#ifdef ENABLE_CLASSIC
|
||||
hci_emit_security_level(handle, gap_security_level_for_connection(conn));
|
||||
#endif
|
||||
|
||||
break;
|
||||
|
||||
#ifdef ENABLE_CLASSIC
|
||||
@ -3617,6 +3637,11 @@ static void hci_run(void){
|
||||
hci_send_cmd(&hci_set_connection_encryption, connection->con_handle, 1);
|
||||
return;
|
||||
}
|
||||
if (connection->bonding_flags & BONDING_SEND_READ_ENCRYPTION_KEY_SIZE){
|
||||
connection->bonding_flags &= ~BONDING_SEND_READ_ENCRYPTION_KEY_SIZE;
|
||||
hci_send_cmd(&hci_read_encryption_key_size, connection->con_handle, 1);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (connection->bonding_flags & BONDING_DISCONNECT_SECURITY_BLOCK){
|
||||
|
24
src/hci.h
24
src/hci.h
@ -218,15 +218,16 @@ typedef enum {
|
||||
|
||||
// bonding flags
|
||||
enum {
|
||||
BONDING_REQUEST_REMOTE_FEATURES = 0x01,
|
||||
BONDING_RECEIVED_REMOTE_FEATURES = 0x02,
|
||||
BONDING_REMOTE_SUPPORTS_SSP = 0x04,
|
||||
BONDING_DISCONNECT_SECURITY_BLOCK = 0x08,
|
||||
BONDING_DISCONNECT_DEDICATED_DONE = 0x10,
|
||||
BONDING_SEND_AUTHENTICATE_REQUEST = 0x20,
|
||||
BONDING_SEND_ENCRYPTION_REQUEST = 0x40,
|
||||
BONDING_DEDICATED = 0x80,
|
||||
BONDING_EMIT_COMPLETE_ON_DISCONNECT = 0x100
|
||||
BONDING_REQUEST_REMOTE_FEATURES = 0x01,
|
||||
BONDING_RECEIVED_REMOTE_FEATURES = 0x02,
|
||||
BONDING_REMOTE_SUPPORTS_SSP = 0x04,
|
||||
BONDING_DISCONNECT_SECURITY_BLOCK = 0x08,
|
||||
BONDING_DISCONNECT_DEDICATED_DONE = 0x10,
|
||||
BONDING_SEND_AUTHENTICATE_REQUEST = 0x20,
|
||||
BONDING_SEND_ENCRYPTION_REQUEST = 0x40,
|
||||
BONDING_SEND_READ_ENCRYPTION_KEY_SIZE = 0x80,
|
||||
BONDING_DEDICATED = 0x100,
|
||||
BONDING_EMIT_COMPLETE_ON_DISCONNECT = 0x200
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
@ -481,9 +482,12 @@ typedef struct {
|
||||
uint16_t bonding_flags;
|
||||
uint8_t bonding_status;
|
||||
|
||||
// encryption key size (in octets)
|
||||
uint8_t encryption_key_size;
|
||||
|
||||
// requested security level
|
||||
gap_security_level_t requested_security_level;
|
||||
|
||||
|
||||
//
|
||||
link_key_type_t link_key_type;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user