?? zl5011xpackettx.c
字號(hào):
/* With the fully populated structures, call the API functions to setup the
headers. First layers 2and3 and then layers 4and5. */
if (status == ZL5011X_OK)
{
/* The layer 2/3 header can only be changed when the device is in the INIT state.
i.e. its a one-off setting because if you tried to change it dynamically you
would almost certainly cause packet corruption while the change was in progress. */
if (zl5011xParams->wanIf.plaCurrent.context[par->context].state == ZL5011X_STATE_INIT)
{
/* store the protocol type for future reference */
zl5011xParams->packetIf.packetTx.txHeader[par->context].protocolType = par->protocolType;
zl5011xParams->packetIf.packetTx.txHeader[par->context].pwStatusPos = pwStatusPos;
ZL5011X_TRACE(ZL5011X_PACKET_FN_ID,
"zl5011xPacketTxSetHeader: Ptx header length %d, length pos %d, chk %d, len val %d",
layer2and3Header->header.txLowLength,
layer2and3Header->header.layer3LengthPos,
layer2and3Header->header.layer3ChecksumPos,
layer2and3Header->header.layer3LengthValue, 0, 0);
status = zl5011xLanTxSetLayer2and3Header(zl5011xParams, layer2and3Header);
}
}
if (status == ZL5011X_OK)
{
/* The layer 4/5 header can be changed dynamically because any changes will go
into the "shadow" header until a context switch occurs */
if (layer4and5Header->header.txHighLength != 0)
{
ZL5011X_TRACE(ZL5011X_PACKET_FN_ID,
"zl5011xPacketTxSetHeader: Rtp header length %d, length pos %d, chk %d, seq %d, time %d",
layer4and5Header->header.txHighLength,
layer4and5Header->header.layer4LengthPos,
layer4and5Header->header.layer4ChecksumPos,
layer4and5Header->header.layer5SequenceNumPos,
layer4and5Header->header.layer5TimestampPos, 0);
status = zl5011xLanTxSetLayer4and5Header(zl5011xParams, layer4and5Header);
}
}
/* free up the memory allocated for the headers */
if (layer2and3Header != NULL)
{
OS_FREE(layer2and3Header);
}
if (layer4and5Header != NULL)
{
OS_FREE(layer4and5Header);
}
return(status);
}
/******************************************************************************
Function:
zl5011xAddEthernetHeader
Description:
Modify the structure information passed in to setup header for the common
Ethernet (layer2) protocols. Take into account the impact of SNAP and VLAN
Inputs:
layer2and3Header Pointer to zl5011xLanTxSetLayer2and3HeaderS structure to
be modified to with Ethernet information.
par Pointer to the zl5011xPacketTxSetHeaderS structure.
Outputs:
None
Returns:
zlStatusE
Remarks:
All protocol stacks use Ethernet.
******************************************************************************/
zlStatusE zl5011xAddEthernetHeader(zl5011xLanTxSetLayer2and3HeaderS *layer2and3Header,
zl5011xPacketTxSetHeaderS * par)
{
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_PACKET_FN_ID,
"zl5011xAddEthernetHeader:",
0, 0, 0, 0, 0, 0);
/* Determine the format of the lowest layer header - Ethernet. This is
dependent upon the presence of Subnetwork Access Protocol (SNAP). */
if (par->enableSnap == ZL5011X_TRUE)
{
layer2and3Header->header.txLowLength = ZL5011X_PKT_ETHERSNAP_HDR_LEN;
layer2and3Header->header.layer2LengthEnable = ZL5011X_TRUE;
layer2and3Header->header.layer2LengthPos = ZL5011X_PKT_ETHERSNAP_LEN_POS;
}
else
{
layer2and3Header->header.txLowLength = ZL5011X_PKT_ETHERNET_HDR_LEN;
}
/* If VLAN is turned on then the Ethernet header will be larger. */
if (par->enableVlan == ZL5011X_TRUE)
{
layer2and3Header->header.txLowLength += ZL5011X_PKT_VLAN_HDR_LEN;
}
return(status);
}
/******************************************************************************
Function:
zl5011xAddIPHeader
Description:
Modify the structure information passed in to setup header for the IP
(layer3) protocols. Take into account the impact of different IP versions.
Inputs:
layer2and3Header Pointer to zl5011xLanTxSetLayer2and3HeaderS structure to
be modified with IP information.
par Pointer to the zl5011xPacketTxSetHeaderS structure.
Outputs:
None
Returns:
zlStatusE
Remarks:
The length value set up by this function is just the length of the IP
header itself. This means that the IP header is the last header contained
in the PTX. That is, the payload length is updated by the RTP block when
the higher headers are added.
******************************************************************************/
zlStatusE zl5011xAddIPHeader(zl5011xLanTxSetLayer2and3HeaderS *
layer2and3Header, zl5011xPacketTxSetHeaderS * par)
{
zlStatusE status = ZL5011X_OK;
Uint32T ipHeaderStart;
ZL5011X_TRACE(ZL5011X_PACKET_FN_ID,
"zl5011xAddIPHeader:",
0, 0, 0, 0, 0, 0);
ipHeaderStart = layer2and3Header->header.txLowLength;
/* The layer 3 portion of the header will depend on which version of IP we
are dealing with. */
if (par->ipVer4 == ZL5011X_TRUE)
{
/* setup IPv4 length */
layer2and3Header->header.txLowLength += ZL5011X_PKT_IPV4_HDR_LEN;
layer2and3Header->header.layer3LengthEnable = ZL5011X_TRUE;
layer2and3Header->header.layer3LengthValue = ZL5011X_PKT_IPV4_HDR_LEN;
layer2and3Header->header.layer3LengthPos = (Uint8T)(ipHeaderStart + ZL5011X_PKT_IPV4_LEN_POS);
/* setup IPv4 checksum */
layer2and3Header->header.layer3ChecksumEnable = ZL5011X_TRUE;
layer2and3Header->header.layer3ChecksumPos = (Uint8T)(ipHeaderStart + ZL5011X_PKT_IPV4_CHKSUM_POS);
}
else
{
/* setup IPv6 length */
layer2and3Header->header.txLowLength += ZL5011X_PKT_IPV6_HDR_LEN;
layer2and3Header->header.layer3LengthEnable = ZL5011X_TRUE;
layer2and3Header->header.layer3LengthValue = 0;
layer2and3Header->header.layer3LengthPos = (Uint8T)(ipHeaderStart + ZL5011X_PKT_IPV6_LEN_POS);
}
return(status);
}
/******************************************************************************
Function:
zl5011xAddMPLSHeader
Description:
Modify the structure information passed in to setup header for the
MPLS (layer3) protocols.
Inputs:
layer2and3Header Pointer to zl5011xLanTxSetLayer2and3HeaderS structure to
be modified to with MPLS information.
par Pointer to the zl5011xPacketTxSetHeaderS structure.
Outputs:
None
Returns:
zlStatusE
Remarks:
******************************************************************************/
zlStatusE zl5011xAddMPLSHeader(zl5011xLanTxSetLayer2and3HeaderS *layer2and3Header,
zl5011xPacketTxSetHeaderS * par)
{
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_PACKET_FN_ID,
"zl5011xAddMPLSHeader:",
0, 0, 0, 0, 0, 0);
layer2and3Header->header.txLowLength += ZL5011X_PKT_MPLS_HDR_LEN;
return(status);
}
/******************************************************************************
Function:
zl5011xAddUDPHeader
Description:
Modify the structure information passed in to setup header for UDP (layer4)
Inputs:
layer4and5Header Pointer to zl5011xLanTxSetLayer4and5HeaderS structure to
be modified to with UDP information.
par Pointer to the zl5011xPacketTxSetHeaderS structure.
Outputs:
None
Returns:
zlStatusE
Remarks:
None
******************************************************************************/
zlStatusE zl5011xAddUDPHeader(zl5011xLanTxSetLayer4and5HeaderS *layer4and5Header,
zl5011xPacketTxSetHeaderS * par)
{
zlStatusE status = ZL5011X_OK;
ZL5011X_TRACE(ZL5011X_PACKET_FN_ID,
"zl5011xAddUDPHeader:",
0, 0, 0, 0, 0, 0);
/* setup the layer 4 fields : UDP length and checksum */
layer4and5Header->header.layer4LengthEnable = ZL5011X_TRUE;
layer4and5Header->header.layer4LengthPos = ZL5011X_PKT_UDP_LEN_POS;
if (par->enableUDPChecksum == ZL5011X_TRUE)
{
layer4and5Header->header.layer4ChecksumEnable = ZL5011X_TRUE;
}
layer4and5Header->header.layer4ChecksumPresent = ZL5011X_TRUE;
layer4and5Header->header.layer4ChecksumPos = ZL5011X_PKT_UDP_CHKSUM_POS;
/* setup the layer 5 fields : */
layer4and5Header->header.layer5TimestampIncrement = (Uint16T)par->rtpTimestampInc; /* seq no. */
layer4and5Header->header.layer5TimestampFromWan = par->rtpTimestampFromWan; /* timestamp */
switch (par->protocolType)
{
case ZL5011X_IP_UDP_RTP:
layer4and5Header->header.layer5SequenceNumEnable = ZL5011X_TRUE;
layer4and5Header->header.layer5SequenceNum16bit = ZL5011X_TRUE;
layer4and5Header->header.layer5SequenceNumPos = ZL5011X_PKT_UDP_HDR_LEN + ZL5011X_PKT_RTP_SEQ_POS;
layer4and5Header->header.layer5TimestampEnable = ZL5011X_TRUE;
layer4and5Header->header.layer5Timestamp32bit = ZL5011X_TRUE;
layer4and5Header->header.layer5TimestampPos = ZL5011X_PKT_UDP_HDR_LEN + ZL5011X_PKT_RTP_TS_POS;
break;
case ZL5011X_IP_UDP_RTP_PW:
case ZL5011X_IP_UDP_RTP_PW_ALT:
layer4and5Header->header.layer5SequenceNumEnable = ZL5011X_TRUE;
layer4and5Header->header.layer5SequenceNum16bit = ZL5011X_TRUE;
if (par->rtpForceSeqNumber == ZL5011X_TRUE)
{
layer4and5Header->header.layer5SequenceNumPos = ZL5011X_PKT_UDP_HDR_LEN + ZL5011X_PKT_RTP_SEQ_POS;
}
else
{
layer4and5Header->header.layer5SequenceNumPos = ZL5011X_PKT_UDP_HDR_LEN + ZL5011X_PKT_RTP_HDR_LEN + ZL5011X_PKT_PW_SEQ_POS;
}
layer4and5Header->header.layer5TimestampEnable = ZL5011X_TRUE;
layer4and5Header->header.layer5Timestamp32bit = ZL5011X_TRUE;
layer4and5Header->header.layer5TimestampPos = ZL5011X_PKT_UDP_HDR_LEN + ZL5011X_PKT_RTP_TS_POS;
break;
case ZL5011X_IP_UDP_L2TPV2_PW:
layer4and5Header->header.layer5SequenceNumEnable = ZL5011X_TRUE;
layer4and5Header->header.layer5SequenceNum16bit = ZL5011X_TRUE;
layer4and5Header->header.layer5SequenceNumPos = ZL5011X_PKT_UDP_HDR_LEN + ZL5011X_PKT_L2TP_HDR_LEN + ZL5011X_PKT_PW_SEQ_POS;
break;
case ZL5011X_IP_UDP_PW:
layer4and5Header->header.layer5SequenceNumEnable = ZL5011X_TRUE;
layer4and5Header->header.layer5SequenceNum16bit = ZL5011X_TRUE;
layer4and5Header->header.layer5SequenceNumPos = ZL5011X_PKT_UDP_HDR_LEN + ZL5011X_PKT_PW_SEQ_POS;
break;
case ZL5011X_IP_UDP_CD: /* intentional fall through */
case ZL5011X_IP_UDP:
/* no special fields */
break;
default :
status = ZL5011X_PARAMETER_INVALID;
}
return(status);
}
/******************************************************************************
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -