USBMonFlt.cpp revision 59190ecd61435d19ba3515b876272aee7bd12298
2N/A#include "VBoxUSBFilterMgr.h"
#include <devguid.h>
#define szBusQueryCompatibleIDs L"USB\\Class_ff&SubClass_00&Prot_00\0USB\\Class_ff&SubClass_00\0USB\\Class_ff\0\0"
bool fForceGrab;
bool fDisableFilters;
NTSTATUS VBoxUSBGetDeviceDescription(PDEVICE_OBJECT pDevObj, USHORT *pusVendorId, USHORT *pusProductId, USHORT *pusRevision);
#define ACQUIRE_LOCK() \
#define RELEASE_LOCK() \
return STATUS_SUCCESS;
return STATUS_SUCCESS;
AssertMsgFailed(("SUPUSBFLT_IOCTL_USB_CHANGE: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
//// DebugPrint(("SUPUSBFLT_IOCTL_USB_CHANGE -> %d\n", DrvInstance.cUSBStateChange));
AssertMsgFailed(("SUPUSBFLT_IOCTL_GET_NUM_DEVICES: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
AssertMsgFailed(("SUPUSBFLT_IOCTL_CAPTURE_DEVICE: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
AssertMsgFailed(("SUPUSBFLT_IOCTL_RELEASE_DEVICE: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
AssertMsgFailed(("SUPUSBFLT_IOCTL_GET_VERSION: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
if (RT_UNLIKELY(!ioBuffer || inputBufferLength != sizeof(*pFilter) || outputBufferLength != sizeof(*pOut)))
AssertMsgFailed(("SUPUSBFLT_IOCTL_ADD_FILTER: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
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
DebugPrint(("VBoxUSBClient::addFilter: idVendor=%#x idProduct=%#x bcdDevice=%#x bDeviceClass=%#x bDeviceSubClass=%#x bDeviceProtocol=%#x bBus=%#x bPort=%#x\n",
AssertMsgFailed(("SUPUSBFLT_IOCTL_REMOVE_FILTER: Invalid input/output sizes. cbIn=%d expected %d. cbOut=%d expected %d.\n",
return status;
return STATUS_SUCCESS;
ACQUIRE_LOCK();
RELEASE_LOCK();
return STATUS_SUCCESS;
unsigned myxdigit(char c)
int index;
ACQUIRE_LOCK();
RELEASE_LOCK();
RELEASE_LOCK();
#ifdef DEBUG
pszDeviceId++;
if(*pszDeviceId == 0)
pszDeviceId++;
pszDeviceId++;
if(*pszDeviceId == 0)
pszDeviceId++;
ACQUIRE_LOCK();
RELEASE_LOCK();
RELEASE_LOCK();
for (int i=0;i<MAX_ATTACHED_USB_DEVICES;i++)
RELEASE_LOCK();
RELEASE_LOCK();
ACQUIRE_LOCK();
for (int i=0;i<MAX_ATTACHED_USB_DEVICES;i++)
RELEASE_LOCK();
RELEASE_LOCK();
ACQUIRE_LOCK();
for (int i=0;i<MAX_ATTACHED_USB_DEVICES;i++)
RELEASE_LOCK();
RELEASE_LOCK();
ACQUIRE_LOCK();
for (int i=0;i<MAX_ATTACHED_USB_DEVICES;i++)
RELEASE_LOCK();
RELEASE_LOCK();
/* If we manually release a device, then all filters will be temporarily disabled; Enable them again when the
/* If we manually capture a device, we are forced to grab the next device that arrives. Disable this mode here */
bool ret;
ACQUIRE_LOCK();
for (int i=0;i<MAX_ATTACHED_USB_DEVICES;i++)
RELEASE_LOCK();
return ret;
RELEASE_LOCK();
pIrp = IoBuildDeviceIoControlRequest(control_code, pDevObj, NULL, 0, NULL, 0, TRUE, &event, &io_status);
if (!pIrp)
return STATUS_INSUFFICIENT_RESOURCES;
return status;
NTSTATUS VBoxUSBGetDescriptor(PDEVICE_OBJECT pDevObj, void *buffer, int size, int type, int index, int language_id)
return STATUS_INSUFFICIENT_RESOURCES;
#ifdef DEBUG
DebugPrint(("VBoxUSBGetDescriptor: VBoxUSBSendIOCTL failed with %x (%x)\n", rc, urb->UrbHeader.Status));
return rc;
unsigned length;
*lang_id = 0;
goto fail;
fail:
return status;
NTSTATUS VBoxUSBGetStringDescriptor(PDEVICE_OBJECT pDevObj, char *dest, unsigned size, int index, int lang_id)
unsigned length;
if (index)
if (!pstrdescr)
goto fail;
status = VBoxUSBGetDescriptor(pDevObj, pstrdescr, length, USB_STRING_DESCRIPTOR_TYPE, index, lang_id);
goto fail;
fail:
if (pstrdescr)
return status;
goto fail;
status = VBoxUSBGetDescriptor(pDevObj, devdescr, sizeof(*devdescr), USB_DEVICE_DESCRIPTOR_TYPE, 0, 0);
goto fail;
DebugPrint(("Device pid=%x vid=%x rev=%x\n", devdescr->idVendor, devdescr->idProduct, devdescr->bcdDevice));
int langId;
goto fail;
status = VBoxUSBGetStringDescriptor(pDevObj, pFltDev->szSerial, sizeof(pFltDev->szSerial), devdescr->iSerialNumber, langId);
goto fail;
status = VBoxUSBGetStringDescriptor(pDevObj, pFltDev->szMfgName, sizeof(pFltDev->szMfgName), devdescr->iManufacturer, langId);
goto fail;
status = VBoxUSBGetStringDescriptor(pDevObj, pFltDev->szProduct, sizeof(pFltDev->szProduct), devdescr->iProduct, langId);
goto fail;
fail:
if (devdescr)
return status;
NTSTATUS VBoxUSBGetDeviceDescription(PDEVICE_OBJECT pDevObj, USHORT *pusVendorId, USHORT *pusProductId, USHORT *pusRevision)
goto fail;
status = VBoxUSBGetDescriptor(pDevObj, devdescr, sizeof(*devdescr), USB_DEVICE_DESCRIPTOR_TYPE, 0, 0);
goto fail;
DebugPrint(("Device pid=%x vid=%x rev=%x\n", devdescr->idVendor, devdescr->idProduct, devdescr->bcdDevice));
return STATUS_SUCCESS;
fail:
if (devdescr)
return status;
NTSTATUS VBoxUSBReplugDevice(USHORT usVendorId, USHORT usProductId, USHORT usRevision, bool fCaptured, bool *pfReplugged)
*pfReplugged = false;
DebugPrint(("IoGetDeviceObjectPointer for %s returned %p %p\n", szHubName, pHubDevObj, pHubFileObj));
if (!RtlCompareUnicodeString(&szStandardControllerName[j], &pHubDevObj->DriverObject->DriverName, TRUE /* case insensitive */))
DebugPrint(("Associated driver %wZ -> related dev obj=%p\n", pHubDevObj->DriverObject->DriverName, IoGetRelatedDeviceObject(pHubFileObj)));
&& pDevRelations)
VBoxUSBGetDeviceDescription(pDevRelations->Objects[k], &usPDOVendorId, &usPDOProductId, &usPDORevision);
*pfReplugged = true;
if (*pfReplugged == true)
if (*pfReplugged == true)
if (*pfReplugged == true)
return STATUS_SUCCESS;
bool fReplugged;
|| !fReplugged)
return status;
bool fReplugged;
|| !fReplugged)
return status;