]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/SnpDxe/ComponentName.c
BaseTools:Change the path of the file that Binary Cache
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / ComponentName.c
index e8da93010ce4aac347c8fe0de6bcb4ea2398427f..2139e2a47f534c83f16269e0cfd6f5db1d5746ce 100644 (file)
@@ -1,25 +1,12 @@
 /** @file\r
+    UEFI Component Name(2) protocol implementation for SnpDxe driver.\r
 \r
-Copyright (c) 2004 - 2007, Intel Corporation\r
-All rights reserved. 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
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-Module Name:\r
-\r
-  ComponentName.c\r
-\r
-Abstract:\r
-\r
+Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 \r
-\r
 #include "Snp.h"\r
 \r
 //\r
@@ -45,7 +32,7 @@ Abstract:
                                 languages specified in SupportedLanguages. The\r
                                 number of languages supported by a driver is up\r
                                 to the driver writer. Language is specified\r
-                                in RFC 3066 or ISO 639-2 language code format.\r
+                                in RFC 4646 or ISO 639-2 language code format.\r
 \r
   @param  DriverName[out]       A pointer to the Unicode string to return.\r
                                 This Unicode string is the name of the\r
@@ -110,7 +97,7 @@ SimpleNetworkComponentNameGetDriverName (
                                 languages specified in SupportedLanguages. The\r
                                 number of languages supported by a driver is up\r
                                 to the driver writer. Language is specified in\r
-                                RFC 3066 or ISO 639-2 language code format.\r
+                                RFC 4646 or ISO 639-2 language code format.\r
 \r
   @param  ControllerName[out]   A pointer to the Unicode string to return.\r
                                 This Unicode string is the name of the\r
@@ -124,7 +111,7 @@ SimpleNetworkComponentNameGetDriverName (
                                 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
@@ -182,6 +169,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
@@ -202,7 +191,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mSimpleNetworkDriverNameT
                                 languages specified in SupportedLanguages. The\r
                                 number of languages supported by a driver is up\r
                                 to the driver writer. Language is specified\r
-                                in RFC 3066 or ISO 639-2 language code format.\r
+                                in RFC 4646 or ISO 639-2 language code format.\r
 \r
   @param  DriverName[out]       A pointer to the Unicode string to return.\r
                                 This Unicode string is the name of the\r
@@ -238,6 +227,79 @@ 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 * sizeof (CHAR16),\r
+                L"%02X-",\r
+                Snp->Mode->CurrentAddress.Addr[Index]\r
+                );\r
+  }\r
+  ASSERT (OffSet > 0);\r
+  //\r
+  // Remove the last '-'\r
+  //\r
+  OffSet--;\r
+  OffSet += UnicodeSPrint (\r
+              HandleName + OffSet,\r
+              sizeof (HandleName) - OffSet * sizeof (CHAR16),\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
@@ -250,6 +312,7 @@ SimpleNetworkComponentNameGetDriverName (
   managing the controller specified by ControllerHandle and ChildHandle,\r
   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not\r
   support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
+  Currently not implemented.\r
 \r
   @param  This[in]              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
                                 EFI_COMPONENT_NAME_PROTOCOL instance.\r
@@ -275,7 +338,7 @@ SimpleNetworkComponentNameGetDriverName (
                                 languages specified in SupportedLanguages. The\r
                                 number of languages supported by a driver is up\r
                                 to the driver writer. Language is specified in\r
-                                RFC 3066 or ISO 639-2 language code format.\r
+                                RFC 4646 or ISO 639-2 language code format.\r
 \r
   @param  ControllerName[out]   A pointer to the Unicode string to return.\r
                                 This Unicode string is the name of the\r
@@ -289,7 +352,7 @@ SimpleNetworkComponentNameGetDriverName (
                                 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
@@ -316,5 +379,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