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.

207 lines
7.6 KiB

  1. /* Tprtctrl.h
  2. *
  3. * Copyright (c) 1996 by Microsoft Corporation
  4. *
  5. * Abstract:
  6. * This is the transport for Winsock over TCP.
  7. *
  8. * This module controls making and breaking socket connections. When the
  9. * transport creates or detects a connection, Transprt.cpp is notified.
  10. * It then instantiates a connection object which tracks the socket until
  11. * it is destroyed. The TCP stack notifies Transprt.cpp when a socket
  12. * connection is up and running. It also notifies us if the link is broken
  13. * for some reason. As a result, the Tprtctrl module will notify the user
  14. * of new or broken connections.
  15. *
  16. * When the user wants to make a data request of a specific transport
  17. * connection, this module maps the connection id to a socket number. The
  18. * data request is passed on to TCP. Data Indications are passed
  19. * to the user by ReadRequest().
  20. *
  21. * USER CALLBACKS:
  22. * The user communicates with this DLL by making calls directly to the
  23. * DLL. The DLL communicates with the user by issuing callbacks.
  24. * The TInitialize() call accepts as a parameter, a callback address and
  25. * a user defined variable. When a significant event occurs in the DLL,
  26. * the DLL will jump to the callback address. The first parameter of
  27. * the callback is the message. This could be a CONNECT_INDICATION,
  28. * DISCONNECT_INDICATION, or any number of significant events. The
  29. * second parameter is a message specific parameter. The third
  30. * parameter is the user defined variable that was passed in during
  31. * the TInitialize() function. See the MCATTPRT.h interface file
  32. * for a complete description of the callback messages.
  33. *
  34. * MAKING A CALL:
  35. * After the initialization has been done, the user will eventually,
  36. * want to attempt a connection. The user issues a TConnectRequest() call
  37. * with the IP address of the remote location. The connection request
  38. * is passed on to the Winsock layer. It eventually issues FD_CONNECT to
  39. * our window to say that the connection was successful.
  40. *
  41. * RECEIVING A CALL:
  42. * If we receive a call from a remote location, Winsock notifies
  43. * us with FD_ACCEPT. We then create a new connection object
  44. * associated with the new socket.
  45. *
  46. * SENDING PACKETS:
  47. * To send data to the remote location, use the DataRequest() function
  48. * call. This module will pass the packet to the socket that it is
  49. * associated with. The send may actually occur after the call has
  50. * returned to the user.
  51. *
  52. * RECEIVING PACKETS:
  53. * The user receives packets by DATA_INDICATION callbacks. When Winsock
  54. * notifies us with a FD_READ, we issue a recv() to receive any new
  55. * packets. If a packet is complete, we issue a DATA_INDICATION
  56. * callback to the user with the socket handle, the address
  57. * of the packet, and the packet length.
  58. *
  59. * DISCONNECTING A TRANSPORT:
  60. * To disconnect a transport connection, use the DisconnectRequest()
  61. * function. After the link has been brought down, we perform a
  62. * callback to the user to verify the disconnect.
  63. *
  64. */
  65. #ifndef _TRANSPORT_CONTROLLER_
  66. #define _TRANSPORT_CONTROLLER_
  67. /* Header for a RFC1006 packet */
  68. typedef struct _rfc_tag
  69. {
  70. UChar Version; /* Should be RFC1006_VERSION_NUMBER (3) */
  71. UChar Reserved; /* Must be 0x00 */
  72. UChar msbPacketSize; /* msb of packet size, including RFC header */
  73. UChar lsbPacketSize; /* lsb of packet size, including RFC header */
  74. } RFC_HEADER;
  75. /* Header for X224 data packet */
  76. typedef struct _data_packet_tag
  77. {
  78. RFC_HEADER rfc; /* RFC1006 packet header */
  79. UChar HeaderSize; /* Must be 0x02, for data packets */
  80. UChar PacketType; /* Must be DATA_PACKET, for data packets */
  81. UChar FinalPacket; /* EOT_BIT or 0 */
  82. } X224_DATA_PACKET;
  83. #include "socket.h"
  84. /* Connection Info (used for both CONNECTION_REQUEST and CONNECTION_CONFIRM) */
  85. typedef struct _connect_common_tag
  86. {
  87. UChar PacketType; /* CONNECTION_REQUEST_PACKET or CONFIRM_PACKET */
  88. UChar msbDest; /* msb of destination-side (answering) socket id */
  89. UChar lsbDest; /* lsb of destination-side (answering) socket id */
  90. UChar msbSrc; /* msb of source-side (initiating) socket id */
  91. UChar lsbSrc; /* lsb of source-side (initiating) socket id */
  92. UChar DataClass; /* Must be 0x00 */
  93. } X224_CONNECT_COMMON;
  94. /* Transport variable field info type and size. */
  95. typedef struct _t_variable_field_info
  96. {
  97. UChar InfoType;
  98. UChar InfoSize;
  99. } X224_VARIABLE_INFO;
  100. /* TPDU Arbitration Info (not used with CONNECTION_CONFIRM) */
  101. typedef struct _tpdu_info_tag
  102. {
  103. UChar InfoType; /* Must be TPDU_SIZE (192) */
  104. UChar InfoSize; /* Must be 1 */
  105. UChar Info; /* Requested PDU Size (default: 10, or 1K bytes) */
  106. } X224_TPDU_INFO;
  107. /* Minimal Connection Request/Confirm packet */
  108. typedef struct _connect_tag
  109. {
  110. RFC_HEADER rfc; /* RFC1006 packet header */
  111. UChar HeaderSize;
  112. X224_CONNECT_COMMON conn; /* Connection Info */
  113. } X224_CONNECT;
  114. typedef X224_CONNECT X224_CR_FIXED;
  115. typedef X224_CONNECT X224_CC_FIXED;
  116. typedef struct _disconnect_info_tag
  117. {
  118. UChar PacketType; /* Must be DISCONNECT_REQUEST_PACKET */
  119. UChar msbDest;
  120. UChar lsbDest;
  121. UChar msbSrc;
  122. UChar lsbSrc;
  123. UChar reason; /* DR Reason Code */
  124. } X224_DISCONN;
  125. typedef struct _disconnect_request_fixed
  126. {
  127. RFC_HEADER rfc;
  128. UChar HeaderSize;
  129. X224_DISCONN disconn;
  130. } X224_DR_FIXED;
  131. #define X224_SIZE_OFFSET 2
  132. #define UNK 0 // Used to initialize fields in static
  133. // data structures that will be initialized
  134. // later.
  135. /* 2^DEFAULT_TPDU_SIZE is the default X224 packet size we request */
  136. #define DEFAULT_TPDU_SIZE 13 /* 2^13 is 8K packet size */
  137. #define LOWEST_TPDU_SIZE 7 /* 2^7 is 128 bytes */
  138. #define HIGHEST_TPDU_SIZE 20 /* 2^20 is ... too big */
  139. #define DEFAULT_MAX_X224_SIZE (1 << DEFAULT_TPDU_SIZE)
  140. /* Function definitions */
  141. TransportError ConnectRequest (TransportAddress transport_address, BOOL fSecure, PTransportConnection pXprtConn);
  142. BOOL ConnectResponse (TransportConnection XprtConn);
  143. void DisconnectRequest (TransportConnection XprtConn, ULONG ulNotify);
  144. TransportError DataRequest ( TransportConnection XprtConn,
  145. PSimplePacket packet);
  146. void SendX224ConnectRequest (TransportConnection);
  147. void EnableReceiver (Void);
  148. void PurgeRequest (TransportConnection XprtConn);
  149. void AcceptCall (TransportType);
  150. void AcceptCall (TransportConnection);
  151. void ReadRequest(TransportConnection);
  152. void ReadRequestEx(TransportConnection);
  153. TransportError FlushSendBuffer(PSocket pSocket, LPBYTE buffer, UINT length);
  154. #ifdef TSTATUS_INDICATION
  155. Void SendStatusMessage( PChar RemoteAddress,
  156. TransportState state,
  157. UInt message_id);
  158. #endif
  159. void QoSLock(Void);
  160. void QoSUnlock(Void);
  161. void ShutdownAndClose (TransportConnection, BOOL fShutdown, int how );
  162. TransportError GetLocalAddress(TransportConnection XprtConn,
  163. TransportAddress address,
  164. int * size);
  165. /* The TCP message window procedure (processes all Windows messages) */
  166. LRESULT WindowProcedure (HWND, UINT, WPARAM, LPARAM);
  167. /* RFC definitions */
  168. #define RFC1006_VERSION_NUMBER 3
  169. #define RFC1006_VERSION_SHIFTED_LEFT 0x03000000L /* Optimizes AddRFCHeader */
  170. /* Packet types */
  171. #define CONNECTION_REQUEST_PACKET 0xe0
  172. #define CONNECTION_CONFIRM_PACKET 0xd0
  173. #define DISCONNECT_REQUEST_PACKET 0x80
  174. #define ERROR_PACKET 0x70
  175. #define DATA_PACKET 0xf0
  176. #define TPDU_SIZE 0xc0
  177. #define T_SELECTOR 0xc1
  178. #define T_SELECTOR_2 0xc2
  179. /* X224 definitions */
  180. #define EOT_BIT 0x80
  181. /* Macro to fill-in RFC header at specified buffer location */
  182. #define AddRFCSize(ptr, size) { \
  183. ASSERT((size) < 65536L ); \
  184. ((LPBYTE) (ptr))[X224_SIZE_OFFSET] = (BYTE) ((size) >> 8); \
  185. ((LPBYTE) (ptr))[X224_SIZE_OFFSET + 1] = (BYTE) (size); }
  186. #endif /* _TRANSPORT_CONTROLLER_ */