/** @file
Implementation of the Socket.
Copyright (c) 2009 - 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 "SockImpl.h"
/**
Get the first buffer block in the specific socket buffer.
@param[in] Sockbuf Pointer to the socket buffer.
@return Pointer to the first buffer in the queue. NULL if the queue is empty.
**/
NET_BUF *
)
{
if (IsListEmpty (NetbufList)) {
return NULL;
}
}
/**
Get the next buffer block in the specific socket buffer.
@param[in] Sockbuf Pointer to the socket buffer.
@param[in] SockEntry Pointer to the buffer block prior to the required one.
@return Pointer to the buffer block next to SockEntry. NULL if SockEntry is
the tail or head entry.
**/
NET_BUF *
)
{
) {
return NULL;
}
}
/**
User provided callback function for NetbufFromExt.
@param[in] Event The Event this notify function registered to, ignored.
**/
)
{
return;
}
/**
Get the length of the data that can be retrieved from the socket
receive buffer.
@param[in] SockBuffer Pointer to the socket receive buffer.
@param[out] IsUrg Pointer to a BOOLEAN variable.
If TRUE the data is OOB.
@param[in] BufLen The maximum length of the data buffer to
store the received data in the socket layer.
@return The length of the data can be retreived.
**/
)
{
//
// Get the first socket receive buffer
//
//
// Check whether the receive data is out of bound. If yes, calculate the maximum
// allowed length of the urgent data and output it.
//
} else {
TcpRsvData->UrgLen = 0;
}
return DataLen;
}
//
// Process the next socket receive buffer to get the maximum allowed length
// of the received data.
//
break;
}
TcpRsvData->UrgLen = 0;
} else {
}
}
}
return DataLen;
}
/**
Copy data from socket buffer to an application provided receive buffer.
@param[in] Sock Pointer to the socket.
@param[in] TcpRxData Pointer to the application provided receive buffer.
@param[in] RcvdBytes The maximum length of the data can be copied.
@param[in] IsUrg If TRUE the data is Out of Bound, FALSE the data is normal.
**/
)
{
OffSet = 0;
//
// Copy the CopyBytes data from socket receive buffer to RxData.
//
);
}
}
/**
Process the send token.
@param[in, out] Sock Pointer to the socket.
**/
)
{
//
// to determine if process a send token using
// socket layer flow control policy
//
&(Sock->SndTokenList),
);
//
// process this token
//
);
//
// Proceess it in the light of SockType
//
goto OnError;
}
FreeSpace = 0;
} else {
}
}
return;
}
/**
Get received data from the socket layer to the receive token.
@param[in, out] Sock Pointer to the socket.
@param[in, out] RcvToken Pointer to the application provided receive token.
@return The length of data received in this token.
**/
)
{
&IsUrg,
);
//
// Copy data from RcvBuffer of socket to user
// provided RxData and set the fields in TCP RxData
//
return TokenRcvdBytes;
}
/**
Process the TCP send data, buffer the tcp txdata, and append
the buffer to socket send buffer, then try to send it.
@param[in] Sock Pointer to the socket.
@param[in] TcpTxData Pointer to the application provided send buffer.
@retval EFI_SUCCESS The operation completed successfully.
@retval EFI_OUT_OF_RESOURCES Failed due to resource limits.
**/
)
{
//
// transform this TxData into a NET_BUFFER
// and insert it into Sock->SndBuffer
//
SndData = NetbufFromExt (
0,
0,
);
DEBUG (
"SockKProcessSndData: Failed to call NetBufferFromExt\n")
);
return EFI_OUT_OF_RESOURCES;
}
//
// notify the low layer protocol to handle this send token
//
return Status;
}
}
return Status;
}
}
//
// low layer protocol should really handle the sending
// process when catching SOCK_SND request
//
return Status;
}
return EFI_SUCCESS;
}
/**
Flush the tokens in the specific token list.
@param[in] Sock Pointer to the socket.
@param[in, out] PendingTokenList Pointer to the token list to be flushed.
**/
)
{
while (!IsListEmpty (PendingTokenList)) {
);
}
}
/**
Wake up the connection token while the connection is successfully established,
then try to process any pending send token.
@param[in, out] Sock Pointer to the socket.
**/
)
{
//
// check to see if some pending send token existed?
//
}
/**
Wake up the listen token while the connection is established successfully.
@param[in, out] Sock Pointer to the socket.
**/
)
{
);
DEBUG (
"SockWakeListenToken: accept a socket, now conncnt is %d",
);
}
}
/**
Wake up the receive token while some data is received.
@param[in, out] Sock Pointer to the socket.
**/
)
{
&Sock->RcvTokenList,
);
if (0 == TokenRcvdBytes) {
return ;
}
}
}
/**
Create a socket with initial data SockInitData.
@param[in] SockInitData Pointer to the initial data of the socket.
@return Pointer to the newly created socket, return NULL when an exception occurs.
**/
SOCKET *
)
{
ProtocolLength = sizeof (EFI_TCP4_PROTOCOL);
} else {
ProtocolLength = sizeof (EFI_TCP6_PROTOCOL);
}
DEBUG (
"SockCreate: Socket parent has reached its connection limit with %d ConnCnt and %d BackLog\n",
);
return NULL;
}
return NULL;
}
DEBUG (
"SockCreate: No resource to allocate SndBuffer for new socket\n")
);
goto OnError;
}
DEBUG (
"SockCreate: No resource to allocate RcvBuffer for new socket\n")
);
goto OnError;
}
//
// Install protocol on Sock->SockHandle
//
//
// copy the protodata into socket
//
&Sock->SockHandle,
&Sock->NetProtocol,
);
DEBUG (
"SockCreate: Install TCP protocol in socket failed with %r\n",
);
goto OnError;
}
//
// need to add it into Parent->ConnectionList
// if the Parent->ConnCnt < Parent->BackLog
//
DEBUG (
"SockCreate: Create a new socket and add to parent, now conncnt is %d\n",
);
}
goto OnError;
}
}
return Sock;
&Sock->NetProtocol,
);
}
}
}
return NULL;
}
/**
Destroy a socket.
@param[in, out] Sock Pointer to the socket.
**/
)
{
}
//
// Flush the completion token buffered
// by sock and rcv, snd buffer
//
if (!SOCK_IS_UNCONFIGURED (Sock)) {
}
//
// Destory the RcvBuffer Queue and SendBuffer Queue
//
//
// Remove it from parent connection list if needed
//
DEBUG (
"SockDestory: Delete a unaccepted socket from parent now conncnt is %d\n",
);
}
//
// Set the protocol guid and driver binding handle
// in the light of Sock->SockType
//
} else {
}
//
// Retrieve the protocol installed on this sock
//
);
DEBUG (
"SockDestroy: Open protocol installed on socket failed with %r\n",
);
goto FreeSock;
}
//
// Uninstall the protocol installed on this sock
// in the light of Sock->SockType
//
);
}
/**
Flush the sndBuffer and rcvBuffer of socket.
@param[in, out] Sock Pointer to the socket.
**/
)
{
//
// Clear the flag in this socket
//
//
// Flush the SndBuffer and RcvBuffer of Sock
//
//
// Signal the pending token
//
}
}
//
// Destroy the pending connection, if it is a listening socket
//
if (SOCK_IS_LISTENING (Sock)) {
Child = NET_LIST_HEAD (
);
}
}
}
/**
Set the state of the socket.
@param[in, out] Sock Pointer to the socket.
@param[in] State The new socket state to be set.
**/
)
{
}
/**
Clone a new socket, including its associated protocol control block.
@param[in] Sock Pointer to the socket to be cloned.
@return Pointer to the newly cloned socket. If NULL, an error condition occurred.
**/
SOCKET *
)
{
if (NULL == ClonedSock) {
return NULL;
}
return ClonedSock;
}
/**
Called by the low layer protocol to indicate the socket a connection is
established.
This function just changes the socket's state to SO_CONNECTED
and signals the token used for connection establishment.
@param[in, out] Sock Pointer to the socket associated with the
established connection.
**/
)
{
} else {
}
}
/**
Called by the low layer protocol to indicate the connection is closed.
This function flushes the socket, sets the state to SO_CLOSED, and signals
the close token.
@param[in, out] Sock Pointer to the socket associated with the closed
connection.
**/
)
{
}
}
}
/**
Called by low layer protocol to indicate that some data was sent or processed.
This function trims the sent data in the socket send buffer, and signals the data
token if proper.
@param[in, out] Sock Pointer to the socket.
@param[in] Count The length of the data processed or sent, in bytes.
**/
)
{
//
// To check if we can signal some snd token in this socket
//
while (Count > 0) {
);
} else {
Count = 0;
}
}
//
// to judge if we can process some send token in
// Sock->SndTokenList, if so process those send token
//
}
/**
Called by the low layer protocol to copy some data in the socket send
buffer starting from the specific offset to a buffer provided by
the caller.
@param[in] Sock Pointer to the socket.
@param[in] Offset The start point of the data to be copied.
@param[in] Len The length of the data to be copied.
@param[out] Dest Pointer to the destination to copy the data.
@return The data size copied.
**/
)
{
return NetbufQueCopy (
Len,
);
}
/**
Called by the low layer protocol to deliver received data to socket layer.
This function will append the data to the socket receive buffer, set the
urgent data length, and then check if any receive token can be signaled.
@param[in, out] Sock Pointer to the socket.
@param[in, out] NetBuffer Pointer to the buffer that contains the received data.
@param[in] UrgLen The length of the urgent data in the received data.
**/
)
{
}
/**
Get the length of the free space of the specific socket buffer.
@param[in] Sock Pointer to the socket.
@param[in] Which Flag to indicate which socket buffer to check:
either send buffer or receive buffer.
@return The length of the free space, in bytes.
**/
)
{
if (SOCK_SND_BUF == Which) {
} else {
}
return 0;
}
}
/**
Called by the low layer protocol to indicate that there will be no more data
from the communication peer.
This function sets the socket's state to SO_NO_MORE_DATA and signals all queued
IO tokens with the error status EFI_CONNECTION_FIN.
@param[in, out] Sock Pointer to the socket.
**/
)
{
}
}