diff --git a/headers/private/shared/usb-utils.h b/headers/private/shared/usb-utils.h index fe6749a90b..4ce85ea259 100644 --- a/headers/private/shared/usb-utils.h +++ b/headers/private/shared/usb-utils.h @@ -1,23 +1,25 @@ /* - * Copyright 2008, Haiku, Inc. All Rights Reserved. + * Copyright 2008-2012, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: * Jérôme Duval */ + #include -#include "usbdevs.h" -#include "usbdevs_data.h" +#include "usbhdr.h" + void usb_get_vendor_info(uint16 vendorID, const char **vendorName) { int i; - for (i = 0; usb_knowndevs[i].vendor != 0; i++) { - if (usb_knowndevs[i].vendor == vendorID) { - *vendorName = usb_knowndevs[i].vendorname; + for (i = 0; i < (int)USB_VENTABLE_LEN; i++) { + if (UsbVenTable[i].VenId == vendorID) { + *vendorName = UsbVenTable[i].VenName && UsbVenTable[i].VenName[0] + ? UsbVenTable[i].VenName : NULL; return; } } @@ -26,18 +28,16 @@ usb_get_vendor_info(uint16 vendorID, const char **vendorName) void -usb_get_vendor_device_info(uint16 vendorID, uint16 deviceID, const char **vendorName, const char **deviceName) +usb_get_device_info(uint16 vendorID, uint16 deviceID, const char **deviceName) { int i; - for (i = 0; usb_knowndevs[i].vendor != 0; i++) { - if (usb_knowndevs[i].vendor == vendorID - && usb_knowndevs[i].product == deviceID - && usb_knowndevs[i].flags != USB_KNOWNDEV_NOPROD) { - *deviceName = usb_knowndevs[i].productname; - *vendorName = usb_knowndevs[i].vendorname; + // search for the device + for (i = 0; i < (int)USB_DEVTABLE_LEN; i++) { + if (UsbDevTable[i].VenId == vendorID && UsbDevTable[i].DevId == deviceID ) { + *deviceName = UsbDevTable[i].ChipDesc && UsbDevTable[i].ChipDesc[0] + ? UsbDevTable[i].ChipDesc : NULL; return; } } - *vendorName = NULL; *deviceName = NULL; } diff --git a/src/apps/devices/Jamfile b/src/apps/devices/Jamfile index e69b600b1e..89f45823a6 100644 --- a/src/apps/devices/Jamfile +++ b/src/apps/devices/Jamfile @@ -19,28 +19,30 @@ rule ISAPnPHeaderGen actions ISAPnPHeaderGen1 { - grep '^PNP[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] ' $(2[1]) | gawk -f $(2[2]) > $(1) ; + grep '^PNP[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] ' $(2[1]) \ +| gawk -f $(2[2]) > $(1) ; } ISAPnPHeaderGen [ FGristFiles isapnpids.h ] : isapnp_devids.txt : devlist2h.awk ; -rule USBHeaderGen +rule USBDevsHeaderGen { SEARCH on $(2) = $(SEARCH_SOURCE) ; SEARCH on $(3) = $(SEARCH_SOURCE) ; Depends $(1) : $(2) $(3) ; MakeLocateArch $(<) ; - USBHeaderGen1 $(1) : $(2) $(3) ; + USBDevsHeaderGen1 $(1) : $(2) $(3) ; LocalClean clean : $(<) ; } -actions USBHeaderGen1 +actions USBDevsHeaderGen1 { gawk -v HEADERFILE=$(1[1]) -v DATAFILE=$(1[2]) -f $(2[2]) $(2[1]) } -USBHeaderGen [ FGristFiles usbdevs.h usbdevs_data.h ] : usbdevs : usb_devlist2h.awk ; +USBDevsHeaderGen [ FGristFiles usbdevs.h usbdevs_data.h ] : usbdevs + : usb_devlist2h.awk ; rule PCIHeaderGen { @@ -63,6 +65,27 @@ local pciidsFile = [ DownloadFile pci.ids PCIHeaderGen [ FGristFiles pcihdr.h ] : $(pciidsFile) : pci-header.awk ; +rule USBHeaderGen +{ + SEARCH on $(2) = $(SEARCH_SOURCE) ; + SEARCH on $(3) = $(SEARCH_SOURCE) ; + + Depends $(1) : $(2) $(3) ; + MakeLocateArch $(<) ; + USBHeaderGen1 $(1) : $(2) $(3) ; + LocalClean clean : $(<) ; +} + +actions USBHeaderGen1 +{ + gawk -v HEADERFILE=$(1) -f $(2[2]) $(2[1]) +} + +local usbidsFile = [ DownloadFile usb.ids + : http://www.linux-usb.org/usb.ids ] ; + +USBHeaderGen [ FGristFiles usbhdr.h ] : $(usbidsFile) : usb-header.awk ; + Application Devices : DevicesApplication.cpp DevicesView.cpp @@ -91,7 +114,5 @@ DoCatalogs Devices : Device.cpp ; -Includes [ FGristFiles DevicesInfo.cpp ] : [ FGristFiles isapnpids.h usbdevs.h - usbdevs_data.h ] ; -Includes [ FGristFiles ConfigurationWindow.cpp ] : [ FGristFiles pcihdr.h ] ; +Includes [ FGristFiles DevicePCI.cpp ] : [ FGristFiles pcihdr.h ] ; diff --git a/src/apps/devices/pci-header.awk b/src/apps/devices/pci-header.awk index 2ee642666e..2d3fad9f71 100644 --- a/src/apps/devices/pci-header.awk +++ b/src/apps/devices/pci-header.awk @@ -56,6 +56,7 @@ BEGIN { /^\t[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] / { device = substr($0, 8) + gsub( /\\/, "\\\\", device ) gsub( /\"/, "\\\"", device ) # store device ID for possible devices afterwards diff --git a/src/apps/devices/usb-header.awk b/src/apps/devices/usb-header.awk new file mode 100644 index 0000000000..1aef370352 --- /dev/null +++ b/src/apps/devices/usb-header.awk @@ -0,0 +1,95 @@ +# USB Header script +# +# Copyright 2006-2012, Haiku. +# Distributed under the terms of the MIT License. +# +# Authors: +# John Drinkwater, john@nextraweb.com +# +# Use with http://www.linux-usb.org/usb.ids +# run as: awk -v HEADERFILE=usbhdr.h -f usb-header.awk usb.ids + +BEGIN { + + # field separator, defining because user could have overridden + FS = " " + + # Pass this in from outside with -v HEADERFILE=filenametouse + # we require usbhdr.h for our system + ofile = HEADERFILE + + # possibly use this in the future + cleanvalues = "[^A-Za-z0-9{}\"'&@?!*.,:;+<> \\t\\/_\\[\\]=#()-]" + # ToDo: currently IDs aren't checked, we dumbly assume the source is clean + + # descriptive output header + print "#if 0" > ofile + print "#\tUSBHDR.H: USB Vendors, Devices\n#" > ofile + print "#\tGenerated by usb-header.awk, source data from the following URI:\n#\thttp://www.linux-usb.org/usb.ids\n#" > ofile + print "#\tHeader created on " strftime( "%A, %d %b %Y %H:%M:%S %Z", systime() ) > ofile + print "#endif" > ofile + + # and we start with vendors.. + print "\ntypedef struct _USB_VENTABLE\n{\n\tunsigned short\tVenId ;\n\tconst char *\tVenName ;\n} USB_VENTABLE, *PUSB_VENTABLE ;\n" > ofile + print "USB_VENTABLE\tUsbVenTable [] =\n{" > ofile +} + +# matches vendor - starts with an id as first thing on the line +# because this occurs first in the header file, we output it without worry +/^[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] / { + + if ( vendorcount++ > 0 ) { + formatting = ",\n" + } else { + formatting = "" + } + + # store vendor ID for possible devices afterwards + vendorid = $1 + vendor = substr($0, 7) + gsub( /\"/, "\\\"", vendor ) + + printf formatting "\t{ 0x" vendorid ", \"" vendor "\" }" > ofile +} + +# matches device +/^\t[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]] / { + + device = substr($0, 8) + gsub( /\\/, "\\\\", device ) + gsub( /\"/, "\\\"", device ) + + # store device ID for possible devices afterwards + deviceid = $1 + devicecount++ + devices[devicecount, 1] = vendorid + devices[devicecount, 2] = $1 + devices[devicecount, 3] = device +} + +# We've processed the file, now output. +END { + + print "\n};\n\n// Use this value for loop control during searching:\n#define\tUSB_VENTABLE_LEN\t(sizeof(UsbVenTable)/sizeof(USB_VENTABLE))\n" > ofile + + if ( devicecount > 0 ) { + + print "typedef struct _USB_DEVTABLE\n{\n\tunsigned short VenId ;\n\tunsigned short DevId ;\n\tconst char *\tChipDesc ;\n} USB_DEVTABLE, *PUSB_DEVTABLE ;\n" > ofile + print "USB_DEVTABLE\tUsbDevTable [] =\n{" > ofile + for (i = 1; i <= devicecount; i++) { + + if (i != 1) { + formatting = ",\n" + } else { + formatting = "" + } + printf formatting "\t{ 0x" devices[i, 1] ", 0x" devices[i, 2] ", \"" devices[i, 3] "\" }" > ofile + } + print "\n} ;\n\n// Use this value for loop control during searching:\n#define USB_DEVTABLE_LEN (sizeof(UsbDevTable)/sizeof(USB_DEVTABLE))\n" > ofile + + } + + close(ofile) +} + + diff --git a/src/bin/Jamfile b/src/bin/Jamfile index c8e033f256..45589320fd 100644 --- a/src/bin/Jamfile +++ b/src/bin/Jamfile @@ -198,7 +198,9 @@ StdBinCommands : be libdevice.so : $(haiku-utils_rsrc) ; ObjectHdrs [ FGristFiles listusb$(SUFOBJ) ] - : [ FDirName $(SUBDIR) $(DOTDOT) add-ons kernel bus_managers usb ] ; + : [ FDirName $(SUBDIR) $(DOTDOT) add-ons kernel bus_managers usb ] + [ FDirName $(TARGET_COMMON_DEBUG_OBJECT_DIR) apps devices ] ; +Includes [ FGristFiles listusb.cpp ] : usbhdr.h ; # standard commands that need libbluetooth.so, due the Bluetooth Kit StdBinCommands diff --git a/src/bin/listusb.cpp b/src/bin/listusb.cpp index f1e9782a1e..b30f89989d 100644 --- a/src/bin/listusb.cpp +++ b/src/bin/listusb.cpp @@ -14,6 +14,7 @@ #include #include "usbspec_private.h" +#include "usb-utils.h" const char* @@ -152,6 +153,10 @@ DumpInfo(BUSBDevice &device, bool verbose) return; } + const char *vendorName = NULL, *deviceName = NULL; + usb_get_vendor_info(device.VendorID(), &vendorName); + usb_get_device_info(device.VendorID(), device.ProductID(), &deviceName); + printf("[Device /dev/bus/usb%s]\n", device.Location()); printf(" Class .................. 0x%02x (%s)\n", device.Class(), ClassName(device.Class())); @@ -159,9 +164,13 @@ DumpInfo(BUSBDevice &device, bool verbose) printf(" Protocol ............... 0x%02x\n", device.Protocol()); printf(" Max Endpoint 0 Packet .. %d\n", device.MaxEndpoint0PacketSize()); printf(" USB Version ............ 0x%04x\n", device.USBVersion()); - printf(" Vendor ID .............. 0x%04x\n", device.VendorID()); - printf(" Product ID ............. 0x%04x\n", device.ProductID()); - printf(" Product Version ........ 0x%04x\n", device.Version()); + printf(" Vendor ID .............. 0x%04x", device.VendorID()); + if (vendorName != NULL) + printf(" (%s)", vendorName); + printf("\n Product ID ............. 0x%04x", device.ProductID()); + if (deviceName != NULL) + printf(" (%s)", deviceName); + printf("\n Product Version ........ 0x%04x\n", device.Version()); printf(" Manufacturer String .... \"%s\"\n", device.ManufacturerString()); printf(" Product String ......... \"%s\"\n", device.ProductString()); printf(" Serial Number .......... \"%s\"\n", device.SerialNumberString());