|
|
thewatertower.org.uk |
![]() |
| thewatertower.org.uk |
Linux: Automatic actions driven by USB eventsMaking things happen when most common USB devices are connected is pretty common place. For example: getting a /media mountpoint when a USB drive is connected. I assume, therefore, that the irritating windows-esque 'what do you want to do' GUI is triggered by the same progress. Irritating because it never remembers what to do. I want to be able to make specific things happening. Of most significance are:
Both work satisfactorily on SuSE 9.3, but the hotplug approach seems to have been depreciated by 10.2 The old way: USB HotplugLinux USB hotplug allows scripts to be run when a USB event occurs. For example, when I hotsync my PalmOS powered Sony Clie, Linux serves out an IP address using pppd so the Clie can connect across the network to Windows. Unfortunately, the entire hotplug infrastructure seems to be have been switched out between 2.6.11 and 2.6.18. It used to comprise:
Atul Chitnis - the source for the original pppd script and methodology I use The new way: udev rulesLooks simple enough, based on my sources: udev/HAL/submount basicsFunctionality relating to hotplugging and device automation appears to be fragmented and / or littered all over the system. Some of the locations I've found with scripts and configuration include:
udevget udev to rescan sysfs:
Turn on logging (to /var/log/messages) in /etc/udev/udev.conf
Interact with udev daemon
Monitor udev kernel events etc. real time (works on Ubuntu 8.04, missing on Suse 10.3)
Not present on Ubuntu 6.06, try instead:
HALQuery devices on the system
Restart HAL daemon
sourcesopensuse article on switching off 'sync' for USB drives Suse bug relating to slow USB devices; turning off sync udev rules - sources of informationInformation on which to base rules can come from the following sources. All the non-sysfs values appear to be also written to the environment context. the following rule and script writes the environment out to /tmp and logs to syslog.
Qualifying the rule further with sysfs info requires you to query the right device. Establish this with the following command ..
.. and then query the device:
udev - bind synthesizer to MIDI keyboardThe first step was to turn on debugging (udevcontrol log_priority=debug) and then use the output to give clues about which part of the udev rules are key. Some of the notable actions, such as switching the controlC* value to snd/controlC* is done by /etc/udev/rules.d/40-alsa.rules, as is the call to alsactl.
My goal is to put a rule for when the synthesizer is to be unloaded, and a rule after it when it needs to be started up. It then becomes necessary to narrow down the events; the keyboard generated at least a dozen, and I only want one of them to be picked up. Having tried different approaches, I finally settled on an iterative approach. I loaded up the trigger script and rule39, see above, and then further qualified it with the device's description. This will ensure other devices don't trigger the same rules.
I would then look to filter it down to a single event based on the SUBSYSTEM or DEVNAME. Follows are the entries logged out by my trigger script.
Its not that simple though. Suspect sysfs doesn't present the same information when a device is being shut down. So, I settled for the following two rules:
Getting this working on Ubuntu 6.06First, I had to enable 'universe' for the package manager; there were entries remarked out in /etc/apt/sources.list
udev - ppp for Palm (Suse 10.2)final udev rules and ppp script are here Based on Carsten's page, I set up some initial rules. Goal is to run a script off the back of the palm pilot turning up, so to see what I have to work with, I dump the environment.
Something I discovered using hotplug was that the Palm creates two devices; Carsten's rule is only interested in the odd numbered one, which I'll stick with. Syslog output is as follows:
Looks like I get two USB events for the price of one. First is for a usb-serial device ..
.. second is for a tty device; a sub-device, methinks.
Reference back to my hotplug solution showed it working off /dev/ttyUSB0 (I'll settle for its twin) so I think I want the second. Daniel's doc says there's a SUBSYSTEM key, so I'll modify the rule ...
Sure enough, I just get one execution now, the second. Combined with relevant code from the old hotplug script, I got it working, within the PPP "server", with the following modifications. NB - I've moved the script to /etc/udev/scripts.d/udev_pilot, after creating the scripts.d directory. First, PPP can't work with the odd devices, only the even ones.
So I change the rule to have eyes only for the evens.
Second, the procedure for setting up routing external to the PPP server appeared to have failed. However, it seems that while I can't ping the address from elsewhere on the network, it has connectivity just fine.
Investigating, I found another way to achieve the same goal, and also how to query iptables.
ppp for Palm - compression errorsSomethings don't change. I was getting these errors with hotplug, and IIRC it can be pretty disruptive.
Edit /etc/ppp/options and add the following line. I put it a little after 'noauth'.
udev - ppp for Palm (Ubuntu 8.04)Off the shelf, the TTY devices aren't being created. Have established also that the 'visor' driver is blacklisted, which appears to prevent it being loaded by modprobe from within udev rules. This, I think, would happen in /etc/udev/rules.d/90-modprobe.rules, via /sbin/modprobe -Q $env{MODALIAS}. This is effectively what SuSE does, only via the /sbin/hwup script. Remarked out the 'blacklist visor' entry in /etc/modprobe.d/libpisock9, and it gets this far:
The links below suggest that visor is best loaded at boot, so its in /etc/modules now - and back in the blacklist. However, it appears that the issue is in the Kernel; potentially fixed in 2.6.25 or 2.6.26. So it looks like my Palms will be getting IP addresses from SuSE for while. Ubuntu bug 222052 - pilot -5 error ubuntu bug 226197 - pilot -5 error Printed and hosted by Prater Raines Ltd, 98 Sandgate High Street, Folkestone CT20 3BY. Published and promoted by Ben Prescott, 14, St James's Square, Bournemouth, BH5 2BX. All rights reserved. The views expressed are solely those of the author, not of the service provider. |