source: uKadecot/trunk/uip/net/ip/uip.h@ 262

Last change on this file since 262 was 262, checked in by coas-nagasima, 7 years ago

uIPを更新
プロジェクトファイルを更新

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-chdr; charset=SHIFT_JIS
File size: 45.3 KB
Line 
1
2/**
3 * \addtogroup uip
4 * @{
5 */
6
7/**
8 * \file
9 * Header file for the uIP TCP/IP stack.
10 * \author Adam Dunkels <adam@dunkels.com>
11 *
12 * The uIP TCP/IP stack header file contains definitions for a number
13 * of C macros that are used by uIP programs as well as internal uIP
14 * structures, TCP/IP header structures and function declarations.
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 262 2016-11-18 05:58:30Z coas-nagasima $
49 *
50 */
51
52#ifndef __UIP_H__
53#define __UIP_H__
54
55#include "net/ip/uipopt.h"
56
57/**
58 * Representation of an IP address.
59 *
60 */
61#if UIP_CONF_IPV6
62typedef union uip_ip6addr_t {
63 uint8_t u8[16]; /* Initializer, must come first!!! */
64 uint16_t u16[8];
65} uip_ip6addr_t;
66
67typedef uip_ip6addr_t uip_ipaddr_t;
68#else /* UIP_CONF_IPV6 */
69typedef union uip_ip4addr_t {
70 uint8_t u8[4]; /* Initializer, must come first!!! */
71 uint16_t u16[2];
72#if 0
73 uint32_t u32;
74#endif
75} uip_ip4addr_t;
76typedef uip_ip4addr_t uip_ipaddr_t;
77#endif /* UIP_CONF_IPV6 */
78
79/*---------------------------------------------------------------------------*/
80/* First, the functions that should be called from the
81 * system. Initialization, the periodic timer and incoming packets are
82 * handled by the following three functions.
83 */
84/**
85 * \defgroup uipconffunc uIP configuration functions
86 * @{
87 *
88 * The uIP configuration functions are used for setting run-time
89 * parameters in uIP such as IP addresses.
90 */
91
92/**
93 * Set the IP address of this host.
94 *
95 * The IP address is represented as a 4-byte array where the first
96 * octet of the IP address is put in the first member of the 4-byte
97 * array.
98 *
99 * Example:
100 \code
101
102 uip_ipaddr_t addr;
103
104 uip_ipaddr(&addr, 192,168,1,2);
105 uip_sethostaddr(&addr);
106
107 \endcode
108 * \param addr A pointer to an IP address of type uip_ipaddr_t;
109 *
110 * \sa uip_ipaddr()
111 *
112 * \hideinitializer
113 */
114#define uip_sethostaddr(addr) uip_ipaddr_copy(&uip_hostaddr, (addr))
115
116/**
117 * Get the IP address of this host.
118 *
119 * The IP address is represented as a 4-byte array where the first
120 * octet of the IP address is put in the first member of the 4-byte
121 * array.
122 *
123 * Example:
124 \code
125 uip_ipaddr_t hostaddr;
126
127 uip_gethostaddr(&hostaddr);
128 \endcode
129 * \param addr A pointer to a uip_ipaddr_t variable that will be
130 * filled in with the currently configured IP address.
131 *
132 * \hideinitializer
133 */
134#define uip_gethostaddr(addr) uip_ipaddr_copy((addr), &uip_hostaddr)
135
136/**
137 * Set the default router's IP address.
138 *
139 * \param addr A pointer to a uip_ipaddr_t variable containing the IP
140 * address of the default router.
141 *
142 * \sa uip_ipaddr()
143 *
144 * \hideinitializer
145 */
146#define uip_setdraddr(addr) uip_ipaddr_copy(&uip_draddr, (addr))
147
148/**
149 * Set the netmask.
150 *
151 * \param addr A pointer to a uip_ipaddr_t variable containing the IP
152 * address of the netmask.
153 *
154 * \sa uip_ipaddr()
155 *
156 * \hideinitializer
157 */
158#define uip_setnetmask(addr) uip_ipaddr_copy(&uip_netmask, (addr))
159
160
161/**
162 * Get the default router's IP address.
163 *
164 * \param addr A pointer to a uip_ipaddr_t variable that will be
165 * filled in with the IP address of the default router.
166 *
167 * \hideinitializer
168 */
169#define uip_getdraddr(addr) uip_ipaddr_copy((addr), &uip_draddr)
170
171/**
172 * Get the netmask.
173 *
174 * \param addr A pointer to a uip_ipaddr_t variable that will be
175 * filled in with the value of the netmask.
176 *
177 * \hideinitializer
178 */
179#define uip_getnetmask(addr) uip_ipaddr_copy((addr), &uip_netmask)
180
181/** @} */
182
183/**
184 * \defgroup uipinit uIP initialization functions
185 * @{
186 *
187 * The uIP initialization functions are used for booting uIP.
188 */
189
190/**
191 * uIP initialization function.
192 *
193 * This function should be called at boot up to initilize the uIP
194 * TCP/IP stack.
195 */
196void uip_init(void);
197
198/**
199 * uIP initialization function.
200 *
201 * This function may be used at boot time to set the initial ip_id.
202 */
203void uip_setipid(uint16_t id);
204
205/** @} */
206
207/**
208 * \defgroup uipdevfunc uIP device driver functions
209 * @{
210 *
211 * These functions are used by a network device driver for interacting
212 * with uIP.
213 */
214
215/**
216 * Process an incoming packet.
217 *
218 * This function should be called when the device driver has received
219 * a packet from the network. The packet from the device driver must
220 * be present in the uip_buf buffer, and the length of the packet
221 * should be placed in the uip_len variable.
222 *
223 * When the function returns, there may be an outbound packet placed
224 * in the uip_buf packet buffer. If so, the uip_len variable is set to
225 * the length of the packet. If no packet is to be sent out, the
226 * uip_len variable is set to 0.
227 *
228 * The usual way of calling the function is presented by the source
229 * code below.
230 \code
231 uip_len = devicedriver_poll();
232 if(uip_len > 0) {
233 uip_input();
234 if(uip_len > 0) {
235 devicedriver_send();
236 }
237 }
238 \endcode
239 *
240 * \note If you are writing a uIP device driver that needs ARP
241 * (Address Resolution Protocol), e.g., when running uIP over
242 * Ethernet, you will need to call the uIP ARP code before calling
243 * this function:
244 \code
245 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
246 uip_len = ethernet_devicedrver_poll();
247 if(uip_len > 0) {
248 if(BUF->type == UIP_HTONS(UIP_ETHTYPE_IP)) {
249 uip_arp_ipin();
250 uip_input();
251 if(uip_len > 0) {
252 uip_arp_out();
253 ethernet_devicedriver_send();
254 }
255 } else if(BUF->type == UIP_HTONS(UIP_ETHTYPE_ARP)) {
256 uip_arp_arpin();
257 if(uip_len > 0) {
258 ethernet_devicedriver_send();
259 }
260 }
261 \endcode
262 *
263 * \hideinitializer
264 */
265#define uip_input() uip_process(UIP_DATA)
266
267
268/**
269 * Periodic processing for a connection identified by its number.
270 *
271 * This function does the necessary periodic processing (timers,
272 * polling) for a uIP TCP conneciton, and should be called when the
273 * periodic uIP timer goes off. It should be called for every
274 * connection, regardless of whether they are open of closed.
275 *
276 * When the function returns, it may have an outbound packet waiting
277 * for service in the uIP packet buffer, and if so the uip_len
278 * variable is set to a value larger than zero. The device driver
279 * should be called to send out the packet.
280 *
281 * The usual way of calling the function is through a for() loop like
282 * this:
283 \code
284 for(i = 0; i < UIP_CONNS; ++i) {
285 uip_periodic(i);
286 if(uip_len > 0) {
287 devicedriver_send();
288 }
289 }
290 \endcode
291 *
292 * \note If you are writing a uIP device driver that needs ARP
293 * (Address Resolution Protocol), e.g., when running uIP over
294 * Ethernet, you will need to call the uip_arp_out() function before
295 * calling the device driver:
296 \code
297 for(i = 0; i < UIP_CONNS; ++i) {
298 uip_periodic(i);
299 if(uip_len > 0) {
300 uip_arp_out();
301 ethernet_devicedriver_send();
302 }
303 }
304 \endcode
305 *
306 * \param conn The number of the connection which is to be periodically polled.
307 *
308 * \hideinitializer
309 */
310#define uip_periodic(conn) do { uip_conn = &uip_conns[conn]; \
311 uip_process(UIP_TIMER); } while (0)
312
313/**
314 *
315 *
316 */
317#define uip_conn_active(conn) (uip_conns[conn].tcpstateflags != UIP_CLOSED)
318
319/**
320 * Perform periodic processing for a connection identified by a pointer
321 * to its structure.
322 *
323 * Same as uip_periodic() but takes a pointer to the actual uip_conn
324 * struct instead of an integer as its argument. This function can be
325 * used to force periodic processing of a specific connection.
326 *
327 * \param conn A pointer to the uip_conn struct for the connection to
328 * be processed.
329 *
330 * \hideinitializer
331 */
332#define uip_periodic_conn(conn) do { uip_conn = conn; \
333 uip_process(UIP_TIMER); } while (0)
334
335/**
336 * Request that a particular connection should be polled.
337 *
338 * Similar to uip_periodic_conn() but does not perform any timer
339 * processing. The application is polled for new data.
340 *
341 * \param conn A pointer to the uip_conn struct for the connection to
342 * be processed.
343 *
344 * \hideinitializer
345 */
346#define uip_poll_conn(conn) do { uip_conn = conn; \
347 uip_process(UIP_POLL_REQUEST); } while (0)
348
349
350#if UIP_UDP
351/**
352 * Periodic processing for a UDP connection identified by its number.
353 *
354 * This function is essentially the same as uip_periodic(), but for
355 * UDP connections. It is called in a similar fashion as the
356 * uip_periodic() function:
357 \code
358 for(i = 0; i < UIP_UDP_CONNS; i++) {
359 uip_udp_periodic(i);
360 if(uip_len > 0) {
361 devicedriver_send();
362 }
363 }
364 \endcode
365 *
366 * \note As for the uip_periodic() function, special care has to be
367 * taken when using uIP together with ARP and Ethernet:
368 \code
369 for(i = 0; i < UIP_UDP_CONNS; i++) {
370 uip_udp_periodic(i);
371 if(uip_len > 0) {
372 uip_arp_out();
373 ethernet_devicedriver_send();
374 }
375 }
376 \endcode
377 *
378 * \param conn The number of the UDP connection to be processed.
379 *
380 * \hideinitializer
381 */
382#define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \
383 uip_process(UIP_UDP_TIMER); } while (0)
384
385/**
386 * Periodic processing for a UDP connection identified by a pointer to
387 * its structure.
388 *
389 * Same as uip_udp_periodic() but takes a pointer to the actual
390 * uip_conn struct instead of an integer as its argument. This
391 * function can be used to force periodic processing of a specific
392 * connection.
393 *
394 * \param conn A pointer to the uip_udp_conn struct for the connection
395 * to be processed.
396 *
397 * \hideinitializer
398 */
399#define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn; \
400 uip_process(UIP_UDP_TIMER); } while (0)
401#endif /* UIP_UDP */
402
403/**
404 * The uIP packet buffer.
405 *
406 * The uip_buf array is used to hold incoming and outgoing
407 * packets. The device driver should place incoming data into this
408 * buffer. When sending data, the device driver should read the link
409 * level headers and the TCP/IP headers from this buffer. The size of
410 * the link level headers is configured by the UIP_LLH_LEN define.
411 *
412 * \note The application data need not be placed in this buffer, so
413 * the device driver must read it from the place pointed to by the
414 * uip_appdata pointer as illustrated by the following example:
415 \code
416 void
417 devicedriver_send(void)
418 {
419 hwsend(&uip_buf[0], UIP_LLH_LEN);
420 if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN) {
421 hwsend(&uip_buf[UIP_LLH_LEN], uip_len - UIP_LLH_LEN);
422 } else {
423 hwsend(&uip_buf[UIP_LLH_LEN], UIP_TCPIP_HLEN);
424 hwsend(uip_appdata, uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN);
425 }
426 }
427 \endcode
428 */
429#if 0
430extern uint8_t uip_buf[UIP_BUFSIZE+2];
431#else
432extern uint8_t *uip_buf;
433#endif
434
435/** @} */
436
437/*---------------------------------------------------------------------------*/
438/* Functions that are used by the uIP application program. Opening and
439 * closing connections, sending and receiving data, etc. is all
440 * handled by the functions below.
441*/
442/**
443 * \defgroup uipappfunc uIP application functions
444 * @{
445 *
446 * Functions used by an application running of top of uIP.
447 */
448
449/**
450 * Start listening to the specified port.
451 *
452 * \note Since this function expects the port number in network byte
453 * order, a conversion using UIP_HTONS() or uip_htons() is necessary.
454 *
455 \code
456 uip_listen(UIP_HTONS(80));
457 \endcode
458 *
459 * \param port A 16-bit port number in network byte order.
460 */
461void uip_listen(uint16_t port);
462
463/**
464 * Stop listening to the specified port.
465 *
466 * \note Since this function expects the port number in network byte
467 * order, a conversion using UIP_HTONS() or uip_htons() is necessary.
468 *
469 \code
470 uip_unlisten(UIP_HTONS(80));
471 \endcode
472 *
473 * \param port A 16-bit port number in network byte order.
474 */
475void uip_unlisten(uint16_t port);
476
477/**
478 * Connect to a remote host using TCP.
479 *
480 * This function is used to start a new connection to the specified
481 * port on the specified host. It allocates a new connection identifier,
482 * sets the connection to the SYN_SENT state and sets the
483 * retransmission timer to 0. This will cause a TCP SYN segment to be
484 * sent out the next time this connection is periodically processed,
485 * which usually is done within 0.5 seconds after the call to
486 * uip_connect().
487 *
488 * \note This function is available only if support for active open
489 * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h.
490 *
491 * \note Since this function requires the port number to be in network
492 * byte order, a conversion using UIP_HTONS() or uip_htons() is necessary.
493 *
494 \code
495 uip_ipaddr_t ipaddr;
496
497 uip_ipaddr(&ipaddr, 192,168,1,2);
498 uip_connect(&ipaddr, UIP_HTONS(80));
499 \endcode
500 *
501 * \param ripaddr The IP address of the remote host.
502 *
503 * \param port A 16-bit port number in network byte order.
504 *
505 * \return A pointer to the uIP connection identifier for the new connection,
506 * or NULL if no connection could be allocated.
507 *
508 */
509struct uip_conn *uip_connect(uip_ipaddr_t *ripaddr, uint16_t port);
510
511
512
513/**
514 * \internal
515 *
516 * Check if a connection has outstanding (i.e., unacknowledged) data.
517 *
518 * \param conn A pointer to the uip_conn structure for the connection.
519 *
520 * \hideinitializer
521 */
522#define uip_outstanding(conn) ((conn)->len)
523
524/**
525 * Send data on the current connection.
526 *
527 * This function is used to send out a single segment of TCP
528 * data. Only applications that have been invoked by uIP for event
529 * processing can send data.
530 *
531 * The amount of data that actually is sent out after a call to this
532 * function is determined by the maximum amount of data TCP allows. uIP
533 * will automatically crop the data so that only the appropriate
534 * amount of data is sent. The function uip_mss() can be used to query
535 * uIP for the amount of data that actually will be sent.
536 *
537 * \note This function does not guarantee that the sent data will
538 * arrive at the destination. If the data is lost in the network, the
539 * application will be invoked with the uip_rexmit() event being
540 * set. The application will then have to resend the data using this
541 * function.
542 *
543 * \param data A pointer to the data which is to be sent.
544 *
545 * \param len The maximum amount of data bytes to be sent.
546 *
547 * \hideinitializer
548 */
549void uip_send(const void *data, int len);
550
551/**
552 * The length of any incoming data that is currently available (if available)
553 * in the uip_appdata buffer.
554 *
555 * The test function uip_data() must first be used to check if there
556 * is any data available at all.
557 *
558 * \hideinitializer
559 */
560/*void uip_datalen(void);*/
561#define uip_datalen() uip_len
562
563/**
564 * The length of any out-of-band data (urgent data) that has arrived
565 * on the connection.
566 *
567 * \note The configuration parameter UIP_URGDATA must be set for this
568 * function to be enabled.
569 *
570 * \hideinitializer
571 */
572#define uip_urgdatalen() uip_urglen
573
574/**
575 * Close the current connection.
576 *
577 * This function will close the current connection in a nice way.
578 *
579 * \hideinitializer
580 */
581#define uip_close() (uip_flags = UIP_CLOSE)
582
583/**
584 * Abort the current connection.
585 *
586 * This function will abort (reset) the current connection, and is
587 * usually used when an error has occurred that prevents using the
588 * uip_close() function.
589 *
590 * \hideinitializer
591 */
592#define uip_abort() (uip_flags = UIP_ABORT)
593
594/**
595 * Tell the sending host to stop sending data.
596 *
597 * This function will close our receiver's window so that we stop
598 * receiving data for the current connection.
599 *
600 * \hideinitializer
601 */
602#define uip_stop() (uip_conn->tcpstateflags |= UIP_STOPPED)
603
604/**
605 * Find out if the current connection has been previously stopped with
606 * uip_stop().
607 *
608 * \hideinitializer
609 */
610#define uip_stopped(conn) ((conn)->tcpstateflags & UIP_STOPPED)
611
612/**
613 * Restart the current connection, if is has previously been stopped
614 * with uip_stop().
615 *
616 * This function will open the receiver's window again so that we
617 * start receiving data for the current connection.
618 *
619 * \hideinitializer
620 */
621#define uip_restart() do { uip_flags |= UIP_NEWDATA; \
622 uip_conn->tcpstateflags &= ~UIP_STOPPED; \
623 } while(0)
624
625
626/* uIP tests that can be made to determine in what state the current
627 connection is, and what the application function should do. */
628
629/**
630 * Is the current connection a UDP connection?
631 *
632 * This function checks whether the current connection is a UDP connection.
633 *
634 * \hideinitializer
635 *
636 */
637#define uip_udpconnection() (uip_conn == NULL)
638
639/**
640 * Is new incoming data available?
641 *
642 * Will reduce to non-zero if there is new data for the application
643 * present at the uip_appdata pointer. The size of the data is
644 * available through the uip_len variable.
645 *
646 * \hideinitializer
647 */
648#define uip_newdata() (uip_flags & UIP_NEWDATA)
649
650/**
651 * Has previously sent data been acknowledged?
652 *
653 * Will reduce to non-zero if the previously sent data has been
654 * acknowledged by the remote host. This means that the application
655 * can send new data.
656 *
657 * \hideinitializer
658 */
659#define uip_acked() (uip_flags & UIP_ACKDATA)
660
661/**
662 * Has the connection just been connected?
663 *
664 * Reduces to non-zero if the current connection has been connected to
665 * a remote host. This will happen both if the connection has been
666 * actively opened (with uip_connect()) or passively opened (with
667 * uip_listen()).
668 *
669 * \hideinitializer
670 */
671#define uip_connected() (uip_flags & UIP_CONNECTED)
672
673/**
674 * Has the connection been closed by the other end?
675 *
676 * Is non-zero if the connection has been closed by the remote
677 * host. The application may then do the necessary clean-ups.
678 *
679 * \hideinitializer
680 */
681#define uip_closed() (uip_flags & UIP_CLOSE)
682
683/**
684 * Has the connection been aborted by the other end?
685 *
686 * Non-zero if the current connection has been aborted (reset) by the
687 * remote host.
688 *
689 * \hideinitializer
690 */
691#define uip_aborted() (uip_flags & UIP_ABORT)
692
693/**
694 * Has the connection timed out?
695 *
696 * Non-zero if the current connection has been aborted due to too many
697 * retransmissions.
698 *
699 * \hideinitializer
700 */
701#define uip_timedout() (uip_flags & UIP_TIMEDOUT)
702
703/**
704 * Do we need to retransmit previously data?
705 *
706 * Reduces to non-zero if the previously sent data has been lost in
707 * the network, and the application should retransmit it. The
708 * application should send the exact same data as it did the last
709 * time, using the uip_send() function.
710 *
711 * \hideinitializer
712 */
713#define uip_rexmit() (uip_flags & UIP_REXMIT)
714
715/**
716 * Is the connection being polled by uIP?
717 *
718 * Is non-zero if the reason the application is invoked is that the
719 * current connection has been idle for a while and should be
720 * polled.
721 *
722 * The polling event can be used for sending data without having to
723 * wait for the remote host to send data.
724 *
725 * \hideinitializer
726 */
727#define uip_poll() (uip_flags & UIP_POLL)
728
729/**
730 * Get the initial maximum segment size (MSS) of the current
731 * connection.
732 *
733 * \hideinitializer
734 */
735#define uip_initialmss() (uip_conn->initialmss)
736
737/**
738 * Get the current maximum segment size that can be sent on the current
739 * connection.
740 *
741 * The current maximum segment size that can be sent on the
742 * connection is computed from the receiver's window and the MSS of
743 * the connection (which also is available by calling
744 * uip_initialmss()).
745 *
746 * \hideinitializer
747 */
748#define uip_mss() (uip_conn->mss)
749
750/**
751 * Set up a new UDP connection.
752 *
753 * This function sets up a new UDP connection. The function will
754 * automatically allocate an unused local port for the new
755 * connection. However, another port can be chosen by using the
756 * uip_udp_bind() call, after the uip_udp_new() function has been
757 * called.
758 *
759 * Example:
760 \code
761 uip_ipaddr_t addr;
762 struct uip_udp_conn *c;
763
764 uip_ipaddr(&addr, 192,168,2,1);
765 c = uip_udp_new(&addr, UIP_HTONS(12345));
766 if(c != NULL) {
767 uip_udp_bind(c, UIP_HTONS(12344));
768 }
769 \endcode
770 * \param ripaddr The IP address of the remote host.
771 *
772 * \param rport The remote port number in network byte order.
773 *
774 * \return The uip_udp_conn structure for the new connection or NULL
775 * if no connection could be allocated.
776 */
777struct uip_udp_conn *uip_udp_new(const uip_ipaddr_t *ripaddr, uint16_t rport);
778
779/**
780 * Removed a UDP connection.
781 *
782 * \param conn A pointer to the uip_udp_conn structure for the connection.
783 *
784 * \hideinitializer
785 */
786#define uip_udp_remove(conn) (conn)->lport = 0
787
788/**
789 * Bind a UDP connection to a local port.
790 *
791 * \param conn A pointer to the uip_udp_conn structure for the
792 * connection.
793 *
794 * \param port The local port number, in network byte order.
795 *
796 * \hideinitializer
797 */
798#define uip_udp_bind(conn, port) (conn)->lport = port
799
800/**
801 * Send a UDP datagram of length len on the current connection.
802 *
803 * This function can only be called in response to a UDP event (poll
804 * or newdata). The data must be present in the uip_buf buffer, at the
805 * place pointed to by the uip_appdata pointer.
806 *
807 * \param len The length of the data in the uip_buf buffer.
808 *
809 * \hideinitializer
810 */
811#define uip_udp_send(len) uip_send((char *)uip_appdata, len)
812
813/** @} */
814
815/* uIP convenience and converting functions. */
816
817/**
818 * \defgroup uipconvfunc uIP conversion functions
819 * @{
820 *
821 * These functions can be used for converting between different data
822 * formats used by uIP.
823 */
824
825/**
826 * Construct an IP address from four bytes.
827 *
828 * This function constructs an IP address of the type that uIP handles
829 * internally from four bytes. The function is handy for specifying IP
830 * addresses to use with e.g. the uip_connect() function.
831 *
832 * Example:
833 \code
834 uip_ipaddr_t ipaddr;
835 struct uip_conn *c;
836
837 uip_ipaddr(&ipaddr, 192,168,1,2);
838 c = uip_connect(&ipaddr, UIP_HTONS(80));
839 \endcode
840 *
841 * \param addr A pointer to a uip_ipaddr_t variable that will be
842 * filled in with the IP address.
843 *
844 * \param addr0 The first octet of the IP address.
845 * \param addr1 The second octet of the IP address.
846 * \param addr2 The third octet of the IP address.
847 * \param addr3 The forth octet of the IP address.
848 *
849 * \hideinitializer
850 */
851#define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \
852 (addr)->u8[0] = addr0; \
853 (addr)->u8[1] = addr1; \
854 (addr)->u8[2] = addr2; \
855 (addr)->u8[3] = addr3; \
856 } while(0)
857
858/**
859 * Construct an IPv6 address from eight 16-bit words.
860 *
861 * This function constructs an IPv6 address.
862 *
863 * \hideinitializer
864 */
865#define uip_ip6addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) do { \
866 (addr)->u16[0] = UIP_HTONS(addr0); \
867 (addr)->u16[1] = UIP_HTONS(addr1); \
868 (addr)->u16[2] = UIP_HTONS(addr2); \
869 (addr)->u16[3] = UIP_HTONS(addr3); \
870 (addr)->u16[4] = UIP_HTONS(addr4); \
871 (addr)->u16[5] = UIP_HTONS(addr5); \
872 (addr)->u16[6] = UIP_HTONS(addr6); \
873 (addr)->u16[7] = UIP_HTONS(addr7); \
874 } while(0)
875
876/**
877 * Copy an IP address to another IP address.
878 *
879 * Copies an IP address from one place to another.
880 *
881 * Example:
882 \code
883 uip_ipaddr_t ipaddr1, ipaddr2;
884
885 uip_ipaddr(&ipaddr1, 192,16,1,2);
886 uip_ipaddr_copy(&ipaddr2, &ipaddr1);
887 \endcode
888 *
889 * \param dest The destination for the copy.
890 * \param src The source from where to copy.
891 *
892 * \hideinitializer
893 */
894#ifndef uip_ipaddr_copy
895#define uip_ipaddr_copy(dest, src) (*(dest) = *(src))
896#endif
897
898/**
899 * Compare two IP addresses
900 *
901 * Compares two IP addresses.
902 *
903 * Example:
904 \code
905 uip_ipaddr_t ipaddr1, ipaddr2;
906
907 uip_ipaddr(&ipaddr1, 192,16,1,2);
908 if(uip_ipaddr_cmp(&ipaddr2, &ipaddr1)) {
909 printf("They are the same");
910 }
911 \endcode
912 *
913 * \param addr1 The first IP address.
914 * \param addr2 The second IP address.
915 *
916 * \hideinitializer
917 */
918#if !UIP_CONF_IPV6
919#define uip_ipaddr_cmp(addr1, addr2) ((addr1)->u16[0] == (addr2)->u16[0] && \
920 (addr1)->u16[1] == (addr2)->u16[1])
921#else /* !UIP_CONF_IPV6 */
922#define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0)
923#endif /* !UIP_CONF_IPV6 */
924
925/**
926 * Compare two IP addresses with netmasks
927 *
928 * Compares two IP addresses with netmasks. The masks are used to mask
929 * out the bits that are to be compared.
930 *
931 * Example:
932 \code
933 uip_ipaddr_t ipaddr1, ipaddr2, mask;
934
935 uip_ipaddr(&mask, 255,255,255,0);
936 uip_ipaddr(&ipaddr1, 192,16,1,2);
937 uip_ipaddr(&ipaddr2, 192,16,1,3);
938 if(uip_ipaddr_maskcmp(&ipaddr1, &ipaddr2, &mask)) {
939 printf("They are the same");
940 }
941 \endcode
942 *
943 * \param addr1 The first IP address.
944 * \param addr2 The second IP address.
945 * \param mask The netmask.
946 *
947 * \hideinitializer
948 */
949#define uip_ipaddr_maskcmp(addr1, addr2, mask) \
950 (((((uint16_t *)addr1)[0] & ((uint16_t *)mask)[0]) == \
951 (((uint16_t *)addr2)[0] & ((uint16_t *)mask)[0])) && \
952 ((((uint16_t *)addr1)[1] & ((uint16_t *)mask)[1]) == \
953 (((uint16_t *)addr2)[1] & ((uint16_t *)mask)[1])))
954
955
956/**
957 * Mask out the network part of an IP address.
958 *
959 * Masks out the network part of an IP address, given the address and
960 * the netmask.
961 *
962 * Example:
963 \code
964 uip_ipaddr_t ipaddr1, ipaddr2, netmask;
965
966 uip_ipaddr(&ipaddr1, 192,16,1,2);
967 uip_ipaddr(&netmask, 255,255,255,0);
968 uip_ipaddr_mask(&ipaddr2, &ipaddr1, &netmask);
969 \endcode
970 *
971 * In the example above, the variable "ipaddr2" will contain the IP
972 * address 192.168.1.0.
973 *
974 * \param dest Where the result is to be placed.
975 * \param src The IP address.
976 * \param mask The netmask.
977 *
978 * \hideinitializer
979 */
980#define uip_ipaddr_mask(dest, src, mask) do { \
981 ((uint16_t *)dest)[0] = ((uint16_t *)src)[0] & ((uint16_t *)mask)[0]; \
982 ((uint16_t *)dest)[1] = ((uint16_t *)src)[1] & ((uint16_t *)mask)[1]; \
983 } while(0)
984
985/**
986 * Pick the first octet of an IP address.
987 *
988 * Picks out the first octet of an IP address.
989 *
990 * Example:
991 \code
992 uip_ipaddr_t ipaddr;
993 uint8_t octet;
994
995 uip_ipaddr(&ipaddr, 1,2,3,4);
996 octet = uip_ipaddr1(&ipaddr);
997 \endcode
998 *
999 * In the example above, the variable "octet" will contain the value 1.
1000 *
1001 * \hideinitializer
1002 */
1003#define uip_ipaddr1(addr) ((addr)->u8[0])
1004
1005/**
1006 * Pick the second octet of an IP address.
1007 *
1008 * Picks out the second octet of an IP address.
1009 *
1010 * Example:
1011 \code
1012 uip_ipaddr_t ipaddr;
1013 uint8_t octet;
1014
1015 uip_ipaddr(&ipaddr, 1,2,3,4);
1016 octet = uip_ipaddr2(&ipaddr);
1017 \endcode
1018 *
1019 * In the example above, the variable "octet" will contain the value 2.
1020 *
1021 * \hideinitializer
1022 */
1023#define uip_ipaddr2(addr) ((addr)->u8[1])
1024
1025/**
1026 * Pick the third octet of an IP address.
1027 *
1028 * Picks out the third octet of an IP address.
1029 *
1030 * Example:
1031 \code
1032 uip_ipaddr_t ipaddr;
1033 uint8_t octet;
1034
1035 uip_ipaddr(&ipaddr, 1,2,3,4);
1036 octet = uip_ipaddr3(&ipaddr);
1037 \endcode
1038 *
1039 * In the example above, the variable "octet" will contain the value 3.
1040 *
1041 * \hideinitializer
1042 */
1043#define uip_ipaddr3(addr) ((addr)->u8[2])
1044
1045/**
1046 * Pick the fourth octet of an IP address.
1047 *
1048 * Picks out the fourth octet of an IP address.
1049 *
1050 * Example:
1051 \code
1052 uip_ipaddr_t ipaddr;
1053 uint8_t octet;
1054
1055 uip_ipaddr(&ipaddr, 1,2,3,4);
1056 octet = uip_ipaddr4(&ipaddr);
1057 \endcode
1058 *
1059 * In the example above, the variable "octet" will contain the value 4.
1060 *
1061 * \hideinitializer
1062 */
1063#define uip_ipaddr4(addr) ((addr)->u8[3])
1064
1065/**
1066 * Convert 16-bit quantity from host byte order to network byte order.
1067 *
1068 * This macro is primarily used for converting constants from host
1069 * byte order to network byte order. For converting variables to
1070 * network byte order, use the uip_htons() function instead.
1071 *
1072 * \hideinitializer
1073 */
1074#ifndef UIP_HTONS
1075# if UIP_BYTE_ORDER == UIP_BIG_ENDIAN
1076# define UIP_HTONS(n) (n)
1077# define UIP_HTONL(n) (n)
1078# else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
1079# define UIP_HTONS(n) (uint16_t)((((uint16_t) (n)) << 8) | (((uint16_t) (n)) >> 8))
1080# define UIP_HTONL(n) (((uint32_t)UIP_HTONS(n) << 16) | UIP_HTONS((uint32_t)(n) >> 16))
1081# endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */
1082#else
1083#error "UIP_HTONS already defined!"
1084#endif /* UIP_HTONS */
1085
1086/**
1087 * Convert 16-bit quantity from host byte order to network byte order.
1088 *
1089 * This function is primarily used for converting variables from host
1090 * byte order to network byte order. For converting constants to
1091 * network byte order, use the UIP_HTONS() macro instead.
1092 */
1093#ifndef uip_htons
1094uint16_t uip_htons(uint16_t val);
1095#endif /* uip_htons */
1096#ifndef uip_ntohs
1097#define uip_ntohs uip_htons
1098#endif
1099
1100/** @} */
1101
1102/**
1103 * Pointer to the application data in the packet buffer.
1104 *
1105 * This pointer points to the application data when the application is
1106 * called. If the application wishes to send data, the application may
1107 * use this space to write the data into before calling uip_send().
1108 */
1109extern void *uip_appdata;
1110
1111#if UIP_URGDATA > 0
1112/* uint8_t *uip_urgdata:
1113 *
1114 * This pointer points to any urgent data that has been received. Only
1115 * present if compiled with support for urgent data (UIP_URGDATA).
1116 */
1117extern void *uip_urgdata;
1118#endif /* UIP_URGDATA > 0 */
1119
1120
1121/**
1122 * \defgroup uipdrivervars Variables used in uIP device drivers
1123 * @{
1124 *
1125 * uIP has a few global variables that are used in device drivers for
1126 * uIP.
1127 */
1128
1129/**
1130 * The length of the packet in the uip_buf buffer.
1131 *
1132 * The global variable uip_len holds the length of the packet in the
1133 * uip_buf buffer.
1134 *
1135 * When the network device driver calls the uIP input function,
1136 * uip_len should be set to the length of the packet in the uip_buf
1137 * buffer.
1138 *
1139 * When sending packets, the device driver should use the contents of
1140 * the uip_len variable to determine the length of the outgoing
1141 * packet.
1142 *
1143 */
1144extern uint16_t uip_len;
1145
1146/** @} */
1147
1148#if UIP_URGDATA > 0
1149extern uint16_t uip_urglen, uip_surglen;
1150#endif /* UIP_URGDATA > 0 */
1151
1152
1153/**
1154 * Representation of a uIP TCP connection.
1155 *
1156 * The uip_conn structure is used for identifying a connection. All
1157 * but one field in the structure are to be considered read-only by an
1158 * application. The only exception is the appstate field whose purpose
1159 * is to let the application store application-specific state (e.g.,
1160 * file pointers) for the connection. The type of this field is
1161 * configured in the "uipopt.h" header file.
1162 */
1163struct uip_conn {
1164 uip_ipaddr_t ripaddr; /**< The IP address of the remote host. */
1165
1166 uint16_t lport; /**< The local TCP port, in network byte order. */
1167 uint16_t rport; /**< The local remote TCP port, in network byte
1168 order. */
1169
1170 uint8_t rcv_nxt[4]; /**< The sequence number that we expect to
1171 receive next. */
1172 uint8_t snd_nxt[4]; /**< The sequence number that was last sent by
1173 us. */
1174 uint16_t len; /**< Length of the data that was previously sent. */
1175 uint16_t mss; /**< Current maximum segment size for the
1176 connection. */
1177 uint16_t initialmss; /**< Initial maximum segment size for the
1178 connection. */
1179 uint8_t sa; /**< Retransmission time-out calculation state
1180 variable. */
1181 uint8_t sv; /**< Retransmission time-out calculation state
1182 variable. */
1183 uint8_t rto; /**< Retransmission time-out. */
1184 uint8_t tcpstateflags; /**< TCP state and flags. */
1185 uint8_t timer; /**< The retransmission timer. */
1186 uint8_t nrtx; /**< The number of retransmissions for the last
1187 segment sent. */
1188
1189 /** The application state. */
1190 uip_tcp_appstate_t appstate;
1191};
1192
1193
1194/**
1195 * Pointer to the current TCP connection.
1196 *
1197 * The uip_conn pointer can be used to access the current TCP
1198 * connection.
1199 */
1200
1201extern struct uip_conn *uip_conn;
1202/* The array containing all uIP connections. */
1203extern struct uip_conn uip_conns[UIP_CONNS];
1204/**
1205 * \addtogroup uiparch
1206 * @{
1207 */
1208
1209/**
1210 * 4-byte array used for the 32-bit sequence number calculations.
1211 */
1212extern uint8_t uip_acc32[4];
1213/** @} */
1214
1215
1216#if UIP_UDP
1217/**
1218 * Representation of a uIP UDP connection.
1219 */
1220struct uip_udp_conn {
1221 uip_ipaddr_t ripaddr; /**< The IP address of the remote peer. */
1222 uint16_t lport; /**< The local port number in network byte order. */
1223 uint16_t rport; /**< The remote port number in network byte order. */
1224 uint8_t ttl; /**< Default time-to-live. */
1225
1226 /** The application state. */
1227 uip_udp_appstate_t appstate;
1228};
1229
1230/**
1231 * The current UDP connection.
1232 */
1233extern struct uip_udp_conn *uip_udp_conn;
1234extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS];
1235#endif /* UIP_UDP */
1236
1237/**
1238 * The structure holding the TCP/IP statistics that are gathered if
1239 * UIP_STATISTICS is set to 1.
1240 *
1241 */
1242struct uip_stats {
1243 struct {
1244 uip_stats_t recv; /**< Number of received packets at the IP
1245 layer. */
1246 uip_stats_t sent; /**< Number of sent packets at the IP
1247 layer. */
1248 uip_stats_t drop; /**< Number of dropped packets at the IP
1249 layer. */
1250 uip_stats_t vhlerr; /**< Number of packets dropped due to wrong
1251 IP version or header length. */
1252 uip_stats_t hblenerr; /**< Number of packets dropped due to wrong
1253 IP length, high byte. */
1254 uip_stats_t lblenerr; /**< Number of packets dropped due to wrong
1255 IP length, low byte. */
1256 uip_stats_t fragerr; /**< Number of packets dropped since they
1257 were IP fragments. */
1258 uip_stats_t chkerr; /**< Number of packets dropped due to IP
1259 checksum errors. */
1260 uip_stats_t protoerr; /**< Number of packets dropped since they
1261 were neither ICMP, UDP nor TCP. */
1262 } ip; /**< IP statistics. */
1263 struct {
1264 uip_stats_t recv; /**< Number of received ICMP packets. */
1265 uip_stats_t sent; /**< Number of sent ICMP packets. */
1266 uip_stats_t drop; /**< Number of dropped ICMP packets. */
1267 uip_stats_t typeerr; /**< Number of ICMP packets with a wrong
1268 type. */
1269 } icmp; /**< ICMP statistics. */
1270 struct {
1271 uip_stats_t recv; /**< Number of recived TCP segments. */
1272 uip_stats_t sent; /**< Number of sent TCP segments. */
1273 uip_stats_t drop; /**< Number of dropped TCP segments. */
1274 uip_stats_t chkerr; /**< Number of TCP segments with a bad
1275 checksum. */
1276 uip_stats_t ackerr; /**< Number of TCP segments with a bad ACK
1277 number. */
1278 uip_stats_t rst; /**< Number of recevied TCP RST (reset) segments. */
1279 uip_stats_t rexmit; /**< Number of retransmitted TCP segments. */
1280 uip_stats_t syndrop; /**< Number of dropped SYNs due to too few
1281 connections was available. */
1282 uip_stats_t synrst; /**< Number of SYNs for closed ports,
1283 triggering a RST. */
1284 } tcp; /**< TCP statistics. */
1285#if UIP_UDP
1286 struct {
1287 uip_stats_t drop; /**< Number of dropped UDP segments. */
1288 uip_stats_t recv; /**< Number of recived UDP segments. */
1289 uip_stats_t sent; /**< Number of sent UDP segments. */
1290 uip_stats_t chkerr; /**< Number of UDP segments with a bad
1291 checksum. */
1292 } udp; /**< UDP statistics. */
1293#endif /* UIP_UDP */
1294};
1295
1296/**
1297 * The uIP TCP/IP statistics.
1298 *
1299 * This is the variable in which the uIP TCP/IP statistics are gathered.
1300 */
1301extern struct uip_stats uip_stat;
1302
1303
1304/*---------------------------------------------------------------------------*/
1305/* All the stuff below this point is internal to uIP and should not be
1306 * used directly by an application or by a device driver.
1307 */
1308/*---------------------------------------------------------------------------*/
1309
1310
1311
1312/* uint8_t uip_flags:
1313 *
1314 * When the application is called, uip_flags will contain the flags
1315 * that are defined in this file. Please read below for more
1316 * information.
1317 */
1318extern uint8_t uip_flags;
1319
1320/* The following flags may be set in the global variable uip_flags
1321 before calling the application callback. The UIP_ACKDATA,
1322 UIP_NEWDATA, and UIP_CLOSE flags may both be set at the same time,
1323 whereas the others are mutually exclusive. Note that these flags
1324 should *NOT* be accessed directly, but only through the uIP
1325 functions/macros. */
1326
1327#define UIP_ACKDATA 1 /* Signifies that the outstanding data was
1328 acked and the application should send
1329 out new data instead of retransmitting
1330 the last data. */
1331#define UIP_NEWDATA 2 /* Flags the fact that the peer has sent
1332 us new data. */
1333#define UIP_REXMIT 4 /* Tells the application to retransmit the
1334 data that was last sent. */
1335#define UIP_POLL 8 /* Used for polling the application, to
1336 check if the application has data that
1337 it wants to send. */
1338#define UIP_CLOSE 16 /* The remote host has closed the
1339 connection, thus the connection has
1340 gone away. Or the application signals
1341 that it wants to close the
1342 connection. */
1343#define UIP_ABORT 32 /* The remote host has aborted the
1344 connection, thus the connection has
1345 gone away. Or the application signals
1346 that it wants to abort the
1347 connection. */
1348#define UIP_CONNECTED 64 /* We have got a connection from a remote
1349 host and have set up a new connection
1350 for it, or an active connection has
1351 been successfully established. */
1352
1353#define UIP_TIMEDOUT 128 /* The connection has been aborted due to
1354 too many retransmissions. */
1355
1356/* uip_process(flag):
1357 *
1358 * The actual uIP function which does all the work.
1359 */
1360void uip_process(uint8_t flag);
1361
1362/* The following flags are passed as an argument to the uip_process()
1363 function. They are used to distinguish between the two cases where
1364 uip_process() is called. It can be called either because we have
1365 incoming data that should be processed, or because the periodic
1366 timer has fired. These values are never used directly, but only in
1367 the macros defined in this file. */
1368
1369#define UIP_DATA 1 /* Tells uIP that there is incoming
1370 data in the uip_buf buffer. The
1371 length of the data is stored in the
1372 global variable uip_len. */
1373#define UIP_TIMER 2 /* Tells uIP that the periodic timer
1374 has fired. */
1375#define UIP_POLL_REQUEST 3 /* Tells uIP that a connection should
1376 be polled. */
1377#define UIP_UDP_SEND_CONN 4 /* Tells uIP that a UDP datagram
1378 should be constructed in the
1379 uip_buf buffer. */
1380#if UIP_UDP
1381#define UIP_UDP_TIMER 5
1382#endif /* UIP_UDP */
1383
1384/* The TCP states used in the uip_conn->tcpstateflags. */
1385#define UIP_CLOSED 0
1386#define UIP_SYN_RCVD 1
1387#define UIP_SYN_SENT 2
1388#define UIP_ESTABLISHED 3
1389#define UIP_FIN_WAIT_1 4
1390#define UIP_FIN_WAIT_2 5
1391#define UIP_CLOSING 6
1392#define UIP_TIME_WAIT 7
1393#define UIP_LAST_ACK 8
1394#define UIP_TS_MASK 15
1395
1396#define UIP_STOPPED 16
1397
1398#ifdef __RX
1399#pragma pack
1400#elif _MSC_VER
1401#pragma pack(push, 1)
1402#endif
1403
1404/* The TCP and IP headers. */
1405struct uip_tcpip_hdr {
1406#if UIP_CONF_IPV6
1407 /* IPv6 header. */
1408 uint8_t vtc,
1409 tcflow;
1410 uint16_t flow;
1411 uint8_t len[2];
1412 uint8_t proto, ttl;
1413 uip_ip6addr_t srcipaddr, destipaddr;
1414#else /* UIP_CONF_IPV6 */
1415 /* IPv4 header. */
1416 uint8_t vhl,
1417 tos,
1418 len[2],
1419 ipid[2],
1420 ipoffset[2],
1421 ttl,
1422 proto;
1423 uint16_t ipchksum;
1424 uip_ipaddr_t srcipaddr, destipaddr;
1425#endif /* UIP_CONF_IPV6 */
1426
1427 /* TCP header. */
1428 uint16_t srcport,
1429 destport;
1430 uint8_t seqno[4],
1431 ackno[4],
1432 tcpoffset,
1433 flags,
1434 wnd[2];
1435 uint16_t tcpchksum;
1436 uint8_t urgp[2];
1437 uint8_t optdata[4];
1438};
1439
1440/* The ICMP and IP headers. */
1441struct uip_icmpip_hdr {
1442#if UIP_CONF_IPV6
1443 /* IPv6 header. */
1444 uint8_t vtc,
1445 tcf;
1446 uint16_t flow;
1447 uint8_t len[2];
1448 uint8_t proto, ttl;
1449 uip_ip6addr_t srcipaddr, destipaddr;
1450#else /* UIP_CONF_IPV6 */
1451 /* IPv4 header. */
1452 uint8_t vhl,
1453 tos,
1454 len[2],
1455 ipid[2],
1456 ipoffset[2],
1457 ttl,
1458 proto;
1459 uint16_t ipchksum;
1460 uip_ipaddr_t srcipaddr, destipaddr;
1461#endif /* UIP_CONF_IPV6 */
1462
1463 /* ICMP header. */
1464 uint8_t type, icode;
1465 uint16_t icmpchksum;
1466#if !UIP_CONF_IPV6
1467 uint16_t id, seqno;
1468 uint8_t flags, reserved1, reserved2, reserved3;
1469 uint8_t icmp6data[16];
1470 uint8_t options[1];
1471#endif /* !UIP_CONF_IPV6 */
1472};
1473
1474
1475/* The UDP and IP headers. */
1476struct uip_udpip_hdr {
1477#if UIP_CONF_IPV6
1478 /* IPv6 header. */
1479 uint8_t vtc,
1480 tcf;
1481 uint16_t flow;
1482 uint8_t len[2];
1483 uint8_t proto, ttl;
1484 uip_ip6addr_t srcipaddr, destipaddr;
1485#else /* UIP_CONF_IPV6 */
1486 /* IP header. */
1487 uint8_t vhl,
1488 tos,
1489 len[2],
1490 ipid[2],
1491 ipoffset[2],
1492 ttl,
1493 proto;
1494 uint16_t ipchksum;
1495 uip_ipaddr_t srcipaddr, destipaddr;
1496#endif /* UIP_CONF_IPV6 */
1497
1498 /* UDP header. */
1499 uint16_t srcport,
1500 destport;
1501 uint16_t udplen;
1502 uint16_t udpchksum;
1503};
1504
1505#ifdef __RX
1506#pragma unpack
1507#elif _MSC_VER
1508#pragma pack(pop)
1509#endif
1510
1511/**
1512 * The buffer size available for user data in the \ref uip_buf buffer.
1513 *
1514 * This macro holds the available size for user data in the \ref
1515 * uip_buf buffer. The macro is intended to be used for checking
1516 * bounds of available user data.
1517 *
1518 * Example:
1519 \code
1520 snprintf(uip_appdata, UIP_APPDATA_SIZE, "%u\n", i);
1521 \endcode
1522 *
1523 * \hideinitializer
1524 */
1525#define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN)
1526
1527
1528#define UIP_PROTO_ICMP 1
1529#define UIP_PROTO_TCP 6
1530#define UIP_PROTO_UDP 17
1531#define UIP_PROTO_ICMP6 58
1532
1533/* Header sizes. */
1534#if UIP_CONF_IPV6
1535#define UIP_IPH_LEN 40
1536#else /* UIP_CONF_IPV6 */
1537#define UIP_IPH_LEN 20 /* Size of IP header */
1538#endif /* UIP_CONF_IPV6 */
1539#define UIP_UDPH_LEN 8 /* Size of UDP header */
1540#define UIP_TCPH_LEN 20 /* Size of TCP header */
1541#define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN) /* Size of IP +
1542 UDP
1543 header */
1544#define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN) /* Size of IP +
1545 TCP
1546 header */
1547#define UIP_TCPIP_HLEN UIP_IPTCPH_LEN
1548
1549
1550#if UIP_FIXEDADDR
1551extern const uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
1552#else /* UIP_FIXEDADDR */
1553extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr;
1554#endif /* UIP_FIXEDADDR */
1555extern const uip_ipaddr_t uip_broadcast_addr;
1556extern const uip_ipaddr_t uip_all_zeroes_addr;
1557
1558
1559
1560/**
1561 * Representation of a 48-bit Ethernet address.
1562 */
1563struct uip_eth_addr {
1564 uint8_t addr[6];
1565};
1566
1567/**
1568 * Calculate the Internet checksum over a buffer.
1569 *
1570 * The Internet checksum is the one's complement of the one's
1571 * complement sum of all 16-bit words in the buffer.
1572 *
1573 * See RFC1071.
1574 *
1575 * \param buf A pointer to the buffer over which the checksum is to be
1576 * computed.
1577 *
1578 * \param len The length of the buffer over which the checksum is to
1579 * be computed.
1580 *
1581 * \return The Internet checksum of the buffer.
1582 */
1583uint16_t uip_chksum(uint16_t *buf, uint16_t len);
1584
1585/**
1586 * Calculate the IP header checksum of the packet header in uip_buf.
1587 *
1588 * The IP header checksum is the Internet checksum of the 20 bytes of
1589 * the IP header.
1590 *
1591 * \return The IP header checksum of the IP header in the uip_buf
1592 * buffer.
1593 */
1594uint16_t uip_ipchksum(void);
1595
1596/**
1597 * Calculate the TCP checksum of the packet in uip_buf and uip_appdata.
1598 *
1599 * The TCP checksum is the Internet checksum of data contents of the
1600 * TCP segment, and a pseudo-header as defined in RFC793.
1601 *
1602 * \return The TCP checksum of the TCP segment in uip_buf and pointed
1603 * to by uip_appdata.
1604 */
1605uint16_t uip_tcpchksum(void);
1606
1607/**
1608 * Calculate the UDP checksum of the packet in uip_buf and uip_appdata.
1609 *
1610 * The UDP checksum is the Internet checksum of data contents of the
1611 * UDP segment, and a pseudo-header as defined in RFC768.
1612 *
1613 * \return The UDP checksum of the UDP segment in uip_buf and pointed
1614 * to by uip_appdata.
1615 */
1616uint16_t uip_udpchksum(void);
1617
1618
1619#endif /* __UIP_H__ */
1620
1621
1622/** @} */
Note: See TracBrowser for help on using the repository browser.