diff --git a/CHANGELOG.md b/CHANGELOG.md index f39a9c140..3443b8116 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - HCI Dump: Support BTSnoop format in hci_dump_posix_fs.c for format = HCI_DUMP_BTSNOOP - HCI Dump RTT STDOUT: drop messages if RTT buffer is full and RTT is configured for non-blocking - hci_cmd: support variable length fields and arrayed parameters +- GAP: ENABLE_EXPLICIT_LINK_KEY_REPLY allows for asynchronous link key lookup by application - POSIX: btstack_signal allows to register for callback on signal, e.g. ctrl-c - Windows: btstack_stdin_window_register_ctrl_c_callback allows to register for ctrl-c - A2DP: allow to register media codec validator for sink and source with: diff --git a/doc/manual/docs-template/how_to.md b/doc/manual/docs-template/how_to.md index ad90bf46a..f746cf25f 100644 --- a/doc/manual/docs-template/how_to.md +++ b/doc/manual/docs-template/how_to.md @@ -110,6 +110,7 @@ ENABLE_CONTROLLER_WARM_BOOT | Enable stack startup without power cycle (if ENABLE_SEGGER_RTT | Use SEGGER RTT for console output and packet log, see [additional options](#sec:rttConfiguration) ENABLE_EXPLICIT_CONNECTABLE_MODE_CONTROL | Disable calls to control Connectable Mode by L2CAP ENABLE_EXPLICIT_IO_CAPABILITIES_REPLY | Let application trigger sending IO Capabilities (Negative) Reply +ENABLE_EXPLICIT_LINK_KEY_REPLY | Let application trigger sending Link Key (Negative) Response, allows for asynchronous link key lookup ENABLE_CLASSIC_OOB_PAIRING | Enable support for classic Out-of-Band (OOB) pairing ENABLE_A2DP_SOURCE_EXPLICIT_CONFIG | Let application configure stream endpoint (skip auto-config of SBC endpoint) ENABLE_AVDTP_ACCEPTOR_EXPLICIT_START_STREAM_CONFIRMATION | allow accept or reject of stream start on A2DP_SUBEVENT_START_STREAM_REQUESTED diff --git a/src/gap.h b/src/gap.h index b0c5e9971..e5b85121a 100644 --- a/src/gap.h +++ b/src/gap.h @@ -844,6 +844,16 @@ uint8_t gap_ssp_io_capabilities_response(const bd_addr_t addr); */ uint8_t gap_ssp_io_capabilities_negative(const bd_addr_t addr); +/** + * Send Link Key Reponse + * @note Link Key (Negative) Reply is sent automaticallyu unless ENABLE_EXPLICIT_LINK_KEY_RESPONSE + * @param addr + * @param link_key + * @param type or INVALID_LINK_KEY if link key not available + * @return 0 if ok + */ + uint8_t gap_send_link_key_response(const bd_addr_t addr, link_key_t link_key, link_key_type_t type); + /** * @brief Enter Sniff mode * @param con_handle diff --git a/src/hci.c b/src/hci.c index e5b35b916..2940b5576 100644 --- a/src/hci.c +++ b/src/hci.c @@ -2827,6 +2827,7 @@ static void event_handler(uint8_t *packet, uint16_t size){ break; case HCI_EVENT_LINK_KEY_REQUEST: +#ifndef ENABLE_EXPLICIT_LINK_KEY_REPLY hci_event_link_key_request_get_bd_addr(packet, addr); conn = hci_connection_for_bd_addr_and_type(addr, BD_ADDR_TYPE_ACL); if (!conn) break; @@ -6533,8 +6534,7 @@ int gap_ssp_confirmation_negative(const bd_addr_t addr){ return gap_pairing_set_state_and_run(addr, GAP_PAIRING_STATE_SEND_CONFIRMATION_NEGATIVE); } -#ifdef ENABLE_EXPLICIT_IO_CAPABILITIES_REPLY - +#if defined(ENABLE_EXPLICIT_IO_CAPABILITIES_REPLY) || defined(ENABLE_EXPLICIT_LINK_KEY_REPLY) static uint8_t gap_set_auth_flag_and_run(const bd_addr_t addr, hci_authentication_flags_t flag){ hci_connection_t * conn = hci_connection_for_bd_addr_and_type(addr, BD_ADDR_TYPE_ACL); if (!conn) return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; @@ -6542,7 +6542,9 @@ static uint8_t gap_set_auth_flag_and_run(const bd_addr_t addr, hci_authenticatio hci_run(); return ERROR_CODE_SUCCESS; } +#endif +#ifdef ENABLE_EXPLICIT_IO_CAPABILITIES_REPLY uint8_t gap_ssp_io_capabilities_response(const bd_addr_t addr){ return gap_set_auth_flag_and_run(addr, AUTH_FLAG_SEND_IO_CAPABILITIES_REPLY); } @@ -6588,6 +6590,20 @@ void gap_ssp_generate_oob_data(void){ #endif +#ifdef ENABLE_EXPLICIT_LINK_KEY_REPLY +uint8_t gap_send_link_key_response(const bd_addr_t addr, link_key_t link_key, link_key_type_t type){ + hci_connection_t * connection = hci_connection_for_bd_addr_and_type(addr, BD_ADDR_TYPE_ACL); + if (connection == NULL) { + return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER; + } + + memcpy(connection->link_key, link_key, sizeof(link_key_t)); + connection->link_key_type = type; + + return gap_set_auth_flag_and_run(addr, AUTH_FLAG_HANDLE_LINK_KEY_REQUEST); +} + +#endif // ENABLE_EXPLICIT_LINK_KEY_REPLY /** * @brief Set inquiry mode: standard, with RSSI, with RSSI + Extended Inquiry Results. Has to be called before power on. * @param inquiry_mode see bluetooth_defines.h