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.

559 lines
24 KiB

  1. /****************************************************************************/
  2. // xt.h
  3. //
  4. // XT layer - portable API header.
  5. //
  6. // Copyright (C) 1997-1999 Microsoft Corporation
  7. /****************************************************************************/
  8. #ifndef _H_XT
  9. #define _H_XT
  10. extern "C" {
  11. //#include <amcsapi.h>
  12. //#include <atdapi.h>
  13. #include <adcgdata.h>
  14. }
  15. #include "mcs.h"
  16. #include "td.h"
  17. #include "cd.h"
  18. #define TRC_FILE "xtapi"
  19. #define TRC_GROUP TRC_GROUP_NETWORK
  20. /****************************************************************************/
  21. /* Define the XT buffer handle type. */
  22. /****************************************************************************/
  23. typedef ULONG_PTR XT_BUFHND;
  24. typedef XT_BUFHND DCPTR PXT_BUFHND;
  25. /****************************************************************************/
  26. /* Maximum and minimum sizes of an XT header. These are traced out in */
  27. /* XT_Init for diagnostic purposes. */
  28. /****************************************************************************/
  29. #define XT_MAX_HEADER_SIZE DC_MAX(sizeof(XT_CR), \
  30. DC_MAX(sizeof(XT_CC), \
  31. DC_MAX(sizeof(XT_DR), \
  32. DC_MAX(sizeof(XT_DT), \
  33. sizeof(XT_ER)))))
  34. #define XT_MIN_HEADER_SIZE DC_MIN(sizeof(XT_CR), \
  35. DC_MIN(sizeof(XT_CC), \
  36. DC_MIN(sizeof(XT_DR), \
  37. DC_MIN(sizeof(XT_DT), \
  38. sizeof(XT_ER)))))
  39. //
  40. // Internal
  41. //
  42. /****************************************************************************/
  43. /* XT receive state variables. */
  44. /****************************************************************************/
  45. #define XT_RCVST_HEADER 1
  46. #define XT_RCVST_FASTPATH_OUTPUT_HEADER 2
  47. #define XT_RCVST_FASTPATH_OUTPUT_BEGIN_DATA 3
  48. #define XT_RCVST_FASTPATH_OUTPUT_CONTINUE_DATA 4
  49. #define XT_RCVST_X224_HEADER 5
  50. #define XT_RCVST_X224_CONTROL 6
  51. #define XT_RCVST_X224_DATA 7
  52. // The base number of bytes needed to parse a fast-path output header.
  53. #define XT_FASTPATH_OUTPUT_BASE_HEADER_SIZE 2
  54. /****************************************************************************/
  55. /* XT packet types. These values are the same as those used in the X224 */
  56. /* header. */
  57. /****************************************************************************/
  58. #define XT_PKT_CR 14
  59. #define XT_PKT_CC 13
  60. #define XT_PKT_DR 8
  61. #define XT_PKT_DT 15
  62. #define XT_PKT_ER 7
  63. /****************************************************************************/
  64. /* Maximum data size. The maximum length of data in an XT packet (the TSDU */
  65. /* length) is 65535 octets less the length of the XT data header (which is */
  66. /* 7 octets) so the maximum allowable data len is 65528 octets. */
  67. /****************************************************************************/
  68. #define XT_MAX_DATA_SIZE (65535 - sizeof(XT_DT))
  69. /****************************************************************************/
  70. /* TPKT version. This should always be 3. */
  71. /****************************************************************************/
  72. #define XT_TPKT_VERSION 3
  73. /****************************************************************************/
  74. /* Hard-coded data for XT TPDUs. */
  75. /* */
  76. /* First up is the data for the Connect-Request TPDU. */
  77. /****************************************************************************/
  78. #define XT_CR_DATA \
  79. {0x03, /* TPKT version always = 3 */ \
  80. 0x00, /* Reserved always = 0 */ \
  81. 0x00, /* XT packet length high part */ \
  82. 0x0B, /* XT packet length low part */ \
  83. 0x06, /* Length indicator */ \
  84. 0xE0, /* TPDU type and credit */ \
  85. 0x00, /* Destination ref = 0 */ \
  86. 0x00, /* Source ref */ \
  87. 0x00} /* Class and options */ \
  88. /****************************************************************************/
  89. /* Hard-coded data for the Data TPDU. */
  90. /****************************************************************************/
  91. #define XT_DT_DATA \
  92. {0x03, /* TPKT version always = 3 */ \
  93. 0x00, /* Reserved always = 0 */ \
  94. 0x00, /* XT packet length unknown */ \
  95. 0x00, /* XT packet length unknown */ \
  96. 0x02, /* Length indicator */ \
  97. 0xF0, /* TPDU type */ \
  98. 0x80} /* Send-sequence number */ \
  99. /****************************************************************************/
  100. /* Constants used in redirection info in XTSendCR */
  101. /****************************************************************************/
  102. #define USERNAME_TRUNCATED_LENGTH 10
  103. #define HASHMODE_COOKIE_LENGTH 32
  104. /****************************************************************************/
  105. /* Inline functions to convert between XT byte order and local byte order. */
  106. /****************************************************************************/
  107. __inline DCUINT16 DCINTERNAL XTWireToLocal16(DCUINT16 val)
  108. {
  109. return((DCUINT16) (((DCUINT16)(((PDCUINT8)&(val))[0]) << 8) | \
  110. ((DCUINT16)(((PDCUINT8)&(val))[1]))));
  111. }
  112. #define XTLocalToWire16 XTWireToLocal16
  113. /****************************************************************************/
  114. // Turn on single-byte packing for these structures which we use to
  115. // overlay a byte stream from the network.
  116. /****************************************************************************/
  117. #pragma pack(push, XTpack, 1)
  118. /****************************************************************************/
  119. /* Structure: XT_CMNHDR */
  120. /* */
  121. /* Description: This structure represents the common header part of an XT */
  122. /* packet - which is the TPKT header, the X224 length */
  123. /* indicator and the X224 type/Credit field. */
  124. /****************************************************************************/
  125. typedef struct tagXT_CMNHDR
  126. {
  127. DCUINT8 vrsn;
  128. DCUINT8 reserved;
  129. DCUINT8 lengthHighPart;
  130. DCUINT8 lengthLowPart;
  131. DCUINT8 li;
  132. DCUINT8 typeCredit;
  133. } XT_CMNHDR, DCPTR PXT_CMNHDR;
  134. /****************************************************************************/
  135. /* Structure: XT_CR */
  136. /* */
  137. /* Description: Represents a Connect-Request TPDU. */
  138. /****************************************************************************/
  139. typedef struct tagXT_CR
  140. {
  141. XT_CMNHDR hdr;
  142. DCUINT16 dstRef;
  143. DCUINT16 srcRef;
  144. DCUINT8 classOptions;
  145. } XT_CR, DCPTR PXT_CR;
  146. /****************************************************************************/
  147. /* Structure: XT_CC */
  148. /* */
  149. /* Description: Represents a Connect-Confirm TPDU. */
  150. /****************************************************************************/
  151. typedef struct tagXT_CC
  152. {
  153. XT_CMNHDR hdr;
  154. DCUINT16 dstRef;
  155. DCUINT16 srcRef;
  156. DCUINT8 classOptions;
  157. } XT_CC, DCPTR PXT_CC;
  158. /****************************************************************************/
  159. /* Structure: XT_DR */
  160. /* */
  161. /* Description: Represents a Detach-Request TPDU. */
  162. /****************************************************************************/
  163. typedef struct tagXT_DR
  164. {
  165. XT_CMNHDR hdr;
  166. DCUINT16 dstRef;
  167. DCUINT16 srcRef;
  168. DCUINT8 reason;
  169. } XT_DR, DCPTR PXT_DR;
  170. /****************************************************************************/
  171. /* Structure: XT_DT */
  172. /* */
  173. /* Description: Represents a Data TPDU. */
  174. /****************************************************************************/
  175. typedef struct tagXT_DT
  176. {
  177. XT_CMNHDR hdr;
  178. DCUINT8 nrEot;
  179. } XT_DT, DCPTR PXT_DT;
  180. /****************************************************************************/
  181. /* Structure: XT_ER */
  182. /* */
  183. /* Description: Represents an Error TPDU. */
  184. /****************************************************************************/
  185. typedef struct tagXT_ER
  186. {
  187. XT_CMNHDR hdr;
  188. DCUINT16 dstRef;
  189. DCUINT8 cause;
  190. } XT_ER, DCPTR PXT_ER;
  191. /****************************************************************************/
  192. /* Reset structure packing to its default. */
  193. /****************************************************************************/
  194. #pragma pack(pop, XTpack)
  195. /****************************************************************************/
  196. /* Structure: XT_GLOBAL_DATA */
  197. /* */
  198. /* Description: */
  199. /****************************************************************************/
  200. typedef struct tagXT_GLOBAL_DATA
  201. {
  202. DCUINT rcvState;
  203. DCUINT hdrBytesNeeded;
  204. DCUINT hdrBytesRead;
  205. DCUINT dataBytesLeft;
  206. DCUINT disconnectErrorCode;
  207. DCBOOL dataInXT;
  208. DCUINT8 pHdrBuf[XT_MAX_HEADER_SIZE];
  209. DCBOOL inXTOnTDDataAvail;
  210. } XT_GLOBAL_DATA;
  211. class CCD;
  212. class CSL;
  213. class CTD;
  214. class CMCS;
  215. class CUT;
  216. #include "objs.h"
  217. class CXT
  218. {
  219. public:
  220. CXT(CObjs* objs);
  221. ~CXT();
  222. public:
  223. //
  224. // API functions
  225. //
  226. /****************************************************************************/
  227. /* FUNCTIONS */
  228. /****************************************************************************/
  229. DCVOID DCAPI XT_Init(DCVOID);
  230. DCVOID DCAPI XT_SendBuffer(PDCUINT8 pData,
  231. DCUINT dataLength,
  232. XT_BUFHND bufHandle);
  233. DCUINT DCAPI XT_Recv(PDCUINT8 pData, DCUINT length);
  234. DCVOID DCINTERNAL XTSendCR(ULONG_PTR unused);
  235. EXPOSE_CD_SIMPLE_NOTIFICATION_FN(CXT, XTSendCR);
  236. DCVOID DCINTERNAL XTHandleControlPkt(DCVOID);
  237. inline XT_ResetDataState(DCVOID)
  238. {
  239. _XT.rcvState = XT_RCVST_HEADER;
  240. _XT.hdrBytesNeeded = XT_FASTPATH_OUTPUT_BASE_HEADER_SIZE;
  241. _XT.hdrBytesRead = 0;
  242. _XT.dataBytesLeft = 0;
  243. _XT.dataInXT = FALSE;
  244. }
  245. inline XT_IgnoreRestofPacket(DCVOID)
  246. {
  247. XT_ResetDataState();
  248. TD_IgnoreRestofPacket(_pTd);
  249. }
  250. //
  251. // Callbacks
  252. //
  253. DCVOID DCCALLBACK XT_OnTDConnected(DCVOID);
  254. DCVOID DCCALLBACK XT_OnTDDisconnected(DCUINT reason);
  255. DCVOID DCCALLBACK XT_OnTDDataAvailable(DCVOID);
  256. //
  257. // Static versions (delegate to appropriate instance)
  258. //
  259. inline static DCVOID DCCALLBACK XT_StaticOnTDConnected(CXT* inst)
  260. {
  261. inst->XT_OnTDConnected();
  262. }
  263. inline static DCVOID DCCALLBACK XT_StaticOnTDDisconnected(CXT* inst, DCUINT reason)
  264. {
  265. inst->XT_OnTDDisconnected( reason);
  266. }
  267. inline DCVOID DCCALLBACK XT_StaticOnTDBufferAvailable(CXT* inst)
  268. {
  269. inst->XT_OnTDBufferAvailable();
  270. }
  271. /****************************************************************************/
  272. /* Name: XT_Term */
  273. /* */
  274. /* Purpose: This terminates _XT. Since XT is stateless and doesn't own */
  275. /* any resources which need to be freed this function just calls */
  276. /* _pTd->TD_Term. */
  277. /****************************************************************************/
  278. inline DCVOID DCAPI XT_Term(DCVOID)
  279. {
  280. _pTd->TD_Term();
  281. } /* XT_Term */
  282. /****************************************************************************/
  283. /* Name: XT_Connect */
  284. /* */
  285. /* Purpose: Initiates the XT connection process. The first stage is */
  286. /* to connect TD - which will result in an asynchronous */
  287. /* callback. Upon receiving this callback, XT can continue the */
  288. /* connection process. */
  289. /* */
  290. /* Params: IN bInitiateConnect - TRUE if initate connection, FALSE */
  291. /* connect with existing socket */
  292. /* IN pServerAddress - the address of the server to connect to. */
  293. /****************************************************************************/
  294. inline DCVOID DCAPI XT_Connect(BOOL bInitiateConnect, PDCTCHAR pServerAddress)
  295. {
  296. //
  297. // Make sure to reset XT and TD state from any previous connections
  298. //
  299. XT_IgnoreRestofPacket();
  300. /************************************************************************/
  301. /* Begin the connection process by calling TD_Connect. TD will call */
  302. /* us back once the connection has been established. */
  303. /************************************************************************/
  304. _pTd->TD_Connect(bInitiateConnect, pServerAddress);
  305. } /* XT_Connect */
  306. /****************************************************************************/
  307. /* Name: XT_Disconnect */
  308. /* */
  309. /* Purpose: This function disconnects from the server. Since we do not */
  310. /* send an XT DR packet we just need to call TD_Disconnect */
  311. /* directly. */
  312. /****************************************************************************/
  313. inline DCVOID DCAPI XT_Disconnect(DCVOID)
  314. {
  315. _pTd->TD_Disconnect();
  316. } /* XT_Disconnect */
  317. /**PROC+*********************************************************************/
  318. /* Name: XT_GetBufferHeaderLen */
  319. /* */
  320. /* Purpose: Returns the size of the XT header. */
  321. /**PROC-*********************************************************************/
  322. inline DCUINT XT_GetBufferHeaderLen(DCVOID)
  323. {
  324. return(sizeof(XT_DT));
  325. } /* XT_GetBufferHeaderLen */
  326. /****************************************************************************/
  327. /* Name: XT_GetPublicBuffer */
  328. /* */
  329. /* Purpose: Attempts to get a public buffer. This function gets a */
  330. /* buffer which is big enough to include the XT header and then */
  331. /* updates the buffer pointer obtained from TD past the space */
  332. /* reserved for the XT header. */
  333. /* */
  334. /* Returns: TRUE if a buffer is successfully obtained and FALSE */
  335. /* otherwise. */
  336. /* */
  337. /* Params: IN dataLength - length of the buffer requested. */
  338. /* OUT ppBuffer - a pointer to a pointer to the buffer. */
  339. /* OUT pBufHandle - a pointer to a buffer handle. */
  340. /****************************************************************************/
  341. inline DCBOOL DCAPI XT_GetPublicBuffer(
  342. DCUINT dataLength,
  343. PPDCUINT8 ppBuffer,
  344. PXT_BUFHND pBufHandle)
  345. {
  346. DCBOOL rc;
  347. PDCUINT8 pBuf;
  348. DC_BEGIN_FN("XT_GetPublicBuffer");
  349. // Now get a buffer from TD, adding the max XT data header size to the
  350. // beginning.
  351. rc = _pTd->TD_GetPublicBuffer(dataLength + sizeof(XT_DT), &pBuf,
  352. (PTD_BUFHND) pBufHandle);
  353. if (rc) {
  354. // Now move the buffer pointer along to make space for our header.
  355. *ppBuffer = pBuf + sizeof(XT_DT);
  356. }
  357. else {
  358. TRC_NRM((TB, _T("Failed to get a public buffer from TD")));
  359. }
  360. DC_END_FN();
  361. return rc;
  362. } /* XT_GetPublicBuffer */
  363. /****************************************************************************/
  364. /* Name: XT_GetPrivateBuffer */
  365. /* */
  366. /* Purpose: Attempts to get a private buffer. This function gets a */
  367. /* buffer which is big enough to include the XT header and then */
  368. /* updates the buffer pointer obtained from TD past the space */
  369. /* reserved for the XT header. */
  370. /* */
  371. /* Returns: TRUE if a buffer is successfully obtained and FALSE */
  372. /* otherwise. */
  373. /* */
  374. /* Params: IN dataLength - length of the buffer requested. */
  375. /* OUT ppBuffer - a pointer to a pointer to the buffer. */
  376. /* OUT pBufHandle - a pointer to a buffer handle. */
  377. /****************************************************************************/
  378. inline DCBOOL DCAPI XT_GetPrivateBuffer(
  379. DCUINT dataLength,
  380. PPDCUINT8 ppBuffer,
  381. PXT_BUFHND pBufHandle)
  382. {
  383. DCBOOL rc;
  384. PDCUINT8 pBuf;
  385. DC_BEGIN_FN("XT_GetPublicBuffer");
  386. // Now get a buffer from TD, adding the max XT data header size to the
  387. // beginning.
  388. rc = _pTd->TD_GetPrivateBuffer(dataLength + sizeof(XT_DT), &pBuf,
  389. (PTD_BUFHND) pBufHandle);
  390. if (rc) {
  391. // Now move the buffer pointer along to make space for our header.
  392. *ppBuffer = pBuf + sizeof(XT_DT);
  393. }
  394. else {
  395. TRC_NRM((TB, _T("Failed to get a public buffer from TD")));
  396. }
  397. DC_END_FN();
  398. return rc;
  399. } /* XT_GetPrivateBuffer */
  400. /****************************************************************************/
  401. /* Name: XT_FreeBuffer */
  402. /* */
  403. /* Purpose: Frees a buffer. */
  404. /****************************************************************************/
  405. inline DCVOID DCAPI XT_FreeBuffer(XT_BUFHND bufHandle)
  406. {
  407. /************************************************************************/
  408. /* Not much to do here other than call TD. */
  409. /************************************************************************/
  410. _pTd->TD_FreeBuffer((TD_BUFHND)bufHandle);
  411. } /* XT_FreeBuffer */
  412. /****************************************************************************/
  413. /* Name: XT_QueryDataAvailable */
  414. /* */
  415. /* Purpose: This function returns whether data is currently available */
  416. /* in _XT. */
  417. /* */
  418. /* Returns: TRUE if data is available and FALSE otherwise. */
  419. /****************************************************************************/
  420. _inline DCBOOL DCAPI XT_QueryDataAvailable(DCVOID)
  421. {
  422. DC_BEGIN_FN("XT_QueryDataAvailable");
  423. TRC_DBG((TB, "Data is%s available in XT", _XT.dataInXT ? "" : _T(" NOT")));
  424. DC_END_FN();
  425. return _XT.dataInXT;
  426. } /* XT_QueryDataAvailable */
  427. /****************************************************************************/
  428. /* Name: XT_OnTDBufferAvailable */
  429. /* */
  430. /* Purpose: Callback from TD indicating that a back-pressure situation */
  431. /* which caused an earlier TD_GetBuffer call to fail has now */
  432. /* been relieved. */
  433. /****************************************************************************/
  434. inline DCVOID DCCALLBACK XT_OnTDBufferAvailable(DCVOID)
  435. {
  436. /************************************************************************/
  437. /* We're not interested in this notification so just pass it up. */
  438. /************************************************************************/
  439. _pMcs->MCS_OnXTBufferAvailable();
  440. } /* XT_OnTDBufferAvailable */
  441. public:
  442. //
  443. // Public data members
  444. //
  445. XT_GLOBAL_DATA _XT;
  446. private:
  447. CCD* _pCd;
  448. CSL* _pSl;
  449. CTD* _pTd;
  450. CMCS* _pMcs;
  451. CUT* _pUt;
  452. CUI* _pUi;
  453. CCLX* _pClx;
  454. private:
  455. CObjs* _pClientObjects;
  456. };
  457. #undef TRC_FILE
  458. #undef TRC_GROUP
  459. #endif //_H_XT