From 569fd9ed30ef9f43e929c73f088f171c6211b17f Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Thu, 7 Jun 2018 12:29:57 +0100 Subject: [PATCH 1/2] Cordio BLE: Add hook to HCI driver and transport. A friend class living in the namespace ble::vendor::cordio and named CordioHCITransportDriver can be added in applications requiring access to internal data of the HCI driver and HCI transport driver. This is meant to be internal and not easily exploitable by application code. --- .../targets/TARGET_CORDIO/driver/CordioHCIDriver.h | 4 ++++ .../targets/TARGET_CORDIO/driver/CordioHCITransportDriver.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.h index 10ac769c82..a3b923e270 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.h @@ -58,6 +58,10 @@ struct buf_pool_desc_t { * - Access to the write function of the underlying HCITransport driver. */ class CordioHCIDriver { + + // hook for internal tests and passthrough driver + friend class CordioHCIHook; + public: /** * Construct a new instance of an HCI driver. diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCITransportDriver.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCITransportDriver.h index a7e7499f21..b33d407909 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCITransportDriver.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCITransportDriver.h @@ -28,6 +28,10 @@ namespace cordio { * It allow the stack to write data in the HCI channel. */ class CordioHCITransportDriver { + + // hook for internal tests and passthrough driver + friend class CordioHCIHook; + public: /** * Driver destructor. From 06d9aac14c3ed31673af599374056993bd328527 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Thu, 7 Jun 2018 12:30:34 +0100 Subject: [PATCH 2/2] Cordio BLE: Allow replacement of hci RX handler. --- .../driver/CordioHCITransportDriver.cpp | 18 +++++++++++++++++- .../driver/CordioHCITransportDriver.h | 7 +++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCITransportDriver.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCITransportDriver.cpp index 01b0b1016a..ba4475b638 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCITransportDriver.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCITransportDriver.cpp @@ -14,6 +14,9 @@ * limitations under the License. */ +#include +#include + #include "CordioHCITransportDriver.h" #include "CordioHCIDriver.h" @@ -23,9 +26,22 @@ namespace ble { namespace vendor { namespace cordio { +CordioHCITransportDriver::data_received_handler_t + CordioHCITransportDriver::data_received_handler = hciTrSerialRxIncoming; + void CordioHCITransportDriver::on_data_received(uint8_t* data, uint16_t len) { - hciTrSerialRxIncoming(data, len); + while (len) { + uint8_t chunk_length = std::min(len, (uint16_t) std::numeric_limits::max()); + data_received_handler(data, chunk_length); + len = len - chunk_length; + data = data + chunk_length; + } +} + +void CordioHCITransportDriver::set_data_received_handler(data_received_handler_t handler) +{ + data_received_handler = handler; } } // namespace cordio diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCITransportDriver.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCITransportDriver.h index b33d407909..cd980767f1 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCITransportDriver.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCITransportDriver.h @@ -68,6 +68,13 @@ public: * @param len Number of bytes received. */ static void on_data_received(uint8_t* data, uint16_t len); + +private: + typedef void (*data_received_handler_t)(uint8_t* data, uint8_t len); + + static data_received_handler_t data_received_handler; + + static void set_data_received_handler(data_received_handler_t handler); }; } // namespace cordio