EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

MdeModulePkg/Universal/Network/SnpDxe/Receive.c

Go to the documentation of this file.
00001 
00016 #include "Snp.h"
00017 
00044 EFI_STATUS
00045 PxeReceive (
00046   SNP_DRIVER      *Snp,
00047   VOID            *Buffer,
00048   UINTN           *BufferSize,
00049   UINTN           *HeaderSize,
00050   EFI_MAC_ADDRESS *SrcAddr,
00051   EFI_MAC_ADDRESS *DestAddr,
00052   UINT16          *Protocol
00053   )
00054 {
00055   PXE_CPB_RECEIVE *Cpb;
00056   PXE_DB_RECEIVE  *Db;
00057   UINTN           BuffSize;
00058 
00059   Cpb       = Snp->Cpb;
00060   Db        = Snp->Db;
00061   BuffSize  = *BufferSize;
00062 
00063   Cpb->BufferAddr = (UINT64)(UINTN) Buffer;
00064   Cpb->BufferLen  = (UINT32) *BufferSize;
00065 
00066   Cpb->reserved       = 0;
00067 
00068   Snp->Cdb.OpCode     = PXE_OPCODE_RECEIVE;
00069   Snp->Cdb.OpFlags    = PXE_OPFLAGS_NOT_USED;
00070 
00071   Snp->Cdb.CPBsize    = (UINT16) sizeof (PXE_CPB_RECEIVE);
00072   Snp->Cdb.CPBaddr    = (UINT64)(UINTN) Cpb;
00073 
00074   Snp->Cdb.DBsize     = (UINT16) sizeof (PXE_DB_RECEIVE);
00075   Snp->Cdb.DBaddr     = (UINT64)(UINTN) Db;
00076 
00077   Snp->Cdb.StatCode   = PXE_STATCODE_INITIALIZE;
00078   Snp->Cdb.StatFlags  = PXE_STATFLAGS_INITIALIZE;
00079   Snp->Cdb.IFnum      = Snp->IfNum;
00080   Snp->Cdb.Control    = PXE_CONTROL_LAST_CDB_IN_LIST;
00081 
00082   //
00083   // Issue UNDI command and check result.
00084   //
00085   DEBUG ((EFI_D_NET, "\nsnp->undi.receive ()  "));
00086 
00087   (*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);
00088 
00089   switch (Snp->Cdb.StatCode) {
00090   case PXE_STATCODE_SUCCESS:
00091     break;
00092 
00093   case PXE_STATCODE_NO_DATA:
00094     DEBUG (
00095       (EFI_D_NET,
00096       "\nsnp->undi.receive ()  %xh:%xh\n",
00097       Snp->Cdb.StatFlags,
00098       Snp->Cdb.StatCode)
00099       );
00100 
00101     return EFI_NOT_READY;
00102 
00103   default:
00104     DEBUG (
00105       (EFI_D_ERROR,
00106       "\nsnp->undi.receive()  %xh:%xh\n",
00107       Snp->Cdb.StatFlags,
00108       Snp->Cdb.StatCode)
00109       );
00110 
00111     return EFI_DEVICE_ERROR;
00112   }
00113 
00114   *BufferSize = Db->FrameLen;
00115 
00116   if (HeaderSize != NULL) {
00117     *HeaderSize = Db->MediaHeaderLen;
00118   }
00119 
00120   if (SrcAddr != NULL) {
00121     CopyMem (SrcAddr, &Db->SrcAddr, Snp->Mode.HwAddressSize);
00122   }
00123 
00124   if (DestAddr != NULL) {
00125     CopyMem (DestAddr, &Db->DestAddr, Snp->Mode.HwAddressSize);
00126   }
00127 
00128   if (Protocol != NULL) {
00129     //
00130     // We need to do the byte swapping
00131     //
00132     *Protocol = (UINT16) PXE_SWAP_UINT16 (Db->Protocol);
00133   }
00134 
00135   //
00136   // We have received a packet from network interface, which implies that the
00137   // network cable should be present. While, some UNDI driver may not report
00138   // correct media status during Snp->Initialize(). So, we need ensure
00139   // MediaPresent in SNP mode data is set to correct value.
00140   //
00141   if (Snp->Mode.MediaPresentSupported && !Snp->Mode.MediaPresent) {
00142     Snp->Mode.MediaPresent = TRUE;
00143   }
00144 
00145   return (*BufferSize <= BuffSize) ? EFI_SUCCESS : EFI_BUFFER_TOO_SMALL;
00146 }
00147 
00196 EFI_STATUS
00197 EFIAPI
00198 SnpUndi32Receive (
00199   IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
00200   OUT UINTN                      *HeaderSize OPTIONAL,
00201   IN OUT UINTN                   *BufferSize,
00202   OUT VOID                       *Buffer,
00203   OUT EFI_MAC_ADDRESS            *SrcAddr OPTIONAL,
00204   OUT EFI_MAC_ADDRESS            *DestAddr OPTIONAL,
00205   OUT UINT16                     *Protocol OPTIONAL
00206   )
00207 {
00208   SNP_DRIVER  *Snp;
00209   EFI_TPL     OldTpl;
00210   EFI_STATUS  Status;
00211 
00212   if (This == NULL) {
00213     return EFI_INVALID_PARAMETER;
00214   }
00215 
00216   Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);
00217 
00218   OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
00219 
00220   switch (Snp->Mode.State) {
00221   case EfiSimpleNetworkInitialized:
00222     break;
00223 
00224   case EfiSimpleNetworkStopped:
00225     Status = EFI_NOT_STARTED;
00226     goto ON_EXIT;
00227 
00228   default:
00229     Status = EFI_DEVICE_ERROR;
00230     goto ON_EXIT;
00231   }
00232 
00233   if ((BufferSize == NULL) || (Buffer == NULL)) {
00234     Status = EFI_INVALID_PARAMETER;
00235     goto ON_EXIT;
00236   }
00237 
00238   if (Snp->Mode.ReceiveFilterSetting == 0) {
00239     Status = EFI_DEVICE_ERROR;
00240     goto ON_EXIT;
00241   }
00242 
00243   Status = PxeReceive (
00244              Snp,
00245              Buffer,
00246              BufferSize,
00247              HeaderSize,
00248              SrcAddr,
00249              DestAddr,
00250              Protocol
00251              );
00252 
00253 ON_EXIT:
00254   gBS->RestoreTPL (OldTpl);
00255 
00256   return Status;
00257 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines