linux - udev rule with few parent device attributes -
i need complex , universal udev
rule determine usb-device plugged in port of usb hub. so, have combine parent attributes of different layers of device tree...
i have this:
$udevadm info --query=all --name=/dev/ttyusb0 --attribute-walk looking @ 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 @ 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 @ 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 constructed udev rule identify port of 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 try use attributes different parent layers.
i know udev supports additional attributes 1 particular parent device. need rule combines attributes 2 parent nodes of device
could suggest solution? there trick it?
after many of unsuccessful experiences, found solution!
the key feature of setting environment variable:
- on plugging event, looking
vendor:id
pair , remember in environment variable. - on same event, compare saved variable , usb-device tree nodes ids assign exact names of ports of usb-hub.
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, useful someone.
Comments
Post a Comment