Subversion Repositories HelenOS

Rev

Rev 4743 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4727 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 tcp
30
 *  @{
31
 */
32
 
33
/** @file
34
 *  TCP header definition.
4743 mejdrech 35
 *  Based on the RFC~793.
4727 mejdrech 36
 */
37
 
38
#ifndef __NET_TCP_HEADER_H__
39
#define __NET_TCP_HEADER_H__
40
 
41
#include <sys/types.h>
42
 
4756 mejdrech 43
/** Returns the actual TCP header length in bytes.
44
 *  @param[in] header The TCP packet header.
4743 mejdrech 45
 */
46
#define TCP_HEADER_LENGTH( header )     (( header )->header_length * 4u )
47
 
4756 mejdrech 48
/** Returns the TCP header length.
49
 *  @param[in] length The TCP header length in bytes.
4743 mejdrech 50
 */
51
#define TCP_COMPUTE_HEADER_LENGTH( length )     (( uint8_t ) (( length ) / 4u ))
52
 
4727 mejdrech 53
/** Type definition of the transmission datagram header.
54
 *  @see tcp_header
55
 */
56
typedef struct tcp_header   tcp_header_t;
57
 
58
/** Type definition of the transmission datagram header pointer.
59
 *  @see tcp_header
60
 */
61
typedef tcp_header_t *      tcp_header_ref;
62
 
4743 mejdrech 63
/** Type definition of the transmission datagram header option.
64
 *  @see tcp_option
65
 */
66
typedef struct tcp_option   tcp_option_t;
67
 
68
/** Type definition of the transmission datagram header option pointer.
69
 *  @see tcp_option
70
 */
71
typedef tcp_option_t *      tcp_option_ref;
72
 
73
/** Type definition of the Maximum segment size TCP option.
74
 *  @see ...
75
 */
76
typedef struct tcp_max_segment_size_option  tcp_max_segment_size_option_t;
77
 
78
/** Type definition of the Maximum segment size TCP option pointer.
79
 *  @see tcp_max_segment_size_option
80
 */
81
typedef tcp_max_segment_size_option_t *     tcp_max_segment_size_option_ref;
82
 
4727 mejdrech 83
/** Transmission datagram header.
84
 */
85
struct tcp_header{
4743 mejdrech 86
    /** The source port number.
4727 mejdrech 87
     */
4743 mejdrech 88
    uint16_t    source_port;
89
    /** The destination port number.
4727 mejdrech 90
     */
4743 mejdrech 91
    uint16_t    destination_port;
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.
4727 mejdrech 94
     */
4743 mejdrech 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.
97
     *  Once a~connection is established this is always sent.
98
     *  @see acknowledge
4727 mejdrech 99
     */
4743 mejdrech 100
    uint32_t    acknowledgement_number;
4727 mejdrech 101
#ifdef ARCH_IS_BIG_ENDIAN
4743 mejdrech 102
    /** The number of 32~bit words in the TCP Header.
103
     *  This indicates where the data begins.
104
     *  The TCP header (even one including options) is an integral number of 32~bits long.
4727 mejdrech 105
     */
4743 mejdrech 106
    uint8_t header_length:4;
4727 mejdrech 107
    /** Four bits reserved for future use.
108
     *  Must be zero.
109
     */
4743 mejdrech 110
    uint8_t reserved1:4;
4727 mejdrech 111
#else
112
    /** Four bits reserved for future use.
113
     *  Must be zero.
114
     */
4743 mejdrech 115
    uint8_t reserved1:4;
116
    /** The number of 32~bit words in the TCP Header.
117
     *  This indicates where the data begins.
118
     *  The TCP header (even one including options) is an integral number of 32~bits long.
4727 mejdrech 119
     */
4743 mejdrech 120
    uint8_t header_length:4;
4727 mejdrech 121
#endif
122
#ifdef ARCH_IS_BIG_ENDIAN
123
    /** Two bits reserved for future use.
124
     *  Must be zero.
125
     */
4743 mejdrech 126
    uint8_t reserved2:2;
127
    /** Urgent Pointer field significant.
128
     *  @see tcp_header:urgent_pointer
4727 mejdrech 129
     */
4743 mejdrech 130
    uint8_t urgent:1;
131
    /** Acknowledgment field significant
132
     *  @see tcp_header:acknowledgement_number
4727 mejdrech 133
     */
4743 mejdrech 134
    uint8_t acknowledge:1;
4727 mejdrech 135
    /** Push function.
136
     */
4743 mejdrech 137
    uint8_t push:1;
138
    /** Reset the connection.
4727 mejdrech 139
     */
4743 mejdrech 140
    uint8_t reset:1;
141
    /** Synchronize the sequence numbers.
4727 mejdrech 142
     */
4743 mejdrech 143
    uint8_t synchronize:1;
144
    /** No more data from the sender.
4727 mejdrech 145
     */
4743 mejdrech 146
    uint8_t finalize:1;
4727 mejdrech 147
#else
4743 mejdrech 148
    /** No more data from the sender.
4727 mejdrech 149
     */
4743 mejdrech 150
    uint8_t finalize:1;
151
    /** Synchronize the sequence numbers.
4727 mejdrech 152
     */
4743 mejdrech 153
    uint8_t synchronize:1;
154
    /** Reset the connection.
4727 mejdrech 155
     */
4743 mejdrech 156
    uint8_t reset:1;
4727 mejdrech 157
    /** Push function.
158
     */
4743 mejdrech 159
    uint8_t push:1;
160
    /** Acknowledgment field significant.
161
     *  @see tcp_header:acknowledgement_number
4727 mejdrech 162
     */
4743 mejdrech 163
    uint8_t acknowledge:1;
164
    /** Urgent Pointer field significant.
165
     *  @see tcp_header:urgent_pointer
4727 mejdrech 166
     */
4743 mejdrech 167
    uint8_t urgent:1;
4727 mejdrech 168
    /** Two bits reserved for future use.
169
     *  Must be zero.
170
     */
4743 mejdrech 171
    uint8_t reserved2:2;
4727 mejdrech 172
#endif
4743 mejdrech 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
4727 mejdrech 175
     */
176
    uint16_t    window;
4743 mejdrech 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.
179
     *  The pad is not transmitted as part of the segment.
180
     *  While computing the checksum, the checksum field itself is replaced with zeros.
181
     *  The checksum also coves a~pseudo header conceptually.
4727 mejdrech 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.
184
     *  If the computed checksum is zero, it is transmitted as all ones (the equivalent in one's complement arithmetic).
185
     */
4743 mejdrech 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.
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.
190
     *  @see tcp_header:urgent
4727 mejdrech 191
     */
4743 mejdrech 192
    uint16_t    urgent_pointer;
4727 mejdrech 193
} __attribute__ ((packed));
194
 
4743 mejdrech 195
/** Transmission datagram header option.
196
 */
197
struct tcp_option{
198
    /** Option type.
199
     */
200
    uint8_t     type;
201
    /** Option length.
202
     */
203
    uint8_t     length;
204
};
205
 
206
/** Maximum segment size TCP option.
207
 */
208
struct tcp_max_segment_size_option{
209
    /** TCP option.
210
     *  @see TCPOPT_MAX_SEGMENT_SIZE
211
     *  @see TCPOPT_MAX_SEGMENT_SIZE_LENGTH
212
     */
213
    tcp_option_t    option;
214
    /** Maximum segment size in bytes.
215
     */
216
    uint16_t        max_segment_size;
217
} __attribute__ ((packed));
218
 
4727 mejdrech 219
#endif
220
 
221
/** @}
222
 */