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.

530 lines
17 KiB

  1. /*++
  2. Copyright (c) 1989-1993 Microsoft Corporation
  3. Module Name:
  4. spxpkt.h
  5. Abstract:
  6. Author:
  7. Nikhil Kamkolkar (nikhilk) 11-November-1993
  8. Environment:
  9. Kernel mode
  10. Revision History:
  11. --*/
  12. // Use our own NDIS packets
  13. //#define SPX_OWN_PACKETS 1
  14. //
  15. // List of NDIS_PACKETS stored...
  16. //
  17. extern SLIST_HEADER SendPacketList;
  18. extern SLIST_HEADER RecvPacketList;
  19. EXTERNAL_LOCK(RecvHeaderLock);
  20. EXTERNAL_LOCK(SendHeaderLock);
  21. // Offsets into the IPX header
  22. #define IPX_HDRSIZE 30 // Size of the IPX header
  23. #define IPX_CHECKSUM 0 // Checksum
  24. #define IPX_LENGTH 2 // Length
  25. #define IPX_XPORTCTL 4 // Transport Control
  26. #define IPX_PKTTYPE 5 // Packet Type
  27. #define IPX_DESTADDR 6 // Dest. Address (Total)
  28. #define IPX_DESTNET 6 // Dest. Network Address
  29. #define IPX_DESTNODE 10 // Dest. Node Address
  30. #define IPX_DESTSOCK 16 // Dest. Socket Number
  31. #define IPX_SRCADDR 18 // Source Address (Total)
  32. #define IPX_SRCNET 18 // Source Network Address
  33. #define IPX_SRCNODE 22 // Source Node Address
  34. #define IPX_SRCSOCK 28 // Source Socket Number
  35. #define IPX_NET_LEN 4
  36. #define IPX_NODE_LEN 6
  37. #include <packon.h>
  38. // Definition of the IPX/SPX header.
  39. typedef struct _IPXSPX_HEADER
  40. {
  41. USHORT hdr_CheckSum;
  42. USHORT hdr_PktLen;
  43. UCHAR hdr_XportCtrl;
  44. UCHAR hdr_PktType;
  45. UCHAR hdr_DestNet[4];
  46. UCHAR hdr_DestNode[6];
  47. USHORT hdr_DestSkt;
  48. UCHAR hdr_SrcNet[4];
  49. UCHAR hdr_SrcNode[6];
  50. USHORT hdr_SrcSkt;
  51. // SPX Header Elements
  52. UCHAR hdr_ConnCtrl;
  53. UCHAR hdr_DataType;
  54. USHORT hdr_SrcConnId;
  55. USHORT hdr_DestConnId;
  56. USHORT hdr_SeqNum;
  57. USHORT hdr_AckNum;
  58. USHORT hdr_AllocNum;
  59. // For non-CR SPXII packets only
  60. USHORT hdr_NegSize;
  61. } IPXSPX_HDR, *PIPXSPX_HDR;
  62. #include <packoff.h>
  63. // NDIS Packet size - two more ulongs added... 11/26/96
  64. #define NDIS_PACKET_SIZE 48+8
  65. // Minimum header size (doesnt include neg size)
  66. #define MIN_IPXSPX_HDRSIZE (sizeof(IPXSPX_HDR) - sizeof(USHORT))
  67. #define MIN_IPXSPX2_HDRSIZE sizeof(IPXSPX_HDR)
  68. #define SPX_CR_PKTLEN 42
  69. // SPX packet type
  70. #define SPX_PKT_TYPE 0x5
  71. // Connection control fields
  72. #define SPX_CC_XHD 0x01
  73. #define SPX_CC_RES1 0x02
  74. #define SPX_CC_NEG 0x04
  75. #define SPX_CC_SPX2 0x08
  76. #define SPX_CC_EOM 0x10
  77. #define SPX_CC_ATN 0x20
  78. #define SPX_CC_ACK 0x40
  79. #define SPX_CC_SYS 0x80
  80. #define SPX_CC_CR (SPX_CC_ACK | SPX_CC_SYS)
  81. // Data stream types
  82. #define SPX2_DT_ORDREL 0xFD
  83. #define SPX2_DT_IDISC 0xFE
  84. #define SPX2_DT_IDISC_ACK 0xFF
  85. // Negotiation size
  86. #define SPX_MAX_PACKET 576
  87. #define SPX_NEG_MIN SPX_MAX_PACKET
  88. #define SPX_NEG_MAX 65535
  89. // No packet references connection. But if the sends are being aborted, and
  90. // the packet happens to be owned by ipx at the time, the pkt is dequeued from
  91. // conn, the ABORT flag is set and conn is referenced for packet.
  92. //
  93. // Send packet states
  94. // ABORT : Used for aborted packet. Calls AbortSendPkt().
  95. // IPXOWNS : Currently owned by ipx
  96. // FREEDATA: Frees the data associated with second ndis buffer desc
  97. // ACKREQ : Only for sequenced packets. Set by retry timer in packets it wants
  98. // resent (1 for spx1, all pending for spx2) with ack bit set.
  99. // DESTROY : Only for non-sequenced packets, dequeue packet from list and free.
  100. // REQ : For both seq/non-seq. A request is associated with the packet
  101. // SEQ : Packet is a sequenced packet.
  102. // LASTPKT : Packet is last packet comprising the request, if acked req is done.
  103. // EOM : Send EOM with the last packet for this request
  104. // ACKEDPKT: Send completion must only deref req with pkt and complete if zero.
  105. //
  106. #define SPX_SENDPKT_IDLE 0
  107. #define SPX_SENDPKT_ABORT 0x0002
  108. #define SPX_SENDPKT_IPXOWNS 0x0004
  109. #define SPX_SENDPKT_FREEDATA 0x0008
  110. #define SPX_SENDPKT_ACKREQ 0x0010
  111. #define SPX_SENDPKT_DESTROY 0x0020
  112. #define SPX_SENDPKT_REQ 0x0040
  113. #define SPX_SENDPKT_SEQ 0x0080
  114. #define SPX_SENDPKT_LASTPKT 0x0100
  115. #define SPX_SENDPKT_ACKEDPKT 0x0200
  116. #define SPX_SENDPKT_EOM 0x0400
  117. #define SPX_SENDPKT_REXMIT 0x0800
  118. // Packet types
  119. #define SPX_TYPE_CR 0x01
  120. #define SPX_TYPE_CRACK 0x02
  121. #define SPX_TYPE_SN 0x03
  122. #define SPX_TYPE_SNACK 0x04
  123. #define SPX_TYPE_SS 0x05
  124. #define SPX_TYPE_SSACK 0x06
  125. #define SPX_TYPE_RR 0x07
  126. #define SPX_TYPE_RRACK 0x08
  127. #define SPX_TYPE_IDISC 0x09
  128. #define SPX_TYPE_IDISCACK 0x0a
  129. #define SPX_TYPE_ORDREL 0x0b
  130. #define SPX_TYPE_ORDRELACK 0x0c
  131. #define SPX_TYPE_DATA 0x0d
  132. #define SPX_TYPE_DATAACK 0x0e
  133. #define SPX_TYPE_DATANACK 0x0f
  134. #define SPX_TYPE_PROBE 0x10
  135. // Definition of the protocol reserved field of a send packet.
  136. // Make Len/HdrLen USHORTS, move to the end before the
  137. // sr_SentTime so we dont use padding space.
  138. typedef struct _SPX_SEND_RESD
  139. {
  140. UCHAR sr_Id; // Set to SPX
  141. UCHAR sr_Type; // What kind of packet
  142. USHORT sr_State; // State of send packet
  143. PVOID sr_Reserved1; // Needed by IPX
  144. PVOID sr_Reserved2; // Needed by IPX
  145. #if defined(_PNP_POWER)
  146. PVOID sr_Reserved[SEND_RESERVED_COMMON_SIZE-2]; // needed by IPX for local target
  147. #endif _PNP_POWER
  148. ULONG sr_Len; // Length of packet
  149. ULONG sr_HdrLen; // Included header length
  150. struct _SPX_SEND_RESD * sr_Next; // Points to next packet
  151. // in send queue in conn.
  152. PREQUEST sr_Request; // request associated
  153. ULONG sr_Offset; // Offset in mdl for sends
  154. #ifndef SPX_OWN_PACKETS
  155. PVOID sr_FreePtr; // Ptr to use in free chunk
  156. #endif
  157. struct _SPX_CONN_FILE * sr_ConnFile; // that this send is on
  158. USHORT sr_SeqNum; // Seq num for seq pkts
  159. // Quad word aligned.
  160. LARGE_INTEGER sr_SentTime; // Time packet was sent
  161. // Only valid for data pkt
  162. // with ACKREQ set.
  163. SINGLE_LIST_ENTRY Linkage;
  164. } SPX_SEND_RESD, *PSPX_SEND_RESD;
  165. // Recv packet states
  166. #define SPX_RECVPKT_IDLE 0
  167. #define SPX_RECVPKT_BUFFERING 0x0001
  168. #define SPX_RECVPKT_IDISC 0x0002
  169. #define SPX_RECVPKT_ORD_DISC 0x0004
  170. #define SPX_RECVPKT_INDICATED 0x0008
  171. #define SPX_RECVPKT_SENDACK 0x0010
  172. #define SPX_RECVPKT_EOM 0x0020
  173. #define SPX_RECVPKT_IMMEDACK 0x0040
  174. #define SPX_RECVPKT_DISCMASK (SPX_RECVPKT_ORD_DISC | SPX_RECVPKT_IDISC)
  175. // Definition of the protocol reserved field of a receive packet.
  176. typedef struct _SPX_RECV_RESD
  177. {
  178. UCHAR rr_Id; // Set to SPX
  179. USHORT rr_State; // State of receive packet
  180. struct _SPX_RECV_RESD * rr_Next; // Points to next packet
  181. ULONG rr_DataOffset; // To indicate/copy from
  182. #ifndef SPX_OWN_PACKETS
  183. PVOID rr_FreePtr; // Ptr to use in free chunk
  184. #endif
  185. #if DBG
  186. USHORT rr_SeqNum; // Seq num of packet
  187. #endif
  188. SINGLE_LIST_ENTRY Linkage;
  189. PREQUEST rr_Request; // request waiting on xfer
  190. struct _SPX_CONN_FILE * rr_ConnFile; // that this recv is on
  191. } SPX_RECV_RESD, *PSPX_RECV_RESD;
  192. // Destination built as an assign of 3 ulongs.
  193. #define SpxBuildIpxHdr(pIpxSpxHdr, PktLen, pRemAddr, SrcSkt) \
  194. { \
  195. PBYTE pDestIpxAddr = (PBYTE)pIpxSpxHdr->hdr_DestNet; \
  196. (pIpxSpxHdr)->hdr_CheckSum = 0xFFFF; \
  197. PUTSHORT2SHORT((PUSHORT)(&(pIpxSpxHdr)->hdr_PktLen), (PktLen)); \
  198. (pIpxSpxHdr)->hdr_XportCtrl = 0; \
  199. (pIpxSpxHdr)->hdr_PktType = SPX_PKT_TYPE; \
  200. *((UNALIGNED ULONG *)pDestIpxAddr) = \
  201. *((UNALIGNED ULONG *)pRemAddr); \
  202. *((UNALIGNED ULONG *)(pDestIpxAddr+4)) = \
  203. *((UNALIGNED ULONG *)(pRemAddr+4)); \
  204. *((UNALIGNED ULONG *)(pDestIpxAddr+8)) = \
  205. *((UNALIGNED ULONG *)(pRemAddr+8)); \
  206. *((UNALIGNED ULONG *)((pIpxSpxHdr)->hdr_SrcNet))= \
  207. *((UNALIGNED ULONG *)(SpxDevice->dev_Network)); \
  208. *((UNALIGNED ULONG *)((pIpxSpxHdr)->hdr_SrcNode)) = \
  209. *((UNALIGNED ULONG *)SpxDevice->dev_Node); \
  210. *((UNALIGNED USHORT *)((pIpxSpxHdr)->hdr_SrcNode+4)) = \
  211. *((UNALIGNED USHORT *)(SpxDevice->dev_Node+4)); \
  212. *((UNALIGNED USHORT *)&((pIpxSpxHdr)->hdr_SrcSkt)) = \
  213. SrcSkt; \
  214. }
  215. #define SpxCopyIpxAddr(pIpxSpxHdr, pDestIpxAddr) \
  216. { \
  217. PBYTE pRemAddr = (PBYTE)pIpxSpxHdr->hdr_SrcNet; \
  218. *((UNALIGNED ULONG *)pDestIpxAddr) = \
  219. *((UNALIGNED ULONG *)pRemAddr); \
  220. *((UNALIGNED ULONG *)(pDestIpxAddr+4)) = \
  221. *((UNALIGNED ULONG *)(pRemAddr+4)); \
  222. *((UNALIGNED ULONG *)(pDestIpxAddr+8)) = \
  223. *((UNALIGNED ULONG *)(pRemAddr+8)); \
  224. }
  225. #ifdef UNDEFINDED
  226. #define SpxAllocRecvPacket(_Device,_RecvPacket,_Status) \
  227. { \
  228. PSINGLE_LIST_ENTRY Link; \
  229. \
  230. Link = ExInterlockedPopEntrySList( \
  231. &PacketList, \
  232. &HeaderLock \
  233. ); \
  234. \
  235. if (Link != NULL) { \
  236. Common = STRUCT_OF(struct PCCommon, Link, pc_link); \
  237. PC = STRUCT_OF(PacketContext, Common, pc_common); \
  238. (*_RecvPacket) = STRUCT_OF(NDIS_PACKET, PC, ProtocolReserved); \
  239. (*_Status) = NDIS_STATUS_SUCCESS; \
  240. } else { \
  241. \
  242. (*_RecvPacket) = GrowSPXPacketsList(); \
  243. (*_Status) = NDIS_STATUS_SUCCESS; \
  244. if (NULL == _RecvPacket) { \
  245. DBGPRINT(NDIS, ("Couldn't grow packets allocated...\r\n")); \
  246. (*_Status) = NDIS_STATUS_RESOURCES; \
  247. } \
  248. } \
  249. }
  250. #define SpxFreeSendPacket(_Device,_Packet) \
  251. { \
  252. DBGPRINT(NDIS \
  253. ("SpxFreeSendPacket\n")); \
  254. SpxFreePacket(_Device, _Packet); \
  255. } \
  256. #define SpxFreeRecvPacket(_Device,_Packet) \
  257. { \
  258. DBGPRINT(NDIS \
  259. ("SpxFreeRecvPacket\n")); \
  260. SpxFreePacket(_Device, _Packet); \
  261. } \
  262. #define SpxReInitSendPacket(_Packet) \
  263. { \
  264. DBGPRINT(NDIS \
  265. ("SpxReInitSendPacket\n")); \
  266. } \
  267. #define SpxReInitRecvPacket(_Packet) \
  268. { \
  269. DBGPRINT(NDIS, \
  270. ("SpxReInitRecvPacket\n")); \
  271. }
  272. \
  273. #endif
  274. #if !defined SPX_OWN_PACKETS
  275. #define SEND_RESD(_Packet) ((PSPX_SEND_RESD)((_Packet)->ProtocolReserved))
  276. #define RECV_RESD(_Packet) ((PSPX_RECV_RESD)((_Packet)->ProtocolReserved))
  277. #else
  278. #define SpxAllocSendPacket(_Device, _SendPacket, _Status) \
  279. { \
  280. if (*(_SendPacket) = SpxBPAllocBlock(BLKID_NDISSEND)) \
  281. *(_Status) = NDIS_STATUS_SUCCESS; \
  282. else \
  283. *(_Status) = NDIS_STATUS_RESOURCES; \
  284. }
  285. #define SpxAllocRecvPacket(_Device,_RecvPacket,_Status) \
  286. { \
  287. if (*(_RecvPacket) = SpxBPAllocBlock(BLKID_NDISRECV)) \
  288. *(_Status) = NDIS_STATUS_SUCCESS; \
  289. else \
  290. *(_Status) = NDIS_STATUS_RESOURCES; \
  291. }
  292. #define SpxFreeSendPacket(_Device,_Packet) \
  293. { \
  294. SpxBPFreeBlock(_Packet, BLKID_NDISSEND); \
  295. }
  296. #define SpxFreeRecvPacket(_Device,_Packet) \
  297. { \
  298. SpxBPFreeBlock(_Packet, BLKID_NDISRECV); \
  299. }
  300. #define SpxReInitSendPacket(_Packet) \
  301. { \
  302. }
  303. #define SpxReInitRecvPacket(_Packet) \
  304. { \
  305. }
  306. #define SEND_RESD(_Packet) ((PSPX_SEND_RESD)((_Packet)->ProtocolReserved))
  307. #define RECV_RESD(_Packet) ((PSPX_RECV_RESD)((_Packet)->ProtocolReserved))
  308. #endif
  309. #if !defined SPX_OWN_PACKETS
  310. //
  311. // If we DO NOT use SPX_OWN_PACKETS, we would rather make it a function call
  312. //
  313. PNDIS_PACKET
  314. SpxAllocSendPacket(
  315. IN PDEVICE _Device,
  316. OUT PNDIS_PACKET *_SendPacket,
  317. OUT PNDIS_STATUS _Status
  318. );
  319. PNDIS_PACKET
  320. SpxAllocRecvPacket(
  321. IN PDEVICE _Device,
  322. OUT PNDIS_PACKET *_SendPacket,
  323. OUT PNDIS_STATUS _Status
  324. );
  325. void
  326. SpxFreeSendPacket(
  327. PDEVICE _Device,
  328. PNDIS_PACKET _Packet
  329. );
  330. void
  331. SpxFreeRecvPacket(
  332. PDEVICE _Device,
  333. PNDIS_PACKET _Packet
  334. );
  335. void
  336. SpxReInitSendPacket(
  337. PNDIS_PACKET _Packet
  338. );
  339. void
  340. SpxReInitRecvPacket(
  341. PNDIS_PACKET _Packet
  342. );
  343. #endif // SPX_OWN_PACKETS
  344. //
  345. // Routine Prototypes
  346. //
  347. VOID
  348. SpxPktBuildCr(
  349. IN struct _SPX_CONN_FILE * pSpxConnFile,
  350. IN struct _SPX_ADDR * pSpxAddr,
  351. OUT PNDIS_PACKET * ppPkt,
  352. IN USHORT State,
  353. IN BOOLEAN fSpx2);
  354. VOID
  355. SpxPktBuildCrAck(
  356. IN struct _SPX_CONN_FILE * pSpxConnFile,
  357. IN struct _SPX_ADDR * pSpxAddr,
  358. OUT PNDIS_PACKET * ppPkt,
  359. IN USHORT State,
  360. IN BOOLEAN fNeg,
  361. IN BOOLEAN fSpx2);
  362. VOID
  363. SpxPktBuildSn(
  364. IN struct _SPX_CONN_FILE * pSpxConnFile,
  365. OUT PNDIS_PACKET * ppPkt,
  366. IN USHORT State);
  367. VOID
  368. SpxPktBuildSs(
  369. IN struct _SPX_CONN_FILE * pSpxConnFile,
  370. OUT PNDIS_PACKET * ppPkt,
  371. IN USHORT State);
  372. VOID
  373. SpxPktBuildSsAck(
  374. IN struct _SPX_CONN_FILE * pSpxConnFile,
  375. OUT PNDIS_PACKET * ppPkt,
  376. IN USHORT State);
  377. VOID
  378. SpxPktBuildSnAck(
  379. IN struct _SPX_CONN_FILE * pSpxConnFile,
  380. OUT PNDIS_PACKET * ppPkt,
  381. IN USHORT State);
  382. VOID
  383. SpxPktBuildRr(
  384. IN struct _SPX_CONN_FILE * pSpxConnFile,
  385. OUT PNDIS_PACKET * ppPkt,
  386. IN USHORT SeqNum,
  387. IN USHORT State);
  388. VOID
  389. SpxPktBuildRrAck(
  390. IN struct _SPX_CONN_FILE * pSpxConnFile,
  391. OUT PNDIS_PACKET * ppPkt,
  392. IN USHORT State,
  393. IN USHORT MaxPktSize);
  394. VOID
  395. SpxPktBuildProbe(
  396. IN struct _SPX_CONN_FILE * pSpxConnFile,
  397. OUT PNDIS_PACKET * ppPkt,
  398. IN USHORT State,
  399. IN BOOLEAN fSpx2);
  400. VOID
  401. SpxPktBuildData(
  402. IN struct _SPX_CONN_FILE * pSpxConnFile,
  403. OUT PNDIS_PACKET * ppPkt,
  404. IN USHORT State,
  405. IN USHORT Length);
  406. VOID
  407. SpxCopyBufferChain(
  408. OUT PNDIS_STATUS Status,
  409. OUT PNDIS_BUFFER * TargetChain,
  410. IN NDIS_HANDLE PoolHandle,
  411. IN PNDIS_BUFFER SourceChain,
  412. IN UINT Offset,
  413. IN UINT Length
  414. );
  415. VOID
  416. SpxPktBuildAck(
  417. IN struct _SPX_CONN_FILE * pSpxConnFile,
  418. OUT PNDIS_PACKET * ppPkt,
  419. IN USHORT State,
  420. IN BOOLEAN fBuildNack,
  421. IN USHORT NumToResend);
  422. VOID
  423. SpxPktBuildDisc(
  424. IN struct _SPX_CONN_FILE * pSpxConnFile,
  425. IN PREQUEST pRequest,
  426. OUT PNDIS_PACKET * ppPkt,
  427. IN USHORT State,
  428. IN UCHAR DataType);
  429. VOID
  430. SpxPktRecvRelease(
  431. IN PNDIS_PACKET pPkt);
  432. VOID
  433. SpxPktSendRelease(
  434. IN PNDIS_PACKET pPkt);