]>
Commit | Line | Data |
---|---|---|
a3bcde70 HT |
1 | /** @file\r |
2 | TCP protocol header file.\r | |
3 | \r | |
4 | Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r | |
5 | \r | |
6 | This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php.\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #ifndef _TCP_PROTO_H_\r | |
17 | #define _TCP_PROTO_H_\r | |
18 | \r | |
19 | ///\r | |
20 | /// Tcp states don't change their order. It is used as an\r | |
21 | /// index to mTcpOutFlag and other macros.\r | |
22 | ///\r | |
23 | #define TCP_CLOSED 0\r | |
24 | #define TCP_LISTEN 1\r | |
25 | #define TCP_SYN_SENT 2\r | |
26 | #define TCP_SYN_RCVD 3\r | |
27 | #define TCP_ESTABLISHED 4\r | |
28 | #define TCP_FIN_WAIT_1 5\r | |
29 | #define TCP_FIN_WAIT_2 6\r | |
30 | #define TCP_CLOSING 7\r | |
31 | #define TCP_TIME_WAIT 8\r | |
32 | #define TCP_CLOSE_WAIT 9\r | |
33 | #define TCP_LAST_ACK 10\r | |
34 | \r | |
35 | \r | |
36 | ///\r | |
37 | /// Flags in the TCP header\r | |
38 | ///\r | |
39 | #define TCP_FLG_FIN 0x01\r | |
40 | #define TCP_FLG_SYN 0x02\r | |
41 | #define TCP_FLG_RST 0x04\r | |
42 | #define TCP_FLG_PSH 0x08\r | |
43 | #define TCP_FLG_ACK 0x10\r | |
44 | #define TCP_FLG_URG 0x20\r | |
45 | \r | |
46 | //\r | |
47 | // mask for all the flags\r | |
48 | //\r | |
49 | #define TCP_FLG_FLAG 0x3F\r | |
50 | \r | |
51 | \r | |
52 | #define TCP_CONNECT_REFUSED (-1) ///< TCP error status\r | |
53 | #define TCP_CONNECT_RESET (-2) ///< TCP error status\r | |
54 | #define TCP_CONNECT_CLOSED (-3) ///< TCP error status\r | |
55 | \r | |
56 | //\r | |
57 | // Current congestion status as suggested by RFC3782.\r | |
58 | //\r | |
59 | #define TCP_CONGEST_RECOVER 1 ///< During the NewReno fast recovery.\r | |
60 | #define TCP_CONGEST_LOSS 2 ///< Retxmit because of retxmit time out.\r | |
61 | #define TCP_CONGEST_OPEN 3 ///< TCP is opening its congestion window.\r | |
62 | \r | |
63 | //\r | |
64 | // TCP control flags\r | |
65 | //\r | |
66 | #define TCP_CTRL_NO_NAGLE 0x0001 ///< Disable Nagle algorithm\r | |
67 | #define TCP_CTRL_NO_KEEPALIVE 0x0002 ///< Disable keepalive timer.\r | |
68 | #define TCP_CTRL_NO_WS 0x0004 ///< Disable window scale option.\r | |
69 | #define TCP_CTRL_RCVD_WS 0x0008 ///< Received a wnd scale option in syn.\r | |
70 | #define TCP_CTRL_NO_TS 0x0010 ///< Disable Timestamp option.\r | |
71 | #define TCP_CTRL_RCVD_TS 0x0020 ///< Received a Timestamp option in syn.\r | |
72 | #define TCP_CTRL_SND_TS 0x0040 ///< Send Timestamp option to remote.\r | |
73 | #define TCP_CTRL_SND_URG 0x0080 ///< In urgent send mode.\r | |
74 | #define TCP_CTRL_RCVD_URG 0x0100 ///< In urgent receive mode.\r | |
75 | #define TCP_CTRL_SND_PSH 0x0200 ///< In PUSH send mode.\r | |
76 | #define TCP_CTRL_FIN_SENT 0x0400 ///< FIN is sent.\r | |
77 | #define TCP_CTRL_FIN_ACKED 0x0800 ///< FIN is ACKed.\r | |
78 | #define TCP_CTRL_TIMER_ON 0x1000 ///< At least one of the timer is on.\r | |
79 | #define TCP_CTRL_RTT_ON 0x2000 ///< The RTT measurement is on.\r | |
80 | #define TCP_CTRL_ACK_NOW 0x4000 ///< Send the ACK now, don't delay.\r | |
81 | \r | |
82 | //\r | |
83 | // Timer related values\r | |
84 | //\r | |
85 | #define TCP_TIMER_CONNECT 0 ///< Connection establishment timer.\r | |
86 | #define TCP_TIMER_REXMIT 1 ///< Retransmit timer.\r | |
87 | #define TCP_TIMER_PROBE 2 ///< Window probe timer.\r | |
88 | #define TCP_TIMER_KEEPALIVE 3 ///< Keepalive timer.\r | |
89 | #define TCP_TIMER_FINWAIT2 4 ///< FIN_WAIT_2 timer.\r | |
90 | #define TCP_TIMER_2MSL 5 ///< TIME_WAIT timer.\r | |
91 | #define TCP_TIMER_NUMBER 6 ///< The total number of the TCP timer.\r | |
92 | #define TCP_TICK 200 ///< Every TCP tick is 200ms.\r | |
93 | #define TCP_TICK_HZ 5 ///< The frequence of TCP tick.\r | |
94 | #define TCP_RTT_SHIFT 3 ///< SRTT & RTTVAR scaled by 8.\r | |
95 | #define TCP_RTO_MIN TCP_TICK_HZ ///< The minium value of RTO.\r | |
96 | #define TCP_RTO_MAX (TCP_TICK_HZ * 60) ///< The maxium value of RTO.\r | |
97 | #define TCP_FOLD_RTT 4 ///< Timeout threshod to fold RTT.\r | |
98 | \r | |
99 | //\r | |
100 | // Default values for some timers\r | |
101 | //\r | |
102 | #define TCP_MAX_LOSS 12 ///< Default max times to retxmit.\r | |
103 | #define TCP_KEEPALIVE_IDLE_MIN (TCP_TICK_HZ * 60 * 60 * 2) ///< First keepalive.\r | |
104 | #define TCP_KEEPALIVE_PERIOD (TCP_TICK_HZ * 60)\r | |
105 | #define TCP_MAX_KEEPALIVE 8\r | |
106 | #define TCP_FIN_WAIT2_TIME (2 * TCP_TICK_HZ)\r | |
107 | #define TCP_TIME_WAIT_TIME (2 * TCP_TICK_HZ)\r | |
108 | #define TCP_PAWS_24DAY (24 * 24 * 60 * 60 * TCP_TICK_HZ)\r | |
109 | #define TCP_CONNECT_TIME (75 * TCP_TICK_HZ)\r | |
110 | \r | |
111 | //\r | |
112 | // The header space to be reserved before TCP data to accomodate :\r | |
113 | // 60byte IP head + 60byte TCP head + link layer head\r | |
114 | //\r | |
115 | #define TCP_MAX_HEAD 192\r | |
116 | \r | |
117 | //\r | |
118 | // Value ranges for some control option\r | |
119 | //\r | |
120 | #define TCP_RCV_BUF_SIZE (2 * 1024 * 1024)\r | |
121 | #define TCP_RCV_BUF_SIZE_MIN (8 * 1024)\r | |
122 | #define TCP_SND_BUF_SIZE (2 * 1024 * 1024)\r | |
123 | #define TCP_SND_BUF_SIZE_MIN (8 * 1024)\r | |
124 | #define TCP_BACKLOG 10\r | |
125 | #define TCP_BACKLOG_MIN 5\r | |
126 | #define TCP_MAX_LOSS_MIN 6\r | |
127 | #define TCP_CONNECT_TIME_MIN (60 * TCP_TICK_HZ)\r | |
128 | #define TCP_MAX_KEEPALIVE_MIN 4\r | |
129 | #define TCP_KEEPALIVE_IDLE_MAX (TCP_TICK_HZ * 60 * 60 * 4)\r | |
130 | #define TCP_KEEPALIVE_PERIOD_MIN (TCP_TICK_HZ * 30)\r | |
131 | #define TCP_FIN_WAIT2_TIME_MAX (4 * TCP_TICK_HZ)\r | |
132 | #define TCP_TIME_WAIT_TIME_MAX (60 * TCP_TICK_HZ)\r | |
133 | \r | |
134 | ///\r | |
135 | /// TCP_CONNECTED: both ends have synchronized their ISN.\r | |
136 | ///\r | |
137 | #define TCP_CONNECTED(state) ((state) > TCP_SYN_RCVD)\r | |
138 | \r | |
139 | #define TCP_FIN_RCVD(State) \\r | |
140 | ( \\r | |
141 | ((State) == TCP_CLOSE_WAIT) || \\r | |
142 | ((State) == TCP_LAST_ACK) || \\r | |
143 | ((State) == TCP_CLOSING) || \\r | |
144 | ((State) == TCP_TIME_WAIT) \\r | |
145 | )\r | |
146 | \r | |
147 | #define TCP_LOCAL_CLOSED(State) \\r | |
148 | ( \\r | |
149 | ((State) == TCP_FIN_WAIT_1) || \\r | |
150 | ((State) == TCP_FIN_WAIT_2) || \\r | |
151 | ((State) == TCP_CLOSING) || \\r | |
152 | ((State) == TCP_TIME_WAIT) || \\r | |
153 | ((State) == TCP_LAST_ACK) \\r | |
154 | )\r | |
155 | \r | |
156 | //\r | |
157 | // Get the TCP_SEG point from a net buffer's ProtoData.\r | |
158 | //\r | |
159 | #define TCPSEG_NETBUF(NBuf) ((TCP_SEG *) ((NBuf)->ProtoData))\r | |
160 | \r | |
161 | //\r | |
162 | // Macros to compare sequence no\r | |
163 | //\r | |
164 | #define TCP_SEQ_LT(SeqA, SeqB) ((INT32) ((SeqA) - (SeqB)) < 0)\r | |
165 | #define TCP_SEQ_LEQ(SeqA, SeqB) ((INT32) ((SeqA) - (SeqB)) <= 0)\r | |
166 | #define TCP_SEQ_GT(SeqA, SeqB) ((INT32) ((SeqB) - (SeqA)) < 0)\r | |
167 | #define TCP_SEQ_GEQ(SeqA, SeqB) ((INT32) ((SeqB) - (SeqA)) <= 0)\r | |
168 | \r | |
169 | //\r | |
170 | // TCP_SEQ_BETWEEN return whether b <= m <= e\r | |
171 | //\r | |
172 | #define TCP_SEQ_BETWEEN(b, m, e) ((e) - (b) >= (m) - (b))\r | |
173 | \r | |
174 | //\r | |
175 | // TCP_SUB_SEQ returns Seq1 - Seq2. Make sure Seq1 >= Seq2\r | |
176 | //\r | |
177 | #define TCP_SUB_SEQ(Seq1, Seq2) ((UINT32) ((Seq1) - (Seq2)))\r | |
178 | \r | |
179 | //\r | |
180 | // Check whether Flag is on\r | |
181 | //\r | |
182 | #define TCP_FLG_ON(Value, Flag) ((BOOLEAN) (((Value) & (Flag)) != 0))\r | |
183 | //\r | |
184 | // Set and Clear operation on a Flag\r | |
185 | //\r | |
186 | #define TCP_SET_FLG(Value, Flag) ((Value) |= (Flag))\r | |
187 | #define TCP_CLEAR_FLG(Value, Flag) ((Value) &= ~(Flag))\r | |
188 | \r | |
189 | //\r | |
190 | // Test whether two peers are equal\r | |
191 | //\r | |
192 | #define TCP_PEER_EQUAL(Pa, Pb, Ver) \\r | |
193 | (((Pa)->Port == (Pb)->Port) && TcpIsIpEqual(&((Pa)->Ip), &((Pb)->Ip), Ver))\r | |
194 | \r | |
195 | //\r | |
196 | // Test whether Pa matches Pb, or Pa is more specific\r | |
197 | // than pb. Zero means wildcard.\r | |
198 | //\r | |
199 | #define TCP_PEER_MATCH(Pa, Pb, Ver) \\r | |
200 | ( \\r | |
201 | (((Pb)->Port == 0) || ((Pb)->Port == (Pa)->Port)) && \\r | |
202 | (TcpIsIpZero (&((Pb)->Ip), Ver) || TcpIsIpEqual (&((Pb)->Ip), &((Pa)->Ip), Ver)) \\r | |
203 | )\r | |
204 | \r | |
205 | #define TCP_TIMER_ON(Flag, Timer) ((Flag) & (1 << (Timer)))\r | |
206 | #define TCP_SET_TIMER(Flag, Timer) ((Flag) = (UINT16) ((Flag) | (1 << (Timer))))\r | |
207 | #define TCP_CLEAR_TIMER(Flag, Timer) ((Flag) = (UINT16) ((Flag) & (~(1 << (Timer)))))\r | |
208 | \r | |
209 | \r | |
210 | #define TCP_TIME_LT(Ta, Tb) ((INT32) ((Ta) - (Tb)) < 0)\r | |
211 | #define TCP_TIME_LEQ(Ta, Tb) ((INT32) ((Ta) - (Tb)) <= 0)\r | |
212 | #define TCP_SUB_TIME(Ta, Tb) ((UINT32) ((Ta) - (Tb)))\r | |
213 | \r | |
214 | #define TCP_MAX_WIN 0xFFFFU\r | |
215 | \r | |
216 | ///\r | |
217 | /// TCP segmentation data.\r | |
218 | ///\r | |
219 | typedef struct _TCP_SEG {\r | |
220 | TCP_SEQNO Seq; ///< Starting sequence number.\r | |
221 | TCP_SEQNO End; ///< The sequence of the last byte + 1, include SYN/FIN. End-Seq = SEG.LEN.\r | |
222 | TCP_SEQNO Ack; ///< ACK field in the segment.\r | |
223 | UINT8 Flag; ///< TCP header flags.\r | |
224 | UINT16 Urg; ///< Valid if URG flag is set.\r | |
225 | UINT32 Wnd; ///< TCP window size field.\r | |
226 | } TCP_SEG;\r | |
227 | \r | |
228 | ///\r | |
229 | /// Network endpoint, IP plus Port structure.\r | |
230 | ///\r | |
231 | typedef struct _TCP_PEER {\r | |
232 | EFI_IP_ADDRESS Ip; ///< IP address, in network byte order.\r | |
233 | TCP_PORTNO Port; ///< Port number, in network byte order.\r | |
234 | } TCP_PEER;\r | |
235 | \r | |
236 | typedef struct _TCP_CONTROL_BLOCK TCP_CB;\r | |
237 | \r | |
238 | ///\r | |
239 | /// TCP control block: it includes various states.\r | |
240 | ///\r | |
241 | struct _TCP_CONTROL_BLOCK {\r | |
242 | LIST_ENTRY List; ///< Back and forward link entry\r | |
243 | TCP_CB *Parent; ///< The parent TCP_CB structure\r | |
244 | \r | |
245 | SOCKET *Sk; ///< The socket it controled.\r | |
246 | TCP_PEER LocalEnd; ///< Local endpoint.\r | |
247 | TCP_PEER RemoteEnd;///< Remote endpoint.\r | |
248 | \r | |
249 | LIST_ENTRY SndQue; ///< Retxmission queue.\r | |
250 | LIST_ENTRY RcvQue; ///< Reassemble queue.\r | |
251 | UINT32 CtrlFlag; ///< Control flags, such as NO_NAGLE.\r | |
252 | INT32 Error; ///< Soft error status, such as TCP_CONNECT_RESET.\r | |
253 | \r | |
254 | //\r | |
255 | // RFC793 and RFC1122 defined variables\r | |
256 | //\r | |
257 | UINT8 State; ///< TCP state, such as SYN_SENT, LISTEN.\r | |
258 | UINT8 DelayedAck; ///< Number of delayed ACKs.\r | |
259 | UINT16 HeadSum; ///< Checksum of the fixed parts of pesudo\r | |
260 | ///< header: Src IP, Dst IP, 0, Protocol,\r | |
261 | ///< do not include the TCP length.\r | |
262 | \r | |
263 | TCP_SEQNO Iss; ///< Initial Sending Sequence.\r | |
264 | TCP_SEQNO SndUna; ///< First unacknowledged data.\r | |
265 | TCP_SEQNO SndNxt; ///< Next data sequence to send.\r | |
266 | TCP_SEQNO SndPsh; ///< Send PUSH point.\r | |
267 | TCP_SEQNO SndUp; ///< Send urgent point.\r | |
268 | UINT32 SndWnd; ///< Window advertised by the remote peer.\r | |
269 | UINT32 SndWndMax; ///< Max send window advertised by the peer.\r | |
270 | TCP_SEQNO SndWl1; ///< Seq number used for last window update.\r | |
271 | TCP_SEQNO SndWl2; ///< Ack no of last window update.\r | |
272 | UINT16 SndMss; ///< Max send segment size.\r | |
273 | TCP_SEQNO RcvNxt; ///< Next sequence no to receive.\r | |
274 | UINT32 RcvWnd; ///< Window advertised by the local peer.\r | |
275 | TCP_SEQNO RcvWl2; ///< The RcvNxt (or ACK) of last window update.\r | |
276 | ///< It is necessary because of delayed ACK.\r | |
277 | \r | |
278 | TCP_SEQNO RcvUp; ///< Urgent point;\r | |
279 | TCP_SEQNO Irs; ///< Initial Receiving Sequence.\r | |
280 | UINT16 RcvMss; ///< Max receive segment size.\r | |
281 | UINT16 EnabledTimer; ///< Which timer is currently enabled.\r | |
282 | UINT32 Timer[TCP_TIMER_NUMBER]; ///< When the timer will expire.\r | |
283 | INT32 NextExpire; ///< Countdown offset for the nearest timer.\r | |
284 | UINT32 Idle; ///< How long the connection is in idle.\r | |
285 | UINT32 ProbeTime; ///< The time out value for current window prober.\r | |
286 | BOOLEAN ProbeTimerOn;///< If TRUE, the probe time is on.\r | |
287 | \r | |
288 | //\r | |
289 | // RFC1323 defined variables, about window scale,\r | |
290 | // timestamp and PAWS\r | |
291 | //\r | |
292 | UINT8 SndWndScale; ///< Wndscale received from the peer.\r | |
293 | UINT8 RcvWndScale; ///< Wndscale used to scale local buffer.\r | |
294 | UINT32 TsRecent; ///< TsRecent to echo to the remote peer.\r | |
295 | UINT32 TsRecentAge; ///< When this TsRecent is updated.\r | |
296 | \r | |
297 | //\r | |
298 | // RFC2988 defined variables. about RTT measurement\r | |
299 | //\r | |
300 | TCP_SEQNO RttSeq; ///< The seq of measured segment now.\r | |
301 | UINT32 RttMeasure; ///< Currently measured RTT in heartbeats.\r | |
302 | UINT32 SRtt; ///< Smoothed RTT, scaled by 8.\r | |
303 | UINT32 RttVar; ///< RTT variance, scaled by 8.\r | |
304 | UINT32 Rto; ///< Current RTO, not scaled.\r | |
305 | \r | |
306 | //\r | |
307 | // RFC2581, and 3782 variables.\r | |
308 | // Congestion control + NewReno fast recovery.\r | |
309 | //\r | |
310 | UINT32 CWnd; ///< Sender's congestion window.\r | |
311 | UINT32 Ssthresh; ///< Slow start threshold.\r | |
312 | TCP_SEQNO Recover; ///< Recover point for NewReno.\r | |
313 | UINT16 DupAck; ///< Number of duplicate ACKs.\r | |
314 | UINT8 CongestState; ///< The current congestion state(RFC3782).\r | |
315 | UINT8 LossTimes; ///< Number of retxmit timeouts in a row.\r | |
316 | TCP_SEQNO LossRecover; ///< Recover point for retxmit.\r | |
317 | \r | |
318 | //\r | |
319 | // configuration parameters, for EFI_TCP4_PROTOCOL specification\r | |
320 | //\r | |
321 | UINT32 KeepAliveIdle; ///< Idle time before sending first probe.\r | |
322 | UINT32 KeepAlivePeriod; ///< Interval for subsequent keep alive probe.\r | |
323 | UINT8 MaxKeepAlive; ///< Maxium keep alive probe times.\r | |
324 | UINT8 KeepAliveProbes; ///< The number of keep alive probe.\r | |
325 | UINT16 MaxRexmit; ///< The maxium number of retxmit before abort.\r | |
326 | UINT32 FinWait2Timeout; ///< The FIN_WAIT_2 timeout.\r | |
327 | UINT32 TimeWaitTimeout; ///< The TIME_WAIT timeout.\r | |
328 | UINT32 ConnectTimeout; ///< The connect establishment timeout.\r | |
329 | \r | |
330 | //\r | |
331 | // configuration for tcp provided by user\r | |
332 | //\r | |
333 | BOOLEAN UseDefaultAddr;\r | |
334 | UINT8 Tos;\r | |
335 | UINT8 Ttl;\r | |
336 | EFI_IPv4_ADDRESS SubnetMask;\r | |
337 | \r | |
338 | IP_IO_IP_INFO *IpInfo; ///< Pointer reference to Ip used to send pkt\r | |
339 | UINT32 Tick; ///< 1 tick = 200ms\r | |
340 | };\r | |
341 | \r | |
342 | #endif\r |