android/A2DP: Add handling of incoming transport connection

This adds handling of incoming transport connection attempt.
This commit is contained in:
Luiz Augusto von Dentz 2014-01-14 13:24:47 +02:00
parent fa8aa7b269
commit c6fed41a02

View File

@ -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);
}