Skip to content

Commit 2cc1a14

Browse files
committed
Find client by handle during disconnect event.
Rather than searching the client list by connection address, search by connection handle. This avoids an issue where the target device has RPA enabled and addresses will not match. Additionally, update the client peer address with the ID address when the identity has been resolved.
1 parent 6f0b9dd commit 2cc1a14

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/NimBLEClient.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -934,11 +934,7 @@ int NimBLEClient::handleGapEvent(struct ble_gap_event* event, void* arg) {
934934
switch (event->type) {
935935
case BLE_GAP_EVENT_DISCONNECT: {
936936

937-
// workaround for bug in NimBLE stack where disconnect event argument is not passed correctly
938-
pClient = NimBLEDevice::getClientByPeerAddress(event->disconnect.conn.peer_ota_addr);
939-
if (pClient == nullptr) {
940-
pClient = NimBLEDevice::getClientByPeerAddress(event->disconnect.conn.peer_id_addr);
941-
}
937+
pClient = NimBLEDevice::getClientByHandle(event->disconnect.conn.conn_handle);
942938

943939
if (pClient == nullptr) {
944940
NIMBLE_LOGE(LOG_TAG, "Disconnected client not found, conn_handle=%d",
@@ -1156,6 +1152,7 @@ int NimBLEClient::handleGapEvent(struct ble_gap_event* event, void* arg) {
11561152
break;
11571153
}
11581154

1155+
pClient->setPeerAddress(peerInfo.getIdAddress());
11591156
pClient->m_pClientCallbacks->onIdentity(peerInfo);
11601157
break;
11611158
} // BLE_GAP_EVENT_IDENTITY_RESOLVED

0 commit comments

Comments
 (0)