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