Linux-Bluetooth Archive on lore.kernel.org
 help / color / Atom feed
* [Bluez PATCH] gatt: Support DeviceInfo Service when vid/pid is specified
@ 2020-07-17 13:42 Alain Michaud
  2020-07-17 13:49 ` [Bluez] " bluez.test.bot
  0 siblings, 1 reply; 2+ messages in thread
From: Alain Michaud @ 2020-07-17 13:42 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Alain Michaud, Miao-chen Chou

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 <mcchou@chromium.org>
Signed-off-by: Alain Michaud <alainm@chromium.org>
---
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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: [Bluez] gatt: Support DeviceInfo Service when vid/pid is specified
  2020-07-17 13:42 [Bluez PATCH] gatt: Support DeviceInfo Service when vid/pid is specified Alain Michaud
@ 2020-07-17 13:49 ` bluez.test.bot
  0 siblings, 0 replies; 2+ messages in thread
From: bluez.test.bot @ 2020-07-17 13:49 UTC (permalink / raw)
  To: linux-bluetooth, alainm


[-- Attachment #1: Type: text/plain, Size: 1568 bytes --]


This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
While we are preparing for reviewing the patches, we found the following
issue/warning.

Test Result:
checkbuild Failed

Outputs:
ar: `u' modifier ignored since `D' is the default (see `U')
ar: `u' modifier ignored since `D' is the default (see `U')
ar: `u' modifier ignored since `D' is the default (see `U')
ar: `u' modifier ignored since `D' is the default (see `U')
ar: `u' modifier ignored since `D' is the default (see `U')
In file included from peripheral/gatt.c:44:
./src/hcid.h:53:2: error: unknown type name ‘gboolean’
   53 |  gboolean pairable;
      |  ^~~~~~~~
./src/hcid.h:99:2: error: unknown type name ‘gboolean’
   99 |  gboolean reverse_discovery;
      |  ^~~~~~~~
./src/hcid.h:100:2: error: unknown type name ‘gboolean’
  100 |  gboolean name_resolv;
      |  ^~~~~~~~
./src/hcid.h:101:2: error: unknown type name ‘gboolean’
  101 |  gboolean debug_keys;
      |  ^~~~~~~~
./src/hcid.h:102:2: error: unknown type name ‘gboolean’
  102 |  gboolean fast_conn;
      |  ^~~~~~~~
./src/hcid.h:122:1: error: unknown type name ‘gboolean’
  122 | gboolean plugin_init(const char *enable, const char *disable);
      | ^~~~~~~~
./src/hcid.h:128:1: error: unknown type name ‘GKeyFile’
  128 | GKeyFile *btd_get_main_conf(void);
      | ^~~~~~~~
make[1]: *** [Makefile:6791: peripheral/gatt.o] Error 1
make: *** [Makefile:4010: all] Error 2



---
Regards,
Linux Bluetooth

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-17 13:42 [Bluez PATCH] gatt: Support DeviceInfo Service when vid/pid is specified Alain Michaud
2020-07-17 13:49 ` [Bluez] " bluez.test.bot

Linux-Bluetooth Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-bluetooth/0 linux-bluetooth/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-bluetooth linux-bluetooth/ https://lore.kernel.org/linux-bluetooth \
		linux-bluetooth@vger.kernel.org
	public-inbox-index linux-bluetooth

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-bluetooth


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git