summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
...
* windows: Fix build with --disable-logRosen Penev2022-09-042-5/+5
| | | | | | | | | | | | On Windows we use UNREFERENCED_PARAMETER for UNUSED (commit 521105f). UNREFERENCED_PARAMETER evaluates to {(ctx) = (ctx);} which errors out: error: lvalue required as left operand of assignment. in the cases where ctx is NULL. Closes #1152 [Tormod: Add ctx reference to avoid unused variable warnings] Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* windows: Mark libusb_set_option as WINAPIVRosen Penev2022-09-044-3/+6
| | | | | | | | | | | WINAPI evaluates to __stdcall, which does not work with variadic functions. MSVC and MinGW implicitly demote this to __cdecl (clang does too and also warns about it). Instead of having this implicit, make it explicit. Closes #1160 Signed-off-by: Rosen Penev <rosenp@gmail.com>
* windows: Avoid invalid dereference in debug printTormod Volden2022-09-032-3/+3
| | | | | | | | | The device structure is not always valid at this point. Fixes #1179 Closes #1186 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* core: Avoid mutex lock while printing error and warningTormod Volden2022-09-032-4/+6
| | | | | | | Closes #1187 Reviewed-by: Dmitry Zakablukov <dimaz@passware.com> Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* Fix possible memory leak of configuration descriptor (Darwin/Windows)Ihor Dutchak2022-09-033-5/+10
| | | | | | | | | | | | | | The config descriptor was not released in some (rare) cases: - Darwin: never released in case GetPipeProperties failed - Windows: not released for some non-USB compliant descriptors Follow-up of commit f5275f9a and commit aa1d76cd References #1093 References #1039 Closes #1183 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* Add Emscripten backend for WebAssembly + WebUSB supportIngvar Stepanyan2022-06-267-3/+705
| | | | | Fixes #501 Closes #1057
* windows: Correct function name in commentTormod Volden2022-06-262-2/+2
| | | | Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* windows: Use sdk-defined GUIDs where possibleShawn Hoffman2022-06-262-9/+5
| | | | Closes #1115
* msvc: Correct usage comments about linkingShawn Hoffman2022-06-262-8/+5
| | | | Closes #1114
* msvc: Implement LIBUSB_DEPRECATED_FORShawn Hoffman2022-06-262-1/+3
| | | | Closes #1113
* windows: Whitespace fixShawn Hoffman2022-06-262-2/+2
| | | | Closes #1111
* msvc: Rework msbuild filesShawn Hoffman2022-06-26122-6937/+657
| | | | | | | | | | | Refactor common settings into .props files. Enables building full PlatformToolset, Platform, Configuration matrix easily. Also update the appveyor file. Technically we no longer need different images (could just have a single vs2022 image which is executed multiple times in parallel, or so) Closes #1116
* core: Remove select case not possibly reachedTormod Volden2022-06-262-2/+1
| | | | | | References #1067 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* configure.ac: Link with -latomic only if no atomic builtinsLonnie Abelbeck2022-06-262-2/+16
| | | | | | | | | | | | Follow-up to 561dbda, a check of GCC atomic builtins needs to be done first. I'm no autoconf guru, but using this: https://github.com/mesa3d/mesa/blob/0df485c285b73c34ba9062f0c27e55c3c702930d/configure.ac#L469 as inspiration, I created a pre-check before calling AC_SEARCH_LIBS(...) Fixes #1135 Closes #1139
* Doxygen: Improve libusb_wrap_sys_device() documentationLudovic Rousseau2022-06-262-5/+6
| | | | | | Create links to: - libusb_set_option() - LIBUSB_OPTION_NO_DEVICE_DISCOVERY
* Doxygen: Add references to LIBUSB_ERROR codesLudovic Rousseau2022-06-267-86/+87
| | | | Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
* windows: Add clock_gettime checkRosen Penev2022-06-262-1/+3
| | | | | | | Under MSYS2, the windows usbi_get_monotonic_time interferes with the static inline function under libusbi.h Closes #1151
* examples: Replace most uses of sprintf with safer snprintfSean McBride2022-06-263-6/+6
| | | | Closes #1155
* windows: Pass on returned isochronous packet status on libusbKTormod Volden2022-06-262-3/+2
| | | | | | Closes #1109 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* Simplify clock_gettime() conditionalization and fallback on macOSSean McBride2022-06-265-69/+29
| | | | | | | | | | | | | | Removed the logic in configure.ac (for Darwin only) that detected if the clock_gettime() function exists. Instead, just use the preprocessor to introspect the macOS SDK version and deployment target and call clock_gettime() if they are new enough. Also replaced the fallback code for older macOS with mach_absolute_time() and gettimeofday(), which are simplier because they do not need setup and teardown carefully balanced and their usage is in one place instead of spread in multiple places in the file. Closes #1080
* config: allow configure to continue without pkg-config installedNathan Hjelm2022-04-152-7/+9
| | | | | | | | | libusb only uses pkg-config macros in configure to check for umockdev. Since this is only required for testing it makes sense to protect the usage of these macros to only be used when pkg-config is installed. This will be the case for maintainers and testers. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* darwin: add missing locking around cached device list cleanupNathan Hjelm2022-04-142-64/+77
| | | | | | | | | | | | | | | | | | | The cleanup function darwin_cleanup_devices was intented to be called only once at program exit. When the initialization/finalization code was changed to destroy the cached device list on last exit this function should have been modified to require a lock on darwin_cached_devices_lock. This commit updates cleanup to protect the cached device list with the cached devices mutex and updates darwin_init to print out an error and return if a reference leak is detected. Also using this opportunity to correct the naming of the mutex. Changed darwin_cached_devices_lock to darwin_cached_devices_mutex. Also cleaning the initialization code up a bit. Removing the context pointer from the hotplug thread as it is not used for anything but logging. Fixes #1124 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* Fix `exit` order to match reverse of `init`Craig Hutchinson2022-04-132-2/+4
| | | | | | | | | | This commit resolve the ordering of 'exit' dependencies as was started for 'init' in https://github.com/libusb/libusb/commit/0846456f3a9fda8ff5469d9d0b9700837ff16f04 (Relates to https://github.com/xloem/libusb/pull/5) Closes #1126 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* libusb 1.0.26v1.0.26Tormod Volden2022-04-104-3/+8
| | | | Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* darwin: Document OS-specific behaviour of libusb_cancel_transferMartin Ling2022-04-092-1/+21
| | | | | | | | | | | | | The behaviour of libusb_cancel_transfer is different on Darwin: - Cancellation cancels all transfers on the same endpoint. - A ClearFeature(ENDPOINT_HALT) request is sent after cancellation. This documents both differences and their implications. Fixes #1110 Closes #1121
* darwin: Fix crash in log handler when stopping event threadBenjamin Berg2022-04-092-4/+5
| | | | | | | | | | | | The darwin event thread (in contrast to other OS implementations) tries to log to the context that created it. However, this context is only guaranteed to be valid until the thread has started. It may be that another context is the last one to be destroyed, causing the event thread to log using an already destroyed context. Fix this by only passing on ctx where it is acceptable. Fixes #1108
* windows: Silence zero-sized array warning in libusb.h for msvcShawn Hoffman2022-04-061-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Silence "nonstandard extension used : zero-sized array in struct/union" (C4200) warning caused by use of ZERO_SIZED_ARRAY in structures defined in libusb.h when compiling with msvc. A libusb user including the header from a c++ file is more likely to be annoyed by the warning because it is activated at level 2 as opposed to being included from a C file, where it's not activated until level 4. (on msvc, level 4 is the last step before -Wall). This causes problems when you also enable -Werror for your own source, since the libusb header just gets merged into the compilation unit. 9>hotplugtest.c 9>C:\src\libusb\libusb\libusb.h(786,11): error C2220: the following warning is treated as an error 9>C:\src\libusb\libusb\libusb.h(786,11): error C2220: uint8_t dev_capability_data[ZERO_SIZED_ARRAY]; 9>C:\src\libusb\libusb\libusb.h(786,11): error C2220: ^ 9>C:\src\libusb\libusb\libusb.h(786,11): warning C4200: nonstandard extension used: zero-sized array in struct/union 9>C:\src\libusb\libusb\libusb.h(786,11): warning C4200: uint8_t dev_capability_data[ZERO_SIZED_ARRAY]; 9>C:\src\libusb\libusb\libusb.h(786,11): warning C4200: ^ 9>C:\src\libusb\libusb\libusb.h(811,47): warning C4200: nonstandard extension used: zero-sized array in struct/union 5>C:\src\libusb\libusb\libusb.h(811,47): warning C4200: struct libusb_bos_dev_capability_descriptor *dev_capability[ZERO_SIZED_ARRAY]; 5>C:\src\libusb\libusb\libusb.h(811,47): warning C4200: ^ 9>C:\src\libusb\libusb\libusb.h(1284,38): warning C4200: nonstandard extension used: zero-sized array in struct/union 9>C:\src\libusb\libusb\libusb.h(1284,38): warning C4200: struct libusb_iso_packet_descriptor iso_packet_desc[ZERO_SIZED_ARRAY]; 9>C:\src\libusb\libusb\libusb.h(1284,38): warning C4200: ^ 9>Done building project "hotplugtest.vcxproj" -- FAILED. Closes #1112
* windows: Update isochronous OUT packet actual lengthTormod Volden2022-04-042-2/+11
| | | | | | | | | | | | | | | | | | | On Windows, unlike other platforms, the isochronous packet actual_length value is not set on completion of OUT transfers. However, our API requires the user to check this value for isochronous transfers instead of the transfer actual_length, if the transferred length is of interest. The usbd Length field is not used for isochronous OUT transfers: https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/usb/ns-usb-_usbd_iso_packet_descriptor To make it consistent with other platforms, just return the requested length. Fixes #1105 Closes #1107 Tested-by: Xiaofan Chen <xiaofanc@gmail.com> Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* windows: Fix type mismatch in winusbx_copy_transfer_dataTormod Volden2022-04-042-2/+6
| | | | | | | | | | We cannot use the CHECK_WINUSBX_AVAILABLE macro since it may return with the wrong error type/value. Fixes #1100 Closes #1101 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* CI: Add MinGW build on MSYS2 (Windows)Tormod Volden2022-04-042-1/+22
| | | | | | Closes #1102 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* libusb 1.0.26-rc1v1.0.26-rc1Tormod Volden2022-03-274-3/+21
| | | | Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* darwin: Reset by re-enumerate on non-macOS platformsosy2022-03-252-3/+30
| | | | | | | | On non-macOS platforms, ResetDevice() does nothing so we use the "old" way of calling re-enumerate. If the device is captured, we have to re-enumerate, then re-capture, re-authorize, and finally restore the state. Closes #1088
* darwin: Fix Makefile build on macOS 10.11 and olderTormod Volden2022-03-242-2/+2
| | | | | | | | | | | TARGET_OS_OSX is not defined when building with the clang 8 provided by Xcode 8.2.1 on 10.11.5 (unless the Xcode project is used). If it is not defined we'll just assume we have a "OSX" target. Closes #1097 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* windows: Correct isochronous frame calculation for full-speed devicesSeneral2022-03-212-2/+6
| | | | | | | | | | The WinUSB isochronous transfer implementation always assumed HighSpeed microframes. https://github.com/libusb/libusb/issues/747#issuecomment-649491619 References #747 References #749
* windows: Fix WinUSB isochronous transfer regressionKeith Ahluwalia2022-03-212-1/+4
| | | | | | | | | | | | | | | | Put back missing CHECK_WINUSBX_AVAILABLE macro. The subapi is generally set in the backend functions themselves, using the macro CHECK_WINUSBX_AVAILABLE. However, this macro was (likely inadvertently) removed from winusbx_copy_transfer_data() in commit 9c28ad2 causing the subapi in this function to always be SUB_API_NOTSET. This results in the error: libusb: debug [winusbx_copy_transfer_data] unsupported API call for 'copy_transfer_data' (unrecognized device driver) https://github.com/libusb/libusb/issues/747#issuecomment-649619615 References #749 Closes #1095
* core: Install first context as implicit default (and warn about its use)Benjamin Berg2022-03-204-5/+59
| | | | | | | | | | | | | | | | | There was a behaviour change in libusb 1.0.25 which triggers issues when the API is misused. This caused for instance gutenprint to crash, see https://bugzilla.redhat.com/show_bug.cgi?id=2055504 This seems to affect several applications "out in the wild". For now, work around this by installing an implicit default. But, change the code to log an error in case this "feature" is being used. This will allow some grace time for developers to fix their applications, before we at a later point revert to the stricter behaviour. Fixes #1089
* windows: Fix product string retrieval on HID composite devicesMathias Hjärtström2022-03-202-2/+5
| | | | | | | | | | | | | | | | | | | | | A HID composite device with three interfaces (e.g. keyboard and touch screen built into one), with all three interfaces referencing their own names in the interface descriptor, was reported to have an iProduct string equal to the name of the last interface instead of the actual product name (e.g. "TOUCH" repeated twice instead of "PRODUCT" and "TOUCH"). This behavior differ from what for instance Microsoft USB Device Viewer will report for the same device. This fix will make them report the same thing. Use HidD_GetIndexedString() instead of HidD_GetProductString(), as the latter would otherwise return the name of the interface instead of the iProduct string whenever the iInterface member of the USB_INTERFACE_DESCRIPTOR structure for the interface is nonzero (see Remarks section in the Microsoft documentation of the HID API routines). Closes #1091
* darwin: Always use GetPipePropertiesV3 when availableTormod Volden2022-03-202-10/+34
| | | | | | | | | | | | | | | | | The V3 API goes back to macOS 10.8.2 (2012), and we have already been using it when targeting 10.9 or higher for a while. However in a few places we were still using the older API. Affects get_endpoints() and submit_iso_transfer(). In the latter also: - Check success of pipe properties retrieval. - Remove a duplicate call to GetPipeProperties(). References #919 Closes #1056 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* Add interface bounds checks in darwin and windows endpoint functionsRyan Hileman2022-03-183-1/+9
| | | | | | | | A broken device with invalid interface numbering could cause an out-of-bounds array access. Fixes #1039 Closes #1093
* android: Fix typo and syntax in commentsYegor Yefremov2022-03-182-5/+4
| | | | | | | | | | | Fix a typo and add missing commas. Also, delete a blank line at the end of the file and use /* */ for comments consistently. Closes #1071 Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
* appveyor: Retain MinGW and cygwin build artifactsTormod Volden2022-03-182-1/+5
| | | | Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* windows: Add "or later" to debug print of Windows version 8Tormod Volden2022-03-182-1/+8
| | | | | | | | | | | | Windows 10 and 11 is detected as Windows 8 unless there is an application manifest. We simply cannot tell by appropriate means. Note that we currently only use the detected version to check for the minimal version (Vista), so it doesn't matter much. Closes #1021 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* windows: Discern Windows 11 (if manifest allows)Tormod Volden2022-03-182-2/+5
| | | | | | | | | | Pre-releases of Windows 11 had build numbers from 20000. Thanks to Pete Batard for extensive explanation. Fixes #1021 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* windows: Add Windows 11 to list of defined releasesTormod Volden2022-03-183-4/+6
| | | | | | | And guess "12" for whatever comes after. Although with macOS already at 12 this is not given :) Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* darwin: Avoid cast warnings in time calculationTormod Volden2022-03-182-4/+5
| | | | | | | | Also use the USEC_PER_SEC macro for readability. References #1035 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* Add container build for umockdevBenjamin Berg2022-03-183-1/+74
|
* tests: Add some umockdev based testsBenjamin Berg2022-03-184-2/+1166
| | | | | | | Add some basic umockdev tests. The setup in this case is all in one process, but umockdev in principle could also work between processes. This is just a start, more tests would make sense.
* darwin: Avoid possibly undefined version macro in configure.acTormod Volden2022-03-162-2/+2
| | | | | | References #1056 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* darwin: Use usbi_get_monotonic_time() wrapperAndrew Goodney2022-03-162-3/+3
| | | | | | On macOS < 10.12 we cannot use clock_gettime(). Closes #1070
* windows: Link gcc helpers statically on MinGWTormod Volden2022-03-163-2/+5
| | | | | | Fixes #1049 Signed-off-by: Tormod Volden <debian.tormod@gmail.com>