Linux bluetooth development
 help / color / mirror / Atom feed
From: Simon Mikuda <simon.mikuda@streamunlimited.com>
To: linux-bluetooth@vger.kernel.org
Cc: Simon Mikuda <simon.mikuda@streamunlimited.com>,
	Marcel Holtmann <marcel@holtmann.org>,
	Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Subject: [PATCH v2 3/3] Bluetooth: hci_sync: Fix closing all BISes while their BIG is created
Date: Tue, 24 Nov 2026 12:40:10 +0100	[thread overview]
Message-ID: <20261124114010.1696510-3-simon.mikuda@streamunlimited.com> (raw)
In-Reply-To: <20261124114010.1696510-1-simon.mikuda@streamunlimited.com>

LE Create BIG does not wait for LE BIG Complete. If all BIS sockets of
the BIG are closed in between, their BISes are still bound and the BIG
is not marked as created, so the cleanup of the last one disables the
periodic advertising and removes the advertising set the BIG is being
created on. The BIG is terminated only afterwards, when LE BIG Complete
finds no BIS for it.

Steps to reproduce, with btmon running: open two ISO sockets for one
BIG as BlueZ does (BT_ISO_QOS and BT_ISO_BASE on both, BT_DEFER_SETUP
on the first, then connect() both, the second one non-blocking, which
sends LE Create BIG) and close() both right after that connect().

With the Zephyr controller (on an nRF54L15) and a 7.3-rc2 based kernel,
in 5 of 5 runs:

  < HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068)
  > HCI Event: Command Status (0x0f) plen 4
          Status: Success (0x00)
  < 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: Command Disallowed (0x0c)
  > HCI Event: LE Meta Event (0x3e) plen 23
        LE Broadcast Isochronous Group Complete (0x1b)
          Status: Success (0x00)
  < HCI Command: LE Terminate Broadcast Isochronous Group (0x08|0x006a)

  Bluetooth: hci1: Opcode 0x203c failed: -16

The BIG is terminated, but the advertising set stays in the controller
and as an advertising instance in the host.

With a Synaptics SYN43756 controller and a 6.18.2 based vendor kernel,
LE BIG Complete came 2 to 66 ms after LE Create BIG and the cleanup
started 43 to 55 ms after the command, so there the order depends on
timing: 5 of 10 runs went wrong. In 4 of them the set was removed
first, with Success. LE BIG Complete then never came, and the next LE
Create BIG with that BIG handle got Command Disallowed. In the fifth,
LE BIG Complete arrived during the cleanup; the controller answered the
LE Terminate BIG that followed the removal of the set with a Command
Status, then sent 2690 vendor events instead of LE Terminate BIG
Complete and answered no command after that.

Wait for LE BIG Complete, or LE Create BIG Complete v2 on an HDT capable
controller, for up to conn->conn_timeout, as LE Create CIS waits for LE
CIS Established. Delete a BIS closed meanwhile as one of a created BIG, so
that the last one terminates the BIG first.

Both test kernels lack hci_le_create_big_sync() and send LE Create BIG
from hci_le_create_big() in hci_conn.c, so the same wait was tested
there, and LE Create BIG v2 was not run on either controller. With the
wait, both controllers get LE Terminate BIG after LE BIG Complete, and
the periodic advertising is disabled, the advertising disabled and the
set removed after LE Terminate BIG Complete, all with Success: 5 of 5
runs with Zephyr, 15 of 15 with the Synaptics controller. In these runs
one of the two BISes is connected at LE BIG Complete and gets LE Setup
ISO Data Path before LE Terminate BIG.

Fixes: eca0ae4aea66 ("Bluetooth: Add initial implementation of BIS connections")
Signed-off-by: Simon Mikuda <simon.mikuda@streamunlimited.com>
---
 net/bluetooth/hci_event.c | 11 +++++++++++
 net/bluetooth/hci_sync.c  | 23 +++++++++++++++++++----
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index b6c7f9a9f55a..25bf13a06179 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -7894,6 +7894,17 @@ static void hci_le_create_big_complete(struct hci_dev *hdev, u8 status,
 			continue;
 		}
 
+		/* A BIS closed during LE Create BIG is still bound. Delete it
+		 * now, so that the last one terminates the BIG first.
+		 */
+		if (conn->abort_reason) {
+			i++;
+			set_bit(HCI_CONN_BIG_CREATED, conn->flags);
+			hci_connect_cfm(conn, conn->abort_reason);
+			hci_conn_del(conn);
+			continue;
+		}
+
 		if (hci_conn_set_handle(conn,
 					__le16_to_cpu(bis_handle[i++]))) {
 			bt_dev_err(hdev,
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 83e59ba2a45b..01a691269f37 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -8998,8 +8998,15 @@ static int hci_le_create_big_v2_sync(struct hci_conn *conn,
 		cp.bis.hdt_rates = cpu_to_le16(qos->bcast.out.rates ? :
 					       hci_hdt_tx_rates(hdev));
 
-	return __hci_cmd_sync_status(hdev, HCI_OP_LE_CREATE_BIG_V2,
-				     sizeof(cp), &cp, HCI_CMD_TIMEOUT);
+	/* Wait for LE BIG Complete, so that the cleanup of BISes closed
+	 * meanwhile terminates the BIG before removing its advertising set.
+	 * An HDT capable controller reports it with LE Create BIG Complete v2,
+	 * which hci_le_set_event_mask_sync() unmasks for it.
+	 */
+	return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CREATE_BIG_V2,
+					sizeof(cp), &cp,
+					HCI_EVT_LE_CREATE_BIG_COMPLETE_V2,
+					conn->conn_timeout, NULL);
 }
 
 int hci_le_create_big_sync(struct hci_conn *conn, struct bt_iso_qos_ext *qos,
@@ -9025,8 +9032,16 @@ int hci_le_create_big_sync(struct hci_conn *conn, struct bt_iso_qos_ext *qos,
 	cp.bis.encryption = qos->bcast.encryption;
 	memcpy(cp.bis.bcode, qos->bcast.bcode, sizeof(cp.bis.bcode));
 
-	return __hci_cmd_sync_status(hdev, HCI_OP_LE_CREATE_BIG,
-				     sizeof(cp), &cp, HCI_CMD_TIMEOUT);
+	/* Wait for LE BIG Complete, so that the cleanup of BISes closed
+	 * meanwhile terminates the BIG before removing its advertising set.
+	 * An HDT capable controller reports it with LE Create BIG Complete v2
+	 * even here, since that is the one unmasked.
+	 */
+	return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CREATE_BIG,
+					sizeof(cp), &cp, hdt_capable(hdev) ?
+					HCI_EVT_LE_CREATE_BIG_COMPLETE_V2 :
+					HCI_EVT_LE_CREATE_BIG_COMPLETE,
+					conn->conn_timeout, NULL);
 }
 
 static void le_enable_encrypt_complete(struct hci_dev *hdev, void *data, int err)
-- 
2.43.0


  parent 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 ` [PATCH v2 2/3] Bluetooth: hci_conn: Terminate a BIG before its periodic advertising Simon Mikuda
2026-11-24 11:40 ` Simon Mikuda [this message]
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-3-simon.mikuda@streamunlimited.com \
    --to=simon.mikuda@streamunlimited.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox