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.

427 lines
11 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. asp.h
  5. Abstract:
  6. This module contains definitions for the server side ASP code.
  7. Author:
  8. Jameel Hyder (jameelh@microsoft.com)
  9. Nikhil Kamkolkar (nikhilk@microsoft.com)
  10. Revision History:
  11. 19 Jun 1992 Initial Version
  12. Notes: Tab stop: 4
  13. --*/
  14. #ifndef _ASP_
  15. #define _ASP_
  16. // This defines only the server side ASP protocol solely for the consumption of the
  17. // AFP Server. Hence any functionality not needed by the AFP Server is missing here
  18. // ASP command type bytes:
  19. #define ASP_CLOSE_SESSION 1
  20. #define ASP_CMD 2
  21. #define ASP_GET_STATUS 3
  22. #define ASP_OPEN_SESSION 4
  23. #define ASP_TICKLE 5
  24. #define ASP_WRITE 6
  25. #define ASP_WRITE_DATA 7
  26. #define ASP_ATTENTION 8
  27. // ASP version:
  28. #define ASP_VERSION "\001\000"
  29. // Asp error codes that are visible on the wire
  30. #define ASP_BAD_VERSION (USHORT)-1066
  31. #define ASP_BUFFER_TOO_SMALL (USHORT)-1067
  32. #define ASP_NO_MORE_SESSIONS (USHORT)-1068
  33. #define ASP_NO_SERVERS (USHORT)-1069
  34. #define ASP_PARAM_ERROR (USHORT)-1070
  35. #define ASP_SERVER_BUSY (USHORT)-1071
  36. #define ASP_SIZE_ERROR (USHORT)-1073
  37. #define ASP_TOO_MANY_CLIENTS (USHORT)-1074
  38. #define ASP_NO_ACK (USHORT)-1075
  39. // Offsets into the ATP user bytes for finding various fields:
  40. #define ASP_CMD_OFF 0
  41. #define ASP_CMD_RESULT_OFF 0
  42. #define ASP_SSS_OFF 0
  43. #define ASP_SESSIONID_OFF 1
  44. #define ASP_WSS_OFF 1
  45. #define ASP_VERSION_OFF 2
  46. #define ASP_ERRORCODE_OFF 2
  47. #define ASP_ATTN_WORD_OFF 2
  48. #define ASP_SEQUENCE_NUM_OFF 2
  49. #define ASP_CMD_RESULT_SIZE 4
  50. // ASP timer values:
  51. #define ATP_MAX_INTERVAL_FOR_ASP 20 // In 100ms units
  52. #define ATP_MIN_INTERVAL_FOR_ASP 3 // In 100ms units
  53. #define ATP_INITIAL_INTERVAL_FOR_ASP 3
  54. #define ASP_TICKLE_INTERVAL 300 // In 100ms units
  55. #define ASP_MAX_SESSION_IDLE_TIME 1200 // In 100ms units. How long before we kill it
  56. #define ASP_SESSION_MAINTENANCE_TIMER 1200 // In 100ms units. How often the timer runs
  57. #define ASP_SESSION_TIMER_STAGGER 50 // In 100ms units. How are different queues staggered
  58. #define ATP_RETRIES_FOR_ASP 10 // For open, status, close;
  59. // infinite for others.
  60. #define ASP_WRITE_DATA_SIZE 2 // WriteData command has two
  61. // bytes of data with it.
  62. // Session status size:
  63. #define ASP_MAX_STATUS_SIZE ATP_MAX_TOTAL_RESPONSE_SIZE
  64. #define MAX_WRITE_REQ_SIZE 20
  65. #define ASP_CONN_HASH_BUCKETS 37 // Hashed by NodeAddr
  66. #define HASH_SRCADDR(pSrcAddr) \
  67. ((((pSrcAddr)->ata_Node >> 2) + \
  68. ((pSrcAddr)->ata_Network & 0xFF)) % ASP_CONN_HASH_BUCKETS)
  69. // For resolving forward references
  70. struct _AspAddress;
  71. struct _AspConnxn;
  72. struct _AspRequest;
  73. #define ASPAO_CLOSING 0x8000
  74. #define ASPAO_SIGNATURE *(PULONG)"ASAO"
  75. #if DBG
  76. #define VALID_ASPAO(pAspAddr) (((pAspAddr) != NULL) && \
  77. ((pAspAddr)->aspao_Signature == ASPAO_SIGNATURE))
  78. #else
  79. #define VALID_ASPAO(pAspAddr) ((pAspAddr) != NULL)
  80. #endif
  81. typedef struct _AspAddress
  82. {
  83. #if DBG
  84. ULONG aspao_Signature;
  85. #endif
  86. LONG aspao_RefCount; // References to the address obj
  87. ULONG aspao_Flags;
  88. PATP_ADDROBJ aspao_pSlsAtpAddr; // Sls Atp Socket
  89. PATP_ADDROBJ aspao_pSssAtpAddr; // Sss Atp Socket
  90. struct _AspConnxn * aspao_pSessions[ASP_CONN_HASH_BUCKETS];
  91. // List of open sessions
  92. PBYTE aspao_pStatusBuf; // Status buffer
  93. USHORT aspao_StsBufSize; // Size of the status buffer
  94. BYTE aspao_NextSessionId;// Id of the next session that comes in
  95. BOOLEAN aspao_EnableNewConnections;
  96. GENERIC_COMPLETION aspao_CloseCompletion;
  97. PVOID aspao_CloseContext;
  98. ASP_CLIENT_ENTRIES aspao_ClientEntries;// Entry points from the client
  99. ATALK_SPIN_LOCK aspao_Lock;
  100. } ASP_ADDROBJ, *PASP_ADDROBJ;
  101. #define ASPCO_ACTIVE 0x0001
  102. #define ASPCO_TICKLING 0x0002
  103. #define ASPCO_CLEANING_UP 0x0010
  104. #define ASPCO_LOCAL_CLOSE 0x0020
  105. #define ASPCO_REMOTE_CLOSE 0x0040
  106. #define ASPCO_DROPPED 0x0080
  107. #define ASPCO_SHUTDOWN 0x0100
  108. #define ASPCO_CLOSING 0x8000
  109. #define ASPCO_SIGNATURE *(PULONG)"ASCO"
  110. #if DBG
  111. #define VALID_ASPCO(pAspConn) (((pAspConn) != NULL) && \
  112. ((pAspConn)->aspco_Signature == ASPCO_SIGNATURE))
  113. #else
  114. #define VALID_ASPCO(pAspConn) ((pAspConn) != NULL)
  115. #endif
  116. typedef struct _AspConnxn
  117. {
  118. #if DBG
  119. ULONG aspco_Signature;
  120. #endif
  121. struct _AspConnxn * aspco_NextOverflow; // Overflow link for hash bucket
  122. // These is non NULL only when on
  123. // active list
  124. struct _AspConnxn * aspco_NextSession; // Linked to active session list
  125. struct _AspConnxn ** aspco_PrevSession; // Linked to active session list
  126. LONG aspco_RefCount; // References to the conn obj
  127. struct _AspAddress * aspco_pAspAddr; // Back pointer to the listener
  128. struct _AspRequest * aspco_pActiveReqs; // List of requests being processed
  129. struct _AspRequest * aspco_pFreeReqs; // Free requests
  130. PVOID aspco_ConnContext; // User context associated with this conn.
  131. LONG aspco_LastContactTime;
  132. ATALK_ADDR aspco_WssRemoteAddr;// This is the remote addr which
  133. // issues the commands/writes
  134. BYTE aspco_SessionId;
  135. BYTE aspco_cReqsInProcess;// Count of requests in process
  136. USHORT aspco_Flags; // ASPCO_xxx values
  137. USHORT aspco_NextExpectedSeqNum;
  138. USHORT aspco_TickleXactId; // Transaction id for tickles
  139. RT aspco_RT; // Used for adaptive round-trip time calculation
  140. PVOID aspco_CloseContext;
  141. CLIENT_CLOSE_COMPLETION aspco_CloseCompletion;
  142. PVOID aspco_AttentionContext;
  143. ATALK_SPIN_LOCK aspco_Lock;
  144. } ASP_CONNOBJ, *PASP_CONNOBJ;
  145. #define ASPRQ_WRTCONT 0x01 // Set if we are doing a write continue
  146. #define ASPRQ_WRTCONT_CANCELLED 0x10 // Set if a write continue was cancelled
  147. #define ASPRQ_REPLY 0x02 // Set if a reply is being processed
  148. #define ASPRQ_REPLY_CANCELLED 0x20 // Set if a reply is cancelled
  149. #define ASPRQ_REPLY_ABORTED 0x40 // Reply aborted due to a closing session
  150. // The request gets created when an incoming request arrives.
  151. #define ASPRQ_SIGNATURE *(PULONG)"ASRQ"
  152. #if DBG
  153. #define VALID_ASPRQ(pAspReq) (((pAspReq) != NULL) && \
  154. ((pAspReq)->asprq_Signature == ASPRQ_SIGNATURE))
  155. #else
  156. #define VALID_ASPRQ(pAspReq) ((pAspReq) != NULL)
  157. #endif
  158. typedef struct _AspRequest
  159. {
  160. #if DBG
  161. ULONG asprq_Signature;
  162. #endif
  163. struct _AspRequest * asprq_Next; // Link to next request
  164. struct _AspConnxn * asprq_pAspConn; // Owning connection
  165. USHORT asprq_SeqNum; // As generated by the wksta end
  166. USHORT asprq_WCXactId; // Transaction Id of the write
  167. // continue in progress
  168. PATP_RESP asprq_pAtpResp; // Used by PostResp/Cancel
  169. BYTE asprq_ReqType; // Cmd/WrtCont
  170. BYTE asprq_Flags; // Various ASPRQ_xxx values
  171. ATALK_ADDR asprq_RemoteAddr;// This address is used for
  172. // future communications but only
  173. // for this request
  174. REQUEST asprq_Request; // Request parameters
  175. UCHAR asprq_ReqBuf[MAX_WRITE_REQ_SIZE];
  176. // The request is copied here during a
  177. // write request
  178. BYTE asprq_WrtContRespBuf[ASP_WRITE_DATA_SIZE];
  179. } ASP_REQUEST, *PASP_REQUEST;
  180. // MACROS
  181. #define AtalkAspGetDdpAddress(pAspAddr) \
  182. AtalkAtpGetDdpAddress((pAspAddr)->aspao_pSlsAtpAddr)
  183. extern
  184. VOID
  185. AtalkInitAspInitialize(
  186. VOID
  187. );
  188. extern
  189. ATALK_ERROR
  190. AtalkAspCreateAddress(
  191. OUT PASP_ADDROBJ * ppAspAddr
  192. );
  193. extern
  194. ATALK_ERROR
  195. AtalkAspCloseAddress(
  196. IN PASP_ADDROBJ pAspAddr,
  197. IN GENERIC_COMPLETION CompletionRoutine,
  198. IN PVOID CloseContext
  199. );
  200. extern
  201. ATALK_ERROR
  202. AtalkAspBind(
  203. IN PASP_ADDROBJ pAspAddr,
  204. IN PASP_BIND_PARAMS pBindParms,
  205. IN PACTREQ pActReq
  206. );
  207. NTSTATUS FASTCALL
  208. AtalkAspWriteContinue(
  209. IN PREQUEST pRequest
  210. );
  211. ATALK_ERROR FASTCALL
  212. AtalkAspReply(
  213. IN PREQUEST pRequest,
  214. IN PBYTE pResultCode // Pointer to the 4-byte result
  215. );
  216. extern
  217. NTSTATUS
  218. AtalkAspSetStatus(
  219. IN PASP_ADDROBJ pAspAddr,
  220. IN PUCHAR pStatusBuf,
  221. IN USHORT StsBufSize
  222. );
  223. extern
  224. NTSTATUS FASTCALL
  225. AtalkAspListenControl(
  226. IN PASP_ADDROBJ pAspAddr,
  227. IN BOOLEAN Enable
  228. );
  229. extern
  230. PASP_ADDROBJ FASTCALL
  231. AtalkAspReferenceAddr(
  232. IN PASP_ADDROBJ pAspAddr
  233. );
  234. extern
  235. VOID FASTCALL
  236. AtalkAspDereferenceAddr(
  237. IN PASP_ADDROBJ pAspAddr
  238. );
  239. extern
  240. ATALK_ERROR
  241. AtalkAspCleanupConnection(
  242. IN PASP_CONNOBJ pAspConn
  243. );
  244. extern
  245. ATALK_ERROR
  246. AtalkAspCloseConnection(
  247. IN PASP_CONNOBJ pAspConn
  248. );
  249. extern
  250. ATALK_ERROR
  251. AtalkAspFreeConnection(
  252. IN PASP_CONNOBJ pAspConn
  253. );
  254. extern
  255. NTSTATUS
  256. AtalkAspSendAttention(
  257. IN PASP_CONNOBJ pAspConn,
  258. IN USHORT AttentionWord,
  259. IN PVOID pContext
  260. );
  261. extern
  262. VOID FASTCALL
  263. AtalkAspDereferenceConn(
  264. IN PASP_CONNOBJ pAspConn
  265. );
  266. // This is a list of all active connections. This is scanned by the session
  267. // maintenance timer.
  268. #define NUM_ASP_CONN_LISTS 4
  269. typedef struct
  270. {
  271. PASP_CONNOBJ ascm_ConnList;
  272. TIMERLIST ascm_SMTTimer;
  273. } ASP_CONN_MAINT, *PASP_CONN_MAINT;
  274. extern ASP_CONN_MAINT atalkAspConnMaint[NUM_ASP_CONN_LISTS];
  275. extern ATALK_SPIN_LOCK atalkAspLock;
  276. typedef struct
  277. {
  278. PATP_RESP aps_pAtpResp;
  279. PAMDL aps_pAMdl;
  280. } ASP_POSTSTAT_CTX, *PASP_POSTSTAT_CTX;
  281. LOCAL ATALK_ERROR FASTCALL
  282. atalkAspPostWriteContinue(
  283. IN PASP_REQUEST pAspReq
  284. );
  285. LOCAL PASP_CONNOBJ
  286. atalkAspReferenceConnBySrcAddr(
  287. IN PASP_ADDROBJ pAspAddr,
  288. IN PATALK_ADDR pSrcAddr,
  289. IN BYTE SessionId
  290. );
  291. LOCAL VOID
  292. atalkAspSlsXHandler(
  293. IN ATALK_ERROR ErrorCode,
  294. IN PASP_ADDROBJ pAspAddr, // Listener (our context)
  295. IN PATP_RESP RespCtxt, // Used by PostResp/CancelResp
  296. IN PATALK_ADDR pSrcAddr, // Address of requestor
  297. IN USHORT PktLen,
  298. IN PBYTE pPkt,
  299. IN PBYTE pUserBytes
  300. );
  301. LOCAL VOID
  302. atalkAspSssXHandler(
  303. IN ATALK_ERROR ErrorCode,
  304. IN PASP_ADDROBJ pAspAddr, // Listener (our context)
  305. IN PATP_RESP RespCtxt, // Used by PostResp/CancelResp
  306. IN PATALK_ADDR pSrcAddr, // Address of requestor
  307. IN USHORT PktLen,
  308. IN PBYTE pPkt,
  309. IN PBYTE pUserBytes
  310. );
  311. LOCAL VOID FASTCALL
  312. atalkAspReplyRelease(
  313. IN ATALK_ERROR Error,
  314. IN PASP_REQUEST pAspReq
  315. );
  316. LOCAL VOID
  317. atalkAspWriteContinueResp(
  318. IN ATALK_ERROR Error,
  319. IN PASP_REQUEST pAspReq,
  320. IN PAMDL pReqAMdl,
  321. IN PAMDL pRespAMdl,
  322. IN USHORT RespSize,
  323. IN PBYTE RespUserBytes
  324. );
  325. LOCAL VOID
  326. atalkAspSendAttentionResp(
  327. IN ATALK_ERROR Error,
  328. IN PVOID pContext,
  329. IN PAMDL pReqAMdl,
  330. IN PAMDL pRespAMdl,
  331. IN USHORT RespSize,
  332. IN PBYTE RespUserBytes
  333. );
  334. LOCAL VOID
  335. atalkAspSessionClose(
  336. IN PASP_CONNOBJ pAspConn
  337. );
  338. LOCAL LONG FASTCALL
  339. atalkAspSessionMaintenanceTimer(
  340. IN PTIMERLIST pTimer,
  341. IN BOOLEAN TimerShuttingDown
  342. );
  343. LOCAL VOID FASTCALL
  344. atalkAspRespComplete(
  345. IN ATALK_ERROR Error,
  346. IN PASP_POSTSTAT_CTX pStsCtx
  347. );
  348. LOCAL VOID
  349. atalkAspCloseComplete(
  350. IN ATALK_ERROR Status,
  351. IN PASP_ADDROBJ pAspAddr
  352. );
  353. LOCAL VOID
  354. atalkAspReturnResp(
  355. IN PATP_RESP pAtpResp,
  356. IN PATALK_ADDR pDstAddr,
  357. IN BYTE Byte0,
  358. IN BYTE Byte1,
  359. IN USHORT Word2
  360. );
  361. #endif // _ASP_
  362.