Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp4129956rwb; Tue, 16 Aug 2022 15:18:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR4DfCxg/68a4P/Bu3j2jFawk0EHwYcBO0Gjt9Kf2WuqPK5xD9BsWtP4ER0NrU0moSFC35dX X-Received: by 2002:a17:907:11c1:b0:731:5c53:d912 with SMTP id va1-20020a17090711c100b007315c53d912mr14559720ejb.354.1660688283745; Tue, 16 Aug 2022 15:18:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660688283; cv=none; d=google.com; s=arc-20160816; b=uhkyrTPMXpsaghVLkndDMAdDqnFN+2XeksAL6HK+suB8Trq5RPIc9S1kDfTWOtXi5j JZRU1j/5Jcg9ob/ZOAjyBZfQ5YMU4mgdiPeEfYdEpDok8SpRKlpzCBsUww7aN8bqinc8 QhMlEEBHqNa0ZPXxHCip7jAX4hriXcsQkYit8o9WB6ASHvCtIGEXl1bvpBNAIzMFBwgi 75Jjmddnp5UKqtE9i5zayFssel6hW4tyXoCwPXlZAoD+Y5y1wcrn35qj8wk5AbgwRVOE yordiTk2nZpJzf1y4RsAfR+6nl9gXn/hgDrI5dyhciV4tZW+/FZtXZK7FSC+akCOFsba //pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=kQGO0sS9sRtaLSp95kykOALXFP1iVmlbPRjhN9fyz8g=; b=UTvx8M1QFXWrxdBRuXqj64t6gJyPzAS8gYSpx0czI3giqO5z15t34jF2az03s0XAML ETz2vTv57SuDbOwA/W72fmYUGV/caC4frJX44YM8X5oqLuob746DQEvbZzwZhQ0tzHTU 3vmOx9WS6+dVeLryJ9PDb+5Gi8vtP2UXFF4SalYJdcox7zayJ+AZSuIp/cuuACVve6zj v3nq4QANg3P6aYYb4HGO9rHGp6XFlQaLyfQnDWLxe4J6noSeLAlb9YzmXIztI+NPgPEk c5rnXKcN1rGiFhagT2rWKq/J1Jms6lAO772uCJlyG3Qk++j3y2xZOIgl8XfH5rOH+LOC jxyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="LE4bTFz/"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ho35-20020a1709070ea300b0072e6774827asi14357836ejc.915.2022.08.16.15.17.32; Tue, 16 Aug 2022 15:18:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="LE4bTFz/"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237535AbiHPWFz (ORCPT + 99 others); Tue, 16 Aug 2022 18:05:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233253AbiHPWFy (ORCPT ); Tue, 16 Aug 2022 18:05:54 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEB7572FFB for ; Tue, 16 Aug 2022 15:05:53 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id x23so10419750pll.7 for ; Tue, 16 Aug 2022 15:05:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc; bh=kQGO0sS9sRtaLSp95kykOALXFP1iVmlbPRjhN9fyz8g=; b=LE4bTFz/KAYHFGeQlKSvbvzF9fQkC2RlfJ7fY+to8lxgPBFSZ6FPXaq2NLAEV4Hozc VIQO2Mj7doBIqt6WIZ1q2NwfnjH4YeB12w1xIb2/SV3w1cU5RNl9lZ1tzBvCPTQjGML7 Bj2Npqho1n85/hfEMEXPUJjdeE9lLXya2u3kUVWp/k1FyS4PxCL/FhcIx0xJYR008k6o O+wPq9xvO6XdpHET5EzWhbzCSmrwpO0RYwayOlwMUKNNwtPpVcx6o92DeVPgocrrh8hf cqbYXSas914pgVGKz5OtqhsbCmHdW/EwZ4+5fWfzhFIPy+KbJX0c7d8z2sK6yrDanoxc 3cIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc; bh=kQGO0sS9sRtaLSp95kykOALXFP1iVmlbPRjhN9fyz8g=; b=wG/o2rpN+22ANXABIHrJ75dGXjLQ91sgUA99b90Au0DsK8F/poqx4GDnnsbpDsra14 9YbGqWRf+frhFi/Fk1fYo2gaj/4ePxx9GCVkLO096aY2FPkI5SBRRAIlwUfs18MiiUtz JtYsHps/H3oGzNrwzpEdJXTbrvCA6mFIHus3BLV1Sog11T+rvSeqOFpq7m1Yjy6sYnK8 gaN7fKq4WI29BUgoPT0jNzgNHrK6WWAcPdkPfXvmJl5Z6uIY8azRXvV/y3RACvgLsrgG 85dMpi2AReRbl0gvP22UNlt+iLzsaHMCPsuqx/ViAoEh28eOxDSWjPRQGRkuDbesEbTe obkg== X-Gm-Message-State: ACgBeo34664Tj3dV0Qw+AJmxpmZUuDMRn7R0TBz/gHOa4blcFLb5RxUg LgNZXfWHLBKK/2/yJi8FVizyDz7WbkXMA3Aa X-Received: by 2002:a17:90b:48d0:b0:1fa:b438:1b20 with SMTP id li16-20020a17090b48d000b001fab4381b20mr35097pjb.239.1660687552756; Tue, 16 Aug 2022 15:05:52 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id a20-20020aa79714000000b0052d2cd99490sm8954286pfg.5.2022.08.16.15.05.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 15:05:52 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v2 1/2] hog-lib: Don't restrict Report MAP size Date: Tue, 16 Aug 2022 15:05:47 -0700 Message-Id: <20220816220548.1555673-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz Although HIDS spec is quite clear the Report MAP shall be limited to 512 bytes it doesn't seem OS do enforce that on the profile/client side and since there isn't any qualification test enforcing it either there are quite many devices which uses Report MAP bigger that 512 bytes (e.g.: Brydge W-Touch and Lenovo Duet 3 BT Folio). https://github.com/bluez/bluez/issues/377 --- profiles/input/hog-lib.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/profiles/input/hog-lib.c b/profiles/input/hog-lib.c index 4a9c601853f1..ace233d3ce8b 100644 --- a/profiles/input/hog-lib.c +++ b/profiles/input/hog-lib.c @@ -64,7 +64,6 @@ #define HOG_PROTO_MODE_BOOT 0 #define HOG_PROTO_MODE_REPORT 1 -#define HOG_REPORT_MAP_MAX_SIZE 512 #define HID_INFO_SIZE 4 #define ATT_NOTIFICATION_HEADER_SIZE 3 @@ -103,11 +102,6 @@ struct bt_hog { struct queue *input; }; -struct report_map { - uint8_t value[HOG_REPORT_MAP_MAX_SIZE]; - size_t length; -}; - struct report { struct bt_hog *hog; bool numbered; @@ -1096,7 +1090,7 @@ static void report_map_read_cb(guint8 status, const guint8 *pdu, guint16 plen, { struct gatt_request *req = user_data; struct bt_hog *hog = req->user_data; - uint8_t value[HOG_REPORT_MAP_MAX_SIZE]; + uint8_t *value; ssize_t vlen; remove_gatt_req(req, status); @@ -1106,10 +1100,12 @@ static void report_map_read_cb(guint8 status, const guint8 *pdu, guint16 plen, return; } - vlen = dec_read_resp(pdu, plen, value, sizeof(value)); + value = new0(uint8_t, plen); + + vlen = dec_read_resp(pdu, plen, value, plen); if (vlen < 0) { error("ATT protocol error"); - return; + goto done; } uhid_create(hog, value, vlen); @@ -1120,6 +1116,9 @@ static void report_map_read_cb(guint8 status, const guint8 *pdu, guint16 plen, NULL, db_report_map_write_value_cb, NULL); } + +done: + free(value); } static void read_report_map(struct bt_hog *hog) @@ -1394,7 +1393,7 @@ static void db_report_map_read_value_cb(struct gatt_db_attribute *attrib, int err, const uint8_t *value, size_t length, void *user_data) { - struct report_map *map = user_data; + struct iovec *map = user_data; if (err) { error("Error reading report map from gatt db %s", @@ -1405,8 +1404,9 @@ static void db_report_map_read_value_cb(struct gatt_db_attribute *attrib, if (!length) return; - map->length = length < sizeof(map->value) ? length : sizeof(map->value); - memcpy(map->value, value, map->length); + + map->iov_len = length; + map->iov_base = (void *) value; } static void foreach_hog_chrc(struct gatt_db_attribute *attr, void *user_data) @@ -1415,7 +1415,7 @@ static void foreach_hog_chrc(struct gatt_db_attribute *attr, void *user_data) bt_uuid_t uuid, report_uuid, report_map_uuid, info_uuid; bt_uuid_t proto_mode_uuid, ctrlpt_uuid; uint16_t handle, value_handle; - struct report_map report_map = {0}; + struct iovec map = {}; gatt_db_attribute_get_char_data(attr, &handle, &value_handle, NULL, NULL, &uuid); @@ -1438,14 +1438,14 @@ static void foreach_hog_chrc(struct gatt_db_attribute *attr, void *user_data) gatt_db_attribute_read(hog->report_map_attr, 0, BT_ATT_OP_READ_REQ, NULL, db_report_map_read_value_cb, - &report_map); + &map); } - if (report_map.length) { + if (map.iov_len) { /* Report map found in the cache, straight to creating * UHID to optimize reconnection. */ - uhid_create(hog, report_map.value, report_map.length); + uhid_create(hog, map.iov_base, map.iov_len); } gatt_db_service_foreach_desc(attr, foreach_hog_external, hog); -- 2.37.2