summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* move on to 1.0.23-rc3v1.0.23-rc3Nathan Hjelm2019-08-143-3/+6
| | | | Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* windows: fix buildNathan Hjelm2019-08-142-4/+4
| | | | | | | | | Make code compliant with C89 so it will compile. References #609 Closes #611 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* windows: Fix libusb_get_device_list failure if virual usb host installledFrank Li2019-08-142-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If a virtual usb host driver install, but no port on that. libusb_get_device_list will return failure. but it should skip this host devices. the below is virtual host control information ============USB Host Controller ======================= +++++++++++++++++ Device Information ++++++++++++++++++ Device Description : Leostream Corporation Virtual USB Host Controller Device Path : \\?\root#system#0004#{3abf6f2d-71c4-462a-8a92-1e6861e6af27} Device ID : ROOT\SYSTEM\0004 Hardware IDs : *lsusbdhcDevice Driver KeyName : {4d36e97d-e325-11ce-bfc1-08002be10318}\0049 (GUID_DEVCLASS_SYSTEM) Driver : \SystemRoot\System32\drivers\lsusbdbus.sys (Version: 6.3.2.2570 Date: 2018-11-12) Driver Inf : C:\WINDOWS\inf\oem25.inf Legacy BusType : Internal Class : System Class GUID : {4d36e97d-e325-11ce-bfc1-08002be10318} (GUID_DEVCLASS_SYSTEM) Interface GUID : {3abf6f2d-71c4-462a-8a92-1e6861e6af27} (GUID_DEVINTERFACE_USB_HOST_CONTROLLER) Service : lsusbdbus Enumerator : ROOT Location Info : - Manufacturer Info : Leostream Corporation Capabilities : 0x00 (-) Status : 0x0180200B (DN_ROOT_ENUMERATED, DN_DRIVER_LOADED, DN_STARTED, DN_DISABLEABLE, DN_NT_ENUMERATOR, DN_NT_DRIVER) Problem Code : 0 Power State : D0 (supported: D0, D3) HcInfo0 Error : ERROR_INVALID_FUNCTION Roothub Symbolic Link : LSUSBDBUS BusStatistics Error : ERROR_INVALID_FUNCTION DriverVersion Error : ERROR_INVALID_FUNCTION BandwidthInfo Error : ERROR_INVALID_FUNCTION PowerInfo Error : ERROR_INVALID_FUNCTION Closes #608 Signed-off-by: Frank Li <Frank.Li@nxp.com> Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* core: protect against changes to the pollfd list during handle_eventsNathan Hjelm2019-08-143-2/+37
| | | | | | | | | | | | | | It is possible a file descriptor to be removed due to a close and the same file descriptor value to be added during the same event loop. This can cause the backend to get a stale revent and incorrectly remove the file descriptor. This commit addresses the issue by delaying the actual removal of the ipollfds entry until just before the backend handle_events is called. handle_events then goes through the list of closed fds and clears out the revents associated with the closed file descriptor. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* core: abandon sync transfers after libusb_close()Nathan Hjelm2019-08-132-1/+9
| | | | | | | | | | | | | | | | | | | This commit adds an additional check to synchronous transfer progression to prevent accessing a potentially deleted context. This access can occur if a code calls libusb_close() then libusb_exit() from one thread while another thread is in a synchronous transfer. Note that this is likely a user error. The application should wait for all transfers to complete before calling libusb_close(). This commit is being offered as a best-effort attempt to prevent the invalid access and return a useful error to the application. There may still be a window where an invalid access is possible. This commit is a work around until a better fix is available. References #610 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* update to 1.0.23-rc2v1.0.23-rc2Nathan Hjelm2019-08-093-3/+4
| | | | Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* windows_winusb: Add support for reporting super speed plus devicesHarry Mallon2019-08-093-2/+7
| | | | | | Closes #531 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* windows_winusb: fix pedantic format string warnings.Josh Gao2019-08-092-9/+9
| | | | | | | | | clang is pedantic about requiring the l prefix for DWORD, which is a typedef to unsigned long. Closes #590 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* windows_winusb: fix size_t format strings.Josh Gao2019-08-091-2/+2
| | | | | | Use %zu to print size_t for 64-bit compatibility. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* windows: remove total fds (256) limitationsFrank Li2019-08-093-15/+52
| | | | | | | | | | | | | | | When queue more usb requests, and more devices working at the same time 256's limitation is easy to reach. This patch remove such limitation of windows version. dymatic allocate map fd_table. each time increase 256 entry if request more fds. Closes #592 Signed-off-by: Frank Li <Frank.Li@nxp.com> Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* Use `%zu` for sizes instead of `%d`William Orr2019-08-092-3/+3
| | | | | | Closes #593 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* Remove infinite recursion in OpenBSD backendWilliam Orr2019-08-091-2/+0
| | | | | | | `usbi_dbg` calls `usbi_backend.clock_gettime`, so `obsd_clock_gettime` should not call `usbi_dbg` Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* Use a designated initializer for openbsd backendWilliam Orr2019-08-091-49/+29
| | | | | | | | At some point `wrap_sys_device` was added to the `usbi_backend` struct, and OpenBSD's backend was never updated along with it. Use a designated initializer for this, so that we can avoid this class of error. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* Windows: Workaround for composite devices with U2F on Win10 1903Axel Gembe2019-08-092-2/+11
| | | | | | | | | | | | On Windows 10 version 1903 and later Windows blocks attempts to open HID devices with a U2F usage unless running as administrator. This patch makes the composite_open function ignore when opening the HID part of a composite device fails. Closes #603 Signed-off-by: Axel Gembe <derago@gmail.com> Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* Windows: Fix detection of Windows 10 when manifest declares supportAxel Gembe2019-08-092-2/+3
| | | | | | | | | | | | | | | | | | On Windows 10 GetVersionEx will return version 10.0 when the running application has a manifest that declares Windows 10 compatibility. https://docs.microsoft.com/en-us/windows/win32/sbscs/application-manifests#supportedOS When no such manifest is found, the call will report version 6.2, which is Windows 8. The 6.4 version is returned by early Windows 10 Insider Previews and Windows Server 2017 Technical Preview 1. Closes #604 Signed-off-by: Axel Gembe <derago@gmail.com> Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* darwin: fix bugs in the reenumeration of devicesNathan Hjelm2019-08-092-47/+89
| | | | | | | | | | | | | | | | This commit fixes two bugs in device re-enumeration (enumeration after init): - The internal device object (cached device) was being re-used but the user-visible one was not. This would cause the user to get stale data when using the device afer reset. Now the (per libusb spec) the user-visible device object is re-used and updated. - If multiple libusb contexts were active then only the first context was handled correctly. Fixed by moving the cached device search out of process_new_device(). Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* Unix: fix library version for next releaseLudovic Rousseau2019-08-092-2/+2
| | | | | | | | | | | | | | | | https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html says: 4. If any interfaces have been added, removed, or changed since the last update, increment current, and set revision to 0. 5. If any interfaces have been added since the last public release, then increment age. So both current and age must be incremented. The patch in fde20bb9b7cba0ea6e96db920d0a0169c361ca92 was not complete. Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
* Various fixes for the Haiku portAdrien Destugues2019-07-076-12/+51
| | | | | | | | | | | - Use native API for getting full configuration descriptors instead of using a raw request - Implement some callbacks that are mandatory and result in crashes if not available Closes #565 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Fix some -Wformat warnings.Josh Gao2019-07-074-7/+7
| | | | | | Closes #561 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* windows_winusb: Set policy ISO_ALWAYS_START_ASAP for libusbKLéo Lam2019-07-073-1/+10
| | | | | | | | | | | | | | | | | In some cases, this is required to avoid eventually getting a USBD_STATUS_BAD_START_FRAME error back from the Windows USB stack. This makes the libusbK code match the behaviour of the Linux backend. It appears that the libusbK backend tried to get this behaviour by setting StartFrame to 0. However, libusbK docs state that: "Specifing 0 for KISO_CONTEXT::StartFrame (start transfer ASAP) is restricted to the first transaction on a newly opened or reset pipe." Closes #569 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* windows_winusb: Bounds check interface for check_valid_interfaceLéo Lam2019-07-072-1/+4
| | | | | | | | | This prevents a nasty out-of-bounds read and a likely crash when the interface number is invalid. Closes #568 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* windows_winusb: Mask wIndex correctly when checking interfacesLéo Lam2019-07-072-2/+2
| | | | | | | | | | | | | According to the USB 3.0 spec (9.3.4), the interface number is in the lower 8 bits of wIndex. Note that wIndex must not be modified because some (non-compliant?) devices actually use the higher 8 bits for custom data with recipient-interface requests. Closes #567 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* windows: fix return type of usbi_{inc,dec}_fds_ref.Josh Gao2019-07-073-5/+5
| | | | | | | | | These functions were declared as returning int, but failed to actually return anything, and no one was using their return values anyway. Closes #562 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Typo fixes in commentsfollower2019-07-072-3/+3
| | | | | | Closes #563 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* mingw fixRipleyTom2019-07-072-1/+2
| | | | | | Closes #566 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Adds /utf-8 to compile optionsRipleyTom2019-07-0746-1/+46
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Change all $(SolutionDir) to $(ProjectDir)RipleyTom2019-07-0746-91/+91
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Address issue 554: Default context is erase before backend exits in libusb_exitmac Wang2019-04-092-4/+19
| | | | | | | Closes #554 Closes #556 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Issue 555: Memory passed to ioctl is not initialized in reap_for_handlemac Wang2019-04-082-2/+2
| | | | | | | Closes #557 Closes #555 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* update to 1.0.23-rc1v1.0.23-rc1Nathan Hjelm2019-04-053-4/+9
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Add support for isochronous transfers with WinUSB.philemonf2019-04-055-48/+391
| | | | | | Closes #284 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* windows: get usb device until usb configuration is sethaidong.zheng2019-04-052-15/+39
| | | | | | | | | | | | | There are low possiblity to open device before windows complete usb configuration. Then claim interface will be always failure. this patch workaround this problem, make sure return device until windows finish usb configuration. Closes #505 Signed-off-by: Frank Li <Frank.Li@nxp.com> Signed-off-by: Tom Zheng <haidong.zheng@nxp.com> Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* darwin: Retry IOCreatePlugInInterfaceForService on failureJuan Cruz Viotti2019-04-052-4/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We have a case where a device might not be detected by libusb if we plug it after initializing the library. We were able to reproduce this issue pretty consistently on a Mac Mini and several MacBook Pros running very recent macOS versions (Mojave) using the Balena Fin board (https://www.balena.io/fin/). I don't know if this happens with other USB devices. Enabling debug output revealed the following: ``` [ 7.901582] [00004f07] libusb: debug [darwin_get_cached_device] finding cached device for sessionID 0x2a9b5279f04 [ 7.901764] [00004f07] libusb: debug [darwin_get_cached_device] matching sessionID 0x2a9b5279f04 against cached device with sessionID 0x17dbd029b6a [ 7.901798] [00004f07] libusb: debug [darwin_get_cached_device] matching sessionID 0x2a9b5279f04 against cached device with sessionID 0x1688763269f [ 7.901818] [00004f07] libusb: debug [darwin_get_cached_device] matching sessionID 0x2a9b5279f04 against cached device with sessionID 0x4c0aefaa [ 7.901831] [00004f07] libusb: debug [darwin_get_cached_device] matching sessionID 0x2a9b5279f04 against cached device with sessionID 0x0 [ 7.901845] [00004f07] libusb: debug [darwin_get_cached_device] caching new device with sessionID 0x2a9b5279f04 [ 7.903377] [00004f07] libusb: debug [darwin_device_from_service] could not set up plugin for service: out of resources [ 8.029152] [00000307] libusb: debug [libusb_get_device_list] ``` The "out of resources" error comes from `IOCreatePlugInInterfaceForService` which will apparently return this error if the `Start` method of the interface is not success (see https://github.com/opensource-apple/IOKitUser/blob/b80a5cbc0ebfb5c4954ef6d757918db0e4dc4b7f/IOCFPlugIn.c#L232). Retrying `IOCreatePlugInInterfaceForService` makes it work for me. Closes #542 Signed-off-by: Juan Cruz Viotti <juan@balena.io> Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* xusb: Report SuperSpeedPlusHarry Mallon2019-04-042-4/+4
| | | | | | Closes #530 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* solaris: Fix crash on closing libusb handleAlexander Pyhalov2019-04-043-24/+34
| | | | | | | | | | | | | libusb_close() can interrupt transfer to device, setting dev_handle to NULL. In this case all async requests should exit gracefully. Also usbi_signal_transfer_completion() can dereference dev_handle in this case. Closes #434 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* windows: Improved log message output to MSVCdmitrykos2019-04-042-6/+7
| | | | | | | | | | | | | Improved log message output to MSVC handling by converting multi-byte string (assumed to be UTF-8) to WCHAR string if UNICODE is defined, if UNICODE is not defined then multi-byte string is sent to MSVC (Windows CE defines UNICODE always, so it will use UNICODE case), added check for 0 to avoid sending trash to MSVC (and possibly crash the process) if conversion to WCHAR string fails. Closes #504 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Fixed log message incorrect data format sent to MSVC if Unicode defined.Dmitry Kostjuchenko2019-04-042-2/+2
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Allow set configuration control requests when using libusb0.sysFrederik Carlier2019-04-042-3/+4
| | | | | | Closes #473 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Fix control transfer interface selectionkuro68k2019-04-042-6/+32
| | | | | | | | | When bmRequestType indicates the recipient is an interface, get interface number from wIndex. Closes #398 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Use more portable di_prop_lookup_ints() interfaceAlexander Pyhalov2019-04-042-8/+8
| | | | | | Closes #433 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* transfer_lock should be released before usbi_handle_transfer_completion() callAlexander Pyhalov2019-04-042-2/+8
| | | | | | Closes #430 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Adding support for ARM & ARM64 Windows PlatformDj Art2019-04-0411-10/+298
| | | | | | Closes #423 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* fix windows crash when multi-thread do sync transferFrank Li2019-04-045-11/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fun() { libusb_open() ... sync transfer libusb_close() } two thread call fun infininately. to speed up crash, enable application verifier below 20 cycle, assert(fd!=NULL) happen at check_pollfds below 100 cycle, crash at pollable_fd->overlappend in winusb_get_overlapped result with this fix, success fun over 1000 cycles in handle_events usbi_mutex_lock() fds = ctx->pollfds nfds = ctx->pollfds_cnt; usbi_mutex_unclock() usbi_poll() callback. usbi poll is not in mutex. pollfds may be change by usbi_add_pollfd and usbi_remove_pollfd. Although usbi_add_pollfd and usbi_remove_pollfd hold mutex, but usbi_poll and callback is not in protext of mutex. windows use fd as index of fb_table. fb_table may changed by usbi_remove_pollfd. the map between fd and internal file_descriptor may be wrong. this patch added ref count for file_descriptor, only free file_desciptor and remove it from fb_table when ref count is 0. ref count will be increase when fds copy with mutex lock. so fd always index validate file_descriptor. ref count will be descress before return from handle_events. the file_descriptor can be free safely at this time. Closes #521 Signed-off-by: Frank Li <Frank.Li@nxp.com> Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Fix copy paste error in libusb_free_* docsHarry Mallon2019-04-042-5/+6
| | | | | | Closes #535 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Fixed Xcode 10.1 warning by setting project setting ↵Sean McBride2019-04-043-1/+8
| | | | | | | | | | | | 'ALWAYS_SEARCH_USER_PATHS = NO' The warning was: "Traditional headermap style is no longer supported; please migrate to using separate headermaps and set 'ALWAYS_SEARCH_USER_PATHS' to NO." Also made sure all targets are referencing the xcconfig files. Closes #532 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Initialize the non-control endpoint fds in netbsd_open()Aymeric Vincent2019-04-042-1/+6
| | | | | | | | | | | | Not all users of libusb use libusb_claim_interface(), and in that case, the NetBSD backend fails to open() the necessary /dev/ugenX.Y and will try to send ioctl()s to fd 0, which fortunately fails. This unbreaks e.g. openocd on NetBSD. Closes #539 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* darwin: fix reset deviceNathan Hjelm2019-04-043-53/+154
| | | | | | | | | | | | | | | | | | This commit fixes the backend of reset device to restore the state of the device if possible. This fixes a bug introduced in c14ab5fc4d22749aab9e3534d56012718a0b0f67. The previous commit was necessary due to changes in the system USB stack that essentially turned the ResetDevice function into a no-op. This required libusb to move to USBDevuceReEnumerate to effectively reset the device. The problem is that both the device handle and libusb devices became invalid. This commit fixes the bug by waiting for the re-enumeration to complete then 1) checking whether the descriptors changed, 2) restoring the active configuration, and 3) restoring claimed interfaces. Closes #523 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Fixed -Wformat warnings by casting intptr_t to void*Sean McBride2019-02-082-3/+3
| | | | | | | | | | %p is for pointers, not integers; therefore added a cast. Fixes the following warnings: libusb/core.c:1252:33: Format specifies type 'void *' but the argument has type 'intptr_t' (aka 'long') libusb/core.c:1276:45: Format specifies type 'void *' but the argument has type 'intptr_t' (aka 'long') Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
* haiku_usb_raw: Add missing wrap_sys_device field to usbi_os_backendAndrew Aldridge2019-01-302-40/+41
| | | | | | Closes #527 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* haiku_usb_raw: return written length instead of LIBUSB_SUCCESSAndrew Aldridge2019-01-302-8/+7
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>