summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
...
* configure: remove usage of deprecated AC_HELP_STRINGNathan Hjelm2021-07-262-2/+2
| | | | | | | This macro was replaced by AS_HELP_STRING. This commit updates the lingering deprecated call with the new macro as used elsewhere in configure.ac. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* core: set default backend options before calling backend initNathan Hjelm2021-07-262-16/+16
| | | | | | | | | | | This commit restores the previous behavior with regards to setting some backend options and restores the ability to set default context options before libusb_init. None of the backends use anything set in init in their set_option function so this should be safe with all backends and options. References #942 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* Update libusb-1.0.defmcuee2021-07-262-2/+2
| | | | | | | | | | | This fixes issue #944 C++ symbol for libusb_set_option not exported correctly. As per the report in issue #944, original commit is correct but subsequent edits cause the regression. https://github.com/libusb/libusb/blob/v1.0.22-rc1/libusb/libusb-1.0.def#L156 Closes #964 Signed-off-by: Xiaofan Chen xiaofanc@gmail.com Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* darwin: only attempt to auto-detach driver is one is activeNathan Hjelm2021-07-222-2/+2
| | | | | | | | | This commit improves the auto-detach code so that it doesn't attempt to detach a kernel driver if none exists. This will avoid extra info/warning output on the failed detach. Closes #960 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* darwin: use the IO registry to detect if a kernel driver is attached to an ↵Nathan Hjelm2021-07-214-5/+55
| | | | | | | | | | | | interface The implementation of libusb_kernel_driver_active was attempting to open the interface to check if a driver is attached. This may have side effects (like configuring the device) that may be unexpected to the user. This commit updates the code to find the interface's IO registry entry (either IOUSBHostInterface or the legacy IOUSBInterface) and check if the entry has a child entry. A child entry indicates that a driver is currently attached. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* xusb: add check for interface kernel driverNathan Hjelm2021-07-212-1/+3
| | | | | | | This commit adds a call to libusb_kernel_driver_active and prints out the result. This provides a way to quickly check the result when testing. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* core: update usbi_dbg to take the context as an argumentNathan Hjelm2021-07-2121-513/+530
| | | | | | | | | | | | | This commit fixes a performance issue caused by the disconnection of the first context allocated from the default context. usbi_dbg now takes the explicit context instead of relying on the default context (which may not exist) in most cases. All call sites have been updated to pass the context or explicitly pass NULL if the context is not available. We should actively discourage using NULL as the context in the future and patch all call sites to always pass the context. Fixes #951 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* darwin: downgrade error message on failure to open interface to infoNathan Hjelm2021-07-202-7/+7
| | | | | | | | | | | | | This resolves an issue introduced by the implementation of the kernel detach code. This code used claim_interface to detect if a kernel driver is attached. The issue is that if a driver is attached or the interface is not available and an error message was printed out. Since this is not an error the info level is more appropriate. Also downgrading a number of warnings to clean up the output. Closes #955 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* darwin: add a comment on how the bus number is calculatedNathan Hjelm2021-07-202-1/+3
| | | | | | | | This commit adds a comment about the bus number calculation to indicate how the location ID is constructed and why libusb is using the top byte for the bus number. It also indicates that the bus number starts at 0. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* darwin: update the list of endpoints after successfull SetAlternateInterface()Dmitry Zakablukov2021-07-202-2/+12
| | | | | | Closes #950 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* winusb: Ignore missing DeviceInterfaceGUIDTormod Volden2021-07-202-2/+4
| | | | | | | Closes #948 Signed-off-by: Tormod Volden <debian.tormod@gmail.com> Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* darwin: improve support for auto-detaching a kernel driverNathan Hjelm2021-07-092-17/+33
| | | | | | | | | | | | | | | This commit improves the code around auto attach/detach of a kernel driver: - Log a warning when a driver can not be auto-detached and continue when claiming an interface. It could be the case that the interface has no driver attached or that the claim will still succeed. - Log a warning if the driver can not be auto-attached and return success when releasing an interface. The operation did complete successfully but the re-enumeration may have failed. This can be discovered on the next device access. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* darwin: fix SEGV on libusb_close after failed re-enumerationNathan Hjelm2021-07-082-3/+9
| | | | | | | | This commit fixes an issue that can occur if the user calls libusb_close after a failed attempt of libusb_reset (re-enumerate). This can lead to an attempt to dereference dpriv->device which was set to NULL during the re-enumeration. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* [Issue-912] Lock open_devs_lock in context to avoid access violationDmitry Zakablukov2021-07-082-10/+23
| | | | | | Closes #943 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* New NO_DEVICE_DISCOVERY option to replace WEAK_AUTHORITY optionTormod Volden2021-07-084-16/+30
| | | | | | | | | | | | | The option disables device enumeration (and hotplug, which depends on enumeration). Since this has a much broader usage scope than "weak authority", give the option a name reflecting what it does. For now, keep the old option name working as an alias. Closes #935 Signed-off-by: Tormod Volden <debian.tormod@gmail.com> Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* windows: Allow GUID with and without trailing zeroesCraig Hutchinson2021-07-082-5/+11
| | | | | | | | | | | | | Improve the GUID length check to accommodate the cases where the GUID string fetched from registry does not have a trailing zero, or if a multi-string entry, one or two trailing zeroes. Closes #927 Signed-off-by: Craig Hutchinson <54269136+CraigHutchinson@users.noreply.github.com> [Tormod: Use correct types and simplify comparisons] Signed-off-by: Tormod Volden <debian.tormod@gmail.com> Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* Fix build failure on Mac OS X 10.7Ryan Schmidt2021-07-082-2/+2
| | | | | | | | | | Apple documentation says kUSBDeviceSpeedSuper is available in 10.7 and later but in fact it is only defined in the 10.8 SDK and later. Closes #410 Closes #929 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* darwin: release device parent reference when re-enumerating deviceNathan Hjelm2021-06-112-3/+6
| | | | | | | | | | | | | This commit fixes a dangling device reference that can occur when a device is being re-enumerated. The problem is the code was unconditionally re-caching the parent device which then takes a reference on the parent device. If the field was already populated this reference was not needed. To ensure the code works even if the parent device also changes during the re-enumeration the code release the parent reference and grabs a fresh reference. Fixes #924 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* Do not restrict "weak authority" option to AndroidTormod Volden2021-06-113-16/+8
| | | | | | | | | | | | | libusb_wrap_sys_device() is an often needed feature on Android, but can also be very convenient on other Linux platforms. In many cases the initial device scanning is not needed and LIBUSB_OPTION_WEAK_AUTHORITY thus provides a performance enhancement. Closes #925 Signed-off-by: Tormod Volden <debian.tormod@gmail.com> Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* core: really fix dangling devicesNathan Hjelm2021-06-112-14/+16
| | | | | | | | | | | The prior fix made an incorrect assumption about the reference counting of parent devices. This CL fixes the issue by checking if the parent device should be removed from the list as well. This is needed as when the child device is released the parent may also be released. Closes #924 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* darwin_set_interface_altsetting: Avoid device reset on pipe errorTormod Volden2021-06-102-13/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the device doesn't support the SET_INTERFACE request (which is allowed if there are no alternate interfaces) it should stall the pipe. A successful device request would clear all endpoints of the interface. We therefore plaster over the failed request by clearing the endpoints and returning success, effectively replacing the missing device request support. Up to now this was done by resetting the device, but this would affect other interfaces as well. So only clear the endpoints of the selected interface. Only do this in the case the request tried setting the already selected setting. Otherwise return the pipe error to the caller. For any other error than pipe error return with failure. Note that we need to reclaim the interface after the pipe error. This is maybe papering over a bug in libusb or darwin: The interface becomes inaccessible after the failed SetAlternateInterface() call. The reclaim recovers from it, without device side-effects. The need to recover was maybe the reason for the original reset "hammer". Closes #852 Signed-off-by: Tormod Volden <debian.tormod@gmail.com> Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* winusb: Check for ClassGuid changes on re-enumerationTormod Volden2021-06-103-1/+9
| | | | | | | | | | | | | | Previously only the dev_id (VID/PID/serial) was checked, but if the bcdDevice has changed, Windows will have re-enumerated the device and possibly attributed another ClassGuid to it. Fixes issue #897. Closes #900 Thanks to Craig Hutchinson for reporting, suggestion and testing. Signed-off-by: Tormod Volden <debian.tormod@gmail.com> Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* core: only increment devices_released when a device is destroyedNathan Hjelm2021-06-102-3/+4
| | | | | | | Fix a typo in the last commit to ensure the loop does exit when there is a dangling reference. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* core: ensure that all devices are properly cleaned up on libusb_exitNathan Hjelm2021-06-102-10/+15
| | | | | | | | | | | | | | | | | | | | When cleaning up the context on libusb_exit the last step is to to call hotplug_exit. This function took one pass over the devices and released any devices where the reference count had reached 0. All remaining devices were assumed to have leaked references and a warning message was printed out. Unfortunately, this cleanup was too simplistic. It ignored the references created when a device was the parent of another device (which takes a reference). This reference is released when the child device is released. To ensure that we do not erroneously warn about devices with leftover references the code now loops over the device list until no more devices have a single reference. This ensures that we will eventually remove all devices with no external references. Fixes #924 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* core: allow libusb_set_option on the default context before libusb_initNathan Hjelm2021-06-075-21/+71
| | | | | | | | This commit updates libusb_set_option to save the options if setting them on the default context. This ensures the options 1) can be set before libusb_init(NULL, ...), and 2) are honored even if the default context is destroyed and re-created. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* Windows: Try alternative methods to query port numberJim Chen2021-06-072-4/+43
| | | | | | | | | | | | | | This commit is similar to #634 but I think it offers a better approach. The commit adds two more methods for querying the port number, in addition to the existing SPDRP_ADDRESS method, which may not actually return the port number when using USB drivers other than the Microsoft driver. The first method uses SPDRP_LOCATION_INFORMATION, which may return a port in a format similar to "Port_#0002.Hub_#000D". The second method uses SPDRP_LOCATION_PATHS, which returns the device location in a format similar to "PCIROOT(B2)#PCI(0300)#PCI(0000)#USBROOT(0)#USB(1)#USB(2)#USBMI(3)", where the port number is the number within the last "#USB()" token. If both methods fail, SPDRP_ADDRESS is still used as a fallback. Closes #867 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* Windows: Support LIBUSB_TRANSFER_ADD_ZERO_PACKET on winusbPatrick Stewart2021-06-073-3/+29
| | | | | | Closes #312 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* doc: Add since version tag to libusb_wrap_sys_device()Ihor Dutchak2021-06-062-1/+3
| | | | | | Closes #914 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* doc: correction of LIBUSB_OPTION_WEAK_AUTHORITY availabilityIhor Dutchak2021-06-062-4/+4
| | | | | | | | | Even though its implementation is in linux/usbfs, in fact it is under `ifdef` and only used by Android builds. Closes #916 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* darwin: do not reset darwin_cached_devices on last call to libusb_exitNathan Hjelm2021-06-062-6/+5
| | | | | | | | | | | This fixes a bug in the change that removed the library destructor function. We should not be setting the darwin_cached_devices next and prev pointers to NULL as other parts of libusb may still have references to the devices (hotplug for example). When those references are release it may modify darwin_cached_devices. This commit fixes the issue by only initializing darwin_cached_devices on the very first call to libusb_init and not modifying darwin_cached_devices in libusb_exit (beyond unrefing the devices). Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* core: Refactor initialization and how the default context is handledChris Dickens2021-06-0228-451/+333
| | | | | | | | | | | | | | | | | | | Highlights for this change: - usbi_default_context is only set if libusb_init() is called with NULL. - All hotplug related functionality (e.g. initialization, processing) has been moved to hotplug.c - Backends are simplified by removing initialization mutexes. Mutual exclusion between init()/exit() is provided by default_context_lock. - Make hotplug types and functions part of libusbi.h with the common usbi_ prefixes (removes hotplug.h). Addresses issue highlighted in #855 Closes #856 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com> Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* make libusb.h usable with WatcomOzkan Sezer2021-05-162-3/+3
| | | | | | Closes #904 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* Update ChangeLog in preparation for 1.0.25Nathan Hjelm2021-05-162-2/+4
| | | | Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* darwin: remove redundant macOS version checksosy2021-05-162-15/+15
| | | | | | | | | | | The InterfaceVersion is what we want and there is no reason to also check that the InterfaceVersion matches the macOS version it was introduced in. This check inadvertently disables features for other Apple platforms that use IOKit. Closes #911 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* darwin: add authorization for device captureosy2021-05-165-27/+106
| | | | | | | | | | | | | | | | | | | To use USBDeviceReEnumerate with kUSBReEnumerateCaptureDeviceMask your app either needs to be running as root OR have the 'com.apple.vm.device-access' entitlement AND have the user authorization requested via IOServiceAuthorize(). We can use the capture re-enumerate APIs if either 1) the process is running as root or 2) the 'com.apple.vm.device-access' entitlement is used AND IOServiceAuthorize() is called. We assume that if the entitlement is not there then we are running as root--if this is not true, then darwin_detach_kernel_driver will fail anyways. The authorization status is cached in the device's start() so we have to stop() and start() the device by destroying the plugin and recreating it again. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* darwin: use detach kernel APIs for captureosy2021-05-164-28/+147
| | | | | | | | | | | | | | | | | | | When libusb_detach_kernel_driver() is called on the first interface, we use the capture re-enumerate APIs to force kernel drivers to detach. On subsequent calls, a counter is incremented to keep track of the number of detach calls. When libusb_attach_kernel_driver() is called for the same number of times, then we re-enumerate (reset) and let kernel drivers re-attach. darwin_kernel_driver_active() is changed to attempt to claim an interface and return 1 only if a kIOReturnExclusiveAccess status is returned. The old implementation which looks for a CFBundleID in the IORegistryEntry does not seem to work in all cases. darwin_reset_device() is aware of the capture status and will re-set twice if capture mode is enabled: once to do a USB reset and again to re-capture. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* darwin: rename darwin_reset_deviceosy2021-05-162-8/+9
| | | | | | | Since it calls USBDeviceReEnumerate() and not USBDeviceReset(), we name it accordingly. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* darwin: add timeout for reset reenumerateosy2021-05-162-1/+12
| | | | | | | USBDeviceReEnumerate() does not return an error code (bug?) so if it fails we could be stuck waiting forever. Set a sane timeout to 10s. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* autogen: Support being called from external build dirMarco Trevisan (Treviño)2021-04-143-3/+7
| | | | | | | | | | | Building libusb from another build directory doesn't properly work right now, as calling autogen.sh from there won't work. An example is when using jhbuild to build it. So always use absolute paths to call configure and bootstrap scripts Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
* Doxygen: fix warning about PAPER_TYPELudovic Rousseau2021-02-222-2/+2
| | | | | | | warning: argument 'a4wide' for option PAPER_TYPE is not a valid enum value Using the default: a4! Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
* Doxygen: update config file from 1.8.16 to 1.9.0Ludovic Rousseau2021-02-222-66/+146
| | | | | | | | | warning: Tag 'TCL_SUBST' at line 255 of file 'doxygen.cfg.in' has become obsolete. This tag has been removed. warning: Tag 'COLS_IN_ALPHA_INDEX' at line 1056 of file 'doxygen.cfg.in' has become obsolete. This tag has been removed. Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
* darwin: Don't drop partial data on timeoutVegard Storheil Eriksen2021-02-152-2/+2
| | | | | | | | | A timed out transfer might have been partially filled. Propagate tpriv->size to avoid dropping this data. Closes #876 Signed-off-by: Nathan Hjelm <hjelmn@cs.unm.edu>
* doc: Add since version tag to libusb_set_log_cb()Victor Toso2021-02-153-1/+9
| | | | | | | | | | | | | The commit f74c7f5 "core: new API libusb_set_log_cb() to redirect global and per context log messages to the provided log handling function" in 2018-12-05 is present from 1.0.23 onwards. This commit just adds this to the docs. Closes #872 Signed-off-by: Victor Toso <victortoso@redhat.com> Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* linux_usbfs: Gracefully handle buggy devices with a configuration 0Chris Dickens2021-02-082-36/+60
| | | | | | | | | | | | | | | | | The USB spec states that a configuration value of 0 is reserved and is used to indicate the device in not configured (e.g. is in the address state). Unfortunately some devices do exist that violate this and use 0 as the bConfigurationValue of the configuration descriptor. Improve how the Linux backend handles such non-conformant devices by adding special handling around the configuration value 0. Most devices will not require this special handling, but for those that do there is no way to distinguish between the device being unconfigured and using configuration 0. Closes #850 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* linux_usbfs: Accept sysfs attributes not terminated with newlineChris Dickens2021-02-082-6/+8
| | | | | | | | | | | | | Benjamin Berg reports that some CI systems that simulate sysfs devices are causing libusb to report errors because such systems are not conforming to the sysfs pattern of terminating attribute values with a newline character. Reduce the severity of encountering such non-conforming attibute values from an error that prevents enumeration to a warning message. Closes #857 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* linux_netlink: Change order of header includes per netlink(7)Chris Dickens2021-02-082-2/+2
| | | | | | Closes #869 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* darwin: fix const array size to work with GCC compilersMichael Dickens2021-02-082-2/+2
| | | | | | Closes #833 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Fix HID and synchronous transfer completionChris Dickens2021-02-013-13/+16
| | | | | | | | | | | Commit b51c743e42 ("Windows: Filter out non-libusb I/O completions") causes problems with the HID backend functions and synchronous transfer completions. Address these by fetching the correct pointer in the HID functions and posting an I/O completion for synchronous transfers. Closes #863 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Filter out non-libusb I/O completionsChris Dickens2021-01-155-32/+88
| | | | | | | | | | | | | | | | | | | | The I/O completion port thread gets notified of every I/O operation that completes for a given HANDLE, but not all I/O operations originate from within libusb. For example, libusbK performs a number of I/O control calls during initialization and specific device operations, such as setting an interface alternate setting. These non-libusb operations need to be ignored as the OVERLAPPED associated with such operations is not tied to a libusb_transfer structure. Resolve this situation by using the libusb device handle as the I/O completion port's unique key and keeping a list of active transfers for each device handle. When the I/O competion port thread is notified of an I/O completion, it will first match the OVERLAPPED to an outstanding transfer before acting on it. Closes #844 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* configure.ac: Consider Mac OS X target version for clock_gettime()Chris Dickens2021-01-152-5/+25
| | | | | | | | | | | | | | | | The AC_CHECK_FUNCS() macro checks whether a program compiled on the host will link against the function, but it does not help when targeting older systems where that function is not available. Additionally, the way that autoconf compiles the program ignores any attributes or preprocessor guards that installed headers might have applied to that function. Resolve this by verifying that the OS X target version is 10.12 or newer before checking for clock_gettime(). Closes #836 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>