blob: 877f35c24783e8cae318584f56e6c216aee04e47 [file] [log] [blame]
adamdunkels1e45c6d2003-09-02 21:47:27 +00001/**
2 * \file
3 * Header file for the uIP TCP/IP stack.
4 * \author Adam Dunkels <adam@dunkels.com>
5 *
6 * The uIP TCP/IP stack header file contains definitions for a number
7 * of C macros that are used by uIP programs as well as internal uIP
8 * structures, TCP/IP header structures and function declarations.
9 *
10 */
11
adamdunkelsca9ddcb2003-03-19 14:13:31 +000012/*
adamdunkels1e45c6d2003-09-02 21:47:27 +000013 * Copyright (c) 2001-2003, Adam Dunkels.
adamdunkelsca9ddcb2003-03-19 14:13:31 +000014 * All rights reserved.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
adamdunkels1e45c6d2003-09-02 21:47:27 +000024 * 3. The name of the author may not be used to endorse or promote
adamdunkelsca9ddcb2003-03-19 14:13:31 +000025 * products derived from this software without specific prior
26 * written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
29 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
32 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
34 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * This file is part of the uIP TCP/IP stack.
41 *
adamdunkels1e45c6d2003-09-02 21:47:27 +000042 * $Id: uip.h,v 1.7 2003/09/02 21:47:29 adamdunkels Exp $
adamdunkelsca9ddcb2003-03-19 14:13:31 +000043 *
44 */
45
46#ifndef __UIP_H__
47#define __UIP_H__
48
49#include "uipopt.h"
50
adamdunkelsca9ddcb2003-03-19 14:13:31 +000051/*-----------------------------------------------------------------------------------*/
52/* First, the functions that should be called from the
53 * system. Initialization, the periodic timer and incoming packets are
54 * handled by the following three functions.
55 */
56
adamdunkels1e45c6d2003-09-02 21:47:27 +000057/**
58 * Set the IP address of this host.
adamdunkelsca9ddcb2003-03-19 14:13:31 +000059 *
adamdunkels1e45c6d2003-09-02 21:47:27 +000060 * The IP address is represented as a 4-byte array where the first
61 * octet of the IP address is put in the first member of the 4-byte
62 * array.
adamdunkelsca9ddcb2003-03-19 14:13:31 +000063 *
adamdunkels1e45c6d2003-09-02 21:47:27 +000064 * \param addr A pointer to a 4-byte representation of the IP address.
adamdunkelsca9ddcb2003-03-19 14:13:31 +000065 */
66#define uip_sethostaddr(addr) do { uip_hostaddr[0] = addr[0]; \
67 uip_hostaddr[1] = addr[1]; } while(0)
68
adamdunkels1e45c6d2003-09-02 21:47:27 +000069/**
70 * Get the IP address of this host.
adamdunkels66c6af62003-04-16 18:28:16 +000071 *
adamdunkels1e45c6d2003-09-02 21:47:27 +000072 * The IP address is represented as a 4-byte array where the first
73 * octet of the IP address is put in the first member of the 4-byte
74 * array.
75 *
76 * \param addr A pointer to a 4-byte array that will be filled in with
77 * the currently configured IP address.
adamdunkels66c6af62003-04-16 18:28:16 +000078 */
79#define uip_gethostaddr(addr) do { addr[0] = uip_hostaddr[0]; \
80 addr[1] = uip_hostaddr[1]; } while(0)
81
adamdunkels1e45c6d2003-09-02 21:47:27 +000082/**
83 * Process an incoming packet.
84 *
85 * This function should be called when the device driver has received
86 * a packet from the network. The packet from the device driver must
87 * be present in the uip_buf buffer, and the length of the packet
88 * should be placed in the uip_len variable.
89 *
90 * When the function returns, there may be an outbound packet placed
91 * in the uip_buf packet buffer. If so, the uip_len variable is set to
92 * the length of the packet. If no packet is to be sent out, the
93 * uip_len variable is set to 0.
94 *
95 * The usual way of calling the function is presented by the source
96 * code below.
97 \code
98 uip_len = devicedriver_poll();
99 if(uip_len > 0) {
100 uip_input();
101 if(uip_len > 0) {
102 devicedriver_send();
103 }
104 }
105 \endcode
106 *
107 * \note If you are writing a uIP device driver that needs ARP
108 * (Address Resolution Protocol), e.g., when running uIP over
109 * Ethernet, you will need to call the uIP ARP code before calling
110 * this function:
111 \code
112 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
113 uip_len = ethernet_devicedrver_poll();
114 if(uip_len > 0) {
115 if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
116 uip_arp_ipin();
117 uip_len -= sizeof(struct uip_eth_hdr);
118 uip_input();
119 if(uip_len > 0) {
120 uip_arp_out();
121 ethernet_devicedriver_send();
122 }
123 } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
124 uip_arp_arpin();
125 if(uip_len > 0) {
126 ethernet_devicedriver_send();
127 }
128 }
129 \endcode
130 */
131#define uip_input() uip_process(UIP_DATA)
132
133/**
134 * uIP initialization function.
135 *
136 * This function should be called at boot up to initilize the uIP
137 * TCP/IP stack.
138 */
139void uip_init(void);
140
141/**
142 * Periodic processing for a connection identified by its number.
143 *
144 * This function does the necessary periodic processing (timers,
145 * polling) for a uIP TCP conneciton, and should be called when the
146 * periodic uIP timer goes off. It should be called for every
147 * connection, regardless of whether they are open of closed.
148 *
149 * When the function returns, it may have an outbound packet waiting
150 * for service in the uIP packet buffer, and if so the uip_len
151 * variable is set to a value larger than zero. The device driver
152 * should be called to send out the packet.
153 *
154 * The ususal way of calling the function is through a for() loop like
155 * this:
156 \code
157 for(i = 0; i < UIP_CONNS; ++i) {
158 uip_periodic(i);
159 if(uip_len > 0) {
160 devicedriver_send();
161 }
162 }
163 \endcode
164 *
165 * \note If you are writing a uIP device driver that needs ARP
166 * (Address Resolution Protocol), e.g., when running uIP over
167 * Ethernet, you will need to call the uip_arp_out() function before
168 * calling the device driver:
169 \code
170 for(i = 0; i < UIP_CONNS; ++i) {
171 uip_periodic(i);
172 if(uip_len > 0) {
173 uip_arp_out();
174 ethernet_devicedriver_send();
175 }
176 }
177 \endcode
178 *
179 * \param conn The number of the connection which is to be periodically polled.
180 */
181#define uip_periodic(conn) do { uip_conn = &uip_conns[conn]; \
182 uip_process(UIP_TIMER); } while (0)
183
184/**
185 * Periodic processing for a connection identified by a pointer to its structure.
186 *
187 * Same as uip_periodic() but takes a pointer to the actual uip_conn
188 * struct instead of an integer as its argument. This function can be
189 * used to force periodic processing of a specific connection.
190 *
191 * \param conn A pointer to the uip_conn struct for the connection to
192 * be processed.
193 */
194#define uip_periodic_conn(conn) do { uip_conn = conn; \
195 uip_process(UIP_TIMER); } while (0)
196
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000197#if UIP_UDP
adamdunkels1e45c6d2003-09-02 21:47:27 +0000198/**
199 * Periodic processing for a UDP connection identified by its number.
200 *
201 * This function is essentially the same as uip_prerioic(), but for
202 * UDP connections. It is called in a similar fashion as the
203 * uip_periodic() function:
204 \code
205 for(i = 0; i < UIP_UDP_CONNS; i++) {
206 uip_udp_periodic(i);
207 if(uip_len > 0) {
208 devicedriver_send();
209 }
210 }
211 \endcode
212 *
213 * \note As for the uip_periodic() function, special care has to be
214 * taken when using uIP together with ARP and Ethernet:
215 \code
216 for(i = 0; i < UIP_UDP_CONNS; i++) {
217 uip_udp_periodic(i);
218 if(uip_len > 0) {
219 uip_arp_out();
220 ethernet_devicedriver_send();
221 }
222 }
223 \endcode
224 *
225 * \param conn The number of the UDP connection to be processed.
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000226 */
227#define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \
228 uip_process(UIP_UDP_TIMER); } while (0)
adamdunkelseb91d5f2003-08-20 20:58:08 +0000229
adamdunkels1e45c6d2003-09-02 21:47:27 +0000230/**
231 * Periodic processing for a UDP connection identified by a pointer to
232 * its structure.
233 *
234 * Same as uip_udp_periodic() but takes a pointer to the actual
235 * uip_conn struct instead of an integer as its argument. This
236 * function can be used to force periodic processing of a specific
237 * connection.
238 *
239 * \param conn A pointer to the uip_udp_conn struct for the connection
240 * to be processed.
adamdunkelseb91d5f2003-08-20 20:58:08 +0000241 */
242#define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn; \
243 uip_process(UIP_UDP_TIMER); } while (0)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000244#endif /* UIP_UDP */
245/*-----------------------------------------------------------------------------------*/
246/* Functions that are used by the uIP application program. Opening and
247 * closing connections, sending and receiving data, etc. is all
248 * handled by the functions below.
249*/
250
adamdunkels1e45c6d2003-09-02 21:47:27 +0000251/**
252 * Start listening to the specified port.
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000253 *
adamdunkels1e45c6d2003-09-02 21:47:27 +0000254 * \note Since this function expects the port number in network byte
255 * order, a conversion using HTONS() or htons() is necessary.
256 *
257 \code
258 uip_listen(HTONS(80));
259 \endcode
260 *
261 * \param port A 16-bit port number in network byte order.
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000262 */
263void uip_listen(u16_t port);
264
adamdunkels1e45c6d2003-09-02 21:47:27 +0000265/**
266 * Stop listening to the specified port.
adamdunkelscd8c3a22003-08-13 22:52:48 +0000267 *
adamdunkels1e45c6d2003-09-02 21:47:27 +0000268 * \note Since this function expects the port number in network byte
269 * order, a conversion using HTONS() or htons() is necessary.
270 *
271 \code
272 uip_unlisten(HTONS(80));
273 \endcode
274 *
275 * \param port A 16-bit port number in network byte order.
adamdunkelscd8c3a22003-08-13 22:52:48 +0000276 */
277void uip_unlisten(u16_t port);
278
adamdunkels1e45c6d2003-09-02 21:47:27 +0000279/**
280 * Connect to a remote host using TCP.
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000281 *
adamdunkels1e45c6d2003-09-02 21:47:27 +0000282 * This function is used to start a new connection to the specified
283 * port on the specied host. It allocates a new connection identifier,
284 * sets the connection to the SYN_SENT state and sets the
285 * retransmission timer to 0. This will cause a TCP SYN segment to be
286 * sent out the next time this connection is periodically processed,
287 * which usually is done within 0.5 seconds after the call to
288 * uip_connect().
289 *
290 * \note This function is avaliable only if support for active open
291 * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h.
292 *
293 * \note Since this function requires the port number to be in network
294 * byte order, a convertion using HTONS() or htons() is necessary.
295 *
296 \code
297 u16_t ipaddr[2];
298
299 uip_ipaddr(ipaddr, 192,168,1,2);
300 uip_connect(ipaddr, HTONS(80));
301 \endcode
302 *
303 * \param ripaddr A pointer to a 4-byte array representing the IP
304 * address of the remote hot.
305 *
306 * \param port A 16-bit port number in network byte order.
307 *
308 * \return A pointer to the uIP connection identifier for the new connection,
309 * or NULL if no connection could be allocated.
310 *
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000311 */
312struct uip_conn *uip_connect(u16_t *ripaddr, u16_t port);
313
314#if UIP_UDP
315/* uip_udp_new(ripaddr, rport):
316 *
317 * Sets up a new UDP "connection" with the specified parameters.
318 */
319struct uip_udp_conn *uip_udp_new(u16_t *ripaddr, u16_t rport);
320
321/* uip_udp_remove(conn):
322 *
323 * Removes the UDP "connection".
324 */
325#define uip_udp_remove(conn) (conn)->lport = 0
326
327/* uip_udp_send(len):
328 *
329 * Sends a UDP datagram of length len. The data must be present in the
330 * uip_buf buffer (pointed to by uip_appdata).
331 */
332#define uip_udp_send(len) uip_slen = (len)
333#endif /* UIP_UDP */
334
335
336/* uip_outstanding(conn):
337 *
338 * Checks whether a connection has outstanding (i.e., unacknowledged)
339 * data.
340 */
341#define uip_outstanding(conn) ((conn)->len)
342
343/* uip_send(data, len):
344 *
345 * Send data on the current connection. The length of the data must
346 * not exceed the maxium segment size (MSS) for the connection.
347 */
348#define uip_send(data, len) do { uip_appdata = (data); uip_slen = (len);} while(0)
349
350/* uip_datalen():
351 *
352 * The length of the data that is currently avaliable (if avaliable)
353 * in the uip_appdata buffer. The test function uip_data() is
354 * used to check if data is avaliable.
355 */
356#define uip_datalen() uip_len
357
358#define uip_urgdatalen() uip_urglen
359
360/* uip_close():
361 *
362 * Close the current connection.
363 */
364#define uip_close() (uip_flags = UIP_CLOSE)
365
366/* uip_abort():
367 *
368 * Abort the current connection.
369 */
370#define uip_abort() (uip_flags = UIP_ABORT)
371
372/* uip_stop():
373 *
374 * Close our receiver's window so that we stop receiving data for the
375 * current connection.
376 */
377#define uip_stop() (uip_conn->tcpstateflags |= UIP_STOPPED)
378
379/* uip_stopped():
380 *
381 * Find out if the current connection has been previously stopped.
382 */
383#define uip_stopped(conn) ((conn)->tcpstateflags & UIP_STOPPED)
384
385/* uip_restart():
386 *
387 * Open the window again so that we start receiving data for the
388 * current connection.
389 */
390#define uip_restart() do { uip_flags |= UIP_NEWDATA; \
391 uip_conn->tcpstateflags &= ~UIP_STOPPED; \
392 } while(0)
393
394
395/* uIP tests that can be made to determine in what state the current
396 connection is, and what the application function should do. */
397
398/* uip_newdata():
399 *
400 * Will reduce to non-zero if there is new data for the application
401 * present at the uip_appdata pointer. The size of the data is
402 * avaliable through the uip_len variable.
403 */
404#define uip_newdata() (uip_flags & UIP_NEWDATA)
405
406/* uip_acked():
407 *
408 * Will reduce to non-zero if the previously sent data has been
409 * acknowledged by the remote host. This means that the application
410 * can send new data. uip_reset_acked() can be used to reset the acked
411 * flag.
412 */
413#define uip_acked() (uip_flags & UIP_ACKDATA)
414#define uip_reset_acked() (uip_flags &= ~UIP_ACKDATA)
415
416/* uip_connected():
417 *
418 * Reduces to non-zero if the current connection has been connected to
419 * a remote host. This will happen both if the connection has been
420 * actively opened (with uip_connect()) or passively opened (with
421 * uip_listen()).
422 */
423#define uip_connected() (uip_flags & UIP_CONNECTED)
424
425/* uip_closed():
426 *
427 * Is non-zero if the connection has been closed by the remote
428 * host. The application may do the necessary clean-ups.
429 */
430#define uip_closed() (uip_flags & UIP_CLOSE)
431
432/* uip_aborted():
433 *
434 * Non-zero if the current connection has been aborted (reset) by the
435 * remote host.
436 */
437#define uip_aborted() (uip_flags & UIP_ABORT)
438
439/* uip_timedout():
440 *
441 * Non-zero if the current connection has been aborted due to too many
442 * retransmissions.
443 */
444#define uip_timedout() (uip_flags & UIP_TIMEDOUT)
445
446/* uip_rexmit():
447 *
448 * Reduces to non-zero if the previously sent data has been lost in
449 * the network, and the application should retransmit it. The
450 * application should set the uip_appdata buffer and the uip_len
451 * variable just as it did the last time this data was to be
452 * transmitted.
453 */
454#define uip_rexmit() (uip_flags & UIP_REXMIT)
455
456/* uip_poll():
457 *
458 * Is non-zero if the reason the application is invoked is that the
459 * current connection has been idle for a while and should be
460 * polled.
461 */
462#define uip_poll() (uip_flags & UIP_POLL)
463
464/* uip_mss():
465 *
466 * Gives the current maxium segment size (MSS) of the current
467 * connection.
468 */
469#define uip_mss() (uip_conn->mss)
470
471
472/* uIP convenience and converting functions. */
473
474/* uip_ipaddr(&ipaddr, addr0,addr1,addr2,addr3):
475 *
476 * Packs an IP address into a two element 16-bit array. Such arrays
477 * are used to represent IP addresses in uIP.
478 */
479#define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \
adamdunkels47ec7fa2003-03-28 12:11:17 +0000480 (addr)[0] = HTONS(((addr0) << 8) | (addr1)); \
481 (addr)[1] = HTONS(((addr2) << 8) | (addr3)); \
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000482 } while(0)
483
adamdunkels47ec7fa2003-03-28 12:11:17 +0000484/* HTONS():
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000485 *
486 * Macros for converting 16-bit quantities between host and network
487 * byte order.
488 */
adamdunkels47ec7fa2003-03-28 12:11:17 +0000489#ifndef HTONS
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000490# if BYTE_ORDER == BIG_ENDIAN
adamdunkels47ec7fa2003-03-28 12:11:17 +0000491# define HTONS(n) (n)
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000492# else /* BYTE_ORDER == BIG_ENDIAN */
adamdunkels47ec7fa2003-03-28 12:11:17 +0000493# define HTONS(n) ((((u16_t)((n) & 0xff)) << 8) | (((n) & 0xff00) >> 8))
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000494# endif /* BYTE_ORDER == BIG_ENDIAN */
adamdunkels47ec7fa2003-03-28 12:11:17 +0000495#endif /* HTONS */
496
497#ifndef htons
498u16_t htons(u16_t val);
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000499#endif /* htons */
500
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000501/*-----------------------------------------------------------------------------------*/
502/* The following global variables are used for passing parameters
503 * between uIP, the network device driver and the application. */
504/*-----------------------------------------------------------------------------------*/
505
506/* u8_t uip_buf[UIP_BUFSIZE]:
507 *
508 * The uip_buf array is used to hold incoming and outgoing
509 * packets. The device driver fills this with incoming packets.
510 */
adamdunkelsa49d1dc2003-08-21 22:26:57 +0000511extern u8_t uip_buf[UIP_BUFSIZE+2];
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000512
513/* u8_t *uip_appdata:
514 *
515 * This pointer points to the application data when the application is
516 * called. If the application wishes to send data, this is where the
517 * application should write it. The application can also point this to
518 * another location.
519 */
520extern volatile u8_t *uip_appdata;
521
522#if UIP_URGDATA > 0
523/* u8_t *uip_urgdata:
524 *
525 * This pointer points to any urgent data that has been received. Only
526 * present if compiled with support for urgent data (UIP_URGDATA).
527 */
528extern volatile u8_t *uip_urgdata;
529#endif /* UIP_URGDATA > 0 */
530
531
532/* u[8|16]_t uip_len:
533 *
534 * When the application is called, uip_len contains the length of any
535 * new data that has been received from the remote host. The
536 * application should set this variable to the size of any data that
537 * the application wishes to send. When the network device driver
538 * output function is called, uip_len should contain the length of the
539 * outgoing packet.
540 */
541#if UIP_BUFSIZE > 255
542extern volatile u16_t uip_len, uip_slen;
543#else
544extern volatile u8_t uip_len, uip_slen;
545#endif
546
547#if UIP_URGDATA > 0
548extern volatile u8_t uip_urglen, uip_surglen;
549#endif /* UIP_URGDATA > 0 */
550
551extern volatile u8_t uip_acc32[4];
552
553/* struct uip_conn:
554 *
555 * The uip_conn structure is used for identifying a connection. All
556 * but one field in the structure are to be considered read-only by an
557 * application. The only exception is the appstate field whos purpose
558 * is to let the application store application-specific state (e.g.,
559 * file pointers) for the connection. The size of this field is
560 * configured in the "uipopt.h" header file.
561 */
562struct uip_conn {
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000563 u16_t ripaddr[2]; /* The IP address of the remote peer. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000564
565 u16_t lport, rport; /* The local and the remote port. */
566
567 u8_t rcv_nxt[4]; /* The sequence number that we expect to receive
568 next. */
569 u8_t snd_nxt[4]; /* The sequence number that was last sent by
570 us. */
571#if UIP_TCP_MSS > 255
572 u16_t len;
573 u16_t mss; /* Maximum segment size for the connection. */
574#else
575 u8_t len;
576 u8_t mss;
577#endif /* UIP_TCP_MSS */
578 u8_t sa, sv, rto;
579 u8_t tcpstateflags; /* TCP state and flags. */
580 u8_t timer; /* The retransmission timer. */
581 u8_t nrtx; /* Counts the number of retransmissions for a
582 particular segment. */
583
584 u8_t appstate[UIP_APPSTATE_SIZE];
585};
586
587/* struct uip_conn *uip_conn:
588 *
589 * When the application is called, uip_conn will point to the current
590 * conntection, the one that should be processed by the
591 * application. The uip_conns[] array is a list containing all
592 * connections.
593 */
594extern struct uip_conn *uip_conn;
595extern struct uip_conn uip_conns[UIP_CONNS];
596
597#if UIP_UDP
adamdunkels1e45c6d2003-09-02 21:47:27 +0000598/**
599 * Representation of a uIP UDP connection.
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000600 */
601struct uip_udp_conn {
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000602 u16_t ripaddr[2]; /* The IP address of the remote peer. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000603 u16_t lport, rport;
604};
605
606extern struct uip_udp_conn *uip_udp_conn;
607extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
608#endif /* UIP_UDP */
609
610/* struct uip_stats:
611 *
612 * Contains statistics about the TCP/IP stack.
613 */
614struct uip_stats {
615 struct {
616 uip_stats_t drop;
617 uip_stats_t recv;
618 uip_stats_t sent;
619 uip_stats_t vhlerr; /* Number of packets dropped due to wrong IP version
620 or header length. */
621 uip_stats_t hblenerr; /* Number of packets dropped due to wrong IP length,
622 high byte. */
623 uip_stats_t lblenerr; /* Number of packets dropped due to wrong IP length,
624 low byte. */
625 uip_stats_t fragerr; /* Number of packets dropped since they were IP
626 fragments. */
627 uip_stats_t chkerr; /* Number of packets dropped due to IP checksum errors. */
628 uip_stats_t protoerr; /* Number of packets dropped since they were neither
629 ICMP nor TCP. */
630 } ip;
631 struct {
632 uip_stats_t drop;
633 uip_stats_t recv;
634 uip_stats_t sent;
635 uip_stats_t typeerr;
636 } icmp;
637 struct {
638 uip_stats_t drop;
639 uip_stats_t recv;
640 uip_stats_t sent;
641 uip_stats_t chkerr;
642 uip_stats_t ackerr;
643 uip_stats_t rst;
644 uip_stats_t rexmit;
645 uip_stats_t syndrop; /* Number of dropped SYNs due to too few
646 connections was avaliable. */
647 uip_stats_t synrst; /* Number of SYNs for closed ports, triggering a
648 RST. */
649 } tcp;
650};
651
652extern struct uip_stats uip_stat;
653
654
655/*-----------------------------------------------------------------------------------*/
656/* All the stuff below this point is internal to uIP and should not be
657 * used directly by an application or by a device driver.
658 */
659/*-----------------------------------------------------------------------------------*/
660/* u8_t uip_flags:
661 *
662 * When the application is called, uip_flags will contain the flags
663 * that are defined in this file. Please read below for more
664 * infomation.
665 */
666extern volatile u8_t uip_flags;
667
668/* The following flags may be set in the global variable uip_flags
669 before calling the application callback. The UIP_ACKDATA and
670 UIP_NEWDATA flags may both be set at the same time, whereas the
671 others are mutualy exclusive. Note that these flags should *NOT* be
672 accessed directly, but through the uIP functions/macros. */
673
674#define UIP_ACKDATA 1 /* Signifies that the outstanding data was
675 acked and the application should send
676 out new data instead of retransmitting
677 the last data. */
678#define UIP_NEWDATA 2 /* Flags the fact that the peer has sent
679 us new data. */
680#define UIP_REXMIT 4 /* Tells the application to retransmit the
681 data that was last sent. */
682#define UIP_POLL 8 /* Used for polling the application, to
683 check if the application has data that
684 it wants to send. */
685#define UIP_CLOSE 16 /* The remote host has closed the
686 connection, thus the connection has
687 gone away. Or the application signals
688 that it wants to close the
689 connection. */
690#define UIP_ABORT 32 /* The remote host has aborted the
691 connection, thus the connection has
692 gone away. Or the application signals
693 that it wants to abort the
694 connection. */
695#define UIP_CONNECTED 64 /* We have got a connection from a remote
696 host and have set up a new connection
697 for it, or an active connection has
698 been successfully established. */
699
700#define UIP_TIMEDOUT 128 /* The connection has been aborted due to
701 too many retransmissions. */
702
703
704/* uip_process(flag):
705 *
706 * The actual uIP function which does all the work.
707 */
708void uip_process(u8_t flag);
709
710/* The following flags are passed as an argument to the uip_process()
711 function. They are used to distinguish between the two cases where
712 uip_process() is called. It can be called either because we have
713 incoming data that should be processed, or because the periodic
714 timer has fired. */
715
716#define UIP_DATA 1 /* Tells uIP that there is incoming data in
717 the uip_buf buffer. The length of the
718 data is stored in the global variable
719 uip_len. */
720#define UIP_TIMER 2 /* Tells uIP that the periodic timer has
721 fired. */
722#if UIP_UDP
723#define UIP_UDP_TIMER 3
724#endif /* UIP_UDP */
725
726/* The TCP states used in the uip_conn->tcpstateflags. */
727#define CLOSED 0
728#define SYN_RCVD 1
729#define SYN_SENT 2
730#define ESTABLISHED 3
731#define FIN_WAIT_1 4
732#define FIN_WAIT_2 5
733#define CLOSING 6
734#define TIME_WAIT 7
735#define LAST_ACK 8
736#define TS_MASK 15
737
738#define UIP_STOPPED 16
739
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000740#define UIP_TCPIP_HLEN 40
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000741
742/* The TCP and IP headers. */
743typedef struct {
744 /* IP header. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000745 u8_t vhl,
746 tos,
747 len[2],
748 ipid[2],
749 ipoffset[2],
750 ttl,
751 proto;
752 u16_t ipchksum;
753 u16_t srcipaddr[2],
754 destipaddr[2];
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000755
756 /* TCP header. */
757 u16_t srcport,
758 destport;
759 u8_t seqno[4],
760 ackno[4],
761 tcpoffset,
762 flags,
763 wnd[2];
764 u16_t tcpchksum;
765 u8_t urgp[2];
766 u8_t optdata[4];
767} uip_tcpip_hdr;
768
769/* The ICMP and IP headers. */
770typedef struct {
771 /* IP header. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000772 u8_t vhl,
773 tos,
774 len[2],
775 ipid[2],
776 ipoffset[2],
777 ttl,
778 proto;
779 u16_t ipchksum;
780 u16_t srcipaddr[2],
781 destipaddr[2];
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000782 /* ICMP (echo) header. */
783 u8_t type, icode;
784 u16_t icmpchksum;
785 u16_t id, seqno;
786} uip_icmpip_hdr;
787
788
789/* The UDP and IP headers. */
790typedef struct {
791 /* IP header. */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000792 u8_t vhl,
793 tos,
794 len[2],
795 ipid[2],
796 ipoffset[2],
797 ttl,
798 proto;
799 u16_t ipchksum;
800 u16_t srcipaddr[2],
801 destipaddr[2];
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000802
803 /* UDP header. */
804 u16_t srcport,
805 destport;
806 u16_t udplen;
807 u16_t udpchksum;
808} uip_udpip_hdr;
809
810#define UIP_PROTO_ICMP 1
811#define UIP_PROTO_TCP 6
812#define UIP_PROTO_UDP 17
813
814#if UIP_FIXEDADDR
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000815extern const u16_t uip_hostaddr[2];
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000816#else /* UIP_FIXEDADDR */
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000817extern u16_t uip_hostaddr[2];
adamdunkelsca9ddcb2003-03-19 14:13:31 +0000818#endif /* UIP_FIXEDADDR */
819
820#endif /* __UIP_H__ */
821
822
823
824
825
826
827