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>
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>
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>
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>
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>
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>
- 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>
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>
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>
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>
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>
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>
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>
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>
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>