Skip to content

nimble/host: guard ble_gattc_cache_refresh() with BLE_GATTC - #128

Open
acouvreur wants to merge 1 commit into
espressif:nimble-1.6.0-idffrom
acouvreur:fix/gattc-cache-refresh-without-gattc
Open

nimble/host: guard ble_gattc_cache_refresh() with BLE_GATTC#128
acouvreur wants to merge 1 commit into
espressif:nimble-1.6.0-idffrom
acouvreur:fix/gattc-cache-refresh-without-gattc

Conversation

@acouvreur

Copy link
Copy Markdown

Summary

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 defined only
inside #if MYNEWT_VAL(BLE_GATTC) blocks. On a server-only build
(BLE_GATT_CACHING && !BLE_GATTC) it fails to compile:

ble_gattc_cache_conn.c: In function 'ble_gattc_cache_refresh':
error: implicit declaration of function 'ble_gattc_cache_conn_disc';
       did you mean 'ble_gattc_cache_conn_find'?

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_mgr BLE_CONN_MGR_GATT_CHANGED_AUTO, which selects
BT_NIMBLE_GATT_CACHING while BT_NIMBLE_GATT_CLIENT (→ BLE_GATTC) stays off
because 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_ENOTSUP when the GATT client is absent — there is no peer
cache to refresh without it. The public symbol remains available so server-only
builds with caching link cleanly.

Minimal, no behavior change when BLE_GATTC is enabled.

Fixes #127

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>
peer->cache_state = CACHE_INVALID;
}
}
#endif

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should just move this #endif after the ble_gattc_cache_refresh function instead of the current change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ble_gattc_cache_refresh() fails to build with BLE_GATT_CACHING enabled but BLE_GATTC disabled (server-only/peripheral)

1 participant