Linux bluetooth development
 help / color / mirror / Atom feed
From: Simon Mikuda <simon.mikuda@streamunlimited.com>
To: linux-bluetooth@vger.kernel.org
Cc: Michal Dzik <michal.dzik@streamunlimited.com>,
	Marcel Holtmann <marcel@holtmann.org>,
	Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
	Simon Mikuda <simon.mikuda@streamunlimited.com>
Subject: [PATCH v2 2/3] Bluetooth: hci_conn: Terminate a BIG before its periodic advertising
Date: Tue, 24 Nov 2026 12:40:09 +0100	[thread overview]
Message-ID: <20261124114010.1696510-2-simon.mikuda@streamunlimited.com> (raw)
In-Reply-To: <20261124114010.1696510-1-simon.mikuda@streamunlimited.com>

From: Michal Dzik <michal.dzik@streamunlimited.com>

terminate_big_sync() disables the periodic advertising of a broadcast
source and removes its advertising set first, and only then terminates
the BIG: the same order in which they are created rather than the
reverse. Every BIG has an associated periodic advertising train, which
carries its BIGInfo ([Vol 6] Part B, Section 4.4.6.9), and the BIG
exists until the controller reports HCI_LE_Terminate_BIG_Complete
([Vol 4] Part E, Section 7.8.105), so removing the set first leaves a
BIG without its train.

Steps to reproduce, with btmon running: open an ISO socket for a BIS
with BT_ISO_QOS and BT_ISO_BASE, connect() it, which creates a BIG
with that one BIS, and close() it 3 s later.

A Synaptics SYN43756 controller, with a 6.18.2 based vendor kernel,
answers LE Terminate BIG with a Command Status, then sends 2690 vendor
events instead of LE Terminate BIG Complete and answers no command
after that, in 5 of 5 runs:

  < HCI Command: LE Set Periodic Advertising Enable (0x08|0x0040)
          Periodic advertising: Disabled (0x00)
  > HCI Event: Command Complete (0x0e) plen 4
          Status: Success (0x00)
  < HCI Command: LE Set Extended Advertising Enable (0x08|0x0039)
          Extended advertising: Disabled (0x00)
  > HCI Event: Command Complete (0x0e) plen 4
          Status: Success (0x00)
  < HCI Command: LE Remove Advertising Set (0x08|0x003c)
  > HCI Event: Command Complete (0x0e) plen 4
          Status: Success (0x00)
  < HCI Command: LE Terminate Broadcast Isochronous Group (0x08|0x006a)
          BIG Handle: 0x01
  > HCI Event: Command Status (0x0f) plen 4
          Status: Success (0x00)
  > HCI Event: Vendor (0xff) plen 244

The Zephyr controller (on an nRF54L15), with a 7.3-rc2 based kernel,
does not remove the advertising set of a BIG, in 5 of 5 runs:

  < HCI Command: LE Remove Advertising Set (0x08|0x003c)
  > HCI Event: Command Complete (0x0e) plen 4
          Status: Command Disallowed (0x0c)
  < HCI Command: LE Terminate Broadcast Isochronous Group (0x08|0x006a)

  Bluetooth: hci1: Opcode 0x203c failed: -16

It terminates the BIG, but the advertising set stays in the controller
and as an advertising instance in the host.

Terminate the BIG first, and make hci_le_terminate_big_sync() wait for
HCI_LE_Terminate_BIG_Complete, as hci_disconnect_sync() waits for
HCI_Disconnection_Complete, before the advertising is disabled and
removed. A controller that does not send the event delays the teardown
by HCI_CMD_TIMEOUT, after which the advertising is disabled and removed
as before. hci_iso_term_big_sync(), which terminates a BIG created after
its BISes were closed, waits for the event too. The wait is in the
cmd_sync work, so the teardown of one BIG cannot interleave with the
creation of the next one on the same advertising set.

With that, both controllers send LE Terminate BIG Complete, and the
periodic advertising is disabled, the advertising disabled and the set
removed after it, all with Success, in 5 of 5 runs with each.

Fixes: eca0ae4aea66 ("Bluetooth: Add initial implementation of BIS connections")
Signed-off-by: Michal Dzik <michal.dzik@streamunlimited.com>
Signed-off-by: Simon Mikuda <simon.mikuda@streamunlimited.com>
---
 include/net/bluetooth/hci.h |  2 ++
 net/bluetooth/hci_conn.c    | 17 +++++++++++------
 net/bluetooth/hci_sync.c    |  9 +++++++--
 3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index efb85c781e4e..7dd968ca25ec 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -3335,6 +3335,8 @@ struct hci_evt_le_create_big_complete {
 	__le16  bis_handle[];
 } __packed;
 
+#define HCI_EVT_LE_TERM_BIG_COMPLETE	0x1c
+
 #define HCI_EVT_LE_BIG_SYNC_ESTABLISHED 0x1d
 struct hci_evt_le_big_sync_established {
 	__u8    status;
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 9fa8dab2520e..5b7526a85442 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -769,18 +769,23 @@ static void bis_list(struct hci_conn *conn, void *data)
 static int terminate_big_sync(struct hci_dev *hdev, void *data)
 {
 	struct iso_list_data *d = data;
+	int err = 0;
 
 	bt_dev_dbg(hdev, "big 0x%2.2x bis 0x%2.2x", d->big, d->bis);
 
+	/* Only terminate BIG if it has been created. Terminate it before the
+	 * periodic advertising that carries its BIGInfo, in the reverse order
+	 * of creating them: some controllers fail to terminate a BIG whose
+	 * advertising set has already been removed.
+	 */
+	if (d->big_term)
+		err = hci_le_terminate_big_sync(hdev, d->big,
+						HCI_ERROR_LOCAL_HOST_TERM);
+
 	hci_disable_per_advertising_sync(hdev, d->bis);
 	hci_remove_ext_adv_instance_sync(hdev, d->bis, NULL);
 
-	/* Only terminate BIG if it has been created */
-	if (!d->big_term)
-		return 0;
-
-	return hci_le_terminate_big_sync(hdev, d->big,
-					 HCI_ERROR_LOCAL_HOST_TERM);
+	return err;
 }
 
 static void terminate_big_destroy(struct hci_dev *hdev, void *data, int err)
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 2e88af51b8f3..83e59ba2a45b 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -2320,8 +2320,13 @@ int hci_le_terminate_big_sync(struct hci_dev *hdev, u8 handle, u8 reason)
 	cp.handle = handle;
 	cp.reason = reason;
 
-	return __hci_cmd_sync_status(hdev, HCI_OP_LE_TERM_BIG,
-				     sizeof(cp), &cp, HCI_CMD_TIMEOUT);
+	/* Wait for HCI_LE_Terminate_BIG_Complete, so the periodic advertising
+	 * of the BIG is not disabled while the BIG is still being terminated.
+	 */
+	return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_TERM_BIG,
+					sizeof(cp), &cp,
+					HCI_EVT_LE_TERM_BIG_COMPLETE,
+					HCI_CMD_TIMEOUT, NULL);
 }
 
 int hci_schedule_adv_instance_sync(struct hci_dev *hdev, u8 instance,
-- 
2.43.0


  reply	other threads:[~2026-11-24 11:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 11:40 [PATCH v2 1/3] Bluetooth: hci_conn: Fix BIG cleanup while BISes are still bound Simon Mikuda
2026-11-24 11:40 ` Simon Mikuda [this message]
2026-11-24 11:40 ` [PATCH v2 3/3] Bluetooth: hci_sync: Fix closing all BISes while their BIG is created Simon Mikuda
2026-11-24 17:20 ` [PATCH v2 1/3] Bluetooth: hci_conn: Fix BIG cleanup while BISes are still bound 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=20261124114010.1696510-2-simon.mikuda@streamunlimited.com \
    --to=simon.mikuda@streamunlimited.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    --cc=michal.dzik@streamunlimited.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox