]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/Tcp4Dxe/Socket.h
0317efa3229da4568c47a756e3fecaae1d826f59
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Tcp4Dxe / Socket.h
1 /** @file
2 Socket header file.
3
4 Copyright (c) 2005 - 2009, Intel Corporation. All rights reserved.<BR>
5 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<BR>
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 _SOCKET_H_
16 #define _SOCKET_H_
17
18 #include <Uefi.h>
19
20 #include <Protocol/Ip4.h>
21 #include <Protocol/Tcp4.h>
22 #include <Protocol/Udp4.h>
23
24 #include <Library/NetLib.h>
25 #include <Library/DebugLib.h>
26 #include <Library/BaseMemoryLib.h>
27 #include <Library/MemoryAllocationLib.h>
28 #include <Library/UefiRuntimeServicesTableLib.h>
29 #include <Library/UefiBootServicesTableLib.h>
30 #include <Library/UefiDriverEntryPoint.h>
31 #include <Library/UefiLib.h>
32 #include <Library/DpcLib.h>
33
34 #define SOCK_SND_BUF 0
35 #define SOCK_RCV_BUF 1
36
37 #define SOCK_BUFF_LOW_WATER (2 * 1024)
38 #define SOCK_RCV_BUFF_SIZE (8 * 1024)
39 #define SOCK_SND_BUFF_SIZE (8 * 1024)
40 #define SOCK_BACKLOG 5
41
42 #define PROTO_RESERVED_LEN 20
43
44 #define SO_NO_MORE_DATA 0x0001
45
46 //
47 //
48 //
49 // When a socket is created it enters into SO_UNCONFIGURED,
50 // no actions can be taken on this socket, only after calling
51 // SockConfigure. The state transition diagram of socket is
52 // as following:
53 //
54 // SO_UNCONFIGURED --- SO_CONFIGURED --- SO_CONNECTING
55 // ^ | |
56 // | ---> SO_LISTENING |
57 // | |
58 // |------------------SO_DISCONNECTING<-- SO_CONNECTED
59 //
60 // A passive socket can only go into SO_LISTENING and
61 // SO_UNCONFIGURED state. SO_XXXING state is a middle state
62 // when a socket is undergoing a protocol procedure such
63 // as requesting a TCP connection.
64 //
65 //
66 //
67
68 ///
69 /// Socket state
70 ///
71 #define SO_CLOSED 0
72 #define SO_LISTENING 1
73 #define SO_CONNECTING 2
74 #define SO_CONNECTED 3
75 #define SO_DISCONNECTING 4
76
77 ///
78 /// Socket configure state
79 ///
80 #define SO_UNCONFIGURED 0
81 #define SO_CONFIGURED_ACTIVE 1
82 #define SO_CONFIGURED_PASSIVE 2
83 #define SO_NO_MAPPING 3
84
85 /**
86 Set socket SO_NO_MORE_DATA flag.
87
88 @param Sock Pointer to the socket
89
90 **/
91 #define SOCK_NO_MORE_DATA(Sock) ((Sock)->Flag |= SO_NO_MORE_DATA)
92
93 /**
94 Check whether the socket is unconfigured.
95
96 @param Sock Pointer to the socket
97
98 @retval True The socket is unconfigued
99 @retval False The socket is not unconfigued
100
101 **/
102 #define SOCK_IS_UNCONFIGURED(Sock) ((Sock)->ConfigureState == SO_UNCONFIGURED)
103
104 /**
105 Check whether the socket is configured.
106
107 @param Sock Pointer to the socket
108
109 @retval True The socket is configued
110 @retval False The socket is not configued
111
112 **/
113 #define SOCK_IS_CONFIGURED(Sock) \
114 (((Sock)->ConfigureState == SO_CONFIGURED_ACTIVE) || \
115 ((Sock)->ConfigureState == SO_CONFIGURED_PASSIVE))
116
117 /**
118 Check whether the socket is configured to active mode.
119
120 @param Sock Pointer to the socket
121
122 @retval True The socket is configued to active mode
123 @retval False The socket is not configued to active mode
124
125 **/
126 #define SOCK_IS_CONFIGURED_ACTIVE(Sock) \
127 ((Sock)->ConfigureState == SO_CONFIGURED_ACTIVE)
128
129 /**
130 Check whether the socket is configured to passive mode.
131
132 @param Sock Pointer to the socket
133
134 @retval True The socket is configued to passive mode
135 @retval False The socket is not configued to passive mode
136
137 **/
138 #define SOCK_IS_CONNECTED_PASSIVE(Sock) \
139 ((Sock)->ConfigureState == SO_CONFIGURED_PASSIVE)
140
141 /**
142 Check whether the socket is mapped.
143
144 @param Sock Pointer to the socket
145
146 @retval True The socket is no mapping
147 @retval False The socket is mapped
148
149 **/
150 #define SOCK_IS_NO_MAPPING(Sock) \
151 ((Sock)->ConfigureState == SO_NO_MAPPING)
152
153 /**
154 Check whether the socket is closed.
155
156 @param Sock Pointer to the socket
157
158 @retval True The socket is closed
159 @retval False The socket is not closed
160
161 **/
162 #define SOCK_IS_CLOSED(Sock) ((Sock)->State == SO_CLOSED)
163
164 /**
165 Check whether the socket is listening.
166
167 @param Sock Pointer to the socket
168
169 @retval True The socket is listening
170 @retval False The socket is not listening
171
172 **/
173 #define SOCK_IS_LISTENING(Sock) ((Sock)->State == SO_LISTENING)
174
175 /**
176 Check whether the socket is connecting.
177
178 @param Sock Pointer to the socket
179
180 @retval True The socket is connecting
181 @retval False The socket is not connecting
182
183 **/
184 #define SOCK_IS_CONNECTING(Sock) ((Sock)->State == SO_CONNECTING)
185
186 /**
187 Check whether the socket has connected.
188
189 @param Sock Pointer to the socket
190
191 @retval True The socket has connected
192 @retval False The socket has not connected
193
194 **/
195 #define SOCK_IS_CONNECTED(Sock) ((Sock)->State == SO_CONNECTED)
196
197 /**
198 Check whether the socket is disconnecting.
199
200 @param Sock Pointer to the socket
201
202 @retval True The socket is disconnecting
203 @retval False The socket is not disconnecting
204
205 **/
206 #define SOCK_IS_DISCONNECTING(Sock) ((Sock)->State == SO_DISCONNECTING)
207
208 /**
209 Check whether the socket is no more data.
210
211 @param Sock Pointer to the socket
212
213 @retval True The socket is no more data
214 @retval False The socket still has data
215
216 **/
217 #define SOCK_IS_NO_MORE_DATA(Sock) (0 != ((Sock)->Flag & SO_NO_MORE_DATA))
218
219 /**
220 Set the size of the receive buffer.
221
222 @param Sock Pointer to the socket
223 @param Size The size to set
224
225 **/
226 #define SET_RCV_BUFFSIZE(Sock, Size) ((Sock)->RcvBuffer.HighWater = (Size))
227
228 /**
229 Get the size of the receive buffer.
230
231 @param Sock Pointer to the socket
232
233 @return The receive buffer size
234
235 **/
236 #define GET_RCV_BUFFSIZE(Sock) ((Sock)->RcvBuffer.HighWater)
237
238 /**
239 Get the size of the receive data.
240
241 @param Sock Pointer to the socket
242
243 @return The received data size
244
245 **/
246 #define GET_RCV_DATASIZE(Sock) (((Sock)->RcvBuffer.DataQueue)->BufSize)
247
248 /**
249 Set the size of the send buffer.
250
251 @param Sock Pointer to the socket
252 @param Size The size to set
253
254 **/
255 #define SET_SND_BUFFSIZE(Sock, Size) ((Sock)->SndBuffer.HighWater = (Size))
256
257 /**
258 Get the size of the send buffer.
259
260 @param Sock Pointer to the socket
261
262 @return The send buffer size
263
264 **/
265 #define GET_SND_BUFFSIZE(Sock) ((Sock)->SndBuffer.HighWater)
266
267 /**
268 Get the size of the send data.
269
270 @param Sock Pointer to the socket
271
272 @return The send data size
273
274 **/
275 #define GET_SND_DATASIZE(Sock) (((Sock)->SndBuffer.DataQueue)->BufSize)
276
277 /**
278 Set the backlog value of the socket.
279
280 @param Sock Pointer to the socket
281 @param Value The value to set
282
283 **/
284 #define SET_BACKLOG(Sock, Value) ((Sock)->BackLog = (Value))
285
286 /**
287 Get the backlog value of the socket.
288
289 @param Sock Pointer to the socket
290
291 @return The backlog value
292
293 **/
294 #define GET_BACKLOG(Sock) ((Sock)->BackLog)
295
296 /**
297 Set the socket with error state.
298
299 @param Sock Pointer to the socket
300 @param Error The error state
301
302 **/
303 #define SOCK_ERROR(Sock, Error) ((Sock)->SockError = (Error))
304
305 #define SND_BUF_HDR_LEN(Sock) \
306 ((SockBufFirst (&((Sock)->SndBuffer)))->TotalSize)
307
308 #define RCV_BUF_HDR_LEN(Sock) \
309 ((SockBufFirst (&((Sock)->RcvBuffer)))->TotalSize)
310
311 #define SOCK_SIGNATURE SIGNATURE_32 ('S', 'O', 'C', 'K')
312
313 #define SOCK_FROM_THIS(a) CR ((a), SOCKET, NetProtocol, SOCK_SIGNATURE)
314
315 #define SOCK_FROM_TOKEN(Token) (((SOCK_TOKEN *) (Token))->Sock)
316
317 #define PROTO_TOKEN_FORM_SOCK(SockToken, Type) \
318 ((Type *) (((SOCK_TOKEN *) (SockToken))->Token))
319
320 typedef struct _SOCKET SOCKET;
321
322 ///
323 /// Socket completion token
324 ///
325 typedef struct _SOCK_COMPLETION_TOKEN {
326 EFI_EVENT Event; ///< The event to be issued
327 EFI_STATUS Status; ///< The status to be issued
328 } SOCK_COMPLETION_TOKEN;
329
330 typedef union {
331 VOID *RxData;
332 VOID *TxData;
333 } SOCK_IO_DATA;
334
335 ///
336 /// The application token with data packet
337 ///
338 typedef struct _SOCK_IO_TOKEN {
339 SOCK_COMPLETION_TOKEN Token;
340 SOCK_IO_DATA Packet;
341 } SOCK_IO_TOKEN;
342
343 ///
344 /// The request issued from socket layer to protocol layer.
345 ///
346 #define SOCK_ATTACH 0 ///< Attach current socket to a new PCB
347 #define SOCK_DETACH 1 ///< Detach current socket from the PCB
348 #define SOCK_CONFIGURE 2 ///< Configure attached PCB
349 #define SOCK_FLUSH 3 ///< Flush attached PCB
350 #define SOCK_SND 4 ///< Need protocol to send something
351 #define SOCK_SNDPUSH 5 ///< Need protocol to send pushed data
352 #define SOCK_SNDURG 6 ///< Need protocol to send urgent data
353 #define SOCK_CONSUMED 7 ///< Application has retrieved data from socket
354 #define SOCK_CONNECT 8 ///< Need to connect to a peer
355 #define SOCK_CLOSE 9 ///< Need to close the protocol process
356 #define SOCK_ABORT 10 ///< Need to reset the protocol process
357 #define SOCK_POLL 11 ///< Need to poll to the protocol layer
358 #define SOCK_ROUTE 12 ///< Need to add a route information
359 #define SOCK_MODE 13 ///< Need to get the mode data of the protocol
360 #define SOCK_GROUP 14 ///< Need to join a mcast group
361
362 ///
363 /// The socket type.
364 ///
365 typedef enum {
366 SockDgram, ///< This socket providing datagram service
367 SockStream ///< This socket providing stream service
368 } SOCK_TYPE;
369
370 ///
371 /// The buffer structure of rcvd data and send data used by socket.
372 ///
373 typedef struct _SOCK_BUFFER {
374 UINT32 HighWater; ///< The buffersize upper limit of sock_buffer
375 UINT32 LowWater; ///< The low warter mark of sock_buffer
376 NET_BUF_QUEUE *DataQueue; ///< The queue to buffer data
377 } SOCK_BUFFER;
378
379 /**
380 The handler of protocol for request from socket.
381
382 @param Socket The socket issuing the request to protocol
383 @param Request The request issued by socket
384 @param RequestData The request related data
385
386 @retval EFI_SUCCESS The socket request is completed successfully.
387 @retval other The error status returned by the corresponding TCP
388 layer function.
389
390 **/
391 typedef
392 EFI_STATUS
393 (*SOCK_PROTO_HANDLER) (
394 IN SOCKET *Socket,
395 IN UINT8 Request,
396 IN VOID *RequestData
397 );
398
399
400 //
401 // Socket provided oprerations for low layer protocol
402 //
403
404 //
405 // Socket provided operations for user interface
406 //
407
408 /**
409 Set the state of the socket.
410
411 @param Sock Pointer to the socket.
412 @param State The new socket state to be set.
413
414 **/
415 VOID
416 SockSetState (
417 IN OUT SOCKET *Sock,
418 IN UINT8 State
419 );
420
421 /**
422 Called by the low layer protocol to indicate the socket a connection is
423 established.
424
425 This function just changes the socket's state to SO_CONNECTED
426 and signals the token used for connection establishment.
427
428 @param Sock Pointer to the socket associated with the
429 established connection.
430
431 **/
432 VOID
433 SockConnEstablished (
434 IN SOCKET *Sock
435 );
436
437 /**
438 Called by the low layer protocol to indicate the connection is closed.
439
440 This function flushes the socket, sets the state to SO_CLOSED and signals
441 the close token.
442
443 @param Sock Pointer to the socket associated with the closed
444 connection.
445
446 **/
447 VOID
448 SockConnClosed (
449 IN OUT SOCKET *Sock
450 );
451
452 /**
453 Called by low layer protocol to indicate that some data is sent or processed.
454
455 This function trims the sent data in the socket send buffer, signals the data
456 token if proper.
457
458 @param Sock Pointer to the socket.
459 @param Count The length of the data processed or sent, in bytes.
460
461 **/
462 VOID
463 SockDataSent (
464 IN SOCKET *Sock,
465 IN UINT32 Count
466 );
467
468 /**
469 Called by the low layer protocol to copy some data in socket send
470 buffer starting from the specific offset to a buffer provided by
471 the caller.
472
473 @param Sock Pointer to the socket.
474 @param Offset The start point of the data to be copied.
475 @param Len The length of the data to be copied.
476 @param Dest Pointer to the destination to copy the data.
477
478 @return The data size copied.
479
480 **/
481 UINT32
482 SockGetDataToSend (
483 IN SOCKET *Sock,
484 IN UINT32 Offset,
485 IN UINT32 Len,
486 IN UINT8 *Dest
487 );
488
489 /**
490 Called by the low layer protocol to indicate that there
491 will be no more data from the communication peer.
492
493 This function set the socket's state to SO_NO_MORE_DATA and
494 signal all queued IO tokens with the error status EFI_CONNECTION_FIN.
495
496 @param Sock Pointer to the socket.
497
498 **/
499 VOID
500 SockNoMoreData (
501 IN OUT SOCKET *Sock
502 );
503
504 /**
505 Called by the low layer protocol to deliver received data to socket layer.
506
507 This function will append the data to the socket receive buffer, set ther
508 urgent data length and then check if any receive token can be signaled.
509
510 @param Sock Pointer to the socket.
511 @param NetBuffer Pointer to the buffer that contains the received
512 data.
513 @param UrgLen The length of the urgent data in the received data.
514
515 **/
516 VOID
517 SockDataRcvd (
518 IN SOCKET *Sock,
519 IN OUT NET_BUF *NetBuffer,
520 IN UINT32 UrgLen
521 );
522
523 /**
524 Get the length of the free space of the specific socket buffer.
525
526 @param Sock Pointer to the socket.
527 @param Which Flag to indicate which socket buffer to check,
528 either send buffer or receive buffer.
529
530 @return The length of the free space, in bytes.
531
532 **/
533 UINT32
534 SockGetFreeSpace (
535 IN SOCKET *Sock,
536 IN UINT32 Which
537 );
538
539 /**
540 Clone a new socket including its associated protocol control block.
541
542 @param Sock Pointer to the socket to be cloned.
543
544 @return Pointer to the newly cloned socket. If NULL, error condition occurred.
545
546 **/
547 SOCKET *
548 SockClone (
549 IN SOCKET *Sock
550 );
551
552 /**
553 Signal the receive token with the specific error or
554 set socket error code after error is received.
555
556 @param Sock Pointer to the socket.
557 @param Error The error code received.
558
559 **/
560 VOID
561 SockRcvdErr (
562 IN OUT SOCKET *Sock,
563 IN EFI_STATUS Error
564 );
565
566 ///
567 /// Proto type of the create callback
568 ///
569 typedef
570 EFI_STATUS
571 (*SOCK_CREATE_CALLBACK) (
572 IN SOCKET *This,
573 IN VOID *Context
574 );
575
576 ///
577 /// Proto type of the destroy callback
578 ///
579 typedef
580 VOID
581 (*SOCK_DESTROY_CALLBACK) (
582 IN SOCKET *This,
583 IN VOID *Context
584 );
585
586 ///
587 /// The initialize data for create a new socket.
588 ///
589 typedef struct _SOCK_INIT_DATA {
590 SOCK_TYPE Type;
591 UINT8 State;
592
593 SOCKET *Parent; ///< The parent of this socket
594 UINT32 BackLog; ///< The connection limit for listening socket
595 UINT32 SndBufferSize; ///< The high warter mark of send buffer
596 UINT32 RcvBufferSize; ///< The high warter mark of receive buffer
597 VOID *Protocol; ///< The pointer to protocol function template
598 ///< wanted to install on socket
599
600 //
601 // Callbacks after socket is created and before socket is to be destroyed.
602 //
603 SOCK_CREATE_CALLBACK CreateCallback; ///< Callback after created
604 SOCK_DESTROY_CALLBACK DestroyCallback; ///< Callback before destroied
605 VOID *Context; ///< The context of the callback
606
607 //
608 // Opaque protocol data.
609 //
610 VOID *ProtoData;
611 UINT32 DataSize;
612
613 SOCK_PROTO_HANDLER ProtoHandler; ///< The handler of protocol for socket request
614
615 EFI_HANDLE DriverBinding; ///< The driver binding handle
616 } SOCK_INIT_DATA;
617
618 ///
619 /// The union type of TCP and UDP protocol.
620 ///
621 typedef union _NET_PROTOCOL {
622 EFI_TCP4_PROTOCOL TcpProtocol; ///< Tcp protocol
623 EFI_UDP4_PROTOCOL UdpProtocol; ///< Udp protocol
624 } NET_PROTOCOL;
625
626 ///
627 /// The socket structure representing a network service access point
628 ///
629 struct _SOCKET {
630
631 //
632 // Socket description information
633 //
634 UINT32 Signature; ///< Signature of the socket
635 EFI_HANDLE SockHandle; ///< The virtual handle of the socket
636 EFI_HANDLE DriverBinding; ///< Socket's driver binding protocol
637 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
638 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
639 LIST_ENTRY Link;
640 UINT8 ConfigureState;
641 SOCK_TYPE Type;
642 UINT8 State;
643 UINT16 Flag;
644 EFI_LOCK Lock; ///< The lock of socket
645 SOCK_BUFFER SndBuffer; ///< Send buffer of application's data
646 SOCK_BUFFER RcvBuffer; ///< Receive buffer of received data
647 EFI_STATUS SockError; ///< The error returned by low layer protocol
648 BOOLEAN IsDestroyed;
649
650 //
651 // Fields used to manage the connection request
652 //
653 UINT32 BackLog; ///< the limit of connection to this socket
654 UINT32 ConnCnt; ///< the current count of connections to it
655 SOCKET *Parent; ///< listening parent that accept the connection
656 LIST_ENTRY ConnectionList; ///< the connections maintained by this socket
657
658 //
659 // The queue to buffer application's asynchronous token
660 //
661 LIST_ENTRY ListenTokenList;
662 LIST_ENTRY RcvTokenList;
663 LIST_ENTRY SndTokenList;
664 LIST_ENTRY ProcessingSndTokenList;
665
666 SOCK_COMPLETION_TOKEN *ConnectionToken; ///< app's token to signal if connected
667 SOCK_COMPLETION_TOKEN *CloseToken; ///< app's token to signal if closed
668
669 //
670 // Interface for low level protocol
671 //
672 SOCK_PROTO_HANDLER ProtoHandler; ///< The request handler of protocol
673 UINT8 ProtoReserved[PROTO_RESERVED_LEN]; ///< Data fields reserved for protocol
674 NET_PROTOCOL NetProtocol; ///< TCP or UDP protocol socket used
675
676 //
677 // Callbacks after socket is created and before socket is to be destroyed.
678 //
679 SOCK_CREATE_CALLBACK CreateCallback; ///< Callback after created
680 SOCK_DESTROY_CALLBACK DestroyCallback; ///< Callback before destroied
681 VOID *Context; ///< The context of the callback
682 };
683
684 ///
685 /// The token structure buffered in socket layer.
686 ///
687 typedef struct _SOCK_TOKEN {
688 LIST_ENTRY TokenList; ///< The entry to add in the token list
689 SOCK_COMPLETION_TOKEN *Token; ///< The application's token
690 UINT32 RemainDataLen; ///< Unprocessed data length
691 SOCKET *Sock; ///< The poninter to the socket this token
692 ///< belongs to
693 } SOCK_TOKEN;
694
695 ///
696 /// Reserved data to access the NET_BUF delivered by UDP driver.
697 ///
698 typedef struct _UDP_RSV_DATA {
699 EFI_TIME TimeStamp;
700 EFI_UDP4_SESSION_DATA Session;
701 } UDP_RSV_DATA;
702
703 ///
704 /// Reserved data to access the NET_BUF delivered by TCP driver.
705 ///
706 typedef struct _TCP_RSV_DATA {
707 UINT32 UrgLen;
708 } TCP_RSV_DATA;
709
710 /**
711 Create a socket and its associated protocol control block
712 with the intial data SockInitData and protocol specific
713 data ProtoData.
714
715 @param SockInitData Inital data to setting the socket.
716
717 @return Pointer to the newly created socket. If NULL, error condition occured.
718
719 **/
720 SOCKET *
721 SockCreateChild (
722 IN SOCK_INIT_DATA *SockInitData
723 );
724
725 /**
726 Destory the socket Sock and its associated protocol control block.
727
728 @param Sock The socket to be destroyed.
729
730 @retval EFI_SUCCESS The socket Sock is destroyed successfully.
731 @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket.
732
733 **/
734 EFI_STATUS
735 SockDestroyChild (
736 IN SOCKET *Sock
737 );
738
739 /**
740 Configure the specific socket Sock using configuration data ConfigData.
741
742 @param Sock Pointer to the socket to be configured.
743 @param ConfigData Pointer to the configuration data.
744
745 @retval EFI_SUCCESS The socket is configured successfully.
746 @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket or the
747 socket is already configured.
748
749 **/
750 EFI_STATUS
751 SockConfigure (
752 IN SOCKET *Sock,
753 IN VOID *ConfigData
754 );
755
756 /**
757 Initiate a connection establishment process.
758
759 @param Sock Pointer to the socket to initiate the initate the
760 connection.
761 @param Token Pointer to the token used for the connection
762 operation.
763
764 @retval EFI_SUCCESS The connection is initialized successfully.
765 @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
766 socket is closed, or the socket is not configured to
767 be an active one, or the token is already in one of
768 this socket's lists.
769 @retval EFI_NO_MAPPING The IP address configuration operation is not
770 finished.
771 @retval EFI_NOT_STARTED The socket is not configured.
772
773 **/
774 EFI_STATUS
775 SockConnect (
776 IN SOCKET *Sock,
777 IN VOID *Token
778 );
779
780 /**
781 Issue a listen token to get an existed connected network instance
782 or wait for a connection if there is none.
783
784 @param Sock Pointer to the socket to accept connections.
785 @param Token The token to accept a connection.
786
787 @retval EFI_SUCCESS Either a connection is accpeted or the Token is
788 buffered for further acception.
789 @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
790 socket is closed, or the socket is not configured to
791 be a passive one, or the token is already in one of
792 this socket's lists.
793 @retval EFI_NO_MAPPING The IP address configuration operation is not
794 finished.
795 @retval EFI_NOT_STARTED The socket is not configured.
796 @retval EFI_OUT_OF_RESOURCE Failed to buffer the Token due to memory limit.
797
798 **/
799 EFI_STATUS
800 SockAccept (
801 IN SOCKET *Sock,
802 IN VOID *Token
803 );
804
805 /**
806 Issue a token with data to the socket to send out.
807
808 @param Sock Pointer to the socket to process the token with
809 data.
810 @param Token The token with data that needs to send out.
811
812 @retval EFI_SUCCESS The token is processed successfully.
813 @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
814 socket is closed, or the socket is not in a
815 synchronized state , or the token is already in one
816 of this socket's lists.
817 @retval EFI_NO_MAPPING The IP address configuration operation is not
818 finished.
819 @retval EFI_NOT_STARTED The socket is not configured.
820 @retval EFI_OUT_OF_RESOURCE Failed to buffer the token due to memory limit.
821
822 **/
823 EFI_STATUS
824 SockSend (
825 IN SOCKET *Sock,
826 IN VOID *Token
827 );
828
829 /**
830 Issue a token to get data from the socket.
831
832 @param Sock Pointer to the socket to get data from.
833 @param Token The token to store the received data from the
834 socket.
835
836 @retval EFI_SUCCESS The token is processed successfully.
837 @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
838 socket is closed, or the socket is not in a
839 synchronized state , or the token is already in one
840 of this socket's lists.
841 @retval EFI_NO_MAPPING The IP address configuration operation is not
842 finished.
843 @retval EFI_NOT_STARTED The socket is not configured.
844 @retval EFI_CONNECTION_FIN The connection is closed and there is no more data.
845 @retval EFI_OUT_OF_RESOURCE Failed to buffer the token due to memory limit.
846
847 **/
848 EFI_STATUS
849 SockRcv (
850 IN SOCKET *Sock,
851 IN VOID *Token
852 );
853
854 /**
855 Reset the socket and its associated protocol control block.
856
857 @param Sock Pointer to the socket to be flushed.
858
859 @retval EFI_SUCCESS The socket is flushed successfully.
860 @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket.
861
862 **/
863 EFI_STATUS
864 SockFlush (
865 IN SOCKET *Sock
866 );
867
868 /**
869 Close or abort the socket associated connection.
870
871 @param Sock Pointer to the socket of the connection to close or
872 abort.
873 @param Token The token for close operation.
874 @param OnAbort TRUE for aborting the connection, FALSE to close it.
875
876 @retval EFI_SUCCESS The close or abort operation is initialized
877 successfully.
878 @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
879 socket is closed, or the socket is not in a
880 synchronized state , or the token is already in one
881 of this socket's lists.
882 @retval EFI_NO_MAPPING The IP address configuration operation is not
883 finished.
884 @retval EFI_NOT_STARTED The socket is not configured.
885
886 **/
887 EFI_STATUS
888 SockClose (
889 IN SOCKET *Sock,
890 IN VOID *Token,
891 IN BOOLEAN OnAbort
892 );
893
894 /**
895 Get the mode data of the low layer protocol.
896
897 @param Sock Pointer to the socket to get mode data from.
898 @param Mode Pointer to the data to store the low layer mode
899 information.
900
901 @retval EFI_SUCCESS The mode data is got successfully.
902 @retval EFI_NOT_STARTED The socket is not configured.
903
904 **/
905 EFI_STATUS
906 SockGetMode (
907 IN SOCKET *Sock,
908 IN OUT VOID *Mode
909 );
910
911 /**
912 Configure the low level protocol to join a multicast group for
913 this socket's connection.
914
915 @param Sock Pointer to the socket of the connection to join the
916 specific multicast group.
917 @param GroupInfo Pointer to the multicast group info.
918
919 @retval EFI_SUCCESS The configuration is done successfully.
920 @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket.
921 @retval EFI_NOT_STARTED The socket is not configured.
922
923 **/
924 EFI_STATUS
925 SockGroup (
926 IN SOCKET *Sock,
927 IN VOID *GroupInfo
928 );
929
930 /**
931 Add or remove route information in IP route table associated
932 with this socket.
933
934 @param Sock Pointer to the socket associated with the IP route
935 table to operate on.
936 @param RouteInfo Pointer to the route information to be processed.
937
938 @retval EFI_SUCCESS The route table is updated successfully.
939 @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket.
940 @retval EFI_NO_MAPPING The IP address configuration operation is not
941 finished.
942 @retval EFI_NOT_STARTED The socket is not configured.
943
944 **/
945 EFI_STATUS
946 SockRoute (
947 IN SOCKET *Sock,
948 IN VOID *RouteInfo
949 );
950
951 //
952 // Supporting function to operate on socket buffer
953 //
954
955 /**
956 Get the first buffer block in the specific socket buffer.
957
958 @param Sockbuf Pointer to the socket buffer.
959
960 @return Pointer to the first buffer in the queue. NULL if the queue is empty.
961
962 **/
963 NET_BUF *
964 SockBufFirst (
965 IN SOCK_BUFFER *Sockbuf
966 );
967
968 /**
969 Get the next buffer block in the specific socket buffer.
970
971 @param Sockbuf Pointer to the socket buffer.
972 @param SockEntry Pointer to the buffer block prior to the required
973 one.
974
975 @return Pointer to the buffer block next to SockEntry. NULL if SockEntry is
976 the tail or head entry.
977
978 **/
979 NET_BUF *
980 SockBufNext (
981 IN SOCK_BUFFER *Sockbuf,
982 IN NET_BUF *SockEntry
983 );
984
985 #endif