solid: lookup PCI/USB IDs if present from UDev backend

fixes vendor/product detection for some devices

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2021-07-04 19:35:56 +03:00
parent a0a531772a
commit 68cafb44c0
5 changed files with 26107 additions and 19 deletions

View file

@ -0,0 +1,57 @@
#!/usr/local/bin/python2
import sys
def splitpciline(fromline):
doublespaceindex = fromline.index(b' ')
lineid = fromline[:doublespaceindex]
linename = fromline[doublespaceindex+2:]
linename = linename.replace('"', '\\"')
# what is the question? (in 2a15)
linename = linename.replace('???', 'Unknown')
return (lineid, linename)
vendormap = {}
devicemap = {}
with open('/usr/local/share/pciids/pci.ids', 'rb') as f:
ingroupsection = False
for line in f.readlines():
sline = line.strip()
if not sline or sline.startswith(b'#'):
continue;
elif line.startswith(b'\t\t'):
# subvendor
continue
elif line.startswith(b'C'):
ingroupsection = True
elif line.startswith(b'\t') and not ingroupsection:
deviceid, devicename = splitpciline(sline)
if b' ' in deviceid:
print('ranges are not supported: %s' % deviceid)
sys.exit(123)
devicemap[deviceid] = devicename
else:
ingroupsection = False
vendorid, vendorname = splitpciline(sline)
if b' ' in vendorid:
print('ranges are not supported: %s' % vendorid)
sys.exit(123)
vendormap[vendorid] = vendorname
print('''static const struct pciVendorTblData {
const char* const vendorid;
const char* const vendorname;
} pciVendorTbl[] = {''')
for vendorid in vendormap.keys():
print(' { "%s", "%s" },' % (vendorid, vendormap[vendorid]))
print('};')
print('static const size_t pciVendorTblSize = sizeof(pciVendorTb) / sizeof(pciVendorTbData);')
print('')
print('''static const struct pciDeviceTblData {
const char* const deviceid;
const char* const devicename;
} pciDeviceTbl[] = {''')
for deviceid in devicemap.keys():
print(' { "%s", "%s" },' % (deviceid, devicemap[deviceid]))
print('};')
print('static const size_t pciDeviceTblSize = sizeof(pciDeviceTbl) / sizeof(pciDeviceTblData);')

View file

@ -0,0 +1,57 @@
#!/usr/local/bin/python2
import sys
def splitusbline(fromline):
doublespaceindex = fromline.index(b' ')
lineid = fromline[:doublespaceindex]
linename = fromline[doublespaceindex+2:]
linename = linename.replace('"', '\\"')
# what is the question? (in 1183)
linename = linename.replace('???', 'Unknown')
return (lineid, linename)
vendormap = {}
devicemap = {}
with open('/usr/local/share/usbids/usb.ids', 'rb') as f:
ingroupsection = False
for line in f.readlines():
sline = line.strip()
if not sline or sline.startswith(b'#'):
continue;
elif line.startswith(b'\t\t'):
# subvendor
continue
elif line.startswith((b'C', b'AT', b'HID', b'R', b'BIAS', b'PHY', b'HUT', b'L', b'HCC', b'VT')):
ingroupsection = True
elif line.startswith(b'\t') and not ingroupsection:
deviceid, devicename = splitusbline(sline)
if b' ' in deviceid:
print('ranges are not supported: %s' % deviceid)
sys.exit(123)
devicemap[deviceid] = devicename
else:
ingroupsection = False
vendorid, vendorname = splitusbline(sline)
if b' ' in vendorid:
print('ranges are not supported: %s' % vendorid)
sys.exit(123)
vendormap[vendorid] = vendorname
print('''static const struct usbVendorTblData {
const char* const vendorid;
const char* const vendorname;
} usbVendorTbl[] = {''')
for vendorid in vendormap.keys():
print(' { "%s", "%s" },' % (vendorid, vendormap[vendorid]))
print('};')
print('static const size_t usbVendorTblSize = sizeof(usbVendorTbl) / sizeof(usbVendorTblData);')
print('')
print('''static const struct usbDeviceTblData {
const char* const deviceid;
const char* const devicename;
} usbDeviceTbl[] = {''')
for deviceid in devicemap.keys():
print(' { "%s", "%s" },' % (deviceid, devicemap[deviceid]))
print('};')
print('static const size_t usbDeviceTblSize = sizeof(usbDeviceTbl) / sizeof(usbDeviceTblData);')

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -35,6 +35,8 @@
#include "udevnetworkinterface.h"
#include "udevbutton.h"
#include "udevmanager.h"
#include "../shared/pciidstables.h"
#include "../shared/usbidstables.h"
#include "cpuinfo.h"
#include "kglobal.h"
#include "klocale.h"
@ -86,22 +88,31 @@ QString UDevDevice::vendor() const
{
QString vendor = m_device.sysfsProperty("manufacturer");
if (vendor.isEmpty()) {
if (queryDeviceInterface(Solid::DeviceInterface::Processor)) {
// sysfs doesn't have anything useful here
if (queryDeviceInterface(Solid::DeviceInterface::Processor)) {
// sysfs doesn't have anything useful here
vendor = extractCpuInfoLine(deviceNumber(), "vendor_id\\s+:\\s+(\\S.+)");
} else if (queryDeviceInterface(Solid::DeviceInterface::Video)) {
vendor = m_device.deviceProperty("ID_VENDOR").replace('_', " ");
} else if (queryDeviceInterface(Solid::DeviceInterface::NetworkInterface)) {
vendor = m_device.deviceProperty("ID_VENDOR_FROM_DATABASE");
} else if (queryDeviceInterface(Solid::DeviceInterface::AudioInterface)) {
if (m_device.parent().isValid()) {
vendor = m_device.parent().deviceProperty("ID_VENDOR_FROM_DATABASE");
}
}
} else if (queryDeviceInterface(Solid::DeviceInterface::AudioInterface)) {
const UdevQt::Device deviceparent(m_device.parent());
if (deviceparent.isValid()) {
vendor = deviceparent.deviceProperty("ID_VENDOR_FROM_DATABASE");
}
}
if (vendor.isEmpty()) {
vendor = m_device.deviceProperty("ID_VENDOR").replace('_', ' ');
}
if (vendor.isEmpty()) {
vendor = m_device.deviceProperty("ID_VENDOR_FROM_DATABASE");;
}
if (vendor.isEmpty()) {
const QByteArray idvendorid(m_device.deviceProperty("ID_VENDOR_ID").toLatin1());
if (!idvendorid.isEmpty()) {
const QString idbus(m_device.deviceProperty("ID_BUS"));
if (idbus == QLatin1String("pci")) {
vendor = lookupPCIVendor(idvendorid.constData());
} else if (idbus == QLatin1String("usb")) {
vendor = lookupUSBVendor(idvendorid.constData());
}
}
}
}
return vendor;
}
@ -122,20 +133,30 @@ QString UDevDevice::product() const
const NetworkInterface netIface(const_cast<UDevDevice *>(this));
if (netIface.isLoopback()) {
product = QLatin1String("Loopback device Interface");
} else {
product = m_device.deviceProperty("ID_MODEL_FROM_DATABASE");
}
} else if(queryDeviceInterface(Solid::DeviceInterface::SerialInterface)) {
const SerialInterface serialIface(const_cast<UDevDevice *>(this));
if (serialIface.serialType() == Solid::SerialInterface::Platform) {
product.append(QLatin1String("Platform serial"));
product = QLatin1String("Platform serial");
} else if (serialIface.serialType() == Solid::SerialInterface::Usb) {
product.append(QLatin1String("USB Serial Port"));
product = QLatin1String("USB Serial Port");
}
}
if (product.isEmpty()) {
product = m_device.deviceProperty("ID_MODEL").replace('_', ' ');
product = m_device.deviceProperty("ID_MODEL_FROM_DATABASE");
}
if (product.isEmpty()) {
const QByteArray idmodelid(m_device.deviceProperty("ID_MODEL_ID").toLatin1());
if (!idmodelid.isEmpty()) {
const QString idbus(m_device.deviceProperty("ID_BUS"));
if (idbus == QLatin1String("pci")) {
product = lookupPCIDevice(idmodelid.constData());
} else if (idbus == QLatin1String("usb")) {
product = lookupUSBDevice(idmodelid.constData());
}
}
}
}
return product;