Commit Graph

129 Commits

Author SHA1 Message Date
hjelmn@cs.unm.edu
1eff220474 Misc: Revert all references to libusb/libusb.info 2014-01-08 23:51:01 +00:00
Ludovic Rousseau
30747cee3f 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
2013-12-06 17:02:49 +01:00
Paul Fertser
c089900c48 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>
2013-08-21 16:04:08 +02:00
Hans de Goede
a06eafdc52 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>
2013-08-21 14:46:45 +02:00
Sean McBride
ea6c827af0 fixed some clang -Wdocumentation warnings from bad doxygen markup 2013-07-30 10:44:02 -06:00
Pete Batard
b4c18fac65 Doc: update hotplug, topology and descriptor documentation
* Also fix some typos
* Closes #95
2013-07-04 18:39:22 +01:00
Luca Longinotti
88828bd7c8 Fix several -Wconversion warnings from GCC inside the static inline functions.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2013-06-19 11:17:59 +02:00
Hans de Goede
fc51f19341 libusb: Add auto-detach-kernel-driver functionality
Add auto-detach-kernel-driver functionality, and a
libusb_set_auto_detach_kernel_driver() function.

Note that I went with a libusb_set_auto_detach_kernel_driver() function,
rather then with a libusb_enable_auto_detach_kernel_driver(), so that apps
can also disable it again. This is necessary to handle 2 corner cases:

1) When an app wants to do a libusb_set_configuration after claiming 1 or
more interfaces, it needs to first release the interface(s), and in this
case libusb_release_interface() should *not* (re-)attach the kernel driver

2) Some usb classes use multiple interfaces for one function, ie usb-audio
devices do this. In this case attaching the driver will fail until all
interfaces are released, so the app should first release all interfaces, and
only then (re-)attach the kernel driver.

auto-detach-kernel-driver functionality is still useful for these apps, since
doing libusb_detach_kernel_driver() followed by libusb_claim_interface() in
2 separate calls is inherently racy, but they need to be able to disable the
auto-detach functionality before releasing interfaces to be able to properly
handle the 2 described corner cases.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2013-06-19 11:04:14 +02:00
Hans de Goede
511ed18228 Core: Add a libusb_strerror() function
This patch adds the much requested libusb_strerror() function, taking into
account all issues people raised wrt previous attempts.

Criteria / Decisions underlying this implementation:
- Must support translated messages
- Must not use gettext as that does not work well in combination with Windows
 (when building with Visual C, or for Windows CE)
- API compatible with FreeBSD and various patched libusb-s floating around
- KISS:
 - Do not add any (other) library dependencies
 - Do not try to deal with message encodings (iconv), simply always return UTF-8
   making encoding the problem of the application using libusb_strerror.
 - Defaults to English, so apps which don't want translated messages,
   don't need to do anything special
 - Defaults to English (with pure ASCII messages), so apps which don't
   call libusb_setlocale() don't need to worry about encoding
2013-06-10 00:16:36 +01:00
Hans de Goede
d7b796f1fe Add BOS descriptor support
Based on earlier work done on this by Maya Erez <merez@codeaurora.org>,
Nathan Hjelm <hjelmn@me.com> and Pete Batard <pete@akeo.ie>.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2013-05-30 14:20:51 +02:00
Hans de Goede
ef698c633d Add superspeed endpoint companion descriptor support
Based on earlier work done on this by Maya Erez <merez@codeaurora.org>,
Nathan Hjelm <hjelmn@me.com> and Pete Batard <pete@akeo.ie>.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2013-05-30 14:20:44 +02:00
Hans de Goede
4d7789be7e core: Add a new public libusb_get_port_numbers function
This new function replaces the now deprecated libusb_get_port_path function,
as that is the only function operating on a libusb_device which also takes
a libusb_context, which is rather inconsistent.

Note we will keep libusb_get_port_path around in the 1.0.x for the forseeable
future for ABI compatibility reasons, but it should not be used in any new
code.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2013-05-17 10:36:32 +02:00
Hans de Goede
86031e26ad Bump LIBUSBX_API_VERSION for new hotplug API
And document the minimum version under which hotplug is supported

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2013-05-15 20:43:35 +02:00
Nathan Hjelm
7801ff94fa Add hotplug support.
The internal API is changing as follows:
 - Adding two new functions. usbi_connect_device, and usbi_disconnect_device.
   Backends must call these functions to add them to the context's device list
   at one of two places: initial enumeration (done at init), and on device
   attach and removal. These functions need to be called once per context.
 - Backends that support hotplug should not provide a get_device_list funtion.
   This function is now deprecated and will likely be removed once all backends
   support hotplug.

The external API is changing as follows:
 - Two new functions have been added to register and deregister callbacks for
   hotplug notification: libusb_hotplug_register_callback(),
   libusb_hotplug_deregister_callback(). Hotplug callbacks are called by
   libusb_handle_events(). Details of the new API can be found in libusb.h.
 - A new capability check has been added to check for hotplug support. See
   LIBUSB_CAP_HAS_HOTPLUG.

Aa suggested by Xiaofan add new example has been added to show how to use
the new external hotplug API. See examples/hotplugtest.c.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2013-05-15 17:28:06 +02:00
Hans de Goede
2790e8f2b0 libusb.h: Correct errors in doxygen comment for struct libusb_device
The comment refers to the non-existing libusb_device_ref and
libusb_device_unref functions, this should be libusb_ref_device resp.
libusb_unref_device.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2013-04-23 11:15:39 +02:00
Pete Batard
e0628c566a Core: Add HID and kernel detach capability detection for all backends
* Also remove Linux special case from xusb sample.
* Note that LIBUSBX_API_VERSION is incremented as a result of
  libusb_has_capability() returning nonzero rather than 1 when
  a capability is supported.
* A LIBUSB_CAP_HAS_HOTPLUG is also added, though it is currently
  not implemented on any platform
* Closes #102
2013-04-02 19:13:47 +01:00
Pete Batard
0ded9c126e Misc: Simplify includes and misc. cleanup
* fxload sample provenance
* No need for <sys/types.h> in samples as already in libusb.h
* Don't bother about sscanf_s in xusb
* Use HAVE_### and rely on config.h where possible
* Formal inclusion of <winsock.h> in libusb.h for WinCE and WDK
* Cleanup of Windows' config.h
* Avoid ENAMETOOLONG and ENOTEMPTY conflict between errno.h and winsock.h for WinCE
* Additional newlines & braces cleanup
2013-02-27 22:58:49 +00:00
Toby Gray
244271931a WinCE: Add support for WinCE (sources) 2013-01-23 00:40:18 +00:00
Pete Batard
f17d190f0f libusbx-1.0.14 2012-09-25 23:52:40 +01:00
Pete Batard
517f9827c4 Doc: Fix doxygen warnings and issues
* Remove obsolete tags
* Use QUIET = yes to make issues more prominent
* Fix code display for LIBUSBX_API_VERSION and missing parameter
  documentation for libusb_get_port_path()
* Most of the above suggested by Ludovic Rousseau
2012-09-16 17:23:48 +01:00
Pete Batard
9d368fc477 Core: Introduce LIBUSBX_API_VERSION macro
* This macro can be used to detect if the version of libusbx being
  compiled against has a specific API feature, as well as to detect
  whether compilation occurs against libusb or libusbx.
2012-09-15 23:57:21 +01:00
Hans de Goede
75b94b24cf Core: Make libusb_error_name also handle transfer status codes
Note that for the code 0 which means success resp. completed we have an
overlap in the codes. This is not a problem since normally one would not
call libusb_error_name on success / normal completion.
2012-09-15 23:29:32 +01:00
Pete Batard
3f513b6246 Core: Update libusb.h header in accordance with the latest USB specs
* IMPORTANT: This update fixes a typo in the API where MaxPower was being
  used instead of bMaxPower, with the latter being what is actually in
  the specs.
* As a result, applications that were using MaxPower need to be updated
  for bMaxPower.
* If you must maintain compatibility with libusb or older versions of
  libusbx, you may also want to either use a #define or copy/paste
  struct libusb_config_descriptor from libusb.h under a new name, and
  then use a cast on calls that require it. For more info, see the
  1.0.13 release notes in the NEWS file.
* Also update copyright notice
2012-09-15 02:05:24 +01:00
Anthony Clay, ZarthCode LLC
c86fb21a3b Windows: Fix C4005 warning under VS2012 for inline.
* Changed inline macro to not fire when using Visual Studio/C++,
  which attempts to redefine the macro - resulting in a C4005 warning.
2012-08-20 01:14:44 +01:00
Pete Batard
7ec94a45ed Core: Prefix LOG_LEVEL_ with LIBUSB_ to avoid conflicts
* The LOG_LEVEL_ enums, that were moved to the public API
  in 933a319469 may conflict
  with applications/headers that also define their own
  LOG_LEVEL_ values internally.
* As a matter of fact, as per Trac #31, this produces a
  conflict with libusb-compat, as it defines its own levels.
2012-07-03 11:01:41 +01:00
Pete Batard
933a319469 Core: Define log levels in libusb.h
* Also update xusb sample to use these levels
2012-05-28 10:35:23 +01:00
Pete Batard
cfb8610242 All: Add parent and port topology calls
* Adds libusb_get_port_number, libusb_get_parent and libusb_get_port_path
* Linux implementation provided by Alan Stern, OS X by Nathan Hjelm
* Unsupported for *BSD platforms
2012-05-28 10:26:44 +01:00
Pete Batard
a544e5972b Misc: Ensure all sources are UTF-8
* Also remove extra lines at the end of samples
2012-05-23 18:25:01 +01:00
Pete Batard
00d61a396c Core: update version struct for ABI compatibility
* Adds a static string for describe
* Also update version documentation
2012-04-26 00:39:17 +01:00
Pete Batard
37dfd16c8c Core: Add get_version() call
* Also some formatting/typo improvements
2012-04-10 12:46:10 +01:00
Pete Batard
b49cfaec78 Misc: Fix missing libsub's -> libusbx's from previous patches 2012-04-03 16:32:10 +01:00
Pete Batard
791b7473ec Misc: Rebrand to libusbx
* Mentions of 'libusb' in doxygen are changed to 'libusbx'
* Also update copyright notices and remove unneeded EOF LFs
2012-04-03 15:42:10 +01:00
Peter Stuge
e3d0a4cb9e Add LIBUSB_TRANSFER_ADD_ZERO_PACKET flag to indicate need for ZLP
Some protocols which use USB require an extra zero length data packet
to signal end-of-transfer on bulk endpoints, if the last data packet
is exactly wMaxPacketSize bytes long.

This flag allows applications to inform libusb about this requirement,
so that libusb can handle the issue transparently.

At the moment the new flag is only supported on Linux, and submitting
a transfer with the flag set returns an error at submit time on other
systems. Hopefully implementations will soon follow for other systems.

References #6.
2012-02-22 14:21:54 +01:00
Peter Stuge
7e0c747cc5 libusb.h: Add comma after last value in enums to ease future expansion 2012-02-19 06:58:16 +01:00
Michael Plante
bb37939ab4 libusb.h: Cast in libusb_get_string_descriptor() to avoid MSVC6 warning
On MSVC6 bitwise OR promotes to int, causing the warning.
2012-02-08 14:46:17 +01:00
Pete Batard
fdbac89712 Windows: Add uint32_t typedef for old MSC so that DDK can build lsusb 2011-10-17 16:25:51 +02:00
Peter Stuge
1b0f758a33 Add libusb_error_name() API function
Until we have i18ned error messages we can at least offer easy
translation from numeric error code to the error code's name.

[hansg: switch() on enum to get a compiler warning if a case is missing]
[hansg: Better return value when called with an unknown error code]
[hansg: Fix DEFAULT_VISIBILITY in definition to compile on all platforms]
2011-10-17 16:25:50 +02:00
Peter Stuge
e16805130a Add libusb_has_capability() API function
Since it is currently not planned to change the filename of the libusb
library between libusb-1.0 versions at least on Windows systems it's
important to have a capability API.

Currently there exists only one capability; LIBUSB_CAP_HAS_CAPABILITY,
which tests support for the libusb_has_capability() API.
2011-10-17 16:23:54 +02:00
Graeme Gill
6696512aad Fix #56 race condition causing delayed completion of sync transfers
The sync API had a race where it would check a condition to know if it
needed to call a libusb_handle_events() function. However, the check
was done outside of the lock that is held while the condition is set,
so another thread could completely serve whatever was needed to make
the condition true between it being checked and the event handler being
called. This situation would be detected after a libusb-internal timeout
of 60 seconds, after which the transfer would be completed without
error, but with significant delay.

Original patch at http://marc.info/?l=libusb-devel&m=127252114815709

Changes by Hans de Goede:
- Renamed the "race-proof" functions from libusb_handle_events*_check()
  to libusb_handle_events*_completed()
- Drop r = 0 setting in libusb_handle_events_timeout_completed()
  (to make both completed checking cases identical flow wise)

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
[stuge: Simplify libusb_handle_events_timeout() change with a goto]
[pbatard: Fix _handle_events_timeout() and _completed() definitions]
2011-09-22 11:25:29 +02:00
Nathan Hjelm
d1bd234f7e Fix #64 use of reserved identifiers throughout libusb 2011-09-22 10:46:48 +02:00
Hans de Goede
c8c40bcbd2 Add new API function libusb_get_device_speed()
Reworked version of my earlier patch, largely modelled after (if not
copy and pasted from) Trygve Laugstøl's <trygvis@inamo.no> similar
commit 5a6541e0d80fb1f21e2b960bc2337a612f9d74fb in
git://git.libusb.org/libusb-trygvis.git
http://git.libusb.org/libusb-trygvis.git
http://git.libusb.org/?p=libusb-trygvis.git;a=commitdiff;h=5a6541e0d

This patch does not add any OS specific code. The supporting code in
each backend follows in separate patches. References #45.

Signed-off-By: Hans de Goede <hdegoede@redhat.com>
2011-09-15 15:16:04 +02:00
Peter Stuge
d3543e9140 libusb.h: Add missing LIBUSB_CLASS_ codes currently defined by usb.org
LIBUSB_CLASS_PHYSICAL
LIBUSB_CLASS_SMART_CARD
LIBUSB_CLASS_CONTENT_SECURITY
LIBUSB_CLASS_VIDEO
LIBUSB_CLASS_PERSONAL_HEALTHCARE
LIBUSB_CLASS_DIAGNOSTIC_DEVICE

Per http://www.usb.org/developers/defined_class
2011-07-24 22:29:10 +02:00
Peter Stuge
08bc7ffb6a libusb.h: Add LIBUSB_CLASS_IMAGE in addition to LIBUSB_CLASS_PTP
The old LIBUSB_CLASS_PTP name is kept for compatibility. Fixes #106.
2011-07-24 22:29:10 +02:00
Peter Stuge
3d7938d85a libusb.h: Fix LIBUSB_CLASS_PRINTER description typo
References #106.
2011-07-24 22:29:10 +02:00
Pete Batard
c1e7543141 Windows: MS project files part 1 - support files & preliminaries
* adds the MSVC support files used by MSVC6, VS2005 and WDK
* also adds missing defines required by MS compilers in libusb.h
* also anticipatory sets .gitattributes for CRLF handling
* also adds manually maintained .def file for import lib generation

References #57.
2011-06-13 22:06:30 +02:00
Peter Stuge
4be84ab49c Revert libusb_strerror() until we have i18n and l10n 2011-06-13 22:06:30 +02:00
Pete Batard
29f9f9e3af Introduced calling convention (for Windows)
Under Windows, a variety of compilers and configurations are available,
meaning that the manner of parameter passing (e.g. registers vs stack)
can vary.

Match the Windows API calling convention and document this appropriately.
This calling convention will be used regardless of the configuration of
the user's development platform.

The only user-level complication is that all functions used as libusb
callbacks must use the same calling convention as libusb. The
LIBUSB_CALL macro is provided to make this easy.

Signed-off-by: Michael Plante <michael.plante@gmail.com>
Signed-off-by: Pete Batard <pbatard@gmail.com>
[dsd: slight change of strategy, add documentation]
2010-08-23 18:48:55 -06:00
Xiaofan Chen
fe5d1d2050 Fix inconsistencies between prototypes and definitions
This removes some warnings on cygwin regarding a name clash against
the standard library "index" function.
2010-08-02 21:24:06 -06:00
Pete Batard
9a4249f8a1 Add Windows support
Via Cygwin/MinGW, libusb now has windows support.
Thanks to contributors: Michael Plante, Orin Eman, Peter Stuge,
Stephan Meyer, Xiaofan Chen.
2010-07-27 20:57:20 -06:00
Daniel Drake
7211aba6e2 Only include sys/time.h on appropriate platforms
This header doesn't exist on windows.
For libusb, determine at configure-time if the header is available.
For libusb.h, use gcc predefined macros to only include the header
on platforms that need it.
2010-06-25 12:01:58 -05:00