]>
git.ipfire.org Git - thirdparty/pciutils.git/blob - lib/filter.c
fab0025bd7322ad7f836a5ec459f911f736614d3
2 * The PCI Library -- Device Filtering
4 * Copyright (c) 1998--2003 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
15 pci_filter_init(struct pci_access
*a UNUSED
, struct pci_filter
*f
)
17 f
->domain
= f
->bus
= f
->slot
= f
->func
= -1;
18 f
->vendor
= f
->device
= f
->class = -1;
21 /* Slot filter syntax: [[[domain]:][bus]:][slot][.[func]] */
24 pci_filter_parse_slot(struct pci_filter
*f
, char *str
)
26 char *colon
= strrchr(str
, ':');
27 char *dot
= strchr((colon
? colon
+ 1 : str
), '.');
29 char *e
, *bus
, *colon2
;
35 colon2
= strchr(str
, ':');
40 if (str
[0] && strcmp(str
, "*"))
42 long int x
= strtol(str
, &e
, 16);
43 if ((e
&& *e
) || (x
< 0 || x
> 0xffff))
44 return "Invalid domain number";
50 if (bus
[0] && strcmp(bus
, "*"))
52 long int x
= strtol(bus
, &e
, 16);
53 if ((e
&& *e
) || (x
< 0 || x
> 0xff))
54 return "Invalid bus number";
60 if (mid
[0] && strcmp(mid
, "*"))
62 long int x
= strtol(mid
, &e
, 16);
63 if ((e
&& *e
) || (x
< 0 || x
> 0x1f))
64 return "Invalid slot number";
67 if (dot
&& dot
[0] && strcmp(dot
, "*"))
69 long int x
= strtol(dot
, &e
, 16);
70 if ((e
&& *e
) || (x
< 0 || x
> 7))
71 return "Invalid function number";
77 /* ID filter syntax: [vendor]:[device][:class] */
80 pci_filter_parse_id(struct pci_filter
*f
, char *str
)
88 return "':' expected";
90 if (str
[0] && strcmp(str
, "*"))
92 long int x
= strtol(str
, &e
, 16);
93 if ((e
&& *e
) || (x
< 0 || x
> 0xffff))
94 return "Invalid vendor ID";
100 if (s
[0] && strcmp(s
, "*"))
102 long int x
= strtol(s
, &e
, 16);
103 if ((e
&& *e
) || (x
< 0 || x
> 0xffff))
104 return "Invalid device ID";
107 if (c
&& c
[0] && strcmp(s
, "*"))
109 long int x
= strtol(c
, &e
, 16);
110 if ((e
&& *e
) || (x
< 0 || x
> 0xffff))
111 return "Invalid class code";
118 pci_filter_match(struct pci_filter
*f
, struct pci_dev
*d
)
120 if ((f
->domain
>= 0 && f
->domain
!= d
->domain
) ||
121 (f
->bus
>= 0 && f
->bus
!= d
->bus
) ||
122 (f
->slot
>= 0 && f
->slot
!= d
->dev
) ||
123 (f
->func
>= 0 && f
->func
!= d
->func
))
125 if (f
->device
>= 0 || f
->vendor
>= 0)
127 pci_fill_info_v32(d
, PCI_FILL_IDENT
);
128 if ((f
->device
>= 0 && f
->device
!= d
->device_id
) ||
129 (f
->vendor
>= 0 && f
->vendor
!= d
->vendor_id
))
134 pci_fill_info(d
, PCI_FILL_CLASS
);
135 if (f
->class != d
->device_class
)