From 951a6be4c86dca26e7b768726554296245a7b9c2 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Tue, 17 Apr 2018 15:58:21 +0100 Subject: [PATCH] BLE: retrieve and fill resolving list at GenericSecurityManager startup. --- .../ble/generic/GenericSecurityManager.h | 14 +++++++- .../source/generic/GenericSecurityManager.cpp | 36 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/features/FEATURE_BLE/ble/generic/GenericSecurityManager.h b/features/FEATURE_BLE/ble/generic/GenericSecurityManager.h index e30e4b9114..68f664f837 100644 --- a/features/FEATURE_BLE/ble/generic/GenericSecurityManager.h +++ b/features/FEATURE_BLE/ble/generic/GenericSecurityManager.h @@ -25,6 +25,7 @@ #include "ble/pal/SigningEventMonitor.h" #include "ble/generic/GenericGap.h" #include "ble/pal/PalSecurityManager.h" +#include "ble/ArrayView.h" namespace ble { namespace generic { @@ -402,13 +403,24 @@ private: /** * Callback invoked by the secure DB when an identity entry has been * retrieved. - * @param identity + * @param entry Handle of the entry. + * @param identity The identity associated with the entry; may be NULL. */ void on_security_entry_retrieved( pal::SecurityDb::entry_handle_t entry, const pal::SecurityEntryIdentity_t* identity ); + /** + * Callback invoked by the secure DB when the identity list has been + * retrieved. + * @param identity + */ + void on_identity_list_retrieved( + ble::ArrayView&, + size_t count + ); + private: struct ControlBlock_t : public pal::SecurityDistributionFlags_t { ControlBlock_t(); diff --git a/features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp b/features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp index 83e86de435..0b93ac0b7d 100644 --- a/features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp +++ b/features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp @@ -74,6 +74,22 @@ ble_error_t GenericSecurityManager::init( _signing_monitor.set_signing_event_handler(this); _pal.set_event_handler(this); + uint8_t resolving_list_capacity = _pal.read_resolving_list_capacity(); + pal::SecurityEntryIdentity_t** identity_list_p = + new (std::nothrow) pal::SecurityEntryIdentity_t*[resolving_list_capacity]; + + if (identity_list_p) { + ArrayView identity_list( + identity_list_p, + resolving_list_capacity + ); + + _db.get_identity_list( + mbed::callback(this, &GenericSecurityManager::on_identity_list_retrieved), + identity_list + ); + } + return BLE_ERROR_NONE; } @@ -883,6 +899,26 @@ void GenericSecurityManager::on_security_entry_retrieved( ); } +void GenericSecurityManager::on_identity_list_retrieved( + ble::ArrayView& identity_list, + size_t count +) { + typedef advertising_peer_address_type_t address_type_t; + + _pal.clear_resolving_list(); + for (size_t i = 0; i < count; ++i) { + _pal.add_device_to_resolving_list( + identity_list[i]->identity_address_is_public ? + address_type_t::PUBLIC_ADDRESS : + address_type_t::RANDOM_ADDRESS, + identity_list[i]->identity_address, + identity_list[i]->irk + ); + } + + delete [] identity_list.data(); +} + /* Implements ble::pal::SecurityManagerEventHandler */