summaryrefslogtreecommitdiff
path: root/src/components/ble/NimbleController.h
diff options
context:
space:
mode:
authorJames A. Jerkins <evergreen@jamesjerkinscomputer.com>2021-12-04 14:49:49 -0600
committerJF <JF002@users.noreply.github.com>2021-12-09 21:14:16 +0100
commit150fa3b6615e524a072a1af6d6728519381fa737 (patch)
tree32d3a0f5885c5d51ed5db405e67a7b14f83142f9 /src/components/ble/NimbleController.h
parent1e4130a9cfe6e1385d83d93e544d1e1cd79f11f8 (diff)
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.
Diffstat (limited to 'src/components/ble/NimbleController.h')
-rw-r--r--src/components/ble/NimbleController.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/components/ble/NimbleController.h b/src/components/ble/NimbleController.h
index 895b87f2..944e8cad 100644
--- a/src/components/ble/NimbleController.h
+++ b/src/components/ble/NimbleController.h
@@ -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;
}
}