Fix pairing when already in progress.

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.
This commit is contained in:
h2zero 2022-10-23 19:15:57 -06:00 committed by h2zero
parent 05ac9deaea
commit 7d2d73d8fc

View file

@ -336,6 +336,7 @@ bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttributes)
* @return True on success. * @return True on success.
*/ */
bool NimBLEClient::secureConnection() { bool NimBLEClient::secureConnection() {
NIMBLE_LOGD(LOG_TAG, ">> secureConnection()");
TaskHandle_t cur_task = xTaskGetCurrentTaskHandle(); TaskHandle_t cur_task = xTaskGetCurrentTaskHandle();
ble_task_data_t taskData = {this, cur_task, 0, nullptr}; ble_task_data_t taskData = {this, cur_task, 0, nullptr};
@ -345,7 +346,7 @@ bool NimBLEClient::secureConnection() {
m_pTaskData = &taskData; m_pTaskData = &taskData;
int rc = NimBLEDevice::startSecurity(m_conn_id); int rc = NimBLEDevice::startSecurity(m_conn_id);
if(rc != 0){ if(rc != 0 && rc != BLE_HS_EALREADY){
m_lastErr = rc; m_lastErr = rc;
m_pTaskData = nullptr; m_pTaskData = nullptr;
return false; return false;
@ -360,9 +361,11 @@ bool NimBLEClient::secureConnection() {
if(taskData.rc != 0){ if(taskData.rc != 0){
m_lastErr = taskData.rc; m_lastErr = taskData.rc;
NIMBLE_LOGE(LOG_TAG, "secureConnection: failed rc=%d", taskData.rc);
return false; return false;
} }
NIMBLE_LOGD(LOG_TAG, "<< secureConnection: success");
return true; return true;
} // secureConnection } // secureConnection