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.

983 lines
27 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. atkndis.h
  5. Abstract:
  6. This module contains the ndis init/deint and protocol-support
  7. for ndis definitions.
  8. Author:
  9. Jameel Hyder (jameelh@microsoft.com)
  10. Nikhil Kamkolkar (nikhilk@microsoft.com)
  11. Revision History:
  12. 19 Jun 1992 Initial Version
  13. Notes: Tab stop: 4
  14. --*/
  15. #ifndef _ATKNDIS_
  16. #define _ATKNDIS_
  17. // This is the name that will be used in NdisRegisterProtocol. This has to match the
  18. // registry section for PnP to work !!!
  19. #define PROTOCOL_REGISTER_NAME L"Appletalk"
  20. // NDIS Version (4.0)
  21. #define PROTOCOL_MAJORNDIS_VERSION 4
  22. #define PROTOCOL_MINORNDIS_VERSION 0
  23. // IEEE802.2 Definitions
  24. // Offsets within the Extended 802.2 header:
  25. #define IEEE8022_DSAP_OFFSET 0
  26. #define IEEE8022_SSAP_OFFSET 1
  27. #define IEEE8022_CONTROL_OFFSET 2
  28. #define IEEE8022_PROTO_OFFSET 3
  29. // 808.2 header length: DSAP, SSAP, UI, and PID (protocol ID).
  30. #define IEEE8022_HDR_LEN 8
  31. // Values for SSAP and DSAP (the SNAP SAP) indicating 802.2 Extended.
  32. #define SNAP_SAP ((BYTE)0xAA)
  33. #define SNAP_SAP_FINAL ((BYTE)0xAB)
  34. // Value for Control Field:
  35. #define UNNUMBERED_INFO 0x03
  36. #define UNNUMBERED_FORMAT 0xF3
  37. // Length of 802.2 SNAP protocol discriminators.
  38. #define IEEE8022_PROTO_TYPE_LEN 5
  39. // The MAX_OPTHDR_LEN should be such that it holds the maximum header following
  40. // the ddp header from the upper layers (ADSP 13/ATP 8) and also it should allow a
  41. // full aarp packet to be held in the buffer when including the DDP header buffer.
  42. // i.e. 28. Ddp long header is 13. So the max works out to 15.
  43. #define MAX_OPTHDR_LEN 15
  44. // AARP hardware types:
  45. #define AARP_ELAP_HW_TYPE 1
  46. #define AARP_TLAP_HW_TYPE 2
  47. // Packet sizes.
  48. #define AARP_MAX_DATA_SIZE 38 // Var fields... Enet is max
  49. #define AARP_MIN_DATA_SIZE 28
  50. #define AARP_MAX_PKT_SIZE (IEEE8022_HDR_LEN + AARP_MAX_DATA_SIZE)
  51. #define AARPLINK_MAX_PKT_SIZE AARP_MAX_PKT_SIZE
  52. #define AARP_ATALK_PROTO_TYPE 0x809B
  53. #define NUM_PACKET_DESCRIPTORS 300
  54. #define NUM_BUFFER_DESCRIPTORS 600
  55. #define ROUTING_FACTOR 4
  56. // ETHERNET
  57. #define ELAP_MIN_PKT_LEN 60
  58. #define ELAP_ADDR_LEN 6
  59. #define ELAP_DEST_OFFSET 0
  60. #define ELAP_SRC_OFFSET 6
  61. #define ELAP_LEN_OFFSET 12
  62. #define ELAP_8022_START_OFFSET 14
  63. #define ELAP_LINKHDR_LEN 14
  64. // Ethernet multicast address:
  65. #define ELAP_BROADCAST_ADDR_INIT \
  66. { 0x09, 0x00, 0x07, 0xFF, 0xFF, 0xFF }
  67. #define ELAP_ZONE_MULTICAST_ADDRS 253
  68. #define ELAP_NUM_INIT_AARP_BUFFERS 10
  69. #define AtalkNdisFreeBuffer(_ndisBuffer) \
  70. { \
  71. PNDIS_BUFFER _ThisBuffer, _NextBuffer; \
  72. \
  73. _ThisBuffer = _ndisBuffer; \
  74. while (_ThisBuffer) \
  75. { \
  76. _NextBuffer = _ThisBuffer->Next; \
  77. _ThisBuffer->Next = NULL; \
  78. NdisFreeBuffer(_ThisBuffer); \
  79. ATALK_DBG_DEC_COUNT(AtalkDbgMdlsAlloced);\
  80. _ThisBuffer = _NextBuffer; \
  81. } \
  82. }
  83. // Values that are global to ndis routines
  84. // These are the media the stack will support
  85. extern NDIS_MEDIUM AtalkSupportedMedia[];
  86. extern ULONG AtalkSupportedMediaSize;
  87. extern NDIS_HANDLE AtalkNdisProtocolHandle;
  88. extern BYTE AtalkElapBroadcastAddr[ELAP_ADDR_LEN];
  89. extern BYTE AtalkAlapBroadcastAddr[];
  90. extern BYTE AtalkAarpProtocolType[IEEE8022_PROTO_TYPE_LEN];
  91. extern BYTE AtalkAppletalkProtocolType[IEEE8022_PROTO_TYPE_LEN];
  92. extern ATALK_NETWORKRANGE AtalkStartupNetworkRange;
  93. #define ELAP_MCAST_HDR_LEN (ELAP_ADDR_LEN - 1)
  94. extern BYTE AtalkEthernetZoneMulticastAddrsHdr[ELAP_MCAST_HDR_LEN];
  95. extern BYTE AtalkEthernetZoneMulticastAddrs[ELAP_ZONE_MULTICAST_ADDRS];
  96. // TOKENRING
  97. #define TLAP_ADDR_LEN 6
  98. // For the following offsets we assume that a TokenRing packet as handed to
  99. // us will be complete EXCEPT for the "non-data" portions: Starting Delimiter
  100. // (SD), Frame Check Sequence (FCS), End of Frame Sequence (EFS), and Ending
  101. // Delimiter (ED).
  102. #define TLAP_ACCESS_CTRL_OFFSET 0
  103. #define TLAP_FRAME_CTRL_OFFSET 1
  104. #define TLAP_DEST_OFFSET 2
  105. #define TLAP_SRC_OFFSET 8
  106. #define TLAP_ROUTE_INFO_OFFSET 14
  107. // A few "magic" values:
  108. #define TLAP_ACCESS_CTRL_VALUE 0x00 // Priority zero frame.
  109. #define TLAP_FRAME_CTRL_VALUE 0x40 // LLC frame, priority zero.
  110. #define TLAP_SRC_ROUTING_MASK 0x80 // In first byte of source
  111. // address.
  112. // Token ring source routing info stuff:
  113. #define TLAP_ROUTE_INFO_SIZE_MASK 0x1F // In first byte of routing
  114. // info, if present.
  115. #define TLAP_MIN_ROUTING_BYTES 2
  116. #define TLAP_MAX_ROUTING_BYTES MAX_ROUTING_BYTES
  117. #define TLAP_MAX_ROUTING_SPACE MAX_ROUTING_SPACE
  118. // Previously defined in ports.h
  119. #define TLAP_BROADCAST_INFO_MASK 0xE0 // In first byte of routing
  120. // info.
  121. #define TLAP_NON_BROADCAST_MASK 0x1F // To reset above bits.
  122. #define TLAP_DIRECTION_MASK 0x80 // In second byte of routing
  123. // info.
  124. #define TLAP_MIN_LINKHDR_LEN TLAP_ROUTE_INFO_OFFSET
  125. #define TLAP_MAX_LINKHDR_LEN (TLAP_ROUTE_INFO_OFFSET + MAX_ROUTING_SPACE)
  126. #define TLAP_BROADCAST_DEST_LEN 2
  127. // TokenRing multicast address:
  128. #define TLAP_BROADCAST_ADDR_INIT { 0xC0, 0x00, 0x40, 0x00, 0x00, 0x00 }
  129. #define TLAP_ZONE_MULTICAST_ADDRS 19
  130. #define TLAP_NUM_INIT_AARP_BUFFERS 6
  131. #define TLAP_MCAST_HDR_LEN 2
  132. extern BYTE AtalkTokenRingZoneMulticastAddrsHdr[TLAP_MCAST_HDR_LEN];
  133. extern BYTE AtalkTokenRingZoneMulticastAddrs[TLAP_ZONE_MULTICAST_ADDRS]
  134. [TLAP_ADDR_LEN - TLAP_MCAST_HDR_LEN];
  135. extern BYTE AtalkTlapBroadcastAddr[TLAP_ADDR_LEN];
  136. extern BYTE AtalkBroadcastRouteInfo[TLAP_MIN_ROUTING_BYTES];
  137. extern BYTE AtalkSimpleRouteInfo[TLAP_MIN_ROUTING_BYTES];
  138. extern BYTE AtalkBroadcastDestHdr[TLAP_BROADCAST_DEST_LEN];
  139. // FDDI
  140. #define FDDI_HEADER_BYTE 0x57 // Highest priority
  141. #define MIN_FDDI_PKT_LEN 53 // From emperical data
  142. #define FDDI_ADDR_LEN 6
  143. #define FDDI_DEST_OFFSET 1
  144. #define FDDI_SRC_OFFSET 7
  145. #define FDDI_802DOT2_START_OFFSET 13
  146. #define FDDI_LINKHDR_LEN 13
  147. #define FDDI_NUM_INIT_AARP_BUFFERS 10
  148. // LOCALTALK
  149. #define ALAP_DEST_OFFSET 0
  150. #define ALAP_SRC_OFFSET 1
  151. #define ALAP_TYPE_OFFSET 2
  152. #define ALAP_LINKHDR_LEN 3 // src, dest, lap type
  153. #define ALAP_SDDP_HDR_TYPE 1
  154. #define ALAP_LDDP_HDR_TYPE 2
  155. #define ALAP_NUM_INIT_AARP_BUFFERS 0
  156. // WAN
  157. #define WAN_LINKHDR_LEN 14
  158. // For send buffers, define a max. linkhdr len which is max of ELAP, TLAP, FDDI & ALAP
  159. #define MAX_LINKHDR_LEN (IEEE8022_HDR_LEN + TLAP_MAX_LINKHDR_LEN)
  160. #define MAX_SENDBUF_LEN (MAX_OPTHDR_LEN + MAX_LINKHDR_LEN + LDDP_HDR_LEN)
  161. //
  162. // 14 for "fake" ethernet hdr, 5 (worst case, with non-optimized phase) for
  163. // MNP LT hdr, 5 for Start,Stop flags)
  164. //
  165. #define MNP_MINSEND_LEN (MNP_MINPKT_SIZE + WAN_LINKHDR_LEN + 5 + 5 + 40)
  166. #define MNP_MAXSEND_LEN (MNP_MAXPKT_SIZE + WAN_LINKHDR_LEN + 5 + 5 + 40)
  167. // Localtalk broadcast address: (only the first byte - 0xFF)
  168. #define ALAP_BROADCAST_ADDR_INIT \
  169. { 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00 }
  170. // there is no broadcast addr for Arap: just put 0's
  171. #define ARAP_BROADCAST_ADDR_INIT \
  172. { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
  173. // Completion routine type for ndis requests
  174. typedef struct _SEND_COMPL_INFO
  175. {
  176. TRANSMIT_COMPLETION sc_TransmitCompletion;
  177. PVOID sc_Ctx1;
  178. PVOID sc_Ctx2;
  179. PVOID sc_Ctx3;
  180. } SEND_COMPL_INFO, *PSEND_COMPL_INFO;
  181. typedef VOID (*SEND_COMPLETION)(
  182. NDIS_STATUS Status,
  183. PBUFFER_DESC BufferChain,
  184. PSEND_COMPL_INFO SendInfo OPTIONAL
  185. );
  186. // For incoming packets:
  187. // The structure of our ddp packets will be
  188. // +-------+
  189. // |Header |
  190. //Returned->+-------+
  191. //Ptr | DDP |
  192. // | HDR |
  193. // | DATA |
  194. // | AARP |
  195. // | DATA |
  196. // +-------+
  197. //
  198. // The link header is stored in the ndis packet descriptor.
  199. //
  200. typedef struct _BUFFER_HDR
  201. {
  202. PNDIS_PACKET bh_NdisPkt;
  203. PNDIS_BUFFER bh_NdisBuffer;
  204. } BUFFER_HDR, *PBUFFER_HDR;
  205. typedef struct _AARP_BUFFER
  206. {
  207. BUFFER_HDR ab_Hdr;
  208. BYTE ab_Data[AARP_MAX_DATA_SIZE];
  209. } AARP_BUFFER, *PAARP_BUFFER;
  210. typedef struct _DDP_SMBUFFER
  211. {
  212. BUFFER_HDR dsm_Hdr;
  213. BYTE dsm_Data[LDDP_HDR_LEN +
  214. 8 + // ATP header size
  215. 64]; // ASP Data size (Average)
  216. } DDP_SMBUFFER, *PDDP_SMBUFFER;
  217. typedef struct _DDP_LGBUFFER
  218. {
  219. BUFFER_HDR dlg_Hdr;
  220. BYTE dlg_Data[MAX_LDDP_PKT_SIZE];
  221. } DDP_LGBUFFER, *PDDP_LGBUFFER;
  222. // BUFFERING for sends
  223. // For outgoing packets, we preallocate buffer headers with buffer descriptors
  224. // following it, and the link/ddp/max opt hdr len memory following it.
  225. // +-------+
  226. // |Header |
  227. // +-------+
  228. // |BuffDes|
  229. // +-------+
  230. // |MAXLINK|
  231. // +-------+
  232. // |MAX DDP|
  233. // +-------+
  234. // |MAX OPT|
  235. // +-------+
  236. //
  237. // The header will contain a ndis buffer descriptor which will describe the
  238. // MAXLINK/MAXDDP/MAXOPT area. Set the size before sending. And reset when
  239. // Freeing. The next pointer in the buffer descriptor is used for chaining in
  240. // free list.
  241. //
  242. // NOTE: Since for receives, we store the link header in the packet descriptor,
  243. // the question arises, why not for sends? Because we want to use just one
  244. // ndis buffer descriptor to describe all the non-data part.
  245. //
  246. // !!!!IMPORTANT!!!!
  247. // The buffer descriptor header is accessed by going back from the buffer descriptor
  248. // pointer, so its important that the buffer descriptor header start from an
  249. // aligned address, i.e. make sure the structure does not contain elements that
  250. // could throw it out of alignment.
  251. typedef struct _SENDBUF
  252. {
  253. // NOTE: BUFFER_HDR must be the first thing. Look at AtalkBPAllocBlock();
  254. BUFFER_HDR sb_BuffHdr;
  255. BUFFER_DESC sb_BuffDesc;
  256. BYTE sb_Space[MAX_SENDBUF_LEN];
  257. } SENDBUF, *PSENDBUF;
  258. //
  259. // !!!!IMPORTANT!!!!
  260. // This structure needs to stay aligned (i.e. Buffer[1] field MUST start on an
  261. // aligned addr! If necessary, add a padding!)
  262. //
  263. typedef struct _MNPSENDBUF
  264. {
  265. // NOTE: BUFFER_HDR must be the first thing. Look at AtalkBPAllocBlock();
  266. BUFFER_HDR sb_BuffHdr;
  267. BUFFER_DESC sb_BuffDesc;
  268. LIST_ENTRY Linkage; // to queue in ArapRetransmitQ
  269. #if DBG
  270. DWORD Signature;
  271. #endif
  272. LONG RetryTime; // at this time, we will retransmit this send
  273. PARAPCONN pArapConn; // who owns this send
  274. PARAP_SEND_COMPLETION ComplRoutine; // routine to call when this send completes
  275. LONG TimeAlloced; // time the first send came in on this buf
  276. USHORT DataSize; // how much of the buffer is data
  277. USHORT BytesFree; // can we stuff more packet(s)?
  278. // NOTE: (Remember: Buffer[1] must start on DWORD boundary) see if we can make Flags a byte
  279. DWORD Flags;
  280. BYTE SeqNum; // sequence number used for this send
  281. BYTE RetryCount; // how many times we have retransmitted this
  282. BYTE RefCount; // free this buffer when refcount goes to 0
  283. BYTE NumSends; // how many sends do we have stuffed here
  284. PBYTE FreeBuffer; // pointer to free space
  285. BYTE Buffer[1];
  286. } MNPSENDBUF, *PMNPSENDBUF;
  287. typedef struct _ARAPBUF
  288. {
  289. LIST_ENTRY Linkage; // to queue in ReceiveQ
  290. #if DBG
  291. DWORD Signature;
  292. #endif
  293. BYTE MnpFrameType; // type of frame this is (LT, LN etc.)
  294. BYTE BlockId; // what kind of buffer is this
  295. USHORT BufferSize; // how big is the buffer (set at init only)
  296. USHORT DataSize; // how many bytes are valid (possible >1 srp)
  297. PBYTE CurrentBuffer; // where does data begin...
  298. BYTE Buffer[1]; // the buffer (with v42bis compressed pkt)
  299. } ARAPBUF, *PARAPBUF;
  300. #define ARAPCONN_SIGNATURE 0x99999999
  301. #define ATCPCONN_SIGNATURE 0x88888888
  302. #define MNPSMSENDBUF_SIGNATURE 0xbeef1111
  303. #define MNPLGSENDBUF_SIGNATURE 0xbeef8888
  304. #define ARAPSMPKT_SIGNATURE 0xcafe2222
  305. #define ARAPMDPKT_SIGNATURE 0xcafe3333
  306. #define ARAPLGPKT_SIGNATURE 0xcafe4444
  307. #define ARAPLGBUF_SIGNATURE 0xdeebacad
  308. #define ARAPUNLMTD_SIGNATURE 0xfafababa
  309. // PROTOCOL RESERVED Structure
  310. // This is what we expect to be in the packet descriptor. And we use it
  311. // to store information to be used during the completion of the send/
  312. // receives.
  313. typedef struct
  314. {
  315. // !!!WARNING!!!
  316. // pr_Linkage must be the first element in this structure for the
  317. // CONTAINING_RECORD macro to work in receive completion.
  318. union
  319. {
  320. struct
  321. {
  322. PPORT_DESCRIPTOR pr_Port;
  323. PBUFFER_DESC pr_BufferDesc;
  324. SEND_COMPLETION pr_SendCompletion;
  325. SEND_COMPL_INFO pr_SendInfo;
  326. } Send;
  327. struct
  328. {
  329. LIST_ENTRY pr_Linkage;
  330. PPORT_DESCRIPTOR pr_Port;
  331. LOGICAL_PROTOCOL pr_Protocol;
  332. NDIS_STATUS pr_ReceiveStatus;
  333. PBUFFER_HDR pr_BufHdr;
  334. BYTE pr_LinkHdr[TLAP_MAX_LINKHDR_LEN];
  335. USHORT pr_DataLength;
  336. BOOLEAN pr_Processed;
  337. BYTE pr_OptimizeType;
  338. BYTE pr_OptimizeSubType;
  339. PVOID pr_OptimizeCtx;
  340. ATALK_ADDR pr_SrcAddr;
  341. ATALK_ADDR pr_DestAddr;
  342. BOOLEAN pr_OffCablePkt;
  343. union
  344. {
  345. // ATP Structure
  346. struct
  347. {
  348. BYTE pr_AtpHdr[8]; // ATP header size
  349. struct _ATP_ADDROBJ * pr_AtpAddrObj;
  350. };
  351. // ADSP Structure
  352. };
  353. } Receive;
  354. };
  355. } PROTOCOL_RESD, *PPROTOCOL_RESD;
  356. // ATALK NDIS REQUEST
  357. // Used to store completion routine information for NDIS requests.
  358. typedef struct _ATALK_NDIS_REQ
  359. {
  360. NDIS_REQUEST nr_Request;
  361. REQ_COMPLETION nr_RequestCompletion;
  362. PVOID nr_Ctx;
  363. KEVENT nr_Event;
  364. NDIS_STATUS nr_RequestStatus;
  365. BOOLEAN nr_Sync;
  366. } ATALK_NDIS_REQ, *PATALK_NDIS_REQ;
  367. #define GET_PORT_TYPE(medium) \
  368. ((medium == NdisMedium802_3) ? ELAP_PORT :\
  369. ((medium == NdisMediumFddi) ? FDDI_PORT :\
  370. ((medium == NdisMedium802_5) ? TLAP_PORT :\
  371. ((medium == NdisMediumLocalTalk) ? ALAP_PORT : \
  372. ((medium == NdisMediumWan) ? ARAP_PORT : \
  373. 0)))))
  374. // Handlers for the different port types.
  375. typedef struct _PORT_HANDLERS
  376. {
  377. ADDMULTICASTADDR ph_AddMulticastAddr;
  378. REMOVEMULTICASTADDR ph_RemoveMulticastAddr;
  379. BYTE ph_BroadcastAddr[MAX_HW_ADDR_LEN];
  380. USHORT ph_BroadcastAddrLen;
  381. USHORT ph_AarpHardwareType;
  382. USHORT ph_AarpProtocolType;
  383. } PORT_HANDLERS, *PPORT_HANDLERS;
  384. typedef enum
  385. {
  386. AT_PNP_SWITCH_ROUTING=0,
  387. AT_PNP_SWITCH_DEFAULT_ADAPTER,
  388. AT_PNP_RECONFIGURE_PARMS
  389. } ATALK_PNP_MSGTYPE;
  390. typedef struct _ATALK_PNP_EVENT
  391. {
  392. ATALK_PNP_MSGTYPE PnpMessage;
  393. } ATALK_PNP_EVENT, *PATALK_PNP_EVENT;
  394. // MACROS for building/verifying 802.2 headers
  395. #define ATALK_VERIFY8022_HDR(pPkt, PktLen, Protocol, Result) \
  396. { \
  397. Result = TRUE; \
  398. if ((PktLen >= (IEEE8022_PROTO_OFFSET+IEEE8022_PROTO_TYPE_LEN)) && \
  399. (*(pPkt + IEEE8022_DSAP_OFFSET) == SNAP_SAP) && \
  400. (*(pPkt + IEEE8022_SSAP_OFFSET) == SNAP_SAP) && \
  401. (*(pPkt + IEEE8022_CONTROL_OFFSET)== UNNUMBERED_INFO)) \
  402. { \
  403. if (!memcmp(pPkt + IEEE8022_PROTO_OFFSET, \
  404. AtalkAppletalkProtocolType, \
  405. IEEE8022_PROTO_TYPE_LEN)) \
  406. { \
  407. Protocol = APPLETALK_PROTOCOL; \
  408. } \
  409. else if (!memcmp(pPkt + IEEE8022_PROTO_OFFSET, \
  410. AtalkAarpProtocolType, \
  411. IEEE8022_PROTO_TYPE_LEN)) \
  412. { \
  413. Protocol = AARP_PROTOCOL; \
  414. } \
  415. else \
  416. { \
  417. Result = FALSE; \
  418. } \
  419. } \
  420. else \
  421. { \
  422. Result = FALSE; \
  423. } \
  424. }
  425. #define ATALK_BUILD8022_HDR(Packet, Protocol) \
  426. { \
  427. PUTBYTE2BYTE( \
  428. Packet + IEEE8022_DSAP_OFFSET, \
  429. SNAP_SAP); \
  430. \
  431. PUTBYTE2BYTE( \
  432. Packet + IEEE8022_SSAP_OFFSET, \
  433. SNAP_SAP); \
  434. \
  435. PUTBYTE2BYTE( \
  436. Packet + IEEE8022_CONTROL_OFFSET, \
  437. UNNUMBERED_INFO); \
  438. \
  439. RtlCopyMemory( \
  440. Packet + IEEE8022_PROTO_OFFSET, \
  441. ((Protocol == APPLETALK_PROTOCOL) ? \
  442. AtalkAppletalkProtocolType : AtalkAarpProtocolType), \
  443. IEEE8022_PROTO_TYPE_LEN); \
  444. }
  445. // Allocating and freeing send buffers
  446. #define AtalkNdisAllocBuf(_ppBuffDesc) \
  447. { \
  448. PSENDBUF _pSendBuf; \
  449. \
  450. _pSendBuf = AtalkBPAllocBlock(BLKID_SENDBUF); \
  451. if ((_pSendBuf) != NULL) \
  452. { \
  453. *(_ppBuffDesc) = &(_pSendBuf)->sb_BuffDesc; \
  454. (_pSendBuf)->sb_BuffDesc.bd_Next = NULL; \
  455. (_pSendBuf)->sb_BuffDesc.bd_Length = MAX_SENDBUF_LEN; \
  456. (_pSendBuf)->sb_BuffDesc.bd_Flags = BD_CHAR_BUFFER; \
  457. (_pSendBuf)->sb_BuffDesc.bd_CharBuffer= (_pSendBuf)->sb_Space; \
  458. (_pSendBuf)->sb_BuffDesc.bd_FreeBuffer= NULL; \
  459. } \
  460. else \
  461. { \
  462. *(_ppBuffDesc) = NULL; \
  463. \
  464. DBGPRINT(DBG_COMP_NDISSEND, DBG_LEVEL_ERR, \
  465. ("AtalkNdisAllocBuf: AtalkBPAllocBlock failed\n")); \
  466. \
  467. LOG_ERROR(EVENT_ATALK_NDISRESOURCES, \
  468. NDIS_STATUS_RESOURCES, \
  469. NULL, \
  470. 0); \
  471. } \
  472. }
  473. #define AtalkNdisFreeBuf(_pBuffDesc) \
  474. { \
  475. PSENDBUF _pSendBuf; \
  476. \
  477. ASSERT(VALID_BUFFDESC(_pBuffDesc)); \
  478. _pSendBuf = (PSENDBUF)((PBYTE)(_pBuffDesc) - sizeof(BUFFER_HDR)); \
  479. NdisAdjustBufferLength( \
  480. (_pSendBuf)->sb_BuffHdr.bh_NdisBuffer, \
  481. MAX_SENDBUF_LEN); \
  482. AtalkBPFreeBlock((_pSendBuf)); \
  483. }
  484. #define ArapNdisFreeBuf(_pMnpSendBuf) \
  485. { \
  486. PBUFFER_DESC _pBufDes; \
  487. _pBufDes = &_pMnpSendBuf->sb_BuffDesc; \
  488. \
  489. DBGPRINT(DBG_COMP_RAS, DBG_LEVEL_INFO, \
  490. ("ArapNdisFreeBuf: freeing %lx NdisPkt=%lx\n", \
  491. _pMnpSendBuf,_pMnpSendBuf->sb_BuffHdr.bh_NdisPkt)); \
  492. \
  493. NdisAdjustBufferLength( \
  494. (_pMnpSendBuf)->sb_BuffHdr.bh_NdisBuffer, \
  495. (_pBufDes)->bd_Length); \
  496. \
  497. AtalkBPFreeBlock((_pMnpSendBuf)); \
  498. }
  499. // Exported Prototypes
  500. ATALK_ERROR
  501. AtalkInitNdisQueryAddrInfo(
  502. IN PPORT_DESCRIPTOR pPortDesc
  503. );
  504. ATALK_ERROR
  505. AtalkInitNdisStartPacketReception(
  506. IN PPORT_DESCRIPTOR pPortDesc
  507. );
  508. ATALK_ERROR
  509. AtalkInitNdisSetLookaheadSize(
  510. IN PPORT_DESCRIPTOR pPortDesc,
  511. IN INT LookaheadSize
  512. );
  513. ATALK_ERROR
  514. AtalkNdisReplaceMulticast(
  515. IN PPORT_DESCRIPTOR pPortDesc,
  516. IN PBYTE OldAddress,
  517. IN PBYTE NewAddress
  518. );
  519. ATALK_ERROR
  520. AtalkNdisAddMulticast(
  521. IN PPORT_DESCRIPTOR pPortDesc,
  522. IN PBYTE Address,
  523. IN BOOLEAN ExecuteSynchronously,
  524. IN REQ_COMPLETION AddCompletion,
  525. IN PVOID AddContext
  526. );
  527. ATALK_ERROR
  528. AtalkNdisRemoveMulticast(
  529. IN PPORT_DESCRIPTOR pPortDesc,
  530. IN PBYTE Address,
  531. IN BOOLEAN ExecuteSynchronously,
  532. IN REQ_COMPLETION RemoveCompletion,
  533. IN PVOID RemoveContext
  534. );
  535. ATALK_ERROR
  536. AtalkNdisSendPacket(
  537. IN PPORT_DESCRIPTOR pPortDesc,
  538. IN PBUFFER_DESC BufferChain,
  539. IN SEND_COMPLETION SendCompletion OPTIONAL,
  540. IN PSEND_COMPL_INFO pSendInfo OPTIONAL
  541. );
  542. ATALK_ERROR
  543. AtalkNdisAddFunctional(
  544. IN PPORT_DESCRIPTOR pPortDesc,
  545. IN PUCHAR Address,
  546. IN BOOLEAN ExecuteSynchronously,
  547. IN REQ_COMPLETION AddCompletion,
  548. IN PVOID AddContext
  549. );
  550. ATALK_ERROR
  551. AtalkNdisRemoveFunctional(
  552. IN PPORT_DESCRIPTOR pPortDesc,
  553. IN PUCHAR Address,
  554. IN BOOLEAN ExecuteSynchronously,
  555. IN REQ_COMPLETION RemoveCompletion,
  556. IN PVOID RemoveContext
  557. );
  558. USHORT
  559. AtalkNdisBuildEthHdr(
  560. IN PUCHAR PortAddr, // 802 address of port
  561. IN PBYTE pLinkHdr, // Start of link header
  562. IN PBYTE pDestHwOrMcastAddr, // Destination or multicast addr
  563. IN LOGICAL_PROTOCOL Protocol, // Logical protocol
  564. IN USHORT ActualDataLen // Length for ethernet packets
  565. );
  566. USHORT
  567. AtalkNdisBuildTRHdr(
  568. IN PUCHAR PortAddr, // 802 address of port
  569. IN PBYTE pLinkHdr, // Start of link header
  570. IN PBYTE pDestHwOrMcastAddr, // Destination or multicast addr
  571. IN LOGICAL_PROTOCOL Protocol, // Logical protocol
  572. IN PBYTE pRouteInfo, // Routing info for tokenring
  573. IN USHORT RouteInfoLen // Length of above
  574. );
  575. USHORT
  576. AtalkNdisBuildFDDIHdr(
  577. IN PUCHAR PortAddr, // 802 address of port
  578. IN PBYTE pLinkHdr, // Start of link header
  579. IN PBYTE pDestHwOrMcastAddr, // Destination or multicast addr
  580. IN LOGICAL_PROTOCOL Protocol // Logical protocol
  581. );
  582. USHORT
  583. AtalkNdisBuildLTHdr(
  584. IN PBYTE pLinkHdr, // Start of link header
  585. IN PBYTE pDestHwOrMcastAddr, // Destination or multicast addr
  586. IN BYTE AlapSrc, // Localtalk source node
  587. IN BYTE AlapType // Localtalk ddp header type
  588. );
  589. #define AtalkNdisBuildARAPHdr(_pLnkHdr, _pConn) \
  590. RtlCopyMemory(_pLnkHdr, _pConn->NdiswanHeader, WAN_LINKHDR_LEN)
  591. #define AtalkNdisBuildPPPPHdr(_pLnkHdr, _pConn) \
  592. RtlCopyMemory(_pLnkHdr, _pConn->NdiswanHeader, WAN_LINKHDR_LEN)
  593. #define AtalkNdisBuildHdr(pPortDesc, \
  594. pLinkHdr, \
  595. linkLen, \
  596. ActualDataLen, \
  597. pDestHwOrMcastAddr, \
  598. pRouteInfo, \
  599. RouteInfoLen, \
  600. Protocol) \
  601. { \
  602. switch (pPortDesc->pd_NdisPortType) \
  603. { \
  604. case NdisMedium802_3: \
  605. linkLen = AtalkNdisBuildEthHdr( \
  606. (pPortDesc)->pd_PortAddr, \
  607. pLinkHdr, \
  608. pDestHwOrMcastAddr, \
  609. Protocol, \
  610. ActualDataLen); \
  611. break; \
  612. \
  613. case NdisMedium802_5: \
  614. linkLen = AtalkNdisBuildTRHdr( \
  615. (pPortDesc)->pd_PortAddr, \
  616. pLinkHdr, \
  617. pDestHwOrMcastAddr, \
  618. Protocol, \
  619. pRouteInfo, \
  620. RouteInfoLen); \
  621. break; \
  622. \
  623. case NdisMediumFddi: \
  624. linkLen = AtalkNdisBuildFDDIHdr( \
  625. (pPortDesc)->pd_PortAddr, \
  626. pLinkHdr, \
  627. pDestHwOrMcastAddr, \
  628. Protocol); \
  629. break; \
  630. \
  631. case NdisMediumLocalTalk: \
  632. ASSERTMSG("AtalkNdisBuildHdr called for LT\n", 0); \
  633. break; \
  634. \
  635. default: \
  636. ASSERT (0); \
  637. KeBugCheck(0); \
  638. break; \
  639. } \
  640. }
  641. VOID
  642. AtalkNdisSendTokRingTestRespComplete(
  643. IN NDIS_STATUS Status,
  644. IN PBUFFER_DESC pBuffDesc,
  645. IN PSEND_COMPL_INFO pInfo OPTIONAL);
  646. VOID
  647. AtalkNdisSendTokRingTestResp(
  648. IN PPORT_DESCRIPTOR pPortDesc,
  649. IN PBYTE HdrBuf,
  650. IN UINT HdrBufSize,
  651. IN PBYTE LkBuf,
  652. IN UINT LkBufSize,
  653. IN UINT pPktSize);
  654. // PORT HANDLERS
  655. //
  656. extern PORT_HANDLERS AtalkPortHandlers[LAST_PORTTYPE];
  657. // Exported Prototypes
  658. ATALK_ERROR
  659. AtalkNdisInitRegisterProtocol(
  660. VOID
  661. );
  662. VOID
  663. AtalkNdisDeregisterProtocol(
  664. VOID
  665. );
  666. VOID
  667. AtalkNdisReleaseResources(
  668. VOID
  669. );
  670. NDIS_STATUS
  671. AtalkNdisInitBind(
  672. IN PPORT_DESCRIPTOR pPortDesc
  673. );
  674. VOID
  675. AtalkNdisUnbind(
  676. IN PPORT_DESCRIPTOR pPortDesc
  677. );
  678. NDIS_STATUS
  679. AtalkNdisSubmitRequest(
  680. PPORT_DESCRIPTOR pPortDesc,
  681. PNDIS_REQUEST Request,
  682. BOOLEAN ExecuteSync,
  683. REQ_COMPLETION CompletionRoutine,
  684. PVOID Ctx
  685. );
  686. VOID
  687. AtalkOpenAdapterComplete(
  688. IN NDIS_HANDLE NdisBindCtx,
  689. IN NDIS_STATUS Status,
  690. IN NDIS_STATUS OpenErrorStatus
  691. );
  692. VOID
  693. AtalkCloseAdapterComplete(
  694. IN NDIS_HANDLE NdisBindCtx,
  695. IN NDIS_STATUS Status
  696. );
  697. VOID
  698. AtalkResetComplete(
  699. IN NDIS_HANDLE NdisBindCtx,
  700. IN NDIS_STATUS Status
  701. );
  702. VOID
  703. AtalkRequestComplete(
  704. IN NDIS_HANDLE NdisBindCtx,
  705. IN PNDIS_REQUEST NdisRequest,
  706. IN NDIS_STATUS Status
  707. );
  708. VOID
  709. AtalkStatusIndication (
  710. IN NDIS_HANDLE NdisBindCtx,
  711. IN NDIS_STATUS GeneralStatus,
  712. IN PVOID StatusBuf,
  713. IN UINT StatusBufLen
  714. );
  715. VOID
  716. AtalkStatusComplete (
  717. IN NDIS_HANDLE ProtoBindCtx
  718. );
  719. VOID
  720. AtalkReceiveComplete (
  721. IN NDIS_HANDLE BindingCtx
  722. );
  723. VOID
  724. AtalkTransferDataComplete(
  725. IN NDIS_HANDLE BindingCtx,
  726. IN PNDIS_PACKET NdisPkt,
  727. IN NDIS_STATUS Status,
  728. IN UINT BytesTransferred
  729. );
  730. NDIS_STATUS
  731. AtalkReceiveIndication(
  732. IN NDIS_HANDLE BindingCtx,
  733. IN NDIS_HANDLE ReceiveCtx,
  734. IN PVOID HdrBuf,
  735. IN UINT HdrBufSize,
  736. IN PVOID LkBuf,
  737. IN UINT LkBufSize,
  738. IN UINT PktSize
  739. );
  740. ATALK_ERROR
  741. ArapAdapterInit(
  742. IN OUT PPORT_DESCRIPTOR pPortDesc
  743. );
  744. VOID
  745. AtalkSendComplete(
  746. IN NDIS_HANDLE ProtoBindCtx,
  747. IN PNDIS_PACKET NdisPkt,
  748. IN NDIS_STATUS NdisStatus
  749. );
  750. VOID
  751. AtalkBindAdapter(
  752. OUT PNDIS_STATUS Status,
  753. IN NDIS_HANDLE BindContext,
  754. IN PNDIS_STRING DeviceName,
  755. IN PVOID SystemSpecific1,
  756. IN PVOID SystemSpecific2
  757. );
  758. VOID
  759. AtalkUnbindAdapter(
  760. OUT PNDIS_STATUS Status,
  761. IN NDIS_HANDLE ProtocolBindingContext,
  762. IN NDIS_HANDLE UnbindContext
  763. );
  764. NDIS_STATUS
  765. AtalkPnPHandler(
  766. IN NDIS_HANDLE NdisBindCtx,
  767. IN PNET_PNP_EVENT NetPnPEvent
  768. );
  769. NDIS_STATUS
  770. AtalkPnPReconfigure(
  771. IN NDIS_HANDLE NdisBindCtx,
  772. IN PNET_PNP_EVENT NetPnPEvent
  773. );
  774. NTSTATUS
  775. AtalkPnPDisableAdapter(
  776. IN PPORT_DESCRIPTOR pPortDesc
  777. );
  778. NTSTATUS
  779. AtalkPnPEnableAdapter(
  780. IN PPORT_DESCRIPTOR pPortDesc
  781. );
  782. PPORT_DESCRIPTOR
  783. AtalkFindDefaultPort(
  784. IN VOID
  785. );
  786. // Receive indication copy macro. This accomodates shared memory copies.
  787. #define ATALK_RECV_INDICATION_COPY(_pPortDesc, _pDest, _pSrc, _Len) \
  788. { \
  789. TdiCopyLookaheadData(_pDest, \
  790. _pSrc, \
  791. _Len, \
  792. ((_pPortDesc)->pd_MacOptions & NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA) ? \
  793. TDI_RECEIVE_COPY_LOOKAHEAD : 0); \
  794. }
  795. LOCAL NDIS_STATUS
  796. atalkNdisInitInitializeResources(
  797. VOID
  798. );
  799. #endif // _ATKNDIS_
  800.