Skip to content

Commit 345ef03

Browse files
authored
Fix pairing when already in progress. (#469)
If pairing is requested before performing an action on a protected attribute pairing could fail due to already being in progress. This fix will wait for the result of the pairing process before proceeding with the action.
1 parent 57cd0c1 commit 345ef03

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/NimBLEClient.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttributes)
336336
* @return True on success.
337337
*/
338338
bool NimBLEClient::secureConnection() {
339+
NIMBLE_LOGD(LOG_TAG, ">> secureConnection()");
339340
TaskHandle_t cur_task = xTaskGetCurrentTaskHandle();
340341
ble_task_data_t taskData = {this, cur_task, 0, nullptr};
341342

@@ -345,7 +346,7 @@ bool NimBLEClient::secureConnection() {
345346
m_pTaskData = &taskData;
346347

347348
int rc = NimBLEDevice::startSecurity(m_conn_id);
348-
if(rc != 0){
349+
if(rc != 0 && rc != BLE_HS_EALREADY){
349350
m_lastErr = rc;
350351
m_pTaskData = nullptr;
351352
return false;
@@ -360,9 +361,11 @@ bool NimBLEClient::secureConnection() {
360361

361362
if(taskData.rc != 0){
362363
m_lastErr = taskData.rc;
364+
NIMBLE_LOGE(LOG_TAG, "secureConnection: failed rc=%d", taskData.rc);
363365
return false;
364366
}
365367

368+
NIMBLE_LOGD(LOG_TAG, "<< secureConnection: success");
366369
return true;
367370
} // secureConnection
368371

0 commit comments

Comments
 (0)