1 | /** @file
|
---|
2 | Tcp option's routine header file.
|
---|
3 |
|
---|
4 | Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
|
---|
5 |
|
---|
6 | This program and the accompanying materials
|
---|
7 | are licensed and made available under the terms and conditions of the BSD License
|
---|
8 | which accompanies this distribution. The full text of the license may be found at
|
---|
9 | http://opensource.org/licenses/bsd-license.php.
|
---|
10 |
|
---|
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
---|
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
---|
13 |
|
---|
14 | **/
|
---|
15 |
|
---|
16 | #ifndef _TCP_OPTION_H_
|
---|
17 | #define _TCP_OPTION_H_
|
---|
18 |
|
---|
19 | //
|
---|
20 | // Supported TCP option types and their length.
|
---|
21 | //
|
---|
22 | #define TCP_OPTION_EOP 0 ///< End Of oPtion
|
---|
23 | #define TCP_OPTION_NOP 1 ///< No-Option.
|
---|
24 | #define TCP_OPTION_MSS 2 ///< Maximum Segment Size
|
---|
25 | #define TCP_OPTION_WS 3 ///< Window scale
|
---|
26 | #define TCP_OPTION_TS 8 ///< Timestamp
|
---|
27 | #define TCP_OPTION_MSS_LEN 4 ///< Length of MSS option
|
---|
28 | #define TCP_OPTION_WS_LEN 3 ///< Length of window scale option
|
---|
29 | #define TCP_OPTION_TS_LEN 10 ///< Length of timestamp option
|
---|
30 | #define TCP_OPTION_WS_ALIGNED_LEN 4 ///< Length of window scale option, aligned
|
---|
31 | #define TCP_OPTION_TS_ALIGNED_LEN 12 ///< Length of timestamp option, aligned
|
---|
32 |
|
---|
33 | //
|
---|
34 | // recommend format of timestamp window scale
|
---|
35 | // option for fast process.
|
---|
36 | //
|
---|
37 | #define TCP_OPTION_TS_FAST ((TCP_OPTION_NOP << 24) | \
|
---|
38 | (TCP_OPTION_NOP << 16) | \
|
---|
39 | (TCP_OPTION_TS << 8) | \
|
---|
40 | (TCP_OPTION_TS_LEN))
|
---|
41 |
|
---|
42 | #define TCP_OPTION_WS_FAST ((TCP_OPTION_NOP << 24) | \
|
---|
43 | (TCP_OPTION_WS << 16) | \
|
---|
44 | (TCP_OPTION_WS_LEN << 8))
|
---|
45 |
|
---|
46 | #define TCP_OPTION_MSS_FAST ((TCP_OPTION_MSS << 24) | (TCP_OPTION_MSS_LEN << 16))
|
---|
47 |
|
---|
48 | //
|
---|
49 | // Other misc definations
|
---|
50 | //
|
---|
51 | #define TCP_OPTION_RCVD_MSS 0x01
|
---|
52 | #define TCP_OPTION_RCVD_WS 0x02
|
---|
53 | #define TCP_OPTION_RCVD_TS 0x04
|
---|
54 | #define TCP_OPTION_MAX_WS 14 ///< Maxium window scale value
|
---|
55 | #define TCP_OPTION_MAX_WIN 0xffff ///< Max window size in TCP header
|
---|
56 |
|
---|
57 | ///
|
---|
58 | /// The structure to store the parse option value.
|
---|
59 | /// ParseOption only parses the options, doesn't process them.
|
---|
60 | ///
|
---|
61 | typedef struct _TCP_OPTION {
|
---|
62 | UINT8 Flag; ///< Flag such as TCP_OPTION_RCVD_MSS
|
---|
63 | UINT8 WndScale; ///< The WndScale received
|
---|
64 | UINT16 Mss; ///< The Mss received
|
---|
65 | UINT32 TSVal; ///< The TSVal field in a timestamp option
|
---|
66 | UINT32 TSEcr; ///< The TSEcr field in a timestamp option
|
---|
67 | } TCP_OPTION;
|
---|
68 |
|
---|
69 | /**
|
---|
70 | Compute the window scale value according to the given buffer size.
|
---|
71 |
|
---|
72 | @param[in] Tcb Pointer to the TCP_CB of this TCP instance.
|
---|
73 |
|
---|
74 | @return The scale value.
|
---|
75 |
|
---|
76 | **/
|
---|
77 | UINT8
|
---|
78 | TcpComputeScale (
|
---|
79 | IN TCP_CB *Tcb
|
---|
80 | );
|
---|
81 |
|
---|
82 | /**
|
---|
83 | Build the TCP option in three-way handshake.
|
---|
84 |
|
---|
85 | @param[in] Tcb Pointer to the TCP_CB of this TCP instance.
|
---|
86 | @param[in] Nbuf Pointer to the buffer to store the options.
|
---|
87 |
|
---|
88 | @return The total length of the TCP option field.
|
---|
89 |
|
---|
90 | **/
|
---|
91 | UINT16
|
---|
92 | TcpSynBuildOption (
|
---|
93 | IN TCP_CB *Tcb,
|
---|
94 | IN NET_BUF *Nbuf
|
---|
95 | );
|
---|
96 |
|
---|
97 | /**
|
---|
98 | Build the TCP option in synchronized states.
|
---|
99 |
|
---|
100 | @param[in] Tcb Pointer to the TCP_CB of this TCP instance.
|
---|
101 | @param[in] Nbuf Pointer to the buffer to store the options.
|
---|
102 |
|
---|
103 | @return The total length of the TCP option field.
|
---|
104 |
|
---|
105 | **/
|
---|
106 | UINT16
|
---|
107 | TcpBuildOption (
|
---|
108 | IN TCP_CB *Tcb,
|
---|
109 | IN NET_BUF *Nbuf
|
---|
110 | );
|
---|
111 |
|
---|
112 | /**
|
---|
113 | Parse the supported options.
|
---|
114 |
|
---|
115 | @param[in] Tcp Pointer to the TCP_CB of this TCP instance.
|
---|
116 | @param[in, out] Option Pointer to the TCP_OPTION used to store the
|
---|
117 | successfully pasrsed options.
|
---|
118 |
|
---|
119 | @retval 0 The options successfully pasrsed.
|
---|
120 | @retval -1 Ilegal option was found.
|
---|
121 |
|
---|
122 | **/
|
---|
123 | INTN
|
---|
124 | TcpParseOption (
|
---|
125 | IN TCP_HEAD *Tcp,
|
---|
126 | IN OUT TCP_OPTION *Option
|
---|
127 | );
|
---|
128 |
|
---|
129 | /**
|
---|
130 | Check the segment against PAWS.
|
---|
131 |
|
---|
132 | @param[in] Tcb Pointer to the TCP_CB of this TCP instance.
|
---|
133 | @param[in] TSVal The timestamp value.
|
---|
134 |
|
---|
135 | @retval 1 The segment passed the PAWS check.
|
---|
136 | @retval 0 The segment failed to pass the PAWS check.
|
---|
137 |
|
---|
138 | **/
|
---|
139 | UINT32
|
---|
140 | TcpPawsOK (
|
---|
141 | IN TCP_CB *Tcb,
|
---|
142 | IN UINT32 TSVal
|
---|
143 | );
|
---|
144 |
|
---|
145 | #endif
|
---|