summaryrefslogtreecommitdiff
path: root/android/a2dp.c
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2014-01-14 13:24:47 +0200
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2014-01-15 14:52:44 +0200
commitc6fed41a02d30732e6a0797185ae7397d565b954 (patch)
tree2255afcb11b4604b30388c3237da00322159df57 /android/a2dp.c
parentfa8aa7b269f4eb1a581e8beb9d069d4ea4e079a0 (diff)
downloadbluez-c6fed41a02d30732e6a0797185ae7397d565b954.tar.gz
android/A2DP: Add handling of incoming transport connection
This adds handling of incoming transport connection attempt.
Diffstat (limited to 'android/a2dp.c')
-rw-r--r--android/a2dp.c64
1 files changed, 60 insertions, 4 deletions
diff --git a/android/a2dp.c b/android/a2dp.c
index 27360d3bd..d89c828d8 100644
--- a/android/a2dp.c
+++ b/android/a2dp.c
@@ -477,6 +477,60 @@ static const struct ipc_handler cmd_handlers[] = {
{ bt_a2dp_disconnect, false, sizeof(struct hal_cmd_a2dp_disconnect) },
};
+static struct a2dp_setup *find_setup_by_device(struct a2dp_device *dev)
+{
+ GSList *l;
+
+ for (l = setups; l; l = g_slist_next(l)) {
+ struct a2dp_setup *setup = l->data;
+
+ if (setup->dev == dev)
+ return setup;
+ }
+
+ return NULL;
+}
+
+static void transport_connect_cb(GIOChannel *chan, GError *err,
+ gpointer user_data)
+{
+ struct a2dp_device *dev = user_data;
+ struct a2dp_setup *setup;
+ uint16_t imtu, omtu;
+ GError *gerr = NULL;
+ int fd;
+
+ if (err) {
+ error("%s", err->message);
+ return;
+ }
+
+ setup = find_setup_by_device(dev);
+ if (!setup) {
+ error("Unable to find stream setup");
+ return;
+ }
+
+ bt_io_get(chan, &gerr,
+ BT_IO_OPT_IMTU, &imtu,
+ BT_IO_OPT_OMTU, &omtu,
+ BT_IO_OPT_INVALID);
+ if (gerr) {
+ error("%s", gerr->message);
+ g_error_free(gerr);
+ return;
+ }
+
+ fd = g_io_channel_unix_get_fd(chan);
+
+ if (!avdtp_stream_set_transport(setup->stream, fd, imtu, omtu)) {
+ error("avdtp_stream_set_transport: failed");
+ return;
+ }
+
+ g_io_channel_set_close_on_unref(chan, FALSE);
+}
+
static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
{
struct a2dp_device *dev;
@@ -501,13 +555,15 @@ static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
return;
}
- l = g_slist_find_custom(devices, &dst, device_cmp);
- if (l)
- return;
-
ba2str(&dst, address);
DBG("Incoming connection from %s", address);
+ l = g_slist_find_custom(devices, &dst, device_cmp);
+ if (l) {
+ transport_connect_cb(chan, err, l->data);
+ return;
+ }
+
dev = a2dp_device_new(&dst);
signaling_connect_cb(chan, err, dev);
}