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>
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.
`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.
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
In macOS 13.3 the kUSBInterfaceNumber is no longer one of the properties
of the IOHIDDevice (even if its transport is USB).
In case if kUSBInterfaceNumber property (for USB Interface number)
is not available as an IOHIDDevice property - find the value for that property
in one of the Parent IORegistry Entries.
- as per documentation `kCFRunLoopRunStopped` should be handled once the runloop is closed via `CFRunLoopStop`;
- if it is not handled - a race condition/crash may happen on the latest macOS when a device gets disconnected while being open;
- 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;
- 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: #431Closes: #164Closes: #163
`kIOMasterPortDefault` is deprecated since macOS 12.0.
One alternative is to use named constant `kIOMainPortDefault` which is not available before macOS 12.0.
Both named constants are just an alias for `NULL`, so it is simpler to use it directly instead.
Fixes: #377
With some device connection configurations,
the device paths become over 512 bytes (io_string_t max length)
which makes them unusable with current implementation.
Rather than using ServiceRegistry string path, use its ID,
which is uint64_t and easily serializable/deserializable into a string.
Implementation idea by felix.schwarz@iospirit.com8d251c3854Fixes: #127, #236.
Removes a possible cause for a segmentation fault observed in `CFSetGetCount`.
Related: #208 ("Segmentation fault on Mac OS Catalina").
Signed-off-by: Jonas Malaco <jonas@protocubo.io>
In one of the early versions of macOS, when you try to close the device
with IOHIDDeviceClose() that is being physically disconnected.
Starting with some version of macOS, this crash bug was fixed,
and starting with macSO 10.15 the opposite effect took place:
in some environments crash happens if IOHIDDeviceClose() is _not_ called.
This patch is to keep a workaround for old versions of macOS,
and don't have a leak in new/tested environments.
Fixes: #144.
The compiler provided the following warning message:
```
hid.c:830:29: warning: format specifies type 'void *' but the argument has type 'IOHIDDeviceRef' (aka 'struct __IOHIDDevice *') [-Wformat-pedantic]
sprintf(str, "HIDAPI_%p", dev->device_handle);
~~ ^~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/secure/_stdio.h:47:56: note: expanded from macro 'sprintf'
__builtin___sprintf_chk (str, 0, __darwin_obsz(str), __VA_ARGS__)
```