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.

236 lines
5.6 KiB

  1. /***************************************************************************
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. INTREAD.H
  5. Abstract:
  6. Public interface for generic USB routines - must be called at PASSIVE_LEVEL
  7. Environment:
  8. Kernel Mode Only
  9. Notes:
  10. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  11. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  12. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  13. PURPOSE.
  14. Copyright (c) 2001 Microsoft Corporation. All Rights Reserved.
  15. Revision History:
  16. 06/13/2001 : created
  17. Authors:
  18. Tom Green
  19. ****************************************************************************/
  20. #ifndef __INTREAD_H__
  21. #define __INTREAD_H__
  22. //#include "usbutil.h"
  23. #define USBWRAP_BUFFER_GUARD 'draG'
  24. #define USBWRAP_TAG 'prwU'
  25. #define PINGPONG_START_READ 0x01
  26. #define PINGPONG_END_READ 0x02
  27. #define PINGPONG_IMMEDIATE_READ 0x03
  28. #define USBWRAP_INCOMING_QUEUE 0x01
  29. #define USBWRAP_SAVED_QUEUE 0x02
  30. #define PUMP_STATE_RUNNING 0x00
  31. #define PUMP_STATE_STOPPED 0x01
  32. #define PUMP_STATE_ERROR 0x02
  33. typedef NTSTATUS (*INTERRUPT_CALLBACK)(IN PVOID Context,
  34. IN PVOID Buffer,
  35. ULONG BufferLength,
  36. ULONG NotificationType,
  37. OUT PBOOLEAN QueueData);
  38. typedef struct _USB_WRAPPER_EXTENSION *PUSB_WRAPPER_EXTENSION;
  39. typedef struct _USB_WRAPPER_PINGPONG {
  40. #define PINGPONG_SIG (ULONG)'ppwU'
  41. ULONG sig;
  42. //
  43. // Read interlock value to protect us from running out of stack space
  44. //
  45. ULONG ReadInterlock;
  46. PIRP irp;
  47. PURB urb;
  48. PUCHAR reportBuffer;
  49. LONG weAreCancelling;
  50. KEVENT sentEvent; // When a read has been sent.
  51. KEVENT pumpDoneEvent; // When the read loop is finally exitting.
  52. PUSB_WRAPPER_EXTENSION myWrapExt;
  53. /*
  54. * Timeout context for back-off algorithm applied to broken devices.
  55. */
  56. KTIMER backoffTimer;
  57. KDPC backoffTimerDPC;
  58. LARGE_INTEGER backoffTimerPeriod; // in negative 100-nsec units
  59. } USB_WRAPPER_PINGPONG, *PUSB_WRAPPER_PINGPONG;
  60. typedef struct _USB_WRAPPER_DATA_BLOCK {
  61. LIST_ENTRY ListEntry;
  62. ULONG DataLen;
  63. PVOID Buffer;
  64. } USB_WRAPPER_DATA_BLOCK, *PUSB_WRAPPER_DATA_BLOCK;
  65. typedef struct _INTERRUPT_READ_WRAPPER {
  66. PUSBD_PIPE_INFORMATION InterruptPipe;
  67. INTERRUPT_CALLBACK ClientCallback;
  68. PVOID ClientContext;
  69. ULONG MaxTransferSize;
  70. ULONG NotificationTypes;
  71. PUSB_WRAPPER_PINGPONG PingPongs;
  72. ULONG NumPingPongs;
  73. ULONG MaxReportSize;
  74. ULONG OutstandingRequests;
  75. LIST_ENTRY SavedQueue;
  76. LIST_ENTRY IncomingQueue;
  77. KSPIN_LOCK QueueLock;
  78. ULONG PumpState;
  79. ULONG HandlingError;
  80. ULONG WorkItemRunning;
  81. ULONG ErrorCount;
  82. ULONG TransferCount;
  83. } INTERRUPT_READ_WRAPPER, *PINTERRUPT_READ_WRAPPER;
  84. NTSTATUS UsbWrapInitializeInterruptReadData(
  85. IN PUSB_WRAPPER_EXTENSION WrapExtension,
  86. IN PUSBD_PIPE_INFORMATION InterruptPipe,
  87. IN INTERRUPT_CALLBACK DriverCallback,
  88. IN PVOID DriverContext,
  89. IN ULONG MaxTransferSize,
  90. IN ULONG NotificationTypes,
  91. IN ULONG PingPongCount
  92. );
  93. VOID UsbWrapEnqueueData(
  94. IN PUSB_WRAPPER_EXTENSION WrapExt,
  95. IN PVOID Data,
  96. IN ULONG DataLength,
  97. IN PLIST_ENTRY Queue
  98. );
  99. VOID UsbWrapDequeueData(
  100. IN PUSB_WRAPPER_EXTENSION WrapExt,
  101. OUT PVOID *Data,
  102. OUT ULONG *DataLength,
  103. IN PLIST_ENTRY Queue
  104. );
  105. PVOID UsbWrapGetTransferBuffer(
  106. IN PUSB_WRAPPER_EXTENSION WrapExt
  107. );
  108. VOID UsbWrapFreeTransferBuffer(
  109. IN PUSB_WRAPPER_EXTENSION WrapExt,
  110. PVOID Buffer
  111. );
  112. NTSTATUS UsbWrapInitializePingPongIrps(
  113. PUSB_WRAPPER_EXTENSION WrapExtension
  114. );
  115. NTSTATUS UsbWrapSubmitInterruptRead(
  116. IN PUSB_WRAPPER_EXTENSION WrapExtension,
  117. PUSB_WRAPPER_PINGPONG PingPong,
  118. BOOLEAN *IrpSent
  119. );
  120. USB_WRAPPER_PINGPONG *GetPingPongFromIrp(
  121. PUSB_WRAPPER_EXTENSION WrapExt,
  122. PIRP irp
  123. );
  124. NTSTATUS UsbWrapInterruptReadComplete(
  125. IN PDEVICE_OBJECT DeviceObject,
  126. IN PIRP Irp,
  127. IN PVOID Context
  128. );
  129. NTSTATUS UsbWrapStartAllPingPongs(
  130. PUSB_WRAPPER_EXTENSION WrapExt
  131. );
  132. VOID UsbWrapCancelAllPingPongIrps(
  133. PUSB_WRAPPER_EXTENSION WrapExt
  134. );
  135. VOID UsbWrapDestroyPingPongs(
  136. PUSB_WRAPPER_EXTENSION WrapExt
  137. );
  138. VOID UsbWrapPingpongBackoffTimerDpc(
  139. IN PKDPC Dpc,
  140. IN PVOID DeferredContext,
  141. IN PVOID SystemArgument1,
  142. IN PVOID SystemArgument2
  143. );
  144. NTSTATUS UsbWrapReadData(
  145. IN PUSB_WRAPPER_EXTENSION WrapExt,
  146. IN PVOID Buffer,
  147. IN ULONG *BufferLength
  148. );
  149. VOID UsbWrapCancelPingPongIrp(
  150. USB_WRAPPER_PINGPONG *PingPong
  151. );
  152. VOID
  153. UsbWrapEmptyQueue(
  154. PUSB_WRAPPER_EXTENSION WrapExt,
  155. PLIST_ENTRY Queue
  156. );
  157. #endif // __INTREAD_H__