]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/TcpDxe/TcpFunc.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / NetworkPkg / TcpDxe / TcpFunc.h
CommitLineData
a3bcde70
HT
1/** @file\r
2 Declaration of external functions shared in TCP driver.\r
3\r
d551cc64 4 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
a3bcde70 5\r
ecf98fbc 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
a3bcde70
HT
7\r
8**/\r
9\r
10#ifndef _TCP_FUNC_H_\r
11#define _TCP_FUNC_H_\r
12\r
13#include "TcpOption.h"\r
14\r
15#define TCP_COMP_VAL(Min, Max, Default, Val) \\r
16 ((((Val) <= (Max)) && ((Val) >= (Min))) ? (Val) : (Default))\r
17\r
18/**\r
19 Timeout handler prototype.\r
20\r
21 @param[in, out] Tcb Pointer to the TCP_CB of this TCP instance.\r
22\r
23**/\r
24typedef\r
25VOID\r
26(*TCP_TIMER_HANDLER) (\r
d1050b9d 27 IN OUT TCP_CB *Tcb\r
a3bcde70
HT
28 );\r
29\r
30//\r
31// Functions in TcpMisc.c\r
32//\r
33\r
34/**\r
35 Initialize the Tcb locally related members.\r
36\r
37 @param[in, out] Tcb Pointer to the TCP_CB of this TCP instance.\r
38\r
39**/\r
40VOID\r
41TcpInitTcbLocal (\r
d1050b9d 42 IN OUT TCP_CB *Tcb\r
a3bcde70
HT
43 );\r
44\r
45/**\r
46 Initialize the peer related members.\r
47\r
48 @param[in, out] Tcb Pointer to the TCP_CB of this TCP instance.\r
81c6f176 49 @param[in] Seg Pointer to the segment that contains the peer's initial information.\r
a3bcde70
HT
50 @param[in] Opt Pointer to the options announced by the peer.\r
51\r
52**/\r
53VOID\r
54TcpInitTcbPeer (\r
d1050b9d
MK
55 IN OUT TCP_CB *Tcb,\r
56 IN TCP_SEG *Seg,\r
57 IN TCP_OPTION *Opt\r
a3bcde70
HT
58 );\r
59\r
60/**\r
61 Try to find one Tcb whose <Ip, Port> equals to <IN Addr, IN Port>.\r
62\r
63 @param[in] Addr Pointer to the IP address needs to match.\r
64 @param[in] Port The port number needs to match.\r
65 @param[in] Version IP_VERSION_4 indicates TCP is running on IP4 stack.\r
66 IP_VERSION_6 indicates TCP is running on IP6 stack.\r
67\r
68\r
69 @retval TRUE The Tcb which matches the <Addr Port> pairs exists.\r
70 @retval FALSE Otherwise\r
71\r
72**/\r
73BOOLEAN\r
74TcpFindTcbByPeer (\r
75 IN EFI_IP_ADDRESS *Addr,\r
76 IN TCP_PORTNO Port,\r
77 IN UINT8 Version\r
78 );\r
79\r
80/**\r
81 Locate the TCP_CB related to the socket pair.\r
82\r
83 @param[in] LocalPort The local port number.\r
84 @param[in] LocalIp The local IP address.\r
85 @param[in] RemotePort The remote port number.\r
86 @param[in] RemoteIp The remote IP address.\r
87 @param[in] Version IP_VERSION_4 indicates TCP is running on IP4 stack,\r
88 IP_VERSION_6 indicates TCP is running on IP6 stack.\r
89 @param[in] Syn If TRUE, the listen sockets are searched.\r
90\r
91 @return Pointer to the related TCP_CB. If NULL, no match is found.\r
92\r
93**/\r
94TCP_CB *\r
95TcpLocateTcb (\r
96 IN TCP_PORTNO LocalPort,\r
97 IN EFI_IP_ADDRESS *LocalIp,\r
98 IN TCP_PORTNO RemotePort,\r
99 IN EFI_IP_ADDRESS *RemoteIp,\r
100 IN UINT8 Version,\r
101 IN BOOLEAN Syn\r
102 );\r
103\r
104/**\r
105 Insert a Tcb into the proper queue.\r
106\r
107 @param[in] Tcb Pointer to the TCP_CB to be inserted.\r
108\r
109 @retval 0 The Tcb was inserted successfully.\r
110 @retval -1 An error condition occurred.\r
111\r
112**/\r
113INTN\r
114TcpInsertTcb (\r
d1050b9d 115 IN TCP_CB *Tcb\r
a3bcde70
HT
116 );\r
117\r
118/**\r
119 Clone a TCP_CB from Tcb.\r
120\r
121 @param[in] Tcb Pointer to the TCP_CB to be cloned.\r
122\r
123 @return Pointer to the new cloned TCP_CB. If NULL, an error condition occurred.\r
124\r
125**/\r
126TCP_CB *\r
127TcpCloneTcb (\r
d1050b9d 128 IN TCP_CB *Tcb\r
a3bcde70
HT
129 );\r
130\r
131/**\r
132 Compute an ISS to be used by a new connection.\r
133\r
134 @return The result ISS.\r
135\r
136**/\r
137TCP_SEQNO\r
138TcpGetIss (\r
139 VOID\r
140 );\r
141\r
142/**\r
143 Get the local mss.\r
144\r
145 @param[in] Sock Pointer to the socket to get mss.\r
146\r
147 @return The mss size.\r
148\r
149**/\r
150UINT16\r
151TcpGetRcvMss (\r
152 IN SOCKET *Sock\r
153 );\r
154\r
155/**\r
156 Set the Tcb's state.\r
157\r
158 @param[in] Tcb Pointer to the TCP_CB of this TCP instance.\r
159 @param[in] State The state to be set.\r
160\r
161**/\r
162VOID\r
163TcpSetState (\r
d1050b9d
MK
164 IN TCP_CB *Tcb,\r
165 IN UINT8 State\r
a3bcde70
HT
166 );\r
167\r
168/**\r
169 Compute the TCP segment's checksum.\r
170\r
171 @param[in] Nbuf Pointer to the buffer that contains the TCP segment.\r
172 @param[in] HeadSum The checksum value of the fixed part of pseudo header.\r
173\r
174 @return The checksum value.\r
175\r
176**/\r
177UINT16\r
178TcpChecksum (\r
d1050b9d
MK
179 IN NET_BUF *Nbuf,\r
180 IN UINT16 HeadSum\r
a3bcde70
HT
181 );\r
182\r
183/**\r
184 Translate the information from the head of the received TCP\r
185 segment Nbuf contains, and fill it into a TCP_SEG structure.\r
186\r
187 @param[in] Tcb Pointer to the TCP_CB of this TCP instance.\r
188 @param[in, out] Nbuf Pointer to the buffer contains the TCP segment.\r
189\r
190 @return Pointer to the TCP_SEG that contains the translated TCP head information.\r
191\r
192**/\r
193TCP_SEG *\r
194TcpFormatNetbuf (\r
d1050b9d
MK
195 IN TCP_CB *Tcb,\r
196 IN OUT NET_BUF *Nbuf\r
a3bcde70
HT
197 );\r
198\r
199/**\r
200 Initialize an active connection,\r
201\r
202 @param[in, out] Tcb Pointer to the TCP_CB that wants to initiate a\r
203 connection.\r
204\r
205**/\r
206VOID\r
207TcpOnAppConnect (\r
208 IN OUT TCP_CB *Tcb\r
209 );\r
210\r
211/**\r
212 Application has consumed some data, check whether\r
213 to send a window update ack or a delayed ack.\r
214\r
215 @param[in] Tcb Pointer to the TCP_CB of this TCP instance.\r
216\r
217**/\r
218VOID\r
219TcpOnAppConsume (\r
d1050b9d 220 IN TCP_CB *Tcb\r
a3bcde70
HT
221 );\r
222\r
223/**\r
224 Initiate the connection close procedure, called when\r
225 applications want to close the connection.\r
226\r
227 @param[in, out] Tcb Pointer to the TCP_CB of this TCP instance.\r
228\r
229**/\r
230VOID\r
231TcpOnAppClose (\r
d1050b9d 232 IN OUT TCP_CB *Tcb\r
a3bcde70
HT
233 );\r
234\r
235/**\r
236 Check whether the application's newly delivered data can be sent out.\r
237\r
238 @param[in, out] Tcb Pointer to the TCP_CB of this TCP instance.\r
239\r
240 @retval 0 The data has been sent out successfully.\r
241 @retval -1 The Tcb is not in a state that data is permitted to\r
242 be sent out.\r
243\r
244**/\r
245INTN\r
246TcpOnAppSend (\r
d1050b9d 247 IN OUT TCP_CB *Tcb\r
a3bcde70
HT
248 );\r
249\r
250/**\r
251 Abort the connection by sending a reset segment: called\r
252 when the application wants to abort the connection.\r
253\r
254 @param[in] Tcb Pointer to the TCP_CB of the TCP instance.\r
255\r
256**/\r
257VOID\r
258TcpOnAppAbort (\r
d1050b9d 259 IN TCP_CB *Tcb\r
a3bcde70
HT
260 );\r
261\r
262/**\r
263 Reset the connection related with Tcb.\r
264\r
265 @param[in] Tcb Pointer to the TCP_CB of the connection to be reset.\r
266\r
267**/\r
268VOID\r
269TcpResetConnection (\r
d1050b9d 270 IN TCP_CB *Tcb\r
a3bcde70
HT
271 );\r
272\r
a3bcde70
HT
273/**\r
274 Install the device path protocol on the TCP instance.\r
275\r
276 @param[in] Sock Pointer to the socket representing the TCP instance.\r
277\r
278 @retval EFI_SUCCESS The device path protocol installed.\r
279 @retval other Failed to install the device path protocol.\r
280\r
281**/\r
282EFI_STATUS\r
283TcpInstallDevicePath (\r
d1050b9d 284 IN SOCKET *Sock\r
a3bcde70
HT
285 );\r
286\r
a3bcde70
HT
287//\r
288// Functions in TcpOutput.c\r
289//\r
290\r
291/**\r
292 Compute the sequence space left in the old receive window.\r
293\r
294 @param[in] Tcb Pointer to the TCP_CB of this TCP instance.\r
295\r
296 @return The sequence space left in the old receive window.\r
297\r
298**/\r
299UINT32\r
300TcpRcvWinOld (\r
d1050b9d 301 IN TCP_CB *Tcb\r
a3bcde70
HT
302 );\r
303\r
304/**\r
305 Compute the current receive window.\r
306\r
307 @param[in] Tcb Pointer to the TCP_CB of this TCP instance.\r
308\r
309 @return The size of the current receive window, in bytes.\r
310\r
311**/\r
312UINT32\r
313TcpRcvWinNow (\r
d1050b9d 314 IN TCP_CB *Tcb\r
a3bcde70
HT
315 );\r
316\r
317/**\r
318 Get the maximum SndNxt.\r
319\r
320 @param[in] Tcb Pointer to the TCP_CB of this TCP instance.\r
321\r
322 @return The sequence number of the maximum SndNxt.\r
323\r
324**/\r
325TCP_SEQNO\r
326TcpGetMaxSndNxt (\r
d1050b9d 327 IN TCP_CB *Tcb\r
a3bcde70
HT
328 );\r
329\r
330/**\r
331 Compute how much data to send.\r
332\r
333 @param[in] Tcb Pointer to the TCP_CB of this TCP instance.\r
334 @param[in] Force If TRUE, ignore the sender's SWS avoidance algorithm\r
335 and send out data by force.\r
336\r
337 @return The length of the data that can be sent. If 0, no data can be sent.\r
338\r
339**/\r
340UINT32\r
341TcpDataToSend (\r
d1050b9d
MK
342 IN TCP_CB *Tcb,\r
343 IN INTN Force\r
a3bcde70
HT
344 );\r
345\r
346/**\r
347 Retransmit the segment from sequence Seq.\r
348\r
349 @param[in] Tcb Pointer to the TCP_CB of this TCP instance.\r
350 @param[in] Seq The sequence number of the segment to be retransmitted.\r
351\r
352 @retval 0 The retransmission succeeded.\r
353 @retval -1 An error condition occurred.\r
354\r
355**/\r
356INTN\r
357TcpRetransmit (\r
d1050b9d
MK
358 IN TCP_CB *Tcb,\r
359 IN TCP_SEQNO Seq\r
a3bcde70
HT
360 );\r
361\r
362/**\r
363 Check whether to send data/SYN/FIN and piggyback an ACK.\r
364\r
365 @param[in, out] Tcb Pointer to the TCP_CB of this TCP instance.\r
366 @param[in] Force If TRUE, ignore the sender's SWS avoidance algorithm\r
367 and send out data by force.\r
368\r
369 @return The number of bytes sent.\r
370\r
371**/\r
372INTN\r
373TcpToSendData (\r
d1050b9d
MK
374 IN OUT TCP_CB *Tcb,\r
375 IN INTN Force\r
a3bcde70
HT
376 );\r
377\r
378/**\r
379 Check whether to send an ACK or delayed ACK.\r
380\r
381 @param[in, out] Tcb Pointer to the TCP_CB of this TCP instance.\r
382\r
383**/\r
384VOID\r
385TcpToSendAck (\r
d1050b9d 386 IN OUT TCP_CB *Tcb\r
a3bcde70
HT
387 );\r
388\r
389/**\r
390 Send an ACK immediately.\r
391\r
392 @param[in, out] Tcb Pointer to the TCP_CB of this TCP instance.\r
393\r
394**/\r
395VOID\r
396TcpSendAck (\r
d1050b9d 397 IN OUT TCP_CB *Tcb\r
a3bcde70
HT
398 );\r
399\r
400/**\r
401 Send a zero probe segment. It can be used by keepalive and zero window probe.\r
402\r
403 @param[in, out] Tcb Pointer to the TCP_CB of this TCP instance.\r
404\r
405 @retval 0 The zero probe segment was sent out successfully.\r
406 @retval other An error condition occurred.\r
407\r
408**/\r
409INTN\r
410TcpSendZeroProbe (\r
d1050b9d 411 IN OUT TCP_CB *Tcb\r
a3bcde70
HT
412 );\r
413\r
414/**\r
415 Send a RESET segment in response to the segment received.\r
416\r
417 @param[in] Tcb Pointer to the TCP_CB of this TCP instance, may be NULL.\r
418 @param[in] Head TCP header of the segment that triggers the reset.\r
419 @param[in] Len Length of the segment that triggers the reset.\r
420 @param[in] Local Local IP address.\r
421 @param[in] Remote Remote peer's IP address.\r
422 @param[in] Version IP_VERSION_4 indicates TCP is running on IP4 stack,\r
423 IP_VERSION_6 indicates TCP is running on IP6 stack.\r
424\r
425 @retval 0 A reset is sent or no need to send it.\r
426 @retval -1 No reset is sent.\r
427\r
428**/\r
429INTN\r
430TcpSendReset (\r
431 IN TCP_CB *Tcb,\r
432 IN TCP_HEAD *Head,\r
433 IN INT32 Len,\r
434 IN EFI_IP_ADDRESS *Local,\r
435 IN EFI_IP_ADDRESS *Remote,\r
436 IN UINT8 Version\r
437 );\r
438\r
439/**\r
440 Verify that the segment is in good shape.\r
441\r
442 @param[in] Nbuf Buffer that contains the segment to be checked.\r
443\r
444 @retval 0 The segment is broken.\r
445 @retval 1 The segment is in good shape.\r
446\r
447**/\r
448INTN\r
449TcpVerifySegment (\r
d1050b9d 450 IN NET_BUF *Nbuf\r
a3bcde70
HT
451 );\r
452\r
453//\r
454// Functions from TcpInput.c\r
455//\r
456\r
457/**\r
458 Process the received ICMP error messages for TCP.\r
459\r
460 @param[in] Nbuf Buffer that contains part of the TCP segment without IP header\r
461 truncated from the ICMP error packet.\r
462 @param[in] IcmpErr The ICMP error code interpreted from an ICMP error packet.\r
463 @param[in] Src Source address of the ICMP error message.\r
464 @param[in] Dst Destination address of the ICMP error message.\r
465 @param[in] Version IP_VERSION_4 indicates IP4 stack, IP_VERSION_6 indicates\r
466 IP6 stack.\r
467\r
468**/\r
469VOID\r
470TcpIcmpInput (\r
471 IN NET_BUF *Nbuf,\r
472 IN UINT8 IcmpErr,\r
473 IN EFI_IP_ADDRESS *Src,\r
474 IN EFI_IP_ADDRESS *Dst,\r
475 IN UINT8 Version\r
476 );\r
477\r
478/**\r
479 Process the received TCP segments.\r
480\r
481 @param[in] Nbuf Buffer that contains received TCP segment without an IP header.\r
482 @param[in] Src Source address of the segment, or the peer's IP address.\r
483 @param[in] Dst Destination address of the segment, or the local end's IP\r
484 address.\r
485 @param[in] Version IP_VERSION_4 indicates IP4 stack, IP_VERSION_6 indicates\r
486 IP6 stack.\r
487\r
488 @retval 0 The segment processed successfully. It is either accepted or\r
489 discarded. But no connection is reset by the segment.\r
490 @retval -1 A connection is reset by the segment.\r
491\r
492**/\r
493INTN\r
494TcpInput (\r
495 IN NET_BUF *Nbuf,\r
496 IN EFI_IP_ADDRESS *Src,\r
497 IN EFI_IP_ADDRESS *Dst,\r
498 IN UINT8 Version\r
499 );\r
500\r
501//\r
502// Functions in TcpTimer.c\r
503//\r
504\r
505/**\r
506 Close the TCP connection.\r
507\r
508 @param[in, out] Tcb Pointer to the TCP_CB of this TCP instance.\r
509\r
510**/\r
511VOID\r
512TcpClose (\r
d1050b9d 513 IN OUT TCP_CB *Tcb\r
a3bcde70
HT
514 );\r
515\r
516/**\r
517 Heart beat timer handler, queues the DPC at TPL_CALLBACK.\r
518\r
519 @param[in] Event Timer event signaled, ignored.\r
520 @param[in] Context Context of the timer event, ignored.\r
521\r
522**/\r
523VOID\r
524EFIAPI\r
525TcpTicking (\r
d1050b9d
MK
526 IN EFI_EVENT Event,\r
527 IN VOID *Context\r
a3bcde70
HT
528 );\r
529\r
530/**\r
531 Enable a TCP timer.\r
532\r
533 @param[in, out] Tcb Pointer to the TCP_CB of this TCP instance.\r
534 @param[in] Timer The index of the timer to be enabled.\r
535 @param[in] TimeOut The timeout value of this timer.\r
536\r
537**/\r
538VOID\r
539TcpSetTimer (\r
d1050b9d
MK
540 IN OUT TCP_CB *Tcb,\r
541 IN UINT16 Timer,\r
542 IN UINT32 TimeOut\r
a3bcde70
HT
543 );\r
544\r
545/**\r
546 Clear one TCP timer.\r
547\r
548 @param[in, out] Tcb Pointer to the TCP_CB of this TCP instance.\r
549 @param[in] Timer The index of the timer to be cleared.\r
550\r
551**/\r
552VOID\r
553TcpClearTimer (\r
d1050b9d
MK
554 IN OUT TCP_CB *Tcb,\r
555 IN UINT16 Timer\r
a3bcde70
HT
556 );\r
557\r
558/**\r
559 Clear all TCP timers.\r
560\r
561 @param[in, out] Tcb Pointer to the TCP_CB of this TCP instance.\r
562\r
563**/\r
564VOID\r
565TcpClearAllTimer (\r
d1050b9d 566 IN OUT TCP_CB *Tcb\r
a3bcde70
HT
567 );\r
568\r
569/**\r
570 Enable the window prober timer and set the timeout value.\r
571\r
572 @param[in, out] Tcb Pointer to the TCP_CB of this TCP instance.\r
573\r
574**/\r
575VOID\r
576TcpSetProbeTimer (\r
d1050b9d 577 IN OUT TCP_CB *Tcb\r
a3bcde70
HT
578 );\r
579\r
580/**\r
581 Enable the keepalive timer and set the timeout value.\r
582\r
583 @param[in, out] Tcb Pointer to the TCP_CB of this TCP instance.\r
584\r
585**/\r
586VOID\r
587TcpSetKeepaliveTimer (\r
d1050b9d 588 IN OUT TCP_CB *Tcb\r
a3bcde70
HT
589 );\r
590\r
591//\r
592// Functions in TcpIo.c\r
593//\r
594\r
595/**\r
596 Packet receive callback function provided to IP_IO. Used to call\r
597 the proper function to handle the packet received by IP.\r
598\r
599 @param[in] Status Result of the receive request.\r
600 @param[in] IcmpErr Valid when Status is EFI_ICMP_ERROR.\r
601 @param[in] NetSession The IP session for the received packet.\r
602 @param[in] Pkt Packet received.\r
603 @param[in] Context The data provided by the user for the received packet when\r
604 the callback is registered in IP_IO_OPEN_DATA::RcvdContext.\r
605 This is an optional parameter that may be NULL.\r
606\r
607**/\r
608VOID\r
609EFIAPI\r
610TcpRxCallback (\r
d1050b9d
MK
611 IN EFI_STATUS Status,\r
612 IN UINT8 IcmpErr,\r
613 IN EFI_NET_SESSION_DATA *NetSession,\r
614 IN NET_BUF *Pkt,\r
615 IN VOID *Context OPTIONAL\r
a3bcde70
HT
616 );\r
617\r
618/**\r
619 Send the segment to IP via IpIo function.\r
620\r
621 @param[in] Tcb Pointer to the TCP_CB of this TCP instance.\r
622 @param[in] Nbuf Pointer to the TCP segment to be sent.\r
623 @param[in] Src Source address of the TCP segment.\r
624 @param[in] Dest Destination address of the TCP segment.\r
625 @param[in] Version IP_VERSION_4 or IP_VERSION_6\r
626\r
627 @retval 0 The segment was sent out successfully.\r
628 @retval -1 The segment failed to be sent.\r
629\r
630**/\r
631INTN\r
632TcpSendIpPacket (\r
633 IN TCP_CB *Tcb,\r
634 IN NET_BUF *Nbuf,\r
635 IN EFI_IP_ADDRESS *Src,\r
636 IN EFI_IP_ADDRESS *Dest,\r
637 IN UINT8 Version\r
638 );\r
639\r
640/**\r
641 Refresh the remote peer's Neighbor Cache State if already exists.\r
642\r
643 @param[in] Tcb Pointer to the TCP_CB of this TCP instance.\r
644 @param[in] Neighbor Source address of the TCP segment.\r
645 @param[in] Timeout Time in 100-ns units that this entry will remain\r
646 in the neighbor cache. A value of zero means that\r
647 the entry is permanent. A value of non-zero means\r
648 that the entry is dynamic and will be deleted\r
649 after Timeout.\r
650\r
651 @retval EFI_SUCCESS Successfully updated the neighbor relationship.\r
652 @retval EFI_NOT_STARTED The IpIo is not configured.\r
653 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.\r
654 @retval EFI_OUT_OF_RESOURCES Failed to allocate some resources.\r
655 @retval EFI_NOT_FOUND This entry is not in the neighbor table.\r
656\r
657**/\r
658EFI_STATUS\r
659Tcp6RefreshNeighbor (\r
660 IN TCP_CB *Tcb,\r
661 IN EFI_IP_ADDRESS *Neighbor,\r
662 IN UINT32 Timeout\r
663 );\r
664\r
665//\r
666// Functions in TcpDispatcher.c\r
667//\r
668\r
669/**\r
81c6f176 670 The protocol handler provided to the socket layer, used to\r
a3bcde70
HT
671 dispatch the socket level requests by calling the corresponding\r
672 TCP layer functions.\r
673\r
674 @param[in] Sock Pointer to the socket of this TCP instance.\r
675 @param[in] Request The code of this operation request.\r
676 @param[in] Data Pointer to the operation specific data passed in\r
677 together with the operation request. This is an\r
678 optional parameter that may be NULL.\r
679\r
680 @retval EFI_SUCCESS The socket request completed successfully.\r
681 @retval other The error status returned by the corresponding TCP\r
682 layer function.\r
683\r
684**/\r
685EFI_STATUS\r
686TcpDispatcher (\r
d1050b9d
MK
687 IN SOCKET *Sock,\r
688 IN UINT8 Request,\r
689 IN VOID *Data OPTIONAL\r
a3bcde70
HT
690 );\r
691\r
692#endif\r