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

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

?? usblspwr.c

?? 參考著寫其他的驅(qū)動程序就可以了。
?? 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

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91伊人久久大香线蕉| 黄色成人免费在线| 欧洲一区二区三区免费视频| **欧美大码日韩| 色网站国产精品| 亚洲国产一区在线观看| 欧美视频一区二区| 秋霞av亚洲一区二区三| 日韩一区二区三区电影| 国产真实乱对白精彩久久| 国产欧美一区二区精品忘忧草 | 在线成人av网站| 日本午夜一区二区| 久久综合色播五月| www.av精品| 无码av免费一区二区三区试看| 日韩欧美一级二级三级久久久| 国产剧情一区在线| 亚洲欧美福利一区二区| 欧美日高清视频| 国产精品影视在线| 亚洲激情五月婷婷| 欧美不卡在线视频| 色婷婷综合久久久中文一区二区| 亚洲国产视频a| 国产日韩av一区| 欧美色图在线观看| 国产精品自拍网站| 亚洲欧美一区二区久久| 精品国产免费人成在线观看| av成人老司机| 精品一区二区在线看| 亚洲色图制服诱惑| 精品久久一区二区三区| 色综合天天综合| 国产中文一区二区三区| 亚洲一卡二卡三卡四卡无卡久久| 久久综合九色综合97婷婷| 91成人免费在线视频| 久久aⅴ国产欧美74aaa| 夜夜精品视频一区二区| 国产午夜精品在线观看| 欧美日韩中文另类| 99精品在线观看视频| 久久超碰97中文字幕| 亚洲综合男人的天堂| 国产日韩精品一区二区浪潮av | av爱爱亚洲一区| 男男成人高潮片免费网站| 国产精品福利影院| 精品成人佐山爱一区二区| 在线免费观看成人短视频| 国产成人亚洲综合a∨婷婷| 日本视频在线一区| 亚洲主播在线播放| 亚洲女人小视频在线观看| 久久久久久久综合日本| 欧美一区二区免费| 欧美日韩高清一区二区| 色欧美片视频在线观看 | 蜜臀av亚洲一区中文字幕| 亚洲欧美视频在线观看| 国产精品理伦片| 国产拍欧美日韩视频二区| 日韩精品一区二区三区中文不卡| 欧美日韩国产电影| 欧美日韩一级视频| 欧美日韩小视频| 欧美日本一区二区三区| 在线免费视频一区二区| 日本电影欧美片| 91看片淫黄大片一级| 成人黄页在线观看| av综合在线播放| 色综合色综合色综合色综合色综合| 国产成人av影院| 成人丝袜视频网| 成人国产在线观看| 91性感美女视频| 色久综合一二码| 欧美视频完全免费看| 欧美日韩一区二区在线观看视频 | 日韩综合小视频| 依依成人综合视频| 一区二区三区免费网站| 亚洲自拍偷拍九九九| 亚洲一区二区三区视频在线| 亚洲福利一区二区三区| 亚洲成人一区二区在线观看| 亚洲va国产va欧美va观看| 爽爽淫人综合网网站 | 美女视频第一区二区三区免费观看网站 | 国产69精品久久777的优势| 高清在线不卡av| 99久久er热在这里只有精品66| 99精品热视频| 91麻豆精品91久久久久久清纯| 3atv在线一区二区三区| 日韩精品一区二区在线| 日本一区二区三区四区在线视频| 一色屋精品亚洲香蕉网站| 亚洲午夜视频在线| 久久黄色级2电影| 福利一区二区在线| 欧美伊人精品成人久久综合97| 欧美一区日本一区韩国一区| 精品精品国产高清一毛片一天堂| 国产精品乱码一区二三区小蝌蚪| 一区二区三区在线观看欧美 | 久久综合色8888| 亚洲乱码国产乱码精品精98午夜| 视频一区中文字幕国产| 国产一区二区三区日韩| 91老师国产黑色丝袜在线| 制服丝袜日韩国产| 国产精品免费免费| 日韩成人一区二区三区在线观看| 国产精品一区在线观看你懂的| 色偷偷成人一区二区三区91| 日韩一区二区三区av| 亚洲三级久久久| 老司机免费视频一区二区| 91麻豆福利精品推荐| 精品99久久久久久| 一区二区三区小说| 国产suv精品一区二区三区| 欧美日韩专区在线| 亚洲欧洲成人自拍| 精品亚洲欧美一区| 欧美色综合影院| 1024国产精品| 国产一区二三区| 欧美高清精品3d| 国产精品久线在线观看| 激情久久五月天| 69久久夜色精品国产69蝌蚪网| 亚洲欧洲另类国产综合| 久久国产综合精品| 欧美日韩一卡二卡| 亚洲男人天堂一区| 国产成人aaa| 欧美大片一区二区| 天天免费综合色| 欧洲国内综合视频| 亚洲欧美日本韩国| 不卡一卡二卡三乱码免费网站| 911精品国产一区二区在线| 亚洲精选在线视频| 91同城在线观看| 国产精品国产馆在线真实露脸| 国产乱色国产精品免费视频| 日韩午夜在线观看视频| 亚洲成人av一区二区三区| 日本精品免费观看高清观看| 国产精品毛片久久久久久久| 国产一区二区三区最好精华液| 日韩一区二区电影| 青椒成人免费视频| 日韩写真欧美这视频| 日本亚洲天堂网| 日韩一区二区在线观看视频播放| 亚洲永久免费视频| 欧美影片第一页| 亚洲一区二区三区美女| 欧美亚洲综合在线| 午夜精品久久久久久不卡8050| 欧美羞羞免费网站| 亚洲成人在线观看视频| 欧美日韩一级二级三级| 亚洲美女视频在线| 日韩精品一区二区三区四区视频| 樱花草国产18久久久久| 色诱亚洲精品久久久久久| 亚洲精品视频在线观看网站| bt欧美亚洲午夜电影天堂| ...av二区三区久久精品| 精品国产网站在线观看| 日本视频免费一区| 久久综合九色综合97婷婷 | 免费在线观看日韩欧美| 欧美videossexotv100| 国产一区二区三区电影在线观看| 国产日韩欧美在线一区| 盗摄精品av一区二区三区| 综合av第一页| 欧美肥胖老妇做爰| 精品在线亚洲视频| 中文字幕欧美日韩一区| 色偷偷久久一区二区三区| 日产国产高清一区二区三区| 精品国产乱码久久久久久夜甘婷婷| 国产精品99久久久久| 亚洲男人的天堂在线aⅴ视频 | 欧美一区二区三区免费观看视频| 美国十次了思思久久精品导航| 国产三级一区二区三区| 91久久精品日日躁夜夜躁欧美| 天涯成人国产亚洲精品一区av| 精品国产免费人成在线观看| 不卡电影一区二区三区|