From: Andrei Emeltchenko <Andrei.Emeltchenko.news@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH 1/3] android/socket: Refactor connect to allow directly connect to rfcomm
Date: Wed, 18 Dec 2013 16:18:54 +0200 [thread overview]
Message-ID: <1387376336-17092-2-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>
Since Socket HAL allows us to specify RFCOMM channel number and directly
connect refactor send function to allow connect directly is uuid is zero
and channel number is specified.
---
android/socket.c | 71 +++++++++++++++++++++++++++++++-------------------------
1 file changed, 39 insertions(+), 32 deletions(-)
diff --git a/android/socket.c b/android/socket.c
index cee4b6e..656222e 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -838,13 +838,47 @@ fail:
cleanup_rfsock(rfsock);
}
-static void sdp_search_cb(sdp_list_t *recs, int err, gpointer data)
+static bool do_connect(struct rfcomm_sock *rfsock, int chan)
{
- struct rfcomm_sock *rfsock = data;
BtIOSecLevel sec_level = BT_IO_SEC_MEDIUM;
+ GIOChannel *io;
GError *gerr = NULL;
+
+ if (rfsock->profile)
+ sec_level = rfsock->profile->sec_level;
+
+ io = bt_io_connect(connect_cb, rfsock, NULL, &gerr,
+ BT_IO_OPT_SOURCE_BDADDR, &adapter_addr,
+ BT_IO_OPT_DEST_BDADDR, &rfsock->dst,
+ BT_IO_OPT_CHANNEL, chan,
+ BT_IO_OPT_SEC_LEVEL, sec_level,
+ BT_IO_OPT_INVALID);
+ if (!io) {
+ error("Failed connect: %s", gerr->message);
+ g_error_free(gerr);
+ return false;
+ }
+
+ g_io_channel_set_close_on_unref(io, FALSE);
+ g_io_channel_unref(io);
+
+ if (write(rfsock->fd, &chan, sizeof(chan)) != sizeof(chan)) {
+ error("Error sending RFCOMM channel");
+ return false;
+ }
+
+ rfsock->real_sock = g_io_channel_unix_get_fd(io);
+ rfsock_set_buffer(rfsock);
+ rfsock->channel = chan;
+ connections = g_list_append(connections, rfsock);
+
+ return true;
+}
+
+static void sdp_search_cb(sdp_list_t *recs, int err, gpointer data)
+{
+ struct rfcomm_sock *rfsock = data;
sdp_list_t *list;
- GIOChannel *io;
int chan;
DBG("");
@@ -885,36 +919,9 @@ static void sdp_search_cb(sdp_list_t *recs, int err, gpointer data)
DBG("Got RFCOMM channel %d", chan);
- if (rfsock->profile)
- sec_level = rfsock->profile->sec_level;
-
- io = bt_io_connect(connect_cb, rfsock, NULL, &gerr,
- BT_IO_OPT_SOURCE_BDADDR, &adapter_addr,
- BT_IO_OPT_DEST_BDADDR, &rfsock->dst,
- BT_IO_OPT_CHANNEL, chan,
- BT_IO_OPT_SEC_LEVEL, sec_level,
- BT_IO_OPT_INVALID);
- if (!io) {
- error("Failed connect: %s", gerr->message);
- g_error_free(gerr);
- goto fail;
- }
-
- if (write(rfsock->fd, &chan, sizeof(chan)) != sizeof(chan)) {
- error("Error sending RFCOMM channel");
- goto fail;
- }
-
- rfsock->real_sock = g_io_channel_unix_get_fd(io);
- rfsock_set_buffer(rfsock);
- rfsock->channel = chan;
- connections = g_list_append(connections, rfsock);
-
- g_io_channel_unref(io);
-
- return;
+ if (do_connect(rfsock, chan))
+ return;
fail:
- connections = g_list_remove(connections, rfsock);
cleanup_rfsock(rfsock);
}
--
1.8.3.2
next prev 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 ` Andrei Emeltchenko [this message]
2013-12-18 14:18 ` [PATCH 2/3] android/socket: Connect directly to RFCOMM chan is uuid is zero Andrei Emeltchenko
2013-12-19 8:09 ` 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-2-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).