Skip to content

Commit ceaed8e

Browse files
committed
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.
1 parent e9b014e commit ceaed8e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

nimble/host/src/ble_gatts.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,7 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
904904
uint16_t val_handle;
905905
uint16_t dsc_handle;
906906
uint16_t cep_handle;
907+
uint16_t expected_handle;
907908
uint8_t att_flags;
908909
int rc;
909910

@@ -927,6 +928,9 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
927928
return rc;
928929
}
929930

931+
expected_handle = def_handle;
932+
(void)expected_handle;
933+
930934
/* Register characteristic value attribute (cast away const on callback
931935
* arg).
932936
*/
@@ -937,7 +941,7 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
937941
if (rc != 0) {
938942
return rc;
939943
}
940-
BLE_HS_DBG_ASSERT(val_handle == def_handle + 1);
944+
BLE_HS_DBG_ASSERT(val_handle == ++expected_handle);
941945

942946
if (chr->val_handle != NULL) {
943947
*chr->val_handle = val_handle;
@@ -957,15 +961,15 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
957961
if (rc != 0) {
958962
return rc;
959963
}
960-
BLE_HS_DBG_ASSERT(dsc_handle == def_handle + 2);
964+
BLE_HS_DBG_ASSERT(dsc_handle == ++expected_handle);
961965
}
962966

963967
if (ble_gatts_chr_ext_prop_allowed(chr) != 0) {
964968
rc = ble_gatts_register_cep_dsc(&cep_handle, chr->flags);
965969
if (rc != 0) {
966970
return rc;
967971
}
968-
BLE_HS_DBG_ASSERT(cep_handle == def_handle + 3);
972+
BLE_HS_DBG_ASSERT(cep_handle == ++expected_handle);
969973
}
970974

971975
/* Register each descriptor. */

0 commit comments

Comments
 (0)