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

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

?? bulkpwr.c

?? 微軟DDK中關于WDM驅動程序模型中USB設備驅動程序的例子,實現了BULK通道的數據傳輸,對于利用DDK編寫USB驅動程序的朋友是個很好的參考.
?? C
?? 第 1 頁 / 共 3 頁
字號:
/*++

Copyright (c) 2000 Microsoft Corporation

Module Name:

    bulkpwr.c

Abstract:

    The power management related processing.

    The Power Manager uses IRPs to direct drivers to change system
    and device power levels, to respond to system wake-up events,
    and to query drivers about their devices. All power IRPs have
    the major function code IRP_MJ_POWER.

    Most function and filter drivers perform some processing for
    each power IRP, then pass the IRP down to the next lower driver
    without completing it. Eventually the IRP reaches the bus driver,
    which physically changes the power state of the device and completes
    the IRP.

    When the IRP has been completed, the I/O Manager calls any
    IoCompletion routines set by drivers as the IRP traveled
    down the device stack. Whether a driver needs to set a completion
    routine depends upon the type of IRP and the driver's individual
    requirements.

    This code is not USB specific. It is essential for every WDM driver
    to handle power irps.

Environment:

    Kernel mode

Notes:

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

--*/

#include "bulkusb.h"
#include "bulkpwr.h"
#include "bulkpnp.h"
#include "bulkdev.h"
#include "bulkrwr.h"
#include "bulkwmi.h"
#include "bulkusr.h"

NTSTATUS
BulkUsb_DispatchPower(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    )
/*++
 
Routine Description:

    The power dispatch routine.

Arguments:

    DeviceObject - pointer to a device object.

    Irp - pointer to an I/O Request Packet.

Return Value:

    NT status code

--*/
{
    NTSTATUS           ntStatus;
    PIO_STACK_LOCATION irpStack;
    PUNICODE_STRING    tagString;
    PDEVICE_EXTENSION  deviceExtension;
	
    //
    // initialize the variables
    //
	
    irpStack = IoGetCurrentIrpStackLocation(Irp);
    deviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;

    //
    // We don't queue power Irps, we'll only check if the
    // device was removed, otherwise we'll take appropriate
    // action and send it to the next lower driver. In general
    // drivers should not cause long delays while handling power
    // IRPs. If a driver cannot handle a power IRP in a brief time,
    // it should return STATUS_PENDING and queue all incoming
    // IRPs until the IRP completes.
    //

    if(Removed == deviceExtension->DeviceState) {

        //
        // Even if a driver fails the IRP, it must nevertheless call
        // PoStartNextPowerIrp to inform the Power Manager that it
        // is ready to handle another power IRP.
        //

        PoStartNextPowerIrp(Irp);

        Irp->IoStatus.Status = ntStatus = STATUS_DELETE_PENDING;
        Irp->IoStatus.Information = 0;

        IoCompleteRequest(Irp, IO_NO_INCREMENT);

        return ntStatus;
    }

    if(NotStarted == deviceExtension->DeviceState) {

        //
        // if the device is not started yet, pass it down
        //

        PoStartNextPowerIrp(Irp);

        IoSkipCurrentIrpStackLocation(Irp);

        return PoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp);
    }

    BulkUsb_DbgPrint(3, ("BulkUsb_DispatchPower::"));
    BulkUsb_IoIncrement(deviceExtension);
    
    switch(irpStack->MinorFunction) {
    
    case IRP_MN_SET_POWER:

        //
        // The Power Manager sends this IRP for one of the
        // following reasons:
        // 1) To notify drivers of a change to the system power state.
        // 2) To change the power state of a device for which
        //    the Power Manager is performing idle detection.
        // A driver sends IRP_MN_SET_POWER to change the power
        // state of its device if it's a power policy owner for the
        // device.
        //

        IoMarkIrpPending(Irp);

        switch(irpStack->Parameters.Power.Type) {

        case SystemPowerState:

            HandleSystemSetPower(DeviceObject, Irp);

            ntStatus = STATUS_PENDING;

            break;

        case DevicePowerState:

            HandleDeviceSetPower(DeviceObject, Irp);

            ntStatus = STATUS_PENDING;

            break;
        }

        break;

    case IRP_MN_QUERY_POWER:

        //
        // The Power Manager sends a power IRP with the minor
        // IRP code IRP_MN_QUERY_POWER to determine whether it
        // can safely change to the specified system power state
        // (S1-S5) and to allow drivers to prepare for such a change.
        // If a driver can put its device in the requested state,
        // it sets status to STATUS_SUCCESS and passes the IRP down.
        //

        IoMarkIrpPending(Irp);
    
        switch(irpStack->Parameters.Power.Type) {

        case SystemPowerState:
            
            HandleSystemQueryPower(DeviceObject, Irp);

            ntStatus = STATUS_PENDING;

            break;

        case DevicePowerState:

            HandleDeviceQueryPower(DeviceObject, Irp);

            ntStatus = STATUS_PENDING;

            break;
        }

        break;

    case IRP_MN_WAIT_WAKE:

        //
        // The minor power IRP code IRP_MN_WAIT_WAKE provides
        // for waking a device or waking the system. Drivers
        // of devices that can wake themselves or the system
        // send IRP_MN_WAIT_WAKE. The system sends IRP_MN_WAIT_WAKE
        // only to devices that always wake the system, such as
        // the power-on switch.
        //

        IoMarkIrpPending(Irp);

        IoCopyCurrentIrpStackLocationToNext(Irp);

        IoSetCompletionRoutine(
                        Irp,
                        (PIO_COMPLETION_ROUTINE)WaitWakeCompletionRoutine,
                        deviceExtension, 
                        TRUE, 
                        TRUE, 
                        TRUE);

        PoStartNextPowerIrp(Irp);

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

        if(!NT_SUCCESS(ntStatus)) {

            BulkUsb_DbgPrint(1, ("Lower drivers failed the wait-wake Irp"));
        }

        ntStatus = STATUS_PENDING;

        //
        // push back the count HERE and NOT in completion routine
        // a pending Wait Wake Irp should not impede stopping the device
        //

        BulkUsb_DbgPrint(3, ("IRP_MN_WAIT_WAKE::"));
        BulkUsb_IoDecrement(deviceExtension);

        break;

    case IRP_MN_POWER_SEQUENCE:

        //
        // A driver sends this IRP as an optimization to determine
        // whether its device actually entered a specific power state.
        // This IRP is optional. Power Manager cannot send this IRP.
        //

    default:

        PoStartNextPowerIrp(Irp);

        IoSkipCurrentIrpStackLocation(Irp);

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

        if(!NT_SUCCESS(ntStatus)) {

            BulkUsb_DbgPrint(1, ("Lower drivers failed this Irp"));
        }
        
        BulkUsb_DbgPrint(3, ("BulkUsb_DispatchPower::"));
        BulkUsb_IoDecrement(deviceExtension);

        break;
    }

    return ntStatus;
}

NTSTATUS
HandleSystemQueryPower(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    )
/*++
 
Routine Description:

    This routine handles the irp with minor function of type IRP_MN_QUERY_POWER
    for the system power states.

Arguments:

    DeviceObject - pointer to device object
    Irp - I/O request packet sent by the power manager.

Return Value:

    NT status value

--*/
{
    NTSTATUS           ntStatus;
    PDEVICE_EXTENSION  deviceExtension;
    SYSTEM_POWER_STATE systemState;
    PIO_STACK_LOCATION irpStack;
    
    BulkUsb_DbgPrint(3, ("HandleSystemQueryPower - begins\n"));

    //
    // initialize variables
    //

    deviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
    irpStack = IoGetCurrentIrpStackLocation(Irp);
    systemState = irpStack->Parameters.Power.State.SystemState;

    BulkUsb_DbgPrint(3, ("Query for system power state S%X\n"
                         "Current system power state S%X\n",
                         systemState - 1,
                         deviceExtension->SysPower - 1));

    //
    // Fail a query for a power state incompatible with waking up the system
    //

    if((deviceExtension->WaitWakeEnable) &&
       (systemState > deviceExtension->DeviceCapabilities.SystemWake)) {

        BulkUsb_DbgPrint(1, ("Query for an incompatible system power state\n"));

        PoStartNextPowerIrp(Irp);

        Irp->IoStatus.Status = ntStatus = STATUS_INVALID_DEVICE_STATE;
        Irp->IoStatus.Information = 0;

        IoCompleteRequest(Irp, IO_NO_INCREMENT);

        BulkUsb_DbgPrint(3, ("HandleSystemQueryPower::"));
        BulkUsb_IoDecrement(deviceExtension);

        return ntStatus;
    }

    //
    // if querying for a lower S-state, issue a wait-wake
    //

    if((systemState > deviceExtension->SysPower) &&
       (deviceExtension->WaitWakeEnable)) {

        IssueWaitWake(deviceExtension);
    }

    IoCopyCurrentIrpStackLocationToNext(Irp);

    IoSetCompletionRoutine(
            Irp, 
            (PIO_COMPLETION_ROUTINE)SysPoCompletionRoutine,
            deviceExtension, 
            TRUE, 
            TRUE, 
            TRUE);

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

    BulkUsb_DbgPrint(3, ("HandleSystemQueryPower - ends\n"));

    return STATUS_PENDING;
}

NTSTATUS
HandleSystemSetPower(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    )
/*++
 
Routine Description:

    This routine services irps of minor type IRP_MN_SET_POWER
    for the system power state

Arguments:

    DeviceObject - pointer to device object
    Irp - I/O request packet sent by the power manager

Return Value:

    NT status value:

--*/
{
    NTSTATUS           ntStatus;
    PDEVICE_EXTENSION  deviceExtension;
    SYSTEM_POWER_STATE systemState;
    PIO_STACK_LOCATION irpStack;
    
    BulkUsb_DbgPrint(3, ("HandleSystemSetPower - begins\n"));

    //
    // initialize variables
    //

    deviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
    irpStack = IoGetCurrentIrpStackLocation(Irp);
    systemState = irpStack->Parameters.Power.State.SystemState;

    BulkUsb_DbgPrint(3, ("Set request for system power state S%X\n"
                         "Current system power state S%X\n",
                         systemState - 1,
                         deviceExtension->SysPower - 1));

    IoCopyCurrentIrpStackLocationToNext(Irp);

    IoSetCompletionRoutine(
            Irp, 
            (PIO_COMPLETION_ROUTINE)SysPoCompletionRoutine,
            deviceExtension, 
            TRUE, 
            TRUE, 
            TRUE);

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

    BulkUsb_DbgPrint(3, ("HandleSystemSetPower - ends\n"));

    return STATUS_PENDING;
}

NTSTATUS
HandleDeviceQueryPower(
    PDEVICE_OBJECT DeviceObject,
    PIRP           Irp
    )
/*++
 
Routine Description:

    This routine services irps of minor type IRP_MN_QUERY_POWER
    for the device power state

Arguments:

    DeviceObject - pointer to device object
    Irp - I/O request packet sent by the power manager

Return Value:

    NT status value

--*/
{
    NTSTATUS           ntStatus;
    PDEVICE_EXTENSION  deviceExtension;
    PIO_STACK_LOCATION irpStack;
    DEVICE_POWER_STATE deviceState;

    BulkUsb_DbgPrint(3, ("HandleDeviceQueryPower - begins\n"));

    //
    // initialize variables
    //

    deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
    irpStack = IoGetCurrentIrpStackLocation(Irp);
    deviceState = irpStack->Parameters.Power.State.DeviceState;

    BulkUsb_DbgPrint(3, ("Query for device power state D%X\n"
                         "Current device power state D%X\n",
                         deviceState - 1,
                         deviceExtension->DevPower - 1));

    if(deviceExtension->WaitWakeEnable &&
       deviceState > deviceExtension->DeviceCapabilities.DeviceWake) {

        PoStartNextPowerIrp(Irp);

        Irp->IoStatus.Status = ntStatus = STATUS_INVALID_DEVICE_STATE;
        Irp->IoStatus.Information = 0;

        IoCompleteRequest(Irp, IO_NO_INCREMENT);

        BulkUsb_DbgPrint(3, ("HandleDeviceQueryPower::"));
        BulkUsb_IoDecrement(deviceExtension);

        return ntStatus;
    }

    if(deviceState < deviceExtension->DevPower) {

        ntStatus = STATUS_SUCCESS;
    }
    else {

        ntStatus = HoldIoRequests(DeviceObject, Irp);

        if(STATUS_PENDING == ntStatus) {

            return ntStatus;
        }
    }

    //
    // on error complete the Irp.
    // on success pass it to the lower layers
    //

    PoStartNextPowerIrp(Irp);

    Irp->IoStatus.Status = ntStatus;
    Irp->IoStatus.Information = 0;

    if(!NT_SUCCESS(ntStatus)) {

        IoCompleteRequest(Irp, IO_NO_INCREMENT);
    }
    else {

        IoSkipCurrentIrpStackLocation(Irp);

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

    BulkUsb_DbgPrint(3, ("HandleDeviceQueryPower::"));
    BulkUsb_IoDecrement(deviceExtension);

    BulkUsb_DbgPrint(3, ("HandleDeviceQueryPower - ends\n"));

    return ntStatus;
}


NTSTATUS
SysPoCompletionRoutine(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp,
    IN PDEVICE_EXTENSION DeviceExtension
    )
/*++
 
Routine Description:

    This is the completion routine for the system power irps of minor
    function types IRP_MN_QUERY_POWER and IRP_MN_SET_POWER.
    This completion routine sends the corresponding device power irp and
    returns STATUS_MORE_PROCESSING_REQUIRED. The system irp is passed as a
    context to the device power irp completion routine and is completed in
    the device power irp completion routine.

Arguments:

    DeviceObject - pointer to device object
    Irp - I/O request packet
    DeviceExtension - pointer to device extension

Return Value:

    NT status value

--*/
{
    NTSTATUS           ntStatus;
 	PIO_STACK_LOCATION irpStack;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲精品精品亚洲| 在线观看视频一区二区欧美日韩| 自拍偷拍欧美激情| 久久久99精品免费观看| 欧美v日韩v国产v| 欧美一区二区三区在| 欧美一区二区在线不卡| 欧美剧情片在线观看| 欧美日韩精品二区第二页| 欧美午夜理伦三级在线观看| 在线观看亚洲精品| 欧美日韩一本到| 欧美精品日日鲁夜夜添| 欧美日韩国产综合一区二区 | 欧美激情一区二区三区在线| 国产精品久久久久精k8| 中文幕一区二区三区久久蜜桃| 国产亚洲精品7777| 亚洲欧美在线高清| 亚洲激情成人在线| 日本不卡在线视频| 狠狠色丁香久久婷婷综合丁香| 狠狠色狠狠色综合| 暴力调教一区二区三区| 在线看国产一区二区| 在线成人免费观看| 欧美一区二区三级| 久久午夜电影网| 国产精品第一页第二页第三页| 1区2区3区国产精品| 亚洲成人av在线电影| 久久99精品国产麻豆婷婷洗澡| 国产夫妻精品视频| 在线观看精品一区| 久久久av毛片精品| 一区二区免费视频| 国产一本一道久久香蕉| 91麻豆国产福利精品| 91精品欧美久久久久久动漫| 欧美激情综合五月色丁香小说| 亚洲综合成人在线| 国产精品亚洲专一区二区三区| 色综合久久88色综合天天6| 69久久夜色精品国产69蝌蚪网| 国产欧美一区二区在线| 亚洲成a天堂v人片| 粉嫩在线一区二区三区视频| 在线91免费看| 亚洲理论在线观看| 国产一区二区三区免费在线观看| 在线观看日韩精品| 国产午夜精品久久| 日韩精品三区四区| 日本道免费精品一区二区三区| 久久一夜天堂av一区二区三区| 亚洲尤物在线视频观看| 成人自拍视频在线| 日韩欧美专区在线| 午夜国产不卡在线观看视频| 成人精品亚洲人成在线| 日韩精品一区二区三区中文不卡| 亚洲色图欧美激情| 成人福利视频网站| 2023国产精品| 久久成人免费网站| 欧美xxxxxxxxx| 日韩精品一二三| 欧美日韩黄色影视| 亚洲午夜影视影院在线观看| 99久久99久久精品免费看蜜桃| 中文字幕免费在线观看视频一区| 国产综合色产在线精品| 日韩午夜激情免费电影| 天天色天天爱天天射综合| 色素色在线综合| 一区二区三区四区乱视频| bt欧美亚洲午夜电影天堂| 日本一区二区电影| 国产91在线观看丝袜| 国产色产综合产在线视频| 激情六月婷婷综合| 久久综合久久综合久久综合| 久久99久久99小草精品免视看| 欧美一区二区高清| 久久99精品国产.久久久久| 日韩一级片网站| 国内外成人在线| 久久午夜羞羞影院免费观看| 国产精品一区免费在线观看| 久久精品亚洲一区二区三区浴池 | 国产成人高清视频| 国产精品美女久久久久久久| 91在线云播放| 亚洲综合成人在线视频| 在线播放亚洲一区| 精品一区二区三区久久| 国产女人水真多18毛片18精品视频 | 欧美极品aⅴ影院| 99精品在线免费| 亚洲第一会所有码转帖| 欧美mv日韩mv国产网站app| 国产一区二区电影| 亚洲欧美另类小说| 欧美一区二视频| 国产精品18久久久久久久久久久久| 欧美韩国日本不卡| 欧美视频精品在线| 国产一区视频网站| 1024成人网| 欧美一级二级三级蜜桃| 国产成人亚洲精品狼色在线| 亚洲综合男人的天堂| 欧美大片在线观看一区| 99久久精品久久久久久清纯| 偷拍日韩校园综合在线| 久久精品一区二区三区不卡牛牛 | 欧美v日韩v国产v| 91啪亚洲精品| 黄色日韩三级电影| 亚洲一区二区三区自拍| 日韩一二三四区| 99国产麻豆精品| 国内精品国产三级国产a久久| 亚洲色图在线看| 久久香蕉国产线看观看99| 91久久精品国产91性色tv| 精品在线亚洲视频| 亚洲成人综合网站| 国产精品乱码一区二区三区软件 | 精品福利一区二区三区| 色哟哟国产精品免费观看| 国产一区二区精品在线观看| 亚洲一区视频在线观看视频| 国产亚洲女人久久久久毛片| 91精品国产欧美一区二区| 91免费看片在线观看| 国内久久精品视频| 日韩精品电影一区亚洲| 中文字幕综合网| 亚洲国产电影在线观看| 精品国产一区二区精华| 69av一区二区三区| 欧美亚洲国产一区二区三区| 成+人+亚洲+综合天堂| 国产一区二区三区免费在线观看| 水蜜桃久久夜色精品一区的特点| 一个色在线综合| 樱花影视一区二区| 一区二区三区小说| 亚洲综合丁香婷婷六月香| 18成人在线视频| 一区二区三区四区在线免费观看| 中文字幕一区二区不卡| 国产精品―色哟哟| 亚洲欧洲av另类| |精品福利一区二区三区| 1024国产精品| 艳妇臀荡乳欲伦亚洲一区| 一区二区三区四区中文字幕| 一区二区三区自拍| 五月激情综合婷婷| 日韩av电影天堂| 日本三级亚洲精品| 欧美aaaaa成人免费观看视频| 日韩电影在线观看网站| 天天做天天摸天天爽国产一区| 亚洲成av人**亚洲成av**| 亚洲va欧美va天堂v国产综合| 天堂影院一区二区| 免费成人在线观看视频| 久久99精品国产麻豆不卡| 国产一区二区三区黄视频| 国产成人综合在线观看| 99re这里都是精品| 欧美日韩视频不卡| 精品国产人成亚洲区| 欧美高清在线一区二区| 亚洲免费在线视频| 日本一区中文字幕| 久久成人久久鬼色| 激情六月婷婷综合| 91污在线观看| 91精品麻豆日日躁夜夜躁| 精品国产一区二区三区久久久蜜月| 久久在线观看免费| 一区二区三区中文字幕电影| 日本成人在线看| 成人白浆超碰人人人人| 欧美日韩和欧美的一区二区| 久久久九九九九| 五月天中文字幕一区二区| 国产乱淫av一区二区三区 | 91精品国产aⅴ一区二区| 久久综合精品国产一区二区三区 | 中文字幕视频一区| 视频一区欧美精品| 夫妻av一区二区| 日韩天堂在线观看| 中文字幕一区在线观看| 蜜臀av性久久久久蜜臀av麻豆|