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 v2 3/4] shared/hog: Add bt_hog_set_long_report_map
Date: Mon, 30 Nov 2026 21:45:55 +0100	[thread overview]
Message-ID: <20261130204556.357834-4-seb.witt@googlemail.com> (raw)
In-Reply-To: <20261130204556.357834-1-seb.witt@googlemail.com>

Add bt_hog_set_long_report_map to accept a Report Map longer than 512
octets, up to the 4096 octets of HID descriptor UHID_CREATE2 accepts,
by reading it with bt_gatt_client_read_long_value_max_len. It is
disabled by default, so the Report Map is read as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---
 src/shared/hog.c | 43 +++++++++++++++++++++++++++++++++++++++----
 src/shared/hog.h |  5 +++++
 2 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/src/shared/hog.c b/src/shared/hog.c
index e62423fa4..1ef886e42 100644
--- a/src/shared/hog.c
+++ b/src/shared/hog.c
@@ -56,6 +56,13 @@
 #define HOG_PROTO_MODE_BOOT    0
 #define HOG_PROTO_MODE_REPORT  1
 
+/* Some peripherals expose a Report Map longer than the 512 octets an
+ * attribute value may have (Core v5.4, Vol 3, Part F, Section 3.2.9).
+ * When enabled, accept up to the size of HID descriptor UHID_CREATE2 can
+ * take.
+ */
+#define HOG_REPORT_MAP_LONG_MAX_LEN	4096
+
 #define HOG_INFO_FLAG_SCI_SUPPORTED	0x04
 #define HOG_INFO_FLAG_SCI_LOW_POWER	0x08
 
@@ -88,6 +95,7 @@ struct bt_hog {
 	uint16_t		report_map_handle;
 	uint8_t			*report_map;
 	uint16_t		report_map_len;
+	uint16_t		report_map_max_len;
 	uint16_t		sci_mode_handle;
 	uint8_t			sci_mode_props;
 	unsigned int		sci_mode_id;
@@ -151,7 +159,8 @@ static void db_value_cb(struct gatt_db_attribute *attr, int err,
  * The requests are cancelled by cancelling all the requests of the client,
  * which is a clone owned by hog, once detached.
  */
-static void read_char(struct bt_hog *hog, uint16_t handle, bool cache,
+static void read_char_max_len(struct bt_hog *hog, uint16_t handle,
+				bool cache, uint16_t max_len,
 				bt_gatt_client_read_callback_t func, void *data)
 {
 	if (cache) {
@@ -169,11 +178,18 @@ static void read_char(struct bt_hog *hog, uint16_t handle, bool cache,
 		}
 	}
 
-	if (!bt_gatt_client_read_value(hog->client, handle, func, data,
-								NULL))
+	if (!bt_gatt_client_read_long_value_max_len(hog->client, handle, 0,
+						max_len, func, data, NULL))
 		DBG(hog, "Could not read handle 0x%04x", handle);
 }
 
+static void read_char(struct bt_hog *hog, uint16_t handle, bool cache,
+				bt_gatt_client_read_callback_t func, void *data)
+{
+	read_char_max_len(hog, handle, cache, BT_ATT_MAX_VALUE_LEN, func,
+									data);
+}
+
 /* Cache a static value in the gatt_db, see read_char */
 static void cache_value(struct bt_hog *hog, uint16_t handle,
 				const uint8_t *value, uint16_t length)
@@ -1103,7 +1119,9 @@ static void foreach_hog_chrc(struct gatt_db_attribute *attr, void *user_data)
 		 * handled by reading it with Read Blob, unless cached.
 		 */
 		hog->report_map_handle = value_handle;
-		read_char(hog, value_handle, true, report_map_read_cb, hog);
+		read_char_max_len(hog, value_handle, true,
+					hog->report_map_max_len,
+					report_map_read_cb, hog);
 
 		gatt_db_service_foreach_desc(attr, foreach_hog_external, hog);
 		return;
@@ -1194,6 +1212,7 @@ static struct bt_hog *hog_new(int fd, const char *name, uint16_t vendor,
 	hog->version = version;
 	hog->type = type;
 	hog->attr = attr;
+	hog->report_map_max_len = BT_ATT_MAX_VALUE_LEN;
 
 	return hog;
 }
@@ -1220,6 +1239,7 @@ static void foreach_hog_service(struct gatt_db_attribute *attr, void *user_data)
 	instance->debug_data = hog->debug_data;
 	instance->sci_mode_func = hog->sci_mode_func;
 	instance->sci_mode_data = hog->sci_mode_data;
+	instance->report_map_max_len = hog->report_map_max_len;
 
 	queue_push_tail(hog->instances, bt_hog_ref(instance));
 }
@@ -1335,6 +1355,21 @@ void bt_hog_set_ids(struct bt_hog *hog, uint16_t vendor, uint16_t product,
 		bt_hog_set_ids(entry->data, vendor, product, version);
 }
 
+void bt_hog_set_long_report_map(struct bt_hog *hog, bool enable)
+{
+	const struct queue_entry *entry;
+
+	if (!hog)
+		return;
+
+	hog->report_map_max_len = enable ? HOG_REPORT_MAP_LONG_MAX_LEN :
+							BT_ATT_MAX_VALUE_LEN;
+
+	for (entry = queue_get_entries(hog->instances); entry;
+							entry = entry->next)
+		bt_hog_set_long_report_map(entry->data, enable);
+}
+
 static void discovery_idle(void *user_data)
 {
 	struct bt_hog *hog = user_data;
diff --git a/src/shared/hog.h b/src/shared/hog.h
index 910a2261b..a4aa8a5d6 100644
--- a/src/shared/hog.h
+++ b/src/shared/hog.h
@@ -46,6 +46,11 @@ bool bt_hog_set_debug(struct bt_hog *hog, bt_hog_debug_func_t func,
 void bt_hog_set_ids(struct bt_hog *hog, uint16_t vendor, uint16_t product,
 							uint16_t version);
 
+/* Accept a Report Map longer than the 512 octets an attribute value may
+ * have, as exposed by some non-compliant devices. Disabled by default.
+ */
+void bt_hog_set_long_report_map(struct bt_hog *hog, bool enable);
+
 bool bt_hog_attach(struct bt_hog *hog, struct bt_gatt_client *client);
 void bt_hog_detach(struct bt_hog *hog, bool force);
 
-- 
2.56.1


  parent reply	other threads:[~2026-11-30 20:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CABBYNZ+GNO-eVNC5B_4SqCdHOE+OHmXUaW0NwStd_BsbUzx35A@mail.gmail.com>
2026-11-30 20:45 ` [PATCH v2 0/4] Accept HoG Report Map longer than 512 octets Sebastian
2026-11-30 20:45   ` [PATCH v2 1/4] shared/gatt-client: Add bt_gatt_client_read_long_value_max_len Sebastian
2026-11-30 20:45   ` [PATCH v2 2/4] main.conf: Add LongReportMap option to [Input] Sebastian
2026-11-30 20:45   ` Sebastian [this message]
2026-11-30 20:45   ` [PATCH v2 4/4] input/hog: Accept Report Map longer than 512 octets Sebastian

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=20261130204556.357834-4-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