Skip to content

Commit 69cff9a

Browse files
committed
[Bugfix] HCI response to disconnect of unknown ID should return success.
* Update macro use to use conversion macros.
1 parent afe1221 commit 69cff9a

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

src/NimBLEClient.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ bool NimBLEClient::secureConnection(bool async) const {
354354
if (NimBLEDevice::startSecurity(m_connHandle)) {
355355
NimBLEUtils::taskWait(taskData, BLE_NPL_TIME_FOREVER);
356356
}
357-
} while (taskData.m_flags == (BLE_HS_ERR_HCI_BASE + BLE_ERR_PINKEY_MISSING) && retryCount--);
357+
} while (taskData.m_flags == BLE_HS_HCI_ERR(BLE_ERR_PINKEY_MISSING) && retryCount--);
358358

359359
m_pTaskData = nullptr;
360360

@@ -364,7 +364,10 @@ bool NimBLEClient::secureConnection(bool async) const {
364364
}
365365

366366
m_lastErr = taskData.m_flags;
367-
NIMBLE_LOGE(LOG_TAG, "secureConnection: failed rc=%d", taskData.m_flags);
367+
NIMBLE_LOGE(LOG_TAG,
368+
"secureConnection: failed rc=%d %s",
369+
taskData.m_flags,
370+
NimBLEUtils::returnCodeToString(taskData.m_flags));
368371
return false;
369372

370373
} // secureConnection
@@ -375,13 +378,13 @@ bool NimBLEClient::secureConnection(bool async) const {
375378
*/
376379
bool NimBLEClient::disconnect(uint8_t reason) {
377380
int rc = ble_gap_terminate(m_connHandle, reason);
378-
if (rc != 0 && rc != BLE_HS_ENOTCONN && rc != BLE_HS_EALREADY) {
381+
if (rc != 0 && rc != BLE_HS_ENOTCONN && rc != BLE_HS_EALREADY && rc != BLE_HS_HCI_ERR(BLE_ERR_UNK_CONN_ID)) {
379382
NIMBLE_LOGE(LOG_TAG, "ble_gap_terminate failed: rc=%d %s", rc, NimBLEUtils::returnCodeToString(rc));
380383
m_lastErr = rc;
381384
return false;
382385
}
383386

384-
m_connStatus = (rc == BLE_HS_ENOTCONN) ? DISCONNECTED : DISCONNECTING;
387+
m_connStatus = rc == BLE_HS_ENOTCONN ? DISCONNECTED : DISCONNECTING;
385388
return true;
386389
} // disconnect
387390

@@ -1051,7 +1054,7 @@ int NimBLEClient::handleGapEvent(struct ble_gap_event* event, void* arg) {
10511054
// set this incase the client instance was changed due to incorrect event arg bug above
10521055
pTaskData = pClient->m_pTaskData;
10531056

1054-
const int connEstablishFailReason = BLE_HS_ERR_HCI_BASE + BLE_ERR_CONN_ESTABLISHMENT;
1057+
const int connEstablishFailReason = BLE_HS_HCI_ERR(BLE_ERR_CONN_ESTABLISHMENT);
10551058
if (rc == connEstablishFailReason && pClient->m_connectFailRetryCount < pClient->m_config.connectFailRetries) {
10561059
pClient->m_connHandle = BLE_HS_CONN_HANDLE_NONE;
10571060
++pClient->m_connectFailRetryCount;
@@ -1263,16 +1266,15 @@ int NimBLEClient::handleGapEvent(struct ble_gap_event* event, void* arg) {
12631266
pTaskData = nullptr;
12641267
}
12651268

1266-
if (event->enc_change.status == 0 ||
1267-
event->enc_change.status == (BLE_HS_ERR_HCI_BASE + BLE_ERR_PINKEY_MISSING)) {
1269+
if (event->enc_change.status == 0 || event->enc_change.status == BLE_HS_HCI_ERR(BLE_ERR_PINKEY_MISSING)) {
12681270
NimBLEConnInfo peerInfo;
12691271
rc = ble_gap_conn_find(event->enc_change.conn_handle, &peerInfo.m_desc);
12701272
if (rc != 0) {
12711273
rc = 0;
12721274
break;
12731275
}
12741276

1275-
if (event->enc_change.status == (BLE_HS_ERR_HCI_BASE + BLE_ERR_PINKEY_MISSING)) {
1277+
if (event->enc_change.status == BLE_HS_HCI_ERR(BLE_ERR_PINKEY_MISSING)) {
12761278
// Key is missing, try deleting.
12771279
ble_store_util_delete_peer(&peerInfo.m_desc.peer_id_addr);
12781280
// Attempt a retry if async secure failed.

src/NimBLEServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ bool NimBLEServer::start() {
335335
*/
336336
bool NimBLEServer::disconnect(uint16_t connHandle, uint8_t reason) const {
337337
int rc = ble_gap_terminate(connHandle, reason);
338-
if (rc != 0 && rc != BLE_HS_ENOTCONN && rc != BLE_HS_EALREADY) {
338+
if (rc != 0 && rc != BLE_HS_ENOTCONN && rc != BLE_HS_EALREADY && rc != BLE_HS_HCI_ERR(BLE_ERR_UNK_CONN_ID)) {
339339
NIMBLE_LOGE(LOG_TAG, "ble_gap_terminate failed: rc=%d %s", rc, NimBLEUtils::returnCodeToString(rc));
340340
return false;
341341
}

0 commit comments

Comments
 (0)