From 0f3b27c5455c33e8b0ec10e18e85d4b52b73950e Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Wed, 29 Apr 2020 14:20:14 +0200 Subject: [PATCH] hci: implement ENABLE_LE_LIMIT_ACL_FRAGMENT_BY_MAX_OCTETS --- CHANGELOG.md | 1 + doc/manual/docs/how_to.md | 1 + src/hci.c | 21 ++++++++++++++++++--- src/hci.h | 4 ++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4c3ceede..69d549087 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - GAP: gap_set_allow_role_switch allows to prevent role switch in outgoing classic ACL connections - example: hog_boot_host_demo implement an HID-over-GATT Boot Host that supports keyboard and mouse +- hci: add ENABLE_LE_LIMIT_ACL_FRAGMENT_BY_MAX_OCTETS that forces fragmentation of ACL-LE packets to fit into over-the-air packet ### Changed - Broadcom/Cypress: wait 300 ms after PatchRAM update in hci.c to assert Controller is ready diff --git a/doc/manual/docs/how_to.md b/doc/manual/docs/how_to.md index c436e0760..d88d229a4 100644 --- a/doc/manual/docs/how_to.md +++ b/doc/manual/docs/how_to.md @@ -97,6 +97,7 @@ ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE | Enable L2CAP Enhanced Retransmission ENABLE_HCI_CONTROLLER_TO_HOST_FLOW_CONTROL | Enable HCI Controller to Host Flow Control, see below 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 implemenation - required when flash value cannot be overwritten with zero 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) diff --git a/src/hci.c b/src/hci.c index 6c5c99ab0..4d507edc0 100644 --- a/src/hci.c +++ b/src/hci.c @@ -211,7 +211,10 @@ static hci_connection_t * create_connection_for_bd_addr_and_type(bd_addr_t addr, conn->le_con_parameter_update_state = CON_PARAMETER_UPDATE_NONE; #ifdef ENABLE_BLE conn->le_phy_update_all_phys = 0xff; -#endif +#endif +#ifdef ENABLE_LE_LIMIT_ACL_FRAGMENT_BY_MAX_OCTETS + conn->le_max_tx_octets = 27; +#endif btstack_linked_list_add(&hci_stack->connections, (btstack_linked_item_t *) conn); return conn; } @@ -649,8 +652,11 @@ static int hci_send_acl_packet_fragments(hci_connection_t *connection){ max_acl_data_packet_length = hci_stack->le_data_packets_length; } - // testing: reduce buffer to minimum - // max_acl_data_packet_length = 52; +#ifdef ENABLE_LE_LIMIT_ACL_FRAGMENT_BY_MAX_OCTETS + if (hci_is_le_connection(connection)){ + max_acl_data_packet_length = connection->le_max_tx_octets; + } +#endif log_debug("hci_send_acl_packet_fragments entered"); @@ -2600,6 +2606,15 @@ static void event_handler(uint8_t *packet, int size){ } } break; +#ifdef ENABLE_LE_LIMIT_ACL_FRAGMENT_BY_MAX_OCTETS + case HCI_SUBEVENT_LE_DATA_LENGTH_CHANGE: + handle = hci_subevent_le_data_length_change_get_connection_handle(packet); + conn = hci_connection_for_handle(handle); + if (conn) { + conn->le_max_tx_octets = hci_subevent_le_data_length_change_get_max_tx_octets(packet); + } + break; +#endif default: break; } diff --git a/src/hci.h b/src/hci.h index d70414357..1e1e1328c 100644 --- a/src/hci.h +++ b/src/hci.h @@ -566,6 +566,10 @@ typedef struct { // LE Security Manager sm_connection_t sm_connection; +#ifdef ENABLE_LE_LIMIT_ACL_FRAGMENT_BY_MAX_OCTETS + uint16_t le_max_tx_octets; +#endif + // ATT Server att_server_t att_server; #endif