3 #include "windows_common.h"
7 typedef struct USB_DEVICE_DESCRIPTOR {
12 UCHAR bDeviceSubClass;
13 UCHAR bDeviceProtocol;
14 UCHAR bMaxPacketSize0;
21 UCHAR bNumConfigurations;
22 } USB_DEVICE_DESCRIPTOR, *PUSB_DEVICE_DESCRIPTOR;
24 typedef struct USB_CONFIGURATION_DESCRIPTOR {
26 UCHAR bDescriptorType;
29 UCHAR bConfigurationValue;
33 } USB_CONFIGURATION_DESCRIPTOR, *PUSB_CONFIGURATION_DESCRIPTOR;
37 #define MAX_DEVICE_ID_LEN 200
39 typedef struct USB_DK_DEVICE_ID {
40 WCHAR DeviceID[MAX_DEVICE_ID_LEN];
41 WCHAR InstanceID[MAX_DEVICE_ID_LEN];
42 } USB_DK_DEVICE_ID, *PUSB_DK_DEVICE_ID;
44 typedef struct USB_DK_DEVICE_INFO {
49 USB_DEVICE_DESCRIPTOR DeviceDescriptor;
50 } USB_DK_DEVICE_INFO, *PUSB_DK_DEVICE_INFO;
52 typedef struct USB_DK_ISO_TRANSFER_RESULT {
54 ULONG64 TransferResult;
55 } USB_DK_ISO_TRANSFER_RESULT, *PUSB_DK_ISO_TRANSFER_RESULT;
57 typedef struct USB_DK_GEN_TRANSFER_RESULT {
58 ULONG64 BytesTransferred;
59 ULONG64 UsbdStatus; // USBD_STATUS code
60 } USB_DK_GEN_TRANSFER_RESULT, *PUSB_DK_GEN_TRANSFER_RESULT;
62 typedef struct USB_DK_TRANSFER_RESULT {
63 USB_DK_GEN_TRANSFER_RESULT GenResult;
64 PVOID64 IsochronousResultsArray; // array of USB_DK_ISO_TRANSFER_RESULT
65 } USB_DK_TRANSFER_RESULT, *PUSB_DK_TRANSFER_RESULT;
67 typedef struct USB_DK_TRANSFER_REQUEST {
68 ULONG64 EndpointAddress;
72 ULONG64 IsochronousPacketsArraySize;
73 PVOID64 IsochronousPacketsArray;
74 USB_DK_TRANSFER_RESULT Result;
75 } USB_DK_TRANSFER_REQUEST, *PUSB_DK_TRANSFER_REQUEST;
77 struct usbdk_device_priv {
78 USB_DK_DEVICE_INFO info;
79 PUSB_CONFIGURATION_DESCRIPTOR *config_descriptors;
80 HANDLE redirector_handle;
82 uint8_t active_configuration;
85 struct winusb_device_priv {
88 uint8_t active_config;
89 uint8_t depth; // distance to HCD
90 const struct windows_usb_api_backend *apib;
92 char *path; // device interface path
93 int sub_api; // for WinUSB-like APIs
95 char *path; // each interface needs a device interface path,
96 const struct windows_usb_api_backend *apib; // an API backend (multiple drivers support),
98 int8_t nb_endpoints; // and a set of endpoint addresses (USB_MAXENDPOINTS)
100 bool restricted_functionality; // indicates if the interface functionality is restricted
101 // by Windows (eg. HID keyboards or mice cannot do R/W)
102 } usb_interface[USB_MAXINTERFACES];
103 struct hid_device_priv *hid;
104 USB_DEVICE_DESCRIPTOR dev_descriptor;
105 PUSB_CONFIGURATION_DESCRIPTOR *config_descriptor; // list of pointers to the cached config descriptors
108 struct usbdk_device_handle_priv {
109 // Not currently used
113 struct winusb_device_handle_priv {
114 int active_interface;
116 HANDLE dev_handle; // WinUSB needs an extra handle for the file
117 HANDLE api_handle; // used by the API to communicate with the device
118 } interface_handle[USB_MAXINTERFACES];
119 int autoclaim_count[USB_MAXINTERFACES]; // For auto-release
122 struct usbdk_transfer_priv {
123 USB_DK_TRANSFER_REQUEST request;
124 struct winfd pollable_fd;
125 HANDLE system_handle;
126 PULONG64 IsochronousPacketsArray;
127 PUSB_DK_ISO_TRANSFER_RESULT IsochronousResultsArray;
130 struct winusb_transfer_priv {
131 struct winfd pollable_fd;
133 uint8_t interface_number;
134 uint8_t *hid_buffer; // 1 byte extended data buffer, required for HID
135 uint8_t *hid_dest; // transfer buffer destination, required for HID
136 size_t hid_expected_size;