Skip to content

Commit b0a3d05

Browse files
committed
[Bugfix] Delete all bonds does not allow re-pairing.
This change iterates through each bond and unpairs it rather than just deleting the bond data in nvs, allowing a connected peer to rebond.
1 parent c731adc commit b0a3d05

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

src/NimBLEDevice.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -629,10 +629,12 @@ int NimBLEDevice::getNumBonds() {
629629
* @returns True on success.
630630
*/
631631
bool NimBLEDevice::deleteAllBonds() {
632-
int rc = ble_store_clear();
633-
if (rc != 0) {
634-
NIMBLE_LOGE(LOG_TAG, "Failed to delete all bonds; rc=%d", rc);
635-
return false;
632+
int numBonds = NimBLEDevice::getNumBonds();
633+
for (int i = numBonds - 1; i >= 0; i--) {
634+
if (!NimBLEDevice::deleteBond(NimBLEDevice::getBondedAddress(i))) {
635+
NIMBLE_LOGE(LOG_TAG, "Failed to delete bond for address: %s", NimBLEDevice::getBondedAddress(i).toString().c_str());
636+
return false;
637+
}
636638
}
637639
return true;
638640
}
@@ -905,7 +907,8 @@ bool NimBLEDevice::init(const std::string& deviceName) {
905907
bt_cfg.mode = ESP_BT_MODE_BLE;
906908
bt_cfg.ble_max_conn = MYNEWT_VAL(BLE_MAX_CONNECTIONS);
907909
# elif defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S3)
908-
bt_cfg.ble_max_act = MYNEWT_VAL(BLE_MAX_CONNECTIONS) + MYNEWT_VAL(BLE_ROLE_BROADCASTER) + MYNEWT_VAL(BLE_ROLE_OBSERVER);
910+
bt_cfg.ble_max_act =
911+
MYNEWT_VAL(BLE_MAX_CONNECTIONS) + MYNEWT_VAL(BLE_ROLE_BROADCASTER) + MYNEWT_VAL(BLE_ROLE_OBSERVER);
909912
# else
910913
bt_cfg.nimble_max_connections = MYNEWT_VAL(BLE_MAX_CONNECTIONS);
911914
# endif
@@ -1289,13 +1292,13 @@ bool NimBLEDevice::injectConfirmPasskey(const NimBLEConnInfo& peerInfo, bool acc
12891292
* @param [in] deviceName The name to set.
12901293
*/
12911294
bool NimBLEDevice::setDeviceName(const std::string& deviceName) {
1292-
#if !defined(MYNEWT_VAL_BLE_GATTS) || MYNEWT_VAL(BLE_GATTS) > 0
1295+
# if !defined(MYNEWT_VAL_BLE_GATTS) || MYNEWT_VAL(BLE_GATTS) > 0
12931296
int rc = ble_svc_gap_device_name_set(deviceName.c_str());
12941297
if (rc != 0) {
12951298
NIMBLE_LOGE(LOG_TAG, "Device name not set - too long");
12961299
return false;
12971300
}
1298-
#endif
1301+
# endif
12991302
return true;
13001303
} // setDeviceName
13011304

0 commit comments

Comments
 (0)