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

📄 net_arp.c

📁 ucos的tcpip协议占
💻 C
📖 第 1 页 / 共 5 页
字号:
    NetARP_HostAddrPtrHW                =  NetARP_GetHostAddrPtrHW();
    NetARP_HostAddrPtrProtocol          =  NetARP_GetHostAddrPtrProtocol();


/*$PAGE*/
                                                                /* ------------- INIT ARP STAT & ERR CTRS ------------- */
#if (NET_CTR_CFG_STAT_EN                == DEF_ENABLED)
    NetARP_StatRxPktCtr                 =  0;
    NetARP_StatRxMsgProcessedCtr        =  0;
    NetARP_StatRxMsgReqProcessedCtr     =  0;
    NetARP_StatRxMsgReplyProcessedCtr   =  0;

    NetARP_StatTxMsgCtr                 =  0;
    NetARP_StatTxMsgReqCtr              =  0;
    NetARP_StatTxMsgReplyCtr            =  0;
#endif


#if (NET_CTR_CFG_ERR_EN                 == DEF_ENABLED)
    NetARP_ErrNoneAvailCtr              =  0;


    NetARP_ErrRxHdrHW_TypeCtr           =  0;
    NetARP_ErrRxHdrHW_AddrLenCtr        =  0;
    NetARP_ErrRxHdrHW_AddrCtr           =  0;
    NetARP_ErrRxHdrProtocolTypeCtr      =  0;
    NetARP_ErrRxHdrProtocolAddrLenCtr   =  0;
    NetARP_ErrRxHdrProtocolAddrCtr      =  0;
    NetARP_ErrRxHdrOpCodeCtr            =  0;
    NetARP_ErrRxHdrOpAddrCtr            =  0;
    NetARP_ErrRxHdrMsgLenCtr            =  0;

    NetARP_ErrRxPktTargetReplyCtr       =  0;
    NetARP_ErrRxPktTargetNotThisHostCtr =  0;
    NetARP_ErrRxPktDiscardedCtr         =  0;


    NetARP_ErrTxPktDiscardedCtr         =  0;


#if (NET_ERR_CFG_ARG_CHK_DBG_EN         == DEF_ENABLED)
    NetARP_ErrNullPtrCtr                =  0;
    NetARP_ErrNotUsedCtr                =  0;

    NetARP_ErrInvalidTypeCtr            =  0;


    NetARP_ErrRxInvalidBufIxCtr         =  0;

    NetARP_ErrTxHdrOpCodeCtr            =  0;
#endif
#endif
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                      NetARP_CfgCacheTimeout()
*
* Description : Configure ARP cache timeout from ARP Cache List.
*
* Argument(s) : timeout_sec     Desired value for ARP cache timeout (in seconds).
*
* Return(s)   : DEF_OK, ARP cache timeout configured.
*
* Caller(s)   : Net_InitDflt(),
*               Application.
*
*               This function is a network protocol suite application interface (API) function & MAY be 
*               called by application function(s).
*
* Note(s)     : (1) Timeout in seconds converted to 'NET_TMR_TICK' ticks in order to set initial 'NET_TMR'
*                   timeout value.
*********************************************************************************************************
*/

CPU_BOOLEAN  NetARP_CfgCacheTimeout (CPU_INT16U  timeout_sec)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR        cpu_sr;
#endif
    NET_TMR_TICK  tick;


#if (NET_ARP_CACHE_TIMEOUT_MIN_SEC > DEF_INT_16U_MIN_VAL)
    if (timeout_sec < NET_ARP_CACHE_TIMEOUT_MIN_SEC) {
        timeout_sec = NET_ARP_CACHE_TIMEOUT_MIN_SEC;
    }
#endif
#if (NET_ARP_CACHE_TIMEOUT_MAX_SEC < DEF_INT_16U_MAX_VAL)
    if (timeout_sec > NET_ARP_CACHE_TIMEOUT_MAX_SEC) {
        timeout_sec = NET_ARP_CACHE_TIMEOUT_MAX_SEC;
    }
#endif

    tick                     = (NET_TMR_TICK)timeout_sec * NET_TMR_TIME_TICK_PER_SEC;
    CPU_CRITICAL_ENTER();
    NetARP_CacheTimeout_sec  =  timeout_sec;
    NetARP_CacheTimeout_tick =  tick;
    CPU_CRITICAL_EXIT();

    return (DEF_OK);
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                      NetARP_CfgCacheAccessedTh()
*
* Description : Configure ARP cache accessed-promotion threshold.
*
* Argument(s) : nbr_access      Desired number of ARP cache accesses before ARP cache is promoted.
*
* Return(s)   : DEF_OK, ARP cache promotion threshold configured.
*
* Caller(s)   : Net_InitDflt(),
*               Application.
*
*               This function is a network protocol suite application interface (API) function & MAY be 
*               called by application function(s).
*
* Note(s)     : none.
*********************************************************************************************************
*/

CPU_BOOLEAN  NetARP_CfgCacheAccessedTh (CPU_INT16U  nbr_access)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR  cpu_sr;
#endif


#if (NET_ARP_CACHE_ACCESSED_TH_MIN > DEF_INT_16U_MIN_VAL)
    if (nbr_access < NET_ARP_CACHE_ACCESSED_TH_MIN) {
        nbr_access = NET_ARP_CACHE_ACCESSED_TH_MIN;
    }
#endif
#if (NET_ARP_CACHE_ACCESSED_TH_MAX < DEF_INT_16U_MAX_VAL)
    if (nbr_access > NET_ARP_CACHE_ACCESSED_TH_MAX) {
        nbr_access = NET_ARP_CACHE_ACCESSED_TH_MAX;
    }
#endif

    CPU_CRITICAL_ENTER();
    NetARP_CacheAccessedTh_nbr = nbr_access;
    CPU_CRITICAL_EXIT();

    return (DEF_OK);
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                      NetARP_CfgReqMaxRetries()
*
* Description : Configure ARP Request maximum number of requests.
*
* Argument(s) : max_nbr_retries     Desired maximum number of ARP Request attempts.
*
* Return(s)   : DEF_OK, ARP Request maximum number of attempts configured.
*
* Caller(s)   : Net_InitDflt(),
*               Application.
*
*               This function is a network protocol suite application interface (API) function & MAY be 
*               called by application function(s).
*
* Note(s)     : (1) An ARP cache monitors the number of ARP Requests transmitted before receiving an ARP
*                   Reply.  In other words, an ARP cache monitors the number of ARP Request attempts.
*
*                   However, the maximum number of ARP Requests that each ARP cache is allowed to transmit
*                   is configured in terms of retries.  Thus, the total number of attempts is equal to the
*                   configured number of retries plus one (1).
*********************************************************************************************************
*/

CPU_BOOLEAN  NetARP_CfgReqMaxRetries (CPU_INT08U  max_nbr_retries)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR  cpu_sr;
#endif


#if (NET_ARP_REQ_RETRY_MIN > DEF_INT_08U_MIN_VAL)
    if (max_nbr_retries < NET_ARP_REQ_RETRY_MIN) {
        max_nbr_retries = NET_ARP_REQ_RETRY_MIN;
    }
#endif
#if (NET_ARP_REQ_RETRY_MAX < DEF_INT_08U_MAX_VAL)
    if (max_nbr_retries > NET_ARP_REQ_RETRY_MAX) {
        max_nbr_retries = NET_ARP_REQ_RETRY_MAX;
    }
#endif

    CPU_CRITICAL_ENTER();
    NetARP_ReqMaxAttempts_nbr = max_nbr_retries + 1;        /* Set max attempts as max retries + 1 (see Note #1).       */
    CPU_CRITICAL_EXIT();

    return (DEF_OK);
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                       NetARP_CfgReqTimeout()
*
* Description : Configure timeout between ARP Request retries.
*
* Argument(s) : timeout_sec     Desired value for ARP Request pending ARP Reply timeout (in seconds).
*
* Return(s)   : DEF_OK, ARP Request timeout configured.
*
* Caller(s)   : Net_InitDflt(),
*               Application.
*
*               This function is a network protocol suite application interface (API) function & MAY be 
*               called by application function(s).
*
* Note(s)     : (1) RFC #1122, Section 2.3.2.1 states that "an implementation of the Address Resolution
*                   Protocol (ARP) ... MUST provide a mechanism to flush out-of-date cache entries.  If
*                   this mechanism involves a timeout, it SHOULD be possible to configure the timeout
*                   value".
*
*               (2) Timeout in seconds converted to 'NET_TMR_TICK' ticks in order to set initial 'NET_TMR'
*                   timeout value.
*********************************************************************************************************
*/

CPU_BOOLEAN  NetARP_CfgReqTimeout (CPU_INT08U  timeout_sec)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR        cpu_sr;
#endif
    NET_TMR_TICK  tick;


    if (timeout_sec < NET_ARP_REQ_RETRY_TIMEOUT_MIN_SEC) {
        timeout_sec = NET_ARP_REQ_RETRY_TIMEOUT_MIN_SEC;
    }
    if (timeout_sec > NET_ARP_REQ_RETRY_TIMEOUT_MAX_SEC) {
        timeout_sec = NET_ARP_REQ_RETRY_TIMEOUT_MAX_SEC;
    }

    tick                   = (NET_TMR_TICK)timeout_sec * NET_TMR_TIME_TICK_PER_SEC;
    CPU_CRITICAL_ENTER();
    NetARP_ReqTimeout_sec  =  timeout_sec;
    NetARP_ReqTimeout_tick =  tick;
    CPU_CRITICAL_EXIT();

    return (DEF_OK);
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                             NetARP_Rx()
*
* Description : (1) Process received ARP packets & update ARP Cache List :
*
*                   (a) Validate ARP packet
*                   (b) Update   ARP cache
*                   (c) Prepare & transmit an ARP Reply for a received ARP Request
*                   (d) Free ARP packet
*                   (e) Update receive statistics
*
*
* Argument(s) : pbuf        Pointer to network buffer that received ARP packet.
*
*               perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_ARP_ERR_NONE                ARP packet successfully received & processed.
*                               NET_ERR_INIT_INCOMPLETE         Network initialization NOT complete.
*
*                                                               ---- RETURNED BY NetARP_RxPktDiscard() : ----
*                               NET_ERR_RX                      Receive error; packet discarded.
*
* Return(s)   : none.
*
* Caller(s)   : NetIF_RxPktFrameDemux().
*
*               This function is a network protocol suite to network interface (IF) function & SHOULD be 
*               called only by appropriate network interface function(s).
*
* Note(s)     : (2) NetIP_Rx() blocked until network initialization completes; perform NO action.
*********************************************************************************************************
*/

void  NetARP_Rx (NET_BUF  *pbuf,
                 NET_ERR  *perr)
{
#if ((((NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)                    && \
       (NET_CTR_CFG_ERR_EN         == DEF_ENABLED))                   || \
       (NET_CTR_CFG_STAT_EN        == DEF_ENABLED))                   && \

⌨️ 快捷键说明

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