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