@@ -158,6 +158,9 @@ struct bt_codecs {
struct bt_codec codecs[];
} __attribute__((packed));
+#define BT_MSFT_OPEN 20
+#define BT_MSFT_CLOSE 23
+
/* Connection and socket states */
enum {
BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */
@@ -2352,6 +2352,47 @@ static uint16_t get_version(struct avdtp *session)
return ver;
}
+static gboolean avdtp_offload_open(struct avdtp_stream *stream)
+{
+ int sock;
+ struct avdtp_service_capability *cap;
+ GSList *l;
+
+ if (!stream->io)
+ return FALSE;
+
+ sock = g_io_channel_unix_get_fd(stream->io);
+
+ for (l = stream->caps; l ; l = g_slist_next(l)) {
+ cap = l->data;
+
+ if (cap->category != AVDTP_MEDIA_CODEC)
+ continue;
+ break;
+ }
+
+ if (setsockopt(sock, SOL_BLUETOOTH, BT_MSFT_OPEN, cap,
+ sizeof(*cap) + cap->length))
+ return FALSE;
+
+ return TRUE;
+}
+
+static gboolean avdtp_offload_close(struct avdtp_stream *stream)
+{
+ int sock;
+
+ if (!stream->io)
+ return FALSE;
+
+ sock = g_io_channel_unix_get_fd(stream->io);
+
+ if (setsockopt(sock, SOL_BLUETOOTH, BT_MSFT_CLOSE, 0, 0))
+ return FALSE;
+
+ return TRUE;
+}
+
static void avdtp_connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
{
struct avdtp *session = user_data;
@@ -2385,6 +2426,13 @@ static void avdtp_connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
session->pending_open ? "transport" : "signaling",
address);
+ if (session->pending_open && session->use_offload) {
+ if (!avdtp_offload_open(session->pending_open)) {
+ avdtp_offload_close(session->pending_open);
+ goto failed;
+ }
+ }
+
if (session->state == AVDTP_SESSION_STATE_CONNECTING) {
DBG("AVDTP imtu=%u, omtu=%u", session->imtu, session->omtu);