add miax package (thanks to Markus Becker)
[openwrt.git] / openwrt / package / wificonf / include / proto / ethernet.h
1 /*******************************************************************************
2 * $Id$
3 * Copyright 2005, Broadcom Corporation
4 * All Rights Reserved.
5 *
6 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
7 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
8 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
9 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
10 * From FreeBSD 2.2.7: Fundamental constants relating to ethernet.
11 ******************************************************************************/
12
13 #ifndef ETHER_ADDR_LEN
14 #define _NET_ETHERNET_H_
15
16 #ifndef _TYPEDEFS_H_
17 #include "typedefs.h"
18 #endif
19
20 /* enable structure packing */
21 #if defined(__GNUC__)
22 #define PACKED __attribute__((packed))
23 #else
24 #pragma pack(1)
25 #define PACKED
26 #endif
27
28 /*
29 * The number of bytes in an ethernet (MAC) address.
30 */
31 #define ETHER_ADDR_LEN 6
32
33 /*
34 * The number of bytes in the type field.
35 */
36 #define ETHER_TYPE_LEN 2
37
38 /*
39 * The number of bytes in the trailing CRC field.
40 */
41 #define ETHER_CRC_LEN 4
42
43 /*
44 * The length of the combined header.
45 */
46 #define ETHER_HDR_LEN (ETHER_ADDR_LEN*2+ETHER_TYPE_LEN)
47
48 /*
49 * The minimum packet length.
50 */
51 #define ETHER_MIN_LEN 64
52
53 /*
54 * The minimum packet user data length.
55 */
56 #define ETHER_MIN_DATA 46
57
58 /*
59 * The maximum packet length.
60 */
61 #define ETHER_MAX_LEN 1518
62
63 /*
64 * The maximum packet user data length.
65 */
66 #define ETHER_MAX_DATA 1500
67
68 /* ether types */
69 #define ETHER_TYPE_IP 0x0800 /* IP */
70 #define ETHER_TYPE_ARP 0x0806 /* ARP */
71 #define ETHER_TYPE_8021Q 0x8100 /* 802.1Q */
72 #define ETHER_TYPE_BRCM 0x886c /* Broadcom Corp. */
73 #define ETHER_TYPE_802_1X 0x888e /* 802.1x */
74 #ifdef BCMWPA2
75 #define ETHER_TYPE_802_1X_PREAUTH 0x88c7 /* 802.1x preauthentication*/
76 #endif
77
78 /* Broadcom subtype follows ethertype; First 2 bytes are reserved; Next 2 are subtype; */
79 #define ETHER_BRCM_SUBTYPE_LEN 4 /* Broadcom 4 byte subtype */
80 #define ETHER_BRCM_CRAM 0x1 /* Broadcom subtype cram protocol */
81
82 /* ether header */
83 #define ETHER_DEST_OFFSET 0 /* dest address offset */
84 #define ETHER_SRC_OFFSET 6 /* src address offset */
85 #define ETHER_TYPE_OFFSET 12 /* ether type offset */
86
87 /*
88 * A macro to validate a length with
89 */
90 #define ETHER_IS_VALID_LEN(foo) \
91 ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
92
93
94 #ifndef __INCif_etherh /* Quick and ugly hack for VxWorks */
95 /*
96 * Structure of a 10Mb/s Ethernet header.
97 */
98 struct ether_header {
99 uint8 ether_dhost[ETHER_ADDR_LEN];
100 uint8 ether_shost[ETHER_ADDR_LEN];
101 uint16 ether_type;
102 } PACKED;
103
104 /*
105 * Structure of a 48-bit Ethernet address.
106 */
107 struct ether_addr {
108 uint8 octet[ETHER_ADDR_LEN];
109 } PACKED;
110 #endif
111
112 /*
113 * Takes a pointer, sets locally admininistered
114 * address bit in the 48-bit Ethernet address.
115 */
116 #define ETHER_SET_LOCALADDR(ea) ( ((uint8 *)(ea))[0] = \
117 (((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) ( \
128 !(((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 /* Differentiated Services Codepoint - upper 6 bits of tos in iphdr */
161 #define DSCP_MASK 0xFC /* upper 6 bits */
162 #define DSCP_SHIFT 2
163 #define DSCP_WME_PRI_MASK 0xE0 /* upper 3 bits */
164 #define DSCP_WME_PRI_SHIFT 5
165
166 #undef PACKED
167 #if !defined(__GNUC__)
168 #pragma pack()
169 #endif
170
171 #endif /* _NET_ETHERNET_H_ */
This page took 0.081326 seconds and 5 git commands to generate.