]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/Include/Protocol/EfiSocket.h
Fix @return Doxygen commands to be singular instead of plural.
[mirror_edk2.git] / StdLib / Include / Protocol / EfiSocket.h
CommitLineData
d7ce7006 1/** @file\r
2 Definitions for the EFI Socket protocol.\r
3\r
4 Copyright (c) 2011, Intel Corporation\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#ifndef _EFI_SOCKET_H_\r
16#define _EFI_SOCKET_H_\r
17\r
18#include <errno.h>\r
19#include <Uefi.h>\r
20\r
21#include <netinet/in.h>\r
22\r
23#include <sys/poll.h>\r
24#include <sys/socket.h>\r
25\r
26//------------------------------------------------------------------------------\r
27// Data Types\r
28//------------------------------------------------------------------------------\r
29\r
30typedef struct _EFI_SOCKET_PROTOCOL EFI_SOCKET_PROTOCOL;\r
31\r
32/**\r
33 Constructor/Destructor\r
34\r
35 @retval EFI_SUCCESS The operation was successful\r
36\r
37 **/\r
38typedef\r
39EFI_STATUS\r
40(* PFN_ESL_xSTRUCTOR) (\r
41 VOID\r
42 );\r
43\r
44//------------------------------------------------------------------------------\r
45// Data\r
46//------------------------------------------------------------------------------\r
47\r
48extern PFN_ESL_xSTRUCTOR mpfnEslConstructor;\r
49extern PFN_ESL_xSTRUCTOR mpfnEslDestructor;\r
50\r
51extern EFI_GUID gEfiSocketProtocolGuid;\r
52extern EFI_GUID gEfiSocketServiceBindingProtocolGuid;\r
53\r
54//------------------------------------------------------------------------------\r
55// Socket API\r
56//------------------------------------------------------------------------------\r
57\r
58/**\r
59 Accept a network connection.\r
60\r
61 The SocketAccept routine waits for a network connection to the socket.\r
62 It is able to return the remote network address to the caller if\r
63 requested.\r
64\r
65 @param [in] pSocketProtocol Address of the socket protocol structure.\r
66\r
67 @param [in] pSockAddr Address of a buffer to receive the remote\r
68 network address.\r
69\r
70 @param [in, out] pSockAddrLength Length in bytes of the address buffer.\r
71 On output specifies the length of the\r
72 remote network address.\r
73\r
74 @param [out] ppSocketProtocol Address of a buffer to receive the socket protocol\r
75 instance associated with the new socket.\r
76\r
77 @param [out] pErrno Address to receive the errno value upon completion.\r
78\r
79 @retval EFI_SUCCESS New connection successfully created\r
80 @retval EFI_NOT_READY No connection is available\r
81\r
82 **/\r
83typedef\r
84EFI_STATUS\r
85(* PFN_ACCEPT) (\r
86 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
87 IN struct sockaddr * pSockAddr,\r
88 IN OUT socklen_t * pSockAddrLength,\r
89 IN EFI_SOCKET_PROTOCOL ** ppSocketProtocol,\r
90 IN int * pErrno\r
91 );\r
92\r
93/**\r
94 Bind a name to a socket.\r
95\r
96 The ::SocketBind routine connects a name to a socket on the local machine. The\r
97 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html">POSIX</a>\r
98 documentation for the bind routine is available online for reference.\r
99\r
100 @param [in] pSocketProtocol Address of the socket protocol structure.\r
101\r
102 @param [in] pSockAddr Address of a sockaddr structure that contains the\r
103 connection point on the local machine. An IPv4 address\r
104 of INADDR_ANY specifies that the connection is made to\r
105 all of the network stacks on the platform. Specifying a\r
106 specific IPv4 address restricts the connection to the\r
107 network stack supporting that address. Specifying zero\r
108 for the port causes the network layer to assign a port\r
109 number from the dynamic range. Specifying a specific\r
110 port number causes the network layer to use that port.\r
111\r
112 @param [in] SockAddrLen Specifies the length in bytes of the sockaddr structure.\r
113\r
114 @param [out] pErrno Address to receive the errno value upon completion.\r
115\r
116 @retval EFI_SUCCESS - Socket successfully created\r
117\r
118 **/\r
119typedef\r
120EFI_STATUS\r
121(* PFN_BIND) (\r
122 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
123 IN const struct sockaddr * pSockAddr,\r
124 IN socklen_t SockAddrLength,\r
125 OUT int * pErrno\r
126 );\r
127\r
128/**\r
129 Determine if the socket is closed\r
130\r
131 Reverses the operations of the ::SocketAllocate() routine.\r
132\r
133 @param [in] pSocketProtocol Address of the socket protocol structure.\r
134 @param [out] pErrno Address to receive the errno value upon completion.\r
135\r
136 @retval EFI_SUCCESS Socket successfully closed\r
137 @retval EFI_NOT_READY Close still in progress\r
138 @retval EFI_ALREADY Close operation already in progress\r
139 @retval Other Failed to close the socket\r
140\r
141**/\r
142typedef\r
143EFI_STATUS\r
144(* PFN_CLOSE_POLL) (\r
145 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
146 IN int * pErrno\r
147 );\r
148\r
149/**\r
150 Start the close operation on the socket\r
151\r
152 Start closing the socket by closing all of the ports. Upon\r
153 completion, the ::pfnClosePoll() routine finishes closing the\r
154 socket.\r
155\r
156 @param [in] pSocketProtocol Address of the socket protocol structure.\r
157 @param [in] bCloseNow Boolean to control close behavior\r
158 @param [out] pErrno Address to receive the errno value upon completion.\r
159\r
160 @retval EFI_SUCCESS Socket successfully closed\r
161 @retval EFI_NOT_READY Close still in progress\r
162 @retval EFI_ALREADY Close operation already in progress\r
163 @retval Other Failed to close the socket\r
164\r
165**/\r
166typedef\r
167EFI_STATUS\r
168(* PFN_CLOSE_START) (\r
169 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
170 IN BOOLEAN bCloseNow,\r
171 IN int * pErrno\r
172 );\r
173\r
174/**\r
175 Connect to a remote system via the network.\r
176\r
177 The ::Connect routine attempts to establish a connection to a\r
178 socket on the local or remote system using the specified address.\r
179 The\r
180 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html">POSIX</a>\r
181 documentation is available online.\r
182\r
183 There are three states associated with a connection:\r
184 <ul>\r
185 <li>Not connected</li>\r
186 <li>Connection in progress</li>\r
187 <li>Connected</li>\r
188 </ul>\r
189 In the "Not connected" state, calls to ::connect start the connection\r
190 processing and update the state to "Connection in progress". During\r
191 the "Connection in progress" state, connect polls for connection completion\r
192 and moves the state to "Connected" after the connection is established.\r
193 Note that these states are only visible when the file descriptor is marked\r
194 with O_NONBLOCK. Also, the POLL_WRITE bit is set when the connection\r
195 completes and may be used by poll or select as an indicator to call\r
196 connect again.\r
197\r
198 @param [in] pSocketProtocol Address of the socket protocol structure.\r
199\r
200 @param [in] pSockAddr Network address of the remote system.\r
7dc13291 201\r
d7ce7006 202 @param [in] SockAddrLength Length in bytes of the network address.\r
7dc13291 203\r
d7ce7006 204 @param [out] pErrno Address to receive the errno value upon completion.\r
7dc13291 205\r
d7ce7006 206 @retval EFI_SUCCESS The connection was successfully established.\r
207 @retval EFI_NOT_READY The connection is in progress, call this routine again.\r
208 @retval Others The connection attempt failed.\r
209\r
210 **/\r
211typedef\r
212EFI_STATUS\r
213(* PFN_CONNECT) (\r
214 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
215 IN const struct sockaddr * pSockAddr,\r
216 IN socklen_t SockAddrLength,\r
217 IN int * pErrno\r
218 );\r
219\r
220/**\r
221 Get the local address.\r
222\r
223 @param [in] pSocketProtocol Address of the socket protocol structure.\r
7dc13291 224\r
d7ce7006 225 @param [out] pAddress Network address to receive the local system address\r
226\r
227 @param [in,out] pAddressLength Length of the local network address structure\r
228\r
229 @param [out] pErrno Address to receive the errno value upon completion.\r
230\r
231 @retval EFI_SUCCESS - Local address successfully returned\r
232\r
233 **/\r
234typedef\r
235EFI_STATUS\r
236(* PFN_GET_LOCAL) (\r
237 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
238 OUT struct sockaddr * pAddress,\r
239 IN OUT socklen_t * pAddressLength,\r
240 IN int * pErrno\r
241 );\r
242\r
243/**\r
244 Get the peer address.\r
245\r
246 @param [in] pSocketProtocol Address of the socket protocol structure.\r
7dc13291 247\r
d7ce7006 248 @param [out] pAddress Network address to receive the remote system address\r
249\r
250 @param [in,out] pAddressLength Length of the remote network address structure\r
251\r
252 @param [out] pErrno Address to receive the errno value upon completion.\r
253\r
254 @retval EFI_SUCCESS - Remote address successfully returned\r
255\r
256 **/\r
257typedef\r
258EFI_STATUS\r
259(* PFN_GET_PEER) (\r
260 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
261 OUT struct sockaddr * pAddress,\r
262 IN OUT socklen_t * pAddressLength,\r
263 IN int * pErrno\r
264 );\r
265\r
266/**\r
267 Establish the known port to listen for network connections.\r
268\r
269 The ::SocketAisten routine places the port into a state that enables connection\r
270 attempts. Connections are placed into FIFO order in a queue to be serviced\r
271 by the application. The application calls the ::SocketAccept routine to remove\r
272 the next connection from the queue and get the associated socket. The\r
273 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html">POSIX</a>\r
274 documentation for the bind routine is available online for reference.\r
275\r
276 @param [in] pSocketProtocol Address of the socket protocol structure.\r
277\r
278 @param [in] Backlog Backlog specifies the maximum FIFO depth for\r
279 the connections waiting for the application\r
280 to call accept. Connection attempts received\r
281 while the queue is full are refused.\r
282\r
283 @param [out] pErrno Address to receive the errno value upon completion.\r
284\r
285 @retval EFI_SUCCESS - Socket successfully created\r
286 @retval Other - Failed to enable the socket for listen\r
287\r
288**/\r
289typedef\r
290EFI_STATUS\r
291(* PFN_LISTEN) (\r
292 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
293 IN INT32 Backlog,\r
294 OUT int * pErrno\r
295 );\r
296\r
297/**\r
298 Get the socket options\r
299\r
300 Retrieve the socket options one at a time by name. The\r
301 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html">POSIX</a>\r
302 documentation is available online.\r
303\r
304 @param [in] pSocketProtocol Address of the socket protocol structure.\r
305 @param [in] level Option protocol level\r
306 @param [in] OptionName Name of the option\r
307 @param [out] pOptionValue Buffer to receive the option value\r
308 @param [in,out] pOptionLength Length of the buffer in bytes,\r
309 upon return length of the option value in bytes\r
310 @param [out] pErrno Address to receive the errno value upon completion.\r
311\r
312 @retval EFI_SUCCESS - Socket data successfully received\r
313\r
314 **/\r
315typedef\r
316EFI_STATUS\r
317(* PFN_OPTION_GET) (\r
318 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
319 IN int level,\r
320 IN int OptionName,\r
321 OUT void * __restrict pOptionValue,\r
322 IN OUT socklen_t * __restrict pOptionLength,\r
323 IN int * pErrno\r
324 );\r
325\r
326/**\r
327 Set the socket options\r
328\r
329 Adjust the socket options one at a time by name. The\r
330 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html">POSIX</a>\r
331 documentation is available online.\r
332\r
333 @param [in] pSocketProtocol Address of the socket protocol structure.\r
334 @param [in] level Option protocol level\r
335 @param [in] OptionName Name of the option\r
336 @param [in] pOptionValue Buffer containing the option value\r
337 @param [in] OptionLength Length of the buffer in bytes\r
338 @param [out] pErrno Address to receive the errno value upon completion.\r
339\r
340 @retval EFI_SUCCESS - Socket data successfully received\r
341\r
342 **/\r
343typedef\r
344EFI_STATUS\r
345(* PFN_OPTION_SET) (\r
346 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
347 IN int level,\r
348 IN int OptionName,\r
349 IN CONST void * pOptionValue,\r
350 IN socklen_t OptionLength,\r
351 IN int * pErrno\r
352 );\r
353\r
354/**\r
355 Poll a socket for pending activity.\r
356\r
357 The SocketPoll routine checks a socket for pending activity associated\r
358 with the event mask. Activity is returned in the detected event buffer.\r
359\r
360 @param [in] pSocketProtocol Address of the socket protocol structure.\r
361\r
362 @param [in] Events Events of interest for this socket\r
363\r
364 @param [in] pEvents Address to receive the detected events\r
365\r
366 @param [out] pErrno Address to receive the errno value upon completion.\r
367\r
368 @retval EFI_SUCCESS - Socket successfully polled\r
369 @retval EFI_INVALID_PARAMETER - When pEvents is NULL\r
370\r
371 **/\r
372typedef\r
373EFI_STATUS\r
374(* PFN_POLL) (\r
375 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
376 IN short Events,\r
377 IN short * pEvents,\r
378 IN int * pErrno\r
379 );\r
380\r
381/**\r
382 Receive data from a network connection.\r
383\r
384 The ::recv routine waits for receive data from a remote network\r
385 connection. The\r
386 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html">POSIX</a>\r
387 documentation is available online.\r
388\r
389 @param [in] pSocketProtocol Address of the socket protocol structure.\r
7dc13291 390\r
d7ce7006 391 @param [in] Flags Message control flags\r
7dc13291 392\r
d7ce7006 393 @param [in] BufferLength Length of the the buffer\r
7dc13291 394\r
d7ce7006 395 @param [in] pBuffer Address of a buffer to receive the data.\r
7dc13291 396\r
d7ce7006 397 @param [in] pDataLength Number of received data bytes in the buffer.\r
398\r
399 @param [out] pAddress Network address to receive the remote system address\r
400\r
401 @param [in,out] pAddressLength Length of the remote network address structure\r
402\r
403 @param [out] pErrno Address to receive the errno value upon completion.\r
404\r
405 @retval EFI_SUCCESS - Socket data successfully received\r
406\r
407 **/\r
408typedef\r
409EFI_STATUS\r
410(* PFN_RECEIVE) (\r
411 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
412 IN int Flags,\r
413 IN size_t BufferLength,\r
414 IN UINT8 * pBuffer,\r
415 OUT size_t * pDataLength,\r
416 OUT struct sockaddr * pAddress,\r
417 IN OUT socklen_t * pAddressLength,\r
418 IN int * pErrno\r
419 );\r
420\r
421/**\r
422 Send data using a network connection.\r
423\r
424 The SocketTransmit routine queues the data for transmission to the\r
425 remote network connection.\r
426\r
427 @param [in] pSocketProtocol Address of the socket protocol structure.\r
7dc13291 428\r
d7ce7006 429 @param [in] Flags Message control flags\r
7dc13291 430\r
d7ce7006 431 @param [in] BufferLength Length of the the buffer\r
7dc13291 432\r
d7ce7006 433 @param [in] pBuffer Address of a buffer containing the data to send\r
7dc13291 434\r
d7ce7006 435 @param [in] pDataLength Address to receive the number of data bytes sent\r
436\r
437 @param [in] pAddress Network address of the remote system address\r
438\r
439 @param [in] AddressLength Length of the remote network address structure\r
440\r
441 @param [out] pErrno Address to receive the errno value upon completion.\r
442\r
443 @retval EFI_SUCCESS - Socket data successfully queued for transmission\r
444\r
445 **/\r
446typedef\r
447EFI_STATUS\r
448(* PFN_SEND) (\r
449 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
450 IN int Flags,\r
451 IN size_t BufferLength,\r
452 IN CONST UINT8 * pBuffer,\r
453 OUT size_t * pDataLength,\r
454 IN const struct sockaddr * pAddress,\r
455 IN socklen_t AddressLength,\r
456 IN int * pErrno\r
457 );\r
458\r
459/**\r
460 Shutdown the socket receive and transmit operations\r
461\r
462 The SocketShutdown routine stops the socket receive and transmit\r
463 operations.\r
464\r
465 @param [in] pSocketProtocol Address of the socket protocol structure.\r
7dc13291 466\r
d7ce7006 467 @param [in] How Which operations to stop\r
7dc13291 468\r
d7ce7006 469 @param [out] pErrno Address to receive the errno value upon completion.\r
470\r
471 @retval EFI_SUCCESS - Socket operations successfully shutdown\r
472\r
473 **/\r
474typedef\r
475EFI_STATUS\r
476(* PFN_SHUTDOWN) (\r
477 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
478 IN int How,\r
479 IN int * pErrno\r
480 );\r
481\r
482/**\r
483 Initialize an endpoint for network communication.\r
484\r
485 The ::Socket routine initializes the communication endpoint by providing\r
486 the support for the socket library function ::socket. The\r
487 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html">POSIX</a>\r
488 documentation for the socket routine is available online for reference.\r
489\r
490 @param [in] pSocketProtocol Address of the socket protocol structure.\r
491\r
492 @param [in] domain Select the family of protocols for the client or server\r
493 application.\r
494\r
495 @param [in] type Specifies how to make the network connection. The following values\r
496 are supported:\r
497 <ul>\r
498 <li>\r
499 SOCK_STREAM - Connect to TCP, provides a byte stream\r
500 that is manipluated by read, recv, send and write.\r
501 </li>\r
502 <li>\r
503 SOCK_SEQPACKET - Connect to TCP, provides sequenced packet stream\r
504 that is manipulated by read, recv, send and write.\r
505 </li>\r
506 <li>\r
507 SOCK_DGRAM - Connect to UDP, provides a datagram service that is\r
508 manipulated by recvfrom and sendto.\r
509 </li>\r
510 </ul>\r
511\r
512 @param [in] protocol Specifies the lower layer protocol to use. The following\r
513 values are supported:\r
514 <ul>\r
515 <li>IPPROTO_TCP</li> - This value must be combined with SOCK_STREAM.</li>\r
516 <li>IPPROTO_UDP</li> - This value must be combined with SOCK_DGRAM.</li>\r
517 </ul>\r
518\r
519 @param [out] pErrno Address to receive the errno value upon completion.\r
520\r
521 @retval EFI_SUCCESS - Socket successfully created\r
522 @retval EFI_INVALID_PARAMETER - Invalid domain value, errno = EAFNOSUPPORT\r
523 @retval EFI_INVALID_PARAMETER - Invalid type value, errno = EINVAL\r
524 @retval EFI_INVALID_PARAMETER - Invalid protocol value, errno = EINVAL\r
525\r
526 **/\r
527typedef\r
528EFI_STATUS\r
529(*PFN_SOCKET) (\r
530 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
531 IN int domain,\r
532 IN int type,\r
533 IN int protocol,\r
534 IN int * pErrno\r
535 );\r
536\r
537//------------------------------------------------------------------------------\r
538// Socket Protocol\r
539//------------------------------------------------------------------------------\r
540\r
541/**\r
542 Socket protocol declaration\r
543**/\r
544typedef struct _EFI_SOCKET_PROTOCOL {\r
545 EFI_HANDLE SocketHandle; ///< Handle for the socket\r
546 PFN_ACCEPT pfnAccept; ///< Accept a network connection\r
547 PFN_BIND pfnBind; ///< Bind a local address to the socket\r
548 PFN_CLOSE_POLL pfnClosePoll; ///< Determine if the socket is closed\r
549 PFN_CLOSE_START pfnCloseStart; ///< Start the close operation\r
550 PFN_CONNECT pfnConnect; ///< Connect to a remote system\r
551 PFN_GET_LOCAL pfnGetLocal; ///< Get local address\r
552 PFN_GET_PEER pfnGetPeer; ///< Get peer address\r
553 PFN_LISTEN pfnListen; ///< Enable connection attempts on known port\r
554 PFN_POLL pfnPoll; ///< Poll for socket activity\r
555 PFN_OPTION_GET pfnOptionGet; ///< Get socket options\r
556 PFN_OPTION_SET pfnOptionSet; ///< Set socket options\r
557 PFN_RECEIVE pfnReceive; ///< Receive data from a socket\r
558 PFN_SEND pfnSend; ///< Transmit data using the socket\r
559 PFN_SHUTDOWN pfnShutdown; ///< Shutdown receive and transmit operations\r
560 PFN_SOCKET pfnSocket; ///< Initialize the socket\r
561} GCC_EFI_SOCKET_PROTOCOL;\r
562\r
563//------------------------------------------------------------------------------\r
564// Non-blocking routines\r
565//------------------------------------------------------------------------------\r
566\r
567/**\r
568 Non blocking version of accept.\r
569\r
570 See ::accept\r
571\r
572 @param [in] s Socket file descriptor returned from ::socket.\r
573\r
574 @param [in] address Address of a buffer to receive the remote network address.\r
575\r
576 @param [in, out] address_len Address of a buffer containing the Length in bytes\r
577 of the remote network address buffer. Upon return,\r
578 contains the length of the remote network address.\r
579\r
7dc13291 580 @return This routine returns zero if successful and -1 when an error occurs.\r
d7ce7006 581 In the case of an error, errno contains more details.\r
582\r
583 **/\r
584int\r
585AcceptNB (\r
586 int s,\r
587 struct sockaddr * address,\r
588 socklen_t * address_len\r
589 );\r
590\r
591/**\r
592 Connect to the socket driver\r
593\r
594 @param [in] ppSocketProtocol Address to receive the socket protocol address\r
595\r
596 @retval 0 Successfully returned the socket protocol\r
597 @retval other Value for errno\r
598 **/\r
599int\r
600EslServiceGetProtocol (\r
601 IN EFI_SOCKET_PROTOCOL ** ppSocketProtocol\r
602 );\r
603\r
604//------------------------------------------------------------------------------\r
605\r
606#endif // _EFI_SOCKET_H_\r