From 915671389f9158309dd15eec31670024bdcd4d7a Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Wed, 13 Oct 2010 23:32:24 -0400 Subject: [PATCH] lib: added WIN32 check for usb_set_configuration() On Windows, using libusb-win32, you must call usb_set_configuration() before you call claim_interface(). This commit adds a check in platform.h for this issue. --- src/Makefile.am | 1 + src/controller.cc | 3 ++- src/platform.h | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/probe.cc | 3 ++- 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 src/platform.h diff --git a/src/Makefile.am b/src/Makefile.am index a59af51e..30d5d772 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -155,6 +155,7 @@ noinst_HEADERS = cbarry.h \ debug.h \ endian.h \ strnlen.h \ + platform.h \ dp_parser.h \ j_message.h \ j_jdwp.h \ diff --git a/src/controller.cc b/src/controller.cc index 6abd718a..b66cec3a 100644 --- a/src/controller.cc +++ b/src/controller.cc @@ -26,6 +26,7 @@ #include "protostructs.h" #include "data.h" #include "endian.h" +#include "platform.h" #include #define __DEBUG_MODE__ @@ -93,7 +94,7 @@ void Controller::SetupUsb(const ProbeResult &device) throw Usb::Error(m_dev.GetLastError(), "Controller: GetConfiguration failed"); - if( cfg != BLACKBERRY_CONFIGURATION ) { + if( cfg != BLACKBERRY_CONFIGURATION || MUST_SET_CONFIGURATION ) { if( !m_dev.SetConfiguration(BLACKBERRY_CONFIGURATION) ) throw Usb::Error(m_dev.GetLastError(), "Controller: SetConfiguration failed"); diff --git a/src/platform.h b/src/platform.h new file mode 100644 index 00000000..84f91e91 --- /dev/null +++ b/src/platform.h @@ -0,0 +1,58 @@ +/// +/// \file platform.h +/// Platform-specific details +/// + +/* + Copyright (C) 2010, Net Direct Inc. (http://www.netdirect.ca/) + Copyright (C) 2010, RealVNC Ltd. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License in the COPYING file at the + root directory of this project for more details. +*/ + +#ifndef __BARRY_PLATFORM_H__ +#define __BARRY_PLATFORM_H__ + +#include "usbwrap.h" // USB specific details + +// All Windows specific detail +#if defined( WIN32 ) + +// On Windows, we must call usb_set_configuration() before claim_interface() +#define MUST_SET_CONFIGURATION 1 + +#else + +#define MUST_SET_CONFIGURATION 0 + +#endif + + + +// All FreeBSD / BSD specific detail +#if defined( __FreeBSD__ ) + +#endif + + + + +// All Mac OS X specific detail +#if defined( __APPLE__ ) && defined( __MACH__ ) + +#endif + + + +#endif + diff --git a/src/probe.cc b/src/probe.cc index 80bcdd91..e876a90e 100644 --- a/src/probe.cc +++ b/src/probe.cc @@ -32,6 +32,7 @@ #include "record-internal.h" #include "strnlen.h" #include "configfile.h" +#include "platform.h" #include #include #include @@ -225,7 +226,7 @@ void Probe::ProbeDevice(Usb::DeviceIDType devid) if( !dev.GetConfiguration(cfg) ) throw Usb::Error(dev.GetLastError(), "Probe: GetConfiguration failed"); - if( cfg != BLACKBERRY_CONFIGURATION ) { + if( cfg != BLACKBERRY_CONFIGURATION || MUST_SET_CONFIGURATION ) { if( !dev.SetConfiguration(BLACKBERRY_CONFIGURATION) ) throw Usb::Error(dev.GetLastError(), "Probe: SetConfiguration failed"); -- 2.11.4.GIT