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