All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ] main.conf: Add SecureSimplePairing option
@ 2026-11-20 10:56 Jovelyn Custodio
  2026-11-20 14:36 ` [BlueZ] " bluez.test.bot
  0 siblings, 1 reply; 2+ messages in thread
From: Jovelyn Custodio @ 2026-11-20 10:56 UTC (permalink / raw)
  To: linux-bluetooth

This adds SecureSimplePairing option to General section which can be
used to keep Secure Simple Pairing disabled on BR/EDR capable adapters.
It defaults to true, which keeps the current behaviour of always
enabling it.

Some HID devices can't reconnect to a host that has SSP enabled. A
Nintendo Switch Pro Controller reconnecting to an RTL8851BU adapter
authenticates and encrypts the link on its own, opens PSM 17 and then
stalls until Encryption Key Refresh Complete arrives with LMP Response
Timeout 30 seconds later. PSM 19 is never opened. With SSP disabled
the host starts authentication instead, no key refresh takes place and
the controller reconnects.

Assisted-by: Claude:claude-fable-5-2
---

Notes:
    I ran into this with a Switch Pro Controller on an RTL8851BU combo
    stick (kernel 7.3.4, BlueZ 5.88). Fresh pairing works, but pressing
    Home to reconnect fails every time: the controller pages the host,
    authenticates and turns on E0 by itself, opens PSM 17, and about 100 ms
    later the link stalls. 30 seconds on I get Encryption Key Refresh
    Complete with LMP Response Timeout and a disconnect. PSM 19 never shows
    up.
    
    Link policy 0x0000, Secure Connections off, UserspaceHID=false and
    disable_ertm didn't help. Accepting as peripheral (a2dp and avrcp
    plugins off) didn't either, since the controller asks for a role switch
    itself and I'm back at the stall.
    
    Refusing the role switch as well got further: Encryption Key Refresh
    Complete came back with Transaction Collision, then Success, PSM 19
    opened and hid-nintendo bound. About 0.8 seconds later the controller
    turned encryption off and the kernel dropped the link with
    Authentication Failure. So the refresh seems to only get stuck when the
    adapter is central.
    
    Turning SSP off with btmgmt was the only single change that fixed it,
    but bluetoothd switches it back on at every start, hence the option.
    
    Tested on that one adapter and controller only:
     - option absent or true: SSP gets enabled as before
     - option false: SSP stays off after a daemon restart and after
       rebinding btusb, and the Home press reconnect works with a link key
       made while SSP was on
     - pairing from scratch with the option false works too (legacy
       pairing, autopair answers with PIN 0000)
     - make check passes, checkpatch is clean
    
    Not tested:
     - adapters whose controller supports BR/EDR Secure Connections. Going
       by mgmt.c the kernel rejects Set Secure Connections there while SSP
       is off, so they'd lose SC with this option. That's what the note in
       main.conf is about.
     - ControllerMode = bredr
     - UserspaceHID=true. I'd already switched it to false before I found
       this and haven't gone back yet.
    
    I can't see LMP on this chip, so I don't know if the stuck key refresh
    is Realtek's firmware or the controller's. It's probably the same thing
    as https://github.com/bluez/bluez/issues/824.

 src/adapter.c | 22 ++++++++++++++++++----
 src/btd.h     |  1 +
 src/main.c    |  4 ++++
 src/main.conf | 11 +++++++++++
 4 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 1439642..3d3a272 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -10841,6 +10841,19 @@ static void read_exp_features(struct btd_adapter *adapter)
 	btd_error(adapter->dev_id, "Failed to read exp features info");
 }
 
+static void set_ssp(struct btd_adapter *adapter)
+{
+	bool enabled = adapter->current_settings & MGMT_SETTING_SSP;
+
+	if (!(adapter->supported_settings & MGMT_SETTING_SSP))
+		return;
+
+	if (enabled == btd_opts.ssp)
+		return;
+
+	set_mode(adapter, MGMT_OP_SET_SSP, btd_opts.ssp ? 0x01 : 0x00);
+}
+
 static void read_info_complete(uint8_t status, uint16_t length,
 					const void *param, void *user_data)
 {
@@ -10921,8 +10934,8 @@ static void read_info_complete(uint8_t status, uint16_t length,
 			set_mode(adapter, MGMT_OP_SET_LE, 0x01);
 		if (missing_settings & MGMT_SETTING_BREDR)
 			set_mode(adapter, MGMT_OP_SET_BREDR, 0x01);
-		if (missing_settings & MGMT_SETTING_SSP)
-			set_mode(adapter, MGMT_OP_SET_SSP, 0x01);
+
+		set_ssp(adapter);
 		break;
 	case BT_MODE_BREDR:
 		if (!(adapter->supported_settings & MGMT_SETTING_BREDR)) {
@@ -10933,8 +10946,9 @@ static void read_info_complete(uint8_t status, uint16_t length,
 
 		if (missing_settings & MGMT_SETTING_BREDR)
 			set_mode(adapter, MGMT_OP_SET_BREDR, 0x01);
-		if (missing_settings & MGMT_SETTING_SSP)
-			set_mode(adapter, MGMT_OP_SET_SSP, 0x01);
+
+		set_ssp(adapter);
+
 		if (adapter->current_settings & MGMT_SETTING_LE)
 			set_mode(adapter, MGMT_OP_SET_LE, 0x00);
 		break;
diff --git a/src/btd.h b/src/btd.h
index 9bf3102..39fb609 100644
--- a/src/btd.h
+++ b/src/btd.h
@@ -141,6 +141,7 @@ struct btd_opts {
 	bool		device_privacy;
 	uint32_t	name_request_retry_delay;
 	uint8_t		secure_conn;
+	bool		ssp;
 
 	struct btd_defaults defaults;
 
diff --git a/src/main.c b/src/main.c
index 3a051c5..27d98a6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -83,6 +83,7 @@ static const char *supported_options[] = {
 	"MultiProfile",
 	"FastConnectable",
 	"SecureConnections",
+	"SecureSimplePairing",
 	"Privacy",
 	"JustWorksRepairing",
 	"TemporaryTimeout",
@@ -1117,6 +1118,8 @@ static void parse_general(GKeyFile *config)
 	parse_config_bool(config, "General", "RefreshDiscovery",
 						&btd_opts.refresh_discovery);
 	parse_secure_conns(config);
+	parse_config_bool(config, "General", "SecureSimplePairing",
+						&btd_opts.ssp);
 	parse_config_bool(config, "General", "Experimental",
 						&btd_opts.experimental);
 	parse_config_bool(config, "General", "Testing",
@@ -1479,6 +1482,7 @@ static void init_defaults(void)
 	btd_opts.refresh_discovery = TRUE;
 	btd_opts.name_request_retry_delay = DEFAULT_NAME_REQUEST_RETRY_DELAY;
 	btd_opts.secure_conn = SC_ON;
+	btd_opts.ssp = true;
 	btd_opts.filter_discoverable = true;
 
 	btd_opts.defaults.num_entries = 0;
diff --git a/src/main.conf b/src/main.conf
index c990614..76f9ec0 100644
--- a/src/main.conf
+++ b/src/main.conf
@@ -122,6 +122,17 @@
 # Defaults to "on"
 #SecureConnections = on
 
+# Default Secure Simple Pairing setting.
+# Enables Secure Simple Pairing for BR/EDR on adapters that support it.
+# Disabling it makes BR/EDR pairing fall back to legacy PIN code pairing, so
+# only do it for remote devices that don't work otherwise. Existing link keys
+# are kept. The kernel refuses to enable Secure Connections without it on
+# controllers that support BR/EDR Secure Connections. If the adapter is
+# already powered the change applies the next time it is powered on.
+# Possible values: true, false
+# Defaults to true
+#SecureSimplePairing = true
+
 # Enables D-Bus experimental interfaces
 # Possible values: true or false
 #Experimental = false
-- 
2.56.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-20 14:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 10:56 [PATCH BlueZ] main.conf: Add SecureSimplePairing option Jovelyn Custodio
2026-11-20 14:36 ` [BlueZ] " bluez.test.bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.