use only promise ide driver
[openwrt.git] / package / openwrt / include / proto / ethernet.h
1 /*******************************************************************************
2 * $Id$
3 * Copyright 2004, 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 _NET_ETHERNET_H_ /* use native BSD ethernet.h when available */
14 #define _NET_ETHERNET_H_
15
16 #ifndef _TYPEDEFS_H_
17 #include "typedefs.h"
18 #endif
19
20 #if defined(__GNUC__)
21 #define PACKED __attribute__((packed))
22 #else
23 #define PACKED
24 #endif
25
26 /*
27 * The number of bytes in an ethernet (MAC) address.
28 */
29 #ifndef ETHER_ADDR_LEN
30 #define ETHER_ADDR_LEN 6
31 #endif
32
33 /*
34 * The number of bytes in the type field.
35 */
36 #ifndef ETHER_TYPE_LEN
37 #define ETHER_TYPE_LEN 2
38 #endif
39
40 /*
41 * The number of bytes in the trailing CRC field.
42 */
43 #ifndef ETHER_CRC_LEN
44 #define ETHER_CRC_LEN 4
45 #endif
46
47 /*
48 * The length of the combined header.
49 */
50 #ifndef ETHER_HDR_LEN
51 #define ETHER_HDR_LEN (ETHER_ADDR_LEN*2+ETHER_TYPE_LEN)
52 #endif
53
54 /*
55 * The minimum packet length.
56 */
57 #ifndef ETHER_MIN_LEN
58 #define ETHER_MIN_LEN 64
59 #endif
60
61 /*
62 * The minimum packet user data length.
63 */
64 #ifndef ETHER_MIN_DATA
65 #define ETHER_MIN_DATA 46
66 #endif
67
68 /*
69 * The maximum packet length.
70 */
71 #ifndef ETHER_MAX_LEN
72 #define ETHER_MAX_LEN 1518
73 #endif
74
75 /*
76 * The maximum packet user data length.
77 */
78 #define ETHER_MAX_DATA 1500
79
80 /*
81 * Used to uniquely identify a 802.1q VLAN-tagged header.
82 */
83 #define VLAN_TAG 0x8100
84
85 /*
86 * Located after dest & src address in ether header.
87 */
88 #define VLAN_FIELDS_OFFSET (ETHER_ADDR_LEN * 2)
89
90 /*
91 * 4 bytes of vlan field info.
92 */
93 #define VLAN_FIELDS_SIZE 4
94
95 /* location of bits in 16-bit vlan fields */
96 #define VLAN_PRI_SHIFT 13 /* user priority */
97 #define VLAN_CFI_SHIFT 12 /* canonical format indicator bit */
98
99 /* 3 bits of priority */
100 #define VLAN_PRI_MASK 7
101 /* 12 bits of vlan identfier (VID) */
102 #define VLAN_VID_MASK 0xFFF /* VLAN identifier (VID) field */
103
104 struct vlan_tags {
105 uint16 tag_type; /* 0x8100 for VLAN */
106 uint16 tag_control; /* prio | cfi | vid */
107 } PACKED ;
108
109 /* 802.1X ethertype */
110
111 #define ETHER_TYPE_IP 0x0800 /* IP */
112 #define ETHER_TYPE_BRCM 0x886c /* Broadcom Corp. */
113 #define ETHER_TYPE_802_1X 0x888e /* 802.1x */
114
115 #define ETHER_BRCM_SUBTYPE_LEN 4 /* Broadcom 4byte subtype follows ethertype */
116 #define ETHER_BRCM_CRAM 0x1 /* Broadcom subtype cram protocol */
117
118 /*
119 * A macro to validate a length with
120 */
121 #define ETHER_IS_VALID_LEN(foo) \
122 ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
123
124 #ifndef __NET_ETHERNET_H
125 #ifndef __INCif_etherh /* Quick and ugly hack for VxWorks */
126 /*
127 * Structure of a 10Mb/s Ethernet header.
128 */
129 struct ether_header {
130 uint8 ether_dhost[ETHER_ADDR_LEN];
131 uint8 ether_shost[ETHER_ADDR_LEN];
132 uint16 ether_type;
133 } PACKED ;
134
135 /*
136 * Structure of a 48-bit Ethernet address.
137 */
138 struct ether_addr {
139 uint8 octet[ETHER_ADDR_LEN];
140 } PACKED ;
141 #endif
142 #endif
143
144 /*
145 * Takes a pointer, returns true if a 48-bit multicast address
146 * (including broadcast, since it is all ones)
147 */
148 #define ETHER_ISMULTI(ea) (((uint8 *)(ea))[0] & 1)
149
150 /*
151 * Takes a pointer, returns true if a 48-bit broadcast (all ones)
152 */
153 #define ETHER_ISBCAST(ea) ((((uint8 *)(ea))[0] & \
154 ((uint8 *)(ea))[1] & \
155 ((uint8 *)(ea))[2] & \
156 ((uint8 *)(ea))[3] & \
157 ((uint8 *)(ea))[4] & \
158 ((uint8 *)(ea))[5]) == 0xff)
159
160 static const struct ether_addr ether_bcast = {{255, 255, 255, 255, 255, 255}};
161
162 /*
163 * Takes a pointer, returns true if a 48-bit null address (all zeros)
164 */
165 #define ETHER_ISNULLADDR(ea) ((((uint8 *)(ea))[0] | \
166 ((uint8 *)(ea))[1] | \
167 ((uint8 *)(ea))[2] | \
168 ((uint8 *)(ea))[3] | \
169 ((uint8 *)(ea))[4] | \
170 ((uint8 *)(ea))[5]) == 0)
171
172 /* Differentiated Services Codepoint - lower 6 bits of tos in iphdr */
173 #define DSCP_PRI_MASK 0x3F /* bits 0-6 */
174 #define DSCP_WME_PRI_MASK 0x38 /* bits 3-6 */
175 #define DSCP_WME_PRI_SHIFT 3
176
177 #undef PACKED
178
179 #endif /* _NET_ETHERNET_H_ */
This page took 0.049558 seconds and 5 git commands to generate.