/** @file
Common head file for TCP 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.
**/
#ifndef _SOCKET_H_
#define _SOCKET_H_
#include <Uefi.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiBootServicesTableLib.h>
#define SOCK_SND_BUF 0
//
//
//
// When a socket is created it enters into SO_UNCONFIGURED,
// no actions can be taken on this socket, only after calling
// SockConfigure. The state transition diagram of socket is
// as following:
//
// SO_UNCONFIGURED --- SO_CONFIGURED --- SO_CONNECTING
// ^ | |
// | ---> SO_LISTENING |
// | |
// |------------------SO_DISCONNECTING<-- SO_CONNECTED
//
// A passive socket can only go into SO_LISTENING and
// SO_UNCONFIGURED state. SO_XXXING state is a middle state
// when a socket is undergoing a protocol procedure such
// as requesting a TCP connection.
//
//
//
///
/// Socket state
///
#define SO_CLOSED 0
///
/// Socket configure state
///
#define SO_UNCONFIGURED 0
///
/// The request issued from socket layer to protocol layer.
///
/**
Set socket SO_NO_MORE_DATA flag.
@param[in] Sock Pointer to the socket
**/
/**
Check whether the socket is unconfigured.
@param[in] Sock Pointer to the socket.
@retval TRUE The socket is unconfigued.
@retval FALSE The socket is not unconfigued.
**/
/**
Check whether the socket is configured.
@param[in] Sock Pointer to the socket
@retval TRUE The socket is configued
@retval FALSE The socket is not configued
**/
/**
Check whether the socket is configured to active mode.
@param[in] Sock Pointer to the socket.
@retval TRUE The socket is configued to active mode.
@retval FALSE The socket is not configued to active mode.
**/
/**
Check whether the socket is configured to passive mode.
@param[in] Sock Pointer to the socket.
@retval TRUE The socket is configued to passive mode.
@retval FALSE The socket is not configued to passive mode.
**/
/**
Check whether the socket is mapped.
@param[in] Sock Pointer to the socket.
@retval TRUE The socket is not mapping.
@retval FALSE The socket is mapped.
**/
/**
Check whether the socket is closed.
@param[in] Sock Pointer to the socket.
@retval TRUE The socket is closed.
@retval FALSE The socket is not closed.
**/
/**
Check whether the socket is listening.
@param[in] Sock Pointer to the socket.
@retval TRUE The socket is listening.
@retval FALSE The socket is not listening.
**/
/**
Check whether the socket is connecting.
@param[in] Sock Pointer to the socket.
@retval TRUE The socket is connecting.
@retval FALSE The socket is not connecting.
**/
/**
Check whether the socket has connected.
@param[in] Sock Pointer to the socket.
@retval TRUE The socket has connected.
@retval FALSE The socket has not connected.
**/
/**
Check whether the socket is disconnecting.
@param[in] Sock Pointer to the socket.
@retval TRUE The socket is disconnecting.
@retval FALSE The socket is not disconnecting.
**/
/**
Check whether the socket is no more data.
@param[in] Sock Pointer to the socket.
@retval TRUE The socket is no more data.
@retval FALSE The socket still has data.
**/
/**
Set the size of the receive buffer.
@param[in] Sock Pointer to the socket.
@param[in] Size The size to set.
**/
/**
Get the size of the receive buffer.
@param[in] Sock Pointer to the socket.
@return The receive buffer size.
**/
/**
Get the size of the receive data.
@param[in] Sock Pointer to the socket.
@return The received data size.
**/
/**
Set the size of the send buffer.
@param[in] Sock Pointer to the socket.
@param[in] Size The size to set.
**/
/**
Get the size of the send buffer.
@param[in] Sock Pointer to the socket.
@return The send buffer size.
**/
/**
Get the size of the send data.
@param[in] Sock Pointer to the socket.
@return The send data size.
**/
/**
Set the backlog value of the socket.
@param[in] Sock Pointer to the socket.
@param[in] Value The value to set.
**/
/**
Get the backlog value of the socket.
@param[in] Sock Pointer to the socket.
@return The backlog value.
**/
/**
Set the socket with error state.
@param[in] Sock Pointer to the socket.
@param[in] Error The error state.
**/
///
/// Socket completion token
///
typedef struct _SOCK_COMPLETION_TOKEN {
typedef union {
} SOCK_IO_DATA;
///
/// The application token with data packet
///
typedef struct _SOCK_IO_TOKEN {
///
/// The socket type.
///
typedef enum {
} SOCK_TYPE;
///
/// The buffer structure of rcvd data and send data used by socket.
///
typedef struct _SOCK_BUFFER {
} SOCK_BUFFER;
/**
The handler of protocol for request from socket.
@param[in] Socket The socket issuing the request to protocol.
@param[in] Request The request issued by socket.
@param[in] RequestData The request related data.
@retval EFI_SUCCESS The socket request is completed successfully.
@retval other The error status returned by the corresponding TCP
layer function.
**/
typedef
(*SOCK_PROTO_HANDLER) (
);
/**
The Callback funtion called after the TCP socket is created.
@param[in] This Pointer to the socket just created.
@param[in] Context Context of the socket.
@retval EFI_SUCCESS This protocol installed successfully.
@retval other Some error occured.
**/
typedef
(*SOCK_CREATE_CALLBACK) (
);
/**
The callback function called before the TCP socket is to be destroyed.
@param[in] This The TCP socket to be destroyed.
@param[in] Context The context.
**/
typedef
);
///
/// The initialize data for create a new socket.
///
typedef struct _SOCK_INIT_DATA {
///< wanted to install on socket
//
// Callbacks after socket is created and before socket is to be destroyed.
//
//
// Opaque protocol data.
//
///
/// The union type of TCP and UDP protocol.
///
typedef union _NET_PROTOCOL {
} NET_PROTOCOL;
///
/// The socket structure representing a network service access point.
///
struct _TCP_SOCKET {
//
// Socket description information
//
//
// Fields used to manage the connection request
//
//
// The queue to buffer application's asynchronous token
//
//
// Interface for low level protocol
//
//
// Callbacks after socket is created and before socket is to be destroyed.
//
};
///
/// The token structure buffered in socket layer.
///
typedef struct _SOCK_TOKEN {
///< belongs to
} SOCK_TOKEN;
///
/// Reserved data to access the NET_BUF delivered by TCP driver.
///
typedef struct _TCP_RSV_DATA {
} TCP_RSV_DATA;
//
// Socket provided oprerations for low layer protocol implemented in SockImpl.c
//
/**
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 *
);
/**
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.
**/
);
/**
Called by the low layer protocol to indicate that 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 is 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.
**/
);
/**
Called by the low layer protocol to copy some data in 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.
**/
);
/**
Called by the low layer protocol to deliver received data to socket layer.
This function appends the data to the socket receive buffer, set the
urgent data length, then checks 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.
**/
);
/**
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.
**/
);
//
// Socket provided operations for user interface implemented in SockInterface.c
//
/**
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 *
);
/**
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.
**/
);
/**
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.
**/
);
/**
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.
**/
);
/**
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 accepted or the Token is
buffered for further acceptance.
@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 limit.
**/
);
/**
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 a memory limit.
**/
SockSend (
);
/**
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 a memory limit.
**/
SockRcv (
);
/**
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 flushed successfully.
@retval EFI_ACCESS_DENIED Failed to get the lock to access the socket.
**/
);
/**
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 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.
**/
);
/**
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 information.
@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.
**/
);
/**
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.
**/
);
#endif