public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 0/3] bass: Register broadcast code request callback
@ 2025-02-28 15:56 Iulia Tanasescu
  2025-02-28 15:56 ` [PATCH BlueZ 1/3] shared/bap: Add APIs to register broadcast code callback Iulia Tanasescu
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Iulia Tanasescu @ 2025-02-28 15:56 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: claudia.rosu, mihai-octavian.urzica, andrei.istodorescu,
	luiz.dentz, Iulia Tanasescu

This adds support for BASS to register Broadcast Code request callback
with shared/bap, to be notified by the transport plugin when the
Broadcast Code is needed at transport select. This is done to avoid
direct calls between plugins.

Iulia Tanasescu (3):
  shared/bap: Add APIs to register broadcast code callback
  bass: Register broadcast code request callback
  bass: Remove interface

 Makefile.plugins           |  2 +-
 profiles/audio/bap.c       |  1 -
 profiles/audio/bass.c      | 30 +++++++-----
 profiles/audio/bass.h      | 14 ------
 profiles/audio/transport.c |  5 +-
 src/shared/bap.c           | 98 ++++++++++++++++++++++++++++++++++++++
 src/shared/bap.h           | 17 +++++++
 7 files changed, 137 insertions(+), 30 deletions(-)
 delete mode 100644 profiles/audio/bass.h

-- 
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH BlueZ 1/3] shared/bap: Add APIs to register broadcast code callback
  2025-02-28 15:56 [PATCH BlueZ 0/3] bass: Register broadcast code request callback Iulia Tanasescu
@ 2025-02-28 15:56 ` Iulia Tanasescu
  2025-02-28 17:14   ` bass: Register broadcast code request callback bluez.test.bot
  2025-02-28 15:56 ` [PATCH BlueZ 2/3] " Iulia Tanasescu
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Iulia Tanasescu @ 2025-02-28 15:56 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: claudia.rosu, mihai-octavian.urzica, andrei.istodorescu,
	luiz.dentz, Iulia Tanasescu

This adds support for registering Broadcast Code request callback with
shared/bap, to be called when a BAP Scan Delegator needs to receive the
Code from peer Broadcast Assistants.
---
 src/shared/bap.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/shared/bap.h | 17 +++++++++
 2 files changed, 115 insertions(+)

diff --git a/src/shared/bap.c b/src/shared/bap.c
index aa4b1aa86..8b5010f32 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -88,6 +88,13 @@ struct bt_bap_bis_cb {
 	void *data;
 };
 
+struct bt_bap_bcode_cb {
+	unsigned int id;
+	bt_bap_bcode_func_t func;
+	bt_bap_destroy_func_t destroy;
+	void *data;
+};
+
 struct bt_bap_cb {
 	unsigned int id;
 	bt_bap_func_t attached;
@@ -189,6 +196,7 @@ struct bt_bap {
 	struct queue *ready_cbs;
 	struct queue *state_cbs;
 	struct queue *bis_cbs;
+	struct queue *bcode_cbs;
 
 	bt_bap_debug_func_t debug_func;
 	bt_bap_destroy_func_t debug_destroy;
@@ -4226,6 +4234,16 @@ static void bap_bis_cb_free(void *data)
 	free(bis_cb);
 }
 
+static void bap_bcode_cb_free(void *data)
+{
+	struct bt_bap_bcode_cb *cb = data;
+
+	if (cb->destroy)
+		cb->destroy(cb->data);
+
+	free(cb);
+}
+
 static void bap_ep_free(void *data)
 {
 	struct bt_bap_endpoint *ep = data;
@@ -4265,6 +4283,7 @@ static void bap_free(void *data)
 	queue_destroy(bap->ready_cbs, bap_ready_free);
 	queue_destroy(bap->state_cbs, bap_state_free);
 	queue_destroy(bap->bis_cbs, bap_bis_cb_free);
+	queue_destroy(bap->bcode_cbs, bap_bcode_cb_free);
 	queue_destroy(bap->local_eps, free);
 	queue_destroy(bap->remote_eps, bap_ep_free);
 
@@ -4348,6 +4367,7 @@ struct bt_bap *bt_bap_new(struct gatt_db *ldb, struct gatt_db *rdb)
 	bap->streams = queue_new();
 	bap->state_cbs = queue_new();
 	bap->bis_cbs = queue_new();
+	bap->bcode_cbs = queue_new();
 	bap->local_eps = queue_new();
 
 	if (!rdb)
@@ -7350,3 +7370,81 @@ done:
 
 	return ret;
 }
+
+void bt_bap_req_bcode(struct bt_bap_stream *stream,
+				bt_bap_bcode_reply_t reply,
+				void *reply_data)
+{
+	const struct queue_entry *entry;
+
+	if (!bap_stream_valid(stream))
+		return;
+
+	bt_bap_stream_ref(stream);
+
+	if (!bt_bap_ref_safe(stream->bap))
+		goto done;
+
+	entry = queue_get_entries(stream->bap->bcode_cbs);
+
+	while (entry) {
+		struct bt_bap_bcode_cb *cb = entry->data;
+
+		entry = entry->next;
+
+		if (cb->func)
+			cb->func(stream, reply, reply_data, cb->data);
+	}
+
+	bt_bap_unref(stream->bap);
+
+done:
+	bt_bap_stream_unref(stream);
+}
+
+unsigned int bt_bap_bcode_cb_register(struct bt_bap *bap,
+				bt_bap_bcode_func_t func,
+				void *user_data,
+				bt_bap_destroy_func_t destroy)
+{
+	struct bt_bap_bcode_cb *cb;
+	static unsigned int id;
+
+	if (!bap)
+		return 0;
+
+	cb = new0(struct bt_bap_bcode_cb, 1);
+	cb->id = ++id ? id : ++id;
+	cb->func = func;
+	cb->destroy = destroy;
+	cb->data = user_data;
+
+	queue_push_tail(bap->bcode_cbs, cb);
+
+	return cb->id;
+}
+
+static bool match_bcode_cb_id(const void *data, const void *match_data)
+{
+	const struct bt_bap_bcode_cb *cb = data;
+	unsigned int id = PTR_TO_UINT(match_data);
+
+	return (cb->id == id);
+}
+
+bool bt_bap_bcode_cb_unregister(struct bt_bap *bap, unsigned int id)
+{
+	struct bt_bap_bcode_cb *cb;
+
+	if (!bap)
+		return false;
+
+	cb = queue_remove_if(bap->bcode_cbs, match_bcode_cb_id,
+						UINT_TO_PTR(id));
+	if (!cb)
+		return false;
+
+	bap_bcode_cb_free(cb);
+
+	return false;
+}
diff --git a/src/shared/bap.h b/src/shared/bap.h
index adb531b4c..359147b69 100644
--- a/src/shared/bap.h
+++ b/src/shared/bap.h
@@ -44,6 +44,12 @@ typedef void (*bt_bap_bis_func_t)(uint8_t bis, uint8_t sgrp,
 		struct iovec *caps, struct iovec *meta,
 		struct bt_bap_qos *qos, void *user_data);
 
+typedef void (*bt_bap_bcode_reply_t)(void *user_data, int err);
+
+typedef void (*bt_bap_bcode_func_t)(struct bt_bap_stream *stream,
+				bt_bap_bcode_reply_t reply, void *reply_data,
+				void *user_data);
+
 /* Local PAC related functions */
 struct bt_bap_pac_qos {
 	uint8_t  framing;
@@ -279,3 +285,14 @@ bool bt_bap_bis_cb_unregister(struct bt_bap *bap, unsigned int id);
 void bt_bap_bis_probe(struct bt_bap *bap, uint8_t bis, uint8_t sgrp,
 	struct iovec *caps, struct iovec *meta, struct bt_bap_qos *qos);
 void bt_bap_bis_remove(struct bt_bap *bap);
+
+void bt_bap_req_bcode(struct bt_bap_stream *stream,
+				bt_bap_bcode_reply_t reply,
+				void *reply_data);
+
+unsigned int bt_bap_bcode_cb_register(struct bt_bap *bap,
+				bt_bap_bcode_func_t func,
+				void *user_data,
+				bt_bap_destroy_func_t destroy);
+
+bool bt_bap_bcode_cb_unregister(struct bt_bap *bap, unsigned int id);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH BlueZ 2/3] bass: Register broadcast code request callback
  2025-02-28 15:56 [PATCH BlueZ 0/3] bass: Register broadcast code request callback Iulia Tanasescu
  2025-02-28 15:56 ` [PATCH BlueZ 1/3] shared/bap: Add APIs to register broadcast code callback Iulia Tanasescu
@ 2025-02-28 15:56 ` Iulia Tanasescu
  2025-02-28 15:56 ` [PATCH BlueZ 3/3] bass: Remove interface Iulia Tanasescu
  2025-03-06 15:50 ` [PATCH BlueZ 0/3] bass: Register broadcast code request callback patchwork-bot+bluetooth
  3 siblings, 0 replies; 6+ messages in thread
From: Iulia Tanasescu @ 2025-02-28 15:56 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: claudia.rosu, mihai-octavian.urzica, andrei.istodorescu,
	luiz.dentz, Iulia Tanasescu

This updates BASS to register Broadcast Code request callback with
shared/bap instead of having a public API, to avoid making direct calls
between plugins. The registered handler will be called from the transport
plugin via shared/bap.
---
 profiles/audio/bass.c      | 29 +++++++++++++++++++----------
 profiles/audio/bass.h      |  5 -----
 profiles/audio/transport.c |  4 ++--
 3 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/profiles/audio/bass.c b/profiles/audio/bass.c
index f5fe60652..ec5b88ff3 100644
--- a/profiles/audio/bass.c
+++ b/profiles/audio/bass.c
@@ -108,6 +108,7 @@ struct bass_delegator {
 	struct bt_bcast_src *src;
 	struct bt_bap *bap;
 	unsigned int state_id;
+	unsigned int bcode_id;
 	uint8_t *bcode;
 	unsigned int timeout;
 	struct queue *bcode_reqs;
@@ -128,7 +129,7 @@ struct bass_setup {
 
 struct bass_bcode_req {
 	struct bass_setup *setup;
-	bt_bass_bcode_func_t cb;
+	bt_bap_bcode_reply_t cb;
 	void *user_data;
 };
 
@@ -180,7 +181,7 @@ static bool delegator_match_bap(const void *data, const void *match_data)
 }
 
 static void setup_set_bcode(uint8_t *bcode, struct bass_setup *setup,
-				bt_bass_bcode_func_t cb, void *user_data)
+				bt_bap_bcode_reply_t cb, void *user_data)
 {
 	struct bt_bap_qos *qos = bt_bap_stream_get_qos(setup->stream);
 
@@ -203,9 +204,9 @@ static bool match_setup_stream(const void *data, const void *user_data)
 	return setup->stream == stream;
 }
 
-void bass_req_bcode(struct bt_bap_stream *stream,
-				bt_bass_bcode_func_t cb,
-				void *user_data)
+static void bass_req_bcode(struct bt_bap_stream *stream,
+	bt_bap_bcode_reply_t reply, void *reply_data,
+	void *user_data)
 {
 	struct bt_bap *bap = bt_bap_stream_get_session(stream);
 	struct bass_delegator *dg;
@@ -214,19 +215,19 @@ void bass_req_bcode(struct bt_bap_stream *stream,
 
 	dg = queue_find(delegators, delegator_match_bap, bap);
 	if (!dg) {
-		cb(user_data, -EINVAL);
+		reply(reply_data, -EINVAL);
 		return;
 	}
 
 	setup = queue_find(dg->setups, match_setup_stream, stream);
 	if (!setup) {
-		cb(user_data, -EINVAL);
+		reply(reply_data, -EINVAL);
 		return;
 	}
 
 	if (dg->bcode) {
 		/* Broadcast Code has already been received before. */
-		setup_set_bcode(dg->bcode, setup, cb, user_data);
+		setup_set_bcode(dg->bcode, setup, reply, reply_data);
 		return;
 	}
 
@@ -239,8 +240,8 @@ void bass_req_bcode(struct bt_bap_stream *stream,
 		return;
 
 	req->setup = setup;
-	req->cb = cb;
-	req->user_data = user_data;
+	req->cb = reply;
+	req->user_data = reply_data;
 
 	queue_push_tail(dg->bcode_reqs, req);
 
@@ -564,6 +565,12 @@ static void confirm_cb(GIOChannel *io, void *user_data)
 	dg->state_id = bt_bap_state_register(dg->bap, bap_state_changed,
 			NULL, dg, NULL);
 
+	/* Register callback to handle Broadcast Code requests from
+	 * upper layers.
+	 */
+	dg->bcode_id = bt_bap_bcode_cb_register(dg->bap, bass_req_bcode,
+							NULL, NULL);
+
 	dg->io_id = g_io_add_watch(io, G_IO_OUT, big_info_cb, dg);
 }
 
@@ -716,6 +723,8 @@ static void bap_detached(struct bt_bap *bap, void *user_data)
 	/* Unregister BAP stream state changed callback. */
 	bt_bap_state_unregister(dg->bap, dg->state_id);
 
+	bt_bap_bcode_cb_unregister(dg->bap, dg->bcode_id);
+
 	if (dg->timeout)
 		g_source_remove(dg->timeout);
 
diff --git a/profiles/audio/bass.h b/profiles/audio/bass.h
index 42a2c047f..32c7e4def 100644
--- a/profiles/audio/bass.h
+++ b/profiles/audio/bass.h
@@ -7,8 +7,3 @@
  *
  */
 
-typedef void (*bt_bass_bcode_func_t)(void *user_data, int err);
-
-void bass_req_bcode(struct bt_bap_stream *stream,
-				bt_bass_bcode_func_t cb,
-				void *user_data);
diff --git a/profiles/audio/transport.c b/profiles/audio/transport.c
index f3ac1a251..bc7ee6e45 100644
--- a/profiles/audio/transport.c
+++ b/profiles/audio/transport.c
@@ -5,7 +5,7 @@
  *
  *  Copyright (C) 2006-2007  Nokia Corporation
  *  Copyright (C) 2004-2009  Marcel Holtmann <marcel@holtmann.org>
- *  Copyright 2023-2024 NXP
+ *  Copyright 2023-2025 NXP
  *
  *
  */
@@ -1537,7 +1537,7 @@ static void set_bcast_qos(const GDBusPropertyTable *property,
 			 * for the encrypted stream, request the code from
 			 * Broadcast Assistants, if any are available.
 			 */
-			bass_req_bcode(bap->stream, bcast_qos_set,
+			bt_bap_req_bcode(bap->stream, bcast_qos_set,
 						GUINT_TO_POINTER(id));
 			return;
 		}
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH BlueZ 3/3] bass: Remove interface
  2025-02-28 15:56 [PATCH BlueZ 0/3] bass: Register broadcast code request callback Iulia Tanasescu
  2025-02-28 15:56 ` [PATCH BlueZ 1/3] shared/bap: Add APIs to register broadcast code callback Iulia Tanasescu
  2025-02-28 15:56 ` [PATCH BlueZ 2/3] " Iulia Tanasescu
@ 2025-02-28 15:56 ` Iulia Tanasescu
  2025-03-06 15:50 ` [PATCH BlueZ 0/3] bass: Register broadcast code request callback patchwork-bot+bluetooth
  3 siblings, 0 replies; 6+ messages in thread
From: Iulia Tanasescu @ 2025-02-28 15:56 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: claudia.rosu, mihai-octavian.urzica, andrei.istodorescu,
	luiz.dentz, Iulia Tanasescu

This removes the BASS plugin interface, since plugins should not make
direct calls between each other, but use the shared files instead.
---
 Makefile.plugins           | 2 +-
 profiles/audio/bap.c       | 1 -
 profiles/audio/bass.c      | 1 -
 profiles/audio/bass.h      | 9 ---------
 profiles/audio/transport.c | 1 -
 5 files changed, 1 insertion(+), 13 deletions(-)
 delete mode 100644 profiles/audio/bass.h

diff --git a/Makefile.plugins b/Makefile.plugins
index 81cf3155a..43e665432 100644
--- a/Makefile.plugins
+++ b/Makefile.plugins
@@ -118,7 +118,7 @@ endif
 
 if BASS
 builtin_modules += bass
-builtin_sources += profiles/audio/bass.h profiles/audio/bass.c
+builtin_sources += profiles/audio/bass.c
 endif
 
 if MCP
diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c
index 37168e58c..0489f6655 100644
--- a/profiles/audio/bap.c
+++ b/profiles/audio/bap.c
@@ -57,7 +57,6 @@
 #include "src/error.h"
 
 #include "bap.h"
-#include "bass.h"
 
 #define ISO_SOCKET_UUID "6fbaf188-05e0-496a-9885-d6ddfdb4e03e"
 #define PACS_UUID_STR "00001850-0000-1000-8000-00805f9b34fb"
diff --git a/profiles/audio/bass.c b/profiles/audio/bass.c
index ec5b88ff3..44320a78a 100644
--- a/profiles/audio/bass.c
+++ b/profiles/audio/bass.c
@@ -52,7 +52,6 @@
 #include "src/log.h"
 #include "src/error.h"
 
-#include "bass.h"
 #include "bap.h"
 
 #define BASS_UUID_STR "0000184f-0000-1000-8000-00805f9b34fb"
diff --git a/profiles/audio/bass.h b/profiles/audio/bass.h
deleted file mode 100644
index 32c7e4def..000000000
--- a/profiles/audio/bass.h
+++ /dev/null
@@ -1,9 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/*
- *
- *  BlueZ - Bluetooth protocol stack for Linux
- *
- *  Copyright 2024-2025 NXP
- *
- */
-
diff --git a/profiles/audio/transport.c b/profiles/audio/transport.c
index bc7ee6e45..3d1f55b70 100644
--- a/profiles/audio/transport.c
+++ b/profiles/audio/transport.c
@@ -54,7 +54,6 @@
 
 #include "media.h"
 #include "transport.h"
-#include "bass.h"
 #include "vcp.h"
 
 #define MEDIA_TRANSPORT_INTERFACE "org.bluez.MediaTransport1"
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* RE: bass: Register broadcast code request callback
  2025-02-28 15:56 ` [PATCH BlueZ 1/3] shared/bap: Add APIs to register broadcast code callback Iulia Tanasescu
@ 2025-02-28 17:14   ` bluez.test.bot
  0 siblings, 0 replies; 6+ messages in thread
From: bluez.test.bot @ 2025-02-28 17:14 UTC (permalink / raw)
  To: linux-bluetooth, iulia.tanasescu

[-- Attachment #1: Type: text/plain, Size: 1863 bytes --]

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=939060

---Test result---

Test Summary:
CheckPatch                    PENDING   0.21 seconds
GitLint                       PENDING   0.20 seconds
BuildEll                      PASS      20.29 seconds
BluezMake                     PASS      1492.29 seconds
MakeCheck                     PASS      20.78 seconds
MakeDistcheck                 PASS      156.58 seconds
CheckValgrind                 PASS      213.97 seconds
CheckSmatch                   WARNING   284.04 seconds
bluezmakeextell               PASS      97.48 seconds
IncrementalBuild              PENDING   0.22 seconds
ScanBuild                     PASS      856.19 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
src/shared/bap.c:313:25: warning: array of flexible structuressrc/shared/bap.c: note: in included file:./src/shared/ascs.h:88:25: warning: array of flexible structuressrc/shared/bap.c:313:25: warning: array of flexible structuressrc/shared/bap.c: note: in included file:./src/shared/ascs.h:88:25: warning: array of flexible structuressrc/shared/bap.c:313:25: warning: array of flexible structuressrc/shared/bap.c: note: in included file:./src/shared/ascs.h:88:25: warning: array of flexible structures
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:



---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH BlueZ 0/3] bass: Register broadcast code request callback
  2025-02-28 15:56 [PATCH BlueZ 0/3] bass: Register broadcast code request callback Iulia Tanasescu
                   ` (2 preceding siblings ...)
  2025-02-28 15:56 ` [PATCH BlueZ 3/3] bass: Remove interface Iulia Tanasescu
@ 2025-03-06 15:50 ` patchwork-bot+bluetooth
  3 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+bluetooth @ 2025-03-06 15:50 UTC (permalink / raw)
  To: Iulia Tanasescu
  Cc: linux-bluetooth, claudia.rosu, mihai-octavian.urzica,
	andrei.istodorescu, luiz.dentz

Hello:

This series was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Fri, 28 Feb 2025 17:56:31 +0200 you wrote:
> This adds support for BASS to register Broadcast Code request callback
> with shared/bap, to be notified by the transport plugin when the
> Broadcast Code is needed at transport select. This is done to avoid
> direct calls between plugins.
> 
> Iulia Tanasescu (3):
>   shared/bap: Add APIs to register broadcast code callback
>   bass: Register broadcast code request callback
>   bass: Remove interface
> 
> [...]

Here is the summary with links:
  - [BlueZ,1/3] shared/bap: Add APIs to register broadcast code callback
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=2ca6e5215830
  - [BlueZ,2/3] bass: Register broadcast code request callback
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=518d2a7aa566
  - [BlueZ,3/3] bass: Remove interface
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=26bc1c9cd9df

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-03-06 15:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-28 15:56 [PATCH BlueZ 0/3] bass: Register broadcast code request callback Iulia Tanasescu
2025-02-28 15:56 ` [PATCH BlueZ 1/3] shared/bap: Add APIs to register broadcast code callback Iulia Tanasescu
2025-02-28 17:14   ` bass: Register broadcast code request callback bluez.test.bot
2025-02-28 15:56 ` [PATCH BlueZ 2/3] " Iulia Tanasescu
2025-02-28 15:56 ` [PATCH BlueZ 3/3] bass: Remove interface Iulia Tanasescu
2025-03-06 15:50 ` [PATCH BlueZ 0/3] bass: Register broadcast code request callback patchwork-bot+bluetooth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox