gatt: Support DeviceInfo Service when vid/pid is specified
authorAlain Michaud <alainm@chromium.org>
Fri, 17 Jul 2020 14:40:07 +0000 (14:40 +0000)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 12 Apr 2021 09:00:49 +0000 (14:30 +0530)
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)

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/gatt-database.c

index d4873eb..14c1ce8 100644 (file)
@@ -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))
@@ -1452,11 +1453,50 @@ 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);
+
 }
 
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY