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.

307 lines
7.0 KiB

  1. /****************************************************************************
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. usbloop.h
  5. Abstract:
  6. This header file is used both by ring3 app and ring0 driver, hence the
  7. use of #define DRIVER
  8. Environment:
  9. Kernel & user mode
  10. Revision History:
  11. 1-10-96 : created
  12. ****************************************************************************/
  13. #ifdef DRIVER
  14. #include <wdm.h>
  15. #include <usbdi.h>
  16. #include <usbdlib.h>
  17. #else
  18. #include <usbdi.h>
  19. #endif
  20. #include <stdarg.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #define NAME_MAX 256
  24. #define MAX_INTERFACE 8
  25. #define USBLOOP_PARENT "\\\\.\\USBLOOPXXX"
  26. // IOCTL info
  27. #define USBLOOP_IOCTL_INDEX 0x0080
  28. #define GET_NUM_DEVICES CTL_CODE(FILE_DEVICE_UNKNOWN, \
  29. USBLOOP_IOCTL_INDEX+0, \
  30. METHOD_BUFFERED, \
  31. FILE_ANY_ACCESS)
  32. #define GET_DEVICE_INFO CTL_CODE(FILE_DEVICE_UNKNOWN, \
  33. USBLOOP_IOCTL_INDEX+1, \
  34. METHOD_BUFFERED, \
  35. FILE_ANY_ACCESS)
  36. #define GET_DEVICE_DESCRIPTOR CTL_CODE(FILE_DEVICE_UNKNOWN, \
  37. USBLOOP_IOCTL_INDEX+2, \
  38. METHOD_BUFFERED, \
  39. FILE_ANY_ACCESS)
  40. #define GET_CONFIG_DESCRIPTOR CTL_CODE(FILE_DEVICE_UNKNOWN, \
  41. USBLOOP_IOCTL_INDEX+3, \
  42. METHOD_BUFFERED, \
  43. FILE_ANY_ACCESS)
  44. #define GET_VERSION CTL_CODE(FILE_DEVICE_UNKNOWN, \
  45. USBLOOP_IOCTL_INDEX+4, \
  46. METHOD_BUFFERED, \
  47. FILE_ANY_ACCESS)
  48. #define GET_INTERFACE_INFO CTL_CODE(FILE_DEVICE_UNKNOWN, \
  49. USBLOOP_IOCTL_INDEX+5, \
  50. METHOD_BUFFERED, \
  51. FILE_ANY_ACCESS)
  52. #define USBLOOP_START_ISO_TEST CTL_CODE(FILE_DEVICE_UNKNOWN, \
  53. USBLOOP_IOCTL_INDEX+6, \
  54. METHOD_BUFFERED, \
  55. FILE_ANY_ACCESS)
  56. #ifdef DRIVER
  57. #define USBDIAG_NAME_MAX 64
  58. #define USBLOOP_MAX_PIPES 256
  59. #define USBLOOP_MAX_XFER_SIZE 16384 // 16K
  60. #define USBLOOP_MAX_ENUM_DEVICES 8
  61. typedef struct _DEVICE_LIST_ENTRY {
  62. PDEVICE_OBJECT PhysicalDeviceObject;
  63. PDEVICE_OBJECT DeviceObject;
  64. struct _DEVICE_LIST_ENTRY *Next;
  65. ULONG DeviceNumber;
  66. } DEVICE_LIST_ENTRY, *PDEVICE_LIST_ENTRY;
  67. // data structure to describe each pipe
  68. typedef struct _PipeDescr
  69. {
  70. BOOLEAN bPipeInUse; // pipe in use flag
  71. // layout of PipeAttr is LSB|ep|alt_interface|interface|configuration|MSB
  72. ULONG PipeAttr; // describes pipe configuration, interface, etc.
  73. } PipeDescr, *pPipeDescr;
  74. // device extension for driver instance, used to store needed data
  75. typedef struct _DEVICE_EXTENSION
  76. {
  77. PDEVICE_OBJECT PhysicalDeviceObject; // physical device object
  78. PDEVICE_OBJECT StackDeviceObject; // stack device object
  79. PDEVICE_LIST_ENTRY DeviceList;
  80. ULONG ulInstance; // keeps track of device instance
  81. // Name buffer for our named Functional device object link
  82. WCHAR DeviceLinkNameBuffer[USBDIAG_NAME_MAX];
  83. // descriptors for device instance
  84. PUSB_CONFIGURATION_DESCRIPTOR pUsbConfigDesc;
  85. PUSBD_INTERFACE_INFORMATION Interface[MAX_INTERFACE];
  86. ULONG OpenFRC;
  87. PUSB_DEVICE_DESCRIPTOR pDeviceDescriptor;
  88. KTIMER TimeoutTimer;
  89. KDPC TimeoutDpc;
  90. // handle to configuration that was selected
  91. USBD_CONFIGURATION_HANDLE ConfigurationHandle;
  92. ULONG numPipesInUse; // number of pipes in use
  93. PipeDescr pipes[USBLOOP_MAX_PIPES]; // array of pipe descriptors
  94. //Pointer to an Irp outstanding on this device
  95. // BUGBUG (kosar) This should really be kept on a per-pipe basis but
  96. // we're only keeping on outstanding Irp on this device
  97. // at a time.
  98. PIRP pIrp;
  99. BOOLEAN Stopped; // keeps track of device status
  100. BOOLEAN bTestDevice; // flag for test devices
  101. } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
  102. #define PIPE_MASK 0xff
  103. #define NUM_ATTR_BYTES 4
  104. #define ALT_INT_SHIFT 8
  105. #define INT_SHIFT 16
  106. #define CONFIG_SHIFT 24
  107. #define DEADMAN_TIMEOUT 5000
  108. // extract alt interface from FsContext
  109. #define ALT_INTERFACE(context) ((ULONG) ((ULONG) context >> ALT_INT_SHIFT) & PIPE_MASK)
  110. // extract interface from FsContext
  111. #define INTERFACE(context) ((ULONG) ((ULONG) context >> INT_SHIFT) & PIPE_MASK)
  112. // extract configuration from FsContext
  113. #define CONFIGURATION(context) ((ULONG) ((ULONG) context >> CONFIG_SHIFT) & PIPE_MASK)
  114. // extract pipe number from FsContext
  115. #define PIPENUM(context) ((ULONG) context & PIPE_MASK)
  116. // turns ULONGs into attribute byte for pipe
  117. #define MAKEPIPEATTR(config, interface, alt_interface, pipenum) \
  118. ((ULONG) (((config & PIPE_MASK) << CONFIG_SHIFT) + \
  119. ((interface & PIPE_MASK) << INT_SHIFT) + \
  120. ((alt_interface & PIPE_MASK) << ALT_INT_SHIFT) + \
  121. (pipenum & PIPE_MASK)))
  122. ULONG ulNumLogDev;
  123. static WCHAR deviceLinkBuffer[NAME_MAX] = L"\\DosDevices\\USBLOOP";
  124. static WCHAR deviceNameBuffer[NAME_MAX] = L"\\Device\\USBLOOP";
  125. // this data structure will be used for async transfers, contains urb
  126. // structure, a timer object, pointer to the irp, and a callback object for
  127. // the timer. The timer will be cancelled when the USB transfer completes
  128. typedef struct AsyncTransfer
  129. {
  130. struct _URB_BULK_OR_INTERRUPT_TRANSFER urb;
  131. KTIMER TimeoutTimer;
  132. PIRP irp;
  133. KDPC TimeoutDpc;
  134. BOOLEAN bTimerExpired;
  135. } AsyncTransfer, *pAsyncTransfer;
  136. #if DBG
  137. #define USBLOOP_KdPrint(_x_) DbgPrint("USBLOOP.SYS: "); \
  138. DbgPrint _x_ ;
  139. #define USBLOOP_TRAP() DbgBreakPoint()
  140. #else
  141. #define USBLOOP_KdPrint(_x_)
  142. #define USBLOOP_TRAP()
  143. #endif
  144. NTSTATUS
  145. USBLOOP_Dispatch(
  146. IN PDEVICE_OBJECT DeviceObject,
  147. IN PIRP Irp
  148. );
  149. VOID
  150. USBLOOP_Unload(
  151. IN PDRIVER_OBJECT DriverObject
  152. );
  153. NTSTATUS
  154. USBLOOP_StartDevice(
  155. IN PDEVICE_OBJECT DeviceObject
  156. );
  157. NTSTATUS
  158. USBLOOP_StopDevice(
  159. IN PDEVICE_OBJECT DeviceObject
  160. );
  161. NTSTATUS
  162. USBLOOP_CreateDeviceObject(
  163. IN PDRIVER_OBJECT DriverObject,
  164. IN PDEVICE_OBJECT *DeviceObject,
  165. ULONG Instance
  166. );
  167. NTSTATUS
  168. USBLOOP_CallUSBD(
  169. IN PDEVICE_OBJECT DeviceObject,
  170. IN PURB Urb
  171. );
  172. NTSTATUS
  173. USBLOOP_PnPAddDevice(
  174. IN PDRIVER_OBJECT DriverObject,
  175. IN PDEVICE_OBJECT PhysicalDeviceObject
  176. );
  177. NTSTATUS
  178. USBLOOP_SelectInterfaces(
  179. IN PDEVICE_OBJECT DeviceObject,
  180. IN PUSB_CONFIGURATION_DESCRIPTOR configDesc
  181. );
  182. NTSTATUS
  183. USBLOOP_ConfigureDevice(
  184. IN PDEVICE_OBJECT DeviceObject
  185. );
  186. NTSTATUS
  187. USBLOOP_GetDescriptor(
  188. IN PDEVICE_OBJECT DeviceObject,
  189. IN UCHAR DescType,
  190. IN OUT PVOID pvBuffer
  191. );
  192. NTSTATUS
  193. USBLOOP_Read(
  194. IN PDEVICE_OBJECT DeviceObject,
  195. IN PIRP Irp
  196. );
  197. NTSTATUS
  198. USBLOOP_Write(
  199. IN PDEVICE_OBJECT DeviceObject,
  200. IN PIRP Irp
  201. );
  202. NTSTATUS
  203. USBLOOP_getPipeAttr(
  204. IN PCWSTR pDeviceName,
  205. OUT PULONG pPipeAttr
  206. );
  207. pAsyncTransfer
  208. USBLOOP_BuildAsyncRequest(
  209. IN PDEVICE_OBJECT DeviceObject,
  210. IN PIRP Irp,
  211. IN USBD_PIPE_HANDLE PipeHandle,
  212. IN BOOLEAN Read
  213. );
  214. NTSTATUS
  215. USBLOOP_AsyncReadWrite_Complete(
  216. IN PDEVICE_OBJECT DeviceObject,
  217. IN PIRP Irp,
  218. IN PVOID Context
  219. );
  220. VOID
  221. USBLOOP_SyncTimeoutDPC(
  222. IN PKDPC Dpc,
  223. IN PVOID DeferredContext,
  224. IN PVOID SystemArgument1,
  225. IN PVOID SystemArgument2
  226. );
  227. #endif
  228.