Persist bond between reboots

Save bond information in the FS after a disconnect or encryption change
if the bond is not already stored. The bond is restored on boot enabling
automatic reconnection to a previously bonded central.

Two consecutive watch reboots with the central out of range (or BLE off)
will remove the stored bond from the watch.
This commit is contained in:
James A. Jerkins
2021-12-04 14:49:49 -06:00
committed by JF
parent 1e4130a9cf
commit 150fa3b661
3 changed files with 117 additions and 10 deletions

View File

@@ -20,6 +20,7 @@
#include "components/ble/ServiceDiscovery.h"
#include "components/ble/HeartRateService.h"
#include "components/ble/MotionService.h"
#include "components/fs/FS.h"
namespace Pinetime {
namespace Drivers {
@@ -45,7 +46,8 @@ namespace Pinetime {
Controllers::Battery& batteryController,
Pinetime::Drivers::SpiNorFlash& spiNorFlash,
Controllers::HeartRateController& heartRateController,
Controllers::MotionController& motionController);
Controllers::MotionController& motionController,
Pinetime::Controllers::FS& fs);
void Init();
void StartAdvertising();
int OnGAPEvent(ble_gap_event* event);
@@ -78,6 +80,9 @@ namespace Pinetime {
fastAdvCount = 0;
}
void PersistBond(struct ble_gap_conn_desc &desc);
void RestoreBond();
private:
static constexpr const char* deviceName = "InfiniTime";
Pinetime::System::SystemTask& systemTask;
@@ -98,10 +103,12 @@ namespace Pinetime {
ImmediateAlertService immediateAlertService;
HeartRateService heartRateService;
MotionService motionService;
Pinetime::Controllers::FS& fs;
uint8_t addrType; // 1 = Random, 0 = PUBLIC
uint16_t connectionHandle = BLE_HS_CONN_HANDLE_NONE;
uint8_t fastAdvCount = 0;
uint8_t bondId[16] = {0};
ble_uuid128_t dfuServiceUuid {
.u {.type = BLE_UUID_TYPE_128},
@@ -110,6 +117,6 @@ namespace Pinetime {
ServiceDiscovery serviceDiscovery;
};
static NimbleController* nptr;
static NimbleController* nptr;
}
}