]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/IScsiDxe/IScsiConfig.c
MdeModulePkg/DxeCore: invoke the emulator protocol for foreign images
[mirror_edk2.git] / NetworkPkg / IScsiDxe / IScsiConfig.c
index 62df367da78afb23e62d729ccb5a7a1f1638ba2d..b876da7f5ccd3d24732a4221e29b31c00155bb9b 100644 (file)
@@ -1,22 +1,14 @@
 /** @file\r
   Helper functions for configuring or getting the parameters relating to iSCSI.\r
 \r
-Copyright (c) 2004 - 2017, 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
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2004 - 2019, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include "IScsiImpl.h"\r
 \r
 CHAR16          mVendorStorageName[]     = L"ISCSI_CONFIG_IFR_NVDATA";\r
-BOOLEAN         mIScsiDeviceListUpdated  = FALSE;\r
-UINTN           mNumberOfIScsiDevices    = 0;\r
 ISCSI_FORM_CALLBACK_INFO  *mCallbackInfo = NULL;\r
 \r
 HII_VENDOR_DEVICE_PATH  mIScsiHiiVendorDevicePath = {\r
@@ -34,7 +26,7 @@ HII_VENDOR_DEVICE_PATH  mIScsiHiiVendorDevicePath = {
   {\r
     END_DEVICE_PATH_TYPE,\r
     END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
-    { \r
+    {\r
       (UINT8) (END_DEVICE_PATH_LENGTH),\r
       (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
     }\r
@@ -939,7 +931,7 @@ IScsiConvertIfrNvDataToAttemptConfigData (
           L"CHAP Name or CHAP Secret is invalid!",\r
           NULL\r
           );\r
-        \r
+\r
         return EFI_INVALID_PARAMETER;\r
       }\r
 \r
@@ -951,7 +943,7 @@ IScsiConvertIfrNvDataToAttemptConfigData (
           &Key,\r
           L"Reverse CHAP Name or Reverse CHAP Secret is invalid!",\r
           NULL\r
-          );        \r
+          );\r
         return EFI_INVALID_PARAMETER;\r
       }\r
     }\r
@@ -970,7 +962,7 @@ IScsiConvertIfrNvDataToAttemptConfigData (
       if (AttemptName2 == NULL) {\r
         FreePool (AttemptName1);\r
         return EFI_OUT_OF_RESOURCES;\r
-      }      \r
+      }\r
 \r
       AsciiStrToUnicodeStrS (Attempt->AttemptName, AttemptName1, ATTEMPT_NAME_SIZE);\r
       AsciiStrToUnicodeStrS (SameNicAttempt->AttemptName, AttemptName2, ATTEMPT_NAME_SIZE);\r
@@ -988,7 +980,7 @@ IScsiConvertIfrNvDataToAttemptConfigData (
         &Key,\r
         mPrivate->PortString,\r
         NULL\r
-        );       \r
+        );\r
 \r
       FreePool (AttemptName1);\r
       FreePool (AttemptName2);\r
@@ -2026,7 +2018,7 @@ IScsiConfigAddAttempt (
     PortTitleHelpToken = HiiSetString (mCallbackInfo->RegisteredHandle, 0, mPrivate->PortString, NULL);\r
     if (PortTitleHelpToken == 0) {\r
       Status = EFI_INVALID_PARAMETER;\r
-      goto Exit;      \r
+      goto Exit;\r
     }\r
 \r
     HiiCreateGotoOpCode (\r
@@ -2050,14 +2042,14 @@ IScsiConfigAddAttempt (
 Exit:\r
   HiiFreeOpCodeHandle (StartOpCodeHandle);\r
   HiiFreeOpCodeHandle (EndOpCodeHandle);\r
-  \r
+\r
   return Status;\r
 }\r
 \r
 /**\r
   Add the attempts by keyword 'iSCSIAddAttempts', you can use this keyword with\r
   value 'attempt:1 attempt:2' etc to add one or more attempts once. This is different\r
-  with IScsiConfigAddAttempt function which is used to add attempt by UI configuration. \r
+  with IScsiConfigAddAttempt function which is used to add attempt by UI configuration.\r
 \r
   @param[in]  AttemptList        The new attempt List will be added.\r
 \r
@@ -2294,10 +2286,6 @@ IScsiConfigDeleteAttempts (
     //\r
 \r
     AttemptConfigData = NET_LIST_USER_STRUCT (Entry, ISCSI_ATTEMPT_CONFIG_NVDATA, Link);\r
-    if (AttemptConfigData == NULL) {\r
-      Status = EFI_NOT_FOUND;\r
-      goto Error;\r
-    }\r
 \r
     //\r
     // Remove this attempt from UI configured attempt list.\r
@@ -2505,7 +2493,7 @@ IScsiConfigDisplayDeleteAttempts (
              FORMID_DELETE_FORM,              // Form ID\r
              StartOpCodeHandle,               // Label for where to insert opcodes\r
              EndOpCodeHandle                  // Replace data\r
-             );    \r
+             );\r
 \r
   HiiFreeOpCodeHandle (StartOpCodeHandle);\r
   HiiFreeOpCodeHandle (EndOpCodeHandle);\r
@@ -2536,8 +2524,8 @@ IScsiConfigDisplayOrderAttempts (
   EFI_IFR_GUID_LABEL          *StartLabel;\r
   VOID                        *EndOpCodeHandle;\r
   EFI_IFR_GUID_LABEL          *EndLabel;\r
-  VOID                        *OptionsOpCodeHandle;  \r
-  \r
+  VOID                        *OptionsOpCodeHandle;\r
+\r
   Status = IScsiCreateOpCode (\r
              ORDER_ENTRY_LABEL,\r
              &StartOpCodeHandle,\r
@@ -2589,14 +2577,14 @@ IScsiConfigDisplayOrderAttempts (
     DYNAMIC_ORDERED_LIST_QUESTION_ID,           // Question ID\r
     CONFIGURATION_VARSTORE_ID,                  // VarStore ID\r
     DYNAMIC_ORDERED_LIST_VAR_OFFSET,            // Offset in Buffer Storage\r
-    STRING_TOKEN (STR_ORDER_ATTEMPT_ENTRY),     // Question prompt text        \r
-    STRING_TOKEN (STR_ORDER_ATTEMPT_ENTRY),     // Question help text       \r
+    STRING_TOKEN (STR_ORDER_ATTEMPT_ENTRY),     // Question prompt text\r
+    STRING_TOKEN (STR_ORDER_ATTEMPT_ENTRY),     // Question help text\r
     0,                                          // Question flag\r
     EFI_IFR_UNIQUE_SET,                         // Ordered list flag, e.g. EFI_IFR_UNIQUE_SET\r
     EFI_IFR_NUMERIC_SIZE_1,                     // Data type of Question value\r
     ISCSI_MAX_ATTEMPTS_NUM,                     // Maximum container\r
-    OptionsOpCodeHandle,                        // Option Opcode list                        \r
-    NULL                                        // Default Opcode is NULL                               \r
+    OptionsOpCodeHandle,                        // Option Opcode list\r
+    NULL                                        // Default Opcode is NULL\r
     );\r
 \r
 Exit:\r
@@ -2606,11 +2594,11 @@ Exit:
              FORMID_ORDER_FORM,               // Form ID\r
              StartOpCodeHandle,               // Label for where to insert opcodes\r
              EndOpCodeHandle                  // Replace data\r
-             );             \r
+             );\r
 \r
 Error:\r
   HiiFreeOpCodeHandle (StartOpCodeHandle);\r
-  HiiFreeOpCodeHandle (EndOpCodeHandle);  \r
+  HiiFreeOpCodeHandle (EndOpCodeHandle);\r
   if (OptionsOpCodeHandle != NULL) {\r
     HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
   }\r
@@ -2821,10 +2809,10 @@ IScsiConfigProcessDefault (
       if (AttemptConfigData == NULL || AttemptConfigData->Actived == ISCSI_ACTIVE_ENABLED) {\r
         continue;\r
       }\r
-    \r
+\r
       break;\r
     }\r
-    \r
+\r
     if (Index > PcdGet8 (PcdMaxIScsiAttemptNumber)) {\r
       CreatePopUp (\r
         EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
@@ -2858,7 +2846,7 @@ IScsiConfigProcessDefault (
     // Generate OUI-format ISID based on MAC address.\r
     //\r
     CopyMem (AttemptConfigData->SessionConfigData.IsId, &NicInfo->PermanentAddress, 6);\r
-    AttemptConfigData->SessionConfigData.IsId[0] = \r
+    AttemptConfigData->SessionConfigData.IsId[0] =\r
       (UINT8) (AttemptConfigData->SessionConfigData.IsId[0] & 0x3F);\r
 \r
     //\r
@@ -2908,7 +2896,7 @@ IScsiConfigProcessDefault (
     ZeroMem (IfrNvData->ReverseCHAPName, sizeof (IfrNvData->ReverseCHAPName));\r
     ZeroMem (IfrNvData->ReverseCHAPSecret, sizeof (IfrNvData->ReverseCHAPSecret));\r
   }\r
-  \r
+\r
   IScsiConvertAttemptConfigDataToIfrNvData (AttemptConfigData, IfrNvData);\r
 \r
   //\r
@@ -2921,7 +2909,7 @@ IScsiConfigProcessDefault (
 \r
 \r
 /**\r
-   \r
+\r
   This function allows the caller to request the current\r
   configuration for one or more named elements. The resulting\r
   string is in <ConfigAltResp> format. Also, any and all alternative\r
@@ -2950,7 +2938,7 @@ IScsiConfigProcessDefault (
                          to the most recent "&" before the first\r
                          failing name / value pair (or the beginning\r
                          of the string if the failure is in the first\r
-                         name / value pair) if the request was not successful.                        \r
+                         name / value pair) if the request was not successful.\r
 \r
   @param[out] Results    A null-terminated Unicode string in\r
                          <ConfigAltResp> format which has all values\r
@@ -2971,7 +2959,7 @@ IScsiConfigProcessDefault (
                                   would result in this type of\r
                                   error. In this case, the\r
                                   Progress parameter would be\r
-                                  set to NULL. \r
+                                  set to NULL.\r
 \r
   @retval EFI_NOT_FOUND           Routing data doesn't match any\r
                                   known driver. Progress set to the\r
@@ -3046,7 +3034,7 @@ IScsiFormExtractConfig (
     FreePool (IfrNvData);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-    \r
+\r
   Status = gIScsiInitiatorName.Get (&gIScsiInitiatorName, &BufferSize, InitiatorName);\r
   if (EFI_ERROR (Status)) {\r
     IfrNvData->InitiatorName[0] = L'\0';\r
@@ -3114,7 +3102,7 @@ IScsiFormExtractConfig (
 \r
 \r
 /**\r
-   \r
+\r
   This function applies changes in a driver's configuration.\r
   Input is a Configuration, which has the routing data for this\r
   driver followed by name / value configuration pairs. The driver\r
@@ -3127,8 +3115,8 @@ IScsiFormExtractConfig (
   @param[in]  This           Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
 \r
   @param[in]  Configuration  A null-terminated Unicode string in\r
-                             <ConfigString> format. \r
-  \r
+                             <ConfigString> format.\r
+\r
   @param[out] Progress       A pointer to a string filled in with the\r
                              offset of the most recent '&' before the\r
                              first failing name / value pair (or the\r
@@ -3139,16 +3127,16 @@ IScsiFormExtractConfig (
 \r
   @retval EFI_SUCCESS             The results have been distributed or are\r
                                   awaiting distribution.\r
-  \r
+\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
-  \r
+\r
   @retval EFI_INVALID_PARAMETERS  Passing in a NULL for the\r
                                   Results parameter would result\r
                                   in this type of error.\r
-  \r
+\r
   @retval EFI_NOT_FOUND           Target for the specified routing data\r
                                   was not found.\r
 \r
@@ -3374,7 +3362,7 @@ Exit:
 }\r
 \r
 /**\r
-   \r
+\r
   This function is called to provide results data to the driver.\r
   This data consists of a unique key that is used to identify\r
   which data is either being passed back or being asked for.\r
@@ -3383,7 +3371,7 @@ Exit:
   @param[in]       Action        Specifies the type of action taken by the browser.\r
   @param[in]       QuestionId    A unique value which is sent to the original\r
                                  exporting driver so that it can identify the type\r
-                                 of data to expect. The format of the data tends to \r
+                                 of data to expect. The format of the data tends to\r
                                  vary based on the opcode that generated the callback.\r
   @param[in]       Type          The type of value for the question.\r
   @param[in, out]  Value         A pointer to the data being sent to the original\r
@@ -3445,29 +3433,29 @@ IScsiFormCallback (
   }\r
 \r
   Private = ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This);\r
-  \r
+\r
   //\r
   // Retrieve uncommitted data from Browser\r
   //\r
-  \r
+\r
   BufferSize = sizeof (ISCSI_CONFIG_IFR_NVDATA);\r
   IfrNvData = AllocateZeroPool (BufferSize);\r
   if (IfrNvData == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  \r
+\r
   IScsiName = (CHAR8 *) AllocateZeroPool (ISCSI_NAME_MAX_SIZE);\r
   if (IScsiName == NULL) {\r
     FreePool (IfrNvData);\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  \r
+\r
   Status = EFI_SUCCESS;\r
-  \r
+\r
   ZeroMem (&OldIfrNvData, BufferSize);\r
-  \r
+\r
   HiiGetBrowserData (NULL, NULL, BufferSize, (UINT8 *) IfrNvData);\r
-  \r
+\r
   CopyMem (&OldIfrNvData, IfrNvData, BufferSize);\r
 \r
   if (Action == EFI_BROWSER_ACTION_CHANGING) {\r
@@ -3488,10 +3476,10 @@ IScsiFormCallback (
           &Key,\r
           L"Error: please configure iSCSI initiator name first!",\r
           NULL\r
-          );        \r
+          );\r
         break;\r
       }\r
-      \r
+\r
       Status = IScsiConfigAddAttempt ();\r
       break;\r
 \r
@@ -3515,12 +3503,12 @@ IScsiFormCallback (
         );\r
       IScsiConfigDisplayOrderAttempts ();\r
       break;\r
-    \r
+\r
     default:\r
       Status = IScsiConfigProcessDefault (QuestionId, IfrNvData);\r
       break;\r
     }\r
-  } else if (Action == EFI_BROWSER_ACTION_CHANGED) {  \r
+  } else if (Action == EFI_BROWSER_ACTION_CHANGED) {\r
     switch (QuestionId) {\r
     case KEY_INITIATOR_NAME:\r
       UnicodeStrToAsciiStrS (IfrNvData->InitiatorName, IScsiName, ISCSI_NAME_MAX_SIZE);\r
@@ -3533,12 +3521,12 @@ IScsiFormCallback (
           &Key,\r
           L"Invalid iSCSI Name!",\r
           NULL\r
-          );      \r
+          );\r
       }\r
 \r
       *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;\r
       break;\r
-      \r
+\r
     case KEY_SAVE_ATTEMPT_CONFIG:\r
       Status = IScsiConvertIfrNvDataToAttemptConfigData (IfrNvData, Private->Current);\r
       if (EFI_ERROR (Status)) {\r
@@ -3595,17 +3583,17 @@ IScsiFormCallback (
     case KEY_IP_MODE:\r
       switch (Value->u8) {\r
       case IP_MODE_IP6:\r
-        NicInfo = IScsiGetNicInfoByIndex (Private->Current->NicIndex); \r
+        NicInfo = IScsiGetNicInfoByIndex (Private->Current->NicIndex);\r
         if(NicInfo == NULL) {\r
           break;\r
         }\r
 \r
-        if(!NicInfo->Ipv6Available) {                  \r
-             //\r
-          // Current NIC doesn't Support IPv6, hence use IPv4.    \r
-          //    \r
+        if(!NicInfo->Ipv6Available) {\r
+          //\r
+          // Current NIC doesn't Support IPv6, hence use IPv4.\r
+          //\r
           IfrNvData->IpMode = IP_MODE_IP4;\r
-               \r
+\r
           CreatePopUp (\r
             EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
             &Key,\r
@@ -3613,7 +3601,7 @@ IScsiFormCallback (
             NULL\r
             );\r
         }\r
-         \r
+\r
       case IP_MODE_IP4:\r
         ZeroMem (IfrNvData->LocalIp, sizeof (IfrNvData->LocalIp));\r
         ZeroMem (IfrNvData->SubnetMask, sizeof (IfrNvData->SubnetMask));\r
@@ -3624,7 +3612,7 @@ IScsiFormCallback (
         ZeroMem (&Private->Current->SessionConfigData.SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
         ZeroMem (&Private->Current->SessionConfigData.Gateway, sizeof (EFI_IP_ADDRESS));\r
         ZeroMem (&Private->Current->SessionConfigData.TargetIp, sizeof (EFI_IP_ADDRESS));\r
-        \r
+\r
         break;\r
       }\r
 \r
@@ -3632,16 +3620,16 @@ IScsiFormCallback (
 \r
     case KEY_LOCAL_IP:\r
       Status = NetLibStrToIp4 (IfrNvData->LocalIp, &HostIp.v4);\r
-      if (EFI_ERROR (Status) || \r
-          ((Private->Current->SessionConfigData.SubnetMask.Addr[0] != 0) && \r
+      if (EFI_ERROR (Status) ||\r
+          ((Private->Current->SessionConfigData.SubnetMask.Addr[0] != 0) &&\r
            !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), NTOHL(*(UINT32*)Private->Current->SessionConfigData.SubnetMask.Addr)))) {\r
         CreatePopUp (\r
           EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
           &Key,\r
           L"Invalid IP address!",\r
           NULL\r
-          ); \r
-        \r
+          );\r
+\r
         Status = EFI_INVALID_PARAMETER;\r
       } else {\r
         CopyMem (&Private->Current->SessionConfigData.LocalIp, &HostIp.v4, sizeof (HostIp.v4));\r
@@ -3657,8 +3645,8 @@ IScsiFormCallback (
           &Key,\r
           L"Invalid Subnet Mask!",\r
           NULL\r
-          ); \r
-        \r
+          );\r
+\r
         Status = EFI_INVALID_PARAMETER;\r
       } else {\r
         CopyMem (&Private->Current->SessionConfigData.SubnetMask, &SubnetMask.v4, sizeof (SubnetMask.v4));\r
@@ -3668,16 +3656,16 @@ IScsiFormCallback (
 \r
     case KEY_GATE_WAY:\r
       Status = NetLibStrToIp4 (IfrNvData->Gateway, &Gateway.v4);\r
-      if (EFI_ERROR (Status) || \r
-          ((Gateway.Addr[0] != 0) && \r
-           (Private->Current->SessionConfigData.SubnetMask.Addr[0] != 0) && \r
+      if (EFI_ERROR (Status) ||\r
+          ((Gateway.Addr[0] != 0) &&\r
+           (Private->Current->SessionConfigData.SubnetMask.Addr[0] != 0) &&\r
            !NetIp4IsUnicast (NTOHL (Gateway.Addr[0]), NTOHL(*(UINT32*)Private->Current->SessionConfigData.SubnetMask.Addr)))) {\r
         CreatePopUp (\r
           EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
           &Key,\r
           L"Invalid Gateway!",\r
           NULL\r
-          );       \r
+          );\r
         Status = EFI_INVALID_PARAMETER;\r
       } else {\r
         CopyMem (&Private->Current->SessionConfigData.Gateway, &Gateway.v4, sizeof (Gateway.v4));\r
@@ -3734,7 +3722,7 @@ IScsiFormCallback (
           &Key,\r
           L"Invalid LUN string!",\r
           NULL\r
-          );       \r
+          );\r
       } else {\r
         CopyMem (Private->Current->SessionConfigData.BootLun, &Lun, sizeof (Lun));\r
       }\r
@@ -3851,7 +3839,7 @@ IScsiConfigFormInit (
                   NULL\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
-  \r
+\r
   //\r
   // Publish our HII data.\r
   //\r