2 Definitions for the EFI Socket protocol.
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.php
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.
15 #ifndef _EFI_SOCKET_H_
16 #define _EFI_SOCKET_H_
21 #include <netinet/in.h>
24 #include <sys/socket.h>
26 //------------------------------------------------------------------------------
28 //------------------------------------------------------------------------------
30 typedef struct _EFI_SOCKET_PROTOCOL EFI_SOCKET_PROTOCOL
;
33 Constructor/Destructor
35 @retval EFI_SUCCESS The operation was successful
40 (* PFN_ESL_xSTRUCTOR
) (
44 //------------------------------------------------------------------------------
46 //------------------------------------------------------------------------------
48 extern PFN_ESL_xSTRUCTOR mpfnEslConstructor
;
49 extern PFN_ESL_xSTRUCTOR mpfnEslDestructor
;
51 extern EFI_GUID gEfiSocketProtocolGuid
;
52 extern EFI_GUID gEfiSocketServiceBindingProtocolGuid
;
54 //------------------------------------------------------------------------------
56 //------------------------------------------------------------------------------
59 Accept a network connection.
61 The SocketAccept routine waits for a network connection to the socket.
62 It is able to return the remote network address to the caller if
65 @param [in] pSocketProtocol Address of the socket protocol structure.
67 @param [in] pSockAddr Address of a buffer to receive the remote
70 @param [in, out] pSockAddrLength Length in bytes of the address buffer.
71 On output specifies the length of the
72 remote network address.
74 @param [out] ppSocketProtocol Address of a buffer to receive the socket protocol
75 instance associated with the new socket.
77 @param [out] pErrno Address to receive the errno value upon completion.
79 @retval EFI_SUCCESS New connection successfully created
80 @retval EFI_NOT_READY No connection is available
86 IN EFI_SOCKET_PROTOCOL
* pSocketProtocol
,
87 IN
struct sockaddr
* pSockAddr
,
88 IN OUT socklen_t
* pSockAddrLength
,
89 IN EFI_SOCKET_PROTOCOL
** ppSocketProtocol
,
94 Bind a name to a socket.
96 The ::SocketBind routine connects a name to a socket on the local machine. The
97 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html">POSIX</a>
98 documentation for the bind routine is available online for reference.
100 @param [in] pSocketProtocol Address of the socket protocol structure.
102 @param [in] pSockAddr Address of a sockaddr structure that contains the
103 connection point on the local machine. An IPv4 address
104 of INADDR_ANY specifies that the connection is made to
105 all of the network stacks on the platform. Specifying a
106 specific IPv4 address restricts the connection to the
107 network stack supporting that address. Specifying zero
108 for the port causes the network layer to assign a port
109 number from the dynamic range. Specifying a specific
110 port number causes the network layer to use that port.
112 @param [in] SockAddrLen Specifies the length in bytes of the sockaddr structure.
114 @param [out] pErrno Address to receive the errno value upon completion.
116 @retval EFI_SUCCESS - Socket successfully created
122 IN EFI_SOCKET_PROTOCOL
* pSocketProtocol
,
123 IN
const struct sockaddr
* pSockAddr
,
124 IN socklen_t SockAddrLength
,
129 Determine if the socket is closed
131 Reverses the operations of the ::SocketAllocate() routine.
133 @param [in] pSocketProtocol Address of the socket protocol structure.
134 @param [out] pErrno Address to receive the errno value upon completion.
136 @retval EFI_SUCCESS Socket successfully closed
137 @retval EFI_NOT_READY Close still in progress
138 @retval EFI_ALREADY Close operation already in progress
139 @retval Other Failed to close the socket
145 IN EFI_SOCKET_PROTOCOL
* pSocketProtocol
,
150 Start the close operation on the socket
152 Start closing the socket by closing all of the ports. Upon
153 completion, the ::pfnClosePoll() routine finishes closing the
156 @param [in] pSocketProtocol Address of the socket protocol structure.
157 @param [in] bCloseNow Boolean to control close behavior
158 @param [out] pErrno Address to receive the errno value upon completion.
160 @retval EFI_SUCCESS Socket successfully closed
161 @retval EFI_NOT_READY Close still in progress
162 @retval EFI_ALREADY Close operation already in progress
163 @retval Other Failed to close the socket
168 (* PFN_CLOSE_START
) (
169 IN EFI_SOCKET_PROTOCOL
* pSocketProtocol
,
170 IN BOOLEAN bCloseNow
,
175 Connect to a remote system via the network.
177 The ::Connect routine attempts to establish a connection to a
178 socket on the local or remote system using the specified address.
180 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html">POSIX</a>
181 documentation is available online.
183 There are three states associated with a connection:
185 <li>Not connected</li>
186 <li>Connection in progress</li>
189 In the "Not connected" state, calls to ::connect start the connection
190 processing and update the state to "Connection in progress". During
191 the "Connection in progress" state, connect polls for connection completion
192 and moves the state to "Connected" after the connection is established.
193 Note that these states are only visible when the file descriptor is marked
194 with O_NONBLOCK. Also, the POLL_WRITE bit is set when the connection
195 completes and may be used by poll or select as an indicator to call
198 @param [in] pSocketProtocol Address of the socket protocol structure.
200 @param [in] pSockAddr Network address of the remote system.
202 @param [in] SockAddrLength Length in bytes of the network address.
204 @param [out] pErrno Address to receive the errno value upon completion.
206 @retval EFI_SUCCESS The connection was successfully established.
207 @retval EFI_NOT_READY The connection is in progress, call this routine again.
208 @retval Others The connection attempt failed.
214 IN EFI_SOCKET_PROTOCOL
* pSocketProtocol
,
215 IN
const struct sockaddr
* pSockAddr
,
216 IN socklen_t SockAddrLength
,
221 Get the local address.
223 @param [in] pSocketProtocol Address of the socket protocol structure.
225 @param [out] pAddress Network address to receive the local system address
227 @param [in,out] pAddressLength Length of the local network address structure
229 @param [out] pErrno Address to receive the errno value upon completion.
231 @retval EFI_SUCCESS - Local address successfully returned
237 IN EFI_SOCKET_PROTOCOL
* pSocketProtocol
,
238 OUT
struct sockaddr
* pAddress
,
239 IN OUT socklen_t
* pAddressLength
,
244 Get the peer address.
246 @param [in] pSocketProtocol Address of the socket protocol structure.
248 @param [out] pAddress Network address to receive the remote system address
250 @param [in,out] pAddressLength Length of the remote network address structure
252 @param [out] pErrno Address to receive the errno value upon completion.
254 @retval EFI_SUCCESS - Remote address successfully returned
260 IN EFI_SOCKET_PROTOCOL
* pSocketProtocol
,
261 OUT
struct sockaddr
* pAddress
,
262 IN OUT socklen_t
* pAddressLength
,
267 Establish the known port to listen for network connections.
269 The ::SocketAisten routine places the port into a state that enables connection
270 attempts. Connections are placed into FIFO order in a queue to be serviced
271 by the application. The application calls the ::SocketAccept routine to remove
272 the next connection from the queue and get the associated socket. The
273 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html">POSIX</a>
274 documentation for the bind routine is available online for reference.
276 @param [in] pSocketProtocol Address of the socket protocol structure.
278 @param [in] Backlog Backlog specifies the maximum FIFO depth for
279 the connections waiting for the application
280 to call accept. Connection attempts received
281 while the queue is full are refused.
283 @param [out] pErrno Address to receive the errno value upon completion.
285 @retval EFI_SUCCESS - Socket successfully created
286 @retval Other - Failed to enable the socket for listen
292 IN EFI_SOCKET_PROTOCOL
* pSocketProtocol
,
298 Get the socket options
300 Retrieve the socket options one at a time by name. The
301 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html">POSIX</a>
302 documentation is available online.
304 @param [in] pSocketProtocol Address of the socket protocol structure.
305 @param [in] level Option protocol level
306 @param [in] OptionName Name of the option
307 @param [out] pOptionValue Buffer to receive the option value
308 @param [in,out] pOptionLength Length of the buffer in bytes,
309 upon return length of the option value in bytes
310 @param [out] pErrno Address to receive the errno value upon completion.
312 @retval EFI_SUCCESS - Socket data successfully received
318 IN EFI_SOCKET_PROTOCOL
* pSocketProtocol
,
321 OUT
void * __restrict pOptionValue
,
322 IN OUT socklen_t
* __restrict pOptionLength
,
327 Set the socket options
329 Adjust the socket options one at a time by name. The
330 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html">POSIX</a>
331 documentation is available online.
333 @param [in] pSocketProtocol Address of the socket protocol structure.
334 @param [in] level Option protocol level
335 @param [in] OptionName Name of the option
336 @param [in] pOptionValue Buffer containing the option value
337 @param [in] OptionLength Length of the buffer in bytes
338 @param [out] pErrno Address to receive the errno value upon completion.
340 @retval EFI_SUCCESS - Socket data successfully received
346 IN EFI_SOCKET_PROTOCOL
* pSocketProtocol
,
349 IN CONST
void * pOptionValue
,
350 IN socklen_t OptionLength
,
355 Poll a socket for pending activity.
357 The SocketPoll routine checks a socket for pending activity associated
358 with the event mask. Activity is returned in the detected event buffer.
360 @param [in] pSocketProtocol Address of the socket protocol structure.
362 @param [in] Events Events of interest for this socket
364 @param [in] pEvents Address to receive the detected events
366 @param [out] pErrno Address to receive the errno value upon completion.
368 @retval EFI_SUCCESS - Socket successfully polled
369 @retval EFI_INVALID_PARAMETER - When pEvents is NULL
375 IN EFI_SOCKET_PROTOCOL
* pSocketProtocol
,
382 Receive data from a network connection.
384 The ::recv routine waits for receive data from a remote network
386 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html">POSIX</a>
387 documentation is available online.
389 @param [in] pSocketProtocol Address of the socket protocol structure.
391 @param [in] Flags Message control flags
393 @param [in] BufferLength Length of the the buffer
395 @param [in] pBuffer Address of a buffer to receive the data.
397 @param [in] pDataLength Number of received data bytes in the buffer.
399 @param [out] pAddress Network address to receive the remote system address
401 @param [in,out] pAddressLength Length of the remote network address structure
403 @param [out] pErrno Address to receive the errno value upon completion.
405 @retval EFI_SUCCESS - Socket data successfully received
411 IN EFI_SOCKET_PROTOCOL
* pSocketProtocol
,
413 IN
size_t BufferLength
,
415 OUT
size_t * pDataLength
,
416 OUT
struct sockaddr
* pAddress
,
417 IN OUT socklen_t
* pAddressLength
,
422 Send data using a network connection.
424 The SocketTransmit routine queues the data for transmission to the
425 remote network connection.
427 @param [in] pSocketProtocol Address of the socket protocol structure.
429 @param [in] Flags Message control flags
431 @param [in] BufferLength Length of the the buffer
433 @param [in] pBuffer Address of a buffer containing the data to send
435 @param [in] pDataLength Address to receive the number of data bytes sent
437 @param [in] pAddress Network address of the remote system address
439 @param [in] AddressLength Length of the remote network address structure
441 @param [out] pErrno Address to receive the errno value upon completion.
443 @retval EFI_SUCCESS - Socket data successfully queued for transmission
449 IN EFI_SOCKET_PROTOCOL
* pSocketProtocol
,
451 IN
size_t BufferLength
,
452 IN CONST UINT8
* pBuffer
,
453 OUT
size_t * pDataLength
,
454 IN
const struct sockaddr
* pAddress
,
455 IN socklen_t AddressLength
,
460 Shutdown the socket receive and transmit operations
462 The SocketShutdown routine stops the socket receive and transmit
465 @param [in] pSocketProtocol Address of the socket protocol structure.
467 @param [in] How Which operations to stop
469 @param [out] pErrno Address to receive the errno value upon completion.
471 @retval EFI_SUCCESS - Socket operations successfully shutdown
477 IN EFI_SOCKET_PROTOCOL
* pSocketProtocol
,
483 Initialize an endpoint for network communication.
485 The ::Socket routine initializes the communication endpoint by providing
486 the support for the socket library function ::socket. The
487 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html">POSIX</a>
488 documentation for the socket routine is available online for reference.
490 @param [in] pSocketProtocol Address of the socket protocol structure.
492 @param [in] domain Select the family of protocols for the client or server
495 @param [in] type Specifies how to make the network connection. The following values
499 SOCK_STREAM - Connect to TCP, provides a byte stream
500 that is manipluated by read, recv, send and write.
503 SOCK_SEQPACKET - Connect to TCP, provides sequenced packet stream
504 that is manipulated by read, recv, send and write.
507 SOCK_DGRAM - Connect to UDP, provides a datagram service that is
508 manipulated by recvfrom and sendto.
512 @param [in] protocol Specifies the lower layer protocol to use. The following
513 values are supported:
515 <li>IPPROTO_TCP</li> - This value must be combined with SOCK_STREAM.</li>
516 <li>IPPROTO_UDP</li> - This value must be combined with SOCK_DGRAM.</li>
519 @param [out] pErrno Address to receive the errno value upon completion.
521 @retval EFI_SUCCESS - Socket successfully created
522 @retval EFI_INVALID_PARAMETER - Invalid domain value, errno = EAFNOSUPPORT
523 @retval EFI_INVALID_PARAMETER - Invalid type value, errno = EINVAL
524 @retval EFI_INVALID_PARAMETER - Invalid protocol value, errno = EINVAL
530 IN EFI_SOCKET_PROTOCOL
* pSocketProtocol
,
537 //------------------------------------------------------------------------------
539 //------------------------------------------------------------------------------
542 Socket protocol declaration
544 typedef struct _EFI_SOCKET_PROTOCOL
{
545 EFI_HANDLE SocketHandle
; ///< Handle for the socket
546 PFN_ACCEPT pfnAccept
; ///< Accept a network connection
547 PFN_BIND pfnBind
; ///< Bind a local address to the socket
548 PFN_CLOSE_POLL pfnClosePoll
; ///< Determine if the socket is closed
549 PFN_CLOSE_START pfnCloseStart
; ///< Start the close operation
550 PFN_CONNECT pfnConnect
; ///< Connect to a remote system
551 PFN_GET_LOCAL pfnGetLocal
; ///< Get local address
552 PFN_GET_PEER pfnGetPeer
; ///< Get peer address
553 PFN_LISTEN pfnListen
; ///< Enable connection attempts on known port
554 PFN_POLL pfnPoll
; ///< Poll for socket activity
555 PFN_OPTION_GET pfnOptionGet
; ///< Get socket options
556 PFN_OPTION_SET pfnOptionSet
; ///< Set socket options
557 PFN_RECEIVE pfnReceive
; ///< Receive data from a socket
558 PFN_SEND pfnSend
; ///< Transmit data using the socket
559 PFN_SHUTDOWN pfnShutdown
; ///< Shutdown receive and transmit operations
560 PFN_SOCKET pfnSocket
; ///< Initialize the socket
561 } GCC_EFI_SOCKET_PROTOCOL
;
563 //------------------------------------------------------------------------------
564 // Non-blocking routines
565 //------------------------------------------------------------------------------
568 Non blocking version of accept.
572 @param [in] s Socket file descriptor returned from ::socket.
574 @param [in] address Address of a buffer to receive the remote network address.
576 @param [in, out] address_len Address of a buffer containing the Length in bytes
577 of the remote network address buffer. Upon return,
578 contains the length of the remote network address.
580 @returns This routine returns zero if successful and -1 when an error occurs.
581 In the case of an error, errno contains more details.
587 struct sockaddr
* address
,
588 socklen_t
* address_len
592 Connect to the socket driver
594 @param [in] ppSocketProtocol Address to receive the socket protocol address
596 @retval 0 Successfully returned the socket protocol
597 @retval other Value for errno
600 EslServiceGetProtocol (
601 IN EFI_SOCKET_PROTOCOL
** ppSocketProtocol
604 //------------------------------------------------------------------------------
606 #endif // _EFI_SOCKET_H_