⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 etherout.c

📁 代码在ti的c67系列单片机上实现了完整的TCPIP协议栈
💻 C
字号:
//--------------------------------------------------------------------------
// Ip Stack
//--------------------------------------------------------------------------
// ETHEROUT.C
//
// Transmit routine which interacts with the low-level packet support layer.
//
// Author: Michael A. Denio
// Copyright 1999 by Texas Instruments Inc.
//-------------------------------------------------------------------------
#include <stkmain.h>

//--------------------------------------------------------------------
// EtherTxPacket()
//
// This routine takes transmits a packet contained in a packet object
// to the low-level packet layer, after constructing a valid LLC
// layer.
//
// This code is also charged with freeing any memory associtated with
// the packet.
//--------------------------------------------------------------------
void EtherTxPacket( HANDLE hIF, HANDLE hPkt )
{
    ETHDRV  *pe = (ETHDRV *)hIF;
    HANDLE  hFrag,hLLA;
    uint    Offset,BufSize,ValidSize,Flags,w;
    UINT8   *pb;
    UINT8   *pbTmp;

    if( pe->Type != HTYPE_ETH )
    {
        DbgPrintf(DBG_ERROR,"EtherTxPacket: Bad HTYPE (%d)\n",pe->Type);
        PktFree( hPkt );
        return;
    }

    if( !hPkt || !(hFrag = PktGetFrag( hPkt ))  )
    {
        DbgPrintf(DBG_ERROR,"EtherTxPacket: Bad packet\n");
        PktFree( hPkt );
        return;
    }

    // Get the buffer parameters
    pb = FragGetBufParams( hFrag, &BufSize, &ValidSize, &Offset );

    // Get the packet info
    Flags = PktGetFlags( hPkt );

    // Build the LLC if we need to
    if( !(Flags & FLG_PKT_LLC_VALID) )
    {
        // We need room to add the LLC
        if( Offset < pe->EthHdrSize )
        {
            DbgPrintf(DBG_ERROR,"EtherTxPacket: No Header Space");
            PktFree( hPkt );
            return;
        }

        // Add the LLC
        // The end of the header should be flush against the
        // start of the current offset.
        Offset     -= pe->EthHdrSize;
        ValidSize  += pe->EthHdrSize;
        pbTmp       = pb + Offset;

        // Copy SRC MAC into the LLC
        LLAGetData( pe->hLLADirect, 6, pbTmp+pe->OffSrcMac );

        // Get a valid destination LLA
        if( !(hLLA = PktGetLLADst( hPkt )) )
        {
            DbgPrintf(DBG_ERROR,"EtherTxPacket: No Destination");
            PktFree( hPkt );
            return;
        }

        // Copy DST MAC into the LLC
        LLAGetData( hLLA, 6, pbTmp+pe->OffDstMac );

        // Copy EtherType MAC into the LLC
        w = PktGetEthType( hPkt );
        *(pbTmp+pe->OffEtherType)   = w / 256;
        *(pbTmp+pe->OffEtherType+1) = w & 0xFF;

        // Update the frag
        FragSetBufParams( hFrag, ValidSize, Offset );
    }

    // Free the packet
    PktSetFrag( hPkt, 0 );
    PktFree( hPkt );

    //
    // We are now ready to send the packet.
    // ValidSize = Size of frag
    // Offset    = Offset to data in frag
    // pb        = Pointer to buffer
    //

    // Send the buffer
    llPacketSend( pe->llIndex, pb, Offset, ValidSize, hFrag );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -