]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/IScsiDxe/IScsiMisc.c
EmulatorPkg: Fix typos in comments
[mirror_edk2.git] / NetworkPkg / IScsiDxe / IScsiMisc.c
index 05f639aaeeb54fcbade7d66398de62755396dfad..deebf5d9a38751d715440799c7d6cf30a64e6e06 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Miscellaneous routines for iSCSI driver.\r
 \r
-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2016, 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
@@ -226,6 +226,7 @@ IScsiLunToUnicodeStr (
   //\r
   // Remove the last '-'\r
   //\r
+  ASSERT (StrLen(Str) >= 1);\r
   Str[StrLen (Str) - 1] = 0;\r
 \r
   for (Index = StrLen (Str) - 1; Index > 1; Index = Index - 2) {\r
@@ -682,7 +683,7 @@ IScsiGetNicInfoByIndex (
 \r
 \r
 /**\r
-  Get the NIC's PCI location and return it accroding to the composited\r
+  Get the NIC's PCI location and return it according to the composited\r
   format defined in iSCSI Boot Firmware Table.\r
 \r
   @param[in]   Controller        The handle of the controller.\r
@@ -856,22 +857,30 @@ IScsiCreateDriverData (
 /**\r
   Clean the iSCSI driver data.\r
 \r
-  @param[in]  Private The iSCSI driver data.\r
+  @param[in]              Private The iSCSI driver data.\r
+\r
+  @retval EFI_SUCCESS     The clean operation is successful.\r
+  @retval Others          Other errors as indicated.\r
 \r
 **/\r
-VOID\r
+EFI_STATUS\r
 IScsiCleanDriverData (\r
   IN ISCSI_DRIVER_DATA  *Private\r
   )\r
 {\r
   EFI_STATUS            Status;\r
 \r
+  Status = EFI_SUCCESS;\r
+\r
   if (Private->DevicePath != NULL) {\r
-    gBS->UninstallProtocolInterface (\r
-           Private->ExtScsiPassThruHandle,\r
-           &gEfiDevicePathProtocolGuid,\r
-           Private->DevicePath\r
-           );\r
+    Status = gBS->UninstallProtocolInterface (\r
+                    Private->ExtScsiPassThruHandle,\r
+                    &gEfiDevicePathProtocolGuid,\r
+                    Private->DevicePath\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      goto EXIT;\r
+    }\r
 \r
     FreePool (Private->DevicePath);\r
   }\r
@@ -887,9 +896,12 @@ IScsiCleanDriverData (
     }\r
   }\r
 \r
+EXIT:\r
+\r
   gBS->CloseEvent (Private->ExitBootServiceEvent);\r
 \r
   FreePool (Private);\r
+  return Status;\r
 }\r
 \r
 /**\r
@@ -994,6 +1006,7 @@ IScsiDhcpIsConfigured (
 \r
   @retval EFI_SUCCESS            The configuration data is retrieved.\r
   @retval EFI_NOT_FOUND          This iSCSI driver is not configured yet.\r
+  @retval EFI_OUT_OF_RESOURCES   Failed to allocate memory.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1053,7 +1066,7 @@ IScsiGetConfigData (
       // Check the autoconfig path to see whether it should be retried.\r
       //\r
       if (AttemptTmp->SessionConfigData.IpMode == IP_MODE_AUTOCONFIG &&\r
-          AttemptTmp->AutoConfigureMode != IP_MODE_AUTOCONFIG_SUCCESS) {\r
+          !AttemptTmp->AutoConfigureSuccess) {\r
         if (mPrivate->Ipv6Flag &&\r
             AttemptTmp->AutoConfigureMode == IP_MODE_AUTOCONFIG_IP6) {\r
           //\r
@@ -1094,7 +1107,7 @@ IScsiGetConfigData (
           //\r
           // Refresh the state of this attempt to NVR.\r
           //\r
-          AsciiStrToUnicodeStr (AttemptTmp->MacString, MacString);\r
+          AsciiStrToUnicodeStrS (AttemptTmp->MacString, MacString, sizeof (MacString) / sizeof (MacString[0]));\r
           UnicodeSPrint (\r
             mPrivate->PortString,\r
             (UINTN) ISCSI_NAME_IFR_MAX_SIZE,\r
@@ -1133,7 +1146,7 @@ IScsiGetConfigData (
         //\r
         // Refresh the state of this attempt to NVR.\r
         //\r
-        AsciiStrToUnicodeStr (AttemptTmp->MacString, MacString);\r
+        AsciiStrToUnicodeStrS (AttemptTmp->MacString, MacString, sizeof (MacString) / sizeof (MacString[0]));\r
         UnicodeSPrint (\r
           mPrivate->PortString,\r
           (UINTN) ISCSI_NAME_IFR_MAX_SIZE,\r
@@ -1196,6 +1209,7 @@ IScsiGetConfigData (
 \r
       AttemptConfigData->AutoConfigureMode =\r
         (UINT8) (mPrivate->Ipv6Flag ? IP_MODE_AUTOCONFIG_IP6 : IP_MODE_AUTOCONFIG_IP4);\r
+      AttemptConfigData->AutoConfigureSuccess = FALSE;\r
     }\r
     \r
     //\r
@@ -1223,7 +1237,7 @@ IScsiGetConfigData (
       //\r
       // Refresh the state of this attempt to NVR.\r
       //\r
-      AsciiStrToUnicodeStr (AttemptConfigData->MacString, MacString);\r
+      AsciiStrToUnicodeStrS (AttemptConfigData->MacString, MacString, sizeof (MacString) / sizeof (MacString[0]));\r
       UnicodeSPrint (\r
         mPrivate->PortString,\r
         (UINTN) ISCSI_NAME_IFR_MAX_SIZE,\r
@@ -1279,7 +1293,9 @@ IScsiGetConfigData (
                                                  mPrivate->PortString,\r
                                                  NULL\r
                                                  );\r
-    ASSERT (AttemptConfigData->AttemptTitleHelpToken != 0);\r
+    if (AttemptConfigData->AttemptTitleHelpToken == 0) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
 \r
     //\r
     // Record the attempt in global link list.\r
@@ -1351,6 +1367,7 @@ IScsiGetTcpConnDevicePath (
   EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
   EFI_STATUS                Status;\r
   EFI_DEV_PATH              *DPathNode;\r
+  UINTN                     PathLen;\r
 \r
   if (Session->State != SESSION_STATE_LOGGED_IN) {\r
     return NULL;\r
@@ -1389,21 +1406,58 @@ IScsiGetTcpConnDevicePath (
         DPathNode->Ipv4.StaticIpAddress = \r
           (BOOLEAN) (!Session->ConfigData->SessionConfigData.InitiatorInfoFromDhcp);\r
 \r
-        IP4_COPY_ADDRESS (\r
-          &DPathNode->Ipv4.GatewayIpAddress,\r
-          &Session->ConfigData->SessionConfigData.Gateway\r
-          );\r
+        //\r
+        //  Add a judgement here to support previous versions of IPv4_DEVICE_PATH.\r
+        //  In previous versions of IPv4_DEVICE_PATH, GatewayIpAddress and SubnetMask\r
+        //  do not exist.\r
+        //  In new version of IPv4_DEVICE_PATH, structcure length is 27.\r
+        //\r
 \r
-        IP4_COPY_ADDRESS (\r
-          &DPathNode->Ipv4.SubnetMask,\r
-          &Session->ConfigData->SessionConfigData.SubnetMask\r
-          );\r
+        PathLen = DevicePathNodeLength (&DPathNode->Ipv4);\r
+        \r
+        if (PathLen == IP4_NODE_LEN_NEW_VERSIONS) {  \r
+            \r
+          IP4_COPY_ADDRESS (\r
+            &DPathNode->Ipv4.GatewayIpAddress,\r
+            &Session->ConfigData->SessionConfigData.Gateway\r
+            );\r
+\r
+          IP4_COPY_ADDRESS (\r
+            &DPathNode->Ipv4.SubnetMask,\r
+            &Session->ConfigData->SessionConfigData.SubnetMask\r
+            );\r
+        }\r
+        \r
         break;\r
       } else if (Conn->Ipv6Flag && DevicePathSubType (&DPathNode->DevPath) == MSG_IPv6_DP) {\r
         DPathNode->Ipv6.LocalPort       = 0;\r
-        DPathNode->Ipv6.IpAddressOrigin = 0;\r
-        DPathNode->Ipv6.PrefixLength    = IP6_PREFIX_LENGTH;\r
-        ZeroMem (&DPathNode->Ipv6.GatewayIpAddress, sizeof (EFI_IPv6_ADDRESS));\r
+\r
+        //\r
+        //  Add a judgement here to support previous versions of IPv6_DEVICE_PATH.\r
+        //  In previous versions of IPv6_DEVICE_PATH, IpAddressOrigin, PrefixLength\r
+        //  and GatewayIpAddress do not exist.\r
+        //  In new version of IPv6_DEVICE_PATH, structure length is 60, while in \r
+        //  old versions, the length is 43.\r
+        //\r
+\r
+        PathLen = DevicePathNodeLength (&DPathNode->Ipv6);\r
+        \r
+        if (PathLen == IP6_NODE_LEN_NEW_VERSIONS ) { \r
+\r
+          DPathNode->Ipv6.IpAddressOrigin = 0;\r
+          DPathNode->Ipv6.PrefixLength    = IP6_PREFIX_LENGTH;\r
+          ZeroMem (&DPathNode->Ipv6.GatewayIpAddress, sizeof (EFI_IPv6_ADDRESS));\r
+        }\r
+        else if (PathLen == IP6_NODE_LEN_OLD_VERSIONS) { \r
+\r
+          //\r
+          //  StaticIPAddress is a field in old versions of IPv6_DEVICE_PATH, while ignored in new \r
+          //  version. Set StaticIPAddress through its' offset in old IPv6_DEVICE_PATH.\r
+          //\r
+          *((UINT8 *)(&DPathNode->Ipv6) + IP6_OLD_IPADDRESS_OFFSET) = \r
+            (BOOLEAN) (!Session->ConfigData->SessionConfigData.InitiatorInfoFromDhcp);\r
+        }\r
+        \r
         break;\r
       }\r
     }\r