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.

495 lines
16 KiB

  1. /* (C) 1997-1999 Microsoft Corp.
  2. *
  3. * file : MCSImpl.h
  4. * author : Erik Mavrinac
  5. *
  6. * description: MCS implementation-specific defines and structures.
  7. */
  8. #ifndef __MCSIMPL_H
  9. #define __MCSIMPL_H
  10. #include "MCSKernl.h"
  11. #include "X224.h"
  12. #include "MCSIOCTL.h"
  13. #include "SList.h"
  14. #include "Trace.h"
  15. #include "rdperr.h"
  16. #include "domain.h"
  17. /*
  18. * Defines
  19. */
  20. // Memory defines.
  21. #define MCS_POOL_TAG 'cmST'
  22. // Used with PDU handler function tables to allow a PDU name in debug builds.
  23. #if DBG
  24. #define StrOnDbg(str, func) { str, func }
  25. #else
  26. #define StrOnDbg(str, func) { func }
  27. #endif // DBG
  28. #define NULL_ChannelID 0
  29. #define NULL_TokenID 0
  30. #define NULL_UserID 0
  31. // Start of the dynamic MCS channel numbering space.
  32. #define MinDynamicChannel 1002
  33. // Types of channels possible in the MCSChannel struct below.
  34. #define Channel_Unused 0
  35. #define Channel_Static 1
  36. #define Channel_UserID 2
  37. #define Channel_Assigned 3
  38. #define Channel_Convened 4
  39. // Default starting sizes for allocation pools. These are provided as hints
  40. // to data structure management code.
  41. #define DefaultNumChannels 5
  42. #define DefaultNumUserAttachments 2
  43. // DomainParameters required min and max settings.
  44. #define RequiredMinChannels 4
  45. #define RequiredMinUsers 3
  46. #define RequiredDomainHeight 1
  47. #define RequiredMinPDUSize 124
  48. #define RequiredProtocolVer 2
  49. #define RequiredPriorities 1
  50. // Connection states for PD.State below.
  51. // Connection sequence like this:
  52. // 1. Start state: Unconnected
  53. // 2. Client socket created, state: Unconnected
  54. // 3. X.224 Connect TPDU comes in, send accept. State: X224_Connected
  55. // 4. MCS connect-initial comes in, send up to node controller for acceptance,
  56. // state: ConnectProvIndPending
  57. // 5. Node controller responds with connect-provider response: if accepted
  58. // (RESULT_SUCCESSFUL) state = MCS_Connected; otherwise state =
  59. // Disconnected.
  60. // 6. Client sends MCS disconnect-provider ultimatum: state = Disconnected.
  61. // 7. Server calls DisconnectProvider: state = Disconnected.
  62. #define State_Unconnected 0
  63. #define State_X224_Connected 1
  64. #define State_X224_Requesting 2
  65. #define State_ConnectProvIndPending 3
  66. #define State_MCS_Connected 4
  67. #define State_Disconnected 5
  68. // Diagnostic codes - for RejectMCSPDU. Values per T.125 spec.
  69. #define Diag_InconsistentMerge 0
  70. #define Diag_ForbiddenPDUDownward 1
  71. #define Diag_ForbiddenPDUUpward 2
  72. #define Diag_InvalidBEREncoding 3
  73. #define Diag_InvalidPEREncoding 4
  74. #define Diag_MisroutedUser 5
  75. #define Diag_UnrequestedConfirm 6
  76. #define Diag_WrongTransportPriority 7
  77. #define Diag_ChannelIDConflict 8
  78. #define Diag_TokenIDConflict 9
  79. #define Diag_NotUserIDChannel 10
  80. #define Diag_TooManyChannels 11
  81. #define Diag_TooManyTokens 12
  82. #define Diag_TooManyUsers 13
  83. /*
  84. * PDU types and lengths
  85. */
  86. #define MCS_CONNECT_PDU 0x7F
  87. // The 101-based enumerated connect PDU type.
  88. #define MCS_CONNECT_INITIAL_ENUM 0x65
  89. #define MCS_CONNECT_RESPONSE_ENUM 0x66
  90. #define MCS_CONNECT_ADDITIONAL_ENUM 0x67
  91. #define MCS_CONNECT_RESULT_ENUM 0x68
  92. #define MinConnectPDU MCS_CONNECT_INITIAL_ENUM
  93. #define MaxConnectPDU MCS_CONNECT_RESULT_ENUM
  94. // The 0-based enumerated domain PDU type, defined for creating labeled-byte
  95. // tables for Bloodhound.
  96. #define MCS_PLUMB_DOMAIN_INDICATION_ENUM 0
  97. #define MCS_ERECT_DOMAIN_REQUEST_ENUM 1
  98. #define MCS_MERGE_CHANNELS_REQUEST_ENUM 2
  99. #define MCS_MERGE_CHANNELS_CONFIRM_ENUM 3
  100. #define MCS_PURGE_CHANNEL_INDICATION_ENUM 4
  101. #define MCS_MERGE_TOKENS_REQUEST_ENUM 5
  102. #define MCS_MERGE_TOKENS_CONFIRM_ENUM 6
  103. #define MCS_PURGE_TOKEN_INDICATION_ENUM 7
  104. #define MCS_DISCONNECT_PROVIDER_ULTIMATUM_ENUM 8
  105. #define MCS_REJECT_ULTIMATUM_ENUM 9
  106. #define MCS_ATTACH_USER_REQUEST_ENUM 10
  107. #define MCS_ATTACH_USER_CONFIRM_ENUM 11
  108. #define MCS_DETACH_USER_REQUEST_ENUM 12
  109. #define MCS_DETACH_USER_INDICATION_ENUM 13
  110. #define MCS_CHANNEL_JOIN_REQUEST_ENUM 14
  111. #define MCS_CHANNEL_JOIN_CONFIRM_ENUM 15
  112. #define MCS_CHANNEL_LEAVE_REQUEST_ENUM 16
  113. #define MCS_CHANNEL_CONVENE_REQUEST_ENUM 17
  114. #define MCS_CHANNEL_CONVENE_CONFIRM_ENUM 18
  115. #define MCS_CHANNEL_DISBAND_REQUEST_ENUM 19
  116. #define MCS_CHANNEL_DISBAND_INDICATION_ENUM 20
  117. #define MCS_CHANNEL_ADMIT_REQUEST_ENUM 21
  118. #define MCS_CHANNEL_ADMIT_INDICATION_ENUM 22
  119. #define MCS_CHANNEL_EXPEL_REQUEST_ENUM 23
  120. #define MCS_CHANNEL_EXPEL_INDICATION_ENUM 24
  121. #define MCS_SEND_DATA_REQUEST_ENUM 25
  122. #define MCS_SEND_DATA_INDICATION_ENUM 26
  123. #define MCS_UNIFORM_SEND_DATA_REQUEST_ENUM 27
  124. #define MCS_UNIFORM_SEND_DATA_INDICATION_ENUM 28
  125. #define MCS_TOKEN_GRAB_REQUEST_ENUM 29
  126. #define MCS_TOKEN_GRAB_CONFIRM_ENUM 30
  127. #define MCS_TOKEN_INHIBIT_REQUEST_ENUM 31
  128. #define MCS_TOKEN_INHIBIT_CONFIRM_ENUM 32
  129. #define MCS_TOKEN_GIVE_REQUEST_ENUM 33
  130. #define MCS_TOKEN_GIVE_INDICATION_ENUM 34
  131. #define MCS_TOKEN_GIVE_RESPONSE_ENUM 35
  132. #define MCS_TOKEN_GIVE_CONFIRM_ENUM 36
  133. #define MCS_TOKEN_PLEASE_REQUEST_ENUM 37
  134. #define MCS_TOKEN_PLEASE_INDICATION_ENUM 38
  135. #define MCS_TOKEN_RELEASE_REQUEST_ENUM 39
  136. #define MCS_TOKEN_RELEASE_CONFIRM_ENUM 40
  137. #define MCS_TOKEN_TEST_REQUEST_ENUM 41
  138. #define MCS_TOKEN_TEST_CONFIRM_ENUM 42
  139. #define MinDomainPDU MCS_PLUMB_DOMAIN_INDICATION_ENUM
  140. #define MaxDomainPDU MCS_TOKEN_TEST_CONFIRM_ENUM
  141. /*
  142. * PDU size definitions for use allocating buffers for PDUs/headers.
  143. */
  144. // Connect PDUs.
  145. // Connect-response - maximum size. Includes:
  146. // 3 bytes for Result
  147. // 5 bytes for CalledConnectID
  148. // 40 bytes for DomParams
  149. // 6 bytes for UserDataSize
  150. // UserLen bytes for user data
  151. #define ConnectResponseHeaderSize 54
  152. #define ConnectResponseBaseSize(UserLen) (ConnectResponseHeaderSize + UserLen)
  153. #define ConnectResponsePDUSize(UserLen) \
  154. (X224_DataHeaderSize + ConnectResponseBaseSize(UserLen))
  155. // Domain PDUs.
  156. // Prototype for function defined in DomPDU.c.
  157. int GetTotalLengthDeterminantEncodingSize(int);
  158. #define GetLD(x) GetTotalLengthDeterminantEncodingSize(x)
  159. // Plumb-domain indication
  160. #define PDinBaseSize 3
  161. #define PDinPDUSize (X224_DataHeaderSize + PDinBaseSize)
  162. // Erect-domain request
  163. #define EDrqBaseSize 5
  164. #define EDrqPDUSize (X224_DataHeaderSize + EDrqBaseSize)
  165. // Disconnect-provider ultimatum
  166. #define DPumBaseSize 2
  167. #define DPumPDUSize (X224_DataHeaderSize + DPumBaseSize)
  168. // Reject-MCSPDU ultimatum
  169. #define RJumBaseSize(PDUSize) (2 + GetLD(PDUSize) + (PDUSize))
  170. #define RJumPDUSize(PDUSize) (X224_DataHeaderSize + RJumBaseSize(PDUSize))
  171. // Attach-user request
  172. #define AUrqBaseSize 1
  173. #define AUrqPDUSize (X224_DataHeaderSize + AUrqBaseSize)
  174. // Attach-user confirm
  175. #define AUcfBaseSize(bInit) ((bInit) ? 4 : 2)
  176. #define AUcfPDUSize(bInit) (X224_DataHeaderSize + AUcfBaseSize(bInit))
  177. // Detach-user request
  178. #define DUrqBaseSize(NUsers) (2 + GetLD(NUsers) + sizeof(UserID) * (NUsers))
  179. #define DUrqPDUSize(NUsers) (X224_DataHeaderSize + DUrqBaseSize(NUsers))
  180. // Detach-user indication
  181. #define DUinBaseSize(NUsers) DUrqBaseSize(NUsers)
  182. #define DUinPDUSize(NUsers) DUrqPDUSize(NUsers)
  183. // Channel-join request
  184. #define CJrqBaseSize 5
  185. #define CJrqPDUSize (X224_DataHeaderSize + CJrqBaseSize)
  186. // Channel-join confirm
  187. #define CJcfBaseSize(bJoin) ((bJoin) ? 8 : 6)
  188. #define CJcfPDUSize(bJoin) (X224_DataHeaderSize + CJcfBaseSize(bJoin))
  189. // Channel-leave request
  190. #define CLrqBaseSize(NChn) (1 + GetLD(NChn) + sizeof(ChannelID) * (NChn))
  191. #define CLrqPDUSize(NChn) (X224_DataHeaderSize + CLrqBaseSize(NChn))
  192. // Channel-convene request
  193. #define CCrqBaseSize 3
  194. #define CCrqPDUSize (X224_DataHeaderSize + CCrqBaseSize)
  195. // Channel-convene confirm
  196. #define CCcfBaseSize(bChn) ((bChn) ? 6 : 4)
  197. #define CCcfPDUSize(bChn) (X224_DataHeaderSize + CCcfBaseSize(bChn))
  198. // Channel-disband request
  199. #define CDrqBaseSize 5
  200. #define CDrqPDUSize (X224_DataHeaderSize + CDrqBaseSize)
  201. // Channel-disband indication
  202. #define CDinBaseSize 3
  203. #define CDinPDUSize (X224_DataHeaderSize + CDinBaseSize)
  204. // Channel-admit request
  205. #define CArqBaseSize(NUsers) (5 + sizeof(UserID) * (NUsers))
  206. #define CArqPDUSize(NUsers) (X224_DataHeaderSize + CArqBaseSize(NUsers))
  207. // Channel-admit indication
  208. #define CAinBaseSize(NUsers) CArqBaseSize(NUsers)
  209. #define CAinPDUSize(NUsers) CAinPDUSize(NUsers)
  210. // Channel-expel request
  211. #define CErqBaseSize(NUsers) CArqBaseSize(NUsers)
  212. #define CErqPDUSize(NUsers) CAinPDUSize(NUsers)
  213. // Channel-expel indication
  214. #define CEinBaseSize(NUsers) (3 + sizeof(UserID) * (NUsers))
  215. #define CEinPDUSize(NUsers) (X224_DataHeaderSize + CEinBaseSize(NUsers))
  216. // Send data
  217. #define SDBaseSize(DataSize) (6 + GetLD(DataSize) + (DataSize))
  218. #define SDPDUSize(DataSize) (X224_DataHeaderSize + SDBaseSize(DataSize))
  219. // Token-grab request
  220. #define TGrqBaseSize 5
  221. #define TGrqPDUSize (X224_DataHeaderSize + TGrqBaseSize)
  222. // Token-grab confirm
  223. #define TGcfBaseSize 7
  224. #define TGcfPDUSize (X224_DataHeaderSize + TGcfBaseSize)
  225. // Token-inhibit request
  226. #define TIrqBaseSize 5
  227. #define TIrqPDUSize (X224_DataHeaderSize + TIrqBaseSize)
  228. // Token-inhibit confirm
  229. #define TIcfBaseSize TGcfBaseSize
  230. #define TIcfPDUSize TGcfPDUSize
  231. // Token-give request
  232. #define TVrqBaseSize 7
  233. #define TVrqPDUSize (X224_DataHeaderSize + TVrqBaseSize)
  234. // Token-give indication
  235. #define TVinBaseSize 7
  236. #define TVinPDUSize (X224_DataHeaderSize + TVinBaseSize)
  237. // Token-give response
  238. #define TVrsBaseSize 6
  239. #define TVrsPDUSize (X224_DataHeaderSize + TVrsBaseSize)
  240. // Token-give confirm
  241. #define TVcfBaseSize TGcfBaseSize
  242. #define TVcfPDUSize TGcfPDUSize
  243. // Token-please request
  244. #define TPrqBaseSize 5
  245. #define TPrqPDUSize (X224_DataHeaderSize + TPrqBaseSize)
  246. // Token-please indication
  247. #define TPinBaseSize 5
  248. #define TPinPDUSize (X224_DataHeaderSize + TPinBaseSize)
  249. // Token-release request
  250. #define TRrqBaseSize 5
  251. #define TRrqPDUSize (X224_DataHeaderSize + TRrqBaseSize)
  252. // Token-release confirm
  253. #define TRcfBaseSize TGcfBaseSize
  254. #define TRcfPDUSize TGcfPDUSize
  255. // Token-test request
  256. #define TTrqBaseSize 5
  257. #define TTrqPDUSize (X224_DataHeaderSize + TTrqBaseSize)
  258. // Token-test confirm
  259. #define TTcfBaseSize 6
  260. #define TTcfPDUSize (X224_DataHeaderSize + TTcfBaseSize)
  261. /*
  262. * Utility macros and prototypes for decoding and encoding domain PDUs.
  263. */
  264. #define GetByteswappedShort(pStartByte) \
  265. ((*(pStartByte) << 8) + *((pStartByte) + 1))
  266. #define PutByteswappedShort(pStartByte, Val) \
  267. { \
  268. *(pStartByte) = ((Val) & 0xFF00) >> 8; \
  269. *((pStartByte) + 1) = (Val) & 0x00FF; \
  270. }
  271. // Regular Channel ID -- 0..65535: 16 bits.
  272. #define GetChannelID(pStartByte) GetByteswappedShort(pStartByte)
  273. #define PutChannelID(pStartByte, ChID) PutByteswappedShort(pStartByte, ChID)
  274. // Dynamic Channel ID -- 1001..65535: 16 bits, advanced to offset 1001.
  275. #define GetDynamicChannelID(pStartByte) \
  276. ((GetByteswappedShort(pStartByte)) + 1001)
  277. #define PutDynamicChannelID(pStartByte, DChID) \
  278. PutByteswappedShort(pStartByte, (DChID) - 1001)
  279. // Token ID -- 0..65535: 16 bits.
  280. #define GetTokenID(pStartByte) GetByteswappedShort(pStartByte)
  281. #define PutTokenID(pStartByte, TokID) PutByteswappedShort(pStartByte, TokID)
  282. // User ID -- same as dynamic channel ID.
  283. #define GetUserID(pStartByte) GetDynamicChannelID(pStartByte)
  284. #define PutUserID(pStartByte, UsrID) PutDynamicChannelID(pStartByte, UsrID)
  285. // Private channel ID -- same as dynamic channel ID.
  286. #define GetPrivateChannelID(pStartByte) GetDynamicChannelID(pStartByte)
  287. #define PutPrivateChannelID(pStartByte, PrvChID) \
  288. PutDynamicChannelID(pStartByte, PrvChID)
  289. // Reason field.
  290. #define Get3BitFieldAtBit1(pStartByte) \
  291. (((*(pStartByte) & 0x03) << 1) + ((*((pStartByte) + 1) & 0x80) >> 7))
  292. #define Put3BitFieldAtBit1(pStartByte, Val) \
  293. { \
  294. *(pStartByte) |= (((Val) & 0x06) >> 1); \
  295. *((pStartByte) + 1) |= (((Val) & 0x01) << 7); \
  296. }
  297. // Result and Diagnostic fields in various PDUs.
  298. #define Get4BitFieldAtBit0(pStartByte) \
  299. (((*(pStartByte) & 0x01) << 3) + ((*((pStartByte) + 1) & 0xE0) >> 5))
  300. #define Put4BitFieldAtBit0(pStartByte, Val) \
  301. { \
  302. *(pStartByte) |= (((Val) & 0x08) >> 3); \
  303. *((pStartByte) + 1) |= (((Val) & 0x07) << 5); \
  304. }
  305. #define Get4BitFieldAtBit1(pStartByte) \
  306. (((*(pStartByte) & 0x03) << 2) + ((*((pStartByte) + 1) & 0xC0) >> 6))
  307. #define Put4BitFieldAtBit1(pStartByte, Val) \
  308. { \
  309. *(pStartByte) |= (((Val) & 0x0C) >> 2); \
  310. *((pStartByte) + 1) |= (((Val) & 0x03) << 6); \
  311. }
  312. //
  313. // Input buffer allocations are biased to be 8 bytes bigger
  314. // than necessary because the decompression code prefetches
  315. // bytes from after the end of the input buffer.
  316. // It's evil, but it avoids a lot of branches in perf critical code.
  317. // NOTE: We could change the decompression code to check for buffer
  318. // end but it is performance critical so we're not touching it.
  319. //
  320. #define INPUT_BUFFER_BIAS 8
  321. // T.120 request dispatch function signature.
  322. typedef NTSTATUS (*PT120RequestFunc)(PDomain, PSD_IOCTL);
  323. // PDU dispatch table entries.
  324. typedef struct {
  325. #if DBG
  326. char *Name;
  327. #endif
  328. BOOLEAN (__fastcall *HandlePDUFunc)(Domain *, BYTE *, unsigned, unsigned *);
  329. } MCSPDUInfo;
  330. /*
  331. * Globals
  332. */
  333. // Dispatch table defined in MCSCalls.c.
  334. extern const PT120RequestFunc g_T120RequestDispatch[];
  335. // PDU dispatch table defined in ConPDU.c.
  336. extern const MCSPDUInfo ConnectPDUTable[];
  337. // PDU dispatch table defined in DomPDU.c.
  338. extern const MCSPDUInfo DomainPDUTable[];
  339. /*
  340. * Prototypes.
  341. */
  342. // Defined in Decode.c.
  343. NTSTATUS SendX224Confirm(Domain *);
  344. // Defined in DomPDU.c.
  345. void __fastcall EncodeLengthDeterminantPER(BYTE *, unsigned, unsigned *,
  346. BOOLEAN *, unsigned *);
  347. void CreatePlumbDomainInd(unsigned short, BYTE *);
  348. void CreateDisconnectProviderUlt(int, BYTE *);
  349. NTSTATUS ReturnRejectPDU(PDomain, int, BYTE *, unsigned);
  350. void CreateRejectMCSPDUUlt(int, BYTE *, unsigned, BYTE *);
  351. void CreateAttachUserCon(int, BOOLEAN, UserID, BYTE *);
  352. void CreateDetachUserInd(MCSReason, int, UserID *, BYTE *);
  353. void CreateChannelJoinCon(int, UserID, ChannelID, BOOLEAN, ChannelID, BYTE *);
  354. void CreateChannelConveneCon(MCSResult, UserID, BOOLEAN, ChannelID, BYTE *);
  355. void CreateSendDataPDUHeader(int, UserID, ChannelID, MCSPriority,
  356. Segmentation, BYTE **, unsigned *);
  357. BOOLEAN __fastcall HandleAllSendDataPDUs(PDomain, BYTE *, unsigned, unsigned *);
  358. // Defined in TokenPDU.c.
  359. void CreateTokenCon(int, int, UserID, TokenID, int, BYTE *);
  360. void CreateTokenTestCon(UserID, TokenID, int, BYTE *);
  361. // Defined in MCSCore.c.
  362. ChannelID GetNewDynamicChannel(Domain *);
  363. MCSError DetachUser(Domain *, UserHandle, MCSReason, BOOLEAN);
  364. MCSError ChannelLeave(UserHandle, ChannelHandle, BOOLEAN *);
  365. NTSTATUS DisconnectProvider(PDomain, BOOLEAN, MCSReason);
  366. NTSTATUS SendOutBuf(Domain *, POUTBUF);
  367. // Defined in ConPDU.c.
  368. void CreateConnectResponseHeader(PSDCONTEXT, MCSResult, int,
  369. DomainParameters *, unsigned, BYTE *, unsigned *);
  370. // Defined in IcaIFace.c.
  371. void SignalBrokenConnection(Domain *);
  372. #endif // !defined(__MCSIMPL_H)