From 0c4892be95df3c6b80831bcbc58b7186ba2cdab6 Mon Sep 17 00:00:00 2001 From: Prasad Alatkar Date: Wed, 10 Mar 2021 20:35:11 +0530 Subject: [PATCH 1/2] NimBLE NVS: Fix bug in deletion of peer_dev_record - 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 --- nimble/host/src/ble_hs_resolv.c | 2 +- nimble/host/store/config/src/ble_store_nvs.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/nimble/host/src/ble_hs_resolv.c b/nimble/host/src/ble_hs_resolv.c index 46e5577f6..b10fd50ef 100644 --- a/nimble/host/src/ble_hs_resolv.c +++ b/nimble/host/src/ble_hs_resolv.c @@ -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" diff --git a/nimble/host/store/config/src/ble_store_nvs.c b/nimble/host/store/config/src/ble_store_nvs.c index 2ebb26e75..0da302641 100644 --- a/nimble/host/store/config/src/ble_store_nvs.c +++ b/nimble/host/store/config/src/ble_store_nvs.c @@ -205,8 +205,10 @@ get_nvs_db_attribute(int obj_type, bool empty, void *value, int num_value) * non-matching entry from NVS */ if (value) { 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 { if (obj_type != BLE_STORE_OBJ_TYPE_CCCD) { err = get_nvs_matching_index(&cur.sec, value, num_value, From 765b44ac8194057cdd69177abf6e4b0a3032f251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Fri, 2 Oct 2020 11:09:02 +0200 Subject: [PATCH 2/2] nimble/ble_gap: adv_enable_tx preprocessor directives corrections There wher compilation errors for blecent if NIMBLE_BLE_ADVERTISE was not set. Appropriate preprocessor if conditions where added. --- nimble/host/src/ble_gap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index ebd237fee..4029c931a 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -865,7 +865,7 @@ ble_gap_master_ticks_until_exp(void) return 0; } -#if !MYNEWT_VAL(BLE_EXT_ADV) +#if NIMBLE_BLE_ADVERTISE && !MYNEWT_VAL(BLE_EXT_ADV) static uint32_t ble_gap_slave_ticks_until_exp(void) { @@ -1622,7 +1622,7 @@ ble_gap_master_timer(void) return BLE_HS_FOREVER; } -#if !MYNEWT_VAL(BLE_EXT_ADV) +#if NIMBLE_BLE_ADVERTISE && !MYNEWT_VAL(BLE_EXT_ADV) static int32_t ble_gap_slave_timer(void) { @@ -1721,7 +1721,7 @@ ble_gap_timer(void) min_ticks = min(master_ticks, update_ticks); -#if !MYNEWT_VAL(BLE_EXT_ADV) +#if NIMBLE_BLE_ADVERTISE && !MYNEWT_VAL(BLE_EXT_ADV) min_ticks = min(min_ticks, ble_gap_slave_timer()); #endif