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

📄 tcp_ip.h

📁 用于以太网开发
💻 H
📖 第 1 页 / 共 2 页
字号:
									 */
#define TCP_STATE_TIMED_WAIT	11	/**< Waiting for 2MSL to prevent
									 *	 erroneous connection duplication
									 */
#define	TCP_STATE_CONNECTED		12	/**< Connection established and data
									 *	 flowing freely to both sides :-)
									 */



/* TCP callback events			*/

/** \def TCP_EVENT_CONREQ
 *	\brief Connection request event
 *	
 *	Connection request event is notified to TCP server applications'
 *	event listener when SYN packet is received for it's socket. Event
 *	listener can then, if it wants to, inspect IP addres and port number
 *	of the remote host, or some other internal parameters, to decide
 *	whether it should allow connection establishment or not. One of the
 *	following values must then be returned from the event listener:
 *		\li -1 - do not allow connection to be established. RST packet will
 *		be sent to remote host.
 *		\li	-2 - do not respond to this particular SYN packet (keep quiet).
 *		This may be used if device is somehow busy and not yet ready to
 *		establish a connection, but doesn't wan't to forcefully reject the
 *		connection with a RST packet.
 *		\li 1 - allow connection to be established
 */
#define TCP_EVENT_CONREQ		1

/** \def TCP_EVENT_CONNECTED
 *	\brief Connection established event
 *
 *	Applications' event listener is informed by this event that
 *	connection is established and that it may start sending/receiving
 *	data.
 */

#define TCP_EVENT_CONNECTED		2

/** \def TCP_EVENT_CLOSE
 *	\brief Connection closed event
 *
 *	TCP connection was properly closed (either by calling tcp_close() by
 *	application or remote host initialized closing sequence).
 */
#define TCP_EVENT_CLOSE			4

/** \def TCP_EVENT_ABORT
 *	\brief Connection aborted event
 *
 *	Connection is, for some reason, aborted. This can happen for a number
 *	of reasons:
 *		\li Data retransmissions performed sufficient number of times but
 *		no acknowledgment was received
 *		\li No response for some time to keep-alive packets
 *		\li Remote host forcefully closed the connection for some reason
 *		\li Application invoked tcp_abort() function
 */
#define TCP_EVENT_ABORT			8

/** \def TCP_EVENT_ACK
 *	\brief Data acknowledged event
 *
 *	TCP/IP stack has received correct acknowledgment packet for the 
 *	previously sent data and is informing the application about it.
 *	After this event, application can send new data packet to remote
 *	host.
 */
#define TCP_EVENT_ACK			16

/** \def TCP_EVENT_REGENERATE
 *	\brief Regenerate data event
 *
 *	Previously sent data packet was not acknowledged (or the acknowledgment
 *	packet did not arrive) so retransmission needs to be peformed.
 *	Application must resend the data that was sent in the previous packet.
 */
#define TCP_EVENT_REGENERATE	32

/** \def TCP_EVENT_DATA
 *	\brief Data arrival event
 *
 *	TCP received some data from remote host and is informing application
 *	that it is available for reading from the Ethernet controller.
 */
#define	TCP_EVENT_DATA			64



/* TCP and UDP buffer handling			*/

/** \def TCP_APP_OFFSET
 *	\brief Transmit buffer offset for TCP applications
 *
 *  This value defines offset that TCP applications must use when
 *	writing to transmit buffer. This many bytes will be used
 *	<b>before</b> the first byte of applications data in the 
 *	transmit buffer to store TCP header.
 */
#define TCP_APP_OFFSET			MIN_TCP_HLEN		/* Application buffers must have 	*/
													/* this much free on start of buf	*/

/** \def UDP_APP_OFFSET
 *	\brief Transmit buffer offset for UDP applications
 *
 *  This value defines offset that UDP applications must use when
 *	writing to transmit buffer. This many bytes will be used
 *	<b>before</b> the first byte of applications data in the 
 *	transmit buffer to store UDP header.
 */

#define UDP_APP_OFFSET			UDP_HLEN



/* UDP Structures			*/

/** \struct udp_frame
 *	\brief UDP header information
 *
 *	This structures' fields are used to hold information about the headers
 *	of the received UDP packet. 
 *
 *	In addition to standard UDP header fields, buf_index field
 *	has been added allowing applications to re-read the received data many
 *	times by reinitializing reading based on the address stored in this
 *	field.
 */
struct udp_frame
{
	UINT16 sport;		/**< Source port					*/
	UINT16 dport;		/**< Destination port				*/
	UINT16 tlen;		/**< total len (UDP part)			*/
	UINT16 checksum;	/**< UDP checksum					*/
	UINT16 buf_index;	/**< Data offsett from the start
						 * 	 of network buffer			
						 */
};

/** \struct ucb
 *	\brief UDP control block
 *
 *	This structure holds various fields used to keep track of UDP socket
 *	states, settings and event listener function.
 *
 */
struct ucb
{
	/** \brief State of socket entry
	 *
	 *	This variable holds state of a particular UDP socket entry 
	 *	in the UDP socket table. Following values are possible:
	 *		\li UDP_STATE_FREE
	 *		\li UDP_STATE_CLOSED
	 *		\li UDP_STATE_OPENED
	 */
	UINT8 	state;		
	
	/** \brief Type of service allocated for a socket
	 *
	 *	For now no services implemented so this value
	 *	is not important.
	 */	
	UINT8	tos;

	UINT16	locport;	/**< Local UDP port of Socket		*/
	
	/** \brief Socket options 
	 *
	 *	Currently, this holds information about checksum calculation
	 *	options. Can be one of the following:
	 *		\li	UDP_OPT_NONE - cheksum calculation not performed
	 *		\li UDP_OPT_SEND_CS - checksum is calculated for outgoing
	 *		UDP packets
	 *		\li UDP_OPT_CHECK_CS - checksum is checked for incoming
	 *		UDP packets
	 *		\li UDP_OPT_SEND_CS | UDP_OPT_CHECK_CS - both checksum
	 *		calculations are enabled
	 */
	UINT8	opts;		
	
	/** \brief UDP socket application event listener
	 *
	 *	Pointer to a event listener - a callback function used
	 *	by TCP/IP stack to notify application about certain events.
	 */	
	INT32 	(*event_listener)
			(INT8, UINT8, UINT32, UINT16, UINT16, UINT16 );
}; 



/* TCP Structures			*/

/** \struct tcp_frame
 *	\brief TCP header information
 *
 *	This structure holds header fields from the received TCP packet. 
 *
 *	In addition to standard header fields, buf_index field
 *	has been added allowing applications to re-read the received data many
 *	times by reinitializing reading based on the address stored in this
 *	field.
 */
struct tcp_frame
{
	UINT16	sport;						/**< Source port					*/
	UINT16	dport;						/**< Destination port				*/
	UINT32	seqno;						/**< Sequence number				*/
	UINT32	ackno;						/**< Acknowledgement number		*/
	UINT16	hlen_flags;					/**< Header length and flags		*/
	UINT16 	window;						/**< Size of window				*/
	UINT16 	checksum;					/**< TCP packet checksum			*/
	UINT16 	urgent;						/**< Urgent pointer				*/
	UINT8	opt[MAX_TCP_OPTLEN + 1];	/**< Option field					*/
	UINT16	buf_index;					/**< Next offset from the start of
										 *   network buffer				
										 */	
};

/** \struct tcb
 *	\brief TCP transmission control block
 *
 *	This structure holds various fields used to keep track of TCP socket
 *	states, settings and event listener function. It is needed to ensure
 *	proper operation of TCP state machine and TCP connections based on it.
 *
 *	
 */
struct tcb
{
	/** \brief State of the TCP socket [entry]
	 *
	 *	This variable holds information used by the OpenTCP to manage
	 *	sockets as well as information needed to manage TCP connection.
	 *	Possible values are:
	 *		\li TCP_STATE_FREE
	 *		\li TCP_STATE_RESERVED
	 *		\li TCP_STATE_CLOSED
	 *		\li TCP_STATE_LISTENING
	 *		\li TCP_STATE_SYN_RECEIVED
	 *		\li TCP_STATE_SYN_SENT
	 *		\li TCP_STATE_FINW1
	 *		\li TCP_STATE_FINW2
	 *		\li TCP_STATE_CLOSING
	 *		\li TCP_STATE_LAST_ACK
	 *		\li TCP_STATE_TIMED_WAIT
	 *		\li TCP_STATE_CONNECTED
	 */
	UINT8	state;						
	
	/** \brief type of the TCP socket
	 *
	 *	Defines type of the TCP socket allocated. This determines
	 *	how connection is established/closed in some cases.
	 *	Possible values are:
	 *		\li TCP_TYPE_NONE
	 *		\li TCP_TYPE_SERVER
	 *		\li TCP_TYPE_CLIENT
	 *		\li TCP_TYPE_CLIENT_SERVER
	 */
	UINT8	type;						
	UINT8	flags;						/**< State machine flags			*/
#ifdef IPv6
	IPv6Addr*	rem_ip;
#else
	UINT32	rem_ip;						/**< Remote IP address			*/
#endif
	UINT16	remport;					/**< Remote TCP port				*/
	UINT16	locport;					/**< Local TCP port				*/
	UINT32 	send_unacked;
	UINT8	myflags;					/**< My flags to be Txed			*/
	UINT32	send_next;
	UINT16 	send_mtu;
	UINT16	tout;						/**< Socket idle timeout (seconds)*/
	UINT8	tos;						/**< Type of service allocated */
	UINT32	receive_next;
	UINT16	persist_timerh;				/**< Persistent timers' handle */
	UINT16	retransmit_timerh;			/**< Retransmission timers' handle */
	UINT8	retries_left;				/**< Number of retries left before
										 *	 aborting
										 */
	
	/** \brief TCP socket application event listener
	 *
	 *	Pointer to an event listener - a callback function used
	 *	by TCP/IP stack to notify application about certain events.
	 */
#if defined (IPv6)
	INT32 	(*event_listener)(INT8, UINT8, struct _in6_addr *, UINT32);	
#else
	INT32 	(*event_listener)(INT8, UINT8, UINT32, UINT32);	
#endif	
};

/* ICMP function prototypes	*/
#if defined (IPv6)
	INT16 process_icmp_in(struct ipv6_frame*, UINT16);
#else
	INT16 process_icmp_in(struct ip_frame*, UINT16);
#endif

/* UDP Function prototypes */
INT8 udp_init (void);
INT8 udp_getsocket (UINT8 , INT32 (* )(INT8, UINT8, UINT32, UINT16, UINT16, UINT16), UINT8 );
INT8 udp_releasesocket (INT8 );
INT8 udp_open (INT8 , UINT16 );
INT8 udp_close (INT8 );
#ifdef IPv6
INT16 udp_send (INT8 , IPv6Addr * , UINT16 , UINT8* , UINT16 , UINT16 );
#else
INT16 udp_send (INT8 , UINT32 , UINT16 , UINT8* , UINT16 , UINT16 );
#endif
INT16 process_udp_in(struct ip_frame* , UINT16 );
UINT16 udp_getfreeport(void); 

/*	TCP Function prototypes	*/

INT16 process_tcp_in(struct ip_frame*, UINT16);
INT16 process_tcp_out(INT8, UINT8*, UINT16, UINT16);
INT8 tcp_init(void);
INT8 tcp_listen(INT8, UINT16);
INT8 tcp_mapsocket(struct ip_frame*, struct tcp_frame*);
UINT8 tcp_check_cs(struct ip_frame*, UINT16);
void tcp_sendcontrol(INT8);
UINT32 tcp_initseq(void);
void tcp_poll(void);
void tcp_newstate(struct tcb*, UINT8);
#ifdef IPv6
	INT8 tcp_getsocket (UINT8 soctype, UINT8 tos, UINT16 tout, INT32 (*listener)(INT8, UINT8, IPv6Addr*, UINT32) );
#else
	INT8 tcp_getsocket(UINT8, UINT8, UINT16, INT32 (*)(INT8, UINT8, UINT32, UINT32) );
#endif

INT8 tcp_releasesocket(INT8);
#ifdef IPv6
	INT8 tcp_connect (INT8 sochandle, struct _in6_addr* ip, UINT16 rport, UINT16 myport );
#else
	INT8 tcp_connect (INT8 sochandle, UINT32 ip, UINT16 rport, UINT16 myport );
#endif
INT16 tcp_send(INT8, UINT8*, UINT16, UINT16);
INT8 tcp_close(INT8);
#if defined (IPv6)
	void tcp_sendreset(struct tcp_frame*, struct _in6_addr);
#else
	void tcp_sendreset(struct tcp_frame*, UINT32);
#endif
INT8 tcp_getstate(INT8);
UINT16 tcp_getfreeport(void);
INT16 tcp_checksend(INT8);
INT8 tcp_abort(INT8);



#endif


⌨️ 快捷键说明

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