Commit Graph

76 Commits

Author SHA1 Message Date
Ihor Dutchak
95e6b98ce9 Add hid_read_error (#721)
hid_read_error is a separate error function, that returns error status of hid_read/hid_read_timeout.
hid_read/hid_read_timeout is no longer changes internal buffer used by hid_error and it makes it safe to use hid_read/hid_read_timeout from a separa thread, concurently with other device functions.
2025-03-11 19:26:36 +02:00
Megamouse
750bf201ae Add missing checks for malloc/calloc/CloseHandle (#702) 2024-10-03 22:24:19 +03:00
Anonymous Maarten
c3c79a7d82 hidapi: fix "conversion from 'size_t' to 'int', possible loss of data' (#681)
This warning shows up when building with libusb support using MSVC.
Upstreaming of 1664ac4fcb
2024-08-21 12:32:38 +03:00
mbcinergy
4578ea2461 Add hid_send_output_report() (#677)
`hid_send_output_report` sends report over control pipe, unlike existing `hid_write` which would send the data on the first interrupt OUT endpoint, if one exists and only falls back to control pipe.
2024-06-12 19:40:09 +03:00
Ihor Dutchak
76462bd767 Avoid CMake backward compatibility warning (#663)
Avoid a message:
```
Compatibility with CMake < 3.5 will be removed from a future version of CMake.

Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
```

Fixes: #642
2024-03-05 13:26:01 +02:00
Moritz 'Morty' Strübe
4168d87521 Fix the windows build by fixing printf related issues (#641)
- Fix printf/string-related issues
- CI: Turn on -Wformat-signedness for GNU-cc
- Windows: Assert that struct has the correct size
2023-11-17 13:59:40 +02:00
Sam Lantinga
baa0dab611 Only enumerate each interface once (#625)
If a device has multiple altsettings, like an Xbox Series X controller, make sure we only enumerate each interface once, not once for each altsetting.
2023-09-25 00:54:40 +03:00
Ihor Dutchak
8a4de63b56 hidraw: report only Top-Level Usage_page/Usage pairs as 'unique' devices (#601)
- unique Top-Level Usage_page/Usage: to be consistent with Windows/macOS (OS-level implementations).
- support for single Usage Page item for several UsageIDs; 
- support for 32bit Usage items;

Fixes: #298
Fixes: #454
2023-08-26 11:02:42 +03:00
Sam Lantinga
4c932622e8 hidapi/libusb: enable support for Xbox 360 and Xbox One controllers (#572)
Xbox controllers are not technically HID devices, but you can talk to them directly using libusb, and [SDL](https://github.com/libsdl-org/SDL) uses this to talk to controllers which may not have OS-level support.
2023-07-23 12:57:49 +03:00
luzpaz
849c8a9099 Fix various typo (#597)
Found via `codespell -q 3 -L childs,fo,xwindows`
Encountered in downstream https://github.com/libsdl-org/SDL
2023-07-03 17:18:54 +03:00
Sam Lantinga
80e8d62bc1 libusb: same logic to get the config descriptor for hid_open_path() and hid_enumerate() (#568) 2023-06-07 11:54:10 +03:00
Sam Lantinga
fea2357cc5 libusb: use LIBUSB_CALL for the read_callback function (#569) 2023-06-07 01:05:42 +03:00
Sam Lantinga
5eb5544374 libusb: Allow building using non-POSIX runtime (#582) 2023-06-07 01:04:48 +03:00
Oleh Yudin
8588168980 Fix API definitions for clang/gcc flag -Wstrict-prototypes (#533) 2023-04-26 18:28:51 +03:00
Juuso Alasuutari
9f185ec510 libusb: fix crash in hid_enumerate() caused by a stale device handle (#526)
When hid_enumerate() iterates over the device list, it's possible
that libusb_open() fails. If this occurs on the next round after
a successful libusb_open() call, create_device_info_for_device()
is passed the previous iteration's already closed device handle.

Fix the crash by setting the handle to NULL after libusb_close().
2023-04-10 23:24:12 +03:00
Ihor Dutchak
26b5bb0ccf RFC: add hid_get_report_descriptor API function (#451)
- native implementations for hidraw/libusb/macOS;
- HID Report Descriptor reconstruction from HIDP_PREPARSED_DATA on Windows;
- unit-tests for some known devices for `hid_winapi_descriptor_reconstruct_pp_data`;
- support for ASAN builds (mainly to check the `hid_winapi_descriptor_reconstruct_pp_data`/its unit-tests;
2023-03-12 14:45:30 +02:00
Matt Silva
5ce9051e2f libusb: stop read_thread from looping indefinitely (#457)
- When `libusb_submit_transfer` in `read_thread` fails, `read_callback` never gets called and never sets `transfer_loop_finished` to true, causing `read_thread` to loop indefinitely;

- Do not attempt to run a read loop if the initial `libusb_submit_transfer` fails fixes the issue;

Fixes: #456
2022-09-28 17:08:27 +03:00
Ihor Dutchak
4e63d6dfc3 Introduce HID_API_MAX_REPORT_DESCRIPTOR_SIZE (#452)
- first step is to use HID_API_MAX_REPORT_DESCRIPTOR_SIZE internally;
- port a few improvements from get-descriptor branch early;

Resolves: #384
2022-09-15 13:05:56 +03:00
Dimitriy Ryazantcev
0f2cf886e5 RFC: Add HID bus type in hid_device_info (#308) 2022-09-10 19:18:09 +03:00
Ihor Dutchak
ea38f6538f libusb: fix HID Report descriptor request (#444)
- pass the actual HID Report descriptor size (from HID descriptor);
- interface_num has to be wIndex, and not as part of wValue for LIBUSB_DT_REPORT request;
2022-08-16 16:29:10 +03:00
Ihor Dutchak
779346241b libusb: fix enumerating device path w/o root access (#442) 2022-08-15 12:47:27 +03:00
Ihor Dutchak
597160da3c Reattach kernel driver when failed to claim interface (#441)
Potential execution path may happen if kernel driver successfully detached,
but libusb failed to claim the requested interface.

Otherwise the device remains with detached kernel driver.
2022-08-14 12:31:59 +03:00
Julian Waller
5c9f147a07 Add hid_get_device_info (#432)
- new API function: `struct hid_device_info * hid_get_device_info(hid_device *dev);` to get `hid_device_info` after the device already opened;
- reused existing implementation on Windows and macOS from enumeration routines to have the implementation;
- refactored libusb implementation to have a shared routine for `hid_enumerate` and `hid_get_device_info`;
- refactored hidraw implementation to have a shared routine for `hid_enumerate` and `hid_get_device_info`;

Resolves: #431
Closes: #164
Closes: #163
2022-08-13 19:01:57 +03:00
Ihor Dutchak
81dd62dd10 Ensure Iconv is found when provided via CFLAGS/LDFLAGS (#430)
- by default find_file/find_library doesn't respect CFLAGS/LDFLAGS, and FindIconv fails to find Iconv;
- by explicitly trying to link against `-liconv` - we're checking if library is available in such way;
- additionally: if Iconv is detected as BUILT_IN, no need to explicitly depend on `Iconv::Iconv`;
2022-06-22 01:30:45 +03:00
Ihor Dutchak
c95795ab5c Fix hidtest build
- fix including platform-specific includes when HIDAPI is a CMake subdirectory;
- check libusb and winapi platform-specific headers with hidtest;
2022-05-05 14:53:17 +03:00
Ihor Dutchak
cd95af8d70 libusb: cmake: Proper dependency on Iconv (#405)
- explicitly add Iconv as a dependent library;
- check if iconv requires pointer-to-const as input (introduce ICONV_CONST check);
- NetBSD CI (has external Iconv library implementation that uses all of the above);
2022-05-02 14:18:03 +03:00
SNEHAL
536bad201e libusb: Fix double free of buffer pointer in hid_close() (#395)
Make buffer pointer NULL, once it is freed.

In hid_close() buffer pointer is freed and next to that the libusb_free_transfer function is called which checks for if the LIBUSB_TRANSFER_FREE_BUFFER flag is set and the buffer pointer is not NULL. when this condition evaluates true, it
tries to free memory for a buffer which is already free and a crash occurs.

Even though the described behavior should not happen as per libusb documentation, it has been observed with some version(s) of libusb.
2022-04-23 15:54:26 +03:00
Ihor Dutchak
bca404520f Fire v0.12.0 (#398)
- add convenient macros to check HIDAPI version in runtime;
- mark in which version all recent HIAPI API functions where added;
2022-04-23 15:50:41 +03:00
Ihor Dutchak
69dcdc1ff0 Update copyright strings 2022-01-29 18:33:15 +02:00
Ihor Dutchak
f0a4a1fa2e Fix potential crash when libusb_detach_kernel_driver fails (#363)
In case if libusb_detach_kernel_driver fails inside hidapi_initialize_device
HIDAPI had tried to `libusb_close(dev->device_handle)` two times:
- right after `libusb_detach_kernel_driver`;
- outside of `hidapi_initialize_device` function;

The fix: `libusb_close` the device only once.
And since `hidapi_initialize_device` is not responsible for opening the device -
it is not responsible for closing it either.
2022-01-03 14:16:37 +02:00
Ihor Dutchak
0ec60c03cb Add <root>/libusb to includes for in-tree build
Otherwise it is impossible to `#include <hidapi_libusb.h>`,
when HIDAPI is added directly as a subdirectory of a CMake project.
2021-09-27 13:08:20 +03:00
Ihor Dutchak
aaf5f3d172 add libusb-specific hid_libusb_wrap_sys_device
Rationale: on Android one must use UsbManager, to access any
USB device. As a result, libraries like libusb can only use file descriptors
that are provided by UsbManager.
libusb has an API to use such file descriptors: hid_libusb_wrap_sys_device.
Having hid_libusb_wrap_sys_device currently is the only way to make hidapi
work on Android without root access and without custom Android builds.

Relevant info: https://github.com/libusb/libusb/pull/830/files
2021-09-18 18:56:56 +03:00
bearsh
03998f4418 libusb backend: stabilize device path (#291)
Format the path like the linux kernel does:
<busnum>-<port[.port]>…:<config num>.<interface num>

Closes: #117
2021-07-03 22:06:31 +03:00
Ihor Dutchak
f2bb972e7f add CMake build system 2021-07-03 20:38:58 +03:00
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