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