null.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. /*++
  2. Copyright (c) 2012 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. null.c
  5. Abstract:
  6. This module implements the NULL driver.
  7. Author:
  8. Evan Green 25-Sep-2012
  9. Environment:
  10. Kernel
  11. --*/
  12. //
  13. // ------------------------------------------------------------------- Includes
  14. //
  15. #include <minoca/kernel/driver.h>
  16. //
  17. // ---------------------------------------------------------------- Definitions
  18. //
  19. //
  20. // ------------------------------------------------------ Data Type Definitions
  21. //
  22. //
  23. // ----------------------------------------------- Internal Function Prototypes
  24. //
  25. KSTATUS
  26. NullAddDevice (
  27. PVOID Driver,
  28. PSTR DeviceId,
  29. PSTR ClassId,
  30. PSTR CompatibleIds,
  31. PVOID DeviceToken
  32. );
  33. VOID
  34. NullDispatchStateChange (
  35. PIRP Irp,
  36. PVOID DeviceContext,
  37. PVOID IrpContext
  38. );
  39. VOID
  40. NullDispatchOpen (
  41. PIRP Irp,
  42. PVOID DeviceContext,
  43. PVOID IrpContext
  44. );
  45. VOID
  46. NullDispatchClose (
  47. PIRP Irp,
  48. PVOID DeviceContext,
  49. PVOID IrpContext
  50. );
  51. VOID
  52. NullDispatchIo (
  53. PIRP Irp,
  54. PVOID DeviceContext,
  55. PVOID IrpContext
  56. );
  57. VOID
  58. NullDispatchSystemControl (
  59. PIRP Irp,
  60. PVOID DeviceContext,
  61. PVOID IrpContext
  62. );
  63. //
  64. // -------------------------------------------------------------------- Globals
  65. //
  66. PDRIVER NullDriver = NULL;
  67. //
  68. // ------------------------------------------------------------------ Functions
  69. //
  70. KSTATUS
  71. DriverEntry (
  72. PDRIVER Driver
  73. )
  74. /*++
  75. Routine Description:
  76. This routine is the entry point for the null driver. It registers its other
  77. dispatch functions, and performs driver-wide initialization.
  78. Arguments:
  79. Driver - Supplies a pointer to the driver object.
  80. Return Value:
  81. STATUS_SUCCESS on success.
  82. Failure code on error.
  83. --*/
  84. {
  85. DRIVER_FUNCTION_TABLE FunctionTable;
  86. KSTATUS Status;
  87. NullDriver = Driver;
  88. RtlZeroMemory(&FunctionTable, sizeof(DRIVER_FUNCTION_TABLE));
  89. FunctionTable.Version = DRIVER_FUNCTION_TABLE_VERSION;
  90. FunctionTable.AddDevice = NullAddDevice;
  91. FunctionTable.DispatchStateChange = NullDispatchStateChange;
  92. FunctionTable.DispatchOpen = NullDispatchOpen;
  93. FunctionTable.DispatchClose = NullDispatchClose;
  94. FunctionTable.DispatchIo = NullDispatchIo;
  95. FunctionTable.DispatchSystemControl = NullDispatchSystemControl;
  96. Status = IoRegisterDriverFunctions(Driver, &FunctionTable);
  97. return Status;
  98. }
  99. KSTATUS
  100. NullAddDevice (
  101. PVOID Driver,
  102. PSTR DeviceId,
  103. PSTR ClassId,
  104. PSTR CompatibleIds,
  105. PVOID DeviceToken
  106. )
  107. /*++
  108. Routine Description:
  109. This routine is called when a device is detected for which this driver
  110. acts as the function driver. The driver will attach itself to the stack.
  111. Arguments:
  112. Driver - Supplies a pointer to the driver being called.
  113. DeviceId - Supplies a pointer to a string with the device ID.
  114. ClassId - Supplies a pointer to a string containing the device's class ID.
  115. CompatibleIds - Supplies a pointer to a string containing device IDs
  116. that would be compatible with this device.
  117. DeviceToken - Supplies an opaque token that the driver can use to identify
  118. the device in the system. This token should be used when attaching to
  119. the stack.
  120. Return Value:
  121. STATUS_SUCCESS on success.
  122. Failure code if the driver was unsuccessful in attaching itself.
  123. --*/
  124. {
  125. KSTATUS Status;
  126. Status = IoAttachDriverToDevice(Driver, DeviceToken, NULL);
  127. return Status;
  128. }
  129. VOID
  130. NullDispatchStateChange (
  131. PIRP Irp,
  132. PVOID DeviceContext,
  133. PVOID IrpContext
  134. )
  135. /*++
  136. Routine Description:
  137. This routine handles State Change IRPs.
  138. Arguments:
  139. Irp - Supplies a pointer to the I/O request packet.
  140. DeviceContext - Supplies the context pointer supplied by the driver when it
  141. attached itself to the driver stack. Presumably this pointer contains
  142. driver-specific device context.
  143. IrpContext - Supplies the context pointer supplied by the driver when
  144. the IRP was created.
  145. Return Value:
  146. None.
  147. --*/
  148. {
  149. ASSERT(Irp->MajorCode == IrpMajorStateChange);
  150. //
  151. // Do no processing on any IRPs. Let them flow.
  152. //
  153. return;
  154. }
  155. VOID
  156. NullDispatchOpen (
  157. PIRP Irp,
  158. PVOID DeviceContext,
  159. PVOID IrpContext
  160. )
  161. /*++
  162. Routine Description:
  163. This routine handles Open IRPs.
  164. Arguments:
  165. Irp - Supplies a pointer to the I/O request packet.
  166. DeviceContext - Supplies the context pointer supplied by the driver when it
  167. attached itself to the driver stack. Presumably this pointer contains
  168. driver-specific device context.
  169. IrpContext - Supplies the context pointer supplied by the driver when
  170. the IRP was created.
  171. Return Value:
  172. None.
  173. --*/
  174. {
  175. return;
  176. }
  177. VOID
  178. NullDispatchClose (
  179. PIRP Irp,
  180. PVOID DeviceContext,
  181. PVOID IrpContext
  182. )
  183. /*++
  184. Routine Description:
  185. This routine handles Close IRPs.
  186. Arguments:
  187. Irp - Supplies a pointer to the I/O request packet.
  188. DeviceContext - Supplies the context pointer supplied by the driver when it
  189. attached itself to the driver stack. Presumably this pointer contains
  190. driver-specific device context.
  191. IrpContext - Supplies the context pointer supplied by the driver when
  192. the IRP was created.
  193. Return Value:
  194. None.
  195. --*/
  196. {
  197. return;
  198. }
  199. VOID
  200. NullDispatchIo (
  201. PIRP Irp,
  202. PVOID DeviceContext,
  203. PVOID IrpContext
  204. )
  205. /*++
  206. Routine Description:
  207. This routine handles I/O IRPs.
  208. Arguments:
  209. Irp - Supplies a pointer to the I/O request packet.
  210. DeviceContext - Supplies the context pointer supplied by the driver when it
  211. attached itself to the driver stack. Presumably this pointer contains
  212. driver-specific device context.
  213. IrpContext - Supplies the context pointer supplied by the driver when
  214. the IRP was created.
  215. Return Value:
  216. None.
  217. --*/
  218. {
  219. return;
  220. }
  221. VOID
  222. NullDispatchSystemControl (
  223. PIRP Irp,
  224. PVOID DeviceContext,
  225. PVOID IrpContext
  226. )
  227. /*++
  228. Routine Description:
  229. This routine handles System Control IRPs.
  230. Arguments:
  231. Irp - Supplies a pointer to the I/O request packet.
  232. DeviceContext - Supplies the context pointer supplied by the driver when it
  233. attached itself to the driver stack. Presumably this pointer contains
  234. driver-specific device context.
  235. IrpContext - Supplies the context pointer supplied by the driver when
  236. the IRP was created.
  237. Return Value:
  238. None.
  239. --*/
  240. {
  241. ASSERT(Irp->MajorCode == IrpMajorSystemControl);
  242. //
  243. // Do no processing on any IRPs. Let them flow.
  244. //
  245. return;
  246. }
  247. //
  248. // --------------------------------------------------------- Internal Functions
  249. //