Skip to content

bluetooth: hid: fix SDP record and PTS compliance issues#568

Open
EListenX wants to merge 5 commits into
open-vela:devfrom
EListenX:dev2
Open

bluetooth: hid: fix SDP record and PTS compliance issues#568
EListenX wants to merge 5 commits into
open-vela:devfrom
EListenX:dev2

Conversation

@EListenX
Copy link
Copy Markdown
Contributor

@EListenX EListenX commented Apr 2, 2026

Note: Please adhere to Contributing Guidelines.

Summary

Fix multiple HID Device PTS test failures related to SDP record completeness,
protocol mode handling, report callback correctness, and ACL link management.

Changes included:

  1. SDP record fixes

    • Add missing mandatory attributes: HIDNormallyConnectable (0x020d),
      HIDDeviceReleaseNumber (0x0200), HIDProfileVersion (0x020b)
    • Fix HID Additional Protocol Descriptor version to 0x0100
  2. ACL link management

    • Keep ACL alive when HID L2CAP channels are disconnected by remote host,
      allowing reconnection on existing link (HID/DEV/HCR/BV-01-C)
  3. Report callback fixes

    • Fix crash in bttool hidd_get_report_cb/hidd_set_report_cb where cookie
      was incorrectly cast to bt_instance_t*
    • Fix hid_get_report_callback to correctly parse bt_hid_report struct
      with proper alignment handling
    • Reject GET_REPORT with invalid report ID (HID/DEV/HID/BI-01-C)
  4. Protocol mode persistence

    • Store protocol mode in sal_hid_connection for GET/SET_PROTOCOL
      instead of always returning Report mode (HID/DEV/HID/BV-09-C)

Impact

HID Device profile only. No impact on other Bluetooth profiles or build process.

Testing

Verified with Bluetooth PTS test cases:

  • HID/DEV/HCE/BV-01-C (SDP HIDNormallyConnectable)
  • HID/DEV/HCR/BV-01-C (HID reconnection)
  • HID/DEV/HID/BV-09-C (GET/SET_PROTOCOL)
  • HID/DEV/HID/BI-01-C (invalid report ID rejection)
  • HID/DEV/SDD/BV-01-C (SDP mandatory attributes)

Comment thread tools/hid_device.c
Comment thread service/stacks/zephyr/sal_hid_device_interface.c
Comment thread service/stacks/zephyr/sal_hid_device_interface.c Outdated
Comment thread service/stacks/zephyr/sal_hid_device_interface.c Outdated
@EListenX EListenX force-pushed the dev2 branch 2 times, most recently from 653ccec to a93766c Compare April 7, 2026 10:06
zhongzhijie1
zhongzhijie1 previously approved these changes Apr 9, 2026
Copy link
Copy Markdown
Contributor

@zhongzhijie1 zhongzhijie1 left a comment

Choose a reason for hiding this comment

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

LGTM. SDP mandatory attributes 补全、protocol mode 持久化、report callback 修正 cookie 类型和 alignment、invalid report ID 拒绝、ACL keep alive for reconnect。PTS 覆盖充分。

Comment thread service/stacks/zephyr/sal_hid_device_interface.c
chengkai15
chengkai15 previously approved these changes May 8, 2026
EListenX added 4 commits May 12, 2026 09:58
bug: v/88287

The HID SDP record template was missing the mandatory
BT_SDP_ATTR_HID_NORMALLY_CONNECTABLE (0x020d) attribute,
causing PTS test HID/DEV/HCE/BV-01-C to fail during SDP
verification.

Add the HIDNormallyConnectable boolean attribute (set to TRUE)
to hid_attrs_template before HIDBootDevice (0x020e).

Signed-off-by: v-yichenxi <v-yichenxi@xiaomi.com>
bug: v/88725

1. Fix crash in bttool hidd_get_report_cb and hidd_set_report_cb
   where cookie (remote_callback_t*) was incorrectly used as
   bt_instance_t* for bt_hid_device_response_report() and
   bt_hid_device_report_error(). Use g_bttool_ins instead.

2. Add missing HID Normally Connectable (0x020d) SDP attribute
   to hid_attrs_template so PTS can verify it.

3. Fix hid_get_report_callback parameter parsing to correctly
   extract rpt_type, rpt_id and buffer_size from struct
   bt_hid_report, accounting for structure alignment padding.

Signed-off-by: v-yichenxi <v-yichenxi@xiaomi.com>
bug: v/88805

Store the protocol mode in sal_hid_connection so that
SET_PROTOCOL actually saves the value and GET_PROTOCOL
returns the current mode instead of always returning
Report mode. Initialize protocol to Report mode on
connection creation. This fixes PTS test case
HID/DEV/HID/BV-09-C.

Signed-off-by: v-yichenxi <v-yichenxi@xiaomi.com>
bug: v/88814

Validate report ID in hidd_get_report_cb before responding.
If the report ID is not defined in the HID descriptor (only
0x01 and 0x02 are valid), respond with HANDSHAKE error
ERR_INVALID_REPORT_ID instead of sending report data. This
fixes PTS test case HID/DEV/HID/BI-01-C.

Signed-off-by: v-yichenxi <v-yichenxi@xiaomi.com>
bug: v/88816

Add HIDDeviceReleaseNumber (0x0200) and HIDProfileVersion
(0x020b) to the HID SDP record. These are mandatory attributes
required by the HID specification. HIDProfileVersion is set to
0x0100 (HID v1.0) as expected by PTS.

Signed-off-by: v-yichenxi <v-yichenxi@xiaomi.com>
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