]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/SnpDxe/Receive.c
BaseTools:Change the path of the file that Binary Cache
[mirror_edk2.git] / MdeModulePkg / Universal / Network / SnpDxe / Receive.c
index bfabe11aa5e61e63348a90ca09f33e4ae03a8c4c..28cea0d2e9722fbfa5482e7398a2a8388d7a1f9a 100644 (file)
@@ -1,14 +1,8 @@
 /** @file\r
-               Implementation of receiving a packet from a network interface.\r
\r
-Copyright (c) 2004 - 2007, Intel Corporation. <BR> \r
-All rights reserved. This program and the accompanying materials are licensed \r
-and made available under the terms and conditions of the BSD License which \r
-accompanies this distribution. The full text of the license may be found at \r
-http://opensource.org/licenses/bsd-license.php \r
+  Implementation of receiving a packet from a network interface.\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 - 2010, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
@@ -16,21 +10,29 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include "Snp.h"\r
 \r
 /**\r
-  this routine calls undi to receive a packet and fills in the data in the\r
-  input pointers!\r
-\r
-  @param  Snp                 pointer to snp driver structure\r
-  @param  Buffer           pointer to the memory for the received data\r
-  @param  BufferSize         is a pointer to the length of the buffer on entry and\r
-                              contains the length of the received data on return\r
-  @param  HeaderSize       pointer to the header portion of the data received.\r
-  @param  SrcAddr       optional parameter, is a pointer to contain the\r
-                              source ethernet address on return\r
-  @param  DestAddr  optional parameter, is a pointer to contain the\r
-                              destination ethernet address on return\r
-  @param  Protocol         optional parameter, is a pointer to contain the\r
-                              protocol type from the ethernet header on return\r
-\r
+  Call UNDI to receive a packet and fills in the data in the input pointers.\r
+\r
+  @param  Snp          Pointer to snp driver structure\r
+  @param  Buffer       Pointer to the memory for the received data\r
+  @param  BufferSize   Pointer to the length of the buffer on entry and contains\r
+                       the length of the received data on return\r
+  @param  HeaderSize   Pointer to the header portion of the data received.\r
+  @param  SrcAddr      Pointer to contain the source ethernet address on return\r
+  @param  DestAddr     Pointer to contain the destination ethernet address on\r
+                       return\r
+  @param  Protocol     Pointer to contain the protocol type from the ethernet\r
+                       header on return\r
+\r
+\r
+  @retval EFI_SUCCESS           The received data was stored in Buffer, and\r
+                                BufferSize has been updated to the number of\r
+                                bytes received.\r
+  @retval EFI_DEVICE_ERROR      Fail to execute UNDI command.\r
+  @retval EFI_NOT_READY         No packets have been received on the network\r
+                                interface.\r
+  @retval EFI_BUFFER_TOO_SMALL  BufferSize is too small for the received\r
+                                packets. BufferSize has been updated to the\r
+                                required size.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -60,10 +62,10 @@ PxeReceive (
   Snp->Cdb.OpCode     = PXE_OPCODE_RECEIVE;\r
   Snp->Cdb.OpFlags    = PXE_OPFLAGS_NOT_USED;\r
 \r
-  Snp->Cdb.CPBsize    = sizeof (PXE_CPB_RECEIVE);\r
+  Snp->Cdb.CPBsize    = (UINT16) sizeof (PXE_CPB_RECEIVE);\r
   Snp->Cdb.CPBaddr    = (UINT64)(UINTN) Cpb;\r
 \r
-  Snp->Cdb.DBsize     = sizeof (PXE_DB_RECEIVE);\r
+  Snp->Cdb.DBsize     = (UINT16) sizeof (PXE_DB_RECEIVE);\r
   Snp->Cdb.DBaddr     = (UINT64)(UINTN) Db;\r
 \r
   Snp->Cdb.StatCode   = PXE_STATCODE_INITIALIZE;\r
@@ -118,7 +120,20 @@ PxeReceive (
   }\r
 \r
   if (Protocol != NULL) {\r
-    *Protocol = (UINT16) PXE_SWAP_UINT16 (Db->Protocol); /*  we need to do the byte swapping */\r
+    //\r
+    // We need to do the byte swapping\r
+    //\r
+    *Protocol = (UINT16) PXE_SWAP_UINT16 (Db->Protocol);\r
+  }\r
+\r
+  //\r
+  // We have received a packet from network interface, which implies that the\r
+  // network cable should be present. While, some UNDI driver may not report\r
+  // correct media status during Snp->Initialize(). So, we need ensure\r
+  // MediaPresent in SNP mode data is set to correct value.\r
+  //\r
+  if (Snp->Mode.MediaPresentSupported && !Snp->Mode.MediaPresent) {\r
+    Snp->Mode.MediaPresent = TRUE;\r
   }\r
 \r
   return (*BufferSize <= BuffSize) ? EFI_SUCCESS : EFI_BUFFER_TOO_SMALL;\r
@@ -128,44 +143,44 @@ PxeReceive (
   Receives a packet from a network interface.\r
 \r
   This function retrieves one packet from the receive queue of a network interface.\r
-  If there are no packets on the receive queue, then EFI_NOT_READY will be \r
+  If there are no packets on the receive queue, then EFI_NOT_READY will be\r
   returned. If there is a packet on the receive queue, and the size of the packet\r
   is smaller than BufferSize, then the contents of the packet will be placed in\r
   Buffer, and BufferSize will be updated with the actual size of the packet.\r
   In addition, if SrcAddr, DestAddr, and Protocol are not NULL, then these values\r
-  will be extracted from the media header and returned. EFI_SUCCESS will be \r
+  will be extracted from the media header and returned. EFI_SUCCESS will be\r
   returned if a packet was successfully received.\r
   If BufferSize is smaller than the received packet, then the size of the receive\r
   packet will be placed in BufferSize and EFI_BUFFER_TOO_SMALL will be returned.\r
   If the driver has not been initialized, EFI_DEVICE_ERROR will be returned.\r
 \r
   @param This       A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.\r
-  @param HeaderSize The size, in bytes, of the media header received on the network \r
-                    interface. If this parameter is NULL, then the media header size \r
+  @param HeaderSize The size, in bytes, of the media header received on the network\r
+                    interface. If this parameter is NULL, then the media header size\r
                     will not be returned.\r
-  @param BufferSize On entry, the size, in bytes, of Buffer. On exit, the size, in \r
+  @param BufferSize On entry, the size, in bytes, of Buffer. On exit, the size, in\r
                     bytes, of the packet that was received on the network interface.\r
   @param Buffer     A pointer to the data buffer to receive both the media\r
                     header and the data.\r
   @param SrcAddr    The source HW MAC address. If this parameter is NULL, the HW\r
-                    MAC source address will not be extracted from the media header. \r
-  @param DestAddr   The destination HW MAC address. If this parameter is NULL, \r
-                    the HW MAC destination address will not be extracted from \r
+                    MAC source address will not be extracted from the media header.\r
+  @param DestAddr   The destination HW MAC address. If this parameter is NULL,\r
+                    the HW MAC destination address will not be extracted from\r
                     the media header.\r
-  @param Protocol   The media header type. If this parameter is NULL, then the \r
-                    protocol will not be extracted from the media header. See \r
+  @param Protocol   The media header type. If this parameter is NULL, then the\r
+                    protocol will not be extracted from the media header. See\r
                     RFC 1700 section "Ether Types" for examples.\r
 \r
-  @retval EFI_SUCCESS           The received data was stored in Buffer, and \r
-                                BufferSize has been updated to the number of \r
+  @retval EFI_SUCCESS           The received data was stored in Buffer, and\r
+                                BufferSize has been updated to the number of\r
                                 bytes received.\r
   @retval EFI_NOT_STARTED       The network interface has not been started.\r
   @retval EFI_NOT_READY         No packets have been received on the network interface.\r
-  @retval EFI_BUFFER_TOO_SMALL  BufferSize is too small for the received packets. \r
+  @retval EFI_BUFFER_TOO_SMALL  BufferSize is too small for the received packets.\r
                                 BufferSize has been updated to the required size.\r
   @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r
                                 * The This parameter is NULL\r
-                                * The This parameter does not point to a valid \r
+                                * The This parameter does not point to a valid\r
                                   EFI_SIMPLE_NETWORK_PROTOCOL structure.\r
                                 * The BufferSize parameter is NULL\r
                                 * The Buffer parameter is NULL\r
@@ -214,7 +229,7 @@ SnpUndi32Receive (
     goto ON_EXIT;\r
   }\r
 \r
-  if (!Snp->Mode.ReceiveFilterSetting) {\r
+  if (Snp->Mode.ReceiveFilterSetting == 0) {\r
     Status = EFI_DEVICE_ERROR;\r
     goto ON_EXIT;\r
   }\r