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.

180 lines
6.2 KiB

  1. // @doc
  2. /**********************************************************************
  3. *
  4. * @module HIDSWVD.c |
  5. *
  6. * Implementation of the SideWinder Virtual Device Hid Mini-Driver
  7. *
  8. * History
  9. * ----------------------------------------------------------
  10. * Mitchell S. Dernis Original
  11. *
  12. * (c) 1986-1998 Microsoft Corporation. All right reserved.
  13. *
  14. * An overview is provided in HIDSWVD.H
  15. *
  16. * @xref HIDSWVD
  17. *
  18. **********************************************************************/
  19. #include <WDM.H>
  20. #include <HIDPORT.H>
  21. #include "HIDSWVD.H"
  22. //---------------------------------------------------------------------------
  23. // Alloc_text pragma to specify routines that can be paged out.
  24. //---------------------------------------------------------------------------
  25. #ifdef ALLOC_PRAGMA
  26. #pragma alloc_text (INIT, DriverEntry)
  27. #pragma alloc_text (PAGE, HIDSWVD_Power)
  28. #pragma alloc_text (PAGE, HIDSWVD_AddDevice)
  29. #pragma alloc_text (PAGE, HIDSWVD_Unload)
  30. #endif
  31. /***********************************************************************************
  32. **
  33. ** NTSTATUS DriverEntry(IN PDRIVER_OBJECT pDriverObject, IN PUNICODE_STRING puniRegistryPath)
  34. **
  35. ** @func Initializes driver, by setting up serivces and registering with HIDCLASS.SYS
  36. **
  37. ** @rdesc Returns value from HidRegisterMinidriver call.
  38. **
  39. *************************************************************************************/
  40. NTSTATUS
  41. DriverEntry
  42. (
  43. IN PDRIVER_OBJECT pDriverObject, // @parm Driver Object from Loader
  44. IN PUNICODE_STRING puniRegistryPath // @parm Registry Path for this Driver
  45. )
  46. {
  47. NTSTATUS NtStatus = STATUS_SUCCESS;
  48. HID_MINIDRIVER_REGISTRATION HidMinidriverRegistration;
  49. PAGED_CODE();
  50. //This suffice as out entry trace out for DriverEntry, and tell everyone when we were built
  51. HIDSWVD_DBG_PRINT(("Built %s at %s\n", __DATE__, __TIME__));
  52. //Setup Entry Table
  53. pDriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = HIDSWVD_PassThrough;
  54. pDriverObject->MajorFunction[IRP_MJ_PNP] = HIDSWVD_PassThrough;
  55. pDriverObject->MajorFunction[IRP_MJ_POWER] = HIDSWVD_Power;
  56. pDriverObject->DriverExtension->AddDevice = HIDSWVD_AddDevice;
  57. pDriverObject->DriverUnload = HIDSWVD_Unload;
  58. // Setup registration structure for HIDCLASS.SYS module
  59. HidMinidriverRegistration.Revision = HID_REVISION;
  60. HidMinidriverRegistration.DriverObject = pDriverObject;
  61. HidMinidriverRegistration.RegistryPath = puniRegistryPath;
  62. HidMinidriverRegistration.DeviceExtensionSize = sizeof(HIDSWVB_EXTENSION);
  63. // SideWinder Virtual Devices are not polled.
  64. HidMinidriverRegistration.DevicesArePolled = FALSE;
  65. //Register with HIDCLASS.SYS
  66. NtStatus = HidRegisterMinidriver(&HidMinidriverRegistration);
  67. return NtStatus;
  68. }
  69. /***********************************************************************************
  70. **
  71. ** NTSTATUS HIDSWVD_PassThrough(IN PDEVICE_OBJECT pDeviceObject, IN PIRP pIrp)
  72. **
  73. ** @func Passes IRPs down to SWVB module in GcKernel.
  74. **
  75. ** @rdesc Value returned by IoCallDriver to GcKernel
  76. **
  77. *************************************************************************************/
  78. NTSTATUS
  79. HIDSWVD_PassThrough(
  80. IN PDEVICE_OBJECT pDeviceObject, //@parm Device Object to pass down
  81. IN PIRP pIrp //@parm IRP to pass down
  82. )
  83. {
  84. //***
  85. //*** NO TRACEOUT HERE IT WOULD GET CALLED TOO FREQUENTLY
  86. //***
  87. //Get the top of stack from the HIDCLASS part of the device extension (this is documented).
  88. PDEVICE_OBJECT pTopOfStack = ((PHID_DEVICE_EXTENSION)pDeviceObject->DeviceExtension)->NextDeviceObject;
  89. //Call down to SWVB in GcKernel
  90. IoSkipCurrentIrpStackLocation (pIrp);
  91. return IoCallDriver (pTopOfStack, pIrp);
  92. }
  93. /***********************************************************************************
  94. **
  95. ** HIDSWVD_AddDevice(IN PDRIVER_OBJECT pDriverObject, IN PDEVICE_OBJECT pDeviceObject)
  96. **
  97. ** @func Does nothing, we need to have an AddDevice to be PnP compliant, but we have nothing
  98. ** to do.
  99. ** @rdesc Returnes STATUS_SUCCESS.
  100. **
  101. *************************************************************************************/
  102. NTSTATUS
  103. HIDSWVD_AddDevice(
  104. IN PDRIVER_OBJECT pDriverObject, //@parm Driver Object (for our reference)
  105. IN PDEVICE_OBJECT pDeviceObject //@parm Device Object (already created by HIDCLASS.SYS)
  106. )
  107. {
  108. PAGED_CODE();
  109. UNREFERENCED_PARAMETER(pDriverObject);
  110. UNREFERENCED_PARAMETER(pDeviceObject);
  111. HIDSWVD_DBG_PRINT(("Device Object 0x%0.8x was added to pDriverObject 0x%0.8x\n", pDeviceObject, pDriverObject));
  112. return STATUS_SUCCESS;
  113. }
  114. /***********************************************************************************
  115. **
  116. ** NTSTATUS HIDSWVD_Power (IN PDEVICE_OBJECT pDeviceObject, IN PIRP pIrp)
  117. **
  118. ** @func Handles IRP_MJ_POWER
  119. **
  120. ** @rdesc STATUS_SUCCESS, or various errors
  121. **
  122. *************************************************************************************/
  123. NTSTATUS HIDSWVD_Power
  124. (
  125. IN PDEVICE_OBJECT pDeviceObject, // @parm Device Object for our context
  126. IN PIRP pIrp // @parm IRP to handle
  127. )
  128. {
  129. NTSTATUS NtStatus = STATUS_SUCCESS;
  130. PDEVICE_OBJECT pTopOfStack = ((PHID_DEVICE_EXTENSION)pDeviceObject->DeviceExtension)->NextDeviceObject;
  131. PAGED_CODE ();
  132. // Tell system we are ready for the next power IRP
  133. PoStartNextPowerIrp (pIrp);
  134. // NOTE!!! PoCallDriver NOT IoCallDriver.
  135. //Get the top of stack from the HIDCLASS part of the device extension (this is documented).
  136. IoSkipCurrentIrpStackLocation (pIrp);
  137. return PoCallDriver (pTopOfStack, pIrp);
  138. }
  139. /***********************************************************************************
  140. **
  141. ** HIDSWVD_Unload(IN PDRIVER_OBJECT pDriverObject)
  142. **
  143. ** @func Does nothing, but we will never be unloaded if we don't
  144. ** return something.
  145. ** @rdesc None
  146. **
  147. *************************************************************************************/
  148. VOID
  149. HIDSWVD_Unload(
  150. IN PDRIVER_OBJECT pDriverObject //@parm DriverObject - in case we store some globals in there.
  151. )
  152. {
  153. UNREFERENCED_PARAMETER(pDriverObject);
  154. PAGED_CODE();
  155. HIDSWVD_DBG_PRINT(("Unloading\n"));
  156. }