NTSTATUS NTAPI Bus_Power ( PDEVICE_OBJECT DeviceObject, PIRP Irp ) { PIO_STACK_LOCATION irpStack; NTSTATUS status; PCOMMON_DEVICE_DATA commonData; status = STATUS_SUCCESS; irpStack = IoGetCurrentIrpStackLocation (Irp); ASSERT (IRP_MJ_POWER == irpStack->MajorFunction); commonData = (PCOMMON_DEVICE_DATA) DeviceObject->DeviceExtension; if (commonData->IsFDO) { DPRINT("FDO %s IRP:0x%p %s %s\n", PowerMinorFunctionString(irpStack->MinorFunction), Irp, DbgSystemPowerString(commonData->SystemPowerState), DbgDevicePowerString(commonData->DevicePowerState)); status = Bus_FDO_Power ((PFDO_DEVICE_DATA)DeviceObject->DeviceExtension, Irp); } else { DPRINT("PDO %s IRP:0x%p %s %s\n", PowerMinorFunctionString(irpStack->MinorFunction), Irp, DbgSystemPowerString(commonData->SystemPowerState), DbgDevicePowerString(commonData->DevicePowerState)); status = Bus_PDO_Power ((PPDO_DEVICE_DATA)DeviceObject->DeviceExtension, Irp); } return status; }
NTSTATUS Bus_Power ( __in PDEVICE_OBJECT DeviceObject, __in PIRP Irp ) /*++ Handles power Irps sent to both FDO and child PDOs. Note: Currently we do not implement full power handling for the FDO. Arguments: DeviceObject - Pointer to the device object. Irp - Pointer to the irp. Return Value: NT status is returned. --*/ { PIO_STACK_LOCATION irpStack; NTSTATUS status; PCOMMON_DEVICE_DATA commonData; status = STATUS_SUCCESS; irpStack = IoGetCurrentIrpStackLocation (Irp); ASSERT (IRP_MJ_POWER == irpStack->MajorFunction); commonData = (PCOMMON_DEVICE_DATA) DeviceObject->DeviceExtension; // // If the device has been removed, the driver should // not pass the IRP down to the next lower driver. // if (commonData->DevicePnPState == Deleted) { PoStartNextPowerIrp (Irp); Irp->IoStatus.Status = status = STATUS_NO_SUCH_DEVICE ; IoCompleteRequest (Irp, IO_NO_INCREMENT); return status; } if (commonData->IsFDO) { Bus_KdPrint (commonData, BUS_DBG_POWER_TRACE, ("FDO %s IRP:0x%p %s %s\n", PowerMinorFunctionString(irpStack->MinorFunction), Irp, DbgSystemPowerString(commonData->SystemPowerState), DbgDevicePowerString(commonData->DevicePowerState))); status = Bus_FDO_Power ((PFDO_DEVICE_DATA)DeviceObject->DeviceExtension, Irp); } else { Bus_KdPrint (commonData, BUS_DBG_POWER_TRACE, ("PDO %s IRP:0x%p %s %s\n", PowerMinorFunctionString(irpStack->MinorFunction), Irp, DbgSystemPowerString(commonData->SystemPowerState), DbgDevicePowerString(commonData->DevicePowerState))); status = Bus_PDO_Power ((PPDO_DEVICE_DATA)DeviceObject->DeviceExtension, Irp); } return status; }
/////////////////////////////////////////////////////////////////////////////////////////////////// // testdrvDumpIrp // Dump Irp fields to the debugger. // // Arguments: // IN Irp // Irp to display // // Return Value: // None. // VOID testdrvDumpIrp( IN PIRP Irp ) { ULONG debugArea; PIO_STACK_LOCATION irpStack; // Get our current IRP stack location irpStack = IoGetCurrentIrpStackLocation(Irp); // determine debug area switch (irpStack->MajorFunction) { case IRP_MJ_PNP: debugArea = DBG_PNP; break; case IRP_MJ_POWER: debugArea = DBG_POWER; break; case IRP_MJ_CREATE: case IRP_MJ_CLOSE: case IRP_MJ_CLEANUP: debugArea = DBG_CREATECLOSE; break; case IRP_MJ_SYSTEM_CONTROL: debugArea = DBG_WMI; break; case IRP_MJ_READ: case IRP_MJ_WRITE: case IRP_MJ_DEVICE_CONTROL: case IRP_MJ_INTERNAL_DEVICE_CONTROL: debugArea = DBG_IO; break; default: debugArea = DBG_GENERAL; break; } testdrvDebugPrint(debugArea, DBG_INFO, "IRP %p %s", Irp, IrpMajorFunctionString(irpStack->MajorFunction)); if (irpStack->MajorFunction == IRP_MJ_PNP) { testdrvDebugPrint(debugArea, DBG_INFO, "%s", PnPMinorFunctionString(irpStack->MinorFunction)); } else if (irpStack->MajorFunction == IRP_MJ_POWER) { testdrvDebugPrint(debugArea, DBG_INFO, "%s", PowerMinorFunctionString(irpStack->MinorFunction)); if (irpStack->Parameters.Power.Type == SystemPowerState) { testdrvDebugPrint(debugArea, DBG_INFO, "%s", SystemPowerStateString(irpStack->Parameters.Power.State.SystemState)); } else { testdrvDebugPrint(debugArea, DBG_INFO, "%s", DevicePowerStateString(irpStack->Parameters.Power.State.DeviceState)); } } else if (irpStack->MajorFunction == IRP_MJ_SYSTEM_CONTROL) { testdrvDebugPrint(debugArea, DBG_INFO, "%s", WMIMinorFunctionString(irpStack->MinorFunction)); } }
NTSTATUS PPJoy_Ctl_Power (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { NTSTATUS ntStatus; POWER_STATE PowerState; POWER_STATE_TYPE PowerType; PIO_STACK_LOCATION Stack; PDEVICE_EXTENSION DeviceExtension; PAGED_CODE (); /* If it is not for one of our control devices - pass on to HID.sys */ if (GET_NEXT_DEVICE_OBJECT(DeviceObject)) { PPJOY_DBGPRINT (FILE_POWER|PPJOY_HIDHACK, ("Not a control device - passing request on to HID.sys (PPJoy_Ctl_Power)") ); return HIDMajorFunctions[IoGetCurrentIrpStackLocation(Irp)->MajorFunction](DeviceObject,Irp); } PPJOY_DBGPRINT (FILE_POWER | PPJOY_FENTRY, ("Enter PPJoy_Ctl_Power(DeviceObject=0x%p,Irp=0x%p)",DeviceObject,Irp) ); DeviceExtension = GET_MINIDRIVER_DEVICE_EXTENSION (DeviceObject); ntStatus= PPJoy_EnterRequest (DeviceExtension); if (NT_SUCCESS(ntStatus)) { Stack= IoGetCurrentIrpStackLocation (Irp); PowerType= Stack->Parameters.Power.Type; PowerState= Stack->Parameters.Power.State; PPJOY_DBGPRINT (FILE_POWER|PPJOY_BABBLE, ("Received Power IRP %s",PowerMinorFunctionString(Stack->MinorFunction)) ); switch (Stack->MinorFunction) { case IRP_MN_SET_POWER: PPJOY_DBGPRINT (FILE_POWER|PPJOY_BABBLE, ("Request to set %s state to %s", \ ((PowerType==SystemPowerState)?"System":"Device"), \ ((PowerType==SystemPowerState)?DbgSystemPowerString(PowerState.SystemState): \ DbgDevicePowerString(PowerState.DeviceState))) ); if ((PowerType==DevicePowerState)||(PowerType==SystemPowerState)) ntStatus= STATUS_SUCCESS; break; case IRP_MN_QUERY_POWER: ntStatus= STATUS_SUCCESS; break; case IRP_MN_WAIT_WAKE: case IRP_MN_POWER_SEQUENCE: default: ntStatus= STATUS_NOT_SUPPORTED; break; } } /* Must be before IoCompleteRequest(), else bugcheck! */ PoStartNextPowerIrp (Irp); /* We are the lowest level driver for this device, complete IRP */ if (ntStatus!=STATUS_NOT_SUPPORTED) Irp->IoStatus.Status= ntStatus; IoCompleteRequest (Irp,IO_NO_INCREMENT); PPJoy_LeaveRequest (DeviceExtension); PPJOY_EXITPROC (FILE_POWER|PPJOY_FEXIT, "PPJOY_Ctl_Power",ntStatus); return ntStatus; }