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