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