2008-02-20 03:36:47 +01:00
|
|
|
/** @file
|
2008-11-13 04:42:21 +01:00
|
|
|
Implementation of receiving a packet from a network interface.
|
2009-01-12 07:00:53 +01:00
|
|
|
|
|
|
|
Copyright (c) 2004 - 2007, Intel Corporation. <BR>
|
|
|
|
All rights reserved. This program and the accompanying materials are licensed
|
|
|
|
and made available under the terms and conditions of the BSD License which
|
|
|
|
accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
2008-02-20 03:36:47 +01:00
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
|
|
#include "Snp.h"
|
|
|
|
|
|
|
|
/**
|
2008-12-29 02:16:13 +01:00
|
|
|
Call UNDI to receive a packet and fills in the data in the input pointers.
|
|
|
|
|
|
|
|
@param Snp Pointer to snp driver structure
|
|
|
|
@param Buffer Pointer to the memory for the received data
|
|
|
|
@param BufferSize Pointer to the length of the buffer on entry and contains
|
|
|
|
the length of the received data on return
|
|
|
|
@param HeaderSize Pointer to the header portion of the data received.
|
2009-01-12 07:00:53 +01:00
|
|
|
@param SrcAddr Pointer to contain the source ethernet address on return
|
|
|
|
@param DestAddr Pointer to contain the destination ethernet address on
|
2008-12-29 02:16:13 +01:00
|
|
|
return
|
2009-01-12 07:00:53 +01:00
|
|
|
@param Protocol Pointer to contain the protocol type from the ethernet
|
2008-12-29 02:16:13 +01:00
|
|
|
header on return
|
|
|
|
|
|
|
|
|
2009-01-12 07:00:53 +01:00
|
|
|
@retval EFI_SUCCESS The received data was stored in Buffer, and
|
|
|
|
BufferSize has been updated to the number of
|
2008-12-29 02:16:13 +01:00
|
|
|
bytes received.
|
2009-01-12 07:00:53 +01:00
|
|
|
@retval EFI_DEVICE_ERROR Fail to execute UNDI command.
|
|
|
|
@retval EFI_NOT_READY No packets have been received on the network
|
2008-12-29 02:16:13 +01:00
|
|
|
interface.
|
2009-01-12 07:00:53 +01:00
|
|
|
@retval EFI_BUFFER_TOO_SMALL BufferSize is too small for the received
|
2008-12-29 02:16:13 +01:00
|
|
|
packets. BufferSize has been updated to the
|
|
|
|
required size.
|
2008-02-20 03:36:47 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
2008-11-13 04:42:21 +01:00
|
|
|
PxeReceive (
|
|
|
|
SNP_DRIVER *Snp,
|
|
|
|
VOID *Buffer,
|
|
|
|
UINTN *BufferSize,
|
|
|
|
UINTN *HeaderSize,
|
|
|
|
EFI_MAC_ADDRESS *SrcAddr,
|
|
|
|
EFI_MAC_ADDRESS *DestAddr,
|
|
|
|
UINT16 *Protocol
|
2008-02-20 03:36:47 +01:00
|
|
|
)
|
|
|
|
{
|
2008-11-13 04:42:21 +01:00
|
|
|
PXE_CPB_RECEIVE *Cpb;
|
|
|
|
PXE_DB_RECEIVE *Db;
|
|
|
|
UINTN BuffSize;
|
2008-02-20 03:36:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Cpb = Snp->Cpb;
|
|
|
|
Db = Snp->Db;
|
|
|
|
BuffSize = *BufferSize;
|
2008-02-20 03:36:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Cpb->BufferAddr = (UINT64)(UINTN) Buffer;
|
|
|
|
Cpb->BufferLen = (UINT32) *BufferSize;
|
2008-02-20 03:36:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Cpb->reserved = 0;
|
2008-02-20 03:36:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.OpCode = PXE_OPCODE_RECEIVE;
|
|
|
|
Snp->Cdb.OpFlags = PXE_OPFLAGS_NOT_USED;
|
2008-02-20 03:36:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.CPBsize = sizeof (PXE_CPB_RECEIVE);
|
|
|
|
Snp->Cdb.CPBaddr = (UINT64)(UINTN) Cpb;
|
2008-02-20 03:36:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.DBsize = sizeof (PXE_DB_RECEIVE);
|
|
|
|
Snp->Cdb.DBaddr = (UINT64)(UINTN) Db;
|
2008-02-20 03:36:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;
|
|
|
|
Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
|
|
|
|
Snp->Cdb.IFnum = Snp->IfNum;
|
|
|
|
Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
|
2008-02-20 03:36:47 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Issue UNDI command and check result.
|
|
|
|
//
|
2009-01-12 07:00:53 +01:00
|
|
|
DEBUG ((EFI_D_NET, "\nsnp->undi.receive () "));
|
2008-02-20 03:36:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
(*Snp->IssueUndi32Command) ((UINT64)(UINTN) &Snp->Cdb);
|
2008-02-20 03:36:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
switch (Snp->Cdb.StatCode) {
|
2008-02-20 03:36:47 +01:00
|
|
|
case PXE_STATCODE_SUCCESS:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PXE_STATCODE_NO_DATA:
|
|
|
|
DEBUG (
|
2009-01-12 07:00:53 +01:00
|
|
|
(EFI_D_NET,
|
2008-02-20 03:36:47 +01:00
|
|
|
"\nsnp->undi.receive () %xh:%xh\n",
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.StatFlags,
|
|
|
|
Snp->Cdb.StatCode)
|
2008-02-20 03:36:47 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return EFI_NOT_READY;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DEBUG (
|
2009-02-09 02:22:19 +01:00
|
|
|
(EFI_D_ERROR,
|
2008-02-20 03:36:47 +01:00
|
|
|
"\nsnp->undi.receive() %xh:%xh\n",
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.StatFlags,
|
|
|
|
Snp->Cdb.StatCode)
|
2008-02-20 03:36:47 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
*BufferSize = Db->FrameLen;
|
2008-02-20 03:36:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (HeaderSize != NULL) {
|
|
|
|
*HeaderSize = Db->MediaHeaderLen;
|
2008-02-20 03:36:47 +01:00
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (SrcAddr != NULL) {
|
|
|
|
CopyMem (SrcAddr, &Db->SrcAddr, Snp->Mode.HwAddressSize);
|
2008-02-20 03:36:47 +01:00
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (DestAddr != NULL) {
|
|
|
|
CopyMem (DestAddr, &Db->DestAddr, Snp->Mode.HwAddressSize);
|
2008-02-20 03:36:47 +01:00
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (Protocol != NULL) {
|
2008-12-29 02:16:13 +01:00
|
|
|
//
|
|
|
|
// We need to do the byte swapping
|
|
|
|
//
|
|
|
|
*Protocol = (UINT16) PXE_SWAP_UINT16 (Db->Protocol);
|
2008-02-20 03:36:47 +01:00
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
return (*BufferSize <= BuffSize) ? EFI_SUCCESS : EFI_BUFFER_TOO_SMALL;
|
2008-02-20 03:36:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-11-13 04:42:21 +01:00
|
|
|
Receives a packet from a network interface.
|
|
|
|
|
|
|
|
This function retrieves one packet from the receive queue of a network interface.
|
2009-01-12 07:00:53 +01:00
|
|
|
If there are no packets on the receive queue, then EFI_NOT_READY will be
|
2008-11-13 04:42:21 +01:00
|
|
|
returned. If there is a packet on the receive queue, and the size of the packet
|
|
|
|
is smaller than BufferSize, then the contents of the packet will be placed in
|
|
|
|
Buffer, and BufferSize will be updated with the actual size of the packet.
|
|
|
|
In addition, if SrcAddr, DestAddr, and Protocol are not NULL, then these values
|
2009-01-12 07:00:53 +01:00
|
|
|
will be extracted from the media header and returned. EFI_SUCCESS will be
|
2008-11-13 04:42:21 +01:00
|
|
|
returned if a packet was successfully received.
|
|
|
|
If BufferSize is smaller than the received packet, then the size of the receive
|
|
|
|
packet will be placed in BufferSize and EFI_BUFFER_TOO_SMALL will be returned.
|
|
|
|
If the driver has not been initialized, EFI_DEVICE_ERROR will be returned.
|
|
|
|
|
|
|
|
@param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
|
2009-01-12 07:00:53 +01:00
|
|
|
@param HeaderSize The size, in bytes, of the media header received on the network
|
|
|
|
interface. If this parameter is NULL, then the media header size
|
2008-11-13 04:42:21 +01:00
|
|
|
will not be returned.
|
2009-01-12 07:00:53 +01:00
|
|
|
@param BufferSize On entry, the size, in bytes, of Buffer. On exit, the size, in
|
2008-11-13 04:42:21 +01:00
|
|
|
bytes, of the packet that was received on the network interface.
|
|
|
|
@param Buffer A pointer to the data buffer to receive both the media
|
|
|
|
header and the data.
|
|
|
|
@param SrcAddr The source HW MAC address. If this parameter is NULL, the HW
|
2009-01-12 07:00:53 +01:00
|
|
|
MAC source address will not be extracted from the media header.
|
|
|
|
@param DestAddr The destination HW MAC address. If this parameter is NULL,
|
|
|
|
the HW MAC destination address will not be extracted from
|
2008-11-13 04:42:21 +01:00
|
|
|
the media header.
|
2009-01-12 07:00:53 +01:00
|
|
|
@param Protocol The media header type. If this parameter is NULL, then the
|
|
|
|
protocol will not be extracted from the media header. See
|
2008-11-13 04:42:21 +01:00
|
|
|
RFC 1700 section "Ether Types" for examples.
|
|
|
|
|
2009-01-12 07:00:53 +01:00
|
|
|
@retval EFI_SUCCESS The received data was stored in Buffer, and
|
|
|
|
BufferSize has been updated to the number of
|
2008-11-13 04:42:21 +01:00
|
|
|
bytes received.
|
|
|
|
@retval EFI_NOT_STARTED The network interface has not been started.
|
|
|
|
@retval EFI_NOT_READY No packets have been received on the network interface.
|
2009-01-12 07:00:53 +01:00
|
|
|
@retval EFI_BUFFER_TOO_SMALL BufferSize is too small for the received packets.
|
2008-11-13 04:42:21 +01:00
|
|
|
BufferSize has been updated to the required size.
|
|
|
|
@retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:
|
|
|
|
* The This parameter is NULL
|
2009-01-12 07:00:53 +01:00
|
|
|
* The This parameter does not point to a valid
|
2008-11-13 04:42:21 +01:00
|
|
|
EFI_SIMPLE_NETWORK_PROTOCOL structure.
|
|
|
|
* The BufferSize parameter is NULL
|
|
|
|
* The Buffer parameter is NULL
|
|
|
|
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
|
2008-02-20 03:36:47 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
2008-11-13 04:42:21 +01:00
|
|
|
SnpUndi32Receive (
|
|
|
|
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
|
|
|
|
OUT UINTN *HeaderSize OPTIONAL,
|
|
|
|
IN OUT UINTN *BufferSize,
|
|
|
|
OUT VOID *Buffer,
|
|
|
|
OUT EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
|
|
|
|
OUT EFI_MAC_ADDRESS *DestAddr OPTIONAL,
|
|
|
|
OUT UINT16 *Protocol OPTIONAL
|
2008-02-20 03:36:47 +01:00
|
|
|
)
|
|
|
|
{
|
2008-11-13 04:42:21 +01:00
|
|
|
SNP_DRIVER *Snp;
|
2008-02-20 03:36:47 +01:00
|
|
|
EFI_TPL OldTpl;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (This == NULL) {
|
2008-02-20 03:36:47 +01:00
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);
|
2008-02-20 03:36:47 +01:00
|
|
|
|
|
|
|
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
switch (Snp->Mode.State) {
|
2008-02-20 03:36:47 +01:00
|
|
|
case EfiSimpleNetworkInitialized:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EfiSimpleNetworkStopped:
|
|
|
|
Status = EFI_NOT_STARTED;
|
|
|
|
goto ON_EXIT;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Status = EFI_DEVICE_ERROR;
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if ((BufferSize == NULL) || (Buffer == NULL)) {
|
2008-02-20 03:36:47 +01:00
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (!Snp->Mode.ReceiveFilterSetting) {
|
2008-02-20 03:36:47 +01:00
|
|
|
Status = EFI_DEVICE_ERROR;
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Status = PxeReceive (
|
|
|
|
Snp,
|
|
|
|
Buffer,
|
|
|
|
BufferSize,
|
|
|
|
HeaderSize,
|
|
|
|
SrcAddr,
|
|
|
|
DestAddr,
|
|
|
|
Protocol
|
2008-02-20 03:36:47 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
ON_EXIT:
|
|
|
|
gBS->RestoreTPL (OldTpl);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|