]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Impl.c
BaseTools:Change the path of the file that Binary Cache
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Udp4Dxe / Udp4Impl.c
index d9372ba1b8316b58d1e7b38d0d199ddedc2273ea..fb1951fb135774591ac3cc859b6d47ce1cf531c5 100644 (file)
@@ -1,22 +1,8 @@
 /** @file\r
-\r
-Copyright (c) 2006 - 2008, Intel Corporation                                                         \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
-http://opensource.org/licenses/bsd-license.php\r
-\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
-Module Name:\r
-\r
-  Udp4Impl.c\r
-\r
-Abstract:\r
-\r
   The implementation of the Udp4 protocol.\r
 \r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -25,6 +11,15 @@ Abstract:
 \r
 UINT16  mUdp4RandomPort;\r
 \r
+/**\r
+  This function checks and timeouts the I/O datagrams holding by the corresponding\r
+  service context.\r
+\r
+  @param[in]  Event                  The event this function registered to.\r
+  @param[in]  Context                The context data registered during the creation of\r
+                                     the Event.\r
+\r
+**/\r
 VOID\r
 EFIAPI\r
 Udp4CheckTimeout (\r
@@ -32,6 +27,18 @@ Udp4CheckTimeout (
   IN VOID       *Context\r
   );\r
 \r
+/**\r
+  This function finds the udp instance by the specified <Address, Port> pair.\r
+\r
+  @param[in]  InstanceList           Pointer to the head of the list linking the udp\r
+                                     instances.\r
+  @param[in]  Address                Pointer to the specified IPv4 address.\r
+  @param[in]  Port                   The udp port number.\r
+\r
+  @retval TRUE     The specified <Address, Port> pair is found.\r
+  @retval FALSE    Otherwise.\r
+\r
+**/\r
 BOOLEAN\r
 Udp4FindInstanceByPort (\r
   IN LIST_ENTRY        *InstanceList,\r
@@ -39,36 +46,97 @@ Udp4FindInstanceByPort (
   IN UINT16            Port\r
   );\r
 \r
+/**\r
+  This function is the packet transmitting notify function registered to the IpIo\r
+  interface. It's called to signal the udp TxToken when IpIo layer completes the\r
+  transmitting of the udp datagram.\r
+\r
+  @param[in]  Status                 The completion status of the output udp datagram.\r
+  @param[in]  Context                Pointer to the context data.\r
+  @param[in]  Sender                 Specify a pointer of EFI_IP4_PROTOCOL for sending.\r
+  @param[in]  NotifyData             Pointer to the notify data.\r
+\r
+**/\r
 VOID\r
+EFIAPI\r
 Udp4DgramSent (\r
-  IN EFI_STATUS  Status,\r
-  IN VOID        *Context,\r
-  IN VOID        *Sender,\r
-  IN VOID        *NotifyData\r
+  IN EFI_STATUS        Status,\r
+  IN VOID              *Context,\r
+  IN IP_IO_IP_PROTOCOL Sender,\r
+  IN VOID              *NotifyData\r
   );\r
 \r
+/**\r
+  This function processes the received datagram passed up by the IpIo layer.\r
+\r
+  @param[in]  Status             The status of this udp datagram.\r
+  @param[in]  IcmpError          The IcmpError code, only available when Status is\r
+                                 EFI_ICMP_ERROR.\r
+  @param[in]  NetSession         Pointer to the EFI_NET_SESSION_DATA.\r
+  @param[in]  Packet             Pointer to the NET_BUF containing the received udp\r
+                                 datagram.\r
+  @param[in]  Context            Pointer to the context data.\r
+\r
+**/\r
 VOID\r
+EFIAPI\r
 Udp4DgramRcvd (\r
   IN EFI_STATUS            Status,\r
-  IN ICMP_ERROR            IcmpError,\r
+  IN UINT8                 IcmpError,\r
   IN EFI_NET_SESSION_DATA  *NetSession,\r
   IN NET_BUF               *Packet,\r
   IN VOID                  *Context\r
   );\r
 \r
+/**\r
+  This function cancels the token specified by Arg in the Map. This is a callback\r
+  used by Udp4InstanceCancelToken().\r
+\r
+  @param[in]  Map                Pointer to the NET_MAP.\r
+  @param[in]  Item               Pointer to the NET_MAP_ITEM.\r
+  @param[in]  Arg                Pointer to the token to be cancelled, if NULL,\r
+                                 the token specified by Item is cancelled.\r
+\r
+  @retval EFI_SUCCESS            The token is cancelled if Arg is NULL or the token\r
+                                 is not the same as that in the Item if Arg is not\r
+                                 NULL.\r
+  @retval EFI_ABORTED            Arg is not NULL, and the token specified by Arg is\r
+                                 cancelled.\r
+\r
+**/\r
 EFI_STATUS\r
+EFIAPI\r
 Udp4CancelTokens (\r
   IN NET_MAP       *Map,\r
   IN NET_MAP_ITEM  *Item,\r
   IN VOID          *Arg OPTIONAL\r
   );\r
 \r
+/**\r
+  This function matches the received udp datagram with the Instance.\r
+\r
+  @param[in]  Instance           Pointer to the udp instance context data.\r
+  @param[in]  Udp4Session        Pointer to the EFI_UDP4_SESSION_DATA abstracted\r
+                                 from the received udp datagram.\r
+\r
+  @retval TRUE       The udp datagram matches the receiving requirments of the\r
+                     udp Instance.\r
+  @retval FALSE      Otherwise.\r
+\r
+**/\r
 BOOLEAN\r
 Udp4MatchDgram (\r
   IN UDP4_INSTANCE_DATA     *Instance,\r
   IN EFI_UDP4_SESSION_DATA  *Udp4Session\r
   );\r
 \r
+/**\r
+  This function removes the Wrap specified by Context and release relevant resources.\r
+\r
+  @param[in]  Event              The Event this notify function registered to.\r
+  @param[in]  Context            Pointer to the context data.\r
+\r
+**/\r
 VOID\r
 EFIAPI\r
 Udp4RecycleRxDataWrap (\r
@@ -76,6 +144,18 @@ Udp4RecycleRxDataWrap (
   IN VOID       *Context\r
   );\r
 \r
+/**\r
+  This function wraps the Packet and the RxData.\r
+\r
+  @param[in]  Instance               Pointer to the instance context data.\r
+  @param[in]  Packet                 Pointer to the buffer containing the received\r
+                                     datagram.\r
+  @param[in]  RxData                 Pointer to the EFI_UDP4_RECEIVE_DATA of this\r
+                                     datagram.\r
+\r
+  @return Pointer to the structure wrapping the RxData and the Packet.\r
+\r
+**/\r
 UDP4_RXDATA_WRAP *\r
 Udp4WrapRxData (\r
   IN UDP4_INSTANCE_DATA     *Instance,\r
@@ -83,6 +163,18 @@ Udp4WrapRxData (
   IN EFI_UDP4_RECEIVE_DATA  *RxData\r
   );\r
 \r
+/**\r
+  This function enqueues the received datagram into the instances' receiving queues.\r
+\r
+  @param[in]  Udp4Service            Pointer to the udp service context data.\r
+  @param[in]  Packet                 Pointer to the buffer containing the received\r
+                                     datagram.\r
+  @param[in]  RxData                 Pointer to the EFI_UDP4_RECEIVE_DATA of this\r
+                                     datagram.\r
+\r
+  @return The times this datagram is enqueued.\r
+\r
+**/\r
 UINTN\r
 Udp4EnqueueDgram (\r
   IN UDP4_SERVICE_DATA      *Udp4Service,\r
@@ -90,11 +182,27 @@ Udp4EnqueueDgram (
   IN EFI_UDP4_RECEIVE_DATA  *RxData\r
   );\r
 \r
+/**\r
+  This function delivers the datagrams enqueued in the instances.\r
+\r
+  @param[in]  Udp4Service            Pointer to the udp service context data.\r
+\r
+**/\r
 VOID\r
 Udp4DeliverDgram (\r
   IN UDP4_SERVICE_DATA  *Udp4Service\r
   );\r
 \r
+/**\r
+  This function demultiplexes the received udp datagram to the appropriate instances.\r
+\r
+  @param[in]  Udp4Service            Pointer to the udp service context data.\r
+  @param[in]  NetSession             Pointer to the EFI_NET_SESSION_DATA abstracted from\r
+                                     the received datagram.\r
+  @param[in]  Packet                 Pointer to the buffer containing the received udp\r
+                                     datagram.\r
+\r
+**/\r
 VOID\r
 Udp4Demultiplex (\r
   IN UDP4_SERVICE_DATA     *Udp4Service,\r
@@ -102,14 +210,35 @@ Udp4Demultiplex (
   IN NET_BUF               *Packet\r
   );\r
 \r
+/**\r
+  This function handles the received Icmp Error message and demultiplexes it to the\r
+  instance.\r
+\r
+  @param[in]  Udp4Service            Pointer to the udp service context data.\r
+  @param[in]  IcmpError              The icmp error code.\r
+  @param[in]  NetSession             Pointer to the EFI_NET_SESSION_DATA abstracted\r
+                                 from the received Icmp Error packet.\r
+  @param[in]  Packet                 Pointer to the Icmp Error packet.\r
+\r
+**/\r
 VOID\r
 Udp4IcmpHandler (\r
   IN UDP4_SERVICE_DATA     *Udp4Service,\r
-  IN ICMP_ERROR            IcmpError,\r
+  IN UINT8                 IcmpError,\r
   IN EFI_NET_SESSION_DATA  *NetSession,\r
   IN NET_BUF               *Packet\r
   );\r
 \r
+/**\r
+  This function builds and sends out a icmp port unreachable message.\r
+\r
+  @param[in]  IpIo                   Pointer to the IP_IO instance.\r
+  @param[in]  NetSession             Pointer to the EFI_NET_SESSION_DATA of the packet\r
+                                     causes this icmp error message.\r
+  @param[in]  Udp4Header             Pointer to the udp header of the datagram causes\r
+                                     this icmp error message.\r
+\r
+**/\r
 VOID\r
 Udp4SendPortUnreach (\r
   IN IP_IO                 *IpIo,\r
@@ -121,14 +250,14 @@ Udp4SendPortUnreach (
 /**\r
   Create the Udp service context data.\r
 \r
-  @param  Udp4Service            Pointer to the UDP4_SERVICE_DATA.\r
-  @param  ImageHandle            The image handle of this udp4 driver.\r
-  @param  ControllerHandle       The controller handle this udp4 driver binds on.\r
+  @param[in, out] Udp4Service      Pointer to the UDP4_SERVICE_DATA.\r
+  @param[in]      ImageHandle      The image handle of this udp4 driver.\r
+  @param[in]      ControllerHandle The controller handle this udp4 driver binds on.\r
 \r
-  @retval EFI_SUCCESS            The udp4 service context data is created and\r
-                                 initialized.\r
-  @retval EFI_OUT_OF_RESOURCES   Cannot allocate memory.\r
-  @retval other                  Other error occurs.\r
+  @retval EFI_SUCCESS              The udp4 service context data is created and\r
+                                   initialized.\r
+  @retval EFI_OUT_OF_RESOURCES     Cannot allocate memory.\r
+  @retval other                    Other error occurs.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -138,8 +267,9 @@ Udp4CreateService (
   IN     EFI_HANDLE         ControllerHandle\r
   )\r
 {\r
-  EFI_STATUS       Status;\r
-  IP_IO_OPEN_DATA  OpenData;\r
+  EFI_STATUS          Status;\r
+  IP_IO_OPEN_DATA     OpenData;\r
+  EFI_IP4_CONFIG_DATA *Ip4ConfigData;\r
 \r
   ZeroMem (Udp4Service, sizeof (UDP4_SERVICE_DATA));\r
 \r
@@ -154,7 +284,7 @@ Udp4CreateService (
   //\r
   // Create the IpIo for this service context.\r
   //\r
-  Udp4Service->IpIo = IpIoCreate (ImageHandle, ControllerHandle);\r
+  Udp4Service->IpIo = IpIoCreate (ImageHandle, ControllerHandle, IP_VERSION_4);\r
   if (Udp4Service->IpIo == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
@@ -162,12 +292,13 @@ Udp4CreateService (
   //\r
   // Set the OpenData used to open the IpIo.\r
   //\r
-  CopyMem (&OpenData.IpConfigData, &mIpIoDefaultIpConfigData, sizeof (OpenData.IpConfigData));\r
-  OpenData.IpConfigData.AcceptBroadcast = TRUE;\r
-  OpenData.RcvdContext                  = (VOID *) Udp4Service;\r
-  OpenData.SndContext                   = NULL;\r
-  OpenData.PktRcvdNotify                = Udp4DgramRcvd;\r
-  OpenData.PktSentNotify                = Udp4DgramSent;\r
+  Ip4ConfigData = &OpenData.IpConfigData.Ip4CfgData;\r
+  CopyMem (Ip4ConfigData, &mIp4IoDefaultIpConfigData, sizeof (EFI_IP4_CONFIG_DATA));\r
+  Ip4ConfigData->AcceptBroadcast = TRUE;\r
+  OpenData.RcvdContext           = (VOID *) Udp4Service;\r
+  OpenData.SndContext            = NULL;\r
+  OpenData.PktRcvdNotify         = Udp4DgramRcvd;\r
+  OpenData.PktSentNotify         = Udp4DgramSent;\r
 \r
   //\r
   // Configure and start the IpIo.\r
@@ -220,9 +351,7 @@ ON_ERROR:
 /**\r
   Clean the Udp service context data.\r
 \r
-  @param  Udp4Service            Pointer to the UDP4_SERVICE_DATA.\r
-\r
-  @return None.\r
+  @param[in]  Udp4Service            Pointer to the UDP4_SERVICE_DATA.\r
 \r
 **/\r
 VOID\r
@@ -251,11 +380,9 @@ Udp4CleanService (
   This function checks and timeouts the I/O datagrams holding by the corresponding\r
   service context.\r
 \r
-  @param  Event                  The event this function registered to.\r
-  @param  Context                The context data registered during the creation of\r
-                                 the Event.\r
-\r
-  @return None.\r
+  @param[in]  Event                  The event this function registered to.\r
+  @param[in]  Context                The context data registered during the creation of\r
+                                     the Event.\r
 \r
 **/\r
 VOID\r
@@ -295,13 +422,16 @@ Udp4CheckTimeout (
       //\r
       Wrap = NET_LIST_USER_STRUCT (WrapEntry, UDP4_RXDATA_WRAP, Link);\r
 \r
-      if (Wrap->TimeoutTick <= UDP4_TIMEOUT_INTERVAL / 1000) {\r
+      //\r
+      // TimeoutTick unit is microsecond, MNP_TIMEOUT_CHECK_INTERVAL unit is 100ns.\r
+      //\r
+      if (Wrap->TimeoutTick < (UDP4_TIMEOUT_INTERVAL / 10)) {\r
         //\r
         // Remove this RxData if it timeouts.\r
         //\r
         Udp4RecycleRxDataWrap (NULL, (VOID *) Wrap);\r
       } else {\r
-        Wrap->TimeoutTick -= UDP4_TIMEOUT_INTERVAL / 1000;\r
+        Wrap->TimeoutTick -= (UDP4_TIMEOUT_INTERVAL / 10);\r
       }\r
     }\r
   }\r
@@ -311,10 +441,8 @@ Udp4CheckTimeout (
 /**\r
   This function intializes the new created udp instance.\r
 \r
-  @param  Udp4Service            Pointer to the UDP4_SERVICE_DATA.\r
-  @param  Instance               Pointer to the un-initialized UDP4_INSTANCE_DATA.\r
-\r
-  @return None.\r
+  @param[in]      Udp4Service       Pointer to the UDP4_SERVICE_DATA.\r
+  @param[in, out] Instance          Pointer to the un-initialized UDP4_INSTANCE_DATA.\r
 \r
 **/\r
 VOID\r
@@ -350,16 +478,14 @@ Udp4InitInstance (
   Instance->IcmpError   = EFI_SUCCESS;\r
   Instance->Configured  = FALSE;\r
   Instance->IsNoMapping = FALSE;\r
-  Instance->Destroyed   = FALSE;\r
+  Instance->InDestroy   = FALSE;\r
 }\r
 \r
 \r
 /**\r
   This function cleans the udp instance.\r
 \r
-  @param  Instance               Pointer to the UDP4_INSTANCE_DATA to clean.\r
-\r
-  @return None.\r
+  @param[in]  Instance               Pointer to the UDP4_INSTANCE_DATA to clean.\r
 \r
 **/\r
 VOID\r
@@ -376,10 +502,10 @@ Udp4CleanInstance (
 /**\r
   This function finds the udp instance by the specified <Address, Port> pair.\r
 \r
-  @param  InstanceList           Pointer to the head of the list linking the udp\r
-                                 instances.\r
-  @param  Address                Pointer to the specified IPv4 address.\r
-  @param  Port                   The udp port number.\r
+  @param[in]  InstanceList           Pointer to the head of the list linking the udp\r
+                                     instances.\r
+  @param[in]  Address                Pointer to the specified IPv4 address.\r
+  @param[in]  Port                   The udp port number.\r
 \r
   @retval TRUE     The specified <Address, Port> pair is found.\r
   @retval FALSE    Otherwise.\r
@@ -431,9 +557,9 @@ Udp4FindInstanceByPort (
   This function tries to bind the udp instance according to the configured port\r
   allocation strategy.\r
 \r
-  @param  InstanceList           Pointer to the head of the list linking the udp\r
+  @param[in]      InstanceList   Pointer to the head of the list linking the udp\r
                                  instances.\r
-  @param  ConfigData             Pointer to the ConfigData of the instance to be\r
+  @param[in, out] ConfigData     Pointer to the ConfigData of the instance to be\r
                                  bound. ConfigData->StationPort will be assigned\r
                                  with an available port value on success.\r
 \r
@@ -513,9 +639,9 @@ Udp4Bind (
   This function is used to check whether the NewConfigData has any un-reconfigurable\r
   parameters changed compared to the OldConfigData.\r
 \r
-  @param  OldConfigData          Pointer to the current ConfigData the udp instance\r
+  @param[in]  OldConfigData      Pointer to the current ConfigData the udp instance\r
                                  uses.\r
-  @param  NewConfigData          Pointer to the new ConfigData.\r
+  @param[in]  NewConfigData      Pointer to the new ConfigData.\r
 \r
   @retval TRUE     The instance is reconfigurable.\r
   @retval FALSE    Otherwise.\r
@@ -594,10 +720,8 @@ Udp4IsReconfigurable (
 /**\r
   This function builds the Ip4 configdata from the Udp4ConfigData.\r
 \r
-  @param  Udp4ConfigData         Pointer to the EFI_UDP4_CONFIG_DATA.\r
-  @param  Ip4ConfigData          Pointer to the EFI_IP4_CONFIG_DATA.\r
-\r
-  @return None.\r
+  @param[in]       Udp4ConfigData    Pointer to the EFI_UDP4_CONFIG_DATA.\r
+  @param[in, out]  Ip4ConfigData     Pointer to the EFI_IP4_CONFIG_DATA.\r
 \r
 **/\r
 VOID\r
@@ -606,7 +730,7 @@ Udp4BuildIp4ConfigData (
   IN OUT EFI_IP4_CONFIG_DATA   *Ip4ConfigData\r
   )\r
 {\r
-  CopyMem (Ip4ConfigData, &mIpIoDefaultIpConfigData, sizeof (*Ip4ConfigData));\r
+  CopyMem (Ip4ConfigData, &mIp4IoDefaultIpConfigData, sizeof (*Ip4ConfigData));\r
 \r
   Ip4ConfigData->DefaultProtocol   = EFI_IP_PROTO_UDP;\r
   Ip4ConfigData->AcceptBroadcast   = Udp4ConfigData->AcceptBroadcast;\r
@@ -625,8 +749,8 @@ Udp4BuildIp4ConfigData (
 /**\r
   This function validates the TxToken, it returns the error code according to the spec.\r
 \r
-  @param  Instance               Pointer to the udp instance context data.\r
-  @param  TxToken                Pointer to the token to be checked.\r
+  @param[in]  Instance           Pointer to the udp instance context data.\r
+  @param[in]  TxToken            Pointer to the token to be checked.\r
 \r
   @retval EFI_SUCCESS            The TxToken is valid.\r
   @retval EFI_INVALID_PARAMETER  One or more of the following are TRUE: This is\r
@@ -697,7 +821,9 @@ Udp4ValidateTxToken (
   if (TxData->GatewayAddress != NULL) {\r
     CopyMem (&GatewayAddress, TxData->GatewayAddress, sizeof (IP4_ADDR));\r
 \r
-    if (!Ip4IsUnicast (NTOHL (GatewayAddress), 0)) {\r
+    if (!Instance->ConfigData.UseDefaultAddress &&\r
+        (EFI_NTOHL(Instance->ConfigData.SubnetMask) != 0) &&\r
+        !NetIp4IsUnicast (NTOHL (GatewayAddress), EFI_NTOHL(Instance->ConfigData.SubnetMask))) {\r
       //\r
       // The specified GatewayAddress is not a unicast IPv4 address while it's not 0.\r
       //\r
@@ -712,7 +838,10 @@ Udp4ValidateTxToken (
 \r
     CopyMem (&SourceAddress, &UdpSessionData->SourceAddress, sizeof (IP4_ADDR));\r
 \r
-    if ((SourceAddress != 0) && !Ip4IsUnicast (HTONL (SourceAddress), 0)) {\r
+    if ((SourceAddress != 0) &&\r
+        !Instance->ConfigData.UseDefaultAddress &&\r
+        (EFI_NTOHL(Instance->ConfigData.SubnetMask) != 0) &&\r
+        !NetIp4IsUnicast (HTONL (SourceAddress), EFI_NTOHL(Instance->ConfigData.SubnetMask))) {\r
       //\r
       // Check whether SourceAddress is a valid IPv4 address in case it's not zero.\r
       // The configured station address is used if SourceAddress is zero.\r
@@ -752,10 +881,10 @@ Udp4ValidateTxToken (
 /**\r
   This function checks whether the specified Token duplicates with the one in the Map.\r
 \r
-  @param  Map                    Pointer to the NET_MAP.\r
-  @param  Item                   Pointer to the NET_MAP_ITEM contain the pointer to\r
+  @param[in]  Map                Pointer to the NET_MAP.\r
+  @param[in]  Item               Pointer to the NET_MAP_ITEM contain the pointer to\r
                                  the Token.\r
-  @param  Context                Pointer to the Token to be checked.\r
+  @param[in]  Context            Pointer to the Token to be checked.\r
 \r
   @retval EFI_SUCCESS            The Token specified by Context differs from the\r
                                  one in the Item.\r
@@ -763,6 +892,7 @@ Udp4ValidateTxToken (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 Udp4TokenExist (\r
   IN NET_MAP       *Map,\r
   IN NET_MAP_ITEM  *Item,\r
@@ -791,11 +921,11 @@ Udp4TokenExist (
   This function calculates the checksum for the Packet, utilizing the pre-calculated\r
   pseudo HeadSum to reduce some overhead.\r
 \r
-  @param  Packet                 Pointer to the NET_BUF contains the udp datagram.\r
-  @param  HeadSum                Checksum of the pseudo header execpt the length\r
+  @param[in]  Packet             Pointer to the NET_BUF contains the udp datagram.\r
+  @param[in]  HeadSum            Checksum of the pseudo header execpt the length\r
                                  field.\r
 \r
-  @return The 16-bit checksum of this udp datagram.\r
+  @retval The 16-bit checksum of this udp datagram.\r
 \r
 **/\r
 UINT16\r
@@ -818,8 +948,8 @@ Udp4Checksum (
 /**\r
   This function removes the specified Token from the TokenMap.\r
 \r
-  @param  TokenMap               Pointer to the NET_MAP containing the tokens.\r
-  @param  Token                  Pointer to the Token to be removed.\r
+  @param[in, out] TokenMap       Pointer to the NET_MAP containing the tokens.\r
+  @param[in]      Token          Pointer to the Token to be removed.\r
 \r
   @retval EFI_SUCCESS            The specified Token is removed from the TokenMap.\r
   @retval EFI_NOT_FOUND          The specified Token is not found in the TokenMap.\r
@@ -856,20 +986,19 @@ Udp4RemoveToken (
   interface. It's called to signal the udp TxToken when IpIo layer completes the\r
   transmitting of the udp datagram.\r
 \r
-  @param  Status                 The completion status of the output udp datagram.\r
-  @param  Context                Pointer to the context data.\r
-  @param  Sender                 Pointer to the Ip sender of the udp datagram.\r
-  @param  NotifyData             Pointer to the notify data.\r
-\r
-  @return None.\r
+  @param[in]  Status                 The completion status of the output udp datagram.\r
+  @param[in]  Context                Pointer to the context data.\r
+  @param[in]  Sender                 Specify a pointer of EFI_IP4_PROTOCOL for sending.\r
+  @param[in]  NotifyData             Pointer to the notify data.\r
 \r
 **/\r
 VOID\r
+EFIAPI\r
 Udp4DgramSent (\r
-  IN EFI_STATUS  Status,\r
-  IN VOID        *Context,\r
-  IN VOID        *Sender,\r
-  IN VOID        *NotifyData\r
+  IN EFI_STATUS        Status,\r
+  IN VOID              *Context,\r
+  IN IP_IO_IP_PROTOCOL Sender,\r
+  IN VOID              *NotifyData\r
   )\r
 {\r
   UDP4_INSTANCE_DATA         *Instance;\r
@@ -884,7 +1013,7 @@ Udp4DgramSent (
     //\r
     Token->Status = Status;\r
     gBS->SignalEvent (Token->Event);\r
-    NetLibDispatchDpc ();\r
+    DispatchDpc ();\r
   }\r
 }\r
 \r
@@ -892,21 +1021,20 @@ Udp4DgramSent (
 /**\r
   This function processes the received datagram passed up by the IpIo layer.\r
 \r
-  @param  Status                 The status of this udp datagram.\r
-  @param  IcmpError              The IcmpError code, only available when Status is\r
+  @param[in]  Status             The status of this udp datagram.\r
+  @param[in]  IcmpError          The IcmpError code, only available when Status is\r
                                  EFI_ICMP_ERROR.\r
-  @param  NetSession             Pointer to the EFI_NET_SESSION_DATA.\r
-  @param  Packet                 Pointer to the NET_BUF containing the received udp\r
+  @param[in]  NetSession         Pointer to the EFI_NET_SESSION_DATA.\r
+  @param[in]  Packet             Pointer to the NET_BUF containing the received udp\r
                                  datagram.\r
-  @param  Context                Pointer to the context data.\r
-\r
-  @return None.\r
+  @param[in]  Context            Pointer to the context data.\r
 \r
 **/\r
 VOID\r
+EFIAPI\r
 Udp4DgramRcvd (\r
   IN EFI_STATUS            Status,\r
-  IN ICMP_ERROR            IcmpError,\r
+  IN UINT8                 IcmpError,\r
   IN EFI_NET_SESSION_DATA  *NetSession,\r
   IN NET_BUF               *Packet,\r
   IN VOID                  *Context\r
@@ -933,16 +1061,16 @@ Udp4DgramRcvd (
   // Dispatch the DPC queued by the NotifyFunction of the rx token's events\r
   // which are signaled with received data.\r
   //\r
-  NetLibDispatchDpc ();\r
+  DispatchDpc ();\r
 }\r
 \r
 \r
 /**\r
   This function removes the multicast group specified by Arg from the Map.\r
 \r
-  @param  Map                    Pointer to the NET_MAP.\r
-  @param  Item                   Pointer to the NET_MAP_ITEM.\r
-  @param  Arg                    Pointer to the Arg, it's the pointer to a\r
+  @param[in, out] Map            Pointer to the NET_MAP.\r
+  @param[in]      Item           Pointer to the NET_MAP_ITEM.\r
+  @param[in]      Arg            Pointer to the Arg, it's the pointer to a\r
                                  multicast IPv4 Address.\r
 \r
   @retval EFI_SUCCESS            The multicast address is removed.\r
@@ -951,6 +1079,7 @@ Udp4DgramRcvd (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 Udp4LeaveGroup (\r
   IN OUT NET_MAP       *Map,\r
   IN     NET_MAP_ITEM  *Item,\r
@@ -989,9 +1118,9 @@ Udp4LeaveGroup (
   This function cancels the token specified by Arg in the Map. This is a callback\r
   used by Udp4InstanceCancelToken().\r
 \r
-  @param  Map                    Pointer to the NET_MAP.\r
-  @param  Item                   Pointer to the NET_MAP_ITEM.\r
-  @param  Arg                    Pointer to the token to be cancelled, if NULL,\r
+  @param[in]  Map                Pointer to the NET_MAP.\r
+  @param[in]  Item               Pointer to the NET_MAP_ITEM.\r
+  @param[in]  Arg                Pointer to the token to be cancelled, if NULL,\r
                                  the token specified by Item is cancelled.\r
 \r
   @retval EFI_SUCCESS            The token is cancelled if Arg is NULL or the token\r
@@ -1002,6 +1131,7 @@ Udp4LeaveGroup (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 Udp4CancelTokens (\r
   IN NET_MAP       *Map,\r
   IN NET_MAP_ITEM  *Item,\r
@@ -1049,9 +1179,7 @@ Udp4CancelTokens (
 /**\r
   This function removes all the Wrap datas in the RcvdDgramQue.\r
 \r
-  @param  Instance           Pointer to the udp instance context data.\r
-\r
-  @return None.\r
+  @param[in]  Instance           Pointer to the udp instance context data.\r
 \r
 **/\r
 VOID\r
@@ -1079,8 +1207,8 @@ Udp4FlushRcvdDgram (
 /**\r
   Cancel Udp4 tokens from the Udp4 instance.\r
 \r
-  @param  Instance               Pointer to the udp instance context data.\r
-  @param  Token                  Pointer to the token to be canceled, if NULL, all\r
+  @param[in]  Instance           Pointer to the udp instance context data.\r
+  @param[in]  Token              Pointer to the token to be canceled, if NULL, all\r
                                  tokens in this instance will be cancelled.\r
 \r
   @retval EFI_SUCCESS            The Token is cancelled.\r
@@ -1132,8 +1260,8 @@ Udp4InstanceCancelToken (
 /**\r
   This function matches the received udp datagram with the Instance.\r
 \r
-  @param  Instance               Pointer to the udp instance context data.\r
-  @param  Udp4Session            Pointer to the EFI_UDP4_SESSION_DATA abstracted\r
+  @param[in]  Instance           Pointer to the udp instance context data.\r
+  @param[in]  Udp4Session        Pointer to the EFI_UDP4_SESSION_DATA abstracted\r
                                  from the received udp datagram.\r
 \r
   @retval TRUE       The udp datagram matches the receiving requirments of the\r
@@ -1212,10 +1340,8 @@ Udp4MatchDgram (
 /**\r
   This function removes the Wrap specified by Context and release relevant resources.\r
 \r
-  @param  Event                  The Event this notify function registered to.\r
-  @param  Context                Pointer to the context data.\r
-\r
-  @return None.\r
+  @param[in]  Event              The Event this notify function registered to.\r
+  @param[in]  Context            Pointer to the context data.\r
 \r
 **/\r
 VOID\r
@@ -1244,18 +1370,18 @@ Udp4RecycleRxDataWrap (
   //\r
   gBS->CloseEvent (Wrap->RxData.RecycleSignal);\r
 \r
-  gBS->FreePool (Wrap);\r
+  FreePool (Wrap);\r
 }\r
 \r
 \r
 /**\r
   This function wraps the Packet and the RxData.\r
 \r
-  @param  Instance               Pointer to the instance context data.\r
-  @param  Packet                 Pointer to the buffer containing the received\r
-                                 datagram.\r
-  @param  RxData                 Pointer to the EFI_UDP4_RECEIVE_DATA of this\r
-                                 datagram.\r
+  @param[in]  Instance               Pointer to the instance context data.\r
+  @param[in]  Packet                 Pointer to the buffer containing the received\r
+                                     datagram.\r
+  @param[in]  RxData                 Pointer to the EFI_UDP4_RECEIVE_DATA of this\r
+                                     datagram.\r
 \r
   @return Pointer to the structure wrapping the RxData and the Packet.\r
 \r
@@ -1294,7 +1420,7 @@ Udp4WrapRxData (
                   &Wrap->RxData.RecycleSignal\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    gBS->FreePool (Wrap);\r
+    FreePool (Wrap);\r
     return NULL;\r
   }\r
 \r
@@ -1308,11 +1434,11 @@ Udp4WrapRxData (
 /**\r
   This function enqueues the received datagram into the instances' receiving queues.\r
 \r
-  @param  Udp4Service            Pointer to the udp service context data.\r
-  @param  Packet                 Pointer to the buffer containing the received\r
-                                 datagram.\r
-  @param  RxData                 Pointer to the EFI_UDP4_RECEIVE_DATA of this\r
-                                 datagram.\r
+  @param[in]  Udp4Service            Pointer to the udp service context data.\r
+  @param[in]  Packet                 Pointer to the buffer containing the received\r
+                                     datagram.\r
+  @param[in]  RxData                 Pointer to the EFI_UDP4_RECEIVE_DATA of this\r
+                                     datagram.\r
 \r
   @return The times this datagram is enqueued.\r
 \r
@@ -1365,9 +1491,7 @@ Udp4EnqueueDgram (
 /**\r
   This function delivers the received datagrams for the specified instance.\r
 \r
-  @param  Instance               Pointer to the instance context data.\r
-\r
-  @return None.\r
+  @param[in]  Instance               Pointer to the instance context data.\r
 \r
 **/\r
 VOID\r
@@ -1431,9 +1555,7 @@ Udp4InstanceDeliverDgram (
 /**\r
   This function delivers the datagrams enqueued in the instances.\r
 \r
-  @param  Udp4Service            Pointer to the udp service context data.\r
-\r
-  @return None.\r
+  @param[in]  Udp4Service            Pointer to the udp service context data.\r
 \r
 **/\r
 VOID\r
@@ -1463,15 +1585,13 @@ Udp4DeliverDgram (
 \r
 \r
 /**\r
-  This function demultiplexes the received udp datagram to the apropriate instances.\r
-\r
-  @param  Udp4Service            Pointer to the udp service context data.\r
-  @param  NetSession             Pointer to the EFI_NET_SESSION_DATA abstrated from\r
-                                 the received datagram.\r
-  @param  Packet                 Pointer to the buffer containing the received udp\r
-                                 datagram.\r
+  This function demultiplexes the received udp datagram to the appropriate instances.\r
 \r
-  @return None.\r
+  @param[in]  Udp4Service            Pointer to the udp service context data.\r
+  @param[in]  NetSession             Pointer to the EFI_NET_SESSION_DATA abstracted from\r
+                                     the received datagram.\r
+  @param[in]  Packet                 Pointer to the buffer containing the received udp\r
+                                     datagram.\r
 \r
 **/\r
 VOID\r
@@ -1481,24 +1601,30 @@ Udp4Demultiplex (
   IN NET_BUF               *Packet\r
   )\r
 {\r
-  EFI_UDP4_HEADER        *Udp4Header;\r
+  EFI_UDP_HEADER        *Udp4Header;\r
   UINT16                 HeadSum;\r
   EFI_UDP4_RECEIVE_DATA  RxData;\r
   EFI_UDP4_SESSION_DATA  *Udp4Session;\r
   UINTN                  Enqueued;\r
 \r
+  if (Packet->TotalSize < sizeof (EFI_UDP_HEADER)) {\r
+    NetbufFree (Packet);\r
+    return;\r
+  }\r
+\r
   //\r
   // Get the datagram header from the packet buffer.\r
   //\r
-  Udp4Header = (EFI_UDP4_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
+  Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
+  ASSERT (Udp4Header != NULL);\r
 \r
   if (Udp4Header->Checksum != 0) {\r
     //\r
     // check the checksum.\r
     //\r
     HeadSum = NetPseudoHeadChecksum (\r
-                NetSession->Source,\r
-                NetSession->Dest,\r
+                NetSession->Source.Addr[0],\r
+                NetSession->Dest.Addr[0],\r
                 EFI_IP_PROTO_UDP,\r
                 0\r
                 );\r
@@ -1507,12 +1633,11 @@ Udp4Demultiplex (
       //\r
       // Wrong checksum.\r
       //\r
+      NetbufFree (Packet);\r
       return;\r
     }\r
   }\r
 \r
-  gRT->GetTime (&RxData.TimeStamp, NULL);\r
-\r
   Udp4Session                  = &RxData.UdpSession;\r
   Udp4Session->SourcePort      = NTOHS (Udp4Header->SrcPort);\r
   Udp4Session->DestinationPort = NTOHS (Udp4Header->DstPort);\r
@@ -1556,13 +1681,11 @@ Udp4Demultiplex (
 /**\r
   This function builds and sends out a icmp port unreachable message.\r
 \r
-  @param  IpIo                   Pointer to the IP_IO instance.\r
-  @param  NetSession             Pointer to the EFI_NET_SESSION_DATA of the packet\r
-                                 causes this icmp error message.\r
-  @param  Udp4Header             Pointer to the udp header of the datagram causes\r
-                                 this icmp error message.\r
-\r
-  @return None.\r
+  @param[in]  IpIo                   Pointer to the IP_IO instance.\r
+  @param[in]  NetSession             Pointer to the EFI_NET_SESSION_DATA of the packet\r
+                                     causes this icmp error message.\r
+  @param[in]  Udp4Header             Pointer to the udp header of the datagram causes\r
+                                     this icmp error message.\r
 \r
 **/\r
 VOID\r
@@ -1580,19 +1703,19 @@ Udp4SendPortUnreach (
   IP_IO_OVERRIDE       Override;\r
   IP_IO_IP_INFO        *IpSender;\r
 \r
-  IpSender = IpIoFindSender (&IpIo, NetSession->Dest);\r
+  IpSender = IpIoFindSender (&IpIo, NetSession->IpVersion, &NetSession->Dest);\r
   if (IpSender == NULL) {\r
     //\r
-    // No apropriate sender, since we cannot send out the ICMP message through\r
+    // No appropriate sender, since we cannot send out the ICMP message through\r
     // the default zero station address IP instance, abort.\r
     //\r
     return;\r
   }\r
 \r
-  IpHdr = NetSession->IpHdr;\r
+  IpHdr = NetSession->IpHdr.Ip4Hdr;\r
 \r
   //\r
-  // Calculate the requried length of the icmp error message.\r
+  // Calculate the required length of the icmp error message.\r
   //\r
   Len = sizeof (IP4_ICMP_ERROR_HEAD) + (EFI_IP4_HEADER_LEN (IpHdr) -\r
         sizeof (IP4_HEAD)) + ICMP_ERROR_PACKET_LENGTH;\r
@@ -1609,6 +1732,7 @@ Udp4SendPortUnreach (
   // Allocate space for the IP4_ICMP_ERROR_HEAD.\r
   //\r
   IcmpErrHdr = (IP4_ICMP_ERROR_HEAD *) NetbufAllocSpace (Packet, Len, FALSE);\r
+  ASSERT (IcmpErrHdr != NULL);\r
 \r
   //\r
   // Set the required fields for the icmp port unreachable message.\r
@@ -1637,18 +1761,18 @@ Udp4SendPortUnreach (
   //\r
   // Fill the override data.\r
   //\r
-  Override.DoNotFragment = FALSE;\r
-  Override.TypeOfService = 0;\r
-  Override.TimeToLive    = 255;\r
-  Override.Protocol      = EFI_IP_PROTO_ICMP;\r
+  Override.Ip4OverrideData.DoNotFragment = FALSE;\r
+  Override.Ip4OverrideData.TypeOfService = 0;\r
+  Override.Ip4OverrideData.TimeToLive    = 255;\r
+  Override.Ip4OverrideData.Protocol      = EFI_IP_PROTO_ICMP;\r
 \r
-  CopyMem (&Override.SourceAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS));\r
-  ZeroMem (&Override.GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r
+  CopyMem (&Override.Ip4OverrideData.SourceAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS));\r
+  ZeroMem (&Override.Ip4OverrideData.GatewayAddress, sizeof (EFI_IPv4_ADDRESS));\r
 \r
   //\r
   // Send out this icmp packet.\r
   //\r
-  IpIoSend (IpIo, Packet, IpSender, NULL, NULL, NetSession->Source, &Override);\r
+  IpIoSend (IpIo, Packet, IpSender, NULL, NULL, &NetSession->Source, &Override);\r
 \r
   NetbufFree (Packet);\r
 }\r
@@ -1658,29 +1782,33 @@ Udp4SendPortUnreach (
   This function handles the received Icmp Error message and demultiplexes it to the\r
   instance.\r
 \r
-  @param  Udp4Service            Pointer to the udp service context data.\r
-  @param  IcmpError              The icmp error code.\r
-  @param  NetSession             Pointer to the EFI_NET_SESSION_DATA abstracted\r
+  @param[in]  Udp4Service            Pointer to the udp service context data.\r
+  @param[in]  IcmpError              The icmp error code.\r
+  @param[in]  NetSession             Pointer to the EFI_NET_SESSION_DATA abstracted\r
                                  from the received Icmp Error packet.\r
-  @param  Packet                 Pointer to the Icmp Error packet.\r
-\r
-  @return None.\r
+  @param[in]  Packet                 Pointer to the Icmp Error packet.\r
 \r
 **/\r
 VOID\r
 Udp4IcmpHandler (\r
   IN UDP4_SERVICE_DATA     *Udp4Service,\r
-  IN ICMP_ERROR            IcmpError,\r
+  IN UINT8                 IcmpError,\r
   IN EFI_NET_SESSION_DATA  *NetSession,\r
   IN NET_BUF               *Packet\r
   )\r
 {\r
-  EFI_UDP4_HEADER        *Udp4Header;\r
+  EFI_UDP_HEADER        *Udp4Header;\r
   EFI_UDP4_SESSION_DATA  Udp4Session;\r
   LIST_ENTRY             *Entry;\r
   UDP4_INSTANCE_DATA     *Instance;\r
 \r
-  Udp4Header = (EFI_UDP4_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
+  if (Packet->TotalSize < sizeof (EFI_UDP_HEADER)) {\r
+    NetbufFree (Packet);\r
+    return;\r
+  }\r
+\r
+  Udp4Header = (EFI_UDP_HEADER *) NetbufGetByte (Packet, 0, NULL);\r
+  ASSERT (Udp4Header != NULL);\r
 \r
   CopyMem (&Udp4Session.SourceAddress, &NetSession->Source, sizeof (EFI_IPv4_ADDRESS));\r
   CopyMem (&Udp4Session.DestinationAddress, &NetSession->Dest, sizeof (EFI_IPv4_ADDRESS));\r
@@ -1694,16 +1822,7 @@ Udp4IcmpHandler (
     //\r
     Instance = NET_LIST_USER_STRUCT (Entry, UDP4_INSTANCE_DATA, Link);\r
 \r
-    if (!Instance->Configured ||\r
-        Instance->ConfigData.AcceptPromiscuous ||\r
-        Instance->ConfigData.AcceptAnyPort ||\r
-        EFI_IP4_EQUAL (&Instance->ConfigData.StationAddress, &mZeroIp4Addr)\r
-        ) {\r
-      //\r
-      // Don't try to deliver the ICMP error to this instance if it is not configured,\r
-      // or it's configured to be promiscuous or accept any port or accept all the\r
-      // datagrams.\r
-      //\r
+    if (!Instance->Configured) {\r
       continue;\r
     }\r
 \r
@@ -1711,7 +1830,7 @@ Udp4IcmpHandler (
       //\r
       // Translate the Icmp Error code according to the udp spec.\r
       //\r
-      Instance->IcmpError = IpIoGetIcmpErrStatus (IcmpError, NULL, NULL);\r
+      Instance->IcmpError = IpIoGetIcmpErrStatus (IcmpError, IP_VERSION_4, NULL, NULL);\r
 \r
       if (IcmpError > ICMP_ERR_UNREACH_PORT) {\r
         Instance->IcmpError = EFI_ICMP_ERROR;\r
@@ -1733,9 +1852,7 @@ Udp4IcmpHandler (
 /**\r
   This function reports the received ICMP error.\r
 \r
-  @param  Instance               Pointer to the udp instance context data.\r
-\r
-  @return None.\r
+  @param[in]  Instance               Pointer to the udp instance context data.\r
 \r
 **/\r
 VOID\r
@@ -1778,178 +1895,14 @@ Udp4ReportIcmpError (
   This function is a dummy ext-free function for the NET_BUF created for the output\r
   udp datagram.\r
 \r
-  @param  Context                Pointer to the context data.\r
-\r
-  @return None.\r
+  @param[in]  Context                Pointer to the context data.\r
 \r
 **/\r
 VOID\r
+EFIAPI\r
 Udp4NetVectorExtFree (\r
   VOID  *Context\r
   )\r
 {\r
 }\r
 \r
-\r
-/**\r
-  Set the Udp4 variable data.\r
-\r
-  @param  Udp4Service            Udp4 service data.\r
-\r
-  @retval EFI_OUT_OF_RESOURCES   There are not enough resources to set the\r
-                                 variable.\r
-  @retval EFI_SUCCESS            Set variable successfully.\r
-  @retval other                  Set variable failed.\r
-\r
-**/\r
-EFI_STATUS\r
-Udp4SetVariableData (\r
-  IN UDP4_SERVICE_DATA  *Udp4Service\r
-  )\r
-{\r
-  UINT32                  NumConfiguredInstance;\r
-  LIST_ENTRY              *Entry;\r
-  UINTN                   VariableDataSize;\r
-  EFI_UDP4_VARIABLE_DATA  *Udp4VariableData;\r
-  EFI_UDP4_SERVICE_POINT  *Udp4ServicePoint;\r
-  UDP4_INSTANCE_DATA      *Udp4Instance;\r
-  CHAR16                  *NewMacString;\r
-  EFI_STATUS              Status;\r
-\r
-  NumConfiguredInstance = 0;\r
-\r
-  //\r
-  // Go through the children list to count the configured children.\r
-  //\r
-  NET_LIST_FOR_EACH (Entry, &Udp4Service->ChildrenList) {\r
-    Udp4Instance = NET_LIST_USER_STRUCT_S (\r
-                     Entry,\r
-                     UDP4_INSTANCE_DATA,\r
-                     Link,\r
-                     UDP4_INSTANCE_DATA_SIGNATURE\r
-                     );\r
-\r
-    if (Udp4Instance->Configured) {\r
-      NumConfiguredInstance++;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Calculate the size of the Udp4VariableData. As there may be no Udp4 child,\r
-  // we should add extra buffer for the service points only if the number of configured\r
-  // children is more than 1.\r
-  //\r
-  VariableDataSize = sizeof (EFI_UDP4_VARIABLE_DATA);\r
-\r
-  if (NumConfiguredInstance > 1) {\r
-    VariableDataSize += sizeof (EFI_UDP4_SERVICE_POINT) * (NumConfiguredInstance - 1);\r
-  }\r
-\r
-  Udp4VariableData = AllocatePool (VariableDataSize);\r
-  if (Udp4VariableData == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  Udp4VariableData->DriverHandle = Udp4Service->ImageHandle;\r
-  Udp4VariableData->ServiceCount = NumConfiguredInstance;\r
-\r
-  Udp4ServicePoint = &Udp4VariableData->Services[0];\r
-\r
-  //\r
-  // Go through the children list to fill the configured children's address pairs.\r
-  //\r
-  NET_LIST_FOR_EACH (Entry, &Udp4Service->ChildrenList) {\r
-    Udp4Instance = NET_LIST_USER_STRUCT_S (\r
-                     Entry,\r
-                     UDP4_INSTANCE_DATA,\r
-                     Link,\r
-                     UDP4_INSTANCE_DATA_SIGNATURE\r
-                     );\r
-\r
-    if (Udp4Instance->Configured) {\r
-      Udp4ServicePoint->InstanceHandle = Udp4Instance->ChildHandle;\r
-      Udp4ServicePoint->LocalAddress   = Udp4Instance->ConfigData.StationAddress;\r
-      Udp4ServicePoint->LocalPort      = Udp4Instance->ConfigData.StationPort;\r
-      Udp4ServicePoint->RemoteAddress  = Udp4Instance->ConfigData.RemoteAddress;\r
-      Udp4ServicePoint->RemotePort     = Udp4Instance->ConfigData.RemotePort;\r
-\r
-      Udp4ServicePoint++;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Get the mac string.\r
-  //\r
-  Status = NetLibGetMacString (\r
-             Udp4Service->ControllerHandle,\r
-             Udp4Service->ImageHandle,\r
-             &NewMacString\r
-             );\r
-  if (EFI_ERROR (Status)) {\r
-    goto ON_ERROR;\r
-  }\r
-\r
-  if (Udp4Service->MacString != NULL) {\r
-    //\r
-    // The variable is set already, we're going to update it.\r
-    //\r
-    if (StrCmp (Udp4Service->MacString, NewMacString) != 0) {\r
-      //\r
-      // The mac address is changed, delete the previous variable first.\r
-      //\r
-      gRT->SetVariable (\r
-             Udp4Service->MacString,\r
-             &gEfiUdp4ServiceBindingProtocolGuid,\r
-             EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-             0,\r
-             NULL\r
-             );\r
-    }\r
-\r
-    gBS->FreePool (Udp4Service->MacString);\r
-  }\r
-\r
-  Udp4Service->MacString = NewMacString;\r
-\r
-  Status = gRT->SetVariable (\r
-                  Udp4Service->MacString,\r
-                  &gEfiUdp4ServiceBindingProtocolGuid,\r
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-                  VariableDataSize,\r
-                  (VOID *) Udp4VariableData\r
-                  );\r
-\r
-ON_ERROR:\r
-\r
-  gBS->FreePool (Udp4VariableData);\r
-\r
-  return Status;\r
-}\r
-\r
-\r
-/**\r
-  Clear the variable and free the resource.\r
-\r
-  @param  Udp4Service            Udp4 service data.\r
-\r
-  @return None.\r
-\r
-**/\r
-VOID\r
-Udp4ClearVariableData (\r
-  IN UDP4_SERVICE_DATA  *Udp4Service\r
-  )\r
-{\r
-  ASSERT (Udp4Service->MacString != NULL);\r
-\r
-  gRT->SetVariable (\r
-         Udp4Service->MacString,\r
-         &gEfiUdp4ServiceBindingProtocolGuid,\r
-         EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-         0,\r
-         NULL\r
-         );\r
-\r
-  gBS->FreePool (Udp4Service->MacString);\r
-  Udp4Service->MacString = NULL;\r
-}\r