Clear bluetooth bonds on multi-press and factory_reset (#1176)

* Clear bluetooth bonds on multi-press and factory_reset
This commit is contained in:
Ben Meadors 2022-02-01 18:32:26 -06:00 committed by GitHub
parent dd31a829fb
commit b21b7de04b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 2 deletions

View File

@ -340,6 +340,9 @@ class ButtonThread : public OSThread
{ {
#ifndef NO_ESP32 #ifndef NO_ESP32
clearNVS(); clearNVS();
#endif
#ifdef NRF52_SERIES
clearBonds();
#endif #endif
} }

View File

@ -27,4 +27,4 @@ extern uint32_t shutdownAtMsec;
// This will supress the current delay and instead try to run ASAP. // This will supress the current delay and instead try to run ASAP.
extern bool runASAP; extern bool runASAP;
void nrf52Setup(), esp32Setup(), nrf52Loop(), esp32Loop(); void nrf52Setup(), esp32Setup(), nrf52Loop(), esp32Loop(), clearBonds();

View File

@ -26,6 +26,11 @@
#include <nvs_flash.h> #include <nvs_flash.h>
#endif #endif
#ifdef NRF52_SERIES
#include <bluefruit.h>
#include <utility/bonding.h>
#endif
NodeDB nodeDB; NodeDB nodeDB;
// we have plenty of ram so statically alloc this tempbuf (for now) // we have plenty of ram so statically alloc this tempbuf (for now)
@ -90,6 +95,16 @@ bool NodeDB::resetRadioConfig()
#ifndef NO_ESP32 #ifndef NO_ESP32
// This will erase what's in NVS including ssl keys, persistant variables and ble pairing // This will erase what's in NVS including ssl keys, persistant variables and ble pairing
nvs_flash_erase(); nvs_flash_erase();
#endif
#ifdef NRF52_SERIES
Bluefruit.begin();
DEBUG_MSG("Clearing bluetooth bonds!\n");
bond_print_list(BLE_GAP_ROLE_PERIPH);
bond_print_list(BLE_GAP_ROLE_CENTRAL);
Bluefruit.Periph.clearBonds();
Bluefruit.Central.clearBonds();
#endif #endif
didFactoryReset = true; didFactoryReset = true;
} }

View File

@ -5,6 +5,7 @@
#include "mesh/PhoneAPI.h" #include "mesh/PhoneAPI.h"
#include "mesh/mesh-pb-constants.h" #include "mesh/mesh-pb-constants.h"
#include <bluefruit.h> #include <bluefruit.h>
#include <utility/bonding.h>
static BLEService meshBleService = BLEService(BLEUuid(MESH_SERVICE_UUID_16)); static BLEService meshBleService = BLEService(BLEUuid(MESH_SERVICE_UUID_16));
static BLECharacteristic fromNum = BLECharacteristic(BLEUuid(FROMNUM_UUID_16)); static BLECharacteristic fromNum = BLECharacteristic(BLEUuid(FROMNUM_UUID_16));
@ -266,3 +267,13 @@ void updateBatteryLevel(uint8_t level)
{ {
blebas.write(level); blebas.write(level);
} }
void NRF52Bluetooth::clearBonds()
{
DEBUG_MSG("Clearing bluetooth bonds!\n");
bond_print_list(BLE_GAP_ROLE_PERIPH);
bond_print_list(BLE_GAP_ROLE_CENTRAL);
Bluefruit.Periph.clearBonds();
Bluefruit.Central.clearBonds();
}

View File

@ -5,5 +5,6 @@ class NRF52Bluetooth
public: public:
void setup(); void setup();
void shutdown(); void shutdown();
void clearBonds();
}; };

View File

@ -75,7 +75,7 @@ void setBluetoothEnable(bool on)
else { else {
nrf52Bluetooth = new NRF52Bluetooth(); nrf52Bluetooth = new NRF52Bluetooth();
nrf52Bluetooth->setup(); nrf52Bluetooth->setup();
// We delay brownout init until after BLE because BLE starts soft device // We delay brownout init until after BLE because BLE starts soft device
initBrownout(); initBrownout();
} }
@ -185,4 +185,12 @@ void cpuDeepSleep(uint64_t msecToWake)
delay(5000); delay(5000);
DEBUG_MSG("."); DEBUG_MSG(".");
} }
}
void clearBonds() {
if (!nrf52Bluetooth) {
nrf52Bluetooth = new NRF52Bluetooth();
nrf52Bluetooth->setup();
}
nrf52Bluetooth->clearBonds();
} }