From 89797f506dbc08524c1df7b4d4fd9736ca8e6ede Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Wed, 21 Oct 2015 15:09:05 +0300 Subject: [PATCH] core/device: Fix not calling accept callback For GATT based services accept is used to indicate that there is a new connection available so it needs to be called immediately once ATT connects so the driver can register for notification, etc. This also renames probe_gatt_profile to add_gatt_service which is what in fact it was doing. --- src/device.c | 53 ++++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/src/device.c b/src/device.c index ffcd1bc5e..222c87fae 100644 --- a/src/device.c +++ b/src/device.c @@ -3239,7 +3239,7 @@ static bool device_match_profile(struct btd_device *device, return true; } -static void probe_gatt_profile(struct gatt_db_attribute *attr, void *user_data) +static void add_gatt_service(struct gatt_db_attribute *attr, void *user_data) { struct btd_device *device = user_data; struct btd_service *service; @@ -3251,6 +3251,11 @@ static void probe_gatt_profile(struct gatt_db_attribute *attr, void *user_data) gatt_db_attribute_get_service_uuid(attr, &uuid); bt_uuid_to_string(&uuid, uuid_str, sizeof(uuid_str)); + /* Check if service was already probed */ + l = find_service_with_uuid(device->services, uuid_str); + if (l) + return; + /* Add UUID and probe service */ btd_device_add_uuid(device, uuid_str); @@ -3265,15 +3270,17 @@ static void probe_gatt_profile(struct gatt_db_attribute *attr, void *user_data) service = l->data; profile = btd_service_get_profile(service); - /* Don't claim attributes of external profiles */ - if (profile->external) - return; + /* Claim attributes of internal profiles */ + if (!profile->external) { + /* Mark the service as claimed by the existing profile. */ + gatt_db_service_set_claimed(attr, true); + } - /* Mark the service as claimed by the existing profile. */ - gatt_db_service_set_claimed(attr, true); + /* Notify driver about the new connection */ + service_accept(service); } -static void device_probe_gatt_profiles(struct btd_device *device) +static void device_add_gatt_services(struct btd_device *device) { char addr[18]; @@ -3284,7 +3291,7 @@ static void device_probe_gatt_profiles(struct btd_device *device) return; } - gatt_db_foreach_service(device->db, NULL, probe_gatt_profile, device); + gatt_db_foreach_service(device->db, NULL, add_gatt_service, device); } static void device_accept_gatt_profiles(struct btd_device *device) @@ -3332,16 +3339,12 @@ static void gatt_service_added(struct gatt_db_attribute *attr, void *user_data) { struct btd_device *device = user_data; GSList *new_service = NULL; - bt_uuid_t uuid; - char uuid_str[MAX_LEN_UUID_STR]; uint16_t start, end; - GSList *l; if (!bt_gatt_client_is_ready(device->client)) return; - gatt_db_attribute_get_service_data(attr, &start, &end, NULL, &uuid); - bt_uuid_to_string(&uuid, uuid_str, sizeof(uuid_str)); + gatt_db_attribute_get_service_data(attr, &start, &end, NULL, NULL); DBG("start: 0x%04x, end: 0x%04x", start, end); @@ -3353,21 +3356,9 @@ static void gatt_service_added(struct gatt_db_attribute *attr, void *user_data) if (!new_service) return; - l = find_service_with_uuid(device->services, uuid_str); - device_register_primaries(device, new_service, -1); - /* - * If the profile was probed for the first time then call accept on - * the service. - */ - if (!l) { - l = find_service_with_uuid(device->services, uuid_str); - if (l) - service_accept(l->data); - } - - btd_device_add_uuid(device, uuid_str); + add_gatt_service(attr, device); btd_gatt_client_service_added(device->client_dbus, attr); @@ -4527,7 +4518,7 @@ static void register_gatt_services(struct btd_device *device) device_register_primaries(device, services, -1); - device_probe_gatt_profiles(device); + device_add_gatt_services(device); device_svc_resolved(device, device->bdaddr_type, 0); } @@ -4548,8 +4539,6 @@ static void gatt_client_ready_cb(bool success, uint8_t att_ecode, register_gatt_services(device); - device_accept_gatt_profiles(device); - btd_gatt_client_ready(device->client_dbus); /* @@ -4594,6 +4583,12 @@ static void gatt_client_init(struct btd_device *device) /* Notify attio so it can react to notifications */ g_slist_foreach(device->attios, attio_connected, device->attrib); + /* + * Notify notify existing service about the new connection so they can + * react to notifications while discovering services + */ + device_accept_gatt_profiles(device); + if (!bt_gatt_client_set_ready_handler(device->client, gatt_client_ready_cb, device, NULL)) { -- 2.47.3