This is an automated email from the ASF dual-hosted git repository.

janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git


The following commit(s) were added to refs/heads/master by this push:
     new ceaed8e47 nimble/host: Fix assert when registering GATT server 
characteristics
ceaed8e47 is described below

commit ceaed8e47650c39a7a79780fc1f6c34df9b5f2c7
Author: Szymon Janc <[email protected]>
AuthorDate: Fri Dec 12 14:59:05 2025 +0100

    nimble/host: Fix assert when registering GATT server characteristics
    
    If CEP is used, but no CCD than expected handle may vary. Instead of
    hardcoded value use variable for tracking expected next handle.
---
 nimble/host/src/ble_gatts.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/nimble/host/src/ble_gatts.c b/nimble/host/src/ble_gatts.c
index dcd403e12..5d522aed7 100644
--- a/nimble/host/src/ble_gatts.c
+++ b/nimble/host/src/ble_gatts.c
@@ -904,6 +904,7 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
     uint16_t val_handle;
     uint16_t dsc_handle;
     uint16_t cep_handle;
+    uint16_t expected_handle;
     uint8_t att_flags;
     int rc;
 
@@ -927,6 +928,9 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
         return rc;
     }
 
+    expected_handle = def_handle;
+    (void)expected_handle;
+
     /* Register characteristic value attribute (cast away const on callback
      * arg).
      */
@@ -937,7 +941,7 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
     if (rc != 0) {
         return rc;
     }
-    BLE_HS_DBG_ASSERT(val_handle == def_handle + 1);
+    BLE_HS_DBG_ASSERT(val_handle == ++expected_handle);
 
     if (chr->val_handle != NULL) {
         *chr->val_handle = val_handle;
@@ -957,7 +961,7 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
         if (rc != 0) {
             return rc;
         }
-        BLE_HS_DBG_ASSERT(dsc_handle == def_handle + 2);
+        BLE_HS_DBG_ASSERT(dsc_handle == ++expected_handle);
     }
 
     if (ble_gatts_chr_ext_prop_allowed(chr) != 0) {
@@ -965,7 +969,7 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
         if (rc != 0) {
             return rc;
         }
-        BLE_HS_DBG_ASSERT(cep_handle == def_handle + 3);
+        BLE_HS_DBG_ASSERT(cep_handle == ++expected_handle);
     }
 
     /* Register each descriptor. */

Reply via email to