亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? bulkdev.c

?? 支持USB2.0 BULK傳輸范例
?? C
?? 第 1 頁 / 共 3 頁
字號:
    else {

        KdPrint( ("BulkUsb_ResetPipe - failed\n"));
    }

    return ntStatus;
}

NTSTATUS
BulkUsb_ResetDevice(
    IN PDEVICE_OBJECT DeviceObject
    )
/*++
 
Routine Description:

    This routine invokes BulkUsb_ResetParentPort to reset the device

Arguments:

    DeviceObject - pointer to device object

Return Value:

    NT status value

--*/
{
    NTSTATUS ntStatus;
    ULONG    portStatus;

    KdPrint( ("BulkUsb_ResetDevice - begins\n"));

    ntStatus = BulkUsb_GetPortStatus(DeviceObject, &portStatus);

    if((NT_SUCCESS(ntStatus))                 &&
       (!(portStatus & USBD_PORT_ENABLED))    &&
       (portStatus & USBD_PORT_CONNECTED)) {

        ntStatus = BulkUsb_ResetParentPort(DeviceObject);
    }

    KdPrint( ("BulkUsb_ResetDevice - ends\n"));

    return ntStatus;
}

NTSTATUS
BulkUsb_GetPortStatus(
    IN PDEVICE_OBJECT DeviceObject,
    IN OUT PULONG     PortStatus
    )
/*++
 
Routine Description:

    This routine retrieves the status value

Arguments:

    DeviceObject - pointer to device object
    PortStatus - port status

Return Value:

    NT status value

--*/
{
    NTSTATUS           ntStatus;
    KEVENT             event;
    PIRP               irp;
    IO_STATUS_BLOCK    ioStatus;
    PIO_STACK_LOCATION nextStack;
    PDEVICE_EXTENSION  deviceExtension;

    //
    // initialize variables
    //
    deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
    *PortStatus = 0;

    KdPrint( ("BulkUsb_GetPortStatus - begins\n"));

    KeInitializeEvent(&event, NotificationEvent, FALSE);

    irp = IoBuildDeviceIoControlRequest(
                    IOCTL_INTERNAL_USB_GET_PORT_STATUS,
                    deviceExtension->TopOfStackDeviceObject,
                    NULL,
                    0,
                    NULL,
                    0,
                    TRUE,
                    &event,
                    &ioStatus);

    if(NULL == irp) {

        KdPrint( ("memory alloc for irp failed\n"));
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    nextStack = IoGetNextIrpStackLocation(irp);

    ASSERT(nextStack != NULL);

    nextStack->Parameters.Others.Argument1 = PortStatus;

    ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, irp);

    if(STATUS_PENDING == ntStatus) {

        KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
    }
    else {

        ioStatus.Status = ntStatus;
    }

    ntStatus = ioStatus.Status;

    KdPrint( ("BulkUsb_GetPortStatus - ends\n"));

    return ntStatus;
}

NTSTATUS
BulkUsb_ResetParentPort(
    IN PDEVICE_OBJECT DeviceObject
    )
/*++
 
Routine Description:

    This routine sends an IOCTL_INTERNAL_USB_RESET_PORT
    synchronously down the stack.

Arguments:

Return Value:

--*/
{
    NTSTATUS           ntStatus;
    KEVENT             event;
    PIRP               irp;
    IO_STATUS_BLOCK    ioStatus;
    PIO_STACK_LOCATION nextStack;
    PDEVICE_EXTENSION  deviceExtension;

    //
    // initialize variables
    //
    deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;

    KdPrint( ("BulkUsb_ResetParentPort - begins\n"));

    KeInitializeEvent(&event, NotificationEvent, FALSE);

    irp = IoBuildDeviceIoControlRequest(
                    IOCTL_INTERNAL_USB_RESET_PORT,
                    deviceExtension->TopOfStackDeviceObject,
                    NULL,
                    0,
                    NULL,
                    0,
                    TRUE,
                    &event,
                    &ioStatus);

    if(NULL == irp) {

        KdPrint( ("memory alloc for irp failed\n"));
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    nextStack = IoGetNextIrpStackLocation(irp);

    ASSERT(nextStack != NULL);

    ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, irp);

    if(STATUS_PENDING == ntStatus) {

        KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
    }
    else {

        ioStatus.Status = ntStatus;
    }

    ntStatus = ioStatus.Status;

    KdPrint( ("BulkUsb_ResetParentPort - ends\n"));

    return ntStatus;
}


NTSTATUS
SubmitIdleRequestIrp(
    IN PDEVICE_EXTENSION DeviceExtension
    )
/*++
 
Routine Description:

    This routine builds an idle request irp with an associated callback routine
    and a completion routine in the driver and passes the irp down the stack.

Arguments:

    DeviceExtension - pointer to device extension

Return Value:

    NT status value

--*/
{
    PIRP                    irp;
    NTSTATUS                ntStatus;
    KIRQL                   oldIrql;
    PUSB_IDLE_CALLBACK_INFO idleCallbackInfo;
    PIO_STACK_LOCATION      nextStack;

    //
    // initialize variables
    //
    
    irp = NULL;
    idleCallbackInfo = NULL;

    KdPrint( ("SubmitIdleRequest - begins\n"));

    ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);

    if(PowerDeviceD0 != DeviceExtension->DevPower) {

        ntStatus = STATUS_POWER_STATE_INVALID;

        goto SubmitIdleRequestIrp_Exit;
    }

    KeAcquireSpinLock(&DeviceExtension->IdleReqStateLock, &oldIrql);

    if(InterlockedExchange(&DeviceExtension->IdleReqPend, 1)) {

        KdPrint( ("Idle request pending..\n"));

        KeReleaseSpinLock(&DeviceExtension->IdleReqStateLock, oldIrql);

        ntStatus = STATUS_DEVICE_BUSY;

        goto SubmitIdleRequestIrp_Exit;
    }

    //
    // clear the NoIdleReqPendEvent because we are about 
    // to submit an idle request. Since we are so early
    // to clear this event, make sure that if we fail this
    // request we set back the event.
    //
    KeClearEvent(&DeviceExtension->NoIdleReqPendEvent);

    idleCallbackInfo = ExAllocatePool(NonPagedPool, 
                                      sizeof(struct _USB_IDLE_CALLBACK_INFO));

    if(idleCallbackInfo) {

        idleCallbackInfo->IdleCallback = IdleNotificationCallback;

        idleCallbackInfo->IdleContext = (PVOID)DeviceExtension;

        ASSERT(DeviceExtension->IdleCallbackInfo == NULL);

        DeviceExtension->IdleCallbackInfo = idleCallbackInfo;

        //
        // we use IoAllocateIrp to create an irp to selectively suspend the 
        // device. This irp lies pending with the hub driver. When appropriate
        // the hub driver will invoked callback, where we power down. The completion
        // routine is invoked when we power back.
        //
        irp = IoAllocateIrp(DeviceExtension->TopOfStackDeviceObject->StackSize,
                            FALSE);

        if(irp == NULL) {

            KdPrint( ("cannot build idle request irp\n"));

            KeSetEvent(&DeviceExtension->NoIdleReqPendEvent,
                       IO_NO_INCREMENT,
                       FALSE);

            InterlockedExchange(&DeviceExtension->IdleReqPend, 0);

            KeReleaseSpinLock(&DeviceExtension->IdleReqStateLock, oldIrql);

            ExFreePool(idleCallbackInfo);

            ntStatus = STATUS_INSUFFICIENT_RESOURCES;

            goto SubmitIdleRequestIrp_Exit;
        }

        nextStack = IoGetNextIrpStackLocation(irp);

        nextStack->MajorFunction = 
                    IRP_MJ_INTERNAL_DEVICE_CONTROL;

        nextStack->Parameters.DeviceIoControl.IoControlCode = 
                    IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION;

        nextStack->Parameters.DeviceIoControl.Type3InputBuffer =
                    idleCallbackInfo;

        nextStack->Parameters.DeviceIoControl.InputBufferLength =
                    sizeof(struct _USB_IDLE_CALLBACK_INFO);


        IoSetCompletionRoutine(irp, 
                               IdleNotificationRequestComplete,
                               DeviceExtension, 
                               TRUE, 
                               TRUE, 
                               TRUE);

        DeviceExtension->PendingIdleIrp = irp;

        //
        // we initialize the count to 2.
        // The reason is, if the CancelSelectSuspend routine manages
        // to grab the irp from the device extension, then the last of the
        // CancelSelectSuspend routine/IdleNotificationRequestComplete routine 
        // to execute will free this irp. We need to have this schema so that
        // 1. completion routine does not attempt to touch the irp freed by 
        //    CancelSelectSuspend routine.
        // 2. CancelSelectSuspend routine doesnt wait for ever for the completion
        //    routine to complete!
        //
        DeviceExtension->FreeIdleIrpCount = 2;

        KeReleaseSpinLock(&DeviceExtension->IdleReqStateLock, oldIrql);

        //
        // check if the device is idle.
        // A check here ensures that a race condition did not 
        // completely reverse the call sequence of SubmitIdleRequestIrp
        // and CancelSelectiveSuspend
        //

        if(!CanDeviceSuspend(DeviceExtension) ||
           PowerDeviceD0 != DeviceExtension->DevPower) {

            //
            // IRPs created using IoBuildDeviceIoControlRequest should be
            // completed by calling IoCompleteRequest and not merely 
            // deallocated.
            //
     
            KdPrint( ("Device is not idle\n"));

            KeAcquireSpinLock(&DeviceExtension->IdleReqStateLock, &oldIrql);

            DeviceExtension->IdleCallbackInfo = NULL;

            DeviceExtension->PendingIdleIrp = NULL;

            KeSetEvent(&DeviceExtension->NoIdleReqPendEvent,
                       IO_NO_INCREMENT,
                       FALSE);

            InterlockedExchange(&DeviceExtension->IdleReqPend, 0);

            KeReleaseSpinLock(&DeviceExtension->IdleReqStateLock, oldIrql);

            if(idleCallbackInfo) {

                ExFreePool(idleCallbackInfo);
            }

            //
            // it is still safe to touch the local variable "irp" here.
            // the irp has not been passed down the stack, the irp has
            // no cancellation routine. The worse position is that the
            // CancelSelectSuspend has run after we released the spin 
            // lock above. It is still essential to free the irp.
            //
            if(irp) {

                IoFreeIrp(irp);
            }

            goto SubmitIdleRequestIrp_Exit;
        }

        KdPrint( ("Cancel the timers\n"));
        //
        // Cancel the timer so that the DPCs are no longer fired.
        // Thus, we are making judicious usage of our resources.
        // we do not need DPCs because we already have an idle irp pending.
        // The timers are re-initialized in the completion routine.
        //
        KeCancelTimer(&DeviceExtension->Timer);

        ntStatus = IoCallDriver(DeviceExtension->TopOfStackDeviceObject, irp);

        if(!NT_SUCCESS(ntStatus)) {

            KdPrint( ("IoCallDriver failed\n"));

            goto SubmitIdleRequestIrp_Exit;
        }
    }
    else {

        KdPrint( ("Memory allocation for idleCallbackInfo failed\n"));

        KeSetEvent(&DeviceExtension->NoIdleReqPendEvent,
                   IO_NO_INCREMENT,
                   FALSE);

        InterlockedExchange(&DeviceExtension->IdleReqPend, 0);

        KeReleaseSpinLock(&DeviceExtension->IdleReqStateLock, oldIrql);

        ntStatus = STATUS_INSUFFICIENT_RESOURCES;
    }

SubmitIdleRequestIrp_Exit:

    KdPrint( ("SubmitIdleRequest - ends\n"));

    return ntStatus;
}


VOID
IdleNotificationCallback(
    IN PDEVICE_EXTENSION DeviceExtension
    )
/*++
 
Routine Description:

  "A pointer to a callback function in your driver is passed down the stack with
   this IOCTL, and it is this callback function that is called by USBHUB when it
   safe for your device to power down."

  "When the callback in your driver is called, all you really need to do is to
   to first ensure that a WaitWake Irp has been submitted for your device, if 
   remote wake is possible for your device and then request a SetD2 (or DeviceWake)"

Arguments:

    DeviceExtension - pointer to device extension

Return Value:

    NT status value

--*/
{
    NTSTATUS                ntStatus;
    POWER_STATE             powerState;
    KEVENT                  irpCompletionEvent;
    PIRP_COMPLETION_CONTEXT irpContext;

    KdPrint( ("IdleNotificationCallback - begins\n"));

    //
    // Dont idle, if the device was just disconnected or being stopped
    // i.e. return for the following DeviceState(s)
    // NotStarted, Stopped, PendingStop, PendingRemove, SurpriseRemoved, Removed
    //

    if(DeviceExtension->DeviceState != Working) {

        return;
    }

    //
    // If there is not already a WW IRP pending, submit one now
    //
    if(DeviceExtension->WaitWakeEnable) {

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
美女网站色91| 成人aa视频在线观看| 国产伦精品一区二区三区免费| 国产99久久久精品| 欧美成人激情免费网| 国产亚洲一本大道中文在线| 亚洲一区视频在线| 成人av在线播放网址| 91精品国产91热久久久做人人| 国产精品九色蝌蚪自拍| 韩国v欧美v日本v亚洲v| 91精品免费在线观看| 曰韩精品一区二区| 国产福利不卡视频| 日韩视频免费直播| 一区二区三区在线观看视频 | 日韩欧美精品在线| 中文字幕一区二区在线播放| 精久久久久久久久久久| 91精品国产欧美一区二区成人| 亚洲色大成网站www久久九九| 国产乱淫av一区二区三区 | 久久精品人人爽人人爽| 琪琪久久久久日韩精品| 欧美美女喷水视频| 五月婷婷另类国产| 欧美日高清视频| 亚洲高清在线精品| 欧美三电影在线| 亚洲第一会所有码转帖| 色综合久久中文字幕综合网| 亚洲欧美中日韩| 99久久99久久精品免费看蜜桃| 国产欧美va欧美不卡在线| 久久66热偷产精品| 久久综合精品国产一区二区三区| 另类的小说在线视频另类成人小视频在线| 欧美日韩一区二区三区四区五区| 亚洲福利一二三区| 欧美精品一级二级| 九色综合狠狠综合久久| 日韩久久久久久| 狠狠色丁香久久婷婷综合_中| 精品少妇一区二区三区在线视频| 国产精品自在欧美一区| 久久久亚洲精品石原莉奈| 国产激情偷乱视频一区二区三区| 国产午夜精品福利| 一本久久a久久免费精品不卡| 国产精品欧美久久久久无广告| 国产精品一区久久久久| 国产亚洲欧洲997久久综合| 99热精品国产| 亚洲高清免费观看高清完整版在线观看 | 精品奇米国产一区二区三区| 国产福利一区在线| 一区二区三区在线观看动漫| 欧美久久一二区| 国产精品一区在线观看你懂的| 国产精品无码永久免费888| 色偷偷久久人人79超碰人人澡| 亚洲第一综合色| 欧美精品一区二区在线播放| av激情亚洲男人天堂| 一区二区三区中文免费| 精品国产一区二区国模嫣然| 不卡一区二区中文字幕| 免费观看在线色综合| 国产精品毛片久久久久久| 欧美日韩在线观看一区二区| 国产精品一区二区男女羞羞无遮挡| 亚洲欧洲成人自拍| 精品国产亚洲在线| 欧美主播一区二区三区美女| 国产一区二区三区在线观看精品| 一区二区三区中文字幕电影| 26uuu国产在线精品一区二区| 欧洲精品一区二区| 国产91精品入口| 麻豆久久久久久| 亚洲高清视频的网址| 国产精品入口麻豆原神| 欧美岛国在线观看| 欧美色中文字幕| 99久久精品免费观看| 国产在线精品一区二区不卡了 | 国产精品麻豆久久久| 91性感美女视频| 日韩国产一二三区| 一级精品视频在线观看宜春院| 久久综合av免费| 欧美一级高清片在线观看| 色呦呦日韩精品| 成人天堂资源www在线| 老司机免费视频一区二区三区| 亚洲资源在线观看| 亚洲视频免费在线观看| 国产欧美视频在线观看| 久久综合狠狠综合| 欧美变态凌虐bdsm| 欧美一区二区成人| 日韩一级黄色大片| 欧美一区二区三区播放老司机| 欧美午夜片在线观看| 97久久久精品综合88久久| 风间由美性色一区二区三区| 国产麻豆91精品| 国产精品综合一区二区三区| 另类欧美日韩国产在线| 日本欧美肥老太交大片| 日韩精品一级二级| 国产亚洲成aⅴ人片在线观看| 日韩一级片网址| 国产精品影视网| 丝袜国产日韩另类美女| 久久女同互慰一区二区三区| 56国语精品自产拍在线观看| 91国偷自产一区二区三区观看| 成人免费看片app下载| 国产成人免费xxxxxxxx| 国产福利不卡视频| 成人app网站| 色八戒一区二区三区| 94-欧美-setu| 欧美三级电影在线看| 欧美丰满一区二区免费视频| 91精品国产91久久久久久一区二区 | 久久精品国产久精国产| 国产成人亚洲综合a∨婷婷| 国产成人精品亚洲日本在线桃色| 成人黄色av电影| 欧美第一区第二区| 国产欧美精品在线观看| 日韩伦理电影网| 亚洲国产欧美日韩另类综合| 男男视频亚洲欧美| 粉嫩13p一区二区三区| av爱爱亚洲一区| 欧美日韩一区二区三区在线看| 欧美久久高跟鞋激| 久久精品欧美一区二区三区不卡 | 成人欧美一区二区三区视频网页| 亚洲视频小说图片| 蜜桃av噜噜一区二区三区小说| 国产精品12区| 色呦呦日韩精品| 日韩欧美激情四射| 综合婷婷亚洲小说| 美女视频黄 久久| 91视频免费播放| 日韩欧美在线观看一区二区三区| 中文字幕av资源一区| 亚洲成人动漫在线免费观看| 国产综合久久久久久久久久久久| 91日韩在线专区| 久久一二三国产| 亚洲v日本v欧美v久久精品| 国产精品一区二区男女羞羞无遮挡| 色欧美88888久久久久久影院| 日韩免费高清av| 一区二区三区四区激情| 久久99国产精品久久99| 99久久精品免费观看| 欧美本精品男人aⅴ天堂| 亚洲视频电影在线| 韩国毛片一区二区三区| 97久久精品人人做人人爽50路| 欧美一区二区精品在线| 亚洲男人天堂av| 国产成人激情av| 日韩午夜在线播放| 图片区小说区国产精品视频| av成人老司机| 中文字幕精品一区| 国内精品在线播放| 在线电影一区二区三区| 亚洲免费观看在线视频| 福利一区二区在线| 日韩欧美高清一区| 成人欧美一区二区三区白人| 免费观看久久久4p| 欧美日韩视频在线第一区| 一区在线播放视频| 国产精品99久久久久久似苏梦涵 | av在线一区二区| 久久你懂得1024| 国产精一品亚洲二区在线视频| 日韩欧美一级片| 日韩精品乱码av一区二区| 欧美影院一区二区三区| 亚洲精品免费视频| 色婷婷亚洲综合| 亚洲美女精品一区| 一本一道久久a久久精品| 国产精品福利一区二区| 日韩女优毛片在线| 欧美一级日韩不卡播放免费| 亚洲在线中文字幕| 在线中文字幕一区| 亚洲一区二区三区四区在线免费观看 |