summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorPete Batard <pbatard@gmail.com>2010-01-29 20:04:35 +0000
committerPete Batard <pbatard@gmail.com>2010-01-29 20:04:35 +0000
commitafe70cedf774436981defb900c5eb78d13ec13d0 (patch)
tree4e93bf005247dba8f5406c25c0d49c49ada4e99b /examples
parent47c83183c080c866c54bcf886e535ff7db907bb8 (diff)
downloadlibusb-afe70cedf774436981defb900c5eb78d13ec13d0.tar.gz
r123: reverted the use of usb_interface in core and forced interface to be undefined always on Windows
Diffstat (limited to 'examples')
-rw-r--r--examples/xusb.c26
1 files changed, 21 insertions, 5 deletions
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 <string.h>
#include <stdarg.h>
-#include <libusb/libusb.h>
-
#ifdef OS_WINDOWS
#include <windows.h>
#define msleep(msecs) Sleep(msecs)
@@ -42,10 +40,16 @@
#define msleep(msecs) usleep(1000*msecs)
#endif
+#include <libusb/libusb.h>
+
#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<RETRY_MAX));
+ if (r != LIBUSB_SUCCESS) {
+ perr(" send_mass_storage_command: %s\n", libusb_strerror(r));
+ return -1;
+ }
+
+ printf(" sent %d CDB bytes (%d)\n", cdb_len,sizeof(cbw));
return 0;
}