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.

305 lines
6.2 KiB

  1. /*++
  2. Copyright (c) 1997-2000 Microsoft Corporation
  3. Module Name:
  4. dispatch.c
  5. Abstract:
  6. This module provides the functions which dispatch IRPs to FDOs and PDOs.
  7. Author:
  8. Adam Glass
  9. Revision History:
  10. --*/
  11. #include "SpSim.h"
  12. #include "spsimioct.h"
  13. const GUID SPSIM_CTL = {0xbdde6934, 0x529d, 0x4183, 0xa9, 0x52, 0xad,
  14. 0xff, 0xb0, 0xdb, 0xb3, 0xdd};
  15. NTSTATUS
  16. SpSimAddDevice(
  17. IN PDRIVER_OBJECT DriverObject,
  18. IN PDEVICE_OBJECT PhysicalDeviceObject
  19. );
  20. NTSTATUS
  21. SpSimDispatchPnp(
  22. IN PDEVICE_OBJECT DeviceObject,
  23. IN PIRP Irp
  24. );
  25. NTSTATUS
  26. SpSimDispatchPower(
  27. IN PDEVICE_OBJECT DeviceObject,
  28. IN PIRP Irp
  29. );
  30. NTSTATUS
  31. SpSimDispatchPower(
  32. IN PDEVICE_OBJECT DeviceObject,
  33. IN PIRP Irp
  34. );
  35. #ifdef ALLOC_PRAGMA
  36. #pragma alloc_text(PAGE, SpSimAddDevice)
  37. #pragma alloc_text(PAGE, SpSimDispatchPnp)
  38. #endif
  39. NTSTATUS
  40. SpSimAddDevice(
  41. IN PDRIVER_OBJECT DriverObject,
  42. IN PDEVICE_OBJECT PhysicalDeviceObject
  43. )
  44. /*++
  45. Routine Description:
  46. Given a physical device object, this routine creates a functional
  47. device object for it and attaches it to the top of the stack.
  48. Arguments:
  49. DriverObject - Pointer to our driver's DRIVER_OBJECT structure.
  50. PhysicalDeviceObject - Pointer to the physical device object for which
  51. we must create a functional device object.
  52. Return Value:
  53. NT status.
  54. --*/
  55. {
  56. NTSTATUS status;
  57. PDEVICE_OBJECT fdo = NULL;
  58. PSPSIM_EXTENSION extension;
  59. ASSERT(DriverObject == SpSimDriverObject);
  60. PAGED_CODE();
  61. //
  62. // Create our FDO
  63. //
  64. status = SpSimCreateFdo(&fdo);
  65. if (!NT_SUCCESS(status)) {
  66. goto cleanup;
  67. }
  68. extension = fdo->DeviceExtension;
  69. extension->PhysicalDeviceObject = PhysicalDeviceObject;
  70. //
  71. // Attach to the stack
  72. //
  73. extension->AttachedDevice = IoAttachDeviceToDeviceStack(
  74. fdo,
  75. PhysicalDeviceObject
  76. );
  77. if (!extension->AttachedDevice) {
  78. //
  79. // Could not attach
  80. //
  81. status = STATUS_NO_SUCH_DEVICE;
  82. goto cleanup;
  83. }
  84. status = IoRegisterDeviceInterface(PhysicalDeviceObject,
  85. &SPSIM_CTL,
  86. NULL,
  87. &extension->SymbolicLinkName);
  88. if (!NT_SUCCESS(status)) {
  89. goto cleanup;
  90. }
  91. fdo->Flags &= ~DO_DEVICE_INITIALIZING;
  92. DEBUG_MSG(1, ("Completed AddDevice for PDO 0x%08x\n", PhysicalDeviceObject));
  93. return STATUS_SUCCESS;
  94. cleanup:
  95. if (fdo) {
  96. IoDeleteDevice(fdo);
  97. }
  98. return status;
  99. }
  100. NTSTATUS
  101. SpSimDispatchPnp(
  102. IN PDEVICE_OBJECT DeviceObject,
  103. IN PIRP Irp
  104. )
  105. /*++
  106. Routine Description:
  107. This routine handles all IRP_MJ_PNP IRPs for this driver. It dispatches to
  108. the appropriate fdo/pdo routine.
  109. Arguments:
  110. DeviceObject - Pointer to the device object for which this IRP applies.
  111. Irp - Pointer to the IRP_MJ_PNP IRP to dispatch.
  112. Return Value:
  113. NT status.
  114. --*/
  115. {
  116. NTSTATUS status;
  117. PSPSIM_EXTENSION spsim;
  118. PIO_STACK_LOCATION irpStack;
  119. PAGED_CODE();
  120. spsim = (PSPSIM_EXTENSION) DeviceObject->DeviceExtension;
  121. irpStack = IoGetCurrentIrpStackLocation(Irp);
  122. ASSERT(irpStack->MajorFunction == IRP_MJ_PNP);
  123. return SpSimDispatchPnpFdo(DeviceObject,
  124. spsim,
  125. irpStack,
  126. Irp
  127. );
  128. }
  129. NTSTATUS
  130. SpSimOpenClose(
  131. IN PDEVICE_OBJECT DeviceObject,
  132. IN PIRP Irp
  133. )
  134. {
  135. //
  136. // Complete the request and return status.
  137. //
  138. Irp->IoStatus.Status = STATUS_SUCCESS;
  139. Irp->IoStatus.Information = 0;
  140. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  141. return STATUS_SUCCESS;
  142. }
  143. #if 0
  144. NTSTATUS
  145. SpSimDispatchPower(
  146. IN PDEVICE_OBJECT DeviceObject,
  147. IN PIRP Irp
  148. )
  149. /*++
  150. Routine Description:
  151. This routine handles all IRP_MJ_POWER IRPs for this driver. It dispatches
  152. to the routines described in the PoDispatchTable entry in the device object
  153. extension.
  154. This routine is NOT pageable as it can be called at DISPATCH_LEVEL
  155. Arguments:
  156. DeviceObject - Pointer to the device object for which this IRP applies.
  157. Irp - Pointer to the IRP_MJ_PNP IRP to dispatch.
  158. Return Value:
  159. NT status.
  160. --*/
  161. {
  162. NTSTATUS status;
  163. PSpSim_COMMON_EXTENSION common;
  164. PIO_STACK_LOCATION irpStack;
  165. ASSERT_SpSim_DEVICE(DeviceObject);
  166. //
  167. // Find out who we are and what we need to do
  168. //
  169. common = (PSpSim_COMMON_EXTENSION) DeviceObject->DeviceExtension;
  170. irpStack = IoGetCurrentIrpStackLocation(Irp);
  171. ASSERT(irpStack->MajorFunction == IRP_MJ_POWER);
  172. if (IS_FDO(common)) {
  173. return SpSimDispatchPowerFdo(DeviceObject,
  174. (SPSIM_EXTENSION) common,
  175. irpStack,
  176. Irp);
  177. } else {
  178. return SpSimDispatchPowerPdo(DeviceObject,
  179. (PSpSim_CHILD_EXTENSION) common,
  180. irpStack,
  181. Irp);
  182. }
  183. }
  184. #endif
  185. NTSTATUS
  186. SpSimIrpNotSupported(
  187. IN PIRP Irp,
  188. IN PVOID Extension,
  189. IN PIO_STACK_LOCATION IrpStack
  190. )
  191. /*++
  192. Routine Description:
  193. This function handles the unsupported IRPs for both SpSim PDOs and FDOs
  194. This is NOT paged because is can be called from SpSimDispatchPower which can
  195. be called at DISPATCH_LEVEL
  196. Arguments:
  197. Irp - Points to the IRP associated with this request.
  198. Extension - Points to the device extension.
  199. IrpStack - Points to the current stack location for this request.
  200. Return Value:
  201. STATUS_NOT_SUPPORTED
  202. --*/
  203. {
  204. UNREFERENCED_PARAMETER(Irp);
  205. UNREFERENCED_PARAMETER(Extension);
  206. UNREFERENCED_PARAMETER(IrpStack);
  207. DEBUG_MSG(1, ("Skipping upsupported IRP\n"));
  208. return STATUS_NOT_SUPPORTED;
  209. }