From: "Frédéric Danis" <frederic.danis@collabora.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v3 8/8] client/btpclient: Add stream auto acquire for BAP/USR/STR/* tests
Date: Thu, 10 Sep 2026 10:49:17 +0200 [thread overview]
Message-ID: <20260910084917.23512-9-frederic.danis@collabora.com> (raw)
In-Reply-To: <20260910084917.23512-1-frederic.danis@collabora.com>
The sink stream should be auto acquired and data sent on it.
---
client/btpclient/ascs.c | 10 +++-
client/btpclient/bap.c | 108 +++++++++++++++++++++++++++++++++++
client/btpclient/bap.h | 2 +
client/btpclient/btpclient.c | 68 ++++++++++++++++++++++
client/btpclient/btpclient.h | 2 +
5 files changed, 189 insertions(+), 1 deletion(-)
diff --git a/client/btpclient/ascs.c b/client/btpclient/ascs.c
index 6b6154614..f712444e7 100644
--- a/client/btpclient/ascs.c
+++ b/client/btpclient/ascs.c
@@ -1495,7 +1495,15 @@ void ascs_property_changed(struct l_dbus_proxy *proxy, const char *name,
if (!strcmp(state, "active"))
ase_state = BT_BAP_STREAM_STATE_STREAMING;
- else {
+ else if (!strcmp(state, "pending") &&
+ ase->transport_state == ASE_TRANSPORT_READY) {
+ l_dbus_proxy_method_call(proxy, "Acquire",
+ NULL,
+ ascs_acquire_reply,
+ ase, NULL);
+ ase_change_state(ase, ASE_TRANSPORT_ACQUIRING);
+ ase_state = BT_BAP_STREAM_STATE_ENABLING;
+ } else {
if (ase->io) {
l_io_destroy(ase->io);
ase->io = NULL;
diff --git a/client/btpclient/bap.c b/client/btpclient/bap.c
index edb220f54..f2c4a7b23 100644
--- a/client/btpclient/bap.c
+++ b/client/btpclient/bap.c
@@ -366,6 +366,114 @@ void bap_proxy_added(struct l_dbus_proxy *proxy, void *user_data)
}
}
+static bool transport_get_cig_cis(struct l_dbus_proxy *proxy, uint8_t *cig,
+ uint8_t *cis)
+{
+ struct l_dbus_message_iter iter, var;
+ const char *key;
+
+ *cig = BT_ISO_QOS_CIG_UNSET;
+ *cis = BT_ISO_QOS_CIS_UNSET;
+
+ if (!l_dbus_proxy_get_property(proxy, "QoS", "a{sv}", &iter))
+ return false;
+
+ while (l_dbus_message_iter_next_entry(&iter, &key, &var)) {
+ if (!strcmp(key, "CIG")) {
+ if (!l_dbus_message_iter_get_variant(&var, "y", cig))
+ return false;
+ }
+
+ if (!strcmp(key, "CIS")) {
+ if (!l_dbus_message_iter_get_variant(&var, "y", cis))
+ return false;
+ }
+ }
+
+ return true;
+}
+
+static void send_data(struct l_idle *idle, void *user_data)
+{
+ struct btp_ase *ase = user_data;
+ ssize_t bytes_written;
+ uint8_t *data;
+
+ if (!ase->idle_writer || !ase->io) {
+ l_idle_remove(idle);
+ ase->idle_writer = NULL;
+ return;
+ }
+
+ data = l_malloc(ase->tx_mtu);
+ bytes_written = write(l_io_get_fd(ase->io), data, ase->tx_mtu);
+ if (bytes_written < 0) {
+ l_error("Failed to write (%d)", errno);
+ l_idle_remove(idle);
+ ase->idle_writer = NULL;
+ }
+ l_free(data);
+}
+
+void bap_property_changed(struct l_dbus_proxy *proxy, const char *name,
+ struct l_dbus_message *msg, void *user_data)
+{
+ const char *interface = l_dbus_proxy_get_interface(proxy);
+
+ if (!strcmp(interface, "org.bluez.MediaTransport1")) {
+ if (!strcmp(name, "State")) {
+ const char *state, *path, *uuid;
+ struct btp_device *dev;
+ struct btp_adapter *adapter;
+ uint8_t dir, cig, cis;
+ struct btp_ase *ase;
+
+ if (!l_dbus_message_get_arguments(msg, "s", &state))
+ return;
+
+ if (!l_dbus_proxy_get_property(proxy, "Device", "o",
+ &path))
+ return;
+
+ dev = find_device_by_path(path);
+ if (!dev)
+ return;
+
+ adapter = find_adapter_by_device(dev);
+ if (!adapter)
+ return;
+
+ if (!l_dbus_proxy_get_property(proxy, "UUID", "s",
+ &uuid))
+ return;
+
+ if (!bt_uuid_strcmp(uuid, PAC_SINK_UUID))
+ dir = BTP_BAP_DIR_SOURCE;
+ else
+ dir = BTP_BAP_DIR_SINK;
+
+ if (!transport_get_cig_cis(proxy, &cig, &cis))
+ return;
+
+ ase = find_ase(dev, cig, cis, dir);
+ if (!ase)
+ return;
+
+ if (!strcmp(state, "active") && ase->auto_send &&
+ (ase->dir == BTP_BAP_DIR_SINK)) {
+ ase->idle_writer = l_idle_create(send_data,
+ ase, NULL);
+ } else if (!strcmp(state, "pending")) {
+ ase->auto_send = true;
+ } else if (!strcmp(state, "idle") &&
+ ase->idle_writer) {
+ l_idle_remove(ase->idle_writer);
+ ase->idle_writer = NULL;
+ }
+ }
+ }
+}
+
bool bap_register_service(struct btp *btp_, struct l_dbus *dbus_,
struct l_dbus_client *client)
{
diff --git a/client/btpclient/bap.h b/client/btpclient/bap.h
index 7fea19f8b..3c676e0ae 100644
--- a/client/btpclient/bap.h
+++ b/client/btpclient/bap.h
@@ -13,3 +13,5 @@ void bap_unregister_service(struct btp *btp);
bool bap_is_service_registered(void);
void bap_proxy_added(struct l_dbus_proxy *proxy, void *user_data);
+void bap_property_changed(struct l_dbus_proxy *proxy, const char *name,
+ struct l_dbus_message *msg, void *user_data);
diff --git a/client/btpclient/btpclient.c b/client/btpclient/btpclient.c
index 6e084e2c8..760c6e89f 100644
--- a/client/btpclient/btpclient.c
+++ b/client/btpclient/btpclient.c
@@ -445,6 +445,30 @@ static void extract_settings(struct l_dbus_proxy *proxy, uint32_t *current,
*current |= BTP_GAP_SETTING_BONDABLE;
}
+static bool transport_get_cig_cis(struct l_dbus_message_iter *iter,
+ uint8_t *cig, uint8_t *cis)
+{
+ struct l_dbus_message_iter var;
+ const char *key;
+
+ *cig = BT_ISO_QOS_CIG_UNSET;
+ *cis = BT_ISO_QOS_CIS_UNSET;
+
+ while (l_dbus_message_iter_next_entry(iter, &key, &var)) {
+ if (!strcmp(key, "CIG")) {
+ if (!l_dbus_message_iter_get_variant(&var, "y", cig))
+ return false;
+ }
+
+ if (!strcmp(key, "CIS")) {
+ if (!l_dbus_message_iter_get_variant(&var, "y", cis))
+ return false;
+ }
+ }
+
+ return true;
+}
+
static void proxy_added(struct l_dbus_proxy *proxy, void *user_data)
{
const char *interface = l_dbus_proxy_get_interface(proxy);
@@ -773,11 +797,55 @@ static void property_changed(struct l_dbus_proxy *proxy, const char *name,
l_info("Property changed: %s %s %s", name, path, interface);
+ if (!strcmp(interface, "org.bluez.MediaTransport1")) {
+ if (!strcmp(name, "QoS")) {
+ struct btp_device *dev;
+ const char *dev_path, *uuid;
+ uint8_t dir;
+ struct l_dbus_message_iter iter;
+ uint8_t cig = BT_ISO_QOS_CIG_UNSET;
+ uint8_t cis = BT_ISO_QOS_CIS_UNSET;
+ struct btp_ase *ase;
+
+ if (!l_dbus_proxy_get_property(proxy, "Device", "s",
+ &dev_path))
+ return;
+
+ dev = find_device_by_path(path);
+ if (!dev)
+ return;
+
+ if (!l_dbus_proxy_get_property(proxy, "UUID", "s",
+ &uuid))
+ return;
+
+ if (!bt_uuid_strcmp(uuid, PAC_SINK_UUID))
+ dir = BTP_BAP_DIR_SOURCE;
+ else
+ dir = BTP_BAP_DIR_SINK;
+
+ if (!l_dbus_message_get_arguments(msg, "a{sv}", &iter))
+ return;
+
+ if (!transport_get_cig_cis(&iter, &cig, &cis))
+ return;
+
+ ase = find_ase(dev, cig, cis, dir);
+ if (!ase)
+ return;
+
+ ase->transport_proxy = proxy;
+ }
+ }
+
if (gap_is_service_registered())
gap_property_changed(proxy, name, msg, user_data);
if (ascs_is_service_registered())
ascs_property_changed(proxy, name, msg, user_data);
+
+ if (bap_is_service_registered())
+ bap_property_changed(proxy, name, msg, user_data);
}
static void client_connected(struct l_dbus *dbus, void *user_data)
diff --git a/client/btpclient/btpclient.h b/client/btpclient/btpclient.h
index 6fab3d701..54f44ae9a 100644
--- a/client/btpclient/btpclient.h
+++ b/client/btpclient/btpclient.h
@@ -56,6 +56,8 @@ struct btp_ase {
struct l_io *io;
uint16_t rx_mtu;
uint16_t tx_mtu;
+ bool auto_send;
+ struct l_idle *idle_writer;
};
struct btp_agent {
--
2.43.0
next prev parent reply other threads:[~2026-09-10 8:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 8:49 [PATCH BlueZ v3 0/8] client/btpclient: Add BAP/ASCS/PACS support for auto-pts BAP tests Frédéric Danis
2026-09-10 8:49 ` [PATCH BlueZ v3 1/8] client/btpclient: Add BTP_EV_BAP_ASE_FOUND support Frédéric Danis
2026-09-10 8:49 ` [PATCH BlueZ v3 2/8] client/btpclient: Get Codec capabilities on ASE reply Frédéric Danis
2026-09-10 8:49 ` [PATCH BlueZ v3 3/8] client/btpclient: Add ASCS BTP support Frédéric Danis
2026-09-10 8:49 ` [PATCH BlueZ v3 4/8] client/btpclient: Add BTP_OP_PACS_SET_LOCATION support Frédéric Danis
2026-09-10 8:49 ` [PATCH BlueZ v3 5/8] client/btpclient: Add BTP_OP_BAP_SEND support Frédéric Danis
2026-09-10 8:49 ` [PATCH BlueZ v3 6/8] client/btpclient: Add ASCS support for BAP/UCL/STR/* tests Frédéric Danis
2026-09-10 8:49 ` [PATCH BlueZ v3 7/8] client/btpclient: CIG/CIS assignment based on Client/Server role Frédéric Danis
2026-09-10 8:49 ` Frédéric Danis [this message]
2026-09-10 16:30 ` [PATCH BlueZ v3 0/8] client/btpclient: Add BAP/ASCS/PACS support for auto-pts BAP tests 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=20260910084917.23512-9-frederic.danis@collabora.com \
--to=frederic.danis@collabora.com \
--cc=linux-bluetooth@vger.kernel.org \
/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.