2 Implement the TCP6 driver support for the socket layer.
4 Copyright (c) 2011, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 \section ConnectionManagement Connection Management
16 The ::EslTcp6Listen routine initially places the SOCK_STREAM or
17 SOCK_SEQPACKET socket into a listen state. When a remote machine
18 makes a connection to the socket, the TCPv6 network layer calls
19 ::EslTcp6ListenComplete to complete the connection processing.
20 EslTcp6ListenComplete manages the connections by placing them in
21 FIFO order in a queue to be serviced by the application. When the
22 number of connections exceeds the backlog (ESL_SOCKET::MaxFifoDepth),
23 the new connection is closed. Eventually, the application indirectly
24 calls ::EslTcp6Accept to remove the next connection from the queue
25 and get the associated socket.
33 Attempt to connect to a remote TCP port
35 This routine starts the connection processing for a SOCK_STREAM
36 or SOCK_SEQPAKCET socket using the TCPv6 network layer. It
37 configures the local TCPv6 connection point and then attempts to
38 connect to a remote system. Upon completion, the
39 ::EslTcp6ConnectComplete routine gets called with the connection
42 This routine is called by ::EslSocketConnect to initiate the TCPv6
43 network specific connect operations. The connection processing is
44 initiated by this routine and finished by ::EslTcp6ConnectComplete.
45 This pair of routines walks through the list of local TCPv6
46 connection points until a connection to the remote system is
49 @param [in] pSocket Address of an ::ESL_SOCKET structure.
51 @retval EFI_SUCCESS The connection was successfully established.
52 @retval EFI_NOT_READY The connection is in progress, call this routine again.
53 @retval Others The connection attempt failed.
58 IN ESL_SOCKET
* pSocket
63 Process the connection attempt
65 A system has initiated a connection attempt with a socket in the
66 listen state. Attempt to complete the connection.
68 The TCPv6 layer calls this routine when a connection is made to
69 the socket in the listen state. See the
70 \ref ConnectionManagement section.
72 @param [in] Event The listen completion event
74 @param [in] pPort Address of an ::ESL_PORT structure.
78 EslTcp6ListenComplete (
85 Accept a network connection.
87 This routine waits for a network connection to the socket and
88 returns the remote network address to the caller if requested.
90 This routine is called by ::EslSocketAccept to handle the TCPv6 protocol
91 specific accept operations for SOCK_STREAM and SOCK_SEQPACKET sockets.
92 See the \ref ConnectionManagement section.
94 @param [in] pSocket Address of an ::ESL_SOCKET structure.
96 @param [in] pSockAddr Address of a buffer to receive the remote
99 @param [in, out] pSockAddrLength Length in bytes of the address buffer.
100 On output specifies the length of the
101 remote network address.
103 @retval EFI_SUCCESS Remote address is available
104 @retval Others Remote address not available
109 IN ESL_SOCKET
* pSocket
,
110 IN
struct sockaddr
* pSockAddr
,
111 IN OUT socklen_t
* pSockAddrLength
115 struct sockaddr_in6
* pRemoteAddress
;
116 ESL_TCP6_CONTEXT
* pTcp6
;
122 // Validate the socket length
124 pRemoteAddress
= (struct sockaddr_in6
*) pSockAddr
;
125 if (( NULL
== pSockAddrLength
)
126 || ( sizeof ( *pRemoteAddress
) > *pSockAddrLength
)) {
128 // Invalid socket address
130 Status
= EFI_INVALID_PARAMETER
;
131 pSocket
->errno
= EINVAL
;
132 DEBUG (( DEBUG_ACCEPT
,
133 "ERROR - Invalid address length\r\n" ));
139 Status
= EFI_SUCCESS
;
142 // Locate the address context
144 pPort
= pSocket
->pPortList
;
145 pTcp6
= &pPort
->Context
.Tcp6
;
148 // Fill-in the remote address structure
150 ZeroMem ( pRemoteAddress
, sizeof ( *pRemoteAddress
));
151 pRemoteAddress
->sin6_len
= sizeof ( *pRemoteAddress
);
152 pRemoteAddress
->sin6_family
= AF_INET6
;
153 pRemoteAddress
->sin6_port
= SwapBytes16 ( pTcp6
->ConfigData
.AccessPoint
.RemotePort
);
154 CopyMem ( &pRemoteAddress
->sin6_addr
.__u6_addr
.__u6_addr8
[ 0 ],
155 &pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[0],
156 sizeof ( pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
));
160 // Return the operation status
162 DBG_EXIT_STATUS ( Status
);
168 Process the remote connection completion event.
170 This routine handles the completion of a connection attempt. It
171 releases the port (TCPv6 adapter connection) in the case of an
172 error and start a connection attempt on the next port. If the
173 connection attempt was successful then this routine releases all
176 This routine is called by the TCPv6 layer when a connect request
177 completes. It sets the ESL_SOCKET::bConnected flag to notify the
178 ::EslTcp6ConnectComplete routine that the connection is available.
179 The flag is set when the connection is established or no more ports
180 exist in the list. The connection status is passed via
181 ESL_SOCKET::ConnectStatus.
183 @param [in] Event The connect completion event
185 @param [in] pPort Address of an ::ESL_PORT structure.
189 EslTcp6ConnectComplete (
194 BOOLEAN bRemoveFirstPort
;
195 BOOLEAN bRemovePorts
;
196 ESL_PORT
* pNextPort
;
197 ESL_SOCKET
* pSocket
;
198 ESL_TCP6_CONTEXT
* pTcp6
;
204 // Locate the TCP context
206 pSocket
= pPort
->pSocket
;
207 pTcp6
= &pPort
->Context
.Tcp6
;
210 // Get the connection status
212 bRemoveFirstPort
= FALSE
;
213 bRemovePorts
= FALSE
;
214 Status
= pTcp6
->ConnectToken
.CompletionToken
.Status
;
215 pSocket
->ConnectStatus
= Status
;
216 if ( !EFI_ERROR ( Status
)) {
218 // The connection was successful
220 DEBUG (( DEBUG_CONNECT
,
221 "0x%08x: Port connected to [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",
223 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[0],
224 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[1],
225 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[2],
226 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[3],
227 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[4],
228 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[5],
229 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[6],
230 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[7],
231 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[8],
232 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[9],
233 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[10],
234 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[11],
235 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[12],
236 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[13],
237 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[14],
238 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[15],
239 pTcp6
->ConfigData
.AccessPoint
.RemotePort
));
242 // Remove the rest of the ports
248 // The connection failed
250 DEBUG (( DEBUG_CONNECT
,
251 "0x%08x: Port connection to [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d failed, Status: %r\r\n",
253 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[0],
254 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[1],
255 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[2],
256 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[3],
257 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[4],
258 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[5],
259 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[6],
260 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[7],
261 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[8],
262 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[9],
263 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[10],
264 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[11],
265 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[12],
266 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[13],
267 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[14],
268 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[15],
269 pTcp6
->ConfigData
.AccessPoint
.RemotePort
,
273 // Close the current port
275 Status
= EslSocketPortClose ( pPort
);
276 if ( !EFI_ERROR ( Status
)) {
277 DEBUG (( DEBUG_CONNECT
,
278 "0x%08x: Port closed\r\n",
282 DEBUG (( DEBUG_CONNECT
,
283 "ERROR - Failed to close port 0x%08x, Status: %r\r\n",
289 // Try to connect using the next port
291 Status
= EslTcp6ConnectStart ( pSocket
);
292 if ( EFI_NOT_READY
!= Status
) {
293 pSocket
->ConnectStatus
= Status
;
294 bRemoveFirstPort
= TRUE
;
299 // Remove the ports if necessary
301 if ( bRemoveFirstPort
|| bRemovePorts
) {
303 // Remove the first port if necessary
305 pPort
= pSocket
->pPortList
;
306 if (( !bRemoveFirstPort
) && ( NULL
!= pPort
)) {
307 pPort
= pPort
->pLinkSocket
;
311 // Remove the rest of the list
313 while ( NULL
!= pPort
) {
314 pNextPort
= pPort
->pLinkSocket
;
315 EslSocketPortClose ( pPort
);
316 if ( !EFI_ERROR ( Status
)) {
317 DEBUG (( DEBUG_CONNECT
,
318 "0x%08x: Port closed\r\n",
322 DEBUG (( DEBUG_CONNECT
,
323 "ERROR - Failed to close port 0x%08x, Status: %r\r\n",
331 // Notify the poll routine
333 pSocket
->bConnected
= TRUE
;
341 Poll for completion of the connection attempt.
343 This routine polls the ESL_SOCKET::bConnected flag to determine
344 when the connection attempt is complete.
346 This routine is called from ::EslSocketConnect to determine when
347 the connection is complete. The ESL_SOCKET::bConnected flag is
348 set by ::EslTcp6ConnectComplete when the TCPv6 layer establishes
349 a connection or runs out of local network adapters. This routine
350 gets the connection status from ESL_SOCKET::ConnectStatus.
352 @param [in] pSocket Address of an ::ESL_SOCKET structure.
354 @retval EFI_SUCCESS The connection was successfully established.
355 @retval EFI_NOT_READY The connection is in progress, call this routine again.
356 @retval Others The connection attempt failed.
361 IN ESL_SOCKET
* pSocket
369 // Determine if the connection is complete
371 if ( !pSocket
->bConnected
) {
375 pSocket
->errno
= EAGAIN
;
376 Status
= EFI_NOT_READY
;
380 // The connection processing is complete
382 pSocket
->bConnected
= FALSE
;
385 // Translate the connection status
387 Status
= pSocket
->ConnectStatus
;
390 case EFI_DEVICE_ERROR
:
391 pSocket
->errno
= EIO
;
395 pSocket
->errno
= ECONNREFUSED
;
398 case EFI_INVALID_PARAMETER
:
399 pSocket
->errno
= EINVAL
;
403 case EFI_NO_RESPONSE
:
404 pSocket
->errno
= EHOSTUNREACH
;
408 pSocket
->errno
= ENETDOWN
;
411 case EFI_OUT_OF_RESOURCES
:
412 pSocket
->errno
= ENOMEM
;
417 pSocket
->bConfigured
= TRUE
;
421 pSocket
->errno
= ETIMEDOUT
;
424 case EFI_UNSUPPORTED
:
425 pSocket
->errno
= ENOTSUP
;
429 pSocket
->errno
= ECONNRESET
;
435 // Return the initialization status
437 DBG_EXIT_STATUS ( Status
);
443 Attempt to connect to a remote TCP port
445 This routine starts the connection processing for a SOCK_STREAM
446 or SOCK_SEQPAKCET socket using the TCPv6 network layer. It
447 configures the local TCPv6 connection point and then attempts to
448 connect to a remote system. Upon completion, the
449 ::EslTcp6ConnectComplete routine gets called with the connection
452 This routine is called by ::EslSocketConnect to initiate the TCPv6
453 network specific connect operations. The connection processing is
454 initiated by this routine and finished by ::EslTcp6ConnectComplete.
455 This pair of routines walks through the list of local TCPv6
456 connection points until a connection to the remote system is
459 @param [in] pSocket Address of an ::ESL_SOCKET structure.
461 @retval EFI_SUCCESS The connection was successfully established.
462 @retval EFI_NOT_READY The connection is in progress, call this routine again.
463 @retval Others The connection attempt failed.
467 EslTcp6ConnectStart (
468 IN ESL_SOCKET
* pSocket
472 ESL_TCP6_CONTEXT
* pTcp6
;
473 EFI_TCP6_PROTOCOL
* pTcp6Protocol
;
479 // Determine if any more local adapters are available
481 pPort
= pSocket
->pPortList
;
482 if ( NULL
!= pPort
) {
484 // Configure the port
486 pTcp6
= &pPort
->Context
.Tcp6
;
487 pTcp6
->ConfigData
.AccessPoint
.ActiveFlag
= TRUE
;
488 pTcp6
->ConfigData
.TrafficClass
= 0;
489 pTcp6
->ConfigData
.HopLimit
= 255;
490 pTcp6Protocol
= pPort
->pProtocol
.TCPv6
;
491 Status
= pTcp6Protocol
->Configure ( pTcp6Protocol
,
492 &pTcp6
->ConfigData
);
493 if ( EFI_ERROR ( Status
)) {
494 DEBUG (( DEBUG_CONNECT
,
495 "ERROR - Failed to configure the Tcp6 port, Status: %r\r\n",
498 case EFI_ACCESS_DENIED
:
499 pSocket
->errno
= EACCES
;
503 case EFI_DEVICE_ERROR
:
504 pSocket
->errno
= EIO
;
507 case EFI_INVALID_PARAMETER
:
508 pSocket
->errno
= EADDRNOTAVAIL
;
512 pSocket
->errno
= EAFNOSUPPORT
;
515 case EFI_OUT_OF_RESOURCES
:
516 pSocket
->errno
= ENOBUFS
;
519 case EFI_UNSUPPORTED
:
520 pSocket
->errno
= EOPNOTSUPP
;
525 DEBUG (( DEBUG_CONNECT
,
526 "0x%08x: Port configured\r\n",
528 pPort
->bConfigured
= TRUE
;
531 // Attempt the connection to the remote system
533 Status
= pTcp6Protocol
->Connect ( pTcp6Protocol
,
534 &pTcp6
->ConnectToken
);
535 if ( !EFI_ERROR ( Status
)) {
537 // Connection in progress
539 pSocket
->errno
= EINPROGRESS
;
540 Status
= EFI_NOT_READY
;
541 DEBUG (( DEBUG_CONNECT
,
542 "0x%08x: Port attempting connection to [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",
544 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[0],
545 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[1],
546 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[2],
547 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[3],
548 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[4],
549 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[5],
550 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[6],
551 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[7],
552 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[8],
553 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[9],
554 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[10],
555 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[11],
556 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[12],
557 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[13],
558 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[14],
559 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[15],
560 pTcp6
->ConfigData
.AccessPoint
.RemotePort
));
566 DEBUG (( DEBUG_CONNECT
,
567 "ERROR - Port 0x%08x not connected, Status: %r\r\n",
571 // Determine the errno value
575 pSocket
->errno
= EIO
;
578 case EFI_OUT_OF_RESOURCES
:
579 pSocket
->errno
= ENOBUFS
;
583 pSocket
->errno
= ETIMEDOUT
;
586 case EFI_NETWORK_UNREACHABLE
:
587 pSocket
->errno
= ENETDOWN
;
590 case EFI_HOST_UNREACHABLE
:
591 pSocket
->errno
= EHOSTUNREACH
;
594 case EFI_PORT_UNREACHABLE
:
595 case EFI_PROTOCOL_UNREACHABLE
:
596 case EFI_CONNECTION_REFUSED
:
597 pSocket
->errno
= ECONNREFUSED
;
600 case EFI_CONNECTION_RESET
:
601 pSocket
->errno
= ECONNRESET
;
609 // No more local adapters available
611 pSocket
->errno
= ENETUNREACH
;
612 Status
= EFI_NO_RESPONSE
;
616 // Return the operation status
618 DBG_EXIT_STATUS ( Status
);
624 Establish the known port to listen for network connections.
626 This routine places the port into a state that enables connection
629 This routine is called by ::EslSocketListen to handle the network
630 specifics of the listen operation for SOCK_STREAM and SOCK_SEQPACKET
631 sockets. See the \ref ConnectionManagement section.
633 @param [in] pSocket Address of an ::ESL_SOCKET structure.
635 @retval EFI_SUCCESS - Socket successfully created
636 @retval Other - Failed to enable the socket for listen
641 IN ESL_SOCKET
* pSocket
644 ESL_PORT
* pNextPort
;
646 ESL_TCP6_CONTEXT
* pTcp6
;
647 EFI_TCP6_PROTOCOL
* pTcp6Protocol
;
653 // Verify the socket layer synchronization
655 VERIFY_TPL ( TPL_SOCKETS
);
658 // Use for/break instead of goto
662 // Assume no ports are available
664 pSocket
->errno
= EOPNOTSUPP
;
665 Status
= EFI_NOT_READY
;
668 // Walk the list of ports
670 pPort
= pSocket
->pPortList
;
671 while ( NULL
!= pPort
) {
678 // Use for/break insteak of goto
682 // Create the listen completion event
684 pTcp6
= &pPort
->Context
.Tcp6
;
685 Status
= gBS
->CreateEvent ( EVT_NOTIFY_SIGNAL
,
687 (EFI_EVENT_NOTIFY
)EslTcp6ListenComplete
,
689 &pTcp6
->ListenToken
.CompletionToken
.Event
);
690 if ( EFI_ERROR ( Status
)) {
691 DEBUG (( DEBUG_ERROR
| DEBUG_LISTEN
,
692 "ERROR - Failed to create the listen completion event, Status: %r\r\n",
694 pSocket
->errno
= ENOMEM
;
698 "0x%08x: Created listen completion event\r\n",
699 pTcp6
->ListenToken
.CompletionToken
.Event
));
702 // Configure the port
704 pTcp6Protocol
= pPort
->pProtocol
.TCPv6
;
705 Status
= pTcp6Protocol
->Configure ( pTcp6Protocol
,
706 &pTcp6
->ConfigData
);
707 if ( EFI_ERROR ( Status
)) {
708 DEBUG (( DEBUG_LISTEN
,
709 "ERROR - Failed to configure the Tcp6 port, Status: %r\r\n",
712 case EFI_ACCESS_DENIED
:
713 pSocket
->errno
= EACCES
;
717 case EFI_DEVICE_ERROR
:
718 pSocket
->errno
= EIO
;
721 case EFI_INVALID_PARAMETER
:
722 pSocket
->errno
= EADDRNOTAVAIL
;
726 pSocket
->errno
= EAFNOSUPPORT
;
729 case EFI_OUT_OF_RESOURCES
:
730 pSocket
->errno
= ENOBUFS
;
733 case EFI_UNSUPPORTED
:
734 pSocket
->errno
= EOPNOTSUPP
;
739 DEBUG (( DEBUG_LISTEN
,
740 "0x%08x: Port configured\r\n",
742 pPort
->bConfigured
= TRUE
;
745 // Start the listen operation on the port
747 Status
= pTcp6Protocol
->Accept ( pTcp6Protocol
,
748 &pTcp6
->ListenToken
);
749 if ( EFI_ERROR ( Status
)) {
750 DEBUG (( DEBUG_LISTEN
,
751 "ERROR - Failed Tcp6 accept, Status: %r\r\n",
754 case EFI_ACCESS_DENIED
:
755 pSocket
->errno
= EACCES
;
759 case EFI_DEVICE_ERROR
:
760 pSocket
->errno
= EIO
;
763 case EFI_INVALID_PARAMETER
:
764 pSocket
->errno
= EADDRNOTAVAIL
;
767 case EFI_NOT_STARTED
:
768 pSocket
->errno
= ENETDOWN
;
771 case EFI_OUT_OF_RESOURCES
:
772 pSocket
->errno
= ENOBUFS
;
777 DEBUG (( DEBUG_LISTEN
,
778 "0x%08x: Listen pending on Port\r\n",
782 // Listen is pending on this port
790 pNextPort
= pPort
->pLinkSocket
;
793 // Close the port upon error
795 if ( EFI_ERROR ( Status
)) {
796 EslSocketPortCloseStart ( pPort
, TRUE
, DEBUG_LISTEN
);
806 // Determine if any ports are in the listen state
808 if ( NULL
== pSocket
->pPortList
) {
810 // No ports in the listen state
812 pSocket
->MaxFifoDepth
= 0;
815 // Return the last error detected
821 // Mark the socket as configured
823 pSocket
->bConfigured
= TRUE
;
828 DEBUG (( DEBUG_LISTEN
,
829 "0x%08x: pSocket - Listen pending on socket\r\n",
835 // Return the operation status
837 DBG_EXIT_STATUS ( Status
);
843 Process the connection attempt
845 A system has initiated a connection attempt with a socket in the
846 listen state. Attempt to complete the connection.
848 The TCPv6 layer calls this routine when a connection is made to
849 the socket in the listen state. See the
850 \ref ConnectionManagement section.
852 @param [in] Event The listen completion event
854 @param [in] pPort Address of an ::ESL_PORT structure.
858 EslTcp6ListenComplete (
863 EFI_HANDLE ChildHandle
;
864 struct sockaddr_in6 LocalAddress
;
865 EFI_TCP6_CONFIG_DATA
* pConfigData
;
868 ESL_SOCKET
* pNewSocket
;
869 ESL_SOCKET
* pSocket
;
870 ESL_TCP6_CONTEXT
* pTcp6
;
871 EFI_TCP6_PROTOCOL
* pTcp6Protocol
;
873 EFI_HANDLE TcpPortHandle
;
874 EFI_STATUS TempStatus
;
877 VERIFY_AT_TPL ( TPL_SOCKETS
);
882 Status
= EFI_SUCCESS
;
885 // Determine if this connection fits into the connection FIFO
887 pSocket
= pPort
->pSocket
;
888 TcpPortHandle
= pPort
->Context
.Tcp6
.ListenToken
.NewChildHandle
;
889 if (( SOCKET_STATE_LISTENING
== pSocket
->State
)
890 && ( pSocket
->MaxFifoDepth
> pSocket
->FifoDepth
)) {
892 // Allocate a socket for this connection
896 Status
= EslSocketAllocate ( &ChildHandle
,
899 if ( !EFI_ERROR ( Status
)) {
901 // Clone the socket parameters
903 pNewSocket
->pApi
= pSocket
->pApi
;
904 pNewSocket
->Domain
= pSocket
->Domain
;
905 pNewSocket
->Protocol
= pSocket
->Protocol
;
906 pNewSocket
->Type
= pSocket
->Type
;
909 // Build the local address
911 pTcp6
= &pPort
->Context
.Tcp6
;
912 LocalAddress
.sin6_len
= (uint8_t)pNewSocket
->pApi
->MinimumAddressLength
;
913 LocalAddress
.sin6_family
= AF_INET6
;
914 LocalAddress
.sin6_port
= 0;
915 CopyMem ( &LocalAddress
.sin6_addr
.__u6_addr
.__u6_addr8
[ 0 ],
916 &pTcp6
->ConfigData
.AccessPoint
.StationAddress
.Addr
[ 0 ],
917 sizeof ( pTcp6
->ConfigData
.AccessPoint
.StationAddress
.Addr
));
920 // Allocate a port for this connection
921 // Note in this instance Configure may not be called with NULL!
923 Status
= EslSocketPortAllocate ( pNewSocket
,
926 (struct sockaddr
*)&LocalAddress
,
930 if ( !EFI_ERROR ( Status
)) {
932 // Restart the listen operation on the port
934 pTcp6Protocol
= pPort
->pProtocol
.TCPv6
;
935 Status
= pTcp6Protocol
->Accept ( pTcp6Protocol
,
936 &pTcp6
->ListenToken
);
939 // Close the TCP port using SocketClose
941 TcpPortHandle
= NULL
;
942 pTcp6
= &pNewPort
->Context
.Tcp6
;
945 // Check for an accept call error
947 if ( !EFI_ERROR ( Status
)) {
949 // Get the port configuration
951 pNewPort
->bConfigured
= TRUE
;
952 pConfigData
= &pTcp6
->ConfigData
;
953 pConfigData
->ControlOption
= &pTcp6
->Option
;
954 pTcp6Protocol
= pNewPort
->pProtocol
.TCPv6
;
955 Status
= pTcp6Protocol
->GetModeData ( pTcp6Protocol
,
961 if ( !EFI_ERROR ( Status
)) {
963 // Add the new socket to the connection FIFO
965 if ( NULL
== pSocket
->pFifoTail
) {
969 pSocket
->pFifoHead
= pNewSocket
;
973 // Add to end of list.
975 pSocket
->pFifoTail
->pNextConnection
= pNewSocket
;
977 pSocket
->pFifoTail
= pNewSocket
;
978 pSocket
->FifoDepth
+= 1;
981 // Update the socket state
983 pNewSocket
->State
= SOCKET_STATE_IN_FIFO
;
986 // Log the connection
988 DEBUG (( DEBUG_CONNECTION
| DEBUG_INFO
,
989 "0x%08x: Socket on port [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d connected to [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",
991 pConfigData
->AccessPoint
.StationAddress
.Addr
[0],
992 pConfigData
->AccessPoint
.StationAddress
.Addr
[1],
993 pConfigData
->AccessPoint
.StationAddress
.Addr
[2],
994 pConfigData
->AccessPoint
.StationAddress
.Addr
[3],
995 pConfigData
->AccessPoint
.StationAddress
.Addr
[4],
996 pConfigData
->AccessPoint
.StationAddress
.Addr
[5],
997 pConfigData
->AccessPoint
.StationAddress
.Addr
[6],
998 pConfigData
->AccessPoint
.StationAddress
.Addr
[7],
999 pConfigData
->AccessPoint
.StationAddress
.Addr
[8],
1000 pConfigData
->AccessPoint
.StationAddress
.Addr
[9],
1001 pConfigData
->AccessPoint
.StationAddress
.Addr
[10],
1002 pConfigData
->AccessPoint
.StationAddress
.Addr
[11],
1003 pConfigData
->AccessPoint
.StationAddress
.Addr
[12],
1004 pConfigData
->AccessPoint
.StationAddress
.Addr
[13],
1005 pConfigData
->AccessPoint
.StationAddress
.Addr
[14],
1006 pConfigData
->AccessPoint
.StationAddress
.Addr
[15],
1007 pConfigData
->AccessPoint
.StationPort
,
1008 pConfigData
->AccessPoint
.RemoteAddress
.Addr
[0],
1009 pConfigData
->AccessPoint
.RemoteAddress
.Addr
[1],
1010 pConfigData
->AccessPoint
.RemoteAddress
.Addr
[2],
1011 pConfigData
->AccessPoint
.RemoteAddress
.Addr
[3],
1012 pConfigData
->AccessPoint
.RemoteAddress
.Addr
[4],
1013 pConfigData
->AccessPoint
.RemoteAddress
.Addr
[5],
1014 pConfigData
->AccessPoint
.RemoteAddress
.Addr
[6],
1015 pConfigData
->AccessPoint
.RemoteAddress
.Addr
[7],
1016 pConfigData
->AccessPoint
.RemoteAddress
.Addr
[8],
1017 pConfigData
->AccessPoint
.RemoteAddress
.Addr
[9],
1018 pConfigData
->AccessPoint
.RemoteAddress
.Addr
[10],
1019 pConfigData
->AccessPoint
.RemoteAddress
.Addr
[11],
1020 pConfigData
->AccessPoint
.RemoteAddress
.Addr
[12],
1021 pConfigData
->AccessPoint
.RemoteAddress
.Addr
[13],
1022 pConfigData
->AccessPoint
.RemoteAddress
.Addr
[14],
1023 pConfigData
->AccessPoint
.RemoteAddress
.Addr
[15],
1024 pConfigData
->AccessPoint
.RemotePort
));
1025 DEBUG (( DEBUG_CONNECTION
| DEBUG_INFO
,
1026 "0x%08x: Listen socket adding socket 0x%08x to FIFO, depth: %d\r\n",
1029 pSocket
->FifoDepth
));
1032 // Start the receive operation
1034 EslSocketRxStart ( pNewPort
);
1037 DEBUG (( DEBUG_ERROR
| DEBUG_CONNECTION
| DEBUG_INFO
,
1038 "ERROR - GetModeData failed on port 0x%08x, Status: %r\r\n",
1045 // The listen failed on this port
1047 DEBUG (( DEBUG_LISTEN
| DEBUG_INFO
,
1048 "ERROR - Listen failed on port 0x%08x, Status: %r\r\n",
1053 // Close the listening port
1055 EslSocketPortCloseStart ( pPort
, TRUE
, DEBUG_LISTEN
);
1060 // Done with the socket if necessary
1062 if ( EFI_ERROR ( Status
)) {
1063 TempStatus
= EslSocketCloseStart ( &pNewSocket
->SocketProtocol
,
1066 ASSERT ( EFI_SUCCESS
== TempStatus
);
1071 DEBUG (( DEBUG_CONNECTION
,
1072 "0x%08x: Socket FIFO full, connection refused\r\n",
1076 // The FIFO is full or the socket is in the wrong state
1078 Status
= EFI_BUFFER_TOO_SMALL
;
1082 // Close the connection if necessary
1084 if (( EFI_ERROR ( Status
))
1085 && ( NULL
== TcpPortHandle
)) {
1087 // TODO: Finish this code path
1088 // The new connection does not fit into the connection FIFO
1092 // Release the resources
1101 Get the local socket address.
1103 This routine returns the IPv6 address and TCP port number associated
1104 with the local socket.
1106 This routine is called by ::EslSocketGetLocalAddress to determine the
1107 network address for the SOCK_STREAM or SOCK_SEQPACKET socket.
1109 @param [in] pPort Address of an ::ESL_PORT structure.
1111 @param [out] pSockAddr Network address to receive the local system address
1115 EslTcp6LocalAddressGet (
1116 IN ESL_PORT
* pPort
,
1117 OUT
struct sockaddr
* pSockAddr
1120 struct sockaddr_in6
* pLocalAddress
;
1121 ESL_TCP6_CONTEXT
* pTcp6
;
1126 // Return the local address
1128 pTcp6
= &pPort
->Context
.Tcp6
;
1129 pLocalAddress
= (struct sockaddr_in6
*)pSockAddr
;
1130 pLocalAddress
->sin6_family
= AF_INET6
;
1131 pLocalAddress
->sin6_port
= SwapBytes16 ( pTcp6
->ConfigData
.AccessPoint
.StationPort
);
1132 CopyMem ( &pLocalAddress
->sin6_addr
,
1133 &pTcp6
->ConfigData
.AccessPoint
.StationAddress
.Addr
[0],
1134 sizeof ( pLocalAddress
->sin6_addr
));
1141 Set the local port address.
1143 This routine sets the local port address.
1145 This support routine is called by ::EslSocketPortAllocate.
1147 @param [in] pPort Address of an ESL_PORT structure
1148 @param [in] pSockAddr Address of a sockaddr structure that contains the
1149 connection point on the local machine. An IPv6 address
1150 of INADDR_ANY specifies that the connection is made to
1151 all of the network stacks on the platform. Specifying a
1152 specific IPv6 address restricts the connection to the
1153 network stack supporting that address. Specifying zero
1154 for the port causes the network layer to assign a port
1155 number from the dynamic range. Specifying a specific
1156 port number causes the network layer to use that port.
1158 @param [in] bBindTest TRUE = run bind testing
1160 @retval EFI_SUCCESS The operation was successful
1164 EslTcp6LocalAddressSet (
1165 IN ESL_PORT
* pPort
,
1166 IN CONST
struct sockaddr
* pSockAddr
,
1167 IN BOOLEAN bBindTest
1170 EFI_TCP6_ACCESS_POINT
* pAccessPoint
;
1171 CONST
struct sockaddr_in6
* pIpAddress
;
1177 // Validate the address
1179 pIpAddress
= (struct sockaddr_in6
*)pSockAddr
;
1181 // TODO: Fix the following check
1184 if ( INADDR_BROADCAST == pIpAddress->sin6_addr.s_addr ) {
1186 // The local address must not be the broadcast address
1188 Status = EFI_INVALID_PARAMETER;
1189 pPort->pSocket->errno = EADDRNOTAVAIL;
1195 // Set the local address
1197 pAccessPoint
= &pPort
->Context
.Tcp6
.ConfigData
.AccessPoint
;
1198 CopyMem ( &pAccessPoint
->StationAddress
.Addr
[0],
1199 &pIpAddress
->sin6_addr
.__u6_addr
.__u6_addr8
[ 0 ],
1200 sizeof ( pIpAddress
->sin6_addr
.__u6_addr
.__u6_addr8
[ 0 ]));
1203 // Validate the IP address
1205 pAccessPoint
->StationPort
= 0;
1206 Status
= bBindTest
? EslSocketBindTest ( pPort
, EADDRNOTAVAIL
)
1208 if ( !EFI_ERROR ( Status
)) {
1210 // Set the port number
1212 pAccessPoint
->StationPort
= SwapBytes16 ( pIpAddress
->sin6_port
);
1215 // Display the local address
1217 DEBUG (( DEBUG_BIND
,
1218 "0x%08x: Port, Local Tcp6 Address: [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",
1220 pAccessPoint
->StationAddress
.Addr
[0],
1221 pAccessPoint
->StationAddress
.Addr
[1],
1222 pAccessPoint
->StationAddress
.Addr
[2],
1223 pAccessPoint
->StationAddress
.Addr
[3],
1224 pAccessPoint
->StationAddress
.Addr
[4],
1225 pAccessPoint
->StationAddress
.Addr
[5],
1226 pAccessPoint
->StationAddress
.Addr
[6],
1227 pAccessPoint
->StationAddress
.Addr
[7],
1228 pAccessPoint
->StationAddress
.Addr
[8],
1229 pAccessPoint
->StationAddress
.Addr
[9],
1230 pAccessPoint
->StationAddress
.Addr
[10],
1231 pAccessPoint
->StationAddress
.Addr
[11],
1232 pAccessPoint
->StationAddress
.Addr
[12],
1233 pAccessPoint
->StationAddress
.Addr
[13],
1234 pAccessPoint
->StationAddress
.Addr
[14],
1235 pAccessPoint
->StationAddress
.Addr
[15],
1236 pAccessPoint
->StationPort
));
1241 // Return the operation status
1243 DBG_EXIT_STATUS ( Status
);
1249 Free a receive packet
1251 This routine performs the network specific operations necessary
1252 to free a receive packet.
1254 This routine is called by ::EslSocketPortCloseTxDone to free a
1257 @param [in] pPacket Address of an ::ESL_PACKET structure.
1258 @param [in, out] pRxBytes Address of the count of RX bytes
1263 IN ESL_PACKET
* pPacket
,
1264 IN OUT
size_t * pRxBytes
1270 // Account for the receive bytes
1272 *pRxBytes
-= pPacket
->Op
.Tcp6Rx
.RxData
.DataLength
;
1278 Initialize the network specific portions of an ::ESL_PORT structure.
1280 This routine initializes the network specific portions of an
1281 ::ESL_PORT structure for use by the socket.
1283 This support routine is called by ::EslSocketPortAllocate
1284 to connect the socket with the underlying network adapter
1285 running the TCPv6 protocol.
1287 @param [in] pPort Address of an ESL_PORT structure
1288 @param [in] DebugFlags Flags for debug messages
1290 @retval EFI_SUCCESS - Socket successfully created
1294 EslTcp6PortAllocate (
1295 IN ESL_PORT
* pPort
,
1299 EFI_TCP6_ACCESS_POINT
* pAccessPoint
;
1300 ESL_SOCKET
* pSocket
;
1301 ESL_TCP6_CONTEXT
* pTcp6
;
1307 // Use for/break instead of goto
1310 // Allocate the close event
1312 pSocket
= pPort
->pSocket
;
1313 pTcp6
= &pPort
->Context
.Tcp6
;
1314 Status
= gBS
->CreateEvent ( EVT_NOTIFY_SIGNAL
,
1316 (EFI_EVENT_NOTIFY
)EslSocketPortCloseComplete
,
1318 &pTcp6
->CloseToken
.CompletionToken
.Event
);
1319 if ( EFI_ERROR ( Status
)) {
1320 DEBUG (( DEBUG_ERROR
| DebugFlags
,
1321 "ERROR - Failed to create the close event, Status: %r\r\n",
1323 pSocket
->errno
= ENOMEM
;
1326 DEBUG (( DEBUG_CLOSE
| DEBUG_POOL
,
1327 "0x%08x: Created close event\r\n",
1328 pTcp6
->CloseToken
.CompletionToken
.Event
));
1331 // Allocate the connection event
1333 Status
= gBS
->CreateEvent ( EVT_NOTIFY_SIGNAL
,
1335 (EFI_EVENT_NOTIFY
)EslTcp6ConnectComplete
,
1337 &pTcp6
->ConnectToken
.CompletionToken
.Event
);
1338 if ( EFI_ERROR ( Status
)) {
1339 DEBUG (( DEBUG_ERROR
| DebugFlags
,
1340 "ERROR - Failed to create the connect event, Status: %r\r\n",
1342 pSocket
->errno
= ENOMEM
;
1345 DEBUG (( DEBUG_CLOSE
| DEBUG_POOL
,
1346 "0x%08x: Created connect event\r\n",
1347 pTcp6
->ConnectToken
.CompletionToken
.Event
));
1350 // Initialize the port
1352 pSocket
->TxPacketOffset
= OFFSET_OF ( ESL_PACKET
, Op
.Tcp6Tx
.TxData
);
1353 pSocket
->TxTokenEventOffset
= OFFSET_OF ( ESL_IO_MGMT
, Token
.Tcp6Tx
.CompletionToken
.Event
);
1354 pSocket
->TxTokenOffset
= OFFSET_OF ( EFI_TCP6_IO_TOKEN
, Packet
.TxData
);
1357 // Save the cancel, receive and transmit addresses
1358 // pPort->pfnRxCancel = NULL; since the UEFI implementation returns EFI_UNSUPPORTED
1360 pPort
->pfnConfigure
= (PFN_NET_CONFIGURE
)pPort
->pProtocol
.TCPv6
->Configure
;
1361 pPort
->pfnRxPoll
= (PFN_NET_POLL
)pPort
->pProtocol
.TCPv6
->Poll
;
1362 pPort
->pfnRxStart
= (PFN_NET_IO_START
)pPort
->pProtocol
.TCPv6
->Receive
;
1363 pPort
->pfnTxStart
= (PFN_NET_IO_START
)pPort
->pProtocol
.TCPv6
->Transmit
;
1366 // Set the configuration flags
1368 pAccessPoint
= &pPort
->Context
.Tcp6
.ConfigData
.AccessPoint
;
1369 pAccessPoint
->ActiveFlag
= FALSE
;
1370 pTcp6
->ConfigData
.TrafficClass
= 0;
1371 pTcp6
->ConfigData
.HopLimit
= 255;
1376 // Return the operation status
1378 DBG_EXIT_STATUS ( Status
);
1386 This routine releases the network specific resources allocated by
1387 ::EslTcp6PortAllocate.
1389 This routine is called by ::EslSocketPortClose.
1390 See the \ref PortCloseStateMachine section.
1392 @param [in] pPort Address of an ::ESL_PORT structure.
1394 @retval EFI_SUCCESS The port is closed
1395 @retval other Port close error
1404 ESL_TCP6_CONTEXT
* pTcp6
;
1410 // Locate the port in the socket list
1412 Status
= EFI_SUCCESS
;
1413 DebugFlags
= pPort
->DebugFlags
;
1414 pTcp6
= &pPort
->Context
.Tcp6
;
1417 // Done with the connect event
1419 if ( NULL
!= pTcp6
->ConnectToken
.CompletionToken
.Event
) {
1420 Status
= gBS
->CloseEvent ( pTcp6
->ConnectToken
.CompletionToken
.Event
);
1421 if ( !EFI_ERROR ( Status
)) {
1422 DEBUG (( DebugFlags
| DEBUG_POOL
,
1423 "0x%08x: Closed connect event\r\n",
1424 pTcp6
->ConnectToken
.CompletionToken
.Event
));
1427 DEBUG (( DEBUG_ERROR
| DebugFlags
,
1428 "ERROR - Failed to close the connect event, Status: %r\r\n",
1430 ASSERT ( EFI_SUCCESS
== Status
);
1435 // Done with the close event
1437 if ( NULL
!= pTcp6
->CloseToken
.CompletionToken
.Event
) {
1438 Status
= gBS
->CloseEvent ( pTcp6
->CloseToken
.CompletionToken
.Event
);
1439 if ( !EFI_ERROR ( Status
)) {
1440 DEBUG (( DebugFlags
| DEBUG_POOL
,
1441 "0x%08x: Closed close event\r\n",
1442 pTcp6
->CloseToken
.CompletionToken
.Event
));
1445 DEBUG (( DEBUG_ERROR
| DebugFlags
,
1446 "ERROR - Failed to close the close event, Status: %r\r\n",
1448 ASSERT ( EFI_SUCCESS
== Status
);
1453 // Done with the listen completion event
1455 if ( NULL
!= pTcp6
->ListenToken
.CompletionToken
.Event
) {
1456 Status
= gBS
->CloseEvent ( pTcp6
->ListenToken
.CompletionToken
.Event
);
1457 if ( !EFI_ERROR ( Status
)) {
1458 DEBUG (( DebugFlags
| DEBUG_POOL
,
1459 "0x%08x: Closed listen completion event\r\n",
1460 pTcp6
->ListenToken
.CompletionToken
.Event
));
1463 DEBUG (( DEBUG_ERROR
| DebugFlags
,
1464 "ERROR - Failed to close the listen completion event, Status: %r\r\n",
1466 ASSERT ( EFI_SUCCESS
== Status
);
1471 // Return the operation status
1473 DBG_EXIT_STATUS ( Status
);
1479 Perform the network specific close operation on the port.
1481 This routine performs a cancel operations on the TCPv6 port to
1482 shutdown the receive operations on the port.
1484 This routine is called by the ::EslSocketPortCloseTxDone
1485 routine after the port completes all of the transmission.
1487 @param [in] pPort Address of an ::ESL_PORT structure.
1489 @retval EFI_SUCCESS The port is closed, not normally returned
1490 @retval EFI_NOT_READY The port is still closing
1491 @retval EFI_ALREADY_STARTED Error, the port is in the wrong state,
1492 most likely the routine was called already.
1496 EslTcp6PortCloseOp (
1500 ESL_TCP6_CONTEXT
* pTcp6
;
1501 EFI_TCP6_PROTOCOL
* pTcp6Protocol
;
1507 // Close the configured port
1509 Status
= EFI_SUCCESS
;
1510 pTcp6
= &pPort
->Context
.Tcp6
;
1511 pTcp6Protocol
= pPort
->pProtocol
.TCPv6
;
1512 pTcp6
->CloseToken
.AbortOnClose
= pPort
->bCloseNow
;
1513 Status
= pTcp6Protocol
->Close ( pTcp6Protocol
,
1514 &pTcp6
->CloseToken
);
1515 if ( !EFI_ERROR ( Status
)) {
1516 DEBUG (( pPort
->DebugFlags
| DEBUG_CLOSE
| DEBUG_INFO
,
1517 "0x%08x: Port close started\r\n",
1521 DEBUG (( DEBUG_ERROR
| pPort
->DebugFlags
| DEBUG_CLOSE
| DEBUG_INFO
,
1522 "ERROR - Close failed on port 0x%08x, Status: %r\r\n",
1528 // Return the operation status
1530 DBG_EXIT_STATUS ( Status
);
1536 Receive data from a network connection.
1538 This routine attempts to return buffered data to the caller. The
1539 data is removed from the urgent queue if the message flag MSG_OOB
1540 is specified, otherwise data is removed from the normal queue.
1541 See the \ref ReceiveEngine section.
1543 This routine is called by ::EslSocketReceive to handle the network
1544 specific receive operation to support SOCK_STREAM and SOCK_SEQPACKET
1547 @param [in] pPort Address of an ::ESL_PORT structure.
1549 @param [in] pPacket Address of an ::ESL_PACKET structure.
1551 @param [in] pbConsumePacket Address of a BOOLEAN indicating if the packet is to be consumed
1553 @param [in] BufferLength Length of the the buffer
1555 @param [in] pBuffer Address of a buffer to receive the data.
1557 @param [in] pDataLength Number of received data bytes in the buffer.
1559 @param [out] pAddress Network address to receive the remote system address
1561 @param [out] pSkipBytes Address to receive the number of bytes skipped
1563 @return Returns the address of the next free byte in the buffer.
1568 IN ESL_PORT
* pPort
,
1569 IN ESL_PACKET
* pPacket
,
1570 IN BOOLEAN
* pbConsumePacket
,
1571 IN
size_t BufferLength
,
1573 OUT
size_t * pDataLength
,
1574 OUT
struct sockaddr
* pAddress
,
1575 OUT
size_t * pSkipBytes
1579 struct sockaddr_in6
* pRemoteAddress
;
1580 ESL_TCP6_CONTEXT
* pTcp6
;
1585 // Return the remote system address if requested
1587 if ( NULL
!= pAddress
) {
1589 // Build the remote address
1591 pTcp6
= &pPort
->Context
.Tcp6
;
1593 "Getting packet remote address: [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",
1594 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[0],
1595 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[1],
1596 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[2],
1597 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[3],
1598 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[4],
1599 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[5],
1600 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[6],
1601 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[7],
1602 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[8],
1603 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[9],
1604 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[10],
1605 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[11],
1606 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[12],
1607 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[13],
1608 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[14],
1609 pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[15],
1610 pTcp6
->ConfigData
.AccessPoint
.RemotePort
));
1611 pRemoteAddress
= (struct sockaddr_in6
*)pAddress
;
1612 CopyMem ( &pRemoteAddress
->sin6_addr
,
1613 &pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[0],
1614 sizeof ( pRemoteAddress
->sin6_addr
));
1615 pRemoteAddress
->sin6_port
= SwapBytes16 ( pTcp6
->ConfigData
.AccessPoint
.RemotePort
);
1619 // Determine the amount of received data
1621 DataLength
= pPacket
->ValidBytes
;
1622 if ( BufferLength
< DataLength
) {
1623 DataLength
= BufferLength
;
1627 // Move the data into the buffer
1630 "0x%08x: Port copy packet 0x%08x data into 0x%08x, 0x%08x bytes\r\n",
1635 CopyMem ( pBuffer
, pPacket
->pBuffer
, DataLength
);
1638 // Determine if the data is being read
1640 if ( *pbConsumePacket
) {
1642 // Account for the bytes consumed
1644 pPacket
->pBuffer
+= DataLength
;
1645 pPacket
->ValidBytes
-= DataLength
;
1647 "0x%08x: Port account for 0x%08x bytes\r\n",
1652 // Determine if the entire packet was consumed
1654 if (( 0 == pPacket
->ValidBytes
)
1655 || ( SOCK_STREAM
!= pPort
->pSocket
->Type
)) {
1657 // All done with this packet
1658 // Account for any discarded data
1660 *pSkipBytes
= pPacket
->ValidBytes
;
1665 // More data to consume later
1667 *pbConsumePacket
= FALSE
;
1672 // Return the data length and the buffer address
1674 *pDataLength
= DataLength
;
1675 DBG_EXIT_HEX ( pBuffer
);
1681 Get the remote socket address.
1683 This routine returns the address of the remote connection point
1684 associated with the SOCK_STREAM or SOCK_SEQPACKET socket.
1686 This routine is called by ::EslSocketGetPeerAddress to detemine
1687 the TCPv6 address and por number associated with the network adapter.
1689 @param [in] pPort Address of an ::ESL_PORT structure.
1691 @param [out] pAddress Network address to receive the remote system address
1695 EslTcp6RemoteAddressGet (
1696 IN ESL_PORT
* pPort
,
1697 OUT
struct sockaddr
* pAddress
1700 struct sockaddr_in6
* pRemoteAddress
;
1701 ESL_TCP6_CONTEXT
* pTcp6
;
1706 // Return the remote address
1708 pTcp6
= &pPort
->Context
.Tcp6
;
1709 pRemoteAddress
= (struct sockaddr_in6
*)pAddress
;
1710 pRemoteAddress
->sin6_family
= AF_INET6
;
1711 pRemoteAddress
->sin6_port
= SwapBytes16 ( pTcp6
->ConfigData
.AccessPoint
.RemotePort
);
1712 CopyMem ( &pRemoteAddress
->sin6_addr
,
1713 &pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[0],
1714 sizeof ( pRemoteAddress
->sin6_addr
));
1721 Set the remote address
1723 This routine sets the remote address in the port.
1725 This routine is called by ::EslSocketConnect to specify the
1726 remote network address.
1728 @param [in] pPort Address of an ::ESL_PORT structure.
1730 @param [in] pSockAddr Network address of the remote system.
1732 @param [in] SockAddrLength Length in bytes of the network address.
1734 @retval EFI_SUCCESS The operation was successful
1738 EslTcp6RemoteAddressSet (
1739 IN ESL_PORT
* pPort
,
1740 IN CONST
struct sockaddr
* pSockAddr
,
1741 IN socklen_t SockAddrLength
1744 CONST
struct sockaddr_in6
* pRemoteAddress
;
1745 ESL_TCP6_CONTEXT
* pTcp6
;
1751 // Set the remote address
1753 pTcp6
= &pPort
->Context
.Tcp6
;
1754 pRemoteAddress
= (struct sockaddr_in6
*)pSockAddr
;
1755 CopyMem ( &pTcp6
->ConfigData
.AccessPoint
.RemoteAddress
.Addr
[ 0 ],
1756 &pRemoteAddress
->sin6_addr
.__u6_addr
.__u6_addr8
[ 0 ],
1757 sizeof ( pRemoteAddress
->sin6_addr
.__u6_addr
.__u6_addr8
));
1758 pTcp6
->ConfigData
.AccessPoint
.RemotePort
= SwapBytes16 ( pRemoteAddress
->sin6_port
);
1759 Status
= EFI_SUCCESS
;
1762 // TODO: Fix the following check
1765 if ( INADDR_BROADCAST == pRemoteAddress->sin6_addr.s_addr ) {
1766 DEBUG (( DEBUG_CONNECT,
1767 "ERROR - Invalid remote address\r\n" ));
1768 Status = EFI_INVALID_PARAMETER;
1769 pPort->pSocket->errno = EAFNOSUPPORT;
1774 // Return the operation status
1776 DBG_EXIT_STATUS ( Status
);
1782 Process the receive completion
1784 This routine queues the data in FIFO order in either the urgent
1785 or normal data queues depending upon the type of data received.
1786 See the \ref ReceiveEngine section.
1788 This routine is called by the TCPv6 driver when some data is
1791 Buffer the data that was just received.
1793 @param [in] Event The receive completion event
1795 @param [in] pIo Address of an ::ESL_IO_MGMT structure
1801 IN ESL_IO_MGMT
* pIo
1805 size_t LengthInBytes
;
1806 ESL_PACKET
* pPacket
;
1812 // Get the operation status.
1814 Status
= pIo
->Token
.Tcp6Rx
.CompletionToken
.Status
;
1817 // +--------------------+ +---------------------------+
1818 // | ESL_IO_MGMT | | ESL_PACKET |
1820 // | +---------------+ +-----------------------+ |
1821 // | | Token | | EFI_Tcp6_RECEIVE_DATA | |
1822 // | | RxData --> | | |
1823 // | | | +-----------------------+---+
1824 // | | Event | | Data Buffer |
1825 // +----+---------------+ | |
1827 // +---------------------------+
1830 // Duplicate the buffer address and length for use by the
1831 // buffer handling code in EslTcp6Receive. These fields are
1832 // used when a partial read is done of the data from the
1835 pPacket
= pIo
->pPacket
;
1836 pPacket
->pBuffer
= pPacket
->Op
.Tcp6Rx
.RxData
.FragmentTable
[0].FragmentBuffer
;
1837 LengthInBytes
= pPacket
->Op
.Tcp6Rx
.RxData
.DataLength
;
1838 pPacket
->ValidBytes
= LengthInBytes
;
1841 // Get the data type so that it may be linked to the
1842 // correct receive buffer list on the ESL_SOCKET structure
1844 bUrgent
= pPacket
->Op
.Tcp6Rx
.RxData
.UrgentFlag
;
1847 // Complete this request
1849 EslSocketRxComplete ( pIo
, Status
, LengthInBytes
, bUrgent
);
1855 Start a receive operation
1857 This routine posts a receive buffer to the TCPv6 driver.
1858 See the \ref ReceiveEngine section.
1860 This support routine is called by EslSocketRxStart.
1862 @param [in] pPort Address of an ::ESL_PORT structure.
1863 @param [in] pIo Address of an ::ESL_IO_MGMT structure.
1868 IN ESL_PORT
* pPort
,
1869 IN ESL_IO_MGMT
* pIo
1872 ESL_PACKET
* pPacket
;
1877 // Initialize the buffer for receive
1879 pPacket
= pIo
->pPacket
;
1880 pIo
->Token
.Tcp6Rx
.Packet
.RxData
= &pPacket
->Op
.Tcp6Rx
.RxData
;
1881 pPacket
->Op
.Tcp6Rx
.RxData
.DataLength
= sizeof ( pPacket
->Op
.Tcp6Rx
.Buffer
);
1882 pPacket
->Op
.Tcp6Rx
.RxData
.FragmentCount
= 1;
1883 pPacket
->Op
.Tcp6Rx
.RxData
.FragmentTable
[0].FragmentLength
= pPacket
->Op
.Tcp6Rx
.RxData
.DataLength
;
1884 pPacket
->Op
.Tcp6Rx
.RxData
.FragmentTable
[0].FragmentBuffer
= &pPacket
->Op
.Tcp6Rx
.Buffer
[0];
1891 Determine if the socket is configured.
1893 This routine uses the flag ESL_SOCKET::bConfigured to determine
1894 if the network layer's configuration routine has been called.
1896 This routine is called by EslSocketIsConfigured to verify
1897 that the socket has been configured.
1899 @param [in] pSocket Address of an ::ESL_SOCKET structure.
1901 @retval EFI_SUCCESS - The port is connected
1902 @retval EFI_NOT_STARTED - The port is not connected
1906 EslTcp6SocketIsConfigured (
1907 IN ESL_SOCKET
* pSocket
1915 // Determine the socket configuration status
1917 Status
= pSocket
->bConfigured
? EFI_SUCCESS
: EFI_NOT_STARTED
;
1920 // Return the port connected state.
1922 DBG_EXIT_STATUS ( Status
);
1928 Buffer data for transmission over a network connection.
1930 This routine buffers data for the transmit engine in one of two
1931 queues, one for urgent (out-of-band) data and the other for normal
1932 data. The urgent data is provided to TCP as soon as it is available,
1933 allowing the TCP layer to schedule transmission of the urgent data
1934 between packets of normal data.
1936 This routine is called by ::EslSocketTransmit to buffer
1937 data for transmission. When the \ref TransmitEngine has resources,
1938 this routine will start the transmission of the next buffer on
1939 the network connection.
1941 Transmission errors are returned during the next transmission or
1942 during the close operation. Only buffering errors are returned
1943 during the current transmission attempt.
1945 @param [in] pSocket Address of an ::ESL_SOCKET structure
1947 @param [in] Flags Message control flags
1949 @param [in] BufferLength Length of the the buffer
1951 @param [in] pBuffer Address of a buffer to receive the data.
1953 @param [in] pDataLength Number of received data bytes in the buffer.
1955 @param [in] pAddress Network address of the remote system address
1957 @param [in] AddressLength Length of the remote network address structure
1959 @retval EFI_SUCCESS - Socket data successfully buffered
1964 IN ESL_SOCKET
* pSocket
,
1966 IN
size_t BufferLength
,
1967 IN CONST UINT8
* pBuffer
,
1968 OUT
size_t * pDataLength
,
1969 IN
const struct sockaddr
* pAddress
,
1970 IN socklen_t AddressLength
1974 BOOLEAN bUrgentQueue
;
1975 ESL_PACKET
* pPacket
;
1976 ESL_IO_MGMT
** ppActive
;
1977 ESL_IO_MGMT
** ppFree
;
1979 ESL_PACKET
** ppQueueHead
;
1980 ESL_PACKET
** ppQueueTail
;
1981 ESL_PACKET
* pPreviousPacket
;
1982 ESL_TCP6_CONTEXT
* pTcp6
;
1984 EFI_TCP6_TRANSMIT_DATA
* pTxData
;
1986 EFI_TPL TplPrevious
;
1993 Status
= EFI_UNSUPPORTED
;
1994 pSocket
->errno
= ENOTCONN
;
1998 // Verify that the socket is connected
2000 if ( SOCKET_STATE_CONNECTED
== pSocket
->State
) {
2004 pPort
= pSocket
->pPortList
;
2005 if ( NULL
!= pPort
) {
2007 // Determine the queue head
2009 pTcp6
= &pPort
->Context
.Tcp6
;
2010 bUrgent
= (BOOLEAN
)( 0 != ( Flags
& MSG_OOB
));
2011 bUrgentQueue
= bUrgent
2012 && ( !pSocket
->bOobInLine
)
2013 && pSocket
->pApi
->bOobSupported
;
2014 if ( bUrgentQueue
) {
2015 ppQueueHead
= &pSocket
->pTxOobPacketListHead
;
2016 ppQueueTail
= &pSocket
->pTxOobPacketListTail
;
2017 ppActive
= &pPort
->pTxOobActive
;
2018 ppFree
= &pPort
->pTxOobFree
;
2019 pTxBytes
= &pSocket
->TxOobBytes
;
2022 ppQueueHead
= &pSocket
->pTxPacketListHead
;
2023 ppQueueTail
= &pSocket
->pTxPacketListTail
;
2024 ppActive
= &pPort
->pTxActive
;
2025 ppFree
= &pPort
->pTxFree
;
2026 pTxBytes
= &pSocket
->TxBytes
;
2030 // Verify that there is enough room to buffer another
2031 // transmit operation
2033 if ( pSocket
->MaxTxBuf
> *pTxBytes
) {
2034 if ( pPort
->bTxFlowControl
) {
2036 "TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\r\n0x%08x: pPort, TX flow control released, Max bytes: %d > %d bufferred bytes\r\n",
2040 pPort
->bTxFlowControl
= FALSE
;
2044 // Attempt to allocate the packet
2046 Status
= EslSocketPacketAllocate ( &pPacket
,
2047 sizeof ( pPacket
->Op
.Tcp6Tx
)
2048 - sizeof ( pPacket
->Op
.Tcp6Tx
.Buffer
)
2052 if ( !EFI_ERROR ( Status
)) {
2054 // Initialize the transmit operation
2056 pTxData
= &pPacket
->Op
.Tcp6Tx
.TxData
;
2057 pTxData
->Push
= TRUE
|| bUrgent
;
2058 pTxData
->Urgent
= bUrgent
;
2059 pTxData
->DataLength
= (UINT32
) BufferLength
;
2060 pTxData
->FragmentCount
= 1;
2061 pTxData
->FragmentTable
[0].FragmentLength
= (UINT32
) BufferLength
;
2062 pTxData
->FragmentTable
[0].FragmentBuffer
= &pPacket
->Op
.Tcp6Tx
.Buffer
[0];
2065 // Copy the data into the buffer
2067 CopyMem ( &pPacket
->Op
.Tcp6Tx
.Buffer
[0],
2072 // Synchronize with the socket layer
2074 RAISE_TPL ( TplPrevious
, TPL_SOCKETS
);
2077 // Stop transmission after an error
2079 if ( !EFI_ERROR ( pSocket
->TxError
)) {
2081 // Display the request
2084 "Send %d %s bytes from 0x%08x\r\n",
2086 bUrgent
? L
"urgent" : L
"normal",
2090 // Queue the data for transmission
2092 pPacket
->pNext
= NULL
;
2093 pPreviousPacket
= *ppQueueTail
;
2094 if ( NULL
== pPreviousPacket
) {
2095 *ppQueueHead
= pPacket
;
2098 pPreviousPacket
->pNext
= pPacket
;
2100 *ppQueueTail
= pPacket
;
2102 "0x%08x: Packet on %s transmit list\r\n",
2104 bUrgentQueue
? L
"urgent" : L
"normal" ));
2107 // Account for the buffered data
2109 *pTxBytes
+= BufferLength
;
2110 *pDataLength
= BufferLength
;
2113 // Start the transmit engine if it is idle
2115 if ( NULL
!= *ppFree
) {
2116 EslSocketTxStart ( pPort
,
2125 // Previous transmit error
2126 // Stop transmission
2128 Status
= pSocket
->TxError
;
2129 pSocket
->errno
= EIO
;
2134 EslSocketPacketFree ( pPacket
, DEBUG_TX
);
2138 // Release the socket layer synchronization
2140 RESTORE_TPL ( TplPrevious
);
2144 // Packet allocation failed
2146 pSocket
->errno
= ENOMEM
;
2150 if ( !pPort
->bTxFlowControl
) {
2152 "0x%08x: pPort, TX flow control applied, Max bytes %d <= %d bufferred bytes\r\nTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\r\n",
2156 pPort
->bTxFlowControl
= TRUE
;
2159 // Not enough buffer space available
2161 pSocket
->errno
= EAGAIN
;
2162 Status
= EFI_NOT_READY
;
2168 // Return the operation status
2170 DBG_EXIT_STATUS ( Status
);
2176 Process the normal data transmit completion
2178 This routine use ::EslSocketTxComplete to perform the transmit
2179 completion processing for normal data.
2181 This routine is called by the TCPv6 network layer when a
2182 normal data transmit request completes.
2184 @param [in] Event The normal transmit completion event
2186 @param [in] pIo The ESL_IO_MGMT structure address
2192 IN ESL_IO_MGMT
* pIo
2195 UINT32 LengthInBytes
;
2196 ESL_PACKET
* pPacket
;
2198 ESL_SOCKET
* pSocket
;
2204 // Locate the active transmit packet
2206 pPacket
= pIo
->pPacket
;
2208 pSocket
= pPort
->pSocket
;
2211 // Get the transmit length and status
2213 LengthInBytes
= pPacket
->Op
.Tcp6Tx
.TxData
.DataLength
;
2214 pSocket
->TxBytes
-= LengthInBytes
;
2215 Status
= pIo
->Token
.Tcp6Tx
.CompletionToken
.Status
;
2218 // Complete the transmit operation
2220 EslSocketTxComplete ( pIo
,
2224 &pSocket
->pTxPacketListHead
,
2225 &pSocket
->pTxPacketListTail
,
2233 Process the urgent data transmit completion
2235 This routine use ::EslSocketTxComplete to perform the transmit
2236 completion processing for urgent data.
2238 This routine is called by the TCPv6 network layer when a
2239 urgent data transmit request completes.
2241 @param [in] Event The urgent transmit completion event
2243 @param [in] pIo The ESL_IO_MGMT structure address
2247 EslTcp6TxOobComplete (
2249 IN ESL_IO_MGMT
* pIo
2252 UINT32 LengthInBytes
;
2253 ESL_PACKET
* pPacket
;
2255 ESL_SOCKET
* pSocket
;
2261 // Locate the active transmit packet
2263 pPacket
= pIo
->pPacket
;
2265 pSocket
= pPort
->pSocket
;
2268 // Get the transmit length and status
2270 LengthInBytes
= pPacket
->Op
.Tcp6Tx
.TxData
.DataLength
;
2271 pSocket
->TxOobBytes
-= LengthInBytes
;
2272 Status
= pIo
->Token
.Tcp6Tx
.CompletionToken
.Status
;
2275 // Complete the transmit operation
2277 EslSocketTxComplete ( pIo
,
2281 &pSocket
->pTxOobPacketListHead
,
2282 &pSocket
->pTxOobPacketListTail
,
2283 &pPort
->pTxOobActive
,
2284 &pPort
->pTxOobFree
);
2290 Interface between the socket layer and the network specific
2291 code that supports SOCK_STREAM and SOCK_SEQPACKET sockets
2294 CONST ESL_PROTOCOL_API cEslTcp6Api
= {
2297 OFFSET_OF ( ESL_PORT
, Context
.Tcp6
.ConfigData
),
2298 OFFSET_OF ( ESL_LAYER
, pTcp6List
),
2299 sizeof ( struct sockaddr_in6
),
2300 sizeof ( struct sockaddr_in6
),
2302 sizeof (((ESL_PACKET
*)0 )->Op
.Tcp6Rx
),
2303 OFFSET_OF ( ESL_PACKET
, Op
.Tcp6Rx
.Buffer
) - OFFSET_OF ( ESL_PACKET
, Op
),
2304 OFFSET_OF ( ESL_IO_MGMT
, Token
.Tcp6Rx
.Packet
.RxData
),
2309 EslTcp6ConnectStart
,
2310 EslTcp6SocketIsConfigured
,
2311 EslTcp6LocalAddressGet
,
2312 EslTcp6LocalAddressSet
,
2317 EslTcp6PortAllocate
,
2322 EslTcp6RemoteAddressGet
,
2323 EslTcp6RemoteAddressSet
,
2328 EslTcp6TxOobComplete