Rev 4350 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4350 | Rev 4728 | ||
---|---|---|---|
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 | * Names according to the linux src/include/linux/ip.h header file. |
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 | /** Type definition of the Ethernet header with all the extensions. |
56 | * @see eth_header_ex |
56 | * @see eth_header_ex |
57 | */ |
57 | */ |
58 | typedef struct eth_header_ex eth_header_ex_t; |
58 | typedef struct eth_header_ex eth_header_ex_t; |
59 | 59 | ||
60 | /** Type definition of the Ethernet header with all the extensions pointer. |
60 | /** Type definition of the Ethernet header with all the extensions pointer. |
61 | * @see eth_header |
61 | * @see eth_header |
62 | */ |
62 | */ |
63 | typedef eth_header_ex_t * eth_header_ex_ref; |
63 | typedef eth_header_ex_t * eth_header_ex_ref; |
64 | 64 | ||
65 | /** Type definition of the Ethernet header LSAP extension. |
65 | /** Type definition of the Ethernet header LSAP extension. |
66 | * @see eth_header_lsap |
66 | * @see eth_header_lsap |
67 | */ |
67 | */ |
68 | typedef struct eth_header_lsap eth_header_lsap_t; |
68 | typedef struct eth_header_lsap eth_header_lsap_t; |
69 | 69 | ||
70 | /** Type definition of the Ethernet header LSAP extension pointer. |
70 | /** Type definition of the Ethernet header LSAP extension pointer. |
71 | * @see eth_header_lsap |
71 | * @see eth_header_lsap |
72 | */ |
72 | */ |
73 | typedef eth_header_lsap_t * eth_header_lsap_ref; |
73 | typedef eth_header_lsap_t * eth_header_lsap_ref; |
74 | 74 | ||
75 | /** Type definition of the Ethernet header SNAP extension. |
75 | /** Type definition of the Ethernet header SNAP extension. |
76 | * @see eth_header_snap |
76 | * @see eth_header_snap |
77 | */ |
77 | */ |
78 | typedef struct eth_header_snap eth_header_snap_t; |
78 | typedef struct eth_header_snap eth_header_snap_t; |
79 | 79 | ||
80 | /** Type definition of the Ethernet header SNAP extension pointer. |
80 | /** Type definition of the Ethernet header SNAP extension pointer. |
81 | * @see eth_header_snap |
81 | * @see eth_header_snap |
82 | */ |
82 | */ |
83 | typedef eth_header_snap_t * eth_header_snap_ref; |
83 | typedef eth_header_snap_t * eth_header_snap_ref; |
84 | 84 | ||
85 | /** Type definition of the Ethernet header preamble. |
85 | /** Type definition of the Ethernet header preamble. |
86 | * @see preamble |
86 | * @see preamble |
87 | */ |
87 | */ |
88 | typedef struct eth_preamble eth_preamble_t; |
88 | typedef struct eth_preamble eth_preamble_t; |
89 | 89 | ||
90 | /** Type definition of the Ethernet header preamble pointer. |
90 | /** Type definition of the Ethernet header preamble pointer. |
91 | * @see eth_preamble |
91 | * @see eth_preamble |
92 | */ |
92 | */ |
93 | typedef eth_preamble_t * eth_preamble_ref; |
93 | typedef eth_preamble_t * eth_preamble_ref; |
94 | 94 | ||
95 | /** Type definition of the Ethernet header. |
95 | /** Type definition of the Ethernet header. |
96 | * @see eth_header |
96 | * @see eth_header |
97 | */ |
97 | */ |
98 | typedef struct eth_header eth_header_t; |
98 | typedef struct eth_header eth_header_t; |
99 | 99 | ||
100 | /** Type definition of the Ethernet header pointer. |
100 | /** Type definition of the Ethernet header pointer. |
101 | * @see eth_header |
101 | * @see eth_header |
102 | */ |
102 | */ |
103 | typedef eth_header_t * eth_header_ref; |
103 | typedef eth_header_t * eth_header_ref; |
104 | 104 | ||
105 | /** Ethernet header Link Service Access Point extension. |
105 | /** Ethernet header Link Service Access Point extension. |
106 | */ |
106 | */ |
107 | struct eth_header_lsap{ |
107 | struct eth_header_lsap{ |
108 | /** Destination Service Access Point identifier. |
108 | /** Destination Service Access Point identifier. |
109 | * The possible values are assigned by an IEEE committee. |
109 | * The possible values are assigned by an IEEE committee. |
110 | */ |
110 | */ |
111 | uint8_t dsap; |
111 | uint8_t dsap; |
112 | /** Source Service Access Point identifier. |
112 | /** Source Service Access Point identifier. |
113 | * The possible values are assigned by an IEEE committee. |
113 | * The possible values are assigned by an IEEE committee. |
114 | */ |
114 | */ |
115 | uint8_t ssap; |
115 | uint8_t ssap; |
116 | /** Control parameter. |
116 | /** Control parameter. |
117 | * The possible values are assigned by an IEEE committee. |
117 | * The possible values are assigned by an IEEE committee. |
118 | */ |
118 | */ |
119 | uint8_t ctrl; |
119 | uint8_t ctrl; |
120 | } __attribute__ ((packed)); |
120 | } __attribute__ ((packed)); |
121 | 121 | ||
122 | /** Ethernet header SNAP extension. |
122 | /** Ethernet header SNAP extension. |
123 | */ |
123 | */ |
124 | struct eth_header_snap{ |
124 | struct eth_header_snap{ |
125 | /** Protocol identifier or organization code. |
125 | /** Protocol identifier or organization code. |
126 | */ |
126 | */ |
127 | uint8_t proto[ 3 ]; |
127 | uint8_t protocol[ 3 ]; |
128 | /** Ethernet protocol identifier in the network byte order (big endian). |
128 | /** Ethernet protocol identifier in the network byte order (big endian). |
129 | * @see ethernet_protocols.h |
129 | * @see ethernet_protocols.h |
130 | */ |
130 | */ |
131 | uint16_t ethertype; |
131 | uint16_t ethertype; |
132 | } __attribute__ ((packed)); |
132 | } __attribute__ ((packed)); |
133 | 133 | ||
134 | /** Ethernet header preamble. |
134 | /** Ethernet header preamble. |
135 | * Used for dummy devices. |
135 | * Used for dummy devices. |
136 | */ |
136 | */ |
137 | struct eth_preamble{ |
137 | struct eth_preamble{ |
138 | /** Controlling preamble used for the frame transmission synchronization. |
138 | /** Controlling preamble used for the frame transmission synchronization. |
139 | * All should be set to ETH_PREAMBLE. |
139 | * All should be set to ETH_PREAMBLE. |
140 | */ |
140 | */ |
141 | uint8_t preamble[ 7 ]; |
141 | uint8_t preamble[ 7 ]; |
142 | /** Start of Frame Delimiter used for the frame transmission synchronization. |
142 | /** Start of Frame Delimiter used for the frame transmission synchronization. |
143 | * Should be set to ETH_SFD. |
143 | * Should be set to ETH_SFD. |
144 | */ |
144 | */ |
145 | uint8_t sfd; |
145 | uint8_t sfd; |
146 | } __attribute__ ((packed)); |
146 | } __attribute__ ((packed)); |
147 | 147 | ||
148 | /** Ethernet header. |
148 | /** Ethernet header. |
149 | */ |
149 | */ |
150 | struct eth_header{ |
150 | struct eth_header{ |
151 | /** Destination host Ethernet address (MAC address). |
151 | /** Destination host Ethernet address (MAC address). |
152 | */ |
152 | */ |
153 | uint8_t dest[ ETH_ADDR ]; |
153 | uint8_t destination_address[ ETH_ADDR ]; |
154 | /** Source host Ethernet address (MAC address). |
154 | /** Source host Ethernet address (MAC address). |
155 | */ |
155 | */ |
156 | uint8_t src[ ETH_ADDR ]; |
156 | uint8_t source_address[ ETH_ADDR ]; |
157 | /** Ethernet protocol identifier in the network byte order (big endian). |
157 | /** Ethernet protocol identifier in the network byte order (big endian). |
158 | * @see ethernet_protocols.h |
158 | * @see ethernet_protocols.h |
159 | */ |
159 | */ |
160 | uint16_t ethertype; |
160 | uint16_t ethertype; |
161 | } __attribute__ ((packed)); |
161 | } __attribute__ ((packed)); |
162 | 162 | ||
163 | /** Ethernet header with all the extensions. |
163 | /** Ethernet header with all the extensions. |
164 | */ |
164 | */ |
165 | struct eth_header_ex{ |
165 | struct eth_header_ex{ |
166 | /** Ethernet header. |
166 | /** Ethernet header. |
167 | */ |
167 | */ |
168 | eth_header_t header; |
168 | eth_header_t header; |
169 | /** LSAP extension. |
169 | /** LSAP extension. |
170 | * If DSAP and SSAP are set to ETH_LSAP_SNAP the SNAP extension is being used. |
170 | * 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. |
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. |
172 | */ |
172 | */ |
173 | eth_header_lsap_t lsap; |
173 | eth_header_lsap_t lsap; |
174 | /** SNAP extension. |
174 | /** SNAP extension. |
175 | */ |
175 | */ |
176 | eth_header_snap_t snap; |
176 | eth_header_snap_t snap; |
177 | } __attribute__ ((packed)); |
177 | } __attribute__ ((packed)); |
178 | 178 | ||
179 | /** Ethernet Frame Check Sequence. |
179 | /** Ethernet Frame Check Sequence. |
180 | */ |
180 | */ |
181 | typedef uint32_t eth_fcs_t; |
181 | typedef uint32_t eth_fcs_t; |
182 | 182 | ||
183 | /** Ethernet Frame Check Sequence pointer. |
183 | /** Ethernet Frame Check Sequence pointer. |
184 | */ |
184 | */ |
185 | typedef eth_fcs_t * eth_fcs_ref; |
185 | typedef eth_fcs_t * eth_fcs_ref; |
186 | 186 | ||
187 | #endif |
187 | #endif |
188 | 188 | ||
189 | /** @} |
189 | /** @} |
190 | */ |
190 | */ |
191 | 191 |