Skip to content

Commit

Permalink
NimBLE NVS: Fix bug in deletion of peer_dev_record
Browse files Browse the repository at this point in the history
- Fix comparison metric while deleting peer_dev_record. Previous to this,
  random address change after reboot used to result in NVS database mismatch
  and hence sometimes caused wrong NVS entry deletion.
- Closes ESPCS-540
  • Loading branch information
prasad-alatkar authored and ESPAbhinav committed Feb 14, 2024
1 parent 246ec01 commit 1db1eb1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion nimble/host/src/ble_hs_resolv.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ ble_rpa_remove_peer_dev_rec(struct ble_hs_dev_records *p_dev_rec)
ble_store_num_peer_dev_rec--;
if ((i != ble_store_num_peer_dev_rec) && (ble_store_num_peer_dev_rec != 0)) {
memmove(&peer_dev_rec[i], &peer_dev_rec[i + 1],
(ble_store_num_peer_dev_rec - i + 1) * sizeof(struct ble_hs_dev_records ));
(ble_store_num_peer_dev_rec - i) * sizeof(struct ble_hs_dev_records ));
}

BLE_HS_LOG(DEBUG, " RPA: removed device at index = %d, no. of peer records"
Expand Down
6 changes: 4 additions & 2 deletions nimble/host/store/config/src/ble_store_nvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,10 @@ get_nvs_db_attribute(int obj_type, bool empty, void *value, int num_value)
if (value) {
#if MYNEWT_VAL(BLE_HOST_BASED_PRIVACY)
if (obj_type == BLE_STORE_OBJ_TYPE_PEER_DEV_REC) {
err = get_nvs_matching_index(&p_dev_rec, value, num_value,
sizeof(struct ble_hs_dev_records));
err = get_nvs_matching_index(&p_dev_rec.peer_sec,
&((struct ble_hs_dev_records *)value)->peer_sec,
num_value,
sizeof(struct ble_hs_peer_sec));
} else
#endif
{
Expand Down

0 comments on commit 1db1eb1

Please sign in to comment.