I have several USB modems that each have several endpoints: lot of TTYs, a network interface, a cdc-wdm port, and some other things. I'm trying to group them together so that I know, for instance, ttyUSB3, ttyUSB4, wwan1, and cdc-wdm1 all belong to the same physical USB device.
I thought $id
was supposed to identify the physical device, so I tried adding $id
to the environment with ENV{id}=$id
. This seems to work for the network interfaces and serial ports, but not the cdc-wdm ports (id is unset for these ports).
Here is some example data after adding the ENV{id}=$id
rules:
rule: 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
rule: 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
Best Answer
Okay, first I now understand what the documentation for
$id
means by...and it's not what I thought (which was formed by failing to understand the documentation combined with some experimentation).
By "The name of the device", it's talking about the same thing the
KERNEL
key matches. The documentation says about theKERNEL
key is:That is how you know "name" and "KERNEL" are related.
The "matched while searching the devpath upwards for SUBSYSTEMS, KERNELS, DRIVERS and ATTRS" part means that if you specified a "SUBSYSTEMS, KERNELS, DRIVERS, or ATTRS" match in the rule, it will walk up the device tree until it finds a match; the name of the matched device will be used.
So, in my first rule, it was matching with the ATTRS key, and that device happened to be the physical USB device.
Now for my other rule, I had to look at the tree and find something that would match the physical device but not anything below it. Here is my device tree:
The device I want to match is
/devices/platform/atmel-ehci/usb1/1-1/1-1.7/1-1.7.2'
. You can see that the DRIVERS for that device is 'usb' and nothing below it will match that. The following rule solves my problem, should even be a generic solution since I'm pretty sure no endpoint of a device would be handled by the usb driver.And the is the result I was looking for all along: