Skip to contentSkip to conversation

Bluetooth: hci_conn: Fix BIG cleanup while BISes are still bound

PATCH Applied Simon Mikuda 3 participants 6 messages Nov 24

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 Bluetooth: hci_conn: Fix BIG cleanup while BISes are still bound

When a broadcast source BIS is closed, bis_cleanup() calls hci_le_terminate_big() unless another BIS of that BIG is in BT_CONNECTED, BT_CONNECT or BT_OPEN. Until LE BIG Complete the BISes of a BIG are in BT_BOUND, so one that is closed in that time does not see the others, and the teardown is queued while they still wait to be connected. The BIG is not marked as created yet, so it is not
terminated: terminate_big_sync() only disables the periodic advertising and removes the advertising set the BIG is being created on. hci_le_create_big_complete() then connects the BISes that are still bound, in a BIG that has lost its advertising.

Steps to reproduce, with btmon running:

1. 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. That connect() sends LE Create BIG.
2. close() the second socket right after its connect().
3. Keep the first socket open for 12 s and scan for broadcast sources with another device in that time.

With the Zephyr controller (on an nRF54L15) and a 7.3-rc2 based kernel:

< HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068)

Quoted 1 line

HCI Event: Command Status (0x0f) plen 4

          Status: Success (0x00)
  < HCI Command: LE Set Periodic Advertising Enable (0x08|0x0040)
          Periodic advertising: Disabled (0x00)
Quoted 1 line

HCI Event: Command Complete (0x0e) plen 4

          Status: Success (0x00)
  < HCI Command: LE Set Extended Advertising Enable (0x08|0x0039)
          Extended advertising: Disabled (0x00)
Quoted 1 line

HCI Event: Command Complete (0x0e) plen 4

          Status: Success (0x00)

< HCI Command: LE Remove Advertising Set (0x08|0x003c)

Quoted 1 line

HCI Event: Command Complete (0x0e) plen 4

          Status: Command Disallowed (0x0c)
Quoted 1 line

HCI Event: LE Meta Event (0x3e) plen 23

LE Broadcast Isochronous Group Complete (0x1b)
Status: Success (0x00)
Connection Handle #0: 16
Connection Handle #1: 17
< HCI Command: LE Setup Isochronous Data Path (0x08|0x006e)

          Handle: 16
Quoted 1 line

HCI Event: Command Complete (0x0e) plen 6

          Status: Success (0x00)

Bluetooth: hci1: Opcode 0x203c failed: -16

The first socket becomes writable, and LE Terminate BIG is sent only when it is closed, 11.8 s later. The scanning device did not find the broadcast in 5 of 5 runs.

A Synaptics SYN43756 controller, with a 6.18.2 based vendor kernel, answers LE Remove Advertising Set with Success. In 3 of 5 runs the BIS was connected as above, and when its socket was closed the controller answered LE Terminate BIG with a Command Status, then sent 2690 vendor events instead of LE Terminate BIG Complete and answered no command after that:

< HCI Command: LE Terminate Broadcast Isochronous Group (0x08|0x006a)

          BIG Handle: 0x01
Quoted 1 line

HCI Event: Command Status (0x0f) plen 4

          Status: Success (0x00)
Quoted 1 line

HCI Event: Vendor (0xff) plen 244

In the other 2 runs the set was removed before LE BIG Complete, which then never came, and the first socket was neither connected nor given an error.

hci_le_create_big_complete() connects every BIS in BT_BOUND, so count them as users of the BIG too. They were counted until the lookup of any BIS of the BIG was replaced with lookups by state. With that, neither controller gets an advertising command before the last BIS is closed, and the scanning device found the broadcast in 5 of 5 runs with each.

Fixes d36349ea73d8 ("Bluetooth: hci_conn: Fix running bis_cleanup for hci_conn->type PA_LINK")

---
Changes in v2:
- 1/3: controller named correctly: Synaptics, not Broadcom/Infineon
- 1/3: message corrected: the early cleanup does not terminate the BIG
- all: traces are hardware captures now, with steps to reproduce
- 2/3: vendor statement and event-handler paragraph dropped
- 2/3: unused struct hci_evt_le_term_big_complete dropped
- 3/3: Realtek claim removed, it was not reproduced

 net/bluetooth/hci_conn.c | 7 +++++++
 1 file changed, 7 insertions(+)
net/bluetooth/hci_conn.c +7 -0
index 0b76df1bc5fd..9fa8dab2520e 100644
@@ -939,6 +939,13 @@ static void bis_cleanup(struct hci_conn *conn)
 		if (bis)
 			return;
 
+		bis = hci_conn_hash_lookup_big_state(hdev,
+						     conn->iso_qos.bcast.big,
+						     BT_BOUND,
+						     HCI_ROLE_MASTER);
+		if (bis)
+			return;
+
 		hci_le_terminate_big(hdev, conn);
 	} else {
 		hci_le_big_terminate(hdev, conn);

base-commit: ffb95458a0f70dcab620eee0ecf5ef7750971b2f

Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 2/3 Bluetooth: hci_conn: Terminate a BIG before its periodic advertising

From: Michal Dzik <[email protected]>

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)
Quoted 1 line

HCI Event: Command Complete (0x0e) plen 4

          Status: Success (0x00)
  < HCI Command: LE Set Extended Advertising Enable (0x08|0x0039)
          Extended advertising: Disabled (0x00)
Quoted 1 line

HCI Event: Command Complete (0x0e) plen 4

          Status: Success (0x00)

< HCI Command: LE Remove Advertising Set (0x08|0x003c)

Quoted 1 line

HCI Event: Command Complete (0x0e) plen 4

          Status: Success (0x00)
  < HCI Command: LE Terminate Broadcast Isochronous Group (0x08|0x006a)
          BIG Handle: 0x01
Quoted 1 line

HCI Event: Command Status (0x0f) plen 4

          Status: Success (0x00)
Quoted 1 line

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)

Quoted 1 line

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")
---
 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(-)
include/net/bluetooth/hci.h +2 -0
index efb85c781e4e..7dd968ca25ec 100644
@@ -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;
net/bluetooth/hci_conn.c +11 -6
index 9fa8dab2520e..5b7526a85442 100644
@@ -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)
net/bluetooth/hci_sync.c +7 -2
index 2e88af51b8f3..83e59ba2a45b 100644
@@ -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,
Signature · 1 line
2.43.0
#2 lore raw

PATCH v2 3/3 Bluetooth: hci_sync: Fix closing all BISes while their BIG is created

In reply to Simon Mikuda

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)

Quoted 1 line

HCI Event: Command Status (0x0f) plen 4

          Status: Success (0x00)
  < HCI Command: LE Set Periodic Advertising Enable (0x08|0x0040)
          Periodic advertising: Disabled (0x00)
Quoted 1 line

HCI Event: Command Complete (0x0e) plen 4

          Status: Success (0x00)
  < HCI Command: LE Set Extended Advertising Enable (0x08|0x0039)
          Extended advertising: Disabled (0x00)
Quoted 1 line

HCI Event: Command Complete (0x0e) plen 4

          Status: Success (0x00)

< HCI Command: LE Remove Advertising Set (0x08|0x003c)

Quoted 1 line

HCI Event: Command Complete (0x0e) plen 4

          Status: Command Disallowed (0x0c)
Quoted 1 line

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")
---
 net/bluetooth/hci_event.c | 11 +++++++++++
 net/bluetooth/hci_sync.c  | 23 +++++++++++++++++++----
 2 files changed, 30 insertions(+), 4 deletions(-)
net/bluetooth/hci_event.c +11 -0
index b6c7f9a9f55a..25bf13a06179 100644
@@ -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,
net/bluetooth/hci_sync.c +19 -4
index 83e59ba2a45b..01a691269f37 100644
@@ -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)
Signature · 1 line
2.43.0
#3 lore raw
In reply to Simon Mikuda
This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 11 lines · On Tue, 24 Nov 2026 12:40:08 +0100 you wrote:

When a broadcast source BIS is closed, bis_cleanup() calls hci_le_terminate_big() unless another BIS of that BIG is in BT_CONNECTED, BT_CONNECT or BT_OPEN. Until LE BIG Complete the BISes of a BIG are in BT_BOUND, so one that is closed in that time does not see the others, and the teardown is queued while they still wait to be connected. The BIG is not marked as created yet, so it is not
terminated: terminate_big_sync() only disables the periodic advertising and removes the advertising set the BIG is being created on. hci_le_create_big_complete() then connects the BISes that are still bound, in a BIG that has lost its advertising.

Quoted 1 line

[...]

Here is the summary with links:
- [v2,1/3] Bluetooth: hci_conn: Fix BIG cleanup while BISes are still bound

    https://git.kernel.org/bluetooth/bluetooth-next/c/a803233ce7a0
  - [v2,2/3] Bluetooth: hci_conn: Terminate a BIG before its periodic advertising
    https://git.kernel.org/bluetooth/bluetooth-next/c/8b55108e8ebf

- [v2,3/3] Bluetooth: hci_sync: Fix closing all BISes while their BIG is created (no matching commit)

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#4 lore raw
In reply to Simon Mikuda

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/1220748/

---Test result---

Test Summary:

CheckPatch                    PASS      2.96 seconds
VerifyFixes                   PASS      0.12 seconds
VerifySignedoff               PASS      0.12 seconds
GitLint                       PASS      0.98 seconds
SubjectPrefix                 PASS      0.35 seconds
BuildKernel                   PASS      31.51 seconds
CheckAllWarning               PASS      35.75 seconds
CheckSparse                   WARNING   39.03 seconds
BuildKernel32                 PASS      31.16 seconds
CheckKernelLLVM               PASS      33.34 seconds
TestRunnerSetup               PASS      764.88 seconds
TestRunner_l2cap-tester       PASS      14.83 seconds
TestRunner_iso-tester         PASS      17.50 seconds
TestRunner_bnep-tester        PASS      3.22 seconds
TestRunner_mgmt-tester        PASS      89.27 seconds
TestRunner_rfcomm-tester      PASS      4.61 seconds
TestRunner_sco-tester         PASS      5.72 seconds
TestRunner_ioctl-tester       PASS      4.71 seconds
TestRunner_mesh-tester        PASS      4.58 seconds
TestRunner_smp-tester         PASS      4.45 seconds
TestRunner_userchan-tester    PASS      3.28 seconds
TestRunner_6lowpan-tester     PASS      4.50 seconds
IncrementalBuild              FAIL      32.57 seconds

Details
##############################
Test: CheckSparse - WARNING
Desc: Run sparse tool with linux kernel
Output:
net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
##############################
Test: IncrementalBuild - FAIL
Desc: Incremental build with the patches in the series
Output:

error: patch failed: include/net/bluetooth/hci.h:3335
error: include/net/bluetooth/hci.h: patch does not apply
error: patch failed: net/bluetooth/hci_conn.c:769
error: net/bluetooth/hci_conn.c: patch does not apply
error: patch failed: net/bluetooth/hci_sync.c:2320
error: net/bluetooth/hci_sync.c: patch does not apply
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"

https://github.com/bluez/bluetooth-next/pull/1215

---
Regards,
Linux Bluetooth

#5 lore raw
In reply to Simon Mikuda
This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 11 lines · On Tue, 24 Nov 2026 12:40:08 +0100 you wrote:

When a broadcast source BIS is closed, bis_cleanup() calls hci_le_terminate_big() unless another BIS of that BIG is in BT_CONNECTED, BT_CONNECT or BT_OPEN. Until LE BIG Complete the BISes of a BIG are in BT_BOUND, so one that is closed in that time does not see the others, and the teardown is queued while they still wait to be connected. The BIG is not marked as created yet, so it is not
terminated: terminate_big_sync() only disables the periodic advertising and removes the advertising set the BIG is being created on. hci_le_create_big_complete() then connects the BISes that are still bound, in a BIG that has lost its advertising.

Quoted 1 line

[...]

Here is the summary with links:
- [v2,1/3] Bluetooth: hci_conn: Fix BIG cleanup while BISes are still bound (no matching commit)
- [v2,2/3] Bluetooth: hci_conn: Terminate a BIG before its periodic advertising (no matching commit)
- [v2,3/3] Bluetooth: hci_sync: Fix closing all BISes while their BIG is created

    https://git.kernel.org/bluetooth/bluetooth-next/c/e80ea455a2b9

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html