Skip to content

Add GattUpdatesEnabledCallbackParams struct #14506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions connectivity/FEATURE_BLE/include/ble/gatt/GattCallbackParamTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,33 @@ struct GattDataSentCallbackParams {

};

using GattUpdatesEnabledCallbackParams = GattDataSentCallbackParams;
using GattUpdatesDisabledCallbackParams = GattDataSentCallbackParams;
using GattConfirmationReceivedCallbackParams = GattDataSentCallbackParams;
/**
* Gatt Updates Changed Attribute related events
*
* Used by `onUpdatesEnabled` and 'onUpdatesDisabled'
*/
struct GattUpdatesChangedCallbackParams {

/**
* The handle of the connection that triggered the event.
*/
ble::connection_handle_t connHandle;

/**
* The handle of the CCCD producing the event
*/
GattAttribute::Handle_t attHandle;

/**
* The value handle of the characteristic containing the CCCD
*/
GattAttribute::Handle_t charHandle;

};

using GattUpdatesEnabledCallbackParams = GattUpdatesChangedCallbackParams;
using GattUpdatesDisabledCallbackParams = GattUpdatesChangedCallbackParams;
using GattConfirmationReceivedCallbackParams = GattDataSentCallbackParams;

namespace ble {

Expand Down
20 changes: 18 additions & 2 deletions connectivity/FEATURE_BLE/source/cordio/source/GattServerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,15 @@ bool GattServer::get_cccd_index_by_value_handle(GattAttribute::Handle_t char_han
return false;
}

bool GattServer::get_value_handle_by_cccd_handle(GattAttribute::Handle_t cccd_handle, GattAttribute::Handle_t &char_handle) const {
uint8_t idx;
if (!get_cccd_index_by_cccd_handle(cccd_handle, idx)) {
return false;
}
char_handle = cccd_handles[idx];
return true;
}

bool GattServer::is_update_authorized(
connection_handle_t connection,
GattAttribute::Handle_t value_handle
Expand Down Expand Up @@ -1720,13 +1729,18 @@ void GattServer::handleEvent(
GattAttribute::Handle_t attributeHandle
)
{
// To be used in cases where the characteristic value handle differs from the attribute handle
GattAttribute::Handle_t charHandle;

switch (type) {
case GattServerEvents::GATT_EVENT_UPDATES_ENABLED:
tr_info("Updates enabled for attribute %d on connection %d", attributeHandle, connHandle);
MBED_ASSERT(get_value_handle_by_cccd_handle(attributeHandle, charHandle));
if(eventHandler) {
GattUpdatesEnabledCallbackParams params({
.connHandle = connHandle,
.attHandle = attributeHandle
.attHandle = attributeHandle,
.charHandle = charHandle
});
eventHandler->onUpdatesEnabled(params);
}
Expand All @@ -1738,10 +1752,12 @@ void GattServer::handleEvent(
break;
case GattServerEvents::GATT_EVENT_UPDATES_DISABLED:
tr_info("Updates disabled for attribute %d on connection %d", attributeHandle, connHandle);
MBED_ASSERT(get_value_handle_by_cccd_handle(attributeHandle, charHandle));
if(eventHandler) {
GattUpdatesDisabledCallbackParams params({
.connHandle = connHandle,
.attHandle = attributeHandle
.attHandle = attributeHandle,
.charHandle = charHandle
});
eventHandler->onUpdatesDisabled(params);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ class GattServer : public PalSigningMonitor {

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

bool get_value_handle_by_cccd_handle(GattAttribute::Handle_t cccd_handle, GattAttribute::Handle_t &char_handle) const;

bool is_update_authorized(connection_handle_t connection, GattAttribute::Handle_t value_handle);

struct alloc_block_t {
Expand Down