[PD] hid, routing different devices

Frank Barknecht fbar at footils.org
Sun Apr 15 12:12:10 CEST 2007


Hallo,
Hans-Christoph Steiner hat gesagt: // Hans-Christoph Steiner wrote:

> How does it do keep the device ID the same (i.e. what's the device ID  
> based on)? 

I'm no kernel developer. ;) But it's taken from the info you also see
in the syslog when plugging in a device or from "lsusb -v" or
/sys/bus/usb/devices/ etc. 

> From what I have seen, there isn't a way to do this is  
> the USB serial number field isn't used (and it's rarely used).   
> Usually, USB device IDs are built up from port number, bus number and  
> maybe some info from the device plugged in.  But obviously, if you  
> plug a device into a different port, such a device ID will change.

USB devices send their own info as well. For example to configure the
order of USB soundcards with ALSA you can use the Vendor and Product
IDs as module options. These are  independent from port or bus number
of course.

I discovered the "by-id" and "by-name" directories in the /dev-tree when
configuring automatic mounting of USB storage devices like card reader or
external disks. There you can use the permanent names in the automount config
(or in /etc/fstab etc.) Here's a snippet of /etc/auto.usbdisk where I configure
automounting the three partitions on my Maxtor USB drive:

m1      -fstype=auto,rw       :/dev/disk/by-id/usb-Maxtor_3200_UA076GPC-part1
m2      -fstype=auto,rw       :/dev/disk/by-id/usb-Maxtor_3200_UA076GPC-part2
m3      -fstype=auto,rw       :/dev/disk/by-id/usb-Maxtor_3200_UA076GPC-part3

> Also, how does udev deal with multiple USB devices of the exact same  
> type?

I tested this now with a second mouse of the same type. This is what
happened after I plugged in a second mouse: 

(~)-$ ls -l  /dev/input/by-id/
total 0
lrwxrwxrwx 1 root root 9 Apr 15 11:52 usb-Logitech_USB-PS.2_Optical_Mouse-event-mouse -> ../event5
lrwxrwxrwx 1 root root 9 Apr 15 11:52 usb-Logitech_USB-PS.2_Optical_Mouse-mouse -> ../mouse1

Somehow the previous entry (mouse0 and event4, see prev. mail) was overwritten.
But now I get more devices in /dev/input/by-path/:

(~)-$ ls -l  /dev/input/by-path/
total 0
lrwxrwxrwx 1 root root 9 Mar  4 11:53 pci-0000:00:0a.0--event-ir -> ../event2
lrwxrwxrwx 1 root root 9 Mar  4 11:53 pci-0000:00:10.0-usb-0:2:1.0-event-mouse -> ../event4
lrwxrwxrwx 1 root root 9 Mar  4 11:53 pci-0000:00:10.0-usb-0:2:1.0-mouse -> ../mouse0
lrwxrwxrwx 1 root root 9 Apr 15 11:52 pci-0000:00:10.3-usb-0:1:1.0-event-mouse -> ../event5
lrwxrwxrwx 1 root root 9 Apr 15 11:52 pci-0000:00:10.3-usb-0:1:1.0-mouse -> ../mouse1
lrwxrwxrwx 1 root root 9 Mar  4 11:53 pci-0000:00:10.4-usb-0:1.4:1.3-event- -> ../event3
lrwxrwxrwx 1 root root 9 Mar  4 11:53 platform-i8042-serio-1-event-kbd -> ../event0
lrwxrwxrwx 1 root root 9 Mar  4 11:53 platform-pcspkr-event-spkr -> ../event1

Both mouses work. Unplugging the second mouse again has strange results: Now
the whole "by-id" directory disappears: 

$ ls -l  /dev/input/by-id/
ls: /dev/input/by-id/: No such file or directory

but "by-path" correctly shows the removal of one mouse:

$ ls -l  /dev/input/by-path/
total 0
lrwxrwxrwx 1 root root 9 Mar  4 11:53 pci-0000:00:0a.0--event-ir -> ../event2
lrwxrwxrwx 1 root root 9 Mar  4 11:53 pci-0000:00:10.0-usb-0:2:1.0-event-mouse -> ../event4
lrwxrwxrwx 1 root root 9 Mar  4 11:53 pci-0000:00:10.0-usb-0:2:1.0-mouse -> ../mouse0
lrwxrwxrwx 1 root root 9 Mar  4 11:53 pci-0000:00:10.4-usb-0:1.4:1.3-event- -> ../event3
lrwxrwxrwx 1 root root 9 Mar  4 11:53 platform-i8042-serio-1-event-kbd -> ../event0
lrwxrwxrwx 1 root root 9 Mar  4 11:53 platform-pcspkr-event-spkr -> ../event1

I guess this is a bug in udev.

Anyway, the "by-something" entries are generated automatically and
they arwe very conventient. 

However it is also possible to create device entries by hand with
udev-rules.  This is documented on several websites for dealing with
USB storage devices, e.g.
http://www.debian-administration.org/articles/126

It shouldn't be too hard to adapt these to HID devices as well if
needed.

Ciao
-- 
 Frank Barknecht                 _ ______footils.org_ __goto10.org__




More information about the Pd-list mailing list