/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
原因
内核错误 200039 - BT 广告数据包将系统从 S3 唤醒并暂停到空闲。
这会影响 Intel (
8087:0aaa
) 和 Atheros (0cf3:e005
)(0cf3:e007
) 蓝牙:解决方法
一种解决方法是在睡眠/挂起之前自动取消对蓝牙 USB 设备的授权,然后在唤醒时重新授权。
systemd
解决方法是使用以下方法:/etc/systemd/system/bluetooth-disable-before-sleep.service
(注意 CHANGE ME 行):/usr/local/bin/bluetooth-sleep
:归功于这篇文章。