Bluetooth wake up suspends not working

Hi, I want to wake up from suspends using bluetooth mouth/keyboard. I’m following the method from the link https://wiki.archlinux.org/title/bluetooth#Wake_from_suspend

so I create a udev rules as below:

sudo cat  /etc/udev/rules.d/91-keyboard-mouse-wakeup.rules

SUBSYSTEM=="usb", ATTRS{idVendor}=="0489", ATTRS{idProduct}=="e0d8" RUN+="/bin/sh -c 'echo enabled > /sys$env{DEVPATH}/../power/wakeup;'"

and my lsusb output:

lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 046a:0011 CHERRY G83 (RS 6000) Keyboard
Bus 001 Device 003: ID 0489:e0d8 Foxconn / Hon Hai Bluetooth Adapter
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 002: ID 30c9:00a8 Luxvisions Innotech Limited Integrated RGB Camera
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 007 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 008 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

I’m tring to do this mannulay, tells me permisson denied:


ls -la /sys/class/bluetooth/hci0
lrwxrwxrwx 1 root root 0  3月19日 10:12 /sys/class/bluetooth/hci0 -> ../../devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5/1-5:1.0/bluetooth/hci0

ls /sys/devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5/1-5:1.0/bluetooth/hci0/power/       
autosuspend_delay_ms  control  runtime_active_time  runtime_status  runtime_suspended_time


echo 'enabled' | sudo tee /sys/devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5/1-5:1.0/bluetooth/hci0/power/wakeup 
tee: '/sys/devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5/1-5:1.0/bluetooth/hci0/power/wakeup': permisson denied
enabled


echo 'enabled' | sudo tee /sys/devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5/1-5:1.0/bluetooth/hci0/hci0:512/device/power/wakeup
tee: '/sys/devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5/1-5:1.0/bluetooth/hci0/hci0:512/device/power/wakeup': permisson denied
enabled

and my kernel:

uname -a                        
Linux lj-82y8 6.7.9-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Fri, 08 Mar 2024 01:58:50 +0000 x86_64 GNU/Linux

BTW, on the same laptop, I have a manjaro, the arch wiki’s method works.

So, what should I do? Thanks advanecd!
LJ

I think this is because you don’t have any permission to modify the directory. If you look at the contents of the /sys/devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5/1-5:1.0/bluetooth/hci0/power/ directory, you’ll see that there is no wakeup file in it.

So when you try to tee the output into the wakeup file, it will attempt to create a new file inside the directory, which probably don’t have permission.

Can you show the output of

$ ls -l /sys/devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5/1-5:1.0/bluetooth/hci0/power/

The method proposed in the Arch Wiki should work. You’re saying that it doesn’t work on Endeavor? That doesn’t sound right…

➜  power ls -l /sys/devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5/1-5:1.0/bluetooth/hci0/power/ 

总计 0
-rw-r--r-- 1 root root 4096  3月19日 15:38 autosuspend_delay_ms
-rw-r--r-- 1 root root 4096  3月19日 15:38 control
-r--r--r-- 1 root root 4096  3月19日 15:38 runtime_active_time
-r--r--r-- 1 root root 4096  3月19日 15:38 runtime_status
-r--r--r-- 1 root root 4096  3月19日 15:38 runtime_suspended_time

Yes, it works in Manjaro not in Endeavor…

My bad. I made a typo. It should be ls -ld not ls -l.

Can you post the output of lsusb | grep Bluetooth for Endeavor?

OK,

lsusb | grep Bluetooth 
Bus 001 Device 003: ID 0489:e0d8 Foxconn / Hon Hai Bluetooth Adapter


ls -ld /sys/devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5/1-5:1.0/bluetooth/hci0/power/
drwxr-xr-x 2 root root 0  3月19日 16:55 /sys/devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5/1-5:1.0/bluetooth/hci0/power/

Hmm. That’s strange. The udev rule should work. After you have rebooted into Endeavour, there still isn’t any wakeup file inside the device directory?

Yes, I rebooted 2 or 3 times, no differences.

Inside a terminal, run

$ udevadm monitor

While leaving the terminal window open, connect/disconnect the bluetooth keyboard. There should be a bunch of events printed out in the terminal window. Can you post the output?

KERNEL[18694.547112] remove   /devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5/1-5:1.0/bluetooth/hci0/hci0:512 (bluetooth)
UDEV  [18694.549569] remove   /devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5/1-5:1.0/bluetooth/hci0/hci0:512 (bluetooth)
KERNEL[18696.627489] add      /devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5/1-5:1.0/bluetooth/hci0/hci0:512 (bluetooth)
UDEV  [18696.629007] add      /devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5/1-5:1.0/bluetooth/hci0/hci0:512 (bluetooth)

Okay. My current theory is that the udev rule was indeed applied during boot, but the problem is that the command triggered by the udev rule failed due to the permission error. To test out this theory, modify the /etc/udev/rules.d/91-keyboard-mouse-wakeup.rules file to this:

SUBSYSTEM=="usb", ATTRS{idVendor}=="0489", ATTRS{idProduct}=="e0d8" RUN+="/bin/sh -c 'echo enabled > /sys$env{DEVPATH}/../power/wakeup || touch /tmp/failed-udev-command'"

Reboot and test. If my guess is correct, then you should be able to see a file failed-udev-command inside the /tmp directory after you reboot.

Here is the output:

cat /etc/udev/rules.d/91-keyboard-mouse-wakeup.rules 
SUBSYSTEM=="usb", ATTRS{idVendor}=="0489", ATTRS{idProduct}=="e0d8" RUN+="/bin/sh -c 'echo enabled > /sys$env{DEVPATH}/../power/wakeup || touch /tmp/failed-udev-command;'"

ls /tmp
busname                                                                      systemd-private-58026a3c47d545c28cfac912167c0086-polkit.service-HfR8eG
eos-update-notifier.log.dSg0ACDA                                             systemd-private-58026a3c47d545c28cfac912167c0086-power-profiles-daemon.service-nypIAJ
plasma-csd-generator.LaRCAl                                                  systemd-private-58026a3c47d545c28cfac912167c0086-systemd-hostnamed.service-ioLjHC
scoped_dirCBbNqY                                                             systemd-private-58026a3c47d545c28cfac912167c0086-systemd-localed.service-ooYVxD
sddm-:0-KWexMn                                                               systemd-private-58026a3c47d545c28cfac912167c0086-systemd-logind.service-yZ68Ej
sddm-auth-c0d20918-a818-4170-8f82-89aad8fd90c7                               systemd-private-58026a3c47d545c28cfac912167c0086-systemd-timesyncd.service-58HNwL
systemd-private-58026a3c47d545c28cfac912167c0086-bluetooth.service-M0Aa8U    systemd-private-58026a3c47d545c28cfac912167c0086-upower.service-5A6pWR
systemd-private-58026a3c47d545c28cfac912167c0086-dbus-broker.service-oSZz5z  yad-zombies.log


BTW, I have another test script, I printed the DEVPATH, and I CAN find the wakeup file in that path.
But the bluetooth still can NOT wake up the suspends…

cat /etc/udev/rules.d/91-test.rules 
SUBSYSTEM=="usb", ATTRS{idVendor}=="0489", ATTRS{idProduct}=="e0d8" RUN+="/bin/sh -c 'echo $env{DEVPATH} > /tmp/busname;'"

cat /tmp/busname
/devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5/1-5:1.1

cat /sys/devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5/1-5:1.1/../power/wakeup
enabled

Can you post the output of

$ udevadm info -a -p /sys/devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5/1-5:1.0/bluetooth

Sure:

udevadm info -a -p /sys/devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5/1-5:1.0/bluetooth
Unknown device "/sys/devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5/1-5:1.0/bluetooth": No such device

so I run

udevadm info -a -p /sys/devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5/1-5:1.0

paste part of it:

  looking at parent device '/devices/pci0000:00/0000:00:08.1/0000:63:00.3/usb1/1-5':
    KERNELS=="1-5"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{authorized}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bDeviceClass}=="ef"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{bDeviceSubClass}=="02"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bMaxPower}=="100mA"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bNumInterfaces}==" 3"
    ATTRS{bcdDevice}=="0100"
    ATTRS{bmAttributes}=="e0"
    ATTRS{busnum}=="1"
    ATTRS{configuration}=="Config_01"
    ATTRS{devnum}=="3"
    ATTRS{devpath}=="5"
    ATTRS{idProduct}=="e0d8"
    ATTRS{idVendor}=="0489"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="MediaTek Inc."
    ATTRS{maxchild}=="0"
    ATTRS{physical_location/dock}=="no"
    ATTRS{physical_location/horizontal_position}=="left"
    ATTRS{physical_location/lid}=="no"
    ATTRS{physical_location/panel}=="top"
    ATTRS{physical_location/vertical_position}=="upper"
    ATTRS{power/active_duration}=="911928"
    ATTRS{power/autosuspend}=="2"
    ATTRS{power/autosuspend_delay_ms}=="2000"
    ATTRS{power/connected_duration}=="916573"
    ATTRS{power/control}=="on"
    ATTRS{power/level}=="on"
    ATTRS{power/persist}=="1"
    ATTRS{power/runtime_active_time}=="913951"
    ATTRS{power/runtime_status}=="active"
    ATTRS{power/runtime_suspended_time}=="0"
    ATTRS{power/wakeup}=="enabled"
    ATTRS{power/wakeup_abort_count}=="0"
    ATTRS{power/wakeup_active}=="0"
    ATTRS{power/wakeup_active_count}=="0"
    ATTRS{power/wakeup_count}=="0"
    ATTRS{power/wakeup_expire_count}=="0"
    ATTRS{power/wakeup_last_time_ms}=="0"
    ATTRS{power/wakeup_max_time_ms}=="0"
    ATTRS{power/wakeup_total_time_ms}=="0"
    ATTRS{product}=="Wireless_Device"
    ATTRS{quirks}=="0x0"
    ATTRS{removable}=="fixed"
    ATTRS{remove}=="(not readable)"
    ATTRS{rx_lanes}=="1"
    ATTRS{serial}=="000000000"
    ATTRS{speed}=="480"
    ATTRS{tx_lanes}=="1"
    ATTRS{urbnum}=="103744"
    ATTRS{version}==" 2.10"

Is this what you need?

Yes.

The udev rule definitely worked. The wakeup attribute is already enabled. This is weird.

Yes, I tried many times, bluetooth can’t wake up suspends. More werid manjaro on same laptop works… I really don’t know why…

What is the output of cat /proc/acpi/wakeup on Endeavour?

➜  ~ cat /proc/acpi/wakeup
Device	S-state	 Status   Sysfs node
GPP0	 S4	*disabled
GPP1	 S4	*disabled
GPP2	 S4	*disabled
GPP5	 S4	*disabled
GPP6	 S4	*enabled   pci:0000:00:02.2
GPP7	 S4	*disabled  pci:0000:00:02.3
GP11	 S4	*enabled   pci:0000:00:03.1
SWUS	 S4	*disabled
GP12	 S4	*disabled
SWUS	 S4	*disabled
XHC0	 S4	*enabled   pci:0000:63:00.3
XHC1	 S4	*enabled   pci:0000:63:00.4
NHI0	 S4	*enabled   pci:0000:65:00.5
NHI1	 S4	*disabled
XHC2	 S4	*disabled  pci:0000:65:00.0
XHC3	 S3	*enabled   pci:0000:65:00.3
XHC4	 S3	*enabled   pci:0000:65:00.4

Huh. I think this is the problem. The bluetooth adapter wakeup is only listed under S4 (hibernate). Normal suspend is S3.

Can you try to hibernate on Endeavour and see if the bluetooth keyboard can wake the system up?

You can also log into Manjaro and post the output of cat /proc/acpi/wakeup.

Edit:

The S4 entry in /proc/acpi/wakeup table might mean the highest level of wakeup. So if S4 is listed, it can technically send wake up signals to all other sleep states.

Great! But I can’t find hibernate in my KDE, can I change the S4 to S3?

Thanks!

I may have misinterpreted the contents of /proc/acpi/wakeup. See above edit.