summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* 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>
* Fixed many compiler warnings about sign and size mismatchSean McBride2019-01-3014-111/+144
| | | | | | | | | | - added various casts - added some asserts where the casts made assumptions - enabled additional warnings in Xcode project (especially -Wshorten-64-to-32) Closes #509 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* fix race condition at event_handlesFrank Li2019-01-302-3/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | event_handles supposed just run at a thread. There are re-entry check at begin. 1: if (usbi_handling_events(ctx)) 2: return LIBUSB_ERROR_BUSY; 3: usbi_stat_event_handle(ctx); this code is hold any lock it is possible two thread check 1 at the same time, then go through to 3. So two threads will run event_handles. above 3 line code should hold event_data_lock to avoid above race condition. 1: usbi_mutex_lock($ctx->event_data_lock); 2: r = 0; 3: if (usbi_handling_events(ctx)) 4: r = LIBUSB_ERROR_BUSY; 5: else 6: usbi_start_event_handling(ctx); 7: usbi_mutex_unlock($ctx->event_data_lock); 8: if(r) 9: return r; check and set in an atomic operations. Closes #520 Signed-off-by: Frank Li <Frank.Li@nxp.com> Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Add missing structure entry to avoid erroneous shift of following itemswinterrace2019-01-302-1/+2
| | | | | | Closes #526 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* darwin: use internal define when querying plugin interfaceNathan Hjelm2019-01-162-2/+2
| | | | | | | | | | | | | Apple changed the definition of kIOUSBInterfaceInterfaceID in the SDK for macOS 10.14. This looks like it breaks support for building for older macOS versions when running 10.14. I don't know if the change was intentional or a mistake but in order to guarantee libusb builds as it has in the past we can no longer rely on kIOUSBInterfaceInterfaceID. Closes #519 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* darwin: shorten hotplug poll timeoutNathan Hjelm2019-01-082-4/+4
| | | | | | | | | Looks like 5 seconds was indeed too long. Shortened the timeout to 1ms instead. Closes #516 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* linux_usbfs: Disable hotplug events and scanning on AndroidVianney le Clément de Saint-Marcq2019-01-082-6/+10
| | | | | | | | | | | | | | | | On Android, the platform API should be used to scan for and open devices and pass file descriptors to libusb. Newer devices (Android 5+) even prohibit listening for hotplug events, resulting in libusb failing to initialize without this patch. Note that this patch effectively renders libusb useless on older devices that do not have USB support in the platform API (anything before Android 5). Closes #242 Signed-off-by: Vianney le Clément de Saint-Marcq <code@quartic.eu> Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* linux_usbfs: Use fallback usbfs path on AndroidVianney le Clément de Saint-Marcq2019-01-082-3/+5
| | | | | | | | | | | | On newer Android devices (5+), SELinux policies block normal processes from reading /dev. The consequence is that the usbfs path cannot be found. Rather than failing to initialize libusb in such case, fall back to /dev/bus/usb. This path will actually not be used, as USB devices should be opened through the Android API, passing the file descriptor to libusb_wrap_sys_device. Signed-off-by: Vianney le Clément de Saint-Marcq <code@quartic.eu> Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* linux_usbfs: Implement libusb_wrap_sys_device()Vianney le Clément de Saint-Marcq2019-01-082-12/+79
| | | | | | | | | | Add support for the libusb_wrap_sys_device() API on Linux. Because sysfs_dir is set to NULL, only the provided file descriptor will be used. This is needed on some platforms (e.g., Android) where sysfs might not be available. Signed-off-by: Vianney le Clément de Saint-Marcq <code@quartic.eu> Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* core: Add libusb_wrap_sys_device() APIVianney le Clément de Saint-Marcq2019-01-084-1/+102
| | | | | | | | Introduce a new API function for wrapping an existing platform-specific device handle as a libusb_device_handle. Signed-off-by: Vianney le Clément de Saint-Marcq <code@quartic.eu> Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* linux_usbfs: Get device address from file descriptorVianney le Clément de Saint-Marcq2019-01-084-5/+16
| | | | | | | | | | | Extend linux_get_device_address() to try to read the device address from a file descriptor as a last resort, if provided. Additionally, linux_get_device_address() will now return an error if the path could not be parsed. Signed-off-by: Vianney le Clément de Saint-Marcq <code@quartic.eu> Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* linux_usbfs: Extract device handle initialization from op_open()Vianney le Clément de Saint-Marcq2019-01-082-20/+30
| | | | | | | | | Slightly refactor op_open() to extract the device handle initialization code into a new initialize_handle() function, similar to the initialize_device() function. Signed-off-by: Vianney le Clément de Saint-Marcq <code@quartic.eu> Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* linux_usbfs: Fallback to usbfs if device has no sysfs_dirVianney le Clément de Saint-Marcq2019-01-082-14/+16
| | | | | | | | | Handle devices that are initialized with NULL as sysfs_dir. For such devices, the usbfs functions should be used instead of their sysfs counterparts. Signed-off-by: Vianney le Clément de Saint-Marcq <code@quartic.eu> Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Tried to untangle mixing of int, enum libusb_error, kern_return_t, and IOReturn.Sean McBride2019-01-081-89/+94
| | | | | | | | | | | | | | | | - Replace all kern_return_t with IOReturn, they are basically the same, but IOReturn is more common in IOUSBLib - improve consistency by using the name 'kresult' for all IOReturn-type results, and not using that name for libusb_error return values. - changed a few functions to use real 'bool' (this file already uses C99) - replaced some raw '0's with LIBUSB_SUCCESS or kIOReturnSuccess. - replaced some raw 'int's with either IOReturn or enum libusb_error. - replaced ambiguous "if (kresult)" with more explicit "if (kresult != kIOReturnSuccess)" - replaced incorrect use of darwin_to_libusb with darwin_transfer_status Most of these were found by increasing the compiler warning level. Closes #510 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Removed unneeded checks for passing null to free()Sean McBride2019-01-083-14/+8
| | | | | | Closes #507 Signed-off-by: Nathan Hjelm <hjelmn@me.com>