From 0cd55b6c9fa4acb1bfecaaffdf5e10214b8a559a Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Sun, 2 Jul 2023 11:17:06 +0200 Subject: [PATCH] att_dispatch: extract att_dispatch_classic_get_l2cap_cid --- src/ble/att_dispatch.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/ble/att_dispatch.c b/src/ble/att_dispatch.c index a781cdd6b..a71f0cfcd 100644 --- a/src/ble/att_dispatch.c +++ b/src/ble/att_dispatch.c @@ -128,15 +128,24 @@ void att_dispatch_register_server(btstack_packet_handler_t packet_handler){ l2cap_register_fixed_channel(att_packet_handler, L2CAP_CID_ATTRIBUTE_PROTOCOL); } -static bool att_dispatch_can_send_now(hci_con_handle_t con_handle) { #ifdef ENABLE_GATT_OVER_CLASSIC +static uint16_t att_dispatch_classic_get_l2cap_cid(hci_con_handle_t con_handle){ // get l2cap_cid from att_server in hci_connection hci_connection_t * hci_connection = hci_connection_for_handle(con_handle); - if (hci_connection != NULL){ - uint16_t l2cap_cid = hci_connection->att_server.l2cap_cid; - if (l2cap_cid != 0){ - return l2cap_can_send_packet_now(l2cap_cid); - } + if (hci_connection != NULL) { + return hci_connection->att_server.l2cap_cid; + } else { + return 0; + } +} +#endif + + +static bool att_dispatch_can_send_now(hci_con_handle_t con_handle) { +#ifdef ENABLE_GATT_OVER_CLASSIC + uint16_t l2cap_cid = att_dispatch_classic_get_l2cap_cid(con_handle); + if (l2cap_cid != 0){ + return l2cap_can_send_packet_now(l2cap_cid); } #endif return l2cap_can_send_fixed_channel_packet_now(con_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL);