platform/upstream/libusb.git
8 years agodarwin: fix 1 compiler warning
Ludovic Rousseau [Sat, 27 Feb 2016 16:42:55 +0000 (17:42 +0100)]
darwin: fix 1 compiler warning

os/darwin_usb.c:248:18: warning: comparison of integers of different signs:
      'CFIndex' (aka 'long') and 'size_t' (aka 'unsigned long')
      [-Wsign-compare]
      if (length < size) {
          ~~~~~~ ^ ~~~~

Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
8 years agocore: fix 2 compiler warnings
Ludovic Rousseau [Sat, 27 Feb 2016 16:37:49 +0000 (17:37 +0100)]
core: fix 2 compiler warnings

core.c:2361:35: warning: comparison of integers of different signs: 'int' and
      'unsigned long' [-Wsign-compare]
        if (header_len < 0 || header_len >= sizeof(buf)) {
                              ~~~~~~~~~~ ^  ~~~~~~~~~~~
core.c:2370:44: warning: comparison of integers of different signs: 'int' and
      'unsigned long' [-Wsign-compare]
        if (text_len < 0 || text_len + header_len >= sizeof(buf)) {
                            ~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~~

Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
8 years agoREADME.md: add Coverity badge
Ludovic Rousseau [Wed, 2 Mar 2016 13:12:04 +0000 (14:12 +0100)]
README.md: add Coverity badge

The libusb project is available on Coverity at https://scan.coverity.com/projects/libusb-libusb

Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
8 years agoWindows: Fix faulty logic that can pick the wrong config descriptor
Chris Dickens [Wed, 2 Mar 2016 08:16:16 +0000 (00:16 -0800)]
Windows: Fix faulty logic that can pick the wrong config descriptor

The WinUSB backend caches the bConfigurationValue of the currently
active configuration when the device is enumerated. In some parts of
the code, the config descriptor is fetched to correlate interfaces
and endpoints by calling libusb_get_config_descriptor() using the
cached bConfigurationValue. This is incorrect usage of the function
as the input parameter is the zero-based configuration index, which
can differ in some devices from the bConfigurationValue.

See discussion: http://marc.info/?l=libusb-devel&m=144355607228333

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows: Add backend support for get_config_descriptor_by_value()
Chris Dickens [Wed, 2 Mar 2016 08:14:50 +0000 (00:14 -0800)]
Windows: Add backend support for get_config_descriptor_by_value()

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows: Fix dev_interface_path memory leak when reusing device ref
Angus Gratton [Tue, 28 Apr 2015 06:49:57 +0000 (16:49 +1000)]
Windows: Fix dev_interface_path memory leak when reusing device ref

windows_get_device_list was leaking dev_interface_path (in either of two
possible places) when a pre-existing device reference was reused.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows: Fix parent USB device reference leak
Angus Gratton [Tue, 28 Apr 2015 06:46:37 +0000 (16:46 +1000)]
Windows: Fix parent USB device reference leak

If windows_get_device_list() found a device that already existed, it
would erronenously increment the parent_dev refcount and cause a
reference leak - the parent device would never be released.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agobootstrap: use autoreconf
Nathan Hjelm [Thu, 25 Feb 2016 20:35:36 +0000 (13:35 -0700)]
bootstrap: use autoreconf

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
8 years agotravis: one more fix. need packages under apt
Nathan Hjelm [Fri, 26 Feb 2016 04:51:10 +0000 (21:51 -0700)]
travis: one more fix. need packages under apt

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
8 years agotravis: sources line is needed
Nathan Hjelm [Fri, 26 Feb 2016 04:45:15 +0000 (21:45 -0700)]
travis: sources line is needed

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
8 years agotravis: bah. remove tabs
Nathan Hjelm [Fri, 26 Feb 2016 04:40:30 +0000 (21:40 -0700)]
travis: bah. remove tabs

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
8 years agotravis: use addons to install packages
Nathan Hjelm [Fri, 26 Feb 2016 04:36:26 +0000 (21:36 -0700)]
travis: use addons to install packages

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
8 years agoMisc: Link README to README.md to satisfy autotools
Chris Dickens [Thu, 25 Feb 2016 22:13:43 +0000 (14:13 -0800)]
Misc: Link README to README.md to satisfy autotools

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoMisc: Add markdown references for COPYING and PORTING files
Chris Dickens [Thu, 25 Feb 2016 21:53:05 +0000 (13:53 -0800)]
Misc: Add markdown references for COPYING and PORTING files

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoMisc: Convert README to README.md
Chris Dickens [Thu, 25 Feb 2016 21:49:16 +0000 (13:49 -0800)]
Misc: Convert README to README.md

This allows markdown, including displaying Travis build status.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoMerge pull request #154 from hjelmn/darwin_gettime_fix
Nathan Hjelm [Thu, 25 Feb 2016 20:39:46 +0000 (13:39 -0700)]
Merge pull request #154 from hjelmn/darwin_gettime_fix

threads_posix: use backend clock_gettime()

8 years agotravis: test xcode project
Nathan Hjelm [Thu, 25 Feb 2016 20:23:19 +0000 (13:23 -0700)]
travis: test xcode project

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
8 years agothreads_posix: use backend clock_gettime()
Nathan Hjelm [Thu, 25 Feb 2016 17:05:49 +0000 (10:05 -0700)]
threads_posix: use backend clock_gettime()

Some platforms do not implement the optional clock_gettime(). Need
to use the backend implementation instead.

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
8 years agotravis: Add sudo to apt-get commands
Chris Dickens [Thu, 25 Feb 2016 18:56:16 +0000 (10:56 -0800)]
travis: Add sudo to apt-get commands

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agotravis: Update config file
Chris Dickens [Thu, 25 Feb 2016 18:25:19 +0000 (10:25 -0800)]
travis: Update config file

Use 'script' instead of 'install' to specify build command.
Add linux build option with udev disabled.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agotravis: fix typo
Nathan Hjelm [Thu, 25 Feb 2016 17:25:07 +0000 (10:25 -0700)]
travis: fix typo

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
8 years agotravis: ensure udev is installed
Nathan Hjelm [Thu, 25 Feb 2016 17:12:55 +0000 (10:12 -0700)]
travis: ensure udev is installed

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
8 years agoAdd Travis CI configuration
Nathan Hjelm [Thu, 25 Feb 2016 16:55:25 +0000 (09:55 -0700)]
Add Travis CI configuration

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
8 years agocore: Remove POSIX threads influence from synchronization code
Chris Dickens [Sat, 30 Jan 2016 10:24:39 +0000 (02:24 -0800)]
core: Remove POSIX threads influence from synchronization code

This commit changes the signatures of the synchronization functions
to reflect the needs of the library rather than the signature of the
pthreads API. The mutex and condition variable attributes parameters
have been removed as no part of the core library makes use of them.

In addition, the condition variable timed-wait function has been modified
to accept the relative time passed in via libusb_wait_for_event(). This
allows the implementation-specific code to handle conversion to absolute
time as necessary, rather than forcing this to occur.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoMisc: Remove unused definitions for usbi_cond_signal()
Chris Dickens [Sat, 30 Jan 2016 10:24:38 +0000 (02:24 -0800)]
Misc: Remove unused definitions for usbi_cond_signal()

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoMisc: Document the return code for control transfers that are too large
Chris Dickens [Wed, 24 Feb 2016 09:50:40 +0000 (01:50 -0800)]
Misc: Document the return code for control transfers that are too large

Closes #110

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoMisc: Add libusb_interrupt_event_handler() to API docs page
Chris Dickens [Wed, 24 Feb 2016 09:21:52 +0000 (01:21 -0800)]
Misc: Add libusb_interrupt_event_handler() to API docs page

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoMisc: Prefix doxygen references in order to namespace libusb
Chris Dickens [Wed, 24 Feb 2016 09:07:20 +0000 (01:07 -0800)]
Misc: Prefix doxygen references in order to namespace libusb

This change add "libusb_" to every group and page definition (and
updates all references accordingly) so that generated man pages
are namespaced for libusb, thus avoiding possible conflict with
other packages.

Closes #131

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoMisc: Make API parameter names consistent and sensible
Chris Dickens [Wed, 24 Feb 2016 08:23:49 +0000 (00:23 -0800)]
Misc: Make API parameter names consistent and sensible

Prior to this commit, API functions taking a libusb_device_handle
argument had the parameter named dev, handle, or dev_handle. This
commit changes the name of all libusb_device_handle parameters to
dev_handle in both the documentation and actual code.

Closes #132

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agosync: Allow transferred argument to be optional in bulk APIs
Chris Dickens [Wed, 24 Feb 2016 07:45:51 +0000 (23:45 -0800)]
sync: Allow transferred argument to be optional in bulk APIs

Closes #139

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agowindows: Fix compilation for MSYS2
Evan Hunter [Fri, 8 Jan 2016 13:53:42 +0000 (13:53 +0000)]
windows: Fix compilation for MSYS2

Closes #140

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agolinux_netlink: Add message authentication and clean up parsing
Chris Dickens [Thu, 28 Jan 2016 22:29:42 +0000 (14:29 -0800)]
linux_netlink: Add message authentication and clean up parsing

This commit adds credentials checking to ensure that we only process
messages received from the kernel. In addition, the parsing logic
was cleaned up and slightly optimized.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agolinux_netlink: Add useful debug messages and clean up error handling
Chris Dickens [Thu, 28 Jan 2016 22:24:09 +0000 (14:24 -0800)]
linux_netlink: Add useful debug messages and clean up error handling

Also addresses some minor whitespace and stylistic issues.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agolinux_netlink: Remove unnecessary header includes and conditionals
Chris Dickens [Thu, 28 Jan 2016 22:15:29 +0000 (14:15 -0800)]
linux_netlink: Remove unnecessary header includes and conditionals

We always require <sys/socket.h> and do not need <linux/filter.h>.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows: Fix style issues in threading code
Chris Dickens [Sat, 30 Jan 2016 08:52:28 +0000 (00:52 -0800)]
Windows: Fix style issues in threading code

Also moves private structure definition outside of header file.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows: Move definitions for Cygwin.
KIMURA Masaru [Thu, 28 Jan 2016 07:25:37 +0000 (16:25 +0900)]
Windows: Move definitions for Cygwin.

Closes #145

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows (winusb): Fix build break introduced in c8f71151 due to typo
Chris Dickens [Thu, 28 Jan 2016 08:43:15 +0000 (00:43 -0800)]
Windows (winusb): Fix build break introduced in c8f71151 due to typo

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoMisc: Minor stylistic improvements to libusbi.h
Chris Dickens [Thu, 28 Jan 2016 08:41:02 +0000 (00:41 -0800)]
Misc: Minor stylistic improvements to libusbi.h

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows/WinCE: Improve the run-time dynamic linking scheme
Chris Dickens [Thu, 28 Jan 2016 08:29:58 +0000 (00:29 -0800)]
Windows/WinCE: Improve the run-time dynamic linking scheme

Prior to this commit, the Windows and WinCE backends had a specific
shortcoming when loading DLLs, that being that once loaded they were
never unloaded. This commit improves this by providing a means to
unload the DLLs during cleanup.

Note that the use of GetModuleHandle() has been removed in favor of
the exclusive use of LoadLibrary(). This was done to ensure that a
reference count is taken against the loaded DLL, which guards against
some other part of the application unloading the DLL that libusb
is currently using.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows: Fix some minor issues in windows_nt_common.c
Chris Dickens [Thu, 28 Jan 2016 08:22:09 +0000 (00:22 -0800)]
Windows: Fix some minor issues in windows_nt_common.c

1) Address a few more stylistic discrepancies
2) Add appropriate type casts for printf functions

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWinCE: Remove unnecessary/unused structure
Chris Dickens [Thu, 28 Jan 2016 08:20:00 +0000 (00:20 -0800)]
WinCE: Remove unnecessary/unused structure

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWinCE: Miscellaneous changes
Chris Dickens [Thu, 28 Jan 2016 08:15:59 +0000 (00:15 -0800)]
WinCE: Miscellaneous changes

1) Make some variables static that are not used outside wince_usb.c
2) Minor stylistic changes to match the rest of the library source

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows: Ensure proper cleanup when backend init() functions fail
Chris Dickens [Wed, 27 Jan 2016 19:46:01 +0000 (11:46 -0800)]
Windows: Ensure proper cleanup when backend init() functions fail

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows: Fix DDK compilation
Pete Batard [Wed, 27 Jan 2016 19:24:13 +0000 (19:24 +0000)]
Windows: Fix DDK compilation

8 years agoWindows: Minor improvements to windows_nt_common.c
Chris Dickens [Wed, 27 Jan 2016 09:25:49 +0000 (01:25 -0800)]
Windows: Minor improvements to windows_nt_common.c

1) Possible memory leak is avoided if htab_create() is called
   while a hash table is already allocated
2) Error handling is simplified in windows_handle_events()

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows: Replace open-coded string alloc + copy with _strdup()
Chris Dickens [Wed, 27 Jan 2016 09:00:55 +0000 (01:00 -0800)]
Windows: Replace open-coded string alloc + copy with _strdup()

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows: Fix compilation warnings when logging is disabled
Chris Dickens [Wed, 27 Jan 2016 08:33:42 +0000 (00:33 -0800)]
Windows: Fix compilation warnings when logging is disabled

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows (usbdk): Remove unnecessary bookkeeping
Chris Dickens [Wed, 27 Jan 2016 08:27:27 +0000 (00:27 -0800)]
Windows (usbdk): Remove unnecessary bookkeeping

The core library will not call the backend's exit() function if the
init() function does not succeed, so keeping track of whether init()
successfully completed is redundant.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows (usbdk): Remove unnecessary/unused structure
Chris Dickens [Wed, 27 Jan 2016 08:25:25 +0000 (00:25 -0800)]
Windows (usbdk): Remove unnecessary/unused structure

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoMisc: Fix up Visual Studio project files
Chris Dickens [Wed, 27 Jan 2016 08:15:11 +0000 (00:15 -0800)]
Misc: Fix up Visual Studio project files

This commit sorts the source and header files by name (for easier
human parsing), adds windows_nt_common.c to the 2010 and 2012
projects, and removes some CPP defines that should not be present
in the libusb_static_2015.vcxproj file.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows: Source file cleanup
Chris Dickens [Wed, 27 Jan 2016 07:40:33 +0000 (23:40 -0800)]
Windows: Source file cleanup

This commit addresses a few different issues:

1) Whitespace made consistent with the rest of the library source
2) Formatting of function and variable declarations made consistent
   with the rest of the library source
3) Functions and variables made static where possible
4) Definitions in header files moved if not used publicly

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoMisc: Minor makefile cleanup
Chris Dickens [Sun, 24 Jan 2016 07:08:09 +0000 (23:08 -0800)]
Misc: Minor makefile cleanup

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agobuild: Integrate usbdk backend
Dmitry Fleytman [Wed, 20 Jan 2016 15:05:55 +0000 (17:05 +0200)]
build: Integrate usbdk backend

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agousbdk: Introduce usbdk backend
Dmitry Fleytman [Wed, 20 Jan 2016 15:05:54 +0000 (17:05 +0200)]
usbdk: Introduce usbdk backend

Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agowindows: Rename windows_usb.h/c windows_winusb.h/c
Dmitry Fleytman [Wed, 20 Jan 2016 15:05:53 +0000 (17:05 +0200)]
windows: Rename windows_usb.h/c windows_winusb.h/c

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agowindows: Move common definitions to a separate file
Dmitry Fleytman [Wed, 20 Jan 2016 15:05:52 +0000 (17:05 +0200)]
windows: Move common definitions to a separate file

New files windows_nt_common.h/c introduced.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agolinux: Correctly return device configuration when using usbfs
Chris Dickens [Wed, 6 Jan 2016 17:57:15 +0000 (09:57 -0800)]
linux: Correctly return device configuration when using usbfs

libusb_get_configuration() has been broken when using a Linux kernel
that requires the use of usbfs to obtain the current configuration
value. This commit resolves this issue and also modifies the
usbfs_get_active_config() function to update the cached active
configuration value itself instead of requiring the callers to do it.

Closes #137

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWinCE: Fix printf format specifiers
Chris Dickens [Thu, 7 Jan 2016 06:17:22 +0000 (22:17 -0800)]
WinCE: Fix printf format specifiers

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows: Fix printf format specifiers in poll_windows.c
Chris Dickens [Thu, 7 Jan 2016 06:16:58 +0000 (22:16 -0800)]
Windows: Fix printf format specifiers in poll_windows.c

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows: Fix compiler warnings due to type mismatches
Chris Dickens [Thu, 7 Jan 2016 06:16:26 +0000 (22:16 -0800)]
Windows: Fix compiler warnings due to type mismatches

There are some differences in how the DWORD type is defined between
native Windwos compilers and Cygwin where the former always uses long
and the latter uses long or int depending on the architecture. Since
the DWORD type is always 4 bytes, all uses of DWORD in printf are
cast to unsigned int, which consistently 4 bytes across all platforms.
Other mismatching printf format specifiers were also changed appropriately.

Additionally, a type cast is added for _beginthreadex on Cygwin.

Closes #106

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows: Use strcasecmp() instead of stricmp() on Cygwin
Chris Dickens [Thu, 7 Jan 2016 05:52:36 +0000 (21:52 -0800)]
Windows: Use strcasecmp() instead of stricmp() on Cygwin

Cygwin does not define the latter in all versions, so this commit
uses the former POSIX function that Cygwin does provide.

Closes #104

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoExamples: fix typo in Nathan Hjelm email
Ludovic Rousseau [Wed, 6 Jan 2016 09:20:24 +0000 (10:20 +0100)]
Examples: fix typo in Nathan Hjelm email

8 years agoWindows: Add Visual Studio 2015 support
Brent Rector [Sat, 25 Jul 2015 08:36:56 +0000 (01:36 -0700)]
Windows: Add Visual Studio 2015 support

Modified from original to remove two unnecessary files and address
type-casting discrepancies across platforms.

Closes #60
Closes #83
Closes #120

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows: Patch to support VirtualHub
johannrichard [Tue, 22 Dec 2015 16:01:54 +0000 (17:01 +0100)]
Windows: Patch to support VirtualHub

Integrate VirtualHub (VHHUB) in LibUSB, as per
http://libusb.6.n5.nabble.com/libusb-Patch-to-support-VirtualHere-td5714167.html

Closes #133

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoMisc: Spelling fixes
Tobias Klauser [Fri, 25 Sep 2015 11:50:35 +0000 (13:50 +0200)]
Misc: Spelling fixes

Fix spelling errors found by codespell, some of them in API
documentation and user visible messages.

Closes #102

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoMisc: Simplify Haiku build and fix broken parallel build
Chris Dickens [Thu, 3 Dec 2015 20:59:20 +0000 (12:59 -0800)]
Misc: Simplify Haiku build and fix broken parallel build

The Haiku build was previously being done as a nested package
due to its C++ requirement, but for some reason setting SUBDIR
in an automake conditional breaks parallel builds. To fix this
and simplify the Haiku build process, this commit adds an
unconditional check for a C++ compiler using AC_PROG_CXX and
builds the Haiku sources as part of the main libusb project.

Note that AC_PROG_CXX itself does not cause the configure script
to fail if a C++ compiler is not found. Therefore on non-Haiku
platforms there is no requirement to have a C++ compiler installed
in order to build libusb.

Closes #121

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoAPI: Add libusb_interrupt_event_handler() function
Chris Dickens [Thu, 10 Dec 2015 08:20:18 +0000 (00:20 -0800)]
API: Add libusb_interrupt_event_handler() function

This new function will allow the user to purposely interrupt an
event handling thread, causing it to return from the event handling
function. This is mainly useful for cleanly exiting from a dedicated
event handling thread during application shutdown.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agocore: Store different event types as a bitmask within the context
Chris Dickens [Thu, 10 Dec 2015 07:45:21 +0000 (23:45 -0800)]
core: Store different event types as a bitmask within the context

This change introduces a new event_flags member to the libusb_context
that holds a bitmask of different events that have occurred. This will
allow multiple "one-shot" events (those that don't require counting) to
be stored in a single variable. The only existing event of this type,
pollfds_modified, has been converted to use this bitmask instead.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agodarwin: updates to support el capitan
Nathan Hjelm [Sat, 21 Nov 2015 17:30:23 +0000 (10:30 -0700)]
darwin: updates to support el capitan

With the new USB stack Apple changed the underlying device class from
IOUSBDevice to IOUSBHostDevice. Additionally, they removed the PortNum
property from the IO registry entry. This commit add code to detect the
currently running xnu version. If the version is at least 15 (10.11.0)
the new device class is used to find usb devices and the port number
is read from the IOService parent of the USB device instead of the
PortNum property.

Closes #127

May have some effect on either #123 or #96.

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
8 years agodarwin: ignore root hub simulation devices
Nathan Hjelm [Fri, 9 Oct 2015 19:25:24 +0000 (13:25 -0600)]
darwin: ignore root hub simulation devices

This commit fixes #108. In the 10.11.0 release it can take up to 1
second to query the configuration of one of Apple's root hub
simulation devices. Since the devices are not usable anyway go ahead
and mark them as unconfigured.

Signed-off-by: Nathan Hjelm <hjelmn@me.com>
8 years agocore: Prevent attempts to recursively hande events
Chris Dickens [Thu, 10 Sep 2015 09:39:20 +0000 (02:39 -0700)]
core: Prevent attempts to recursively hande events

Prior to this commit, it was possible to call certain functions from
within a hotplug or transfer completion callback that would in turn
attempt to handle events (e.g. any of the sync transfer APIs). This
is dangerous because certain events may cause the nested calls to
free memory that is currently in use by the previous calls.

This implementation uses thread-local storage to store a key within
the context that is set to a non-NULL value whenever event handling
is occurring. This allows us to detect when dangerous calls are made
from within event handling context. Such calls will return an error
code of LIBUSB_ERROR_BUSY.

Note that this implementation was chosen because of its portability.
It is supported on all platforms that libusb supports.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows: Fix potential memory leak
Chris Dickens [Sun, 20 Sep 2015 22:24:05 +0000 (15:24 -0700)]
Windows: Fix potential memory leak

The windows_assign_endpoints() function does not free the config
descriptor before returning in two cases.

Issue reported by dmitrykos <dmitrykos@neutroncode.com>

Closes #98

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoMiscellaneous fixes
Tobias Klauser [Tue, 14 Apr 2015 15:43:05 +0000 (17:43 +0200)]
Miscellaneous fixes

* Use UNUSED macro instead of open coding it
* Use calloc to allocate and zero out buffers where appropriate
* Make unnecessarily global variables static
* Use strdup() instead of open-coding it
* Use passed fd in set_fd_cloexec_nb()
* Remove unused parameter from linux_device_disconnected()
* Closes #65

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agolinux_usbfs: Add support for kernels that can reap after disconnect
Chris Dickens [Fri, 18 Sep 2015 05:27:22 +0000 (22:27 -0700)]
linux_usbfs: Add support for kernels that can reap after disconnect

For kernels that support the REAP_AFTER_DISCONNECT capability, it is
no longer necessary to use the nasty workaround that is the
usbi_handle_disconnect() function. All transfers can be properly
reaped as one would expect and will have an appropriate URB status.

Note that moving usbi_handle_disconnect() after the hotplug section
is fine because the hotplug disconnect message simply gets added to
the hotplug_msgs list to be processed the next time handle_events()
is called.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agolinux_usbfs: Avoid file descriptor leak in error case
Chris Dickens [Fri, 18 Sep 2015 05:27:21 +0000 (22:27 -0700)]
linux_usbfs: Avoid file descriptor leak in error case

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agolinux: Filter hotplug events by DEVTYPE of "usb_device"
Chris Dickens [Fri, 18 Sep 2015 05:27:20 +0000 (22:27 -0700)]
linux: Filter hotplug events by DEVTYPE of "usb_device"

Many different hotplug events can occur for the "usb" subsystem
(e.g. attaching/detaching a class driver), but libusb only needs
to care about events where the device type is "usb_device". All
other events cause needless attempts to lookup the device address,
which will fail as the paths for such events do not correspond to
actual USB device nodes.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agolinux_usbfs: Only remove the device fd from the pollfd list once
Chris Dickens [Fri, 18 Sep 2015 05:27:19 +0000 (22:27 -0700)]
linux_usbfs: Only remove the device fd from the pollfd list once

If the file descriptor gets removed because POLLERR has been
detected, do not attempt to remove it again when closing the device.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoDocs: Add missing functions to API page
Chris Dickens [Mon, 14 Sep 2015 05:43:55 +0000 (22:43 -0700)]
Docs: Add missing functions to API page

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows: Regenerate libusb-1.0.def file from latest DLL
Chris Dickens [Mon, 14 Sep 2015 05:37:30 +0000 (22:37 -0700)]
Windows: Regenerate libusb-1.0.def file from latest DLL

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agolibusb 1.0.20
Chris Dickens [Mon, 14 Sep 2015 00:37:12 +0000 (17:37 -0700)]
libusb 1.0.20

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agolibusb 1.0.20-rc3
Chris Dickens [Sat, 5 Sep 2015 17:33:07 +0000 (10:33 -0700)]
libusb 1.0.20-rc3

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agocore: Add RC string to libusb version message
Chris Dickens [Sat, 5 Sep 2015 17:31:45 +0000 (10:31 -0700)]
core: Add RC string to libusb version message

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows: Fix some build warnings/link issues
Chris Dickens [Sat, 5 Sep 2015 17:23:38 +0000 (10:23 -0700)]
Windows: Fix some build warnings/link issues

* Fix MSVC error C4334 (32-bit bit shift)
* Load User32.dll functions at runtime instead of linking directly
  against library (fixes unresovled symbol errors on DDK build)

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoio: Always complete transfers regardless of timerfd errors
Chris Dickens [Fri, 4 Sep 2015 00:23:22 +0000 (17:23 -0700)]
io: Always complete transfers regardless of timerfd errors

This commit addresses two issues.

First, commit a886bb02 introduced an issue where transfer callbacks
would not be called if the transfer that completed was the first
in line and the timerfd needed to be armed for another transfer.

Second, failure to set the timerfd should not prevent the transfer
from completing. The behavior has always been such, but it will
leave clients waiting for their transfer callbacks to be called.
This change will let the transfer callback complete and will return
the error through the event handling path.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agolibusb 1.0.20-rc2
Chris Dickens [Thu, 3 Sep 2015 02:54:44 +0000 (19:54 -0700)]
libusb 1.0.20-rc2

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agocore: Record when a transfer timeout has been handled
Chris Dickens [Sat, 22 Aug 2015 07:41:58 +0000 (00:41 -0700)]
core: Record when a transfer timeout has been handled

Commit efd02e73 introduced a bug where transfers that timed out
would be handled repeatedly if the cancellation was not successful.
This behavior blocks any event handling from occurring.

This commit adds a new transfer flag to record whether a timeout has
been handled.

Thanks to Jeffrey Nichols for reporting this.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoExamples: fxload improvements
Chris Dickens [Wed, 5 Aug 2015 06:51:12 +0000 (23:51 -0700)]
Examples: fxload improvements

* Add two-stage load support
* Fix leaks in error-handling paths
* Closes #12

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agocore: Correctly report cancellations due to timeouts
Chris Dickens [Mon, 3 Aug 2015 06:26:19 +0000 (23:26 -0700)]
core: Correctly report cancellations due to timeouts

Prior to this commit, the handle_timeout() function would always
set the USBI_TRANSFER_TIMED_OUT flag on the transfer. However, in
some cases the actual cancellation of the transfer does not succeed,
perhaps because the transfer had just completed. This would cause
occasional false reporting of LIBUSB_TRANSFER_TIMED_OUT when the
transfer did not in fact timeout. This commit adds a check for
successful cancellation before setting the transfer flag.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agolinux_usbfs: Set reap action to CANCELLED only when successful
Chris Dickens [Mon, 3 Aug 2015 06:19:57 +0000 (23:19 -0700)]
linux_usbfs: Set reap action to CANCELLED only when successful

Prior to this commit, a call to libusb_cancel_transfer() would set
the reap action of the transfer to CANCELLED regardless of whether
the cancellation was successful or not. This can cause the transfer
status to incorrectly report LIBUSB_TRANSFER_CANCELLED when in some
cases this is not the case. This commit adds a check for a successful
cancellation before setting the reap action as such.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agolinux: Assume usbfs path = /dev/bus/usb when using UDEV
Hans de Goede [Mon, 3 Aug 2015 08:06:05 +0000 (10:06 +0200)]
linux: Assume usbfs path = /dev/bus/usb when using UDEV

On some exotic hardware, e.g. HP ProLiant Moonshot Cartridge servers there
are no usb controllers, so no usb devices at all.

In this case currently libusb_init will fail, because find_usbfs_path
fails. Many apps don't handle this gracefully, and even if they do not crash
the result still is not pretty, e.g.:

unable to initialize libusb: -99

Where one simply would expect empty output.

Since on systems using udev the usbfs path should always be /dev/bus/usb
(as that gets created by udev), simply assume /dev/bus/usb when build with
USE_UDEV and the path cannot be found in the traditional way.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
8 years agoMisc: Remove autom4te.cache directory from Haiku during 'make dist'
Chris Dickens [Wed, 29 Jul 2015 17:15:42 +0000 (10:15 -0700)]
Misc: Remove autom4te.cache directory from Haiku during 'make dist'

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agolibusb 1.0.20-rc1
Chris Dickens [Wed, 29 Jul 2015 08:06:37 +0000 (01:06 -0700)]
libusb 1.0.20-rc1

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoAPI: Add libusb_free_pollfds() function
Chris Dickens [Sun, 1 Mar 2015 08:45:11 +0000 (00:45 -0800)]
API: Add libusb_free_pollfds() function

This patch adds a new API call to ensure that the same memory
allocator is used to both allocate and free the list of libusb_pollfd
structures. It is an incorrect assumption that the user's free() will
use the same memory allocator that libusb uses internally.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agolinux_usbfs: use calloc for multiplication
Marcus Meissner [Sat, 13 Jun 2015 21:50:35 +0000 (23:50 +0200)]
linux_usbfs: use calloc for multiplication

calloc can do n, elemsize multiplication itself

* Closes #74

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoUse locally defined MIN macro instead of min which is (possibly) defined in windows.h
Tim Hutt [Wed, 3 Jun 2015 14:01:06 +0000 (15:01 +0100)]
Use locally defined MIN macro instead of min which is (possibly) defined in windows.h

Some users have to define NOMINMAX which means that windows.h doesn't define min() or max(). Instead of relying on it it is better to use a locally defined function / macro. Fortunately libusbi.h already defines MIN and MAX so we can just use those.

* Closes #72
* Closes #73

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows: Close HID handles when closing composite devices
Chris Dickens [Wed, 29 Jul 2015 05:51:09 +0000 (22:51 -0700)]
Windows: Close HID handles when closing composite devices

* Closes #81

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows: Remove redundant check in windows_claim_interface()
Chris Dickens [Wed, 29 Jul 2015 05:38:10 +0000 (22:38 -0700)]
Windows: Remove redundant check in windows_claim_interface()

* Checking of this parameter is already done by the core
* Closes #77

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
8 years agoWindows: Destroy autoclaim_lock during cleanup
Chris Dickens [Wed, 29 Jul 2015 05:29:11 +0000 (22:29 -0700)]
Windows: Destroy autoclaim_lock during cleanup

* Fixes a resource leak during init error handling or final exit
* Closes #76

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agolinux_usbfs: Fix memory allocation failure.
Gaurav [Wed, 13 May 2015 07:49:14 +0000 (13:19 +0530)]
linux_usbfs: Fix memory allocation failure.

strdup returns NULL in case memory allocation failure occurs.
If Null check is not there, it will crash while dereferencing in "strrchr".

Closes #66

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
9 years agoMisc: Fix doxygen comment for MaxPower field with respect to super-speed
Tobias Klauser [Wed, 13 May 2015 12:19:12 +0000 (14:19 +0200)]
Misc: Fix doxygen comment for MaxPower field with respect to super-speed

The MaxPower field of a configuration descriptor is in units of 8 mA
when the device is operating in super-speed mode according to the USB
3.0 specification, section 9.6.3, table 9-12:

  Maximum power consumption of the device from the
  bus in this specific configuration when the device is
  fully operational. Expressed in 2-mA units when the
  device is operating in high-speed mode and in 8-mA
  units when operating at Gen X speed.
  (i.e., 50 = 100 mA when operating at high-speed and
  50 = 400 mA when operating at Gen X speed).

Adjust the doxygen comment for the MaxPower member of struct
libusb_config_descriptor accordingly.

Closes #69

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>