]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c
Add VLAN support.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / IScsiDxe / IScsiConfig.c
index 34942f752a05030f0eec3768599f53ade77c8732..35214f2ce95b19c09d7f7b0ee286b22584c51516 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Helper functions for configuring or getting the parameters relating to iSCSI.\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation.<BR>\r
+Copyright (c) 2004 - 2009, Intel Corporation.<BR>\r
 All rights reserved. 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
@@ -15,6 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include "IScsiImpl.h"\r
 \r
 EFI_GUID        mVendorGuid              = ISCSI_CONFIG_GUID;\r
+CHAR16          mVendorStorageName[]     = L"ISCSI_CONFIG_IFR_NVDATA";\r
 BOOLEAN         mIScsiDeviceListUpdated  = FALSE;\r
 UINTN           mNumberOfIScsiDevices    = 0;\r
 ISCSI_FORM_CALLBACK_INFO  *mCallbackInfo = NULL;\r
@@ -66,7 +67,7 @@ IScsiIpToStr (
 \r
 /**\r
   Update the list of iSCSI devices the iSCSI driver is controlling.\r
-  \r
+\r
   @retval EFI_SUCCESS            The callback successfully handled the action.\r
   @retval Others                 Other errors as indicated.   \r
 **/\r
@@ -83,19 +84,20 @@ IScsiUpdateDeviceList (
   UINTN                       HandleIndex;\r
   UINTN                       Index;\r
   UINTN                       LastDeviceIndex;\r
-  EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
-  EFI_SIMPLE_NETWORK_MODE     *Mode;\r
+  EFI_MAC_ADDRESS             MacAddress;\r
+  UINTN                       HwAddressSize;\r
+  UINT16                      VlanId;\r
   ISCSI_MAC_INFO              *CurMacInfo;\r
   ISCSI_MAC_INFO              TempMacInfo;\r
-  CHAR16                      MacString[65];\r
+  CHAR16                      MacString[70];\r
   UINTN                       DeviceListSize;\r
 \r
   //\r
-  // Dump all the handles the Simple Network Protocol is installed on.\r
+  // Dump all the handles the Managed Network Service Binding Protocol is installed on.\r
   //\r
   Status = gBS->LocateHandleBuffer (\r
                   ByProtocol,\r
-                  &gEfiSimpleNetworkProtocolGuid,\r
+                  &gEfiManagedNetworkServiceBindingProtocolGuid,\r
                   NULL,\r
                   &NumHandles,\r
                   &Handles\r
@@ -126,14 +128,15 @@ IScsiUpdateDeviceList (
     LastDeviceIndex = 0;\r
 \r
     for (HandleIndex = 0; HandleIndex < NumHandles; HandleIndex++) {\r
-      gBS->HandleProtocol (Handles[HandleIndex], &gEfiSimpleNetworkProtocolGuid, (VOID **)&Snp);\r
-\r
-      Mode = Snp->Mode;\r
+      Status = NetLibGetMacAddress (Handles[HandleIndex], &MacAddress, &HwAddressSize);\r
+      ASSERT (Status == EFI_SUCCESS);\r
+      VlanId = NetLibGetVlanId (Handles[HandleIndex]);\r
 \r
       for (Index = LastDeviceIndex; Index < DeviceList->NumDevice; Index++) {\r
         CurMacInfo = &DeviceList->MacInfo[Index];\r
-        if ((CurMacInfo->Len == Mode->HwAddressSize) &&\r
-            (NET_MAC_EQUAL (&CurMacInfo->Mac, &Mode->PermanentAddress, Mode->HwAddressSize))\r
+        if ((CurMacInfo->Len == HwAddressSize) &&\r
+            (CurMacInfo->VlanId == VlanId) &&\r
+            (NET_MAC_EQUAL (&CurMacInfo->Mac, MacAddress.Addr, HwAddressSize))\r
             ) {\r
           //\r
           // The previous configured NIC is still here.\r
@@ -162,14 +165,14 @@ IScsiUpdateDeviceList (
       // delete the variables\r
       //\r
       CurMacInfo = &DeviceList->MacInfo[Index];\r
-      IScsiMacAddrToStr (&CurMacInfo->Mac, CurMacInfo->Len, MacString);\r
+      IScsiMacAddrToStr (&CurMacInfo->Mac, CurMacInfo->Len, CurMacInfo->VlanId, MacString);\r
       gRT->SetVariable (MacString, &gEfiIScsiInitiatorNameProtocolGuid, 0, 0, NULL);\r
       gRT->SetVariable (MacString, &mIScsiCHAPAuthInfoGuid, 0, 0, NULL);\r
     }\r
 \r
-    gBS->FreePool (DeviceList);\r
+    FreePool (DeviceList);\r
   } else if (Status != EFI_NOT_FOUND) {\r
-    gBS->FreePool (Handles);\r
+    FreePool (Handles);\r
     return Status;\r
   }\r
   //\r
@@ -180,12 +183,12 @@ IScsiUpdateDeviceList (
   DeviceList->NumDevice = (UINT8) NumHandles;\r
 \r
   for (Index = 0; Index < NumHandles; Index++) {\r
-    gBS->HandleProtocol (Handles[Index], &gEfiSimpleNetworkProtocolGuid, (VOID **)&Snp);\r
-    Mode        = Snp->Mode;\r
+    NetLibGetMacAddress (Handles[Index], &MacAddress, &HwAddressSize);\r
 \r
     CurMacInfo  = &DeviceList->MacInfo[Index];\r
-    CopyMem (&CurMacInfo->Mac, &Mode->PermanentAddress, Mode->HwAddressSize);\r
-    CurMacInfo->Len = (UINT8) Mode->HwAddressSize;\r
+    CopyMem (&CurMacInfo->Mac, MacAddress.Addr, HwAddressSize);\r
+    CurMacInfo->Len = (UINT8) HwAddressSize;\r
+    CurMacInfo->VlanId = NetLibGetVlanId (Handles[Index]);\r
   }\r
 \r
   gRT->SetVariable (\r
@@ -196,8 +199,8 @@ IScsiUpdateDeviceList (
         DeviceList\r
         );\r
 \r
-  gBS->FreePool (DeviceList);\r
-  gBS->FreePool (Handles);\r
+  FreePool (DeviceList);\r
+  FreePool (Handles);\r
 \r
   return Status;\r
 }\r
@@ -358,9 +361,10 @@ IScsiFormExtractConfig (
   ISCSI_FORM_CALLBACK_INFO         *Private;\r
   EFI_HII_CONFIG_ROUTING_PROTOCOL  *HiiConfigRouting;\r
 \r
-  if (Request == NULL) {\r
+  if (Request == NULL || Progress == NULL || Results == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
+  *Progress = Request;\r
 \r
   if (!mIScsiDeviceListUpdated) {\r
     //\r
@@ -398,7 +402,7 @@ IScsiFormExtractConfig (
                                Results,\r
                                Progress\r
                                );\r
-  gBS->FreePool (IfrNvData);\r
+  FreePool (IfrNvData);\r
   return Status;\r
 }\r
 \r
@@ -425,7 +429,7 @@ IScsiFormExtractConfig (
 \r
   @retval EFI_SUCCESS             The results have been distributed or are\r
                                   awaiting distribution.  \r
-  @retval EFI_OUT_OF_MEMORY       Not enough memory to store the\r
+  @retval EFI_OUT_OF_RESOURCES    Not enough memory to store the\r
                                   parts of the results that must be\r
                                   stored awaiting possible future\r
                                   protocols.\r
@@ -443,6 +447,20 @@ IScsiFormRouteConfig (
   OUT EFI_STRING                             *Progress\r
   )\r
 {\r
+  if (Configuration == NULL || Progress == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Check routing data in <ConfigHdr>.\r
+  // Note: if only one Storage is used, then this checking could be skipped.\r
+  //\r
+  if (!HiiIsConfigHdrMatch (Configuration, &mVendorGuid, mVendorStorageName)) {\r
+    *Progress = Configuration;\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  *Progress = Configuration + StrLen (Configuration);\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -504,14 +522,14 @@ IScsiFormCallback (
   //\r
   // Retrive uncommitted data from Browser\r
   //\r
-  BufferSize = sizeof (ISCSI_CONFIG_IFR_NVDATA);\r
-  IfrNvData = AllocateZeroPool (BufferSize);\r
+  IfrNvData = AllocateZeroPool (sizeof (ISCSI_CONFIG_IFR_NVDATA));\r
   ASSERT (IfrNvData != NULL);\r
-  Status = GetBrowserData (NULL, NULL, &BufferSize, (UINT8 *) IfrNvData);\r
-  if (EFI_ERROR (Status)) {\r
-    gBS->FreePool (IfrNvData);\r
-    return Status;\r
+  if (!HiiGetBrowserData (&mVendorGuid, mVendorStorageName, sizeof (ISCSI_CONFIG_IFR_NVDATA), (UINT8 *) IfrNvData)) {\r
+    FreePool (IfrNvData);\r
+    return EFI_NOT_FOUND;\r
   }\r
+  \r
+  Status = EFI_SUCCESS;\r
 \r
   switch (QuestionId) {\r
   case KEY_INITIATOR_NAME:\r
@@ -528,7 +546,7 @@ IScsiFormCallback (
   case KEY_LOCAL_IP:\r
     IScsiUnicodeStrToAsciiStr (IfrNvData->LocalIp, Ip4String);\r
     Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4);\r
-    if (EFI_ERROR (Status) || !Ip4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
+    if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
       CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r
       Status = EFI_INVALID_PARAMETER;\r
     } else {\r
@@ -552,7 +570,7 @@ IScsiFormCallback (
   case KEY_GATE_WAY:\r
     IScsiUnicodeStrToAsciiStr (IfrNvData->Gateway, Ip4String);\r
     Status = IScsiAsciiStrToIp (Ip4String, &Gateway.v4);\r
-    if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !Ip4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) {\r
+    if (EFI_ERROR (Status) || ((Gateway.Addr[0] != 0) && !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), 0))) {\r
       CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL);\r
       Status = EFI_INVALID_PARAMETER;\r
     } else {\r
@@ -564,7 +582,7 @@ IScsiFormCallback (
   case KEY_TARGET_IP:\r
     IScsiUnicodeStrToAsciiStr (IfrNvData->TargetIp, Ip4String);\r
     Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4);\r
-    if (EFI_ERROR (Status) || !Ip4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
+    if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
       CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r
       Status = EFI_INVALID_PARAMETER;\r
     } else {\r
@@ -662,7 +680,7 @@ IScsiFormCallback (
       //\r
       if (!Private->Current->SessionConfigData.TargetInfoFromDhcp) {\r
         CopyMem (&HostIp.v4, &Private->Current->SessionConfigData.TargetIp, sizeof (HostIp.v4));\r
-        if (!Ip4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
+        if (!NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
           CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Target IP is invalid!", NULL);\r
           Status = EFI_INVALID_PARAMETER;\r
           break;\r
@@ -716,7 +734,7 @@ IScsiFormCallback (
 \r
       UnicodeSPrint (PortString, (UINTN) 128, L"Port %s", ConfigFormEntry->MacString);\r
       DeviceFormTitleToken = (EFI_STRING_ID) STR_ISCSI_DEVICE_FORM_TITLE;\r
-      HiiLibSetString (Private->RegisteredHandle, DeviceFormTitleToken, PortString);\r
+      HiiSetString (Private->RegisteredHandle, DeviceFormTitleToken, PortString, NULL);\r
 \r
       IScsiConvertDeviceConfigDataToIfrNvData (ConfigFormEntry, IfrNvData);\r
 \r
@@ -730,11 +748,10 @@ IScsiFormCallback (
     //\r
     // Pass changed uncommitted data back to Form Browser\r
     //\r
-    BufferSize = sizeof (ISCSI_CONFIG_IFR_NVDATA);\r
-    Status = SetBrowserData (NULL, NULL, BufferSize, (UINT8 *) IfrNvData, NULL);\r
+    HiiSetBrowserData (&mVendorGuid, mVendorStorageName, sizeof (ISCSI_CONFIG_IFR_NVDATA), (UINT8 *) IfrNvData, NULL);\r
   }\r
 \r
-  gBS->FreePool (IfrNvData);\r
+  FreePool (IfrNvData);\r
   return Status;\r
 }\r
 \r
@@ -761,12 +778,16 @@ IScsiConfigUpdateForm (
   ISCSI_CONFIG_FORM_ENTRY     *ConfigFormEntry;\r
   BOOLEAN                     EntryExisted;\r
   EFI_STATUS                  Status;\r
-  EFI_HII_UPDATE_DATA         UpdateData;\r
-  EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
+  EFI_MAC_ADDRESS             MacAddress;\r
+  UINTN                       HwAddressSize;\r
+  UINT16                      VlanId;\r
   CHAR16                      PortString[128];\r
   UINT16                      FormIndex;\r
   UINTN                       BufferSize;\r
-\r
+  VOID                        *StartOpCodeHandle;\r
+  VOID                        *EndOpCodeHandle;\r
+  EFI_IFR_GUID_LABEL          *StartLabel;\r
+  EFI_IFR_GUID_LABEL          *EndLabel;\r
 \r
   ConfigFormEntry = NULL;\r
   EntryExisted    = FALSE;\r
@@ -796,17 +817,13 @@ IScsiConfigUpdateForm (
       ConfigFormEntry->Controller = Controller;\r
 \r
       //\r
-      // Get the simple network protocol and convert the MAC address into\r
-      // the formatted string.\r
+      // Get the MAC address and convert it into the formatted string.\r
       //\r
-      Status = gBS->HandleProtocol (\r
-                      Controller,\r
-                      &gEfiSimpleNetworkProtocolGuid,\r
-                      (VOID **)&Snp\r
-                      );\r
+      Status = NetLibGetMacAddress (Controller, &MacAddress, &HwAddressSize);\r
       ASSERT (Status == EFI_SUCCESS);\r
+      VlanId = NetLibGetVlanId (Controller);\r
 \r
-      IScsiMacAddrToStr (&Snp->Mode->PermanentAddress, Snp->Mode->HwAddressSize, ConfigFormEntry->MacString);\r
+      IScsiMacAddrToStr (&MacAddress, (UINT32) HwAddressSize, VlanId, ConfigFormEntry->MacString);\r
 \r
       //\r
       // Get the normal session configuration data.\r
@@ -840,13 +857,13 @@ IScsiConfigUpdateForm (
       // Compose the Port string and create a new EFI_STRING_ID.\r
       //\r
       UnicodeSPrint (PortString, 128, L"Port %s", ConfigFormEntry->MacString);\r
-      HiiLibNewString (mCallbackInfo->RegisteredHandle, &ConfigFormEntry->PortTitleToken, PortString);\r
+      ConfigFormEntry->PortTitleToken = HiiSetString (mCallbackInfo->RegisteredHandle, 0, PortString, NULL);\r
 \r
       //\r
       // Compose the help string of this port and create a new EFI_STRING_ID.\r
       //\r
       UnicodeSPrint (PortString, 128, L"Set the iSCSI parameters on port %s", ConfigFormEntry->MacString);\r
-      HiiLibNewString (mCallbackInfo->RegisteredHandle, &ConfigFormEntry->PortTitleHelpToken, PortString);\r
+      ConfigFormEntry->PortTitleHelpToken = HiiSetString (mCallbackInfo->RegisteredHandle, 0, PortString, NULL);\r
 \r
       InsertTailList (&mIScsiConfigFormList, &ConfigFormEntry->Link);\r
       mNumberOfIScsiDevices++;\r
@@ -856,41 +873,61 @@ IScsiConfigUpdateForm (
 \r
     mNumberOfIScsiDevices--;\r
     RemoveEntryList (&ConfigFormEntry->Link);\r
-    gBS->FreePool (ConfigFormEntry);\r
+    FreePool (ConfigFormEntry);\r
   }\r
   //\r
   // Allocate space for creation of Buffer\r
   //\r
-  UpdateData.BufferSize = 0x1000;\r
-  UpdateData.Data = AllocateZeroPool (0x1000);\r
-  UpdateData.Offset = 0;\r
+\r
+  //\r
+  // Init OpCode Handle\r
+  //\r
+  StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
+  ASSERT (StartOpCodeHandle != NULL);\r
+\r
+  EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
+  ASSERT (EndOpCodeHandle != NULL);\r
+\r
+  //\r
+  // Create Hii Extend Label OpCode as the start opcode\r
+  //\r
+  StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
+  StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
+  StartLabel->Number       = DEVICE_ENTRY_LABEL;\r
+\r
+  //\r
+  // Create Hii Extend Label OpCode as the end opcode\r
+  //\r
+  EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
+  EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
+  EndLabel->Number       = LABEL_END;\r
 \r
   FormIndex = 0;\r
   NET_LIST_FOR_EACH (Entry, &mIScsiConfigFormList) {\r
     ConfigFormEntry = NET_LIST_USER_STRUCT (Entry, ISCSI_CONFIG_FORM_ENTRY, Link);\r
 \r
-    CreateGotoOpCode (\r
-      FORMID_DEVICE_FORM,\r
-      ConfigFormEntry->PortTitleToken,\r
-      ConfigFormEntry->PortTitleHelpToken,\r
-      EFI_IFR_FLAG_CALLBACK,\r
-      (UINT16)(KEY_DEVICE_ENTRY_BASE + FormIndex),\r
-      &UpdateData\r
+    HiiCreateGotoOpCode (\r
+      StartOpCodeHandle,                            // Container for dynamic created opcodes\r
+      FORMID_DEVICE_FORM,                           // Target Form ID\r
+      ConfigFormEntry->PortTitleToken,              // Prompt text\r
+      ConfigFormEntry->PortTitleHelpToken,          // Help text\r
+      EFI_IFR_FLAG_CALLBACK,                        // Question flag\r
+      (UINT16)(KEY_DEVICE_ENTRY_BASE + FormIndex)   // Question ID\r
       );\r
 \r
     FormIndex++;\r
   }\r
 \r
-  IfrLibUpdateForm (\r
+  HiiUpdateForm (\r
     mCallbackInfo->RegisteredHandle,\r
     &mVendorGuid,\r
     FORMID_MAIN_FORM,\r
-    DEVICE_ENTRY_LABEL,\r
-    FALSE,\r
-    &UpdateData\r
+    StartOpCodeHandle, // Label DEVICE_ENTRY_LABEL\r
+    EndOpCodeHandle    // LABEL_END\r
     );\r
 \r
-  gBS->FreePool (UpdateData.Data);\r
+  HiiFreeOpCodeHandle (StartOpCodeHandle);\r
+  HiiFreeOpCodeHandle (EndOpCodeHandle);\r
 \r
   return EFI_SUCCESS;\r
 }\r
@@ -911,7 +948,6 @@ IScsiConfigFormInit (
 {\r
   EFI_STATUS                  Status;\r
   EFI_HII_DATABASE_PROTOCOL   *HiiDatabase;\r
-  EFI_HII_PACKAGE_LIST_HEADER *PackageList;\r
   ISCSI_FORM_CALLBACK_INFO    *CallbackInfo;\r
 \r
   Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **)&HiiDatabase);\r
@@ -954,19 +990,16 @@ IScsiConfigFormInit (
   //\r
   // Publish our HII data\r
   //\r
-  PackageList = HiiLibPreparePackageList (2, &mVendorGuid, IScsiDxeStrings, IScsiConfigDxeBin);\r
-  ASSERT (PackageList != NULL);\r
-  \r
-  Status = HiiDatabase->NewPackageList (\r
-                           HiiDatabase,\r
-                           PackageList,\r
-                           CallbackInfo->DriverHandle,\r
-                           &CallbackInfo->RegisteredHandle\r
-                           );\r
-  FreePool (PackageList);\r
-  if (EFI_ERROR (Status)) {\r
+  CallbackInfo->RegisteredHandle = HiiAddPackages (\r
+                                     &mVendorGuid,\r
+                                     CallbackInfo->DriverHandle,\r
+                                     IScsiDxeStrings,\r
+                                     IScsiConfigDxeBin,\r
+                                     NULL\r
+                                     );\r
+  if (CallbackInfo->RegisteredHandle == NULL) {\r
     FreePool(CallbackInfo);\r
-    return Status;\r
+    return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
   mCallbackInfo = CallbackInfo;\r
@@ -1022,7 +1055,7 @@ IScsiConfigFormUnload (
          &mCallbackInfo->ConfigAccess,\r
          NULL\r
          );\r
-  gBS->FreePool (mCallbackInfo);\r
+  FreePool (mCallbackInfo);\r
 \r
   return EFI_SUCCESS;\r
 }\r