From b435e06234e531c17261f382423cd8c2f23dc22d Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 7 Jul 2017 22:34:48 +0200 Subject: [PATCH] hci: require ENABLE_LE_DATA_LENGTH_EXTENSION to enable max packet lenghts --- doc/manual/docs/how_to.md | 31 ++++++++++++----------- port/libusb/btstack_config.h | 1 + port/posix-h4-da14581/btstack_config.h | 1 + port/posix-h4/btstack_config.h | 1 + port/posix-h5-bcm/btstack_config.h | 1 + port/posix-h5/btstack_config.h | 1 + port/stm32-l053r8-em9304/btstack_config.h | 1 + port/wiced-h4/btstack_config.h | 1 + port/wiced-h5/btstack_config.h | 1 + port/windows-h4/btstack_config.h | 1 + port/windows-winusb/btstack_config.h | 1 + src/hci.c | 27 ++++++++++++++++---- src/hci.h | 5 ++++ 13 files changed, 53 insertions(+), 20 deletions(-) diff --git a/doc/manual/docs/how_to.md b/doc/manual/docs/how_to.md index 633692c77..324c5f32e 100644 --- a/doc/manual/docs/how_to.md +++ b/doc/manual/docs/how_to.md @@ -66,21 +66,22 @@ LE_DEVICE_DB_PATH | Path to stored LE device information ### 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_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 (only TI CC256x/WL18xx, CSR + Broadcom H2/USB)) -ENABLE_HFP_WIDE_BAND_SPEECH | Enable support for mSBC codec used in HFP profile for Wide-Band Speech -ENBALE_LE_PERIPHERAL | Enable support for LE Peripheral Role in HCI and Security Manager -ENBALE_LE_CENTRAL | Enable support for LE Central Role in HCI and Security Manager -ENABLE_LE_SECURE_CONNECTIONS | Enable LE Secure Connections using [mbed TLS library](https://tls.mbed.org) -ENABLE_LE_DATA_CHANNELS | Enable LE Data Channels in credit-based flow control mode -ENABLE_LE_SIGNED_WRITE | Enable LE Signed Writes in ATT/GATT +#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_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 (only TI CC256x/WL18xx, CSR + Broadcom H2/USB)) +ENABLE_HFP_WIDE_BAND_SPEECH | Enable support for mSBC codec used in HFP profile for Wide-Band Speech +ENBALE_LE_PERIPHERAL | Enable support for LE Peripheral Role in HCI and Security Manager +ENBALE_LE_CENTRAL | Enable support for LE Central Role in HCI and Security Manager +ENABLE_LE_SECURE_CONNECTIONS | Enable LE Secure Connections using [mbed TLS library](https://tls.mbed.org) +ENABLE_LE_DATA_CHANNELS | Enable LE Data Channels in credit-based flow control mode +ENABLE_LE_DATA_LENGTH_EXTENSION | Enable LE Data Length Extension support +ENABLE_LE_SIGNED_WRITE | Enable LE Signed Writes in ATT/GATT 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. diff --git a/port/libusb/btstack_config.h b/port/libusb/btstack_config.h index b9e43d175..ec4455e5f 100644 --- a/port/libusb/btstack_config.h +++ b/port/libusb/btstack_config.h @@ -18,6 +18,7 @@ #define ENABLE_LE_CENTRAL #define ENABLE_LE_PERIPHERAL #define ENABLE_LE_SECURE_CONNECTIONS +#define ENABLE_LE_DATA_LENGTH_EXTENSION #define ENABLE_LOG_ERROR #define ENABLE_LOG_INFO #define ENABLE_SCO_OVER_HCI diff --git a/port/posix-h4-da14581/btstack_config.h b/port/posix-h4-da14581/btstack_config.h index 4fb360470..0dcef36b5 100644 --- a/port/posix-h4-da14581/btstack_config.h +++ b/port/posix-h4-da14581/btstack_config.h @@ -18,6 +18,7 @@ #define ENABLE_LE_CENTRAL #define ENABLE_LE_PERIPHERAL #define ENABLE_LE_SECURE_CONNECTIONS +#define ENABLE_LE_DATA_LENGTH_EXTENSION #define ENABLE_LOG_ERROR #define ENABLE_LOG_INFO #define ENABLE_SCO_OVER_HCI diff --git a/port/posix-h4/btstack_config.h b/port/posix-h4/btstack_config.h index 4fb360470..0dcef36b5 100644 --- a/port/posix-h4/btstack_config.h +++ b/port/posix-h4/btstack_config.h @@ -18,6 +18,7 @@ #define ENABLE_LE_CENTRAL #define ENABLE_LE_PERIPHERAL #define ENABLE_LE_SECURE_CONNECTIONS +#define ENABLE_LE_DATA_LENGTH_EXTENSION #define ENABLE_LOG_ERROR #define ENABLE_LOG_INFO #define ENABLE_SCO_OVER_HCI diff --git a/port/posix-h5-bcm/btstack_config.h b/port/posix-h5-bcm/btstack_config.h index 82cfd7f5c..2fcbd1e1b 100644 --- a/port/posix-h5-bcm/btstack_config.h +++ b/port/posix-h5-bcm/btstack_config.h @@ -18,6 +18,7 @@ #define ENABLE_LE_CENTRAL #define ENABLE_LE_PERIPHERAL #define ENABLE_LE_SECURE_CONNECTIONS +#define ENABLE_LE_DATA_LENGTH_EXTENSION #define ENABLE_LOG_ERROR #define ENABLE_LOG_INFO #define ENABLE_SCO_OVER_HCI diff --git a/port/posix-h5/btstack_config.h b/port/posix-h5/btstack_config.h index 82cfd7f5c..2fcbd1e1b 100644 --- a/port/posix-h5/btstack_config.h +++ b/port/posix-h5/btstack_config.h @@ -18,6 +18,7 @@ #define ENABLE_LE_CENTRAL #define ENABLE_LE_PERIPHERAL #define ENABLE_LE_SECURE_CONNECTIONS +#define ENABLE_LE_DATA_LENGTH_EXTENSION #define ENABLE_LOG_ERROR #define ENABLE_LOG_INFO #define ENABLE_SCO_OVER_HCI diff --git a/port/stm32-l053r8-em9304/btstack_config.h b/port/stm32-l053r8-em9304/btstack_config.h index 80ec61a37..20183e14d 100644 --- a/port/stm32-l053r8-em9304/btstack_config.h +++ b/port/stm32-l053r8-em9304/btstack_config.h @@ -12,6 +12,7 @@ #define ENABLE_BLE #define ENABLE_LE_PERIPHERAL #define ENABLE_LE_CENTRAL +#define ENABLE_LE_DATA_LENGTH_EXTENSION #define ENABLE_LOG_INFO #define ENABLE_LOG_ERROR diff --git a/port/wiced-h4/btstack_config.h b/port/wiced-h4/btstack_config.h index 205b5bd39..0f55dd0e0 100644 --- a/port/wiced-h4/btstack_config.h +++ b/port/wiced-h4/btstack_config.h @@ -15,6 +15,7 @@ #define ENABLE_LE_PERIPHERAL #define ENABLE_LE_CENTRAL #define ENABLE_LE_SECURE_CONNECTIONS +#define ENABLE_LE_DATA_LENGTH_EXTENSION #define ENABLE_LOG_ERROR #define ENABLE_LOG_INFO diff --git a/port/wiced-h5/btstack_config.h b/port/wiced-h5/btstack_config.h index 7c3da1383..e61461bd3 100644 --- a/port/wiced-h5/btstack_config.h +++ b/port/wiced-h5/btstack_config.h @@ -16,6 +16,7 @@ #define ENABLE_LE_PERIPHERAL #define ENABLE_LE_CENTRAL #define ENABLE_LE_SECURE_CONNECTIONS +#define ENABLE_LE_DATA_LENGTH_EXTENSION #define ENABLE_LOG_ERROR #define ENABLE_LOG_INFO // #define ENABLE_LOG_DEBUG diff --git a/port/windows-h4/btstack_config.h b/port/windows-h4/btstack_config.h index b9e43d175..ec4455e5f 100644 --- a/port/windows-h4/btstack_config.h +++ b/port/windows-h4/btstack_config.h @@ -18,6 +18,7 @@ #define ENABLE_LE_CENTRAL #define ENABLE_LE_PERIPHERAL #define ENABLE_LE_SECURE_CONNECTIONS +#define ENABLE_LE_DATA_LENGTH_EXTENSION #define ENABLE_LOG_ERROR #define ENABLE_LOG_INFO #define ENABLE_SCO_OVER_HCI diff --git a/port/windows-winusb/btstack_config.h b/port/windows-winusb/btstack_config.h index f026e5f58..d3a450e9d 100644 --- a/port/windows-winusb/btstack_config.h +++ b/port/windows-winusb/btstack_config.h @@ -18,6 +18,7 @@ #define ENABLE_LE_CENTRAL #define ENABLE_LE_PERIPHERAL #define ENABLE_LE_SECURE_CONNECTIONS +#define ENABLE_LE_DATA_LENGTH_EXTENSION #define ENABLE_LOG_ERROR #define ENABLE_LOG_INFO #define ENABLE_SCO_OVER_HCI diff --git a/src/hci.c b/src/hci.c index 095f07c16..77305659e 100644 --- a/src/hci.c +++ b/src/hci.c @@ -1297,15 +1297,19 @@ static void hci_initializing_run(void){ hci_stack->substate = HCI_INIT_W4_WRITE_LE_HOST_SUPPORTED; hci_send_cmd(&hci_write_le_host_supported, 1, 0); break; +#endif + +#ifdef ENABLE_LE_DATA_LENGTH_EXTENSION case HCI_INIT_LE_READ_MAX_DATA_LENGTH: hci_stack->substate = HCI_INIT_W4_LE_READ_MAX_DATA_LENGTH; hci_send_cmd(&hci_le_read_maximum_data_length); break; case HCI_INIT_LE_WRITE_SUGGESTED_DATA_LENGTH: hci_stack->substate = HCI_INIT_W4_LE_WRITE_SUGGESTED_DATA_LENGTH; - // TODO: use values from read max data length - hci_send_cmd(&hci_le_write_suggested_default_data_length, 251, 2120); + hci_send_cmd(&hci_le_write_suggested_default_data_length, hci_stack->le_supported_max_tx_octets, hci_stack->le_supported_max_tx_time); break; +#endif + #ifdef ENABLE_LE_CENTRAL case HCI_INIT_READ_WHITE_LIST_SIZE: hci_stack->substate = HCI_INIT_W4_READ_WHITE_LIST_SIZE; @@ -1316,7 +1320,6 @@ static void hci_initializing_run(void){ hci_stack->substate = HCI_INIT_W4_LE_SET_SCAN_PARAMETERS; hci_send_cmd(&hci_le_set_scan_parameters, 1, 0x1e0, 0x30, hci_stack->le_own_addr_type, 0); break; -#endif #endif default: return; @@ -1558,13 +1561,25 @@ static void hci_initializing_event_handler(uint8_t * packet, uint16_t size){ case HCI_INIT_W4_LE_READ_BUFFER_SIZE: // skip write le host if not supported (e.g. on LE only EM9301) if (hci_stack->local_supported_commands[0] & 0x02) break; + // explicit fall through to reduce repetitions + +#ifdef ENABLE_LE_DATA_LENGTH_EXTENSION + case HCI_INIT_W4_WRITE_LE_HOST_SUPPORTED: + if ((hci_stack->local_supported_commands[0] & 0x30) == 0x30){ + hci_stack->substate = HCI_INIT_LE_READ_MAX_DATA_LENGTH; + return; + } + // explicit fall through to reduce repetitions +#endif + #ifdef ENABLE_LE_CENTRAL - hci_stack->substate = HCI_INIT_LE_READ_MAX_DATA_LENGTH; + hci_stack->substate = HCI_INIT_READ_WHITE_LIST_SIZE; #else hci_init_done(); #endif return; #endif + case HCI_INIT_W4_WRITE_LOCAL_NAME: // skip write eir data if no eir data set if (hci_stack->eir_data) break; @@ -1684,17 +1699,19 @@ static void event_handler(uint8_t *packet, int size){ } log_info("hci_le_read_buffer_size: size %u, count %u", hci_stack->le_data_packets_length, hci_stack->le_acl_packets_total_num); } +#endif +#ifdef ENABLE_LE_DATA_LENGTH_EXTENSION if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_le_read_maximum_data_length)){ hci_stack->le_supported_max_tx_octets = little_endian_read_16(packet, 6); hci_stack->le_supported_max_tx_time = little_endian_read_16(packet, 8); log_info("hci_le_read_maximum_data_length: tx octets %u, tx time %u us", hci_stack->le_supported_max_tx_octets, hci_stack->le_supported_max_tx_time); } +#endif #ifdef ENABLE_LE_CENTRAL if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_le_read_white_list_size)){ hci_stack->le_whitelist_capacity = packet[6]; log_info("hci_le_read_white_list_size: size %u", hci_stack->le_whitelist_capacity); } -#endif #endif if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_bd_addr)) { reverse_bd_addr(&packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE + 1], diff --git a/src/hci.h b/src/hci.h index 5bc9bbdb0..5dc6b738e 100644 --- a/src/hci.h +++ b/src/hci.h @@ -598,6 +598,9 @@ typedef enum hci_init_state{ HCI_INIT_W4_LE_READ_BUFFER_SIZE, HCI_INIT_WRITE_LE_HOST_SUPPORTED, HCI_INIT_W4_WRITE_LE_HOST_SUPPORTED, +#endif + +#ifdef ENABLE_LE_DATA_LENGTH_EXTENSION HCI_INIT_LE_READ_MAX_DATA_LENGTH, HCI_INIT_W4_LE_READ_MAX_DATA_LENGTH, HCI_INIT_LE_WRITE_SUGGESTED_DATA_LENGTH, @@ -820,9 +823,11 @@ typedef struct { bd_addr_t le_advertisements_direct_address; #endif +#ifdef ENABLE_LE_DATA_LENGTH_EXTENSION // LE Data Length uint16_t le_supported_max_tx_octets; uint16_t le_supported_max_tx_time; +#endif // custom BD ADDR bd_addr_t custom_bd_addr;