@@ -102,13 +102,19 @@ ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::init_(
102
102
result = init_resolving_list ();
103
103
#endif
104
104
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
+
105
112
if (result != BLE_ERROR_NONE) {
106
113
delete _db;
107
114
_db = NULL ;
108
- return result;
109
115
}
110
116
111
- return BLE_ERROR_NONE ;
117
+ return result ;
112
118
}
113
119
114
120
template <template <class > class TPalSecurityManager , template <class > class SigningMonitor >
@@ -309,6 +315,33 @@ ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::setPair
309
315
return BLE_ERROR_NONE;
310
316
}
311
317
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
+
312
345
// //////////////////////////////////////////////////////////////////////////
313
346
// Feature support
314
347
//
@@ -901,6 +934,33 @@ ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::init_si
901
934
return _pal.set_csrk (*pcsrk, local_sign_counter);
902
935
}
903
936
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
+
904
964
template <template <class > class TPalSecurityManager , template <class > class SigningMonitor >
905
965
ble_error_t GenericSecurityManager<TPalSecurityManager, SigningMonitor>::get_random_data(uint8_t *buffer, size_t size) {
906
966
byte_array_t <8 > random_data;
0 commit comments