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