From 7d0636bc910a60e10230bd972c3e84aa8a9a632a Mon Sep 17 00:00:00 2001 From: h2zero Date: Sat, 9 Nov 2024 09:08:22 -0700 Subject: [PATCH] Fix NimBLEClient::secureConnection incorrectly failing with BLE_HS_EAGAIN. --- src/NimBLEClient.cpp | 5 ++--- src/NimBLEDevice.cpp | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/NimBLEClient.cpp b/src/NimBLEClient.cpp index 840137a..a127996 100644 --- a/src/NimBLEClient.cpp +++ b/src/NimBLEClient.cpp @@ -302,9 +302,8 @@ bool NimBLEClient::secureConnection() const { do { m_pTaskData = &taskData; - int rc = NimBLEDevice::startSecurity(m_connHandle); - if (rc != 0 && rc != BLE_HS_EALREADY) { - m_lastErr = rc; + if (!NimBLEDevice::startSecurity(m_connHandle)) { + m_lastErr = BLE_HS_ENOTCONN; m_pTaskData = nullptr; return false; } diff --git a/src/NimBLEDevice.cpp b/src/NimBLEDevice.cpp index 9573bb5..514004d 100644 --- a/src/NimBLEDevice.cpp +++ b/src/NimBLEDevice.cpp @@ -1127,7 +1127,7 @@ bool NimBLEDevice::startSecurity(uint16_t connHandle) { NIMBLE_LOGE(LOG_TAG, "ble_gap_security_initiate: rc=%d %s", rc, NimBLEUtils::returnCodeToString(rc)); } - return rc == 0; + return rc == 0 || rc == BLE_HS_EALREADY; } // startSecurity /**