我有几个 USB 调制解调器,每个调制解调器都有多个端点:许多 TTY、一个网络接口、一个 cdc-wdm 端口和一些其他东西。我试图将它们分组在一起,以便我知道,例如 ttyUSB3、ttyUSB4、wwan1 和 cdc-wdm1 都属于同一个物理 USB 设备。
我认为$id
应该识别物理设备,所以我尝试$id
使用ENV{id}=$id
.这似乎适用于网络接口和串行端口,但不适用于 cdc-wdm 端口(这些端口的 id 未设置)。
以下是添加规则后的一些示例数据ENV{id}=$id
:
规则:SUBSYSTEM=="net", ATTRS{idVendor}=="106c", ATTRS{idProduct}=="3718", ENV{id}="$id"
# udevadm info --query=all --path=/devices/platform/atmel-ehci/usb1/1-1/1-1.3/1-
1.3:1.5/net/wwan0
P: /devices/platform/atmel-ehci/usb1/1-1/1-1.3/1-1.3:1.5/net/wwan0
E: DEVPATH=/devices/platform/atmel-ehci/usb1/1-1/1-1.3/1-1.3:1.5/net/wwan0
E: DEVTYPE=wwan
E: ID_BUS=usb
E: ID_MODEL=PANTECH_UML290
E: ID_MODEL_ENC=PANTECH\x20UML290
E: ID_MODEL_ID=3718
E: ID_REVISION=0000
E: ID_SERIAL=Pantech__Incorporated_PANTECH_UML290
E: ID_TYPE=generic
E: ID_USB_DRIVER=qmi_wwan
E: ID_USB_INTERFACES=:020201:0a0000:ffffff:fffdff:fffeff:fff1ff:
E: ID_USB_INTERFACE_NUM=05
E: ID_VENDOR=Pantech__Incorporated
E: ID_VENDOR_ENC=Pantech\x2c\x20Incorporated
E: ID_VENDOR_ID=106c
E: IFINDEX=5
E: INTERFACE=wwan0
E: SUBSYSTEM=net
E: USEC_INITIALIZED=174833330
E: id=1-1.3
规则:SUBSYSTEM=="usb", KERNEL=="*cdc-wdm*", ENV{id}="$id"
# udevadm info --query=all --path=/devices/platform/atmel-ehci/usb1/1-1/1-1.3/1-
1.3:1.5/usb/cdc-wdm0
P: /devices/platform/atmel-ehci/usb1/1-1/1-1.3/1-1.3:1.5/usb/cdc-wdm0
N: cdc-wdm0
E: DEVNAME=/dev/cdc-wdm0
E: DEVPATH=/devices/platform/atmel-ehci/usb1/1-1/1-1.3/1-1.3:1.5/usb/cdc-wdm0
E: MAJOR=180
E: MINOR=176
E: SUBSYSTEM=usb
E: USEC_INITIALIZED=174788259
答案1
好吧,首先我现在明白了什么文档对于$id
意味着
向上搜索 devpath 中的 SUBSYSTEMS、KERNELS、DRIVERS 和 ATTRS 时匹配的设备名称。
...这不是我想的那样(这是由于未能理解文档并结合一些实验而形成的)。
通过“设备名称”,它谈论的是与KERNEL
密钥匹配的同一事物。文档中关于KERNEL
密钥的说明是:
匹配事件设备的名称。
这就是您如何知道“名称”和“内核”相关的方式。
“在 devpath 向上搜索 SUBSYSTEMS、KERNELS、DRIVERS 和 ATTRS 时匹配”部分意味着,如果您在规则中指定了“SUBSYSTEMS、KERNELS、DRIVERS 或 ATTRS”匹配项,它将沿着设备树向上查找,直到找到匹配;将使用匹配设备的名称。
因此,在我的第一条规则中,它与 ATTRS 密钥匹配,并且该设备恰好是物理 USB 设备。
现在,对于我的另一条规则,我必须查看树并找到与物理设备匹配的东西,但不能找到其下方的任何东西。这是我的设备树:
# udevadm info --attribute-walk --name=/dev/cdc-wdm0
Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.
looking at device '/devices/platform/atmel-ehci/usb1/1-1/1-1.7/1-1.7.2/1-1.7.2:1.5/usb/cdc-wdm0':
KERNEL=="cdc-wdm0"
SUBSYSTEM=="usb"
DRIVER==""
looking at parent device '/devices/platform/atmel-ehci/usb1/1-1/1-1.7/1-1.7.2/1-1.7.2:1.5':
KERNELS=="1-1.7.2:1.5"
SUBSYSTEMS=="usb"
DRIVERS=="qmi_wwan"
ATTRS{bInterfaceNumber}=="05"
ATTRS{bAlternateSetting}==" 0"
ATTRS{bNumEndpoints}=="03"
ATTRS{bInterfaceClass}=="ff"
ATTRS{bInterfaceSubClass}=="f1"
ATTRS{bInterfaceProtocol}=="ff"
ATTRS{supports_autosuspend}=="1"
looking at parent device '/devices/platform/atmel-ehci/usb1/1-1/1-1.7/1-1.7.2':
KERNELS=="1-1.7.2"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{configuration}=="Pantech, Incorporated"
ATTRS{bNumInterfaces}==" 6"
ATTRS{bConfigurationValue}=="1"
ATTRS{bmAttributes}=="c0"
ATTRS{bMaxPower}=="500mA"
ATTRS{urbnum}=="496"
ATTRS{idVendor}=="106c"
ATTRS{idProduct}=="3718"
ATTRS{bcdDevice}=="0000"
ATTRS{bDeviceClass}=="02"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bDeviceProtocol}=="00"
ATTRS{bNumConfigurations}=="1"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{speed}=="480"
ATTRS{busnum}=="1"
ATTRS{devnum}=="12"
ATTRS{devpath}=="1.7.2"
ATTRS{version}==" 2.00"
ATTRS{maxchild}=="0"
ATTRS{quirks}=="0x0"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{authorized}=="1"
ATTRS{manufacturer}=="Pantech, Incorporated"
ATTRS{product}=="PANTECH UML290"
looking at parent device '/devices/platform/atmel-ehci/usb1/1-1/1-1.7':
KERNELS=="1-1.7"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{configuration}==""
ATTRS{bNumInterfaces}==" 1"
ATTRS{bConfigurationValue}=="1"
ATTRS{bmAttributes}=="e0"
ATTRS{bMaxPower}=="100mA"
ATTRS{urbnum}=="188"
ATTRS{idVendor}=="1a40"
ATTRS{idProduct}=="0101"
ATTRS{bcdDevice}=="0111"
ATTRS{bDeviceClass}=="09"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bDeviceProtocol}=="01"
ATTRS{bNumConfigurations}=="1"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{speed}=="480"
ATTRS{busnum}=="1"
ATTRS{devnum}=="3"
ATTRS{devpath}=="1.7"
ATTRS{version}==" 2.00"
ATTRS{maxchild}=="4"
ATTRS{quirks}=="0x0"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{authorized}=="1"
ATTRS{product}=="USB 2.0 Hub"
looking at parent device '/devices/platform/atmel-ehci/usb1/1-1':
KERNELS=="1-1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{configuration}==""
ATTRS{bNumInterfaces}==" 1"
ATTRS{bConfigurationValue}=="1"
ATTRS{bmAttributes}=="e0"
ATTRS{bMaxPower}=="100mA"
ATTRS{urbnum}=="53"
ATTRS{idVendor}=="1a40"
ATTRS{idProduct}=="0201"
ATTRS{bcdDevice}=="0100"
ATTRS{bDeviceClass}=="09"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bDeviceProtocol}=="02"
ATTRS{bNumConfigurations}=="1"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{speed}=="480"
ATTRS{busnum}=="1"
ATTRS{devnum}=="2"
ATTRS{devpath}=="1"
ATTRS{version}==" 2.00"
ATTRS{maxchild}=="7"
ATTRS{quirks}=="0x0"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{authorized}=="1"
ATTRS{product}=="USB 2.0 Hub [MTT]"
looking at parent device '/devices/platform/atmel-ehci/usb1':
KERNELS=="usb1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{configuration}==""
ATTRS{bNumInterfaces}==" 1"
ATTRS{bConfigurationValue}=="1"
ATTRS{bmAttributes}=="e0"
ATTRS{bMaxPower}==" 0mA"
ATTRS{urbnum}=="26"
ATTRS{idVendor}=="1d6b"
ATTRS{idProduct}=="0002"
ATTRS{bcdDevice}=="0206"
ATTRS{bDeviceClass}=="09"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bDeviceProtocol}=="00"
ATTRS{bNumConfigurations}=="1"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{speed}=="480"
ATTRS{busnum}=="1"
ATTRS{devnum}=="1"
ATTRS{devpath}=="0"
ATTRS{version}==" 2.00"
ATTRS{maxchild}=="3"
ATTRS{quirks}=="0x0"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{authorized}=="1"
ATTRS{manufacturer}=="Linux 2.6.39.4-acnbfx100 ehci_hcd"
ATTRS{product}=="Atmel EHCI UHP HS"
ATTRS{serial}=="atmel-ehci"
ATTRS{authorized_default}=="1"
looking at parent device '/devices/platform/atmel-ehci':
KERNELS=="atmel-ehci"
SUBSYSTEMS=="platform"
DRIVERS=="atmel-ehci"
ATTRS{companion}==""
looking at parent device '/devices/platform':
KERNELS=="platform"
SUBSYSTEMS==""
DRIVERS==""
我要匹配的设备是/devices/platform/atmel-ehci/usb1/1-1/1-1.7/1-1.7.2'
。您可以看到该设备的驱动程序是“usb”,其下方没有任何内容与之匹配。以下规则解决了我的问题,甚至应该是通用解决方案,因为我很确定 USB 驱动程序不会处理设备的端点。
DRIVERS=="usb", KERNEL=="*cdc-wdm*", ENV{id}="$id", RUN="/usr/local/bin/modem_setup.sh"
这就是我一直在寻找的结果:
# udevadm info --query=all --name=/dev/cdc-wdm0
P: /devices/platform/atmel-ehci/usb1/1-1/1-1.7/1-1.7.2/1-1.7.2:1.5/usb/cdc-wdm0
N: cdc-wdm0
E: DEVNAME=/dev/cdc-wdm0
E: DEVPATH=/devices/platform/atmel-ehci/usb1/1-1/1-1.7/1-1.7.2/1-1.7.2:1.5/usb/cdc-wdm0
E: MAJOR=180
E: MINOR=176
E: SUBSYSTEM=usb
E: USEC_INITIALIZED=12243969
E: id=1-1.7.2