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