?? zl5011xpackettx.c
字號:
/******************************************************************************
*
* File name: zl5011xPacketTx.c
*
* Version: 57
*
* Author: JFE
*
* Date created: 19/06/2002
*
* Copyright 2002, 2003, 2004, 2005, Zarlink Semiconductor Limited.
* All rights reserved.
*
* Module Description:
*
* This file contains packet construction routines.
*
* Revision History:
*
* Rev: Date: Author: Comments:
* 1 19/06/2002 JFE Initial revision
* 2 27/06/2002 JFE Added handling for more protocol stacks
* 3 08/07/2002 JFE Added handling for VLAN
* Modified init function to initialise new
* structure member
* 4 09/07/2002 JFE Added support for more protocol stacks
* 5 09/07/2002 JFE Added support for more protocol stacks
* Changed structure member (contextID to context)
* Added range checking for unchecked members
* 6 10/07/2002 MRC Added some new checksum functions
* 7 15/07/2002 JFE Added new functions to handle receipt of packets
* programming the PKC.
* Code review actions.
* 8 06/08/2002 MRC temporarily removed packet Rx functions. Removed
* references to emu880.
* 9 07/08/2002 MRC Updated, adding in checksums calculations etc.
* 10 07/08/2002 MRC Fixed copy header fn
* 11 14/08/2002 MRC Updated
* 12 16/08/2002 MRC Updated checksum functions
* 13 16/08/2002 MRC Added control to allow the Tx RTP timestamp to be
* derived from the WAN interface.
* 14 28/08/2002 MRC Added in support for CD header
* 15 28/08/2002 MRC Fixed a problem in checking the position of the
* CD header
* 16 02/09/2002 MRC Added some checks for the flow type etc.
* 17 03/09/2002 MRC Added ethernet SNAP length field control
* 18 04/09/2002 MRC Adding CD header, broke other protocols
* 19 04/09/2002 MRC checksum modifier wasn't initialised
* 20 05/09/2002 MRC UDP checksum not being recalculated
* 21 05/09/2002 MRC update snap length calculation
* 22 05/09/2002 MRC the context switch bit is now determined by
* examining the current header
* 23 06/09/2002 MRC update snap length calculation
* 24 10/09/2002 MRC CD header now uses context number if an outgoing
* context number is not provided
* 25 10/09/2002 MRC L2TPv3 does not have a length field
* 26 13/09/2002 MRC Changed include file
* 27 31/10/2002 MRC Added variants + minor fixes
* 28 29/01/2003 MRC Added rev A #define
* 29 31/01/2003 MRC Renamed the rev A #define
* 30 21/02/2003 MRC Moved packet checksum functions to apiHigh
* 31 27/02/2003 MRC Added in support for cookie in L2TPv3
* 32 06/03/2003 MRC Added OS exclusion
* 33 25/03/2003 MRC IPv4 and UDP checksums are now computed from
* scratch and do not rely on the checksum being
* valid on calling the function
* 34 19/05/2003 APL L2TPv3 changes
* 35 21/05/2003 MRC L2TPv3 changes + option to fix IPv4 checksum
* 36 05/06/2003 JFE Changed calls to calloc and free for macros
* 37 25/06/2003 MRC CD header changed to be different when over UDP
* 38 25/06/2003 MRC The CD header now immediately follows UDP
* 39 15/07/2003 JFE IP_UDP_CD now works.
* 40 29/07/2003 APL Added support for devices with no TDM interface
* Can now modify packet TX parameters without
* adding a header
* 41 04/08/2003 APL Removed unused variable for some device variants
* 42 28/10/2003 AMS Update
* 43 29/10/2003 AMS Update
* 44 30/10/2003 AMS Update
* 45 07/11/2003 AMS Update
* 46 18/11/2003 AMS Update
* 47 03/12/2003 APL Update
* 48 06/01/2004 MRC Reverted to revision 41
* 49 07/06/2004 MRC Updated MPLS protocol headers
* 50 29/07/2004 MRC Fixed some compiler warnings
* 51 25/08/2004 MRC Protocol updates
* 52 27/09/2004 APL Check correct flow is set for required protocol
* Tx Header for Lan-to-Lan contexts can only be
* changed in INIT state.
* 53 07/10/2004 APL Lan-to-lan contexts can have a null header added.
* 54 26/11/2004 MRC Added extra packet protocols
* 55 01/03/2005 APL Added ZL5011X_ETHERNET protocol. Improved checking
* of invalid flows
* 56 17/05/2005 MRC Added custom 8 byte protocol header support
* 57 21/07/2005 MRC Added IP->UDP->RTP and IP->UDP->RTP->PW->ALT protcols
*
******************************************************************************/
/***************** INCLUDE FILES ****************************/
#include "zl5011xApi.h"
#include "zl5011xMisc.h"
#include "zl5011xLan.h"
#include "zl5011xPacket.h"
/***************** EXTERNAL FUNCTION DEFINITIONS *************************/
/******************************************************************************
Function:
zl5011xPacketTxSetHeaderStructInit
Description:
Initialises structure used by zl5011xPacketTxSetHeader function.
Inputs:
zl5011xParams Pointer to the structure for this device instance
par Pointer to the structure for configuration items.
See main function
Returns:
zlStatusE
Remarks:
None
******************************************************************************/
zlStatusE zl5011xPacketTxSetHeaderStructInit(zl5011xParamsS *zl5011xParams,
zl5011xPacketTxSetHeaderS * par)
{
zlStatusE status = ZL5011X_OK;
/* do some parameter checking */
status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_PACKET_FN_ID,
"zl5011xPacketTxSetHeaderStructInit:",
0, 0, 0, 0, 0, 0);
par->context = (Uint32T)ZL5011X_INVALID_CONTEXT;
par->protocolType = ZL5011X_INVALID_PROTOCOL;
par->header = NULL;
par->headerLength = 0;
par->portNum = 0;
par->queueNum = 0;
par->enableVlan = ZL5011X_FALSE;
par->enableSnap = ZL5011X_FALSE;
par->ipVer4 = ZL5011X_TRUE;
par->enableUDPChecksum = ZL5011X_TRUE;
par->rtpForceSeqNumber = ZL5011X_TRUE;
par->rtpTimestampInc = 0;
par->rtpTimestampFromWan = ZL5011X_FALSE;
par->enableL2TPCookie = ZL5011X_FALSE;
par->contextDescriptorOffset = (Uint32T)ZL5011X_INVALID;
par->contextDescriptorTeardown = ZL5011X_FALSE;
par->contextDescriptorNumber = (Uint8T)ZL5011X_INVALID;
par->fixIpv4Header = ZL5011X_TRUE;
par->payloadLength = 0;
/* MAC Writes Ethernet Src Add */
par->ethernetSrcAddressFromMac = ZL5011X_TRUE;
par->osExclusionEnable = ZL5011X_TRUE;
}
return(status);
}
/******************************************************************************
Function:
zl5011xPacketTxSetHeader
Description:
This function calls the relevant API functions to setup PTX and PE headers
as required by the indicated protocol type.
Inputs:
zl5011xParams Pointer to the structure for this device instance
par Pointer to the structure for configuration items. See below:
Structure inputs:
context context to setup header for
portNum Lan port to send these packets on
queueNum Lan queue to use for these packets
protocolType identifies protocol being set up
header pointer to a buffer containing header data. If NULL then no header
will be added
headerLength length of the header. If 0 then no header will be added
enableVlan ZL5011X_TRUE if this packet uses VLAN
enableSnap ZL5011X_TRUE if this packet uses SNAP
ethernetSrcAddressFromMac ZL5011X_TRUE for the ethernet source address to
be inserted by the LAN port
ipVer4 ZL5011X_TRUE if the IP protocol is IPv4 (IPv6 = ZL5011X_FALSE)
fixIpv4Header ZL5011X_TRUE to use a fixed IPv4 header - payload length
must also be specified
payloadLength length of payload to use if the IPv4 header is fixed
enableUDPChecksum ZL5011X_TRUE to enable UDP checksum insertion
(ZL5011X_FALSE fills the field with 0)
enableL2TPCookie ZL5011X_TRUE if the L2TPv3 header contains a cookie
rtpForceSeqNumber set to ZL5011X_TRUE to force usage of the RTP sequence number
if the RTP and PW headers are both present.
(Note : in order to update the PW status byte, this must
be set to ZL5011X_TRUE when RTP is used)
rtpTimestampInc how much should the RTP timestamp increment by for
each packet
rtpTimestampFromWan ZL5011X_TRUE for the RTP timestamp to be sourced from the
WAN interface. ONLY for in-band differential clock recovery
contextDescriptorOffset byte offset within the header for the CD header
(for MT90880 interoperation)
contextDescriptorNumber context number to use for CD header
(for MT90880 interoperation)
contextDescriptorTeardown ZL5011X_TRUE to form a teardown CD header
(for MT90880 interoperation)
osExclusionEnable ZL5011X_TRUE to enable OS exclusion
Structure outputs:
None
Returns:
zlStatusE
Remarks:
It is the not the responsibility of this function to ensure that the fields
in the header provided by the calling function are valid. Checks must be
done at a higher level to ensure conformance to whatever protocol is
required. This lack of checking in this function is desirable so that it
won't require modification if a new, unknown protocol is used in the future.
******************************************************************************/
extern zlStatusE zl5011xPacketTxSetHeader(zl5011xParamsS * zl5011xParams,
zl5011xPacketTxSetHeaderS * par)
{
zlStatusE status = ZL5011X_OK;
zl5011xLanTxSetLayer2and3HeaderS *layer2and3Header = NULL;
zl5011xLanTxSetLayer4and5HeaderS *layer4and5Header = NULL;
zl5011xBooleanE udpEnable = ZL5011X_FALSE;
zl5011xBooleanE cdEnable = ZL5011X_FALSE;
Uint16T checksumMod = 0;
Uint8T cdPos, pwStatusPos = (Uint8T)ZL5011X_INVALID;
Uint8T pwShuffle = 0;
Uint16T temp;
/* do some parameter checking */
status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);
if (status == ZL5011X_OK)
{
if (par->rtpTimestampFromWan == ZL5011X_TRUE)
{
/* force the UDP checksum off if doing clock recovery using a PRS timestamp */
par->enableUDPChecksum = ZL5011X_FALSE;
}
}
if (status == ZL5011X_OK)
{
status = ZL5011X_CHECK_RUNNING(zl5011xParams);
}
if (status == ZL5011X_OK)
{
status = zl5011xLanPortCheck(zl5011xParams, par->portNum);
}
/* Check that the Wan Rx context is valid. */
if (status == ZL5011X_OK)
{
/* The packet transmit headers for Lan-to-Lan contexts can only be changed in
the INIT state */
if (zl5011xParams->packetIf.lanLanContext[par->context] == ZL5011X_TRUE)
{
status = zl5011xContextCheckRx(zl5011xParams, par->context, ZL5011X_CHECK_CONTEXT_INIT);
}
else
{ /* For Wan Rx contexts the layer 4/5 header can be changed whilst in in any state.
This is because it is implemented using a dual header approach where the new header
can be set up and then switched in one go. The layer 2/3 header does not support
this and so cannot be changed except in the INIT state. This is checked further
down this function. */
status = zl5011xContextCheckRx(zl5011xParams, par->context, ZL5011X_CHECK_CONTEXT_IN_USE);
}
}
/* main function code starts */
if (status == ZL5011X_OK)
{
ZL5011X_TRACE(ZL5011X_PACKET_FN_ID,
"zl5011xPacketTxSetHeader:",
0, 0, 0, 0, 0, 0);
}
/* Perform range checking on structure members passed in */
if (status == ZL5011X_OK)
{
if (par->queueNum >= ZL5011X_PKQ_NUM_QUEUES)
{
status = ZL5011X_PARAMETER_INVALID;
}
}
if (status == ZL5011X_OK)
{
if (par->headerLength > ZL5011X_PACKET_HEADER_MAX)
{
status = ZL5011X_PKT_HEADER_SIZE_ERROR;
}
}
if (status == ZL5011X_OK)
{
/* Allocate memory for the two structures required by the lower level API */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -