Rev 4728 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3992 | mejdrech | 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. |
||
4728 | mejdrech | 35 | * Based on the IEEE~802.3-2005 |
3992 | mejdrech | 36 | */ |
37 | |||
38 | #ifndef __NET_ETH_HEADER_H__ |
||
39 | #define __NET_ETH_HEADER_H__ |
||
40 | |||
41 | #include <sys/types.h> |
||
42 | |||
4350 | mejdrech | 43 | /** Ethernet address length. |
44 | */ |
||
3992 | mejdrech | 45 | #define ETH_ADDR 6 |
46 | |||
4350 | mejdrech | 47 | /** Ethernet header preamble value. |
48 | */ |
||
3992 | mejdrech | 49 | #define ETH_PREAMBLE 0x55 |
50 | |||
4350 | mejdrech | 51 | /** Ethernet header start of frame value. |
52 | */ |
||
4075 | mejdrech | 53 | #define ETH_SFD 0xD5 |
3992 | mejdrech | 54 | |
4743 | mejdrech | 55 | /** IEEE 802.2 unordered information control field. |
3992 | mejdrech | 56 | */ |
4743 | mejdrech | 57 | #define IEEE_8023_2_UI 0x03 |
3992 | mejdrech | 58 | |
4743 | mejdrech | 59 | /** Type definition of the Ethernet header IEEE 802.3 + 802.2 + SNAP extensions. |
60 | * @see eth_header_snap |
||
3992 | mejdrech | 61 | */ |
4743 | mejdrech | 62 | typedef struct eth_header_snap eth_header_snap_t; |
3992 | mejdrech | 63 | |
4743 | mejdrech | 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 | |||
69 | /** Type definition of the Ethernet header IEEE 802.3 + 802.2 + SNAP extensions. |
||
3992 | mejdrech | 70 | * @see eth_header_lsap |
71 | */ |
||
72 | typedef struct eth_header_lsap eth_header_lsap_t; |
||
73 | |||
4743 | mejdrech | 74 | /** Type definition of the Ethernet header IEEE 802.3 + 802.2 extension pointer. |
3992 | mejdrech | 75 | * @see eth_header_lsap |
76 | */ |
||
77 | typedef eth_header_lsap_t * eth_header_lsap_ref; |
||
78 | |||
4743 | mejdrech | 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 | |||
3992 | mejdrech | 89 | /** Type definition of the Ethernet header SNAP extension. |
4743 | mejdrech | 90 | * @see eth_snap |
3992 | mejdrech | 91 | */ |
4743 | mejdrech | 92 | typedef struct eth_snap eth_snap_t; |
3992 | mejdrech | 93 | |
94 | /** Type definition of the Ethernet header SNAP extension pointer. |
||
4743 | mejdrech | 95 | * @see eth_snap |
3992 | mejdrech | 96 | */ |
4743 | mejdrech | 97 | typedef eth_snap_t * eth_snap_ref; |
3992 | mejdrech | 98 | |
4153 | mejdrech | 99 | /** Type definition of the Ethernet header preamble. |
100 | * @see preamble |
||
101 | */ |
||
102 | typedef struct eth_preamble eth_preamble_t; |
||
103 | |||
104 | /** Type definition of the Ethernet header preamble pointer. |
||
105 | * @see eth_preamble |
||
106 | */ |
||
4743 | mejdrech | 107 | typedef eth_preamble_t * eth_preamble_ref; |
4153 | mejdrech | 108 | |
3992 | mejdrech | 109 | /** Type definition of the Ethernet header. |
110 | * @see eth_header |
||
111 | */ |
||
112 | typedef struct eth_header eth_header_t; |
||
113 | |||
114 | /** Type definition of the Ethernet header pointer. |
||
115 | * @see eth_header |
||
116 | */ |
||
117 | typedef eth_header_t * eth_header_ref; |
||
118 | |||
119 | /** Ethernet header Link Service Access Point extension. |
||
120 | */ |
||
4743 | mejdrech | 121 | struct eth_ieee_lsap{ |
3992 | mejdrech | 122 | /** Destination Service Access Point identifier. |
123 | * The possible values are assigned by an IEEE committee. |
||
124 | */ |
||
125 | uint8_t dsap; |
||
126 | /** Source Service Access Point identifier. |
||
127 | * The possible values are assigned by an IEEE committee. |
||
128 | */ |
||
129 | uint8_t ssap; |
||
130 | /** Control parameter. |
||
131 | * The possible values are assigned by an IEEE committee. |
||
132 | */ |
||
133 | uint8_t ctrl; |
||
4243 | mejdrech | 134 | } __attribute__ ((packed)); |
3992 | mejdrech | 135 | |
136 | /** Ethernet header SNAP extension. |
||
137 | */ |
||
4743 | mejdrech | 138 | struct eth_snap{ |
3992 | mejdrech | 139 | /** Protocol identifier or organization code. |
140 | */ |
||
4728 | mejdrech | 141 | uint8_t protocol[ 3 ]; |
3992 | mejdrech | 142 | /** Ethernet protocol identifier in the network byte order (big endian). |
143 | * @see ethernet_protocols.h |
||
144 | */ |
||
145 | uint16_t ethertype; |
||
4243 | mejdrech | 146 | } __attribute__ ((packed)); |
3992 | mejdrech | 147 | |
4153 | mejdrech | 148 | /** Ethernet header preamble. |
149 | * Used for dummy devices. |
||
3992 | mejdrech | 150 | */ |
4153 | mejdrech | 151 | struct eth_preamble{ |
3992 | mejdrech | 152 | /** Controlling preamble used for the frame transmission synchronization. |
153 | * All should be set to ETH_PREAMBLE. |
||
154 | */ |
||
155 | uint8_t preamble[ 7 ]; |
||
156 | /** Start of Frame Delimiter used for the frame transmission synchronization. |
||
157 | * Should be set to ETH_SFD. |
||
158 | */ |
||
159 | uint8_t sfd; |
||
4243 | mejdrech | 160 | } __attribute__ ((packed)); |
4153 | mejdrech | 161 | |
162 | /** Ethernet header. |
||
163 | */ |
||
164 | struct eth_header{ |
||
3992 | mejdrech | 165 | /** Destination host Ethernet address (MAC address). |
166 | */ |
||
4728 | mejdrech | 167 | uint8_t destination_address[ ETH_ADDR ]; |
3992 | mejdrech | 168 | /** Source host Ethernet address (MAC address). |
169 | */ |
||
4728 | mejdrech | 170 | uint8_t source_address[ ETH_ADDR ]; |
3992 | mejdrech | 171 | /** Ethernet protocol identifier in the network byte order (big endian). |
172 | * @see ethernet_protocols.h |
||
173 | */ |
||
174 | uint16_t ethertype; |
||
4243 | mejdrech | 175 | } __attribute__ ((packed)); |
3992 | mejdrech | 176 | |
4743 | mejdrech | 177 | /** Ethernet header IEEE 802.3 + 802.2 extension. |
3992 | mejdrech | 178 | */ |
4743 | mejdrech | 179 | struct eth_header_lsap{ |
3992 | mejdrech | 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 | */ |
||
4743 | mejdrech | 187 | eth_ieee_lsap_t lsap; |
188 | } __attribute__ ((packed)); |
||
189 | |||
190 | /** Ethernet header IEEE 802.3 + 802.2 + SNAP extensions. |
||
191 | */ |
||
192 | struct eth_header_snap{ |
||
193 | /** Ethernet header. |
||
194 | */ |
||
195 | eth_header_t header; |
||
196 | /** LSAP extension. |
||
197 | * If DSAP and SSAP are set to ETH_LSAP_SNAP the SNAP extension is being used. |
||
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. |
||
199 | */ |
||
200 | eth_ieee_lsap_t lsap; |
||
3992 | mejdrech | 201 | /** SNAP extension. |
202 | */ |
||
4743 | mejdrech | 203 | eth_snap_t snap; |
4243 | mejdrech | 204 | } __attribute__ ((packed)); |
3992 | mejdrech | 205 | |
4075 | mejdrech | 206 | /** Ethernet Frame Check Sequence. |
207 | */ |
||
208 | typedef uint32_t eth_fcs_t; |
||
209 | |||
210 | /** Ethernet Frame Check Sequence pointer. |
||
211 | */ |
||
212 | typedef eth_fcs_t * eth_fcs_ref; |
||
213 | |||
3992 | mejdrech | 214 | #endif |
215 | |||
216 | /** @} |
||
217 | */ |