]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Universal / Network / IScsiDxe / IScsiConfig.c
index e263f0e306b68134970ca5caf6c6cdc139245d86..cb1eff1b690cc8494bc631e6f3e2c0497f64e992 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Helper functions for configuring or getting the parameters relating to iSCSI.\r
 \r
-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 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 of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -39,7 +39,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
@@ -180,7 +180,7 @@ IScsiConvertIsIdToString (
   Update the list of iSCSI devices the iSCSI driver is controlling.\r
 \r
   @retval EFI_SUCCESS            The callback successfully handled the action.\r
-  @retval Others                 Other errors as indicated.   \r
+  @retval Others                 Other errors as indicated.\r
 **/\r
 EFI_STATUS\r
 IScsiUpdateDeviceList (\r
@@ -445,7 +445,7 @@ IScsiConvertDeviceConfigDataToIfrNvData (
                                   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
   @retval EFI_NOT_FOUND           Routing data doesn't match any\r
                                   known driver. Progress set to the\r
                                   first character in the routing header.\r
@@ -579,7 +579,7 @@ IScsiFormExtractConfig (
 \r
   @param[in]  This           Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
   @param[in]  Configuration  A null-terminated Unicode string in\r
-                             <ConfigString> format.   \r
+                             <ConfigString> format.\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
@@ -589,7 +589,7 @@ IScsiFormExtractConfig (
                              successful.\r
 \r
   @retval EFI_SUCCESS             The results have been distributed or are\r
-                                  awaiting distribution.  \r
+                                  awaiting distribution.\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
@@ -634,7 +634,7 @@ IScsiFormRouteConfig (
   @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 enerated the callback.\r
   @param[in]  Type               The type of value for the question.\r
   @param[in]  Value              A pointer to the data being sent to the original\r
@@ -648,8 +648,8 @@ IScsiFormRouteConfig (
   @retval EFI_DEVICE_ERROR       The variable could not be saved.\r
   @retval EFI_UNSUPPORTED        The specified Action is not supported by the\r
                                  callback.Currently not implemented.\r
-  @retval EFI_INVALID_PARAMETERS Passing in wrong parameter. \r
-  @retval Others                 Other errors as indicated. \r
+  @retval EFI_INVALID_PARAMETERS Passing in wrong parameter.\r
+  @retval Others                 Other errors as indicated.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -684,7 +684,7 @@ IScsiFormCallback (
 \r
   Private   = ISCSI_FORM_CALLBACK_INFO_FROM_FORM_CALLBACK (This);\r
   //\r
-  // Retrive uncommitted data from Browser\r
+  // Retrieve uncommitted data from Browser\r
   //\r
   IfrNvData = AllocateZeroPool (sizeof (ISCSI_CONFIG_IFR_NVDATA));\r
   ASSERT (IfrNvData != NULL);\r
@@ -711,7 +711,7 @@ IScsiFormCallback (
       Private->Current = ConfigFormEntry;\r
     }\r
   } else if (Action == EFI_BROWSER_ACTION_CHANGED) {\r
-    switch (QuestionId) { \r
+    switch (QuestionId) {\r
     case KEY_INITIATOR_NAME:\r
       IScsiUnicodeStrToAsciiStr (IfrNvData->InitiatorName, IScsiName);\r
       BufferSize  = AsciiStrSize (IScsiName);\r
@@ -727,7 +727,9 @@ IScsiFormCallback (
     case KEY_LOCAL_IP:\r
       IScsiUnicodeStrToAsciiStr (IfrNvData->LocalIp, Ip4String);\r
       Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4);\r
-      if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.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 (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r
         Status = EFI_INVALID_PARAMETER;\r
       } else {\r
@@ -751,7 +753,10 @@ 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) && !NetIp4IsUnicast (NTOHL (Gateway.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 (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid Gateway!", NULL);\r
         Status = EFI_INVALID_PARAMETER;\r
       } else {\r
@@ -763,7 +768,7 @@ IScsiFormCallback (
     case KEY_TARGET_IP:\r
       IScsiUnicodeStrToAsciiStr (IfrNvData->TargetIp, Ip4String);\r
       Status = IScsiAsciiStrToIp (Ip4String, &HostIp.v4);\r
-      if (EFI_ERROR (Status) || !NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
+      if (EFI_ERROR (Status) || IP4_IS_LOCAL_BROADCAST (EFI_NTOHL(HostIp.v4)) || IP4_IS_UNSPECIFIED (EFI_NTOHL(HostIp.v4))) {\r
         CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid IP address!", NULL);\r
         Status = EFI_INVALID_PARAMETER;\r
       } else {\r
@@ -778,7 +783,7 @@ IScsiFormCallback (
       if (EFI_ERROR (Status)) {\r
         CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Invalid iSCSI Name!", NULL);\r
       } else {\r
-        AsciiStrCpy (Private->Current->SessionConfigData.TargetName, IScsiName);\r
+        AsciiStrCpyS (Private->Current->SessionConfigData.TargetName, ISCSI_NAME_MAX_SIZE, IScsiName);\r
       }\r
 \r
       break;\r
@@ -867,7 +872,7 @@ IScsiFormCallback (
         //\r
         if (!Private->Current->SessionConfigData.TargetInfoFromDhcp) {\r
           CopyMem (&HostIp.v4, &Private->Current->SessionConfigData.TargetIp, sizeof (HostIp.v4));\r
-          if (!NetIp4IsUnicast (NTOHL (HostIp.Addr[0]), 0)) {\r
+          if (IP4_IS_UNSPECIFIED (NTOHL (HostIp.Addr[0])) || IP4_IS_LOCAL_BROADCAST (NTOHL (HostIp.Addr[0]))) {\r
             CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, L"Target IP is invalid!", NULL);\r
             Status = EFI_INVALID_PARAMETER;\r
             break;\r
@@ -939,9 +944,9 @@ IScsiFormCallback (
     //\r
     HiiSetBrowserData (&gIp4IScsiConfigGuid, mVendorStorageName, sizeof (ISCSI_CONFIG_IFR_NVDATA), (UINT8 *) IfrNvData, NULL);\r
   }\r
-  \r
+\r
   FreePool (IfrNvData);\r
-  \r
+\r
   return Status;\r
 }\r
 \r
@@ -1028,12 +1033,12 @@ IScsiConfigUpdateForm (
                       );\r
       if (EFI_ERROR (Status)) {\r
         ZeroMem (&ConfigFormEntry->SessionConfigData, sizeof (ConfigFormEntry->SessionConfigData));\r
-        \r
+\r
         //\r
         // Generate OUI-format ISID based on MAC address.\r
         //\r
         CopyMem (ConfigFormEntry->SessionConfigData.IsId, &MacAddress, 6);\r
-        ConfigFormEntry->SessionConfigData.IsId[0] = \r
+        ConfigFormEntry->SessionConfigData.IsId[0] =\r
           (UINT8) (ConfigFormEntry->SessionConfigData.IsId[0] & 0x3F);\r
       }\r
       //\r
@@ -1071,6 +1076,7 @@ IScsiConfigUpdateForm (
     mNumberOfIScsiDevices--;\r
     RemoveEntryList (&ConfigFormEntry->Link);\r
     FreePool (ConfigFormEntry);\r
+    mCallbackInfo->Current = NULL;\r
   }\r
   //\r
   // Allocate space for creation of Buffer\r
@@ -1183,7 +1189,7 @@ IScsiConfigFormInit (
                   NULL\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
-  \r
+\r
   //\r
   // Publish our HII data\r
   //\r
@@ -1210,7 +1216,7 @@ IScsiConfigFormInit (
   free the resources used.\r
 \r
   @param[in]  DriverBindingHandle The iSCSI driverbinding handle.\r
-  \r
+\r
   @retval EFI_SUCCESS             The iSCSI configuration form is unloaded.\r
   @retval EFI_OUT_OF_RESOURCES    Failed to allocate memory.\r
 **/\r