00001 /*! \file netstack.h \brief Network Stack. */ 00002 //***************************************************************************** 00003 // 00004 // File Name : 'netstack.h' 00005 // Title : Network Stack 00006 // Author : Pascal Stang 00007 // Created : 6/28/2005 00008 // Revised : 9/20/2005 00009 // Version : 0.3 00010 // Target MCU : Atmel AVR series 00011 // Editor Tabs : 4 00012 // 00013 /// \ingroup network 00014 /// \defgroup netstack Network Stack (netstack.c) 00015 /// \code #include "net/netstack.h" \endcode 00016 /// \par Description 00017 /// This library co-ordinates the various pieces of a typical IP network 00018 /// stack into one unit. Included are handling for ARP, ICMP, and IP 00019 /// packets. UDP and TCP packets are processed and passed to the user. 00020 /// 00021 /// This is an example of how to use the various network libraries, and 00022 /// is meant to be useful out-of-the-box for most users. However, some 00023 /// users may find it restrictive and write their own handlers instead. 00024 /// This stack implementation is by no means the only way to use the various 00025 /// network libraries. 00026 /// 00027 /// \note This is NOT a full-blown TCP/IP stack. It merely handles lower 00028 /// level stack functions so that UDP and TCP packets can be sent 00029 /// and received easily. End-to-end TCP functionality may be added 00030 /// in a future version. Until then, I can recommend using other embedded 00031 /// TCP/IP stacks like Adam Dunkel's uIP. 00032 // 00033 // This code is distributed under the GNU Public License 00034 // which can be found at http://www.gnu.org/licenses/gpl.txt 00035 //***************************************************************************** 00036 //@{ 00037 00038 #ifndef NETSTACK_H 00039 #define NETSTACK_H 00040 00041 #include "net.h" 00042 #include "arp.h" 00043 #include "icmp.h" 00044 #include "ip.h" 00045 #include "nic.h" 00046 00047 //#define NETSTACK_DEBUG 00048 00049 /// NET_BUFFERSIZE is the common receive/process/transmit buffer. 00050 /// - You may override the default NET_BUFFERSIZE by defining an alternate value in global.h. 00051 /// - Network packets larger than NET_BUFFERSIZE will not be accepted. 00052 #ifndef NETSTACK_BUFFERSIZE 00053 #define NETSTACK_BUFFERSIZE (576+ETH_HEADER_LEN) 00054 #endif 00055 00056 /// netstackInit prepares the network interface for use and should be called 00057 /// once at the beginning of the user program. 00058 /// \note Use ipSetAddress() to change network parameters in mid-run. 00059 void netstackInit(uint32_t ipaddress, uint32_t netmask, uint32_t gatewayip); 00060 00061 /// netstackGetBuffer returns a pointer to the common receive/process/transmit buffer. 00062 u08* netstackGetBuffer(void); 00063 00064 /// netstackService should be called in the main loop of the user program. 00065 /// The function will process one received network packet per call. 00066 /// The return value is the length of the packet processed, or zero if no 00067 /// packet was processed. 00068 int netstackService(void); 00069 00070 /// netstackIPProcess handles distribution of IP received packets. 00071 /// 00072 void netstackIPProcess(unsigned int len, ip_hdr* packet); 00073 00074 /// This weakly-defined function is the default handler for incoming UDP/IP packets. 00075 /// Users should define this same function in user code (same name and arguments) to 00076 /// override this default handler and get access to the received packets. 00077 void netstackUDPIPProcess(unsigned int len, udpip_hdr* packet) __attribute__ ((weak)); 00078 00079 /// This weakly-defined function is the default handler for incoming TCP/IP packets. 00080 /// Users should define this same function in user code (same name and arguments) to 00081 /// override this default handler and get access to the received packets. 00082 void netstackTCPIPProcess(unsigned int len, tcpip_hdr* packet) __attribute__ ((weak)); 00083 00084 #endif 00085 //@}