diff mbox series

[BlueZ,v2,1/1] Add command to create local endpoint in bluetoothctl

Message ID 20240301163946.5484-2-silviu.barbulescu@nxp.com
State New
Headers show
Series Add command to create local endpoint in bluetoothctl | expand

Commit Message

Silviu Florian Barbulescu March 1, 2024, 4:39 p.m. UTC
Example:
endpoint.new_local_ep 00001852-0000-1000-8000-00805f9b34fb 0x06
Endpoint /local/endpoint/bcaa/lc3 registered

---
 client/player.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
diff mbox series

Patch

diff --git a/client/player.c b/client/player.c
index a40bf66e3..e297bb615 100644
--- a/client/player.c
+++ b/client/player.c
@@ -4263,6 +4263,8 @@  done:
 	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
 
+static void cmd_new_local_endpoint(int argc, char *argv[]);
+
 static const struct bt_shell_menu endpoint_menu = {
 	.name = "endpoint",
 	.desc = "Media Endpoint Submenu",
@@ -4287,6 +4289,10 @@  static const struct bt_shell_menu endpoint_menu = {
 						cmd_presets_endpoint,
 						"List available presets",
 						uuid_generator },
+	{ "new_local_ep",  "<UUID> <codec[:company]>",
+						cmd_new_local_endpoint,
+						"Create local endpoint",
+						uuid_generator },
 	{} },
 };
 
@@ -4372,6 +4378,27 @@  static void register_endpoints(GDBusProxy *proxy)
 	}
 }
 
+static void cmd_new_local_endpoint(int argc, char *argv[])
+{
+	struct endpoint *ep = NULL;
+	size_t i;
+	char *uuid = g_strdup(argv[1]);
+
+	for (i = 0; i < ARRAY_SIZE(caps); i++) {
+		const struct capabilities *cap = &caps[i];
+
+		if (strcasecmp(cap->uuid, uuid))
+			continue;
+
+		ep = endpoint_new(cap);
+		endpoint_init_defaults(ep);
+		break;
+	}
+
+	if (ep)
+		bt_shell_printf("Endpoint %s registered\n", ep->path);
+}
+
 static void media_added(GDBusProxy *proxy)
 {
 	medias = g_list_append(medias, proxy);