File tree Expand file tree Collapse file tree 2 files changed +31
-4
lines changed
connectivity/FEATURE_BLE/source/generic Expand file tree Collapse file tree 2 files changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -450,6 +450,20 @@ class SecurityDb {
450450 return _local_identity.irk ;
451451 }
452452
453+ /* *
454+ * Return local identity address.
455+ */
456+ virtual const address_t & get_local_identity_address () {
457+ return _local_identity.identity_address ;
458+ }
459+
460+ /* *
461+ * Return if the local identity address is public or not
462+ */
463+ virtual bool is_local_identity_address_public () {
464+ return _local_identity.identity_address_is_public ;
465+ }
466+
453467 /* list management */
454468
455469 /* *
Original file line number Diff line number Diff line change @@ -1032,23 +1032,36 @@ ble_error_t SecurityManager::init_identity()
10321032 if (!_db) return BLE_ERROR_INITIALIZATION_INCOMPLETE;
10331033 const irk_t *pirk = nullptr ;
10341034
1035+ ble::Gap& gap = BLE::Instance ().gap ();
1036+
10351037 irk_t irk = _db->get_local_irk ();
10361038 if (irk != irk_t ()) {
10371039 pirk = &irk;
1040+
1041+ if (!_db->is_local_identity_address_public ()) {
1042+ // Some controllers doesn't store their random static address and
1043+ // instead generates them at each reboot.
1044+ // The code should replace the random static address with the identity
1045+ // address if this is the case.
1046+ if (_db->get_local_identity_address () != gap.getRandomStaticAddress ()) {
1047+ ble_error_t err =gap.setRandomStaticAddress (_db->get_local_identity_address ());
1048+ if (err) {
1049+ return err;
1050+ }
1051+ }
1052+ }
10381053 } else {
10391054 ble_error_t ret = get_random_data (irk.data (), irk.size ());
10401055 if (ret != BLE_ERROR_NONE) {
10411056 return ret;
10421057 }
10431058
10441059 pirk = &irk;
1045- address_t identity_address;
1046- bool public_address;
1047- ret = _pal.get_identity_address (identity_address, public_address);
1060+ address_t random_static_address = gap.getRandomStaticAddress ();
10481061 if (ret != BLE_ERROR_NONE) {
10491062 return ret;
10501063 }
1051- _db->set_local_identity (irk, identity_address, public_address);
1064+ _db->set_local_identity (irk, random_static_address, /* public_address */ false );
10521065 }
10531066
10541067 auto err = _pal.set_irk (*pirk);
You can’t perform that action at this time.
0 commit comments