Skip to content

Commit 58c6257

Browse files
committed
added define guard on hci set data length implementation
1 parent 0490ea3 commit 58c6257

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ STM32Cube_WPAN has several configuration options, which are set in the `app_conf
2121
This package has a default configuration named `app_conf_default.h`.
2222
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.
2323

24+
## HCI data length
25+
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.
26+
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.
27+
**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!**
28+
Please see
29+
2430
## License
2531

2632
```

src/utility/ATT.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,11 @@ void ATTClass::addConnection(uint16_t handle, uint8_t role, uint8_t peerBdaddrTy
257257
_eventHandlers[BLEConnected](BLEDevice(peerBdaddrType, peerBdaddr));
258258
}
259259
// TODO (krm) increase speed!
260-
HCI.hciSetDataLength(handle, 251, 2120);
260+
#ifdef CFG_BLE_ENABLE_SET_DATA_LENGTH
261+
#if CFG_BLE_ENABLE_SET_DATA_LENGTH < 252 && CFG_BLE_ENABLE_SET_DATA_LENGTH > 26
262+
HCI.hciSetDataLength(handle, CFG_BLE_ENABLE_SET_DATA_LENGTH, 2120);
263+
#endif // CFG_BLE_ENABLE_SET_DATA_LENGTH < 252 && CFG_BLE_ENABLE_SET_DATA_LENGTH > 26
264+
#endif // CFG_BLE_ENABLE_SET_DATA_LENGTH
261265
}
262266

263267
void ATTClass::handleData(uint16_t connectionHandle, uint8_t dlen, uint8_t data[])

src/utility/HCI.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ void HCIClass::setTransport(HCITransportInterface *HCITransport)
672672
_HCITransport = HCITransport;
673673
}
674674

675+
#ifdef CFG_BLE_ENABLE_SET_DATA_LENGTH
675676
int HCIClass::hciSetDataLength(uint16_t connectionHandle, uint16_t txOctects, uint16_t txTime){
676677
const uint8_t payload_len = 6;
677678
const uint16_t opcode = 0x2022;
@@ -685,6 +686,7 @@ int HCIClass::hciSetDataLength(uint16_t connectionHandle, uint16_t txOctects, ui
685686

686687
return sendCommand(opcode, payload_len, cmd_buffer);
687688
}
689+
#endif // CFG_BLE_ENABLE_SET_DATA_LENGTH
688690

689691
#if !defined(FAKE_HCI)
690692
HCIClass HCIObj;

src/utility/HCI.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#include <Arduino.h>
2424
#include "HCITransport.h"
2525

26+
#if __has_include("app_conf_custom.h")
27+
#include "app_conf_custom.h"
28+
#endif
29+
2630
#define BLE_CMD_MAX_PARAM_LEN 255
2731

2832
struct hci_le_set_data_length_cp0{
@@ -82,6 +86,7 @@ class HCIClass {
8286

8387
void setTransport(HCITransportInterface *HCITransport);
8488

89+
#ifdef CFG_BLE_ENABLE_SET_DATA_LENGTH
8590
//-----------------------------
8691
// @brief
8792
// @param connectionHandle Connection_Handle Connection handle for which the command applies.
@@ -96,6 +101,7 @@ class HCIClass {
96101
// Values: 0x0148 ... 0x4290
97102
// @return Value indicating success or error code.
98103
int hciSetDataLength(uint16_t connectionHandle, uint16_t txOctects, uint16_t txTime);
104+
#endif // CFG_BLE_ENABLE_SET_DATA_LENGTH
99105

100106
private:
101107
virtual int sendCommand(uint16_t opcode, uint8_t plen = 0, void* parameters = NULL);

0 commit comments

Comments
 (0)