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

📄 net_arp.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 ARP LAYER
*                                    (ADDRESS RESOLUTION PROTOCOL)
*
* Filename      : net_arp.c
* Version       : V1.87
* Programmer(s) : ITJ
*********************************************************************************************************
* Note(s)       : (1) Address Resolution Protocol ONLY required for network interfaces that require
*                     network-address-to-hardware-address bindings (see RFC #826 'Abstract').
*
*                 (2) Supports Address Resolution Protocol as described in RFC #826 with the following
*                     restrictions/constraints :
*
*                     (a) ONLY supports the following hardware types :
*                         (1) 48-bit Ethernet
*
*                     (b) ONLY supports the following protocol types :
*                         (1) 32-bit IP
*********************************************************************************************************
*/

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

#define    NET_ARP_MODULE
#include  <net.h>


/*
*********************************************************************************************************
*                                               MODULE
*
* Note(s) : (1) See 'net_arp.h  MODULE'.
*********************************************************************************************************
*/

#ifdef  NET_ARP_MODULE_PRESENT


/*$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            NetARP_RxPktValidateBuf     (NET_BUF_HDR    *pbuf_hdr,
                                                     NET_ERR        *perr);
#endif

static  void            NetARP_RxPktValidate        (NET_BUF_HDR    *pbuf_hdr,
                                                     NET_ARP_HDR    *parp_hdr,
                                                     NET_ERR        *perr);

static  void            NetARP_RxPktCacheUpdate     (NET_ARP_HDR    *parp_hdr,
                                                     NET_ERR        *perr);

static  void            NetARP_RxPktReply           (NET_ARP_HDR    *parp_hdr,
                                                     NET_ERR        *perr);

static  void            NetARP_RxPktIsTargetThisHost(NET_ARP_HDR    *parp_hdr,
                                                     NET_ERR        *perr);

static  void            NetARP_RxPktFree            (NET_BUF        *pbuf);

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

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

static  void            NetARP_Tx                   (CPU_INT08U     *paddr_hw_sender,
                                                     CPU_INT08U     *paddr_hw_target,
                                                     CPU_INT08U     *paddr_protocol_sender,
                                                     CPU_INT08U     *paddr_protocol_target,
                                                     CPU_INT16U      op_code,
                                                     NET_ERR        *perr);

static  void            NetARP_TxReq                (NET_ARP_CACHE  *pcache);

static  void            NetARP_TxReply              (NET_ARP_HDR    *parp_hdr);

static  void            NetARP_TxPktPrepareHdr      (NET_BUF        *pbuf,
                                                     CPU_INT16U      msg_ix,
                                                     CPU_INT08U     *paddr_hw_sender,
                                                     CPU_INT08U     *paddr_hw_target,
                                                     CPU_INT08U     *paddr_protocol_sender,
                                                     CPU_INT08U     *paddr_protocol_target,
                                                     CPU_INT16U      op_code,
                                                     NET_ERR        *perr);

static  void            NetARP_TxPktFree            (NET_BUF        *pbuf);

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


/*$PAGE*/
                                                                            /* ----------- ARP CACHE FNCTS ------------ */

static  void            NetARP_CacheTxPktHandler    (NET_BUF        *pbuf_q,
                                                     CPU_INT08U     *paddr_hw);

static  NET_ARP_CACHE  *NetARP_CacheSrch            (CPU_INT08U     *paddr_protocol);

static  void            NetARP_CacheAddPend         (NET_BUF        *pbuf,
                                                     NET_BUF_HDR    *pbuf_hdr,
                                                     CPU_INT08U     *paddr_protocol,
                                                     NET_ERR        *perr);

static  void            NetARP_CacheAddResolved     (CPU_INT08U     *paddr_hw,
                                                     CPU_INT08U     *paddr_protocol,
                                                     NET_ERR        *perr);


static  void            NetARP_CacheRemove          (NET_ARP_CACHE  *pcache,
                                                     CPU_BOOLEAN     tmr_free);

static  void            NetARP_CacheInsert          (NET_ARP_CACHE  *pcache);

static  void            NetARP_CacheUnlink          (NET_ARP_CACHE  *pcache);


static  void            NetARP_CacheReqTimeout      (void           *pcache_timeout);

static  void            NetARP_CacheTimeout         (void           *pcache_timeout);


static  NET_ARP_CACHE  *NetARP_CacheGet             (NET_ERR        *perr);

static  void            NetARP_CacheFree            (NET_ARP_CACHE  *pcache,
                                                     CPU_BOOLEAN     tmr_free);

static  void            NetARP_CacheUnlinkBuf       (NET_BUF        *pbuf);

static  void            NetARP_CacheClr             (NET_ARP_CACHE  *pcache);

#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
static  CPU_BOOLEAN     NetARP_CacheIsUsed          (NET_ARP_CACHE  *pcache);

static  void            NetARP_CacheDiscard         (NET_ARP_CACHE  *pcache);
#endif


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


/*$PAGE*/
/*
*********************************************************************************************************
*                                            NetARP_Init()
*
* Description : (1) Initialize Address Resolution Protocol :
*
*                   (a) Initialize ARP cache pool
*                   (b) Initialize ARP cache table
*                   (c) Initialize ARP cache list pointers
*                   (d) Initialize ARP host address pointers
*                   (e) Initialize ARP statistics & error counters
*
*
* Argument(s) : none.
*
* Return(s)   : none.
*
* Caller(s)   : NetIF_Init().
*
*               This function is a network protocol suite to network interface (IF) function & SHOULD be 
*               called only by appropriate network interface initialization function(s).
*
* Note(s)     : (2) ARP cache pool MUST be initialized PRIOR to initializing the pool with pointers to
*                   ARP caches.
*********************************************************************************************************
*/

void  NetARP_Init (void)
{
    NET_ARP_CACHE      *pcache;
    NET_ARP_CACHE_QTY   i;
    NET_ERR             stat_err;


                                                                /* ------------ INIT ARP CACHE POOL/STATS ------------- */
    NetARP_CachePoolPtr = (NET_ARP_CACHE *)0;                   /* See Note #2.                                         */

    NetStat_PoolInit((NET_STAT_POOL   *)&NetARP_CachePoolStat,
                     (NET_STAT_POOL_QTY) NET_ARP_CFG_NBR_CACHE,
                     (NET_ERR         *)&stat_err);

#if (NET_CTR_CFG_STAT_EN == DEF_ENABLED)
    NetARP_CacheSrchCtr_lo  = 0;
    NetARP_CacheSrchCtr_hi  = 0;
    NetARP_CacheFoundCtr_lo = 0;
    NetARP_CacheFoundCtr_hi = 0;
    NetARP_CacheFoundPct    = 0;
#endif

                                                                /* ---------------- INIT ARP CACHE TBL ---------------- */
    pcache = &NetARP_CacheTbl[0];
    for (i = 0; i < NET_ARP_CFG_NBR_CACHE; i++) {
                                                                /* Init each ARP cache type/addr len--NEVER modify.     */
        pcache->Type            =  NET_ARP_TYPE_CACHE;
        pcache->HW_Type         =  NET_ARP_CFG_HW_TYPE;
        pcache->HW_AddrLen      =  NET_ARP_CFG_HW_ADDR_LEN;
        pcache->ProtocolType    =  NET_ARP_CFG_PROTOCOL_TYPE;
        pcache->ProtocolAddrLen =  NET_ARP_CFG_PROTOCOL_ADDR_LEN;

        pcache->State           =  NET_ARP_CACHE_STATE_FREE;    /* Init each ARP cache as free/NOT used.                */
        pcache->Flags           =  NET_ARP_FLAG_NONE;

#if (NET_DBG_CFG_MEM_CLR_EN == DEF_ENABLED)
        NetARP_CacheClr(pcache);
#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 ------------- */

⌨️ 快捷键说明

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