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

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

?? usblspwr.c

?? microsoft usb開發包,能夠給大家一個很好的參考.
?? C
?? 第 1 頁 / 共 3 頁
字號:
/*++

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

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
毛片一区二区三区| 偷拍亚洲欧洲综合| 精品国产髙清在线看国产毛片| 色噜噜狠狠一区二区三区果冻| 国产a精品视频| 99久久精品99国产精品| 99久久er热在这里只有精品66| 不卡一区二区在线| 日本高清不卡在线观看| 91福利精品第一导航| 在线免费观看日韩欧美| 欧美日韩一区二区三区四区| 欧美日韩国产精选| 欧美一区二区三区四区五区 | 一区二区三区四区av| 国产精品伦一区| 亚洲视频资源在线| 亚洲成人你懂的| 蜜桃精品在线观看| 国产高清亚洲一区| 色综合天天做天天爱| 欧美日韩亚洲高清一区二区| 日韩欧美一区在线观看| 久久精品水蜜桃av综合天堂| 国产精品麻豆视频| 爽爽淫人综合网网站| 久久99久久精品欧美| 成人sese在线| 欧美日韩免费在线视频| 精品国产乱码久久久久久1区2区| 欧美经典一区二区三区| 亚洲一级片在线观看| 国内成人精品2018免费看| 99久久婷婷国产综合精品电影| 欧美日韩另类一区| 久久九九99视频| 亚洲高清一区二区三区| 韩日精品视频一区| 欧美视频中文一区二区三区在线观看| 日韩精品中文字幕在线不卡尤物| 国产精品成人免费| 精品一区二区三区久久久| 91丨porny丨蝌蚪视频| 精品国产电影一区二区| 亚洲小说欧美激情另类| 国产另类ts人妖一区二区| 国产精品网站一区| 国产乱子伦视频一区二区三区 | 一本一本大道香蕉久在线精品| 欧美体内she精高潮| 久久久国际精品| 亚洲欧洲在线观看av| 亚洲精品福利视频网站| 国产精品福利一区| 在线免费观看视频一区| 日韩精品电影在线| 国产视频在线观看一区二区三区| 99久久99久久精品免费观看| 香蕉影视欧美成人| 久久综合九色综合久久久精品综合| 国产一区 二区 三区一级| 亚洲天天做日日做天天谢日日欢| 欧美日韩国产高清一区二区三区 | 欧美一级在线视频| 国产精品一卡二卡| 亚洲精品国久久99热| 日韩一区二区在线观看视频| 国产不卡高清在线观看视频| 亚洲欧洲国产日韩| 欧美一区二区三区免费| 91在线国产福利| 免费日本视频一区| 亚洲丝袜另类动漫二区| 精品国产免费一区二区三区四区 | 国产在线精品免费av| 国产精品欧美一区二区三区| 色屁屁一区二区| 极品销魂美女一区二区三区| 亚洲精品日韩综合观看成人91| 日韩一级精品视频在线观看| 91亚洲精华国产精华精华液| 六月丁香婷婷久久| 亚洲精选视频在线| 国产日产精品1区| 日韩视频在线你懂得| 在线免费观看视频一区| 成人免费高清视频| 精品亚洲国产成人av制服丝袜| 一区二区三区丝袜| 国产精品欧美久久久久一区二区| 欧美va亚洲va在线观看蝴蝶网| 在线免费观看成人短视频| 国产999精品久久久久久绿帽| 三级欧美韩日大片在线看| 亚洲欧美一区二区久久| 久久嫩草精品久久久精品一| 91.xcao| 在线观看精品一区| a在线播放不卡| 色婷婷香蕉在线一区二区| 国产一区欧美二区| 九九视频精品免费| 日韩va亚洲va欧美va久久| 亚洲综合在线五月| 亚洲丝袜美腿综合| 中文字幕亚洲一区二区va在线| 欧美不卡在线视频| 日韩你懂的在线播放| 日韩精品一区二区三区中文不卡 | 2024国产精品视频| 欧美丰满一区二区免费视频| 欧美偷拍一区二区| 欧美日韩第一区日日骚| 欧美日韩成人一区| 91精品国产综合久久精品麻豆 | 久久久久一区二区三区四区| 欧美成人三级电影在线| 亚洲精品一线二线三线无人区| 欧美日韩国产三级| 欧美一区二区播放| 日韩欧美二区三区| 欧美精品一区二区三区四区 | 国产成人亚洲综合a∨婷婷| 国产一区二区三区在线观看精品 | 久久精品国产精品亚洲综合| 裸体在线国模精品偷拍| 国产在线视频一区二区三区| 韩日精品视频一区| 成人av免费在线| 色嗨嗨av一区二区三区| 欧洲一区二区三区在线| 678五月天丁香亚洲综合网| 日韩欧美美女一区二区三区| 欧美成人猛片aaaaaaa| 国产偷国产偷精品高清尤物| 欧美激情一区不卡| 亚洲综合色视频| 六月丁香综合在线视频| 国产成人av自拍| 91麻豆文化传媒在线观看| 欧美日韩亚洲综合在线| 久久综合九色综合欧美亚洲| 中文字幕制服丝袜成人av| 亚洲一级电影视频| 久久成人免费网站| 成人av免费网站| 在线成人av网站| 国产女人18毛片水真多成人如厕 | 老汉av免费一区二区三区| 高清国产一区二区| 日韩免费性生活视频播放| 久久免费电影网| 亚洲在线观看免费视频| 美国毛片一区二区三区| 91女厕偷拍女厕偷拍高清| 欧美一级二级三级蜜桃| 国产精品日韩成人| 全国精品久久少妇| 9色porny自拍视频一区二区| 7777精品伊人久久久大香线蕉完整版| 久久久午夜电影| 五月婷婷久久丁香| 成人激情图片网| 91精品国产综合久久久蜜臀粉嫩| 日本一区二区成人| 免费成人在线网站| 日本高清免费不卡视频| 国产亚洲午夜高清国产拍精品| 亚洲图片欧美一区| 波多野结衣中文一区| 日韩欧美一区在线| 香蕉影视欧美成人| 91亚洲精品乱码久久久久久蜜桃 | 欧美久久久久中文字幕| 国产欧美日产一区| 久久精品国产精品青草| 欧美日韩视频在线一区二区| 国产精品久久久久影院| 精品一区二区三区在线观看国产| 91福利在线导航| 亚洲图片激情小说| 国产一区激情在线| 日韩片之四级片| 亚州成人在线电影| 91美女精品福利| 成人免费小视频| 成人深夜视频在线观看| 精品国内片67194| 丝瓜av网站精品一区二区| 91电影在线观看| 亚洲天堂a在线| 成人av电影在线观看| 怡红院av一区二区三区| 成人动漫在线一区| 国产欧美日韩三级| 国产成人综合网| 国产亚洲污的网站| 黄页视频在线91| 久久青草欧美一区二区三区| 国产自产2019最新不卡|