1 | /*
|
---|
2 | * Copyright (c) 2009 Lukas Mejdrech
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup eth
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 |
|
---|
33 | /** @file
|
---|
34 | * Ethernet protocol header definitions.
|
---|
35 | * Based on the IEEE 802.3-2005
|
---|
36 | */
|
---|
37 |
|
---|
38 | #ifndef NET_ETH_HEADER_H_
|
---|
39 | #define NET_ETH_HEADER_H_
|
---|
40 |
|
---|
41 | #include <sys/types.h>
|
---|
42 |
|
---|
43 | /** Ethernet address length. */
|
---|
44 | #define ETH_ADDR 6
|
---|
45 |
|
---|
46 | /** Ethernet header preamble value. */
|
---|
47 | #define ETH_PREAMBLE 0x55
|
---|
48 |
|
---|
49 | /** Ethernet header start of frame value. */
|
---|
50 | #define ETH_SFD 0xD5
|
---|
51 |
|
---|
52 | /** IEEE 802.2 unordered information control field. */
|
---|
53 | #define IEEE_8023_2_UI 0x03
|
---|
54 |
|
---|
55 | /** Type definition of the Ethernet header IEEE 802.3 + 802.2 + SNAP extensions.
|
---|
56 | * @see eth_header_snap
|
---|
57 | */
|
---|
58 | typedef struct eth_header_snap eth_header_snap_t;
|
---|
59 |
|
---|
60 | /** Type definition of the Ethernet header IEEE 802.3 + 802.2 + SNAP extensions
|
---|
61 | * pointer.
|
---|
62 | *
|
---|
63 | * @see eth_header_snap
|
---|
64 | */
|
---|
65 | typedef eth_header_snap_t *eth_header_snap_ref;
|
---|
66 |
|
---|
67 | /** Type definition of the Ethernet header IEEE 802.3 + 802.2 + SNAP extensions.
|
---|
68 | * @see eth_header_lsap
|
---|
69 | */
|
---|
70 | typedef struct eth_header_lsap eth_header_lsap_t;
|
---|
71 |
|
---|
72 | /** Type definition of the Ethernet header IEEE 802.3 + 802.2 extension pointer.
|
---|
73 | * @see eth_header_lsap
|
---|
74 | */
|
---|
75 | typedef eth_header_lsap_t *eth_header_lsap_ref;
|
---|
76 |
|
---|
77 | /** Type definition of the Ethernet header LSAP extension.
|
---|
78 | * @see eth_ieee_lsap
|
---|
79 | */
|
---|
80 | typedef struct eth_ieee_lsap eth_ieee_lsap_t;
|
---|
81 |
|
---|
82 | /** Type definition of the Ethernet header LSAP extension pointer.
|
---|
83 | * @see eth_ieee_lsap
|
---|
84 | */
|
---|
85 | typedef eth_ieee_lsap_t *eth_ieee_lsap_ref;
|
---|
86 |
|
---|
87 | /** Type definition of the Ethernet header SNAP extension.
|
---|
88 | * @see eth_snap
|
---|
89 | */
|
---|
90 | typedef struct eth_snap eth_snap_t;
|
---|
91 |
|
---|
92 | /** Type definition of the Ethernet header SNAP extension pointer.
|
---|
93 | * @see eth_snap
|
---|
94 | */
|
---|
95 | typedef eth_snap_t *eth_snap_ref;
|
---|
96 |
|
---|
97 | /** Type definition of the Ethernet header preamble.
|
---|
98 | * @see preamble
|
---|
99 | */
|
---|
100 | typedef struct eth_preamble eth_preamble_t;
|
---|
101 |
|
---|
102 | /** Type definition of the Ethernet header preamble pointer.
|
---|
103 | * @see eth_preamble
|
---|
104 | */
|
---|
105 | typedef eth_preamble_t *eth_preamble_ref;
|
---|
106 |
|
---|
107 | /** Type definition of the Ethernet header.
|
---|
108 | * @see eth_header
|
---|
109 | */
|
---|
110 | typedef struct eth_header eth_header_t;
|
---|
111 |
|
---|
112 | /** Type definition of the Ethernet header pointer.
|
---|
113 | * @see eth_header
|
---|
114 | */
|
---|
115 | typedef eth_header_t *eth_header_ref;
|
---|
116 |
|
---|
117 | /** Ethernet header Link Service Access Point extension. */
|
---|
118 | struct eth_ieee_lsap {
|
---|
119 | /**
|
---|
120 | * Destination Service Access Point identifier.
|
---|
121 | * The possible values are assigned by an IEEE committee.
|
---|
122 | */
|
---|
123 | uint8_t dsap;
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * Source Service Access Point identifier.
|
---|
127 | * The possible values are assigned by an IEEE committee.
|
---|
128 | */
|
---|
129 | uint8_t ssap;
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Control parameter.
|
---|
133 | * The possible values are assigned by an IEEE committee.
|
---|
134 | */
|
---|
135 | uint8_t ctrl;
|
---|
136 | } __attribute__ ((packed));
|
---|
137 |
|
---|
138 | /** Ethernet header SNAP extension. */
|
---|
139 | struct eth_snap {
|
---|
140 | /** Protocol identifier or organization code. */
|
---|
141 | uint8_t protocol[3];
|
---|
142 |
|
---|
143 | /**
|
---|
144 | * Ethernet protocol identifier in the network byte order (big endian).
|
---|
145 | * @see ethernet_protocols.h
|
---|
146 | */
|
---|
147 | uint16_t ethertype;
|
---|
148 | } __attribute__ ((packed));
|
---|
149 |
|
---|
150 | /** Ethernet header preamble.
|
---|
151 | *
|
---|
152 | * Used for dummy devices.
|
---|
153 | */
|
---|
154 | struct eth_preamble {
|
---|
155 | /**
|
---|
156 | * Controlling preamble used for the frame transmission synchronization.
|
---|
157 | * All should be set to ETH_PREAMBLE.
|
---|
158 | */
|
---|
159 | uint8_t preamble[7];
|
---|
160 |
|
---|
161 | /**
|
---|
162 | * Start of Frame Delimiter used for the frame transmission
|
---|
163 | * synchronization.
|
---|
164 | * Should be set to ETH_SFD.
|
---|
165 | */
|
---|
166 | uint8_t sfd;
|
---|
167 | } __attribute__ ((packed));
|
---|
168 |
|
---|
169 | /** Ethernet header. */
|
---|
170 | struct eth_header {
|
---|
171 | /** Destination host Ethernet address (MAC address). */
|
---|
172 | uint8_t destination_address[ETH_ADDR];
|
---|
173 | /** Source host Ethernet address (MAC address). */
|
---|
174 | uint8_t source_address[ETH_ADDR];
|
---|
175 |
|
---|
176 | /**
|
---|
177 | * Ethernet protocol identifier in the network byte order (big endian).
|
---|
178 | * @see ethernet_protocols.h
|
---|
179 | */
|
---|
180 | uint16_t ethertype;
|
---|
181 | } __attribute__ ((packed));
|
---|
182 |
|
---|
183 | /** Ethernet header IEEE 802.3 + 802.2 extension. */
|
---|
184 | struct eth_header_lsap {
|
---|
185 | /** Ethernet header. */
|
---|
186 | eth_header_t header;
|
---|
187 |
|
---|
188 | /**
|
---|
189 | * LSAP extension.
|
---|
190 | * If DSAP and SSAP are set to ETH_LSAP_SNAP the SNAP extension is being
|
---|
191 | * used.
|
---|
192 | * If DSAP and SSAP fields are equal to ETH_RAW the raw Ethernet packet
|
---|
193 | * without any extensions is being used and the frame content starts
|
---|
194 | * rigth after the two fields.
|
---|
195 | */
|
---|
196 | eth_ieee_lsap_t lsap;
|
---|
197 | } __attribute__ ((packed));
|
---|
198 |
|
---|
199 | /** Ethernet header IEEE 802.3 + 802.2 + SNAP extensions. */
|
---|
200 | struct eth_header_snap {
|
---|
201 | /** Ethernet header. */
|
---|
202 | eth_header_t header;
|
---|
203 |
|
---|
204 | /**
|
---|
205 | * LSAP extension.
|
---|
206 | * If DSAP and SSAP are set to ETH_LSAP_SNAP the SNAP extension is being
|
---|
207 | * used.
|
---|
208 | * If DSAP and SSAP fields are equal to ETH_RAW the raw Ethernet packet
|
---|
209 | * without any extensions is being used and the frame content starts
|
---|
210 | * rigth after the two fields.
|
---|
211 | */
|
---|
212 | eth_ieee_lsap_t lsap;
|
---|
213 |
|
---|
214 | /** SNAP extension. */
|
---|
215 | eth_snap_t snap;
|
---|
216 | } __attribute__ ((packed));
|
---|
217 |
|
---|
218 | /** Ethernet Frame Check Sequence. */
|
---|
219 | typedef uint32_t eth_fcs_t;
|
---|
220 |
|
---|
221 | /** Ethernet Frame Check Sequence pointer. */
|
---|
222 | typedef eth_fcs_t *eth_fcs_ref;
|
---|
223 |
|
---|
224 | #endif
|
---|
225 |
|
---|
226 | /** @}
|
---|
227 | */
|
---|