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