Created
September 30, 2021 20:19
-
-
Save Vudentz/af6899625df3d83b62cfbc61bbd4b94b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/gatt-database.c b/src/gatt-database.c | |
index fd4a39166..248c51e9a 100644 | |
--- a/src/gatt-database.c | |
+++ b/src/gatt-database.c | |
@@ -115,6 +115,7 @@ struct external_chrc { | |
uint8_t props; | |
uint8_t ext_props; | |
uint32_t perm; | |
+ uint32_t ccc_perm; | |
uint16_t mtu; | |
struct io *write_io; | |
struct io *notify_io; | |
@@ -1059,14 +1060,12 @@ static struct gatt_db_attribute * | |
service_add_ccc(struct gatt_db_attribute *service, | |
struct btd_gatt_database *database, | |
btd_gatt_database_ccc_write_t write_callback, | |
- void *user_data, | |
- uint32_t parent_permissions, | |
+ void *user_data, uint32_t perm, | |
btd_gatt_database_destroy_t destroy) | |
{ | |
struct gatt_db_attribute *ccc; | |
struct ccc_cb_data *ccc_cb; | |
bt_uuid_t uuid; | |
- uint32_t permissions; | |
ccc_cb = new0(struct ccc_cb_data, 1); | |
@@ -1074,19 +1073,10 @@ service_add_ccc(struct gatt_db_attribute *service, | |
* Provide a way for the permissions on a characteristic to dictate | |
* the permissions on the CCC | |
*/ | |
- permissions = BT_ATT_PERM_READ | BT_ATT_PERM_WRITE; | |
- | |
- if (parent_permissions & BT_ATT_PERM_SERVER_INITIATED_UPDATE_ENCRYPT) | |
- permissions |= BT_ATT_PERM_WRITE_ENCRYPT; | |
- | |
- if (parent_permissions & BT_ATT_PERM_SERVER_INITIATED_UPDATE_AUTHEN) | |
- permissions |= BT_ATT_PERM_WRITE_AUTHEN; | |
- | |
- if (parent_permissions & BT_ATT_PERM_SERVER_INITIATED_UPDATE_SECURE) | |
- permissions |= BT_ATT_PERM_WRITE_SECURE; | |
+ perm |= BT_ATT_PERM_READ | BT_ATT_PERM_WRITE; | |
bt_uuid16_create(&uuid, GATT_CLIENT_CHARAC_CFG_UUID); | |
- ccc = gatt_db_service_add_descriptor(service, &uuid, permissions, | |
+ 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"); | |
@@ -1648,12 +1638,19 @@ static bool incr_attr_count(struct external_service *service, uint16_t incr) | |
} | |
static bool parse_chrc_flags(DBusMessageIter *array, uint8_t *props, | |
- uint8_t *ext_props, uint32_t *perm, | |
- bool *req_prep_authorization) | |
+ uint8_t *ext_props, uint32_t *perm, | |
+ uint32_t *ccc_perm, | |
+ bool *req_prep_authorization) | |
{ | |
const char *flag; | |
- *props = *ext_props = 0; | |
+ if (!props || !ext_props || !perm || !ccc_perm) | |
+ return false; | |
+ | |
+ *props = 0; | |
+ *ext_props = 0; | |
+ *perm = 0; | |
+ *ccc_perm = 0; | |
do { | |
if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_STRING) | |
@@ -1707,22 +1704,22 @@ static bool parse_chrc_flags(DBusMessageIter *array, uint8_t *props, | |
} else if (!strcmp("authorize", flag)) { | |
*req_prep_authorization = true; | |
} else if (!strcmp("encrypt-notify", flag)) { | |
- *perm |= BT_ATT_PERM_SERVER_INITIATED_UPDATE_ENCRYPT; | |
+ *ccc_perm |= BT_ATT_PERM_WRITE_ENCRYPT; | |
*props |= BT_GATT_CHRC_PROP_NOTIFY; | |
} else if (!strcmp("encrypt-authenticated-notify", flag)) { | |
- *perm |= BT_ATT_PERM_SERVER_INITIATED_UPDATE_AUTHEN; | |
+ *ccc_perm |= BT_ATT_PERM_WRITE_AUTHEN; | |
*props |= BT_GATT_CHRC_PROP_NOTIFY; | |
} else if (!strcmp("secure-notify", flag)) { | |
- *perm |= BT_ATT_PERM_SERVER_INITIATED_UPDATE_SECURE; | |
+ *ccc_perm |= BT_ATT_PERM_WRITE_SECURE; | |
*props |= BT_GATT_CHRC_PROP_NOTIFY; | |
} else if (!strcmp("encrypt-indicate", flag)) { | |
- *perm |= BT_ATT_PERM_SERVER_INITIATED_UPDATE_ENCRYPT; | |
+ *ccc_perm |= BT_ATT_PERM_WRITE_ENCRYPT; | |
*props |= BT_GATT_CHRC_PROP_INDICATE; | |
} else if (!strcmp("encrypt-authenticated-indicate", flag)) { | |
- *perm |= BT_ATT_PERM_SERVER_INITIATED_UPDATE_AUTHEN; | |
+ *ccc_perm |= BT_ATT_PERM_WRITE_AUTHEN; | |
*props |= BT_GATT_CHRC_PROP_INDICATE; | |
} else if (!strcmp("secure-indicate", flag)) { | |
- *perm |= BT_ATT_PERM_SERVER_INITIATED_UPDATE_SECURE; | |
+ *ccc_perm |= BT_ATT_PERM_WRITE_SECURE; | |
*props |= BT_GATT_CHRC_PROP_INDICATE; | |
} else { | |
error("Invalid characteristic flag: %s", flag); | |
@@ -1777,7 +1774,8 @@ static bool parse_desc_flags(DBusMessageIter *array, uint32_t *perm, | |
} | |
static bool parse_flags(GDBusProxy *proxy, uint8_t *props, uint8_t *ext_props, | |
- uint32_t *perm, bool *req_prep_authorization) | |
+ uint32_t *perm, uint32_t *ccc_perm, | |
+ bool *req_prep_authorization) | |
{ | |
DBusMessageIter iter, array; | |
const char *iface; | |
@@ -1794,7 +1792,7 @@ static bool parse_flags(GDBusProxy *proxy, uint8_t *props, uint8_t *ext_props, | |
if (!strcmp(iface, GATT_DESC_IFACE)) | |
return parse_desc_flags(&array, perm, req_prep_authorization); | |
- return parse_chrc_flags(&array, props, ext_props, perm, | |
+ return parse_chrc_flags(&array, props, ext_props, perm, ccc_perm, | |
req_prep_authorization); | |
} | |
@@ -1844,7 +1842,7 @@ static struct external_chrc *chrc_create(struct gatt_app *app, | |
* created. | |
*/ | |
if (!parse_flags(proxy, &chrc->props, &chrc->ext_props, &chrc->perm, | |
- &chrc->req_prep_authorization)) { | |
+ &chrc->ccc_perm, &chrc->req_prep_authorization)) { | |
error("Failed to parse characteristic properties"); | |
goto fail; | |
} | |
@@ -1926,7 +1924,7 @@ static struct external_desc *desc_create(struct gatt_app *app, | |
* Parse descriptors flags here since they are used to | |
* determine the permission the descriptor should have | |
*/ | |
- if (!parse_flags(proxy, NULL, NULL, &desc->perm, | |
+ if (!parse_flags(proxy, NULL, NULL, &desc->perm, NULL, | |
&desc->req_prep_authorization)) { | |
error("Failed to parse characteristic properties"); | |
goto fail; | |
@@ -2830,7 +2828,8 @@ static bool database_add_ccc(struct external_service *service, | |
return true; | |
chrc->ccc = service_add_ccc(service->attrib, service->app->database, | |
- ccc_write_cb, chrc, chrc->perm, NULL); | |
+ ccc_write_cb, chrc, chrc->ccc_perm, | |
+ NULL); | |
if (!chrc->ccc) { | |
error("Failed to create CCC entry for characteristic"); | |
return false; | |
diff --git a/src/shared/att-types.h b/src/shared/att-types.h | |
index eb5def503..a08b24155 100644 | |
--- a/src/shared/att-types.h | |
+++ b/src/shared/att-types.h | |
@@ -137,10 +137,6 @@ struct bt_att_pdu_error_rsp { | |
BT_ATT_PERM_WRITE_AUTHEN | \ | |
BT_ATT_PERM_WRITE_ENCRYPT | \ | |
BT_ATT_PERM_WRITE_SECURE) | |
-/* Permissions to be applied to the CCC*/ | |
-#define BT_ATT_PERM_SERVER_INITIATED_UPDATE_ENCRYPT 0x0400 | |
-#define BT_ATT_PERM_SERVER_INITIATED_UPDATE_AUTHEN 0x0800 | |
-#define BT_ATT_PERM_SERVER_INITIATED_UPDATE_SECURE 0x1000 | |
/* GATT Characteristic Properties Bitfield values */ | |
#define BT_GATT_CHRC_PROP_BROADCAST 0x01 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment