]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/Include/Efi/EfiSocketLib.h
1. Add Partial Keystroke Support in Nt32 WinNTGopDxe driver. See the Uefi2.3.1a chapt...
[mirror_edk2.git] / StdLib / Include / Efi / EfiSocketLib.h
1 /** @file
2 Definitions for the EFI Socket layer library.
3
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
9
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.
12
13 **/
14
15 #ifndef _EFI_SOCKET_LIB_H_
16 #define _EFI_SOCKET_LIB_H_
17
18 #include <Uefi.h>
19
20 #include <Library/BaseMemoryLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/UefiBootServicesTableLib.h>
23 #include <Library/UefiLib.h>
24
25 #include <Protocol/EfiSocket.h>
26 #include <Protocol/ServiceBinding.h>
27 #include <Protocol/Tcp4.h>
28 #include <Protocol/Udp4.h>
29
30 #include <sys/time.h>
31
32 //------------------------------------------------------------------------------
33 // Constants
34 //------------------------------------------------------------------------------
35
36 #define DEBUG_TPL 0x40000000 ///< Display TPL change messages
37
38 #define TPL_SOCKETS TPL_CALLBACK ///< TPL for routine synchronization
39
40 //------------------------------------------------------------------------------
41 // Macros
42 //------------------------------------------------------------------------------
43
44 #if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
45 #define DBG_ENTER() DEBUG (( DEBUG_INFO, "Entering " __FUNCTION__ "\n" )) ///< Display routine entry
46 #define DBG_EXIT() DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ "\n" )) ///< Display routine exit
47 #define DBG_EXIT_DEC(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", Status: %d\n", Status )) ///< Display routine exit with decimal value
48 #define DBG_EXIT_HEX(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", Status: 0x%08x\n", Status )) ///< Display routine exit with hex value
49 #define DBG_EXIT_STATUS(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", Status: %r\n", Status )) ///< Display routine exit with status value
50 #define DBG_EXIT_TF(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", returning %s\n", (FALSE == Status) ? L"FALSE" : L"TRUE" )) ///< Display routine with TRUE/FALSE value
51 #else // _MSC_VER
52 #define DBG_ENTER()
53 #define DBG_EXIT()
54 #define DBG_EXIT_DEC(Status)
55 #define DBG_EXIT_HEX(Status)
56 #define DBG_EXIT_STATUS(Status)
57 #define DBG_EXIT_TF(Status)
58 #endif // _MSC_VER
59
60 #define DIM(x) ( sizeof ( x ) / sizeof ( x[0] )) ///< Compute the number of entries in an array
61
62 /**
63 Verify new TPL value
64
65 This macro which is enabled when debug is enabled verifies that
66 the new TPL value is >= the current TPL value.
67 **/
68 #ifdef VERIFY_TPL
69 #undef VERIFY_TPL
70 #endif // VERIFY_TPL
71
72 #if !defined(MDEPKG_NDEBUG)
73
74 #define VERIFY_TPL(tpl) \
75 { \
76 EFI_TPL PreviousTpl; \
77 \
78 PreviousTpl = gBS->RaiseTPL ( TPL_HIGH_LEVEL ); \
79 gBS->RestoreTPL ( PreviousTpl ); \
80 if ( PreviousTpl > tpl ) { \
81 DEBUG (( DEBUG_ERROR | DEBUG_TPL, \
82 "Current TPL: %d, New TPL: %d\r\n", \
83 PreviousTpl, tpl )); \
84 ASSERT ( PreviousTpl <= tpl ); \
85 } \
86 }
87
88 #else // MDEPKG_NDEBUG
89
90 #define VERIFY_TPL(tpl)
91
92 #endif // MDEPKG_NDEBUG
93
94 #define RAISE_TPL(PreviousTpl, tpl) \
95 VERIFY_TPL ( tpl ); \
96 PreviousTpl = gBS->RaiseTPL ( tpl ); \
97 DEBUG (( DEBUG_TPL | DEBUG_TPL, \
98 "%d: TPL\r\n", \
99 tpl ))
100
101 #define RESTORE_TPL(tpl) \
102 gBS->RestoreTPL ( tpl ); \
103 DEBUG (( DEBUG_TPL | DEBUG_TPL, \
104 "%d: TPL\r\n", \
105 tpl ))
106
107 //------------------------------------------------------------------------------
108 // Data Types
109 //------------------------------------------------------------------------------
110
111 typedef struct _DT_SERVICE DT_SERVICE; ///< Forward delcaration
112
113 typedef
114 EFI_STATUS
115 (EFIAPI * PFN_SB_INITIALIZE) (
116 DT_SERVICE * pService
117 );
118
119 typedef
120 VOID
121 (EFIAPI * PFN_SB_SHUTDOWN) (
122 DT_SERVICE * pService
123 );
124
125 /**
126 Protocol binding and installation control structure
127
128 The driver uses this structure to simplify the driver binding processing.
129 **/
130 typedef struct {
131 CHAR16 * pName; ///< Protocol name
132 EFI_GUID * pNetworkBinding; ///< Network service binding protocol for socket support
133 CONST EFI_GUID * pTagGuid; ///< Tag to mark protocol in use
134 PFN_SB_INITIALIZE pfnInitialize;///< Routine to initialize the service
135 PFN_SB_SHUTDOWN pfnShutdown; ///< Routine to shutdown the service
136 } DT_SOCKET_BINDING;
137
138 //------------------------------------------------------------------------------
139 // GUIDs
140 //------------------------------------------------------------------------------
141
142 extern CONST EFI_GUID mEslRawServiceGuid;
143 extern CONST EFI_GUID mEslTcp4ServiceGuid;
144 extern CONST EFI_GUID mEslUdp4ServiceGuid;
145
146 //------------------------------------------------------------------------------
147 // Data
148 //------------------------------------------------------------------------------
149
150 extern CONST DT_SOCKET_BINDING cEslSocketBinding [];
151 extern CONST UINTN cEslSocketBindingEntries;
152
153 //------------------------------------------------------------------------------
154 // Service Support Routines
155 //------------------------------------------------------------------------------
156
157 /**
158 Connect to the network service bindings
159
160 Walk the network service protocols on the controller handle and
161 locate any that are not in use. Create service structures to
162 manage the service binding for the socket driver.
163
164 @param [in] BindingHandle Handle for protocol binding.
165 @param [in] Controller Handle of device to work with.
166
167 @retval EFI_SUCCESS This driver is added to Controller.
168 @retval other This driver does not support this device.
169
170 **/
171 EFI_STATUS
172 EFIAPI
173 EslServiceConnect (
174 IN EFI_HANDLE BindingHandle,
175 IN EFI_HANDLE Controller
176 );
177
178 /**
179 Shutdown the network connections to this controller by removing
180 NetworkInterfaceIdentifier protocol and closing the DevicePath
181 and PciIo protocols on Controller.
182
183 @param [in] BindingHandle Handle for protocol binding.
184 @param [in] Controller Handle of device to stop driver on.
185
186 @retval EFI_SUCCESS This driver is removed Controller.
187 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
188 @retval other This driver was not removed from this device.
189
190 **/
191 EFI_STATUS
192 EFIAPI
193 EslServiceDisconnect (
194 IN EFI_HANDLE BindingHandle,
195 IN EFI_HANDLE Controller
196 );
197
198 /**
199 Install the socket service
200
201 @param [in] pImageHandle Address of the image handle
202
203 @retval EFI_SUCCESS Service installed successfully
204 **/
205 EFI_STATUS
206 EFIAPI
207 EslServiceInstall (
208 IN EFI_HANDLE * pImageHandle
209 );
210
211 /**
212 Initialize the service layer
213
214 @param [in] ImageHandle Handle for the image.
215
216 **/
217 VOID
218 EFIAPI
219 EslServiceLoad (
220 IN EFI_HANDLE ImageHandle
221 );
222
223 /**
224 Uninstall the socket service
225
226 @param [in] ImageHandle Handle for the image.
227
228 @retval EFI_SUCCESS Service installed successfully
229 **/
230 EFI_STATUS
231 EFIAPI
232 EslServiceUninstall (
233 IN EFI_HANDLE ImageHandle
234 );
235
236 /**
237 Shutdown the service layer
238
239 **/
240 VOID
241 EFIAPI
242 EslServiceUnload (
243 VOID
244 );
245
246 //------------------------------------------------------------------------------
247 // Socket Service Binding Protocol Routines
248 //------------------------------------------------------------------------------
249
250 /**
251 Creates a child handle and installs a protocol.
252
253 The CreateChild() function installs a protocol on ChildHandle.
254 If pChildHandle is a pointer to NULL, then a new handle is created and returned in pChildHandle.
255 If pChildHandle is not a pointer to NULL, then the protocol installs on the existing pChildHandle.
256
257 @param [in] pThis Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
258 @param [in] pChildHandle Pointer to the handle of the child to create. If it is NULL,
259 then a new handle is created. If it is a pointer to an existing UEFI handle,
260 then the protocol is added to the existing UEFI handle.
261
262 @retval EFI_SUCCES The protocol was added to ChildHandle.
263 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
264 @retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
265 the child
266 @retval other The child handle was not created
267
268 **/
269 EFI_STATUS
270 EFIAPI
271 EslSocketCreateChild (
272 IN EFI_SERVICE_BINDING_PROTOCOL * pThis,
273 IN OUT EFI_HANDLE * pChildHandle
274 );
275
276 /**
277 Destroys a child handle with a protocol installed on it.
278
279 The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
280 that was installed by CreateChild() from ChildHandle. If the removed protocol is the
281 last protocol on ChildHandle, then ChildHandle is destroyed.
282
283 @param [in] pThis Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
284 @param [in] ChildHandle Handle of the child to destroy
285
286 @retval EFI_SUCCES The protocol was removed from ChildHandle.
287 @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
288 @retval EFI_INVALID_PARAMETER Child handle is not a valid UEFI Handle.
289 @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
290 because its services are being used.
291 @retval other The child handle was not destroyed
292
293 **/
294 EFI_STATUS
295 EFIAPI
296 EslSocketDestroyChild (
297 IN EFI_SERVICE_BINDING_PROTOCOL * pThis,
298 IN EFI_HANDLE ChildHandle
299 );
300
301 //------------------------------------------------------------------------------
302 // Socket Protocol Routines
303 //------------------------------------------------------------------------------
304
305 /**
306 Bind a name to a socket.
307
308 The ::SocketBind routine connects a name to a socket on the local machine. The
309 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html">POSIX</a>
310 documentation for the bind routine is available online for reference.
311
312 @param [in] pSocketProtocol Address of the socket protocol structure.
313
314 @param [in] pSockAddr Address of a sockaddr structure that contains the
315 connection point on the local machine. An IPv4 address
316 of INADDR_ANY specifies that the connection is made to
317 all of the network stacks on the platform. Specifying a
318 specific IPv4 address restricts the connection to the
319 network stack supporting that address. Specifying zero
320 for the port causes the network layer to assign a port
321 number from the dynamic range. Specifying a specific
322 port number causes the network layer to use that port.
323
324 @param [in] SockAddrLen Specifies the length in bytes of the sockaddr structure.
325
326 @param [out] pErrno Address to receive the errno value upon completion.
327
328 @retval EFI_SUCCESS - Socket successfully created
329
330 **/
331 EFI_STATUS
332 EslSocketBind (
333 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
334 IN const struct sockaddr * pSockAddr,
335 IN socklen_t SockAddrLength,
336 OUT int * pErrno
337 );
338
339 /**
340 Determine if the socket is closed
341
342 Reverses the operations of the ::SocketAllocate() routine.
343
344 @param [in] pSocketProtocol Address of the socket protocol structure.
345 @param [out] pErrno Address to receive the errno value upon completion.
346
347 @retval EFI_SUCCESS Socket successfully closed
348 @retval EFI_NOT_READY Close still in progress
349 @retval EFI_ALREADY Close operation already in progress
350 @retval Other Failed to close the socket
351
352 **/
353 EFI_STATUS
354 EslSocketClosePoll (
355 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
356 IN int * pErrno
357 );
358
359 /**
360 Start the close operation on the socket
361
362 Start closing the socket by closing all of the ports. Upon
363 completion, the ::SocketPoll() routine finishes closing the
364 socket.
365
366 @param [in] pSocketProtocol Address of the socket protocol structure.
367 @param [in] bCloseNow Boolean to control close behavior
368 @param [out] pErrno Address to receive the errno value upon completion.
369
370 @retval EFI_SUCCESS Socket successfully closed
371 @retval EFI_NOT_READY Close still in progress
372 @retval EFI_ALREADY Close operation already in progress
373 @retval Other Failed to close the socket
374
375 **/
376 EFI_STATUS
377 EslSocketCloseStart (
378 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
379 IN BOOLEAN bCloseNow,
380 IN int * pErrno
381 );
382
383 /**
384 Connect to a remote system via the network.
385
386 The ::SocketConnect routine attempts to establish a connection to a
387 socket on the local or remote system using the specified address.
388 The POSIX
389 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html">connect</a>
390 documentation is available online.
391
392 There are three states associated with a connection:
393 <ul>
394 <li>Not connected</li>
395 <li>Connection in progress</li>
396 <li>Connected</li>
397 </ul>
398 In the "Not connected" state, calls to ::connect start the connection
399 processing and update the state to "Connection in progress". During
400 the "Connection in progress" state, connect polls for connection completion
401 and moves the state to "Connected" after the connection is established.
402 Note that these states are only visible when the file descriptor is marked
403 with O_NONBLOCK. Also, the POLL_WRITE bit is set when the connection
404 completes and may be used by poll or select as an indicator to call
405 connect again.
406
407 @param [in] pSocketProtocol Address of the socket protocol structure.
408
409 @param [in] pSockAddr Network address of the remote system.
410
411 @param [in] SockAddrLength Length in bytes of the network address.
412
413 @param [out] pErrno Address to receive the errno value upon completion.
414
415 @retval EFI_SUCCESS The connection was successfully established.
416 @retval EFI_NOT_READY The connection is in progress, call this routine again.
417 @retval Others The connection attempt failed.
418
419 **/
420 EFI_STATUS
421 EslSocketConnect (
422 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
423 IN const struct sockaddr * pSockAddr,
424 IN socklen_t SockAddrLength,
425 IN int * pErrno
426 );
427
428 /**
429 Get the local address.
430
431 @param [in] pSocketProtocol Address of the socket protocol structure.
432
433 @param [out] pAddress Network address to receive the local system address
434
435 @param [in,out] pAddressLength Length of the local network address structure
436
437 @param [out] pErrno Address to receive the errno value upon completion.
438
439 @retval EFI_SUCCESS - Local address successfully returned
440
441 **/
442 EFI_STATUS
443 EslSocketGetLocalAddress (
444 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
445 OUT struct sockaddr * pAddress,
446 IN OUT socklen_t * pAddressLength,
447 IN int * pErrno
448 );
449
450 /**
451 Get the peer address.
452
453 @param [in] pSocketProtocol Address of the socket protocol structure.
454
455 @param [out] pAddress Network address to receive the remote system address
456
457 @param [in,out] pAddressLength Length of the remote network address structure
458
459 @param [out] pErrno Address to receive the errno value upon completion.
460
461 @retval EFI_SUCCESS - Remote address successfully returned
462
463 **/
464 EFI_STATUS
465 EslSocketGetPeerAddress (
466 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
467 OUT struct sockaddr * pAddress,
468 IN OUT socklen_t * pAddressLength,
469 IN int * pErrno
470 );
471
472 /**
473 Establish the known port to listen for network connections.
474
475 The ::SocketListen routine places the port into a state that enables connection
476 attempts. Connections are placed into FIFO order in a queue to be serviced
477 by the application. The application calls the ::SocketAccept routine to remove
478 the next connection from the queue and get the associated socket. The
479 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html">POSIX</a>
480 documentation for the bind routine is available online for reference.
481
482 @param [in] pSocketProtocol Address of the socket protocol structure.
483
484 @param [in] Backlog Backlog specifies the maximum FIFO depth for
485 the connections waiting for the application
486 to call accept. Connection attempts received
487 while the queue is full are refused.
488
489 @param [out] pErrno Address to receive the errno value upon completion.
490
491 @retval EFI_SUCCESS - Socket successfully created
492 @retval Other - Failed to enable the socket for listen
493
494 **/
495 EFI_STATUS
496 EslSocketListen (
497 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
498 IN INT32 Backlog,
499 OUT int * pErrno
500 );
501
502 /**
503 Get the socket options
504
505 Retrieve the socket options one at a time by name. The
506 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html">POSIX</a>
507 documentation is available online.
508
509 @param [in] pSocketProtocol Address of the socket protocol structure.
510 @param [in] level Option protocol level
511 @param [in] option_name Name of the option
512 @param [out] option_value Buffer to receive the option value
513 @param [in,out] option_len Length of the buffer in bytes,
514 upon return length of the option value in bytes
515 @param [out] pErrno Address to receive the errno value upon completion.
516
517 @retval EFI_SUCCESS - Socket data successfully received
518
519 **/
520 EFI_STATUS
521 EslSocketOptionGet (
522 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
523 IN int level,
524 IN int option_name,
525 OUT void * __restrict option_value,
526 IN OUT socklen_t * __restrict option_len,
527 IN int * pErrno
528 );
529
530 /**
531 Set the socket options
532
533 Adjust the socket options one at a time by name. The
534 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html">POSIX</a>
535 documentation is available online.
536
537 @param [in] pSocketProtocol Address of the socket protocol structure.
538 @param [in] level Option protocol level
539 @param [in] option_name Name of the option
540 @param [in] option_value Buffer containing the option value
541 @param [in] option_len Length of the buffer in bytes
542 @param [out] pErrno Address to receive the errno value upon completion.
543
544 @retval EFI_SUCCESS - Socket data successfully received
545
546 **/
547 EFI_STATUS
548 EslSocketOptionSet (
549 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
550 IN int level,
551 IN int option_name,
552 IN CONST void * option_value,
553 IN socklen_t option_len,
554 IN int * pErrno
555 );
556
557 /**
558 Poll a socket for pending activity.
559
560 The SocketPoll routine checks a socket for pending activity associated
561 with the event mask. Activity is returned in the detected event buffer.
562
563 @param [in] pSocketProtocol Address of the socket protocol structure.
564
565 @param [in] Events Events of interest for this socket
566
567 @param [in] pEvents Address to receive the detected events
568
569 @param [out] pErrno Address to receive the errno value upon completion.
570
571 @retval EFI_SUCCESS - Socket successfully polled
572 @retval EFI_INVALID_PARAMETER - When pEvents is NULL
573
574 **/
575 EFI_STATUS
576 EslSocketPoll (
577 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
578 IN short Events,
579 IN short * pEvents,
580 IN int * pErrno
581 );
582
583 /**
584 Receive data from a network connection.
585
586
587 @param [in] pSocketProtocol Address of the socket protocol structure.
588
589 @param [in] Flags Message control flags
590
591 @param [in] BufferLength Length of the the buffer
592
593 @param [in] pBuffer Address of a buffer to receive the data.
594
595 @param [in] pDataLength Number of received data bytes in the buffer.
596
597 @param [out] pAddress Network address to receive the remote system address
598
599 @param [in,out] pAddressLength Length of the remote network address structure
600
601 @param [out] pErrno Address to receive the errno value upon completion.
602
603 @retval EFI_SUCCESS - Socket data successfully received
604
605 **/
606 EFI_STATUS
607 EslSocketReceive (
608 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
609 IN INT32 Flags,
610 IN size_t BufferLength,
611 IN UINT8 * pBuffer,
612 OUT size_t * pDataLength,
613 OUT struct sockaddr * pAddress,
614 IN OUT socklen_t * pAddressLength,
615 IN int * pErrno
616 );
617
618 /**
619 Shutdown the socket receive and transmit operations
620
621 The SocketShutdown routine stops the socket receive and transmit
622 operations.
623
624 @param [in] pSocketProtocol Address of the socket protocol structure.
625
626 @param [in] How Which operations to stop
627
628 @param [out] pErrno Address to receive the errno value upon completion.
629
630 @retval EFI_SUCCESS - Socket operations successfully shutdown
631
632 **/
633 EFI_STATUS
634 EslSocketShutdown (
635 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
636 IN int How,
637 IN int * pErrno
638 );
639
640 /**
641 Send data using a network connection.
642
643 The SocketTransmit routine queues the data for transmission to the
644 remote network connection.
645
646 @param [in] pSocketProtocol Address of the socket protocol structure.
647
648 @param [in] Flags Message control flags
649
650 @param [in] BufferLength Length of the the buffer
651
652 @param [in] pBuffer Address of a buffer containing the data to send
653
654 @param [in] pDataLength Address to receive the number of data bytes sent
655
656 @param [in] pAddress Network address of the remote system address
657
658 @param [in] AddressLength Length of the remote network address structure
659
660 @param [out] pErrno Address to receive the errno value upon completion.
661
662 @retval EFI_SUCCESS - Socket data successfully received
663
664 **/
665 EFI_STATUS
666 EslSocketTransmit (
667 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
668 IN int Flags,
669 IN size_t BufferLength,
670 IN CONST UINT8 * pBuffer,
671 OUT size_t * pDataLength,
672 IN const struct sockaddr * pAddress,
673 IN socklen_t AddressLength,
674 IN int * pErrno
675 );
676
677 //------------------------------------------------------------------------------
678
679 #endif // _EFI_SOCKET_LIB_H_