Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1987677ybh; Fri, 17 Jul 2020 06:43:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSPZXzgf7HFsYSaHCuK60ApC75d4QF1n4LhPOAnKjbLSXg8WFCfEeX6yVuYAZ2bRf2g7yU X-Received: by 2002:aa7:c3d8:: with SMTP id l24mr9018183edr.97.1594993439487; Fri, 17 Jul 2020 06:43:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594993439; cv=none; d=google.com; s=arc-20160816; b=Pux11R4TkH5Fh03Ioz7mRN0ZVByCtqoowRuudxQ+1qQxJE8CwR/XN9i2YZKdjGx3nO sDrQx1qR2gXUtC3EaJj9SzhxYE+eLmUy40tccILzaeuXEC1eUWDnWMxyJWgkoH1/nEzv fK8v39fUO66YFRXMBBLF4oreTrcNmvp31cO08b5qM/1dZ1MfoudbU+YK+6TVJM5mm13i fF5fEh1JN1nR9AJcv1fINqkEhy1ACbEGi1xyKKhge+C6tI/jS1KWY+IxquTCKplrDTTc wNfOI2wiUIdtreHKSeFVnQmxyMOKswubr0xX58v4Xt9fW76kFwOoXnS9t0T5cX7Epeam naZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=GGV1wbj0653P2xg+RLSu9dXMV9pkHnXxYlofmrHKvcc=; b=CXspxLnFFE8HmPA8RKtnTEKWRGNferp6h3hNDqzySYSLXj0kiXszKcJclHwMele0sd uVUnl4UiDC5FxlhPzKUbFomBYMoTaOdHxc1qcYCQzrFuz6uHo7FOa4Tozn2vWZOcIkY5 ZzmMKvqQz8N+qPp1MRj9AbawSOtrpv+pvdHKzxBtuFAby4OWPTfnjePRbYGXkxulqn3i aOF1VCYxE3ephAZYFTqST8Rwf9qGYuLdF9x81ZpatXq4kfRSW8hnSRXh6UKaQcM988HK B4YP9U+qGQWJIOSq1Oa2Yq+wqsUOijhHlueXRSRMFpKXRA0zgz5i+UcAkr19FL+WVzip 4+kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WeuJSBRc; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d21si4877661eje.437.2020.07.17.06.43.19; Fri, 17 Jul 2020 06:43:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=WeuJSBRc; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726090AbgGQNm5 (ORCPT + 99 others); Fri, 17 Jul 2020 09:42:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726079AbgGQNm5 (ORCPT ); Fri, 17 Jul 2020 09:42:57 -0400 Received: from mail-vs1-xe36.google.com (mail-vs1-xe36.google.com [IPv6:2607:f8b0:4864:20::e36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E9D2C061755 for ; Fri, 17 Jul 2020 06:42:57 -0700 (PDT) Received: by mail-vs1-xe36.google.com with SMTP id o184so4883202vsc.0 for ; Fri, 17 Jul 2020 06:42:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=GGV1wbj0653P2xg+RLSu9dXMV9pkHnXxYlofmrHKvcc=; b=WeuJSBRc31y8MSyH7T1a0bhW+jM124fD+aojzvjSwvpGXIolPgVXtJD4nwdJZ2a25z +jIUyUrNqxnL48bKJW7FJHqLxIB+dmaHHi4Njk+/mjPrOUuTiQioveu8Vo+I48JhqZnP PC1nm0ke1huFdTbtwfXwTDUwuI6HujDtmtSpA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=GGV1wbj0653P2xg+RLSu9dXMV9pkHnXxYlofmrHKvcc=; b=SLOSaAcejGL4Ikq7LTFCw4CiGw6MxXc3nIvoVrsoUzMcbt+9ZmLSikXqOaYGgfDai2 tDbxngfi+c/GU9mLsEdhReIrgOReEsuqeHYaddVSxRBeAub2hgnWWANuIYe5AtuOAYZ4 Hkzu0nsn//qMFLmtMznv5bc7MqSWngcpzTK+etXibcnn4wDPi8bMLqHzIiW1lvXz5F6L c+WX+N2dDo8vhaCJAebxNIIchYsMguODbra0WLG7GYBQmaReLrm+g0WjcqNv54Qb/v95 hmwVQXk5mXoixiJNDQSnEUt5V3T89vzgaTuEZaQX5HutqMMDuLtkI2hly3h7xC1KyhPF Hy+A== X-Gm-Message-State: AOAM531BWTKH2utWRVXGnO2pLOO4negmDUvy96mh2bksZHN8DzXIAvJV H/DgE5pPL3db5JoGTZYb9WFwYOH+img= X-Received: by 2002:a67:f50e:: with SMTP id u14mr7026446vsn.240.1594993375512; Fri, 17 Jul 2020 06:42:55 -0700 (PDT) Received: from alain.c.googlers.com.com (252.177.243.35.bc.googleusercontent.com. [35.243.177.252]) by smtp.gmail.com with ESMTPSA id q11sm1283385vkn.47.2020.07.17.06.42.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2020 06:42:54 -0700 (PDT) From: Alain Michaud To: linux-bluetooth@vger.kernel.org Cc: Alain Michaud , Miao-chen Chou Subject: [Bluez PATCH] gatt: Support DeviceInfo Service when vid/pid is specified Date: Fri, 17 Jul 2020 13:42:51 +0000 Message-Id: <20200717134251.3148686-1-alainm@chromium.org> X-Mailer: git-send-email 2.28.0.rc0.105.gf9edc3c819-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch adds support for the PNPID characteristic when configured in main.conf. This was validated as read correclty both by manually reading the valud and confirming in the Ellisys Analyzer. ATT Read (PnP ID: Source=Bluetooth ID, Vendor=224, Product=50181, ATT Read Response Packet (Source=Bluetooth ID, Vendor=224, Product=50181, Version=86) | OK | 7 bytes (01 E0 00 05 C4 56 00) Reviewed-by: Miao-chen Chou Signed-off-by: Alain Michaud --- I admit I don't know how to quantify the compatibility risk with adding the Device Info Service if the DeviceID is specified. I can see that some system may be configured with an app to publish the DIS and this may break it. If the community feels it is necessary, I can include a DeviceIdOverLE configuration which defaults to false in main.conf to address this compatibility risk. peripheral/gatt.c | 28 +++++++++++++++++++++++++++- src/gatt-database.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/peripheral/gatt.c b/peripheral/gatt.c index bbbf3f59f..aeb286563 100644 --- a/peripheral/gatt.c +++ b/peripheral/gatt.c @@ -41,11 +41,13 @@ #include "src/shared/gatt-db.h" #include "src/shared/gatt-server.h" #include "src/shared/gatt-client.h" +#include "src/hcid.h" #include "peripheral/gatt.h" #define ATT_CID 4 #define UUID_GAP 0x1800 +#define UUID_DIS 0x180a struct gatt_conn { struct bt_att *att; @@ -229,14 +231,38 @@ static void populate_gap_service(struct gatt_db *db) gatt_db_service_set_active(service, true); } +static void device_info_read_pnp_id_cb(struct gatt_db_attribute *attrib, + unsigned int id, uint16_t offset, + uint8_t opcode, struct bt_att *att, + void *user_data) +{ + uint8_t pdu[7]; + + pdu[0] = main_opts.did_source; + put_le16(main_opts.did_vendor, &pdu[1]); + put_le16(main_opts.did_product, &pdu[3]); + put_le16(main_opts.did_version, &pdu[5]); + + gatt_db_attribute_read_result(attrib, id, 0, pdu, sizeof(pdu)); +} + static void populate_devinfo_service(struct gatt_db *db) { struct gatt_db_attribute *service; bt_uuid_t uuid; - bt_uuid16_create(&uuid, 0x180a); + bt_uuid16_create(&uuid, UUID_DIS); service = gatt_db_add_service(db, &uuid, true, 17); + if (main_opts.did_source > 0) { + bt_uuid16_create(&uuid, GATT_CHARAC_PNP_ID); + gatt_db_service_add_characteristic(service, &uuid, + BT_ATT_PERM_READ, + BT_GATT_CHRC_PROP_READ, + device_info_read_pnp_id_cb, + NULL, NULL); + } + gatt_db_service_set_active(service, true); } diff --git a/src/gatt-database.c b/src/gatt-database.c index 95ba39897..07d567078 100644 --- a/src/gatt-database.c +++ b/src/gatt-database.c @@ -57,6 +57,7 @@ #define UUID_GAP 0x1800 #define UUID_GATT 0x1801 +#define UUID_DIS 0x180a #ifndef MIN #define MIN(a, b) ((a) < (b) ? (a) : (b)) @@ -1233,11 +1234,51 @@ static void populate_gatt_service(struct btd_gatt_database *database) database_add_record(database, service); } +static void device_info_read_pnp_id_cb(struct gatt_db_attribute *attrib, + unsigned int id, uint16_t offset, + uint8_t opcode, struct bt_att *att, + void *user_data) +{ + uint8_t pdu[7]; + + pdu[0] = main_opts.did_source; + put_le16(main_opts.did_vendor, &pdu[1]); + put_le16(main_opts.did_product, &pdu[3]); + put_le16(main_opts.did_version, &pdu[5]); + + gatt_db_attribute_read_result(attrib, id, 0, pdu, sizeof(pdu)); +} + +static void populate_devinfo_service(struct btd_gatt_database *database) +{ + struct gatt_db_attribute *service; + bt_uuid_t uuid; + + bt_uuid16_create(&uuid, UUID_DIS); + service = gatt_db_add_service(database->db, &uuid, true, 3); + + if (main_opts.did_source > 0) { + bt_uuid16_create(&uuid, GATT_CHARAC_PNP_ID); + gatt_db_service_add_characteristic(service, &uuid, + BT_ATT_PERM_READ, + BT_GATT_CHRC_PROP_READ, + device_info_read_pnp_id_cb, + NULL, database); + } + + gatt_db_service_set_active(service, true); + + database_add_record(database, service); +} static void register_core_services(struct btd_gatt_database *database) { populate_gap_service(database); populate_gatt_service(database); + + if (main_opts.did_source > 0) + populate_devinfo_service(database); + } static void conf_cb(void *user_data) -- 2.28.0.rc0.105.gf9edc3c819-goog