Skip to contentSkip to conversation

emulator: Generate PA Sync Lost

PATCH Applied Luiz Augusto von Dentz 3 participants 7 messages Nov 7, 2025 – Nov 10, 2025 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH v3 1/5 emulator: Generate PA Sync Lost

From: Luiz Augusto von Dentz <[email protected]>

This attempts to generate a PA Sync Lost whenever a PA is disabled and there is a remote synced to it.

---
 emulator/btdev.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
emulator/btdev.c +30 -1
index 839b4941ca05..5632a822240a 100644
@@ -116,10 +116,12 @@ struct le_ext_adv {
 
 struct le_per_adv {
 	struct btdev *dev;
+	struct btdev *remote;
 	uint8_t addr_type;
 	uint8_t addr[6];
 	uint8_t sid;
 	uint16_t sync_handle;
+	struct queue *syncs;
 };
 
 struct le_big {
@@ -5514,6 +5516,7 @@ static void le_pa_sync_estabilished(struct btdev *dev, struct btdev *remote,
 		sync_handle++;
 
 	per_adv->sync_handle = sync_handle;
+	per_adv->remote = remote;
 
 	ev.handle = cpu_to_le16(per_adv->sync_handle);
 	ev.sid = per_adv->sid;
@@ -5527,6 +5530,24 @@ static void le_pa_sync_estabilished(struct btdev *dev, struct btdev *remote,
 	send_pa(dev, remote, 0, per_adv->sync_handle);
 }
 
+static void le_pa_sync_lost(struct le_per_adv *pa)
+{
+	struct bt_hci_evt_le_per_sync_lost ev;
+
+	memset(&ev, 0, sizeof(ev));
+	ev.handle = cpu_to_le16(pa->sync_handle);
+	le_meta_event(pa->dev, BT_HCI_EVT_LE_PA_SYNC_LOST, &ev, sizeof(ev));
+	free(pa);
+}
+
+static bool match_remote(const void *data, const void *match_data)
+{
+	const struct le_per_adv *pa = data;
+	const struct btdev *remote = match_data;
+
+	return pa->remote == remote;
+}
+
 static int cmd_set_pa_enable(struct btdev *dev, const void *data, uint8_t len)
 {
 	const struct bt_hci_cmd_le_set_pa_enable *cmd = data;
@@ -5549,11 +5570,19 @@ static int cmd_set_pa_enable(struct btdev *dev, const void *data, uint8_t len)
 		if (!remote || remote == dev)
 			continue;
 
-		if (remote->le_scan_enable &&
+		if (dev->le_scan_enable &&
 			queue_find(remote->le_per_adv, match_sync_handle,
 			UINT_TO_PTR(INV_HANDLE)))
 			le_pa_sync_estabilished(remote, dev,
 							BT_HCI_ERR_SUCCESS);
+		else if (!dev->le_pa_enable) {
+			struct le_per_adv *pa;
+
+			pa = queue_remove_if(remote->le_per_adv, match_remote,
+						dev);
+			if (pa)
+				le_pa_sync_lost(pa);
+		}
 	}
 
 	return 0;
Signature · 1 line
2.51.1
author maintainer
#1 lore raw

PATCH v3 2/5 bthost: Add support for terminating a BIG

From: Luiz Augusto von Dentz <[email protected]>

This adds support for sending BT_HCI_CMD_LE_TERM_BIG via bthost_terminate_big.

---
 emulator/bthost.c | 11 +++++++++++
 emulator/bthost.h |  1 +
 2 files changed, 12 insertions(+)
emulator/bthost.c +11 -0
index faabbaa36a4a..9f9538d0dc2c 100644
@@ -3780,6 +3780,17 @@ void bthost_create_big(struct bthost *bthost, uint8_t num_bis,
 	send_command(bthost, BT_HCI_CMD_LE_CREATE_BIG, &cp, sizeof(cp));
 }
 
+void bthost_terminate_big(struct bthost *bthost, uint8_t reason)
+{
+	struct bt_hci_cmd_le_term_big cp;
+
+	memset(&cp, 0, sizeof(cp));
+	cp.handle = 0x01;
+	cp.reason = reason;
+
+	send_command(bthost, BT_HCI_CMD_LE_TERM_BIG, &cp, sizeof(cp));
+}
+
 bool bthost_search_ext_adv_addr(struct bthost *bthost, const uint8_t *addr)
 {
 	const struct queue_entry *entry;
emulator/bthost.h +1 -0
index 4061c0be5349..ce6bd820fefe 100644
@@ -128,6 +128,7 @@ void bthost_set_pa_enable(struct bthost *bthost, uint8_t enable);
 void bthost_past_set_info(struct bthost *bthost, uint16_t handle);
 void bthost_create_big(struct bthost *bthost, uint8_t num_bis, uint8_t enc,
 				const uint8_t *bcode);
+void bthost_terminate_big(struct bthost *bthost, uint8_t reason);
 bool bthost_search_ext_adv_addr(struct bthost *bthost, const uint8_t *addr);
 
 void bthost_set_cig_params(struct bthost *bthost, uint8_t cig_id,
Signature · 1 line
2.51.1
author maintainer
#2 lore raw

PATCH v3 3/5 iso-tester: Add tests for checking proper handling of Sync Lost

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This introduces the following tests to check if BIG/PA Sync Lost are handled properly:

ISO Broadcaster Receiver Sync Lost - Success
ISO Broadcaster PAST Receiver Sync Lost - Success

---
 tools/iso-tester.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
tools/iso-tester.c +49 -0
index 4bf1a287bc68..ff5c85ae410c 100644
@@ -502,6 +502,7 @@ struct iso_client_data {
 	bool listen_bind;
 	bool pa_bind;
 	bool big;
+	bool terminate;
 
 	/* Enable BT_PKT_SEQNUM for RX packet sequence numbers */
 	bool pkt_seqnum;
@@ -1578,6 +1579,27 @@ static const struct iso_client_data bcast_16_2_1_recv_defer_get_base = {
 	.base_len = sizeof(base_lc3_ac_12),
 };
 
+static const struct iso_client_data bcast_16_2_1_recv_terminate = {
+	.qos = QOS_IN_16_2_1,
+	.expect_err = 0,
+	.recv = &send_16_2_1,
+	.bcast = true,
+	.server = true,
+	.big = true,
+	.terminate = true,
+};
+
+static const struct iso_client_data past_16_2_1_recv_terminate = {
+	.qos = QOS_IN_16_2_1,
+	.expect_err = 0,
+	.recv = &send_16_2_1,
+	.bcast = true,
+	.past = true,
+	.server = true,
+	.big = true,
+	.terminate = true,
+};
+
 static const struct iso_client_data bcast_ac_12 = {
 	.qos = BCAST_AC_12,
 	.expect_err = 0,
@@ -2389,6 +2411,21 @@ static void iso_shutdown(struct test_data *data, GIOChannel *io)
 	tester_print("Disconnecting...");
 }
 
+static void iso_terminate(struct test_data *data, GIOChannel *io)
+{
+	struct bthost *host;
+
+	/* Setup watcher to check if fd is closed properly after termination */
+	data->io_id[0] = g_io_add_watch(io, G_IO_HUP, iso_disconnected, data);
+
+	tester_print("Terminating...");
+
+	host = hciemu_client_get_host(data->hciemu);
+
+	bthost_set_pa_enable(host, 0x00);
+	bthost_terminate_big(host, BT_HCI_ERR_LOCAL_HOST_TERM);
+}
+
 static gboolean iso_recv_data(GIOChannel *io, GIOCondition cond,
 							gpointer user_data)
 {
@@ -2498,6 +2535,8 @@ static gboolean iso_recv_data(GIOChannel *io, GIOCondition cond,
 		return TRUE;
 	else if (isodata->disconnect)
 		iso_shutdown(data, io);
+	else if (isodata->terminate)
+		iso_terminate(data, io);
 	else
 		tester_test_passed();
 
@@ -4311,6 +4350,16 @@ int main(int argc, char *argv[])
 					setup_powered,
 					test_bcast_recv);
 
+	test_iso("ISO Broadcaster Receiver Sync Lost - Success",
+					&bcast_16_2_1_recv_terminate,
+					setup_powered,
+					test_bcast_recv);
+
+	test_iso("ISO Broadcaster PAST Receiver Sync Lost - Success",
+					&past_16_2_1_recv_terminate,
+					setup_powered,
+					test_bcast_recv);
+
 	test_iso("ISO Broadcaster AC 12 - Success", &bcast_ac_12, setup_powered,
 							test_bcast);
 
Signature · 1 line
2.51.1
author maintainer
#3 lore raw

PATCH v3 4/5 bass: Fix not cleaning up delegator properly

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

When BIG sync is lost, or the assistant modify removing all streams, delegator should be freed to so the assistant can start over and share another stream.

---
 profiles/audio/bap.c  |  27 +++---
 profiles/audio/bass.c | 208 ++++++++++++++++++++++--------------------
 2 files changed, 126 insertions(+), 109 deletions(-)
profiles/audio/bap.c +16 -11
index c10f019edfea..0883f6c47902 100644
@@ -3270,14 +3270,6 @@ static void pac_removed_broadcast(struct bt_bap_pac *pac, void *user_data)
 	ep_unregister(ep);
 }
 
-static bool match_device(const void *data, const void *match_data)
-{
-	const struct bap_data *bdata = data;
-	const struct btd_device *device = match_data;
-
-	return bdata->device == device;
-}
-
 static struct bap_data *bap_data_new(struct btd_device *device)
 {
 	struct bap_data *data;
@@ -3673,6 +3665,14 @@ static int bap_bcast_probe(struct btd_service *service)
 	return 0;
 }
 
+static bool match_service(const void *data, const void *match_data)
+{
+	const struct bap_data *bdata = data;
+	const struct btd_service *service = match_data;
+
+	return bdata->service == service;
+}
+
 static void bap_bcast_remove(struct btd_service *service)
 {
 	struct btd_device *device = btd_service_get_device(service);
@@ -3682,7 +3682,10 @@ static void bap_bcast_remove(struct btd_service *service)
 	ba2str(device_get_address(device), addr);
 	DBG("%s", addr);
 
-	data = queue_find(sessions, match_device, device);
+	/* Lookup the bap session for this service since in case of
+	 * bass_delegator its user data is set by bass plugin.
+	 */
+	data = queue_find(sessions, match_service, service);
 	if (!data) {
 		error("BAP service not handled by profile");
 		return;
@@ -3791,10 +3794,12 @@ static int bap_disconnect(struct btd_service *service)
 
 static int bap_bcast_disconnect(struct btd_service *service)
 {
-	struct btd_device *device = btd_service_get_device(service);
 	struct bap_data *data;
 
-	data = queue_find(sessions, match_device, device);
+	/* Lookup the bap session for this service since in case of
+	 * bass_delegator its user data is set by bass plugin.
+	 */
+	data = queue_find(sessions, match_service, service);
 	if (!data) {
 		error("BAP service not handled by profile");
 		return -EINVAL;
profiles/audio/bass.c +110 -98

273 lines not on this page · raw message

Signature · 1 line
2.51.1
author maintainer
#4 lore raw

PATCH v3 5/5 btio: Fix endless loop if accept return -EBADFD

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

In certain cases, e.g. ISO Broadcast Listen, the listening socket may get into an invalid state (CONNECTED) if the PA Sync is terminated causing an endless loop of accept syscall.

---
 btio/btio.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
btio/btio.c +4 -1
index 1a34927b2353..cfaa9392de12 100644
@@ -253,8 +253,11 @@ static gboolean server_cb(GIOChannel *io, GIOCondition cond,
 	srv_sock = g_io_channel_unix_get_fd(io);
 
 	cli_sock = accept(srv_sock, NULL, NULL);
-	if (cli_sock < 0)
+	if (cli_sock < 0) {
+		if (errno == EBADFD)
+			return FALSE;
 		return TRUE;
+	}
 
 	cli_io = g_io_channel_unix_new(cli_sock);
 
Signature · 1 line
2.51.1
#5 lore raw
In reply to Luiz Augusto von Dentz

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/project/bluetooth/list/?series=1021075

---Test result---

Test Summary:

CheckPatch                    PENDING   0.36 seconds
GitLint                       PENDING   0.39 seconds
BuildEll                      PASS      17.98 seconds
BluezMake                     PASS      4072.92 seconds
MakeCheck                     PASS      19.82 seconds
MakeDistcheck                 PASS      172.58 seconds
CheckValgrind                 PASS      231.19 seconds
CheckSmatch                   WARNING   275.80 seconds
bluezmakeextell               PASS      121.99 seconds
IncrementalBuild              PENDING   0.37 seconds
ScanBuild                     PASS      833.82 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
emulator/btdev.c:461:29: warning: Variable length array is used.emulator/bthost.c:699:28: warning: Variable length array is used.emulator/bthost.c:700:32: warning: Variable length array is used.emulator/bthost.c:917:28: warning: Variable length array is used.emulator/bthost.c:951:28: warning: Variable length array is used.emulator/bthost.c:952:32: warning: Variable length array is used.
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:

---
Regards,
Linux Bluetooth

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

Hello:

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

Quoted 7 lines · On Fri, 7 Nov 2025 15:18:23 -0500 you wrote:

From: Luiz Augusto von Dentz <[email protected]>

This attempts to generate a PA Sync Lost whenever a PA is disabled and there is a remote synced to it.

---
 emulator/btdev.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

Here is the summary with links:
- [BlueZ,v3,1/5] emulator: Generate PA Sync Lost

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=ca70a0b7d58a
  - [BlueZ,v3,2/5] bthost: Add support for terminating a BIG
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=d9b71705bc40
  - [BlueZ,v3,3/5] iso-tester: Add tests for checking proper handling of Sync Lost
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=2c17c9929b62
  - [BlueZ,v3,4/5] bass: Fix not cleaning up delegator properly
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=1302116ea4b6
  - [BlueZ,v3,5/5] btio: Fix endless loop if accept return -EBADFD
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=51197aac2338

You are awesome, thank you!

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