Skip to content

Commit e1a5249

Browse files
committed
Support multiple PCI class codes for filtering
1 parent ee8f7cb commit e1a5249

File tree

6 files changed

+38
-22
lines changed

6 files changed

+38
-22
lines changed

docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ Exports active physical network interfaces with IPv4 addresses to `report.html`
125125
- --display[=`FILE`]
126126
Print EDID info.
127127
`FILE` specifies the file name of the SPD dump.
128-
- --pci[=`CLASS`]
128+
- --pci[=`CLASS,..`]
129129
Print PCI info.
130-
`CLASS` specifies the class code of PCI devices, e.g. `0C05` (SMBus).
130+
`CLASS` specifies the class codes of PCI devices, e.g. `0c05` or `03,0c05`..
131131
- --spd[=`FILE`]
132132
Print DIMM SPD info.
133133
Driver is required to access SPD data.

libnw/gpu.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ PNWLIB_GPU_INFO NWL_InitGpu(VOID)
4141
info->Initialized = 1;
4242

4343
// TODO: Get GPU vendor/device from pci.ids
44-
info->PciList = NWL_EnumPci(NWL_NodeAlloc("PCI", NFLG_TABLE), "03");
44+
PNWL_ARG_SET pciClasses = NULL;
45+
NWL_ArgSetAddStr(&pciClasses, "03");
46+
info->PciList = NWL_EnumPci(NWL_NodeAlloc("PCI", NFLG_TABLE), pciClasses);
47+
NWL_ArgSetFree(pciClasses);
4548
return info;
4649
}
4750

libnw/libnw.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ VOID NW_Print(LPCSTR lpFileName)
178178
VOID NW_Fini(VOID)
179179
{
180180
NWL_ArgSetFree(NWLC->SmbiosTypes);
181+
NWL_ArgSetFree(NWLC->PciClasses);
181182
if (NWLC->NwRsdp)
182183
free(NWLC->NwRsdp);
183184
if (NWLC->NwRsdt)

libnw/libnw.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ typedef struct _NWLIB_CONTEXT
7373
LPCSTR DevTreeFilter;
7474
DWORD AcpiTable;
7575
PNWL_ARG_SET SmbiosTypes;
76-
LPCSTR PciClass;
76+
PNWL_ARG_SET PciClasses;
7777
LPSTR DiskPath;
7878
LPSTR NetGuid;
7979
LPCSTR ProductPolicy;
@@ -253,7 +253,7 @@ typedef struct _NWLIB_NET_TRAFFIC
253253
} NWLIB_NET_TRAFFIC;
254254
LIBNW_API VOID NWL_GetNetTraffic(NWLIB_NET_TRAFFIC* info, BOOL bit);
255255

256-
LIBNW_API PNODE NWL_EnumPci(PNODE pNode, LPCSTR pciClass);
256+
LIBNW_API PNODE NWL_EnumPci(PNODE pNode, PNWL_ARG_SET pciClasses);
257257

258258
typedef struct _NWLIB_CUR_DISPLAY
259259
{

libnw/pci.c

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "libnw.h"
1010
#include "utils.h"
11+
#include "stb_ds.h"
1112

1213
static void
1314
PrintDriverInfo(PNODE pNode, HDEVINFO hInfo, SP_DEVINFO_DATA* spData)
@@ -38,7 +39,25 @@ PrintDriverInfo(PNODE pNode, HDEVINFO hInfo, SP_DEVINFO_DATA* spData)
3839
NWL_NodeAttrSet(pNode, "Inf Section", NWL_Ucs2ToUtf8(NWLC->NwBufW), 0);
3940
}
4041

41-
PNODE NWL_EnumPci(PNODE pNode, LPCSTR pciClass)
42+
static BOOL
43+
MatchPciClass(PNWL_ARG_SET pciClasses, const char* hwClass)
44+
{
45+
if (!pciClasses)
46+
return TRUE;
47+
48+
for (ptrdiff_t i = 0; i < hmlen(pciClasses); i++)
49+
{
50+
const char* pciClass = pciClasses[i].key.Str;
51+
size_t classLen = strnlen_s(pciClass, 6);
52+
53+
if (_strnicmp(pciClass, hwClass, classLen) == 0)
54+
return TRUE;
55+
}
56+
57+
return FALSE;
58+
}
59+
60+
PNODE NWL_EnumPci(PNODE pNode, PNWL_ARG_SET pciClasses)
4261
{
4362
HDEVINFO hInfo = NULL;
4463
DWORD i = 0;
@@ -67,14 +86,8 @@ PNODE NWL_EnumPci(PNODE pNode, LPCSTR pciClass)
6786
break;
6887
}
6988
}
70-
if (pciClass)
71-
{
72-
size_t PciClassLen = strlen(pciClass);
73-
if (PciClassLen > 6)
74-
PciClassLen = 6;
75-
if (_strnicmp(pciClass, hwClass, PciClassLen) != 0)
76-
continue;
77-
}
89+
if (!MatchPciClass(pciClasses, hwClass))
90+
continue;
7891
npci = NWL_NodeAppendNew(pNode, "Device", NFLG_TABLE_ROW);
7992

8093
NWL_NodeAttrSet(npci, "HWID", NWL_Ucs2ToUtf8(NWLC->NwBufW), 0);
@@ -107,5 +120,5 @@ PNODE NW_Pci(BOOL bAppend)
107120
PNODE node = NWL_NodeAlloc("PCI", NFLG_TABLE);
108121
if (bAppend)
109122
NWL_NodeAppendChild(NWLC->NwRoot, node);
110-
return NWL_EnumPci(node, NWLC->PciClass);
123+
return NWL_EnumPci(node, NWLC->PciClasses);
111124
}

nwinfo.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ static void nwinfo_help(void)
143143
" 'NOCSMI' and 'CSMIRAID'.\n"
144144
" --display[=FILE] Print EDID info.\n"
145145
" FILE Specify the file name of the EDID dump.\n"
146-
" --pci[=CLASS] Print PCI info.\n"
147-
" CLASS specifies the class code of PCI devices,\n"
148-
" e.g. '0C05' (SMBus).\n"
146+
" --pci[=CLASS,..] Print PCI info.\n"
147+
" CLASS specifies the class codes of PCI devices,\n"
148+
" e.g. '0c05' or '03,0c05'.\n"
149149
" --usb Print USB info.\n"
150150
" --spd[=FILE] Print DIMM SPD info.\n"
151151
" WARNING: This option may damage the hardware.\n"
@@ -275,6 +275,7 @@ int main(int argc, char* argv[])
275275
nwContext.AcpiTable = 0;
276276
nwContext.SmbiosTypes = NULL;
277277
nwContext.DiskPath = NULL;
278+
nwContext.PciClasses = NULL;
278279

279280
struct optparse options;
280281
optparse_init(&options, argv);
@@ -354,8 +355,7 @@ int main(int argc, char* argv[])
354355
nwContext.AcpiInfo = TRUE;
355356
break;
356357
case NW_OPT_SMBIOS:
357-
if (options.optarg && options.optarg[0])
358-
nwinfo_parse_arg_set(options.optarg, &nwContext.SmbiosTypes, FALSE);
358+
nwinfo_parse_arg_set(options.optarg, &nwContext.SmbiosTypes, FALSE);
359359
nwContext.DmiInfo = TRUE;
360360
break;
361361
case NW_OPT_DISK:
@@ -420,8 +420,7 @@ int main(int argc, char* argv[])
420420
nwContext.EdidInfo = TRUE;
421421
break;
422422
case NW_OPT_PCI:
423-
if (options.optarg && options.optarg[0])
424-
nwContext.PciClass = options.optarg;
423+
nwinfo_parse_arg_set(options.optarg, &nwContext.PciClasses, TRUE);
425424
nwContext.PciInfo = TRUE;
426425
break;
427426
case NW_OPT_USB:

0 commit comments

Comments
 (0)