]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/Dhcp4Dxe/ComponentName.c
1. Add EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName() support.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Dhcp4Dxe / ComponentName.c
index e9d86fb56e23b7a2d336aa525d05f61797c6c485..2ea07608f1c7d51eadcf5706ad341bb6a9181b09 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2012, 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
@@ -174,6 +174,20 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mDhcpDriverNameTable[] =
   }\r
 };\r
 \r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE    *gDhcpControllerNameTable = NULL;\r
+\r
+CHAR16 *mDhcp4ControllerName[] = {\r
+  L"DHCPv4 (State=0, Stopped)",\r
+  L"DHCPv4 (State=1, Init)",\r
+  L"DHCPv4 (State=2, Selecting)",\r
+  L"DHCPv4 (State=3, Requesting)",\r
+  L"DHCPv4 (State=4, Bound)",\r
+  L"DHCPv4 (State=5, Renewing)",\r
+  L"DHCPv4 (State=6, Rebinding)",\r
+  L"DHCPv4 (State=7, InitReboot)",\r
+  L"DHCPv4 (State=8, Rebooting)"\r
+};\r
+\r
 /**\r
   Retrieves a Unicode string that is the user readable name of the driver.\r
 \r
@@ -230,6 +244,66 @@ DhcpComponentNameGetDriverName (
            );\r
 }\r
 \r
+/**\r
+  Update the component name for the Dhcp4 child handle.\r
+\r
+  @param  Dhcp4[in]               A pointer to the EFI_DHCP4_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
+  @retval EFI_DEVICE_ERROR        DHCP is in unknown state.\r
+  \r
+**/\r
+EFI_STATUS\r
+UpdateName (\r
+  IN     EFI_DHCP4_PROTOCOL             *Dhcp4\r
+  )\r
+{\r
+  EFI_STATUS                       Status;\r
+  EFI_DHCP4_MODE_DATA              Dhcp4ModeData;\r
+\r
+  if (Dhcp4 == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Format the child name into the string buffer.\r
+  //\r
+  Status = Dhcp4->GetModeData (Dhcp4, &Dhcp4ModeData);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  \r
+  if (gDhcpControllerNameTable != NULL) {\r
+    FreeUnicodeStringTable (gDhcpControllerNameTable);\r
+    gDhcpControllerNameTable = NULL;\r
+  }\r
+  \r
+  if (Dhcp4ModeData.State > Dhcp4Rebooting) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+  \r
+  Status = AddUnicodeString2 (\r
+             "eng",\r
+             gDhcp4ComponentName.SupportedLanguages,\r
+             &gDhcpControllerNameTable,\r
+             mDhcp4ControllerName[Dhcp4ModeData.State],\r
+             TRUE\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  \r
+  return AddUnicodeString2 (\r
+           "en",\r
+           gDhcp4ComponentName2.SupportedLanguages,\r
+           &gDhcpControllerNameTable,\r
+           mDhcp4ControllerName[Dhcp4ModeData.State],\r
+           FALSE\r
+           );\r
+}\r
+\r
 /**\r
   Retrieves a Unicode string that is the user readable name of the controller\r
   that is being managed by a driver.\r
@@ -308,5 +382,56 @@ DhcpComponentNameGetControllerName (
   OUT CHAR16                                          **ControllerName\r
   )\r
 {\r
-  return EFI_UNSUPPORTED;\r
+  EFI_STATUS                    Status;\r
+  EFI_DHCP4_PROTOCOL            *Dhcp4;\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
+             &gEfiUdp4ProtocolGuid\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
+                  &gEfiDhcp4ProtocolGuid,\r
+                  (VOID **)&Dhcp4,\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 (Dhcp4);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return LookupUnicodeString2 (\r
+           Language,\r
+           This->SupportedLanguages,\r
+           gDhcpControllerNameTable,\r
+           ControllerName,\r
+           (BOOLEAN)(This == &gDhcp4ComponentName)\r
+           );\r
 }\r