@@ -102,13 +102,19 @@ ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::init_(
102102 result = init_resolving_list ();
103103#endif
104104
105+ #if BLE_FEATURE_PRIVACY
106+ // set the local identity address and irk
107+ if (result != BLE_ERROR_NONE) {
108+ result = init_identity ();
109+ }
110+ #endif // BLE_FEATURE_PRIVACY
111+
105112 if (result != BLE_ERROR_NONE) {
106113 delete _db;
107114 _db = NULL ;
108- return result;
109115 }
110116
111- return BLE_ERROR_NONE ;
117+ return result ;
112118}
113119
114120template <template <class > class TPalSecurityManager , template <class > class SigningMonitor >
@@ -309,6 +315,33 @@ ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::setPair
309315 return BLE_ERROR_NONE;
310316}
311317
318+ template <template <class > class TPalSecurityManager , template <class > class SigningMonitor >
319+ ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::getPeerIdentity_(connection_handle_t connection) {
320+ if (!_db) return BLE_ERROR_INITIALIZATION_INCOMPLETE;
321+ if (eventHandler) {
322+ ControlBlock_t *cb = get_control_block (connection);
323+ if (!cb) {
324+ return BLE_ERROR_INVALID_PARAM;
325+ }
326+
327+ _db->get_entry_identity (
328+ [connection,this ](SecurityDb::entry_handle_t handle, const SecurityEntryIdentity_t* identity) {
329+ if (eventHandler) {
330+ eventHandler->peerIdentity (
331+ connection,
332+ identity ? &identity->identity_address : nullptr ,
333+ identity ? identity->identity_address_is_public : false
334+ );
335+ }
336+ },
337+ cb->db_entry
338+ );
339+ return BLE_ERROR_NONE;
340+ } else {
341+ return BLE_ERROR_INVALID_STATE;
342+ }
343+ }
344+
312345// //////////////////////////////////////////////////////////////////////////
313346// Feature support
314347//
@@ -901,6 +934,33 @@ ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::init_si
901934 return _pal.set_csrk (*pcsrk, local_sign_counter);
902935}
903936
937+ template <template <class > class TPalSecurityManager , template <class > class SigningMonitor >
938+ ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::init_identity() {
939+ if (!_db) return BLE_ERROR_INITIALIZATION_INCOMPLETE;
940+ const irk_t *pirk = nullptr ;
941+
942+ irk_t irk = _db->get_local_irk ();
943+ if (irk != irk_t ()) {
944+ pirk = &irk;
945+ } else {
946+ ble_error_t ret = get_random_data (irk.data (), irk.size ());
947+ if (ret != BLE_ERROR_NONE) {
948+ return ret;
949+ }
950+
951+ pirk = &irk;
952+ address_t identity_address;
953+ bool public_address;
954+ ret = _pal.get_identity_address (identity_address, public_address);
955+ if (ret != BLE_ERROR_NONE) {
956+ return ret;
957+ }
958+ _db->set_local_identity (irk, identity_address, public_address);
959+ }
960+
961+ return _pal.set_irk (*pirk);
962+ }
963+
904964template <template <class > class TPalSecurityManager , template <class > class SigningMonitor >
905965ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::get_random_data(uint8_t *buffer, size_t size) {
906966 byte_array_t <8 > random_data;
0 commit comments