Skip to content

fix(ble): Fix HID BLE permissions, add examples and fix characteristic handle#12260

Merged
me-no-dev merged 2 commits intoespressif:masterfrom
lucasssvaz:fix/ble_hid_permissions
Jan 21, 2026
Merged

fix(ble): Fix HID BLE permissions, add examples and fix characteristic handle#12260
me-no-dev merged 2 commits intoespressif:masterfrom
lucasssvaz:fix/ble_hid_permissions

Conversation

@lucasssvaz
Copy link
Member

@lucasssvaz lucasssvaz commented Jan 19, 2026

Description of Change

This pull request adds robust BLE HID Gamepad client and server examples for ESP32, and improves the BLE HID implementation for better compatibility with the HID over GATT Profile (HOGP) specification. The changes ensure that HID report characteristics and descriptors are accessible as required for enumeration and pairing, and enhance the reliability of BLE descriptor callbacks.

New BLE HID Gamepad Examples:

  • Added a BLE HID gamepad server example (Server_Gamepad.ino) that implements an 8-button, 2-axis gamepad with secure pairing, battery reporting, and automatic reconnection.
  • Added a BLE HID gamepad client example (Client_Gamepad.ino) that scans for HID gamepads, connects, and displays input reports in the serial monitor.
  • Added corresponding CI configuration files for both examples, ensuring they are built with the correct partition scheme and BLE requirements.

BLE HID Device Implementation Improvements:

  • Modified HID report characteristics and descriptors in BLEHIDDevice.cpp so that Report Reference Descriptors and Client Characteristic Configuration Descriptors (CCCD) are readable and writable without encryption, as required by the HID over GATT Profile for device enumeration and notification enabling. [1] [2] [3] [4]
  • Ensured that the BLE server is started when HID services are started, improving service initialization.
  • Fixed a bug by assigning the server pointer in the BLEHIDDevice constructor.

Descriptor Callback Robustness:

  • Improved BLE descriptor callback handling by checking for null pointers before invoking onRead and onWrite callbacks, preventing potential crashes. [1] [2]

Summary of Most Important Changes:

1. New BLE HID Gamepad Examples

  • Added Server_Gamepad.ino and Client_Gamepad.ino to demonstrate BLE HID gamepad server and client functionality, including secure pairing, HID report handling, and user-friendly serial output. [1] [2]
  • Added CI configuration files for both examples to ensure correct build settings and BLE support.

2. BLE HID Device API and HID Compliance

  • Updated BLEHIDDevice.cpp so HID report characteristics and descriptors (including Report Reference and CCCD) are readable/writable without encryption, as required for HID device discovery and notification enabling, ensuring compatibility with standard HID hosts. [1] [2] [3] [4]
  • Ensured BLE server is started when HID services are started, improving reliability.
  • Assigned the BLE server pointer in the BLEHIDDevice constructor for correct internal usage.

3. BLE Descriptor Callback Safety

  • Added null checks before invoking onRead and onWrite callbacks in BLEDescriptor.cpp to prevent crashes if callbacks are not set. [1] [2]

Test Scenarios

Tested locally with ESP32-C6 and ESP32

Related links

#8838

@lucasssvaz lucasssvaz requested a review from me-no-dev January 19, 2026 15:43
@lucasssvaz lucasssvaz self-assigned this Jan 19, 2026
@lucasssvaz lucasssvaz requested a review from SuGlider as a code owner January 19, 2026 15:43
@lucasssvaz lucasssvaz added the Area: BLE Issues related to BLE label Jan 19, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Jan 19, 2026

Messages
📖 🎉 Good Job! All checks are passing!

👋 Hello lucasssvaz, we appreciate your contribution to this project!


📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more.

🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project.

Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against 10e6aba

@github-actions
Copy link
Contributor

github-actions bot commented Jan 19, 2026

Test Results

 90 files   90 suites   33m 42s ⏱️
 67 tests  67 ✅ 0 💤 0 ❌
683 runs  683 ✅ 0 💤 0 ❌

Results for commit 10e6aba.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 19, 2026

Memory usage test (comparing PR against master branch)

The table below shows the summary of memory usage change (decrease - increase) in bytes and percentage for each target.

MemoryFLASH [bytes]FLASH [%]RAM [bytes]RAM [%]
TargetDECINCDECINCDECINCDECINC
ESP32000.000.00000.000.00
ESP32C3💚 -6⚠️ +40.000.00000.000.00
ESP32C5000.000.00000.000.00
ESP32C6000.000.00000.000.00
ESP32H2💚 -6⚠️ +40.000.00000.000.00
ESP32P4💚 -6⚠️ +40.000.00000.000.00
ESP32S30⚠️ +160.000.00000.000.00
Click to expand the detailed deltas report [usage change in BYTES]
TargetESP32ESP32C3ESP32C5ESP32C6ESP32H2ESP32P4ESP32S3
ExampleFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAM
libraries/BLE/examples/Beacon_Scanner00⚠️ +40----⚠️ +40⚠️ +4000
libraries/BLE/examples/Client00💚 -60----💚 -60💚 -60⚠️ +160
libraries/BLE/examples/Client_Gamepad--------------
libraries/BLE/examples/Client_Server00💚 -60----💚 -60💚 -60--
libraries/BLE/examples/Client_multiconnect00💚 -60----💚 -60💚 -60--
libraries/BLE/examples/Client_secure_static_passkey00💚 -60----💚 -60💚 -60--
libraries/BLE/examples/EddystoneTLM_Beacon00⚠️ +40----⚠️ +40⚠️ +40--
libraries/BLE/examples/EddystoneURL_Beacon00⚠️ +40----⚠️ +40⚠️ +40--
libraries/BLE/examples/Notify00⚠️ +40----⚠️ +40⚠️ +40--
libraries/BLE/examples/Scan00⚠️ +40----⚠️ +40⚠️ +40--
libraries/BLE/examples/Server00⚠️ +40----⚠️ +40⚠️ +40--
libraries/BLE/examples/Server_Gamepad--------------
libraries/BLE/examples/Server_multiconnect00⚠️ +40----⚠️ +40⚠️ +40--
libraries/BLE/examples/Server_secure_static_passkey00⚠️ +40----⚠️ +40⚠️ +40--
libraries/BLE/examples/UART00⚠️ +40----⚠️ +40⚠️ +40--
libraries/BLE/examples/Write00⚠️ +40----⚠️ +40⚠️ +40--
libraries/BLE/examples/iBeacon00⚠️ +40----⚠️ +40⚠️ +40--
libraries/BLE/examples/Server_secure_authorization--⚠️ +40----⚠️ +40----

@lucasssvaz lucasssvaz force-pushed the fix/ble_hid_permissions branch 2 times, most recently from aed191c to aadf360 Compare January 19, 2026 17:31
@lucasssvaz lucasssvaz added Type: Bug 🐛 All bugs Type: Example Issue is related to specific example. Status: Review needed Issue or PR is awaiting review labels Jan 19, 2026
@lucasssvaz lucasssvaz changed the title fix(ble): Fix HID BLE permissions fix(ble): Fix HID BLE permissions and examples Jan 19, 2026
@lucasssvaz lucasssvaz force-pushed the fix/ble_hid_permissions branch from aadf360 to fb73892 Compare January 19, 2026 17:51
@lucasssvaz lucasssvaz changed the title fix(ble): Fix HID BLE permissions and examples fix(ble): Fix HID BLE permissions, add examples and fix characteristic handle Jan 19, 2026
Copy link
Contributor

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 pull request enhances the BLE HID implementation to ensure compliance with the HID over GATT Profile (HOGP) specification and adds comprehensive gamepad examples demonstrating BLE HID functionality on ESP32. The changes address permission requirements for HID enumeration, improve callback robustness, optimize characteristic lookup, and provide well-documented examples for both server and client implementations.

Changes:

  • Fixed HID descriptor and CCCD permissions to allow enumeration without encryption per HOGP specification
  • Added isStarted() method to BLEServer to safely check server state before notifications
  • Added null pointer checks in BLEDescriptor callbacks to prevent potential crashes
  • Optimized BLEClient notification handling using handle-based characteristic lookup
  • Added comprehensive BLE HID gamepad server and client examples with CI configuration

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
libraries/BLE/src/BLEServer.h Added isStarted() method declaration
libraries/BLE/src/BLEServer.cpp Implemented isStarted() method with documentation
libraries/BLE/src/BLEHIDDevice.h Added private m_server member variable
libraries/BLE/src/BLEHIDDevice.cpp Fixed HOGP compliance by adjusting permissions, added server pointer initialization, conditional battery notification
libraries/BLE/src/BLEDescriptor.cpp Added null pointer checks before invoking callbacks
libraries/BLE/src/BLEClient.cpp Optimized characteristic lookup using handle-based map for O(log n) performance
libraries/BLE/examples/Server_Gamepad/Server_Gamepad.ino New comprehensive BLE HID gamepad server example with secure pairing
libraries/BLE/examples/Server_Gamepad/ci.yml CI configuration for gamepad server example
libraries/BLE/examples/Client_Gamepad/Client_Gamepad.ino New BLE HID gamepad client example with report parsing
libraries/BLE/examples/Client_Gamepad/ci.yml CI configuration for gamepad client example

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

@me-no-dev me-no-dev added Status: Pending Merge Pull Request is ready to be merged and removed Status: Review needed Issue or PR is awaiting review labels Jan 21, 2026
@me-no-dev me-no-dev merged commit 549ef5d into espressif:master Jan 21, 2026
82 checks passed
@lucasssvaz lucasssvaz deleted the fix/ble_hid_permissions branch January 21, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: BLE Issues related to BLE Status: Pending Merge Pull Request is ready to be merged Type: Bug 🐛 All bugs Type: Example Issue is related to specific example.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants