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