2

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==""
4
  • Is this the complete output of yr udevadm info ... command ? An expanded output, extending to the parent hierarchy would be useful. Can you please edit yr post with that added info ?
    – Cbhihe
    Jan 19 '16 at 11:26
  • I added the attribute-walk with parent devices.
    – beepbeep
    Jan 19 '16 at 20:32
  • If you have a solution of yr own, please post and mark it as the answer with a green check mark. If not, let me know with a comment starting with @Cbhihe how the cookie crumbles. We'll take it from there.
    – Cbhihe
    Jan 23 '16 at 11:15
  • @beepbeep , welcome to Ask Ubuntu, There no way to distinguish between two identical (clone) device. However, you posted only output from single joystick (js2) . Could plug both joysticks, get outputs for both and update the question. let us see what you see.
    – user.dz
    Jan 27 '16 at 19:11
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.

4
  • The product id, vendor id and serial numbers are identical. The link you provided in part A may be helpful. I need to review, test and update once I get a result. The KERNELS name is coming up with "input33" and "input34" so it is making a distinction even if I connect them to the same port. I may be able to work with that.
    – beepbeep
    Jan 19 '16 at 20:58
  • @beepbeep: answer update to reflect yr new info. See A). I could not try this on my systems because I do not have similar gamepads handy. HTH.
    – Cbhihe
    Jan 20 '16 at 0:05
  • Unfortunately no luck. I need to correct my previous comment. The kernel is automatically incrementing the KERNELS value by one each time I connect the device. If I connect/disconnect/connect the same device it increments the input## name. I did a diff on the attribute-walk for both devices and they only differ by that increment. In general this doesn't help and the counter resets after reboot.
    – beepbeep
    Jan 24 '16 at 11:22
  • @beepbeep: Please do update yr post with that last info on KERNELS being incremented upon each successive mount with no intervening reboot. <<- This will benefit future readers. See my updated answer's udev rule (case A).
    – Cbhihe
    Jan 24 '16 at 17:23
0

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.

2
  • Correct. and far from ideal, as you well noted: OP would really have to stick to the same USB ports not to render his/her udev rule completely ineffectual.
    – Cbhihe
    Jan 19 '16 at 10:24
  • In this case there will only be 4 USB ports accessible and I'll be using the path to identify players 1-4. Player 1 may use any kind of gamepad and so on.
    – beepbeep
    Jan 19 '16 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.