From 79d1a060bfcad5c7f32ef3fb17cb382538ad1fc2 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 21 Jan 2022 12:52:14 -0800 Subject: [PATCH] gatt: Make use of gatt_db_attribute_notify This makes use of gatt_db_attribute_notify to send indications of Service Changed. Signed-off-by: Manika Shrivastava Signed-off-by: Ayush Garg --- src/gatt-database.c | 74 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 15 deletions(-) diff --git a/src/gatt-database.c b/src/gatt-database.c index cadd718..75ffd57 100644 --- a/src/gatt-database.c +++ b/src/gatt-database.c @@ -446,6 +446,18 @@ find_device_state_from_address(struct btd_gatt_database *database, const bdaddr_ } #endif +static struct device_state * +find_device_state_by_att(struct btd_gatt_database *database, struct bt_att *att) +{ + bdaddr_t bdaddr; + uint8_t bdaddr_type; + + if (!get_dst_info(att, &bdaddr, &bdaddr_type)) + return NULL; + + return find_device_state(database, &bdaddr, bdaddr_type); +} + static struct device_state *get_device_state(struct btd_gatt_database *database, struct bt_att *att) { @@ -1519,17 +1531,6 @@ static void populate_devinfo_service(struct btd_gatt_database *database) database_add_record(database, service); } -static void register_core_services(struct btd_gatt_database *database) -{ - gatt_db_ccc_register(database->db, gatt_ccc_read_cb, gatt_ccc_write_cb, - NULL, database); - - populate_gap_service(database); - populate_gatt_service(database); - - populate_devinfo_service(database); - -} #ifdef TIZEN_FEATURE_BLUEZ_MODIFY struct notify_indicate { @@ -1836,6 +1837,49 @@ remove: } } +static void gatt_notify_cb(struct gatt_db_attribute *attrib, + struct gatt_db_attribute *ccc, + const uint8_t *value, size_t len, + struct bt_att *att, void *user_data) +{ + struct btd_gatt_database *database = user_data; + struct notify notify; + + memset(¬ify, 0, sizeof(notify)); + + notify.database = database; + notify.handle = gatt_db_attribute_get_handle(attrib); + notify.ccc_handle = gatt_db_attribute_get_handle(ccc); + notify.value = (void *) value; + notify.len = len; + + if (attrib == database->svc_chngd) + notify.conf = service_changed_conf; + + /* If a specific att is provided notify only to that device */ + if (att) { + struct device_state *state; + + state = find_device_state_by_att(database, att); + if (!state) + return; + + send_notification_to_device(state, ¬ify); + } else + queue_foreach(database->device_states, + send_notification_to_device, ¬ify); +} + +static void register_core_services(struct btd_gatt_database *database) +{ + gatt_db_ccc_register(database->db, gatt_ccc_read_cb, gatt_ccc_write_cb, + gatt_notify_cb, database); + + populate_gap_service(database); + populate_gatt_service(database); + populate_devinfo_service(database); +} + static void send_notification_to_devices(struct btd_gatt_database *database, uint16_t handle, uint8_t *value, uint16_t len, uint16_t ccc_handle, @@ -1882,8 +1926,8 @@ static void send_service_changed(struct btd_gatt_database *database, put_le16(start, value); put_le16(end, value + 2); - send_notification_to_devices(database, handle, value, sizeof(value), - ccc_handle, service_changed_conf, NULL); + gatt_db_attribute_notify(database->svc_chngd, value, sizeof(value), + NULL); } static void gatt_db_service_added(struct gatt_db_attribute *attrib, @@ -4633,6 +4677,6 @@ void btd_gatt_database_restore_svc_chng_ccc(struct btd_gatt_database *database) put_le16(0x0001, value); put_le16(0xffff, value + 2); - send_notification_to_devices(database, handle, value, sizeof(value), - ccc_handle, service_changed_conf, NULL); + gatt_db_attribute_notify(database->svc_chngd, value, sizeof(value), + NULL); } -- 2.7.4