蓝牙处于活动状态时如何暂停/睡眠?

蓝牙处于活动状态时如何暂停/睡眠?

当蓝牙处于活动状态时,我无法暂停/睡眠。系统日志中没有错误消息。

但是,在rfkill block bluetooth我可以成功睡眠/挂起之后。

我使用蓝牙鼠标,因此无法永久禁用蓝牙。

如何在仍具有蓝牙功能的情况下睡眠/暂停?

答案1

原因

核心Bug 200039 - BT 广告数据包将系统从 S3 唤醒并挂起至空闲状态

这会影响 Intel ( 8087:0aaa) 和 Atheros ( 0cf3:e005)( 0cf3:e007) 蓝牙:

  • 宏碁雨燕 SF314-55
  • 华硕UX333FA
  • 华硕UX433FN
  • 华硕UX533FD

解决方法

解决方法是在睡眠/挂起之前自动取消对蓝牙 USB 设备的授权,然后在唤醒时重新授权。

解决systemd方法是使用以下内容:

/etc/systemd/system/bluetooth-disable-before-sleep.service(注意“CHANGE ME”行):

[Unit]
Description=disable bluetooth for systemd sleep/suspend targets
Before=sleep.target
Before=suspend.target
Before=hybrid-sleep.target
Before=suspend-then-hibernate.target
StopWhenUnneeded=yes

[Service]
Type=oneshot
RemainAfterExit=yes

# Usage: bluetooth-sleep (start|stop) <vendor> <product>
# Get values from `lsusb`:
# eg: Bus 001 Device 003: ID 8087:0aaa Intel Corp.
# Usage: bluetooth-sleep (start|stop) 8087 0aaa

##### CHANGE ME: (the two hex values at end of next line) ###
ExecStart=/usr/local/bin/bluetooth-sleep start 8087 0aaa
##### CHANGE ME: (the two hex values at end of next line) ###
ExecStop=/usr/local/bin/bluetooth-sleep  stop  8087 0aaa

[Install]
WantedBy=sleep.target
WantedBy=suspend.target
WantedBy=hybrid-sleep.target
WantedBy=suspend-then-hibernate.target

/usr/local/bin/bluetooth-sleep:

#!/bin/bash

# Disable bluetooth given first argument "start"
# Re-enable bluetooth given first argument "stop"
# Expects vendor and product as 2nd and 3rd arguments

set -eu

usage() {
  script_name=${0##*/}
  printf '%s: de-authorise bluetooth during sleep/suspend\n' "$script_name" >&2
  printf 'Usage: %s (start|stop) <vendor> <product>\n' "$script_name" >&2
  exit 1
}

case "${1:-}" in
  start) value=0 ;;
  stop)  value=1 ;;
  *)     usage   ;;
esac

[ $# -ne 3 ] && usage
vendor=$2
product=$3

shopt -s nullglob
for dir in /sys/bus/usb/devices/*; do
  if [[ -L "$dir" && -f $dir/idVendor && -f $dir/idProduct &&
        $(cat "$dir/idVendor")  == "$vendor" &&
        $(cat "$dir/idProduct") == "$product" ]]; then
    echo "$value" > "$dir/authorized"
    echo "echo $value > $dir/authorized"
  fi
done

归功于这个帖子

相关内容