From 0e798b570aca7cf7ee5154eeb32c734667292ffe Mon Sep 17 00:00:00 2001 From: Nebojsa Cvetkovic Date: Wed, 28 May 2025 22:22:56 +0100 Subject: [PATCH 1/2] fix(nimble): Prevent crash when only using dynamic services --- nimble/host/src/ble_gatts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nimble/host/src/ble_gatts.c b/nimble/host/src/ble_gatts.c index 941d2d8001..d94b94a795 100644 --- a/nimble/host/src/ble_gatts.c +++ b/nimble/host/src/ble_gatts.c @@ -2868,7 +2868,7 @@ int ble_gatts_add_dynamic_svcs(const struct ble_gatt_svc_def *svcs) { ble_gatts_free_svc_defs(); /* Fill the cache. */ cfg = ble_gatts_get_last_cfg(&ble_gatts_clt_cfgs); - ha = ble_att_svr_find_by_handle(cfg->chr_val_handle - 1); + ha = cfg == NULL ? NULL : ble_att_svr_find_by_handle(cfg->chr_val_handle - 1); while ((ha = ble_att_svr_find_by_uuid(ha, &uuid.u, 0xffff)) != NULL) { chr = ha->ha_cb_arg; allowed_flags = ble_gatts_chr_clt_cfg_allowed(chr); From deb4cd204b50dfd5bf2925794c9b0105c0e1dfd3 Mon Sep 17 00:00:00 2001 From: Nebojsa Cvetkovic Date: Thu, 29 May 2025 14:42:50 +0100 Subject: [PATCH 2/2] fix(nimble): Allow connections when only using dynamic services When no non-dynamic services have been added the ble_gatts_clt_cfg_pool is empty. Because of this, it reports having no free blocks, as if it was full. We must check if there are any blocks available at all, in case they are all stored in dynamic services. --- nimble/host/src/ble_gatts.c | 1 + 1 file changed, 1 insertion(+) diff --git a/nimble/host/src/ble_gatts.c b/nimble/host/src/ble_gatts.c index d94b94a795..3fa968a8e8 100644 --- a/nimble/host/src/ble_gatts.c +++ b/nimble/host/src/ble_gatts.c @@ -1786,6 +1786,7 @@ int ble_gatts_conn_can_alloc(void) { return ble_gatts_num_cfgable_chrs == 0 || + ble_gatts_clt_cfg_pool.mp_num_blocks == 0 || ble_gatts_clt_cfg_pool.mp_num_free > 0; }