gatt-db: Allow passing Characteristic Value to gatt_db_attribute_get_char_data
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Thu, 12 May 2022 00:55:14 +0000 (17:55 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:54 +0000 (14:55 +0530)
This makes gatt_db_attribute_get_char_data work with Characteristic
Value rather than only with Characteristic Declaration.

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/shared/gatt-db.c

index 9d53708..9a7d64b 100644 (file)
@@ -1535,7 +1535,7 @@ void gatt_db_service_foreach_char(struct gatt_db_attribute *attrib,
        gatt_db_service_foreach(attrib, &characteristic_uuid, func, user_data);
 }
 
-static int gatt_db_attribute_get_index(struct gatt_db_attribute *attrib)
+static int gatt_db_attribute_get_index(const struct gatt_db_attribute *attrib)
 {
        struct gatt_db_service *service;
        int index;
@@ -1860,8 +1860,18 @@ bool gatt_db_attribute_get_char_data(const struct gatt_db_attribute *attrib,
        if (!attrib)
                return false;
 
-       if (bt_uuid_cmp(&characteristic_uuid, &attrib->uuid))
-               return false;
+       if (bt_uuid_cmp(&characteristic_uuid, &attrib->uuid)) {
+               int index;
+
+               /* Check if Characteristic Value was passed instead */
+               index = gatt_db_attribute_get_index(attrib);
+               if (index < 0)
+                       return NULL;
+
+               attrib = attrib->service->attributes[index - 1];
+               if (bt_uuid_cmp(&characteristic_uuid, &attrib->uuid))
+                       return false;
+       }
 
        /*
         * Characteristic declaration value: