]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/TcpDxe/ComponentName.c
Initialize data and correct faulty logic in TcpComponentNameGetControllerName().
[mirror_edk2.git] / NetworkPkg / TcpDxe / ComponentName.c
index f1e0e62f73cae86b3f59e8fafc847e474adc71aa..41eb5a5e13b63376e4b39b54cdb1833c99e8d6d2 100644 (file)
@@ -2,7 +2,7 @@
   Implementation of protocols EFI_COMPONENT_NAME_PROTOCOL and\r
   EFI_COMPONENT_NAME2_PROTOCOL.\r
 \r
-  Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2015, 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
@@ -170,6 +170,8 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE        mTcpDriverNameTabl
   }\r
 };\r
 \r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE        *gTcpControllerNameTable = NULL;\r
+\r
 /**\r
   Retrieves a Unicode string that is the user-readable name of the driver.\r
 \r
@@ -224,6 +226,144 @@ TcpComponentNameGetDriverName (
            );\r
 }\r
 \r
+/**\r
+  Update the component name for the Tcp4 child handle.\r
+\r
+  @param  Tcp4[in]                   A pointer to the EFI_TCP4_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
+UpdateTcp4Name (\r
+  IN    EFI_TCP4_PROTOCOL             *Tcp4\r
+  )\r
+{\r
+  EFI_STATUS                       Status;\r
+  CHAR16                           HandleName[80];\r
+  EFI_TCP4_CONFIG_DATA             Tcp4ConfigData;\r
+\r
+  if (Tcp4 == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Format the child name into the string buffer as:\r
+  // TCPv4 (SrcPort=59, DestPort=60, ActiveFlag=TRUE)\r
+  //\r
+  ZeroMem (&Tcp4ConfigData, sizeof (Tcp4ConfigData));\r
+  Status = Tcp4->GetModeData (Tcp4, NULL, &Tcp4ConfigData, NULL, NULL, NULL);\r
+  if (!EFI_ERROR (Status)) {\r
+    UnicodeSPrint (HandleName, sizeof (HandleName),\r
+      L"TCPv4 (SrcPort=%d, DestPort=%d, ActiveFlag=%s)",\r
+      Tcp4ConfigData.AccessPoint.StationPort,\r
+      Tcp4ConfigData.AccessPoint.RemotePort,\r
+      (Tcp4ConfigData.AccessPoint.ActiveFlag ? L"TRUE" : L"FALSE")\r
+      );\r
+  } else if (Status == EFI_NOT_STARTED) {\r
+    UnicodeSPrint (\r
+      HandleName,\r
+      sizeof (HandleName),\r
+      L"TCPv4 (Not started)"\r
+      );\r
+  } else {\r
+    return Status;\r
+  }\r
+\r
+  if (gTcpControllerNameTable != NULL) {\r
+    FreeUnicodeStringTable (gTcpControllerNameTable);\r
+    gTcpControllerNameTable = NULL;\r
+  }\r
+  \r
+  Status = AddUnicodeString2 (\r
+             "eng",\r
+             gTcpComponentName.SupportedLanguages,\r
+             &gTcpControllerNameTable,\r
+             HandleName,\r
+             TRUE\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  \r
+  return AddUnicodeString2 (\r
+           "en",\r
+           gTcpComponentName2.SupportedLanguages,\r
+           &gTcpControllerNameTable,\r
+           HandleName,\r
+           FALSE\r
+           );\r
+}\r
+\r
+/**\r
+  Update the component name for the Tcp6 child handle.\r
+\r
+  @param  Tcp6[in]                   A pointer to the EFI_TCP6_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
+UpdateTcp6Name (\r
+  IN    EFI_TCP6_PROTOCOL             *Tcp6\r
+  )\r
+{\r
+  EFI_STATUS                       Status;\r
+  CHAR16                           HandleName[80];\r
+  EFI_TCP6_CONFIG_DATA             Tcp6ConfigData;\r
+\r
+  if (Tcp6 == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Format the child name into the string buffer.\r
+  //\r
+  ZeroMem (&Tcp6ConfigData, sizeof (Tcp6ConfigData));\r
+  Status = Tcp6->GetModeData (Tcp6, NULL, &Tcp6ConfigData, NULL, NULL, NULL);\r
+  if (!EFI_ERROR (Status)) {\r
+    UnicodeSPrint (HandleName, sizeof (HandleName),\r
+      L"TCPv6(SrcPort=%d, DestPort=%d, ActiveFlag=%d)",\r
+      Tcp6ConfigData.AccessPoint.StationPort,\r
+      Tcp6ConfigData.AccessPoint.RemotePort,\r
+      Tcp6ConfigData.AccessPoint.ActiveFlag\r
+      );\r
+  } else if (Status == EFI_NOT_STARTED) {\r
+    UnicodeSPrint (HandleName, sizeof (HandleName), L"TCPv6(Not started)");\r
+  } else {\r
+    return Status;\r
+  }\r
+\r
+\r
+  if (gTcpControllerNameTable != NULL) {\r
+    FreeUnicodeStringTable (gTcpControllerNameTable);\r
+    gTcpControllerNameTable = NULL;\r
+  }\r
+  \r
+  Status = AddUnicodeString2 (\r
+             "eng",\r
+             gTcpComponentName.SupportedLanguages,\r
+             &gTcpControllerNameTable,\r
+             HandleName,\r
+             TRUE\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  \r
+  return AddUnicodeString2 (\r
+           "en",\r
+           gTcpComponentName2.SupportedLanguages,\r
+           &gTcpControllerNameTable,\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
@@ -300,5 +440,89 @@ TcpComponentNameGetControllerName (
   OUT CHAR16                       **ControllerName\r
   )\r
 {\r
-  return EFI_UNSUPPORTED;\r
+  EFI_STATUS                    Status;\r
+  EFI_TCP4_PROTOCOL             *Tcp4;\r
+  EFI_TCP6_PROTOCOL             *Tcp6;\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
+             &gEfiIp6ProtocolGuid\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
+                    &gEfiTcp6ProtocolGuid,\r
+                   (VOID **)&Tcp6,\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 = UpdateTcp6Name (Tcp6);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Make sure this driver is currently managing ControllHandle\r
+  //\r
+  Status = EfiTestChildHandle (\r
+             ControllerHandle,\r
+             ChildHandle,\r
+             &gEfiIp4ProtocolGuid\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
+               &gEfiTcp4ProtocolGuid,\r
+              (VOID **)&Tcp4,\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 = UpdateTcp4Name (Tcp4);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  return LookupUnicodeString2 (\r
+           Language,\r
+           This->SupportedLanguages,\r
+           gTcpControllerNameTable,\r
+           ControllerName,\r
+           (BOOLEAN)(This == &gTcpComponentName)\r
+           );\r
 }\r
+\r