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