]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/Dhcp6Dxe/Dhcp6Utility.c
Add new interface GetVariable2 and GetEfiGlobalVariable2 to return more info. Also...
[mirror_edk2.git] / NetworkPkg / Dhcp6Dxe / Dhcp6Utility.c
index be7a9855519743e5bc4f3c34091b7f1ed81bc026..479eb143d8a8e169255e7e6e48ec569566a31a1f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Dhcp6 support functions implementation.\r
 \r
-  Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2012, 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
@@ -34,27 +34,18 @@ Dhcp6GenerateClientId (
   EFI_DHCP6_DUID            *Duid;\r
   EFI_TIME                  Time;\r
   UINT32                    Stamp;\r
+  EFI_GUID                  Uuid;\r
+\r
 \r
   //\r
   // Attempt to get client Id from variable to keep it constant.\r
   // See details in section-9 of rfc-3315.\r
   //\r
-  Duid = GetVariable (L"ClientId", &gEfiDhcp6ServiceBindingProtocolGuid);\r
+  GetVariable2 (L"ClientId", &gEfiDhcp6ServiceBindingProtocolGuid, &Duid, NULL);\r
   if (Duid != NULL) {\r
     return Duid;\r
   }\r
 \r
-  //\r
-  // Generate a time stamp of the seconds from 2000/1/1, assume 30day/month.\r
-  //\r
-  gRT->GetTime (&Time, NULL);\r
-  Stamp = (UINT32)\r
-    (\r
-      (((((Time.Year - 2000) * 360 + (Time.Month - 1)) * 30 + (Time.Day - 1)) * 24 + Time.Hour) * 60 + Time.Minute) *\r
-      60 +\r
-      Time.Second\r
-    );\r
-\r
   //\r
   //  The format of client identifier option:\r
   //\r
@@ -68,42 +59,96 @@ Dhcp6GenerateClientId (
   //    .                                                               .\r
   //    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r
   //\r
-  //\r
-  //  The format of DUID-LLT:\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 (1)        |    hardware type (16 bits)    |\r
-  //    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r
-  //    |                        time (32 bits)                         |\r
-  //    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r
-  //    .                                                               .\r
-  //    .             link-layer address (variable length)              .\r
-  //    .                                                               .\r
-  //    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r
-  //\r
 \r
   //\r
-  // sizeof (option-len + Duid-type + hardware-type + time) = 10 bytes\r
+  // If System UUID is found from SMBIOS Table, use DUID-UUID type.\r
   //\r
-  Duid = AllocateZeroPool (10 + Mode->HwAddressSize);\r
-  if (Duid == NULL) {\r
-    return NULL;\r
-  }\r
+  if (!EFI_ERROR (NetLibGetSystemGuid (&Uuid))) {\r
+    //\r
+    //\r
+    //  The format of DUID-UUID:\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
+    //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               |\r
+    //   |                                                               |\r
+    //   |                                                               |\r
+    //   |                                -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r
+    //   |                                |\r
+    //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\r
 \r
-  //\r
-  // sizeof (Duid-type + hardware-type + time) = 8 bytes\r
-  //\r
-  Duid->Length = (UINT16) (Mode->HwAddressSize + 8);\r
+    //\r
+    // sizeof (option-len + Duid-type + UUID-size) = 20 bytes\r
+    //\r
+    Duid = AllocateZeroPool (2 + 2 + sizeof (EFI_GUID));\r
+    if (Duid == NULL) {\r
+      return NULL;\r
+    }\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
+    // sizeof (Duid-type + UUID-size) = 18 bytes\r
+    //\r
+    Duid->Length = (UINT16) (18);\r
+  \r
+    //\r
+    // Set the Duid-type and copy UUID.\r
+    //\r
+    WriteUnaligned16 ((UINT16 *) (Duid->Duid), HTONS (Dhcp6DuidTypeUuid));\r
+  \r
+    CopyMem (Duid->Duid + 2, &Uuid, sizeof(EFI_GUID));\r
+\r
+  } else {\r
+      \r
+    //\r
+    //\r
+    //  The format of DUID-LLT:\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 (1)        |    hardware type (16 bits)    |\r
+    //    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r
+    //    |                        time (32 bits)                         |\r
+    //    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r
+    //    .                                                               .\r
+    //    .             link-layer address (variable length)              .\r
+    //    .                                                               .\r
+    //    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\r
+    //\r
 \r
-  CopyMem (Duid->Duid + 8, &Mode->CurrentAddress, Mode->HwAddressSize);\r
+    //\r
+    // Generate a time stamp of the seconds from 2000/1/1, assume 30day/month.\r
+    //\r
+    gRT->GetTime (&Time, NULL);\r
+    Stamp = (UINT32)\r
+      (\r
+        (((((Time.Year - 2000) * 360 + (Time.Month - 1)) * 30 + (Time.Day - 1)) * 24 + Time.Hour) * 60 + Time.Minute) *\r
+        60 +\r
+        Time.Second\r
+      );\r
+\r
+    //\r
+    // sizeof (option-len + Duid-type + hardware-type + time) = 10 bytes\r
+    //\r
+    Duid = AllocateZeroPool (10 + Mode->HwAddressSize);\r
+    if (Duid == NULL) {\r
+      return NULL;\r
+    }\r
+  \r
+    //\r
+    // sizeof (Duid-type + hardware-type + time) = 8 bytes\r
+    //\r
+    Duid->Length = (UINT16) (Mode->HwAddressSize + 8);\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
+    CopyMem (Duid->Duid + 8, &Mode->CurrentAddress, Mode->HwAddressSize);\r
+  }\r
 \r
   Status = gRT->SetVariable (\r
                   L"ClientId",\r
@@ -540,7 +585,7 @@ Dhcp6DummyExtFree (
 /**\r
   The callback routine once message transmitted.\r
 \r
-  @param[in]  Udp6Wrap      The pointer to the received net buffer.\r
+  @param[in]  Wrap          The pointer to the received net buffer.\r
   @param[in]  EndPoint      The pointer to the udp end point.\r
   @param[in]  IoStatus      The return status from udp io.\r
   @param[in]  Context       The opaque parameter to the function.\r