Commit Graph

1303 Commits

Author SHA1 Message Date
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
Chris Dickens
6733f242ae Windows: UsbDk: Fix spelling of InterruptTransferType enum
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-06 21:18:13 -08:00
Chris Dickens
798969f5c6 Windows: UsbDk: Fix some strange type-casting
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-06 21:15:39 -08:00
Chris Dickens
4da478cce0 Misc: Add TargetName to getopt VS project files to supress warning
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-04 23:44:57 -08:00
Chris Dickens
9843b689df Misc: Sort projects alphabetically in VS solution files
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-04 23:33:09 -08:00
Chris Dickens
8b6639ea6f Misc: Fix references section in fxload VS project files
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-04 23:32:33 -08:00
Chris Dickens
6dd2b7f9a5 Misc: Fix linker options in getopt VS project files
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-04 23:32:14 -08:00
Chris Dickens
e25e0ce759 Misc: Add missing files to VS2005 projects for libusb
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-04 23:21:48 -08:00
Chris Dickens
cbf2cc8847 Misc: Fix minor discrepancies in WinCE MSVC files
Add missing header files, fix preprocessor definitions for static
library, and sort projects and files by name.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-04 23:19:47 -08:00
Chris Dickens
664c43d9b1 WinCE: Give a variable a more appropriate name, matching other patterns
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-04 21:55:01 -08:00
Chris Dickens
c2791c3cb3 WinCE: Remove empty function for unsupported ISO transfers
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-04 21:54:01 -08:00
Chris Dickens
12c3047c63 WinCE: Add back mistakenly removed errno variable
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-04 21:51:04 -08:00
Chris Dickens
71a779d078 Windows: Rework WinUSB enumeration process to fix issues on Win8+
As they sometimes do, Microsoft made changes to the way in which the
SetupAPI functions list the devices returned by SetupDiGetClassDevs().
In particular, composite devices started returning their interfaces
before the parent device, which caused some issues with the way the
enumeration logic was assigning things. For composite devices, it
appears that the first interface behaves much like the parent device in
some regards, so the library was creating a device specifically for the
first interface and then again when the actual parent device was
encountered. This caused composite devices to appear in the device list
twice, with the first instance being unusable for most operations.

This commit significantly changes the way in which the enumeration
process is done. Previously we would scan for HCDs, hubs, and generic
devices, in that order and in distinct passes (obtaining a new listing
of devices from SetupAPI). Now we will obtain a single snapshot at the
beginning of the enumeration process and iterate through this to scan
for each type of device.

With a single snapshot, we can be assured that the device instance
handle will not change between passes and thus we can use this as the
unique identifier. This completely removes the need to hash the device
instance ID to obtain a unique identifier and simplifies the process.

The previous enumeration process also created "dummy" libusb_device
instances for the HCDs that were never exposed to the user. This has
been removed in favor of identifying which of the encountered hubs are
actually root hubs.

Finally, the query for the port number has been moved to the GENeric
pass at the point where the devices are actually initialized. This query
operation has been relaxed to allow failure, since some virtual USB
devices don't properly implement this query in their drivers.

Closes #215, Closes #251, Closes #257, Closes #288

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-04 16:37:09 -08:00
Chris Dickens
839235a0b4 Windows: Remove port member from device's private structure
The libusb_device structure already has a port_number member that stores
the same information, so don't duplicate this elsewhere.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-04 15:52:56 -08:00
Chris Dickens
def374393b Windows: Be a bit smarter when setting composite interfaces
Instead of open-coding the search for the "MI_" substring, use the
strstr() function to find the string and verify that the following two
characters are indeed digits.

Also guard against the possibility of the interface number being larger
than what we can support.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
2018-01-04 15:45:07 -08:00