Script for generating fsdata.c file
[oweals/u-boot_mod.git] / u-boot / httpd / uip.h
1 /**
2  * \addtogroup uip
3  * @{
4  */
5
6 /**
7  * \file
8  * Header file for the uIP TCP/IP stack.
9  * \author Adam Dunkels <adam@dunkels.com>
10  *
11  * The uIP TCP/IP stack header file contains definitions for a number
12  * of C macros that are used by uIP programs as well as internal uIP
13  * structures, TCP/IP header structures and function declarations.
14  *
15  */
16
17
18 /*
19  * Copyright (c) 2001-2003, Adam Dunkels.
20  * All rights reserved. 
21  *
22  * Redistribution and use in source and binary forms, with or without 
23  * modification, are permitted provided that the following conditions 
24  * are met: 
25  * 1. Redistributions of source code must retain the above copyright 
26  *    notice, this list of conditions and the following disclaimer. 
27  * 2. Redistributions in binary form must reproduce the above copyright 
28  *    notice, this list of conditions and the following disclaimer in the 
29  *    documentation and/or other materials provided with the distribution. 
30  * 3. The name of the author may not be used to endorse or promote
31  *    products derived from this software without specific prior
32  *    written permission.  
33  *
34  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
35  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
36  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
38  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
40  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
41  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
42  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
43  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
44  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
45  *
46  * This file is part of the uIP TCP/IP stack.
47  *
48  * $Id: uip.h,v 1.36.2.7 2003/10/07 13:47:51 adam Exp $
49  *
50  */
51
52 #ifndef __UIP_H__
53 #define __UIP_H__
54 #include <linux/types.h>
55 #include <linux/string.h>
56 #include <linux/ctype.h>
57 #include <malloc.h>
58 #include <common.h>
59
60
61 #include "uipopt.h"
62
63 /*-----------------------------------------------------------------------------------*/
64 /* First, the functions that should be called from the
65  * system. Initialization, the periodic timer and incoming packets are
66  * handled by the following three functions.
67  */
68
69 /**
70  * \defgroup uipconffunc uIP configuration functions
71  * @{
72  *
73  * The uIP configuration functions are used for setting run-time
74  * parameters in uIP such as IP addresses. 
75  */
76
77 /**
78  * Set the IP address of this host.
79  *
80  * The IP address is represented as a 4-byte array where the first
81  * octet of the IP address is put in the first member of the 4-byte
82  * array.
83  *
84  * \param addr A pointer to a 4-byte representation of the IP address.
85  *
86  * \hideinitializer
87  */
88 #define uip_sethostaddr(addr) do { uip_hostaddr[0] = addr[0]; \
89                               uip_hostaddr[1] = addr[1]; } while(0)
90
91 /**
92  * Get the IP address of this host.
93  *
94  * The IP address is represented as a 4-byte array where the first
95  * octet of the IP address is put in the first member of the 4-byte
96  * array.
97  *
98  * \param addr A pointer to a 4-byte array that will be filled in with
99  * the currently configured IP address.
100  *
101  * \hideinitializer
102  */
103 #define uip_gethostaddr(addr) do { addr[0] = uip_hostaddr[0]; \
104                               addr[1] = uip_hostaddr[1]; } while(0)
105
106 /** @} */
107
108 /**
109  * \defgroup uipinit uIP initialization functions
110  * @{
111  *
112  * The uIP initialization functions are used for booting uIP.
113  */
114
115 /**
116  * uIP initialization function.
117  *
118  * This function should be called at boot up to initilize the uIP
119  * TCP/IP stack.
120  */
121 void uip_init(void);
122
123 /** @} */
124
125 /**
126  * \defgroup uipdevfunc uIP device driver functions
127  * @{
128  *
129  * These functions are used by a network device driver for interacting
130  * with uIP.
131  */
132
133 /**
134  * Process an incoming packet.
135  *
136  * This function should be called when the device driver has received
137  * a packet from the network. The packet from the device driver must
138  * be present in the uip_buf buffer, and the length of the packet
139  * should be placed in the uip_len variable.
140  *
141  * When the function returns, there may be an outbound packet placed
142  * in the uip_buf packet buffer. If so, the uip_len variable is set to
143  * the length of the packet. If no packet is to be sent out, the
144  * uip_len variable is set to 0.
145  *
146  * The usual way of calling the function is presented by the source
147  * code below.
148  \code
149   uip_len = devicedriver_poll();
150   if(uip_len > 0) {
151     uip_input();
152     if(uip_len > 0) {
153       devicedriver_send();
154     }
155   }
156  \endcode
157  *
158  * \note If you are writing a uIP device driver that needs ARP
159  * (Address Resolution Protocol), e.g., when running uIP over
160  * Ethernet, you will need to call the uIP ARP code before calling
161  * this function:
162  \code
163   #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
164   uip_len = ethernet_devicedrver_poll();
165   if(uip_len > 0) {
166     if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
167       uip_arp_ipin();
168       uip_input();
169       if(uip_len > 0) {
170         uip_arp_out();
171         ethernet_devicedriver_send();
172       }
173     } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
174       uip_arp_arpin();
175       if(uip_len > 0) {
176         ethernet_devicedriver_send();
177       }
178     }
179  \endcode
180  *
181  * \hideinitializer
182  */
183 #define uip_input()        uip_process(UIP_DATA)
184
185 /**
186  * Periodic processing for a connection identified by its number.
187  * 
188  * This function does the necessary periodic processing (timers,
189  * polling) for a uIP TCP conneciton, and should be called when the
190  * periodic uIP timer goes off. It should be called for every
191  * connection, regardless of whether they are open of closed.
192  *
193  * When the function returns, it may have an outbound packet waiting
194  * for service in the uIP packet buffer, and if so the uip_len
195  * variable is set to a value larger than zero. The device driver
196  * should be called to send out the packet.
197  *
198  * The ususal way of calling the function is through a for() loop like
199  * this:
200  \code
201   for(i = 0; i < UIP_CONNS; ++i) {
202     uip_periodic(i);
203     if(uip_len > 0) {
204       devicedriver_send();
205     }
206   }
207  \endcode
208  *
209  * \note If you are writing a uIP device driver that needs ARP
210  * (Address Resolution Protocol), e.g., when running uIP over
211  * Ethernet, you will need to call the uip_arp_out() function before
212  * calling the device driver:
213  \code
214   for(i = 0; i < UIP_CONNS; ++i) {
215     uip_periodic(i);
216     if(uip_len > 0) {
217       uip_arp_out();
218       ethernet_devicedriver_send();
219     }
220   }
221  \endcode 
222  *
223  * \param conn The number of the connection which is to be periodically polled.
224  *
225  * \hideinitializer
226  */
227 #define uip_periodic(conn) do { uip_conn = &uip_conns[conn]; \
228                                 uip_process(UIP_TIMER); } while (0)
229
230 /**
231  * Periodic processing for a connection identified by a pointer to its structure.
232  *
233  * Same as uip_periodic() but takes a pointer to the actual uip_conn
234  * struct instead of an integer as its argument. This function can be
235  * used to force periodic processing of a specific connection.
236  *
237  * \param conn A pointer to the uip_conn struct for the connection to
238  * be processed.
239  *
240  * \hideinitializer
241  */
242 #define uip_periodic_conn(conn) do { uip_conn = conn; \
243                                      uip_process(UIP_TIMER); } while (0)
244
245 #if UIP_UDP
246 /**
247  * Periodic processing for a UDP connection identified by its number.
248  *
249  * This function is essentially the same as uip_prerioic(), but for
250  * UDP connections. It is called in a similar fashion as the
251  * uip_periodic() function:
252  \code
253   for(i = 0; i < UIP_UDP_CONNS; i++) {
254     uip_udp_periodic(i);
255     if(uip_len > 0) {
256       devicedriver_send();
257     }
258   }   
259  \endcode
260  *
261  * \note As for the uip_periodic() function, special care has to be
262  * taken when using uIP together with ARP and Ethernet:
263  \code
264   for(i = 0; i < UIP_UDP_CONNS; i++) {
265     uip_udp_periodic(i);
266     if(uip_len > 0) {
267       uip_arp_out();
268       ethernet_devicedriver_send();
269     }
270   }   
271  \endcode
272  *
273  * \param conn The number of the UDP connection to be processed.
274  *
275  * \hideinitializer
276  */
277 #define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \
278                                 uip_process(UIP_UDP_TIMER); } while (0)
279
280 /**
281  * Periodic processing for a UDP connection identified by a pointer to
282  * its structure.
283  *
284  * Same as uip_udp_periodic() but takes a pointer to the actual
285  * uip_conn struct instead of an integer as its argument. This
286  * function can be used to force periodic processing of a specific
287  * connection.
288  *
289  * \param conn A pointer to the uip_udp_conn struct for the connection
290  * to be processed.
291  *
292  * \hideinitializer
293  */
294 #define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn; \
295                                          uip_process(UIP_UDP_TIMER); } while (0)
296
297
298 #endif /* UIP_UDP */
299
300 /**
301  * The uIP packet buffer.
302  *
303  * The uip_buf array is used to hold incoming and outgoing
304  * packets. The device driver should place incoming data into this
305  * buffer. When sending data, the device driver should read the link
306  * level headers and the TCP/IP headers from this buffer. The size of
307  * the link level headers is configured by the UIP_LLH_LEN define.
308  *
309  * \note The application data need not be placed in this buffer, so
310  * the device driver must read it from the place pointed to by the
311  * uip_appdata pointer as illustrated by the following example:
312  \code
313  void
314  devicedriver_send(void)
315  {
316     hwsend(&uip_buf[0], UIP_LLH_LEN);
317     hwsend(&uip_buf[UIP_LLH_LEN], 40);
318     hwsend(uip_appdata, uip_len - 40 - UIP_LLH_LEN);
319  }
320  \endcode
321  */
322 extern u8_t uip_buf[UIP_BUFSIZE+2];
323
324 /** @} */
325
326 /*-----------------------------------------------------------------------------------*/
327 /* Functions that are used by the uIP application program. Opening and
328  * closing connections, sending and receiving data, etc. is all
329  * handled by the functions below.
330 */
331 /**
332  * \defgroup uipappfunc uIP application functions
333  * @{
334  *
335  * Functions used by an application running of top of uIP.
336  */
337
338 /**
339  * Start listening to the specified port.
340  *
341  * \note Since this function expects the port number in network byte
342  * order, a conversion using HTONS() or htons() is necessary.
343  *
344  \code
345  uip_listen(HTONS(80)); 
346  \endcode
347  *
348  * \param port A 16-bit port number in network byte order.
349  */
350 void uip_listen(u16_t port);
351
352 /**
353  * Stop listening to the specified port.
354  *
355  * \note Since this function expects the port number in network byte
356  * order, a conversion using HTONS() or htons() is necessary.
357  *
358  \code
359  uip_unlisten(HTONS(80)); 
360  \endcode
361  *
362  * \param port A 16-bit port number in network byte order.
363  */
364 void uip_unlisten(u16_t port);
365
366 /**
367  * Connect to a remote host using TCP.
368  *
369  * This function is used to start a new connection to the specified
370  * port on the specied host. It allocates a new connection identifier,
371  * sets the connection to the SYN_SENT state and sets the
372  * retransmission timer to 0. This will cause a TCP SYN segment to be
373  * sent out the next time this connection is periodically processed,
374  * which usually is done within 0.5 seconds after the call to
375  * uip_connect().
376  *
377  * \note This function is avaliable only if support for active open
378  * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h.
379  *
380  * \note Since this function requires the port number to be in network
381  * byte order, a convertion using HTONS() or htons() is necessary.
382  *
383  \code
384  u16_t ipaddr[2];
385
386  uip_ipaddr(ipaddr, 192,168,1,2);
387  uip_connect(ipaddr, HTONS(80)); 
388  \endcode
389  * 
390  * \param ripaddr A pointer to a 4-byte array representing the IP
391  * address of the remote hot.
392  *
393  * \param port A 16-bit port number in network byte order.
394  *
395  * \return A pointer to the uIP connection identifier for the new connection,
396  * or NULL if no connection could be allocated.   
397  *
398  */
399 struct uip_conn *uip_connect(u16_t *ripaddr, u16_t port);
400
401
402
403 /**
404  * \internal
405  *
406  * Check if a connection has outstanding (i.e., unacknowledged) data.
407  *
408  * \param conn A pointer to the uip_conn structure for the connection.
409  *
410  * \hideinitializer
411  */
412 #define uip_outstanding(conn) ((conn)->len)
413
414 /**
415  * Send data on the current connection.
416  *
417  * This function is used to send out a single segment of TCP
418  * data. Only applications that have been invoked by uIP for event
419  * processing can send data. 
420  *
421  * The amount of data that actually is sent out after a call to this
422  * funcion is determined by the maximum amount of data TCP allows. uIP
423  * will automatically crop the data so that only the appropriate
424  * amount of data is sent. The function uip_mss() can be used to query
425  * uIP for the amount of data that actually will be sent.
426  * 
427  * \note This function does not guarantee that the sent data will
428  * arrive at the destination. If the data is lost in the network, the
429  * application will be invoked with the uip_rexmit() event being
430  * set. The application will then have to resend the data using this
431  * function.
432  * 
433  * \param data A pointer to the data which is to be sent.
434  *
435  * \param len The maximum amount of data bytes to be sent.
436  *
437  * \hideinitializer
438  */
439 #define uip_send(data, len) do { uip_sappdata = (data); uip_slen = (len);} while(0)   
440
441 /**
442  * The length of any incoming data that is currently avaliable (if avaliable)
443  * in the uip_appdata buffer.
444  *
445  * The test function uip_data() must first be used to check if there
446  * is any data available at all.
447  *
448  * \hideinitializer
449  */
450 #define uip_datalen()       uip_len
451
452 /**
453  * The length of any out-of-band data (urgent data) that has arrived
454  * on the connection.
455  *
456  * \note The configuration parameter UIP_URGDATA must be set for this
457  * function to be enabled.
458  *
459  * \hideinitializer
460  */
461 #define uip_urgdatalen()    uip_urglen
462
463 /**
464  * Close the current connection.
465  *
466  * This function will close the current connection in a nice way.
467  *
468  * \hideinitializer
469  */
470 #define uip_close()         (uip_flags = UIP_CLOSE)
471
472 /**
473  * Abort the current connection.
474  *
475  * This function will abort (reset) the current connection, and is
476  * usually used when an error has occured that prevents using the
477  * uip_close() function.
478  *
479  * \hideinitializer
480  */
481 #define uip_abort()         (uip_flags = UIP_ABORT)
482
483 /**
484  * Tell the sending host to stop sending data.
485  *
486  * This function will close our receiver's window so that we stop
487  * receiving data for the current connection.
488  *
489  * \hideinitializer
490  */
491 #define uip_stop()          (uip_conn->tcpstateflags |= UIP_STOPPED)
492
493 /**
494  * Find out if the current connection has been previously stopped with
495  * uip_stop().
496  *
497  * \hideinitializer
498  */
499 #define uip_stopped(conn)   ((conn)->tcpstateflags & UIP_STOPPED)
500
501 /**
502  * Restart the current connection, if is has previously been stopped
503  * with uip_stop().
504  *
505  * This function will open the receiver's window again so that we
506  * start receiving data for the current connection.
507  *
508  * \hideinitializer
509  */
510 #define uip_restart()         do { uip_flags |= UIP_NEWDATA; \
511                                    uip_conn->tcpstateflags &= ~UIP_STOPPED; \
512                               } while(0)
513
514
515 /* uIP tests that can be made to determine in what state the current
516    connection is, and what the application function should do. */
517
518 /**
519  * Is new incoming data available?
520  *
521  * Will reduce to non-zero if there is new data for the application
522  * present at the uip_appdata pointer. The size of the data is
523  * avaliable through the uip_len variable.
524  *
525  * \hideinitializer
526  */
527 #define uip_newdata()   (uip_flags & UIP_NEWDATA)
528
529 /**
530  * Has previously sent data been acknowledged?
531  *
532  * Will reduce to non-zero if the previously sent data has been
533  * acknowledged by the remote host. This means that the application
534  * can send new data. 
535  *
536  * \hideinitializer
537  */
538 #define uip_acked()   (uip_flags & UIP_ACKDATA)
539
540 /**
541  * Has the connection just been connected?  
542  *
543  * Reduces to non-zero if the current connection has been connected to
544  * a remote host. This will happen both if the connection has been
545  * actively opened (with uip_connect()) or passively opened (with
546  * uip_listen()).
547  *
548  * \hideinitializer
549  */
550 #define uip_connected() (uip_flags & UIP_CONNECTED)
551
552 /**
553  * Has the connection been closed by the other end?
554  *
555  * Is non-zero if the connection has been closed by the remote
556  * host. The application may then do the necessary clean-ups.
557  *
558  * \hideinitializer
559  */
560 #define uip_closed()    (uip_flags & UIP_CLOSE)
561
562 /**
563  * Has the connection been aborted by the other end?
564  *
565  * Non-zero if the current connection has been aborted (reset) by the
566  * remote host.
567  *
568  * \hideinitializer
569  */
570 #define uip_aborted()    (uip_flags & UIP_ABORT)
571
572 /**
573  * Has the connection timed out?
574  *
575  * Non-zero if the current connection has been aborted due to too many
576  * retransmissions.
577  *
578  * \hideinitializer
579  */
580 #define uip_timedout()    (uip_flags & UIP_TIMEDOUT)
581
582 /**
583  * Do we need to retransmit previously data?
584  *
585  * Reduces to non-zero if the previously sent data has been lost in
586  * the network, and the application should retransmit it. The
587  * application should send the exact same data as it did the last
588  * time, using the uip_send() function.
589  *
590  * \hideinitializer
591  */
592 #define uip_rexmit()     (uip_flags & UIP_REXMIT)
593
594 /**
595  * Is the connection being polled by uIP?
596  *
597  * Is non-zero if the reason the application is invoked is that the
598  * current connection has been idle for a while and should be
599  * polled.
600  *
601  * The polling event can be used for sending data without having to
602  * wait for the remote host to send data.
603  *
604  * \hideinitializer
605  */ 
606 #define uip_poll()       (uip_flags & UIP_POLL)
607
608 /**
609  * Get the initial maxium segment size (MSS) of the current
610  * connection.
611  *
612  * \hideinitializer
613  */
614 #define uip_initialmss()             (uip_conn->initialmss)
615
616 /**
617  * Get the current maxium segment size that can be sent on the current
618  * connection.
619  *
620  * The current maxiumum segment size that can be sent on the
621  * connection is computed from the receiver's window and the MSS of
622  * the connection (which also is available by calling
623  * uip_initialmss()).
624  *
625  * \hideinitializer
626  */
627 #define uip_mss()             (uip_conn->mss)
628
629 /**
630  * Set up a new UDP connection.
631  *
632  * \param ripaddr A pointer to a 4-byte structure representing the IP
633  * address of the remote host.
634  *
635  * \param rport The remote port number in network byte order.
636  *
637  * \return The uip_udp_conn structure for the new connection or NULL
638  * if no connection could be allocated.
639  */
640 struct uip_udp_conn *uip_udp_new(u16_t *ripaddr, u16_t rport);
641
642 /**
643  * Removed a UDP connection.
644  *
645  * \param conn A pointer to the uip_udp_conn structure for the connection.
646  *
647  * \hideinitializer
648  */
649 #define uip_udp_remove(conn) (conn)->lport = 0
650
651 /**
652  * Send a UDP datagram of length len on the current connection.
653  *
654  * This function can only be called in response to a UDP event (poll
655  * or newdata). The data must be present in the uip_buf buffer, at the
656  * place pointed to by the uip_appdata pointer.
657  *
658  * \param len The length of the data in the uip_buf buffer.
659  *
660  * \hideinitializer
661  */
662 #define uip_udp_send(len) uip_slen = (len)
663
664 /** @} */
665
666 /* uIP convenience and converting functions. */
667
668 /**
669  * \defgroup uipconvfunc uIP conversion functions
670  * @{
671  *
672  * These functions can be used for converting between different data
673  * formats used by uIP.
674  */
675  
676 /**
677  * Pack an IP address into a 4-byte array which is used by uIP to
678  * represent IP addresses.
679  *
680  * Example:
681  \code
682  u16_t ipaddr[2];
683
684  uip_ipaddr(&ipaddr, 192,168,1,2); 
685  \endcode
686  *
687  * \param addr A pointer to a 4-byte array that will be filled in with
688  * the IP addres.
689  * \param addr0 The first octet of the IP address.
690  * \param addr1 The second octet of the IP address.
691  * \param addr2 The third octet of the IP address.
692  * \param addr3 The forth octet of the IP address. 
693  *
694  * \hideinitializer
695  */
696 #define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \
697                      (addr)[0] = HTONS(((addr0) << 8) | (addr1)); \
698                      (addr)[1] = HTONS(((addr2) << 8) | (addr3)); \
699                   } while(0)
700
701 /**
702  * Convert 16-bit quantity from host byte order to network byte order.
703  *
704  * This macro is primarily used for converting constants from host
705  * byte order to network byte order. For converting variables to
706  * network byte order, use the htons() function instead.
707  *
708  * \hideinitializer
709  */
710 #ifndef HTONS
711 #   if BYTE_ORDER == BIG_ENDIAN
712 #      define HTONS(n) (n)
713 #   else /* BYTE_ORDER == BIG_ENDIAN */
714 #      define HTONS(n) ((((u16_t)((n) & 0xff)) << 8) | (((n) & 0xff00) >> 8))
715 #   endif /* BYTE_ORDER == BIG_ENDIAN */
716 #endif /* HTONS */
717
718 /**
719  * Convert 16-bit quantity from host byte order to network byte order.
720  *
721  * This function is primarily used for converting variables from host
722  * byte order to network byte order. For converting constants to
723  * network byte order, use the HTONS() macro instead.
724  */
725 #ifndef htons
726 u16_t htons(u16_t val);
727 #endif /* htons */
728
729 /** @} */
730
731 /**
732  * Pointer to the application data in the packet buffer.
733  *
734  * This pointer points to the application data when the application is
735  * called. If the application wishes to send data, the application may
736  * use this space to write the data into before calling uip_send().
737  */
738 extern volatile u8_t *uip_appdata;
739 extern volatile u8_t *uip_sappdata; 
740
741 #if UIP_URGDATA > 0 
742 /* u8_t *uip_urgdata:
743  *
744  * This pointer points to any urgent data that has been received. Only
745  * present if compiled with support for urgent data (UIP_URGDATA).
746  */
747 extern volatile u8_t *uip_urgdata; 
748 #endif /* UIP_URGDATA > 0 */
749
750
751 /* u[8|16]_t uip_len:
752  *
753  * When the application is called, uip_len contains the length of any
754  * new data that has been received from the remote host. The
755  * application should set this variable to the size of any data that
756  * the application wishes to send. When the network device driver
757  * output function is called, uip_len should contain the length of the
758  * outgoing packet.
759  */
760 extern volatile u16_t uip_len, uip_slen;
761
762 #if UIP_URGDATA > 0 
763 extern volatile u8_t uip_urglen, uip_surglen;
764 #endif /* UIP_URGDATA > 0 */
765
766
767 /**
768  * Representation of a uIP TCP connection.
769  *
770  * The uip_conn structure is used for identifying a connection. All
771  * but one field in the structure are to be considered read-only by an
772  * application. The only exception is the appstate field whos purpose
773  * is to let the application store application-specific state (e.g.,
774  * file pointers) for the connection. The size of this field is
775  * configured in the "uipopt.h" header file.
776  */
777 struct uip_conn {
778   u16_t ripaddr[2];   /**< The IP address of the remote host. */
779   
780   u16_t lport;        /**< The local TCP port, in network byte order. */
781   u16_t rport;        /**< The local remote TCP port, in network byte
782                          order. */  
783   
784   u8_t rcv_nxt[4];    /**< The sequence number that we expect to
785                          receive next. */
786   u8_t snd_nxt[4];    /**< The sequence number that was last sent by
787                          us. */
788   u16_t len;          /**< Length of the data that was previously sent. */
789   u16_t mss;          /**< Current maximum segment size for the
790                          connection. */
791   u16_t initialmss;   /**< Initial maximum segment size for the
792                          connection. */  
793   u8_t sa;            /**< Retransmission time-out calculation state
794                          variable. */
795   u8_t sv;            /**< Retransmission time-out calculation state
796                          variable. */
797   u8_t rto;           /**< Retransmission time-out. */
798   u8_t tcpstateflags; /**< TCP state and flags. */
799   u8_t timer;         /**< The retransmission timer. */
800   u8_t nrtx;          /**< The number of retransmissions for the last
801                          segment sent. */
802
803   /** The application state. */
804   u8_t appstate[UIP_APPSTATE_SIZE];  
805 };
806
807
808 /* Pointer to the current connection. */
809 extern struct uip_conn *uip_conn;
810 /* The array containing all uIP connections. */
811 extern struct uip_conn uip_conns[UIP_CONNS];
812 /**
813  * \addtogroup uiparch
814  * @{
815  */
816
817 /**
818  * 4-byte array used for the 32-bit sequence number calculations.
819  */
820 extern volatile u8_t uip_acc32[4];
821
822 /** @} */
823
824
825 #if UIP_UDP
826 /**
827  * Representation of a uIP UDP connection.
828  */
829 struct uip_udp_conn {
830   u16_t ripaddr[2];   /**< The IP address of the remote peer. */
831   u16_t lport;        /**< The local port number in network byte order. */
832   u16_t rport;        /**< The remote port number in network byte order. */
833 };
834
835 extern struct uip_udp_conn *uip_udp_conn;
836 extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
837 #endif /* UIP_UDP */
838
839 /**
840  * The structure holding the TCP/IP statistics that are gathered if
841  * UIP_STATISTICS is set to 1.
842  *
843  */
844 struct uip_stats {
845   struct {
846     uip_stats_t drop;     /**< Number of dropped packets at the IP
847                              layer. */
848     uip_stats_t recv;     /**< Number of received packets at the IP
849                              layer. */
850     uip_stats_t sent;     /**< Number of sent packets at the IP
851                              layer. */
852     uip_stats_t vhlerr;   /**< Number of packets dropped due to wrong
853                              IP version or header length. */
854     uip_stats_t hblenerr; /**< Number of packets dropped due to wrong
855                              IP length, high byte. */
856     uip_stats_t lblenerr; /**< Number of packets dropped due to wrong
857                              IP length, low byte. */
858     uip_stats_t fragerr;  /**< Number of packets dropped since they
859                              were IP fragments. */
860     uip_stats_t chkerr;   /**< Number of packets dropped due to IP
861                              checksum errors. */
862     uip_stats_t protoerr; /**< Number of packets dropped since they
863                              were neither ICMP, UDP nor TCP. */
864   } ip;                   /**< IP statistics. */
865   struct {
866     uip_stats_t drop;     /**< Number of dropped ICMP packets. */
867     uip_stats_t recv;     /**< Number of received ICMP packets. */
868     uip_stats_t sent;     /**< Number of sent ICMP packets. */
869     uip_stats_t typeerr;  /**< Number of ICMP packets with a wrong
870                              type. */
871   } icmp;                 /**< ICMP statistics. */
872   struct {
873     uip_stats_t drop;     /**< Number of dropped TCP segments. */
874     uip_stats_t recv;     /**< Number of recived TCP segments. */
875     uip_stats_t sent;     /**< Number of sent TCP segments. */
876     uip_stats_t chkerr;   /**< Number of TCP segments with a bad
877                              checksum. */
878     uip_stats_t ackerr;   /**< Number of TCP segments with a bad ACK
879                              number. */
880     uip_stats_t rst;      /**< Number of recevied TCP RST (reset) segments. */
881     uip_stats_t rexmit;   /**< Number of retransmitted TCP segments. */
882     uip_stats_t syndrop;  /**< Number of dropped SYNs due to too few
883                              connections was avaliable. */
884     uip_stats_t synrst;   /**< Number of SYNs for closed ports,
885                              triggering a RST. */
886   } tcp;                  /**< TCP statistics. */
887 };
888
889 /**
890  * The uIP TCP/IP statistics.
891  *
892  * This is the variable in which the uIP TCP/IP statistics are gathered.
893  */
894 extern struct uip_stats uip_stat;
895
896
897 /*-----------------------------------------------------------------------------------*/
898 /* All the stuff below this point is internal to uIP and should not be
899  * used directly by an application or by a device driver.
900  */
901 /*-----------------------------------------------------------------------------------*/
902 /* u8_t uip_flags:
903  *
904  * When the application is called, uip_flags will contain the flags
905  * that are defined in this file. Please read below for more
906  * infomation.
907  */
908 extern volatile u8_t uip_flags;
909
910 /* The following flags may be set in the global variable uip_flags
911    before calling the application callback. The UIP_ACKDATA and
912    UIP_NEWDATA flags may both be set at the same time, whereas the
913    others are mutualy exclusive. Note that these flags should *NOT* be
914    accessed directly, but through the uIP functions/macros. */
915
916 #define UIP_ACKDATA   1     /* Signifies that the outstanding data was
917                                acked and the application should send
918                                out new data instead of retransmitting
919                                the last data. */
920 #define UIP_NEWDATA   2     /* Flags the fact that the peer has sent
921                                us new data. */
922 #define UIP_REXMIT    4     /* Tells the application to retransmit the
923                                data that was last sent. */
924 #define UIP_POLL      8     /* Used for polling the application, to
925                                check if the application has data that
926                                it wants to send. */
927 #define UIP_CLOSE     16    /* The remote host has closed the
928                                connection, thus the connection has
929                                gone away. Or the application signals
930                                that it wants to close the
931                                connection. */
932 #define UIP_ABORT     32    /* The remote host has aborted the
933                                connection, thus the connection has
934                                gone away. Or the application signals
935                                that it wants to abort the
936                                connection. */
937 #define UIP_CONNECTED 64    /* We have got a connection from a remote
938                                host and have set up a new connection
939                                for it, or an active connection has
940                                been successfully established. */
941
942 #define UIP_TIMEDOUT  128   /* The connection has been aborted due to
943                                too many retransmissions. */
944
945
946 /* uip_process(flag):
947  *
948  * The actual uIP function which does all the work.
949  */
950 void uip_process(u8_t flag);
951
952 /* The following flags are passed as an argument to the uip_process()
953    function. They are used to distinguish between the two cases where
954    uip_process() is called. It can be called either because we have
955    incoming data that should be processed, or because the periodic
956    timer has fired. */
957
958 #define UIP_DATA    1     /* Tells uIP that there is incoming data in
959                              the uip_buf buffer. The length of the
960                              data is stored in the global variable
961                              uip_len. */
962 #define UIP_TIMER   2     /* Tells uIP that the periodic timer has
963                              fired. */
964 #if UIP_UDP
965 #define UIP_UDP_TIMER 3
966 #endif /* UIP_UDP */
967
968 /* The TCP states used in the uip_conn->tcpstateflags. */
969 #define CLOSED      0
970 #define SYN_RCVD    1
971 #define SYN_SENT    2
972 #define ESTABLISHED 3
973 #define FIN_WAIT_1  4
974 #define FIN_WAIT_2  5
975 #define CLOSING     6
976 #define TIME_WAIT   7
977 #define LAST_ACK    8
978 #define TS_MASK     15
979   
980 #define UIP_STOPPED      16
981
982 #define UIP_TCPIP_HLEN 40
983
984 /* The TCP and IP headers. */
985 typedef struct {
986   /* IP header. */
987   u8_t vhl,
988     tos,          
989     len[2],       
990     ipid[2],        
991     ipoffset[2],  
992     ttl,          
993     proto;     
994   u16_t ipchksum;
995   u16_t srcipaddr[2], 
996     destipaddr[2];
997   
998   /* TCP header. */
999   u16_t srcport,
1000     destport;
1001   u8_t seqno[4],  
1002     ackno[4],
1003     tcpoffset,
1004     flags,
1005     wnd[2];     
1006   u16_t tcpchksum;
1007   u8_t urgp[2];
1008   u8_t optdata[4];
1009 } uip_tcpip_hdr;
1010
1011 /* The ICMP and IP headers. */
1012 typedef struct {
1013   /* IP header. */
1014   u8_t vhl,
1015     tos,          
1016     len[2],       
1017     ipid[2],        
1018     ipoffset[2],  
1019     ttl,          
1020     proto;     
1021   u16_t ipchksum;
1022   u16_t srcipaddr[2], 
1023     destipaddr[2];
1024   /* ICMP (echo) header. */
1025   u8_t type, icode;
1026   u16_t icmpchksum;
1027   u16_t id, seqno;  
1028 } uip_icmpip_hdr;
1029
1030
1031 /* The UDP and IP headers. */
1032 typedef struct {
1033   /* IP header. */
1034   u8_t vhl,
1035     tos,          
1036     len[2],       
1037     ipid[2],        
1038     ipoffset[2],  
1039     ttl,          
1040     proto;     
1041   u16_t ipchksum;
1042   u16_t srcipaddr[2], 
1043     destipaddr[2];
1044   
1045   /* UDP header. */
1046   u16_t srcport,
1047     destport;
1048   u16_t udplen;
1049   u16_t udpchksum;
1050 } uip_udpip_hdr;
1051
1052 #define UIP_PROTO_ICMP  1
1053 #define UIP_PROTO_TCP   6
1054 #define UIP_PROTO_UDP   17
1055
1056 #if UIP_FIXEDADDR
1057 extern const u16_t uip_hostaddr[2];
1058 #else /* UIP_FIXEDADDR */
1059 extern u16_t uip_hostaddr[2];
1060 #endif /* UIP_FIXEDADDR */
1061
1062 #endif /* __UIP_H__ */
1063
1064
1065 /** @} */
1066