Skip to content

Commit

Permalink
Merge pull request #10581 from pan-/cordio-tx-path
Browse files Browse the repository at this point in the history
BLE - Management of Tx path on Cordio.
  • Loading branch information
0xc0170 committed May 21, 2019
2 parents 0560ecc + cb97b3c commit 2da7436
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 8 deletions.
6 changes: 6 additions & 0 deletions features/FEATURE_BLE/ble/GattServer.h
Expand Up @@ -693,6 +693,12 @@ class GattServer {
confirmationReceivedCallback(attributeHandle);
}
break;

case GattServerEvents::GATT_EVENT_DATA_SENT:
// Called every time a notification or indication has been sent
handleDataSentEvent(1);
break;

default:
break;
}
Expand Down
9 changes: 9 additions & 0 deletions features/FEATURE_BLE/ble/generic/GenericGattClient.h
Expand Up @@ -147,6 +147,15 @@ class GenericGattClient :
uint16_t att_mtu_size
);

/**
* @see pal::GattClient::EventHandler::on_write_command_sent
*/
void on_write_command_sent_(
ble::connection_handle_t connection_handle,
ble::attribute_handle_t attribute_handle,
uint8_t status
);

private:
struct ProcedureControlBlock;
struct DiscoveryControlBlock;
Expand Down
20 changes: 20 additions & 0 deletions features/FEATURE_BLE/ble/pal/PalGattClient.h
Expand Up @@ -52,6 +52,26 @@ struct GattClientEventHandler : StaticInterface<Impl, GattClientEventHandler> {
) {
impl()->on_att_mtu_change_(connection_handle, att_mtu_size);
}

/**
* Function invoked when a write command has been sent out of the stack
* (either to the controller or over the air).
*
* @param connection_handle Connection targeted by the write command
* @param attribute_handle Attribute written
* @param status HCI status of the operation.
*/
void on_write_command_sent(
ble::connection_handle_t connection_handle,
ble::attribute_handle_t attribute_handle,
uint8_t status
) {
impl()->on_write_command_sent_(
connection_handle,
attribute_handle,
status
);
}
};


Expand Down
19 changes: 19 additions & 0 deletions features/FEATURE_BLE/source/generic/GenericGattClient.tpp
Expand Up @@ -966,6 +966,7 @@ GenericGattClient<TPalGattClient, SigningMonitorEventHandler>::GenericGattClient
_pal_client->when_transaction_timeout(
mbed::callback(this, &GenericGattClient::on_transaction_timeout)
);
_pal_client->set_event_handler(this);
}

template<template<class> class TPalGattClient, class SigningMonitorEventHandler>
Expand Down Expand Up @@ -1338,6 +1339,24 @@ void GenericGattClient<TPalGattClient, SigningMonitorEventHandler>::on_att_mtu_c
}
}

template<template<class> class TPalGattClient, class SigningMonitorEventHandler>
void GenericGattClient<TPalGattClient, SigningMonitorEventHandler>::on_write_command_sent_(
ble::connection_handle_t connection_handle,
ble::attribute_handle_t attribute_handle,
uint8_t status
) {
GattWriteCallbackParams response = {
connection_handle,
attribute_handle,
GattWriteCallbackParams::OP_WRITE_CMD,
BLE_ERROR_NONE,
status
};

this->processWriteResponse(&response);
}


template<template<class> class TPalGattClient, class SigningMonitorEventHandler>
void GenericGattClient<TPalGattClient, SigningMonitorEventHandler>::on_termination(connection_handle_t connection_handle) {
if (_termination_callback) {
Expand Down
Expand Up @@ -695,10 +695,6 @@ ble_error_t GattServer::write_(
}
#endif // BLE_FEATURE_SECURITY

if (updates_sent) {
handleDataSentEvent(updates_sent);
}

return BLE_ERROR_NONE;
}

Expand Down Expand Up @@ -749,10 +745,6 @@ ble_error_t GattServer::write_(
}
#endif // BLE_FEATURE_SECURITY

if (updates_sent) {
handleDataSentEvent(updates_sent);
}

return BLE_ERROR_NONE;
}

Expand Down
Expand Up @@ -32,6 +32,16 @@ void CordioAttClient::att_client_handler(const attEvt_t* event)
if (handler) {
handler->on_att_mtu_change(event->hdr.param, event->mtu);
}
} else if (event->hdr.event == ATTC_WRITE_CMD_RSP) {
ble::vendor::cordio::BLE& ble = ble::vendor::cordio::BLE::deviceInstance();
impl::PalGattClientImpl::EventHandler *handler = ble.getPalGattClient().get_event_handler();
if (handler) {
handler->on_write_command_sent(
event->hdr.param,
event->handle,
event->hdr.status
);
}
} else {
// all handlers are stored in a static array
static const event_handler_t handlers[] = {
Expand Down

0 comments on commit 2da7436

Please sign in to comment.