]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StdLib/EfiSocketLib/Tcp4.c
Only use ports with a network connection (media present) when connecting to a remote...
[mirror_edk2.git] / StdLib / EfiSocketLib / Tcp4.c
index 32c7a394c4a4d10497813732f2d01e0577d5db85..0643518f0d663f7b34d5991704e0d522f9fe51af 100644 (file)
@@ -453,6 +453,7 @@ EslTcp4ConnectStart (
   ESL_PORT * pPort;\r
   ESL_TCP4_CONTEXT * pTcp4;\r
   EFI_TCP4_PROTOCOL * pTcp4Protocol;\r
+  EFI_SIMPLE_NETWORK_MODE SnpModeData;\r
   EFI_STATUS Status;\r
 \r
   DBG_ENTER ( );\r
@@ -509,10 +510,41 @@ EslTcp4ConnectStart (
       pPort->bConfigured = TRUE;\r
 \r
       //\r
-      //  Attempt the connection to the remote system\r
+      //  Verify the port connection\r
       //\r
-      Status = pTcp4Protocol->Connect ( pTcp4Protocol,\r
-                                        &pTcp4->ConnectToken );\r
+      Status = pTcp4Protocol->GetModeData ( pTcp4Protocol,\r
+                                            NULL,\r
+                                            NULL,\r
+                                            NULL,\r
+                                            NULL,\r
+                                            &SnpModeData );\r
+      if ( !EFI_ERROR ( Status )) {\r
+        if ( SnpModeData.MediaPresentSupported\r
+          && ( !SnpModeData.MediaPresent )) {\r
+          //\r
+          //  Port is not connected to the network\r
+          //\r
+          pTcp4->ConnectToken.CompletionToken.Status = EFI_NO_MEDIA;\r
+\r
+          //\r
+          //  Continue with the next port\r
+          //\r
+          gBS->CheckEvent ( pTcp4->ConnectToken.CompletionToken.Event );\r
+          gBS->SignalEvent ( pTcp4->ConnectToken.CompletionToken.Event );\r
+\r
+          //\r
+          //  Connection in progress\r
+          //\r
+          Status = EFI_SUCCESS;\r
+        }\r
+        else {\r
+          //\r
+          //  Attempt the connection to the remote system\r
+          //\r
+          Status = pTcp4Protocol->Connect ( pTcp4Protocol,\r
+                                            &pTcp4->ConnectToken );\r
+        }\r
+      }\r
       if ( !EFI_ERROR ( Status )) {\r
         //\r
         //  Connection in progress\r
@@ -552,6 +584,7 @@ EslTcp4ConnectStart (
           pSocket->errno = ETIMEDOUT;\r
           break;\r
 \r
+        case EFI_NO_MEDIA:\r
         case EFI_NETWORK_UNREACHABLE:\r
           pSocket->errno = ENETDOWN;\r
           break;\r
@@ -1571,6 +1604,11 @@ EslTcp4Receive (
             DataLength ));\r
   CopyMem ( pBuffer, pPacket->pBuffer, DataLength );\r
 \r
+  //\r
+  //  Set the next buffer address\r
+  //\r
+  pBuffer += DataLength;\r
+\r
   //\r
   //  Determine if the data is being read\r
   //\r