Skip to content

Commit cb52e56

Browse files
authored
Fixes BLE Server descriptor update (espressif#6919)
Description of Change This PR fixes an issue related to BLE Server and Descriptors. The issue: If the BLE Server code changes its own descriptors, it is not reflected in the GATTS database. BLE2902 CCCD also didn't reflect any changes to the GATTS database. Because of this issue, the client could never read the real Descriptor values from the remote Server. Tests scenarios Tested with ESP32. Related links Fixes espressif#6863 Fixes espressif#6868
1 parent 4a341c9 commit cb52e56

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

libraries/BLE/src/BLE2902.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ void BLE2902::setIndications(bool flag) {
4646
uint8_t *pValue = getValue();
4747
if (flag) pValue[0] |= 1 << 1;
4848
else pValue[0] &= ~(1 << 1);
49+
setValue(pValue, 2);
4950
} // setIndications
5051

5152

@@ -57,6 +58,7 @@ void BLE2902::setNotifications(bool flag) {
5758
uint8_t *pValue = getValue();
5859
if (flag) pValue[0] |= 1 << 0;
5960
else pValue[0] &= ~(1 << 0);
61+
setValue(pValue, 2);
6062
} // setNotifications
6163

6264
#endif

libraries/BLE/src/BLEDescriptor.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ BLEDescriptor::BLEDescriptor(const char* uuid, uint16_t len) : BLEDescriptor(BLE
3232
BLEDescriptor::BLEDescriptor(BLEUUID uuid, uint16_t max_len) {
3333
m_bleUUID = uuid;
3434
m_value.attr_len = 0; // Initial length is 0.
35-
m_value.attr_max_len = max_len; // Maximum length of the data.
35+
m_value.attr_max_len = max_len; // Maximum length of the data.
3636
m_handle = NULL_HANDLE; // Handle is initially unknown.
3737
m_pCharacteristic = nullptr; // No initial characteristic.
3838
m_pCallback = nullptr; // No initial callback.
@@ -235,6 +235,10 @@ void BLEDescriptor::setValue(uint8_t* data, size_t length) {
235235
}
236236
m_value.attr_len = length;
237237
memcpy(m_value.attr_value, data, length);
238+
if (m_handle != NULL_HANDLE) {
239+
esp_ble_gatts_set_attr_value(m_handle, length, (const uint8_t *)data);
240+
log_d("Set the value in the GATTS database using handle 0x%x", m_handle);
241+
}
238242
} // setValue
239243

240244

libraries/BLE/src/BLEDescriptor.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class BLEDescriptor {
5151
uint16_t m_handle;
5252
BLEDescriptorCallbacks* m_pCallback;
5353
BLECharacteristic* m_pCharacteristic;
54-
esp_gatt_perm_t m_permissions = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE;
54+
esp_gatt_perm_t m_permissions = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE;
5555
FreeRTOS::Semaphore m_semaphoreCreateEvt = FreeRTOS::Semaphore("CreateEvt");
5656
esp_attr_value_t m_value;
5757

0 commit comments

Comments
 (0)