gatt: Fix not setting permissions for CCC
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Wed, 21 Sep 2022 21:40:14 +0000 (14:40 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:54 +0000 (14:55 +0530)
CCC shall always have both Read and Write permissions set in addition to
what application set.

Fixes: https://github.com/bluez/bluez/issues/399
Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/gatt-database.c

index f0f74c1..c916790 100644 (file)
@@ -1459,7 +1459,8 @@ static void populate_gatt_service(struct btd_gatt_database *database)
                                NULL, NULL, database);
 
        database->svc_chngd_ccc = service_add_ccc(service, database, NULL, NULL,
-                                                                   0, NULL);
+                                               BT_ATT_PERM_READ |
+                                               BT_ATT_PERM_WRITE, NULL);
 
        bt_uuid16_create(&uuid, GATT_CHARAC_CLI_FEAT);
        database->cli_feat = gatt_db_service_add_characteristic(service,
@@ -2129,8 +2130,10 @@ static bool parse_chrc_flags(DBusMessageIter *array, uint8_t *props,
                        *perm |= BT_ATT_PERM_WRITE;
                } else if (!strcmp("notify", flag)) {
                        *props |= BT_GATT_CHRC_PROP_NOTIFY;
+                       *ccc_perm |= BT_ATT_PERM_WRITE;
                } else if (!strcmp("indicate", flag)) {
                        *props |= BT_GATT_CHRC_PROP_INDICATE;
+                       *ccc_perm |= BT_ATT_PERM_WRITE;
                } else if (!strcmp("authenticated-signed-writes", flag)) {
                        *props |= BT_GATT_CHRC_PROP_AUTH;
                        *perm |= BT_ATT_PERM_WRITE;
@@ -3561,6 +3564,9 @@ static bool database_add_ccc(struct external_service *service,
                                !(chrc->props & BT_GATT_CHRC_PROP_INDICATE))
                return true;
 
+       /* Always set read/write permissions */
+       chrc->ccc_perm |= BT_ATT_PERM_WRITE | BT_ATT_PERM_READ;
+
        chrc->ccc = service_add_ccc(service->attrib, service->app->database,
                                    ccc_write_cb, chrc, chrc->ccc_perm, NULL);
        if (!chrc->ccc) {