BCM WL 6.30.102.9 (r366174)
[tomato.git] / release / src-rt / include / proto / ethernet.h
blob0c1036b8e9c1adf4506fa155213883d96efb7a1d
1 /*
2 * From FreeBSD 2.2.7: Fundamental constants relating to ethernet.
4 * Copyright (C) 2011, Broadcom Corporation. All Rights Reserved.
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
13 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
15 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 * $Id: ethernet.h 333173 2012-05-14 18:07:40Z $
21 #ifndef _NET_ETHERNET_H_ /* use native BSD ethernet.h when available */
22 #define _NET_ETHERNET_H_
24 #ifndef _TYPEDEFS_H_
25 #include "typedefs.h"
26 #endif
28 /* This marks the start of a packed structure section. */
29 #include <packed_section_start.h>
33 * The number of bytes in an ethernet (MAC) address.
35 #define ETHER_ADDR_LEN 6
38 * The number of bytes in the type field.
40 #define ETHER_TYPE_LEN 2
43 * The number of bytes in the trailing CRC field.
45 #define ETHER_CRC_LEN 4
48 * The length of the combined header.
50 #define ETHER_HDR_LEN (ETHER_ADDR_LEN * 2 + ETHER_TYPE_LEN)
53 * The minimum packet length.
55 #define ETHER_MIN_LEN 64
58 * The minimum packet user data length.
60 #define ETHER_MIN_DATA 46
63 * The maximum packet length.
65 #define ETHER_MAX_LEN 1518
68 * The maximum packet user data length.
70 #define ETHER_MAX_DATA 1500
72 /* ether types */
73 #define ETHER_TYPE_MIN 0x0600 /* Anything less than MIN is a length */
74 #define ETHER_TYPE_IP 0x0800 /* IP */
75 #define ETHER_TYPE_ARP 0x0806 /* ARP */
76 #define ETHER_TYPE_8021Q 0x8100 /* 802.1Q */
77 #define ETHER_TYPE_IPV6 0x86dd /* IPv6 */
78 #define ETHER_TYPE_BRCM 0x886c /* Broadcom Corp. */
79 #define ETHER_TYPE_802_1X 0x888e /* 802.1x */
80 #define ETHER_TYPE_802_1X_PREAUTH 0x88c7 /* 802.1x preauthentication */
81 #define ETHER_TYPE_WAI 0x88b4 /* WAI */
82 #define ETHER_TYPE_89_0D 0x890d /* 89-0d frame for TDLS */
84 #define ETHER_TYPE_IPV6 0x86dd /* IPV6 */
86 /* Broadcom subtype follows ethertype; First 2 bytes are reserved; Next 2 are subtype; */
87 #define ETHER_BRCM_SUBTYPE_LEN 4 /* Broadcom 4 byte subtype */
89 /* ether header */
90 #define ETHER_DEST_OFFSET (0 * ETHER_ADDR_LEN) /* dest address offset */
91 #define ETHER_SRC_OFFSET (1 * ETHER_ADDR_LEN) /* src address offset */
92 #define ETHER_TYPE_OFFSET (2 * ETHER_ADDR_LEN) /* ether type offset */
95 * A macro to validate a length with
97 #define ETHER_IS_VALID_LEN(foo) \
98 ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
100 #define ETHER_FILL_MCAST_ADDR_FROM_IP(ea, mgrp_ip) { \
101 ((uint8 *)ea)[0] = 0x01; \
102 ((uint8 *)ea)[1] = 0x00; \
103 ((uint8 *)ea)[2] = 0x5e; \
104 ((uint8 *)ea)[3] = ((mgrp_ip) >> 16) & 0x7f; \
105 ((uint8 *)ea)[4] = ((mgrp_ip) >> 8) & 0xff; \
106 ((uint8 *)ea)[5] = ((mgrp_ip) >> 0) & 0xff; \
109 #ifndef __INCif_etherh /* Quick and ugly hack for VxWorks */
111 * Structure of a 10Mb/s Ethernet header.
113 BWL_PRE_PACKED_STRUCT struct ether_header {
114 uint8 ether_dhost[ETHER_ADDR_LEN];
115 uint8 ether_shost[ETHER_ADDR_LEN];
116 uint16 ether_type;
117 } BWL_POST_PACKED_STRUCT;
120 * Structure of a 48-bit Ethernet address.
122 BWL_PRE_PACKED_STRUCT struct ether_addr {
123 uint8 octet[ETHER_ADDR_LEN];
124 } BWL_POST_PACKED_STRUCT;
125 #endif /* !__INCif_etherh Quick and ugly hack for VxWorks */
128 * Takes a pointer, set, test, clear, toggle locally admininistered
129 * address bit in the 48-bit Ethernet address.
131 #define ETHER_SET_LOCALADDR(ea) (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] | 2))
132 #define ETHER_IS_LOCALADDR(ea) (((uint8 *)(ea))[0] & 2)
133 #define ETHER_CLR_LOCALADDR(ea) (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] & 0xfd))
134 #define ETHER_TOGGLE_LOCALADDR(ea) (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] ^ 2))
136 /* Takes a pointer, marks unicast address bit in the MAC address */
137 #define ETHER_SET_UNICAST(ea) (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] & ~1))
140 * Takes a pointer, returns true if a 48-bit multicast address
141 * (including broadcast, since it is all ones)
143 #define ETHER_ISMULTI(ea) (((const uint8 *)(ea))[0] & 1)
146 /* compare two ethernet addresses - assumes the pointers can be referenced as shorts */
147 #define eacmp(a, b) ((((uint16 *)(a))[0] ^ ((uint16 *)(b))[0]) | \
148 (((uint16 *)(a))[1] ^ ((uint16 *)(b))[1]) | \
149 (((uint16 *)(a))[2] ^ ((uint16 *)(b))[2]))
151 #define ether_cmp(a, b) eacmp(a, b)
153 /* copy an ethernet address - assumes the pointers can be referenced as shorts */
154 #define eacopy(s, d) \
155 do { \
156 ((uint16 *)(d))[0] = ((const uint16 *)(s))[0]; \
157 ((uint16 *)(d))[1] = ((const uint16 *)(s))[1]; \
158 ((uint16 *)(d))[2] = ((const uint16 *)(s))[2]; \
159 } while (0)
161 #define ether_copy(s, d) eacopy(s, d)
164 static const struct ether_addr ether_bcast = {{255, 255, 255, 255, 255, 255}};
165 static const struct ether_addr ether_null = {{0, 0, 0, 0, 0, 0}};
167 #define ETHER_ISBCAST(ea) ((((const uint8 *)(ea))[0] & \
168 ((const uint8 *)(ea))[1] & \
169 ((const uint8 *)(ea))[2] & \
170 ((const uint8 *)(ea))[3] & \
171 ((const uint8 *)(ea))[4] & \
172 ((const uint8 *)(ea))[5]) == 0xff)
173 #define ETHER_ISNULLADDR(ea) ((((const uint8 *)(ea))[0] | \
174 ((const uint8 *)(ea))[1] | \
175 ((const uint8 *)(ea))[2] | \
176 ((const uint8 *)(ea))[3] | \
177 ((const uint8 *)(ea))[4] | \
178 ((const uint8 *)(ea))[5]) == 0)
180 #define ETHER_ISNULLDEST(da) ((((const uint16 *)(da))[0] | \
181 ((const uint16 *)(da))[1] | \
182 ((const uint16 *)(da))[2]) == 0)
183 #define ETHER_ISNULLSRC(sa) ETHER_ISNULLDEST(sa)
185 #define ETHER_MOVE_HDR(d, s) \
186 do { \
187 struct ether_header t; \
188 t = *(struct ether_header *)(s); \
189 *(struct ether_header *)(d) = t; \
190 } while (0)
192 /* This marks the end of a packed structure section. */
193 #include <packed_section_end.h>
195 #endif /* _NET_ETHERNET_H_ */