From 6c0d5426fc1c2c9a00e570cf11ee69d9e02158ec Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Mon, 24 Jan 2022 18:10:16 +0100 Subject: [PATCH] hci: ENABLE_HCI_SERIALIZED_CONTROLLER_OPERATIONS serializes Inquiry, Remote Name Request and Create Connection operations --- CHANGELOG.md | 1 + doc/manual/docs-template/how_to.md | 1 + src/hci.c | 56 +++++++++++++++++++++++++----- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3df446463..6fe8f36a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased ### Added +- HCI: ENABLE_HCI_SERIALIZED_CONTROLLER_OPERATIONS serializes Inquiry, Remote Name Request and Create Connection operations - GAP: support extended advertising with ENABLE_LE_EXTENDED_ADVERTISING - ATT DB: provide gatt_server_get_handle_range_for_service_with_uuid16 to find included service within handle range - GATT Service: Audio Input Control Service Server (AICS 1.0) diff --git a/doc/manual/docs-template/how_to.md b/doc/manual/docs-template/how_to.md index d5593f2de..f1bd0fb04 100644 --- a/doc/manual/docs-template/how_to.md +++ b/doc/manual/docs-template/how_to.md @@ -100,6 +100,7 @@ ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE | Enable Enhanced Retransmission Mode ENABLE_L2CAP_LE_CREDIT_BASED_FLOW_CONTROL_MODE | Enable LE credit-based flow-control mode for L2CAP channels ENABLE_L2CAP_ENHANCED_CREDIT_BASED_FLOW_CONTROL_MODE | Enable Enhanced credit-based flow-control mode for L2CAP Channels ENABLE_HCI_CONTROLLER_TO_HOST_FLOW_CONTROL | Enable HCI Controller to Host Flow Control, see below +ENABLE_HCI_SERIALIZED_CONTROLLER_OPERATIONS | Serialize Inquiry, Remote Name Request, and Create Connection operations ENABLE_ATT_DELAYED_RESPONSE | Enable support for delayed ATT operations, see [GATT Server](profiles/#sec:GATTServerProfile) ENABLE_BCM_PCM_WBS | Enable support for Wide-Band Speech codec in BCM controller, requires ENABLE_SCO_OVER_PCM ENABLE_CC256X_ASSISTED_HFP | Enable support for Assisted HFP mode in CC256x Controller, requires ENABLE_SCO_OVER_PCM diff --git a/src/hci.c b/src/hci.c index 7f05f99d6..1b38c9a1c 100644 --- a/src/hci.c +++ b/src/hci.c @@ -4517,6 +4517,31 @@ static bool hci_run_acl_fragments(void){ } #ifdef ENABLE_CLASSIC + +#ifdef ENABLE_HCI_SERIALIZED_CONTROLLER_OPERATIONS +static bool hci_classic_operation_active(void) { + if (hci_stack->inquiry_state >= GAP_INQUIRY_STATE_W4_ACTIVE){ + return true; + } + if (hci_stack->remote_name_state == GAP_REMOTE_NAME_STATE_W4_COMPLETE){ + return true; + } + btstack_linked_item_t * it; + for (it = (btstack_linked_item_t *) hci_stack->connections; it != NULL; it = it->next) { + hci_connection_t *connection = (hci_connection_t *) it; + switch (connection->state) { + case SENT_CREATE_CONNECTION: + case SENT_CANCEL_CONNECTION: + case SENT_DISCONNECT: + return true; + default: + break; + } + } + return false; +} +#endif + static bool hci_run_general_gap_classic(void){ // assert stack is working and classic is active @@ -4538,10 +4563,15 @@ static bool hci_run_general_gap_classic(void){ // start/stop inquiry if ((hci_stack->inquiry_state >= GAP_INQUIRY_DURATION_MIN) && (hci_stack->inquiry_state <= GAP_INQUIRY_DURATION_MAX)){ - uint8_t duration = hci_stack->inquiry_state; - hci_stack->inquiry_state = GAP_INQUIRY_STATE_W4_ACTIVE; - hci_send_cmd(&hci_inquiry, hci_stack->inquiry_lap, duration, 0); - return true; +#ifdef ENABLE_HCI_SERIALIZED_CONTROLLER_OPERATIONS + if (hci_classic_operation_active() == false) +#endif + { + uint8_t duration = hci_stack->inquiry_state; + hci_stack->inquiry_state = GAP_INQUIRY_STATE_W4_ACTIVE; + hci_send_cmd(&hci_inquiry, hci_stack->inquiry_lap, duration, 0); + return true; + } } if (hci_stack->inquiry_state == GAP_INQUIRY_STATE_W2_CANCEL){ hci_stack->inquiry_state = GAP_INQUIRY_STATE_W4_CANCELLED; @@ -4550,10 +4580,15 @@ static bool hci_run_general_gap_classic(void){ } // remote name request if (hci_stack->remote_name_state == GAP_REMOTE_NAME_STATE_W2_SEND){ - hci_stack->remote_name_state = GAP_REMOTE_NAME_STATE_W4_COMPLETE; - hci_send_cmd(&hci_remote_name_request, hci_stack->remote_name_addr, - hci_stack->remote_name_page_scan_repetition_mode, 0, hci_stack->remote_name_clock_offset); - return true; +#ifdef ENABLE_HCI_SERIALIZED_CONTROLLER_OPERATIONS + if (hci_classic_operation_active() == false) +#endif + { + hci_stack->remote_name_state = GAP_REMOTE_NAME_STATE_W4_COMPLETE; + hci_send_cmd(&hci_remote_name_request, hci_stack->remote_name_addr, + hci_stack->remote_name_page_scan_repetition_mode, 0, hci_stack->remote_name_clock_offset); + return true; + } } #ifdef ENABLE_CLASSIC_PAIRING_OOB // Local OOB data @@ -5757,6 +5792,11 @@ uint8_t hci_send_cmd_packet(uint8_t *packet, int size){ // create connection triggered in disconnect complete event, let's do it now break; case SEND_CREATE_CONNECTION: +#ifdef ENABLE_HCI_SERIALIZED_CONTROLLER_OPERATIONS + if (hci_classic_operation_active()){ + return ERROR_CODE_SUCCESS; + } +#endif // connection created by hci, e.g. dedicated bonding, but not executed yet, let's do it now break; default: