From 2bec081589aa110f5130ef55f538853867e68ab7 Mon Sep 17 00:00:00 2001 From: h2zero Date: Sat, 11 Jan 2025 16:47:47 -0700 Subject: [PATCH] Fix Windows notifications not being sent on reconnection. When Windows bonds with a device and subscribes to notifications/indications of the device characteristics it does not re-subscribe on subsequent connections. If a notification is sent when Windows reconnects it will overwrite the stored subscription value in the NimBLE stack configuration with an invalid value which results in notifications/indications not being sent. This change will ensure that no notification or indication is sent before authentication upon reconnection, avoiding the described issue described above. --- BleConnectionStatus.cpp | 6 +++++- BleConnectionStatus.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/BleConnectionStatus.cpp b/BleConnectionStatus.cpp index e029a9a..4a48287 100644 --- a/BleConnectionStatus.cpp +++ b/BleConnectionStatus.cpp @@ -7,10 +7,14 @@ BleConnectionStatus::BleConnectionStatus(void) void BleConnectionStatus::onConnect(NimBLEServer *pServer, NimBLEConnInfo& connInfo) { pServer->updateConnParams(connInfo.getConnHandle(), 6, 7, 0, 600); - this->connected = true; } void BleConnectionStatus::onDisconnect(NimBLEServer* pServer, NimBLEConnInfo& connInfo, int reason) { this->connected = false; } + +void BleConnectionStatus::onAuthenticationComplete(NimBLEConnInfo& connInfo) +{ + this->connected = true; +} diff --git a/BleConnectionStatus.h b/BleConnectionStatus.h index e4b57e6..bf2b152 100644 --- a/BleConnectionStatus.h +++ b/BleConnectionStatus.h @@ -17,6 +17,7 @@ class BleConnectionStatus : public NimBLEServerCallbacks bool connected = false; void onConnect(NimBLEServer *pServer, NimBLEConnInfo& connInfo) override; void onDisconnect(NimBLEServer *pServer, NimBLEConnInfo& connInfo, int reason) override; + void onAuthenticationComplete(NimBLEConnInfo& connInfo) override; NimBLECharacteristic *inputGamepad; };