VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/VBoxUSB/win/mon/VBoxUsbFlt.cpp@ 67369

Last change on this file since 67369 was 62716, checked in by vboxsync, 8 years ago

HostDrivers: warnings

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 54.7 KB
Line 
1/* $Id: VBoxUsbFlt.cpp 62716 2016-07-29 22:01:27Z vboxsync $ */
2/** @file
3 * VBox USB Monitor Device Filtering functionality
4 */
5/*
6 * Copyright (C) 2011-2016 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
18/*********************************************************************************************************************************
19* Header Files *
20*********************************************************************************************************************************/
21#include "VBoxUsbMon.h"
22#include "../cmn/VBoxUsbTool.h"
23
24#include <VBox/cdefs.h>
25#include <VBox/types.h>
26#include <iprt/process.h>
27#include <iprt/assert.h>
28#include <VBox/err.h>
29//#include <VBox/sup.h>
30
31#include <iprt/assert.h>
32#include <stdio.h>
33
34#pragma warning(disable : 4200)
35#include "usbdi.h"
36#pragma warning(default : 4200)
37#include "usbdlib.h"
38#include "VBoxUSBFilterMgr.h"
39#include <VBox/usblib.h>
40#include <devguid.h>
41
42/*
43 * Note: Must match the VID & PID in the USB driver .inf file!!
44 */
45/*
46 BusQueryDeviceID USB\Vid_80EE&Pid_CAFE
47 BusQueryInstanceID 2
48 BusQueryHardwareIDs USB\Vid_80EE&Pid_CAFE&Rev_0100
49 BusQueryHardwareIDs USB\Vid_80EE&Pid_CAFE
50 BusQueryCompatibleIDs USB\Class_ff&SubClass_00&Prot_00
51 BusQueryCompatibleIDs USB\Class_ff&SubClass_00
52 BusQueryCompatibleIDs USB\Class_ff
53*/
54
55#define szBusQueryDeviceId L"USB\\Vid_80EE&Pid_CAFE"
56#define szBusQueryHardwareIDs L"USB\\Vid_80EE&Pid_CAFE&Rev_0100\0USB\\Vid_80EE&Pid_CAFE\0\0"
57#define szBusQueryCompatibleIDs L"USB\\Class_ff&SubClass_00&Prot_00\0USB\\Class_ff&SubClass_00\0USB\\Class_ff\0\0"
58
59#define szDeviceTextDescription L"VirtualBox USB"
60
61/* Possible USB bus driver names. */
62static LPWSTR lpszStandardControllerName[1] =
63{
64 L"\\Driver\\usbhub",
65};
66
67/*
68 * state transitions:
69 *
70 * (we are not filtering this device )
71 * ADDED --> UNCAPTURED ------------------------------->-
72 * | |
73 * | (we are filtering this device, | (the device is being
74 * | waiting for our device driver | re-plugged to perform
75 * | to pick it up) | capture-uncapture transition)
76 * |-> CAPTURING -------------------------------->|---> REPLUGGING -----
77 * ^ | (device driver picked | |
78 * | | up the device) | (remove cased | (device is removed
79 * | ->---> CAPTURED ---------------------->| by "real" removal | the device info is removed form the list)
80 * | | |------------------->->--> REMOVED
81 * | | |
82 * |-----------<->---> USED_BY_GUEST ------->|
83 * | |
84 * |------------------------<-
85 *
86 * NOTE: the order of enums DOES MATTER!!
87 * Do not blindly modify!! as the code assumes the state is ordered this way.
88 */
89typedef enum
90{
91 VBOXUSBFLT_DEVSTATE_UNKNOWN = 0,
92 VBOXUSBFLT_DEVSTATE_REMOVED,
93 VBOXUSBFLT_DEVSTATE_REPLUGGING,
94 VBOXUSBFLT_DEVSTATE_ADDED,
95 VBOXUSBFLT_DEVSTATE_UNCAPTURED,
96 VBOXUSBFLT_DEVSTATE_CAPTURING,
97 VBOXUSBFLT_DEVSTATE_CAPTURED,
98 VBOXUSBFLT_DEVSTATE_USED_BY_GUEST,
99 VBOXUSBFLT_DEVSTATE_32BIT_HACK = 0x7fffffff
100} VBOXUSBFLT_DEVSTATE;
101
102typedef struct VBOXUSBFLT_DEVICE
103{
104 LIST_ENTRY GlobalLe;
105 /* auxiliary list to be used for gathering devices to be re-plugged
106 * only thread that puts the device to the REPLUGGING state can use this list */
107 LIST_ENTRY RepluggingLe;
108 /* Owning session. Each matched device has an owning session. */
109 struct VBOXUSBFLTCTX *pOwner;
110 /* filter id - if NULL AND device has an owner - the filter is destroyed */
111 uintptr_t uFltId;
112 /* true iff device is filtered with a one-shot filter */
113 bool fIsFilterOneShot;
114 /* The device state. If the non-owner session is requesting the state while the device is grabbed,
115 * the USBDEVICESTATE_USED_BY_HOST is returned. */
116 VBOXUSBFLT_DEVSTATE enmState;
117 volatile uint32_t cRefs;
118 PDEVICE_OBJECT Pdo;
119 uint16_t idVendor;
120 uint16_t idProduct;
121 uint16_t bcdDevice;
122 uint8_t bClass;
123 uint8_t bSubClass;
124 uint8_t bProtocol;
125 char szSerial[MAX_USB_SERIAL_STRING];
126 char szMfgName[MAX_USB_SERIAL_STRING];
127 char szProduct[MAX_USB_SERIAL_STRING];
128#if 0
129 char szDrvKeyName[512];
130 BOOLEAN fHighSpeed;
131#endif
132} VBOXUSBFLT_DEVICE, *PVBOXUSBFLT_DEVICE;
133
134#define PVBOXUSBFLT_DEVICE_FROM_LE(_pLe) ( (PVBOXUSBFLT_DEVICE)( ((uint8_t*)(_pLe)) - RT_OFFSETOF(VBOXUSBFLT_DEVICE, GlobalLe) ) )
135#define PVBOXUSBFLT_DEVICE_FROM_REPLUGGINGLE(_pLe) ( (PVBOXUSBFLT_DEVICE)( ((uint8_t*)(_pLe)) - RT_OFFSETOF(VBOXUSBFLT_DEVICE, RepluggingLe) ) )
136#define PVBOXUSBFLTCTX_FROM_LE(_pLe) ( (PVBOXUSBFLTCTX)( ((uint8_t*)(_pLe)) - RT_OFFSETOF(VBOXUSBFLTCTX, ListEntry) ) )
137
138typedef struct VBOXUSBFLT_LOCK
139{
140 KSPIN_LOCK Lock;
141 KIRQL OldIrql;
142} VBOXUSBFLT_LOCK, *PVBOXUSBFLT_LOCK;
143
144#define VBOXUSBFLT_LOCK_INIT() \
145 KeInitializeSpinLock(&g_VBoxUsbFltGlobals.Lock.Lock)
146#define VBOXUSBFLT_LOCK_TERM() do { } while (0)
147#define VBOXUSBFLT_LOCK_ACQUIRE() \
148 KeAcquireSpinLock(&g_VBoxUsbFltGlobals.Lock.Lock, &g_VBoxUsbFltGlobals.Lock.OldIrql);
149#define VBOXUSBFLT_LOCK_RELEASE() \
150 KeReleaseSpinLock(&g_VBoxUsbFltGlobals.Lock.Lock, g_VBoxUsbFltGlobals.Lock.OldIrql);
151
152
153typedef struct VBOXUSBFLT_BLDEV
154{
155 LIST_ENTRY ListEntry;
156 uint16_t idVendor;
157 uint16_t idProduct;
158 uint16_t bcdDevice;
159} VBOXUSBFLT_BLDEV, *PVBOXUSBFLT_BLDEV;
160
161#define PVBOXUSBFLT_BLDEV_FROM_LE(_pLe) ( (PVBOXUSBFLT_BLDEV)( ((uint8_t*)(_pLe)) - RT_OFFSETOF(VBOXUSBFLT_BLDEV, ListEntry) ) )
162
163typedef struct VBOXUSBFLTGLOBALS
164{
165 LIST_ENTRY DeviceList;
166 LIST_ENTRY ContextList;
167 /* devices known to misbehave */
168 LIST_ENTRY BlackDeviceList;
169 VBOXUSBFLT_LOCK Lock;
170} VBOXUSBFLTGLOBALS, *PVBOXUSBFLTGLOBALS;
171static VBOXUSBFLTGLOBALS g_VBoxUsbFltGlobals;
172
173static bool vboxUsbFltBlDevMatchLocked(uint16_t idVendor, uint16_t idProduct, uint16_t bcdDevice)
174{
175 for (PLIST_ENTRY pEntry = g_VBoxUsbFltGlobals.BlackDeviceList.Flink;
176 pEntry != &g_VBoxUsbFltGlobals.BlackDeviceList;
177 pEntry = pEntry->Flink)
178 {
179 PVBOXUSBFLT_BLDEV pDev = PVBOXUSBFLT_BLDEV_FROM_LE(pEntry);
180 if (pDev->idVendor != idVendor)
181 continue;
182 if (pDev->idProduct != idProduct)
183 continue;
184 if (pDev->bcdDevice != bcdDevice)
185 continue;
186
187 return true;
188 }
189 return false;
190}
191
192static NTSTATUS vboxUsbFltBlDevAddLocked(uint16_t idVendor, uint16_t idProduct, uint16_t bcdDevice)
193{
194 if (vboxUsbFltBlDevMatchLocked(idVendor, idProduct, bcdDevice))
195 return STATUS_SUCCESS;
196 PVBOXUSBFLT_BLDEV pDev = (PVBOXUSBFLT_BLDEV)VBoxUsbMonMemAllocZ(sizeof (*pDev));
197 if (!pDev)
198 {
199 AssertFailed();
200 return STATUS_INSUFFICIENT_RESOURCES;
201 }
202
203 pDev->idVendor = idVendor;
204 pDev->idProduct = idProduct;
205 pDev->bcdDevice = bcdDevice;
206 InsertHeadList(&g_VBoxUsbFltGlobals.BlackDeviceList, &pDev->ListEntry);
207 return STATUS_SUCCESS;
208}
209
210static void vboxUsbFltBlDevClearLocked()
211{
212 PLIST_ENTRY pNext;
213 for (PLIST_ENTRY pEntry = g_VBoxUsbFltGlobals.BlackDeviceList.Flink;
214 pEntry != &g_VBoxUsbFltGlobals.BlackDeviceList;
215 pEntry = pNext)
216 {
217 pNext = pEntry->Flink;
218 VBoxUsbMonMemFree(pEntry);
219 }
220}
221
222static void vboxUsbFltBlDevPopulateWithKnownLocked()
223{
224 /* this one halts when trying to get string descriptors from it */
225 vboxUsbFltBlDevAddLocked(0x5ac, 0x921c, 0x115);
226}
227
228
229DECLINLINE(void) vboxUsbFltDevRetain(PVBOXUSBFLT_DEVICE pDevice)
230{
231 Assert(pDevice->cRefs);
232 ASMAtomicIncU32(&pDevice->cRefs);
233}
234
235static void vboxUsbFltDevDestroy(PVBOXUSBFLT_DEVICE pDevice)
236{
237 Assert(!pDevice->cRefs);
238 Assert(pDevice->enmState == VBOXUSBFLT_DEVSTATE_REMOVED);
239 VBoxUsbMonMemFree(pDevice);
240}
241
242DECLINLINE(void) vboxUsbFltDevRelease(PVBOXUSBFLT_DEVICE pDevice)
243{
244 uint32_t cRefs = ASMAtomicDecU32(&pDevice->cRefs);
245 Assert(cRefs < UINT32_MAX/2);
246 if (!cRefs)
247 {
248 vboxUsbFltDevDestroy(pDevice);
249 }
250}
251
252static void vboxUsbFltDevOwnerSetLocked(PVBOXUSBFLT_DEVICE pDevice, PVBOXUSBFLTCTX pContext, uintptr_t uFltId, bool fIsOneShot)
253{
254 ASSERT_WARN(!pDevice->pOwner, ("device 0x%p has an owner(0x%p)", pDevice, pDevice->pOwner));
255 ++pContext->cActiveFilters;
256 pDevice->pOwner = pContext;
257 pDevice->uFltId = uFltId;
258 pDevice->fIsFilterOneShot = fIsOneShot;
259}
260
261static void vboxUsbFltDevOwnerClearLocked(PVBOXUSBFLT_DEVICE pDevice)
262{
263 ASSERT_WARN(pDevice->pOwner, ("no owner for device 0x%p", pDevice));
264 --pDevice->pOwner->cActiveFilters;
265 ASSERT_WARN(pDevice->pOwner->cActiveFilters < UINT32_MAX/2, ("cActiveFilters (%d)", pDevice->pOwner->cActiveFilters));
266 pDevice->pOwner = NULL;
267 pDevice->uFltId = 0;
268}
269
270static void vboxUsbFltDevOwnerUpdateLocked(PVBOXUSBFLT_DEVICE pDevice, PVBOXUSBFLTCTX pContext, uintptr_t uFltId, bool fIsOneShot)
271{
272 if (pDevice->pOwner != pContext)
273 {
274 if (pDevice->pOwner)
275 vboxUsbFltDevOwnerClearLocked(pDevice);
276 if (pContext)
277 vboxUsbFltDevOwnerSetLocked(pDevice, pContext, uFltId, fIsOneShot);
278 }
279 else if (pContext)
280 {
281 pDevice->uFltId = uFltId;
282 pDevice->fIsFilterOneShot = fIsOneShot;
283 }
284}
285
286static PVBOXUSBFLT_DEVICE vboxUsbFltDevGetLocked(PDEVICE_OBJECT pPdo)
287{
288#ifdef VBOX_USB_WITH_VERBOSE_LOGGING
289 for (PLIST_ENTRY pEntry = g_VBoxUsbFltGlobals.DeviceList.Flink;
290 pEntry != &g_VBoxUsbFltGlobals.DeviceList;
291 pEntry = pEntry->Flink)
292 {
293 PVBOXUSBFLT_DEVICE pDevice = PVBOXUSBFLT_DEVICE_FROM_LE(pEntry);
294 for (PLIST_ENTRY pEntry2 = pEntry->Flink;
295 pEntry2 != &g_VBoxUsbFltGlobals.DeviceList;
296 pEntry2 = pEntry2->Flink)
297 {
298 PVBOXUSBFLT_DEVICE pDevice2 = PVBOXUSBFLT_DEVICE_FROM_LE(pEntry2);
299 ASSERT_WARN( pDevice->idVendor != pDevice2->idVendor
300 || pDevice->idProduct != pDevice2->idProduct
301 || pDevice->bcdDevice != pDevice2->bcdDevice, ("duplicate devices in a list!!"));
302 }
303 }
304#endif
305 for (PLIST_ENTRY pEntry = g_VBoxUsbFltGlobals.DeviceList.Flink;
306 pEntry != &g_VBoxUsbFltGlobals.DeviceList;
307 pEntry = pEntry->Flink)
308 {
309 PVBOXUSBFLT_DEVICE pDevice = PVBOXUSBFLT_DEVICE_FROM_LE(pEntry);
310 ASSERT_WARN( pDevice->enmState == VBOXUSBFLT_DEVSTATE_REPLUGGING
311 || pDevice->enmState == VBOXUSBFLT_DEVSTATE_UNCAPTURED
312 || pDevice->enmState == VBOXUSBFLT_DEVSTATE_CAPTURING
313 || pDevice->enmState == VBOXUSBFLT_DEVSTATE_CAPTURED
314 || pDevice->enmState == VBOXUSBFLT_DEVSTATE_USED_BY_GUEST,
315 ("Invalid device state(%d) for device(0x%p) PDO(0x%p)", pDevice->enmState, pDevice, pDevice->Pdo));
316 if (pDevice->Pdo == pPdo)
317 return pDevice;
318 }
319 return NULL;
320}
321
322PVBOXUSBFLT_DEVICE vboxUsbFltDevGet(PDEVICE_OBJECT pPdo)
323{
324 PVBOXUSBFLT_DEVICE pDevice;
325
326 VBOXUSBFLT_LOCK_ACQUIRE();
327 pDevice = vboxUsbFltDevGetLocked(pPdo);
328 /*
329 * Prevent a host crash when vboxUsbFltDevGetLocked fails to locate the matching PDO
330 * in g_VBoxUsbFltGlobals.DeviceList (see @bugref{6509}).
331 */
332 if (pDevice == NULL)
333 {
334 WARN(("failed to get device for PDO(0x%p)", pPdo));
335 }
336 else if (pDevice->enmState > VBOXUSBFLT_DEVSTATE_ADDED)
337 {
338 vboxUsbFltDevRetain(pDevice);
339 LOG(("found device (0x%p), state(%d) for PDO(0x%p)", pDevice, pDevice->enmState, pPdo));
340 }
341 else
342 {
343 LOG(("found replugging device (0x%p), state(%d) for PDO(0x%p)", pDevice, pDevice->enmState, pPdo));
344 pDevice = NULL;
345 }
346 VBOXUSBFLT_LOCK_RELEASE();
347
348 return pDevice;
349}
350
351static NTSTATUS vboxUsbFltPdoReplug(PDEVICE_OBJECT pDo)
352{
353 LOG(("Replugging PDO(0x%p)", pDo));
354 NTSTATUS Status = VBoxUsbToolIoInternalCtlSendSync(pDo, IOCTL_INTERNAL_USB_CYCLE_PORT, NULL, NULL);
355 ASSERT_WARN(Status == STATUS_SUCCESS, ("replugging PDO(0x%p) failed Status(0x%x)", pDo, Status));
356 LOG(("Replugging PDO(0x%p) done with Status(0x%x)", pDo, Status));
357 return Status;
358}
359
360static bool vboxUsbFltDevCanBeCaptured(PVBOXUSBFLT_DEVICE pDevice)
361{
362 if (pDevice->bClass == USB_DEVICE_CLASS_HUB)
363 {
364 LOG(("device (0x%p), pdo (0x%p) is a hub, can not be captured", pDevice, pDevice->Pdo));
365 return false;
366 }
367 return true;
368}
369
370static PVBOXUSBFLTCTX vboxUsbFltDevMatchLocked(PVBOXUSBFLT_DEVICE pDevice, uintptr_t *puId, bool fRemoveFltIfOneShot, bool *pfFilter, bool *pfIsOneShot)
371{
372 *puId = 0;
373 *pfFilter = false;
374 *pfIsOneShot = false;
375 if (!vboxUsbFltDevCanBeCaptured(pDevice))
376 {
377 LOG(("vboxUsbFltDevCanBeCaptured returned false"));
378 return NULL;
379 }
380
381 USBFILTER DevFlt;
382 USBFilterInit(&DevFlt, USBFILTERTYPE_CAPTURE);
383 USBFilterSetNumExact(&DevFlt, USBFILTERIDX_VENDOR_ID, pDevice->idVendor, true);
384 USBFilterSetNumExact(&DevFlt, USBFILTERIDX_PRODUCT_ID, pDevice->idProduct, true);
385 USBFilterSetNumExact(&DevFlt, USBFILTERIDX_DEVICE_REV, pDevice->bcdDevice, true);
386 USBFilterSetNumExact(&DevFlt, USBFILTERIDX_DEVICE_CLASS, pDevice->bClass, true);
387 USBFilterSetNumExact(&DevFlt, USBFILTERIDX_DEVICE_SUB_CLASS, pDevice->bSubClass, true);
388 USBFilterSetNumExact(&DevFlt, USBFILTERIDX_DEVICE_PROTOCOL, pDevice->bProtocol, true);
389 USBFilterSetStringExact(&DevFlt, USBFILTERIDX_MANUFACTURER_STR, pDevice->szMfgName, true /*fMustBePresent*/, true /*fPurge*/);
390 USBFilterSetStringExact(&DevFlt, USBFILTERIDX_PRODUCT_STR, pDevice->szProduct, true /*fMustBePresent*/, true /*fPurge*/);
391 USBFilterSetStringExact(&DevFlt, USBFILTERIDX_SERIAL_NUMBER_STR, pDevice->szSerial, true /*fMustBePresent*/, true /*fPurge*/);
392
393 /* Run filters on the thing. */
394 PVBOXUSBFLTCTX pOwner = VBoxUSBFilterMatchEx(&DevFlt, puId, fRemoveFltIfOneShot, pfFilter, pfIsOneShot);
395 USBFilterDelete(&DevFlt);
396 return pOwner;
397}
398
399static void vboxUsbFltDevStateMarkReplugLocked(PVBOXUSBFLT_DEVICE pDevice)
400{
401 vboxUsbFltDevOwnerUpdateLocked(pDevice, NULL, 0, false);
402 pDevice->enmState = VBOXUSBFLT_DEVSTATE_REPLUGGING;
403}
404
405static bool vboxUsbFltDevStateIsNotFiltered(PVBOXUSBFLT_DEVICE pDevice)
406{
407 return pDevice->enmState == VBOXUSBFLT_DEVSTATE_UNCAPTURED;
408}
409
410static bool vboxUsbFltDevStateIsFiltered(PVBOXUSBFLT_DEVICE pDevice)
411{
412 return pDevice->enmState >= VBOXUSBFLT_DEVSTATE_CAPTURING;
413}
414
415#define VBOXUSBMON_POPULATE_REQUEST_TIMEOUT_MS 10000
416
417static NTSTATUS vboxUsbFltDevPopulate(PVBOXUSBFLT_DEVICE pDevice, PDEVICE_OBJECT pDo /*, BOOLEAN bPopulateNonFilterProps*/)
418{
419 NTSTATUS Status;
420 PUSB_DEVICE_DESCRIPTOR pDevDr = 0;
421
422 pDevice->Pdo = pDo;
423
424 LOG(("Populating Device(0x%p) for PDO(0x%p)", pDevice, pDo));
425
426 pDevDr = (PUSB_DEVICE_DESCRIPTOR)VBoxUsbMonMemAllocZ(sizeof(*pDevDr));
427 if (pDevDr == NULL)
428 {
429 WARN(("Failed to alloc mem for urb"));
430 return STATUS_INSUFFICIENT_RESOURCES;
431 }
432
433 do
434 {
435 Status = VBoxUsbToolGetDescriptor(pDo, pDevDr, sizeof(*pDevDr), USB_DEVICE_DESCRIPTOR_TYPE, 0, 0, VBOXUSBMON_POPULATE_REQUEST_TIMEOUT_MS);
436 if (!NT_SUCCESS(Status))
437 {
438 WARN(("getting device descriptor failed, Status (0x%x)", Status));
439 break;
440 }
441
442 if (vboxUsbFltBlDevMatchLocked(pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice))
443 {
444 WARN(("found a known black list device, vid(0x%x), pid(0x%x), rev(0x%x)", pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice));
445 Status = STATUS_UNSUCCESSFUL;
446 break;
447 }
448
449 LOG(("Device pid=%x vid=%x rev=%x", pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice));
450 pDevice->idVendor = pDevDr->idVendor;
451 pDevice->idProduct = pDevDr->idProduct;
452 pDevice->bcdDevice = pDevDr->bcdDevice;
453 pDevice->bClass = pDevDr->bDeviceClass;
454 pDevice->bSubClass = pDevDr->bDeviceSubClass;
455 pDevice->bProtocol = pDevDr->bDeviceProtocol;
456 pDevice->szSerial[0] = 0;
457 pDevice->szMfgName[0] = 0;
458 pDevice->szProduct[0] = 0;
459
460 /* If there are no strings, don't even try to get any string descriptors. */
461 if (pDevDr->iSerialNumber || pDevDr->iManufacturer || pDevDr->iProduct)
462 {
463 int langId;
464
465 Status = VBoxUsbToolGetLangID(pDo, &langId, VBOXUSBMON_POPULATE_REQUEST_TIMEOUT_MS);
466 if (!NT_SUCCESS(Status))
467 {
468 WARN(("reading language ID failed"));
469 if (Status == STATUS_CANCELLED)
470 {
471 WARN(("found a new black list device, vid(0x%x), pid(0x%x), rev(0x%x)", pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice));
472 vboxUsbFltBlDevAddLocked(pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice);
473 Status = STATUS_UNSUCCESSFUL;
474 }
475 break;
476 }
477
478 if (pDevDr->iSerialNumber)
479 {
480 Status = VBoxUsbToolGetStringDescriptor(pDo, pDevice->szSerial, sizeof (pDevice->szSerial), pDevDr->iSerialNumber, langId, VBOXUSBMON_POPULATE_REQUEST_TIMEOUT_MS);
481 if (!NT_SUCCESS(Status))
482 {
483 WARN(("reading serial number failed"));
484 ASSERT_WARN(pDevice->szSerial[0] == '\0', ("serial is not zero!!"));
485 if (Status == STATUS_CANCELLED)
486 {
487 WARN(("found a new black list device, vid(0x%x), pid(0x%x), rev(0x%x)", pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice));
488 vboxUsbFltBlDevAddLocked(pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice);
489 Status = STATUS_UNSUCCESSFUL;
490 break;
491 }
492 LOG(("pretending success.."));
493 Status = STATUS_SUCCESS;
494 }
495 }
496
497 if (pDevDr->iManufacturer)
498 {
499 Status = VBoxUsbToolGetStringDescriptor(pDo, pDevice->szMfgName, sizeof (pDevice->szMfgName), pDevDr->iManufacturer, langId, VBOXUSBMON_POPULATE_REQUEST_TIMEOUT_MS);
500 if (!NT_SUCCESS(Status))
501 {
502 WARN(("reading manufacturer name failed"));
503 ASSERT_WARN(pDevice->szMfgName[0] == '\0', ("szMfgName is not zero!!"));
504 if (Status == STATUS_CANCELLED)
505 {
506 WARN(("found a new black list device, vid(0x%x), pid(0x%x), rev(0x%x)", pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice));
507 vboxUsbFltBlDevAddLocked(pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice);
508 Status = STATUS_UNSUCCESSFUL;
509 break;
510 }
511 LOG(("pretending success.."));
512 Status = STATUS_SUCCESS;
513 }
514 }
515
516 if (pDevDr->iProduct)
517 {
518 Status = VBoxUsbToolGetStringDescriptor(pDo, pDevice->szProduct, sizeof (pDevice->szProduct), pDevDr->iProduct, langId, VBOXUSBMON_POPULATE_REQUEST_TIMEOUT_MS);
519 if (!NT_SUCCESS(Status))
520 {
521 WARN(("reading product name failed"));
522 ASSERT_WARN(pDevice->szProduct[0] == '\0', ("szProduct is not zero!!"));
523 if (Status == STATUS_CANCELLED)
524 {
525 WARN(("found a new black list device, vid(0x%x), pid(0x%x), rev(0x%x)", pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice));
526 vboxUsbFltBlDevAddLocked(pDevDr->idVendor, pDevDr->idProduct, pDevDr->bcdDevice);
527 Status = STATUS_UNSUCCESSFUL;
528 break;
529 }
530 LOG(("pretending success.."));
531 Status = STATUS_SUCCESS;
532 }
533 }
534
535#if 0
536 if (bPopulateNonFilterProps)
537 {
538 WCHAR RegKeyBuf[512];
539 ULONG cbRegKeyBuf = sizeof (RegKeyBuf);
540 Status = IoGetDeviceProperty(pDo,
541 DevicePropertyDriverKeyName,
542 cbRegKeyBuf,
543 RegKeyBuf,
544 &cbRegKeyBuf);
545 if (!NT_SUCCESS(Status))
546 {
547 AssertMsgFailed((__FUNCTION__": IoGetDeviceProperty failed Status (0x%x)", Status));
548 break;
549 }
550
551 ANSI_STRING Ansi;
552 UNICODE_STRING Unicode;
553 Ansi.Buffer = pDevice->szDrvKeyName;
554 Ansi.Length = 0;
555 Ansi.MaximumLength = sizeof(pDevice->szDrvKeyName);
556 RtlInitUnicodeString(&Unicode, RegKeyBuf);
557
558 Status = RtlUnicodeStringToAnsiString(&Ansi, &Unicode, FALSE /* do not allocate */);
559 if (!NT_SUCCESS(Status))
560 {
561 AssertMsgFailed((__FUNCTION__": RtlUnicodeStringToAnsiString failed Status (0x%x)", Status));
562 break;
563 }
564
565 pDevice->fHighSpend = FALSE;
566 Status = VBoxUsbToolGetDeviceSpeed(pDo, &pDevice->fHighSpend);
567 if (!NT_SUCCESS(Status))
568 {
569 AssertMsgFailed((__FUNCTION__": VBoxUsbToolGetDeviceSpeed failed Status (0x%x)", Status));
570 break;
571 }
572 }
573#endif
574 LOG((": strings: '%s':'%s':'%s' (lang ID %x)",
575 pDevice->szMfgName, pDevice->szProduct, pDevice->szSerial, langId));
576 }
577
578 LOG(("Populating Device(0x%p) for PDO(0x%p) Succeeded", pDevice, pDo));
579 Status = STATUS_SUCCESS;
580 } while (0);
581
582 VBoxUsbMonMemFree(pDevDr);
583 LOG(("Populating Device(0x%p) for PDO(0x%p) Done, Status (0x%x)", pDevice, pDo, Status));
584 return Status;
585}
586
587static void vboxUsbFltSignalChangeLocked()
588{
589 for (PLIST_ENTRY pEntry = g_VBoxUsbFltGlobals.ContextList.Flink;
590 pEntry != &g_VBoxUsbFltGlobals.ContextList;
591 pEntry = pEntry->Flink)
592 {
593 PVBOXUSBFLTCTX pCtx = PVBOXUSBFLTCTX_FROM_LE(pEntry);
594 /* the removed context can not be in a list */
595 Assert(!pCtx->bRemoved);
596 if (pCtx->pChangeEvent)
597 {
598 KeSetEvent(pCtx->pChangeEvent,
599 0, /* increment*/
600 FALSE /* wait */);
601 }
602 }
603}
604
605static bool vboxUsbFltDevCheckReplugLocked(PVBOXUSBFLT_DEVICE pDevice, PVBOXUSBFLTCTX pContext)
606{
607 ASSERT_WARN(pContext, ("context is NULL!"));
608
609 LOG(("Current context is (0x%p)", pContext));
610 LOG(("Current Device owner is (0x%p)", pDevice->pOwner));
611
612 /* check if device is already replugging */
613 if (pDevice->enmState <= VBOXUSBFLT_DEVSTATE_ADDED)
614 {
615 LOG(("Device (0x%p) is already replugging, return..", pDevice));
616 /* it is, do nothing */
617 ASSERT_WARN(pDevice->enmState == VBOXUSBFLT_DEVSTATE_REPLUGGING,
618 ("Device (0x%p) state is NOT REPLUGGING (%d)", pDevice, pDevice->enmState));
619 return false;
620 }
621
622 if (pDevice->pOwner && pContext != pDevice->pOwner)
623 {
624 LOG(("Device (0x%p) is owned by another context(0x%p), current is(0x%p)", pDevice, pDevice->pOwner, pContext));
625 /* this device is owned by another context, we're not allowed to do anything */
626 return false;
627 }
628
629 uintptr_t uId = 0;
630 bool bNeedReplug = false;
631 bool fFilter = false;
632 bool fIsOneShot = false;
633 PVBOXUSBFLTCTX pNewOwner = vboxUsbFltDevMatchLocked(pDevice, &uId,
634 false, /* do not remove a one-shot filter */
635 &fFilter, &fIsOneShot);
636 LOG(("Matching Info: Filter (0x%p), NewOwner(0x%p), fFilter(%d), fIsOneShot(%d)", uId, pNewOwner, (int)fFilter, (int)fIsOneShot));
637 if (pDevice->pOwner && pNewOwner && pDevice->pOwner != pNewOwner)
638 {
639 LOG(("Matching: Device (0x%p) is requested another owner(0x%p), current is(0x%p)", pDevice, pNewOwner, pDevice->pOwner));
640 /* the device is owned by another owner, we can not change the owner here */
641 return false;
642 }
643
644 if (!fFilter)
645 {
646 LOG(("Matching: Device (0x%p) should NOT be filtered", pDevice));
647 /* the device should NOT be filtered, check the current state */
648 if (vboxUsbFltDevStateIsNotFiltered(pDevice))
649 {
650 LOG(("Device (0x%p) is NOT filtered", pDevice));
651 /* no changes */
652 if (fIsOneShot)
653 {
654 ASSERT_WARN(pNewOwner, ("no new owner"));
655 LOG(("Matching: This is a one-shot filter (0x%p), removing..", uId));
656 /* remove a one-shot filter and keep the original filter data */
657 int tmpRc = VBoxUSBFilterRemove(pNewOwner, uId);
658 ASSERT_WARN(RT_SUCCESS(tmpRc), ("remove filter failed, rc (%d)", tmpRc));
659 if (!pDevice->pOwner)
660 {
661 LOG(("Matching: updating the one-shot owner to (0x%p), fltId(0x%p)", pNewOwner, uId));
662 /* update owner for one-shot if the owner is changed (i.e. assigned) */
663 vboxUsbFltDevOwnerUpdateLocked(pDevice, pNewOwner, uId, true);
664 }
665 else
666 {
667 LOG(("Matching: device already has owner (0x%p) assigned", pDevice->pOwner));
668 }
669 }
670 else
671 {
672 LOG(("Matching: This is NOT a one-shot filter (0x%p), newOwner(0x%p)", uId, pNewOwner));
673 if (pNewOwner)
674 {
675 vboxUsbFltDevOwnerUpdateLocked(pDevice, pNewOwner, uId, false);
676 }
677 }
678 }
679 else
680 {
681 LOG(("Device (0x%p) IS filtered", pDevice));
682 /* the device is currently filtered, we should release it only if
683 * 1. device does not have an owner
684 * or
685 * 2. it should be released bue to a one-shot filter
686 * or
687 * 3. it is NOT grabbed by a one-shot filter */
688 if (!pDevice->pOwner || fIsOneShot || !pDevice->fIsFilterOneShot)
689 {
690 LOG(("Matching: Need replug"));
691 bNeedReplug = true;
692 }
693 }
694 }
695 else
696 {
697 LOG(("Matching: Device (0x%p) SHOULD be filtered", pDevice));
698 /* the device should be filtered, check the current state */
699 ASSERT_WARN(uId, ("zero uid"));
700 ASSERT_WARN(pNewOwner, ("zero pNewOwner"));
701 if (vboxUsbFltDevStateIsFiltered(pDevice))
702 {
703 LOG(("Device (0x%p) IS filtered", pDevice));
704 /* the device is filtered */
705 if (pNewOwner == pDevice->pOwner)
706 {
707 LOG(("Device owner match"));
708 /* no changes */
709 if (fIsOneShot)
710 {
711 LOG(("Matching: This is a one-shot filter (0x%p), removing..", uId));
712 /* remove a one-shot filter and keep the original filter data */
713 int tmpRc = VBoxUSBFilterRemove(pNewOwner, uId);
714 ASSERT_WARN(RT_SUCCESS(tmpRc), ("remove filter failed, rc (%d)", tmpRc));
715 }
716 else
717 {
718 LOG(("Matching: This is NOT a one-shot filter (0x%p), Owner(0x%p)", uId, pDevice->pOwner));
719 vboxUsbFltDevOwnerUpdateLocked(pDevice, pDevice->pOwner, uId, false);
720 }
721 }
722 else
723 {
724 ASSERT_WARN(!pDevice->pOwner, ("device should NOT have owner"));
725 LOG(("Matching: Need replug"));
726 /* the device needs to be filtered, but the owner changes, replug needed */
727 bNeedReplug = true;
728 }
729 }
730 else
731 {
732 /* the device is currently NOT filtered,
733 * we should replug it only if
734 * 1. device does not have an owner
735 * or
736 * 2. it should be captured due to a one-shot filter
737 * or
738 * 3. it is NOT released by a one-shot filter */
739 if (!pDevice->pOwner || fIsOneShot || !pDevice->fIsFilterOneShot)
740 {
741 bNeedReplug = true;
742 LOG(("Matching: Need replug"));
743 }
744 }
745 }
746
747 if (bNeedReplug)
748 {
749 LOG(("Matching: Device needs replugging, marking as such"));
750 vboxUsbFltDevStateMarkReplugLocked(pDevice);
751 }
752 else
753 {
754 LOG(("Matching: Device does NOT need replugging"));
755 }
756
757 return bNeedReplug;
758}
759
760static void vboxUsbFltReplugList(PLIST_ENTRY pList)
761{
762 PLIST_ENTRY pNext;
763 for (PLIST_ENTRY pEntry = pList->Flink;
764 pEntry != pList;
765 pEntry = pNext)
766 {
767 pNext = pEntry->Flink;
768 PVBOXUSBFLT_DEVICE pDevice = PVBOXUSBFLT_DEVICE_FROM_REPLUGGINGLE(pEntry);
769 LOG(("replugging matched PDO(0x%p), pDevice(0x%p)", pDevice->Pdo, pDevice));
770 ASSERT_WARN(pDevice->enmState == VBOXUSBFLT_DEVSTATE_REPLUGGING
771 || pDevice->enmState == VBOXUSBFLT_DEVSTATE_REMOVED,
772 ("invalid state(0x%x) for device(0x%p)", pDevice->enmState, pDevice));
773
774 vboxUsbFltPdoReplug(pDevice->Pdo);
775 ObDereferenceObject(pDevice->Pdo);
776 vboxUsbFltDevRelease(pDevice);
777 }
778}
779
780typedef struct VBOXUSBFLTCHECKWALKER
781{
782 PVBOXUSBFLTCTX pContext;
783} VBOXUSBFLTCHECKWALKER, *PVBOXUSBFLTCHECKWALKER;
784
785static DECLCALLBACK(BOOLEAN) vboxUsbFltFilterCheckWalker(PFILE_OBJECT pFile, PDEVICE_OBJECT pTopDo,
786 PDEVICE_OBJECT pHubDo, PVOID pvContext)
787{
788 RT_NOREF1(pHubDo);
789 PVBOXUSBFLTCHECKWALKER pData = (PVBOXUSBFLTCHECKWALKER)pvContext;
790 PVBOXUSBFLTCTX pContext = pData->pContext;
791
792 LOG(("Visiting pFile(0x%p), pTopDo(0x%p), pHubDo(0x%p), oContext(0x%p)", pFile, pTopDo, pHubDo, pContext));
793 KIRQL Irql = KeGetCurrentIrql();
794 ASSERT_WARN(Irql == PASSIVE_LEVEL, ("unexpected IRQL (%d)", Irql));
795
796 PDEVICE_RELATIONS pDevRelations = NULL;
797
798 NTSTATUS Status = VBoxUsbMonQueryBusRelations(pTopDo, pFile, &pDevRelations);
799 if (Status == STATUS_SUCCESS && pDevRelations)
800 {
801 ULONG cReplugPdos = pDevRelations->Count;
802 LIST_ENTRY ReplugDevList;
803 InitializeListHead(&ReplugDevList);
804 for (ULONG k = 0; k < pDevRelations->Count; ++k)
805 {
806 PDEVICE_OBJECT pDevObj = pDevRelations->Objects[k];
807
808 LOG(("Found existing USB PDO 0x%p", pDevObj));
809 VBOXUSBFLT_LOCK_ACQUIRE();
810 PVBOXUSBFLT_DEVICE pDevice = vboxUsbFltDevGetLocked(pDevObj);
811 if (pDevice)
812 {
813 LOG(("Found existing device info (0x%p) for PDO 0x%p", pDevice, pDevObj));
814 bool bReplug = vboxUsbFltDevCheckReplugLocked(pDevice, pContext);
815 if (bReplug)
816 {
817 LOG(("Replug needed for device (0x%p)", pDevice));
818 InsertHeadList(&ReplugDevList, &pDevice->RepluggingLe);
819 vboxUsbFltDevRetain(pDevice);
820 /* do not dereference object since we will use it later */
821 }
822 else
823 {
824 LOG(("Replug NOT needed for device (0x%p)", pDevice));
825 ObDereferenceObject(pDevObj);
826 }
827
828 VBOXUSBFLT_LOCK_RELEASE();
829
830 pDevRelations->Objects[k] = NULL;
831 --cReplugPdos;
832 ASSERT_WARN((uint32_t)cReplugPdos < UINT32_MAX/2, ("cReplugPdos(%d) state broken", cReplugPdos));
833 continue;
834 }
835 VBOXUSBFLT_LOCK_RELEASE();
836
837 LOG(("NO device info found for PDO 0x%p", pDevObj));
838 VBOXUSBFLT_DEVICE Device;
839 Status = vboxUsbFltDevPopulate(&Device, pDevObj /*, FALSE /* only need filter properties */);
840 if (NT_SUCCESS(Status))
841 {
842 uintptr_t uId = 0;
843 bool fFilter = false;
844 bool fIsOneShot = false;
845 VBOXUSBFLT_LOCK_ACQUIRE();
846 PVBOXUSBFLTCTX pCtx = vboxUsbFltDevMatchLocked(&Device, &uId,
847 false, /* do not remove a one-shot filter */
848 &fFilter, &fIsOneShot);
849 VBOXUSBFLT_LOCK_RELEASE();
850 NOREF(pCtx);
851 LOG(("Matching Info: Filter (0x%p), pCtx(0x%p), fFilter(%d), fIsOneShot(%d)", uId, pCtx, (int)fFilter, (int)fIsOneShot));
852 if (fFilter)
853 {
854 LOG(("Matching: This device SHOULD be filtered"));
855 /* this device needs to be filtered, but it's not,
856 * leave the PDO in array to issue a replug request for it
857 * later on */
858 continue;
859 }
860 }
861 else
862 {
863 WARN(("vboxUsbFltDevPopulate for PDO 0x%p failed with Status 0x%x", pDevObj, Status));
864 }
865
866 LOG(("Matching: This device should NOT be filtered"));
867 /* this device should not be filtered, and it's not */
868 ObDereferenceObject(pDevObj);
869 pDevRelations->Objects[k] = NULL;
870 --cReplugPdos;
871 ASSERT_WARN((uint32_t)cReplugPdos < UINT32_MAX/2, ("cReplugPdos is %d", cReplugPdos));
872 }
873
874 LOG(("(%d) non-matched PDOs to be replugged", cReplugPdos));
875
876 if (cReplugPdos)
877 {
878 for (ULONG k = 0; k < pDevRelations->Count; ++k)
879 {
880 if (!pDevRelations->Objects[k])
881 continue;
882
883 Status = vboxUsbFltPdoReplug(pDevRelations->Objects[k]);
884 ASSERT_WARN(Status == STATUS_SUCCESS, ("vboxUsbFltPdoReplug ailed Status(0x%x)", Status));
885 ObDereferenceObject(pDevRelations->Objects[k]);
886 if (!--cReplugPdos)
887 break;
888 }
889
890 ASSERT_WARN(!cReplugPdos, ("cReplugPdosreached zero!"));
891 }
892
893 vboxUsbFltReplugList(&ReplugDevList);
894
895 ExFreePool(pDevRelations);
896 }
897 else
898 {
899 WARN(("VBoxUsbMonQueryBusRelations failed for DO(0x%p), Status(0x%x), pDevRelations(0x%p)",
900 pTopDo, Status, pDevRelations));
901 }
902
903 LOG(("Done Visiting pFile(0x%p), pTopDo(0x%p), pHubDo(0x%p), oContext(0x%p)", pFile, pTopDo, pHubDo, pContext));
904
905 return TRUE;
906}
907
908NTSTATUS VBoxUsbFltFilterCheck(PVBOXUSBFLTCTX pContext)
909{
910 KIRQL Irql = KeGetCurrentIrql();
911 ASSERT_WARN(Irql == PASSIVE_LEVEL, ("unexpected IRQL (%d)", Irql));
912
913 LOG(("Running filters, Context (0x%p)..", pContext));
914
915 VBOXUSBFLTCHECKWALKER Data;
916 Data.pContext = pContext;
917 vboxUsbMonHubDevWalk(vboxUsbFltFilterCheckWalker, &Data, VBOXUSBMONHUBWALK_F_FDO);
918
919 LOG(("DONE Running filters, Context (0x%p)", pContext));
920
921 return STATUS_SUCCESS;
922}
923
924NTSTATUS VBoxUsbFltClose(PVBOXUSBFLTCTX pContext)
925{
926 LOG(("Closing context(0x%p)", pContext));
927 LIST_ENTRY ReplugDevList;
928 InitializeListHead(&ReplugDevList);
929
930 ASSERT_WARN(pContext, ("null context"));
931
932 KIRQL Irql = KeGetCurrentIrql();
933 ASSERT_WARN(Irql == PASSIVE_LEVEL, ("irql==(%d)", Irql));
934
935 VBOXUSBFLT_LOCK_ACQUIRE();
936
937 pContext->bRemoved = TRUE;
938 if (pContext->pChangeEvent)
939 {
940 LOG(("seting & closing change event (0x%p)", pContext->pChangeEvent));
941 KeSetEvent(pContext->pChangeEvent,
942 0, /* increment*/
943 FALSE /* wait */);
944 ObDereferenceObject(pContext->pChangeEvent);
945 pContext->pChangeEvent = NULL;
946 }
947 else
948 LOG(("no change event"));
949 RemoveEntryList(&pContext->ListEntry);
950
951 LOG(("removing owner filters"));
952 /* now re-arrange the filters */
953 /* 1. remove filters */
954 VBoxUSBFilterRemoveOwner(pContext);
955
956 LOG(("enumerating devices.."));
957 /* 2. check if there are devices owned */
958 for (PLIST_ENTRY pEntry = g_VBoxUsbFltGlobals.DeviceList.Flink;
959 pEntry != &g_VBoxUsbFltGlobals.DeviceList;
960 pEntry = pEntry->Flink)
961 {
962 PVBOXUSBFLT_DEVICE pDevice = PVBOXUSBFLT_DEVICE_FROM_LE(pEntry);
963 if (pDevice->pOwner != pContext)
964 continue;
965
966 LOG(("found device(0x%p), pdo(0x%p), state(%d), filter id(0x%p), oneshot(%d)",
967 pDevice, pDevice->Pdo, pDevice->enmState, pDevice->uFltId, (int)pDevice->fIsFilterOneShot));
968 ASSERT_WARN(pDevice->enmState != VBOXUSBFLT_DEVSTATE_ADDED, ("VBOXUSBFLT_DEVSTATE_ADDED state for device(0x%p)", pDevice));
969 ASSERT_WARN(pDevice->enmState != VBOXUSBFLT_DEVSTATE_REMOVED, ("VBOXUSBFLT_DEVSTATE_REMOVED state for device(0x%p)", pDevice));
970
971 vboxUsbFltDevOwnerClearLocked(pDevice);
972
973 if (vboxUsbFltDevCheckReplugLocked(pDevice, pContext))
974 {
975 LOG(("device needs replug"));
976 InsertHeadList(&ReplugDevList, &pDevice->RepluggingLe);
977 /* retain to ensure the device is not removed before we issue a replug */
978 vboxUsbFltDevRetain(pDevice);
979 /* keep the PDO alive */
980 ObReferenceObject(pDevice->Pdo);
981 }
982 else
983 {
984 LOG(("device does NOT need replug"));
985 }
986 }
987
988 VBOXUSBFLT_LOCK_RELEASE();
989
990 /* this should replug all devices that were either skipped or grabbed due to the context's */
991 vboxUsbFltReplugList(&ReplugDevList);
992
993 LOG(("SUCCESS done context(0x%p)", pContext));
994 return STATUS_SUCCESS;
995}
996
997NTSTATUS VBoxUsbFltCreate(PVBOXUSBFLTCTX pContext)
998{
999 LOG(("Creating context(0x%p)", pContext));
1000 memset(pContext, 0, sizeof (*pContext));
1001 pContext->Process = RTProcSelf();
1002 VBOXUSBFLT_LOCK_ACQUIRE();
1003 InsertHeadList(&g_VBoxUsbFltGlobals.ContextList, &pContext->ListEntry);
1004 VBOXUSBFLT_LOCK_RELEASE();
1005 LOG(("SUCCESS context(0x%p)", pContext));
1006 return STATUS_SUCCESS;
1007}
1008
1009int VBoxUsbFltAdd(PVBOXUSBFLTCTX pContext, PUSBFILTER pFilter, uintptr_t *pId)
1010{
1011 LOG(("adding filter, Context (0x%p)..", pContext));
1012 *pId = 0;
1013 /* LOG the filter details. */
1014 LOG((__FUNCTION__": %s %s %s",
1015 USBFilterGetString(pFilter, USBFILTERIDX_MANUFACTURER_STR) ? USBFilterGetString(pFilter, USBFILTERIDX_MANUFACTURER_STR) : "<null>",
1016 USBFilterGetString(pFilter, USBFILTERIDX_PRODUCT_STR) ? USBFilterGetString(pFilter, USBFILTERIDX_PRODUCT_STR) : "<null>",
1017 USBFilterGetString(pFilter, USBFILTERIDX_SERIAL_NUMBER_STR) ? USBFilterGetString(pFilter, USBFILTERIDX_SERIAL_NUMBER_STR) : "<null>"));
1018#ifdef VBOX_USB_WITH_VERBOSE_LOGGING
1019 LOG(("VBoxUSBClient::addFilter: idVendor=%#x idProduct=%#x bcdDevice=%#x bDeviceClass=%#x bDeviceSubClass=%#x bDeviceProtocol=%#x bBus=%#x bPort=%#x Type%#x",
1020 USBFilterGetNum(pFilter, USBFILTERIDX_VENDOR_ID),
1021 USBFilterGetNum(pFilter, USBFILTERIDX_PRODUCT_ID),
1022 USBFilterGetNum(pFilter, USBFILTERIDX_DEVICE_REV),
1023 USBFilterGetNum(pFilter, USBFILTERIDX_DEVICE_CLASS),
1024 USBFilterGetNum(pFilter, USBFILTERIDX_DEVICE_SUB_CLASS),
1025 USBFilterGetNum(pFilter, USBFILTERIDX_DEVICE_PROTOCOL),
1026 USBFilterGetNum(pFilter, USBFILTERIDX_BUS),
1027 USBFilterGetNum(pFilter, USBFILTERIDX_PORT),
1028 USBFilterGetFilterType(pFilter)));
1029#endif
1030
1031 /* We can't get the bus/port numbers. Ignore them while matching. */
1032 USBFilterSetMustBePresent(pFilter, USBFILTERIDX_BUS, false);
1033 USBFilterSetMustBePresent(pFilter, USBFILTERIDX_PORT, false);
1034
1035 uintptr_t uId = 0;
1036 VBOXUSBFLT_LOCK_ACQUIRE();
1037 /* Add the filter. */
1038 int rc = VBoxUSBFilterAdd(pFilter, pContext, &uId);
1039 VBOXUSBFLT_LOCK_RELEASE();
1040 if (RT_SUCCESS(rc))
1041 {
1042 LOG(("ADDED filer id 0x%p", uId));
1043 ASSERT_WARN(uId, ("uid is NULL"));
1044#ifdef VBOX_USBMON_WITH_FILTER_AUTOAPPLY
1045 VBoxUsbFltFilterCheck();
1046#endif
1047 }
1048 else
1049 {
1050 WARN(("VBoxUSBFilterAdd failed rc (%d)", rc));
1051 ASSERT_WARN(!uId, ("uid is not NULL"));
1052 }
1053
1054 *pId = uId;
1055 return rc;
1056}
1057
1058int VBoxUsbFltRemove(PVBOXUSBFLTCTX pContext, uintptr_t uId)
1059{
1060 LOG(("removing filter id(0x%p), Context (0x%p)..", pContext, uId));
1061 Assert(uId);
1062
1063 VBOXUSBFLT_LOCK_ACQUIRE();
1064 int rc = VBoxUSBFilterRemove(pContext, uId);
1065 if (!RT_SUCCESS(rc))
1066 {
1067 WARN(("VBoxUSBFilterRemove failed rc (%d)", rc));
1068 VBOXUSBFLT_LOCK_RELEASE();
1069 return rc;
1070 }
1071
1072 LOG(("enumerating devices.."));
1073 for (PLIST_ENTRY pEntry = g_VBoxUsbFltGlobals.DeviceList.Flink;
1074 pEntry != &g_VBoxUsbFltGlobals.DeviceList;
1075 pEntry = pEntry->Flink)
1076 {
1077 PVBOXUSBFLT_DEVICE pDevice = PVBOXUSBFLT_DEVICE_FROM_LE(pEntry);
1078 if (pDevice->fIsFilterOneShot)
1079 {
1080 ASSERT_WARN(!pDevice->uFltId, ("oneshot filter on device(0x%p): unexpected uFltId(%d)", pDevice, pDevice->uFltId));
1081 }
1082
1083 if (pDevice->uFltId != uId)
1084 continue;
1085
1086 ASSERT_WARN(pDevice->pOwner == pContext, ("Device(0x%p) owner(0x%p) not match to (0x%p)", pDevice, pDevice->pOwner, pContext));
1087 if (pDevice->pOwner != pContext)
1088 continue;
1089
1090 LOG(("found device(0x%p), pdo(0x%p), state(%d), filter id(0x%p), oneshot(%d)",
1091 pDevice, pDevice->Pdo, pDevice->enmState, pDevice->uFltId, (int)pDevice->fIsFilterOneShot));
1092 ASSERT_WARN(!pDevice->fIsFilterOneShot, ("device(0x%p) is filtered with a oneshot filter", pDevice));
1093 pDevice->uFltId = 0;
1094 /* clear the fIsFilterOneShot flag to ensure the device is replugged on the next VBoxUsbFltFilterCheck call */
1095 pDevice->fIsFilterOneShot = false;
1096 }
1097 VBOXUSBFLT_LOCK_RELEASE();
1098
1099 LOG(("done enumerating devices"));
1100
1101 if (RT_SUCCESS(rc))
1102 {
1103#ifdef VBOX_USBMON_WITH_FILTER_AUTOAPPLY
1104 VBoxUsbFltFilterCheck();
1105#endif
1106 }
1107 return rc;
1108}
1109
1110NTSTATUS VBoxUsbFltSetNotifyEvent(PVBOXUSBFLTCTX pContext, HANDLE hEvent)
1111{
1112 NTSTATUS Status = STATUS_SUCCESS;
1113 PKEVENT pEvent = NULL;
1114 PKEVENT pOldEvent = NULL;
1115 if (hEvent)
1116 {
1117 Status = ObReferenceObjectByHandle(hEvent,
1118 EVENT_MODIFY_STATE,
1119 *ExEventObjectType, UserMode,
1120 (PVOID*)&pEvent,
1121 NULL);
1122 Assert(Status == STATUS_SUCCESS);
1123 if (!NT_SUCCESS(Status))
1124 return Status;
1125 }
1126
1127 VBOXUSBFLT_LOCK_ACQUIRE();
1128 pOldEvent = pContext->pChangeEvent;
1129 pContext->pChangeEvent = pEvent;
1130 VBOXUSBFLT_LOCK_RELEASE();
1131
1132 if (pOldEvent)
1133 {
1134 ObDereferenceObject(pOldEvent);
1135 }
1136
1137 return STATUS_SUCCESS;
1138}
1139
1140static USBDEVICESTATE vboxUsbDevGetUserState(PVBOXUSBFLTCTX pContext, PVBOXUSBFLT_DEVICE pDevice)
1141{
1142 if (vboxUsbFltDevStateIsNotFiltered(pDevice))
1143 return USBDEVICESTATE_USED_BY_HOST_CAPTURABLE;
1144
1145 /* the device is filtered, or replugging */
1146 if (pDevice->enmState == VBOXUSBFLT_DEVSTATE_REPLUGGING)
1147 {
1148 ASSERT_WARN(!pDevice->pOwner, ("replugging device(0x%p) still has an owner(0x%p)", pDevice, pDevice->pOwner));
1149 ASSERT_WARN(!pDevice->uFltId, ("replugging device(0x%p) still has filter(0x%p)", pDevice, pDevice->uFltId));
1150 /* no user state for this, we should not return it tu the user */
1151 return USBDEVICESTATE_USED_BY_HOST;
1152 }
1153
1154 /* the device is filtered, if owner differs from the context, return as USED_BY_HOST */
1155 ASSERT_WARN(pDevice->pOwner, ("device(0x%p) has noowner", pDevice));
1156 /* the id can be null if a filter is removed */
1157// Assert(pDevice->uFltId);
1158
1159 if (pDevice->pOwner != pContext)
1160 {
1161 LOG(("Device owner differs from the current context, returning used by host"));
1162 return USBDEVICESTATE_USED_BY_HOST;
1163 }
1164
1165 switch (pDevice->enmState)
1166 {
1167 case VBOXUSBFLT_DEVSTATE_UNCAPTURED:
1168 case VBOXUSBFLT_DEVSTATE_CAPTURING:
1169 return USBDEVICESTATE_USED_BY_HOST_CAPTURABLE;
1170 case VBOXUSBFLT_DEVSTATE_CAPTURED:
1171 return USBDEVICESTATE_HELD_BY_PROXY;
1172 case VBOXUSBFLT_DEVSTATE_USED_BY_GUEST:
1173 return USBDEVICESTATE_USED_BY_GUEST;
1174 default:
1175 WARN(("unexpected device state(%d) for device(0x%p)", pDevice->enmState, pDevice));
1176 return USBDEVICESTATE_UNSUPPORTED;
1177 }
1178}
1179
1180static void vboxUsbDevToUserInfo(PVBOXUSBFLTCTX pContext, PVBOXUSBFLT_DEVICE pDevice, PUSBSUP_DEVINFO pDevInfo)
1181{
1182#if 0
1183 pDevInfo->usVendorId = pDevice->idVendor;
1184 pDevInfo->usProductId = pDevice->idProduct;
1185 pDevInfo->usRevision = pDevice->bcdDevice;
1186 pDevInfo->enmState = vboxUsbDevGetUserState(pContext, pDevice);
1187
1188 strcpy(pDevInfo->szDrvKeyName, pDevice->szDrvKeyName);
1189 if (pDevInfo->enmState == USBDEVICESTATE_HELD_BY_PROXY
1190 || pDevInfo->enmState == USBDEVICESTATE_USED_BY_GUEST)
1191 {
1192 /* this is the only case where we return the obj name to the client */
1193 strcpy(pDevInfo->szObjName, pDevice->szObjName);
1194 }
1195 pDevInfo->fHighSpeed = pDevice->fHighSpeed;
1196#else
1197 RT_NOREF3(pContext, pDevice, pDevInfo);
1198#endif
1199}
1200
1201NTSTATUS VBoxUsbFltGetDevice(PVBOXUSBFLTCTX pContext, HVBOXUSBDEVUSR hDevice, PUSBSUP_GETDEV_MON pInfo)
1202{
1203 Assert(hDevice);
1204
1205 memset (pInfo, 0, sizeof (*pInfo));
1206 VBOXUSBFLT_LOCK_ACQUIRE();
1207 for (PLIST_ENTRY pEntry = g_VBoxUsbFltGlobals.DeviceList.Flink;
1208 pEntry != &g_VBoxUsbFltGlobals.DeviceList;
1209 pEntry = pEntry->Flink)
1210 {
1211 PVBOXUSBFLT_DEVICE pDevice = PVBOXUSBFLT_DEVICE_FROM_LE(pEntry);
1212 Assert(pDevice->enmState != VBOXUSBFLT_DEVSTATE_REMOVED);
1213 Assert(pDevice->enmState != VBOXUSBFLT_DEVSTATE_ADDED);
1214
1215 if (pDevice != hDevice)
1216 continue;
1217
1218 USBDEVICESTATE enmUsrState = vboxUsbDevGetUserState(pContext, pDevice);
1219 pInfo->enmState = enmUsrState;
1220 VBOXUSBFLT_LOCK_RELEASE();
1221 return STATUS_SUCCESS;
1222 }
1223
1224 VBOXUSBFLT_LOCK_RELEASE();
1225
1226 /* this should not occur */
1227 AssertFailed();
1228
1229 return STATUS_INVALID_PARAMETER;
1230}
1231
1232NTSTATUS VBoxUsbFltPdoAdd(PDEVICE_OBJECT pPdo, BOOLEAN *pbFiltered)
1233{
1234 *pbFiltered = FALSE;
1235 PVBOXUSBFLT_DEVICE pDevice;
1236
1237 /* first check if device is in the a already */
1238 VBOXUSBFLT_LOCK_ACQUIRE();
1239 pDevice = vboxUsbFltDevGetLocked(pPdo);
1240 if (pDevice)
1241 {
1242 LOG(("found device (0x%p), state(%d) for PDO(0x%p)", pDevice, pDevice->enmState, pPdo));
1243 ASSERT_WARN(pDevice->enmState != VBOXUSBFLT_DEVSTATE_ADDED, ("VBOXUSBFLT_DEVSTATE_ADDED state for device(0x%p)", pDevice));
1244 ASSERT_WARN(pDevice->enmState != VBOXUSBFLT_DEVSTATE_REMOVED, ("VBOXUSBFLT_DEVSTATE_REMOVED state for device(0x%p)", pDevice));
1245 *pbFiltered = pDevice->enmState >= VBOXUSBFLT_DEVSTATE_CAPTURING;
1246 VBOXUSBFLT_LOCK_RELEASE();
1247 return STATUS_SUCCESS;
1248 }
1249 VBOXUSBFLT_LOCK_RELEASE();
1250 pDevice = (PVBOXUSBFLT_DEVICE)VBoxUsbMonMemAllocZ(sizeof (*pDevice));
1251 if (!pDevice)
1252 {
1253 WARN(("VBoxUsbMonMemAllocZ failed"));
1254 return STATUS_NO_MEMORY;
1255 }
1256
1257 pDevice->enmState = VBOXUSBFLT_DEVSTATE_ADDED;
1258 pDevice->cRefs = 1;
1259 NTSTATUS Status = vboxUsbFltDevPopulate(pDevice, pPdo /* , TRUE /* need all props */);
1260 if (!NT_SUCCESS(Status))
1261 {
1262 WARN(("vboxUsbFltDevPopulate failed, Status 0x%x", Status));
1263 VBoxUsbMonMemFree(pDevice);
1264 return Status;
1265 }
1266
1267 uintptr_t uId;
1268 bool fFilter = false;
1269 bool fIsOneShot = false;
1270 PVBOXUSBFLTCTX pCtx;
1271 PVBOXUSBFLT_DEVICE pTmpDev;
1272 VBOXUSBFLT_LOCK_ACQUIRE();
1273 /* (paranoia) re-check the device is still not here */
1274 pTmpDev = vboxUsbFltDevGetLocked(pPdo);
1275 if (pTmpDev)
1276 {
1277 LOG(("second try: found device (0x%p), state(%d) for PDO(0x%p)", pDevice, pDevice->enmState, pPdo));
1278 ASSERT_WARN(pDevice->enmState != VBOXUSBFLT_DEVSTATE_ADDED, ("second try: VBOXUSBFLT_DEVSTATE_ADDED state for device(0x%p)", pDevice));
1279 ASSERT_WARN(pDevice->enmState != VBOXUSBFLT_DEVSTATE_REMOVED, ("second try: VBOXUSBFLT_DEVSTATE_REMOVED state for device(0x%p)", pDevice));
1280 *pbFiltered = pTmpDev->enmState >= VBOXUSBFLT_DEVSTATE_CAPTURING;
1281 VBOXUSBFLT_LOCK_RELEASE();
1282 VBoxUsbMonMemFree(pDevice);
1283 return STATUS_SUCCESS;
1284 }
1285
1286 LOG(("Created Device 0x%p for PDO 0x%p", pDevice, pPdo));
1287
1288 pCtx = vboxUsbFltDevMatchLocked(pDevice, &uId,
1289 true, /* remove a one-shot filter */
1290 &fFilter, &fIsOneShot);
1291 LOG(("Matching Info: Filter (0x%p), pCtx(0x%p), fFilter(%d), fIsOneShot(%d)", uId, pCtx, (int)fFilter, (int)fIsOneShot));
1292 if (fFilter)
1293 {
1294 LOG(("Created Device 0x%p should be filtered", pDevice));
1295 ASSERT_WARN(pCtx, ("zero ctx"));
1296 ASSERT_WARN(uId, ("zero uId"));
1297 pDevice->enmState = VBOXUSBFLT_DEVSTATE_CAPTURING;
1298 }
1299 else
1300 {
1301 LOG(("Created Device 0x%p should NOT be filtered", pDevice));
1302 ASSERT_WARN(!uId == !pCtx, ("invalid uid(0x%p) - ctx(0x%p) pair", uId, pCtx)); /* either both zero or both not */
1303 pDevice->enmState = VBOXUSBFLT_DEVSTATE_UNCAPTURED;
1304 }
1305
1306 if (pCtx)
1307 vboxUsbFltDevOwnerSetLocked(pDevice, pCtx, fIsOneShot ? 0 : uId, fIsOneShot);
1308
1309 InsertHeadList(&g_VBoxUsbFltGlobals.DeviceList, &pDevice->GlobalLe);
1310
1311 /* do not need to signal anything here -
1312 * going to do that once the proxy device object starts */
1313 VBOXUSBFLT_LOCK_RELEASE();
1314
1315 *pbFiltered = fFilter;
1316
1317 return STATUS_SUCCESS;
1318}
1319
1320NTSTATUS VBoxUsbFltPdoAddCompleted(PDEVICE_OBJECT pPdo)
1321{
1322 RT_NOREF1(pPdo);
1323 VBOXUSBFLT_LOCK_ACQUIRE();
1324 vboxUsbFltSignalChangeLocked();
1325 VBOXUSBFLT_LOCK_RELEASE();
1326 return STATUS_SUCCESS;
1327}
1328
1329BOOLEAN VBoxUsbFltPdoIsFiltered(PDEVICE_OBJECT pPdo)
1330{
1331 VBOXUSBFLT_DEVSTATE enmState = VBOXUSBFLT_DEVSTATE_REMOVED;
1332 VBOXUSBFLT_LOCK_ACQUIRE();
1333
1334 PVBOXUSBFLT_DEVICE pDevice = vboxUsbFltDevGetLocked(pPdo);
1335 if (pDevice)
1336 enmState = pDevice->enmState;
1337
1338 VBOXUSBFLT_LOCK_RELEASE();
1339
1340 return enmState >= VBOXUSBFLT_DEVSTATE_CAPTURING;
1341}
1342
1343NTSTATUS VBoxUsbFltPdoRemove(PDEVICE_OBJECT pPdo)
1344{
1345 PVBOXUSBFLT_DEVICE pDevice;
1346 VBOXUSBFLT_DEVSTATE enmOldState;
1347
1348 VBOXUSBFLT_LOCK_ACQUIRE();
1349 pDevice = vboxUsbFltDevGetLocked(pPdo);
1350 if (pDevice)
1351 {
1352 RemoveEntryList(&pDevice->GlobalLe);
1353 enmOldState = pDevice->enmState;
1354 pDevice->enmState = VBOXUSBFLT_DEVSTATE_REMOVED;
1355 if (enmOldState != VBOXUSBFLT_DEVSTATE_REPLUGGING)
1356 {
1357 vboxUsbFltSignalChangeLocked();
1358 }
1359 else
1360 {
1361 /* the device *should* reappear, do signlling on re-appear only
1362 * to avoid extra signaling. still there might be a situation
1363 * when the device will not re-appear if it gets physically removed
1364 * before it re-appears
1365 * @todo: set a timer callback to do a notification from it */
1366 }
1367 }
1368 VBOXUSBFLT_LOCK_RELEASE();
1369 if (pDevice)
1370 vboxUsbFltDevRelease(pDevice);
1371 return STATUS_SUCCESS;
1372}
1373
1374HVBOXUSBFLTDEV VBoxUsbFltProxyStarted(PDEVICE_OBJECT pPdo)
1375{
1376 PVBOXUSBFLT_DEVICE pDevice;
1377 VBOXUSBFLT_LOCK_ACQUIRE();
1378 pDevice = vboxUsbFltDevGetLocked(pPdo);
1379 /*
1380 * Prevent a host crash when vboxUsbFltDevGetLocked fails to locate the matching PDO
1381 * in g_VBoxUsbFltGlobals.DeviceList (see @bugref{6509}).
1382 */
1383 if (pDevice == NULL)
1384 {
1385 WARN(("failed to get device for PDO(0x%p)", pPdo));
1386 }
1387 else if (pDevice->enmState = VBOXUSBFLT_DEVSTATE_CAPTURING)
1388 {
1389 pDevice->enmState = VBOXUSBFLT_DEVSTATE_CAPTURED;
1390 LOG(("The proxy notified proxy start for the captured device 0x%x", pDevice));
1391 vboxUsbFltDevRetain(pDevice);
1392 vboxUsbFltSignalChangeLocked();
1393 }
1394 else
1395 {
1396 WARN(("invalid state, %d", pDevice->enmState));
1397 pDevice = NULL;
1398 }
1399 VBOXUSBFLT_LOCK_RELEASE();
1400 return pDevice;
1401}
1402
1403void VBoxUsbFltProxyStopped(HVBOXUSBFLTDEV hDev)
1404{
1405 PVBOXUSBFLT_DEVICE pDevice = (PVBOXUSBFLT_DEVICE)hDev;
1406 /*
1407 * Prevent a host crash when VBoxUsbFltProxyStarted fails, returning NULL.
1408 * See @bugref{6509}.
1409 */
1410 if (pDevice == NULL)
1411 {
1412 WARN(("VBoxUsbFltProxyStopped called with NULL device pointer"));
1413 return;
1414 }
1415 VBOXUSBFLT_LOCK_ACQUIRE();
1416 if (pDevice->enmState == VBOXUSBFLT_DEVSTATE_CAPTURED
1417 || pDevice->enmState == VBOXUSBFLT_DEVSTATE_USED_BY_GUEST)
1418 {
1419 /* this is due to devie was physically removed */
1420 LOG(("The proxy notified proxy stop for the captured device 0x%x, current state %d", pDevice, pDevice->enmState));
1421 pDevice->enmState = VBOXUSBFLT_DEVSTATE_CAPTURING;
1422 vboxUsbFltSignalChangeLocked();
1423 }
1424 else
1425 {
1426 if (pDevice->enmState != VBOXUSBFLT_DEVSTATE_REPLUGGING)
1427 {
1428 WARN(("invalid state, %d", pDevice->enmState));
1429 }
1430 }
1431 VBOXUSBFLT_LOCK_RELEASE();
1432
1433 vboxUsbFltDevRelease(pDevice);
1434}
1435
1436NTSTATUS VBoxUsbFltInit()
1437{
1438 int rc = VBoxUSBFilterInit();
1439 if (RT_FAILURE(rc))
1440 {
1441 WARN(("VBoxUSBFilterInit failed, rc (%d)", rc));
1442 return STATUS_UNSUCCESSFUL;
1443 }
1444
1445 memset(&g_VBoxUsbFltGlobals, 0, sizeof (g_VBoxUsbFltGlobals));
1446 InitializeListHead(&g_VBoxUsbFltGlobals.DeviceList);
1447 InitializeListHead(&g_VBoxUsbFltGlobals.ContextList);
1448 InitializeListHead(&g_VBoxUsbFltGlobals.BlackDeviceList);
1449 vboxUsbFltBlDevPopulateWithKnownLocked();
1450 VBOXUSBFLT_LOCK_INIT();
1451 return STATUS_SUCCESS;
1452}
1453
1454NTSTATUS VBoxUsbFltTerm()
1455{
1456 bool bBusy = false;
1457 VBOXUSBFLT_LOCK_ACQUIRE();
1458 do
1459 {
1460 if (!IsListEmpty(&g_VBoxUsbFltGlobals.ContextList))
1461 {
1462 AssertFailed();
1463 bBusy = true;
1464 break;
1465 }
1466
1467 PLIST_ENTRY pNext = NULL;
1468 for (PLIST_ENTRY pEntry = g_VBoxUsbFltGlobals.DeviceList.Flink;
1469 pEntry != &g_VBoxUsbFltGlobals.DeviceList;
1470 pEntry = pNext)
1471 {
1472 pNext = pEntry->Flink;
1473 PVBOXUSBFLT_DEVICE pDevice = PVBOXUSBFLT_DEVICE_FROM_LE(pEntry);
1474 Assert(!pDevice->uFltId);
1475 Assert(!pDevice->pOwner);
1476 if (pDevice->cRefs != 1)
1477 {
1478 AssertFailed();
1479 bBusy = true;
1480 break;
1481 }
1482 }
1483 } while (0);
1484
1485 VBOXUSBFLT_LOCK_RELEASE()
1486
1487 if (bBusy)
1488 {
1489 return STATUS_DEVICE_BUSY;
1490 }
1491
1492 for (PLIST_ENTRY pEntry = g_VBoxUsbFltGlobals.DeviceList.Flink;
1493 pEntry != &g_VBoxUsbFltGlobals.DeviceList;
1494 pEntry = g_VBoxUsbFltGlobals.DeviceList.Flink)
1495 {
1496 RemoveEntryList(pEntry);
1497 PVBOXUSBFLT_DEVICE pDevice = PVBOXUSBFLT_DEVICE_FROM_LE(pEntry);
1498 pDevice->enmState = VBOXUSBFLT_DEVSTATE_REMOVED;
1499 vboxUsbFltDevRelease(pDevice);
1500 }
1501
1502 vboxUsbFltBlDevClearLocked();
1503
1504 VBOXUSBFLT_LOCK_TERM();
1505
1506 VBoxUSBFilterTerm();
1507
1508 return STATUS_SUCCESS;
1509}
1510
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette