Skip to contentSkip to conversation

adapter: add DisableDiscoveryOnConnect option for combo chip coexistence

PATCH In review StefanCondorache 2 participants 3 messages Apr 18 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 adapter: add DisableDiscoveryOnConnect option for combo chip coexistence

On systems with combo chips (shared Wi-Fi/Bluetooth antenna), background LE scanning for auto-connect devices competes with active connections, causing audio stuttering and Wi-Fi packet loss due to antenna multiplexing via Packet Traffic Arbitration (PTA).

Add a DisableDiscoveryOnConnect boolean option to the [General] section of main.conf. When enabled and an active connection exists, the option suppresses adding devices to the kernel auto-connect list in adapter_auto_connect_add() on kernels supporting KERNEL_CONN_CONTROL, and gates trigger_passive_scanning() on older kernels.

The option defaults to false to preserve existing behavior.

---
 src/adapter.c | 24 ++++++++++++++++++++++++
 src/btd.h     |  2 ++
 src/main.c    |  4 ++++
 src/main.conf |  6 ++++++
 4 files changed, 36 insertions(+)
src/adapter.c +24 -0
index 6df66b3e0..4a18adfe0 100644
@@ -1594,6 +1594,18 @@ static void trigger_passive_scanning(struct btd_adapter *adapter)
 	if (!adapter->connect_list)
 		return;
 
+	/*
+	 * If the user has enabled DisableDiscoveryOnConnect, suppress
+	 * passive scanning whenever there is at least one active connection.
+	 * This prevents antenna multiplexing conflicts on combo chips where
+	 * Wi-Fi and Bluetooth share the same 2.4 GHz radio, which causes
+	 * audio drops and Wi-Fi packet loss during background scans.
+	 */
+	if (btd_opts.disable_discovery_on_connect && adapter->connections) {
+		DBG("suppress passive scan: active connection present");
+		return;
+	}
+
 	adapter->passive_scan_timeout = timeout_add_seconds(CONN_SCAN_TIMEOUT,
 					passive_scanning_timeout, adapter,
 					NULL);
@@ -5717,6 +5729,18 @@ void adapter_auto_connect_add(struct btd_adapter *adapter,
 		return;
 	}
 
+	/*
+	 * If DisableDiscoveryOnConnect is enabled, suppress adding devices
+	 * to the kernel auto-connect list while an active connection exists.
+	 * On combo chips (shared Wi-Fi/Bluetooth antenna), the kernel's
+	 * background scanning for auto-connect devices competes with active
+	 * connections, causing audio drops and Wi-Fi packet loss.
+	 */
+	if (btd_opts.disable_discovery_on_connect && adapter->connections) {
+		DBG("suppress kernel auto-connect: active connection present");
+		return;
+	}
+
 	bdaddr = device_get_address(device);
 	bdaddr_type = btd_device_get_bdaddr_type(device);
 
src/btd.h +2 -0
index c84a600d1..07c4d85ba 100644
@@ -144,6 +144,8 @@ struct btd_opts {
 	bool		experimental;
 	bool		testing;
 	bool		filter_discoverable;
+	bool		disable_discovery_on_connect;
+
 	struct queue	*kernel;
 
 	uint16_t	did_source;
src/main.c +4 -0
index 818f7c06e..d7ddf5643 100644
@@ -92,6 +92,7 @@ static const char *supported_options[] = {
 	"KernelExperimental",
 	"RemoteNameRequestRetryDelay",
 	"FilterDiscoverable",
+	"DisableDiscoveryOnConnect",
 	NULL
 };
 
@@ -1072,6 +1073,8 @@ static void parse_general(GKeyFile *config)
 					0, UINT32_MAX);
 	parse_config_bool(config, "General", "FilterDiscoverable",
 						&btd_opts.filter_discoverable);
+	parse_config_bool(config, "General", "DisableDiscoveryOnConnect",
+					&btd_opts.disable_discovery_on_connect);
 }
 
 static void parse_gatt_cache(GKeyFile *config)
@@ -1283,6 +1286,7 @@ static void init_defaults(void)
 	btd_opts.name_request_retry_delay = DEFAULT_NAME_REQUEST_RETRY_DELAY;
 	btd_opts.secure_conn = SC_ON;
 	btd_opts.filter_discoverable = true;
+	btd_opts.disable_discovery_on_connect = false;
 
 	btd_opts.defaults.num_entries = 0;
 	btd_opts.defaults.br.page_scan_type = 0xFFFF;
src/main.conf +6 -0
index d31dd1b8f..22507c465 100644
@@ -157,6 +157,12 @@
 # some stacks) or when testing bad/unintended behavior.
 #FilterDiscoverable = true
 
+# Disables background LE passive scanning when an active connection is
+# established. Recommended for combo chips (shared Wi-Fi/Bluetooth antenna)
+# to prevent audio stuttering and packet loss caused by antenna multiplexing.
+# Defaults to false.
+#DisableDiscoveryOnConnect = false
+
 [BR]
 # The following values are used to load default adapter parameters for BR/EDR.
 # BlueZ loads the values into the kernel before the adapter is powered if the
Signature · 1 line
2.53.0
#1 lore raw

PATCH 2/2 adapter: remove connected device from kernel accept list on connect

When DisableDiscoveryOnConnect is enabled, remove the device from the kernel accept list once it has successfully connected. This prevents the kernel from continuing background LE scanning for a device that is already connected, eliminating antenna contention on combo chips with shared Wi-Fi/Bluetooth radios.

The device is re-added to the accept list upon disconnection to restore auto-reconnect capability.

---
 src/adapter.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
src/adapter.c +21 -0
index 4a18adfe0..48f0f2cc4 100644
@@ -9533,6 +9533,7 @@ static void disconnected_callback(uint16_t index, uint16_t length,
 {
 	const struct mgmt_ev_device_disconnected *ev = param;
 	struct btd_adapter *adapter = user_data;
+	struct btd_device *device = NULL;
 	uint8_t reason;
 
 	if (length < sizeof(struct mgmt_addr_info)) {
@@ -9546,7 +9547,18 @@ static void disconnected_callback(uint16_t index, uint16_t length,
 	else
 		reason = ev->reason;
 
+	if (btd_opts.disable_discovery_on_connect)
+		device = btd_adapter_find_device(adapter, &ev->addr.bdaddr,
+							ev->addr.type);
+
 	dev_disconnected(adapter, &ev->addr, reason);
+
+	/*
+	 * Re-add the device to the kernel accept list after disconnection
+	 * so it can auto-reconnect in the future.
+	 */
+	if (btd_opts.disable_discovery_on_connect && device)
+		adapter_auto_connect_add(adapter, device);
 }
 
 static void connected_callback(uint16_t index, uint16_t length,
@@ -9593,6 +9605,15 @@ static void connected_callback(uint16_t index, uint16_t length,
 	adapter_add_connection(adapter, device, ev->addr.type,
 					le32_to_cpu(ev->flags));
 
+	/*
+	 * If DisableDiscoveryOnConnect is enabled, remove the device from
+	 * the kernel accept list once it has connected. This stops the kernel
+	 * from continuing to scan for a device that is already connected,
+	 * eliminating antenna contention on combo chips.
+	 */
+	if (btd_opts.disable_discovery_on_connect)
+		adapter_auto_connect_remove(adapter, device);
+
 	name_known = device_name_known(device);
 
 	if (eir_data.name && (eir_data.name_complete || !name_known)) {
Signature · 1 line
2.53.0
#2 lore raw
In reply to StefanCondorache

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

---Test result---

Test Summary:

CheckPatch                    PASS      0.92 seconds
GitLint                       PASS      0.63 seconds
BuildEll                      PASS      20.19 seconds
BluezMake                     PASS      607.56 seconds
MakeCheck                     PASS      19.25 seconds
MakeDistcheck                 PASS      234.43 seconds
CheckValgrind                 PASS      275.18 seconds
CheckSmatch                   WARNING   319.17 seconds
bluezmakeextell               PASS      163.94 seconds
IncrementalBuild              PASS      614.25 seconds
ScanBuild                     PASS      906.25 seconds

Details
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
src/main.c: note: in included file (through src/device.h):

https://github.com/bluez/bluez/pull/2055

---
Regards,
Linux Bluetooth