From 1e5a02e76f483782abec8e685fec47a83ce78fab Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Thu, 12 Feb 2009 00:41:05 +0000 Subject: [PATCH] Renamed usb_dev_info to listusb and made it more useful: By default it now presents a relatively concise list of USB devices found on the bus, with an optional -v flag to dump exhaustive detail. It still also takes an optional device parameter in case you only want information for a particular device. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29185 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- build/jam/HaikuImage | 4 +- src/bin/Jamfile | 2 +- src/bin/{usb_dev_info.cpp => listusb.cpp} | 117 +++++++++++++++++----- 3 files changed, 94 insertions(+), 29 deletions(-) rename src/bin/{usb_dev_info.cpp => listusb.cpp} (53%) diff --git a/build/jam/HaikuImage b/build/jam/HaikuImage index 561b1002e9..8df4682d5b 100644 --- a/build/jam/HaikuImage +++ b/build/jam/HaikuImage @@ -30,7 +30,7 @@ BEOS_BIN = "[" addattr alert arp base64 basename bc beep bootman bzip2 isvolume join keymap kill less lessecho lesskey link listarea listattr listimage listdev - listport listres listsem ln locate logger login logname ls lsindex + listport listres listsem listusb ln locate logger login logname ls lsindex make makebootable md5sum merge mimeset mkdos mkdir mkfifo mkfs mkindex modifiers mount mount_nfs mountvolume mv nc netstat nl nohup od open passwd paste @@ -43,7 +43,7 @@ BEOS_BIN = "[" addattr alert arp base64 basename bc beep bootman bzip2 tac tail tar tcpdump tcptester tee telnet telnetd test top touch tput tr traceroute translate true tsort tty uname unchop unexpand unmount uniq unrar unshar unzip unzipsfx updatedb - uptime urlwrapper usb_dev_info useradd uudecode uuencode + uptime urlwrapper useradd uudecode uuencode vdir version vim vmstat waitfor wc wget whoami xargs xres yes zdiff zforce zgrep zip zipcloak zipgrep zipnote zipsplit zmore znew ; diff --git a/src/bin/Jamfile b/src/bin/Jamfile index 401e3249ea..6389bbdaf1 100644 --- a/src/bin/Jamfile +++ b/src/bin/Jamfile @@ -150,7 +150,7 @@ StdBinCommands # standard commands that need libbe.so, libdevice.so StdBinCommands - usb_dev_info.cpp + listusb.cpp : be libdevice.so : $(haiku-utils_rsrc) ; # standard commands that need libbluetooth.so, due the Bluetooth Kit diff --git a/src/bin/usb_dev_info.cpp b/src/bin/listusb.cpp similarity index 53% rename from src/bin/usb_dev_info.cpp rename to src/bin/listusb.cpp index 5c7107d127..4d34b6187b 100644 --- a/src/bin/usb_dev_info.cpp +++ b/src/bin/listusb.cpp @@ -6,6 +6,10 @@ * Copyright 2007-2008, Haiku Inc. All rights reserved. */ +#include +#include +#include +#include #include #include @@ -89,43 +93,104 @@ DumpConfiguration(const BUSBConfiguration *configuration) static void -DumpInfo(BUSBDevice &device) +DumpInfo(BUSBDevice &device, bool verbose) { - printf("[Device]\n"); - printf(" Class .................. 0x%02x\n", device.Class()); - printf(" Subclass ............... 0x%02x\n", device.Subclass()); - 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(" Manufacturer String .... \"%s\"\n", device.ManufacturerString()); - printf(" Product String ......... \"%s\"\n", device.ProductString()); - printf(" Serial Number .......... \"%s\"\n", device.SerialNumberString()); - - for (uint32 i = 0; i < device.CountConfigurations(); i++) { - printf(" [Configuration %lu]\n", i); - DumpConfiguration(device.ConfigurationAt(i)); + if (verbose) { + printf("[Device %s]\n", device.Location()); + printf(" Class .................. 0x%02x\n", device.Class()); + printf(" Subclass ............... 0x%02x\n", device.Subclass()); + 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(" Manufacturer String .... \"%s\"\n", device.ManufacturerString()); + printf(" Product String ......... \"%s\"\n", device.ProductString()); + printf(" Serial Number .......... \"%s\"\n", device.SerialNumberString()); + + for (uint32 i = 0; i < device.CountConfigurations(); i++) { + printf(" [Configuration %lu]\n", i); + DumpConfiguration(device.ConfigurationAt(i)); + } + } else { + printf("%04x:%04x %s %s (version %04x)\n", device.VendorID(), device.ProductID(), device.ManufacturerString(), device.ProductString(), device.Version()); } } +class DumpRoster : public BUSBRoster +{ + public: + DumpRoster(bool verbose); + ~DumpRoster(); + + virtual status_t DeviceAdded(BUSBDevice *device); + virtual void DeviceRemoved(BUSBDevice *device); + + private: + bool fVerbose; +}; + + +DumpRoster::DumpRoster(bool verbose) + : BUSBRoster(), + fVerbose(verbose) +{ +} + + +DumpRoster::~DumpRoster() +{ +} + +status_t +DumpRoster::DeviceAdded(BUSBDevice *device) +{ + DumpInfo(*device, fVerbose); + return B_OK; +} + +void +DumpRoster::DeviceRemoved(BUSBDevice *) +{ +} + int main(int argc, char *argv[]) { - if(argc == 2) { - BUSBDevice device(argv[1]); - + bool verbose = false; + BString devname = ""; + for (int i = 1; i < argc; i++) { + if (argv[i][0] == '-') { + if (argv[i][1] == 'v') + verbose = true; + else { + printf("Usage: listusb [-v] [device]"); + printf("-v: Show more detailed information including interfaces, configurations, etc.\n\n"); + printf("If a device is not specified, all devices found on the bus will be listed\n"); + return 1; + } + } else { + devname = argv[i]; + } + } + + if (devname.Length() > 0) { + BUSBDevice device(devname.String()); if (device.InitCheck() < B_OK) { - printf("Cannot open USB device: %s\n", argv[1]); + printf("Cannot open USB device: %s\n", devname.String()); return 1; } else { - DumpInfo(device); - return 0; + DumpInfo(device, verbose); + return 0; } } else { - printf("Usage: info \n"); - return 1; - } + DumpRoster *roster = new DumpRoster(verbose); + roster->Start(); + roster->Stop(); + delete roster; + } + + return 0; }