]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/IScsiDxe/ComponentName.c
1. Add EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName() support.
[mirror_edk2.git] / NetworkPkg / IScsiDxe / ComponentName.c
index e4e28e8961efdacace45bb37ee070e67d6439c2b..1ee21f5d5d33b807f3c1e023d680abcf8e33c08f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   UEFI Component Name(2) protocol implementation for iSCSI.\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\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
@@ -43,6 +43,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE     mIScsiDriverNameTable
   }\r
 };\r
 \r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE  *gIScsiControllerNameTable = NULL;\r
+\r
 /**\r
   Retrieves a Unicode string that is the user readable name of the driver.\r
 \r
@@ -99,6 +101,99 @@ IScsiComponentNameGetDriverName (
            );\r
 }\r
 \r
+/**\r
+  Update the component name for the iSCSI NIC handle.\r
+\r
+  @param[in]  Controller            The handle of the NIC controller.\r
+  @param[in]  Ipv6Flag              TRUE if IP6 network stack is used.\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_HANDLE  Controller,\r
+  IN   BOOLEAN     Ipv6Flag\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_MAC_ADDRESS             MacAddr;\r
+  UINTN                       HwAddressSize;\r
+  UINT16                      VlanId;\r
+  ISCSI_NIC_INFO              *ThisNic;\r
+  ISCSI_NIC_INFO              *NicInfo;\r
+  LIST_ENTRY                  *Entry;\r
+  CHAR16                      HandleName[80];\r
+\r
+  //\r
+  // Get MAC address of this network device.\r
+  //\r
+  Status = NetLibGetMacAddress (Controller, &MacAddr, &HwAddressSize);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Get VLAN ID of this network device.\r
+  //\r
+  VlanId = NetLibGetVlanId (Controller);\r
+\r
+  //\r
+  // Check whether the NIC information exists.\r
+  //\r
+  ThisNic = NULL;\r
+\r
+  NET_LIST_FOR_EACH (Entry, &mPrivate->NicInfoList) {\r
+    NicInfo = NET_LIST_USER_STRUCT (Entry, ISCSI_NIC_INFO, Link);\r
+    if (NicInfo->HwAddressSize == HwAddressSize &&\r
+        CompareMem (&NicInfo->PermanentAddress, MacAddr.Addr, HwAddressSize) == 0 &&\r
+        NicInfo->VlanId == VlanId) {\r
+\r
+      ThisNic = NicInfo;\r
+      break;\r
+    }\r
+  }\r
+\r
+  if (ThisNic == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  UnicodeSPrint (\r
+    HandleName,\r
+    sizeof (HandleName),\r
+    L"iSCSI (%s, NicIndex=%d)",\r
+    Ipv6Flag ? L"IPv6" : L"IPv4",\r
+    ThisNic->NicIndex\r
+  );\r
+\r
+  if (gIScsiControllerNameTable != NULL) {\r
+    FreeUnicodeStringTable (gIScsiControllerNameTable);\r
+    gIScsiControllerNameTable = NULL;\r
+  }\r
+\r
+  Status = AddUnicodeString2 (\r
+             "eng",\r
+             gIScsiComponentName.SupportedLanguages,\r
+             &gIScsiControllerNameTable,\r
+             HandleName,\r
+             TRUE\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return AddUnicodeString2 (\r
+           "en",\r
+           gIScsiComponentName2.SupportedLanguages,\r
+           &gIScsiControllerNameTable,\r
+           HandleName,\r
+           FALSE\r
+           );\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
@@ -177,5 +272,54 @@ IScsiComponentNameGetControllerName (
   OUT CHAR16                        **ControllerName\r
   )\r
 {\r
-  return EFI_UNSUPPORTED;\r
+  EFI_HANDLE                      IScsiController;\r
+  BOOLEAN                         Ipv6Flag;\r
+  EFI_STATUS                      Status;\r
+  EFI_GUID                        *IScsiPrivateGuid;\r
+  ISCSI_PRIVATE_PROTOCOL          *IScsiIdentifier;\r
+\r
+  //\r
+  // Get the handle of the controller we are controling.\r
+  //\r
+  IScsiController = NetLibGetNicHandle (ControllerHandle, &gEfiTcp4ProtocolGuid);\r
+  if (IScsiController != NULL) {\r
+    IScsiPrivateGuid = &gIScsiV4PrivateGuid;\r
+    Ipv6Flag = FALSE;\r
+  } else {\r
+    IScsiController = NetLibGetNicHandle (ControllerHandle, &gEfiTcp6ProtocolGuid);\r
+    if (IScsiController != NULL) {\r
+      IScsiPrivateGuid = &gIScsiV6PrivateGuid;\r
+      Ipv6Flag = TRUE;\r
+    } else {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+  }\r
+\r
+  // \r
+  // Retrieve an instance of a produced protocol from IScsiController  \r
+  // \r
+  Status = gBS->OpenProtocol (\r
+                  IScsiController,\r
+                  IScsiPrivateGuid,\r
+                  (VOID **) &IScsiIdentifier,\r
+                  NULL,\r
+                  NULL,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = UpdateName(IScsiController, Ipv6Flag);\r
+  if (EFI_ERROR(Status)) {\r
+    return Status;\r
+  }\r
+\r
+  return LookupUnicodeString2 (\r
+           Language,\r
+           This->SupportedLanguages,\r
+           gIScsiControllerNameTable,\r
+           ControllerName,\r
+           (BOOLEAN)(This == &gIScsiComponentName)\r
+           );\r
 }\r