hci: add workaround for Controllers that fail to send command complete/status for connection that does not get established

This commit is contained in:
Matthias Ringwald 2023-11-27 12:08:26 +01:00
parent 515f33be6f
commit f48a558634
3 changed files with 93 additions and 54 deletions

View File

@ -82,60 +82,61 @@ Chipset properties:
### ENABLE_* directives {#sec:enableDirectives}
BTstack properties:
| \#define | Description |
|-----------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|
| ENABLE_CLASSIC | Enable Classic related code in HCI and L2CAP |
| ENABLE_BLE | Enable BLE related code in HCI and L2CAP |
| ENABLE_EHCILL | Enable eHCILL low power mode on TI CC256x/WL18xx chipsets |
| ENABLE_H5 | Enable support for SLIP mode in `btstack_uart.h` drivers for HCI H5 ('Three-Wire Mode') |
| ENABLE_LOG_DEBUG | Enable log_debug messages |
| ENABLE_LOG_ERROR | Enable log_error messages |
| ENABLE_LOG_INFO | Enable log_info messages |
| ENABLE_SCO_OVER_HCI | Enable SCO over HCI for chipsets (if supported) |
| ENABLE_SCO_OVER_PCM | Enable SCO ofer PCM/I2S for chipsets (if supported) |
| ENABLE_HFP_WIDE_BAND_SPEECH | Enable support for mSBC codec used in HFP profile for Wide-Band Speech |
| ENABLE_HFP_AT_MESSAGES | Enable `HFP_SUBEVENT_AT_MESSAGE_SENT` and `HFP_SUBEVENT_AT_MESSAGE_RECEIVED` events |
| ENABLE_LE_PERIPHERAL | Enable support for LE Peripheral Role in HCI and Security Manager |
| ENABLE_LE_CENTRAL | Enable support for LE Central Role in HCI and Security Manager |
| ENABLE_LE_SECURE_CONNECTIONS | Enable LE Secure Connections |
| ENABLE_LE_SECURE_CONNECTIONS_DEBUG_KEY | Enable support for LE Secure Connection debug keys for testing |
| ENABLE_LE_PROACTIVE_AUTHENTICATION | Enable automatic encryption for bonded devices on re-connect |
| ENABLE_GATT_CLIENT_PAIRING | Enable GATT Client to start pairing and retry operation on security error |
| ENABLE_MICRO_ECC_FOR_LE_SECURE_CONNECTIONS | Use [micro-ecc library](https://github.com/kmackay/micro-ecc) for ECC operations |
| ENABLE_LE_DATA_LENGTH_EXTENSION | Enable LE Data Length Extension support |
| ENABLE_LE_ENHANCED_CONNECTION_COMPLETE_EVENT | Enable LE Enhanced Connection Complete Event v1 & v2 |
| ENABLE_LE_EXTENDED_ADVERTISING | Enable extended advertising and scanning |
| ENABLE_LE_PERIODIC_ADVERTISING | Enable periodic advertising and scanning |
| ENABLE_LE_SIGNED_WRITE | Enable LE Signed Writes in ATT/GATT |
| ENABLE_LE_PRIVACY_ADDRESS_RESOLUTION | Enable address resolution for resolvable private addresses in Controller |
| ENABLE_CROSS_TRANSPORT_KEY_DERIVATION | Enable Cross-Transport Key Derivation (CTKD) for Secure Connections |
| ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE | Enable Enhanced Retransmission Mode for L2CAP Channels. Mandatory for AVRCP Browsing |
| 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 |
| Enable_RTK_PCM_WBS | Enable support for Wide-Band Speech codec in Realtek controller, requires ENABLE_SCO_OVER_PCM |
| ENABLE_CC256X_BAUDRATE_CHANGE_FLOWCONTROL_BUG_WORKAROUND | Enable workaround for bug in CC256x Flow Control during baud rate change, see chipset docs. |
| ENABLE_CYPRESS_BAUDRATE_CHANGE_FLOWCONTROL_BUG_WORKAROUND | Enable workaround for bug in CYW2070x Flow Control during baud rate change, similar to CC256x. |
| ENABLE_LE_LIMIT_ACL_FRAGMENT_BY_MAX_OCTETS | Force HCI to fragment ACL-LE packets to fit into over-the-air packet |
| ENABLE_TLV_FLASH_EXPLICIT_DELETE_FIELD | Enable use of explicit delete field in TLV Flash implementation - required when flash value cannot be overwritten with zero |
| ENABLE_TLV_FLASH_WRITE_ONCE | Enable storing of emtpy tag instead of overwriting existing tag - required when flash value cannot be overwritten at all |
| ENABLE_CONTROLLER_WARM_BOOT | Enable stack startup without power cycle (if supported/possible) |
| 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_EXPLICIT_BR_EDR_SECURITY_MANAGER | Report BR/EDR Security Manager support in L2CAP Information Response |
| ENABLE_EXPLICIT_DEDICATED_BONDING_DISCONNECT | Keep connection after dedicated bonding is complete |
| ENABLE_CLASSIC_OOB_PAIRING | Enable support for classic Out-of-Band (OOB) pairing |
| ENABLE_A2DP_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 |
| ENABLE_LE_WHITELIST_TOUCH_AFTER_RESOLVING_LIST_UPDATE | Enable Workaround for Controller bug |
| ENABLE_LE_SET_ADV_PARAMS_ON_RANDOM_ADDRESS_CHANGE | Send HCI LE Set Advertising Params after HCI LE Set Random Address - workaround for Controller Bug |
| ENABLE_CONTROLLER_DUMP_PACKETS | Dump number of packets in Controller per type for debugging |
| \#define | Description |
|-----------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|
| ENABLE_CLASSIC | Enable Classic related code in HCI and L2CAP |
| ENABLE_BLE | Enable BLE related code in HCI and L2CAP |
| ENABLE_EHCILL | Enable eHCILL low power mode on TI CC256x/WL18xx chipsets |
| ENABLE_H5 | Enable support for SLIP mode in `btstack_uart.h` drivers for HCI H5 ('Three-Wire Mode') |
| ENABLE_LOG_DEBUG | Enable log_debug messages |
| ENABLE_LOG_ERROR | Enable log_error messages |
| ENABLE_LOG_INFO | Enable log_info messages |
| ENABLE_SCO_OVER_HCI | Enable SCO over HCI for chipsets (if supported) |
| ENABLE_SCO_OVER_PCM | Enable SCO ofer PCM/I2S for chipsets (if supported) |
| ENABLE_HFP_WIDE_BAND_SPEECH | Enable support for mSBC codec used in HFP profile for Wide-Band Speech |
| ENABLE_HFP_AT_MESSAGES | Enable `HFP_SUBEVENT_AT_MESSAGE_SENT` and `HFP_SUBEVENT_AT_MESSAGE_RECEIVED` events |
| ENABLE_LE_PERIPHERAL | Enable support for LE Peripheral Role in HCI and Security Manager |
| ENABLE_LE_CENTRAL | Enable support for LE Central Role in HCI and Security Manager |
| ENABLE_LE_SECURE_CONNECTIONS | Enable LE Secure Connections |
| ENABLE_LE_SECURE_CONNECTIONS_DEBUG_KEY | Enable support for LE Secure Connection debug keys for testing |
| ENABLE_LE_PROACTIVE_AUTHENTICATION | Enable automatic encryption for bonded devices on re-connect |
| ENABLE_GATT_CLIENT_PAIRING | Enable GATT Client to start pairing and retry operation on security error |
| ENABLE_MICRO_ECC_FOR_LE_SECURE_CONNECTIONS | Use [micro-ecc library](https://github.com/kmackay/micro-ecc) for ECC operations |
| ENABLE_LE_DATA_LENGTH_EXTENSION | Enable LE Data Length Extension support |
| ENABLE_LE_ENHANCED_CONNECTION_COMPLETE_EVENT | Enable LE Enhanced Connection Complete Event v1 & v2 |
| ENABLE_LE_EXTENDED_ADVERTISING | Enable extended advertising and scanning |
| ENABLE_LE_PERIODIC_ADVERTISING | Enable periodic advertising and scanning |
| ENABLE_LE_SIGNED_WRITE | Enable LE Signed Writes in ATT/GATT |
| ENABLE_LE_PRIVACY_ADDRESS_RESOLUTION | Enable address resolution for resolvable private addresses in Controller |
| ENABLE_CROSS_TRANSPORT_KEY_DERIVATION | Enable Cross-Transport Key Derivation (CTKD) for Secure Connections |
| ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE | Enable Enhanced Retransmission Mode for L2CAP Channels. Mandatory for AVRCP Browsing |
| 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 |
| Enable_RTK_PCM_WBS | Enable support for Wide-Band Speech codec in Realtek controller, requires ENABLE_SCO_OVER_PCM |
| ENABLE_CC256X_BAUDRATE_CHANGE_FLOWCONTROL_BUG_WORKAROUND | Enable workaround for bug in CC256x Flow Control during baud rate change, see chipset docs. |
| ENABLE_CYPRESS_BAUDRATE_CHANGE_FLOWCONTROL_BUG_WORKAROUND | Enable workaround for bug in CYW2070x Flow Control during baud rate change, similar to CC256x. |
| ENABLE_LE_LIMIT_ACL_FRAGMENT_BY_MAX_OCTETS | Force HCI to fragment ACL-LE packets to fit into over-the-air packet |
| ENABLE_TLV_FLASH_EXPLICIT_DELETE_FIELD | Enable use of explicit delete field in TLV Flash implementation - required when flash value cannot be overwritten with zero |
| ENABLE_TLV_FLASH_WRITE_ONCE | Enable storing of emtpy tag instead of overwriting existing tag - required when flash value cannot be overwritten at all |
| ENABLE_CONTROLLER_WARM_BOOT | Enable stack startup without power cycle (if supported/possible) |
| 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_EXPLICIT_BR_EDR_SECURITY_MANAGER | Report BR/EDR Security Manager support in L2CAP Information Response |
| ENABLE_EXPLICIT_DEDICATED_BONDING_DISCONNECT | Keep connection after dedicated bonding is complete |
| ENABLE_CLASSIC_OOB_PAIRING | Enable support for classic Out-of-Band (OOB) pairing |
| ENABLE_A2DP_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 |
| ENABLE_LE_WHITELIST_TOUCH_AFTER_RESOLVING_LIST_UPDATE | Enable Workaround for Controller bug |
| ENABLE_LE_SET_ADV_PARAMS_ON_RANDOM_ADDRESS_CHANGE | Send HCI LE Set Advertising Params after HCI LE Set Random Address - workaround for Controller Bug |
| ENABLE_CONTROLLER_DUMP_PACKETS | Dump number of packets in Controller per type for debugging |
| ENABLE_HCI_COMMAND_STATUS_DISCARDED_FOR_FAILED_CONNECTIONS WORKAROUND | Track connection handle for HCI Commands and assume command has failed if disonnect event for connection is received |
Notes:

View File

@ -2781,6 +2781,9 @@ static void handle_command_complete_event(uint8_t * packet, uint16_t size){
#ifdef ENABLE_LE_ISOCHRONOUS_STREAMS
le_audio_cig_t * cig;
#endif
#if defined(ENABLE_BLE) && defined (ENABLE_HCI_COMMAND_STATUS_DISCARDED_FOR_FAILED_CONNECTIONS WORKAROUND)
hci_stack->hci_command_con_handle = HCI_CON_HANDLE_INVALID;
#endif
// get num cmd packets - limit to 1 to reduce complexity
hci_stack->num_cmd_packets = packet[2] ? 1 : 0;
@ -3196,6 +3199,10 @@ static void handle_command_status_event(uint8_t * packet, uint16_t size) {
bd_addr_t addr;
#endif
#if defined(ENABLE_BLE) && defined (ENABLE_HCI_COMMAND_STATUS_DISCARDED_FOR_FAILED_CONNECTIONS)
hci_stack->hci_command_con_handle = HCI_CON_HANDLE_INVALID;
#endif
switch (opcode){
#ifdef ENABLE_CLASSIC
case HCI_OPCODE_HCI_CREATE_CONNECTION:
@ -4156,6 +4163,15 @@ static void event_handler(uint8_t *packet, uint16_t size){
}
#endif
#if defined(ENABLE_BLE) && defined (ENABLE_HCI_COMMAND_STATUS_DISCARDED_FOR_FAILED_CONNECTIONS WORKAROUND)
if ((handle != HCI_CON_HANDLE_INVALID) && (handle == hci_stack->hci_command_con_handle)){
// we did not receive a HCI Command Complete or HCI Command Status event for the disconnected connection
// if needed, we could also track the hci command opcode and simulate a hci command complete with status
// but the connection has failed anyway, so for now, we only set the num hci commands back to 1
hci_stack->num_cmd_packets = 1;
}
#endif
conn = hci_connection_for_handle(handle);
if (!conn) break;
#ifdef ENABLE_CLASSIC
@ -4750,6 +4766,9 @@ static void hci_state_reset(void){
hci_stack->iso_active_operation_type = HCI_ISO_TYPE_INVALID;
hci_stack->iso_active_operation_group_id = HCI_ISO_GROUP_ID_INVALID;
#endif
#ifdef ENABLE_HCI_COMMAND_STATUS_DISCARDED_FOR_FAILED_CONNECTIONS WORKAROUND
hci_stack->hci_command_con_handle = HCI_CON_HANDLE_INVALID;
#endif
}
#ifdef ENABLE_CLASSIC
@ -7638,6 +7657,21 @@ uint8_t hci_send_cmd_packet(uint8_t *packet, int size){
hci_stack->le_connecting_state = LE_CONNECTING_CANCEL;
break;
#endif
#ifdef ENABLE_HCI_COMMAND_STATUS_DISCARDED_FOR_FAILED_CONNECTIONS WORKAROUND
case HCI_OPCODE_HCI_LE_CONNECTION_UPDATE:
case HCI_OPCODE_HCI_LE_READ_REMOTE_USED_FEATURES:
case HCI_OPCODE_HCI_LE_START_ENCRYPTION:
case HCI_OPCODE_HCI_LE_LONG_TERM_KEY_REQUEST_REPLY:
case HCI_OPCODE_HCI_LE_LONG_TERM_KEY_NEGATIVE_REPLY:
case HCI_OPCODE_HCI_LE_REMOTE_CONNECTION_PARAMETER_REQUEST_REPLY:
case HCI_OPCODE_HCI_LE_REMOTE_CONNECTION_PARAMETER_REQUEST_NEGATIVE_REPLY:
case HCI_OPCODE_HCI_LE_SET_DATA_LENGTH:
case HCI_OPCODE_HCI_LE_READ_PHY:
case HCI_OPCODE_HCI_LE_SET_PHY:
// conection handle is first command parameter
hci_stack->hci_command_con_handle = little_endian_read_16(packet, 3);
break;
#endif
#endif /* ENABLE_BLE */
default:
break;

View File

@ -1207,6 +1207,10 @@ typedef struct {
uint16_t le_supervision_timeout;
uint16_t le_minimum_ce_length;
uint16_t le_maximum_ce_length;
#ifdef ENABLE_HCI_COMMAND_STATUS_DISCARDED_FOR_FAILED_CONNECTIONS
hci_con_handle_t hci_command_con_handle;
#endif
#endif
#ifdef ENABLE_LE_CENTRAL