/** @file
TCP output process routines.
Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "Tcp4Main.h"
0, // TCP_CLOSED
0, // TCP_LISTEN
TCP_FLG_SYN, // TCP_SYN_SENT
TCP_FLG_ACK, // TCP_ESTABLISHED
TCP_FLG_ACK, // TCP_FIN_WAIT_2
TCP_FLG_ACK, // TCP_TIME_WAIT
TCP_FLG_ACK, // TCP_CLOSE_WAIT
};
/**
Compute the sequence space left in the old receive window.
@param Tcb Pointer to the TCP_CB of this TCP instance.
@return The sequence space left in the old receive window.
**/
)
{
OldWin = 0;
OldWin = TCP_SUB_SEQ (
);
}
return OldWin;
}
/**
Compute the current receive window.
@param Tcb Pointer to the TCP_CB of this TCP instance.
@return The size of the current receive window, in bytes.
**/
)
{
Increase = 0;
}
//
// Receiver's SWS: don't advertise a bigger window
// unless it can be increased by at least one Mss or
// half of the receive buffer.
//
return Win;
}
return OldWin;
}
/**
Compute the value to fill in the window size field of the outgoing segment.
@param Tcb Pointer to the TCP_CB of this TCP instance.
@param Syn The flag to indicate whether the outgoing segment is a SYN
segment.
@return The value of the local receive window size used to fill the outing segment.
**/
)
{
//
// RFC requires that initial window not be scaled
//
if (Syn) {
} else {
}
}
/**
Get the maximum SndNxt.
@param Tcb Pointer to the TCP_CB of this TCP instance.
@return The sequence number of the maximum SndNxt.
**/
)
{
}
}
/**
Compute how much data to send.
@param Tcb Pointer to the TCP_CB of this TCP instance.
@param Force Whether to ignore the sender's SWS avoidance algorithm and send
out data by force.
@return The length of the data can be sent, if 0, no data can be sent.
**/
)
{
//
// TCP should NOT send data beyond the send window
// and congestion window. The right edge of send
// window is defined as SND.WL2 + SND.WND. The right
// edge of congestion window is defined as SND.UNA +
// CWND.
//
Win = 0;
}
}
//
// The data to send contains two parts: the data on the
// socket send queue, and the data on the TCB's send
// buffer. The later can be non-zero if the peer shrinks
// its advertised window.
//
}
return Len;
}
goto SetPersistTimer;
}
//
// Sender's SWS avoidance: Don't send a small segment unless
// a)A full-sized segment can be sent,
// b)at least one-half of the maximum sized windows that
// the other end has ever advertised.
// c)It can send everything it has and either it isn't
// expecting an ACK or the Nagle algorithm is disabled.
//
return Len;
}
return Len;
}
//
// RFC1122 suggests to set a timer when SWSA forbids TCP
// sending more data, and combine it with probe timer.
//
DEBUG (
"TcpDataToSend: enter persistent state for TCB %p\n",
Tcb)
);
if (!Tcb->ProbeTimerOn) {
}
}
return 0;
}
/**
Build the TCP header of the TCP segment and transmit the segment by IP.
@param Tcb Pointer to the TCP_CB of this TCP instance.
@param Nbuf Pointer to the buffer containing the segment to be sent out.
@retval 0 The segment is sent out successfully.
@retval other Error condition occurred.
**/
)
{
if (Syn) {
} else {
}
Nbuf,
sizeof (TCP_HEAD),
);
//
// Check whether to set the PSH flag.
//
if (DataLen != 0) {
}
}
//
// Check whether to set the URG flag and the urgent pointer.
//
} else {
0xffff
);
}
}
//
// update the TCP session's control information
//
if (Syn) {
}
//
// clear delayedack flag
//
Tcb->DelayedAck = 0;
}
/**
Get a segment from the Tcb's SndQue.
@param Tcb Pointer to the TCP_CB of this TCP instance.
@param Seq The sequence number of the segment.
@param Len The maximum length of the segment.
@return Pointer to the segment, if NULL some error occurred.
**/
NET_BUF *
)
{
//
// Find the segment that contains the Seq.
//
break;
}
}
//
// Return the buffer if it can be returned without
// adjustment:
//
!NET_BUF_SHARED (Node)) {
NET_GET_REF (Node);
return Node;
}
//
// Create a new buffer and copy data there.
//
return NULL;
}
}
//
// If SYN is set and out of the range, clear the flag.
// Becuase the sequence of the first byte is SEG.SEQ+1,
// adjust Offset by -1. If SYN is in the range, copy
// one byte less.
//
Offset--;
} else {
CopyLen--;
}
}
//
// If FIN is set and in the range, copy one byte less,
// and if it is out of the range, clear the flag.
//
CopyLen--;
} else {
}
}
//
// copy data to the segment
//
if (CopyLen != 0) {
goto OnError;
}
}
return Nbuf;
NetbufFree (Nbuf);
return NULL;
}
/**
Get a segment from the Tcb's socket buffer.
@param Tcb Pointer to the TCP_CB of this TCP instance.
@param Seq The sequence number of the segment.
@param Len The maximum length of the segment.
@return Pointer to the segment, if NULL some error occurred.
**/
NET_BUF *
)
{
"a netbuf for TCB %p\n",Tcb));
return NULL;
}
DataGet = 0;
if (Len != 0) {
//
// copy data to the segment.
//
}
NET_GET_REF (Nbuf);
if (DataGet != 0) {
}
return Nbuf;
}
/**
Get a segment starting from sequence Seq of a maximum
length of Len.
@param Tcb Pointer to the TCP_CB of this TCP instance.
@param Seq The sequence number of the segment.
@param Len The maximum length of the segment.
@return Pointer to the segment, if NULL some error occurred.
**/
NET_BUF *
)
{
//
// Compare the SndNxt with the max sequence number sent.
//
} else {
}
return Nbuf;
}
/**
Retransmit the segment from sequence Seq.
@param Tcb Pointer to the TCP_CB of this TCP instance.
@param Seq The sequence number of the segment to be retransmitted.
@retval 0 Retransmission succeeded.
@retval -1 Error condition occurred.
**/
)
{
//
// Compute the maxium length of retransmission. It is
// limited by three factors:
// 1. Less than SndMss
// 2. must in the current send window
// 3. will not change the boundaries of queued segments.
//
"because send window too small for TCB %p\n", Tcb));
return 0;
}
return -1;
}
goto OnError;
}
//
// The retransmitted buffer may be on the SndQue,
// trim TCP head because all the buffer on SndQue
// are headless.
//
NetbufFree (Nbuf);
return 0;
NetbufFree (Nbuf);
}
return -1;
}
/**
@param Tcb Pointer to the TCP_CB of this TCP instance.
@param Force Whether to ignore the sender's SWS avoidance algorithm and send
out data by force.
@return The number of bytes sent.
**/
)
{
Sent = 0;
return 0;
}
//
// compute how much data can be sent
//
if ((Flag & TCP_FLG_SYN) != 0) {
Len = 0;
}
//
// only send a segment without data if SYN or
// FIN is set.
//
if ((Len == 0) &&
return Sent;
}
DEBUG (
"TcpToSendData: failed to get a segment for TCB %p\n",
Tcb)
);
goto OnError;
}
//
// Set the TcpSeg in Nbuf.
//
End++;
}
if ((Flag & TCP_FLG_FIN) != 0) {
//
// Send FIN if all data is sent, and FIN is
// in the window
//
DEBUG (
"TcpToSendData: send FIN "
"to peer for TCB %p in state %s\n",
Tcb,
);
End++;
} else {
}
}
//
// don't send an empty segment here.
//
" segment for TCB %p, free it now\n", Tcb));
NetbufFree (Nbuf);
return Sent;
}
if ((Flag & TCP_FLG_FIN) != 0) {
}
goto OnError;
}
//
// All the buffer in the SndQue is headless
//
NetbufFree (Nbuf);
//
// update status in TCB
//
Tcb->DelayedAck = 0;
if ((Flag & TCP_FLG_FIN) != 0) {
}
}
}
//
// Enable RTT measurement only if not in retransmit.
// Karn's algorithm reqires not to update RTT when in loss.
//
Tcb->RttMeasure = 0;
}
goto SEND_AGAIN;
}
return Sent;
NetbufFree (Nbuf);
}
return Sent;
}
/**
Send an ACK immediately.
@param Tcb Pointer to the TCP_CB of this TCP instance.
**/
)
{
return;
}
Tcb->DelayedAck = 0;
}
NetbufFree (Nbuf);
}
/**
Send a zero probe segment. It can be used by keepalive and zero window probe.
@param Tcb Pointer to the TCP_CB of this TCP instance.
@retval 0 The zero probe segment was sent out successfully.
@retval other Error condition occurred.
**/
)
{
return -1;
}
//
// SndNxt-1 is out of window. The peer should respond
// with an ACK.
//
NetbufFree (Nbuf);
return Result;
}
/**
Check whether to send an ACK or delayed ACK.
@param Tcb Pointer to the TCP_CB of this TCP instance.
**/
)
{
//
// Generally, TCP should send a delayed ACK unless:
// 1. ACK at least every other FULL sized segment received,
// 2. Packets received out of order
// 3. Receiving window is open
//
TcpSendAck (Tcb);
return;
}
" ACK for TCB %p\n", Tcb));
//
// schedule a delayed ACK
//
Tcb->DelayedAck++;
}
/**
Send a RESET segment in response to the segment received.
@param Tcb Pointer to the TCP_CB of this TCP instance, may be NULL.
@param Head TCP header of the segment that triggers the reset.
@param Len Length of the segment that triggers the reset.
@param Local Local IP address.
@param Remote Remote peer's IP address.
@retval 0 A reset is sent or no need to send it.
@retval -1 No reset is sent.
**/
)
{
//
// Don't respond to a Reset with reset
//
return 0;
}
return -1;
}
Nbuf,
sizeof (TCP_HEAD),
);
//
// associated with it, otherwise from the Tcb
//
} else {
}
} else {
}
NetbufFree (Nbuf);
return 0;
}
/**
Verify that the segment is in good shape.
@param Nbuf Buffer that contains the segment to be checked.
@retval 0 The segment is broken.
@retval 1 The segment is in good shape.
**/
)
{
return 1;
}
return 0;
}
}
Len++;
}
Len++;
}
return 0;
}
return 1;
}
/**
Verify that all the segments in SndQue are in good shape.
@param Head Pointer to the head node of the SndQue.
@retval 0 At least one segment is broken.
@retval 1 All segments in the specific queue are in good shape.
**/
)
{
if (IsListEmpty (Head)) {
return 1;
}
//
// Initialize the Seq
//
if (TcpVerifySegment (Nbuf) == 0) {
return 0;
}
//
// All the node in the SndQue should has:
// SEG.SEQ = LAST_SEG.END
//
return 0;
}
}
return 1;
}