Create udev rule for USB device with multiple virtual ports

lilipop2513

New Member
Joined
Jun 15, 2023
Messages
3
Reaction score
0
Credits
36
Hello Linux Community !

In my embedded project, I came across working with multiple USB devices. So, to avoid checking each time the new port of each device and setting that in my code, I decided to use udev rules to have a unique access to each device.

However, in that process, one device is causing a problem since it has 2 virtual ports (config + data). If I do a standard udev rule for it, I get one access created to the config port only.

Any clues on how to set udev rules for device with 2 virtual ports ?

Thanks in advance,
Lilia :)
 


wizardfromoz

Administrator
Staff member
Gold Supporter
Joined
Apr 30, 2017
Messages
9,186
Reaction score
8,138
Credits
39,448
G'day Lilia and welcome to linux.org :)

This is beyond my knowledge but by my mentioning the following Members -

@JasKinasis , @dos2unix , @osprey , @f33dm3bits (and there are likely others) I have brought this Thread to their attention.

Make allowance for timezone differences.

Once one of those folks lets me know, I may move this Thread to our Command Line subforum, if it involves, as I suspect, writing udev rules.

Good luck

Chris Turner
wizardfromoz
 

osprey

Well-Known Member
Joined
Apr 15, 2022
Messages
1,125
Reaction score
1,102
Credits
10,705
What comes to mind as an initial thought is that it's quite possible to have multiple rules for the same device, so, for example, if you could create a rule each for the two components (the 2 virtual ports), they could be in files with numbers close to each other (e.g. 70-<name>.rules, and 71-<name2>.rules) to determine the order of execution, or, one can have multiple rules in the same file with the rules separated by new lines with each run on a single line. I suppose it's going to depend on whether udevadm identifies the two components. Just thinking.
 
OP
L

lilipop2513

New Member
Joined
Jun 15, 2023
Messages
3
Reaction score
0
Credits
36
What comes to mind as an initial thought is that it's quite possible to have multiple rules for the same device, so, for example, if you could create a rule each for the two components (the 2 virtual ports), they could be in files with numbers close to each other (e.g. 70-<name>.rules, and 71-<name2>.rules) to determine the order of execution, or, one can have multiple rules in the same file with the rules separated by new lines with each run on a single line. I suppose it's going to depend on whether udevadm identifies the two components. Just thinking.
Hey, thanks for the reply.

It is actually one component with 2 virtual ports, means the two has same vendor id, product id and so on. I don't seem to find something that could make the difference between the two.

If you have any ideas, tell me please.
 

dos2unix

Well-Known Member
Joined
May 3, 2019
Messages
2,112
Reaction score
1,728
Credits
15,288
Even though it's the same device, aren't the ports identified uniquely?
 
OP
L

lilipop2513

New Member
Joined
Jun 15, 2023
Messages
3
Reaction score
0
Credits
36
Even though it's the same device, aren't the ports identified uniquely?
Yes the ports are identified uniquely in the /dev directory (exp : ttyUSB0 & ttyUSB1).

Let me reput my question in a better way :

1- Here's a look at what my first tested rule looked like :
Bash:
SUBSYSTEM=="tty", SUBSYSTEMS=="usb", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea70", SYMLINK+="ttyDevice"

I thought that since the device has 2 virtual ports, it would create 2 symlinks but when it takes effect it only gives one symlink that neither allows access to the config nor to the data (basically does nothing).

2- Now, to create my rule, I use the following command for each port (USB0 & USB1) :
Bash:
$udevadm info --attribute-walk /dev/ttyUSB0

However the result gives same details for both ports (Vendor Id, Product Id... everything). The only and unique difference I seem to find is the following :
USB0 : ATTRS{interface}=="Enhanced Com Port"
USB1 : ATTRS{interface}=="Standard Com Port"

If I test making two rules with this slight difference :
Bash:
SUBSYSTEM=="tty", SUBSYSTEMS=="usb", ATTRS{interface}=="Standard Com Port", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea70", SYMLINK+="ttyDeviceStandard"
SUBSYSTEM=="tty", SUBSYSTEMS=="usb", ATTRS{interface}=="Enhanced Com Port", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea70", SYMLINK+="ttyDeviceEnhanced"
It does not work.

PS : I make sure to reload the rules each time with the command below and a reboot
Bash:
sudo udevadm control --reload-rules && udevadm trigger

So to sum it up, my question is :
what's the thing that I can add in the rule of each virtual port to distinguish between them and make sure each has a proper symlink for it ?
Or is there a better way to proceed, am I doing things wrong ?
If you have any clues please share them :confused:
Thank you !
 

Dense

New Member
Joined
Jul 15, 2023
Messages
1
Reaction score
0
Credits
7
Same question here. Teensy set up for 3 serial ports appears in /dev/ as ttyACM(n), ttyACM(n+1), ttyACM(n+2) Where n depends on previous devices loaded or not. How to make udev rules to assign 3 symlinks where all device attributes are the same?
 

Members online


Latest posts

Top