/* $FreeBSD$ */ /*- * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include #include #include #include #include "dump.h" #define DUMP0(n,type,field,...) dump_field(pdev, " ", #field, n->field); #define DUMP1(n,type,field,...) dump_field(pdev, " ", #field, n->field); #define DUMP2(n,type,field,...) dump_field(pdev, " ", #field, n->field); #define DUMP3(n,type,field,...) dump_field(pdev, " ", #field, n->field); const char * dump_mode(uint8_t value) { if (value == LIBUSB20_MODE_HOST) return ("HOST"); return ("DEVICE"); } const char * dump_speed(uint8_t value) { ; /* style fix */ switch (value) { case LIBUSB20_SPEED_LOW: return ("LOW (1.5Mbps)"); case LIBUSB20_SPEED_FULL: return ("FULL (12Mbps)"); case LIBUSB20_SPEED_HIGH: return ("HIGH (480Mbps)"); case LIBUSB20_SPEED_VARIABLE: return ("VARIABLE (52-480Mbps)"); case LIBUSB20_SPEED_SUPER: return ("SUPER (5.0Gbps)"); default: break; } return ("UNKNOWN ()"); } const char * dump_power_mode(uint8_t value) { ; /* style fix */ switch (value) { case LIBUSB20_POWER_OFF: return ("OFF"); case LIBUSB20_POWER_ON: return ("ON"); case LIBUSB20_POWER_SAVE: return ("SAVE"); case LIBUSB20_POWER_SUSPEND: return ("SUSPEND"); case LIBUSB20_POWER_RESUME: return ("RESUME"); default: return ("UNKNOWN"); } } static void dump_field(struct libusb20_device *pdev, const char *plevel, const char *field, uint32_t value) { uint8_t temp_string[256]; printf("%s%s = 0x%04x ", plevel, field, value); if (strlen(plevel) == 8) { /* Endpoint Descriptor */ if (strcmp(field, "bEndpointAddress") == 0) { if (value & 0x80) printf(" \n"); else printf(" \n"); return; } if (strcmp(field, "bmAttributes") == 0) { switch (value & 0x03) { case 0: printf(" \n"); break; case 1: switch (value & 0x0C) { case 0x00: printf(" \n"); break; case 0x04: printf(" \n"); break; case 0x08: printf(" \n"); break; default: printf(" \n"); break; } break; case 2: printf(" \n"); break; default: printf(" \n"); break; } return; } } if ((field[0] == 'i') && (field[1] != 'd')) { /* Indirect String Descriptor */ if (value == 0) { printf(" \n"); return; } if (libusb20_dev_req_string_simple_sync(pdev, value, temp_string, sizeof(temp_string))) { printf(" \n"); return; } printf(" <%s>\n", temp_string); return; } if (strlen(plevel) == 2 || strlen(plevel) == 6) { /* Device and Interface Descriptor class codes */ if (strcmp(field, "bInterfaceClass") == 0 || strcmp(field, "bDeviceClass") == 0) { switch (value) { case 0x00: printf(" \n"); break; case 0x01: printf("