2007-07-23 11:17:39 +02:00
|
|
|
/** @file
|
2008-12-23 08:35:46 +01:00
|
|
|
Help functions to access UDP service, it is used by both the DHCP and MTFTP.
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2012-10-17 10:23:41 +02:00
|
|
|
Copyright (c) 2005 - 2012, Intel Corporation. All rights reserved.<BR>
|
2010-04-24 11:49:11 +02:00
|
|
|
This program and the accompanying materials
|
2007-07-23 11:17:39 +02:00
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
2008-12-26 10:09:02 +01:00
|
|
|
which accompanies this distribution. The full text of the license may be found at<BR>
|
2007-07-23 11:17:39 +02:00
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
**/
|
|
|
|
|
2008-12-23 10:18:06 +01:00
|
|
|
#include <Uefi.h>
|
2007-07-23 11:17:39 +02:00
|
|
|
|
|
|
|
#include <Protocol/Udp4.h>
|
2009-10-30 06:11:38 +01:00
|
|
|
#include <Protocol/Udp6.h>
|
2007-07-23 11:17:39 +02:00
|
|
|
|
|
|
|
#include <Library/UdpIoLib.h>
|
|
|
|
#include <Library/BaseLib.h>
|
|
|
|
#include <Library/DebugLib.h>
|
|
|
|
#include <Library/UefiBootServicesTableLib.h>
|
|
|
|
#include <Library/MemoryAllocationLib.h>
|
2008-02-11 23:21:12 +01:00
|
|
|
#include <Library/BaseMemoryLib.h>
|
2009-07-12 00:51:51 +02:00
|
|
|
#include <Library/DpcLib.h>
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2008-12-23 08:35:46 +01:00
|
|
|
|
|
|
|
/**
|
2008-12-26 10:09:02 +01:00
|
|
|
Free a UDP_TX_TOKEN. The TX event is closed.
|
2008-12-23 08:35:46 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
@param[in] TxToken The UDP_TX_TOKEN to release.
|
2008-12-23 08:35:46 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
UdpIoFreeTxToken (
|
2009-10-30 06:11:38 +01:00
|
|
|
IN UDP_TX_TOKEN *TxToken
|
2008-12-23 08:35:46 +01:00
|
|
|
)
|
|
|
|
{
|
2009-10-30 06:11:38 +01:00
|
|
|
|
|
|
|
if (TxToken->UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) {
|
|
|
|
gBS->CloseEvent (TxToken->Token.Udp4.Event);
|
|
|
|
} else if (TxToken->UdpIo->UdpVersion == UDP_IO_UDP6_VERSION) {
|
|
|
|
gBS->CloseEvent (TxToken->Token.Udp6.Event);
|
|
|
|
} else {
|
|
|
|
ASSERT (FALSE);
|
|
|
|
}
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
FreePool (TxToken);
|
2008-12-23 08:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-12-26 10:09:02 +01:00
|
|
|
Free a UDP_RX_TOKEN. The RX event is closed.
|
2008-12-23 08:35:46 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
@param[in] RxToken The UDP_RX_TOKEN to release.
|
2008-12-23 08:35:46 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
UdpIoFreeRxToken (
|
2009-10-30 06:11:38 +01:00
|
|
|
IN UDP_RX_TOKEN *RxToken
|
2008-12-23 08:35:46 +01:00
|
|
|
)
|
|
|
|
{
|
2009-10-30 06:11:38 +01:00
|
|
|
if (RxToken->UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) {
|
|
|
|
gBS->CloseEvent (RxToken->Token.Udp4.Event);
|
|
|
|
} else if (RxToken->UdpIo->UdpVersion == UDP_IO_UDP6_VERSION) {
|
|
|
|
gBS->CloseEvent (RxToken->Token.Udp6.Event);
|
|
|
|
} else {
|
|
|
|
ASSERT (FALSE);
|
2010-01-08 03:35:56 +01:00
|
|
|
}
|
2009-10-30 06:11:38 +01:00
|
|
|
|
|
|
|
FreePool (RxToken);
|
2008-12-23 08:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
The callback function when the packet is sent by UDP.
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2008-12-23 08:35:46 +01:00
|
|
|
It will remove the packet from the local list then call
|
2008-12-26 10:09:02 +01:00
|
|
|
the packet owner's callback function set by UdpIoSendDatagram.
|
2008-12-23 08:35:46 +01:00
|
|
|
|
2009-01-13 09:48:19 +01:00
|
|
|
@param[in] Context The UDP TX Token.
|
2008-12-23 08:35:46 +01:00
|
|
|
|
|
|
|
**/
|
2007-11-20 06:42:23 +01:00
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
UdpIoOnDgramSentDpc (
|
|
|
|
IN VOID *Context
|
2008-12-23 08:35:46 +01:00
|
|
|
)
|
|
|
|
{
|
2009-10-30 06:11:38 +01:00
|
|
|
UDP_TX_TOKEN *TxToken;
|
2008-12-23 08:35:46 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
TxToken = (UDP_TX_TOKEN *) Context;
|
|
|
|
ASSERT (TxToken->Signature == UDP_IO_TX_SIGNATURE);
|
|
|
|
ASSERT ((TxToken->UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) ||
|
|
|
|
(TxToken->UdpIo->UdpVersion == UDP_IO_UDP6_VERSION));
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
RemoveEntryList (&TxToken->Link);
|
2008-12-23 08:35:46 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if (TxToken->UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) {
|
|
|
|
TxToken->CallBack (TxToken->Packet, NULL, TxToken->Token.Udp4.Status, TxToken->Context);
|
|
|
|
} else {
|
|
|
|
TxToken->CallBack (TxToken->Packet, NULL, TxToken->Token.Udp6.Status, TxToken->Context);
|
|
|
|
}
|
2008-12-23 08:35:46 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
UdpIoFreeTxToken (TxToken);
|
2008-12-23 08:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Request UdpIoOnDgramSentDpc as a DPC at TPL_CALLBACK.
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-01-13 09:48:19 +01:00
|
|
|
@param[in] Event The event signaled.
|
|
|
|
@param[in] Context The UDP TX Token.
|
2007-11-20 06:42:23 +01:00
|
|
|
|
2008-12-23 08:35:46 +01:00
|
|
|
**/
|
2007-07-23 11:17:39 +02:00
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
UdpIoOnDgramSent (
|
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
2008-12-23 08:35:46 +01:00
|
|
|
)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Request UdpIoOnDgramSentDpc as a DPC at TPL_CALLBACK
|
|
|
|
//
|
2009-07-12 00:51:51 +02:00
|
|
|
QueueDpc (TPL_CALLBACK, UdpIoOnDgramSentDpc, Context);
|
2008-12-23 08:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Recycle the received UDP data.
|
|
|
|
|
2009-01-13 09:48:19 +01:00
|
|
|
@param[in] Context The UDP_RX_TOKEN.
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2008-12-23 08:35:46 +01:00
|
|
|
**/
|
|
|
|
VOID
|
2010-04-17 01:24:45 +02:00
|
|
|
EFIAPI
|
2008-12-23 08:35:46 +01:00
|
|
|
UdpIoRecycleDgram (
|
|
|
|
IN VOID *Context
|
|
|
|
)
|
2010-01-08 03:35:56 +01:00
|
|
|
{
|
2009-10-30 06:11:38 +01:00
|
|
|
UDP_RX_TOKEN *RxToken;
|
|
|
|
|
|
|
|
RxToken = (UDP_RX_TOKEN *) Context;
|
|
|
|
|
|
|
|
if (RxToken->UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) {
|
|
|
|
gBS->SignalEvent (RxToken->Token.Udp4.Packet.RxData->RecycleSignal);
|
|
|
|
} else if (RxToken->UdpIo->UdpVersion == UDP_IO_UDP6_VERSION) {
|
|
|
|
gBS->SignalEvent (RxToken->Token.Udp6.Packet.RxData->RecycleSignal);
|
|
|
|
} else {
|
|
|
|
ASSERT (FALSE);
|
|
|
|
}
|
2008-12-23 08:35:46 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
UdpIoFreeRxToken (RxToken);
|
2008-12-23 08:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-12-26 10:09:02 +01:00
|
|
|
The event handle for UDP receive request.
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2008-12-26 10:09:02 +01:00
|
|
|
It will build a NET_BUF from the recieved UDP data, then deliver it
|
2008-12-23 08:35:46 +01:00
|
|
|
to the receiver.
|
|
|
|
|
2009-01-13 09:48:19 +01:00
|
|
|
@param[in] Context The UDP RX token.
|
2008-12-23 08:35:46 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
UdpIoOnDgramRcvdDpc (
|
|
|
|
IN VOID *Context
|
|
|
|
)
|
|
|
|
{
|
2009-10-30 06:11:38 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
VOID *Token;
|
|
|
|
VOID *RxData;
|
|
|
|
VOID *Session;
|
|
|
|
UDP_RX_TOKEN *RxToken;
|
|
|
|
UDP_END_POINT EndPoint;
|
2008-12-23 08:35:46 +01:00
|
|
|
NET_BUF *Netbuf;
|
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
RxToken = (UDP_RX_TOKEN *) Context;
|
2008-12-23 08:35:46 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
ZeroMem (&EndPoint, sizeof(UDP_END_POINT));
|
|
|
|
|
2010-01-08 03:35:56 +01:00
|
|
|
ASSERT ((RxToken->Signature == UDP_IO_RX_SIGNATURE) &&
|
2009-10-30 06:11:38 +01:00
|
|
|
(RxToken == RxToken->UdpIo->RecvRequest));
|
|
|
|
|
|
|
|
ASSERT ((RxToken->UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) ||
|
|
|
|
(RxToken->UdpIo->UdpVersion == UDP_IO_UDP6_VERSION));
|
2008-12-23 08:35:46 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Clear the receive request first in case that the caller
|
|
|
|
// wants to restart the receive in the callback.
|
|
|
|
//
|
2009-10-30 06:11:38 +01:00
|
|
|
RxToken->UdpIo->RecvRequest = NULL;
|
|
|
|
|
|
|
|
if (RxToken->UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) {
|
|
|
|
Token = &RxToken->Token.Udp4;
|
|
|
|
RxData = ((EFI_UDP4_COMPLETION_TOKEN *) Token)->Packet.RxData;
|
|
|
|
Status = ((EFI_UDP4_COMPLETION_TOKEN *) Token)->Status;
|
|
|
|
} else {
|
|
|
|
Token = &RxToken->Token.Udp6;
|
|
|
|
RxData = ((EFI_UDP6_COMPLETION_TOKEN *) Token)->Packet.RxData;
|
|
|
|
Status = ((EFI_UDP6_COMPLETION_TOKEN *) Token)->Status;
|
|
|
|
}
|
2008-12-23 08:35:46 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if (EFI_ERROR (Status) || RxData == NULL) {
|
|
|
|
if (Status != EFI_ABORTED) {
|
2008-12-23 08:35:46 +01:00
|
|
|
//
|
|
|
|
// Invoke the CallBack only if the reception is not actively aborted.
|
|
|
|
//
|
2009-10-30 06:11:38 +01:00
|
|
|
RxToken->CallBack (NULL, NULL, Status, RxToken->Context);
|
2008-12-23 08:35:46 +01:00
|
|
|
}
|
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
UdpIoFreeRxToken (RxToken);
|
2008-12-23 08:35:46 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Build a NET_BUF from the UDP receive data, then deliver it up.
|
|
|
|
//
|
2009-10-30 06:11:38 +01:00
|
|
|
if (RxToken->UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) {
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
Netbuf = NetbufFromExt (
|
|
|
|
(NET_FRAGMENT *)((EFI_UDP4_RECEIVE_DATA *) RxData)->FragmentTable,
|
|
|
|
((EFI_UDP4_RECEIVE_DATA *) RxData)->FragmentCount,
|
|
|
|
0,
|
|
|
|
(UINT32) RxToken->HeadLen,
|
|
|
|
UdpIoRecycleDgram,
|
|
|
|
RxToken
|
|
|
|
);
|
|
|
|
|
|
|
|
if (Netbuf == NULL) {
|
|
|
|
gBS->SignalEvent (((EFI_UDP4_RECEIVE_DATA *) RxData)->RecycleSignal);
|
|
|
|
RxToken->CallBack (NULL, NULL, EFI_OUT_OF_RESOURCES, RxToken->Context);
|
|
|
|
|
|
|
|
UdpIoFreeRxToken (RxToken);
|
|
|
|
return;
|
|
|
|
}
|
2008-12-23 08:35:46 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
Session = &((EFI_UDP4_RECEIVE_DATA *) RxData)->UdpSession;
|
|
|
|
EndPoint.LocalPort = ((EFI_UDP4_SESSION_DATA *) Session)->DestinationPort;
|
|
|
|
EndPoint.RemotePort = ((EFI_UDP4_SESSION_DATA *) Session)->SourcePort;
|
|
|
|
|
|
|
|
CopyMem (
|
|
|
|
&EndPoint.LocalAddr,
|
|
|
|
&((EFI_UDP4_SESSION_DATA *) Session)->DestinationAddress,
|
|
|
|
sizeof (EFI_IPv4_ADDRESS)
|
|
|
|
);
|
|
|
|
|
|
|
|
CopyMem (
|
|
|
|
&EndPoint.RemoteAddr,
|
|
|
|
&((EFI_UDP4_SESSION_DATA *) Session)->SourceAddress,
|
|
|
|
sizeof (EFI_IPv4_ADDRESS)
|
|
|
|
);
|
|
|
|
|
|
|
|
EndPoint.LocalAddr.Addr[0] = NTOHL (EndPoint.LocalAddr.Addr[0]);
|
|
|
|
EndPoint.RemoteAddr.Addr[0] = NTOHL (EndPoint.RemoteAddr.Addr[0]);
|
|
|
|
} else {
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
Netbuf = NetbufFromExt (
|
|
|
|
(NET_FRAGMENT *)((EFI_UDP6_RECEIVE_DATA *) RxData)->FragmentTable,
|
|
|
|
((EFI_UDP6_RECEIVE_DATA *) RxData)->FragmentCount,
|
|
|
|
0,
|
|
|
|
(UINT32) RxToken->HeadLen,
|
|
|
|
UdpIoRecycleDgram,
|
|
|
|
RxToken
|
|
|
|
);
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if (Netbuf == NULL) {
|
|
|
|
gBS->SignalEvent (((EFI_UDP6_RECEIVE_DATA *) RxData)->RecycleSignal);
|
|
|
|
RxToken->CallBack (NULL, NULL, EFI_OUT_OF_RESOURCES, RxToken->Context);
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
UdpIoFreeRxToken (RxToken);
|
|
|
|
return;
|
|
|
|
}
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
Session = &((EFI_UDP6_RECEIVE_DATA *) RxData)->UdpSession;
|
|
|
|
EndPoint.LocalPort = ((EFI_UDP6_SESSION_DATA *) Session)->DestinationPort;
|
|
|
|
EndPoint.RemotePort = ((EFI_UDP6_SESSION_DATA *) Session)->SourcePort;
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
CopyMem (
|
|
|
|
&EndPoint.LocalAddr,
|
|
|
|
&((EFI_UDP6_SESSION_DATA *) Session)->DestinationAddress,
|
|
|
|
sizeof (EFI_IPv6_ADDRESS)
|
|
|
|
);
|
|
|
|
|
|
|
|
CopyMem (
|
|
|
|
&EndPoint.RemoteAddr,
|
|
|
|
&((EFI_UDP6_SESSION_DATA *) Session)->SourceAddress,
|
|
|
|
sizeof (EFI_IPv6_ADDRESS)
|
|
|
|
);
|
|
|
|
|
|
|
|
Ip6Swap128 (&EndPoint.LocalAddr.v6);
|
|
|
|
Ip6Swap128 (&EndPoint.RemoteAddr.v6);
|
|
|
|
}
|
2008-12-23 08:35:46 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
RxToken->CallBack (Netbuf, &EndPoint, EFI_SUCCESS, RxToken->Context);
|
2008-12-23 08:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-12-29 04:49:50 +01:00
|
|
|
Request UdpIoOnDgramRcvdDpc() as a DPC at TPL_CALLBACK.
|
2008-12-23 08:35:46 +01:00
|
|
|
|
2009-01-13 09:48:19 +01:00
|
|
|
@param[in] Event The UDP receive request event.
|
|
|
|
@param[in] Context The UDP RX token.
|
2008-12-23 08:35:46 +01:00
|
|
|
|
|
|
|
**/
|
2007-07-23 11:17:39 +02:00
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
UdpIoOnDgramRcvd (
|
|
|
|
IN EFI_EVENT Event,
|
|
|
|
IN VOID *Context
|
2008-12-23 08:35:46 +01:00
|
|
|
)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Request UdpIoOnDgramRcvdDpc as a DPC at TPL_CALLBACK
|
|
|
|
//
|
2009-07-12 00:51:51 +02:00
|
|
|
QueueDpc (TPL_CALLBACK, UdpIoOnDgramRcvdDpc, Context);
|
2008-12-23 08:35:46 +01:00
|
|
|
}
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2008-12-23 08:35:46 +01:00
|
|
|
/**
|
|
|
|
Create a UDP_RX_TOKEN to wrap the request.
|
|
|
|
|
2009-01-13 09:48:19 +01:00
|
|
|
@param[in] UdpIo The UdpIo to receive packets from.
|
|
|
|
@param[in] CallBack The function to call when receive finished.
|
|
|
|
@param[in] Context The opaque parameter to the CallBack.
|
|
|
|
@param[in] HeadLen The head length to reserver for the packet.
|
2008-12-23 08:35:46 +01:00
|
|
|
|
|
|
|
@return The Wrapped request or NULL if failed to allocate resources or some errors happened.
|
|
|
|
|
|
|
|
**/
|
|
|
|
UDP_RX_TOKEN *
|
|
|
|
UdpIoCreateRxToken (
|
2009-10-30 06:11:38 +01:00
|
|
|
IN UDP_IO *UdpIo,
|
2008-12-23 08:35:46 +01:00
|
|
|
IN UDP_IO_CALLBACK CallBack,
|
|
|
|
IN VOID *Context,
|
|
|
|
IN UINT32 HeadLen
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UDP_RX_TOKEN *Token;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
ASSERT ((UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) ||
|
|
|
|
(UdpIo->UdpVersion == UDP_IO_UDP6_VERSION));
|
|
|
|
|
2008-12-23 08:35:46 +01:00
|
|
|
Token = AllocatePool (sizeof (UDP_RX_TOKEN));
|
|
|
|
|
|
|
|
if (Token == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Token->Signature = UDP_IO_RX_SIGNATURE;
|
|
|
|
Token->UdpIo = UdpIo;
|
|
|
|
Token->CallBack = CallBack;
|
|
|
|
Token->Context = Context;
|
|
|
|
Token->HeadLen = HeadLen;
|
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if (UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) {
|
|
|
|
|
|
|
|
Token->Token.Udp4.Status = EFI_NOT_READY;
|
|
|
|
Token->Token.Udp4.Packet.RxData = NULL;
|
|
|
|
|
|
|
|
Status = gBS->CreateEvent (
|
|
|
|
EVT_NOTIFY_SIGNAL,
|
|
|
|
TPL_NOTIFY,
|
|
|
|
UdpIoOnDgramRcvd,
|
|
|
|
Token,
|
|
|
|
&Token->Token.Udp4.Event
|
|
|
|
);
|
|
|
|
} else {
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
Token->Token.Udp6.Status = EFI_NOT_READY;
|
|
|
|
Token->Token.Udp6.Packet.RxData = NULL;
|
|
|
|
|
|
|
|
Status = gBS->CreateEvent (
|
|
|
|
EVT_NOTIFY_SIGNAL,
|
|
|
|
TPL_NOTIFY,
|
|
|
|
UdpIoOnDgramRcvd,
|
|
|
|
Token,
|
|
|
|
&Token->Token.Udp6.Event
|
|
|
|
);
|
2010-01-08 03:35:56 +01:00
|
|
|
}
|
2008-12-23 08:35:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
2009-10-30 06:11:38 +01:00
|
|
|
FreePool (Token);
|
2008-12-23 08:35:46 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Token;
|
|
|
|
}
|
2007-07-23 11:17:39 +02:00
|
|
|
|
|
|
|
/**
|
2009-10-30 06:11:38 +01:00
|
|
|
Wrap a transmit request into a new created UDP_TX_TOKEN.
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
@param[in] UdpIo The UdpIo to send packet to.
|
2009-01-13 09:48:19 +01:00
|
|
|
@param[in] Packet The user's packet.
|
|
|
|
@param[in] EndPoint The local and remote access point.
|
|
|
|
@param[in] Gateway The overrided next hop.
|
|
|
|
@param[in] CallBack The function to call when transmission completed.
|
|
|
|
@param[in] Context The opaque parameter to the call back.
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2010-01-08 03:35:56 +01:00
|
|
|
@return The wrapped transmission request or NULL if failed to allocate resources
|
2008-12-23 08:35:46 +01:00
|
|
|
or for some errors.
|
2007-07-23 11:17:39 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
UDP_TX_TOKEN *
|
2009-10-30 06:11:38 +01:00
|
|
|
UdpIoCreateTxToken (
|
|
|
|
IN UDP_IO *UdpIo,
|
2007-07-23 11:17:39 +02:00
|
|
|
IN NET_BUF *Packet,
|
2009-10-30 06:11:38 +01:00
|
|
|
IN UDP_END_POINT *EndPoint OPTIONAL,
|
|
|
|
IN EFI_IP_ADDRESS *Gateway OPTIONAL,
|
2007-07-23 11:17:39 +02:00
|
|
|
IN UDP_IO_CALLBACK CallBack,
|
|
|
|
IN VOID *Context
|
|
|
|
)
|
|
|
|
{
|
2009-10-30 06:11:38 +01:00
|
|
|
UDP_TX_TOKEN *TxToken;
|
|
|
|
VOID *Token;
|
|
|
|
VOID *Data;
|
2007-07-23 11:17:39 +02:00
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT32 Count;
|
2009-10-30 06:11:38 +01:00
|
|
|
UINTN Size;
|
2010-01-08 03:35:56 +01:00
|
|
|
IP4_ADDR Ip;
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
ASSERT (Packet != NULL);
|
|
|
|
ASSERT ((UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) ||
|
|
|
|
(UdpIo->UdpVersion == UDP_IO_UDP6_VERSION));
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if (UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) {
|
|
|
|
Size = sizeof (UDP_TX_TOKEN) + sizeof (EFI_UDP4_FRAGMENT_DATA) * (Packet->BlockOpNum - 1);
|
|
|
|
} else {
|
|
|
|
Size = sizeof (UDP_TX_TOKEN) + sizeof (EFI_UDP6_FRAGMENT_DATA) * (Packet->BlockOpNum - 1);
|
2007-07-23 11:17:39 +02:00
|
|
|
}
|
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
TxToken = AllocatePool (Size);
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if (TxToken == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
TxToken->Signature = UDP_IO_TX_SIGNATURE;
|
|
|
|
InitializeListHead (&TxToken->Link);
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
TxToken->UdpIo = UdpIo;
|
|
|
|
TxToken->CallBack = CallBack;
|
|
|
|
TxToken->Packet = Packet;
|
|
|
|
TxToken->Context = Context;
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
Token = &(TxToken->Token);
|
|
|
|
Count = Packet->BlockOpNum;
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if (UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) {
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
((EFI_UDP4_COMPLETION_TOKEN *) Token)->Status = EFI_NOT_READY;
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
Status = gBS->CreateEvent (
|
|
|
|
EVT_NOTIFY_SIGNAL,
|
|
|
|
TPL_NOTIFY,
|
|
|
|
UdpIoOnDgramSent,
|
|
|
|
TxToken,
|
|
|
|
&((EFI_UDP4_COMPLETION_TOKEN *) Token)->Event
|
|
|
|
);
|
2007-08-30 08:58:37 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
FreePool (TxToken);
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-08-30 08:58:37 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
Data = &(TxToken->Data.Udp4);
|
|
|
|
((EFI_UDP4_COMPLETION_TOKEN *) Token)->Packet.TxData = Data;
|
|
|
|
|
|
|
|
((EFI_UDP4_TRANSMIT_DATA *) Data)->UdpSessionData = NULL;
|
|
|
|
((EFI_UDP4_TRANSMIT_DATA *) Data)->GatewayAddress = NULL;
|
|
|
|
((EFI_UDP4_TRANSMIT_DATA *) Data)->DataLength = Packet->TotalSize;
|
|
|
|
|
|
|
|
NetbufBuildExt (
|
|
|
|
Packet,
|
|
|
|
(NET_FRAGMENT *)((EFI_UDP4_TRANSMIT_DATA *) Data)->FragmentTable,
|
|
|
|
&Count
|
|
|
|
);
|
|
|
|
|
|
|
|
((EFI_UDP4_TRANSMIT_DATA *) Data)->FragmentCount = Count;
|
|
|
|
|
|
|
|
if (EndPoint != NULL) {
|
|
|
|
Ip = HTONL (EndPoint->LocalAddr.Addr[0]);
|
|
|
|
CopyMem (
|
2010-01-08 03:35:56 +01:00
|
|
|
&TxToken->Session.Udp4.SourceAddress,
|
|
|
|
&Ip,
|
2009-10-30 06:11:38 +01:00
|
|
|
sizeof (EFI_IPv4_ADDRESS)
|
|
|
|
);
|
|
|
|
|
|
|
|
Ip = HTONL (EndPoint->RemoteAddr.Addr[0]);
|
|
|
|
CopyMem (
|
2010-01-08 03:35:56 +01:00
|
|
|
&TxToken->Session.Udp4.DestinationAddress,
|
|
|
|
&Ip,
|
2009-10-30 06:11:38 +01:00
|
|
|
sizeof (EFI_IPv4_ADDRESS)
|
|
|
|
);
|
|
|
|
|
|
|
|
TxToken->Session.Udp4.SourcePort = EndPoint->LocalPort;
|
|
|
|
TxToken->Session.Udp4.DestinationPort = EndPoint->RemotePort;
|
|
|
|
((EFI_UDP4_TRANSMIT_DATA *) Data)->UdpSessionData = &(TxToken->Session.Udp4);
|
|
|
|
}
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if (Gateway != NULL && (Gateway->Addr[0] != 0)) {
|
|
|
|
Ip = HTONL (Gateway->Addr[0]);
|
|
|
|
CopyMem (&TxToken->Gateway, &Ip, sizeof (EFI_IPv4_ADDRESS));
|
2010-01-08 03:35:56 +01:00
|
|
|
((EFI_UDP4_TRANSMIT_DATA *) Data)->GatewayAddress = &TxToken->Gateway;
|
2009-10-30 06:11:38 +01:00
|
|
|
}
|
2007-08-30 08:58:37 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
} else {
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
((EFI_UDP6_COMPLETION_TOKEN *) Token)->Status = EFI_NOT_READY;
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
Status = gBS->CreateEvent (
|
|
|
|
EVT_NOTIFY_SIGNAL,
|
|
|
|
TPL_NOTIFY,
|
|
|
|
UdpIoOnDgramSent,
|
|
|
|
TxToken,
|
|
|
|
&((EFI_UDP6_COMPLETION_TOKEN *) Token)->Event
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
FreePool (TxToken);
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
Data = &(TxToken->Data.Udp6);
|
|
|
|
((EFI_UDP6_COMPLETION_TOKEN *) Token)->Packet.TxData = Data;
|
|
|
|
((EFI_UDP6_TRANSMIT_DATA *) Data)->UdpSessionData = NULL;
|
|
|
|
((EFI_UDP6_TRANSMIT_DATA *) Data)->DataLength = Packet->TotalSize;
|
|
|
|
|
|
|
|
NetbufBuildExt (
|
|
|
|
Packet,
|
|
|
|
(NET_FRAGMENT *)((EFI_UDP6_TRANSMIT_DATA *) Data)->FragmentTable,
|
|
|
|
&Count
|
|
|
|
);
|
|
|
|
|
|
|
|
((EFI_UDP6_TRANSMIT_DATA *) Data)->FragmentCount = Count;
|
|
|
|
|
|
|
|
if (EndPoint != NULL) {
|
|
|
|
CopyMem (
|
2010-01-08 03:35:56 +01:00
|
|
|
&TxToken->Session.Udp6.SourceAddress,
|
|
|
|
&EndPoint->LocalAddr.v6,
|
2009-10-30 06:11:38 +01:00
|
|
|
sizeof(EFI_IPv6_ADDRESS)
|
|
|
|
);
|
|
|
|
|
|
|
|
CopyMem (
|
2010-01-08 03:35:56 +01:00
|
|
|
&TxToken->Session.Udp6.DestinationAddress,
|
|
|
|
&EndPoint->RemoteAddr.v6,
|
2009-10-30 06:11:38 +01:00
|
|
|
sizeof(EFI_IPv6_ADDRESS)
|
|
|
|
);
|
|
|
|
|
|
|
|
TxToken->Session.Udp6.SourcePort = EndPoint->LocalPort;
|
|
|
|
TxToken->Session.Udp6.DestinationPort = EndPoint->RemotePort;
|
|
|
|
((EFI_UDP6_TRANSMIT_DATA *) Data)->UdpSessionData = &(TxToken->Session.Udp6);
|
2010-01-08 03:35:56 +01:00
|
|
|
}
|
2007-07-23 11:17:39 +02:00
|
|
|
}
|
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
return TxToken;
|
2007-07-23 11:17:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-10-30 06:11:38 +01:00
|
|
|
Creates a UDP_IO to access the UDP service. It creates and configures
|
2008-12-26 10:09:02 +01:00
|
|
|
a UDP child.
|
2010-01-08 03:35:56 +01:00
|
|
|
|
|
|
|
It locates the UDP service binding prototype on the Controller parameter
|
|
|
|
uses the UDP service binding prototype to create a UDP child (also known as
|
|
|
|
a UDP instance) configures the UDP child by calling Configure function prototype.
|
|
|
|
Any failures in creating or configuring the UDP child return NULL for failure.
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-01-13 09:48:19 +01:00
|
|
|
@param[in] Controller The controller that has the UDP service binding.
|
|
|
|
protocol installed.
|
2009-10-30 06:11:38 +01:00
|
|
|
@param[in] ImageHandle The image handle for the driver.
|
2009-01-13 09:48:19 +01:00
|
|
|
@param[in] Configure The function to configure the created UDP child.
|
2009-10-30 06:11:38 +01:00
|
|
|
@param[in] UdpVersion The UDP protocol version, UDP4 or UDP6.
|
2009-01-13 09:48:19 +01:00
|
|
|
@param[in] Context The opaque parameter for the Configure funtion.
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
@return Newly-created UDP_IO or NULL if failed.
|
2007-07-23 11:17:39 +02:00
|
|
|
|
|
|
|
**/
|
2009-10-30 06:11:38 +01:00
|
|
|
UDP_IO *
|
2008-04-11 05:36:07 +02:00
|
|
|
EFIAPI
|
2009-10-30 06:11:38 +01:00
|
|
|
UdpIoCreateIo (
|
2007-07-23 11:17:39 +02:00
|
|
|
IN EFI_HANDLE Controller,
|
2009-10-30 06:11:38 +01:00
|
|
|
IN EFI_HANDLE ImageHandle,
|
2007-07-23 11:17:39 +02:00
|
|
|
IN UDP_IO_CONFIG Configure,
|
2009-10-30 06:11:38 +01:00
|
|
|
IN UINT8 UdpVersion,
|
2007-07-23 11:17:39 +02:00
|
|
|
IN VOID *Context
|
|
|
|
)
|
|
|
|
{
|
2009-10-30 06:11:38 +01:00
|
|
|
UDP_IO *UdpIo;
|
2007-07-23 11:17:39 +02:00
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
ASSERT (Configure != NULL);
|
2009-10-30 06:11:38 +01:00
|
|
|
ASSERT ((UdpVersion == UDP_IO_UDP4_VERSION) || (UdpVersion == UDP_IO_UDP6_VERSION));
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
UdpIo = AllocatePool (sizeof (UDP_IO));
|
2007-07-23 11:17:39 +02:00
|
|
|
|
|
|
|
if (UdpIo == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
UdpIo->UdpVersion = UdpVersion;
|
2007-07-23 11:17:39 +02:00
|
|
|
UdpIo->Signature = UDP_IO_SIGNATURE;
|
2008-02-14 10:40:22 +01:00
|
|
|
InitializeListHead (&UdpIo->Link);
|
2007-07-23 11:17:39 +02:00
|
|
|
UdpIo->RefCnt = 1;
|
|
|
|
|
|
|
|
UdpIo->Controller = Controller;
|
2009-10-30 06:11:38 +01:00
|
|
|
UdpIo->Image = ImageHandle;
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2008-02-14 10:40:22 +01:00
|
|
|
InitializeListHead (&UdpIo->SentDatagram);
|
2007-07-23 11:17:39 +02:00
|
|
|
UdpIo->RecvRequest = NULL;
|
|
|
|
UdpIo->UdpHandle = NULL;
|
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if (UdpVersion == UDP_IO_UDP4_VERSION) {
|
|
|
|
//
|
|
|
|
// Create a UDP child then open and configure it
|
|
|
|
//
|
|
|
|
Status = NetLibCreateServiceChild (
|
|
|
|
Controller,
|
|
|
|
ImageHandle,
|
|
|
|
&gEfiUdp4ServiceBindingProtocolGuid,
|
|
|
|
&UdpIo->UdpHandle
|
|
|
|
);
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto FREE_MEM;
|
|
|
|
}
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
UdpIo->UdpHandle,
|
|
|
|
&gEfiUdp4ProtocolGuid,
|
|
|
|
(VOID **) &UdpIo->Protocol.Udp4,
|
|
|
|
ImageHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto FREE_CHILD;
|
|
|
|
}
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if (EFI_ERROR (Configure (UdpIo, Context))) {
|
|
|
|
goto CLOSE_PROTOCOL;
|
|
|
|
}
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
Status = UdpIo->Protocol.Udp4->GetModeData (
|
2010-01-08 03:35:56 +01:00
|
|
|
UdpIo->Protocol.Udp4,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2009-10-30 06:11:38 +01:00
|
|
|
&UdpIo->SnpMode
|
|
|
|
);
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto CLOSE_PROTOCOL;
|
|
|
|
}
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
} else {
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
Status = NetLibCreateServiceChild (
|
|
|
|
Controller,
|
|
|
|
ImageHandle,
|
|
|
|
&gEfiUdp6ServiceBindingProtocolGuid,
|
|
|
|
&UdpIo->UdpHandle
|
|
|
|
);
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto FREE_MEM;
|
|
|
|
}
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
UdpIo->UdpHandle,
|
|
|
|
&gEfiUdp6ProtocolGuid,
|
|
|
|
(VOID **) &UdpIo->Protocol.Udp6,
|
|
|
|
ImageHandle,
|
|
|
|
Controller,
|
|
|
|
EFI_OPEN_PROTOCOL_BY_DRIVER
|
|
|
|
);
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto FREE_CHILD;
|
|
|
|
}
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if (EFI_ERROR (Configure (UdpIo, Context))) {
|
|
|
|
goto CLOSE_PROTOCOL;
|
|
|
|
}
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
Status = UdpIo->Protocol.Udp6->GetModeData (
|
2010-01-08 03:35:56 +01:00
|
|
|
UdpIo->Protocol.Udp6,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2009-10-30 06:11:38 +01:00
|
|
|
&UdpIo->SnpMode
|
|
|
|
);
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto CLOSE_PROTOCOL;
|
|
|
|
}
|
2007-07-23 11:17:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return UdpIo;
|
|
|
|
|
|
|
|
CLOSE_PROTOCOL:
|
2009-10-30 06:11:38 +01:00
|
|
|
if (UdpVersion == UDP_IO_UDP4_VERSION) {
|
|
|
|
gBS->CloseProtocol (UdpIo->UdpHandle, &gEfiUdp4ProtocolGuid, ImageHandle, Controller);
|
|
|
|
} else {
|
|
|
|
gBS->CloseProtocol (UdpIo->UdpHandle, &gEfiUdp6ProtocolGuid, ImageHandle, Controller);
|
|
|
|
}
|
2007-07-23 11:17:39 +02:00
|
|
|
|
|
|
|
FREE_CHILD:
|
2009-10-30 06:11:38 +01:00
|
|
|
if (UdpVersion == UDP_IO_UDP4_VERSION) {
|
|
|
|
NetLibDestroyServiceChild (
|
|
|
|
Controller,
|
|
|
|
ImageHandle,
|
|
|
|
&gEfiUdp4ServiceBindingProtocolGuid,
|
|
|
|
UdpIo->UdpHandle
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
NetLibDestroyServiceChild (
|
|
|
|
Controller,
|
|
|
|
ImageHandle,
|
|
|
|
&gEfiUdp6ServiceBindingProtocolGuid,
|
|
|
|
UdpIo->UdpHandle
|
|
|
|
);
|
|
|
|
}
|
2007-07-23 11:17:39 +02:00
|
|
|
|
|
|
|
FREE_MEM:
|
2009-10-30 06:11:38 +01:00
|
|
|
FreePool (UdpIo);
|
2007-07-23 11:17:39 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-12-26 10:09:02 +01:00
|
|
|
Cancel all the sent datagram that pass the selection criteria of ToCancel.
|
2007-07-23 11:17:39 +02:00
|
|
|
If ToCancel is NULL, all the datagrams are cancelled.
|
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
@param[in] UdpIo The UDP_IO to cancel packet.
|
2009-01-13 09:48:19 +01:00
|
|
|
@param[in] IoStatus The IoStatus to return to the packet owners.
|
|
|
|
@param[in] ToCancel The select funtion to test whether to cancel this
|
|
|
|
packet or not.
|
|
|
|
@param[in] Context The opaque parameter to the ToCancel.
|
2007-07-23 11:17:39 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
2009-02-24 09:26:40 +01:00
|
|
|
EFIAPI
|
2007-07-23 11:17:39 +02:00
|
|
|
UdpIoCancelDgrams (
|
2009-10-30 06:11:38 +01:00
|
|
|
IN UDP_IO *UdpIo,
|
2007-07-23 11:17:39 +02:00
|
|
|
IN EFI_STATUS IoStatus,
|
|
|
|
IN UDP_IO_TO_CANCEL ToCancel, OPTIONAL
|
|
|
|
IN VOID *Context
|
|
|
|
)
|
|
|
|
{
|
2008-02-14 10:40:22 +01:00
|
|
|
LIST_ENTRY *Entry;
|
|
|
|
LIST_ENTRY *Next;
|
2009-10-30 06:11:38 +01:00
|
|
|
UDP_TX_TOKEN *TxToken;
|
|
|
|
|
|
|
|
ASSERT ((UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) ||
|
|
|
|
(UdpIo->UdpVersion == UDP_IO_UDP6_VERSION));
|
2007-07-23 11:17:39 +02:00
|
|
|
|
|
|
|
NET_LIST_FOR_EACH_SAFE (Entry, Next, &UdpIo->SentDatagram) {
|
2009-10-30 06:11:38 +01:00
|
|
|
TxToken = NET_LIST_USER_STRUCT (Entry, UDP_TX_TOKEN, Link);
|
|
|
|
|
|
|
|
if ((ToCancel == NULL) || (ToCancel (TxToken, Context))) {
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if (UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) {
|
|
|
|
UdpIo->Protocol.Udp4->Cancel (UdpIo->Protocol.Udp4, &TxToken->Token.Udp4);
|
|
|
|
} else {
|
|
|
|
UdpIo->Protocol.Udp6->Cancel (UdpIo->Protocol.Udp6, &TxToken->Token.Udp6);
|
|
|
|
}
|
2007-07-23 11:17:39 +02:00
|
|
|
}
|
2010-01-08 03:35:56 +01:00
|
|
|
}
|
2007-07-23 11:17:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-10-30 06:11:38 +01:00
|
|
|
Free the UDP_IO and all its related resources.
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2008-12-26 10:09:02 +01:00
|
|
|
The function will cancel all sent datagram and receive request.
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
@param[in] UdpIo The UDP_IO to free.
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
@retval EFI_SUCCESS The UDP_IO is freed.
|
2007-07-23 11:17:39 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
2008-04-11 05:36:07 +02:00
|
|
|
EFIAPI
|
2009-10-30 06:11:38 +01:00
|
|
|
UdpIoFreeIo (
|
|
|
|
IN UDP_IO *UdpIo
|
2007-07-23 11:17:39 +02:00
|
|
|
)
|
|
|
|
{
|
2009-10-30 06:11:38 +01:00
|
|
|
UDP_RX_TOKEN *RxToken;
|
|
|
|
|
|
|
|
ASSERT ((UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) ||
|
|
|
|
(UdpIo->UdpVersion == UDP_IO_UDP6_VERSION));
|
2007-07-23 11:17:39 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Cancel all the sent datagram and receive requests. The
|
|
|
|
// callbacks of transmit requests are executed to allow the
|
|
|
|
// caller to release the resource. The callback of receive
|
|
|
|
// request are NOT executed. This is because it is most
|
|
|
|
// likely that the current user of the UDP IO port is closing
|
|
|
|
// itself.
|
|
|
|
//
|
|
|
|
UdpIoCancelDgrams (UdpIo, EFI_ABORTED, NULL, NULL);
|
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if (UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) {
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if ((RxToken = UdpIo->RecvRequest) != NULL) {
|
|
|
|
UdpIo->Protocol.Udp4->Cancel (UdpIo->Protocol.Udp4, &RxToken->Token.Udp4);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2012-10-17 10:23:41 +02:00
|
|
|
// Close then destroy the Udp4 child
|
2009-10-30 06:11:38 +01:00
|
|
|
//
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
UdpIo->UdpHandle,
|
|
|
|
&gEfiUdp4ProtocolGuid,
|
|
|
|
UdpIo->Image,
|
|
|
|
UdpIo->Controller
|
|
|
|
);
|
|
|
|
|
|
|
|
NetLibDestroyServiceChild (
|
|
|
|
UdpIo->Controller,
|
|
|
|
UdpIo->Image,
|
|
|
|
&gEfiUdp4ServiceBindingProtocolGuid,
|
|
|
|
UdpIo->UdpHandle
|
|
|
|
);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if ((RxToken = UdpIo->RecvRequest) != NULL) {
|
|
|
|
UdpIo->Protocol.Udp6->Cancel (UdpIo->Protocol.Udp6, &RxToken->Token.Udp6);
|
|
|
|
}
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
//
|
2012-10-17 10:23:41 +02:00
|
|
|
// Close then destroy the Udp6 child
|
2009-10-30 06:11:38 +01:00
|
|
|
//
|
|
|
|
gBS->CloseProtocol (
|
|
|
|
UdpIo->UdpHandle,
|
|
|
|
&gEfiUdp6ProtocolGuid,
|
|
|
|
UdpIo->Image,
|
|
|
|
UdpIo->Controller
|
|
|
|
);
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
NetLibDestroyServiceChild (
|
|
|
|
UdpIo->Controller,
|
|
|
|
UdpIo->Image,
|
|
|
|
&gEfiUdp6ServiceBindingProtocolGuid,
|
|
|
|
UdpIo->UdpHandle
|
|
|
|
);
|
|
|
|
}
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2007-08-23 04:19:41 +02:00
|
|
|
if (!IsListEmpty(&UdpIo->Link)) {
|
2008-02-14 10:40:22 +01:00
|
|
|
RemoveEntryList (&UdpIo->Link);
|
2007-08-23 04:19:41 +02:00
|
|
|
}
|
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
FreePool (UdpIo);
|
2007-07-23 11:17:39 +02:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-10-30 06:11:38 +01:00
|
|
|
Clean up the UDP_IO without freeing it. The function is called when
|
|
|
|
user wants to re-use the UDP_IO later.
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2008-12-26 10:09:02 +01:00
|
|
|
It will release all the transmitted datagrams and receive request. It will
|
|
|
|
also configure NULL for the UDP instance.
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
@param[in] UdpIo The UDP_IO to clean up.
|
2007-07-23 11:17:39 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
2008-04-11 05:36:07 +02:00
|
|
|
EFIAPI
|
2009-10-30 06:11:38 +01:00
|
|
|
UdpIoCleanIo (
|
|
|
|
IN UDP_IO *UdpIo
|
2007-07-23 11:17:39 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
UDP_RX_TOKEN *RxToken;
|
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
ASSERT ((UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) ||
|
|
|
|
(UdpIo->UdpVersion == UDP_IO_UDP6_VERSION));
|
|
|
|
|
2007-07-23 11:17:39 +02:00
|
|
|
//
|
|
|
|
// Cancel all the sent datagram and receive requests.
|
|
|
|
//
|
|
|
|
UdpIoCancelDgrams (UdpIo, EFI_ABORTED, NULL, NULL);
|
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if (UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) {
|
|
|
|
if ((RxToken = UdpIo->RecvRequest) != NULL) {
|
|
|
|
UdpIo->Protocol.Udp4->Cancel (UdpIo->Protocol.Udp4, &RxToken->Token.Udp4);
|
|
|
|
}
|
|
|
|
|
|
|
|
UdpIo->Protocol.Udp4->Configure (UdpIo->Protocol.Udp4, NULL);
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
} else {
|
|
|
|
if ((RxToken = UdpIo->RecvRequest) != NULL) {
|
|
|
|
UdpIo->Protocol.Udp6->Cancel (UdpIo->Protocol.Udp6, &RxToken->Token.Udp6);
|
|
|
|
}
|
|
|
|
|
|
|
|
UdpIo->Protocol.Udp6->Configure (UdpIo->Protocol.Udp6, NULL);
|
|
|
|
}
|
2007-07-23 11:17:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-10-30 06:11:38 +01:00
|
|
|
Send a packet through the UDP_IO.
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2008-12-26 10:09:02 +01:00
|
|
|
The packet will be wrapped in UDP_TX_TOKEN. Function Callback will be called
|
|
|
|
when the packet is sent. The optional parameter EndPoint overrides the default
|
|
|
|
address pair if specified.
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
@param[in] UdpIo The UDP_IO to send the packet through.
|
2009-01-13 09:48:19 +01:00
|
|
|
@param[in] Packet The packet to send.
|
|
|
|
@param[in] EndPoint The local and remote access point. Override the
|
|
|
|
default address pair set during configuration.
|
2010-01-08 03:35:56 +01:00
|
|
|
@param[in] Gateway The gateway to use.
|
2009-01-13 09:48:19 +01:00
|
|
|
@param[in] CallBack The function being called when packet is
|
|
|
|
transmitted or failed.
|
|
|
|
@param[in] Context The opaque parameter passed to CallBack.
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-01-13 09:48:19 +01:00
|
|
|
@retval EFI_OUT_OF_RESOURCES Failed to allocate resource for the packet.
|
2007-07-23 11:17:39 +02:00
|
|
|
@retval EFI_SUCCESS The packet is successfully delivered to UDP for
|
|
|
|
transmission.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
2008-04-11 05:36:07 +02:00
|
|
|
EFIAPI
|
2007-07-23 11:17:39 +02:00
|
|
|
UdpIoSendDatagram (
|
2009-10-30 06:11:38 +01:00
|
|
|
IN UDP_IO *UdpIo,
|
2007-07-23 11:17:39 +02:00
|
|
|
IN NET_BUF *Packet,
|
2009-10-30 06:11:38 +01:00
|
|
|
IN UDP_END_POINT *EndPoint OPTIONAL,
|
|
|
|
IN EFI_IP_ADDRESS *Gateway OPTIONAL,
|
2007-07-23 11:17:39 +02:00
|
|
|
IN UDP_IO_CALLBACK CallBack,
|
|
|
|
IN VOID *Context
|
|
|
|
)
|
|
|
|
{
|
2009-10-30 06:11:38 +01:00
|
|
|
UDP_TX_TOKEN *TxToken;
|
2007-07-23 11:17:39 +02:00
|
|
|
EFI_STATUS Status;
|
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
ASSERT ((UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) ||
|
|
|
|
(UdpIo->UdpVersion == UDP_IO_UDP6_VERSION));
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
TxToken = UdpIoCreateTxToken (UdpIo, Packet, EndPoint, Gateway, CallBack, Context);
|
|
|
|
|
|
|
|
if (TxToken == NULL) {
|
2007-07-23 11:17:39 +02:00
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2007-11-20 06:42:23 +01:00
|
|
|
//
|
|
|
|
// Insert the tx token into SendDatagram list before transmitting it. Remove
|
|
|
|
// it from the list if the returned status is not EFI_SUCCESS.
|
|
|
|
//
|
2009-10-30 06:11:38 +01:00
|
|
|
InsertHeadList (&UdpIo->SentDatagram, &TxToken->Link);
|
|
|
|
|
|
|
|
if (UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) {
|
|
|
|
Status = UdpIo->Protocol.Udp4->Transmit (UdpIo->Protocol.Udp4, &TxToken->Token.Udp4);
|
|
|
|
} else {
|
|
|
|
Status = UdpIo->Protocol.Udp6->Transmit (UdpIo->Protocol.Udp6, &TxToken->Token.Udp6);
|
|
|
|
}
|
|
|
|
|
2007-07-23 11:17:39 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
2009-10-30 06:11:38 +01:00
|
|
|
RemoveEntryList (&TxToken->Link);
|
|
|
|
UdpIoFreeTxToken (TxToken);
|
2007-07-23 11:17:39 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2008-12-26 10:09:02 +01:00
|
|
|
The select function to cancel a single sent datagram.
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-01-13 09:48:19 +01:00
|
|
|
@param[in] Token The UDP_TX_TOKEN to test against
|
|
|
|
@param[in] Context The NET_BUF of the sent datagram
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2008-12-23 08:35:46 +01:00
|
|
|
@retval TRUE The packet is to be cancelled.
|
|
|
|
@retval FALSE The packet is not to be cancelled.
|
2007-07-23 11:17:39 +02:00
|
|
|
**/
|
|
|
|
BOOLEAN
|
2010-04-17 01:24:45 +02:00
|
|
|
EFIAPI
|
2007-07-23 11:17:39 +02:00
|
|
|
UdpIoCancelSingleDgram (
|
|
|
|
IN UDP_TX_TOKEN *Token,
|
|
|
|
IN VOID *Context
|
|
|
|
)
|
|
|
|
{
|
|
|
|
NET_BUF *Packet;
|
|
|
|
|
|
|
|
Packet = (NET_BUF *) Context;
|
|
|
|
|
|
|
|
if (Token->Packet == Packet) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Cancel a single sent datagram.
|
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
@param[in] UdpIo The UDP_IO to cancel the packet from
|
2009-01-13 09:48:19 +01:00
|
|
|
@param[in] Packet The packet to cancel
|
2007-07-23 11:17:39 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
2008-04-11 05:36:07 +02:00
|
|
|
EFIAPI
|
2007-07-23 11:17:39 +02:00
|
|
|
UdpIoCancelSentDatagram (
|
2009-10-30 06:11:38 +01:00
|
|
|
IN UDP_IO *UdpIo,
|
2007-07-23 11:17:39 +02:00
|
|
|
IN NET_BUF *Packet
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UdpIoCancelDgrams (UdpIo, EFI_ABORTED, UdpIoCancelSingleDgram, Packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-10-30 06:11:38 +01:00
|
|
|
Issue a receive request to the UDP_IO.
|
2010-01-08 03:35:56 +01:00
|
|
|
|
2008-12-26 10:09:02 +01:00
|
|
|
This function is called when upper-layer needs packet from UDP for processing.
|
|
|
|
Only one receive request is acceptable at a time so a common usage model is
|
|
|
|
to invoke this function inside its Callback function when the former packet
|
|
|
|
is processed.
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
@param[in] UdpIo The UDP_IO to receive the packet from.
|
2009-01-13 09:48:19 +01:00
|
|
|
@param[in] CallBack The call back function to execute when the packet
|
|
|
|
is received.
|
|
|
|
@param[in] Context The opaque context passed to Callback.
|
2009-10-30 06:11:38 +01:00
|
|
|
@param[in] HeadLen The length of the upper-layer's protocol header.
|
2007-07-23 11:17:39 +02:00
|
|
|
|
|
|
|
@retval EFI_ALREADY_STARTED There is already a pending receive request. Only
|
2008-12-26 10:09:02 +01:00
|
|
|
one receive request is supported at a time.
|
|
|
|
@retval EFI_OUT_OF_RESOURCES Failed to allocate needed resources.
|
2007-07-23 11:17:39 +02:00
|
|
|
@retval EFI_SUCCESS The receive request is issued successfully.
|
2009-10-30 06:11:38 +01:00
|
|
|
@retval EFI_UNSUPPORTED The UDP version in UDP_IO is not supported.
|
2007-07-23 11:17:39 +02:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
2008-04-11 05:36:07 +02:00
|
|
|
EFIAPI
|
2007-07-23 11:17:39 +02:00
|
|
|
UdpIoRecvDatagram (
|
2009-10-30 06:11:38 +01:00
|
|
|
IN UDP_IO *UdpIo,
|
2007-07-23 11:17:39 +02:00
|
|
|
IN UDP_IO_CALLBACK CallBack,
|
|
|
|
IN VOID *Context,
|
|
|
|
IN UINT32 HeadLen
|
|
|
|
)
|
|
|
|
{
|
2009-10-30 06:11:38 +01:00
|
|
|
UDP_RX_TOKEN *RxToken;
|
2007-07-23 11:17:39 +02:00
|
|
|
EFI_STATUS Status;
|
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
ASSERT ((UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) ||
|
|
|
|
(UdpIo->UdpVersion == UDP_IO_UDP6_VERSION));
|
|
|
|
|
2007-07-23 11:17:39 +02:00
|
|
|
if (UdpIo->RecvRequest != NULL) {
|
|
|
|
return EFI_ALREADY_STARTED;
|
|
|
|
}
|
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
RxToken = UdpIoCreateRxToken (UdpIo, CallBack, Context, HeadLen);
|
2007-07-23 11:17:39 +02:00
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
if (RxToken == NULL) {
|
2007-07-23 11:17:39 +02:00
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2009-10-30 06:11:38 +01:00
|
|
|
UdpIo->RecvRequest = RxToken;
|
|
|
|
if (UdpIo->UdpVersion == UDP_IO_UDP4_VERSION) {
|
|
|
|
Status = UdpIo->Protocol.Udp4->Receive (UdpIo->Protocol.Udp4, &RxToken->Token.Udp4);
|
|
|
|
} else {
|
|
|
|
Status = UdpIo->Protocol.Udp6->Receive (UdpIo->Protocol.Udp6, &RxToken->Token.Udp6);
|
|
|
|
}
|
2007-07-23 11:17:39 +02:00
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
2007-11-20 06:42:23 +01:00
|
|
|
UdpIo->RecvRequest = NULL;
|
2009-10-30 06:11:38 +01:00
|
|
|
UdpIoFreeRxToken (RxToken);
|
2007-07-23 11:17:39 +02:00
|
|
|
}
|
|
|
|
|
2007-11-20 06:42:23 +01:00
|
|
|
return Status;
|
2007-07-23 11:17:39 +02:00
|
|
|
}
|