Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: hci_sync: Disable PA before removing an advertising set
@ 2026-11-27 21:34 Roland Schober
  2026-11-27 22:39 ` bluez.test.bot
  0 siblings, 1 reply; 2+ messages in thread
From: Roland Schober @ 2026-11-27 21:34 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: luiz.dentz, marcel, Roland Schober

The controller answers LE Remove Advertising Set and LE Clear Advertising
Sets with Command Disallowed while periodic advertising is enabled on
a set (Core specification, Vol 4, Part E, 7.8.59 and 7.8.60). Both are
sent without disabling periodic advertising first.

A BIG is the one user of periodic advertising so far. Its own removal
disables periodic advertising, but powering the controller off does not:
hci_power_off_sync() clears the advertising sets before the connections
are terminated, so with a BIG running the command fails and the power
off with it:

  Bluetooth: hci0: Opcode 0x203d failed: -16

  # btmgmt power off
  Set Powered for hci0 failed with status 0x0a (Busy)

The BlueZ emulator accepts both commands in that state, which is why no
tester shows it. With the emulator following the specification [1] the
BAP broadcast cases of test-functional fail, as the controller is power
cycled between two cases.

Disable periodic advertising in the removal itself, for one set in
hci_remove_ext_adv_instance_sync() and for all of them before LE Clear
Advertising Sets.

[1] https://patchwork.kernel.org/project/bluetooth/patch/20261127085525.264299-8-rolandschober1968@gmail.com/

Fixes: eca0ae4aea66 ("Bluetooth: Add initial implementation of BIS connections")
Assisted-by: Claude:claude-fable-5-2
Signed-off-by: Roland Schober <rolandschober1968@gmail.com>
---
 net/bluetooth/hci_sync.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index ee426ffeaa03..a1c723aad55e 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -2263,6 +2263,13 @@ int hci_remove_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance,
 	if (err)
 		return err;
 
+	/* The controller refuses to remove an advertising set which has
+	 * periodic advertising enabled.
+	 */
+	err = hci_disable_per_advertising_sync(hdev, instance);
+	if (err)
+		return err;
+
 	if (instance) {
 		hci_dev_lock(hdev);
 
@@ -2392,6 +2399,32 @@ int hci_schedule_adv_instance_sync(struct hci_dev *hdev, u8 instance,
 	return hci_start_adv_sync(hdev, instance);
 }
 
+/* The controller refuses to clear the advertising sets while one of them has
+ * periodic advertising enabled.
+ */
+static int hci_disable_per_advertising_all_sync(struct hci_dev *hdev)
+{
+	u8 instances[HCI_MAX_ADV_INSTANCES];
+	struct adv_info *adv;
+	u8 i, n = 0;
+	int err;
+
+	hci_dev_lock(hdev);
+	list_for_each_entry(adv, &hdev->adv_instances, list) {
+		if (adv->periodic_enabled && n < ARRAY_SIZE(instances))
+			instances[n++] = adv->instance;
+	}
+	hci_dev_unlock(hdev);
+
+	for (i = 0; i < n; i++) {
+		err = hci_disable_per_advertising_sync(hdev, instances[i]);
+		if (err)
+			return err;
+	}
+
+	return 0;
+}
+
 static int hci_clear_adv_sets_sync(struct hci_dev *hdev, struct sock *sk)
 {
 	int err;
@@ -2404,6 +2437,10 @@ static int hci_clear_adv_sets_sync(struct hci_dev *hdev, struct sock *sk)
 	if (err)
 		return err;
 
+	err = hci_disable_per_advertising_all_sync(hdev);
+	if (err)
+		return err;
+
 	return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CLEAR_ADV_SETS,
 					0, NULL, 0, HCI_CMD_TIMEOUT, sk);
 }

base-commit: f57f78086ab54f3b3122fbaeba2c842ba7bb6d00
-- 
2.47.3


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

end of thread, other threads:[~2026-11-27 22:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 21:34 [PATCH] Bluetooth: hci_sync: Disable PA before removing an advertising set Roland Schober
2026-11-27 22:39 ` bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox