From 40579b271e64c05e6cc0121941f32c0705cdf11d Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Wed, 2 Mar 2011 00:07:28 +0000 Subject: [xusb] minor improvements --- examples/xusb.c | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/examples/xusb.c b/examples/xusb.c index ed69f5a..1c404c1 100644 --- a/examples/xusb.c +++ b/examples/xusb.c @@ -1,12 +1,9 @@ /* - * xusb: libusb-winusb specific test program - * Copyright (c) 2009-2010 Pete Batard + * xusb: Generic USB test program + * Copyright (c) 2009-2011 Pete Batard * Based on lsusb, copyright (c) 2007 Daniel Drake * With contributions to Mass Storage test by Alan Stern. * - * This test program tries to access an USB device through WinUSB. - * To access your device, modify this source and add your VID/PID. - * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either @@ -138,9 +135,9 @@ static uint8_t cdb_length[256] = { }; enum test_type { + USE_GENERIC, USE_XBOX, - USE_KEY, - USE_JTAG, + USE_SCSI, USE_HID, } test_mode; uint16_t VID, PID; @@ -516,7 +513,7 @@ int test_hid(libusb_device_handle *handle, uint8_t endpoint_in) printf("\nReading HID Report Descriptors:\n"); descriptor_size = libusb_control_transfer(handle, LIBUSB_ENDPOINT_IN|LIBUSB_REQUEST_TYPE_STANDARD|LIBUSB_RECIPIENT_INTERFACE, - LIBUSB_REQUEST_GET_DESCRIPTOR, LIBUSB_DT_REPORT<<8, 0, hid_report_descriptor, 256, 1000); + LIBUSB_REQUEST_GET_DESCRIPTOR, LIBUSB_DT_REPORT<<8, 0, hid_report_descriptor, sizeof(hid_report_descriptor), 1000); if (descriptor_size < 0) { printf("failed\n"); return -1; @@ -614,7 +611,6 @@ int test_device(uint16_t vid, uint16_t pid) // Attaching/detaching the kernel driver is only relevant for Linux int iface_detached = -1; #endif - bool test_scsi = false; struct libusb_device_descriptor dev_desc; char string[128]; uint8_t string_index[3]; // indexes of the string descriptors @@ -670,7 +666,7 @@ int test_device(uint16_t vid, uint16_t pid) || (conf_desc->usb_interface[i].altsetting[j].bInterfaceSubClass == 0x06) ) && (conf_desc->usb_interface[i].altsetting[j].bInterfaceProtocol == 0x50) ) { // Mass storage devices that can use basic SCSI commands - test_scsi = true; + test_mode = USE_SCSI; } for (k=0; kusb_interface[i].altsetting[j].bNumEndpoints; k++) { endpoint = &conf_desc->usb_interface[i].altsetting[j].endpoint[k]; @@ -727,14 +723,12 @@ int test_device(uint16_t vid, uint16_t pid) case USE_HID: test_hid(handle, endpoint_in); break; + case USE_SCSI: + CALL_CHECK(test_mass_storage(handle, endpoint_in, endpoint_out)); default: break; } - if (test_scsi) { - CALL_CHECK(test_mass_storage(handle, endpoint_in, endpoint_out)); - } - printf("\n"); for (iface = 0; iface 7)) { - printf("usage: %s [-d] [-b [file]] [-h] [-i] [-j] [-k] [-l] [-s] [-x] [vid:pid]\n", argv[0]); + printf("usage: %s [-d] [-b [file]] [-h] [-i] [-j] [-k] [-x] [vid:pid]\n", argv[0]); printf(" -h: display usage\n"); printf(" -d: enable debug output (if library was compiled with debug enabled)\n"); - printf(" -b: dump raw HID report descriptor or Mass Storage first block to binary file\n"); - printf(" -i: test generic HID device (default)\n"); + printf(" -b: dump Mass Storage first block to binary file\n"); + printf(" -g: short generic test (default)\n"); printf(" -k: test generic Mass Storage USB device (using WinUSB)\n"); printf(" -j: test FTDI based JTAG device (using WinUSB)\n"); printf(" -l: test Plantronics Headset (using HID)\n"); @@ -889,4 +875,3 @@ int main(int argc, char** argv) return 0; } - -- cgit v1.2.1