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.

473 lines
12 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. aspc.h
  5. Abstract:
  6. This module contains definitions for the client side ASP code.
  7. Author:
  8. Jameel Hyder (jameelh@microsoft.com)
  9. Revision History:
  10. 19 Jun 1992 Initial Version
  11. Notes: Tab stop: 4
  12. --*/
  13. #ifndef _ASPC_
  14. #define _ASPC_
  15. #define ASPC_CONN_HASH_BUCKETS 13 // Hashed by NodeAddr
  16. #define HASH_ASPC_SRCADDR(pSrcAddr) \
  17. ((((pSrcAddr)->ata_Node >> 2) + \
  18. ((pSrcAddr)->ata_Network & 0xFF)) % ASPC_CONN_HASH_BUCKETS)
  19. // For resolving forward references
  20. struct _AspCAddress;
  21. struct _AspCConnxn;
  22. struct _AspCRequest;
  23. #define ASP_MIN_REQ_INTERVAL 5 // In 100ms units
  24. #define ASP_MAX_REQ_INTERVAL 20 // In 100ms units
  25. #define ASP_INIT_REQ_INTERVAL 5 // In 100ms units
  26. #define ASPCAO_CLOSING 0x8000
  27. #define ASPCAO_SIGNATURE *(PULONG)"ACAO"
  28. #define VALID_ASPCAO(pAspCAddr) (((pAspCAddr) != NULL) && \
  29. (((struct _AspCAddress *)(pAspCAddr))->aspcao_Signature == ASPCAO_SIGNATURE))
  30. // Also known as the listener.
  31. typedef struct _AspCAddress
  32. {
  33. ULONG aspcao_Signature;
  34. struct _AspCAddress * aspcao_Next; // Links to global list
  35. struct _AspCAddress ** aspcao_Prev;
  36. LONG aspcao_RefCount; // References to the address obj
  37. ULONG aspcao_Flags;
  38. PATP_ADDROBJ aspcao_pAtpAddr; // Atp Socket for this asp conn
  39. GENERIC_COMPLETION aspcao_CloseCompletion;
  40. PVOID aspcao_CloseContext;
  41. PTDI_IND_DISCONNECT aspcao_DisconnectHandler;
  42. PVOID aspcao_DisconnectHandlerCtx;
  43. PTDI_IND_RECEIVE_EXPEDITED aspcao_ExpRecvHandler; // Used to indicate attention
  44. PVOID aspcao_ExpRecvHandlerCtx;
  45. ATALK_SPIN_LOCK aspcao_Lock;
  46. } ASPC_ADDROBJ, *PASPC_ADDROBJ;
  47. #define ASPCCO_ASSOCIATED 0x0001
  48. #define ASPCCO_ACTIVE 0x0002
  49. #define ASPCCO_TICKLING 0x0004
  50. #define ASPCCO_CONNECTING 0x0008
  51. #define ASPCCO_CLEANING_UP 0x0010
  52. #define ASPCCO_LOCAL_CLOSE 0x0020
  53. #define ASPCCO_REMOTE_CLOSE 0x0040
  54. #define ASPCCO_DROPPED 0x0080
  55. #define ASPCCO_ATTN_PENDING 0x0100
  56. #define ASPCCO_DISCONNECTING 0x0200
  57. #define ASPCCO_CLOSING 0x8000
  58. #define ASPCCO_SIGNATURE *(PULONG)"ACCO"
  59. #define MAX_ASPC_ATTNS 8
  60. #define VALID_ASPCCO(pAspConn) (((pAspConn) != NULL) && \
  61. (((struct _AspCConnxn *)(pAspConn))->aspcco_Signature == ASPCCO_SIGNATURE))
  62. typedef struct _AspCConnxn
  63. {
  64. ULONG aspcco_Signature;
  65. struct _AspCConnxn * aspcco_Next; // Links to global list
  66. struct _AspCConnxn ** aspcco_Prev;
  67. LONG aspcco_RefCount; // References to the conn obj
  68. struct _AspCAddress * aspcco_pAspCAddr; // Back pointer to the address
  69. struct _AspCRequest * aspcco_pActiveReqs; // List of requests being processed
  70. PATP_ADDROBJ aspcco_pAtpAddr; // Atp Socket for this asp conn
  71. // Copy of aspcao_pAtpAddr for efficiency
  72. LONG aspcco_LastContactTime;
  73. ATALK_ADDR aspcco_ServerSlsAddr;//This is the server addr to which we send
  74. // the tickles/open/getstatus
  75. ATALK_ADDR aspcco_ServerSssAddr;//This is the server addr to which we send
  76. // the commands/writes
  77. BYTE aspcco_SessionId;
  78. BYTE aspcco_cReqsInProcess;// Count of requests in process
  79. USHORT aspcco_Flags; // aspcco_xxx values
  80. USHORT aspcco_NextSeqNum;
  81. USHORT aspcco_OpenSessTid;
  82. USHORT aspcco_TickleTid;
  83. union
  84. {
  85. USHORT aspcco_TickleXactId;// Transaction id for tickles
  86. USHORT aspcco_OpenSessId; // Transaction id for open-session request
  87. };
  88. // We keep a circular buffer for storing attentions. If full further attention
  89. // bytes overwrite it
  90. USHORT aspcco_AttnBuf[MAX_ASPC_ATTNS];
  91. USHORT aspcco_AttnInPtr;
  92. USHORT aspcco_AttnOutPtr;
  93. RT aspcco_RT; // Used for adaptive round-trip time calculation
  94. PVOID aspcco_ConnCtx;
  95. // Read (GetAttn) Completion routine
  96. GENERIC_READ_COMPLETION aspcco_ReadCompletion;
  97. PVOID aspcco_ReadCtx;
  98. // Connect inform routine
  99. GENERIC_COMPLETION aspcco_ConnectCompletion;
  100. PVOID aspcco_ConnectCtx;
  101. // Disconnect inform routine
  102. GENERIC_COMPLETION aspcco_DisconnectInform;
  103. PVOID aspcco_DisconnectInformCtx;
  104. // Disconnect request completion
  105. ATALK_ERROR aspcco_DisconnectStatus;
  106. GENERIC_COMPLETION aspcco_DisconnectCompletion;
  107. PVOID aspcco_DisconnectCtx;
  108. // Completion routine to be called when socket is cleaned-up
  109. GENERIC_COMPLETION aspcco_CleanupComp;
  110. PVOID aspcco_CleanupCtx;
  111. // Completion routine to be called when socket is closed
  112. GENERIC_COMPLETION aspcco_CloseComp;
  113. PVOID aspcco_CloseCtx;
  114. PATALK_DEV_CTX aspcco_pDevCtx;
  115. ATALK_SPIN_LOCK aspcco_Lock;
  116. } ASPC_CONNOBJ, *PASPC_CONNOBJ;
  117. #define ASPCRQ_COMMAND 0x0001 // Asp Command
  118. #define ASPCRQ_WRITE 0x0002 // Asp Write
  119. #define ASPCRQ_WRTCONT 0x0004 // Write continue recvd. and replied
  120. // The request gets created when a Command or Write is posted
  121. #define ASPCRQ_SIGNATURE *(PULONG)"ACRQ"
  122. #if DBG
  123. #define VALID_ASPCRQ(pAspCReq) (((pAspCReq) != NULL) && \
  124. ((pAspCReq)->aspcrq_Signature == ASPRQ_SIGNATURE))
  125. #else
  126. #define VALID_ASPCRQ(pAspCReq) ((pAspCReq) != NULL)
  127. #endif
  128. typedef struct _AspCRequest
  129. {
  130. #if DBG
  131. ULONG aspcrq_Signature;
  132. #endif
  133. struct _AspCRequest * aspcrq_Next; // Link to next request
  134. LONG aspcrq_RefCount;// Reference Count
  135. struct _AspCConnxn * aspcrq_pAspConn;// Owning connection
  136. PATP_RESP aspcrq_pAtpResp;// Used to reply to a wrtcont request
  137. PACTREQ aspcrq_pActReq; // Request completion
  138. union
  139. {
  140. PAMDL aspcrq_pReplyMdl;
  141. PAMDL aspcrq_pWriteMdl;
  142. };
  143. USHORT aspcrq_SeqNum;
  144. USHORT aspcrq_ReqXactId;// Transaction Id of the request/command
  145. USHORT aspcrq_Flags; // Various ASPRQ_xxx values
  146. union
  147. {
  148. USHORT aspcrq_ReplySize;
  149. USHORT aspcrq_WriteSize;
  150. };
  151. ATALK_SPIN_LOCK aspcrq_Lock; // Spin-lock
  152. } ASPC_REQUEST, *PASPC_REQUEST;
  153. // MACROS
  154. #define AtalkAspCGetDdpAddress(pAspAddr) \
  155. AtalkAtpGetDdpAddress((pAspAddr)->aspcao_pAtpAddr)
  156. extern
  157. VOID
  158. AtalkInitAspCInitialize(
  159. VOID
  160. );
  161. extern
  162. ATALK_ERROR
  163. AtalkAspCCreateAddress(
  164. IN PATALK_DEV_CTX pDevCtx OPTIONAL,
  165. OUT PASPC_ADDROBJ * ppAspAddr
  166. );
  167. extern
  168. ATALK_ERROR
  169. AtalkAspCCleanupAddress(
  170. IN PASPC_ADDROBJ pAspAddr
  171. );
  172. extern
  173. ATALK_ERROR
  174. AtalkAspCCloseAddress(
  175. IN PASPC_ADDROBJ pAspAddr,
  176. IN GENERIC_COMPLETION CompletionRoutine,
  177. IN PVOID CloseContext
  178. );
  179. extern
  180. ATALK_ERROR
  181. AtalkAspCCreateConnection(
  182. IN PVOID ConnCtx,
  183. IN PATALK_DEV_CTX pDevCtx OPTIONAL,
  184. OUT PASPC_CONNOBJ * ppAspConn
  185. );
  186. extern
  187. ATALK_ERROR
  188. AtalkAspCCleanupConnection(
  189. IN PASPC_CONNOBJ pAspConn
  190. );
  191. extern
  192. ATALK_ERROR
  193. AtalkAspCCloseConnection(
  194. IN PASPC_CONNOBJ pAspConn,
  195. IN GENERIC_COMPLETION CompletionRoutine,
  196. IN PVOID CloseContext
  197. );
  198. // MACROS
  199. #define AtalkAspCAddrReferenceNonInterlock(_pAspAddr, _pError) \
  200. { \
  201. if (((_pAspAddr)->aspcao_Flags & ASPCAO_CLOSING) == 0) \
  202. { \
  203. ASSERT((_pAspAddr)->aspcao_RefCount >= 1); \
  204. (_pAspAddr)->aspcao_RefCount++; \
  205. *(_pError) = ATALK_NO_ERROR; \
  206. } \
  207. else \
  208. { \
  209. *(_pError) = ATALK_ASPC_ADDR_CLOSING; \
  210. } \
  211. if (ATALK_SUCCESS(*(_pError))) \
  212. { \
  213. DBGPRINT(DBG_COMP_ASP, DBG_LEVEL_REFASPADDR, \
  214. ("RefAddr %lx at %s(%d) = %d\n", \
  215. _pAspAddr, __FILE__, __LINE__, \
  216. ((_pAspAddr)->aspcao_RefCount))); \
  217. } \
  218. }
  219. #define AtalkAspCAddrReference(_pAspAddr, _pError) \
  220. { \
  221. KIRQL OldIrql; \
  222. \
  223. ACQUIRE_SPIN_LOCK(&(_pAspAddr)->aspcao_Lock, &OldIrql); \
  224. AtalkAspCAddrReferenceNonInterlock(_pAspAddr, _pError); \
  225. RELEASE_SPIN_LOCK(&(_pAspAddr)->aspcao_Lock, OldIrql); \
  226. }
  227. #define AtalkAspCConnReferenceByPtrNonInterlock(_pAspConn, _pError) \
  228. { \
  229. if (((_pAspConn)->aspcco_Flags & ASPCCO_CLOSING) == 0) \
  230. { \
  231. ASSERT((_pAspConn)->aspcco_RefCount >= 1); \
  232. (_pAspConn)->aspcco_RefCount++; \
  233. *(_pError) = ATALK_NO_ERROR; \
  234. } \
  235. else \
  236. { \
  237. *(_pError) = ATALK_ASPC_ADDR_CLOSING; \
  238. } \
  239. }
  240. #define AtalkAspCConnReference(_pAspConn, _pError) \
  241. { \
  242. KIRQL OldIrql; \
  243. \
  244. ACQUIRE_SPIN_LOCK(&(_pAspConn)->aspcco_Lock, &OldIrql); \
  245. AtalkAspCConnReferenceByPtrNonInterlock(_pAspConn, _pError);\
  246. RELEASE_SPIN_LOCK(&(_pAspConn)->aspcco_Lock, OldIrql); \
  247. }
  248. extern
  249. VOID FASTCALL
  250. AtalkAspCAddrDereference(
  251. IN PASPC_ADDROBJ pAspAddr
  252. );
  253. extern
  254. VOID FASTCALL
  255. AtalkAspCConnDereference(
  256. IN PASPC_CONNOBJ pAspConn
  257. );
  258. extern
  259. ATALK_ERROR
  260. AtalkAspCAssociateAddress(
  261. IN PASPC_ADDROBJ pAspAddr,
  262. IN PASPC_CONNOBJ pAspConn
  263. );
  264. extern
  265. ATALK_ERROR
  266. AtalkAspCDissociateAddress(
  267. IN PASPC_CONNOBJ pAspConn
  268. );
  269. extern
  270. ATALK_ERROR
  271. AtalkAspCPostConnect(
  272. IN PASPC_CONNOBJ pAspConn,
  273. IN PATALK_ADDR pRemoteAddr,
  274. IN PVOID pConnectCtx,
  275. IN GENERIC_COMPLETION CompletionRoutine
  276. );
  277. extern
  278. ATALK_ERROR
  279. AtalkAspCDisconnect(
  280. IN PASPC_CONNOBJ pAspConn,
  281. IN ATALK_DISCONNECT_TYPE DisconnectType,
  282. IN PVOID pDisconnectCtx,
  283. IN GENERIC_COMPLETION CompletionRoutine
  284. );
  285. extern
  286. ATALK_ERROR
  287. AtalkAspCGetStatus(
  288. IN PASPC_ADDROBJ pAspAddr,
  289. IN PATALK_ADDR pRemoteAddr,
  290. IN PAMDL pStatusAmdl,
  291. IN USHORT AmdlSize,
  292. IN PACTREQ pActReq
  293. );
  294. extern
  295. ATALK_ERROR
  296. AtalkAspCGetAttn(
  297. IN PASPC_CONNOBJ pAspConn,
  298. IN PAMDL pReadBuf,
  299. IN USHORT ReadBufLen,
  300. IN ULONG ReadFlags,
  301. IN PVOID pReadCtx,
  302. IN GENERIC_READ_COMPLETION CompletionRoutine
  303. );
  304. extern
  305. ATALK_ERROR
  306. AtalkAspCCmdOrWrite(
  307. IN PASPC_CONNOBJ pAspConn,
  308. IN PAMDL pCmdMdl,
  309. IN USHORT CmdSize,
  310. IN PAMDL pReplyMdl,
  311. IN USHORT ReplySize,
  312. IN BOOLEAN fWrite, // If TRUE, its a write else command
  313. IN PACTREQ pActReq
  314. );
  315. BOOLEAN
  316. AtalkAspCConnectionIsValid(
  317. IN PASPC_CONNOBJ pAspConn
  318. );
  319. // This is a list of all active connections. This is scanned by the session
  320. // maintenance timer.
  321. typedef struct
  322. {
  323. PASP_CONNOBJ ascm_ConnList;
  324. TIMERLIST ascm_SMTTimer;
  325. } ASPC_CONN_MAINT, *PASPC_CONN_MAINT;
  326. extern ASPC_CONN_MAINT atalkAspCConnMaint;
  327. extern ATALK_SPIN_LOCK atalkAspCLock;
  328. extern PASPC_ADDROBJ atalkAspCAddrList;
  329. extern PASPC_CONNOBJ atalkAspCConnList;
  330. LOCAL VOID
  331. atalkAspCCloseSession(
  332. IN PASPC_CONNOBJ pAspConn
  333. );
  334. LOCAL VOID
  335. atalkAspCHandler(
  336. IN ATALK_ERROR ErrorCode,
  337. IN PASPC_CONNOBJ pAspConn, // Listener (our context)
  338. IN PATP_RESP RespCtxt, // Used by PostResp/CancelResp
  339. IN PATALK_ADDR pSrcAddr, // Address of requestor
  340. IN USHORT PktLen,
  341. IN PBYTE pPkt,
  342. IN PBYTE pUserBytes
  343. );
  344. LOCAL VOID
  345. atalkAspCIncomingOpenReply(
  346. IN ATALK_ERROR ErrorCode,
  347. IN PASPC_CONNOBJ pAspConn, // Our context
  348. IN PAMDL pReqAmdl,
  349. IN PAMDL pReadAmdl,
  350. IN USHORT ReadLen,
  351. IN PBYTE ReadUserBytes
  352. );
  353. LOCAL VOID
  354. atalkAspCIncomingStatus(
  355. IN ATALK_ERROR ErrorCode,
  356. IN PACTREQ pActReq, // Our Ctx
  357. IN PAMDL pReqAmdl,
  358. IN PAMDL pStatusAmdl,
  359. IN USHORT StatusLen,
  360. IN PBYTE ReadUserBytes
  361. );
  362. LOCAL VOID
  363. atalkAspCIncomingCmdReply(
  364. IN ATALK_ERROR Error,
  365. IN PASPC_REQUEST pAspReq,
  366. IN PAMDL pReqAMdl,
  367. IN PAMDL pRespAMdl,
  368. IN USHORT RespSize,
  369. IN PBYTE RespUserBytes
  370. );
  371. LOCAL LONG FASTCALL
  372. atalkAspCSessionMaintenanceTimer(
  373. IN PTIMERLIST pTimer,
  374. IN BOOLEAN TimerShuttingDown
  375. );
  376. LOCAL VOID FASTCALL
  377. atalkAspCGenericRespComplete(
  378. IN ATALK_ERROR ErrorCode,
  379. IN PATP_RESP pAtpResp
  380. );
  381. LOCAL VOID
  382. atalkAspCQueueAddrGlobalList(
  383. IN PASPC_ADDROBJ pAspCAddr
  384. );
  385. LOCAL VOID
  386. atalkAspCDeQueueAddrGlobalList(
  387. IN PASPC_ADDROBJ pAspCAddr
  388. );
  389. LOCAL VOID
  390. atalkAspCQueueConnGlobalList(
  391. IN PASPC_CONNOBJ pAspConn
  392. );
  393. LOCAL VOID
  394. atalkAspCDeQueueConnGlobalList(
  395. IN PASPC_CONNOBJ pAspCConn
  396. );
  397. #endif // _ASPC_
  398.