summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorPete Batard <pbatard@gmail.com>2010-01-14 01:26:01 +0000
committerPete Batard <pbatard@gmail.com>2010-01-14 01:26:01 +0000
commit191930f7007f373144ee7ecfc098eb390a33265d (patch)
treec24f780f70f0cd0c7add5d967b0406e7c4101ee2 /examples
parent0cf1a367fabb80de559b7bb3e99ee541e59510ae (diff)
downloadlibusb-191930f7007f373144ee7ecfc098eb390a33265d.tar.gz
svn r42:
- code cleanup - device reset improvement (tentative) - inquiry request for Mass Storage in xusb.c
Diffstat (limited to 'examples')
-rw-r--r--examples/xusb.c43
1 files changed, 38 insertions, 5 deletions
diff --git a/examples/xusb.c b/examples/xusb.c
index d2124a0..0341d7f 100644
--- a/examples/xusb.c
+++ b/examples/xusb.c
@@ -134,6 +134,16 @@ int test_mass_storage(libusb_device_handle *handle)
unsigned char lun;
struct command_block_wrapper cbw;
struct command_status_wrapper csw;
+ uint8_t buffer[512];
+ if (buffer == NULL) {
+ perr("failed to allocate mass storage test buffer\n");
+ return -1;
+ }
+
+ // This reset doesn't seem to work...
+ printf("Resetting device...\n");
+ CALL_CHECK(libusb_reset_device(handle));
+
printf("Sending Mass Storage Reset...\n");
CALL_CHECK(libusb_control_transfer(handle, LIBUSB_ENDPOINT_OUT|LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE,
BOMS_RESET, 0, 0, NULL, 0, 1000));
@@ -152,15 +162,31 @@ int test_mass_storage(libusb_device_handle *handle)
cbw.bCBWLUN = 0;
cbw.bCBWCBLength = 1;
- CALL_CHECK(libusb_bulk_transfer(handle, 0x01, (unsigned char*)&cbw, 16, &size, 1000));
+ CALL_CHECK(libusb_bulk_transfer(handle, 0x01, (unsigned char*)&cbw, 16, &size, 1000));
printf("sent %d bytes\n", size);
- CALL_CHECK(libusb_bulk_transfer(handle, 0x81, (unsigned char*)&csw, 13, &size, 1000));
+ CALL_CHECK(libusb_bulk_transfer(handle, 0x81, (unsigned char*)&csw, 13, &size, 1000));
printf("received %d bytes\n", size);
printf("Tag = %08X\n", csw.dCSWTag);
printf("Status = %02X\n", csw.bCSWStatus);
- printf("Resetting device...\n");
- CALL_CHECK(libusb_reset_device(handle));
+ // Send Inquiry
+ cbw.dCBWSignature[0] = 'U';
+ cbw.dCBWSignature[1] = 'S';
+ cbw.dCBWSignature[2] = 'B';
+ cbw.dCBWSignature[3] = 'C';
+ cbw.dCBWTag = 0x01234567;
+ cbw.dCBWDataTransferLength = 0x60;
+ cbw.bmCBWFlags = 0x80;
+ cbw.bCBWLUN = 0;
+ cbw.bCBWCBLength = 6;
+ cbw.CBWCB[0] = 0x12; // Inquiry
+ cbw.CBWCB[4] = 0x60; // Inquiry data size
+
+ CALL_CHECK(libusb_bulk_transfer(handle, 0x01, (unsigned char*)&cbw, 22, &size, 100));
+ printf("sent %d bytes\n", size);
+ CALL_CHECK(libusb_bulk_transfer(handle, 0x81, (unsigned char*)&buffer, 0x60, &size, 100));
+ printf("received %d bytes\n", size);
+ printf("VID:PID:REV:SPE %s:%s:%s:%s\n", &buffer[8], &buffer[16], &buffer[32], &buffer[38]);
return 0;
}
@@ -172,6 +198,7 @@ int test_device(uint16_t vid, uint16_t pid)
const struct libusb_endpoint_descriptor *endpoint;
int i, j, k, r;
int iface, nb_ifaces;
+ int test_scsi = 0;
printf("Opening device...\n");
handle = libusb_open_device_with_vid_pid(NULL, vid, pid);
@@ -206,6 +233,12 @@ int test_device(uint16_t vid, uint16_t pid)
conf_desc->interface[i].altsetting[j].bInterfaceClass,
conf_desc->interface[i].altsetting[j].bInterfaceSubClass,
conf_desc->interface[i].altsetting[j].bInterfaceProtocol);
+ if ( (conf_desc->interface[i].altsetting[j].bInterfaceClass == LIBUSB_CLASS_MASS_STORAGE)
+ && ( (conf_desc->interface[i].altsetting[j].bInterfaceSubClass == 0x01)
+ || (conf_desc->interface[i].altsetting[j].bInterfaceSubClass == 0x06) ) ) {
+ // Mass storage devices that can use basic SCSI commands
+ test_scsi = -1;
+ }
for (k=0; k<conf_desc->interface[i].altsetting[j].bNumEndpoints; k++) {
endpoint = &conf_desc->interface[i].altsetting[j].endpoint[k];
printf(" endpoint[%d].address: %02X\n", k, endpoint->bEndpointAddress);
@@ -245,7 +278,7 @@ int test_device(uint16_t vid, uint16_t pid)
printf("Got string: \"%s\"\n", string);
}
- if (test_mode == USE_KEY) {
+ if (test_scsi) {
CALL_CHECK(test_mass_storage(handle));
}