@@ -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 >
@@ -161,7 +167,21 @@ template<template<class> class TPalSecurityManager, template<class> class Signin
161167ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::purgeAllBondingState_(void ) {
162168 if (!_db) return BLE_ERROR_INITIALIZATION_INCOMPLETE;
163169 _db->clear_entries ();
164- return BLE_ERROR_NONE;
170+
171+ ble_error_t ret = BLE_ERROR_NONE;
172+
173+ #if BLE_FEATURE_SIGNING
174+ // generate new csrk and irk
175+ ret = init_signing ();
176+ if (ret) {
177+ return ret;
178+ }
179+ #endif // BLE_FEATURE_SIGNING
180+ #if BLE_FEATURE_PRIVACY
181+ ret = init_identity ();
182+ #endif // BLE_FEATURE_PRIVACY
183+
184+ return ret;
165185}
166186
167187template <template <class > class TPalSecurityManager , template <class > class SigningMonitor >
@@ -309,6 +329,33 @@ ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::setPair
309329 return BLE_ERROR_NONE;
310330}
311331
332+ template <template <class > class TPalSecurityManager , template <class > class SigningMonitor >
333+ ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::getPeerIdentity_(connection_handle_t connection) {
334+ if (!_db) return BLE_ERROR_INITIALIZATION_INCOMPLETE;
335+ if (eventHandler) {
336+ ControlBlock_t *cb = get_control_block (connection);
337+ if (!cb) {
338+ return BLE_ERROR_INVALID_PARAM;
339+ }
340+
341+ _db->get_entry_identity (
342+ [connection,this ](SecurityDb::entry_handle_t handle, const SecurityEntryIdentity_t* identity) {
343+ if (eventHandler) {
344+ eventHandler->peerIdentity (
345+ connection,
346+ identity ? &identity->identity_address : nullptr ,
347+ identity ? identity->identity_address_is_public : false
348+ );
349+ }
350+ },
351+ cb->db_entry
352+ );
353+ return BLE_ERROR_NONE;
354+ } else {
355+ return BLE_ERROR_INVALID_STATE;
356+ }
357+ }
358+
312359// //////////////////////////////////////////////////////////////////////////
313360// Feature support
314361//
@@ -901,6 +948,33 @@ ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::init_si
901948 return _pal.set_csrk (*pcsrk, local_sign_counter);
902949}
903950
951+ template <template <class > class TPalSecurityManager , template <class > class SigningMonitor >
952+ ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::init_identity() {
953+ if (!_db) return BLE_ERROR_INITIALIZATION_INCOMPLETE;
954+ const irk_t *pirk = nullptr ;
955+
956+ irk_t irk = _db->get_local_irk ();
957+ if (irk != irk_t ()) {
958+ pirk = &irk;
959+ } else {
960+ ble_error_t ret = get_random_data (irk.data (), irk.size ());
961+ if (ret != BLE_ERROR_NONE) {
962+ return ret;
963+ }
964+
965+ pirk = &irk;
966+ address_t identity_address;
967+ bool public_address;
968+ ret = _pal.get_identity_address (identity_address, public_address);
969+ if (ret != BLE_ERROR_NONE) {
970+ return ret;
971+ }
972+ _db->set_local_identity (irk, identity_address, public_address);
973+ }
974+
975+ return _pal.set_irk (*pirk);
976+ }
977+
904978template <template <class > class TPalSecurityManager , template <class > class SigningMonitor >
905979ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::get_random_data(uint8_t *buffer, size_t size) {
906980 byte_array_t <8 > random_data;
0 commit comments