Ubuntu: Use udev to rename devices with same properties



Question:

I have two types of gamepad that have the same udev properties. One is a USB NES controller and the other is a USB SNES controller. The udev info is identical for both of them.

P: /devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-1/3-1:1.0/input/input18/js2  N: input/js2  S: input/by-id/usb-0079_USB_Gamepad-joystick  S: input/by-path/pci-0000:0e:00.0-usb-0:1:1.0-joystick  E: DEVLINKS=/dev/input/by-id/usb-0079_USB_Gamepad-joystick /dev/input/by-path/pci-0000:0e:00.0-usb-0:1:1.0-joystick  E: DEVNAME=/dev/input/js2  E: DEVPATH=/devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-1/3-1:1.0/input/input18/js2  E: ID_BUS=usb  E: ID_FOR_SEAT=input-pci-0000_0e_00_0-usb-0_1_1_0  E: ID_INPUT=1  E: ID_INPUT_JOYSTICK=1  E: ID_MODEL=USB_Gamepad  E: ID_MODEL_ENC=USB\x20Gamepad\x20  E: ID_MODEL_ID=0011  E: ID_PATH=pci-0000:0e:00.0-usb-0:1:1.0  E: ID_PATH_TAG=pci-0000_0e_00_0-usb-0_1_1_0  E: ID_REVISION=0106  E: ID_SERIAL=0079_USB_Gamepad  E: ID_TYPE=hid  E: ID_USB_DRIVER=usbhid  E: ID_USB_INTERFACES=:030000:  E: ID_USB_INTERFACE_NUM=00  E: ID_VENDOR=0079  E: ID_VENDOR_ENC=0079  E: ID_VENDOR_ID=0079  E: MAJOR=13  E: MINOR=2  E: SUBSYSTEM=input  E: TAGS=:seat:uaccess:  E: USEC_INITIALIZED=738808992  

The application uses the ID_MODEL value to identify the controller and assign a button map. I have several gamepads that do the same thing but am keeping it to 2 for this example.

How would I get udev to either rename or alias ifferent devices that have the same info? What would that rule look like?

  looking at device '/devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-1/3-1:1.0/input/input32/js2':      KERNEL=="js2"      SUBSYSTEM=="input"      DRIVER==""      looking at parent device '/devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-1/3-1:1.0/input/input32':      KERNELS=="input32"      SUBSYSTEMS=="input"      DRIVERS==""      ATTRS{name}=="USB Gamepad "      ATTRS{phys}=="usb-0000:0e:00.0-1/input0"      ATTRS{uniq}==""      ATTRS{properties}=="0"      looking at parent device '/devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-1/3-1:1.0':      KERNELS=="3-1:1.0"      SUBSYSTEMS=="usb"      DRIVERS=="usbhid"      ATTRS{bInterfaceClass}=="03"      ATTRS{bInterfaceSubClass}=="00"      ATTRS{bInterfaceProtocol}=="00"      ATTRS{bNumEndpoints}=="01"      ATTRS{supports_autosuspend}=="1"      ATTRS{bAlternateSetting}==" 0"      ATTRS{bInterfaceNumber}=="00"      looking at parent device '/devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-1':      KERNELS=="3-1"      SUBSYSTEMS=="usb"      DRIVERS=="usb"      ATTRS{bDeviceSubClass}=="00"      ATTRS{bDeviceProtocol}=="00"      ATTRS{devpath}=="1"      ATTRS{idVendor}=="0079"      ATTRS{speed}=="1.5"      ATTRS{bNumInterfaces}==" 1"      ATTRS{bConfigurationValue}=="1"      ATTRS{bMaxPacketSize0}=="8"      ATTRS{busnum}=="3"      ATTRS{devnum}=="15"      ATTRS{configuration}==""      ATTRS{bMaxPower}=="100mA"      ATTRS{authorized}=="1"      ATTRS{bmAttributes}=="80"      ATTRS{bNumConfigurations}=="1"      ATTRS{maxchild}=="0"      ATTRS{bcdDevice}=="0106"      ATTRS{avoid_reset_quirk}=="0"      ATTRS{quirks}=="0x0"      ATTRS{version}==" 1.00"      ATTRS{urbnum}=="13"      ATTRS{ltm_capable}=="no"      ATTRS{removable}=="unknown"      ATTRS{idProduct}=="0011"      ATTRS{bDeviceClass}=="00"      ATTRS{product}=="USB Gamepad "      looking at parent device '/devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3':      KERNELS=="usb3"      SUBSYSTEMS=="usb"      DRIVERS=="usb"      ATTRS{bDeviceSubClass}=="00"      ATTRS{bDeviceProtocol}=="01"      ATTRS{devpath}=="0"      ATTRS{idVendor}=="1d6b"      ATTRS{speed}=="480"      ATTRS{bNumInterfaces}==" 1"      ATTRS{bConfigurationValue}=="1"      ATTRS{bMaxPacketSize0}=="64"      ATTRS{authorized_default}=="1"      ATTRS{busnum}=="3"      ATTRS{devnum}=="1"      ATTRS{configuration}==""      ATTRS{bMaxPower}=="0mA"      ATTRS{authorized}=="1"      ATTRS{bmAttributes}=="e0"      ATTRS{bNumConfigurations}=="1"      ATTRS{maxchild}=="2"      ATTRS{bcdDevice}=="0313"      ATTRS{avoid_reset_quirk}=="0"      ATTRS{quirks}=="0x0"      ATTRS{serial}=="0000:0e:00.0"      ATTRS{version}==" 2.00"      ATTRS{urbnum}=="241"      ATTRS{ltm_capable}=="no"      ATTRS{manufacturer}=="Linux 3.13.0-74-generic xhci_hcd"      ATTRS{removable}=="unknown"      ATTRS{idProduct}=="0002"      ATTRS{bDeviceClass}=="09"      ATTRS{product}=="xHCI Host Controller"      looking at parent device '/devices/pci0000:00/0000:00:1c.6/0000:0e:00.0':      KERNELS=="0000:0e:00.0"      SUBSYSTEMS=="pci"      DRIVERS=="xhci_hcd"      ATTRS{irq}=="18"      ATTRS{subsystem_vendor}=="0x17aa"      ATTRS{broken_parity_status}=="0"      ATTRS{class}=="0x0c0330"      ATTRS{consistent_dma_mask_bits}=="64"      ATTRS{dma_mask_bits}=="64"      ATTRS{local_cpus}=="00000000,00000000,00000000,00000000,00000000,00000000,00000000,000000ff"      ATTRS{device}=="0x0194"      ATTRS{enable}=="1"      ATTRS{msi_bus}==""      ATTRS{local_cpulist}=="0-7"      ATTRS{vendor}=="0x1033"      ATTRS{subsystem_device}=="0x21cf"      ATTRS{numa_node}=="-1"      ATTRS{d3cold_allowed}=="1"      looking at parent device '/devices/pci0000:00/0000:00:1c.6':      KERNELS=="0000:00:1c.6"      SUBSYSTEMS=="pci"      DRIVERS=="pcieport"      ATTRS{irq}=="18"      ATTRS{subsystem_vendor}=="0x17aa"      ATTRS{broken_parity_status}=="0"      ATTRS{class}=="0x060400"      ATTRS{consistent_dma_mask_bits}=="32"      ATTRS{dma_mask_bits}=="32"      ATTRS{local_cpus}=="00000000,00000000,00000000,00000000,00000000,00000000,00000000,000000ff"      ATTRS{device}=="0x1c1c"      ATTRS{enable}=="2"      ATTRS{msi_bus}=="1"      ATTRS{local_cpulist}=="0-7"      ATTRS{vendor}=="0x8086"      ATTRS{subsystem_device}=="0x21cf"      ATTRS{numa_node}=="-1"      ATTRS{d3cold_allowed}=="0"      looking at parent device '/devices/pci0000:00':      KERNELS=="pci0000:00"      SUBSYSTEMS==""      DRIVERS==""  


Solution:1

It may happen that vendor_id, product_id AND serial_nbr are all identical for different physical devices. To check look up yr /var/log/messages after plugging in your devices, one by one to be able to differentiate them in the better case where some difference in id will crop up between them.

A) If, in addition to product's id and vendor's id, serial numbers are also identical across devices, read up here (as pointed out by @ChrisObrian in a previous answer). His answer is identical in principle to that provided by @Grumbel in this thread. This would also probably make yr post a duplicate. In any case, searching the devpath upwards for a matching device name, yr udev rule can be:

SUBSYSTEMS=="input", ATTRS{name}=="USB Gamepad ", KERNELS=="input[0-9]*", SYMLINK+="gamepad_Z"  

B) In case serial numbers are not identical, you'd have the following simple udev rule (one per device):

SUBSYSTEM=="input", ATTRS{idVendor}=="0079", ATTRS{idProduct}=="XXXX", ATTRS{serial}=="YYYYYY", SYMLINK+="gamepad_Z"  

where you will have to fill in XXXX and YYYYYY with proper values from output from udevadmin info ... or from /var/log/messages when devices are plugged in.

NOTE: In both cases above, you choose Z arbitrarily. Yr devices will show up as /dev/gamepad_Z pointing always to the same physical devices.


Solution:2

If you can't tell the devices apart by other means you can always use the USB path via ID_PATH, as that is the name of the actual USB port the device is connected to. You then just have to plug the device always into the same USB port.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »