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.

1052 lines
27 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. adsp.h
  5. Abstract:
  6. This module contains definitions for the ADSP code.
  7. Author:
  8. Jameel Hyder (jameelh@microsoft.com)
  9. Nikhil Kamkolkar (nikhilk@microsoft.com)
  10. Revision History:
  11. 20 May 1993 Initial Version
  12. Notes: Tab stop: 4
  13. --*/
  14. #ifndef _ADSP_
  15. #define _ADSP_
  16. // ADSP_ version.
  17. #define ADSP_VERSION 0x0100
  18. // ADSP_ field offsets within a Ddp datagram.
  19. #define ADSP_SRC_CONNID_OFF 0
  20. #define ADSP_FIRST_BYTE_SEQNUM_OFF 2
  21. #define ADSP_THIS_ATTEN_SEQNUM_OFF 2
  22. #define ADSP_NEXT_RX_BYTESEQNUM_OFF 6
  23. #define ADSP_NEXT_RX_ATTNSEQNUM_OFF 6
  24. #define ADSP_RX_WINDOW_SIZE_OFF 10
  25. #define ADSP_RX_ATTEN_SIZE_OFF 10
  26. #define ADSP_DESCRIPTOR_OFF 12
  27. #define ADSP_DATA_OFF 13
  28. #define ADSP_VERSION_STAMP_OFF 13
  29. #define ADSP_ATTEN_CODE_OFF 13
  30. #define ADSP_ATTEN_DATA_OFF 15
  31. #define ADSP_DEST_CONNID_OFF 15
  32. #define ADSP_NEXT_ATTEN_SEQNUM_OFF 17
  33. // Bit fields in the ADSP_ descriptor
  34. #define ADSP_CONTROL_FLAG 0x80
  35. #define ADSP_ACK_REQ_FLAG 0x40
  36. #define ADSP_EOM_FLAG 0x20
  37. #define ADSP_ATTEN_FLAG 0x10
  38. // Control codes in the ADSP_ descriptor:
  39. #define ADSP_CONTROL_MASK 0x0F
  40. #define ADSP_PROBE_OR_ACK_CODE 0
  41. #define ADSP_OPENCONN_REQ_CODE 1
  42. #define ADSP_OPENCONN_ACK_CODE 2
  43. #define ADSP_OPENCONN_REQANDACK_CODE 3
  44. #define ADSP_OPENCONN_DENY_CODE 4
  45. #define ADSP_CLOSE_CONN_CODE 5
  46. #define ADSP_FORWARD_RESET_CODE 6
  47. #define ADSP_FORWARD_RESETACK_CODE 7
  48. #define ADSP_RETRANSMIT_CODE 8
  49. // Data sizes:
  50. #define ADSP_MAX_DATA_SIZE 572
  51. #define ADSP_MAX_ATTEN_DATA_SIZE 570
  52. #define ADSP_MAX_ATTEN_PKT_SIZE 572
  53. #define ADSP_MIN_ATTEN_PKT_SIZE sizeof(USHORT)
  54. // Largest allowed send/receive window size.
  55. #define ADSP_MAX_SEND_RX_WINDOW_SIZE 0xFFFF
  56. #define ADSP_DEF_SEND_RX_WINDOW_SIZE ((1024*8)+1) // 8K + 1 (EOM)
  57. // Attention code info:
  58. #define ADSP_MIN_ATTENCODE 0x0000
  59. #define ADSP_MAX_ATTENCODE 0xEFFF
  60. // How long do we try Open's for?
  61. #define ADSP_MAX_OPEN_ATTEMPTS 10
  62. #define ADSP_OPEN_INTERVAL 20 // In 100ms units
  63. // Connection maintenance timer values:
  64. #define ADSP_PROBE_INTERVAL 30
  65. #define ADSP_CONNECTION_INTERVAL 1200 // In 100ms units
  66. // Retransmit timer values:
  67. #define ADSP_RETRANSMIT_INTERVAL 20 // In 100ms units
  68. // How often do we retransmit attentions?
  69. #define ADSP_ATTENTION_INTERVAL 20 // In 100ms units
  70. #define ADSP_DISCONNECT_DELAY 7 // In 100ms units
  71. // How often do we retransmit forward resets?
  72. #define ADSP_FORWARD_RESET_INTERVAL 20 // In 100ms units
  73. // How many out of sequence packets do we allow before requesting a retransmition.
  74. #define ADSP_OUT_OF_SEQ_PACKETS_MAX 3
  75. // For resolving forward references
  76. struct _ADSP_CONNOBJ;
  77. struct _ADSP_ADDROBJ;
  78. typedef enum
  79. {
  80. ADSP_SEND_QUEUE,
  81. ADSP_RECV_QUEUE
  82. } ADSP_QUEUE_TYPE;
  83. #define BC_EOM (USHORT)0x0001
  84. #define BC_SEND (USHORT)0x0002
  85. #define BC_DISCONNECT (USHORT)0x4000
  86. #define BC_CLOSING (USHORT)0x8000
  87. // We use buffer chunks for the send receive queues
  88. typedef struct _BUFFER_CHUNK
  89. {
  90. struct _BUFFER_CHUNK * bc_Next;
  91. ATALK_SPIN_LOCK bc_Lock;
  92. ULONG bc_RefCount;
  93. // Size of data copied over from the users mdl. This
  94. // could be less than the size of the users data.
  95. USHORT bc_DataSize;
  96. USHORT bc_Flags;
  97. // Write completion information. This is only valid if
  98. // the BC_SEND bit is set. With a week left to ship, i'm
  99. // wimping out and making a copy to keep things as consistent
  100. // and stable as possible. Eventually though, we should just
  101. // use the User's buffer to make mdl's out of.
  102. PAMDL bc_WriteBuf;
  103. GENERIC_WRITE_COMPLETION bc_WriteCompletion;
  104. PVOID bc_WriteCtx;
  105. ATALK_ERROR bc_WriteError;
  106. // Backpointer to the connection object on which this is queued
  107. struct _ADSP_CONNOBJ * bc_ConnObj;
  108. //
  109. // BYTE bc_Data[]
  110. //
  111. } BUFFER_CHUNK, *PBUFFER_CHUNK;
  112. // Buffer queues used for send/receive
  113. typedef struct _BUFFER_QUEUE
  114. {
  115. ULONG bq_StartIndex;
  116. PBUFFER_CHUNK bq_Head;
  117. PBUFFER_CHUNK bq_Tail;
  118. } BUFFER_QUEUE, *PBUFFER_QUEUE;
  119. #define ADSP_CONN_HASH_SIZE 23
  120. // ADSP ADDRESS OBJECT STATES
  121. #define ADSPAO_LISTENER 0x00000001
  122. #define ADSPAO_CONNECT 0x00000002
  123. #define ADSPAO_MESSAGE 0x00000010
  124. #define ADSPAO_CLOSING 0x80000000
  125. #define ADSPAO_SIGNATURE (*(PULONG)"ADAO")
  126. #define VALID_ADSPAO(pAdspAddr) (((pAdspAddr) != NULL) && \
  127. (((struct _ADSP_ADDROBJ *)(pAdspAddr))->adspao_Signature == ADSPAO_SIGNATURE))
  128. typedef struct _ADSP_ADDROBJ
  129. {
  130. ULONG adspao_Signature;
  131. // Global list of address objects.
  132. struct _ADSP_ADDROBJ * adspao_pNextGlobal;
  133. ULONG adspao_Flags;
  134. ULONG adspao_RefCount;
  135. ATALK_SPIN_LOCK adspao_Lock;
  136. PATALK_DEV_CTX adspao_pDevCtx;
  137. // List of connections associated with this address object.
  138. // Potentially greater than one if this address object is a listener.
  139. struct _ADSP_CONNOBJ * adspao_pAssocConn;
  140. // List of connections that are associated, but also have a listen/connect
  141. // posted on them.
  142. union
  143. {
  144. struct _ADSP_CONNOBJ * adspao_pListenConn;
  145. struct _ADSP_CONNOBJ * adspao_pConnectConn;
  146. };
  147. // List of indicated connections waiting for acceptance.
  148. struct _ADSP_OPEN_REQ * adspao_OpenReq;
  149. // Lookup list of all active connections hashed by connId and remote
  150. // address.
  151. struct _ADSP_CONNOBJ * adspao_pActiveHash[ADSP_CONN_HASH_SIZE];
  152. // Next connection to use.
  153. USHORT adspao_NextConnId;
  154. // Event support routines.
  155. //
  156. // This function pointer points to a connection indication handler for this
  157. // Address. Any time a connect request is received on the address, this
  158. // routine is invoked.
  159. PTDI_IND_CONNECT adspao_ConnHandler;
  160. PVOID adspao_ConnHandlerCtx;
  161. PTDI_IND_DISCONNECT adspao_DisconnectHandler;
  162. PVOID adspao_DisconnectHandlerCtx;
  163. PTDI_IND_RECEIVE adspao_RecvHandler;
  164. PVOID adspao_RecvHandlerCtx;
  165. PTDI_IND_RECEIVE_EXPEDITED adspao_ExpRecvHandler;
  166. PVOID adspao_ExpRecvHandlerCtx;
  167. PTDI_IND_SEND_POSSIBLE adspao_SendPossibleHandler;
  168. PVOID adspao_SendPossibleHandlerCtx;
  169. // DDP Address for this adsp address. If this is a listener, then the DDP
  170. // address will be what the listens effectively will be posted on. This
  171. // will also be the address over which the connections will be active.
  172. // if this is a connect address object, then this ddp address will be what the
  173. // associated connection be active over.
  174. PDDP_ADDROBJ adspao_pDdpAddr;
  175. // Completion routine to be called when address is closed
  176. GENERIC_COMPLETION adspao_CloseComp;
  177. PVOID adspao_CloseCtx;
  178. } ADSP_ADDROBJ, *PADSP_ADDROBJ;
  179. #define ADSPCO_ASSOCIATED 0x00000001
  180. #define ADSPCO_IND_RECV 0x00000002
  181. #define ADSPCO_LISTENING 0x00000004
  182. #define ADSPCO_CONNECTING 0x00000008
  183. #define ADSPCO_ACCEPT_IRP 0x00000010
  184. #define ADSPCO_LISTEN_IRP 0x00000020
  185. #define ADSPCO_HALF_ACTIVE 0x00000040
  186. #define ADSPCO_ACTIVE 0x00000080
  187. #define ADSPCO_SEEN_REMOTE_OPEN 0x00000100
  188. #define ADSPCO_DISCONNECTING 0x00000200
  189. #define ADSPCO_SERVER_JOB 0x00000400
  190. #define ADSPCO_REMOTE_CLOSE 0x00000800
  191. #define ADSPCO_SEND_IN_PROGRESS 0x00001000
  192. #define ADSPCO_SEND_DENY 0x00002000
  193. #define ADSPCO_SEND_OPENACK 0x00004000
  194. #define ADSPCO_SEND_WINDOW_CLOSED 0x00008000
  195. #define ADSPCO_READ_PENDING 0x00010000
  196. #define ADSPCO_EXREAD_PENDING 0x00020000
  197. #define ADSPCO_FORWARD_RESET_RECD 0x00040000
  198. #define ADSPCO_ATTN_DATA_RECD 0x00080000
  199. #define ADSPCO_ATTN_DATA_EOM 0x00100000
  200. #define ADSPCO_EXSEND_IN_PROGRESS 0x00200000
  201. #define ADSPCO_OPEN_TIMER 0x01000000
  202. #define ADSPCO_RETRANSMIT_TIMER 0x02000000
  203. #define ADSPCO_CONN_TIMER 0x04000000
  204. #define ADSPCO_LOCAL_DISCONNECT 0x08000000
  205. #define ADSPCO_REMOTE_DISCONNECT 0x10000000
  206. #define ADSPCO_DELAYED_DISCONNECT 0x20000000
  207. #define ADSPCO_STOPPING 0x40000000
  208. #define ADSPCO_CLOSING 0x80000000
  209. #define ADSPCO_SIGNATURE (*(PULONG)"ADCO")
  210. #define VALID_ADSPCO(pAdspConn) (((pAdspConn) != NULL) && \
  211. (((struct _ADSP_CONNOBJ *)(pAdspConn))->adspco_Signature == ADSPCO_SIGNATURE))
  212. // This will represent a 'job' on the Pap address. This could either be a
  213. // workstation job or a server job. In the latter case it could either
  214. // be in a 'listen' state or active state. In the former case it is either
  215. // active or 'waiting'
  216. typedef struct _ADSP_CONNOBJ
  217. {
  218. ULONG adspco_Signature;
  219. // Used to queue into the address object's associated list.
  220. struct _ADSP_CONNOBJ * adspco_pNextAssoc;
  221. ULONG adspco_Flags;
  222. ULONG adspco_RefCount;
  223. ATALK_SPIN_LOCK adspco_Lock;
  224. PATALK_DEV_CTX adspco_pDevCtx;
  225. // !!!NOTE!!!
  226. // The address this connection uses will be the address object's DDP address.
  227. PDDP_ADDROBJ adspco_pDdpAddr;
  228. // Used to queue into the address object's listen/connect list. When it
  229. // is removed from the listen/connect, it goes into the active list of the
  230. // address object.
  231. union
  232. {
  233. struct _ADSP_CONNOBJ * adspco_pNextListen;
  234. struct _ADSP_CONNOBJ * adspco_pNextConnect;
  235. struct _ADSP_CONNOBJ * adspco_pNextActive;
  236. };
  237. // Global list of connection objects.
  238. struct _ADSP_CONNOBJ * adspco_pNextGlobal;
  239. // Used to queue into the lookup by remote connid/remote address
  240. // list in address obj.
  241. struct _ADSP_CONNOBJ * adspco_pHashNext;
  242. // Backpointer to the associated address
  243. struct _ADSP_ADDROBJ * adspco_pAssocAddr;
  244. // Address of remote end of the connection
  245. ATALK_ADDR adspco_RemoteAddr;
  246. // Connection ids
  247. USHORT adspco_LocalConnId;
  248. USHORT adspco_RemoteConnId;
  249. // Connection timer. During open time this will be the open timer.
  250. union
  251. {
  252. TIMERLIST adspco_ConnTimer;
  253. TIMERLIST adspco_OpenTimer;
  254. };
  255. TIMERLIST adspco_RetransmitTimer;
  256. ULONG adspco_LastTimerRtmtSeq;
  257. LONG adspco_LastContactTime;
  258. // Connection context
  259. PVOID adspco_ConnCtx;
  260. // List of pended sends
  261. LIST_ENTRY adspco_PendedSends;
  262. // Sequence numbers
  263. ULONG adspco_SendSeq;
  264. ULONG adspco_FirstRtmtSeq;
  265. ULONG adspco_SendWindowSeq;
  266. ULONG adspco_SendAttnSeq;
  267. ULONG adspco_RecvSeq;
  268. ULONG adspco_RecvAttnSeq;
  269. // Window/buffers
  270. LONG adspco_RecvWindow;
  271. LONG adspco_SendQueueMax;
  272. LONG adspco_RecvQueueMax;
  273. // Previously indicated data
  274. ULONG adspco_PrevIndicatedData;
  275. // Buffer queues
  276. BUFFER_QUEUE adspco_SendQueue;
  277. BUFFER_QUEUE adspco_NextSendQueue;
  278. BUFFER_QUEUE adspco_RecvQueue;
  279. // Number of out of sequence packets received
  280. ULONG adspco_OutOfSeqCount;
  281. // The connection object can have either a CONNECT or a LISTEN posted
  282. // on it, but not both.
  283. union
  284. {
  285. struct
  286. {
  287. // Pending Listen routine.
  288. GENERIC_COMPLETION adspco_ListenCompletion;
  289. PVOID adspco_ListenCtx;
  290. };
  291. struct
  292. {
  293. // Pending Connect routine. The status buffer is remember and
  294. // returned via socket options. The pConnectRespBuf is remembered
  295. // to avoid having to get the system address for it. It is freed
  296. // when connection is taken off the connectlist.
  297. GENERIC_COMPLETION adspco_ConnectCompletion;
  298. PVOID adspco_ConnectCtx;
  299. ULONG adspco_ConnectAttempts;
  300. };
  301. };
  302. // Read completion information
  303. ULONG adspco_ReadFlags;
  304. PAMDL adspco_ReadBuf;
  305. USHORT adspco_ReadBufLen;
  306. GENERIC_READ_COMPLETION adspco_ReadCompletion;
  307. PVOID adspco_ReadCtx;
  308. PBYTE adspco_ExRecdData;
  309. USHORT adspco_ExRecdLen;
  310. // Expedited Read completion information
  311. ULONG adspco_ExReadFlags;
  312. USHORT adspco_ExReadBufLen;
  313. PAMDL adspco_ExReadBuf;
  314. GENERIC_READ_COMPLETION adspco_ExReadCompletion;
  315. PVOID adspco_ExReadCtx;
  316. // Expedited Write completion information
  317. TIMERLIST adspco_ExRetryTimer;
  318. PBYTE adspco_ExWriteChBuf;
  319. ULONG adspco_ExWriteFlags;
  320. USHORT adspco_ExWriteBufLen;
  321. PAMDL adspco_ExWriteBuf;
  322. GENERIC_WRITE_COMPLETION adspco_ExWriteCompletion;
  323. PVOID adspco_ExWriteCtx;
  324. // Disconnect inform routine
  325. GENERIC_COMPLETION adspco_DisconnectInform;
  326. PVOID adspco_DisconnectInformCtx;
  327. // Disconnect request completion
  328. ATALK_ERROR adspco_DisconnectStatus;
  329. GENERIC_COMPLETION adspco_DisconnectCompletion;
  330. PVOID adspco_DisconnectCtx;
  331. // The following is a hack to get around the problem of rcv/disconnet race condn.
  332. // Since this involves major rework, a safe approach is taken
  333. TIMERLIST adspco_DisconnectTimer;
  334. // Cleanup irp completion
  335. GENERIC_COMPLETION adspco_CleanupComp;
  336. PVOID adspco_CleanupCtx;
  337. // Completion routine to be called when socket is closed
  338. GENERIC_COMPLETION adspco_CloseComp;
  339. PVOID adspco_CloseCtx;
  340. } ADSP_CONNOBJ, *PADSP_CONNOBJ;
  341. // Used for the list of indicated connections waiting acceptance
  342. typedef struct _ADSP_OPEN_REQ
  343. {
  344. struct _ADSP_OPEN_REQ * or_Next;
  345. ATALK_ADDR or_RemoteAddr;
  346. ULONG or_FirstByteSeq;
  347. ULONG or_NextRecvSeq;
  348. LONG or_RecvWindow;
  349. USHORT or_RemoteConnId;
  350. } ADSP_OPEN_REQ, *PADSP_OPEN_REQ;
  351. // Routine prototypes
  352. VOID
  353. AtalkInitAdspInitialize(
  354. VOID);
  355. ATALK_ERROR
  356. AtalkAdspCreateAddress(
  357. IN PATALK_DEV_CTX pDevCtx OPTIONAL,
  358. IN BYTE SocketType,
  359. OUT PADSP_ADDROBJ * ppAdspAddr);
  360. ATALK_ERROR
  361. AtalkAdspCleanupAddress(
  362. IN PADSP_ADDROBJ pAdspAddr);
  363. ATALK_ERROR
  364. AtalkAdspCloseAddress(
  365. IN PADSP_ADDROBJ pAdspAddr,
  366. IN GENERIC_COMPLETION CompletionRoutine,
  367. IN PVOID pCloseCtx);
  368. ATALK_ERROR
  369. AtalkAdspCreateConnection(
  370. IN PVOID pConnCtx, // Context to associate with the session
  371. IN PATALK_DEV_CTX pDevCtx OPTIONAL,
  372. OUT PADSP_CONNOBJ * ppAdspConn);
  373. ATALK_ERROR
  374. AtalkAdspCloseConnection(
  375. IN PADSP_CONNOBJ pAdspConn,
  376. IN GENERIC_COMPLETION CompletionRoutine,
  377. IN PVOID pCloseCtx);
  378. ATALK_ERROR
  379. AtalkAdspCleanupConnection(
  380. IN PADSP_CONNOBJ pAdspConn);
  381. ATALK_ERROR
  382. AtalkAdspAssociateAddress(
  383. IN PADSP_ADDROBJ pAdspAddr,
  384. IN PADSP_CONNOBJ pAdspConn);
  385. ATALK_ERROR
  386. AtalkAdspDissociateAddress(
  387. IN PADSP_CONNOBJ pAdspConn);
  388. ATALK_ERROR
  389. AtalkAdspPostListen(
  390. IN PADSP_CONNOBJ pAdspConn,
  391. IN PVOID pListenCtx,
  392. IN GENERIC_COMPLETION CompletionRoutine);
  393. ATALK_ERROR
  394. AtalkAdspCancelListen(
  395. IN PADSP_CONNOBJ pAdspConn) ;
  396. ATALK_ERROR
  397. AtalkAdspPostConnect(
  398. IN PADSP_CONNOBJ pAdspConn,
  399. IN PATALK_ADDR pRemoteAddr,
  400. IN PVOID pConnectCtx,
  401. IN GENERIC_COMPLETION CompletionRoutine);
  402. ATALK_ERROR
  403. AtalkAdspDisconnect(
  404. IN PADSP_CONNOBJ pAdspConn,
  405. IN ATALK_DISCONNECT_TYPE DisconnectType,
  406. IN PVOID pDisconnectCtx,
  407. IN GENERIC_COMPLETION CompletionRoutine);
  408. ATALK_ERROR
  409. AtalkAdspRead(
  410. IN PADSP_CONNOBJ pAdspConn,
  411. IN PAMDL pReadBuf,
  412. IN USHORT ReadBufLen,
  413. IN ULONG ReadFlags,
  414. IN PVOID pReadCtx,
  415. IN GENERIC_READ_COMPLETION CompletionRoutine);
  416. ATALK_ERROR
  417. AtalkAdspWrite(
  418. IN PADSP_CONNOBJ pAdspConn,
  419. IN PAMDL pWriteBuf,
  420. IN USHORT WriteBufLen,
  421. IN ULONG SendFlags,
  422. IN PVOID pWriteCtx,
  423. IN GENERIC_WRITE_COMPLETION CompletionRoutine);
  424. VOID
  425. AtalkAdspQuery(
  426. IN PVOID pObject,
  427. IN ULONG ObjectType,
  428. IN PAMDL pAmdl,
  429. OUT PULONG BytesWritten);
  430. VOID
  431. atalkAdspAddrRefNonInterlock(
  432. IN PADSP_ADDROBJ pAdspAddr,
  433. OUT PATALK_ERROR pError);
  434. VOID
  435. atalkAdspAddrDeref(
  436. IN PADSP_ADDROBJ pAdspAddr);
  437. VOID
  438. atalkAdspConnRefByPtrNonInterlock(
  439. IN PADSP_CONNOBJ pAdspConn,
  440. IN ULONG NumCount,
  441. OUT PATALK_ERROR pError);
  442. VOID
  443. atalkAdspConnRefByCtxNonInterlock(
  444. IN PADSP_ADDROBJ pAdspAddr,
  445. IN CONNECTION_CONTEXT Ctx,
  446. OUT PADSP_CONNOBJ * pAdspConn,
  447. OUT PATALK_ERROR pError);
  448. VOID
  449. atalkAdspConnRefBySrcAddr(
  450. IN PADSP_ADDROBJ pAdspAddr,
  451. IN PATALK_ADDR pRemoteAddr,
  452. IN USHORT RemoteConnId,
  453. OUT PADSP_CONNOBJ * ppAdspConn,
  454. OUT PATALK_ERROR pError);
  455. VOID
  456. atalkAdspConnRefNextNc(
  457. IN PADSP_CONNOBJ pAdspConn,
  458. IN PADSP_CONNOBJ * ppAdspConnNext,
  459. OUT PATALK_ERROR pError);
  460. VOID
  461. AtalkAdspProcessQueuedSend(
  462. IN PADSP_CONNOBJ pAdspConn);
  463. VOID
  464. atalkAdspConnDeref(
  465. IN PADSP_CONNOBJ pAdspConn);
  466. // MACROS
  467. #define UNSIGNED_BETWEEN_WITH_WRAP(Low, High, Target) \
  468. ((Low <= High) ? ((Target >= Low) && (Target <= High)) : \
  469. ((Target >= Low) || (Target <= High)))
  470. // This didnt make sense until JameelH explained what was going on.
  471. // This is with the assumption that the window size will never be greater
  472. // than the difference of 0x80000 and 0x10000. If High is < 10000 and Low
  473. // is > 80000 then we can assume a wrap happened. Otherwise, we assume no
  474. // wrap and do a straight compare.
  475. #define UNSIGNED_GREATER_WITH_WRAP(High, Low) \
  476. (((High < 0x10000) && (Low > 0x80000)) ? TRUE : (High > Low))
  477. // (((High < 0x80000) && (Low > 0x10000)) ? TRUE : (High > Low))
  478. #define AtalkAdspGetDdpAddress(pAdspAddr) \
  479. ((pAdspAddr)->adspao_pDdpAddr)
  480. #define AtalkAdspAddrReferenceNonInterlock(pAdspAddr, pError) \
  481. { \
  482. DBGPRINT(DBG_COMP_ADSP, DBG_LEVEL_INFO, ("RefAddr %lx at %s %d - %d\n", \
  483. pAdspAddr, __FILE__, __LINE__, ((pAdspAddr)->adspao_RefCount))); \
  484. atalkAdspAddrRefNonInterlock(pAdspAddr, pError); \
  485. }
  486. #define AtalkAdspAddrReference(pAdspAddr, pError) \
  487. { \
  488. KIRQL OldIrql; \
  489. \
  490. ACQUIRE_SPIN_LOCK(&(pAdspAddr)->adspao_Lock, &OldIrql); \
  491. AtalkAdspAddrReferenceNonInterlock(pAdspAddr, pError); \
  492. RELEASE_SPIN_LOCK(&(pAdspAddr)->adspao_Lock, OldIrql); \
  493. }
  494. #define AtalkAdspAddrDereference(pAdspAddr) \
  495. { \
  496. DBGPRINT(DBG_COMP_ADSP, DBG_LEVEL_INFO, ("DerefAddr %lx at %s %d - %d\n",\
  497. pAdspAddr, __FILE__, __LINE__, ((pAdspAddr)->adspao_RefCount))); \
  498. atalkAdspAddrDeref(pAdspAddr); \
  499. }
  500. #define AtalkAdspConnReferenceByPtrNonInterlock(pAdspConn, NumCount, pError) \
  501. { \
  502. atalkAdspConnRefByPtrNonInterlock(pAdspConn, NumCount, pError); \
  503. }
  504. #define AtalkAdspConnReferenceByPtr(pAdspConn, pError) \
  505. { \
  506. KIRQL OldIrql; \
  507. \
  508. ACQUIRE_SPIN_LOCK(&(pAdspConn)->adspco_Lock, &OldIrql); \
  509. AtalkAdspConnReferenceByPtrNonInterlock(pAdspConn, 1, pError);\
  510. RELEASE_SPIN_LOCK(&(pAdspConn)->adspco_Lock, OldIrql); \
  511. }
  512. #define AtalkAdspConnReferenceByCtxNonInterlock(pAdspAddr, Ctx, ppAdspConn, pError) \
  513. atalkAdspConnRefByCtxNonInterlock(pAdspAddr, Ctx, ppAdspConn, pError)
  514. #define AtalkAdspConnReferenceBySrcAddr(pAdspAddr, pSrc, SessId, pErr) \
  515. atalkAdspConnRefBySrcAddr(pAdspAddr, pSrc, SessId, pErr)
  516. #define AtalkAdspConnDereference(pAdspConn) \
  517. { \
  518. DBGPRINT(DBG_COMP_ADSP, DBG_LEVEL_INFO, \
  519. ("DerefConn %lx at %s %d - %d\n", \
  520. pAdspConn, __FILE__, __LINE__, \
  521. (pAdspConn)->adspco_RefCount)); \
  522. atalkAdspConnDeref(pAdspConn); \
  523. }
  524. // How many bytes/seqnums does eom occupy?
  525. #define BYTECOUNT(eom) ((ULONG)((eom) ? 1 : 0))
  526. //
  527. // PLIST_ENTRY
  528. // WRITECTX_LINKAGE(
  529. // IN PVOID WriteCtx
  530. // );
  531. //
  532. // Returns a pointer to a linkage field in the write context (Assumed to be IRP).
  533. //
  534. #define WRITECTX_LINKAGE(_Request) \
  535. (&(((PIRP)_Request)->Tail.Overlay.ListEntry))
  536. #define WRITECTX(_Request) ((PIRP)(_Request))
  537. //
  538. // PVOID
  539. // LIST_ENTRY_TO_WRITECTX(
  540. // IN PLIST_ENTRY ListEntry
  541. // );
  542. //
  543. // Returns a request given a linkage field in it.
  544. //
  545. #define LIST_ENTRY_TO_WRITECTX(_ListEntry) \
  546. ((PVOID)(CONTAINING_RECORD(_ListEntry, IRP, Tail.Overlay.ListEntry)))
  547. //
  548. // PVOID
  549. // WRITECTX_TDI_BUFFER
  550. // IN PVOID Request
  551. // );
  552. //
  553. // Returns the TDI buffer chain associated with a request.
  554. //
  555. #define WRITECTX_TDI_BUFFER(_Request) \
  556. ((PVOID)(((PIRP)(_Request))->MdlAddress))
  557. //
  558. // ULONG
  559. // WRITECTX_SIZE(
  560. // IN PVOID Request
  561. // );
  562. //
  563. // Obtains size of send
  564. //
  565. #define WRITECTX_SIZE(_Request) \
  566. (((PTDI_REQUEST_KERNEL_SEND)(&((IoGetCurrentIrpStackLocation((PIRP)_Request))->Parameters)))->SendLength)
  567. //
  568. // ULONG
  569. // WRITECTX_FLAGS(
  570. // IN PVOID Request
  571. // );
  572. //
  573. // Obtains size of send
  574. //
  575. #define WRITECTX_FLAGS(_Request) \
  576. (((PTDI_REQUEST_KERNEL_SEND)(&((IoGetCurrentIrpStackLocation((PIRP)_Request))->Parameters)))->SendFlags)
  577. extern PADSP_ADDROBJ atalkAdspAddrList;
  578. extern PADSP_CONNOBJ atalkAdspConnList;
  579. extern ATALK_SPIN_LOCK atalkAdspLock;
  580. PBUFFER_CHUNK
  581. atalkAdspAllocCopyChunk(
  582. IN PVOID pWriteBuf,
  583. IN USHORT WriteBufLen,
  584. IN BOOLEAN Eom,
  585. IN BOOLEAN IsCharBuffer);
  586. VOID
  587. atalkAdspPacketIn(
  588. IN PPORT_DESCRIPTOR pPortDesc,
  589. IN PDDP_ADDROBJ pDdpAddr,
  590. IN PBYTE pPkt,
  591. IN USHORT PktLen,
  592. IN PATALK_ADDR pSrcAddr,
  593. IN PATALK_ADDR pDestAddr,
  594. IN ATALK_ERROR ErrorCode,
  595. IN BYTE DdpType,
  596. IN PADSP_ADDROBJ pAdspAddr,
  597. IN BOOLEAN OptimizePath,
  598. IN PVOID OptimizeCtx);
  599. LOCAL VOID
  600. atalkAdspHandleOpenControl(
  601. IN PADSP_ADDROBJ pAdspAddr,
  602. IN PBYTE pPkt,
  603. IN USHORT PktLen,
  604. IN PATALK_ADDR pSrcAddr,
  605. IN USHORT RemoteConnId,
  606. IN ULONG RemoteFirstByteSeq,
  607. IN ULONG RemoteNextRecvSeq,
  608. IN ULONG RemoteRecvWindow,
  609. IN BYTE Descriptor);
  610. LOCAL VOID
  611. atalkAdspHandleAttn(
  612. IN PADSP_CONNOBJ pAdspConn,
  613. IN PBYTE pPkt,
  614. IN USHORT PktLen,
  615. IN PATALK_ADDR pSrcAddr,
  616. IN ULONG RemoteFirstByteSeq,
  617. IN ULONG RemoteNextRecvSeq,
  618. IN ULONG RemoteRecvWindow,
  619. IN BYTE Descriptor);
  620. LOCAL VOID
  621. atalkAdspHandlePiggyBackAck(
  622. IN PADSP_CONNOBJ pAdspConn,
  623. IN ULONG RemoteNextRecvSeq,
  624. IN ULONG RemoteRecvWindow);
  625. LOCAL VOID
  626. atalkAdspHandleControl(
  627. IN PADSP_CONNOBJ pAdspConn,
  628. IN PBYTE pPkt,
  629. IN USHORT PktLen,
  630. IN PATALK_ADDR pSrcAddr,
  631. IN ULONG RemoteFirstByteSeq,
  632. IN ULONG RemoteNextRecvSeq,
  633. IN ULONG RemoteRecvWindow,
  634. IN BYTE Descriptor);
  635. LOCAL VOID
  636. atalkAdspHandleData(
  637. IN PADSP_CONNOBJ pAdspConn,
  638. IN PBYTE pPkt,
  639. IN USHORT PktLen,
  640. IN PATALK_ADDR pSrcAddr,
  641. IN ULONG RemoteFirstByteSeq,
  642. IN ULONG RemoteNextRecvSeq,
  643. IN ULONG RemoteRecvWindow,
  644. IN BYTE Descriptor);
  645. LOCAL VOID
  646. atalkAdspHandleOpenReq(
  647. IN PADSP_ADDROBJ pAdspAddr,
  648. IN PBYTE pPkt,
  649. IN USHORT PktLen,
  650. IN PATALK_ADDR pSrcAddr,
  651. IN USHORT RemoteConnId,
  652. IN ULONG RemoteFirstByteSeq,
  653. IN ULONG RemoteNextRecvSeq,
  654. IN ULONG RemoteRecvWindow,
  655. IN BYTE Descriptor);
  656. LOCAL VOID
  657. atalkAdspListenIndicateNonInterlock(
  658. IN PADSP_ADDROBJ pAdspAddr,
  659. IN PADSP_OPEN_REQ pOpenReq,
  660. IN PADSP_CONNOBJ * ppAdspConn,
  661. IN PATALK_ERROR pError);
  662. ATALK_ERROR
  663. atalkAdspSendExpedited(
  664. IN PADSP_CONNOBJ pAdspConn,
  665. IN PAMDL pWriteBuf,
  666. IN USHORT WriteBufLen,
  667. IN ULONG SendFlags,
  668. IN PVOID pWriteCtx,
  669. IN GENERIC_WRITE_COMPLETION CompletionRoutine);
  670. LOCAL VOID
  671. atalkAdspSendOpenControl(
  672. IN PADSP_CONNOBJ pAdspConn);
  673. LOCAL VOID
  674. atalkAdspSendControl(
  675. IN PADSP_CONNOBJ pAdspConn,
  676. IN BYTE Descriptor);
  677. LOCAL VOID
  678. atalkAdspSendAttn(
  679. IN PADSP_CONNOBJ pAdspConn);
  680. LOCAL VOID
  681. atalkAdspSendData(
  682. IN PADSP_CONNOBJ pAdspConn);
  683. LOCAL VOID
  684. atalkAdspRecvAttn(
  685. IN PADSP_CONNOBJ pAdspConn);
  686. LOCAL VOID
  687. atalkAdspRecvData(
  688. IN PADSP_CONNOBJ pAdspConn);
  689. LOCAL VOID
  690. atalkAdspSendDeny(
  691. IN PADSP_ADDROBJ pAdspAddr,
  692. IN PATALK_ADDR pRemoteAddr,
  693. IN USHORT pRemoteConnId);
  694. VOID FASTCALL
  695. atalkAdspSendAttnComplete(
  696. IN NDIS_STATUS Status,
  697. IN PSEND_COMPL_INFO pSendInfo);
  698. VOID FASTCALL
  699. atalkAdspConnSendComplete(
  700. IN NDIS_STATUS Status,
  701. IN PSEND_COMPL_INFO pSendInfo);
  702. VOID FASTCALL
  703. atalkAdspAddrSendComplete(
  704. IN NDIS_STATUS Status,
  705. IN PSEND_COMPL_INFO pSendInfo);
  706. VOID FASTCALL
  707. atalkAdspSendDataComplete(
  708. IN NDIS_STATUS Status,
  709. IN PSEND_COMPL_INFO pSendInfo);
  710. LOCAL LONG FASTCALL
  711. atalkAdspConnMaintenanceTimer(
  712. IN PTIMERLIST pTimer,
  713. IN BOOLEAN TimerShuttingDown);
  714. LOCAL LONG FASTCALL
  715. atalkAdspRetransmitTimer(
  716. IN PTIMERLIST pTimer,
  717. IN BOOLEAN TimerShuttingDown);
  718. LOCAL LONG FASTCALL
  719. atalkAdspAttnRetransmitTimer(
  720. IN PTIMERLIST pTimer,
  721. IN BOOLEAN TimerShuttingDown);
  722. LOCAL LONG FASTCALL
  723. atalkAdspOpenTimer(
  724. IN PTIMERLIST pTimer,
  725. IN BOOLEAN TimerShuttingDown);
  726. LOCAL LONG FASTCALL
  727. atalkAdspDisconnectTimer(
  728. IN PTIMERLIST pTimer,
  729. IN BOOLEAN TimerShuttingDown);
  730. VOID
  731. atalkAdspDecodeHeader(
  732. IN PBYTE Datagram,
  733. OUT PUSHORT RemoteConnId,
  734. OUT PULONG FirstByteSeq,
  735. OUT PULONG NextRecvSeq,
  736. OUT PLONG Window,
  737. OUT PBYTE Descriptor);
  738. LOCAL USHORT
  739. atalkAdspGetNextConnId(
  740. IN PADSP_ADDROBJ pAdspAddr,
  741. OUT PATALK_ERROR pError);
  742. LOCAL BOOLEAN
  743. atalkAdspConnDeQueueAssocList(
  744. IN PADSP_ADDROBJ pAdspAddr,
  745. IN PADSP_CONNOBJ pAdspConn);
  746. LOCAL BOOLEAN
  747. atalkAdspConnDeQueueConnectList(
  748. IN PADSP_ADDROBJ pAdspAddr,
  749. IN PADSP_CONNOBJ pAdspConn);
  750. LOCAL BOOLEAN
  751. atalkAdspConnDeQueueListenList(
  752. IN PADSP_ADDROBJ pAdspAddr,
  753. IN PADSP_CONNOBJ pAdspConn);
  754. LOCAL BOOLEAN
  755. atalkAdspConnDeQueueActiveList(
  756. IN PADSP_ADDROBJ pAdspAddr,
  757. IN PADSP_CONNOBJ pAdspConn);
  758. LOCAL VOID
  759. atalkAdspAddrQueueGlobalList(
  760. IN PADSP_ADDROBJ pAdspAddr);
  761. LOCAL VOID
  762. atalkAdspAddrDeQueueGlobalList(
  763. IN PADSP_ADDROBJ pAdspAddr);
  764. LOCAL VOID
  765. atalkAdspConnDeQueueGlobalList(
  766. IN PADSP_CONNOBJ pAdspConn);
  767. LOCAL BOOLEAN
  768. atalkAdspAddrDeQueueOpenReq(
  769. IN PADSP_ADDROBJ pAdspAddr,
  770. IN USHORT RemoteConnId,
  771. IN PATALK_ADDR pSrcAddr,
  772. OUT PADSP_OPEN_REQ * ppOpenReq);
  773. LOCAL BOOLEAN
  774. atalkAdspIsDuplicateOpenReq(
  775. IN PADSP_ADDROBJ pAdspAddr,
  776. IN USHORT RemoteConnId,
  777. IN PATALK_ADDR pSrcAddr);
  778. LOCAL VOID
  779. atalkAdspGenericComplete(
  780. IN ATALK_ERROR ErrorCode,
  781. IN PIRP pIrp);
  782. ULONG
  783. atalkAdspMaxSendSize(
  784. IN PADSP_CONNOBJ pAdspConn);
  785. ULONG
  786. atalkAdspMaxNextReadSize(
  787. IN PBUFFER_QUEUE pQueue,
  788. OUT PBOOLEAN pEom,
  789. OUT PBUFFER_CHUNK * pBufferChunk);
  790. ULONG
  791. atalkAdspBufferQueueSize(
  792. IN PBUFFER_QUEUE pQueue);
  793. ULONG
  794. atalkAdspMessageSize(
  795. IN PBUFFER_QUEUE pQueue,
  796. IN PBOOLEAN pEom);
  797. PBYTE
  798. atalkAdspGetLookahead(
  799. IN PBUFFER_QUEUE pQueue,
  800. OUT PULONG pLookaheadSize);
  801. ULONG
  802. atalkAdspReadFromBufferQueue(
  803. IN PBUFFER_QUEUE pQueue,
  804. IN ULONG pFlags,
  805. OUT PAMDL pReadBuf,
  806. IN OUT PUSHORT pReadLen,
  807. OUT PBOOLEAN pEom);
  808. BOOLEAN
  809. atalkAdspDiscardFromBufferQueue(
  810. IN PBUFFER_QUEUE pQueue,
  811. IN ULONG DataSize,
  812. OUT PBUFFER_QUEUE pAuxQueue,
  813. IN ATALK_ERROR Error,
  814. IN PADSP_CONNOBJ pAdspConn OPTIONAL);
  815. VOID
  816. atalkAdspAddToBufferQueue(
  817. IN OUT PBUFFER_QUEUE pQueue,
  818. IN PBUFFER_CHUNK pChunk,
  819. IN OUT PBUFFER_QUEUE pAuxQueue OPTIONAL);
  820. VOID
  821. atalkAdspBufferChunkReference(
  822. IN PBUFFER_CHUNK pBufferChunk);
  823. VOID
  824. atalkAdspBufferChunkDereference(
  825. IN PBUFFER_CHUNK pBufferChunk,
  826. IN BOOLEAN CreationDeref,
  827. IN PADSP_CONNOBJ pAdspConn OPTIONAL);
  828. VOID
  829. atalkAdspConnFindInConnect(
  830. IN PADSP_ADDROBJ pAdspAddr,
  831. IN USHORT DestConnId,
  832. IN PATALK_ADDR pRemoteAddr,
  833. OUT PADSP_CONNOBJ * ppAdspConn,
  834. IN PATALK_ERROR pError);
  835. ULONG
  836. atalkAdspDescribeFromBufferQueue(
  837. IN PBUFFER_QUEUE pQueue,
  838. OUT PBOOLEAN pEom,
  839. IN ULONG WindowSize,
  840. OUT PBUFFER_CHUNK * ppBufferChunk,
  841. OUT PBUFFER_DESC * ppBufDesc);
  842. #endif // _ADSP_
  843.