Rev 4743 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4743 | Rev 4756 | ||
---|---|---|---|
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 tcp |
29 | /** @addtogroup tcp |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** @file |
33 | /** @file |
34 | * TCP header definition. |
34 | * TCP header definition. |
35 | * Based on the RFC~793. |
35 | * Based on the RFC~793. |
36 | */ |
36 | */ |
37 | 37 | ||
38 | #ifndef __NET_TCP_HEADER_H__ |
38 | #ifndef __NET_TCP_HEADER_H__ |
39 | #define __NET_TCP_HEADER_H__ |
39 | #define __NET_TCP_HEADER_H__ |
40 | 40 | ||
41 | #include <sys/types.h> |
41 | #include <sys/types.h> |
42 | 42 | ||
43 | /** Returns the actual TCP header length. |
43 | /** Returns the actual TCP header length in bytes. |
44 | * @param header The TCP packet header. Input parameter. |
44 | * @param[in] header The TCP packet header. |
45 | */ |
45 | */ |
46 | #define TCP_HEADER_LENGTH( header ) (( header )->header_length * 4u ) |
46 | #define TCP_HEADER_LENGTH( header ) (( header )->header_length * 4u ) |
47 | 47 | ||
48 | /** Returns the actual TCP header length. |
48 | /** Returns the TCP header length. |
49 | * @param header The TCP packet header. Input parameter. |
49 | * @param[in] length The TCP header length in bytes. |
50 | */ |
50 | */ |
51 | #define TCP_COMPUTE_HEADER_LENGTH( length ) (( uint8_t ) (( length ) / 4u )) |
51 | #define TCP_COMPUTE_HEADER_LENGTH( length ) (( uint8_t ) (( length ) / 4u )) |
52 | 52 | ||
53 | /** Type definition of the transmission datagram header. |
53 | /** Type definition of the transmission datagram header. |
54 | * @see tcp_header |
54 | * @see tcp_header |
55 | */ |
55 | */ |
56 | typedef struct tcp_header tcp_header_t; |
56 | typedef struct tcp_header tcp_header_t; |
57 | 57 | ||
58 | /** Type definition of the transmission datagram header pointer. |
58 | /** Type definition of the transmission datagram header pointer. |
59 | * @see tcp_header |
59 | * @see tcp_header |
60 | */ |
60 | */ |
61 | typedef tcp_header_t * tcp_header_ref; |
61 | typedef tcp_header_t * tcp_header_ref; |
62 | 62 | ||
63 | /** Type definition of the transmission datagram header option. |
63 | /** Type definition of the transmission datagram header option. |
64 | * @see tcp_option |
64 | * @see tcp_option |
65 | */ |
65 | */ |
66 | typedef struct tcp_option tcp_option_t; |
66 | typedef struct tcp_option tcp_option_t; |
67 | 67 | ||
68 | /** Type definition of the transmission datagram header option pointer. |
68 | /** Type definition of the transmission datagram header option pointer. |
69 | * @see tcp_option |
69 | * @see tcp_option |
70 | */ |
70 | */ |
71 | typedef tcp_option_t * tcp_option_ref; |
71 | typedef tcp_option_t * tcp_option_ref; |
72 | 72 | ||
73 | /** Type definition of the Maximum segment size TCP option. |
73 | /** Type definition of the Maximum segment size TCP option. |
74 | * @see ... |
74 | * @see ... |
75 | */ |
75 | */ |
76 | typedef struct tcp_max_segment_size_option tcp_max_segment_size_option_t; |
76 | typedef struct tcp_max_segment_size_option tcp_max_segment_size_option_t; |
77 | 77 | ||
78 | /** Type definition of the Maximum segment size TCP option pointer. |
78 | /** Type definition of the Maximum segment size TCP option pointer. |
79 | * @see tcp_max_segment_size_option |
79 | * @see tcp_max_segment_size_option |
80 | */ |
80 | */ |
81 | typedef tcp_max_segment_size_option_t * tcp_max_segment_size_option_ref; |
81 | typedef tcp_max_segment_size_option_t * tcp_max_segment_size_option_ref; |
82 | 82 | ||
83 | /** Transmission datagram header. |
83 | /** Transmission datagram header. |
84 | */ |
84 | */ |
85 | struct tcp_header{ |
85 | struct tcp_header{ |
86 | /** The source port number. |
86 | /** The source port number. |
87 | */ |
87 | */ |
88 | uint16_t source_port; |
88 | uint16_t source_port; |
89 | /** The destination port number. |
89 | /** The destination port number. |
90 | */ |
90 | */ |
91 | uint16_t destination_port; |
91 | uint16_t destination_port; |
92 | /** The sequence number of the first data octet in this segment (except when SYN is present). |
92 | /** The sequence number of the first data octet in this segment (except when SYN is present). |
93 | * If SYN is present the sequence number is the initial sequence number (ISN) and the first data octet is ISN+1. |
93 | * If SYN is present the sequence number is the initial sequence number (ISN) and the first data octet is ISN+1. |
94 | */ |
94 | */ |
95 | uint32_t sequence_number; |
95 | uint32_t sequence_number; |
96 | /** If the ACK control bit is set this field contains the value of the next sequence number the sender of the segment is expecting to receive. |
96 | /** If the ACK control bit is set this field contains the value of the next sequence number the sender of the segment is expecting to receive. |
97 | * Once a~connection is established this is always sent. |
97 | * Once a~connection is established this is always sent. |
98 | * @see acknowledge |
98 | * @see acknowledge |
99 | */ |
99 | */ |
100 | uint32_t acknowledgement_number; |
100 | uint32_t acknowledgement_number; |
101 | #ifdef ARCH_IS_BIG_ENDIAN |
101 | #ifdef ARCH_IS_BIG_ENDIAN |
102 | /** The number of 32~bit words in the TCP Header. |
102 | /** The number of 32~bit words in the TCP Header. |
103 | * This indicates where the data begins. |
103 | * This indicates where the data begins. |
104 | * The TCP header (even one including options) is an integral number of 32~bits long. |
104 | * The TCP header (even one including options) is an integral number of 32~bits long. |
105 | */ |
105 | */ |
106 | uint8_t header_length:4; |
106 | uint8_t header_length:4; |
107 | /** Four bits reserved for future use. |
107 | /** Four bits reserved for future use. |
108 | * Must be zero. |
108 | * Must be zero. |
109 | */ |
109 | */ |
110 | uint8_t reserved1:4; |
110 | uint8_t reserved1:4; |
111 | #else |
111 | #else |
112 | /** Four bits reserved for future use. |
112 | /** Four bits reserved for future use. |
113 | * Must be zero. |
113 | * Must be zero. |
114 | */ |
114 | */ |
115 | uint8_t reserved1:4; |
115 | uint8_t reserved1:4; |
116 | /** The number of 32~bit words in the TCP Header. |
116 | /** The number of 32~bit words in the TCP Header. |
117 | * This indicates where the data begins. |
117 | * This indicates where the data begins. |
118 | * The TCP header (even one including options) is an integral number of 32~bits long. |
118 | * The TCP header (even one including options) is an integral number of 32~bits long. |
119 | */ |
119 | */ |
120 | uint8_t header_length:4; |
120 | uint8_t header_length:4; |
121 | #endif |
121 | #endif |
122 | #ifdef ARCH_IS_BIG_ENDIAN |
122 | #ifdef ARCH_IS_BIG_ENDIAN |
123 | /** Two bits reserved for future use. |
123 | /** Two bits reserved for future use. |
124 | * Must be zero. |
124 | * Must be zero. |
125 | */ |
125 | */ |
126 | uint8_t reserved2:2; |
126 | uint8_t reserved2:2; |
127 | /** Urgent Pointer field significant. |
127 | /** Urgent Pointer field significant. |
128 | * @see tcp_header:urgent_pointer |
128 | * @see tcp_header:urgent_pointer |
129 | */ |
129 | */ |
130 | uint8_t urgent:1; |
130 | uint8_t urgent:1; |
131 | /** Acknowledgment field significant |
131 | /** Acknowledgment field significant |
132 | * @see tcp_header:acknowledgement_number |
132 | * @see tcp_header:acknowledgement_number |
133 | */ |
133 | */ |
134 | uint8_t acknowledge:1; |
134 | uint8_t acknowledge:1; |
135 | /** Push function. |
135 | /** Push function. |
136 | */ |
136 | */ |
137 | uint8_t push:1; |
137 | uint8_t push:1; |
138 | /** Reset the connection. |
138 | /** Reset the connection. |
139 | */ |
139 | */ |
140 | uint8_t reset:1; |
140 | uint8_t reset:1; |
141 | /** Synchronize the sequence numbers. |
141 | /** Synchronize the sequence numbers. |
142 | */ |
142 | */ |
143 | uint8_t synchronize:1; |
143 | uint8_t synchronize:1; |
144 | /** No more data from the sender. |
144 | /** No more data from the sender. |
145 | */ |
145 | */ |
146 | uint8_t finalize:1; |
146 | uint8_t finalize:1; |
147 | #else |
147 | #else |
148 | /** No more data from the sender. |
148 | /** No more data from the sender. |
149 | */ |
149 | */ |
150 | uint8_t finalize:1; |
150 | uint8_t finalize:1; |
151 | /** Synchronize the sequence numbers. |
151 | /** Synchronize the sequence numbers. |
152 | */ |
152 | */ |
153 | uint8_t synchronize:1; |
153 | uint8_t synchronize:1; |
154 | /** Reset the connection. |
154 | /** Reset the connection. |
155 | */ |
155 | */ |
156 | uint8_t reset:1; |
156 | uint8_t reset:1; |
157 | /** Push function. |
157 | /** Push function. |
158 | */ |
158 | */ |
159 | uint8_t push:1; |
159 | uint8_t push:1; |
160 | /** Acknowledgment field significant. |
160 | /** Acknowledgment field significant. |
161 | * @see tcp_header:acknowledgement_number |
161 | * @see tcp_header:acknowledgement_number |
162 | */ |
162 | */ |
163 | uint8_t acknowledge:1; |
163 | uint8_t acknowledge:1; |
164 | /** Urgent Pointer field significant. |
164 | /** Urgent Pointer field significant. |
165 | * @see tcp_header:urgent_pointer |
165 | * @see tcp_header:urgent_pointer |
166 | */ |
166 | */ |
167 | uint8_t urgent:1; |
167 | uint8_t urgent:1; |
168 | /** Two bits reserved for future use. |
168 | /** Two bits reserved for future use. |
169 | * Must be zero. |
169 | * Must be zero. |
170 | */ |
170 | */ |
171 | uint8_t reserved2:2; |
171 | uint8_t reserved2:2; |
172 | #endif |
172 | #endif |
173 | /** The number of data octets beginning with the one indicated in the acknowledgment field which the sender of this segment is willing to accept. |
173 | /** The number of data octets beginning with the one indicated in the acknowledgment field which the sender of this segment is willing to accept. |
174 | * @see tcp_header:acknowledge |
174 | * @see tcp_header:acknowledge |
175 | */ |
175 | */ |
176 | uint16_t window; |
176 | uint16_t window; |
177 | /** The checksum field is the 16~bit one's complement of the one's complement sum of all 16~bit words in the header and text. |
177 | /** The checksum field is the 16~bit one's complement of the one's complement sum of all 16~bit words in the header and text. |
178 | * If a~segment contains an odd number of header and text octets to be checksummed, the last octet is padded on the right with zeros to form a~16~bit word for checksum purposes. |
178 | * If a~segment contains an odd number of header and text octets to be checksummed, the last octet is padded on the right with zeros to form a~16~bit word for checksum purposes. |
179 | * The pad is not transmitted as part of the segment. |
179 | * The pad is not transmitted as part of the segment. |
180 | * While computing the checksum, the checksum field itself is replaced with zeros. |
180 | * While computing the checksum, the checksum field itself is replaced with zeros. |
181 | * The checksum also coves a~pseudo header conceptually. |
181 | * The checksum also coves a~pseudo header conceptually. |
182 | * The pseudo header conceptually prefixed to the TCP header contains the source address, the destination address, the protocol, and the TCP length. |
182 | * The pseudo header conceptually prefixed to the TCP header contains the source address, the destination address, the protocol, and the TCP length. |
183 | * This information gives protection against misrouted datagrams. |
183 | * This information gives protection against misrouted datagrams. |
184 | * If the computed checksum is zero, it is transmitted as all ones (the equivalent in one's complement arithmetic). |
184 | * If the computed checksum is zero, it is transmitted as all ones (the equivalent in one's complement arithmetic). |
185 | */ |
185 | */ |
186 | uint16_t checksum; |
186 | uint16_t checksum; |
187 | /** This field communicates the current value of the urgent pointer as a~positive offset from the sequence number in this segment. |
187 | /** This field communicates the current value of the urgent pointer as a~positive offset from the sequence number in this segment. |
188 | * The urgent pointer points to the sequence number of the octet following the urgent data. |
188 | * The urgent pointer points to the sequence number of the octet following the urgent data. |
189 | * This field is only be interpreted in segments with the URG control bit set. |
189 | * This field is only be interpreted in segments with the URG control bit set. |
190 | * @see tcp_header:urgent |
190 | * @see tcp_header:urgent |
191 | */ |
191 | */ |
192 | uint16_t urgent_pointer; |
192 | uint16_t urgent_pointer; |
193 | } __attribute__ ((packed)); |
193 | } __attribute__ ((packed)); |
194 | 194 | ||
195 | /** Transmission datagram header option. |
195 | /** Transmission datagram header option. |
196 | */ |
196 | */ |
197 | struct tcp_option{ |
197 | struct tcp_option{ |
198 | /** Option type. |
198 | /** Option type. |
199 | */ |
199 | */ |
200 | uint8_t type; |
200 | uint8_t type; |
201 | /** Option length. |
201 | /** Option length. |
202 | */ |
202 | */ |
203 | uint8_t length; |
203 | uint8_t length; |
204 | }; |
204 | }; |
205 | 205 | ||
206 | /** Maximum segment size TCP option. |
206 | /** Maximum segment size TCP option. |
207 | */ |
207 | */ |
208 | struct tcp_max_segment_size_option{ |
208 | struct tcp_max_segment_size_option{ |
209 | /** TCP option. |
209 | /** TCP option. |
210 | * @see TCPOPT_MAX_SEGMENT_SIZE |
210 | * @see TCPOPT_MAX_SEGMENT_SIZE |
211 | * @see TCPOPT_MAX_SEGMENT_SIZE_LENGTH |
211 | * @see TCPOPT_MAX_SEGMENT_SIZE_LENGTH |
212 | */ |
212 | */ |
213 | tcp_option_t option; |
213 | tcp_option_t option; |
214 | /** Maximum segment size in bytes. |
214 | /** Maximum segment size in bytes. |
215 | */ |
215 | */ |
216 | uint16_t max_segment_size; |
216 | uint16_t max_segment_size; |
217 | } __attribute__ ((packed)); |
217 | } __attribute__ ((packed)); |
218 | 218 | ||
219 | #endif |
219 | #endif |
220 | 220 | ||
221 | /** @} |
221 | /** @} |
222 | */ |
222 | */ |
223 | 223 |