* [PATCH 1/2] shared/hog: Read the PnP ID before creating the uHID device
2026-11-30 19:25 [PATCH 0/2] Read the PnP ID before creating the uHID device Sebastian
@ 2026-11-30 19:25 ` Sebastian
2026-11-30 19:39 ` Luiz Augusto von Dentz
2026-11-30 19:25 ` [PATCH 2/2] unit/test-hog: Add test for the PnP ID Sebastian
1 sibling, 1 reply; 4+ messages in thread
From: Sebastian @ 2026-11-30 19:25 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Sebastian, Claude Opus 5.5
Since commit 96f1201f5ac2 ("input/hog: Use shared/hog") the vendor,
product and version of the uHID device are the ones of the btd_device
when the connection is accepted. On the first connection after pairing
they are not known yet, as the deviceinfo plugin reads the PnP ID
concurrently, so the uHID device is created with 0000:0000 and the
kernel drivers and quirks matching the device don't apply until it
reconnects:
hid-multitouch 0005:0000:0000.001C: input,hidraw1: BLUETOOTH HID v0.00
hog-lib used to read the PnP ID itself before creating the uHID device,
so read it again, if the Device Information Service has one, along with
the other characteristics the uHID device is created after.
Fixes: 96f1201f5ac2 ("input/hog: Use shared/hog")
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---
src/shared/hog.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
diff --git a/src/shared/hog.c b/src/shared/hog.c
index e62423fa4..ed89b3960 100644
--- a/src/shared/hog.c
+++ b/src/shared/hog.c
@@ -61,6 +61,10 @@
#define HID_INFO_SIZE 4
+#define DIS_UUID16 0x180A
+#define DIS_PNP_ID_UUID 0x2A50
+#define PNP_ID_SIZE 7
+
struct bt_hog {
int ref_count;
char *name;
@@ -78,6 +82,7 @@ struct bt_hog {
uint16_t bcdhid;
uint8_t bcountrycode;
uint16_t info_handle;
+ uint16_t pnp_id_handle;
uint16_t proto_mode_handle;
uint16_t cp_handle;
uint8_t flags;
@@ -1335,6 +1340,74 @@ void bt_hog_set_ids(struct bt_hog *hog, uint16_t vendor, uint16_t product,
bt_hog_set_ids(entry->data, vendor, product, version);
}
+static void pnp_id_read_cb(bool success, uint8_t att_ecode,
+ const uint8_t *value, uint16_t length,
+ void *user_data)
+{
+ struct bt_hog *hog = user_data;
+ struct iovec iov = { (void *)value, length };
+ uint8_t source;
+
+ if (!success) {
+ DBG(hog, "PnP ID read failed: 0x%02x", att_ecode);
+ return;
+ }
+
+ if (length < PNP_ID_SIZE) {
+ DBG(hog, "Malformed PnP ID: length %u", length);
+ return;
+ }
+
+ cache_value(hog, hog->pnp_id_handle, value, length);
+
+ if (!util_iov_pull_u8(&iov, &source) ||
+ !util_iov_pull_le16(&iov, &hog->vendor) ||
+ !util_iov_pull_le16(&iov, &hog->product) ||
+ !util_iov_pull_le16(&iov, &hog->version))
+ return;
+
+ DBG(hog, "source: 0x%02X vendor: 0x%04X product: 0x%04X "
+ "version: 0x%04X", source, hog->vendor, hog->product,
+ hog->version);
+}
+
+static void foreach_dis_chrc(struct gatt_db_attribute *attr, void *user_data)
+{
+ struct bt_hog *hog = user_data;
+ bt_uuid_t uuid, pnp_id_uuid;
+ uint16_t value_handle;
+
+ gatt_db_attribute_get_char_data(attr, NULL, &value_handle, NULL,
+ NULL, &uuid);
+
+ bt_uuid16_create(&pnp_id_uuid, DIS_PNP_ID_UUID);
+ if (!bt_uuid_cmp(&pnp_id_uuid, &uuid))
+ hog->pnp_id_handle = value_handle;
+}
+
+static void foreach_dis_service(struct gatt_db_attribute *attr,
+ void *user_data)
+{
+ gatt_db_service_foreach_char(attr, foreach_dis_chrc, user_data);
+}
+
+/* Read the PnP ID of the Device Information Service, if any, so the uHID
+ * device is created with the vendor, product and version of the device
+ * even on the first connection, when they are not known yet.
+ */
+static void read_pnp_id(struct bt_hog *hog)
+{
+ bt_uuid_t uuid;
+
+ hog->pnp_id_handle = 0;
+
+ bt_uuid16_create(&uuid, DIS_UUID16);
+ gatt_db_foreach_service(hog->db, &uuid, foreach_dis_service, hog);
+
+ if (hog->pnp_id_handle)
+ read_char(hog, hog->pnp_id_handle, true, pnp_id_read_cb, hog);
+}
+
static void discovery_idle(void *user_data)
{
struct bt_hog *hog = user_data;
@@ -1376,6 +1449,9 @@ bool bt_hog_attach(struct bt_hog *hog, struct bt_gatt_client *client)
DBG(hog, "HoG discovering characteristics");
gatt_db_service_foreach_char(hog->attr, foreach_hog_chrc, hog);
+ if (!created)
+ read_pnp_id(hog);
+
/* Create the uHID device once every request is complete, including
* the ones made once others complete, e.g. the CCC once the Report
* Reference is read, even if some failed, e.g. reading an optional
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] unit/test-hog: Add test for the PnP ID
2026-11-30 19:25 [PATCH 0/2] Read the PnP ID before creating the uHID device Sebastian
2026-11-30 19:25 ` [PATCH 1/2] shared/hog: " Sebastian
@ 2026-11-30 19:25 ` Sebastian
1 sibling, 0 replies; 4+ messages in thread
From: Sebastian @ 2026-11-30 19:25 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Sebastian, Claude Opus 5.5
Add a HID Device with a Device Information Service, and check the uHID
device is created with the vendor, product and version of its PnP ID.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---
unit/test-hog.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 63 insertions(+), 4 deletions(-)
diff --git a/unit/test-hog.c b/unit/test-hog.c
index 969e02f44..ebaa997ed 100644
--- a/unit/test-hog.c
+++ b/unit/test-hog.c
@@ -64,7 +64,9 @@
* 0x001d Client Characteristic Configuration
* 0x001f HID SCI Information (Read) - SCI variant
*
- * followed by a Battery Service with the Battery Level characteristic.
+ * followed by a Battery Service with the Battery Level characteristic, the
+ * PnP ID variant adding a Device Information Service at 0x001f with the
+ * PnP ID characteristic at 0x0020.
*
* The Client Characteristic Configuration descriptors following a
* characteristic with no other descriptor are not discovered with Find
@@ -99,6 +101,10 @@ struct test_config {
uint8_t mode[2];
/* Number of HID SCI Mode notifications per mode */
unsigned int notifications;
+ /* Whether the IDs are expected from the PnP ID, instead of the ones
+ * HoG is created with.
+ */
+ bool pnp_id;
/* uHID event expected after the action */
uint32_t uhid_type;
const uint8_t *uhid_data;
@@ -306,9 +312,15 @@ static bool uhid_read(struct io *io, void *user_data)
if (ev.type == UHID_CREATE2) {
g_assert_cmpstr((char *) ev.u.create2.name, ==, "bluez-hog");
- g_assert_cmpint(ev.u.create2.vendor, ==, 0x0002);
- g_assert_cmpint(ev.u.create2.product, ==, 0x0001);
- g_assert_cmpint(ev.u.create2.version, ==, 0x0001);
+ if (data->cfg->pnp_id) {
+ g_assert_cmpint(ev.u.create2.vendor, ==, 0x1234);
+ g_assert_cmpint(ev.u.create2.product, ==, 0x5678);
+ g_assert_cmpint(ev.u.create2.version, ==, 0x0100);
+ } else {
+ g_assert_cmpint(ev.u.create2.vendor, ==, 0x0002);
+ g_assert_cmpint(ev.u.create2.product, ==, 0x0001);
+ g_assert_cmpint(ev.u.create2.version, ==, 0x0001);
+ }
g_assert_cmpint(ev.u.create2.bus, ==, BUS_BLUETOOTH);
g_assert_cmpint(ev.u.create2.rd_size, ==, REPORT_MAP_LEN);
@@ -510,6 +522,9 @@ static void test_teardown(const void *user_data)
#define READ_OUTPUT_REF READ(0x11, 0x01, 0x02)
#define READ_FEATURE READ(0x13, 0x00)
#define READ_FEATURE_REF READ(0x14, 0x01, 0x03)
+/* PnP ID: USB vendor 0x1234, product 0x5678, version 0x0100 */
+#define READ_PNP_ID READ(0x21, 0x02, 0x34, 0x12, 0x78, 0x56, \
+ 0x00, 0x01)
#define READ_INPUT_CCC READ(0x0d, 0x00, 0x00)
#define ENABLE_INPUT_CCC WRITE(0x0d, 0x01, 0x00)
#define READ_SCI_MODE READ(0x1c, 0x00)
@@ -637,6 +652,30 @@ static const struct iovec setup_basic[] = {
DISC_HID_DESC,
};
+/* The basic layout followed by a Device Information Service */
+static const struct iovec setup_pnp_id[] = {
+ DISC_MTU,
+ DISC_SR_FEATURES,
+ IOV_DATA(0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28),
+ IOV_DATA(0x11, 0x06, 0x01, 0x00, 0x1a, 0x00, 0x12, 0x18, 0x1b,
+ 0x00, 0x1e, 0x00, 0x0f, 0x18, 0x1f, 0x00, 0x21,
+ 0x00, 0x0a, 0x18),
+ IOV_DATA(0x10, 0x22, 0x00, 0xff, 0xff, 0x00, 0x28),
+ IOV_DATA(0x01, 0x10, 0x22, 0x00, 0x0a),
+ DISC_SECONDARY,
+ IOV_DATA(0x08, 0x01, 0x00, 0x21, 0x00, 0x02, 0x28),
+ IOV_DATA(0x01, 0x08, 0x01, 0x00, 0x0a),
+ IOV_DATA(0x08, 0x01, 0x00, 0x21, 0x00, 0x03, 0x28),
+ DISC_HID_CHRC_1,
+ IOV_DATA(0x08, 0x16, 0x00, 0x21, 0x00, 0x03, 0x28),
+ IOV_DATA(0x09, 0x07, 0x18, 0x00, 0x12, 0x19, 0x00, 0x33, 0x2a,
+ 0x1c, 0x00, 0x12, 0x1d, 0x00, 0x19, 0x2a, 0x20,
+ 0x00, 0x02, 0x21, 0x00, 0x50, 0x2a),
+ IOV_DATA(0x08, 0x21, 0x00, 0x21, 0x00, 0x03, 0x28),
+ IOV_DATA(0x01, 0x08, 0x21, 0x00, 0x0a),
+ DISC_HID_DESC,
+};
+
static const struct iovec setup_sci[] = {
DISC_MTU,
DISC_SR_FEATURES,
@@ -827,6 +866,12 @@ static const struct test_config cfg_attach = {
.creates = 1,
};
+static const struct test_config cfg_pnp_id_attach = {
+ .action = ACT_NONE,
+ .creates = 1,
+ .pnp_id = true,
+};
+
static const struct test_config cfg_multi_attach = {
.action = ACT_NONE,
.creates = 2,
@@ -1104,6 +1149,20 @@ int main(int argc, char *argv[])
NOTIFY(0x0c, INPUT_REPORT));
/* Characteristic GGIT, the discovery being done by bt_gatt_client */
+ define_test("/hog/pnp-id", setup_pnp_id, &cfg_pnp_id_attach,
+ READ_PROTO_MODE,
+ READ_REPORT_MAP,
+ READ_EXT_REPORT_REF,
+ READ_INFO,
+ READ_INPUT,
+ READ_INPUT_REF,
+ READ_OUTPUT,
+ READ_OUTPUT_REF,
+ READ_FEATURE,
+ READ_FEATURE_REF,
+ READ_PNP_ID,
+ READ_INPUT_CCC,
+ ENABLE_INPUT_CCC);
define_test("HOGP/RH/CGGIT/CHA/BV-01-C [Characteristic GGIT - Report "
"Map - RH]",
setup_basic, &cfg_attach,
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread