summaryrefslogtreecommitdiff
path: root/libusb/descriptor.c
Commit message (Collapse)AuthorAgeFilesLines
* core: re-add one more conditionalNathan Hjelm2016-03-061-3/+5
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* core: revert some of prior patchNathan Hjelm2016-03-061-16/+20
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* free can handle NULL ptr.Gaurav2016-03-061-28/+18
| | | | | | | | free(NULL) is no operation. Contributed by @ya1gaurav. Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Misc: Prefix doxygen references in order to namespace libusbChris Dickens2016-02-241-17/+17
| | | | | | | | | | | This change add "libusb_" to every group and page definition (and updates all references accordingly) so that generated man pages are namespaced for libusb, thus avoiding possible conflict with other packages. Closes #131 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Misc: Make API parameter names consistent and sensibleChris Dickens2016-02-241-12/+12
| | | | | | | | | | | Prior to this commit, API functions taking a libusb_device_handle argument had the parameter named dev, handle, or dev_handle. This commit changes the name of all libusb_device_handle parameters to dev_handle in both the documentation and actual code. Closes #132 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Miscellaneous fixesTobias Klauser2015-09-201-9/+3
| | | | | | | | | | | | | * Use UNUSED macro instead of open coding it * Use calloc to allocate and zero out buffers where appropriate * Make unnecessarily global variables static * Use strdup() instead of open-coding it * Use passed fd in set_fd_cloexec_nb() * Remove unused parameter from linux_device_disconnected() * Closes #65 Signed-off-by: Tobias Klauser <tklauser@distanz.ch> Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Misc: Remove unnecessary \n from log messagesMatthias Bolte2015-04-281-1/+1
| | | | | | | | | | | The final end-of-line marker is added in usbi_log_v() using the USBI_LOG_LINE_END define. Also don't mix hardcoded \n and USBI_LOG_LINE_END in usbi_log_v(). Closes #59 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* core: Make use of headers consistent across all filesChris Dickens2014-09-061-0/+2
| | | | | | | | * Include config.h before anything else in all files * Remove unnecessary inclusion of libusb.h * Use angle brackets for system headers and quotes for local headers Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Misc: Revert all references to libusb/libusb.infohjelmn@cs.unm.edu2014-01-081-2/+2
|
* Core: defensive programmingSean McBride2013-08-021-2/+4
| | | | | | | | | | | | | | Defensively set return-by-reference value to -1 in error condition NB: The comments do not match the implementation. Comments: "[return] the index of the configuration matching a specific bConfigurationValue in the idx output parameter, or -1 if the config was not found" There is a code path where idx is never touched. Perhaps clients of the function are careful to only read idx if the return value is success, but also setting idx to -1 is much safer.
* Doc: update hotplug, topology and descriptor documentationPete Batard2013-07-041-0/+3
| | | | | * Also fix some typos * Closes #95
* libusb_get_bos_descriptor: Don't log an error on devices without a BOSHans de Goede2013-06-141-1/+2
| | | | | | | 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>
* Windows: Fix broken WDK compilationPete Batard2013-05-301-4/+4
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* Add BOS descriptor supportHans de Goede2013-05-301-0/+323
| | | | | | | 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-301-2/+86
| | | | | | | 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>
* descriptor.c: AlternateSettings are related by InterfaceNumberHans de Goede2013-05-301-1/+5
| | | | | | | | 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>
* all: ensure host_endian is always initializedHans de Goede2013-05-241-1/+1
| | | | | | | | | | | 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-241-2/+12
| | | | | | | | | | | | 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-241-67/+43
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* descriptor.c: Consequently check bDescriptorType and bLength everywhereHans de Goede2013-05-241-57/+85
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* descriptor.c: Read a full config-desc-header on first config-desc readHans de Goede2013-05-241-5/+23
| | | | | | | | | | | | For some reason the first get config call to determine the total-length was only reading 8 of the 9 bytes of a full config-desc-header, which is weird. The Linux kernel reads the full 9 on the first call, so lets do that in libusb too. Note that for backends which cache the config this does not matter. Also check that we've actually gotten back a full header, before parsing it. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* all: Make usbi_os_backend.get_[active_]config_descriptor return lenHans de Goede2013-05-241-5/+3
| | | | | | | | | | | | | | | | | | | | Since commit 5e479f1821d3294fb1cc70c5867c69eca2551de7: "Core: Avoid short read failures on broken descriptors" usbi_os_backend.get_[active_]config_descriptor no longer return on error (under Linux) when returning less bytes then requested. But libusb_get_[active_]config_descriptor still not only requests wTotalLength bytes, but also blindly assumes that on success it has gotten wTotalLength bytes. This patch fixes this, it changes all usbi_os_backend.get_*config_descriptor implementations to return the actual length on success and uses this value as the descriptor size in parse_configuration(). Note that the linux and wince backends were already returning the actual length and thus are not touched. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* Add some editor meta-comments for proper tab usageNathan Hjelm2013-05-151-0/+1
| | | | Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* Core: Cache device descriptors in the coreNathan Hjelm2013-05-151-15/+21
| | | | | | | | | | | | | | Discussion: It is necessary to cache the device descriptor in the core to support reading the descriptors after a device is disconnected. We could either 1) allow each backend to handle this caching (which would most certainly duplicate code), or 2) cache the descritors when a device is added. This patch does the later. Further discussion: It might be beneficial to cache more than just the device descriptors in the core. It might also be worthwhile caching the configuration and BOS descriptors as well. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* Core: Filter out 8-bit characters in libusb_get_string_descriptor_asciiРоман Донченко2013-01-071-1/+1
| | | | * Closes #68
* Core: Avoid short read failures on broken descriptorsPeter Stuge2012-11-251-0/+14
| | | | * See http://marc.info/?t=135132844600001&r=1&w=2
* Core: Fix Clang warningsPete Batard2012-06-131-1/+3
| | | | | | | | | | | | | | | core.c: * Result of 'malloc' is converted to a pointer of type 'struct libusb_device *', which is incompatible with sizeof operand type 'void *' * Memory is never released; potential leak of memory pointed to by 'devs' * Assigned value is garbage or undefined (due to potentially empty and uninitialized device list) descriptor.c: * Function call argument is an uninitialized value io.c: * Call to 'malloc' has an allocation size of 0 bytes * Branch condition evaluates to a garbage value (due to get_next_timeout returning a negative error code instead of zero on error)
* All: Prevent memory leaks on realloc failuresPete Batard2012-06-081-1/+1
| | | | | | | | * p = realloc(p, new_size) does not free the original buffer in case of a realloc failure. * reallocf() can be used to do so, but is not available on all platforms. * This patch introduces usbi_reallocf() in libusbi.h and use that instead of realloc * Issue and original patch submitted by Moritz Lipp (trac #27)
* Misc: Rebrand to libusbxPete Batard2012-04-031-4/+3
| | | | | * Mentions of 'libusb' in doxygen are changed to 'libusbx' * Also update copyright notices and remove unneeded EOF LFs
* descriptor.c: Use size_t for minor 64 bit compliance improvementSean McBride2011-10-171-2/+2
| | | | Fixes #121.
* descriptor.c: Fix buffer read overflow caught by valgrindVitali Lovich2011-07-241-5/+7
| | | | | | | | In parse_interface() an unexpected descriptor would be parsed without validating the descriptor's length. It is possible for size to be 0 at this point, which means that the parsing would read past the end of the source buffer. Fix #83 by checking the length of the remaining buffer before parsing.
* Disallow libusb_get_string_descriptor_ascii() with index 0Konrad Rzepecki2010-11-221-4/+11
| | | | | | String descriptor 0 is the list of supported language IDs in the device, which can't have an ASCII representation. Calling the function with index 0 is thus not really useful. Fixes #43.
* Use const for the usbi_parse_descriptor() format stringLudovic Rousseau2010-11-221-3/+3
| | | | | Constant strings should be "const char *" instead of "char *". Silence "discards qualifiers from pointer target type" warnings. Fixes #61.
* Introduced calling convention (for Windows)Pete Batard2010-08-231-6/+6
| | | | | | | | | | | | | | | | | | Under Windows, a variety of compilers and configurations are available, meaning that the manner of parameter passing (e.g. registers vs stack) can vary. Match the Windows API calling convention and document this appropriately. This calling convention will be used regardless of the configuration of the user's development platform. The only user-level complication is that all functions used as libusb callbacks must use the same calling convention as libusb. The LIBUSB_CALL macro is provided to make this easy. Signed-off-by: Michael Plante <michael.plante@gmail.com> Signed-off-by: Pete Batard <pbatard@gmail.com> [dsd: slight change of strategy, add documentation]
* Switched to standard int pointer type for windows 64-bit compatPete Batard2010-06-031-1/+2
| | | | | | | | On 64-bit Windows a pointer is 64 bit, but long is still 32 bit for backwards compatibility. uintptr_t nicely hides this difference and also works on Linux. [dsd: add appropriate include]
* Rename all interface parameters to usb_interface or interface_numberPete Batard2010-05-181-21/+21
| | | | | | | | | | Remove the use of the ambiguous "interface" where possible without breaking the API. 'interface' is a preprocessor #define already associated with COM on Windows, that can cause a conflict as soon as windows.h is included. There are a few more places where interface is still used, which should be changed for libusb-2.0
* Stricter types and castsPete Batard2010-05-171-4/+5
|
* Linux: fix config descriptor parsing on big-endian systemsDaniel Drake2009-06-101-0/+1
| | | | | | | 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.
* Fix memory leak in config descriptor parsingDaniel Drake2009-05-261-0/+2
| | | | Pointed out by Martin Koegler.
* Fix endianness in device descriptorsDaniel Drake2009-02-161-5/+5
| | | | Pointed out by Nathan Hjelm.
* Fix double free in descriptor parsing error pathDaniel Drake2008-12-091-0/+1
| | | | Pointed out by Shannon Chuang.
* Introduce contexts to the APIDaniel Drake2008-06-261-22/+28
| | | | | Suggested by David Zeuthen. This allows multiple libraries in the same process to independently use libusb without interfering.
* Fix endianness with descriptor handlingDaniel Drake2008-05-161-43/+51
| | | | | Alan Stern pointed out that usbfs gives host-endian data, but sysfs gives bus-endian.
* Support unconfigured devicesDaniel Drake2008-05-101-44/+59
|
* Linux: fix caching of active configuration for non-sysfsDaniel Drake2008-05-101-18/+30
|
* Fetch configurations by index (not value)Daniel Drake2008-05-101-9/+56
| | | | Otherwise there is no way to know which values to look for.
* Rework configuration handlingDaniel Drake2008-05-091-17/+136
| | | | | | 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.
* Documentation workDaniel Drake2008-05-081-0/+3
| | | | Partially based on some libusb-devel discussions
* documentation touchupsDaniel Drake2008-05-051-8/+8
|
* more error code sanitizationDaniel Drake2008-05-051-11/+11
|