line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::Generic::USB; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
104433034
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
64
|
|
4
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
76
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
428
|
use FusionInventory::Agent::Tools; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
241
|
|
7
|
2
|
|
|
2
|
|
756
|
use FusionInventory::Agent::Tools::Generic; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
886
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub isEnabled { |
10
|
0
|
|
|
0
|
0
|
0
|
my (%params) = @_; |
11
|
0
|
0
|
|
|
|
0
|
return 0 if $params{no_category}->{usb}; |
12
|
0
|
|
|
|
|
0
|
return canRun('lsusb'); |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub doInventory { |
16
|
0
|
|
|
0
|
0
|
0
|
my (%params) = @_; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
0
|
my $inventory = $params{inventory}; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
0
|
foreach my $device (_getDevices( |
21
|
|
|
|
|
|
|
logger => $params{logger}, |
22
|
|
|
|
|
|
|
datadir => $params{datadir}) |
23
|
|
|
|
|
|
|
) { |
24
|
0
|
|
|
|
|
0
|
$inventory->addEntry( |
25
|
|
|
|
|
|
|
section => 'USBDEVICES', |
26
|
|
|
|
|
|
|
entry => $device, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _getDevices { |
32
|
1
|
|
|
1
|
|
15561
|
my @devices; |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
3
|
foreach my $device (_getDevicesFromLsusb(@_)) { |
35
|
15
|
50
|
|
|
|
26
|
next unless $device->{PRODUCTID}; |
36
|
15
|
50
|
|
|
|
21
|
next unless $device->{VENDORID}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# ignore the USB Hub |
39
|
|
|
|
|
|
|
next if |
40
|
|
|
|
|
|
|
$device->{PRODUCTID} eq "0001" || |
41
|
15
|
100
|
100
|
|
|
46
|
$device->{PRODUCTID} eq "0002" ; |
42
|
|
|
|
|
|
|
|
43
|
6
|
50
|
66
|
|
|
16
|
if (defined($device->{SERIAL}) && length($device->{SERIAL}) < 5) { |
44
|
0
|
|
|
|
|
0
|
$device->{SERIAL} = undef; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
6
|
|
|
|
|
13
|
my $vendor = getUSBDeviceVendor(id => $device->{VENDORID}, @_); |
48
|
6
|
50
|
|
|
|
8
|
if ($vendor) { |
49
|
6
|
|
|
|
|
8
|
$device->{MANUFACTURER} = $vendor->{name}; |
50
|
|
|
|
|
|
|
|
51
|
6
|
|
|
|
|
6
|
my $entry = $vendor->{devices}->{$device->{PRODUCTID}}; |
52
|
6
|
50
|
|
|
|
11
|
if ($entry) { |
53
|
6
|
|
|
|
|
7
|
$device->{CAPTION} = $entry->{name}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
6
|
|
|
|
|
7
|
push @devices, $device; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
14
|
return @devices; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _getDevicesFromLsusb { |
64
|
2
|
|
|
2
|
|
13
|
my $handle = getFileHandle( |
65
|
|
|
|
|
|
|
@_, |
66
|
|
|
|
|
|
|
command => 'lsusb -v', |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
|
69
|
2
|
50
|
|
|
|
3
|
return unless $handle; |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
2
|
my @devices; |
72
|
|
|
|
|
|
|
my $device; |
73
|
|
|
|
|
|
|
|
74
|
2
|
|
|
|
|
63
|
while (my $line = <$handle>) { |
75
|
2698
|
100
|
|
|
|
11559
|
if ($line =~ /^$/) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
76
|
30
|
100
|
|
|
|
44
|
push @devices, $device if $device; |
77
|
30
|
|
|
|
|
61
|
undef $device; |
78
|
|
|
|
|
|
|
} elsif ($line =~ /^\s*idVendor\s*0x(\w+)/i) { |
79
|
30
|
|
|
|
|
85
|
$device->{VENDORID} = $1; |
80
|
|
|
|
|
|
|
} elsif ($line =~ /^\s*idProduct\s*0x(\w+)/i) { |
81
|
30
|
|
|
|
|
62
|
$device->{PRODUCTID} = $1; |
82
|
|
|
|
|
|
|
} elsif ($line =~ /^\s*iSerial\s*\d+\s(\w+)/i) { |
83
|
18
|
|
|
|
|
61
|
$device->{SERIAL} = $1; |
84
|
|
|
|
|
|
|
} elsif ($line =~ /^\s*bInterfaceClass\s*(\d+)/i) { |
85
|
50
|
|
|
|
|
108
|
$device->{CLASS} = $1; |
86
|
|
|
|
|
|
|
} elsif ($line =~ /^\s*bInterfaceSubClass\s*(\d+)/i) { |
87
|
50
|
|
|
|
|
102
|
$device->{SUBCLASS} = $1; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
2
|
|
|
|
|
13
|
close $handle; |
91
|
2
|
50
|
|
|
|
4
|
push @devices, $device if $device; |
92
|
|
|
|
|
|
|
|
93
|
2
|
|
|
|
|
11
|
return @devices; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |