+++ /dev/null
-/** @file\r
- Definitions for the EFI Socket protocol.\r
-\r
- Copyright (c) 2011, Intel Corporation\r
- All rights reserved. This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-\r
-#ifndef _EFI_SOCKET_H_\r
-#define _EFI_SOCKET_H_\r
-\r
-#include <errno.h>\r
-#include <Uefi.h>\r
-\r
-#include <netinet/in.h>\r
-\r
-#include <sys/poll.h>\r
-#include <sys/socket.h>\r
-\r
-//------------------------------------------------------------------------------\r
-// Data Types\r
-//------------------------------------------------------------------------------\r
-\r
-/**\r
-EfiSocketLib (SocketDxe) interface \r
-**/\r
-typedef struct _EFI_SOCKET_PROTOCOL EFI_SOCKET_PROTOCOL;\r
-\r
-/**\r
- Constructor/Destructor\r
-\r
- @retval EFI_SUCCESS The operation was successful\r
-\r
- **/\r
-typedef\r
-EFI_STATUS\r
-(* PFN_ESL_xSTRUCTOR) (\r
- VOID\r
- );\r
-\r
-//------------------------------------------------------------------------------\r
-// Data\r
-//------------------------------------------------------------------------------\r
-\r
-extern PFN_ESL_xSTRUCTOR mpfnEslConstructor; ///< Constructor address for EslSocketLib\r
-extern PFN_ESL_xSTRUCTOR mpfnEslDestructor; ///< Destructor address for EslSocketLib\r
-\r
-extern EFI_GUID gEfiSocketProtocolGuid; ///< Socket protocol GUID\r
-extern EFI_GUID gEfiSocketServiceBindingProtocolGuid; ///< Socket layer service binding protocol GUID\r
-\r
-//------------------------------------------------------------------------------\r
-// Socket API\r
-//------------------------------------------------------------------------------\r
-\r
-/**\r
- Accept a network connection.\r
-\r
- This routine calls the network specific layer to remove the next\r
- connection from the FIFO.\r
-\r
- The ::accept calls this routine to poll for a network\r
- connection to the socket. When a connection is available\r
- this routine returns the ::EFI_SOCKET_PROTOCOL structure address\r
- associated with the new socket and the remote network address\r
- if requested.\r
-\r
- @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.\r
-\r
- @param [in] pSockAddr Address of a buffer to receive the remote\r
- network address.\r
-\r
- @param [in, out] pSockAddrLength Length in bytes of the address buffer.\r
- On output specifies the length of the\r
- remote network address.\r
-\r
- @param [out] ppSocketProtocol Address of a buffer to receive the\r
- ::EFI_SOCKET_PROTOCOL instance\r
- associated with the new socket.\r
-\r
- @param [out] pErrno Address to receive the errno value upon completion.\r
-\r
- @retval EFI_SUCCESS New connection successfully created\r
- @retval EFI_NOT_READY No connection is available\r
-\r
- **/\r
-typedef\r
-EFI_STATUS\r
-(* PFN_ACCEPT) (\r
- IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
- IN struct sockaddr * pSockAddr,\r
- IN OUT socklen_t * pSockAddrLength,\r
- IN EFI_SOCKET_PROTOCOL ** ppSocketProtocol,\r
- IN int * pErrno\r
- );\r
-\r
-/**\r
- Bind a name to a socket.\r
-\r
- This routine calls the network specific layer to save the network\r
- address of the local connection point.\r
-\r
- The ::bind routine calls this routine to connect a name\r
- (network address and port) to a socket on the local machine.\r
-\r
- @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.\r
-\r
- @param [in] pSockAddr Address of a sockaddr structure that contains the\r
- connection point on the local machine. An IPv4 address\r
- of INADDR_ANY specifies that the connection is made to\r
- all of the network stacks on the platform. Specifying a\r
- specific IPv4 address restricts the connection to the\r
- network stack supporting that address. Specifying zero\r
- for the port causes the network layer to assign a port\r
- number from the dynamic range. Specifying a specific\r
- port number causes the network layer to use that port.\r
-\r
- @param [in] SockAddrLen Specifies the length in bytes of the sockaddr structure.\r
-\r
- @param [out] pErrno Address to receive the errno value upon completion.\r
-\r
- @retval EFI_SUCCESS - Socket successfully created\r
-\r
- **/\r
-typedef\r
-EFI_STATUS\r
-(* PFN_BIND) (\r
- IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
- IN const struct sockaddr * pSockAddr,\r
- IN socklen_t SockAddrLength,\r
- OUT int * pErrno\r
- );\r
-\r
-/**\r
- Determine if the socket is closed\r
-\r
- This routine checks the state of the socket to determine if\r
- the network specific layer has completed the close operation.\r
-\r
- The ::close routine polls this routine to determine when the\r
- close operation is complete. The close operation needs to\r
- reverse the operations of the ::EslSocketAllocate routine.\r
-\r
- @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.\r
- @param [out] pErrno Address to receive the errno value upon completion.\r
-\r
- @retval EFI_SUCCESS Socket successfully closed\r
- @retval EFI_NOT_READY Close still in progress\r
- @retval EFI_ALREADY Close operation already in progress\r
- @retval Other Failed to close the socket\r
-\r
-**/\r
-typedef\r
-EFI_STATUS\r
-(* PFN_CLOSE_POLL) (\r
- IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
- IN int * pErrno\r
- );\r
-\r
-/**\r
- Start the close operation on the socket\r
-\r
- This routine calls the network specific layer to initiate the\r
- close state machine. This routine then calls the network\r
- specific layer to determine if the close state machine has gone\r
- to completion. The result from this poll is returned to the\r
- caller.\r
-\r
- The ::close routine calls this routine to start the close\r
- operation which reverses the operations of the\r
- ::EslSocketAllocate routine. The close routine then polls\r
- the ::EslSocketClosePoll routine to determine when the\r
- socket is closed.\r
-\r
- @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.\r
- @param [in] bCloseNow Boolean to control close behavior\r
- @param [out] pErrno Address to receive the errno value upon completion.\r
-\r
- @retval EFI_SUCCESS Socket successfully closed\r
- @retval EFI_NOT_READY Close still in progress\r
- @retval EFI_ALREADY Close operation already in progress\r
- @retval Other Failed to close the socket\r
-\r
-**/\r
-typedef\r
-EFI_STATUS\r
-(* PFN_CLOSE_START) (\r
- IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
- IN BOOLEAN bCloseNow,\r
- IN int * pErrno\r
- );\r
-\r
-/**\r
- Connect to a remote system via the network.\r
-\r
- This routine calls the network specific layer to establish\r
- the remote system address and establish the connection to\r
- the remote system.\r
-\r
- The ::connect routine calls this routine to establish a\r
- connection with the specified remote system. This routine\r
- is designed to be polled by the connect routine for completion\r
- of the network connection.\r
- \r
- @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.\r
-\r
- @param [in] pSockAddr Network address of the remote system.\r
- \r
- @param [in] SockAddrLength Length in bytes of the network address.\r
- \r
- @param [out] pErrno Address to receive the errno value upon completion.\r
- \r
- @retval EFI_SUCCESS The connection was successfully established.\r
- @retval EFI_NOT_READY The connection is in progress, call this routine again.\r
- @retval Others The connection attempt failed.\r
-\r
- **/\r
-typedef\r
-EFI_STATUS\r
-(* PFN_CONNECT) (\r
- IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
- IN const struct sockaddr * pSockAddr,\r
- IN socklen_t SockAddrLength,\r
- IN int * pErrno\r
- );\r
-\r
-/**\r
- Get the local address.\r
-\r
- This routine calls the network specific layer to get the network\r
- address of the local host connection point.\r
-\r
- The ::getsockname routine calls this routine to obtain the network\r
- address associated with the local host connection point.\r
-\r
- @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.\r
- \r
- @param [out] pAddress Network address to receive the local system address\r
-\r
- @param [in,out] pAddressLength Length of the local network address structure\r
-\r
- @param [out] pErrno Address to receive the errno value upon completion.\r
-\r
- @retval EFI_SUCCESS - Local address successfully returned\r
-\r
- **/\r
-typedef\r
-EFI_STATUS\r
-(* PFN_GET_LOCAL) (\r
- IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
- OUT struct sockaddr * pAddress,\r
- IN OUT socklen_t * pAddressLength,\r
- IN int * pErrno\r
- );\r
-\r
-/**\r
- Get the peer address.\r
-\r
- This routine calls the network specific layer to get the remote\r
- system connection point.\r
-\r
- The ::getpeername routine calls this routine to obtain the network\r
- address of the remote connection point.\r
-\r
- @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.\r
- \r
- @param [out] pAddress Network address to receive the remote system address\r
-\r
- @param [in,out] pAddressLength Length of the remote network address structure\r
-\r
- @param [out] pErrno Address to receive the errno value upon completion.\r
-\r
- @retval EFI_SUCCESS - Remote address successfully returned\r
-\r
- **/\r
-typedef\r
-EFI_STATUS\r
-(* PFN_GET_PEER) (\r
- IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
- OUT struct sockaddr * pAddress,\r
- IN OUT socklen_t * pAddressLength,\r
- IN int * pErrno\r
- );\r
-\r
-/**\r
- Establish the known port to listen for network connections.\r
-\r
- This routine calls into the network protocol layer to establish\r
- a handler that is called upon connection completion. The handler\r
- is responsible for inserting the connection into the FIFO.\r
-\r
- The ::listen routine indirectly calls this routine to place the\r
- socket into a state that enables connection attempts. Connections\r
- are placed in a FIFO that is serviced by the application. The\r
- application calls the ::accept (::EslSocketAccept) routine to\r
- remove the next connection from the FIFO and get the associated\r
- socket and address.\r
-\r
- @param [in] pSocketProtocol Address of the socket protocol structure.\r
-\r
- @param [in] Backlog Backlog specifies the maximum FIFO depth for\r
- the connections waiting for the application\r
- to call accept. Connection attempts received\r
- while the queue is full are refused.\r
-\r
- @param [out] pErrno Address to receive the errno value upon completion.\r
-\r
- @retval EFI_SUCCESS - Socket successfully created\r
- @retval Other - Failed to enable the socket for listen\r
-\r
-**/\r
-typedef\r
-EFI_STATUS\r
-(* PFN_LISTEN) (\r
- IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
- IN INT32 Backlog,\r
- OUT int * pErrno\r
- );\r
-\r
-/**\r
- Get the socket options\r
-\r
- This routine handles the socket level options and passes the\r
- others to the network specific layer.\r
-\r
- The ::getsockopt routine calls this routine to retrieve the\r
- socket options one at a time by name.\r
-\r
- @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.\r
- @param [in] level Option protocol level\r
- @param [in] OptionName Name of the option\r
- @param [out] pOptionValue Buffer to receive the option value\r
- @param [in,out] pOptionLength Length of the buffer in bytes,\r
- upon return length of the option value in bytes\r
- @param [out] pErrno Address to receive the errno value upon completion.\r
-\r
- @retval EFI_SUCCESS - Socket data successfully received\r
-\r
- **/\r
-typedef\r
-EFI_STATUS\r
-(* PFN_OPTION_GET) (\r
- IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
- IN int level,\r
- IN int OptionName,\r
- OUT void * __restrict pOptionValue,\r
- IN OUT socklen_t * __restrict pOptionLength,\r
- IN int * pErrno\r
- );\r
-\r
-/**\r
- Set the socket options\r
-\r
- This routine handles the socket level options and passes the\r
- others to the network specific layer.\r
-\r
- The ::setsockopt routine calls this routine to adjust the socket\r
- options one at a time by name.\r
-\r
- @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.\r
- @param [in] level Option protocol level\r
- @param [in] OptionName Name of the option\r
- @param [in] pOptionValue Buffer containing the option value\r
- @param [in] OptionLength Length of the buffer in bytes\r
- @param [out] pErrno Address to receive the errno value upon completion.\r
-\r
- @retval EFI_SUCCESS - Option successfully set\r
-\r
- **/\r
-typedef\r
-EFI_STATUS\r
-(* PFN_OPTION_SET) (\r
- IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
- IN int level,\r
- IN int OptionName,\r
- IN CONST void * pOptionValue,\r
- IN socklen_t OptionLength,\r
- IN int * pErrno\r
- );\r
-\r
-/**\r
- Poll a socket for pending activity.\r
-\r
- This routine builds a detected event mask which is returned to\r
- the caller in the buffer provided.\r
-\r
- The ::poll routine calls this routine to determine if the socket\r
- needs to be serviced as a result of connection, error, receive or\r
- transmit activity.\r
-\r
- @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.\r
-\r
- @param [in] Events Events of interest for this socket\r
-\r
- @param [in] pEvents Address to receive the detected events\r
-\r
- @param [out] pErrno Address to receive the errno value upon completion.\r
-\r
- @retval EFI_SUCCESS - Socket successfully polled\r
- @retval EFI_INVALID_PARAMETER - When pEvents is NULL\r
-\r
- **/\r
-typedef\r
-EFI_STATUS\r
-(* PFN_POLL) (\r
- IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
- IN short Events,\r
- IN short * pEvents,\r
- IN int * pErrno\r
- );\r
-\r
-/**\r
- Receive data from a network connection.\r
-\r
- This routine calls the network specific routine to remove the\r
- next portion of data from the receive queue and return it to the\r
- caller.\r
-\r
- The ::recvfrom routine calls this routine to determine if any data\r
- is received from the remote system. Note that the other routines\r
- ::recv and ::read are layered on top of ::recvfrom.\r
-\r
- @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.\r
- \r
- @param [in] Flags Message control flags\r
- \r
- @param [in] BufferLength Length of the the buffer\r
- \r
- @param [in] pBuffer Address of a buffer to receive the data.\r
- \r
- @param [in] pDataLength Number of received data bytes in the buffer.\r
-\r
- @param [out] pAddress Network address to receive the remote system address\r
-\r
- @param [in,out] pAddressLength Length of the remote network address structure\r
-\r
- @param [out] pErrno Address to receive the errno value upon completion.\r
-\r
- @retval EFI_SUCCESS - Socket data successfully received\r
-\r
- **/\r
-typedef\r
-EFI_STATUS\r
-(* PFN_RECEIVE) (\r
- IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
- IN int Flags,\r
- IN size_t BufferLength,\r
- IN UINT8 * pBuffer,\r
- OUT size_t * pDataLength,\r
- OUT struct sockaddr * pAddress,\r
- IN OUT socklen_t * pAddressLength,\r
- IN int * pErrno\r
- );\r
-\r
-/**\r
- Shutdown the socket receive and transmit operations\r
-\r
- This routine sets a flag to stop future transmissions and calls\r
- the network specific layer to cancel the pending receive operation.\r
-\r
- The ::shutdown routine calls this routine to stop receive and transmit\r
- operations on the socket.\r
-\r
- @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.\r
- \r
- @param [in] How Which operations to stop\r
- \r
- @param [out] pErrno Address to receive the errno value upon completion.\r
-\r
- @retval EFI_SUCCESS - Socket operations successfully shutdown\r
-\r
- **/\r
-typedef\r
-EFI_STATUS\r
-(* PFN_SHUTDOWN) (\r
- IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
- IN int How,\r
- IN int * pErrno\r
- );\r
-\r
-/**\r
- Initialize an endpoint for network communication.\r
-\r
- This routine initializes the communication endpoint.\r
-\r
- The ::socket routine calls this routine indirectly to create\r
- the communication endpoint.\r
-\r
- @param [in] pSocketProtocol Address of the socket protocol structure.\r
- @param [in] domain Select the family of protocols for the client or server\r
- application. See the ::socket documentation for values.\r
- @param [in] type Specifies how to make the network connection.\r
- See the ::socket documentation for values.\r
- @param [in] protocol Specifies the lower layer protocol to use.\r
- See the ::socket documentation for values.\r
- @param [out] pErrno Address to receive the errno value upon completion.\r
-\r
- @retval EFI_SUCCESS - Socket successfully created\r
- @retval EFI_INVALID_PARAMETER - Invalid domain value, errno = EAFNOSUPPORT\r
- @retval EFI_INVALID_PARAMETER - Invalid type value, errno = EINVAL\r
- @retval EFI_INVALID_PARAMETER - Invalid protocol value, errno = EINVAL\r
-\r
- **/\r
-typedef\r
-EFI_STATUS\r
-(*PFN_SOCKET) (\r
- IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
- IN int domain,\r
- IN int type,\r
- IN int protocol,\r
- IN int * pErrno\r
- );\r
-\r
-/**\r
- Send data using a network connection.\r
-\r
- This routine calls the network specific layer to queue the data\r
- for transmission. Eventually the buffer will reach the head of\r
- the queue and will get transmitted over the network. For datagram\r
- sockets there is no guarantee that the data reaches the application\r
- running on the remote system.\r
-\r
- The ::sendto routine calls this routine to send data to the remote\r
- system. Note that ::send and ::write are layered on top of ::sendto.\r
-\r
- @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.\r
- \r
- @param [in] Flags Message control flags\r
- \r
- @param [in] BufferLength Length of the the buffer\r
- \r
- @param [in] pBuffer Address of a buffer containing the data to send\r
- \r
- @param [in] pDataLength Address to receive the number of data bytes sent\r
-\r
- @param [in] pAddress Network address of the remote system address\r
-\r
- @param [in] AddressLength Length of the remote network address structure\r
-\r
- @param [out] pErrno Address to receive the errno value upon completion.\r
-\r
- @retval EFI_SUCCESS - Socket data successfully queued for transmit\r
-\r
- **/\r
-typedef\r
-EFI_STATUS\r
-(* PFN_TRANSMIT) (\r
- IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
- IN int Flags,\r
- IN size_t BufferLength,\r
- IN CONST UINT8 * pBuffer,\r
- OUT size_t * pDataLength,\r
- IN const struct sockaddr * pAddress,\r
- IN socklen_t AddressLength,\r
- IN int * pErrno\r
- );\r
-\r
-//------------------------------------------------------------------------------\r
-// Socket Protocol\r
-//------------------------------------------------------------------------------\r
-\r
-/**\r
- Socket protocol declaration\r
-**/\r
-typedef struct _EFI_SOCKET_PROTOCOL {\r
- EFI_HANDLE SocketHandle; ///< Handle for the socket\r
- PFN_ACCEPT pfnAccept; ///< Accept a network connection\r
- PFN_BIND pfnBind; ///< Bind a local address to the socket\r
- PFN_CLOSE_POLL pfnClosePoll; ///< Determine if the socket is closed\r
- PFN_CLOSE_START pfnCloseStart; ///< Start the close operation\r
- PFN_CONNECT pfnConnect; ///< Connect to a remote system\r
- PFN_GET_LOCAL pfnGetLocal; ///< Get local address\r
- PFN_GET_PEER pfnGetPeer; ///< Get peer address\r
- PFN_LISTEN pfnListen; ///< Enable connection attempts on known port\r
- PFN_OPTION_GET pfnOptionGet; ///< Get socket options\r
- PFN_OPTION_SET pfnOptionSet; ///< Set socket options\r
- PFN_POLL pfnPoll; ///< Poll for socket activity\r
- PFN_RECEIVE pfnReceive; ///< Receive data from a socket\r
- PFN_SHUTDOWN pfnShutdown; ///< Shutdown receive and transmit operations\r
- PFN_SOCKET pfnSocket; ///< Initialize the socket\r
- PFN_TRANSMIT pfnTransmit; ///< Transmit data using the socket\r
-} GCC_EFI_SOCKET_PROTOCOL;\r
-\r
-//------------------------------------------------------------------------------\r
-// Non-blocking routines\r
-//------------------------------------------------------------------------------\r
-\r
-/**\r
- Non blocking version of ::accept.\r
-\r
- @param [in] s Socket file descriptor returned from ::socket.\r
-\r
- @param [in] address Address of a buffer to receive the remote network address.\r
-\r
- @param [in, out] address_len Address of a buffer containing the Length in bytes\r
- of the remote network address buffer. Upon return,\r
- contains the length of the remote network address.\r
-\r
- @return This routine returns zero if successful and -1 when an error occurs.\r
- In the case of an error, ::errno contains more details.\r
-\r
- **/\r
-int\r
-AcceptNB (\r
- int s,\r
- struct sockaddr * address,\r
- socklen_t * address_len\r
- );\r
-\r
-/**\r
- Free the socket resources\r
-\r
- This releases the socket resources allocated by calling\r
- EslServiceGetProtocol.\r
-\r
- This routine is called from the ::close routine in BsdSocketLib\r
- to release the socket resources.\r
-\r
- @param [in] pSocketProtocol Address of an ::EFI_SOCKET_PROTOCOL\r
- structure\r
-\r
- @return Value for ::errno, zero (0) indicates success.\r
-\r
- **/\r
-int\r
-EslServiceFreeProtocol (\r
- IN EFI_SOCKET_PROTOCOL * pSocketProtocol\r
- );\r
-\r
-/**\r
- Connect to the EFI socket library\r
-\r
- @param [in] ppSocketProtocol Address to receive the socket protocol address\r
-\r
- @return Value for ::errno, zero (0) indicates success.\r
-\r
- **/\r
-int\r
-EslServiceGetProtocol (\r
- IN EFI_SOCKET_PROTOCOL ** ppSocketProtocol\r
- );\r
-\r
-//------------------------------------------------------------------------------\r
-\r
-#endif // _EFI_SOCKET_H_\r