linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 6/7] android/a2dp: Add initial implementation of HAL_OP_A2DP_CONNECT
Date: Thu, 14 Nov 2013 12:18:20 +0200	[thread overview]
Message-ID: <1384424301-31265-6-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1384424301-31265-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 android/a2dp.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 71 insertions(+), 18 deletions(-)

diff --git a/android/a2dp.c b/android/a2dp.c
index 5ffb8ae..adbad05 100644
--- a/android/a2dp.c
+++ b/android/a2dp.c
@@ -45,6 +45,7 @@
 static int notification_sk = -1;
 static GIOChannel *io = NULL;
 static GSList *devices = NULL;
+static const bdaddr_t *adapter_addr = NULL;
 
 struct a2dp_device {
 	bdaddr_t	dst;
@@ -104,11 +105,74 @@ static void bt_a2dp_notify_state(struct a2dp_device *dev, uint8_t state)
 			HAL_EV_A2DP_CONN_STATE, sizeof(ev), &ev, -1);
 }
 
+static gboolean watch_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
+{
+	struct a2dp_device *dev = data;
+
+	bt_a2dp_notify_state(dev, HAL_A2DP_STATE_DISCONNECTED);
+
+	a2dp_device_free(dev);
+
+	return FALSE;
+}
+
+static void signaling_connect_cb(GIOChannel *chan, GError *err,
+							gpointer user_data)
+{
+	struct a2dp_device *dev = user_data;
+
+	if (err) {
+		bt_a2dp_notify_state(dev, HAL_A2DP_STATE_DISCONNECTED);
+		error("%s", err->message);
+		a2dp_device_free(dev);
+		return;
+	}
+
+	dev->watch = g_io_add_watch(dev->io, G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+								watch_cb, dev);
+
+	bt_a2dp_notify_state(dev, HAL_A2DP_STATE_CONNECTED);
+}
+
 static uint8_t bt_a2dp_connect(struct hal_cmd_a2dp_connect *cmd, uint16_t len)
 {
-	DBG("Not Implemented");
+	struct a2dp_device *dev;
+	char addr[18];
+	bdaddr_t dst;
+	GSList *l;
+	GError *err = NULL;
 
-	return HAL_STATUS_FAILED;
+	DBG("");
+
+	if (len < sizeof(*cmd))
+		return HAL_STATUS_INVALID;
+
+	android2bdaddr(&cmd->bdaddr, &dst);
+
+	l = g_slist_find_custom(devices, &dst, device_cmp);
+	if (l)
+		return HAL_STATUS_FAILED;
+
+	dev = a2dp_device_new(&dst);
+	dev->io = bt_io_connect(signaling_connect_cb, dev, NULL, &err,
+					BT_IO_OPT_SOURCE_BDADDR, adapter_addr,
+					BT_IO_OPT_DEST_BDADDR, &dev->dst,
+					BT_IO_OPT_PSM, L2CAP_PSM_AVDTP,
+					BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
+					BT_IO_OPT_INVALID);
+	if (err) {
+		error("%s", err->message);
+		g_error_free(err);
+		a2dp_device_free(dev);
+		return HAL_STATUS_FAILED;
+	}
+
+	ba2str(&dev->dst, addr);
+	DBG("connecting to %s", addr);
+
+	bt_a2dp_notify_state(dev, HAL_A2DP_STATE_CONNECTING);
+
+	return HAL_STATUS_SUCCESS;
 }
 
 static uint8_t bt_a2dp_disconnect(struct hal_cmd_a2dp_connect *cmd,
@@ -138,17 +202,6 @@ void bt_a2dp_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)
 	ipc_send_rsp(sk, HAL_SERVICE_ID_A2DP, status);
 }
 
-static gboolean watch_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
-{
-	struct a2dp_device *dev = data;
-
-	bt_a2dp_notify_state(dev, HAL_A2DP_STATE_DISCONNECTED);
-
-	a2dp_device_free(dev);
-
-	return FALSE;
-}
-
 static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
 {
 	struct a2dp_device *dev;
@@ -181,10 +234,7 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
 	DBG("Incoming connection from %s", address);
 
 	dev = a2dp_device_new(&dst);
-	dev->watch = g_io_add_watch(dev->io, G_IO_HUP | G_IO_ERR | G_IO_NVAL,
-								watch_cb, dev);
-
-	bt_a2dp_notify_state(dev, HAL_A2DP_STATE_CONNECTED);
+	signaling_connect_cb(chan, err, dev);
 }
 
 bool bt_a2dp_register(int sk, const bdaddr_t *addr)
@@ -193,8 +243,10 @@ bool bt_a2dp_register(int sk, const bdaddr_t *addr)
 
 	DBG("");
 
+	adapter_addr = addr;
+
 	io = bt_io_listen(connect_cb, NULL, NULL, NULL, &err,
-				BT_IO_OPT_SOURCE_BDADDR, addr,
+				BT_IO_OPT_SOURCE_BDADDR, adapter_addr,
 				BT_IO_OPT_PSM, L2CAP_PSM_AVDTP,
 				BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM,
 				BT_IO_OPT_INVALID);
@@ -213,6 +265,7 @@ void bt_a2dp_unregister(void)
 {
 	DBG("");
 
+	adapter_addr = NULL;
 	notification_sk = -1;
 
 	if (io) {
-- 
1.8.3.1


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

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-14 10:18 [PATCH BlueZ 1/7] android/hal-a2dp: Use conn_state instead of connection_state Luiz Augusto von Dentz
2013-11-14 10:18 ` [PATCH BlueZ 2/7] android/hal-a2dp: Add implemention of .init Luiz Augusto von Dentz
2013-11-14 10:18 ` [PATCH BlueZ 3/7] android/hal-a2dp: Add implemention of .cleanup Luiz Augusto von Dentz
2013-11-14 10:18 ` [PATCH BlueZ 4/7] android/hal-a2dp: Add defines for possible connection states Luiz Augusto von Dentz
2013-11-14 10:18 ` [PATCH BlueZ 5/7] android/a2dp: Add initial implementation of socket handling Luiz Augusto von Dentz
2013-11-14 10:18 ` Luiz Augusto von Dentz [this message]
2013-11-14 10:18 ` [PATCH BlueZ 7/7] android/a2dp: Add initial implementation of HAL_OP_A2DP_DISCONNECT Luiz Augusto von Dentz
2013-11-14 12:26 ` [PATCH BlueZ 1/7] android/hal-a2dp: Use conn_state instead of connection_state 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=1384424301-31265-6-git-send-email-luiz.dentz@gmail.com \
    --to=luiz.dentz@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).