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