gatt: Add support for Central Address Resolution characteristic
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 28 Jul 2021 20:44:44 +0000 (13:44 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:36 +0000 (19:08 +0530)
This adds Central Address Resolution characteristic so peripherals can
use directed advertising using RPA as initiator address.

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

index 4d86ad3..e613c52 100755 (executable)
@@ -130,6 +130,7 @@ extern "C" {
 #define GATT_CHARAC_SOFTWARE_REVISION_STRING           0x2A28
 #define GATT_CHARAC_MANUFACTURER_NAME_STRING           0x2A29
 #define GATT_CHARAC_PNP_ID                             0x2A50
+#define GATT_CHARAC_CAR                                        0x2AA6
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
 #define GATT_CHARAC_CENTRAL_RPA_RESOLUTION             0x2AA6
 #endif
index 1da4d64..45ceba1 100644 (file)
@@ -803,6 +803,18 @@ static void gap_appearance_read_cb(struct gatt_db_attribute *attrib,
        gatt_db_attribute_read_result(attrib, id, error, value, len);
 }
 
+static void gap_car_read_cb(struct gatt_db_attribute *attrib,
+                                       unsigned int id, uint16_t offset,
+                                       uint8_t opcode, struct bt_att *att,
+                                       void *user_data)
+{
+       uint8_t value = 0x01;
+
+       DBG("GAP Central Address Resolution read request\n");
+
+       gatt_db_attribute_read_result(attrib, id, 0, &value, sizeof(value));
+}
+
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
 static void gap_rpa_res_support_read_cb(struct gatt_db_attribute *attrib,
                                        unsigned int id, uint16_t offset,
@@ -957,7 +969,7 @@ static void populate_gap_service(struct btd_gatt_database *database)
 
        /* Add the GAP service */
        bt_uuid16_create(&uuid, UUID_GAP);
-       service = gatt_db_add_service(database->db, &uuid, true, 5);
+       service = gatt_db_add_service(database->db, &uuid, true, 7);
 
        /*
         * Device Name characteristic.
@@ -990,6 +1002,17 @@ static void populate_gap_service(struct btd_gatt_database *database)
 
        gatt_db_attribute_set_fixed_length(attrib, 2);
 
+       /*
+        * Central Address Resolution characteristic.
+        */
+       bt_uuid16_create(&uuid, GATT_CHARAC_CAR);
+       attrib = gatt_db_service_add_characteristic(service, &uuid,
+                                                       BT_ATT_PERM_READ,
+                                                       BT_GATT_CHRC_PROP_READ,
+                                                       gap_car_read_cb,
+                                                       NULL, database);
+       gatt_db_attribute_set_fixed_length(attrib, 1);
+
        gatt_db_service_set_active(service, true);
 
        database_add_record(database, service);
@@ -4569,13 +4592,7 @@ void btd_gatt_database_restore_svc_chng_ccc(struct btd_gatt_database *database)
         */
        btd_adapter_for_each_device(database->adapter, restore_state, database);
 
-       /* This needs to be updated (probably to 0x0001) if we ever change
-        * core services
-        *
-        * TODO we could also store this info (along with CCC value) and be able
-        * to send 0x0001-0xffff only once per device.
-        */
-       put_le16(0x000a, value);
+       put_le16(0x0001, value);
        put_le16(0xffff, value + 2);
 
        send_notification_to_devices(database, handle, value, sizeof(value),