From 9a0566e791b76b74dae640d434430c36811a601b Mon Sep 17 00:00:00 2001 From: "injun.yang" Date: Mon, 13 Apr 2020 12:07:23 +0900 Subject: [PATCH] Set the permission of CCC descriptior properly [Model] All [BinType] AP [Customer] OPEN [Issue#] N/A [Request] Internal [Occurrence Version] N/A [Problem] Non bonded device can access to CCCD which have encrypted_authenticated permission [Cause & Measure] Even though application set encrypted_authenticated permission to CCCD, bluez set it as read & write permission [Checking Method] Register gatt server app which have encrypted_authenticated permiion on descriptor [Team] Convergence BT [Developer] Injun Yang [Solution company] Samsung [Change Type] Specification change Change-Id: If6e718946a1e14297f6bd8c7af232d7425947746 --- src/gatt-database.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/src/gatt-database.c b/src/gatt-database.c index 3eeebb3..ec83420 100644 --- a/src/gatt-database.c +++ b/src/gatt-database.c @@ -1239,6 +1239,42 @@ service_add_ccc(struct gatt_db_attribute *service, return ccc; } +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY +static struct gatt_db_attribute * +service_add_ccc_extra(struct gatt_db_attribute *service, + struct btd_gatt_database *database, + btd_gatt_database_ccc_write_t write_callback, + uint32_t perm, + void *user_data, + btd_gatt_database_destroy_t destroy) +{ + struct gatt_db_attribute *ccc; + struct ccc_cb_data *ccc_cb; + bt_uuid_t uuid; + + ccc_cb = new0(struct ccc_cb_data, 1); + + bt_uuid16_create(&uuid, GATT_CLIENT_CHARAC_CFG_UUID); + ccc = gatt_db_service_add_descriptor(service, &uuid, + perm, + gatt_ccc_read_cb, gatt_ccc_write_cb, database); + if (!ccc) { + error("Failed to create CCC entry in database"); + free(ccc_cb); + return NULL; + } + + ccc_cb->handle = gatt_db_attribute_get_handle(ccc); + ccc_cb->callback = write_callback; + ccc_cb->destroy = destroy; + ccc_cb->user_data = user_data; + + queue_push_tail(database->ccc_callbacks, ccc_cb); + + return ccc; +} +#endif + static void cli_feat_read_cb(struct gatt_db_attribute *attrib, unsigned int id, uint16_t offset, uint8_t opcode, struct bt_att *att, @@ -3153,6 +3189,32 @@ static void property_changed_cb(GDBusProxy *proxy, const char *name, #endif } +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY +static bool database_add_ccc_extra(struct external_service *service, + struct external_chrc *chrc, struct external_desc *desc) +{ + if (!(chrc->props & BT_GATT_CHRC_PROP_NOTIFY) && + !(chrc->props & BT_GATT_CHRC_PROP_INDICATE)) + return true; + + chrc->ccc = service_add_ccc_extra(service->attrib, service->app->database, + ccc_write_cb, desc->perm, chrc, NULL); + if (!chrc->ccc) { + error("Failed to create CCC entry for characteristic"); + return false; + } + + if (g_dbus_proxy_set_property_watch(chrc->proxy, property_changed_cb, + chrc) == FALSE) { + error("Failed to set up property watch for characteristic"); + return false; + } + + DBG("Created CCC entry for characteristic"); + + return true; +} +#else static bool database_add_ccc(struct external_service *service, struct external_chrc *chrc) { @@ -3177,6 +3239,7 @@ static bool database_add_ccc(struct external_service *service, return true; } +#endif static void cep_write_cb(struct gatt_db_attribute *attrib, int err, void *user_data) @@ -3565,7 +3628,7 @@ static bool database_add_chrc(struct external_service *service, /* Check if Application wants to add CCC and use existing * implemenation to add CCC descriptors */ if (database_check_ccc_desc(desc)) { - if (!database_add_ccc(service, chrc)) { + if (!database_add_ccc_extra(service, chrc, desc)) { chrc->attrib = NULL; return false; } -- 2.7.4