Skip to contentSkip to conversation

avdtp: Add a flag in struct avdtp to control a2dp offload

PATCH In review Kiran K 3 participants 9 messages Nov 15, 2021 – Nov 19, 2021

Subsystems (2)
lore
Share & tools
lore

Kiran K

author
#0 lore raw

PATCH 1/5 avdtp: Add a flag in struct avdtp to control a2dp offload

Define a flag in struct avdtp and set it based on
the definition of env variable USE_OFFLOAD

---
 profiles/audio/avdtp.c | 8 ++++++++
 1 file changed, 8 insertions(+)
profiles/audio/avdtp.c +8 -0
index d3dfbf96dda3..b6feac0ba4d5 100644
@@ -409,6 +409,9 @@ struct avdtp {
 
 	/* Attempt stream setup instead of disconnecting */
 	gboolean stream_setup;
+
+	/* use offload for transport */
+	gboolean use_offload;
 };
 
 static GSList *state_callbacks = NULL;
@@ -2425,6 +2428,7 @@ struct avdtp *avdtp_new(GIOChannel *chan, struct btd_device *device,
 							struct queue *lseps)
 {
 	struct avdtp *session;
+	char *use_offload;
 
 	session = g_new0(struct avdtp, 1);
 
@@ -2436,6 +2440,10 @@ struct avdtp *avdtp_new(GIOChannel *chan, struct btd_device *device,
 
 	session->version = get_version(session);
 
+	use_offload = getenv("USE_OFFLOAD");
+	if (use_offload && !strncmp(use_offload, "1", 1))
+		session->use_offload = TRUE;
+
 	if (!chan)
 		return session;
 
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 2/5 avdtp: Add support for offload msft open command

In a2dp offload use case, controller needs to be sent MSFT avdtp command after opening media transport channel

---
 lib/bluetooth.h        |  3 +++
 profiles/audio/avdtp.c | 48 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)
lib/bluetooth.h +3 -0
index 0fcf412c6c6b..59ef178a563a 100644
@@ -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 */
profiles/audio/avdtp.c +48 -0

60 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#2 lore raw

PATCH 3/5 avdtp: Add support for offload msft start command

In reply to Kiran K

Send MSFT avdtp start command to trigger a2dp offload streaming after sending remote AVDTP start command.

---
 lib/bluetooth.h        |  1 +
 profiles/audio/avdtp.c | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+)
lib/bluetooth.h +1 -0
index 59ef178a563a..32a3b5f0c2b9 100644
@@ -159,6 +159,7 @@ struct bt_codecs {
 } __attribute__((packed));
 
 #define BT_MSFT_OPEN	20
+#define BT_MSFT_START	21
 #define BT_MSFT_CLOSE	23
 
 /* Connection and socket states */
profiles/audio/avdtp.c +18 -0
index 1cd4b4472b08..1ae96e3e8a07 100644
@@ -2910,6 +2910,21 @@ static gboolean avdtp_open_resp(struct avdtp *session, struct avdtp_stream *stre
 	return TRUE;
 }
 
+static gboolean avdtp_offload_start(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_START, 0, 0))
+		return FALSE;
+
+	return TRUE;
+}
+
 static gboolean avdtp_start_resp(struct avdtp *session,
 					struct avdtp_stream *stream,
 					struct seid_rej *resp, int size)
@@ -2924,6 +2939,9 @@ static gboolean avdtp_start_resp(struct avdtp *session,
 	if (sep->state != AVDTP_STATE_STREAMING)
 		avdtp_sep_set_state(session, sep, AVDTP_STATE_STREAMING);
 
+	if (session->use_offload)
+		avdtp_offload_start(stream);
+
 	return TRUE;
 }
 
Signature · 1 line
2.17.1
author
#3 lore raw

PATCH 4/5 avdtp: Add support for offload msft suspend command

In reply to Kiran K

In a2dp offload use case, send MSFT avdtp suspend command followed by remote AVDTP suspend command.

---
 lib/bluetooth.h        |  1 +
 profiles/audio/avdtp.c | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+)
lib/bluetooth.h +1 -0
index 32a3b5f0c2b9..2bd253aeeed4 100644
@@ -160,6 +160,7 @@ struct bt_codecs {
 
 #define BT_MSFT_OPEN	20
 #define BT_MSFT_START	21
+#define BT_MSFT_SUSPEND 22
 #define BT_MSFT_CLOSE	23
 
 /* Connection and socket states */
profiles/audio/avdtp.c +18 -0
index 1ae96e3e8a07..d5e8c7856be3 100644
@@ -2958,6 +2958,21 @@ static gboolean avdtp_close_resp(struct avdtp *session,
 	return TRUE;
 }
 
+static gboolean avdtp_offload_suspend(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_SUSPEND, 0, 0))
+		return FALSE;
+
+	return TRUE;
+}
+
 static gboolean avdtp_suspend_resp(struct avdtp *session,
 					struct avdtp_stream *stream,
 					void *data, int size)
@@ -2969,6 +2984,9 @@ static gboolean avdtp_suspend_resp(struct avdtp *session,
 	if (sep->cfm && sep->cfm->suspend)
 		sep->cfm->suspend(session, sep, stream, NULL, sep->user_data);
 
+	if (session->use_offload)
+		avdtp_offload_suspend(stream);
+
 	return TRUE;
 }
 
Signature · 1 line
2.17.1
author
#4 lore raw

PATCH 5/5 avdtp: Add support for offload msft close command

In reply to Kiran K

In a2dp offload use case, send MSFT avdtp close
command followed by remote AVDTP close command.

---
 profiles/audio/avdtp.c | 3 +++
 1 file changed, 3 insertions(+)
profiles/audio/avdtp.c +3 -0
index d5e8c7856be3..3ee5f30967f0 100644
@@ -2953,6 +2953,9 @@ static gboolean avdtp_close_resp(struct avdtp *session,
 
 	avdtp_sep_set_state(session, sep, AVDTP_STATE_CLOSING);
 
+	if (session->use_offload)
+		avdtp_offload_close(stream);
+
 	close_stream(stream);
 
 	return TRUE;
Signature · 1 line
2.17.1
#5 lore raw
In reply to Kiran K

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=580019

---Test result---

Test Summary:

CheckPatch                    PASS      7.21 seconds
GitLint                       PASS      4.81 seconds
Prep - Setup ELL              PASS      42.19 seconds
Build - Prep                  PASS      0.53 seconds
Build - Configure             PASS      7.91 seconds
Build - Make                  FAIL      138.55 seconds
Make Check                    FAIL      1.60 seconds
Make Distcheck                PASS      214.63 seconds
Build w/ext ELL - Configure   PASS      8.04 seconds
Build w/ext ELL - Make        FAIL      128.87 seconds

Details
##############################
Test: Build - Make - FAIL
Desc: Build the BlueZ source tree
Output:
profiles/audio/avdtp.c: In function ‘avdtp_connect_cb’:
profiles/audio/avdtp.c:2374:6: error: ‘cap’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

 2374 |  if (setsockopt(sock, SOL_BLUETOOTH, BT_MSFT_OPEN, cap,
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2375 |          sizeof(*cap) + cap->length))
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~

profiles/audio/avdtp.c:2358:35: note: ‘cap’ was declared here
2358 | struct avdtp_service_capability *cap;
| ^~~
cc1: all warnings being treated as errors
make[1]: *** [Makefile:8640: profiles/audio/bluetoothd-avdtp.o] Error 1
make: *** [Makefile:4175: all] Error 2

##############################
Test: Make Check - FAIL
Desc: Run 'make check'
Output:
profiles/audio/avdtp.c: In function ‘avdtp_connect_cb’:
profiles/audio/avdtp.c:2374:6: error: ‘cap’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

 2374 |  if (setsockopt(sock, SOL_BLUETOOTH, BT_MSFT_OPEN, cap,
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2375 |          sizeof(*cap) + cap->length))
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~

profiles/audio/avdtp.c:2358:35: note: ‘cap’ was declared here
2358 | struct avdtp_service_capability *cap;
| ^~~
cc1: all warnings being treated as errors
make[1]: *** [Makefile:8640: profiles/audio/bluetoothd-avdtp.o] Error 1
make: *** [Makefile:10501: check] Error 2

##############################
Test: Build w/ext ELL - Make - FAIL
Desc: Build BlueZ source with '--enable-external-ell' configuration
Output:
profiles/audio/avdtp.c: In function ‘avdtp_connect_cb’:
profiles/audio/avdtp.c:2374:6: error: ‘cap’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

 2374 |  if (setsockopt(sock, SOL_BLUETOOTH, BT_MSFT_OPEN, cap,
      |      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 2375 |          sizeof(*cap) + cap->length))
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~

profiles/audio/avdtp.c:2358:35: note: ‘cap’ was declared here
2358 | struct avdtp_service_capability *cap;
| ^~~
cc1: all warnings being treated as errors
make[1]: *** [Makefile:8640: profiles/audio/bluetoothd-avdtp.o] Error 1
make: *** [Makefile:4175: all] Error 2

---
Regards,
Linux Bluetooth

#6 lore raw
In reply to Kiran K

Hi Kiran,

Quoted 30 lines · Kiran K

Define a flag in struct avdtp and set it based on
the definition of env variable USE_OFFLOAD

---
 profiles/audio/avdtp.c | 8 ++++++++
 1 file changed, 8 insertions(+)
profiles/audio/avdtp.c +4 -0
index d3dfbf96dda3..b6feac0ba4d5 100644
@@ -409,6 +409,9 @@ struct avdtp {
 
        /* Attempt stream setup instead of disconnecting */
        gboolean stream_setup;
+
+       /* use offload for transport */
+       gboolean use_offload;
 };
 
 static GSList *state_callbacks = NULL;
@@ -2425,6 +2428,7 @@ struct avdtp *avdtp_new(GIOChannel *chan, struct btd_device *device,
                                                        struct queue *lseps)
 {
        struct avdtp *session;
+       char *use_offload;
 
        session = g_new0(struct avdtp, 1);
 

profiles/audio/avdtp.c struct avdtp *avdtp_new(GIOChannel *chan, struct btd_device *device, · line 2446

Quoted 7 lines
profiles/audio/avdtp.c +4 -0
@@ -2436,6 +2440,10 @@ struct avdtp *avdtp_new(GIOChannel *chan, struct btd_device *device,
 
        session->version = get_version(session);
 
+       use_offload = getenv("USE_OFFLOAD");
+       if (use_offload && !strncmp(use_offload, "1", 1))
+               session->use_offload = TRUE;
+

We already have a configuration for experimental flags:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/main.conf#n118

So you just have to check if experimental is enabled, or the offload UUID, in adapter.c, also perhaps we should have something like btd_adapter_experimental_is_enabled(adapter, uuid) so it would take care of doing all the checking if that had been enabled in the kernel or not.

Quoted 6 lines
profiles/audio/avdtp.c +0 -1
        if (!chan)
                return session;
 
--

2.17.1

Signature · 1 line
Luiz Augusto von Dentz
#7 lore raw

Hi Kiran,

Quoted 37 lines · Luiz Augusto von Dentz

Hi Kiran,

Quoted 33 lines · Kiran K

Define a flag in struct avdtp and set it based on
the definition of env variable USE_OFFLOAD

---
 profiles/audio/avdtp.c | 8 ++++++++
 1 file changed, 8 insertions(+)
profiles/audio/avdtp.c +4 -0
index d3dfbf96dda3..b6feac0ba4d5 100644
@@ -409,6 +409,9 @@ struct avdtp {
 
        /* Attempt stream setup instead of disconnecting */
        gboolean stream_setup;
+
+       /* use offload for transport */
+       gboolean use_offload;
 };
 
 static GSList *state_callbacks = NULL;
@@ -2425,6 +2428,7 @@ struct avdtp *avdtp_new(GIOChannel *chan, struct btd_device *device,
                                                        struct queue *lseps)
 {
        struct avdtp *session;
+       char *use_offload;
 
        session = g_new0(struct avdtp, 1);
 
@@ -2436,6 +2440,10 @@ struct avdtp *avdtp_new(GIOChannel *chan, struct btd_device *device,
 
        session->version = get_version(session);
 
Quoted 8 lines

profiles/audio/avdtp.c struct avdtp *avdtp_new(GIOChannel *chan, struct btd_device *device, · line 2446

Quoted 4 lines
profiles/audio/avdtp.c +4 -0
+       use_offload = getenv("USE_OFFLOAD");
+       if (use_offload && !strncmp(use_offload, "1", 1))
+               session->use_offload = TRUE;
+

We already have a configuration for experimental flags:

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/main.conf#n118

Correction, we may need to introduce yet another experimental UUID given the UUID above is just about codec offload not MSFT A2DP offload which may require a completely different set of commands.

Quoted 16 lines

So you just have to check if experimental is enabled, or the offload UUID, in adapter.c, also perhaps we should have something like btd_adapter_experimental_is_enabled(adapter, uuid) so it would take care of doing all the checking if that had been enabled in the kernel or not.

Quoted 6 lines
profiles/audio/avdtp.c +0 -1
        if (!chan)
                return session;
 
--

2.17.1

--
Luiz Augusto von Dentz

Signature · 1 line
Luiz Augusto von Dentz
author
#8 lore raw

Hi Luiz,

Quoted 60 lines

-----Original Message-----
From: Luiz Augusto von Dentz <[email protected]>
Sent: Tuesday, November 16, 2021 1:15 AM
To: K, Kiran <[email protected]>
Cc: [email protected]; Srivatsa, Ravishankar <[email protected]>; Tumkur Narayan, Chethan <[email protected]>; Von Dentz, Luiz <[email protected]>
Subject: Re: [PATCH v1 1/5] avdtp: Add a flag in struct avdtp to control a2dp offload

Hi Kiran,

Quoted 45 lines · Luiz Augusto von Dentz

Hi Kiran,

Quoted 30 lines · Kiran K

Define a flag in struct avdtp and set it based on the definition of env variable USE_OFFLOAD

---
 profiles/audio/avdtp.c | 8 ++++++++
 1 file changed, 8 insertions(+)
profiles/audio/avdtp.c index renamed from profiles/audio/avdtp.c +0 -0

d3dfbf96dda3..b6feac0ba4d5 100644

profiles/audio/avdtp.c +3 -0
@@ -409,6 +409,9 @@ struct avdtp {
 
        /* Attempt stream setup instead of disconnecting */
        gboolean stream_setup;
+
+       /* use offload for transport */
+       gboolean use_offload;
 };
 
 static GSList *state_callbacks = NULL; @@ -2425,6 +2428,7 @@ struct

avdtp *avdtp_new(GIOChannel *chan, struct btd_device *device,
struct queue

*lseps)  {
        struct avdtp *session;
profiles/audio/avdtp.c +1 -0
+       char *use_offload;
 
        session = g_new0(struct avdtp, 1);

profiles/audio/avdtp.c struct avdtp *avdtp_new(GIOChannel *chan, · line 2447

Quoted 8 lines
profiles/audio/avdtp.c +4 -0
@@ -2436,6 +2440,10 @@ struct avdtp *avdtp_new(GIOChannel *chan,
 struct btd_device *device,
 
        session->version = get_version(session);
 
+       use_offload = getenv("USE_OFFLOAD");
+       if (use_offload && !strncmp(use_offload, "1", 1))
+               session->use_offload = TRUE;
+

We already have a configuration for experimental flags:

Quoted 7 lines
Quoted 2 lines

https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/src/main.conf#
n118

Correction, we may need to introduce yet another experimental UUID given the UUID above is just about codec offload not MSFT A2DP offload which may require a completely different set of commands.

Ok. I will introduce a new UUID for a2dp offload codecs.

Quoted 14 lines
Quoted 14 lines

So you just have to check if experimental is enabled, or the offload UUID, in adapter.c, also perhaps we should have something like btd_adapter_experimental_is_enabled(adapter, uuid) so it would take care of doing all the checking if that had been enabled in the kernel or not.

Quoted 6 lines
profiles/audio/avdtp.c +0 -1
        if (!chan)
                return session;
 
--

2.17.1

Quoted 7 lines
Quoted 2 lines

--
Luiz Augusto von Dentz

--
Luiz Augusto von Dentz

Thanks,
Kiran