1 | /* $Id: VBoxUsbRt.cpp 50349 2014-02-06 15:01:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox USB R0 runtime
|
---|
4 | */
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2011 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #include "VBoxUsbCmn.h"
|
---|
18 | #include "../cmn/VBoxUsbIdc.h"
|
---|
19 | #include "../cmn/VBoxUsbTool.h"
|
---|
20 |
|
---|
21 | #include <VBox/usblib-win.h>
|
---|
22 | #include <iprt/assert.h>
|
---|
23 | #include <VBox/log.h>
|
---|
24 | #define _USBD_
|
---|
25 |
|
---|
26 | #define USBD_DEFAULT_PIPE_TRANSFER 0x00000008
|
---|
27 |
|
---|
28 | #define VBOXUSB_MAGIC 0xABCF1423
|
---|
29 |
|
---|
30 | typedef struct VBOXUSB_URB_CONTEXT
|
---|
31 | {
|
---|
32 | PURB pUrb;
|
---|
33 | PMDL pMdlBuf;
|
---|
34 | PVBOXUSBDEV_EXT pDevExt;
|
---|
35 | PVOID pOut;
|
---|
36 | ULONG ulTransferType;
|
---|
37 | ULONG ulMagic;
|
---|
38 | } VBOXUSB_URB_CONTEXT, * PVBOXUSB_URB_CONTEXT;
|
---|
39 |
|
---|
40 | typedef struct VBOXUSB_SETUP
|
---|
41 | {
|
---|
42 | uint8_t bmRequestType;
|
---|
43 | uint8_t bRequest;
|
---|
44 | uint16_t wValue;
|
---|
45 | uint16_t wIndex;
|
---|
46 | uint16_t wLength;
|
---|
47 | } VBOXUSB_SETUP, *PVBOXUSB_SETUP;
|
---|
48 |
|
---|
49 | static bool vboxUsbRtCtxSetOwner(PVBOXUSBDEV_EXT pDevExt, PFILE_OBJECT pFObj)
|
---|
50 | {
|
---|
51 | bool bRc = ASMAtomicCmpXchgPtr(&pDevExt->Rt.pOwner, pFObj, NULL);
|
---|
52 | if (bRc)
|
---|
53 | {
|
---|
54 | Log((__FUNCTION__": pDevExt (0x%x) Owner(0x%x) acquired\n", pFObj));
|
---|
55 | }
|
---|
56 | else
|
---|
57 | {
|
---|
58 | Log((__FUNCTION__": pDevExt (0x%x) Owner(0x%x) FAILED!!\n", pFObj));
|
---|
59 | }
|
---|
60 | return bRc;
|
---|
61 | }
|
---|
62 |
|
---|
63 | static bool vboxUsbRtCtxReleaseOwner(PVBOXUSBDEV_EXT pDevExt, PFILE_OBJECT pFObj)
|
---|
64 | {
|
---|
65 | bool bRc = ASMAtomicCmpXchgPtr(&pDevExt->Rt.pOwner, NULL, pFObj);
|
---|
66 | if (bRc)
|
---|
67 | {
|
---|
68 | Log((__FUNCTION__": pDevExt (0x%x) Owner(0x%x) released\n", pFObj));
|
---|
69 | }
|
---|
70 | else
|
---|
71 | {
|
---|
72 | Log((__FUNCTION__": pDevExt (0x%x) Owner(0x%x) release: is NOT an owner\n", pFObj));
|
---|
73 | }
|
---|
74 | return bRc;
|
---|
75 | }
|
---|
76 |
|
---|
77 | static bool vboxUsbRtCtxIsOwner(PVBOXUSBDEV_EXT pDevExt, PFILE_OBJECT pFObj)
|
---|
78 | {
|
---|
79 | PFILE_OBJECT pOwner = (PFILE_OBJECT)ASMAtomicReadPtr((void *volatile *)(&pDevExt->Rt.pOwner));
|
---|
80 | return pOwner == pFObj;
|
---|
81 | }
|
---|
82 |
|
---|
83 | static NTSTATUS vboxUsbRtIdcSubmit(ULONG uCtl, void *pvBuffer)
|
---|
84 | {
|
---|
85 | /* we just reuse the standard usb tooling for simplicity here */
|
---|
86 | NTSTATUS Status = VBoxUsbToolIoInternalCtlSendSync(g_VBoxUsbGlobals.RtIdc.pDevice, uCtl, pvBuffer, NULL);
|
---|
87 | Assert(Status == STATUS_SUCCESS);
|
---|
88 | return Status;
|
---|
89 | }
|
---|
90 |
|
---|
91 | static NTSTATUS vboxUsbRtIdcInit()
|
---|
92 | {
|
---|
93 | UNICODE_STRING UniName;
|
---|
94 | RtlInitUnicodeString(&UniName, USBMON_DEVICE_NAME_NT);
|
---|
95 | NTSTATUS Status = IoGetDeviceObjectPointer(&UniName, FILE_ALL_ACCESS, &g_VBoxUsbGlobals.RtIdc.pFile, &g_VBoxUsbGlobals.RtIdc.pDevice);
|
---|
96 | if (NT_SUCCESS(Status))
|
---|
97 | {
|
---|
98 | VBOXUSBIDC_VERSION Version;
|
---|
99 | vboxUsbRtIdcSubmit(VBOXUSBIDC_INTERNAL_IOCTL_GET_VERSION, &Version);
|
---|
100 | if (NT_SUCCESS(Status))
|
---|
101 | {
|
---|
102 | if (Version.u32Major == VBOXUSBIDC_VERSION_MAJOR
|
---|
103 | && Version.u32Minor >= VBOXUSBIDC_VERSION_MINOR)
|
---|
104 | return STATUS_SUCCESS;
|
---|
105 | AssertFailed();
|
---|
106 | }
|
---|
107 | else
|
---|
108 | {
|
---|
109 | AssertFailed();
|
---|
110 | }
|
---|
111 |
|
---|
112 | /* this will as well dereference the dev obj */
|
---|
113 | ObDereferenceObject(g_VBoxUsbGlobals.RtIdc.pFile);
|
---|
114 | }
|
---|
115 | else
|
---|
116 | {
|
---|
117 | AssertFailed();
|
---|
118 | }
|
---|
119 |
|
---|
120 | memset(&g_VBoxUsbGlobals.RtIdc, 0, sizeof (g_VBoxUsbGlobals.RtIdc));
|
---|
121 | return Status;
|
---|
122 | }
|
---|
123 |
|
---|
124 | static VOID vboxUsbRtIdcTerm()
|
---|
125 | {
|
---|
126 | Assert(g_VBoxUsbGlobals.RtIdc.pFile);
|
---|
127 | Assert(g_VBoxUsbGlobals.RtIdc.pDevice);
|
---|
128 | ObDereferenceObject(g_VBoxUsbGlobals.RtIdc.pFile);
|
---|
129 | memset(&g_VBoxUsbGlobals.RtIdc, 0, sizeof (g_VBoxUsbGlobals.RtIdc));
|
---|
130 | }
|
---|
131 |
|
---|
132 | static NTSTATUS vboxUsbRtIdcReportDevStart(PDEVICE_OBJECT pPDO, HVBOXUSBIDCDEV *phDev)
|
---|
133 | {
|
---|
134 | VBOXUSBIDC_PROXY_STARTUP Start;
|
---|
135 | Start.u.pPDO = pPDO;
|
---|
136 |
|
---|
137 | *phDev = NULL;
|
---|
138 |
|
---|
139 | NTSTATUS Status = vboxUsbRtIdcSubmit(VBOXUSBIDC_INTERNAL_IOCTL_PROXY_STARTUP, &Start);
|
---|
140 | Assert(Status == STATUS_SUCCESS);
|
---|
141 | if (!NT_SUCCESS(Status))
|
---|
142 | return Status;
|
---|
143 |
|
---|
144 | *phDev = Start.u.hDev;
|
---|
145 | return STATUS_SUCCESS;
|
---|
146 | }
|
---|
147 |
|
---|
148 | static NTSTATUS vboxUsbRtIdcReportDevStop(HVBOXUSBIDCDEV hDev)
|
---|
149 | {
|
---|
150 | VBOXUSBIDC_PROXY_TEARDOWN Stop;
|
---|
151 | Stop.hDev = hDev;
|
---|
152 |
|
---|
153 | NTSTATUS Status = vboxUsbRtIdcSubmit(VBOXUSBIDC_INTERNAL_IOCTL_PROXY_TEARDOWN, &Stop);
|
---|
154 | Assert(Status == STATUS_SUCCESS);
|
---|
155 | return Status;
|
---|
156 | }
|
---|
157 |
|
---|
158 |
|
---|
159 | DECLHIDDEN(NTSTATUS) vboxUsbRtGlobalsInit()
|
---|
160 | {
|
---|
161 | return vboxUsbRtIdcInit();
|
---|
162 | }
|
---|
163 |
|
---|
164 | DECLHIDDEN(VOID) vboxUsbRtGlobalsTerm()
|
---|
165 | {
|
---|
166 | vboxUsbRtIdcTerm();
|
---|
167 | }
|
---|
168 |
|
---|
169 |
|
---|
170 | DECLHIDDEN(NTSTATUS) vboxUsbRtInit(PVBOXUSBDEV_EXT pDevExt)
|
---|
171 | {
|
---|
172 | RtlZeroMemory(&pDevExt->Rt, sizeof (pDevExt->Rt));
|
---|
173 | NTSTATUS Status = IoRegisterDeviceInterface(pDevExt->pPDO, &GUID_CLASS_VBOXUSB,
|
---|
174 | NULL, /* IN PUNICODE_STRING ReferenceString OPTIONAL */
|
---|
175 | &pDevExt->Rt.IfName);
|
---|
176 | Assert(Status == STATUS_SUCCESS);
|
---|
177 | if (NT_SUCCESS(Status))
|
---|
178 | {
|
---|
179 | Status = vboxUsbRtIdcReportDevStart(pDevExt->pPDO, &pDevExt->Rt.hMonDev);
|
---|
180 | Assert(Status == STATUS_SUCCESS);
|
---|
181 | if (NT_SUCCESS(Status))
|
---|
182 | {
|
---|
183 | Assert(pDevExt->Rt.hMonDev);
|
---|
184 | return STATUS_SUCCESS;
|
---|
185 | }
|
---|
186 |
|
---|
187 | NTSTATUS tmpStatus = IoSetDeviceInterfaceState(&pDevExt->Rt.IfName, FALSE);
|
---|
188 | Assert(tmpStatus == STATUS_SUCCESS);
|
---|
189 | if (NT_SUCCESS(tmpStatus))
|
---|
190 | {
|
---|
191 | RtlFreeUnicodeString(&pDevExt->Rt.IfName);
|
---|
192 | }
|
---|
193 | }
|
---|
194 | return Status;
|
---|
195 | }
|
---|
196 |
|
---|
197 | /**
|
---|
198 | * Free cached USB device/configuration descriptors
|
---|
199 | *
|
---|
200 | * @param pDevExt USB DevExt pointer
|
---|
201 | */
|
---|
202 | static void vboxUsbRtFreeCachedDescriptors(PVBOXUSBDEV_EXT pDevExt)
|
---|
203 | {
|
---|
204 | if (pDevExt->Rt.devdescr)
|
---|
205 | {
|
---|
206 | vboxUsbMemFree(pDevExt->Rt.devdescr);
|
---|
207 | pDevExt->Rt.devdescr = NULL;
|
---|
208 | }
|
---|
209 | for (ULONG i = 0; i < VBOXUSBRT_MAX_CFGS; ++i)
|
---|
210 | {
|
---|
211 | if (pDevExt->Rt.cfgdescr[i])
|
---|
212 | {
|
---|
213 | vboxUsbMemFree(pDevExt->Rt.cfgdescr[i]);
|
---|
214 | pDevExt->Rt.cfgdescr[i] = NULL;
|
---|
215 | }
|
---|
216 | }
|
---|
217 | }
|
---|
218 |
|
---|
219 | /**
|
---|
220 | * Free per-device interface info
|
---|
221 | *
|
---|
222 | * @param pDevExt USB DevExt pointer
|
---|
223 | * @param fAbortPipes If true, also abort any open pipes
|
---|
224 | */
|
---|
225 | static void vboxUsbRtFreeInterfaces(PVBOXUSBDEV_EXT pDevExt, BOOLEAN fAbortPipes)
|
---|
226 | {
|
---|
227 | unsigned i;
|
---|
228 | unsigned j;
|
---|
229 |
|
---|
230 | /*
|
---|
231 | * Free old interface info
|
---|
232 | */
|
---|
233 | if (pDevExt->Rt.pVBIfaceInfo)
|
---|
234 | {
|
---|
235 | for (i=0;i<pDevExt->Rt.uNumInterfaces;i++)
|
---|
236 | {
|
---|
237 | if (pDevExt->Rt.pVBIfaceInfo[i].pInterfaceInfo)
|
---|
238 | {
|
---|
239 | if (fAbortPipes)
|
---|
240 | {
|
---|
241 | for(j=0; j<pDevExt->Rt.pVBIfaceInfo[i].pInterfaceInfo->NumberOfPipes; j++)
|
---|
242 | {
|
---|
243 | Log(("Aborting Pipe %d handle %x address %x\n", j,
|
---|
244 | pDevExt->Rt.pVBIfaceInfo[i].pInterfaceInfo->Pipes[j].PipeHandle,
|
---|
245 | pDevExt->Rt.pVBIfaceInfo[i].pInterfaceInfo->Pipes[j].EndpointAddress));
|
---|
246 | VBoxUsbToolPipeClear(pDevExt->pLowerDO, pDevExt->Rt.pVBIfaceInfo[i].pInterfaceInfo->Pipes[j].PipeHandle, FALSE);
|
---|
247 | }
|
---|
248 | }
|
---|
249 | vboxUsbMemFree(pDevExt->Rt.pVBIfaceInfo[i].pInterfaceInfo);
|
---|
250 | }
|
---|
251 | pDevExt->Rt.pVBIfaceInfo[i].pInterfaceInfo = NULL;
|
---|
252 | if (pDevExt->Rt.pVBIfaceInfo[i].pPipeInfo)
|
---|
253 | vboxUsbMemFree(pDevExt->Rt.pVBIfaceInfo[i].pPipeInfo);
|
---|
254 | pDevExt->Rt.pVBIfaceInfo[i].pPipeInfo = NULL;
|
---|
255 | }
|
---|
256 | vboxUsbMemFree(pDevExt->Rt.pVBIfaceInfo);
|
---|
257 | pDevExt->Rt.pVBIfaceInfo = NULL;
|
---|
258 | }
|
---|
259 | }
|
---|
260 |
|
---|
261 | DECLHIDDEN(VOID) vboxUsbRtClear(PVBOXUSBDEV_EXT pDevExt)
|
---|
262 | {
|
---|
263 | vboxUsbRtFreeCachedDescriptors(pDevExt);
|
---|
264 | vboxUsbRtFreeInterfaces(pDevExt, FALSE);
|
---|
265 | }
|
---|
266 |
|
---|
267 | DECLHIDDEN(NTSTATUS) vboxUsbRtRm(PVBOXUSBDEV_EXT pDevExt)
|
---|
268 | {
|
---|
269 | if (!pDevExt->Rt.IfName.Buffer)
|
---|
270 | return STATUS_SUCCESS;
|
---|
271 |
|
---|
272 | NTSTATUS Status = vboxUsbRtIdcReportDevStop(pDevExt->Rt.hMonDev);
|
---|
273 | Assert(Status == STATUS_SUCCESS);
|
---|
274 | Status = IoSetDeviceInterfaceState(&pDevExt->Rt.IfName, FALSE);
|
---|
275 | Assert(Status == STATUS_SUCCESS);
|
---|
276 | if (NT_SUCCESS(Status))
|
---|
277 | {
|
---|
278 | RtlFreeUnicodeString(&pDevExt->Rt.IfName);
|
---|
279 | pDevExt->Rt.IfName.Buffer = NULL;
|
---|
280 | }
|
---|
281 | return Status;
|
---|
282 | }
|
---|
283 |
|
---|
284 | DECLHIDDEN(NTSTATUS) vboxUsbRtStart(PVBOXUSBDEV_EXT pDevExt)
|
---|
285 | {
|
---|
286 | NTSTATUS Status = IoSetDeviceInterfaceState(&pDevExt->Rt.IfName, TRUE);
|
---|
287 | Assert(Status == STATUS_SUCCESS);
|
---|
288 | return Status;
|
---|
289 | }
|
---|
290 |
|
---|
291 | static NTSTATUS vboxUsbRtCacheDescriptors(PVBOXUSBDEV_EXT pDevExt)
|
---|
292 | {
|
---|
293 | NTSTATUS Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
294 | // uint32_t uTotalLength;
|
---|
295 | // unsigned i;
|
---|
296 |
|
---|
297 | /* Read device descriptor */
|
---|
298 | Assert(!pDevExt->Rt.devdescr);
|
---|
299 | pDevExt->Rt.devdescr = (PUSB_DEVICE_DESCRIPTOR)vboxUsbMemAlloc(sizeof (USB_DEVICE_DESCRIPTOR));
|
---|
300 | if (pDevExt->Rt.devdescr)
|
---|
301 | {
|
---|
302 | memset(pDevExt->Rt.devdescr, 0, sizeof (USB_DEVICE_DESCRIPTOR));
|
---|
303 | Status = VBoxUsbToolGetDescriptor(pDevExt->pLowerDO, pDevExt->Rt.devdescr, sizeof (USB_DEVICE_DESCRIPTOR), USB_DEVICE_DESCRIPTOR_TYPE, 0, 0, RT_INDEFINITE_WAIT);
|
---|
304 | if (NT_SUCCESS(Status))
|
---|
305 | {
|
---|
306 | Assert(pDevExt->Rt.devdescr->bNumConfigurations > 0);
|
---|
307 | PUSB_CONFIGURATION_DESCRIPTOR pDr = (PUSB_CONFIGURATION_DESCRIPTOR)vboxUsbMemAlloc(sizeof (USB_CONFIGURATION_DESCRIPTOR));
|
---|
308 | Assert(pDr);
|
---|
309 | if (pDr)
|
---|
310 | {
|
---|
311 | UCHAR i = 0;
|
---|
312 | for (; i < pDevExt->Rt.devdescr->bNumConfigurations; ++i)
|
---|
313 | {
|
---|
314 | Status = VBoxUsbToolGetDescriptor(pDevExt->pLowerDO, pDr, sizeof (USB_CONFIGURATION_DESCRIPTOR), USB_CONFIGURATION_DESCRIPTOR_TYPE, i, 0, RT_INDEFINITE_WAIT);
|
---|
315 | if (!NT_SUCCESS(Status))
|
---|
316 | {
|
---|
317 | break;
|
---|
318 | }
|
---|
319 |
|
---|
320 | USHORT uTotalLength = pDr->wTotalLength;
|
---|
321 | pDevExt->Rt.cfgdescr[i] = (PUSB_CONFIGURATION_DESCRIPTOR)vboxUsbMemAlloc(uTotalLength);
|
---|
322 | if (!pDevExt->Rt.cfgdescr[i])
|
---|
323 | {
|
---|
324 | Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
325 | break;
|
---|
326 | }
|
---|
327 |
|
---|
328 | Status = VBoxUsbToolGetDescriptor(pDevExt->pLowerDO, pDevExt->Rt.cfgdescr[i], uTotalLength, USB_CONFIGURATION_DESCRIPTOR_TYPE, i, 0, RT_INDEFINITE_WAIT);
|
---|
329 | if (!NT_SUCCESS(Status))
|
---|
330 | {
|
---|
331 | break;
|
---|
332 | }
|
---|
333 | }
|
---|
334 |
|
---|
335 | vboxUsbMemFree(pDr);
|
---|
336 |
|
---|
337 | if (NT_SUCCESS(Status))
|
---|
338 | return Status;
|
---|
339 |
|
---|
340 | /* recources will be freed in vboxUsbRtFreeCachedDescriptors below */
|
---|
341 | }
|
---|
342 | }
|
---|
343 |
|
---|
344 | vboxUsbRtFreeCachedDescriptors(pDevExt);
|
---|
345 | }
|
---|
346 |
|
---|
347 | /* shoud be only on fail here */
|
---|
348 | Assert(!NT_SUCCESS(Status));
|
---|
349 | return Status;
|
---|
350 | }
|
---|
351 |
|
---|
352 | static NTSTATUS vboxUsbRtDispatchClaimDevice(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp)
|
---|
353 | {
|
---|
354 | PIO_STACK_LOCATION pSl = IoGetCurrentIrpStackLocation(pIrp);
|
---|
355 | PFILE_OBJECT pFObj = pSl->FileObject;
|
---|
356 | PUSBSUP_CLAIMDEV pDev = (PUSBSUP_CLAIMDEV)pIrp->AssociatedIrp.SystemBuffer;
|
---|
357 | ULONG cbOut = 0;
|
---|
358 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
359 |
|
---|
360 | do
|
---|
361 | {
|
---|
362 | if (!pFObj)
|
---|
363 | {
|
---|
364 | AssertFailed();
|
---|
365 | Status = STATUS_INVALID_PARAMETER;
|
---|
366 | break;
|
---|
367 | }
|
---|
368 |
|
---|
369 | if ( !pDev
|
---|
370 | || pSl->Parameters.DeviceIoControl.InputBufferLength != sizeof (*pDev)
|
---|
371 | || pSl->Parameters.DeviceIoControl.OutputBufferLength != sizeof (*pDev))
|
---|
372 | {
|
---|
373 | AssertFailed();
|
---|
374 | Status = STATUS_INVALID_PARAMETER;
|
---|
375 | break;
|
---|
376 | }
|
---|
377 |
|
---|
378 | if (!vboxUsbRtCtxSetOwner(pDevExt, pFObj))
|
---|
379 | {
|
---|
380 | AssertFailed();
|
---|
381 | pDev->fClaimed = false;
|
---|
382 | cbOut = sizeof (*pDev);
|
---|
383 | break;
|
---|
384 | }
|
---|
385 |
|
---|
386 | vboxUsbRtFreeCachedDescriptors(pDevExt);
|
---|
387 | Status = vboxUsbRtCacheDescriptors(pDevExt);
|
---|
388 | if (NT_SUCCESS(Status))
|
---|
389 | {
|
---|
390 | pDev->fClaimed = true;
|
---|
391 | cbOut = sizeof (*pDev);
|
---|
392 | }
|
---|
393 | } while (0);
|
---|
394 |
|
---|
395 | Assert(Status != STATUS_PENDING);
|
---|
396 | VBoxDrvToolIoComplete(pIrp, Status, cbOut);
|
---|
397 | vboxUsbDdiStateRelease(pDevExt);
|
---|
398 | return Status;
|
---|
399 | }
|
---|
400 |
|
---|
401 | static NTSTATUS vboxUsbRtDispatchReleaseDevice(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp)
|
---|
402 | {
|
---|
403 | PIO_STACK_LOCATION pSl = IoGetCurrentIrpStackLocation(pIrp);
|
---|
404 | PFILE_OBJECT pFObj = pSl->FileObject;
|
---|
405 | NTSTATUS Status= STATUS_SUCCESS;
|
---|
406 |
|
---|
407 | if (vboxUsbRtCtxIsOwner(pDevExt, pFObj))
|
---|
408 | {
|
---|
409 | vboxUsbRtFreeCachedDescriptors(pDevExt);
|
---|
410 | bool bRc = vboxUsbRtCtxReleaseOwner(pDevExt, pFObj);
|
---|
411 | Assert(bRc);
|
---|
412 | }
|
---|
413 | else
|
---|
414 | {
|
---|
415 | AssertFailed();
|
---|
416 | Status = STATUS_ACCESS_DENIED;
|
---|
417 | }
|
---|
418 |
|
---|
419 | VBoxDrvToolIoComplete(pIrp, STATUS_SUCCESS, 0);
|
---|
420 | vboxUsbDdiStateRelease(pDevExt);
|
---|
421 | return STATUS_SUCCESS;
|
---|
422 | }
|
---|
423 |
|
---|
424 | static NTSTATUS vboxUsbRtGetDeviceDescription(PVBOXUSBDEV_EXT pDevExt)
|
---|
425 | {
|
---|
426 | NTSTATUS Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
427 | PUSB_DEVICE_DESCRIPTOR pDr = (PUSB_DEVICE_DESCRIPTOR)vboxUsbMemAllocZ(sizeof (USB_DEVICE_DESCRIPTOR));
|
---|
428 | if (pDr)
|
---|
429 | {
|
---|
430 | Status = VBoxUsbToolGetDescriptor(pDevExt->pLowerDO, pDr, sizeof(*pDr), USB_DEVICE_DESCRIPTOR_TYPE, 0, 0, RT_INDEFINITE_WAIT);
|
---|
431 | if (NT_SUCCESS(Status))
|
---|
432 | {
|
---|
433 | pDevExt->Rt.idVendor = pDr->idVendor;
|
---|
434 | pDevExt->Rt.idProduct = pDr->idProduct;
|
---|
435 | pDevExt->Rt.bcdDevice = pDr->bcdDevice;
|
---|
436 | pDevExt->Rt.szSerial[0] = 0;
|
---|
437 |
|
---|
438 | if (pDr->iSerialNumber
|
---|
439 | #ifdef DEBUG
|
---|
440 | || pDr->iProduct || pDr->iManufacturer
|
---|
441 | #endif
|
---|
442 | )
|
---|
443 | {
|
---|
444 | int langId;
|
---|
445 | Status = VBoxUsbToolGetLangID(pDevExt->pLowerDO, &langId, RT_INDEFINITE_WAIT);
|
---|
446 | if (NT_SUCCESS(Status))
|
---|
447 | {
|
---|
448 | Status = VBoxUsbToolGetStringDescriptorA(pDevExt->pLowerDO, pDevExt->Rt.szSerial, sizeof (pDevExt->Rt.szSerial), pDr->iSerialNumber, langId, RT_INDEFINITE_WAIT);
|
---|
449 | }
|
---|
450 | else
|
---|
451 | {
|
---|
452 | Status = STATUS_SUCCESS;
|
---|
453 | }
|
---|
454 | }
|
---|
455 | }
|
---|
456 | vboxUsbMemFree(pDr);
|
---|
457 | }
|
---|
458 |
|
---|
459 | return Status;
|
---|
460 | }
|
---|
461 |
|
---|
462 | static NTSTATUS vboxUsbRtDispatchGetDevice(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp)
|
---|
463 | {
|
---|
464 | PIO_STACK_LOCATION pSl = IoGetCurrentIrpStackLocation(pIrp);
|
---|
465 | PUSBSUP_GETDEV pDev = (PUSBSUP_GETDEV)pIrp->AssociatedIrp.SystemBuffer;
|
---|
466 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
467 | ULONG cbOut = 0;
|
---|
468 |
|
---|
469 | /* don't check for owner since this request is allowed for non-owners as well */
|
---|
470 |
|
---|
471 | if (pDev && pSl->Parameters.DeviceIoControl.InputBufferLength == sizeof (*pDev)
|
---|
472 | && pSl->Parameters.DeviceIoControl.OutputBufferLength == sizeof (*pDev))
|
---|
473 | {
|
---|
474 | Status = VBoxUsbToolGetDeviceSpeed(pDevExt->pLowerDO, &pDevExt->Rt.fIsHighSpeed);
|
---|
475 | if (NT_SUCCESS(Status))
|
---|
476 | {
|
---|
477 | pDev->hDevice = pDevExt->Rt.hMonDev;
|
---|
478 | pDev->fAttached = true;
|
---|
479 | pDev->fHiSpeed = pDevExt->Rt.fIsHighSpeed;
|
---|
480 | cbOut = sizeof (*pDev);
|
---|
481 | }
|
---|
482 | }
|
---|
483 | else
|
---|
484 | {
|
---|
485 | Status = STATUS_INVALID_PARAMETER;
|
---|
486 | }
|
---|
487 |
|
---|
488 | Assert(Status != STATUS_PENDING);
|
---|
489 | VBoxDrvToolIoComplete(pIrp, Status, cbOut);
|
---|
490 | vboxUsbDdiStateRelease(pDevExt);
|
---|
491 | return Status;
|
---|
492 | }
|
---|
493 |
|
---|
494 | static NTSTATUS vboxUsbRtDispatchUsbReset(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp)
|
---|
495 | {
|
---|
496 | PIO_STACK_LOCATION pSl = IoGetCurrentIrpStackLocation(pIrp);
|
---|
497 | PFILE_OBJECT pFObj = pSl->FileObject;
|
---|
498 | PUSBSUP_GETDEV pDev = (PUSBSUP_GETDEV)pIrp->AssociatedIrp.SystemBuffer;
|
---|
499 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
500 |
|
---|
501 | do
|
---|
502 | {
|
---|
503 | if (!pFObj)
|
---|
504 | {
|
---|
505 | AssertFailed();
|
---|
506 | Status = STATUS_INVALID_PARAMETER;
|
---|
507 | break;
|
---|
508 | }
|
---|
509 |
|
---|
510 | if (!vboxUsbRtCtxIsOwner(pDevExt, pFObj))
|
---|
511 | {
|
---|
512 | AssertFailed();
|
---|
513 | Status = STATUS_ACCESS_DENIED;
|
---|
514 | break;
|
---|
515 | }
|
---|
516 |
|
---|
517 | if (pIrp->AssociatedIrp.SystemBuffer
|
---|
518 | || pSl->Parameters.DeviceIoControl.InputBufferLength
|
---|
519 | || pSl->Parameters.DeviceIoControl.OutputBufferLength)
|
---|
520 | {
|
---|
521 | AssertFailed();
|
---|
522 | Status = STATUS_INVALID_PARAMETER;
|
---|
523 | break;
|
---|
524 | }
|
---|
525 |
|
---|
526 | Status = VBoxUsbToolIoInternalCtlSendSync(pDevExt->pLowerDO, IOCTL_INTERNAL_USB_RESET_PORT, NULL, NULL);
|
---|
527 | Assert(NT_SUCCESS(Status));
|
---|
528 | } while (0);
|
---|
529 |
|
---|
530 | Assert(Status != STATUS_PENDING);
|
---|
531 | VBoxDrvToolIoComplete(pIrp, Status, 0);
|
---|
532 | vboxUsbDdiStateRelease(pDevExt);
|
---|
533 | return Status;
|
---|
534 | }
|
---|
535 |
|
---|
536 | static PUSB_CONFIGURATION_DESCRIPTOR vboxUsbRtFindConfigDesc(PVBOXUSBDEV_EXT pDevExt, uint8_t uConfiguration)
|
---|
537 | {
|
---|
538 | PUSB_CONFIGURATION_DESCRIPTOR pCfgDr = NULL;
|
---|
539 |
|
---|
540 | for (ULONG i = 0; i < VBOXUSBRT_MAX_CFGS; ++i)
|
---|
541 | {
|
---|
542 | if (pDevExt->Rt.cfgdescr[i])
|
---|
543 | {
|
---|
544 | if (pDevExt->Rt.cfgdescr[i]->bConfigurationValue == uConfiguration)
|
---|
545 | {
|
---|
546 | pCfgDr = pDevExt->Rt.cfgdescr[i];
|
---|
547 | break;
|
---|
548 | }
|
---|
549 | }
|
---|
550 | }
|
---|
551 |
|
---|
552 | return pCfgDr;
|
---|
553 | }
|
---|
554 |
|
---|
555 | static NTSTATUS vboxUsbRtSetConfig(PVBOXUSBDEV_EXT pDevExt, uint8_t uConfiguration)
|
---|
556 | {
|
---|
557 | PURB pUrb = NULL;
|
---|
558 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
559 | uint32_t i;
|
---|
560 |
|
---|
561 | if (!uConfiguration)
|
---|
562 | {
|
---|
563 | pUrb = VBoxUsbToolUrbAllocZ(URB_FUNCTION_SELECT_CONFIGURATION, sizeof (struct _URB_SELECT_CONFIGURATION));
|
---|
564 | if(!pUrb)
|
---|
565 | {
|
---|
566 | AssertMsgFailed((__FUNCTION__": VBoxUsbToolUrbAlloc failed\n"));
|
---|
567 | return STATUS_INSUFFICIENT_RESOURCES;
|
---|
568 | }
|
---|
569 |
|
---|
570 | vboxUsbRtFreeInterfaces(pDevExt, TRUE);
|
---|
571 |
|
---|
572 | pUrb->UrbSelectConfiguration.ConfigurationDescriptor = NULL;
|
---|
573 |
|
---|
574 | Status = VBoxUsbToolUrbPost(pDevExt->pLowerDO, pUrb, RT_INDEFINITE_WAIT);
|
---|
575 | if(NT_SUCCESS(Status) && USBD_SUCCESS(pUrb->UrbHeader.Status))
|
---|
576 | {
|
---|
577 | pDevExt->Rt.hConfiguration = pUrb->UrbSelectConfiguration.ConfigurationHandle;
|
---|
578 | pDevExt->Rt.uConfigValue = uConfiguration;
|
---|
579 | }
|
---|
580 | else
|
---|
581 | {
|
---|
582 | AssertMsgFailed((__FUNCTION__": VBoxUsbToolUrbPost failed Status (0x%x), usb Status (0x%x)\n", Status, pUrb->UrbHeader.Status));
|
---|
583 | }
|
---|
584 |
|
---|
585 | VBoxUsbToolUrbFree(pUrb);
|
---|
586 |
|
---|
587 | return Status;
|
---|
588 | }
|
---|
589 |
|
---|
590 | PUSB_CONFIGURATION_DESCRIPTOR pCfgDr = vboxUsbRtFindConfigDesc(pDevExt, uConfiguration);
|
---|
591 | if (!pCfgDr)
|
---|
592 | {
|
---|
593 | AssertMsgFailed((__FUNCTION__": VBoxUSBFindConfigDesc did not find cfg (%d)\n", uConfiguration));
|
---|
594 | return STATUS_INVALID_PARAMETER;
|
---|
595 | }
|
---|
596 |
|
---|
597 | PUSBD_INTERFACE_LIST_ENTRY pIfLe = (PUSBD_INTERFACE_LIST_ENTRY)vboxUsbMemAllocZ((pCfgDr->bNumInterfaces + 1) * sizeof(USBD_INTERFACE_LIST_ENTRY));
|
---|
598 | if (!pIfLe)
|
---|
599 | {
|
---|
600 | AssertMsgFailed((__FUNCTION__": vboxUsbMemAllocZ for pIfLe failed\n"));
|
---|
601 | return STATUS_INSUFFICIENT_RESOURCES;
|
---|
602 | }
|
---|
603 |
|
---|
604 | for (i = 0; i < pCfgDr->bNumInterfaces; i++)
|
---|
605 | {
|
---|
606 | pIfLe[i].InterfaceDescriptor = USBD_ParseConfigurationDescriptorEx(pCfgDr, pCfgDr, i, 0, -1, -1, -1);
|
---|
607 | if (!pIfLe[i].InterfaceDescriptor)
|
---|
608 | {
|
---|
609 | AssertMsgFailed((__FUNCTION__": interface %d not found\n", i));
|
---|
610 | Status = STATUS_INVALID_PARAMETER;
|
---|
611 | break;
|
---|
612 | }
|
---|
613 | }
|
---|
614 |
|
---|
615 | if (NT_SUCCESS(Status))
|
---|
616 | {
|
---|
617 | pUrb = USBD_CreateConfigurationRequestEx(pCfgDr, pIfLe);
|
---|
618 | if (pUrb)
|
---|
619 | {
|
---|
620 | Status = VBoxUsbToolUrbPost(pDevExt->pLowerDO, pUrb, RT_INDEFINITE_WAIT);
|
---|
621 | if (NT_SUCCESS(Status) && USBD_SUCCESS(pUrb->UrbHeader.Status))
|
---|
622 | {
|
---|
623 | vboxUsbRtFreeInterfaces(pDevExt, FALSE);
|
---|
624 |
|
---|
625 | pDevExt->Rt.hConfiguration = pUrb->UrbSelectConfiguration.ConfigurationHandle;
|
---|
626 | pDevExt->Rt.uConfigValue = uConfiguration;
|
---|
627 | pDevExt->Rt.uNumInterfaces = pCfgDr->bNumInterfaces;
|
---|
628 |
|
---|
629 | pDevExt->Rt.pVBIfaceInfo = (VBOXUSB_IFACE_INFO*)vboxUsbMemAllocZ(pDevExt->Rt.uNumInterfaces * sizeof (VBOXUSB_IFACE_INFO));
|
---|
630 | if (pDevExt->Rt.pVBIfaceInfo)
|
---|
631 | {
|
---|
632 | Assert(NT_SUCCESS(Status));
|
---|
633 | for (i = 0; i < pDevExt->Rt.uNumInterfaces; i++)
|
---|
634 | {
|
---|
635 | uint32_t uTotalIfaceInfoLength = sizeof (struct _URB_SELECT_INTERFACE) + ((pIfLe[i].Interface->NumberOfPipes > 0) ? (pIfLe[i].Interface->NumberOfPipes - 1) : 0) * sizeof(USBD_PIPE_INFORMATION);
|
---|
636 | pDevExt->Rt.pVBIfaceInfo[i].pInterfaceInfo = (PUSBD_INTERFACE_INFORMATION)vboxUsbMemAlloc(uTotalIfaceInfoLength);
|
---|
637 | if (!pDevExt->Rt.pVBIfaceInfo[i].pInterfaceInfo)
|
---|
638 | {
|
---|
639 | AssertMsgFailed((__FUNCTION__": vboxUsbMemAlloc failed\n"));
|
---|
640 | Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
641 | break;
|
---|
642 | }
|
---|
643 |
|
---|
644 | if (pIfLe[i].Interface->NumberOfPipes > 0)
|
---|
645 | {
|
---|
646 | pDevExt->Rt.pVBIfaceInfo[i].pPipeInfo = (VBOXUSB_PIPE_INFO *)vboxUsbMemAlloc(pIfLe[i].Interface->NumberOfPipes * sizeof(VBOXUSB_PIPE_INFO));
|
---|
647 | if (!pDevExt->Rt.pVBIfaceInfo[i].pPipeInfo)
|
---|
648 | {
|
---|
649 | AssertMsgFailed((__FUNCTION__": vboxUsbMemAlloc failed\n"));
|
---|
650 | Status = STATUS_NO_MEMORY;
|
---|
651 | break;
|
---|
652 | }
|
---|
653 | }
|
---|
654 | else
|
---|
655 | {
|
---|
656 | pDevExt->Rt.pVBIfaceInfo[i].pPipeInfo = NULL;
|
---|
657 | }
|
---|
658 |
|
---|
659 | *pDevExt->Rt.pVBIfaceInfo[i].pInterfaceInfo = *pIfLe[i].Interface;
|
---|
660 |
|
---|
661 | for (ULONG j = 0; j < pIfLe[i].Interface->NumberOfPipes; j++)
|
---|
662 | {
|
---|
663 | pDevExt->Rt.pVBIfaceInfo[i].pInterfaceInfo->Pipes[j] = pIfLe[i].Interface->Pipes[j];
|
---|
664 | pDevExt->Rt.pVBIfaceInfo[i].pPipeInfo[j].EndpointAddress = pIfLe[i].Interface->Pipes[j].EndpointAddress;
|
---|
665 | pDevExt->Rt.pVBIfaceInfo[i].pPipeInfo[j].NextScheduledFrame = 0;
|
---|
666 | }
|
---|
667 | }
|
---|
668 |
|
---|
669 | // if (NT_SUCCESS(Status))
|
---|
670 | // {
|
---|
671 | //
|
---|
672 | // }
|
---|
673 | }
|
---|
674 | else
|
---|
675 | {
|
---|
676 | AssertMsgFailed((__FUNCTION__": vboxUsbMemAllocZ failed\n"));
|
---|
677 | Status = STATUS_NO_MEMORY;
|
---|
678 | }
|
---|
679 | }
|
---|
680 | else
|
---|
681 | {
|
---|
682 | AssertMsgFailed((__FUNCTION__": VBoxUsbToolUrbPost failed Status (0x%x), usb Status (0x%x)\n", Status, pUrb->UrbHeader.Status));
|
---|
683 | }
|
---|
684 | ExFreePool(pUrb);
|
---|
685 | }
|
---|
686 | else
|
---|
687 | {
|
---|
688 | AssertMsgFailed((__FUNCTION__": USBD_CreateConfigurationRequestEx failed\n"));
|
---|
689 | Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
690 | }
|
---|
691 | }
|
---|
692 |
|
---|
693 | vboxUsbMemFree(pIfLe);
|
---|
694 |
|
---|
695 | return Status;
|
---|
696 | }
|
---|
697 |
|
---|
698 | static NTSTATUS vboxUsbRtDispatchUsbSetConfig(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp)
|
---|
699 | {
|
---|
700 | PIO_STACK_LOCATION pSl = IoGetCurrentIrpStackLocation(pIrp);
|
---|
701 | PFILE_OBJECT pFObj = pSl->FileObject;
|
---|
702 | PUSBSUP_SET_CONFIG pCfg = (PUSBSUP_SET_CONFIG)pIrp->AssociatedIrp.SystemBuffer;
|
---|
703 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
704 |
|
---|
705 | do
|
---|
706 | {
|
---|
707 | if (!pFObj)
|
---|
708 | {
|
---|
709 | AssertFailed();
|
---|
710 | Status = STATUS_INVALID_PARAMETER;
|
---|
711 | break;
|
---|
712 | }
|
---|
713 |
|
---|
714 | if (!vboxUsbRtCtxIsOwner(pDevExt, pFObj))
|
---|
715 | {
|
---|
716 | AssertFailed();
|
---|
717 | Status = STATUS_ACCESS_DENIED;
|
---|
718 | break;
|
---|
719 | }
|
---|
720 |
|
---|
721 | if ( !pCfg
|
---|
722 | || pSl->Parameters.DeviceIoControl.InputBufferLength != sizeof (*pCfg)
|
---|
723 | || pSl->Parameters.DeviceIoControl.OutputBufferLength != 0)
|
---|
724 | {
|
---|
725 | AssertMsgFailed((__FUNCTION__": STATUS_INVALID_PARAMETER\n"));
|
---|
726 | Status = STATUS_INVALID_PARAMETER;
|
---|
727 | break;
|
---|
728 | }
|
---|
729 |
|
---|
730 | Status = vboxUsbRtSetConfig(pDevExt, pCfg->bConfigurationValue);
|
---|
731 | } while (0);
|
---|
732 |
|
---|
733 | Assert(Status != STATUS_PENDING);
|
---|
734 | VBoxDrvToolIoComplete(pIrp, Status, 0);
|
---|
735 | vboxUsbDdiStateRelease(pDevExt);
|
---|
736 | return Status;
|
---|
737 | }
|
---|
738 |
|
---|
739 | static NTSTATUS vboxUsbRtSetInterface(PVBOXUSBDEV_EXT pDevExt, uint32_t InterfaceNumber, int AlternateSetting)
|
---|
740 | {
|
---|
741 | if (!pDevExt->Rt.uConfigValue)
|
---|
742 | {
|
---|
743 | AssertMsgFailed((__FUNCTION__": Can't select an interface without an active configuration\n"));
|
---|
744 | return STATUS_INVALID_PARAMETER;
|
---|
745 | }
|
---|
746 |
|
---|
747 | if (InterfaceNumber >= pDevExt->Rt.uNumInterfaces)
|
---|
748 | {
|
---|
749 | AssertMsgFailed((__FUNCTION__": InterfaceNumber %d too high!!\n", InterfaceNumber));
|
---|
750 | return STATUS_INVALID_PARAMETER;
|
---|
751 | }
|
---|
752 |
|
---|
753 | PUSB_CONFIGURATION_DESCRIPTOR pCfgDr = vboxUsbRtFindConfigDesc(pDevExt, pDevExt->Rt.uConfigValue);
|
---|
754 | if (!pCfgDr)
|
---|
755 | {
|
---|
756 | AssertMsgFailed((__FUNCTION__": configuration %d not found!!\n", pDevExt->Rt.uConfigValue));
|
---|
757 | return STATUS_INVALID_PARAMETER;
|
---|
758 | }
|
---|
759 |
|
---|
760 | PUSB_INTERFACE_DESCRIPTOR pIfDr = USBD_ParseConfigurationDescriptorEx(pCfgDr, pCfgDr, InterfaceNumber, AlternateSetting, -1, -1, -1);
|
---|
761 | if (!pIfDr)
|
---|
762 | {
|
---|
763 | AssertMsgFailed((__FUNCTION__": invalid interface %d or alternate setting %d\n", InterfaceNumber, AlternateSetting));
|
---|
764 | return STATUS_UNSUCCESSFUL;
|
---|
765 | }
|
---|
766 |
|
---|
767 | USHORT uUrbSize = GET_SELECT_INTERFACE_REQUEST_SIZE(pIfDr->bNumEndpoints);
|
---|
768 | ULONG uTotalIfaceInfoLength = GET_USBD_INTERFACE_SIZE(pIfDr->bNumEndpoints);
|
---|
769 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
770 | PURB pUrb = VBoxUsbToolUrbAllocZ(0, uUrbSize);
|
---|
771 | if (!pUrb)
|
---|
772 | {
|
---|
773 | AssertMsgFailed((__FUNCTION__": VBoxUsbToolUrbAlloc failed\n"));
|
---|
774 | return STATUS_NO_MEMORY;
|
---|
775 | }
|
---|
776 |
|
---|
777 | /*
|
---|
778 | * Free old interface and pipe info, allocate new again
|
---|
779 | */
|
---|
780 | if (pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo)
|
---|
781 | {
|
---|
782 | /* Clear pipes associated with the interface, else Windows may hang. */
|
---|
783 | for(ULONG i = 0; i < pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo->NumberOfPipes; i++)
|
---|
784 | {
|
---|
785 | VBoxUsbToolPipeClear(pDevExt->pLowerDO, pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo->Pipes[i].PipeHandle, FALSE);
|
---|
786 | }
|
---|
787 | vboxUsbMemFree(pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo);
|
---|
788 | }
|
---|
789 |
|
---|
790 | if (pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo)
|
---|
791 | {
|
---|
792 | vboxUsbMemFree(pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo);
|
---|
793 | }
|
---|
794 |
|
---|
795 | pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo = (PUSBD_INTERFACE_INFORMATION)vboxUsbMemAlloc(uTotalIfaceInfoLength);
|
---|
796 | if (pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo)
|
---|
797 | {
|
---|
798 | if (pIfDr->bNumEndpoints > 0)
|
---|
799 | {
|
---|
800 | pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo = (VBOXUSB_PIPE_INFO*)vboxUsbMemAlloc(pIfDr->bNumEndpoints * sizeof(VBOXUSB_PIPE_INFO));
|
---|
801 | if (!pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo)
|
---|
802 | {
|
---|
803 | AssertMsgFailed(("VBoxUSBSetInterface: ExAllocatePool failed!\n"));
|
---|
804 | Status = STATUS_NO_MEMORY;
|
---|
805 | }
|
---|
806 | }
|
---|
807 | else
|
---|
808 | {
|
---|
809 | pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo = NULL;
|
---|
810 | }
|
---|
811 |
|
---|
812 | if (NT_SUCCESS(Status))
|
---|
813 | {
|
---|
814 | UsbBuildSelectInterfaceRequest(pUrb, uUrbSize, pDevExt->Rt.hConfiguration, InterfaceNumber, AlternateSetting);
|
---|
815 | pUrb->UrbSelectInterface.Interface.Length = GET_USBD_INTERFACE_SIZE(pIfDr->bNumEndpoints);
|
---|
816 |
|
---|
817 | Status = VBoxUsbToolUrbPost(pDevExt->pLowerDO, pUrb, RT_INDEFINITE_WAIT);
|
---|
818 | if (NT_SUCCESS(Status) && USBD_SUCCESS(pUrb->UrbHeader.Status))
|
---|
819 | {
|
---|
820 | USBD_INTERFACE_INFORMATION *pIfInfo = &pUrb->UrbSelectInterface.Interface;
|
---|
821 | memcpy(pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo, pIfInfo, GET_USBD_INTERFACE_SIZE(pIfDr->bNumEndpoints));
|
---|
822 |
|
---|
823 | Assert(pIfInfo->NumberOfPipes == pIfDr->bNumEndpoints);
|
---|
824 | for(ULONG i = 0; i < pIfInfo->NumberOfPipes; i++)
|
---|
825 | {
|
---|
826 | pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pInterfaceInfo->Pipes[i] = pIfInfo->Pipes[i];
|
---|
827 | pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo[i].EndpointAddress = pIfInfo->Pipes[i].EndpointAddress;
|
---|
828 | pDevExt->Rt.pVBIfaceInfo[InterfaceNumber].pPipeInfo[i].NextScheduledFrame = 0;
|
---|
829 | }
|
---|
830 | }
|
---|
831 | else
|
---|
832 | {
|
---|
833 | AssertMsgFailed((__FUNCTION__": VBoxUsbToolUrbPost failed Status (0x%x) usb Status (0x%x)\n", Status, pUrb->UrbHeader.Status));
|
---|
834 | }
|
---|
835 | }
|
---|
836 |
|
---|
837 | }
|
---|
838 | else
|
---|
839 | {
|
---|
840 | AssertMsgFailed(("VBoxUSBSetInterface: ExAllocatePool failed!\n"));
|
---|
841 | Status = STATUS_NO_MEMORY;
|
---|
842 | }
|
---|
843 |
|
---|
844 | VBoxUsbToolUrbFree(pUrb);
|
---|
845 |
|
---|
846 | return Status;
|
---|
847 | }
|
---|
848 |
|
---|
849 | static NTSTATUS vboxUsbRtDispatchUsbSelectInterface(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp)
|
---|
850 | {
|
---|
851 | PIO_STACK_LOCATION pSl = IoGetCurrentIrpStackLocation(pIrp);
|
---|
852 | PFILE_OBJECT pFObj = pSl->FileObject;
|
---|
853 | PUSBSUP_SELECT_INTERFACE pIf = (PUSBSUP_SELECT_INTERFACE)pIrp->AssociatedIrp.SystemBuffer;
|
---|
854 | NTSTATUS Status;
|
---|
855 |
|
---|
856 | do
|
---|
857 | {
|
---|
858 | if (!pFObj)
|
---|
859 | {
|
---|
860 | AssertFailed();
|
---|
861 | Status = STATUS_INVALID_PARAMETER;
|
---|
862 | break;
|
---|
863 | }
|
---|
864 |
|
---|
865 | if (!vboxUsbRtCtxIsOwner(pDevExt, pFObj))
|
---|
866 | {
|
---|
867 | AssertFailed();
|
---|
868 | Status = STATUS_ACCESS_DENIED;
|
---|
869 | break;
|
---|
870 | }
|
---|
871 |
|
---|
872 | if ( !pIf
|
---|
873 | || pSl->Parameters.DeviceIoControl.InputBufferLength != sizeof (*pIf)
|
---|
874 | || pSl->Parameters.DeviceIoControl.OutputBufferLength != 0)
|
---|
875 | {
|
---|
876 | AssertMsgFailed((__FUNCTION__": STATUS_INVALID_PARAMETER\n"));
|
---|
877 | Status = STATUS_INVALID_PARAMETER;
|
---|
878 | break;
|
---|
879 | }
|
---|
880 |
|
---|
881 | Status = vboxUsbRtSetInterface(pDevExt, pIf->bInterfaceNumber, pIf->bAlternateSetting);
|
---|
882 | } while (0);
|
---|
883 |
|
---|
884 | Assert(Status != STATUS_PENDING);
|
---|
885 | VBoxDrvToolIoComplete(pIrp, Status, 0);
|
---|
886 | vboxUsbDdiStateRelease(pDevExt);
|
---|
887 | return Status;
|
---|
888 | }
|
---|
889 |
|
---|
890 | static HANDLE vboxUsbRtGetPipeHandle(PVBOXUSBDEV_EXT pDevExt, uint32_t EndPointAddress)
|
---|
891 | {
|
---|
892 | for (ULONG i = 0; i < pDevExt->Rt.uNumInterfaces; i++)
|
---|
893 | {
|
---|
894 | for (ULONG j = 0; j < pDevExt->Rt.pVBIfaceInfo[i].pInterfaceInfo->NumberOfPipes; j++)
|
---|
895 | {
|
---|
896 | /* Note that bit 7 determines pipe direction, but is still significant
|
---|
897 | * because endpoints may be numbered like 0x01, 0x81, 0x02, 0x82 etc.
|
---|
898 | */
|
---|
899 | if (pDevExt->Rt.pVBIfaceInfo[i].pInterfaceInfo->Pipes[j].EndpointAddress == EndPointAddress)
|
---|
900 | return pDevExt->Rt.pVBIfaceInfo[i].pInterfaceInfo->Pipes[j].PipeHandle;
|
---|
901 | }
|
---|
902 | }
|
---|
903 | return 0;
|
---|
904 | }
|
---|
905 |
|
---|
906 | static VBOXUSB_PIPE_INFO* vboxUsbRtGetPipeInfo(PVBOXUSBDEV_EXT pDevExt, uint32_t EndPointAddress)
|
---|
907 | {
|
---|
908 | for (ULONG i = 0; i < pDevExt->Rt.uNumInterfaces; i++)
|
---|
909 | {
|
---|
910 | for (ULONG j = 0; j < pDevExt->Rt.pVBIfaceInfo[i].pInterfaceInfo->NumberOfPipes; j++)
|
---|
911 | {
|
---|
912 | if (pDevExt->Rt.pVBIfaceInfo[i].pPipeInfo[j].EndpointAddress == EndPointAddress)
|
---|
913 | return &pDevExt->Rt.pVBIfaceInfo[i].pPipeInfo[j];
|
---|
914 | }
|
---|
915 | }
|
---|
916 | return NULL;
|
---|
917 | }
|
---|
918 |
|
---|
919 |
|
---|
920 |
|
---|
921 | static NTSTATUS vboxUsbRtClearEndpoint(PVBOXUSBDEV_EXT pDevExt, uint32_t EndPointAddress, bool fReset)
|
---|
922 | {
|
---|
923 | NTSTATUS Status = VBoxUsbToolPipeClear(pDevExt->pLowerDO, vboxUsbRtGetPipeHandle(pDevExt, EndPointAddress), fReset);
|
---|
924 | if (!NT_SUCCESS(Status))
|
---|
925 | {
|
---|
926 | AssertMsgFailed((__FUNCTION__": VBoxUsbToolPipeClear failed Status (0x%x)\n", Status));
|
---|
927 | }
|
---|
928 |
|
---|
929 | return Status;
|
---|
930 | }
|
---|
931 |
|
---|
932 | static NTSTATUS vboxUsbRtDispatchUsbClearEndpoint(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp)
|
---|
933 | {
|
---|
934 | PIO_STACK_LOCATION pSl = IoGetCurrentIrpStackLocation(pIrp);
|
---|
935 | PFILE_OBJECT pFObj = pSl->FileObject;
|
---|
936 | PUSBSUP_CLEAR_ENDPOINT pCe = (PUSBSUP_CLEAR_ENDPOINT)pIrp->AssociatedIrp.SystemBuffer;
|
---|
937 | NTSTATUS Status;
|
---|
938 |
|
---|
939 | do
|
---|
940 | {
|
---|
941 | if (!pFObj)
|
---|
942 | {
|
---|
943 | AssertFailed();
|
---|
944 | Status = STATUS_INVALID_PARAMETER;
|
---|
945 | break;
|
---|
946 | }
|
---|
947 |
|
---|
948 | if (!vboxUsbRtCtxIsOwner(pDevExt, pFObj))
|
---|
949 | {
|
---|
950 | AssertFailed();
|
---|
951 | Status = STATUS_ACCESS_DENIED;
|
---|
952 | break;
|
---|
953 | }
|
---|
954 |
|
---|
955 | if ( !pCe
|
---|
956 | || pSl->Parameters.DeviceIoControl.InputBufferLength != sizeof (*pCe)
|
---|
957 | || pSl->Parameters.DeviceIoControl.OutputBufferLength != 0)
|
---|
958 | {
|
---|
959 | AssertMsgFailed((__FUNCTION__": STATUS_INVALID_PARAMETER\n"));
|
---|
960 | Status = STATUS_INVALID_PARAMETER;
|
---|
961 | break;
|
---|
962 | }
|
---|
963 |
|
---|
964 | Status = vboxUsbRtClearEndpoint(pDevExt, pCe->bEndpoint, TRUE);
|
---|
965 | } while (0);
|
---|
966 |
|
---|
967 | Assert(Status != STATUS_PENDING);
|
---|
968 | VBoxDrvToolIoComplete(pIrp, Status, 0);
|
---|
969 | vboxUsbDdiStateRelease(pDevExt);
|
---|
970 | return Status;
|
---|
971 | }
|
---|
972 |
|
---|
973 | static NTSTATUS vboxUsbRtDispatchUsbAbortEndpoint(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp)
|
---|
974 | {
|
---|
975 | PIO_STACK_LOCATION pSl = IoGetCurrentIrpStackLocation(pIrp);
|
---|
976 | PFILE_OBJECT pFObj = pSl->FileObject;
|
---|
977 | PUSBSUP_CLEAR_ENDPOINT pCe = (PUSBSUP_CLEAR_ENDPOINT)pIrp->AssociatedIrp.SystemBuffer;
|
---|
978 | NTSTATUS Status;
|
---|
979 |
|
---|
980 | do
|
---|
981 | {
|
---|
982 | if (!pFObj)
|
---|
983 | {
|
---|
984 | AssertFailed();
|
---|
985 | Status = STATUS_INVALID_PARAMETER;
|
---|
986 | break;
|
---|
987 | }
|
---|
988 |
|
---|
989 | if (!vboxUsbRtCtxIsOwner(pDevExt, pFObj))
|
---|
990 | {
|
---|
991 | AssertFailed();
|
---|
992 | Status = STATUS_ACCESS_DENIED;
|
---|
993 | break;
|
---|
994 | }
|
---|
995 |
|
---|
996 | if ( !pCe
|
---|
997 | || pSl->Parameters.DeviceIoControl.InputBufferLength != sizeof (*pCe)
|
---|
998 | || pSl->Parameters.DeviceIoControl.OutputBufferLength != 0)
|
---|
999 | {
|
---|
1000 | AssertMsgFailed((__FUNCTION__": STATUS_INVALID_PARAMETER\n"));
|
---|
1001 | Status = STATUS_INVALID_PARAMETER;
|
---|
1002 | break;
|
---|
1003 | }
|
---|
1004 |
|
---|
1005 | Status = vboxUsbRtClearEndpoint(pDevExt, pCe->bEndpoint, FALSE);
|
---|
1006 | } while (0);
|
---|
1007 |
|
---|
1008 | Assert(Status != STATUS_PENDING);
|
---|
1009 | VBoxDrvToolIoComplete(pIrp, Status, 0);
|
---|
1010 | vboxUsbDdiStateRelease(pDevExt);
|
---|
1011 | return Status;
|
---|
1012 | }
|
---|
1013 |
|
---|
1014 | static NTSTATUS vboxUsbRtUrbSendCompletion(PDEVICE_OBJECT pDevObj, IRP *pIrp, void *pvContext)
|
---|
1015 | {
|
---|
1016 | if (!pvContext)
|
---|
1017 | {
|
---|
1018 | AssertMsgFailed((__FUNCTION__": context is NULL\n"));
|
---|
1019 | pIrp->IoStatus.Information = 0;
|
---|
1020 | return STATUS_CONTINUE_COMPLETION;
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 | PVBOXUSB_URB_CONTEXT pContext = (PVBOXUSB_URB_CONTEXT)pvContext;
|
---|
1024 |
|
---|
1025 | if (pContext->ulMagic != VBOXUSB_MAGIC)
|
---|
1026 | {
|
---|
1027 | AssertMsgFailed((__FUNCTION__": Invalid context magic\n"));
|
---|
1028 | pIrp->IoStatus.Information = 0;
|
---|
1029 | return STATUS_CONTINUE_COMPLETION;
|
---|
1030 | }
|
---|
1031 |
|
---|
1032 | PURB pUrb = pContext->pUrb;
|
---|
1033 | PMDL pMdlBuf = pContext->pMdlBuf;
|
---|
1034 | PUSBSUP_URB pUrbInfo = (PUSBSUP_URB)pContext->pOut;
|
---|
1035 | PVBOXUSBDEV_EXT pDevExt = pContext->pDevExt;
|
---|
1036 |
|
---|
1037 | if (!pUrb || !pMdlBuf || !pUrbInfo | !pDevExt)
|
---|
1038 | {
|
---|
1039 | AssertMsgFailed((__FUNCTION__": Invalid args\n"));
|
---|
1040 | if (pDevExt)
|
---|
1041 | vboxUsbDdiStateRelease(pDevExt);
|
---|
1042 | pIrp->IoStatus.Information = 0;
|
---|
1043 | return STATUS_CONTINUE_COMPLETION;
|
---|
1044 | }
|
---|
1045 |
|
---|
1046 | NTSTATUS Status = pIrp->IoStatus.Status;
|
---|
1047 | if (Status == STATUS_SUCCESS)
|
---|
1048 | {
|
---|
1049 | switch(pUrb->UrbHeader.Status)
|
---|
1050 | {
|
---|
1051 | case USBD_STATUS_CRC:
|
---|
1052 | pUrbInfo->error = USBSUP_XFER_CRC;
|
---|
1053 | break;
|
---|
1054 | case USBD_STATUS_SUCCESS:
|
---|
1055 | pUrbInfo->error = USBSUP_XFER_OK;
|
---|
1056 | break;
|
---|
1057 | case USBD_STATUS_STALL_PID:
|
---|
1058 | pUrbInfo->error = USBSUP_XFER_STALL;
|
---|
1059 | break;
|
---|
1060 | case USBD_STATUS_INVALID_URB_FUNCTION:
|
---|
1061 | case USBD_STATUS_INVALID_PARAMETER:
|
---|
1062 | AssertMsgFailed((__FUNCTION__": sw error, urb Status (0x%x)\n", pUrb->UrbHeader.Status));
|
---|
1063 | case USBD_STATUS_DEV_NOT_RESPONDING:
|
---|
1064 | default:
|
---|
1065 | pUrbInfo->error = USBSUP_XFER_DNR;
|
---|
1066 | break;
|
---|
1067 | }
|
---|
1068 |
|
---|
1069 | switch(pContext->ulTransferType)
|
---|
1070 | {
|
---|
1071 | case USBSUP_TRANSFER_TYPE_CTRL:
|
---|
1072 | case USBSUP_TRANSFER_TYPE_MSG:
|
---|
1073 | pUrbInfo->len = pUrb->UrbControlTransfer.TransferBufferLength;
|
---|
1074 | if (pContext->ulTransferType == USBSUP_TRANSFER_TYPE_MSG)
|
---|
1075 | {
|
---|
1076 | /* QUSB_TRANSFER_TYPE_MSG is a control transfer, but it is special
|
---|
1077 | * the first 8 bytes of the buffer is the setup packet so the real
|
---|
1078 | * data length is therefore urb->len - 8
|
---|
1079 | */
|
---|
1080 | pUrbInfo->len += sizeof (pUrb->UrbControlTransfer.SetupPacket);
|
---|
1081 | }
|
---|
1082 | break;
|
---|
1083 | case USBSUP_TRANSFER_TYPE_ISOC:
|
---|
1084 | pUrbInfo->len = pUrb->UrbIsochronousTransfer.TransferBufferLength;
|
---|
1085 | break;
|
---|
1086 | case USBSUP_TRANSFER_TYPE_BULK:
|
---|
1087 | case USBSUP_TRANSFER_TYPE_INTR:
|
---|
1088 | if (pUrbInfo->dir == USBSUP_DIRECTION_IN && pUrbInfo->error == USBSUP_XFER_OK
|
---|
1089 | && !(pUrbInfo->flags & USBSUP_FLAG_SHORT_OK)
|
---|
1090 | && pUrbInfo->len > pUrb->UrbBulkOrInterruptTransfer.TransferBufferLength
|
---|
1091 | )
|
---|
1092 | {
|
---|
1093 | /* If we don't use the USBD_SHORT_TRANSFER_OK flag, the returned buffer lengths are
|
---|
1094 | * wrong for short transfers (always a multiple of max packet size?). So we just figure
|
---|
1095 | * out if this was a data underrun on our own.
|
---|
1096 | */
|
---|
1097 | pUrbInfo->error = USBSUP_XFER_UNDERRUN;
|
---|
1098 | }
|
---|
1099 | pUrbInfo->len = pUrb->UrbBulkOrInterruptTransfer.TransferBufferLength;
|
---|
1100 | break;
|
---|
1101 | default:
|
---|
1102 | break;
|
---|
1103 | }
|
---|
1104 | }
|
---|
1105 | else
|
---|
1106 | {
|
---|
1107 | pUrbInfo->len = 0;
|
---|
1108 |
|
---|
1109 | Log((__FUNCTION__": URB failed Status (0x%x) urb Status (0x%x)\n", Status, pUrb->UrbHeader.Status));
|
---|
1110 | #ifdef DEBUG
|
---|
1111 | switch(pContext->ulTransferType)
|
---|
1112 | {
|
---|
1113 | case USBSUP_TRANSFER_TYPE_CTRL:
|
---|
1114 | case USBSUP_TRANSFER_TYPE_MSG:
|
---|
1115 | LogRel(("Ctrl/Msg length=%d\n", pUrb->UrbControlTransfer.TransferBufferLength));
|
---|
1116 | break;
|
---|
1117 | case USBSUP_TRANSFER_TYPE_ISOC:
|
---|
1118 | LogRel(("ISOC length=%d\n", pUrb->UrbIsochronousTransfer.TransferBufferLength));
|
---|
1119 | break;
|
---|
1120 | case USBSUP_TRANSFER_TYPE_BULK:
|
---|
1121 | case USBSUP_TRANSFER_TYPE_INTR:
|
---|
1122 | LogRel(("BULK/INTR length=%d\n", pUrb->UrbBulkOrInterruptTransfer.TransferBufferLength));
|
---|
1123 | break;
|
---|
1124 | }
|
---|
1125 | #endif
|
---|
1126 | switch(pUrb->UrbHeader.Status)
|
---|
1127 | {
|
---|
1128 | case USBD_STATUS_CRC:
|
---|
1129 | pUrbInfo->error = USBSUP_XFER_CRC;
|
---|
1130 | Status = STATUS_SUCCESS;
|
---|
1131 | break;
|
---|
1132 | case USBD_STATUS_STALL_PID:
|
---|
1133 | pUrbInfo->error = USBSUP_XFER_STALL;
|
---|
1134 | Status = STATUS_SUCCESS;
|
---|
1135 | break;
|
---|
1136 | case USBD_STATUS_DEV_NOT_RESPONDING:
|
---|
1137 | case USBD_STATUS_DEVICE_GONE:
|
---|
1138 | pUrbInfo->error = USBSUP_XFER_DNR;
|
---|
1139 | Status = STATUS_SUCCESS;
|
---|
1140 | break;
|
---|
1141 | case ((USBD_STATUS)0xC0010000L): // USBD_STATUS_CANCELED - too bad usbdi.h and usb.h aren't consistent!
|
---|
1142 | // TODO: What the heck are we really supposed to do here?
|
---|
1143 | pUrbInfo->error = USBSUP_XFER_STALL;
|
---|
1144 | Status = STATUS_SUCCESS;
|
---|
1145 | break;
|
---|
1146 | case USBD_STATUS_BAD_START_FRAME: // This one really shouldn't happen
|
---|
1147 | case USBD_STATUS_ISOCH_REQUEST_FAILED:
|
---|
1148 | pUrbInfo->error = USBSUP_XFER_NAC;
|
---|
1149 | Status = STATUS_SUCCESS;
|
---|
1150 | break;
|
---|
1151 | default:
|
---|
1152 | AssertMsgFailed((__FUNCTION__": err Status (0x%x) (0x%x)\n", Status, pUrb->UrbHeader.Status));
|
---|
1153 | pUrbInfo->error = USBSUP_XFER_DNR;
|
---|
1154 | Status = STATUS_SUCCESS;
|
---|
1155 | break;
|
---|
1156 | }
|
---|
1157 | }
|
---|
1158 | // For isochronous transfers, always update the individual packets
|
---|
1159 | if (pContext->ulTransferType == USBSUP_TRANSFER_TYPE_ISOC)
|
---|
1160 | {
|
---|
1161 | Assert(pUrbInfo->numIsoPkts == pUrb->UrbIsochronousTransfer.NumberOfPackets);
|
---|
1162 | for (ULONG i = 0; i < pUrbInfo->numIsoPkts; ++i)
|
---|
1163 | {
|
---|
1164 | Assert(pUrbInfo->aIsoPkts[i].off == pUrb->UrbIsochronousTransfer.IsoPacket[i].Offset);
|
---|
1165 | pUrbInfo->aIsoPkts[i].cb = (uint16_t)pUrb->UrbIsochronousTransfer.IsoPacket[i].Length;
|
---|
1166 | switch (pUrb->UrbIsochronousTransfer.IsoPacket[i].Status)
|
---|
1167 | {
|
---|
1168 | case USBD_STATUS_SUCCESS:
|
---|
1169 | pUrbInfo->aIsoPkts[i].stat = USBSUP_XFER_OK;
|
---|
1170 | break;
|
---|
1171 | case USBD_STATUS_NOT_ACCESSED:
|
---|
1172 | pUrbInfo->aIsoPkts[i].stat = USBSUP_XFER_NAC;
|
---|
1173 | break;
|
---|
1174 | default:
|
---|
1175 | pUrbInfo->aIsoPkts[i].stat = USBSUP_XFER_STALL;
|
---|
1176 | break;
|
---|
1177 | }
|
---|
1178 | }
|
---|
1179 | }
|
---|
1180 |
|
---|
1181 | MmUnlockPages(pMdlBuf);
|
---|
1182 | IoFreeMdl(pMdlBuf);
|
---|
1183 |
|
---|
1184 | vboxUsbMemFree(pContext);
|
---|
1185 |
|
---|
1186 | vboxUsbDdiStateRelease(pDevExt);
|
---|
1187 |
|
---|
1188 | Assert(pIrp->IoStatus.Status != STATUS_IO_TIMEOUT);
|
---|
1189 | pIrp->IoStatus.Information = sizeof(*pUrbInfo);
|
---|
1190 | pIrp->IoStatus.Status = Status;
|
---|
1191 | return STATUS_CONTINUE_COMPLETION;
|
---|
1192 | }
|
---|
1193 |
|
---|
1194 | static NTSTATUS vboxUsbRtUrbSend(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp, PUSBSUP_URB pUrbInfo)
|
---|
1195 | {
|
---|
1196 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
1197 | PVBOXUSB_URB_CONTEXT pContext = NULL;
|
---|
1198 | PMDL pMdlBuf = NULL;
|
---|
1199 | ULONG cbUrb;
|
---|
1200 |
|
---|
1201 | Assert(pUrbInfo);
|
---|
1202 | if (pUrbInfo->type == USBSUP_TRANSFER_TYPE_ISOC)
|
---|
1203 | {
|
---|
1204 | Assert(pUrbInfo->numIsoPkts <= 8);
|
---|
1205 | cbUrb = GET_ISO_URB_SIZE(pUrbInfo->numIsoPkts);
|
---|
1206 | }
|
---|
1207 | else
|
---|
1208 | cbUrb = sizeof (URB);
|
---|
1209 |
|
---|
1210 | do
|
---|
1211 | {
|
---|
1212 | pContext = (PVBOXUSB_URB_CONTEXT)vboxUsbMemAllocZ(cbUrb + sizeof (VBOXUSB_URB_CONTEXT));
|
---|
1213 | if (!pContext)
|
---|
1214 | {
|
---|
1215 | AssertMsgFailed((__FUNCTION__": vboxUsbMemAlloc failed\n"));
|
---|
1216 | Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
1217 | break;
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 | PURB pUrb = (PURB)(pContext + 1);
|
---|
1221 | HANDLE hPipe = NULL;
|
---|
1222 | if (pUrbInfo->ep)
|
---|
1223 | {
|
---|
1224 | hPipe = vboxUsbRtGetPipeHandle(pDevExt, pUrbInfo->ep | ((pUrbInfo->dir == USBSUP_DIRECTION_IN) ? 0x80 : 0x00));
|
---|
1225 | if (!hPipe)
|
---|
1226 | {
|
---|
1227 | AssertMsgFailed((__FUNCTION__": vboxUsbRtGetPipeHandle failed for endpoint (0x%x)\n", pUrbInfo->ep));
|
---|
1228 | Status = STATUS_INVALID_PARAMETER;
|
---|
1229 | break;
|
---|
1230 | }
|
---|
1231 | }
|
---|
1232 |
|
---|
1233 | pMdlBuf = IoAllocateMdl(pUrbInfo->buf, (ULONG)pUrbInfo->len, FALSE, FALSE, NULL);
|
---|
1234 | if (!pMdlBuf)
|
---|
1235 | {
|
---|
1236 | AssertMsgFailed((__FUNCTION__": IoAllocateMdl failed for buffer (0x%p) length (%d)\n", pUrbInfo->buf, pUrbInfo->len));
|
---|
1237 | Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
1238 | break;
|
---|
1239 | }
|
---|
1240 |
|
---|
1241 | __try
|
---|
1242 | {
|
---|
1243 | MmProbeAndLockPages(pMdlBuf, KernelMode, IoModifyAccess);
|
---|
1244 | }
|
---|
1245 | __except(EXCEPTION_EXECUTE_HANDLER)
|
---|
1246 | {
|
---|
1247 | Status = GetExceptionCode();
|
---|
1248 | IoFreeMdl(pMdlBuf);
|
---|
1249 | pMdlBuf = NULL;
|
---|
1250 | AssertMsgFailed((__FUNCTION__": Exception Code (0x%x)\n", Status));
|
---|
1251 | break;
|
---|
1252 | }
|
---|
1253 |
|
---|
1254 | /* For some reason, passing a MDL in the URB does not work reliably. Notably
|
---|
1255 | * the iPhone when used with iTunes fails.
|
---|
1256 | */
|
---|
1257 | PVOID pBuffer = MmGetSystemAddressForMdlSafe(pMdlBuf, NormalPagePriority);
|
---|
1258 | if (!pBuffer)
|
---|
1259 | {
|
---|
1260 | AssertMsgFailed((__FUNCTION__": MmGetSystemAddressForMdlSafe failed\n"));
|
---|
1261 | Status = STATUS_INSUFFICIENT_RESOURCES;
|
---|
1262 | break;
|
---|
1263 | }
|
---|
1264 |
|
---|
1265 | switch (pUrbInfo->type)
|
---|
1266 | {
|
---|
1267 | case USBSUP_TRANSFER_TYPE_CTRL:
|
---|
1268 | case USBSUP_TRANSFER_TYPE_MSG:
|
---|
1269 | {
|
---|
1270 | pUrb->UrbHeader.Function = URB_FUNCTION_CONTROL_TRANSFER;
|
---|
1271 | pUrb->UrbHeader.Length = sizeof (struct _URB_CONTROL_TRANSFER);
|
---|
1272 | pUrb->UrbControlTransfer.PipeHandle = hPipe;
|
---|
1273 | pUrb->UrbControlTransfer.TransferBufferLength = (ULONG)pUrbInfo->len;
|
---|
1274 | pUrb->UrbControlTransfer.TransferFlags = ((pUrbInfo->dir == USBSUP_DIRECTION_IN) ? USBD_TRANSFER_DIRECTION_IN : USBD_TRANSFER_DIRECTION_OUT);
|
---|
1275 | pUrb->UrbControlTransfer.UrbLink = 0;
|
---|
1276 |
|
---|
1277 | if (!hPipe)
|
---|
1278 | pUrb->UrbControlTransfer.TransferFlags |= USBD_DEFAULT_PIPE_TRANSFER;
|
---|
1279 |
|
---|
1280 | if (pUrbInfo->type == USBSUP_TRANSFER_TYPE_MSG)
|
---|
1281 | {
|
---|
1282 | /* QUSB_TRANSFER_TYPE_MSG is a control transfer, but it is special
|
---|
1283 | * the first 8 bytes of the buffer is the setup packet so the real
|
---|
1284 | * data length is therefore pUrb->len - 8
|
---|
1285 | */
|
---|
1286 | PVBOXUSB_SETUP pSetup = (PVBOXUSB_SETUP)pUrb->UrbControlTransfer.SetupPacket;
|
---|
1287 | memcpy(pUrb->UrbControlTransfer.SetupPacket, pBuffer, min(sizeof (pUrb->UrbControlTransfer.SetupPacket), pUrbInfo->len));
|
---|
1288 |
|
---|
1289 | if (pUrb->UrbControlTransfer.TransferBufferLength <= sizeof (pUrb->UrbControlTransfer.SetupPacket))
|
---|
1290 | pUrb->UrbControlTransfer.TransferBufferLength = 0;
|
---|
1291 | else
|
---|
1292 | pUrb->UrbControlTransfer.TransferBufferLength -= sizeof (pUrb->UrbControlTransfer.SetupPacket);
|
---|
1293 |
|
---|
1294 | pUrb->UrbControlTransfer.TransferBuffer = (uint8_t *)pBuffer + sizeof(pUrb->UrbControlTransfer.SetupPacket);
|
---|
1295 | pUrb->UrbControlTransfer.TransferBufferMDL = 0;
|
---|
1296 | pUrb->UrbControlTransfer.TransferFlags |= USBD_SHORT_TRANSFER_OK;
|
---|
1297 | }
|
---|
1298 | else
|
---|
1299 | {
|
---|
1300 | pUrb->UrbControlTransfer.TransferBuffer = 0;
|
---|
1301 | pUrb->UrbControlTransfer.TransferBufferMDL = pMdlBuf;
|
---|
1302 | }
|
---|
1303 | break;
|
---|
1304 | }
|
---|
1305 | case USBSUP_TRANSFER_TYPE_ISOC:
|
---|
1306 | {
|
---|
1307 | Assert(pUrbInfo->dir == USBSUP_DIRECTION_IN || pUrbInfo->type == USBSUP_TRANSFER_TYPE_BULK);
|
---|
1308 | Assert(hPipe);
|
---|
1309 | VBOXUSB_PIPE_INFO *pPipeInfo = vboxUsbRtGetPipeInfo(pDevExt, pUrbInfo->ep | ((pUrbInfo->dir == USBSUP_DIRECTION_IN) ? 0x80 : 0x00));
|
---|
1310 | if (pPipeInfo == NULL)
|
---|
1311 | {
|
---|
1312 | /* Can happen if the isoc request comes in too early or late. */
|
---|
1313 | AssertMsgFailed((__FUNCTION__": pPipeInfo not found\n"));
|
---|
1314 | Status = STATUS_INVALID_PARAMETER;
|
---|
1315 | break;
|
---|
1316 | }
|
---|
1317 |
|
---|
1318 | pUrb->UrbHeader.Function = URB_FUNCTION_ISOCH_TRANSFER;
|
---|
1319 | pUrb->UrbHeader.Length = (USHORT)cbUrb;
|
---|
1320 | pUrb->UrbIsochronousTransfer.PipeHandle = hPipe;
|
---|
1321 | pUrb->UrbIsochronousTransfer.TransferBufferLength = (ULONG)pUrbInfo->len;
|
---|
1322 | pUrb->UrbIsochronousTransfer.TransferBufferMDL = 0;
|
---|
1323 | pUrb->UrbIsochronousTransfer.TransferBuffer = pBuffer;
|
---|
1324 | pUrb->UrbIsochronousTransfer.TransferFlags = ((pUrbInfo->dir == USBSUP_DIRECTION_IN) ? USBD_TRANSFER_DIRECTION_IN : USBD_TRANSFER_DIRECTION_OUT);
|
---|
1325 | pUrb->UrbIsochronousTransfer.TransferFlags |= USBD_SHORT_TRANSFER_OK; // May be implied already
|
---|
1326 | pUrb->UrbIsochronousTransfer.NumberOfPackets = pUrbInfo->numIsoPkts;
|
---|
1327 | pUrb->UrbIsochronousTransfer.ErrorCount = 0;
|
---|
1328 | pUrb->UrbIsochronousTransfer.UrbLink = 0;
|
---|
1329 |
|
---|
1330 | Assert(pUrbInfo->numIsoPkts == pUrb->UrbIsochronousTransfer.NumberOfPackets);
|
---|
1331 | for (ULONG i = 0; i < pUrbInfo->numIsoPkts; ++i)
|
---|
1332 | {
|
---|
1333 | pUrb->UrbIsochronousTransfer.IsoPacket[i].Offset = pUrbInfo->aIsoPkts[i].off;
|
---|
1334 | pUrb->UrbIsochronousTransfer.IsoPacket[i].Length = pUrbInfo->aIsoPkts[i].cb;
|
---|
1335 | }
|
---|
1336 |
|
---|
1337 | /* We have to schedule the URBs ourselves. There is an ASAP flag but
|
---|
1338 | * that can only be reliably used after pipe creation/reset, ie. it's
|
---|
1339 | * almost completely useless.
|
---|
1340 | */
|
---|
1341 | ULONG iFrame, iStartFrame;
|
---|
1342 | VBoxUsbToolCurrentFrame(pDevExt->pLowerDO, pIrp, &iFrame);
|
---|
1343 | iFrame += 2;
|
---|
1344 | iStartFrame = pPipeInfo->NextScheduledFrame;
|
---|
1345 | if ((iFrame < iStartFrame) || (iStartFrame > iFrame + 512))
|
---|
1346 | iFrame = iStartFrame;
|
---|
1347 | pPipeInfo->NextScheduledFrame = iFrame + pUrbInfo->numIsoPkts;
|
---|
1348 | pUrb->UrbIsochronousTransfer.StartFrame = iFrame;
|
---|
1349 | break;
|
---|
1350 | }
|
---|
1351 | case USBSUP_TRANSFER_TYPE_BULK:
|
---|
1352 | case USBSUP_TRANSFER_TYPE_INTR:
|
---|
1353 | {
|
---|
1354 | Assert(pUrbInfo->dir != USBSUP_DIRECTION_SETUP);
|
---|
1355 | Assert(pUrbInfo->dir == USBSUP_DIRECTION_IN || pUrbInfo->type == USBSUP_TRANSFER_TYPE_BULK);
|
---|
1356 | Assert(hPipe);
|
---|
1357 |
|
---|
1358 | pUrb->UrbHeader.Function = URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER;
|
---|
1359 | pUrb->UrbHeader.Length = sizeof (struct _URB_BULK_OR_INTERRUPT_TRANSFER);
|
---|
1360 | pUrb->UrbBulkOrInterruptTransfer.PipeHandle = hPipe;
|
---|
1361 | pUrb->UrbBulkOrInterruptTransfer.TransferBufferLength = (ULONG)pUrbInfo->len;
|
---|
1362 | pUrb->UrbBulkOrInterruptTransfer.TransferBufferMDL = 0;
|
---|
1363 | pUrb->UrbBulkOrInterruptTransfer.TransferBuffer = pBuffer;
|
---|
1364 | pUrb->UrbBulkOrInterruptTransfer.TransferFlags = ((pUrbInfo->dir == USBSUP_DIRECTION_IN) ? USBD_TRANSFER_DIRECTION_IN : USBD_TRANSFER_DIRECTION_OUT);
|
---|
1365 |
|
---|
1366 | if (pUrb->UrbBulkOrInterruptTransfer.TransferFlags & USBD_TRANSFER_DIRECTION_IN)
|
---|
1367 | pUrb->UrbBulkOrInterruptTransfer.TransferFlags |= (USBD_SHORT_TRANSFER_OK);
|
---|
1368 |
|
---|
1369 | pUrb->UrbBulkOrInterruptTransfer.UrbLink = 0;
|
---|
1370 | break;
|
---|
1371 | }
|
---|
1372 | default:
|
---|
1373 | {
|
---|
1374 | AssertFailed();
|
---|
1375 | Status = STATUS_INVALID_PARAMETER;
|
---|
1376 | break;
|
---|
1377 | }
|
---|
1378 | }
|
---|
1379 |
|
---|
1380 | if (!NT_SUCCESS(Status))
|
---|
1381 | {
|
---|
1382 | break;
|
---|
1383 | }
|
---|
1384 |
|
---|
1385 | pContext->pDevExt = pDevExt;
|
---|
1386 | pContext->pMdlBuf = pMdlBuf;
|
---|
1387 | pContext->pUrb = pUrb;
|
---|
1388 | pContext->pOut = pUrbInfo;
|
---|
1389 | pContext->ulTransferType = pUrbInfo->type;
|
---|
1390 | pContext->ulMagic = VBOXUSB_MAGIC;
|
---|
1391 |
|
---|
1392 | PIO_STACK_LOCATION pSl = IoGetNextIrpStackLocation(pIrp);
|
---|
1393 | pSl->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
|
---|
1394 | pSl->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
|
---|
1395 | pSl->Parameters.Others.Argument1 = pUrb;
|
---|
1396 | pSl->Parameters.Others.Argument2 = NULL;
|
---|
1397 |
|
---|
1398 | IoSetCompletionRoutine(pIrp, vboxUsbRtUrbSendCompletion, pContext, TRUE, TRUE, TRUE);
|
---|
1399 | IoMarkIrpPending(pIrp);
|
---|
1400 | Status = IoCallDriver(pDevExt->pLowerDO, pIrp);
|
---|
1401 | AssertMsg(NT_SUCCESS(Status), (__FUNCTION__": IoCallDriver failed Status (0x%x)\n", Status));
|
---|
1402 | return STATUS_PENDING;
|
---|
1403 | } while (0);
|
---|
1404 |
|
---|
1405 | Assert(!NT_SUCCESS(Status));
|
---|
1406 |
|
---|
1407 | if (pMdlBuf)
|
---|
1408 | {
|
---|
1409 | MmUnlockPages(pMdlBuf);
|
---|
1410 | IoFreeMdl(pMdlBuf);
|
---|
1411 | }
|
---|
1412 |
|
---|
1413 | if (pContext)
|
---|
1414 | vboxUsbMemFree(pContext);
|
---|
1415 |
|
---|
1416 | VBoxDrvToolIoComplete(pIrp, Status, 0);
|
---|
1417 | vboxUsbDdiStateRelease(pDevExt);
|
---|
1418 | return Status;
|
---|
1419 | }
|
---|
1420 |
|
---|
1421 | static NTSTATUS vboxUsbRtDispatchSendUrb(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp)
|
---|
1422 | {
|
---|
1423 | PIO_STACK_LOCATION pSl = IoGetCurrentIrpStackLocation(pIrp);
|
---|
1424 | PFILE_OBJECT pFObj = pSl->FileObject;
|
---|
1425 | PUSBSUP_URB pUrbInfo = (PUSBSUP_URB)pIrp->AssociatedIrp.SystemBuffer;
|
---|
1426 | NTSTATUS Status;
|
---|
1427 |
|
---|
1428 | do
|
---|
1429 | {
|
---|
1430 | if (!pFObj)
|
---|
1431 | {
|
---|
1432 | AssertFailed();
|
---|
1433 | Status = STATUS_INVALID_PARAMETER;
|
---|
1434 | break;
|
---|
1435 | }
|
---|
1436 |
|
---|
1437 | if (!vboxUsbRtCtxIsOwner(pDevExt, pFObj))
|
---|
1438 | {
|
---|
1439 | AssertFailed();
|
---|
1440 | Status = STATUS_ACCESS_DENIED;
|
---|
1441 | break;
|
---|
1442 | }
|
---|
1443 |
|
---|
1444 | if ( !pUrbInfo
|
---|
1445 | || pSl->Parameters.DeviceIoControl.InputBufferLength != sizeof (*pUrbInfo)
|
---|
1446 | || pSl->Parameters.DeviceIoControl.OutputBufferLength != sizeof (*pUrbInfo))
|
---|
1447 | {
|
---|
1448 | AssertMsgFailed((__FUNCTION__": STATUS_INVALID_PARAMETER\n"));
|
---|
1449 | Status = STATUS_INVALID_PARAMETER;
|
---|
1450 | break;
|
---|
1451 | }
|
---|
1452 | return vboxUsbRtUrbSend(pDevExt, pIrp, pUrbInfo);
|
---|
1453 | } while (0);
|
---|
1454 |
|
---|
1455 | Assert(Status != STATUS_PENDING);
|
---|
1456 | VBoxDrvToolIoComplete(pIrp, Status, 0);
|
---|
1457 | vboxUsbDdiStateRelease(pDevExt);
|
---|
1458 | return Status;
|
---|
1459 | }
|
---|
1460 |
|
---|
1461 | static NTSTATUS vboxUsbRtDispatchIsOperational(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp)
|
---|
1462 | {
|
---|
1463 | VBoxDrvToolIoComplete(pIrp, STATUS_SUCCESS, 0);
|
---|
1464 | vboxUsbDdiStateRelease(pDevExt);
|
---|
1465 | return STATUS_SUCCESS;
|
---|
1466 | }
|
---|
1467 |
|
---|
1468 | static NTSTATUS vboxUsbRtDispatchGetVersion(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp)
|
---|
1469 | {
|
---|
1470 | PIO_STACK_LOCATION pSl = IoGetCurrentIrpStackLocation(pIrp);
|
---|
1471 | PUSBSUP_VERSION pVer= (PUSBSUP_VERSION)pIrp->AssociatedIrp.SystemBuffer;
|
---|
1472 | NTSTATUS Status = STATUS_SUCCESS;
|
---|
1473 |
|
---|
1474 | if (pVer && pSl->Parameters.DeviceIoControl.InputBufferLength == 0
|
---|
1475 | && pSl->Parameters.DeviceIoControl.OutputBufferLength == sizeof (*pVer))
|
---|
1476 | {
|
---|
1477 | pVer->u32Major = USBDRV_MAJOR_VERSION;
|
---|
1478 | pVer->u32Minor = USBDRV_MINOR_VERSION;
|
---|
1479 | }
|
---|
1480 | else
|
---|
1481 | {
|
---|
1482 | AssertMsgFailed((__FUNCTION__": STATUS_INVALID_PARAMETER\n"));
|
---|
1483 | Status = STATUS_INVALID_PARAMETER;
|
---|
1484 | }
|
---|
1485 |
|
---|
1486 | Assert(Status != STATUS_PENDING);
|
---|
1487 | VBoxDrvToolIoComplete(pIrp, Status, sizeof (*pVer));
|
---|
1488 | vboxUsbDdiStateRelease(pDevExt);
|
---|
1489 | return Status;
|
---|
1490 | }
|
---|
1491 |
|
---|
1492 | static NTSTATUS vboxUsbRtDispatchDefault(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp)
|
---|
1493 | {
|
---|
1494 | VBoxDrvToolIoComplete(pIrp, STATUS_INVALID_DEVICE_REQUEST, 0);
|
---|
1495 | vboxUsbDdiStateRelease(pDevExt);
|
---|
1496 | return STATUS_INVALID_DEVICE_REQUEST;
|
---|
1497 | }
|
---|
1498 |
|
---|
1499 | DECLHIDDEN(NTSTATUS) vboxUsbRtCreate(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp)
|
---|
1500 | {
|
---|
1501 | PIO_STACK_LOCATION pSl = IoGetCurrentIrpStackLocation(pIrp);
|
---|
1502 | PFILE_OBJECT pFObj = pSl->FileObject;
|
---|
1503 | if (!pFObj)
|
---|
1504 | {
|
---|
1505 | AssertFailed();
|
---|
1506 | return STATUS_INVALID_PARAMETER;
|
---|
1507 | }
|
---|
1508 |
|
---|
1509 | return STATUS_SUCCESS;
|
---|
1510 | }
|
---|
1511 |
|
---|
1512 | DECLHIDDEN(NTSTATUS) vboxUsbRtClose(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp)
|
---|
1513 | {
|
---|
1514 | PIO_STACK_LOCATION pSl = IoGetCurrentIrpStackLocation(pIrp);
|
---|
1515 | PFILE_OBJECT pFObj = pSl->FileObject;
|
---|
1516 | Assert(pFObj);
|
---|
1517 |
|
---|
1518 | vboxUsbRtCtxReleaseOwner(pDevExt, pFObj);
|
---|
1519 |
|
---|
1520 | return STATUS_SUCCESS;
|
---|
1521 | }
|
---|
1522 |
|
---|
1523 | DECLHIDDEN(NTSTATUS) vboxUsbRtDispatch(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp)
|
---|
1524 | {
|
---|
1525 | PIO_STACK_LOCATION pSl = IoGetCurrentIrpStackLocation(pIrp);
|
---|
1526 | switch (pSl->Parameters.DeviceIoControl.IoControlCode)
|
---|
1527 | {
|
---|
1528 | case SUPUSB_IOCTL_USB_CLAIM_DEVICE:
|
---|
1529 | {
|
---|
1530 | return vboxUsbRtDispatchClaimDevice(pDevExt, pIrp);
|
---|
1531 | }
|
---|
1532 | case SUPUSB_IOCTL_USB_RELEASE_DEVICE:
|
---|
1533 | {
|
---|
1534 | return vboxUsbRtDispatchReleaseDevice(pDevExt, pIrp);
|
---|
1535 | }
|
---|
1536 | case SUPUSB_IOCTL_GET_DEVICE:
|
---|
1537 | {
|
---|
1538 | return vboxUsbRtDispatchGetDevice(pDevExt, pIrp);
|
---|
1539 | }
|
---|
1540 | case SUPUSB_IOCTL_USB_RESET:
|
---|
1541 | {
|
---|
1542 | return vboxUsbRtDispatchUsbReset(pDevExt, pIrp);
|
---|
1543 | }
|
---|
1544 | case SUPUSB_IOCTL_USB_SET_CONFIG:
|
---|
1545 | {
|
---|
1546 | return vboxUsbRtDispatchUsbSetConfig(pDevExt, pIrp);
|
---|
1547 | }
|
---|
1548 | case SUPUSB_IOCTL_USB_SELECT_INTERFACE:
|
---|
1549 | {
|
---|
1550 | return vboxUsbRtDispatchUsbSelectInterface(pDevExt, pIrp);
|
---|
1551 | }
|
---|
1552 | case SUPUSB_IOCTL_USB_CLEAR_ENDPOINT:
|
---|
1553 | {
|
---|
1554 | return vboxUsbRtDispatchUsbClearEndpoint(pDevExt, pIrp);
|
---|
1555 | }
|
---|
1556 | case SUPUSB_IOCTL_USB_ABORT_ENDPOINT:
|
---|
1557 | {
|
---|
1558 | return vboxUsbRtDispatchUsbAbortEndpoint(pDevExt, pIrp);
|
---|
1559 | }
|
---|
1560 | case SUPUSB_IOCTL_SEND_URB:
|
---|
1561 | {
|
---|
1562 | return vboxUsbRtDispatchSendUrb(pDevExt, pIrp);
|
---|
1563 | }
|
---|
1564 | case SUPUSB_IOCTL_IS_OPERATIONAL:
|
---|
1565 | {
|
---|
1566 | return vboxUsbRtDispatchIsOperational(pDevExt, pIrp);
|
---|
1567 | }
|
---|
1568 | case SUPUSB_IOCTL_GET_VERSION:
|
---|
1569 | {
|
---|
1570 | return vboxUsbRtDispatchGetVersion(pDevExt, pIrp);
|
---|
1571 | }
|
---|
1572 | default:
|
---|
1573 | {
|
---|
1574 | return vboxUsbRtDispatchDefault(pDevExt, pIrp);
|
---|
1575 | }
|
---|
1576 | }
|
---|
1577 | }
|
---|