All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v1 11/12] test: functional: add BAP broadcast assistant test
Date: Wed,  9 Sep 2026 15:23:07 -0400	[thread overview]
Message-ID: <20260909192308.1306567-12-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20260909192308.1306567-1-luiz.dentz@gmail.com>

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

Add a test covering the Broadcast Assistant sharing a broadcast with a
Scan Delegator, with the Broadcast Source and the Broadcast Assistant
colocated so the assistant shares its own broadcast. The delegator
receives the periodic advertising sync over the connection to the
assistant (PAST), instead of scanning the source itself.

The topology where the assistant relays a source it scanned, which
does not use PAST, needs the assistant on a third host and can be
added later.

Assisted-by: opencode:claude-opus-5
---
 doc/functional-bap.rst      |  94 +++++++++++++++++++++++++++++
 test/functional/test_bap.py | 115 ++++++++++++++++++++++++++++++------
 2 files changed, 192 insertions(+), 17 deletions(-)

diff --git a/doc/functional-bap.rst b/doc/functional-bap.rst
index 99a3d63eef68..f9392bd2dbce 100644
--- a/doc/functional-bap.rst
+++ b/doc/functional-bap.rst
@@ -194,3 +194,97 @@ test_bap_broadcast_transport_acquire[lc3|pbp]
 	not issue ``transport.acquire`` itself. The broadcast code has to
 	match the one the source encrypted the BIG with, otherwise the
 	sink cannot decrypt the stream.
+
+BROADCAST ASSISTANT
+===================
+
+Two hosts, with the Broadcast Source and the Broadcast Assistant
+colocated on host0, sharing its own broadcast with the Scan Delegator:
+
+.. code-block::
+
+	+------------------------+                 +------------------------+
+	| host0                  |                 | host1                  |
+	| Broadcast Source       |   extended +    | Scan Delegator         |
+	| + Broadcast Assistant  |  periodic adv   | (Broadcast Sink)       |
+	| bluetoothctl -a auto   | --------------> | bluetoothctl -a auto   |
+	| broadcast-source.bt    |                 | broadcast-delegator.bt |
+	| BCAA endpoint (0x1852) |   BIG (BIS 1)   | BAA endpoint (0x1851)  |
+	|                        | ==============> |                        |
+	|                        | ACL, BASS, PAST |                        |
+	|                        | --------------> |                        |
+	+------------------------+                 +------------------------+
+
+	--> advertising is scanned by          ==> audio flows towards
+
+	The assistant connects to the delegator over ACL and shares the
+	local broadcast with it: the delegator receives the periodic
+	advertising sync over that connection (PAST), rather than scanning
+	the source itself.
+
+``client/scripts/broadcast-source.bt`` on host0
+	Registers a Broadcast Source endpoint
+	(``00001852-0000-1000-8000-00805f9b34fb``) with LC3, configures it
+	with the 16_2_1 preset and acquires the transport, which starts
+	the broadcast. The stream is encrypted with the broadcast code
+	`bluetoothctl` uses by default.
+
+``client/scripts/broadcast-delegator.bt`` on host1
+	Registers a Broadcast Sink endpoint
+	(``00001851-0000-1000-8000-00805f9b34fb``) with LC3, enables
+	automatic transport selection and acquisition, and advertises, so
+	the Broadcast Assistant can discover it and connect.
+
+The local broadcast of host0 is exposed as a MediaAssistant object in
+the ``local`` state, under the adapter path, e.g.
+``/org/bluez/hci0/sid0/bis1``. The push is driven through the commands
+of the assistant submenu, see **bluetoothctl-assistant(1)**.
+
+test_bass_past_transport_acquire
+--------------------------------
+
+:Setup: As above.
+
+:Steps:
+	1. Start `bluetoothctl` with the source script on host0 and the
+	   delegator script on host1.
+	2. Assistant: ``scan on``, wait for the delegator device, then
+	   ``connect`` it.
+	3. Assistant: ``assistant.push <local assistant path>``, answering
+	   the device prompt with the delegator device path and, if asked,
+	   the broadcast code prompt with the code the stream is encrypted
+	   with.
+
+:Expected:
+	1. ``Acquire successful: fd <fd> MTU <read>:<write>`` on the
+	   source, i.e. it is broadcasting, and the local stream is
+	   exposed as ``[NEW] Assistant <adapter>/sid0/bis1``. On the
+	   delegator, ``Advertising object registered``.
+	2. ``Connection successful``, with the delegator authorizing the
+	   assistant.
+	3. ``Assistant <path> pushed``.
+	4. On the delegator a transport is created for the BIS, and
+	   selected and acquired automatically, reaching
+	   ``State: broadcasting``, i.e. it synced to the BIG, and then
+	   ``State: active``.
+
+:Notes: The delegator does not scan the source: it syncs to the
+	periodic advertising over the ACL to the assistant, as pushing a
+	local stream requests PAST. When instead the assistant scans and
+	relays a *remote* source, it shares the stream without PAST and
+	the delegator has to sync by scanning itself; that topology, with
+	the assistant on a third host, is left to be added later.
+
+	The broadcast code of the local stream is handed to the delegator
+	by the push, so its automatic transport selection does not have to
+	prompt for it, and the push itself is only asked for the device to
+	share the stream with.
+
+	The delegator is paired first: the Broadcast Receive State
+	characteristic requires an encrypted link, and without it the
+	assistant fails to read it and the push is rejected with
+	``org.bluez.Error.InvalidArguments``.
+
+	The stream is verified on the delegator rather than through the
+	state of the MediaAssistant object, as an object created for a
+	local stream stays in the ``local`` state.
diff --git a/test/functional/test_bap.py b/test/functional/test_bap.py
index 6b62338ac676..bc9bcfb83ad8 100644
--- a/test/functional/test_bap.py
+++ b/test/functional/test_bap.py
@@ -34,13 +34,18 @@ def dev_addr(host):
 
 def expect_all(ctl, patterns):
     """
-    Expect all the given patterns, in any order.
+    Expect all the given patterns, in any order, returning the groups
+    each of them matched.
     """
-    patterns = list(patterns)
+    pending = list(enumerate(patterns))
+    groups = [None] * len(patterns)
 
-    while patterns:
-        idx, _ = ctl.expect(patterns)
-        patterns.pop(idx)
+    while pending:
+        idx, m = ctl.expect([pattern for _, pattern in pending])
+        groups[pending[idx][0]] = m
+        pending.pop(idx)
+
+    return groups
 
 
 def script(name):
@@ -63,28 +68,39 @@ def start_bluetoothctl(host, init_script):
     return ctl
 
 
-def pair_le(host0, ctl0, host1, ctl1):
+def pair_le(host0, ctl0, host1, ctl1, advertise=True, services=False):
     ctl0.send("scan on\n")
     ctl0.expect(f"Controller {host0.bdaddr.upper()} Discovering: yes")
 
-    ctl1.send("advertise on\n")
-    ctl1.expect("Advertising object registered")
+    if advertise:
+        ctl1.send("advertise on\n")
+        ctl1.expect("Advertising object registered")
 
     ctl0.expect(f"Device {host1.bdaddr.upper()}")
     ctl0.send(f"pair {host1.bdaddr.upper()}\n")
 
+    pending = ["Pairing successful"]
+    if services:
+        pending.append(f"Device {host1.bdaddr.upper()} ServicesResolved: yes")
+
     # See test_bluetoothctl_pair_le: passkey confirmation is handled by
     # the auto agent, but legacy passkey entry still needs an answer
-    idx, m = ctl0.expect([r"\[agent\].*Passkey:.*m(\d+)", "Pairing successful"])
+    legacy = r"\[agent\].*Passkey:.*m(\d+)"
 
-    if idx == 0:
-        warnings.warn(
-            "BUG: we got passkey authentication, bluetoothd/kernel should be fixed"
-        )
-        key = m[0].decode("utf-8")
-        ctl1.expect(r"\[agent\] Enter passkey \(number in 0-999999\):")
-        ctl1.send(f"{key}\n")
-        ctl0.expect("Pairing successful")
+    while pending:
+        idx, m = ctl0.expect([legacy] + pending)
+
+        if idx == 0:
+            warnings.warn(
+                "BUG: we got passkey authentication, bluetoothd/kernel "
+                "should be fixed"
+            )
+            key = m[0].decode("utf-8")
+            ctl1.expect(r"\[agent\] Enter passkey \(number in 0-999999\):")
+            ctl1.send(f"{key}\n")
+            continue
+
+        pending.pop(idx - 1)
 
     ctl0.send("scan off\n")
 
@@ -235,3 +251,68 @@ def test_bap_broadcast_transport_acquire(hosts, source_script):
             f"Transport {transport} State: active",
         ],
     )
+
+
+past_host_config = host_config(
+    [Bluetoothd(conf=BAP_CONF), Pexpect()],
+    [Bluetoothd(conf=BAP_CONF), Pexpect()],
+)
+
+LOCAL_ASSISTANT_RE = r"Assistant (/org/bluez/\S+/sid\d+/bis\d+)"
+
+
+@past_host_config
+def test_bass_past_transport_acquire(hosts):
+    source_host, delegator_host = hosts
+
+    # Source broadcasting, and its own stream exposed as a local
+    # MediaAssistant object
+    source = start_bluetoothctl(source_host, "broadcast-source.bt")
+    groups = expect_all(
+        source,
+        [LOCAL_ASSISTANT_RE, r"Acquire successful: fd \d+ MTU \d+:\d+"],
+    )
+    assistant_path = groups[0][0].decode("utf-8")
+
+    # Delegator advertising, selecting and acquiring automatically
+    delegator = start_bluetoothctl(delegator_host, "broadcast-delegator.bt")
+    delegator.expect("Advertising object registered")
+
+    # Pair with the delegator: the Broadcast Receive State requires
+    # an encrypted link to be read
+    pair_le(
+        source_host,
+        source,
+        delegator_host,
+        delegator,
+        advertise=False,
+        services=True,
+    )
+
+    # Share the local broadcast: the delegator receives the periodic
+    # advertising sync over the connection (PAST)
+    source.send(f"assistant.push {assistant_path}\n")
+    source.expect(r"Enter Device \(path\):")
+    source.send(f"/org/bluez/hci0/dev_{dev_addr(delegator_host)}\n")
+
+    # The local stream may already know the broadcast code
+    idx, _ = source.expect(
+        [r"Enter Broadcast Code \(auto/value\):", r"Assistant \S+ pushed"]
+    )
+    if idx == 0:
+        source.send(f"{BCAST_CODE}\n")
+        source.expect(r"Assistant \S+ pushed")
+
+    # A transport is created on the delegator, selected and acquired
+    # automatically
+    _, m = delegator.expect(TRANSPORT_RE)
+    transport = m[0].decode("utf-8")
+
+    expect_all(
+        delegator,
+        [
+            r"Acquire successful: fd \d+ MTU \d+:\d+",
+            f"Transport {transport} State: broadcasting",
+            f"Transport {transport} State: active",
+        ],
+    )
-- 
2.55.0


  parent reply	other threads:[~2026-09-09 19:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09 19:22 [PATCH BlueZ v1 00/12] Add functional tests for A2DP and BAP Luiz Augusto von Dentz
2026-09-09 19:22 ` [PATCH BlueZ v1 01/12] build: add doc/test-functional.rst to EXTRA_DIST Luiz Augusto von Dentz
2026-09-10 18:28   ` Add functional tests for A2DP and BAP bluez.test.bot
2026-09-09 19:22 ` [PATCH BlueZ v1 02/12] doc: describe the functional test cases Luiz Augusto von Dentz
2026-09-09 19:22 ` [PATCH BlueZ v1 03/12] client: do not prompt for LE Audio settings on A2DP endpoints Luiz Augusto von Dentz
2026-09-09 19:23 ` [PATCH BlueZ v1 04/12] client: add A2DP endpoint registration scripts Luiz Augusto von Dentz
2026-09-09 19:23 ` [PATCH BlueZ v1 05/12] test: functional: add A2DP tests Luiz Augusto von Dentz
2026-09-09 19:23 ` [PATCH BlueZ v1 06/12] client: rename media endpoint scripts to include the codec Luiz Augusto von Dentz
2026-09-09 19:23 ` [PATCH BlueZ v1 07/12] client: add BAP endpoint registration scripts Luiz Augusto von Dentz
2026-09-09 19:23 ` [PATCH BlueZ v1 08/12] doc: bluetoothctl: document init script option and scripts Luiz Augusto von Dentz
2026-09-09 19:23 ` [PATCH BlueZ v1 09/12] test: functional: add BAP unicast tests Luiz Augusto von Dentz
2026-09-09 19:23 ` [PATCH BlueZ v1 10/12] test: functional: add BAP broadcast tests Luiz Augusto von Dentz
2026-09-09 19:23 ` Luiz Augusto von Dentz [this message]
2026-09-09 19:23 ` [PATCH BlueZ v1 12/12] bap: reuse the PA sync established to discover a Broadcast Source Luiz Augusto von Dentz
2026-09-10 20:50 ` [PATCH BlueZ v1 00/12] Add functional tests for A2DP and BAP 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=20260909192308.1306567-12-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.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.