* Added configuration and interface strings to the output

* Added printing generic descriptors from 2000 sample code archive
* Added license header
* Adjusted style

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19914 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz 2007-01-23 16:40:36 +00:00
parent 3c0b8e7fff
commit a0398f333c

View File

@ -1,78 +1,110 @@
/*
* Originally released under the Be Sample Code License.
* Copyright 2000, Be Incorporated. All rights reserved.
*
* Modified for Haiku by François Revol and Michael Lotz.
* Copyright 2007, Haiku Inc. All rights reserved.
*/
#include <usb/USBKit.h> #include <USBKit.h>
#include <stdio.h> #include <stdio.h>
static void DumpInterface(const BUSBInterface *ifc)
static void
DumpInterface(const BUSBInterface *interface)
{ {
int i; if (!interface)
const BUSBEndpoint *ept; return;
if(!ifc) return;
printf(" Class .............. %d\n",ifc->Class()); printf(" Class .............. %d\n", interface->Class());
printf(" Subclass ........... %d\n",ifc->Subclass()); printf(" Subclass ........... %d\n", interface->Subclass());
printf(" Protocol ........... %d\n",ifc->Protocol()); printf(" Protocol ........... %d\n", interface->Protocol());
for(i=0;i<ifc->CountEndpoints();i++){ printf(" Interface String ... \"%s\"\n", interface->InterfaceString());
if(ept = ifc->EndpointAt(i)){
printf(" [Endpoint %d]\n",i); for (int32 i = 0; i < interface->CountEndpoints(); i++) {
printf(" MaxPacketSize .... %d\n",ept->MaxPacketSize()); const BUSBEndpoint *endpoint = interface->EndpointAt(i);
printf(" Interval ......... %d\n",ept->Interval()); if (!endpoint)
if(ept->IsBulk()){ continue;
printf(" [Endpoint %d]\n", i);
printf(" MaxPacketSize .... %d\n", endpoint->MaxPacketSize());
printf(" Interval ......... %d\n", endpoint->Interval());
if (endpoint->IsControl())
printf(" Type ............. Control\n");
else if (endpoint->IsBulk())
printf(" Type ............. Bulk\n"); printf(" Type ............. Bulk\n");
} else if (endpoint->IsIsochronous())
if(ept->IsIsochronous()){
printf(" Type ............. Isochronous\n"); printf(" Type ............. Isochronous\n");
} else if (endpoint->IsInterrupt())
if(ept->IsInterrupt()){
printf(" Type ............. Interrupt\n"); printf(" Type ............. Interrupt\n");
}
if(ept->IsInput()){ if(endpoint->IsInput())
printf(" Direction ........ Input\n"); printf(" Direction ........ Input\n");
} else { else
printf(" Direction ........ Output\n"); printf(" Direction ........ Output\n");
} }
}
char buffer[256];
usb_descriptor *generic = (usb_descriptor *)buffer;
for (int32 i = 0; interface->OtherDescriptorAt(i, generic, 256) == B_OK; i++) {
printf(" [Descriptor %d]\n", i);
printf(" Type ............. 0x%02x\n", generic->generic.descriptor_type);
printf(" Data ............. ");
for(int32 j = 0; j < generic->generic.length; j++)
printf("%02x ", generic->generic.data[j]);
printf("\n");
} }
} }
static void DumpConfiguration(const BUSBConfiguration *conf)
static void
DumpConfiguration(const BUSBConfiguration *configuration)
{ {
int i; if (!configuration)
if(!conf) return; return;
for(i=0;i<conf->CountInterfaces();i++){
printf(" [Interface %d]\n",i); printf(" Configuration String . \"%s\"\n", configuration->ConfigurationString());
DumpInterface(conf->InterfaceAt(i)); for (int32 i = 0; i < configuration->CountInterfaces(); i++) {
printf(" [Interface %d]\n", i);
DumpInterface(configuration->InterfaceAt(i));
} }
} }
static void DumpInfo(BUSBDevice &dev)
{
int i;
static void
DumpInfo(BUSBDevice &device)
{
printf("[Device]\n"); printf("[Device]\n");
printf("Class .................. %d\n",dev.Class()); printf("Class .................. %d\n", device.Class());
printf("Subclass ............... %d\n",dev.Subclass()); printf("Subclass ............... %d\n", device.Subclass());
printf("Protocol ............... %d\n",dev.Protocol()); printf("Protocol ............... %d\n", device.Protocol());
printf("Vendor ID .............. 0x%04x\n",dev.VendorID()); printf("Vendor ID .............. 0x%04x\n", device.VendorID());
printf("Product ID ............. 0x%04x\n",dev.ProductID()); printf("Product ID ............. 0x%04x\n", device.ProductID());
printf("Version ................ 0x%04x\n",dev.Version()); printf("Version ................ 0x%04x\n", device.Version());
printf("Manufacturer String .... \"%s\"\n",dev.ManufacturerString()); printf("Manufacturer String .... \"%s\"\n", device.ManufacturerString());
printf("Product String ......... \"%s\"\n",dev.ProductString()); printf("Product String ......... \"%s\"\n", device.ProductString());
printf("Serial Number .......... \"%s\"\n",dev.SerialNumberString()); printf("Serial Number .......... \"%s\"\n", device.SerialNumberString());
for(i=0;i<dev.CountConfigurations();i++){ for (int32 i = 0; i < device.CountConfigurations(); i++) {
printf(" [Configuration %d]\n",i); printf(" [Configuration %d]\n", i);
DumpConfiguration(dev.ConfigurationAt(i)); DumpConfiguration(device.ConfigurationAt(i));
} }
} }
int main(int argc, char *argv[])
int
main(int argc, char *argv[])
{ {
if(argc == 2){ if(argc == 2) {
BUSBDevice dev(argv[1]); BUSBDevice device(argv[1]);
if(dev.InitCheck()){
printf("Cannot open USB device: %s\n",argv[1]); if (device.InitCheck() < B_OK) {
printf("Cannot open USB device: %s\n", argv[1]);
return 1; return 1;
} else { } else {
DumpInfo(dev); DumpInfo(device);
return 0; return 0;
} }
} else { } else {