All of lore.kernel.org
 help / color / mirror / Atom feed
From: Silviu Florian Barbulescu <silviu.barbulescu@nxp.com>
To: linux-bluetooth@vger.kernel.org
Cc: mihai-octavian.urzica@nxp.com, silviu.barbulescu@nxp.com,
	vlad.pruteanu@nxp.com, andrei.istodorescu@nxp.com,
	luiz.dentz@gmail.com, iulia.tanasescu@nxp.com
Subject: [PATCH BlueZ 2/2] player: Allow endpoint config without local endpoint argument
Date: Wed, 20 Mar 2024 16:41:53 +0200	[thread overview]
Message-ID: <20240320144153.46408-3-silviu.barbulescu@nxp.com> (raw)
In-Reply-To: <20240320144153.46408-1-silviu.barbulescu@nxp.com>

Update endpoint config command to create local endpoint for broadcast
 endpoint, this will be used to configure a broadcast source\sink if
 register endpoint is done from another application like PipeWire
---
 client/player.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 77 insertions(+), 3 deletions(-)

diff --git a/client/player.c b/client/player.c
index ab33bfc46..b02a40423 100644
--- a/client/player.c
+++ b/client/player.c
@@ -3662,10 +3662,15 @@ static void endpoint_set_config_bcast(struct endpoint_config *cfg)
 		config_endpoint_iso_group, cfg);
 }
 
+static void endpoint_init_defaults(struct endpoint *ep);
 static void cmd_config_endpoint(int argc, char *argv[])
 {
+	DBusMessageIter iter;
 	struct endpoint_config *cfg;
-	const struct codec_preset *preset;
+	const struct codec_preset *preset = NULL;
+	const struct capabilities *cap;
+	uint8_t codec;
+	const char *uuid;
 
 	cfg = new0(struct endpoint_config, 1);
 
@@ -3680,8 +3685,75 @@ static void cmd_config_endpoint(int argc, char *argv[])
 	/* Search for the local endpoint */
 	cfg->ep = endpoint_find(argv[2]);
 	if (!cfg->ep) {
-		bt_shell_printf("Local Endpoint %s not found\n", argv[2]);
-		goto fail;
+		/* If argc != 3 then argv[2] should be the
+		 * local endpoint. Return error.
+		 */
+		if (argc != 3) {
+			bt_shell_printf("Local Endpoint %s not found\n",
+					argv[2]);
+			goto fail;
+		}
+
+		/* If local endpoint is not found verify if this is a
+		 * broadcast remote endpoint because this can be an
+		 * endpoint config command with remote endpoint and
+		 * preset. In this case we have to create its own
+		 * local endpoint.
+		 */
+		if (!g_dbus_proxy_get_property(cfg->proxy, "UUID", &iter))
+			return;
+		dbus_message_iter_get_basic(&iter, &uuid);
+
+		/* The local endpoint must have the UUID of local pac but
+		 * the remote endpoint has the UUID of the remote pac, so
+		 * based on this information we determine the UUID for the
+		 * local endpoint.
+		 */
+		if (!strcmp(uuid, BAA_SERVICE_UUID))
+			uuid = BCAA_SERVICE_UUID;
+		else if (!strcmp(uuid, BCAA_SERVICE_UUID))
+			uuid = BAA_SERVICE_UUID;
+		else {
+			/* This should be a local endpoint because is not
+			 * a broadcast endpoint.
+			 */
+			bt_shell_printf("Local Endpoint %s not found\n",
+					argv[2]);
+			goto fail;
+		}
+
+		if (!g_dbus_proxy_get_property(cfg->proxy, "Codec", &iter))
+			return;
+
+		dbus_message_iter_get_basic(&iter, &codec);
+
+		/* Verify if the local endpoint already exists */
+		cfg->ep = endpoint_find(uuid);
+		if ((!cfg->ep) || (cfg->ep->codec != codec)) {
+			/* Get capabilities to create the local endpoint */
+			cap = find_capabilities(uuid, codec);
+			if (!cap) {
+				bt_shell_printf(
+					"Capabilities not found for UUID %s, codec id %d",
+					uuid, codec);
+				goto fail;
+			}
+
+			cfg->ep = endpoint_new(cap);
+			endpoint_init_defaults(cfg->ep);
+		}
+
+		/* Verify if argv[2] parameter is a valid preset */
+		preset = preset_find_name(cfg->ep->preset, argv[2]);
+		if (!preset) {
+			bt_shell_printf("Preset %s not found\n",
+				argv[2]);
+			/* Free created endpoint */
+			local_endpoints = g_list_remove(local_endpoints,
+						cfg->ep);
+			endpoint_free(cfg->ep);
+			goto fail;
+		}
 	}
 
 	if (argc > 3) {
@@ -3690,7 +3762,9 @@ static void cmd_config_endpoint(int argc, char *argv[])
 			bt_shell_printf("Preset %s not found\n", argv[3]);
 			goto fail;
 		}
+	}
 
+	if (preset) {
 		cfg->caps = g_new0(struct iovec, 1);
 		/* Copy capabilities */
 		util_iov_append(cfg->caps, preset->data.iov_base,
-- 
2.39.2


  parent reply	other threads:[~2024-03-20 14:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-20 14:41 [PATCH BlueZ 0/2] Allow endpoint config without local endpoint argument Silviu Florian Barbulescu
2024-03-20 14:41 ` [PATCH BlueZ 1/2] bap: Add bcast source support for MediaEndpoint Codec Silviu Florian Barbulescu
2024-03-20 17:05   ` Allow endpoint config without local endpoint argument bluez.test.bot
2024-03-20 14:41 ` Silviu Florian Barbulescu [this message]
2024-03-20 17:32   ` [PATCH BlueZ 2/2] player: " Luiz Augusto von Dentz
2024-03-21 11:33     ` Silviu Florian Barbulescu
2024-03-28 14:40 ` [PATCH BlueZ 0/2] " 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=20240320144153.46408-3-silviu.barbulescu@nxp.com \
    --to=silviu.barbulescu@nxp.com \
    --cc=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=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.