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

* Clear bluetooth bonds on multi-press and factory_reset
pull/1177/head^2
Ben Meadors 2022-02-01 18:32:26 -06:00 zatwierdzone przez GitHub
rodzic dd31a829fb
commit b21b7de04b
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
6 zmienionych plików z 40 dodań i 2 usunięć

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

@ -26,6 +26,11 @@
#include <nvs_flash.h>
#endif
#ifdef NRF52_SERIES
#include <bluefruit.h>
#include <utility/bonding.h>
#endif
NodeDB nodeDB;
// we have plenty of ram so statically alloc this tempbuf (for now)
@ -90,6 +95,16 @@ bool NodeDB::resetRadioConfig()
#ifndef NO_ESP32
// This will erase what's in NVS including ssl keys, persistant variables and ble pairing
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
didFactoryReset = true;
}

Wyświetl plik

@ -5,6 +5,7 @@
#include "mesh/PhoneAPI.h"
#include "mesh/mesh-pb-constants.h"
#include <bluefruit.h>
#include <utility/bonding.h>
static BLEService meshBleService = BLEService(BLEUuid(MESH_SERVICE_UUID_16));
static BLECharacteristic fromNum = BLECharacteristic(BLEUuid(FROMNUM_UUID_16));
@ -266,3 +267,13 @@ void updateBatteryLevel(uint8_t 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();
}

Wyświetl plik

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

Wyświetl plik

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