summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlpleahy <lpleahy@6f19259b-4bc3-4df7-8a09-765794883524>2011-08-27 03:14:56 +0000
committerlpleahy <lpleahy@6f19259b-4bc3-4df7-8a09-765794883524>2011-08-27 03:14:56 +0000
commit26e71aa2cf4d3bf70960f0a964e2284b73c20f06 (patch)
treef7c83c25e524f54f4bee1e39af0bb0550111b59e
parent459e8005d229a15a895c0420f075ebaa8d9d7192 (diff)
downloadedk2-26e71aa2cf4d3bf70960f0a964e2284b73c20f06.zip
edk2-26e71aa2cf4d3bf70960f0a964e2284b73c20f06.tar.gz
edk2-26e71aa2cf4d3bf70960f0a964e2284b73c20f06.tar.bz2
* Update the Doxygen comments for the EfiSocketLib interface.
* Breakout some SocketDxe specific routines to reduce the size of the applications linked against the EfiSocketLib. * Remove some junk that was no longer in use. * Fixed the TCP (SOCK_STREAM) receive hang caused by the API pointer not being set by the EslTcpListenComplete4 routine. Signed-off by: Lee Leahy git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/branches/EADK@12216 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r--StdLib/BsdSocketLib/sendto.c16
-rw-r--r--StdLib/BsdSocketLib/socket.c17
-rw-r--r--StdLib/EfiSocketLib/DxeSupport.c314
-rw-r--r--StdLib/EfiSocketLib/EfiSocketLib.inf1
-rw-r--r--StdLib/EfiSocketLib/Init.c10
-rw-r--r--StdLib/EfiSocketLib/Service.c117
-rw-r--r--StdLib/EfiSocketLib/Socket.c561
-rw-r--r--StdLib/EfiSocketLib/Socket.h12
-rw-r--r--StdLib/EfiSocketLib/Tcp4.c1
-rw-r--r--StdLib/EfiSocketLib/UseEfiSocketLib.c37
-rw-r--r--StdLib/Include/Efi/EfiSocketLib.h372
-rw-r--r--StdLib/Include/Protocol/EfiSocket.h320
-rw-r--r--StdLib/SocketDxe/EntryUnload.c28
-rw-r--r--StdLib/UseSocketDxe/UseSocketDxe.c11
14 files changed, 1029 insertions, 788 deletions
diff --git a/StdLib/BsdSocketLib/sendto.c b/StdLib/BsdSocketLib/sendto.c
index c0c2add..61a42f1 100644
--- a/StdLib/BsdSocketLib/sendto.c
+++ b/StdLib/BsdSocketLib/sendto.c
@@ -78,14 +78,14 @@ sendto (
pData = buffer;
do {
errno = 0;
- Status = pSocketProtocol->pfnSend ( pSocketProtocol,
- flags,
- length,
- pData,
- (size_t *)&LengthInBytes,
- to,
- tolen,
- &errno );
+ Status = pSocketProtocol->pfnTransmit ( pSocketProtocol,
+ flags,
+ length,
+ pData,
+ (size_t *)&LengthInBytes,
+ to,
+ tolen,
+ &errno );
if ( EFI_ERROR ( Status ) && ( EFI_NOT_READY != Status )) {
LengthInBytes = -1;
break;
diff --git a/StdLib/BsdSocketLib/socket.c b/StdLib/BsdSocketLib/socket.c
index 8c2e792..d0a5089 100644
--- a/StdLib/BsdSocketLib/socket.c
+++ b/StdLib/BsdSocketLib/socket.c
@@ -170,22 +170,25 @@ BslSocketProtocolToFd (
documentation is available online.
@param [in] domain Select the family of protocols for the client or server
- application.
+ application. The supported values are:
+ <ul>
+ <li>AF_INET - Version 4 UEFI network stack</li>
+ </ul>
@param [in] type Specifies how to make the network connection. The following values
are supported:
<ul>
<li>
- SOCK_STREAM - Connect to TCP, provides a byte stream
- that is manipluated by read, recv, send and write.
+ SOCK_DGRAM - Connect to UDP, provides a datagram service that is
+ manipulated by recvfrom and sendto.
</li>
<li>
- SOCK_SEQPACKET - Connect to TCP, provides sequenced packet stream
- that is manipulated by read, recv, send and write.
+ SOCK_STREAM - Connect to TCP, provides a byte stream
+ that is manipluated by read, recv, send and write.
</li>
<li>
- SOCK_DGRAM - Connect to UDP, provides a datagram service that is
- manipulated by recvfrom and sendto.
+ SOCK_RAW - Connect to IP, provides a datagram service that
+ is manipulated by recvfrom and sendto.
</li>
</ul>
diff --git a/StdLib/EfiSocketLib/DxeSupport.c b/StdLib/EfiSocketLib/DxeSupport.c
new file mode 100644
index 0000000..73aea04
--- /dev/null
+++ b/StdLib/EfiSocketLib/DxeSupport.c
@@ -0,0 +1,314 @@
+/** @file
+ SocketDxe support routines
+
+ Copyright (c) 2011, Intel Corporation
+ All rights reserved. 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
+ http://opensource.org/licenses/bsd-license.php
+
+ 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 "Socket.h"
+
+
+/**
+ Creates a child handle and installs a protocol.
+
+ When the socket application is linked against UseSocketDxe, the ::socket
+ routine indirectly calls this routine in SocketDxe to create a child
+ handle if necessary and install the socket protocol on the handle.
+ Upon return, EslServiceGetProtocol in UseSocketLib returns the
+ ::EFI_SOCKET_PROTOCOL address to the socket routine.
+
+ @param [in] pThis Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
+ @param [in] pChildHandle Pointer to the handle of the child to create. If it is NULL,
+ then a new handle is created. If it is a pointer to an existing UEFI handle,
+ then the protocol is added to the existing UEFI handle.
+
+ @retval EFI_SUCCESS The protocol was added to ChildHandle.
+ @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
+ the child
+ @retval other The child handle was not created
+
+**/
+EFI_STATUS
+EFIAPI
+EslDxeCreateChild (
+ IN EFI_SERVICE_BINDING_PROTOCOL * pThis,
+ IN OUT EFI_HANDLE * pChildHandle
+ )
+{
+ DT_SOCKET * pSocket;
+ EFI_STATUS Status;
+
+ DBG_ENTER ( );
+
+ //
+ // Create a socket structure
+ //
+ Status = EslSocketAllocate ( pChildHandle,
+ DEBUG_SOCKET,
+ &pSocket );
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+ Destroys a child handle with a protocol installed on it.
+
+ When the socket application is linked against UseSocketDxe, the ::close
+ routine indirectly calls this routine in SocketDxe to undo the operations
+ done by the ::EslDxeCreateChild routine. This routine removes the socket
+ protocol from the handle and then destroys the child handle if there are
+ no other protocols attached.
+
+ @param [in] pThis Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
+ @param [in] ChildHandle Handle of the child to destroy
+
+ @retval EFI_SUCCESS The protocol was removed from ChildHandle.
+ @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
+ @retval EFI_INVALID_PARAMETER Child handle is not a valid UEFI Handle.
+ @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
+ because its services are being used.
+ @retval other The child handle was not destroyed
+
+**/
+EFI_STATUS
+EFIAPI
+EslDxeDestroyChild (
+ IN EFI_SERVICE_BINDING_PROTOCOL * pThis,
+ IN EFI_HANDLE ChildHandle
+ )
+{
+ DT_LAYER * pLayer;
+ DT_SOCKET * pSocket;
+ DT_SOCKET * pSocketPrevious;
+ EFI_SOCKET_PROTOCOL * pSocketProtocol;
+ EFI_STATUS Status;
+ EFI_TPL TplPrevious;
+
+ DBG_ENTER ( );
+
+ //
+ // Locate the socket control structure
+ //
+ pLayer = &mEslLayer;
+ Status = gBS->OpenProtocol (
+ ChildHandle,
+ &gEfiSocketProtocolGuid,
+ (VOID **)&pSocketProtocol,
+ pLayer->ImageHandle,
+ NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if ( !EFI_ERROR ( Status )) {
+ pSocket = SOCKET_FROM_PROTOCOL ( pSocketProtocol );
+
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+
+ //
+ // Walk the socket list
+ //
+ pSocketPrevious = pLayer->pSocketList;
+ if ( NULL != pSocketPrevious ) {
+ if ( pSocket == pSocketPrevious ) {
+ //
+ // Remove the socket from the head of the list
+ //
+ pLayer->pSocketList = pSocket->pNext;
+ }
+ else {
+ //
+ // Find the socket in the middle of the list
+ //
+ while (( NULL != pSocketPrevious )
+ && ( pSocket != pSocketPrevious->pNext )) {
+ //
+ // Set the next socket
+ //
+ pSocketPrevious = pSocketPrevious->pNext;
+ }
+ if ( NULL != pSocketPrevious ) {
+ //
+ // Remove the socket from the middle of the list
+ //
+ pSocketPrevious = pSocket->pNext;
+ }
+ }
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_POOL,
+ "ERROR - Socket list is empty!\r\n" ));
+ }
+
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+
+ //
+ // Determine if the socket was found
+ //
+ if ( NULL != pSocketPrevious ) {
+ pSocket->pNext = NULL;
+
+ //
+ // Remove the socket protocol
+ //
+ Status = gBS->UninstallMultipleProtocolInterfaces (
+ ChildHandle,
+ &gEfiSocketProtocolGuid,
+ &pSocket->SocketProtocol,
+ NULL );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_POOL | DEBUG_INFO,
+ "Removed: gEfiSocketProtocolGuid from 0x%08x\r\n",
+ ChildHandle ));
+
+ //
+ // Free the socket structure
+ //
+ Status = gBS->FreePool ( pSocket );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_POOL,
+ "0x%08x: Free pSocket, %d bytes\r\n",
+ pSocket,
+ sizeof ( *pSocket )));
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_POOL,
+ "ERROR - Failed to free pSocket 0x%08x, Status: %r\r\n",
+ pSocket,
+ Status ));
+ }
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INFO,
+ "ERROR - Failed to remove gEfiSocketProtocolGuid from 0x%08x, Status: %r\r\n",
+ ChildHandle,
+ Status ));
+ }
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_INFO,
+ "ERROR - The socket was not in the socket list!\r\n" ));
+ Status = EFI_NOT_FOUND;
+ }
+ }
+ else {
+ DEBUG (( DEBUG_ERROR,
+ "ERROR - Failed to open socket protocol on 0x%08x, Status; %r\r\n",
+ ChildHandle,
+ Status ));
+ }
+
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
+Install the socket service
+
+SocketDxe uses this routine to announce the socket interface to
+the rest of EFI.
+
+@param [in] pImageHandle Address of the image handle
+
+@retval EFI_SUCCESS Service installed successfully
+**/
+EFI_STATUS
+EFIAPI
+EslDxeInstall (
+ IN EFI_HANDLE * pImageHandle
+ )
+{
+ EFI_STATUS Status;
+
+ //
+ // Install the socket service binding protocol
+ //
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ pImageHandle,
+ &gEfiSocketServiceBindingProtocolGuid,
+ mEslLayer.pServiceBinding,
+ NULL
+ );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
+ "Installed: gEfiSocketServiceBindingProtocolGuid on 0x%08x\r\n",
+ *pImageHandle ));
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
+ "ERROR - InstallMultipleProtocolInterfaces failed, Status: %r\r\n",
+ Status ));
+ }
+
+ //
+ // Return the operation status
+ //
+ return Status;
+}
+
+
+/**
+Uninstall the socket service
+
+SocketDxe uses this routine to notify EFI that the socket layer
+is no longer available.
+
+@param [in] ImageHandle Handle for the image.
+
+@retval EFI_SUCCESS Service installed successfully
+**/
+EFI_STATUS
+EFIAPI
+EslDxeUninstall (
+ IN EFI_HANDLE ImageHandle
+ )
+{
+ EFI_STATUS Status;
+
+ //
+ // Install the socket service binding protocol
+ //
+ Status = gBS->UninstallMultipleProtocolInterfaces (
+ ImageHandle,
+ &gEfiSocketServiceBindingProtocolGuid,
+ mEslLayer.pServiceBinding,
+ NULL
+ );
+ if ( !EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_POOL | DEBUG_INIT,
+ "Removed: gEfiSocketServiceBindingProtocolGuid from 0x%08x\r\n",
+ ImageHandle ));
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
+ "ERROR - Failed to remove gEfiSocketServiceBindingProtocolGuid from 0x%08x, Status: %r\r\n",
+ ImageHandle,
+ Status ));
+ }
+
+ //
+ // Return the operation status
+ //
+ return Status;
+}
diff --git a/StdLib/EfiSocketLib/EfiSocketLib.inf b/StdLib/EfiSocketLib/EfiSocketLib.inf
index a2a714a..3095ed2 100644
--- a/StdLib/EfiSocketLib/EfiSocketLib.inf
+++ b/StdLib/EfiSocketLib/EfiSocketLib.inf
@@ -28,6 +28,7 @@
#
[Sources.common]
+ DxeSupport.c
Init.c
Ip4.c
Service.c
diff --git a/StdLib/EfiSocketLib/Init.c b/StdLib/EfiSocketLib/Init.c
index f444acc..91c5714 100644
--- a/StdLib/EfiSocketLib/Init.c
+++ b/StdLib/EfiSocketLib/Init.c
@@ -18,6 +18,11 @@
/**
EFI Socket Library Constructor
+ Constructor listed in the EfiSocketLib.inf file. This routine
+ supports an implementation dependent constructor depending upon
+ whether the library is linked to an application or to the SocketDxe
+ driver.
+
@retval EFI_SUCCESS The initialization was successful
**/
@@ -54,6 +59,11 @@ EslConstructor (
/**
EFI Socket Library Destructor
+ Destructor listed in the EfiSocketLib.inf file. This routine
+ supports an implementation dependent destructor depending upon
+ whether the library is linked to an application or to the SocketDxe
+ driver.
+
@retval EFI_SUCCESS The shutdown was successful
**/
diff --git a/StdLib/EfiSocketLib/Service.c b/StdLib/EfiSocketLib/Service.c
index fcb1059..5e6b5f3 100644
--- a/StdLib/EfiSocketLib/Service.c
+++ b/StdLib/EfiSocketLib/Service.c
@@ -14,15 +14,16 @@
#include "Socket.h"
-EFI_TCP4_PROTOCOL * mpEfiTcpClose4[ 1024 ];
-
/**
Connect to the network service bindings
Walk the network service protocols on the controller handle and
- locate any that are not in use. Create service structures to
- manage the service binding for the socket driver.
+ locate any that are not in use. Create ::DT_SERVICE structures to
+ manage the network layer interfaces for the socket driver. Tag
+ each of the network interfaces that are being used. Finally, this
+ routine calls DT_SOCKET_BINDING::pfnInitialize to prepare the network
+ interface for use by the socket layer.
@param [in] BindingHandle Handle for protocol binding.
@param [in] Controller Handle of device to work with.
@@ -253,12 +254,14 @@ EslServiceConnect (
/**
- Shutdown the network connections to this controller by removing
- NetworkInterfaceIdentifier protocol and closing the DevicePath
- and PciIo protocols on Controller.
+ Shutdown the connections to the network layer by locating the
+ tags on the network interfaces established by ::EslServiceConnect.
+ This routine calls DT_SOCKET_BINDING::pfnShutdown to shutdown the any
+ activity on the network interface and then free the ::DT_SERVICE
+ structures.
@param [in] BindingHandle Handle for protocol binding.
- @param [in] Controller Handle of device to stop driver on.
+ @param [in] Controller Handle of device to stop driver on.
@retval EFI_SUCCESS This driver is removed Controller.
@retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
@@ -388,48 +391,6 @@ EslServiceDisconnect (
/**
-Install the socket service
-
-@param [in] pImageHandle Address of the image handle
-
-@retval EFI_SUCCESS Service installed successfully
-**/
-EFI_STATUS
-EFIAPI
-EslServiceInstall (
- IN EFI_HANDLE * pImageHandle
- )
-{
- EFI_STATUS Status;
-
- //
- // Install the socket service binding protocol
- //
- Status = gBS->InstallMultipleProtocolInterfaces (
- pImageHandle,
- &gEfiSocketServiceBindingProtocolGuid,
- &mEslLayer.ServiceBinding,
- NULL
- );
- if ( !EFI_ERROR ( Status )) {
- DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
- "Installed: gEfiSocketServiceBindingProtocolGuid on 0x%08x\r\n",
- *pImageHandle ));
- }
- else {
- DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
- "ERROR - InstallMultipleProtocolInterfaces failed, Status: %r\r\n",
- Status ));
- }
-
- //
- // Return the operation status
- //
- return Status;
-}
-
-
-/**
Initialize the service layer
@param [in] ImageHandle Handle for the image.
@@ -447,63 +408,14 @@ EslServiceLoad (
// Save the image handle
//
pLayer = &mEslLayer;
+ ZeroMem ( pLayer, sizeof ( *pLayer ));
pLayer->Signature = LAYER_SIGNATURE;
pLayer->ImageHandle = ImageHandle;
//
- // Initialize the TCP4 close
- //
- pLayer->TcpCloseMax4 = DIM ( mpEfiTcpClose4 );
- pLayer->ppTcpClose4 = mpEfiTcpClose4;
-
- //
// Connect the service binding protocol to the image handle
//
- pLayer->ServiceBinding.CreateChild = EslSocketCreateChild;
- pLayer->ServiceBinding.DestroyChild = EslSocketDestroyChild;
-}
-
-
-/**
-Uninstall the socket service
-
-@param [in] ImageHandle Handle for the image.
-
-@retval EFI_SUCCESS Service installed successfully
-**/
-EFI_STATUS
-EFIAPI
-EslServiceUninstall (
- IN EFI_HANDLE ImageHandle
- )
-{
- EFI_STATUS Status;
-
- //
- // Install the socket service binding protocol
- //
- Status = gBS->UninstallMultipleProtocolInterfaces (
- ImageHandle,
- &gEfiSocketServiceBindingProtocolGuid,
- &mEslLayer.ServiceBinding,
- NULL
- );
- if ( !EFI_ERROR ( Status )) {
- DEBUG (( DEBUG_POOL | DEBUG_INIT,
- "Removed: gEfiSocketServiceBindingProtocolGuid from 0x%08x\r\n",
- ImageHandle ));
- }
- else {
- DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
- "ERROR - Failed to remove gEfiSocketServiceBindingProtocolGuid from 0x%08x, Status: %r\r\n",
- ImageHandle,
- Status ));
- }
-
- //
- // Return the operation status
- //
- return Status;
+ pLayer->pServiceBinding = &mEfiServiceBinding;
}
@@ -524,6 +436,5 @@ EslServiceUnload (
//
pLayer = &mEslLayer;
pLayer->ImageHandle = NULL;
- pLayer->ServiceBinding.CreateChild = NULL;
- pLayer->ServiceBinding.DestroyChild = NULL;
+ pLayer->pServiceBinding = NULL;
}
diff --git a/StdLib/EfiSocketLib/Socket.c b/StdLib/EfiSocketLib/Socket.c
index af7a3bc..85a5146 100644
--- a/StdLib/EfiSocketLib/Socket.c
+++ b/StdLib/EfiSocketLib/Socket.c
@@ -75,41 +75,18 @@ DT_LAYER mEslLayer;
/**
Initialize an endpoint for network communication.
- The ::Socket routine initializes the communication endpoint by providing
- the support for the socket library function ::socket. The
- <a href="http://www.linuxhowtos.org/manpages/2/socket.htm">Linux</a>,
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html">POSIX</a>
- and <a href="http://msdn.microsoft.com/en-us/library/ms740506(v=VS.85).aspx">Windows</a>
- documentation for the socket routine are available online for reference.
+ This routine initializes the communication endpoint.
+
+ The ::socket routine calls this routine indirectly to create
+ the communication endpoint.
@param [in] pSocketProtocol Address of the socket protocol structure.
@param [in] domain Select the family of protocols for the client or server
- application.
-
- @param [in] type Specifies how to make the network connection. The following values
- are supported:
- <ul>
- <li>
- SOCK_STREAM - Connect to TCP, provides a byte stream
- that is manipluated by read, recv, send and write.
- </li>
- <li>
- SOCK_SEQPACKET - Connect to TCP, provides sequenced packet stream
- that is manipulated by read, recv, send and write.
- </li>
- <li>
- SOCK_DGRAM - Connect to UDP, provides a datagram service that is
- manipulated by recvfrom and sendto.
- </li>
- </ul>
-
- @param [in] protocol Specifies the lower layer protocol to use. The following
- values are supported:
- <ul>
- <li>IPPROTO_TCP</li> - This value must be combined with SOCK_STREAM.</li>
- <li>IPPROTO_UDP</li> - This value must be combined with SOCK_DGRAM.</li>
- </ul>
-
+ application. See the ::socket documentation for values.
+ @param [in] type Specifies how to make the network connection.
+ See the ::socket documentation for values.
+ @param [in] protocol Specifies the lower layer protocol to use.
+ See the ::socket documentation for values.
@param [out] pErrno Address to receive the errno value upon completion.
@retval EFI_SUCCESS - Socket successfully created
@@ -253,11 +230,16 @@ EslSocket (
/**
Accept a network connection.
- The SocketAccept routine waits for a network connection to the socket.
- It is able to return the remote network address to the caller if
- requested.
+ This routine calls the network specific layer to remove the next
+ connection from the FIFO.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::accept calls this routine to poll for a network
+ connection to the socket. When a connection is available
+ this routine returns the ::EFI_SOCKET_PROTOCOL structure address
+ associated with the new socket and the remote network address
+ if requested.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] pSockAddr Address of a buffer to receive the remote
network address.
@@ -266,8 +248,9 @@ EslSocket (
On output specifies the length of the
remote network address.
- @param [out] ppSocketProtocol Address of a buffer to receive the socket protocol
- instance associated with the new socket.
+ @param [out] ppSocketProtocol Address of a buffer to receive the
+ ::EFI_SOCKET_PROTOCOL instance
+ associated with the new socket.
@param [out] pErrno Address to receive the errno value upon completion.
@@ -440,7 +423,7 @@ EslSocketAccept (
/**
Allocate and initialize a DT_SOCKET structure.
- The ::SocketAllocate() function allocates a DT_SOCKET structure
+ This support function allocates a ::DT_SOCKET structure
and installs a protocol on ChildHandle. If pChildHandle is a
pointer to NULL, then a new handle is created and returned in
pChildHandle. If pChildHandle is not a pointer to NULL, then
@@ -452,11 +435,11 @@ EslSocketAccept (
then the protocol is added to the existing UEFI
handle.
@param [in] DebugFlags Flags for debug messages
- @param [in, out] ppSocket The buffer to receive the DT_SOCKET structure address.
+ @param [in, out] ppSocket The buffer to receive the ::DT_SOCKET structure address.
@retval EFI_SUCCESS The protocol was added to ChildHandle.
@retval EFI_INVALID_PARAMETER ChildHandle is NULL.
- @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
the child
@retval other The child handle was not created
@@ -510,9 +493,9 @@ EslSocketAllocate (
pSocket->SocketProtocol.pfnOptionSet = EslSocketOptionSet;
pSocket->SocketProtocol.pfnPoll = EslSocketPoll;
pSocket->SocketProtocol.pfnReceive = EslSocketReceive;
- pSocket->SocketProtocol.pfnSend = EslSocketTransmit;
pSocket->SocketProtocol.pfnShutdown = EslSocketShutdown;
pSocket->SocketProtocol.pfnSocket = EslSocket;
+ pSocket->SocketProtocol.pfnTransmit = EslSocketTransmit;
pSocket->MaxRxBuf = MAX_RX_DATA;
pSocket->MaxTxBuf = MAX_TX_DATA;
@@ -590,11 +573,13 @@ EslSocketAllocate (
/**
Bind a name to a socket.
- The ::SocketBind routine connects a name to a socket on the local machine. The
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html">POSIX</a>
- documentation for the bind routine is available online for reference.
+ This routine calls the network specific layer to save the network
+ address of the local connection point.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::bind routine calls this routine to connect a name
+ (network address and port) to a socket on the local machine.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] pSockAddr Address of a sockaddr structure that contains the
connection point on the local machine. An IPv4 address
@@ -725,9 +710,14 @@ EslSocketBind (
/**
Determine if the socket is closed
- Reverses the operations of the ::SocketAllocate() routine.
+ This routine checks the state of the socket to determine if
+ the network specific layer has completed the close operation.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::close routine polls this routine to determine when the
+ close operation is complete. The close operation needs to
+ reverse the operations of the ::EslSocketAllocate routine.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [out] pErrno Address to receive the errno value upon completion.
@retval EFI_SUCCESS Socket successfully closed
@@ -858,11 +848,19 @@ EslSocketClosePoll (
/**
Start the close operation on the socket
- Start closing the socket by closing all of the ports. Upon
- completion, the ::SocketPoll() routine finishes closing the
- socket.
+ This routine calls the network specific layer to initiate the
+ close state machine. This routine then calls the network
+ specific layer to determine if the close state machine has gone
+ to completion. The result from this poll is returned to the
+ caller.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::close routine calls this routine to start the close
+ operation which reverses the operations of the
+ ::EslSocketAllocate routine. The close routine then polls
+ the ::EslSocketClosePoll routine to determine when the
+ socket is closed.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] bCloseNow Boolean to control close behavior
@param [out] pErrno Address to receive the errno value upon completion.
@@ -964,28 +962,16 @@ EslSocketCloseStart (
/**
Connect to a remote system via the network.
- The ::SocketConnect routine attempts to establish a connection to a
- socket on the local or remote system using the specified address.
- The POSIX
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html">connect</a>
- documentation is available online.
+ This routine calls the network specific layer to establish
+ the remote system address and establish the connection to
+ the remote system.
- There are three states associated with a connection:
- <ul>
- <li>Not connected</li>
- <li>Connection in progress</li>
- <li>Connected</li>
- </ul>
- In the "Not connected" state, calls to ::connect start the connection
- processing and update the state to "Connection in progress". During
- the "Connection in progress" state, connect polls for connection completion
- and moves the state to "Connected" after the connection is established.
- Note that these states are only visible when the file descriptor is marked
- with O_NONBLOCK. Also, the POLL_WRITE bit is set when the connection
- completes and may be used by poll or select as an indicator to call
- connect again.
-
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::connect routine calls this routine to establish a
+ connection with the specified remote system. This routine
+ is designed to be polled by the connect routine for completion
+ of the network connection.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] pSockAddr Network address of the remote system.
@@ -1163,213 +1149,15 @@ EslSocketConnect (
/**
- Creates a child handle and installs a protocol.
-
- The CreateChild() function installs a protocol on ChildHandle.
- If pChildHandle is a pointer to NULL, then a new handle is created and returned in pChildHandle.
- If pChildHandle is not a pointer to NULL, then the protocol installs on the existing pChildHandle.
-
- @param [in] pThis Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
- @param [in] pChildHandle Pointer to the handle of the child to create. If it is NULL,
- then a new handle is created. If it is a pointer to an existing UEFI handle,
- then the protocol is added to the existing UEFI handle.
-
- @retval EFI_SUCCESS The protocol was added to ChildHandle.
- @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
- @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
- the child
- @retval other The child handle was not created
-
-**/
-EFI_STATUS
-EFIAPI
-EslSocketCreateChild (
- IN EFI_SERVICE_BINDING_PROTOCOL * pThis,
- IN OUT EFI_HANDLE * pChildHandle
- )
-{
- DT_SOCKET * pSocket;
- EFI_STATUS Status;
-
- DBG_ENTER ( );
-
- //
- // Create a socket structure
- //
- Status = EslSocketAllocate ( pChildHandle,
- DEBUG_SOCKET,
- &pSocket );
-
- //
- // Return the operation status
- //
- DBG_EXIT_STATUS ( Status );
- return Status;
-}
-
-
-/**
- Destroys a child handle with a protocol installed on it.
-
- The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
- that was installed by CreateChild() from ChildHandle. If the removed protocol is the
- last protocol on ChildHandle, then ChildHandle is destroyed.
-
- @param [in] pThis Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
- @param [in] ChildHandle Handle of the child to destroy
-
- @retval EFI_SUCCESS The protocol was removed from ChildHandle.
- @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
- @retval EFI_INVALID_PARAMETER Child handle is not a valid UEFI Handle.
- @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
- because its services are being used.
- @retval other The child handle was not destroyed
-
-**/
-EFI_STATUS
-EFIAPI
-EslSocketDestroyChild (
- IN EFI_SERVICE_BINDING_PROTOCOL * pThis,
- IN EFI_HANDLE ChildHandle
- )
-{
- DT_LAYER * pLayer;
- DT_SOCKET * pSocket;
- DT_SOCKET * pSocketPrevious;
- EFI_SOCKET_PROTOCOL * pSocketProtocol;
- EFI_STATUS Status;
- EFI_TPL TplPrevious;
-
- DBG_ENTER ( );
-
- //
- // Locate the socket control structure
- //
- pLayer = &mEslLayer;
- Status = gBS->OpenProtocol (
- ChildHandle,
- &gEfiSocketProtocolGuid,
- (VOID **)&pSocketProtocol,
- pLayer->ImageHandle,
- NULL,
- EFI_OPEN_PROTOCOL_GET_PROTOCOL
- );
- if ( !EFI_ERROR ( Status )) {
- pSocket = SOCKET_FROM_PROTOCOL ( pSocketProtocol );
-
- //
- // Synchronize with the socket layer
- //
- RAISE_TPL ( TplPrevious, TPL_SOCKETS );
-
- //
- // Walk the socket list
- //
- pSocketPrevious = pLayer->pSocketList;
- if ( NULL != pSocketPrevious ) {
- if ( pSocket == pSocketPrevious ) {
- //
- // Remove the socket from the head of the list
- //
- pLayer->pSocketList = pSocket->pNext;
- }
- else {
- //
- // Find the socket in the middle of the list
- //
- while (( NULL != pSocketPrevious )
- && ( pSocket != pSocketPrevious->pNext )) {
- //
- // Set the next socket
- //
- pSocketPrevious = pSocketPrevious->pNext;
- }
- if ( NULL != pSocketPrevious ) {
- //
- // Remove the socket from the middle of the list
- //
- pSocketPrevious = pSocket->pNext;
- }
- }
- }
- else {
- DEBUG (( DEBUG_ERROR | DEBUG_POOL,
- "ERROR - Socket list is empty!\r\n" ));
- }
-
- //
- // Release the socket layer synchronization
- //
- RESTORE_TPL ( TplPrevious );
-
- //
- // Determine if the socket was found
- //
- if ( NULL != pSocketPrevious ) {
- pSocket->pNext = NULL;
-
- //
- // Remove the socket protocol
- //
- Status = gBS->UninstallMultipleProtocolInterfaces (
- ChildHandle,
- &gEfiSocketProtocolGuid,
- &pSocket->SocketProtocol,
- NULL );
- if ( !EFI_ERROR ( Status )) {
- DEBUG (( DEBUG_POOL | DEBUG_INFO,
- "Removed: gEfiSocketProtocolGuid from 0x%08x\r\n",
- ChildHandle ));
-
- //
- // Free the socket structure
- //
- Status = gBS->FreePool ( pSocket );
- if ( !EFI_ERROR ( Status )) {
- DEBUG (( DEBUG_POOL,
- "0x%08x: Free pSocket, %d bytes\r\n",
- pSocket,
- sizeof ( *pSocket )));
- }
- else {
- DEBUG (( DEBUG_ERROR | DEBUG_POOL,
- "ERROR - Failed to free pSocket 0x%08x, Status: %r\r\n",
- pSocket,
- Status ));
- }
- }
- else {
- DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INFO,
- "ERROR - Failed to remove gEfiSocketProtocolGuid from 0x%08x, Status: %r\r\n",
- ChildHandle,
- Status ));
- }
- }
- else {
- DEBUG (( DEBUG_ERROR | DEBUG_INFO,
- "ERROR - The socket was not in the socket list!\r\n" ));
- Status = EFI_NOT_FOUND;
- }
- }
- else {
- DEBUG (( DEBUG_ERROR,
- "ERROR - Failed to open socket protocol on 0x%08x, Status; %r\r\n",
- ChildHandle,
- Status ));
- }
-
- //
- // Return the operation status
- //
- DBG_EXIT_STATUS ( Status );
- return Status;
-}
+ Get the local address.
+ This routine calls the network specific layer to get the network
+ address of the local host connection point.
-/**
- Get the local address.
+ The ::getsockname routine calls this routine to obtain the network
+ address associated with the local host connection point.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [out] pAddress Network address to receive the local system address
@@ -1477,7 +1265,13 @@ EslSocketGetLocalAddress (
/**
Get the peer address.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ This routine calls the network specific layer to get the remote
+ system connection point.
+
+ The ::getpeername routine calls this routine to obtain the network
+ address of the remote connection point.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [out] pAddress Network address to receive the remote system address
@@ -1515,47 +1309,53 @@ EslSocketGetPeerAddress (
pSocket = SOCKET_FROM_PROTOCOL ( pSocketProtocol );
//
- // Verify the API
+ // Verify the socket state
//
- if ( NULL == pSocket->pApi->pfnGetRemoteAddr ) {
- Status = EFI_UNSUPPORTED;
- pSocket->errno = ENOTSUP;
- }
- else {
+ Status = EslSocketIsConfigured ( pSocket );
+ if ( !EFI_ERROR ( Status )) {
//
- // Verify the address buffer and length address
+ // Verify the API
//
- if (( NULL != pAddress ) && ( NULL != pAddressLength )) {
+ if ( NULL == pSocket->pApi->pfnGetRemoteAddr ) {
+ Status = EFI_UNSUPPORTED;
+ pSocket->errno = ENOTSUP;
+ }
+ else {
//
- // Verify the socket state
+ // Verify the address buffer and length address
//
- if ( SOCKET_STATE_CONNECTED == pSocket->State ) {
+ if (( NULL != pAddress ) && ( NULL != pAddressLength )) {
//
- // Synchronize with the socket layer
+ // Verify the socket state
//
- RAISE_TPL ( TplPrevious, TPL_SOCKETS );
+ if ( SOCKET_STATE_CONNECTED == pSocket->State ) {
+ //
+ // Synchronize with the socket layer
+ //
+ RAISE_TPL ( TplPrevious, TPL_SOCKETS );
- //
- // Get the remote address
- //
- Status = pSocket->pApi->pfnGetRemoteAddr ( pSocket,
- pAddress,
- pAddressLength );
+ //
+ // Get the remote address
+ //
+ Status = pSocket->pApi->pfnGetRemoteAddr ( pSocket,
+ pAddress,
+ pAddressLength );
- //
- // Release the socket layer synchronization
- //
- RESTORE_TPL ( TplPrevious );
+ //
+ // Release the socket layer synchronization
+ //
+ RESTORE_TPL ( TplPrevious );
+ }
+ else {
+ pSocket->errno = ENOTCONN;
+ Status = EFI_NOT_STARTED;
+ }
}
else {
- pSocket->errno = ENOTCONN;
- Status = EFI_NOT_STARTED;
+ pSocket->errno = EINVAL;
+ Status = EFI_INVALID_PARAMETER;
}
}
- else {
- pSocket->errno = EINVAL;
- Status = EFI_INVALID_PARAMETER;
- }
}
}
@@ -1579,7 +1379,19 @@ EslSocketGetPeerAddress (
/**
Determine if the socket is configured
- @param [in] pSocket The DT_SOCKET structure address
+ This support routine is called to determine if the socket if the
+ configuration call was made to the network layer. The following
+ routines call this routine to verify that they may be successful
+ in their operations:
+ <ul>
+ <li>::EslSocketGetLocalAddress</li>
+ <li>::EslSocketGetPeerAddress</li>
+ <li>::EslSocketPoll</li>
+ <li>::EslSocketReceive</li>
+ <li>::EslSocketTransmit</li>
+ </ul>
+
+ @param [in] pSocket The ::DT_SOCKET structure address
@retval EFI_SUCCESS - The socket is configured
@@ -1643,12 +1455,16 @@ EslSocketIsConfigured (
/**
Establish the known port to listen for network connections.
- The ::SocketListen routine places the port into a state that enables connection
- attempts. Connections are placed into FIFO order in a queue to be serviced
- by the application. The application calls the ::SocketAccept routine to remove
- the next connection from the queue and get the associated socket. The
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html">POSIX</a>
- documentation for the listen routine is available online for reference.
+ This routine calls into the network protocol layer to establish
+ a handler that is called upon connection completion. The handler
+ is responsible for inserting the connection into the FIFO.
+
+ The ::listen routine indirectly calls this routine to place the
+ socket into a state that enables connection attempts. Connections
+ are placed in a FIFO that is serviced by the application. The
+ application calls the ::accept (::EslSocketAccept) routine to
+ remove the next connection from the FIFO and get the associated
+ socket and address.
@param [in] pSocketProtocol Address of the socket protocol structure.
@@ -1809,11 +1625,13 @@ EslSocketListen (
/**
Get the socket options
- Retrieve the socket options one at a time by name. The
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html">POSIX</a>
- documentation is available online.
+ This routine handles the socket level options and passes the
+ others to the network specific layer.
+
+ The ::getsockopt routine calls this routine to retrieve the
+ socket options one at a time by name.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] level Option protocol level
@param [in] OptionName Name of the option
@param [out] pOptionValue Buffer to receive the option value
@@ -1887,11 +1705,24 @@ EslSocketOptionGet (
switch ( OptionName ) {
default:
//
- // Option not supported
+ // See if the protocol will handle the socket option
//
- DEBUG (( DEBUG_INFO | DEBUG_OPTION, "ERROR - Invalid socket option\r\n" ));
- errno = ENOTSUP;
- Status = EFI_UNSUPPORTED;
+ if ( NULL != pSocket->pApi->pfnOptionGet ) {
+ Status = pSocket->pApi->pfnOptionGet ( pSocket,
+ level,
+ OptionName,
+ &pOptionData,
+ &LengthInBytes );
+ errno = pSocket->errno;
+ }
+ else {
+ //
+ // Socket option not supported
+ //
+ DEBUG (( DEBUG_INFO | DEBUG_OPTION, "ERROR - Invalid socket option\r\n" ));
+ errno = ENOTSUP;
+ Status = EFI_UNSUPPORTED;
+ }
break;
case SO_OOBINLINE:
@@ -1980,11 +1811,13 @@ EslSocketOptionGet (
/**
Set the socket options
- Adjust the socket options one at a time by name. The
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html">POSIX</a>
- documentation is available online.
+ This routine handles the socket level options and passes the
+ others to the network specific layer.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::setsockopt routine calls this routine to adjust the socket
+ options one at a time by name.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] level Option protocol level
@param [in] OptionName Name of the option
@param [in] pOptionValue Buffer containing the option value
@@ -2054,10 +1887,23 @@ EslSocketOptionSet (
switch ( OptionName ) {
default:
//
- // Option not supported
+ // See if the protocol will handle the socket option
//
- errno = ENOTSUP;
- Status = EFI_UNSUPPORTED;
+ if ( NULL != pSocket->pApi->pfnOptionSet ) {
+ Status = pSocket->pApi->pfnOptionSet ( pSocket,
+ level,
+ OptionName,
+ pOptionValue,
+ OptionLength );
+ errno = pSocket->errno;
+ }
+ else {
+ //
+ // Option not supported
+ //
+ errno = ENOTSUP;
+ Status = EFI_UNSUPPORTED;
+ }
break;
case SO_OOBINLINE:
@@ -2144,7 +1990,10 @@ EslSocketOptionSet (
/**
Allocate a packet for a receive or transmit operation
- @param [in] ppPacket Address to receive the DT_PACKET structure
+ This support routine is called by the network specific RxStart
+ and TxBuffer routines to get buffer space for the next operation.
+
+ @param [in] ppPacket Address to receive the ::DT_PACKET structure
@param [in] LengthInBytes Length of the packet structure
@param [in] DebugFlags Flags for debug messages
@@ -2202,6 +2051,11 @@ EslSocketPacketAllocate (
/**
Free a packet used for receive or transmit operation
+ This support routine is called by the network specific Close
+ and TxComplete routines and during error cases in RxComplete
+ and TxBuffer. Note that the network layers typically place
+ receive packets on the DT_SOCKET::pRxFree list for reuse.
+
@param [in] pPacket Address of the DT_PACKET structure
@param [in] DebugFlags Flags for debug messages
@@ -2248,10 +2102,14 @@ EslSocketPacketFree (
/**
Poll a socket for pending activity.
- The SocketPoll routine checks a socket for pending activity associated
- with the event mask. Activity is returned in the detected event buffer.
+ This routine builds a detected event mask which is returned to
+ the caller in the buffer provided.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::poll routine calls this routine to determine if the socket
+ needs to be serviced as a result of connection, error, receive or
+ transmit activity.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] Events Events of interest for this socket
@@ -2403,8 +2261,15 @@ EslSocketPoll (
/**
Receive data from a network connection.
+ This routine calls the network specific routine to remove the
+ next portion of data from the receive queue and return it to the
+ caller.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::recvfrom routine calls this routine to determine if any data
+ is received from the remote system. Note that the other routines
+ ::recv and ::read are layered on top of ::recvfrom.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] Flags Message control flags
@@ -2543,10 +2408,13 @@ EslSocketReceive (
/**
Shutdown the socket receive and transmit operations
- The SocketShutdown routine stops the socket receive and transmit
- operations.
+ This routine sets a flag to stop future transmissions and calls
+ the network specific layer to cancel the pending receive operation.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::shutdown routine calls this routine to stop receive and transmit
+ operations on the socket.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] How Which operations to stop
@@ -2663,10 +2531,16 @@ EslSocketShutdown (
/**
Send data using a network connection.
- The SocketTransmit routine queues the data for transmission to the
- remote network connection.
+ This routine calls the network specific layer to queue the data
+ for transmission. Eventually the buffer will reach the head of
+ the queue and will get transmitted over the network. For datagram
+ sockets there is no guarantee that the data reaches the application
+ running on the remote system.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::sendto routine calls this routine to send data to the remote
+ system. Note that ::send and ::write are layered on top of ::sendto.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] Flags Message control flags
@@ -2824,12 +2698,3 @@ EslSocketTransmit (
DBG_EXIT_STATUS ( Status );
return Status;
}
-
-
-/**
- Socket layer's service binding protocol delcaration.
-**/
-EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding = {
- EslSocketCreateChild,
- EslSocketDestroyChild
-};
diff --git a/StdLib/EfiSocketLib/Socket.h b/StdLib/EfiSocketLib/Socket.h
index c680679..2b9bec2 100644
--- a/StdLib/EfiSocketLib/Socket.h
+++ b/StdLib/EfiSocketLib/Socket.h
@@ -730,7 +730,7 @@ typedef struct {
//
// Service binding interface
//
- EFI_SERVICE_BINDING_PROTOCOL ServiceBinding;///< Driver's binding
+ CONST EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding; ///< Driver's binding
//
// Image data
@@ -748,14 +748,6 @@ typedef struct {
// Socket management
//
DT_SOCKET * pSocketList; ///< List of sockets
-
- //
- // TCP4 service
- //
- UINTN TcpCloseMax4; ///< Number of entries in the ring buffer
- UINTN TcpCloseIn4; ///< Offset into TcpClose4 ring buffer - Close request
- UINTN TcpCloseOut4; ///< Offset into TcpClose4 ring buffer - Close operation
- EFI_TCP4_PROTOCOL ** ppTcpClose4; ///< Ring buffer to close TCP4 ports
} DT_LAYER;
#define LAYER_FROM_SERVICE(a) CR (a, DT_LAYER, ServiceBinding, LAYER_SIGNATURE) ///< Locate DT_LAYER from service binding
@@ -770,6 +762,8 @@ extern CONST DT_PROTOCOL_API cEslIp4Api;
extern CONST DT_PROTOCOL_API cEslTcp4Api;
extern CONST DT_PROTOCOL_API cEslUdp4Api;
+extern CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding;
+
//------------------------------------------------------------------------------
// Socket Support Routines
//------------------------------------------------------------------------------
diff --git a/StdLib/EfiSocketLib/Tcp4.c b/StdLib/EfiSocketLib/Tcp4.c
index bec5dbe..6cd9a87 100644
--- a/StdLib/EfiSocketLib/Tcp4.c
+++ b/StdLib/EfiSocketLib/Tcp4.c
@@ -1197,6 +1197,7 @@ EslTcpListenComplete4 (
//
// Clone the socket parameters
//
+ pNewSocket->pApi = pSocket->pApi;
pNewSocket->Domain = pSocket->Domain;
pNewSocket->Protocol = pSocket->Protocol;
pNewSocket->Type = pSocket->Type;
diff --git a/StdLib/EfiSocketLib/UseEfiSocketLib.c b/StdLib/EfiSocketLib/UseEfiSocketLib.c
index 70523fb..a431cc8 100644
--- a/StdLib/EfiSocketLib/UseEfiSocketLib.c
+++ b/StdLib/EfiSocketLib/UseEfiSocketLib.c
@@ -15,14 +15,25 @@
#include "Socket.h"
+/**
+ Tag GUID - IPv4 in use by an application using EfiSocketLib
+**/
CONST EFI_GUID mEslIp4ServiceGuid = {
0x9c756011, 0x5d44, 0x4ee0, { 0xbc, 0xe7, 0xc3, 0x82, 0x18, 0xfe, 0x39, 0x8d }
};
+
+/**
+ Tag GUID - TCPv4 in use by an application using EfiSocketLib
+**/
CONST EFI_GUID mEslTcp4ServiceGuid = {
0xffc659c2, 0x4ef2, 0x4532, { 0xb8, 0x75, 0xcd, 0x9a, 0xa4, 0x27, 0x4c, 0xde }
};
+
+/**
+ Tag GUID - UDPv4 in use by an application using EfiSocketLib
+**/
CONST EFI_GUID mEslUdp4ServiceGuid = {
0x44e03a55, 0x8d97, 0x4511, { 0xbf, 0xef, 0xa, 0x8b, 0xc6, 0x2c, 0x25, 0xae }
};
@@ -31,6 +42,11 @@ CONST EFI_GUID mEslUdp4ServiceGuid = {
/**
Connect to the EFI socket library
+ This routine is called from the socket routine in BsdSocketLib
+ to create the data structure for a socket. This specific
+ implementation is used when an application links directly to
+ the EslSocketLib.
+
@param [in] ppSocketProtocol Address to receive the socket protocol address
@return Value for ::errno, zero (0) indicates success.
@@ -81,6 +97,10 @@ EslServiceGetProtocol (
/**
Connect to the network layer
+ Constructor for the EfiSocketLib when the library is linked
+ directly to an application. This routine locates the network
+ devices and makes them available to EfiSocketLib.
+
@retval EFI_SUCCESS Successfully connected to the network layer
**/
@@ -158,6 +178,10 @@ EslServiceNetworkConnect (
/**
Disconnect from the network layer
+ Destructor for the EfiSocketLib when the library is linked
+ directly to an application. This routine breaks any connections
+ to the network devices and removes them from use by EfiSocketLib.
+
@retval EFI_SUCCESS Successfully disconnected from the network layer
**/
@@ -238,5 +262,14 @@ EslServiceNetworkDisconnect (
}
-PFN_ESL_xSTRUCTOR mpfnEslConstructor = EslServiceNetworkConnect;
-PFN_ESL_xSTRUCTOR mpfnEslDestructor = EslServiceNetworkDisconnect;
+/**
+ Socket layer's service binding protocol delcaration.
+**/
+CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding = {
+ NULL,
+ NULL
+};
+
+
+PFN_ESL_xSTRUCTOR mpfnEslConstructor = EslServiceNetworkConnect; ///< Constructor for EfiSocketLib
+PFN_ESL_xSTRUCTOR mpfnEslDestructor = EslServiceNetworkDisconnect; ///< Destructor for EfiSocketLib
diff --git a/StdLib/Include/Efi/EfiSocketLib.h b/StdLib/Include/Efi/EfiSocketLib.h
index 79f60aa..0c6108a 100644
--- a/StdLib/Include/Efi/EfiSocketLib.h
+++ b/StdLib/Include/Efi/EfiSocketLib.h
@@ -166,151 +166,166 @@ extern CONST DT_SOCKET_BINDING cEslSocketBinding[]; ///< List of network servic
extern CONST UINTN cEslSocketBindingEntries; ///< Number of network service bindings
//------------------------------------------------------------------------------
-// Service Support Routines
+// DXE Support Routines
//------------------------------------------------------------------------------
/**
- Connect to the network service bindings
+ Creates a child handle and installs a protocol.
- Walk the network service protocols on the controller handle and
- locate any that are not in use. Create service structures to
- manage the service binding for the socket driver.
+ When the socket application is linked against UseSocketDxe, the ::socket
+ routine indirectly calls this routine in SocketDxe to create a child
+ handle if necessary and install the socket protocol on the handle.
+ Upon return, EslServiceGetProtocol in UseSocketLib returns the
+ ::EFI_SOCKET_PROTOCOL address to the socket routine.
- @param [in] BindingHandle Handle for protocol binding.
- @param [in] Controller Handle of device to work with.
+ @param [in] pThis Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
+ @param [in] pChildHandle Pointer to the handle of the child to create. If it is NULL,
+ then a new handle is created. If it is a pointer to an existing UEFI handle,
+ then the protocol is added to the existing UEFI handle.
- @retval EFI_SUCCESS This driver is added to Controller.
- @retval other This driver does not support this device.
+ @retval EFI_SUCCESS The protocol was added to ChildHandle.
+ @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
+ @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
+ the child
+ @retval other The child handle was not created
**/
EFI_STATUS
EFIAPI
-EslServiceConnect (
- IN EFI_HANDLE BindingHandle,
- IN EFI_HANDLE Controller
+EslDxeCreateChild (
+ IN EFI_SERVICE_BINDING_PROTOCOL * pThis,
+ IN OUT EFI_HANDLE * pChildHandle
);
/**
- Shutdown the network connections to this controller by removing
- NetworkInterfaceIdentifier protocol and closing the DevicePath
- and PciIo protocols on Controller.
+ Destroys a child handle with a protocol installed on it.
+
+ When the socket application is linked against UseSocketDxe, the ::close
+ routine indirectly calls this routine in SocketDxe to undo the operations
+ done by the ::EslDxeCreateChild routine. This routine removes the socket
+ protocol from the handle and then destroys the child handle if there are
+ no other protocols attached.
- @param [in] BindingHandle Handle for protocol binding.
- @param [in] Controller Handle of device to stop driver on.
+ @param [in] pThis Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
+ @param [in] ChildHandle Handle of the child to destroy
- @retval EFI_SUCCESS This driver is removed Controller.
- @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
- @retval other This driver was not removed from this device.
+ @retval EFI_SUCCESS The protocol was removed from ChildHandle.
+ @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
+ @retval EFI_INVALID_PARAMETER Child handle is not a valid UEFI Handle.
+ @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
+ because its services are being used.
+ @retval other The child handle was not destroyed
**/
EFI_STATUS
EFIAPI
-EslServiceDisconnect (
- IN EFI_HANDLE BindingHandle,
- IN EFI_HANDLE Controller
+EslDxeDestroyChild (
+ IN EFI_SERVICE_BINDING_PROTOCOL * pThis,
+ IN EFI_HANDLE ChildHandle
);
/**
Install the socket service
+SocketDxe uses this routine to announce the socket interface to
+the rest of EFI.
+
@param [in] pImageHandle Address of the image handle
@retval EFI_SUCCESS Service installed successfully
**/
EFI_STATUS
EFIAPI
-EslServiceInstall (
+EslDxeInstall (
IN EFI_HANDLE * pImageHandle
);
/**
-Initialize the service layer
-
-@param [in] ImageHandle Handle for the image.
-
-**/
-VOID
-EFIAPI
-EslServiceLoad (
- IN EFI_HANDLE ImageHandle
- );
-
-/**
Uninstall the socket service
+SocketDxe uses this routine to notify EFI that the socket layer
+is no longer available.
+
@param [in] ImageHandle Handle for the image.
@retval EFI_SUCCESS Service installed successfully
**/
EFI_STATUS
EFIAPI
-EslServiceUninstall (
+EslDxeUninstall (
IN EFI_HANDLE ImageHandle
);
+//------------------------------------------------------------------------------
+// Service Support Routines
+//------------------------------------------------------------------------------
+
/**
- Shutdown the service layer
+ Connect to the network service bindings
+
+ Walk the network service protocols on the controller handle and
+ locate any that are not in use. Create ::DT_SERVICE structures to
+ manage the network layer interfaces for the socket driver. Tag
+ each of the network interfaces that are being used. Finally, this
+ routine calls DT_SOCKET_BINDING::pfnInitialize to prepare the network
+ interface for use by the socket layer.
+
+ @param [in] BindingHandle Handle for protocol binding.
+ @param [in] Controller Handle of device to work with.
+
+ @retval EFI_SUCCESS This driver is added to Controller.
+ @retval other This driver does not support this device.
**/
-VOID
+EFI_STATUS
EFIAPI
-EslServiceUnload (
- VOID
+EslServiceConnect (
+ IN EFI_HANDLE BindingHandle,
+ IN EFI_HANDLE Controller
);
-//------------------------------------------------------------------------------
-// Socket Service Binding Protocol Routines
-//------------------------------------------------------------------------------
-
/**
- Creates a child handle and installs a protocol.
+ Shutdown the connections to the network layer by locating the
+ tags on the network interfaces established by ::EslServiceConnect.
+ This routine calls DT_SOCKET_BINDING::pfnShutdown to shutdown the any
+ activity on the network interface and then free the ::DT_SERVICE
+ structures.
- The CreateChild() function installs a protocol on ChildHandle.
- If pChildHandle is a pointer to NULL, then a new handle is created and returned in pChildHandle.
- If pChildHandle is not a pointer to NULL, then the protocol installs on the existing pChildHandle.
-
- @param [in] pThis Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
- @param [in] pChildHandle Pointer to the handle of the child to create. If it is NULL,
- then a new handle is created. If it is a pointer to an existing UEFI handle,
- then the protocol is added to the existing UEFI handle.
+ @param [in] BindingHandle Handle for protocol binding.
+ @param [in] Controller Handle of device to stop driver on.
- @retval EFI_SUCCES The protocol was added to ChildHandle.
- @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
- @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
- the child
- @retval other The child handle was not created
+ @retval EFI_SUCCESS This driver is removed Controller.
+ @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
+ @retval other This driver was not removed from this device.
**/
EFI_STATUS
EFIAPI
-EslSocketCreateChild (
- IN EFI_SERVICE_BINDING_PROTOCOL * pThis,
- IN OUT EFI_HANDLE * pChildHandle
+EslServiceDisconnect (
+ IN EFI_HANDLE BindingHandle,
+ IN EFI_HANDLE Controller
);
/**
- Destroys a child handle with a protocol installed on it.
+Initialize the service layer
- The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
- that was installed by CreateChild() from ChildHandle. If the removed protocol is the
- last protocol on ChildHandle, then ChildHandle is destroyed.
+@param [in] ImageHandle Handle for the image.
- @param [in] pThis Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
- @param [in] ChildHandle Handle of the child to destroy
+**/
+VOID
+EFIAPI
+EslServiceLoad (
+ IN EFI_HANDLE ImageHandle
+ );
- @retval EFI_SUCCES The protocol was removed from ChildHandle.
- @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
- @retval EFI_INVALID_PARAMETER Child handle is not a valid UEFI Handle.
- @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
- because its services are being used.
- @retval other The child handle was not destroyed
+/**
+ Shutdown the service layer
**/
-EFI_STATUS
+VOID
EFIAPI
-EslSocketDestroyChild (
- IN EFI_SERVICE_BINDING_PROTOCOL * pThis,
- IN EFI_HANDLE ChildHandle
+EslServiceUnload (
+ VOID
);
//------------------------------------------------------------------------------
@@ -320,11 +335,13 @@ EslSocketDestroyChild (
/**
Bind a name to a socket.
- The ::EslSocketBind routine connects a name to a socket on the local machine. The
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html">POSIX</a>
- documentation for the bind routine is available online for reference.
+ This routine calls the network specific layer to save the network
+ address of the local connection point.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::bind routine calls this routine to connect a name
+ (network address and port) to a socket on the local machine.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] pSockAddr Address of a sockaddr structure that contains the
connection point on the local machine. An IPv4 address
@@ -336,7 +353,7 @@ EslSocketDestroyChild (
number from the dynamic range. Specifying a specific
port number causes the network layer to use that port.
- @param [in] SockAddrLength Specifies the length in bytes of the sockaddr structure.
+ @param [in] SockAddrLen Specifies the length in bytes of the sockaddr structure.
@param [out] pErrno Address to receive the errno value upon completion.
@@ -354,9 +371,14 @@ EslSocketBind (
/**
Determine if the socket is closed
- Reverses the operations of the ::EslSocketAllocate() routine.
+ This routine checks the state of the socket to determine if
+ the network specific layer has completed the close operation.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::close routine polls this routine to determine when the
+ close operation is complete. The close operation needs to
+ reverse the operations of the ::EslSocketAllocate routine.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [out] pErrno Address to receive the errno value upon completion.
@retval EFI_SUCCESS Socket successfully closed
@@ -374,11 +396,19 @@ EslSocketClosePoll (
/**
Start the close operation on the socket
- Start closing the socket by closing all of the ports. Upon
- completion, the ::EslSocketPoll() routine finishes closing the
- socket.
+ This routine calls the network specific layer to initiate the
+ close state machine. This routine then calls the network
+ specific layer to determine if the close state machine has gone
+ to completion. The result from this poll is returned to the
+ caller.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::close routine calls this routine to start the close
+ operation which reverses the operations of the
+ ::EslSocketAllocate routine. The close routine then polls
+ the ::EslSocketClosePoll routine to determine when the
+ socket is closed.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] bCloseNow Boolean to control close behavior
@param [out] pErrno Address to receive the errno value upon completion.
@@ -398,35 +428,23 @@ EslSocketCloseStart (
/**
Connect to a remote system via the network.
- The ::EslSocketConnect routine attempts to establish a connection to a
- socket on the local or remote system using the specified address.
- The POSIX
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html">connect</a>
- documentation is available online.
-
- There are three states associated with a connection:
- <ul>
- <li>Not connected</li>
- <li>Connection in progress</li>
- <li>Connected</li>
- </ul>
- In the "Not connected" state, calls to ::connect start the connection
- processing and update the state to "Connection in progress". During
- the "Connection in progress" state, connect polls for connection completion
- and moves the state to "Connected" after the connection is established.
- Note that these states are only visible when the file descriptor is marked
- with O_NONBLOCK. Also, the POLL_WRITE bit is set when the connection
- completes and may be used by poll or select as an indicator to call
- connect again.
+ This routine calls the network specific layer to establish
+ the remote system address and establish the connection to
+ the remote system.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::connect routine calls this routine to establish a
+ connection with the specified remote system. This routine
+ is designed to be polled by the connect routine for completion
+ of the network connection.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] pSockAddr Network address of the remote system.
-
+
@param [in] SockAddrLength Length in bytes of the network address.
-
+
@param [out] pErrno Address to receive the errno value upon completion.
-
+
@retval EFI_SUCCESS The connection was successfully established.
@retval EFI_NOT_READY The connection is in progress, call this routine again.
@retval Others The connection attempt failed.
@@ -443,8 +461,14 @@ EslSocketConnect (
/**
Get the local address.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ This routine calls the network specific layer to get the network
+ address of the local host connection point.
+
+ The ::getsockname routine calls this routine to obtain the network
+ address associated with the local host connection point.
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+
@param [out] pAddress Network address to receive the local system address
@param [in,out] pAddressLength Length of the local network address structure
@@ -465,8 +489,14 @@ EslSocketGetLocalAddress (
/**
Get the peer address.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ This routine calls the network specific layer to get the remote
+ system connection point.
+
+ The ::getpeername routine calls this routine to obtain the network
+ address of the remote connection point.
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+
@param [out] pAddress Network address to receive the remote system address
@param [in,out] pAddressLength Length of the remote network address structure
@@ -487,12 +517,16 @@ EslSocketGetPeerAddress (
/**
Establish the known port to listen for network connections.
- The ::EslSocketListen routine places the port into a state that enables connection
- attempts. Connections are placed into FIFO order in a queue to be serviced
- by the application. The application calls the ::EslSocketAccept routine to remove
- the next connection from the queue and get the associated socket. The
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html">POSIX</a>
- documentation for the bind routine is available online for reference.
+ This routine calls into the network protocol layer to establish
+ a handler that is called upon connection completion. The handler
+ is responsible for inserting the connection into the FIFO.
+
+ The ::listen routine indirectly calls this routine to place the
+ socket into a state that enables connection attempts. Connections
+ are placed in a FIFO that is serviced by the application. The
+ application calls the ::accept (::EslSocketAccept) routine to
+ remove the next connection from the FIFO and get the associated
+ socket and address.
@param [in] pSocketProtocol Address of the socket protocol structure.
@@ -517,17 +551,19 @@ EslSocketListen (
/**
Get the socket options
- Retrieve the socket options one at a time by name. The
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html">POSIX</a>
- documentation is available online.
+ This routine handles the socket level options and passes the
+ others to the network specific layer.
- @param [in] pSocketProtocol Address of the socket protocol structure.
- @param [in] level Option protocol level
- @param [in] option_name Name of the option
- @param [out] option_value Buffer to receive the option value
- @param [in,out] option_len Length of the buffer in bytes,
- upon return length of the option value in bytes
- @param [out] pErrno Address to receive the errno value upon completion.
+ The ::getsockopt routine calls this routine to retrieve the
+ socket options one at a time by name.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+ @param [in] level Option protocol level
+ @param [in] OptionName Name of the option
+ @param [out] pOptionValue Buffer to receive the option value
+ @param [in,out] pOptionLength Length of the buffer in bytes,
+ upon return length of the option value in bytes
+ @param [out] pErrno Address to receive the errno value upon completion.
@retval EFI_SUCCESS - Socket data successfully received
@@ -545,18 +581,20 @@ EslSocketOptionGet (
/**
Set the socket options
- Adjust the socket options one at a time by name. The
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html">POSIX</a>
- documentation is available online.
+ This routine handles the socket level options and passes the
+ others to the network specific layer.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::setsockopt routine calls this routine to adjust the socket
+ options one at a time by name.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] level Option protocol level
- @param [in] option_name Name of the option
- @param [in] option_value Buffer containing the option value
- @param [in] option_len Length of the buffer in bytes
+ @param [in] OptionName Name of the option
+ @param [in] pOptionValue Buffer containing the option value
+ @param [in] OptionLength Length of the buffer in bytes
@param [out] pErrno Address to receive the errno value upon completion.
- @retval EFI_SUCCESS - Socket data successfully received
+ @retval EFI_SUCCESS - Option successfully set
**/
EFI_STATUS
@@ -572,10 +610,14 @@ EslSocketOptionSet (
/**
Poll a socket for pending activity.
- The SocketPoll routine checks a socket for pending activity associated
- with the event mask. Activity is returned in the detected event buffer.
+ This routine builds a detected event mask which is returned to
+ the caller in the buffer provided.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::poll routine calls this routine to determine if the socket
+ needs to be serviced as a result of connection, error, receive or
+ transmit activity.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] Events Events of interest for this socket
@@ -598,15 +640,22 @@ EslSocketPoll (
/**
Receive data from a network connection.
+ This routine calls the network specific routine to remove the
+ next portion of data from the receive queue and return it to the
+ caller.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::recvfrom routine calls this routine to determine if any data
+ is received from the remote system. Note that the other routines
+ ::recv and ::read are layered on top of ::recvfrom.
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+
@param [in] Flags Message control flags
-
+
@param [in] BufferLength Length of the the buffer
-
+
@param [in] pBuffer Address of a buffer to receive the data.
-
+
@param [in] pDataLength Number of received data bytes in the buffer.
@param [out] pAddress Network address to receive the remote system address
@@ -633,13 +682,16 @@ EslSocketReceive (
/**
Shutdown the socket receive and transmit operations
- The SocketShutdown routine stops the socket receive and transmit
- operations.
+ This routine sets a flag to stop future transmissions and calls
+ the network specific layer to cancel the pending receive operation.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::shutdown routine calls this routine to stop receive and transmit
+ operations on the socket.
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+
@param [in] How Which operations to stop
-
+
@param [out] pErrno Address to receive the errno value upon completion.
@retval EFI_SUCCESS - Socket operations successfully shutdown
@@ -655,17 +707,23 @@ EslSocketShutdown (
/**
Send data using a network connection.
- The SocketTransmit routine queues the data for transmission to the
- remote network connection.
+ This routine calls the network specific layer to queue the data
+ for transmission. Eventually the buffer will reach the head of
+ the queue and will get transmitted over the network. For datagram
+ sockets there is no guarantee that the data reaches the application
+ running on the remote system.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::sendto routine calls this routine to send data to the remote
+ system. Note that ::send and ::write are layered on top of ::sendto.
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+
@param [in] Flags Message control flags
-
+
@param [in] BufferLength Length of the the buffer
-
+
@param [in] pBuffer Address of a buffer containing the data to send
-
+
@param [in] pDataLength Address to receive the number of data bytes sent
@param [in] pAddress Network address of the remote system address
@@ -674,7 +732,7 @@ EslSocketShutdown (
@param [out] pErrno Address to receive the errno value upon completion.
- @retval EFI_SUCCESS - Socket data successfully received
+ @retval EFI_SUCCESS - Socket data successfully queued for transmit
**/
EFI_STATUS
diff --git a/StdLib/Include/Protocol/EfiSocket.h b/StdLib/Include/Protocol/EfiSocket.h
index 0dff0df..2664f01 100644
--- a/StdLib/Include/Protocol/EfiSocket.h
+++ b/StdLib/Include/Protocol/EfiSocket.h
@@ -27,6 +27,9 @@
// Data Types
//------------------------------------------------------------------------------
+/**
+EfiSocketLib (SocketDxe) interface
+**/
typedef struct _EFI_SOCKET_PROTOCOL EFI_SOCKET_PROTOCOL;
/**
@@ -45,11 +48,11 @@ EFI_STATUS
// Data
//------------------------------------------------------------------------------
-extern PFN_ESL_xSTRUCTOR mpfnEslConstructor;
-extern PFN_ESL_xSTRUCTOR mpfnEslDestructor;
+extern PFN_ESL_xSTRUCTOR mpfnEslConstructor; ///< Constructor address for EslSocketLib
+extern PFN_ESL_xSTRUCTOR mpfnEslDestructor; ///< Destructor address for EslSocketLib
-extern EFI_GUID gEfiSocketProtocolGuid;
-extern EFI_GUID gEfiSocketServiceBindingProtocolGuid;
+extern EFI_GUID gEfiSocketProtocolGuid; ///< Socket protocol GUID
+extern EFI_GUID gEfiSocketServiceBindingProtocolGuid; ///< Socket layer service binding protocol GUID
//------------------------------------------------------------------------------
// Socket API
@@ -58,11 +61,16 @@ extern EFI_GUID gEfiSocketServiceBindingProtocolGuid;
/**
Accept a network connection.
- The SocketAccept routine waits for a network connection to the socket.
- It is able to return the remote network address to the caller if
- requested.
+ This routine calls the network specific layer to remove the next
+ connection from the FIFO.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::accept calls this routine to poll for a network
+ connection to the socket. When a connection is available
+ this routine returns the ::EFI_SOCKET_PROTOCOL structure address
+ associated with the new socket and the remote network address
+ if requested.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] pSockAddr Address of a buffer to receive the remote
network address.
@@ -71,8 +79,9 @@ extern EFI_GUID gEfiSocketServiceBindingProtocolGuid;
On output specifies the length of the
remote network address.
- @param [out] ppSocketProtocol Address of a buffer to receive the socket protocol
- instance associated with the new socket.
+ @param [out] ppSocketProtocol Address of a buffer to receive the
+ ::EFI_SOCKET_PROTOCOL instance
+ associated with the new socket.
@param [out] pErrno Address to receive the errno value upon completion.
@@ -93,11 +102,13 @@ EFI_STATUS
/**
Bind a name to a socket.
- The ::SocketBind routine connects a name to a socket on the local machine. The
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html">POSIX</a>
- documentation for the bind routine is available online for reference.
+ This routine calls the network specific layer to save the network
+ address of the local connection point.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::bind routine calls this routine to connect a name
+ (network address and port) to a socket on the local machine.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] pSockAddr Address of a sockaddr structure that contains the
connection point on the local machine. An IPv4 address
@@ -128,9 +139,14 @@ EFI_STATUS
/**
Determine if the socket is closed
- Reverses the operations of the ::SocketAllocate() routine.
+ This routine checks the state of the socket to determine if
+ the network specific layer has completed the close operation.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::close routine polls this routine to determine when the
+ close operation is complete. The close operation needs to
+ reverse the operations of the ::EslSocketAllocate routine.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [out] pErrno Address to receive the errno value upon completion.
@retval EFI_SUCCESS Socket successfully closed
@@ -149,11 +165,19 @@ EFI_STATUS
/**
Start the close operation on the socket
- Start closing the socket by closing all of the ports. Upon
- completion, the ::pfnClosePoll() routine finishes closing the
- socket.
+ This routine calls the network specific layer to initiate the
+ close state machine. This routine then calls the network
+ specific layer to determine if the close state machine has gone
+ to completion. The result from this poll is returned to the
+ caller.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::close routine calls this routine to start the close
+ operation which reverses the operations of the
+ ::EslSocketAllocate routine. The close routine then polls
+ the ::EslSocketClosePoll routine to determine when the
+ socket is closed.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] bCloseNow Boolean to control close behavior
@param [out] pErrno Address to receive the errno value upon completion.
@@ -174,35 +198,23 @@ EFI_STATUS
/**
Connect to a remote system via the network.
- The ::Connect routine attempts to establish a connection to a
- socket on the local or remote system using the specified address.
- The
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html">POSIX</a>
- documentation is available online.
-
- There are three states associated with a connection:
- <ul>
- <li>Not connected</li>
- <li>Connection in progress</li>
- <li>Connected</li>
- </ul>
- In the "Not connected" state, calls to ::connect start the connection
- processing and update the state to "Connection in progress". During
- the "Connection in progress" state, connect polls for connection completion
- and moves the state to "Connected" after the connection is established.
- Note that these states are only visible when the file descriptor is marked
- with O_NONBLOCK. Also, the POLL_WRITE bit is set when the connection
- completes and may be used by poll or select as an indicator to call
- connect again.
+ This routine calls the network specific layer to establish
+ the remote system address and establish the connection to
+ the remote system.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::connect routine calls this routine to establish a
+ connection with the specified remote system. This routine
+ is designed to be polled by the connect routine for completion
+ of the network connection.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] pSockAddr Network address of the remote system.
-
+
@param [in] SockAddrLength Length in bytes of the network address.
-
+
@param [out] pErrno Address to receive the errno value upon completion.
-
+
@retval EFI_SUCCESS The connection was successfully established.
@retval EFI_NOT_READY The connection is in progress, call this routine again.
@retval Others The connection attempt failed.
@@ -220,8 +232,14 @@ EFI_STATUS
/**
Get the local address.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ This routine calls the network specific layer to get the network
+ address of the local host connection point.
+
+ The ::getsockname routine calls this routine to obtain the network
+ address associated with the local host connection point.
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+
@param [out] pAddress Network address to receive the local system address
@param [in,out] pAddressLength Length of the local network address structure
@@ -243,8 +261,14 @@ EFI_STATUS
/**
Get the peer address.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ This routine calls the network specific layer to get the remote
+ system connection point.
+
+ The ::getpeername routine calls this routine to obtain the network
+ address of the remote connection point.
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+
@param [out] pAddress Network address to receive the remote system address
@param [in,out] pAddressLength Length of the remote network address structure
@@ -266,12 +290,16 @@ EFI_STATUS
/**
Establish the known port to listen for network connections.
- The ::SocketAisten routine places the port into a state that enables connection
- attempts. Connections are placed into FIFO order in a queue to be serviced
- by the application. The application calls the ::SocketAccept routine to remove
- the next connection from the queue and get the associated socket. The
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html">POSIX</a>
- documentation for the bind routine is available online for reference.
+ This routine calls into the network protocol layer to establish
+ a handler that is called upon connection completion. The handler
+ is responsible for inserting the connection into the FIFO.
+
+ The ::listen routine indirectly calls this routine to place the
+ socket into a state that enables connection attempts. Connections
+ are placed in a FIFO that is serviced by the application. The
+ application calls the ::accept (::EslSocketAccept) routine to
+ remove the next connection from the FIFO and get the associated
+ socket and address.
@param [in] pSocketProtocol Address of the socket protocol structure.
@@ -297,11 +325,13 @@ EFI_STATUS
/**
Get the socket options
- Retrieve the socket options one at a time by name. The
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html">POSIX</a>
- documentation is available online.
+ This routine handles the socket level options and passes the
+ others to the network specific layer.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::getsockopt routine calls this routine to retrieve the
+ socket options one at a time by name.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] level Option protocol level
@param [in] OptionName Name of the option
@param [out] pOptionValue Buffer to receive the option value
@@ -326,18 +356,20 @@ EFI_STATUS
/**
Set the socket options
- Adjust the socket options one at a time by name. The
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html">POSIX</a>
- documentation is available online.
+ This routine handles the socket level options and passes the
+ others to the network specific layer.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::setsockopt routine calls this routine to adjust the socket
+ options one at a time by name.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] level Option protocol level
@param [in] OptionName Name of the option
@param [in] pOptionValue Buffer containing the option value
@param [in] OptionLength Length of the buffer in bytes
@param [out] pErrno Address to receive the errno value upon completion.
- @retval EFI_SUCCESS - Socket data successfully received
+ @retval EFI_SUCCESS - Option successfully set
**/
typedef
@@ -354,10 +386,14 @@ EFI_STATUS
/**
Poll a socket for pending activity.
- The SocketPoll routine checks a socket for pending activity associated
- with the event mask. Activity is returned in the detected event buffer.
+ This routine builds a detected event mask which is returned to
+ the caller in the buffer provided.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::poll routine calls this routine to determine if the socket
+ needs to be serviced as a result of connection, error, receive or
+ transmit activity.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
@param [in] Events Events of interest for this socket
@@ -381,19 +417,22 @@ EFI_STATUS
/**
Receive data from a network connection.
- The ::recv routine waits for receive data from a remote network
- connection. The
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html">POSIX</a>
- documentation is available online.
+ This routine calls the network specific routine to remove the
+ next portion of data from the receive queue and return it to the
+ caller.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::recvfrom routine calls this routine to determine if any data
+ is received from the remote system. Note that the other routines
+ ::recv and ::read are layered on top of ::recvfrom.
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+
@param [in] Flags Message control flags
-
+
@param [in] BufferLength Length of the the buffer
-
+
@param [in] pBuffer Address of a buffer to receive the data.
-
+
@param [in] pDataLength Number of received data bytes in the buffer.
@param [out] pAddress Network address to receive the remote system address
@@ -419,53 +458,18 @@ EFI_STATUS
);
/**
- Send data using a network connection.
-
- The SocketTransmit routine queues the data for transmission to the
- remote network connection.
-
- @param [in] pSocketProtocol Address of the socket protocol structure.
-
- @param [in] Flags Message control flags
-
- @param [in] BufferLength Length of the the buffer
-
- @param [in] pBuffer Address of a buffer containing the data to send
-
- @param [in] pDataLength Address to receive the number of data bytes sent
-
- @param [in] pAddress Network address of the remote system address
-
- @param [in] AddressLength Length of the remote network address structure
-
- @param [out] pErrno Address to receive the errno value upon completion.
-
- @retval EFI_SUCCESS - Socket data successfully queued for transmission
-
- **/
-typedef
-EFI_STATUS
-(* PFN_SEND) (
- IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
- IN int Flags,
- IN size_t BufferLength,
- IN CONST UINT8 * pBuffer,
- OUT size_t * pDataLength,
- IN const struct sockaddr * pAddress,
- IN socklen_t AddressLength,
- IN int * pErrno
- );
-
-/**
Shutdown the socket receive and transmit operations
- The SocketShutdown routine stops the socket receive and transmit
- operations.
+ This routine sets a flag to stop future transmissions and calls
+ the network specific layer to cancel the pending receive operation.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::shutdown routine calls this routine to stop receive and transmit
+ operations on the socket.
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+
@param [in] How Which operations to stop
-
+
@param [out] pErrno Address to receive the errno value upon completion.
@retval EFI_SUCCESS - Socket operations successfully shutdown
@@ -482,40 +486,18 @@ EFI_STATUS
/**
Initialize an endpoint for network communication.
- The ::Socket routine initializes the communication endpoint by providing
- the support for the socket library function ::socket. The
- <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html">POSIX</a>
- documentation for the socket routine is available online for reference.
+ This routine initializes the communication endpoint.
- @param [in] pSocketProtocol Address of the socket protocol structure.
+ The ::socket routine calls this routine indirectly to create
+ the communication endpoint.
+ @param [in] pSocketProtocol Address of the socket protocol structure.
@param [in] domain Select the family of protocols for the client or server
- application.
-
- @param [in] type Specifies how to make the network connection. The following values
- are supported:
- <ul>
- <li>
- SOCK_STREAM - Connect to TCP, provides a byte stream
- that is manipluated by read, recv, send and write.
- </li>
- <li>
- SOCK_SEQPACKET - Connect to TCP, provides sequenced packet stream
- that is manipulated by read, recv, send and write.
- </li>
- <li>
- SOCK_DGRAM - Connect to UDP, provides a datagram service that is
- manipulated by recvfrom and sendto.
- </li>
- </ul>
-
- @param [in] protocol Specifies the lower layer protocol to use. The following
- values are supported:
- <ul>
- <li>IPPROTO_TCP</li> - This value must be combined with SOCK_STREAM.</li>
- <li>IPPROTO_UDP</li> - This value must be combined with SOCK_DGRAM.</li>
- </ul>
-
+ application. See the ::socket documentation for values.
+ @param [in] type Specifies how to make the network connection.
+ See the ::socket documentation for values.
+ @param [in] protocol Specifies the lower layer protocol to use.
+ See the ::socket documentation for values.
@param [out] pErrno Address to receive the errno value upon completion.
@retval EFI_SUCCESS - Socket successfully created
@@ -534,6 +516,50 @@ EFI_STATUS
IN int * pErrno
);
+/**
+ Send data using a network connection.
+
+ This routine calls the network specific layer to queue the data
+ for transmission. Eventually the buffer will reach the head of
+ the queue and will get transmitted over the network. For datagram
+ sockets there is no guarantee that the data reaches the application
+ running on the remote system.
+
+ The ::sendto routine calls this routine to send data to the remote
+ system. Note that ::send and ::write are layered on top of ::sendto.
+
+ @param [in] pSocketProtocol Address of the ::EFI_SOCKET_PROTOCOL structure.
+
+ @param [in] Flags Message control flags
+
+ @param [in] BufferLength Length of the the buffer
+
+ @param [in] pBuffer Address of a buffer containing the data to send
+
+ @param [in] pDataLength Address to receive the number of data bytes sent
+
+ @param [in] pAddress Network address of the remote system address
+
+ @param [in] AddressLength Length of the remote network address structure
+
+ @param [out] pErrno Address to receive the errno value upon completion.
+
+ @retval EFI_SUCCESS - Socket data successfully queued for transmit
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_TRANSMIT) (
+ IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
+ IN int Flags,
+ IN size_t BufferLength,
+ IN CONST UINT8 * pBuffer,
+ OUT size_t * pDataLength,
+ IN const struct sockaddr * pAddress,
+ IN socklen_t AddressLength,
+ IN int * pErrno
+ );
+
//------------------------------------------------------------------------------
// Socket Protocol
//------------------------------------------------------------------------------
@@ -551,13 +577,13 @@ typedef struct _EFI_SOCKET_PROTOCOL {
PFN_GET_LOCAL pfnGetLocal; ///< Get local address
PFN_GET_PEER pfnGetPeer; ///< Get peer address
PFN_LISTEN pfnListen; ///< Enable connection attempts on known port
- PFN_POLL pfnPoll; ///< Poll for socket activity
PFN_OPTION_GET pfnOptionGet; ///< Get socket options
PFN_OPTION_SET pfnOptionSet; ///< Set socket options
+ PFN_POLL pfnPoll; ///< Poll for socket activity
PFN_RECEIVE pfnReceive; ///< Receive data from a socket
- PFN_SEND pfnSend; ///< Transmit data using the socket
PFN_SHUTDOWN pfnShutdown; ///< Shutdown receive and transmit operations
PFN_SOCKET pfnSocket; ///< Initialize the socket
+ PFN_TRANSMIT pfnTransmit; ///< Transmit data using the socket
} GCC_EFI_SOCKET_PROTOCOL;
//------------------------------------------------------------------------------
diff --git a/StdLib/SocketDxe/EntryUnload.c b/StdLib/SocketDxe/EntryUnload.c
index ff59f8b..b8f77e3 100644
--- a/StdLib/SocketDxe/EntryUnload.c
+++ b/StdLib/SocketDxe/EntryUnload.c
@@ -15,14 +15,25 @@
#include "Socket.h"
+/**
+ Tag GUID - IPv4 in use by SocketDxe
+**/
CONST EFI_GUID mEslIp4ServiceGuid = {
0x4e3a82e6, 0xe43f, 0x460a, { 0x86, 0x6e, 0x9b, 0x5a, 0xab, 0x80, 0x44, 0x48 }
};
+
+/**
+ Tag GUID - TCPv4 in use by SocketDxe
+**/
CONST EFI_GUID mEslTcp4ServiceGuid = {
0x4dcaab0a, 0x1990, 0x4352, { 0x8d, 0x2f, 0x2d, 0x8f, 0x13, 0x55, 0x98, 0xa5 }
};
+
+/**
+ Tag GUID - UDPv4 in use by SocketDxe
+**/
CONST EFI_GUID mEslUdp4ServiceGuid = {
0x43a110ce, 0x9ccd, 0x402b, { 0x8c, 0x29, 0x4a, 0x6d, 0x8a, 0xf7, 0x79, 0x90 }
};
@@ -131,7 +142,7 @@ DriverUnload (
// Done with the socket layer
//
if ( !EFI_ERROR ( Status )) {
- Status = EslServiceUninstall ( ImageHandle );
+ Status = EslDxeUninstall ( ImageHandle );
if ( !EFI_ERROR ( Status )) {
//
// Remove the protocols installed by the EntryPoint routine.
@@ -250,7 +261,7 @@ EntryPoint (
// Make the socket serivces available to other drivers
// and applications
//
- Status = EslServiceInstall ( &ImageHandle );
+ Status = EslDxeInstall ( &ImageHandle );
if ( EFI_ERROR ( Status )) {
//
// Disconnect from the network
@@ -292,5 +303,14 @@ EntryPoint (
}
-PFN_ESL_xSTRUCTOR mpfnEslConstructor = NULL;
-PFN_ESL_xSTRUCTOR mpfnEslDestructor = NULL;
+/**
+ Socket layer's service binding protocol delcaration.
+**/
+CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding = {
+ EslDxeCreateChild,
+ EslDxeDestroyChild
+};
+
+
+PFN_ESL_xSTRUCTOR mpfnEslConstructor = NULL; ///< No EfiSocketLib constructor needed for SocketDxe
+PFN_ESL_xSTRUCTOR mpfnEslDestructor = NULL; ///< No EfiSocketLib destructor needed for SocketDxe
diff --git a/StdLib/UseSocketDxe/UseSocketDxe.c b/StdLib/UseSocketDxe/UseSocketDxe.c
index 0b7194c..d5cf213 100644
--- a/StdLib/UseSocketDxe/UseSocketDxe.c
+++ b/StdLib/UseSocketDxe/UseSocketDxe.c
@@ -23,12 +23,17 @@
/**
- Connect to the socket driver
+ Connect to the EFI socket library
+
+ This routine is called from the socket routine in BsdSocketLib
+ to create the data structure for a socket. This specific
+ implementation is used when an application links to UseSocketDxe
+ and redirects all requests to the SocketDxe driver.
@param [in] ppSocketProtocol Address to receive the socket protocol address
- @retval 0 Successfully returned the socket protocol
- @retval other Value for errno
+ @return Value for ::errno, zero (0) indicates success.
+
**/
int
EslServiceGetProtocol (