Accept re-pairing from a bonded peer (espressif) - #11237
Open
dhalbert wants to merge 1 commit into
Open
Conversation
NimBLE reports BLE_GAP_EVENT_REPEAT_PAIRING when a peer we still hold a bond for asks to pair again. Unless the application deletes the old bond and returns BLE_GAP_REPEAT_PAIRING_RETRY, the stack silently ignores the pairing request. The event was unhandled, so a central that had forgotten its side of the bond could not pair again: the board's bonds had to be erased first. Delete the stale bond with ble_store_util_delete_peer() and retry, matching the nordic port, which clears the stored keys when a peer re-pairs.
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.
Claude found this deficiency (not an outright bug) and wrote the fix.
(Part of the series of small PRs replacing #11178. Independent of the others.)
The problem
A central will ask to pair again when it no longer has its own copy of the bond. This happens whenever the user forgets the device in their OS Bluetooth settings, or the bonding info has otherwise gone away.
In this situation, before this fix, when the central asked to pair again, NimBLE reported
BLE_GAP_EVENT_REPEAT_PAIRINGto _bleio. But we did not handle that event, and nothing was sent back to the central. The board therefore could not be paired with again at all, and had to have its bonds erased with a blue-flash reset.The fix
Handle the
BLE_GAP_EVENT_REPEAT_PAIRINGevent by deleting the stale bond withble_store_util_delete_peer()and returningBLE_GAP_REPEAT_PAIRING_RETRY. This idiom is used in NimBLE's own bleprph example. The nordic port already behaves this way: it clears the stored keys onBLE_GAP_EVT_SEC_PARAMS_REQUESTand lets the new pairing replace them.ESP-IDF also offers
CONFIG_BT_NIMBLE_HANDLE_REPEAT_PAIRING_DELETION, which makes the stack delete the bond itself. But we didn't use that because Claude's analysis showed the code enabled by that config option is not resilient to the connection going away.Testing
Tested on a Metro ESP32-S3 with the web editor on Linux. Paired and transferred files, then removed the bond on the host only, leaving the board's bond in place, and reconnected: before this change nothing happened and no pairing prompt appeared, and now the central pairs and the session works.
Note that the reverse case cannot be fixed here. If the board's bonds are erased while the host keeps its key, the host offers a key the board no longer knows, encryption fails with PIN or Key Missing, and the host has to forget the device.
Other ports
As noted, this is not needed on nordic. I'll file separate issues for the other ports.