Udev rule to match multiple node USB device
Solution 1
Your rules all have syntax errors in them:
-
=
is for assignment==
is for comparison, so you were not actually looking at whatDEV
equaled, you were assigning it. - You need
,
between all the statements, there were none beforeSYMLINK+=
.
Fist Rule
ACTION=="add", DEV=="/devices/platform/pxa27x-ohci/usb1/1-2/1-2.2/1-2.2:1.0", SYMLINK+="huawey0"
Second Rule
ACTION=="add", KERNEL=="1-2.2:1.0", SYMLINK+="huawey0"
Third Rule
ACTION=="add", DEV=="/devices/platform/pxa27x-ohci/usb1/1-2/1-2.2/1-2.2:1.[0-4]", ATTR{bInterfaceNumber}=="00", SYMLINK+="huawey0"
Fourth Rule
ACTION=="add", ATTR{bInterfaceNumber}=="00", SYMLINK+="huawey0"
All these rules should do what you want now (I would use the first one personally).
Solution 2
Although this post was asked three years ago, and this might not address the answer, I still want to share my successful experience here for the future reference.
According to Jens Reimann's Identify GSM modem devices using udev, "the device attribute “bInterfaceNumber” is not on the tty device, but on the usb device in the parent hierarchy", so I created two rules for my FTDI usb-to-4-port-serial adapter:
SUBSYSTEMS=="usb", ENV{.LOCAL_ifNum}="$attr{bInterfaceNumber}"
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6011", SYMLINK+="ttyUSB_FTDI_4_PORT_%E{.LOCAL_ifNum}"
This stores the attribute “bInterfaceNumber” into the environment variable “.LOCAL_ifNum” (the prefixed dot is a notation for temporary or hidden variables). In the second rule the same variable is pulled on using the “%E” syntax. Newer udev versions also support “$env” instead of “%E”.
(by Jens Reimann)
where ttyUSB_FTDI_4_PORT_
is the symlink name.
These two rules will create symlinks as ttyUSB_FTDI_4_PORT_00
, ttyUSB_FTDI_4_PORT_01
, ttyUSB_FTDI_4_PORT_02
, ttyUSB_FTDI_4_PORT_03
.
You can add ATTRS{serial}
attribute to constrain the enumeration further.
Jens Reimann also acknowlegfed the contribution of Ketan Patel's U&L question, Udev rule file for modem not working, with accepted answer by derobert.
Related videos on Youtube
Joao Pincho
A programmer by job and hobby, I like to try out new stuff, mix software with hardware and make it go BOOM! ( Preferably not, but ok ). Linux addict all the way.
Updated on September 18, 2022Comments
-
Joao Pincho over 1 year
I have a 3G/GPS device that creates 5 tty nodes, although it's only one physical USB connection. Basically, a multi port usb-serial adapter.
I'm trying to create some
udev
rules to make sure those nodes always have the same name, or at least a symlink to them.I can indeed find the device at
/sys/devices/platform/pxa27x-ohci/usb1/1-2/1-2.2/
. Inside are1-2.2:1.0/
to1-2.2:1.4/
, for the 5 nodes it creates.I can also find it at
/sys/bus/usb/devices/1-2.2
.The udev info for the device is as follows:
udevadm info -a -p /sys/bus/usb/devices/1-2.2/1-2.2\:1.0 looking at device '/bus/usb/devices/1-2.2/1-2.2:1.0': KERNEL=="1-2.2:1.0" SUBSYSTEM=="usb" DRIVER=="option" ATTR{bInterfaceNumber}=="00" ATTR{bAlternateSetting}==" 0" ATTR{bNumEndpoints}=="03" ATTR{bInterfaceClass}=="ff" ATTR{bInterfaceSubClass}=="01" ATTR{bInterfaceProtocol}=="01" ATTR{modalias}=="usb:v12D1p1506d0000dc00dsc00dp00icFFisc01ip01" ATTR{supports_autosuspend}=="0"
From this point on, all the nodes have the same info. And the only thing varying between nodes is the bInterfaceNumber property, and the device path. So, I thought of writing a rule by dev path.
Now, for some reason, the following rule gets matched by all those nodes.
ACTION=="add", DEV="/devices/platform/pxa27x-ohci/usb1/1-2/1-2.2/1-2.2:1.0" SYMLINK+="huawey0"
So basically,
huawey0
points to the last node enumerated. The device created nodes from ttyUSB2 to 6, and this link points to USB6.So, I tried by kernel node:
ACTION=="add", KERNEL=="1-2.2:1.0" SYMLINK+="huawey0"
Now, nothing appears on /dev.
After this, I tried using the bInterfaceNumber to separate them. I used the following rule
ACTION=="add", DEV="/devices/platform/pxa27x-ohci/usb1/1-2/1-2.2/1-2.2:1.[0-4]" ATTR{bInterfaceNumber}=="00" SYMLINK+="huawey0"
And still, nothing happens. I even tried a trimmed down version of the rule..
ACTION=="add", ATTR{bInterfaceNumber}=="00" SYMLINK+="huawey0"
And still nothing happens. Why is it not matching?