summaryrefslogtreecommitdiff
path: root/libusb/os/linux_usbfs.c
Commit message (Collapse)AuthorAgeFilesLines
* merge abstraction for POSIX Threads and integration changes (Michael Plante, ↵r169Pete Batard2010-02-241-15/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Peter Stuge) v1.0.6 release Darwin: support multiple calls to libusb_init Credit to Orin Eman for finding this bug. Darwin: use logging functions Use usbi_warn, usbi_err, and usbi_info instead of _usbi_log. Darwin: fix memory leak in process_device Credit to Mike Colagrosso for finding this bug. Add internal abstraction for POSIX Threads This prepares for a Windows backend without dependency on pthreads-w32. pthread_* is renamed to usbi_* and PTHREAD_* to USBI_*. A usbi_mutex_static_t and usbi_mutex_static_lock() and _unlock() are introduced for statically initialized mutexes, since they may be implemented using other types when pthreads mutexes aren't used. Move -pthread from libusb/Makefile.am to host-specific AM_CFLAGS in configure.ac. AM_CFLAGS is already used in Makefile.am. (Numerous merge conflicts resolved by Michael Plante) misc fixes to pthreads abstraction * windows_compat.h should not be directly included (use libusbi.h) * windows_usb.c still had some references to pthread_mutex_[un]lock Add libusb_strerror() to get short error message in English from enum (Merge conflicts resolved by Michael Plante) Better cleanup on errors, stricter types and some good casts Avoid various memory leaks in error code paths and remove warnings. Also add usbi_cond_destroy in os/threads_posix.h because it's used for cleanup now. (Merge conflicts resolved by Michael Plante) Rename all interface parameters to usb_interface or interface_number (Merge conflicts resolved by Michael Plante) Add type parameter to the list_for_each_entry() and _safe() macros (Merge conflicts resolved by Michael Plante) VA_ARGS workaround for logging with MSVC6 (Merge conflicts resolved by Michael Plante) Fix context memory leak in libusb_init() * Now holds default_context_lock for duration of libusb_init * Doesn't allocate it if not needed Fix the last MSVC /W3 warning removal of pthreads from MSVC and mingw * removed pthread*.lib from linking in msvc6 (2005/8 not yet edited) * added threads_windows.[ch] to all project files in msvc6 * added usbi_cond_signal to both threading versions, unused * added native windows threading code, now used removed redundant time.h includes removed pthread-win32 informational solution files updated MSVC 2005/2008 for thread abstraction fixed DDK build fixed cygwin's use of POSIX threads fixed dpfp/dpfp_threaded for MinGW compatibility config_msvc.h -> msvc/config.h pthread abstraction for DLL project files fixed bad reference to thread_windows in 2005 DLL vcproj cygwin ifdef is not required in threads_windows.h - removed fixed residuals from previous patches moved thread source detection into autotool scripts
* svn r55: - fixes list_for_each_entry calls for Darwin and LinuxPete Batard2010-01-141-1/+1
|
* Use timerfd for timeout handlingDaniel Drake2009-11-071-46/+35
| | | | | | | | | | | | Use a new file descriptor from the timerfd system calls to handle timeouts. On supported systems, this means that there is less hassle figuring out when the poll() timeout should be, since libusb_get_next_timeout() will always return 0 and the timeout events will be triggered as regular activity on the file descriptor set. Add API function libusb_pollfds_handle_timeouts() to detect whether you're on a platform with the timing headache, and flesh out the surrounding documentation.
* Linux: Add support for the new URB_BULK_CONTINUATION flagDavid Moore2009-11-061-1/+51
| | | | | | | | | | | | | | | | | | Add support for the new USBDEVFS_URB_BULK_CONTINUATION flag to libusb. This flag, which is expected to be available in usbfs starting with kernel 2.6.32, allows the kernel to cancel multiple URBs upon receipt of a short packet. This capability allows libusb to preserve data integrity of large bulk transfers that are split into multiple URBs. Without this support, these URBs must be canceled in userspace upon receipt of a short packet, a race condition against future transfers which might partially fill these canceled URBs. This patch automatically detects whether a supported kernel is present and enables the use of the flag when possible. [dsd: tweaks to supported kernel detection, and some inline documentation of this mechanism]
* Transfer lockingDaniel Drake2009-11-061-13/+32
| | | | | | | | | | | | At least on Linux, there were some possible races that could occur if a transfer is cancelled from one thread while another thread is handling an event for that transfer, or for if a transfer completes while it is still being submitted from another thread, etc. On the global level, transfers could be submitted and cancelled at the same time. Fix those issues with transfer-level locks.
* Linux: more flexibility with monotonic clockDaniel Drake2009-09-111-2/+46
| | | | | | | | | | | | | Some users have reported that CLOCK_MONOTONIC does not work on their systems - I suspect it is available on x86 but perhaps not some of the more uncommon architectures. We should fall back on CLOCK_REALTIME in these cases. Also, CLOCK_MONOTONIC_RAW seems even more monotonic, so we should use that if it is available. We now test different clock IDs during initialization to find the best one that works.
* Linux: try harder not to lose any dataDaniel Drake2009-07-091-11/+35
| | | | | We would previously lose any data that was present on a cancelled URB. Work harder to make sure this doesn't happen.
* Linux: fix sending of zero length bulk packetsDaniel Drake2009-06-201-1/+5
| | | | | Note that there are is a kernel bug preventing this from working properly at the moment, even after this fix.
* Linux: fix config descriptor parsing on big-endian systemsDaniel Drake2009-06-101-2/+7
| | | | | | | Multi-byte fields in the configuration descriptors that come back from usbfs are always in bus endian format. Thanks to Joe Jezak for help investigating and fixing this.
* Abstract clock reading into OS layerNathan Hjelm2009-02-161-0/+14
| | | | | | This will differ on Linux and Darwin, at least. [dsd: minor style tweaks]
* Prevent transfer from being submitted twice or improperly canceledDavid Moore2009-01-121-6/+32
| | | | | | | | | | This ensures that tpriv->urbs and tpriv->iso_urbs are always set to NULL whenever a transfer is not submitted. In this way, submit_*_transfer() and cancel_*_transfer() can error check to ensure that the transfer is in the correct state to be either submitted or canceled, preventing potential memory leaks or double frees. Signed-off-by: David Moore <dcm@acm.org>
* Linux: Fix race condition in cancel_bulk_transfer()David Moore2009-01-101-98/+38
| | | | | | | | | | | | | | | | | | | | | | | This fixes a race condition in cancel_bulk_transfer(). In the old version, awaiting_reap and awaiting_discard are incremented in cancel_bulk_transfer() and decremented in handle_bulk_completion(). However, since these events may take place in two different threads, these variables may reach zero before all URBs have been canceled, triggered spurious callbacks and duplicate frees. This changes the logic to use a single variable "num_retired" to replace both awaiting_reap and awaiting_discard. num_retired is incremented only in handle_bulk_completion() and thus there is no race. The handler will know that all URBs have been canceled when num_retired becomes equal to num_urbs. This change also simplifies a great deal of the logic in both functions and is a net reduction in the amount of code. Note that some variables such as "reap_action" probably need to still be protected by a mutex, and this patch does not address that issue. Signed-off-by: David Moore <dcm@acm.org>
* Linux: fix reading of active configurationDaniel Drake2008-12-091-1/+1
| | | | | Shannon Chuang pointed out that we only read 1 byte into an uninitialized integer, and then return the whole thing.
* Add libusb_attach_kernel_driver()Bastien Nocera2008-11-031-0/+33
| | | | | | Add support for re-attaching a driver to a device under Linux. [dsd: fixed handling of return value, and added LIBUSB_ERROR_BUSY case]
* Linux: handle low-level transfer errorsDaniel Drake2008-11-021-11/+40
| | | | Handle more URB error status codes, thanks to Lou and Alan Stern.
* Linux: fix sysfs directory handlingDaniel Drake2008-07-161-3/+9
| | | | | The length of the directory name varies, e.g. when you have nested hubs. Use dynamic allocation to be able to deal with any length of name.
* Linux: correct usage of MAX_PATHDavid Engraf2008-07-161-6/+6
| | | | | Thanks to clarification from Artem Egorkine, MAX_PATH already includes space for the trailing NULL.
* Linux: fix bulk/iso transfer double-cancellationDaniel Drake2008-07-081-0/+4
| | | | | | Reset counters to 0 so that it's possible to cancel a transfer twice without breaking things. Not sure that I want to support this properly, but this makes it work at least.
* Linux: Compatibility with new sysfs descriptors fileDaniel Drake2008-06-281-81/+156
| | | | | As of 2.6.26, the descriptors file now includes all descriptors, not just the active one.
* Introduce contexts to the APIDaniel Drake2008-06-261-105/+151
| | | | | Suggested by David Zeuthen. This allows multiple libraries in the same process to independently use libusb without interfering.
* Overflow handlingDaniel Drake2008-06-201-1/+12
|
* a fix for SIGSEGV in handle_bulk_completion()Artem Egorkine2008-06-171-1/+1
| | | | | | We cannot dereference tpriv after calling usbi_handle_transfer_cancellation() because that function may invoke the user-supplied callback which may free the transfer.
* Refine libusb_set_configuration() semanticsDaniel Drake2008-05-291-0/+15
| | | | | | | | | | | | | Applications will generally want to set a configuration before claiming interfaces. The problem is that the interface may already be set, and someone else may have claimed an interface (meaning that all calls to set_configuration will fail, even if it's for the same configuration). There are now 2 options: 1. Use the new libusb_get_configuration() to determine active configuration before calling libusb_set_configuration() 2. Or just call libusb_set_configuration() as usual, which will do nothing if that configuration is already active.
* Linux: fix handling of ioctl failureDavid Engraf2008-05-191-14/+16
| | | | | | The return value of some ioctl commands in linux_usbfs.c are not handeled correct. The ioctl function returns != 0 and errno is set with the error code.
* Fix endianness with descriptor handlingDaniel Drake2008-05-161-10/+16
| | | | | Alan Stern pointed out that usbfs gives host-endian data, but sysfs gives bus-endian.
* Linux: fix caching of guessed configurationDaniel Drake2008-05-121-5/+11
| | | | Reported and tested by Xiaofan Chen
* Linux: fix bulk transfer early completionRob Walker2008-05-111-7/+42
| | | | | | | We were forgetting about the remaining urbs when a non-final urb completed early. [dsd: some touchups and a warning message for a corner case that we don't handle]
* Handle hot-unpluggingDaniel Drake2008-05-111-26/+101
| | | | | This involved moving from select() to poll() because there is no way to distinguish usbfs's POLLERR condition with select().
* Support unconfigured devicesDaniel Drake2008-05-101-15/+52
|
* Linux: fix caching of active configuration for non-sysfsDaniel Drake2008-05-101-3/+9
|
* Fetch configurations by index (not value)Daniel Drake2008-05-101-45/+11
| | | | Otherwise there is no way to know which values to look for.
* Linux: comprehensive sysfs vs usbfs accessDaniel Drake2008-05-101-102/+210
| | | | Be more flexible when certain parts of sysfs are not available.
* Linux: no need to store usbfs node pathDaniel Drake2008-05-091-19/+15
| | | | This can be computed from bus number and device address
* Rework configuration handlingDaniel Drake2008-05-091-53/+316
| | | | | | libusb no longer caches descriptors in libusb_device but backends are intended to be able to provide copies from memory. In the common linux case we can use sysfs.
* Linux: fix clear_halt implementationDaniel Drake2008-05-081-1/+2
| | | | | The ioctl expects an integer. Bug found with the assistance of Soumen Mondal
* Linux: enumerate devices and descriptors from sysfsDaniel Drake2008-05-051-22/+134
| | | | | | Suggested by Alan Stern. This avoids waking up any suspended USB devices. sysfs is not available on all systems, so the usbfs mechanism is still in place as a fallback.
* more error code sanitizationDaniel Drake2008-05-051-6/+6
|
* move descriptor parsing into main libraryDaniel Drake2008-05-051-100/+101
| | | | | OS modules now provide functionality for fetching device/config descriptors
* Detect endpoint halts and unsupported control requestsDaniel Drake2008-05-051-6/+19
|
* Linux: fix logical URB allocationDaniel Drake2008-05-051-2/+8
| | | | | We were allocating the wrong number of URBs for transfers of size multiples of 16k.
* add functionality for querying and detaching kernel driverDaniel Drake2008-05-041-0/+48
|
* implement libusb_reset_device()Daniel Drake2008-05-041-0/+16
|
* Add functionality to clear endpoint halt conditionsDaniel Drake2008-05-041-0/+17
|
* Well-defined error codes for some operationsDaniel Drake2008-05-031-4/+11
| | | | | Also renamed set_interface_altsetting to set_interface_alt_setting for better consistency
* Add libusb_set_configuration()Daniel Drake2008-05-031-0/+17
|
* rename LIBUSB_ERROR_NOMEM to LIBUSB_ERROR_NO_MEMDaniel Drake2008-05-031-4/+4
| | | | improves consistency
* Linux: better EACCES handlingDaniel Drake2008-05-031-2/+10
|
* Rename reference counting APIDaniel Drake2008-05-031-1/+1
| | | | This improves consistency with the naming style of other functions
* Linux: use read-only access to enumerate devices and descriptorsDaniel Drake2008-05-031-2/+2
| | | | | Write access is not needed until later. Also fix handling of open() error code.
* detect short descriptor readsDaniel Drake2008-05-021-1/+5
|