Commit Graph

363 Commits

Author SHA1 Message Date
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
Mark A. Tsuchida
171a521b91 windows: Limit hid_read() return value to buffer length
hid_read() and hid_read_timeout() now return the number of bytes copied,
instead of the number of bytes returned by GetOverlappekdResult() (which is
the maximum report size for the device).  This limits the return value to
the requested length (buffer size), matching the behavior on other
platforms.
2014-07-22 17:35:56 -04:00
Alan Ott
99d0219a87 configure: Check for Fox 1.7 as well as Fox 1.6 for the testgui
The testgui will work with both, so check for them both at
configure time.

This came from Alex Barker <alex@1stleg.com> and was posted on github.
2014-07-22 17:27:42 -04:00
Scott Talbert
627f3aa478 windows: Set the OS report buffer size to 64 reports
Resolves issues with dropped input reports when receiving a large amount
of data.
2014-07-22 16:53:23 -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
Benedikt Wildenhain
56e8c3939f hidtest: Remove "All Rights Reserved" from hidtest.cpp
The language may be confusing for this file, since the hidtest.cpp file
may be used by anyone for any reason.
2014-07-22 15:51:53 -04:00
Klee Dienes
3a66d4e513 linux: Better kernel version detection
Refactor version detection into a function.
Handle versions of form X.Y.Z as well as X.Y.
Don't do workarounds for old kernels if version cannot be detected.
2013-12-12 22:31:55 -05:00
Alan Ott
1a42177fa5 header: Clarify comment on hid_read() and hid_read_timeout()
Clarify that a return value of zero means no packet was available.
2013-11-01 09:38:31 -04:00
Alan Ott
40cf516139 HIDAPI 0.8.0-rc1 hidapi-0.8.0-rc1 2013-10-06 18:43:37 -04:00
Alan Ott
4ecb5a6903 autotools: Add mac_support.h to Makefile.am
Not sure how this got missed.
2013-10-06 18:43:37 -04:00
Alan Ott
837ba31050 testgui: Remove pre-built testgui executable
Executables should have never been in the repo to begin with.
2013-10-06 17:55:21 -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
Alan Ott
a88c7244d6 mac: Fix incorrect device list after device removal
On Mac OS X 10.8.x (Mountain Lion), if a device is connected, opened, then
closed, then unplugged, subsequent calls to hid_enumerate() will still
list the device (even though it's been unplugged).  If the device is
plugged in again, a second instance will show up in the list and often it
will be impossible to open either.  Github user TamToucan figured out that
in hid_enumerate() if a call is made to IOHIDManagerSetDeviceMatching()
before the call to IOHIDManagerCopyDevices() that this will clear the
problem.

Thanks to TamToucan for figuring this out.
2013-09-09 09:39:31 -04:00
Alan Ott
1ec76ad9bd README: Add build dependencies
Some build system dependencies were missing from the documentation.
2013-09-09 00:18:00 -04:00
Spencer Oliver
4e6e9ffe86 gitignore: add config.* to .gitignore
This makes HIDAPI less noisy when used a git submodule.

Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
2013-09-08 22:23:46 -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
Alan Ott
776ec62dfc windows: Fix leak of event handle on open_device() failure
Create a new free_hid_device() function which takes care of all the
resources in hid_device which may need to be freed/released.

Reported-by: Johan Lindh <johan@linkdata.se>
2013-04-23 13:56:06 -04:00
Alan Ott
f75f6f735d mac: Unregister the proper removal callback in hid_close()
Unregister from IOHIDManager instead of IOHIDDevice.

Thanks to github user tomsor for noticing this.
2013-03-05 18:05:25 -05:00
Alan Ott
119135b8ce linux: Use poll() even in non-blocking mode
It appears that calls to read() when in non-blocking mode will not set errno
to other than EAGAIN when the a device has been disconnected.  Note that
this is the same errno code set when there is simply no data to return.

Make it so that poll() is used, in non-blocking mode, to check the
status of the device. In blocking mode though, poll() is not needed.
2013-01-21 13:19:23 -05: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
Alan Ott
b20777fc0c testgui: more robust handling of report length fields
Improve logic of report length field handling for empty fields.
Add column headers for data and length fields.
Add documentation statement about length fields.
Increase window size.
Add message boxes when invalid values are entered.
memset() buffers to zero.
2012-11-26 22:27:24 -05:00
Michael Pisarski
1fba3f98f0 testgui: Add fields for lengths of reports
Windows platforms return errors When you do not specify the proper buffer
size and length.
2012-11-26 22:27:24 -05:00
Nikolaj Løbner Sheller
0ed94093c8 windows: replace magic number 2 with sizeof(wchar_t)
Changed for readability, as I think this is what was intended by
the author.
2012-11-26 20:30:09 -05:00
Alan Ott
c6f2900275 Merge branch 'master' of github.com:signal11/hidapi 2012-11-26 20:20:43 -05:00
Justin R. Cutler
b0e2fb8d35 libusb/mac: gcc -pedantic warning fixes 2012-11-26 20:20:13 -05:00
Justin R. Cutler
b5b15d0d83 windows: mingw: minor gcc -pedantic warning fixes 2012-11-26 20:00:48 -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
Stan Hu
d5710b4f96 linux: Fix memory leaks on serial number and product name
In get_device_string() serial_number_utf8 and product_name_utf8 could end
up not getting freed if certain errors occurred.
2012-11-26 15:07:51 -05:00
Stan Hu
1774c81f04 linux: check for EINPROGRESS from read()
Non-blocking I/O can cause read() to return EINPROGRESS in addition to
EAGAIN.  Handle this case.
2012-11-26 15:03:10 -05:00
Stan Hu
901fbe9e39 mac: Use Location ID in make_path instead of pointers
Using locations makes the path the same for each run of a HIDAPI based
program.  This is useful for opening devices which don't have a serial
number, and where multiple devices of the same type are attached to the
system at once.

This references pull request #78.
2012-11-26 14:31:17 -05:00
Alan Ott
dc6c170672 mac: Fix string handling
There were errors regarding the length of strings in conversion from CFString
to wchar_t.

Thanks to github user nikolajsheller for pointing this out in pull request #80.
2012-11-26 13:59:33 -05:00
Ludovic Rousseau
54d32f6aa3 mac: Use exclusivce device access
Use kIOHIDOptionsTypeSeizeDevice instead of kIOHIDOptionsTypeNone to
avoid interferences with other applications trying to use the HID device
at the same time.
2012-11-26 13:35:12 -05:00
Ludovic Rousseau
f74e0c64e8 hidtest: Use hid_init()
Use hid_init() in hidtest/hidtest.cpp
2012-11-26 13:34:54 -05:00
Ludovic Rousseau
e569477ef1 README.txt: Improve sample code
- use hid_init()/hid_exit()
- include windows.h only on Windows
2012-11-26 11:21:55 -05:00
Ludovic Rousseau
1826eabaef linux/hidraw: Fix compiler warning
hid.c: In function 'uses_numbered_reports':
hid.c:126:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
hid.c:143:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
2012-11-26 11:21:42 -05:00
Ludovic Rousseau
85d608e80e Linux: Fix warning: function declaration isn't a prototype
linux/hid.c:83:13: warning: function declaration isn't a prototype [-Wstrict-prototypes]
linux/hid.c: In function 'new_hid_device':
linux/hid.c:83:13: warning: old-style function definition [-Wold-style-definition]
2012-09-21 10:51:34 -04:00
Ludovic Rousseau
8def28f09d Mac, Linux: Remove extra spaces at end of lines 2012-09-21 10:51:26 -04:00
Ludovic Rousseau
5d2b6b8eab Mac: Fix warning: function declaration isn't a prototype
hid.c:386: warning: function declaration isn't a prototype
2012-09-21 10:51:15 -04:00
Ludovic Rousseau
c279c1d25b Linux: Fix warning: comparison between signed and unsigned
mbstowcs() returns a size_t not an int.

hid.c: In function 'get_device_string':
hid.c:285:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
hid.c:289:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
hid.c:318:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
2012-09-21 10:49:22 -04:00
Ludovic Rousseau
bfb2b5924d Linux: Remove unused function register_error()
Fix compiler warning
hid.c:93:13: warning: 'register_error' defined but not used [-Wunused-function]
2012-09-21 10:49:09 -04:00
Ludovic Rousseau
61757847c4 Linux: Fix warning: enumeration value not handled in switch
hid.c:282:5: warning: enumeration value 'DEVICE_STRING_COUNT' not handled in switch [-Wswitch-enum]
2012-09-21 10:49:03 -04:00
Ludovic Rousseau
6761e3f5ba Linux: Fix warning: no previous prototype
hid.c:190:1: warning: no previous prototype for 'parse_uevent_info' [-Wmissing-prototypes]
2012-09-21 10:48:54 -04:00
Ludovic Rousseau
367fc3f3aa linux: Fix bug on mbstowcs() usage
In case of error mbstowcs() returns (size_t) -1
It is not a negative value since mbstowcs() returns a size_t (unsigned)

Fix compiler warning:
hid.c: In function 'utf8_to_wchar_t':
hid.c:105:3: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
2012-09-21 10:48:36 -04:00