Skip to content

bluetooth: add server-side GATT caching support#1708

Draft
gmarull wants to merge 4 commits into
coredevices:mainfrom
teslabs:gatt-hash-new
Draft

bluetooth: add server-side GATT caching support#1708
gmarull wants to merge 4 commits into
coredevices:mainfrom
teslabs:gatt-hash-new

Conversation

@gmarull

@gmarull gmarull commented Jul 14, 2026

Copy link
Copy Markdown
Member

Stacked on #1705 (the first two commits — Mbed TLS + NimBLE upstream master migration — belong to that PR; only the last three commits are new here). Will be rebased once #1705 merges.

Add server-side GATT caching (Core spec v5.4, Vol 3, Part G, 2.5.2 and 7.3):

  • third_party/nimble: move the submodule to the gatt-hash-new branch, which carries the GATT caching series on top of upstream master (Database Hash characteristic 0x2B2A, CSFC/database hash store object types, Database Out Of Sync ATT error, robust caching state machine), and enable BLE_GATT_CACHING for both SoC targets.
  • services/bluetooth: new persistent storage record for GATT caching state.
  • bluetooth-fw/nimble: handle the new store object types in the NimBLE store glue. Per-bonded-peer Client Supported Features and change-aware state are kept in a RAM list, serialized into the new storage record, and lazily loaded on first access.

With this, a bonded phone that enabled robust caching gets a Database Out Of Sync ATT error when it operates on stale attribute handles after a firmware update changed the GATT database, instead of silently misbehaving, and clients can detect database changes deterministically by reading the hash on reconnection. Awareness state survives reboots on both sides.

The NimBLE series is intended to be submitted to apache/mynewt-nimble; the submodule branch keeps it rebased on upstream master for that purpose.

Build-verified on asterix and obelix.

🤖 Generated with Claude Code

gmarull and others added 4 commits July 21, 2026 23:09
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
Pull NimBLE support for the GATT Database Hash characteristic (0x2B2A,
Core spec v5.4, Vol 3, Part G, 7.3.1) by moving the submodule to the
gatt-hash-new branch, which carries the GATT caching series on top of
upstream master, and enable BLE_GATT_CACHING for both SoC targets, in
the generated syscfg headers and in the syscfg generation project.

Clients that cache the attribute database (notably iOS and Android) can
now detect database changes across firmware updates deterministically
by reading the hash on reconnection, instead of relying only on Service
Changed indications.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
Add storage for the GATT caching peer state table (an opaque
driver-defined blob) and the local GATT database hash, stored as
singleton records in the bonding settings file. PRF does not persist
either, matching its CCCD storage stubs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
Pull NimBLE support for server-side GATT robust caching (Vol 3, Part G,
2.5.2.1) and handle the new store object types in the NimBLE store
glue.

Per-bonded-peer Client Supported Features and change-aware state are
kept in a RAM list, serialized as a fixed-layout blob into the new GATT
caching persistent storage record, and lazily loaded on first access.
Storage I/O happens outside the store mutex, since bt_persistent_storage
holds its own lock while registering records back into this store. The
database hash is read and written through storage directly.

With this, a bonded phone that enabled robust caching gets a Database
Out Of Sync ATT error when it operates on stale attribute handles after
a firmware update changed the GATT database, instead of silently
misbehaving, and its awareness state survives reboots on both sides.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
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.

1 participant