Skip to content

Commit 2ecfc40

Browse files
committed
Workaround for bug in NimBLE stack when connect re-attempt enabled.
Connect reattempt does not pass the arg parameter correctly and the disconnect event will have no client pointer in the argument. This finds the client from the connection handle to compensate.
1 parent e366800 commit 2ecfc40

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/NimBLEClient.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,12 @@ int NimBLEClient::handleGapEvent(struct ble_gap_event* event, void* arg) {
909909

910910
switch (event->type) {
911911
case BLE_GAP_EVENT_DISCONNECT: {
912+
// workaround for bug in NimBLE stack where disconnect event argument is not passed correctly
913+
pClient = NimBLEDevice::getClientByHandle(event->disconnect.conn.conn_handle);
914+
if (pClient == nullptr) {
915+
return 0;
916+
}
917+
912918
rc = event->disconnect.reason;
913919
// If Host reset tell the device now before returning to prevent
914920
// any errors caused by calling host functions before resyncing.
@@ -921,11 +927,6 @@ int NimBLEClient::handleGapEvent(struct ble_gap_event* event, void* arg) {
921927
NimBLEDevice::onReset(rc);
922928
break;
923929
default:
924-
// Check that the event is for this client.
925-
if (pClient->m_connHandle != event->disconnect.conn.conn_handle) {
926-
return 0;
927-
}
928-
929930
break;
930931
}
931932

0 commit comments

Comments
 (0)