|
|
1.1 ! root 1: /*++ ! 2: ! 3: Copyright (c) 1989-1993 Microsoft Corporation ! 4: ! 5: Module Name: ! 6: ! 7: stmac.h ! 8: ! 9: Abstract: ! 10: ! 11: This header file defines manifest constants and necessary macros for use ! 12: by transports dealing with multiple MAC cards through the NDIS interface. ! 13: ! 14: Revision History: ! 15: ! 16: --*/ ! 17: ! 18: #ifndef _STMAC_ ! 19: #define _STMAC_ ! 20: ! 21: // ! 22: // MAC-specific definitions, some of which get used below ! 23: // ! 24: ! 25: #define MAX_MAC_HEADER_LENGTH 32 ! 26: #define MAX_SOURCE_ROUTING 18 ! 27: #define MAX_DEFAULT_SR 2 ! 28: ! 29: #define ETHERNET_ADDRESS_LENGTH 6 ! 30: #define ETHERNET_PACKET_LENGTH 1514 // max size of an ethernet packet ! 31: #define ETHERNET_HEADER_LENGTH 14 // size of the ethernet MAC header ! 32: #define ETHERNET_DATA_LENGTH_OFFSET 12 ! 33: #define ETHERNET_DESTINATION_OFFSET 0 ! 34: #define ETHERNET_SOURCE_OFFSET 6 ! 35: ! 36: #define TR_ADDRESS_LENGTH 6 ! 37: #define TR_ADDRESS_OFFSET 2 ! 38: #define TR_SPECIFIC_OFFSET 0 ! 39: #define TR_PACKET_LENGTH 1514 // max size of a TR packet //BUGBUG ! 40: #define TR_HEADER_LENGTH 36 // size of the MAC header w/o source routing ! 41: #define TR_DATA_LENGTH_OFFSET 0 ! 42: #define TR_DESTINATION_OFFSET 2 ! 43: #define TR_SOURCE_OFFSET 8 ! 44: #define TR_ROUTING_OFFSET 14 // starts at the 14th byte ! 45: #define TR_GR_BCAST_LENGTH 2 ! 46: #define TR_GR_BROADCAST 0xC270 // what a general route b'cast looks like ! 47: #define TR_ROUTING_LENGTH_MASK 0x1F // low 5 bits in byte ! 48: #define TR_DIRECTION_MASK 0x80 // returns direction bit ! 49: ! 50: #define TR_PREAMBLE_AC 0x10 // how would these be specified? ! 51: #define TR_PREAMBLE_FC 0x40 ! 52: ! 53: #define TR_HEADER_BYTE_0 0x10 ! 54: #define TR_HEADER_BYTE_1 0x40 ! 55: ! 56: #define FDDI_ADDRESS_LENGTH 6 ! 57: #define FDDI_HEADER_BYTE 0x57 ! 58: ! 59: ! 60: ! 61: // ! 62: // We need this to define information about the MAC. Note that ! 63: // it is a strange structure in that the first four elements ! 64: // are for use internally by the stmac routines, while the ! 65: // DeviceContext knows about and uses the last two. ! 66: // ! 67: ! 68: typedef struct _ST_NDIS_IDENTIFICATION { ! 69: NDIS_MEDIUM MediumType; ! 70: BOOLEAN SourceRouting; ! 71: BOOLEAN MediumAsync; ! 72: BOOLEAN CopyLookahead; ! 73: ULONG DestinationOffset; ! 74: ULONG SourceOffset; ! 75: ULONG AddressLength; ! 76: ULONG MaxHeaderLength; ! 77: } ST_NDIS_IDENTIFICATION, *PST_NDIS_IDENTIFICATION; ! 78: ! 79: ! 80: ! 81: VOID ! 82: MacConstructHeader( ! 83: IN PST_NDIS_IDENTIFICATION MacInfo, ! 84: IN PUCHAR Buffer, ! 85: IN PUCHAR DestinationAddress, ! 86: IN PUCHAR SourceAddress, ! 87: IN UINT PacketLength, ! 88: IN PUCHAR SourceRouting, ! 89: IN UINT SourceRoutingLength, ! 90: OUT PUINT HeaderLength ! 91: ); ! 92: ! 93: VOID ! 94: MacReturnMaxDataSize( ! 95: IN PST_NDIS_IDENTIFICATION MacInfo, ! 96: IN PUCHAR SourceRouting, ! 97: IN UINT SourceRoutingLength, ! 98: IN UINT DeviceMaxFrameSize, ! 99: OUT PUINT MaxFrameSize ! 100: ); ! 101: ! 102: VOID ! 103: MacInitializeMacInfo( ! 104: IN NDIS_MEDIUM MacType, ! 105: OUT PST_NDIS_IDENTIFICATION MacInfo ! 106: ); ! 107: ! 108: ! 109: extern UCHAR SingleRouteSourceRouting[]; ! 110: extern UCHAR GeneralRouteSourceRouting[]; ! 111: extern ULONG DefaultSourceRoutingLength; ! 112: ! 113: ! 114: //++ ! 115: // ! 116: // VOID ! 117: // MacReturnDestinationAddress( ! 118: // IN PST_NDIS_IDENTIFICATION MacInfo, ! 119: // IN PVOID Packet, ! 120: // OUT PVOID * DestinationAddress ! 121: // ); ! 122: // ! 123: // Routine Description: ! 124: // ! 125: // Returns the a pointer to the destination address in the packet. ! 126: // ! 127: // Arguments: ! 128: // ! 129: // MacInfo - Describes the MAC we wish to decode. ! 130: // ! 131: // Packet - The packet data. ! 132: // ! 133: // DestinationAddress - Returns the start of the destination address. ! 134: // ! 135: // Return Value: ! 136: // ! 137: // None. ! 138: // ! 139: //-- ! 140: ! 141: #define MacReturnDestinationAddress(_MacInfo, _Packet, _DestinationAddress) \ ! 142: *(_DestinationAddress) = ((PUCHAR)(_Packet)) + (_MacInfo)->DestinationOffset ! 143: ! 144: ! 145: //++ ! 146: // ! 147: // VOID ! 148: // MacReturnSourceAddress( ! 149: // IN PST_NDIS_IDENTIFICATION MacInfo, ! 150: // IN PVOID Packet, ! 151: // OUT PHARDWARE_ADDRESS SourceAddressBuffer, ! 152: // OUT PHARDWARE_ADDRESS * SourceAddress, ! 153: // ); ! 154: // ! 155: // Routine Description: ! 156: // ! 157: // Copies the source address in the packet into SourceAddress. ! 158: // NOTE THAT IT MAY COPY THE DATA, UNLIKE ReturnDestinationAddress ! 159: // AND ReturnSourceRouting. Optionally, indicates whether the ! 160: // destination address is a multicast address. ! 161: // ! 162: // Arguments: ! 163: // ! 164: // MacInfo - Describes the MAC we wish to decode. ! 165: // ! 166: // Packet - The packet data. ! 167: // ! 168: // SourceAddressBuffer - A buffer to hold the source address, ! 169: // if needed. ! 170: // ! 171: // SourceAddress - Returns a pointer to the source address. ! 172: // ! 173: // Multicast - Optional pointer to a BOOLEAN to receive indication ! 174: // of whether the destination was a multicast address. ! 175: // ! 176: // Return Value: ! 177: // ! 178: // None. ! 179: // ! 180: //-- ! 181: ! 182: // ! 183: // NOTE: The default case below handles Ethernet and FDDI. ! 184: // ! 185: ! 186: #define MacReturnSourceAddress(_MacInfo, _Packet, _SourceAddressBuffer, _SourceAddress) \ ! 187: { \ ! 188: PUCHAR TmpPacket = (PUCHAR)(_Packet); \ ! 189: PUCHAR SrcBuffer = (PUCHAR)(_SourceAddressBuffer); \ ! 190: \ ! 191: switch ((_MacInfo)->MediumType) { \ ! 192: case NdisMedium802_5: \ ! 193: *(PULONG)SrcBuffer = *(ULONG UNALIGNED *)(&TmpPacket[8]) & ~0x80;\ ! 194: SrcBuffer[4] = TmpPacket[12]; \ ! 195: SrcBuffer[5] = TmpPacket[13]; \ ! 196: *(_SourceAddress) = (PHARDWARE_ADDRESS)SrcBuffer; \ ! 197: break; \ ! 198: default: \ ! 199: *(_SourceAddress) = (PHARDWARE_ADDRESS)(TmpPacket + \ ! 200: (_MacInfo)->SourceOffset); \ ! 201: break; \ ! 202: } \ ! 203: } ! 204: ! 205: ! 206: //++ ! 207: // ! 208: // VOID ! 209: // MacReturnSourceRouting( ! 210: // IN PST_NDIS_IDENTIFICATION MacInfo, ! 211: // IN PVOID Packet, ! 212: // OUT PVOID * SourceRouting ! 213: // OUT PUINT SourceRoutingLength ! 214: // ); ! 215: // ! 216: // Routine Description: ! 217: // ! 218: // Returns the a pointer to the source routing info in the packet. ! 219: // ! 220: // Arguments: ! 221: // ! 222: // MacInfo - Describes the MAC we wish to decode. ! 223: // ! 224: // Packet - The packet data. ! 225: // ! 226: // SourceRouting - Returns the start of the source routing information, ! 227: // or NULL if none is present. ! 228: // ! 229: // SourceRoutingLength - Returns the length of the source routing ! 230: // information. ! 231: // ! 232: // Return Value: ! 233: // ! 234: // None. ! 235: // ! 236: //-- ! 237: ! 238: #define MacReturnSourceRouting(_MacInfo, _Packet, _SourceRouting, _SourceRoutingLength) \ ! 239: { \ ! 240: PUCHAR TmpPacket = (PUCHAR)(_Packet); \ ! 241: if ((_MacInfo)->SourceRouting) { \ ! 242: if (TmpPacket[8] & 0x80) { \ ! 243: *(_SourceRouting) = TmpPacket + 14; \ ! 244: *(_SourceRoutingLength) = TmpPacket[14] & 0x1f; \ ! 245: } else { \ ! 246: *(_SourceRouting) = NULL; \ ! 247: } \ ! 248: } else { \ ! 249: *(_SourceRouting) = NULL; \ ! 250: } \ ! 251: } ! 252: ! 253: //++ ! 254: // ! 255: // VOID ! 256: // MacReturnPacketLength( ! 257: // IN PST_NDIS_IDENTIFICATION MacInfo, ! 258: // IN PVOID Header, ! 259: // IN UINT PacketLength, ! 260: // OUT PUINT DataLength ! 261: // ); ! 262: // ! 263: // Routine Description: ! 264: // ! 265: // Returns the length of data in the packet given the header. ! 266: // ! 267: // Arguments: ! 268: // ! 269: // MacInfo - Describes the MAC we wish to decode. ! 270: // ! 271: // Header - The packet header. ! 272: // ! 273: // PacketLength - The length of the data (not including header). ! 274: // ! 275: // DataLength - Returns the length of the data. Unchanged if the ! 276: // packet is not recognized. Should be initialized by caller to 0. ! 277: // ! 278: // Return Value: ! 279: // ! 280: // None. ! 281: // ! 282: //-- ! 283: ! 284: #define MacReturnPacketLength(_MacInfo, _Header, _HeaderLength, _PacketLength, _DataLength) \ ! 285: { \ ! 286: PUCHAR TmpPacket = (PUCHAR)(_Header); \ ! 287: UINT TmpLength; \ ! 288: \ ! 289: switch ((_MacInfo)->MediumType) { \ ! 290: case NdisMedium802_3: \ ! 291: if ((_HeaderLength) >= 14) { \ ! 292: TmpLength = (TmpPacket[12] << 8) | TmpPacket[13]; \ ! 293: if (TmpLength <= 0x600) { \ ! 294: if (TmpLength <= (_PacketLength)) { \ ! 295: *(_DataLength) = TmpLength; \ ! 296: } \ ! 297: } \ ! 298: } \ ! 299: break; \ ! 300: case NdisMedium802_5: \ ! 301: if (((_HeaderLength) >= 14) && \ ! 302: (!(TmpPacket[8] & 0x80) || \ ! 303: ((_HeaderLength) >= \ ! 304: (UINT)(14 + (TmpPacket[14] & 0x1f))))) { \ ! 305: *(_DataLength) = (_PacketLength); \ ! 306: } \ ! 307: break; \ ! 308: case NdisMediumFddi: \ ! 309: if ((_HeaderLength) >= 13) { \ ! 310: *(_DataLength) = (_PacketLength); \ ! 311: } \ ! 312: break; \ ! 313: } \ ! 314: } ! 315: ! 316: //++ ! 317: // ! 318: // VOID ! 319: // MacReturnHeaderLength( ! 320: // IN PST_NDIS_IDENTIFICATION MacInfo, ! 321: // IN PVOID Packet, ! 322: // OUT PVOID HeaderLength, ! 323: // ); ! 324: // ! 325: // Routine Description: ! 326: // ! 327: // Returns the length of the MAC header in a packet (this ! 328: // is used for loopback indications to separate header ! 329: // and data). ! 330: // ! 331: // Arguments: ! 332: // ! 333: // MacInfo - Describes the MAC we wish to decode. ! 334: // ! 335: // Header - The packet header. ! 336: // ! 337: // HeaderLength - Returns the length of the header. ! 338: // ! 339: // Return Value: ! 340: // ! 341: // None. ! 342: // ! 343: //-- ! 344: ! 345: #define MacReturnHeaderLength(_MacInfo, _Header, _HeaderLength) \ ! 346: { \ ! 347: PUCHAR TmpPacket = (PUCHAR)(_Header); \ ! 348: \ ! 349: switch ((_MacInfo)->MediumType) { \ ! 350: case NdisMedium802_3: \ ! 351: *(_HeaderLength) = 14; \ ! 352: break; \ ! 353: case NdisMedium802_5: \ ! 354: if (TmpPacket[8] & 0x80) { \ ! 355: *(_HeaderLength) = (TmpPacket[14] & 0x1f) + 14; \ ! 356: } else { \ ! 357: *(_HeaderLength) = 14; \ ! 358: } \ ! 359: break; \ ! 360: case NdisMediumFddi: \ ! 361: *(_HeaderLength) = 13; \ ! 362: break; \ ! 363: } \ ! 364: } ! 365: ! 366: //++ ! 367: // ! 368: // VOID ! 369: // MacReturnSingleRouteSR( ! 370: // IN PST_NDIS_IDENTIFICATION MacInfo, ! 371: // OUT PVOID * SingleRouteSR, ! 372: // OUT PUINT SingleRouteSRLength ! 373: // ); ! 374: // ! 375: // Routine Description: ! 376: // ! 377: // Returns the a pointer to the standard single route broadcast ! 378: // source routing information for the media type. This is used ! 379: // for ADD_NAME_QUERY, DATAGRAM, NAME_IN_CONFLICT, NAME_QUERY, ! 380: // and STATUS_QUERY frames. ! 381: // ! 382: // Arguments: ! 383: // ! 384: // MacInfo - Describes the MAC we wish to decode. ! 385: // ! 386: // SingleRouteSR - Returns a pointer to the data. ! 387: // ! 388: // SingleRouteSRLength - The length of SingleRouteSR. ! 389: // ! 390: // Return Value: ! 391: // ! 392: // None. ! 393: // ! 394: //-- ! 395: ! 396: #define MacReturnSingleRouteSR(_MacInfo, _SingleRouteSR, _SingleRouteSRLength) \ ! 397: { \ ! 398: switch ((_MacInfo)->MediumType) { \ ! 399: case NdisMedium802_5: \ ! 400: *(_SingleRouteSR) = SingleRouteSourceRouting; \ ! 401: *(_SingleRouteSRLength) = DefaultSourceRoutingLength; \ ! 402: break; \ ! 403: default: \ ! 404: *(_SingleRouteSR) = NULL; \ ! 405: break; \ ! 406: } \ ! 407: } ! 408: ! 409: ! 410: //++ ! 411: // ! 412: // VOID ! 413: // MacReturnGeneralRouteSR( ! 414: // IN PST_NDIS_IDENTIFICATION MacInfo, ! 415: // OUT PVOID * GeneralRouteSR, ! 416: // OUT PUINT GeneralRouteSRLength ! 417: // ); ! 418: // ! 419: // Routine Description: ! 420: // ! 421: // Returns the a pointer to the standard general route broadcast ! 422: // source routing information for the media type. This is used ! 423: // for NAME_RECOGNIZED frames. ! 424: // ! 425: // Arguments: ! 426: // ! 427: // MacInfo - Describes the MAC we wish to decode. ! 428: // ! 429: // GeneralRouteSR - Returns a pointer to the data. ! 430: // ! 431: // GeneralRouteSRLength - The length of GeneralRouteSR. ! 432: // ! 433: // Return Value: ! 434: // ! 435: // None. ! 436: // ! 437: //-- ! 438: ! 439: #define MacReturnGeneralRouteSR(_MacInfo, _GeneralRouteSR, _GeneralRouteSRLength) \ ! 440: { \ ! 441: switch ((_MacInfo)->MediumType) { \ ! 442: case NdisMedium802_5: \ ! 443: *(_GeneralRouteSR) = GeneralRouteSourceRouting; \ ! 444: *(_GeneralRouteSRLength) = DefaultSourceRoutingLength; \ ! 445: break; \ ! 446: default: \ ! 447: *(_GeneralRouteSR) = NULL; \ ! 448: break; \ ! 449: } \ ! 450: } ! 451: ! 452: #if 0 ! 453: ! 454: //++ ! 455: // ! 456: // VOID ! 457: // MacCreateGeneralRouteReplySR( ! 458: // IN PST_NDIS_IDENTIFICATION MacInfo, ! 459: // IN PUCHAR ExistingSR, ! 460: // IN UINT ExistingSRLength, ! 461: // OUT PUCHAR * NewSR ! 462: // ); ! 463: // ! 464: // Routine Description: ! 465: // ! 466: // This modifies an existing source routing entry to make ! 467: // it into a general-route source routing entry. The assumption ! 468: // is that is to reply to existing source routing, so the ! 469: // direction bit is also reversed. In addition, if it is ! 470: // determined that no source routing is needed in the reply, ! 471: // then NULL is returned. ! 472: // ! 473: // Note that the information is modified in-place, but a ! 474: // separate pointer is returned (to allow NULL to be returned). ! 475: // ! 476: // Arguments: ! 477: // ! 478: // MacInfo - Describes the MAC we wish to decode. ! 479: // ! 480: // ExistingSR - The existing source routing to be modified. ! 481: // ! 482: // Return Value: ! 483: // ! 484: // None. ! 485: // ! 486: //-- ! 487: ! 488: #define MacCreateGeneralRouteReplySR(_MacInfo, _ExistingSR, _ExistingSRLength, _NewSR) \ ! 489: { \ ! 490: if (_ExistingSR) { \ ! 491: PUCHAR TmpSR = (PUCHAR)(_ExistingSR); \ ! 492: switch ((_MacInfo)->MediumType) { \ ! 493: case NdisMedium802_5: \ ! 494: TmpSR[0] = (TmpSR[0] & 0x1f) | 0x80; \ ! 495: TmpSR[1] = (TmpSR[1] ^ 0x80) | 0x70; \ ! 496: *(_NewSR) = (_ExistingSR); \ ! 497: break; \ ! 498: default: \ ! 499: *(_NewSR) = (_ExistingSR); \ ! 500: break; \ ! 501: } \ ! 502: } else { \ ! 503: *(_NewSR) = NULL; \ ! 504: } \ ! 505: } ! 506: #endif ! 507: ! 508: ! 509: //++ ! 510: // ! 511: // VOID ! 512: // MacCreateNonBroadcastReplySR( ! 513: // IN PST_NDIS_IDENTIFICATION MacInfo, ! 514: // IN PUCHAR ExistingSR, ! 515: // IN UINT ExistingSRLength, ! 516: // OUT PUCHAR * NewSR ! 517: // ); ! 518: // ! 519: // Routine Description: ! 520: // ! 521: // This modifies an existing source routing entry to make ! 522: // it into a non-broadcast source routing entry. The assumption ! 523: // is that is to reply to existing source routing, so the ! 524: // direction bit is also reversed. In addition, if it is ! 525: // determined that no source routing is needed in the reply, ! 526: // then NULL is returned. ! 527: // ! 528: // Note that the information is modified in-place, but a ! 529: // separate pointer is returned (to allow NULL to be returned). ! 530: // ! 531: // Arguments: ! 532: // ! 533: // MacInfo - Describes the MAC we wish to decode. ! 534: // ! 535: // ExistingSR - The existing source routing to be modified. ! 536: // ! 537: // Return Value: ! 538: // ! 539: // None. ! 540: // ! 541: //-- ! 542: ! 543: #define MacCreateNonBroadcastReplySR(_MacInfo, _ExistingSR, _ExistingSRLength, _NewSR) \ ! 544: { \ ! 545: if (_ExistingSR) { \ ! 546: PUCHAR TmpSR = (PUCHAR)(_ExistingSR); \ ! 547: switch ((_MacInfo)->MediumType) { \ ! 548: case NdisMedium802_5: \ ! 549: if ((_ExistingSRLength) == 2) { \ ! 550: *(_NewSR) = NULL; \ ! 551: } else { \ ! 552: TmpSR[0] = (TmpSR[0] & 0x1f); \ ! 553: TmpSR[1] = (TmpSR[1] ^ 0x80) | 0x70; \ ! 554: *(_NewSR) = (_ExistingSR); \ ! 555: } \ ! 556: break; \ ! 557: default: \ ! 558: *(_NewSR) = (_ExistingSR); \ ! 559: break; \ ! 560: } \ ! 561: } else { \ ! 562: *(_NewSR) = NULL; \ ! 563: } \ ! 564: } ! 565: ! 566: ! 567: //++ ! 568: // ! 569: // VOID ! 570: // MacModifyHeader( ! 571: // IN PST_NDIS_IDENTIFICATION MacInfo, ! 572: // IN PUCHAR Header, ! 573: // IN UINT PacketLength ! 574: // ); ! 575: // ! 576: // Routine Description: ! 577: // ! 578: // Modifies a pre-built packet header to include the ! 579: // packet length. Used for connection-oriented traffic ! 580: // where the header is pre-built. ! 581: // ! 582: // Arguments: ! 583: // ! 584: // MacInfo - Describes the MAC we wish to decode. ! 585: // ! 586: // Header - The header to modify. ! 587: // ! 588: // PacketLength - Packet length (not including the header). ! 589: // Currently this is the only field that cannot be pre-built. ! 590: // ! 591: // Return Value: ! 592: // ! 593: // None. ! 594: // ! 595: //-- ! 596: ! 597: #define MacModifyHeader(_MacInfo, _Header, _PacketLength) \ ! 598: { \ ! 599: switch ((_MacInfo)->MediumType) { \ ! 600: case NdisMedium802_3: \ ! 601: (_Header)[12] = (UCHAR)((_PacketLength) >> 8); \ ! 602: (_Header)[13] = (UCHAR)((_PacketLength) & 0xff); \ ! 603: break; \ ! 604: } \ ! 605: } ! 606: ! 607: ! 608: VOID ! 609: MacSetMulticastAddress( ! 610: IN NDIS_MEDIUM Type, ! 611: IN PUCHAR Buffer ! 612: ); ! 613: ! 614: ! 615: ! 616: // VOID ! 617: // StSetNdisPacketLength ( ! 618: // IN NDIS_PACKET Packet, ! 619: // IN ULONG Length ! 620: // ); ! 621: // ! 622: // NB: This is not a general purpose macro; it assumes that we are setting the ! 623: // length of an NDIS packet with only one NDIS_BUFFER chained. We do ! 624: // this to save time during the sending of short control packets. ! 625: // ! 626: ! 627: #define StSetNdisPacketLength(_packet,_length) { \ ! 628: PNDIS_BUFFER NdisBuffer; \ ! 629: NdisQueryPacket((_packet), NULL, NULL, &NdisBuffer, NULL); \ ! 630: NdisAdjustBufferLength(NdisBuffer, (_length)); \ ! 631: NdisRecalculatePacketCounts(_packet); \ ! 632: } ! 633: ! 634: #endif // ifdef _STMAC_ ! 635:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.