Skip to content

Commit d70b360

Browse files
author
Rohit Grover
committed
Add the packet characteristic to the DFU Service.
This helps mimic the layout of the actual DFU service in the dfu-bootloader. Without this, some FOTA clients might get confused as service definitions change after handing control over to the bootloader.
1 parent b13f6f3 commit d70b360

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

services/DFUService.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const uint8_t DFUServiceBaseUUID[] = {
2222
};
2323
const uint16_t DFUServiceShortUUID = 0x1530;
2424
const uint16_t DFUServiceControlCharacteristicShortUUID = 0x1531;
25+
const uint16_t DFUServicePacketCharacteristicShortUUID = 0x1532;
2526

2627
const uint8_t DFUServiceUUID[] = {
2728
0x00, 0x00, (uint8_t)(DFUServiceShortUUID >> 8), (uint8_t)(DFUServiceShortUUID & 0xFF), 0x12, 0x12, 0xEF, 0xDE,
@@ -31,5 +32,9 @@ const uint8_t DFUServiceControlCharacteristicUUID[] = {
3132
0x00, 0x00, (uint8_t)(DFUServiceControlCharacteristicShortUUID >> 8), (uint8_t)(DFUServiceControlCharacteristicShortUUID & 0xFF), 0x12, 0x12, 0xEF, 0xDE,
3233
0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23,
3334
};
35+
const uint8_t DFUServicePacketCharacteristicUUID[] = {
36+
0x00, 0x00, (uint8_t)(DFUServicePacketCharacteristicShortUUID >> 8), (uint8_t)(DFUServicePacketCharacteristicShortUUID & 0xFF), 0x12, 0x12, 0xEF, 0xDE,
37+
0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23,
38+
};
3439

3540
DFUService::ResetPrepare_t DFUService::handoverCallback = NULL;

services/DFUService.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ extern const uint16_t DFUServiceControlCharacteristicShortUUID;
2828

2929
extern const uint8_t DFUServiceUUID[];
3030
extern const uint8_t DFUServiceControlCharacteristicUUID[];
31+
extern const uint8_t DFUServicePacketCharacteristicUUID[];
3132

3233
class DFUService {
3334
public:
3435
/**
3536
* Signature for the handover callback. The application may provide such a
3637
* callback when setting up the DFU service, in which case it will be
37-
* invoked before handing control over to the Bootloader.
38+
* invoked before handing control over to the bootloader.
3839
*/
3940
typedef void (*ResetPrepare_t)(void);
4041

@@ -43,13 +44,15 @@ class DFUService {
4344
ble(_ble),
4445
controlBytes(),
4546
controlPoint(DFUServiceControlCharacteristicUUID, controlBytes, SIZEOF_CONTROL_BYTES, SIZEOF_CONTROL_BYTES,
46-
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) {
47+
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
48+
packet(DFUServicePacketCharacteristicUUID, packetBytes, SIZEOF_PACKET_BYTES, SIZEOF_PACKET_BYTES,
49+
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE) {
4750
static bool serviceAdded = false; /* We should only ever need to add the DFU service once. */
4851
if (serviceAdded) {
4952
return;
5053
}
5154

52-
GattCharacteristic *dfuChars[] = {&controlPoint};
55+
GattCharacteristic *dfuChars[] = {&controlPoint, &packet};
5356
GattService dfuService(DFUServiceUUID, dfuChars, sizeof(dfuChars) / sizeof(GattCharacteristic *));
5457

5558
ble.addService(dfuService);
@@ -70,6 +73,7 @@ class DFUService {
7073
*/
7174
virtual void onDataWritten(const GattCharacteristicWriteCBParams *params) {
7275
if (params->charHandle == controlPoint.getValueAttribute().getHandle()) {
76+
/* At present, writing anything will do the trick--this needs to be improved. */
7377
if (handoverCallback) {
7478
handoverCallback();
7579
}
@@ -80,13 +84,26 @@ class DFUService {
8084

8185
private:
8286
static const unsigned SIZEOF_CONTROL_BYTES = 2;
87+
static const unsigned SIZEOF_PACKET_BYTES = 20;
8388

8489
static ResetPrepare_t handoverCallback; /**< application specific handover callback. */
8590

8691
private:
8792
BLEDevice &ble;
8893
uint8_t controlBytes[SIZEOF_CONTROL_BYTES];
94+
uint8_t packetBytes[SIZEOF_PACKET_BYTES];
95+
96+
/**< Writing to the control characteristic triggers the handover to dfu-
97+
* bootloader. At present, writing anything will do the trick--this needs
98+
* to be improved. */
8999
GattCharacteristic controlPoint;
100+
101+
/**< The packet characteristic in this service doesn't do anything meaningful, but
102+
* is only a placeholder to mimic the corresponding characteristic in the
103+
* actual DFU service implemented by the bootloader. Without this, some
104+
* FOTA clients might get confused as service definitions change after
105+
* handing control over to the bootloader. */
106+
GattCharacteristic packet;
90107
};
91108

92109
#endif /* #ifndef __BLE_DFU_SERVICE_H__*/

0 commit comments

Comments
 (0)