/** @file
Interface function of the Socket.
Copyright (c) 2009 - 2011, 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"
/**
Check whether the Event is in the List.
@param[in] List Pointer to the token list to be searched.
@param[in] Event The event to be checked.
@retval TRUE The specific Event exists in the List.
@retval FALSE The specific Event is not in the List.
**/
)
{
);
return TRUE;
}
}
return FALSE;
}
/**
Call SockTokenExistedInList() to check whether the Event is
in the related socket's lists.
@param[in] Sock Pointer to the instance's socket.
@param[in] Event The event to be checked.
@retval TRUE The Event exists in related socket's lists.
@retval FALSE The Event is not in related socket's lists.
**/
)
{
) {
return TRUE;
}
return TRUE;
}
return TRUE;
}
return FALSE;
}
/**
Buffer a token into the specific list of the socket Sock.
@param[in] Sock Pointer to the instance's socket.
@param[in] List Pointer to the list to store the token.
@param[in] Token Pointer to the token to be buffered.
@param[in] DataLen The data length of the buffer contained in Token.
@return Pointer to the token that wraps Token. If NULL, an error condition occurred.
**/
)
{
DEBUG (
"SockBufferIOToken: No Memory to allocate SockToken\n")
);
return NULL;
}
return SockToken;
}
/**
Destory the socket Sock and its associated protocol control block.
@param[in, out] Sock The socket to be destroyed.
@retval EFI_SUCCESS The socket Sock was destroyed successfully.
@retval EFI_ACCESS_DENIED Failed to get the lock to access the socket.
**/
)
{
if (Sock->IsDestroyed) {
return EFI_SUCCESS;
}
DEBUG (
"SockDestroyChild: Get the lock to access socket failed with %r\n",
);
return EFI_ACCESS_DENIED;
}
//
// force protocol layer to detach the PCB
//
DEBUG (
"SockDestroyChild: Protocol detach socket failed with %r\n",
);
} else if (SOCK_IS_CONFIGURED (Sock)) {
}
return Status;
}
SockDestroy (Sock);
return EFI_SUCCESS;
}
/**
Create a socket and its associated protocol control block
with the intial data SockInitData and protocol specific
data ProtoData.
@param[in] SockInitData Inital data to setting the socket.
@return Pointer to the newly created socket. If NULL, an error condition occured.
**/
SOCKET *
)
{
//
// create a new socket
//
DEBUG (
"SockCreateChild: No resource to create a new socket\n")
);
return NULL;
}
DEBUG (
"SockCreateChild: Get the lock to access socket failed with %r\n",
);
SockDestroy (Sock);
return NULL;
}
//
// inform the protocol layer to attach the socket
// with a new protocol control block
//
DEBUG (
"SockCreateChild: Protocol failed to attach a socket with %r\n",
);
SockDestroy (Sock);
}
return Sock;
}
/**
Configure the specific socket Sock using configuration data ConfigData.
@param[in] Sock Pointer to the socket to be configured.
@param[in] ConfigData Pointer to the configuration data.
@retval EFI_SUCCESS The socket configured successfully.
@retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
socket is already configured.
**/
)
{
DEBUG (
"SockConfigure: Get the access for socket failed with %r",
);
return EFI_ACCESS_DENIED;
}
if (SOCK_IS_CONFIGURED (Sock)) {
goto OnExit;
}
return Status;
}
/**
Initiate a connection establishment process.
@param[in] Sock Pointer to the socket to initiate the initate the
connection.
@param[in] Token Pointer to the token used for the connection
operation.
@retval EFI_SUCCESS The connection initialized successfully.
@retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
socket is closed, or the socket is not configured to
be an active one, or the token is already in one of
this socket's lists.
@retval EFI_NO_MAPPING The IP address configuration operation is not
finished.
@retval EFI_NOT_STARTED The socket is not configured.
**/
)
{
DEBUG (
"SockConnect: Get the access for socket failed with %r",
);
return EFI_ACCESS_DENIED;
}
if (SOCK_IS_NO_MAPPING (Sock)) {
goto OnExit;
}
if (SOCK_IS_UNCONFIGURED (Sock)) {
goto OnExit;
}
goto OnExit;
}
goto OnExit;
}
return Status;
}
/**
Issue a listen token to get an existed connected network instance
or wait for a connection if there is none.
@param[in] Sock Pointer to the socket to accept connections.
@param[in] Token The token to accept a connection.
@retval EFI_SUCCESS Either a connection is accpeted or the Token is
buffered for further acception.
@retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
socket is closed, or the socket is not configured to
be a passive one, or the token is already in one of
this socket's lists.
@retval EFI_NO_MAPPING The IP address configuration operation is not
finished.
@retval EFI_NOT_STARTED The socket is not configured.
@retval EFI_OUT_OF_RESOURCE Failed to buffer the Token due to memory limits.
**/
)
{
DEBUG (
"SockAccept: Get the access for socket failed with %r",
);
return EFI_ACCESS_DENIED;
}
if (SOCK_IS_NO_MAPPING (Sock)) {
goto Exit;
}
if (SOCK_IS_UNCONFIGURED (Sock)) {
goto Exit;
}
if (!SOCK_IS_LISTENING (Sock)) {
goto Exit;
}
goto Exit;
}
//
// Check if a connection has already in this Sock->ConnectionList
//
if (SOCK_IS_CONNECTED (Socket)) {
DEBUG (
"SockAccept: Accept a socket, now conncount is %d",
);
goto Exit;
}
}
//
// Buffer this token for latter incoming connection request
//
}
Exit:
return Status;
}
/**
Issue a token with data to the socket to send out.
@param[in] Sock Pointer to the socket to process the token with
data.
@param[in] Token The token with data that needs to send out.
@retval EFI_SUCCESS The token processed successfully.
@retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
socket is closed, or the socket is not in a
synchronized state , or the token is already in one
of this socket's lists.
@retval EFI_NO_MAPPING The IP address configuration operation is not
finished.
@retval EFI_NOT_STARTED The socket is not configured.
@retval EFI_OUT_OF_RESOURCE Failed to buffer the token due to memory limits.
**/
SockSend (
)
{
DEBUG (
"SockSend: Get the access for socket failed with %r",
);
return EFI_ACCESS_DENIED;
}
if (SOCK_IS_NO_MAPPING (Sock)) {
goto Exit;
}
if (SOCK_IS_UNCONFIGURED (Sock)) {
goto Exit;
}
goto Exit;
}
//
// check if a token is already in the token buffer
//
goto Exit;
}
//
// process this sending token now or buffer it only?
//
Sock,
&Sock->SndTokenList,
);
}
} else {
Sock,
);
DEBUG (
"SockSend: Failed to buffer IO token into socket processing SndToken List\n",
);
goto Exit;
}
DEBUG (
"SockSend: Failed to process Snd Data\n",
);
}
}
Exit:
return Status;
}
/**
Issue a token to get data from the socket.
@param[in] Sock Pointer to the socket to get data from.
@param[in] Token The token to store the received data from the
socket.
@retval EFI_SUCCESS The token processed successfully.
@retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
socket is closed, or the socket is not in a
synchronized state , or the token is already in one
of this socket's lists.
@retval EFI_NO_MAPPING The IP address configuration operation is not
finished.
@retval EFI_NOT_STARTED The socket is not configured.
@retval EFI_CONNECTION_FIN The connection is closed and there is no more data.
@retval EFI_OUT_OF_RESOURCE Failed to buffer the token due to memory limit.
**/
SockRcv (
)
{
DEBUG (
"SockRcv: Get the access for socket failed with %r",
);
return EFI_ACCESS_DENIED;
}
if (SOCK_IS_NO_MAPPING (Sock)) {
goto Exit;
}
if (SOCK_IS_UNCONFIGURED (Sock)) {
goto Exit;
}
goto Exit;
}
//
// check if a token is already in the token buffer of this socket
//
goto Exit;
}
//
// check whether an error has happened before
//
goto Exit;
}
//
// check whether can not receive and there is no any
// data buffered in Sock->RcvBuffer
//
goto Exit;
}
if (RcvdBytes != 0) {
goto Exit;
}
} else {
}
}
Exit:
return Status;
}
/**
Reset the socket and its associated protocol control block.
@param[in, out] Sock Pointer to the socket to be flushed.
@retval EFI_SUCCESS The socket is flushed successfully.
@retval EFI_ACCESS_DENIED Failed to get the lock to access the socket.
**/
)
{
DEBUG (
"SockFlush: Get the access for socket failed with %r",
);
return EFI_ACCESS_DENIED;
}
if (!SOCK_IS_CONFIGURED (Sock)) {
goto Exit;
}
DEBUG (
"SockFlush: Protocol failed handling SOCK_FLUSH with %r",
);
goto Exit;
}
Exit:
return Status;
}
/**
Close or abort the socket associated connection.
@param[in, out] Sock Pointer to the socket of the connection to close
or abort.
@param[in] Token The token for a close operation.
@param[in] OnAbort TRUE for aborting the connection; FALSE to close it.
@retval EFI_SUCCESS The close or abort operation initialized
successfully.
@retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
socket is closed, or the socket is not in a
synchronized state , or the token is already in one
of this socket's lists.
@retval EFI_NO_MAPPING The IP address configuration operation is not
finished.
@retval EFI_NOT_STARTED The socket is not configured.
**/
)
{
DEBUG (
"SockClose: Get the access for socket failed with %r",
);
return EFI_ACCESS_DENIED;
}
if (SOCK_IS_NO_MAPPING (Sock)) {
goto Exit;
}
if (SOCK_IS_UNCONFIGURED (Sock)) {
goto Exit;
}
if (SOCK_IS_DISCONNECTING (Sock)) {
goto Exit;
}
goto Exit;
}
if (OnAbort) {
} else {
}
Exit:
return Status;
}
/**
Get the mode data of the low layer protocol.
@param[in] Sock Pointer to the socket to get mode data from.
@param[in, out] Mode Pointer to the data to store the low layer mode
information.
@retval EFI_SUCCESS The mode data was obtained successfully.
@retval EFI_NOT_STARTED The socket is not configured.
**/
)
{
}
/**
Configure the low level protocol to join a multicast group for
this socket's connection.
@param[in] Sock Pointer to the socket of the connection to join the
specific multicast group.
@param[in] GroupInfo Pointer to the multicast group info.
@retval EFI_SUCCESS The configuration completed successfully.
@retval EFI_ACCESS_DENIED Failed to get the lock to access the socket.
@retval EFI_NOT_STARTED The socket is not configured.
**/
)
{
DEBUG (
"SockGroup: Get the access for socket failed with %r",
);
return EFI_ACCESS_DENIED;
}
if (SOCK_IS_UNCONFIGURED (Sock)) {
goto Exit;
}
Exit:
return Status;
}
/**
Add or remove route information in IP route table associated
with this socket.
@param[in] Sock Pointer to the socket associated with the IP route
table to operate on.
@param[in] RouteInfo Pointer to the route information to be processed.
@retval EFI_SUCCESS The route table updated successfully.
@retval EFI_ACCESS_DENIED Failed to get the lock to access the socket.
@retval EFI_NO_MAPPING The IP address configuration operation is not
finished.
@retval EFI_NOT_STARTED The socket is not configured.
**/
)
{
DEBUG (
"SockRoute: Get the access for socket failed with %r",
);
return EFI_ACCESS_DENIED;
}
if (SOCK_IS_NO_MAPPING (Sock)) {
goto Exit;
}
if (SOCK_IS_UNCONFIGURED (Sock)) {
goto Exit;
}
Exit:
return Status;
}