public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ v1] client: Fix transport.acquire auto not working as initiator
@ 2025-12-02 20:18 Luiz Augusto von Dentz
  2025-12-02 21:13 ` [BlueZ,v1] " bluez.test.bot
  2025-12-04 16:00 ` [PATCH BlueZ v1] " patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2025-12-02 20:18 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Transports configured as client/initiator do not transit to
State:pending since that is used to indicate that a stream has been
configured and has to be accepted, when acting as initiator role
SelectProperties/SelectConfiguration can used to indicate that
endpoint stream configuration has been initiated locally so use that
to mark endpoint to auto configure if that has been set.
---
 client/player.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/client/player.c b/client/player.c
index 121c64f0a8d4..b6b02a0001b8 100644
--- a/client/player.c
+++ b/client/player.c
@@ -112,10 +112,13 @@ struct endpoint {
 	uint16_t supported_context;
 	uint16_t context;
 	bool auto_accept;
+	bool auto_acquire;
 	uint8_t max_transports;
 	uint8_t iso_group;
 	uint8_t iso_stream;
 	struct queue *acquiring;
+	struct queue *auto_acquiring;
+	unsigned int auto_acquiring_id;
 	struct queue *selecting;
 	unsigned int selecting_id;
 	struct queue *transports;
@@ -1170,6 +1173,51 @@ static void ep_set_selecting(struct endpoint *ep, const char *path)
 						NULL);
 }
 
+static void transport_acquire(GDBusProxy *proxy, bool prompt);
+
+static bool ep_auto_acquiring_process(void *user_data)
+{
+	struct endpoint *ep = user_data;
+	const struct queue_entry *entry;
+
+	ep->auto_acquiring_id = 0;
+
+	if (queue_isempty(ep->auto_acquiring))
+		return true;
+
+	for (entry = queue_get_entries(ep->auto_acquiring); entry;
+					entry = entry->next) {
+		GDBusProxy *proxy;
+
+		proxy = g_dbus_proxy_lookup(transports, NULL, entry->data,
+					BLUEZ_MEDIA_TRANSPORT_INTERFACE);
+		if (!proxy)
+			continue;
+
+		transport_acquire(proxy, false);
+	}
+
+	queue_destroy(ep->auto_acquiring, NULL);
+	ep->auto_acquiring = NULL;
+
+	return true;
+}
+
+static void ep_set_auto_acquiring(struct endpoint *ep, const char *path)
+{
+	bt_shell_printf("Transport %s auto acquiring\n", path);
+
+	if (!ep->auto_acquiring)
+		ep->auto_acquiring = queue_new();
+
+	queue_push_tail(ep->auto_acquiring, strdup(path));
+
+	if (!ep->auto_acquiring_id)
+		ep->auto_acquiring_id = timeout_add(1000,
+						ep_auto_acquiring_process,
+						ep, NULL);
+}
+
 static DBusMessage *endpoint_set_configuration(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
@@ -1209,6 +1257,8 @@ static DBusMessage *endpoint_set_configuration(DBusConnection *conn,
 	if (ep->auto_accept) {
 		if (auto_select && ep->broadcast)
 			ep_set_selecting(ep, path);
+		else if (ep->auto_acquire && !ep->broadcast)
+			ep_set_auto_acquiring(ep, path);
 
 		bt_shell_printf("Auto Accepting...\n");
 		return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
@@ -1815,6 +1865,11 @@ static DBusMessage *endpoint_select_configuration(DBusConnection *conn,
 
 	bt_shell_printf("Auto Accepting using %s...\n", p->name);
 
+	/* Mark auto_acquire if set so the transport is acquired upon
+	 * SetConfiguration.
+	 */
+	ep->auto_acquire = auto_acquire;
+
 	return reply;
 }
 
@@ -2264,6 +2319,11 @@ static DBusMessage *endpoint_select_properties(DBusConnection *conn,
 	if (!reply)
 		return NULL;
 
+	/* Mark auto_acquire if set so the transport is acquired upon
+	 * SetConfiguration.
+	 */
+	ep->auto_acquire = auto_acquire;
+
 	return reply;
 }
 
@@ -3015,8 +3075,10 @@ static void endpoint_free(void *data)
 		free(ep->preset);
 
 	timeout_remove(ep->selecting_id);
+	timeout_remove(ep->auto_acquiring_id);
 
 	queue_destroy(ep->acquiring, NULL);
+	queue_destroy(ep->auto_acquiring, free);
 	queue_destroy(ep->selecting, free);
 	queue_destroy(ep->transports, free);
 
-- 
2.52.0


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

end of thread, other threads:[~2025-12-04 16:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-02 20:18 [PATCH BlueZ v1] client: Fix transport.acquire auto not working as initiator Luiz Augusto von Dentz
2025-12-02 21:13 ` [BlueZ,v1] " bluez.test.bot
2025-12-04 16:00 ` [PATCH BlueZ v1] " 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