summaryrefslogtreecommitdiff
path: root/libusb/os/windows_winusb.h
Commit message (Collapse)AuthorAgeFilesLines
* windows: Add GetPipePolicy to struct winusb_interfaceMartin Ling2023-01-201-0/+8
|
* windows: Use sdk-defined GUIDs where possibleShawn Hoffman2022-06-261-8/+4
| | | | Closes #1115
* core: update usbi_dbg to take the context as an argumentNathan Hjelm2021-07-211-1/+1
| | | | | | | | | | | | | 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>
* Windows: Break dependency on OLE32Chris Dickens2020-12-191-5/+1
| | | | | | | | | The OLE32 library provides the IIDFromString() function to parse a string to a GUID, but we can implement a simple GUID parsing function and remove this dependence. Doing so also avoids fetching the Unicode form of the "DeviceInterfaceGUIDs" property. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Cleanup header includes and definiionsChris Dickens2020-12-191-42/+19
| | | | | | | | | | Now that a sufficiently recent toolchain is required to build, we can drop a bunch of redundant definitions and get the definitions from the Windows headers instead. We can also remove a number of '#ifndef' guards because no header included by the source would have defined the symbols being protected. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Improve how root hubs are reportedChris Dickens2020-08-171-5/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | Microsoft provides very little information about the actual root hub characterstics beyond the number of ports. Determining the maximum supported speed of the root hub is not directly possible but instead requires that a device matching the highest speed of the root hub is connected. Additionally, Windows 8 or later is required for _any_ successful detection of SuperSpeed devices. One other inconvenience is that there are no descriptors exposed for root hubs. This does not fit well with the structure of the library because root hubs are considered first-class devices. This change addresses some of these shortcomings. Each root hub is now given a configuration descriptor that is matched to the fastest speed detected for the root hub. The information is most accurate on Windows 8 or later, but the best information possible is constructed on earlier versions. The device descriptor is also adjusted accordingly based on the detected speed. This solution is not perfect but is better than the status quo. Closes #688 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* core: Narrow the types passed to certain backend functionsChris Dickens2020-04-281-4/+4
| | | | | | | | | Backend functions dealing with interfaces and alternate settings should use a type whose range represents that of valid values for interfaces and alternate settings. Switch to use uint8_t instead of int so that backends do not have to cast values or do range checks. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* core: Kill backend get_device_descriptor() functionChris Dickens2020-04-281-2/+2
| | | | | | | | | | | | | | | | | Simplify the library by moving device descriptor initialization to the backend, while the device is being set up. This removes the duplication of essentially the same code in every backend. Add some missing calls to libusb_le16_to_cpu() when reading multi-byte fields from the "raw" device descriptor. It has worked thus far because the platforms not using the calls happen to be the same endianness as the USB bus. While here, throw in some static assertions to ensure there is no mismatch between the libusb device descriptor structure and any device descriptor structure provided by the platform headers. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* core: Fix some minor inconsistencies in API and codingChris Dickens2020-04-271-1/+1
| | | | | | | | | | | | | | | | | | | | | All of the API functions should take the typedef'ed versions of the opaque libusb structures, but some recent additions to the API did not follow this convention. Fix this by making the changes to the declarations and definitions of the functions. Make the placement of the asterisk in pointer variable declarations consistent (always with the variable name, not the type). Remove some unnecessary casts and initializations relating to dynamically allocated memory. While at it, make casts within the core library consistent in style with no space after the closing parenthesis of the cast. Most of the core already used this style. When using the 'sizeof' operator, dereference the pointer instead of using the type. Most of the core was already doing this, so fix up the few places that weren't. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* core: Move parameter validation from backend to coreChris Dickens2020-03-161-2/+2
| | | | | | | | | | | | | | Some functions (e.g. libusb_set_interface_alt_setting()) do not perform sufficient parameter validation, leaving the burden on the backend to catch invalid user input. Much of this validation is common across all backends, yet not every backend implemented it. Fix this by moving parameter validation to the core library functions. This is also a good opportunity to remove the redundant 'num_configurations' field from the libusb_device structure. The value of this field is already contained in the 'device_descriptor' member. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Fix some harmless build warningsChris Dickens2020-03-091-1/+0
| | | | Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* core: Introduce accessor functions for structure private dataChris Dickens2020-02-261-27/+16
| | | | | | | | | | | | | | | | | | | | | The backend private data for the internal library structures has been accessed through a zero-length os_priv array of type unsigned char. This approach had two particular disadvantages: 1) A special attribute was needed on the 'os_priv' member to ensure that the field was properly aligned to a natural pointer alignment. The support needed for this is not available in every compiler. 2) Each access to the private data areas required an explicit cast from unsigned char to the type required by the backend. This change reworks the way the private data is accessed by the backends. New accessor functions return the private data as a void pointer type, removing the need for an explicit cast (except for Haiku, which is C++). The special alignment attribute trickery is also replaced by simple pointer arithmetic. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: fix MAX_PATH_LENGTHa1exdandy2020-02-221-1/+1
| | | | | | | | | | | | The MAX_PATH_LENGTH in libusb Windows backend is used as size of dev_id buffer. This buffer used for retreiving Device Instance Id by SetupDiGetDeviceInstanceIdA function. Acording to Microsoft, Device Instance Id must be less than MAX_DEVICE_ID_LEN = 200. So, value of 128 maybe not enough. Closes #699 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Refactoring to consolidate and simplify common codeChris Dickens2020-02-071-78/+80
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Both the UsbDk and WinUSB backends perform common steps when handling transfers in order to interact with the poll abstraction, both during submission and when processing transfer completion. With some rearranging of shared structures, this can be yanked from the individual backends and placed in the common area. This allows for several functions to be removed outright from each backend. The cancellation logic can also be simplified by attempting CancelIoEx() at the highest level and delegating to the backend if there are alternatives to try should CancelIoEx() fail. After some analysis of how Windows processes asychronous (OVERLAPPED) requests that the underlying driver completes synchronously, it is now evident that such requests need not be handled in any special fashion. Each function that called a driver function that was expected to complete asynchronously had logic to handle the case of a synchronous completion, so this has all been killed off. This significantly cleans up these call sites as now they must only check for an error condition. Finally, the initialization code for the WinUSB backend has been reworked to load the WinUSB DLL independent of the libusbK DLL. Previously when the libusbK DLL was present, all requests to devices using WinUSB would first be sent through the libusbK DLL where they would then be forwarded to the WinUSB DLL. This is slightly inefficient but is also limiting when using Windows 8.1 or later because support for isochronous transfers through WinUSB will be lost. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* core: Convert internal macros to static inline functionsChris Dickens2020-01-251-4/+0
| | | | | | | | | | | | Older versions of the Visual Studio compiler are picky about macros constructed with the 'do { ... } while (0)' construct. Convert these internal ones to static inline functions. The result is functionally equivalent but gets us type checking and a bit more readability. Also address some compiler warnings due to some header files that are being included in a different order than before. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Remove support for WinCE and Visual Studio older than 2013Chris Dickens2020-01-201-2/+4
| | | | | | | | | | | There appears to be no need for the WinCE backend anymore, and it is increasingly difficult to keep healthy as the rest of the library changes. Require at least Visual Studio 2013 to compile. This simplifies matters as there is some semblance of C99 support there. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* windows_winusb: Add support for reporting super speed plus devicesHarry Mallon2019-08-091-1/+3
| | | | | | Closes #531 Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* windows_winusb: Set policy ISO_ALWAYS_START_ASAP for libusbKLéo Lam2019-07-071-0/+3
| | | | | | | | | | | | | | | | | In some cases, this is required to avoid eventually getting a USBD_STATUS_BAD_START_FRAME error back from the Windows USB stack. This makes the libusbK code match the behaviour of the Linux backend. It appears that the libusbK backend tried to get this behaviour by setting StartFrame to 0. However, libusbK docs state that: "Specifing 0 for KISO_CONTEXT::StartFrame (start transfer ASAP) is restricted to the first transaction on a newly opened or reset pipe." Closes #569 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Add support for isochronous transfers with WinUSB.philemonf2019-04-051-0/+63
| | | | | | Closes #284 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Windows: WinUSB: Do not assume that driver implements CancelIoEx()Chris Dickens2018-03-121-0/+1
| | | | | | | | | | | Cancelling an individual OVERLAPPED I/O operation is something that a driver can optionally implement. It appears that the native WinUSB driver supports this but libusbK does not. Therefore we will attempt to use it and fall back to the AbortPipe() call if an error occurs. Closes #400 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Check composite interfaces before calling functionsChris Dickens2018-01-271-2/+9
| | | | | | | | | | | Commit c4438b3c introduced a regression by failing to check for the presence of a function in the backend when called on a composite device. Fix this by introducing a new helper macro and checking for function pointers at all necessary locations. Closes #383 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Added isochronous support via libusbkJoshua Blake2018-01-081-0/+42
| | | | | | | | [dickens] Rebased against latest changes and fixed some styling issues Closes #246 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Enable dynamic selection between WinUSB and UsbDk backendsChris Dickens2018-01-081-57/+8
| | | | | | | | | | | | | This commit unifies the two Windows backends into a single project and enables the user to switch to the UsbDk backend, if available, using the libusb_set_option() function. All contexts will use the WinUSB backend by default for backwards compatibility. With this change, the UsbDk-specific projects are no longer required. Closes #309 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Rework poll() emulation to a much simpler and effective designChris Dickens2018-01-061-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous poll() implementation worked okay but had some issues. It was inefficient, had a large footprint, and there were simply some use cases that didn't work (e.g. a synchronous transfer that completes when no other event or transfer is pending would not be processed until the next poll() timeout). This commit introduces a new, simpler design that simply associates an OVERLAPPED structure to an integer that acts as a file descriptor. The poll() emulation now solely cares about the OVERLAPPED structure, not transfers or HANDLEs or cancelation functions. These details have been moved up into the higher OS-specific layers. For Windows NT environments, several deficiencies have been addressed: 1) It was previously possible to successfully submit a transfer but fail to add the "file descriptor" to the pollfd set. This was silently ignored and would result in the user never seeing the transfer being completed. 2) Synchronously completed transfers would previously not be processed unless another event (such as a timeout or other transfer completion) was processed. 3) Canceling any one transfer on an endpoint would previously result in *all* transfers on that endpoint being canceled, due to the use of the AbortPipe() function. This commit addresses all of these issues. In particular, run-time detection of the CancelIoEx() function will allow the user to cancel a single outstanding transfer without affecting any others still in process. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Rework WinUSB enumeration process to fix issues on Win8+Chris Dickens2018-01-041-6/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As they sometimes do, Microsoft made changes to the way in which the SetupAPI functions list the devices returned by SetupDiGetClassDevs(). In particular, composite devices started returning their interfaces before the parent device, which caused some issues with the way the enumeration logic was assigning things. For composite devices, it appears that the first interface behaves much like the parent device in some regards, so the library was creating a device specifically for the first interface and then again when the actual parent device was encountered. This caused composite devices to appear in the device list twice, with the first instance being unusable for most operations. This commit significantly changes the way in which the enumeration process is done. Previously we would scan for HCDs, hubs, and generic devices, in that order and in distinct passes (obtaining a new listing of devices from SetupAPI). Now we will obtain a single snapshot at the beginning of the enumeration process and iterate through this to scan for each type of device. With a single snapshot, we can be assured that the device instance handle will not change between passes and thus we can use this as the unique identifier. This completely removes the need to hash the device instance ID to obtain a unique identifier and simplifies the process. The previous enumeration process also created "dummy" libusb_device instances for the HCDs that were never exposed to the user. This has been removed in favor of identifying which of the encountered hubs are actually root hubs. Finally, the query for the port number has been moved to the GENeric pass at the point where the devices are actually initialized. This query operation has been relaxed to allow failure, since some virtual USB devices don't properly implement this query in their drivers. Closes #215, Closes #251, Closes #257, Closes #288 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Remove port member from device's private structureChris Dickens2018-01-041-1/+0
| | | | | | | The libusb_device structure already has a port_number member that stores the same information, so don't duplicate this elsewhere. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Constify variables that aren't supposed to changeChris Dickens2018-01-031-2/+2
| | | | Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Kill empty functions and switch to runtime checkingChris Dickens2018-01-031-6/+4
| | | | | | | | | | | | Instead of requiring each driver API to provide a complete set of functions, some of which may be simple containers for returning an unsupported error code, allow function pointers to be NULL and return an error when a NULL pointer is encountered. Also remove the unused sub_api parameter from the API init/exit functions. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Remove unused DLL functions and header definitionsChris Dickens2018-01-031-89/+4
| | | | Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Fix some minor style issuesChris Dickens2018-01-031-63/+53
| | | | Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Improve enumeration processChris Dickens2018-01-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Prior to this commit, there were some limitations and inefficiencies during the enmeration process. First, the maximum number of device interface GUIDs that could be enumerated was fixed at 64. This limit has been removed and the list of GUIDs is dynamically resized as new ones are encountered. Logic has also been added to detect the presence of duplicate GUIDs in order to speed up the enumeration process. Next, when searching for device interface GUIDs, only the "DeviceInterfaceGUIDs" registry key was being consulted. Now we will also consider "DeviceInterfaceGUID" in order to support devices that have the GUID listed under this key (such as some WCID devices). Finally, there used to be a static list of USB PnP enumerator strings that were used to detect devices during the GENeric enumeration pass. In many cases, this is wasteful as these enumerators are only present with very specific hardware. To improve this, we now keep track of the USB PnP enumerator string encountered as we enumerate the hubs. This allows the enumeration process to only search for devices that could possibly be present on the system given the hardware and drivers that were encountered. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Report correct usagePage and usage values for HIDchunyu.xie2017-12-221-0/+2
| | | | | | Closes #278, Closes #281 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Fix libusb_get_string_descriptor for HID deviceschunyu.xie2017-12-221-1/+2
| | | | | | | | | When querying vendor-defined string descriptors, use GetIndexedString of the HID library. Closes #279, Closes #280 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Header file cleanupChris Dickens2017-06-051-182/+48
| | | | | | | | | | This commit removes unused or redundant definitions from the windows_winusb.h header file and leverages existing definitions within the core library headers. The definitions of structures related to the Windows API are also modified to match official headers. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Fix regression introduced by 05b0b55bChris Dickens2017-05-111-2/+4
| | | | | | Closes #298, Closes #300 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Fix possible memory leak when caching descriptors failsChris Dickens2017-03-261-4/+2
| | | | Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Clean up unnecessary variable initializationChris Dickens2017-01-121-11/+0
| | | | | | | Don't zero out variables that already are zero (calloc'ed) and don't set variables that aren't read before being set again. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows/WinCE: Remove uses of safe_* macros where not usefulChris Dickens2017-01-121-6/+6
| | | | Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Fix possible false error message during device enumerationv1.0.21-rc6Chris Dickens2016-10-011-2/+0
| | | | | | | | | | | | | | | During early phases of enumeration, it is possible for a device to be enumerated before its parent. When this occurs, the device assigned as the parent will actually be a grandparent. During later phases of enumeration, the parent device will in fact exist but will not match what has already been assigned to the device. This commit adds code to check for and update the parent device when this situation occurs. Closes #206 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Fix false assertion failure message during enumerationChris Dickens2016-05-291-1/+3
| | | | | | | | | | | | Commit 1d54ee1b6687c532eca75925f56eb12e2a34ce42 addressed a device reference leak but introduced a false warning message that occurs for devices detected in early enumeration passes (e.g. hubs). The assertion is meant to warn of a mismatch between parent devices but fails to account for the fact that some devices that are allocated early do not have a parent device assigned until the later enumeration passes. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Fix MinGW buildChris Dickens2016-03-031-5/+0
| | | | | | | | The integration of UsbDk moved the windows_error_str() function to windows_nt_common.c, but the definition of FACILITY_SETUPAPI (which MinGW headers do not provide) did not follow the move. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Move definitions for Cygwin.KIMURA Masaru2016-01-281-8/+0
| | | | | | Closes #145 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows/WinCE: Improve the run-time dynamic linking schemeChris Dickens2016-01-281-32/+41
| | | | | | | | | | | | | | | Prior to this commit, the Windows and WinCE backends had a specific shortcoming when loading DLLs, that being that once loaded they were never unloaded. This commit improves this by providing a means to unload the DLLs during cleanup. Note that the use of GetModuleHandle() has been removed in favor of the exclusive use of LoadLibrary(). This was done to ensure that a reference count is taken against the loaded DLL, which guards against some other part of the application unloading the DLL that libusb is currently using. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Source file cleanupChris Dickens2016-01-261-250/+255
| | | | | | | | | | | | This commit addresses a few different issues: 1) Whitespace made consistent with the rest of the library source 2) Formatting of function and variable declarations made consistent with the rest of the library source 3) Functions and variables made static where possible 4) Definitions in header files moved if not used publicly Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* windows: Rename windows_usb.h/c windows_winusb.h/cDmitry Fleytman2016-01-231-0/+947
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com> Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>