154 Commits

Author SHA1 Message Date
Ihor Dutchak
0ab6c14264 Add missing sanity checks (#727)
Based on #696

- Add missing checks for zero/null arguments;
- Better management of error strings in case of failures;

---------

Co-authored-by: Megamouse <studienricky89@googlemail.com>
2025-03-13 13:11:20 +02:00
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
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
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
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
a88805e013 hidraw: fixed crash if uevent info isn't available (#580)
Signed-off-by: Sam Lantinga <slouken@libsdl.org>
2023-05-31 20:38:48 +03:00
Ihor Dutchak
ca8373a5b7 Fix "Use after free" (#559)
Fixes: #542
2023-05-22 13:08:48 +03:00
Ihor Dutchak
435650a8fb Fix "Out-of-bounds write" (#560)
Fixes: #541
2023-05-22 13:08:36 +03:00
Oleh Yudin
8588168980 Fix API definitions for clang/gcc flag -Wstrict-prototypes (#533) 2023-04-26 18:28:51 +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
Jonas Malaco
64b778b0dd hidraw: fix number of bytes to copy from uevent in parse_uevent_info (#497)
Commit 5c9f147a07 (#432) replaced a call to strdup with an explicit
memcpy to a buffer on the stack.

However, it incorrectly used the buffer size, instead of the clamped
uevent length, as the argument to memcpy, resulting in reads past the
end of uevent:

Fix this by using uevent_len as the argument to memcpy.

Calling strndupa was considered but abandoned, as it is not standard.

Fixes: 5c9f147a07 (#432)
Fixes: 4779d63d8760
2023-01-09 13:29:52 +02:00
vaaronna
987fd0ac03 Add support for HID over SPI (#486)
This adds (or more accurately completes, since it was already started) support for HID over SPI devices.
Handling is almost identical to HID over I2C.
2022-12-20 19:16:23 +02: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
Ian Douglas Scott
dbd1681831 linux: Open files with O_CLOEXEC to not leak fds to child processes (#446)
Motivation described here: https://github.com/libusb/hidapi/pull/446
2022-08-21 21:40:39 +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
eaa5c7c6f1 hid_error improvements (#428)
- make the behaviour of methods which set hid_error more consistent;
- make the documentation and the implementation of hid_error consistent and safe;
- windows: add global error implementation;

Co-authored-by: Julian Waller <git@julusian.co.uk>
2022-06-22 01:34:39 +03:00
Ihor Dutchak
69dcdc1ff0 Update copyright strings 2022-01-29 18:33:15 +02:00
Ihor Dutchak
0feb5a4fdd Fix wording (#368) 2022-01-22 04:34:32 +02:00
Be
d67b5c9fec implement hid_get_input_report for Linux hidraw backend
Fixes https://github.com/libusb/hidapi/issues/259
2021-12-10 14:48:56 +02: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
MonkeybreadSoftware
6f0056e1ce Build workaround for kernels older than 2.6.39 (#260) 2021-05-05 11:51:16 +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
Jacob Alexander
ffb50afd5f hidraw: Add support for HID over I2C and uhid devices (#166)
- uhid USB, Bluetooth (standard) and I2C now enumerating
  * USB uhid support was added by removing the udev USB endpoint check;
- HID over I2C was excluded before (likely because it didn't exist when
  hidraw was developed);
2020-11-23 21:53:04 +02:00
Jacob Alexander
48cacfa98b Usage Page and Usage on Linux with hidraw (#139)
NOTE: This commit does not handle composite HID descriptors
I am interested in adding support for composite descriptors though I still need to find a
device with a composite descriptor to test it correctly.

The implementation idea is similar, as in #125 for macOS.
2020-11-23 21:02:16 +02:00
Marc Zyngier
ad985aeaf4 linux/hidraw: Don't consider open returning 0 as an error
The open systcall is allowed to return 0 as a valid file descriptor,
and considering it an error breaks environments where unnecessary
fds are closed before executing untrusted processes.

Fixes: #199

Signed-off-by: Marc Zyngier <maz@kernel.org>
2020-10-20 19:01:54 +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
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
Ludovic Rousseau
8184eb2087 Linux: fix Makefile-manual to build hidtest 2019-11-05 14:00:44 +01:00
Andrew Eikum
5d9b4cd93c Zero-initialize new hid_device_info structs
This fixes an uninitialized usage_page value leaking from the Linux
backend. It may fix other uninitialized values, too.
2019-07-25 08:08:12 +02:00
Andrew Eikum
93dca80762 Update more repository URLs 2019-07-25 07:57:59 +02:00
Ihor Dutchak
e4ad5ec64f Update README: hidraw: minimum supported kernel 2019-07-23 23:50:56 +03:00
Niklas Hambüchen
3bfe1001b6 hidraw: Implement hid_error() 2019-07-15 13:15:46 +03:00
Luca Weiss
6f79625abb linux: Drop workaround for kernel < 2.6.34
Also drop HIDIOC* definitions as they are present since kernel 2.6.39.
2019-07-15 13:14:08 +03:00
luz.paz
f01c4ede50 Misc. typo fixes
Found via `codespell -q 3`
2019-07-14 13:54:55 +02:00
Iakov Kirilenko
73b9ccb996 Explicit cast from void* to corresponding type
Fix compilation without -fpermissive
2019-06-24 22:55:27 +02:00
Diego Herranz
a6a622ffb6 all: Fix a few typos 2016-09-19 23:40:12 -04:00
Diego Herranz
1f615efdbe Documentation: path fixes
hid-libusb.c was renamed hid.c long ago but documentation wasn't
updated.
2016-09-19 23:40:11 -04:00
Ludovic Rousseau
98629a104b linux: Check value returned by fstat(2)
Problem reported by the Coverity tool

CID 1042532 (#1 of 1): Unchecked return value from library
(CHECKED_RETURN)2. check_return: Calling function
"fstat(dev->device_handle, &s)" without checking return value. This
library function may fail and return an error code.
2016-03-03 11:01:36 -05: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
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
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
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
69a91a8f6c All: Convert C99 comments (//) into C89 comments (/* */) 2012-11-26 18:49:51 -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
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