aboutsummaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
...
* Core: Avoid passing uninitialised data down the hotplug pipe.Toby Gray2013-06-262-1/+3
| | | | | | | | | | | Due to alignment requirements, libusb_hotplug_message might have some padding bytes. This change makes sure that these padding bytes are initialised. Valgrind no longer complains about passing uninitialised data to the write system call. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* core.c: Initialize auto_detach_kernel_driver to 0 for new handleChris Dickens2013-06-262-1/+2
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* openbsd: Fix memleak in obsd_get_device_list()Hans de Goede2013-06-262-2/+6
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* core: Only do hotplug cleanup for hotplug capable backendsHans de Goede2013-06-262-9/+11
| | | | | | | | | | | | | | | | | | | | | | Xiaofan encountered a crash while testing on openbsd. The main problem here is libusb_exit doing hotplug cleanup on a non hotplug capable backend. If the usb_devs list is non empty (*) at libusb_exit time with a non hotplug capable backend, then the hotplug cleanup code will unref the devices in the list. Assuming this is the last unref, then libusb_unref_device will call usbi_disconnect_device, which will try to take the usb_devs_lock, which is already hold by libusb_exit. Note that if this deadlock was not there, that we then also would have a double list_del issue. *) This should never happen, if it does either libusb or the app has a memleak, or the app still holds a reference to the device. The latter is an application bug, since device->ctx will be invalid after libusb_exit, so the application should not hold references after calling libusb_exit. In this case we have a memleak the libusb openbsd code causing the usb_devs list to be non empty. This will be fixed in another commit. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* WinCE: ref result of usbi_get_device_by_session_id()Hans de Goede2013-06-262-1/+2
| | | | | | | | | | | | | After the "WinCE: Fix device reference leak which caused crash on libusb_exit()" commit, the code always unref-s dev after adding it to discovered_devs. But if dev comes from usbi_get_device_by_session_id() it is a weak ref and as such should not be unreffed. Instead of re-adding comlicate ref tracking logic, this patch fixes this with a libusb_device_ref(dev) of dev comes from usbi_get_device_by_session_id(), turning the weak ref into a strong ref. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* WinCE: Fix device reference leak which caused crash on libusb_exit().Toby Gray2013-06-262-7/+5
| | | | | | | | | | | | The Windows CE device allocation code has always had a bug where it would leak references to devices when they are allocated. This commit removes the reference leak. This leak was highlighted by the new hotplug code which now triggers a NULL pointer dereference if not all devices are unreferenced before libusb_exit is called. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* Misc: Update AUTHORS filePete Batard2013-06-202-3/+5
|
* Prepare for 1.0.16-rc1 releaseHans de Goede2013-06-204-3/+23
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* autogen.sh: Honor NOCONFIGURE=1Colin Walters2013-06-202-2/+4
| | | | | | | | | | | | See http://people.gnome.org/~walters/docs/build-api.txt Hdg: I know this may seem unnecessary since we also have bootstrap.sh, but the Gnome people are doing continues build testing of Gnome + dependencies and having all autogen.sh scripts support NOCONFIGURE=1 makes live easier for them. Note that in return we get "free" continues build-testing and patches and / or a heads up when we break things. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* sync.c: Remove code duplicationHans de Goede2013-06-202-36/+24
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* sync.c: Do not free an incompleted transferHans de Goede2013-06-202-11/+9
| | | | | | | | | | | | | | | | | | Before this patch the code in sync.c would free an incomplete transfer when libusb_handle_events_completed exits with an error twice in a row. But we should never free an incomplete transfer, otherwise we may end up referencing free-ed memory later on. This patch simply logs an error and keeps on trying until the transfer completes. Note that if libusb_handle_events_completed keeps throwing an error the entire time, without ever completing the transfer, this patch effectively replaces a potential crash / unspecified behavior, with an endless loop and logging a ton of errors making clear what is going on. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* Revert "Core: Don't wait for completion if cancel_transfer failed"Hans de Goede2013-06-202-11/+9
| | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 2f5023c41d3176e56bf0abc521b7c5f8b1ac4664. 2f5023c4 was an attempt to fix: https://github.com/libusbx/libusbx/issues/76 As seen in: http://libusbx.1081486.n5.nabble.com/Libusbx-devel-libusb-interrupt-transfer-does-not-return-in-case-of-error-td626.html [372849.680990] [0000275b] libusbx: error [reap_for_handle] reap failed error -1 errno=14 [372849.681752] [0000275b] libusbx: error [handle_events] backend handle_events failed with error -1 [372850.680466] [0000275b] libusbx: warning [handle_timeout] async cancel failed -5 errno=22 The problem begins with reap_for_handle failing with errno == 14, which is EFAULT. So the real problem is the application passing in an invalid (or too short) buffer, and thus is an application bug. The fix masks this problem, but causes the problem of calling libusb_transfer_free() on a non finished transfer, so it is no good. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Conflicts: AUTHORS libusb/version_nano.h
* Use Android logging when building on AndroidIlya Konstantinov2013-06-202-1/+28
| | | | | | Closes #101 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* Linux: Fix get_kernel_driver_active() when another app has claimed the interfaceHans de Goede2013-06-202-2/+2
| | | | | | | | | | When another app has claimed the interface, IOCTL_USBFS_GETDRIVER will succeed and report a driver of "usbfs" being attached. Since this is not a regular kernel-driver (and detach_kernel_driver does not detach it), get_kernel_driver_active() should return 0 in this case. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* Core: fix another compiler warning in libusb_setlocale()Pete Batard2013-06-192-2/+2
| | | | | * VS2012 (64 bit) produces the following in strerror.c(156): warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
* Core: fix compiler warning in libusb_setlocale()Ludovic Rousseau2013-06-192-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | Hello, A small patch for: strerror.c: In function 'libusb_setlocale': strerror.c:148: warning: comparison between signed and unsigned strerror.c:152: warning: comparison between signed and unsigned -- Dr. Ludovic Rousseau From a4144845845cd0a06fb9074ba2d6669ece3a5b1a Mon Sep 17 00:00:00 2001 From: Ludovic Rousseau <ludovic.rousseau+github@gmail.com> Date: Wed, 19 Jun 2013 13:16:31 +0200 Subject: [PATCH] Core: fix compiler warning in libusb_setlocale() strerror.c: In function 'libusb_setlocale': strerror.c:148: warning: comparison between signed and unsigned strerror.c:152: warning: comparison between signed and unsigned Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* Fix several -Wconversion warnings from GCC inside the static inline functions.Luca Longinotti2013-06-192-10/+10
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* examples: use libusb_set_auto_detach_kernel_driver()Hans de Goede2013-06-193-26/+3
| | | | | | | What better way to show how useful libusb_set_auto_detach_kernel_driver() is, then to use it in our examples? Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* linux_usbfs: Work around a driver binding race in reset handlingHans de Goede2013-06-192-3/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | I've been seeing these intermittent failures to reclaim an interface after a device reset. After much debugging and inserting sleeps in strategic places to make the race window larger I've found the following race: 1) A user is running some software using libusbx which will automatically detect, and "bind" to, any newly plugged in USB-devices. For example a virtual machine viewer with automatic USB-redirection 2) The user plugs in a new usb-storage device 3) The usb-storage driver is not yet loaded, udev spawns "modprobe usb-storage", this blocks on disk-io 4) The libusbx app opens the device, claims all interfaces, does a device-reset 5) While the IOCTL_USBFS_RESET is running the modprobe completes 6) The driver registration blocks on an USB lock held by the reset code path 7) When the reset finishes the driver registration completes and the driver binds itself to the device, before IOCTL_USBFS_RESET returns to userspace 8) libusbx tries to re-claim all interfaces it had claimed before the reset 9) libusbx fails as usb-storage is now bound to it This patch works around this issue by simply unbinding the driver for all interfaces which were claimed before the reset. Normally this is a no-op as no driver (other then usbfs) can be bound for claimed interfaces before the reset. This patch also improves the error logging, and makes libusb_device_reset properly return an error when re-claiming fails. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* linux_usbfs: Add support for new disconnect-and-claim ioctlHans de Goede2013-06-193-2/+36
| | | | | | | | | | | | | | | | | | Currently the linux_usbfs detach_kernel_driver_and_claim() helper function makes 3 system calls: 1) IOCTL_USBFS_GETDRIVER, to check the driver is not usbfs 2) IOCTL_USBFS_DISCONNECT 3) IOCTL_USBFS_CLAIMINTF Between each of these calls the state of the interface can change, and things might not work as expected when it does, iow this is inherently racy. To fix this a new IOCTL_USBFS_DISCONNECT_CLAIM ioctl has been added to the kernel a while back, which does all 3 in one. This patch adds support for this ioctl, with a fall back to the old method for kernels lacking this new ioctl. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* libusb: Add auto-detach-kernel-driver functionalityHans de Goede2013-06-196-6/+93
| | | | | | | | | | | | | | | | | | | | | | | | | | Add auto-detach-kernel-driver functionality, and a libusb_set_auto_detach_kernel_driver() function. Note that I went with a libusb_set_auto_detach_kernel_driver() function, rather then with a libusb_enable_auto_detach_kernel_driver(), so that apps can also disable it again. This is necessary to handle 2 corner cases: 1) When an app wants to do a libusb_set_configuration after claiming 1 or more interfaces, it needs to first release the interface(s), and in this case libusb_release_interface() should *not* (re-)attach the kernel driver 2) Some usb classes use multiple interfaces for one function, ie usb-audio devices do this. In this case attaching the driver will fail until all interfaces are released, so the app should first release all interfaces, and only then (re-)attach the kernel driver. auto-detach-kernel-driver functionality is still useful for these apps, since doing libusb_detach_kernel_driver() followed by libusb_claim_interface() in 2 separate calls is inherently racy, but they need to be able to disable the auto-detach functionality before releasing interfaces to be able to properly handle the 2 described corner cases. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* linux_udev: Fix spelling of guarantee in commentHans de Goede2013-06-192-2/+2
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* POSIX: Set usbi_pipe to non-blocking by oring O_NONBLOCK to fd flags.Chris Dickens2013-06-172-4/+14
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* linux_udev: Don't free the udev_monitor while the event thread may still use itHans de Goede2013-06-172-6/+6
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* linux_udev: Join the hotplug-event-thread when we stop event monitoringHans de Goede2013-06-142-6/+7
| | | | | | | To ensure that it is stopped before we continue (and if later libusb gets re-initialized start another thread). Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* libusb_get_bos_descriptor: Don't log an error on devices without a BOSHans de Goede2013-06-142-2/+3
| | | | | | | An error of LIBUSB_ERROR_PIPE simply means the device has no BOS, so don't log an error to the console for this. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* hotplug: ensure udev monitor fd is non-blockingChris Dickens2013-06-142-1/+14
| | | | | | | | | | | Some older versions of udev do not automatically set the udev monitor fd to non-blocking mode. This patch ensures that this is always set. HdG: Get flags then or in O_NONBLOCK and set them, rather then setting flags to only O_NONBLOCK. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* linux_udev: Log error code on pthread_create failureHans de Goede2013-06-142-2/+2
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* Examples: add a missing \n at end of error messagesLudovic Rousseau2013-06-112-3/+3
|
* Core: Add a libusb_strerror() functionHans de Goede2013-06-1020-19/+265
| | | | | | | | | | | | | | | | | | | This patch adds the much requested libusb_strerror() function, taking into account all issues people raised wrt previous attempts. Criteria / Decisions underlying this implementation: - Must support translated messages - Must not use gettext as that does not work well in combination with Windows (when building with Visual C, or for Windows CE) - API compatible with FreeBSD and various patched libusb-s floating around - KISS: - Do not add any (other) library dependencies - Do not try to deal with message encodings (iconv), simply always return UTF-8 making encoding the problem of the application using libusb_strerror. - Defaults to English, so apps which don't want translated messages, don't need to do anything special - Defaults to English (with pure ASCII messages), so apps which don't call libusb_setlocale() don't need to worry about encoding
* Merge pull request #114 from hjelmn/darwin_device_cacheHans de Goede2013-06-062-243/+299
|\ | | | | Darwin device cache
| * darwin: return correct error code from libusb_get_config_descriptor when the ↵Nathan Hjelm2013-06-061-1/+1
| | | | | | | | configuration is not found
| * darwin: increment the reference counter to the parent deviceNathan Hjelm2013-06-061-0/+5
| |
| * darwin: avoid enumerating devices more than onceNathan Hjelm2013-06-062-243/+294
|/ | | | | | | | | | | | | | | | | | | | This patch attempts to avoid enumerating devices multiple times by keeping a cache of device information (IOUSBDeviceInterface pointers, device descriptors, etc) between calls to libusb_init(). This should avoid two potential problems: 1) Devices that respond slowly to DeviceRequest. These devices can take multiple seconds to respond and they usually respond with a failure (on older versions of OSX at least). By keeping track of these devices the penalty for enumerating them will be paid only once. 2) Repeated enumeration of the same device may cause IOCreatePlugInInterfaceForService() to fail. The root cause of this problem is not well understood but might be a leak in IOUSBFamily. To clean up the cached device information an atexit() function is used.
* Windows: Fix broken WDK compilationPete Batard2013-05-302-5/+5
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* examples: Add sam3u_benchmark isochronous example by Harald WeltePeter Stuge2013-05-304-1/+198
| | | | | | | | | | | | | | | | Copied with the author's permission under LGPL-2.1 from usb-benchmark-project/host/benchmark.c in git://git.gnumonks.org/sam3u-tests.git commit 74959f7ee88f1597286cd435f312a8ff52c56b7e http://git.gnumonks.org/cgi-bin/gitweb.cgi?p=sam3u-tests.git;a=blob;f=usb-benchmark-project/host/benchmark.c;h=74959f7ee88f1597286cd435f312a8ff52c56b7e An Atmel SAM3U test firmware is also available in the above repository. Conflicts: .gitignore Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* Add BOS descriptor supportHans de Goede2013-05-305-2/+631
| | | | | | | Based on earlier work done on this by Maya Erez <merez@codeaurora.org>, Nathan Hjelm <hjelmn@me.com> and Pete Batard <pete@akeo.ie>. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* Add superspeed endpoint companion descriptor supportHans de Goede2013-05-306-7/+157
| | | | | | | Based on earlier work done on this by Maya Erez <merez@codeaurora.org>, Nathan Hjelm <hjelmn@me.com> and Pete Batard <pete@akeo.ie>. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* hotplug: Add a hotplug_poll backend functionHans de Goede2013-05-3010-15/+70
| | | | | | | | | | | | | | | | | | | | Apps which were written before hotplug support, may listen for hotplug events on their own and call libusb_get_device_list on device addition. In this case libusb_get_device_list will likely return a list without the new device in there, as the hotplug event thread will still be busy enumerating the device, which may take a while, or may not even have seen the event yet. To avoid this add a new hotplug_poll backend function and make libusb_get_device_list call a this before copying ctx->usb_devs to the user. In this function the backend should ensure any pending hotplug events are fully processed before returning. This patch implements hotplug_poll for linux, it should probably be also implemented for darwin. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* linux: rework hotplug lock handlingHans de Goede2013-05-305-11/+13
| | | | | | | | I could not find if libudev is completely threadsafe anywhere, so rework the lock handling to serialize all libudev accesses. This is a preparation patch for adding hotplug_poll support, see the next patch in this series. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* linux: Add a linux_netlink_read_message helper functionHans de Goede2013-05-302-30/+40
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* descriptor.c: AlternateSettings are related by InterfaceNumberHans de Goede2013-05-302-2/+6
| | | | | | | | A block of AlternateSettings for a certain InterfaceNumber does not necessarily start with AlternateSetting 0, so check Interface Descriptors belong to each other by using InterfaceNumber, as specified in the spec. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* WinCE: Add hotplug.c to projectsToby Gray2013-05-283-1/+9
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* Windows: Add new symbol for libusb_get_port_numbers to def fileToby Gray2013-05-282-1/+3
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* Hotplug: Make use of HAVE_SYS_TYPES_H defineToby Gray2013-05-282-1/+3
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* POSIX: Move setting of pipes to non-blocking into usbi_pipeToby Gray2013-05-285-12/+52
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* wince_get_active_config_descriptor() sets host_endian incorrectlySimon Haggett2013-05-242-2/+2
| | | | | | | | wince_get_active_config_descriptor() retrieves configuration descriptors as raw bytes, in bus-endian order. Therefore, host_endian should be set to 0 (as in wince_get_config_descriptor()). Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* all: ensure host_endian is always initializedHans de Goede2013-05-243-2/+3
| | | | | | | | | | | The get_device_descriptor backend call done from descriptor.c was passing in an uninitialized host_endian value. Likewise for the windows backend, host_endian was not being set from get_[active_]config_descriptor. Since the 2 problem cases are for different backend calls, we were never using an uninitialized host_endian, still lets set it everywhere for safety, Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* all: Allow backend to provide a better get_config_descriptor_by_valueHans de Goede2013-05-247-9/+39
| | | | | | | | | | | | Our core get_config_descriptor_by_value is not exactly pretty nor efficient, allow the backends to provide something better. Note that the callback signature differs from get_config_descriptor in that backend owned memory gets returned. This saves a needless malloc + memcpy + free. If this turns out to be a problem for some backends we can always change things to work like get_config_descriptor. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* descriptor.c: Add a raw_desc_to_config helper functionHans de Goede2013-05-242-68/+44
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>