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:
@@ -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 <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
|
||||
zdiff zforce zgrep zip zipcloak <bin>zipgrep zipnote zipsplit zmore znew
|
||||
;
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
* Copyright 2007-2008, Haiku Inc. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <Directory.h>
|
||||
#include <Entry.h>
|
||||
#include <Path.h>
|
||||
#include <String.h>
|
||||
#include <USBKit.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -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 <device>\n");
|
||||
return 1;
|
||||
}
|
||||
DumpRoster *roster = new DumpRoster(verbose);
|
||||
roster->Start();
|
||||
roster->Stop();
|
||||
delete roster;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user