Broadcom SDK and wireless driver: another attempt to update to ver. 5.10.147.0
[tomato.git] / release / src-rt / include / proto / ethernet.h
blobe471866c4141cd15a0a9a69f7cac3aa869512894
1 /*
2 * From FreeBSD 2.2.7: Fundamental constants relating to ethernet.
4 * Copyright (C) 2009, 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.
12 * $Id: ethernet.h,v 9.45.12.3 2009/10/12 23:01:02 Exp $
15 #ifndef _NET_ETHERNET_H_ /* use native BSD ethernet.h when available */
16 #define _NET_ETHERNET_H_
18 #ifndef _TYPEDEFS_H_
19 #include "typedefs.h"
20 #endif
22 /* enable structure packing */
23 #if defined(__GNUC__)
24 #define PACKED __attribute__((packed))
25 #else
26 #pragma pack(1)
27 #define PACKED
28 #endif
31 * The number of bytes in an ethernet (MAC) address.
33 #define ETHER_ADDR_LEN 6
36 * The number of bytes in the type field.
38 #define ETHER_TYPE_LEN 2
41 * The number of bytes in the trailing CRC field.
43 #define ETHER_CRC_LEN 4
46 * The length of the combined header.
48 #define ETHER_HDR_LEN (ETHER_ADDR_LEN * 2 + ETHER_TYPE_LEN)
51 * The minimum packet length.
53 #define ETHER_MIN_LEN 64
56 * The minimum packet user data length.
58 #define ETHER_MIN_DATA 46
61 * The maximum packet length.
63 #define ETHER_MAX_LEN 1518
66 * The maximum packet user data length.
68 #define ETHER_MAX_DATA 1500
70 /* ether types */
71 #define ETHER_TYPE_MIN 0x0600 /* Anything less than MIN is a length */
72 #define ETHER_TYPE_IP 0x0800 /* IP */
73 #define ETHER_TYPE_ARP 0x0806 /* ARP */
74 #define ETHER_TYPE_8021Q 0x8100 /* 802.1Q */
75 #define ETHER_TYPE_BRCM 0x886c /* Broadcom Corp. */
76 #define ETHER_TYPE_802_1X 0x888e /* 802.1x */
77 #ifdef BCMWPA2
78 #define ETHER_TYPE_802_1X_PREAUTH 0x88c7 /* 802.1x preauthentication */
79 #endif
81 /* Broadcom subtype follows ethertype; First 2 bytes are reserved; Next 2 are subtype; */
82 #define ETHER_BRCM_SUBTYPE_LEN 4 /* Broadcom 4 byte subtype */
83 #define ETHER_BRCM_CRAM 1 /* Broadcom subtype cram protocol */
85 /* ether header */
86 #define ETHER_DEST_OFFSET (0 * ETHER_ADDR_LEN) /* dest address offset */
87 #define ETHER_SRC_OFFSET (1 * ETHER_ADDR_LEN) /* src address offset */
88 #define ETHER_TYPE_OFFSET (2 * ETHER_ADDR_LEN) /* ether type offset */
91 * A macro to validate a length with
93 #define ETHER_IS_VALID_LEN(foo) \
94 ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
96 #define ETHER_FILL_MCAST_ADDR_FROM_IP(eaddr, mgrp_ip) \
97 eaddr[0] = 0x01; \
98 eaddr[1] = 0x00; \
99 eaddr[2] = 0x5e; \
100 eaddr[5] = mgrp_ip & 0xff; mgrp_ip >>= 8; \
101 eaddr[4] = mgrp_ip & 0xff; mgrp_ip >>= 8; \
102 eaddr[3] = mgrp_ip & 0x7f
104 #ifndef __INCif_etherh /* Quick and ugly hack for VxWorks */
106 * Structure of a 10Mb/s Ethernet header.
108 struct ether_header {
109 uint8 ether_dhost[ETHER_ADDR_LEN];
110 uint8 ether_shost[ETHER_ADDR_LEN];
111 uint16 ether_type;
112 } PACKED;
115 * Structure of a 48-bit Ethernet address.
117 struct ether_addr {
118 uint8 octet[ETHER_ADDR_LEN];
119 } PACKED;
120 #endif /* !__INCif_etherh Quick and ugly hack for VxWorks */
123 * Takes a pointer, set, test, clear, toggle locally admininistered
124 * address bit in the 48-bit Ethernet address.
126 #define ETHER_SET_LOCALADDR(ea) (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] | 2))
127 #define ETHER_IS_LOCALADDR(ea) (((uint8 *)(ea))[0] & 2)
128 #define ETHER_CLR_LOCALADDR(ea) (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] & 0xd))
129 #define ETHER_TOGGLE_LOCALADDR(ea) (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] ^ 2))
131 /* Takes a pointer, marks unicast address bit in the MAC address */
132 #define ETHER_SET_UNICAST(ea) (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] & ~1))
135 * Takes a pointer, returns true if a 48-bit multicast address
136 * (including broadcast, since it is all ones)
138 #define ETHER_ISMULTI(ea) (((const uint8 *)(ea))[0] & 1)
141 /* compare two ethernet addresses - assumes the pointers can be referenced as shorts */
142 #define ether_cmp(a, b) (!(((short*)a)[0] == ((short*)b)[0]) | \
143 !(((short*)a)[1] == ((short*)b)[1]) | \
144 !(((short*)a)[2] == ((short*)b)[2]))
146 /* copy an ethernet address - assumes the pointers can be referenced as shorts */
147 #define ether_copy(s, d) { \
148 ((short*)d)[0] = ((short*)s)[0]; \
149 ((short*)d)[1] = ((short*)s)[1]; \
150 ((short*)d)[2] = ((short*)s)[2]; }
153 * Takes a pointer, returns true if a 48-bit broadcast (all ones)
155 #define ETHER_ISBCAST(ea) ((((uint8 *)(ea))[0] & \
156 ((uint8 *)(ea))[1] & \
157 ((uint8 *)(ea))[2] & \
158 ((uint8 *)(ea))[3] & \
159 ((uint8 *)(ea))[4] & \
160 ((uint8 *)(ea))[5]) == 0xff)
162 static const struct ether_addr ether_bcast = {{255, 255, 255, 255, 255, 255}};
163 static const struct ether_addr ether_null = {{0, 0, 0, 0, 0, 0}};
166 * Takes a pointer, returns true if a 48-bit null address (all zeros)
168 #define ETHER_ISNULLADDR(ea) ((((uint8 *)(ea))[0] | \
169 ((uint8 *)(ea))[1] | \
170 ((uint8 *)(ea))[2] | \
171 ((uint8 *)(ea))[3] | \
172 ((uint8 *)(ea))[4] | \
173 ((uint8 *)(ea))[5]) == 0)
175 #define ETHER_MOVE_HDR(d, s) \
176 do { \
177 struct ether_header t; \
178 t = *(struct ether_header *)(s); \
179 *(struct ether_header *)(d) = t; \
180 } while (0)
182 #undef PACKED
183 #if !defined(__GNUC__)
184 #pragma pack()
185 #endif
187 #endif /* _NET_ETHERNET_H_ */