udev rule with few parent device attributes

后端 未结 2 517
逝去的感伤
逝去的感伤 2021-02-10 00:07

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 laye

2条回答
  •  迷失自我
    2021-02-10 00:46

    After many of unsuccessful experiences, i found the solution!

    The key feature of it is setting the environment variable:

    1. On plugging event, we looking the vendor:id pair and remember it in environment variable.
    2. On the same event, we compare the saved variable and usb-device tree nodes IDs to assign exact names of ports of certain 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, it will be useful for someone.

提交回复
热议问题