nimble/host: guard ble_gattc_cache_refresh() with BLE_GATTC - #128
Open
acouvreur wants to merge 1 commit into
Open
nimble/host: guard ble_gattc_cache_refresh() with BLE_GATTC#128acouvreur wants to merge 1 commit into
acouvreur wants to merge 1 commit into
Conversation
ble_gattc_cache_refresh() is compiled whenever BLE_GATT_CACHING is enabled, but its body calls ble_gattc_cache_conn_find_by_addr(), ble_gattc_cacheReset() and ble_gattc_cache_conn_disc(), all of which are defined only inside #if MYNEWT_VAL(BLE_GATTC) blocks. On a server-only build (peripheral that enables GATT caching for the Database Hash / Service Changed feature, e.g. via esp-idf's ble_conn_mgr BLE_CONN_MGR_GATT_CHANGED_AUTO which selects BT_NIMBLE_GATT_CACHING) the GATT client is absent, so the function fails to build: error: implicit declaration of function 'ble_gattc_cache_conn_disc' Guard the body with MYNEWT_VAL(BLE_GATTC) and return BLE_HS_ENOTSUP when the client is not present, since there is no peer cache to refresh without it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
acouvreur
commented
Jun 26, 2026
| peer->cache_state = CACHE_INVALID; | ||
| } | ||
| } | ||
| #endif |
Author
There was a problem hiding this comment.
I'm wondering if we should just move this #endif after the ble_gattc_cache_refresh function instead of the current change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ble_gattc_cache_refresh()is compiled wheneverBLE_GATT_CACHINGis enabled,but its body calls
ble_gattc_cache_conn_find_by_addr(),ble_gattc_cacheReset()andble_gattc_cache_conn_disc()— all defined onlyinside
#if MYNEWT_VAL(BLE_GATTC)blocks. On a server-only build(
BLE_GATT_CACHING && !BLE_GATTC) it fails to compile:This combination is reached on peripheral/GATT-server-only products that enable
GATT caching for the Database Hash / Service Changed feature — e.g. ESP-IDF's
ble_conn_mgrBLE_CONN_MGR_GATT_CHANGED_AUTO, whichselectsBT_NIMBLE_GATT_CACHINGwhileBT_NIMBLE_GATT_CLIENT(→BLE_GATTC) stays offbecause it depends on the central role.
Fix
Guard the body of
ble_gattc_cache_refresh()with#if MYNEWT_VAL(BLE_GATTC)and return
BLE_HS_ENOTSUPwhen the GATT client is absent — there is no peercache to refresh without it. The public symbol remains available so server-only
builds with caching link cleanly.
Minimal, no behavior change when
BLE_GATTCis enabled.Fixes #127