summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Batard <pete@akeo.ie>2012-01-08 00:16:34 +0000
committerPete Batard <pete@akeo.ie>2012-01-08 01:52:40 +0000
commitc7224c9c90c6533a2c568cd6adb3ba3c65b67b39 (patch)
tree1e007cf9dd05e524d5b0eed5804991b0989de2c6
parente182dbad23570634d6cca971aa6b820898377d4e (diff)
downloadlibusb-c7224c9c90c6533a2c568cd6adb3ba3c65b67b39.tar.gz
[misc] align with master
* up to "Core: Fix #122 warning: no previous prototype for ‘usbi_log_v’" a8e2e7cab278fbfcba91909eaf762cf66da9eda5
-rw-r--r--.gitattributes12
-rw-r--r--.gitignore8
-rw-r--r--Makefile.am5
-rw-r--r--configure.ac7
-rw-r--r--libusb/Makefile.am2
-rw-r--r--libusb/core.c37
-rw-r--r--libusb/descriptor.c4
-rw-r--r--libusb/io.c171
-rw-r--r--libusb/libusb-1.0.def30
-rw-r--r--libusb/libusb-1.0.rc9
-rw-r--r--libusb/libusb.h27
-rw-r--r--libusb/libusbi.h23
-rw-r--r--libusb/os/darwin_usb.c224
-rw-r--r--libusb/os/darwin_usb.h2
-rw-r--r--libusb/os/linux_usbfs.c241
-rw-r--r--libusb/os/linux_usbfs.h4
-rw-r--r--libusb/os/poll_posix.h6
-rw-r--r--libusb/os/poll_windows.h2
-rw-r--r--libusb/os/threads_posix.c2
-rw-r--r--libusb/os/threads_posix.h8
-rw-r--r--libusb/os/threads_windows.h6
-rw-r--r--libusb/os/windows_usb.c174
-rw-r--r--libusb/os/windows_usb.h52
-rw-r--r--libusb/sync.c11
-rw-r--r--libusb/version.h5
-rw-r--r--msvc/config.h2
26 files changed, 607 insertions, 467 deletions
diff --git a/.gitattributes b/.gitattributes
index 57af597..1a1929c 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,7 +1,7 @@
-*.sh eol=lf
-*.ac eol=lf
-*.am eol=lf
-*.dsw eol=crlf
-*.dsp eol=crlf
-*.sln eol=crlf
+*.sh eol=lf
+*.ac eol=lf
+*.am eol=lf
+*.dsw eol=crlf
+*.dsp eol=crlf whitespace=space-before-tab
+*.sln eol=crlf
*.vcxproj* eol=crlf
diff --git a/.gitignore b/.gitignore
index 1bb7437..e2b19d1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,6 +9,7 @@ libtool
ltmain.sh
missing
stamp-h1
+m4/
autom4te.cache
install-sh
depcomp
@@ -16,7 +17,8 @@ configure
aclocal.m4
compile
config.guess
-config.h
+config.h*
+!msvc/config.h
config.log
config.status
config.sub
@@ -26,10 +28,8 @@ lsusb
xusb
dpfp
dpfp_threaded
-.exe
+*.exe
*.pc
-fpusb-*.tar.bz2
-fpusb-*.tar.gz
ChangeLog
doc/html
*.plg
diff --git a/Makefile.am b/Makefile.am
index 1b65a92..f59b8c3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,7 @@
AUTOMAKE_OPTIONS = dist-bzip2 no-dist-gzip
ACLOCAL_AMFLAGS = -I m4
-DISTCLEANFILES = ChangeLog libusb-1.0.pc
+DISTCLEANFILES = libusb-1.0.pc
+MAINTAINERCLEANFILES = ChangeLog
EXTRA_DIST = TODO PORTING
SUBDIRS = libusb doc
@@ -22,6 +23,6 @@ dist-up: dist
rm -rf $(reldir)
mkdir -p $(reldir)
cp $(distdir).tar.bz2 $(reldir)
- rsync -rv $(reldir) dsd_,libusb@frs.sourceforge.net:/home/frs/project/l/li/libusb/libusb-1.0/
+ rsync -rv $(reldir) frs.sourceforge.net:/home/frs/project/l/li/libusb/libusb-1.0/
rm -rf $(reldir)
diff --git a/configure.ac b/configure.ac
index 6c00b0f..f983e48 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3,16 +3,19 @@ m4_define([LU_VERSION_H], m4_include([libusb/version.h]))
m4_define([LU_DEFINE_VERSION_ATOM],
[m4_define([$1], m4_bregexp(LU_VERSION_H,
[^#define\s*$1\s*\([0-9]*\).*], [\1]))])
+m4_define([LU_DEFINE_VERSION_RC_ATOM],
+ [m4_define([$1], m4_bregexp(LU_VERSION_H,
+ [^#define\s*$1\s*"\(-rc[0-9]*\)".*], [\1]))])
dnl The m4_bregexp() returns (only) the numbers following the #define named
dnl in the first macro parameter. m4_define() then defines the name for use
dnl in AC_INIT().
-
LU_DEFINE_VERSION_ATOM([LIBUSB_MAJOR])
LU_DEFINE_VERSION_ATOM([LIBUSB_MINOR])
LU_DEFINE_VERSION_ATOM([LIBUSB_MICRO])
+LU_DEFINE_VERSION_RC_ATOM([LIBUSB_RC])
-AC_INIT([libusb], LIBUSB_MAJOR[.]LIBUSB_MINOR[.]LIBUSB_MICRO, [libusb-devel@lists.sourceforge.net], [libusb], [http://www.libusb.org/])
+AC_INIT([libusb], LIBUSB_MAJOR[.]LIBUSB_MINOR[.]LIBUSB_MICRO[]LIBUSB_RC, [libusb-devel@lists.sourceforge.net], [libusb], [http://www.libusb.org/])
# Library versioning
# These numbers should be tweaked on every release. Read carefully:
diff --git a/libusb/Makefile.am b/libusb/Makefile.am
index 60d9312..13f3c75 100644
--- a/libusb/Makefile.am
+++ b/libusb/Makefile.am
@@ -31,6 +31,8 @@ pkg_v_rc_0 = @echo " RC $@";
.rc.lo:
$(pkg_v_rc)$(LIBTOOL) $(AM_V_lt) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --tag=RC --mode=compile $(RC) $(RCFLAGS) -i $< -o $@
+
+libusb-1.0.rc: version.h
endif
if THREADS_POSIX
diff --git a/libusb/core.c b/libusb/core.c
index 3969fd5..5317f47 100644
--- a/libusb/core.c
+++ b/libusb/core.c
@@ -551,10 +551,8 @@ int usbi_sanitize_device(struct libusb_device *dev)
if (num_configurations > USB_MAXCONFIG) {
usbi_err(DEVICE_CTX(dev), "too many configurations");
return LIBUSB_ERROR_IO;
- } else if (num_configurations < 1) {
- usbi_dbg("no configurations?");
- return LIBUSB_ERROR_IO;
- }
+ } else if (0 == num_configurations)
+ usbi_dbg("zero configurations, maybe an unauthorized device");
dev->num_configurations = num_configurations;
return 0;
@@ -597,8 +595,8 @@ struct libusb_device *usbi_get_device_by_session_id(struct libusb_context *ctx,
* \param ctx the context to operate on, or NULL for the default context
* \param list output location for a list of devices. Must be later freed with
* libusb_free_device_list().
- * \returns the number of devices in the outputted list, or LIBUSB_ERROR_NO_MEM
- * on memory allocation failure.
+ * \returns the number of devices in the outputted list, or any
+ * \ref libusb_error according to errors encountered by the backend.
*/
ssize_t API_EXPORTED libusb_get_device_list(libusb_context *ctx,
libusb_device ***list)
@@ -739,12 +737,12 @@ uint8_t API_EXPORTED libusb_get_device_address(libusb_device *dev)
}
/** \ingroup dev
- * Get the negotiated speed of the device.
+ * Get the negotiated connection speed for a device.
* \param dev a device
- * \returns the device speed or LIBUSB_SPEED_UNKNOWN if the OS doesn't know or
- * support returning the negotiated speed.
+ * \returns a \ref libusb_speed code, where LIBUSB_SPEED_UNKNOWN means that
+ * the OS doesn't know or doesn't support returning the negotiated speed.
*/
-enum libusb_speed API_EXPORTED libusb_get_device_speed(libusb_device *dev)
+int API_EXPORTED libusb_get_device_speed(libusb_device *dev)
{
return dev->speed;
}
@@ -1003,6 +1001,7 @@ int API_EXPORTED libusb_open(libusb_device *dev,
r = usbi_backend->open(_handle);
if (r < 0) {
+ usbi_dbg("open %d.%d returns %d", dev->bus_number, dev->device_address, r);
libusb_unref_device(dev);
usbi_mutex_destroy(&_handle->lock);
free(_handle);
@@ -1091,7 +1090,7 @@ static void do_close(struct libusb_context *ctx,
/* safe iteration because transfers may be being deleted */
list_for_each_entry_safe(itransfer, tmp, &ctx->flying_transfers, list, struct usbi_transfer) {
struct libusb_transfer *transfer =
- __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
if (transfer->dev_handle != dev_handle)
continue;
@@ -1730,6 +1729,22 @@ void API_EXPORTED libusb_exit(struct libusb_context *ctx)
free(ctx);
}
+/** \ingroup misc
+ * Check at runtime if the loaded library has a given capability.
+ *
+ * \param capability the \ref libusb_capability to check for
+ * \returns 1 if the running library has the capability, 0 otherwise
+ */
+int API_EXPORTED libusb_has_capability(uint32_t capability)
+{
+ enum libusb_capability cap = capability;
+ switch (cap) {
+ case LIBUSB_CAP_HAS_CAPABILITY:
+ return 1;
+ }
+ return 0;
+}
+
void usbi_log_v(struct libusb_context *ctx, enum usbi_log_level level,
const char *function, const char *format, va_list args)
{
diff --git a/libusb/descriptor.c b/libusb/descriptor.c
index d6ec46c..e358e9e 100644
--- a/libusb/descriptor.c
+++ b/libusb/descriptor.c
@@ -188,7 +188,7 @@ static int parse_interface(libusb_context *ctx,
int len;
int r;
int parsed = 0;
- int tmp;
+ size_t tmp;
struct usb_descriptor_header header;
struct libusb_interface_descriptor *ifp;
unsigned char *begin;
@@ -336,7 +336,7 @@ static int parse_configuration(struct libusb_context *ctx,
int i;
int r;
int size;
- int tmp;
+ size_t tmp;
struct usb_descriptor_header header;
struct libusb_interface *usb_interface;
diff --git a/libusb/io.c b/libusb/io.c
index 43e683b..7508e31 100644
--- a/libusb/io.c
+++ b/libusb/io.c
@@ -96,8 +96,8 @@
* in the following style:
\code
unsigned char data[4];
-int actual_length,
-int r = libusb_bulk_transfer(handle, EP_IN, data, sizeof(data), &actual_length, 0);
+int actual_length;
+int r = libusb_bulk_transfer(handle, LIBUSB_ENDPOINT_IN, data, sizeof(data), &actual_length, 0);
if (r == 0 && actual_length == sizeof(data)) {
// results of the transaction can now be found in the data buffer
// parse them here and report button press
@@ -625,9 +625,9 @@ while (user has not requested application exit) {
poll(on libusb file descriptors plus any other event sources of interest,
using a timeout no larger than the value libusb just suggested)
if (poll() indicated activity on libusb file descriptors)
- libusb_handle_events_timeout(ctx, 0);
+ libusb_handle_events_timeout(ctx, &zero_tv);
if (time has elapsed to or beyond the libusb timeout)
- libusb_handle_events_timeout(ctx, 0);
+ libusb_handle_events_timeout(ctx, &zero_tv);
// handle events from other sources here
}
@@ -660,7 +660,7 @@ while (user has not requested application exit) {
poll(on libusb file descriptors plus any other event sources of interest,
using any timeout that you like)
if (poll() indicated activity on libusb file descriptors)
- libusb_handle_events_timeout(ctx, 0);
+ libusb_handle_events_timeout(ctx, &zero_tv);
// handle events from other sources here
}
@@ -745,7 +745,7 @@ void myfunc() {
while (!completed) {
poll(libusb file descriptors, 120*1000);
if (poll indicates activity)
- libusb_handle_events_timeout(ctx, 0);
+ libusb_handle_events_timeout(ctx, &zero_tv);
}
printf("completed!");
// other code here
@@ -774,9 +774,52 @@ void myfunc() {
*
* Before we go any further, it is worth mentioning that all libusb-wrapped
* event handling procedures fully adhere to the scheme documented below.
- * This includes libusb_handle_events() and all the synchronous I/O functions -
- * libusb hides this headache from you. You do not need to worry about any
- * of these issues if you stick to that level.
+ * This includes libusb_handle_events() and its variants, and all the
+ * synchronous I/O functions - libusb hides this headache from you.
+ *
+ * \section Using libusb_handle_events() from multiple threads
+ *
+ * Even when only using libusb_handle_events() and synchronous I/O functions,
+ * you can still have a race condition. You might be tempted to solve the
+ * above with libusb_handle_events() like so:
+ *
+\code
+ libusb_submit_transfer(transfer);
+
+ while (!completed) {
+ libusb_handle_events(ctx);
+ }
+ printf("completed!");
+\endcode
+ *
+ * This however has a race between the checking of completed and
+ * libusb_handle_events() acquiring the events lock, so another thread
+ * could have completed the transfer, resulting in this thread hanging
+ * until either a timeout or another event occurs. See also commit
+ * 6696512aade99bb15d6792af90ae329af270eba6 which fixes this in the
+ * synchronous API implementation of libusb.
+ *
+ * Fixing this race requires checking the variable completed only after
+ * taking the event lock, which defeats the concept of just calling
+ * libusb_handle_events() without worrying about locking. This is why
+ * libusb-1.0.9 introduces the new libusb_handle_events_timeout_completed()
+ * and libusb_handle_events_completed() functions, which handles doing the
+ * completion check for you after they have acquired the lock:
+ *
+\code
+ libusb_submit_transfer(transfer);
+
+ while (!completed) {
+ libusb_handle_events_completed(ctx, &completed);
+ }
+ printf("completed!");
+\endcode
+ *
+ * This nicely fixes the race in our example. Note that if all you want to
+ * do is submit a single transfer and wait for its completion, then using
+ * one of the synchronous I/O functions is much easier.
+ *
+ * \section eventlock The events lock
*
* The problem is when we consider the fact that libusb exposes file
* descriptors to allow for you to integrate asynchronous USB I/O into
@@ -784,8 +827,6 @@ void myfunc() {
* libusb's back. If you do take libusb's file descriptors and pass them to
* poll()/select() yourself, you need to be aware of the associated issues.
*
- * \section eventlock The events lock
- *
* The first concept to be introduced is the events lock. The events lock
* is used to serialize threads that want to handle events, such that only
* one thread is handling events at any one time.
@@ -803,7 +844,7 @@ void myfunc() {
while (!completed) {
poll(libusb file descriptors, 120*1000);
if (poll indicates activity)
- libusb_handle_events_timeout(ctx, 0);
+ libusb_handle_events_timeout(ctx, &zero_tv);
}
libusb_unlock_events(ctx);
\endcode
@@ -1089,7 +1130,7 @@ static int calculate_timeout(struct usbi_transfer *transfer)
int r;
struct timespec current_time;
unsigned int timeout =
- __USBI_TRANSFER_TO_LIBUSB_TRANSFER(transfer)->timeout;
+ USBI_TRANSFER_TO_LIBUSB_TRANSFER(transfer)->timeout;
if (!timeout)
return 0;
@@ -1202,7 +1243,7 @@ struct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer(
memset(itransfer, 0, alloc_size);
itransfer->num_iso_packets = iso_packets;
usbi_mutex_init(&itransfer->lock, NULL);
- return __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ return USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
}
/** \ingroup asyncio
@@ -1231,7 +1272,7 @@ void API_EXPORTED libusb_free_transfer(struct libusb_transfer *transfer)
if (transfer->flags & LIBUSB_TRANSFER_FREE_BUFFER && transfer->buffer)
free(transfer->buffer);
- itransfer = __LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer);
+ itransfer = LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer);
usbi_mutex_destroy(&itransfer->lock);
free(itransfer);
}
@@ -1250,7 +1291,7 @@ int API_EXPORTED libusb_submit_transfer(struct libusb_transfer *transfer)
{
struct libusb_context *ctx = TRANSFER_CTX(transfer);
struct usbi_transfer *itransfer =
- __LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer);
+ LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer);
int r;
int first;
@@ -1307,7 +1348,7 @@ out:
int API_EXPORTED libusb_cancel_transfer(struct libusb_transfer *transfer)
{
struct usbi_transfer *itransfer =
- __LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer);
+ LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer);
int r;
usbi_dbg("");
@@ -1364,7 +1405,7 @@ static int arm_timerfd_for_next_timeout(struct libusb_context *ctx)
int r;
const struct itimerspec it = { {0, 0},
{ cur_tv->tv_sec, cur_tv->tv_usec * 1000 } };
- usbi_dbg("next timeout originally %dms", __USBI_TRANSFER_TO_LIBUSB_TRANSFER(transfer)->timeout);
+ usbi_dbg("next timeout originally %dms", USBI_TRANSFER_TO_LIBUSB_TRANSFER(transfer)->timeout);
r = timerfd_settime(ctx->timerfd, TFD_TIMER_ABSTIME, &it, NULL);
if (r < 0)
return LIBUSB_ERROR_OTHER;
@@ -1377,10 +1418,12 @@ static int arm_timerfd_for_next_timeout(struct libusb_context *ctx)
#else
static int disarm_timerfd(struct libusb_context *ctx)
{
+ (void)ctx;
return 0;
}
static int arm_timerfd_for_next_timeout(struct libusb_context *ctx)
{
+ (void)ctx;
return 0;
}
#endif
@@ -1397,7 +1440,7 @@ int usbi_handle_transfer_completion(struct usbi_transfer *itransfer,
enum libusb_transfer_status status)
{
struct libusb_transfer *transfer =
- __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct libusb_context *ctx = TRANSFER_CTX(transfer);
uint8_t flags;
int r;
@@ -1713,7 +1756,7 @@ int API_EXPORTED libusb_wait_for_event(libusb_context *ctx, struct timeval *tv)
static void handle_timeout(struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer =
- __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
int r;
itransfer->flags |= USBI_TRANSFER_TIMED_OUT;
@@ -1945,13 +1988,20 @@ static int get_next_timeout(libusb_context *ctx, struct timeval *tv,
* timeout. If an event arrives or a signal is raised, this function will
* return early.
*
+ * If the parameter completed is not NULL then <em>after obtaining the event
+ * handling lock</em> this function will return immediately if the integer
+ * pointed to is not 0. This allows for race free waiting for the completion
+ * of a specific transfer.
+ *
* \param ctx the context to operate on, or NULL for the default context
- * \param tv the maximum time to block waiting for events, or zero for
- * non-blocking mode
+ * \param tv the maximum time to block waiting for events, or an all zero
+ * timeval struct for non-blocking mode
+ * \param completed pointer to completion integer to check, or NULL
* \returns 0 on success, or a LIBUSB_ERROR code on failure
+ * \see \ref mtasync
*/
-int API_EXPORTED libusb_handle_events_timeout(libusb_context *ctx,
- struct timeval *tv)
+int API_EXPORTED libusb_handle_events_timeout_completed(libusb_context *ctx,
+ struct timeval *tv, int *completed)
{
int r;
struct timeval poll_timeout;
@@ -1965,16 +2015,22 @@ int API_EXPORTED libusb_handle_events_timeout(libusb_context *ctx,
retry:
if (libusb_try_lock_events(ctx) == 0) {
- /* we obtained the event lock: do our own event handling */
- r = handle_events(ctx, &poll_timeout);
+ if (completed == NULL || !*completed) {
+ /* we obtained the event lock: do our own event handling */
+ usbi_dbg("doing our own event handling");
+ r = handle_events(ctx, &poll_timeout);
+ }
libusb_unlock_events(ctx);
return r;
}
- /* another thread is doing event handling. wait for pthread events that
+ /* another thread is doing event handling. wait for thread events that
* notify event completion. */
libusb_lock_event_waiters(ctx);
+ if (completed && *completed)
+ goto already_done;
+
if (!libusb_event_handler_active(ctx)) {
/* we hit a race: whoever was event handling earlier finished in the
* time it took us to reach this point. try the cycle again. */
@@ -1985,6 +2041,8 @@ retry:
usbi_dbg("another thread is doing event handling");
r = libusb_wait_for_event(ctx, &poll_timeout);
+
+already_done:
libusb_unlock_event_waiters(ctx);
if (r < 0)
@@ -1996,10 +2054,37 @@ retry:
}
/** \ingroup poll
+ * Handle any pending events
+ *
+ * Like libusb_handle_events_timeout_completed(), but without the completed
+ * parameter, calling this function is equivalent to calling
+ * libusb_handle_events_timeout_completed() with a NULL completed parameter.
+ *
+ * This function is kept primarily for backwards compatibility.
+ * All new code should call libusb_handle_events_completed() or
+ * libusb_handle_events_timeout_completed() to avoid race conditions.
+ *
+ * \param ctx the context to operate on, or NULL for the default context
+ * \param tv the maximum time to block waiting for events, or an all zero
+ * timeval struct for non-blocking mode
+ * \returns 0 on success, or a LIBUSB_ERROR code on failure
+ */
+int API_EXPORTED libusb_handle_events_timeout(libusb_context *ctx,
+ struct timeval *tv)
+{
+ return libusb_handle_events_timeout_completed(ctx, tv, NULL);
+}
+
+/** \ingroup poll
* Handle any pending events in blocking mode. There is currently a timeout
* hardcoded at 60 seconds but we plan to make it unlimited in future. For
* finer control over whether this function is blocking or non-blocking, or
- * for control over the timeout, use libusb_handle_events_timeout() instead.
+ * for control over the timeout, use libusb_handle_events_timeout_completed()
+ * instead.
+ *
+ * This function is kept primarily for backwards compatibility.
+ * All new code should call libusb_handle_events_completed() or
+ * libusb_handle_events_timeout_completed() to avoid race conditions.
*
* \param ctx the context to operate on, or NULL for the default context
* \returns 0 on success, or a LIBUSB_ERROR code on failure
@@ -2009,7 +2094,30 @@ int API_EXPORTED libusb_handle_events(libusb_context *ctx)
struct timeval tv;
tv.tv_sec = 60;
tv.tv_usec = 0;
- return libusb_handle_events_timeout(ctx, &tv);
+ return libusb_handle_events_timeout_completed(ctx, &tv, NULL);
+}
+
+/** \ingroup poll
+ * Handle any pending events in blocking mode.
+ *
+ * Like libusb_handle_events(), with the addition of a completed parameter
+ * to allow for race free waiting for the completion of a specific transfer.
+ *
+ * See libusb_handle_events_timeout_completed() for details on the completed
+ * parameter.
+ *
+ * \param ctx the context to operate on, or NULL for the default context
+ * \param completed pointer to completion integer to check, or NULL
+ * \returns 0 on success, or a LIBUSB_ERROR code on failure
+ * \see \ref mtasync
+ */
+int API_EXPORTED libusb_handle_events_completed(libusb_context *ctx,
+ int *completed)
+{
+ struct timeval tv;
+ tv.tv_sec = 60;
+ tv.tv_usec = 0;
+ return libusb_handle_events_timeout_completed(ctx, &tv, completed);
}
/** \ingroup poll
@@ -2079,6 +2187,7 @@ int API_EXPORTED libusb_pollfds_handle_timeouts(libusb_context *ctx)
USBI_GET_CONTEXT(ctx);
return usbi_using_timerfd(ctx);
#else
+ (void)ctx;
return 0;
#endif
}
@@ -2292,6 +2401,8 @@ out:
usbi_mutex_unlock(&ctx->pollfds_lock);
return (const struct libusb_pollfd **) ret;
#else
+ usbi_err(ctx, "external polling of libusb's internal descriptors "\
+ "is not yet supported on Windows platforms");
return NULL;
#endif
}
@@ -2324,7 +2435,7 @@ void usbi_handle_disconnect(struct libusb_device_handle *handle)
usbi_mutex_lock(&HANDLE_CTX(handle)->flying_transfers_lock);
to_cancel = NULL;
list_for_each_entry(cur, &HANDLE_CTX(handle)->flying_transfers, list, struct usbi_transfer)
- if (__USBI_TRANSFER_TO_LIBUSB_TRANSFER(cur)->dev_handle == handle) {
+ if (USBI_TRANSFER_TO_LIBUSB_TRANSFER(cur)->dev_handle == handle) {
to_cancel = cur;
break;
}
diff --git a/libusb/libusb-1.0.def b/libusb/libusb-1.0.def
index b2f3861..a3b2ac6 100644
--- a/libusb/libusb-1.0.def
+++ b/libusb/libusb-1.0.def
@@ -350,6 +350,16 @@ EXPORTS
libusb_handle_events@32 = libusb_handle_events
libusb_handle_events@4 = libusb_handle_events
libusb_handle_events@8 = libusb_handle_events
+ libusb_handle_events_completed
+ libusb_handle_events_completed@0 = libusb_handle_events_completed
+ libusb_handle_events_completed@12 = libusb_handle_events_completed
+ libusb_handle_events_completed@16 = libusb_handle_events_completed
+ libusb_handle_events_completed@20 = libusb_handle_events_completed
+ libusb_handle_events_completed@24 = libusb_handle_events_completed
+ libusb_handle_events_completed@28 = libusb_handle_events_completed
+ libusb_handle_events_completed@32 = libusb_handle_events_completed
+ libusb_handle_events_completed@4 = libusb_handle_events_completed
+ libusb_handle_events_completed@8 = libusb_handle_events_completed
libusb_handle_events_locked
libusb_handle_events_locked@0 = libusb_handle_events_locked
libusb_handle_events_locked@12 = libusb_handle_events_locked
@@ -370,6 +380,26 @@ EXPORTS
libusb_handle_events_timeout@32 = libusb_handle_events_timeout
libusb_handle_events_timeout@4 = libusb_handle_events_timeout
libusb_handle_events_timeout@8 = libusb_handle_events_timeout
+ libusb_handle_events_timeout_completed
+ libusb_handle_events_timeout_completed@0 = libusb_handle_events_timeout_completed
+ libusb_handle_events_timeout_completed@12 = libusb_handle_events_timeout_completed
+ libusb_handle_events_timeout_completed@16 = libusb_handle_events_timeout_completed
+ libusb_handle_events_timeout_completed@20 = libusb_handle_events_timeout_completed
+ libusb_handle_events_timeout_completed@24 = libusb_handle_events_timeout_completed
+ libusb_handle_events_timeout_completed@28 = libusb_handle_events_timeout_completed
+ libusb_handle_events_timeout_completed@32 = libusb_handle_events_timeout_completed
+ libusb_handle_events_timeout_completed@4 = libusb_handle_events_timeout_completed
+ libusb_handle_events_timeout_completed@8 = libusb_handle_events_timeout_completed
+ libusb_has_capability
+ libusb_has_capability@0 = libusb_has_capability
+ libusb_has_capability@12 = libusb_has_capability
+ libusb_has_capability@16 = libusb_has_capability
+ libusb_has_capability@20 = libusb_has_capability
+ libusb_has_capability@24 = libusb_has_capability
+ libusb_has_capability@28 = libusb_has_capability
+ libusb_has_capability@32 = libusb_has_capability
+ libusb_has_capability@4 = libusb_has_capability
+ libusb_has_capability@8 = libusb_has_capability
libusb_init
libusb_init@0 = libusb_init
libusb_init@12 = libusb_init
diff --git a/libusb/libusb-1.0.rc b/libusb/libusb-1.0.rc
index 6072159..e2e8617 100644
--- a/libusb/libusb-1.0.rc
+++ b/libusb/libusb-1.0.rc
@@ -11,9 +11,15 @@
#ifndef LIBUSB_VERSIONSTRING
#define LU_STR(s) #s
#define LU_XSTR(s) LU_STR(s)
+#if LIBUSB_NANO > 0
#define LIBUSB_VERSIONSTRING \
LU_XSTR(LIBUSB_MAJOR) "." LU_XSTR(LIBUSB_MINOR) "." \
- LU_XSTR(LIBUSB_MICRO) "." LU_XSTR(LIBUSB_NANO)
+ LU_XSTR(LIBUSB_MICRO) "." LU_XSTR(LIBUSB_NANO) LIBUSB_RC "\0"
+#else
+#define LIBUSB_VERSIONSTRING \
+ LU_XSTR(LIBUSB_MAJOR) "." LU_XSTR(LIBUSB_MINOR) "." \
+ LU_XSTR(LIBUSB_MICRO) LIBUSB_RC "\0"
+#endif
#endif
VS_VERSION_INFO VERSIONINFO
@@ -33,7 +39,6 @@ BEGIN
BEGIN
BLOCK "040904b0"
BEGIN
- VALUE "Comments", "http://libusb.org/\0"
VALUE "CompanyName", "libusb.org\0"
VALUE "FileDescription", "C library for writing portable USB drivers in userspace\0"
VALUE "FileVersion", LIBUSB_VERSIONSTRING
diff --git a/libusb/libusb.h b/libusb/libusb.h
index e29c9b8..37f0d81 100644
--- a/libusb/libusb.h
+++ b/libusb/libusb.h
@@ -18,8 +18,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef __LIBUSB_H__
-#define __LIBUSB_H__
+#ifndef LIBUSB_H
+#define LIBUSB_H
#ifdef _MSC_VER
/* on MS environments, the inline keyword is available in C++ only */
@@ -40,6 +40,7 @@
#if defined(_MSC_VER) && (_MSC_VER < 1600) && (!defined(_STDINT)) && (!defined(_STDINT_H))
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
+typedef unsigned __int32 uint32_t;
#else
#include <stdint.h>
#endif
@@ -717,8 +718,8 @@ enum libusb_speed {
/** \ingroup misc
* Error codes. Most libusb functions return 0 on success or one of these
* codes on failure.
- * You can use libusb_strerror() to retrieve a short string description of
- * a libusb_error enumeration value.
+ * You can use libusb_strerror() to retrieve a short string description
+ * of an error code.
*/
enum libusb_error {
/** Success (no error) */
@@ -900,11 +901,22 @@ struct libusb_transfer {
;
};
+/** \ingroup misc
+ * Capabilities supported by this instance of libusb. Test if the loaded
+ * library supports a given capability by calling
+ * \ref libusb_has_capability().
+ */
+enum libusb_capability {
+ /** The libusb_has_capability() API is available. */
+ LIBUSB_CAP_HAS_CAPABILITY = 0,
+};
+
int LIBUSB_CALL libusb_init(libusb_context **ctx);
void LIBUSB_CALL libusb_exit(libusb_context *ctx);
void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level);
const char * LIBUSB_CALL libusb_strerror(enum libusb_error errcode);
const struct libusb_version * LIBUSB_CALL libusb_getversion(void);
+int LIBUSB_CALL libusb_has_capability(uint32_t capability);
ssize_t LIBUSB_CALL libusb_get_device_list(libusb_context *ctx,
libusb_device ***list);
@@ -930,7 +942,7 @@ uint8_t LIBUSB_CALL libusb_get_port_number(libusb_device *dev);
libusb_device * LIBUSB_CALL libusb_get_parent(libusb_device *dev);
int LIBUSB_CALL libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t* path, uint8_t path_length);
uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev);
-enum libusb_speed LIBUSB_CALL libusb_get_device_speed(libusb_device *dev);
+int LIBUSB_CALL libusb_get_device_speed(libusb_device *dev);
int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev,
unsigned char endpoint);
int LIBUSB_CALL libusb_get_max_iso_packet_size(libusb_device *dev,
@@ -1335,7 +1347,10 @@ int LIBUSB_CALL libusb_wait_for_event(libusb_context *ctx, struct timeval *tv);
int LIBUSB_CALL libusb_handle_events_timeout(libusb_context *ctx,
struct timeval *tv);
+int LIBUSB_CALL libusb_handle_events_timeout_completed(libusb_context *ctx,
+ struct timeval *tv, int *completed);
int LIBUSB_CALL libusb_handle_events(libusb_context *ctx);
+int LIBUSB_CALL libusb_handle_events_completed(libusb_context *ctx, int *completed);
int LIBUSB_CALL libusb_handle_events_locked(libusb_context *ctx,
struct timeval *tv);
int LIBUSB_CALL libusb_pollfds_handle_timeouts(libusb_context *ctx);
@@ -1390,4 +1405,4 @@ void LIBUSB_CALL libusb_set_pollfd_notifiers(libusb_context *ctx,
}
#endif
-#endif \ No newline at end of file
+#endif
diff --git a/libusb/libusbi.h b/libusb/libusbi.h
index 9651387..2395d50 100644
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -18,14 +18,15 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef __LIBUSBI_H__
-#define __LIBUSBI_H__
+#ifndef LIBUSBI_H
+#define LIBUSBI_H
#include <config.h>
#include <stddef.h>
#include <stdint.h>
#include <time.h>
+#include <stdarg.h>
#ifdef HAVE_POLL_H
#include <poll.h>
#endif
@@ -110,8 +111,8 @@ static inline void list_del(struct list_head *entry)
}
#define container_of(ptr, type, member) ({ \
- const typeof( ((type *)0)->member ) *__mptr = (ptr); \
- (type *)( (char *)__mptr - offsetof(type,member) );})
+ const typeof( ((type *)0)->member ) *mptr = (ptr); \
+ (type *)( (char *)mptr - offsetof(type,member) );})
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
@@ -128,6 +129,9 @@ enum usbi_log_level {
void usbi_log(struct libusb_context *ctx, enum usbi_log_level level,
const char *function, const char *format, ...);
+void usbi_log_v(struct libusb_context *ctx, enum usbi_log_level level,
+ const char *function, const char *format, va_list args);
+
#if !defined(_MSC_VER) || _MSC_VER > 1200
#ifdef ENABLE_LOGGING
@@ -148,9 +152,6 @@ void usbi_log(struct libusb_context *ctx, enum usbi_log_level level,
#else /* !defined(_MSC_VER) || _MSC_VER > 1200 */
-void usbi_log_v(struct libusb_context *ctx, enum usbi_log_level level,
- const char *function, const char *format, va_list args);
-
#ifdef ENABLE_LOGGING
#define LOG_BODY(ctxt, level) \
{ \
@@ -187,7 +188,7 @@ static inline void usbi_dbg(const char *format, ...)
#define HANDLE_CTX(handle) (DEVICE_CTX((handle)->dev))
#define TRANSFER_CTX(transfer) (HANDLE_CTX((transfer)->dev_handle))
#define ITRANSFER_CTX(transfer) \
- (TRANSFER_CTX(__USBI_TRANSFER_TO_LIBUSB_TRANSFER(transfer)))
+ (TRANSFER_CTX(USBI_TRANSFER_TO_LIBUSB_TRANSFER(transfer)))
/* Internal abstractions for thread synchronization and poll */
#if defined(THREADS_POSIX)
@@ -342,13 +343,13 @@ enum usbi_transfer_flags {
USBI_TRANSFER_CANCELLING = 1 << 2,
/* Operation on the transfer failed because the device disappeared */
- USBI_TRANSFER_DEVICE_DISAPPEARED = 1 << 3,
+ USBI_TRANSFER_DEVICE_DISAPPEARED = 1 << 3,
};
-#define __USBI_TRANSFER_TO_LIBUSB_TRANSFER(transfer) \
+#define USBI_TRANSFER_TO_LIBUSB_TRANSFER(transfer) \
((struct libusb_transfer *)(((unsigned char *)(transfer)) \
+ sizeof(struct usbi_transfer)))
-#define __LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer) \
+#define LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer) \
((struct usbi_transfer *)(((unsigned char *)(transfer)) \
- sizeof(struct usbi_transfer)))
diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c
index d9f21b9..b5952f4 100644
--- a/libusb/os/darwin_usb.c
+++ b/libusb/os/darwin_usb.c
@@ -47,7 +47,13 @@
#include "darwin_usb.h"
-static mach_port_t libusb_darwin_mp = 0; /* master port */
+/* async event thread */
+static pthread_mutex_t libusb_darwin_at_mutex;
+static pthread_cond_t libusb_darwin_at_cond;
+
+static clock_serv_t clock_realtime;
+static clock_serv_t clock_monotonic;
+
static CFRunLoopRef libusb_darwin_acfl = NULL; /* async cf loop */
static int initCount = 0;
@@ -123,7 +129,7 @@ static int ep_to_pipeRef(struct libusb_device_handle *dev_handle, uint8_t ep, ui
struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
/* current interface */
- struct __darwin_interface *cInterface;
+ struct darwin_interface *cInterface;
int8_t i, iface;
@@ -175,29 +181,14 @@ static int usb_setup_device_iterator (io_iterator_t *deviceIterator, long locati
/* else we can still proceed as long as the caller accounts for the possibility of other devices in the iterator */
}
- return IOServiceGetMatchingServices(libusb_darwin_mp, matchingDict, deviceIterator);
-}
-
-int get_ioregistry_value_number (io_service_t service, CFStringRef property, CFNumberType type, void *p) {
- CFTypeRef cfNumber = IORegistryEntryCreateCFProperty (service, property, kCFAllocatorDefault, 0);
- int ret = 0;
-
- if (cfNumber) {
- if (CFGetTypeID(cfNumber) == CFNumberGetTypeID()) {
- ret = CFNumberGetValue(cfNumber, type, p);
- }
-
- CFRelease (cfNumber);
- }
-
- return ret;
+ return IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDict, deviceIterator);
}
-static usb_device_t **usb_get_next_device (io_iterator_t deviceIterator, UInt32 *locationp, UInt8 *portp, UInt32 *parent_locationp) {
+static usb_device_t **usb_get_next_device (io_iterator_t deviceIterator, UInt32 *locationp) {
io_cf_plugin_ref_t *plugInInterface = NULL;
usb_device_t **device;
- io_service_t usbDevice, parent;
- kern_return_t result;
+ io_service_t usbDevice;
+ long result;
SInt32 score;
if (!IOIteratorIsValid (deviceIterator))
@@ -209,21 +200,8 @@ static usb_device_t **usb_get_next_device (io_iterator_t deviceIterator, UInt32
kIOCFPlugInInterfaceID, &plugInInterface,
&score);
- if (portp) {
- *portp = 0;
- (void) get_ioregistry_value_number (usbDevice, CFSTR("PortNum"), kCFNumberSInt8Type, portp);
- }
-
- if (parent_locationp) {
- *parent_locationp = 0;
-
- result = IORegistryEntryGetParentEntry (usbDevice, kIOUSBPlane, &parent);
-
- if (kIOReturnSuccess == result) {
- (void) get_ioregistry_value_number (parent, CFSTR("locationID"), kCFNumberLongType, parent_locationp);
- }
- }
-
+ /* we are done with the usb_device_t */
+ (void)IOObjectRelease(usbDevice);
if (kIOReturnSuccess == result && plugInInterface)
break;
@@ -233,7 +211,6 @@ static usb_device_t **usb_get_next_device (io_iterator_t deviceIterator, UInt32
if (!usbDevice)
return NULL;
- (void)IOObjectRelease(usbDevice);
(void)(*plugInInterface)->QueryInterface(plugInInterface, CFUUIDGetUUIDBytes(DeviceInterfaceID),
(LPVOID)&device);
@@ -257,7 +234,7 @@ static kern_return_t darwin_get_device (uint32_t dev_location, usb_device_t ***d
return kresult;
/* This port of libusb uses locations to keep track of devices. */
- while ((*darwin_device = usb_get_next_device (deviceIterator, &location, NULL, NULL)) != NULL) {
+ while ((*darwin_device = usb_get_next_device (deviceIterator, &location)) != NULL) {
if (location == dev_location)
break;
@@ -282,16 +259,28 @@ static void darwin_devices_detached (void *ptr, io_iterator_t rem_devices) {
io_service_t device;
long location;
+ bool locationValid;
+ CFTypeRef locationCF;
UInt32 message;
usbi_info (ctx, "a device has been detached");
while ((device = IOIteratorNext (rem_devices)) != 0) {
/* get the location from the i/o registry */
+ locationCF = IORegistryEntryCreateCFProperty (device, CFSTR(kUSBDevicePropertyLocationID), kCFAllocatorDefault, 0);
+
+ IOObjectRelease (device);
- if (!get_ioregistry_value_number (device, CFSTR(kUSBDevicePropertyLocationID), kCFNumberLongType, &location)) {
+ if (!locationCF)
+ continue;
+
+ locationValid = CFGetTypeID(locationCF) == CFNumberGetTypeID() &&
+ CFNumberGetValue(locationCF, kCFNumberLongType, &location);
+
+ CFRelease (locationCF);
+
+ if (!locationValid)
continue;
- }
usbi_mutex_lock(&ctx->open_devs_lock);
list_for_each_entry(handle, &ctx->open_devs, list, struct libusb_device_handle) {
@@ -322,6 +311,12 @@ static void *event_thread_main (void *arg0) {
struct libusb_context *ctx = (struct libusb_context *)arg0;
CFRunLoopRef runloop;
+ /* Set this thread's name, so it can be seen in the debugger
+ and crash reports. */
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
+ pthread_setname_np ("org.libusb.device-detach");
+#endif
+
/* Tell the Objective-C garbage collector about this thread.
This is required because, unlike NSThreads, pthreads are
not automatically registered. Although we don't use
@@ -341,7 +336,7 @@ static void *event_thread_main (void *arg0) {
CFRetain (runloop);
/* add the notification port to the run loop */
- libusb_notification_port = IONotificationPortCreate (libusb_darwin_mp);
+ libusb_notification_port = IONotificationPortCreate (kIOMasterPortDefault);
libusb_notification_cfsource = IONotificationPortGetRunLoopSource (libusb_notification_port);
CFRunLoopAddSource(CFRunLoopGetCurrent (), libusb_notification_cfsource, kCFRunLoopDefaultMode);
@@ -360,10 +355,15 @@ static void *event_thread_main (void *arg0) {
/* arm notifiers */
darwin_clear_iterator (libusb_rem_device_iterator);
+ usbi_info (ctx, "thread ready to receive events");
+
/* let the main thread know about the async runloop */
libusb_darwin_acfl = CFRunLoopGetCurrent ();
- usbi_info (ctx, "thread ready to receive events");
+ /* signal the main thread */
+ pthread_mutex_lock (&libusb_darwin_at_mutex);
+ pthread_cond_signal (&libusb_darwin_at_cond);
+ pthread_mutex_unlock (&libusb_darwin_at_mutex);
/* run the runloop */
CFRunLoopRun();
@@ -371,8 +371,8 @@ static void *event_thread_main (void *arg0) {
usbi_info (ctx, "thread exiting");
/* delete notification port */
- CFRunLoopSourceInvalidate (libusb_notification_cfsource);
IONotificationPortDestroy (libusb_notification_port);
+ IOObjectRelease (libusb_rem_device_iterator);
CFRelease (runloop);
@@ -382,21 +382,25 @@ static void *event_thread_main (void *arg0) {
}
static int darwin_init(struct libusb_context *ctx) {
- IOReturn kresult;
+ host_name_port_t host_self;
if (!(initCount++)) {
- /* Create the master port for talking to IOKit */
- if (!libusb_darwin_mp) {
- kresult = IOMasterPort (MACH_PORT_NULL, &libusb_darwin_mp);
+ /* create the clocks that will be used */
- if (kresult != kIOReturnSuccess || !libusb_darwin_mp)
- return darwin_to_libusb (kresult);
- }
+ host_self = mach_host_self();
+ host_get_clock_service(host_self, CALENDAR_CLOCK, &clock_realtime);
+ host_get_clock_service(host_self, SYSTEM_CLOCK, &clock_monotonic);
+ mach_port_deallocate(mach_task_self(), host_self);
+
+ pthread_mutex_init (&libusb_darwin_at_mutex, NULL);
+ pthread_cond_init (&libusb_darwin_at_cond, NULL);
pthread_create (&libusb_darwin_at, NULL, event_thread_main, (void *)ctx);
+ pthread_mutex_lock (&libusb_darwin_at_mutex);
while (!libusb_darwin_acfl)
- usleep (10);
+ pthread_cond_wait (&libusb_darwin_at_cond, &libusb_darwin_at_mutex);
+ pthread_mutex_unlock (&libusb_darwin_at_mutex);
}
return 0;
@@ -404,15 +408,12 @@ static int darwin_init(struct libusb_context *ctx) {
static void darwin_exit (void) {
if (!(--initCount)) {
+ mach_port_deallocate(mach_task_self(), clock_realtime);
+ mach_port_deallocate(mach_task_self(), clock_monotonic);
/* stop the async runloop */
CFRunLoopStop (libusb_darwin_acfl);
pthread_join (libusb_darwin_at, NULL);
-
- if (libusb_darwin_mp)
- mach_port_deallocate(mach_task_self(), libusb_darwin_mp);
-
- libusb_darwin_mp = 0;
}
}
@@ -692,11 +693,9 @@ static int darwin_cache_device_descriptor (struct libusb_context *ctx, struct li
return 0;
}
-static int process_new_device (struct libusb_context *ctx, usb_device_t **device, UInt32 locationID,
- UInt32 parent_location, UInt8 port, struct discovered_devs **_discdevs) {
+static int process_new_device (struct libusb_context *ctx, usb_device_t **device, UInt32 locationID, struct discovered_devs **_discdevs) {
struct darwin_device_priv *priv;
- static struct libusb_device *last_dev = NULL;
- struct libusb_device *dev, *parent = NULL;
+ struct libusb_device *dev;
struct discovered_devs *discdevs;
UInt16 address;
UInt8 devSpeed;
@@ -729,19 +728,6 @@ static int process_new_device (struct libusb_context *ctx, usb_device_t **device
if (ret < 0)
break;
- /* the device iterator provides devices in increasing order of location. given this property
- * we can use the last device to find the parent. */
- for (parent = last_dev ; parent ; parent = parent->parent_dev) {
- struct darwin_device_priv *parent_priv = (struct darwin_device_priv *) parent->os_priv;
-
- if (parent_priv->location == parent_location) {
- break;
- }
- }
-
- dev->parent_dev = parent;
-
- dev->port_number = port;
dev->bus_number = locationID >> 24;
dev->device_address = address;
@@ -772,10 +758,8 @@ static int process_new_device (struct libusb_context *ctx, usb_device_t **device
}
*_discdevs = discdevs;
- last_dev = dev;
- usbi_info (ctx, "found device with address %d port = %d parent = %p at %p", dev->device_address,
- dev->port_number, priv->sys_path, (void *) parent);
+ usbi_info (ctx, "found device with address %d at %s", dev->device_address, priv->sys_path);
} while (0);
if (need_unref)
@@ -788,19 +772,14 @@ static int darwin_get_device_list(struct libusb_context *ctx, struct discovered_
io_iterator_t deviceIterator;
usb_device_t **device;
kern_return_t kresult;
- UInt32 location, parent_location;
- UInt8 port;
- int ret = 0;
-
- if (!libusb_darwin_mp)
- return LIBUSB_ERROR_INVALID_PARAM;
+ UInt32 location;
kresult = usb_setup_device_iterator (&deviceIterator, 0);
if (kresult != kIOReturnSuccess)
return darwin_to_libusb (kresult);
- while ((device = usb_get_next_device (deviceIterator, &location, &port, &parent_location)) != NULL) {
- (void) process_new_device (ctx, device, location, parent_location, port, _discdevs);
+ while ((device = usb_get_next_device (deviceIterator, &location)) != NULL) {
+ (void) process_new_device (ctx, device, location, _discdevs);
(*(device))->Release(device);
}
@@ -1001,7 +980,7 @@ static int get_endpoints (struct libusb_device_handle *dev_handle, int iface) {
struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
/* current interface */
- struct __darwin_interface *cInterface = &priv->interfaces[iface];
+ struct darwin_interface *cInterface = &priv->interfaces[iface];
kern_return_t kresult;
@@ -1049,7 +1028,7 @@ static int darwin_claim_interface(struct libusb_device_handle *dev_handle, int i
SInt32 score;
/* current interface */
- struct __darwin_interface *cInterface = &priv->interfaces[iface];
+ struct darwin_interface *cInterface = &priv->interfaces[iface];
kresult = darwin_get_interface (dpriv->device, iface, &usbInterface);
if (kresult != kIOReturnSuccess)
@@ -1081,6 +1060,10 @@ static int darwin_claim_interface(struct libusb_device_handle *dev_handle, int i
/* get an interface to the device's interface */
kresult = IOCreatePlugInInterfaceForService (usbInterface, kIOUSBInterfaceUserClientTypeID,
kIOCFPlugInInterfaceID, &plugInInterface, &score);
+
+ /* ignore release error */
+ (void)IOObjectRelease (usbInterface);
+
if (kresult) {
usbi_err (HANDLE_CTX (dev_handle), "IOCreatePlugInInterfaceForService: %s", darwin_error_str(kresult));
return darwin_to_libusb (kresult);
@@ -1091,21 +1074,17 @@ static int darwin_claim_interface(struct libusb_device_handle *dev_handle, int i
return LIBUSB_ERROR_NOT_FOUND;
}
- /* ignore release error */
- (void)IOObjectRelease (usbInterface);
-
/* Do the actual claim */
kresult = (*plugInInterface)->QueryInterface(plugInInterface,
CFUUIDGetUUIDBytes(kIOUSBInterfaceInterfaceID),
(LPVOID)&cInterface->interface);
+ /* We no longer need the intermediate plug-in */
+ IODestroyPlugInInterface (plugInInterface);
if (kresult || !cInterface->interface) {
usbi_err (HANDLE_CTX (dev_handle), "QueryInterface: %s", darwin_error_str(kresult));
return darwin_to_libusb (kresult);
}
- /* We no longer need the intermediate plug-in */
- (*plugInInterface)->Release(plugInInterface);
-
/* claim the interface */
kresult = (*(cInterface->interface))->USBInterfaceOpen(cInterface->interface);
if (kresult) {
@@ -1148,7 +1127,7 @@ static int darwin_release_interface(struct libusb_device_handle *dev_handle, int
IOReturn kresult;
/* current interface */
- struct __darwin_interface *cInterface = &priv->interfaces[iface];
+ struct darwin_interface *cInterface = &priv->interfaces[iface];
/* Check to see if an interface is open */
if (!cInterface->interface)
@@ -1181,7 +1160,7 @@ static int darwin_set_interface_altsetting(struct libusb_device_handle *dev_hand
IOReturn kresult;
/* current interface */
- struct __darwin_interface *cInterface = &priv->interfaces[iface];
+ struct darwin_interface *cInterface = &priv->interfaces[iface];
if (!cInterface->interface)
return LIBUSB_ERROR_NO_DEVICE;
@@ -1206,7 +1185,7 @@ static int darwin_clear_halt(struct libusb_device_handle *dev_handle, unsigned c
struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)dev_handle->os_priv;
/* current interface */
- struct __darwin_interface *cInterface;
+ struct darwin_interface *cInterface;
uint8_t pipeRef, iface;
IOReturn kresult;
@@ -1270,18 +1249,23 @@ static int darwin_kernel_driver_active(struct libusb_device_handle *dev_handle,
/* attaching/detaching kernel drivers is not currently supported (maybe in the future?) */
static int darwin_attach_kernel_driver (struct libusb_device_handle *dev_handle, int interface) {
+ (void)dev_handle;
+ (void)interface;
return LIBUSB_ERROR_NOT_SUPPORTED;
}
static int darwin_detach_kernel_driver (struct libusb_device_handle *dev_handle, int interface) {
+ (void)dev_handle;
+ (void)interface;
return LIBUSB_ERROR_NOT_SUPPORTED;
}
static void darwin_destroy_device(struct libusb_device *dev) {
+ (void)dev;
}
static int submit_bulk_transfer(struct usbi_transfer *itransfer) {
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)transfer->dev_handle->os_priv;
IOReturn ret;
@@ -1291,7 +1275,7 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer) {
uint8_t direction, number, interval, pipeRef, iface;
uint16_t maxPacketSize;
- struct __darwin_interface *cInterface;
+ struct darwin_interface *cInterface;
/* are we reading or writing? */
is_read = transfer->endpoint & LIBUSB_ENDPOINT_IN;
@@ -1337,7 +1321,7 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer) {
}
static int submit_iso_transfer(struct usbi_transfer *itransfer) {
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct darwin_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)transfer->dev_handle->os_priv;
@@ -1348,7 +1332,7 @@ static int submit_iso_transfer(struct usbi_transfer *itransfer) {
AbsoluteTime atTime;
int i;
- struct __darwin_interface *cInterface;
+ struct darwin_interface *cInterface;
/* are we reading or writing? */
is_read = transfer->endpoint & LIBUSB_ENDPOINT_IN;
@@ -1418,7 +1402,7 @@ static int submit_iso_transfer(struct usbi_transfer *itransfer) {
}
static int submit_control_transfer(struct usbi_transfer *itransfer) {
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct libusb_control_setup *setup = (struct libusb_control_setup *) transfer->buffer;
struct darwin_device_priv *dpriv = (struct darwin_device_priv *)transfer->dev_handle->dev->os_priv;
struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)transfer->dev_handle->os_priv;
@@ -1445,7 +1429,7 @@ static int submit_control_transfer(struct usbi_transfer *itransfer) {
/* all transfers in libusb-1.0 are async */
if (transfer->endpoint) {
- struct __darwin_interface *cInterface;
+ struct darwin_interface *cInterface;
uint8_t pipeRef, iface;
if (ep_to_pipeRef (transfer->dev_handle, transfer->endpoint, &pipeRef, &iface) != 0) {
@@ -1468,7 +1452,7 @@ static int submit_control_transfer(struct usbi_transfer *itransfer) {
}
static int darwin_submit_transfer(struct usbi_transfer *itransfer) {
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
switch (transfer->type) {
case LIBUSB_TRANSFER_TYPE_CONTROL:
@@ -1485,21 +1469,25 @@ static int darwin_submit_transfer(struct usbi_transfer *itransfer) {
}
static int cancel_control_transfer(struct usbi_transfer *itransfer) {
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct darwin_device_priv *dpriv = (struct darwin_device_priv *)transfer->dev_handle->dev->os_priv;
IOReturn kresult;
usbi_info (ITRANSFER_CTX (itransfer), "WARNING: aborting all transactions control pipe");
+ if (!dpriv->device)
+ return LIBUSB_ERROR_NO_DEVICE;
+
kresult = (*(dpriv->device))->USBDeviceAbortPipeZero (dpriv->device);
return darwin_to_libusb (kresult);
}
static int darwin_abort_transfers (struct usbi_transfer *itransfer) {
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct darwin_device_priv *dpriv = (struct darwin_device_priv *)transfer->dev_handle->dev->os_priv;
struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)transfer->dev_handle->os_priv;
- struct __darwin_interface *cInterface;
+ struct darwin_interface *cInterface;
uint8_t pipeRef, iface;
IOReturn kresult;
@@ -1511,6 +1499,9 @@ static int darwin_abort_transfers (struct usbi_transfer *itransfer) {
cInterface = &priv->interfaces[iface];
+ if (!dpriv->device)
+ return LIBUSB_ERROR_NO_DEVICE;
+
usbi_info (ITRANSFER_CTX (itransfer), "WARNING: aborting all transactions on interface %d pipe %d", iface, pipeRef);
/* abort transactions */
@@ -1530,7 +1521,7 @@ static int darwin_abort_transfers (struct usbi_transfer *itransfer) {
}
static int darwin_cancel_transfer(struct usbi_transfer *itransfer) {
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
switch (transfer->type) {
case LIBUSB_TRANSFER_TYPE_CONTROL:
@@ -1546,7 +1537,7 @@ static int darwin_cancel_transfer(struct usbi_transfer *itransfer) {
}
static void darwin_clear_transfer_priv (struct usbi_transfer *itransfer) {
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct darwin_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
if (transfer->type == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS && tpriv->isoc_framelist) {
@@ -1557,18 +1548,20 @@ static void darwin_clear_transfer_priv (struct usbi_transfer *itransfer) {
static void darwin_async_io_callback (void *refcon, IOReturn result, void *arg0) {
struct usbi_transfer *itransfer = (struct usbi_transfer *)refcon;
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct darwin_device_handle_priv *priv = (struct darwin_device_handle_priv *)transfer->dev_handle->os_priv;
- UInt32 message;
+ UInt32 message, size;
usbi_info (ITRANSFER_CTX (itransfer), "an async io operation has completed");
+ size = (UInt32) arg0;
+
/* send a completion message to the device's file descriptor */
message = MESSAGE_ASYNC_IO_COMPLETE;
write (priv->fds[1], &message, sizeof (message));
write (priv->fds[1], &itransfer, sizeof (itransfer));
write (priv->fds[1], &result, sizeof (IOReturn));
- write (priv->fds[1], &arg0, sizeof (UInt32));
+ write (priv->fds[1], &size, sizeof (size));
}
static int darwin_transfer_status (struct usbi_transfer *itransfer, kern_return_t result) {
@@ -1598,7 +1591,7 @@ static int darwin_transfer_status (struct usbi_transfer *itransfer, kern_return_
}
static void darwin_handle_callback (struct usbi_transfer *itransfer, kern_return_t result, UInt32 io_size) {
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct darwin_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
int isIsoc = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS == transfer->type;
int isBulk = LIBUSB_TRANSFER_TYPE_BULK == transfer->type;
@@ -1635,7 +1628,8 @@ static int op_handle_events(struct libusb_context *ctx, struct pollfd *fds, POLL
struct usbi_transfer *itransfer;
UInt32 io_size;
IOReturn kresult;
- int i = 0, ret;
+ POLL_NFDS_TYPE i = 0;
+ ssize_t ret;
UInt32 message;
usbi_mutex_lock(&ctx->open_devs_lock);
@@ -1658,7 +1652,7 @@ static int op_handle_events(struct libusb_context *ctx, struct pollfd *fds, POLL
if (!(pollfd->revents & POLLERR)) {
ret = read (hpriv->fds[0], &message, sizeof (message));
- if (ret < sizeof (message))
+ if (ret < (ssize_t)sizeof (message))
continue;
} else
/* could not poll the device-- response is to delete the device (this seems a little heavy-handed) */
@@ -1703,11 +1697,11 @@ static int darwin_clock_gettime(int clk_id, struct timespec *tp) {
switch (clk_id) {
case USBI_CLOCK_REALTIME:
/* CLOCK_REALTIME represents time since the epoch */
- host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &clock_ref);
+ clock_ref = clock_realtime;
break;
case USBI_CLOCK_MONOTONIC:
/* use system boot time as reference for the monotonic clock */
- host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &clock_ref);
+ clock_ref = clock_monotonic;
break;
default:
return LIBUSB_ERROR_INVALID_PARAM;
diff --git a/libusb/os/darwin_usb.h b/libusb/os/darwin_usb.h
index 9ffd6df..59d0a69 100644
--- a/libusb/os/darwin_usb.h
+++ b/libusb/os/darwin_usb.h
@@ -135,7 +135,7 @@ struct darwin_device_handle_priv {
CFRunLoopSourceRef cfSource;
int fds[2];
- struct __darwin_interface {
+ struct darwin_interface {
usb_interface_t **interface;
uint8_t num_endpoints;
CFRunLoopSourceRef cfSource;
diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
index 57e8f5a..2b81189 100644
--- a/libusb/os/linux_usbfs.c
+++ b/libusb/os/linux_usbfs.c
@@ -140,18 +140,18 @@ struct linux_transfer_priv {
int iso_packet_offset;
};
-static void __get_usbfs_path(struct libusb_device *dev, char *path)
+static void _get_usbfs_path(struct libusb_device *dev, char *path)
{
snprintf(path, PATH_MAX, "%s/%03d/%03d", usbfs_path, dev->bus_number,
dev->device_address);
}
-static struct linux_device_priv *__device_priv(struct libusb_device *dev)
+static struct linux_device_priv *_device_priv(struct libusb_device *dev)
{
return (struct linux_device_priv *) dev->os_priv;
}
-static struct linux_device_handle_priv *__device_handle_priv(
+static struct linux_device_handle_priv *_device_handle_priv(
struct libusb_device_handle *handle)
{
return (struct linux_device_handle_priv *) handle->os_priv;
@@ -220,25 +220,33 @@ static clockid_t find_monotonic_clock(void)
static int check_flag_bulk_continuation(void)
{
struct utsname uts;
- int major, minor, sublevel;
+ int atoms, major, minor, sublevel;
if (uname(&uts) < 0)
return -1;
- if (strlen(uts.release) < 4)
+ atoms = sscanf(uts.release, "%d.%d.%d", &major, &minor, &sublevel);
+ if (atoms < 1)
+ return -1;
+
+ if (major > 2)
+ return 1;
+ if (major < 2)
return 0;
- if (sscanf(uts.release, "%d.%d.%d", &major, &minor, &sublevel) != 3)
+
+ if (atoms < 2)
return 0;
- if (major < 2)
+
+ /* major == 2 */
+ if (minor < 6)
return 0;
- if (major == 2) {
- if (minor < 6)
- return 0;
- if (minor == 6) {
- if (sublevel < 32)
- return 0;
- }
- }
- return 1;
+ if (minor > 6) /* Does not exist, just here for correctness */
+ return 1;
+
+ /* 2.6.x */
+ if (3 == atoms && sublevel >= 32)
+ return 1;
+
+ return 0;
}
/* Return 1 if filename exists inside dirname in sysfs.
@@ -350,16 +358,16 @@ static int op_init(struct libusb_context *ctx)
static int usbfs_get_device_descriptor(struct libusb_device *dev,
unsigned char *buffer)
{
- struct linux_device_priv *priv = __device_priv(dev);
+ struct linux_device_priv *priv = _device_priv(dev);
/* return cached copy */
memcpy(buffer, priv->dev_descriptor, DEVICE_DESC_LENGTH);
return 0;
}
-static int __open_sysfs_attr(struct libusb_device *dev, const char *attr)
+static int _open_sysfs_attr(struct libusb_device *dev, const char *attr)
{
- struct linux_device_priv *priv = __device_priv(dev);
+ struct linux_device_priv *priv = _device_priv(dev);
char filename[PATH_MAX];
int fd;
@@ -419,7 +427,7 @@ static int sysfs_get_device_descriptor(struct libusb_device *dev,
/* sysfs provides access to an in-memory copy of the device descriptor,
* so we use that rather than keeping our own copy */
- fd = __open_sysfs_attr(dev, "descriptors");
+ fd = _open_sysfs_attr(dev, "descriptors");
if (fd < 0)
return fd;
@@ -450,7 +458,7 @@ static int op_get_device_descriptor(struct libusb_device *dev,
static int usbfs_get_active_config_descriptor(struct libusb_device *dev,
unsigned char *buffer, size_t len)
{
- struct linux_device_priv *priv = __device_priv(dev);
+ struct linux_device_priv *priv = _device_priv(dev);
if (!priv->config_descriptor)
return LIBUSB_ERROR_NOT_FOUND; /* device is unconfigured */
@@ -468,7 +476,7 @@ static int sysfs_get_active_config(struct libusb_device *dev, int *config)
int fd;
ssize_t r;
- fd = __open_sysfs_attr(dev, "bConfigurationValue");
+ fd = _open_sysfs_attr(dev, "bConfigurationValue");
if (fd < 0)
return fd;
@@ -554,7 +562,7 @@ static int sysfs_get_active_config_descriptor(struct libusb_device *dev,
/* sysfs provides access to an in-memory copy of the device descriptor,
* so we use that rather than keeping our own copy */
- fd = __open_sysfs_attr(dev, "descriptors");
+ fd = _open_sysfs_attr(dev, "descriptors");
if (fd < 0)
return fd;
@@ -688,7 +696,7 @@ static int op_get_config_descriptor(struct libusb_device *dev,
* in the descriptors file. but its kinda hard to detect if the kernel
* is sufficiently new. */
- __get_usbfs_path(dev, filename);
+ _get_usbfs_path(dev, filename);
fd = open(filename, O_RDONLY);
if (fd < 0) {
usbi_err(DEVICE_CTX(dev),
@@ -707,7 +715,7 @@ static int op_get_config_descriptor(struct libusb_device *dev,
static int cache_active_config(struct libusb_device *dev, int fd,
int active_config)
{
- struct linux_device_priv *priv = __device_priv(dev);
+ struct linux_device_priv *priv = _device_priv(dev);
struct libusb_config_descriptor config;
unsigned char tmp[8];
unsigned char *buf;
@@ -781,7 +789,7 @@ static int usbfs_get_active_config(struct libusb_device *dev, int fd)
static int initialize_device(struct libusb_device *dev, uint8_t busnum,
uint8_t devaddr, const char *sysfs_dir)
{
- struct linux_device_priv *priv = __device_priv(dev);
+ struct linux_device_priv *priv = _device_priv(dev);
unsigned char *dev_buf;
char path[PATH_MAX];
int fd, speed;
@@ -830,7 +838,7 @@ static int initialize_device(struct libusb_device *dev, uint8_t busnum,
device_configured = 0;
}
- __get_usbfs_path(dev, path);
+ _get_usbfs_path(dev, path);
fd = open(path, O_RDWR);
if (fd < 0 && errno == EACCES) {
fd = open(path, O_RDONLY);
@@ -972,7 +980,7 @@ static int usbfs_scan_busdir(struct libusb_context *ctx,
char dirpath[PATH_MAX];
struct dirent *entry;
struct discovered_devs *discdevs = *_discdevs;
- int r = 0;
+ int r = LIBUSB_ERROR_IO;
snprintf(dirpath, PATH_MAX, "%s/%03d", usbfs_path, busnum);
usbi_dbg("%s", dirpath);
@@ -981,7 +989,7 @@ static int usbfs_scan_busdir(struct libusb_context *ctx,
usbi_err(ctx, "opendir '%s' failed, errno=%d", dirpath, errno);
/* FIXME: should handle valid race conditions like hub unplugged
* during directory iteration - this is not an error */
- return LIBUSB_ERROR_IO;
+ return r;
}
while ((entry = readdir(dir))) {
@@ -996,13 +1004,16 @@ static int usbfs_scan_busdir(struct libusb_context *ctx,
continue;
}
- r = enumerate_device(ctx, &discdevs, busnum, (uint8_t) devaddr, NULL);
- if (r < 0)
- goto out;
+ if (enumerate_device(ctx, &discdevs, busnum, (uint8_t) devaddr, NULL)) {
+ usbi_dbg("failed to enumerate dir entry %s", entry->d_name);
+ continue;
+ }
+
+ r = 0;
}
- *_discdevs = discdevs;
-out:
+ if (!r)
+ *_discdevs = discdevs;
closedir(dir);
return r;
}
@@ -1070,85 +1081,17 @@ static int sysfs_scan_device(struct libusb_context *ctx,
devname);
}
-static void sysfs_analyze_topology(struct discovered_devs *discdevs)
-{
- struct linux_device_priv *priv;
- int i, j;
- struct libusb_device *dev1, *dev2;
- const char *sysfs_dir1, *sysfs_dir2;
- const char *p;
- int n, boundary_char;
-
- /* Fill in the port_number and parent_dev fields for each device */
-
- for (i = 0; i < discdevs->len; ++i) {
- dev1 = discdevs->devices[i];
- priv = __device_priv(dev1);
- if (!priv)
- continue;
- sysfs_dir1 = priv->sysfs_dir;
-
- /* Root hubs have sysfs_dir names of the form "usbB",
- * where B is the bus number. All other devices have
- * sysfs_dir names of the form "B-P[.P ...]", where the
- * P values are port numbers leading from the root hub
- * to the device.
- */
-
- /* Root hubs don't have parents or port numbers */
- if (sysfs_dir1[0] == 'u')
- continue;
-
- /* The rightmost component is the device's port number */
- p = strrchr(sysfs_dir1, '.');
- if (!p) {
- p = strchr(sysfs_dir1, '-');
- if (!p)
- continue; /* Should never happen */
- }
- dev1->port_number = atoi(p + 1);
-
- /* Search for the parent device */
- boundary_char = *p;
- n = p - sysfs_dir1;
- for (j = 0; j < discdevs->len; ++j) {
- dev2 = discdevs->devices[j];
- priv = __device_priv(dev2);
- if (!priv)
- continue;
- sysfs_dir2 = priv->sysfs_dir;
-
- if (boundary_char == '-') {
- /* The parent's name must begin with 'usb';
- * skip past that part of sysfs_dir2.
- */
- if (sysfs_dir2[0] != 'u')
- continue;
- sysfs_dir2 += 3;
- }
-
- /* The remainder of the parent's name must be equal to
- * the first n bytes of sysfs_dir1.
- */
- if (memcmp(sysfs_dir1, sysfs_dir2, n) == 0 && !sysfs_dir2[n]) {
- dev1->parent_dev = dev2;
- break;
- }
- }
- }
-}
-
static int sysfs_get_device_list(struct libusb_context *ctx,
struct discovered_devs **_discdevs)
{
struct discovered_devs *discdevs = *_discdevs;
DIR *devices = opendir(SYSFS_DEVICE_PATH);
struct dirent *entry;
- int r = 0;
+ int r = LIBUSB_ERROR_IO;
if (!devices) {
usbi_err(ctx, "opendir devices failed errno=%d", errno);
- return LIBUSB_ERROR_IO;
+ return r;
}
while ((entry = readdir(devices))) {
@@ -1158,16 +1101,18 @@ static int sysfs_get_device_list(struct libusb_context *ctx,
|| strchr(entry->d_name, ':'))
continue;
- r = sysfs_scan_device(ctx, &discdevs_new, entry->d_name);
- if (r < 0 && r != LIBUSB_ERROR_NO_DEVICE)
- goto out;
+ if (sysfs_scan_device(ctx, &discdevs_new, entry->d_name)) {
+ usbi_dbg("failed to enumerate dir entry %s", entry->d_name);
+ continue;
+ }
+
+ r = 0;
discdevs = discdevs_new;
}
- r = 0;
-out:
+
+ if (!r)
+ *_discdevs = discdevs;
closedir(devices);
- *_discdevs = discdevs;
- sysfs_analyze_topology(discdevs);
return r;
}
@@ -1192,10 +1137,11 @@ static int op_get_device_list(struct libusb_context *ctx,
static int op_open(struct libusb_device_handle *handle)
{
- struct linux_device_handle_priv *hpriv = __device_handle_priv(handle);
+ struct linux_device_handle_priv *hpriv = _device_handle_priv(handle);
char filename[PATH_MAX];
- __get_usbfs_path(handle->dev, filename);
+ _get_usbfs_path(handle->dev, filename);
+ usbi_dbg("opening %s", filename);
hpriv->fd = open(filename, O_RDWR);
if (hpriv->fd < 0) {
if (errno == EACCES) {
@@ -1205,6 +1151,8 @@ static int op_open(struct libusb_device_handle *handle)
"libusb requires write access to USB device nodes.");
return LIBUSB_ERROR_ACCESS;
} else if (errno == ENOENT) {
+ usbi_err(HANDLE_CTX(handle), "libusb couldn't open USB device %s: "
+ "No such file or directory.", filename);
return LIBUSB_ERROR_NO_DEVICE;
} else {
usbi_err(HANDLE_CTX(handle),
@@ -1218,7 +1166,7 @@ static int op_open(struct libusb_device_handle *handle)
static void op_close(struct libusb_device_handle *dev_handle)
{
- int fd = __device_handle_priv(dev_handle)->fd;
+ int fd = _device_handle_priv(dev_handle)->fd;
usbi_remove_pollfd(HANDLE_CTX(dev_handle), fd);
close(fd);
}
@@ -1242,8 +1190,8 @@ static int op_get_configuration(struct libusb_device_handle *handle,
static int op_set_configuration(struct libusb_device_handle *handle, int config)
{
- struct linux_device_priv *priv = __device_priv(handle->dev);
- int fd = __device_handle_priv(handle)->fd;
+ struct linux_device_priv *priv = _device_priv(handle->dev);
+ int fd = _device_handle_priv(handle)->fd;
int r = ioctl(fd, IOCTL_USBFS_SETCONFIG, &config);
if (r) {
if (errno == EINVAL)
@@ -1277,7 +1225,7 @@ static int op_set_configuration(struct libusb_device_handle *handle, int config)
static int op_claim_interface(struct libusb_device_handle *handle, int iface)
{
- int fd = __device_handle_priv(handle)->fd;
+ int fd = _device_handle_priv(handle)->fd;
int r = ioctl(fd, IOCTL_USBFS_CLAIMINTF, &iface);
if (r) {
if (errno == ENOENT)
@@ -1296,7 +1244,7 @@ static int op_claim_interface(struct libusb_device_handle *handle, int iface)
static int op_release_interface(struct libusb_device_handle *handle, int iface)
{
- int fd = __device_handle_priv(handle)->fd;
+ int fd = _device_handle_priv(handle)->fd;
int r = ioctl(fd, IOCTL_USBFS_RELEASEINTF, &iface);
if (r) {
if (errno == ENODEV)
@@ -1312,7 +1260,7 @@ static int op_release_interface(struct libusb_device_handle *handle, int iface)
static int op_set_interface(struct libusb_device_handle *handle, int iface,
int altsetting)
{
- int fd = __device_handle_priv(handle)->fd;
+ int fd = _device_handle_priv(handle)->fd;
struct usbfs_setinterface setintf;
int r;
@@ -1336,7 +1284,7 @@ static int op_set_interface(struct libusb_device_handle *handle, int iface,
static int op_clear_halt(struct libusb_device_handle *handle,
unsigned char endpoint)
{
- int fd = __device_handle_priv(handle)->fd;
+ int fd = _device_handle_priv(handle)->fd;
unsigned int _endpoint = endpoint;
int r = ioctl(fd, IOCTL_USBFS_CLEAR_HALT, &_endpoint);
if (r) {
@@ -1355,7 +1303,7 @@ static int op_clear_halt(struct libusb_device_handle *handle,
static int op_reset_device(struct libusb_device_handle *handle)
{
- int fd = __device_handle_priv(handle)->fd;
+ int fd = _device_handle_priv(handle)->fd;
int i, r, ret = 0;
/* Doing a device reset will cause the usbfs driver to get unbound
@@ -1402,7 +1350,7 @@ out:
static int op_kernel_driver_active(struct libusb_device_handle *handle,
int interface)
{
- int fd = __device_handle_priv(handle)->fd;
+ int fd = _device_handle_priv(handle)->fd;
struct usbfs_getdriver getdrv;
int r;
@@ -1425,7 +1373,7 @@ static int op_kernel_driver_active(struct libusb_device_handle *handle,
static int op_detach_kernel_driver(struct libusb_device_handle *handle,
int interface)
{
- int fd = __device_handle_priv(handle)->fd;
+ int fd = _device_handle_priv(handle)->fd;
struct usbfs_ioctl command;
int r;
@@ -1453,7 +1401,7 @@ static int op_detach_kernel_driver(struct libusb_device_handle *handle,
static int op_attach_kernel_driver(struct libusb_device_handle *handle,
int interface)
{
- int fd = __device_handle_priv(handle)->fd;
+ int fd = _device_handle_priv(handle)->fd;
struct usbfs_ioctl command;
int r;
@@ -1484,7 +1432,7 @@ static int op_attach_kernel_driver(struct libusb_device_handle *handle,
static void op_destroy_device(struct libusb_device *dev)
{
- struct linux_device_priv *priv = __device_priv(dev);
+ struct linux_device_priv *priv = _device_priv(dev);
if (!sysfs_has_descriptors) {
if (priv->dev_descriptor)
free(priv->dev_descriptor);
@@ -1499,11 +1447,11 @@ static void op_destroy_device(struct libusb_device *dev)
static int discard_urbs(struct usbi_transfer *itransfer, int first, int last_plus_one)
{
struct libusb_transfer *transfer =
- __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct linux_transfer_priv *tpriv =
usbi_transfer_get_os_priv(itransfer);
struct linux_device_handle_priv *dpriv =
- __device_handle_priv(transfer->dev_handle);
+ _device_handle_priv(transfer->dev_handle);
int i, ret = 0;
struct usbfs_urb *urb;
@@ -1549,10 +1497,10 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer,
unsigned char urb_type)
{
struct libusb_transfer *transfer =
- __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct linux_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
struct linux_device_handle_priv *dpriv =
- __device_handle_priv(transfer->dev_handle);
+ _device_handle_priv(transfer->dev_handle);
struct usbfs_urb *urbs;
int is_out = (transfer->endpoint & LIBUSB_ENDPOINT_DIR_MASK)
== LIBUSB_ENDPOINT_OUT;
@@ -1666,10 +1614,10 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer,
static int submit_iso_transfer(struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer =
- __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct linux_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
struct linux_device_handle_priv *dpriv =
- __device_handle_priv(transfer->dev_handle);
+ _device_handle_priv(transfer->dev_handle);
struct usbfs_urb **urbs;
size_t alloc_size;
int num_packets = transfer->num_iso_packets;
@@ -1817,9 +1765,9 @@ static int submit_control_transfer(struct usbi_transfer *itransfer)
{
struct linux_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
struct libusb_transfer *transfer =
- __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct linux_device_handle_priv *dpriv =
- __device_handle_priv(transfer->dev_handle);
+ _device_handle_priv(transfer->dev_handle);
struct usbfs_urb *urb;
int r;
@@ -1860,7 +1808,7 @@ static int submit_control_transfer(struct usbi_transfer *itransfer)
static int op_submit_transfer(struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer =
- __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
switch (transfer->type) {
case LIBUSB_TRANSFER_TYPE_CONTROL:
@@ -1882,7 +1830,7 @@ static int op_cancel_transfer(struct usbi_transfer *itransfer)
{
struct linux_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
struct libusb_transfer *transfer =
- __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
switch (transfer->type) {
case LIBUSB_TRANSFER_TYPE_BULK:
@@ -1909,18 +1857,25 @@ static int op_cancel_transfer(struct usbi_transfer *itransfer)
static void op_clear_transfer_priv(struct usbi_transfer *itransfer)
{
struct libusb_transfer *transfer =
- __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct linux_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
+ /* urbs can be freed also in submit_transfer so lock mutex first */
switch (transfer->type) {
case LIBUSB_TRANSFER_TYPE_CONTROL:
case LIBUSB_TRANSFER_TYPE_BULK:
case LIBUSB_TRANSFER_TYPE_INTERRUPT:
- free(tpriv->urbs);
+ usbi_mutex_lock(&itransfer->lock);
+ if (tpriv->urbs)
+ free(tpriv->urbs);
tpriv->urbs = NULL;
+ usbi_mutex_unlock(&itransfer->lock);
break;
case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS:
- free_iso_urbs(tpriv);
+ usbi_mutex_lock(&itransfer->lock);
+ if (tpriv->iso_urbs)
+ free_iso_urbs(tpriv);
+ usbi_mutex_unlock(&itransfer->lock);
break;
default:
usbi_err(TRANSFER_CTX(transfer),
@@ -1932,7 +1887,7 @@ static int handle_bulk_completion(struct usbi_transfer *itransfer,
struct usbfs_urb *urb)
{
struct linux_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
int urb_idx = urb - tpriv->urbs;
usbi_mutex_lock(&itransfer->lock);
@@ -2065,7 +2020,7 @@ static int handle_iso_completion(struct usbi_transfer *itransfer,
struct usbfs_urb *urb)
{
struct libusb_transfer *transfer =
- __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct linux_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
int num_urbs = tpriv->num_urbs;
int urb_idx = 0;
@@ -2212,7 +2167,7 @@ static int handle_control_completion(struct usbi_transfer *itransfer,
static int reap_for_handle(struct libusb_device_handle *handle)
{
- struct linux_device_handle_priv *hpriv = __device_handle_priv(handle);
+ struct linux_device_handle_priv *hpriv = _device_handle_priv(handle);
int r;
struct usbfs_urb *urb;
struct usbi_transfer *itransfer;
@@ -2231,7 +2186,7 @@ static int reap_for_handle(struct libusb_device_handle *handle)
}
itransfer = urb->usercontext;
- transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
usbi_dbg("urb type=%d status=%d transferred=%d", urb->type, urb->status,
urb->actual_length);
@@ -2268,7 +2223,7 @@ static int op_handle_events(struct libusb_context *ctx,
num_ready--;
list_for_each_entry(handle, &ctx->open_devs, list, struct libusb_device_handle) {
- hpriv = __device_handle_priv(handle);
+ hpriv = _device_handle_priv(handle);
if (hpriv->fd == pollfd->fd)
break;
}
diff --git a/libusb/os/linux_usbfs.h b/libusb/os/linux_usbfs.h
index bd02edc..93e7f31 100644
--- a/libusb/os/linux_usbfs.h
+++ b/libusb/os/linux_usbfs.h
@@ -18,8 +18,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef __LIBUSB_USBFS_H__
-#define __LIBUSB_USBFS_H__
+#ifndef LIBUSB_USBFS_H
+#define LIBUSB_USBFS_H
#define SYSFS_DEVICE_PATH "/sys/bus/usb/devices"
diff --git a/libusb/os/poll_posix.h b/libusb/os/poll_posix.h
index f8c9e21..0e5e7f5 100644
--- a/libusb/os/poll_posix.h
+++ b/libusb/os/poll_posix.h
@@ -1,5 +1,5 @@
-#ifndef __LIBUSB_POLL_POSIX_H__
-#define __LIBUSB_POLL_POSIX_H__
+#ifndef LIBUSB_POLL_POSIX_H
+#define LIBUSB_POLL_POSIX_H
#define usbi_write write
#define usbi_read read
@@ -7,4 +7,4 @@
#define usbi_pipe pipe
#define usbi_poll poll
-#endif /* __LIBUSB_POLL_POSIX_H__ */
+#endif /* LIBUSB_POLL_POSIX_H */
diff --git a/libusb/os/poll_windows.h b/libusb/os/poll_windows.h
index 4cc345b..fee89f5 100644
--- a/libusb/os/poll_windows.h
+++ b/libusb/os/poll_windows.h
@@ -38,7 +38,7 @@
#define STATUS_COMPLETED_SYNCHRONOUSLY STATUS_REPARSE
#define HasOverlappedIoCompletedSync(lpOverlapped) (((DWORD)(lpOverlapped)->Internal) == STATUS_COMPLETED_SYNCHRONOUSLY)
-#define DUMMY_HANDLE ((HANDLE)(LONG)-2)
+#define DUMMY_HANDLE ((HANDLE)(LONG_PTR)-2)
enum windows_version {
WINDOWS_UNSUPPORTED,
diff --git a/libusb/os/threads_posix.c b/libusb/os/threads_posix.c
index 9b8487c..435b873 100644
--- a/libusb/os/threads_posix.c
+++ b/libusb/os/threads_posix.c
@@ -52,4 +52,4 @@ finish:
pthread_mutexattr_destroy(&stack_attr);
return err;
-} \ No newline at end of file
+}
diff --git a/libusb/os/threads_posix.h b/libusb/os/threads_posix.h
index 6aa13f5..9752208 100644
--- a/libusb/os/threads_posix.h
+++ b/libusb/os/threads_posix.h
@@ -18,8 +18,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef __LIBUSB_THREADS_POSIX_H__
-#define __LIBUSB_THREADS_POSIX_H__
+#ifndef LIBUSB_THREADS_POSIX_H
+#define LIBUSB_THREADS_POSIX_H
#include <pthread.h>
@@ -41,8 +41,8 @@
#define usbi_cond_timedwait pthread_cond_timedwait
#define usbi_cond_broadcast pthread_cond_broadcast
#define usbi_cond_destroy pthread_cond_destroy
-#define usbi_cond_signal pthread_cond_signal
+#define usbi_cond_signal pthread_cond_signal
extern int usbi_mutex_init_recursive(pthread_mutex_t *mutex, pthread_mutexattr_t *attr);
-#endif /* __LIBUSB_THREADS_POSIX_H__ */
+#endif /* LIBUSB_THREADS_POSIX_H */
diff --git a/libusb/os/threads_windows.h b/libusb/os/threads_windows.h
index 9f77598..195e424 100644
--- a/libusb/os/threads_windows.h
+++ b/libusb/os/threads_windows.h
@@ -18,8 +18,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef __LIBUSB_THREADS_WINDOWS_H__
-#define __LIBUSB_THREADS_WINDOWS_H__
+#ifndef LIBUSB_THREADS_WINDOWS_H
+#define LIBUSB_THREADS_WINDOWS_H
#define usbi_mutex_static_t volatile LONG
#define USBI_MUTEX_INITIALIZER 0
@@ -82,4 +82,4 @@ int usbi_cond_timedwait(usbi_cond_t *cond,
int usbi_cond_broadcast(usbi_cond_t *cond);
int usbi_cond_signal(usbi_cond_t *cond);
-#endif /* __LIBUSB_THREADS_WINDOWS_H__ */
+#endif /* LIBUSB_THREADS_WINDOWS_H */
diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c
index e6e3273..694d72b 100644
--- a/libusb/os/windows_usb.c
+++ b/libusb/os/windows_usb.c
@@ -592,7 +592,7 @@ static unsigned long get_ancestor_session_id(DWORD devinst, unsigned level)
static int windows_assign_endpoints(struct libusb_device_handle *dev_handle, int iface, int altsetting)
{
int i, r;
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
struct libusb_config_descriptor *conf_desc;
const struct libusb_interface_descriptor *if_desc;
struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev);
@@ -664,9 +664,9 @@ static bool is_api_driver(char* driver, uint8_t api)
static int auto_claim(struct libusb_transfer *transfer, int *interface_number, int api_type)
{
struct libusb_context *ctx = DEVICE_CTX(transfer->dev_handle->dev);
- struct windows_device_handle_priv *handle_priv = __device_handle_priv(
+ struct windows_device_handle_priv *handle_priv = _device_handle_priv(
transfer->dev_handle);
- struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(transfer->dev_handle->dev);
int current_interface = *interface_number;
int r = LIBUSB_SUCCESS;
@@ -706,9 +706,9 @@ static int auto_claim(struct libusb_transfer *transfer, int *interface_number, i
static void auto_release(struct usbi_transfer *itransfer)
{
struct windows_transfer_priv *transfer_priv = (struct windows_transfer_priv*)usbi_transfer_get_os_priv(itransfer);
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
libusb_device_handle *dev_handle = transfer->dev_handle;
- struct windows_device_handle_priv* handle_priv = __device_handle_priv(dev_handle);
+ struct windows_device_handle_priv* handle_priv = _device_handle_priv(dev_handle);
int r;
usbi_mutex_lock(&autoclaim_lock);
@@ -878,7 +878,7 @@ init_exit: // Holds semaphore here.
*/
static int force_hcd_device_descriptor(struct libusb_device *dev)
{
- struct windows_device_priv *parent_priv, *priv = __device_priv(dev);
+ struct windows_device_priv *parent_priv, *priv = _device_priv(dev);
struct libusb_context *ctx = DEVICE_CTX(dev);
int vid, pid;
@@ -892,7 +892,7 @@ static int force_hcd_device_descriptor(struct libusb_device *dev)
usbi_err(ctx, "program assertion failed - HCD hub has no parent");
return LIBUSB_ERROR_NO_DEVICE;
}
- parent_priv = __device_priv(priv->parent_dev);
+ parent_priv = _device_priv(priv->parent_dev);
if (sscanf(parent_priv->path, "\\\\.\\PCI#VEN_%04x&DEV_%04x%*s", &vid, &pid) == 2) {
priv->dev_descriptor.idVendor = (uint16_t)vid;
priv->dev_descriptor.idProduct = (uint16_t)pid;
@@ -911,7 +911,7 @@ static int cache_config_descriptors(struct libusb_device *dev, HANDLE hub_handle
{
DWORD size, ret_size;
struct libusb_context *ctx = DEVICE_CTX(dev);
- struct windows_device_priv *priv = __device_priv(dev);
+ struct windows_device_priv *priv = _device_priv(dev);
int r;
uint8_t i;
@@ -1021,8 +1021,8 @@ static int init_device(struct libusb_device* dev, struct libusb_device* parent_d
if ((dev == NULL) || (parent_dev == NULL)) {
return LIBUSB_ERROR_NOT_FOUND;
}
- priv = __device_priv(dev);
- parent_priv = __device_priv(parent_dev);
+ priv = _device_priv(dev);
+ parent_priv = _device_priv(parent_dev);
if (parent_priv->apib->id != USB_API_HUB) {
usbi_warn(ctx, "parent for device '%s' is not a hub", device_id);
return LIBUSB_ERROR_NOT_FOUND;
@@ -1171,7 +1171,7 @@ static int set_composite_interface(struct libusb_context* ctx, struct libusb_dev
char* dev_interface_path, char* device_id, uint8_t api)
{
unsigned i;
- struct windows_device_priv *priv = __device_priv(dev);
+ struct windows_device_priv *priv = _device_priv(dev);
int interface_number;
if (priv->apib->id != USB_API_COMPOSITE) {
@@ -1217,7 +1217,7 @@ static int windows_get_device_list(struct libusb_context *ctx, struct discovered
{
struct discovered_devs *discdevs;
HDEVINFO dev_info = { 0 };
- char* usb_class[2] = {"USB", "NUSB3"};
+ char* usb_class[2] = {"USB", "NUSB3"};
SP_DEVINFO_DATA dev_info_data;
SP_DEVICE_INTERFACE_DETAIL_DATA_A *dev_interface_details = NULL;
#define MAX_ENUM_GUIDS 64
@@ -1320,7 +1320,7 @@ static int windows_get_device_list(struct libusb_context *ctx, struct discovered
} else {
// Workaround for a Nec/Renesas USB 3.0 driver bug where root hubs are
// being listed under the "NUSB3" PnP Symbolic Name rather than "USB"
- while ( (class_index < 2) &&
+ while ( (class_index < 2) &&
(!(b = get_devinfo_data(ctx, &dev_info, &dev_info_data, usb_class[class_index], i))) ) {
class_index++;
i = 0;
@@ -1426,7 +1426,7 @@ static int windows_get_device_list(struct libusb_context *ctx, struct discovered
usbi_dbg("unlisted ancestor for '%s' (newly connected, etc.) - ignoring", dev_id_path);
continue;
}
- parent_priv = __device_priv(parent_dev);
+ parent_priv = _device_priv(parent_dev);
// virtual USB devices are also listed during GEN - don't process these yet
if ( (pass == GEN_PASS) && (parent_priv->apib->id != USB_API_HUB) ) {
continue;
@@ -1465,7 +1465,7 @@ static int windows_get_device_list(struct libusb_context *ctx, struct discovered
usbi_dbg("found existing device for session [%X] (%d.%d)",
session_id, dev->bus_number, dev->device_address);
}
- priv = __device_priv(dev);
+ priv = _device_priv(dev);
}
// Setup device
@@ -1616,7 +1616,7 @@ static void windows_exit(void)
static int windows_get_device_descriptor(struct libusb_device *dev, unsigned char *buffer, int *host_endian)
{
- struct windows_device_priv *priv = __device_priv(dev);
+ struct windows_device_priv *priv = _device_priv(dev);
memcpy(buffer, &(priv->dev_descriptor), DEVICE_DESC_LENGTH);
*host_endian = 0;
@@ -1626,7 +1626,7 @@ static int windows_get_device_descriptor(struct libusb_device *dev, unsigned cha
static int windows_get_config_descriptor(struct libusb_device *dev, uint8_t config_index, unsigned char *buffer, size_t len, int *host_endian)
{
- struct windows_device_priv *priv = __device_priv(dev);
+ struct windows_device_priv *priv = _device_priv(dev);
PUSB_CONFIGURATION_DESCRIPTOR config_header;
size_t size;
@@ -1650,7 +1650,7 @@ static int windows_get_config_descriptor(struct libusb_device *dev, uint8_t conf
*/
static int windows_get_active_config_descriptor(struct libusb_device *dev, unsigned char *buffer, size_t len, int *host_endian)
{
- struct windows_device_priv *priv = __device_priv(dev);
+ struct windows_device_priv *priv = _device_priv(dev);
if (priv->active_config == 0)
return LIBUSB_ERROR_NOT_FOUND;
@@ -1661,7 +1661,7 @@ static int windows_get_active_config_descriptor(struct libusb_device *dev, unsig
static int windows_open(struct libusb_device_handle *dev_handle)
{
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev);
if (priv->apib == NULL) {
@@ -1674,14 +1674,14 @@ static int windows_open(struct libusb_device_handle *dev_handle)
static void windows_close(struct libusb_device_handle *dev_handle)
{
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
priv->apib->close(dev_handle);
}
static int windows_get_configuration(struct libusb_device_handle *dev_handle, int *config)
{
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
if (priv->active_config == 0) {
*config = 0;
@@ -1699,7 +1699,7 @@ static int windows_get_configuration(struct libusb_device_handle *dev_handle, in
*/
static int windows_set_configuration(struct libusb_device_handle *dev_handle, int config)
{
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
int r = LIBUSB_SUCCESS;
if (config >= USB_MAXCONFIG)
@@ -1719,7 +1719,7 @@ static int windows_set_configuration(struct libusb_device_handle *dev_handle, in
static int windows_claim_interface(struct libusb_device_handle *dev_handle, int iface)
{
int r = LIBUSB_SUCCESS;
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
if (iface >= USB_MAXINTERFACES)
return LIBUSB_ERROR_INVALID_PARAM;
@@ -1739,7 +1739,7 @@ static int windows_claim_interface(struct libusb_device_handle *dev_handle, int
static int windows_set_interface_altsetting(struct libusb_device_handle *dev_handle, int iface, int altsetting)
{
int r = LIBUSB_SUCCESS;
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
safe_free(priv->usb_interface[iface].endpoint);
priv->usb_interface[iface].nb_endpoints= 0;
@@ -1755,20 +1755,20 @@ static int windows_set_interface_altsetting(struct libusb_device_handle *dev_han
static int windows_release_interface(struct libusb_device_handle *dev_handle, int iface)
{
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
return priv->apib->release_interface(dev_handle, iface);
}
static int windows_clear_halt(struct libusb_device_handle *dev_handle, unsigned char endpoint)
{
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
return priv->apib->clear_halt(dev_handle, endpoint);
}
static int windows_reset_device(struct libusb_device_handle *dev_handle)
{
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
return priv->apib->reset_device(dev_handle);
}
@@ -1806,10 +1806,10 @@ static void windows_clear_transfer_priv(struct usbi_transfer *itransfer)
static int submit_bulk_transfer(struct usbi_transfer *itransfer)
{
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct libusb_context *ctx = DEVICE_CTX(transfer->dev_handle->dev);
struct windows_transfer_priv *transfer_priv = (struct windows_transfer_priv*)usbi_transfer_get_os_priv(itransfer);
- struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(transfer->dev_handle->dev);
int r;
r = priv->apib->submit_bulk_transfer(itransfer);
@@ -1828,10 +1828,10 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer)
static int submit_iso_transfer(struct usbi_transfer *itransfer)
{
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct libusb_context *ctx = DEVICE_CTX(transfer->dev_handle->dev);
struct windows_transfer_priv *transfer_priv = (struct windows_transfer_priv*)usbi_transfer_get_os_priv(itransfer);
- struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(transfer->dev_handle->dev);
int r;
r = priv->apib->submit_iso_transfer(itransfer);
@@ -1850,10 +1850,10 @@ static int submit_iso_transfer(struct usbi_transfer *itransfer)
static int submit_control_transfer(struct usbi_transfer *itransfer)
{
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct libusb_context *ctx = DEVICE_CTX(transfer->dev_handle->dev);
struct windows_transfer_priv *transfer_priv = (struct windows_transfer_priv*)usbi_transfer_get_os_priv(itransfer);
- struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(transfer->dev_handle->dev);
int r;
r = priv->apib->submit_control_transfer(itransfer);
@@ -1872,7 +1872,7 @@ static int submit_control_transfer(struct usbi_transfer *itransfer)
static int windows_submit_transfer(struct usbi_transfer *itransfer)
{
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
switch (transfer->type) {
case LIBUSB_TRANSFER_TYPE_CONTROL:
@@ -1890,23 +1890,23 @@ static int windows_submit_transfer(struct usbi_transfer *itransfer)
static int windows_abort_control(struct usbi_transfer *itransfer)
{
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct windows_device_priv *priv = _device_priv(transfer->dev_handle->dev);
return priv->apib->abort_control(itransfer);
}
static int windows_abort_transfers(struct usbi_transfer *itransfer)
{
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct windows_device_priv *priv = _device_priv(transfer->dev_handle->dev);
return priv->apib->abort_transfers(itransfer);
}
static int windows_cancel_transfer(struct usbi_transfer *itransfer)
{
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
#if defined(FORCE_INSTANT_TIMEOUTS)
struct windows_transfer_priv *transfer_priv = usbi_transfer_get_os_priv(itransfer);
@@ -1930,8 +1930,8 @@ static int windows_cancel_transfer(struct usbi_transfer *itransfer)
static void windows_transfer_callback(struct usbi_transfer *itransfer, uint32_t io_result, uint32_t io_size)
{
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
- struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct windows_device_priv *priv = _device_priv(transfer->dev_handle->dev);
int status;
usbi_dbg("handling I/O completion with errcode %d", io_result);
@@ -1968,7 +1968,7 @@ static void windows_transfer_callback(struct usbi_transfer *itransfer, uint32_t
static void windows_handle_callback (struct usbi_transfer *itransfer, uint32_t io_result, uint32_t io_size)
{
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
switch (transfer->type) {
case LIBUSB_TRANSFER_TYPE_CONTROL:
@@ -2382,8 +2382,8 @@ static int winusb_exit(void)
static int winusb_open(struct libusb_device_handle *dev_handle)
{
struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev);
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
- struct windows_device_handle_priv *handle_priv = __device_handle_priv(dev_handle);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
+ struct windows_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
HANDLE file_handle;
int i;
@@ -2416,8 +2416,8 @@ static int winusb_open(struct libusb_device_handle *dev_handle)
static void winusb_close(struct libusb_device_handle *dev_handle)
{
- struct windows_device_handle_priv *handle_priv = __device_handle_priv(dev_handle);
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
HANDLE file_handle;
int i;
@@ -2436,8 +2436,8 @@ static void winusb_close(struct libusb_device_handle *dev_handle)
static int winusb_configure_endpoints(struct libusb_device_handle *dev_handle, int iface)
{
- struct windows_device_handle_priv *handle_priv = __device_handle_priv(dev_handle);
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
HANDLE winusb_handle = handle_priv->interface_handle[iface].api_handle;
UCHAR policy;
ULONG timeout = 0;
@@ -2481,8 +2481,8 @@ static int winusb_configure_endpoints(struct libusb_device_handle *dev_handle, i
static int winusb_claim_interface(struct libusb_device_handle *dev_handle, int iface)
{
struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev);
- struct windows_device_handle_priv *handle_priv = __device_handle_priv(dev_handle);
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
bool is_using_usbccgp = (priv->apib->id == USB_API_COMPOSITE);
HANDLE file_handle, winusb_handle;
@@ -2554,7 +2554,7 @@ static int winusb_claim_interface(struct libusb_device_handle *dev_handle, int i
static int winusb_release_interface(struct libusb_device_handle *dev_handle, int iface)
{
- struct windows_device_handle_priv *handle_priv = __device_handle_priv(dev_handle);
+ struct windows_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
HANDLE winusb_handle;
CHECK_WINUSB_AVAILABLE;
@@ -2575,7 +2575,7 @@ static int winusb_release_interface(struct libusb_device_handle *dev_handle, int
*/
static int winusb_get_valid_interface(struct libusb_device_handle *dev_handle)
{
- struct windows_device_handle_priv *handle_priv = __device_handle_priv(dev_handle);
+ struct windows_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
int i;
for (i=0; i<USB_MAXINTERFACES; i++) {
@@ -2614,11 +2614,11 @@ static int interface_by_endpoint(struct windows_device_priv *priv,
static int winusb_submit_control_transfer(struct usbi_transfer *itransfer)
{
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct libusb_context *ctx = DEVICE_CTX(transfer->dev_handle->dev);
- struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(transfer->dev_handle->dev);
struct windows_transfer_priv *transfer_priv = (struct windows_transfer_priv*)usbi_transfer_get_os_priv(itransfer);
- struct windows_device_handle_priv *handle_priv = __device_handle_priv(
+ struct windows_device_handle_priv *handle_priv = _device_handle_priv(
transfer->dev_handle);
WINUSB_SETUP_PACKET *setup = (WINUSB_SETUP_PACKET *) transfer->buffer;
ULONG size;
@@ -2688,7 +2688,7 @@ static int winusb_submit_control_transfer(struct usbi_transfer *itransfer)
static int winusb_set_interface_altsetting(struct libusb_device_handle *dev_handle, int iface, int altsetting)
{
struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev);
- struct windows_device_handle_priv *handle_priv = __device_handle_priv(dev_handle);
+ struct windows_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
HANDLE winusb_handle;
CHECK_WINUSB_AVAILABLE;
@@ -2713,11 +2713,11 @@ static int winusb_set_interface_altsetting(struct libusb_device_handle *dev_hand
static int winusb_submit_bulk_transfer(struct usbi_transfer *itransfer)
{
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct libusb_context *ctx = DEVICE_CTX(transfer->dev_handle->dev);
struct windows_transfer_priv *transfer_priv = (struct windows_transfer_priv*)usbi_transfer_get_os_priv(itransfer);
- struct windows_device_handle_priv *handle_priv = __device_handle_priv(transfer->dev_handle);
- struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev);
+ struct windows_device_handle_priv *handle_priv = _device_handle_priv(transfer->dev_handle);
+ struct windows_device_priv *priv = _device_priv(transfer->dev_handle->dev);
HANDLE winusb_handle;
bool direction_in, ret;
int current_interface;
@@ -2771,8 +2771,8 @@ static int winusb_submit_bulk_transfer(struct usbi_transfer *itransfer)
static int winusb_clear_halt(struct libusb_device_handle *dev_handle, unsigned char endpoint)
{
struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev);
- struct windows_device_handle_priv *handle_priv = __device_handle_priv(dev_handle);
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
HANDLE winusb_handle;
int current_interface;
@@ -2809,9 +2809,9 @@ static int winusb_abort_control(struct usbi_transfer *itransfer)
static int winusb_abort_transfers(struct usbi_transfer *itransfer)
{
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct libusb_context *ctx = DEVICE_CTX(transfer->dev_handle->dev);
- struct windows_device_handle_priv *handle_priv = __device_handle_priv(transfer->dev_handle);
+ struct windows_device_handle_priv *handle_priv = _device_handle_priv(transfer->dev_handle);
struct windows_transfer_priv *transfer_priv = usbi_transfer_get_os_priv(itransfer);
HANDLE winusb_handle;
int current_interface;
@@ -2847,8 +2847,8 @@ static int winusb_abort_transfers(struct usbi_transfer *itransfer)
static int winusb_reset_device(struct libusb_device_handle *dev_handle)
{
struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev);
- struct windows_device_handle_priv *handle_priv = __device_handle_priv(dev_handle);
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
struct winfd wfd;
HANDLE winusb_handle;
int i, j;
@@ -2912,7 +2912,7 @@ static int composite_exit(void)
static int composite_open(struct libusb_device_handle *dev_handle)
{
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
unsigned api;
int r;
uint8_t flag = 1<<USB_API_WINUSB;
@@ -2931,7 +2931,7 @@ static int composite_open(struct libusb_device_handle *dev_handle)
static void composite_close(struct libusb_device_handle *dev_handle)
{
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
unsigned api;
uint8_t flag = 1<<USB_API_WINUSB;
@@ -2945,27 +2945,27 @@ static void composite_close(struct libusb_device_handle *dev_handle)
static int composite_claim_interface(struct libusb_device_handle *dev_handle, int iface)
{
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
return priv->usb_interface[iface].apib->claim_interface(dev_handle, iface);
}
static int composite_set_interface_altsetting(struct libusb_device_handle *dev_handle, int iface, int altsetting)
{
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
return priv->usb_interface[iface].apib->set_interface_altsetting(dev_handle, iface, altsetting);
}
static int composite_release_interface(struct libusb_device_handle *dev_handle, int iface)
{
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
return priv->usb_interface[iface].apib->release_interface(dev_handle, iface);
}
static int composite_submit_control_transfer(struct usbi_transfer *itransfer)
{
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct libusb_context *ctx = DEVICE_CTX(transfer->dev_handle->dev);
- struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(transfer->dev_handle->dev);
int i;
for (i=0; i<USB_MAXINTERFACES; i++) {
@@ -2980,10 +2980,10 @@ static int composite_submit_control_transfer(struct usbi_transfer *itransfer)
}
static int composite_submit_bulk_transfer(struct usbi_transfer *itransfer) {
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct libusb_context *ctx = DEVICE_CTX(transfer->dev_handle->dev);
- struct windows_device_handle_priv *handle_priv = __device_handle_priv(transfer->dev_handle);
- struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev);
+ struct windows_device_handle_priv *handle_priv = _device_handle_priv(transfer->dev_handle);
+ struct windows_device_priv *priv = _device_priv(transfer->dev_handle->dev);
int current_interface;
current_interface = interface_by_endpoint(priv, handle_priv, transfer->endpoint);
@@ -2996,10 +2996,10 @@ static int composite_submit_bulk_transfer(struct usbi_transfer *itransfer) {
}
static int composite_submit_iso_transfer(struct usbi_transfer *itransfer) {
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct libusb_context *ctx = DEVICE_CTX(transfer->dev_handle->dev);
- struct windows_device_handle_priv *handle_priv = __device_handle_priv(transfer->dev_handle);
- struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev);
+ struct windows_device_handle_priv *handle_priv = _device_handle_priv(transfer->dev_handle);
+ struct windows_device_priv *priv = _device_priv(transfer->dev_handle->dev);
int current_interface;
current_interface = interface_by_endpoint(priv, handle_priv, transfer->endpoint);
@@ -3014,8 +3014,8 @@ static int composite_submit_iso_transfer(struct usbi_transfer *itransfer) {
static int composite_clear_halt(struct libusb_device_handle *dev_handle, unsigned char endpoint)
{
struct libusb_context *ctx = DEVICE_CTX(dev_handle->dev);
- struct windows_device_handle_priv *handle_priv = __device_handle_priv(dev_handle);
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_handle_priv *handle_priv = _device_handle_priv(dev_handle);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
int current_interface;
current_interface = interface_by_endpoint(priv, handle_priv, endpoint);
@@ -3029,25 +3029,25 @@ static int composite_clear_halt(struct libusb_device_handle *dev_handle, unsigne
static int composite_abort_control(struct usbi_transfer *itransfer)
{
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct windows_transfer_priv *transfer_priv = usbi_transfer_get_os_priv(itransfer);
- struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(transfer->dev_handle->dev);
return priv->usb_interface[transfer_priv->interface_number].apib->abort_control(itransfer);
}
static int composite_abort_transfers(struct usbi_transfer *itransfer)
{
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct windows_transfer_priv *transfer_priv = usbi_transfer_get_os_priv(itransfer);
- struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(transfer->dev_handle->dev);
return priv->usb_interface[transfer_priv->interface_number].apib->abort_transfers(itransfer);
}
static int composite_reset_device(struct libusb_device_handle *dev_handle)
{
- struct windows_device_priv *priv = __device_priv(dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(dev_handle->dev);
unsigned api;
int r;
uint8_t flag = 1<<USB_API_WINUSB;
@@ -3066,9 +3066,9 @@ static int composite_reset_device(struct libusb_device_handle *dev_handle)
static int composite_copy_transfer_data(struct usbi_transfer *itransfer, uint32_t io_size)
{
- struct libusb_transfer *transfer = __USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
struct windows_transfer_priv *transfer_priv = usbi_transfer_get_os_priv(itransfer);
- struct windows_device_priv *priv = __device_priv(transfer->dev_handle->dev);
+ struct windows_device_priv *priv = _device_priv(transfer->dev_handle->dev);
return priv->usb_interface[transfer_priv->interface_number].apib->copy_transfer_data(itransfer, io_size);
}
diff --git a/libusb/os/windows_usb.h b/libusb/os/windows_usb.h
index 118e088..e74f82d 100644
--- a/libusb/os/windows_usb.h
+++ b/libusb/os/windows_usb.h
@@ -170,12 +170,12 @@ struct windows_device_priv {
unsigned char **config_descriptor; // list of pointers to the cached config descriptors
};
-static inline struct windows_device_priv *__device_priv(struct libusb_device *dev) {
+static inline struct windows_device_priv *_device_priv(struct libusb_device *dev) {
return (struct windows_device_priv *)dev->os_priv;
}
static inline void windows_device_priv_init(libusb_device* dev) {
- struct windows_device_priv* p = __device_priv(dev);
+ struct windows_device_priv* p = _device_priv(dev);
int i;
p->depth = 0;
p->port = 0;
@@ -195,7 +195,7 @@ static inline void windows_device_priv_init(libusb_device* dev) {
}
static inline void windows_device_priv_release(libusb_device* dev) {
- struct windows_device_priv* p = __device_priv(dev);
+ struct windows_device_priv* p = _device_priv(dev);
int i;
safe_free(p->path);
if ((dev->num_configurations > 0) && (p->config_descriptor != NULL)) {
@@ -222,7 +222,7 @@ struct windows_device_handle_priv {
#endif
};
-static inline struct windows_device_handle_priv *__device_handle_priv(
+static inline struct windows_device_handle_priv *_device_handle_priv(
struct libusb_device_handle *handle)
{
return (struct windows_device_handle_priv *) handle->os_priv;
@@ -347,7 +347,7 @@ typedef RETURN_TYPE CONFIGRET;
((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))
#endif
-typedef enum _USB_CONNECTION_STATUS {
+typedef enum USB_CONNECTION_STATUS {
NoDeviceConnected,
DeviceConnected,
DeviceFailedEnumeration,
@@ -359,7 +359,7 @@ typedef enum _USB_CONNECTION_STATUS {
DeviceInLegacyHub
} USB_CONNECTION_STATUS, *PUSB_CONNECTION_STATUS;
-typedef enum _USB_HUB_NODE {
+typedef enum USB_HUB_NODE {
UsbHub,
UsbMIParent
} USB_HUB_NODE;
@@ -397,7 +397,7 @@ DLL_DECLARE(WINAPI, CONFIGRET, CM_Get_Device_IDA, (DEVINST, PCHAR, ULONG, ULONG)
// Most of the structures below need to be packed
#pragma pack(push, 1)
-typedef struct _USB_INTERFACE_DESCRIPTOR {
+typedef struct USB_INTERFACE_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
UCHAR bInterfaceNumber;
@@ -409,7 +409,7 @@ typedef struct _USB_INTERFACE_DESCRIPTOR {
UCHAR iInterface;
} USB_INTERFACE_DESCRIPTOR, *PUSB_INTERFACE_DESCRIPTOR;
-typedef struct _USB_CONFIGURATION_DESCRIPTOR {
+typedef struct USB_CONFIGURATION_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
USHORT wTotalLength;
@@ -420,7 +420,7 @@ typedef struct _USB_CONFIGURATION_DESCRIPTOR {
UCHAR MaxPower;
} USB_CONFIGURATION_DESCRIPTOR, *PUSB_CONFIGURATION_DESCRIPTOR;
-typedef struct _USB_CONFIGURATION_DESCRIPTOR_SHORT {
+typedef struct USB_CONFIGURATION_DESCRIPTOR_SHORT {
struct {
ULONG ConnectionIndex;
struct {
@@ -434,7 +434,7 @@ typedef struct _USB_CONFIGURATION_DESCRIPTOR_SHORT {
USB_CONFIGURATION_DESCRIPTOR data;
} USB_CONFIGURATION_DESCRIPTOR_SHORT;
-typedef struct _USB_ENDPOINT_DESCRIPTOR {
+typedef struct USB_ENDPOINT_DESCRIPTOR {
UCHAR bLength;
UCHAR bDescriptorType;
UCHAR bEndpointAddress;
@@ -443,7 +443,7 @@ typedef struct _USB_ENDPOINT_DESCRIPTOR {
UCHAR bInterval;
} USB_ENDPOINT_DESCRIPTOR, *PUSB_ENDPOINT_DESCRIPTOR;
-typedef struct _USB_DESCRIPTOR_REQUEST {
+typedef struct USB_DESCRIPTOR_REQUEST {
ULONG ConnectionIndex;
struct {
UCHAR bmRequest;
@@ -455,7 +455,7 @@ typedef struct _USB_DESCRIPTOR_REQUEST {
// UCHAR Data[0];
} USB_DESCRIPTOR_REQUEST, *PUSB_DESCRIPTOR_REQUEST;
-typedef struct _USB_HUB_DESCRIPTOR {
+typedef struct USB_HUB_DESCRIPTOR {
UCHAR bDescriptorLength;
UCHAR bDescriptorType;
UCHAR bNumberOfPorts;
@@ -465,45 +465,45 @@ typedef struct _USB_HUB_DESCRIPTOR {
UCHAR bRemoveAndPowerMask[64];
} USB_HUB_DESCRIPTOR, *PUSB_HUB_DESCRIPTOR;
-typedef struct _USB_ROOT_HUB_NAME {
+typedef struct USB_ROOT_HUB_NAME {
ULONG ActualLength;
WCHAR RootHubName[1];
} USB_ROOT_HUB_NAME, *PUSB_ROOT_HUB_NAME;
-typedef struct _USB_ROOT_HUB_NAME_FIXED {
+typedef struct USB_ROOT_HUB_NAME_FIXED {
ULONG ActualLength;
WCHAR RootHubName[MAX_PATH_LENGTH];
} USB_ROOT_HUB_NAME_FIXED;
-typedef struct _USB_NODE_CONNECTION_NAME {
+typedef struct USB_NODE_CONNECTION_NAME {
ULONG ConnectionIndex;
ULONG ActualLength;
WCHAR NodeName[1];
} USB_NODE_CONNECTION_NAME, *PUSB_NODE_CONNECTION_NAME;
-typedef struct _USB_NODE_CONNECTION_NAME_FIXED {
+typedef struct USB_NODE_CONNECTION_NAME_FIXED {
ULONG ConnectionIndex;
ULONG ActualLength;
WCHAR NodeName[MAX_PATH_LENGTH];
} USB_NODE_CONNECTION_NAME_FIXED;
-typedef struct _USB_HUB_NAME_FIXED {
+typedef struct USB_HUB_NAME_FIXED {
union {
USB_ROOT_HUB_NAME_FIXED root;
USB_NODE_CONNECTION_NAME_FIXED node;
} u;
} USB_HUB_NAME_FIXED;
-typedef struct _USB_HUB_INFORMATION {
+typedef struct USB_HUB_INFORMATION {
USB_HUB_DESCRIPTOR HubDescriptor;
BOOLEAN HubIsBusPowered;
} USB_HUB_INFORMATION, *PUSB_HUB_INFORMATION;
-typedef struct _USB_MI_PARENT_INFORMATION {
+typedef struct USB_MI_PARENT_INFORMATION {
ULONG NumberOfInterfaces;
} USB_MI_PARENT_INFORMATION, *PUSB_MI_PARENT_INFORMATION;
-typedef struct _USB_NODE_INFORMATION {
+typedef struct USB_NODE_INFORMATION {
USB_HUB_NODE NodeType;
union {
USB_HUB_INFORMATION HubInformation;
@@ -511,12 +511,12 @@ typedef struct _USB_NODE_INFORMATION {
} u;
} USB_NODE_INFORMATION, *PUSB_NODE_INFORMATION;
-typedef struct _USB_PIPE_INFO {
+typedef struct USB_PIPE_INFO {
USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
ULONG ScheduleOffset;
} USB_PIPE_INFO, *PUSB_PIPE_INFO;
-typedef struct _USB_NODE_CONNECTION_INFORMATION_EX {
+typedef struct USB_NODE_CONNECTION_INFORMATION_EX {
ULONG ConnectionIndex;
USB_DEVICE_DESCRIPTOR DeviceDescriptor;
UCHAR CurrentConfigurationValue;
@@ -528,7 +528,7 @@ typedef struct _USB_NODE_CONNECTION_INFORMATION_EX {
// USB_PIPE_INFO PipeList[0];
} USB_NODE_CONNECTION_INFORMATION_EX, *PUSB_NODE_CONNECTION_INFORMATION_EX;
-typedef struct _USB_HUB_CAP_FLAGS {
+typedef struct USB_HUB_CAP_FLAGS {
ULONG HubIsHighSpeedCapable:1;
ULONG HubIsHighSpeed:1;
ULONG HubIsMultiTtCapable:1;
@@ -538,11 +538,11 @@ typedef struct _USB_HUB_CAP_FLAGS {
ULONG ReservedMBZ:26;
} USB_HUB_CAP_FLAGS, *PUSB_HUB_CAP_FLAGS;
-typedef struct _USB_HUB_CAPABILITIES {
+typedef struct USB_HUB_CAPABILITIES {
ULONG HubIs2xCapable : 1;
} USB_HUB_CAPABILITIES, *PUSB_HUB_CAPABILITIES;
-typedef struct _USB_HUB_CAPABILITIES_EX {
+typedef struct USB_HUB_CAPABILITIES_EX {
USB_HUB_CAP_FLAGS CapabilityFlags;
} USB_HUB_CAPABILITIES_EX, *PUSB_HUB_CAPABILITIES_EX;
@@ -565,7 +565,7 @@ typedef struct _USB_HUB_CAPABILITIES_EX {
#define FullSpeed 0x02
#define HighSpeed 0x03
-typedef enum _USBD_PIPE_TYPE {
+typedef enum USBD_PIPE_TYPE {
UsbdPipeTypeControl,
UsbdPipeTypeIsochronous,
UsbdPipeTypeBulk,
diff --git a/libusb/sync.c b/libusb/sync.c
index f6dc2a7..8572c4d 100644
--- a/libusb/sync.c
+++ b/libusb/sync.c
@@ -102,13 +102,13 @@ int API_EXPORTED libusb_control_transfer(libusb_device_handle *dev_handle,
}
while (!completed) {
- r = libusb_handle_events(HANDLE_CTX(dev_handle));
+ r = libusb_handle_events_completed(HANDLE_CTX(dev_handle), &completed);
if (r < 0) {
if (r == LIBUSB_ERROR_INTERRUPTED)
continue;
libusb_cancel_transfer(transfer);
while (!completed)
- if (libusb_handle_events(HANDLE_CTX(dev_handle)) < 0)
+ if (libusb_handle_events_completed(HANDLE_CTX(dev_handle), &completed) < 0)
break;
libusb_free_transfer(transfer);
return r;
@@ -132,6 +132,9 @@ int API_EXPORTED libusb_control_transfer(libusb_device_handle *dev_handle,
case LIBUSB_TRANSFER_NO_DEVICE:
r = LIBUSB_ERROR_NO_DEVICE;
break;
+ case LIBUSB_TRANSFER_OVERFLOW:
+ r = LIBUSB_ERROR_OVERFLOW;
+ break;
default:
usbi_warn(HANDLE_CTX(dev_handle),
"unrecognised status code %d", transfer->status);
@@ -172,13 +175,13 @@ static int do_sync_bulk_transfer(struct libusb_device_handle *dev_handle,
}
while (!completed) {
- r = libusb_handle_events(HANDLE_CTX(dev_handle));
+ r = libusb_handle_events_completed(HANDLE_CTX(dev_handle), &completed);
if (r < 0) {
if (r == LIBUSB_ERROR_INTERRUPTED)
continue;
libusb_cancel_transfer(transfer);
while (!completed)
- if (libusb_handle_events(HANDLE_CTX(dev_handle)) < 0)
+ if (libusb_handle_events_completed(HANDLE_CTX(dev_handle), &completed) < 0)
break;
libusb_free_transfer(transfer);
return r;
diff --git a/libusb/version.h b/libusb/version.h
index 49da538..8cdf16b 100644
--- a/libusb/version.h
+++ b/libusb/version.h
@@ -8,6 +8,11 @@
#ifndef LIBUSB_MICRO
#define LIBUSB_MICRO 8
#endif
+/* LIBUSB_NANO may be used for Windows internal versioning. 0 means unused. */
#ifndef LIBUSB_NANO
#define LIBUSB_NANO 10347
#endif
+/* LIBUSB_RC is the release candidate suffix. Should normally be empty. */
+#ifndef LIBUSB_RC
+#define LIBUSB_RC ""
+#endif
diff --git a/msvc/config.h b/msvc/config.h
index 0430858..61ad632 100644
--- a/msvc/config.h
+++ b/msvc/config.h
@@ -18,7 +18,7 @@
#define ENABLE_LOGGING 1
/* Windows backend */
-#define OS_WINDOWS /**/
+#define OS_WINDOWS 1
/* type of second poll() argument */
#define POLL_NFDS_TYPE unsigned int