2008-02-20 03:41:47 +01:00
|
|
|
/** @file
|
2008-11-13 04:42:21 +01:00
|
|
|
Implementation of transmitting a packet.
|
|
|
|
|
2010-04-24 11:33:45 +02:00
|
|
|
Copyright (c) 2004 - 2007, Intel Corporation. All rights reserved.<BR>
|
|
|
|
This program and the accompanying materials are licensed
|
2008-11-13 04:42:21 +01:00
|
|
|
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:41: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 create the meadia header for the given data buffer.
|
2008-02-20 03:41:47 +01:00
|
|
|
|
2008-12-29 02:16:13 +01:00
|
|
|
@param Snp Pointer to SNP driver structure.
|
|
|
|
@param MacHeaderPtr Address where the media header will be filled in.
|
|
|
|
@param HeaderSize Size of the memory at MacHeaderPtr.
|
|
|
|
@param Buffer Data buffer pointer.
|
|
|
|
@param BufferSize Size of data in the Buffer
|
|
|
|
@param DestAddr Address of the destination mac address buffer.
|
|
|
|
@param SrcAddr Address of the source mac address buffer.
|
|
|
|
@param ProtocolPtr Address of the protocol type.
|
2008-02-20 03:41:47 +01:00
|
|
|
|
2008-12-29 02:16:13 +01:00
|
|
|
@retval EFI_SUCCESS Successfully completed the undi call.
|
|
|
|
@retval Other Error return from undi call.
|
2008-02-20 03:41:47 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
2008-11-13 04:42:21 +01:00
|
|
|
PxeFillHeader (
|
|
|
|
SNP_DRIVER *Snp,
|
2008-02-20 03:41:47 +01:00
|
|
|
VOID *MacHeaderPtr,
|
2008-11-13 04:42:21 +01:00
|
|
|
UINTN HeaderSize,
|
|
|
|
VOID *Buffer,
|
|
|
|
UINTN BufferSize,
|
|
|
|
EFI_MAC_ADDRESS *DestAddr,
|
|
|
|
EFI_MAC_ADDRESS *SrcAddr,
|
2008-02-20 03:41:47 +01:00
|
|
|
UINT16 *ProtocolPtr
|
|
|
|
)
|
|
|
|
{
|
2008-11-13 04:42:21 +01:00
|
|
|
PXE_CPB_FILL_HEADER_FRAGMENTED *Cpb;
|
2008-02-20 03:41:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Cpb = Snp->Cpb;
|
|
|
|
if (SrcAddr != NULL) {
|
2008-02-20 03:41:47 +01:00
|
|
|
CopyMem (
|
2008-11-13 04:42:21 +01:00
|
|
|
(VOID *) Cpb->SrcAddr,
|
|
|
|
(VOID *) SrcAddr,
|
|
|
|
Snp->Mode.HwAddressSize
|
2008-02-20 03:41:47 +01:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
CopyMem (
|
2008-11-13 04:42:21 +01:00
|
|
|
(VOID *) Cpb->SrcAddr,
|
|
|
|
(VOID *) &(Snp->Mode.CurrentAddress),
|
|
|
|
Snp->Mode.HwAddressSize
|
2008-02-20 03:41:47 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyMem (
|
2008-11-13 04:42:21 +01:00
|
|
|
(VOID *) Cpb->DestAddr,
|
|
|
|
(VOID *) DestAddr,
|
|
|
|
Snp->Mode.HwAddressSize
|
2008-02-20 03:41:47 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
//
|
|
|
|
// we need to do the byte swapping
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
Cpb->Protocol = (UINT16) PXE_SWAP_UINT16 (*ProtocolPtr);
|
2008-02-20 03:41:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Cpb->PacketLen = (UINT32) (BufferSize);
|
|
|
|
Cpb->MediaHeaderLen = (UINT16) HeaderSize;
|
2008-02-20 03:41:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Cpb->FragCnt = 2;
|
|
|
|
Cpb->reserved = 0;
|
2008-02-20 03:41:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Cpb->FragDesc[0].FragAddr = (UINT64)(UINTN) MacHeaderPtr;
|
|
|
|
Cpb->FragDesc[0].FragLen = (UINT32) HeaderSize;
|
|
|
|
Cpb->FragDesc[1].FragAddr = (UINT64)(UINTN) Buffer;
|
|
|
|
Cpb->FragDesc[1].FragLen = (UINT32) BufferSize;
|
2008-02-20 03:41:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Cpb->FragDesc[0].reserved = Cpb->FragDesc[1].reserved = 0;
|
2008-02-20 03:41:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.OpCode = PXE_OPCODE_FILL_HEADER;
|
|
|
|
Snp->Cdb.OpFlags = PXE_OPFLAGS_FILL_HEADER_FRAGMENTED;
|
2008-02-20 03:41:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.DBsize = PXE_DBSIZE_NOT_USED;
|
|
|
|
Snp->Cdb.DBaddr = PXE_DBADDR_NOT_USED;
|
2008-02-20 03:41:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.CPBsize = sizeof (PXE_CPB_FILL_HEADER_FRAGMENTED);
|
|
|
|
Snp->Cdb.CPBaddr = (UINT64)(UINTN) Cpb;
|
2008-02-20 03:41: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:41:47 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Issue UNDI command and check result.
|
|
|
|
//
|
2009-02-09 02:22:19 +01:00
|
|
|
DEBUG ((EFI_D_NET, "\nSnp->undi.fill_header() "));
|
2008-02-20 03:41:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
(*Snp->IssueUndi32Command) ((UINT64) (UINTN) &Snp->Cdb);
|
2008-02-20 03:41:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
switch (Snp->Cdb.StatCode) {
|
2008-02-20 03:41:47 +01:00
|
|
|
case PXE_STATCODE_SUCCESS:
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
|
|
|
|
case PXE_STATCODE_INVALID_PARAMETER:
|
|
|
|
DEBUG (
|
|
|
|
(EFI_D_ERROR,
|
2008-11-13 04:42:21 +01:00
|
|
|
"\nSnp->undi.fill_header() %xh:%xh\n",
|
|
|
|
Snp->Cdb.StatFlags,
|
|
|
|
Snp->Cdb.StatCode)
|
2008-02-20 03:41:47 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DEBUG (
|
|
|
|
(EFI_D_ERROR,
|
2008-11-13 04:42:21 +01:00
|
|
|
"\nSnp->undi.fill_header() %xh:%xh\n",
|
|
|
|
Snp->Cdb.StatFlags,
|
|
|
|
Snp->Cdb.StatCode)
|
2008-02-20 03:41:47 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
This routine calls undi to transmit the given data buffer
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
@param Snp pointer to SNP driver structure
|
|
|
|
@param Buffer data buffer pointer
|
|
|
|
@param BufferSize Size of data in the Buffer
|
2008-02-20 03:41:47 +01:00
|
|
|
|
|
|
|
@retval EFI_SUCCESS if successfully completed the undi call
|
|
|
|
@retval Other error return from undi call.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
2008-11-13 04:42:21 +01:00
|
|
|
PxeTransmit (
|
|
|
|
SNP_DRIVER *Snp,
|
|
|
|
VOID *Buffer,
|
|
|
|
UINTN BufferSize
|
2008-02-20 03:41:47 +01:00
|
|
|
)
|
|
|
|
{
|
2008-11-13 04:42:21 +01:00
|
|
|
PXE_CPB_TRANSMIT *Cpb;
|
2008-02-20 03:41:47 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Cpb = Snp->Cpb;
|
|
|
|
Cpb->FrameAddr = (UINT64) (UINTN) Buffer;
|
|
|
|
Cpb->DataLen = (UINT32) BufferSize;
|
2008-02-20 03:41:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Cpb->MediaheaderLen = 0;
|
|
|
|
Cpb->reserved = 0;
|
2008-02-20 03:41:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.OpFlags = PXE_OPFLAGS_TRANSMIT_WHOLE;
|
2008-02-20 03:41:47 +01:00
|
|
|
|
2010-09-15 09:48:11 +02:00
|
|
|
Snp->Cdb.CPBsize = (UINT16) sizeof (PXE_CPB_TRANSMIT);
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.CPBaddr = (UINT64)(UINTN) Cpb;
|
2008-02-20 03:41:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Snp->Cdb.OpCode = PXE_OPCODE_TRANSMIT;
|
|
|
|
Snp->Cdb.DBsize = PXE_DBSIZE_NOT_USED;
|
|
|
|
Snp->Cdb.DBaddr = PXE_DBADDR_NOT_USED;
|
2008-02-20 03:41: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:41:47 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Issue UNDI command and check result.
|
|
|
|
//
|
2009-02-09 02:22:19 +01:00
|
|
|
DEBUG ((EFI_D_NET, "\nSnp->undi.transmit() "));
|
|
|
|
DEBUG ((EFI_D_NET, "\nSnp->Cdb.OpCode == %x", Snp->Cdb.OpCode));
|
|
|
|
DEBUG ((EFI_D_NET, "\nSnp->Cdb.CPBaddr == %LX", Snp->Cdb.CPBaddr));
|
|
|
|
DEBUG ((EFI_D_NET, "\nSnp->Cdb.DBaddr == %LX", Snp->Cdb.DBaddr));
|
|
|
|
DEBUG ((EFI_D_NET, "\nCpb->FrameAddr == %LX\n", Cpb->FrameAddr));
|
2008-02-20 03:41:47 +01:00
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
(*Snp->IssueUndi32Command) ((UINT64) (UINTN) &Snp->Cdb);
|
2008-02-20 03:41:47 +01:00
|
|
|
|
2009-02-09 02:22:19 +01:00
|
|
|
DEBUG ((EFI_D_NET, "\nexit Snp->undi.transmit() "));
|
|
|
|
DEBUG ((EFI_D_NET, "\nSnp->Cdb.StatCode == %r", Snp->Cdb.StatCode));
|
2008-02-20 03:41:47 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// we will unmap the buffers in get_status call, not here
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
switch (Snp->Cdb.StatCode) {
|
2008-02-20 03:41:47 +01:00
|
|
|
case PXE_STATCODE_SUCCESS:
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
|
|
|
|
case PXE_STATCODE_QUEUE_FULL:
|
|
|
|
case PXE_STATCODE_BUSY:
|
|
|
|
Status = EFI_NOT_READY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Status = EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG (
|
|
|
|
(EFI_D_ERROR,
|
2008-11-13 04:42:21 +01:00
|
|
|
"\nSnp->undi.transmit() %xh:%xh\n",
|
|
|
|
Snp->Cdb.StatFlags,
|
|
|
|
Snp->Cdb.StatCode)
|
2008-02-20 03:41:47 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-11-13 04:42:21 +01:00
|
|
|
Places a packet in the transmit queue of a network interface.
|
|
|
|
|
|
|
|
This function places the packet specified by Header and Buffer on the transmit
|
|
|
|
queue. If HeaderSize is nonzero and HeaderSize is not equal to
|
|
|
|
This->Mode->MediaHeaderSize, then EFI_INVALID_PARAMETER will be returned. If
|
|
|
|
BufferSize is less than This->Mode->MediaHeaderSize, then EFI_BUFFER_TOO_SMALL
|
|
|
|
will be returned. If Buffer is NULL, then EFI_INVALID_PARAMETER will be
|
|
|
|
returned. If HeaderSize is nonzero and DestAddr or Protocol is NULL, then
|
|
|
|
EFI_INVALID_PARAMETER will be returned. If the transmit engine of the network
|
|
|
|
interface is busy, then EFI_NOT_READY will be returned. If this packet can be
|
|
|
|
accepted by the transmit engine of the network interface, the packet contents
|
|
|
|
specified by Buffer will be placed on the transmit queue of the network
|
|
|
|
interface, and EFI_SUCCESS will be returned. GetStatus() can be used to
|
|
|
|
determine when the packet has actually been transmitted. The contents of the
|
|
|
|
Buffer must not be modified until the packet has actually been transmitted.
|
|
|
|
The Transmit() function performs nonblocking I/O. A caller who wants to perform
|
|
|
|
blocking I/O, should call Transmit(), and then GetStatus() until the
|
|
|
|
transmitted buffer shows up in the recycled transmit buffer.
|
|
|
|
If the driver has not been initialized, EFI_DEVICE_ERROR will be returned.
|
|
|
|
|
|
|
|
@param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
|
|
|
|
@param HeaderSize The size, in bytes, of the media header to be filled in by the
|
|
|
|
Transmit() function. If HeaderSize is nonzero, then it must
|
|
|
|
be equal to This->Mode->MediaHeaderSize and the DestAddr and
|
|
|
|
Protocol parameters must not be NULL.
|
|
|
|
@param BufferSize The size, in bytes, of the entire packet (media header and
|
|
|
|
data) to be transmitted through the network interface.
|
|
|
|
@param Buffer A pointer to the packet (media header followed by data) to be
|
|
|
|
transmitted. This parameter cannot be NULL. If HeaderSize is
|
|
|
|
zero, then the media header in Buffer must already be filled
|
|
|
|
in by the caller. If HeaderSize is nonzero, then the media
|
|
|
|
header will be filled in by the Transmit() function.
|
|
|
|
@param SrcAddr The source HW MAC address. If HeaderSize is zero, then this
|
|
|
|
parameter is ignored. If HeaderSize is nonzero and SrcAddr
|
|
|
|
is NULL, then This->Mode->CurrentAddress is used for the
|
|
|
|
source HW MAC address.
|
|
|
|
@param DestAddr The destination HW MAC address. If HeaderSize is zero, then
|
|
|
|
this parameter is ignored.
|
|
|
|
@param Protocol The type of header to build. If HeaderSize is zero, then this
|
|
|
|
parameter is ignored. See RFC 1700, section "Ether Types,"
|
|
|
|
for examples.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The packet was placed on the transmit queue.
|
|
|
|
@retval EFI_NOT_STARTED The network interface has not been started.
|
|
|
|
@retval EFI_NOT_READY The network interface is too busy to accept this
|
|
|
|
transmit request.
|
|
|
|
@retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
|
|
|
|
@retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported
|
|
|
|
value.
|
|
|
|
@retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
|
|
|
|
@retval EFI_UNSUPPORTED This function is not supported by the network interface.
|
2008-02-20 03:41:47 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
2008-11-13 04:42:21 +01:00
|
|
|
SnpUndi32Transmit (
|
|
|
|
IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
|
|
|
|
IN UINTN HeaderSize,
|
|
|
|
IN UINTN BufferSize,
|
|
|
|
IN VOID *Buffer,
|
|
|
|
IN EFI_MAC_ADDRESS *SrcAddr, OPTIONAL
|
|
|
|
IN EFI_MAC_ADDRESS *DestAddr, OPTIONAL
|
|
|
|
IN UINT16 *Protocol OPTIONAL
|
2008-02-20 03:41:47 +01:00
|
|
|
)
|
|
|
|
{
|
2008-11-13 04:42:21 +01:00
|
|
|
SNP_DRIVER *Snp;
|
2008-02-20 03:41:47 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_TPL OldTpl;
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (This == NULL) {
|
2008-02-20 03:41: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:41:47 +01:00
|
|
|
|
|
|
|
OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (Snp == NULL) {
|
2008-02-20 03:41:47 +01:00
|
|
|
return EFI_DEVICE_ERROR;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
switch (Snp->Mode.State) {
|
2008-02-20 03:41: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 (Buffer == NULL) {
|
2008-02-20 03:41:47 +01:00
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
if (BufferSize < Snp->Mode.MediaHeaderSize) {
|
2008-02-20 03:41:47 +01:00
|
|
|
Status = EFI_BUFFER_TOO_SMALL;
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
// if the HeaderSize is non-zero, we need to fill up the header and for that
|
2008-02-20 03:41:47 +01:00
|
|
|
// we need the destination address and the protocol
|
|
|
|
//
|
2008-11-13 04:42:21 +01:00
|
|
|
if (HeaderSize != 0) {
|
|
|
|
if (HeaderSize != Snp->Mode.MediaHeaderSize || DestAddr == 0 || Protocol == 0) {
|
2008-02-20 03:41:47 +01:00
|
|
|
Status = EFI_INVALID_PARAMETER;
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Status = PxeFillHeader (
|
|
|
|
Snp,
|
|
|
|
Buffer,
|
|
|
|
HeaderSize,
|
|
|
|
(UINT8 *) Buffer + HeaderSize,
|
|
|
|
BufferSize - HeaderSize,
|
|
|
|
DestAddr,
|
|
|
|
SrcAddr,
|
|
|
|
Protocol
|
2008-02-20 03:41:47 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto ON_EXIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-13 04:42:21 +01:00
|
|
|
Status = PxeTransmit (Snp, Buffer, BufferSize);
|
2008-02-20 03:41:47 +01:00
|
|
|
|
|
|
|
ON_EXIT:
|
|
|
|
gBS->RestoreTPL (OldTpl);
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|