📄 net_udp.c
字号:
/*
*********************************************************************************************************
* uC/TCP-IP
* The Embedded TCP/IP Suite
*
* (c) Copyright 2003-2006; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
* Knowledge of the source code may not be used to write a similar
* product. This file may only be used in accordance with a license
* and should not be redistributed in any way.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* NETWORK UDP LAYER
* (USER DATAGRAM PROTOCOL)
*
* Filename : net_udp.c
* Version : V1.86
* Programmer(s) : ITJ
*********************************************************************************************************
* Note(s) : (1) Supports User Datagram Protocol as described in RFC #768.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#define NET_UDP_MODULE
#include <net.h>
/*
*********************************************************************************************************
* 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 NetUDP_RxPktValidateBuf (NET_BUF_HDR *pbuf_hdr,
NET_ERR *perr);
#endif
static void NetUDP_RxPktValidate (NET_BUF *pbuf,
NET_BUF_HDR *pbuf_hdr,
NET_UDP_HDR *pudp_hdr,
NET_ERR *perr);
static void NetUDP_RxPktDemuxDatagram(NET_BUF *pbuf,
NET_ERR *perr);
#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))
static void NetUDP_RxPktDemuxAppData (NET_BUF *pbuf,
NET_ERR *perr);
static void NetUDP_RxPktFree (NET_BUF *pbuf);
#endif
static void NetUDP_RxPktDiscard (NET_BUF *pbuf,
NET_ERR *perr);
/* --------------- TX FNCTS --------------- */
static void NetUDP_Tx (NET_BUF *pbuf,
NET_IP_ADDR src_addr,
NET_UDP_PORT_NBR src_port,
NET_IP_ADDR dest_addr,
NET_UDP_PORT_NBR dest_port,
NET_IP_TOS TOS,
NET_IP_TTL TTL,
CPU_INT16U flags_udp,
CPU_INT16U flags_ip,
void *popts_ip,
NET_ERR *perr);
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
static void NetUDP_TxPktValidate (NET_BUF *pbuf,
NET_BUF_HDR *pbuf_hdr,
NET_UDP_PORT_NBR src_port,
NET_UDP_PORT_NBR dest_port,
CPU_INT16U flags_udp,
NET_ERR *perr);
#endif
static void NetUDP_TxPktPrepareHdr (NET_BUF *pbuf,
NET_BUF_HDR *pbuf_hdr,
NET_IP_ADDR src_addr,
NET_UDP_PORT_NBR src_port,
NET_IP_ADDR dest_addr,
NET_UDP_PORT_NBR dest_port,
CPU_INT16U flags_udp,
NET_ERR *perr);
static void NetUDP_TxPktFree (NET_BUF *pbuf);
static void NetUDP_TxPktDiscard (NET_BUF *pbuf);
/*
*********************************************************************************************************
* LOCAL CONFIGURATION ERRORS
*********************************************************************************************************
*/
/*$PAGE*/
/*
*********************************************************************************************************
* NetUDP_Init()
*
* Description : (1) Initialize User Datagram Protocol Layer :
*
* (a) Initialize UDP statistics & error counters
*
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : Net_Init().
*
* Note(s) : none.
*********************************************************************************************************
*/
void NetUDP_Init (void)
{
/* ------------- INIT UDP STAT & ERR CTRS ------------- */
#if (NET_CTR_CFG_STAT_EN == DEF_ENABLED)
NetUDP_StatRxPktCtr = 0;
NetUDP_StatRxDatagramProcessedCtr = 0;
NetUDP_StatTxDatagramCtr = 0;
#endif
#if (NET_CTR_CFG_ERR_EN == DEF_ENABLED)
NetUDP_ErrNullPtrCtr = 0;
NetUDP_ErrRxHdrDatagramLenCtr = 0;
NetUDP_ErrRxHdrPortSrcCtr = 0;
NetUDP_ErrRxHdrPortDestCtr = 0;
NetUDP_ErrRxHdrChkSumCtr = 0;
NetUDP_ErrRxDestCtr = 0;
NetUDP_ErrRxPktDiscardedCtr = 0;
NetUDP_ErrTxPktDiscardedCtr = 0;
#if (NET_ERR_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)
NetUDP_ErrTxInvalidSizeCtr = 0;
#endif
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
NetUDP_ErrRxInvalidBufIxCtr = 0;
NetUDP_ErrRxHdrDataLenCtr = 0;
NetUDP_ErrTxProtocolCtr = 0;
NetUDP_ErrTxInvalidBufIxCtr = 0;
NetUDP_ErrTxHdrDataLenCtr = 0;
NetUDP_ErrTxHdrPortSrcCtr = 0;
NetUDP_ErrTxHdrPortDestCtr = 0;
NetUDP_ErrTxHdrFlagsCtr = 0;
#endif
#endif
}
/*$PAGE*/
/*
*********************************************************************************************************
* NetUDP_Rx()
*
* Description : (1) Process received datagrams & forward to socket or application layer :
*
* (a) Validate UDP packet
* (b) Demultiplex datagram to socket/application connection
* (c) Update receive statistics
*
* (2) Although UDP data units are typically referred to as 'datagrams' (see RFC #768, Section
* 'Introduction'), the term 'UDP packet' (see RFC #1983, 'packet') is used for UDP Receive
* until the packet is validated as a UDP datagram.
*
*
* Argument(s) : pbuf Pointer to network buffer that received UDP packet.
*
* perr Pointer to variable that will receive the return error code from this function :
*
* NET_UDP_ERR_NONE UDP datagram successfully received & processed.
* NET_ERR_INIT_INCOMPLETE Network initialization NOT complete.
*
* ----- RETURNED BY NetUDP_RxPktDiscard() : -----
* NET_ERR_RX Receive error; packet discarded.
*
* Return(s) : none.
*
* Caller(s) : NetIP_RxPktDemuxDatagram().
*
* Note(s) : (3) NetUDP_Rx() blocked until network initialization completes; perform NO action.
*
* (4) Network buffer already freed by higher layer; only increment error counter.
*
* (5) RFC #792, Section 'Destination Unreachable Message : Description' states that
* "if, in the destination host, the IP module cannot deliver the datagram because
* the indicated ... process port is not active, the destination host may send a
* destination unreachable message to the source host".
*********************************************************************************************************
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -