summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlpleahy <lpleahy@6f19259b-4bc3-4df7-8a09-765794883524>2011-09-13 22:53:32 +0000
committerlpleahy <lpleahy@6f19259b-4bc3-4df7-8a09-765794883524>2011-09-13 22:53:32 +0000
commit2481fa19834126489c9b627caa8f3bf137e57191 (patch)
tree0dc5bd74eef439538bb59f3bacef4ad02b28f365
parent4a75850903eb843cfa31f885e3b44fd62355613b (diff)
downloadedk2-2481fa19834126489c9b627caa8f3bf137e57191.zip
edk2-2481fa19834126489c9b627caa8f3bf137e57191.tar.gz
edk2-2481fa19834126489c9b627caa8f3bf137e57191.tar.bz2
Merge the PortAllocate code.
Signed-off by: Lee Leahy git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/branches/EADK@12342 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r--StdLib/EfiSocketLib/Ip4.c247
-rw-r--r--StdLib/EfiSocketLib/Socket.c266
-rw-r--r--StdLib/EfiSocketLib/Socket.h186
-rw-r--r--StdLib/EfiSocketLib/Tcp4.c220
-rw-r--r--StdLib/EfiSocketLib/Udp4.c204
5 files changed, 530 insertions, 593 deletions
diff --git a/StdLib/EfiSocketLib/Ip4.c b/StdLib/EfiSocketLib/Ip4.c
index 88c8df2..780127e 100644
--- a/StdLib/EfiSocketLib/Ip4.c
+++ b/StdLib/EfiSocketLib/Ip4.c
@@ -62,13 +62,16 @@ CONST ESL_PROTOCOL_API cEslIp4Api = {
NULL, // Listen
EslIp4OptionGet,
EslIp4OptionSet,
+ EslIp4PortAllocate,
EslIp4PortClose,
EslIp4PortClosePacketFree,
EslIp4PortCloseRxStop,
TRUE,
EslIp4Receive,
EslIp4RxCancel,
- EslIp4TxBuffer
+ EslIp4TxBuffer,
+ EslIp4TxComplete,
+ NULL // TxOobComplete
};
@@ -113,7 +116,6 @@ EslIp4Bind (
ESL_PORT * pPort;
ESL_SERVICE * pService;
EFI_STATUS Status;
- EFI_STATUS TempStatus;
DBG_ENTER ( );
@@ -157,38 +159,18 @@ EslIp4Bind (
//
// Open the port
//
- Status = EslIp4PortAllocate ( pSocket,
- pService,
- ChildHandle,
- (UINT8 *) &pIp4Address->sin_addr.s_addr,
- DEBUG_BIND,
- &pPort );
+ Status = EslSocketPortAllocate ( pSocket,
+ pService,
+ ChildHandle,
+ (UINT8 *) &pIp4Address->sin_addr.s_addr,
+ 0,
+ DEBUG_BIND,
+ &pPort );
}
else {
DEBUG (( DEBUG_BIND | DEBUG_POOL,
"ERROR - Failed to open Ip4 port handle, Status: %r\r\n",
Status ));
- ChildHandle = NULL;
- }
-
- //
- // Close the port if necessary
- //
- if (( EFI_ERROR ( Status )) && ( NULL != ChildHandle )) {
- TempStatus = pServiceBinding->DestroyChild ( pServiceBinding,
- ChildHandle );
- if ( !EFI_ERROR ( TempStatus )) {
- DEBUG (( DEBUG_BIND | DEBUG_POOL,
- "0x%08x: Ip4 port handle destroyed\r\n",
- ChildHandle ));
- }
- else {
- DEBUG (( DEBUG_ERROR | DEBUG_BIND | DEBUG_POOL,
- "ERROR - Failed to destroy the Ip4 port handle 0x%08x, Status: %r\r\n",
- ChildHandle,
- TempStatus ));
- ASSERT ( EFI_SUCCESS == TempStatus );
- }
}
//
@@ -733,45 +715,35 @@ EslIp4OptionSet (
}
-
/**
- Allocate and initialize an ::ESL_PORT structure.
+ Initialize the network specific portions of an ::ESL_PORT structure.
- This routine initializes an ::ESL_PORT structure for use by the
- socket.
+ This routine initializes the network specific portions of an
+ ::ESL_PORT structure for use by the socket.
- This support routine is called by ::EslIp4Bind to connect the
- socket with the underlying network adapter running the IPv4
- protocol.
+ This support routine is called by ::EslSocketPortAllocate
+ to connect the socket with the underlying network adapter
+ running the IPv4 protocol.
- @param [in] pSocket Address of an ::ESL_SOCKET structure.
- @param [in] pService Address of an ::ESL_SERVICE structure.
- @param [in] ChildHandle Ip4 child handle
+ @param [in] ppPort Address of an ESL_PORT structure
@param [in] pIpAddress Buffer containing IP4 network address of the local host
+ @param [in] PortNumber Port number - not used
@param [in] DebugFlags Flags for debug messages
- @param [out] ppPort Buffer to receive new ESL_PORT structure address
@retval EFI_SUCCESS - Socket successfully created
**/
EFI_STATUS
EslIp4PortAllocate (
- IN ESL_SOCKET * pSocket,
- IN ESL_SERVICE * pService,
- IN EFI_HANDLE ChildHandle,
+ IN ESL_PORT * pPort,
IN CONST UINT8 * pIpAddress,
- IN UINTN DebugFlags,
- OUT ESL_PORT ** ppPort
+ IN UINT16 PortNumber,
+ IN UINTN DebugFlags
)
{
- UINTN LengthInBytes;
- UINT8 * pBuffer;
EFI_IP4_CONFIG_DATA * pConfig;
- ESL_IO_MGMT * pIo;
ESL_IP4_CONTEXT * pIp4;
- ESL_LAYER * pLayer;
- ESL_PORT * pPort;
- CONST ESL_SOCKET_BINDING * pSocketBinding;
+ ESL_SOCKET * pSocket;
EFI_STATUS Status;
DBG_ENTER ( );
@@ -780,48 +752,9 @@ EslIp4PortAllocate (
// Use for/break instead of goto
for ( ; ; ) {
//
- // Allocate a port structure
- //
- pLayer = &mEslLayer;
- LengthInBytes = sizeof ( *pPort )
- + ESL_STRUCTURE_ALIGNMENT_BYTES
- + ( pService->pSocketBinding->TxIoNormal
- * sizeof ( ESL_IO_MGMT ));
- Status = gBS->AllocatePool ( EfiRuntimeServicesData,
- LengthInBytes,
- (VOID **)&pPort );
- if ( EFI_ERROR ( Status )) {
- DEBUG (( DEBUG_ERROR | DebugFlags | DEBUG_POOL | DEBUG_INIT,
- "ERROR - Failed to allocate the port structure, Status: %r\r\n",
- Status ));
- pSocket->errno = ENOMEM;
- pPort = NULL;
- break;
- }
- DEBUG (( DebugFlags | DEBUG_POOL | DEBUG_INIT,
- "0x%08x: Allocate pPort, %d bytes\r\n",
- pPort,
- LengthInBytes ));
-
- //
- // Initialize the port
- //
- ZeroMem ( pPort, LengthInBytes );
- pPort->Signature = PORT_SIGNATURE;
- pPort->pService = pService;
- pPort->pSocket = pSocket;
- pPort->DebugFlags = DebugFlags;
- pSocket->TxPacketOffset = OFFSET_OF ( ESL_PACKET, Op.Ip4Tx.TxData );
- pSocket->TxTokenEventOffset = OFFSET_OF ( ESL_IO_MGMT, Token.Ip4Tx.Event );
- pSocket->TxTokenOffset = OFFSET_OF ( EFI_IP4_COMPLETION_TOKEN, Packet.TxData );
- pBuffer = (UINT8 *)&pPort[ 1 ];
- pBuffer = &pBuffer[ ESL_STRUCTURE_ALIGNMENT_BYTES ];
- pBuffer = (UINT8 *)( ESL_STRUCTURE_ALIGNMENT_MASK & (UINTN)pBuffer );
- pIo = (ESL_IO_MGMT *)pBuffer;
-
- //
// Allocate the receive event
//
+ pSocket = pPort->pSocket;
pIp4 = &pPort->Context.Ip4;
Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL,
TPL_SOCKETS,
@@ -840,42 +773,11 @@ EslIp4PortAllocate (
pIp4->RxToken.Event ));
//
- // Allocate the transmit events
- //
- Status = EslSocketIoInit ( pPort,
- &pIo,
- pService->pSocketBinding->TxIoNormal,
- &pPort->pTxFree,
- DebugFlags | DEBUG_POOL,
- "transmit",
- OFFSET_OF ( ESL_IO_MGMT, Token.Ip4Tx.Event ),
- EslIp4TxComplete );
- if ( EFI_ERROR ( Status )) {
- break;
- }
-
- //
- // Open the port protocol
+ // Initialize the port
//
- pSocketBinding = pService->pSocketBinding;
- Status = gBS->OpenProtocol (
- ChildHandle,
- pSocketBinding->pNetworkProtocolGuid,
- &pPort->pProtocol.v,
- pLayer->ImageHandle,
- NULL,
- EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL );
- if ( EFI_ERROR ( Status )) {
- DEBUG (( DEBUG_ERROR | DebugFlags,
- "ERROR - Failed to open gEfiIp4ProtocolGuid on controller 0x%08x\r\n",
- pPort->Handle ));
- pSocket->errno = EEXIST;
- break;
- }
- DEBUG (( DebugFlags,
- "0x%08x: gEfiIp4ProtocolGuid opened on controller 0x%08x\r\n",
- pPort->pProtocol.v,
- ChildHandle ));
+ pSocket->TxPacketOffset = OFFSET_OF ( ESL_PACKET, Op.Ip4Tx.TxData );
+ pSocket->TxTokenEventOffset = OFFSET_OF ( ESL_IO_MGMT, Token.Ip4Tx.Event );
+ pSocket->TxTokenOffset = OFFSET_OF ( EFI_IP4_COMPLETION_TOKEN, Packet.TxData );
//
// Save the transmit address
@@ -885,7 +787,6 @@ EslIp4PortAllocate (
//
// Set the port address
//
- pPort->Handle = ChildHandle;
pConfig = &pPort->Context.Ip4.ModeData.ConfigData;
pConfig->DefaultProtocol = (UINT8)pSocket->Protocol;
if (( 0 == pIpAddress[0])
@@ -898,6 +799,7 @@ EslIp4PortAllocate (
pPort ));
}
else {
+ pConfig->UseDefaultAddress = FALSE;
pConfig->StationAddress.Addr[0] = pIpAddress[0];
pConfig->StationAddress.Addr[1] = pIpAddress[1];
pConfig->StationAddress.Addr[2] = pIpAddress[2];
@@ -924,45 +826,10 @@ EslIp4PortAllocate (
pConfig->RawData = FALSE;
pConfig->ReceiveTimeout = 0;
pConfig->TransmitTimeout = 0;
-
- //
- // Verify the socket layer synchronization
- //
- VERIFY_TPL ( TPL_SOCKETS );
-
- //
- // Add this port to the socket
- //
- pPort->pLinkSocket = pSocket->pPortList;
- pSocket->pPortList = pPort;
- DEBUG (( DebugFlags,
- "0x%08x: Socket adding port: 0x%08x\r\n",
- pSocket,
- pPort ));
-
- //
- // Add this port to the service
- //
- pPort->pLinkService = pService->pPortList;
- pService->pPortList = pPort;
-
- //
- // Return the port
- //
- *ppPort = pPort;
break;
}
//
- // Clean up after the error if necessary
- //
- if (( EFI_ERROR ( Status )) && ( NULL != pPort )) {
- //
- // Close the port
- //
- EslSocketPortClose ( pPort );
- }
- //
// Return the operation status
//
DBG_EXIT_STATUS ( Status );
@@ -1852,6 +1719,7 @@ EslIp4Shutdown (
IN ESL_SOCKET * pSocket
)
{
+ UINTN Index;
ESL_PORT * pPort;
ESL_PORT * pNextPort;
ESL_IP4_CONTEXT * pIp4;
@@ -1958,9 +1826,46 @@ EslIp4Shutdown (
}
}
else {
- DEBUG (( DEBUG_LISTEN,
- "0x%08x: Port configured\r\n",
- pPort ));
+ DEBUG (( DEBUG_TX,
+ "0x%08x: pPort Configured for %d.%d.%d.%d --> %d.%d.%d.%d\r\n",
+ pPort,
+ pIp4->ModeData.ConfigData.StationAddress.Addr[0],
+ pIp4->ModeData.ConfigData.StationAddress.Addr[1],
+ pIp4->ModeData.ConfigData.StationAddress.Addr[2],
+ pIp4->ModeData.ConfigData.StationAddress.Addr[3],
+ pIp4->DestinationAddress.Addr[0],
+ pIp4->DestinationAddress.Addr[1],
+ pIp4->DestinationAddress.Addr[2],
+ pIp4->DestinationAddress.Addr[3]));
+ DEBUG (( DEBUG_TX,
+ "Subnet Mask: %d.%d.%d.%d\r\n",
+ pIp4->ModeData.ConfigData.SubnetMask.Addr[0],
+ pIp4->ModeData.ConfigData.SubnetMask.Addr[1],
+ pIp4->ModeData.ConfigData.SubnetMask.Addr[2],
+ pIp4->ModeData.ConfigData.SubnetMask.Addr[3]));
+ DEBUG (( DEBUG_TX,
+ "Route Count: %d\r\n",
+ pIp4->ModeData.RouteCount ));
+ for ( Index = 0; pIp4->ModeData.RouteCount > Index; Index++ ) {
+ if ( 0 == Index ) {
+ DEBUG (( DEBUG_TX, "Route Table:\r\n" ));
+ }
+ DEBUG (( DEBUG_TX,
+ "%5d: %d.%d.%d.%d, %d.%d.%d.%d ==> %d.%d.%d.%d\r\n",
+ Index,
+ pIp4->ModeData.RouteTable[Index].SubnetAddress.Addr[0],
+ pIp4->ModeData.RouteTable[Index].SubnetAddress.Addr[1],
+ pIp4->ModeData.RouteTable[Index].SubnetAddress.Addr[2],
+ pIp4->ModeData.RouteTable[Index].SubnetAddress.Addr[3],
+ pIp4->ModeData.RouteTable[Index].SubnetMask.Addr[0],
+ pIp4->ModeData.RouteTable[Index].SubnetMask.Addr[1],
+ pIp4->ModeData.RouteTable[Index].SubnetMask.Addr[2],
+ pIp4->ModeData.RouteTable[Index].SubnetMask.Addr[3],
+ pIp4->ModeData.RouteTable[Index].GatewayAddress.Addr[0],
+ pIp4->ModeData.RouteTable[Index].GatewayAddress.Addr[1],
+ pIp4->ModeData.RouteTable[Index].GatewayAddress.Addr[2],
+ pIp4->ModeData.RouteTable[Index].GatewayAddress.Addr[3]));
+ }
pPort->bConfigured = TRUE;
//
@@ -2163,9 +2068,17 @@ EslIp4TxBuffer (
// Display the request
//
DEBUG (( DEBUG_TX,
- "Send %d %s bytes from 0x%08x\r\n",
+ "Send %d bytes from 0x%08x, %d.%d.%d.%d --> %d.%d.%d.%d\r\n",
BufferLength,
- pBuffer ));
+ pBuffer,
+ pIp4->ModeData.ConfigData.StationAddress.Addr[0],
+ pIp4->ModeData.ConfigData.StationAddress.Addr[1],
+ pIp4->ModeData.ConfigData.StationAddress.Addr[2],
+ pIp4->ModeData.ConfigData.StationAddress.Addr[3],
+ pTxData->TxData.DestinationAddress.Addr[0],
+ pTxData->TxData.DestinationAddress.Addr[1],
+ pTxData->TxData.DestinationAddress.Addr[2],
+ pTxData->TxData.DestinationAddress.Addr[3]));
//
// Queue the data for transmission
diff --git a/StdLib/EfiSocketLib/Socket.c b/StdLib/EfiSocketLib/Socket.c
index 012fb6c..2c367fc 100644
--- a/StdLib/EfiSocketLib/Socket.c
+++ b/StdLib/EfiSocketLib/Socket.c
@@ -40,9 +40,9 @@
<li>Arc: ::EslSocketPortCloseComplete - Called by the TCP layer
when the port is closed.
<li>State: PORT_STATE_CLOSE_DONE</li>
- <li>Arc: ::EslSocketPortClose - Releases the port resources. Calls
- a routine via ESL_PROTOCOL_API::pfnPortClose to close the network
- specific resources:
+ <li>Arc: ::EslSocketPortClose - Releases the port resources allocated
+ by ::EslSocketPortAllocate. Calls ESL_PROTOCOL_API::pfnPortClose to
+ close the network specific resources:
<ul>
<li>::EslIp4PortClose</li>
<li>::EslTcp4PortClose</li>
@@ -56,14 +56,13 @@
\section TransmitEngine Transmit Engine
The transmit engine uses the ESL_IO_MGMT structures to manage
- multiple transmit buffers. The network specific PortAllocate
- routine allocate the ::ESL_IO_MGMT structures and place them
- on the free list by calling ::EslSocketIoInit. During their
- lifetime, the ESL_IO_MGMT structures will move from the free
- list to the active list and back again. The active list contains
- the packets that are actively being processed by the network
- stack. Eventually the ESL_IO_MGMT structures will be removed
- from the free list and be deallocated by the network specific
+ multiple transmit buffers. ::EslSocketPortAllocate allocates the
+ ::ESL_IO_MGMT structures and place them on the free list by calling
+ ::EslSocketIoInit. During their lifetime, the ESL_IO_MGMT structures
+ will move from the free list to the active list and back again. The
+ active list contains the packets that are actively being processed by
+ the network stack. Eventually the ESL_IO_MGMT structures will be
+ removed from the free list and be deallocated by the network specific
PortClose routines.
The network specific code calls the ::EslSocketTxStart routine
@@ -1552,7 +1551,7 @@ EslSocketIoFree (
This support routine initializes the ESL_IO_MGMT structure and
places them on to a free list.
- This routine is called by the PortAllocate routines to prepare
+ This routine is called by ::EslSocketPortAllocate routines to prepare
the transmit engines. See the \ref TransmitEngine section.
@param [in] pPort Address of an ::ESL_PORT structure
@@ -1562,7 +1561,6 @@ EslSocketIoFree (
@param [in] ppFreeQueue Address of the free queue head
@param [in] DebugFlags Flags for debug messages
@param [in] pEventName Zero terminated string containing the event name
- @param [in] EventOffset Offset of the event in the ::ESL_IO_MGMT structure
@param [in] pfnCompletion Completion routine address
@retval EFI_SUCCESS - The structures were properly initialized
@@ -1576,7 +1574,6 @@ EslSocketIoInit (
IN ESL_IO_MGMT ** ppFreeQueue,
IN UINTN DebugFlags,
IN CHAR8 * pEventName,
- IN UINTN EventOffset,
IN EFI_EVENT_NOTIFY pfnCompletion
)
{
@@ -1609,7 +1606,7 @@ EslSocketIoInit (
//
// Allocate the event for this structure
//
- pEvent = (EFI_EVENT *)&(((UINT8 *)pIo)[ EventOffset ]);
+ pEvent = (EFI_EVENT *)&(((UINT8 *)pIo)[ pSocket->TxTokenEventOffset ]);
Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL,
TPL_SOCKETS,
(EFI_EVENT_NOTIFY)pfnCompletion,
@@ -2537,18 +2534,247 @@ EslSocketPoll (
/**
+ Allocate and initialize a ESL_PORT structure.
+
+ This routine initializes an ::ESL_PORT structure for use by
+ the socket. This routine calls a routine via
+ ESL_PROTOCOL_API::pfnPortAllocate to initialize the network
+ specific resources. The resources are released later by the
+ \ref PortCloseStateMachine.
+
+ This support routine is called by:
+ <ul>
+ <li>::EslIp4Bind</li>
+ <li>::EslTcp4Bind</li>
+ <li>::EslTcp4ListenComplete</li>
+ <li>::EslUdp4Bind::</li>
+ to connect the socket with the underlying network adapter
+ to the socket.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure.
+ @param [in] pService Address of an ::ESL_SERVICE structure.
+ @param [in] ChildHandle TCP4 child handle
+ @param [in] pIpAddress Buffer containing IP4 network address of the local host
+ @param [in] PortNumber Tcp4 port number
+ @param [in] DebugFlags Flags for debug messages
+ @param [out] ppPort Buffer to receive new ::ESL_PORT structure address
+
+ @retval EFI_SUCCESS - Socket successfully created
+
+ **/
+EFI_STATUS
+EslSocketPortAllocate (
+ IN ESL_SOCKET * pSocket,
+ IN ESL_SERVICE * pService,
+ IN EFI_HANDLE ChildHandle,
+ IN CONST UINT8 * pIpAddress,
+ IN UINT16 PortNumber,
+ IN UINTN DebugFlags,
+ OUT ESL_PORT ** ppPort
+ )
+{
+ UINTN LengthInBytes;
+ UINT8 * pBuffer;
+ ESL_IO_MGMT * pIo;
+ ESL_LAYER * pLayer;
+ ESL_PORT * pPort;
+ EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding;
+ CONST ESL_SOCKET_BINDING * pSocketBinding;
+ EFI_STATUS Status;
+ EFI_STATUS TempStatus;
+
+ DBG_ENTER ( );
+
+ //
+ // Verify the socket layer synchronization
+ //
+ VERIFY_TPL ( TPL_SOCKETS );
+
+ //
+ // Use for/break instead of goto
+ pSocketBinding = pService->pSocketBinding;
+ for ( ; ; ) {
+ //
+ // Allocate a port structure
+ //
+ pLayer = &mEslLayer;
+ LengthInBytes = sizeof ( *pPort )
+ + ESL_STRUCTURE_ALIGNMENT_BYTES
+ + (( pSocketBinding->TxIoNormal
+ + pSocketBinding->TxIoUrgent )
+ * sizeof ( ESL_IO_MGMT ));
+ Status = gBS->AllocatePool ( EfiRuntimeServicesData,
+ LengthInBytes,
+ (VOID **)&pPort );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR | DebugFlags | DEBUG_POOL | DEBUG_INIT,
+ "ERROR - Failed to allocate the port structure, Status: %r\r\n",
+ Status ));
+ pSocket->errno = ENOMEM;
+ pPort = NULL;
+ break;
+ }
+ DEBUG (( DebugFlags | DEBUG_POOL | DEBUG_INIT,
+ "0x%08x: Allocate pPort, %d bytes\r\n",
+ pPort,
+ LengthInBytes ));
+
+ //
+ // Initialize the port
+ //
+ ZeroMem ( pPort, LengthInBytes );
+ pPort->DebugFlags = DebugFlags;
+ pPort->Handle = ChildHandle;
+ pPort->pService = pService;
+ pPort->pSocket = pSocket;
+ pPort->Signature = PORT_SIGNATURE;
+
+ //
+ // Open the port protocol
+ //
+ Status = gBS->OpenProtocol ( pPort->Handle,
+ pSocketBinding->pNetworkProtocolGuid,
+ &pPort->pProtocol.v,
+ pLayer->ImageHandle,
+ NULL,
+ EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL );
+ if ( EFI_ERROR ( Status )) {
+ DEBUG (( DEBUG_ERROR | DebugFlags,
+ "ERROR - Failed to open network protocol GUID on controller 0x%08x\r\n",
+ pPort->Handle ));
+ pSocket->errno = EEXIST;
+ break;
+ }
+ DEBUG (( DebugFlags,
+ "0x%08x: Network protocol GUID opened on controller 0x%08x\r\n",
+ pPort->pProtocol.v,
+ pPort->Handle ));
+
+ //
+ // Initialize the port specific resources
+ //
+ Status = pSocket->pApi->pfnPortAllocate ( pPort,
+ pIpAddress,
+ PortNumber,
+ DebugFlags );
+ if ( EFI_ERROR ( Status )) {
+ break;
+ }
+
+ //
+ // Initialize the urgent transmit structures
+ //
+ pBuffer = (UINT8 *)&pPort[ 1 ];
+ pBuffer = &pBuffer[ ESL_STRUCTURE_ALIGNMENT_BYTES ];
+ pBuffer = (UINT8 *)( ESL_STRUCTURE_ALIGNMENT_MASK & (UINTN)pBuffer );
+ pIo = (ESL_IO_MGMT *)pBuffer;
+ if (( 0 != pSocketBinding->TxIoUrgent )
+ && ( NULL != pSocket->pApi->pfnTxOobComplete )) {
+ Status = EslSocketIoInit ( pPort,
+ &pIo,
+ pSocketBinding->TxIoUrgent,
+ &pPort->pTxOobFree,
+ DebugFlags | DEBUG_POOL,
+ "urgent transmit",
+ pSocket->pApi->pfnTxOobComplete );
+ if ( EFI_ERROR ( Status )) {
+ break;
+ }
+ }
+
+ //
+ // Initialize the normal transmit structures
+ //
+ if (( 0 != pSocketBinding->TxIoNormal )
+ && ( NULL != pSocket->pApi->pfnTxComplete )) {
+ Status = EslSocketIoInit ( pPort,
+ &pIo,
+ pSocketBinding->TxIoNormal,
+ &pPort->pTxFree,
+ DebugFlags | DEBUG_POOL,
+ "normal transmit",
+ pSocket->pApi->pfnTxComplete );
+ if ( EFI_ERROR ( Status )) {
+ break;
+ }
+ }
+
+ //
+ // Add this port to the socket
+ //
+ pPort->pLinkSocket = pSocket->pPortList;
+ pSocket->pPortList = pPort;
+ DEBUG (( DebugFlags,
+ "0x%08x: Socket adding port: 0x%08x\r\n",
+ pSocket,
+ pPort ));
+
+ //
+ // Add this port to the service
+ //
+ pPort->pLinkService = pService->pPortList;
+ pService->pPortList = pPort;
+
+ //
+ // Return the port
+ //
+ *ppPort = pPort;
+ break;
+ }
+
+ //
+ // Clean up after the error if necessary
+ //
+ if ( EFI_ERROR ( Status )) {
+ if ( NULL != pPort ) {
+ //
+ // Close the port
+ //
+ EslSocketPortClose ( pPort );
+ }
+ else {
+ //
+ // Close the port if necessary
+ //
+ pServiceBinding = pService->pServiceBinding;
+ TempStatus = pServiceBinding->DestroyChild ( pServiceBinding,
+ ChildHandle );
+ if ( !EFI_ERROR ( TempStatus )) {
+ DEBUG (( DEBUG_BIND | DEBUG_POOL,
+ "0x%08x: %s port handle destroyed\r\n",
+ ChildHandle,
+ pSocketBinding->pName ));
+ }
+ else {
+ DEBUG (( DEBUG_ERROR | DEBUG_BIND | DEBUG_POOL,
+ "ERROR - Failed to destroy the %s port handle 0x%08x, Status: %r\r\n",
+ pSocketBinding->pName,
+ ChildHandle,
+ TempStatus ));
+ ASSERT ( EFI_SUCCESS == TempStatus );
+ }
+ }
+ }
+ //
+ // Return the operation status
+ //
+ DBG_EXIT_STATUS ( Status );
+ return Status;
+}
+
+
+/**
Close a port.
- This routine releases the resources allocated by the network specific
- PortAllocate routine.
+ This routine releases the resources allocated by ::EslSocketPortAllocate.
+ This routine calls ESL_PROTOCOL_API::pfnPortClose to release the network
+ specific resources.
This routine is called by:
<ul>
- <li>::EslIp4PortAllocate - Port initialization failure</li>
+ <li>::EslSocketPortAllocate - Port initialization failure</li>
<li>::EslSocketPortCloseRxDone - Last step of close processing</li>
<li>::EslTcp4ConnectComplete - Connection failure and reducint the port list to a single port</li>
- <li>::EslTcp4PortAllocate - Port initialization failure</li>
- <li>::EslUdp4PortAllocate - Port initialization failure</li>
</ul>
See the \ref PortCloseStateMachine section.
diff --git a/StdLib/EfiSocketLib/Socket.h b/StdLib/EfiSocketLib/Socket.h
index fd7066a..5a99370 100644
--- a/StdLib/EfiSocketLib/Socket.h
+++ b/StdLib/EfiSocketLib/Socket.h
@@ -231,7 +231,7 @@ typedef struct {
//
// Receive data management
//
- EFI_IP4_COMPLETION_TOKEN RxToken; ///< Receive token
+ EFI_IP4_COMPLETION_TOKEN RxToken; ///< Receive token
} ESL_IP4_CONTEXT;
@@ -244,20 +244,20 @@ typedef struct {
//
// TCP4 context
//
- EFI_TCP4_CONFIG_DATA ConfigData; ///< TCP4 configuration data
- EFI_TCP4_OPTION Option; ///< TCP4 port options
+ EFI_TCP4_CONFIG_DATA ConfigData; ///< TCP4 configuration data
+ EFI_TCP4_OPTION Option; ///< TCP4 port options
//
// Tokens
//
- EFI_TCP4_LISTEN_TOKEN ListenToken; ///< Listen control
+ EFI_TCP4_LISTEN_TOKEN ListenToken; ///< Listen control
EFI_TCP4_CONNECTION_TOKEN ConnectToken; ///< Connection control
- EFI_TCP4_CLOSE_TOKEN CloseToken; ///< Close control
+ EFI_TCP4_CLOSE_TOKEN CloseToken; ///< Close control
//
// Receive data management
//
- EFI_TCP4_IO_TOKEN RxToken; ///< Receive token
+ EFI_TCP4_IO_TOKEN RxToken; ///< Receive token
} ESL_TCP4_CONTEXT;
/**
@@ -567,6 +567,33 @@ EFI_STATUS
);
/**
+ Initialize the network specific portions of an ::ESL_PORT structure.
+
+ This routine initializes the network specific portions of an
+ ::ESL_PORT structure for use by the socket.
+
+ This support routine is called by ::EslSocketPortAllocate
+ to connect the socket with the underlying network adapter
+ running the IPv4 protocol.
+
+ @param [in] ppPort Address of an ESL_PORT structure
+ @param [in] pIpAddress Buffer containing IP4 network address of the local host
+ @param [in] PortNumber Tcp4 port number
+ @param [in] DebugFlags Flags for debug messages
+
+ @retval EFI_SUCCESS - Socket successfully created
+
+ **/
+typedef
+EFI_STATUS
+(* PFN_API_PORT_ALLOC) (
+ IN ESL_PORT * pPort,
+ IN CONST UINT8 * pIpAddress,
+ IN UINT16 PortNumber,
+ IN UINTN DebugFlags
+ );
+
+/**
Close a network specific port.
This routine releases the resources allocated by the
@@ -710,6 +737,27 @@ EFI_STATUS
);
/**
+ Process the transmit completion
+
+ This routine calls ::EslSocketTxComplete to handle the
+ transmit completion.
+
+ This routine is called by the network layers upon the completion
+ of a transmit operation.
+
+ @param [in] Event The urgent transmit completion event
+
+ @param [in] pIo The ESL_IO_MGMT structure address
+
+**/
+typedef
+VOID
+(* PFN_API_TX_COMPLETE) (
+ IN EFI_EVENT Event,
+ IN ESL_IO_MGMT * pIo
+ );
+
+/**
Socket type control structure
This driver uses this structure to define the API for the socket type.
@@ -726,13 +774,16 @@ typedef struct {
PFN_API_LISTEN pfnListen; ///< Listen for connections on known server port
PFN_API_OPTION_GET pfnOptionGet; ///< Get the option value
PFN_API_OPTION_SET pfnOptionSet; ///< Set the option value
- PFN_API_PORT_CLOSE pfnPortClose; ///< Close the port
+ PFN_API_PORT_ALLOC pfnPortAllocate; ///< Allocate the network specific resources for the port
+ PFN_API_PORT_CLOSE pfnPortClose; ///< Close the network specific resources for the port
PFN_API_PORT_CLOSE_PF pfnPortClosePktFree;///< Free the receive packet
PFN_API_PORT_CLOSE_OP pfnPortCloseRxStop; ///< Perform the close operation on the port
BOOLEAN bPortCloseComplete; ///< TRUE = Close is complete after close operation
PFN_API_RECEIVE pfnReceive; ///< Attempt to receive some data
PFN_API_RX_CANCEL pfnRxCancel; ///< Cancel a receive operation
PFN_API_TRANSMIT pfnTransmit; ///< Attempt to buffer a packet for transmit
+ PFN_API_TX_COMPLETE pfnTxComplete; ///< TX completion for normal data
+ PFN_API_TX_COMPLETE pfnTxOobComplete; ///< TX completion for urgent data
} ESL_PROTOCOL_API;
@@ -947,7 +998,6 @@ EslSocketIoFree (
@param [in] ppFreeQueue Address of the free queue head
@param [in] DebugFlags Flags for debug messages
@param [in] pEventName Zero terminated string containing the event name
- @param [in] EventOffset Offset of the event in the ::ESL_IO_MGMT structure
@param [in] pfnCompletion Completion routine address
@retval EFI_SUCCESS - The structures were properly initialized
@@ -961,7 +1011,6 @@ EslSocketIoInit (
IN ESL_IO_MGMT ** ppFreeQueue,
IN UINTN DebugFlags,
IN CHAR8 * pEventName,
- IN UINTN EventOffset,
IN EFI_EVENT_NOTIFY pfnCompletion
);
@@ -1031,10 +1080,51 @@ EslSocketPacketFree (
);
/**
+ Allocate and initialize a ESL_PORT structure.
+
+ This routine initializes an ::ESL_PORT structure for use by
+ the socket. This routine calls a routine via
+ ESL_PROTOCOL_API::pfnPortAllocate to initialize the network
+ specific resources. The resources are released later by the
+ \ref PortCloseStateMachine.
+
+ This support routine is called by:
+ <ul>
+ <li>::EslIp4Bind</li>
+ <li>::EslTcp4Bind</li>
+ <li>::EslTcp4ListenComplete</li>
+ <li>::EslUdp4Bind::</li>
+ to connect the socket with the underlying network adapter
+ to the socket.
+
+ @param [in] pSocket Address of an ::ESL_SOCKET structure.
+ @param [in] pService Address of an ::ESL_SERVICE structure.
+ @param [in] ChildHandle TCP4 child handle
+ @param [in] pIpAddress Buffer containing IP4 network address of the local host
+ @param [in] PortNumber Tcp4 port number
+ @param [in] DebugFlags Flags for debug messages
+ @param [out] ppPort Buffer to receive new ::ESL_PORT structure address
+
+ @retval EFI_SUCCESS - Socket successfully created
+
+ **/
+EFI_STATUS
+EslSocketPortAllocate (
+ IN ESL_SOCKET * pSocket,
+ IN ESL_SERVICE * pService,
+ IN EFI_HANDLE ChildHandle,
+ IN CONST UINT8 * pIpAddress,
+ IN UINT16 PortNumber,
+ IN UINTN DebugFlags,
+ OUT ESL_PORT ** ppPort
+ );
+
+/**
Close a port.
- This routine releases the resources allocated by the network specific
- PortAllocate routine.
+ This routine releases the resources allocated by ::EslSocketPortAllocate.
+ This routine calls ESL_PROTOCOL_API::pfnPortClose to release the network
+ specific resources.
This routine is called by:
<ul>
@@ -1414,33 +1504,29 @@ EslIp4OptionSet (
);
/**
- Allocate and initialize an ::ESL_PORT structure.
+ Initialize the network specific portions of an ::ESL_PORT structure.
- This routine initializes an ::ESL_PORT structure for use by the
- socket.
+ This routine initializes the network specific portions of an
+ ::ESL_PORT structure for use by the socket.
- This support routine is called by ::EslIp4Bind to connect the
- socket with the underlying network adapter running the IPv4
- protocol.
+ This support routine is called by ::EslSocketPortAllocate
+ to connect the socket with the underlying network adapter
+ running the IPv4 protocol.
- @param [in] pSocket Address of an ::ESL_SOCKET structure.
- @param [in] pService Address of an ::ESL_SERVICE structure.
- @param [in] ChildHandle Ip4 child handle
+ @param [in] ppPort Address of an ESL_PORT structure
@param [in] pIpAddress Buffer containing IP4 network address of the local host
+ @param [in] PortNumber Port number - not used
@param [in] DebugFlags Flags for debug messages
- @param [out] ppPort Buffer to receive new ESL_PORT structure address
@retval EFI_SUCCESS - Socket successfully created
**/
EFI_STATUS
EslIp4PortAllocate (
- IN ESL_SOCKET * pSocket,
- IN ESL_SERVICE * pService,
- IN EFI_HANDLE ChildHandle,
+ IN ESL_PORT * pPort,
IN CONST UINT8 * pIpAddress,
- IN UINTN DebugFlags,
- OUT ESL_PORT ** ppPort
+ IN UINT16 PortNumber,
+ IN UINTN DebugFlags
);
/**
@@ -1954,35 +2040,29 @@ EslTcp4ListenComplete (
);
/**
- Allocate and initialize a ESL_PORT structure.
+ Initialize the network specific portions of an ::ESL_PORT structure.
- This routine initializes an ::ESL_PORT structure for use by the
- socket.
+ This routine initializes the network specific portions of an
+ ::ESL_PORT structure for use by the socket.
- This support routine is called by ::EslTcp4Bind and
- ::EslTcp4ListenComplete to connect the socket with the underlying
- network adapter running the TCPv4 protocol.
+ This support routine is called by ::EslSocketPortAllocate
+ to connect the socket with the underlying network adapter
+ running the TCPv4 protocol.
- @param [in] pSocket Address of an ::ESL_SOCKET structure.
- @param [in] pService Address of an ::ESL_SERVICE structure.
- @param [in] ChildHandle TCP4 child handle
+ @param [in] ppPort Address of an ESL_PORT structure
@param [in] pIpAddress Buffer containing IP4 network address of the local host
@param [in] PortNumber Tcp4 port number
@param [in] DebugFlags Flags for debug messages
- @param [out] ppPort Buffer to receive new ESL_PORT structure address
@retval EFI_SUCCESS - Socket successfully created
**/
EFI_STATUS
EslTcp4PortAllocate (
- IN ESL_SOCKET * pSocket,
- IN ESL_SERVICE * pService,
- IN EFI_HANDLE ChildHandle,
+ IN ESL_PORT * pPort,
IN CONST UINT8 * pIpAddress,
IN UINT16 PortNumber,
- IN UINTN DebugFlags,
- OUT ESL_PORT ** ppPort
+ IN UINTN DebugFlags
);
/**
@@ -2423,35 +2503,29 @@ EslUdp4Initialize (
);
/**
- Allocate and initialize an ::ESL_PORT structure.
+ Initialize the network specific portions of an ::ESL_PORT structure.
- This routine initializes an ::ESL_PORT structure for use by the
- socket.
+ This routine initializes the network specific portions of an
+ ::ESL_PORT structure for use by the socket.
- This support routine is called by ::EslUdp4Bind to connect the
- socket with the underlying network adapter running the UDPv4
- protocol.
+ This support routine is called by ::EslSocketPortAllocate
+ to connect the socket with the underlying network adapter
+ running the UDPv4 protocol.
- @param [in] pSocket Address of an ::ESL_SOCKET structure.
- @param [in] pService Address of an ::ESL_SERVICE structure.
- @param [in] ChildHandle Udp4 child handle
+ @param [in] ppPort Address of an ESL_PORT structure
@param [in] pIpAddress Buffer containing IP4 network address of the local host
@param [in] PortNumber Udp4 port number
@param [in] DebugFlags Flags for debug messages
- @param [out] ppPort Buffer to receive new ::ESL_PORT structure address
@retval EFI_SUCCESS - Socket successfully created
**/
EFI_STATUS
EslUdp4PortAllocate (
- IN ESL_SOCKET * pSocket,
- IN ESL_SERVICE * pService,
- IN EFI_HANDLE ChildHandle,
+ IN ESL_PORT * pPort,
IN CONST UINT8 * pIpAddress,
IN UINT16 PortNumber,
- IN UINTN DebugFlags,
- OUT ESL_PORT ** ppPort
+ IN UINTN DebugFlags
);
/**
diff --git a/StdLib/EfiSocketLib/Tcp4.c b/StdLib/EfiSocketLib/Tcp4.c
index 23137cf..6b75423 100644
--- a/StdLib/EfiSocketLib/Tcp4.c
+++ b/StdLib/EfiSocketLib/Tcp4.c
@@ -74,13 +74,16 @@ CONST ESL_PROTOCOL_API cEslTcp4Api = {
EslTcp4Listen,
NULL, // OptionGet
NULL, // OptionSet
+ EslTcp4PortAllocate,
EslTcp4PortClose,
EslTcp4PortClosePacketFree,
EslTcp4PortCloseRxStop,
FALSE,
EslTcp4Receive,
EslTcp4RxCancel,
- EslTcp4TxBuffer
+ EslTcp4TxBuffer,
+ EslTcp4TxComplete,
+ EslTcp4TxOobComplete
};
@@ -213,7 +216,6 @@ EslTcp4Bind (
CONST struct sockaddr_in * pIp4Address;
EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding;
EFI_STATUS Status;
- EFI_STATUS TempStatus;
DBG_ENTER ( );
@@ -256,39 +258,18 @@ EslTcp4Bind (
//
// Open the port
//
- Status = EslTcp4PortAllocate ( pSocket,
- pService,
- ChildHandle,
- (UINT8 *) &pIp4Address->sin_addr.s_addr,
- SwapBytes16 ( pIp4Address->sin_port ),
- DEBUG_BIND,
- &pPort );
+ Status = EslSocketPortAllocate ( pSocket,
+ pService,
+ ChildHandle,
+ (UINT8 *) &pIp4Address->sin_addr.s_addr,
+ SwapBytes16 ( pIp4Address->sin_port ),
+ DEBUG_BIND,
+ &pPort );
}
else {
DEBUG (( DEBUG_BIND | DEBUG_POOL,
"ERROR - Failed to open Tcp4 port handle, Status: %r\r\n",
Status ));
- ChildHandle = NULL;
- }
-
- //
- // Close the port if necessary
- //
- if (( EFI_ERROR ( Status )) && ( NULL != ChildHandle )) {
- TempStatus = pServiceBinding->DestroyChild ( pServiceBinding,
- ChildHandle );
- if ( !EFI_ERROR ( TempStatus )) {
- DEBUG (( DEBUG_BIND | DEBUG_POOL,
- "0x%08x: Tcp4 port handle destroyed\r\n",
- ChildHandle ));
- }
- else {
- DEBUG (( DEBUG_ERROR | DEBUG_BIND | DEBUG_POOL,
- "ERROR - Failed to destroy the Tcp4 port handle 0x%08x, Status: %r\r\n",
- ChildHandle,
- TempStatus ));
- ASSERT ( EFI_SUCCESS == TempStatus );
- }
}
//
@@ -543,7 +524,7 @@ EslTcp4ConnectComplete (
//
// Close the current port
//
- Status = EslTcp4PortClose ( pPort );
+ Status = EslSocketPortClose ( pPort );
if ( !EFI_ERROR ( Status )) {
DEBUG (( DEBUG_CONNECT,
"0x%08x: Port closed\r\n",
@@ -583,7 +564,7 @@ EslTcp4ConnectComplete (
//
while ( NULL != pPort ) {
pNextPort = pPort->pLinkSocket;
- EslTcp4PortClose ( pPort );
+ EslSocketPortClose ( pPort );
if ( !EFI_ERROR ( Status )) {
DEBUG (( DEBUG_CONNECT,
"0x%08x: Port closed\r\n",
@@ -1306,13 +1287,13 @@ EslTcp4ListenComplete (
// Allocate a port for this connection
//
pTcp4 = &pPort->Context.Tcp4;
- Status = EslTcp4PortAllocate ( pNewSocket,
- pPort->pService,
- TcpPortHandle,
- &pTcp4->ConfigData.AccessPoint.StationAddress.Addr[0],
- 0,
- DEBUG_CONNECTION,
- &pNewPort );
+ Status = EslSocketPortAllocate ( pNewSocket,
+ pPort->pService,
+ TcpPortHandle,
+ &pTcp4->ConfigData.AccessPoint.StationAddress.Addr[0],
+ 0,
+ DEBUG_CONNECTION,
+ &pNewPort );
if ( !EFI_ERROR ( Status )) {
//
// Restart the listen operation on the port
@@ -1460,43 +1441,33 @@ EslTcp4ListenComplete (
/**
- Allocate and initialize a ESL_PORT structure.
+ Initialize the network specific portions of an ::ESL_PORT structure.
- This routine initializes an ::ESL_PORT structure for use by the
- socket.
+ This routine initializes the network specific portions of an
+ ::ESL_PORT structure for use by the socket.
- This support routine is called by ::EslTcp4Bind and
- ::EslTcp4ListenComplete to connect the socket with the underlying
- network adapter running the TCPv4 protocol.
+ This support routine is called by ::EslSocketPortAllocate
+ to connect the socket with the underlying network adapter
+ running the TCPv4 protocol.
- @param [in] pSocket Address of an ::ESL_SOCKET structure.
- @param [in] pService Address of an ::ESL_SERVICE structure.
- @param [in] ChildHandle TCP4 child handle
+ @param [in] ppPort Address of an ESL_PORT structure
@param [in] pIpAddress Buffer containing IP4 network address of the local host
@param [in] PortNumber Tcp4 port number
@param [in] DebugFlags Flags for debug messages
- @param [out] ppPort Buffer to receive new ::ESL_PORT structure address
@retval EFI_SUCCESS - Socket successfully created
**/
EFI_STATUS
EslTcp4PortAllocate (
- IN ESL_SOCKET * pSocket,
- IN ESL_SERVICE * pService,
- IN EFI_HANDLE ChildHandle,
+ IN ESL_PORT * pPort,
IN CONST UINT8 * pIpAddress,
IN UINT16 PortNumber,
- IN UINTN DebugFlags,
- OUT ESL_PORT ** ppPort
+ IN UINTN DebugFlags
)
{
- UINTN LengthInBytes;
EFI_TCP4_ACCESS_POINT * pAccessPoint;
- UINT8 * pBuffer;
- ESL_IO_MGMT * pIo;
- ESL_LAYER * pLayer;
- ESL_PORT * pPort;
+ ESL_SOCKET * pSocket;
ESL_TCP4_CONTEXT * pTcp4;
EFI_STATUS Status;
@@ -1506,49 +1477,9 @@ EslTcp4PortAllocate (
// Use for/break instead of goto
for ( ; ; ) {
//
- // Allocate a port structure
- //
- pLayer = &mEslLayer;
- LengthInBytes = sizeof ( *pPort )
- + ESL_STRUCTURE_ALIGNMENT_BYTES
- + (( pService->pSocketBinding->TxIoNormal
- + pService->pSocketBinding->TxIoUrgent )
- * sizeof ( ESL_IO_MGMT ));
- Status = gBS->AllocatePool ( EfiRuntimeServicesData,
- LengthInBytes,
- (VOID **)&pPort );
- if ( EFI_ERROR ( Status )) {
- DEBUG (( DEBUG_ERROR | DebugFlags | DEBUG_POOL | DEBUG_INIT,
- "ERROR - Failed to allocate the port structure, Status: %r\r\n",
- Status ));
- pSocket->errno = ENOMEM;
- pPort = NULL;
- break;
- }
- DEBUG (( DebugFlags | DEBUG_POOL | DEBUG_INIT,
- "0x%08x: Allocate pPort, %d bytes\r\n",
- pPort,
- LengthInBytes ));
-
- //
- // Initialize the port
- //
- ZeroMem ( pPort, LengthInBytes );
- pPort->Signature = PORT_SIGNATURE;
- pPort->pService = pService;
- pPort->pSocket = pSocket;
- pPort->DebugFlags = DebugFlags;
- pSocket->TxPacketOffset = OFFSET_OF ( ESL_PACKET, Op.Tcp4Tx.TxData );
- pSocket->TxTokenEventOffset = OFFSET_OF ( ESL_IO_MGMT, Token.Tcp4Tx.CompletionToken.Event );
- pSocket->TxTokenOffset = OFFSET_OF ( EFI_TCP4_IO_TOKEN, Packet.TxData );
- pBuffer = (UINT8 *)&pPort[ 1 ];
- pBuffer = &pBuffer[ ESL_STRUCTURE_ALIGNMENT_BYTES ];
- pBuffer = (UINT8 *)( ESL_STRUCTURE_ALIGNMENT_MASK & (UINTN)pBuffer );
- pIo = (ESL_IO_MGMT *)pBuffer;
-
- //
// Allocate the receive event
//
+ pSocket = pPort->pSocket;
pTcp4 = &pPort->Context.Tcp4;
Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL,
TPL_SOCKETS,
@@ -1567,36 +1498,6 @@ EslTcp4PortAllocate (
pTcp4->RxToken.CompletionToken.Event ));
//
- // Initialize the urgent transmit structures
- //
- Status = EslSocketIoInit ( pPort,
- &pIo,
- pService->pSocketBinding->TxIoUrgent,
- &pPort->pTxOobFree,
- DebugFlags | DEBUG_POOL,
- "urgent transmit",
- OFFSET_OF ( ESL_IO_MGMT, Token.Tcp4Tx.CompletionToken.Event ),
- EslTcp4TxOobComplete );
- if ( EFI_ERROR ( Status )) {
- break;
- }
-
- //
- // Initialize the normal transmit structures
- //
- Status = EslSocketIoInit ( pPort,
- &pIo,
- pService->pSocketBinding->TxIoNormal,
- &pPort->pTxFree,
- DebugFlags | DEBUG_POOL,
- "normal transmit",
- OFFSET_OF ( ESL_IO_MGMT, Token.Tcp4Tx.CompletionToken.Event ),
- EslTcp4TxComplete );
- if ( EFI_ERROR ( Status )) {
- break;
- }
-
- //
// Allocate the close event
//
Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL,
@@ -1635,26 +1536,11 @@ EslTcp4PortAllocate (
pTcp4->ConnectToken.CompletionToken.Event ));
//
- // Open the port protocol
+ // Initialize the port
//
- Status = gBS->OpenProtocol (
- ChildHandle,
- &gEfiTcp4ProtocolGuid,
- &pPort->pProtocol.v,
- pLayer->ImageHandle,
- NULL,
- EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL );
- if ( EFI_ERROR ( Status )) {
- DEBUG (( DEBUG_ERROR | DebugFlags,
- "ERROR - Failed to open gEfiTcp4ProtocolGuid on controller 0x%08x\r\n",
- pPort->Handle ));
- pSocket->errno = EEXIST;
- break;
- }
- DEBUG (( DebugFlags,
- "0x%08x: gEfiTcp4ProtocolGuid opened on controller 0x%08x\r\n",
- pPort->pProtocol.v,
- ChildHandle ));
+ pSocket->TxPacketOffset = OFFSET_OF ( ESL_PACKET, Op.Tcp4Tx.TxData );
+ pSocket->TxTokenEventOffset = OFFSET_OF ( ESL_IO_MGMT, Token.Tcp4Tx.CompletionToken.Event );
+ pSocket->TxTokenOffset = OFFSET_OF ( EFI_TCP4_IO_TOKEN, Packet.TxData );
//
// Save the transmit address
@@ -1664,7 +1550,6 @@ EslTcp4PortAllocate (
//
// Set the port address
//
- pPort->Handle = ChildHandle;
pAccessPoint = &pPort->Context.Tcp4.ConfigData.AccessPoint;
pAccessPoint->StationPort = PortNumber;
if (( 0 == pIpAddress[0])
@@ -1685,45 +1570,10 @@ EslTcp4PortAllocate (
}
pAccessPoint->ActiveFlag = FALSE;
pTcp4->ConfigData.TimeToLive = 255;
-
- //
- // Verify the socket layer synchronization
- //
- VERIFY_TPL ( TPL_SOCKETS );
-
- //
- // Add this port to the socket
- //
- pPort->pLinkSocket = pSocket->pPortList;
- pSocket->pPortList = pPort;
- DEBUG (( DebugFlags,
- "0x%08x: Socket adding port: 0x%08x\r\n",
- pSocket,
- pPort ));
-
- //
- // Add this port to the service
- //
- pPort->pLinkService = pService->pPortList;
- pService->pPortList = pPort;
-
- //
- // Return the port
- //
- *ppPort = pPort;
break;
}
//
- // Clean up after the error if necessary
- //
- if (( EFI_ERROR ( Status )) && ( NULL != pPort )) {
- //
- // Close the port
- //
- EslTcp4PortClose ( pPort );
- }
- //
// Return the operation status
//
DBG_EXIT_STATUS ( Status );
diff --git a/StdLib/EfiSocketLib/Udp4.c b/StdLib/EfiSocketLib/Udp4.c
index f8ec06e..916086e 100644
--- a/StdLib/EfiSocketLib/Udp4.c
+++ b/StdLib/EfiSocketLib/Udp4.c
@@ -62,13 +62,16 @@ CONST ESL_PROTOCOL_API cEslUdp4Api = {
NULL, // Listen
NULL, // OptionGet
NULL, // OptionSet
+ EslUdp4PortAllocate,
EslUdp4PortClose,
EslUdp4PortClosePacketFree,
EslUdp4PortCloseRxStop,
TRUE,
EslUdp4Receive,
EslUdp4RxCancel,
- EslUdp4TxBuffer
+ EslUdp4TxBuffer,
+ EslUdp4TxComplete,
+ NULL // TxOobComplete
};
@@ -116,7 +119,6 @@ EslUdp4Bind (
CONST struct sockaddr_in * pIp4Address;
EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding;
EFI_STATUS Status;
- EFI_STATUS TempStatus;
DBG_ENTER ( );
@@ -160,39 +162,18 @@ EslUdp4Bind (
//
// Open the port
//
- Status = EslUdp4PortAllocate ( pSocket,
- pService,
- ChildHandle,
- (UINT8 *) &pIp4Address->sin_addr.s_addr,
- SwapBytes16 ( pIp4Address->sin_port ),
- DEBUG_BIND,
- &pPort );
+ Status = EslSocketPortAllocate ( pSocket,
+ pService,
+ ChildHandle,
+ (UINT8 *) &pIp4Address->sin_addr.s_addr,
+ SwapBytes16 ( pIp4Address->sin_port ),
+ DEBUG_BIND,
+ &pPort );
}
else {
DEBUG (( DEBUG_BIND | DEBUG_POOL,
"ERROR - Failed to open Udp4 port handle, Status: %r\r\n",
Status ));
- ChildHandle = NULL;
- }
-
- //
- // Close the port if necessary
- //
- if (( EFI_ERROR ( Status )) && ( NULL != ChildHandle )) {
- TempStatus = pServiceBinding->DestroyChild ( pServiceBinding,
- ChildHandle );
- if ( !EFI_ERROR ( TempStatus )) {
- DEBUG (( DEBUG_BIND | DEBUG_POOL,
- "0x%08x: Udp4 port handle destroyed\r\n",
- ChildHandle ));
- }
- else {
- DEBUG (( DEBUG_ERROR | DEBUG_BIND | DEBUG_POOL,
- "ERROR - Failed to destroy the Udp4 port handle 0x%08x, Status: %r\r\n",
- ChildHandle,
- TempStatus ));
- ASSERT ( EFI_SUCCESS == TempStatus );
- }
}
//
@@ -554,45 +535,34 @@ EslUdp4Initialize (
/**
- Allocate and initialize an ::ESL_PORT structure.
+ Initialize the network specific portions of an ::ESL_PORT structure.
- This routine initializes an ::ESL_PORT structure for use by the
- socket.
+ This routine initializes the network specific portions of an
+ ::ESL_PORT structure for use by the socket.
- This support routine is called by ::EslUdp4Bind to connect the
- socket with the underlying network adapter running the UDPv4
- protocol.
+ This support routine is called by ::EslSocketPortAllocate
+ to connect the socket with the underlying network adapter
+ running the UDPv4 protocol.
- @param [in] pSocket Address of an ::ESL_SOCKET structure.
- @param [in] pService Address of an ::ESL_SERVICE structure.
- @param [in] ChildHandle Udp4 child handle
+ @param [in] ppPort Address of an ESL_PORT structure
@param [in] pIpAddress Buffer containing IP4 network address of the local host
@param [in] PortNumber Udp4 port number
@param [in] DebugFlags Flags for debug messages
- @param [out] ppPort Buffer to receive new ::ESL_PORT structure address
@retval EFI_SUCCESS - Socket successfully created
**/
EFI_STATUS
EslUdp4PortAllocate (
- IN ESL_SOCKET * pSocket,
- IN ESL_SERVICE * pService,
- IN EFI_HANDLE ChildHandle,
+ IN ESL_PORT * pPort,
IN CONST UINT8 * pIpAddress,
IN UINT16 PortNumber,
- IN UINTN DebugFlags,
- OUT ESL_PORT ** ppPort
+ IN UINTN DebugFlags
)
{
- UINTN LengthInBytes;
- UINT8 * pBuffer;
EFI_UDP4_CONFIG_DATA * pConfig;
- ESL_IO_MGMT * pIo;
- ESL_LAYER * pLayer;
- ESL_PORT * pPort;
- CONST ESL_SOCKET_BINDING * pSocketBinding;
ESL_UDP4_CONTEXT * pUdp4;
+ ESL_SOCKET * pSocket;
EFI_STATUS Status;
DBG_ENTER ( );
@@ -601,48 +571,9 @@ EslUdp4PortAllocate (
// Use for/break instead of goto
for ( ; ; ) {
//
- // Allocate a port structure
- //
- pLayer = &mEslLayer;
- LengthInBytes = sizeof ( *pPort )
- + ESL_STRUCTURE_ALIGNMENT_BYTES
- + ( pService->pSocketBinding->TxIoNormal
- * sizeof ( ESL_IO_MGMT ));
- Status = gBS->AllocatePool ( EfiRuntimeServicesData,
- LengthInBytes,
- (VOID **)&pPort );
- if ( EFI_ERROR ( Status )) {
- DEBUG (( DEBUG_ERROR | DebugFlags | DEBUG_POOL | DEBUG_INIT,
- "ERROR - Failed to allocate the port structure, Status: %r\r\n",
- Status ));
- pSocket->errno = ENOMEM;
- pPort = NULL;
- break;
- }
- DEBUG (( DebugFlags | DEBUG_POOL | DEBUG_INIT,
- "0x%08x: Allocate pPort, %d bytes\r\n",
- pPort,
- LengthInBytes ));
-
- //
- // Initialize the port
- //
- ZeroMem ( pPort, LengthInBytes );
- pPort->Signature = PORT_SIGNATURE;
- pPort->pService = pService;
- pPort->pSocket = pSocket;
- pPort->DebugFlags = DebugFlags;
- pSocket->TxPacketOffset = OFFSET_OF ( ESL_PACKET, Op.Udp4Tx.TxData );
- pSocket->TxTokenEventOffset = OFFSET_OF ( ESL_IO_MGMT, Token.Udp4Tx.Event );
- pSocket->TxTokenOffset = OFFSET_OF ( EFI_UDP4_COMPLETION_TOKEN, Packet.TxData );
- pBuffer = (UINT8 *)&pPort[ 1 ];
- pBuffer = &pBuffer[ ESL_STRUCTURE_ALIGNMENT_BYTES ];
- pBuffer = (UINT8 *)( ESL_STRUCTURE_ALIGNMENT_MASK & (UINTN)pBuffer );
- pIo = (ESL_IO_MGMT *)pBuffer;
-
- //
// Allocate the receive event
//
+ pSocket = pPort->pSocket;
pUdp4 = &pPort->Context.Udp4;
Status = gBS->CreateEvent ( EVT_NOTIFY_SIGNAL,
TPL_SOCKETS,
@@ -661,42 +592,11 @@ EslUdp4PortAllocate (
pUdp4->RxToken.Event ));
//
- // Allocate the transmit events
- //
- Status = EslSocketIoInit ( pPort,
- &pIo,
- pService->pSocketBinding->TxIoNormal,
- &pPort->pTxFree,
- DebugFlags | DEBUG_POOL,
- "transmit",
- OFFSET_OF ( ESL_IO_MGMT, Token.Udp4Tx.Event ),
- EslUdp4TxComplete );
- if ( EFI_ERROR ( Status )) {
- break;
- }
-
- //
- // Open the port protocol
+ // Initialize the port
//
- pSocketBinding = pService->pSocketBinding;
- Status = gBS->OpenProtocol (
- ChildHandle,
- pSocketBinding->pNetworkProtocolGuid,
- &pPort->pProtocol.v,
- pLayer->ImageHandle,
- NULL,
- EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL );
- if ( EFI_ERROR ( Status )) {
- DEBUG (( DEBUG_ERROR | DebugFlags,
- "ERROR - Failed to open gEfiUdp4ProtocolGuid on controller 0x%08x\r\n",
- pPort->Handle ));
- pSocket->errno = EEXIST;
- break;
- }
- DEBUG (( DebugFlags,
- "0x%08x: gEfiUdp4ProtocolGuid opened on controller 0x%08x\r\n",
- pPort->pProtocol.v,
- ChildHandle ));
+ pSocket->TxPacketOffset = OFFSET_OF ( ESL_PACKET, Op.Udp4Tx.TxData );
+ pSocket->TxTokenEventOffset = OFFSET_OF ( ESL_IO_MGMT, Token.Udp4Tx.Event );
+ pSocket->TxTokenOffset = OFFSET_OF ( EFI_UDP4_COMPLETION_TOKEN, Packet.TxData );
//
// Save the transmit address
@@ -706,7 +606,6 @@ EslUdp4PortAllocate (
//
// Set the port address
//
- pPort->Handle = ChildHandle;
pConfig = &pPort->Context.Udp4.ConfigData;
pConfig->StationPort = PortNumber;
if (( 0 == pIpAddress[0])
@@ -731,45 +630,10 @@ EslUdp4PortAllocate (
pConfig->AcceptPromiscuous = FALSE;
pConfig->AllowDuplicatePort = TRUE;
pConfig->DoNotFragment = TRUE;
-
- //
- // Verify the socket layer synchronization
- //
- VERIFY_TPL ( TPL_SOCKETS );
-
- //
- // Add this port to the socket
- //
- pPort->pLinkSocket = pSocket->pPortList;
- pSocket->pPortList = pPort;
- DEBUG (( DebugFlags,
- "0x%08x: Socket adding port: 0x%08x\r\n",
- pSocket,
- pPort ));
-
- //
- // Add this port to the service
- //
- pPort->pLinkService = pService->pPortList;
- pService->pPortList = pPort;
-
- //
- // Return the port
- //
- *ppPort = pPort;
break;
}
//
- // Clean up after the error if necessary
- //
- if (( EFI_ERROR ( Status )) && ( NULL != pPort )) {
- //
- // Close the port
- //
- EslSocketPortClose ( pPort );
- }
- //
// Return the operation status
//
DBG_EXIT_STATUS ( Status );
@@ -1743,9 +1607,19 @@ EslUdp4Shutdown (
}
}
else {
- DEBUG (( DEBUG_LISTEN,
- "0x%08x: Port configured\r\n",
- pPort ));
+ DEBUG (( DEBUG_TX,
+ "0x%08x: pPort Configured for %d.%d.%d.%d:%d --> %d.%d.%d.%d:%d\r\n",
+ pPort,
+ pUdp4->ConfigData.StationAddress.Addr[0],
+ pUdp4->ConfigData.StationAddress.Addr[1],
+ pUdp4->ConfigData.StationAddress.Addr[2],
+ pUdp4->ConfigData.StationAddress.Addr[3],
+ pUdp4->ConfigData.StationPort,
+ pUdp4->ConfigData.RemoteAddress.Addr[0],
+ pUdp4->ConfigData.RemoteAddress.Addr[1],
+ pUdp4->ConfigData.RemoteAddress.Addr[2],
+ pUdp4->ConfigData.RemoteAddress.Addr[3],
+ pUdp4->ConfigData.RemotePort ));
pPort->bConfigured = TRUE;
//