]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/cdrom/yaird-0.0.5/perl/UsbDev.pm
Initial revision
[bacula/rescue] / rescue / linux / cdrom / yaird-0.0.5 / perl / UsbDev.pm
1 #!perl -w
2 #
3 # UsbDev -- the probed values for a USB device, as found in /sys.
4 #   Copyright (C) 2005  Erik van Konijnenburg
5 #
6 #   This program is free software; you can redistribute it and/or modify
7 #   it under the terms of the GNU General Public License as published by
8 #   the Free Software Foundation; either version 2 of the License, or
9 #   (at your option) any later version.
10 #
11 #   This program is distributed in the hope that it will be useful,
12 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #   GNU General Public License for more details.
15 #
16 #   You should have received a copy of the GNU General Public License
17 #   along with this program; if not, write to the Free Software
18 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 #
20 #
21 # The information passed to the matcher should correspond to what
22 # is passed by hotplug.
23 #
24 # For devices:
25 #       vendor, product, bcdDevice = 0, 0, 0
26 #       deviceClass, subClass, protocol = from /sys
27 #       interfaceClass, subClass, protocol = 1000,1000,1000
28 # For interfaces:
29 #       vendor, product, bcdDevice = from /sys in parent device
30 #       deviceClass, subClass, protocol = 1000,1000,1000
31 #       interfaceClass, subClass, protocol = from /sys
32 #
33 # Note that somewhere in 2.5, the hotplug events for USB
34 # changed: old kernels only had an event for the first interface,
35 # with no distinction between interface and device.
36 #
37 use strict;
38 use warnings;
39 use Base;
40 package UsbDev;
41 use base 'Obj';
42
43
44 sub fill {
45         my $self = shift;
46         $self->SUPER::fill();
47         $self->takeArgs ('path');
48         my $path = $self->{path};
49         if (-f "$path/bDeviceClass") {
50                 $self->{idVendor} = 0;
51                 $self->{idProduct} = 0;
52                 $self->{bcdDevice} = 0;
53                 $self->{bDeviceClass} = Base::getHexFile ("$path/bDeviceClass");
54                 $self->{bDeviceSubClass} = Base::getHexFile ("$path/bDeviceSubClass");
55                 $self->{bDeviceProtocol} = Base::getHexFile ("$path/bDeviceProtocol");
56                 $self->{bInterfaceClass} = 1000;
57                 $self->{bInterfaceSubClass} = 1000;
58                 $self->{bInterfaceProtocol} = 1000;
59         }
60         elsif (-f "$path/bInterfaceClass") {
61                 $self->{idVendor} = Base::getHexFile ("$path/../idVendor");
62                 $self->{idProduct} = Base::getHexFile ("$path/../idProduct");
63                 $self->{bcdDevice} = Base::getHexFile ("$path/../bcdDevice");
64                 $self->{bDeviceClass} = 1000;
65                 $self->{bDeviceSubClass} = 1000;
66                 $self->{bDeviceProtocol} = 1000;
67                 $self->{bInterfaceClass} = Base::getHexFile ("$path/bInterfaceClass");
68                 $self->{bInterfaceSubClass} = Base::getHexFile ("$path/bInterfaceSubClass");
69                 $self->{bInterfaceProtocol} = Base::getHexFile ("$path/bInterfaceProtocol");
70         }
71         else {
72                 Base::fatal "trying to interpret $path as /sys USB devive";
73         }
74 }
75
76 sub idVendor            { return $_[0]->{idVendor}; }
77 sub idProduct           { return $_[0]->{idProduct}; }
78 sub bcdDevice           { return $_[0]->{bcdDevice}; }
79 sub bDeviceClass        { return $_[0]->{bDeviceClass}; }
80 sub bDeviceSubClass     { return $_[0]->{bDeviceSubClass}; }
81 sub bDeviceProtocol     { return $_[0]->{bDeviceProtocol}; }
82 sub bInterfaceClass     { return $_[0]->{bInterfaceClass}; }
83 sub bInterfaceSubClass  { return $_[0]->{bInterfaceSubClass}; }
84 sub bInterfaceProtocol  { return $_[0]->{bInterfaceProtocol}; }
85
86
87
88 1;