]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Func.h
Fix the IN OUT modifier for parameters.
[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 OUT 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 OUT 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 OUT TCP_CB *Tcb,
152 IN UINT8 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 OUT 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 OUT 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 OUT 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 OUT 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 OUT 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 OUT 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 OUT 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 OUT 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 **/
522 VOID
523 TcpTrimInWnd (
524 IN TCP_CB *Tcb,
525 IN NET_BUF *Nbuf
526 );
527
528 /**
529 Store the data into the reassemble queue.
530
531 @param Tcb Pointer to the TCP_CB of this TCP instance.
532 @param Nbuf Pointer to the buffer containing the data to be queued.
533
534 **/
535 VOID
536 TcpQueueData (
537 IN OUT TCP_CB *Tcb,
538 IN NET_BUF *Nbuf
539 );
540
541 /**
542 Ajust the send queue or the retransmit queue.
543
544 @param Tcb Pointer to the TCP_CB of this TCP instance.
545 @param Ack The acknowledge seuqence number of the received segment.
546
547 **/
548 VOID
549 TcpAdjustSndQue (
550 IN TCP_CB *Tcb,
551 IN TCP_SEQNO Ack
552 );
553
554 //
555 // Functions from Tcp4Misc.c
556 //
557 /**
558 Compute the TCP segment's checksum.
559
560 @param Nbuf Pointer to the buffer that contains the TCP
561 segment.
562 @param HeadSum The checksum value of the fixed part of pseudo
563 header.
564
565 @return The checksum value.
566
567 **/
568 UINT16
569 TcpChecksum (
570 IN NET_BUF *Nbuf,
571 IN UINT16 HeadSum
572 );
573
574 /**
575 Translate the information from the head of the received TCP
576 segment Nbuf contains and fill it into a TCP_SEG structure.
577
578 @param Tcb Pointer to the TCP_CB of this TCP instance.
579 @param Nbuf Pointer to the buffer contains the TCP segment.
580
581 @return Pointer to the TCP_SEG that contains the translated TCP head information.
582
583 **/
584 TCP_SEG *
585 TcpFormatNetbuf (
586 IN TCP_CB *Tcb,
587 IN OUT NET_BUF *Nbuf
588 );
589
590 /**
591 Initialize an active connection.
592
593 @param Tcb Pointer to the TCP_CB that wants to initiate a
594 connection.
595
596 **/
597 VOID
598 TcpOnAppConnect (
599 IN OUT TCP_CB *Tcb
600 );
601
602 /**
603 Application has consumed some data, check whether
604 to send a window updata ack or a delayed ack.
605
606 @param Tcb Pointer to the TCP_CB of this TCP instance.
607
608 **/
609 VOID
610 TcpOnAppConsume (
611 IN TCP_CB *Tcb
612 );
613
614 /**
615 Initiate the connection close procedure, called when
616 applications want to close the connection.
617
618 @param Tcb Pointer to the TCP_CB of this TCP instance.
619
620 **/
621 VOID
622 TcpOnAppClose (
623 IN OUT TCP_CB *Tcb
624 );
625
626 /**
627 Check whether the application's newly delivered data can be sent out.
628
629 @param Tcb Pointer to the TCP_CB of this TCP instance.
630
631 @retval 0 Whether the data is sent out or is buffered for
632 further sending.
633 @retval -1 The Tcb is not in a state that data is permitted to
634 be sent out.
635
636 **/
637 INTN
638 TcpOnAppSend (
639 IN OUT TCP_CB *Tcb
640 );
641
642 /**
643 Abort the connection by sending a reset segment, called
644 when the application wants to abort the connection.
645
646 @param Tcb Pointer to the TCP_CB of the TCP instance.
647
648 **/
649 VOID
650 TcpOnAppAbort (
651 IN TCP_CB *Tcb
652 );
653
654 /**
655 Reset the connection related with Tcb.
656
657 @param Tcb Pointer to the TCP_CB of the connection to be
658 reset.
659
660 **/
661 VOID
662 TcpResetConnection (
663 IN TCP_CB *Tcb
664 );
665
666 //
667 // Functions in Tcp4Timer.c
668 //
669 /**
670 Close the TCP connection.
671
672 @param Tcb Pointer to the TCP_CB of this TCP instance.
673
674 **/
675 VOID
676 TcpClose (
677 IN OUT TCP_CB *Tcb
678 );
679
680 /**
681 Heart beat timer handler, queues the DPC at TPL_CALLBACK.
682
683 @param Event Timer event signaled, ignored.
684 @param Context Context of the timer event, ignored.
685
686 **/
687 VOID
688 EFIAPI
689 TcpTicking (
690 IN EFI_EVENT Event,
691 IN VOID *Context
692 );
693
694 /**
695 Enable a TCP timer.
696
697 @param Tcb Pointer to the TCP_CB of this TCP instance.
698 @param Timer The index of the timer to be enabled.
699 @param TimeOut The timeout value of this timer.
700
701 **/
702 VOID
703 TcpSetTimer (
704 IN OUT TCP_CB *Tcb,
705 IN UINT16 Timer,
706 IN UINT32 TimeOut
707 );
708
709 /**
710 Clear one TCP timer.
711
712 @param Tcb Pointer to the TCP_CB of this TCP instance.
713 @param Timer The index of the timer to be cleared.
714
715 **/
716 VOID
717 TcpClearTimer (
718 IN OUT TCP_CB *Tcb,
719 IN UINT16 Timer
720 );
721
722 /**
723 Clear all TCP timers.
724
725 @param Tcb Pointer to the TCP_CB of this TCP instance.
726
727 **/
728 VOID
729 TcpClearAllTimer (
730 IN OUT TCP_CB *Tcb
731 );
732
733 /**
734 Enable the window prober timer and set the timeout value.
735
736 @param Tcb Pointer to the TCP_CB of this TCP instance.
737
738 **/
739 VOID
740 TcpSetProbeTimer (
741 IN OUT TCP_CB *Tcb
742 );
743
744 /**
745 Enable the keepalive timer and set the timeout value.
746
747 @param Tcb Pointer to the TCP_CB of this TCP instance.
748
749 **/
750 VOID
751 TcpSetKeepaliveTimer (
752 IN OUT TCP_CB *Tcb
753 );
754
755 /**
756 Backoff the RTO.
757
758 @param Tcb Pointer to the TCP_CB of this TCP instance.
759
760 **/
761 VOID
762 TcpBackoffRto (
763 IN OUT TCP_CB *Tcb
764 );
765
766 /**
767 Set the Tdp4 variable data.
768
769 @param Tcp4Service Pointer to Tcp4 service data.
770
771 @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the variable.
772 @retval other Set variable failed.
773
774 **/
775 EFI_STATUS
776 TcpSetVariableData (
777 IN TCP4_SERVICE_DATA *Tcp4Service
778 );
779
780 /**
781 Clear the variable and free the resource.
782
783 @param Tcp4Service Pointer to Tcp4 service data.
784
785 **/
786 VOID
787 TcpClearVariableData (
788 IN TCP4_SERVICE_DATA *Tcp4Service
789 );
790
791 /**
792 Install the device path protocol on the TCP instance.
793
794 @param Sock Pointer to the socket representing the TCP instance.
795
796 @retval EFI_SUCCESS The device path protocol is installed.
797 @retval other Failed to install the device path protocol.
798
799 **/
800 EFI_STATUS
801 TcpInstallDevicePath (
802 IN SOCKET *Sock
803 );
804
805 #endif