VirtualBox

Ignore:
Timestamp:
May 7, 2011 8:19:55 PM (14 years ago)
Author:
vboxsync
Message:

usb: device capture filter & enum fixes

Location:
trunk/src/VBox/HostDrivers/VBoxUSB/win
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxUSB/win/dev/VBoxUsbDev.h

    r36968 r36998  
    2727
    2828extern VBOXUSB_GLOBALS g_VBoxUsbGlobals;
    29 
    30 typedef struct VBOXUSB_IOSTATE
    31 {
    32     volatile uint32_t cRefs;
    33 } VBOXUSB_IOSTATE, *PVBOXUSB_IOSTATE;
    3429
    3530/* pnp state decls */
  • trunk/src/VBox/HostDrivers/VBoxUSB/win/lib/VBoxUsbLib-win.cpp

    r36968 r36998  
    354354    if (!DeviceIoControl(hHub, IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME, &Name, sizeof (Name), &Name, sizeof (Name), &cbReturned, NULL))
    355355    {
     356#ifdef DEBUG_misha
    356357        DWORD winEr = GetLastError();
    357358        AssertMsgFailed((__FUNCTION__": DeviceIoControl 1 fail winEr (%d)\n", winEr));
     359#endif
    358360        return VERR_GENERAL_FAILURE;
    359361    }
     
    761763    if (RT_FAILURE(rc))
    762764    {
    763         AssertMsgFailed((__FUNCTION__": usbLibDevStrDriverKeyGet failed\n"));
    764765        return rc;
    765766    }
     
    889890static int usbLibMonDevicesUpdate(PVBOXUSBGLOBALSTATE pGlobal, PUSBDEVICE pDevs, uint32_t cDevs, PVBOXUSB_DEV pDevInfos, uint32_t cDevInfos)
    890891{
     892    PUSBDEVICE pDevsHead = pDevs;
    891893    for (; pDevInfos; pDevInfos = pDevInfos->pNext)
    892894    {
    893         for (; pDevs; pDevs = pDevs->pNext)
     895        for (pDevs = pDevsHead; pDevs; pDevs = pDevs->pNext)
    894896        {
    895897            if (usbLibMonDevicesCmp(pDevs, pDevInfos))
  • trunk/src/VBox/HostDrivers/VBoxUSB/win/mon/VBoxUsbFlt.cpp

    r36968 r36998  
    459459}
    460460
    461 static bool vboxUsbFltDevCheckReplugLocked(PVBOXUSBFLT_DEVICE pDevice)
    462 {
     461static bool vboxUsbFltDevCheckReplugLocked(PVBOXUSBFLT_DEVICE pDevice, PVBOXUSBFLTCTX pContext)
     462{
     463    Assert(pContext);
     464
     465    /* check if device is already replugging */
    463466    if (pDevice->enmState <= VBOXUSBFLT_DEVSTATE_ADDED)
    464467    {
     468        /* it is, do nothing */
    465469        Assert(pDevice->enmState == VBOXUSBFLT_DEVSTATE_REPLUGGING);
     470        return false;
     471    }
     472
     473    if (pDevice->pOwner && pContext != pDevice->pOwner)
     474    {
     475        /* this device is owned by another context, we're not allowed to do anything */
    466476        return false;
    467477    }
     
    474484            false, /* do not remove a one-shot filter */
    475485            &fFilter, &fIsOneShot);
    476     if (pDevice->pOwner && pDevice->uFltId && pNewOwner != pDevice->pOwner)
    477     {
    478         /* the device is owned by another context by a valid filter */
     486    if (pDevice->pOwner && pNewOwner && pDevice->pOwner != pNewOwner)
     487    {
     488        /* the device is owned by another owner, we can not change the owner here */
    479489        return false;
    480490    }
     
    488498            if (fIsOneShot)
    489499            {
     500                Assert(pNewOwner);
    490501                /* remove a one-shot filter and keep the original filter data */
    491502                int tmpRc = VBoxUSBFilterRemove(pNewOwner, uId);
    492503                AssertRC(tmpRc);
     504                if (!pDevice->pOwner)
     505                {
     506                    /* update owner for one-shot if the owner is changed (i.e. assigned) */
     507                    vboxUsbFltDevOwnerUpdateLocked(pDevice, pNewOwner, uId, true);
     508                }
    493509            }
    494510            else
    495511            {
    496                 vboxUsbFltDevOwnerUpdateLocked(pDevice, pNewOwner, uId, false);
     512                if (pNewOwner)
     513                {
     514                    vboxUsbFltDevOwnerUpdateLocked(pDevice, pNewOwner, uId, false);
     515                }
    497516            }
    498517        }
    499518        else
    500519        {
    501             /* the device is currently filtered, while it should not, replug needed */
    502             bNeedReplug = true;
     520            /* the device is currently filtered, we should release it only if it is NOT grabbed by a one-shot filter */
     521            if (!pDevice->pOwner || !pDevice->fIsFilterOneShot)
     522            {
     523                bNeedReplug = true;
     524            }
    503525        }
    504526    }
    505527    else
    506528    {
    507         /* the device should NOT be filtered, check the current state  */
     529        /* the device should be filtered, check the current state  */
    508530        Assert(uId);
    509531        Assert(pNewOwner);
     
    527549            else
    528550            {
     551                Assert(!pDevice->pOwner);
    529552                /* the device needs to be filtered, but the owner changes, replug needed */
    530553                bNeedReplug = true;
     
    533556        else
    534557        {
    535             /* the device is currently NOT filtered, while it should, replug needed */
    536             bNeedReplug = true;
     558            /* the device is currently NOT filtered, we should replug it only if it is NOT grabbed by a one-shot filter */
     559            if (!pDevice->pOwner || !pDevice->fIsFilterOneShot)
     560            {
     561                bNeedReplug = true;
     562            }
    537563        }
    538564    }
     
    564590}
    565591
    566 NTSTATUS VBoxUsbFltFilterCheck()
     592NTSTATUS VBoxUsbFltFilterCheck(PVBOXUSBFLTCTX pContext)
    567593{
    568594    NTSTATUS Status;
     
    635661                                if (pDevice)
    636662                                {
    637                                     bool bReplug = vboxUsbFltDevCheckReplugLocked(pDevice);
     663                                    bool bReplug = vboxUsbFltDevCheckReplugLocked(pDevice, pContext);
    638664                                    if (bReplug)
    639665                                    {
     
    757783        vboxUsbFltDevOwnerClearLocked(pDevice);
    758784
    759         if (vboxUsbFltDevCheckReplugLocked(pDevice))
     785        if (vboxUsbFltDevCheckReplugLocked(pDevice, pContext))
    760786        {
    761787            InsertHeadList(&ReplugDevList, &pDevice->RepluggingLe);
     
    856882            continue;
    857883
    858         Assert(pDevice->pOwner);
     884        Assert(pDevice->pOwner == pContext);
     885        if (pDevice->pOwner != pContext)
     886            continue;
     887
    859888        Assert(!pDevice->fIsFilterOneShot);
    860889        pDevice->uFltId = 0;
     890        /* clear the fIsFilterOneShot flag to ensure the device is replugged on the next VBoxUsbFltFilterCheck call */
     891        pDevice->fIsFilterOneShot = false;
    861892    }
    862893    VBOXUSBFLT_LOCK_RELEASE();
  • trunk/src/VBox/HostDrivers/VBoxUSB/win/mon/VBoxUsbFlt.h

    r36968 r36998  
    3838int VBoxUsbFltRemove(PVBOXUSBFLTCTX pContext, uintptr_t uId);
    3939NTSTATUS VBoxUsbFltSetNotifyEvent(PVBOXUSBFLTCTX pContext, HANDLE hEvent);
    40 NTSTATUS VBoxUsbFltFilterCheck();
     40NTSTATUS VBoxUsbFltFilterCheck(PVBOXUSBFLTCTX pContext);
    4141
    4242NTSTATUS VBoxUsbFltGetDevice(PVBOXUSBFLTCTX pContext, HVBOXUSBDEVUSR hDevice, PUSBSUP_GETDEV_MON pInfo);
  • trunk/src/VBox/HostDrivers/VBoxUSB/win/mon/VBoxUsbMon.cpp

    r36968 r36998  
    862862static NTSTATUS VBoxUsbMonRunFilters(PVBOXUSBMONCTX pContext)
    863863{
    864     NTSTATUS Status = VBoxUsbFltFilterCheck();
     864    NTSTATUS Status = VBoxUsbFltFilterCheck(&pContext->FltCtx);
    865865    return Status;
    866866}
Note: See TracChangeset for help on using the changeset viewer.

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