From b24dbde8d730dcf72d5cd0b818c8a17069c0317a Mon Sep 17 00:00:00 2001 From: Guillaume Bougard Date: Tue, 17 Oct 2023 16:25:12 +0200 Subject: [PATCH] fix: Fix inventory of usb bar code scanner from Symbol Technologies Also cleanup wrong 0000 usb serial for hubs on linux Closes #519 --- Changes | 2 ++ lib/GLPI/Agent/Task/Inventory/Generic/USB.pm | 11 ++++++-- lib/GLPI/Agent/Task/Inventory/Win32/USB.pm | 13 +++++++--- .../generic/lsusb/ubuntu-bar-code-scanner | 16 ++++++++++++ .../bar-code-scanner-CIM_LogicalDevice.wmi | Bin 0 -> 1124 bytes t/tasks/inventory/generic/usb.t | 24 ++++++++++++------ t/tasks/inventory/windows/usb.t | 10 ++++++++ 7 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 resources/generic/lsusb/ubuntu-bar-code-scanner create mode 100644 resources/win32/wmi/bar-code-scanner-CIM_LogicalDevice.wmi diff --git a/Changes b/Changes index ef7064d0c..e8f3a9128 100644 --- a/Changes +++ b/Changes @@ -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 diff --git a/lib/GLPI/Agent/Task/Inventory/Generic/USB.pm b/lib/GLPI/Agent/Task/Inventory/Generic/USB.pm index caaf6bddd..c66898a82 100644 --- a/lib/GLPI/Agent/Task/Inventory/Generic/USB.pm +++ b/lib/GLPI/Agent/Task/Inventory/Generic/USB.pm @@ -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) { diff --git a/lib/GLPI/Agent/Task/Inventory/Win32/USB.pm b/lib/GLPI/Agent/Task/Inventory/Win32/USB.pm index 2e1319312..48a978621 100644 --- a/lib/GLPI/Agent/Task/Inventory/Win32/USB.pm +++ b/lib/GLPI/Agent/Task/Inventory/Win32/USB.pm @@ -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 }; } diff --git a/resources/generic/lsusb/ubuntu-bar-code-scanner b/resources/generic/lsusb/ubuntu-bar-code-scanner new file mode 100644 index 000000000..6c21b922d --- /dev/null +++ b/resources/generic/lsusb/ubuntu-bar-code-scanner @@ -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: + diff --git a/resources/win32/wmi/bar-code-scanner-CIM_LogicalDevice.wmi b/resources/win32/wmi/bar-code-scanner-CIM_LogicalDevice.wmi new file mode 100644 index 0000000000000000000000000000000000000000..d440faaf74d9e0ca86ae4b5fbc2788bd8c721280 GIT binary patch literal 1124 zcmdUuOH0E*6ot=P@Nc-a^;v~3G__dlBQ!oXLh%u$*v67*rGH-i&O~k8C@y7~gt?D% z&%I~n?R8Zv@;=a9R~l==_d5K?deTD8;EnXCOn2Dt)gvNf-z!zFBX*8Amt$_RHC6j1 z=S)S&t)e#7hC^2gh~^W4m{R45nywuMW(ApjtkY2E0$-+0ZD^zuEDM-F;?3boSHfV|4^4Y59bj~x2adtn&J;j9kd$jlE`&x?Q?FxtPX=nJK6)M&bIAHTjVza zMvL<{T-w?tu0>=-r3P!HA(7`G^|1_@UqbAGj*04Ft${Zn`jo#B%)C0)3GCfdN>`;C zORqaD=r5+t7H5Qo-VVx(L)8dON=v?_)ATlW&eV#XJV}K z=h_O)9nr@(MTHbb1MW+kb4Ha<6-$*0vOQ;K#Gz)P7jUgx$u9;ehVy^bFQ%K9Foo)C z@vY66MMTdt_VS&L@pvlbM1IOmnCOhe~7`1Bk&A0=hte2pv XRZmgwudmMcV+tGJ2y0%&a#inl< '0', CLASS => '9', PRODUCTID => '0001', - SERIAL => '0000', }, { VENDORID => '0a5c', @@ -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' @@ -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' @@ -88,7 +83,6 @@ my %lsusb_tests = ( }, { CLASS => '9', - SERIAL => '0000', SUBCLASS => '0', VENDORID => '1d6b', PRODUCTID => '0001' @@ -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', + } ] ); @@ -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') + } ] ); diff --git a/t/tasks/inventory/windows/usb.t b/t/tasks/inventory/windows/usb.t index 5ab2cbacf..745bf5884 100755 --- a/t/tasks/inventory/windows/usb.t +++ b/t/tasks/inventory/windows/usb.t @@ -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' + } ] );