UDEV 规则更改蓝牙控制器名称

UDEV 规则更改蓝牙控制器名称

我的 Ubuntu 23.04 服务器、内核 6.2.0 上有几个通过蓝牙连接的 PS4 和 PS5 控制器。

我正在尝试建立一个 UDEV 规则来重命名它们,因为默认情况下它们都被称为“无线控制器”。

首先,这是其中一个设备连接时的 udev 链:

$ udevadm monitor --environment --udev
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing

UDEV  [7829.628341] add      /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256 (bluetooth)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256
SUBSYSTEM=bluetooth
DEVTYPE=link
SEQNUM=4898
USEC_INITIALIZED=7829627332
SYSTEMD_ALIAS=/sys/subsystem/bluetooth/devices/hci0:256
SYSTEMD_WANTS=bluetooth.target
SYSTEMD_USER_WANTS=bluetooth.target
TAGS=:systemd:
CURRENT_TAGS=:systemd:

UDEV  [7829.980224] add      /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005 (hid)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005
SUBSYSTEM=hid
HID_ID=0005:0000054C:000005C4
HID_NAME=Wireless Controller
HID_PHYS=f4:ce:23:f7:16:91
HID_UNIQ=90:fb:a6:e0:4f:6b
MODALIAS=hid:b0005g0000v0000054Cp000005C4
SEQNUM=4899
USEC_INITIALIZED=7829979731
DRIVER=playstation

UDEV  [7829.985433] add      /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/hidraw/hidraw2 (hidraw)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/hidraw/hidraw2
SUBSYSTEM=hidraw
DEVNAME=/dev/hidraw2
SEQNUM=4900
USEC_INITIALIZED=7829985139
MAJOR=238
MINOR=2

UDEV  [7830.037426] add      /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/input/input20 (input)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/input/input20
SUBSYSTEM=input
PRODUCT=5/54c/5c4/8100
NAME="Wireless Controller"
UNIQ="90:fb:a6:e0:4f:6b"
PROP=0
EV=20000b
KEY=7fdb000000000000 0 0 0 0
ABS=3003f
FF=107030000 0
MODALIAS=input:b0005v054Cp05C4e8100-e0,1,3,15,k130,131,133,134,136,137,138,139,13A,13B,13C,13D,13E,ra0,1,2,3,4,5,10,11,mlsf50,51,58,59,5A,60,w
SEQNUM=4901
USEC_INITIALIZED=7830035831
ID_INPUT=1
ID_INPUT_JOYSTICK=1
ID_BUS=bluetooth
ID_PATH=pci-0000:00:14.0-usb-0:10:1.0
ID_PATH_TAG=pci-0000_00_14_0-usb-0_10_1_0
ID_FOR_SEAT=input-pci-0000_00_14_0-usb-0_10_1_0
TAGS=:seat:
CURRENT_TAGS=:seat:

UDEV  [7830.042666] add      /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:6d/INT3515:01/wakeup/wakeup49 (wakeup)
ACTION=add
DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:6d/INT3515:01/wakeup/wakeup49
SUBSYSTEM=wakeup
SEQNUM=4916
USEC_INITIALIZED=7830042488

UDEV  [7830.044656] add      /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/leds/input20:blue (leds)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/leds/input20:blue
SUBSYSTEM=leds
SEQNUM=4913
USEC_INITIALIZED=7830044275
ID_PATH=pci-0000:00:14.0-usb-0:10:1.0
ID_PATH_TAG=pci-0000_00_14_0-usb-0_10_1_0
ID_FOR_SEAT=leds-pci-0000_00_14_0-usb-0_10_1_0
TAGS=:seat:
CURRENT_TAGS=:seat:

UDEV  [7830.044881] add      /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/power_supply/ps-controller-battery-90:fb:a6:e0:4f:6b/wakeup48 (wakeup)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/power_supply/ps-controller-battery-90:fb:a6:e0:4f:6b/wakeup48
SUBSYSTEM=wakeup
SEQNUM=4909
USEC_INITIALIZED=7830044633

UDEV  [7830.045190] remove   /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:6d/INT3515:01/wakeup/wakeup49 (wakeup)
ACTION=remove
DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:6d/INT3515:01/wakeup/wakeup49
SUBSYSTEM=wakeup
SEQNUM=4917
USEC_INITIALIZED=7830038304

UDEV  [7830.045672] add      /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/power_supply/ps-controller-battery-90:fb:a6:e0:4f:6b/hwmon4 (hwmon)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/power_supply/ps-controller-battery-90:fb:a6:e0:4f:6b/hwmon4
SUBSYSTEM=hwmon
SEQNUM=4910
USEC_INITIALIZED=7830045556

UDEV  [7830.046198] add      /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/input/input22 (input)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/input/input22
SUBSYSTEM=input
PRODUCT=5/54c/5c4/8100
NAME="Wireless Controller Touchpad"
UNIQ="90:fb:a6:e0:4f:6b"
PROP=5
EV=b
KEY=2420 10000 0 0 0 0
ABS=260800000000003
MODALIAS=input:b0005v054Cp05C4e8100-e0,1,3,k110,145,14A,14D,ra0,1,2F,35,36,39,mlsfw
SEQNUM=4906
USEC_INITIALIZED=7830045407
ID_INPUT=1
ID_INPUT_TOUCHPAD=1
ID_BUS=bluetooth
ID_PATH=pci-0000:00:14.0-usb-0:10:1.0
ID_PATH_TAG=pci-0000_00_14_0-usb-0_10_1_0
ID_FOR_SEAT=input-pci-0000_00_14_0-usb-0_10_1_0
TAGS=:seat:
CURRENT_TAGS=:seat:

UDEV  [7830.046518] add      /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/input/input21 (input)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/input/input21
SUBSYSTEM=input
PRODUCT=5/54c/5c4/8100
NAME="Wireless Controller Motion Sensors"
UNIQ="90:fb:a6:e0:4f:6b"
PROP=40
EV=19
ABS=3f
MSC=20
MODALIAS=input:b0005v054Cp05C4e8100-e0,3,4,kra0,1,2,3,4,5,m5,lsfw
SEQNUM=4904
USEC_INITIALIZED=7830045429
ID_INPUT=1
ID_INPUT_ACCELEROMETER=1
ID_BUS=bluetooth
ID_PATH=pci-0000:00:14.0-usb-0:10:1.0
ID_PATH_TAG=pci-0000_00_14_0-usb-0_10_1_0
ID_FOR_SEAT=input-pci-0000_00_14_0-usb-0_10_1_0
IIO_SENSOR_PROXY_TYPE=input-accel
SYSTEMD_WANTS=iio-sensor-proxy.service
TAGS=:systemd:seat:
CURRENT_TAGS=:systemd:seat:

UDEV  [7830.046940] add      /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/leds/input20:green (leds)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/leds/input20:green
SUBSYSTEM=leds
SEQNUM=4912
USEC_INITIALIZED=7830045983
ID_PATH=pci-0000:00:14.0-usb-0:10:1.0
ID_PATH_TAG=pci-0000_00_14_0-usb-0_10_1_0
ID_FOR_SEAT=leds-pci-0000_00_14_0-usb-0_10_1_0
TAGS=:seat:
CURRENT_TAGS=:seat:

UDEV  [7830.047143] add      /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/leds/input20:red (leds)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/leds/input20:red
SUBSYSTEM=leds
SEQNUM=4911
USEC_INITIALIZED=7830046002
ID_PATH=pci-0000:00:14.0-usb-0:10:1.0
ID_PATH_TAG=pci-0000_00_14_0-usb-0_10_1_0
ID_FOR_SEAT=leds-pci-0000_00_14_0-usb-0_10_1_0
TAGS=:seat:
CURRENT_TAGS=:seat:

UDEV  [7830.047281] add      /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/leds/input20:global (leds)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/leds/input20:global
SUBSYSTEM=leds
SEQNUM=4914
USEC_INITIALIZED=7830046326
ID_PATH=pci-0000:00:14.0-usb-0:10:1.0
ID_PATH_TAG=pci-0000_00_14_0-usb-0_10_1_0
ID_FOR_SEAT=leds-pci-0000_00_14_0-usb-0_10_1_0
TAGS=:seat:
CURRENT_TAGS=:seat:

UDEV  [7830.047647] add      /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:6e/INT3515:02/wakeup/wakeup49 (wakeup)
ACTION=add
DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:6e/INT3515:02/wakeup/wakeup49
SUBSYSTEM=wakeup
SEQNUM=4918
USEC_INITIALIZED=7830047562

UDEV  [7830.048851] remove   /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:6e/INT3515:02/wakeup/wakeup49 (wakeup)
ACTION=remove
DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:6e/INT3515:02/wakeup/wakeup49
SUBSYSTEM=wakeup
SEQNUM=4919
USEC_INITIALIZED=7830043912

UDEV  [7830.052068] add      /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/input/input22/mouse1 (input)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/input/input22/mouse1
SUBSYSTEM=input
DEVNAME=/dev/input/mouse1
SEQNUM=4907
USEC_INITIALIZED=7830051921
ID_INPUT=1
ID_INPUT_TOUCHPAD=1
ID_BUS=bluetooth
MAJOR=13
MINOR=33

UDEV  [7830.057325] add      /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/input/input20/js0 (input)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/input/input20/js0
SUBSYSTEM=input
DEVNAME=/dev/input/js0
SEQNUM=4903
USEC_INITIALIZED=7830047828
ID_INPUT=1
ID_INPUT_JOYSTICK=1
ID_BUS=bluetooth
ID_PATH=pci-0000:00:14.0-usb-0:10:1.0
ID_PATH_TAG=pci-0000_00_14_0-usb-0_10_1_0
ID_FOR_SEAT=input-pci-0000_00_14_0-usb-0_10_1_0
MAJOR=13
MINOR=0
TAGS=:uaccess:seat:
CURRENT_TAGS=:uaccess:seat:

UDEV  [7830.096185] add      /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/input/input20/event14 (input)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/input/input20/event14
SUBSYSTEM=input
DEVNAME=/dev/input/event14
SEQNUM=4902
USEC_INITIALIZED=7830095820
.HAVE_HWDB_PROPERTIES=1
ID_INPUT=1
ID_INPUT_JOYSTICK=1
ID_BUS=bluetooth
ID_INPUT_JOYSTICK_INTEGRATION=external
ID_PATH=pci-0000:00:14.0-usb-0:10:1.0
ID_PATH_TAG=pci-0000_00_14_0-usb-0_10_1_0
ID_FOR_SEAT=input-pci-0000_00_14_0-usb-0_10_1_0
MAJOR=13
MINOR=78
TAGS=:uaccess:seat:
CURRENT_TAGS=:uaccess:seat:

UDEV  [7830.139067] add      /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/input/input21/event15 (input)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/input/input21/event15
SUBSYSTEM=input
DEVNAME=/dev/input/event15
SEQNUM=4905
USEC_INITIALIZED=7830138822
.HAVE_HWDB_PROPERTIES=1
ID_INPUT=1
ID_INPUT_ACCELEROMETER=1
ID_INPUT_WIDTH_MM=8
ID_INPUT_HEIGHT_MM=8
ID_BUS=bluetooth
IIO_SENSOR_PROXY_TYPE=input-accel
SYSTEMD_WANTS=iio-sensor-proxy.service
MAJOR=13
MINOR=79
TAGS=:systemd:
CURRENT_TAGS=:systemd:

UDEV  [7830.209947] add      /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/input/input22/event16 (input)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/input/input22/event16
SUBSYSTEM=input
DEVNAME=/dev/input/event16
SEQNUM=4908
USEC_INITIALIZED=7830158302
.HAVE_HWDB_PROPERTIES=1
ID_INPUT=1
ID_INPUT_TOUCHPAD=1
ID_BUS=bluetooth
ID_INPUT_TOUCHPAD_INTEGRATION=external
MAJOR=13
MINOR=80

UDEV  [7830.210992] bind     /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005 (hid)
ACTION=bind
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005
SUBSYSTEM=hid
DRIVER=playstation
HID_ID=0005:0000054C:000005C4
HID_NAME=Wireless Controller
HID_PHYS=f4:ce:23:f7:16:91
HID_UNIQ=90:fb:a6:e0:4f:6b
MODALIAS=hid:b0005g0000v0000054Cp000005C4
SEQNUM=4915
USEC_INITIALIZED=7830210897

UDEV  [7830.212264] change   /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/power_supply/ps-controller-battery-90:fb:a6:e0:4f:6b (power_supply)
ACTION=change
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/power_supply/ps-controller-battery-90:fb:a6:e0:4f:6b
SUBSYSTEM=power_supply
POWER_SUPPLY_NAME=ps-controller-battery-90:fb:a6:e0:4f:6b
POWER_SUPPLY_TYPE=Battery
POWER_SUPPLY_STATUS=Full
POWER_SUPPLY_PRESENT=1
POWER_SUPPLY_CAPACITY=100
POWER_SUPPLY_SCOPE=Device
SEQNUM=4920
USEC_INITIALIZED=7830212162

这是一个 DualShock 4 控制器,有很多子设备(触摸板、传感器、LED),我感兴趣的是以下设备:/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/input/input22 这是实际处理前面按钮的设备。

所以我制定了以下规则

ACTION=="add", SUBSYSTEM=="input", ATTR{uniq}=="90:fb:a6:e0:4f:6b", ATTR{name}="PS4 Anniversary"

但它失败并出现以下错误:

input22: /etc/udev/rules.d/98-pads.rules:2 ATTR '/sys/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/input/input22/name' writing 'PS4 Anniversary input'
input22: /etc/udev/rules.d/98-pads.rules:2 Failed to write ATTR{/sys/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/input/input22/name}, ignoring: Permission denied

权限被拒绝,我认为这是因为给定的文件 /sys/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/input/input22/name 是只读的 (-r--r--r-)。为了测试,我编辑了权限并再次尝试,结果显示“输入/输出错误”。这看起来不是可写数据,所以我认为它是从父级继承的。

现在我正在尝试使用父设备 /devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005 这里是可用的“udevadm info -a”:

  looking at device '/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005':
    KERNEL=="0005:054C:05C4.0005"
    SUBSYSTEM=="hid"
    DRIVER=="playstation"
    ATTR{country}=="00"
    ATTR{firmware_version}=="0x00002029"
    ATTR{hardware_version}=="0x00005400"
    ATTR{power/async}=="enabled"
    ATTR{power/control}=="auto"
    ATTR{power/runtime_active_kids}=="0"
    ATTR{power/runtime_active_time}=="0"
    ATTR{power/runtime_enabled}=="disabled"
    ATTR{power/runtime_status}=="unsupported"
    ATTR{power/runtime_suspended_time}=="0"
    ATTR{power/runtime_usage}=="0"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256':
    KERNELS=="hci0:256"
    SUBSYSTEMS=="bluetooth"
    DRIVERS==""
    ATTRS{power/async}=="disabled"
    ATTRS{power/control}=="auto"
    ATTRS{power/runtime_active_kids}=="0"
    ATTRS{power/runtime_active_time}=="0"
    ATTRS{power/runtime_enabled}=="disabled"
    ATTRS{power/runtime_status}=="unsupported"
    ATTRS{power/runtime_suspended_time}=="0"
    ATTRS{power/runtime_usage}=="0"

但我不太明白,例如“udevadm info /path/to/device”告诉我有“HID_UNIQ”这样的属性可以让我匹配设备,但它们不在“udevadm info -a”中,我无法让它在规则中匹配,我尝试了以下方法但都没有用:

ACTION=="add", ATTR{hid_uniq}=="90:fb:a6:e0:4f:6b", ATTR{hid_name}="PS4 Anniversary hid"
ACTION=="add", HID_UNIQ=="90:fb:a6:e0:4f:6b", HID_NAME="PS4 Anniversary hid"

该规则从未被触发,这意味着至少匹配的部分不起作用。

我注意到该设备文件夹中有一个可写入的“uevent”文件:

-rw-r--r-- 1 root root 4096 May 18 22:35 /sys/devices/pci0000:00/0000:00:14.0/usb1/1-10/1-10:1.0/bluetooth/hci0/hci0:256/0005:054C:05C4.0005/uevent

该文件的内容应允许我使用其“uniq”地址匹配设备并重命名它,以便它可以传播到子设备:

DRIVER=playstation
HID_ID=0005:0000054C:000005C4
HID_NAME=Wireless Controller
HID_PHYS=f4:ce:23:f7:16:91
HID_UNIQ=90:fb:a6:e0:4f:6b
MODALIAS=hid:b0005g0000v0000054Cp000005C4

这个 uevent 文件可以通过 udev 规则使用吗?

也许我太过努力了,还有更直接的方法来重命名蓝牙设备?好吧,即使那是 cae,我也想了解我能用 udev 规则做什么或不能做什么...

干杯

相关内容