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.

454 lines
9.7 KiB

  1. #ifndef _COMMASSOC_
  2. #define _COMMASSOC_
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /*++
  7. Copyright (c) 1989 Microsoft Corporation
  8. Module Name:
  9. assoc.c
  10. Abstract:
  11. This is the header file to be included for calling assoc.c functions
  12. Author:
  13. Pradeep Bahl (PradeepB) Dec-1992
  14. Revision History:
  15. --*/
  16. /*
  17. includes
  18. */
  19. #include <wins.h>
  20. #include "winsock2.h"
  21. #include "comm.h"
  22. /*
  23. defines
  24. */
  25. #define COMMASSOC_UDP_BUFFER_HEAP_SIZE 10000
  26. #define COMMASSOC_UDP_DLG_HEAP_SIZE 5000
  27. #define COMMASSOC_DLG_DS_SZ sizeof(COMMASSOC_DLG_CTX_T)
  28. #define COMMASSOC_ASSOC_DS_SZ sizeof(COMMASSOC_ASSOC_CTX_T)
  29. /*
  30. *
  31. * size of header put by RtlInsertElementGenericTable.
  32. */
  33. FUTURES("Gary Kimura (2/13) said that he would provide a macro for the size")
  34. FUTURES("Use that when it is available")
  35. #define COMMASSOC_TBL_HDR_SIZE (sizeof(RTL_SPLAY_LINKS) + sizeof(LIST_ENTRY))
  36. /*
  37. Size of memory block to allocate for sending any of association set up
  38. messages. We use the largest of the sizes of the various assoc. set up
  39. messages so that we can reuse a buffer. The buffer size is kept a multiple
  40. of 16.
  41. */
  42. #define COMMASSOC_START_REQ_ASSOC_MSG_SIZE (32 + sizeof(COMM_HEADER_T))
  43. #define COMMASSOC_START_RSP_ASSOC_MSG_SIZE (16 + sizeof(COMM_HEADER_T))
  44. #define COMMASSOC_STOP_REQ_ASSOC_MSG_SIZE (16 + sizeof(COMM_HEADER_T))
  45. #define COMMASSOC_ASSOC_MSG_SIZE COMMASSOC_START_REQ_ASSOC_MSG_SIZE
  46. #if SUPPORT612WINS > 0
  47. #define COMMASSOC_POST_BETA1_ASSOC_MSG_SIZE (COMMASSOC_ASSOC_MSG_SIZE + 1)
  48. #endif
  49. /*
  50. Initial memory sizes for heaps used for allocating assoc. and dlg ctx blocks
  51. */
  52. #define COMMASSOC_ASSOC_BLKS_HEAP_SIZE 1000
  53. #define COMMASSOC_DLG_BLKS_HEAP_SIZE 4000
  54. #define COMMASSOC_TCP_MSG_HEAP_SIZE 10000
  55. //
  56. // defines to access the next and prev assoc. in the list
  57. //
  58. #define NEXT_ASSOC_M(pAssocCtx) ((PCOMMASSOC_ASSOC_CTX_T) \
  59. ((pAssocCtx)->Top.Head.Flink))
  60. #define PREV_ASSOC_M(pAssocCtx) ((PCOMMASSOC_ASSOC_CTX_T) \
  61. ((pAssocCtx)->Top.Head.Blink))
  62. //
  63. // Macro to unlink an association from the table of responder associations
  64. // Called by CommStopMonDlg in commapi.c and by CommAssocDeleteAssocInTbl
  65. //
  66. #define COMMASSOC_UNLINK_RSP_ASSOC_M(pAssocCtx) { \
  67. NEXT_ASSOC_M(PREV_ASSOC_M((pAssocCtx))) = NEXT_ASSOC_M((pAssocCtx)); \
  68. PREV_ASSOC_M(NEXT_ASSOC_M((pAssocCtx))) = PREV_ASSOC_M((pAssocCtx)); \
  69. }
  70. /*
  71. Macros
  72. */
  73. //
  74. // Sets up Communication data structures (assoc and dlg ctx blocks)
  75. //
  76. #define COMMASSOC_SETUP_COMM_DS_M(mpDlgCtx, mpAssocCtx, mType_e, mRole_e) \
  77. { \
  78. (mpAssocCtx)->DlgHdl.SeqNo = (mpDlgCtx)->Top.SeqNo; \
  79. (mpAssocCtx)->DlgHdl.pEnt = (mpDlgCtx); \
  80. (mpAssocCtx)->State_e = COMMASSOC_ASSOC_E_ACTIVE; \
  81. (mpAssocCtx)->Typ_e = (mType_e); \
  82. \
  83. (mpDlgCtx)->AssocHdl.SeqNo = (mpAssocCtx)->Top.SeqNo; \
  84. (mpDlgCtx)->AssocHdl.pEnt = (mpAssocCtx); \
  85. (mpDlgCtx)->Role_e = (mRole_e); \
  86. (mpDlgCtx)->Typ_e = (mType_e); \
  87. }
  88. /*
  89. externs
  90. */
  91. /*
  92. Handles to the heaps created for allocating assoc. ctx blocks and
  93. Dlg Ctx blocks
  94. */
  95. extern HANDLE CommAssocAssocHeapHdl;
  96. extern HANDLE CommAssocDlgHeapHdl;
  97. extern HANDLE CommAssocTcpMsgHeapHdl;
  98. /*
  99. typedefs
  100. */
  101. typedef DWORD IP_ADDRESS;
  102. typedef IP_ADDRESS HOST_ADDRESS;
  103. typedef enum _COMMASSOC_ASSOC_STOP_RSN_E {
  104. COMMASSOC_E_USER_INITIATED = 0,
  105. COMMASSOC_E_AUTH_FAILURE,
  106. COMMASSOC_E_INCOMP_VERS,
  107. COMMASSOC_E_BUG_CHECK,
  108. COMMASSOC_E_MSG_ERR //some error in message format
  109. } COMMASSOC_STP_RSN_E, *PCOMMASSOC_STP_RSN_E;
  110. /*
  111. ASSOC_ROLE_E -- Enumerator for the different roles
  112. */
  113. typedef enum _COMMASSOC_ASSOC_ROLE_E {
  114. COMMASSOC_ASSOC_E_INITIATOR = 0,
  115. COMMASSOC_ASSOC_E_RESPONDER
  116. } COMMASSOC_ASSOC_ROLE_E, *PCOMMASSOC_ASSOC_ROLE_E;
  117. /*
  118. COMMASSOC_DLG_ROLE_E -- Enumerator for the different roles
  119. */
  120. typedef enum _COMMASSOC_DLG_ROLE_E {
  121. COMMASSOC_DLG_E_IMPLICIT = 0,
  122. COMMASSOC_DLG_E_EXPLICIT
  123. } COMMASSOC_DLG_ROLE_E, *PCOMMASSOC_PDLG_ROLE_E;
  124. /*
  125. ASSOC_MSG_TYP_E - different assoc. messages
  126. */
  127. typedef enum _COMMASSOC_ASSOC_MSG_TYP_E{
  128. COMMASSOC_ASSOC_E_START_REQ = 0,
  129. COMMASSOC_ASSOC_E_STOP_REQ,
  130. COMMASSOC_ASSOC_E_START_RESP
  131. } COMMASSOC_MSG_TYP_E, *PCOMMASSOC_MSG_TYP_E;
  132. /*
  133. DLG_STATE_E - states of a dialogue
  134. */
  135. typedef enum _COMMASSOC_DLG_STATE_E {
  136. COMMASSOC_DLG_E_INACTIVE = 0,
  137. COMMASSOC_DLG_E_ACTIVE,
  138. COMMASSOC_DLG_E_DYING
  139. } COMMASSOC_DLG_STATE_E, *PCOMMASSOC_DLG_STATE_E;
  140. /*
  141. DLG_HDL_T - Dialogue Context Block
  142. The ctx block must have COMM_TOP_T structure at the top (used by DeallocEnt in
  143. assoc.c)
  144. */
  145. typedef struct _COMMASSOC_DLG_CTX_T {
  146. COMM_TOP_T Top;
  147. COMM_HDL_T AssocHdl; //ptr to the Assoc ctx block
  148. COMMASSOC_DLG_STATE_E State_e; // state of the dialogue
  149. COMM_TYP_E Typ_e; // type of the dialogue
  150. COMMASSOC_DLG_ROLE_E Role_e; //Role - IMPLICIT/EXPLICIT
  151. FUTURES("There is no need to store pMsg and MsgLen in dlg ctx block")
  152. FUTURES("since now I am storing FirstWrdOfMsg in it. Make sure that this")
  153. FUTURES("assertion is indeed true")
  154. MSG_T pMsg; //ptr to datagram received on
  155. //UDP port
  156. MSG_LEN_T MsgLen; //msg Length of datagram
  157. DWORD FirstWrdOfMsg; //first word of message received
  158. struct sockaddr_in FromAdd; //address of sender of datagram
  159. CHECK("Is this needed")
  160. DWORD QuesNameSecLen; //Length of question section
  161. //in name req
  162. DWORD RspLen; //length of the response packet
  163. SOCKET SockNo; //sock. # of connection
  164. //created when simulating an
  165. //nbt node (to send a name
  166. //reg request to a remote WINS)
  167. //see ClastAtReplUniqueR
  168. } COMMASSOC_DLG_CTX_T, *PCOMMASSOC_DLG_CTX_T;
  169. /*
  170. ASSOC_STATE_E -- Enumerator for the different states of an Association
  171. */
  172. typedef enum _COMMASSOC_ASSOC_STATE_E {
  173. COMMASSOC_ASSOC_E_NON_EXISTENT = 0,
  174. COMMASSOC_ASSOC_E_STARTING,
  175. COMMASSOC_ASSOC_E_ACTIVE,
  176. COMMASSOC_ASSOC_E_STOPPING,
  177. COMMASSOC_ASSOC_E_DISCONNECTED
  178. } COMMASSOC_ASSOC_STATE_E, *PCOMMASSOC_ASSOC_STATE_E;
  179. typedef COMMASSOC_DLG_CTX_T DLG_CTX_T;
  180. typedef COMM_HDL_T COMMASSOC_DLG_HDL_T;
  181. typedef COMM_HDL_T COMMASSOC_ASSOC_HDL_T;
  182. /*
  183. ASSOC_CTX - Association Context Block
  184. The ctx block must have COMM_TOP_T structure at the top (used by DeallocEnt in
  185. assoc.c)
  186. */
  187. typedef struct _COMMASSOC_ASSOC_CTX_T {
  188. COMM_TOP_T Top;
  189. COMM_HDL_T DlgHdl; //ptr to the Assoc ctx block
  190. SOCKET SockNo; /*handle to TCP/UDP socket*/
  191. ULONG uRemAssocCtx; /*remote assoc ctx block*/
  192. DWORD MajVersNo;
  193. DWORD MinVersNo;
  194. COMMASSOC_ASSOC_STATE_E State_e; /* state */
  195. COMM_TYP_E Typ_e; /* type */
  196. COMMASSOC_ASSOC_ROLE_E Role_e; /*Role -- Initiator/responder*/
  197. COMM_ADD_TYP_E AddTyp_e;
  198. union {
  199. struct sockaddr_in RemoteAdd; //Address of remote node
  200. struct sockaddr_in RemoteAddIpx; //Address of remote node
  201. };
  202. ULONG nTag; // 32bit tag to be used in replication protocol
  203. } COMMASSOC_ASSOC_CTX_T, *PCOMMASSOC_ASSOC_CTX_T;
  204. /*
  205. ASSOC_TAG - Mapping between (64bit) pointers and 32bit values.
  206. This has to be used in order to locate the local COMMASSOC_ASSOC_CTX_T structure from the
  207. 32bit value handed by the partner through the replication protocol.
  208. */
  209. #define COMMASSOC_TAG_CHUNK 64
  210. typedef struct _COMMASSOC_TAG_POOL_T {
  211. CRITICAL_SECTION crtSection; // mutual exclusion guard
  212. LPVOID *ppStorage; // array of (64bit) pointer values
  213. ULONG *pTagPool; // array of 32bit tags
  214. ULONG nIdxLimit; // number of entries available in both arrays above
  215. ULONG nMaxIdx; // maximum number of free tags
  216. } COMMASSOC_TAG_POOL_T, *PCOMMASSOC_TAG_POOL_T;
  217. extern COMMASSOC_TAG_POOL_T sTagAssoc; //32bit ULONG -> LPVOID mapping
  218. /*
  219. function prototypes
  220. */
  221. extern
  222. VOID
  223. CommAssocSetUpAssoc(
  224. PCOMM_HDL_T pDlgHdl,
  225. PCOMM_ADD_T pAdd,
  226. COMM_TYP_E CommTyp_e,
  227. PCOMMASSOC_ASSOC_CTX_T *ppAssocCtx
  228. );
  229. extern
  230. VOID
  231. CommAssocFrmStartAssocReq(
  232. PCOMMASSOC_ASSOC_CTX_T pAssocCtx,
  233. MSG_T pMsg,
  234. MSG_LEN_T MsgLen
  235. );
  236. extern
  237. VOID
  238. CommAssocUfmStartAssocReq(
  239. IN MSG_T pMsg,
  240. OUT PCOMM_TYP_E pAssocTyp_e,
  241. OUT LPDWORD pMajorVer,
  242. OUT LPDWORD pMinorVer,
  243. OUT ULONG *puRemAssocCtx
  244. );
  245. extern
  246. VOID
  247. CommAssocFrmStartAssocRsp(
  248. PCOMMASSOC_ASSOC_CTX_T pAssocCtx,
  249. MSG_T pMsg,
  250. MSG_LEN_T MsgLen
  251. );
  252. extern
  253. VOID
  254. CommAssocUfmStartAssocRsp(
  255. IN MSG_T pMsg,
  256. OUT LPDWORD pMajorVer,
  257. OUT LPDWORD pMinorVer,
  258. IN ULONG *puRemAssocCtx
  259. );
  260. extern
  261. VOID
  262. CommAssocFrmStopAssocReq(
  263. PCOMMASSOC_ASSOC_CTX_T pAssocCtx,
  264. MSG_T pMsg,
  265. MSG_LEN_T MsgLen,
  266. COMMASSOC_STP_RSN_E StopRsn_e
  267. );
  268. extern
  269. VOID
  270. CommAssocUfmStopAssocReq(
  271. MSG_T pMsg,
  272. PCOMMASSOC_STP_RSN_E pStopRsn_e
  273. );
  274. extern
  275. VOID
  276. CommAssocDeallocAssoc(
  277. LPVOID pAssocCtx
  278. );
  279. extern
  280. VOID
  281. CommAssocDeallocDlg(
  282. LPVOID pDlgCtx
  283. );
  284. extern
  285. LPVOID
  286. CommAssocAllocAssoc(
  287. VOID
  288. );
  289. extern
  290. LPVOID
  291. CommAssocAllocDlg(
  292. VOID
  293. );
  294. extern
  295. VOID
  296. CommAssocInit(
  297. VOID
  298. );
  299. extern
  300. PCOMMASSOC_DLG_CTX_T
  301. CommAssocInsertUdpDlgInTbl(
  302. IN PCOMMASSOC_DLG_CTX_T pCtx,
  303. OUT LPBOOL pfNewElem
  304. );
  305. extern
  306. VOID
  307. CommAssocDeleteUdpDlgInTbl(
  308. IN PCOMMASSOC_DLG_CTX_T pDlgCtx
  309. );
  310. extern
  311. LPVOID
  312. CommAssocCreateAssocInTbl(
  313. SOCKET SockNo
  314. );
  315. extern
  316. VOID
  317. CommAssocDeleteAssocInTbl(
  318. PCOMMASSOC_ASSOC_CTX_T pAssocCtx
  319. );
  320. extern
  321. LPVOID
  322. CommAssocLookupAssoc(
  323. SOCKET SockNo
  324. );
  325. extern
  326. VOID
  327. CommAssocInsertAssocInTbl(
  328. PCOMMASSOC_ASSOC_CTX_T pAssocCtx
  329. );
  330. extern
  331. ULONG
  332. CommAssocTagAlloc(
  333. PCOMMASSOC_TAG_POOL_T pTag,
  334. LPVOID pPtrValue
  335. );
  336. extern
  337. VOID
  338. CommAssocTagFree(
  339. PCOMMASSOC_TAG_POOL_T pTag,
  340. ULONG nTag
  341. );
  342. extern
  343. LPVOID
  344. CommAssocTagMap(
  345. PCOMMASSOC_TAG_POOL_T pTag,
  346. ULONG nTag
  347. );
  348. #ifdef __cplusplus
  349. }
  350. #endif
  351. #endif
  352.