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