]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c
add security check.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / UefiPxeBcDxe / PxeBcSupport.c
index 200d43141eba035ba54aef418a54c947fdaa220b..087c2619aa0967956e31fbb046e23bae329f5020 100644 (file)
@@ -1,6 +1,7 @@
 /** @file\r
-\r
-Copyright (c) 2007, Intel Corporation\r
+  Support routines for PxeBc.\r
+  \r
+Copyright (c) 2007 - 2009, 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
@@ -9,15 +10,6 @@ http://opensource.org/licenses/bsd-license.php
 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
-  PxeBcSupport.c\r
-\r
-Abstract:\r
-\r
-  Support routines for PxeBc\r
-\r
-\r
 **/\r
 \r
 \r
@@ -25,7 +17,8 @@ Abstract:
 \r
 \r
 /**\r
-\r
+  This function returns SMBIOS string given the string number.\r
+  \r
   @param  Smbios              Pointer to SMBIOS structure\r
   @param  StringNumber        String number to return. 0 is used to skip all\r
                               strings and  point to the next SMBIOS structure.\r
@@ -33,7 +26,6 @@ Abstract:
   @return Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == 0\r
 \r
 **/\r
-// GC_NOTO: function comment is missing 'Routine Description:'\r
 CHAR8 *\r
 GetSmbiosString (\r
   IN  SMBIOS_STRUCTURE_POINTER  *Smbios,\r
@@ -78,14 +70,14 @@ GetSmbiosString (
 \r
 \r
 /**\r
-  This function gets system guid and serial number from the smbios table\r
+  This function gets system guid and serial number from the smbios table.\r
 \r
-  @param  SystemGuid          The pointer of returned system guid\r
-  @param  SystemSerialNumber  The pointer of returned system serial number\r
+  @param  SystemGuid          The pointer of returned system guid.\r
+  @param  SystemSerialNumber  The pointer of returned system serial number.\r
 \r
   @retval EFI_SUCCESS         Successfully get the system guid and system serial\r
-                              number\r
-  @retval EFI_NOT_FOUND       Not find the SMBIOS table\r
+                              number.\r
+  @retval EFI_NOT_FOUND       Not find the SMBIOS table.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -145,15 +137,16 @@ GetSmbiosSystemGuidAndSerialNumber (
 \r
 \r
 /**\r
-  GC_NOTO: Add function description\r
+  The common notify function associated with various PxeBc events. \r
 \r
-  @param  Event               GC_NOTO: add argument description\r
-  @param  Context             GC_NOTO: add argument description\r
+  @param  Event     The event signaled.\r
+  @param  Context   The context.\r
 \r
-  @return GC_NOTO: add return values\r
+  @return None\r
 \r
 **/\r
 VOID\r
+EFIAPI\r
 PxeBcCommonNotify (\r
   IN EFI_EVENT           Event,\r
   IN VOID                *Context\r
@@ -164,39 +157,115 @@ PxeBcCommonNotify (
 \r
 \r
 /**\r
-  Convert number to ASCII value\r
+  This function initialize(or configure) the Udp4Write instance.\r
+  \r
+  @param  Udp4       Pointer to the EFI_UDP4_PROTOCOL instance.\r
+  @param  StationIp  Pointer to the station ip address.\r
+  @param  SubnetMask Pointer to the subnetmask of the station ip address.\r
+  @param  Gateway    Pointer to the gateway ip address.\r
+  @param  SrcPort    Pointer to the srouce port of the station.\r
+  \r
+  @retval EFI_SUCCESS           The configuration settings were set, changed, or reset successfully.\r
+  @retval EFI_NO_MAPPING        When using a default address, configuration (DHCP, BOOTP,\r
+                                RARP, etc.) is not finished yet.\r
+  @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:\r
+  @retval EFI_ALREADY_STARTED   The EFI UDPv4 Protocol instance is already started/configured\r
+                                and must be stopped/reset before it can be reconfigured.\r
+  @retval EFI_ACCESS_DENIED     UdpConfigData. AllowDuplicatePort is FALSE\r
+                                and UdpConfigData.StationPort is already used by\r
+                                other instance.\r
+  @retval EFI_OUT_OF_RESOURCES  The EFI UDPv4 Protocol driver cannot allocate memory for this\r
+                                EFI UDPv4 Protocol instance.\r
+  @retval EFI_DEVICE_ERROR      An unexpected network or system error occurred and this instance\r
+                                was not opened.\r
+  @retval Others                Please examine the function Udp4->Routes(Udp4, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, Gateway) returns.\r
+  \r
+**/\r
+EFI_STATUS\r
+PxeBcConfigureUdpWriteInstance (\r
+  IN EFI_UDP4_PROTOCOL  *Udp4,\r
+  IN EFI_IPv4_ADDRESS   *StationIp,\r
+  IN EFI_IPv4_ADDRESS   *SubnetMask,\r
+  IN EFI_IPv4_ADDRESS   *Gateway,\r
+  IN OUT UINT16         *SrcPort\r
+  )\r
+{\r
+  EFI_UDP4_CONFIG_DATA  Udp4CfgData;\r
+  EFI_STATUS            Status;\r
+\r
+  ZeroMem (&Udp4CfgData, sizeof (Udp4CfgData));\r
+\r
+  Udp4CfgData.ReceiveTimeout = 1000;\r
+  Udp4CfgData.TypeOfService  = DEFAULT_ToS;\r
+  Udp4CfgData.TimeToLive     = DEFAULT_TTL;\r
+  Udp4CfgData.AllowDuplicatePort = TRUE;\r
+\r
+  CopyMem (&Udp4CfgData.StationAddress, StationIp, sizeof (*StationIp));\r
+  CopyMem (&Udp4CfgData.SubnetMask, SubnetMask, sizeof (*SubnetMask));\r
+\r
+  Udp4CfgData.StationPort    = *SrcPort;\r
+\r
+  //\r
+  // Reset the instance.\r
+  //\r
+  Udp4->Configure (Udp4, NULL);\r
+\r
+  Status = Udp4->Configure (Udp4, &Udp4CfgData);\r
+  if (!EFI_ERROR (Status) && (Gateway->Addr[0] != 0)) {\r
+    //\r
+    // basic configuration OK, need to add the default route entry\r
+    //\r
+    Status = Udp4->Routes (Udp4, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, Gateway);\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // roll back\r
+      //\r
+      Udp4->Configure (Udp4, NULL);\r
+    }\r
+  }\r
+\r
+  if (!EFI_ERROR (Status) && (*SrcPort == 0)) {\r
+    Udp4->GetModeData (Udp4, &Udp4CfgData, NULL, NULL, NULL);\r
+    *SrcPort = Udp4CfgData.StationPort;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Convert number to ASCII value.\r
 \r
   @param  Number              Numeric value to convert to decimal ASCII value.\r
-  @param  Buffer              Buffer to place ASCII version of the Number\r
+  @param  Buffer              Buffer to place ASCII version of the Number.\r
   @param  Length              Length of Buffer.\r
 \r
-  @retval none                none\r
-\r
 **/\r
 VOID\r
 CvtNum (\r
   IN UINTN  Number,\r
   IN UINT8  *Buffer,\r
-  IN INTN   Length\r
+  IN UINTN   Length\r
   )\r
 {\r
   UINTN Remainder;\r
 \r
-  while (Length--) {\r
+  while (Length > 0) {\r
     Remainder = Number % 10;\r
     Number /= 10;\r
+    Length--;\r
     Buffer[Length] = (UINT8) ('0' + Remainder);\r
   }\r
 }\r
 \r
 \r
 /**\r
-  GC_NOTO: Add function description\r
+  Convert unsigned int number to decimal number.\r
 \r
-  @param  Number              GC_NOTO: add argument description\r
-  @param  Buffer              GC_NOTO: add argument description\r
+  @param  Number   The unsigned int number will be converted.\r
+  @param  Buffer   Pointer to the buffer to store the decimal number after transform.\r
 \r
-  @return GC_NOTO: add return values\r
+  @return the length of the number after transform.\r
 \r
 **/\r
 UINTN\r
@@ -224,12 +293,11 @@ UtoA10 (
 \r
 \r
 /**\r
-  Convert ASCII numeric string to a UINTN value\r
+  Convert ASCII numeric string to a UINTN value.\r
 \r
-  @param  Number              Numeric value to convert to decimal ASCII value.\r
-  @param  Buffer              Buffer to place ASCII version of the Number\r
+  @param  Buffer  Pointer to the 8-byte unsigned int value.\r
 \r
-  @retval Value               UINTN value of the ASCII string.\r
+  @return UINTN value of the ASCII string.\r
 \r
 **/\r
 UINT64\r