I need complex and universal udev
rule to determine USB-device plugged in certain port of the any USB hub. so, i have to combine parent attributes of different layers of the device tree...
I have this:
$udevadm info --query=all --name=/dev/ttyUSB0 --attribute-walk
looking at device '/devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.4/1-1.2.4:1.0/ttyUSB0/tty/ttyUSB0':
KERNEL=="ttyUSB0"
SUBSYSTEM=="tty"
DRIVER==""
. . .
looking at parent device '/devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2.4':
KERNELS=="1-1.2.4"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
...
looking at parent device '/devices/platform/bcm2708_usb/usb1/1-1/1-1.2':
KERNELS=="1-1.2"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{devpath}=="1.2"
ATTRS{idVendor}=="0835"
...
ATTRS{idProduct}=="8500"
ATTRS{bDeviceClass}=="09"
ATTRS{product}=="USB2.0 Hub"
. . .
Then i constructed udev rule something like this to identify certain port of certain USB hub:
KERNEL=="ttyUSB[0-9]*", KERNELS=="1-1.2.4", ATTRS{idVendor}=="0835", ATTRS{idProduct}=="8500", SYMLINK+="port1"
But it's not working when i try to use attributes from different parent layers.
I know that udev supports additional attributes only from one particular parent device. But I really need to get the rule that combines attributes from 2 parent nodes of my device
Could anybody suggest the solution? Is there any trick to get it?
Udev is a device manager for Linux that dynamically creates and removes nodes for hardware devices. In short, it helps your computer find your robot easily. By default, hardware devices attached to your Linux (Ubuntu) PC will belong to the root user.
udev is a generic device manager running as a daemon on a Linux system and listening (via a netlink socket) to uevents the kernel sends out if a new device is initialized or a device is removed from the system.
After many of unsuccessful experiences, i found the solution!
The key feature of it is setting the environment variable:
vendor:id
pair and remember it in environment variable.This document helped me http://www.reactivated.net/writing_udev_rules.html
KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", SUBSYSTEMS=="usb", ATTRS{idVendor}=="05e3", ATTRS{idProduct}=="0610", ENV{USB_HUB_TYPE}="05e3:0610"
KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", SUBSYSTEMS=="usb", ATTRS{idVendor}=="0835", ATTRS{idProduct}=="8500", ENV{USB_HUB_TYPE}="0835:8500"
#
ENV{USB_HUB_TYPE}=="0835:8500", KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", KERNELS=="1-1.[2-3].4:1.0", SYMLINK+="port1"
ENV{USB_HUB_TYPE}=="0835:8500", KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", KERNELS=="1-1.[2-3].3:1.0", SYMLINK+="port2"
ENV{USB_HUB_TYPE}=="0835:8500", KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", KERNELS=="1-1.[2-3].2:1.0", SYMLINK+="port3"
ENV{USB_HUB_TYPE}=="0835:8500", KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", KERNELS=="1-1.[2-3].5.5:1.0", SYMLINK+="port4"
ENV{USB_HUB_TYPE}=="0835:8500", KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", KERNELS=="1-1.[2-3].5.2:1.0", SYMLINK+="port5"
ENV{USB_HUB_TYPE}=="0835:8500", KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", KERNELS=="1-1.[2-3].5.3:1.0", SYMLINK+="port6"
ENV{USB_HUB_TYPE}=="0835:8500", KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", KERNELS=="1-1.[2-3].5.4:1.0", SYMLINK+="port7"
#
ENV{USB_HUB_TYPE}=="05e3:0610", KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", KERNELS=="1-1.[2-3].1.1:1.0" SYMLINK+="port1"
ENV{USB_HUB_TYPE}=="05e3:0610", KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", KERNELS=="1-1.[2-3].2:1.0", SYMLINK+="port2"
ENV{USB_HUB_TYPE}=="05e3:0610", KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", KERNELS=="1-1.[2-3].1.2:1.0", SYMLINK+="port3"
ENV{USB_HUB_TYPE}=="05e3:0610", KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", KERNELS=="1-1.[2-3].3:1.0", SYMLINK+="port4"
ENV{USB_HUB_TYPE}=="05e3:0610", KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", KERNELS=="1-1.[2-3].1.3:1.0", SYMLINK+="port5"
ENV{USB_HUB_TYPE}=="05e3:0610", KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", KERNELS=="1-1.[2-3].4:1.0", SYMLINK+="port6"
ENV{USB_HUB_TYPE}=="05e3:0610", KERNEL=="ttyUSB[0-9]*", SUBSYSTEM=="tty", KERNELS=="1-1.[2-3].1.4:1.0", SYMLINK+="port7"
Perhaps, it will be useful for someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With