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.
|
---|
35 | * Based on the RFC 793.
|
---|
36 | */
|
---|
37 |
|
---|
38 | #ifndef NET_TCP_HEADER_H_
|
---|
39 | #define NET_TCP_HEADER_H_
|
---|
40 |
|
---|
41 | #include <sys/types.h>
|
---|
42 |
|
---|
43 | /** TCP header size in bytes. */
|
---|
44 | #define TCP_HEADER_SIZE sizeof(tcp_header_t)
|
---|
45 |
|
---|
46 | /** Returns the actual TCP header length in bytes.
|
---|
47 | * @param[in] header The TCP packet header.
|
---|
48 | */
|
---|
49 | #define TCP_HEADER_LENGTH(header) ((header)->header_length * 4U)
|
---|
50 |
|
---|
51 | /** Returns the TCP header length.
|
---|
52 | * @param[in] length The TCP header length in bytes.
|
---|
53 | */
|
---|
54 | #define TCP_COMPUTE_HEADER_LENGTH(length) ((uint8_t) ((length) / 4U))
|
---|
55 |
|
---|
56 | /** Type definition of the transmission datagram header.
|
---|
57 | * @see tcp_header
|
---|
58 | */
|
---|
59 | typedef struct tcp_header tcp_header_t;
|
---|
60 |
|
---|
61 | /** Type definition of the transmission datagram header option.
|
---|
62 | * @see tcp_option
|
---|
63 | */
|
---|
64 | typedef struct tcp_option tcp_option_t;
|
---|
65 |
|
---|
66 | /** Type definition of the Maximum segment size TCP option. */
|
---|
67 | typedef struct tcp_max_segment_size_option tcp_max_segment_size_option_t;
|
---|
68 |
|
---|
69 | /** Transmission datagram header. */
|
---|
70 | struct tcp_header {
|
---|
71 | uint16_t source_port;
|
---|
72 | uint16_t destination_port;
|
---|
73 | uint32_t sequence_number;
|
---|
74 | uint32_t acknowledgement_number;
|
---|
75 |
|
---|
76 | #ifdef ARCH_IS_BIG_ENDIAN
|
---|
77 | uint8_t header_length:4;
|
---|
78 | uint8_t reserved1:4;
|
---|
79 | #else
|
---|
80 | uint8_t reserved1:4;
|
---|
81 | uint8_t header_length:4;
|
---|
82 | #endif
|
---|
83 |
|
---|
84 | #ifdef ARCH_IS_BIG_ENDIAN
|
---|
85 | uint8_t reserved2:2;
|
---|
86 | uint8_t urgent:1;
|
---|
87 | uint8_t acknowledge:1;
|
---|
88 | uint8_t push:1;
|
---|
89 | uint8_t reset:1;
|
---|
90 | uint8_t synchronize:1;
|
---|
91 | uint8_t finalize:1;
|
---|
92 | #else
|
---|
93 | uint8_t finalize:1;
|
---|
94 | uint8_t synchronize:1;
|
---|
95 | uint8_t reset:1;
|
---|
96 | uint8_t push:1;
|
---|
97 | uint8_t acknowledge:1;
|
---|
98 | uint8_t urgent:1;
|
---|
99 | uint8_t reserved2:2;
|
---|
100 | #endif
|
---|
101 |
|
---|
102 | uint16_t window;
|
---|
103 | uint16_t checksum;
|
---|
104 | uint16_t urgent_pointer;
|
---|
105 | } __attribute__ ((packed));
|
---|
106 |
|
---|
107 | /** Transmission datagram header option. */
|
---|
108 | struct tcp_option {
|
---|
109 | /** Option type. */
|
---|
110 | uint8_t type;
|
---|
111 | /** Option length. */
|
---|
112 | uint8_t length;
|
---|
113 | };
|
---|
114 |
|
---|
115 | /** Maximum segment size TCP option. */
|
---|
116 | struct tcp_max_segment_size_option {
|
---|
117 | /** TCP option.
|
---|
118 | * @see TCPOPT_MAX_SEGMENT_SIZE
|
---|
119 | * @see TCPOPT_MAX_SEGMENT_SIZE_LENGTH
|
---|
120 | */
|
---|
121 | tcp_option_t option;
|
---|
122 |
|
---|
123 | /** Maximum segment size in bytes. */
|
---|
124 | uint16_t max_segment_size;
|
---|
125 | } __attribute__ ((packed));
|
---|
126 |
|
---|
127 | #endif
|
---|
128 |
|
---|
129 | /** @}
|
---|
130 | */
|
---|