Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH BlueZ] adapter: Don't power on while blocked by rfkill
@ 2026-10-24 10:32 Tobias Wilken
  2026-10-24 14:23 ` [BlueZ] " bluez.test.bot
  2026-10-26 21:40 ` [PATCH BlueZ] " patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Tobias Wilken @ 2026-10-24 10:32 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Tobias Wilken

btd_adapter_new() reads the rfkill state and sets PowerState to
off-blocked when the adapter is blocked. With AutoEnable, the default
since commit 180cf09933b2 ("policy: Change AutoEnable default to
true"), the policy plugin then calls btd_adapter_restore_powered(),
which sends Set Powered anyway. It can only fail, so every start with
Bluetooth turned off logs an error:

  bluetoothd[1212]: Failed to set mode: Failed (0x03)

or, with a kernel that reports the rfkill block:

  bluetoothd[1212]: Failed to set mode: Blocked through rfkill (0x12)

Don't send Set Powered from btd_adapter_restore_powered() while rfkill
reports the adapter blocked. The rfkill unblock event calls it again,
and that powers the adapter on as before. If the rfkill state can't be
read, keep the current behaviour. Setting the Powered property over
D-Bus still sends the command and reports the error.

Assisted-by: Claude:claude-opus-5-5
---

Notes:
    Tested with bluetoothd built from master on Debian's 7.2.9 kernel,
    Bluetooth soft-blocked, AutoEnable at its default:
    - without this patch: "Failed to set mode: Failed (0x03)" at start
    - with it: no error, PowerState off-blocked
    - bluetoothctl power on while blocked: still fails as before
    - rfkill unblock: adapter powers on by itself, PowerState on
    - block again: off-blocked
    make check passes.

 src/adapter.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index d3aa03f..1561ea3 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -8260,14 +8260,23 @@ int btd_cancel_authorization(guint id)
 int btd_adapter_restore_powered(struct btd_adapter *adapter)
 {
 	bool powered;
+	int blocked;
 
 	powered = btd_adapter_get_powered(adapter);
-	if (adapter->power_state == ADAPTER_POWER_STATE_OFF_BLOCKED &&
-	    rfkill_get_blocked(adapter->dev_id) == 0) {
-		adapter_set_power_state(adapter,
-					powered ?
-					ADAPTER_POWER_STATE_ON :
-					ADAPTER_POWER_STATE_OFF);
+	if (adapter->power_state == ADAPTER_POWER_STATE_OFF_BLOCKED) {
+		blocked = rfkill_get_blocked(adapter->dev_id);
+
+		/* Powering on can't succeed while blocked, the rfkill
+		 * unblock event calls this function again.
+		 */
+		if (blocked > 0)
+			return 0;
+
+		if (blocked == 0)
+			adapter_set_power_state(adapter,
+						powered ?
+						ADAPTER_POWER_STATE_ON :
+						ADAPTER_POWER_STATE_OFF);
 	}
 
 	if (powered)
-- 
2.47.3


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

end of thread, other threads:[~2026-10-26 21:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-24 10:32 [PATCH BlueZ] adapter: Don't power on while blocked by rfkill Tobias Wilken
2026-10-24 14:23 ` [BlueZ] " bluez.test.bot
2026-10-26 21:40 ` [PATCH BlueZ] " patchwork-bot+bluetooth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox