* [RFC BlueZ 1/3] core/device: Only connect profiles which are enabled
2013-11-13 8:53 [RFC BlueZ 0/3] Check if profile local_uuid is enabled Luiz Augusto von Dentz
@ 2013-11-13 8:53 ` Luiz Augusto von Dentz
2013-11-13 8:53 ` [RFC BlueZ 2/3] audio/A2DP: Set profile .local_uuid properly Luiz Augusto von Dentz
2013-11-13 8:53 ` [RFC BlueZ 3/3] input: Fix setting .local_uuid Luiz Augusto von Dentz
2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2013-11-13 8:53 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
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(-)
diff --git a/src/device.c b/src/device.c
index 9ca457e..60efd62 100644
--- a/src/device.c
+++ b/src/device.c
@@ -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);
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [RFC BlueZ 2/3] audio/A2DP: Set profile .local_uuid properly
2013-11-13 8:53 [RFC BlueZ 0/3] Check if profile local_uuid is enabled Luiz Augusto von Dentz
2013-11-13 8:53 ` [RFC BlueZ 1/3] core/device: Only connect profiles which are enabled Luiz Augusto von Dentz
@ 2013-11-13 8:53 ` Luiz Augusto von Dentz
2013-11-13 8:53 ` [RFC BlueZ 3/3] input: Fix setting .local_uuid Luiz Augusto von Dentz
2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2013-11-13 8:53 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
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(+)
diff --git a/profiles/audio/a2dp.c b/profiles/audio/a2dp.c
index 6b3d6b2..0a347e5 100644
--- a/profiles/audio/a2dp.c
+++ b/profiles/audio/a2dp.c
@@ -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,
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread