diff --git a/features/FEATURE_BLE/ble/BLETypes.h b/features/FEATURE_BLE/ble/BLETypes.h index 3bc5e8f75d..a66c760a00 100644 --- a/features/FEATURE_BLE/ble/BLETypes.h +++ b/features/FEATURE_BLE/ble/BLETypes.h @@ -370,11 +370,11 @@ struct address_t : public octet_type_t<6> { } /** - * Initialize a mac address from an array of bytes. + * Initialize a data from an array of bytes. * - * @param input_value value of the MAC address. + * @param input_value value of the data. */ - address_t(const uint8_t (&input_value)[6]) { + address_t(const uint8_t *input_value) { memcpy(_value, input_value, sizeof(_value)); } @@ -386,7 +386,7 @@ struct address_t : public octet_type_t<6> { * * @param tag Tag used to select this constructor. The value does not matter. */ - address_t(const uint8_t* input_value, bool tag) { + address_t(const uint8_t *input_value, bool tag) { memcpy(_value, input_value, sizeof(_value)); } }; diff --git a/features/FEATURE_BLE/ble/ConnectionEventMonitor.h b/features/FEATURE_BLE/ble/ConnectionEventMonitor.h index e9be7447ca..daa3ae4e14 100644 --- a/features/FEATURE_BLE/ble/ConnectionEventMonitor.h +++ b/features/FEATURE_BLE/ble/ConnectionEventMonitor.h @@ -32,6 +32,7 @@ namespace ble { class ConnectionEventHandler { +public: virtual void on_connected( connection_handle_t connection, Gap::Role_t role, @@ -42,20 +43,21 @@ class ConnectionEventHandler { const Gap::ConnectionParams_t *connection_params ) = 0; - void on_disconnected( + virtual void on_disconnected( connection_handle_t connection, Gap::DisconnectionReason_t reason ) = 0; }; class ConnectionEventMonitor { +public: /** * Register a handler for connection events to be used internally and serviced first. * * @param[in] connection_event_handler Event handler being registered. */ - void set_connection_event_handler(ConnectionEventHandler *connection_event_handler) = 0; -} + virtual void set_connection_event_handler(ConnectionEventHandler *connection_event_handler) = 0; +}; } diff --git a/features/FEATURE_BLE/ble/generic/GenericGap.h b/features/FEATURE_BLE/ble/generic/GenericGap.h index 7d66c95e38..cdc8d5a2b9 100644 --- a/features/FEATURE_BLE/ble/generic/GenericGap.h +++ b/features/FEATURE_BLE/ble/generic/GenericGap.h @@ -272,6 +272,11 @@ public: DisconnectionReason_t reason ); + /** @note Implements ConnectionEventMonitor. + * @copydoc ConnectionEventMonitor::set_connection_event_handler + */ + virtual void set_connection_event_handler(ConnectionEventHandler *_connection_event_handler); + private: void on_scan_timeout(); @@ -301,9 +306,6 @@ private: bool initialize_whitelist() const; - /** implements ConnectionEventMonitor */ - void set_connection_event_handler(ConnectionEventHandler *_connection_event_handler); - pal::EventQueue& _event_queue; pal::Gap &_pal_gap; pal::GenericAccessService &_gap_service; diff --git a/features/FEATURE_BLE/ble/generic/GenericSecurityManager.h b/features/FEATURE_BLE/ble/generic/GenericSecurityManager.h index 96e246977e..2e742e12af 100644 --- a/features/FEATURE_BLE/ble/generic/GenericSecurityManager.h +++ b/features/FEATURE_BLE/ble/generic/GenericSecurityManager.h @@ -390,7 +390,7 @@ private: * @param[in] peer_address Address of the connected device. * @return BLE_ERROR_NONE or appropriate error code indicating the failure reason. */ - void on_connected( + virtual void on_connected( connection_handle_t connection, Gap::Role_t role, BLEProtocol::AddressType_t peer_address_type, @@ -407,7 +407,7 @@ private: * @param[in] connectionHandle Handle to identify the connection. * @return BLE_ERROR_NONE or appropriate error code indicating the failure reason. */ - void on_disconnected( + virtual void on_disconnected( connection_handle_t connection, Gap::DisconnectionReason_t reason ); diff --git a/features/FEATURE_BLE/ble/pal/MemorySecurityDB.h b/features/FEATURE_BLE/ble/pal/MemorySecurityDB.h index dac831fd12..b72ea9ef06 100644 --- a/features/FEATURE_BLE/ble/pal/MemorySecurityDB.h +++ b/features/FEATURE_BLE/ble/pal/MemorySecurityDB.h @@ -18,6 +18,7 @@ #define PAL_MEMORY_SECURITY_MANAGER_DB_H__ #include "SecurityDB.h" +#include "Gap.h" namespace ble { namespace pal { @@ -341,12 +342,12 @@ public: _local_csrk = csrk_t(); } - virtual void get_whitelist(WhitelistDbCb_t cb, Gap::Whitelist_t *whitelist) { + virtual void get_whitelist(WhitelistDbCb_t cb, ::Gap::Whitelist_t *whitelist) { /*TODO: fill whitelist*/ cb(whitelist); } - virtual void generate_whitelist_from_bond_table(WhitelistDbCb_t cb, Gap::Whitelist_t *whitelist) { + virtual void generate_whitelist_from_bond_table(WhitelistDbCb_t cb, ::Gap::Whitelist_t *whitelist) { for (size_t i = 0; i < MAX_ENTRIES && i < whitelist->capacity; i++) { if (_db[i].entry.peer_address_is_public) { whitelist->addresses[i].type = BLEProtocol::AddressType::PUBLIC; @@ -364,9 +365,9 @@ public: cb(whitelist); } - virtual void update_whitelist(Gap::Whitelist_t &whitelist) { } + virtual void update_whitelist(::Gap::Whitelist_t &whitelist) { } - virtual void set_whitelist(const Gap::Whitelist_t &whitelist) { }; + virtual void set_whitelist(const ::Gap::Whitelist_t &whitelist) { }; virtual void add_whitelist_entry(const address_t &address) { } diff --git a/features/FEATURE_BLE/ble/pal/SecurityDb.h b/features/FEATURE_BLE/ble/pal/SecurityDb.h index 2e82d77e7e..703f4177a8 100644 --- a/features/FEATURE_BLE/ble/pal/SecurityDb.h +++ b/features/FEATURE_BLE/ble/pal/SecurityDb.h @@ -25,8 +25,6 @@ namespace ble { namespace pal { -using pal::connection_peer_address_type_t; - /* separate structs for keys to allow db implementation * to minimise memory usage, only holding live connection * state in memory */ @@ -127,7 +125,7 @@ struct SecurityEntryIdentity_t { typedef mbed::Callback SecurityEntryKeysDbCb_t; typedef mbed::Callback SecurityEntryCsrkDbCb_t; -typedef mbed::Callback WhitelistDbCb_t; +typedef mbed::Callback WhitelistDbCb_t; /** * SecurityDB holds the state for active connections and bonded devices. @@ -475,7 +473,7 @@ public: */ virtual void get_whitelist( WhitelistDbCb_t cb, - Gap::Whitelist_t *whitelist + ::Gap::Whitelist_t *whitelist ) = 0; /** @@ -488,7 +486,7 @@ public: */ virtual void generate_whitelist_from_bond_table( WhitelistDbCb_t cb, - Gap::Whitelist_t *whitelist + ::Gap::Whitelist_t *whitelist ) = 0; /** @@ -497,7 +495,7 @@ public: * @param[in] whitelist */ virtual void set_whitelist( - const Gap::Whitelist_t &whitelist + const ::Gap::Whitelist_t &whitelist ) = 0; /** diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioSecurityManager.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioSecurityManager.h index 4e0e51217f..96a4ca7c20 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioSecurityManager.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioSecurityManager.h @@ -20,7 +20,7 @@ #include #include "ble/generic/GenericSecurityManager.h" -#include "ble/generic/GenericSecurityDb.h" +#include "ble/pal/MemorySecurityDb.h" #include "ble/generic/GenericGap.h" #include "ble/pal/PalSecurityManager.h" #include "CordioPalSecurityManager.h" @@ -36,16 +36,16 @@ class SecurityManager : public generic::GenericSecurityManager public: static SecurityManager &getInstance() { - static generic::MemoryGenericSecurityDb m_db; + static pal::MemorySecurityDb m_db; static pal::vendor::cordio::CordioSecurityManager m_pal; - static SecurityManager m_instance(m_pal, m_db, cordio::Gap::getInstance()); + static SecurityManager m_instance(m_pal, m_db, *(reinterpret_cast(&(cordio::Gap::getInstance())))); return m_instance; } public: SecurityManager( pal::SecurityManager &palImpl, - generic::GenericSecurityDb &dbImpl, + pal::SecurityDb &dbImpl, generic::GenericGap &gapImpl ) : generic::GenericSecurityManager(palImpl, dbImpl, gapImpl) { /* empty */