UDEV-How to get value of a child device attributes

試著忘記壹切 提交于 2019-12-13 01:22:03

问题


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


回答1:


This is rule I made to create an alias for 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"



回答2:


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}"


来源:https://stackoverflow.com/questions/19273418/udev-how-to-get-value-of-a-child-device-attributes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!