null.c 6.8 KB

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