From e00caf9ce995069263df4592d192ce395663faf1 Mon Sep 17 00:00:00 2001 From: "matthias.ringwald@gmail.com" Date: Thu, 16 Jan 2014 21:36:05 +0000 Subject: [PATCH] fix handling of IO Capability Request if non-bondable --- include/btstack/hci_cmds.h | 7 +++++-- src/hci.c | 24 +++++++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/include/btstack/hci_cmds.h b/include/btstack/hci_cmds.h index 1521cbc85..eecc5140c 100644 --- a/include/btstack/hci_cmds.h +++ b/include/btstack/hci_cmds.h @@ -244,13 +244,16 @@ extern "C" { #define SM_AUTHORIZATION_REQUEST 0xb9 #define SM_AUTHORIZATION_RESULT 0xba -// ATT +// GAP SECURITY + + // data: event(8), len(8), status (8), hci_handle (16), security_level (8) + #define GAP_AUTHENTICATION_RESULT 0xc0 // Error Code +#define ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER 0x02 #define ERROR_CODE_PAIRING_NOT_ALLOWED 0x18 // last error code in 2.1 is 0x38 - we start with 0x50 for BTstack errors - #define BTSTACK_CONNECTION_TO_BTDAEMON_FAILED 0x50 #define BTSTACK_ACTIVATION_FAILED_SYSTEM_BLUETOOTH 0x51 #define BTSTACK_ACTIVATION_POWERON_FAILED 0x52 diff --git a/src/hci.c b/src/hci.c index 70bb0e4d8..cea4ab0be 100644 --- a/src/hci.c +++ b/src/hci.c @@ -677,7 +677,6 @@ static void event_handler(uint8_t *packet, int size){ case HCI_EVENT_IO_CAPABILITY_REQUEST: hci_add_connection_flags_for_flipped_bd_addr(&packet[2], RECV_IO_CAPABILITIES_REQUEST); - if (!hci_stack.bondable || hci_stack.ssp_io_capability == SSP_IO_CAPABILITY_UNKNOWN) break; hci_add_connection_flags_for_flipped_bd_addr(&packet[2], SEND_IO_CAPABILITIES_REPLY); break; @@ -1248,7 +1247,7 @@ void hci_run(){ } if (connection->authentication_flags & SEND_IO_CAPABILITIES_REPLY){ - if (hci_stack.bondable){ + if (hci_stack.bondable && hci_stack.ssp_io_capability != SSP_IO_CAPABILITY_UNKNOWN){ hci_send_cmd(&hci_io_capability_request_reply, &connection->address, hci_stack.ssp_io_capability, NULL, hci_stack.ssp_authentication_requirement); } else { hci_send_cmd(&hci_io_capability_request_negative_reply, &connection->address, ERROR_CODE_PAIRING_NOT_ALLOWED); @@ -1699,6 +1698,19 @@ void hci_emit_discoverable_enabled(uint8_t enabled){ hci_stack.packet_handler(HCI_EVENT_PACKET, event, sizeof(event)); } +void hci_emit_security_level(hci_con_handle_t con_handle, uint8_t status, gap_security_level_t level){ + uint8_t event[6]; + int pos = 0; + event[pos++] = GAP_AUTHENTICATION_RESULT; + event[pos++] = sizeof(event) - 2; + event[pos++] = status; + bt_store_16(event, 3, con_handle); + pos += 2; + event[pos++] = level; + hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); + hci_stack.packet_handler(HCI_EVENT_PACKET, event, sizeof(event)); +} + // GAP API /** * @bbrief enable/disable bonding. default is enabled @@ -1732,5 +1744,11 @@ gap_security_level_t gap_security_level(hci_con_handle_t con_handle){ * @result GAP_AUTHENTICATION_RESULT */ void gap_request_security_level(hci_con_handle_t con_handle, gap_security_level_t level){ -} + hci_connection_t * connection = hci_connection_for_handle(con_handle); + if (!connection){ + hci_emit_security_level(con_handle, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER, LEVEL_0); + return; + } + // +}