adapter: Don't power on while blocked by rfkill
PATCH 1/1 adapter: Don't power on while blocked by rfkill
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.
---
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(-)
src/adapter.c +15 -6
@@ -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)
Signature · 1 line
2.47.3
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/1192615/
---Test result---
Test Summary:
CheckPatch PASS 8.11 seconds GitLint PASS 1.24 seconds BuildEll PASS 19.48 seconds BluezMake PASS 297.29 seconds CheckSmatch PASS 291.11 seconds bluezmakeextell PASS 93.31 seconds TestFunctional PASS 1103.66 seconds IncrementalBuild PASS 303.28 seconds ScanBuild PASS 1119.50 seconds
https://github.com/bluez/bluez/pull/2707
---
Regards,
Linux Bluetooth
This patch was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Hello:
This patch was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:
Quoted 8 lines · On Sat, 24 Oct 2026 12:32:55 +0200 you wrote:
btd_adapter_new()reads the rfkill state and sets PowerState to off-blocked when the adapter is blocked. With AutoEnable, the default since commit180cf09933b2("policy: Change AutoEnable default to true"), the policy plugin then callsbtd_adapter_restore_powered(), which sends Set Powered anyway. It can only fail, so every start with Bluetooth turned off logs an error:[...]
Here is the summary with links:
- [BlueZ] adapter: Don't power on while blocked by rfkill
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=aa3d6c761cb1
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html