From b848f4ec55c2f9cb9657076b314f55e2d0a04fd6 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Mon, 24 Feb 2025 11:00:22 +0100 Subject: [PATCH] hid_host_demo: only accept incoming connection if status is ok --- example/hid_host_demo.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/example/hid_host_demo.c b/example/hid_host_demo.c index cfb36e7ab..71826bc24 100644 --- a/example/hid_host_demo.c +++ b/example/hid_host_demo.c @@ -343,11 +343,18 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack switch (hci_event_hid_meta_get_subevent_code(packet)){ case HID_SUBEVENT_INCOMING_CONNECTION: - // There is an incoming connection: we can accept it or decline it. - // The hid_host_report_mode in the hid_host_accept_connection function - // allows the application to request a protocol mode. - // For available protocol modes, see hid_protocol_mode_t in btstack_hid.h file. - hid_host_accept_connection(hid_subevent_incoming_connection_get_hid_cid(packet), hid_host_report_mode); + // There is an incoming connection: we can accept it or decline it + + // If there are no resources to handle the connection, + // the status will be ERROR_CODE_MEMORY_CAPACITY_EXCEEDED + + // The hid_host_report_mode in the hid_host_accept_connection function + // allows the application to request a protocol mode. + + // For available protocol modes, see hid_protocol_mode_t in btstack_hid.h file. + if (hid_subevent_incoming_connection_get_status(packet) == ERROR_CODE_SUCCESS) { + hid_host_accept_connection(hid_subevent_incoming_connection_get_hid_cid(packet), hid_host_report_mode); + } break; case HID_SUBEVENT_CONNECTION_OPENED: