diff --git a/src/device.c b/src/device.c
index ffcd1bc..222c87f 100644
--- a/src/device.c
+++ b/src/device.c
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;
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);
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];
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)
{
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);
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);
device_register_primaries(device, services, -1);
- device_probe_gatt_profiles(device);
+ device_add_gatt_services(device);
device_svc_resolved(device, device->bdaddr_type, 0);
}
register_gatt_services(device);
- device_accept_gatt_profiles(device);
-
btd_gatt_client_ready(device->client_dbus);
/*
/* 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)) {