2 Implement the UDP4 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.
19 Get the local socket address
21 This routine returns the IPv6 address and UDP port number associated
22 with the local socket.
24 This routine is called by ::EslSocketGetLocalAddress to determine the
25 network address for the SOCK_DGRAM socket.
27 @param [in] pPort Address of an ::ESL_PORT structure.
29 @param [out] pSockAddr Network address to receive the local system address
33 EslUdp6LocalAddressGet (
35 OUT
struct sockaddr
* pSockAddr
38 struct sockaddr_in6
* pLocalAddress
;
39 ESL_UDP6_CONTEXT
* pUdp6
;
44 // Return the local address
46 pUdp6
= &pPort
->Context
.Udp6
;
47 pLocalAddress
= (struct sockaddr_in6
*)pSockAddr
;
48 pLocalAddress
->sin6_family
= AF_INET6
;
49 pLocalAddress
->sin6_port
= SwapBytes16 ( pUdp6
->ConfigData
.StationPort
);
50 CopyMem ( &pLocalAddress
->sin6_addr
,
51 &pUdp6
->ConfigData
.StationAddress
.Addr
[0],
52 sizeof ( pLocalAddress
->sin6_addr
));
59 Set the local port address.
61 This routine sets the local port address.
63 This support routine is called by ::EslSocketPortAllocate.
65 @param [in] pPort Address of an ESL_PORT structure
66 @param [in] pSockAddr Address of a sockaddr structure that contains the
67 connection point on the local machine. An IPv6 address
68 of INADDR_ANY specifies that the connection is made to
69 all of the network stacks on the platform. Specifying a
70 specific IPv6 address restricts the connection to the
71 network stack supporting that address. Specifying zero
72 for the port causes the network layer to assign a port
73 number from the dynamic range. Specifying a specific
74 port number causes the network layer to use that port.
76 @param [in] bBindTest TRUE = run bind testing
78 @retval EFI_SUCCESS The operation was successful
82 EslUdp6LocalAddressSet (
84 IN CONST
struct sockaddr
* pSockAddr
,
88 EFI_UDP6_CONFIG_DATA
* pConfig
;
89 CONST
struct sockaddr_in6
* pIpAddress
;
90 CONST UINT8
* pIPv6Address
;
96 // Set the local address
98 pIpAddress
= (struct sockaddr_in6
*)pSockAddr
;
99 pIPv6Address
= (UINT8
*)&pIpAddress
->sin6_addr
;
100 pConfig
= &pPort
->Context
.Udp6
.ConfigData
;
101 CopyMem ( &pConfig
->StationAddress
,
103 sizeof ( pConfig
->StationAddress
));
106 // Validate the IP address
108 pConfig
->StationPort
= 0;
109 Status
= bBindTest
? EslSocketBindTest ( pPort
, EADDRNOTAVAIL
)
111 if ( !EFI_ERROR ( Status
)) {
113 // Set the port number
115 pConfig
->StationPort
= SwapBytes16 ( pIpAddress
->sin6_port
);
116 pPort
->pSocket
->bAddressSet
= TRUE
;
119 // Display the local address
122 "0x%08x: Port, Local UDP6 Address: [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",
124 pConfig
->StationAddress
.Addr
[0],
125 pConfig
->StationAddress
.Addr
[1],
126 pConfig
->StationAddress
.Addr
[2],
127 pConfig
->StationAddress
.Addr
[3],
128 pConfig
->StationAddress
.Addr
[4],
129 pConfig
->StationAddress
.Addr
[5],
130 pConfig
->StationAddress
.Addr
[6],
131 pConfig
->StationAddress
.Addr
[7],
132 pConfig
->StationAddress
.Addr
[8],
133 pConfig
->StationAddress
.Addr
[9],
134 pConfig
->StationAddress
.Addr
[10],
135 pConfig
->StationAddress
.Addr
[11],
136 pConfig
->StationAddress
.Addr
[12],
137 pConfig
->StationAddress
.Addr
[13],
138 pConfig
->StationAddress
.Addr
[14],
139 pConfig
->StationAddress
.Addr
[15],
140 pConfig
->StationPort
));
144 // Return the operation status
146 DBG_EXIT_STATUS ( Status
);
152 Free a receive packet
154 This routine performs the network specific operations necessary
155 to free a receive packet.
157 This routine is called by ::EslSocketPortCloseTxDone to free a
160 @param [in] pPacket Address of an ::ESL_PACKET structure.
161 @param [in, out] pRxBytes Address of the count of RX bytes
166 IN ESL_PACKET
* pPacket
,
167 IN OUT
size_t * pRxBytes
170 EFI_UDP6_RECEIVE_DATA
* pRxData
;
175 // Account for the receive bytes
177 pRxData
= pPacket
->Op
.Udp6Rx
.pRxData
;
178 *pRxBytes
-= pRxData
->DataLength
;
181 // Disconnect the buffer from the packet
183 pPacket
->Op
.Udp6Rx
.pRxData
= NULL
;
186 // Return the buffer to the UDP6 driver
188 gBS
->SignalEvent ( pRxData
->RecycleSignal
);
194 Initialize the network specific portions of an ::ESL_PORT structure.
196 This routine initializes the network specific portions of an
197 ::ESL_PORT structure for use by the socket.
199 This support routine is called by ::EslSocketPortAllocate
200 to connect the socket with the underlying network adapter
201 running the UDPv4 protocol.
203 @param [in] pPort Address of an ESL_PORT structure
204 @param [in] DebugFlags Flags for debug messages
206 @retval EFI_SUCCESS - Socket successfully created
210 EslUdp6PortAllocate (
215 EFI_UDP6_CONFIG_DATA
* pConfig
;
216 ESL_SOCKET
* pSocket
;
222 // Initialize the port
224 pSocket
= pPort
->pSocket
;
225 pSocket
->TxPacketOffset
= OFFSET_OF ( ESL_PACKET
, Op
.Udp6Tx
.TxData
);
226 pSocket
->TxTokenEventOffset
= OFFSET_OF ( ESL_IO_MGMT
, Token
.Udp6Tx
.Event
);
227 pSocket
->TxTokenOffset
= OFFSET_OF ( EFI_UDP6_COMPLETION_TOKEN
, Packet
.TxData
);
230 // Save the cancel, receive and transmit addresses
232 pPort
->pfnConfigure
= (PFN_NET_CONFIGURE
)pPort
->pProtocol
.UDPv6
->Configure
;
233 pPort
->pfnRxCancel
= (PFN_NET_IO_START
)pPort
->pProtocol
.UDPv6
->Cancel
;
234 pPort
->pfnRxPoll
= (PFN_NET_POLL
)pPort
->pProtocol
.UDPv6
->Poll
;
235 pPort
->pfnRxStart
= (PFN_NET_IO_START
)pPort
->pProtocol
.UDPv6
->Receive
;
236 pPort
->pfnTxStart
= (PFN_NET_IO_START
)pPort
->pProtocol
.UDPv6
->Transmit
;
239 // Do not drop packets
241 pConfig
= &pPort
->Context
.Udp6
.ConfigData
;
242 pConfig
->ReceiveTimeout
= 0;
243 pConfig
->ReceiveTimeout
= pConfig
->ReceiveTimeout
;
246 // Set the configuration flags
248 pConfig
->AllowDuplicatePort
= TRUE
;
249 pConfig
->AcceptAnyPort
= FALSE
;
250 pConfig
->AcceptPromiscuous
= FALSE
;
251 pConfig
->HopLimit
= 255;
252 pConfig
->TrafficClass
= 0;
254 Status
= EFI_SUCCESS
;
257 // Return the operation status
259 DBG_EXIT_STATUS ( Status
);
265 Receive data from a network connection.
267 This routine attempts to return buffered data to the caller. The
268 data is removed from the urgent queue if the message flag MSG_OOB
269 is specified, otherwise data is removed from the normal queue.
270 See the \ref ReceiveEngine section.
272 This routine is called by ::EslSocketReceive to handle the network
273 specific receive operation to support SOCK_DGRAM sockets.
275 @param [in] pPort Address of an ::ESL_PORT structure.
277 @param [in] pPacket Address of an ::ESL_PACKET structure.
279 @param [in] pbConsumePacket Address of a BOOLEAN indicating if the packet is to be consumed
281 @param [in] BufferLength Length of the the buffer
283 @param [in] pBuffer Address of a buffer to receive the data.
285 @param [in] pDataLength Number of received data bytes in the buffer.
287 @param [out] pAddress Network address to receive the remote system address
289 @param [out] pSkipBytes Address to receive the number of bytes skipped
291 @return Returns the address of the next free byte in the buffer.
297 IN ESL_PACKET
* pPacket
,
298 IN BOOLEAN
* pbConsumePacket
,
299 IN
size_t BufferLength
,
301 OUT
size_t * pDataLength
,
302 OUT
struct sockaddr
* pAddress
,
303 OUT
size_t * pSkipBytes
307 struct sockaddr_in6
* pRemoteAddress
;
308 EFI_UDP6_RECEIVE_DATA
* pRxData
;
312 pRxData
= pPacket
->Op
.Udp6Rx
.pRxData
;
314 // Return the remote system address if requested
316 if ( NULL
!= pAddress
) {
318 // Build the remote address
321 "Getting packet remote address: [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",
322 pRxData
->UdpSession
.SourceAddress
.Addr
[0],
323 pRxData
->UdpSession
.SourceAddress
.Addr
[1],
324 pRxData
->UdpSession
.SourceAddress
.Addr
[2],
325 pRxData
->UdpSession
.SourceAddress
.Addr
[3],
326 pRxData
->UdpSession
.SourceAddress
.Addr
[4],
327 pRxData
->UdpSession
.SourceAddress
.Addr
[5],
328 pRxData
->UdpSession
.SourceAddress
.Addr
[6],
329 pRxData
->UdpSession
.SourceAddress
.Addr
[7],
330 pRxData
->UdpSession
.SourceAddress
.Addr
[8],
331 pRxData
->UdpSession
.SourceAddress
.Addr
[9],
332 pRxData
->UdpSession
.SourceAddress
.Addr
[10],
333 pRxData
->UdpSession
.SourceAddress
.Addr
[11],
334 pRxData
->UdpSession
.SourceAddress
.Addr
[12],
335 pRxData
->UdpSession
.SourceAddress
.Addr
[13],
336 pRxData
->UdpSession
.SourceAddress
.Addr
[14],
337 pRxData
->UdpSession
.SourceAddress
.Addr
[15],
338 pRxData
->UdpSession
.SourcePort
));
339 pRemoteAddress
= (struct sockaddr_in6
*)pAddress
;
340 CopyMem ( &pRemoteAddress
->sin6_addr
,
341 &pRxData
->UdpSession
.SourceAddress
.Addr
[0],
342 sizeof ( pRemoteAddress
->sin6_addr
));
343 pRemoteAddress
->sin6_port
= SwapBytes16 ( pRxData
->UdpSession
.SourcePort
);
347 // Copy the received data
349 pBuffer
= EslSocketCopyFragmentedBuffer ( pRxData
->FragmentCount
,
350 (EFI_IP4_FRAGMENT_DATA
*)&pRxData
->FragmentTable
[0],
356 // Determine if the data is being read
358 if ( *pbConsumePacket
) {
360 // Display for the bytes consumed
363 "0x%08x: Port account for 0x%08x bytes\r\n",
368 // Account for any discarded data
370 *pSkipBytes
= pRxData
->DataLength
- DataBytes
;
374 // Return the data length and the buffer address
376 *pDataLength
= DataBytes
;
377 DBG_EXIT_HEX ( pBuffer
);
383 Get the remote socket address
385 This routine returns the address of the remote connection point
386 associated with the SOCK_DGRAM socket.
388 This routine is called by ::EslSocketGetPeerAddress to detemine
389 the UDPv4 address and port number associated with the network adapter.
391 @param [in] pPort Address of an ::ESL_PORT structure.
393 @param [out] pAddress Network address to receive the remote system address
397 EslUdp6RemoteAddressGet (
399 OUT
struct sockaddr
* pAddress
402 struct sockaddr_in6
* pRemoteAddress
;
403 ESL_UDP6_CONTEXT
* pUdp6
;
408 // Return the remote address
410 pUdp6
= &pPort
->Context
.Udp6
;
411 pRemoteAddress
= (struct sockaddr_in6
*)pAddress
;
412 pRemoteAddress
->sin6_family
= AF_INET6
;
413 pRemoteAddress
->sin6_port
= SwapBytes16 ( pUdp6
->ConfigData
.RemotePort
);
414 CopyMem ( &pRemoteAddress
->sin6_addr
,
415 &pUdp6
->ConfigData
.RemoteAddress
.Addr
[0],
416 sizeof ( pRemoteAddress
->sin6_addr
));
423 Set the remote address
425 This routine sets the remote address in the port.
427 This routine is called by ::EslSocketConnect to specify the
428 remote network address.
430 @param [in] pPort Address of an ::ESL_PORT structure.
432 @param [in] pSockAddr Network address of the remote system.
434 @param [in] SockAddrLength Length in bytes of the network address.
436 @retval EFI_SUCCESS The operation was successful
440 EslUdp6RemoteAddressSet (
442 IN CONST
struct sockaddr
* pSockAddr
,
443 IN socklen_t SockAddrLength
446 CONST
struct sockaddr_in6
* pRemoteAddress
;
447 ESL_UDP6_CONTEXT
* pUdp6
;
453 // Set the remote address
455 pUdp6
= &pPort
->Context
.Udp6
;
456 pRemoteAddress
= (struct sockaddr_in6
*)pSockAddr
;
457 CopyMem ( &pUdp6
->ConfigData
.RemoteAddress
,
458 &pRemoteAddress
->sin6_addr
,
459 sizeof ( pUdp6
->ConfigData
.RemoteAddress
));
460 pUdp6
->ConfigData
.RemotePort
= SwapBytes16 ( pRemoteAddress
->sin6_port
);
461 Status
= EFI_SUCCESS
;
464 // Return the operation status
466 DBG_EXIT_STATUS ( Status
);
472 Process the receive completion
474 This routine keeps the UDPv4 driver's buffer and queues it in
475 in FIFO order to the data queue. The UDP6 driver's buffer will
476 be returned by either ::EslUdp6Receive or ::EslSocketPortCloseTxDone.
477 See the \ref ReceiveEngine section.
479 This routine is called by the UDPv4 driver when data is
482 @param [in] Event The receive completion event
484 @param [in] pIo Address of an ::ESL_IO_MGMT structure
493 size_t LengthInBytes
;
494 ESL_PACKET
* pPacket
;
495 EFI_UDP6_RECEIVE_DATA
* pRxData
;
501 // Get the operation status.
503 Status
= pIo
->Token
.Udp6Rx
.Status
;
506 // Get the packet length
508 pRxData
= pIo
->Token
.Udp6Rx
.Packet
.RxData
;
509 LengthInBytes
= pRxData
->DataLength
;
512 // +--------------------+ +-----------------------+
513 // | ESL_IO_MGMT | | Data Buffer |
514 // | | | (Driver owned) |
515 // | +---------------+ +-----------------------+
518 // | | | +-----------------------+
519 // | | RxData --> | EFI_UDP6_RECEIVE_DATA |
520 // +----+---------------+ | (Driver owned) |
521 // +-----------------------+
522 // +--------------------+ ^
525 // | +---------------+ .
526 // | | pRxData --> NULL .......
527 // +----+---------------+
530 // Save the data in the packet
532 pPacket
= pIo
->pPacket
;
533 pPacket
->Op
.Udp6Rx
.pRxData
= pRxData
;
536 // Complete this request
538 EslSocketRxComplete ( pIo
, Status
, LengthInBytes
, FALSE
);
544 Determine if the socket is configured.
546 This routine uses the flag ESL_SOCKET::bConfigured to determine
547 if the network layer's configuration routine has been called.
548 This routine calls the bind and configuration routines if they
549 were not already called. After the port is configured, the
550 \ref ReceiveEngine is started.
552 This routine is called by EslSocketIsConfigured to verify
553 that the socket is configured.
555 @param [in] pSocket Address of an ::ESL_SOCKET structure
557 @retval EFI_SUCCESS - The port is connected
558 @retval EFI_NOT_STARTED - The port is not connected
562 EslUdp6SocketIsConfigured (
563 IN ESL_SOCKET
* pSocket
566 EFI_UDP6_CONFIG_DATA
* pConfigData
;
568 ESL_PORT
* pNextPort
;
569 ESL_UDP6_CONTEXT
* pUdp6
;
570 EFI_UDP6_PROTOCOL
* pUdp6Protocol
;
572 struct sockaddr_in6 LocalAddress
;
579 Status
= EFI_SUCCESS
;
582 // Configure the port if necessary
584 if ( !pSocket
->bConfigured
) {
586 // Fill in the port list if necessary
588 pSocket
->errno
= ENETDOWN
;
589 if ( NULL
== pSocket
->pPortList
) {
590 ZeroMem ( &LocalAddress
, sizeof ( LocalAddress
));
591 LocalAddress
.sin6_len
= sizeof ( LocalAddress
);
592 LocalAddress
.sin6_family
= AF_INET6
;
593 Status
= EslSocketBind ( &pSocket
->SocketProtocol
,
594 (struct sockaddr
*)&LocalAddress
,
595 LocalAddress
.sin6_len
,
600 // Walk the port list
602 pPort
= pSocket
->pPortList
;
603 while ( NULL
!= pPort
) {
605 // Attempt to configure the port
607 pNextPort
= pPort
->pLinkSocket
;
608 pUdp6
= &pPort
->Context
.Udp6
;
609 pUdp6Protocol
= pPort
->pProtocol
.UDPv6
;
610 pConfigData
= &pUdp6
->ConfigData
;
612 "0x%08x: pPort Configuring for [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d --> [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",
614 pConfigData
->StationAddress
.Addr
[0],
615 pConfigData
->StationAddress
.Addr
[1],
616 pConfigData
->StationAddress
.Addr
[2],
617 pConfigData
->StationAddress
.Addr
[3],
618 pConfigData
->StationAddress
.Addr
[4],
619 pConfigData
->StationAddress
.Addr
[5],
620 pConfigData
->StationAddress
.Addr
[6],
621 pConfigData
->StationAddress
.Addr
[7],
622 pConfigData
->StationAddress
.Addr
[8],
623 pConfigData
->StationAddress
.Addr
[9],
624 pConfigData
->StationAddress
.Addr
[10],
625 pConfigData
->StationAddress
.Addr
[11],
626 pConfigData
->StationAddress
.Addr
[12],
627 pConfigData
->StationAddress
.Addr
[13],
628 pConfigData
->StationAddress
.Addr
[14],
629 pConfigData
->StationAddress
.Addr
[15],
630 pConfigData
->StationPort
,
631 pConfigData
->RemoteAddress
.Addr
[0],
632 pConfigData
->RemoteAddress
.Addr
[1],
633 pConfigData
->RemoteAddress
.Addr
[2],
634 pConfigData
->RemoteAddress
.Addr
[3],
635 pConfigData
->RemoteAddress
.Addr
[4],
636 pConfigData
->RemoteAddress
.Addr
[5],
637 pConfigData
->RemoteAddress
.Addr
[6],
638 pConfigData
->RemoteAddress
.Addr
[7],
639 pConfigData
->RemoteAddress
.Addr
[8],
640 pConfigData
->RemoteAddress
.Addr
[9],
641 pConfigData
->RemoteAddress
.Addr
[10],
642 pConfigData
->RemoteAddress
.Addr
[11],
643 pConfigData
->RemoteAddress
.Addr
[12],
644 pConfigData
->RemoteAddress
.Addr
[13],
645 pConfigData
->RemoteAddress
.Addr
[14],
646 pConfigData
->RemoteAddress
.Addr
[15],
647 pConfigData
->RemotePort
));
648 Status
= pUdp6Protocol
->Configure ( pUdp6Protocol
,
650 if ( !EFI_ERROR ( Status
)) {
652 // Update the configuration data
654 Status
= pUdp6Protocol
->GetModeData ( pUdp6Protocol
,
660 if ( EFI_ERROR ( Status
)) {
661 if ( !pSocket
->bConfigured
) {
662 DEBUG (( DEBUG_LISTEN
,
663 "ERROR - Failed to configure the Udp6 port, Status: %r\r\n",
666 case EFI_ACCESS_DENIED
:
667 pSocket
->errno
= EACCES
;
671 case EFI_DEVICE_ERROR
:
672 pSocket
->errno
= EIO
;
675 case EFI_INVALID_PARAMETER
:
676 pSocket
->errno
= EADDRNOTAVAIL
;
680 pSocket
->errno
= EAFNOSUPPORT
;
683 case EFI_OUT_OF_RESOURCES
:
684 pSocket
->errno
= ENOBUFS
;
687 case EFI_UNSUPPORTED
:
688 pSocket
->errno
= EOPNOTSUPP
;
695 "0x%08x: pPort Configured for [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d --> [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",
697 pConfigData
->StationAddress
.Addr
[0],
698 pConfigData
->StationAddress
.Addr
[1],
699 pConfigData
->StationAddress
.Addr
[2],
700 pConfigData
->StationAddress
.Addr
[3],
701 pConfigData
->StationAddress
.Addr
[4],
702 pConfigData
->StationAddress
.Addr
[5],
703 pConfigData
->StationAddress
.Addr
[6],
704 pConfigData
->StationAddress
.Addr
[7],
705 pConfigData
->StationAddress
.Addr
[8],
706 pConfigData
->StationAddress
.Addr
[9],
707 pConfigData
->StationAddress
.Addr
[10],
708 pConfigData
->StationAddress
.Addr
[11],
709 pConfigData
->StationAddress
.Addr
[12],
710 pConfigData
->StationAddress
.Addr
[13],
711 pConfigData
->StationAddress
.Addr
[14],
712 pConfigData
->StationAddress
.Addr
[15],
713 pConfigData
->StationPort
,
714 pConfigData
->RemoteAddress
.Addr
[0],
715 pConfigData
->RemoteAddress
.Addr
[1],
716 pConfigData
->RemoteAddress
.Addr
[2],
717 pConfigData
->RemoteAddress
.Addr
[3],
718 pConfigData
->RemoteAddress
.Addr
[4],
719 pConfigData
->RemoteAddress
.Addr
[5],
720 pConfigData
->RemoteAddress
.Addr
[6],
721 pConfigData
->RemoteAddress
.Addr
[7],
722 pConfigData
->RemoteAddress
.Addr
[8],
723 pConfigData
->RemoteAddress
.Addr
[9],
724 pConfigData
->RemoteAddress
.Addr
[10],
725 pConfigData
->RemoteAddress
.Addr
[11],
726 pConfigData
->RemoteAddress
.Addr
[12],
727 pConfigData
->RemoteAddress
.Addr
[13],
728 pConfigData
->RemoteAddress
.Addr
[14],
729 pConfigData
->RemoteAddress
.Addr
[15],
730 pConfigData
->RemotePort
));
731 pPort
->bConfigured
= TRUE
;
732 pSocket
->bConfigured
= TRUE
;
735 // Start the first read on the port
737 EslSocketRxStart ( pPort
);
740 // The socket is connected
742 pSocket
->State
= SOCKET_STATE_CONNECTED
;
754 // Determine the socket configuration status
756 Status
= pSocket
->bConfigured
? EFI_SUCCESS
: EFI_NOT_STARTED
;
759 // Return the port connected state.
761 DBG_EXIT_STATUS ( Status
);
767 Buffer data for transmission over a network connection.
769 This routine buffers data for the transmit engine in the normal
770 data queue. When the \ref TransmitEngine has resources, this
771 routine will start the transmission of the next buffer on the
774 This routine is called by ::EslSocketTransmit to buffer
775 data for transmission. The data is copied into a local buffer
776 freeing the application buffer for reuse upon return. When
777 necessary, this routine starts the transmit engine that
778 performs the data transmission on the network connection. The
779 transmit engine transmits the data a packet at a time over the
782 Transmission errors are returned during the next transmission or
783 during the close operation. Only buffering errors are returned
784 during the current transmission attempt.
786 @param [in] pSocket Address of an ::ESL_SOCKET structure
788 @param [in] Flags Message control flags
790 @param [in] BufferLength Length of the the buffer
792 @param [in] pBuffer Address of a buffer to receive the data.
794 @param [in] pDataLength Number of received data bytes in the buffer.
796 @param [in] pAddress Network address of the remote system address
798 @param [in] AddressLength Length of the remote network address structure
800 @retval EFI_SUCCESS - Socket data successfully buffered
805 IN ESL_SOCKET
* pSocket
,
807 IN
size_t BufferLength
,
808 IN CONST UINT8
* pBuffer
,
809 OUT
size_t * pDataLength
,
810 IN
const struct sockaddr
* pAddress
,
811 IN socklen_t AddressLength
814 ESL_PACKET
* pPacket
;
815 ESL_PACKET
* pPreviousPacket
;
817 const struct sockaddr_in6
* pRemoteAddress
;
818 ESL_UDP6_CONTEXT
* pUdp6
;
820 ESL_UDP6_TX_DATA
* pTxData
;
829 Status
= EFI_UNSUPPORTED
;
830 pSocket
->errno
= ENOTCONN
;
834 // Verify that the socket is connected
836 if ( SOCKET_STATE_CONNECTED
== pSocket
->State
) {
840 pPort
= pSocket
->pPortList
;
841 if ( NULL
!= pPort
) {
843 // Determine the queue head
845 pUdp6
= &pPort
->Context
.Udp6
;
846 pTxBytes
= &pSocket
->TxBytes
;
849 // Verify that there is enough room to buffer another
850 // transmit operation
852 if ( pSocket
->MaxTxBuf
> *pTxBytes
) {
854 // Attempt to allocate the packet
856 Status
= EslSocketPacketAllocate ( &pPacket
,
857 sizeof ( pPacket
->Op
.Udp6Tx
)
858 - sizeof ( pPacket
->Op
.Udp6Tx
.Buffer
)
862 if ( !EFI_ERROR ( Status
)) {
864 // Initialize the transmit operation
866 pTxData
= &pPacket
->Op
.Udp6Tx
;
867 pTxData
->TxData
.UdpSessionData
= NULL
;
868 pTxData
->TxData
.DataLength
= (UINT32
) BufferLength
;
869 pTxData
->TxData
.FragmentCount
= 1;
870 pTxData
->TxData
.FragmentTable
[0].FragmentLength
= (UINT32
) BufferLength
;
871 pTxData
->TxData
.FragmentTable
[0].FragmentBuffer
= &pPacket
->Op
.Udp6Tx
.Buffer
[0];
874 // Set the remote system address if necessary
876 pTxData
->TxData
.UdpSessionData
= NULL
;
877 if ( NULL
!= pAddress
) {
878 pRemoteAddress
= (const struct sockaddr_in6
*)pAddress
;
879 CopyMem ( &pTxData
->Session
.SourceAddress
,
880 &pUdp6
->ConfigData
.StationAddress
,
881 sizeof ( pTxData
->Session
.SourceAddress
));
882 pTxData
->Session
.SourcePort
= 0;
883 CopyMem ( &pTxData
->Session
.DestinationAddress
,
884 &pRemoteAddress
->sin6_addr
,
885 sizeof ( pTxData
->Session
.DestinationAddress
));
886 pTxData
->Session
.DestinationPort
= SwapBytes16 ( pRemoteAddress
->sin6_port
);
889 // Use the remote system address when sending this packet
891 pTxData
->TxData
.UdpSessionData
= &pTxData
->Session
;
895 // Copy the data into the buffer
897 CopyMem ( &pPacket
->Op
.Udp6Tx
.Buffer
[0],
902 // Synchronize with the socket layer
904 RAISE_TPL ( TplPrevious
, TPL_SOCKETS
);
907 // Stop transmission after an error
909 if ( !EFI_ERROR ( pSocket
->TxError
)) {
911 // Display the request
914 "Send %d %s bytes from 0x%08x\r\n",
919 // Queue the data for transmission
921 pPacket
->pNext
= NULL
;
922 pPreviousPacket
= pSocket
->pTxPacketListTail
;
923 if ( NULL
== pPreviousPacket
) {
924 pSocket
->pTxPacketListHead
= pPacket
;
927 pPreviousPacket
->pNext
= pPacket
;
929 pSocket
->pTxPacketListTail
= pPacket
;
931 "0x%08x: Packet on transmit list\r\n",
935 // Account for the buffered data
937 *pTxBytes
+= BufferLength
;
938 *pDataLength
= BufferLength
;
941 // Start the transmit engine if it is idle
943 if ( NULL
!= pPort
->pTxFree
) {
944 EslSocketTxStart ( pPort
,
945 &pSocket
->pTxPacketListHead
,
946 &pSocket
->pTxPacketListTail
,
953 // Previous transmit error
956 Status
= pSocket
->TxError
;
957 pSocket
->errno
= EIO
;
962 EslSocketPacketFree ( pPacket
, DEBUG_TX
);
966 // Release the socket layer synchronization
968 RESTORE_TPL ( TplPrevious
);
972 // Packet allocation failed
974 pSocket
->errno
= ENOMEM
;
979 // Not enough buffer space available
981 pSocket
->errno
= EAGAIN
;
982 Status
= EFI_NOT_READY
;
988 // Return the operation status
990 DBG_EXIT_STATUS ( Status
);
996 Process the transmit completion
998 This routine use ::EslSocketTxComplete to perform the transmit
999 completion processing for data packets.
1001 This routine is called by the UDPv4 network layer when a data
1002 transmit request completes.
1004 @param [in] Event The normal transmit completion event
1006 @param [in] pIo Address of an ::ESL_IO_MGMT structure
1012 IN ESL_IO_MGMT
* pIo
1015 UINT32 LengthInBytes
;
1017 ESL_PACKET
* pPacket
;
1018 ESL_SOCKET
* pSocket
;
1024 // Locate the active transmit packet
1026 pPacket
= pIo
->pPacket
;
1028 pSocket
= pPort
->pSocket
;
1031 // Get the transmit length and status
1033 LengthInBytes
= pPacket
->Op
.Udp6Tx
.TxData
.DataLength
;
1034 pSocket
->TxBytes
-= LengthInBytes
;
1035 Status
= pIo
->Token
.Udp6Tx
.Status
;
1038 // Complete the transmit operation
1040 EslSocketTxComplete ( pIo
,
1044 &pSocket
->pTxPacketListHead
,
1045 &pSocket
->pTxPacketListTail
,
1053 Interface between the socket layer and the network specific
1054 code that supports SOCK_DGRAM sockets over UDPv4.
1056 CONST ESL_PROTOCOL_API cEslUdp6Api
= {
1059 OFFSET_OF ( ESL_PORT
, Context
.Udp6
.ConfigData
),
1060 OFFSET_OF ( ESL_LAYER
, pUdp6List
),
1061 sizeof ( struct sockaddr_in6
),
1062 sizeof ( struct sockaddr_in6
),
1064 sizeof (((ESL_PACKET
*)0 )->Op
.Udp6Rx
),
1065 sizeof (((ESL_PACKET
*)0 )->Op
.Udp6Rx
),
1066 OFFSET_OF ( ESL_IO_MGMT
, Token
.Udp6Rx
.Packet
.RxData
),
1070 NULL
, // ConnectPoll
1071 NULL
, // ConnectStart
1072 EslUdp6SocketIsConfigured
,
1073 EslUdp6LocalAddressGet
,
1074 EslUdp6LocalAddressSet
,
1079 EslUdp6PortAllocate
,
1081 NULL
, // PortCloseOp
1084 EslUdp6RemoteAddressGet
,
1085 EslUdp6RemoteAddressSet
,
1090 NULL
// TxOobComplete