Skip to contentSkip to conversation

shared/gatt-db: Fix declaration attributes permission

PATCH In review Konstantin Zhukov 2 participants 2 messages Feb 12, 2018 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 shared/gatt-db: Fix declaration attributes permission

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.

---
 src/shared/gatt-db.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
src/shared/gatt-db.c +11 -1
index 2487584f3..814e79bed 100644
@@ -115,6 +115,12 @@ 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);
+
 static void pending_read_result(struct pending_read *p, int err,
 					const uint8_t *data, size_t length)
 {
@@ -387,6 +393,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;
 }
 
@@ -718,6 +726,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);
@@ -929,7 +939,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);
 }
Signature · 1 line
2.14.1
#1 lore raw

Hi Konstantin,

Quoted 57 lines · Konstantin Zhukov

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.

---
 src/shared/gatt-db.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
src/shared/gatt-db.c +11 -2
index 2487584f3..814e79bed 100644
@@ -115,6 +115,12 @@ 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);
+
 static void pending_read_result(struct pending_read *p, int err,
                                        const uint8_t *data, size_t length)
 {
@@ -387,6 +393,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;
 }
 
@@ -718,6 +726,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);
@@ -929,7 +939,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);
 }
--
Quoted 1 line

2.14.1

Applied after changing it to not use a forward declaration, thanks.

Signature · 1 line
Luiz Augusto von Dentz