Pete Batard [Mon, 17 May 2010 22:30:27 +0000 (19:30 -0300)]
Stricter types and casts
Pete Batard [Mon, 17 May 2010 22:16:54 +0000 (19:16 -0300)]
Fixes to error handling and exit codepaths
Various locks and things were being leaked/left open when handling
errors and during deinitialization.
[dsd: small tweaks]
Nathan Hjelm [Thu, 13 May 2010 22:38:05 +0000 (19:38 -0300)]
Darwin: Define IO_OBJECT_NULL if not already defined
Needed on Mac OSX 10.3
Hans Ulrich Niedermann [Fri, 29 Jan 2010 11:08:52 +0000 (12:08 +0100)]
libusb_cpu_to_le16: macro->static inline function
The libusb_cpu_to_le16 macro was a ({ ... }) expression, which
generates the following compiler warning every time it is used,
(and that is several times for every #include <libusb.h>):
libusb.h:880: warning: ISO C forbids braced-groups within expressions
With this patch, #include <libusb.h> stops generating compiler
warnings on gcc 4.4.
As libusb.h heavily relies on the use of static inline functions
those can be relied on to work properly, and there should not be
any significant difference in the code the compiler generates.
Francesco [Tue, 9 Mar 2010 22:35:35 +0000 (16:35 -0600)]
Add libusb_strerror() to get short error message in English from enum
[dsd: small tweaks]
Michael Plante [Fri, 26 Feb 2010 01:39:22 +0000 (19:39 -0600)]
Fix libusb_device::lock memory leak
Pete Batard [Thu, 13 May 2010 00:46:31 +0000 (21:46 -0300)]
Whitespace cleanup
Peter Stuge [Mon, 10 May 2010 23:51:43 +0000 (00:51 +0100)]
Add internal abstraction for POSIX Threads
This prepares for a Windows backend without dependency on pthreads-w32.
pthread_* is renamed to usbi_* and PTHREAD_* to USBI_*.
A usbi_mutex_static_t and usbi_mutex_static_lock() and _unlock() are
introduced for statically initialized mutexes, since they may be
implemented using other types when pthreads mutexes aren't used.
Move -pthread from libusb/Makefile.am to host-specific THREAD_CFLAGS in
configure.ac. This will enable optional use of -lpthread for cygwin.
[dsd: minor tweaks, and roll in a change based on patches from Pete
Batard to only build dpfp_threaded example when we're using pthreads]
Daniel Drake [Tue, 4 May 2010 22:01:59 +0000 (19:01 -0300)]
v1.0.8 release
Daniel Drake [Thu, 22 Apr 2010 21:12:51 +0000 (18:12 -0300)]
Linux: don't set SHORT_NOT_OK on bulk out URBs (#20
Setting this flag is illegal, and the behaviour we're looking for
is already in place for host-to-device transfers without this flag.
Daniel Drake [Tue, 20 Apr 2010 23:14:09 +0000 (20:14 -0300)]
Linux: Handle failure to read active configuration during enumeration
Nathan Hjelm [Tue, 20 Apr 2010 22:43:06 +0000 (19:43 -0300)]
Darwin: don't reuse cached descriptors during enumeration
Descriptor reuse was causing scans to return invalid information when
the device at a location has changed.
Daniel Drake [Mon, 19 Apr 2010 22:36:55 +0000 (19:36 -0300)]
v1.0.7 release
Daniel Drake [Mon, 19 Apr 2010 22:31:12 +0000 (19:31 -0300)]
Document that fd set contents are an internal implementation detail (#36)
Martin Koegler [Mon, 19 Apr 2010 22:22:46 +0000 (19:22 -0300)]
Linux: correct config descriptor endianness fix
The seek_to_next_config codepath deals with both sysfs and usbfs;
make sure we only convert values in the usbfs path.
Martin Koegler [Mon, 5 Apr 2010 15:11:32 +0000 (17:11 +0200)]
Linux: Fix endianness handling of usbfs config descriptors (#27)
driver/usb/core/devio.c function usbdev_read translate the follwing files
to CPU endianess:
le16_to_cpus(&temp_desc.bcdUSB);
le16_to_cpus(&temp_desc.idVendor);
le16_to_cpus(&temp_desc.idProduct);
le16_to_cpus(&temp_desc.bcdDevice);
All other data is passed without any change.
libusb/os/linux_usbfs.c calls usbi_parse_descriptor with host_endian=1
for config descriptors. According to the kernel code, they must be
processed with host_endian=0, as they are not translated by the kernel.
Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>
Nathan Hjelm [Tue, 23 Mar 2010 22:22:08 +0000 (16:22 -0600)]
Darwin: fix enumeration of devices with non-consecutive addresses (#23)
Bastien Nocera [Mon, 8 Mar 2010 10:50:51 +0000 (10:50 +0000)]
Add more interface classes
As used in bluez.
Nathan Hjelm [Thu, 18 Mar 2010 17:32:32 +0000 (11:32 -0600)]
Darwin: Cleanup async callback code, catch request timeouts
Nathan Hjelm [Thu, 18 Mar 2010 17:31:46 +0000 (11:31 -0600)]
Darwin: fix endianness of control setup packet
IOUSBLib expects the control request to be in host byte order.
Swap the request into host byte order.
Nathan Hjelm [Mon, 15 Feb 2010 20:10:08 +0000 (14:10 -0600)]
Darwin: fix memory leak in process_device
Credit to Mike Colagrosso for finding this bug.
Nathan Hjelm [Mon, 15 Feb 2010 20:09:19 +0000 (14:09 -0600)]
Darwin: use logging functions
Use usbi_warn, usbi_err, and usbi_info instead of _usbi_log.
Nathan Hjelm [Mon, 15 Feb 2010 20:07:44 +0000 (14:07 -0600)]
Darwin: support multiple calls to libusb_init
Credit to Orin Eman for finding this bug.
Daniel Drake [Sun, 22 Nov 2009 17:20:53 +0000 (17:20 +0000)]
v1.0.6 release
Ludovic Rousseau [Sun, 25 Oct 2009 09:06:41 +0000 (10:06 +0100)]
lsusb example: make print_devs() static
lsusb.c:26: warning: no previous prototype for ‘print_devs’
Ludovic Rousseau [Sun, 25 Oct 2009 09:05:10 +0000 (10:05 +0100)]
Darwin: fix warning in darwin_error_str()
os/darwin_usb.c:63: warning: return discards qualifiers from pointer
target type
Nathan Hjelm [Sat, 21 Nov 2009 17:06:43 +0000 (17:06 +0000)]
Darwin: allow devices to be opened multiple times
Allows libusb applications to access multiple interfaces of the same
device in the same application.
Also fixes a set alt interface bug.
Daniel Drake [Sat, 21 Nov 2009 17:01:32 +0000 (17:01 +0000)]
Increase libusb_handle_events() timeout to 60 seconds
The internal timing seems to be working, this will be a better test of
it before we make this timeout unlimited.
Daniel Drake [Sat, 21 Nov 2009 16:57:25 +0000 (16:57 +0000)]
Refine timerfd header check (#18)
Require glibc-2.9 for the working timerfd support.
Daniel Drake [Sun, 15 Nov 2009 12:17:13 +0000 (12:17 +0000)]
v1.0.5 release
Daniel Drake [Sat, 7 Nov 2009 10:43:59 +0000 (10:43 +0000)]
Update documentation about early completion caveats
Ludovic Rousseau [Sun, 25 Oct 2009 08:59:51 +0000 (09:59 +0100)]
Add libusb_get_max_iso_packet_size() to libusb.h
core.c:777: warning: no previous prototype for 'libusb_get_max_iso_packet_size'
Daniel Drake [Wed, 28 Oct 2009 14:48:49 +0000 (20:33 +0545)]
Use timerfd for timeout handling
Use a new file descriptor from the timerfd system calls to handle
timeouts. On supported systems, this means that there is less hassle
figuring out when the poll() timeout should be, since
libusb_get_next_timeout() will always return 0 and the timeout events will
be triggered as regular activity on the file descriptor set.
Add API function libusb_pollfds_handle_timeouts() to detect whether
you're on a platform with the timing headache, and flesh out the
surrounding documentation.
Daniel Drake [Sat, 7 Nov 2009 10:03:07 +0000 (10:03 +0000)]
Use AM_SILENT_RULES for building
Daniel Drake [Fri, 6 Nov 2009 21:54:08 +0000 (21:54 +0000)]
v1.0.4 release
David Moore [Fri, 6 Nov 2009 21:37:25 +0000 (21:37 +0000)]
Linux: Add support for the new URB_BULK_CONTINUATION flag
Add support for the new USBDEVFS_URB_BULK_CONTINUATION flag to libusb.
This flag, which is expected to be available in usbfs starting with
kernel 2.6.32, allows the kernel to cancel multiple URBs upon receipt
of a short packet. This capability allows libusb to preserve data
integrity of large bulk transfers that are split into multiple URBs.
Without this support, these URBs must be canceled in userspace upon
receipt of a short packet, a race condition against future transfers
which might partially fill these canceled URBs.
This patch automatically detects whether a supported kernel is present
and enables the use of the flag when possible.
[dsd: tweaks to supported kernel detection, and some inline
documentation of this mechanism]
Daniel Drake [Wed, 28 Oct 2009 09:28:22 +0000 (15:13 +0545)]
Transfer locking
At least on Linux, there were some possible races that could occur if
a transfer is cancelled from one thread while another thread is handling
an event for that transfer, or for if a transfer completes while it is
still being submitted from another thread, etc.
On the global level, transfers could be submitted and cancelled at the
same time.
Fix those issues with transfer-level locks.
Daniel Drake [Mon, 14 Sep 2009 07:01:24 +0000 (08:01 +0100)]
Clarify that timeout 0 means unlimited timeout
Daniel Drake [Fri, 11 Sep 2009 21:09:12 +0000 (22:09 +0100)]
Linux: more flexibility with monotonic clock
Some users have reported that CLOCK_MONOTONIC does not work on their
systems - I suspect it is available on x86 but perhaps not some
of the more uncommon architectures. We should fall back on
CLOCK_REALTIME in these cases.
Also, CLOCK_MONOTONIC_RAW seems even more monotonic, so we should use
that if it is available.
We now test different clock IDs during initialization to find the
best one that works.
Nathan Hjelm [Fri, 11 Sep 2009 17:00:29 +0000 (18:00 +0100)]
Darwin: handle overflows
Daniel Drake [Thu, 27 Aug 2009 15:29:54 +0000 (21:14 +0545)]
v1.0.3 release
Toby Peterson [Sun, 23 Aug 2009 04:19:59 +0000 (10:04 +0545)]
Darwin: 64-bit type fixes
Nathan Hjelm [Sun, 23 Aug 2009 04:17:55 +0000 (10:02 +0545)]
Darwin: fix crash when reading descriptors after close
Fix a crash which occurs if the user does the following sequence on a
device: open, close, get_configuration_descriptor.
Daniel Drake [Sat, 1 Aug 2009 08:10:15 +0000 (13:55 +0545)]
move bug info to bug tracker
Protection needed: http://www.libusb.org/ticket/4
Losing data: fixed in previous commit
Daniel Drake [Thu, 9 Jul 2009 21:09:04 +0000 (22:09 +0100)]
Linux: try harder not to lose any data
We would previously lose any data that was present on a cancelled URB.
Work harder to make sure this doesn't happen.
Daniel Drake [Sun, 28 Jun 2009 18:49:10 +0000 (19:49 +0100)]
Add libusb_get_max_iso_packet_size()
As pointed out by Dennis Muhlestein, libusb_get_max_packet_size()
doesn't really do what the documentation might suggest because it
does not consider the number of transaction opportunities per
microframe.
Add a new function to do what is useful for isochronous I/O.
Daniel Drake [Sat, 20 Jun 2009 21:33:21 +0000 (22:33 +0100)]
Linux: fix sending of zero length bulk packets
Note that there are is a kernel bug preventing this from working
properly at the moment, even after this fix.
Nathan Hjelm [Fri, 19 Jun 2009 21:18:44 +0000 (22:18 +0100)]
Darwin: Don't cancel transfers on timeout
...because the OS does this for us.
Daniel Drake [Sun, 14 Jun 2009 18:23:21 +0000 (19:23 +0100)]
Don't terminate enums with commas
g++ -pedantic doesn't like this
Reported by Eberhard Mattes
Daniel Drake [Sat, 13 Jun 2009 16:19:07 +0000 (17:19 +0100)]
v1.0.2 release
Daniel Drake [Wed, 10 Jun 2009 20:42:05 +0000 (21:42 +0100)]
Linux: fix config descriptor parsing on big-endian systems
Multi-byte fields in the configuration descriptors that come back from
usbfs are always in bus endian format.
Thanks to Joe Jezak for help investigating and fixing this.
Nathan Hjelm [Sun, 7 Jun 2009 21:29:35 +0000 (22:29 +0100)]
Darwin: improve handling of disconnected devices
Nathan Hjelm [Sun, 7 Jun 2009 21:26:37 +0000 (22:26 +0100)]
Darwin: fix parsing of config descriptors
This was a confusion between configuration numbers and zero-based
configuration indexes.
Daniel Drake [Sun, 7 Jun 2009 21:19:53 +0000 (22:19 +0100)]
Eliminate -Wsign-compare compiler warnings
This was due to an API inconsistency which can be safely worked around.
Hopefully we'll remember to fix the API next time we come to break
things.
David Moore [Thu, 28 May 2009 06:15:54 +0000 (23:15 -0700)]
Make synchronous transfer APIs robust against signal interruption
libusb_control_transfer and libusb_bulk_transfer are designed to be
synchronous such that control is not returned until the transfer
definitively succeeds or fails. That assumption is violated if a signal
interrupts these functions because there is no way for the application
to continue waiting for the transfer without resubmitting it. This
patch changes these synchronous APIs so they do not abort in the case of
a signal interruption.
Signed-off-by: David Moore <dcm@acm.org>
Alex Vatchenko [Thu, 28 May 2009 19:58:50 +0000 (15:58 -0400)]
pre-gcc-3.4 compatibility
The -fvisibility and -Wno-pointer-sign options are not available on
old GCC versions.
Daniel Drake [Tue, 26 May 2009 19:53:26 +0000 (15:53 -0400)]
Fix memory leak in config descriptor parsing
Pointed out by Martin Koegler.
Daniel Drake [Tue, 12 May 2009 23:20:51 +0000 (19:20 -0400)]
Update AUTHORS
Daniel Drake [Tue, 12 May 2009 23:03:37 +0000 (19:03 -0400)]
v1.0.1 release
Daniel Drake [Tue, 12 May 2009 23:01:44 +0000 (19:01 -0400)]
Add BUGS file
Probably missed a couple of outstanding issues
Nathan Hjelm [Mon, 23 Mar 2009 01:13:29 +0000 (21:13 -0400)]
Darwin: get_config_descriptor bugfixes
Daniel Drake [Wed, 25 Feb 2009 15:33:33 +0000 (12:33 -0300)]
Fix compilation of Darwin backend
My fault. Reported by ihryamzik@gmail.com
Nathan Hjelm [Tue, 17 Feb 2009 00:39:29 +0000 (21:39 -0300)]
Darwin backend
Nathan Hjelm [Tue, 17 Feb 2009 00:30:49 +0000 (21:30 -0300)]
Make endianness macros endian-independent
Implementation suggested by David Moore. Needed for proper universal
code support on Darwin.
Nathan Hjelm [Tue, 17 Feb 2009 00:25:18 +0000 (21:25 -0300)]
Abstract clock reading into OS layer
This will differ on Linux and Darwin, at least.
[dsd: minor style tweaks]
Daniel Drake [Tue, 17 Feb 2009 00:20:28 +0000 (21:20 -0300)]
Fix endianness in device descriptors
Pointed out by Nathan Hjelm.
Nathan Hjelm [Tue, 17 Feb 2009 00:13:52 +0000 (21:13 -0300)]
Only link with librt on Linux
[dsd: tweak configure.ac change]
Hans Ulrich Niedermann [Sun, 25 Jan 2009 23:31:48 +0000 (00:31 +0100)]
API docs: describe libusb_transfer_cb_fn type
Add some text describing the libusb_transfer_cb_fn function type
with the semantics I have gathered from reading other parts of
the API docs, referring to the proper section for more details.
[dsd: tweaked the description slightly]
Hans Ulrich Niedermann [Sun, 25 Jan 2009 17:21:59 +0000 (18:21 +0100)]
Make empty array in struct compatible with C99
If the compiler is known to be running in C99 mode,
use "flexible array members" ("foo[]").
If the compiler is running in any other mode, continue
using the non-standard but widely common "foo[0]" syntax.
Hans Ulrich Niedermann [Sun, 25 Jan 2009 17:20:45 +0000 (18:20 +0100)]
Avoid signedness errors in API docs example code
Daniel Drake [Sat, 17 Jan 2009 00:25:40 +0000 (00:25 +0000)]
Decrement poll() result when internal pipe has been handled
When we receive data on the internal control pipe, we need to correctly
decrement the number of ready file descriptors before passing on the
remaining work to the OS implementation.
David Moore [Mon, 12 Jan 2009 05:46:17 +0000 (21:46 -0800)]
Prevent transfer from being submitted twice or improperly canceled
This ensures that tpriv->urbs and tpriv->iso_urbs are always set to NULL
whenever a transfer is not submitted. In this way, submit_*_transfer()
and cancel_*_transfer() can error check to ensure that the transfer is
in the correct state to be either submitted or canceled, preventing
potential memory leaks or double frees.
Signed-off-by: David Moore <dcm@acm.org>
David Moore [Thu, 8 Jan 2009 06:31:09 +0000 (22:31 -0800)]
Linux: Fix race condition in cancel_bulk_transfer()
This fixes a race condition in cancel_bulk_transfer(). In the old
version, awaiting_reap and awaiting_discard are incremented in
cancel_bulk_transfer() and decremented in handle_bulk_completion().
However, since these events may take place in two different threads,
these variables may reach zero before all URBs have been canceled,
triggered spurious callbacks and duplicate frees.
This changes the logic to use a single variable "num_retired" to replace
both awaiting_reap and awaiting_discard. num_retired is incremented
only in handle_bulk_completion() and thus there is no race. The handler
will know that all URBs have been canceled when num_retired becomes
equal to num_urbs.
This change also simplifies a great deal of the logic in both functions
and is a net reduction in the amount of code.
Note that some variables such as "reap_action" probably need to still be
protected by a mutex, and this patch does not address that issue.
Signed-off-by: David Moore <dcm@acm.org>
Daniel Drake [Sat, 13 Dec 2008 20:06:49 +0000 (20:06 +0000)]
v1.0.0 release
It's here!
Mikhail Gusarov [Wed, 10 Dec 2008 09:24:05 +0000 (15:24 +0600)]
EOL-whitespace fixes
Signed-off-by: Mikhail Gusarov <dottedmag@dottedmag.ent>
Daniel Drake [Tue, 9 Dec 2008 21:43:37 +0000 (21:43 +0000)]
Linux: fix reading of active configuration
Shannon Chuang pointed out that we only read 1 byte into an
uninitialized integer, and then return the whole thing.
Daniel Drake [Tue, 9 Dec 2008 21:39:11 +0000 (21:39 +0000)]
Fix double free in descriptor parsing error path
Pointed out by Shannon Chuang.
Daniel Drake [Fri, 21 Nov 2008 13:28:32 +0000 (13:28 +0000)]
Improvements to multi-threaded I/O system
Documentation brushed up, and I realised that another function is
needed for tight event handling loops -- they must be able to check
if an open/close operation is trying to interrupt it.
Daniel Drake [Fri, 21 Nov 2008 11:00:47 +0000 (11:00 +0000)]
SourceForge website upload system changed
Daniel Drake [Fri, 21 Nov 2008 10:54:57 +0000 (10:54 +0000)]
v0.9.4 release
Daniel Drake [Thu, 20 Nov 2008 15:31:10 +0000 (15:31 +0000)]
Pause event handling while opening and closing devices
Ludovic Rousseau found that crashes often occur if you close a device
while another thread is doing event handling.
Fix this by adding an internal control pipe, which the close routines
use to interrupt the event handler and obtain the event handling lock,
ensuring that no other thread is handling events while the device is
closed. After the close completes, it signals all the event handlers
to start up again using the usual mechanism.
Also modified libusb_open() to do a similar thing, so that event
handlers are interrupted in order to realise that a new poll fd has
appeared.
Bastien Nocera [Thu, 30 Oct 2008 14:35:23 +0000 (14:35 +0000)]
Add libusb_attach_kernel_driver()
Add support for re-attaching a driver to a device under Linux.
[dsd: fixed handling of return value, and added LIBUSB_ERROR_BUSY case]
Daniel Drake [Sun, 2 Nov 2008 21:45:54 +0000 (21:45 +0000)]
Linux: handle low-level transfer errors
Handle more URB error status codes, thanks to Lou and Alan Stern.
Aurelien Jarno [Thu, 4 Sep 2008 11:50:49 +0000 (13:50 +0200)]
Support for out-of-tree building
Contrary to libusb 0.1, libusb 1.0 does not support out-of-tree building
for the documentation part. This patch fixes that by using a
doxygen.cfg.in file, which contains @top_srcdir@ to refer to the
location of the libusb source code.
Daniel Drake [Sun, 2 Nov 2008 15:00:39 +0000 (15:00 +0000)]
Document the logging style
Suggested by Lou.
Daniel Drake [Thu, 28 Aug 2008 03:44:24 +0000 (22:44 -0500)]
Async I/O documentation touchups
Daniel Drake [Thu, 28 Aug 2008 02:23:10 +0000 (21:23 -0500)]
Doc: fix typo in events lock section
Daniel Drake [Sat, 23 Aug 2008 06:00:21 +0000 (01:00 -0500)]
v0.9.3 release
Daniel Drake [Sat, 23 Aug 2008 05:57:44 +0000 (00:57 -0500)]
Reset internal transfer flags on submit
This fixes a problem pointed out by Lou, where resubmitting a transfer
that previously timed out never timed out again, as if the timeout had
been set to 0.
Daniel Drake [Sun, 10 Aug 2008 22:09:48 +0000 (17:09 -0500)]
Add libusb_get_configuration prototype
Pointed out by Lou
Daniel Drake [Sat, 19 Jul 2008 22:51:28 +0000 (17:51 -0500)]
v0.9.2 release
Daniel Drake [Wed, 16 Jul 2008 14:22:12 +0000 (09:22 -0500)]
Linux: fix sysfs directory handling
The length of the directory name varies, e.g. when you have nested hubs.
Use dynamic allocation to be able to deal with any length of name.
David Engraf [Wed, 16 Jul 2008 14:16:38 +0000 (09:16 -0500)]
Linux: correct usage of MAX_PATH
Thanks to clarification from Artem Egorkine, MAX_PATH already includes
space for the trailing NULL.
Daniel Drake [Wed, 9 Jul 2008 02:15:54 +0000 (21:15 -0500)]
Linux: fix bulk/iso transfer double-cancellation
Reset counters to 0 so that it's possible to cancel a transfer twice
without breaking things. Not sure that I want to support this properly,
but this makes it work at least.
Daniel Drake [Sun, 29 Jun 2008 02:28:44 +0000 (21:28 -0500)]
v0.9.1 release
Daniel Drake [Sun, 29 Jun 2008 02:24:49 +0000 (21:24 -0500)]
Add missing GET_CONTEXT()
Daniel Drake [Sun, 29 Jun 2008 02:18:41 +0000 (21:18 -0500)]
Linux: Compatibility with new sysfs descriptors file
As of 2.6.26, the descriptors file now includes all descriptors, not
just the active one.
Daniel Drake [Fri, 27 Jun 2008 03:47:05 +0000 (22:47 -0500)]
Allow user data pointer to be passed through pollfd notification API
Daniel Drake [Wed, 25 Jun 2008 04:01:51 +0000 (23:01 -0500)]
Introduce contexts to the API
Suggested by David Zeuthen. This allows multiple libraries in the same
process to independently use libusb without interfering.
Daniel Drake [Wed, 25 Jun 2008 02:31:13 +0000 (21:31 -0500)]
Revert "Temporary workaround for event handling serialization issue"
This reverts commit
2d3a1111caff40ebb87983c861ff548cdc9e5946.
This was based on the assumption that dying threads would automatically
release mutexes, which is not the case.