From afe70cedf774436981defb900c5eb78d13ec13d0 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Fri, 29 Jan 2010 20:04:35 +0000 Subject: r123: reverted the use of usb_interface in core and forced interface to be undefined always on Windows --- examples/xusb.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/xusb.c b/examples/xusb.c index add6ef0..78dcbd1 100644 --- a/examples/xusb.c +++ b/examples/xusb.c @@ -32,8 +32,6 @@ #include #include -#include - #ifdef OS_WINDOWS #include #define msleep(msecs) Sleep(msecs) @@ -42,10 +40,16 @@ #define msleep(msecs) usleep(1000*msecs) #endif +#include + #if !defined(_MSC_VER) #define sscanf_s sscanf #endif +// Future versions of libusb will use usb_interface instead of interface +// in libusb_config_descriptor => catter for that +#define usb_interface interface + inline static int perr(char const *format, ...) { va_list args; @@ -178,7 +182,7 @@ int send_mass_storage_command(libusb_device_handle *handle, uint8_t endpoint, ui { static uint32_t tag = 1; uint8_t cdb_len; - int r, size; + int i, r, size; struct command_block_wrapper cbw; if (cdb == NULL) { @@ -211,8 +215,20 @@ int send_mass_storage_command(libusb_device_handle *handle, uint8_t endpoint, ui cbw.bCBWCBLength = cdb_len; memcpy(cbw.CBWCB, cdb, cdb_len); - CALL_CHECK(libusb_bulk_transfer(handle, endpoint, (unsigned char*)&cbw, sizeof(cbw), &size, 1000)); - printf(" sent %d CDB bytes\n", cdb_len); + i = 0; + do { + r = libusb_bulk_transfer(handle, endpoint, (unsigned char*)&cbw, sizeof(cbw), &size, 1000); + if (r == LIBUSB_ERROR_PIPE) { + libusb_clear_halt(handle, endpoint); + } + i++; + } while ((r == LIBUSB_ERROR_PIPE) && (i