]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/UefiPxeBcDxe/PxeBcSupport.c
MdeModulePkg: Update PXE driver to follow edk2 coding standards.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / UefiPxeBcDxe / PxeBcSupport.c
index 9327f6206731c39e99f5e2a1c3165834e9055231..a20fdb7a84aac3f877f15691260a0fa727611a4c 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\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
+\r
+Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
+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
@@ -17,133 +17,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \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
-\r
-  @return Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == 0\r
-\r
-**/\r
-CHAR8 *\r
-GetSmbiosString (\r
-  IN  SMBIOS_STRUCTURE_POINTER  *Smbios,\r
-  IN  UINT16                    StringNumber\r
-  )\r
-{\r
-  UINT16  Index;\r
-  CHAR8   *String;\r
-\r
-  //\r
-  // Skip over formatted section\r
-  //\r
-  String = (CHAR8 *) (Smbios->Raw + Smbios->Hdr->Length);\r
-\r
-  //\r
-  // Look through unformated section\r
-  //\r
-  for (Index = 1; Index <= StringNumber || StringNumber == 0; Index++) {\r
-    if (StringNumber == Index) {\r
-      return String;\r
-    }\r
-    //\r
-    // Skip string\r
-    //\r
-    for (; *String != 0; String++)\r
-      ;\r
-    String++;\r
-\r
-    if (*String == 0) {\r
-      //\r
-      // If double NULL then we are done.\r
-      //  Return pointer to next structure in Smbios.\r
-      //  if you pass in a 0 you will always get here\r
-      //\r
-      Smbios->Raw = (UINT8 *)++String;\r
-      return NULL;\r
-    }\r
-  }\r
-\r
-  return NULL;\r
-}\r
-\r
-\r
-/**\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
-\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
-\r
-**/\r
-EFI_STATUS\r
-GetSmbiosSystemGuidAndSerialNumber (\r
-  IN  EFI_GUID  *SystemGuid,\r
-  OUT CHAR8     **SystemSerialNumber\r
-  )\r
-{\r
-  EFI_STATUS                Status;\r
-  SMBIOS_TABLE_ENTRY_POINT  *SmbiosTable;\r
-  SMBIOS_STRUCTURE_POINTER  Smbios;\r
-  SMBIOS_STRUCTURE_POINTER  SmbiosEnd;\r
-  UINT16                    Index;\r
-\r
-  Status = EfiGetSystemConfigurationTable (&gEfiSmbiosTableGuid, (VOID **) &SmbiosTable);\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    return EFI_NOT_FOUND;\r
-  }\r
-\r
-  Smbios.Hdr    = (SMBIOS_STRUCTURE *) (UINTN) SmbiosTable->TableAddress;\r
-  SmbiosEnd.Raw = (UINT8 *) (UINTN) (SmbiosTable->TableAddress + SmbiosTable->TableLength);\r
-\r
-  for (Index = 0; Index < SmbiosTable->TableLength; Index++) {\r
-    if (Smbios.Hdr->Type == 1) {\r
-      if (Smbios.Hdr->Length < 0x19) {\r
-        //\r
-        // Older version did not support Guid and Serial number\r
-        //\r
-        continue;\r
-      }\r
-      //\r
-      // SMBIOS tables are byte packed so we need to do a byte copy to\r
-      // prevend alignment faults on Itanium-based platform.\r
-      //\r
-      CopyMem (SystemGuid, &Smbios.Type1->Uuid, sizeof (EFI_GUID));\r
-      *SystemSerialNumber = GetSmbiosString (&Smbios, Smbios.Type1->SerialNumber);\r
-\r
-      return EFI_SUCCESS;\r
-    }\r
-    //\r
-    // Make Smbios point to the next record\r
-    //\r
-    GetSmbiosString (&Smbios, 0);\r
-\r
-    if (Smbios.Raw >= SmbiosEnd.Raw) {\r
-      //\r
-      // SMBIOS 2.1 incorrectly stated the length of SmbiosTable as 0x1e.\r
-      // given this we must double check against the length of the structure.\r
-      //\r
-      return EFI_SUCCESS;\r
-    }\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-\r
-/**\r
-  The common notify function associated with various PxeBc events. \r
+  The common notify function associated with various PxeBc events.\r
 \r
   @param  Event     The event signaled.\r
   @param  Context   The context.\r
 \r
-  @return None\r
-\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -158,13 +36,15 @@ PxeBcCommonNotify (
 \r
 /**\r
   This function initialize(or configure) the Udp4Write instance.\r
-  \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
+  @param  Ttl        The time to live field of the IP header. \r
+  @param  ToS        The type of service field of the IP header.\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
@@ -179,7 +59,7 @@ PxeBcCommonNotify (
   @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
 **/\r
 EFI_STATUS\r
 PxeBcConfigureUdpWriteInstance (\r
@@ -187,7 +67,9 @@ PxeBcConfigureUdpWriteInstance (
   IN EFI_IPv4_ADDRESS   *StationIp,\r
   IN EFI_IPv4_ADDRESS   *SubnetMask,\r
   IN EFI_IPv4_ADDRESS   *Gateway,\r
-  IN OUT UINT16         *SrcPort\r
+  IN OUT UINT16         *SrcPort,\r
+  IN     UINT8          Ttl,\r
+  IN     UINT8          ToS\r
   )\r
 {\r
   EFI_UDP4_CONFIG_DATA  Udp4CfgData;\r
@@ -195,9 +77,9 @@ PxeBcConfigureUdpWriteInstance (
 \r
   ZeroMem (&Udp4CfgData, sizeof (Udp4CfgData));\r
 \r
-  Udp4CfgData.ReceiveTimeout = 1000;\r
-  Udp4CfgData.TypeOfService  = DEFAULT_ToS;\r
-  Udp4CfgData.TimeToLive     = DEFAULT_TTL;\r
+  Udp4CfgData.ReceiveTimeout = PXEBC_DEFAULT_LIFETIME;\r
+  Udp4CfgData.TypeOfService  = ToS;\r
+  Udp4CfgData.TimeToLive     = TTL;\r
   Udp4CfgData.AllowDuplicatePort = TRUE;\r
 \r
   CopyMem (&Udp4CfgData.StationAddress, StationIp, sizeof (*StationIp));\r
@@ -250,9 +132,10 @@ CvtNum (
 {\r
   UINTN Remainder;\r
 \r
-  while (Length-- > 0) {\r
+  while (Length > 0) {\r
     Remainder = Number % 10;\r
     Number /= 10;\r
+    Length--;\r
     Buffer[Length] = (UINT8) ('0' + Remainder);\r
   }\r
 }\r
@@ -261,16 +144,18 @@ CvtNum (
 /**\r
   Convert unsigned int number to decimal number.\r
 \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
+  @param      Number         The unsigned int number will be converted.\r
+  @param      Buffer         Pointer to the buffer to store the decimal number after transform.\r
+  @param[in]  BufferSize     The maxsize of the buffer.\r
+  \r
   @return the length of the number after transform.\r
 \r
 **/\r
 UINTN\r
 UtoA10 (\r
   IN UINTN Number,\r
-  IN CHAR8 *Buffer\r
+  IN CHAR8 *Buffer,\r
+  IN UINTN BufferSize\r
   )\r
 {\r
   UINTN Index;\r
@@ -285,7 +170,7 @@ UtoA10 (
     Number          = Number / 10;\r
   } while (Number != 0);\r
 \r
-  AsciiStrCpy (Buffer, &TempStr[Index]);\r
+  AsciiStrCpyS (Buffer, BufferSize, &TempStr[Index]);\r
 \r
   return AsciiStrLen (Buffer);\r
 }\r