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