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.

190 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 1996,1997 Microsoft Corporation
  3. Module Name:
  4. ioctl.c
  5. Abstract: Human Input Device (HID) minidriver that creates an example
  6. device.
  7. --*/
  8. #include <WDM.H>
  9. #include <USBDI.H>
  10. #include <HIDPORT.H>
  11. #include <HIDMINI.H>
  12. NTSTATUS
  13. HidMiniIoctl(
  14. IN PDEVICE_OBJECT DeviceObject,
  15. IN PIRP Irp
  16. )
  17. /*++
  18. Routine Description:
  19. Process the Control IRPs sent to this device.
  20. Arguments:
  21. DeviceObject - pointer to a device object.
  22. Irp - pointer to an I/O Request Packet.
  23. Return Value:
  24. NT status code
  25. --*/
  26. {
  27. NTSTATUS ntStatus = STATUS_SUCCESS;
  28. PDEVICE_EXTENSION DeviceExtension;
  29. PIO_STACK_LOCATION IrpStack;
  30. DBGPrint(("'HIDMINI.SYS: HidMiniIoctl Enter\n"));
  31. //
  32. // Get a pointer to the current location in the Irp
  33. //
  34. IrpStack = IoGetCurrentIrpStackLocation(Irp);
  35. //
  36. // Get a pointer to the device extension
  37. //
  38. DeviceExtension = GET_MINIDRIVER_DEVICE_EXTENSION(DeviceObject);
  39. switch(IrpStack->Parameters.DeviceIoControl.IoControlCode)
  40. {
  41. case IOCTL_HID_GET_DEVICE_DESCRIPTOR:
  42. //
  43. // Return the HID descriptor
  44. //
  45. DBGPrint(("'HIDMINI.SYS: IOCTL_HID_GET_DEVICE_DESCRIPTOR\n"));
  46. ntStatus = HidMiniGetHIDDescriptor (DeviceObject, Irp);
  47. break;
  48. case IOCTL_HID_GET_REPORT_DESCRIPTOR:
  49. //
  50. // Return the Report descriptor
  51. //
  52. DBGPrint(("'HIDMINI.SYS: IOCTL_HID_GET_REPORT_DESCRIPTOR\n"));
  53. ntStatus = HidMiniGetReportDescriptor (DeviceObject, Irp);
  54. break;
  55. case IOCTL_HID_READ_REPORT:
  56. //
  57. // Perform a read
  58. //
  59. DBGPrint(("'HIDMINI.SYS: IOCTL_HID_READ_REPORT\n"));
  60. ntStatus = HidMiniReadReport (DeviceObject, Irp);
  61. break;
  62. case IOCTL_HID_WRITE_REPORT:
  63. //
  64. // Perform a write
  65. //
  66. DBGPrint(("'HIDMINI.SYS: IOCTL_HID_WRITE_REPORT\n"));
  67. ntStatus = HidMiniWriteReport (DeviceObject, Irp);
  68. break;
  69. case IOCTL_HID_GET_STRING:
  70. //
  71. // Get the friendly name for the device
  72. //
  73. DBGPrint(("'HIDMINI.SYS: IOCTL_HID_GET_STRING\n"));
  74. ntStatus = HidMiniGetStringDescriptor(DeviceObject, Irp);
  75. break;
  76. case IOCTL_HID_OPEN_COLLECTION:
  77. //
  78. // Notification that a client is opening a top level collection
  79. //
  80. DBGPrint(("'HIDMINI.SYS: IOCTL_HID_OPEN_COLLECTION\n"));
  81. ntStatus = HidMiniOpenCollection (DeviceObject, Irp);
  82. break;
  83. case IOCTL_HID_CLOSE_COLLECTION:
  84. //
  85. // Notification that a client is closing a top level collection
  86. //
  87. DBGPrint(("'HIDMINI.SYS: IOCTL_HID_CLOSE_COLLECTION\n"));
  88. ntStatus = HidMiniCloseCollection (DeviceObject, Irp);
  89. break;
  90. case IOCTL_HID_ACTIVATE_DEVICE:
  91. //
  92. // Notification of first open of a device
  93. //
  94. DBGPrint(("'HIDMINI.SYS: IOCTL_HID_ACTIVATE_DEVICE\n"));
  95. ntStatus = STATUS_SUCCESS;
  96. break;
  97. case IOCTL_HID_DEACTIVATE_DEVICE:
  98. //
  99. // Notification of last close of a device
  100. //
  101. DBGPrint(("'HIDMINI.SYS: IOCTL_HID_DEACTIVATE_DEVICE\n"));
  102. ntStatus = STATUS_SUCCESS;
  103. break;
  104. case IOCTL_HID_GET_DEVICE_ATTRIBUTES:
  105. DBGPrint(("'HIDMINI.SYS: IOCTL_GET_DEVICE_ATTRIBUTES\n"));
  106. ntStatus = HidMiniGetDeviceAttributes(DeviceObject, Irp);
  107. break;
  108. case IOCTL_HID_GET_FEATURE:
  109. case IOCTL_HID_SET_FEATURE:
  110. case IOCTL_GET_PHYSICAL_DESCRIPTOR:
  111. default:
  112. DBGPrint(("'HIDMINI.SYS: Unknown or unsupported IOCTL (%x)\n", IrpStack->Parameters.DeviceIoControl.IoControlCode));
  113. ntStatus = STATUS_NOT_SUPPORTED;
  114. break;
  115. }
  116. //
  117. // Set real return status in Irp
  118. //
  119. Irp->IoStatus.Status = ntStatus;
  120. //
  121. // Complete Irp
  122. //
  123. if (ntStatus != STATUS_PENDING) {
  124. IoCompleteRequest(Irp, IO_NO_INCREMENT);
  125. //
  126. // NOTE: Real return status set in Irp->IoStatus.Status
  127. //
  128. ntStatus = STATUS_SUCCESS;
  129. } else {
  130. IoMarkIrpPending( Irp );
  131. }
  132. DBGPrint(("'HIDMINI.SYS: HidMiniIoctl Exit = %x\n", ntStatus));
  133. return ntStatus;
  134. }