00001 /* 00002 *Copyright (c) 2000-2002 Viola Systems Ltd. 00003 *All rights reserved. 00004 * 00005 *Redistribution and use in source and binary forms, with or without 00006 *modification, are permitted provided that the following conditions 00007 *are met: 00008 * 00009 *1. Redistributions of source code must retain the above copyright 00010 *notice, this list of conditions and the following disclaimer. 00011 * 00012 *2. Redistributions in binary form must reproduce the above copyright 00013 *notice, this list of conditions and the following disclaimer in the 00014 *documentation and/or other materials provided with the distribution. 00015 * 00016 *3. The end-user documentation included with the redistribution, if 00017 *any, must include the following acknowledgment: 00018 * "This product includes software developed by Viola 00019 * Systems (http://www.violasystems.com/)." 00020 * 00021 *Alternately, this acknowledgment may appear in the software itself, 00022 *if and wherever such third-party acknowledgments normally appear. 00023 * 00024 *4. The names "OpenTCP" and "Viola Systems" must not be used to 00025 *endorse or promote products derived from this software without prior 00026 *written permission. For written permission, please contact 00027 *opentcp@opentcp.org. 00028 * 00029 *5. Products derived from this software may not be called "OpenTCP", 00030 *nor may "OpenTCP" appear in their name, without prior written 00031 *permission of the Viola Systems Ltd. 00032 * 00033 *THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00034 *WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00035 *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00036 *IN NO EVENT SHALL VIOLA SYSTEMS LTD. OR ITS CONTRIBUTORS BE LIABLE 00037 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00038 *CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00039 *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 00040 *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 00041 *WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 00042 *OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00043 *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00044 *==================================================================== 00045 * 00046 *OpenTCP is the unified open source TCP/IP stack available on a series 00047 *of 8/16-bit microcontrollers, please see <http://www.opentcp.org>. 00048 * 00049 *For more information on how to network-enable your devices, or how to 00050 *obtain commercial technical support for OpenTCP, please see 00051 *<http://www.violasystems.com/>. 00052 */ 00053 00064 #ifndef INCLUDE_IP_H 00065 #define INCLUDE_IP_H 00066 00067 #include<inet/datatypes.h> 00068 #include<inet/ethernet.h> 00069 00070 #define PHY_ADR_LEN ETH_ADDRESS_LEN 00072 #define IP_ICMP 0x01 00073 #define IP_UDP 17 00074 #define IP_TCP 6 00076 #define IP_HLEN 20 /* IP Header Length in bytes */ 00077 #define IP_MIN_HLEN 20 00078 #define IP_DEF_VIHL 0x45 00079 #define IP_DEF_TTL 100 00080 #define MAX_IP_OPTLEN 40 /* Max IP Header option field length */ 00081 #define IP_MAX_HLEN IP_MIN_HLEN + MAX_IP_OPTLEN 00082 00083 #define IP_DONT_FRAGMENT 0x4000 /* Don't Fragment Flag */ 00084 #define IP_FRAGOFF 0x1FFF /* Fragment offset mask */ 00085 #define IP_MOREFRAGS 0x2000 /* More fragments bit */ 00086 00087 #define IP_GOOD_CS 0 00088 00089 /* IP Option control commands */ 00090 00091 #define IPO_COPY 0x80 /* Copy on fragment mask */ 00092 #define IPO_NOP 0x01 /* No operation */ 00093 #define IPO_EOOP 0x00 /* End of options */ 00094 00095 /* Reserved addresses */ 00096 00097 #define IP_BROADCAST_ADDRESS 0xFFFFFFFF /* 255.255.255.255 */ 00098 00113 struct ip_frame 00114 { 00115 UINT8 vihl; 00116 UINT8 tos; 00117 UINT16 tlen; 00118 UINT16 id; 00119 UINT16 frags; 00120 UINT8 ttl; 00121 UINT8 protocol; 00122 UINT16 checksum; 00123 UINT32 sip; 00124 UINT32 dip; 00125 UINT8 opt[MAX_IP_OPTLEN + 1]; 00126 UINT16 buf_index; 00130 }; 00131 00132 /* IP function prototypes */ 00133 00134 INT16 process_ip_in(struct ethernet_frame*); 00135 INT16 process_ip_out(UINT32, UINT8, UINT8, UINT8, UINT8*, UINT16); 00136 UINT8 ip_check_cs(struct ip_frame*); 00137 UINT16 ip_checksum(UINT16, UINT8, UINT8); 00138 UINT32 ip_checksum_buf (UINT16 cs, UINT8* buf, UINT16 len); 00139 UINT32 ip_construct_cs(struct ip_frame*); 00140 00141 #endif