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

📄 net_arp.c

📁 ucos的tcpip协议占
💻 C
📖 第 1 页 / 共 5 页
字号:
                 break;


            case NET_ARP_CACHE_STATE_NONE:
            case NET_ARP_CACHE_STATE_FREE:
            default:
                 NetARP_CacheRemove(pcache, DEF_YES);
                 NetARP_CacheAddPend(pbuf, pbuf_hdr, paddr_protocol, perr);
                 break;
        }

    } else {                                                    /* Else add new ARP cache into ARP Cache List.          */
        NetARP_CacheAddPend(pbuf, pbuf_hdr, paddr_protocol, perr);
    }
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                       NetARP_CacheCalcStat()
*
* Description : (1) Calculate ARP statistics :
*
*                   (a) ARP cache found percentage
*
*
* Argument(s) : none.
*
* Return(s)   : ARP  cache found percentage, if NO errors,
*
*               NULL cache found percentage, otherwise.
*
* Caller(s)   : Application.
*
*               This function is a network protocol suite application interface (API) function & MAY be 
*               called by application function(s).
*
* Note(s)     : (2) NetARP_CacheCalcStat() blocked until network initialization completes; return NULL
*                   ARP cache found percentage.
*
*               (3) These ARP statistics calculation(s) are potentially expensive operations.  Recommended
*                   only from low-priority, background tasks.
*********************************************************************************************************
*/

CPU_INT08U  NetARP_CacheCalcStat (void)
{
#if (NET_CTR_CFG_STAT_EN     == DEF_ENABLED)
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR      cpu_sr;
#endif
    NET_CTR     pct_numer_hi;
    NET_CTR     pct_numer_lo;
    NET_CTR     pct_denom_hi;
    NET_CTR     pct_denom_lo;
#endif
    CPU_INT08U  pct;


#if (NET_ERR_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)
    if (Net_InitDone != DEF_YES) {                              /* If init NOT complete, ...                            */
        return (0);                                             /* ... rtn NULL pct (see Note #2).                      */
    }
#endif

                                                                /* ------------- CALC ARP CACHE FOUND PCT ------------- */
#if (NET_CTR_CFG_STAT_EN == DEF_ENABLED)
    CPU_CRITICAL_ENTER();
    pct_numer_hi = NetARP_CacheFoundCtr_hi;
    pct_numer_lo = NetARP_CacheFoundCtr_lo;
    pct_denom_hi = NetARP_CacheSrchCtr_hi;
    pct_denom_lo = NetARP_CacheSrchCtr_lo;
    CPU_CRITICAL_EXIT();

    pct = NetCtr_CalcPctLarge(pct_numer_hi,
                              pct_numer_lo,
                              pct_denom_hi,
                              pct_denom_lo);

    CPU_CRITICAL_ENTER();
    NetARP_CacheFoundPct = pct;
    CPU_CRITICAL_EXIT();

#else
    pct = 0;
#endif

    return (pct);
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                      NetARP_CachePoolStatGet()
*
* Description : Get ARP statistics pool.
*
* Argument(s) : none.
*
* Return(s)   : ARP  statistics pool, if NO errors.
*
*               NULL statistics pool, otherwise.
*
* Caller(s)   : Application.
*
*               This function is a network protocol suite application interface (API) function & MAY be 
*               called by application function(s).
*
* Note(s)     : (1) NetARP_CachePoolStatGet() blocked until network initialization completes; return NULL
*                   statistics pool.
*********************************************************************************************************
*/

NET_STAT_POOL  NetARP_CachePoolStatGet (void)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR         cpu_sr;
#endif
#if (NET_ERR_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)
    NET_ERR        err;
#endif
    NET_STAT_POOL  stat_pool;


#if (NET_ERR_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)
    if (Net_InitDone != DEF_YES) {                              /* If init NOT complete, ...                            */
        NetStat_PoolClr(&stat_pool, &err);
        return (stat_pool);                                     /* ... rtn NULL stat pool (see Note #1).                */
    }
#endif


    CPU_CRITICAL_ENTER();
    stat_pool = NetARP_CachePoolStat;
    CPU_CRITICAL_EXIT();

    return (stat_pool);
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                 NetARP_CachePoolStatResetMaxUsed()
*
* Description : Reset ARP statistics pool's maximum number of entries used.
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : Application.
*
*               This function is a network protocol suite application interface (API) function & MAY be 
*               called by application function(s).
*
* Note(s)     : none.
*********************************************************************************************************
*/

void  NetARP_CachePoolStatResetMaxUsed (void)
{
    NET_ERR  err;


    NetStat_PoolResetUsedMax(&NetARP_CachePoolStat, &err);
}


/*$PAGE*/
/*
*********************************************************************************************************
*********************************************************************************************************
*                                           LOCAL FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                      NetARP_RxPktValidateBuf()
*
* Description : Validate received buffer header as ARP protocol.
*
* Argument(s) : pbuf_hdr    Pointer to network buffer header that received ARP packet.
*               --------    Argument validated in NetARP_Rx().
*
*               perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_ARP_ERR_NONE                Received buffer's ARP header validated.
*                               NET_ERR_INVALID_PROTOCOL        Buffer's protocol type is NOT ARP.
*                               NET_BUF_ERR_INVALID_IX          Invalid buffer index.
*
* Return(s)   : none.
*
* Caller(s)   : NetARP_Rx().
*
* Note(s)     : none.
*********************************************************************************************************
*/

#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
static  void  NetARP_RxPktValidateBuf (NET_BUF_HDR  *pbuf_hdr,
                                       NET_ERR      *perr)
{
#if ((NET_CTR_CFG_ERR_EN      == DEF_ENABLED)                    && \
     (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL))
    CPU_SR  cpu_sr;
#endif

                                                                /* --------------- VALIDATE ARP BUF HDR --------------- */
    if (pbuf_hdr->ProtocolHdrType != NET_PROTOCOL_TYPE_ARP) {
        NET_CTR_ERR_INC(Net_ErrInvalidProtocolCtr);
       *perr = NET_ERR_INVALID_PROTOCOL;
        return;
    }

    if (pbuf_hdr->ARP_MsgIx == NET_BUF_IX_NONE) {
        NET_CTR_ERR_INC(NetARP_ErrRxInvalidBufIxCtr);
       *perr = NET_BUF_ERR_INVALID_IX;
        return;
    }

   *perr = NET_ARP_ERR_NONE;
}
#endif


/*$PAGE*/
/*
*********************************************************************************************************
*                                       NetARP_RxPktValidate()
*
* Description : (1) Validate received ARP packet :
*
*                   (a) Convert the following ARP header fields from network-order to host-order :
*
*                       (1) Hardware  Type
*                       (2) Protocol  Type
*                       (3) Operation Code                                  See Note #1aB
*
*                           (A) These fields are NOT converted directly in the received packet buffer's 
*                               data area but are converted in local or network buffer variables ONLY.
*
*                           (B) To avoid storing the ARP operation code in a network buffer variable & 
*                               passing an additional pointer to the network buffer header that received 
*                               ARP packet, ARP operation code is converted in the following functions :
*
*                               (1) NetARP_RxPktValidate()
*                               (2) NetARP_RxPktCacheUpdate()
*                               (3) NetARP_RxPktReply()
*                               (4) NetARP_RxPktIsTargetThisHost()
*
*                           (C) Hardware & Protocol Addresses are NOT converted from network-order to 
*                               host-order & MUST be accessed as multi-octet arrays.
*
*                   (b) Validate the received packet's following ARP header fields :
*
*                       (1) Hardware  Type
*                       (2) Hardware  Address Length
*                       (3) Hardware  Address : Sender's
*                       (4) Protocol  Type
*                       (5) Protocol  Address Length
*                       (6) Protocol  Address : Sender's
*                       (7) Operation Code
*
*                   (c) Update network buffer's length controls.
*
*                   (d) Validate ARP message length :
*
*                       (1) The ARP message length is compared to the remaining packet length which should
*                           be identical.
*
*                       (2) However, some network interface frame types append 'pad' octets (octets with a
*                           dummy value to be ignored) if the data length for the frame does NOT meet the
*                           frame's required minimum size.  Thus, if the ARP message length is NOT greater
*                           than the frame's minimum size, then pad octets were appended & the ARP message
*                           length CANNOT be compared.
*
*
* Argument(s) : pbuf_hdr    Pointer to network buffer header that received ARP packet.
*               --------    Argument validated in NetARP_Rx().
*
*               parp_hdr    Pointer to received packet's ARP header.
*               --------    Argument validated in NetARP_Rx()/NetARP_RxPktValidateBuf().
*
*               perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_ARP_ERR_NONE                        Received packet validated.
*                               NET_ARP_ERR_INVALID_HW_TYPE             Invalid ARP hardware type.
*                               NET_ARP_ERR_INVALID_HW_LEN              Invalid ARP hardware address length.
*                               NET_ARP_ERR_INVALID_HW_ADDR             Invalid ARP hardware address.
*                               NET_ARP_ERR_INVALID_PROTOCOL_TYPE       Invalid ARP protocol type.
*                               NET_ARP_ERR_INVALID_PROTOCOL_LEN        Invalid ARP protocol length.
*                               NET_ARP_ERR_INVALID_PROTOCOL_ADDR       Invalid ARP protocol address.
*                               NET_ARP_ERR_INVALID_OP_CODE             Invalid ARP operation code.

⌨️ 快捷键说明

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