Repository navigation
Conversation
ble_store_config_persist_cccds() and _persist_csfcs() only compared the NVS and RAM entry counts, so overwriting an existing entry in place (same key, new value) never reached NVS and the old value was restored after a reboot. When the counts are equal, rewrite the NVS entry that no longer matches RAM with the RAM entry that has the same key. Fixes h2zero#1192
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (1)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughArr, CCCD and CSFC persistence now checks for changed entries when RAM and NVS counts are equal and nonzero. It matches entries by store key and updates an unmatched NVS value from RAM. ChangesCCCD and CSFC persistence
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~12 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The change addresses in-place subscription persistence. No newly introduced merge-blocking issue is established. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Arr, equal counts once hid the change, Comment |
|
Thanks! |
Fixes #1192.
ble_store_config_persist_cccds()only compares the NVS and RAM entry counts. Whenble_store_config_write_cccd()overwrites an existing entry in place (same peer and handle, new flags), the counts stay equal and nothing is written to NVS, so the old value comes back after a reboot.persist_csfcs()has the same gap.This adds an equal-count branch to both: it looks for the NVS entry that no longer matches any RAM entry and rewrites it with the RAM entry that has the same key (peer address + characteristic handle for CCCDs, peer address for CSFCs). If every NVS entry still matches, nothing is written, so a repeated identical write doesn't touch flash. Add and delete paths are unchanged.
Espressif's esp-nimble fixed this in espressif/esp-nimble@4e54569 (
nimble-1.10.0-idf) with an equal-count update branch in everypersist_*()function. That version is built on their newer shared-NVS-handle code, so this is a smaller port that fits the current file, limited to CCCDs and CSFCs: they have a simple key and are what the issue hits. The sec/IRK/RPA paths carry extra bond-count ordering upstream, so I'd rather do those in a separate PR if you want them.Testing (no hardware):
ble_store_nvs.cagainst an in-memory NVS, uses the same find/overwrite/append logic asble_store_config_write_cccd()/_write_csfc(), and "reboots" by clearing the RAM db and callingble_store_config_conf_init(). With the sequence from the issue (bonding persists 0x80 placeholders for handles 29/36, host then subscribes with 0x01), master restores 29=0x80 and 36=0x80, the same as the issue shows; with this change they restore as 0x01. Also checked: unsubscribe in place (0x1 -> 0x0) survives a reboot, an identical rewrite does 0 NVS writes, appending a second peer still persists, and a CSFC in-place update survives a reboot. Built with ASan/UBSan, no reports.pio runwithexamples/NimBLE_Serverfor esp32dev and esp32-s3-devkitc-1 (espressif32 / Arduino,-Wall -Wextra):ble_store_nvs.ccompiles with no warnings on master and with this change. With my local arduino-esp32 3.3.12 package the final link fails onmbedtls_cipher_cmac_*fromble_sm_alg.con master as well, so I didn't get a linked image here.Summary by CodeRabbit