Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH BlueZ] mesh: Fix Command Disallowed on random address change in generic IO
@ 2026-10-22 18:01 Aurélien Rivet
  2026-10-22 19:41 ` [BlueZ] " bluez.test.bot
  2026-10-23 22:20 ` [PATCH BlueZ] " patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Aurélien Rivet @ 2026-10-22 18:01 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: Luiz Augusto von Dentz, Luiz Augusto von Dentz,
	Aurélien Rivet

send_cancel_done() issues LE Set Random Address at the end of every
burst of ADVs. The controller rejects that command with Command
Disallowed (0x0c) while scanning is enabled, per Core Spec, Vol 4,
Part E, Section 7.8.4, so the address never rotates as long as any
scan is registered, such as a provisioner discovering unprovisioned
devices.

Pause scanning around the address change and resume it afterwards,
mirroring the disable/re-enable sequence restart_scan() already uses.
When no scan is registered there is nothing to pause, so the address
change is issued directly.

Confirmed with btmon on a Raspberry Pi built-in controller: over a
60 s capture, 12 rotations about 5 s apart, each one LE Set Scan
Enable(disable) -> LE Set Random Address -> LE Set Scan
Enable(enable), every command completing with Success and every
rotation programming a distinct address. No Command Disallowed
anywhere in the capture, where the address change previously failed
on every attempt. Scanning is suspended for 1.2 ms to 2.6 ms per
rotation, which mesh retransmissions absorb.

Assisted-by: Claude:claude-sonnet-5
Assisted-by: Claude:claude-opus-5
---

Third submission. The first two (2026-09-14, 2026-09-30) were archived
by the CI bot after two weeks with no review. Both were sent without
the [PATCH BlueZ] subject prefix required by HACKING rule 6, which may
be why they were missed; this one carries it.

The patch itself is unchanged, rebased onto current master.
 mesh/mesh-io-generic.c | 68 ++++++++++++++++++++++++++++++++++++++----
 1 file changed, 62 insertions(+), 6 deletions(-)

diff --git a/mesh/mesh-io-generic.c b/mesh/mesh-io-generic.c
index df1450ebe..7f65ec4f2 100644
--- a/mesh/mesh-io-generic.c
+++ b/mesh/mesh-io-generic.c
@@ -39,6 +39,7 @@ struct mesh_io_private {
 	struct tx_pkt *tx;
 	uint16_t interval;
 	bool sending;
+	bool scan_paused;
 	bool active;
 };
 
@@ -454,22 +455,77 @@ static bool dev_caps(struct mesh_io *io, struct mesh_io_caps *caps)
 	return true;
 }
 
-static void send_cancel_done(const void *buf, uint8_t size,
+static void set_random_address_rsp(const void *buf, uint8_t size,
 							void *user_data)
 {
 	struct mesh_io_private *pvt = user_data;
-	struct bt_hci_cmd_le_set_random_address cmd;
+	uint8_t status = *((uint8_t *) buf);
 
-	if (!pvt)
+	if (status)
+		l_error("LE Set Random Address failed (0x%02x)", status);
+
+	if (!pvt->scan_paused)
 		return;
 
-	pvt->sending = false;
+	pvt->scan_paused = false;
+
+	/* Only resume if a scan is still wanted: recv_deregister() may have
+	 * stopped it while the address change was in flight.
+	 */
+	if (!l_queue_isempty(pvt->io->rx_regs))
+		set_recv_scan_enable(NULL, 0, pvt);
+}
+
+static void send_set_random_address(struct mesh_io_private *pvt)
+{
+	struct bt_hci_cmd_le_set_random_address cmd;
 
-	/* At end of any burst of ADVs, change random address */
 	l_getrandom(cmd.addr, 6);
 	cmd.addr[5] |= 0xc0;
 	bt_hci_send(pvt->hci, BT_HCI_CMD_LE_SET_RANDOM_ADDRESS,
-				&cmd, sizeof(cmd), NULL, NULL, NULL);
+				&cmd, sizeof(cmd), set_random_address_rsp,
+				pvt, NULL);
+}
+
+static void scan_disable_for_addr_change_rsp(const void *buf, uint8_t size,
+							void *user_data)
+{
+	struct mesh_io_private *pvt = user_data;
+	uint8_t status = *((uint8_t *) buf);
+
+	if (status)
+		l_error("LE Scan disable failed (0x%02x)", status);
+
+	send_set_random_address(pvt);
+}
+
+static void send_cancel_done(const void *buf, uint8_t size,
+							void *user_data)
+{
+	struct mesh_io_private *pvt = user_data;
+	struct bt_hci_cmd_le_set_scan_enable cmd;
+
+	if (!pvt)
+		return;
+
+	pvt->sending = false;
+
+	/* At end of any burst of ADVs, change random address. The controller
+	 * rejects LE Set Random Address with Command Disallowed while
+	 * scanning is enabled (Core Spec, Vol 4, Part E, Section 7.8.4).
+	 */
+	pvt->scan_paused = !l_queue_isempty(pvt->io->rx_regs);
+
+	if (!pvt->scan_paused) {
+		send_set_random_address(pvt);
+		return;
+	}
+
+	cmd.enable = 0x00;	/* Disable scanning */
+	cmd.filter_dup = 0x00;	/* Report duplicates */
+	bt_hci_send(pvt->hci, BT_HCI_CMD_LE_SET_SCAN_ENABLE,
+				&cmd, sizeof(cmd),
+				scan_disable_for_addr_change_rsp, pvt, NULL);
 }
 
 static void send_cancel(struct mesh_io_private *pvt)
-- 
2.56.0


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

* RE: [BlueZ] mesh: Fix Command Disallowed on random address change in generic IO
  2026-10-22 18:01 [PATCH BlueZ] mesh: Fix Command Disallowed on random address change in generic IO Aurélien Rivet
@ 2026-10-22 19:41 ` bluez.test.bot
  2026-10-23 22:20 ` [PATCH BlueZ] " patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2026-10-22 19:41 UTC (permalink / raw)
  To: linux-bluetooth, aurelienrivet

[-- Attachment #1: Type: text/plain, Size: 3343 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1191507/

---Test result---

Test Summary:
CheckPatch                    PASS      0.47 seconds
GitLint                       PASS      0.29 seconds
BuildEll                      PASS      17.28 seconds
BluezMake                     PASS      248.29 seconds
MakeCheck                     PASS      0.77 seconds
MakeDistcheck                 PASS      119.46 seconds
CheckValgrind                 PASS      119.67 seconds
CheckSmatch                   PASS      199.74 seconds
bluezmakeextell               PASS      76.31 seconds
TestFunctional                FAIL      1023.54 seconds
IncrementalBuild              PASS      227.66 seconds
ScanBuild                     PASS      808.37 seconds

Details
##############################
Test: TestFunctional - FAIL
Desc: Run test-functional
Output:
FAIL functional.test_bap::test_bass_past_earbuds_transport_acquire[hosts10-vm3]: pytest_bluezenv.rpc.RemoteError: <pexpect.popen_spawn.PopenSpawn object at 0x7f85506b2a50>
    searcher: searcher_re:
        0: re.compile(b'Transport (/org/bluez/\\S+/bis2/fd\\d+)')
    <pexpect.popen_spawn.PopenSpawn object at 0x7f85506b2a50>
    searcher: searcher_re:
        0: re.compile(b'Transport (/org/bluez/\\S+/bis2/fd\\d+)')
    Remote traceback:
        Traceback (most recent call last):
          File "/usr/local/lib/python3.14/dist-packages/pytest_bluezenv/../pytest_bluezenv/rpc.py", line 102, in server_stream
            result = method(*msg["a"], **msg["kw"])
          File "/usr/local/lib/python3.14/dist-packages/pytest_bluezenv/../pytest_bluezenv/env.py", line 256, in call_plugin
            return getattr(self.plugins[name], method)(*a, **kw)
                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
          File "/usr/local/lib/python3.14/dist-packages/pytest_bluezenv/../pytest_bluezenv/host_plugins.py", line 441, in expect
            ret = ctl.expect(*a, **kw)
          File "/usr/lib/python3/dist-packages/pexpect/spawnbase.py", line 354, in expect
            return self.expect_list(compiled_pattern_list,
                   ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
                    timeout, searchwindowsize, async_)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          File "/usr/lib/python3/dist-packages/pexpect/spawnbase.py", line 383, in expect_list
            return exp.expect_loop(timeout)
                   ~~~~~~~~~~~~~~~^^^^^^^^^
          File "/usr/lib/python3/dist-packages/pexpect/expect.py", line 181, in expect_loop
            return self.timeout(e)
                   ~~~~~~~~~~~~^^^
          File "/usr/lib/python3/dist-packages/pexpect/expect.py", line 144, in timeout
            raise exc
        pexpect.exceptions.TIMEOUT: <pexpect.popen_spawn.PopenSpawn object at 0x7f85506b2a50>
        searcher: searcher_re:
            0: re.compile(b'Transport (/org/bluez/\\S+/bis2/fd\\d+)')
        <pexpect.popen_spawn.PopenSpawn object at 0x7f85506b2a50>
        searcher: searcher_re:
            0: re.compile(b'Transport (/org/bluez/\\S+/bis2/fd\\d+)')


https://github.com/bluez/bluez/pull/2702

---
Regards,
Linux Bluetooth


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

* Re: [PATCH BlueZ] mesh: Fix Command Disallowed on random address change in generic IO
  2026-10-22 18:01 [PATCH BlueZ] mesh: Fix Command Disallowed on random address change in generic IO Aurélien Rivet
  2026-10-22 19:41 ` [BlueZ] " bluez.test.bot
@ 2026-10-23 22:20 ` patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bluetooth @ 2026-10-23 22:20 UTC (permalink / raw)
  To: =?utf-8?q?Aur=C3=A9lien_Rivet_=3Caurelienrivet=40hotmail=2Efr=3E?=
  Cc: linux-bluetooth, luiz.von.dentz, luiz.dentz

Hello:

This patch was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Thu, 22 Oct 2026 18:01:26 +0000 you wrote:
> send_cancel_done() issues LE Set Random Address at the end of every
> burst of ADVs. The controller rejects that command with Command
> Disallowed (0x0c) while scanning is enabled, per Core Spec, Vol 4,
> Part E, Section 7.8.4, so the address never rotates as long as any
> scan is registered, such as a provisioner discovering unprovisioned
> devices.
> 
> [...]

Here is the summary with links:
  - [BlueZ] mesh: Fix Command Disallowed on random address change in generic IO
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=4de4f60f1e78

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2026-10-23 22:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-22 18:01 [PATCH BlueZ] mesh: Fix Command Disallowed on random address change in generic IO Aurélien Rivet
2026-10-22 19:41 ` [BlueZ] " bluez.test.bot
2026-10-23 22:20 ` [PATCH BlueZ] " 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