1 | /*++
|
---|
2 |
|
---|
3 | Copyright (c) 2000 Microsoft Corporation
|
---|
4 |
|
---|
5 | Module Name:
|
---|
6 |
|
---|
7 | vboxusb.h
|
---|
8 |
|
---|
9 | Abstract:
|
---|
10 |
|
---|
11 | Environment:
|
---|
12 |
|
---|
13 | Kernel mode
|
---|
14 |
|
---|
15 | Notes:
|
---|
16 |
|
---|
17 | Copyright (c) 2000 Microsoft Corporation.
|
---|
18 | All Rights Reserved.
|
---|
19 |
|
---|
20 | --*/
|
---|
21 | #ifndef _VBOXUSB_H
|
---|
22 | #define _VBOXUSB_H
|
---|
23 |
|
---|
24 |
|
---|
25 | #include <VBox/cdefs.h>
|
---|
26 | #include <VBox/types.h>
|
---|
27 | #include <iprt/assert.h>
|
---|
28 | #include <VBox/sup.h>
|
---|
29 | #include <iprt/asm.h>
|
---|
30 |
|
---|
31 | RT_C_DECLS_BEGIN
|
---|
32 | #if (_MSC_VER >= 1400) && !defined(VBOX_WITH_PATCHED_DDK)
|
---|
33 | # define _InterlockedExchange _InterlockedExchange_StupidDDKVsCompilerCrap
|
---|
34 | # define _InterlockedExchangeAdd _InterlockedExchangeAdd_StupidDDKVsCompilerCrap
|
---|
35 | # define _InterlockedCompareExchange _InterlockedCompareExchange_StupidDDKVsCompilerCrap
|
---|
36 | # define _InterlockedAddLargeStatistic _InterlockedAddLargeStatistic_StupidDDKVsCompilerCrap
|
---|
37 | # pragma warning(disable : 4163)
|
---|
38 | #endif
|
---|
39 | #if (_MSC_VER >= 1600) && !defined(VBOX_WITH_PATCHED_DDK)
|
---|
40 | # define _interlockedbittestandset _interlockedbittestandset_StillStupidDdkVsCompilerCrap
|
---|
41 | # define _interlockedbittestandreset _interlockedbittestandreset_StillStupidDdkVsCompilerCrap
|
---|
42 | # define _interlockedbittestandset64 _interlockedbittestandset64_StillStupidDdkVsCompilerCrap
|
---|
43 | # define _interlockedbittestandreset64 _interlockedbittestandreset64_StillStupidDdkVsCompilerCrap
|
---|
44 | # pragma warning(disable : 4163)
|
---|
45 | #endif
|
---|
46 |
|
---|
47 | #include <initguid.h>
|
---|
48 | #include <wdm.h>
|
---|
49 | #include <wmilib.h>
|
---|
50 | #include <wmistr.h>
|
---|
51 | /* The pragma shuts up the following warning:
|
---|
52 | ...inc\ddk\wnet\usbioctl.h(447) : warning C4200: nonstandard extension used : zero-sized array in struct/union
|
---|
53 | Cannot generate copy-ctor or copy-assignment operator when UDT contains a zero-sized array */
|
---|
54 | #pragma warning( disable : 4200 )
|
---|
55 | #include "usbdi.h"
|
---|
56 | #pragma warning( default : 4200 )
|
---|
57 | #include "usbdlib.h"
|
---|
58 | #include <VBox/usblib.h>
|
---|
59 |
|
---|
60 | #if (_MSC_VER >= 1400) && !defined(VBOX_WITH_PATCHED_DDK)
|
---|
61 | # pragma warning(default : 4163)
|
---|
62 | # undef _InterlockedExchange
|
---|
63 | # undef _InterlockedExchangeAdd
|
---|
64 | # undef _InterlockedCompareExchange
|
---|
65 | # undef _InterlockedAddLargeStatistic
|
---|
66 | #endif
|
---|
67 | #if (_MSC_VER >= 1600) && !defined(VBOX_WITH_PATCHED_DDK)
|
---|
68 | # pragma warning(default : 4163)
|
---|
69 | # undef _interlockedbittestandset
|
---|
70 | # undef _interlockedbittestandreset
|
---|
71 | # undef _interlockedbittestandset64
|
---|
72 | # undef _interlockedbittestandreset64
|
---|
73 | #endif
|
---|
74 | RT_C_DECLS_END
|
---|
75 |
|
---|
76 | #if defined(DEBUG) && !defined(NO_LOGGING)
|
---|
77 | # define dprintf(a) DbgPrint a
|
---|
78 | #else
|
---|
79 | # define dprintf(a) do {} while (0)
|
---|
80 | #endif
|
---|
81 |
|
---|
82 | // from usb.h
|
---|
83 | #define USBD_DEFAULT_PIPE_TRANSFER 0x00000008
|
---|
84 |
|
---|
85 | #define VBOXUSBTAG (ULONG) 'UxBV'
|
---|
86 |
|
---|
87 | #undef ExAllocatePool
|
---|
88 | #define ExAllocatePool(type, size) \
|
---|
89 | ExAllocatePoolWithTag(type, size, VBOXUSBTAG);
|
---|
90 |
|
---|
91 | typedef struct _GLOBALS {
|
---|
92 |
|
---|
93 | UNICODE_STRING VBoxUSB_RegistryPath;
|
---|
94 |
|
---|
95 | } GLOBALS;
|
---|
96 |
|
---|
97 | #define IDLE_INTERVAL 5000
|
---|
98 |
|
---|
99 | typedef enum _DEVSTATE {
|
---|
100 |
|
---|
101 | NotStarted, // not started
|
---|
102 | Stopped, // device stopped
|
---|
103 | Working, // started and working
|
---|
104 | PendingStop, // stop pending
|
---|
105 | PendingRemove, // remove pending
|
---|
106 | SurpriseRemoved, // removed by surprise
|
---|
107 | Removed // removed
|
---|
108 |
|
---|
109 | } DEVSTATE;
|
---|
110 |
|
---|
111 | typedef enum _QUEUE_STATE {
|
---|
112 |
|
---|
113 | HoldRequests, // device is not started yet
|
---|
114 | AllowRequests, // device is ready to process
|
---|
115 | FailRequests // fail both existing and queued up requests
|
---|
116 |
|
---|
117 | } QUEUE_STATE;
|
---|
118 |
|
---|
119 | typedef enum _WDM_VERSION {
|
---|
120 |
|
---|
121 | WinXpOrBetter,
|
---|
122 | Win2kOrBetter,
|
---|
123 | WinMeOrBetter,
|
---|
124 | Win98OrBetter
|
---|
125 |
|
---|
126 | } WDM_VERSION;
|
---|
127 |
|
---|
128 | #define INITIALIZE_PNP_STATE(_Data_) \
|
---|
129 | (_Data_)->DeviceState = NotStarted;\
|
---|
130 | (_Data_)->PrevDevState = NotStarted;
|
---|
131 |
|
---|
132 | #define SET_NEW_PNP_STATE(_Data_, _state_) \
|
---|
133 | (_Data_)->PrevDevState = (_Data_)->DeviceState;\
|
---|
134 | (_Data_)->DeviceState = (_state_);
|
---|
135 |
|
---|
136 | #define RESTORE_PREVIOUS_PNP_STATE(_Data_) \
|
---|
137 | (_Data_)->DeviceState = (_Data_)->PrevDevState;
|
---|
138 |
|
---|
139 |
|
---|
140 | #define VBOXUSB_MAX_TRANSFER_SIZE 256
|
---|
141 | #define VBOXUSB_TEST_BOARD_TRANSFER_BUFFER_SIZE (64 *1024 )
|
---|
142 |
|
---|
143 | //
|
---|
144 | // registry path used for parameters
|
---|
145 | // global to all instances of the driver
|
---|
146 | //
|
---|
147 |
|
---|
148 | #define VBOXUSB_REGISTRY_PARAMETERS_PATH \
|
---|
149 | L"\\REGISTRY\\Machine\\System\\CurrentControlSet\\SERVICES\\VBOXUSB\\Parameters"
|
---|
150 |
|
---|
151 |
|
---|
152 | typedef struct _VBOXUSB_PIPE_CONTEXT {
|
---|
153 |
|
---|
154 | BOOLEAN PipeOpen;
|
---|
155 |
|
---|
156 | } VBOXUSB_PIPE_CONTEXT, *PVBOXUSB_PIPE_CONTEXT;
|
---|
157 |
|
---|
158 | typedef struct _VBOXUSB_PIPE_INFO {
|
---|
159 | UCHAR EndpointAddress;
|
---|
160 | ULONG NextScheduledFrame;
|
---|
161 | } VBOXUSB_PIPE_INFO;
|
---|
162 |
|
---|
163 | typedef struct _VBOXUSB_IFACE_INFO {
|
---|
164 | USBD_INTERFACE_INFORMATION *pInterfaceInfo;
|
---|
165 | VBOXUSB_PIPE_INFO *pPipeInfo;
|
---|
166 | } VBOXUSB_IFACE_INFO;
|
---|
167 |
|
---|
168 |
|
---|
169 | // A number that should cover the vast majority of USB devices
|
---|
170 | #define MAX_CFGS 4
|
---|
171 |
|
---|
172 | //
|
---|
173 | // A structure representing the instance information associated with
|
---|
174 | // this particular device.
|
---|
175 | //
|
---|
176 |
|
---|
177 | typedef struct _DEVICE_EXTENSION {
|
---|
178 |
|
---|
179 | // Functional Device Object
|
---|
180 | PDEVICE_OBJECT FunctionalDeviceObject;
|
---|
181 |
|
---|
182 | // Device object we call when submitting Urbs
|
---|
183 | PDEVICE_OBJECT TopOfStackDeviceObject;
|
---|
184 |
|
---|
185 | // The bus driver object
|
---|
186 | PDEVICE_OBJECT PhysicalDeviceObject;
|
---|
187 |
|
---|
188 | // Name buffer for our named Functional device object link
|
---|
189 | // The name is generated based on the driver's class GUID
|
---|
190 | UNICODE_STRING InterfaceName;
|
---|
191 |
|
---|
192 | // Bus drivers set the appropriate values in this structure in response
|
---|
193 | // to an IRP_MN_QUERY_CAPABILITIES IRP. Function and filter drivers might
|
---|
194 | // alter the capabilities set by the bus driver.
|
---|
195 | DEVICE_CAPABILITIES DeviceCapabilities;
|
---|
196 |
|
---|
197 | // Configuration Descriptor
|
---|
198 | PUSB_CONFIGURATION_DESCRIPTOR UsbConfigurationDescriptor;
|
---|
199 |
|
---|
200 | // Interface Information structure
|
---|
201 | PUSBD_INTERFACE_INFORMATION UsbInterface;
|
---|
202 |
|
---|
203 | // Pipe context for the vboxusb driver
|
---|
204 | PVBOXUSB_PIPE_CONTEXT PipeContext;
|
---|
205 |
|
---|
206 | // current state of device
|
---|
207 | DEVSTATE DeviceState;
|
---|
208 |
|
---|
209 | // state prior to removal query
|
---|
210 | DEVSTATE PrevDevState;
|
---|
211 |
|
---|
212 | // obtain and hold this lock while changing the device state,
|
---|
213 | // the queue state and while processing the queue.
|
---|
214 | KSPIN_LOCK DevStateLock;
|
---|
215 |
|
---|
216 | // current system power state
|
---|
217 | SYSTEM_POWER_STATE SysPower;
|
---|
218 |
|
---|
219 | // current device power state
|
---|
220 | DEVICE_POWER_STATE DevPower;
|
---|
221 |
|
---|
222 | // Pending I/O queue state
|
---|
223 | QUEUE_STATE QueueState;
|
---|
224 |
|
---|
225 | // Pending I/O queue
|
---|
226 | LIST_ENTRY NewRequestsQueue;
|
---|
227 |
|
---|
228 | // I/O Queue Lock
|
---|
229 | KSPIN_LOCK QueueLock;
|
---|
230 |
|
---|
231 | KEVENT RemoveEvent;
|
---|
232 |
|
---|
233 | KEVENT StopEvent;
|
---|
234 |
|
---|
235 | ULONG OutStandingIO;
|
---|
236 |
|
---|
237 | KSPIN_LOCK IOCountLock;
|
---|
238 |
|
---|
239 | // selective suspend variables
|
---|
240 |
|
---|
241 | LONG SSEnable;
|
---|
242 |
|
---|
243 | LONG SSRegistryEnable;
|
---|
244 |
|
---|
245 | PUSB_IDLE_CALLBACK_INFO IdleCallbackInfo;
|
---|
246 |
|
---|
247 | PIRP PendingIdleIrp;
|
---|
248 |
|
---|
249 | LONG IdleReqPend;
|
---|
250 |
|
---|
251 | LONG FreeIdleIrpCount;
|
---|
252 |
|
---|
253 | KSPIN_LOCK IdleReqStateLock;
|
---|
254 |
|
---|
255 | KEVENT NoIdleReqPendEvent;
|
---|
256 |
|
---|
257 | // default power state to power down to on self-susped
|
---|
258 | ULONG PowerDownLevel;
|
---|
259 |
|
---|
260 | // remote wakeup variables
|
---|
261 | PIRP WaitWakeIrp;
|
---|
262 |
|
---|
263 | LONG FlagWWCancel;
|
---|
264 |
|
---|
265 | LONG FlagWWOutstanding;
|
---|
266 |
|
---|
267 | LONG WaitWakeEnable;
|
---|
268 |
|
---|
269 | // open handle count
|
---|
270 | LONG OpenHandleCount;
|
---|
271 |
|
---|
272 | // selective suspend model uses timers, dpcs and work item.
|
---|
273 | KTIMER Timer;
|
---|
274 |
|
---|
275 | KDPC DeferredProcCall;
|
---|
276 |
|
---|
277 | // This event is cleared when a DPC/Work Item is queued.
|
---|
278 | // and signaled when the work-item completes.
|
---|
279 | // This is essential to prevent the driver from unloading
|
---|
280 | // while we have DPC or work-item queued up.
|
---|
281 | KEVENT NoDpcWorkItemPendingEvent;
|
---|
282 |
|
---|
283 | #ifdef SUPPORT_WMI
|
---|
284 | // WMI information
|
---|
285 | WMILIB_CONTEXT WmiLibInfo;
|
---|
286 | #endif
|
---|
287 |
|
---|
288 | // WDM version
|
---|
289 | WDM_VERSION WdmVersion;
|
---|
290 |
|
---|
291 | struct
|
---|
292 | {
|
---|
293 | HANDLE hConfiguration;
|
---|
294 | uint32_t uConfigValue;
|
---|
295 |
|
---|
296 | LONG fClaimed;
|
---|
297 |
|
---|
298 | uint32_t uNumInterfaces;
|
---|
299 | USB_DEVICE_DESCRIPTOR *devdescr;
|
---|
300 | USB_CONFIGURATION_DESCRIPTOR *cfgdescr[MAX_CFGS];
|
---|
301 |
|
---|
302 | VBOXUSB_IFACE_INFO *pVBIfaceInfo;
|
---|
303 |
|
---|
304 | uint16_t idVendor, idProduct, bcdDevice;
|
---|
305 | char szSerial[MAX_USB_SERIAL_STRING];
|
---|
306 | uint8_t fIsHighSpeed;
|
---|
307 |
|
---|
308 | } usbdev;
|
---|
309 |
|
---|
310 | } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
|
---|
311 |
|
---|
312 |
|
---|
313 | typedef struct _IRP_COMPLETION_CONTEXT {
|
---|
314 |
|
---|
315 | PDEVICE_EXTENSION DeviceExtension;
|
---|
316 |
|
---|
317 | PKEVENT Event;
|
---|
318 |
|
---|
319 | } IRP_COMPLETION_CONTEXT, *PIRP_COMPLETION_CONTEXT;
|
---|
320 |
|
---|
321 | extern GLOBALS Globals;
|
---|
322 |
|
---|
323 |
|
---|
324 | typedef struct {
|
---|
325 | uint8_t bmRequestType;
|
---|
326 | uint8_t bRequest;
|
---|
327 | uint16_t wValue;
|
---|
328 | uint16_t wIndex;
|
---|
329 | uint16_t wLength;
|
---|
330 | } USBSETUP, *PUSBSETUP;
|
---|
331 |
|
---|
332 |
|
---|
333 | RT_C_DECLS_BEGIN
|
---|
334 |
|
---|
335 | /* Hack to get imported names correctly in both win32 & win64 */
|
---|
336 | #ifdef _WIN64
|
---|
337 | #define DECLSPEC_USBIMPORT DECLSPEC_IMPORT
|
---|
338 | #else
|
---|
339 | #define DECLSPEC_USBIMPORT
|
---|
340 |
|
---|
341 | #define USBD_ParseDescriptors _USBD_ParseDescriptors
|
---|
342 | #define USBD_ParseConfigurationDescriptorEx _USBD_ParseConfigurationDescriptorEx
|
---|
343 | #define USBD_CreateConfigurationRequestEx _USBD_CreateConfigurationRequestEx
|
---|
344 | #endif
|
---|
345 |
|
---|
346 | DECLSPEC_USBIMPORT PUSB_COMMON_DESCRIPTOR
|
---|
347 | USBD_ParseDescriptors(
|
---|
348 | IN PVOID DescriptorBuffer,
|
---|
349 | IN ULONG TotalLength,
|
---|
350 | IN PVOID StartPosition,
|
---|
351 | IN LONG DescriptorType
|
---|
352 | );
|
---|
353 |
|
---|
354 | DECLSPEC_USBIMPORT PUSB_INTERFACE_DESCRIPTOR
|
---|
355 | USBD_ParseConfigurationDescriptorEx(
|
---|
356 | IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
|
---|
357 | IN PVOID StartPosition,
|
---|
358 | IN LONG InterfaceNumber,
|
---|
359 | IN LONG AlternateSetting,
|
---|
360 | IN LONG InterfaceClass,
|
---|
361 | IN LONG InterfaceSubClass,
|
---|
362 | IN LONG InterfaceProtocol
|
---|
363 | );
|
---|
364 |
|
---|
365 | DECLSPEC_USBIMPORT PURB
|
---|
366 | USBD_CreateConfigurationRequestEx(
|
---|
367 | IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
|
---|
368 | IN PUSBD_INTERFACE_LIST_ENTRY InterfaceList
|
---|
369 | );
|
---|
370 |
|
---|
371 | RT_C_DECLS_END
|
---|
372 |
|
---|
373 | #endif
|
---|