Commit Graph

42 Commits

Author SHA1 Message Date
Erik OShaughnessy 7620bc7faa Guard against zero length buffers in hid_write (#279) 2021-06-14 04:09:13 +03:00
Ihor Dutchak c7a2339b05 libusb: add support for potential Android JNI backend 2021-05-18 16:39:01 +03:00
Ihor Dutchak f6d0073fcd hidraw/libusb: fix -Wall -Wextra -pedantic -Werror compilation (#214)
- minor code-style fixes;
2020-11-24 13:39:27 +02:00
Ihor Dutchak d2c3a9862e libusb: fix race condition on device close (#189)
Read callback may fire itself on its own even after its been
requested to stop and exactly before the calling code
waits for its completion in indefinite loop.

Explicitly preventing re-fireing the submission loop,
fixes the issue.

Fixes: #142.

Signed-off-by: Ihor Dutchak <ihor.youw@gmail.com>
2020-10-14 18:43:26 +03:00
Ihor Dutchak 8f72236099 add hid_version/hid_version_str API (#192)
- API functions to get runtime version of the library;
- macros to get static/compile-time version of the library;
- VERSION file;
2020-10-14 18:41:08 +03:00
CodeforEvolution f2611e0237 Changes to Build System for Haiku
Co-authored-by: @CodeforEvolution
Co-authored-by: Luca Weiss <luca@z3ntu.xyz>
Co-authored-by: Begasus <begasus@gmail.com>
Co-authored-by: Panagiotis Vasilopoulos <hello@alwayslivid.com>
2020-02-12 17:00:07 +02:00
wet34t 533dd9229a libusb: allow hidapi to be configured without using iconv 2020-02-09 15:22:22 +02:00
Fredrik Fornwall 90ddfc61b7 Fix build when targetting Android 7 or later
Support for pthread_barrier was introduced in Android 7, so trying to
build a custom implementation of that clashes with the system headers.
2020-01-22 14:05:08 +02:00
Luca Weiss 51bdec7844 Fix manual Makefiles and add CI for them (#131) 2020-01-12 04:09:48 +02:00
Daniel Van Noord 083223e779 Added support for Get Input Report (#59)
- Get Input Report supported on linux/libusb, mac and windows;
- linux/hidraw doesn't support it on kernel level;
2019-11-15 13:55:51 +02:00
Mayank Suman fa75ffb743 Reattach kernel driver in hidapi-libusb 2019-10-31 12:56:00 +02:00
Andrew Eikum 93dca80762 Update more repository URLs 2019-07-25 07:57:59 +02:00
Luca Weiss b0ec6f0918 libusb: Return string in hid_error() 2019-07-15 13:15:46 +03:00
luz.paz f01c4ede50 Misc. typo fixes
Found via `codespell -q 3`
2019-07-14 13:54:55 +02:00
Luca Weiss 95adae423d Fix compile warning on FreeBSD
hid.c:458:18: warning: passing 'const char **' to parameter of type 'char **' discards qualifiers in nested pointer types
      [-Wincompatible-pointer-types-discards-qualifiers]
        res = iconv(ic, &inptr, &inbytes, &outptr, &outbytes);
                        ^~~~~~
/usr/local/include/iconv.h:85:43: note: passing argument to parameter 'inbuf' here
extern size_t iconv (iconv_t cd,  char* * inbuf, size_t *inbytesleft, char* * outbuf, size_t *outbytesleft);
                                          ^
1 warning generated.
2019-07-13 22:32:10 +03:00
iakov c022f55080 Remove excess incorrect space
Co-Authored-By: Filip Kubicz <Qbicz@users.noreply.github.com>
2019-06-24 22:55:27 +02:00
Iakov Kirilenko 73b9ccb996 Explicit cast from void* to corresponding type
Fix compilation without -fpermissive
2019-06-24 22:55:27 +02:00
Luca Weiss 2f7a7c9948 Rename hid_device* parameters to dev
Previously, the header file used hid_device *device and the
implementations used hid_device *dev. Make this consistent.
2019-06-17 11:32:48 +02:00
Diego Herranz a6a622ffb6 all: Fix a few typos 2016-09-19 23:40:12 -04:00
Tobias Rehbein 0cbc3a409b libusb: Adapt to FreeBSD 10
FreeBSD 10 has libusb_get_string_descriptor() in base libusb, so don't
define it here.
2014-07-23 16:50:14 -04:00
Pavol Rusnak 417b2bf081 libusb: Add Android support
This code originally came from Pekka Nikander <pekka.nikander@senseg.com>
2014-07-23 16:40:51 -04:00
Michael Hanselmann ac6120b589 libusb: Fix null pointer dereference in hid_open()
Make sure hid_device_info.serial_number is not null before passing it to
wcscmp().

When libusb can't open a device for any reason (e.g. file system
permissions), hid_device_info.serial_number is NULL. Make sure
hid_device_info.serial_number is not null before passing it to wcscmp(3).

Signed-off-by: Michael Hanselmann <public@hansmi.ch>
2014-07-22 17:38:16 -04:00
Scott Talbert 6a4743ee59 libusb: Include PTHREAD_CFLAGS when linking libhidapi-libusb
m4/ax_pthread.m4 says that PTHREAD_CFLAGS needs to be provided to the
linker line as well as the compile line.  This enables static library
builds of hidapi.
2014-07-22 16:39:30 -04:00
Scott Talbert 54db8ca208 libusb: Add support for compiling on Debian/kFreeBSD 2014-07-22 16:29:52 -04:00
Mario Kleiner 996dafd2a8 libusb: Fix 'dev' memory leak on hid_init() failure.
Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
2013-10-06 17:36:27 -04:00
Bei Zhang 2e27f98b3e all: Fix license name
"GNU Public License" does not exist. It is called "GNU General Public
License", "GNU GPL" or simply "GPL".
2013-10-06 17:33:44 -04:00
Hans de Goede 02a882c890 libusb: Properly wait for transfer cancellation on read_thread() exit
While triaging libusb bugs, I took an indepth look at:
https://github.com/libusbx/libusbx/issues/25

This has lead me to the conclusion that there are 2 issues with hidapi's
libusb code wrt waiting for the transfer cancellation on read_thread()
exit:

1) There is a race where hid_close() can successfully cancel the transfer
after a read_callback() has submitted it but before read_thread() checks
shutdown_thread.  If this race is hit, then the libusb_cancel_transfer()
in read_thread() will fail, causing read_thread() to not call
libusb_handle_events() to complete the cancelled transfer.  hid_close()
will then free the transfer, and if later on libusb_handle_events() gets
called on the same context, it will try to complete the now freed
transfer.  This is what I believe leads to the segfault described in
https://github.com/libusbx/libusbx/issues/25

2) hidapi uses one read_thread() per hid_device, so if there are multiple
hid_devices then there are multiple threads calling
libusb_handle_events(), in this case there is no guarantee that a single
libusb_handle_events() call will successfully lead to the cancelled
transfer being completed.  If the transfer completion is already handled
by another read_thread() and there are no other events, then the
libusb_handle_events() call will hang, and thus the pthread_join() and
thus hidapi_close() will hang.

As number 2 is a generic problem found in more libusb apps, libusb has
gotten a new API called libusb_handle_events_completed(), which takes an
extra pointer to an int, whose contents must be set to nonzero on
completion by the callback, which allows waiting for the completion of a
specific transfer in a race-free manner.

This patch switches the waiting for the transfer's final completion to
using libusb_handle_events_completed(), thereby fixing both issues.  Note
the while is necessary since libusb_handle_events_completed(), like
libusb_handle_events(), will return as soon as it has handled *any* event.
The difference with libusb_handle_events_completed() is that once it has
all the necessary internal libusb locks, it checks the contents of the
completed parameter, and will bail if that has become nonzero without
waiting for further events.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2013-09-08 21:50:36 -04:00
Spencer Oliver a991328721 linux/libusb: do not check bDeviceClass on enumeration
Some composite devices do not have bDeviceClass set to
LIBUSB_CLASS_PER_INTERFACE and were ignored when enumerating HID devices.

Ignore checking the bDeviceClass as we will be checking interface
bInterfaceClass later anyway.

Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
2013-01-21 12:04:03 -05:00
Atsushi NAGASE ba5612e37f libusb: check for failure of hid_init()
Return NULL from hid_enumerate() and hid_open_path() if hid_init() fails.
2013-01-21 11:57:51 -05:00
Ludovic Rousseau 0d7c7ef066 libusb: remove extra spaces
Remove spaces and tabs at end of lines.
2012-11-28 10:33:43 -05:00
Ludovic Rousseau ec24f93100 all: make hid_enumerate() able to match any vendor or any product
Passing product_id=0 will match any product of a given vendor.  This patch
makes it also possible to use vendor_id=0 to match any vendor for a given
product id.

Windows code added to Ludovic's patch by Alan Ott.
2012-11-27 22:12:35 -05:00
Justin R. Cutler b0e2fb8d35 libusb/mac: gcc -pedantic warning fixes 2012-11-26 20:20:13 -05:00
Justin R. Cutler 69a91a8f6c All: Convert C99 comments (//) into C89 comments (/* */) 2012-11-26 18:49:51 -05:00
Justin R. Cutler 3bfaffbfe0 linux: fix gcc warnings when INVASIVE_GET_USAGE is defined. 2012-11-26 15:29:01 -05:00
Alex Dupre 645a0c357a FreeBSD: Conditionally remove calls to libusb_detach_kernel_driver()
libusb_detach_kernel_driver() is not needed on FreeBSD.
2012-07-16 00:52:43 -04:00
Alex Dupre 49021efd0f FreeBSD: Add $(LIBS) to libhidapi.so target (Makefile.freebsd) 2012-07-16 00:52:17 -04:00
Alan Ott 6d50f8fa0f Add Autotools build system (automake, autconf)
This adds the familiar autotools build system and associated documentation
for Linux, FreeBSD, Mac, MinGW, and Cygwin.  The old Makefiles have been
kept, and where appropriate have been renamed Makefile-manual.

Thanks to Peter Stuge, Ludovic Rousseau, Xiaofan Chen, Alex Dupre, and
Segher Boessenkool for providing testing, review, and suggestions, and to
Ludovic Rousseau for providing patches which contributed to this commit.
2012-07-16 00:43:04 -04:00
Alan Ott 38a7bf75f0 Renamed manual makefiles so they're out of the way of autotools
Files named Makefile which will conflict with autotools have been renamed to
Makefile-manual.
2012-07-16 00:43:04 -04:00
Sean M. Pappalardo 308ab89a26 Libusb: Prevent bailing out of read_thread() on non-critical errors 2012-05-18 13:12:28 -04:00
Alan Ott bdb87db5b8 Libusb: testgui: Explicitly link to libpthread.
Reported by: Xiaofan Chen <xiaofanc@gmail.com>
2012-05-03 22:25:40 -04:00
Alex Dupre 498fbb42f9 Libusb: Cleanup
Remove unnecessary initialization in new_hid_device()
Remove unnecessary NULL-termination in usb_get_string()
2012-05-02 18:55:37 -04:00
Alan Ott 74440e2dbb FreeBSD: Add FreeBSD implementation.
This adds a FreeBSD implementation to HIDAPI using the libusb back-end. The
libusb/ folder now contains the libusb implementation and associated
Makefiles for Linux and FreeBSD. All libusb code has been removed from the
linux/ folder, so that the code in libusb/ can be shared by both (and
future) platforms.

This commit renames linux/hid-libusb.c to libusb/hid.c. Make sure to
use git log --follow to see full history of that file.

This code was written by:
 Alex Dupre <ale@FreeBSD.org>
 Alan Ott <alan@signal11.us>
2012-05-02 18:55:28 -04:00