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

📄 net_udp.c

📁 ucos+lwip用于AT91SAM7X256
💻 C
📖 第 1 页 / 共 5 页
字号:
/*$PAGE*/
void  NetUDP_Rx (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;
    NET_UDP_HDR  *pudp_hdr;
    NET_ERR       msg_err;


#if (NET_ERR_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)
    if (Net_InitDone != DEF_YES) {                              /* If init NOT complete, exit rx (see Note #3).         */
        NetUDP_RxPktDiscard(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) {
        NetUDP_RxPktDiscard(pbuf, perr);
        NET_CTR_ERR_INC(NetUDP_ErrNullPtrCtr);
        return;
    }
#endif


    NET_CTR_STAT_INC(NetUDP_StatRxPktCtr);


                                                                /* ----------------- VALIDATE UDP PKT ----------------- */
    pbuf_hdr = &pbuf->Hdr;
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
    NetUDP_RxPktValidateBuf(pbuf_hdr, perr);                    /* Validate rx'd buf.                                   */
    switch (*perr) {
        case NET_UDP_ERR_NONE:
             break;


        case NET_ERR_INVALID_PROTOCOL:
        case NET_BUF_ERR_INVALID_IX:
        default:
             NetUDP_RxPktDiscard(pbuf, perr);
             return;                                            /* Prevent 'break NOT reachable' compiler warning.      */
    }
#endif
    pudp_hdr = (NET_UDP_HDR *)&pbuf->Data[pbuf_hdr->TCP_UDP_HdrDataIx];
    NetUDP_RxPktValidate(pbuf, pbuf_hdr, pudp_hdr, perr);       /* Validate rx'd pkt.                                   */


                                                                /* ------------------ DEMUX DATAGRAM ------------------ */
    switch (*perr) {
        case NET_UDP_ERR_NONE:
             NetUDP_RxPktDemuxDatagram(pbuf, perr);
             break;


        case NET_UDP_ERR_INVALID_PORT_NBR:
        case NET_UDP_ERR_INVALID_LEN:
        case NET_UDP_ERR_INVALID_LEN_DATA:
        case NET_UDP_ERR_INVALID_CHK_SUM:
        default:
             NetUDP_RxPktDiscard(pbuf, perr);
             return;                                            /* Prevent 'break NOT reachable' compiler warning.      */
    }


/*$PAGE*/
                                                                /* ----------------- UPDATE RX STATS ------------------ */
    switch (*perr) {                                            /* Chk err from NetUDP_RxPktDemuxDatagram().            */
        case NET_APP_ERR_NONE:
        case NET_SOCK_ERR_NONE:
             NET_CTR_STAT_INC(NetUDP_StatRxDatagramProcessedCtr);
            *perr = NET_UDP_ERR_NONE;
             break;


        case NET_ERR_INIT_INCOMPLETE:
        case NET_ERR_RX:
             NET_CTR_ERR_INC(NetUDP_ErrRxPktDiscardedCtr);      /* See Note #4.                                         */
             return;                                            /* Prevent 'break NOT reachable' compiler warning.      */


        case NET_ERR_RX_DEST:
             NET_CTR_ERR_INC(NetUDP_ErrRxDestCtr);
                                                                /* Tx ICMP port unreach (see Note #5).                  */
             NetICMP_TxMsgErr(pbuf, NET_ICMP_MSG_TYPE_DEST_UNREACH, NET_ICMP_MSG_CODE_DEST_PORT, NET_ICMP_MSG_PTR_NONE, &msg_err);
             NetUDP_RxPktDiscard(pbuf, perr);
             return;                                            /* Prevent 'break NOT reachable' compiler warning.      */


        default:
             NetUDP_RxPktDiscard(pbuf, perr);
             return;                                            /* Prevent 'break NOT reachable' compiler warning.      */
    }
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                         NetUDP_RxAppData()
*
* Description : (1) Deframe application data & received IP options from received UDP packet buffer(s) :
*
*                   (a) Get any received IP options                                         See Note #5
*                   (b) Deframe application data from UDP packet buffer(s)                  See Note #4
*                   (c) Free UDP packet buffer(s)
*
*
* Argument(s) : pbuf                Pointer to network buffer that received UDP datagram.
*
*               pdata_buf           Pointer to application buffer to receive application data.
*
*               data_buf_len        Size    of application receive buffer (in octets) [see Note #4].
*
*               pip_opts_buf        Pointer to buffer to receive possible IP options (see Note #5a).
*
*               ip_opts_buf_len     Size of IP options receive buffer (in octets) [see Note #5b].
*
*               pip_opts_len        Pointer to variable that will receive the return size of any received IP options.
*
*               perr                Pointer to variable that will receive the return error code from this function :
*
*                                       NET_APP_ERR_NONE                Application data successfully deframed.
*                                       NET_APP_ERR_NULL_PTR            Argument 'pbuf'/'pdata_buf' passed a NULL pointer.
*                                       NET_APP_ERR_INVALID_DATA_SIZE   Application data receive buffer insufficient size;
*                                                                           some, but not all, application data deframed
*                                                                           into receive buffer (see Note #4b).
*
*                                       NET_ERR_INIT_INCOMPLETE         Network initialization NOT complete.
*
*                                                                       
*                                                                       ------ RETURNED BY NetUDP_RxPktDiscard() : -------
*                                       NET_ERR_RX                      Receive error; packet discarded.
*
* Return(s)   : Total application data octets deframed into receive buffer, if NO errors.
*
*               0,                                                          otherwise.
*
* Caller(s)   : NetUDP_RxAppDataHandler().
*
* Note(s)     : (2) NetUDP_RxAppData() MUST be called with the global network lock already acquired.
*
*                   #### Developer required to encapsulate function call within global network lock?
*
*                   See also 'NetUDP_RxPktDemuxAppData()  Note #1a1A1b'.
*
*               (3) NetUDP_RxAppData() blocked until network initialization completes; perform NO action.
*
*               (4) (a) Application data receive buffer should be large enough to receive either ...
*
*                       (1) The maximum UDP datagram size (i.e. 65,507 octets)
*                             OR
*                       (2) The application's expected maximum UDP datagram size
*
*                   (b) If the application receive buffer size is NOT large enough for the received UDP datagram,
*                       the remaining application data octets are discarded & NET_APP_ERR_INVALID_DATA_SIZE error 
*                       is returned.
*
*               (5) (a) If ...
*
*                       (1) NO IP options were received with the UDP datagram
*                             OR
*                       (2) NO IP options receive buffer is provided by the application
*                             OR
*                       (3) IP options receive buffer NOT large enough for the received IP options
*
*                       ... then any received IP options are silently discarded.
*
*                       #### Received IP options should be provided via appropriate IP layer API :
*                            (A) Returned via reference pointers directly to application connection handler?
*
*                   (b) The IP options receive buffer size SHOULD be large enough to receive the maximum 
*                       IP options size, NET_IP_HDR_OPT_SIZE_MAX.
*
*                   (c) For fragmented datagrams, IP options are received from the first fragment.
*
*               (6) Pointers to variables that return length or size values MUST be initialized to return
*                   zero PRIOR to all other validation or function handling in case of any error(s).
*
*               (7) (a) On any internal receive     errors, UDP receive packets are     discarded.
*
*                   (b) On any external application errors, UDP receive packets are NOT discarded;
*                       the application MAY continue to attempt to receive the application data
*                       via NetUDP_RxAppData().
*********************************************************************************************************
*/
/*$PAGE*/
#if ((NET_UDP_CFG_APP_API_SEL == NET_UDP_APP_API_SEL_APP     ) || \
     (NET_UDP_CFG_APP_API_SEL == NET_UDP_APP_API_SEL_SOCK_APP))
CPU_INT16U  NetUDP_RxAppData (NET_BUF     *pbuf,
                              void        *pdata_buf,
                              CPU_INT16U   data_buf_len,
                              void        *pip_opts_buf,
                              CPU_INT08U   ip_opts_buf_len,
                              CPU_INT08U  *pip_opts_len,
                              NET_ERR     *perr)
{
#if ((NET_ERR_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)                    && \
     (NET_CTR_CFG_ERR_EN         == DEF_ENABLED)                    && \
     (CPU_CFG_CRITICAL_METHOD    == CPU_CRITICAL_METHOD_STATUS_LOCAL))
    CPU_SR         cpu_sr;
#endif
#if (NET_ERR_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)
    CPU_BOOLEAN    used;
#endif
    NET_BUF       *pbuf_head;
    NET_BUF       *pbuf_next;
    NET_BUF_HDR   *pbuf_hdr;
    NET_BUF_SIZE   data_len_pkt;
    CPU_INT16U     data_len_buf_rem;
    CPU_INT16U     data_len_tot;
    CPU_INT08U    *p_data;
    CPU_INT08U    *pip_opts;
    CPU_INT08U     ip_opt_len;
    NET_ERR        err;
    NET_ERR        err_rtn;

                                                                
    if (pip_opts_len != (CPU_INT08U *)0) {                      /* Init len for err (see Note #6).                      */
       *pip_opts_len  =  0;
    }

#if (NET_ERR_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)
    if (Net_InitDone != DEF_YES) {                              /* If init NOT complete, exit rx (see Notes #3 & #7b).  */
       *perr =  NET_ERR_INIT_INCOMPLETE;
        return (0);
    }

                                                                /* ------------------ VALIDATE PTRS ------------------- */
    if (pbuf == (NET_BUF *)0) {                                 /* See Note #7b.                                        */
       *perr =  NET_APP_ERR_NULL_PTR;
        return (0);
    }
    if (pdata_buf == (CPU_INT08U *)0) {                         /* See Note #7b.                                        */
       *perr =  NET_APP_ERR_NULL_PTR;
        return (0);
    }
                                                                /* ------------------ VALIDATE SIZE ------------------- */
    if (data_buf_len < 1) {                                     /* See Note #7b.                                        */
       *perr =  NET_APP_ERR_INVALID_DATA_SIZE;
        return (0);
    }

                                                                /* ------------------ VALIDATE TYPE ------------------- */
    used = NetBuf_IsUsed(pbuf);
    if (used != DEF_YES) {
        NET_CTR_ERR_INC(NetUDP_ErrRxPktDiscardedCtr);
       *perr =  NET_ERR_RX;
        return (0);
    }
#endif


/*$PAGE*/
                                                                /* ----------------- GET RX'D IP OPTS ----------------- */

⌨️ 快捷键说明

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