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