Commit Graph

1317 Commits

Author SHA1 Message Date
MSuih
7cfa00e9d7 Remove obsolete MSVC compiler option 2019-06-28 16:13:35 +03:00
RipleyTom
2e41930f74 CMake implementation based on https://github.com/nonolith/libusb and updated 2019-02-07 04:04:29 +03:00
RipleyTom
ac5c05b3c3 output to ProjectDir not SolutionDir 2019-02-02 00:59:04 +01:00
RipleyTom
599b50fb4e set encoding to UTF8-BOM 2019-02-02 00:58:50 +01:00
Chris Dickens
0034b2afdc libusb 1.0.22
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
v1.0.22
2018-03-24 17:43:43 -07:00
Chris Dickens
f69255217c examples: testlibusb: Fix DDK build warning
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-03-24 17:42:46 -07:00
Chris Dickens
dc5e33e382 Windows: Add back resource and definition files to VS DLL projects
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-03-20 10:01:48 -07:00
Chris Dickens
b0fcdea99f libusb 1.0.22-rc4
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
v1.0.22-rc4
2018-03-17 00:21:14 -07:00
Chris Dickens
2da989c2a0 Windows: WinUSB: Allow caching config descriptors to fail
Certain buggy devices may not provide all the advertised configuration
descriptors. Prior to this commit, failure to cache any one of the
descriptors would result in all of the descriptors being freed and the
device being inaccessible. Work around this by continuing on if fetching
a configuration descriptor fails. The device may still be usable if the
descriptor for the current configuration was successfully retrieved.

Closes #390

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-03-17 00:15:20 -07:00
Chris Dickens
0aac390bb2 Windows: Restructure DDK/MSVC project files
For simplicity and to address some build warnings, this commit reworks
the project files to eliminate duplication and consolidate common build
flags and options. Also adds the stress and testlibusb projects to the
DDK build script.

Closes #402

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-03-12 10:39:26 -07:00
Chris Dickens
d236b63e81 Windows: WinUSB: Guard against erroneous reporting of devices
During enumeration, obtaining the port number via SPDRP_ADDRESS might
return a bogus value for some third-party HCD drivers. If this occurs,
we might end up reporting the device as having the VID/PID from the last
successful enumeration. Guard against this particular situation by
clearing the USB_NODE_CONNECTION_INFORMATION_EX structure before issuing
the DeviceIoControl() call.

References #403

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-03-12 10:28:40 -07:00
Chris Dickens
76b0677b14 Windows: UsbDk: Fix potential buffer overflow
Closes #397

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-03-12 10:25:02 -07:00
Chris Dickens
81ce8be59b Windows: WinUSB: Do not assume that driver implements CancelIoEx()
Cancelling an individual OVERLAPPED I/O operation is something that a
driver can optionally implement. It appears that the native WinUSB
driver supports this but libusbK does not. Therefore we will attempt
to use it and fall back to the AbortPipe() call if an error occurs.

Closes #400

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-03-12 10:24:04 -07:00
Chris Dickens
828ec95424 Windows: Plug HANDLE leak
Restore a CloseHandle() call that was mistakenly removed during a merge
conflict resolution.

Closes #404

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-03-12 09:54:33 -07:00
Chris Dickens
8681342edc libusb 1.0.22-rc3
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
v1.0.22-rc3
2018-02-24 02:02:34 -08:00
Chris Dickens
8e03a6586c Windows: UsbDk: Implement get_config_descriptor_by_value()
This fixes a NULL pointer dereference when the user selects the UsbDk
backend and subsequently calls libusb_get_config_descriptor_by_value().

Closes #395

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-02-24 02:02:03 -08:00
zachary
8551e4a7a2 Windows: Fix hid_abort_transfers blocking
Closes #392

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-02-24 00:03:43 -08:00
Patrick Stewart
32617df714 Windows: Fix race condition between submit and handle events
Check the event object for completion in poll instead of using
HasOverlappedIoCompleted. When we submit a transfer on Windows the fd is
added to the poll list before the read/write begins, so
HasOverlappedIoCompleted can be called before overlapped.Internal is set
to ERROR_IO_PENDING if events are being being handled concurrently, so
the fd will be marked as completed before it has actually started.

[dickens] Instead of replacing HasOverlappedIoCompleted, supplement it
so that it can provide a fast path to avoid WaitForSingleObject() in
the general case

Closes #386, Closes #387

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-02-23 23:55:52 -08:00
Chris Dickens
cd7aeec8e7 Windows: Always search for "USB" PnP enumerator class
On systems running Windows 7 and earlier that only have a USB 3.0 host
controller, devices may not be listed correctly if the root hub PnP
enumerator is anything other than "USB". This regression was introduced
in the recent enumeration refactoring (commit 71a779d07).

Closes #385

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-02-01 23:31:18 -08:00
Chris Dickens
8ddd8d994d libusb 1.0.22-rc2 v1.0.22-rc2 2018-01-27 17:29:46 -08:00
Chris Dickens
4687401350 Windows: Regenerate libusb-1.0.def file from latest DLL
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-27 17:27:53 -08:00
Chris Dickens
e5a7bb548a Windows: Check composite interfaces before calling functions
Commit c4438b3c introduced a regression by failing to check for the
presence of a function in the backend when called on a composite device.
Fix this by introducing a new helper macro and checking for function
pointers at all necessary locations.

Closes #383

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-27 16:22:10 -08:00
Chris Dickens
84209b4fb5 libusb 1.0.22-rc1
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
v1.0.22-rc1
2018-01-08 23:08:47 -08:00
Sean McBride
fef88bf2b9 darwin: Improve error checking to prevent (very unlikely) null dereference
Defend against the very unlikely possibility of CFNumberCreate() returning null.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-08 22:11:40 -08:00
Sean McBride
4f9d58564e darwin: Suppress deprecation warning when building against 10.13 SDK
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-08 22:11:04 -08:00
Sean McBride
c8069cd8c9 darwin: Test use of kUSBDeviceSpeedSuper against SDK version
Closes #362

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-08 22:10:12 -08:00
Sean McBride
3f6a48d00e darwin: extend enum libusb_speed for 10000MBit/s case
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-08 22:08:04 -08:00
Chris Dickens
03f100869e linux_usbfs: Add support for reporting super speed plus devices
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-08 22:04:56 -08:00
Chris Dickens
7a91d7cdcc core: Add definition for LIBUSB_SUPER_SPEED_PLUS (10Gb/s)
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-08 22:03:49 -08:00
Joshua Blake
55ced7746d Windows: Added isochronous support via libusbk
[dickens] Rebased against latest changes and fixed some styling issues

Closes #246

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-08 21:55:47 -08:00
Chris Dickens
ca0b6c09fa Fix appveyor scripts for Cygwin and MinGW to build as intended
The sub-directory created to store the generated files and build objects
was not being used as intended, because each invocation of the bash
starts in the home directory. Fix this by changing to the intended
directory prior to each command invocation.

Also replace the invocation of autogen.sh with bootstrap.sh, since using
autogen.sh calls ./configure and we weren't using the results of that
work. Instead we call configure directly from the sub-directory while
enabling the examples and test builds (for Cygwin) as autogen.sh would do.

Also fix the invalid value for the --build option provided to the x64
build of MinGW.

Finally, propagate errors from each script command so that failures are
caught and reported.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-08 21:03:50 -08:00
Chris Dickens
d88c58eb5b Windows: Fix MinGW build warnings/errors
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-08 12:31:55 -08:00
Sean McBride
678a43bcf3 core: Fixed clang -Wcomma warning
Fixes:

descriptor.c:1179:13: Possible misuse of comma operator here

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-08 10:33:47 -08:00
Sean McBride
297238cda8 darwin: Changed weirdo fixed-sized typedefs with the usual IOUSBLib.h ones
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-08 10:33:40 -08:00
Sean McBride
d2ebbf793c darwin: Untangle clock_* API tests from atomics tests
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-08 10:29:45 -08:00
Sean McBride
860657126e darwin: Replaced low-level mach API with pthread API
Found this because clang was warning that the return value was being
converted from unsigned to signed.

The need for a mach API surprised me, and I found this alternative
formulation in a Chromium bug:

https://groups.google.com/forum/#!topic/native-client-reviews/z---hlHbQNc

which describes: "mach_thread_self() needs to be balanced by mach_port_deallocate(),
which is two system calls. pthread_mach_thread_np(pthread_self()) is two libc
function calls and no system calls, because pthread caches the Mach port."

Fixed the conversion warning too, with a cast.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-08 10:28:16 -08:00
Sean McBride
0f59214f12 darwin: Cleanup and fixes related to Mac OS IOUSBLib interface checks
- revisited fix to issue #48:
  - guard kIOUSBDeviceInterfaceID500 with 10.8 deployment (not 10.9).
    I believe a typo in the bug report caused this to be guarded too
    strictly.
  - added deployment target tests to every interface check. Necessary
    because merely checking for a macro definition tells us nothing
    about what features are available at runtime. It is common to build
    against new SDKs but deploy to older OSes.
- properly guard kIOUSBInterfaceInterfaceID700 against 10.10 deployment
  (not 10.9).  It was added in 10.10.  Probably a copy-pasto.
- changed non-existent kIOUSBDeviceInterfaceID220 to
  kIOUSBDeviceInterfaceID197.  Probably a copy-pasto.
- don't use defines like MAC_OS_X_VERSION_10_9 since they don't exist in
  older SDKs and would fail to compile, use raw numbers instead.
- added tests for newer interfaces: kIOUSBInterfaceInterfaceID800,
  kIOUSBInterfaceInterfaceID650, kIOUSBDeviceInterfaceID650.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-08 10:26:07 -08:00
Sean McBride
3bffd5ca31 Added some Xcode-related items to .gitignore
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-08 10:25:45 -08:00
Sean McBride
6bd5658dd7 darwin: Configure Xcode project to specify tab/space, indent amount
All source files are now tagged as using tabs of 4 spaces, except
darwin_usb.c and darwin_usb.h which use spaces of 2 spaces. This allows
editing files in Xcode without it messing up any particular files.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-08 10:25:13 -08:00
Sean McBride
fc00bb7f4b Misc: Replace "Mac OS X" with "macOS", its current name
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-08 10:23:13 -08:00
Sameeh Jubran
020103af78 Windows: Ditch UsbDk build configuration
Previous patch introduced run-time UsbDk backend activation,
therefore separate build configuration is not needed anymore.

Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
2018-01-08 10:18:09 -08:00
Chris Dickens
54884e84d0 Windows: Enable dynamic selection between WinUSB and UsbDk backends
This commit unifies the two Windows backends into a single project and
enables the user to switch to the UsbDk backend, if available, using the
libusb_set_option() function. All contexts will use the WinUSB backend
by default for backwards compatibility.

With this change, the UsbDk-specific projects are no longer required.

Closes #309

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-08 10:17:26 -08:00
Chris Dickens
d0779e9303 Windows: Rework poll() emulation to a much simpler and effective design
The previous poll() implementation worked okay but had some issues. It
was inefficient, had a large footprint, and there were simply some use
cases that didn't work (e.g. a synchronous transfer that completes when
no other event or transfer is pending would not be processed until the
next poll() timeout).

This commit introduces a new, simpler design that simply associates an
OVERLAPPED structure to an integer that acts as a file descriptor. The
poll() emulation now solely cares about the OVERLAPPED structure, not
transfers or HANDLEs or cancelation functions. These details have been
moved up into the higher OS-specific layers.

For Windows NT environments, several deficiencies have been addressed:

1) It was previously possible to successfully submit a transfer but fail
   to add the "file descriptor" to the pollfd set. This was silently
   ignored and would result in the user never seeing the transfer being
   completed.

2) Synchronously completed transfers would previously not be processed
   unless another event (such as a timeout or other transfer completion)
   was processed.

3) Canceling any one transfer on an endpoint would previously result in
   *all* transfers on that endpoint being canceled, due to the use of
   the AbortPipe() function.

This commit addresses all of these issues. In particular, run-time
detection of the CancelIoEx() function will allow the user to cancel a
single outstanding transfer without affecting any others still in
process.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-06 21:43:12 -08:00
Chris Dickens
0865774fe9 Windows: Add check for ERROR_FILE_NOT_FOUND, which means device removed
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-06 21:32:23 -08:00
Chris Dickens
f3b387fe37 Windows: UsbDk: Fix some minor style/naming issues
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-06 21:20:37 -08:00
Chris Dickens
aacfff6284 Windows: UsbDk: Return appropriate error code for malloc failure
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-06 21:18:43 -08:00
Chris Dickens
af66830223 Windows: UsbDk: Fix direction determination for control transfers
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-06 21:18:14 -08:00
Chris Dickens
6239788f9b Windows: UsbDk: Remove unnecessary empty functions
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-06 21:18:13 -08:00
Chris Dickens
6cffee5086 Windows: UsbDk: Cache system redirector handle
This handle is needed for each transfer submission, so eliminate
repeated calls to obtain the handle by caching it during open.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-06 21:18:13 -08:00
Chris Dickens
2c1f7969eb Windows: UsbDk: Use a better macro for getting context
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-06 21:18:13 -08:00