Skip to content

Add bonding and pairing support with standard HID UUID advertising#1

Draft
Copilot wants to merge 3 commits intodevfrom
copilot/vscode1758099593101
Draft

Add bonding and pairing support with standard HID UUID advertising#1
Copilot wants to merge 3 commits intodevfrom
copilot/vscode1758099593101

Conversation

Copy link
Copy Markdown

Copilot AI commented Sep 17, 2025

This PR addresses the authentication failure issues (disconnect reason 5) by implementing proper BLE bonding and pairing support while ensuring the device advertises the standard HID Service UUID for better OS compatibility.

Problem

The device was experiencing BT_HCI_ERR_AUTH_FAIL (reason 5) disconnections when BLE centrals attempted to pair. This occurred because:

  • The device advertised as a HID service (BT_UUID_HIDS) but lacked SMP/security support
  • Operating systems expect HID devices to support pairing and encryption
  • No persistent bonding storage was configured

Solution

Implemented comprehensive bonding and pairing support:

Configuration Changes (app/prj.conf)

  • Enabled CONFIG_BT_SMP=y for Security Manager Protocol
  • Enabled CONFIG_BT_BONDABLE=y to allow bonding with peers
  • Added CONFIG_BT_KEYS_OVERWRITE_OLDEST=y for efficient bond management
  • Enabled CONFIG_SETTINGS=y and CONFIG_BT_SETTINGS=y for persistent bond storage

Code Implementation (app/src/main.c)

  • Added authentication callbacks with proper logging:
    • auth_cancel() - handles pairing cancellation
    • auth_pairing_complete() - logs successful bonding
    • auth_pairing_failed() - logs pairing failures
  • Integrated settings_load() after bt_enable() to restore stored bonds
  • Registered authentication callbacks with bt_conn_auth_cb_register()
  • Enhanced advertising data to include HID Service UUID (0x1812) for better discoverability

Version Update

Bumped version to 0.2.0 to reflect externally observable behavior changes.

Expected Behavior

  • Pairing: Device accepts pairing requests using "Just Works" authentication
  • Bonding: Successfully bonded devices reconnect automatically
  • Persistence: Bond information survives power cycles and firmware updates
  • Discovery: Device appears as a standard HID device in BLE scanners
  • Compatibility: Eliminates authentication failure disconnects

Testing

To test the changes:

  1. Clear any existing bonds on both device and central
  2. Flash the updated firmware
  3. Initiate pairing from a BLE central (phone/PC)
  4. Verify successful pairing without disconnect reason 5
  5. Test automatic reconnection after power cycle

The device now provides a proper BLE HID experience with persistent bonding while maintaining the existing custom characteristic functionality for raw keyboard report injection.

Created from VS Code via the GitHub Pull Request extension.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: mr-u0b0dy <63730630+mr-u0b0dy@users.noreply.github.com>
Copilot AI changed the title [WIP] Transition to Standard HID UUID with Bonding and Pairing Support Add bonding and pairing support with standard HID UUID advertising Sep 17, 2025
Copilot AI requested a review from mr-u0b0dy September 17, 2025 09:07
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.

2 participants