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.

324 lines
9.2 KiB

  1. /****************************************************************************/
  2. // sdapi.h
  3. //
  4. // TS protocol stack driver common definitions.
  5. //
  6. // Copyright (C) 1998-2000 Microsoft Corporation
  7. /****************************************************************************/
  8. #ifndef __SDAPI_H
  9. #define __SDAPI_H
  10. /*
  11. * TRACE defines
  12. */
  13. #if DBG
  14. #define TRACE(_arg) IcaStackTrace _arg
  15. #define TRACEBUF(_arg) IcaStackTraceBuffer _arg
  16. #else
  17. #define TRACE(_arg)
  18. #define TRACEBUF(_arg)
  19. #endif
  20. /*
  21. * Input buffer data structure
  22. */
  23. typedef struct _INBUF {
  24. LIST_ENTRY Links; // Pointer to previous/next buffer
  25. PUCHAR pBuffer; // Pointer to current location in Buffer
  26. ULONG ByteCount; // Number of bytes in Buffer
  27. ULONG MaxByteCount; // Max size of Buffer
  28. PIRP pIrp; // pointer to Irp to use for I/O
  29. PMDL pMdl; // pointer to MDL to use for I/O
  30. PVOID pPrivate; // pointer to private data
  31. } INBUF, *PINBUF;
  32. /*
  33. * Outpuf Buffer data structure
  34. */
  35. typedef struct _OUTBUF {
  36. /*
  37. * Non-inherited fields
  38. */
  39. ULONG OutBufLength; // length of allocated memory for outbuf
  40. int PoolIndex; // Stores the buffer pool this buffer goes to.
  41. LIST_ENTRY Links; // pointer to previous/next outbuf
  42. PUCHAR pBuffer; // pointer within buffer memory
  43. ULONG ByteCount; // byte count pointed to by pBuffer
  44. ULONG MaxByteCount; // maximum byte count possible (static)
  45. PETHREAD ThreadId; // thread id which issued i/o reqst for this buf
  46. PIRP pIrp; // pointer to Irp to use for I/O
  47. PMDL pMdl; // pointer to MDL to use for I/O
  48. PVOID pPrivate; // pointer to private data
  49. /*
  50. * Inherited fields (when pd allocates new outbuf and copies the data)
  51. */
  52. ULONG StartTime; // pdreli - transmit time (used to measure roundtrip)
  53. UCHAR Sequence; // pdreli - output sequence number
  54. UCHAR Fragment; // pdreli - outbuf fragment number
  55. ULONG fWait : 1; // pdreli - waits allowed on this outbuf
  56. ULONG fControl : 1; // pdreli - control buffer (ack/nak)
  57. ULONG fRetransmit : 1; // pdreli - buffer has been retransmited
  58. ULONG fCompress : 1; // pdcomp - buffer should be compressed
  59. // Other flags.
  60. ULONG fIrpCompleted : 1; // Used on completion to prevent canceling.
  61. } OUTBUF, * POUTBUF;
  62. /*
  63. * Typedefs for Stack Driver callup routines
  64. */
  65. typedef NTSTATUS (*PSDBUFFERALLOC)(
  66. IN PVOID pContext,
  67. IN BOOLEAN bWait,
  68. IN BOOLEAN bControl,
  69. ULONG ByteCount,
  70. PVOID pBufferOrig,
  71. PVOID *pBuffer);
  72. typedef VOID (*PSDBUFFERFREE)(IN PVOID pContext, PVOID pBuffer);
  73. typedef NTSTATUS (*PSDRAWINPUT)(
  74. IN PVOID pContext,
  75. IN PINBUF pInBuf OPTIONAL,
  76. IN PUCHAR pBuffer OPTIONAL,
  77. IN ULONG ByteCount);
  78. typedef NTSTATUS (*PSDCHANNELINPUT)(
  79. IN PVOID pContext,
  80. IN CHANNELCLASS ChannelClass,
  81. IN VIRTUALCHANNELCLASS VirtualClass,
  82. IN PINBUF pInBuf OPTIONAL,
  83. IN PUCHAR pBuffer OPTIONAL,
  84. IN ULONG ByteCount);
  85. /*
  86. * Stack Driver callup table
  87. */
  88. typedef struct _SDCALLUP {
  89. PSDBUFFERALLOC pSdBufferAlloc;
  90. PSDBUFFERFREE pSdBufferFree;
  91. PSDBUFFERFREE pSdBufferError;
  92. PSDRAWINPUT pSdRawInput;
  93. PSDCHANNELINPUT pSdChannelInput;
  94. } SDCALLUP, *PSDCALLUP;
  95. /*
  96. * Stack Driver Context structure
  97. * This is filled in by the SD at load time, and is passed
  98. * as an argument to most ICA driver helper routines.
  99. */
  100. typedef struct _SDCONTEXT {
  101. PVOID pProcedures; // Pointer to proc table for this driver
  102. PSDCALLUP pCallup; // Pointer to callup table for this driver
  103. PVOID pContext; // Context value passed on calls to driver
  104. } SDCONTEXT, *PSDCONTEXT;
  105. /*
  106. * Stack Driver Load/Unload procedure prototype
  107. */
  108. typedef NTSTATUS (_stdcall *PSDLOADPROC)(
  109. IN OUT PSDCONTEXT pSdContext,
  110. IN BOOLEAN bLoad);
  111. /*
  112. * Stack Driver procedure prototype
  113. */
  114. typedef NTSTATUS (_stdcall *PSDPROCEDURE)(
  115. IN PVOID pContext,
  116. IN PVOID pParms);
  117. /*=============================================================================
  118. == Stack Driver interface
  119. =============================================================================*/
  120. /*
  121. * Stack Driver (WD/PD/TD) APIs
  122. */
  123. #define SD$OPEN 0
  124. #define SD$CLOSE 1
  125. #define SD$RAWWRITE 2
  126. #define SD$CHANNELWRITE 3
  127. #define SD$SYNCWRITE 4
  128. #define SD$IOCTL 5
  129. #define SD$COUNT 6
  130. /*
  131. * SdOpen structure
  132. */
  133. typedef struct _SD_OPEN {
  134. STACKCLASS StackClass; // IN: stack type
  135. PPROTOCOLSTATUS pStatus; // IN:
  136. PCLIENTMODULES pClient; // IN:
  137. WDCONFIG WdConfig; // IN: WD configuration data
  138. PDCONFIG PdConfig; // IN: PD configuration data
  139. char OEMId[4]; // IN: WinFrame Server OEM Id from registry
  140. WINSTATIONNAME WinStationRegName; // IN: WinStation registry name
  141. PDEVICE_OBJECT DeviceObject; // IN: pointer to device object to use with the unload safe completion routine
  142. ULONG OutBufHeader; // IN: number of header bytes to reserve
  143. ULONG OutBufTrailer; // IN: number of trailer bytes to reserve
  144. ULONG SdOutBufHeader; // OUT: returned by sd
  145. ULONG SdOutBufTrailer; // OUT: returned by sd
  146. } SD_OPEN, *PSD_OPEN;
  147. /*
  148. * SdClose structure
  149. */
  150. typedef struct _SD_CLOSE {
  151. ULONG SdOutBufHeader; // OUT: returned by sd
  152. ULONG SdOutBufTrailer; // OUT: returned by sd
  153. } SD_CLOSE, *PSD_CLOSE;
  154. /*
  155. * SdRawWrite structure
  156. */
  157. typedef struct _SD_RAWWRITE {
  158. POUTBUF pOutBuf;
  159. PUCHAR pBuffer;
  160. ULONG ByteCount;
  161. } SD_RAWWRITE, *PSD_RAWWRITE;
  162. /*
  163. * SdChannelWrite fFlags Values
  164. */
  165. #define SD_CHANNELWRITE_LOWPRIO 0x00000001 // Write can block behind
  166. // default priority writes.
  167. /*
  168. * SdChannelWrite structure
  169. *
  170. * The flags field is passed to termdd.sys via an IRP_MJ_WRITE
  171. * Irp, as a ULONG pointer in the Irp->Tail.Overlay.DriverContext[0] field.
  172. */
  173. typedef struct _SD_CHANNELWRITE {
  174. CHANNELCLASS ChannelClass;
  175. VIRTUALCHANNELCLASS VirtualClass;
  176. BOOLEAN fScreenData;
  177. POUTBUF pOutBuf;
  178. PUCHAR pBuffer;
  179. ULONG ByteCount;
  180. ULONG fFlags;
  181. } SD_CHANNELWRITE, *PSD_CHANNELWRITE;
  182. /*
  183. * SdIoctl structure
  184. */
  185. typedef struct _SD_IOCTL {
  186. ULONG IoControlCode; // IN
  187. PVOID InputBuffer; // IN OPTIONAL
  188. ULONG InputBufferLength; // IN
  189. PVOID OutputBuffer; // OUT OPTIONAL
  190. ULONG OutputBufferLength; // OUT
  191. ULONG BytesReturned; // OUT
  192. } SD_IOCTL, *PSD_IOCTL;
  193. /*
  194. * SdSyncWrite structure
  195. */
  196. typedef struct _SD_SYNCWRITE {
  197. ULONG notused;
  198. } SD_SYNCWRITE, *PSD_SYNCWRITE;
  199. /*=============================================================================
  200. == Stack Drivers helper routines
  201. =============================================================================*/
  202. #define ICALOCK_IO 0x00000001
  203. #define ICALOCK_DRIVER 0x00000002
  204. NTSTATUS IcaBufferAlloc(PSDCONTEXT, BOOLEAN, BOOLEAN, ULONG, PVOID, PVOID *);
  205. void IcaBufferFree(PSDCONTEXT, PVOID);
  206. void IcaBufferError(PSDCONTEXT, PVOID);
  207. unsigned IcaBufferGetUsableSpace(unsigned);
  208. NTSTATUS IcaRawInput(PSDCONTEXT, PINBUF, PUCHAR, ULONG);
  209. NTSTATUS IcaChannelInput(PSDCONTEXT, CHANNELCLASS, VIRTUALCHANNELCLASS,
  210. PINBUF, PUCHAR, ULONG);
  211. NTSTATUS IcaCreateThread(PSDCONTEXT, PVOID, PVOID, ULONG, PHANDLE);
  212. NTSTATUS IcaCallNextDriver(PSDCONTEXT, ULONG, PVOID);
  213. NTSTATUS IcaTimerCreate(PSDCONTEXT, PVOID *);
  214. BOOLEAN IcaTimerStart(PVOID, PVOID, PVOID, ULONG, ULONG);
  215. BOOLEAN IcaTimerCancel(PVOID);
  216. BOOLEAN IcaTimerClose(PVOID);
  217. NTSTATUS IcaQueueWorkItem(PSDCONTEXT, PVOID, PVOID, ULONG);
  218. NTSTATUS IcaSleep(PSDCONTEXT, ULONG);
  219. NTSTATUS IcaWaitForSingleObject(PSDCONTEXT, PVOID, LONG);
  220. NTSTATUS IcaFlowControlSleep(PSDCONTEXT, ULONG);
  221. NTSTATUS IcaFlowControlWait(PSDCONTEXT, PVOID, LONG);
  222. NTSTATUS IcaWaitForMultipleObjects(PSDCONTEXT, ULONG, PVOID [], WAIT_TYPE,
  223. LONG);
  224. NTSTATUS IcaLogError(PSDCONTEXT, NTSTATUS, LPWSTR *, ULONG, PVOID, ULONG);
  225. VOID _cdecl IcaStackTrace(PSDCONTEXT, ULONG, ULONG, CHAR *, ...);
  226. VOID IcaStackTraceBuffer(PSDCONTEXT, ULONG, ULONG, PVOID, ULONG);
  227. NTSTATUS
  228. IcaQueueWorkItemEx(
  229. IN PSDCONTEXT pContext,
  230. IN PVOID pFunc,
  231. IN PVOID pParam,
  232. IN ULONG LockFlags,
  233. IN PVOID pIcaWorkItem
  234. );
  235. NTSTATUS
  236. IcaAllocateWorkItem(
  237. OUT PVOID *pParam
  238. );
  239. NTSTATUS
  240. IcaCreateHandle(
  241. PVOID Context,
  242. ULONG ContextSize,
  243. PVOID *ppHandle
  244. );
  245. NTSTATUS
  246. IcaReturnHandle(
  247. PVOID Handle,
  248. PVOID *ppContext,
  249. PULONG pContextSize
  250. );
  251. NTSTATUS
  252. IcaCloseHandle(
  253. PVOID Handle,
  254. PVOID *ppContext,
  255. PULONG pContextSize
  256. );
  257. PVOID IcaStackAllocatePoolWithTag(
  258. IN POOL_TYPE PoolType,
  259. IN SIZE_T NumberOfBytes,
  260. IN ULONG Tag );
  261. PVOID IcaStackAllocatePool(
  262. IN POOL_TYPE PoolType,
  263. IN SIZE_T NumberOfBytes);
  264. void IcaStackFreePool(IN PVOID Pointer);
  265. ULONG IcaGetLowWaterMark(IN PSDCONTEXT pContext);
  266. ULONG IcaGetSizeForNoLowWaterMark(IN PSDCONTEXT pContext);
  267. #endif // __SDAPI_H