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

📄 zl5011xpacketrx.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************
*
*  File name:              zl5011xPacketRx.c
*
*  Version:                90
*
*  Author:                 JFE
*
*  Date created:           19/06/2002
*
*  Copyright 2002, 2003, 2004, 2005, Zarlink Semiconductor Limited.
*  All rights reserved.
*
*  Module Description:
*
*  This file contains packet Rx construction routines.
*
*  Revision History:
*
*  Rev:  Date:       Author:  Comments:
*  1     19/06/2002  JFE      Initial revision
*  2     04/09/2002  JFE      Made functions to control classifier and
*                             pre-classifier separate.
*                             Added the protocol stack template stuff.
*  3     06/09/2002  JFE      Fixed a #define use.
*  4     06/09/2002  JFE      Fixed a little bug with classify check bytes.
*                             Added support for VLAN
*                             Changed name of protocolType structure member
*  5     06/09/2002  JFE      Fixed bug with programming the classifier rules
*  6     06/09/2002  JFE      Added support for SNAP
*                             par->header is now a pointer which needs to be
*                             checked before it can be used.
*  7     06/09/2002  JFE      Changed name of template structure array so that
*                             a different pointer can be obtained for IPv4
*                             protocols to the pointer for IPv6.
*                             Fixed a problem with vlan support when a check
*                             or classify is required on VLAN tag.
*  8     11/09/2002  JFE      Added condition that ZL5011X_PW can only be used
*                             when VLAN enabled.
*  9     12/09/2002  JFE      Sorted out some length / modifier issues
*                             Added capability to deal with CD protocol stacks
*                             Fixed returns to free dynamic memory allocated
*  10    13/09/2002  JFE      Modified to deal with option of L2TP cookie
*  11    16/09/2002  JFE      Change zl5011xPacketRxSetHeader to be able to
*                             setup checking on length field.
*  12    16/09/2002  JFE      Changed zl5011xGetHeaderLength to take care of
*                             new control protocol stacks.
*                             Fixed a problem with VLAN.
*  13    17/09/2002  JFE      Fixed a problem with checking on IP length field.
*  14    17/09/2002  JFE      Fixed more issues with classification on VLAN.
*  15    18/09/2002  JFE      Fixed VLAN classification key and mask extraction.
*  16    18/09/2002  JFE      VLAN Post Verification issue. Also fixed uninit variable.
*  17    18/09/2002  JFE      Fixed another VLAN pv issue.
*  18    19/09/2002  JFE      Fixed some information for PKC task message setup.
*  19    20/09/2002  JFE      Changed #include to zl5011xApi.h
*  20    23/09/2002  JFE      Added function zl5011xPacketRxSetControlHeader()
*  21    23/09/2002  JFE      Mainly cosmetic changes
*                             Changed endian of check bytes for IP length in line
*                             with PKC endian.
*  22    25/09/2002  JFE      Added capability to deal with calling function
*                             trying to set up the same protocol type.
*  23    27/09/2002  JFE      Changed the way we deal with double-setting up
*                             same protocol stack. Now not using device structure.
*  24    02/10/2002  JFE      When calling function doesn't setup the context
*                             descriptor parameters, program the PKC to assume
*                             the CD field exists as the last two bytes in the header.
*                             Changed ZL5011X_TRACE macros to include function name first.
*  25    02/10/2002  JFE      Fixed problem with determining CD field position.
*  26    03/10/2002  DJA      ZL5011X_TRACE messages fixed up
*  27    03/10/2002  JFE      Added setup of PW Status ram (in PKC) for all new
*                             contexts involving PW.
*  28    03/10/2002  JFE      Fixed confusion between context no & matchNum
*  29    08/10/2002  JFE      Peer review actions.
*  30    10/10/2002  JFE      Made changes to accommodate revelation that IPv6 pre-
*                             classification with VLAN is hard.
*  31    10/10/2002  JFE      Enlarged on code to determine whether or not a protocol
*                             stack has been setup to include support for CD
*                             protocol stacks with various CD offsets.
*  32    14/10/2002  SAC      Fixed single '=' in conditional expression.
*  33    21/10/2002  JFE      Modified handling of L2TPv3 optional cookie.
*  34    31/10/2002  MRC      Added variants + minor fixes
*  35    31/10/2002  JFE      Fixed type in L2TPv3 optional cookie handling.
*  36    31/10/2002  JFE      Fixed problems with decision making for reuse of shared
*                             stub with CD protocol stacks involving SNAP.
*  37    04/11/2002  JFE      Added the protocolTwoByteSeq handling.
*                             Fixed incorrect usage of L2TP Header Length macro.
*                             Took SNAP out of the equation for L2TPv3 header pos.
*  38    06/11/2002  JFE      Made changes to allow for correct calculation of PW byte
*                             position in presence of VLAN.
*  39    06/11/2002  JFE      Fixed header length calculation for L2TPV3 / RTCP Ctrl
*  40    12/11/2002  JFE      Fixed a bit of a bug in pw position calculation.
*  41    15/11/2002  JFE      Added function to deal with the removal of protocol match
*                             entries.
*  42    18/11/2002  JFE      Fixed a bug with packetRxDeleteHeader
*  43    05/03/2003  MRC      Fairly big tweak
*  44    06/03/2003  MRC      Tidied up references to a cookie and IP->L2TPV3_CTRL
*  45    06/03/2003  MRC      Added OS exclusion and VLAN fix
*  46    10/03/2003  MRC      Length check enable now checks that the length
*                             position != 0 before changing masks etc.
*  47    24/03/2003  MRC      Add parameter to force one byte seq numbers
*  48    25/03/2003  MRC      Updated comment for parameter discardUdpCheckFails
*  49    19/05/2003  APL      L2TPv3 changes
*  50    22/05/2003  MRC      Reverted L2TPv3 changes
*  51    04/06/2003  JFE      Fixed problem with ZL5011X_CD making multiple pre-classify
*                             templates when only difference is IP Ver.
*  52    05/06/2003  JFE      Improved co-existence of SNAP and VLAN by changing the order
*                             (SNAP comes before VLAN).
*  53    06/06/2003  JFE      Changed call to calloc to use macro
*  54    10/06/2003  JFE      Performed pre-audit actions
*  55    11/06/2003  JFE      Added more useful information returned in structure when
*                             attempt to add pre-classifier match fails.
*  56    18/06/2003  ARW      Returning the value of  realContextDescriptorOffset when
*                             reusing a protcol involving CD
*  57    25/06/2003  MRC      Fixed a couple of problems with CD classification
*  58    25/06/2003  MRC      Fill in the CD header type automatically
*  59    18/07/2003  JFE      Fixed ZL5011X_CD freeing up issue
*  60    29/07/2003  APL      Added support for devices with no TDM interface
*  61    30/07/2003  APL      Audit action - rename of PacketToTdmMapping
*  62    13/08/2003  JFE      Added checking for concurrency of conflicting stacks
*  63    15/04/2004  MRC      Added option to disable timestamp extraction to
*                             packet Rx function
*  64    07/06/2004  MRC      Updated for MPLS->PW->RTP protocol
*  65    29/07/2004  MRC      Fixed some compiler warnings
*  66    04/08/2004  MRC      Updated MPLS protocols
*  67    25/08/2004  MRC      Protocol updates
*  68    27/08/2004  MRC      Corrected PW mask setting
*  69    13/09/2004  APL      Added option to remove headers or not.
*                             Ensure a valid payload length is specified if required.
*                             Corrected logic for host control packet matching.
*  70    27/09/2004  MRC      Uses the status byte mask for classification rather
*                             than value from the template
*  71    30/09/2004  MRC      Corrected classification mask for VLAN
*  72    17/11/2004  APL      Corrected logic to check for a valid payload length
*  73    19/11/2004  MRC      Added enum to allow more control over operations
*                             on the length for Packet Rx
*  74    26/11/2004  MRC      Added extra packet protocols
*  75    16/12/2004  MRC      Fixed header length calc for new protocols
*  76    21/01/2005  MRC      Added option for PacketRx to match ethernet MAC
*                             address (matchDestMacAddress) and a function
*                             for use on device reset zl5011xPacketRxFreeDevice
*  77    25/01/2005  APL      Removed check for device running in
*                             zl5011xPacketRxFreeDevice
*  78    28/01/2005  MRC      Added options to PacketRx to match IPv4 addresses
*  79    04/02/2005  MRC      Added option to apply masks to UDP ports and
*                             disable post classification checks
*  80    10/02/2005  MRC      Fixed some typos and allow protocol match number
*                             to be specified in call to zl5011xPacketRxSetProtocol
*  81    14/02/2005  APL      zl5011xPacketRxFreeDevice returns a meaningful error code
*                             if no packet matches have yet been defined.
*  82    18/02/2005  APL      Updated some comments
*  83    28/02/2005  APL      Added ZL5011X_ETHERNET type
*  84    17/03/2005  APL      Updated comment for zl5011xGetHeaderLength
*  85    18/03/2005  APL      Further update to comment for zl5011xGetHeaderLength
*  86    29/03/2005  APL      zl5011xPacketRxDeleteHeader now deletes header properly
*  87    19/04/2005  MRC      Added another packet length option
*  88    17/05/2005  MRC      Added custom 8 byte protocol header support
*  89    19/05/2005  MRC      Added PW byte support for custom headers
*  90    21/07/2005  MRC      Added IP->UDP->RTP and IP->UDP->RTP->PW->ALT protcols
*                             and support for UDP ports during protocol matching
*
******************************************************************************/

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

#include "zl5011xApi.h"
#include "zl5011xMisc.h"
#include "zl5011xLan.h"
#include "zl5011xPacket.h"
#include "zl5011xPkcMap.h"
#include "zl5011xPacketRxTemplates.h"

/*****************   STATIC FUNCTION DECLARATIONS   ***************************/

#ifdef _DEBUG
   #define static
#endif

/* Declare an array of devices to keep track of protocol stacks in use on a per-
   device basis. This information is not stored in the device structure because
   protocol stacks being supported are considered to be implementation-specific
   and it is not desirable to tie the API to specific protocol stacks. The only
   concept of protocol stacks should exist in the packet helper functions, hence
   the relevant structures are decleared as global in this file. */
static zl5011xProtocolTableS Zl5011xProtocolTable[ZL5011X_MAX_NUMBER_DEVICES];
static zl5011xBooleanE Zl5011xProtocolTableInitialised = ZL5011X_FALSE;
static OS_MUTEX_ID Zl5011xProtocolTableExclusion = OS_SEM_INVALID;

static zlStatusE zl5011xPacketInitialiseTable(zl5011xPacketRxSetHeaderS * par);
static zlStatusE zl5011xPacketGetTable(zl5011xBooleanE waitForever);
static zlStatusE zl5011xPacketReleaseTable(void);
static zlStatusE zl5011xPacketRxSetProtocolFunc(zl5011xParamsS * zl5011xParams,
      zl5011xPacketRxSetHeaderS *par);
static zlStatusE zl5011xPacketRxSetHeaderFunc(zl5011xParamsS * zl5011xParams,
      zl5011xPacketRxSetHeaderS *par);
static zlStatusE zl5011xPacketRxSetControlHeaderFunc(zl5011xParamsS * zl5011xParams,
      zl5011xPacketRxSetHeaderS *par);

/*****************   EXTERNAL FUNCTION DEFINITIONS   *************************/

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

 Function:
    zl5011xPacketRxSetHeaderStructInit

 Description:
   Initialises structure used by functions :
      zl5011xPacketRxSetHeader
      zl5011xPacketRxSetProtocol
      zl5011xPacketRxSetControlHeader
      zl5011xPacketRxDeleteHeader

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   par            Pointer to the structure for configuration items.
                  See main functions

 Returns:
   zlStatusE

 Remarks:
    If osExclusionEnable is set to ZL5011X_TRUE then a semaphore is created.

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

zlStatusE zl5011xPacketRxSetHeaderStructInit(zl5011xParamsS *zl5011xParams,
      zl5011xPacketRxSetHeaderS * par)
{
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_PACKET_FN_ID,"zl5011xPacketRxSetHeaderStructInit:",0, 0, 0, 0, 0, 0);

   /* do some parameter checking */
   status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);

   if (status == ZL5011X_OK)
   {
      par->context = (Uint32T)ZL5011X_INVALID_CONTEXT;
      par->protocolType = ZL5011X_INVALID_PROTOCOL;
      par->cpuQueue = ZL5011X_QUEUE_0;
      par->header = NULL;
      par->headerLength = 0;
      par->protocolMatchNumber = (Uint32T)ZL5011X_INVALID;
      par->classifyMatchNumber = (Uint32T)ZL5011X_INVALID;
      par->enableVlan = ZL5011X_FALSE;
      par->enableSnap = ZL5011X_FALSE;
      par->ipVer4 = ZL5011X_TRUE;
      par->discardUdpCheckFails = ZL5011X_TRUE;
      par->enableL2TPCookie = ZL5011X_FALSE;
      par->contextDescriptorOffset = (Uint32T)ZL5011X_INVALID;
      par->contextDescriptorNumber = ZL5011X_PKT_UNINIT;

      par->forceOneByteSeq = ZL5011X_TRUE;

      /* control whether the protocol classification phase should check the
         dest MAC and / or IPv4 fields */
      par->matchDestMacAddress = ZL5011X_FALSE;
      par->matchDestIpv4Address = ZL5011X_FALSE;

      /* control whether the classification stage should use the IPv4 src address */
      par->matchSrcIpv4Address = ZL5011X_TRUE;

      /* default to matching the UDP ports during classification */
      par->srcUdpPortMask = 0x0000;
      par->destUdpPortMask = 0x0000;

      /* enable classification checks by default */
      par->enableClassificationChecks = ZL5011X_TRUE;

      /* set to ZL5011X_TRUE to force the sequence number to be extracted from

⌨️ 快捷键说明

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