Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.7 KiB

  1. /*
  2. * UNIMODEM "Fakemodem" controllerless driver illustrative example
  3. *
  4. * (C) 2000 Microsoft Corporation
  5. * All Rights Reserved
  6. *
  7. */
  8. #include "fakemodem.h"
  9. #ifdef FAKEMODEM_POWER
  10. VOID
  11. DevicePowerCompleteRoutine(
  12. PDEVICE_OBJECT DeviceObject,
  13. IN UCHAR MinorFunction,
  14. IN POWER_STATE PowerState,
  15. IN PVOID Context,
  16. IN PIO_STATUS_BLOCK IoStatus
  17. )
  18. {
  19. D_POWER(DbgPrint("FAKEMODEM: PoRequestPowerIrp: completion %08lx\n",IoStatus->Status);)
  20. return;
  21. }
  22. #endif
  23. NTSTATUS
  24. FakeModemPower(
  25. IN PDEVICE_OBJECT DeviceObject,
  26. IN PIRP Irp
  27. )
  28. {
  29. PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
  30. PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation(Irp);
  31. NTSTATUS status;
  32. POWER_STATE PowerState;
  33. D_POWER(DbgPrint("FAKEMODEM: Power IRP, MN func=%d\n",irpSp->MinorFunction);)
  34. #ifdef FAKEMODEM_POWER
  35. switch (irpSp->MinorFunction) {
  36. case IRP_MN_SET_POWER:
  37. D_POWER(DbgPrint("FAKEMODEM: IRP_MN_SET_POWER, Type=%s, state=%d\n",irpSp->Parameters.Power.Type == SystemPowerState ? "SystemPowerState" : "DevicePowerState",irpSp->Parameters.Power.State.SystemState);)
  38. if (irpSp->Parameters.Power.Type == SystemPowerState) {
  39. //
  40. // system power state change
  41. //
  42. //
  43. // request the change in device power state based on systemstate map
  44. //
  45. PowerState.DeviceState=deviceExtension->SystemPowerStateMap[irpSp->Parameters.Power.State.SystemState];
  46. PoRequestPowerIrp( deviceExtension->Pdo, IRP_MN_SET_POWER,
  47. PowerState, DevicePowerCompleteRoutine, Irp, NULL);
  48. } else {
  49. //
  50. // changing device state
  51. //
  52. PoSetPowerState( deviceExtension->Pdo,
  53. irpSp->Parameters.Power.Type,
  54. irpSp->Parameters.Power.State);
  55. }
  56. break;
  57. case IRP_MN_QUERY_POWER:
  58. D_POWER(DbgPrint("FAKEMODEM: IRP_MN_QUERY_POWER, Type=%s, state=%d\n",irpSp->Parameters.Power.Type == SystemPowerState ? "SystemPowerState" : "DevicePowerState",irpSp->Parameters.Power.State.DeviceState);)
  59. Irp->IoStatus.Status = STATUS_SUCCESS;
  60. break;
  61. default:
  62. D_POWER(DbgPrint("FAKEMODEM: Power IRP, MN func=%d\n",irpSp->MinorFunction);)
  63. break;
  64. }
  65. #endif
  66. PoStartNextPowerIrp(Irp);
  67. IoSkipCurrentIrpStackLocation(Irp);
  68. status=PoCallDriver(deviceExtension->LowerDevice, Irp);
  69. return status;
  70. }