--- /dev/null
+/** @file\r
+Copyright (c) 2004 - 2007, Intel Corporation\r
+All rights reserved. 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
+\r
+Module name:\r
+ receive.c\r
+\r
+Abstract:\r
+\r
+Revision history:\r
+ 2000-Feb-03 M(f)J Genesis.\r
+\r
+**/\r
+\r
+\r
+#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 BufferPtr pointer to the memory for the received data\r
+ @param BuffSizePtr is a pointer to the length of the buffer on entry and\r
+ contains the length of the received data on return\r
+ @param HeaderSizePtr pointer to the header portion of the data received.\r
+ @param SourceAddrPtr optional parameter, is a pointer to contain the\r
+ source ethernet address on return\r
+ @param DestinationAddrPtr optional parameter, is a pointer to contain the\r
+ destination ethernet address on return\r
+ @param ProtocolPtr optional parameter, is a pointer to contain the\r
+ protocol type from the ethernet header on return\r
+\r
+\r
+**/\r
+STATIC\r
+EFI_STATUS\r
+pxe_receive (\r
+ SNP_DRIVER *snp,\r
+ VOID *BufferPtr,\r
+ UINTN *BuffSizePtr,\r
+ UINTN *HeaderSizePtr,\r
+ EFI_MAC_ADDRESS *SourceAddrPtr,\r
+ EFI_MAC_ADDRESS *DestinationAddrPtr,\r
+ UINT16 *ProtocolPtr\r
+ )\r
+{\r
+ PXE_CPB_RECEIVE *cpb;\r
+ PXE_DB_RECEIVE *db;\r
+ UINTN buf_size;\r
+\r
+ cpb = snp->cpb;\r
+ db = snp->db;\r
+ buf_size = *BuffSizePtr;\r
+\r
+ cpb->BufferAddr = (UINT64)(UINTN) BufferPtr;\r
+ cpb->BufferLen = (UINT32) *BuffSizePtr;\r
+\r
+ cpb->reserved = 0;\r
+\r
+ 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.CPBaddr = (UINT64)(UINTN) cpb;\r
+\r
+ snp->cdb.DBsize = sizeof (PXE_DB_RECEIVE);\r
+ snp->cdb.DBaddr = (UINT64)(UINTN) db;\r
+\r
+ snp->cdb.StatCode = PXE_STATCODE_INITIALIZE;\r
+ snp->cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;\r
+ snp->cdb.IFnum = snp->if_num;\r
+ snp->cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;\r
+\r
+ //\r
+ // Issue UNDI command and check result.\r
+ //\r
+ DEBUG ((EFI_D_NET, "\nsnp->undi.receive () "));\r
+\r
+ (*snp->issue_undi32_command) ((UINT64)(UINTN) &snp->cdb);\r
+\r
+ switch (snp->cdb.StatCode) {\r
+ case PXE_STATCODE_SUCCESS:\r
+ break;\r
+\r
+ case PXE_STATCODE_NO_DATA:\r
+ DEBUG (\r
+ (EFI_D_NET,\r
+ "\nsnp->undi.receive () %xh:%xh\n",\r
+ snp->cdb.StatFlags,\r
+ snp->cdb.StatCode)\r
+ );\r
+\r
+ return EFI_NOT_READY;\r
+\r
+ default:\r
+ DEBUG (\r
+ (EFI_D_ERROR,\r
+ "\nsnp->undi.receive() %xh:%xh\n",\r
+ snp->cdb.StatFlags,\r
+ snp->cdb.StatCode)\r
+ );\r
+\r
+ return EFI_DEVICE_ERROR;\r
+ }\r
+\r
+ *BuffSizePtr = db->FrameLen;\r
+\r
+ if (HeaderSizePtr != NULL) {\r
+ *HeaderSizePtr = db->MediaHeaderLen;\r
+ }\r
+\r
+ if (SourceAddrPtr != NULL) {\r
+ CopyMem (SourceAddrPtr, &db->SrcAddr, snp->mode.HwAddressSize);\r
+ }\r
+\r
+ if (DestinationAddrPtr != NULL) {\r
+ CopyMem (DestinationAddrPtr, &db->DestAddr, snp->mode.HwAddressSize);\r
+ }\r
+\r
+ if (ProtocolPtr != NULL) {\r
+ *ProtocolPtr = (UINT16) PXE_SWAP_UINT16 (db->Protocol); /* we need to do the byte swapping */\r
+ }\r
+\r
+ return (*BuffSizePtr <= buf_size) ? EFI_SUCCESS : EFI_BUFFER_TOO_SMALL;\r
+}\r
+\r
+\r
+/**\r
+ This is the SNP interface routine for receiving network data.\r
+ This routine basically retrieves snp structure, checks the SNP state and\r
+ calls the pxe_receive routine to actually do the receive!\r
+\r
+ @param this context pointer\r
+ @param HeaderSizePtr optional parameter and is a pointer to the header\r
+ portion of the data received.\r
+ @param BuffSizePtr is a pointer to the length of the buffer on entry and\r
+ contains the length of the received data on return\r
+ @param BufferPtr pointer to the memory for the received data\r
+ @param SourceAddrPtr optional parameter, is a pointer to contain the\r
+ source ethernet address on return\r
+ @param DestinationAddrPtr optional parameter, is a pointer to contain the\r
+ destination ethernet address on return\r
+ @param ProtocolPtr optional parameter, is a pointer to contain the\r
+ protocol type from the ethernet header on return\r
+\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+snp_undi32_receive (\r
+ IN EFI_SIMPLE_NETWORK_PROTOCOL * this,\r
+ OUT UINTN *HeaderSizePtr OPTIONAL,\r
+ IN OUT UINTN *BuffSizePtr,\r
+ OUT VOID *BufferPtr,\r
+ OUT EFI_MAC_ADDRESS * SourceAddrPtr OPTIONAL,\r
+ OUT EFI_MAC_ADDRESS * DestinationAddrPtr OPTIONAL,\r
+ OUT UINT16 *ProtocolPtr OPTIONAL\r
+ )\r
+{\r
+ SNP_DRIVER *snp;\r
+ EFI_TPL OldTpl;\r
+ EFI_STATUS Status;\r
+\r
+ if (this == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (this);\r
+\r
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+ switch (snp->mode.State) {\r
+ case EfiSimpleNetworkInitialized:\r
+ break;\r
+\r
+ case EfiSimpleNetworkStopped:\r
+ Status = EFI_NOT_STARTED;\r
+ goto ON_EXIT;\r
+\r
+ default:\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto ON_EXIT;\r
+ }\r
+\r
+ if ((BuffSizePtr == NULL) || (BufferPtr == NULL)) {\r
+ Status = EFI_INVALID_PARAMETER;\r
+ goto ON_EXIT;\r
+ }\r
+\r
+ if (!snp->mode.ReceiveFilterSetting) {\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto ON_EXIT;\r
+ }\r
+\r
+ Status = pxe_receive (\r
+ snp,\r
+ BufferPtr,\r
+ BuffSizePtr,\r
+ HeaderSizePtr,\r
+ SourceAddrPtr,\r
+ DestinationAddrPtr,\r
+ ProtocolPtr\r
+ );\r
+\r
+ON_EXIT:\r
+ gBS->RestoreTPL (OldTpl);\r
+\r
+ return Status;\r
+}\r