]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/VlanConfigDxe/VlanConfigImpl.c
1. Add EFI_COMPONENT_NAME2_PROTOCOL.GetControllerName() support.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / VlanConfigDxe / VlanConfigImpl.c
index e9e98fa225a8372e9407c4a660ddb5f7930b6619..10fb7fa670b5bb329154af2989ba50cd4a667001 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   HII Config Access protocol implementation of VLAN configuration module.\r
 \r
-Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2009 - 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\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
-EFI_GUID                        mVlanFormSetGuid = VLAN_CONFIG_PRIVATE_GUID;\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
-  VLAN_CONFIG_PRIVATE_GUID\r
+  VLAN_CONFIG_FORM_SET_GUID\r
 };\r
 \r
 /**\r
@@ -89,7 +88,7 @@ VlanExtractConfig (
   }\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
@@ -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
-    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
@@ -187,7 +186,7 @@ VlanRouteConfig (
   }\r
 \r
   *Progress = Configuration;\r
-  if (!HiiIsConfigHdrMatch (Configuration, &mVlanFormSetGuid, mVlanStorageName)) {\r
+  if (!HiiIsConfigHdrMatch (Configuration, &gVlanConfigFormSetGuid, mVlanStorageName)) {\r
     return EFI_NOT_FOUND;\r
   }\r
 \r
@@ -236,22 +235,15 @@ VlanCallback (
 \r
   PrivateData = VLAN_CONFIG_PRIVATE_DATA_FROM_THIS (This);\r
 \r
-  if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {\r
-    if (QuestionId == VLAN_ADD_QUESTION_ID) {\r
-      //\r
-      // Update current VLAN list into Form when Form is opened.\r
-      // This will be done only in FORM_OPEN CallBack of question with VLAN_ADD_QUESTION_ID.\r
-      //\r
-      VlanUpdateForm (PrivateData);\r
-    }\r
+  if ((Action == EFI_BROWSER_ACTION_FORM_OPEN) || (Action == EFI_BROWSER_ACTION_FORM_CLOSE)) {\r
     return EFI_SUCCESS;\r
   }\r
 \r
-  if (Action == EFI_BROWSER_ACTION_FORM_CLOSE) {\r
+  if ((Action != EFI_BROWSER_ACTION_CHANGED) && (Action != EFI_BROWSER_ACTION_CHANGING)) {\r
     //\r
-    // Do nothing for UEFI FORM_CLOSE action\r
+    // All other action return unsupported.\r
     //\r
-    return EFI_SUCCESS;\r
+    return EFI_UNSUPPORTED;\r
   }\r
 \r
   //\r
@@ -259,70 +251,84 @@ VlanCallback (
   //\r
   Configuration = AllocateZeroPool (sizeof (VLAN_CONFIGURATION));\r
   ASSERT (Configuration != NULL);\r
-  HiiGetBrowserData (&mVlanFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration);\r
+  HiiGetBrowserData (&gVlanConfigFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration);\r
 \r
   VlanConfig = PrivateData->VlanConfig;\r
 \r
-  switch (QuestionId) {\r
-  case VLAN_ADD_QUESTION_ID:\r
-    //\r
-    // Add a VLAN\r
-    //\r
-    VlanConfig->Set (VlanConfig, Configuration->VlanId, Configuration->Priority);\r
-    VlanUpdateForm (PrivateData);\r
+  if (Action == EFI_BROWSER_ACTION_CHANGED) {\r
+    switch (QuestionId) {\r
+    case VLAN_ADD_QUESTION_ID:\r
+      //\r
+      // Add a VLAN\r
+      //\r
+      VlanConfig->Set (VlanConfig, Configuration->VlanId, Configuration->Priority);\r
+      VlanUpdateForm (PrivateData);\r
 \r
-    //\r
-    // Connect the newly created VLAN device\r
-    //\r
-    VlanHandle = NetLibGetVlanHandle (PrivateData->ControllerHandle, Configuration->VlanId);\r
-    if (VlanHandle == NULL) {\r
       //\r
-      // There may be no child handle created for VLAN ID 0, connect the parent handle\r
+      // Connect the newly created VLAN device\r
       //\r
-      VlanHandle = PrivateData->ControllerHandle;\r
-    }\r
-    gBS->ConnectController (VlanHandle, NULL, NULL, TRUE);\r
+      VlanHandle = NetLibGetVlanHandle (PrivateData->ControllerHandle, Configuration->VlanId);\r
+      if (VlanHandle == NULL) {\r
+        //\r
+        // There may be no child handle created for VLAN ID 0, connect the parent handle\r
+        //\r
+        VlanHandle = PrivateData->ControllerHandle;\r
+      }\r
+      gBS->ConnectController (VlanHandle, NULL, NULL, TRUE);\r
 \r
-    //\r
-    // Clear UI data\r
-    //\r
-    *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
-    Configuration->VlanId = 0;\r
-    Configuration->Priority = 0;\r
-    break;\r
+      //\r
+      // Clear UI data\r
+      //\r
+      *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r
+      Configuration->VlanId = 0;\r
+      Configuration->Priority = 0;\r
+      break;\r
 \r
-  case VLAN_REMOVE_QUESTION_ID:\r
-    //\r
-    // Remove VLAN\r
-    //\r
-    ASSERT (PrivateData->NumberOfVlan <= MAX_VLAN_NUMBER);\r
-    for (Index = 0; Index < PrivateData->NumberOfVlan; Index++) {\r
-      if (Configuration->VlanList[Index] != 0) {\r
+    case VLAN_REMOVE_QUESTION_ID:\r
+      //\r
+      // Remove VLAN\r
+      //\r
+      ASSERT (PrivateData->NumberOfVlan <= MAX_VLAN_NUMBER);\r
+      for (Index = 0; Index < PrivateData->NumberOfVlan; Index++) {\r
+        if (Configuration->VlanList[Index] != 0) {\r
+          //\r
+          // Checkbox is selected, need remove this VLAN\r
+          //\r
+          VlanConfig->Remove (VlanConfig, PrivateData->VlanId[Index]);\r
+        }\r
+      }\r
+\r
+      VlanUpdateForm (PrivateData);\r
+      if (PrivateData->NumberOfVlan == 0) {\r
         //\r
-        // Checkbox is selected, need remove this VLAN\r
+        // No VLAN device now, connect the physical NIC handle.\r
+        // Note: PrivateData->NumberOfVlan has been updated by VlanUpdateForm()\r
         //\r
-        VlanConfig->Remove (VlanConfig, PrivateData->VlanId[Index]);\r
+        gBS->ConnectController (PrivateData->ControllerHandle, NULL, NULL, TRUE);\r
       }\r
-    }\r
 \r
-    VlanUpdateForm (PrivateData);\r
-    if (PrivateData->NumberOfVlan == 0) {\r
+      *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\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
-      // No VLAN device now, connect the physical NIC handle.\r
-      // Note: PrivateData->NumberOfVlan has been updated by VlanUpdateForm()\r
+      // Update current VLAN list into Form.\r
       //\r
-      gBS->ConnectController (PrivateData->ControllerHandle, NULL, NULL, TRUE);\r
-    }\r
-\r
-    *ActionRequest = EFI_BROWSER_ACTION_REQUEST_SUBMIT;\r
-    ZeroMem (Configuration->VlanList, MAX_VLAN_NUMBER);\r
-    break;\r
+      VlanUpdateForm (PrivateData);\r
+      break;\r
 \r
-  default:\r
-    break;\r
+    default:\r
+      break;\r
+    }\r
   }\r
-\r
-  HiiSetBrowserData (&mVlanFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration, NULL);\r
+  \r
+  HiiSetBrowserData (&gVlanConfigFormSetGuid, mVlanStorageName, sizeof (VLAN_CONFIGURATION), (UINT8 *) Configuration, NULL);\r
   FreePool (Configuration);\r
   return EFI_SUCCESS;\r
 }\r
@@ -444,7 +450,7 @@ VlanUpdateForm (
 \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
@@ -483,6 +489,7 @@ InstallVlanConfigForm (
   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
@@ -511,11 +518,27 @@ InstallVlanConfigForm (
   }\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
-                &mVlanFormSetGuid,\r
+                &gVlanConfigFormSetGuid,\r
                 DriverHandle,\r
                 VlanConfigDxeStrings,\r
                 VlanConfigBin,\r
@@ -527,7 +550,7 @@ InstallVlanConfigForm (
   PrivateData->HiiHandle = HiiHandle;\r
 \r
   //\r
-  // Update formset title\r
+  // Update formset title help string.\r
   //\r
   MacString = NULL;\r
   Status = NetLibGetMacString (PrivateData->ControllerHandle, PrivateData->ImageHandle, &MacString);\r
@@ -547,7 +570,7 @@ InstallVlanConfigForm (
     );\r
 \r
   //\r
-  // Update form title\r
+  // Update form title help string.\r
   //\r
   HiiSetString (\r
     HiiHandle,\r
@@ -587,6 +610,16 @@ UninstallVlanConfigForm (
     PrivateData->HiiHandle = NULL;\r
   }\r
 \r
+  //\r
+  // End the parent-child relationship.\r
+  //\r
+  gBS->CloseProtocol (\r
+         PrivateData->ControllerHandle,\r
+         &gEfiVlanConfigProtocolGuid,\r
+         PrivateData->ImageHandle,\r
+         PrivateData->DriverHandle\r
+         );\r
+\r
   //\r
   // Uninstall HII Config Access Protocol\r
   //\r