]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/SnpDxe/ComponentName.c
1. Add EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName() support.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / ComponentName.c
index e8f7ec18bc03ee50a53f7aef784cb9a2ce63d478..ef499d18cf6578b96d83e58636ca72edad72dfc8 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
     UEFI Component Name(2) protocol implementation for SnpDxe driver.\r
 \r
-Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed \r
 and made available under the terms and conditions of the BSD License which \r
 accompanies this distribution. The full text of the license may be found at \r
@@ -175,6 +175,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mSimpleNetworkDriverNameT
   }\r
 };\r
 \r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gSimpleNetworkControllerNameTable = NULL;\r
+\r
 /**\r
   Retrieves a Unicode string that is the user readable name of the driver.\r
 \r
@@ -231,6 +233,78 @@ SimpleNetworkComponentNameGetDriverName (
            );\r
 }\r
 \r
+/**\r
+  Update the component name for the Snp child handle.\r
+\r
+  @param  Snp[in]                   A pointer to the EFI_SIMPLE_NETWORK_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_SIMPLE_NETWORK_PROTOCOL   *Snp\r
+  )\r
+{\r
+  EFI_STATUS                       Status;\r
+  CHAR16                           HandleName[80];\r
+  UINTN                            OffSet;\r
+  UINTN                            Index;\r
+\r
+  if (Snp == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OffSet = 0;\r
+  OffSet += UnicodeSPrint (\r
+              HandleName,\r
+              sizeof (HandleName),\r
+              L"SNP (MAC="\r
+              );\r
+  for (Index = 0; Index < Snp->Mode->HwAddressSize; Index++) {\r
+    OffSet += UnicodeSPrint (\r
+                HandleName + OffSet,\r
+                sizeof (HandleName) - OffSet,\r
+                L"%02X-",\r
+                Snp->Mode->CurrentAddress.Addr[Index]\r
+                );\r
+  }\r
+  //\r
+  // Remove the last '-'\r
+  //\r
+  OffSet--;\r
+  OffSet += UnicodeSPrint (\r
+              HandleName,\r
+              sizeof (HandleName),\r
+              L")"\r
+              );\r
+  if (gSimpleNetworkControllerNameTable != NULL) {\r
+    FreeUnicodeStringTable (gSimpleNetworkControllerNameTable);\r
+    gSimpleNetworkControllerNameTable = NULL;\r
+  }\r
+  \r
+  Status = AddUnicodeString2 (\r
+             "eng",\r
+             gSimpleNetworkComponentName.SupportedLanguages,\r
+             &gSimpleNetworkControllerNameTable,\r
+             HandleName,\r
+             TRUE\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  \r
+  return AddUnicodeString2 (\r
+           "en",\r
+           gSimpleNetworkComponentName2.SupportedLanguages,\r
+           &gSimpleNetworkControllerNameTable,\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
@@ -310,5 +384,52 @@ SimpleNetworkComponentNameGetControllerName (
   OUT CHAR16                                          **ControllerName\r
   )\r
 {\r
-  return EFI_UNSUPPORTED;\r
+  EFI_STATUS                    Status;\r
+  EFI_SIMPLE_NETWORK_PROTOCOL   *Snp;\r
+  \r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Make sure this driver is currently managing ControllHandle\r
+  //\r
+  Status = EfiTestManagedDevice (\r
+             ControllerHandle,\r
+             gSimpleNetworkDriverBinding.DriverBindingHandle,\r
+             &gEfiSimpleNetworkProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  // \r
+  // Retrieve an instance of a produced protocol from ControllerHandle\r
+  // \r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiSimpleNetworkProtocolGuid,\r
+                  (VOID **)&Snp,\r
+                  NULL,\r
+                  NULL,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Update the component name for this child handle.\r
+  //\r
+  Status = UpdateName (Snp);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return LookupUnicodeString2 (\r
+           Language,\r
+           This->SupportedLanguages,\r
+           gSimpleNetworkControllerNameTable,\r
+           ControllerName,\r
+           (BOOLEAN)(This == &gSimpleNetworkComponentName)\r
+           );\r
 }\r