Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages   Examples  

Main loop functions


Detailed Description

This is a group of functions invoked usually from main loop to perform period tasks for the TCP/IP stack and to manage data processing. They are not part of the API functions, but they must still be invoked by the user.

Not all of these functions must be invoked all the time in the main loop. Certain functions are only invoked when it is needed (IP, UDP and TCP processing for example). Check their individual documentation for detailed instructions on how to use them.

Defines

#define NETWORK_CHECK_IF_RECEIVED()   NE2000ReceiveFrame()
 Use this macro to check if there is recieved data in Ethernet controller.

#define NETWORK_RECEIVE_END()   NE2000DumpRxFrame()
 Dump received packet in the Ethernet controller.


Functions

void arp_manage (void)
 Manage ARP cache periodically.

void NE2000CheckOverFlow (void)
 Check if receive-buffer overflow occured.

INT16 process_icmp_in (struct ip_frame *frame, UINT16 len)
 Process recieved ICMP datagram.

INT16 process_ip_in (struct ethernet_frame *)
 Process received IP frame.

void tcp_poll (void)
 Poll TCP sockets periodically.

INT16 process_tcp_in (struct ip_frame *, UINT16)
 Check and process the received TCP frame.

INT16 process_udp_in (struct ip_frame *, UINT16)
 Process received UDP frame.


Define Documentation

 
#define NETWORK_CHECK_IF_RECEIVED      NE2000ReceiveFrame()
 

Invoke this macro periodically (see main_demo.c for example) to check if there is new data in the Ethernet controller.

If there is new data in the Ethernet controller, this macro (function that it points to that is) will return a value of TRUE and fill in the appropriate values in the received_frame variable. Otherwise it returns FALSE.

Examples:
main_demo.c.

Definition at line 262 of file system.h.

 
#define NETWORK_RECEIVE_END      NE2000DumpRxFrame()
 

Invoke this macro when the received Ethernet packet is not needed any more and can be discarded.

Examples:
main_demo.c.

Definition at line 279 of file system.h.


Function Documentation

void arp_manage void   
 

Author:
Date:
04.11.2001
Warning:
  • Invoke this function periodically to ensure proper ARP cache behaviour
Iterate through ARP cache aging entries. If timed-out entry is found, remove it (dynamic address) or update it (static address). This function must be called periodically by the system.
Examples:
main_demo.c.

Definition at line 785 of file arp.c.

References ARP_FIXED_IP, ARP_FREE, ARP_PENDING, ARP_REFRESHING, ARP_RESEND, ARP_RESOLVED, arp_send_req(), ARP_TEMP_IP, ARP_TIMEOUT, arp_timer, check_timer(), init_timer(), arp_entry::pradr, arp_entry::retries, arp_entry::state, TIMERTIC, arp_entry::ttl, and arp_entry::type.

void NE2000CheckOverFlow void   
 

Author:
Date:
19.02.2002
This function checks if receive-buffer overflow has happened. If it did, NIC is reinitialized to ensure proper operation.

Invoke this function periodically to ensure proper operation under heavy load.

Examples:
main_demo.c.

Definition at line 393 of file ethernet.c.

References BOUNDARY, CR, CURR, inNE2000(), ISR, NE2000CurrPktPtr, NE2000NextPktPtr, outNE2000(), RBCR0, and TCR.

INT16 process_icmp_in struct ip_frame   frame,
UINT16    len
 

Author:
Date:
08.07.2002
Parameters:
frame  - pointer to received IP frame structure
len  - length of the received IP datagram (in bytes)
Returns:
  • -1 - packet not OK (not proper ICMP or not ICMP at all)
  • >=0 - packet OK
Invoke process_icmp_in whenever IP datagram containing ICMP message is detected (see main_demo.c for example main loop implementing this).

This function simply checks correctnes of received ICMP message and send ICMP replies when requested.

Examples:
main_demo.c.

Definition at line 97 of file icmp.c.

References ip_frame::buf_index, ip_frame::dip, ip_checksum(), ip_checksum_buf(), IP_ICMP, NETWORK_RECEIVE_INITIALIZE, NETWORK_TX_BUFFER_SIZE, process_ip_out(), ip_frame::protocol, RECEIVE_NETWORK_B, RECEIVE_NETWORK_BUF, ip_frame::sip, and TXBUF.

INT16 process_ip_in struct ethernet_frame   frame
 

Author:
  • Jari Lahti
Date:
11.06.2002
Parameters:
frame  pointer to ethernet_frame structure holding information about the received frame that carries IP datagram.
Returns:
  • -1 - IP packet not OK
  • >0 - Length of next layer data (IP packet OK)
Process received IP packet by checking necessary header information and storing it accordingly to received_ip_packet variable. If everything checks out, return length of the data carried in the IP datagram (for higher-level protocols), otherwise return -1.
Examples:
main_demo.c.

Definition at line 115 of file ip.c.

References arp_add(), ARP_TEMP_IP, ethernet_frame::buf_index, ip_frame::buf_index, ip_frame::checksum, ethernet_frame::destination, ip_frame::dip, ip_frame::frags, ethernet_frame::frame_size, ip_frame::id, ip_check_cs(), IP_ICMP, NETWORK_RECEIVE_INITIALIZE, ip_frame::opt, PHY_ADR_LEN, ethernet_frame::protocol, ip_frame::protocol, PROTOCOL_IP, RECEIVE_NETWORK_B, ip_frame::sip, ethernet_frame::source, ip_frame::tlen, ip_frame::tos, TRUE, ip_frame::ttl, and ip_frame::vihl.

void tcp_poll void   
 

Author:
Date:
19.07.2002
Warning:
  • This function must be invoked periodically from the main loop. See main_demo.c for an example.
This function checks all TCP sockets and performs various actions if timeouts occur. What kind of action is performed is defined by the state of the TCP socket.
Examples:
main_demo.c.

Definition at line 808 of file tcp.c.

References check_timer(), tcb::event_listener, tcb::flags, init_timer(), tcb::myflags, tcb::persist_timerh, tcb::rem_ip, tcb::remport, tcb::retransmit_timerh, tcb::retries_left, tcb::send_mtu, tcb::send_next, tcb::send_unacked, tcb::state, TCP_DEF_RETRY_TOUT, TCP_EVENT_ABORT, TCP_EVENT_CLOSE, TCP_EVENT_REGENERATE, tcp_newstate(), tcp_sendcontrol(), TCP_STATE_CLOSED, TCP_STATE_CLOSING, TCP_STATE_CONNECTED, TCP_STATE_FINW1, TCP_STATE_FINW2, TCP_STATE_FREE, TCP_STATE_LAST_ACK, TCP_STATE_LISTENING, TCP_STATE_RESERVED, TCP_STATE_SYN_RECEIVED, TCP_STATE_SYN_SENT, TCP_STATE_TIMED_WAIT, TCP_SYN_RETRY_TOUT, TCP_TYPE_SERVER, TIMERTIC, and tcb::type.

INT16 process_tcp_in struct ip_frame   frame,
UINT16    len
 

Author:
Date:
12.07.2002
Parameters:
frame  pointer to received ip_frame structure
len  length of data contained in IP datagram (in bytes)
Returns:
  • -1 - Error (packet not OK, or not TCP,or something else)
  • >0 - Packet OK
Invoke this function to process received TCP frames. See main_demo.c for an example on how to accomplish this.
Examples:
main_demo.c.

Definition at line 1250 of file tcp.c.

References tcp_frame::ackno, ip_frame::buf_index, tcp_frame::buf_index, tcp_frame::checksum, tcp_frame::dport, tcb::event_listener, tcb::flags, tcp_frame::hlen_flags, IP_TCP, tcb::myflags, NETWORK_RECEIVE_INITIALIZE, tcp_frame::opt, ip_frame::protocol, RECEIVE_NETWORK_B, tcb::receive_next, tcb::rem_ip, tcb::remport, RESET_SYSTEM, tcb::send_next, tcb::send_unacked, tcp_frame::seqno, ip_frame::sip, tcp_frame::sport, tcb::state, tcp_check_cs(), TCP_EVENT_ABORT, TCP_EVENT_ACK, TCP_EVENT_CLOSE, TCP_EVENT_CONNECTED, TCP_EVENT_CONREQ, TCP_EVENT_DATA, tcp_initseq(), tcp_mapsocket(), tcp_newstate(), tcp_sendcontrol(), tcp_sendreset(), TCP_STATE_CLOSED, TCP_STATE_CLOSING, TCP_STATE_CONNECTED, TCP_STATE_FINW1, TCP_STATE_FINW2, TCP_STATE_FREE, TCP_STATE_LAST_ACK, TCP_STATE_LISTENING, TCP_STATE_SYN_RECEIVED, TCP_STATE_SYN_SENT, TCP_STATE_TIMED_WAIT, TCP_TYPE_SERVER, tcb::type, tcp_frame::urgent, and tcp_frame::window.

INT16 process_udp_in struct ip_frame   frame,
UINT16    len
 

Author:
Date:
15.07.2002
Parameters:
frame  pointer to received IP frame structure
len  length of data in bytes
Returns:
  • -1 - Error (packet not UDP, header errror or no socket for it)
  • >0 - Packet OK
Invoke this function to process received UDP frames. See main_demo.c for an example on how to accomplish this.
Examples:
main_demo.c.

Definition at line 550 of file udp.c.

References ip_frame::buf_index, udp_frame::buf_index, udp_frame::checksum, ip_frame::dip, udp_frame::dport, ip_checksum(), IP_UDP, ucb::locport, NETWORK_RECEIVE_INITIALIZE, ucb::opts, ip_frame::protocol, RECEIVE_NETWORK_B, ip_frame::sip, udp_frame::sport, ucb::state, udp_frame::tlen, UDP_EVENT_DATA, UDP_HLEN, UDP_OPT_CHECK_CS, and UDP_STATE_OPENED.


Generated on Sun Aug 3 20:33:01 2003 for OpenTCP by doxygen1.2.18