Commit Graph

86 Commits

Author SHA1 Message Date
Jonas Malaco ce606fac8f macOS: check if IOHIDManagerCopyDevices returned a NULL (#209)
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>
2020-11-23 21:03:03 +02:00
Ihor Dutchak a731aae2a3 macOS: fix -Wall -Wextra -pedantic compilation warnings 2020-10-16 13:06:50 +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
Ihor Dutchak fd53f39f25 macOS: enumerate device with primary usage/usage_page first (#193)
It improves backward compatibility with versions of hidapi, where
usage/usage_pairs didn't emit seaprate hid_devices_info.
2020-10-14 18:37:27 +03:00
Ihor Dutchak cdc473dfe4 Don't leak device handle in macOS 10.10 or newer (#186)
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.
2020-09-29 14:01:30 +03:00
Pavel Hübner 24a822c80f Fix compilation warning in pedantic mode on macOS
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__)
```
2020-03-20 01:43:44 +02:00
Luca Weiss 51bdec7844 Fix manual Makefiles and add CI for them (#131) 2020-01-12 04:09:48 +02:00
0xDP 65d22a9c31 macOS: correct IOKit framework location (#120) 2019-12-07 18:54:07 +02:00
Tod E. Kurt ca1a2d6efa macOS support for multiple usage/usage-pages (#125)
* macOS support for multiple usage/usage-pages
Update of @fengji2006 PR#65, second try

* apply requested changes and test

* handle possible nullptr
2019-12-05 10:53:44 -08: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 3cea631d43 macOS: fix Makefile-manual to build hidtest 2019-11-05 14:00:44 +01:00
Ihor Dutchak d64f6c6a16 macOS: send report id conditionally for hid_get_feature_report (#70)
same as in hid_send_feature_report, and Windows/Linux
2019-09-24 13:34:59 +03:00
Josh Junon d8b6588d09 mac: prevent memory leak in hid_open_path() if hid_init() fails 2019-09-24 13:25:23 +03: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
Luca Weiss 42dede9db5 mac: 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
Tod E. Kurt 0ebecbd1f6 fix small casting issue 2019-07-02 23:10:41 -07:00
Iakov 'Jake' Kirilenko e32d3f1266 Initialize local variable with smth meaningful
I prefer explicit INVALID rather than possible compiler warning about uninitialized var sometimes later
2019-06-24 22:55:27 +02:00
iakov 9d569ba8a9 Add missed NULL initialisation to local variable
Co-Authored-By: Ihor Dutchak <ihor.youw@gmail.com>
2019-06-24 22:55:27 +02:00
Iakov Kirilenko 0324a0b0e5 Codestyle conformance: add spaces after type-case 2019-06-24 22:55:27 +02:00
Iakov Kirilenko 7d08fd907d More rigorous & even C++ compatible code for macOS 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
Tod E. Kurt 121567d64a Merge pull request #2 from z3ntu/pr_380
mac: Set a valid interface number on hid_device_info for USB HID dev…
2019-06-09 11:54:01 -07:00
Dylan McKay 00e6e4568f mac: Set a valid interface number on hid_device_info for USB HID devices
Previously the interface would never be set on Mac.

This presents a big pain because retrieving interface numbers can be the
only way to distinguish between the interfaces returned by HIDAPI.

This change makes it possible to retrieve interface number from an
hid_device_info on Mac for USB HID devices only.

It is unclear if the macOS IOKit library returns valid interface numbers
for non-HID USB devices. Because of this, I have opted to simply skip
that case - leave it initialised to `-1`.

In the future, we can easily relax this restriction if it turns out
IOKit correctly returns interface number with non-HID USB devices. For
now, this commit brings 90% of the value at 5% of the risk.
2019-06-06 17:31:48 +02:00
Raphaël P. Barazzutti d8336833fc mac: fix behaviour of hid_get_feature_report (was writing on the report id byte) and return value was not right) 2019-06-06 00:23:45 +02:00
Diego Herranz a6a622ffb6 all: Fix a few typos 2016-09-19 23:40:12 -04:00
Brendan Shanks ae15b65ed9 Mac: Disable unused get_location_id()
Disable get_location_id(). It's not used in active code since make_path()
was removed.
2016-09-19 22:13:10 -04:00
Brendan Shanks 474145e766 Mac: Remove unused get_string_property_utf8()
Remove get_string_property_utf8(), it's not used since make_path() was removed
2016-09-19 22:13:10 -04:00
Brendan Shanks 59a076705b Mac: Use IOKit IOService:/ paths for devices
Change hid_enumerate() and hid_open_path() to use IOKit IOService:/
paths to uniquely identify devices, instead of creating a path
(done by the make_path() function).

The path passed to hid_open_path() now must be a valid path to an
IOHIDDevice in the IOService plane, like:
"IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/EHC1@1D,7/
AppleUSBEHCI/PLAYSTATION(R)3
Controller@fd120000/IOUSBInterface@0/IOUSBHIDDriver"
2016-09-19 22:13:03 -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 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
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
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 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
Brendan Shanks ee808f9dfc Mac: Remove 'next' from struct hid_device_
Remove 'next' from struct hid_device_, it's unused since device_list was
removed
2012-09-17 21:25:09 -04:00
Brendan Shanks 471dd9d5ae Mac: Remove device_list and its mutex/code
Remove device_list, which was used to match up IOHIDDeviceRef's and
hid_device's in the device removal callback. This was needed because the
removal callback was attached to the whole IOHIDManager, instead of
individual IOHIDDevices.
Instead attach the removal callback to each IOHIDDevice individually,
and have a pointer to the device's hid_device passed to the callback.
2012-09-17 21:25:08 -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
bsupnik 517b3acd71 Mac: Add CFRetain()/CFRelease() pair on the device handle
Adding retain/release to the device since we keep the reference in
our object.
2012-05-17 08:53:29 +08:00
philip 1186ca26c7 All: Make serial_number parameter to hid_open() const.
This prevents a warning when passing in a literal.
2012-03-28 18:05:49 -04:00
Nikolaj Løbner Sheller a22320f76d Mac: Fix return value for string functions
get_serial_number()
	get_manufacturer_string()
	get_product_string()

This is to match the documentation in the header file, returning 0 on
success and -1 on error.
2012-02-28 11:26:28 -05:00
Alan Ott 240bad3b66 Remove unnecessary setlocale() on Mac 2012-02-27 12:05:23 -05:00