]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c
NetworkPkg: Clean up source files
[mirror_edk2.git] / NetworkPkg / Dhcp6Dxe / Dhcp6Utility.c
index 32247c927b0a63a6b89af29be80c24cb0950bd5e..10a99a00d4b5595c93547501d7f8a2dcbe457400 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
   Dhcp6 support functions implementation.\r
 \r
 /** @file\r
   Dhcp6 support functions implementation.\r
 \r
-  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -63,11 +64,11 @@ Dhcp6GenerateClientId (
   //\r
   // If System UUID is found from SMBIOS Table, use DUID-UUID type.\r
   //\r
   //\r
   // If System UUID is found from SMBIOS Table, use DUID-UUID type.\r
   //\r
-  if (!EFI_ERROR (NetLibGetSystemGuid (&Uuid))) {\r
+  if ((PcdGet8 (PcdDhcp6UidType) == Dhcp6DuidTypeUuid) && !EFI_ERROR (NetLibGetSystemGuid (&Uuid)) && !CompareGuid (&Uuid, &gZeroGuid)) {\r
     //\r
     //\r
     //  The format of DUID-UUID:\r
     //\r
     //\r
     //  The format of DUID-UUID:\r
-    //   \r
+    //\r
     //    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1\r
     //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r
     //   |          DUID-Type (4)        |    UUID (128 bits)            |\r
     //    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1\r
     //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r
     //   |          DUID-Type (4)        |    UUID (128 bits)            |\r
@@ -90,16 +91,16 @@ Dhcp6GenerateClientId (
     // sizeof (Duid-type + UUID-size) = 18 bytes\r
     //\r
     Duid->Length = (UINT16) (18);\r
     // sizeof (Duid-type + UUID-size) = 18 bytes\r
     //\r
     Duid->Length = (UINT16) (18);\r
-  \r
+\r
     //\r
     // Set the Duid-type and copy UUID.\r
     //\r
     WriteUnaligned16 ((UINT16 *) (Duid->Duid), HTONS (Dhcp6DuidTypeUuid));\r
     //\r
     // Set the Duid-type and copy UUID.\r
     //\r
     WriteUnaligned16 ((UINT16 *) (Duid->Duid), HTONS (Dhcp6DuidTypeUuid));\r
-  \r
+\r
     CopyMem (Duid->Duid + 2, &Uuid, sizeof(EFI_GUID));\r
 \r
   } else {\r
     CopyMem (Duid->Duid + 2, &Uuid, sizeof(EFI_GUID));\r
 \r
   } else {\r
-      \r
+\r
     //\r
     //\r
     //  The format of DUID-LLT:\r
     //\r
     //\r
     //  The format of DUID-LLT:\r
@@ -134,19 +135,19 @@ Dhcp6GenerateClientId (
     if (Duid == NULL) {\r
       return NULL;\r
     }\r
     if (Duid == NULL) {\r
       return NULL;\r
     }\r
-  \r
+\r
     //\r
     // sizeof (Duid-type + hardware-type + time) = 8 bytes\r
     //\r
     Duid->Length = (UINT16) (Mode->HwAddressSize + 8);\r
     //\r
     // sizeof (Duid-type + hardware-type + time) = 8 bytes\r
     //\r
     Duid->Length = (UINT16) (Mode->HwAddressSize + 8);\r
-  \r
+\r
     //\r
     // Set the Duid-type, hardware-type, time and copy the hardware address.\r
     //\r
     //\r
     // Set the Duid-type, hardware-type, time and copy the hardware address.\r
     //\r
-    WriteUnaligned16 ((UINT16 *) (Duid->Duid), HTONS (Dhcp6DuidTypeLlt));\r
-    WriteUnaligned16 ((UINT16 *) (Duid->Duid + 2), HTONS (NET_IFTYPE_ETHERNET));\r
-    WriteUnaligned32 ((UINT32 *) (Duid->Duid + 4), HTONL (Stamp));\r
-  \r
+    WriteUnaligned16 ((UINT16 *) ((UINT8 *) Duid + OFFSET_OF (EFI_DHCP6_DUID, Duid)), HTONS (Dhcp6DuidTypeLlt));\r
+    WriteUnaligned16 ((UINT16 *) ((UINT8 *) Duid + OFFSET_OF (EFI_DHCP6_DUID, Duid) + 2), HTONS (NET_IFTYPE_ETHERNET));\r
+    WriteUnaligned32 ((UINT32 *) ((UINT8 *) Duid + OFFSET_OF (EFI_DHCP6_DUID, Duid) + 4), HTONL (Stamp));\r
+\r
     CopyMem (Duid->Duid + 8, &Mode->CurrentAddress, Mode->HwAddressSize);\r
   }\r
 \r
     CopyMem (Duid->Duid + 8, &Mode->CurrentAddress, Mode->HwAddressSize);\r
   }\r
 \r
@@ -157,7 +158,10 @@ Dhcp6GenerateClientId (
                   Duid->Length + 2,\r
                   (VOID *) Duid\r
                   );\r
                   Duid->Length + 2,\r
                   (VOID *) Duid\r
                   );\r
-  ASSERT_EFI_ERROR (Status);\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (Duid);\r
+    return NULL;\r
+  }\r
 \r
   return Duid;\r
 }\r
 \r
   return Duid;\r
 }\r
@@ -383,7 +387,6 @@ Dhcp6CalculateLeaseTime (
   IN DHCP6_IA_CB              *IaCb\r
   )\r
 {\r
   IN DHCP6_IA_CB              *IaCb\r
   )\r
 {\r
-  EFI_DHCP6_IA_ADDRESS        *IaAddr;\r
   UINT32                      MinLt;\r
   UINT32                      MaxLt;\r
   UINTN                       Index;\r
   UINT32                      MinLt;\r
   UINT32                      MaxLt;\r
   UINTN                       Index;\r
@@ -398,9 +401,8 @@ Dhcp6CalculateLeaseTime (
   // valid life time.\r
   //\r
   for (Index = 0; Index < IaCb->Ia->IaAddressCount; Index++) {\r
   // valid life time.\r
   //\r
   for (Index = 0; Index < IaCb->Ia->IaAddressCount; Index++) {\r
-    IaAddr = IaCb->Ia->IaAddress + Index * sizeof (EFI_DHCP6_IA_ADDRESS);\r
-    MinLt  = MIN (MinLt, IaAddr->ValidLifetime);\r
-    MaxLt  = MAX (MinLt, IaAddr->ValidLifetime);\r
+    MinLt  = MIN (MinLt, IaCb->Ia->IaAddress[Index].ValidLifetime);\r
+    MaxLt  = MAX (MinLt, IaCb->Ia->IaAddress[Index].ValidLifetime);\r
   }\r
 \r
   //\r
   }\r
 \r
   //\r
@@ -685,7 +687,7 @@ Dhcp6AppendIaAddrOption (
   //      .                        IAaddr-options                         .\r
   //      .                                                               .\r
   //      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r
   //      .                        IAaddr-options                         .\r
   //      .                                                               .\r
   //      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r
-  \r
+\r
   //\r
   // Fill the value of Ia Address option type\r
   //\r
   //\r
   // Fill the value of Ia Address option type\r
   //\r
@@ -998,7 +1000,7 @@ Dhcp6SeekIaOption (
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
-  Check whether the incoming IPv6 address in IaAddr is one of the maintained \r
+  Check whether the incoming IPv6 address in IaAddr is one of the maintained\r
   addresses in the IA control blcok.\r
 \r
   @param[in]  IaAddr            The pointer to the IA Address to be checked.\r
   addresses in the IA control blcok.\r
 \r
   @param[in]  IaAddr            The pointer to the IA Address to be checked.\r
@@ -1017,7 +1019,7 @@ Dhcp6AddrIsInCurrentIa (
   UINT32    Index;\r
 \r
   ASSERT (IaAddr != NULL && CurrentIa != NULL);\r
   UINT32    Index;\r
 \r
   ASSERT (IaAddr != NULL && CurrentIa != NULL);\r
-  \r
+\r
   for (Index = 0; Index < CurrentIa->IaAddressCount; Index++) {\r
     if (EFI_IP6_EQUAL(&IaAddr->IpAddress, &CurrentIa->IaAddress[Index].IpAddress)) {\r
       return TRUE;\r
   for (Index = 0; Index < CurrentIa->IaAddressCount; Index++) {\r
     if (EFI_IP6_EQUAL(&IaAddr->IpAddress, &CurrentIa->IaAddress[Index].IpAddress)) {\r
       return TRUE;\r
@@ -1301,7 +1303,7 @@ EFI_STATUS
 Dhcp6GetMappingTimeOut (\r
   IN  EFI_IP6_CONFIG_PROTOCOL       *Ip6Cfg,\r
   OUT UINTN                         *TimeOut\r
 Dhcp6GetMappingTimeOut (\r
   IN  EFI_IP6_CONFIG_PROTOCOL       *Ip6Cfg,\r
   OUT UINTN                         *TimeOut\r
-  ) \r
+  )\r
 {\r
   EFI_STATUS            Status;\r
   UINTN                 DataSize;\r
 {\r
   EFI_STATUS            Status;\r
   UINTN                 DataSize;\r
@@ -1321,8 +1323,8 @@ Dhcp6GetMappingTimeOut (
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
-  \r
+\r
   *TimeOut = TICKS_PER_SECOND * DadXmits.DupAddrDetectTransmits + DHCP6_DAD_ADDITIONAL_DELAY;\r
   *TimeOut = TICKS_PER_SECOND * DadXmits.DupAddrDetectTransmits + DHCP6_DAD_ADDITIONAL_DELAY;\r
-  \r
+\r
   return EFI_SUCCESS;\r
 }\r
   return EFI_SUCCESS;\r
 }\r