From 9a2cabcf31640e3bdd7b0cec1b26f89c48bc405d Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Mon, 24 Feb 2025 11:01:31 +0100 Subject: [PATCH] hid_host: emit HID_SUBEVENT_INCOMING_CONNECTION if memory allocation fails --- CHANGELOG.md | 1 + src/classic/hid_host.c | 25 ++++++++++++------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 722a67c9c..5448f854d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed - HCI: hci_request_cis_can_send_now_events for CIG in Central role will emit can send now events for all streams in group - GAP: validate params in gap_set_scan_params +- HID Host: emit HID_SUBEVENT_INCOMING_CONNECTION if memory allocation fails - BTstack HID: remove HID_PROTOCOL_MODE_REPORT_WITH_FALLBACK_TO_BOOT ## Release v1.6.2 diff --git a/src/classic/hid_host.c b/src/classic/hid_host.c index ba09fa804..bea380cfa 100644 --- a/src/classic/hid_host.c +++ b/src/classic/hid_host.c @@ -882,23 +882,22 @@ static void hid_host_packet_handler(uint8_t packet_type, uint16_t channel, uint8 l2cap_decline_connection(channel); break; } - connection = hid_host_create_connection(address); - if (!connection){ + if (connection == NULL) { log_error("Cannot create connection for %s", bd_addr_to_str(address)); l2cap_decline_connection(channel); - break; + // inform user about failed incoming connection due to memory + hid_emit_incoming_connection_event(connection->hid_cid, address, con_handle, ERROR_CODE_MEMORY_CAPACITY_EXCEEDED); + } else { + connection->state = HID_HOST_W4_CONTROL_CONNECTION_ESTABLISHED; + connection->hid_descriptor_status = ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE; + connection->con_handle = con_handle; + connection->control_cid = l2cap_event_incoming_connection_get_local_cid(packet); + connection->incoming = true; + // emit connection request + // user calls either hid_host_accept_connection or hid_host_decline_connection + hid_emit_incoming_connection_event(connection->hid_cid, address, con_handle, ERROR_CODE_SUCCESS); } - - connection->state = HID_HOST_W4_CONTROL_CONNECTION_ESTABLISHED; - connection->hid_descriptor_status = ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE; - connection->con_handle = con_handle; - connection->control_cid = l2cap_event_incoming_connection_get_local_cid(packet); - connection->incoming = true; - - // emit connection request - // user calls either hid_host_accept_connection or hid_host_decline_connection - hid_emit_incoming_connection_event(connection->hid_cid, address, con_handle, ERROR_CODE_SUCCESS); break; case PSM_HID_INTERRUPT: