Commit Graph

120 Commits

Author SHA1 Message Date
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
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
faaf22cba2 Windows: fix build of hidtest 2019-11-05 14:00:44 +01: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
Luca Weiss
065d46ab27 Add Windows (msbuild & cygwin) CI (#37)
* Upgrade Windows projects to VS2015
* add MSVC x64 configuration
2019-07-17 20:14:38 +03:00
Niklas Hambüchen
1515eb2c16 windows: Allow hid_error(NULL) 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
Thomas Petazzoni
d98c408ed3 hidtest: don't use a C++ source file, since it's pure C
This allows to build the test program with toolchains that don't have
C++ support.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
2019-06-25 15:09:11 +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
Mark A. Tsuchida
171a521b91 windows: Limit hid_read() return value to buffer length
hid_read() and hid_read_timeout() now return the number of bytes copied,
instead of the number of bytes returned by GetOverlappekdResult() (which is
the maximum report size for the device).  This limits the return value to
the requested length (buffer size), matching the behavior on other
platforms.
2014-07-22 17:35:56 -04:00
Scott Talbert
627f3aa478 windows: Set the OS report buffer size to 64 reports
Resolves issues with dropped input reports when receiving a large amount
of data.
2014-07-22 16:53:23 -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
776ec62dfc windows: Fix leak of event handle on open_device() failure
Create a new free_hid_device() function which takes care of all the
resources in hid_device which may need to be freed/released.

Reported-by: Johan Lindh <johan@linkdata.se>
2013-04-23 13:56:06 -04: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
Nikolaj Løbner Sheller
0ed94093c8 windows: replace magic number 2 with sizeof(wchar_t)
Changed for readability, as I think this is what was intended by
the author.
2012-11-26 20:30:09 -05:00
Justin R. Cutler
b5b15d0d83 windows: mingw: minor gcc -pedantic warning fixes 2012-11-26 20:00:48 -05:00
Justin R. Cutler
69a91a8f6c All: Convert C99 comments (//) into C89 comments (/* */) 2012-11-26 18:49:51 -05:00
Alan Ott
44f9df5ec1 Windows: Make sure a driver is present for enumeration.
Windows will enumerate a device before the driver has been attached to
that device. This is problematic, and causes hangups on Windows 7
(possibly othes) when the device is opened before a driver is attached
and then closed. This patch makes sure that a driver has been attached
to the device before putting it in the enumeration list.
2012-07-16 13:02:32 +08: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
Chris Serio
c8e917f018 Windows: Fixed an incorrect return type on HidP_GetCaps()
Addresses an issue with the return type of HidP_GetCaps() which was
returning the wrong status code because of the invalid return type of
BOOLEAN which is a UCHAR. The return code is supposed to be 0x110000
which obviously doesn't fit in a UCHAR so it was being rounded to
0x0. Basically, no return codes were ever making it through that call.
2012-05-17 08:53:30 +08:00
Chris Serio
e4310539ff Windows: Fix compile when using DDK
There are type definitions that allow compilation without requiring the
Windows DDK to be installed for compilation/linking however one of the
types used was wrong and when actually compiled against the DDK, it
would fail.
2012-05-17 08:53:28 +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
Alan Ott
e3ab121099 Windows: Don't let device disappear from hid_enumerate() when open
Change the CreateFileA() flags to support the following:
1. Devices can still be opened in exclusive mode,
2. Devices which must be opened in shared mode can still be opened.
3. Opened devices (even with exclusive opens) still show in
hid_enumerate()

Thanks to github user vanweric for suggesting these flags and to Brendan
Shanks for discussion and testing.
2012-01-26 11:14:04 +08:00
Vitali Lovich
c26a0c13f2 Don't copy too many bytes from hid_read() in Windows.
Make sure that too many bytes aren't copied to the user if they pass in a
short buffer to hid_read_*().

From: Vitali Lovich <vlovich@gmail.com>
2011-12-31 03:00:01 +08:00
Vitali Lovich
ee4ecc02ae Fix output report length bug
On Windows, data shorter than the output report length must be padded.
This is because in the case of multiple reports, Windows expects the number
of bytes which are in the _longest_ report to be given to WriteFile() even
if the user is sending a report which has fewer bytes.

This allocates a temporary buffer in the case that the user passes in too
few bytes.

From: Vitali Lovich <vlovich@gmail.com>
Modified-by: Alan Ott <alan@signal11.us>
2011-12-31 02:59:43 +08:00
Alan Ott
4419c3bdf4 Change windows/hid.cpp to windows/hid.c
The changes to make it compile with just C (not C++) are already in.
2011-09-22 18:59:33 -04:00
Alan Ott
6a44b8772c Return 0 on success to lookup_functions (Windows)
There was no return value before. I guess I missed the warning.
2011-09-22 18:47:26 -04:00
Alan Ott
e85acbed71 Add hid_init() and hid_exit to Windows. 2011-09-12 14:09:03 -04:00
Alan Ott
169bc1b8d9 Change the WinIoCTL.h include in windows/hid.cpp to lower case winioctl.h
This is necessary for cross-compile on Linux. While WinIoCTL.h is the
actual name of the file on Windows, it is apparently not the case on
the Linux cross-compile tools.

This patch is from Ryan Pavlik <abiryan@ryand.net>
2011-09-10 16:13:01 -04:00
Ryan Pavlik
2089519798 Add NTSTATUS typedef if needed 2011-09-10 16:06:42 -04:00
Alan Ott
c491f95935 Make windows/test.cpp compile in either C or C++. 2011-09-10 16:01:48 -04:00
Alan Ott
c7f35c3a46 Try opening with sharing mode enabled on Windows if normal open fails.
Multiple users have reported the need to pass
SHARE_MODE_READ|SHARE_MODE_WRITE to CreateFileA(). It seems that some
devices will not open at all if sharing is not requested. This commit
makes it so that CreateFileA() will be tried twice, the first time with
sharing mode OFF (passing 0x0 to the ShareMode parameter of CreateFileA()),
and if that fails, it will try to open the device with share mode ON
(passing the above SHARE_MODE_ flags to the ShareMode parameter of
CreateFileA()). This will have the following effects:

For normal devices:
   Devices will open as normal. Only one instance can be opened at a time.
For devices which require share mode to be on:
   Devices will now open (they would not open at all before). Multiple
   instances can be opened. This is less than desirable, but the
   alternative is that these devices don't open at all.
2011-08-31 12:39:02 -04:00
Ryan Pavlik
36c309f521 Parse the interface number out of the path on Windows where possible.
Although the Windows API doesn't provide direct access to interface number,
on child devices representing the interfaces of a composite device, it is
parsable from the device path. An excerpt of a path for interface 1 of a
Razer Hydra device is as follows:
\?\hid#vid_1532&pid_0300&mi_01

See table 4 and related text here:
  http://msdn.microsoft.com/en-us/windows/hardware/gg487473

This patch, if a path is available, and further, if &mi_ is found, parses
what it can for a hex value into the interface_number field. If there is
any problem, the invalid value (-1) is used instead.

Patch from Ryan Pavlik <abiryan@ryand.net> with modifications by Alan Ott.
2011-08-30 16:55:59 -04:00
Alan Ott
e62dba691d hid_read_timeout() (Linux and Windows).
hid_read_timeout() will execute a blocking read up until a timeout has been
reached or data has been received.

This patch implements it on all platforms and comes from Urs Fleisch.
Commit log message by Alan Ott.

Signed-off-by: Urs Fleisch <urs.fleisch@gmail.com>
Tested-by: Alan Ott <alan@signal11.us>
2011-08-08 21:01:37 -04:00
Alan Ott
7e93a4e068 Logic error fix.
Fixed Logic error from the last commit where the wrong data was checked.
2011-07-25 23:42:05 -04:00
Alan Ott
9448fd8fcb Re-design of hid_read().
This fixes the performance issue caused by calling CancelIo() when no data arrives in asynchronous (non-blocking) mode. Reported by Bill Good.

This new design also fixes the race condition causing lost packets that can happen if data comes between the time when the Event was checked (WaitForSingleObject()) and the CancelIo() call. Reported by Hans Van Leemputten.
2011-07-25 17:53:12 -04:00
Alan Ott
687a8385a1 Fix memory leak on Windows.
The EVENT object in hid_read() was not getting closed when in blocking mode. Fix from John Hu.
2011-06-19 22:11:09 -04:00
Alan Ott
f61cea6e69 Makefiles for MinGW 2011-04-08 18:48:12 -04:00
Alan Ott
3290860713 Change interface field to interface_number in hid_device_info struct.
Change field named interface to interface_number because Visual Studio uses
interface as a keyword for managed C++.
2011-01-18 23:00:59 -05:00
Alan Ott
a93cdfbeac Add the interface number to hid_device_info on Linux/libusb implementation.
The interface number is added to the hid_device_info struct. Since the
Linux/libusb implementation can't put the Usage and Usage Page in the
hid_device_info struct because it requires detaching the kernel driver, the
interface number is added instead so that users with composite HID devices
can differentiate between the interfaces on the device.
2011-01-18 22:52:06 -05:00
Bastaan Veelo
ba51d59a4e hid_device_info with bcdDevice release number. 2011-01-18 18:38:35 -05:00
Alan Ott
3a4192eb45 Support for Usage Page and Usage for each device in the hid_device_info struct. 2011-01-11 23:59:12 -05:00
Alan Ott
7650ac65b2 Merge branch 'master' of github.com:signal11/hidapi 2010-09-13 11:16:35 -04:00
Alan Ott
09cb41aada Additional licenses. HIDAPI is now GPLv3, BSD, or the original license,
at the discretion of the user. This should provide maximum flexibility and
freedom.
2010-09-13 11:15:24 -04:00
Alan Ott
5fa9bf37c4 Changes made for Cygwin. The _stdcall had to come out. I'm not sure about taking this out, but it's the only way I've found so far to make Cygwin work. 2010-09-07 14:13:41 -04:00
Alan Ott
57c6eebe56 Made windows/hid.cpp work on MinGW. In the process, cleaned up some unnecessary initializations, and cleaned up a warning. 2010-09-06 14:58:26 -04:00
Alan Ott
cc51331c6c Make sure only one report is returned per call to hid_read(). 2010-08-23 15:11:42 -04:00
Alan Ott
17c4c9251c Changed hid_error() to return const. 2010-08-21 13:22:03 -04:00
Alan Ott
f53f5fb0f8 Changed hid_get_feature_report() to return the number of bytes actually read on Windows. This involved changing the implementation to use DeviceIoControl() rather than HidD_GetFeature().
Changed it on Mac as well to return the same. The Linux implementation already did this.
2010-08-14 14:12:43 -04:00
Alan Ott
65331407a7 Made the hid_error() return wchar_t* so we can get translated error messages. 2010-08-10 14:58:59 -04:00
Alan Ott
7309d191cc Fixed path for hidapi.h 2010-08-10 14:14:22 -04:00
Alan Ott
da1ab35011 Fixed up the header comments. 2010-07-28 20:32:41 -04:00
Alan Ott
d5d0b59005 Make hid_close NULL-safe, like delete and free() are. 2010-07-28 20:24:36 -04:00
Alan Ott
e561beba37 Fixed the Windows build files to have the proper paths. 2010-07-28 20:23:14 -04:00
Alan Ott
e21e31d1c2 Shifted stuff around and cleaned it up in the windows/ folder. 2010-07-28 20:19:07 -04:00
Alan Ott
80ad44b7cf Moved Windows build files to windows/ 2010-07-28 19:38:45 -04:00
Alan Ott
3301d7a91e .gitignore to ignore generated files 2010-07-27 22:57:10 -04:00
Alan Ott
2097e314fc Modified the windows build to not require the DDK to build the DLL.
Also moved the windows hid.cpp file to windows/ from hidapi/. hidapi/ now
only contains the library header file.
2010-07-27 22:28:42 -04:00
Alan Ott
5dafc59018 Changed to not use the DDK to build the library. 2010-07-27 21:42:19 -04:00
Alan Ott
5ff108a94b Changed name from hidapi/ to windows/ 2010-07-27 21:40:17 -04:00