]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/IScsiDxe/ComponentName.c
Verified ChildHandle, and correct the name for a child.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / IScsiDxe / ComponentName.c
index e88587a4bbc8d15f13c904e381dd7a535128cb1a..063b3722921ac9f630a706835fe573b43b343e70 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   UEFI Component Name(2) protocol implementation for iSCSI.\r
 \r
 /** @file\r
   UEFI Component Name(2) protocol implementation for iSCSI.\r
 \r
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2015, 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
 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
@@ -37,10 +37,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mIScsiDriverNameTable[] =
   {NULL, NULL}\r
 };\r
 \r
   {NULL, NULL}\r
 };\r
 \r
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE  mIScsiControllerNameTable[] = {\r
-  {"eng;en", L"iSCSI (IPv4)"},\r
-  {NULL, NULL}\r
-};\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE  *mIScsiControllerNameTable = NULL;\r
 \r
 /**\r
   Retrieves a Unicode string that is the user readable name of the EFI Driver.\r
 \r
 /**\r
   Retrieves a Unicode string that is the user readable name of the EFI Driver.\r
@@ -87,6 +84,77 @@ IScsiComponentNameGetDriverName (
           );\r
 }\r
 \r
           );\r
 }\r
 \r
+/**\r
+  Update the component name for the iSCSI instance.\r
+\r
+  @param[in]  IScsiExtScsiPassThru  A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\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_UNSUPPORTED           Can't get the corresponding NIC info from the Controller handle.\r
+  \r
+**/\r
+EFI_STATUS\r
+UpdateName (\r
+  IN   EFI_EXT_SCSI_PASS_THRU_PROTOCOL *IScsiExtScsiPassThru\r
+  )\r
+{\r
+  EFI_STATUS                       Status;\r
+  CHAR16                           HandleName[150];\r
+  ISCSI_DRIVER_DATA                *Private;\r
+  EFI_MAC_ADDRESS                  MacAddress;\r
+  UINTN                            HwAddressSize;\r
+  UINT16                           VlanId;\r
+  CHAR16                           MacString[70];\r
+\r
+  if (IScsiExtScsiPassThru == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  Private  = ISCSI_DRIVER_DATA_FROM_EXT_SCSI_PASS_THRU (IScsiExtScsiPassThru);\r
+\r
+  //\r
+  // Get the mac string, it's the name of various variable\r
+  //\r
+  Status = NetLibGetMacAddress (Private->Controller, &MacAddress, &HwAddressSize);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  VlanId = NetLibGetVlanId (Private->Controller);\r
+  IScsiMacAddrToStr (&MacAddress, (UINT32) HwAddressSize, VlanId, MacString);\r
+    \r
+  UnicodeSPrint (\r
+    HandleName,\r
+    sizeof (HandleName),\r
+    L"iSCSI IPv4 (MacString=%s)",\r
+    MacString\r
+  );\r
+\r
+  if (mIScsiControllerNameTable != NULL) {\r
+    FreeUnicodeStringTable (mIScsiControllerNameTable);\r
+    mIScsiControllerNameTable = NULL;\r
+  }\r
+\r
+  Status = AddUnicodeString2 (\r
+             "eng",\r
+             gIScsiComponentName.SupportedLanguages,\r
+             &mIScsiControllerNameTable,\r
+             HandleName,\r
+             TRUE\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return AddUnicodeString2 (\r
+           "en",\r
+           gIScsiComponentName2.SupportedLanguages,\r
+           &mIScsiControllerNameTable,\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 an EFI Driver.Currently not implemented.\r
 /**\r
   Retrieves a Unicode string that is the user readable name of the controller\r
   that is being managed by an EFI Driver.Currently not implemented.\r
@@ -136,10 +204,17 @@ IScsiComponentNameGetControllerName (
   OUT CHAR16                        **ControllerName\r
   )\r
 {\r
   OUT CHAR16                        **ControllerName\r
   )\r
 {\r
+  EFI_STATUS                      Status;\r
+\r
   EFI_HANDLE                      IScsiController;\r
   ISCSI_PRIVATE_PROTOCOL          *IScsiIdentifier;\r
   EFI_HANDLE                      IScsiController;\r
   ISCSI_PRIVATE_PROTOCOL          *IScsiIdentifier;\r
-  EFI_STATUS                      Status;\r
-  \r
+\r
+  EFI_EXT_SCSI_PASS_THRU_PROTOCOL *IScsiExtScsiPassThru;\r
+\r
+  if (ControllerHandle == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
   //\r
   // Get the handle of the controller we are controling.\r
   //\r
   //\r
   // Get the handle of the controller we are controling.\r
   //\r
@@ -159,6 +234,43 @@ IScsiComponentNameGetControllerName (
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
+\r
+  if (ChildHandle != NULL) {\r
+    //\r
+    // Make sure this driver produced ChildHandle\r
+    //\r
+    Status = EfiTestChildHandle (\r
+               ControllerHandle,\r
+               ChildHandle,\r
+               &gEfiTcp4ProtocolGuid\r
+               );\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Retrieve an instance of a produced protocol from ChildHandle\r
+      //\r
+      Status = gBS->OpenProtocol (\r
+                      ChildHandle,\r
+                      &gEfiExtScsiPassThruProtocolGuid,\r
+                     (VOID **)&IScsiExtScsiPassThru,\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 (IScsiExtScsiPassThru);\r
+      if (EFI_ERROR (Status)) {\r
+        return Status;\r
+      }\r
+    } else {\r
+      return Status;\r
+    }\r
+  }\r
   \r
   return LookupUnicodeString2 (\r
            Language,\r
   \r
   return LookupUnicodeString2 (\r
            Language,\r