📄 net_arp.h
字号:
#define NET_ARP_HDR_OP_REQ 0x0001
#define NET_ARP_HDR_OP_REPLY 0x0002
#define NET_ARP_MSG_LEN NET_ARP_HDR_SIZE
#define NET_ARP_MSG_LEN_DATA 0
/*$PAGE*/
/*
*********************************************************************************************************
* ARP CACHE STATES
*
* (1) (2)
* ARP REQUEST ARP REPLY
* ---------- FETCHES NEW ----------- RESOLVES ------------
* | | ARP CACHE | | ARP CACHE | |
* | FREE | -----------------> | PENDING | -----------------> | RESOLVED |
* | | | | | |
* ---------- (3) ----------- ------------
* ^ ^ ARP REQUEST | |
* | | TIMES OUT | |
* | | AFTER RETRIES | (4) |
* | ------------------------------ ARP CACHE |
* | TIMES OUT |
* -----------------------------------------------------------------
*
*
* Note(s) : (1) ARP cache lookup fails to find the ARP cache with corresponding protocol address. A new
* ARP cache is allocated from the ARP cache pool & inserted into the ARP Cache List in the
* 'PENDING' state. An ARP Request is generated & transmitted to resolve the pending ARP cache.
*
* (2) An ARP Reply resolves the pending ARP cache's hardware address.
*
* (3) Alternatively, no corresponding ARP Reply is received after the maximum number of ARP
* Request retries & the ARP cache is freed.
*
* (4) ARP cache times out & is freed.
*********************************************************************************************************
*/
#define NET_ARP_CACHE_STATE_NONE 0
#define NET_ARP_CACHE_STATE_FREE 1
#define NET_ARP_CACHE_STATE_PEND 2
#define NET_ARP_CACHE_STATE_RESOLVED 3
/*$PAGE*/
/*
*********************************************************************************************************
* DATA TYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* ARP CACHE QUANTITY DATA TYPE
*********************************************************************************************************
*/
typedef CPU_INT16U NET_ARP_CACHE_QTY; /* Defines max qty of ARP caches to support. */
/*
*********************************************************************************************************
* ARP CACHE STATE DATA TYPE
*********************************************************************************************************
*/
typedef CPU_INT08U NET_ARP_CACHE_STATE;
/*
*********************************************************************************************************
* ARP HEADER
*
* Note(s) : (1) See RFC #826, Section 'Packet Format' for ARP packet header format.
*
* (2) See 'ARP HEADER / MESSAGE DEFINES'.
*********************************************************************************************************
*/
/* --------------- NET ARP HDR ---------------- */
typedef struct net_arp_hdr {
CPU_INT16U HW_Type; /* ARP pkt hw type. */
CPU_INT16U ProtocolType; /* ARP pkt protocol type. */
CPU_INT08U HW_AddrLen; /* ARP pkt hw addr len (in octets). */
CPU_INT08U ProtocolAddrLen; /* ARP pkt protocol addr len (in octets). */
CPU_INT16U OpCode; /* ARP op code (see Note #2). */
CPU_INT08U HW_AddrSender[NET_ARP_CFG_HW_ADDR_LEN]; /* Sender hw addr. */
CPU_INT08U ProtocolAddrSender[NET_ARP_CFG_PROTOCOL_ADDR_LEN]; /* Sender protocol addr. */
CPU_INT08U HW_AddrTarget[NET_ARP_CFG_HW_ADDR_LEN]; /* Target hw addr. */
CPU_INT08U ProtocolAddrTarget[NET_ARP_CFG_PROTOCOL_ADDR_LEN]; /* Target protocol addr. */
} NET_ARP_HDR;
/*$PAGE*/
/*
*********************************************************************************************************
* ARP CACHE ENTRY DATA TYPE
*
* NET_ARP_CACHE
* |-------------|
* | Cache Type |
* Previous |-------------|
* Cache <----------O |
* |-------------| Next
* | O----------> Cache Buffer Queue
* |-------------| Head -------
* | O------------------------------------> | |
* |-------------| | |
* | O---------------------- -------
* |-------------| | | ^
* | O----------> Cache | v |
* |-------------| Timer | -------
* | Hardware: | | | |
* | Type | | | |
* | Length | | -------
* | Address | | | ^
* |-------------| | Buffer Queue v |
* | Protocol: | | Tail -------
* | Type | ---------------> | |
* | Length | | |
* | Address | -------
* |-------------|
* | Flags |
* |-------------|
* | Accessed |
* | Counter |
* |-------------|
* | Request |
* | Counter |
* |-------------|
* | State |
* |-------------|
*
*
* Note(s) : (1) Forced word-alignment at start of ARP cache NOT required since first data member
* 'Type' is declared as 'CPU_INT32U'.
*
* (2) 'PrevPtr'/'NextPtr' ideally declared as 'NET_ARP_CACHE' pointers; declared as 'void'
* pointers because 'NET_ARP_CACHE' NOT fully defined at time of declaration.
*
* (3) These fields are configured by the developer via 'net_cfg_net.h' at compile time.
*
* See 'net_arp.h Note #2' & 'ARP HARDWARE & PROTOCOL DEFINES Note #1' for supported
* hardware & protocol types.
*********************************************************************************************************
*/
/* --------------- NET ARP CACHE -------------- */
typedef struct net_arp_cache {
NET_TYPE Type; /* Type cfg'd @ init : NET_ARP_TYPE_CACHE. */
void *PrevPtr; /* Ptr to PREV ARP cache. */
void *NextPtr; /* Ptr to NEXT ARP cache. */
NET_BUF *BufQ_Head; /* Ptr to head of cache's buf Q. */
NET_BUF *BufQ_Tail; /* Ptr to tail of cache's buf Q. */
NET_TMR *TmrPtr; /* Ptr to cache TMR. */
CPU_INT16U HW_Type; /* HW type (see Note #3). */
CPU_INT08U HW_AddrLen; /* HW addr len (see Note #3). */
CPU_INT08U HW_Addr[NET_ARP_CFG_HW_ADDR_LEN]; /* HW addr. */
CPU_INT16U ProtocolType; /* Protocol type (see Note #3). */
CPU_INT08U ProtocolAddrLen; /* Protocol addr len (see Note #3). */
CPU_INT08U ProtocolAddr[NET_ARP_CFG_PROTOCOL_ADDR_LEN]; /* Protocol addr. */
CPU_INT16U Flags; /* ARP cache flags. */
CPU_INT16U AccessedCtr; /* Nbr successful srchs. */
CPU_INT08U ReqAttemptsCtr; /* ARP req attempts ctr. */
NET_ARP_CACHE_STATE State; /* Cur cache state. */
} NET_ARP_CACHE;
/*$PAGE*/
/*
*********************************************************************************************************
* GLOBAL VARIABLES
*********************************************************************************************************
*/
NET_ARP_EXT CPU_INT08U *NetARP_HostAddrPtrHW; /* Ptr to host's hw addr. */
NET_ARP_EXT CPU_INT08U *NetARP_HostAddrPtrProtocol; /* Ptr to host's protocol addr. */
NET_ARP_EXT NET_ARP_CACHE NetARP_CacheTbl[NET_ARP_CFG_NBR_CACHE];
NET_ARP_EXT NET_ARP_CACHE *NetARP_CachePoolPtr; /* Ptr to pool of free ARP caches. */
NET_ARP_EXT NET_STAT_POOL NetARP_CachePoolStat;
#if (NET_CTR_CFG_STAT_EN == DEF_ENABLED)
NET_ARP_EXT NET_CTR NetARP_CacheSrchCtr_lo; /* Inc'd for EVERY cache lookup (lo ctr). */
NET_ARP_EXT NET_CTR NetARP_CacheSrchCtr_hi; /* Cache lookup hi ctr. */
NET_ARP_EXT NET_CTR NetARP_CacheFoundCtr_lo; /* Inc'd for EVERY cache found (lo ctr). */
NET_ARP_EXT NET_CTR NetARP_CacheFoundCtr_hi; /* Cache found hi ctr. */
NET_ARP_EXT CPU_INT08U NetARP_CacheFoundPct; /* Found % = (FoundCtr / SrchCtr) * 100% */
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -