📄 net_arp.c
字号:
#endif
/* Free each ARP cache to cache pool (see Note #2). */
pcache->NextPtr = (void *)NetARP_CachePoolPtr;
NetARP_CachePoolPtr = (NET_ARP_CACHE *)pcache;
pcache++;
}
/* ------------- INIT ARP CACHE LIST PTRS ------------- */
NetARP_CacheListHead = (NET_ARP_CACHE *)0;
NetARP_CacheListTail = (NET_ARP_CACHE *)0;
/* ------------- INIT ARP HOST ADDR PTRS ------------- */
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_EXT_EN == DEF_ENABLED) || \
(NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED))
NetARP_ErrNullPtrCtr = 0;
#endif
#if (NET_ERR_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)
NetARP_ErrInvalidAddrLenHW_Ctr = 0;
NetARP_ErrInvalidAddrLenProtocolCtr = 0;
#endif
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
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) 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 pre-compute initial
* timeout value in 'NET_TMR_TICK' ticks.
*********************************************************************************************************
*/
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_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) Timeout in seconds converted to 'NET_TMR_TICK' ticks in order to pre-compute initial
* timeout value in 'NET_TMR_TICK' ticks.
*********************************************************************************************************
*/
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_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_ProbeAddrOnNet()
*
* Description : (1) Transmit an ARP Request to probe the local network for a specific protocol address :
*
* (a) Remove ARP cache with desired protocol address from ARP Cache List, if available
* (b) Configure ARP cache :
* (1) Get default-configured ARP cache
* (2) ARP cache state
* (c) Transmit ARP Request to probe local network for desired protocol address
*
*
* (2) NetARP_ProbeAddrOnNet() SHOULD be used in conjunction with NetARP_CacheGetAddrHW()
* to determine if a specific protocol address is available on the local network :
*
* (a) After successfully transmitting an ARP Request to probe the local network & ...
* (b) After some time delay(s) [on the order of ARP Request timeouts & retries]; ...
* (c) Check ARP Cache for the hardware address of a host on the local network that
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -