]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/EfiSocketLib/Socket.h
Merged socket development branch
[mirror_edk2.git] / StdLib / EfiSocketLib / Socket.h
CommitLineData
d7ce7006 1/** @file\r
2 Definitions for the Socket layer driver.\r
3\r
4 Copyright (c) 2011, Intel Corporation\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14#ifndef _SOCKET_H_\r
15#define _SOCKET_H_\r
16\r
17#include <Efi/EfiSocketLib.h>\r
18\r
19//------------------------------------------------------------------------------\r
20// Constants\r
21//------------------------------------------------------------------------------\r
22\r
23#define DEBUG_SOCKET 0x20000000 ///< Display Socket related messages\r
24#define DEBUG_BIND 0x10000000 ///< Display bind related messages\r
25#define DEBUG_LISTEN 0x08000000 ///< Display listen related messages\r
26#define DEBUG_CONNECTION 0x04000000 ///< Display connection list related messages\r
27#define DEBUG_POLL 0x02000000 ///< Display poll messages\r
28#define DEBUG_ACCEPT 0x01000000 ///< Display accept related messages\r
29#define DEBUG_RX 0x00800000 ///< Display receive messages\r
30#define DEBUG_TX 0x00400000 ///< Display transmit messages\r
31#define DEBUG_CLOSE 0x00200000 ///< Display close messages\r
32#define DEBUG_CONNECT 0x00100000 ///< Display connect messages\r
a88c3163 33#define DEBUG_OPTION 0x00080000 ///< Display option messages\r
d7ce7006 34\r
35#define MAX_PENDING_CONNECTIONS 1 ///< Maximum connection FIFO depth\r
36#define MAX_RX_DATA 65536 ///< Maximum receive data size\r
a88c3163 37#define MAX_TX_DATA ( MAX_RX_DATA * 2 ) ///< Maximum buffered transmit data in bytes\r
d7ce7006 38#define RX_PACKET_DATA 16384 ///< Maximum number of bytes in a RX packet\r
a88c3163 39#define MAX_UDP_RETRANSMIT 16 ///< UDP retransmit attempts to handle address not mapped\r
d7ce7006 40\r
a88c3163 41#define ESL_STRUCTURE_ALIGNMENT_BYTES 15 ///< Number of bytes for structure alignment\r
42#define ESL_STRUCTURE_ALIGNMENT_MASK ( ~ESL_STRUCTURE_ALIGNMENT_BYTES ) ///< Mask to align structures\r
d7ce7006 43\r
a88c3163 44#define LAYER_SIGNATURE SIGNATURE_32 ('S','k','t','L') ///< ESL_LAYER memory signature\r
45#define SERVICE_SIGNATURE SIGNATURE_32 ('S','k','t','S') ///< ESL_SERVICE memory signature\r
46#define SOCKET_SIGNATURE SIGNATURE_32 ('S','c','k','t') ///< ESL_SOCKET memory signature\r
47#define PORT_SIGNATURE SIGNATURE_32 ('P','o','r','t') ///< ESL_PORT memory signature\r
d7ce7006 48\r
a88c3163 49\r
50/**\r
51 Socket states\r
52**/\r
d7ce7006 53typedef enum\r
54{\r
55 SOCKET_STATE_NOT_CONFIGURED = 0, ///< socket call was successful\r
56 SOCKET_STATE_BOUND, ///< bind call was successful\r
57 SOCKET_STATE_LISTENING, ///< listen call was successful\r
58 SOCKET_STATE_NO_PORTS, ///< No ports available\r
59 SOCKET_STATE_IN_FIFO, ///< Socket on FIFO\r
60 SOCKET_STATE_CONNECTING, ///< Connecting to a remote system\r
61 SOCKET_STATE_CONNECTED, ///< Accept or connect call was successful\r
62\r
63 //\r
64 // Close state must be the last in the list\r
65 //\r
66 SOCKET_STATE_CLOSED ///< Close call was successful\r
67} SOCKET_STATE;\r
68\r
a88c3163 69\r
70/**\r
71 Port states\r
72**/\r
d7ce7006 73typedef enum\r
74{\r
75 PORT_STATE_ALLOCATED = 0, ///< Port allocated\r
76 PORT_STATE_OPEN, ///< Port opened\r
77 PORT_STATE_RX_ERROR, ///< Receive error detected\r
78\r
79 //\r
a88c3163 80 // Close state must be last in the list!\r
81 //\r
82 // Using < <= > >= in tests code to detect port close state\r
83 // machine has started\r
d7ce7006 84 //\r
85 PORT_STATE_CLOSE_STARTED, ///< Close started on port\r
86 PORT_STATE_CLOSE_TX_DONE, ///< Transmits shutdown\r
a88c3163 87 PORT_STATE_CLOSE_DONE, ///< Port close operation complete\r
88 PORT_STATE_CLOSE_RX_DONE ///< Receives shutdown\r
d7ce7006 89} PORT_STATE;\r
90\r
91//------------------------------------------------------------------------------\r
92// Data Types\r
93//------------------------------------------------------------------------------\r
94\r
a88c3163 95typedef struct _ESL_IO_MGMT ESL_IO_MGMT;///< Forward declaration\r
96typedef struct _ESL_PACKET ESL_PACKET; ///< Forward declaration\r
97typedef struct _ESL_PORT ESL_PORT; ///< Forward declaration\r
98typedef struct _ESL_SOCKET ESL_SOCKET; ///< Forward declaration\r
99\r
100/**\r
101 Receive context for SOCK_RAW sockets using IPv4.\r
102**/\r
103typedef struct\r
104{\r
105 EFI_IP4_RECEIVE_DATA * pRxData; ///< Receive operation description\r
106} ESL_IP4_RX_DATA;\r
107\r
108\r
109/**\r
110 Transmit context for SOCK_RAW sockets using IPv4.\r
111**/\r
112typedef struct\r
113{\r
114 EFI_IP4_OVERRIDE_DATA Override; ///< Override data\r
115 EFI_IP4_TRANSMIT_DATA TxData; ///< Transmit operation description\r
116 UINT8 Buffer[ 1 ]; ///< Data buffer\r
117} ESL_IP4_TX_DATA;\r
d7ce7006 118\r
a88c3163 119\r
120/**\r
121 Receive context for SOCK_STREAM and SOCK_SEQPACKET sockets using TCPv4.\r
122**/\r
d7ce7006 123typedef struct\r
124{\r
125 EFI_TCP4_RECEIVE_DATA RxData; ///< Receive operation description\r
a88c3163 126 UINT8 Buffer[ RX_PACKET_DATA ]; ///< Data buffer\r
127} ESL_TCP4_RX_DATA;\r
128\r
d7ce7006 129\r
a88c3163 130/**\r
131 Transmit context for SOCK_STREAM and SOCK_SEQPACKET sockets using TCPv4.\r
132**/\r
d7ce7006 133typedef struct\r
134{\r
135 EFI_TCP4_TRANSMIT_DATA TxData; ///< Transmit operation description\r
a88c3163 136 UINT8 Buffer[ 1 ]; ///< Data buffer\r
137} ESL_TCP4_TX_DATA;\r
d7ce7006 138\r
a88c3163 139\r
140/**\r
141 Receive context for SOCK_DGRAM sockets using UDPv4.\r
142**/\r
d7ce7006 143typedef struct\r
144{\r
a88c3163 145 EFI_UDP4_SESSION_DATA Session; ///< Remote network address\r
146 EFI_UDP4_RECEIVE_DATA * pRxData; ///< Receive operation description\r
147} ESL_UDP4_RX_DATA;\r
d7ce7006 148\r
a88c3163 149\r
150/**\r
151 Transmit context for SOCK_DGRAM sockets using UDPv4.\r
152**/\r
d7ce7006 153typedef struct\r
154{\r
155 EFI_UDP4_SESSION_DATA Session; ///< Remote network address\r
156 EFI_UDP4_TRANSMIT_DATA TxData; ///< Transmit operation description\r
a88c3163 157 UINTN RetransmitCount; ///< Retransmit to handle ARP negotiation\r
158 UINT8 Buffer[ 1 ]; ///< Data buffer\r
159} ESL_UDP4_TX_DATA;\r
160\r
d7ce7006 161\r
a88c3163 162/**\r
163 Network specific context for transmit and receive packets.\r
164**/\r
165typedef struct _ESL_PACKET {\r
166 ESL_PACKET * pNext; ///< Next packet in the receive list\r
d7ce7006 167 size_t PacketSize; ///< Size of this data structure\r
a88c3163 168 size_t ValidBytes; ///< Length of valid data in bytes\r
169 UINT8 * pBuffer; ///< Current data pointer\r
d7ce7006 170 union {\r
a88c3163 171 ESL_IP4_RX_DATA Ip4Rx; ///< Receive operation description\r
172 ESL_IP4_TX_DATA Ip4Tx; ///< Transmit operation description\r
173 ESL_TCP4_RX_DATA Tcp4Rx; ///< Receive operation description\r
174 ESL_TCP4_TX_DATA Tcp4Tx; ///< Transmit operation description\r
175 ESL_UDP4_RX_DATA Udp4Rx; ///< Receive operation description\r
176 ESL_UDP4_TX_DATA Udp4Tx; ///< Transmit operation description\r
177 } Op; ///< Network specific context\r
178} GCC_ESL_PACKET;\r
d7ce7006 179\r
180/**\r
181 Service control structure\r
182\r
183 The driver uses this structure to manage the network devices.\r
184**/\r
a88c3163 185typedef struct _ESL_SERVICE {\r
d7ce7006 186 UINTN Signature; ///< Structure identification\r
187\r
188 //\r
189 // Links\r
190 //\r
a88c3163 191 ESL_SERVICE * pNext; ///< Next service in the service list\r
d7ce7006 192\r
193 //\r
194 // Service data\r
195 //\r
a88c3163 196 CONST ESL_SOCKET_BINDING * pSocketBinding; ///< Name and shutdown routine\r
197 EFI_HANDLE Controller; ///< Controller for the service\r
198 EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding; ///< Network layer service binding interface\r
d7ce7006 199\r
200 //\r
201 // Network data\r
202 //\r
a88c3163 203 ESL_PORT * pPortList; ///< List of ports using this service\r
204}GCC_ESL_SERVICE;\r
d7ce7006 205\r
206/**\r
a88c3163 207 IO management structure\r
d7ce7006 208\r
a88c3163 209 This structure manages a single operation with the network.\r
210**/\r
211typedef struct _ESL_IO_MGMT {\r
212 ESL_IO_MGMT * pNext; ///< Next TX management structure\r
213 ESL_PORT * pPort; ///< Port structure address\r
214 ESL_PACKET * pPacket; ///< Packet structure address\r
215 union {\r
216 EFI_IP4_COMPLETION_TOKEN Ip4Rx; ///< IP4 receive token\r
217 EFI_IP4_COMPLETION_TOKEN Ip4Tx; ///< IP4 transmit token\r
218 EFI_TCP4_IO_TOKEN Tcp4Rx; ///< TCP4 receive token\r
219 EFI_TCP4_IO_TOKEN Tcp4Tx; ///< TCP4 transmit token\r
220 EFI_UDP4_COMPLETION_TOKEN Udp4Rx; ///< UDP4 receive token\r
221 EFI_UDP4_COMPLETION_TOKEN Udp4Tx; ///< UDP4 transmit token\r
222 } Token; ///< Completion token for the network operation\r
58081f2c 223} GCC_IO_MGMT;\r
a88c3163 224\r
225/**\r
226 IP4 context structure\r
d7ce7006 227\r
a88c3163 228 The driver uses this structure to manage the IP4 connections.\r
d7ce7006 229**/\r
a88c3163 230typedef struct {\r
231 //\r
232 // IP4 context\r
233 //\r
234 EFI_IP4_MODE_DATA ModeData; ///< IP4 mode data, includes configuration data\r
235 EFI_IPv4_ADDRESS DestinationAddress; ///< Default destination address\r
236} ESL_IP4_CONTEXT;\r
237\r
d7ce7006 238\r
239/**\r
240 TCP4 context structure\r
241\r
242 The driver uses this structure to manage the TCP4 connections.\r
243**/\r
244typedef struct {\r
245 //\r
246 // TCP4 context\r
247 //\r
a88c3163 248 EFI_TCP4_CONFIG_DATA ConfigData; ///< TCP4 configuration data\r
249 EFI_TCP4_OPTION Option; ///< TCP4 port options\r
d7ce7006 250\r
251 //\r
252 // Tokens\r
253 //\r
a88c3163 254 EFI_TCP4_LISTEN_TOKEN ListenToken; ///< Listen control\r
d7ce7006 255 EFI_TCP4_CONNECTION_TOKEN ConnectToken; ///< Connection control\r
a88c3163 256 EFI_TCP4_CLOSE_TOKEN CloseToken; ///< Close control\r
257} ESL_TCP4_CONTEXT;\r
d7ce7006 258\r
259/**\r
260 UDP4 context structure\r
261\r
262 The driver uses this structure to manage the UDP4 connections.\r
263**/\r
264typedef struct {\r
265 //\r
266 // UDP4 context\r
267 //\r
d7ce7006 268 EFI_UDP4_CONFIG_DATA ConfigData; ///< UDP4 configuration data\r
a88c3163 269} ESL_UDP4_CONTEXT;\r
d7ce7006 270\r
d7ce7006 271\r
a88c3163 272/**\r
273 Configure the network layer.\r
274\r
275 @param [in] pProtocol Protocol structure address\r
276 @param [in] pConfigData Address of the confiuration data\r
277\r
278 @return Returns EFI_SUCCESS if the operation is successfully\r
279 started.\r
280**/\r
281typedef\r
282EFI_STATUS\r
283(* PFN_NET_CONFIGURE) (\r
284 IN VOID * pProtocol,\r
285 IN VOID * pConfigData\r
286 );\r
287\r
288/**\r
289 Hand an I/O operation to the network layer.\r
290\r
291 @param [in] pProtocol Protocol structure address\r
292 @param [in] pToken Completion token address\r
d7ce7006 293\r
a88c3163 294 @return Returns EFI_SUCCESS if the operation is successfully\r
295 started.\r
296**/\r
297typedef\r
298EFI_STATUS\r
299(* PFN_NET_IO_START) (\r
300 IN VOID * pProtocol,\r
301 IN VOID * pToken\r
302 );\r
d7ce7006 303\r
304/**\r
305 Port control structure\r
306\r
307 The driver uses this structure to manager the socket's connection\r
308 with the network driver.\r
309**/\r
a88c3163 310typedef struct _ESL_PORT {\r
d7ce7006 311 UINTN Signature; ///< Structure identification\r
312\r
313 //\r
314 // List links\r
315 //\r
a88c3163 316 ESL_PORT * pLinkService; ///< Link in service port list\r
317 ESL_PORT * pLinkSocket; ///< Link in socket port list\r
d7ce7006 318\r
319 //\r
320 // Structures\r
321 //\r
a88c3163 322 ESL_SERVICE * pService; ///< Service for this port\r
323 ESL_SOCKET * pSocket; ///< Socket for this port\r
d7ce7006 324\r
325 //\r
a88c3163 326 // Eliminate the pService references during port close\r
d7ce7006 327 //\r
a88c3163 328 EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding; ///< Service binding for network layer\r
329 CONST ESL_SOCKET_BINDING * pSocketBinding; ///< Socket binding for network layer\r
d7ce7006 330\r
331 //\r
a88c3163 332 // Port management\r
d7ce7006 333 //\r
a88c3163 334 EFI_HANDLE Handle; ///< Network port handle\r
335 PORT_STATE State; ///< State of the port\r
336 UINTN DebugFlags; ///< Debug flags used to close the port\r
337 BOOLEAN bCloseNow; ///< TRUE = Close the port immediately\r
338 BOOLEAN bConfigured; ///< TRUE = Configure call made to network layer\r
339 PFN_NET_CONFIGURE pfnConfigure; ///< Configure the network layer\r
d7ce7006 340\r
341 //\r
342 // Transmit data management\r
343 //\r
a88c3163 344 BOOLEAN bTxFlowControl; ///< TX flow control applied\r
345 PFN_NET_IO_START pfnTxStart; ///< Start a transmit on the network\r
346 ESL_IO_MGMT * pTxActive; ///< Normal data queue\r
347 ESL_IO_MGMT * pTxFree; ///< Normal free queue\r
d7ce7006 348\r
a88c3163 349 ESL_IO_MGMT * pTxOobActive; ///< Urgent data queue\r
350 ESL_IO_MGMT * pTxOobFree; ///< Urgent free queue\r
d7ce7006 351\r
352 //\r
a88c3163 353 // Receive data management\r
d7ce7006 354 //\r
a88c3163 355 PFN_NET_IO_START pfnRxCancel; ///< Cancel a receive on the network\r
356 PFN_NET_IO_START pfnRxStart; ///< Start a receive on the network\r
357 ESL_IO_MGMT * pRxActive; ///< Active receive operation queue\r
358 ESL_IO_MGMT * pRxFree; ///< Free structure queue\r
d7ce7006 359\r
360 //\r
a88c3163 361 // Protocol specific management data\r
d7ce7006 362 //\r
a88c3163 363 union {\r
364 VOID * v; ///< VOID pointer\r
365 EFI_IP4_PROTOCOL * IPv4; ///< IP4 protocol pointer\r
366 EFI_TCP4_PROTOCOL * TCPv4; ///< TCP4 protocol pointer\r
367 EFI_UDP4_PROTOCOL * UDPv4; ///< UDP4 protocol pointer\r
368 } pProtocol; ///< Protocol structure address\r
369 union {\r
370 ESL_IP4_CONTEXT Ip4; ///< IPv4 management data\r
371 ESL_TCP4_CONTEXT Tcp4; ///< TCPv4 management data\r
372 ESL_UDP4_CONTEXT Udp4; ///< UDPv4 management data\r
373 } Context; ///< Network specific context\r
374}GCC_ESL_PORT;\r
d7ce7006 375\r
376/**\r
377 Accept a network connection.\r
378\r
d7ce7006 379 @param [in] pSocket Address of the socket structure.\r
380\r
381 @param [in] pSockAddr Address of a buffer to receive the remote\r
382 network address.\r
383\r
384 @param [in, out] pSockAddrLength Length in bytes of the address buffer.\r
385 On output specifies the length of the\r
386 remote network address.\r
387\r
388 @retval EFI_SUCCESS Remote address is available\r
389 @retval Others Remote address not available\r
390\r
391 **/\r
a88c3163 392typedef\r
d7ce7006 393EFI_STATUS\r
a88c3163 394(* PFN_API_ACCEPT) (\r
395 IN ESL_SOCKET * pSocket,\r
d7ce7006 396 IN struct sockaddr * pSockAddr,\r
397 IN OUT socklen_t * pSockAddrLength\r
398 );\r
399\r
400/**\r
a88c3163 401 Poll for completion of the connection attempt.\r
d7ce7006 402\r
a88c3163 403 @param [in] pSocket Address of an ::ESL_SOCKET structure.\r
d7ce7006 404\r
a88c3163 405 @retval EFI_SUCCESS The connection was successfully established.\r
406 @retval EFI_NOT_READY The connection is in progress, call this routine again.\r
407 @retval Others The connection attempt failed.\r
d7ce7006 408\r
409 **/\r
a88c3163 410typedef\r
d7ce7006 411EFI_STATUS\r
a88c3163 412(* PFN_API_CONNECT_POLL) (\r
413 IN ESL_SOCKET * pSocket\r
d7ce7006 414 );\r
415\r
416/**\r
a88c3163 417 Attempt to connect to a remote TCP port\r
418\r
419 This routine starts the connection processing for a SOCK_STREAM\r
420 or SOCK_SEQPAKCET socket using the TCP network layer.\r
d7ce7006 421\r
a88c3163 422 This routine is called by ::EslSocketConnect to initiate the TCP\r
423 network specific connect operations.\r
d7ce7006 424\r
a88c3163 425 @param [in] pSocket Address of an ::ESL_SOCKET structure.\r
d7ce7006 426\r
427 @retval EFI_SUCCESS The connection was successfully established.\r
428 @retval EFI_NOT_READY The connection is in progress, call this routine again.\r
429 @retval Others The connection attempt failed.\r
430\r
431 **/\r
a88c3163 432typedef\r
d7ce7006 433EFI_STATUS\r
a88c3163 434(* PFN_API_CONNECT_START) (\r
435 IN ESL_SOCKET * pSocket\r
d7ce7006 436 );\r
437\r
438/**\r
a88c3163 439 Get the local socket address\r
d7ce7006 440\r
a88c3163 441 @param [in] pPort Address of an ::ESL_PORT structure.\r
d7ce7006 442\r
a88c3163 443 @param [out] pAddress Network address to receive the local system address\r
d7ce7006 444\r
445**/\r
a88c3163 446typedef\r
447VOID\r
448(* PFN_API_LOCAL_ADDR_GET) (\r
449 IN ESL_PORT * pPort,\r
450 OUT struct sockaddr * pAddress\r
d7ce7006 451 );\r
452\r
453/**\r
a88c3163 454 Set the local port address.\r
d7ce7006 455\r
a88c3163 456 This routine sets the local port address.\r
d7ce7006 457\r
a88c3163 458 This support routine is called by ::EslSocketPortAllocate.\r
d7ce7006 459\r
a88c3163 460 @param [in] ppPort Address of an ESL_PORT structure\r
461 @param [in] pSockAddr Address of a sockaddr structure that contains the\r
462 connection point on the local machine. An IPv4 address\r
463 of INADDR_ANY specifies that the connection is made to\r
464 all of the network stacks on the platform. Specifying a\r
465 specific IPv4 address restricts the connection to the\r
466 network stack supporting that address. Specifying zero\r
467 for the port causes the network layer to assign a port\r
468 number from the dynamic range. Specifying a specific\r
469 port number causes the network layer to use that port.\r
470 @param [in] bBindTest TRUE = run bind testing\r
d7ce7006 471\r
a88c3163 472 @retval EFI_SUCCESS The operation was successful\r
d7ce7006 473\r
a88c3163 474 **/\r
475typedef\r
d7ce7006 476EFI_STATUS\r
a88c3163 477(* PFN_API_LOCAL_ADDR_SET) (\r
478 IN ESL_PORT * pPort,\r
479 IN CONST struct sockaddr * pSockAddr,\r
480 IN BOOLEAN bBindTest\r
d7ce7006 481 );\r
482\r
58081f2c 483/**\r
484 Process the completion event\r
485\r
486 This routine handles the I/O completion event.\r
487\r
488 This routine is called by the low level network driver when\r
489 the operation is completed.\r
490\r
491 @param [in] Event The receive completion event\r
492\r
493 @param [in] pIo The address of an ::ESL_IO_MGMT structure\r
494\r
495**/\r
496typedef\r
497VOID\r
498(* PFN_API_IO_COMPLETE) (\r
499 IN EFI_EVENT Event,\r
500 IN ESL_IO_MGMT * pIo\r
501 );\r
502\r
d7ce7006 503/**\r
a88c3163 504 Determine if the socket is configured.\r
d7ce7006 505\r
d7ce7006 506\r
a88c3163 507 @param [in] pSocket Address of a ESL_SOCKET structure\r
508 \r
509 @retval EFI_SUCCESS - The port is connected\r
510 @retval EFI_NOT_STARTED - The port is not connected\r
d7ce7006 511\r
a88c3163 512 **/\r
513 typedef\r
514 EFI_STATUS\r
515 (* PFN_API_IS_CONFIGURED) (\r
516 IN ESL_SOCKET * pSocket\r
d7ce7006 517 );\r
518\r
519/**\r
520 Establish the known port to listen for network connections.\r
521\r
d7ce7006 522 @param [in] pSocket Address of the socket structure.\r
a88c3163 523\r
d7ce7006 524 @retval EFI_SUCCESS - Socket successfully created\r
525 @retval Other - Failed to enable the socket for listen\r
526\r
527**/\r
a88c3163 528typedef\r
d7ce7006 529EFI_STATUS\r
a88c3163 530(* PFN_API_LISTEN) (\r
531 IN ESL_SOCKET * pSocket\r
d7ce7006 532 );\r
533\r
534/**\r
a88c3163 535 Get the option value\r
d7ce7006 536\r
a88c3163 537 Retrieve the protocol options one at a time by name.\r
d7ce7006 538\r
a88c3163 539 @param [in] pSocket Address of a ESL_SOCKET structure\r
540 @param [in] OptionName Name of the option\r
541 @param [out] ppOptionData Buffer to receive address of option value\r
542 @param [out] pOptionLength Buffer to receive the option length\r
d7ce7006 543\r
a88c3163 544 @retval EFI_SUCCESS - Socket data successfully received\r
d7ce7006 545\r
546 **/\r
a88c3163 547typedef\r
d7ce7006 548EFI_STATUS\r
a88c3163 549(* PFN_API_OPTION_GET) (\r
550 IN ESL_SOCKET * pSocket,\r
551 IN int OptionName,\r
552 OUT CONST void ** __restrict ppOptionData,\r
553 OUT socklen_t * __restrict pOptionLength\r
d7ce7006 554 );\r
555\r
556/**\r
a88c3163 557 Set the option value\r
d7ce7006 558\r
a88c3163 559 Adjust the protocol options one at a time by name.\r
d7ce7006 560\r
a88c3163 561 @param [in] pSocket Address of a ESL_SOCKET structure\r
562 @param [in] OptionName Name of the option\r
563 @param [in] pOptionValue Buffer containing the option value\r
564 @param [in] OptionLength Length of the buffer in bytes\r
d7ce7006 565\r
a88c3163 566 @retval EFI_SUCCESS - Option successfully set\r
567\r
568 **/\r
569typedef\r
d7ce7006 570EFI_STATUS\r
a88c3163 571(* PFN_API_OPTION_SET) (\r
572 IN ESL_SOCKET * pSocket,\r
573 IN int OptionName,\r
574 IN CONST void * pOptionValue,\r
575 IN socklen_t OptionLength\r
d7ce7006 576 );\r
577\r
578/**\r
a88c3163 579 Free a receive packet\r
d7ce7006 580\r
a88c3163 581 This routine performs the network specific operations necessary\r
582 to free a receive packet.\r
d7ce7006 583\r
a88c3163 584 This routine is called by ::EslSocketPortCloseTxDone to free a\r
585 receive packet.\r
586\r
587 @param [in] pPacket Address of an ::ESL_PACKET structure.\r
588 @param [in, out] pRxBytes Address of the count of RX bytes\r
d7ce7006 589\r
590**/\r
a88c3163 591typedef\r
d7ce7006 592VOID\r
a88c3163 593(* PFN_API_PACKET_FREE) (\r
594 IN ESL_PACKET * pPacket,\r
595 IN OUT size_t * pRxBytes\r
d7ce7006 596 );\r
597\r
598/**\r
a88c3163 599 Initialize the network specific portions of an ::ESL_PORT structure.\r
d7ce7006 600\r
a88c3163 601 This routine initializes the network specific portions of an\r
602 ::ESL_PORT structure for use by the socket.\r
d7ce7006 603\r
a88c3163 604 This support routine is called by ::EslSocketPortAllocate\r
605 to connect the socket with the underlying network adapter\r
606 running the IPv4 protocol.\r
d7ce7006 607\r
a88c3163 608 @param [in] ppPort Address of an ESL_PORT structure\r
609 @param [in] DebugFlags Flags for debug messages\r
d7ce7006 610\r
a88c3163 611 @retval EFI_SUCCESS - Socket successfully created\r
612\r
613 **/\r
614typedef\r
d7ce7006 615EFI_STATUS\r
a88c3163 616(* PFN_API_PORT_ALLOC) (\r
617 IN ESL_PORT * pPort,\r
618 IN UINTN DebugFlags\r
d7ce7006 619 );\r
620\r
621/**\r
a88c3163 622 Close a network specific port.\r
d7ce7006 623\r
a88c3163 624 This routine releases the resources allocated by the\r
625 network specific PortAllocate routine.\r
626\r
627 This routine is called by ::EslSocketPortCloseRxDone as\r
628 the last step of closing processing.\r
629 See the \ref PortCloseStateMachine section.\r
630 \r
631 @param [in] pPort Address of an ::ESL_PORT structure.\r
632\r
633 @retval EFI_SUCCESS The port is closed\r
634 @retval other Port close error\r
d7ce7006 635\r
636**/\r
a88c3163 637typedef\r
d7ce7006 638EFI_STATUS\r
a88c3163 639(* PFN_API_PORT_CLOSE) (\r
640 IN ESL_PORT * pPort\r
d7ce7006 641 );\r
642\r
643/**\r
a88c3163 644 Perform the network specific close operation on the port.\r
d7ce7006 645\r
a88c3163 646 This routine performs the network specific operation to\r
647 shutdown receive operations on the port.\r
d7ce7006 648\r
a88c3163 649 This routine is called by the ::EslSocketPortCloseTxDone\r
650 routine after the port completes all of the transmission.\r
d7ce7006 651\r
a88c3163 652 @param [in] pPort Address of an ::ESL_PORT structure.\r
653\r
654 @retval EFI_SUCCESS The port is closed, not normally returned\r
d7ce7006 655 @retval EFI_NOT_READY The port is still closing\r
656 @retval EFI_ALREADY_STARTED Error, the port is in the wrong state,\r
657 most likely the routine was called already.\r
658\r
659**/\r
a88c3163 660typedef\r
d7ce7006 661EFI_STATUS\r
a88c3163 662(* PFN_API_PORT_CLOSE_OP) (\r
663 IN ESL_PORT * pPort\r
d7ce7006 664 );\r
665\r
666/**\r
667 Receive data from a network connection.\r
668\r
a88c3163 669 This routine attempts to return buffered data to the caller. The\r
670 data is removed from the urgent queue if the message flag MSG_OOB\r
671 is specified, otherwise data is removed from the normal queue.\r
672 See the \ref ReceiveEngine section.\r
d7ce7006 673\r
a88c3163 674 This routine is called by ::EslSocketReceive to handle the network\r
675 specific receive operation.\r
676\r
677 @param [in] pPort Address of an ::ESL_PORT structure.\r
678\r
679 @param [in] pPacket Address of an ::ESL_PACKET structure.\r
d7ce7006 680 \r
a88c3163 681 @param [in] pbConsumePacket Address of a BOOLEAN indicating if the packet is to be consumed\r
d7ce7006 682 \r
683 @param [in] BufferLength Length of the the buffer\r
684 \r
685 @param [in] pBuffer Address of a buffer to receive the data.\r
686 \r
687 @param [in] pDataLength Number of received data bytes in the buffer.\r
688\r
689 @param [out] pAddress Network address to receive the remote system address\r
690\r
a88c3163 691 @param [out] pSkipBytes Address to receive the number of bytes skipped\r
d7ce7006 692\r
a88c3163 693 @return Returns the address of the next free byte in the buffer.\r
d7ce7006 694\r
695 **/\r
a88c3163 696typedef\r
697UINT8 *\r
698(* PFN_API_RECEIVE) (\r
699 IN ESL_PORT * pPort,\r
700 IN ESL_PACKET * pPacket,\r
701 IN BOOLEAN * pbConsumePacket,\r
d7ce7006 702 IN size_t BufferLength,\r
703 IN UINT8 * pBuffer,\r
704 OUT size_t * pDataLength,\r
705 OUT struct sockaddr * pAddress,\r
a88c3163 706 OUT size_t * pSkipBytes\r
d7ce7006 707 );\r
708\r
709/**\r
a88c3163 710 Get the remote socket address\r
d7ce7006 711\r
a88c3163 712 @param [in] pPort Address of an ::ESL_PORT structure.\r
d7ce7006 713\r
a88c3163 714 @param [out] pAddress Network address to receive the remote system address\r
715\r
716**/\r
717typedef\r
718VOID\r
719(* PFN_API_REMOTE_ADDR_GET) (\r
720 IN ESL_PORT * pPort,\r
721 OUT struct sockaddr * pAddress\r
d7ce7006 722 );\r
723\r
724/**\r
a88c3163 725 Set the remote address\r
d7ce7006 726\r
a88c3163 727 This routine sets the remote address in the port.\r
d7ce7006 728\r
a88c3163 729 This routine is called by ::EslSocketConnect to specify the\r
730 remote network address.\r
d7ce7006 731\r
a88c3163 732 @param [in] pPort Address of an ::ESL_PORT structure.\r
d7ce7006 733\r
a88c3163 734 @param [in] pSockAddr Network address of the remote system.\r
d7ce7006 735\r
a88c3163 736 @param [in] SockAddrLength Length in bytes of the network address.\r
d7ce7006 737\r
a88c3163 738 @retval EFI_SUCCESS The operation was successful\r
d7ce7006 739\r
740 **/\r
a88c3163 741typedef\r
742EFI_STATUS\r
743(* PFN_API_REMOTE_ADDR_SET) (\r
744 IN ESL_PORT * pPort,\r
745 IN CONST struct sockaddr * pSockAddr,\r
746 IN socklen_t SockAddrLength\r
d7ce7006 747 );\r
748\r
d7ce7006 749/**\r
a88c3163 750 Start a receive operation\r
d7ce7006 751\r
a88c3163 752 This routine prepares a packet for the receive operation.\r
753 See the \ref ReceiveEngine section.\r
d7ce7006 754\r
a88c3163 755 This support routine is called by EslSocketRxStart.\r
756\r
757 @param [in] pPort Address of an ::ESL_PORT structure.\r
758 @param [in] pIo Address of an ::ESL_IO_MGMT structure.\r
d7ce7006 759\r
760 **/\r
a88c3163 761typedef\r
762VOID\r
763(* PFN_API_RX_START) (\r
764 IN ESL_PORT * pPort,\r
765 IN ESL_IO_MGMT * pIo\r
d7ce7006 766 );\r
767\r
768/**\r
769 Buffer data for transmission over a network connection.\r
770\r
a88c3163 771 @param [in] pSocket Address of a ESL_SOCKET structure\r
d7ce7006 772\r
d7ce7006 773 @param [in] Flags Message control flags\r
a88c3163 774\r
d7ce7006 775 @param [in] BufferLength Length of the the buffer\r
a88c3163 776\r
d7ce7006 777 @param [in] pBuffer Address of a buffer to receive the data.\r
a88c3163 778\r
d7ce7006 779 @param [in] pDataLength Number of received data bytes in the buffer.\r
780\r
a88c3163 781 @param [in] pAddress Network address of the remote system address\r
782\r
783 @param [in] AddressLength Length of the remote network address structure\r
784\r
d7ce7006 785 @retval EFI_SUCCESS - Socket data successfully buffered\r
786\r
a88c3163 787**/\r
788typedef\r
d7ce7006 789EFI_STATUS\r
a88c3163 790(* PFN_API_TRANSMIT) (\r
791 IN ESL_SOCKET * pSocket,\r
d7ce7006 792 IN int Flags,\r
793 IN size_t BufferLength,\r
794 IN CONST UINT8 * pBuffer,\r
a88c3163 795 OUT size_t * pDataLength,\r
796 IN const struct sockaddr * pAddress,\r
797 IN socklen_t AddressLength\r
d7ce7006 798 );\r
799\r
800/**\r
a88c3163 801 Process the transmit completion\r
d7ce7006 802\r
a88c3163 803 This routine calls ::EslSocketTxComplete to handle the\r
804 transmit completion.\r
d7ce7006 805\r
a88c3163 806 This routine is called by the network layers upon the completion\r
807 of a transmit operation.\r
808\r
809 @param [in] Event The urgent transmit completion event\r
810\r
811 @param [in] pIo The ESL_IO_MGMT structure address\r
d7ce7006 812\r
813**/\r
a88c3163 814typedef\r
d7ce7006 815VOID\r
a88c3163 816(* PFN_API_TX_COMPLETE) (\r
d7ce7006 817 IN EFI_EVENT Event,\r
a88c3163 818 IN ESL_IO_MGMT * pIo\r
d7ce7006 819 );\r
820\r
821/**\r
a88c3163 822 Socket type control structure\r
823\r
824 This driver uses this structure to define the API for the socket type.\r
825**/\r
826typedef struct {\r
827 CONST CHAR8 * pName; ///< Protocol name\r
828 int DefaultProtocol; ///< Default protocol\r
829 UINTN ConfigDataOffset; ///< Offset in ::ESL_PORT to the configuration data\r
830 UINTN ServiceListOffset; ///< Offset in ::ESL_LAYER for the list of services\r
831 socklen_t MinimumAddressLength; ///< Minimum address length in bytes\r
832 socklen_t AddressLength; ///< Address length in bytes\r
833 sa_family_t AddressFamily; ///< Address family\r
834 UINTN RxPacketBytes; ///< Length of the RX packet allocation\r
835 UINTN RxZeroBytes; ///< Number of bytes to zero in RX packet\r
836 UINTN RxBufferOffset; ///< Offset of buffer address in ESL_IO_MGMT structure\r
837 BOOLEAN bOobSupported; ///< TRUE if out-of-band messages are supported\r
838 int BindTestErrno; ///< errno value if EslSocketBindTest fails\r
839 PFN_API_ACCEPT pfnAccept; ///< Accept a network connection\r
840 PFN_API_CONNECT_POLL pfnConnectPoll; ///< Poll for connection complete\r
841 PFN_API_CONNECT_START pfnConnectStart; ///< Start the connection to a remote system\r
842 PFN_API_IS_CONFIGURED pfnIsConfigured; ///< Determine if the socket is configured\r
843 PFN_API_LOCAL_ADDR_GET pfnLocalAddrGet; ///< Get the local address\r
844 PFN_API_LOCAL_ADDR_SET pfnLocalAddrSet; ///< Set the local address\r
845 PFN_API_LISTEN pfnListen; ///< Listen for connections on known server port\r
846 PFN_API_OPTION_GET pfnOptionGet; ///< Get the option value\r
847 PFN_API_OPTION_SET pfnOptionSet; ///< Set the option value\r
848 PFN_API_PACKET_FREE pfnPacketFree; ///< Free the receive packet\r
849 PFN_API_PORT_ALLOC pfnPortAllocate; ///< Allocate the network specific resources for the port\r
850 PFN_API_PORT_CLOSE pfnPortClose; ///< Close the network specific resources for the port\r
851 PFN_API_PORT_CLOSE_OP pfnPortCloseOp; ///< Perform the close operation on the port\r
852 BOOLEAN bPortCloseComplete; ///< TRUE = Close is complete after close operation\r
853 PFN_API_RECEIVE pfnReceive; ///< Attempt to receive some data\r
854 PFN_API_REMOTE_ADDR_GET pfnRemoteAddrGet; ///< Get remote address\r
855 PFN_API_REMOTE_ADDR_SET pfnRemoteAddrSet; ///< Set the remote system address\r
58081f2c 856 PFN_API_IO_COMPLETE pfnRxComplete; ///< RX completion\r
a88c3163 857 PFN_API_RX_START pfnRxStart; ///< Start a network specific receive operation\r
858 PFN_API_TRANSMIT pfnTransmit; ///< Attempt to buffer a packet for transmit\r
859 PFN_API_TX_COMPLETE pfnTxComplete; ///< TX completion for normal data\r
860 PFN_API_TX_COMPLETE pfnTxOobComplete; ///< TX completion for urgent data\r
861} ESL_PROTOCOL_API;\r
d7ce7006 862\r
d7ce7006 863\r
a88c3163 864/**\r
865 Socket control structure\r
d7ce7006 866\r
a88c3163 867 The driver uses this structure to manage the socket.\r
d7ce7006 868**/\r
a88c3163 869typedef struct _ESL_SOCKET {\r
870 UINTN Signature; ///< Structure identification\r
d7ce7006 871\r
a88c3163 872 //\r
873 // Protocol binding\r
874 //\r
875 EFI_SOCKET_PROTOCOL SocketProtocol; ///< Socket protocol declaration\r
876 CONST ESL_PROTOCOL_API * pApi; ///< API for the protocol\r
877\r
878 //\r
879 // Socket management\r
880 //\r
881 ESL_SOCKET * pNext; ///< Next socket in the list of sockets\r
882 int errno; ///< Error information for this socket\r
883 EFI_STATUS Status; ///< Asyncronous error information for this socket\r
884 SOCKET_STATE State; ///< Socket state\r
885 UINT32 DebugFlags; ///< Debug flags\r
d7ce7006 886\r
a88c3163 887 //\r
888 // Socket options\r
889 //\r
890 BOOLEAN bListenCalled; ///< TRUE if listen was successfully called\r
891 BOOLEAN bOobInLine; ///< TRUE if out-of-band messages are to be received inline with normal data\r
892 BOOLEAN bIncludeHeader; ///< TRUE if including the IP header\r
d7ce7006 893\r
a88c3163 894 //\r
895 // Socket data\r
896 //\r
897 int Domain; ///< Specifies family of protocols\r
898 int Type; ///< Specifies how to make network connection\r
899 int Protocol; ///< Specifies lower layer protocol to use\r
900 BOOLEAN bConfigured; ///< Set after the socket is configured\r
d7ce7006 901\r
a88c3163 902 BOOLEAN bRxDisable; ///< Receive disabled via shutdown\r
903 size_t RxBytes; ///< Total Rx bytes\r
904 size_t RxOobBytes; ///< Urgent Rx bytes\r
905 EFI_STATUS RxError; ///< Error during receive\r
d7ce7006 906\r
a88c3163 907 BOOLEAN bTxDisable; ///< Transmit disabled via shutdown\r
908 size_t TxBytes; ///< Normal Tx bytes\r
909 size_t TxOobBytes; ///< Urgent Tx bytes\r
910 EFI_STATUS TxError; ///< Error during transmit\r
911\r
912 //\r
913 // Pending connection data\r
914 //\r
915 BOOLEAN bConnected; ///< Set when connected, cleared by poll\r
916 EFI_STATUS ConnectStatus; ///< Connection status\r
917 UINTN MaxFifoDepth; ///< Maximum FIFO depth\r
918 UINTN FifoDepth; ///< Number of sockets in the FIFO\r
919 ESL_SOCKET * pFifoHead; ///< Head of the FIFO\r
920 ESL_SOCKET * pFifoTail; ///< Tail of the FIFO\r
921 ESL_SOCKET * pNextConnection; ///< Link in the FIFO\r
922\r
923 //\r
924 // Network use\r
925 //\r
926 ESL_PORT * pPortList; ///< List of ports managed by this socket\r
927 EFI_EVENT WaitAccept; ///< Wait for accept completion\r
928\r
929 //\r
930 // Receive data management\r
931 //\r
932 UINT32 MaxRxBuf; ///< Maximum size of the receive buffer\r
933 struct timeval RxTimeout; ///< Receive timeout\r
934 ESL_PACKET * pRxFree; ///< Free packet list\r
935 ESL_PACKET * pRxOobPacketListHead;///< Urgent data list head\r
936 ESL_PACKET * pRxOobPacketListTail;///< Urgent data list tail\r
937 ESL_PACKET * pRxPacketListHead; ///< Normal data list head\r
938 ESL_PACKET * pRxPacketListTail; ///< Normal data list tail\r
939\r
940 //\r
941 // Transmit data management\r
942 //\r
943 UINTN TxPacketOffset; ///< Offset for data pointer in ::ESL_PACKET\r
944 UINTN TxTokenEventOffset; ///< Offset to the Event in the TX token\r
945 UINTN TxTokenOffset; ///< Offset for data pointer in TX token\r
946 UINT32 MaxTxBuf; ///< Maximum size of the transmit buffer\r
947 ESL_PACKET * pTxOobPacketListHead;///< Urgent data list head\r
948 ESL_PACKET * pTxOobPacketListTail;///< Urgent data list tail\r
949 ESL_PACKET * pTxPacketListHead; ///< Normal data list head\r
950 ESL_PACKET * pTxPacketListTail; ///< Normal data list tail\r
951}GCC_ESL_SOCKET;\r
952\r
953#define SOCKET_FROM_PROTOCOL(a) CR (a, ESL_SOCKET, SocketProtocol, SOCKET_SIGNATURE) ///< Locate ESL_SOCKET from protocol\r
d7ce7006 954\r
955/**\r
a88c3163 956 Socket layer control structure\r
d7ce7006 957\r
a88c3163 958 The driver uses this structure to manage the driver.\r
959**/\r
960typedef struct {\r
961 UINTN Signature; ///< Structure identification\r
d7ce7006 962\r
a88c3163 963 //\r
964 // Service binding interface\r
965 //\r
966 CONST EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding; ///< Driver's binding\r
d7ce7006 967\r
a88c3163 968 //\r
969 // Image data\r
970 //\r
971 EFI_HANDLE ImageHandle; ///< Image handle\r
d7ce7006 972\r
a88c3163 973 //\r
974 // Network services\r
975 //\r
976 ESL_SERVICE * pIp4List; ///< List of Ip4 services\r
977 ESL_SERVICE * pTcp4List; ///< List of Tcp4 services\r
978 ESL_SERVICE * pUdp4List; ///< List of Udp4 services\r
d7ce7006 979\r
a88c3163 980 //\r
981 // Socket management\r
982 //\r
983 ESL_SOCKET * pSocketList; ///< List of sockets\r
984} ESL_LAYER;\r
d7ce7006 985\r
a88c3163 986#define LAYER_FROM_SERVICE(a) CR (a, ESL_LAYER, ServiceBinding, LAYER_SIGNATURE) ///< Locate ESL_LAYER from service binding\r
d7ce7006 987\r
a88c3163 988//------------------------------------------------------------------------------\r
989// Data\r
990//------------------------------------------------------------------------------\r
991\r
992extern ESL_LAYER mEslLayer;\r
993\r
994extern CONST ESL_PROTOCOL_API cEslIp4Api;\r
995extern CONST ESL_PROTOCOL_API cEslTcp4Api;\r
996extern CONST ESL_PROTOCOL_API cEslUdp4Api;\r
d7ce7006 997\r
a88c3163 998extern CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding;\r
d7ce7006 999\r
a88c3163 1000//------------------------------------------------------------------------------\r
1001// Socket Support Routines\r
1002//------------------------------------------------------------------------------\r
1003\r
1004/**\r
1005 Allocate and initialize a ESL_SOCKET structure.\r
1006 \r
1007 This support function allocates an ::ESL_SOCKET structure\r
1008 and installs a protocol on ChildHandle. If pChildHandle is a\r
1009 pointer to NULL, then a new handle is created and returned in\r
1010 pChildHandle. If pChildHandle is not a pointer to NULL, then\r
1011 the protocol installs on the existing pChildHandle.\r
d7ce7006 1012\r
a88c3163 1013 @param [in, out] pChildHandle Pointer to the handle of the child to create.\r
1014 If it is NULL, then a new handle is created.\r
1015 If it is a pointer to an existing UEFI handle, \r
1016 then the protocol is added to the existing UEFI\r
1017 handle.\r
1018 @param [in] DebugFlags Flags for debug messages\r
1019 @param [in, out] ppSocket The buffer to receive an ::ESL_SOCKET structure address.\r
d7ce7006 1020\r
a88c3163 1021 @retval EFI_SUCCESS The protocol was added to ChildHandle.\r
1022 @retval EFI_INVALID_PARAMETER ChildHandle is NULL.\r
1023 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create\r
1024 the child\r
1025 @retval other The child handle was not created\r
1026 \r
d7ce7006 1027**/\r
1028EFI_STATUS\r
1029EFIAPI\r
a88c3163 1030EslSocketAllocate (\r
1031 IN OUT EFI_HANDLE * pChildHandle,\r
1032 IN UINTN DebugFlags,\r
1033 IN OUT ESL_SOCKET ** ppSocket\r
d7ce7006 1034 );\r
1035\r
1036/**\r
a88c3163 1037 Test the bind configuration.\r
d7ce7006 1038\r
a88c3163 1039 @param [in] pPort Address of the ::ESL_PORT structure.\r
1040 @param [in] ErrnoValue errno value if test fails\r
d7ce7006 1041\r
a88c3163 1042 @retval EFI_SUCCESS The connection was successfully established.\r
1043 @retval Others The connection attempt failed.\r
d7ce7006 1044\r
1045 **/\r
1046EFI_STATUS\r
a88c3163 1047EslSocketBindTest (\r
1048 IN ESL_PORT * pPort,\r
1049 IN int ErrnoValue\r
d7ce7006 1050 );\r
1051\r
1052/**\r
a88c3163 1053 Copy a fragmented buffer into a destination buffer.\r
d7ce7006 1054\r
a88c3163 1055 This support routine copies a fragmented buffer to the caller specified buffer.\r
d7ce7006 1056\r
a88c3163 1057 This routine is called by ::EslIp4Receive and ::EslUdp4Receive.\r
d7ce7006 1058\r
a88c3163 1059 @param [in] FragmentCount Number of fragments in the table\r
d7ce7006 1060\r
a88c3163 1061 @param [in] pFragmentTable Address of an EFI_IP4_FRAGMENT_DATA structure\r
d7ce7006 1062\r
a88c3163 1063 @param [in] BufferLength Length of the the buffer\r
d7ce7006 1064\r
a88c3163 1065 @param [in] pBuffer Address of a buffer to receive the data.\r
1066\r
1067 @param [in] pDataLength Number of received data bytes in the buffer.\r
1068\r
1069 @return Returns the address of the next free byte in the buffer.\r
d7ce7006 1070\r
1071**/\r
a88c3163 1072UINT8 *\r
1073EslSocketCopyFragmentedBuffer (\r
1074 IN UINT32 FragmentCount,\r
1075 IN EFI_IP4_FRAGMENT_DATA * pFragmentTable,\r
1076 IN size_t BufferLength,\r
1077 IN UINT8 * pBuffer,\r
1078 OUT size_t * pDataLength\r
d7ce7006 1079 );\r
1080\r
1081/**\r
a88c3163 1082 Free the ESL_IO_MGMT event and structure\r
d7ce7006 1083\r
a88c3163 1084 This support routine walks the free list to close the event in\r
1085 the ESL_IO_MGMT structure and remove the structure from the free\r
1086 list.\r
d7ce7006 1087\r
a88c3163 1088 See the \ref TransmitEngine section.\r
d7ce7006 1089\r
a88c3163 1090 @param [in] pPort Address of an ::ESL_PORT structure\r
1091 @param [in] ppFreeQueue Address of the free queue head\r
1092 @param [in] DebugFlags Flags for debug messages\r
1093 @param [in] pEventName Zero terminated string containing the event name\r
1094\r
1095 @retval EFI_SUCCESS - The structures were properly initialized\r
d7ce7006 1096\r
1097**/\r
1098EFI_STATUS\r
a88c3163 1099EslSocketIoFree (\r
1100 IN ESL_PORT * pPort,\r
1101 IN ESL_IO_MGMT ** ppFreeQueue,\r
1102 IN UINTN DebugFlags,\r
1103 IN CHAR8 * pEventName\r
d7ce7006 1104 );\r
1105\r
1106/**\r
a88c3163 1107 Initialize the ESL_IO_MGMT structures\r
d7ce7006 1108\r
a88c3163 1109 This support routine initializes the ESL_IO_MGMT structure and\r
1110 places them on to a free list.\r
d7ce7006 1111\r
a88c3163 1112 This routine is called by the PortAllocate routines to prepare\r
1113 the transmit engines. See the \ref TransmitEngine section.\r
d7ce7006 1114\r
a88c3163 1115 @param [in] pPort Address of an ::ESL_PORT structure\r
1116 @param [in, out] ppIo Address containing the first structure address. Upon\r
1117 return this buffer contains the next structure address.\r
1118 @param [in] TokenCount Number of structures to initialize\r
1119 @param [in] ppFreeQueue Address of the free queue head\r
1120 @param [in] DebugFlags Flags for debug messages\r
1121 @param [in] pEventName Zero terminated string containing the event name\r
1122 @param [in] pfnCompletion Completion routine address\r
d7ce7006 1123\r
a88c3163 1124 @retval EFI_SUCCESS - The structures were properly initialized\r
1125\r
1126**/\r
d7ce7006 1127EFI_STATUS\r
a88c3163 1128EslSocketIoInit (\r
1129 IN ESL_PORT * pPort,\r
1130 IN ESL_IO_MGMT ** ppIo,\r
1131 IN UINTN TokenCount,\r
1132 IN ESL_IO_MGMT ** ppFreeQueue,\r
1133 IN UINTN DebugFlags,\r
1134 IN CHAR8 * pEventName,\r
58081f2c 1135 IN PFN_API_IO_COMPLETE pfnCompletion\r
d7ce7006 1136 );\r
1137\r
1138/**\r
a88c3163 1139 Determine if the socket is configured\r
d7ce7006 1140\r
a88c3163 1141 This support routine is called to determine if the socket if the\r
1142 configuration call was made to the network layer. The following\r
1143 routines call this routine to verify that they may be successful\r
1144 in their operations:\r
1145 <ul>\r
1146 <li>::EslSocketGetLocalAddress</li>\r
1147 <li>::EslSocketGetPeerAddress</li>\r
1148 <li>::EslSocketPoll</li>\r
1149 <li>::EslSocketReceive</li>\r
1150 <li>::EslSocketTransmit</li>\r
1151 </ul>\r
d7ce7006 1152\r
a88c3163 1153 @param [in] pSocket Address of an ::ESL_SOCKET structure\r
d7ce7006 1154\r
a88c3163 1155 @retval EFI_SUCCESS - The socket is configured\r
d7ce7006 1156\r
1157**/\r
1158EFI_STATUS\r
a88c3163 1159EslSocketIsConfigured (\r
1160 IN ESL_SOCKET * pSocket\r
d7ce7006 1161 );\r
1162\r
1163/**\r
a88c3163 1164 Allocate a packet for a receive or transmit operation\r
d7ce7006 1165\r
a88c3163 1166 This support routine is called by ::EslSocketRxStart and the\r
1167 network specific TxBuffer routines to get buffer space for the\r
1168 next operation.\r
d7ce7006 1169\r
a88c3163 1170 @param [in] ppPacket Address to receive the ::ESL_PACKET structure\r
1171 @param [in] LengthInBytes Length of the packet structure\r
1172 @param [in] ZeroBytes Length of packet to zero\r
1173 @param [in] DebugFlags Flags for debug messages\r
d7ce7006 1174\r
a88c3163 1175 @retval EFI_SUCCESS - The packet was allocated successfully\r
d7ce7006 1176\r
a88c3163 1177 **/\r
d7ce7006 1178EFI_STATUS\r
a88c3163 1179EslSocketPacketAllocate (\r
1180 IN ESL_PACKET ** ppPacket,\r
1181 IN size_t LengthInBytes,\r
1182 IN size_t ZeroBytes,\r
1183 IN UINTN DebugFlags\r
d7ce7006 1184 );\r
1185\r
1186/**\r
a88c3163 1187 Free a packet used for receive or transmit operation\r
d7ce7006 1188\r
a88c3163 1189 This support routine is called by the network specific Close\r
1190 and TxComplete routines and during error cases in RxComplete\r
1191 and TxBuffer. Note that the network layers typically place\r
1192 receive packets on the ESL_SOCKET::pRxFree list for reuse.\r
d7ce7006 1193\r
a88c3163 1194 @param [in] pPacket Address of an ::ESL_PACKET structure\r
1195 @param [in] DebugFlags Flags for debug messages\r
d7ce7006 1196\r
a88c3163 1197 @retval EFI_SUCCESS - The packet was allocated successfully\r
d7ce7006 1198\r
a88c3163 1199 **/\r
1200EFI_STATUS\r
1201EslSocketPacketFree (\r
1202 IN ESL_PACKET * pPacket,\r
1203 IN UINTN DebugFlags\r
1204 );\r
d7ce7006 1205\r
a88c3163 1206/**\r
1207 Allocate and initialize a ESL_PORT structure.\r
d7ce7006 1208\r
a88c3163 1209 This routine initializes an ::ESL_PORT structure for use by\r
1210 the socket. This routine calls a routine via\r
1211 ESL_PROTOCOL_API::pfnPortAllocate to initialize the network\r
1212 specific resources. The resources are released later by the\r
1213 \ref PortCloseStateMachine.\r
d7ce7006 1214\r
a88c3163 1215 This support routine is called by ::EslSocketBind and\r
1216 ::EslTcp4ListenComplete to connect the socket with the\r
1217 underlying network adapter to the socket.\r
d7ce7006 1218\r
a88c3163 1219 @param [in] pSocket Address of an ::ESL_SOCKET structure.\r
1220 @param [in] pService Address of an ::ESL_SERVICE structure.\r
1221 @param [in] ChildHandle TCP4 child handle\r
1222 @param [in] pSockAddr Address of a sockaddr structure that contains the\r
1223 connection point on the local machine. An IPv4 address\r
1224 of INADDR_ANY specifies that the connection is made to\r
1225 all of the network stacks on the platform. Specifying a\r
1226 specific IPv4 address restricts the connection to the\r
1227 network stack supporting that address. Specifying zero\r
1228 for the port causes the network layer to assign a port\r
1229 number from the dynamic range. Specifying a specific\r
1230 port number causes the network layer to use that port.\r
1231 @param [in] bBindTest TRUE if EslSocketBindTest should be called\r
1232 @param [in] DebugFlags Flags for debug messages\r
1233 @param [out] ppPort Buffer to receive new ::ESL_PORT structure address\r
d7ce7006 1234\r
a88c3163 1235 @retval EFI_SUCCESS - Socket successfully created\r
d7ce7006 1236\r
a88c3163 1237 **/\r
d7ce7006 1238EFI_STATUS\r
a88c3163 1239EslSocketPortAllocate (\r
1240 IN ESL_SOCKET * pSocket,\r
1241 IN ESL_SERVICE * pService,\r
1242 IN EFI_HANDLE ChildHandle,\r
1243 IN CONST struct sockaddr * pSockAddr,\r
1244 IN BOOLEAN bBindTest,\r
1245 IN UINTN DebugFlags,\r
1246 OUT ESL_PORT ** ppPort\r
d7ce7006 1247 );\r
1248\r
1249/**\r
a88c3163 1250 Close a port.\r
1251\r
1252 This routine releases the resources allocated by ::EslSocketPortAllocate.\r
1253 This routine calls ESL_PROTOCOL_API::pfnPortClose to release the network\r
1254 specific resources.\r
1255\r
1256 This routine is called by:\r
1257 <ul>\r
1258 <li>::EslIp4PortAllocate - Port initialization failure</li>\r
1259 <li>::EslSocketPortCloseRxDone - Last step of close processing</li>\r
1260 <li>::EslTcp4ConnectComplete - Connection failure and reducint the port list to a single port</li>\r
1261 <li>::EslTcp4PortAllocate - Port initialization failure</li>\r
1262 <li>::EslUdp4PortAllocate - Port initialization failure</li>\r
1263 </ul>\r
1264 See the \ref PortCloseStateMachine section.\r
d7ce7006 1265 \r
a88c3163 1266 @param [in] pPort Address of an ::ESL_PORT structure.\r
d7ce7006 1267\r
a88c3163 1268 @retval EFI_SUCCESS The port is closed\r
1269 @retval other Port close error\r
1270\r
1271**/\r
d7ce7006 1272EFI_STATUS\r
a88c3163 1273EslSocketPortClose (\r
1274 IN ESL_PORT * pPort\r
d7ce7006 1275 );\r
1276\r
1277/**\r
a88c3163 1278 Process the port close completion event\r
d7ce7006 1279\r
a88c3163 1280 This routine attempts to complete the port close operation.\r
d7ce7006 1281\r
a88c3163 1282 This routine is called by the TCP layer upon completion of\r
1283 the close operation.\r
1284 See the \ref PortCloseStateMachine section.\r
d7ce7006 1285\r
a88c3163 1286 @param [in] Event The close completion event\r
1287\r
1288 @param [in] pPort Address of an ::ESL_PORT structure.\r
d7ce7006 1289\r
1290**/\r
1291VOID\r
a88c3163 1292EslSocketPortCloseComplete (\r
d7ce7006 1293 IN EFI_EVENT Event,\r
a88c3163 1294 IN ESL_PORT * pPort\r
d7ce7006 1295 );\r
1296\r
1297/**\r
a88c3163 1298 Port close state 3\r
d7ce7006 1299\r
a88c3163 1300 This routine determines the state of the receive operations and\r
1301 continues the close operation after the pending receive operations\r
1302 are cancelled.\r
d7ce7006 1303\r
a88c3163 1304 This routine is called by\r
1305 <ul>\r
1306 <li>::EslIp4RxComplete</li>\r
1307 <li>::EslSocketPortCloseComplete</li>\r
1308 <li>::EslSocketPortCloseTxDone</li>\r
1309 <li>::EslUdp4RxComplete</li>\r
1310 </ul>\r
1311 to determine the state of the receive operations.\r
1312 See the \ref PortCloseStateMachine section.\r
1313\r
1314 @param [in] pPort Address of an ::ESL_PORT structure.\r
1315\r
1316 @retval EFI_SUCCESS The port is closed\r
1317 @retval EFI_NOT_READY The port is still closing\r
1318 @retval EFI_ALREADY_STARTED Error, the port is in the wrong state,\r
1319 most likely the routine was called already.\r
1320\r
1321**/\r
1322EFI_STATUS\r
1323EslSocketPortCloseRxDone (\r
1324 IN ESL_PORT * pPort\r
d7ce7006 1325 );\r
1326\r
1327/**\r
a88c3163 1328 Start the close operation on a port, state 1.\r
d7ce7006 1329\r
a88c3163 1330 This routine marks the port as closed and initiates the \ref\r
1331 PortCloseStateMachine. The first step is to allow the \ref\r
1332 TransmitEngine to run down.\r
d7ce7006 1333\r
a88c3163 1334 This routine is called by ::EslSocketCloseStart to initiate the socket\r
1335 network specific close operation on the socket.\r
d7ce7006 1336\r
a88c3163 1337 @param [in] pPort Address of an ::ESL_PORT structure.\r
1338 @param [in] bCloseNow Set TRUE to abort active transfers\r
1339 @param [in] DebugFlags Flags for debug messages\r
1340\r
1341 @retval EFI_SUCCESS The port is closed, not normally returned\r
1342 @retval EFI_NOT_READY The port has started the closing process\r
1343 @retval EFI_ALREADY_STARTED Error, the port is in the wrong state,\r
1344 most likely the routine was called already.\r
1345\r
1346**/\r
1347EFI_STATUS\r
1348EslSocketPortCloseStart (\r
1349 IN ESL_PORT * pPort,\r
1350 IN BOOLEAN bCloseNow,\r
1351 IN UINTN DebugFlags\r
d7ce7006 1352 );\r
1353\r
1354/**\r
a88c3163 1355 Port close state 2\r
1356\r
1357 This routine determines the state of the transmit engine and\r
1358 continue the close operation after the transmission is complete.\r
1359 The next step is to stop the \ref ReceiveEngine.\r
1360 See the \ref PortCloseStateMachine section.\r
d7ce7006 1361\r
a88c3163 1362 This routine is called by ::EslSocketPortCloseStart to determine\r
1363 if the transmission is complete.\r
d7ce7006 1364\r
a88c3163 1365 @param [in] pPort Address of an ::ESL_PORT structure.\r
1366\r
1367 @retval EFI_SUCCESS The port is closed, not normally returned\r
1368 @retval EFI_NOT_READY The port is still closing\r
1369 @retval EFI_ALREADY_STARTED Error, the port is in the wrong state,\r
1370 most likely the routine was called already.\r
d7ce7006 1371\r
1372**/\r
a88c3163 1373EFI_STATUS\r
1374EslSocketPortCloseTxDone (\r
1375 IN ESL_PORT * pPort\r
d7ce7006 1376 );\r
1377\r
1378/**\r
a88c3163 1379 Cancel the receive operations\r
d7ce7006 1380\r
a88c3163 1381 This routine cancels a pending receive operation.\r
1382 See the \ref ReceiveEngine section.\r
d7ce7006 1383\r
a88c3163 1384 This routine is called by ::EslSocketShutdown when the socket\r
1385 layer is being shutdown.\r
d7ce7006 1386\r
a88c3163 1387 @param [in] pPort Address of an ::ESL_PORT structure\r
1388 @param [in] pIo Address of an ::ESL_IO_MGMT structure\r
1389\r
1390 **/\r
d7ce7006 1391VOID\r
a88c3163 1392EslSocketRxCancel (\r
1393 IN ESL_PORT * pPort,\r
1394 IN ESL_IO_MGMT * pIo\r
d7ce7006 1395 );\r
1396\r
1397/**\r
a88c3163 1398 Process the receive completion\r
d7ce7006 1399\r
a88c3163 1400 This routine queues the data in FIFO order in either the urgent\r
1401 or normal data queues depending upon the type of data received.\r
1402 See the \ref ReceiveEngine section.\r
d7ce7006 1403\r
a88c3163 1404 This routine is called when some data is received by:\r
1405 <ul>\r
1406 <li>::EslIp4RxComplete</li>\r
1407 <li>::EslTcp4RxComplete</li>\r
1408 <li>::EslUdp4RxComplete</li>\r
1409 </ul>\r
d7ce7006 1410\r
a88c3163 1411 @param [in] pIo Address of an ::ESL_IO_MGMT structure\r
1412 @param [in] Status Receive status\r
1413 @param [in] LengthInBytes Length of the receive data\r
1414 @param [in] bUrgent TRUE if urgent data is received and FALSE\r
1415 for normal data.\r
d7ce7006 1416\r
a88c3163 1417**/\r
1418VOID\r
1419EslSocketRxComplete (\r
1420 IN ESL_IO_MGMT * pIo,\r
1421 IN EFI_STATUS Status,\r
1422 IN UINTN LengthInBytes,\r
1423 IN BOOLEAN bUrgent\r
1424 );\r
d7ce7006 1425\r
a88c3163 1426/**\r
1427 Start a receive operation\r
d7ce7006 1428\r
a88c3163 1429 This routine posts a receive buffer to the network adapter.\r
1430 See the \ref ReceiveEngine section.\r
d7ce7006 1431\r
a88c3163 1432 This support routine is called by:\r
1433 <ul>\r
1434 <li>::EslIp4Receive to restart the receive engine to release flow control.</li>\r
1435 <li>::EslIp4RxComplete to continue the operation of the receive engine if flow control is not being applied.</li>\r
1436 <li>::EslIp4SocketIsConfigured to start the recevie engine for the new socket.</li>\r
1437 <li>::EslTcp4ListenComplete to start the recevie engine for the new socket.</li>\r
1438 <li>::EslTcp4Receive to restart the receive engine to release flow control.</li>\r
1439 <li>::EslTcp4RxComplete to continue the operation of the receive engine if flow control is not being applied.</li>\r
1440 <li>::EslUdp4Receive to restart the receive engine to release flow control.</li>\r
1441 <li>::EslUdp4RxComplete to continue the operation of the receive engine if flow control is not being applied.</li>\r
1442 <li>::EslUdp4SocketIsConfigured to start the recevie engine for the new socket.</li>\r
1443 </ul>\r
d7ce7006 1444\r
a88c3163 1445 @param [in] pPort Address of an ::ESL_PORT structure.\r
d7ce7006 1446\r
a88c3163 1447 **/\r
1448VOID\r
1449EslSocketRxStart (\r
1450 IN ESL_PORT * pPort\r
1451 );\r
d7ce7006 1452\r
a88c3163 1453/**\r
1454 Complete the transmit operation\r
1455\r
1456 This support routine handles the transmit completion processing for\r
1457 the various network layers. It frees the ::ESL_IO_MGMT structure\r
1458 and and frees packet resources by calling ::EslSocketPacketFree.\r
1459 Transmit errors are logged in ESL_SOCKET::TxError.\r
1460 See the \ref TransmitEngine section.\r
1461\r
1462 This routine is called by:\r
1463 <ul>\r
1464 <li>::EslIp4TxComplete</li>\r
1465 <li>::EslTcp4TxComplete</li>\r
1466 <li>::EslTcp4TxOobComplete</li>\r
1467 <li>::EslUdp4TxComplete</li>\r
1468 </ul>\r
1469\r
1470 @param [in] pIo Address of an ::ESL_IO_MGMT structure\r
1471 @param [in] LengthInBytes Length of the data in bytes\r
1472 @param [in] Status Transmit operation status\r
1473 @param [in] pQueueType Zero terminated string describing queue type\r
1474 @param [in] ppQueueHead Transmit queue head address\r
1475 @param [in] ppQueueTail Transmit queue tail address\r
1476 @param [in] ppActive Active transmit queue address\r
1477 @param [in] ppFree Free transmit queue address\r
d7ce7006 1478\r
a88c3163 1479 **/\r
1480VOID\r
1481EslSocketTxComplete (\r
1482 IN ESL_IO_MGMT * pIo,\r
1483 IN UINT32 LengthInBytes,\r
1484 IN EFI_STATUS Status,\r
1485 IN CONST CHAR8 * pQueueType,\r
1486 IN ESL_PACKET ** ppQueueHead,\r
1487 IN ESL_PACKET ** ppQueueTail,\r
1488 IN ESL_IO_MGMT ** ppActive,\r
1489 IN ESL_IO_MGMT ** ppFree\r
d7ce7006 1490 );\r
1491\r
1492/**\r
1493 Transmit data using a network connection.\r
1494\r
a88c3163 1495 This support routine starts a transmit operation on the\r
1496 underlying network layer.\r
1497\r
1498 The network specific code calls this routine to start a\r
1499 transmit operation. See the \ref TransmitEngine section.\r
1500\r
1501 @param [in] pPort Address of an ::ESL_PORT structure\r
1502 @param [in] ppQueueHead Transmit queue head address\r
1503 @param [in] ppQueueTail Transmit queue tail address\r
1504 @param [in] ppActive Active transmit queue address\r
1505 @param [in] ppFree Free transmit queue address\r
d7ce7006 1506\r
1507 **/\r
1508VOID\r
a88c3163 1509EslSocketTxStart (\r
1510 IN ESL_PORT * pPort,\r
1511 IN ESL_PACKET ** ppQueueHead,\r
1512 IN ESL_PACKET ** ppQueueTail,\r
1513 IN ESL_IO_MGMT ** ppActive,\r
1514 IN ESL_IO_MGMT ** ppFree\r
d7ce7006 1515 );\r
1516\r
1517//------------------------------------------------------------------------------\r
1518\r
1519#endif // _SOCKET_H_\r