]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/IScsiDxe/IScsiProto.c
Maintainers.txt: update mailing list information
[mirror_edk2.git] / NetworkPkg / IScsiDxe / IScsiProto.c
index a67bbd5c8700ad98b06eb67a4dcac4a4a830ad32..6fbf973e35f307ce5b6c98de2900cd72c090c331 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
   The implementation of iSCSI protocol based on RFC3720.\r
 \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
-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 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -17,7 +11,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 UINT32 mDataSegPad = 0;\r
 \r
 /**\r
-  Attach the iSCSI connection to the iSCSI session. \r
+  Attach the iSCSI connection to the iSCSI session.\r
 \r
   @param[in, out]  Session The iSCSI session.\r
   @param[in, out]  Conn    The iSCSI connection.\r
@@ -35,7 +29,7 @@ IScsiAttatchConnection (
 }\r
 \r
 /**\r
-  Detach the iSCSI connection from the session it belongs to. \r
+  Detach the iSCSI connection from the session it belongs to.\r
 \r
   @param[in, out]  Conn The iSCSI connection.\r
 \r
@@ -52,7 +46,7 @@ IScsiDetatchConnection (
 \r
 \r
 /**\r
-  Check the sequence number according to RFC3720. \r
+  Check the sequence number according to RFC3720.\r
 \r
   @param[in, out]  ExpSN   The currently expected sequence number.\r
   @param[in]       NewSN   The sequence number to check.\r
@@ -124,7 +118,7 @@ IScsiUpdateCmdSN (
 \r
   @retval EFI_SUCCESS        The iSCSI connection is logged into the iSCSI target.\r
   @retval EFI_TIMEOUT        Timeout occurred during the login procedure.\r
-  @retval Others             Other errors as indicated.  \r
+  @retval Others             Other errors as indicated.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -255,9 +249,26 @@ IScsiCreateConnection (
   Conn->HeaderDigest              = IScsiDigestNone;\r
   Conn->DataDigest                = IScsiDigestNone;\r
 \r
+  if (NvData->DnsMode) {\r
+    //\r
+    // perform dns process if target address expressed by domain name.\r
+    //\r
+    if (!Conn->Ipv6Flag) {\r
+      Status = IScsiDns4 (Private->Image, Private->Controller, NvData);\r
+    } else {\r
+      Status = IScsiDns6 (Private->Image, Private->Controller, NvData);\r
+    }\r
+\r
+    if (EFI_ERROR(Status)) {\r
+      DEBUG ((EFI_D_ERROR, "The configuration of Target address or DNS server address is invalid!\n"));\r
+      FreePool (Conn);\r
+      return NULL;\r
+    }\r
+  }\r
+\r
   if (!Conn->Ipv6Flag) {\r
     Tcp4IoConfig = &TcpIoConfig.Tcp4IoConfigData;\r
-    \r
+\r
     CopyMem (&Tcp4IoConfig->LocalIp, &NvData->LocalIp, sizeof (EFI_IPv4_ADDRESS));\r
     CopyMem (&Tcp4IoConfig->SubnetMask, &NvData->SubnetMask, sizeof (EFI_IPv4_ADDRESS));\r
     CopyMem (&Tcp4IoConfig->Gateway, &NvData->Gateway, sizeof (EFI_IPv4_ADDRESS));\r
@@ -268,7 +279,7 @@ IScsiCreateConnection (
     Tcp4IoConfig->StationPort = 0;\r
   } else {\r
     Tcp6IoConfig = &TcpIoConfig.Tcp6IoConfigData;\r
-  \r
+\r
     CopyMem (&Tcp6IoConfig->RemoteIp, &NvData->TargetIp, sizeof (EFI_IPv6_ADDRESS));\r
     Tcp6IoConfig->RemotePort  = NvData->TargetPort;\r
     Tcp6IoConfig->ActiveFlag  = TRUE;\r
@@ -321,7 +332,7 @@ IScsiDestroyConnection (
 \r
   @retval     EFI_SUCCESS      Get the NIC information successfully.\r
   @retval     Others           Other errors as indicated.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 IScsiGetIp6NicInfo (\r
@@ -427,14 +438,14 @@ IScsiSessionLogin (
   VOID              *Tcp;\r
   EFI_GUID          *ProtocolGuid;\r
   UINT8             RetryCount;\r
-  BOOLEAN           MediaPresent;\r
+  EFI_STATUS        MediaStatus;\r
 \r
   //\r
   // Check media status before session login.\r
   //\r
-  MediaPresent = TRUE;\r
-  NetLibDetectMedia (Session->Private->Controller, &MediaPresent);\r
-  if (!MediaPresent) {\r
+  MediaStatus = EFI_SUCCESS;\r
+  NetLibDetectMediaWaitTimeout (Session->Private->Controller, ISCSI_CHECK_MEDIA_LOGIN_WAITING_TIME, &MediaStatus);\r
+  if (MediaStatus != EFI_SUCCESS) {\r
     return EFI_NO_MEDIA;\r
   }\r
 \r
@@ -477,7 +488,7 @@ IScsiSessionLogin (
     Session->State = SESSION_STATE_LOGGED_IN;\r
 \r
     if (!Conn->Ipv6Flag) {\r
-      ProtocolGuid = &gEfiTcp4ProtocolGuid;      \r
+      ProtocolGuid = &gEfiTcp4ProtocolGuid;\r
     } else {\r
       ProtocolGuid = &gEfiTcp6ProtocolGuid;\r
     }\r
@@ -488,7 +499,7 @@ IScsiSessionLogin (
                     (VOID **) &Tcp,\r
                     Session->Private->Image,\r
                     Session->Private->ExtScsiPassThruHandle,\r
-                    EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER                    \r
+                    EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
                     );\r
 \r
     ASSERT_EFI_ERROR (Status);\r
@@ -595,7 +606,7 @@ IScsiSendLoginReq (
   Receive and process the iSCSI login response.\r
 \r
   @param[in]  Conn             The connection in the iSCSI login phase.\r
-  \r
+\r
   @retval EFI_SUCCESS          The iSCSI login response PDU is received and processed.\r
   @retval Others               Other errors as indicated.\r
 \r
@@ -776,7 +787,7 @@ IScsiPrepareLoginReq (
   case ISCSI_SECURITY_NEGOTIATION:\r
     //\r
     // Both none authentication and CHAP authentication share the CHAP path.\r
-    // \r
+    //\r
     //\r
     if (Session->AuthType != ISCSI_AUTH_TYPE_KRB) {\r
       Status = IScsiCHAPToSendReq (Conn, Nbuf);\r
@@ -791,7 +802,7 @@ IScsiPrepareLoginReq (
     if (!Conn->ParamNegotiated) {\r
       IScsiFillOpParams (Conn, Nbuf);\r
     }\r
-    \r
+\r
     ISCSI_SET_FLAG (LoginReq, ISCSI_LOGIN_REQ_PDU_FLAG_TRANSIT);\r
     break;\r
 \r
@@ -947,7 +958,7 @@ IScsiProcessLoginRsp (
     // the value presented in CmdSN as the target value for ExpCmdSN.\r
     //\r
     if ((Session->State == SESSION_STATE_FREE) && (Session->CmdSN != LoginRsp->ExpCmdSN)) {\r
-      return EFI_PROTOCOL_ERROR;     \r
+      return EFI_PROTOCOL_ERROR;\r
     }\r
 \r
     //\r
@@ -1055,7 +1066,7 @@ IScsiProcessLoginRsp (
   @param[in]      Data         The data segment that should contain the\r
                                TargetAddress key-value list.\r
   @param[in]      Len          Length of the data.\r
-  \r
+\r
   @retval EFI_SUCCESS          The target address is updated.\r
   @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
   @retval EFI_NOT_FOUND        The TargetAddress key is not found.\r
@@ -1084,7 +1095,7 @@ IScsiUpdateTargetAddress (
 \r
   Status = EFI_NOT_FOUND;\r
   NvData = &Session->ConfigData->SessionConfigData;\r
\r
+\r
   while (TRUE) {\r
     TargetAddress = IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_TARGET_ADDRESS);\r
     if (TargetAddress == NULL) {\r
@@ -1131,8 +1142,13 @@ IScsiUpdateTargetAddress (
     } else {\r
       //\r
       // The domainname of the target is presented in the format of a DNS host name.\r
-      // Temporary not supported.\r
-      continue;\r
+      //\r
+      IpStr = TargetAddress;\r
+\r
+      while ((*TargetAddress != '\0') && (*TargetAddress != ':') && (*TargetAddress != ',')) {\r
+        TargetAddress++;\r
+      }\r
+      NvData->DnsMode = TRUE;\r
     }\r
 \r
     //\r
@@ -1166,7 +1182,7 @@ IScsiUpdateTargetAddress (
 \r
     //\r
     // Save the origial user setting which specifies the proxy/virtual iSCSI target.\r
-    //    \r
+    //\r
     CopyMem (&NvData->OriginalTargetIp, &NvData->TargetIp, sizeof (EFI_IP_ADDRESS));\r
 \r
     //\r
@@ -1178,17 +1194,28 @@ IScsiUpdateTargetAddress (
       IpMode = Session->ConfigData->AutoConfigureMode;\r
     }\r
 \r
-    Status = IScsiAsciiStrToIp (\r
-               IpStr,\r
-               IpMode,\r
-               &Session->ConfigData->SessionConfigData.TargetIp\r
-               );\r
-\r
-    if (EFI_ERROR (Status)) {\r
-      continue;\r
+    if (NvData->DnsMode) {\r
+      //\r
+      // Target address is expressed as URL format, just save it and\r
+      // do DNS resolution when creating a TCP connection.\r
+      //\r
+      if (AsciiStrSize (IpStr) > sizeof (Session->ConfigData->SessionConfigData.TargetUrl)){\r
+        return EFI_INVALID_PARAMETER;\r
+      }\r
+      CopyMem (&Session->ConfigData->SessionConfigData.TargetUrl, IpStr, AsciiStrSize (IpStr));\r
     } else {\r
-      NvData->RedirectFlag = TRUE;\r
-      break;\r
+      Status = IScsiAsciiStrToIp (\r
+                 IpStr,\r
+                 IpMode,\r
+                 &Session->ConfigData->SessionConfigData.TargetIp\r
+                 );\r
+\r
+      if (EFI_ERROR (Status)) {\r
+        continue;\r
+      } else {\r
+        NvData->RedirectFlag = TRUE;\r
+        break;\r
+      }\r
     }\r
   }\r
 \r
@@ -1332,7 +1359,7 @@ IScsiReceivePdu (
   switch (ISCSI_GET_OPCODE (Header)) {\r
   case ISCSI_OPCODE_SCSI_DATA_IN:\r
     //\r
-    // To reduce memory copy overhead, try to use the buffer described by Context \r
+    // To reduce memory copy overhead, try to use the buffer described by Context\r
     // if the PDU is an iSCSI SCSI data.\r
     //\r
     InDataOffset = ISCSI_GET_BUFFER_OFFSET (Header);\r
@@ -1680,7 +1707,7 @@ IScsiCheckOpParams (
   IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_TARGET_ALIAS);\r
   IScsiGetValueByKeyFromList (KeyValueList, ISCSI_KEY_TARGET_PORTAL_GROUP_TAG);\r
 \r
-  \r
+\r
   //\r
   // Remove the key-value that may not needed for result function is OR.\r
   //\r
@@ -2063,39 +2090,6 @@ IScsiDelTcb (
 }\r
 \r
 \r
-/**\r
-  Find the task control block by the initator task tag.\r
-\r
-  @param[in]  TcbList         The tcb list.\r
-  @param[in]  InitiatorTaskTag The initiator task tag.\r
-\r
-  @return The task control block found.\r
-  @retval NULL The task control block cannot be found.\r
-\r
-**/\r
-ISCSI_TCB *\r
-IScsiFindTcbByITT (\r
-  IN LIST_ENTRY      *TcbList,\r
-  IN UINT32          InitiatorTaskTag\r
-  )\r
-{\r
-  ISCSI_TCB       *Tcb;\r
-  LIST_ENTRY      *Entry;\r
-\r
-  Tcb = NULL;\r
-\r
-  NET_LIST_FOR_EACH (Entry, TcbList) {\r
-    Tcb = NET_LIST_USER_STRUCT (Entry, ISCSI_TCB, Link);\r
-\r
-    if (Tcb->InitiatorTaskTag == InitiatorTaskTag) {\r
-      break;\r
-    }\r
-  }\r
-\r
-  return Tcb;\r
-}\r
-\r
-\r
 /**\r
   Create a data segment, pad it, and calculate the CRC if needed.\r
 \r
@@ -2195,7 +2189,7 @@ IScsiNewScsiCmdPdu (
   if (ScsiCmd == NULL) {\r
     NetbufFree (PduHeader);\r
     return NULL;\r
-  }    \r
+  }\r
   Header  = (ISCSI_ADDITIONAL_HEADER *) (ScsiCmd + 1);\r
 \r
   ZeroMem (ScsiCmd, Length);\r
@@ -2869,8 +2863,8 @@ IScsiOnNopInRcvd (
   @param[in]       Lun       The LUN.\r
   @param[in, out]  Packet    The request packet containing IO request, SCSI command\r
                              buffer and buffers to read/write.\r
-                             \r
-  @retval EFI_SUCCES           The SCSI command is executed and the result is updated to \r
+\r
+  @retval EFI_SUCCES           The SCSI command is executed and the result is updated to\r
                                the Packet.\r
   @retval EFI_DEVICE_ERROR     Session state was not as required.\r
   @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
@@ -3164,7 +3158,7 @@ IScsiSessionAbort (
     if (!Conn->Ipv6Flag) {\r
       ProtocolGuid = &gEfiTcp4ProtocolGuid;\r
     } else {\r
-      ProtocolGuid = &gEfiTcp6ProtocolGuid;    \r
+      ProtocolGuid = &gEfiTcp6ProtocolGuid;\r
     }\r
 \r
     gBS->CloseProtocol (\r