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

📄 zl5011xpktprotocol.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
字号:
/******************************************************************************
*
*  File name:              zl5011xPktProtocol.c
*
*  Version:                4
*
*  Author:                 APL
*
*  Date created:           28/01/2005
*
*  Copyright 2002, 2003, 2004, 2005, Zarlink Semiconductor Limited.
*  All rights reserved.
*
*  Module Description:
*
*  Packet interface helper functions for determining what protocols are in a
*  combined stack definition
*
*  Revision History:
*
*  Rev:  Date:       Author:  Comments:
*  1     28/01/2005  APL      Initial revision
*  2     01/03/2005  APL      Fixed include file error
*  3     01/06/2005  MRC      Removed dependency on order of protocol enum
*  4     21/07/2005  MRC      Added IP->UDP->RTP and IP->UDP->RTP->PW->ALT protocols
*
******************************************************************************/

/*****************   INCLUDE FILES   *****************************************/

#include "zl5011xPktProtocol.h"

/*****************   MACROS   ************************************************/

/*****************   ENUMERATIONS AND STRUCTURES *****************************/

/* A pointer to a null terminated list of zl5011xProtocolPartsE, defining the elements
   of a stack */
const Uint8T protocolList_ZL5011X_CD[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_CD, 0 };

const Uint8T protocolList_ZL5011X_PW[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_PW, 0 };

const Uint8T protocolList_ZL5011X_IP_CD[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_IP, ZL5011X_PROTOCOL_CD, 0 };

const Uint8T protocolList_ZL5011X_IP_UDP[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_IP, ZL5011X_PROTOCOL_UDP, 0 };

const Uint8T protocolList_ZL5011X_IP_UDP_PW[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_IP, ZL5011X_PROTOCOL_UDP, ZL5011X_PROTOCOL_PW, 0 };

const Uint8T protocolList_ZL5011X_IP_UDP_CD[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_IP, ZL5011X_PROTOCOL_UDP, ZL5011X_PROTOCOL_CD, 0 };

const Uint8T protocolList_ZL5011X_IP_UDP_RTP[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_IP, ZL5011X_PROTOCOL_UDP, ZL5011X_PROTOCOL_RTP, 0 };

const Uint8T protocolList_ZL5011X_IP_UDP_RTP_PW[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_IP, ZL5011X_PROTOCOL_UDP, ZL5011X_PROTOCOL_RTP, ZL5011X_PROTOCOL_PW, 0 };

const Uint8T protocolList_ZL5011X_IP_UDP_L2TPV2_PW[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_IP, ZL5011X_PROTOCOL_UDP, ZL5011X_PROTOCOL_L2TPV2, ZL5011X_PROTOCOL_PW, 0 };

const Uint8T protocolList_ZL5011X_IP_L2TPV3_PW[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_IP, ZL5011X_PROTOCOL_L2TPV3, ZL5011X_PROTOCOL_PW, 0 };

const Uint8T protocolList_ZL5011X_IP_L2TPV3_RTP_PW[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_IP, ZL5011X_PROTOCOL_L2TPV3, ZL5011X_PROTOCOL_RTP, ZL5011X_PROTOCOL_PW, 0 };

const Uint8T protocolList_ZL5011X_IP_PW_TS[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_IP, ZL5011X_PROTOCOL_PW, ZL5011X_PROTOCOL_TS, 0 };

const Uint8T protocolList_ZL5011X_MPLS[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_MPLS, 0 };

const Uint8T protocolList_ZL5011X_MPLS_PW[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_MPLS, ZL5011X_PROTOCOL_PW, 0 };
   /* Note ZL5011X_ECID_PW is identical */

const Uint8T protocolList_ZL5011X_MPLS_MPLS_PW[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_MPLS, ZL5011X_PROTOCOL_MPLS, ZL5011X_PROTOCOL_PW, 0 };

const Uint8T protocolList_ZL5011X_MPLS_PW_RTP[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_MPLS, ZL5011X_PROTOCOL_PW, ZL5011X_PROTOCOL_RTP, 0 };
   /* Note ZL5011X_ECID_PW_RTP is identical */

   /* Control Protocol Stacks */
const Uint8T protocolList_ZL5011X_IP_UDP_RTCP_CTRL[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_IP, ZL5011X_PROTOCOL_UDP, ZL5011X_PROTOCOL_RTCP, ZL5011X_PROTOCOL_CTRL, 0 };

const Uint8T protocolList_ZL5011X_IP_UDP_L2TPV2_CTRL[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_IP, ZL5011X_PROTOCOL_UDP, ZL5011X_PROTOCOL_L2TPV2, ZL5011X_PROTOCOL_CTRL, 0 };

const Uint8T protocolList_ZL5011X_IP_L2TPV3_CTRL[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_IP, ZL5011X_PROTOCOL_L2TPV3, ZL5011X_PROTOCOL_CTRL, 0 };

const Uint8T protocolList_ZL5011X_IP_L2TPV3_RTCP_CTRL[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_IP, ZL5011X_PROTOCOL_L2TPV3, ZL5011X_PROTOCOL_RTCP, ZL5011X_PROTOCOL_CTRL, 0 };

const Uint8T protocolList_ZL5011X_MPLS_RTCP_CTRL[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_MPLS, ZL5011X_PROTOCOL_RTCP, ZL5011X_PROTOCOL_CTRL, 0 };

const Uint8T protocolList_ZL5011X_CUSTOM8_PW[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_PW, 0 };

const Uint8T protocolList_ZL5011X_CUSTOM8_RTP_PW[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_RTP, ZL5011X_PROTOCOL_PW, 0 };

const Uint8T protocolList_ZL5011X_CUSTOM8_PW_RTP[] =
   { ZL5011X_PROTOCOL_ETHERNET, ZL5011X_PROTOCOL_PW, ZL5011X_PROTOCOL_RTP, 0 };

/* Generic ethernet protocol */
const Uint8T protocolList_ZL5011X_ETHERNET[] =
   { ZL5011X_PROTOCOL_ETHERNET, 0 };

typedef struct
{
   zl5011xProtocolTypeE protocolType;
   const Uint8T *list;
} zl5011xPktProtocolDefinitionsS;

/* Null terminated list of pointers to protocol definitions */
const zl5011xPktProtocolDefinitionsS zl5011xPktProtocolDefinitions[] =
{
   {ZL5011X_CD,                    protocolList_ZL5011X_CD },
   {ZL5011X_PW,                    protocolList_ZL5011X_PW},
   {ZL5011X_IP_CD,                 protocolList_ZL5011X_IP_CD},
   {ZL5011X_IP_UDP,                protocolList_ZL5011X_IP_UDP},
   {ZL5011X_IP_UDP_PW,             protocolList_ZL5011X_IP_UDP_PW},
   {ZL5011X_IP_UDP_CD,             protocolList_ZL5011X_IP_UDP_CD},
   {ZL5011X_IP_UDP_RTP,            protocolList_ZL5011X_IP_UDP_RTP},
   {ZL5011X_IP_UDP_RTP_PW,         protocolList_ZL5011X_IP_UDP_RTP_PW},
   {ZL5011X_IP_UDP_RTP_PW_ALT,     protocolList_ZL5011X_IP_UDP_RTP_PW},
   {ZL5011X_IP_UDP_L2TPV2_PW,      protocolList_ZL5011X_IP_UDP_L2TPV2_PW},
   {ZL5011X_IP_L2TPV3_PW,          protocolList_ZL5011X_IP_L2TPV3_PW},
   {ZL5011X_IP_L2TPV3_RTP_PW,      protocolList_ZL5011X_IP_L2TPV3_RTP_PW},
   {ZL5011X_IP_PW_TS,              protocolList_ZL5011X_IP_PW_TS},
   {ZL5011X_MPLS,                  protocolList_ZL5011X_MPLS},
   {ZL5011X_MPLS_PW,               protocolList_ZL5011X_MPLS_PW},
   {ZL5011X_MPLS_MPLS_PW,          protocolList_ZL5011X_MPLS_MPLS_PW},
   {ZL5011X_MPLS_PW_RTP,           protocolList_ZL5011X_MPLS_PW_RTP},
   {ZL5011X_CUSTOM8_PW,            protocolList_ZL5011X_CUSTOM8_PW},
   {ZL5011X_CUSTOM8_RTP_PW,        protocolList_ZL5011X_CUSTOM8_RTP_PW},
   {ZL5011X_CUSTOM8_PW_RTP,        protocolList_ZL5011X_CUSTOM8_PW_RTP},

/* Control Protocol Stacks */
   {ZL5011X_IP_UDP_RTCP_CTRL,      protocolList_ZL5011X_IP_UDP_RTCP_CTRL},
   {ZL5011X_IP_UDP_L2TPV2_CTRL,    protocolList_ZL5011X_IP_UDP_L2TPV2_CTRL},
   {ZL5011X_IP_L2TPV3_CTRL,        protocolList_ZL5011X_IP_L2TPV3_CTRL},
   {ZL5011X_IP_L2TPV3_RTCP_CTRL,   protocolList_ZL5011X_IP_L2TPV3_RTCP_CTRL},
   {ZL5011X_MPLS_RTCP_CTRL,        protocolList_ZL5011X_MPLS_RTCP_CTRL},

   {ZL5011X_ETHERNET,              protocolList_ZL5011X_ETHERNET},

   {ZL5011X_INVALID_PROTOCOL,      NULL}
};

/*******************************************************************************

 Function:
    zl5011xFindProtocolInStack

 Description:
    Finds a protocol in a specified aggregated stack description

 Inputs:
   protocol       The protocol to find
   protocolStack  The protocol stack to look in

 Outputs:
   None

 Returns:
   The zero based index of the protocol within the stack or -1 if not found

 Remarks:
   For example, if protocol is ZL5011X_PROTOCOL_UDP and protocolStack is ZL5011X_IP_UDP_RTP
   the return value will be 2

*******************************************************************************/

Sint8T zl5011xFindProtocolInStack(zl5011xProtocolPartsE protocol, zl5011xProtocolTypeE protocolStack)
{
   Sint8T retValue = -1;
   Uint8T loop, index;

   for (loop = 0; zl5011xPktProtocolDefinitions[loop].protocolType != ZL5011X_INVALID_PROTOCOL; loop++)
   {
      if (zl5011xPktProtocolDefinitions[loop].protocolType == protocolStack)
      {
         break;
      }
   }

   if (zl5011xPktProtocolDefinitions[loop].protocolType == protocolStack)
   {
      index = 0;

      while (zl5011xPktProtocolDefinitions[loop].list[index] != 0)
      {
         if (zl5011xPktProtocolDefinitions[loop].list[index] == protocol)
         {
            retValue = index;
            break;
         }

         index++;
      }
   }

   return retValue;
}

/*******************************************************************************

 Function:
    zl5011xProtocolIsInStack

 Description:
    Finds whether a protocol is within a specified aggregated stack description

 Inputs:
   protocol       The protocol to find
   protocolStack  The protocol stack to look in

 Outputs:
   None

 Returns:
   ZL5011X_TRUE if the protocol is within the stack,
   ZL5011X_FALSE if not

 Remarks:

*******************************************************************************/

zl5011xBooleanE zl5011xProtocolIsInStack(zl5011xProtocolPartsE protocol, zl5011xProtocolTypeE protocolStack)
{
   return (zl5011xFindProtocolInStack(protocol, protocolStack) >= 0) ? ZL5011X_TRUE : ZL5011X_FALSE;
}

⌨️ 快捷键说明

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