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
This commit is contained in:
Rene Gollent
2009-02-12 00:41:05 +00:00
parent 8f7c075428
commit 1e5a02e76f
3 changed files with 94 additions and 29 deletions
+2 -2
View File
@@ -30,7 +30,7 @@ BEOS_BIN = "[" addattr alert arp base64 basename bc beep bootman bzip2
isvolume isvolume
join join
keymap kill less lessecho lesskey link listarea listattr listimage listdev 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 make makebootable md5sum merge mimeset mkdos mkdir mkfifo mkfs mkindex
modifiers mount mount_nfs mountvolume mv modifiers mount mount_nfs mountvolume mv
nc netstat nl nohup od open passwd paste 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 tac tail tar tcpdump tcptester tee telnet telnetd test top touch tput tr
traceroute translate true tsort tty traceroute translate true tsort tty
uname unchop unexpand unmount uniq unrar unshar unzip unzipsfx <bin>updatedb uname unchop unexpand unmount uniq unrar unshar unzip unzipsfx <bin>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 vdir version vim vmstat waitfor wc wget whoami xargs xres yes
zdiff zforce zgrep zip zipcloak <bin>zipgrep zipnote zipsplit zmore znew zdiff zforce zgrep zip zipcloak <bin>zipgrep zipnote zipsplit zmore znew
; ;
+1 -1
View File
@@ -150,7 +150,7 @@ StdBinCommands
# standard commands that need libbe.so, libdevice.so # standard commands that need libbe.so, libdevice.so
StdBinCommands StdBinCommands
usb_dev_info.cpp listusb.cpp
: be libdevice.so : $(haiku-utils_rsrc) ; : be libdevice.so : $(haiku-utils_rsrc) ;
# standard commands that need libbluetooth.so, due the Bluetooth Kit # standard commands that need libbluetooth.so, due the Bluetooth Kit
@@ -6,6 +6,10 @@
* Copyright 2007-2008, Haiku Inc. All rights reserved. * Copyright 2007-2008, Haiku Inc. All rights reserved.
*/ */
#include <Directory.h>
#include <Entry.h>
#include <Path.h>
#include <String.h>
#include <USBKit.h> #include <USBKit.h>
#include <stdio.h> #include <stdio.h>
@@ -89,43 +93,104 @@ DumpConfiguration(const BUSBConfiguration *configuration)
static void static void
DumpInfo(BUSBDevice &device) DumpInfo(BUSBDevice &device, bool verbose)
{ {
printf("[Device]\n"); if (verbose) {
printf(" Class .................. 0x%02x\n", device.Class()); printf("[Device %s]\n", device.Location());
printf(" Subclass ............... 0x%02x\n", device.Subclass()); printf(" Class .................. 0x%02x\n", device.Class());
printf(" Protocol ............... 0x%02x\n", device.Protocol()); printf(" Subclass ............... 0x%02x\n", device.Subclass());
printf(" Max Endpoint 0 Packet .. %d\n", device.MaxEndpoint0PacketSize()); printf(" Protocol ............... 0x%02x\n", device.Protocol());
printf(" USB Version ............ 0x%04x\n", device.USBVersion()); printf(" Max Endpoint 0 Packet .. %d\n", device.MaxEndpoint0PacketSize());
printf(" Vendor ID .............. 0x%04x\n", device.VendorID()); printf(" USB Version ............ 0x%04x\n", device.USBVersion());
printf(" Product ID ............. 0x%04x\n", device.ProductID()); printf(" Vendor ID .............. 0x%04x\n", device.VendorID());
printf(" Product Version ........ 0x%04x\n", device.Version()); printf(" Product ID ............. 0x%04x\n", device.ProductID());
printf(" Manufacturer String .... \"%s\"\n", device.ManufacturerString()); printf(" Product Version ........ 0x%04x\n", device.Version());
printf(" Product String ......... \"%s\"\n", device.ProductString()); printf(" Manufacturer String .... \"%s\"\n", device.ManufacturerString());
printf(" Serial Number .......... \"%s\"\n", device.SerialNumberString()); 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); for (uint32 i = 0; i < device.CountConfigurations(); i++) {
DumpConfiguration(device.ConfigurationAt(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 int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
if(argc == 2) { bool verbose = false;
BUSBDevice device(argv[1]); 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) { 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; return 1;
} else { } else {
DumpInfo(device); DumpInfo(device, verbose);
return 0; return 0;
} }
} else { } else {
printf("Usage: info <device>\n"); DumpRoster *roster = new DumpRoster(verbose);
return 1; roster->Start();
} roster->Stop();
delete roster;
}
return 0;
} }