VBoxUsbFlt.cpp revision 6cb6e43f3a668826e9b9d00102f7dee1299589e7
2362N/A * available from http://www.virtualbox.org. This file is free software;
0N/A#include "VBoxUsbMon.h"
0N/A#include "../cmn/VBoxUsbTool.h"
0N/A#include "VBoxUSBFilterMgr.h"
0N/A#define szBusQueryCompatibleIDs L"USB\\Class_ff&SubClass_00&Prot_00\0USB\\Class_ff&SubClass_00\0USB\\Class_ff\0\0"
0N/A * | ->---> CAPTURED ---------------------->| by "real" removal | the device info is removed form the list)
0N/Atypedef struct VBOXUSBFLT_DEVICE
0N/A bool fIsFilterOneShot;
0N/A /* The device state. If the non-owner session is requesting the state while the device is grabbed,
0N/A#define PVBOXUSBFLT_DEVICE_FROM_LE(_pLe) ( (PVBOXUSBFLT_DEVICE)( ((uint8_t*)(_pLe)) - RT_OFFSETOF(VBOXUSBFLT_DEVICE, GlobalLe) ) )
0N/A#define PVBOXUSBFLT_DEVICE_FROM_REPLUGGINGLE(_pLe) ( (PVBOXUSBFLT_DEVICE)( ((uint8_t*)(_pLe)) - RT_OFFSETOF(VBOXUSBFLT_DEVICE, RepluggingLe) ) )
0N/A#define PVBOXUSBFLTCTX_FROM_LE(_pLe) ( (PVBOXUSBFLTCTX)( ((uint8_t*)(_pLe)) - RT_OFFSETOF(VBOXUSBFLTCTX, ListEntry) ) )
0N/Atypedef struct VBOXUSBFLT_LOCK
0N/A#define VBOXUSBFLT_LOCK_INIT() \
0N/A#define VBOXUSBFLT_LOCK_TERM() do { } while (0)
0N/A#define VBOXUSBFLT_LOCK_ACQUIRE() \
0N/A#define VBOXUSBFLT_LOCK_RELEASE() \
0N/Atypedef struct VBOXUSBFLTGLOBALS
0N/Astatic void vboxUsbFltDevOwnerSetLocked(PVBOXUSBFLT_DEVICE pDevice, PVBOXUSBFLTCTX pContext, uintptr_t uFltId, bool fIsOneShot)
0N/Astatic void vboxUsbFltDevOwnerUpdateLocked(PVBOXUSBFLT_DEVICE pDevice, PVBOXUSBFLTCTX pContext, uintptr_t uFltId, bool fIsOneShot)
0N/A#ifdef DEBUG_mista
0N/A NTSTATUS Status = VBoxUsbToolIoInternalCtlSendSync(pDo, IOCTL_INTERNAL_USB_CYCLE_PORT, NULL, NULL);
0N/Astatic PVBOXUSBFLTCTX vboxUsbFltDevMatchLocked(PVBOXUSBFLT_DEVICE pDevice, uintptr_t *puId, bool fRemoveFltIfOneShot, bool *pfFilter, bool *pfIsOneShot)
0N/A *pfIsOneShot = false;
0N/A PVBOXUSBFLTCTX pOwner = VBoxUSBFilterMatchEx(&DevFlt, puId, fRemoveFltIfOneShot, pfFilter, pfIsOneShot);
static NTSTATUS vboxUsbFltDevPopulate(PVBOXUSBFLT_DEVICE pDevice, PDEVICE_OBJECT pDo /*, BOOLEAN bPopulateNonFilterProps*/)
return STATUS_INSUFFICIENT_RESOURCES;
int langId;
Status = VBoxUsbToolGetStringDescriptorA(pDo, pDevice->szSerial, sizeof (pDevice->szSerial), pDevDr->iSerialNumber, langId);
Status = VBoxUsbToolGetStringDescriptorA(pDo, pDevice->szMfgName, sizeof (pDevice->szMfgName), pDevDr->iManufacturer, langId);
Status = VBoxUsbToolGetStringDescriptorA(pDo, pDevice->szProduct, sizeof (pDevice->szProduct), pDevDr->iProduct, langId);
&cbRegKeyBuf);
return Status;
static void vboxUsbFltSignalChangeLocked()
bool bNeedReplug = false;
bool fFilter = false;
bool fIsOneShot = false;
if (!fFilter)
if (fIsOneShot)
if (pNewOwner)
bNeedReplug = true;
if (fIsOneShot)
bNeedReplug = true;
bNeedReplug = true;
if (bNeedReplug)
return bNeedReplug;
if (!RtlCompareUnicodeString(&szStandardControllerName[j], &pHubDevObj->DriverObject->DriverName, TRUE /* case insensitive */))
#ifdef DEBUG
AssertFailed();
bool fIsHub = false;
if (!RtlCompareUnicodeString(&szStandardControllerName[z], &pDevObj->DriverObject->DriverName, TRUE /* case insensitive */))
fIsHub = true;
if (fIsHub)
if (pDevice)
if (bReplug)
--cReplugPdos;
Status = vboxUsbFltDevPopulate(&Device, pDevRelations->Objects[k] /*, FALSE /* only need filter properties */);
bool fFilter = false;
bool fIsOneShot = false;
if (!fFilter)
--cReplugPdos;
if (cReplugPdos)
if (!--cReplugPdos)
return STATUS_SUCCESS;
return STATUS_SUCCESS;
return STATUS_SUCCESS;
*pId = 0;
USBFilterGetString(pFilter, USBFILTERIDX_MANUFACTURER_STR) ? USBFilterGetString(pFilter, USBFILTERIDX_MANUFACTURER_STR) : "<null>",
USBFilterGetString(pFilter, USBFILTERIDX_PRODUCT_STR) ? USBFilterGetString(pFilter, USBFILTERIDX_PRODUCT_STR) : "<null>",
USBFilterGetString(pFilter, USBFILTERIDX_SERIAL_NUMBER_STR) ? USBFilterGetString(pFilter, USBFILTERIDX_SERIAL_NUMBER_STR) : "<null>"));
#ifdef DEBUG
Log(("VBoxUSBClient::addFilter: idVendor=%#x idProduct=%#x bcdDevice=%#x bDeviceClass=%#x bDeviceSubClass=%#x bDeviceProtocol=%#x bBus=%#x bPort=%#x\n",
return rc;
AssertFailed();
return rc;
/* clear the fIsFilterOneShot flag to ensure the device is replugged on the next VBoxUsbFltFilterCheck call */
return rc;
if (hEvent)
NULL);
return Status;
if (pOldEvent)
return STATUS_SUCCESS;
AssertFailed();
return USBDEVICESTATE_USED_BY_HOST;
return USBDEVICESTATE_USED_BY_HOST;
return USBDEVICESTATE_HELD_BY_PROXY;
return USBDEVICESTATE_USED_BY_GUEST;
AssertFailed();
return USBDEVICESTATE_UNSUPPORTED;
static void vboxUsbDevToUserInfo(PVBOXUSBFLTCTX pContext, PVBOXUSBFLT_DEVICE pDevice, PUSBSUP_DEVINFO pDevInfo)
NTSTATUS VBoxUsbFltGetDevice(PVBOXUSBFLTCTX pContext, HVBOXUSBDEVUSR hDevice, PUSBSUP_GETDEV_MON pInfo)
return STATUS_SUCCESS;
AssertFailed();
return STATUS_INVALID_PARAMETER;
if (pDevice)
return STATUS_SUCCESS;
if (!pDevice)
AssertFailed();
return STATUS_NO_MEMORY;
AssertFailed();
return Status;
bool fFilter = false;
bool fIsOneShot = false;
if (pTmpDev)
return STATUS_SUCCESS;
if (fFilter)
if (pCtx)
return STATUS_SUCCESS;
return STATUS_SUCCESS;
if (pDevice)
if (pDevice)
if (pDevice)
return STATUS_SUCCESS;
AssertFailed();
return pDevice;
return STATUS_UNSUCCESSFUL;
return STATUS_SUCCESS;
bool bBusy = false;
AssertFailed();
bBusy = true;
AssertFailed();
bBusy = true;
if (bBusy)
return STATUS_DEVICE_BUSY;
return STATUS_SUCCESS;