--- usbutils-0.7/usbmodules.h Fri Nov 3 06:00:32 2000 +++ usbutils/usbmodules.h Sat Jan 20 03:33:25 2001 @@ -1,7 +1,19 @@ /* Declaring the usb_device_id fields as unsigned int simplifies the sscanf call. */ +#define USB_MATCH_VENDOR 0x0001 +#define USB_MATCH_PRODUCT 0x0002 +#define USB_MATCH_DEV_LO 0x0004 +#define USB_MATCH_DEV_HI 0x0008 +#define USB_MATCH_DEV_CLASS 0x0010 +#define USB_MATCH_DEV_SUBCLASS 0x0020 +#define USB_MATCH_DEV_PROTOCOL 0x0040 +#define USB_MATCH_INT_CLASS 0x0080 +#define USB_MATCH_INT_SUBCLASS 0x0100 +#define USB_MATCH_INT_PROTOCOL 0x0200 + struct usbmap_entry { + unsigned int match_flags; /* * vendor/product codes are checked, if vendor is nonzero * Range is for device revision (bcdDevice), inclusive; --- usbutils-0.7/usbmodules.c Fri Nov 3 07:30:52 2000 +++ usbutils/usbmodules.c Sat Jan 20 03:38:53 2001 @@ -3,13 +3,17 @@ /* * usmodules.c -- pcimodules like utility for the USB bus * - * Written by primarily by Adam J. Richter. lspci.c is derived from: - * lsusb.c, written by Thomas Sailer, and pcimodules.c, which is - * also written by Adam J. Richter. usbmodules.h is derived from - * linux-2.4.0-test10/include/linux/usb.h (exact authorship unknown, - * probably Randy Dunlap). + * lsusb.c is derived from: * - * Copyright (C) 2000 Yggdrasil Computing, Inc. + * lspci.c by Thomas Sailer, + * pcimodules.c by Adam J. Richter + * linux-2.4.0-test10/include/linux/usb.h probably by Randy Dunlap + * + * The code in usbmodules not derived from elsewhere was written by + * Adam J. Richter. David Brownell added the --mapfile and --version + * options. + * + * Copyright (C) 2000, 2001 Yggdrasil Computing, Inc. * Copyright (C) 1999 Thomas Sailer (sailer@ife.ee.ethz.ch) * * This program is free software; you can redistribute it and/or modify @@ -92,8 +96,6 @@ static char *checkname = NULL; -static const char *procbususb = "/proc/bus/usb"; - static int idVendor; static int idProduct; static int bcdDevice; @@ -109,6 +111,80 @@ fprintf(stderr, "Memory allocation failure.\n"); exit(1); } + return result; +} + +static int +scan_without_flags(const char *line, struct usbmap_entry *entry, char *name) { + unsigned int driver_info; + if (sscanf(line, + "%s 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", + name, + &entry->idVendor, + &entry->idProduct, + &entry->bcdDevice_lo, + &entry->bcdDevice_hi, + &entry->bDeviceClass, + &entry->bDeviceSubClass, + &entry->bDeviceProtocol, + &entry->bInterfaceClass, + &entry->bInterfaceSubClass, + &entry->bInterfaceProtocol, + &driver_info) != 12) + return 0; + + entry->match_flags = 0; + + /* idVendor==0 is the wildcard for both idVendor and idProduct, + because idProduct==0 is a legitimate product ID. */ + if (entry->idVendor) + entry->match_flags |= USB_MATCH_VENDOR | USB_MATCH_PRODUCT; + + if (entry->bcdDevice_lo) + entry->match_flags |= USB_MATCH_DEV_LO; + + if (entry->bcdDevice_hi) + entry->match_flags |= USB_MATCH_DEV_HI; + + if (entry->bDeviceClass) + entry->match_flags |= USB_MATCH_DEV_CLASS; + + if (entry->bDeviceSubClass) + entry->match_flags |= USB_MATCH_DEV_SUBCLASS; + + if (entry->bDeviceProtocol) + entry->match_flags |= USB_MATCH_DEV_PROTOCOL; + + if (entry->bInterfaceClass) + entry->match_flags |= USB_MATCH_INT_CLASS; + + if (entry->bInterfaceSubClass) + entry->match_flags |= USB_MATCH_INT_SUBCLASS; + + if (entry->bInterfaceProtocol) + entry->match_flags |= USB_MATCH_INT_PROTOCOL; + + return 1; +} + +static int +scan_with_flags(const char *line, struct usbmap_entry *entry, char *name) { + unsigned int driver_info; + return (sscanf(line, "%s 0x%x 0x%x " + "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", + name, + &entry->match_flags, + &entry->idVendor, + &entry->idProduct, + &entry->bcdDevice_lo, + &entry->bcdDevice_hi, + &entry->bDeviceClass, + &entry->bDeviceSubClass, + &entry->bDeviceProtocol, + &entry->bInterfaceClass, + &entry->bInterfaceSubClass, + &entry->bInterfaceProtocol, + &driver_info) == 13); } void @@ -120,7 +196,6 @@ char line[LINELENGTH]; struct usbmap_entry *prev; struct usbmap_entry *entry; - unsigned int driver_data; char name[LINELENGTH]; if (uname(&utsname) < 0) { @@ -140,18 +215,8 @@ entry = xmalloc(sizeof(struct usbmap_entry)); - if (sscanf(line, "%s 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", - name, - &entry->idVendor, - &entry->idProduct, - &entry->bcdDevice_lo, - &entry->bcdDevice_hi, - &entry->bDeviceClass, - &entry->bDeviceSubClass, - &entry->bDeviceProtocol, - &entry->bInterfaceClass, - &entry->bInterfaceSubClass, - &entry->bInterfaceProtocol) != 10) { + if (!scan_with_flags(line, entry, name) && + !scan_without_flags(line, entry, name)) { fprintf (stderr, "modules.usbmap unparsable line: %s.\n", line); free(entry); @@ -195,45 +260,44 @@ for (mod = usbmap_list; mod != NULL; mod = mod->next) { - if (mod->idVendor && + if ((mod->match_flags & USB_MATCH_VENDOR) && mod->idVendor != idVendor) continue; - if (mod->idProduct && + if ((mod->match_flags & USB_MATCH_PRODUCT) && mod->idProduct != idProduct) continue; - /* No need to test mod->bcdDevice_lo != 0, since 0 is never - greater than any unsigned number. */ - if (mod->bcdDevice_lo > bcdDevice) + if ((mod->match_flags & USB_MATCH_DEV_LO) && + mod->bcdDevice_lo > bcdDevice) continue; - if (mod->bcdDevice_hi && + if ((mod->match_flags & USB_MATCH_DEV_HI) && mod->bcdDevice_hi < bcdDevice) continue; - if (mod->bDeviceClass && + if ((mod->match_flags & USB_MATCH_DEV_CLASS) && mod->bDeviceClass != bDeviceClass) continue; - if (mod->bDeviceSubClass && - mod->bDeviceSubClass!= bDeviceClass) + if ((mod->match_flags & USB_MATCH_DEV_SUBCLASS) && + mod->bDeviceSubClass != bDeviceSubClass) continue; - if (mod->bDeviceProtocol && + if ((mod->match_flags & USB_MATCH_DEV_PROTOCOL) && mod->bDeviceProtocol != bDeviceProtocol) continue; - if (mod->bInterfaceClass - && mod->bInterfaceClass != bInterfaceClass) + if ((mod->match_flags & USB_MATCH_INT_CLASS) && + mod->bInterfaceClass != bInterfaceClass) continue; - if (mod->bInterfaceSubClass && + if ((mod->match_flags & USB_MATCH_INT_SUBCLASS) && mod->bInterfaceSubClass != bInterfaceSubClass) continue; - if (mod->bInterfaceProtocol - && mod->bInterfaceProtocol != bInterfaceProtocol) + if ((mod->match_flags & USB_MATCH_INT_PROTOCOL) && + mod->bInterfaceProtocol != bInterfaceProtocol) continue; if (checkname != NULL) { @@ -286,9 +350,6 @@ { unsigned char buf[1024], *p; unsigned int sz; - int bInterfaceClass; - int bInterfaceSubClass; - int bInterfaceProtocol; if (usb_control_msg(fd, USB_DIR_IN, USB_REQ_GET_DESCRIPTOR, (USB_DT_CONFIG << 8) | nr, @@ -327,8 +388,6 @@ static void process_device(const char *path) { unsigned char buf[USB_DT_DEVICE_SIZE]; - unsigned int vid, pid; - char vendor[128], product[128]; int fd; unsigned int i, maxcfg;