Skip to contentSkip to conversation

Check if profile local_uuid is enabled

RFC New Luiz Augusto von Dentz 1 participant 4 messages Nov 13, 2013 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

cover Check if profile local_uuid is enabled

From: Luiz Augusto von Dentz <[email protected]>

This attempts to solve a problem with certain APIs that are adapter bond such as Media interface and adapter_service_add as opposed to btd_profile that is valid for every adapter.

Making Media API to be available on /org/bluez and perhaps tight btd_profile and adapter_service_add should solve the problem in the long term but since we cannot just break the API this is probably still necessary.

Luiz Augusto von Dentz (3):
core/device: Only connect profiles which are enabled audio/A2DP: Set profile .local_uuid properly
input: Fix setting .local_uuid

 profiles/audio/a2dp.c    |  2 ++
 profiles/input/manager.c |  1 -
 src/device.c             | 35 ++++++++++++++++++++++++++++++-----
 3 files changed, 32 insertions(+), 6 deletions(-)
Signature · 1 line
1.8.3.1
author maintainer
#1 lore raw

RFC 1/3 core/device: Only connect profiles which are enabled

From: Luiz Augusto von Dentz <[email protected]>

Some profile may register their records dynamically e.g. A2DP so the code has to check if the profile is really available before attempting to connect.

---
 src/device.c | 35 ++++++++++++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 5 deletions(-)
src/device.c +30 -5
index 9ca457e..60efd62 100644
@@ -1224,11 +1224,25 @@ void device_add_eir_uuids(struct btd_device *dev, GSList *uuids)
 						DEVICE_INTERFACE, "UUIDs");
 }
 
+static int uuid_cmp(const void *a, const void *b)
+{
+	const sdp_record_t *rec = a;
+	const char *string = b;
+	uuid_t uuid;
+
+	if (bt_string2uuid(&uuid, string) < 0)
+		return -1;
+
+	return sdp_uuid_cmp(&rec->svclass, &uuid);
+}
+
 static struct btd_service *find_connectable_service(struct btd_device *dev,
 							const char *uuid)
 {
 	GSList *l;
+	sdp_list_t *uuids;
 
+	uuids = btd_adapter_get_services(dev->adapter);
 	for (l = dev->services; l != NULL; l = g_slist_next(l)) {
 		struct btd_service *service = l->data;
 		struct btd_profile *p = btd_service_get_profile(service);
@@ -1236,7 +1250,12 @@ static struct btd_service *find_connectable_service(struct btd_device *dev,
 		if (!p->connect || !p->remote_uuid)
 			continue;
 
-		if (strcasecmp(uuid, p->remote_uuid) == 0)
+		if (strcasecmp(uuid, p->remote_uuid))
+			continue;
+
+		/* Check if adapter has the local_uuid enabled */
+		if (!p->local_uuid || sdp_list_find(uuids,
+					(void *) p->local_uuid, uuid_cmp))
 			return service;
 	}
 
@@ -1256,6 +1275,7 @@ static GSList *create_pending_list(struct btd_device *dev, const char *uuid)
 	struct btd_service *service;
 	struct btd_profile *p;
 	GSList *l;
+	sdp_list_t *uuids;
 
 	if (uuid) {
 		service = find_connectable_service(dev, uuid);
@@ -1265,6 +1285,7 @@ static GSList *create_pending_list(struct btd_device *dev, const char *uuid)
 		return dev->pending;
 	}
 
+	uuids = btd_adapter_get_services(dev->adapter);
 	for (l = dev->services; l != NULL; l = g_slist_next(l)) {
 		service = l->data;
 		p = btd_service_get_profile(service);
@@ -1272,14 +1293,18 @@ static GSList *create_pending_list(struct btd_device *dev, const char *uuid)
 		if (!p->auto_connect)
 			continue;
 
-		if (g_slist_find(dev->pending, service))
-			continue;
-
 		if (btd_service_get_state(service) !=
 						BTD_SERVICE_STATE_DISCONNECTED)
 			continue;
 
-		dev->pending = g_slist_insert_sorted(dev->pending, service,
+		if (g_slist_find(dev->pending, service))
+			continue;
+
+		/* Check if adapter has the local_uuid enabled */
+		if (!p->local_uuid || sdp_list_find(uuids,
+					(void *) p->local_uuid, uuid_cmp))
+			dev->pending = g_slist_insert_sorted(dev->pending,
+							service,
 							service_prio_cmp);
 	}
 
Signature · 1 line
1.8.3.1
author maintainer
#2 lore raw

RFC 2/3 audio/A2DP: Set profile .local_uuid properly

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

With the changes to the core now it does a strict match of adapter profiles with .local_uuid to prevent connecting to profiles not enabled in SDP.

---
 profiles/audio/a2dp.c | 2 ++
 1 file changed, 2 insertions(+)
profiles/audio/a2dp.c +2 -0
index 6b3d6b2..0a347e5 100644
@@ -2008,6 +2008,7 @@ static struct btd_profile a2dp_source_profile = {
 	.name		= "a2dp-source",
 	.priority	= BTD_PROFILE_PRIORITY_MEDIUM,
 
+	.local_uuid	= A2DP_SINK_UUID,
 	.remote_uuid	= A2DP_SOURCE_UUID,
 	.device_probe	= a2dp_source_probe,
 	.device_remove	= a2dp_source_remove,
@@ -2024,6 +2025,7 @@ static struct btd_profile a2dp_sink_profile = {
 	.name		= "a2dp-sink",
 	.priority	= BTD_PROFILE_PRIORITY_MEDIUM,
 
+	.local_uuid	= A2DP_SOURCE_UUID,
 	.remote_uuid	= A2DP_SINK_UUID,
 	.device_probe	= a2dp_sink_probe,
 	.device_remove	= a2dp_sink_remove,
Signature · 1 line
1.8.3.1
author maintainer
#3 lore raw

RFC 3/3 input: Fix setting .local_uuid

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

By setting .local_uuid it makes the core do a scrict check on uuids enabled for the adapter but HID host does not have a record so it does not require a .local_uuid to be set.

---
 profiles/input/manager.c | 1 -
 1 file changed, 1 deletion(-)
profiles/input/manager.c +0 -1
index 689ccdd..b12b43e 100644
@@ -57,7 +57,6 @@ static void hid_server_remove(struct btd_profile *p,
 
 static struct btd_profile input_profile = {
 	.name		= "input-hid",
-	.local_uuid	= HID_UUID,
 	.remote_uuid	= HID_UUID,
 
 	.auto_connect	= true,
Signature · 1 line
1.8.3.1