BLE: retrieve and fill resolving list at GenericSecurityManager startup.

pull/6932/head
Vincent Coubard 2018-04-17 15:58:21 +01:00
parent ede3d43743
commit 951a6be4c8
2 changed files with 49 additions and 1 deletions

View File

@ -25,6 +25,7 @@
#include "ble/pal/SigningEventMonitor.h" #include "ble/pal/SigningEventMonitor.h"
#include "ble/generic/GenericGap.h" #include "ble/generic/GenericGap.h"
#include "ble/pal/PalSecurityManager.h" #include "ble/pal/PalSecurityManager.h"
#include "ble/ArrayView.h"
namespace ble { namespace ble {
namespace generic { namespace generic {
@ -402,13 +403,24 @@ private:
/** /**
* Callback invoked by the secure DB when an identity entry has been * Callback invoked by the secure DB when an identity entry has been
* retrieved. * 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( void on_security_entry_retrieved(
pal::SecurityDb::entry_handle_t entry, pal::SecurityDb::entry_handle_t entry,
const pal::SecurityEntryIdentity_t* identity 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<pal::SecurityEntryIdentity_t*>&,
size_t count
);
private: private:
struct ControlBlock_t : public pal::SecurityDistributionFlags_t { struct ControlBlock_t : public pal::SecurityDistributionFlags_t {
ControlBlock_t(); ControlBlock_t();

View File

@ -74,6 +74,22 @@ ble_error_t GenericSecurityManager::init(
_signing_monitor.set_signing_event_handler(this); _signing_monitor.set_signing_event_handler(this);
_pal.set_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<pal::SecurityEntryIdentity_t*> 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; return BLE_ERROR_NONE;
} }
@ -883,6 +899,26 @@ void GenericSecurityManager::on_security_entry_retrieved(
); );
} }
void GenericSecurityManager::on_identity_list_retrieved(
ble::ArrayView<pal::SecurityEntryIdentity_t*>& 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 */ /* Implements ble::pal::SecurityManagerEventHandler */