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

📄 zl5011xpackettx.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 5 页
字号:
      layer2and3Header = (zl5011xLanTxSetLayer2and3HeaderS *)OS_CALLOC(
            sizeof(zl5011xLanTxSetLayer2and3HeaderS), 1);
      layer4and5Header = (zl5011xLanTxSetLayer4and5HeaderS *)OS_CALLOC(
            sizeof(zl5011xLanTxSetLayer4and5HeaderS), 1);
   }

   if (status == ZL5011X_OK)
   {
      if ((layer2and3Header == NULL) || (layer4and5Header == NULL))
      {
         status = ZL5011X_RTOS_MEMORY_FAIL;
      }
   }

   /* Call the lower level API structure initialisation functions */
   if (status == ZL5011X_OK)
   {
      status = zl5011xLanTxSetLayer2and3HeaderStructInit(zl5011xParams, layer2and3Header);
      layer2and3Header->osExclusionEnable = par->osExclusionEnable;
   }

   if (status == ZL5011X_OK)
   {
      status = zl5011xLanTxSetLayer4and5HeaderStructInit(zl5011xParams, layer4and5Header);
      layer4and5Header->osExclusionEnable = par->osExclusionEnable;
   }

   /* Copy structure members that are common for all protocol stacks */
   if (status == ZL5011X_OK)
   {
      layer2and3Header->header.ethernetSrcAddressFromMac = par->ethernetSrcAddressFromMac;
      layer2and3Header->context = par->context;
      layer2and3Header->portNum = par->portNum;
      layer2and3Header->queueNum = par->queueNum;
      layer4and5Header->context = par->context;
   }

   if ((par->headerLength == 0) || (par->header == NULL))
   {
      /* A Lan-to-Lan context is allowed to have a null header added
         but for other contexts this is an error */
      if (zl5011xParams->packetIf.lanLanContext[par->context] == ZL5011X_FALSE)
      {
         status = ZL5011X_PARAMETER_INVALID;
      }
   }
   else
   {
      if (status == ZL5011X_OK)
      {
         /* Layer 2: Ethernet header is present for all protocols */
         status = zl5011xAddEthernetHeader(layer2and3Header, par);

         /* Switch on the protocol stack, and populate the header structures as
           appropriate. */
         if (status == ZL5011X_OK)
         {
            switch (par->protocolType)
            {
               case ZL5011X_IP_UDP:
                  /* Layer 3: IP  */
                  if (status == ZL5011X_OK)
                  {
                     status = zl5011xAddIPHeader(layer2and3Header, par);
                  }

                  /* Layer 4: UDP */
                  if (status == ZL5011X_OK)
                  {
                     status = zl5011xAddUDPHeader(layer4and5Header, par);
                     udpEnable = ZL5011X_TRUE;
                  }

                  layer4and5Header->header.txHighLength = ZL5011X_PKT_UDP_HDR_LEN;
                  break;

               case ZL5011X_IP_UDP_PW:
                  /* Layer 3: IP  */
                  if (status == ZL5011X_OK)
                  {
                     status = zl5011xAddIPHeader(layer2and3Header, par);
                  }

                  /* add the UDP + PW header fields */
                  if (status == ZL5011X_OK)
                  {
                     status = zl5011xAddUDPHeader(layer4and5Header, par);
                     udpEnable = ZL5011X_TRUE;
                  }

                  layer4and5Header->header.txHighLength = ZL5011X_PKT_UDP_HDR_LEN + ZL5011X_PKT_PW_HDR_LEN;

                  pwStatusPos = layer4and5Header->header.txHighLength - ZL5011X_PKT_PW_HDR_LEN;
                  break;

               case ZL5011X_IP_PW_TS:
                  /* Layer 3: IP  */
                  if (status == ZL5011X_OK)
                  {
                     status = zl5011xAddIPHeader(layer2and3Header, par);
                  }

                  /* add the PW + TS header fields
                     setup the PW seq no */
                  layer4and5Header->header.layer5SequenceNumEnable = ZL5011X_TRUE;
                  layer4and5Header->header.layer5SequenceNum16bit = ZL5011X_TRUE;
                  layer4and5Header->header.layer5SequenceNumPos = ZL5011X_PKT_PW_SEQ_POS;

                  /* setup the timestamp field for the TS header */
                  layer4and5Header->header.layer5TimestampEnable = ZL5011X_TRUE;
                  layer4and5Header->header.layer5TimestampIncrement = (Uint16T)par->rtpTimestampInc;
                  layer4and5Header->header.layer5TimestampFromWan = par->rtpTimestampFromWan;
                  layer4and5Header->header.layer5Timestamp32bit = ZL5011X_FALSE;
                  layer4and5Header->header.layer5TimestampPos = ZL5011X_PKT_PW_HDR_LEN + 0;

                  layer4and5Header->header.txHighLength = ZL5011X_PKT_PW_HDR_LEN + 2;

                  pwStatusPos = 0;
                  break;

               case ZL5011X_PW:
                  /* setup the PW seq no */
                  layer4and5Header->header.layer5SequenceNumEnable = ZL5011X_TRUE;
                  layer4and5Header->header.layer5SequenceNum16bit = ZL5011X_TRUE;
                  layer4and5Header->header.layer5SequenceNumPos = ZL5011X_PKT_PW_SEQ_POS;

                  layer4and5Header->header.txHighLength = ZL5011X_PKT_PW_HDR_LEN;

                  pwStatusPos = layer4and5Header->header.txHighLength - ZL5011X_PKT_PW_HDR_LEN;
                  break;

               case ZL5011X_IP_UDP_RTP:
                  /* Layer 3: IP  */
                  if (status == ZL5011X_OK)
                  {
                     status = zl5011xAddIPHeader(layer2and3Header, par);
                  }

                  /* add the UDP + RTP + PW header fields */
                  if (status == ZL5011X_OK)
                  {
                     status = zl5011xAddUDPHeader(layer4and5Header, par);
                     udpEnable = ZL5011X_TRUE;
                  }

                  layer4and5Header->header.txHighLength = ZL5011X_PKT_UDP_HDR_LEN + ZL5011X_PKT_RTP_HDR_LEN;
                  break;

               case ZL5011X_IP_UDP_RTP_PW:
               case ZL5011X_IP_UDP_RTP_PW_ALT:
                  /* Layer 3: IP  */
                  if (status == ZL5011X_OK)
                  {
                     status = zl5011xAddIPHeader(layer2and3Header, par);
                  }

                  /* add the UDP + RTP + PW header fields */
                  if (status == ZL5011X_OK)
                  {
                     status = zl5011xAddUDPHeader(layer4and5Header, par);
                     udpEnable = ZL5011X_TRUE;
                  }

                  layer4and5Header->header.txHighLength = ZL5011X_PKT_UDP_HDR_LEN +
                        ZL5011X_PKT_RTP_HDR_LEN + ZL5011X_PKT_PW_HDR_LEN;

                  pwStatusPos = layer4and5Header->header.txHighLength - ZL5011X_PKT_PW_HDR_LEN;
                  break;

               case ZL5011X_IP_UDP_L2TPV2_PW:
                  /* Layer 3: IP  */
                  if (status == ZL5011X_OK)
                  {
                     status = zl5011xAddIPHeader(layer2and3Header, par);
                  }

                  /* add the UDP + L2TP + PW header fields */
                  if (status == ZL5011X_OK)
                  {
                     status = zl5011xAddUDPHeader(layer4and5Header, par);
                     udpEnable = ZL5011X_TRUE;
                  }

                  layer4and5Header->header.txHighLength = ZL5011X_PKT_UDP_HDR_LEN +
                        ZL5011X_PKT_L2TP_HDR_LEN + ZL5011X_PKT_PW_HDR_LEN;

                  pwStatusPos = layer4and5Header->header.txHighLength - ZL5011X_PKT_PW_HDR_LEN;
                  break;

               case ZL5011X_IP_L2TPV3_PW:
                  /* Layer 3: IP  */
                  if (status == ZL5011X_OK)
                  {
                     status = zl5011xAddIPHeader(layer2and3Header, par);
                  }

                  /* setup the PW seq no */
                  layer4and5Header->header.layer5SequenceNumEnable = ZL5011X_TRUE;
                  layer4and5Header->header.layer5SequenceNum16bit = ZL5011X_TRUE;
                  layer4and5Header->header.layer5SequenceNumPos = ZL5011X_PKT_L2TPV3_HDR_LEN + ZL5011X_PKT_PW_SEQ_POS;

                  layer4and5Header->header.txHighLength = ZL5011X_PKT_L2TPV3_HDR_LEN +
                        ZL5011X_PKT_PW_HDR_LEN;

                  if (par->enableL2TPCookie == ZL5011X_TRUE)
                  {
                     layer4and5Header->header.layer5SequenceNumPos += ZL5011X_PKT_L2TPV3_COOKIE_LEN;
                     layer4and5Header->header.txHighLength += ZL5011X_PKT_L2TPV3_COOKIE_LEN;

                  }

                  pwStatusPos = layer4and5Header->header.txHighLength - ZL5011X_PKT_PW_HDR_LEN;
                  break;

               case ZL5011X_IP_L2TPV3_RTP_PW:
                  /* Layer 3: IP  */
                  if (status == ZL5011X_OK)
                  {
                     status = zl5011xAddIPHeader(layer2and3Header, par);
                  }

                  /* setup the seq no field for the RTP header */
                  layer4and5Header->header.layer5SequenceNumEnable = ZL5011X_TRUE;
                  layer4and5Header->header.layer5SequenceNum16bit = ZL5011X_TRUE;

                  if (par->rtpForceSeqNumber == ZL5011X_TRUE)
                  {
                     layer4and5Header->header.layer5SequenceNumPos = ZL5011X_PKT_L2TPV3_HDR_LEN + ZL5011X_PKT_RTP_SEQ_POS;
                  }
                  else
                  {
                     layer4and5Header->header.layer5SequenceNumPos = ZL5011X_PKT_L2TPV3_HDR_LEN + ZL5011X_PKT_RTP_HDR_LEN + ZL5011X_PKT_PW_SEQ_POS;
                  }

                  /* setup the timestamp field for the RTP header */
                  layer4and5Header->header.layer5TimestampEnable = ZL5011X_TRUE;
                  layer4and5Header->header.layer5TimestampIncrement = (Uint16T)par->rtpTimestampInc;
                  layer4and5Header->header.layer5TimestampFromWan = par->rtpTimestampFromWan;
                  layer4and5Header->header.layer5Timestamp32bit = ZL5011X_TRUE;
                  layer4and5Header->header.layer5TimestampPos = ZL5011X_PKT_L2TPV3_HDR_LEN + ZL5011X_PKT_RTP_TS_POS;

                  layer4and5Header->header.txHighLength = ZL5011X_PKT_L2TPV3_HDR_LEN +
                        ZL5011X_PKT_RTP_HDR_LEN + ZL5011X_PKT_PW_HDR_LEN;

                  if (par->enableL2TPCookie == ZL5011X_TRUE)
                  {
                     layer4and5Header->header.layer5SequenceNumPos += ZL5011X_PKT_L2TPV3_COOKIE_LEN;
                     layer4and5Header->header.txHighLength += ZL5011X_PKT_L2TPV3_COOKIE_LEN;
                     layer4and5Header->header.layer5TimestampPos += ZL5011X_PKT_L2TPV3_COOKIE_LEN;
                  }

                  pwStatusPos = layer4and5Header->header.txHighLength - ZL5011X_PKT_PW_HDR_LEN;
                  break;

               case ZL5011X_MPLS:
                  /* Layer 3: MPLS - place in the PE block to allow context switching */
                  layer4and5Header->header.txHighLength = ZL5011X_PKT_MPLS_HDR_LEN;
                  break;

               case ZL5011X_MPLS_PW:
                  /* Layer 3: MPLS - place in the PE block to allow context switching.
                     Setup the PW sequence number */
                  layer4and5Header->header.layer5SequenceNumEnable = ZL5011X_TRUE;
                  layer4and5Header->header.layer5SequenceNum16bit = ZL5011X_TRUE;
                  layer4and5Header->header.layer5SequenceNumPos = ZL5011X_PKT_MPLS_HDR_LEN + ZL5011X_PKT_PW_SEQ_POS;

                  layer4and5Header->header.txHighLength = ZL5011X_PKT_MPLS_HDR_LEN + ZL5011X_PKT_PW_HDR_LEN;

                  pwStatusPos = layer4and5Header->header.txHighLength - ZL5011X_PKT_PW_HDR_LEN;
                  break;

               case ZL5011X_MPLS_MPLS_PW:
                  /* Layer 3: MPLS  */
                  if (status == ZL5011X_OK)
                  {
                     status = zl5011xAddMPLSHeader(layer2and3Header, par);
                  }

                  /* Layer 3: MPLS - place in the PE block to allow context switching.
                     Setup the PW sequence number */
                  layer4and5Header->header.layer5SequenceNumEnable = ZL5011X_TRUE;
                  layer4and5Header->header.layer5SequenceNum16bit = ZL5011X_TRUE;
                  layer4and5Header->header.layer5SequenceNumPos = ZL5011X_PKT_MPLS_HDR_LEN + ZL5011X_PKT_PW_SEQ_POS;

                  layer4and5Header->header.txHighLength = ZL5011X_PKT_MPLS_HDR_LEN + ZL5011X_PKT_PW_HDR_LEN;

                  pwStatusPos = layer4and5Header->header.txHighLength - ZL5011X_PKT_PW_HDR_LEN;
                  break;

               case ZL5011X_MPLS_PW_RTP:
                  /* Layer 3: MPLS - place in the PE block to allow context switching.
                     Setup the PW sequence number */
                  layer4and5Header->header.layer5SequenceNumEnable = ZL5011X_TRUE;
                  layer4and5Header->header.layer5SequenceNum16bit = ZL5011X_TRUE;
                  if (par->rtpForceSeqNumber == ZL5011X_TRUE)
                  {
                     layer4and5Header->header.layer5SequenceNumPos = ZL5011X_PKT_MPLS_HDR_LEN + ZL5011X_PKT_PW_HDR_LEN + ZL5011X_PKT_RTP_SEQ_POS;
                  }
                  else
                  {
                     layer4and5Header->header.layer5SequenceNumPos = ZL5011X_PKT_MPLS_HDR_LEN + ZL5011X_PKT_PW_SEQ_POS;
                  }

                  /* setup the timestamp field for the RTP header */
                  layer4and5Header->header.layer5TimestampEnable = ZL5011X_TRUE;
                  layer4and5Header->header.layer5TimestampIncrement = (Uint16T)par->rtpTimestampInc;
                  layer4and5Header->header.layer5TimestampFromWan = par->rtpTimestampFromWan;
                  layer4and5Header->header.layer5Timestamp32bit = ZL5011X_TRUE;
                  layer4and5Header->header.layer5TimestampPos = ZL5011X_PKT_MPLS_HDR_LEN + ZL5011X_PKT_PW_HDR_LEN +
                        ZL5011X_PKT_RTP_TS_POS;

                  layer4and5Header->header.txHighLength = ZL5011X_PKT_MPLS_HDR_LEN + ZL5011X_PKT_PW_HDR_LEN +
                        ZL5011X_PKT_RTP_HDR_LEN;

                  pwStatusPos = layer4and5Header->header.txHighLength - ZL5011X_PKT_RTP_HDR_LEN - ZL5011X_PKT_PW_HDR_LEN;
                  break;

               case ZL5011X_CD:
                  layer4and5Header->header.txHighLength = 0;
                  status = zl5011xAddCDHeader(layer2and3Header, layer4and5Header, par, &cdPos);
                  cdEnable = ZL5011X_TRUE;

⌨️ 快捷键说明

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