From 6724cd9e0e8ff005aa86cb62959276bf44acdda8 Mon Sep 17 00:00:00 2001 From: "matthias.ringwald@gmail.com" Date: Fri, 17 Jan 2014 19:28:03 +0000 Subject: [PATCH] track legacy and ssp pairing, new implementation for hci_authentication_active_for_handle based on that --- src/hci.c | 35 +++++++++++++++++++++++++++-------- src/hci.h | 18 +++++++----------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/hci.c b/src/hci.c index d9f3a7518..7338b2c6c 100644 --- a/src/hci.c +++ b/src/hci.c @@ -182,10 +182,9 @@ static void hci_add_connection_flags_for_flipped_bd_addr(uint8_t *bd_addr, hci_a int hci_authentication_active_for_handle(hci_con_handle_t handle){ hci_connection_t * conn = hci_connection_for_handle(handle); if (!conn) return 0; - if (!conn->authentication_flags) return 0; - if (conn->authentication_flags & SENT_LINK_KEY_REPLY) return 0; - if (conn->authentication_flags & RECV_LINK_KEY_NOTIFICATION) return 0; - return 1; + if (conn->authentication_flags & LEGACY_PAIRING_ACTIVE) return 1; + if (conn->authentication_flags & SSP_PAIRING_ACTIVE) return 1; + return 0; } void hci_drop_link_key_for_bd_addr(bd_addr_t *addr){ @@ -664,7 +663,7 @@ static void event_handler(uint8_t *packet, int size){ } case HCI_EVENT_PIN_CODE_REQUEST: - hci_add_connection_flags_for_flipped_bd_addr(&packet[2], RECV_PIN_CODE_REQUEST); + hci_add_connection_flags_for_flipped_bd_addr(&packet[2], LEGACY_PAIRING_ACTIVE); // non-bondable mode: pin code negative reply will be sent if (!hci_stack.bondable){ hci_add_connection_flags_for_flipped_bd_addr(&packet[2], DENY_PIN_CODE_REQUEST); @@ -683,13 +682,13 @@ static void event_handler(uint8_t *packet, int size){ break; case HCI_EVENT_USER_CONFIRMATION_REQUEST: - hci_add_connection_flags_for_flipped_bd_addr(&packet[2], RECV_USER_CONFIRM_REQUEST); + hci_add_connection_flags_for_flipped_bd_addr(&packet[2], SSP_PAIRING_ACTIVE); if (!hci_stack.ssp_auto_accept) break; hci_add_connection_flags_for_flipped_bd_addr(&packet[2], SEND_USER_CONFIRM_REPLY); break; case HCI_EVENT_USER_PASSKEY_REQUEST: - hci_add_connection_flags_for_flipped_bd_addr(&packet[2], RECV_USER_PASSKEY_REQUEST); + hci_add_connection_flags_for_flipped_bd_addr(&packet[2], SSP_PAIRING_ACTIVE); if (!hci_stack.ssp_auto_accept) break; hci_add_connection_flags_for_flipped_bd_addr(&packet[2], SEND_USER_PASSKEY_REPLY); break; @@ -1572,7 +1571,27 @@ int hci_send_cmd_packet(uint8_t *packet, int size){ hci_stack.remote_device_db->delete_link_key(&addr); } } - + + if (IS_COMMAND(packet, hci_pin_code_request_negative_reply) + || IS_COMMAND(packet, hci_pin_code_request_reply)){ + bt_flip_addr(addr, &packet[3]); + conn = connection_for_address(addr); + if (conn){ + connectionClearAuthenticationFlags(conn, LEGACY_PAIRING_ACTIVE); + } + } + + if (IS_COMMAND(packet, hci_user_confirmation_request_negative_reply) + || IS_COMMAND(packet, hci_user_confirmation_request_reply) + || IS_COMMAND(packet, hci_user_passkey_request_negative_reply) + || IS_COMMAND(packet, hci_user_passkey_request_reply)) { + bt_flip_addr(addr, &packet[3]); + conn = connection_for_address(addr); + if (conn){ + connectionClearAuthenticationFlags(conn, SSP_PAIRING_ACTIVE); + } + } + #ifdef HAVE_BLE if (IS_COMMAND(packet, hci_le_set_advertising_parameters)){ hci_stack.adv_addr_type = packet[8]; diff --git a/src/hci.h b/src/hci.h index 23ff3e532..e4d0bf38d 100644 --- a/src/hci.h +++ b/src/hci.h @@ -205,22 +205,18 @@ typedef enum { SENT_LINK_KEY_REPLY = 0x0004, SENT_LINK_KEY_NEGATIVE_REQUEST = 0x0008, RECV_LINK_KEY_NOTIFICATION = 0x0010, - RECV_PIN_CODE_REQUEST = 0x0020, DENY_PIN_CODE_REQUEST = 0x0040, - // SSP RECV_IO_CAPABILITIES_REQUEST = 0x0080, SEND_IO_CAPABILITIES_REPLY = 0x0100, - RECV_USER_CONFIRM_REQUEST = 0x0200, - SEND_USER_CONFIRM_REPLY = 0x0400, - RECV_USER_PASSKEY_REQUEST = 0x0800, - SEND_USER_PASSKEY_REPLY = 0x1000, + SEND_USER_CONFIRM_REPLY = 0x0200, + SEND_USER_PASSKEY_REPLY = 0x0400, + + // pairing status + LEGACY_PAIRING_ACTIVE = 0x2000, + SSP_PAIRING_ACTIVE = 0x4000, // connection status - CONNECTION_ENCRYPTED = 0x2000, - - // SENT_PIN_CODE_REPLY = 0x0080, - // SENT_PIN_CODE_NEGATIVE_REPLY = 0x0100, - + CONNECTION_ENCRYPTED = 0x8000, } hci_authentication_flags_t; typedef enum {