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
);
118 // Display the local address
121 "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",
123 pConfig
->StationAddress
.Addr
[0],
124 pConfig
->StationAddress
.Addr
[1],
125 pConfig
->StationAddress
.Addr
[2],
126 pConfig
->StationAddress
.Addr
[3],
127 pConfig
->StationAddress
.Addr
[4],
128 pConfig
->StationAddress
.Addr
[5],
129 pConfig
->StationAddress
.Addr
[6],
130 pConfig
->StationAddress
.Addr
[7],
131 pConfig
->StationAddress
.Addr
[8],
132 pConfig
->StationAddress
.Addr
[9],
133 pConfig
->StationAddress
.Addr
[10],
134 pConfig
->StationAddress
.Addr
[11],
135 pConfig
->StationAddress
.Addr
[12],
136 pConfig
->StationAddress
.Addr
[13],
137 pConfig
->StationAddress
.Addr
[14],
138 pConfig
->StationAddress
.Addr
[15],
139 pConfig
->StationPort
));
143 // Return the operation status
145 DBG_EXIT_STATUS ( Status
);
151 Free a receive packet
153 This routine performs the network specific operations necessary
154 to free a receive packet.
156 This routine is called by ::EslSocketPortCloseTxDone to free a
159 @param [in] pPacket Address of an ::ESL_PACKET structure.
160 @param [in, out] pRxBytes Address of the count of RX bytes
165 IN ESL_PACKET
* pPacket
,
166 IN OUT
size_t * pRxBytes
169 EFI_UDP6_RECEIVE_DATA
* pRxData
;
174 // Account for the receive bytes
176 pRxData
= pPacket
->Op
.Udp6Rx
.pRxData
;
177 *pRxBytes
-= pRxData
->DataLength
;
180 // Disconnect the buffer from the packet
182 pPacket
->Op
.Udp6Rx
.pRxData
= NULL
;
185 // Return the buffer to the UDP6 driver
187 gBS
->SignalEvent ( pRxData
->RecycleSignal
);
193 Initialize the network specific portions of an ::ESL_PORT structure.
195 This routine initializes the network specific portions of an
196 ::ESL_PORT structure for use by the socket.
198 This support routine is called by ::EslSocketPortAllocate
199 to connect the socket with the underlying network adapter
200 running the UDPv4 protocol.
202 @param [in] pPort Address of an ESL_PORT structure
203 @param [in] DebugFlags Flags for debug messages
205 @retval EFI_SUCCESS - Socket successfully created
209 EslUdp6PortAllocate (
214 EFI_UDP6_CONFIG_DATA
* pConfig
;
215 ESL_SOCKET
* pSocket
;
221 // Initialize the port
223 pSocket
= pPort
->pSocket
;
224 pSocket
->TxPacketOffset
= OFFSET_OF ( ESL_PACKET
, Op
.Udp6Tx
.TxData
);
225 pSocket
->TxTokenEventOffset
= OFFSET_OF ( ESL_IO_MGMT
, Token
.Udp6Tx
.Event
);
226 pSocket
->TxTokenOffset
= OFFSET_OF ( EFI_UDP6_COMPLETION_TOKEN
, Packet
.TxData
);
229 // Save the cancel, receive and transmit addresses
231 pPort
->pfnConfigure
= (PFN_NET_CONFIGURE
)pPort
->pProtocol
.UDPv6
->Configure
;
232 pPort
->pfnRxCancel
= (PFN_NET_IO_START
)pPort
->pProtocol
.UDPv6
->Cancel
;
233 pPort
->pfnRxPoll
= (PFN_NET_POLL
)pPort
->pProtocol
.UDPv6
->Poll
;
234 pPort
->pfnRxStart
= (PFN_NET_IO_START
)pPort
->pProtocol
.UDPv6
->Receive
;
235 pPort
->pfnTxStart
= (PFN_NET_IO_START
)pPort
->pProtocol
.UDPv6
->Transmit
;
238 // Do not drop packets
240 pConfig
= &pPort
->Context
.Udp6
.ConfigData
;
241 pConfig
->ReceiveTimeout
= 0;
242 pConfig
->ReceiveTimeout
= pConfig
->ReceiveTimeout
;
245 // Set the configuration flags
247 pConfig
->AllowDuplicatePort
= TRUE
;
248 pConfig
->AcceptAnyPort
= FALSE
;
249 pConfig
->AcceptPromiscuous
= FALSE
;
250 pConfig
->HopLimit
= 255;
251 pConfig
->TrafficClass
= 0;
253 Status
= EFI_SUCCESS
;
256 // Return the operation status
258 DBG_EXIT_STATUS ( Status
);
264 Receive data from a network connection.
266 This routine attempts to return buffered data to the caller. The
267 data is removed from the urgent queue if the message flag MSG_OOB
268 is specified, otherwise data is removed from the normal queue.
269 See the \ref ReceiveEngine section.
271 This routine is called by ::EslSocketReceive to handle the network
272 specific receive operation to support SOCK_DGRAM sockets.
274 @param [in] pPort Address of an ::ESL_PORT structure.
276 @param [in] pPacket Address of an ::ESL_PACKET structure.
278 @param [in] pbConsumePacket Address of a BOOLEAN indicating if the packet is to be consumed
280 @param [in] BufferLength Length of the the buffer
282 @param [in] pBuffer Address of a buffer to receive the data.
284 @param [in] pDataLength Number of received data bytes in the buffer.
286 @param [out] pAddress Network address to receive the remote system address
288 @param [out] pSkipBytes Address to receive the number of bytes skipped
290 @return Returns the address of the next free byte in the buffer.
296 IN ESL_PACKET
* pPacket
,
297 IN BOOLEAN
* pbConsumePacket
,
298 IN
size_t BufferLength
,
300 OUT
size_t * pDataLength
,
301 OUT
struct sockaddr
* pAddress
,
302 OUT
size_t * pSkipBytes
306 struct sockaddr_in6
* pRemoteAddress
;
307 EFI_UDP6_RECEIVE_DATA
* pRxData
;
311 pRxData
= pPacket
->Op
.Udp6Rx
.pRxData
;
313 // Return the remote system address if requested
315 if ( NULL
!= pAddress
) {
317 // Build the remote address
320 "Getting packet remote address: [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",
321 pRxData
->UdpSession
.SourceAddress
.Addr
[0],
322 pRxData
->UdpSession
.SourceAddress
.Addr
[1],
323 pRxData
->UdpSession
.SourceAddress
.Addr
[2],
324 pRxData
->UdpSession
.SourceAddress
.Addr
[3],
325 pRxData
->UdpSession
.SourceAddress
.Addr
[4],
326 pRxData
->UdpSession
.SourceAddress
.Addr
[5],
327 pRxData
->UdpSession
.SourceAddress
.Addr
[6],
328 pRxData
->UdpSession
.SourceAddress
.Addr
[7],
329 pRxData
->UdpSession
.SourceAddress
.Addr
[8],
330 pRxData
->UdpSession
.SourceAddress
.Addr
[9],
331 pRxData
->UdpSession
.SourceAddress
.Addr
[10],
332 pRxData
->UdpSession
.SourceAddress
.Addr
[11],
333 pRxData
->UdpSession
.SourceAddress
.Addr
[12],
334 pRxData
->UdpSession
.SourceAddress
.Addr
[13],
335 pRxData
->UdpSession
.SourceAddress
.Addr
[14],
336 pRxData
->UdpSession
.SourceAddress
.Addr
[15],
337 pRxData
->UdpSession
.SourcePort
));
338 pRemoteAddress
= (struct sockaddr_in6
*)pAddress
;
339 CopyMem ( &pRemoteAddress
->sin6_addr
,
340 &pRxData
->UdpSession
.SourceAddress
.Addr
[0],
341 sizeof ( pRemoteAddress
->sin6_addr
));
342 pRemoteAddress
->sin6_port
= SwapBytes16 ( pRxData
->UdpSession
.SourcePort
);
346 // Copy the received data
348 pBuffer
= EslSocketCopyFragmentedBuffer ( pRxData
->FragmentCount
,
349 (EFI_IP4_FRAGMENT_DATA
*)&pRxData
->FragmentTable
[0],
355 // Determine if the data is being read
357 if ( *pbConsumePacket
) {
359 // Display for the bytes consumed
362 "0x%08x: Port account for 0x%08x bytes\r\n",
367 // Account for any discarded data
369 *pSkipBytes
= pRxData
->DataLength
- DataBytes
;
373 // Return the data length and the buffer address
375 *pDataLength
= DataBytes
;
376 DBG_EXIT_HEX ( pBuffer
);
382 Get the remote socket address
384 This routine returns the address of the remote connection point
385 associated with the SOCK_DGRAM socket.
387 This routine is called by ::EslSocketGetPeerAddress to detemine
388 the UDPv4 address and port number associated with the network adapter.
390 @param [in] pPort Address of an ::ESL_PORT structure.
392 @param [out] pAddress Network address to receive the remote system address
396 EslUdp6RemoteAddressGet (
398 OUT
struct sockaddr
* pAddress
401 struct sockaddr_in6
* pRemoteAddress
;
402 ESL_UDP6_CONTEXT
* pUdp6
;
407 // Return the remote address
409 pUdp6
= &pPort
->Context
.Udp6
;
410 pRemoteAddress
= (struct sockaddr_in6
*)pAddress
;
411 pRemoteAddress
->sin6_family
= AF_INET6
;
412 pRemoteAddress
->sin6_port
= SwapBytes16 ( pUdp6
->ConfigData
.RemotePort
);
413 CopyMem ( &pRemoteAddress
->sin6_addr
,
414 &pUdp6
->ConfigData
.RemoteAddress
.Addr
[0],
415 sizeof ( pRemoteAddress
->sin6_addr
));
422 Set the remote address
424 This routine sets the remote address in the port.
426 This routine is called by ::EslSocketConnect to specify the
427 remote network address.
429 @param [in] pPort Address of an ::ESL_PORT structure.
431 @param [in] pSockAddr Network address of the remote system.
433 @param [in] SockAddrLength Length in bytes of the network address.
435 @retval EFI_SUCCESS The operation was successful
439 EslUdp6RemoteAddressSet (
441 IN CONST
struct sockaddr
* pSockAddr
,
442 IN socklen_t SockAddrLength
445 CONST
struct sockaddr_in6
* pRemoteAddress
;
446 ESL_UDP6_CONTEXT
* pUdp6
;
452 // Set the remote address
454 pUdp6
= &pPort
->Context
.Udp6
;
455 pRemoteAddress
= (struct sockaddr_in6
*)pSockAddr
;
456 CopyMem ( &pUdp6
->ConfigData
.RemoteAddress
,
457 &pRemoteAddress
->sin6_addr
,
458 sizeof ( pUdp6
->ConfigData
.RemoteAddress
));
459 pUdp6
->ConfigData
.RemotePort
= SwapBytes16 ( pRemoteAddress
->sin6_port
);
460 Status
= EFI_SUCCESS
;
463 // Return the operation status
465 DBG_EXIT_STATUS ( Status
);
471 Process the receive completion
473 This routine keeps the UDPv4 driver's buffer and queues it in
474 in FIFO order to the data queue. The UDP6 driver's buffer will
475 be returned by either ::EslUdp6Receive or ::EslSocketPortCloseTxDone.
476 See the \ref ReceiveEngine section.
478 This routine is called by the UDPv4 driver when data is
481 @param [in] Event The receive completion event
483 @param [in] pIo Address of an ::ESL_IO_MGMT structure
492 size_t LengthInBytes
;
493 ESL_PACKET
* pPacket
;
494 EFI_UDP6_RECEIVE_DATA
* pRxData
;
500 // Get the operation status.
502 Status
= pIo
->Token
.Udp6Rx
.Status
;
505 // Get the packet length
507 pRxData
= pIo
->Token
.Udp6Rx
.Packet
.RxData
;
508 LengthInBytes
= pRxData
->DataLength
;
511 // +--------------------+ +-----------------------+
512 // | ESL_IO_MGMT | | Data Buffer |
513 // | | | (Driver owned) |
514 // | +---------------+ +-----------------------+
517 // | | | +-----------------------+
518 // | | RxData --> | EFI_UDP6_RECEIVE_DATA |
519 // +----+---------------+ | (Driver owned) |
520 // +-----------------------+
521 // +--------------------+ ^
524 // | +---------------+ .
525 // | | pRxData --> NULL .......
526 // +----+---------------+
529 // Save the data in the packet
531 pPacket
= pIo
->pPacket
;
532 pPacket
->Op
.Udp6Rx
.pRxData
= pRxData
;
535 // Complete this request
537 EslSocketRxComplete ( pIo
, Status
, LengthInBytes
, FALSE
);
543 Determine if the socket is configured.
545 This routine uses the flag ESL_SOCKET::bConfigured to determine
546 if the network layer's configuration routine has been called.
547 This routine calls the bind and configuration routines if they
548 were not already called. After the port is configured, the
549 \ref ReceiveEngine is started.
551 This routine is called by EslSocketIsConfigured to verify
552 that the socket is configured.
554 @param [in] pSocket Address of an ::ESL_SOCKET structure
556 @retval EFI_SUCCESS - The port is connected
557 @retval EFI_NOT_STARTED - The port is not connected
561 EslUdp6SocketIsConfigured (
562 IN ESL_SOCKET
* pSocket
565 EFI_UDP6_CONFIG_DATA
* pConfigData
;
567 ESL_PORT
* pNextPort
;
568 ESL_UDP6_CONTEXT
* pUdp6
;
569 EFI_UDP6_PROTOCOL
* pUdp6Protocol
;
571 struct sockaddr_in6 LocalAddress
;
578 Status
= EFI_SUCCESS
;
581 // Configure the port if necessary
583 if ( !pSocket
->bConfigured
) {
585 // Fill in the port list if necessary
587 if ( NULL
== pSocket
->pPortList
) {
588 ZeroMem ( &LocalAddress
, sizeof ( LocalAddress
));
589 LocalAddress
.sin6_len
= sizeof ( LocalAddress
);
590 LocalAddress
.sin6_family
= AF_INET6
;
591 Status
= EslSocketBind ( &pSocket
->SocketProtocol
,
592 (struct sockaddr
*)&LocalAddress
,
593 LocalAddress
.sin6_len
,
598 // Walk the port list
600 pPort
= pSocket
->pPortList
;
601 while ( NULL
!= pPort
) {
603 // Attempt to configure the port
605 pNextPort
= pPort
->pLinkSocket
;
606 pUdp6
= &pPort
->Context
.Udp6
;
607 pUdp6Protocol
= pPort
->pProtocol
.UDPv6
;
608 pConfigData
= &pUdp6
->ConfigData
;
610 "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",
612 pConfigData
->StationAddress
.Addr
[0],
613 pConfigData
->StationAddress
.Addr
[1],
614 pConfigData
->StationAddress
.Addr
[2],
615 pConfigData
->StationAddress
.Addr
[3],
616 pConfigData
->StationAddress
.Addr
[4],
617 pConfigData
->StationAddress
.Addr
[5],
618 pConfigData
->StationAddress
.Addr
[6],
619 pConfigData
->StationAddress
.Addr
[7],
620 pConfigData
->StationAddress
.Addr
[8],
621 pConfigData
->StationAddress
.Addr
[9],
622 pConfigData
->StationAddress
.Addr
[10],
623 pConfigData
->StationAddress
.Addr
[11],
624 pConfigData
->StationAddress
.Addr
[12],
625 pConfigData
->StationAddress
.Addr
[13],
626 pConfigData
->StationAddress
.Addr
[14],
627 pConfigData
->StationAddress
.Addr
[15],
628 pConfigData
->StationPort
,
629 pConfigData
->RemoteAddress
.Addr
[0],
630 pConfigData
->RemoteAddress
.Addr
[1],
631 pConfigData
->RemoteAddress
.Addr
[2],
632 pConfigData
->RemoteAddress
.Addr
[3],
633 pConfigData
->RemoteAddress
.Addr
[4],
634 pConfigData
->RemoteAddress
.Addr
[5],
635 pConfigData
->RemoteAddress
.Addr
[6],
636 pConfigData
->RemoteAddress
.Addr
[7],
637 pConfigData
->RemoteAddress
.Addr
[8],
638 pConfigData
->RemoteAddress
.Addr
[9],
639 pConfigData
->RemoteAddress
.Addr
[10],
640 pConfigData
->RemoteAddress
.Addr
[11],
641 pConfigData
->RemoteAddress
.Addr
[12],
642 pConfigData
->RemoteAddress
.Addr
[13],
643 pConfigData
->RemoteAddress
.Addr
[14],
644 pConfigData
->RemoteAddress
.Addr
[15],
645 pConfigData
->RemotePort
));
646 Status
= pUdp6Protocol
->Configure ( pUdp6Protocol
,
648 if ( !EFI_ERROR ( Status
)) {
650 // Update the configuration data
652 Status
= pUdp6Protocol
->GetModeData ( pUdp6Protocol
,
658 if ( EFI_ERROR ( Status
)) {
659 DEBUG (( DEBUG_LISTEN
,
660 "ERROR - Failed to configure the Udp6 port, Status: %r\r\n",
663 case EFI_ACCESS_DENIED
:
664 pSocket
->errno
= EACCES
;
668 case EFI_DEVICE_ERROR
:
669 pSocket
->errno
= EIO
;
672 case EFI_INVALID_PARAMETER
:
673 pSocket
->errno
= EADDRNOTAVAIL
;
677 pSocket
->errno
= EAFNOSUPPORT
;
680 case EFI_OUT_OF_RESOURCES
:
681 pSocket
->errno
= ENOBUFS
;
684 case EFI_UNSUPPORTED
:
685 pSocket
->errno
= EOPNOTSUPP
;
691 "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",
693 pConfigData
->StationAddress
.Addr
[0],
694 pConfigData
->StationAddress
.Addr
[1],
695 pConfigData
->StationAddress
.Addr
[2],
696 pConfigData
->StationAddress
.Addr
[3],
697 pConfigData
->StationAddress
.Addr
[4],
698 pConfigData
->StationAddress
.Addr
[5],
699 pConfigData
->StationAddress
.Addr
[6],
700 pConfigData
->StationAddress
.Addr
[7],
701 pConfigData
->StationAddress
.Addr
[8],
702 pConfigData
->StationAddress
.Addr
[9],
703 pConfigData
->StationAddress
.Addr
[10],
704 pConfigData
->StationAddress
.Addr
[11],
705 pConfigData
->StationAddress
.Addr
[12],
706 pConfigData
->StationAddress
.Addr
[13],
707 pConfigData
->StationAddress
.Addr
[14],
708 pConfigData
->StationAddress
.Addr
[15],
709 pConfigData
->StationPort
,
710 pConfigData
->RemoteAddress
.Addr
[0],
711 pConfigData
->RemoteAddress
.Addr
[1],
712 pConfigData
->RemoteAddress
.Addr
[2],
713 pConfigData
->RemoteAddress
.Addr
[3],
714 pConfigData
->RemoteAddress
.Addr
[4],
715 pConfigData
->RemoteAddress
.Addr
[5],
716 pConfigData
->RemoteAddress
.Addr
[6],
717 pConfigData
->RemoteAddress
.Addr
[7],
718 pConfigData
->RemoteAddress
.Addr
[8],
719 pConfigData
->RemoteAddress
.Addr
[9],
720 pConfigData
->RemoteAddress
.Addr
[10],
721 pConfigData
->RemoteAddress
.Addr
[11],
722 pConfigData
->RemoteAddress
.Addr
[12],
723 pConfigData
->RemoteAddress
.Addr
[13],
724 pConfigData
->RemoteAddress
.Addr
[14],
725 pConfigData
->RemoteAddress
.Addr
[15],
726 pConfigData
->RemotePort
));
727 pPort
->bConfigured
= TRUE
;
730 // Start the first read on the port
732 EslSocketRxStart ( pPort
);
735 // The socket is connected
737 pSocket
->State
= SOCKET_STATE_CONNECTED
;
747 // Determine the configuration status
749 if ( NULL
!= pSocket
->pPortList
) {
750 pSocket
->bConfigured
= TRUE
;
755 // Determine the socket configuration status
757 if ( !EFI_ERROR ( Status
)) {
758 Status
= pSocket
->bConfigured
? EFI_SUCCESS
: EFI_NOT_STARTED
;
762 // Return the port connected state.
764 DBG_EXIT_STATUS ( Status
);
770 Buffer data for transmission over a network connection.
772 This routine buffers data for the transmit engine in the normal
773 data queue. When the \ref TransmitEngine has resources, this
774 routine will start the transmission of the next buffer on the
777 This routine is called by ::EslSocketTransmit to buffer
778 data for transmission. The data is copied into a local buffer
779 freeing the application buffer for reuse upon return. When
780 necessary, this routine starts the transmit engine that
781 performs the data transmission on the network connection. The
782 transmit engine transmits the data a packet at a time over the
785 Transmission errors are returned during the next transmission or
786 during the close operation. Only buffering errors are returned
787 during the current transmission attempt.
789 @param [in] pSocket Address of an ::ESL_SOCKET structure
791 @param [in] Flags Message control flags
793 @param [in] BufferLength Length of the the buffer
795 @param [in] pBuffer Address of a buffer to receive the data.
797 @param [in] pDataLength Number of received data bytes in the buffer.
799 @param [in] pAddress Network address of the remote system address
801 @param [in] AddressLength Length of the remote network address structure
803 @retval EFI_SUCCESS - Socket data successfully buffered
808 IN ESL_SOCKET
* pSocket
,
810 IN
size_t BufferLength
,
811 IN CONST UINT8
* pBuffer
,
812 OUT
size_t * pDataLength
,
813 IN
const struct sockaddr
* pAddress
,
814 IN socklen_t AddressLength
817 ESL_PACKET
* pPacket
;
818 ESL_PACKET
* pPreviousPacket
;
820 const struct sockaddr_in6
* pRemoteAddress
;
821 ESL_UDP6_CONTEXT
* pUdp6
;
823 ESL_UDP6_TX_DATA
* pTxData
;
832 Status
= EFI_UNSUPPORTED
;
833 pSocket
->errno
= ENOTCONN
;
837 // Verify that the socket is connected
839 if ( SOCKET_STATE_CONNECTED
== pSocket
->State
) {
843 pPort
= pSocket
->pPortList
;
844 if ( NULL
!= pPort
) {
846 // Determine the queue head
848 pUdp6
= &pPort
->Context
.Udp6
;
849 pTxBytes
= &pSocket
->TxBytes
;
852 // Verify that there is enough room to buffer another
853 // transmit operation
855 if ( pSocket
->MaxTxBuf
> *pTxBytes
) {
857 // Attempt to allocate the packet
859 Status
= EslSocketPacketAllocate ( &pPacket
,
860 sizeof ( pPacket
->Op
.Udp6Tx
)
861 - sizeof ( pPacket
->Op
.Udp6Tx
.Buffer
)
865 if ( !EFI_ERROR ( Status
)) {
867 // Initialize the transmit operation
869 pTxData
= &pPacket
->Op
.Udp6Tx
;
870 pTxData
->TxData
.UdpSessionData
= NULL
;
871 pTxData
->TxData
.DataLength
= (UINT32
) BufferLength
;
872 pTxData
->TxData
.FragmentCount
= 1;
873 pTxData
->TxData
.FragmentTable
[0].FragmentLength
= (UINT32
) BufferLength
;
874 pTxData
->TxData
.FragmentTable
[0].FragmentBuffer
= &pPacket
->Op
.Udp6Tx
.Buffer
[0];
877 // Set the remote system address if necessary
879 pTxData
->TxData
.UdpSessionData
= NULL
;
880 if ( NULL
!= pAddress
) {
881 pRemoteAddress
= (const struct sockaddr_in6
*)pAddress
;
882 CopyMem ( &pTxData
->Session
.SourceAddress
,
883 &pUdp6
->ConfigData
.StationAddress
,
884 sizeof ( pTxData
->Session
.SourceAddress
));
885 pTxData
->Session
.SourcePort
= 0;
886 CopyMem ( &pTxData
->Session
.DestinationAddress
,
887 &pRemoteAddress
->sin6_addr
,
888 sizeof ( pTxData
->Session
.DestinationAddress
));
889 pTxData
->Session
.DestinationPort
= SwapBytes16 ( pRemoteAddress
->sin6_port
);
892 // Use the remote system address when sending this packet
894 pTxData
->TxData
.UdpSessionData
= &pTxData
->Session
;
898 // Copy the data into the buffer
900 CopyMem ( &pPacket
->Op
.Udp6Tx
.Buffer
[0],
905 // Synchronize with the socket layer
907 RAISE_TPL ( TplPrevious
, TPL_SOCKETS
);
910 // Stop transmission after an error
912 if ( !EFI_ERROR ( pSocket
->TxError
)) {
914 // Display the request
917 "Send %d %s bytes from 0x%08x\r\n",
922 // Queue the data for transmission
924 pPacket
->pNext
= NULL
;
925 pPreviousPacket
= pSocket
->pTxPacketListTail
;
926 if ( NULL
== pPreviousPacket
) {
927 pSocket
->pTxPacketListHead
= pPacket
;
930 pPreviousPacket
->pNext
= pPacket
;
932 pSocket
->pTxPacketListTail
= pPacket
;
934 "0x%08x: Packet on transmit list\r\n",
938 // Account for the buffered data
940 *pTxBytes
+= BufferLength
;
941 *pDataLength
= BufferLength
;
944 // Start the transmit engine if it is idle
946 if ( NULL
!= pPort
->pTxFree
) {
947 EslSocketTxStart ( pPort
,
948 &pSocket
->pTxPacketListHead
,
949 &pSocket
->pTxPacketListTail
,
956 // Previous transmit error
959 Status
= pSocket
->TxError
;
960 pSocket
->errno
= EIO
;
965 EslSocketPacketFree ( pPacket
, DEBUG_TX
);
969 // Release the socket layer synchronization
971 RESTORE_TPL ( TplPrevious
);
975 // Packet allocation failed
977 pSocket
->errno
= ENOMEM
;
982 // Not enough buffer space available
984 pSocket
->errno
= EAGAIN
;
985 Status
= EFI_NOT_READY
;
991 // Return the operation status
993 DBG_EXIT_STATUS ( Status
);
999 Process the transmit completion
1001 This routine use ::EslSocketTxComplete to perform the transmit
1002 completion processing for data packets.
1004 This routine is called by the UDPv4 network layer when a data
1005 transmit request completes.
1007 @param [in] Event The normal transmit completion event
1009 @param [in] pIo Address of an ::ESL_IO_MGMT structure
1015 IN ESL_IO_MGMT
* pIo
1018 UINT32 LengthInBytes
;
1020 ESL_PACKET
* pPacket
;
1021 ESL_SOCKET
* pSocket
;
1027 // Locate the active transmit packet
1029 pPacket
= pIo
->pPacket
;
1031 pSocket
= pPort
->pSocket
;
1034 // Get the transmit length and status
1036 LengthInBytes
= pPacket
->Op
.Udp6Tx
.TxData
.DataLength
;
1037 pSocket
->TxBytes
-= LengthInBytes
;
1038 Status
= pIo
->Token
.Udp6Tx
.Status
;
1041 // Complete the transmit operation
1043 EslSocketTxComplete ( pIo
,
1047 &pSocket
->pTxPacketListHead
,
1048 &pSocket
->pTxPacketListTail
,
1056 Interface between the socket layer and the network specific
1057 code that supports SOCK_DGRAM sockets over UDPv4.
1059 CONST ESL_PROTOCOL_API cEslUdp6Api
= {
1062 OFFSET_OF ( ESL_PORT
, Context
.Udp6
.ConfigData
),
1063 OFFSET_OF ( ESL_LAYER
, pUdp6List
),
1064 sizeof ( struct sockaddr_in6
),
1065 sizeof ( struct sockaddr_in6
),
1067 sizeof (((ESL_PACKET
*)0 )->Op
.Udp6Rx
),
1068 sizeof (((ESL_PACKET
*)0 )->Op
.Udp6Rx
),
1069 OFFSET_OF ( ESL_IO_MGMT
, Token
.Udp6Rx
.Packet
.RxData
),
1073 NULL
, // ConnectPoll
1074 NULL
, // ConnectStart
1075 EslUdp6SocketIsConfigured
,
1076 EslUdp6LocalAddressGet
,
1077 EslUdp6LocalAddressSet
,
1082 EslUdp6PortAllocate
,
1084 NULL
, // PortCloseOp
1087 EslUdp6RemoteAddressGet
,
1088 EslUdp6RemoteAddressSet
,
1093 NULL
// TxOobComplete