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

📄 net_ip.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 IP LAYER
*                                         (INTERNET PROTOCOL)
*
* Filename      : net_ip.c
* Version       : V1.87
* Programmer(s) : ITJ
*********************************************************************************************************
* Note(s)       : (1) Supports Internet Protocol as described in RFC #791, also known as IPv4, with the
*                     following restrictions/constraints :
*
*                     (a) ONLY supports a single network interface/            RFC # 791, Section 2.3
*                            host IP address                                                'Addressing'
*
*                     (b) ONLY supports a single default gateway               RFC #1122, Section 3.3.1
*
*                     (c) IP forwarding/routing  NOT           supported       RFC #1122, Sections 3.3.1,
*                                                                                            3.3.4 & 3.3.5
*
*                     (d) IP multicasting        NOT           supported       RFC #1122, Section 3.3.7
*
*                     (e) Transmit fragmentation NOT currently supported       RFC # 791, Section 2.3
*                                                                                           'Fragmentation & 
*                                                                                              Reassembly'
*                     (f) IP Security options    NOT currently supported       RFC #1108
*********************************************************************************************************
*/

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

#define    NET_IP_MODULE
#include  <net.h>


/*$PAGE*/
/*
*********************************************************************************************************
*                                            LOCAL DEFINES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                           LOCAL CONSTANTS
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                          LOCAL DATA TYPES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                            LOCAL TABLES
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                       LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/


/*$PAGE*/
/*
*********************************************************************************************************
*                                      LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/

                                                                            /* -------- VALIDATE RX DATAGRAMS --------- */

#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
static  void          NetIP_RxPktValidateBuf        (NET_BUF_HDR   *pbuf_hdr,
                                                     NET_ERR       *perr);
#endif

static  void          NetIP_RxPktValidate           (NET_BUF       *pbuf,
                                                     NET_BUF_HDR   *pbuf_hdr,
                                                     NET_IP_HDR    *pip_hdr,
                                                     NET_ERR       *perr);

static  void          NetIP_RxPktValidateOpt        (NET_BUF       *pbuf,
                                                     NET_BUF_HDR   *pbuf_hdr,
                                                     NET_IP_HDR    *pip_hdr,
                                                     CPU_INT08U     ip_hdr_len_size,
                                                     NET_ERR       *perr);

static  CPU_BOOLEAN   NetIP_RxPktValidateOptRoute   (CPU_INT08U    *popts,
                                                     CPU_INT08U     opt_list_len_rem,
                                                     CPU_INT08U    *popt_len,
                                                     NET_ERR       *perr);

static  CPU_BOOLEAN   NetIP_RxPktValidateOptTS      (CPU_INT08U    *popts,
                                                     CPU_INT08U     opt_list_len_rem,
                                                     CPU_INT08U    *popt_len,
                                                     NET_ERR       *perr);


                                                                            /* ------------ REASM RX FRAGS ------------ */

static  NET_BUF      *NetIP_RxPktFragReasm          (NET_BUF       *pbuf,
                                                     NET_BUF_HDR   *pbuf_hdr,
                                                     NET_IP_HDR    *pip_hdr,
                                                     NET_ERR       *perr);

static  NET_BUF      *NetIP_RxPktFragListAdd        (NET_BUF       *pbuf,
                                                     NET_BUF_HDR   *pbuf_hdr,
                                                     CPU_INT16U     frag_ip_flags,
                                                     CPU_INT16U     frag_offset,
                                                     CPU_INT16U     frag_size,
                                                     NET_ERR       *perr);

static  NET_BUF      *NetIP_RxPktFragListInsert     (NET_BUF       *pbuf,
                                                     NET_BUF_HDR   *pbuf_hdr,
                                                     CPU_INT16U     frag_ip_flags,
                                                     CPU_INT16U     frag_offset,
                                                     CPU_INT16U     frag_size,
                                                     NET_BUF       *pfrag_list,
                                                     NET_ERR       *perr);

static  void          NetIP_RxPktFragListRemove     (NET_BUF       *pfrag_list,
                                                     CPU_BOOLEAN    tmr_free);

static  void          NetIP_RxPktFragListDiscard    (NET_BUF       *pfrag_list,
                                                     CPU_BOOLEAN    tmr_free,
                                                     NET_ERR       *perr);

static  void          NetIP_RxPktFragListUpdate     (NET_BUF_HDR   *pfrag_list_buf_hdr,
                                                     CPU_INT16U     frag_ip_flags,
                                                     CPU_INT16U     frag_offset,
                                                     CPU_INT16U     frag_size);

static  NET_BUF      *NetIP_RxPktFragListChkComplete(NET_BUF       *pfrag_list,
                                                     NET_BUF_HDR   *pfrag_list_buf_hdr,
                                                     NET_ERR       *perr);

static  void          NetIP_RxPktFragTimeout        (void          *pfrag_list_timeout);


                                                                            /* ---------- DEMUX RX DATAGRAMS ---------- */

static  void          NetIP_RxPktDemuxDatagram      (NET_BUF       *pbuf,
                                                     NET_BUF_HDR   *pbuf_hdr,
                                                     NET_ERR       *perr);



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


/*$PAGE*/
                                                                            /* ----------- VALIDATE TX PKTS ----------- */

#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
static  void          NetIP_TxPktValidate           (NET_BUF       *pbuf,
                                                     NET_BUF_HDR   *pbuf_hdr,
                                                     NET_IP_ADDR    addr_src,
                                                     NET_IP_ADDR    addr_dest,
                                                     NET_IP_TOS     TOS,
                                                     NET_IP_TTL     TTL,
                                                     CPU_INT16U     flags,
                                                     void          *popts,
                                                     NET_ERR       *perr);

static  void          NetIP_TxPktValidateOpt        (void          *popts,
                                                     NET_ERR       *perr);

static  void          NetIP_TxPktValidateOptRouteTS (void          *popt_route_ts,
                                                     CPU_INT08U    *popt_len,
                                                     void         **popt_next,
                                                     NET_ERR       *perr);
#endif

                                                                            /* -------------- TX IP PKTS -------------- */

static  void          NetIP_TxPkt                   (NET_BUF       *pbuf,
                                                     NET_BUF_HDR   *pbuf_hdr,
                                                     NET_IP_ADDR    addr_src,
                                                     NET_IP_ADDR    addr_dest,
                                                     NET_IP_TOS     TOS,
                                                     NET_IP_TTL     TTL,
                                                     CPU_INT16U     flags,
                                                     void          *popts,
                                                     NET_ERR       *perr);

static  CPU_INT08U    NetIP_TxPktPrepareOpt         (NET_BUF       *pbuf,
                                                     NET_BUF_HDR   *pbuf_hdr,
                                                     void          *popts,
                                                     CPU_INT08U    *popt_hdr,
                                                     NET_ERR       *perr);

static  void          NetIP_TxPktPrepareOptRoute    (void          *popts,
                                                     CPU_INT08U    *popt_hdr,
                                                     CPU_INT08U    *popt_len,
                                                     void         **popt_next,
                                                     NET_ERR       *perr);

static  void          NetIP_TxPktPrepareOptTS       (void          *popts,
                                                     CPU_INT08U    *popt_hdr,
                                                     CPU_INT08U    *popt_len,
                                                     void         **popt_next,
                                                     NET_ERR       *perr);

static  void          NetIP_TxPktPrepareOptTSRoute  (void          *popts,
                                                     CPU_INT08U    *popt_hdr,
                                                     CPU_INT08U    *popt_len,
                                                     void         **popt_next,
                                                     NET_ERR       *perr);

static  void          NetIP_TxPktPrepareHdr         (NET_BUF       *pbuf,
                                                     NET_BUF_HDR   *pbuf_hdr,
                                                     CPU_INT16U     ip_hdr_len_tot,
                                                     CPU_INT08U     ip_opt_len_tot,
                                                     CPU_INT16U     protocol_ix,
                                                     NET_IP_ADDR    addr_src,
                                                     NET_IP_ADDR    addr_dest,
                                                     NET_IP_TOS     TOS,
                                                     NET_IP_TTL     TTL,
                                                     CPU_INT16U     flags,
                                                     CPU_INT32U    *pip_hdr_opts,
                                                     NET_ERR       *perr);


                                                                            /* ------------ TX IP DATAGRAMS ----------- */

static  void          NetIP_TxPktDatagram           (NET_BUF       *pbuf,
                                                     NET_BUF_HDR   *pbuf_hdr,
                                                     NET_ERR       *perr);

static  void          NetIP_TxPktDatagramNextHopSel (NET_BUF_HDR   *pbuf_hdr,
                                                     NET_ERR       *perr);



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


/*$PAGE*/
                                                                            /* ------------ RE-TX IP PKTS ------------- */

static  void          NetIP_ReTxPkt                 (NET_BUF       *pbuf,
                                                     NET_BUF_HDR   *pbuf_hdr,
                                                     NET_ERR       *perr);

static  void          NetIP_ReTxPktPrepareHdr       (NET_BUF       *pbuf,
                                                     NET_BUF_HDR   *pbuf_hdr,
                                                     NET_ERR       *perr);


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


/*$PAGE*/
/*
*********************************************************************************************************
*                                            NetIP_Init()
*

⌨️ 快捷键说明

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