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 3/3] Bluetooth: hci_sync: Fix closing all BISes while their BIG is created
Date: Sun, 22 Nov 2026 21:13:50 +0100	[thread overview]
Message-ID: <20261122201351.2854661-3-simon.mikuda@streamunlimited.com> (raw)
In-Reply-To: <20261122201351.2854661-1-simon.mikuda@streamunlimited.com>

LE Create BIG does not wait for LE BIG Complete. If all BIS sockets close
in between, the cleanup removes the advertising set the BIG is being
created on and terminates the BIG only after that:

    < LE Create Broadcast Isochronous Group
    > Command Status: Success
    < LE Set Periodic Advertising Enable: Disabled
    > LE Broadcast Isochronous Group Complete: Success
    < LE Set Extended Advertising Enable: Disabled
    < LE Remove Advertising Set
    < LE Terminate Broadcast Isochronous Group

A Realtek controller then stops answering commands:

    Bluetooth: hci0: command 0x2039 tx timeout

Wait for LE BIG Complete, or LE Create BIG Complete v2 after LE Create
BIG v2, and delete a BIS closed meanwhile as one of a created BIG, so
that the last one terminates the BIG first.

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  | 20 ++++++++++++++++----
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index ab875b90a143..eeb27bf249ee 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -7881,6 +7881,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 bdb173440176..d6e0b0fe10b7 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -8962,8 +8962,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,
@@ -8989,8 +8996,13 @@ 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.
+	 */
+	return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CREATE_BIG,
+					sizeof(cp), &cp,
+					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-22 20:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22 20:13 [PATCH 1/3] Bluetooth: hci_conn: Fix BIG cleanup while BISes are still bound Simon Mikuda
2026-11-22 20:13 ` [PATCH 2/3] Bluetooth: hci_conn: Terminate a BIG before its periodic advertising Simon Mikuda
2026-11-22 20:13 ` Simon Mikuda [this message]
2026-11-22 22:55 ` [1/3] Bluetooth: hci_conn: Fix BIG cleanup while BISes are still bound bluez.test.bot

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=20261122201351.2854661-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