summaryrefslogtreecommitdiff
path: root/MdeModulePkg
diff options
context:
space:
mode:
Diffstat (limited to 'MdeModulePkg')
-rw-r--r--MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.c542
1 files changed, 236 insertions, 306 deletions
diff --git a/MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.c b/MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.c
index c24f888..39d3cc9 100644
--- a/MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.c
+++ b/MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.c
@@ -1,6 +1,7 @@
/** @file
-
-Copyright (c) 2006 - 2007, Intel Corporation
+ Help functions to access UDP service, it is used by both the DHCP and MTFTP.
+
+Copyright (c) 2005 - 2007, Intel Corporation.<BR>
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -8,17 +9,6 @@ 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.
-
-
-Module Name:
-
- Udp4Io.c
-
-Abstract:
-
- Help functions to access UDP service, it is used by both the DHCP and MTFTP.
-
-
**/
#include <PiDxe.h>
@@ -32,26 +22,251 @@ Abstract:
#include <Library/MemoryAllocationLib.h>
#include <Library/BaseMemoryLib.h>
+
+/**
+ Free a UDP_TX_TOKEN. The event is closed and memory released.
+
+ @param Token The UDP_TX_TOKEN to release.
+
+**/
+VOID
+UdpIoFreeTxToken (
+ IN UDP_TX_TOKEN *Token
+ )
+{
+ gBS->CloseEvent (Token->UdpToken.Event);
+ gBS->FreePool (Token);
+}
+
+/**
+ Free a receive request wrap.
+
+ @param Token The receive request to release.
+
+**/
+VOID
+UdpIoFreeRxToken (
+ IN UDP_RX_TOKEN *Token
+ )
+{
+ gBS->CloseEvent (Token->UdpToken.Event);
+ gBS->FreePool (Token);
+}
+
+/**
+ The callback function when the packet is sent by UDP.
+ It will remove the packet from the local list then call
+ the packet owner's callback function.
+
+ @param Context The UDP TX Token.
+
+**/
VOID
EFIAPI
UdpIoOnDgramSentDpc (
IN VOID *Context
- );
+ )
+{
+ UDP_TX_TOKEN *Token;
+
+ Token = (UDP_TX_TOKEN *) Context;
+ ASSERT (Token->Signature == UDP_IO_TX_SIGNATURE);
+
+ RemoveEntryList (&Token->Link);
+ Token->CallBack (Token->Packet, NULL, Token->UdpToken.Status, Token->Context);
+
+ UdpIoFreeTxToken (Token);
+}
+
+/**
+ Request UdpIoOnDgramSentDpc as a DPC at TPL_CALLBACK.
+
+ @param Event The event signaled.
+ @param Context The UDP TX Token.
+**/
VOID
EFIAPI
UdpIoOnDgramSent (
IN EFI_EVENT Event,
IN VOID *Context
- );
+ )
+{
+ //
+ // Request UdpIoOnDgramSentDpc as a DPC at TPL_CALLBACK
+ //
+ NetLibQueueDpc (TPL_CALLBACK, UdpIoOnDgramSentDpc, Context);
+}
+
+/**
+ Recycle the received UDP data.
+
+ @param Context The UDP_RX_TOKEN
+**/
+VOID
+UdpIoRecycleDgram (
+ IN VOID *Context
+ )
+{
+ UDP_RX_TOKEN *Token;
+
+ Token = (UDP_RX_TOKEN *) Context;
+ gBS->SignalEvent (Token->UdpToken.Packet.RxData->RecycleSignal);
+ UdpIoFreeRxToken (Token);
+}
+
+/**
+ The event handle for UDP receive request. It will build
+ a NET_BUF from the recieved UDP data, then deliver it
+ to the receiver.
+
+ @param Context The UDP RX token.
+
+**/
+VOID
+EFIAPI
+UdpIoOnDgramRcvdDpc (
+ IN VOID *Context
+ )
+{
+ EFI_UDP4_COMPLETION_TOKEN *UdpToken;
+ EFI_UDP4_RECEIVE_DATA *UdpRxData;
+ EFI_UDP4_SESSION_DATA *UdpSession;
+ UDP_RX_TOKEN *Token;
+ UDP_POINTS Points;
+ NET_BUF *Netbuf;
+
+ Token = (UDP_RX_TOKEN *) Context;
+
+ ASSERT ((Token->Signature == UDP_IO_RX_SIGNATURE) &&
+ (Token == Token->UdpIo->RecvRequest));
+
+ //
+ // Clear the receive request first in case that the caller
+ // wants to restart the receive in the callback.
+ //
+ Token->UdpIo->RecvRequest = NULL;
+
+ UdpToken = &Token->UdpToken;
+ UdpRxData = UdpToken->Packet.RxData;
+
+ if (EFI_ERROR (UdpToken->Status) || (UdpRxData == NULL)) {
+ if (UdpToken->Status != EFI_ABORTED) {
+ //
+ // Invoke the CallBack only if the reception is not actively aborted.
+ //
+ Token->CallBack (NULL, NULL, UdpToken->Status, Token->Context);
+ }
+
+ UdpIoFreeRxToken (Token);
+ return;
+ }
+
+ //
+ // Build a NET_BUF from the UDP receive data, then deliver it up.
+ //
+ Netbuf = NetbufFromExt (
+ (NET_FRAGMENT *) UdpRxData->FragmentTable,
+ UdpRxData->FragmentCount,
+ 0,
+ (UINT32) Token->HeadLen,
+ UdpIoRecycleDgram,
+ Token
+ );
+
+ if (Netbuf == NULL) {
+ gBS->SignalEvent (UdpRxData->RecycleSignal);
+ Token->CallBack (NULL, NULL, EFI_OUT_OF_RESOURCES, Token->Context);
+
+ UdpIoFreeRxToken (Token);
+ return;
+ }
+
+ UdpSession = &UdpRxData->UdpSession;
+ Points.LocalPort = UdpSession->DestinationPort;
+ Points.RemotePort = UdpSession->SourcePort;
+
+ CopyMem (&Points.LocalAddr, &UdpSession->DestinationAddress, sizeof (IP4_ADDR));
+ CopyMem (&Points.RemoteAddr, &UdpSession->SourceAddress, sizeof (IP4_ADDR));
+ Points.LocalAddr = NTOHL (Points.LocalAddr);
+ Points.RemoteAddr = NTOHL (Points.RemoteAddr);
+
+ Token->CallBack (Netbuf, &Points, EFI_SUCCESS, Token->Context);
+}
+
+/**
+ Request UdpIoOnDgramRcvdDpc as a DPC at TPL_CALLBACK.
+
+ @param Event The UDP receive request event.
+ @param Context The UDP RX token.
+
+**/
VOID
EFIAPI
UdpIoOnDgramRcvd (
IN EFI_EVENT Event,
IN VOID *Context
- );
+ )
+{
+ //
+ // Request UdpIoOnDgramRcvdDpc as a DPC at TPL_CALLBACK
+ //
+ NetLibQueueDpc (TPL_CALLBACK, UdpIoOnDgramRcvdDpc, Context);
+}
+/**
+ Create a UDP_RX_TOKEN to wrap the request.
+
+ @param UdpIo The UdpIo to receive packets from
+ @param CallBack The function to call when receive finished.
+ @param Context The opaque parameter to the CallBack
+ @param HeadLen The head length to reserver for the packet.
+
+ @return The Wrapped request or NULL if failed to allocate resources or some errors happened.
+
+**/
+UDP_RX_TOKEN *
+UdpIoCreateRxToken (
+ IN UDP_IO_PORT *UdpIo,
+ IN UDP_IO_CALLBACK CallBack,
+ IN VOID *Context,
+ IN UINT32 HeadLen
+ )
+{
+ UDP_RX_TOKEN *Token;
+ EFI_STATUS Status;
+
+ 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;
+
+ Token->UdpToken.Status = EFI_NOT_READY;
+ Token->UdpToken.Packet.RxData = NULL;
+
+ Status = gBS->CreateEvent (
+ EVT_NOTIFY_SIGNAL,
+ TPL_NOTIFY,
+ UdpIoOnDgramRcvd,
+ Token,
+ &Token->UdpToken.Event
+ );
+
+ if (EFI_ERROR (Status)) {
+ gBS->FreePool (Token);
+ return NULL;
+ }
+
+ return Token;
+}
/**
Wrap a transmit request into a UDP_TX_TOKEN.
@@ -63,7 +278,8 @@ UdpIoOnDgramRcvd (
@param CallBack The function to call when transmission completed.
@param Context The opaque parameter to the call back
- @return The wrapped transmission request or NULL if failed to allocate resources.
+ @return The wrapped transmission request or NULL if failed to allocate resources
+ or for some errors.
**/
UDP_TX_TOKEN *
@@ -148,94 +364,6 @@ UdpIoWrapTx (
}
-/**
- Free a UDP_TX_TOKEN. The event is closed and memory released.
-
- @param Token The UDP_TX_TOKEN to release.
-
- @return None
-
-**/
-VOID
-UdpIoFreeTxToken (
- IN UDP_TX_TOKEN *Token
- )
-{
- gBS->CloseEvent (Token->UdpToken.Event);
- gBS->FreePool (Token);
-}
-
-
-/**
- Create a UDP_RX_TOKEN to wrap the request.
-
- @param UdpIo The UdpIo to receive packets from
- @param CallBack The function to call when receive finished.
- @param Context The opaque parameter to the CallBack
- @param HeadLen The head length to reserver for the packet.
-
- @return The Wrapped request or NULL if failed to allocate resources.
-
-**/
-UDP_RX_TOKEN *
-UdpIoCreateRxToken (
- IN UDP_IO_PORT *UdpIo,
- IN UDP_IO_CALLBACK CallBack,
- IN VOID *Context,
- IN UINT32 HeadLen
- )
-{
- UDP_RX_TOKEN *Token;
- EFI_STATUS Status;
-
- 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;
-
- Token->UdpToken.Status = EFI_NOT_READY;
- Token->UdpToken.Packet.RxData = NULL;
-
- Status = gBS->CreateEvent (
- EVT_NOTIFY_SIGNAL,
- TPL_NOTIFY,
- UdpIoOnDgramRcvd,
- Token,
- &Token->UdpToken.Event
- );
-
- if (EFI_ERROR (Status)) {
- gBS->FreePool (Token);
- return NULL;
- }
-
- return Token;
-}
-
-
-/**
- Free a receive request wrap.
-
- @param Token The receive request to release.
-
- @return None
-
-**/
-VOID
-UdpIoFreeRxToken (
- IN UDP_RX_TOKEN *Token
- )
-{
- gBS->CloseEvent (Token->UdpToken.Event);
- gBS->FreePool (Token);
-}
/**
@@ -248,7 +376,7 @@ UdpIoFreeRxToken (
@param Configure The function to configure the created UDP child
@param Context The opaque parameter for the Configure funtion.
- @return A point to just created UDP IO port or NULL if failed.
+ @return A point to just created UDP IO port or NULL if some error happened.
**/
UDP_IO_PORT *
@@ -348,8 +476,6 @@ FREE_MEM:
packet or not.
@param Context The opaque parameter to the ToCancel.
- @return None
-
**/
VOID
UdpIoCancelDgrams (
@@ -437,8 +563,6 @@ UdpIoFreePort (
@param UdpIo UDP IO port to clean up.
- @return None
-
**/
VOID
EFIAPI
@@ -460,57 +584,6 @@ UdpIoCleanPort (
UdpIo->Udp->Configure (UdpIo->Udp, NULL);
}
-
-/**
- The callback function when the packet is sent by UDP.
- It will remove the packet from the local list then call
- the packet owner's callback function.
-
- @param Context The UDP TX Token.
-
- @return None
-
-**/
-VOID
-EFIAPI
-UdpIoOnDgramSentDpc (
- IN VOID *Context
- )
-{
- UDP_TX_TOKEN *Token;
-
- Token = (UDP_TX_TOKEN *) Context;
- ASSERT (Token->Signature == UDP_IO_TX_SIGNATURE);
-
- RemoveEntryList (&Token->Link);
- Token->CallBack (Token->Packet, NULL, Token->UdpToken.Status, Token->Context);
-
- UdpIoFreeTxToken (Token);
-}
-
-/**
- Request UdpIoOnDgramSentDpc as a DPC at TPL_CALLBACK.
-
- @param Event The event signalled.
- @param Context The UDP TX Token.
-
- @return None
-
-**/
-VOID
-EFIAPI
-UdpIoOnDgramSent (
- IN EFI_EVENT Event,
- IN VOID *Context
- )
-{
- //
- // Request UdpIoOnDgramSentDpc as a DPC at TPL_CALLBACK
- //
- NetLibQueueDpc (TPL_CALLBACK, UdpIoOnDgramSentDpc, Context);
-}
-
-
/**
Send a packet through the UDP IO port.
@@ -569,8 +642,8 @@ UdpIoSendDatagram (
@param Token The UDP TX token to test againist.
@param Context The context
- @return TRUE if the packet is to be cancelled, otherwise FALSE.
-
+ @retval TRUE The packet is to be cancelled.
+ @retval FALSE The packet is not to be cancelled.
**/
BOOLEAN
UdpIoCancelSingleDgram (
@@ -596,8 +669,6 @@ UdpIoCancelSingleDgram (
@param UdpIo The UDP IO port to cancel the packet from
@param Packet The packet to cancel
- @return None
-
**/
VOID
EFIAPI
@@ -609,147 +680,6 @@ UdpIoCancelSentDatagram (
UdpIoCancelDgrams (UdpIo, EFI_ABORTED, UdpIoCancelSingleDgram, Packet);
}
-
-/**
- Recycle the received UDP data.
-
- @param Context The UDP_RX_TOKEN
-
- @return None
-
-**/
-VOID
-UdpIoRecycleDgram (
- IN VOID *Context
- )
-{
- UDP_RX_TOKEN *Token;
-
- Token = (UDP_RX_TOKEN *) Context;
- gBS->SignalEvent (Token->UdpToken.Packet.RxData->RecycleSignal);
- UdpIoFreeRxToken (Token);
-}
-
-/**
- The event handle for UDP receive request. It will build
- a NET_BUF from the recieved UDP data, then deliver it
- to the receiver.
-
- @param Context The UDP RX token.
-
- @return None
-
-**/
-VOID
-EFIAPI
-UdpIoOnDgramRcvdDpc (
- IN VOID *Context
- )
-{
- EFI_UDP4_COMPLETION_TOKEN *UdpToken;
- EFI_UDP4_RECEIVE_DATA *UdpRxData;
- EFI_UDP4_SESSION_DATA *UdpSession;
- UDP_RX_TOKEN *Token;
- UDP_POINTS Points;
- NET_BUF *Netbuf;
-
- Token = (UDP_RX_TOKEN *) Context;
-
- ASSERT ((Token->Signature == UDP_IO_RX_SIGNATURE) &&
- (Token == Token->UdpIo->RecvRequest));
-
- //
- // Clear the receive request first in case that the caller
- // wants to restart the receive in the callback.
- //
- Token->UdpIo->RecvRequest = NULL;
-
- UdpToken = &Token->UdpToken;
- UdpRxData = UdpToken->Packet.RxData;
-
- if (EFI_ERROR (UdpToken->Status) || (UdpRxData == NULL)) {
- if (UdpToken->Status != EFI_ABORTED) {
- //
- // Invoke the CallBack only if the reception is not actively aborted.
- //
- Token->CallBack (NULL, NULL, UdpToken->Status, Token->Context);
- }
-
- UdpIoFreeRxToken (Token);
- return;
- }
-
- //
- // Build a NET_BUF from the UDP receive data, then deliver it up.
- //
- Netbuf = NetbufFromExt (
- (NET_FRAGMENT *) UdpRxData->FragmentTable,
- UdpRxData->FragmentCount,
- 0,
- (UINT32) Token->HeadLen,
- UdpIoRecycleDgram,
- Token
- );
-
- if (Netbuf == NULL) {
- gBS->SignalEvent (UdpRxData->RecycleSignal);
- Token->CallBack (NULL, NULL, EFI_OUT_OF_RESOURCES, Token->Context);
-
- UdpIoFreeRxToken (Token);
- return;
- }
-
- UdpSession = &UdpRxData->UdpSession;
- Points.LocalPort = UdpSession->DestinationPort;
- Points.RemotePort = UdpSession->SourcePort;
-
- CopyMem (&Points.LocalAddr, &UdpSession->DestinationAddress, sizeof (IP4_ADDR));
- CopyMem (&Points.RemoteAddr, &UdpSession->SourceAddress, sizeof (IP4_ADDR));
- Points.LocalAddr = NTOHL (Points.LocalAddr);
- Points.RemoteAddr = NTOHL (Points.RemoteAddr);
-
- Token->CallBack (Netbuf, &Points, EFI_SUCCESS, Token->Context);
-}
-
-/**
- Request UdpIoOnDgramRcvdDpc as a DPC at TPL_CALLBACK.
-
- @param Event The UDP receive request event.
- @param Context The UDP RX token.
-
- @return None
-
-**/
-VOID
-EFIAPI
-UdpIoOnDgramRcvd (
- IN EFI_EVENT Event,
- IN VOID *Context
- )
-/*++
-
-Routine Description:
-
- Request UdpIoOnDgramRcvdDpc as a DPC at TPL_CALLBACK
-
-Arguments:
-
- Event - The UDP receive request event
- Context - The UDP RX token.
-
-Returns:
-
- None
-
---*/
-{
- //
- // Request UdpIoOnDgramRcvdDpc as a DPC at TPL_CALLBACK
- //
- NetLibQueueDpc (TPL_CALLBACK, UdpIoOnDgramRcvdDpc, Context);
-}
-
-
/**
Issue a receive request to the UDP IO port.