0

I was trying to solve my problem looking at other threads such as Why My USB port fixing udev rules are not working and udev rules doesn't work with small number among other several posts regarding udev rules but none of the posts I've checked is helping me to find out why I'm experiencing this issue.

udev rule with bInterfaceNumber doesn't work is a very very similar problem to the one I have, essentially the same, but it doesn't have an answer since 2013 and I think is forgotten by now.

I have the following rules that work perfectly:

SUBSYSTEM=="tty", SUBSYSTEMS=="usb-serial", DRIVERS=="mos7840", ATTRS{port_number}=="0", SYMLINK+="USB-RS232-0", MODE="0777"
SUBSYSTEM=="tty", SUBSYSTEMS=="usb-serial", DRIVERS=="mos7840", ATTRS{port_number}=="1", SYMLINK+="USB-RS232-1", MODE="0777"
SUBSYSTEM=="tty", SUBSYSTEMS=="usb-serial", DRIVERS=="ftdi_sio", ATTRS{port_number}=="0", SYMLINK+="USB-TTL-0", MODE="0777"

The problem is that I have 2 devices that are the same and the only difference between the attributes of the two is the serial number, they even have the same VID/PID, therefore I need to add ATTRS{serial} to the rules to end up having:

SUBSYSTEM=="tty", SUBSYSTEMS=="usb-serial", DRIVERS=="mos7840", ATTRS{port_number}=="0", SYMLINK+="USB-RS232-0", MODE="0777"
SUBSYSTEM=="tty", SUBSYSTEMS=="usb-serial", DRIVERS=="mos7840", ATTRS{port_number}=="1", SYMLINK+="USB-RS232-1", MODE="0777"
SUBSYSTEM=="tty", SUBSYSTEMS=="usb-serial", DRIVERS=="ftdi_sio", ATTRS{port_number}=="0", ATTRS{serial}=="AFYS1HLQ", SYMLINK+="USB-TTL-0", MODE="0777"
SUBSYSTEM=="tty", SUBSYSTEMS=="usb-serial", DRIVERS=="ftdi_sio", ATTRS{port_number}=="0", ATTRS{serial}=="FTV8IUSR", SYMLINK+="USB-TTL-1", MODE="0777"

So after adding ATTRS{serial} to the two last rules then both stop working.

Why is this?

Thanks!!

m4l490n
  • 722
  • 5
  • 13
  • Have you checked in `/sys` or `udevadm info -a` that they (or a parent device) _do_ actually have a file named `serial` with that exact content? – u1686_grawity Nov 07 '16 at 05:40
  • @grawity yes I have checked, that is the exact information for both devices – m4l490n Nov 07 '16 at 07:08
  • 1
    Are the `port_number` and `serial` in the same device directory? `ATTRS` is a bit surprising, in that although it searches up the tree, it performs all matches at the same level in the tree. – Toby Speight Nov 09 '16 at 09:25
  • @TobySpeight I changed my rule to include just attributes from the same directory and it works, nevertheless, the first set of rules work and they are not in the same directory. So why is this? – m4l490n Nov 09 '16 at 18:44

1 Answers1

1

The key piece of information is in this paragraph in the udev(7) man page (my emhpasis):

ATTRS{filename}

Search the devpath upwards for a device with matching sysfs attribute values. If multiple ATTRS matches are specified, all of them must match on the same device. Trailing whitespace in the attribute values is ignored unless the specified match value itself contains trailing whitespace.

So if you have more than one ATTRS rule (as you do), all the properties (filenames) matched must be in the same device directory.

This does not need to be the same device that matches a SUBSYSTEMS or DRIVERS rule.

Toby Speight
  • 4,866
  • 1
  • 26
  • 36
  • Ok, so the thing is if my rule is going to be based on multiple ATTRS{filename} then all of these have to be in the same directory. That makes sense since "port_number" and "serial" are not in the same directory then the rule was failing. But when I modified it to include ATTRS just from one directory then the rules worked. Thanks!! – m4l490n Nov 09 '16 at 20:15