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.

472 lines
10 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. //
  4. // Copyright (c) 1996, 1997 Microsoft Corporation
  5. //
  6. //
  7. // Module Name:
  8. // Mpe.h
  9. //
  10. // Abstract:
  11. //
  12. //
  13. // Author:
  14. //
  15. // P Porzuczek
  16. //
  17. // Environment:
  18. //
  19. // Revision History:
  20. //
  21. //
  22. //////////////////////////////////////////////////////////////////////////////
  23. #ifndef _MPE_H_
  24. #define _MPE_H_
  25. #define ENTRIES(a) (sizeof(a)/sizeof(*(a)))
  26. ///////////////////////////////////////////////////////////////////////////////
  27. //
  28. //
  29. #define MPENAME "MPE"
  30. #define MPENAMEUNICODE L"MPE"
  31. ///////////////////////////////////////////////////////////////////////////////
  32. //
  33. // This defines the name of the WMI device that manages service IOCTLS
  34. //
  35. #define CodecDeviceName (L"\\\\.\\" MPENAMEUNICODE)
  36. #define CodecSymbolicName (L"\\DosDevices\\" MPENAMEUNICODE)
  37. ///////////////////////////////////////////////////////////////////////////////
  38. //
  39. //
  40. typedef struct
  41. {
  42. ULONG ulSize;
  43. UCHAR data;
  44. } MPE_BUFFER, *PMPE_BUFFER;
  45. ///////////////////////////////////////////////////////////////////////////////
  46. //
  47. //
  48. typedef enum
  49. {
  50. MPE_STREAM = 0,
  51. MPE_IPV4
  52. } MPE_STREAMS;
  53. ///////////////////////////////////////////////////////////////////////////////
  54. //
  55. // The MAX_STREAM_COUNT value must be equal to DRIVER_STREAM_COUNT
  56. // This particular value must be defined here to avoid circular references
  57. //
  58. #define MAX_STREAM_COUNT DRIVER_STREAM_COUNT
  59. ///////////////////////////////////////////////////////////////////////////////
  60. //
  61. // We manage multiple instances of each pin up to this limit
  62. //
  63. #define MAX_PIN_INSTANCES 8
  64. #define BIT(n) (1L<<(n))
  65. #define BITSIZE(v) (sizeof(v)*8)
  66. #define SETBIT(array,n) (array[n/BITSIZE(*array)] |= BIT(n%BITSIZE(*array)))
  67. #define CLEARBIT(array,n) (array[n/BITSIZE(*array)] &= ~BIT(n%BITSIZE(*array)))
  68. /////////////////////////////////////////////////////////////////////////////
  69. //
  70. //
  71. //
  72. typedef NTSTATUS (*QUERY_INTERFACE) (PVOID pvContext);
  73. typedef ULONG (*ADD_REF) (PVOID pvContext);
  74. typedef ULONG (*RELEASE) (PVOID pvContext);
  75. /////////////////////////////////////////////////////////////////////////////
  76. //
  77. //
  78. //
  79. typedef struct _STATS_
  80. {
  81. ULONG ulTotalSectionsWritten;
  82. ULONG ulTotalPacketsRead;
  83. ULONG ulTotalInvalidSections;
  84. ULONG ulTotalUnexpectedSections;
  85. ULONG ulTotalUnavailableOutputBuffers;
  86. ULONG ulTotalOutputBuffersTooSmall;
  87. ULONG ulTotalInvalidIPSnapHeaders;
  88. ULONG ulTotalIPPacketsWritten;
  89. ULONG ulTotalIPBytesWritten;
  90. ULONG ulTotalIPFrameBytesWritten;
  91. ULONG ulTotalNetPacketsWritten;
  92. ULONG ulTotalUnknownPacketsWritten;
  93. } STATS, *PSTATS;
  94. /////////////////////////////////////////////////////////////////////////////
  95. //
  96. //
  97. //
  98. typedef struct
  99. {
  100. QUERY_INTERFACE QueryInterface;
  101. ADD_REF AddRef;
  102. RELEASE Release;
  103. } FILTER_VTABLE, *PFILTER_VTABLE;
  104. /////////////////////////////////////////////////////////////////////////////
  105. //
  106. //
  107. // definition of the full HW device extension structure This is the structure
  108. // that will be allocated in HW_INITIALIZATION by the stream class driver
  109. // Any information that is used in processing a device request (as opposed to
  110. // a STREAM based request) should be in this structure. A pointer to this
  111. // structure will be passed in all requests to the minidriver. (See
  112. // HW_STREAM_REQUEST_BLOCK in STRMINI.H)
  113. //
  114. typedef struct _MPE_FILTER_
  115. {
  116. LIST_ENTRY AdapterSRBQueue;
  117. KSPIN_LOCK AdapterSRBSpinLock;
  118. BOOLEAN bAdapterQueueInitialized;
  119. //
  120. //
  121. //
  122. BOOLEAN bInitializationComplete;
  123. //
  124. // Statistics
  125. //
  126. STATS Stats;
  127. //
  128. //
  129. //
  130. PDEVICE_OBJECT DeviceObject;
  131. //
  132. //
  133. //
  134. PDRIVER_OBJECT DriverObject;
  135. //
  136. //
  137. //
  138. PFILTER_VTABLE lpVTable;
  139. //
  140. //
  141. //
  142. ULONG ulRefCount;
  143. //
  144. //
  145. //
  146. PVOID pStream [2][1];
  147. //
  148. //
  149. //
  150. ULONG ulActualInstances [2]; // Count of instances per stream
  151. //
  152. //
  153. //
  154. KSPIN_LOCK IpV4StreamDataSpinLock; // Data queue spin lock
  155. LIST_ENTRY IpV4StreamDataQueue; // Stream data queue
  156. KSPIN_LOCK StreamControlSpinLock; // Command queue spin lock
  157. LIST_ENTRY StreamControlQueue; // Stream command queue
  158. KSPIN_LOCK StreamDataSpinLock; // Data queue spin lock
  159. LIST_ENTRY StreamDataQueue; // Stream data queue
  160. //
  161. //
  162. //
  163. KSPIN_LOCK StreamUserSpinLock;
  164. LIST_ENTRY StreamContxList;
  165. LARGE_INTEGER liLastTimeChecked;
  166. BOOLEAN bDiscontinuity;
  167. } MPE_FILTER, *PMPE_FILTER;
  168. /////////////////////////////////////////////////////////////////////////////
  169. //
  170. // this structure is our per stream extension structure. This stores
  171. // information that is relevant on a per stream basis. Whenever a new stream
  172. // is opened, the stream class driver will allocate whatever extension size
  173. // is specified in the HwInitData.PerStreamExtensionSize.
  174. //
  175. typedef struct _STREAM_
  176. {
  177. PMPE_FILTER pFilter;
  178. PHW_STREAM_OBJECT pStreamObject; // For timer use
  179. KSSTATE KSState; // Run, Stop, Pause
  180. HANDLE hMasterClock;
  181. HANDLE hClock;
  182. ULONG ulStreamInstance; // 0..NumberOfPossibleInstances-1
  183. KSDATAFORMAT OpenedFormat; // Based on the actual open request.
  184. KSDATARANGE MatchedFormat;
  185. ULONG Type; // type of this structure
  186. ULONG Size; // size of this structure
  187. PUCHAR pTransformBuffer; // temp buffer used for translating MPE to IP
  188. PUCHAR pOut; // pointer to next insertion point in output buffer
  189. BYTE bExpectedSection; // expected section number
  190. } STREAM, *PSTREAM;
  191. ///////////////////////////////////////////////////////////////////////////////
  192. //
  193. // This structure is our per SRB extension, and carries the forward and backward
  194. // links for the pending SRB queue.
  195. //
  196. typedef struct _SRB_EXTENSION
  197. {
  198. LIST_ENTRY ListEntry;
  199. PHW_STREAM_REQUEST_BLOCK pSrb;
  200. } SRB_EXTENSION, *PSRB_EXTENSION;
  201. //////////////////////////////////////////////////////////////////////////////
  202. //
  203. // the following section defines prototypes for the minidriver initialization
  204. // routines
  205. //
  206. BOOLEAN
  207. CodecInitialize (
  208. IN OUT PHW_STREAM_REQUEST_BLOCK pSrb
  209. );
  210. BOOLEAN
  211. CodecUnInitialize(
  212. PHW_STREAM_REQUEST_BLOCK pSrb
  213. );
  214. BOOLEAN
  215. CodecQueryUnload (
  216. PHW_STREAM_REQUEST_BLOCK pSrb
  217. ); // Not implemented currently
  218. BOOLEAN
  219. HwInterrupt (
  220. IN PMPE_FILTER pFilter
  221. );
  222. VOID
  223. CodecStreamInfo(
  224. PHW_STREAM_REQUEST_BLOCK pSrb
  225. );
  226. VOID
  227. CodecOpenStream(
  228. PHW_STREAM_REQUEST_BLOCK pSrb
  229. );
  230. VOID
  231. CodecCloseStream(
  232. PHW_STREAM_REQUEST_BLOCK pSrb
  233. );
  234. VOID STREAMAPI
  235. CodecReceivePacket(
  236. IN PHW_STREAM_REQUEST_BLOCK Srb
  237. );
  238. VOID STREAMAPI
  239. CodecCancelPacket(
  240. IN PHW_STREAM_REQUEST_BLOCK Srb
  241. );
  242. VOID STREAMAPI
  243. CodecTimeoutPacket(
  244. IN PHW_STREAM_REQUEST_BLOCK Srb
  245. );
  246. VOID STREAMAPI
  247. CodecGetProperty(
  248. IN PHW_STREAM_REQUEST_BLOCK Srb
  249. );
  250. VOID STREAMAPI
  251. CodecSetProperty(
  252. IN PHW_STREAM_REQUEST_BLOCK Srb
  253. );
  254. BOOL
  255. CodecVerifyFormat(
  256. IN KSDATAFORMAT *pKSDataFormat,
  257. UINT StreamNumber,
  258. PKSDATARANGE pMatchedFormat
  259. );
  260. BOOL
  261. CodecFormatFromRange(
  262. IN PHW_STREAM_REQUEST_BLOCK pSrb
  263. );
  264. void
  265. CompleteStreamSRB (
  266. IN PHW_STREAM_REQUEST_BLOCK pSrb,
  267. STREAM_MINIDRIVER_STREAM_NOTIFICATION_TYPE NotificationType1,
  268. BOOL fUseNotification2,
  269. STREAM_MINIDRIVER_STREAM_NOTIFICATION_TYPE NotificationType2
  270. );
  271. void
  272. CompleteDeviceSRB (
  273. IN PHW_STREAM_REQUEST_BLOCK pSrb,
  274. IN STREAM_MINIDRIVER_DEVICE_NOTIFICATION_TYPE NotificationType,
  275. BOOL fReadyForNext
  276. );
  277. /////////////////////////////////////////////////////////////////////////////////////
  278. //
  279. // SRB Queue Management functions
  280. //
  281. BOOL STREAMAPI
  282. QueueAddIfNotEmpty(
  283. IN PHW_STREAM_REQUEST_BLOCK,
  284. IN PKSPIN_LOCK,
  285. IN PLIST_ENTRY
  286. );
  287. BOOL STREAMAPI
  288. QueueAdd(
  289. IN PHW_STREAM_REQUEST_BLOCK,
  290. IN PKSPIN_LOCK,
  291. IN PLIST_ENTRY
  292. );
  293. BOOL STREAMAPI
  294. QueueRemove(
  295. IN OUT PHW_STREAM_REQUEST_BLOCK *,
  296. IN PKSPIN_LOCK,
  297. IN PLIST_ENTRY
  298. );
  299. BOOL STREAMAPI
  300. QueuePush (
  301. IN PHW_STREAM_REQUEST_BLOCK pSrb,
  302. IN PKSPIN_LOCK pQueueSpinLock,
  303. IN PLIST_ENTRY pQueue
  304. );
  305. BOOL STREAMAPI
  306. QueueRemoveSpecific(
  307. IN PHW_STREAM_REQUEST_BLOCK,
  308. IN PKSPIN_LOCK,
  309. IN PLIST_ENTRY
  310. );
  311. BOOL STREAMAPI
  312. QueueEmpty(
  313. IN PKSPIN_LOCK,
  314. IN PLIST_ENTRY
  315. );
  316. VOID
  317. STREAMAPI
  318. CodecReceivePacket(
  319. IN PHW_STREAM_REQUEST_BLOCK pSrb
  320. );
  321. BOOLEAN
  322. CodecInitialize (
  323. IN OUT PHW_STREAM_REQUEST_BLOCK pSrb
  324. );
  325. VOID
  326. STREAMAPI
  327. CodecCancelPacket(
  328. PHW_STREAM_REQUEST_BLOCK pSrb
  329. );
  330. VOID
  331. STREAMAPI
  332. CodecTimeoutPacket(
  333. PHW_STREAM_REQUEST_BLOCK pSrb
  334. );
  335. BOOL
  336. CompareGUIDsAndFormatSize(
  337. IN PKSDATARANGE pDataRange1,
  338. IN PKSDATARANGE pDataRange2,
  339. BOOLEAN bCheckSize
  340. );
  341. BOOL
  342. CompareStreamFormat (
  343. IN PHW_STREAM_REQUEST_BLOCK pSrb
  344. );
  345. BOOLEAN
  346. VerifyFormat(
  347. IN KSDATAFORMAT *pKSDataFormat,
  348. UINT StreamNumber,
  349. PKSDATARANGE pMatchedFormat
  350. );
  351. VOID
  352. OpenStream (
  353. PHW_STREAM_REQUEST_BLOCK pSrb
  354. );
  355. VOID
  356. CloseStream (
  357. PHW_STREAM_REQUEST_BLOCK pSrb
  358. );
  359. VOID
  360. STREAMAPI
  361. ReceiveDataPacket (
  362. IN PHW_STREAM_REQUEST_BLOCK pSrb
  363. );
  364. VOID
  365. STREAMAPI
  366. ReceiveCtrlPacket(
  367. IN PHW_STREAM_REQUEST_BLOCK pSrb
  368. );
  369. VOID
  370. MpeSetState(
  371. PHW_STREAM_REQUEST_BLOCK pSrb
  372. );
  373. VOID
  374. MpeGetState(
  375. PHW_STREAM_REQUEST_BLOCK pSrb
  376. );
  377. #endif // _MPE_H_
  378.