Finch Udev rules

Getting the Initial Information

First plug the finch in and run dmesg to see what the system log made of it:

[merichar@dormouse ~]% dmesg | tail
[226206.828073] usb 5-1: new full speed USB device using uhci_hcd and address 11
[226207.008109] usb 5-1: New USB device found, idVendor=2354, idProduct=1111
[226207.008118] usb 5-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[226207.008125] usb 5-1: Product: Finch
[226207.008130] usb 5-1: Manufacturer: BirdBrain Tools
[226207.146317] generic-usb 0003:2354:1111.0001: hiddev0,hidraw0: USB HID v1.11 Device [BirdBrain Tools Finch] on usb-0000:00:1d.0-1/input0
[226207.146386] usbcore: registered new interface driver usbhid
[226207.146388] usbhid: USB HID core driver

Since it was successfully presenting itself as a usb device, we could also use lsusb to obtain details about it (and the other usb devices associated):

[merichar@dormouse ~]% lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
...
Bus 003 Device 009: ID 0a5c:2110 Broadcom Corp. Bluetooth Controller
Bus 005 Device 013: ID 2354:1111

Even though lsusb didn’t provide the human-readable vendor and product information, the vendor and product IDs match those of the dmesg output above.
So now we know that the vendor ID for the finch is 2354 and the product id is 1111.

We can also look at the default permissions of the device, since we know from lsusb that it’s bus 5, device 13 (adjust those numbers to your reality):

[merichar@dormouse ~]% ls -l /dev/bus/usb/005/013
crw-rw-r-- 1 root root 189 ...

From dmesg we saw that it also identifies as a USB HID: hiddev0, so we can look at bus mapping-agnostic permissions:

[merichar@dormouse ~]% ls -l /dev/usb
total 0
crw------- 1 root root 180, 0 Jun 14 11:00 /dev/usb/hiddev0

What do we want?

The goal is to not have to run processing or java as root when using the finch. Therefore, we must adjust the permissions of the device such that we (and perhaps others) are able to communicate with it directly.

Getting what we want

udev rules are the best way to change the default permissions of the finch. udev is the linux device manager, so it’s queen of mapping nodes in /dev. In Debian, user created udev rules are placed within /etc/udev/rules.d as (usually) device-specific .rules files.

As root, we are going to create the file:

/etc/udev/rules.d/55-finch.rules

containing the following:

SUBSYSTEM=="usb", SYSFS{idVendor}=="2354", SYSFS{idProduct}=="1111", MODE="0660", GROUP="plugdev"

The expected behavior would be that the next time the finch, as identified by the 2-tuple of vendor id and product id, is introduced to the system, the device’s group changes from root to plugdev and the permissions become 0660 (i.e. readable and writable by both the user and group owners). The 55- prefix to the rules file is its priority. plugdev is a group whose members should be able to access hot-pluggable devices, more traditionally cameras and usb sticks; see Martin’s post on the subject: here.

Sanity Check

After the 55-finch.rules is in place, let’s try it out. If the finch is plugged in to a USB port unplug it. The mappings should be gone from within /dev. Now plug the finch back in. If you were to perform another dmesg or lsusb, the output should be almost identical. e.g.:

[merichar@dormouse ~]% lsusb
...
Bus 005 Device 014: ID 2354:1111

In my case, the device mapping incremented by one. The device mapping will not affect the implementation of our rules file, and as you can see the rules file does not reference a mapping at all. That is the joy of dynamic mapping with udev. The new mapping is important because we do want to confirm that the permissions and ownership we defined in the .rules file actually took to the new mapping and all subsequent mappings:

[merichar@dormouse ~]% ls -l /dev/bus/usb/005/014
crw-rw-r-- 1 root plugdev 189, 525 Jun 14 12:00 /dev/bus/usb/005/014

Therefore, anyone in group plugdev is able to communicate directly with the finch.
We do a quick check that the user we care about is actually in the group plugdev:

[merichar@dormouse ~]% groups merichar
merichar : merichar dialout cdrom floppy sudo audio video plugdev netdev powerdev svn

And that’s that. I startup processing or java normally and as the user merichar I’m able to control the finch.