| 1 | /* |
| 2 | * From FreeBSD 2.2.7: Fundamental constants relating to ethernet. |
| 3 | * |
| 4 | * Copyright 2006, Broadcom Corporation |
| 5 | * All Rights Reserved. |
| 6 | * |
| 7 | * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY |
| 8 | * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM |
| 9 | * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS |
| 10 | * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #ifndef __NET_ETHERNET_H |
| 15 | #define __NET_ETHERNET_H |
| 16 | |
| 17 | #ifndef _TYPEDEFS_H_ |
| 18 | #include "typedefs.h" |
| 19 | #endif |
| 20 | |
| 21 | /* enable structure packing */ |
| 22 | #if defined(__GNUC__) |
| 23 | #define PACKED __attribute__((packed)) |
| 24 | #else |
| 25 | #pragma pack(1) |
| 26 | #define PACKED |
| 27 | #endif |
| 28 | |
| 29 | /* |
| 30 | * The number of bytes in an ethernet (MAC) address. |
| 31 | */ |
| 32 | #define ETHER_ADDR_LEN 6 |
| 33 | |
| 34 | /* |
| 35 | * The number of bytes in the type field. |
| 36 | */ |
| 37 | #define ETHER_TYPE_LEN 2 |
| 38 | |
| 39 | /* |
| 40 | * The number of bytes in the trailing CRC field. |
| 41 | */ |
| 42 | #define ETHER_CRC_LEN 4 |
| 43 | |
| 44 | /* |
| 45 | * The length of the combined header. |
| 46 | */ |
| 47 | #define ETHER_HDR_LEN (ETHER_ADDR_LEN*2+ETHER_TYPE_LEN) |
| 48 | |
| 49 | /* |
| 50 | * The minimum packet length. |
| 51 | */ |
| 52 | #define ETHER_MIN_LEN 64 |
| 53 | |
| 54 | /* |
| 55 | * The minimum packet user data length. |
| 56 | */ |
| 57 | #define ETHER_MIN_DATA 46 |
| 58 | |
| 59 | /* |
| 60 | * The maximum packet length. |
| 61 | */ |
| 62 | #define ETHER_MAX_LEN 1518 |
| 63 | |
| 64 | /* |
| 65 | * The maximum packet user data length. |
| 66 | */ |
| 67 | #define ETHER_MAX_DATA 1500 |
| 68 | |
| 69 | /* ether types */ |
| 70 | #define ETHER_TYPE_IP 0x0800 /* IP */ |
| 71 | #define ETHER_TYPE_ARP 0x0806 /* ARP */ |
| 72 | #define ETHER_TYPE_8021Q 0x8100 /* 802.1Q */ |
| 73 | #define ETHER_TYPE_BRCM 0x886c /* Broadcom Corp. */ |
| 74 | #define ETHER_TYPE_802_1X 0x888e /* 802.1x */ |
| 75 | #ifdef BCMWPA2 |
| 76 | #define ETHER_TYPE_802_1X_PREAUTH 0x88c7 /* 802.1x preauthentication */ |
| 77 | #endif |
| 78 | |
| 79 | /* Broadcom subtype follows ethertype; First 2 bytes are reserved; Next 2 are subtype; */ |
| 80 | #define ETHER_BRCM_SUBTYPE_LEN 4 /* Broadcom 4 byte subtype */ |
| 81 | #define ETHER_BRCM_CRAM 0x1 /* Broadcom subtype cram protocol */ |
| 82 | |
| 83 | /* ether header */ |
| 84 | #define ETHER_DEST_OFFSET 0 /* dest address offset */ |
| 85 | #define ETHER_SRC_OFFSET 6 /* src address offset */ |
| 86 | #define ETHER_TYPE_OFFSET 12 /* ether type offset */ |
| 87 | |
| 88 | /* |
| 89 | * A macro to validate a length with |
| 90 | */ |
| 91 | #define ETHER_IS_VALID_LEN(foo) \ |
| 92 | ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN) |
| 93 | |
| 94 | |
| 95 | #ifndef __INCif_etherh /* Quick and ugly hack for VxWorks */ |
| 96 | /* |
| 97 | * Structure of a 10Mb/s Ethernet header. |
| 98 | */ |
| 99 | struct ether_header { |
| 100 | uint8 ether_dhost[ETHER_ADDR_LEN]; |
| 101 | uint8 ether_shost[ETHER_ADDR_LEN]; |
| 102 | uint16 ether_type; |
| 103 | } PACKED; |
| 104 | |
| 105 | /* |
| 106 | * Structure of a 48-bit Ethernet address. |
| 107 | */ |
| 108 | struct ether_addr { |
| 109 | uint8 octet[ETHER_ADDR_LEN]; |
| 110 | } PACKED; |
| 111 | #endif /* !__INCif_etherh Quick and ugly hack for VxWorks */ |
| 112 | |
| 113 | /* |
| 114 | * Takes a pointer, sets locally admininistered |
| 115 | * address bit in the 48-bit Ethernet address. |
| 116 | */ |
| 117 | #define ETHER_SET_LOCALADDR(ea) (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] | 2)) |
| 118 | |
| 119 | /* |
| 120 | * Takes a pointer, returns true if a 48-bit multicast address |
| 121 | * (including broadcast, since it is all ones) |
| 122 | */ |
| 123 | #define ETHER_ISMULTI(ea) (((uint8 *)(ea))[0] & 1) |
| 124 | |
| 125 | |
| 126 | /* compare two ethernet addresses - assumes the pointers can be referenced as shorts */ |
| 127 | #define ether_cmp(a, b) (!(((short*)a)[0] == ((short*)b)[0]) | \ |
| 128 | !(((short*)a)[1] == ((short*)b)[1]) | \ |
| 129 | !(((short*)a)[2] == ((short*)b)[2])) |
| 130 | |
| 131 | /* copy an ethernet address - assumes the pointers can be referenced as shorts */ |
| 132 | #define ether_copy(s, d) { \ |
| 133 | ((short*)d)[0] = ((short*)s)[0]; \ |
| 134 | ((short*)d)[1] = ((short*)s)[1]; \ |
| 135 | ((short*)d)[2] = ((short*)s)[2]; } |
| 136 | |
| 137 | /* |
| 138 | * Takes a pointer, returns true if a 48-bit broadcast (all ones) |
| 139 | */ |
| 140 | #define ETHER_ISBCAST(ea) ((((uint8 *)(ea))[0] & \ |
| 141 | ((uint8 *)(ea))[1] & \ |
| 142 | ((uint8 *)(ea))[2] & \ |
| 143 | ((uint8 *)(ea))[3] & \ |
| 144 | ((uint8 *)(ea))[4] & \ |
| 145 | ((uint8 *)(ea))[5]) == 0xff) |
| 146 | |
| 147 | static const struct ether_addr ether_bcast = {{255, 255, 255, 255, 255, 255}}; |
| 148 | |
| 149 | /* |
| 150 | * Takes a pointer, returns true if a 48-bit null address (all zeros) |
| 151 | */ |
| 152 | #define ETHER_ISNULLADDR(ea) ((((uint8 *)(ea))[0] | \ |
| 153 | ((uint8 *)(ea))[1] | \ |
| 154 | ((uint8 *)(ea))[2] | \ |
| 155 | ((uint8 *)(ea))[3] | \ |
| 156 | ((uint8 *)(ea))[4] | \ |
| 157 | ((uint8 *)(ea))[5]) == 0) |
| 158 | |
| 159 | #undef PACKED |
| 160 | #if !defined(__GNUC__) |
| 161 | #pragma pack() |
| 162 | #endif |
| 163 | |
| 164 | #endif /* __NET_ETHERNET_H */ |
| 165 | |