Skip to content

Add BLE pairing-mode flag and stale bond recovery#105

Merged
zjwhitehead merged 4 commits intoopenppg:masterfrom
PaulDWhite:ble-pairing-mode-filter
Mar 27, 2026
Merged

Add BLE pairing-mode flag and stale bond recovery#105
zjwhitehead merged 4 commits intoopenppg:masterfrom
PaulDWhite:ble-pairing-mode-filter

Conversation

@PaulDWhite
Copy link
Copy Markdown
Collaborator

@PaulDWhite PaulDWhite commented Mar 27, 2026

Summary

  • Adds manufacturer data to BLE advertisements (both legacy and extended advertising paths) with a pairing-mode flag byte so the Flutter app can filter non-pairable controllers from the scan list
  • During pairing mode, proactively requests fresh security negotiation on connect to recover from stale iOS bonds (rc=19 failures)
  • On auth failure during pairing mode, deletes stale peer data and re-initiates pairing instead of immediately rejecting the connection

Details

Manufacturer data format: Espressif company ID (0x02E5 LE) + 1 flag byte

  • 0x01 = pairing mode active (controller accepting new bonds)
  • 0x00 = normal mode (only bonded devices accepted)

Stale bond recovery: When iOS caches old encryption keys after a controller bond clear, the connection fails with rc=19 (BLE_ERR_UNSPECIFIED). The firmware now:

  1. On connect during pairing mode: calls ble_gap_security_initiate() to request fresh security
  2. On auth failure during pairing mode: calls NimBLEDevice::deleteBond() for the peer and re-initiates pairing

Test plan

  • Flash firmware, verify controller advertises normally with bonded devices
  • Enter pairing mode (10s button hold), verify new device can discover and pair
  • Clear controller bonds, verify stale iOS bond recovery works during pairing mode
  • Verify non-pairing-mode controllers are not connectable by unbonded devices

🤖 Generated with Claude Code

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the BLE pairing UX by advertising an explicit “pairing mode” flag for the Flutter app to filter scan results, and by adding recovery behavior for stale iOS bonds during pairing mode.

Changes:

  • Add manufacturer data payload (Espressif company ID + pairing-mode flag byte) to both extended and legacy advertising paths.
  • During pairing mode, proactively initiate a security exchange on connect to recover from stale iOS bonding state.
  • On authentication failure during pairing mode, delete peer bond data and re-initiate pairing instead of immediately disconnecting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

zjwhitehead and others added 3 commits March 26, 2026 21:33
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@zjwhitehead zjwhitehead merged commit dc4f5e6 into openppg:master Mar 27, 2026
3 of 4 checks passed
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.

3 participants