66 Commits

Author SHA1 Message Date
Jake 7b142f45fd Implement hid_write_control, so we can use HidD_SetOutputReport on win, all others are just a wrapper until tested 2023-02-09 22:15:08 +01:00
Dimitriy Ryazantcev 0f2cf886e5 RFC: Add HID bus type in hid_device_info (#308) 2022-09-10 19:18:09 +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
MeeSong 844e4682a9 Fix: memory write out of bounds. (#418) 2022-05-25 15:49:47 +03:00
Jacob Shaffer 08563a0249 add better windows error handling (#388) 2022-05-02 14:08:44 +03:00
Frederik Seiffert 2cfd63ac41 windows: Add Windows-specific API to get device container ID (#379) 2022-02-25 10:53:00 +02:00
Dimitriy Ryazantcev c84e42ad91 Extract CM_Get_DevNode_PropertyW() and CM_Get_Device_Interface_PropertyW() calls to separate functions (#372) 2022-02-05 17:03:42 +02:00
Ihor Dutchak 2551a5d84b Reorganize Windows source structure
- separate HID declarations for non-DDK build into re-usable headers;
- refactor initialisation/deinitialisation of HIDAPI;
- make all the comments consistent (C-style only);
2022-01-29 18:33:15 +02:00
Ihor Dutchak 6f37897bef Remove stale Windows/macOS example/test 2022-01-29 18:33:15 +02:00
Ihor Dutchak 69dcdc1ff0 Update copyright strings 2022-01-29 18:33:15 +02:00
Megamouse 5f66a371ca Win32: Don't pass invalid pointers to HidD_FreePreparsedData in hid_open_path (#373)
Fixes a segfault that happens when hid_open_path is called on a previously disconnected device.
This is a regression caused by:
b600727 - Win32: Fix memory leak in `free_hid_device` (#361)

Co-authored-by: Megamouse <studienricky89@googlemail.de>
2022-01-29 18:32:25 +02:00
Dimitriy Ryazantcev fe9a2a2e28 Ported code from SetupApi to CfgMgr32 (#362)
- https://docs.microsoft.com/windows-hardware/drivers/install/porting-from-setupapi-to-cfgmgr32
-  Use Unicode Windows API internally where possible.
2022-01-21 18:43:08 +02:00
Dimitriy Ryazantcev af6c6012b6 Parse USB interface number from device Hardware IDs (#360)
Strickly speaking we cannot parse interface string at all and only allowed to parse Hardware ID string.
2021-12-23 00:01:41 +02:00
Dimitriy Ryazantcev b600727200 Win32: Fix memory leak in free_hid_device (#361)
- Fix memory leak in `free_hid_device`;
- Simpllify `hid_open_path` code;
2021-12-22 23:59:56 +02:00
selsta eb26015189 windows: add missing include for mingw32 (#348) 2021-11-11 01:00:25 +02:00
Ihor Dutchak b923aeda68 Windows: hid_get_feature/input_report return size fix (#334)
- It appears when the numbered reports aren't used,
WinAPI returns size of the report excluding the data[0] which contains 0,
as an indication that numbered reports aren't used;
Explicity count that byte in the result.

Fixes: #328
2021-09-27 13:07:02 +03:00
Ihor Dutchak e050afb197 Fix sygwin compilation warnings (#331)
Fixes: #330
2021-09-18 18:31:26 +03:00
Dimitriy Ryazantcev 11cc0e8a86 Fetch Bluetooth LE HID device info from Windows devnode properties (#309)
As per MS, HidD_GetProductString/HidD_GetManufacturerString/HidD_GetSerialNumberString [doesn't work](https://docs.microsoft.com/en-us/answers/questions/401236/hidd-getproductstring-with-ble-hid-device.html) with Bluetooth LE (BLE) devices.

Add special handling for BLE devices and fill `manufacturer_string`/`product_string`/`serial_number` using BLE-specific API.

Fixes: #282
2021-09-06 19:16:15 +03:00
mcuee 8741697359 Update hid.c to fix MSYS2 MinGW-w64 compiler warning (#311)
This fixed a compiler warning when using MSYS2 MinGW-w64 compiler as mentioned in issue #289.

Since we changed strncpy to memcpy, it is not necessary to disable warning 4996 for MSVC.
2021-07-27 13:02:57 +03:00
Dimitriy Ryazantcev 2a24bf9fcb windows: cleanup code a bit (#305) 2021-07-16 19:11:58 +03:00
Dimitriy Ryazantcev 9404a954af Whitespace cleanup in windows implementation (#302) 2021-07-09 17:32:43 +03:00
Dimitriy Ryazantcev 5a88dcd7ab Fix possible garbage in device strings returned from hid_enumerate()
In some cases HidD_GetSerialNumberString/HidD_GetManufacturerString/HidD_GetProductString can fail.
For example if we have Bluetooth LE gamepad on Windows.
In this case we are currently returning not initialized strings in `hid_device_info`.
2021-07-08 14:39:54 +03:00
Ihor Dutchak 6fcb0bb228 win: hid_get_feature_report: Correct number of bytes_returned (#286)
This originally tested/confirmed by @mcuee.
Confirmed the expected behavior by Tim Roberts https://sourceforge.net/p/libusb/mailman/message/37303650/.
Relates to: #232.
2021-06-19 07:23:35 +03:00
JoergAtGithub e74189d867 win: hid_get_input_report: Correct number of bytes_returned (#232)
Fixes: #229

This originally tested/confirmed by @JoergAtGithub and @mcuee.
And confirmed the expected behavior by Tim Roberts https://sourceforge.net/p/libusb/mailman/message/37303650/.
2021-06-19 06:09:47 +03:00
Erik OShaughnessy 7620bc7faa Guard against zero length buffers in hid_write (#279) 2021-06-14 04:09:13 +03:00
Ihor Dutchak 0ea5e9502f windows: cache write buffer allocated for small user buffers 2021-03-07 13:58:57 +02:00
Mariusz Jaskółka 3cd1742737 Windows: Fix devices enumeration (#235)
Based on
https://github.com/microsoft/Windows-driver-samples/blob/d40232638faaab19de557e70a3ee938da7a35295/hid/hclient/pnp.c#L32

Fixes wrong detection of the class of devices.

Fixes: #234
2021-01-30 15:20:01 +02:00
Mornix fb4135c7a8 Windows: ensure buffer passed to HidD_SetFeature is large enough (#224) 2020-12-24 08:13:54 +02:00
Pavol Rusnak fe724003c6 windows: make hid.c non-executable 2020-12-11 21:01:19 +02:00
Russell Taylor 9828cad691 Windows: fix strict typecast (#206) 2020-11-23 21:12:26 +02:00
Ihor Dutchak 2eb8af161f MSVC: fix /W4 /WX compilation (#191) 2020-10-14 18:42:27 +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
Kevin Teynor b1a2628eea Windows: crash bugfix when trying to open device without a serial number (#194) 2020-10-14 18:36:12 +03:00
UweBonnes 8a88108a49 windows/hid.c: Silence some warnings. (#181) 2020-09-27 18:22:45 +03:00
Cristian GLAVANA f7c7f97d09 Windows Handle GetOverlappedResult blocking on read/write (#129)
- Implemented solution from issue signal11/hidapi#88
- Allows read/write frames up to 1000 per second
2020-09-22 15:21:16 +03:00
Stanley Pinchak ad27b46170 FIX Compiler Warnings on Windows
- cast hidapi supplied size_t parameters to DWORD when calling Windows
  API functions
- cast size_t return variables in `hid_read_timeout` and
  `hid_send_feature_report` to int in order to match hidapi signature.
2020-08-13 19:12:07 +03:00
Jonas Malaco 2dd94af2ea Move local variable declaration to the beginning of the function
Older versions of MSVC (for example when using Visual Studio 10) don't
yet support variable declaration in the middle of blocks:

hidapi\windows\hid.c(845) : error C2275: 'BOOL' : illegal use of this type as an expression
        C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\windef.h(153) : see declaration of 'BOOL'

Move the declaration of res to the beginning of the function.  Like in
hid_get_feature_report, only res is moved, essentially ignoring the #if
0 block (or assuming it will never be enabled).
2020-02-09 15:15:43 +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
Josep Maria Antolín Segura dd16e7c16f Fix uninitialized strings on Windows (#109)
Fix for unusual cases where the hardware does not return the name and the string is not initialized at all.
2019-10-28 16:23:24 +02:00
Andrew Eikum 93dca80762 Update more repository URLs 2019-07-25 07:57:59 +02:00
Niklas Hambüchen 1515eb2c16 windows: Allow hid_error(NULL) 2019-07-15 13:15:46 +03:00
Kubicz, Filip c4f86a7d85 windows: Fix undeclared variable name in register_error()
Signed-off-by: Kubicz, Filip <Filip.Kubicz@nordicsemi.no>
2019-06-18 13:14:47 +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
Kubicz, Filip 76d4ffd853 Windows: enumerate simple devices
Right now, in hid_open it is checked if the connected devices have
"HIDClass" driver name. This is true for composite devices, but some
simple HID devices only have "Mouse" or "Keyboard" driver name.

One of devices that cannot be opened is Dell MS116t, but any mouse which
is not part of composite device can be affected.

With this change, one can enumerate and open these devices.

Signed-off-by: Kubicz, Filip <filip.kubicz@nordicsemi.no>
2019-06-07 08:33:25 +02:00
Sean Cross f7ee9ccd4e windows: retry open_device() without r/w if it fails
Modern Windows implementations don't allow opening HID devices in
READ/WRITE mode if they are claimed by the system.  Examples of such
devices include keyboards and mice.

However, these devices can be opened without READ/WRITE permissions, in
order to allow sending and receiving feature reports.

If open_device() fails, retry without requesting READ/WRITE permissions.

This inverts the logic of the parameter to open_device().

It is a refactor of #44 by @pqu.

Signed-off-by: Sean Cross <sean@xobs.io>
2019-06-05 09:38:14 +02:00
Diego Herranz a6a622ffb6 all: Fix a few typos 2016-09-19 23:40:12 -04:00
Austin Mullins 901512e88b windows: Set maximum buffer for USB strings to 0xFFF wide characters
Limit the size of the buffer passed to hid_get_manufacturer_string(),
hid_get_product_string(), and hid_get_serial_number_string() because
calling the underlying win32 functions with larger buffers causes them
to fail.
2016-09-19 23:31:39 -04:00
Alan Ott b5b2e1779b windows: Always open with sharing enabled
In the past, there was desire to make hid_open() open devices
exclusively, preventing devices from being opened more than once.
Unfortunately, recent versions of Windows have made this largely
impossible for many devices, as it appears that Windows itself is
holding certain HID devices open or preventing them from being
opened in exclusive mode.

This patch will always open devices in SHARED mode on Windows.
2016-03-03 10:54:51 -05:00
Alan Ott 54eb31dc16 windows: Return the correct length from hid_get_feature_report()
The Windows DeviceIoControl() doesn't account for the report ID byte.

Reported-by: Petr Stehlík <pstehlik@sophics.cz>
2014-08-18 11:17:13 -04:00