Annotation of ntddk/src/network/tdi/stmac.c, revision 1.1.1.1

1.1       root        1: /*++
                      2: 
                      3: Copyright (c) 1989-1993  Microsoft Corporation
                      4: 
                      5: Module Name:
                      6: 
                      7:     nbfmac.c
                      8: 
                      9: Abstract:
                     10: 
                     11:     This module contains code which implements Mac type dependent code for
                     12:     the ST transport.
                     13: 
                     14: Environment:
                     15: 
                     16:     Kernel mode (Actually, unimportant)
                     17: 
                     18: Revision History:
                     19: 
                     20: --*/
                     21: 
                     22: #include "st.h"
                     23: 
                     24: UCHAR SingleRouteSourceRouting[] = { 0xc2, 0x70 };
                     25: UCHAR GeneralRouteSourceRouting[] = { 0x82, 0x70 };
                     26: ULONG DefaultSourceRoutingLength = 2;
                     27: 
                     28: VOID
                     29: MacInitializeMacInfo(
                     30:     IN NDIS_MEDIUM MacType,
                     31:     OUT PST_NDIS_IDENTIFICATION MacInfo
                     32:     );
                     33: 
                     34: //
                     35: // This is the interpretation of the length bits in
                     36: // the 802.5 source-routing information.
                     37: //
                     38: 
                     39: ULONG SR802_5Lengths[8] = {  516,  1500,  2052,  4472,
                     40:                             8144, 11407, 17800, 17800 };
                     41: 
                     42: 
                     43: #ifdef ALLOC_PRAGMA
                     44: #pragma alloc_text(init,MacInitializeMacInfo)
                     45: #pragma alloc_text(init,MacSetMulticastAddress)
                     46: #endif
                     47: 
                     48: 
                     49: 
                     50: VOID
                     51: MacInitializeMacInfo(
                     52:     IN NDIS_MEDIUM MacType,
                     53:     OUT PST_NDIS_IDENTIFICATION MacInfo
                     54:     )
                     55: 
                     56: /*++
                     57: 
                     58: Routine Description:
                     59: 
                     60:     Fills in the MacInfo table based on MacType.
                     61: 
                     62: Arguments:
                     63: 
                     64:     MacType - The MAC type we wish to decode.
                     65: 
                     66:     MacInfo - The MacInfo structure to fill in.
                     67: 
                     68: Return Value:
                     69: 
                     70:     None.
                     71: 
                     72: --*/
                     73: 
                     74: {
                     75:     switch (MacType) {
                     76:     case NdisMedium802_3:
                     77:         MacInfo->DestinationOffset = 0;
                     78:         MacInfo->SourceOffset = 6;
                     79:         MacInfo->SourceRouting = FALSE;
                     80:         MacInfo->AddressLength = 6;
                     81:         MacInfo->MaxHeaderLength = 14;
                     82:         MacInfo->MediumType = NdisMedium802_3;
                     83:         break;
                     84:     case NdisMedium802_5:
                     85:         MacInfo->DestinationOffset = 2;
                     86:         MacInfo->SourceOffset = 8;
                     87:         MacInfo->SourceRouting = TRUE;
                     88:         MacInfo->AddressLength = 6;
                     89:         MacInfo->MaxHeaderLength = 32;
                     90:         MacInfo->MediumType = NdisMedium802_5;
                     91:         break;
                     92:     case NdisMediumFddi:
                     93:         MacInfo->DestinationOffset = 1;
                     94:         MacInfo->SourceOffset = 7;
                     95:         MacInfo->SourceRouting = FALSE;
                     96:         MacInfo->AddressLength = 6;
                     97:         MacInfo->MaxHeaderLength = 13;
                     98:         MacInfo->MediumType = NdisMediumFddi;
                     99:         break;
                    100:     default:
                    101:         ASSERT(FALSE);
                    102:     }
                    103: }
                    104: 
                    105: VOID
                    106: MacConstructHeader (
                    107:     IN PST_NDIS_IDENTIFICATION MacInfo,
                    108:     IN PUCHAR Buffer,
                    109:     IN PUCHAR DestinationAddress,
                    110:     IN PUCHAR SourceAddress,
                    111:     IN UINT PacketLength,
                    112:     IN PUCHAR SourceRouting,
                    113:     IN UINT SourceRoutingLength,
                    114:     OUT PUINT HeaderLength
                    115:     )
                    116: 
                    117: /*++
                    118: 
                    119: Routine Description:
                    120: 
                    121:     This routine is called to construct the Mac header for the particular
                    122:     network type we're talking to.
                    123: 
                    124: Arguments:
                    125: 
                    126:     MacInfo - Describes the mac we wish to build a header for.
                    127: 
                    128:     Buffer - Where to build the header.
                    129: 
                    130:     DestinationAddress - the address this packet is to be sent to.
                    131: 
                    132:     SourceAddress - Our address. Passing it in as a parameter allows us to play
                    133:             games with source if we need to.
                    134: 
                    135:     PacketLength - The length of this packet. Note that this does not
                    136:             includes the Mac header.
                    137: 
                    138:     SourceRouting - Optional source routing information.
                    139: 
                    140:     SourceRoutingLength - The length of SourceRouting.
                    141: 
                    142:     HeaderLength - Returns the length of the constructed header.
                    143: 
                    144: Return Value:
                    145: 
                    146:     None.
                    147: 
                    148: --*/
                    149: {
                    150:     //
                    151:     // Note network order of bytes.
                    152:     //
                    153: 
                    154:     switch (MacInfo->MediumType) {
                    155: 
                    156:     case NdisMedium802_3:
                    157: 
                    158:         *(ULONG UNALIGNED *)&Buffer[6] = *(ULONG UNALIGNED *)&SourceAddress[0];
                    159:         Buffer[10] = SourceAddress[4];
                    160:         Buffer[11] = SourceAddress[5];
                    161: 
                    162:         *(ULONG UNALIGNED *)&Buffer[0] = *(ULONG UNALIGNED *)&DestinationAddress[0];
                    163:         Buffer[4] = DestinationAddress[4];
                    164:         Buffer[5] = DestinationAddress[5];
                    165: 
                    166:         Buffer[12] = (UCHAR)(PacketLength >> 8);
                    167:         Buffer[13] = (UCHAR)PacketLength;
                    168: 
                    169:         *HeaderLength = 14;
                    170: 
                    171:         break;
                    172: 
                    173:     case NdisMedium802_5:
                    174: 
                    175:         Buffer[0] = TR_HEADER_BYTE_0;
                    176:         Buffer[1] = TR_HEADER_BYTE_1;
                    177: 
                    178:         ASSERT (TR_ADDRESS_LENGTH == 6);
                    179: 
                    180:         *(ULONG UNALIGNED *)&Buffer[8] = *(ULONG UNALIGNED *)&SourceAddress[0];
                    181:         Buffer[12] = SourceAddress[4];
                    182:         Buffer[13] = SourceAddress[5];
                    183: 
                    184:         *(ULONG UNALIGNED *)&Buffer[2] = *(ULONG UNALIGNED *)&DestinationAddress[0];
                    185:         Buffer[6] = DestinationAddress[4];
                    186:         Buffer[7] = DestinationAddress[5];
                    187: 
                    188:         *HeaderLength = 14;
                    189:         if (SourceRouting != NULL) {
                    190:             RtlCopyMemory (&Buffer[14], SourceRouting, SourceRoutingLength);
                    191:             Buffer[8] |= 0x80;           // add SR bit in source address
                    192:             *HeaderLength = 14 + SourceRoutingLength;
                    193:         }
                    194: 
                    195:         break;
                    196: 
                    197:     case NdisMediumFddi:
                    198: 
                    199:         Buffer[0] = FDDI_HEADER_BYTE;
                    200: 
                    201:         *(ULONG UNALIGNED *)&Buffer[7] = *(ULONG UNALIGNED *)&SourceAddress[0];
                    202:         Buffer[11] = SourceAddress[4];
                    203:         Buffer[12] = SourceAddress[5];
                    204: 
                    205:         *(ULONG UNALIGNED *)&Buffer[1] = *(ULONG UNALIGNED *)&DestinationAddress[0];
                    206:         Buffer[5] = DestinationAddress[4];
                    207:         Buffer[6] = DestinationAddress[5];
                    208: 
                    209:         *HeaderLength = 13;
                    210: 
                    211:         break;
                    212: 
                    213:     default:
                    214:         PANIC ("MacConstructHeader: PANIC! called with unsupported Mac type.\n");
                    215:     }
                    216: }
                    217: 
                    218: 
                    219: VOID
                    220: MacReturnMaxDataSize(
                    221:     IN PST_NDIS_IDENTIFICATION MacInfo,
                    222:     IN PUCHAR SourceRouting,
                    223:     IN UINT SourceRoutingLength,
                    224:     IN UINT DeviceMaxFrameSize,
                    225:     OUT PUINT MaxFrameSize
                    226:     )
                    227: 
                    228: /*++
                    229: 
                    230: Routine Description:
                    231: 
                    232:     This routine returns the space available for user data in a MAC packet.
                    233:     This will be the available space after the MAC header; all headers
                    234:     headers will be included in this space.
                    235: 
                    236: Arguments:
                    237: 
                    238:     MacInfo - Describes the MAC we wish to decode.
                    239: 
                    240:     SourceRouting - If we are concerned about a reply to a specific
                    241:         frame, then this information is used.
                    242: 
                    243:     SourceRouting - The length of SourceRouting.
                    244: 
                    245:     MaxFrameSize - The maximum frame size as returned by the adapter.
                    246: 
                    247:     MaxDataSize - The maximum data size computed.
                    248: 
                    249: Return Value:
                    250: 
                    251:     None.
                    252: 
                    253: --*/
                    254: 
                    255: {
                    256:     switch (MacInfo->MediumType) {
                    257: 
                    258:     case NdisMedium802_3:
                    259: 
                    260:         //
                    261:         // For 802.3, we always have a 14-byte MAC header.
                    262:         //
                    263: 
                    264:         *MaxFrameSize = DeviceMaxFrameSize - 14;
                    265:         break;
                    266: 
                    267:     case NdisMedium802_5:
                    268: 
                    269:         //
                    270:         // For 802.5, if we have source routing information then
                    271:         // use that, otherwise assume the worst.
                    272:         //
                    273: 
                    274:         if (SourceRouting && SourceRoutingLength >= 2) {
                    275: 
                    276:             UINT SRLength;
                    277: 
                    278:             SRLength = SR802_5Lengths[(SourceRouting[1] & 0x70) >> 4];
                    279:             DeviceMaxFrameSize -= (SourceRoutingLength + 14);
                    280: 
                    281:             if (DeviceMaxFrameSize < SRLength) {
                    282:                 *MaxFrameSize = DeviceMaxFrameSize;
                    283:             } else {
                    284:                 *MaxFrameSize = SRLength;
                    285:             }
                    286: 
                    287:         } else {
                    288: 
                    289:             if (DeviceMaxFrameSize < 548) {
                    290:                 *MaxFrameSize = DeviceMaxFrameSize - 32;
                    291:             } else {
                    292:                 *MaxFrameSize = 516;
                    293:             }
                    294:         }
                    295: 
                    296:         break;
                    297: 
                    298:     case NdisMediumFddi:
                    299: 
                    300:         //
                    301:         // For FDDI, we always have a 13-byte MAC header.
                    302:         //
                    303: 
                    304:         *MaxFrameSize = DeviceMaxFrameSize - 13;
                    305:         break;
                    306: 
                    307:     }
                    308: }
                    309: 
                    310: 
                    311: 
                    312: VOID
                    313: MacSetMulticastAddress (
                    314:     IN NDIS_MEDIUM Type,
                    315:     IN PUCHAR Buffer
                    316:     )
                    317: /*++
                    318: 
                    319: Routine Description:
                    320: 
                    321:     This routine sets the multicast address into a buffer provided
                    322:     by the user.
                    323: 
                    324: Arguments:
                    325: 
                    326:     Type the Mac Medium type.
                    327: 
                    328:     Buffer the buffer to put the multicast address in.
                    329: 
                    330: 
                    331: Return Value:
                    332: 
                    333:     none.
                    334: 
                    335: --*/
                    336: {
                    337:     switch (Type) {
                    338:     case NdisMedium802_3:
                    339:     case NdisMediumFddi:
                    340:         Buffer[0] = 0x03;
                    341:         Buffer[1] = 0x07;
                    342:         Buffer[2] = 0x03;
                    343:         Buffer[3] = 0x07;
                    344:         Buffer[4] = 0x03;
                    345:         Buffer[5] = 0x07;
                    346:         break;
                    347: 
                    348:     case NdisMedium802_5:
                    349:         Buffer[0] = 0xc0;
                    350:         Buffer[3] = 0x20;
                    351:         break;
                    352: 
                    353:     default:
                    354:         PANIC ("MacSetMulticastAddress: PANIC! called with unsupported Mac type.\n");
                    355:     }
                    356: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.