Merge pull request #14506 from noonfom/value-handle

Add GattUpdatesEnabledCallbackParams struct
pull/14524/head
Martin Kojtal 2021-04-08 09:53:04 +02:00 committed by GitHub
commit 9bbc8c914c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 5 deletions

View File

@ -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 {

View File

@ -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
@ -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);
}
@ -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);
}

View File

@ -293,6 +293,8 @@ private:
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 {