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

/opentcp/include/inet/tcp_ip.h

Go to the documentation of this file.
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_TCP_IP_H
00065 #define INCLUDE_TCP_IP_H
00066 
00067 #include <inet/datatypes.h>
00068 #include <inet/ethernet.h>
00069 #include <inet/ip.h>
00070 
00071 /* User define                  */
00072 
00081 #define NO_OF_TCPSOCKETS        8
00082 
00091 #define NO_OF_UDPSOCKETS        4
00092 
00100 #define TCP_PORTS_END           1023
00101 
00109 #define UDP_PORTS_END                   1023                                    
00110 
00111 /* UDP Control optios                   */
00112 
00122 #define UDP_OPT_NONE            0
00123 
00132 #define UDP_OPT_SEND_CS         1
00133 
00140 #define UDP_OPT_CHECK_CS        2
00141 
00142 #define UDP_SEND_MTU            ETH_MTU - ETH_HEADER_LEN - UDP_HLEN - IP_MAX_HLEN
00143 
00144 #define UDP_HLEN                        8                               
00146 #define MIN_TCP_HLEN            20
00147 #define MAX_TCP_OPTLEN          40                              
00148 #define TCP_DEF_MTU                     512                             /* Default MTU for TCP                  */
00149 
00160 #define TCP_DEF_RETRIES         7                       
00161 
00169 #define TCP_CON_ATTEMPTS        7
00170 
00180 #define TCP_DEF_KEEPALIVE       4                       
00181 
00189 #define TCP_DEF_RETRY_TOUT      4
00190 
00198 #define TCP_INIT_RETRY_TOUT     1
00199 
00206 #define TCP_SYN_RETRY_TOUT      2
00207 
00214 #define TCP_TOS_NORMAL          0
00215 
00225 #define TCP_DEF_TOUT            120                             
00226 
00227 #define TCP_HALF_SEQ_SPACE      0x0000FFFF              /* For detecting sequence space */
00228 
00229 
00230 /* ICMP message types */
00231 
00232 #define ICMP_TYPE_DEST_UNREACHABLE      3
00233 #define ICMP_ECHO_REQUEST       8
00234 #define ICMP_ECHO_REPLY         0
00235 #define ICMP_CODE_FRAGMENTATION_NEEDED_DF_SET   4
00236 #define ICMP_MTUMSG_LEN 16
00237 #define ICMP_ECHOREQ_HLEN       8
00238 #define ICMP_TEMPIPSET_DATALEN  102
00239 
00240 
00241 /* UDP States                                   */
00242 
00249 #define UDP_STATE_FREE                  1
00250 
00258 #define UDP_STATE_CLOSED                2
00259 
00266 #define UDP_STATE_OPENED                3
00267 
00268 /* UDP Events                                   */
00269 
00276 #define UDP_EVENT_DATA                  64
00277 
00278 
00279 /* TCP FLAGS                                    */
00280 
00281 #define TCP_FLAG_ACK                    0x10
00282 #define TCP_FLAG_PUSH                   0x08
00283 #define TCP_FLAG_RESET                  0x04
00284 #define TCP_FLAG_SYN                    0x02
00285 #define TCP_FLAG_FIN                    0x01
00286 
00287 /* TCP Internal flags                   */
00288 
00289 #define TCP_INTFLAGS_CLOSEPENDING       0x01
00290 
00291 /* TCP socket types                             */
00300 #define TCP_TYPE_NONE                   0x00
00301 
00310 #define TCP_TYPE_SERVER                 0x01
00311 
00320 #define TCP_TYPE_CLIENT                 0x02
00321 
00329 #define TCP_TYPE_CLIENT_SERVER  0x03
00330 
00331 /* TCP States. For more detailed descriptions see RFC793                */
00332 
00333 #define TCP_STATE_FREE                  1       
00334 #define TCP_STATE_RESERVED              2       
00335 #define TCP_STATE_CLOSED                3       
00336 #define TCP_STATE_LISTENING             4       
00339 #define TCP_STATE_SYN_RECEIVED  5       
00343 #define TCP_STATE_SYN_SENT              6       
00346 #define TCP_STATE_FINW1                 7       
00349 #define TCP_STATE_FINW2                 8       
00353 #define TCP_STATE_CLOSING               9       
00356 #define TCP_STATE_LAST_ACK              10      
00359 #define TCP_STATE_TIMED_WAIT    11      
00362 #define TCP_STATE_CONNECTED             12      
00368 /* TCP callback events                  */
00369 
00387 #define TCP_EVENT_CONREQ                1
00388 
00397 #define TCP_EVENT_CONNECTED             2
00398 
00405 #define TCP_EVENT_CLOSE                 4
00406 
00418 #define TCP_EVENT_ABORT                 8
00419 
00428 #define TCP_EVENT_ACK                   16
00429 
00437 #define TCP_EVENT_REGENERATE    32
00438 
00445 #define TCP_EVENT_DATA                  64
00446 
00447 
00448 
00449 /* TCP and UDP buffer handling                  */
00450 
00459 #define TCP_APP_OFFSET                  MIN_TCP_HLEN            /* Application buffers must have        */
00460                                                                                                         /* this much free on start of buf       */
00461 
00471 #define UDP_APP_OFFSET                  UDP_HLEN
00472 
00473 
00474 
00475 /* UDP Structures                       */
00476 
00488 struct udp_frame
00489 {
00490         UINT16 sport;           
00491         UINT16 dport;           
00492         UINT16 tlen;            
00493         UINT16 checksum;        
00494         UINT16 buf_index;       
00497 };
00498 
00506 struct ucb
00507 {
00516         UINT8   state;          
00517         
00523         UINT8   tos;
00524 
00525         UINT16  locport;        
00539         UINT8   opts;           
00540         
00546         INT32   (*event_listener)
00547                         (INT8, UINT8, UINT32, UINT16, UINT16, UINT16 );
00548 }; 
00549 
00550 
00551 
00552 /* TCP Structures                       */
00553 
00564 struct tcp_frame
00565 {
00566         UINT16  sport;                                          
00567         UINT16  dport;                                          
00568         UINT32  seqno;                                          
00569         UINT32  ackno;                                          
00570         UINT16  hlen_flags;                                     
00571         UINT16  window;                                         
00572         UINT16  checksum;                                       
00573         UINT16  urgent;                                         
00574         UINT8   opt[MAX_TCP_OPTLEN + 1];        
00575         UINT16  buf_index;                                      
00578 };
00579 
00589 struct tcb
00590 {
00609         UINT8   state;                                          
00610         
00621         UINT8   type;                                           
00622         UINT8   flags;                                          
00623         UINT32  rem_ip;                                         
00624         UINT16  remport;                                        
00625         UINT16  locport;                                        
00626         UINT32  send_unacked;
00627         UINT8   myflags;                                        
00628         UINT32  send_next;
00629         UINT16  send_mtu;
00630         UINT16  tout;                                           
00631         UINT8   tos;                                            
00632         UINT32  receive_next;
00633         UINT16  persist_timerh;                         
00634         UINT16  retransmit_timerh;                      
00635         UINT8   retries_left;                           
00644         INT32   (*event_listener)(INT8, UINT8, UINT32, UINT32); 
00645         
00646 };
00647 
00648 /* ICMP function prototypes     */
00649 
00650 INT16 process_icmp_in(struct ip_frame*, UINT16);
00651 
00652 /* UDP Function prototypes */
00653 INT8 udp_init (void);
00654 INT8 udp_getsocket (UINT8 , INT32 (* )(INT8, UINT8, UINT32, UINT16, UINT16, UINT16), UINT8 );
00655 INT8 udp_releasesocket (INT8 );
00656 INT8 udp_open (INT8 , UINT16 );
00657 INT8 udp_close (INT8 );
00658 INT16 udp_send (INT8 , UINT32 , UINT16 , UINT8* , UINT16 , UINT16 );
00659 INT16 process_udp_in(struct ip_frame* , UINT16 );
00660 UINT16 udp_getfreeport(void); 
00661 
00662 /*      TCP Function prototypes */
00663 
00664 INT16 process_tcp_in(struct ip_frame*, UINT16);
00665 INT16 process_tcp_out(INT8, UINT8*, UINT16, UINT16);
00666 INT8 tcp_init(void);
00667 INT8 tcp_listen(INT8, UINT16);
00668 INT8 tcp_mapsocket(struct ip_frame*, struct tcp_frame*);
00669 UINT8 tcp_check_cs(struct ip_frame*, UINT16);
00670 void tcp_sendcontrol(INT8);
00671 UINT32 tcp_initseq(void);
00672 void tcp_poll(void);
00673 void tcp_newstate(struct tcb*, UINT8);
00674 INT8 tcp_getsocket(UINT8, UINT8, UINT16, INT32 (*)(INT8, UINT8, UINT32, UINT32) );
00675 INT8 tcp_releasesocket(INT8);
00676 INT8 tcp_connect(INT8, UINT32, UINT16, UINT16);
00677 INT16 tcp_send(INT8, UINT8*, UINT16, UINT16);
00678 INT8 tcp_close(INT8);
00679 void tcp_sendreset(struct tcp_frame*, UINT32);
00680 INT8 tcp_getstate(INT8);
00681 UINT16 tcp_getfreeport(void);
00682 INT16 tcp_checksend(INT8);
00683 INT8 tcp_abort(INT8);
00684 
00685 
00686 
00687 #endif
00688 
00689 

Generated on Sun Aug 3 20:32:59 2003 for OpenTCP by doxygen1.2.18