auto detecting device type
I'm looking for info on how to automatically detect what exactly is
inserted on the USB port.
I know about hotplug, and I know I can use the PRODUCT environment
variable to start a device specific script or program.
However that is not exactly what I want. What I want is a
program/script to detect what kind of device it is and preferably
also to which major device it maps.
I think with quite some effort (going from hotplug
to /proc/bus/usb/...) etc I can find what i need but I feel there is
a better way.
Questions I am facing are:
- how do I easily detect the device class
- can I detect a subtype (e.g. when it is an MSC device, is it a
cdrom, a memory stick, a floppy drive or a hard disk)?
- For MSC how can I find out which major device number it got (and
probably the supported minors as well). Currently I can only do this
by trial and error)
The script/program I am planning to write could for instance:
- if a camera is inserted automatically backup all images to hard
disk (for both mass storage and ptp)
- if a cdrom is present and an audio cd is inserted it will rip the
cd (to wav) and store it on hard disk.
- if a memory stick is inserted it could backup the contents to hard
- if a portable mp3 player is inserted it could load the thing with
I know how to perform each of these tasks for a single device or even
for a set of devices that are known upfront, but I am missing the
info to write a generic dispatcher.
Anyone a suggestion how to tackle this?
Thanks alot! Frans.