]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/Dhcp6Dxe/ComponentName.c
1. Add EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName() support.
[mirror_edk2.git] / NetworkPkg / Dhcp6Dxe / ComponentName.c
index 178c8bca45a60482fb9581df3b5b56dc6abdecee..352df087f91b11afd0e881b783de6cf8555467dc 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   UEFI Component Name(2) protocol implementation for Dhcp6 driver.\r
 \r
 /** @file\r
   UEFI Component Name(2) protocol implementation for Dhcp6 driver.\r
 \r
-  Copyright (c) 2009 - 2011, 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
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -172,6 +172,19 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE       mDhcp6DriverNameTab
   }\r
 };\r
 \r
   }\r
 };\r
 \r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE   *gDhcp6ControllerNameTable = NULL;\r
+\r
+CHAR16 *mDhcp6ControllerName[] = {\r
+  L"DHCPv6 (State=0, Init)",\r
+  L"DHCPv6 (State=1, Selecting)",\r
+  L"DHCPv6 (State=2, Requesting)",\r
+  L"DHCPv6 (State=3, Declining)",\r
+  L"DHCPv6 (State=4, Confirming)",\r
+  L"DHCPv6 (State=5, Releasing)",\r
+  L"DHCPv6 (State=6, Bound)",\r
+  L"DHCPv6 (State=7, Renewing)",\r
+  L"DHCPv6 (State=8, Rebinding)"\r
+};\r
 \r
 /**\r
   Retrieves a Unicode string that is the user-readable name of the driver.\r
 \r
 /**\r
   Retrieves a Unicode string that is the user-readable name of the driver.\r
@@ -229,6 +242,67 @@ Dhcp6ComponentNameGetDriverName (
            );\r
 }\r
 \r
            );\r
 }\r
 \r
+/**\r
+  Update the component name for the Dhcp6 child handle.\r
+\r
+  @param  Dhcp6[in]                   A pointer to the EFI_DHCP6_PROTOCOL.\r
+\r
+  \r
+  @retval EFI_SUCCESS                 Update the ControllerNameTable of this instance successfully.\r
+  @retval EFI_INVALID_PARAMETER       The input parameter is invalid.\r
+  \r
+**/\r
+EFI_STATUS\r
+UpdateName (\r
+  IN   EFI_DHCP6_PROTOCOL             *Dhcp6\r
+  )\r
+{\r
+  EFI_STATUS                       Status;\r
+  EFI_DHCP6_MODE_DATA              Dhcp6ModeData;\r
+  CHAR16                           HandleName[64];\r
+\r
+  if (Dhcp6 == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Format the child name into the string buffer.\r
+  //\r
+  Status = Dhcp6->GetModeData (Dhcp6, &Dhcp6ModeData, NULL);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  \r
+  if (gDhcp6ControllerNameTable != NULL) {\r
+    FreeUnicodeStringTable (gDhcp6ControllerNameTable);\r
+    gDhcp6ControllerNameTable = NULL;\r
+  }\r
+  \r
+  if (Dhcp6ModeData.Ia == NULL) {\r
+    UnicodeSPrint (HandleName, sizeof (HandleName), L"DHCPv6 (No configured IA)");\r
+  } else {\r
+    StrCpy (HandleName, mDhcp6ControllerName[Dhcp6ModeData.Ia->State]);\r
+  }\r
+  \r
+  Status = AddUnicodeString2 (\r
+             "eng",\r
+             gDhcp6ComponentName.SupportedLanguages,\r
+             &gDhcp6ControllerNameTable,\r
+             HandleName,\r
+             TRUE\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  \r
+  return AddUnicodeString2 (\r
+           "en",\r
+           gDhcp6ComponentName2.SupportedLanguages,\r
+           &gDhcp6ControllerNameTable,\r
+           HandleName,\r
+           FALSE\r
+           );\r
+}\r
 \r
 /**\r
   Retrieves a Unicode string that is the user-readable name of the controller\r
 \r
 /**\r
   Retrieves a Unicode string that is the user-readable name of the controller\r
@@ -308,5 +382,57 @@ Dhcp6ComponentNameGetControllerName (
   OUT CHAR16                                          **ControllerName\r
   )\r
 {\r
   OUT CHAR16                                          **ControllerName\r
   )\r
 {\r
-  return EFI_UNSUPPORTED;\r
+  EFI_STATUS                    Status;\r
+  EFI_DHCP6_PROTOCOL            *Dhcp6;\r
+\r
+  //\r
+  // Only provide names for child handles.\r
+  //\r
+  if (ChildHandle == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  \r
+  // \r
+  // Make sure this driver produced ChildHandle \r
+  // \r
+  Status = EfiTestChildHandle (\r
+             ControllerHandle,\r
+             ChildHandle, \r
+             &gEfiUdp6ProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Retrieve an instance of a produced protocol from ChildHandle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ChildHandle,\r
+                  &gEfiDhcp6ProtocolGuid,\r
+                  (VOID **)&Dhcp6, \r
+                  NULL,\r
+                  NULL,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Update the component name for this child handle.\r
+  //\r
+  Status = UpdateName (Dhcp6);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return LookupUnicodeString2 (\r
+           Language,\r
+           This->SupportedLanguages,\r
+           gDhcp6ControllerNameTable,\r
+           ControllerName,\r
+           (BOOLEAN)(This == &gDhcp6ComponentName)\r
+           );\r
 }\r
 }\r
+\r