Čeština / English
Login

SVN Repository / Prohlížení

Aktuální adresář: FITkit / trunk / mcu / libs / enc28j60 /

enc28j60_tcp.h

   1  /*******************************************************************************
   2  
   3     Copyright (C) 2010 Brno University of Technology,
   4                        Faculty of Information Technology
   5     Author(s): Martin Musil <xmusil34 AT fit.vutbr.cz>
   6  
   7     LICENSE TERMS
   8  
   9     Redistribution and use in source and binary forms, with or without
  10     modification, are permitted provided that the following conditions
  11     are met:
  12     1. Redistributions of source code must retain the above copyright
  13        notice, this list of conditions and the following disclaimer.
  14     2. Redistributions in binary form must reproduce the above copyright
  15        notice, this list of conditions and the following disclaimer in
  16        the documentation and/or other materials provided with the
  17        distribution.
  18     3. All advertising materials mentioning features or use of this software
  19        or firmware must display the following acknowledgement:
  20  
  21          This product includes software developed by the University of
  22          Technology, Faculty of Information Technology, Brno and its
  23          contributors.
  24  
  25     4. Neither the name of the Company nor the names of its contributors
  26        may be used to endorse or promote products derived from this
  27        software without specific prior written permission.
  28  
  29     This software or firmware is provided ``as is'', and any express or implied
  30     warranties, including, but not limited to, the implied warranties of
  31     merchantability and fitness for a particular purpose are disclaimed.
  32     In no event shall the company or contributors be liable for any
  33     direct, indirect, incidental, special, exemplary, or consequential
  34     damages (including, but not limited to, procurement of substitute
  35     goods or services; loss of use, data, or profits; or business
  36     interruption) however caused and on any theory of liability, whether
  37     in contract, strict liability, or tort (including negligence or
  38     otherwise) arising in any way out of the use of this software, even
  39     if advised of the possibility of such damage.
  40  
  41     $Id$
  42  
  43  *******************************************************************************/
  44  
  45  /**
  46  	\file enc28j60_tcp.h
  47  
  48  */
  49  
  50  #ifndef _ENC28J60_TCP_
  51  #define _ENC28J60_TCP_
  52  
  53  #include "enc28j60_ip.h"
  54  
  55  
  56  
  57  /**
  58   \cond
  59   **/
  60  
  61  
  62  //TCP flagy
  63  #define TCP_CWR 0x80
  64  #define TCP_ECE 0x40
  65  #define TCP_URG 0x20
  66  #define TCP_ACK 0x10
  67  #define TCP_PSH 0x08
  68  #define TCP_RST 0x04
  69  #define TCP_SYN 0x02
  70  #define TCP_FIN 0x01
  71  
  72  
  73  #define TCP_SERVER	1
  74  #define TCP_CLIENT	2
  75  
  76  
  77  //TCP FSM stavy
  78  #define FSM_IDLE			0
  79  #define FSM_NOT_CONNECTED	1
  80  #define FSM_LISTEN			2
  81  #define FSM_SYN				3
  82  #define FSM_SYN_ACK			4
  83  
  84  #define FSM_ESTABILISHED	5
  85  
  86  #define FSM_FIN_WAIT1		6
  87  #define FSM_HALF_OPEN		7
  88  #define FSM_CLOSE_WAIT		8
  89  #define FSM_TIME_WAIT		9
  90  
  91  
  92  
  93  #define TIME_WAIT_TIMEOUT	5		//zkraceno, mensi cekani po skonceni -> rychleji se uvolni TCP spoj
  94  #define FIN_WAIT1_TIMEOUT	40
  95  #define FIN_TIMEOUT			15
  96  #define CLOSE_WAIT_TIMEOUT	40
  97  #define MAX_RETRANSMIT		40
  98  
  99  
 100  /**
 101   \endcond
 102   **/
 103  
 104  /**
 105  
 106   \struct tcp_h
 107   **/
 108  struct tcp_h{
 109  
 110  
 111  
 112  
 113  
 114  
 115  
 116  	unsigned int window_size;		///< velikost okna
 117  
 118  	unsigned int urgent_ptr;		///< Urgent pointer
 119  };
 120  
 121  ///deklarace TCP callback handleru
 122  #define TCP_APP_HANDLER(x) void (x)(struct ip_h *ip_header, struct tcp_h *tcp_header)
 123  
 124  /**
 125   \cond
 126   **/
 127  
 128  /**
 129   \brief struktura tcp_socket - TCP socket.
 130   \struct tcp_socket
 131   **/
 132  struct tcp_socket{
 133  
 134  
 135  
 136  
 137  
 138  	unsigned char type;				///< typ socketu (klient/server)
 139  };
 140  
 141  /**
 142  
 143  
 144   **/
 145  char tcp_fsm(struct tcp_h * tcp_header);
 146  
 147  /**
 148  
 149  
 150   **/
 151  void tcp_recv(struct ip_h* ip_header);
 152  
 153  /**
 154   \endcond
 155   **/
 156  
 157  /**
 158  
 159  
 160  
 161   **/
 162  char tcp_send();
 163  
 164  /**
 165   \cond
 166   **/
 167  
 168  /**
 169  
 170  
 171  
 172  
 173  
 174  
 175   **/
 176  char tcp_out(unsigned long seq, unsigned long ack, unsigned char flags);
 177  
 178  /**
 179  
 180  
 181  
 182  
 183   **/
 184  unsigned int tcp_checksum(unsigned long dest_ip,unsigned int length);
 185  
 186  /**
 187  
 188  
 189  
 190  
 191   **/
 192  char tcp_send_header(unsigned char flags);
 193  
 194  /**
 195  
 196   **/
 197  void tcp_fsm_reset();
 198  
 199  /**
 200   \endcond
 201   **/
 202  
 203  /**
 204  
 205  
 206   \param src_port - port socketu
 207  
 208  
 209  
 210   **/
 211  unsigned char create_tcp_socket(unsigned int src_port, void* handler);
 212  
 213  /**
 214  
 215  
 216  
 217   **/
 218  char delete_tcp_socket();
 219  
 220  /**
 221  
 222   \param new_handler - Callback handler (TCP_APP_HANDLER()).
 223   **/
 224  void change_tcp_handler(void* new_handler);
 225  
 226  /**
 227  
 228  
 229  
 230  
 231  
 232   **/
 233  char tcp_connect(unsigned long ip, unsigned int port);
 234  
 235  /**
 236  
 237  
 238  
 239   **/
 240  char tcp_bind();
 241  
 242  /**
 243  
 244   \retval 1 - socket odpojen
 245  
 246   **/
 247  char tcp_unbind();
 248  
 249  /**
 250  
 251   **/
 252  inline void tcp_disconnect();
 253  
 254  /**
 255  
 256  
 257  
 258   **/
 259  char tcp_connected();
 260  
 261  /**
 262  
 263  
 264  
 265   **/
 266  char tcp_is_idle();
 267  
 268  /**
 269  
 270  
 271   **/
 272  inline void tcp_timer();
 273  
 274  #endif /*_ENC28J60_TCP_*/
 275  
Zobrazeno: 683842x Naposledy: 5.7.2022 05:04:24