Source code of Windows XP (NT5)
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.

377 lines
7.8 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. dispatch.c
  5. Abstract:
  6. This module contains the dispatch routines for SAC.
  7. Author:
  8. Sean Selitrennikoff (v-seans) - Jan 13, 1999
  9. Revision History:
  10. --*/
  11. #include "sac.h"
  12. NTSTATUS
  13. DispatchClose(
  14. IN PSAC_DEVICE_CONTEXT DeviceContext,
  15. IN PIRP Irp
  16. );
  17. NTSTATUS
  18. DispatchCreate(
  19. IN PSAC_DEVICE_CONTEXT DeviceContext,
  20. IN PIRP Irp
  21. );
  22. VOID
  23. CancelReceiveIrp(
  24. IN PDEVICE_OBJECT DeviceObject,
  25. IN PIRP Irp
  26. );
  27. NTSTATUS
  28. CompleteSendIrp (
  29. IN PDEVICE_OBJECT DeviceObject,
  30. IN PIRP Irp,
  31. IN PVOID Context
  32. );
  33. VOID
  34. CancelSendIrp(
  35. IN PDEVICE_OBJECT DeviceObject,
  36. IN PIRP Irp
  37. );
  38. NTSTATUS
  39. Dispatch(
  40. IN PDEVICE_OBJECT DeviceObject,
  41. IN PIRP Irp
  42. )
  43. /*++
  44. Routine Description:
  45. This is the dispatch routine for SAC.
  46. Arguments:
  47. DeviceObject - Pointer to device object for target device
  48. Irp - Pointer to I/O request packet
  49. Return Value:
  50. NTSTATUS -- Indicates whether the request was successfully queued.
  51. --*/
  52. {
  53. PSAC_DEVICE_CONTEXT DeviceContext = (PSAC_DEVICE_CONTEXT)DeviceObject->DeviceExtension;
  54. PIO_STACK_LOCATION IrpSp;
  55. NTSTATUS Status;
  56. IF_SAC_DEBUG(SAC_DEBUG_FUNC_TRACE, KdPrint(("SAC Dispatch: Entering.\n")));
  57. IrpSp = IoGetCurrentIrpStackLocation(Irp);
  58. switch (IrpSp->MajorFunction) {
  59. case IRP_MJ_CREATE:
  60. Status = DispatchCreate(DeviceContext, Irp);
  61. IF_SAC_DEBUG(SAC_DEBUG_FUNC_TRACE,
  62. KdPrint(("SAC Dispatch: Exiting with status 0x%x\n", Status)));
  63. return Status;
  64. case IRP_MJ_CLEANUP:
  65. Status = STATUS_SUCCESS;
  66. IF_SAC_DEBUG(SAC_DEBUG_FUNC_TRACE,
  67. KdPrint(("SAC Dispatch: Exiting cleanup status 0x%x\n", Status)));
  68. return Status;
  69. case IRP_MJ_CLOSE:
  70. Status = DispatchClose(DeviceContext, Irp);
  71. IF_SAC_DEBUG(SAC_DEBUG_FUNC_TRACE,
  72. KdPrint(("SAC Dispatch: Exiting close status 0x%x\n", Status)));
  73. return Status;
  74. case IRP_MJ_DEVICE_CONTROL:
  75. Status = DispatchDeviceControl(DeviceObject, Irp);
  76. IF_SAC_DEBUG(SAC_DEBUG_FUNC_TRACE,
  77. KdPrint(("SAC Dispatch: Exiting with status 0x%x\n", Status)));
  78. return Status;
  79. default:
  80. IF_SAC_DEBUG(SAC_DEBUG_FAILS,
  81. KdPrint(( "SAC Dispatch: Invalid major function %lx\n", IrpSp->MajorFunction )));
  82. Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
  83. IoCompleteRequest(Irp, DeviceContext->PriorityBoost);
  84. Status = STATUS_NOT_IMPLEMENTED;
  85. IF_SAC_DEBUG(SAC_DEBUG_FUNC_TRACE,
  86. KdPrint(("SAC Dispatch: Exiting with status 0x%x\n", Status)));
  87. return Status;
  88. }
  89. } // Dispatch
  90. NTSTATUS
  91. DispatchDeviceControl(
  92. IN PDEVICE_OBJECT DeviceObject,
  93. IN PIRP Irp
  94. )
  95. /*++
  96. Routine Description:
  97. This is the dispatch routine for SAC IOCTLs.
  98. Arguments:
  99. DeviceObject - Pointer to device object for target device
  100. Irp - Pointer to I/O request packet
  101. Return Value:
  102. NTSTATUS -- Indicates whether the request was successfully queued.
  103. --*/
  104. {
  105. NTSTATUS Status;
  106. PSAC_DEVICE_CONTEXT DeviceContext = (PSAC_DEVICE_CONTEXT)DeviceObject;
  107. IF_SAC_DEBUG(SAC_DEBUG_FUNC_TRACE, KdPrint(("SAC DispatchDeviceControl: Entering.\n")));
  108. //
  109. // If we made it this far, then the ioctl is invalid.
  110. //
  111. Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
  112. IoCompleteRequest(Irp, DeviceContext->PriorityBoost);
  113. Status = STATUS_INVALID_DEVICE_REQUEST;
  114. IF_SAC_DEBUG(SAC_DEBUG_FUNC_TRACE,
  115. KdPrint(("SAC DispatchDeviceControl: Exiting with status 0x%x\n", Status)));
  116. return Status;
  117. } // DispatchDeviceControl
  118. NTSTATUS
  119. DispatchShutdownControl(
  120. IN PDEVICE_OBJECT DeviceObject,
  121. IN PIRP Irp
  122. )
  123. /*++
  124. Routine Description:
  125. This is the dispatch routine which receives the shutdown IRP.
  126. Arguments:
  127. DeviceObject - Pointer to device object for target device
  128. Irp - Pointer to I/O request packet
  129. Return Value:
  130. NTSTATUS -- Indicates whether the request was successfully queued.
  131. --*/
  132. {
  133. UNREFERENCED_PARAMETER(DeviceObject);
  134. IF_SAC_DEBUG(SAC_DEBUG_FUNC_TRACE, KdPrint(("SAC DispatchShutdownControl: Entering.\n")));
  135. //
  136. // Notify any user.
  137. //
  138. SacPutSimpleMessage(SAC_ENTER);
  139. SacPutSimpleMessage(SAC_SHUTDOWN);
  140. SacPutSimpleMessage(SAC_ENTER);
  141. IF_SAC_DEBUG(SAC_DEBUG_FUNC_TRACE, KdPrint(("SAC DispatchShutdownControl: Exiting.\n")));
  142. Irp->IoStatus.Status = STATUS_SUCCESS;
  143. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  144. return STATUS_SUCCESS;
  145. } // DispatchShutdownControl
  146. NTSTATUS
  147. DispatchCreate(
  148. IN PSAC_DEVICE_CONTEXT DeviceContext,
  149. IN PIRP Irp
  150. )
  151. /*++
  152. Routine Description:
  153. This is the dispatch routine for SAC IOCTL Create
  154. Arguments:
  155. DeviceContext - Pointer to device context for target device
  156. Irp - Pointer to I/O request packet
  157. Return Value:
  158. NTSTATUS -- Indicates whether the request was successfully queued.
  159. --*/
  160. {
  161. NTSTATUS Status;
  162. PIO_STACK_LOCATION IrpSp;
  163. IF_SAC_DEBUG(SAC_DEBUG_FUNC_TRACE, KdPrint(("SAC DispatchCreate: Entering.\n")));
  164. //
  165. // Check to see if we are done initializing.
  166. //
  167. if (!GlobalDataInitialized || !DeviceContext->InitializedAndReady) {
  168. Irp->IoStatus.Status = STATUS_INVALID_DEVICE_STATE;
  169. IoCompleteRequest (Irp, DeviceContext->PriorityBoost);
  170. Status = STATUS_INVALID_DEVICE_STATE;
  171. IF_SAC_DEBUG(SAC_DEBUG_FUNC_TRACE,
  172. KdPrint(("SAC DispatchCreate: Exiting with status 0x%x\n", Status)));
  173. return Status;
  174. }
  175. //
  176. // Get a pointer to the current stack location in the IRP. This is where
  177. // the function codes and parameters are stored.
  178. //
  179. IrpSp = IoGetCurrentIrpStackLocation (Irp);
  180. //
  181. // Case on the function that is being performed by the requestor. If the
  182. // operation is a valid one for this device, then make it look like it was
  183. // successfully completed, where possible.
  184. //
  185. switch (IrpSp->MajorFunction) {
  186. //
  187. // The Create function opens a connection to this device.
  188. //
  189. case IRP_MJ_CREATE:
  190. Status = STATUS_UNSUCCESSFUL;
  191. break;
  192. default:
  193. Status = STATUS_INVALID_DEVICE_REQUEST;
  194. }
  195. Irp->IoStatus.Status = Status;
  196. Irp->IoStatus.Information = 0;
  197. IoCompleteRequest (Irp, DeviceContext->PriorityBoost);
  198. //
  199. // Return the immediate status code to the caller.
  200. //
  201. IF_SAC_DEBUG(SAC_DEBUG_FUNC_TRACE,
  202. KdPrint(("SAC DispatchCreate: Exiting with status 0x%x\n", Status)));
  203. return Status;
  204. }
  205. NTSTATUS
  206. DispatchClose(
  207. IN PSAC_DEVICE_CONTEXT DeviceContext,
  208. IN PIRP Irp
  209. )
  210. /*++
  211. Routine Description:
  212. This is the dispatch routine for SAC IOCTL Close
  213. Arguments:
  214. DeviceContext - Pointer to device context for target device
  215. Irp - Pointer to I/O request packet
  216. Return Value:
  217. NTSTATUS -- Indicates whether the request was successfully queued.
  218. --*/
  219. {
  220. NTSTATUS Status;
  221. IF_SAC_DEBUG(SAC_DEBUG_FUNC_TRACE, KdPrint(("SAC DispatchClose: Entering.\n")));
  222. //
  223. // Check to see if we are done initializing.
  224. //
  225. if (!GlobalDataInitialized || !DeviceContext->InitializedAndReady) {
  226. Irp->IoStatus.Status = STATUS_INVALID_DEVICE_STATE;
  227. IoCompleteRequest (Irp, DeviceContext->PriorityBoost);
  228. Status = STATUS_INVALID_DEVICE_STATE;
  229. IF_SAC_DEBUG(SAC_DEBUG_FUNC_TRACE,
  230. KdPrint(("SAC DispatchClose: Exiting with status 0x%x\n", Status)));
  231. return Status;
  232. }
  233. Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
  234. IoCompleteRequest (Irp, DeviceContext->PriorityBoost);
  235. Status = STATUS_UNSUCCESSFUL;
  236. return Status;
  237. }