linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrei Emeltchenko <Andrei.Emeltchenko.news@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH 2/3] android/socket: Connect directly to RFCOMM chan is uuid is zero
Date: Wed, 18 Dec 2013 16:18:55 +0200	[thread overview]
Message-ID: <1387376336-17092-3-git-send-email-Andrei.Emeltchenko.news@gmail.com> (raw)
In-Reply-To: <1387376336-17092-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

Check uuid and connect to specified channel number directly.
---
 android/socket.c | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/android/socket.c b/android/socket.c
index 656222e..7bc5b0b 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -925,10 +925,17 @@ fail:
 	cleanup_rfsock(rfsock);
 }
 
+static bool is_empty(const uint8_t *uuid)
+{
+	static uint8_t zero_uuid[16];
+
+	return memcmp(uuid, zero_uuid, sizeof(zero_uuid)) == 0;
+}
+
 static void handle_connect(const void *buf, uint16_t len)
 {
 	const struct hal_cmd_sock_connect *cmd = buf;
-	struct rfcomm_sock *rfsock;
+	struct rfcomm_sock *rfsock = NULL;
 	uuid_t uuid;
 	int hal_fd = -1;
 
@@ -940,17 +947,21 @@ static void handle_connect(const void *buf, uint16_t len)
 
 	android2bdaddr(cmd->bdaddr, &rfsock->dst);
 
-	memset(&uuid, 0, sizeof(uuid));
-	uuid.type = SDP_UUID128;
-	memcpy(&uuid.value.uuid128, cmd->uuid, sizeof(uint128_t));
+	if (is_empty(cmd->uuid)) {
+		if (!do_connect(rfsock, cmd->channel))
+			goto failed;
+	} else {
+		memset(&uuid, 0, sizeof(uuid));
+		uuid.type = SDP_UUID128;
+		memcpy(&uuid.value.uuid128, cmd->uuid, sizeof(uint128_t));
 
-	rfsock->profile = get_profile_by_uuid(cmd->uuid);
+		rfsock->profile = get_profile_by_uuid(cmd->uuid);
 
-	if (bt_search_service(&adapter_addr, &rfsock->dst, &uuid,
+		if (bt_search_service(&adapter_addr, &rfsock->dst, &uuid,
 					sdp_search_cb, rfsock, NULL) < 0) {
-		error("Failed to search SDP records");
-		cleanup_rfsock(rfsock);
-		goto failed;
+			error("Failed to search SDP records");
+			goto failed;
+		}
 	}
 
 	ipc_send_rsp_full(HAL_SERVICE_ID_SOCK, HAL_OP_SOCK_CONNECT, 0, NULL,
@@ -962,6 +973,9 @@ failed:
 	ipc_send_rsp(HAL_SERVICE_ID_SOCK, HAL_OP_SOCK_CONNECT,
 							HAL_STATUS_FAILED);
 
+	if (rfsock)
+		cleanup_rfsock(rfsock);
+
 	if (hal_fd >= 0)
 		close(hal_fd);
 }
-- 
1.8.3.2


  parent reply	other threads:[~2013-12-18 14:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-18 14:18 [PATCH 0/3] Allow directly connect to RFCOMM channel Andrei Emeltchenko
2013-12-18 14:18 ` [PATCH 1/3] android/socket: Refactor connect to allow directly connect to rfcomm Andrei Emeltchenko
2013-12-18 14:18 ` Andrei Emeltchenko [this message]
2013-12-19  8:09   ` [PATCH 2/3] android/socket: Connect directly to RFCOMM chan is uuid is zero Johan Hedberg
2013-12-18 14:18 ` [PATCH 3/3] android/tester: Test that connect call returns channel number Andrei Emeltchenko
2013-12-19  8:49 ` [PATCHv2 1/3] android/socket: Refactor connect to allow directly connect to rfcomm Andrei Emeltchenko
2013-12-19  8:49   ` [PATCHv2 2/3] android/socket: Connect directly to RFCOMM channel if uuid is zero Andrei Emeltchenko
2013-12-19  8:49   ` [PATCHv2 3/3] android/tester: Test that connect call returns channel number Andrei Emeltchenko
2013-12-19  9:08   ` [PATCHv2 1/3] android/socket: Refactor connect to allow directly connect to rfcomm 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=1387376336-17092-3-git-send-email-Andrei.Emeltchenko.news@gmail.com \
    --to=andrei.emeltchenko.news@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /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).