linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mikel Astiz <mikel.astiz.oss@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Mikel Astiz <mikel.astiz@bmw-carit.de>
Subject: [PATCH BlueZ v0 3/6] network: Remove find_connection()
Date: Mon, 27 May 2013 14:04:06 +0200	[thread overview]
Message-ID: <1369656249-27980-4-git-send-email-mikel.astiz.oss@gmail.com> (raw)
In-Reply-To: <1369656249-27980-1-git-send-email-mikel.astiz.oss@gmail.com>

From: Mikel Astiz <mikel.astiz@bmw-carit.de>

The userdata pointer in btd_service provides the necessary information
to find which service should be connected. This makes possible to remove
the restriction of having one single UUID instance per profile.
---
 profiles/network/connection.c | 31 ++++++++++---------------------
 1 file changed, 10 insertions(+), 21 deletions(-)

diff --git a/profiles/network/connection.c b/profiles/network/connection.c
index bac3b69..960a1fe 100644
--- a/profiles/network/connection.c
+++ b/profiles/network/connection.c
@@ -102,18 +102,6 @@ static struct network_peer *find_peer(GSList *list, struct btd_device *device)
 	return NULL;
 }
 
-static struct network_conn *find_connection(GSList *list, uint16_t id)
-{
-	for (; list; list = list->next) {
-		struct network_conn *nc = list->data;
-
-		if (nc->id == id)
-			return nc;
-	}
-
-	return NULL;
-}
-
 static struct network_conn *find_connection_by_state(GSList *list,
 							conn_state state)
 {
@@ -414,8 +402,10 @@ static DBusMessage *local_connect(DBusConnection *conn,
 						DBusMessage *msg, void *data)
 {
 	struct network_peer *peer = data;
+	struct btd_service *service;
 	struct network_conn *nc;
 	const char *svc;
+	const char *uuid;
 	uint16_t id;
 	int err;
 
@@ -424,11 +414,17 @@ static DBusMessage *local_connect(DBusConnection *conn,
 		return btd_error_invalid_args(msg);
 
 	id = bnep_service_id(svc);
+	uuid = bnep_uuid(id);
 
-	nc = find_connection(peer->connections, id);
-	if (nc == NULL)
+	if (uuid == NULL)
 		return btd_error_invalid_args(msg);
 
+	service = btd_device_get_service(peer->device, uuid);
+	if (service == NULL)
+		return btd_error_not_supported(msg);
+
+	nc = btd_service_get_user_data(service);
+
 	if (nc->connect != NULL)
 		return btd_error_busy(msg);
 
@@ -694,13 +690,6 @@ int connection_register(struct btd_service *service)
 		peers = g_slist_append(peers, peer);
 	}
 
-	nc = find_connection(peer->connections, id);
-	if (nc) {
-		error("Device %s has multiple connection instances of %d",
-						device_get_path(device), id);
-		return -1;
-	}
-
 	nc = g_new0(struct network_conn, 1);
 	nc->id = id;
 	memset(nc->dev, 0, sizeof(nc->dev));
-- 
1.8.1.4


  parent reply	other threads:[~2013-05-27 12:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-27 12:04 [PATCH BlueZ v0 0/6] Exploit btd_service's userdata pointer Mikel Astiz
2013-05-27 12:04 ` [PATCH BlueZ v0 1/6] network: Remove duplicated search Mikel Astiz
2013-05-27 12:04 ` [PATCH BlueZ v0 2/6] network: Fix missing NULL check for given UUID Mikel Astiz
2013-05-27 12:04 ` Mikel Astiz [this message]
2013-05-27 12:04 ` [PATCH BlueZ v0 4/6] deviceinfo: Use btd_service userdata pointer Mikel Astiz
2013-05-27 12:04 ` [PATCH BlueZ v0 5/6] scanparam: " Mikel Astiz
2013-05-27 12:04 ` [PATCH BlueZ v0 6/6] input: " Mikel Astiz
2013-06-24  8:19 ` [PATCH BlueZ v0 0/6] Exploit btd_service's " Johan Hedberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1369656249-27980-4-git-send-email-mikel.astiz.oss@gmail.com \
    --to=mikel.astiz.oss@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=mikel.astiz@bmw-carit.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).