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.

239 lines
5.4 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. hidusb.c
  5. Abstract: Human Input Device (HID) minidriver for Universal Serial Bus (USB) devices
  6. The HID USB Minidriver (HUM, Hum) provides an abstraction layer for the
  7. HID Class so that future HID devices whic are not USB devices can be supported.
  8. Author:
  9. Daniel Dean, Mercury Engineering.
  10. Environment:
  11. Kernel mode
  12. Revision History:
  13. --*/
  14. #include "pch.h"
  15. #if DBG
  16. ULONG HIDUSB_DebugLevel = 0; // 1 is lowest debug level
  17. BOOLEAN dbgTrapOnWarn = FALSE;
  18. #endif
  19. NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING registryPath)
  20. /*++
  21. Routine Description:
  22. Installable driver initialization entry point.
  23. This entry point is called directly by the I/O system.
  24. Arguments:
  25. DriverObject - pointer to the driver object
  26. registryPath - pointer to a unicode string representing the path,
  27. to driver-specific key in the registry.
  28. Return Value:
  29. STATUS_SUCCESS if successful,
  30. STATUS_UNSUCCESSFUL otherwise
  31. --*/
  32. {
  33. NTSTATUS ntStatus = STATUS_SUCCESS;
  34. HID_MINIDRIVER_REGISTRATION hidMinidriverRegistration;
  35. DBGPRINT(1,("DriverEntry Enter"));
  36. DBGPRINT(1,("DriverObject (%lx)", DriverObject));
  37. //
  38. // Create dispatch points
  39. //
  40. DriverObject->MajorFunction[IRP_MJ_CREATE] =
  41. DriverObject->MajorFunction[IRP_MJ_CLOSE] = HumCreateClose;
  42. DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = HumInternalIoctl;
  43. DriverObject->MajorFunction[IRP_MJ_PNP] = HumPnP;
  44. DriverObject->MajorFunction[IRP_MJ_POWER] = HumPower;
  45. DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = HumSystemControl;
  46. DriverObject->DriverExtension->AddDevice = HumAddDevice;
  47. DriverObject->DriverUnload = HumUnload;
  48. //
  49. // Register USB layer with HID.SYS module
  50. //
  51. hidMinidriverRegistration.Revision = HID_REVISION;
  52. hidMinidriverRegistration.DriverObject = DriverObject;
  53. hidMinidriverRegistration.RegistryPath = registryPath;
  54. hidMinidriverRegistration.DeviceExtensionSize = sizeof(DEVICE_EXTENSION);
  55. /*
  56. * HIDUSB is a minidriver for USB devices, which do not need to be polled.
  57. */
  58. hidMinidriverRegistration.DevicesArePolled = FALSE;
  59. DBGPRINT(1,("DeviceExtensionSize = %x", hidMinidriverRegistration.DeviceExtensionSize));
  60. DBGPRINT(1,("Registering with HID.SYS"));
  61. ntStatus = HidRegisterMinidriver(&hidMinidriverRegistration);
  62. KeInitializeSpinLock(&resetWorkItemsListSpinLock);
  63. DBGPRINT(1,("DriverEntry Exit = %x", ntStatus));
  64. return ntStatus;
  65. }
  66. NTSTATUS HumCreateClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
  67. /*++
  68. Routine Description:
  69. Process the Create and close IRPs sent to this device.
  70. Arguments:
  71. DeviceObject - pointer to a device object.
  72. Irp - pointer to an I/O Request Packet.
  73. Return Value:
  74. NT status code
  75. --*/
  76. {
  77. PIO_STACK_LOCATION IrpStack;
  78. NTSTATUS ntStatus = STATUS_SUCCESS;
  79. DBGPRINT(1,("HumCreateClose Enter"));
  80. DBGBREAK;
  81. //
  82. // Get a pointer to the current location in the Irp.
  83. //
  84. IrpStack = IoGetCurrentIrpStackLocation(Irp);
  85. switch(IrpStack->MajorFunction)
  86. {
  87. case IRP_MJ_CREATE:
  88. DBGPRINT(1,("IRP_MJ_CREATE"));
  89. Irp->IoStatus.Information = 0;
  90. break;
  91. case IRP_MJ_CLOSE:
  92. DBGPRINT(1,("IRP_MJ_CLOSE"));
  93. Irp->IoStatus.Information = 0;
  94. break;
  95. default:
  96. DBGPRINT(1,("Invalid CreateClose Parameter"));
  97. ntStatus = STATUS_INVALID_PARAMETER;
  98. break;
  99. }
  100. //
  101. // Save Status for return and complete Irp
  102. //
  103. Irp->IoStatus.Status = ntStatus;
  104. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  105. DBGPRINT(1,("HumCreateClose Exit = %x", ntStatus));
  106. return ntStatus;
  107. }
  108. NTSTATUS HumAddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT FunctionalDeviceObject)
  109. /*++
  110. Routine Description:
  111. Process the IRPs sent to this device.
  112. Arguments:
  113. DeviceObject - pointer to a device object.
  114. PhysicalDeviceObject - pointer to a device object pointer created by the bus
  115. Return Value:
  116. NT status code.
  117. --*/
  118. {
  119. NTSTATUS ntStatus = STATUS_SUCCESS;
  120. PDEVICE_EXTENSION deviceExtension;
  121. DBGPRINT(1,("HumAddDevice Entry"));
  122. deviceExtension = GET_MINIDRIVER_DEVICE_EXTENSION(FunctionalDeviceObject);
  123. deviceExtension->DeviceFlags = 0;
  124. deviceExtension->NumPendingRequests = 0;
  125. KeInitializeEvent( &deviceExtension->AllRequestsCompleteEvent,
  126. NotificationEvent,
  127. FALSE);
  128. deviceExtension->ResetWorkItem = NULL;
  129. deviceExtension->DeviceState = DEVICE_STATE_NONE;
  130. deviceExtension->functionalDeviceObject = FunctionalDeviceObject;
  131. DBGPRINT(1,("HumAddDevice Exit = %x", ntStatus));
  132. return ntStatus;
  133. }
  134. VOID HumUnload(IN PDRIVER_OBJECT DriverObject
  135. )
  136. /*++
  137. Routine Description:
  138. Free all the allocated resources, etc.
  139. Arguments:
  140. DriverObject - pointer to a driver object.
  141. Return Value:
  142. VOID.
  143. --*/
  144. {
  145. DBGPRINT(1,("HumUnload Enter"));
  146. DBGPRINT(1,("Unloading DriverObject = %x", DriverObject));
  147. ASSERT (NULL == DriverObject->DeviceObject);
  148. DBGPRINT(1,("Unloading Exit = VOID"));
  149. }