From 0490ea33ff86d926f83d07ee28fb100b51ad922c Mon Sep 17 00:00:00 2001 From: KMeldgaard Date: Wed, 24 Nov 2021 16:11:46 +0100 Subject: [PATCH 1/4] added set_data_length --- src/utility/ATT.cpp | 2 ++ src/utility/HCI.cpp | 14 ++++++++++++++ src/utility/HCI.h | 23 +++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index 6c502068..3bfb76e6 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -256,6 +256,8 @@ void ATTClass::addConnection(uint16_t handle, uint8_t role, uint8_t peerBdaddrTy if (_eventHandlers[BLEConnected]) { _eventHandlers[BLEConnected](BLEDevice(peerBdaddrType, peerBdaddr)); } + // TODO (krm) increase speed! + HCI.hciSetDataLength(handle, 251, 2120); } void ATTClass::handleData(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]) diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index 96b42537..86a77b31 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -672,6 +672,20 @@ void HCIClass::setTransport(HCITransportInterface *HCITransport) _HCITransport = HCITransport; } +int HCIClass::hciSetDataLength(uint16_t connectionHandle, uint16_t txOctects, uint16_t txTime){ + const uint8_t payload_len = 6; + const uint16_t opcode = 0x2022; + uint8_t cmd_buffer[BLE_CMD_MAX_PARAM_LEN]; + hci_le_set_data_length_cp0 *cp0 = (hci_le_set_data_length_cp0*)(cmd_buffer); + + // create payload + cp0->Connection_Handle = connectionHandle; + cp0->TxOctets = txOctects; + cp0->TxTime = txTime; + + return sendCommand(opcode, payload_len, cmd_buffer); +} + #if !defined(FAKE_HCI) HCIClass HCIObj; HCIClass& HCI = HCIObj; diff --git a/src/utility/HCI.h b/src/utility/HCI.h index 0efd8125..72bab320 100644 --- a/src/utility/HCI.h +++ b/src/utility/HCI.h @@ -23,6 +23,14 @@ #include #include "HCITransport.h" +#define BLE_CMD_MAX_PARAM_LEN 255 + +struct hci_le_set_data_length_cp0{ + uint16_t Connection_Handle; + uint16_t TxOctets; + uint16_t TxTime; +}; + class HCIClass { public: HCIClass(); @@ -74,6 +82,21 @@ class HCIClass { void setTransport(HCITransportInterface *HCITransport); + //----------------------------- + // @brief + // @param connectionHandle Connection_Handle Connection handle for which the command applies. + // Values: 0x0000 ... 0x0EFF + // @param txOctects TxOctets Preferred maximum number of payload octets that the local + // Controller should include in a single Link Layer packet on this + // connection. + // Values: 0x001B ... 0x00FB + // @param txTime TxTime Preferred maximum number of microseconds that the local + // Controller should use to transmit a single Link Layer packet on this + // connection. + // Values: 0x0148 ... 0x4290 + // @return Value indicating success or error code. + int hciSetDataLength(uint16_t connectionHandle, uint16_t txOctects, uint16_t txTime); + private: virtual int sendCommand(uint16_t opcode, uint8_t plen = 0, void* parameters = NULL); From 58c62579961223036cd3ba445ecf0064a6b1ea2c Mon Sep 17 00:00:00 2001 From: KMeldgaard Date: Thu, 25 Nov 2021 09:34:25 +0100 Subject: [PATCH 2/4] added define guard on hci set data length implementation --- README.md | 6 ++++++ src/utility/ATT.cpp | 6 +++++- src/utility/HCI.cpp | 2 ++ src/utility/HCI.h | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b2d48b13..20219efd 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,12 @@ STM32Cube_WPAN has several configuration options, which are set in the `app_conf This package has a default configuration named `app_conf_default.h`. The user can include the file `app_conf_custom.h` to customize the ble application. Options wrapped in `#ifndef, #endif` in `app_conf_default.h` can be overwritten. Additional options can be added. +## HCI data length +By default the data length (max payload per BLE packet) is set to 27 bytes. This can cause fragmentation when tranmitting large characteristics using a large ATT_MTU. +To increase the data length user must define `CFG_BLE_ENABLE_SET_DATA_LENGTH` (in `app_conf_default.h`). Further more, the wanted data length must bbe set in same define - eg: `#define CFG_BLE_ENABLE_SET_DATA_LENGTH 251`. Valid range: 27 --> 251. +**Note: if this is enabled the pheripheral will attempt to increase the HCI data length with every connected device! There is no guarantee all BLE devices support all sizes!** +Please see + ## License ``` diff --git a/src/utility/ATT.cpp b/src/utility/ATT.cpp index 3bfb76e6..05ecf0f8 100644 --- a/src/utility/ATT.cpp +++ b/src/utility/ATT.cpp @@ -257,7 +257,11 @@ void ATTClass::addConnection(uint16_t handle, uint8_t role, uint8_t peerBdaddrTy _eventHandlers[BLEConnected](BLEDevice(peerBdaddrType, peerBdaddr)); } // TODO (krm) increase speed! - HCI.hciSetDataLength(handle, 251, 2120); + #ifdef CFG_BLE_ENABLE_SET_DATA_LENGTH + #if CFG_BLE_ENABLE_SET_DATA_LENGTH < 252 && CFG_BLE_ENABLE_SET_DATA_LENGTH > 26 + HCI.hciSetDataLength(handle, CFG_BLE_ENABLE_SET_DATA_LENGTH, 2120); + #endif // CFG_BLE_ENABLE_SET_DATA_LENGTH < 252 && CFG_BLE_ENABLE_SET_DATA_LENGTH > 26 + #endif // CFG_BLE_ENABLE_SET_DATA_LENGTH } void ATTClass::handleData(uint16_t connectionHandle, uint8_t dlen, uint8_t data[]) diff --git a/src/utility/HCI.cpp b/src/utility/HCI.cpp index 86a77b31..6f9c9737 100644 --- a/src/utility/HCI.cpp +++ b/src/utility/HCI.cpp @@ -672,6 +672,7 @@ void HCIClass::setTransport(HCITransportInterface *HCITransport) _HCITransport = HCITransport; } +#ifdef CFG_BLE_ENABLE_SET_DATA_LENGTH int HCIClass::hciSetDataLength(uint16_t connectionHandle, uint16_t txOctects, uint16_t txTime){ const uint8_t payload_len = 6; const uint16_t opcode = 0x2022; @@ -685,6 +686,7 @@ int HCIClass::hciSetDataLength(uint16_t connectionHandle, uint16_t txOctects, ui return sendCommand(opcode, payload_len, cmd_buffer); } +#endif // CFG_BLE_ENABLE_SET_DATA_LENGTH #if !defined(FAKE_HCI) HCIClass HCIObj; diff --git a/src/utility/HCI.h b/src/utility/HCI.h index 72bab320..034950f8 100644 --- a/src/utility/HCI.h +++ b/src/utility/HCI.h @@ -23,6 +23,10 @@ #include #include "HCITransport.h" +#if __has_include("app_conf_custom.h") +#include "app_conf_custom.h" +#endif + #define BLE_CMD_MAX_PARAM_LEN 255 struct hci_le_set_data_length_cp0{ @@ -82,6 +86,7 @@ class HCIClass { void setTransport(HCITransportInterface *HCITransport); + #ifdef CFG_BLE_ENABLE_SET_DATA_LENGTH //----------------------------- // @brief // @param connectionHandle Connection_Handle Connection handle for which the command applies. @@ -96,6 +101,7 @@ class HCIClass { // Values: 0x0148 ... 0x4290 // @return Value indicating success or error code. int hciSetDataLength(uint16_t connectionHandle, uint16_t txOctects, uint16_t txTime); + #endif // CFG_BLE_ENABLE_SET_DATA_LENGTH private: virtual int sendCommand(uint16_t opcode, uint8_t plen = 0, void* parameters = NULL); From d7787a94ca5cf0e881b31246cac522abe53c35b5 Mon Sep 17 00:00:00 2001 From: KMeldgaard Date: Thu, 25 Nov 2021 09:39:40 +0100 Subject: [PATCH 3/4] rearranged readme --- README.md | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 20219efd..63299586 100644 --- a/README.md +++ b/README.md @@ -15,18 +15,6 @@ https://github.com/stm32duino/wiki/wiki/STM32duinoBLE#stm32duinoble-with-x-nucle For more information about ArduinoBLE library please visit the official web page at: https://github.com/arduino-libraries/ArduinoBLE - -# Configuration -STM32Cube_WPAN has several configuration options, which are set in the `app_conf.h`. -This package has a default configuration named `app_conf_default.h`. -The user can include the file `app_conf_custom.h` to customize the ble application. Options wrapped in `#ifndef, #endif` in `app_conf_default.h` can be overwritten. Additional options can be added. - -## HCI data length -By default the data length (max payload per BLE packet) is set to 27 bytes. This can cause fragmentation when tranmitting large characteristics using a large ATT_MTU. -To increase the data length user must define `CFG_BLE_ENABLE_SET_DATA_LENGTH` (in `app_conf_default.h`). Further more, the wanted data length must bbe set in same define - eg: `#define CFG_BLE_ENABLE_SET_DATA_LENGTH 251`. Valid range: 27 --> 251. -**Note: if this is enabled the pheripheral will attempt to increase the HCI data length with every connected device! There is no guarantee all BLE devices support all sizes!** -Please see - ## License ``` @@ -47,3 +35,12 @@ You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ``` + +# Configuration +STM32Cube_WPAN has several configuration options, which are set in the `app_conf.h`. +This package has a default configuration named `app_conf_default.h`. +The user can include the file `app_conf_custom.h` to customize the ble application. Options wrapped in `#ifndef, #endif` in `app_conf_default.h` can be overwritten. Additional options can be added. +## HCI data length +By default the data length (max payload per BLE packet) is set to 27 bytes. This can cause fragmentation when tranmitting large characteristics using a large ATT_MTU. +To increase the data length user must define `CFG_BLE_ENABLE_SET_DATA_LENGTH` (in `app_conf_default.h`). Further more, the wanted data length must bbe set in same define - eg: `#define CFG_BLE_ENABLE_SET_DATA_LENGTH 251`. Valid range: 27 --> 251. +**Note: if this is enabled the pheripheral will attempt to increase the HCI data length with every connected device! There is no guarantee all BLE devices support all sizes!** From 78b918cb5d799b73935cbfc6c62bd3c3d938096c Mon Sep 17 00:00:00 2001 From: KMeldgaard Date: Thu, 25 Nov 2021 09:48:26 +0100 Subject: [PATCH 4/4] spell check fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 63299586..938897c5 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,6 @@ STM32Cube_WPAN has several configuration options, which are set in the `app_conf This package has a default configuration named `app_conf_default.h`. The user can include the file `app_conf_custom.h` to customize the ble application. Options wrapped in `#ifndef, #endif` in `app_conf_default.h` can be overwritten. Additional options can be added. ## HCI data length -By default the data length (max payload per BLE packet) is set to 27 bytes. This can cause fragmentation when tranmitting large characteristics using a large ATT_MTU. +By default the data length (max payload per BLE packet) is set to 27 bytes. This can cause fragmentation when transmitting large characteristics using a large ATT_MTU. To increase the data length user must define `CFG_BLE_ENABLE_SET_DATA_LENGTH` (in `app_conf_default.h`). Further more, the wanted data length must bbe set in same define - eg: `#define CFG_BLE_ENABLE_SET_DATA_LENGTH 251`. Valid range: 27 --> 251. **Note: if this is enabled the pheripheral will attempt to increase the HCI data length with every connected device! There is no guarantee all BLE devices support all sizes!**