Skip to content

Commit

Permalink
fix: Fix inventory of usb bar code scanner from Symbol Technologies
Browse files Browse the repository at this point in the history
Also cleanup wrong 0000 usb serial for hubs on linux
Closes #519
  • Loading branch information
g-bougard committed Oct 17, 2023
1 parent 0e0a042 commit b24dbde
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 14 deletions.
2 changes: 2 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ inventory:
* fix #511: First try to use ip route to find default gateway on linux
Also fix default gateway suppport on most unix
* Fix no more available local users inventory since 1.5 on win32
* fix #519: Fix inventory of usb bar code scanner from Symbol Technologies
On linux, skip wrong serialnumbers like "0000" on usb hubs

netdiscovery/netinventory:
* Enhanced Aruba IAP models support
Expand Down
11 changes: 9 additions & 2 deletions lib/GLPI/Agent/Task/Inventory/Generic/USB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,15 @@ sub _getDevicesFromLsusb {
$device->{VENDORID} = $1;
} elsif ($line =~ /^\s*idProduct\s*0x(\w+)/i) {
$device->{PRODUCTID} = $1;
} elsif ($line =~ /^\s*iSerial\s*\d+\s(\w+)/i) {
$device->{SERIAL} = $1;
} elsif ($line =~ /^\s*iSerial\s*\d+\s(.*)$/i) {
my $iSerial = trimWhitespace($1);
# 1. Support manufacturers wrongly using iSerial with fields definition
# 2. Don't include serials with colons as they seems to be an internal id for hub layers
if ($iSerial =~ /S\/N:([^: ]+)/) {
$device->{SERIAL} = $1;
} elsif (!empty($iSerial) && $iSerial !~ /:/) {
$device->{SERIAL} = $1;
}
} elsif ($line =~ /^\s*bInterfaceClass\s*(\d+)/i) {
$device->{CLASS} = $1;
} elsif ($line =~ /^\s*bInterfaceSubClass\s*(\d+)/i) {
Expand Down
13 changes: 9 additions & 4 deletions lib/GLPI/Agent/Task/Inventory/Win32/USB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,23 @@ sub _getDevices {
sub _getDevicesFromWMI {
my @devices;

my ($vendorid, $productid, $serial);

foreach my $object (getWMIObjects(
class => 'CIM_LogicalDevice',
properties => [ qw/Caption DeviceID Name/ ]
)) {
next unless $object->{DeviceID} =~ /^USB\\VID_(\w+)&PID_(\w+)\\(.*)/;
next unless ($vendorid, $productid, $serial) = $object->{DeviceID} =~ /^USB\\VID_(\w+)&PID_(\w+)\\(.*)/;

# Support manufacturers wrongly using iSerial with fields definition
$serial = $1 if $serial =~ /^S\/N:([0-9A-F]+)/i;

push @devices, {
CAPTION => $object->{Caption},
NAME => $object->{Name},
VENDORID => $1,
PRODUCTID => $2,
SERIAL => $3
VENDORID => $vendorid,
PRODUCTID => $productid,
SERIAL => $serial
};
}

Expand Down
16 changes: 16 additions & 0 deletions resources/generic/lsusb/ubuntu-bar-code-scanner
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Bus 002 Device 018: ID 05e0:1200 Symbol Technologies Bar Code Scanner
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 0
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x05e0 Symbol Technologies
idProduct 0x1200 Bar Code Scanner
bcdDevice 2.01
iManufacturer 1 ᄅSymbol Technologies, Inc, 2002
iProduct 2 Symbol Bar Code Scanner
iSerial 3 S/N:28A1CC69D1D8AE4585EDA53F7CD6CB88 Rev:NBRMSAAHDM:

Binary file not shown.
24 changes: 16 additions & 8 deletions t/tasks/inventory/generic/usb.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ my %lsusb_tests = (
SUBCLASS => '0',
CLASS => '9',
PRODUCTID => '0001',
SERIAL => '0000',
},
{
VENDORID => '0a5c',
Expand Down Expand Up @@ -47,14 +46,12 @@ my %lsusb_tests = (
},
{
CLASS => '9',
SERIAL => '0000',
SUBCLASS => '0',
VENDORID => '1d6b',
PRODUCTID => '0001'
},
{
CLASS => '9',
SERIAL => '0000',
SUBCLASS => '0',
VENDORID => '1d6b',
PRODUCTID => '0001'
Expand All @@ -68,14 +65,12 @@ my %lsusb_tests = (
},
{
CLASS => '9',
SERIAL => '0000',
SUBCLASS => '0',
VENDORID => '1d6b',
PRODUCTID => '0001'
},
{
CLASS => '9',
SERIAL => '0000',
SUBCLASS => '0',
VENDORID => '1d6b',
PRODUCTID => '0001'
Expand All @@ -88,7 +83,6 @@ my %lsusb_tests = (
},
{
CLASS => '9',
SERIAL => '0000',
SUBCLASS => '0',
VENDORID => '1d6b',
PRODUCTID => '0001'
Expand All @@ -101,18 +95,23 @@ my %lsusb_tests = (
},
{
CLASS => '9',
SERIAL => '0000',
SUBCLASS => '0',
VENDORID => '1d6b',
PRODUCTID => '0002'
},
{
CLASS => '9',
SERIAL => '0000',
SUBCLASS => '0',
VENDORID => '1d6b',
PRODUCTID => '0002'
}
],
'ubuntu-bar-code-scanner' => [
{
VENDORID => '05e0',
PRODUCTID => '1200',
SERIAL => '28A1CC69D1D8AE4585EDA53F7CD6CB88',
}
]
);

Expand Down Expand Up @@ -167,6 +166,15 @@ my %usb_tests = (
MANUFACTURER => 'Kensington',
CAPTION => re('^PocketMouse Pro')
}
],
'ubuntu-bar-code-scanner' => [
{
VENDORID => '05e0',
PRODUCTID => '1200',
MANUFACTURER => 'Symbol Technologies',
SERIAL => '28A1CC69D1D8AE4585EDA53F7CD6CB88',
CAPTION => re('^Bar Code Scanner')
}
]
);

Expand Down
10 changes: 10 additions & 0 deletions t/tasks/inventory/windows/usb.t
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ my %tests = (
VENDORID => '03F0',
PRODUCTID => '3817'
}
],
"bar-code-scanner" => [
{
MANUFACTURER => 'Symbol Technologies',
NAME => 'Bar Code Scanner',
CAPTION => 'Bar Code Scanner',
SERIAL => '28A1CC69D1D8AE4585EDA53F7CD6CB88',
VENDORID => '05E0',
PRODUCTID => '1200'
}
]
);

Expand Down

0 comments on commit b24dbde

Please sign in to comment.