Merged socket development branch:

* Fixed bug report (Duane Voth: Python sockets test application not working) by starting the receive operations when a connection is established!
* Increased performance by extending the idle loop into the network stack with the Poll call.
* Added support for TCPv6 (SOCK_STREAM) and UDPv6 (SOCK_DGRAM).
* Added support for getaddrinfo and getnameinfo calls.
* Moved application PCD values into AppPkg

Signed-off-by: lpleahy

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13002 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
lpleahy
2012-02-09 19:16:44 +00:00
parent 5709e4e290
commit 3bdf9aae5f
19 changed files with 6551 additions and 25 deletions

View File

@@ -34,7 +34,9 @@
Service.c
Socket.c
Tcp4.c
Tcp6.c
Udp4.c
Udp6.c
UseEfiSocketLib.c
[Packages]
@@ -52,9 +54,15 @@
[Protocols]
gEfiIp4ProtocolGuid
gEfiIp4ServiceBindingProtocolGuid
gEfiIp6ProtocolGuid
gEfiIp6ServiceBindingProtocolGuid
gEfiTcp4ProtocolGuid
gEfiTcp4ServiceBindingProtocolGuid
gEfiTcp6ProtocolGuid
gEfiTcp6ServiceBindingProtocolGuid
gEfiUdp4ProtocolGuid
gEfiUdp4ServiceBindingProtocolGuid
gEfiUdp6ProtocolGuid
gEfiUdp6ServiceBindingProtocolGuid
gEfiSocketProtocolGuid
gEfiSocketServiceBindingProtocolGuid

View File

@@ -383,6 +383,7 @@ EslIp4PortAllocate (
//
pPort->pfnConfigure = (PFN_NET_CONFIGURE)pPort->pProtocol.IPv4->Configure;
pPort->pfnRxCancel = (PFN_NET_IO_START)pPort->pProtocol.IPv4->Cancel;
pPort->pfnRxPoll = (PFN_NET_POLL)pPort->pProtocol.IPv4->Poll;
pPort->pfnRxStart = (PFN_NET_IO_START)pPort->pProtocol.IPv4->Receive;
pPort->pfnTxStart = (PFN_NET_IO_START)pPort->pProtocol.IPv4->Transmit;

View File

@@ -481,6 +481,14 @@ CONST ESL_SOCKET_BINDING cEslSocketBinding[] = {
4, // RX buffers
4, // TX buffers
4 }, // TX Oob buffers
{ L"Tcp6",
&gEfiTcp6ServiceBindingProtocolGuid,
&gEfiTcp6ProtocolGuid,
&mEslTcp6ServiceGuid,
OFFSET_OF ( ESL_LAYER, pTcp6List ),
4, // RX buffers
4, // TX buffers
4 }, // TX Oob buffers
{ L"Udp4",
&gEfiUdp4ServiceBindingProtocolGuid,
&gEfiUdp4ProtocolGuid,
@@ -488,6 +496,14 @@ CONST ESL_SOCKET_BINDING cEslSocketBinding[] = {
OFFSET_OF ( ESL_LAYER, pUdp4List ),
4, // RX buffers
4, // TX buffers
0 }, // TX Oob buffers
{ L"Udp6",
&gEfiUdp6ServiceBindingProtocolGuid,
&gEfiUdp6ProtocolGuid,
&mEslUdp6ServiceGuid,
OFFSET_OF ( ESL_LAYER, pUdp6List ),
4, // RX buffers
4, // TX buffers
0 } // TX Oob buffers
};
@@ -516,11 +532,11 @@ CONST int cEslAfInetApiSize = DIM ( cEslAfInetApi );
**/
CONST ESL_PROTOCOL_API * cEslAfInet6Api[] = {
NULL, // 0
NULL, // SOCK_STREAM
NULL, // SOCK_DGRAM
&cEslTcp6Api, // SOCK_STREAM
&cEslUdp6Api, // SOCK_DGRAM
NULL, // SOCK_RAW
NULL, // SOCK_RDM
NULL // SOCK_SEQPACKET
&cEslTcp6Api // SOCK_SEQPACKET
};
/**
@@ -603,6 +619,7 @@ EslSocket (
// Validate the domain value
//
if (( AF_INET != domain )
&& ( AF_INET6 != domain )
&& ( AF_LOCAL != domain )) {
DEBUG (( DEBUG_ERROR | DEBUG_SOCKET,
"ERROR - Invalid domain value\r\n" ));
@@ -1789,6 +1806,11 @@ EslSocketConnect (
if ( EFI_NOT_READY != Status ) {
if ( !EFI_ERROR ( Status )) {
pSocket->State = SOCKET_STATE_CONNECTED;
//
// Start the receive operations
//
EslSocketRxStart ( pSocket->pPortList );
}
else {
pSocket->State = SOCKET_STATE_BOUND;
@@ -1980,7 +2002,8 @@ EslSocketGetLocalAddress (
//
// Verify the socket state
//
if ( SOCKET_STATE_CONNECTED == pSocket->State ) {
if (( SOCKET_STATE_CONNECTED == pSocket->State )
|| ( SOCKET_STATE_LISTENING == pSocket->State )) {
//
// Verify the API
//
@@ -3096,7 +3119,7 @@ EslSocketPacketAllocate (
LengthInBytes,
(VOID **)&pPacket );
if ( !EFI_ERROR ( Status )) {
DEBUG (( DebugFlags | DEBUG_POOL | DEBUG_INIT,
DEBUG (( DebugFlags | DEBUG_POOL,
"0x%08x: Allocate pPacket, %d bytes\r\n",
pPacket,
LengthInBytes ));
@@ -3210,6 +3233,7 @@ EslSocketPoll (
short DetectedEvents;
ESL_SOCKET * pSocket;
EFI_STATUS Status;
EFI_TPL TplPrevious;
short ValidEvents;
DEBUG (( DEBUG_POLL, "Entering SocketPoll\r\n" ));
@@ -3247,6 +3271,22 @@ EslSocketPoll (
Events & ( ~ValidEvents )));
}
else {
//
// Synchronize with the socket layer
//
RAISE_TPL ( TplPrevious, TPL_SOCKETS );
//
// Increase the network performance by extending the
// polling (idle) loop down into the LAN driver
//
EslSocketRxPoll ( pSocket );
//
// Release the socket layer synchronization
//
RESTORE_TPL ( TplPrevious );
//
// Check for pending connections
//
@@ -4366,6 +4406,11 @@ EslSocketReceive (
// Verify that the socket is connected
//
if ( SOCKET_STATE_CONNECTED == pSocket->State ) {
//
// Poll the network to increase performance
//
EslSocketRxPoll ( pSocket );
//
// Locate the port
//
@@ -4847,6 +4892,49 @@ EslSocketRxComplete (
}
/**
Poll a socket for pending receive activity.
This routine is called at elivated TPL and extends the idle
loop which polls a socket down into the LAN driver layer to
determine if there is any receive activity.
The ::EslSocketPoll, ::EslSocketReceive and ::EslSocketTransmit
routines call this routine when there is nothing to do.
@param [in] pSocket Address of an ::EFI_SOCKET structure.
**/
VOID
EslSocketRxPoll (
IN ESL_SOCKET * pSocket
)
{
ESL_PORT * pPort;
DEBUG (( DEBUG_POLL, "Entering EslSocketRxPoll\r\n" ));
//
// Increase the network performance by extending the
// polling (idle) loop down into the LAN driver
//
pPort = pSocket->pPortList;
while ( NULL != pPort ) {
//
// Poll the LAN adapter
//
pPort->pfnRxPoll ( pPort->pProtocol.v );
//
// Locate the next LAN adapter
//
pPort = pPort->pLinkSocket;
}
DEBUG (( DEBUG_POLL, "Exiting EslSocketRxPoll\r\n" ));
}
/**
Start a receive operation
@@ -5291,6 +5379,11 @@ EslSocketTransmit (
//
RAISE_TPL ( TplPrevious, TPL_SOCKETS );
//
// Poll the network to increase performance
//
EslSocketRxPoll ( pSocket );
//
// Attempt to buffer the packet for transmission
//

View File

@@ -137,6 +137,26 @@ typedef struct
} ESL_TCP4_TX_DATA;
/**
Receive context for SOCK_STREAM and SOCK_SEQPACKET sockets using TCPv6.
**/
typedef struct
{
EFI_TCP6_RECEIVE_DATA RxData; ///< Receive operation description
UINT8 Buffer[ RX_PACKET_DATA ]; ///< Data buffer
} ESL_TCP6_RX_DATA;
/**
Transmit context for SOCK_STREAM and SOCK_SEQPACKET sockets using TCPv6.
**/
typedef struct
{
EFI_TCP6_TRANSMIT_DATA TxData; ///< Transmit operation description
UINT8 Buffer[ 1 ]; ///< Data buffer
} ESL_TCP6_TX_DATA;
/**
Receive context for SOCK_DGRAM sockets using UDPv4.
**/
@@ -159,6 +179,28 @@ typedef struct
} ESL_UDP4_TX_DATA;
/**
Receive context for SOCK_DGRAM sockets using UDPv6.
**/
typedef struct
{
EFI_UDP6_SESSION_DATA Session; ///< Remote network address
EFI_UDP6_RECEIVE_DATA * pRxData; ///< Receive operation description
} ESL_UDP6_RX_DATA;
/**
Transmit context for SOCK_DGRAM sockets using UDPv6.
**/
typedef struct
{
EFI_UDP6_SESSION_DATA Session; ///< Remote network address
EFI_UDP6_TRANSMIT_DATA TxData; ///< Transmit operation description
UINTN RetransmitCount; ///< Retransmit to handle ARP negotiation
UINT8 Buffer[ 1 ]; ///< Data buffer
} ESL_UDP6_TX_DATA;
/**
Network specific context for transmit and receive packets.
**/
@@ -172,8 +214,12 @@ typedef struct _ESL_PACKET {
ESL_IP4_TX_DATA Ip4Tx; ///< Transmit operation description
ESL_TCP4_RX_DATA Tcp4Rx; ///< Receive operation description
ESL_TCP4_TX_DATA Tcp4Tx; ///< Transmit operation description
ESL_TCP6_RX_DATA Tcp6Rx; ///< Receive operation description
ESL_TCP6_TX_DATA Tcp6Tx; ///< Transmit operation description
ESL_UDP4_RX_DATA Udp4Rx; ///< Receive operation description
ESL_UDP4_TX_DATA Udp4Tx; ///< Transmit operation description
ESL_UDP6_RX_DATA Udp6Rx; ///< Receive operation description
ESL_UDP6_TX_DATA Udp6Tx; ///< Transmit operation description
} Op; ///< Network specific context
} GCC_ESL_PACKET;
@@ -217,8 +263,12 @@ typedef struct _ESL_IO_MGMT {
EFI_IP4_COMPLETION_TOKEN Ip4Tx; ///< IP4 transmit token
EFI_TCP4_IO_TOKEN Tcp4Rx; ///< TCP4 receive token
EFI_TCP4_IO_TOKEN Tcp4Tx; ///< TCP4 transmit token
EFI_TCP6_IO_TOKEN Tcp6Rx; ///< TCP6 receive token
EFI_TCP6_IO_TOKEN Tcp6Tx; ///< TCP6 transmit token
EFI_UDP4_COMPLETION_TOKEN Udp4Rx; ///< UDP4 receive token
EFI_UDP4_COMPLETION_TOKEN Udp4Tx; ///< UDP4 transmit token
EFI_UDP6_COMPLETION_TOKEN Udp6Rx; ///< UDP6 receive token
EFI_UDP6_COMPLETION_TOKEN Udp6Tx; ///< UDP6 transmit token
} Token; ///< Completion token for the network operation
} GCC_IO_MGMT;
@@ -256,6 +306,26 @@ typedef struct {
EFI_TCP4_CLOSE_TOKEN CloseToken; ///< Close control
} ESL_TCP4_CONTEXT;
/**
TCP6 context structure
The driver uses this structure to manage the TCP6 connections.
**/
typedef struct {
//
// TCP6 context
//
EFI_TCP6_CONFIG_DATA ConfigData; ///< TCP6 configuration data
EFI_TCP6_OPTION Option; ///< TCP6 port options
//
// Tokens
//
EFI_TCP6_LISTEN_TOKEN ListenToken; ///< Listen control
EFI_TCP6_CONNECTION_TOKEN ConnectToken; ///< Connection control
EFI_TCP6_CLOSE_TOKEN CloseToken; ///< Close control
} ESL_TCP6_CONTEXT;
/**
UDP4 context structure
@@ -268,6 +338,18 @@ typedef struct {
EFI_UDP4_CONFIG_DATA ConfigData; ///< UDP4 configuration data
} ESL_UDP4_CONTEXT;
/**
UDP6 context structure
The driver uses this structure to manage the UDP6 connections.
**/
typedef struct {
//
// UDP6 context
//
EFI_UDP6_CONFIG_DATA ConfigData; ///< UDP6 configuration data
} ESL_UDP6_CONTEXT;
/**
Configure the network layer.
@@ -301,6 +383,21 @@ EFI_STATUS
IN VOID * pToken
);
/**
Poll the LAN adapter for receive packets.
@param [in] pProtocol Protocol structure address
@param [in] pToken Completion token address
@return Returns EFI_SUCCESS if the operation is successfully
started.
**/
typedef
EFI_STATUS
(* PFN_NET_POLL) (
IN VOID * pProtocol
);
/**
Port control structure
@@ -353,6 +450,7 @@ typedef struct _ESL_PORT {
// Receive data management
//
PFN_NET_IO_START pfnRxCancel; ///< Cancel a receive on the network
PFN_NET_POLL pfnRxPoll; ///< Poll the LAN adapter for receive packets
PFN_NET_IO_START pfnRxStart; ///< Start a receive on the network
ESL_IO_MGMT * pRxActive; ///< Active receive operation queue
ESL_IO_MGMT * pRxFree; ///< Free structure queue
@@ -364,12 +462,16 @@ typedef struct _ESL_PORT {
VOID * v; ///< VOID pointer
EFI_IP4_PROTOCOL * IPv4; ///< IP4 protocol pointer
EFI_TCP4_PROTOCOL * TCPv4; ///< TCP4 protocol pointer
EFI_TCP6_PROTOCOL * TCPv6; ///< TCP6 protocol pointer
EFI_UDP4_PROTOCOL * UDPv4; ///< UDP4 protocol pointer
EFI_UDP6_PROTOCOL * UDPv6; ///< UDP6 protocol pointer
} pProtocol; ///< Protocol structure address
union {
ESL_IP4_CONTEXT Ip4; ///< IPv4 management data
ESL_TCP4_CONTEXT Tcp4; ///< TCPv4 management data
ESL_TCP6_CONTEXT Tcp6; ///< TCPv6 management data
ESL_UDP4_CONTEXT Udp4; ///< UDPv4 management data
ESL_UDP6_CONTEXT Udp6; ///< UDPv6 management data
} Context; ///< Network specific context
}GCC_ESL_PORT;
@@ -975,7 +1077,9 @@ typedef struct {
//
ESL_SERVICE * pIp4List; ///< List of Ip4 services
ESL_SERVICE * pTcp4List; ///< List of Tcp4 services
ESL_SERVICE * pTcp6List; ///< List of Tcp6 services
ESL_SERVICE * pUdp4List; ///< List of Udp4 services
ESL_SERVICE * pUdp6List; ///< List of Udp6 services
//
// Socket management
@@ -992,8 +1096,11 @@ typedef struct {
extern ESL_LAYER mEslLayer;
extern CONST ESL_PROTOCOL_API cEslIp4Api;
extern CONST ESL_PROTOCOL_API cEslIp6Api;
extern CONST ESL_PROTOCOL_API cEslTcp4Api;
extern CONST ESL_PROTOCOL_API cEslTcp6Api;
extern CONST ESL_PROTOCOL_API cEslUdp4Api;
extern CONST ESL_PROTOCOL_API cEslUdp6Api;
extern CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding;
@@ -1423,6 +1530,24 @@ EslSocketRxComplete (
IN BOOLEAN bUrgent
);
/**
Poll a socket for pending receive activity.
This routine is called at elivated TPL and extends the idle
loop which polls a socket down into the LAN driver layer to
determine if there is any receive activity.
The ::EslSocketPoll, ::EslSocketReceive and ::EslSocketTransmit
routines call this routine when there is nothing to do.
@param [in] pSocket Address of an ::EFI_SOCKET structure.
**/
VOID
EslSocketRxPoll (
IN ESL_SOCKET * pSocket
);
/**
Start a receive operation

View File

@@ -1307,6 +1307,7 @@ EslTcp4PortAllocate (
// pPort->pfnRxCancel = NULL; since the UEFI implementation returns EFI_UNSUPPORTED
//
pPort->pfnConfigure = (PFN_NET_CONFIGURE)pPort->pProtocol.TCPv4->Configure;
pPort->pfnRxPoll = (PFN_NET_POLL)pPort->pProtocol.TCPv4->Poll;
pPort->pfnRxStart = (PFN_NET_IO_START)pPort->pProtocol.TCPv4->Receive;
pPort->pfnTxStart = (PFN_NET_IO_START)pPort->pProtocol.TCPv4->Transmit;

2329
StdLib/EfiSocketLib/Tcp6.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -253,6 +253,7 @@ EslUdp4PortAllocate (
//
pPort->pfnConfigure = (PFN_NET_CONFIGURE)pPort->pProtocol.UDPv4->Configure;
pPort->pfnRxCancel = (PFN_NET_IO_START)pPort->pProtocol.UDPv4->Cancel;
pPort->pfnRxPoll = (PFN_NET_POLL)pPort->pProtocol.UDPv4->Poll;
pPort->pfnRxStart = (PFN_NET_IO_START)pPort->pProtocol.UDPv4->Receive;
pPort->pfnTxStart = (PFN_NET_IO_START)pPort->pProtocol.UDPv4->Transmit;

1094
StdLib/EfiSocketLib/Udp6.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -28,6 +28,14 @@ CONST EFI_GUID mEslIp4ServiceGuid = {
};
/**
Tag GUID - IPv6 in use by an application using EfiSocketLib
**/
CONST EFI_GUID mEslIp6ServiceGuid = {
0xc51b2761, 0xc476, 0x45fe, { 0xbe, 0x61, 0xba, 0x4b, 0xcc, 0x32, 0xf2, 0x34 }
};
/**
Tag GUID - TCPv4 in use by an application using EfiSocketLib
**/
@@ -36,6 +44,14 @@ CONST EFI_GUID mEslTcp4ServiceGuid = {
};
/**
Tag GUID - TCPv6 in use by an application using EfiSocketLib
**/
CONST EFI_GUID mEslTcp6ServiceGuid = {
0x279858a4, 0x4e9e, 0x4e53, { 0x93, 0x22, 0xf2, 0x54, 0xe0, 0x7e, 0xef, 0xd4 }
};
/**
Tag GUID - UDPv4 in use by an application using EfiSocketLib
**/
@@ -44,6 +60,14 @@ CONST EFI_GUID mEslUdp4ServiceGuid = {
};
/**
Tag GUID - UDPv6 in use by an application using EfiSocketLib
**/
CONST EFI_GUID mEslUdp6ServiceGuid = {
0xaa4af677, 0x6efe, 0x477c, { 0x96, 0x68, 0xe8, 0x13, 0x9d, 0x2, 0xfd, 0x9b }
};
/**
Connect to the EFI socket library
@@ -252,10 +276,8 @@ EslServiceNetworkDisconnect (
NULL,
&HandleCount,
&pHandles );
if ( EFI_ERROR ( Status )) {
break;
}
if ( NULL != pHandles ) {
if (( !EFI_ERROR ( Status ))
&& ( NULL != pHandles )) {
//
// Attempt to disconnect from this network adapter
//
@@ -277,6 +299,7 @@ EslServiceNetworkDisconnect (
// Set the next network protocol
//
pSocketBinding += 1;
Status = EFI_SUCCESS;
}
//