6.4. Automating the USB connection

Unfortunately, automating the USB connection on the GNU/Linux host heavily depends on the GNU/Linux distribution you are using. As a guideline, here is what happens when an USB device is plugged or unplugged. The kernel first checks for a /proc/sys/kernel/hotplug pseudo-file that should contain the name of a user program to launch with the event type (usb, pci, isapnp, net, ieee1394, printer, disk, parport, ...) and a device descriptor as arguments. This program is usually a shell script, that will delegate processing to some other scripts, using text configuration files. Not two different GNU/Linux distributions are using the same schema, which makes it very difficult to write a general way of automating. So, the only general way to handle this will be to edit the hotplug script.

On my RedHat 7.2, I need to add the following lines at the beginning of the /sbin/hotplug file to use the /etc/rc.d/init.d/ipaq script introduced above:

if [ "$*" = "usb" ]; then
    if [ "$PRODUCT" = "49f/505a/0" ]; then
        path_to_ipaqnet/ipaqnet $ACTION
        exit
    fi
fi

This way, the USB network will be correctly brought up/shut down when you plug/unplug the iPAQ.