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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? usblspwr.c

?? 一個(gè)好用的MS的USB驅(qū)動(dòng)編程工具包,希望有用.
?? C
?? 第 1 頁 / 共 3 頁
字號(hào):
/*++

Copyright (c) 1999  Microsoft Corporation

Module Name:

    usblspwr.c 

Abstract:

    USB LS-120 Mass Storage Device Sample Driver
    Power Management module


Environment:

    kernel mode only

Notes:

  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  PURPOSE.

  Copyright (c) 1999 Microsoft Corporation.  All Rights Reserved.


Revision History:

    1/13/99: MRB	Adapted from the BULKUSB DDK sample.

--*/


#include "wdm.h"
#include "stdarg.h"
#include "stdio.h"

#include "usbdi.h"
#include "usbdlib.h"
#include "usbls120.h"


NTSTATUS
USBLS120_ProcessPowerIrp(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP           Irp
    )
/*++

Routine Description:

    This is our FDO's dispatch table function for IRP_MJ_POWER.
    It processes the Power IRPs sent to the PDO for this device.

    For every power IRP, drivers must call PoStartNextPowerIrp and use PoCallDriver
    to pass the IRP all the way down the driver stack to the underlying PDO.


Arguments:

    DeviceObject - pointer to our device object (FDO)

    Irp          - pointer to an I/O Request Packet

Return Value:

    NT status code

--*/
{

    PIO_STACK_LOCATION irpStack;
    NTSTATUS ntStatus = STATUS_SUCCESS;
    PDEVICE_EXTENSION deviceExtension;
    BOOLEAN fGoingToD0 = FALSE;
    POWER_STATE sysPowerState, desiredDevicePowerState;
    KEVENT event;

    USBLS120_KdPrint( DBGLVL_DEFAULT,(" USBLS120_ProcessPowerIrp() IRP_MJ_POWER\n"));

    deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
    irpStack = IoGetCurrentIrpStackLocation (Irp);
    USBLS120_IncrementIoCount(DeviceObject);

    switch (irpStack->MinorFunction) {

        case IRP_MN_WAIT_WAKE:

            USBLS120_KdPrint( DBGLVL_MEDIUM,("USBLS120_ProcessPowerIrp() Enter IRP_MN_WAIT_WAKE\n"));

            // A driver sends IRP_MN_WAIT_WAKE to indicate that the system should 
            // wait for its device to signal a wake event. The exact nature of the event
            // is device-dependent. 
            // Drivers send this IRP for two reasons: 
            // 1) To allow a device to wake the system
            // 2) To wake a device that has been put into a sleep state to save power
            //    but still must be able to communicate with its driver under certain circumstances. 
            // When a wake event occurs, the driver completes the IRP and returns 
            // STATUS_SUCCESS. If the device is sleeping when the event occurs, 
            // the driver must first wake up the device before completing the IRP. 
            // In a completion routine, the driver calls PoRequestPowerIrp to send a 
            // PowerDeviceD0 request. When the device has powered up, the driver can 
            //  handle the IRP_MN_WAIT_WAKE request.

            // deviceExtension->DeviceCapabilities.DeviceWake specifies the lowest device power state (least powered)
            // from which the device can signal a wake event 
            deviceExtension->PowerDownLevel = deviceExtension->DeviceCapabilities.DeviceWake;


            if  ( ( PowerDeviceD0 == deviceExtension->CurrentDevicePowerState )  ||
                  ( deviceExtension->DeviceCapabilities.DeviceWake > deviceExtension->CurrentDevicePowerState ) ) {
                //
                //    STATUS_INVALID_DEVICE_STATE is returned if the device in the PowerD0 state
                //    or a state below which it can support waking, or if the SystemWake state
                //    is below a state which can be supported. A pending IRP_MN_WAIT_WAKE will complete
                //    with this error if the device's state is changed to be incompatible with the wake 
                //    request.

                //  If a driver fails this IRP, it should complete the IRP immediately without
                //  passing the IRP to the next-lower driver.
                ntStatus = STATUS_INVALID_DEVICE_STATE;
                Irp->IoStatus.Status = ntStatus;
                IoCompleteRequest (Irp,IO_NO_INCREMENT );
                USBLS120_KdPrint( DBGLVL_HIGH, ( "Exit USBLS120_ProcessPowerIrp(), ntStatus STATUS_INVALID_DEVICE_STATE\n" ) );
                USBLS120_DecrementIoCount(DeviceObject);
                return ntStatus;
            }
       
            // flag we're enabled for wakeup
            deviceExtension->EnabledForWakeup = TRUE;

            // init an event for our completion routine to signal when PDO is done with this Irp
            KeInitializeEvent(&event, NotificationEvent, FALSE);

            // If not failing outright, pass this on to our PDO for further handling
            IoCopyCurrentIrpStackLocationToNext(Irp);

            // Set a completion routine so it can signal our event when
            //  the PDO is done with the Irp
            IoSetCompletionRoutine(
                Irp,
                USBLS120_IrpCompletionRoutine,
                &event,  // pass the event to the completion routine as the Context
                TRUE,    // invoke on success
                TRUE,    // invoke on error
                TRUE     // invoke on cancellation
                );

            PoStartNextPowerIrp(Irp);

            ntStatus = PoCallDriver(
                           deviceExtension->TopOfStackDeviceObject,
                           Irp
                           );

            // if PDO is not done yet, wait for the event to be set in our completion routine
            if (ntStatus == STATUS_PENDING) {

                // wait for irp to complete

                NTSTATUS waitStatus = KeWaitForSingleObject(
                                          &event,
                                          Suspended,
                                          KernelMode,
                                          FALSE,
                                          NULL
                                          );

                USBLS120_KdPrint( DBGLVL_MEDIUM,("USBLS120_ProcessPowerIrp() done waiting for PDO to finish IRP_MN_WAIT_WAKE\n"));
            }

            // now tell the device to actually wake up
            USBLS120_SelfSuspendOrActivate( DeviceObject, FALSE );

            // flag we're done with wakeup irp
            deviceExtension->EnabledForWakeup = FALSE;

            USBLS120_DecrementIoCount(DeviceObject);
      
            USBLS120_KdPrint( DBGLVL_MEDIUM,("USBLS120_ProcessPowerIrp() Exit IRP_MN_WAIT_WAKE\n"));
            break;

    case IRP_MN_SET_POWER:
    {

        // The system power policy manager sends this IRP to set the system power state. 
        // A device power policy manager sends this IRP to set the device power state for a device.

        USBLS120_KdPrint( DBGLVL_MEDIUM,("USBLS120_ProcessPowerIrp() Enter IRP_MN_SET_POWER\n"));

        // Set Irp->IoStatus.Status to STATUS_SUCCESS to indicate that the device
        // has entered the requested state. Drivers cannot fail this IRP.

        switch (irpStack->Parameters.Power.Type) {
            case SystemPowerState:

                // Get input system power state
                sysPowerState.SystemState = irpStack->Parameters.Power.State.SystemState;

                USBLS120_KdPrint( DBGLVL_MEDIUM,("USBLS120_ProcessPowerIrp() Set Power, type SystemPowerState = %s\n",
                    USBLS120_StringForSysState( sysPowerState.SystemState ) ));

                // If system is in working state always set our device to D0
                //  regardless of the wait state or system-to-device state power map
                if ( sysPowerState.SystemState ==  PowerSystemWorking) {
                    desiredDevicePowerState.DeviceState = PowerDeviceD0;

                    USBLS120_KdPrint( DBGLVL_MEDIUM,("USBLS120_ProcessPowerIrp() PowerSystemWorking, will set D0, not use state map\n"));
                } else {
                    // set to corresponding system state if IRP_MN_WAIT_WAKE pending
                    if ( deviceExtension->EnabledForWakeup ) { // got a WAIT_WAKE IRP pending?

                        // Find the device power state equivalent to the given system state.
                        // We get this info from the DEVICE_CAPABILITIES struct in our device
                        // extension (initialized in USBLS120_PnPAddDevice() )
                        desiredDevicePowerState.DeviceState =
                            deviceExtension->DeviceCapabilities.DeviceState[ sysPowerState.SystemState ];

                        USBLS120_KdPrint( DBGLVL_MEDIUM,("USBLS120_ProcessPowerIrp() IRP_MN_WAIT_WAKE pending, will use state map\n"));
                    } else {  
                        // if no wait pending and the system's not in working state, just turn off
                        desiredDevicePowerState.DeviceState = PowerDeviceD3;

                        USBLS120_KdPrint( DBGLVL_MEDIUM,("USBLS120_ProcessPowerIrp() Not EnabledForWakeup and the system's not in working state,\n  settting PowerDeviceD3 (off )\n"));
                    }
                }

                //
                // We've determined the desired device state; are we already in this state?
                //

                USBLS120_KdPrint( DBGLVL_MEDIUM,("USBLS120_ProcessPowerIrp() Set Power, desiredDevicePowerState = %s\n",
                    USBLS120_StringForDevState( desiredDevicePowerState.DeviceState ) ));

                if (desiredDevicePowerState.DeviceState !=
                    deviceExtension->CurrentDevicePowerState) {

                    // USBLS120_IncrementIoCount(DeviceObject);

                    // No, request that we be put into this state
                    // by requesting a new Power Irp from the Pnp manager
                    deviceExtension->PowerIrp = Irp;
                    ntStatus = PoRequestPowerIrp(
                                   deviceExtension->PhysicalDeviceObject,
                                   IRP_MN_SET_POWER,
                                   desiredDevicePowerState,
                                   // completion routine will pass the Irp down to the PDO
                                   USBLS120_PoRequestCompletion, 
                                   DeviceObject,
                                   NULL
                                   );

                } else {
                    // Yes, just pass it on to PDO (Physical Device Object)
                    IoCopyCurrentIrpStackLocationToNext(Irp);

                    PoStartNextPowerIrp(Irp);

                    ntStatus = PoCallDriver(
                                   deviceExtension->TopOfStackDeviceObject,
                                   Irp
                                   );

                    USBLS120_DecrementIoCount(DeviceObject);
                    USBLS120_KdPrint( DBGLVL_MEDIUM,("USBLS120_ProcessPowerIrp() Exit IRP_MN_SET_POWER\n"));

                }
                break;


            case DevicePowerState:

                USBLS120_KdPrint( DBGLVL_MEDIUM,("USBLS120_ProcessPowerIrp() Set Power, type DevicePowerState = %s\n",
                    USBLS120_StringForDevState( irpStack->Parameters.Power.State.DeviceState ) ));

                // For requests to D1, D2, or D3 ( sleep or off states ),
                // sets deviceExtension->CurrentDevicePowerState to DeviceState immediately.
                // This enables any code checking state to consider us as sleeping or off
                // already, as this will imminently become our state.

                // For requests to DeviceState D0 ( fully on ), sets fGoingToD0 flag TRUE
                // to flag that we must set a completion routine and update
                // deviceExtension->CurrentDevicePowerState there.
                // In the case of powering up to fully on, we really want to make sure
                // the process is completed before updating our CurrentDevicePowerState,
                // so no IO will be attempted or accepted before we're really ready.

                fGoingToD0 = USBLS120_SetDevicePowerState(
                                 DeviceObject,
                                 irpStack->Parameters.Power.State.DeviceState
                                 ); // returns TRUE for D0

                IoCopyCurrentIrpStackLocationToNext(Irp);

                if (fGoingToD0) {
                    USBLS120_KdPrint( DBGLVL_MEDIUM,("USBLS120_ProcessPowerIrp() Set PowerIrp Completion Routine, fGoingToD0 =%d\n", fGoingToD0));
                    IoSetCompletionRoutine(
                        Irp,
                        USBLS120_PowerIrp_Complete,
                        // Always pass FDO to completion routine as its Context;
                        // This is because the DriverObject passed by the system to the routine
                        // is the Physical Device Object ( PDO ) not the Functional Device Object ( FDO )
                        DeviceObject,
                        TRUE,            // invoke on success
                        TRUE,            // invoke on error
                        TRUE             // invoke on cancellation of the Irp
                        );
                }

                PoStartNextPowerIrp(Irp);

                ntStatus = PoCallDriver(
                               deviceExtension->TopOfStackDeviceObject,
                               Irp
                               );

                if ( !fGoingToD0 ) // completion routine will decrement
                    USBLS120_DecrementIoCount(DeviceObject);

                USBLS120_KdPrint( DBGLVL_MEDIUM,("USBLS120_ProcessPowerIrp() Exit IRP_MN_SET_POWER\n"));
                break;
            } /* case irpStack->Parameters.Power.Type */

        }
        break; /* IRP_MN_SET_POWER */


    case IRP_MN_QUERY_POWER:
        //
        // A power policy manager sends this IRP to determine whether it can change
        // the system or device power state, typically to go to sleep.
        //

        USBLS120_KdPrint( DBGLVL_MEDIUM,("USBLS120_ProcessPowerIrp() IRP_MN_QUERY_POWER\n"));

        // We do nothing special here, just let the PDO handle it
        IoCopyCurrentIrpStackLocationToNext(Irp);
        PoStartNextPowerIrp(Irp);

        ntStatus = PoCallDriver(
                       deviceExtension->TopOfStackDeviceObject,
                       Irp
                       );

        USBLS120_DecrementIoCount(DeviceObject);

        break; /* IRP_MN_QUERY_POWER */


    default:
        USBLS120_KdPrint( DBGLVL_MEDIUM,("USBLS120_ProcessPowerIrp() UNKNOWN POWER MESSAGE (%x)\n", irpStack->MinorFunction));

        //
        // All unhandled power messages are passed on to the PDO
        //

        IoCopyCurrentIrpStackLocationToNext(Irp);

        PoStartNextPowerIrp(Irp);

        ntStatus = PoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);

        USBLS120_DecrementIoCount(DeviceObject);

    } /* irpStack->MinorFunction */

    USBLS120_KdPrint( DBGLVL_MEDIUM,  ( "Exit USBLS120_ProcessPowerIrp()  ntStatus = 0x%x\n", ntStatus ) );
    return ntStatus;
}


NTSTATUS
USBLS120_PoRequestCompletion(
    IN PDEVICE_OBJECT       DeviceObject,
    IN UCHAR                MinorFunction,
    IN POWER_STATE          PowerState,
    IN PVOID                Context,
    IN PIO_STATUS_BLOCK     IoStatus
    )
/*++

Routine Description:

    This is the completion routine set in a call to PoRequestPowerIrp()
    that was made in USBLS120_ProcessPowerIrp() in response to receiving
    an IRP_MN_SET_POWER of type 'SystemPowerState' when the device was

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久精品一区二区三区不卡牛牛 | 国产区在线观看成人精品| 久久噜噜亚洲综合| 亚洲第一狼人社区| 色噜噜久久综合| 久久久久久久久久久久电影| 亚洲妇熟xx妇色黄| 97国产精品videossex| 国产午夜精品久久久久久久| 奇米精品一区二区三区四区| 在线观看不卡一区| 国产免费观看久久| 国产一区欧美日韩| 日韩欧美一级特黄在线播放| 丝袜美腿亚洲一区| 欧美午夜理伦三级在线观看| 中文字幕一区二区三区在线观看 | 日韩视频一区在线观看| 亚洲永久精品国产| 色av综合在线| 亚洲精品国产精华液| aaa欧美日韩| 中文字幕第一区综合| 国产精品一区二区在线看| 欧美成人欧美edvon| 免费一级欧美片在线观看| 欧美丰满嫩嫩电影| 五月天婷婷综合| 欧美精品一卡二卡| 蜜乳av一区二区| 日韩欧美在线观看一区二区三区| 日韩精品每日更新| 日韩午夜电影在线观看| 久久精品国产一区二区| 日韩免费看网站| 国产盗摄精品一区二区三区在线 | 一区二区三区国产豹纹内裤在线| 91丝袜国产在线播放| 亚洲欧美自拍偷拍| 91行情网站电视在线观看高清版| 一区二区三区影院| 欧美日韩国产首页| 免费看欧美美女黄的网站| 欧美一区二区三区免费在线看 | 成人黄色网址在线观看| 国产精品区一区二区三区| 99久久国产综合精品女不卡| 亚洲欧美国产毛片在线| 欧美日韩电影在线播放| 韩国中文字幕2020精品| 国产精品伦理一区二区| 日本久久一区二区三区| 午夜精品久久久久影视| 久久久久九九视频| 91蝌蚪porny成人天涯| 天天色天天操综合| 欧美大片一区二区三区| 成人午夜在线播放| 亚洲一区二区av在线| 精品国产sm最大网站免费看| 9i看片成人免费高清| 日本特黄久久久高潮| 国产精品高潮久久久久无| 欧美日韩国产综合视频在线观看| 国产激情一区二区三区| 亚洲一区二区在线视频| 久久色在线观看| 色先锋资源久久综合| 久久99国产精品久久| 亚洲免费视频中文字幕| 337p粉嫩大胆噜噜噜噜噜91av | 欧美精品亚洲一区二区在线播放| 精品亚洲成a人| 一区二区三区电影在线播| 欧美大片一区二区| 欧美性生活影院| 国产91在线|亚洲| 午夜激情一区二区三区| 1024成人网| 国产亚洲视频系列| 91麻豆精品国产91久久久资源速度 | 一区二区日韩av| 国产欧美一区二区三区网站| 欧美日韩国产精品成人| 97精品久久久久中文字幕 | 精品国产凹凸成av人导航| 欧美中文字幕一区二区三区亚洲| 国产中文一区二区三区| 国产成人精品免费视频网站| 日本色综合中文字幕| 亚洲精品免费一二三区| 国产精品久久久久影院亚瑟 | 综合精品久久久| 久久久一区二区三区| 欧美一级精品大片| 欧美日韩精品电影| 99精品黄色片免费大全| 国产成人av影院| 日本欧美韩国一区三区| 亚洲欧美偷拍另类a∨色屁股| 久久久噜噜噜久久中文字幕色伊伊| 欧美久久久一区| 在线一区二区视频| 一本大道久久a久久综合| 成人a级免费电影| 极品美女销魂一区二区三区免费| 天堂蜜桃一区二区三区| 一区二区三区四区乱视频| 亚洲日本va午夜在线影院| 中文一区二区完整视频在线观看 | 欧美一级欧美三级| 538在线一区二区精品国产| 欧美亚洲国产bt| 在线观看视频91| 精品视频999| 欧美肥大bbwbbw高潮| 欧美日韩国产电影| 日韩视频中午一区| 欧美va亚洲va| 国产亚洲一二三区| 国产精品欧美极品| 亚洲日本在线a| 亚洲精品乱码久久久久久黑人| 亚洲男人电影天堂| 亚洲成人av一区二区| 亚洲成人av资源| 久久er精品视频| 国产成人高清在线| 91蜜桃在线免费视频| 色婷婷国产精品| 91精品国产免费| 精品精品国产高清一毛片一天堂| 2021国产精品久久精品| 中文字幕一区在线| 亚洲电影一级黄| 麻豆国产欧美一区二区三区| 国产福利不卡视频| 色婷婷一区二区| 日韩一区二区三| 国产日产欧美一区二区视频| 亚洲欧美偷拍另类a∨色屁股| 亚洲成人精品一区二区| 韩国三级在线一区| 91社区在线播放| 日韩欧美黄色影院| 中文字幕一区三区| 日韩av电影免费观看高清完整版 | 日韩一区二区三区四区| 国产亚洲一区二区在线观看| 一区二区三区在线视频观看 | 99国产精品久| 在线电影一区二区三区| 久久久久国产精品人| 亚洲一区二区三区三| 久久99热这里只有精品| 91在线看国产| 日韩欧美中文一区二区| 一区二区三区在线观看欧美 | 日日夜夜精品免费视频| 风流少妇一区二区| 欧美美女激情18p| 欧美国产激情二区三区| 日韩电影免费一区| 91免费视频观看| 久久这里只有精品6| 亚洲综合在线免费观看| 国产a精品视频| 日韩你懂的在线播放| 亚洲成人手机在线| 99久精品国产| 国产视频一区二区在线观看| 青青草一区二区三区| 欧美日韩在线播放一区| 亚洲欧洲av色图| 丰满亚洲少妇av| 日韩免费高清av| 天天综合色天天| 欧美亚洲综合一区| 亚洲另类一区二区| 岛国精品在线观看| 国产三级三级三级精品8ⅰ区| 五月综合激情网| 在线观看www91| 一区二区三区在线视频免费观看 | 在线综合视频播放| 亚洲一区在线观看网站| 99精品久久久久久| 国产精品久久久久一区二区三区 | 免费看精品久久片| 欧美日本不卡视频| 亚洲国产精品嫩草影院| 色天天综合久久久久综合片| 中文字幕亚洲一区二区va在线| 国产激情一区二区三区桃花岛亚洲| 精品国偷自产国产一区| 另类小说色综合网站| 欧美xfplay| 国产美女视频91| 国产欧美一区二区精品秋霞影院| 国产酒店精品激情|