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

📄 zl5011xpacket.h

📁 Zalink50114----TDMoIP芯片驱动源码
💻 H
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
*
*  File name:              zl5011xPacket.h
*
*  Version:                69
*
*  Author:                 JFE
*
*  Date created:           19/06/2002
*
*  Copyright 2002, 2003, 2004, 2005, Zarlink Semiconductor Limited.
*  All rights reserved.
*
*  Module Description:
*
*  This is the header file for the packet functions.
*
*  Revision History:
*
*  Rev:  Date:       Author:  Comments:
*  1     19/06/2002  JFE      Initial revision
*  2     05/07/2002  JFE      Added some macros
*                             Changed a couple of offset macros so that the
*                             unit is in bytes.
*  3     09/07/2002  JFE      Added some macros
*                             Added new structure member to specify whether or
*                             not MAC should append ethernet src address.
*  4     09/07/2002  JFE      Made changes to protocol type enumeration.
*  5     09/07/2002  JFE      Change to contextID -> context structure member.
*  6     10/07/2002  MRC      Added prototypes for checksum functions.
*  7     10/07/2002  JFE      Changed VLAN header length to 4 bytes.
*                             Added support for PacketRxSetHeader function.
*                             Code review actions.
*  8     06/08/2002  MRC      Changed error code in check macro
*  9     07/08/2002  MRC      Updated, adding in checksums calculations etc.
*  10    14/08/2002  MRC      Added update UDP checksum function
*  11    16/08/2002  MRC      Added another checksum function
*  12    16/08/2002  MRC      Added control to allow the Tx RTP timestamp to be
*                             derived from the WAN interface.
*  13    28/08/2002  MRC      Added support for packet Tx CD headers
*  14    03/09/2002  MRC      Added teardown for Tx CD headers
*  15    04/09/2002  JFE      Changes to packet rx function structures and static
*                             function prototypes.
*  16    05/09/2002  JFE      Fixed mask in/out macros which were upside down
*  17    05/09/2002  MRC      changed fn zl5011xPacketGetWanRxCDHeader
*  18    06/09/2002  JFE      Changed some #defines for header field positions
*  19    11/09/2002  JFE      Added #define for minimum packet size
*  20    12/09/2002  JFE      Added payload length member to zl5011xPacketRxSetHeaderS
*  21    13/09/2002  JFE      Added member to zl5011xPacketRxSetHeaderS for optional
*                             L2TP cookie.
*  22    13/09/2002  JFE      Added #define for L2TPV3 since cookie is optional which
*                             affects length of header.
*                             Modified zl5011xPacketRxTemplateS to allow option of cookie
*  23    16/09/2002  JFE      Added control protocol stacks to the protocolType enum.
*  24    23/09/2002  JFE      Added prototype for function zl5011xPacketRxSetControlHeader.
*                             Added cpu queue to the packet rx structure for control headers.
*  25    25/09/2002  JFE      Updating of a comment.
*  26    27/09/2002  JFE      Added a couple of structures to deal with double setting up
*                             of protocol stacks.
*  27    03/10/2002  JFE      Added #define for initialising PW Status Ram.
*  28    08/10/2002  JFE      Peer review actions.
*  29    10/10/2002  JFE      Changed zl5011xPacketProtocolStackS to include members to
*                             deal with the same CD stacks with different CD offsets.
*  30    22/10/2002  JFE      Added a third dimension to protocolMatchNumber to take account
*                             of presence of l2tpv3 cookie.
*  31    31/10/2002  MRC      Added variants + minor fixes
*  32    31/10/2002  JFE      Changed header length for L2TPv2 Control
*  33    04/11/2002  JFE      Added packet rx structure member to override
*                              template sequence number 2-byte instruction
*  34    15/11/2002  JFE      New function prototype for zl5011xPacketRxDeleteHeader.
*  35    21/02/2003  MRC      Moved packet checksum functions to apiHigh
*  36    21/02/2003  JFE      Added some new definitions for ethertypes
*  37    28/02/2003  JFE      Added IP protocol definitions
*  38    05/03/2003  MRC      Fairly big tweak
*  39    06/03/2003  MRC      Added OS exclusion
*  40    24/03/2003  MRC      Add parameter to force one byte seq numbers
*  41    25/03/2003  MRC      Added field positions for UDP checksum calc
*  42    19/05/2003  APL      L2TPv3 changes
*  43    22/05/2003  MRC      Allows the IPv4 header fields to be fixed
*  44    25/06/2003  MRC      Added CD header defines
*  45    29/07/2003  APL      Removed duplicate macro definition
*  46    04/08/2003  APL      Removed unused variable for some device variants
*  47    28/10/2003  AMS      Update
*  48    29/10/2003  AMS      Update
*  49    30/10/2003  AMS      Update
*  50    07/11/2003  AMS      Update
*  51    11/11/2003  AMS      Update
*  52    18/11/2003  AMS      Update
*  53    06/01/2004  MRC      Reverted to revision 46
*  54    15/04/2004  MRC      Added option to disable timestamp extraction to
*                             packet Rx function
*  55    07/06/2004  MRC      Updated for MPLS->PW->RTP protocol
*  56    29/07/2004  MRC      Fixed some compiler warnings
*  57    25/08/2004  MRC      Protocol updates
*  58    13/09/2004  APL      Allow option to not remove headers
*  59    27/09/2004  MRC      Added default value for status byte mask
*  60    19/11/2004  MRC      Added enum to allow more control over operations
*                             on the length for Packet Rx
*  61    21/01/2005  MRC      Added option for PacketRx to match ethernet MAC
*                             address (matchDestMacAddress) and a function
*                             for use on device reset zl5011xPacketRxFreeDevice
*  62    28/01/2005  MRC      Added options to PacketRx to match IPv4 addresses
*  63    04/02/2005  MRC      Added option to apply masks to UDP ports and
*                             disable post classification checks
*  64    10/02/2005  MRC      Fixed some typos
*  65    01/03/2005  APL      Added function to delete specified protocol match
*  66    01/03/2005  APL      Added include file
*  67    09/03/2005  APL      Added another include file
*  68    17/03/2005  APL      Added ZL5011X_PACKET_ETHERNET_FCS
*  69    19/04/2005  MRC      Added another packet length option
*
******************************************************************************/

#ifndef _ZL5011X_PACKET_H
#define _ZL5011X_PACKET_H

#ifdef __cplusplus
extern "C" {
#endif

/*****************   INCLUDE FILES   *****************************************/
#include "zl5011xLan.h"
#include "zl5011xPktProtocol.h"

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

#define ZL5011X_PACKET_RX_MUTEX_TIMEOUT_MS  2000

#define ZL5011X_CHECK_POINTER(x)  if (x == NULL) return(ZL5011X_PARAMETER_INVALID);
#define ZL5011X_CHECK_STATUS(x)   if (x != ZL5011X_OK) return(x);

#define ZL5011X_PACKET_DEFAULT_STATUS_MASK  0xe

#define ZL5011X_PKT_ETHERNET_HDR_LEN  14 /* Number of bytes in ethernet header     */
#define ZL5011X_PKT_ETHERSNAP_HDR_LEN (ZL5011X_PKT_ETHERNET_HDR_LEN + ZL5011X_PKT_SNAP_FIELD_LEN)
#define ZL5011X_PKT_SNAP_FIELD_LEN    8  /* Number of bytes in SNAP field          */
#define ZL5011X_PKT_CD_HDR_LEN        2  /* Number of bytes in Context Descr. hdr  */
#define ZL5011X_PKT_VLAN_HDR_LEN      4  /* Number of bytes in VLAN header         */
#define ZL5011X_PKT_MPLS_HDR_LEN      4  /* Number of bytes in MPLS header         */
#define ZL5011X_PKT_IPV4_HDR_LEN      20 /* Number of bytes in IP v4 header        */
#define ZL5011X_PKT_IPV6_HDR_LEN      40 /* Number of bytes in IP v6 header        */
#define ZL5011X_PKT_UDP_HDR_LEN       8  /* Number of bytes in UDP header          */
#define ZL5011X_PKT_RTP_HDR_LEN       12 /* Number of bytes in RTP header          */
#define ZL5011X_PKT_PW_HDR_LEN        4  /* Number of bytes in PW header           */
#define ZL5011X_PKT_L2TP_HDR_LEN      8  /* Number of bytes in L2TP header         */
#define ZL5011X_PKT_L2TPV3_HDR_LEN    4  /* Number of bytes in the L2TPv3 header   */
#define ZL5011X_PKT_L2TPV3_COOKIE_LEN 4
#define ZL5011X_PKT_ETHERSNAP_LEN_POS 12 /* -from start of ETH hdr (8-bit bytes)   */
#define ZL5011X_PKT_IPV4_IDENT_POS    4  /* -from start of IP hdr (8-bit bytes)    */
#define ZL5011X_PKT_IPV4_LEN_POS      2  /* -from start of IP hdr (8-bit bytes)    */
#define ZL5011X_PKT_IPV4_ADDR_POS     12 /* -from start of IP hdr (8-bit bytes)    */
#define ZL5011X_PKT_IPV4_ADDR_LEN     8  /* number of bytes in the IP addresses */
#define ZL5011X_PKT_IPV4_SRC_POS      12 /* -from start of IP hdr (8-bit bytes) */
#define ZL5011X_PKT_IPV4_DEST_POS     16 /* -from start of IP hdr (8-bit bytes) */
#define ZL5011X_PKT_IPV6_LEN_POS      4  /* -from start of IP hdr (8-bit bytes)    */
#define ZL5011X_PKT_IPV6_ADDR_POS     8  /* -from start of IP hdr (8-bit bytes)    */
#define ZL5011X_PKT_IPV6_ADDR_LEN     32 /* number of bytes in the IP addresses */
#define ZL5011X_PKT_UDP_LEN_POS       4  /* -from start of UDP hdr (8-bit bytes)   */
#define ZL5011X_PKT_L2TP_LEN_POS      2  /* -from start of L2TP hdr (8-bit bytes)  */
#define ZL5011X_PKT_IPV4_CHKSUM_POS   10 /* -from start of IP hdr (8-bit bytes)    */
#define ZL5011X_PKT_UDP_CHKSUM_POS    6  /* -from start of UDP hdr (8-bit bytes)   */
#define ZL5011X_PKT_RTP_SEQ_POS       2  /* -from start of RTP hdr (8-bit bytes)   */
#define ZL5011X_PKT_PW_SEQ_POS        2  /* -from start of PW hdr (8-bit bytes) NB:
                                      It is not exactly 16 bits because the
                                      sequence number is 14 bits long.       */
#define ZL5011X_PKT_IPV4_TYPE_POS     9  /* -from start of IP header               */
#define ZL5011X_PKT_IPV6_TYPE_POS     6  /* -from start of IP header               */
#define ZL5011X_PKT_UDP_SRC_PORT_POS  0  /* -from start of UDP header              */
#define ZL5011X_PKT_UDP_DEST_PORT_POS 2  /* -from start of UDP header              */
#define ZL5011X_PKT_L2TP_TNL_ID_POS   4  /* -from start of L2TP header             */
#define ZL5011X_PKT_L2TP_SESS_ID_POS  6  /* -from start of L2TP header             */
#define ZL5011X_PKT_RTP_TS_POS        4  /* -from start of RTP hdr (8-bit bytes)   */
#define ZL5011X_PKT_MPLS_VC_TLV_POS   0  /* -from start of MPLS header             */
#define ZL5011X_PKT_MPLS_GROUP_ID_POS 4  /* -from start of MPLS header             */
#define ZL5011X_PKT_MPLS_VC_ID_POS    8  /* -from start of MPLS header             */

#define ZL5011X_PACKET_HEADER_MAX (ZL5011X_PTX_LOW_HEADER_MAX_LEN + \
                                                 ZL5011X_RTP_HIGH_HEADER_MAX_LEN)
#define ZL5011X_PACKET_PACKET_MIN     64 /* Minimum number of bytes in ethernet packet */
#define ZL5011X_PACKET_ETHERNET_FCS   4  /* Size of the Ethernet Frame Check Sequence */

#define ZL5011X_PKT_CD_TYPE_POS       13
#define ZL5011X_PKT_CD_TYPE_UDP       0x1
#define ZL5011X_PKT_CD_TYPE_STD       0x0

#define ZL5011X_PKT_CD_SWITCH_POS     12
#define ZL5011X_PKT_CD_TEARDOWN_POS   8
#define ZL5011X_PKT_CD_CONTEXT_POS    0
#define ZL5011X_PKT_CD_CONTEXT_MASK   0xff

/* Macros for the PKC */
#define ZL5011X_DONT_CARE         0xFF
#define ZL5011X_MASK_OUT          0xFF
#define ZL5011X_MASK_IN           0x00
#define ZL5011X_MASK_IN_VLAN_ID   (Uint32T)0xF000

#define ZL5011X_ETHERTYPE_IPV4_A  0x08 /* First byte of IPv4 Ethertype         */
#define ZL5011X_ETHERTYPE_IPV4_B  0x00 /* Second byte of IPv4 Ethertype        */
#define ZL5011X_ETHERTYPE_IPV6_A  0x86 /* First byte of IPv6 Ethertype         */
#define ZL5011X_ETHERTYPE_IPV6_B  0xDD /* Second byte of IPv6 Ethertype        */
#define ZL5011X_ETHERTYPE_UMPLS_A 0x88 /* First byte of unicast MPLS Ethertype */
#define ZL5011X_ETHERTYPE_UMPLS_B 0x47 /* Second byte of u-cast MPLS Ethertype */
#define ZL5011X_ETHERTYPE_MMPLS_A 0x88 /* First byte of m-cast MPLS Ethertype  */
#define ZL5011X_ETHERTYPE_MMPLS_B 0x48 /* Second byte of m-cast MPLS Ethertype */
#define ZL5011X_IP_VERSION_IPV4   0x40
#define ZL5011X_IP_VERSION_IPV6   0x60
#define ZL5011X_IP_TYPE_UDP       0x11 /* Contents of IP type field            */
#define ZL5011X_IP_TYPE_L2TP      0x73 /* Contents of IP type field            */
#define ZL5011X_MPLS_VC_TYPE      0x0005
#define ZL5011X_MPLS_VC_TYPE_VLAN 0x0004

#define ZL5011X_PKT_UNINIT        0xff

#define ZL5011X_PKT_RTCP_CTRL_HDR_LEN    8  /* Number of bytes */
#define ZL5011X_PKT_L2TPV2_CTRL_HDR_LEN  14 /* Number of bytes */
#define ZL5011X_PKT_L2TPV3_CTRL_HDR_LEN  16 /* Number of bytes */

/*****  ETHERTYPES: */
#define ZL5011X_PKT_ETHERTYPE_LEN     (2)  /* Number of bytes */
#define ZL5011X_PKT_ETHERTYPE_VLAN    ((Uint16T)0x8100)
#define ZL5011X_PKT_ETHERTYPE_CD      ((Uint16T)0x80CD)
#define ZL5011X_PKT_ETHERTYPE_PW      ((Uint16T)0xDEAF)
#define ZL5011X_PKT_ETHERTYPE_IPV4    ((Uint16T)0x0800)
#define ZL5011X_PKT_ETHERTYPE_IPV6    ((Uint16T)0x86DD)
#define ZL5011X_PKT_ETHERTYPE_MPLS    ((Uint16T)0x8847)

#define ZL5011X_PKT_IP_PROTOCOL_UDP   ((Uint16T)17)
#define ZL5011X_PKT_IP_PROTOCOL_L2TP  ((Uint16T)115)

/* Constant required to support multiple devices */
#define ZL5011X_MAX_NUMBER_DEVICES             16

/*****************   DATA STRUCTURES   ***************************************/

#define ZL5011X_PKT_INCOMPATIBLE_HEADER  ZL5011X_PKC_NUM_PROTOCOL_ENTRIES

typedef struct
{
   Uint32T context;
   zl5011xProtocolTypeE protocolType;
   Uint8T portNum;
   Uint8T queueNum;
   Uint8T *header;
   Uint8T headerLength;

   /* Ethernet control variables */
   zl5011xBooleanE enableVlan;
   zl5011xBooleanE enableSnap;
   zl5011xBooleanE ethernetSrcAddressFromMac;

   /* IP version - ZL5011X_TRUE for IPv4 and ZL5011X_FALSE for IPv6 */
   zl5011xBooleanE ipVer4;

   /* allow IP header to be fixed - no dynamic fields from device */
   zl5011xBooleanE fixIpv4Header;

   /* when using a fixed IPv4 header, the payload length MUST be supplied,
      to allow construction of the header */
   Uint16T payloadLength;

   /* enable for UDP checksum */
   zl5011xBooleanE enableUDPChecksum;

   /* L2TP Control Structure Members */
   zl5011xBooleanE  enableL2TPCookie;

   /* RTP Control Structure members: */
   Uint32T rtpTimestampInc;
   zl5011xBooleanE rtpTimestampFromWan;

   /* in the presence of both RTP and PW headers, this can be used to control
      which of the two sequence numbers gets used */

⌨️ 快捷键说明

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