platform/upstream/libusb.git
10 years agoWindows: Add support for (old?) Intel USB 3.0 hub driver
Pete Batard [Sat, 1 Feb 2014 22:38:26 +0000 (22:38 +0000)]
Windows: Add support for (old?) Intel USB 3.0 hub driver

* Has VID:PID 8086:1111

10 years agolibusb 1.0.18
Pete Batard [Sat, 25 Jan 2014 22:43:39 +0000 (22:43 +0000)]
libusb 1.0.18

10 years agoWindows: Fix MinGW parallel build
xantares [Fri, 24 Jan 2014 09:07:11 +0000 (09:07 +0000)]
Windows: Fix MinGW parallel build

10 years agoDarwin: Fix Xcode warning in 'struct timeval' initialization
Sean McBride [Tue, 21 Jan 2014 16:20:20 +0000 (11:20 -0500)]
Darwin: Fix Xcode warning in 'struct timeval' initialization

10 years agolibusb 1.0.18-rc1
Pete Batard [Wed, 8 Jan 2014 23:51:38 +0000 (23:51 +0000)]
libusb 1.0.18-rc1

10 years agoMisc: Revert all references to libusb/libusb.info
hjelmn@cs.unm.edu [Wed, 8 Jan 2014 23:50:34 +0000 (23:50 +0000)]
Misc: Revert all references to libusb/libusb.info

10 years agoWindows: Fix a MinGW compilation issue
Pete Batard [Wed, 8 Jan 2014 19:56:12 +0000 (19:56 +0000)]
Windows: Fix a MinGW compilation issue

* Some MinGW platforms may not have FACILITY_SETUPAPI defined
* Issue introduced with 8b46e1c088167eb86b1712765896e2f17d70d148

10 years agoDarwin: Fix format of 64-bit sessionIDs in log messages
Matthias Bolte [Mon, 14 Oct 2013 17:05:12 +0000 (19:05 +0200)]
Darwin: Fix format of 64-bit sessionIDs in log messages

* The sessionID value is 64-bit, so print it as such.
* Closes #153

10 years agoDarwin: Fix a SIGFPE
Bei Zhang [Fri, 23 Aug 2013 08:10:35 +0000 (01:10 -0700)]
Darwin: Fix a SIGFPE

* GetPipeProperties() may fail when the device is unplugged if DeviceVersion is not greater than 320.
* In this case maxPacketSize will be zero and the integer division will throw a EXC_ARITHMETIC signal.
* Closes #136

10 years agoDarwin: Return error code in darwin_error_str() on unknown error
Francisco Facioni [Fri, 14 Jun 2013 16:03:54 +0000 (13:03 -0300)]
Darwin: Return error code in darwin_error_str() on unknown error

* Closes #117

10 years agoWindows: Add SetupAPI error handling
Pete Batard [Mon, 30 Dec 2013 21:32:28 +0000 (21:32 +0000)]
Windows: Add SetupAPI error handling

* http://msdn.microsoft.com/en-us/library/windows/hardware/ff545011.aspx
  states that SetupAPI errors must be be converted before passing it to FormatMessage().
* Use our own implementation of HRESULT_FROM_SETUPAPI to avoid defining a new function call.
* Issue and original fix suggested by Matthias Bolte
* Closes #166

10 years agoLinux: Remove trailing whitespace
Moritz Fischer [Thu, 7 Nov 2013 07:56:31 +0000 (08:56 +0100)]
Linux: Remove trailing whitespace

* Closes #157

10 years agoAndroid: Add support for Linux/Android platforms
Kuangye Guo [Tue, 22 Oct 2013 01:36:15 +0000 (18:36 -0700)]
Android: Add support for Linux/Android platforms

* Closes #154

10 years agoAndroid: Build for all Android architectures
Andrew Fernandes [Tue, 20 Aug 2013 16:19:26 +0000 (12:19 -0400)]
Android: Build for all Android architectures

* Don't limit support to ARM only (adds MIPS support)
* Also add a workaround for a MIPS NDK linker bug
* Also add a gitignore entry required to run bootstrap.sh on OS X
* Closes #134

10 years agoWindows: Add Visual Studio 2013 solution files
Joshua Blake [Mon, 9 Dec 2013 03:58:17 +0000 (22:58 -0500)]
Windows: Add Visual Studio 2013 solution files

* Also update gitignore
* Closes #162

10 years agocore: fix Doxygen warning
Ludovic Rousseau [Fri, 6 Dec 2013 15:56:16 +0000 (16:56 +0100)]
core: fix Doxygen warning

libusbx/libusb/libusb.h:153: warning: no matching file member found for
libusb_cpu_to_le16()Possible candidates:
  static uint16_t libusb_cpu_to_le16(const uint16_t x)

Thanks to Serhat Sevki Dincer for the bug report
http://sourceforge.net/mailarchive/message.php?msg_id=31719691

10 years agoWindows: Fix a crash when HID transfers return no data
Pete Batard [Wed, 27 Nov 2013 22:02:55 +0000 (22:02 +0000)]
Windows: Fix a crash when HID transfers return no data

* Issue reported by Surmakyynis
* Closes #160

10 years agocore: Make LIBUSB_DEBUG environment variable also work from libusb_exit
Hans de Goede [Tue, 15 Oct 2013 14:03:05 +0000 (16:03 +0200)]
core: Make LIBUSB_DEBUG environment variable also work from libusb_exit

libusb_exit sets usbi_default_context to NULL, modify usbi_log_v so that
it still honors the  LIBUSB_DEBUG environment variable in this case.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agohotplug: Fix usb_device memleak with hotunplug events pending on libusb_exit
Hans de Goede [Tue, 15 Oct 2013 13:30:02 +0000 (15:30 +0200)]
hotplug: Fix usb_device memleak with hotunplug events pending on libusb_exit

Closes #150

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoio: Ensure all pending events are consumed in one libusb_handle_events call
Hans de Goede [Tue, 15 Oct 2013 13:15:31 +0000 (15:15 +0200)]
io: Ensure all pending events are consumed in one libusb_handle_events call

Before this patch if ie multiple hot-plug events were pending, multiple
handle_events calls would be necessary to handle them all, this patch
changes handle_events so that the poll is re-done to check for more events
if there was activity on any of the special fds.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoWindows: Add support for VIA VL805 USB 3.0 Host Controllers
Omri Iluz [Mon, 7 Oct 2013 11:09:12 +0000 (04:09 -0700)]
Windows: Add support for VIA VL805 USB 3.0 Host Controllers

* These controllers identify themselves as VUSB3HUB
* Closes #152

10 years agoexamples: check value returned by ftell()
Ludovic Rousseau [Sun, 6 Oct 2013 12:23:20 +0000 (14:23 +0200)]
examples: check value returned by ftell()

Problem detected by the Coverity tool
CID 1042546 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)3.
negative_returns: "initial_pos" is passed to a parameter that cannot be
negative.

fseek(3) can't be called with a negative offset with SEEK_SET

10 years agoWindows: Avoid potential mismatch in transfer error reporting
Matthias Bolte [Tue, 1 Oct 2013 12:10:48 +0000 (14:10 +0200)]
Windows: Avoid potential mismatch in transfer error reporting

The default case in windows_transfer_callback() calls windows_error_str(0)
which will convert the error code returned by GetLastError() to a string.
This currently works because windows_transfer_callback() is either called
with io_result set to NO_ERROR or io_result set to GetLastError().

If windows_transfer_callback() will ever be called with io_result set
differently then the default case might report the wrong error message.

Call windows_error_str(io_result) instead to avoid this.

Closes #151

10 years agoexamples: add an option to force a device request for WCID descriptors
Pete Batard [Sun, 29 Sep 2013 20:39:26 +0000 (21:39 +0100)]
examples: add an option to force a device request for WCID descriptors

* Add option 'w' to force the use of a Device Request rather than an
  Interface Request when querying the WCID OS Extended Properties descriptor.
* This is due to a WinUSB limitation where all Interface Requests have the
  wIndex set to the interface number.
* This assumes that the WCID firmware answers both Device and Interface requests
  equally.

10 years agoexamples: fix warning
Ludovic Rousseau [Sat, 28 Sep 2013 11:14:17 +0000 (13:14 +0200)]
examples: fix warning

ezusb.c: In function 'ezusb_load_ram':
ezusb.c:719:6: warning: 'ret' may be used uninitialized in this function
[-Wmaybe-uninitialized]
  int ret;

10 years agotests: set output_file to a valid value
Ludovic Rousseau [Sun, 22 Sep 2013 19:29:50 +0000 (21:29 +0200)]
tests: set output_file to a valid value

If fdopen(3) fails then ctx->output_file is NULL and should not be used
in cleanup_test_output() called next.

Problem detected by the Coverity tool
CID 1042543 (#1 of 1): Dereference after null check (FORWARD_NULL)9.
var_deref_model: Passing "ctx" to function
"cleanup_test_output(libusbx_testlib_ctx *)", which dereferences null
"ctx->output_file".

10 years agoexamples: check value returned by libusb_bulk_transfer()
Ludovic Rousseau [Sun, 22 Sep 2013 19:25:00 +0000 (21:25 +0200)]
examples: check value returned by libusb_bulk_transfer()

Problem detected by the Coverity tool
CID 1042540 (#1 of 1): Unchecked return value (CHECKED_RETURN)1.
check_return: Calling function "libusb_bulk_transfer(struct
libusb_device_handle *, unsigned char, unsigned char *, int, int *,
unsigned int)" without checking return value (as is done elsewhere 4 out
of 5 times).

10 years agoexamples: check the value returned by libusb_handle_events()
Ludovic Rousseau [Sun, 22 Sep 2013 19:19:06 +0000 (21:19 +0200)]
examples: check the value returned by libusb_handle_events()

Problem detected by the Coverity tool
CID 1042539 (#1 of 1): Unchecked return value (CHECKED_RETURN)8.
check_return: Calling function "libusb_handle_events(libusb_context *)"
without checking return value (as is done elsewhere 6 out of 7 times).

10 years agoexamples: check the value returned by libusb_init()
Ludovic Rousseau [Sun, 22 Sep 2013 19:15:56 +0000 (21:15 +0200)]
examples: check the value returned by libusb_init()

Problem detected by the Coverity tool
CID 1042538 (#1 of 1): Unchecked return value (CHECKED_RETURN)4.
check_return: Calling function "libusb_init(libusb_context **)" without
checking return value (as is done elsewhere 11 out of 12 times).

10 years agolinux: take newline into account for sysfs_get_active_config
Karsten Koenig [Wed, 25 Sep 2013 22:08:16 +0000 (18:08 -0400)]
linux: take newline into account for sysfs_get_active_config

bConfigurationValue in sysfs can be 3 digits (1byte value) + 1 new line
= 4 bytes

In it's current form a bConfigurationValue of 128 will be detected as
not null terminated due to the trailing newline, simple fix is to just
extend the array size to 5

10 years agoexamples: Fix a memory leak
Ludovic Rousseau [Thu, 19 Sep 2013 21:51:04 +0000 (23:51 +0200)]
examples: Fix a memory leak

Close the image file before exiting the function

Problem detected by the Coverity tool
CID 1042549 (#2 of 3): Resource leak (RESOURCE_LEAK)9. leaked_storage:
Variable "image" going out of scope leaks the storage it points to.

10 years agoexamples: Fix a memory leak
Ludovic Rousseau [Thu, 19 Sep 2013 21:46:14 +0000 (23:46 +0200)]
examples: Fix a memory leak

Close the image file before exiting the function

Problem detected by the Coverity tool
CID 1042550 (#1 of 15): Resource leak (RESOURCE_LEAK)7. leaked_storage:
Variable "image" going out of scope leaks the storage it points to.

10 years agoFix darwin compilation broken by the usbi_get_device_by_session_id changes
Hans de Goede [Sun, 15 Sep 2013 09:47:23 +0000 (11:47 +0200)]
Fix darwin compilation broken by the usbi_get_device_by_session_id changes

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoMake usbi_get_device_by_session_id return a ref to the found device
Hans de Goede [Fri, 6 Sep 2013 14:49:26 +0000 (16:49 +0200)]
Make usbi_get_device_by_session_id return a ref to the found device

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoopenbsd: Fix a memleak
Hans de Goede [Fri, 6 Sep 2013 14:45:10 +0000 (16:45 +0200)]
openbsd: Fix a memleak

discovered_devs_append takes a reference to the past in dev, so we must
release our own reference.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoopenbsd: Fix usbi_sanitize_device error handling
Hans de Goede [Fri, 6 Sep 2013 14:40:51 +0000 (16:40 +0200)]
openbsd: Fix usbi_sanitize_device error handling

If usbi_sanitize_device fails we need to continue from the beginning of
the loop, rather then going on with the device we've just free-ed.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoconfigure.ac: uclinux is also linux
Gustavo Zacarias [Tue, 3 Sep 2013 13:24:04 +0000 (10:24 -0300)]
configure.ac: uclinux is also linux

When the tuple contains uclinux rather than just linux (nommu flat
targets) configure will fail with an unknown operating system.

Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoRelease 1.0.17
Hans de Goede [Fri, 6 Sep 2013 09:20:53 +0000 (11:20 +0200)]
Release 1.0.17

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoWindows: Address an VS2012/x64 warning in hotplug.c
Xiaofan Chen [Mon, 2 Sep 2013 10:35:40 +0000 (11:35 +0100)]
Windows: Address an VS2012/x64 warning in hotplug.c

..\libusb\hotplug.c(255): warning C4244: '=' : conversion from
'ssize_t' to 'int', possible loss of data

10 years agoNathan is a maintainer now, so add him to the README
Hans de Goede [Fri, 30 Aug 2013 14:50:12 +0000 (16:50 +0200)]
Nathan is a maintainer now, so add him to the README

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoRemove unused THANKS file
Hans de Goede [Fri, 30 Aug 2013 14:49:32 +0000 (16:49 +0200)]
Remove unused THANKS file

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoMakefile.am: Add Xcode dir to EXTRA_DIST
Hans de Goede [Fri, 30 Aug 2013 14:44:45 +0000 (16:44 +0200)]
Makefile.am: Add Xcode dir to EXTRA_DIST

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoAndroid: Add android build files to source tarball
Toby Gray [Fri, 30 Aug 2013 12:42:34 +0000 (14:42 +0200)]
Android: Add android build files to source tarball

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoRelease 1.0.17-rc1
Hans de Goede [Wed, 28 Aug 2013 08:17:53 +0000 (10:17 +0200)]
Release 1.0.17-rc1

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agodarwin: return libusb error codes instead of kernel error codes and fix
Nathan Hjelm [Tue, 27 Aug 2013 02:40:52 +0000 (20:40 -0600)]
darwin: return libusb error codes instead of kernel error codes and fix
a bug introduced in the last commit.

10 years agodarwin: clean up some code. remove a clang warning
Nathan Hjelm [Tue, 27 Aug 2013 02:12:23 +0000 (20:12 -0600)]
darwin: clean up some code. remove a clang warning

The check for NULL != cached_device was unnecessary and caused clang's
static analysis to print out a warning.

10 years agoAndroid: Add further documentation to Android README file
Toby Gray [Wed, 21 Aug 2013 14:27:03 +0000 (16:27 +0200)]
Android: Add further documentation to Android README file

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoOpenBSD: Add basic support for non ugen(4) devices using usb(4)
Martin Pieuchot [Tue, 16 Jul 2013 09:32:23 +0000 (11:32 +0200)]
OpenBSD: Add basic support for non ugen(4) devices using usb(4)

It is now possible to have a read access and submit control transfers
to all USB devices using libusb, please note that controllers and hubs
also appear as devices.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoopenbsd: Split openbsd backend into separate openbsd and netbsd backends
Hans de Goede [Wed, 21 Aug 2013 14:18:39 +0000 (16:18 +0200)]
openbsd: Split openbsd backend into separate openbsd and netbsd backends

Note the new netbsd_usb.c is an unmodified copy of openbsd_usb.c with
s/obsd/netbsd done on it. The reason for this split is that the openbsd
developers have been working on various improvements for their userspace
usb support, and adding support for those means breaking netbsd support,
by giving netbsd its own backend we can add support for the openbsd
improvements without breaking netbsd support.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoClarify alignment requirements for the control transfer buffer
Paul Fertser [Mon, 1 Jul 2013 17:07:24 +0000 (21:07 +0400)]
Clarify alignment requirements for the control transfer buffer

Since the buffer pointer will later be casted to ``struct
libusb_control_setup *'', it should point to memory aligned to at least
2 bytes boundary as that's the strictest requirement of the struct fields.

Also, use a (void *) casting trick to convince the compiler the cast is
safe, to fix warnings such as:

/usr/local/include/libusb-1.0/libusb.h: In function 'libusb_control_transfer_get_setup':
/usr/local/include/libusb-1.0/libusb.h:1435:9: error: cast increases required alignment of target type [-Werror=cast-align]
/usr/local/include/libusb-1.0/libusb.h: In function 'libusb_fill_control_setup':
/usr/local/include/libusb-1.0/libusb.h:1464:39: error: cast increases required alignment of target type [-Werror=cast-align]
/usr/local/include/libusb-1.0/libusb.h: In function 'libusb_fill_control_transfer':
/usr/local/include/libusb-1.0/libusb.h:1509:39: error: cast increases required alignment of target type [-Werror=cast-align]
cc1: all warnings being treated as errors

This actually can lead to failure to build from the sources for certain
projects which use -Werror=cast-align on ARM.

Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agolinux: Handle device disconnection early when possible
Chris Dickens [Thu, 27 Jun 2013 16:14:15 +0000 (09:14 -0700)]
linux: Handle device disconnection early when possible

If a device is open, the device's fd will trigger a POLLERR condition
once it is removed. Sometimes this can occur well before the udev
monitor sends the remove event. This can also be caught early if
the device is not currently open but an attempt to open it is made.

In both situations, this can be caught early and processed so that
the device does not continue to show up in the device list after it
has been disconnected but before the udev monitor processes the event.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agohotplug: Document LIBUSB_HOTPLUG_ENUMERATE gotchas
Hans de Goede [Wed, 21 Aug 2013 12:46:45 +0000 (14:46 +0200)]
hotplug: Document LIBUSB_HOTPLUG_ENUMERATE gotchas

When libusb_hotplug_register_callback gets called with the
LIBUSB_HOTPLUG_ENUMERATE flag, there may still be hotplug events pending
in the hotplug pipe, waiting for dispatching from libusb_handle_events.

This means that the user callback can be called twice for arrival of the
same device, once from libusb_hotplug_register_callback, since the device
is already part of the usb_devs list, and once from libusb_handle_events
when it reads the event from the hotplug pipe.

This could be fixed by adding a mechanism to pause hotplug handling, then
drain the hotplug pipe (ie by calling libusb_handle_events from
libusb_hotplug_register_callback), before iterating over the usb_devs list,
and then un-pausing hotplug handling afterwards, doing this however requires
a lot of hairy code, which will be prone to dead-locking.

OTOH it is quite simple for user applications which care about this to detect
this and ignore the 2nd call, so lets simply document this may happen and
be done with it.

Note that this is also the solution which ie libudev has choosen, there is
no way with libudev to get a device-list + listen for device arrival / removal
without running into the same problem.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agohotplug: Document that callbacks cannot unregister themselves when called from hotplu...
Hans de Goede [Wed, 21 Aug 2013 12:30:51 +0000 (14:30 +0200)]
hotplug: Document that callbacks cannot unregister themselves when called from hotplug_register_callback

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agohotplug: Don't call the user callback while holding various locks
Hans de Goede [Wed, 21 Aug 2013 12:18:09 +0000 (14:18 +0200)]
hotplug: Don't call the user callback while holding various locks

Calling user callbacks with locks held is a bad idea and should be avoided
whenever possible. Before this patch this could lead ie to the following hang:

1) User calls libusb_hotplug_register_callback with the
   LIBUSB_HOTPLUG_ENUMERATE flag
2) libusb_hotplug_register_callback calls the user callback while holding the
   hotplug_cbs_lock
3) The callback calls a synchronous libusb function
4) The synchronous libusb function calls libusb_handle_events
5) There is an hotplug event waiting in the hotplug pipe and
   libusb_handle_events calls usbi_hotplug_match
6) usbi_hotplug_match tries to take the lock a 2nd time
7) hang / assert / abort (depending on the platform)

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agohotplug: Remove device from usb_devs before signalling its removal
Hans de Goede [Tue, 20 Aug 2013 13:18:59 +0000 (15:18 +0200)]
hotplug: Remove device from usb_devs before signalling its removal

If we write the remove event to the pipe before doing the list_del,
in theory another thread can process the event and unref the device before
it has been removed from usb_devs.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agolibusb: Fix usb_devs_lock mutex use after free in libusb_init error path
Hans de Goede [Tue, 20 Aug 2013 12:41:36 +0000 (14:41 +0200)]
libusb: Fix usb_devs_lock mutex use after free in libusb_init error path

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agolinux/netlink: correct usage of fcntl
Nathan Hjelm [Wed, 14 Aug 2013 17:08:36 +0000 (11:08 -0600)]
linux/netlink: correct usage of fcntl

Closes #130

10 years agoWindows: Fix a cast warning when compiling for x64 in VS
Pete Batard [Tue, 13 Aug 2013 18:00:54 +0000 (19:00 +0100)]
Windows: Fix a cast warning when compiling for x64 in VS

* Also fixes and closes #129 again

10 years agoWindows: Fix VS2010 project files
Pete Batard [Mon, 12 Aug 2013 21:04:39 +0000 (22:04 +0100)]
Windows: Fix VS2010 project files

* Closes #129

10 years agoAndroid: Add examples and stress tests
Toby Gray [Thu, 8 Aug 2013 17:22:21 +0000 (18:22 +0100)]
Android: Add examples and stress tests

10 years agoAndroid: Add formal Android support
Toby Gray [Tue, 9 Jul 2013 15:43:53 +0000 (16:43 +0100)]
Android: Add formal Android support

* Also fix an issue with LIBUSB_LOG_LEVEL_NONE

10 years agoCore: Add compile time option to use native OS logging facility
Toby Gray [Tue, 9 Jul 2013 15:05:39 +0000 (16:05 +0100)]
Core: Add compile time option to use native OS logging facility

* This change makes it easier to debug issues in UI applications
  which don't necessarily have a console connected to stderr.
* Outputting to the debugger shouldn't occur in normal situations so
  this change has to be explicitly enabled by a build-time config flag.
* Uses OutputDebugString() on Windows platforms or the syslog facility
  on other OSes, if available.
* Also align the report of configure defaults to autotool's.

10 years agolinux: ensure the netlink socket is correctly opened with older Linux kernels
Nathan Hjelm [Thu, 8 Aug 2013 03:01:43 +0000 (21:01 -0600)]
linux: ensure the netlink socket is correctly opened with older Linux kernels

It is possible for the extra socket flags (available from 2.6.27 on) to be
defined but not available. Check for this case and set the flags correctly
on the netlink socket.

10 years agoCore: Fix potential segfault caused by using freed memory
Chris Dickens [Tue, 6 Aug 2013 20:16:16 +0000 (13:16 -0700)]
Core: Fix potential segfault caused by using freed memory

When a transfer is submitted, the device is referenced in libusb_submit_transfer()
and unreferenced in usbi_handle_transfer_completion(). This transfer could potentially
be freed by any user callback, or is freed by libusb if LIBUSB_TRANSFER_FREE_TRANSFER
is set in the flags. The call to unreference the device uses this potentially freed
memory. Reading the device handle beforehand will prevent this disaster.

10 years agoWindows: Fix race between windows_clock_gettime_threaded() and windows_clock_gettime()
Simon Haggett [Fri, 12 Jul 2013 09:06:00 +0000 (10:06 +0100)]
Windows: Fix race between windows_clock_gettime_threaded() and windows_clock_gettime()

* When the timer thread is created in windows_init(), it performs an
  initialisation phase in which it uses QueryPerformanceFrequency() to determine
  if there is a high resolution timer available, and sets hires_frequency and
  hires_ticks_to_ps appropriately. However, since windows_init() does not wait for
  this initialisation phase to complete, windows_clock_gettime() can be called
  before hires_frequency and hires_ticks_to_ps have been updated. This can result
  in windows_clock_gettime() temporarily returning real-time clock values even
  though the platform supports a monotonic clock.
* See http://sourceforge.net/mailarchive/forum.php?thread_name=1373620013-3574-1-git-send-email-simon.haggett%40realvnc.com&forum_name=libusbx-devel

10 years agoWinCE: Fix race between wince_clock_gettime_threaded() and wince_clock_gettime()
Simon Haggett [Fri, 12 Jul 2013 09:06:00 +0000 (10:06 +0100)]
WinCE: Fix race between wince_clock_gettime_threaded() and wince_clock_gettime()

* When the timer thread is created in wince_init(), it performs an initialisation
  phase in which it uses QueryPerformanceFrequency() to determine if there is a
  high resolution timer available, and sets hires_frequency and hires_ticks_to_ps
  appropriately. However, since wince_init() does not wait for this initialisation
  phase to complete, wince_clock_gettime() can be called before hires_frequency
  and hires_ticks_to_ps have been updated. This can result in
  wince_clock_gettime() temporarily returning real-time clock values even though
  the platform supports a monotonic clock.
* See http://sourceforge.net/mailarchive/forum.php?thread_name=1373619997-3535-1-git-send-email-simon.haggett%40realvnc.com&forum_name=libusbx-devel

10 years agoWindows: fd_to_winfd() shouldn't treat fd 0 as invalid
Simon Haggett [Thu, 11 Jul 2013 16:27:00 +0000 (17:27 +0100)]
Windows: fd_to_winfd() shouldn't treat fd 0 as invalid

* fd_to_winfd() currently returns INVALID_WINFD if fd is 0, but usbi_create_fd()
  can legally assign an fd number of 0 if poll_fd[0] is not already occupied.
* Transfers which are assigned an fd number of 0 for their event handle are then
  unable to have their event handle retrieved later on.

See http://libusbx.1081486.n5.nabble.com/Libusbx-devel-PATCH-1-1-Windows-fd-to-winfd-shouldn-t-treat-fd-0-as-invalid-tt1535.html

10 years agoREADME: Add OS X specific notes
Sean McBride [Fri, 12 Oct 2012 19:04:03 +0000 (15:04 -0400)]
README: Add OS X specific notes

Xcode 4.3 do not provide autotools anymore.
libusbx now provides a Xcode project to ease build Mac OS X.

10 years agoCore: correctly check usbi_read() returned value
Chris Dickens [Fri, 2 Aug 2013 09:33:41 +0000 (11:33 +0200)]
Core: correctly check usbi_read() returned value

For messages received on the hotplug pipe, the message was read via
usbi_read() (ssize_t) and compared against the size of the message
struct (size_t). usbi_read() returns -1 on an error condition, so some
systems can cast the ssize_t to size_t for the comparison, making it
equal to SIZE_MAX and causing the error check condition to incorrectly
evaluate to false.

10 years agoCore: defensive programming
Sean McBride [Fri, 12 Oct 2012 21:31:45 +0000 (17:31 -0400)]
Core: defensive programming

Defensively set return-by-reference value to -1 in error condition

NB: The comments do not match the implementation.

Comments: "[return] the index of the configuration matching a specific
bConfigurationValue in the idx output parameter, or -1 if the config was
not found"

There is a code path where idx is never touched. Perhaps clients of the
function are careful to only read idx if the return value is success,
but also setting idx to -1 is much safer.

10 years agodarwin: fix clang warnings about explicit conversion
hjelmn [Tue, 30 Jul 2013 19:28:27 +0000 (13:28 -0600)]
darwin: fix clang warnings about explicit conversion

There shouldn't be any problems with any supported version of OSX in
converting a UInt64 to an unsigned long. They should be the same size
but even if they are not the session should still be unique.

10 years agofixed link errors by adding missing files to Xcode project
Sean McBride [Fri, 26 Jul 2013 18:11:53 +0000 (14:11 -0400)]
fixed link errors by adding missing files to Xcode project

10 years agomade some globals static to fix warnings
Sean McBride [Fri, 26 Jul 2013 18:13:45 +0000 (14:13 -0400)]
made some globals static to fix warnings

10 years agofixed some clang -Wdocumentation warnings from bad doxygen markup
Sean McBride [Fri, 26 Jul 2013 18:13:40 +0000 (14:13 -0400)]
fixed some clang -Wdocumentation warnings from bad doxygen markup

10 years agofixed compiler warning about possible uninitialized use by zero initializing
Sean McBride [Fri, 26 Jul 2013 18:13:03 +0000 (14:13 -0400)]
fixed compiler warning about possible uninitialized use by zero initializing

10 years agomake targets for examples depend on library target. Generate library named libusb...
Sean McBride [Wed, 31 Oct 2012 17:18:32 +0000 (13:18 -0400)]
make targets for examples depend on library target.  Generate library named libusb-1.0.0.dylib not libusbx.dylib.  Added several xcconfig files to make source control and documentation easier.  Reorganised a few files' positions within the project.  Disable strict aliasing since libusbx breaks strict aliasing rules anyway. Set project format as 3.1-compatible.

Conflicts:
Xcode/libusbx.xcodeproj/project.pbxproj

10 years agoXcode: build for 32 and 64 bits
Ludovic Rousseau [Wed, 31 Oct 2012 08:20:33 +0000 (09:20 +0100)]
Xcode: build for 32 and 64 bits

10 years agoXcode: remove implicit/default configuration
Ludovic Rousseau [Fri, 26 Oct 2012 07:44:16 +0000 (09:44 +0200)]
Xcode: remove implicit/default configuration

10 years agoAdd minimal config.h for Xcode
Ludovic Rousseau [Fri, 26 Oct 2012 07:32:54 +0000 (09:32 +0200)]
Add minimal config.h for Xcode

Xcode do not use ./configure so the config.h file needs to be generated
by hand.
This config.h is the minimal file for libusbx built using Xcode.

10 years agoAdapt Xcode project to the new paths
Ludovic Rousseau [Fri, 26 Oct 2012 07:25:22 +0000 (09:25 +0200)]
Adapt Xcode project to the new paths

10 years agoMove Xcode project in Xcode/ directory
Ludovic Rousseau [Fri, 26 Oct 2012 07:21:35 +0000 (09:21 +0200)]
Move Xcode project in Xcode/ directory

This is to use Xcode special config.h file in a independent directory.
The same is already done for MS Visual C with msvc/ directory.

10 years agoXcode project
Ludovic Rousseau [Fri, 12 Oct 2012 21:30:26 +0000 (23:30 +0200)]
Xcode project

10 years agolinux_netlink: Remove use of pthread_cancel
Hans de Goede [Fri, 19 Jul 2013 08:52:18 +0000 (10:52 +0200)]
linux_netlink: Remove use of pthread_cancel

Using pthread_cancel() presents the opportunity for deadlock, so
use a control pipe to cause the event thread to gracefully exit.

Inspired on the identical patch for linux_udev from Chris Dickens.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agolinux_netlink: close netlink socket on init error
Hans de Goede [Tue, 30 Jul 2013 14:56:54 +0000 (16:56 +0200)]
linux_netlink: close netlink socket on init error

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agohotplug: Remove use of pthread_cancel from linux_udev
Chris Dickens [Sat, 20 Jul 2013 20:01:41 +0000 (13:01 -0700)]
hotplug: Remove use of pthread_cancel from linux_udev

Using pthread_cancel() presents the opportunity for deadlock, so
use a control pipe to cause the event thread to gracefully exit.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agolinux: Use a separate lock to serialize start/stop vs hotplug events
Hans de Goede [Tue, 30 Jul 2013 13:57:16 +0000 (15:57 +0200)]
linux: Use a separate lock to serialize start/stop vs hotplug events

Using one lock for this is a bad idea, as we should not be holding any
locks used by the hotplug thread when trying to stop otherwise the stop
function may wait indefinetely in pthread_join, while the event-thread
is waiting for the lock the caller of the stop function holds.

Using 2 separate locks for this should fix this deadlock, which has been
reported here: https://bugzilla.redhat.com/show_bug.cgi?id=985484

Many thanks to Chris Dickens for figuring out the cause of this deadlock!

CC: Chris Dickens <christopher.a.dickens@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agowork around Linux systems that don't provide SOCK_CLOEXEC or SOCK_NONBLOCK
hjelmn [Mon, 29 Jul 2013 16:22:53 +0000 (10:22 -0600)]
work around Linux systems that don't provide SOCK_CLOEXEC or SOCK_NONBLOCK

These options were added in 2.6.27 and are not available on all kernels
that support netlink. Set these options using fcntl when SOCK_CLOEXEC and
SOCK_NONBLOCK are not available.

Closes #124.

10 years agofix warnings in linux_get_device_address
hjelmn [Mon, 29 Jul 2013 16:11:33 +0000 (10:11 -0600)]
fix warnings in linux_get_device_address

Warnings:

os/linux_usbfs.c: In function 'linux_get_device_address':
os/linux_usbfs.c:620: warning: comparison is always false due to limited range of data type
os/linux_usbfs.c:624: warning: comparison is always false due to limited range of data type
os/linux_usbfs.c:628: warning: comparison is always false due to limited range of data type
os/linux_usbfs.c:628: warning: comparison is always false due to limited range of data type

10 years agoinclude stdlib.h for free and realloc in libusbi.h
hjelmn [Mon, 29 Jul 2013 16:10:56 +0000 (10:10 -0600)]
include stdlib.h for free and realloc in libusbi.h

References #124.

10 years agoSilence automake 1.14 warning
Nathan Hjelm [Sat, 27 Jul 2013 19:57:39 +0000 (13:57 -0600)]
Silence automake 1.14 warning

The warning is:

libusb/Makefile.am:57: warning: source file 'os/threads_windows.c' is in a subdirectory,
libusb/Makefile.am:57: but option 'subdir-objects' is disabled
automake: warning: possible forward-incompatibility.
automake: At least a source file is in a subdirectory, but the 'subdir-objects'
automake: automake option hasn't been enabled.  For now, the corresponding output
automake: object file(s) will be placed in the top-level directory.  However,
automake: this behaviour will change in future Automake versions: they will
automake: unconditionally cause object files to be placed in the same subdirectory
automake: of the corresponding sources.
automake: You are advised to start using 'subdir-objects' option throughout your
automake: project, to avoid future incompatibilities.

Fixed by setting the subdir-objects option.

Closes #125.

10 years agoAdd checks for headers needed by linux/netlink.h
Nathan Hjelm [Sat, 27 Jul 2013 18:35:51 +0000 (12:35 -0600)]
Add checks for headers needed by linux/netlink.h

These headers are required by netlink.h. I am not sure how this
worked at all. It certainly doesn't work with older versions of Linux
2.6.

References #124.

10 years agokeep a reference to the device for each active transfer and let the backend handle...
Nathan Hjelm [Wed, 24 Jul 2013 02:56:37 +0000 (20:56 -0600)]
keep a reference to the device for each active transfer and let the backend handle cancelling active transfers when a device is disconnected

This commit should fix issues with active transfers when a device is
disconnected. The backend is responsible for making sure the completion
callbacks are made, not the hotplug code. This should fix a number of
issues including duplicate callbacks and segmentation faults.

References #124.

10 years agohotplug: Pass explicit context to callbacks
Florian Albrechtskirchinger [Fri, 12 Jul 2013 13:10:00 +0000 (14:10 +0100)]
hotplug: Pass explicit context to callbacks

* Instead of passing NULL for the context to hotplug callbacks, if the
  context happens to be the default context, always pass the explicit
  context pointer.

10 years agoPrepare for 1.0.16 final release
Hans de Goede [Thu, 11 Jul 2013 09:04:02 +0000 (11:04 +0200)]
Prepare for 1.0.16 final release

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoPrepare for 1.0.16-rc3 release
Hans de Goede [Sat, 6 Jul 2013 07:09:25 +0000 (09:09 +0200)]
Prepare for 1.0.16-rc3 release

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoDocumentation: add an Using an event handling thread section
Hans de Goede [Fri, 5 Jul 2013 14:57:51 +0000 (16:57 +0200)]
Documentation: add an Using an event handling thread section

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agoDocumentation: explain the 2 main viable event handling approaches
Hans de Goede [Fri, 5 Jul 2013 14:17:45 +0000 (16:17 +0200)]
Documentation: explain the 2 main viable event handling approaches

Stop pretending that having a separate event handling thread is a bad thing,
specifically delete the "[this] option is not very nice either, but may be
the nicest option available to you if the "proper" approach can not be applied
to your application", which suggests that using poll integration into a main
loop is the one and only "proper" approach.

Instead clearly document there are 2 viable approaches, using a separate
thread, or poll integration into a main loop.

Also stop claiming that libusb does not use threads internally, as with
the new hotplug support this is no longer true.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agohotplug: Wakeup libusb_handle_events on libusb_hotplug_deregister_callback
Hans de Goede [Thu, 4 Jul 2013 14:38:22 +0000 (16:38 +0200)]
hotplug: Wakeup libusb_handle_events on libusb_hotplug_deregister_callback

This serves 2 purposes:

1) We use lazy free-ing of the callback structure, for it to be actually
free-ed usbi_hotplug_match() needs to be called. This ensures this actually
happens (rather then waiting for a hotplug event to arrive, and not freeing
the callback as long as no such event arrives).

2) It causes libusb_handle_events to return to its caller on a call to
libusb_hotplug_deregister_callback, which is very useful for apps which use
a thread to do their apps (hotplug) event handling, otherwise that thread will
hang when the app tries to stop until some event happens.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
10 years agohotplug: Give the usbi_hotplug_match* functions a context parameter
Hans de Goede [Thu, 4 Jul 2013 14:30:36 +0000 (16:30 +0200)]
hotplug: Give the usbi_hotplug_match* functions a context parameter

So that the device parameter can be NULL, in combination with a 0
events parameter, to be used to force lazy deregistration.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
11 years agoDoc: update hotplug, topology and descriptor documentation
Pete Batard [Wed, 3 Jul 2013 21:41:55 +0000 (22:41 +0100)]
Doc: update hotplug, topology and descriptor documentation

* Also fix some typos
* Closes #95