From 65cd834ce65d20bc51df716f231ec36b4df5f850 Mon Sep 17 00:00:00 2001 From: h2zero Date: Sun, 25 Feb 2024 15:07:42 -0700 Subject: [PATCH] Set characteristic cpfd to null to prevent crashing when registering characteristic. * TODO: remove or embrace this new addition. --- src/NimBLEService.cpp | 1 + src/nimble/nimble/host/include/host/ble_gatt.h | 2 +- src/nimble/nimble/host/src/ble_gatts.c | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/NimBLEService.cpp b/src/NimBLEService.cpp index 6c4780c8..6d0247c8 100644 --- a/src/NimBLEService.cpp +++ b/src/NimBLEService.cpp @@ -212,6 +212,7 @@ bool NimBLEService::start() { pChr_a[i].flags = (*chr_it)->m_properties; pChr_a[i].min_key_size = 0; pChr_a[i].val_handle = &(*chr_it)->m_handle; + pChr_a[i].cpfd = nullptr; ++i; } diff --git a/src/nimble/nimble/host/include/host/ble_gatt.h b/src/nimble/nimble/host/include/host/ble_gatt.h index 56ff604d..3c24367e 100644 --- a/src/nimble/nimble/host/include/host/ble_gatt.h +++ b/src/nimble/nimble/host/include/host/ble_gatt.h @@ -882,7 +882,7 @@ struct ble_gatt_cpfd { uint16_t unit; /** The name space of the description. */ - uint8_t namespace_; + uint8_t name_space; /** The description of this characteristic. Depends on name space. */ uint16_t description; diff --git a/src/nimble/nimble/host/src/ble_gatts.c b/src/nimble/nimble/host/src/ble_gatts.c index d9e8e9e9..66475759 100644 --- a/src/nimble/nimble/host/src/ble_gatts.c +++ b/src/nimble/nimble/host/src/ble_gatts.c @@ -761,7 +761,7 @@ ble_gatts_cpfd_is_sane(const struct ble_gatt_cpfd *cpfd) return 0; } - if ((cpfd->namespace_ == BLE_GATT_CHR_NAMESPACE_BT_SIG) && (cpfd->description > 0x0110)) { + if ((cpfd->name_space == BLE_GATT_CHR_NAMESPACE_BT_SIG) && (cpfd->description > 0x0110)) { return 0; } @@ -1058,7 +1058,7 @@ ble_gatts_cpfd_access(uint16_t conn_handle, uint16_t attr_handle, rc += os_mbuf_append(*om, &(cpfd->format), sizeof(cpfd->format)); rc += os_mbuf_append(*om, &(cpfd->exponent), sizeof(cpfd->exponent)); rc += os_mbuf_append(*om, &(cpfd->unit), sizeof(cpfd->unit)); - rc += os_mbuf_append(*om, &(cpfd->namespace_), sizeof(cpfd->namespace_)); + rc += os_mbuf_append(*om, &(cpfd->name_space), sizeof(cpfd->name_space)); rc += os_mbuf_append(*om, &(cpfd->description), sizeof(cpfd->description)); return ((rc == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES);