shared/gatt-db: Fix declaration attributes permission 02/204902/1
authorKonstantin Zhukov <zhukov@mercurydevelopment.com>
Mon, 12 Feb 2018 10:40:30 +0000 (14:40 +0400)
committerAmit Purwar <amit.purwar@samsung.com>
Mon, 15 Apr 2019 03:27:15 +0000 (08:57 +0530)
According to Bluetooth Core specification v4.2 (Vol. 3, part G,
section 3.1), service declararion attributes should have only READ
permission. The same obligation has charateristic declaration and
include service declaration attributes.

Without this permission connected clients could corrupt GATT database
by writing to declaration attributes. After thatm service discovery
fails in other clients.

Change-Id: Ib18c4de213e9c242a09a770d9f24cd850a1af6a0
Signed-off-by: Amit Purwar <amit.purwar@samsung.com>
src/shared/gatt-db.c

index b99263c..4f2fb30 100644 (file)
@@ -119,6 +119,18 @@ struct gatt_db_service {
        struct gatt_db_attribute **attributes;
 };
 
+static void set_attribute_data(struct gatt_db_attribute *attribute,
+                                               gatt_db_read_t read_func,
+                                               gatt_db_write_t write_func,
+                                               uint32_t permissions,
+                                               void *user_data)
+{
+       attribute->permissions = permissions;
+       attribute->read_func = read_func;
+       attribute->write_func = write_func;
+       attribute->user_data = user_data;
+}
+
 static void pending_read_result(struct pending_read *p, int err,
                                        const uint8_t *data, size_t length)
 {
@@ -391,6 +403,8 @@ static struct gatt_db_service *gatt_db_service_create(const bt_uuid_t *uuid,
                return NULL;
        }
 
+       set_attribute_data(service->attributes[0], NULL, NULL, BT_ATT_PERM_READ, NULL);
+
        return service;
 }
 
@@ -659,18 +673,6 @@ attribute_update(struct gatt_db_service *service, int index)
        return service->attributes[index];
 }
 
-static void set_attribute_data(struct gatt_db_attribute *attribute,
-                                               gatt_db_read_t read_func,
-                                               gatt_db_write_t write_func,
-                                               uint32_t permissions,
-                                               void *user_data)
-{
-       attribute->permissions = permissions;
-       attribute->read_func = read_func;
-       attribute->write_func = write_func;
-       attribute->user_data = user_data;
-}
-
 static struct gatt_db_attribute *
 service_insert_characteristic(struct gatt_db_service *service,
                                        uint16_t handle,
@@ -722,6 +724,8 @@ service_insert_characteristic(struct gatt_db_service *service,
        if (!service->attributes[i])
                return NULL;
 
+       set_attribute_data(service->attributes[i], NULL, NULL, BT_ATT_PERM_READ, NULL);
+
        i++;
 
        service->attributes[i] = new_attribute(service, handle, uuid, NULL, 0);
@@ -936,7 +940,7 @@ service_insert_included(struct gatt_db_service *service, uint16_t handle,
         *
         * TODO handle permissions
         */
-       set_attribute_data(service->attributes[index], NULL, NULL, 0, NULL);
+       set_attribute_data(service->attributes[index], NULL, NULL, BT_ATT_PERM_READ, NULL);
 
        return attribute_update(service, index);
 }