Linux bluetooth development
 help / color / mirror / Atom feed
From: Sebastian <seb.witt@googlemail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Sebastian <seb.witt@googlemail.com>,
	"Claude Opus 5.5" <noreply@anthropic.com>
Subject: [PATCH 2/2] unit/test-hog: Add test for the PnP ID
Date: Mon, 30 Nov 2026 20:25:21 +0100	[thread overview]
Message-ID: <20261130192521.246374-3-seb.witt@googlemail.com> (raw)
In-Reply-To: <20261130192521.246374-1-seb.witt@googlemail.com>

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


      parent reply	other threads:[~2026-11-30 19:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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:39   ` Luiz Augusto von Dentz
2026-11-30 19:25 ` Sebastian [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261130192521.246374-3-seb.witt@googlemail.com \
    --to=seb.witt@googlemail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=noreply@anthropic.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox