]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/Ip6Dxe/ComponentName.c
Clean up the code. Action statement should not have text two opcode.
[mirror_edk2.git] / NetworkPkg / Ip6Dxe / ComponentName.c
index c8382f74a9fc66b0855eda880649fed81bdce8bf..75a1562ca07f31e2e3d1b78bf3c2f31763effde4 100644 (file)
@@ -2,7 +2,7 @@
   Implementation of EFI_COMPONENT_NAME_PROTOCOL and\r
   EFI_COMPONENT_NAME2_PROTOCOL protocol.\r
 \r
   Implementation of EFI_COMPONENT_NAME_PROTOCOL and\r
   EFI_COMPONENT_NAME2_PROTOCOL protocol.\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
 \r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
@@ -118,7 +118,7 @@ Ip6ComponentNameGetDriverName (
                                 driver specified by This was returned in\r
                                 DriverName.\r
 \r
                                 driver specified by This was returned in\r
                                 DriverName.\r
 \r
-  @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
 \r
   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid\r
                                 EFI_HANDLE.\r
 \r
   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid\r
                                 EFI_HANDLE.\r
@@ -174,6 +174,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE      mIp6DriverNameTable[
   }\r
 };\r
 \r
   }\r
 };\r
 \r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE      *gIp6ControllerNameTable = NULL;\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
 \r
@@ -231,6 +233,88 @@ Ip6ComponentNameGetDriverName (
 \r
 }\r
 \r
 \r
 }\r
 \r
+/**\r
+  Update the component name for the IP6 child handle.\r
+\r
+  @param  Ip6[in]                   A pointer to the EFI_IP6_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_IP6_PROTOCOL         *Ip6\r
+  )\r
+{\r
+  EFI_STATUS                       Status;\r
+  CHAR16                           HandleName[128];\r
+  EFI_IP6_MODE_DATA                Ip6ModeData;\r
+  UINTN                            Offset;\r
+  CHAR16                           Address[sizeof"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];\r
+\r
+  if (Ip6 == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Format the child name into the string buffer.\r
+  //\r
+  Offset = 0;\r
+  Status = Ip6->GetModeData (Ip6, &Ip6ModeData, NULL, NULL);\r
+  if (!EFI_ERROR (Status) && Ip6ModeData.IsStarted) {\r
+    Status = NetLibIp6ToStr (&Ip6ModeData.ConfigData.StationAddress, Address, sizeof(Address));\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+    Offset += UnicodeSPrint (\r
+                HandleName,\r
+                sizeof(HandleName),\r
+                L"IPv6(StationAddress=%s, ",\r
+                Address\r
+                );\r
+    Status = NetLibIp6ToStr (&Ip6ModeData.ConfigData.DestinationAddress, Address, sizeof(Address));\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+    UnicodeSPrint (\r
+      HandleName + Offset,\r
+      sizeof(HandleName) - Offset * sizeof (CHAR16),\r
+      L"DestinationAddress=%s)",\r
+      Address\r
+      );\r
+  } else if (!Ip6ModeData.IsStarted) {\r
+    UnicodeSPrint (HandleName, sizeof(HandleName), L"IPv6(Not started)");\r
+  } else {\r
+    UnicodeSPrint (HandleName, sizeof(HandleName), L"IPv6(%r)", Status);\r
+  }\r
+\r
+  if (gIp6ControllerNameTable != NULL) {\r
+      FreeUnicodeStringTable (gIp6ControllerNameTable);\r
+      gIp6ControllerNameTable = NULL;\r
+  }\r
+  \r
+  Status = AddUnicodeString2 (\r
+             "eng",\r
+             gIp6ComponentName.SupportedLanguages,\r
+             &gIp6ControllerNameTable,\r
+             HandleName,\r
+             TRUE\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  \r
+  return AddUnicodeString2 (\r
+           "en",\r
+           gIp6ComponentName2.SupportedLanguages,\r
+           &gIp6ControllerNameTable,\r
+           HandleName,\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
 /**\r
   Retrieves a Unicode string that is the user-readable name of the controller\r
   that is being managed by a driver.\r
@@ -282,7 +366,7 @@ Ip6ComponentNameGetDriverName (
                                 driver specified by This was returned in\r
                                 DriverName.\r
 \r
                                 driver specified by This was returned in\r
                                 DriverName.\r
 \r
-  @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
+  @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
 \r
   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid\r
                                 EFI_HANDLE.\r
 \r
   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL, and it is not a valid\r
                                 EFI_HANDLE.\r
@@ -309,5 +393,56 @@ Ip6ComponentNameGetControllerName (
   OUT CHAR16                                          **ControllerName\r
   )\r
 {\r
   OUT CHAR16                                          **ControllerName\r
   )\r
 {\r
-  return EFI_UNSUPPORTED;\r
+  EFI_STATUS                    Status;\r
+  EFI_IP6_PROTOCOL              *Ip6;\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
+             &gEfiManagedNetworkProtocolGuid\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
+                  &gEfiIp6ProtocolGuid,\r
+                  (VOID **)&Ip6,\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 (Ip6);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return LookupUnicodeString2 (\r
+           Language,\r
+           This->SupportedLanguages,\r
+           gIp6ControllerNameTable,\r
+           ControllerName,\r
+           (BOOLEAN)(This == &gIp6ComponentName)\r
+           );\r
 }\r
 }\r