2 Definitions for the Socket layer driver.
4 Copyright (c) 2011, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Efi/EfiSocketLib.h>
19 //------------------------------------------------------------------------------
21 //------------------------------------------------------------------------------
23 #define DEBUG_SOCKET 0x20000000 ///< Display Socket related messages
24 #define DEBUG_BIND 0x10000000 ///< Display bind related messages
25 #define DEBUG_LISTEN 0x08000000 ///< Display listen related messages
26 #define DEBUG_CONNECTION 0x04000000 ///< Display connection list related messages
27 #define DEBUG_POLL 0x02000000 ///< Display poll messages
28 #define DEBUG_ACCEPT 0x01000000 ///< Display accept related messages
29 #define DEBUG_RX 0x00800000 ///< Display receive messages
30 #define DEBUG_TX 0x00400000 ///< Display transmit messages
31 #define DEBUG_CLOSE 0x00200000 ///< Display close messages
32 #define DEBUG_CONNECT 0x00100000 ///< Display connect messages
34 #define MAX_PENDING_CONNECTIONS 1 ///< Maximum connection FIFO depth
35 #define MAX_RX_DATA 65536 ///< Maximum receive data size
36 #define MAX_TX_DATA ( MAX_RX_DATA * 2 )
37 #define RX_PACKET_DATA 16384 ///< Maximum number of bytes in a RX packet
39 #define LAYER_SIGNATURE SIGNATURE_32('S','k','t','L') ///< DT_LAYER memory signature
40 #define SERVICE_SIGNATURE SIGNATURE_32('S','k','t','S') ///< DT_SERVICE memory signature
41 #define SOCKET_SIGNATURE SIGNATURE_32('S','c','k','t') ///< DT_SOCKET memory signature
42 #define PORT_SIGNATURE SIGNATURE_32('P','o','r','t') ///< DT_PORT memory signature
46 NETWORK_TYPE_UNKNOWN
= 0,
56 SOCKET_STATE_NOT_CONFIGURED
= 0, ///< socket call was successful
57 SOCKET_STATE_BOUND
, ///< bind call was successful
58 SOCKET_STATE_LISTENING
, ///< listen call was successful
59 SOCKET_STATE_NO_PORTS
, ///< No ports available
60 SOCKET_STATE_IN_FIFO
, ///< Socket on FIFO
61 SOCKET_STATE_CONNECTING
, ///< Connecting to a remote system
62 SOCKET_STATE_CONNECTED
, ///< Accept or connect call was successful
65 // Close state must be the last in the list
67 SOCKET_STATE_CLOSED
///< Close call was successful
72 PORT_STATE_ALLOCATED
= 0, ///< Port allocated
73 PORT_STATE_OPEN
, ///< Port opened
74 PORT_STATE_RX_ERROR
, ///< Receive error detected
77 // Close state must be last in the list
79 PORT_STATE_CLOSE_STARTED
, ///< Close started on port
80 PORT_STATE_CLOSE_TX_DONE
, ///< Transmits shutdown
81 PORT_STATE_CLOSE_RX_DONE
, ///< Receives shutdown
82 PORT_STATE_CLOSE_DONE
///< Port close operation complete
85 //------------------------------------------------------------------------------
87 //------------------------------------------------------------------------------
89 typedef struct _DT_PACKET DT_PACKET
; ///< Forward declaration
90 typedef struct _DT_PORT DT_PORT
; ///< Forward declaration
91 typedef struct _DT_SOCKET DT_SOCKET
; ///< Forward declaration
95 EFI_TCP4_RECEIVE_DATA RxData
; ///< Receive operation description
96 size_t ValidBytes
; ///< Length of valid data in bytes
97 UINT8
* pBuffer
; ///< Current data pointer
98 UINT8 Buffer
[ RX_PACKET_DATA
]; ///< Data buffer
103 EFI_TCP4_TRANSMIT_DATA TxData
; ///< Transmit operation description
104 UINT8 Buffer
[ 1 ]; ///< Data buffer
109 EFI_UDP4_SESSION_DATA Session
; ///< * Remote network address
110 EFI_UDP4_RECEIVE_DATA
* pRxData
; ///< * Receive operation description
115 EFI_UDP4_SESSION_DATA Session
; ///< Remote network address
116 EFI_UDP4_TRANSMIT_DATA TxData
; ///< Transmit operation description
117 UINT8 Buffer
[ 1 ]; ///< Data buffer
120 typedef struct _DT_PACKET
{
121 DT_PACKET
* pNext
; ///< Next packet in the receive list
122 size_t PacketSize
; ///< Size of this data structure
124 DT_TCP4_RX_DATA Tcp4Rx
; ///< Receive operation description
125 DT_TCP4_TX_DATA Tcp4Tx
; ///< Transmit operation description
126 DT_UDP4_RX_DATA Udp4Rx
; ///< Receive operation description
127 DT_UDP4_TX_DATA Udp4Tx
; ///< Transmit operation description
132 Service control structure
134 The driver uses this structure to manage the network devices.
136 typedef struct _DT_SERVICE
{
137 UINTN Signature
; ///< Structure identification
142 DT_SERVICE
* pNext
; ///< Next service in the service list
147 CONST DT_SOCKET_BINDING
* pSocketBinding
; ///< Name and shutdown routine
148 EFI_HANDLE Controller
; ///< Controller for the service
149 VOID
* pInterface
; ///< Network layer service binding interface
154 NETWORK_TYPE NetworkType
; ///< Type of network service
155 DT_PORT
* pPortList
; ///< List of ports using this service
159 Start the close operation on a TCP4 port.
161 @param [in] pPort Address of the port structure.
162 @param [in] bAbort Set TRUE to abort active transfers
163 @param [in] DebugFlags Flags for debug messages
168 PFN_PORT_CLOSE_START (
175 TCP4 context structure
177 The driver uses this structure to manage the TCP4 connections.
183 EFI_HANDLE Handle
; ///< TCP4 port handle
184 EFI_TCP4_PROTOCOL
* pProtocol
; ///< TCP4 protocol pointer
185 EFI_TCP4_CONFIG_DATA ConfigData
; ///< TCP4 configuration data
186 EFI_TCP4_OPTION Option
; ///< TCP4 port options
187 BOOLEAN bConfigured
; ///< TRUE if configuration was successful
192 EFI_TCP4_LISTEN_TOKEN ListenToken
; ///< Listen control
193 EFI_TCP4_CONNECTION_TOKEN ConnectToken
; ///< Connection control
194 EFI_TCP4_CLOSE_TOKEN CloseToken
; ///< Close control
197 // Receive data management
199 EFI_TCP4_IO_TOKEN RxToken
; ///< Receive token
200 DT_PACKET
* pReceivePending
; ///< Receive operation in progress
203 // Transmit data management
205 EFI_TCP4_IO_TOKEN TxOobToken
; ///< Urgent data token
206 DT_PACKET
* pTxOobPacket
; ///< Urgent data in progress
208 EFI_TCP4_IO_TOKEN TxToken
; ///< Normal data token
209 DT_PACKET
* pTxPacket
; ///< Normal transmit in progress
213 UDP4 context structure
215 The driver uses this structure to manage the UDP4 connections.
221 EFI_HANDLE Handle
; ///< UDP4 port handle
222 EFI_UDP4_PROTOCOL
* pProtocol
; ///< UDP4 protocol pointer
223 EFI_UDP4_CONFIG_DATA ConfigData
; ///< UDP4 configuration data
224 BOOLEAN bConfigured
; ///< TRUE if configuration was successful
227 // Receive data management
229 EFI_UDP4_COMPLETION_TOKEN RxToken
;///< Receive token
230 DT_PACKET
* pReceivePending
; ///< Receive operation in progress
233 // Transmit data management
235 EFI_UDP4_COMPLETION_TOKEN TxToken
;///< Transmit token
236 DT_PACKET
* pTxPacket
; ///< Transmit in progress
241 Port control structure
243 The driver uses this structure to manager the socket's connection
244 with the network driver.
246 typedef struct _DT_PORT
{
247 UINTN Signature
; ///< Structure identification
252 DT_PORT
* pLinkService
; ///< Link in service port list
253 DT_PORT
* pLinkSocket
; ///< Link in socket port list
258 DT_SERVICE
* pService
; ///< Service for this port
259 DT_SOCKET
* pSocket
; ///< Socket for this port
260 // PFN_CLOSE_PORT pfnClosePort; ///< Routine to immediately close the port
261 PFN_PORT_CLOSE_START
* pfnCloseStart
; ///< Routine to start closing the port
264 // Protocol specific management data
266 PORT_STATE State
; ///< State of the port
267 UINTN DebugFlags
; ///< Debug flags used to close the port
268 BOOLEAN bCloseNow
; ///< TRUE = Close the port immediately
271 DT_TCP4_CONTEXT Tcp4
; ///< TCPv4 management data
272 DT_UDP4_CONTEXT Udp4
; ///< UDPv4 management data
277 Socket control structure
279 The driver uses this structure to manage the socket.
281 typedef struct _DT_SOCKET
{
282 UINTN Signature
; ///< Structure identification
287 EFI_SOCKET_PROTOCOL SocketProtocol
; ///< Socket protocol declaration
292 DT_SOCKET
* pNext
; ///< Next socket in the list of sockets
293 int errno
; ///< Error information for this socket
294 EFI_STATUS Status
; ///< Asyncronous error information for this socket
295 SOCKET_STATE State
; ///< Socket state
300 int Domain
; ///< Specifies family of protocols
301 int Type
; ///< Specifies how to make network connection
302 int Protocol
; ///< Specifies lower layer protocol to use
303 BOOLEAN bConfigured
; ///< Set after the socket is configured
305 BOOLEAN bRxDisable
; ///< Receive disabled via shutdown
306 size_t RxBytes
; ///< Total Rx bytes
307 size_t RxOobBytes
; ///< Urgent Rx bytes
308 EFI_STATUS RxError
; ///< Error during receive
310 BOOLEAN bTxDisable
; ///< Transmit disabled via shutdown
311 size_t TxBytes
; ///< Normal Tx bytes
312 size_t TxOobBytes
; ///< Urgent Tx bytes
313 EFI_STATUS TxError
; ///< Error during transmit
316 // Pending connection data
318 BOOLEAN bConnected
; ///< Set when connected, cleared by poll
319 EFI_STATUS ConnectStatus
; ///< Connection status
320 UINTN MaxFifoDepth
; ///< Maximum FIFO depth
321 UINTN FifoDepth
; ///< Number of sockets in the FIFO
322 DT_SOCKET
* pFifoHead
; ///< Head of the FIFO
323 DT_SOCKET
* pFifoTail
; ///< Tail of the FIFO
324 DT_SOCKET
* pNextConnection
; ///< Link in the FIFO
329 DT_PORT
* pPortList
; ///< List of ports managed by this socket
330 EFI_EVENT WaitAccept
; ///< Wait for accept completion
333 // Receive data management
335 UINT32 MaxRxBuf
; ///< Maximum size of the receive buffer
336 struct timeval RxTimeout
; ///< Receive timeout
337 DT_PACKET
* pRxFree
; ///< Free packet list
338 DT_PACKET
* pRxOobPacketListHead
; ///< Urgent data list head
339 DT_PACKET
* pRxOobPacketListTail
; ///< Urgent data list tail
340 DT_PACKET
* pRxPacketListHead
; ///< Normal data list head
341 DT_PACKET
* pRxPacketListTail
; ///< Normal data list tail
344 // Transmit data management
346 UINT32 MaxTxBuf
; ///< Maximum size of the transmit buffer
347 DT_PACKET
* pTxOobPacketListHead
; ///< Urgent data list head
348 DT_PACKET
* pTxOobPacketListTail
; ///< Urgent data list tail
349 DT_PACKET
* pTxPacketListHead
; ///< Normal data list head
350 DT_PACKET
* pTxPacketListTail
; ///< Normal data list tail
353 #define SOCKET_FROM_PROTOCOL(a) CR(a, DT_SOCKET, SocketProtocol, SOCKET_SIGNATURE) ///< Locate DT_SOCKET from protocol
356 Socket layer control structure
358 The driver uses this structure to manage the driver.
361 UINTN Signature
; ///< Structure identification
364 // Service binding interface
366 EFI_SERVICE_BINDING_PROTOCOL ServiceBinding
;///< Driver's binding
371 EFI_HANDLE ImageHandle
; ///< Image handle
376 DT_SERVICE
* pTcp4List
; ///< List of Tcp4 services
377 DT_SERVICE
* pUdp4List
; ///< List of Udp4 services
382 DT_SOCKET
* pSocketList
; ///< List of sockets
387 UINTN TcpCloseMax4
; ///< Number of entries in the ring buffer
388 UINTN TcpCloseIn4
; ///< Offset into TcpClose4 ring buffer - Close request
389 UINTN TcpCloseOut4
; ///< Offset into TcpClose4 ring buffer - Close operation
390 EFI_TCP4_PROTOCOL
** ppTcpClose4
; ///< Ring buffer to close TCP4 ports
393 #define LAYER_FROM_SERVICE(a) CR(a, DT_LAYER, ServiceBinding, LAYER_SIGNATURE) ///< Locate DT_LAYER from service binding
395 //------------------------------------------------------------------------------
397 //------------------------------------------------------------------------------
399 extern DT_LAYER mEslLayer
;
401 //------------------------------------------------------------------------------
402 // Socket Support Routines
403 //------------------------------------------------------------------------------
406 Allocate and initialize a DT_SOCKET structure.
408 The ::SocketAllocate() function allocates a DT_SOCKET structure
409 and installs a protocol on ChildHandle. If pChildHandle is a
410 pointer to NULL, then a new handle is created and returned in
411 pChildHandle. If pChildHandle is not a pointer to NULL, then
412 the protocol installs on the existing pChildHandle.
414 @param [in, out] pChildHandle Pointer to the handle of the child to create.
415 If it is NULL, then a new handle is created.
416 If it is a pointer to an existing UEFI handle,
417 then the protocol is added to the existing UEFI
419 @param [in] DebugFlags Flags for debug messages
420 @param [in, out] ppSocket The buffer to receive the DT_SOCKET structure address.
422 @retval EFI_SUCCESS The protocol was added to ChildHandle.
423 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
424 @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
426 @retval other The child handle was not created
432 IN OUT EFI_HANDLE
* pChildHandle
,
434 IN OUT DT_SOCKET
** ppSocket
438 Allocate a packet for a receive or transmit operation
440 @param [in] ppPacket Address to receive the DT_PACKET structure
441 @param [in] LengthInBytes Length of the packet structure
442 @param [in] DebugFlags Flags for debug messages
444 @retval EFI_SUCCESS - The packet was allocated successfully
448 EslSocketPacketAllocate (
449 IN DT_PACKET
** ppPacket
,
450 IN
size_t LengthInBytes
,
455 Free a packet used for receive or transmit operation
457 @param [in] pPacket Address of the DT_PACKET structure
458 @param [in] DebugFlags Flags for debug messages
460 @retval EFI_SUCCESS - The packet was allocated successfully
464 EslSocketPacketFree (
465 IN DT_PACKET
* pPacket
,
469 //------------------------------------------------------------------------------
471 //------------------------------------------------------------------------------
474 Accept a network connection.
476 The SocketAccept routine waits for a network connection to the socket.
477 It is able to return the remote network address to the caller if
480 @param [in] pSocket Address of the socket structure.
482 @param [in] pSockAddr Address of a buffer to receive the remote
485 @param [in, out] pSockAddrLength Length in bytes of the address buffer.
486 On output specifies the length of the
487 remote network address.
489 @retval EFI_SUCCESS Remote address is available
490 @retval Others Remote address not available
495 IN DT_SOCKET
* pSocket
,
496 IN
struct sockaddr
* pSockAddr
,
497 IN OUT socklen_t
* pSockAddrLength
501 Bind a name to a socket.
503 The ::TcpBind4 routine connects a name to A TCP4 stack on the local machine.
505 @param [in] pSocket Address of the socket structure.
507 @param [in] pSockAddr Address of a sockaddr structure that contains the
508 connection point on the local machine. An IPv4 address
509 of INADDR_ANY specifies that the connection is made to
510 all of the network stacks on the platform. Specifying a
511 specific IPv4 address restricts the connection to the
512 network stack supporting that address. Specifying zero
513 for the port causes the network layer to assign a port
514 number from the dynamic range. Specifying a specific
515 port number causes the network layer to use that port.
517 @param [in] SockAddrLen Specifies the length in bytes of the sockaddr structure.
519 @retval EFI_SUCCESS - Socket successfully created
524 IN DT_SOCKET
* pSocket
,
525 IN
const struct sockaddr
* pSockAddr
,
526 IN socklen_t SockAddrLength
530 Poll for completion of the connection attempt.
532 The ::TcpConnectPoll4 routine determines when the connection
533 attempt transitions from being in process to being complete.
535 @param [in] pSocket Address of the socket structure.
537 @retval EFI_SUCCESS The connection was successfully established.
538 @retval EFI_NOT_READY The connection is in progress, call this routine again.
539 @retval Others The connection attempt failed.
544 IN DT_SOCKET
* pSocket
548 Connect to a remote system via the network.
550 The ::TcpConnectStart4= routine starts the connection processing
553 @param [in] pSocket Address of the socket structure.
555 @param [in] pSockAddr Network address of the remote system.
557 @param [in] SockAddrLength Length in bytes of the network address.
559 @retval EFI_SUCCESS The connection was successfully established.
560 @retval EFI_NOT_READY The connection is in progress, call this routine again.
561 @retval Others The connection attempt failed.
565 EslTcpConnectStart4 (
566 IN DT_SOCKET
* pSocket
,
567 IN
const struct sockaddr
* pSockAddr
,
568 IN socklen_t SockAddrLength
572 Initialize the TCP4 service.
574 This routine initializes the TCP4 service after its service binding
575 protocol was located on a controller.
577 @param [in] pService DT_SERVICE structure address
579 @retval EFI_SUCCESS The service was properly initialized
580 @retval other A failure occurred during the service initialization
586 IN DT_SERVICE
* pService
590 Get the local socket address
592 @param [in] pSocket Address of the socket structure.
594 @param [out] pAddress Network address to receive the local system address
596 @param [in,out] pAddressLength Length of the local network address structure
598 @retval EFI_SUCCESS - Address available
599 @retval Other - Failed to get the address
603 EslTcpGetLocalAddress4 (
604 IN DT_SOCKET
* pSocket
,
605 OUT
struct sockaddr
* pAddress
,
606 IN OUT socklen_t
* pAddressLength
610 Get the remote socket address
612 @param [in] pSocket Address of the socket structure.
614 @param [out] pAddress Network address to receive the remote system address
616 @param [in,out] pAddressLength Length of the remote network address structure
618 @retval EFI_SUCCESS - Address available
619 @retval Other - Failed to get the address
623 EslTcpGetRemoteAddress4 (
624 IN DT_SOCKET
* pSocket
,
625 OUT
struct sockaddr
* pAddress
,
626 IN OUT socklen_t
* pAddressLength
630 Establish the known port to listen for network connections.
632 The ::Tcp4Listen routine places the port into a state that enables connection
633 attempts. Connections are placed into FIFO order in a queue to be serviced
634 by the application. The application calls the ::Tcp4Accept routine to remove
635 the next connection from the queue and get the associated socket. The
636 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html">POSIX</a>
637 documentation for the listen routine is available online for reference.
639 @param [in] pSocket Address of the socket structure.
641 @retval EFI_SUCCESS - Socket successfully created
642 @retval Other - Failed to enable the socket for listen
647 IN DT_SOCKET
* pSocket
651 Process the connection attempt
653 A system has initiated a connection attempt with a socket in the
654 listen state. Attempt to complete the connection.
656 @param Event The listeen completion event
658 @param pPort The DT_PORT structure address
662 EslTcpListenComplete4 (
668 Allocate and initialize a DT_PORT structure.
670 @param [in] pSocket Address of the socket structure.
671 @param [in] pService Address of the DT_SERVICE structure.
672 @param [in] ChildHandle TCP4 child handle
673 @param [in] pIpAddress Buffer containing IP4 network address of the local host
674 @param [in] PortNumber Tcp4 port number
675 @param [in] DebugFlags Flags for debug messages
676 @param [out] ppPort Buffer to receive new DT_PORT structure address
678 @retval EFI_SUCCESS - Socket successfully created
682 EslTcpPortAllocate4 (
683 IN DT_SOCKET
* pSocket
,
684 IN DT_SERVICE
* pService
,
685 IN EFI_HANDLE ChildHandle
,
686 IN CONST UINT8
*pIpAddress
,
687 IN UINT16 PortNumber
,
689 OUT DT_PORT
** ppPort
695 This routine releases the resources allocated by
696 ::TcpPortAllocate4().
698 @param [in] pPort Address of the port structure.
700 @retval EFI_SUCCESS The port is closed
701 @retval other Port close error
710 Process the port close completion
712 @param Event The close completion event
714 @param pPort The DT_PORT structure address
718 EslTcpPortCloseComplete4 (
726 Continue the close operation after the receive is complete.
728 @param [in] pPort Address of the port structure.
730 @retval EFI_SUCCESS The port is closed
731 @retval EFI_NOT_READY The port is still closing
732 @retval EFI_ALREADY_STARTED Error, the port is in the wrong state,
733 most likely the routine was called already.
737 EslTcpPortCloseRxDone4 (
742 Start the close operation on a TCP4 port.
744 @param [in] pPort Address of the port structure.
745 @param [in] bAbort Set TRUE to abort active transfers
746 @param [in] DebugFlags Flags for debug messages
750 EslTcpPortCloseStart4 (
759 Continue the close operation after the transmission is complete.
761 @param [in] pPort Address of the port structure.
763 @retval EFI_NOT_READY The port is still closing
764 @retval EFI_ALREADY_STARTED Error, the port is in the wrong state,
765 most likely the routine was called already.
769 EslTcpPortCloseTxDone4 (
774 Receive data from a network connection.
777 @param [in] pSocket Address of a DT_SOCKET structure
779 @param [in] Flags Message control flags
781 @param [in] BufferLength Length of the the buffer
783 @param [in] pBuffer Address of a buffer to receive the data.
785 @param [in] pDataLength Number of received data bytes in the buffer.
787 @param [out] pAddress Network address to receive the remote system address
789 @param [in,out] pAddressLength Length of the remote network address structure
791 @retval EFI_SUCCESS - Socket data successfully received
796 IN DT_SOCKET
* pSocket
,
798 IN
size_t BufferLength
,
800 OUT
size_t * pDataLength
,
801 OUT
struct sockaddr
* pAddress
,
802 IN OUT socklen_t
* pAddressLength
806 Cancel the receive operations
808 @param [in] pSocket Address of a DT_SOCKET structure
810 @retval EFI_SUCCESS - The cancel was successful
815 IN DT_SOCKET
* pSocket
819 Process the receive completion
821 Buffer the data that was just received.
823 @param Event The receive completion event
825 @param pPort The DT_PORT structure address
835 Start a receive operation
837 @param [in] pPort Address of the DT_PORT structure.
846 Shutdown the TCP4 service.
848 This routine undoes the work performed by ::TcpInitialize4.
850 @param [in] pService DT_SERVICE structure address
856 IN DT_SERVICE
* pService
860 Determine if the socket is configured.
863 @param [in] pSocket Address of a DT_SOCKET structure
865 @retval EFI_SUCCESS - The port is connected
866 @retval EFI_NOT_STARTED - The port is not connected
870 EslTcpSocketIsConfigured4 (
871 IN DT_SOCKET
* pSocket
875 Buffer data for transmission over a network connection.
877 This routine is called by the socket layer API to buffer
878 data for transmission. When necessary, this routine will
879 start the transmit engine that performs the data transmission
880 on the network connection.
882 @param [in] pSocket Address of a DT_SOCKET structure
884 @param [in] Flags Message control flags
886 @param [in] BufferLength Length of the the buffer
888 @param [in] pBuffer Address of a buffer to receive the data.
890 @param [in] pDataLength Number of received data bytes in the buffer.
892 @retval EFI_SUCCESS - Socket data successfully buffered
897 IN DT_SOCKET
* pSocket
,
899 IN
size_t BufferLength
,
900 IN CONST UINT8
* pBuffer
,
901 OUT
size_t * pDataLength
905 Process the normal data transmit completion
907 @param Event The normal transmit completion event
909 @param pPort The DT_PORT structure address
919 Process the urgent data transmit completion
921 @param Event The urgent transmit completion event
923 @param pPort The DT_PORT structure address
927 EslTcpTxOobComplete4 (
933 Transmit data using a network connection.
936 @param [in] pPort Address of a DT_PORT structure
937 @param [in] pToken Address of either the OOB or normal transmit token
938 @param [in] ppQueueHead Transmit queue head address
939 @param [in] ppQueueTail Transmit queue tail address
940 @param [in] ppPacket Active transmit packet address
946 IN EFI_TCP4_IO_TOKEN
* pToken
,
947 IN DT_PACKET
** ppQueueHead
,
948 IN DT_PACKET
** ppQueueTail
,
949 IN DT_PACKET
** ppPacket
952 //------------------------------------------------------------------------------
954 //------------------------------------------------------------------------------
957 Bind a name to a socket.
959 The ::UdpBind4 routine connects a name to a UDP4 stack on the local machine.
961 @param [in] pSocket Address of the socket structure.
963 @param [in] pSockAddr Address of a sockaddr structure that contains the
964 connection point on the local machine. An IPv4 address
965 of INADDR_ANY specifies that the connection is made to
966 all of the network stacks on the platform. Specifying a
967 specific IPv4 address restricts the connection to the
968 network stack supporting that address. Specifying zero
969 for the port causes the network layer to assign a port
970 number from the dynamic range. Specifying a specific
971 port number causes the network layer to use that port.
973 @param [in] SockAddrLen Specifies the length in bytes of the sockaddr structure.
975 @retval EFI_SUCCESS - Socket successfully created
980 IN DT_SOCKET
* pSocket
,
981 IN
const struct sockaddr
* pSockAddr
,
982 IN socklen_t SockAddrLength
986 Initialize the UDP4 service.
988 This routine initializes the UDP4 service after its service binding
989 protocol was located on a controller.
991 @param [in] pService DT_SERVICE structure address
993 @retval EFI_SUCCESS The service was properly initialized
994 @retval other A failure occurred during the service initialization
1000 IN DT_SERVICE
* pService
1004 Allocate and initialize a DT_PORT structure.
1006 @param [in] pSocket Address of the socket structure.
1007 @param [in] pService Address of the DT_SERVICE structure.
1008 @param [in] ChildHandle Udp4 child handle
1009 @param [in] pIpAddress Buffer containing IP4 network address of the local host
1010 @param [in] PortNumber Udp4 port number
1011 @param [in] DebugFlags Flags for debug messages
1012 @param [out] ppPort Buffer to receive new DT_PORT structure address
1014 @retval EFI_SUCCESS - Socket successfully created
1018 EslUdpPortAllocate4 (
1019 IN DT_SOCKET
* pSocket
,
1020 IN DT_SERVICE
* pService
,
1021 IN EFI_HANDLE ChildHandle
,
1022 IN CONST UINT8
* pIpAddress
,
1023 IN UINT16 PortNumber
,
1024 IN UINTN DebugFlags
,
1025 OUT DT_PORT
** ppPort
1031 This routine releases the resources allocated by
1032 ::UdpPortAllocate4().
1034 @param [in] pPort Address of the port structure.
1036 @retval EFI_SUCCESS The port is closed
1037 @retval other Port close error
1046 Start the close operation on a UDP4 port, state 1.
1048 Closing a port goes through the following states:
1049 1. Port close starting - Mark the port as closing and wait for transmission to complete
1050 2. Port TX close done - Transmissions complete, close the port and abort the receives
1051 3. Port RX close done - Receive operations complete, close the port
1052 4. Port closed - Release the port resources
1054 @param [in] pPort Address of the port structure.
1055 @param [in] bCloseNow Set TRUE to abort active transfers
1056 @param [in] DebugFlags Flags for debug messages
1058 @retval EFI_SUCCESS The port is closed, not normally returned
1059 @retval EFI_NOT_READY The port has started the closing process
1060 @retval EFI_ALREADY_STARTED Error, the port is in the wrong state,
1061 most likely the routine was called already.
1065 EslUdpPortCloseStart4 (
1067 IN BOOLEAN bCloseNow
,
1074 Continue the close operation after the transmission is complete.
1076 @param [in] pPort Address of the port structure.
1078 @retval EFI_SUCCESS The port is closed, not normally returned
1079 @retval EFI_NOT_READY The port is still closing
1080 @retval EFI_ALREADY_STARTED Error, the port is in the wrong state,
1081 most likely the routine was called already.
1085 EslUdpPortCloseTxDone4 (
1090 Connect to a remote system via the network.
1092 The ::UdpConnectStart4= routine sets the remote address for the connection.
1094 @param [in] pSocket Address of the socket structure.
1096 @param [in] pSockAddr Network address of the remote system.
1098 @param [in] SockAddrLength Length in bytes of the network address.
1100 @retval EFI_SUCCESS The connection was successfully established.
1101 @retval EFI_NOT_READY The connection is in progress, call this routine again.
1102 @retval Others The connection attempt failed.
1107 IN DT_SOCKET
* pSocket
,
1108 IN
const struct sockaddr
* pSockAddr
,
1109 IN socklen_t SockAddrLength
1113 Get the local socket address
1115 @param [in] pSocket Address of the socket structure.
1117 @param [out] pAddress Network address to receive the local system address
1119 @param [in,out] pAddressLength Length of the local network address structure
1121 @retval EFI_SUCCESS - Address available
1122 @retval Other - Failed to get the address
1126 EslUdpGetLocalAddress4 (
1127 IN DT_SOCKET
* pSocket
,
1128 OUT
struct sockaddr
* pAddress
,
1129 IN OUT socklen_t
* pAddressLength
1133 Get the remote socket address
1135 @param [in] pSocket Address of the socket structure.
1137 @param [out] pAddress Network address to receive the remote system address
1139 @param [in,out] pAddressLength Length of the remote network address structure
1141 @retval EFI_SUCCESS - Address available
1142 @retval Other - Failed to get the address
1146 EslUdpGetRemoteAddress4 (
1147 IN DT_SOCKET
* pSocket
,
1148 OUT
struct sockaddr
* pAddress
,
1149 IN OUT socklen_t
* pAddressLength
1153 Receive data from a network connection.
1155 To minimize the number of buffer copies, the ::UdpRxComplete4
1156 routine queues the UDP4 driver's buffer to a list of datagrams
1157 waiting to be received. The socket driver holds on to the
1158 buffers from the UDP4 driver until the application layer requests
1159 the data or the socket is closed.
1161 The application calls this routine in the socket layer to
1162 receive datagrams from one or more remote systems. This routine
1163 removes the next available datagram from the list of datagrams
1164 and copies the data from the UDP4 driver's buffer into the
1165 application's buffer. The UDP4 driver's buffer is then returned.
1167 @param [in] pSocket Address of a DT_SOCKET structure
1169 @param [in] Flags Message control flags
1171 @param [in] BufferLength Length of the the buffer
1173 @param [in] pBuffer Address of a buffer to receive the data.
1175 @param [in] pDataLength Number of received data bytes in the buffer.
1177 @param [out] pAddress Network address to receive the remote system address
1179 @param [in,out] pAddressLength Length of the remote network address structure
1181 @retval EFI_SUCCESS - Socket data successfully received
1186 IN DT_SOCKET
* pSocket
,
1188 IN
size_t BufferLength
,
1190 OUT
size_t * pDataLength
,
1191 OUT
struct sockaddr
* pAddress
,
1192 IN OUT socklen_t
* pAddressLength
1196 Cancel the receive operations
1198 @param [in] pSocket Address of a DT_SOCKET structure
1200 @retval EFI_SUCCESS - The cancel was successful
1205 IN DT_SOCKET
* pSocket
1209 Process the receive completion
1211 Keep the UDP4 driver's buffer and append it to the list of
1212 datagrams for the application to receive. The UDP4 driver's
1213 buffer will be returned by either ::UdpReceive4 or
1214 ::UdpPortCloseTxDone4.
1216 @param Event The receive completion event
1218 @param pPort The DT_PORT structure address
1228 Start a receive operation
1230 @param [in] pPort Address of the DT_PORT structure.
1239 Determine if the socket is configured.
1242 @param [in] pSocket Address of a DT_SOCKET structure
1244 @retval EFI_SUCCESS - The port is connected
1245 @retval EFI_NOT_STARTED - The port is not connected
1249 EslUdpSocketIsConfigured4 (
1250 IN DT_SOCKET
* pSocket
1254 Process the transmit completion
1256 @param Event The normal transmit completion event
1258 @param pPort The DT_PORT structure address
1268 Shutdown the UDP4 service.
1270 This routine undoes the work performed by ::UdpInitialize4.
1272 @param [in] pService DT_SERVICE structure address
1278 IN DT_SERVICE
* pService
1282 Buffer data for transmission over a network connection.
1284 This routine is called by the socket layer API to buffer
1285 data for transmission. The data is copied into a local buffer
1286 freeing the application buffer for reuse upon return. When
1287 necessary, this routine will start the transmit engine that
1288 performs the data transmission on the network connection. The
1289 transmit engine transmits the data a packet at a time over the
1292 Transmission errors are returned during the next transmission or
1293 during the close operation. Only buffering errors are returned
1294 during the current transmission attempt.
1296 @param [in] pSocket Address of a DT_SOCKET structure
1298 @param [in] Flags Message control flags
1300 @param [in] BufferLength Length of the the buffer
1302 @param [in] pBuffer Address of a buffer to receive the data.
1304 @param [in] pDataLength Number of received data bytes in the buffer.
1306 @param [in] pAddress Network address of the remote system address
1308 @param [in] AddressLength Length of the remote network address structure
1310 @retval EFI_SUCCESS - Socket data successfully buffered
1315 IN DT_SOCKET
* pSocket
,
1317 IN
size_t BufferLength
,
1318 IN CONST UINT8
* pBuffer
,
1319 OUT
size_t * pDataLength
,
1320 IN
const struct sockaddr
* pAddress
,
1321 IN socklen_t AddressLength
1325 Transmit data using a network connection.
1327 @param [in] pPort Address of a DT_PORT structure
1335 //------------------------------------------------------------------------------
1337 #endif // _SOCKET_H_