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