📄 epower.c
字号:
// #define DRIVER
//
// Include files needed for WDM driver support
//
#include <wdm.h>
#include "stdarg.h"
#include "stdio.h"
//
// Include files needed for USB support
//
#include "usbdi.h"
#include "usbdlib.h"
//
// Include file for the Ezusb Device
//
#include "ezusbsys.h"
NTSTATUS
e_DispatchPower(
IN PDEVICE_OBJECT fdo,
IN PIRP Irp
)
/*++
Routine Description:
Process the IRPs sent to this device.
Arguments:
fdo - pointer to a device object
Irp - pointer to an I/O Request Packet
Return Value:
NTSTATUS
--*/
{
PIO_STACK_LOCATION irpStack, nextStack;
PDEVICE_EXTENSION pdx = fdo->DeviceExtension;
NTSTATUS ntStatus;
Ezusb_KdPrint (("Enter Ezusb_DispatchPower\n"));
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
//
// Get a pointer to the current location in the Irp. This is where
// the function codes and parameters are located.
//
irpStack = IoGetCurrentIrpStackLocation (Irp);
Ezusb_KdPrint (("IRP_MJ_POWER MIN=0x%x Type=0x%x State=0x%x\n",irpStack->MinorFunction,
irpStack->Parameters.Power.Type,
irpStack->Parameters.Power.State.DeviceState));
switch (irpStack->MinorFunction)
{
case IRP_MN_SET_POWER:
switch (irpStack->Parameters.Power.Type)
{
case SystemPowerState:
break; //SystemPowerState
case DevicePowerState:
switch (irpStack->Parameters.Power.State.DeviceState)
{
case PowerDeviceD3:
Ezusb_KdPrint (("IRP_MN_SET_D3\n"));
break;
case PowerDeviceD2:
Ezusb_KdPrint (("IRP_MN_SET_D2\n"));
break;
case PowerDeviceD1:
Ezusb_KdPrint (("IRP_MN_SET_D1\n"));
break;
case PowerDeviceD0:
Ezusb_KdPrint (("IRP_MN_SET_D0\n"));
break;
} // switch on Power.State.DeviceState
break; //DevicePowerState
}// switch on Power.Type
break; //IRP_MN_SET_POWER
case IRP_MN_QUERY_POWER:
// Look at what type of power query this is
switch (irpStack->Parameters.Power.Type)
{
case SystemPowerState:
break; //SystemPowerState
case DevicePowerState:
switch (irpStack->Parameters.Power.State.DeviceState)
{
case PowerDeviceD2:
Ezusb_KdPrint (("IRP_MN_QUERY_D2\n"));
break;
case PowerDeviceD1:
Ezusb_KdPrint (("IRP_MN_QUERY_D1\n"));
break;
case PowerDeviceD3:
Ezusb_KdPrint (("IRP_MN_QUERY_D3\n"));
break;
} //switch on Power.State.DeviceState
break; //DevicePowerState
}//switch on Power.Type
break; //IRP_MN_QUERY_POWER
default:
// A PnP Minor Function was not handled
Ezusb_KdPrint (("Power IOCTL not handled\n"));
} /* switch MinorFunction*/
nextStack = IoGetNextIrpStackLocation(Irp);
ASSERT(nextStack != NULL);
RtlCopyMemory(nextStack, irpStack, sizeof(IO_STACK_LOCATION));
//
// All PNP_POWER messages get passed to the StackDeviceObject that
// we were given in PnPAddDevice.
//
// This stack device object is managed by the USB software subsystem,
// and so this IRP must be propagated to the owning device driver for
// that stack device object, so that driver in turn can perform any
// device state management (e.g., remove its device object, etc.).
//
Ezusb_KdPrint (("Passing Power Irp down\n"));
//
// Notes on passing power IRPs down: Using IoCallDriver() to pass
// down power IRPs worked until Windows 2000. Using this method
// with Win2K causes a blue screen at system shutdown. Because of this,
// I am modifying the driver to use the more correct PoXXX() functions
// to handle power IRPs. Unfortunately, the PoXXX() calls weren't
// added until the kernel until after the release of Windows 95 OSR2.
// So, a driver using these calls will not load on a Windows 95 system.
// If you need to use this driver under Windows 95. then you must
// #define WIN95.
//
#ifdef WIN95
ntStatus = IoCallDriver(pdx->StackDeviceObject, Irp);
#else
PoStartNextPowerIrp(Irp);
ntStatus = PoCallDriver(pdx->StackDeviceObject,Irp);
#endif
//
// If lower layer driver marked the Irp as pending then reflect that by
// calling IoMarkIrpPending.
//
if (ntStatus == STATUS_PENDING)
{
IoMarkIrpPending(Irp);
Ezusb_KdPrint (("Power Irp came back with STATUS_PENDING (%x)\n", ntStatus));
}
else
{
Ezusb_KdPrint (("Power Irp came back, status = %x\n", ntStatus));
} // if ntStatus is PENDING
goto Ezusb_Dispatch_Done;
Ezusb_Dispatch_Done:
Ezusb_KdPrint (("Exit Ezusb_DispatchPower %x\n", ntStatus));
return ntStatus;
}//Ezusb_DispatchPower
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -