]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Func.h
Add comments for functions.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Tcp4Dxe / Tcp4Func.h
1 /** @file
2
3 Copyright (c) 2005 - 2006, Intel Corporation<BR>
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<BR>
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 **/
13
14 #ifndef _TCP4_FUNC_H_
15 #define _TCP4_FUNC_H_
16
17 //
18 // Declaration of all the functions in TCP
19 // protocol. It is intended to keep tcp.h
20 // clear.
21 //
22
23 //
24 // Functions in tcp.c
25 //
26
27 /**
28 Try to find one Tcb whose <Ip, Port> equals to <IN Addr, IN Port>.
29
30 @param Addr Pointer to the IP address needs to match.
31 @param Port The port number needs to match.
32
33 @return The Tcb which matches the <Addr Port> paire exists or not.
34
35 **/
36 BOOLEAN
37 TcpFindTcbByPeer (
38 IN EFI_IPv4_ADDRESS *Addr,
39 IN TCP_PORTNO Port
40 );
41
42 /**
43 Locate the TCP_CB related to the socket pair.
44
45 @param LocalPort The local port number.
46 @param LocalIp The local IP address.
47 @param RemotePort The remote port number.
48 @param RemoteIp The remote IP address.
49 @param Syn Whether to search the listen sockets, if TRUE, the
50 listen sockets are searched.
51
52 @return Pointer to the related TCP_CB, if NULL no match is found.
53
54 **/
55 TCP_CB *
56 TcpLocateTcb (
57 IN TCP_PORTNO LocalPort,
58 IN UINT32 LocalIp,
59 IN TCP_PORTNO RemotePort,
60 IN UINT32 RemoteIp,
61 IN BOOLEAN Syn
62 );
63
64 /**
65 Insert a Tcb into the proper queue.
66
67 @param Tcb Pointer to the TCP_CB to be inserted.
68
69 @retval 0 The Tcb is inserted successfully.
70 @retval -1 Error condition occurred.
71
72 **/
73 INTN
74 TcpInsertTcb (
75 IN TCP_CB *Tcb
76 );
77
78 /**
79 Clone a TCP_CB from Tcb.
80
81 @param Tcb Pointer to the TCP_CB to be cloned.
82
83 @return Pointer to the new cloned TCP_CB, if NULL error condition occurred.
84
85 **/
86 TCP_CB *
87 TcpCloneTcb (
88 IN TCP_CB *Tcb
89 );
90
91 /**
92 Compute an ISS to be used by a new connection.
93
94 @return The result ISS.
95
96 **/
97 TCP_SEQNO
98 TcpGetIss (
99 VOID
100 );
101
102 /**
103 Initialize the Tcb local related members.
104
105 @param Tcb Pointer to the TCP_CB of this TCP instance.
106
107 **/
108 VOID
109 TcpInitTcbLocal (
110 IN TCP_CB *Tcb
111 );
112
113 /**
114 Initialize the peer related members.
115
116 @param Tcb Pointer to the TCP_CB of this TCP instance.
117 @param Seg Pointer to the segment that contains the peer's
118 intial info.
119 @param Opt Pointer to the options announced by the peer.
120
121 **/
122 VOID
123 TcpInitTcbPeer (
124 IN TCP_CB *Tcb,
125 IN TCP_SEG *Seg,
126 IN TCP_OPTION *Opt
127 );
128
129 /**
130 Get the local mss.
131
132 @param Sock Pointer to the socket to get mss
133
134 @return The mss size.
135
136 **/
137 UINT16
138 TcpGetRcvMss (
139 IN SOCKET *Sock
140 );
141
142 /**
143 Set the Tcb's state.
144
145 @param Tcb Pointer to the TCP_CB of this TCP instance.
146 @param State The state to be set.
147
148 **/
149 VOID
150 TcpSetState (
151 IN TCP_CB *Tcb,
152 IN TCP_STATES State
153 );
154
155 //
156 // Functions in Tcp4Output.c
157 //
158 /**
159 Send the segment to IP via IpIo function.
160
161 @param Tcb Pointer to the TCP_CB of this TCP instance.
162 @param Nbuf Pointer to the TCP segment to be sent.
163 @param Src Source address of the TCP segment.
164 @param Dest Destination address of the TCP segment.
165
166 @retval 0 The segment was sent out successfully.
167 @retval -1 The segment was failed to send.
168
169 **/
170 INTN
171 TcpSendIpPacket (
172 IN TCP_CB *Tcb,
173 IN NET_BUF *Nbuf,
174 IN UINT32 Src,
175 IN UINT32 Dest
176 );
177
178 /**
179 Check whether to send data/SYN/FIN and piggy back an ACK.
180
181 @param Tcb Pointer to the TCP_CB of this TCP instance.
182 @param Force Whether to ignore the sender's SWS avoidance algorithm and send
183 out data by force.
184
185 @return The number of bytes sent.
186
187 **/
188 INTN
189 TcpToSendData (
190 IN TCP_CB *Tcb,
191 IN INTN Force
192 );
193
194 /**
195 Check whether to send an ACK or delayed ACK.
196
197 @param Tcb Pointer to the TCP_CB of this TCP instance.
198
199 **/
200 VOID
201 TcpToSendAck (
202 IN TCP_CB *Tcb
203 );
204
205 /**
206 Send an ACK immediately.
207
208 @param Tcb Pointer to the TCP_CB of this TCP instance.
209
210 **/
211 VOID
212 TcpSendAck (
213 IN TCP_CB *Tcb
214 );
215
216 /**
217 Send a zero probe segment. It can be used by keepalive and zero window probe.
218
219 @param Tcb Pointer to the TCP_CB of this TCP instance.
220
221 @retval 0 The zero probe segment was sent out successfully.
222 @retval other Error condition occurred.
223
224 **/
225 INTN
226 TcpSendZeroProbe (
227 IN TCP_CB *Tcb
228 );
229
230 /**
231 Process the data and FIN flag, check whether to deliver
232 data to the socket layer.
233
234 @param Tcb Pointer to the TCP_CB of this TCP instance.
235
236 @retval 0 No error occurred to deliver data.
237 @retval -1 Error condition occurred. Proper response is to reset the
238 connection.
239
240 **/
241 INTN
242 TcpDeliverData (
243 IN TCP_CB *Tcb
244 );
245
246 /**
247 Send a RESET segment in response to the segment received.
248
249 @param Tcb Pointer to the TCP_CB of this TCP instance, may be NULL.
250 @param Head TCP header of the segment that triggers the reset.
251 @param Len Length of the segment that triggers the reset.
252 @param Local Local IP address.
253 @param Remote Remote peer's IP address.
254
255 @retval 0 A reset is sent or no need to send it.
256 @retval -1 No reset is sent.
257
258 **/
259 INTN
260 TcpSendReset (
261 IN TCP_CB *Tcb,
262 IN TCP_HEAD *Head,
263 IN INT32 Len,
264 IN UINT32 Local,
265 IN UINT32 Remote
266 );
267
268 /**
269 Compute the sequence space left in the old receive window.
270
271 @param Tcb Pointer to the TCP_CB of this TCP instance.
272
273 @return The sequence space left in the old receive window.
274
275 **/
276 UINT32
277 TcpRcvWinOld (
278 IN TCP_CB *Tcb
279 );
280
281 /**
282 Compute the current receive window.
283
284 @param Tcb Pointer to the TCP_CB of this TCP instance.
285
286 @return The size of the current receive window, in bytes.
287
288 **/
289 UINT32
290 TcpRcvWinNow (
291 IN TCP_CB *Tcb
292 );
293
294 /**
295 Retransmit the segment from sequence Seq.
296
297 @param Tcb Pointer to the TCP_CB of this TCP instance.
298 @param Seq The sequence number of the segment to be retransmitted.
299
300 @retval 0 Retransmission succeeded.
301 @retval -1 Error condition occurred.
302
303 **/
304 INTN
305 TcpRetransmit (
306 IN TCP_CB *Tcb,
307 IN TCP_SEQNO Seq
308 );
309
310 /**
311 Compute how much data to send.
312
313 @param Tcb Pointer to the TCP_CB of this TCP instance.
314 @param Force Whether to ignore the sender's SWS avoidance algorithm and send
315 out data by force.
316
317 @return The length of the data can be sent, if 0, no data can be sent.
318
319 **/
320 UINT32
321 TcpDataToSend (
322 IN TCP_CB *Tcb,
323 IN INTN Force
324 );
325
326 /**
327 Verify that the segment is in good shape.
328
329 @param Nbuf Buffer that contains the segment to be checked.
330
331 @retval 0 The segment is broken.
332 @retval 1 The segment is in good shape.
333
334 **/
335 INTN
336 TcpVerifySegment (
337 IN NET_BUF *Nbuf
338 );
339
340 /**
341 Verify that all the segments in SndQue are in good shape.
342
343 @param Head Pointer to the head node of the SndQue.
344
345 @retval 0 At least one segment is broken.
346 @retval 1 All segments in the specific queue are in good shape.
347
348 **/
349 INTN
350 TcpCheckSndQue (
351 IN LIST_ENTRY *Head
352 );
353
354 /**
355 Get a segment from the Tcb's SndQue.
356
357 @param Tcb Pointer to the TCP_CB of this TCP instance.
358 @param Seq The sequence number of the segment.
359 @param Len The maximum length of the segment.
360
361 @return Pointer to the segment, if NULL some error occurred.
362
363 **/
364 NET_BUF *
365 TcpGetSegmentSndQue (
366 IN TCP_CB *Tcb,
367 IN TCP_SEQNO Seq,
368 IN UINT32 Len
369 );
370
371 /**
372 Get a segment from the Tcb's socket buffer.
373
374 @param Tcb Pointer to the TCP_CB of this TCP instance.
375 @param Seq The sequence number of the segment.
376 @param Len The maximum length of the segment.
377
378 @return Pointer to the segment, if NULL some error occurred.
379
380 **/
381 NET_BUF *
382 TcpGetSegmentSock (
383 IN TCP_CB *Tcb,
384 IN TCP_SEQNO Seq,
385 IN UINT32 Len
386 );
387
388 /**
389 Get a segment starting from sequence Seq of a maximum
390 length of Len.
391
392 @param Tcb Pointer to the TCP_CB of this TCP instance.
393 @param Seq The sequence number of the segment.
394 @param Len The maximum length of the segment.
395
396 @return Pointer to the segment, if NULL some error occurred.
397
398 **/
399 NET_BUF *
400 TcpGetSegment (
401 IN TCP_CB *Tcb,
402 IN TCP_SEQNO Seq,
403 IN UINT32 Len
404 );
405
406 /**
407 Get the maximum SndNxt.
408
409 @param Tcb Pointer to the TCP_CB of this TCP instance.
410
411 @return The sequence number of the maximum SndNxt.
412
413 **/
414 TCP_SEQNO
415 TcpGetMaxSndNxt (
416 IN TCP_CB *Tcb
417 );
418
419 //
420 // Functions from Tcp4Input.c
421 //
422 /**
423 Process the received ICMP error messages for TCP.
424
425 @param Nbuf Buffer that contains part of the TCP segment without IP header
426 truncated from the ICMP error packet.
427 @param IcmpErr The ICMP error code interpreted from ICMP error packet.
428 @param Src Source address of the ICMP error message.
429 @param Dst Destination address of the ICMP error message.
430
431 **/
432 VOID
433 TcpIcmpInput (
434 IN NET_BUF *Nbuf,
435 IN ICMP_ERROR IcmpErr,
436 IN UINT32 Src,
437 IN UINT32 Dst
438 );
439
440 /**
441 Process the received TCP segments.
442
443 @param Nbuf Buffer that contains received TCP segment without IP header.
444 @param Src Source address of the segment, or the peer's IP address.
445 @param Dst Destination address of the segment, or the local end's IP
446 address.
447
448 @retval 0 Segment is processed successfully. It is either accepted or
449 discarded. But no connection is reset by the segment.
450 @retval -1 A connection is reset by the segment.
451
452 **/
453 INTN
454 TcpInput (
455 IN NET_BUF *Nbuf,
456 IN UINT32 Src,
457 IN UINT32 Dst
458 );
459
460 /**
461 Check whether the sequence number of the incoming segment is acceptable.
462
463 @param Tcb Pointer to the TCP_CB of this TCP instance.
464 @param Seg Pointer to the incoming segment.
465
466 @retval 1 The sequence number is acceptable.
467 @retval 0 The sequence number is not acceptable.
468
469 **/
470 INTN
471 TcpSeqAcceptable (
472 IN TCP_CB *Tcb,
473 IN TCP_SEG *Seg
474 );
475
476 /**
477 NewReno fast recovery, RFC3782.
478
479 @param Tcb Pointer to the TCP_CB of this TCP instance.
480 @param Seg Segment that triggers the fast recovery.
481
482 **/
483 VOID
484 TcpFastRecover (
485 IN TCP_CB *Tcb,
486 IN TCP_SEG *Seg
487 );
488
489 /**
490 NewReno fast loss recovery, RFC3792.
491
492 @param Tcb Pointer to the TCP_CB of this TCP instance.
493 @param Seg Segment that triggers the fast loss recovery.
494
495 **/
496 VOID
497 TcpFastLossRecover (
498 IN TCP_CB *Tcb,
499 IN TCP_SEG *Seg
500 );
501
502 /**
503 Compute the RTT as specified in RFC2988.
504
505 @param Tcb Pointer to the TCP_CB of this TCP instance.
506 @param Measure Currently measured RTT in heart beats.
507
508 **/
509 VOID
510 TcpComputeRtt (
511 IN TCP_CB *Tcb,
512 IN UINT32 Measure
513 );
514
515 /**
516 Trim off the data outside the tcb's receive window.
517
518 @param Tcb Pointer to the TCP_CB of this TCP instance.
519 @param Nbuf Pointer to the NET_BUF containing the received tcp segment.
520
521 @return 0 The data is trimmed.
522
523 **/
524 INTN
525 TcpTrimInWnd (
526 IN TCP_CB *Tcb,
527 IN NET_BUF *Nbuf
528 );
529
530 /**
531 Store the data into the reassemble queue.
532
533 @param Tcb Pointer to the TCP_CB of this TCP instance.
534 @param Nbuf Pointer to the buffer containing the data to be queued.
535
536 **/
537 VOID
538 TcpQueueData (
539 IN TCP_CB *Tcb,
540 IN NET_BUF *Nbuf
541 );
542
543 /**
544 Ajust the send queue or the retransmit queue.
545
546 @param Tcb Pointer to the TCP_CB of this TCP instance.
547 @param Ack The acknowledge seuqence number of the received segment.
548
549 **/
550 VOID
551 TcpAdjustSndQue (
552 IN TCP_CB *Tcb,
553 IN TCP_SEQNO Ack
554 );
555
556 //
557 // Functions from Tcp4Misc.c
558 //
559 /**
560 Compute the TCP segment's checksum.
561
562 @param Nbuf Pointer to the buffer that contains the TCP
563 segment.
564 @param HeadSum The checksum value of the fixed part of pseudo
565 header.
566
567 @return The checksum value.
568
569 **/
570 UINT16
571 TcpChecksum (
572 IN NET_BUF *Nbuf,
573 IN UINT16 HeadSum
574 );
575
576 /**
577 Translate the information from the head of the received TCP
578 segment Nbuf contains and fill it into a TCP_SEG structure.
579
580 @param Tcb Pointer to the TCP_CB of this TCP instance.
581 @param Nbuf Pointer to the buffer contains the TCP segment.
582
583 @return Pointer to the TCP_SEG that contains the translated TCP head information.
584
585 **/
586 TCP_SEG *
587 TcpFormatNetbuf (
588 IN TCP_CB *Tcb,
589 IN NET_BUF *Nbuf
590 );
591
592 /**
593 Initialize an active connection.
594
595 @param Tcb Pointer to the TCP_CB that wants to initiate a
596 connection.
597
598 **/
599 VOID
600 TcpOnAppConnect (
601 IN TCP_CB *Tcb
602 );
603
604 /**
605 Application has consumed some data, check whether
606 to send a window updata ack or a delayed ack.
607
608 @param Tcb Pointer to the TCP_CB of this TCP instance.
609
610 **/
611 INTN
612 TcpOnAppConsume (
613 IN TCP_CB *Tcb
614 );
615
616 /**
617 Initiate the connection close procedure, called when
618 applications want to close the connection.
619
620 @param Tcb Pointer to the TCP_CB of this TCP instance.
621
622 **/
623 VOID
624 TcpOnAppClose (
625 IN TCP_CB *Tcb
626 );
627
628 /**
629 Check whether the application's newly delivered data can be sent out.
630
631 @param Tcb Pointer to the TCP_CB of this TCP instance.
632
633 @retval 0 Whether the data is sent out or is buffered for
634 further sending.
635 @retval -1 The Tcb is not in a state that data is permitted to
636 be sent out.
637
638 **/
639 INTN
640 TcpOnAppSend (
641 IN TCP_CB *Tcb
642 );
643
644 /**
645 Abort the connection by sending a reset segment, called
646 when the application wants to abort the connection.
647
648 @param Tcb Pointer to the TCP_CB of the TCP instance.
649
650 **/
651 VOID
652 TcpOnAppAbort (
653 IN TCP_CB *Tcb
654 );
655
656 /**
657 Reset the connection related with Tcb.
658
659 @param Tcb Pointer to the TCP_CB of the connection to be
660 reset.
661
662 **/
663 VOID
664 TcpResetConnection (
665 IN TCP_CB *Tcb
666 );
667
668 //
669 // Functions in Tcp4Timer.c
670 //
671 /**
672 Close the TCP connection.
673
674 @param Tcb Pointer to the TCP_CB of this TCP instance.
675
676 **/
677 VOID
678 TcpClose (
679 IN TCP_CB *Tcb
680 );
681
682 /**
683 Heart beat timer handler, queues the DPC at TPL_CALLBACK.
684
685 @param Event Timer event signaled, ignored.
686 @param Context Context of the timer event, ignored.
687
688 **/
689 VOID
690 EFIAPI
691 TcpTicking (
692 IN EFI_EVENT Event,
693 IN VOID *Context
694 );
695
696 /**
697 Enable a TCP timer.
698
699 @param Tcb Pointer to the TCP_CB of this TCP instance.
700 @param Timer The index of the timer to be enabled.
701 @param TimeOut The timeout value of this timer.
702
703 **/
704 VOID
705 TcpSetTimer (
706 IN TCP_CB *Tcb,
707 IN UINT16 Timer,
708 IN UINT32 TimeOut
709 );
710
711 /**
712 Clear one TCP timer.
713
714 @param Tcb Pointer to the TCP_CB of this TCP instance.
715 @param Timer The index of the timer to be cleared.
716
717 **/
718 VOID
719 TcpClearTimer (
720 IN TCP_CB *Tcb,
721 IN UINT16 Timer
722 );
723
724 /**
725 Clear all TCP timers.
726
727 @param Tcb Pointer to the TCP_CB of this TCP instance.
728
729 **/
730 VOID
731 TcpClearAllTimer (
732 IN TCP_CB *Tcb
733 );
734
735 /**
736 Enable the window prober timer and set the timeout value.
737
738 @param Tcb Pointer to the TCP_CB of this TCP instance.
739
740 **/
741 VOID
742 TcpSetProbeTimer (
743 IN TCP_CB *Tcb
744 );
745
746 /**
747 Enable the keepalive timer and set the timeout value.
748
749 @param Tcb Pointer to the TCP_CB of this TCP instance.
750
751 **/
752 VOID
753 TcpSetKeepaliveTimer (
754 IN TCP_CB *Tcb
755 );
756
757 /**
758 Backoff the RTO.
759
760 @param Tcb Pointer to the TCP_CB of this TCP instance.
761
762 **/
763 VOID
764 TcpBackoffRto (
765 IN TCP_CB *Tcb
766 );
767
768 /**
769 Set the Tdp4 variable data.
770
771 @param Tcp4Service Pointer to Tcp4 service data.
772
773 @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the variable.
774 @retval other Set variable failed.
775
776 **/
777 EFI_STATUS
778 TcpSetVariableData (
779 IN TCP4_SERVICE_DATA *Tcp4Service
780 );
781
782 /**
783 Clear the variable and free the resource.
784
785 @param Tcp4Service Pointer to Tcp4 service data.
786
787 **/
788 VOID
789 TcpClearVariableData (
790 IN TCP4_SERVICE_DATA *Tcp4Service
791 );
792
793 /**
794 Install the device path protocol on the TCP instance.
795
796 @param Sock Pointer to the socket representing the TCP instance.
797
798 @retval EFI_SUCCESS The device path protocol is installed.
799 @retval other Failed to install the device path protocol.
800
801 **/
802 EFI_STATUS
803 TcpInstallDevicePath (
804 IN SOCKET *Sock
805 );
806
807 #endif