From 8158a16fbf3d716fd2dd16f6f8990c12265aefe7 Mon Sep 17 00:00:00 2001 From: Guo-Rong <5484552+gkoh@users.noreply.github.com> Date: Thu, 16 Jan 2025 12:01:47 +1030 Subject: [PATCH] Fix characteristic discovery with no descriptors. Avoid discovery of descriptors if there are no handles remaining. --- src/NimBLERemoteCharacteristic.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/NimBLERemoteCharacteristic.cpp b/src/NimBLERemoteCharacteristic.cpp index b9c16c7..bac8574 100644 --- a/src/NimBLERemoteCharacteristic.cpp +++ b/src/NimBLERemoteCharacteristic.cpp @@ -101,6 +101,12 @@ int NimBLERemoteCharacteristic::descriptorDiscCB( bool NimBLERemoteCharacteristic::retrieveDescriptors(const NimBLEUUID* uuidFilter) const { NIMBLE_LOGD(LOG_TAG, ">> retrieveDescriptors() for characteristic: %s", getUUID().toString().c_str()); + // If this is the last handle then there are no descriptors + if (getHandle() == getRemoteService()->getEndHandle()) { + NIMBLE_LOGD(LOG_TAG, "<< retrieveDescriptors(): found 0 descriptors."); + return true; + } + NimBLETaskData taskData(const_cast(this)); desc_filter_t filter = {uuidFilter, &taskData};