Hotplug USB IrDA Dongle (gentoo Linux)

Fri, 03. Oct 2008

Categories: en sysadmin Tags: gentoo IrDA udev

Udev can help to get rid of the ugly $ sudo irattach irda0 -s in my previous blog post.

I added the following udev rule:

1$ cat /etc/udev/rules.d/95-usb-irda.rules
2# Connect the IRDA USB Dongle
3# see http://de.gentoo-wiki.com/Udev_Rules
4# use "$ lsusb -v" to get the details about the dongle
5ACTION=="add", BUS=="usb", SYSFS{manufacturer}==" Sigmatel Inc ", SYSFS{product}==" IrDA/USB Bridge", NAME="%k", RUN+="/usr/local/bin/usb-irda-add.sh"
6# ACTION=="remove", BUS=="usb", SYSFS{idVendor}=="066f", SYSFS{idProduct}=="4200", RUN+="/usr/local/bin/usb-irda-remove.sh"

combined with the script

1# cat /usr/local/bin/usb-irda-add.sh
2#!/bin/sh
3# Init script for /etc/udev/rules.d/95-usb-irda.rules
4# modprobe ircomm_tty
5irattach irda0 -s
6# http://osdir.com/ml/drivers.gnokii/2003-09/msg00014.html
7echo 115200 > /proc/sys/net/irda/max_baud_rate

and voila, the dongle hotplugs.

What’s puzzling me, is that /var/log/messages shows multiple identical entries:

 1Oct  3 22:06:17 sifr irattach: executing: '/sbin/modprobe irda0'
 2Oct  3 22:06:17 sifr irattach: executing: 'echo sifr > /proc/sys/net/irda/devname'
 3Oct  3 22:06:17 sifr irattach: executing: '/sbin/modprobe irda0'
 4Oct  3 22:06:17 sifr irattach: executing: 'echo 1 > /proc/sys/net/irda/discovery'
 5Oct  3 22:06:17 sifr irattach: executing: '/sbin/modprobe irda0'
 6Oct  3 22:06:17 sifr irattach: executing: 'echo sifr > /proc/sys/net/irda/devname'
 7Oct  3 22:06:17 sifr irattach: Starting device irda0
 8Oct  3 22:06:17 sifr irattach: executing: 'echo 1 > /proc/sys/net/irda/discovery'
 9Oct  3 22:06:17 sifr irattach: executing: 'echo sifr > /proc/sys/net/irda/devname'
10Oct  3 22:06:17 sifr irattach: executing: '/sbin/modprobe irda0'
11Oct  3 22:06:17 sifr irattach: Starting device irda0
12Oct  3 22:06:17 sifr irattach: executing: 'echo 1 > /proc/sys/net/irda/discovery'
13Oct  3 22:06:17 sifr irattach: executing: 'echo sifr > /proc/sys/net/irda/devname'
14Oct  3 22:06:17 sifr irattach: Starting device irda0
15Oct  3 22:06:17 sifr irattach: executing: 'echo 1 > /proc/sys/net/irda/discovery'
16Oct  3 22:06:17 sifr irattach: Starting device irda0

and that unplugging doesn’t unload the kernel modules, despite the script

1$ cat /usr/local/bin/usb-irda-remove.sh
2#!/bin/sh
3# Removal script for /etc/udev/rules.d/95-usb-irda.rules
4rmmod ircomm_tty ircomm stir4200 irda crc_ccitt