From: Konstantin Zhukov Date: Mon, 12 Feb 2018 10:40:30 +0000 (+0400) Subject: shared/gatt-db: Fix declaration attributes permission X-Git-Tag: accepted/tizen/unified/20190522.085452~1^2~180 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a52c80d2450226e1f63589f6b6f2c5451b0b55f8;p=platform%2Fupstream%2Fbluez.git 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. Change-Id: Ib18c4de213e9c242a09a770d9f24cd850a1af6a0 Signed-off-by: Amit Purwar --- diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c index b99263c..4f2fb30 100644 --- a/src/shared/gatt-db.c +++ b/src/shared/gatt-db.c @@ -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); }