Ejemplo n.º 1
0
static NTSTATUS vboxUsbPnPMnRemoveDevice(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp)
{
    ENMVBOXUSB_PNPSTATE enmState = vboxUsbPnPStateGet(pDevExt);
    NTSTATUS Status = STATUS_SUCCESS;
    if (enmState != ENMVBOXUSB_PNPSTATE_SURPRISE_REMOVED)
    {
        Status = vboxUsbPnPRmDev(pDevExt);
        Assert(Status == STATUS_SUCCESS);
    }

    vboxUsbPnPStateSet(pDevExt, ENMVBOXUSB_PNPSTATE_REMOVED);

    vboxUsbDdiStateRelease(pDevExt);

    vboxUsbDdiStateReleaseAndWaitRemoved(pDevExt);

    vboxUsbRtClear(pDevExt);

    pIrp->IoStatus.Status = STATUS_SUCCESS;
    pIrp->IoStatus.Information = 0;
    IoSkipCurrentIrpStackLocation(pIrp);
    Status = IoCallDriver(pDevExt->pLowerDO, pIrp);

    IoDetachDevice(pDevExt->pLowerDO);
    IoDeleteDevice(pDevExt->pFDO);

    return Status;
}
Ejemplo n.º 2
0
DECLHIDDEN(NTSTATUS) vboxUsbDispatchPnP(IN PDEVICE_OBJECT pDeviceObject, IN PIRP pIrp)
{
    PVBOXUSBDEV_EXT pDevExt = (PVBOXUSBDEV_EXT)pDeviceObject->DeviceExtension;
    ENMVBOXUSB_PNPSTATE enmState = vboxUsbPnPStateGet(pDevExt);
    if (!vboxUsbDdiStateRetainIfNotRemoved(pDevExt))
    {
        return VBoxDrvToolIoComplete(pIrp, STATUS_DELETE_PENDING, 0);
    }

    PIO_STACK_LOCATION pSl = IoGetCurrentIrpStackLocation(pIrp);

    switch (pSl->MinorFunction)
    {
        case IRP_MN_START_DEVICE:
        {
            return vboxUsbPnPMnStartDevice(pDevExt, pIrp);
        }
        case IRP_MN_QUERY_STOP_DEVICE:
        {
            return vboxUsbPnPMnQueryStopDevice(pDevExt, pIrp);
        }
        case IRP_MN_STOP_DEVICE:
        {
            return vboxUsbPnPMnStopDevice(pDevExt, pIrp);
        }
        case IRP_MN_CANCEL_STOP_DEVICE:
        {
            return vboxUsbPnPMnCancelStopDevice(pDevExt, pIrp);
        }
        case IRP_MN_QUERY_REMOVE_DEVICE:
        {
            return vboxUsbPnPMnQueryRemoveDevice(pDevExt, pIrp);
        }
        case IRP_MN_REMOVE_DEVICE:
        {
            return vboxUsbPnPMnRemoveDevice(pDevExt, pIrp);
        }
        case IRP_MN_CANCEL_REMOVE_DEVICE:
        {
            return vboxUsbPnPMnCancelRemoveDevice(pDevExt, pIrp);
        }
        case IRP_MN_SURPRISE_REMOVAL:
        {
            return vboxUsbPnPMnSurpriseRemoval(pDevExt, pIrp);
        }
        case IRP_MN_QUERY_CAPABILITIES:
        {
            return vboxUsbPnPMnQueryCapabilities(pDevExt, pIrp);
        }
        default:
        {
            return vboxUsbPnPMnDefault(pDevExt, pIrp);
        }
    }
}
Ejemplo n.º 3
0
static NTSTATUS vboxUsbPnPMnCancelStopDevice(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp)
{
    ENMVBOXUSB_PNPSTATE enmState = vboxUsbPnPStateGet(pDevExt);
    NTSTATUS Status = STATUS_SUCCESS;

    IoCopyCurrentIrpStackLocationToNext(pIrp);
    Status = VBoxDrvToolIoPostSync(pDevExt->pLowerDO, pIrp);
    if (NT_SUCCESS(Status) && enmState == ENMVBOXUSB_PNPSTATE_STOP_PENDING)
    {
        vboxUsbPnPStateRestore(pDevExt);
    }

    Status = STATUS_SUCCESS;
    VBoxDrvToolIoComplete(pIrp, Status, 0);
    vboxUsbDdiStateRelease(pDevExt);

    return Status;
}
Ejemplo n.º 4
0
static NTSTATUS vboxUsbDispatchCreate(IN PDEVICE_OBJECT pDeviceObject, IN PIRP pIrp)
{
    PVBOXUSBDEV_EXT pDevExt = (PVBOXUSBDEV_EXT)pDeviceObject->DeviceExtension;
    NTSTATUS Status = STATUS_INVALID_HANDLE;
    do
    {
        if (vboxUsbPnPStateGet(pDevExt) != ENMVBOXUSB_PNPSTATE_STARTED)
        {
            Status = STATUS_INVALID_DEVICE_STATE;
            break;
        }

        PIO_STACK_LOCATION pSl = IoGetCurrentIrpStackLocation(pIrp);
        PFILE_OBJECT pFObj = pSl->FileObject;
        if (!pFObj)
        {
            Status = STATUS_INVALID_PARAMETER;
            break;
        }

        pFObj->FsContext = NULL;

        if (pFObj->FileName.Length)
        {
            Status = STATUS_INVALID_PARAMETER;
            break;
        }

        Status = vboxUsbRtCreate(pDevExt, pIrp);
        if (!NT_SUCCESS(Status))
        {
            AssertFailed();
            break;
        }

        ASMAtomicIncU32(&pDevExt->cHandles);
        Status = STATUS_SUCCESS;
        break;
    } while (0);

    Status = VBoxDrvToolIoComplete(pIrp, Status, 0);
    return Status;
}
Ejemplo n.º 5
0
static NTSTATUS vboxUsbPnPMnCancelRemoveDevice(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp)
{
    ENMVBOXUSB_PNPSTATE enmState = vboxUsbPnPStateGet(pDevExt);
    NTSTATUS Status = STATUS_SUCCESS;
    if (enmState == ENMVBOXUSB_PNPSTATE_REMOVE_PENDING)
    {
        IoCopyCurrentIrpStackLocationToNext(pIrp);
        Status = VBoxDrvToolIoPostSync(pDevExt->pLowerDO, pIrp);
        if (NT_SUCCESS(Status))
        {
            vboxUsbPnPStateRestore(pDevExt);
        }
    }
    else
    {
        Assert(0);
        Assert(enmState == ENMVBOXUSB_PNPSTATE_STARTED);
    }

    VBoxDrvToolIoComplete(pIrp, Status, 0);
    vboxUsbDdiStateRelease(pDevExt);

    return Status;
}