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