]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigImpl.c
MdeModulePkg: Delete IScsiDxe in MdeModulePkg.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / VlanConfigDxe / VlanConfigImpl.c
index 6d544f53214d22f3c1552ad8f42225881efd9e25..0bdffa2ee4373a45cc4d6258e05b76846b6747f5 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   HII Config Access protocol implementation of VLAN configuration module.\r
 \r
 /** @file\r
   HII Config Access protocol implementation of VLAN configuration module.\r
 \r
-Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions\r
 of the BSD License which accompanies this distribution.  The full\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions\r
 of the BSD License which accompanies this distribution.  The full\r
@@ -15,7 +15,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "VlanConfigImpl.h"\r
 \r
 \r
 #include "VlanConfigImpl.h"\r
 \r
-EFI_GUID                        mVlanFormSetGuid = VLAN_CONFIG_PRIVATE_GUID;\r
 CHAR16                          mVlanStorageName[] = L"VlanNvData";\r
 EFI_HII_CONFIG_ROUTING_PROTOCOL *mHiiConfigRouting = NULL;\r
 \r
 CHAR16                          mVlanStorageName[] = L"VlanNvData";\r
 EFI_HII_CONFIG_ROUTING_PROTOCOL *mHiiConfigRouting = NULL;\r
 \r
@@ -37,7 +36,7 @@ VENDOR_DEVICE_PATH              mHiiVendorDevicePathNode = {
       (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
     }\r
   },\r
       (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
     }\r
   },\r
-  VLAN_CONFIG_PRIVATE_GUID\r
+  VLAN_CONFIG_FORM_SET_GUID\r
 };\r
 \r
 /**\r
 };\r
 \r
 /**\r
@@ -89,7 +88,7 @@ VlanExtractConfig (
   }\r
 \r
   *Progress = Request;\r
   }\r
 \r
   *Progress = Request;\r
-  if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &mVlanFormSetGuid, mVlanStorageName)) {\r
+  if ((Request != NULL) && !HiiIsConfigHdrMatch (Request, &gVlanConfigFormSetGuid, mVlanStorageName)) {\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
     return EFI_NOT_FOUND;\r
   }\r
 \r
@@ -119,7 +118,7 @@ VlanExtractConfig (
     // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r
     // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r
     //\r
     // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r
     // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r
     //\r
-    ConfigRequestHdr = HiiConstructConfigHdr (&mVlanFormSetGuid, mVlanStorageName, PrivateData->DriverHandle);\r
+    ConfigRequestHdr = HiiConstructConfigHdr (&gVlanConfigFormSetGuid, mVlanStorageName, PrivateData->DriverHandle);\r
     Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r
     ConfigRequest = AllocateZeroPool (Size);\r
     ASSERT (ConfigRequest != NULL);\r
     Size = (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16);\r
     ConfigRequest = AllocateZeroPool (Size);\r
     ASSERT (ConfigRequest != NULL);\r
@@ -187,7 +186,7 @@ VlanRouteConfig (
   }\r
 \r
   *Progress = Configuration;\r
   }\r
 \r
   *Progress = Configuration;\r
-  if (!HiiIsConfigHdrMatch (Configuration, &mVlanFormSetGuid, mVlanStorageName)) {\r
+  if (!HiiIsConfigHdrMatch (Configuration, &gVlanConfigFormSetGuid, mVlanStorageName)) {\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
     return EFI_NOT_FOUND;\r
   }\r
 \r
@@ -240,16 +239,23 @@ VlanCallback (
     return EFI_SUCCESS;\r
   }\r
 \r
     return EFI_SUCCESS;\r
   }\r
 \r
-  if (Action == EFI_BROWSER_ACTION_CHANGING) {\r
+  if ((Action != EFI_BROWSER_ACTION_CHANGED) && (Action != EFI_BROWSER_ACTION_CHANGING)) {\r
     //\r
     //\r
-    // Get Browser data\r
+    // All other action return unsupported.\r
     //\r
     //\r
-    Configuration = AllocateZeroPool (sizeof (VLAN_CONFIGURATION));\r
-    ASSERT (Configuration != NULL);\r
-    HiiGetBrowserData (&mVlanFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration);\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Get Browser data\r
+  //\r
+  Configuration = AllocateZeroPool (sizeof (VLAN_CONFIGURATION));\r
+  ASSERT (Configuration != NULL);\r
+  HiiGetBrowserData (&gVlanConfigFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration);\r
 \r
 \r
-    VlanConfig = PrivateData->VlanConfig;\r
+  VlanConfig = PrivateData->VlanConfig;\r
 \r
 \r
+  if (Action == EFI_BROWSER_ACTION_CHANGED) {\r
     switch (QuestionId) {\r
     case VLAN_ADD_QUESTION_ID:\r
       //\r
     switch (QuestionId) {\r
     case VLAN_ADD_QUESTION_ID:\r
       //\r
@@ -305,6 +311,11 @@ VlanCallback (
       ZeroMem (Configuration->VlanList, MAX_VLAN_NUMBER);\r
       break;\r
 \r
       ZeroMem (Configuration->VlanList, MAX_VLAN_NUMBER);\r
       break;\r
 \r
+    default:\r
+      break;\r
+    }\r
+  } else if (Action == EFI_BROWSER_ACTION_CHANGING) {\r
+    switch (QuestionId) {\r
     case VLAN_UPDATE_QUESTION_ID:\r
       //\r
       // Update current VLAN list into Form.\r
     case VLAN_UPDATE_QUESTION_ID:\r
       //\r
       // Update current VLAN list into Form.\r
@@ -315,16 +326,11 @@ VlanCallback (
     default:\r
       break;\r
     }\r
     default:\r
       break;\r
     }\r
-\r
-    HiiSetBrowserData (&mVlanFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration, NULL);\r
-    FreePool (Configuration);\r
-    return EFI_SUCCESS;\r
   }\r
 \r
   }\r
 \r
-  //\r
-  // All other action return unsupported.\r
-  //\r
-  return EFI_UNSUPPORTED;\r
+  HiiSetBrowserData (&gVlanConfigFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration, NULL);\r
+  FreePool (Configuration);\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 \r
 }\r
 \r
 \r
@@ -406,19 +412,27 @@ VlanUpdateForm (
   for (Index = 0; Index < NumberOfVlan; Index++) {\r
     String = VlanStr;\r
 \r
   for (Index = 0; Index < NumberOfVlan; Index++) {\r
     String = VlanStr;\r
 \r
-    StrCpy (String, L"  VLAN ID:");\r
+    StrCpyS (String, (sizeof (VlanStr) /sizeof (CHAR16)), L"  VLAN ID:");\r
     String += 10;\r
     //\r
     // Pad VlanId string up to 4 characters with space\r
     //\r
     String += 10;\r
     //\r
     // Pad VlanId string up to 4 characters with space\r
     //\r
-    DigitalCount = UnicodeValueToString (VlanIdStr, 0, VlanData[Index].VlanId, 5);\r
+    UnicodeValueToStringS (VlanIdStr, sizeof (VlanIdStr), 0, VlanData[Index].VlanId, 5);\r
+    DigitalCount = StrnLenS (VlanIdStr, ARRAY_SIZE (VlanIdStr));\r
     SetMem16 (String, (4 - DigitalCount) * sizeof (CHAR16), L' ');\r
     SetMem16 (String, (4 - DigitalCount) * sizeof (CHAR16), L' ');\r
-    StrCpy (String + 4 - DigitalCount, VlanIdStr);\r
+    StrCpyS (String + 4 - DigitalCount, (sizeof (VlanStr) /sizeof (CHAR16)) - 10 - (4 - DigitalCount), VlanIdStr);\r
     String += 4;\r
 \r
     String += 4;\r
 \r
-    StrCpy (String, L", Priority:");\r
+    StrCpyS (String,  (sizeof (VlanStr) /sizeof (CHAR16)) - 10 - (4 - DigitalCount) - 4, L", Priority:");\r
     String += 11;\r
     String += 11;\r
-    String += UnicodeValueToString (String, 0, VlanData[Index].Priority, 4);\r
+    UnicodeValueToStringS (\r
+      String,\r
+      sizeof (VlanStr) - ((UINTN)String - (UINTN)VlanStr),\r
+      0,\r
+      VlanData[Index].Priority,\r
+      4\r
+      );\r
+    String += StrnLenS (String, ARRAY_SIZE (VlanStr) - ((UINTN)String - (UINTN)VlanStr) / sizeof (CHAR16));\r
     *String = 0;\r
 \r
     StringId = HiiSetString (PrivateData->HiiHandle, 0, VlanStr, NULL);\r
     *String = 0;\r
 \r
     StringId = HiiSetString (PrivateData->HiiHandle, 0, VlanStr, NULL);\r
@@ -444,7 +458,7 @@ VlanUpdateForm (
 \r
   HiiUpdateForm (\r
     PrivateData->HiiHandle,     // HII handle\r
 \r
   HiiUpdateForm (\r
     PrivateData->HiiHandle,     // HII handle\r
-    &mVlanFormSetGuid,          // Formset GUID\r
+    &gVlanConfigFormSetGuid,    // Formset GUID\r
     VLAN_CONFIGURATION_FORM_ID, // Form ID\r
     StartOpCodeHandle,          // Label for where to insert opcodes\r
     EndOpCodeHandle             // Replace data\r
     VLAN_CONFIGURATION_FORM_ID, // Form ID\r
     StartOpCodeHandle,          // Label for where to insert opcodes\r
     EndOpCodeHandle             // Replace data\r
@@ -483,6 +497,7 @@ InstallVlanConfigForm (
   CHAR16                          *MacString;\r
   EFI_DEVICE_PATH_PROTOCOL        *ChildDevicePath;\r
   EFI_HII_CONFIG_ACCESS_PROTOCOL  *ConfigAccess;\r
   CHAR16                          *MacString;\r
   EFI_DEVICE_PATH_PROTOCOL        *ChildDevicePath;\r
   EFI_HII_CONFIG_ACCESS_PROTOCOL  *ConfigAccess;\r
+  EFI_VLAN_CONFIG_PROTOCOL        *VlanConfig;\r
 \r
   //\r
   // Create child handle and install HII Config Access Protocol\r
 \r
   //\r
   // Create child handle and install HII Config Access Protocol\r
@@ -511,11 +526,27 @@ InstallVlanConfigForm (
   }\r
   PrivateData->DriverHandle = DriverHandle;\r
 \r
   }\r
   PrivateData->DriverHandle = DriverHandle;\r
 \r
+  //\r
+  // Establish the parent-child relationship between the new created\r
+  // child handle and the ControllerHandle.\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  PrivateData->ControllerHandle,\r
+                  &gEfiVlanConfigProtocolGuid,\r
+                  (VOID **)&VlanConfig,\r
+                  PrivateData->ImageHandle,\r
+                  PrivateData->DriverHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
   //\r
   // Publish the HII package list\r
   //\r
   HiiHandle = HiiAddPackages (\r
   //\r
   // Publish the HII package list\r
   //\r
   HiiHandle = HiiAddPackages (\r
-                &mVlanFormSetGuid,\r
+                &gVlanConfigFormSetGuid,\r
                 DriverHandle,\r
                 VlanConfigDxeStrings,\r
                 VlanConfigBin,\r
                 DriverHandle,\r
                 VlanConfigDxeStrings,\r
                 VlanConfigBin,\r
@@ -536,9 +567,9 @@ InstallVlanConfigForm (
   }\r
   PrivateData->MacString = MacString;\r
 \r
   }\r
   PrivateData->MacString = MacString;\r
 \r
-  StrCpy (Str, L"VLAN Configuration (MAC:");\r
-  StrnCat (Str, MacString, sizeof (EFI_MAC_ADDRESS) * 2);\r
-  StrCat (Str, L")");\r
+  StrCpyS (Str, sizeof (Str) / sizeof (CHAR16), L"VLAN Configuration (MAC:");\r
+  StrCatS (Str, sizeof (Str) / sizeof (CHAR16), MacString);\r
+  StrCatS (Str, sizeof (Str) / sizeof (CHAR16), L")");\r
   HiiSetString (\r
     HiiHandle,\r
     STRING_TOKEN (STR_VLAN_FORM_SET_TITLE_HELP),\r
   HiiSetString (\r
     HiiHandle,\r
     STRING_TOKEN (STR_VLAN_FORM_SET_TITLE_HELP),\r
@@ -565,40 +596,54 @@ InstallVlanConfigForm (
 \r
   @param[in, out]  PrivateData   Points to VLAN configuration private data.\r
 \r
 \r
   @param[in, out]  PrivateData   Points to VLAN configuration private data.\r
 \r
+  @retval EFI_SUCCESS            HII Form has been uninstalled successfully.\r
+  @retval Others                 Other errors as indicated.\r
+\r
 **/\r
 **/\r
-VOID\r
+EFI_STATUS\r
 UninstallVlanConfigForm (\r
   IN OUT VLAN_CONFIG_PRIVATE_DATA    *PrivateData\r
   )\r
 {\r
 UninstallVlanConfigForm (\r
   IN OUT VLAN_CONFIG_PRIVATE_DATA    *PrivateData\r
   )\r
 {\r
-  //\r
-  // Free MAC string\r
-  //\r
-  if (PrivateData->MacString != NULL) {\r
-    FreePool (PrivateData->MacString);\r
-    PrivateData->MacString = NULL;\r
-  }\r
+  EFI_STATUS                   Status;\r
+  EFI_VLAN_CONFIG_PROTOCOL     *VlanConfig;\r
 \r
   //\r
 \r
   //\r
-  // Uninstall HII package list\r
+  // End the parent-child relationship.\r
   //\r
   //\r
-  if (PrivateData->HiiHandle != NULL) {\r
-    HiiRemovePackages (PrivateData->HiiHandle);\r
-    PrivateData->HiiHandle = NULL;\r
+  Status = gBS->CloseProtocol (\r
+                  PrivateData->ControllerHandle,\r
+                  &gEfiVlanConfigProtocolGuid,\r
+                  PrivateData->ImageHandle,\r
+                  PrivateData->DriverHandle\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
   }\r
 \r
   //\r
   // Uninstall HII Config Access Protocol\r
   //\r
   if (PrivateData->DriverHandle != NULL) {\r
   }\r
 \r
   //\r
   // Uninstall HII Config Access Protocol\r
   //\r
   if (PrivateData->DriverHandle != NULL) {\r
-    gBS->UninstallMultipleProtocolInterfaces (\r
-           PrivateData->DriverHandle,\r
-           &gEfiDevicePathProtocolGuid,\r
-           PrivateData->ChildDevicePath,\r
-           &gEfiHiiConfigAccessProtocolGuid,\r
-           &PrivateData->ConfigAccess,\r
-           NULL\r
-           );\r
+    Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                    PrivateData->DriverHandle,\r
+                    &gEfiDevicePathProtocolGuid,\r
+                    PrivateData->ChildDevicePath,\r
+                    &gEfiHiiConfigAccessProtocolGuid,\r
+                    &PrivateData->ConfigAccess,\r
+                    NULL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      gBS->OpenProtocol (\r
+             PrivateData->ControllerHandle,\r
+             &gEfiVlanConfigProtocolGuid,\r
+             (VOID **)&VlanConfig,\r
+             PrivateData->ImageHandle,\r
+             PrivateData->DriverHandle,\r
+             EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+             );\r
+      return Status;\r
+    }\r
     PrivateData->DriverHandle = NULL;\r
 \r
     if (PrivateData->ChildDevicePath != NULL) {\r
     PrivateData->DriverHandle = NULL;\r
 \r
     if (PrivateData->ChildDevicePath != NULL) {\r
@@ -606,4 +651,21 @@ UninstallVlanConfigForm (
       PrivateData->ChildDevicePath = NULL;\r
     }\r
   }\r
       PrivateData->ChildDevicePath = NULL;\r
     }\r
   }\r
+\r
+  //\r
+  // Free MAC string\r
+  //\r
+  if (PrivateData->MacString != NULL) {\r
+    FreePool (PrivateData->MacString);\r
+    PrivateData->MacString = NULL;\r
+  }\r
+\r
+  //\r
+  // Uninstall HII package list\r
+  //\r
+  if (PrivateData->HiiHandle != NULL) {\r
+    HiiRemovePackages (PrivateData->HiiHandle);\r
+    PrivateData->HiiHandle = NULL;\r
+  }\r
+  return EFI_SUCCESS;\r
 }\r
 }\r