Skip to content

Commit 9bbc8c9

Browse files
authored
Merge pull request #14506 from noonfom/value-handle
Add GattUpdatesEnabledCallbackParams struct
2 parents 622e2b3 + 52483f3 commit 9bbc8c9

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

connectivity/FEATURE_BLE/include/ble/gatt/GattCallbackParamTypes.h

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,33 @@ struct GattDataSentCallbackParams {
443443

444444
};
445445

446-
using GattUpdatesEnabledCallbackParams = GattDataSentCallbackParams;
447-
using GattUpdatesDisabledCallbackParams = GattDataSentCallbackParams;
448-
using GattConfirmationReceivedCallbackParams = GattDataSentCallbackParams;
446+
/**
447+
* Gatt Updates Changed Attribute related events
448+
*
449+
* Used by `onUpdatesEnabled` and 'onUpdatesDisabled'
450+
*/
451+
struct GattUpdatesChangedCallbackParams {
452+
453+
/**
454+
* The handle of the connection that triggered the event.
455+
*/
456+
ble::connection_handle_t connHandle;
457+
458+
/**
459+
* The handle of the CCCD producing the event
460+
*/
461+
GattAttribute::Handle_t attHandle;
462+
463+
/**
464+
* The value handle of the characteristic containing the CCCD
465+
*/
466+
GattAttribute::Handle_t charHandle;
467+
468+
};
469+
470+
using GattUpdatesEnabledCallbackParams = GattUpdatesChangedCallbackParams;
471+
using GattUpdatesDisabledCallbackParams = GattUpdatesChangedCallbackParams;
472+
using GattConfirmationReceivedCallbackParams = GattDataSentCallbackParams;
449473

450474
namespace ble {
451475

connectivity/FEATURE_BLE/source/cordio/source/GattServerImpl.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,15 @@ bool GattServer::get_cccd_index_by_value_handle(GattAttribute::Handle_t char_han
15421542
return false;
15431543
}
15441544

1545+
bool GattServer::get_value_handle_by_cccd_handle(GattAttribute::Handle_t cccd_handle, GattAttribute::Handle_t &char_handle) const {
1546+
uint8_t idx;
1547+
if (!get_cccd_index_by_cccd_handle(cccd_handle, idx)) {
1548+
return false;
1549+
}
1550+
char_handle = cccd_handles[idx];
1551+
return true;
1552+
}
1553+
15451554
bool GattServer::is_update_authorized(
15461555
connection_handle_t connection,
15471556
GattAttribute::Handle_t value_handle
@@ -1720,13 +1729,18 @@ void GattServer::handleEvent(
17201729
GattAttribute::Handle_t attributeHandle
17211730
)
17221731
{
1732+
// To be used in cases where the characteristic value handle differs from the attribute handle
1733+
GattAttribute::Handle_t charHandle;
1734+
17231735
switch (type) {
17241736
case GattServerEvents::GATT_EVENT_UPDATES_ENABLED:
17251737
tr_info("Updates enabled for attribute %d on connection %d", attributeHandle, connHandle);
1738+
MBED_ASSERT(get_value_handle_by_cccd_handle(attributeHandle, charHandle));
17261739
if(eventHandler) {
17271740
GattUpdatesEnabledCallbackParams params({
17281741
.connHandle = connHandle,
1729-
.attHandle = attributeHandle
1742+
.attHandle = attributeHandle,
1743+
.charHandle = charHandle
17301744
});
17311745
eventHandler->onUpdatesEnabled(params);
17321746
}
@@ -1738,10 +1752,12 @@ void GattServer::handleEvent(
17381752
break;
17391753
case GattServerEvents::GATT_EVENT_UPDATES_DISABLED:
17401754
tr_info("Updates disabled for attribute %d on connection %d", attributeHandle, connHandle);
1755+
MBED_ASSERT(get_value_handle_by_cccd_handle(attributeHandle, charHandle));
17411756
if(eventHandler) {
17421757
GattUpdatesDisabledCallbackParams params({
17431758
.connHandle = connHandle,
1744-
.attHandle = attributeHandle
1759+
.attHandle = attributeHandle,
1760+
.charHandle = charHandle
17451761
});
17461762
eventHandler->onUpdatesDisabled(params);
17471763
}

connectivity/FEATURE_BLE/source/cordio/source/GattServerImpl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ class GattServer : public PalSigningMonitor {
293293

294294
bool get_cccd_index_by_value_handle(GattAttribute::Handle_t char_handle, uint8_t &idx) const;
295295

296+
bool get_value_handle_by_cccd_handle(GattAttribute::Handle_t cccd_handle, GattAttribute::Handle_t &char_handle) const;
297+
296298
bool is_update_authorized(connection_handle_t connection, GattAttribute::Handle_t value_handle);
297299

298300
struct alloc_block_t {

0 commit comments

Comments
 (0)