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.

237 lines
6.4 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. buttons.c
  5. Abstract: Button HID Driver.
  6. Environment:
  7. Kernel mode
  8. Author:
  9. Michael Tsang (MikeTs) 13-Apr-2000
  10. Revision History:
  11. --*/
  12. #include "pch.h"
  13. #ifdef ALLOC_PRAGMA
  14. #pragma alloc_text(INIT, DriverEntry)
  15. #pragma alloc_text(PAGE, HbutCreateClose)
  16. #pragma alloc_text(PAGE, HbutAddDevice)
  17. #pragma alloc_text(PAGE, HbutUnload)
  18. #endif //ifdef ALLOC_PRAGMA
  19. /*****************************************************************************
  20. *
  21. * @doc EXTERNAL
  22. *
  23. * @func NTSTATUS | DriverEntry |
  24. * Installable driver initialization entry point.
  25. * <nl>This entry point is called directly by the I/O system.
  26. *
  27. * @parm IN PDRIVER_OBJECT | DrvObj | Points to the driver object.
  28. * @parm IN PUNICODE_STRINT | RegPath | Points to the registry path.
  29. *
  30. * @rvalue SUCCESS | returns STATUS_SUCCESS
  31. * @rvalue FAILURE | returns NT status code
  32. *
  33. *****************************************************************************/
  34. NTSTATUS EXTERNAL
  35. DriverEntry(
  36. IN PDRIVER_OBJECT DrvObj,
  37. IN PUNICODE_STRING RegPath
  38. )
  39. {
  40. PROCNAME("DriverEntry")
  41. NTSTATUS status = STATUS_SUCCESS;
  42. HID_MINIDRIVER_REGISTRATION hidMinidriverRegistration;
  43. ENTER(1, ("(DrvObj=%p,RegPath=%p)\n", DrvObj, RegPath));
  44. DrvObj->MajorFunction[IRP_MJ_CREATE] =
  45. DrvObj->MajorFunction[IRP_MJ_CLOSE] = HbutCreateClose;
  46. DrvObj->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = HbutInternalIoctl;
  47. DrvObj->MajorFunction[IRP_MJ_PNP] = HbutPnp;
  48. DrvObj->MajorFunction[IRP_MJ_POWER] = HbutPower;
  49. DrvObj->DriverUnload = HbutUnload;
  50. DrvObj->DriverExtension->AddDevice = HbutAddDevice;
  51. //
  52. // Register with HIDCLASS.SYS module
  53. //
  54. RtlZeroMemory(&hidMinidriverRegistration,
  55. sizeof(hidMinidriverRegistration));
  56. hidMinidriverRegistration.Revision = HID_REVISION;
  57. hidMinidriverRegistration.DriverObject = DrvObj;
  58. hidMinidriverRegistration.RegistryPath = RegPath;
  59. hidMinidriverRegistration.DeviceExtensionSize = sizeof(DEVICE_EXTENSION);
  60. hidMinidriverRegistration.DevicesArePolled = FALSE;
  61. status = HidRegisterMinidriver(&hidMinidriverRegistration);
  62. if (NT_SUCCESS(status))
  63. {
  64. #ifdef DEBUG
  65. ExInitializeFastMutex(&gmutexDevExtList);
  66. InitializeListHead(&glistDevExtHead);
  67. #endif
  68. }
  69. else
  70. {
  71. ERRPRINT(("failed to register mini driver (status=%x)\n", status));
  72. }
  73. EXIT(1, ("=%x\n", status));
  74. return status;
  75. } //DriverEntry
  76. /*****************************************************************************
  77. *
  78. * @doc EXTERNAL
  79. *
  80. * @func NTSTATUS | HbutCreateClose |
  81. * Process the create and close IRPs sent to this device.
  82. *
  83. * @parm IN PDEVICE_OBJECT | DevObj | Points to the device object.
  84. * @parm IN PIRP | Irp | Points to an I/O Request Packet.
  85. *
  86. * @rvalue STATUS_SUCCESS | success
  87. * @rvalue STATUS_INVALID_PARAMETER | Irp not handled
  88. *
  89. *****************************************************************************/
  90. NTSTATUS EXTERNAL
  91. HbutCreateClose(
  92. IN PDEVICE_OBJECT DevObj,
  93. IN PIRP Irp
  94. )
  95. {
  96. PROCNAME("HbutCreateClose")
  97. NTSTATUS status = STATUS_SUCCESS;
  98. PIO_STACK_LOCATION irpsp;
  99. PAGED_CODE ();
  100. UNREFERENCED_PARAMETER(DevObj);
  101. irpsp = IoGetCurrentIrpStackLocation(Irp);
  102. ENTER(1, ("(DevObj=%p,Irp=%p,IrpStack=%p,Major=%s)\n",
  103. DevObj, Irp, irpsp,
  104. LookupName(irpsp->MajorFunction, MajorFnNames)));
  105. switch(irpsp->MajorFunction)
  106. {
  107. case IRP_MJ_CREATE:
  108. case IRP_MJ_CLOSE:
  109. Irp->IoStatus.Information = 0;
  110. break;
  111. default:
  112. ERRPRINT(("invalid major function %s\n",
  113. LookupName(irpsp->MajorFunction, MajorFnNames)));
  114. status = STATUS_INVALID_PARAMETER;
  115. break;
  116. }
  117. Irp->IoStatus.Status = status;
  118. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  119. EXIT(1, ("=%x\n", status));
  120. return status;
  121. } //HbutCreateClose
  122. /*****************************************************************************
  123. *
  124. * @doc EXTERNAL
  125. *
  126. * @func NTSTATUS | HbutAddDevice |
  127. * Called by hidclass, allows us to initialize our device extensions.
  128. *
  129. * @parm IN PDRIVER_OBJECT | DrvObj | Points to the driver object.
  130. * @parm IN PDEVICE_OBJECT | DevObj |
  131. * Points to a functional device object created by hidclass.
  132. *
  133. * @rvalue SUCCESS | Returns STATUS_SUCCESS.
  134. * @rvalue FAILURE | Returns NT status code.
  135. *
  136. *****************************************************************************/
  137. NTSTATUS EXTERNAL
  138. HbutAddDevice(
  139. IN PDRIVER_OBJECT DrvObj,
  140. IN PDEVICE_OBJECT DevObj
  141. )
  142. {
  143. PROCNAME("HbutAddDevice")
  144. NTSTATUS status;
  145. PDEVICE_EXTENSION devext;
  146. PAGED_CODE ();
  147. ENTER(1, ("(DrvObj=%p,DevObj=%p)\n", DrvObj, DevObj));
  148. ASSERT(DevObj != NULL);
  149. UNREFERENCED_PARAMETER(DrvObj);
  150. devext = GET_MINIDRIVER_DEVICE_EXTENSION(DevObj);
  151. RtlZeroMemory(devext, sizeof(*devext));
  152. IoInitializeRemoveLock(&devext->RemoveLock, HBUT_POOL_TAG, 0, 10);
  153. KeInitializeSpinLock(&devext->SpinLock);
  154. InitializeListHead(&devext->PendingIrpList);
  155. devext->DebounceTime.QuadPart = Int32x32To64(OEM_BUTTON_DEBOUNCE_TIME,
  156. -10000);
  157. KeInitializeTimer(&devext->DebounceTimer);
  158. KeInitializeDpc(&devext->TimerDpc, OemButtonDebounceDpc, devext);
  159. #ifdef DEBUG
  160. ExAcquireFastMutex(&gmutexDevExtList);
  161. InsertTailList(&glistDevExtHead, &devext->List);
  162. ExReleaseFastMutex(&gmutexDevExtList);
  163. #endif
  164. DevObj->Flags &= ~DO_DEVICE_INITIALIZING;
  165. DevObj->Flags |= DO_POWER_PAGABLE;
  166. status = STATUS_SUCCESS;
  167. EXIT(1, ("=%x\n", status));
  168. return status;
  169. } //HbutAddDevice
  170. /*****************************************************************************
  171. *
  172. * @doc EXTERNAL
  173. *
  174. * @func void | HbutUnload | Free all the allocated resources, etc.
  175. *
  176. * @parm IN PDRIVER_OBJECT | DrvObj | Points to the driver object.
  177. *
  178. *****************************************************************************/
  179. VOID EXTERNAL
  180. HbutUnload(
  181. IN PDRIVER_OBJECT DrvObj
  182. )
  183. {
  184. PROCNAME("HbutUnload")
  185. PAGED_CODE();
  186. ENTER(1, ("(DrvObj=%p)\n", DrvObj));
  187. ASSERT(DrvObj->DeviceObject == NULL);
  188. UNREFERENCED_PARAMETER(DrvObj);
  189. EXIT(1, ("!\n"));
  190. return;
  191. } //HbutUnload