Subversion Repositories HelenOS

Rev

Rev 4727 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4727 Rev 4743
Line 30... Line 30...
30
 *  @{
30
 *  @{
31
 */
31
 */
32
 
32
 
33
/** @file
33
/** @file
34
 *  TCP header definition.
34
 *  TCP header definition.
35
 *  Names according to the linux src/include/linux/tcp.h header file.
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.
-
 
44
 *  @param header The TCP packet header. Input parameter.
-
 
45
 */
-
 
46
#define TCP_HEADER_LENGTH( header )     (( header )->header_length * 4u )
-
 
47
 
-
 
48
/** Returns the actual TCP header length.
-
 
49
 *  @param header The TCP packet header. Input parameter.
-
 
50
 */
-
 
51
#define TCP_COMPUTE_HEADER_LENGTH( length )     (( uint8_t ) (( length ) / 4u ))
-
 
52
 
43
/** Type definition of the transmission datagram header.
53
/** Type definition of the transmission datagram header.
44
 *  @see tcp_header
54
 *  @see tcp_header
45
 */
55
 */
46
typedef struct tcp_header   tcp_header_t;
56
typedef struct tcp_header   tcp_header_t;
47
 
57
 
48
/** Type definition of the transmission datagram header pointer.
58
/** Type definition of the transmission datagram header pointer.
49
 *  @see tcp_header
59
 *  @see tcp_header
50
 */
60
 */
51
typedef tcp_header_t *      tcp_header_ref;
61
typedef tcp_header_t *      tcp_header_ref;
52
 
62
 
-
 
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
 
53
/** Transmission datagram header.
83
/** Transmission datagram header.
54
 */
84
 */
55
struct tcp_header{
85
struct tcp_header{
56
    /** The 16-bit source port number, used by the receiver to reply.
86
    /** The source port number.
57
     */
87
     */
58
    uint16_t    source;
88
    uint16_t    source_port;
59
    /** The 16-bit destination port number.
89
    /** The destination port number.
60
     */
90
     */
61
    uint16_t    dest;
91
    uint16_t    destination_port;
62
    /** The sequence number of the first data byte in this segment.
92
    /** The sequence number of the first data octet in this segment (except when SYN is present).
63
     *  If the SYN control bit is set, the sequence number is the initial sequence number (n) and the first data byte is n+1.
93
     *  If SYN is present the sequence number is the initial sequence number (ISN) and the first data octet is ISN+1.
64
     */
94
     */
65
    uint32_t    seq;
95
    uint32_t    sequence_number;
66
    /** If the ACK control bit is set, this field contains the value of the next sequence number that the receiver 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.
-
 
98
     *  @see acknowledge
67
     */
99
     */
68
    uint32_t    ack_seq;
100
    uint32_t    acknowledgement_number;
69
#ifdef ARCH_IS_BIG_ENDIAN
101
#ifdef ARCH_IS_BIG_ENDIAN
70
    /** The number of 32-bit words in the TCP header.
102
    /** The number of 32~bit words in the TCP Header.
71
     *  It 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.
72
     */
105
     */
73
    uint8_t doff:4;
106
    uint8_t header_length:4;
74
    /** Four bits reserved for future use.
107
    /** Four bits reserved for future use.
75
     *  Must be zero.
108
     *  Must be zero.
76
     */
109
     */
77
    uint8_t res1:4;
110
    uint8_t reserved1:4;
78
#else
111
#else
79
    /** Four bits reserved for future use.
112
    /** Four bits reserved for future use.
80
     *  Must be zero.
113
     *  Must be zero.
81
     */
114
     */
82
    uint8_t res1:4;
115
    uint8_t reserved1:4;
83
    /** The number of 32-bit words in the TCP header.
116
    /** The number of 32~bit words in the TCP Header.
84
     *  It 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.
85
     */
119
     */
86
    uint8_t doff:4;
120
    uint8_t header_length:4;
87
#endif
121
#endif
88
#ifdef ARCH_IS_BIG_ENDIAN
122
#ifdef ARCH_IS_BIG_ENDIAN
89
    /** Two bits reserved for future use.
123
    /** Two bits reserved for future use.
90
     *  Must be zero.
124
     *  Must be zero.
91
     */
125
     */
92
    uint8_t res2:2;
126
    uint8_t reserved2:2;
93
    /** Indicates that the urgent pointer field is significant in this segment.
127
    /** Urgent Pointer field significant.
-
 
128
     *  @see tcp_header:urgent_pointer
-
 
129
     */
-
 
130
    uint8_t urgent:1;
-
 
131
    /** Acknowledgment field significant
-
 
132
     *  @see tcp_header:acknowledgement_number
94
     */
133
     */
95
    uint8_t urg:1;
-
 
96
    /** Indicates that the acknowledgment field is significant in this segment.
-
 
97
     */
-
 
98
    uint8_t ack:1;
134
    uint8_t acknowledge:1;
99
    /** Push function.
135
    /** Push function.
100
     */
136
     */
101
    uint8_t psh:1;
137
    uint8_t push:1;
102
    /** Resets the connection.
138
    /** Reset the connection.
103
     */
139
     */
104
    uint8_t rst:1;
140
    uint8_t reset:1;
105
    /** Synchronizes the sequence numbers.
141
    /** Synchronize the sequence numbers.
106
     */
142
     */
107
    uint8_t syn:1;
143
    uint8_t synchronize:1;
108
    /** No more data from sender.
144
    /** No more data from the sender.
109
     */
145
     */
110
    uint8_t fin:1;
146
    uint8_t finalize:1;
111
#else
147
#else
112
    /** No more data from sender.
148
    /** No more data from the sender.
113
     */
149
     */
114
    uint8_t fin:1;
150
    uint8_t finalize:1;
115
    /** Synchronizes the sequence numbers.
151
    /** Synchronize the sequence numbers.
116
     */
152
     */
117
    uint8_t syn:1;
153
    uint8_t synchronize:1;
118
    /** Resets the connection.
154
    /** Reset the connection.
119
     */
155
     */
120
    uint8_t rst:1;
156
    uint8_t reset:1;
121
    /** Push function.
157
    /** Push function.
122
     */
158
     */
123
    uint8_t psh:1;
159
    uint8_t push:1;
124
    /** Indicates that the acknowledgment field is significant in this segment.
160
    /** Acknowledgment field significant.
-
 
161
     *  @see tcp_header:acknowledgement_number
125
     */
162
     */
126
    uint8_t ack:1;
163
    uint8_t acknowledge:1;
127
    /** Indicates that the urgent pointer field is significant in this segment.
164
    /** Urgent Pointer field significant.
-
 
165
     *  @see tcp_header:urgent_pointer
128
     */
166
     */
129
    uint8_t urg:1;
167
    uint8_t urgent:1;
130
    /** Two bits reserved for future use.
168
    /** Two bits reserved for future use.
131
     *  Must be zero.
169
     *  Must be zero.
132
     */
170
     */
133
    uint8_t res2:2;
171
    uint8_t reserved2:2;
134
#endif
172
#endif
135
    /** Used in ACK segments.
-
 
136
     *  It specifies the number of data bytes, beginning with the one indicated in the acknowledgment number field that the receiver (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
137
     */
175
     */
138
    uint16_t    window;
176
    uint16_t    window;
139
    /** The 16-bit one's complement of the one's complement sum of all 16-bit words in a pseudo-header, the TCP header, and the TCP data.
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.
140
     *  While computing the checksum, the checksum field itself is considered zero.
180
     *  While computing the checksum, the checksum field itself is replaced with zeros.
-
 
181
     *  The checksum also coves a~pseudo header conceptually.
141
     *  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.
142
     *  This information gives protection against misrouted datagrams.
183
     *  This information gives protection against misrouted datagrams.
143
     *  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).
144
     */
185
     */
145
    uint16_t    check;
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.
146
    /** Points to the first data octet following the urgent data.
188
     *  The urgent pointer points to the sequence number of the octet following the urgent data.
147
     *  Only significant when the URG control bit is set.
189
     *  This field is only be interpreted in segments with the URG control bit set.
-
 
190
     *  @see tcp_header:urgent
-
 
191
     */
-
 
192
    uint16_t    urgent_pointer;
-
 
193
} __attribute__ ((packed));
-
 
194
 
-
 
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.
148
     */
215
     */
149
    uint16_t    urg_ptr;
216
    uint16_t        max_segment_size;
150
} __attribute__ ((packed));
217
} __attribute__ ((packed));
151
 
218
 
152
#endif
219
#endif
153
 
220
 
154
/** @}
221
/** @}