All of lore.kernel.org
 help / color / mirror / Atom feed
From: Claudia Draghicescu <claudia.rosu@nxp.com>
To: linux-bluetooth@vger.kernel.org
Cc: iulia.tanasescu@nxp.com, mihai-octavian.urzica@nxp.com,
	silviu.barbulescu@nxp.com, vlad.pruteanu@nxp.com,
	andrei.istodorescu@nxp.com,
	Claudia Draghicescu <claudia.rosu@nxp.com>
Subject: [PATCH BlueZ 1/2] bap: Fix source+sink endpoint registration
Date: Fri, 13 Oct 2023 13:05:36 +0300	[thread overview]
Message-ID: <20231013100537.3867-2-claudia.rosu@nxp.com> (raw)
In-Reply-To: <20231013100537.3867-1-claudia.rosu@nxp.com>

Create new endpoint name for the simulated broadcast sink that is
created when registering a broadcast source endpoint.
This removes the ambiguity when having registered a local
broadcast sink and fixes the situation when multiple remote
endpoints are created when discovering a broadcast source.

---
 src/shared/bap.c | 54 +++++++++++++++++++++++++++---------------------
 src/shared/bap.h |  1 +
 2 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/src/shared/bap.c b/src/shared/bap.c
index 925501c48..266116235 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -644,7 +644,7 @@ static struct bt_bap_endpoint *bap_endpoint_new_broadcast(struct bt_bap_db *bdb,
 	if (type == BT_BAP_BCAST_SINK)
 		ep->dir = BT_BAP_BCAST_SOURCE;
 	else
-		ep->dir = BT_BAP_BCAST_SINK;
+		ep->dir = BT_BAP_SIMULATED_BCAST_SINK;
 
 	return ep;
 }
@@ -1500,12 +1500,12 @@ static void ep_config_cb(struct bt_bap_stream *stream, int err)
 		return;
 
 	if (bt_bap_stream_get_type(stream) == BT_BAP_STREAM_TYPE_BCAST) {
-		if (bt_bap_stream_io_dir(stream) == BT_BAP_BCAST_SINK)
+		if (bt_bap_stream_io_dir(stream) == BT_BAP_SIMULATED_BCAST_SINK)
 			stream_set_state_broadcast(stream,
-						BT_BAP_STREAM_STATE_QOS);
+				BT_BAP_STREAM_STATE_QOS);
 		else if (bt_bap_stream_io_dir(stream) == BT_BAP_BCAST_SOURCE)
 			stream_set_state_broadcast(stream,
-						BT_BAP_STREAM_STATE_CONFIG);
+				BT_BAP_STREAM_STATE_CONFIG);
 		return;
 	}
 
@@ -2710,15 +2710,15 @@ struct bt_bap_pac *bt_bap_add_vendor_pac(struct gatt_db *db,
 		break;
 	case BT_BAP_BCAST_SOURCE:
 		bap_add_broadcast_source(pac);
-		if (queue_isempty(bdb->broadcast_sinks)) {
-			/* When adding a local broadcast source, add also a
-			 * local broadcast sink
-			 */
-			pac_broadcast_sink = bap_pac_new(bdb, name,
-					BT_BAP_BCAST_SINK, &codec, qos,
-					data, metadata);
-			bap_add_broadcast_sink(pac_broadcast_sink);
-		}
+		/* When adding a local broadcast source, add also a
+		 * local broadcast sink
+		 */
+		pac_broadcast_sink = bap_pac_new(bdb, name,
+			BT_BAP_SIMULATED_BCAST_SINK, &codec, qos,
+			data, metadata);
+		bap_add_broadcast_sink(pac_broadcast_sink);
+		queue_foreach(sessions, notify_session_pac_added, pac_broadcast_sink);
+		return pac;
 		break;
 	case BT_BAP_BCAST_SINK:
 		bap_add_broadcast_sink(pac);
@@ -4457,13 +4457,23 @@ static void bap_foreach_pac(struct queue *l, struct queue *r,
 		for (er = queue_get_entries(r); er; er = er->next) {
 			struct bt_bap_pac *rpac = er->data;
 
+			if ((lpac->type == BT_BAP_BCAST_SOURCE)
+				&& (rpac->type != BT_BAP_SIMULATED_BCAST_SINK))
+				continue;
+			if ((rpac->type == BT_BAP_SIMULATED_BCAST_SINK)
+				&& (lpac->type == BT_BAP_BCAST_SOURCE)) {
+				func(lpac, rpac, user_data);
+				return;
+			}
+
 			/* Skip checking codec for bcast source,
 			 * it will be checked when BASE info are received
 			 */
 			if ((rpac->type != BT_BAP_BCAST_SOURCE) &&
 				(!bap_codec_equal(&lpac->codec, &rpac->codec)))
 				continue;
-
+			if (rpac->type == BT_BAP_SIMULATED_BCAST_SINK)
+				continue;
 			if (!func(lpac, rpac, user_data))
 				return;
 		}
@@ -4484,12 +4494,6 @@ void bt_bap_foreach_pac(struct bt_bap *bap, uint8_t type,
 		return bap_foreach_pac(bap->ldb->sinks, bap->rdb->sources,
 							   func, user_data);
 	case BT_BAP_BCAST_SOURCE:
-		if (queue_isempty(bap->rdb->broadcast_sources)
-			&& queue_isempty(bap->rdb->broadcast_sinks))
-			return bap_foreach_pac(bap->ldb->broadcast_sources,
-					bap->ldb->broadcast_sinks,
-					func, user_data);
-
 		return bap_foreach_pac(bap->ldb->broadcast_sinks,
 					bap->rdb->broadcast_sources,
 					func, user_data);
@@ -4497,6 +4501,10 @@ void bt_bap_foreach_pac(struct bt_bap *bap, uint8_t type,
 		return bap_foreach_pac(bap->ldb->broadcast_sinks,
 					bap->rdb->broadcast_sources,
 					func, user_data);
+	case BT_BAP_SIMULATED_BCAST_SINK:
+		return bap_foreach_pac(bap->ldb->broadcast_sources,
+					bap->ldb->broadcast_sinks,
+					func, user_data);
 	}
 }
 
@@ -4927,12 +4935,12 @@ unsigned int bt_bap_stream_enable(struct bt_bap_stream *stream,
 		queue_foreach(stream->links, bap_stream_enable_link, metadata);
 		break;
 	case BT_BAP_STREAM_TYPE_BCAST:
-		if (bt_bap_stream_io_dir(stream) == BT_BAP_BCAST_SINK)
+		if (bt_bap_stream_io_dir(stream) == BT_BAP_SIMULATED_BCAST_SINK)
 			stream_set_state_broadcast(stream,
-						BT_BAP_STREAM_STATE_CONFIG);
+				BT_BAP_STREAM_STATE_CONFIG);
 		else if (bt_bap_stream_io_dir(stream) == BT_BAP_BCAST_SOURCE)
 			stream_set_state_broadcast(stream,
-						BT_BAP_STREAM_STATE_STREAMING);
+				 BT_BAP_STREAM_STATE_STREAMING);
 
 		return 1;
 	}
diff --git a/src/shared/bap.h b/src/shared/bap.h
index ebe4dbf7d..af3b6be71 100644
--- a/src/shared/bap.h
+++ b/src/shared/bap.h
@@ -19,6 +19,7 @@
 #define	BT_BAP_SOURCE			0x02
 #define	BT_BAP_BCAST_SOURCE		0x03
 #define	BT_BAP_BCAST_SINK		0x04
+#define BT_BAP_SIMULATED_BCAST_SINK	0x05
 
 #define BT_BAP_STREAM_TYPE_UCAST	0x01
 #define	BT_BAP_STREAM_TYPE_BCAST	0x02
-- 
2.39.2


  reply	other threads:[~2023-10-13 10:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-13 10:05 [PATCH BlueZ 0/2] bap: Fix source+sink endpoint registration Claudia Draghicescu
2023-10-13 10:05 ` Claudia Draghicescu [this message]
2023-10-13 11:26   ` bluez.test.bot
2023-10-13 17:29   ` [PATCH BlueZ 1/2] " Luiz Augusto von Dentz
2023-10-16 13:27     ` Claudia Draghicescu
2023-10-13 10:05 ` [PATCH BlueZ 2/2] " Claudia Draghicescu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231013100537.3867-2-claudia.rosu@nxp.com \
    --to=claudia.rosu@nxp.com \
    --cc=andrei.istodorescu@nxp.com \
    --cc=iulia.tanasescu@nxp.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=mihai-octavian.urzica@nxp.com \
    --cc=silviu.barbulescu@nxp.com \
    --cc=vlad.pruteanu@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.