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

📄 net_icmp.c

📁 ucos的tcpip协议占
💻 C
📖 第 1 页 / 共 5 页
字号:
/*
*********************************************************************************************************
*                                              uC/TCP-IP
*                                      The Embedded TCP/IP Suite
*
*                          (c) Copyright 2003-2006; Micrium, Inc.; Weston, FL
*
*               All rights reserved.  Protected by international copyright laws.
*
*               uC/TCP-IP is provided in source form for FREE evaluation, for educational
*               use or peaceful research.  If you plan on using uC/TCP-IP in a commercial
*               product you need to contact Micrium to properly license its use in your
*               product.  We provide ALL the source code for your convenience and to help
*               you experience uC/TCP-IP.  The fact that the source code is provided does
*               NOT mean that you can use it without paying a licensing fee.
*
*               Knowledge of the source code may NOT be used to develop a similar product.
*
*               Please help us continue to provide the Embedded community with the finest
*               software available.  Your honesty is greatly appreciated.
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*
*                                          NETWORK ICMP LAYER
*                                 (INTERNET CONTROL MESSAGE PROTOCOL)
*
* Filename      : net_icmp.c
* Version       : V1.87
* Programmer(s) : ITJ
*********************************************************************************************************
* Note(s)       : (1) Supports Internet Control Message Protocol as described in RFC #792 with the following
*                     restrictions/constraints :
*
*                     (a) Does NOT support IP forwarding/routing               RFC #1122, Section 3.3.1
*
*                     (b) Does NOT support IP multicasting                     RFC #1122, Section 3.3.7
*
*                     (c) Does NOT support ICMP Address Mask Agent/Server      RFC #1122, Section 3.2.2.9
*********************************************************************************************************
*/

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

#define    NET_ICMP_MODULE
#include  <net.h>


/*$PAGE*/
/*
*********************************************************************************************************
*                                            LOCAL DEFINES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                           LOCAL CONSTANTS
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                          LOCAL DATA TYPES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                            LOCAL TABLES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                       LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/


/*$PAGE*/
/*
*********************************************************************************************************
*                                      LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/

                                                                    /* ------------------- RX FNCTS ------------------- */

#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
static  void                     NetICMP_RxPktValidateBuf         (NET_BUF_HDR             *pbuf_hdr,
                                                                   NET_ERR                 *perr);
#endif

static  void                     NetICMP_RxPktValidate            (NET_BUF                 *pbuf,
                                                                   NET_BUF_HDR             *pbuf_hdr,
                                                                   NET_ICMP_HDR            *picmp_hdr,
                                                                   NET_ERR                 *perr);

static  void                     NetICMP_RxPktFree                (NET_BUF                 *pbuf);

static  void                     NetICMP_RxPktDiscard             (NET_BUF                 *pbuf,
                                                                   NET_ERR                 *perr);


                                                                    /* ------------------- TX FNCTS ------------------- */

static  void                     NetICMP_TxMsgErrValidate         (NET_BUF                 *pbuf,
                                                                   NET_BUF_HDR             *pbuf_hdr,
                                                                   NET_IP_HDR              *pip_hdr,
                                                                   CPU_INT08U               type,
                                                                   CPU_INT08U               code,
                                                                   CPU_INT08U               ptr,
                                                                   NET_ERR                 *perr);


static  void                     NetICMP_TxMsgReqValidate         (CPU_INT08U               type,
                                                                   CPU_INT08U               code,
                                                                   NET_ERR                 *perr);


static  void                     NetICMP_TxMsgReply               (NET_BUF                 *pbuf,
                                                                   NET_BUF_HDR             *pbuf_hdr,
                                                                   NET_ICMP_HDR            *picmp_hdr,
                                                                   NET_ERR                 *perr);



static  void                     NetICMP_TxPktFree                (NET_BUF                 *pbuf);

static  void                     NetICMP_TxPktDiscard             (NET_BUF                 *pbuf,
                                                                   NET_ERR                 *perr);


                                                                    /* ---------------- HANDLER FNCTS ----------------- */

#if (NET_ICMP_CFG_TX_SRC_QUENCH_EN == DEF_ENABLED)
static  void                     NetICMP_HandlerTxSrcQuench       (NET_BUF                 *pbuf);

static  void                     NetICMP_HandlerTxSrcQuenchClrList(void);

static  void                     NetICMP_HandlerTxSrcQuenchClr    (NET_ICMP_TX_SRC_QUENCH  *ptx_src_quench);

static  NET_ICMP_TX_SRC_QUENCH  *NetICMP_HandlerTxSrcQuenchGet    (NET_ERR                 *perr);

static  void                     NetICMP_HandlerTxSrcQuenchFree   (NET_ICMP_TX_SRC_QUENCH  *ptx_src_quench);

static  void                     NetICMP_HandlerTxSrcQuenchRemove (NET_ICMP_TX_SRC_QUENCH  *ptx_src_quench);

static  void                     NetICMP_HandlerTxSrcQuenchInsert (NET_ICMP_TX_SRC_QUENCH  *ptx_src_quench);

static  void                     NetICMP_HandlerTxSrcQuenchUnlink (NET_ICMP_TX_SRC_QUENCH  *ptx_src_quench);

#if (NET_ERR_CFG_ARG_CHK_DBG_EN  == DEF_ENABLED)
static  void                     NetICMP_HandlerTxSrcQuenchDiscard(NET_ICMP_TX_SRC_QUENCH  *ptx_src_quench);
#endif
#endif


/*
*********************************************************************************************************
*                                     LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/


/*$PAGE*/
/*
*********************************************************************************************************
*                                           NetICMP_Init()
*
* Description : (1) Initialize Internet Control Message Protocol Layer :
*
*                   (a) Initialize ICMP transmit source quench :
*                       (1) Initialize ICMP transmit source quench pool
*                           (A) Pool MUST be initialized PRIOR to initializing the pool with pointers to
*                               ICMP transmit source quench entries.
*                       (2) Initialize ICMP transmit source quench table
*                       (3) Initialize ICMP transmit source quench list pointers
*                   (c) Initialize ICMP statistics & error counters
*
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : Net_Init().
*
*               This function is an INTERNAL network protocol suite function & MUST NOT be called by 
*               application function(s).
*
* Note(s)     : none.
*********************************************************************************************************
*/

void  NetICMP_Init (void)
{
#if (NET_ICMP_CFG_TX_SRC_QUENCH_EN == DEF_ENABLED)
    NET_ICMP_TX_SRC_QUENCH   *ptx_src_quench_tbl;
    NET_ICMP_SRC_QUENCH_QTY   i;
    NET_ERR                   err;


                                                                /* -------- INIT ICMP TX SRC QUENCH POOL/STATS -------- */
    NetICMP_TxSrcQuenchPoolPtr = (NET_ICMP_TX_SRC_QUENCH *)0;   /* See Note #1a1A.                                      */

    NetStat_PoolInit((NET_STAT_POOL   *)&NetICMP_TxSrcQuenchPoolStat,
                     (NET_STAT_POOL_QTY) NET_ICMP_CFG_TX_SRC_QUENCH_SIZE,
                     (NET_ERR         *)&err);


                                                                /* ----------- INIT ICMP TX SRC QUENCH TBL ------------ */
    ptx_src_quench_tbl = &NetICMP_TxSrcQuenchTbl[0];
    for (i = 0; i < NET_ICMP_CFG_TX_SRC_QUENCH_SIZE; i++) {
                                                                /* Init each ICMP tx src quench type--NEVER modify.     */
        ptx_src_quench_tbl->Type  = NET_ICMP_TYPE_TX_SRC_QUENCH;

        ptx_src_quench_tbl->Flags = NET_ICMP_FLAG_NONE;         /* Init each ICMP tx src quench as NOT used.            */

#if (NET_DBG_CFG_MEM_CLR_EN == DEF_ENABLED)
        NetICMP_HandlerTxSrcQuenchClr(ptx_src_quench_tbl);
#endif
                                                                /* Free each entry to pool (see Note #1a1A).            */
        ptx_src_quench_tbl->NextPtr = (void *)NetICMP_TxSrcQuenchPoolPtr;    
        NetICMP_TxSrcQuenchPoolPtr  =  ptx_src_quench_tbl;                         

        ptx_src_quench_tbl++;
    }


                                                                /* -------- INIT ICMP TX SRC QUENCH LIST PTRS --------- */
    NetICMP_TxSrcQuenchListHead = (NET_ICMP_TX_SRC_QUENCH *)0;
    NetICMP_TxSrcQuenchListTail = (NET_ICMP_TX_SRC_QUENCH *)0;
#endif


/*$PAGE*/
                                                                /* ------------ INIT ICMP STAT & ERR CTRS ------------- */
    NetICMP_TxSeqNbrCtr                =  0;


#if (NET_CTR_CFG_STAT_EN               == DEF_ENABLED)
    NetICMP_StatRxMsgCtr               =  0;
    NetICMP_StatRxMsgProcessedCtr      =  0;
    NetICMP_StatRxMsgErrProcessedCtr   =  0;
    NetICMP_StatRxMsgReqProcessedCtr   =  0;
    NetICMP_StatRxMsgReplyProcessedCtr =  0;

    NetICMP_StatTxMsgCtr               =  0;
    NetICMP_StatTxMsgErrCtr            =  0;
    NetICMP_StatTxMsgReqCtr            =  0;
    NetICMP_StatTxMsgReplyCtr          =  0;
#endif


#if (NET_CTR_CFG_ERR_EN                == DEF_ENABLED)
    NetICMP_ErrRxHdrTypeCtr            =  0;
    NetICMP_ErrRxHdrCodeCtr            =  0;
    NetICMP_ErrRxHdrMsgLenCtr          =  0;
    NetICMP_ErrRxHdrPtrCtr             =  0;
    NetICMP_ErrRxHdrChkSumCtr          =  0;

    NetICMP_ErrRxBroadcastCtr          =  0;

    NetICMP_ErrRxPktDiscardedCtr       =  0;


    NetICMP_ErrTxInvalidLenCtr         =  0;

    NetICMP_ErrTxHdrTypeCtr            =  0;
    NetICMP_ErrTxHdrCodeCtr            =  0;

    NetICMP_ErrTxPktDiscardedCtr       =  0;


#if (NET_ERR_CFG_ARG_CHK_DBG_EN        == DEF_ENABLED)
    NetICMP_ErrNullPtrCtr              =  0;
    NetICMP_ErrNotUsedCtr              =  0;

⌨️ 快捷键说明

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