Linux-Bluetooth Archive mirror
 help / color / mirror / Atom feed
From: Andrei Istodorescu <andrei.istodorescu@nxp.com>
To: linux-bluetooth@vger.kernel.org
Cc: luiz.dentz@gmail.com, mihai-octavian.urzica@nxp.com,
	silviu.barbulescu@nxp.com, vlad.pruteanu@nxp.com,
	iulia.tanasescu@nxp.com,
	Andrei Istodorescu <andrei.istodorescu@nxp.com>
Subject: [PATCH BlueZ 1/5] shared/bap: Allow NULL bap endpoint in streams
Date: Fri, 19 Apr 2024 21:07:48 +0300	[thread overview]
Message-ID: <20240419180752.96699-2-andrei.istodorescu@nxp.com> (raw)
In-Reply-To: <20240419180752.96699-1-andrei.istodorescu@nxp.com>

---
 src/shared/bap.c | 54 +++++++++++++++++++++++++++++++++++-------------
 1 file changed, 40 insertions(+), 14 deletions(-)

diff --git a/src/shared/bap.c b/src/shared/bap.c
index 71eadbdb68b1..6328ff35f3c3 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -2115,7 +2115,8 @@ static struct bt_bap_stream *bap_stream_new(struct bt_bap *bap,
 	stream = new0(struct bt_bap_stream, 1);
 	stream->bap = bap;
 	stream->ep = ep;
-	ep->stream = stream;
+	if (ep != NULL)
+		ep->stream = stream;
 	stream->lpac = lpac;
 	stream->rpac = rpac;
 	stream->cc = util_iov_dup(data, 1);
@@ -2209,6 +2210,7 @@ static void bap_stream_set_io(void *data, void *user_data)
 	struct bt_bap_stream *stream = data;
 	int fd = PTR_TO_INT(user_data);
 	bool ret;
+	uint8_t state;
 
 	if (fd >= 0)
 		ret = bap_stream_io_attach(stream, fd, false);
@@ -2218,7 +2220,12 @@ static void bap_stream_set_io(void *data, void *user_data)
 	if (!ret)
 		return;
 
-	switch (stream->ep->state) {
+	if (bt_bap_stream_get_type(stream) == BT_BAP_STREAM_TYPE_BCAST)
+		state = stream->state;
+	else
+		state = stream->ep->state;
+
+	switch (state) {
 	case BT_BAP_STREAM_STATE_ENABLING:
 		if (fd < 0)
 			bt_bap_stream_disable(stream, false, NULL, NULL);
@@ -5424,7 +5431,8 @@ uint8_t bt_bap_stream_get_state(struct bt_bap_stream *stream)
 	if (!stream)
 		return BT_BAP_STREAM_STATE_IDLE;
 
-	if (stream->lpac->type != BT_BAP_BCAST_SOURCE)
+	if (stream->lpac->type != BT_BAP_BCAST_SOURCE &&
+			stream->lpac->type != BT_BAP_BCAST_SINK)
 		return stream->ep->state;
 	else
 		return stream->state;
@@ -5611,7 +5619,13 @@ uint8_t bt_bap_stream_get_dir(struct bt_bap_stream *stream)
 	if (!stream)
 		return 0x00;
 
-	return stream->ep->dir;
+	if (stream->ep)
+		return stream->ep->dir;
+
+	if (bt_bap_pac_get_type(stream->lpac) == BT_BAP_BCAST_SINK)
+		return BT_BAP_BCAST_SOURCE;
+	else
+		return BT_BAP_BCAST_SINK;
 }
 
 uint32_t bt_bap_stream_get_location(struct bt_bap_stream *stream)
@@ -5623,15 +5637,17 @@ uint32_t bt_bap_stream_get_location(struct bt_bap_stream *stream)
 
 	pacs = stream->client ? stream->bap->rdb->pacs : stream->bap->ldb->pacs;
 
-	if (stream->ep->dir == BT_BAP_SOURCE)
-		return pacs->source_loc_value;
-	else if (stream->ep->dir == BT_BAP_SINK)
-		return pacs->sink_loc_value;
-	else
-		/* TO DO get the location values from metadata
-		 * for brodcast source and sink
-		 */
-		return stream->bap->ldb->pacs->source_loc_value;
+	if (stream->ep) {
+		if (stream->ep->dir == BT_BAP_SOURCE)
+			return pacs->source_loc_value;
+		else if (stream->ep->dir == BT_BAP_SINK)
+			return pacs->sink_loc_value;
+	}
+
+	/* TO DO get the location values from metadata
+	 * for brodcast source and sink
+	 */
+	return stream->bap->ldb->pacs->source_loc_value;
 }
 
 struct iovec *bt_bap_stream_get_config(struct bt_bap_stream *stream)
@@ -5841,7 +5857,17 @@ uint8_t bt_bap_stream_io_dir(struct bt_bap_stream *stream)
 	if (!stream)
 		return 0x00;
 
-	dir = stream->ep->dir;
+	if (stream->ep)
+		dir = stream->ep->dir;
+	else {
+		uint8_t pac_type = bt_bap_pac_get_type(stream->lpac);
+
+		if (pac_type == BT_BAP_BCAST_SINK)
+			dir = BT_BAP_BCAST_SOURCE;
+		else
+			dir = BT_BAP_BCAST_SINK;
+
+	}
 
 	if (stream->link)
 		dir |= stream->link->ep->dir;
-- 
2.40.1


  reply	other threads:[~2024-04-19 18:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-19 18:07 [PATCH BlueZ 0/5] Create transports for matching BISes Andrei Istodorescu
2024-04-19 18:07 ` Andrei Istodorescu [this message]
2024-04-19 21:16   ` bluez.test.bot
2024-04-19 18:07 ` [PATCH BlueZ 2/5] shared/bap: Get broadcast channel location from stream capabilities Andrei Istodorescu
2024-04-19 18:07 ` [PATCH BlueZ 3/5] shared/bap: Update stream management to avoid PACs Andrei Istodorescu
2024-04-19 19:31   ` Luiz Augusto von Dentz
2024-04-19 18:07 ` [PATCH BlueZ 4/5] shared/bap: In case of a BIS-PAC match return also the local pac Andrei Istodorescu
2024-04-19 18:07 ` [PATCH BlueZ 5/5] bap: Create streams and transports for each matching BIS Andrei Istodorescu
2024-04-19 19:28   ` Luiz Augusto von Dentz
2024-04-23 17:40 ` [PATCH BlueZ 0/5] Create transports for matching BISes patchwork-bot+bluetooth

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=20240419180752.96699-2-andrei.istodorescu@nxp.com \
    --to=andrei.istodorescu@nxp.com \
    --cc=iulia.tanasescu@nxp.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).