Skip to content

Commit 61543b2

Browse files
committed
fix: correct duplicate descriptor handle assignment for same-UUID descriptors
When multiple GATT descriptors share the same UUID (e.g. 0x2904 Presentation Format), NimBLEServer::start() incorrectly assigned them all the same handle due to ble_gatts_find_dsc() performing a UUID-only lookup.
1 parent 5dad893 commit 61543b2

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/NimBLEServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ void NimBLEServer::start() {
210210
// Set the descriptor handles now as the stack does not set these when the service is started
211211
for (const auto& chr : svc->m_vChars) {
212212
for (auto& desc : chr->m_vDescriptors) {
213-
ble_gatts_find_dsc(svc->getUUID().getBase(), chr->getUUID().getBase(), desc->getUUID().getBase(), &desc->m_handle);
213+
ble_gatts_find_dsc(svc->getUUID().getBase(), chr->getUUID().getBase(), desc->getUUID().getBase(), desc, &desc->m_handle);
214214
}
215215
}
216216
}

src/nimble/nimble/host/include/host/ble_gatt.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,11 @@ int ble_gatts_find_chr(const ble_uuid_t *svc_uuid, const ble_uuid_t *chr_uuid,
13601360
*
13611361
* @param svc_uuid The UUID of the grandparent service.
13621362
* @param chr_uuid The UUID of the parent characteristic.
1363-
* @param dsc_uuid The UUID of the descriptor ro look up.
1363+
* @param dsc_uuid The UUID of the descriptor to look up.
1364+
* @param dsc_arg The descriptor argument; a pointer to a
1365+
* NimBLEDescriptor instance used to search
1366+
* across multiple descriptors sharing
1367+
* the same UUID.
13641368
* @param out_dsc_handle On success, populated with the handle
13651369
* of the descriptor attribute. Pass null if
13661370
* you don't need this value.
@@ -1371,7 +1375,7 @@ int ble_gatts_find_chr(const ble_uuid_t *svc_uuid, const ble_uuid_t *chr_uuid,
13711375
* found.
13721376
*/
13731377
int ble_gatts_find_dsc(const ble_uuid_t *svc_uuid, const ble_uuid_t *chr_uuid,
1374-
const ble_uuid_t *dsc_uuid, uint16_t *out_dsc_handle);
1378+
const ble_uuid_t *dsc_uuid, void* dsc_arg, uint16_t *out_dsc_handle);
13751379

13761380
/** Type definition for GATT service iteration callback function. */
13771381
typedef void (*ble_gatt_svc_foreach_fn)(const struct ble_gatt_svc_def *svc,

src/nimble/nimble/host/src/ble_gatts.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2740,7 +2740,7 @@ ble_gatts_find_chr(const ble_uuid_t *svc_uuid, const ble_uuid_t *chr_uuid,
27402740

27412741
int
27422742
ble_gatts_find_dsc(const ble_uuid_t *svc_uuid, const ble_uuid_t *chr_uuid,
2743-
const ble_uuid_t *dsc_uuid, uint16_t *out_handle)
2743+
const ble_uuid_t *dsc_uuid, void* dsc_arg, uint16_t *out_handle)
27442744
{
27452745
struct ble_gatts_svc_entry *svc_entry;
27462746
struct ble_att_svr_entry *att_chr;
@@ -2772,7 +2772,7 @@ ble_gatts_find_dsc(const ble_uuid_t *svc_uuid, const ble_uuid_t *chr_uuid,
27722772
return BLE_HS_ENOENT;
27732773
}
27742774

2775-
if (ble_uuid_cmp(cur->ha_uuid, dsc_uuid) == 0) {
2775+
if (ble_uuid_cmp(cur->ha_uuid, dsc_uuid) == 0 && (dsc_arg == NULL || (dsc_arg != NULL && cur->ha_cb_arg == dsc_arg))) {
27762776
if (out_handle != NULL) {
27772777
*out_handle = cur->ha_handle_id;
27782778
return 0;

0 commit comments

Comments
 (0)