From 5999ee11ac6e1ae965ccccaa44efcd2dc55113d0 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 3 Mar 2022 12:28:56 +0100 Subject: [PATCH] hci: emit dedicated bonding complete on pairing complete and encryption complete with error --- src/hci.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/hci.c b/src/hci.c index c83983350..5c0db6783 100644 --- a/src/hci.c +++ b/src/hci.c @@ -497,6 +497,13 @@ static void hci_pairing_complete(hci_connection_t * hci_connection, uint8_t stat reverse_bd_addr(hci_connection->address, &event[4]); event[10] = status; hci_emit_event(event, sizeof(event), 1); + + // emit dedicated bonding done on failure, otherwise verify that connection can be encrypted + if ((status != ERROR_CODE_SUCCESS) && ((hci_connection->bonding_flags & BONDING_DEDICATED) != 0)){ + hci_connection->bonding_flags &= ~BONDING_DEDICATED; + hci_connection->bonding_flags |= BONDING_DISCONNECT_DEDICATED_DONE; + hci_connection->bonding_status = status; + } } bool hci_authentication_active_for_handle(hci_con_handle_t handle){ @@ -3282,14 +3289,6 @@ static void event_handler(uint8_t *packet, uint16_t size){ #ifdef ENABLE_CLASSIC else { - // dedicated bonding: send result and disconnect - if (conn->bonding_flags & BONDING_DEDICATED){ - conn->bonding_flags &= ~BONDING_DEDICATED; - conn->bonding_flags |= BONDING_DISCONNECT_DEDICATED_DONE; - conn->bonding_status = packet[2]; - break; - } - // Detect Secure Connection -> Legacy Connection Downgrade Attack (BIAS) bool sc_used_during_pairing = gap_secure_connection_for_link_key_type(conn->link_key_type); bool connected_uses_aes_ccm = encryption_enabled == 2; @@ -3327,6 +3326,13 @@ static void event_handler(uint8_t *packet, uint16_t size){ } else { conn->authentication_flags &= ~AUTH_FLAG_CONNECTION_ENCRYPTED; } + } else { + uint8_t status = hci_event_encryption_change_get_status(packet); + if ((conn->bonding_flags & BONDING_DEDICATED) != 0){ + conn->bonding_flags &= ~BONDING_DEDICATED; + conn->bonding_flags |= BONDING_DISCONNECT_DEDICATED_DONE; + conn->bonding_status = status; + } } break;