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

📄 net_ip.c

📁 ucos+lwip用于AT91SAM7X256
💻 C
📖 第 1 页 / 共 5 页
字号:
*
* Note(s)     : (2) NetIP_Tx() blocked until network initialization completes; perform NO action.
*
*               (3) Network buffer already freed by lower layer; only increment error counter.
*********************************************************************************************************
*/
/*$PAGE*/
void  NetIP_Tx (NET_BUF      *pbuf,
                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)
{
#if (((NET_CTR_CFG_STAT_EN     == DEF_ENABLED)                    || \
      (NET_CTR_CFG_ERR_EN      == DEF_ENABLED))                   && \
      (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL))
    CPU_SR        cpu_sr;
#endif
    NET_BUF_HDR  *pbuf_hdr;


#if (NET_ERR_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)
    if (Net_InitDone != DEF_YES) {                              /* If init NOT complete, exit tx (see Note #2).         */
        NetIP_TxPktDiscard(pbuf, perr);
       *perr = NET_ERR_INIT_INCOMPLETE;
        return;
    }
#endif


#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
                                                                /* ------------------- VALIDATE PTR ------------------- */
    if (pbuf == (NET_BUF *)0) {
        NetIP_TxPktDiscard(pbuf, perr);
        NET_CTR_ERR_INC(NetIP_ErrNullPtrCtr);
        return;
    }
#endif


                                                                /* ---------------- VALIDATE TX IP PKT ---------------- */
    pbuf_hdr = &pbuf->Hdr;
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
    NetIP_TxPktValidate(pbuf,
                        pbuf_hdr,
                        addr_src,
                        addr_dest,
                        TOS,
                        TTL,
                        flags,
                        popts,
                        perr);
    switch (*perr) {
        case NET_IP_ERR_NONE:
             break;


        case NET_ERR_INVALID_PROTOCOL:
        case NET_BUF_ERR_INVALID_IX:
        case NET_IP_ERR_INVALID_LEN_DATA:
        case NET_IP_ERR_INVALID_TOS:
        case NET_IP_ERR_INVALID_ADDR_SRC:
        case NET_IP_ERR_INVALID_ADDR_DEST:
        case NET_IP_ERR_INVALID_FLAG:
        case NET_IP_ERR_INVALID_OPT_TYPE:
        case NET_IP_ERR_INVALID_OPT_LEN:
        case NET_IP_ERR_INVALID_OPT_CFG:
        case NET_IP_ERR_INVALID_OPT_ROUTE:
        default:
             NetIP_TxPktDiscard(pbuf, perr);
             return;                                            /* Prevent 'break NOT reachable' compiler warning.      */
    }
#endif


/*$PAGE*/
                                                                /* -------------------- TX IP PKT --------------------- */
    NetIP_TxPkt(pbuf,
                pbuf_hdr,
                addr_src,
                addr_dest,
                TOS,
                TTL,
                flags,
                popts,
                perr);


                                                                /* ----------------- UPDATE TX STATS ------------------ */
    switch (*perr) {
        case NET_IP_ERR_NONE:
        case NET_IF_ERR_NONE:
             NET_CTR_STAT_INC(NetIP_StatTxDatagramCtr);
            *perr = NET_IP_ERR_NONE;
             break;


        case NET_ERR_INIT_INCOMPLETE:
        case NET_ERR_RX:
        case NET_ERR_TX:
             NET_CTR_ERR_INC(NetIP_ErrTxPktDiscardedCtr);       /* See Note #3.                                         */
            *perr = NET_ERR_TX;
             return;                                            /* Prevent 'break NOT reachable' compiler warning.      */


        case NET_ERR_INVALID_PROTOCOL:
        case NET_IP_ERR_INVALID_LEN_HDR:
        case NET_IP_ERR_INVALID_FRAG:
        case NET_IP_ERR_INVALID_OPT_TYPE:
        case NET_IP_ERR_INVALID_OPT_LEN:
        case NET_IP_ERR_TX_DEST_INVALID:
        case NET_IP_ERR_INVALID_ADDR_HOST:
        case NET_IP_ERR_INVALID_ADDR_NET:
        case NET_IP_ERR_INVALID_ADDR_GATEWAY:
        case NET_BUF_ERR_INVALID_IX:
        case NET_BUF_ERR_INVALID_LEN:
        case NET_UTIL_ERR_NULL_PTR:
        case NET_UTIL_ERR_NULL_SIZE:
        default:
             NetIP_TxPktDiscard(pbuf, perr);
             return;                                            /* Prevent 'break NOT reachable' compiler warning.      */
    }
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                            NetIP_ReTx()
*
* Description : (1) Prepare & re-transmit packets from transport protocol layers to network interface layer :
*
*                   (a) Validate  re-transmit packet
*                   (b) Prepare & re-transmit packet datagram
*                   (c) Update    re-transmit statistics
*
*
* Argument(s) : pbuf        Pointer to network buffer to re-transmit IP packet.
*
*               perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_IP_ERR_NONE                 IP datagram(s) successfully prepared & re-transmitted
*                                                                   to network interface layer.
*                               NET_ERR_INIT_INCOMPLETE         Network initialization NOT complete.
*
*                                                               -------- RETURNED BY NetIP_TxPktDiscard() : ---------
*                               NET_ERR_TX                      Transmit error; packet discarded.
*
* Return(s)   : none.
*
* Caller(s)   : NetTCP_TxConnReTxQ_Timeout().
*
* Note(s)     : (2) NetIP_ReTx() blocked until network initialization completes; perform NO action.
*
*               (3) Network buffer already freed by lower layer; only increment error counter.
*********************************************************************************************************
*/
/*$PAGE*/
void  NetIP_ReTx (NET_BUF  *pbuf,
                  NET_ERR  *perr)
{
#if (((NET_CTR_CFG_STAT_EN     == DEF_ENABLED)                    || \
      (NET_CTR_CFG_ERR_EN      == DEF_ENABLED))                   && \
      (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL))
    CPU_SR        cpu_sr;
#endif
    NET_BUF_HDR  *pbuf_hdr;


#if (NET_ERR_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)
    if (Net_InitDone != DEF_YES) {                              /* If init NOT complete, exit tx (see Note #2).         */
        NetIP_TxPktDiscard(pbuf, perr);
       *perr = NET_ERR_INIT_INCOMPLETE;
        return;
    }
#endif


#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
                                                                /* ------------------- VALIDATE PTR ------------------- */
    if (pbuf == (NET_BUF *)0) {
        NetIP_TxPktDiscard(pbuf, perr);
        NET_CTR_ERR_INC(NetIP_ErrNullPtrCtr);
        return;
    }
#endif


                                                                /* -------------- VALIDATE RE-TX IP PKT --------------- */
    pbuf_hdr = &pbuf->Hdr;
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
    if (pbuf_hdr->IP_HdrIx == NET_BUF_IX_NONE) {
        NetIP_TxPktDiscard(pbuf, perr);
        NET_CTR_ERR_INC(NetIP_ErrTxInvalidBufIxCtr);
        return;
    }
#endif


                                                                /* ------------------- RE-TX IP PKT ------------------- */
    NetIP_ReTxPkt(pbuf,
                  pbuf_hdr,
                  perr);


                                                                /* ---------------- UPDATE RE-TX STATS ---------------- */
    switch (*perr) {
        case NET_IP_ERR_NONE:
        case NET_IF_ERR_NONE:
             NET_CTR_STAT_INC(NetIP_StatTxDatagramCtr);
            *perr = NET_IP_ERR_NONE;
             break;


        case NET_ERR_INIT_INCOMPLETE:
        case NET_ERR_RX:
        case NET_ERR_TX:
             NET_CTR_ERR_INC(NetIP_ErrTxPktDiscardedCtr);       /* See Note #3.                                         */
            *perr = NET_ERR_TX;
             return;                                            /* Prevent 'break NOT reachable' compiler warning.      */


        case NET_IP_ERR_TX_DEST_INVALID:
        case NET_IP_ERR_INVALID_ADDR_HOST:
        case NET_IP_ERR_INVALID_ADDR_NET:
        case NET_IP_ERR_INVALID_ADDR_GATEWAY:
        case NET_UTIL_ERR_NULL_PTR:
        case NET_UTIL_ERR_NULL_SIZE:
        default:
             NetIP_TxPktDiscard(pbuf, perr);
             return;                                            /* Prevent 'break NOT reachable' compiler warning.      */
    }
}


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

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

#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
static  void  NetIP_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 IP BUF HDR --------------- */
    if (pbuf_hdr->ProtocolHdrType != NET_PROTOCOL_TYPE_IP) {
        NET_CTR_ERR_INC(Net_ErrInvalidProtocolCtr);
       *perr = NET_ERR_INVALID_PROTOCOL;
        return;
    }

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

   *perr = NET_IP_ERR_NONE;
}
#endif


/*$PAGE*/
/*
*********************************************************************************************************
*                                        NetIP_RxPktValidate()
*
* Description : (1) Validate

⌨️ 快捷键说明

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