UDEV-How to get value of a child device attributes
Asked Answered
T

2

6

I am writting an udev rule to set name of two serial ports. I want to use the value of the attribute bInterfaceNumber in the symlink.

My rules is:

SUBSYSTEMS=="usb", DRIVERS=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", SYMLINK+="toto%s{bInterfaceNumber}"

The rule matched the device but value of the attribute is never found.

Here is the hierarchical view of one device:

console@host:udevadm info --name=/dev/ttyUSB0 --attribute-walk
looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1:1.0':
    KERNELS=="1-1:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="ftdi_sio"
    ATTRS{bInterfaceNumber}=="00"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb1/1-1':
    KERNELS=="1-1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{idVendor}=="0403"
    ATTRS{idProduct}=="6010"

Thanks in advance

Tish answered 9/10, 2013 at 13:25 Comment(0)
M
4

This is a rule I made to create an alias for a dual port FTDI chip:

# Internal serial ports
SUBSYSTEMS=="usb", ATTRS{interface}=="Dual RS232", SYMLINK+="sertest%s{bInterfaceNumber}"

According to this post, the attributes must be matching on one level. That's why idVendor and idProduct won't work with bInterfaceNumber. Below, you can see that interface and bInterfaceNumber belong to the same level:

looking at parent device '/devices/platform/omap/musb-ti81xx/musb-hdrc.1/usb1/1-1/1-1.2/1-1.2:1.0':
KERNELS=="1-1.2:1.0"
SUBSYSTEMS=="usb"
DRIVERS=="ftdi_sio"
ATTRS{bInterfaceNumber}=="00"
ATTRS{bAlternateSetting}==" 0"
ATTRS{bNumEndpoints}=="02"
ATTRS{bInterfaceClass}=="ff"
ATTRS{bInterfaceSubClass}=="ff"
ATTRS{bInterfaceProtocol}=="ff"
ATTRS{supports_autosuspend}=="1"
ATTRS{interface}=="Dual RS232"
Mentholated answered 10/10, 2013 at 6:43 Comment(1)
Thanks for the answer. I done the same rule. I would have liked to use idvendor to be more precise.Tish
H
1

I think you can use environmental variables like that.

In your case it will be something like this:

SUBSYSTEM=="usb", DRIVER=="ftdi_sio", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010" ENV{MY_DEV}="yes"

ENV{MY_DEV}="yes", SUBSYSTEMS=="usb", SYMLINK+="toto%s{bInterfaceNumber}"
Hypotenuse answered 6/2, 2015 at 11:39 Comment(1)
That did not quite work, but with some inspiration from /usr/lib/udev/rules.d/60-serial.rules: SUBSYSTEMS=="usb", ENV{ID_USB_INTERFACE_NUM}="$attr{bInterfaceNumber}" SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6011", SYMLINK+="tty%s{serial}_$env{ID_USB_INTERFACE_NUM}"Seashore

© 2022 - 2024 — McMap. All rights reserved.