From 0c0765e3e3b8893761773d3bd792b47871b62f0d Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Tue, 2 Feb 2021 14:11:35 +0000 Subject: [server/pci] Restructure parseIds output & small bug fixes --- server/lib/pci/index.js | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/server/lib/pci/index.js b/server/lib/pci/index.js index 5a7d468..282ad1f 100644 --- a/server/lib/pci/index.js +++ b/server/lib/pci/index.js @@ -18,16 +18,26 @@ module.exports = { if (Object.keys(parsedPciList).length === 0) await parsePciList() let pciInformation = { - 'vendorId': vendorId, - 'vendor': vendorId ? parsedPciList[vendorId].name : undefined, - 'deviceId': deviceId, - 'device': deviceId ? parsedPciList[vendorId].devices[deviceId].name : undefined, - 'subvendorId': subvendorId, - 'subvendor': (subvendorId && subdeviceId) ? parsedPciList[vendorId].devices[deviceId].subsystems[subvendorId][subdeviceId].name : undefined, - 'classId': classId, - 'class': classId ? parsedDeviceClasses[classId].name : undefined, - 'subclassId': subclassId, - 'subclass': subclassId ? parsedDeviceClasses[classId].subclasses[subclassId].name : undefined + 'vendor': vendorId && vendorId.length === 4 ? { + 'id': vendorId, + 'name': parsedPciList[vendorId].name, + 'device': deviceId && deviceId.length === 4 ? { + 'id': deviceId, + 'name': deviceId ? parsedPciList[vendorId].devices[deviceId].name : undefined, + 'subvendor': subvendorId && subdeviceId && subvendorId.length === 4 && subdeviceId.length === 4 ? { + 'id': subvendorId, + 'name': parsedPciList[vendorId].devices[deviceId].subsystems[subvendorId][subdeviceId].name + } : undefined + } : undefined + } : undefined, + 'class': classId && classId.length === 2 ? { + 'id': classId, + 'name': parsedDeviceClasses[classId].name, + 'subclass': subclassId && subclassId.length === 2 ? { + 'id': subclassId, + 'name': parsedDeviceClasses[classId].subclasses[subclassId].name + } : undefined + } : undefined } return pciInformation @@ -165,8 +175,8 @@ function parsePciList () { const subdevice = line.substring(7, 11) const subsystem = line.substring(13) - if (result[lastVendorId].devices[lastDeviceId].subsystems[subvendor] === undefined) result[lastVendorId].devices[lastDeviceId][subvendor] = {} - result[lastVendorId].devices[lastDeviceId][subvendor][subdevice] = { + if (result[lastVendorId].devices[lastDeviceId].subsystems[subvendor] === undefined) result[lastVendorId].devices[lastDeviceId].subsystems[subvendor] = {} + result[lastVendorId].devices[lastDeviceId].subsystems[subvendor][subdevice] = { 'name': subsystem } } else if (line.match(regexClass)) { -- cgit v1.2.3-55-g7522