Commit d8b2ea8
Disable CCCD persistence to prevent flash corruption
This commit intentionally disables the saving of CCCD (Client Characteristic
Configuration Descriptor) values to flash storage while maintaining API
compatibility. This change addresses a critical flash corruption issue that
has been affecting BLE keyboard users.
Problem:
--------
Users have reported that their BLE keyboards fail to reconnect after sleep,
requiring re-pairing. Investigation revealed that bonding data files were
becoming corrupted, particularly during the wake-from-sleep sequence.
Root Cause:
-----------
1. When a device wakes from sleep, the BLE connection is re-established
2. The host automatically re-writes CCCD values to enable notifications
3. These writes are queued via ada_callback() to execute asynchronously
4. The wake period is unstable - connections often drop with errors 0x08
(BLE_HCI_CONNECTION_TIMEOUT) or 0x22 (BLE_HCI_STATUS_CODE_LMP_RESPONSE_TIMEOUT)
5. When disconnection occurs during flash write, the operation is interrupted
6. The flash_cache layer silently ignores write errors, resulting in corrupted data
Why Disable CCCD Saving:
------------------------
1. UNNECESSARY: For HID devices, CCCD values are constant - notifications must
always be enabled for keyboard functionality. Every host writes the same value.
2. DANGEROUS: The post-wake period creates a perfect storm for corruption:
unstable connections + automatic CCCD writes + poor error handling
3. MINIMAL IMPACT: Hosts automatically re-enable notifications on connection.
The only theoretical downside is a 1-2 second delay for non-HID services
like Battery Service, which is negligible.
Implementation:
---------------
- bond_save_cccd() now returns true immediately without writing to flash
- bond_load_cccd() remains functional for compatibility and migration
- BLEGatt.cpp call site preserved to maintain API compatibility
- Extensive comments document the rationale and trade-offs
This eliminates a major corruption vector while having no functional impact
on keyboard operation. The change is backward compatible - existing devices
will load stored CCCDs one final time, then stop saving new values.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>1 parent 56a379b commit d8b2ea8
File tree
3 files changed
+69
-2
lines changed- libraries/Bluefruit52Lib/src
- utility
3 files changed
+69
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
145 | 151 | | |
146 | 152 | | |
147 | 153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
261 | | - | |
262 | | - | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
263 | 310 | | |
264 | 311 | | |
265 | 312 | | |
266 | 313 | | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
267 | 326 | | |
268 | 327 | | |
269 | 328 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
65 | 67 | | |
66 | 68 | | |
67 | 69 | | |
| |||
0 commit comments