]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Io.c
Fixed GCC 4.4 build issues due to EFIAPI not being used when required.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Dhcp4Dxe / Dhcp4Io.c
index 7c48340d8b32751c9132de73fa02f9c7fb609411..56b03a8a596cebd96ad16be354e78ba6fa3f3243 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   EFI DHCP protocol implementation.\r
   \r
-Copyright (c) 2006 - 2008, Intel Corporation.<BR>\r
+Copyright (c) 2006 - 2010, 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
@@ -227,7 +227,7 @@ DhcpSetState (
 \r
   DhcpSb->CurRetry      = 0;\r
   DhcpSb->PacketToLive  = 0;\r
-\r
+  DhcpSb->LastTimeout   = 0;\r
   DhcpSb->DhcpState     = State;\r
   return EFI_SUCCESS;\r
 }\r
@@ -260,6 +260,7 @@ DhcpSetTransmitTimer (
   }\r
 \r
   DhcpSb->PacketToLive = Times[DhcpSb->CurRetry];\r
+  DhcpSb->LastTimeout  = DhcpSb->PacketToLive;\r
 \r
   return;\r
 }\r
@@ -271,7 +272,7 @@ DhcpSetTransmitTimer (
 \r
   @param  DhcpSb                The DHCP service instance\r
   @param  Para                  The DHCP parameter extracted from the server's\r
-                                response.                             \r
+                                response.\r
 **/\r
 VOID\r
 DhcpComputeLease (\r
@@ -304,7 +305,7 @@ DhcpComputeLease (
   DHCP driver needs this port to unicast packet to the server\r
   such as DHCP release.\r
 \r
-  @param[in]  UdpIo                 The UDP IO port to configure\r
+  @param[in]  UdpIo                 The UDP IO to configure\r
   @param[in]  Context               Dhcp service instance.\r
 \r
   @retval EFI_SUCCESS           The UDP IO port is successfully configured.\r
@@ -312,8 +313,9 @@ DhcpComputeLease (
 \r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 DhcpConfigLeaseIoPort (\r
-  IN UDP_IO_PORT            *UdpIo,\r
+  IN UDP_IO                 *UdpIo,\r
   IN VOID                   *Context\r
   )\r
 {\r
@@ -348,7 +350,7 @@ DhcpConfigLeaseIoPort (
 \r
   ZeroMem (&UdpConfigData.RemoteAddress, sizeof (EFI_IPv4_ADDRESS));\r
 \r
-  Status = UdpIo->Udp->Configure (UdpIo->Udp, &UdpConfigData);\r
+  Status = UdpIo->Protocol.Udp4->Configure (UdpIo->Protocol.Udp4, &UdpConfigData);\r
 \r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
@@ -363,7 +365,7 @@ DhcpConfigLeaseIoPort (
     Ip = HTONL (DhcpSb->Para->Router);\r
     CopyMem (&Gateway, &Ip, sizeof (EFI_IPv4_ADDRESS));\r
 \r
-    UdpIo->Udp->Routes (UdpIo->Udp, FALSE, &Subnet, &Subnet, &Gateway);\r
+    UdpIo->Protocol.Udp4->Routes (UdpIo->Protocol.Udp4, FALSE, &Subnet, &Subnet, &Gateway);\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -401,7 +403,7 @@ DhcpLeaseAcquired (
   }\r
 \r
   if (DhcpSb->LeaseIoPort != NULL) {\r
-    UdpIoFreePort (DhcpSb->LeaseIoPort);\r
+    UdpIoFreeIo (DhcpSb->LeaseIoPort);\r
   }\r
 \r
   //\r
@@ -409,10 +411,11 @@ DhcpLeaseAcquired (
   // and transmit unicast packet with it as source address. Don't\r
   // start receive on this port, the queued packet will be timeout.\r
   //\r
-  DhcpSb->LeaseIoPort = UdpIoCreatePort (\r
+  DhcpSb->LeaseIoPort = UdpIoCreateIo (\r
                           DhcpSb->Controller,\r
                           DhcpSb->Image,\r
                           DhcpConfigLeaseIoPort,\r
+                          UDP_IO_UDP4_VERSION,\r
                           DhcpSb\r
                           );\r
 \r
@@ -442,20 +445,21 @@ DhcpCleanLease (
   DhcpSb->DhcpState   = Dhcp4Init;\r
   DhcpSb->Xid         = DhcpSb->Xid + 1;\r
   DhcpSb->ClientAddr  = 0;\r
+  DhcpSb->Netmask     = 0;\r
   DhcpSb->ServerAddr  = 0;\r
 \r
   if (DhcpSb->LastOffer != NULL) {\r
-    gBS->FreePool (DhcpSb->LastOffer);\r
+    FreePool (DhcpSb->LastOffer);\r
     DhcpSb->LastOffer = NULL;\r
   }\r
 \r
   if (DhcpSb->Selected != NULL) {\r
-    gBS->FreePool (DhcpSb->Selected);\r
+    FreePool (DhcpSb->Selected);\r
     DhcpSb->Selected = NULL;\r
   }\r
 \r
   if (DhcpSb->Para != NULL) {\r
-    gBS->FreePool (DhcpSb->Para);\r
+    FreePool (DhcpSb->Para);\r
     DhcpSb->Para = NULL;\r
   }\r
 \r
@@ -465,19 +469,25 @@ DhcpCleanLease (
   DhcpSb->ExtraRefresh  = FALSE;\r
 \r
   if (DhcpSb->LeaseIoPort != NULL) {\r
-    UdpIoFreePort (DhcpSb->LeaseIoPort);\r
+    UdpIoFreeIo (DhcpSb->LeaseIoPort);\r
     DhcpSb->LeaseIoPort = NULL;\r
   }\r
 \r
   if (DhcpSb->LastPacket != NULL) {\r
-    NetbufFree (DhcpSb->LastPacket);\r
+    FreePool (DhcpSb->LastPacket);\r
     DhcpSb->LastPacket = NULL;\r
   }\r
 \r
   DhcpSb->PacketToLive  = 0;\r
+  DhcpSb->LastTimeout   = 0;\r
   DhcpSb->CurRetry      = 0;\r
   DhcpSb->MaxRetries    = 0;\r
   DhcpSb->LeaseLife     = 0;\r
+\r
+  //\r
+  // Clean active config data.\r
+  //\r
+  DhcpCleanConfigure (&DhcpSb->ActiveConfig);\r
 }\r
 \r
 \r
@@ -521,7 +531,7 @@ DhcpChooseOffer (
     TempPacket = (EFI_DHCP4_PACKET *) AllocatePool (NewPacket->Size);\r
     if (TempPacket != NULL) {\r
       CopyMem (TempPacket, NewPacket, NewPacket->Size);\r
-      gBS->FreePool (Selected);\r
+      FreePool (Selected);\r
       Selected = TempPacket;\r
     }\r
   }\r
@@ -634,7 +644,7 @@ DhcpHandleSelect (
 \r
   if (Status == EFI_SUCCESS) {\r
     if (DhcpSb->LastOffer != NULL) {\r
-      gBS->FreePool (DhcpSb->LastOffer);\r
+      FreePool (DhcpSb->LastOffer);\r
     }\r
 \r
     DhcpSb->LastOffer = Packet;\r
@@ -643,7 +653,7 @@ DhcpHandleSelect (
 \r
   } else if (Status == EFI_NOT_READY) {\r
     if (DhcpSb->LastOffer != NULL) {\r
-      gBS->FreePool (DhcpSb->LastOffer);\r
+      FreePool (DhcpSb->LastOffer);\r
     }\r
 \r
     DhcpSb->LastOffer = Packet;\r
@@ -659,7 +669,7 @@ DhcpHandleSelect (
   return EFI_SUCCESS;\r
 \r
 ON_EXIT:\r
-  gBS->FreePool (Packet);\r
+  FreePool (Packet);\r
   return Status;\r
 }\r
 \r
@@ -745,14 +755,14 @@ DhcpHandleRequest (
   DhcpSb->IoStatus = EFI_SUCCESS;\r
   DhcpNotifyUser (DhcpSb, DHCP_NOTIFY_COMPLETION);\r
 \r
-  gBS->FreePool (Packet);\r
+  FreePool (Packet);\r
   return EFI_SUCCESS;\r
 \r
 REJECT:\r
   DhcpSendMessage (DhcpSb, DhcpSb->Selected, DhcpSb->Para, DHCP_MSG_DECLINE, Message);\r
 \r
 ON_EXIT:\r
-  gBS->FreePool (Packet);\r
+  FreePool (Packet);\r
   return Status;\r
 }\r
 \r
@@ -836,7 +846,7 @@ DhcpHandleRenewRebind (
   }\r
 \r
 ON_EXIT:\r
-  gBS->FreePool (Packet);\r
+  FreePool (Packet);\r
   return Status;\r
 }\r
 \r
@@ -905,18 +915,14 @@ DhcpHandleReboot (
   //\r
   // OK, get the parameter from server, record the lease\r
   //\r
-  DhcpSb->Para = AllocatePool (sizeof (DHCP_PARAMETER));\r
-\r
+  DhcpSb->Para = AllocateCopyPool (sizeof (DHCP_PARAMETER), Para);\r
   if (DhcpSb->Para == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
     goto ON_EXIT;\r
   }\r
 \r
   DhcpSb->Selected  = Packet;\r
-  CopyMem (DhcpSb->Para, Para, sizeof (*DhcpSb->Para));\r
-\r
   Status            = DhcpLeaseAcquired (DhcpSb);\r
-\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
@@ -926,7 +932,7 @@ DhcpHandleReboot (
   return EFI_SUCCESS;\r
 \r
 ON_EXIT:\r
-  gBS->FreePool (Packet);\r
+  FreePool (Packet);\r
   return Status;\r
 }\r
 \r
@@ -936,15 +942,16 @@ ON_EXIT:
   state machine.\r
 \r
   @param  UdpPacket             The UDP packets received.\r
-  @param  Points                The local/remote UDP access points\r
+  @param  EndPoint              The local/remote UDP access point\r
   @param  IoStatus              The status of the UDP receive\r
   @param  Context               The opaque parameter to the function.\r
 \r
 **/\r
 VOID\r
+EFIAPI\r
 DhcpInput (\r
   NET_BUF                   *UdpPacket,\r
-  UDP_POINTS                *Points,\r
+  UDP_END_POINT             *EndPoint,\r
   EFI_STATUS                IoStatus,\r
   VOID                      *Context\r
   )\r
@@ -1046,7 +1053,7 @@ DhcpInput (
     //\r
     // Ignore the packet in INITREBOOT, INIT and BOUND states\r
     //\r
-    gBS->FreePool (Packet);\r
+    FreePool (Packet);\r
     Status = EFI_SUCCESS;\r
     break;\r
 \r
@@ -1061,13 +1068,14 @@ DhcpInput (
   }\r
 \r
   if (Para != NULL) {\r
-    gBS->FreePool (Para);\r
+    FreePool (Para);\r
   }\r
 \r
   Packet = NULL;\r
 \r
   if (EFI_ERROR (Status)) {\r
     NetbufFree (UdpPacket);\r
+    UdpIoRecvDatagram (DhcpSb->UdpIo, DhcpInput, DhcpSb, 0);\r
     DhcpEndSession (DhcpSb, Status);\r
     return ;\r
   }\r
@@ -1076,7 +1084,7 @@ RESTART:
   NetbufFree (UdpPacket);\r
 \r
   if (Packet != NULL) {\r
-    gBS->FreePool (Packet);\r
+    FreePool (Packet);\r
   }\r
 \r
   Status = UdpIoRecvDatagram (DhcpSb->UdpIo, DhcpInput, DhcpSb, 0);\r
@@ -1094,11 +1102,12 @@ RESTART:
 \r
 **/\r
 VOID\r
+EFIAPI\r
 DhcpReleasePacket (\r
   IN VOID                   *Arg\r
   )\r
 {\r
-  gBS->FreePool (Arg);\r
+  FreePool (Arg);\r
 }\r
 \r
 \r
@@ -1106,15 +1115,16 @@ DhcpReleasePacket (
   Release the net buffer when packet is sent.\r
 \r
   @param  UdpPacket             The UDP packets received.\r
-  @param  Points                The local/remote UDP access points\r
+  @param  EndPoint              The local/remote UDP access point\r
   @param  IoStatus              The status of the UDP receive\r
   @param  Context               The opaque parameter to the function.\r
 \r
 **/\r
 VOID\r
+EFIAPI\r
 DhcpOnPacketSent (\r
   NET_BUF                   *Packet,\r
-  UDP_POINTS                *Points,\r
+  UDP_END_POINT             *EndPoint,\r
   EFI_STATUS                IoStatus,\r
   VOID                      *Context\r
   )\r
@@ -1157,8 +1167,8 @@ DhcpSendMessage (
   EFI_DHCP4_PACKET          *NewPacket;\r
   EFI_DHCP4_HEADER          *Head;\r
   EFI_DHCP4_HEADER          *SeedHead;\r
-  UDP_IO_PORT               *UdpIo;\r
-  UDP_POINTS                EndPoint;\r
+  UDP_IO                    *UdpIo;\r
+  UDP_END_POINT             EndPoint;\r
   NET_BUF                   *Wrap;\r
   NET_FRAGMENT              Frag;\r
   EFI_STATUS                Status;\r
@@ -1318,12 +1328,12 @@ DhcpSendMessage (
   }\r
 \r
   if (EFI_ERROR (Status)) {\r
-    gBS->FreePool (Packet);\r
+    FreePool (Packet);\r
     return Status;\r
   }\r
 \r
   if (NewPacket != NULL) {\r
-    gBS->FreePool (Packet);\r
+    FreePool (Packet);\r
     Packet = NewPacket;\r
   }\r
 \r
@@ -1345,7 +1355,7 @@ DhcpSendMessage (
   Wrap      = NetbufFromExt (&Frag, 1, 0, 0, DhcpReleasePacket, Packet);\r
 \r
   if (Wrap == NULL) {\r
-    gBS->FreePool (Packet);\r
+    FreePool (Packet);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
@@ -1353,34 +1363,42 @@ DhcpSendMessage (
   // Save it as the last sent packet for retransmission\r
   //\r
   if (DhcpSb->LastPacket != NULL) {\r
-    NetbufFree (DhcpSb->LastPacket);\r
+    FreePool (DhcpSb->LastPacket);\r
   }\r
 \r
-  NET_GET_REF (Wrap);\r
-  DhcpSb->LastPacket = Wrap;\r
+  DhcpSb->LastPacket = Packet;\r
   DhcpSetTransmitTimer (DhcpSb);\r
 \r
   //\r
   // Broadcast the message, unless we know the server address.\r
   // Use the lease UdpIo port to send the unicast packet.\r
   //\r
-  EndPoint.RemoteAddr = 0xffffffff;\r
-  EndPoint.LocalAddr  = 0;\r
-  EndPoint.RemotePort = DHCP_SERVER_PORT;\r
-  EndPoint.LocalPort  = DHCP_CLIENT_PORT;\r
-  UdpIo               = DhcpSb->UdpIo;\r
+  EndPoint.RemoteAddr.Addr[0] = 0xffffffff;\r
+  EndPoint.LocalAddr.Addr[0]  = 0;\r
+  EndPoint.RemotePort         = DHCP_SERVER_PORT;\r
+  EndPoint.LocalPort          = DHCP_CLIENT_PORT;\r
+  UdpIo                       = DhcpSb->UdpIo;\r
 \r
   if ((DhcpSb->DhcpState == Dhcp4Renewing) || (Type == DHCP_MSG_RELEASE)) {\r
-    EndPoint.RemoteAddr = DhcpSb->ServerAddr;\r
-    EndPoint.LocalAddr  = DhcpSb->ClientAddr;\r
-    UdpIo               = DhcpSb->LeaseIoPort;\r
+    EndPoint.RemoteAddr.Addr[0] = DhcpSb->ServerAddr;\r
+    EndPoint.LocalAddr.Addr[0]  = DhcpSb->ClientAddr;\r
+    UdpIo                       = DhcpSb->LeaseIoPort;\r
   }\r
 \r
   ASSERT (UdpIo != NULL);\r
-  Status = UdpIoSendDatagram (UdpIo, Wrap, &EndPoint, 0, DhcpOnPacketSent, DhcpSb);\r
+  NET_GET_REF (Wrap);\r
+  \r
+  Status = UdpIoSendDatagram (\r
+             UdpIo, \r
+             Wrap, \r
+             &EndPoint, \r
+             NULL, \r
+             DhcpOnPacketSent, \r
+             DhcpSb\r
+             );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    NetbufFree (Wrap);\r
+    NET_PUT_REF (Wrap);\r
     return EFI_ACCESS_DENIED;\r
   }\r
 \r
@@ -1403,41 +1421,56 @@ DhcpRetransmit (
   IN DHCP_SERVICE           *DhcpSb\r
   )\r
 {\r
-  UDP_IO_PORT               *UdpIo;\r
-  UDP_POINTS                EndPoint;\r
+  UDP_IO                    *UdpIo;\r
+  UDP_END_POINT             EndPoint;\r
+  NET_BUF                   *Wrap;\r
+  NET_FRAGMENT              Frag;\r
   EFI_STATUS                Status;\r
 \r
   ASSERT (DhcpSb->LastPacket != NULL);\r
 \r
+  DhcpSb->LastPacket->Dhcp4.Header.Seconds = HTONS (*(UINT16 *)(&DhcpSb->LastTimeout));\r
+\r
+  //\r
+  // Wrap it into a netbuf then send it.\r
+  //\r
+  Frag.Bulk = (UINT8 *) &DhcpSb->LastPacket->Dhcp4.Header;\r
+  Frag.Len  = DhcpSb->LastPacket->Length;\r
+  Wrap      = NetbufFromExt (&Frag, 1, 0, 0, DhcpReleasePacket, DhcpSb->LastPacket);\r
+\r
+  if (Wrap == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  \r
   //\r
   // Broadcast the message, unless we know the server address.\r
   //\r
-  EndPoint.RemotePort = DHCP_SERVER_PORT;\r
-  EndPoint.LocalPort  = DHCP_CLIENT_PORT;\r
-  EndPoint.RemoteAddr = 0xffffffff;\r
-  EndPoint.LocalAddr  = 0;\r
-  UdpIo               = DhcpSb->UdpIo;\r
+  EndPoint.RemotePort         = DHCP_SERVER_PORT;\r
+  EndPoint.LocalPort          = DHCP_CLIENT_PORT;\r
+  EndPoint.RemoteAddr.Addr[0] = 0xffffffff;\r
+  EndPoint.LocalAddr.Addr[0]  = 0;\r
+  UdpIo                       = DhcpSb->UdpIo;\r
 \r
   if (DhcpSb->DhcpState == Dhcp4Renewing) {\r
-    EndPoint.RemoteAddr = DhcpSb->ServerAddr;\r
-    EndPoint.LocalAddr  = DhcpSb->ClientAddr;\r
-    UdpIo               = DhcpSb->LeaseIoPort;\r
+    EndPoint.RemoteAddr.Addr[0] = DhcpSb->ServerAddr;\r
+    EndPoint.LocalAddr.Addr[0]  = DhcpSb->ClientAddr;\r
+    UdpIo                       = DhcpSb->LeaseIoPort;\r
   }\r
 \r
   ASSERT (UdpIo != NULL);\r
 \r
-  NET_GET_REF (DhcpSb->LastPacket);\r
+  NET_GET_REF (Wrap);\r
   Status = UdpIoSendDatagram (\r
              UdpIo,\r
-             DhcpSb->LastPacket,\r
+             Wrap,\r
              &EndPoint,\r
-             0,\r
+             NULL,\r
              DhcpOnPacketSent,\r
              DhcpSb\r
              );\r
 \r
   if (EFI_ERROR (Status)) {\r
-    NET_PUT_REF (DhcpSb->LastPacket);\r
+    NET_PUT_REF (Wrap);\r
     return EFI_ACCESS_DENIED;\r
   }\r
 \r