Skip to content

Commit 67fa477

Browse files
committed
[Bugfix] Remote descriptor not found when char handles out of order
This resolves the issue of retrieving characteristics out of handle order and then trying to subscribe or do some other fetch of a descriptor belonging to that characteristic and the search handle was limited to the handle of the next characteristic in the vector. This ensures that the vector is sorted in ascending order based on handle values so the next characteristic in the vector will always have a higher handle value and the desciptor serach will function as intended.
1 parent 0db2215 commit 67fa477

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/NimBLERemoteService.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
# include "NimBLELog.h"
2626

2727
# include <climits>
28+
# include <algorithm>
2829

2930
static const char* LOG_TAG = "NimBLERemoteService";
3031

@@ -207,6 +208,12 @@ bool NimBLERemoteService::retrieveCharacteristics(const NimBLEUUID* uuidFilter)
207208
NimBLEUtils::taskWait(taskData, BLE_NPL_TIME_FOREVER);
208209
rc = taskData.m_flags;
209210
if (rc == 0 || rc == BLE_HS_EDONE) {
211+
// sort the characteristics vector by handle to make sure the search range for descriptors is correct
212+
std::sort(m_vChars.begin(),
213+
m_vChars.end(),
214+
[](const NimBLERemoteCharacteristic* a, const NimBLERemoteCharacteristic* b) {
215+
return a->getHandle() < b->getHandle();
216+
});
210217
NIMBLE_LOGD(LOG_TAG, "<< retrieveCharacteristics()");
211218
return true;
212219
}

0 commit comments

Comments
 (0)