Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of UIPEthernet by
Diff: utility/uip.h
- Revision:
- 4:d774541a34da
- Parent:
- 3:5b17e4656dd0
- Child:
- 8:4acb22344932
--- a/utility/uip.h Sat Dec 20 11:10:40 2014 +0000 +++ b/utility/uip.h Sun Mar 08 20:26:56 2015 +0000 @@ -14,6 +14,8 @@ * structures, TCP/IP header structures and function declarations. * */ + + /* * Copyright (c) 2001-2003, Adam Dunkels. * All rights reserved. @@ -47,31 +49,30 @@ * $Id: uip.h,v 1.40 2006/06/08 07:12:07 adam Exp $ * */ + #ifndef __UIP_H__ - #define __UIP_H__ +#define __UIP_H__ - #include "uipopt.h" +#include "uipopt.h" /** * Repressentation of an IP address. * */ - typedef u16_t uip_ip4addr_t[2]; -typedef u16_t uip_ip6addr_t[8]; - #if UIP_CONF_IPV6 -typedef uip_ip6addr_t uip_ipaddr_t; - #else /* UIP_CONF_IPV6 */ - -typedef uip_ip4addr_t uip_ipaddr_t; - #endif /* UIP_CONF_IPV6 */ +typedef u16_t uip_ip6addr_t[8]; +#if UIP_CONF_IPV6 +typedef uip_ip6addr_t uip_ipaddr_t; +#else /* UIP_CONF_IPV6 */ +typedef uip_ip4addr_t uip_ipaddr_t; +#endif /* UIP_CONF_IPV6 */ /*---------------------------------------------------------------------------*/ - /* First, the functions that should be called from the * system. Initialization, the periodic timer and incoming packets are * handled by the following three functions. */ + /** * \defgroup uipconffunc uIP configuration functions * @{ @@ -94,7 +95,7 @@ uip_ipaddr(&addr, 192,168,1,2); uip_sethostaddr(&addr); - + \endcode * \param addr A pointer to an IP address of type uip_ipaddr_t; * @@ -102,7 +103,7 @@ * * \hideinitializer */ - #define uip_sethostaddr(addr) uip_ipaddr_copy(uip_hostaddr, (addr)) +#define uip_sethostaddr(addr) uip_ipaddr_copy(uip_hostaddr, (addr)) /** * Get the IP address of this host. @@ -122,8 +123,7 @@ * * \hideinitializer */ - - #define uip_gethostaddr(addr) uip_ipaddr_copy((addr), uip_hostaddr) +#define uip_gethostaddr(addr) uip_ipaddr_copy((addr), uip_hostaddr) /** * Set the default router's IP address. @@ -135,8 +135,7 @@ * * \hideinitializer */ - - #define uip_setdraddr(addr) uip_ipaddr_copy(uip_draddr, (addr)) +#define uip_setdraddr(addr) uip_ipaddr_copy(uip_draddr, (addr)) /** * Set the netmask. @@ -148,8 +147,8 @@ * * \hideinitializer */ +#define uip_setnetmask(addr) uip_ipaddr_copy(uip_netmask, (addr)) - #define uip_setnetmask(addr) uip_ipaddr_copy(uip_netmask, (addr)) /** * Get the default router's IP address. @@ -159,8 +158,7 @@ * * \hideinitializer */ - - #define uip_getdraddr(addr) uip_ipaddr_copy((addr), uip_draddr) +#define uip_getdraddr(addr) uip_ipaddr_copy((addr), uip_draddr) /** * Get the netmask. @@ -170,8 +168,7 @@ * * \hideinitializer */ - - #define uip_getnetmask(addr) uip_ipaddr_copy((addr), uip_netmask) +#define uip_getnetmask(addr) uip_ipaddr_copy((addr), uip_netmask) /** @} */ @@ -181,20 +178,21 @@ * * The uIP initialization functions are used for booting uIP. */ + /** * uIP initialization function. * * This function should be called at boot up to initilize the uIP * TCP/IP stack. */ -void uip_init(void); +void uip_init(void); /** * uIP initialization function. * * This function may be used at boot time to set the initial ip_id. */ -void uip_setipid(u16_t id); +void uip_setipid(u16_t id); /** @} */ @@ -244,19 +242,19 @@ uip_input(); if(uip_len > 0) { uip_arp_out(); - ethernet_devicedriver_send(); + ethernet_devicedriver_send(); } } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); if(uip_len > 0) { - ethernet_devicedriver_send(); + ethernet_devicedriver_send(); } } \endcode * * \hideinitializer */ - #define uip_input() uip_process(UIP_DATA) +#define uip_input() uip_process(UIP_DATA) /** * Periodic processing for a connection identified by its number. @@ -300,20 +298,14 @@ * * \hideinitializer */ - - #define uip_periodic(conn) \ - do \ - { \ - uip_conn = &uip_conns[conn]; \ - uip_process(UIP_TIMER); \ - } while(0) +#define uip_periodic(conn) do { uip_conn = &uip_conns[conn]; \ + uip_process(UIP_TIMER); } while (0) /** * * */ - - #define uip_conn_active(conn) (uip_conns[conn].tcpstateflags != UIP_CLOSED) +#define uip_conn_active(conn) (uip_conns[conn].tcpstateflags != UIP_CLOSED) /** * Perform periodic processing for a connection identified by a pointer @@ -328,13 +320,8 @@ * * \hideinitializer */ - - #define uip_periodic_conn(conn) \ - do \ - { \ - uip_conn = conn; \ - uip_process(UIP_TIMER); \ - } while(0) +#define uip_periodic_conn(conn) do { uip_conn = conn; \ + uip_process(UIP_TIMER); } while (0) /** * Reuqest that a particular connection should be polled. @@ -347,15 +334,11 @@ * * \hideinitializer */ +#define uip_poll_conn(conn) do { uip_conn = conn; \ + uip_process(UIP_POLL_REQUEST); } while (0) - #define uip_poll_conn(conn) \ - do \ - { \ - uip_conn = conn; \ - uip_process(UIP_POLL_REQUEST); \ - } while(0) - #if UIP_UDP +#if UIP_UDP /** * Periodic processing for a UDP connection identified by its number. * @@ -387,13 +370,8 @@ * * \hideinitializer */ - - #define uip_udp_periodic(conn) \ - do \ - { \ - uip_udp_conn = &uip_udp_conns[conn]; \ - uip_process(UIP_UDP_TIMER); \ - } while(0) +#define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \ + uip_process(UIP_UDP_TIMER); } while (0) /** * Periodic processing for a UDP connection identified by a pointer to @@ -409,16 +387,13 @@ * * \hideinitializer */ +#define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn; \ + uip_process(UIP_UDP_TIMER); } while (0) - #define uip_udp_periodic_conn(conn) \ - do \ - { \ - uip_udp_conn = conn; \ - uip_process(UIP_UDP_TIMER); \ - } while(0) - #endif /* UIP_UDP */ - /** +#endif /* UIP_UDP */ + +/** * The uIP packet buffer. * * The uip_buf array is used to hold incoming and outgoing @@ -444,7 +419,7 @@ } \endcode */ - extern u8_t uip_buf[UIP_BUFSIZE + 2]; +extern u8_t uip_buf[UIP_BUFSIZE+2]; /** @} */ @@ -459,6 +434,7 @@ * * Functions used by an application running of top of uIP. */ + /** * Start listening to the specified port. * @@ -471,7 +447,7 @@ * * \param port A 16-bit port number in network byte order. */ -void uip_listen(u16_t port); +void uip_listen(u16_t port); /** * Stop listening to the specified port. @@ -485,7 +461,7 @@ * * \param port A 16-bit port number in network byte order. */ -void uip_unlisten(u16_t port); +void uip_unlisten(u16_t port); /** * Connect to a remote host using TCP. @@ -519,7 +495,9 @@ * or NULL if no connection could be allocated. * */ -struct uip_conn* uip_connect(uip_ipaddr_t* ripaddr, u16_t port); +struct uip_conn *uip_connect(uip_ipaddr_t *ripaddr, u16_t port); + + /** * \internal @@ -530,8 +508,7 @@ * * \hideinitializer */ - - #define uip_outstanding(conn) ((conn)->len) +#define uip_outstanding(conn) ((conn)->len) /** * Send data on the current connection. @@ -558,7 +535,7 @@ * * \hideinitializer */ -void uip_send(const void* data, int len); +void uip_send(const void *data, int len); /** * The length of any incoming data that is currently avaliable (if avaliable) @@ -569,9 +546,8 @@ * * \hideinitializer */ - /*void uip_datalen(void);*/ - #define uip_datalen() uip_len +#define uip_datalen() uip_len /** * The length of any out-of-band data (urgent data) that has arrived @@ -582,8 +558,7 @@ * * \hideinitializer */ - - #define uip_urgdatalen() uip_urglen +#define uip_urgdatalen() uip_urglen /** * Close the current connection. @@ -592,8 +567,7 @@ * * \hideinitializer */ - - #define uip_close() (uip_flags = UIP_CLOSE) +#define uip_close() (uip_flags = UIP_CLOSE) /** * Abort the current connection. @@ -604,8 +578,7 @@ * * \hideinitializer */ - - #define uip_abort() (uip_flags = UIP_ABORT) +#define uip_abort() (uip_flags = UIP_ABORT) /** * Tell the sending host to stop sending data. @@ -615,8 +588,7 @@ * * \hideinitializer */ - - #define uip_stop() (uip_conn->tcpstateflags |= UIP_STOPPED) +#define uip_stop() (uip_conn->tcpstateflags |= UIP_STOPPED) /** * Find out if the current connection has been previously stopped with @@ -624,8 +596,7 @@ * * \hideinitializer */ - - #define uip_stopped(conn) ((conn)->tcpstateflags & UIP_STOPPED) +#define uip_stopped(conn) ((conn)->tcpstateflags & UIP_STOPPED) /** * Restart the current connection, if is has previously been stopped @@ -636,15 +607,12 @@ * * \hideinitializer */ +#define uip_restart() do { uip_flags |= UIP_NEWDATA; \ + uip_conn->tcpstateflags &= ~UIP_STOPPED; \ + } while(0) - #define uip_restart() \ - do \ - { \ - uip_flags |= UIP_NEWDATA; \ - uip_conn->tcpstateflags &= ~UIP_STOPPED; \ - } while(0) - /* uIP tests that can be made to determine in what state the current +/* uIP tests that can be made to determine in what state the current connection is, and what the application function should do. */ /** @@ -655,7 +623,7 @@ * \hideinitializer * */ - #define uip_udpconnection() (uip_conn == NULL) +#define uip_udpconnection() (uip_conn == NULL) /** * Is new incoming data available? @@ -666,8 +634,7 @@ * * \hideinitializer */ - - #define uip_newdata() (uip_flags & UIP_NEWDATA) +#define uip_newdata() (uip_flags & UIP_NEWDATA) /** * Has previously sent data been acknowledged? @@ -678,8 +645,7 @@ * * \hideinitializer */ - - #define uip_acked() (uip_flags & UIP_ACKDATA) +#define uip_acked() (uip_flags & UIP_ACKDATA) /** * Has the connection just been connected? @@ -691,8 +657,7 @@ * * \hideinitializer */ - - #define uip_connected() (uip_flags & UIP_CONNECTED) +#define uip_connected() (uip_flags & UIP_CONNECTED) /** * Has the connection been closed by the other end? @@ -702,8 +667,7 @@ * * \hideinitializer */ - - #define uip_closed() (uip_flags & UIP_CLOSE) +#define uip_closed() (uip_flags & UIP_CLOSE) /** * Has the connection been aborted by the other end? @@ -713,8 +677,7 @@ * * \hideinitializer */ - - #define uip_aborted() (uip_flags & UIP_ABORT) +#define uip_aborted() (uip_flags & UIP_ABORT) /** * Has the connection timed out? @@ -724,8 +687,7 @@ * * \hideinitializer */ - - #define uip_timedout() (uip_flags & UIP_TIMEDOUT) +#define uip_timedout() (uip_flags & UIP_TIMEDOUT) /** * Do we need to retransmit previously data? @@ -737,8 +699,7 @@ * * \hideinitializer */ - - #define uip_rexmit() (uip_flags & UIP_REXMIT) +#define uip_rexmit() (uip_flags & UIP_REXMIT) /** * Is the connection being polled by uIP? @@ -752,8 +713,7 @@ * * \hideinitializer */ - - #define uip_poll() (uip_flags & UIP_POLL) +#define uip_poll() (uip_flags & UIP_POLL) /** * Get the initial maxium segment size (MSS) of the current @@ -761,8 +721,7 @@ * * \hideinitializer */ - - #define uip_initialmss() (uip_conn->initialmss) +#define uip_initialmss() (uip_conn->initialmss) /** * Get the current maxium segment size that can be sent on the current @@ -775,9 +734,9 @@ * * \hideinitializer */ +#define uip_mss() (uip_conn->mss) - #define uip_mss() (uip_conn->mss) - /** +/** * Set up a new UDP connection. * * This function sets up a new UDP connection. The function will @@ -790,7 +749,7 @@ \code uip_ipaddr_t addr; struct uip_udp_conn *c; - + uip_ipaddr(&addr, 192,168,2,1); c = uip_udp_new(&addr, HTONS(12345)); if(c != NULL) { @@ -804,7 +763,7 @@ * \return The uip_udp_conn structure for the new connection or NULL * if no connection could be allocated. */ - struct uip_udp_conn* uip_udp_new(uip_ipaddr_t* ripaddr, u16_t rport); +struct uip_udp_conn *uip_udp_new(uip_ipaddr_t *ripaddr, u16_t rport); /** * Removed a UDP connection. @@ -813,8 +772,7 @@ * * \hideinitializer */ - - #define uip_udp_remove(conn) (conn)->lport = 0 +#define uip_udp_remove(conn) (conn)->lport = 0 /** * Bind a UDP connection to a local port. @@ -826,8 +784,7 @@ * * \hideinitializer */ - - #define uip_udp_bind(conn, port) (conn)->lport = port +#define uip_udp_bind(conn, port) (conn)->lport = port /** * Send a UDP datagram of length len on the current connection. @@ -840,12 +797,12 @@ * * \hideinitializer */ - - #define uip_udp_send(len) uip_send((char*)uip_appdata, len) +#define uip_udp_send(len) uip_send((char *)uip_appdata, len) /** @} */ /* uIP convenience and converting functions. */ + /** * \defgroup uipconvfunc uIP conversion functions * @{ @@ -853,7 +810,7 @@ * These functions can be used for converting between different data * formats used by uIP. */ - + /** * Construct an IP address from four bytes. * @@ -865,7 +822,7 @@ \code uip_ipaddr_t ipaddr; struct uip_conn *c; - + uip_ipaddr(&ipaddr, 192,168,1,2); c = uip_connect(&ipaddr, HTONS(80)); \endcode @@ -880,12 +837,10 @@ * * \hideinitializer */ - #define uip_ipaddr(addr, addr0, addr1, addr2, addr3) \ - do \ - { \ - ((u16_t *) (addr))[0] = HTONS(((addr0) << 8) | (addr1)); \ - ((u16_t *) (addr))[1] = HTONS(((addr2) << 8) | (addr3)); \ - } while(0) +#define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \ + ((u16_t *)(addr))[0] = HTONS(((addr0) << 8) | (addr1)); \ + ((u16_t *)(addr))[1] = HTONS(((addr2) << 8) | (addr3)); \ + } while(0) /** * Construct an IPv6 address from eight 16-bit words. @@ -894,19 +849,18 @@ * * \hideinitializer */ +#define uip_ip6addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) do { \ + ((u16_t *)(addr))[0] = HTONS((addr0)); \ + ((u16_t *)(addr))[1] = HTONS((addr1)); \ + ((u16_t *)(addr))[2] = HTONS((addr2)); \ + ((u16_t *)(addr))[3] = HTONS((addr3)); \ + ((u16_t *)(addr))[4] = HTONS((addr4)); \ + ((u16_t *)(addr))[5] = HTONS((addr5)); \ + ((u16_t *)(addr))[6] = HTONS((addr6)); \ + ((u16_t *)(addr))[7] = HTONS((addr7)); \ + } while(0) - #define uip_ip6addr(addr, addr0, addr1, addr2, addr3, addr4, addr5, addr6, addr7) \ - do \ - { \ - ((u16_t *) (addr))[0] = HTONS((addr0)); \ - ((u16_t *) (addr))[1] = HTONS((addr1)); \ - ((u16_t *) (addr))[2] = HTONS((addr2)); \ - ((u16_t *) (addr))[3] = HTONS((addr3)); \ - ((u16_t *) (addr))[4] = HTONS((addr4)); \ - ((u16_t *) (addr))[5] = HTONS((addr5)); \ - ((u16_t *) (addr))[6] = HTONS((addr6)); \ - ((u16_t *) (addr))[7] = HTONS((addr7)); \ - } while(0) /** +/** * Copy an IP address to another IP address. * * Copies an IP address from one place to another. @@ -924,20 +878,16 @@ * * \hideinitializer */ +#if !UIP_CONF_IPV6 +#define uip_ipaddr_copy(dest, src) do { \ + ((u16_t *)dest)[0] = ((u16_t *)src)[0]; \ + ((u16_t *)dest)[1] = ((u16_t *)src)[1]; \ + } while(0) +#else /* !UIP_CONF_IPV6 */ +#define uip_ipaddr_copy(dest, src) memcpy(dest, src, sizeof(uip_ip6addr_t)) +#endif /* !UIP_CONF_IPV6 */ - #if !UIP_CONF_IPV6 - #define uip_ipaddr_copy(dest, src) \ - do \ - { \ - ((u16_t*)dest)[0] = ((u16_t*)src)[0]; \ - ((u16_t*)dest)[1] = ((u16_t*)src)[1]; \ - } while(0) - #else /* !UIP_CONF_IPV6 */ - - #define uip_ipaddr_copy(dest, src) memcpy(dest, src, sizeof(uip_ip6addr_t)) - #endif /* !UIP_CONF_IPV6 */ - - /** +/** * Compare two IP addresses * * Compares two IP addresses. @@ -957,14 +907,12 @@ * * \hideinitializer */ - - #if !UIP_CONF_IPV6 - #define uip_ipaddr_cmp(addr1, addr2) \ - (((u16_t*)addr1)[0] == ((u16_t*)addr2)[0] && ((u16_t*)addr1)[1] == ((u16_t*)addr2)[1]) - #else /* !UIP_CONF_IPV6 */ - - #define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0) - #endif /* !UIP_CONF_IPV6 */ +#if !UIP_CONF_IPV6 +#define uip_ipaddr_cmp(addr1, addr2) (((u16_t *)addr1)[0] == ((u16_t *)addr2)[0] && \ + ((u16_t *)addr1)[1] == ((u16_t *)addr2)[1]) +#else /* !UIP_CONF_IPV6 */ +#define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0) +#endif /* !UIP_CONF_IPV6 */ /** * Compare two IP addresses with netmasks @@ -990,12 +938,12 @@ * * \hideinitializer */ +#define uip_ipaddr_maskcmp(addr1, addr2, mask) \ + (((((u16_t *)addr1)[0] & ((u16_t *)mask)[0]) == \ + (((u16_t *)addr2)[0] & ((u16_t *)mask)[0])) && \ + ((((u16_t *)addr1)[1] & ((u16_t *)mask)[1]) == \ + (((u16_t *)addr2)[1] & ((u16_t *)mask)[1]))) - #define uip_ipaddr_maskcmp(addr1, addr2, mask) \ - ( \ - ((((u16_t*)addr1)[0] & ((u16_t*)mask)[0]) == (((u16_t*)addr2)[0] & ((u16_t*)mask)[0])) \ - && ((((u16_t*)addr1)[1] & ((u16_t*)mask)[1]) == (((u16_t*)addr2)[1] & ((u16_t*)mask)[1])) \ - ) /** * Mask out the network part of an IP address. @@ -1021,13 +969,10 @@ * * \hideinitializer */ - - #define uip_ipaddr_mask(dest, src, mask) \ - do \ - { \ - ((u16_t*)dest)[0] = ((u16_t*)src)[0] & ((u16_t*)mask)[0]; \ - ((u16_t*)dest)[1] = ((u16_t*)src)[1] & ((u16_t*)mask)[1]; \ - } while(0) +#define uip_ipaddr_mask(dest, src, mask) do { \ + ((u16_t *)dest)[0] = ((u16_t *)src)[0] & ((u16_t *)mask)[0]; \ + ((u16_t *)dest)[1] = ((u16_t *)src)[1] & ((u16_t *)mask)[1]; \ + } while(0) /** * Pick the first octet of an IP address. @@ -1047,8 +992,7 @@ * * \hideinitializer */ - - #define uip_ipaddr1(addr) (htons(((u16_t *) (addr))[0]) >> 8) +#define uip_ipaddr1(addr) (htons(((u16_t *)(addr))[0]) >> 8) /** * Pick the second octet of an IP address. @@ -1068,8 +1012,7 @@ * * \hideinitializer */ - - #define uip_ipaddr2(addr) (htons(((u16_t *) (addr))[0]) & 0xff) +#define uip_ipaddr2(addr) (htons(((u16_t *)(addr))[0]) & 0xff) /** * Pick the third octet of an IP address. @@ -1089,8 +1032,7 @@ * * \hideinitializer */ - - #define uip_ipaddr3(addr) (htons(((u16_t *) (addr))[1]) >> 8) +#define uip_ipaddr3(addr) (htons(((u16_t *)(addr))[1]) >> 8) /** * Pick the fourth octet of an IP address. @@ -1110,9 +1052,9 @@ * * \hideinitializer */ +#define uip_ipaddr4(addr) (htons(((u16_t *)(addr))[1]) & 0xff) - #define uip_ipaddr4(addr) (htons(((u16_t *) (addr))[1]) & 0xff) - /** +/** * Convert 16-bit quantity from host byte order to network byte order. * * This macro is primarily used for converting constants from host @@ -1121,34 +1063,30 @@ * * \hideinitializer */ - - #ifndef HTONS - #if UIP_BYTE_ORDER == UIP_BIG_ENDIAN - #define HTONS(n) (n) - #else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */ +#ifndef HTONS +# if UIP_BYTE_ORDER == UIP_BIG_ENDIAN +# define HTONS(n) (n) +# else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */ +# define HTONS(n) (u16_t)((((u16_t) (n)) << 8) | (((u16_t) (n)) >> 8)) +# endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */ +#else +#error "HTONS already defined!" +#endif /* HTONS */ - #define HTONS(n) (u16_t) ((((u16_t) (n)) << 8) | (((u16_t) (n)) >> 8)) - #endif /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */ - - #else - #error "HTONS already defined!" - #endif /* HTONS */ - - /** +/** * Convert 16-bit quantity from host byte order to network byte order. * * This function is primarily used for converting variables from host * byte order to network byte order. For converting constants to * network byte order, use the HTONS() macro instead. */ +#ifndef htons +u16_t htons(u16_t val); +#endif /* htons */ +#ifndef ntohs +#define ntohs htons +#endif - #ifndef htons - u16_t htons(u16_t val); - #endif /* htons */ - - #ifndef ntohs - #define ntohs htons - #endif /** @} */ /** @@ -1158,16 +1096,17 @@ * called. If the application wishes to send data, the application may * use this space to write the data into before calling uip_send(). */ -extern void* uip_appdata; +extern void *uip_appdata; - #if UIP_URGDATA > 0 +#if UIP_URGDATA > 0 /* u8_t *uip_urgdata: * * This pointer points to any urgent data that has been received. Only * present if compiled with support for urgent data (UIP_URGDATA). */ -extern void* uip_urgdata; - #endif /* UIP_URGDATA > 0 */ +extern void *uip_urgdata; +#endif /* UIP_URGDATA > 0 */ + /** * \defgroup uipdrivervars Variables used in uIP device drivers @@ -1192,12 +1131,14 @@ * packet. * */ -extern u16_t uip_len; +extern u16_t uip_len; /** @} */ - #if UIP_URGDATA > 0 -extern u16_t uip_urglen, uip_surglen; - #endif /* UIP_URGDATA > 0 */ + +#if UIP_URGDATA > 0 +extern u16_t uip_urglen, uip_surglen; +#endif /* UIP_URGDATA > 0 */ + /** * Representation of a uIP TCP connection. @@ -1209,146 +1150,137 @@ * file pointers) for the connection. The type of this field is * configured in the "uipopt.h" header file. */ - -struct uip_conn -{ - uip_ipaddr_t ripaddr; /**< The IP address of the remote host. */ - - u16_t lport; /**< The local TCP port, in network byte order. */ - u16_t rport; /**< The local remote TCP port, in network byte - order. */ - - u8_t rcv_nxt[4]; /**< The sequence number that we expect to - receive next. */ - u8_t snd_nxt[4]; /**< The sequence number that was last sent by +struct uip_conn { + uip_ipaddr_t ripaddr; /**< The IP address of the remote host. */ + + u16_t lport; /**< The local TCP port, in network byte order. */ + u16_t rport; /**< The local remote TCP port, in network byte + order. */ + + u8_t rcv_nxt[4]; /**< The sequence number that we expect to + receive next. */ + u8_t snd_nxt[4]; /**< The sequence number that was last sent by us. */ - u16_t len; /**< Length of the data that was previously sent. */ - u16_t mss; /**< Current maximum segment size for the - connection. */ - u16_t initialmss; /**< Initial maximum segment size for the - connection. */ - u8_t sa; /**< Retransmission time-out calculation state - variable. */ - u8_t sv; /**< Retransmission time-out calculation state - variable. */ - u8_t rto; /**< Retransmission time-out. */ - u8_t tcpstateflags; /**< TCP state and flags. */ - u8_t timer; /**< The retransmission timer. */ - u8_t nrtx; /**< The number of retransmissions for the last - segment sent. */ + u16_t len; /**< Length of the data that was previously sent. */ + u16_t mss; /**< Current maximum segment size for the + connection. */ + u16_t initialmss; /**< Initial maximum segment size for the + connection. */ + u8_t sa; /**< Retransmission time-out calculation state + variable. */ + u8_t sv; /**< Retransmission time-out calculation state + variable. */ + u8_t rto; /**< Retransmission time-out. */ + u8_t tcpstateflags; /**< TCP state and flags. */ + u8_t timer; /**< The retransmission timer. */ + u8_t nrtx; /**< The number of retransmissions for the last + segment sent. */ - /** The application state. */ - uip_tcp_appstate_t appstate; + /** The application state. */ + uip_tcp_appstate_t appstate; }; + /** * Pointer to the current TCP connection. * * The uip_conn pointer can be used to access the current TCP * connection. */ -extern struct uip_conn* uip_conn; - +extern struct uip_conn *uip_conn; /* The array containing all uIP connections. */ -extern struct uip_conn uip_conns[UIP_CONNS]; - +extern struct uip_conn uip_conns[UIP_CONNS]; /** * \addtogroup uiparch * @{ */ + /** * 4-byte array used for the 32-bit sequence number calculations. */ -extern u8_t uip_acc32[4]; +extern u8_t uip_acc32[4]; /** @} */ - #if UIP_UDP +#if UIP_UDP /** * Representation of a uIP UDP connection. */ -struct uip_udp_conn -{ - uip_ipaddr_t ripaddr; /**< The IP address of the remote peer. */ - u16_t lport; /**< The local port number in network byte order. */ - u16_t rport; /**< The remote port number in network byte order. */ - u8_t ttl; /**< Default time-to-live. */ +struct uip_udp_conn { + uip_ipaddr_t ripaddr; /**< The IP address of the remote peer. */ + u16_t lport; /**< The local port number in network byte order. */ + u16_t rport; /**< The remote port number in network byte order. */ + u8_t ttl; /**< Default time-to-live. */ - /** The application state. */ - uip_udp_appstate_t appstate; + /** The application state. */ + uip_udp_appstate_t appstate; }; /** * The current UDP connection. */ -extern struct uip_udp_conn* uip_udp_conn; -extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS]; - #endif /* UIP_UDP */ +extern struct uip_udp_conn *uip_udp_conn; +extern struct uip_udp_conn uip_udp_conns[UIP_UDP_CONNS]; +#endif /* UIP_UDP */ /** * The structure holding the TCP/IP statistics that are gathered if * UIP_STATISTICS is set to 1. * */ - -struct uip_stats -{ - struct - { - uip_stats_t drop; /**< Number of dropped packets at the IP - layer. */ - uip_stats_t recv; /**< Number of received packets at the IP - layer. */ - uip_stats_t sent; /**< Number of sent packets at the IP - layer. */ - uip_stats_t vhlerr; /**< Number of packets dropped due to wrong - IP version or header length. */ - uip_stats_t hblenerr; /**< Number of packets dropped due to wrong - IP length, high byte. */ - uip_stats_t lblenerr; /**< Number of packets dropped due to wrong - IP length, low byte. */ - uip_stats_t fragerr; /**< Number of packets dropped since they - were IP fragments. */ - uip_stats_t chkerr; /**< Number of packets dropped due to IP - checksum errors. */ - uip_stats_t protoerr; /**< Number of packets dropped since they - were neither ICMP, UDP nor TCP. */ - } ip; /**< IP statistics. */ - struct - { - uip_stats_t drop; /**< Number of dropped ICMP packets. */ - uip_stats_t recv; /**< Number of received ICMP packets. */ - uip_stats_t sent; /**< Number of sent ICMP packets. */ - uip_stats_t typeerr; /**< Number of ICMP packets with a wrong - type. */ - } icmp; /**< ICMP statistics. */ - struct - { - uip_stats_t drop; /**< Number of dropped TCP segments. */ - uip_stats_t recv; /**< Number of recived TCP segments. */ - uip_stats_t sent; /**< Number of sent TCP segments. */ - uip_stats_t chkerr; /**< Number of TCP segments with a bad - checksum. */ - uip_stats_t ackerr; /**< Number of TCP segments with a bad ACK - number. */ - uip_stats_t rst; /**< Number of recevied TCP RST (reset) segments. */ - uip_stats_t rexmit; /**< Number of retransmitted TCP segments. */ - uip_stats_t syndrop; /**< Number of dropped SYNs due to too few - connections was avaliable. */ - uip_stats_t synrst; /**< Number of SYNs for closed ports, - triggering a RST. */ - } tcp; /**< TCP statistics. */ - #if UIP_UDP - struct - { - uip_stats_t drop; /**< Number of dropped UDP segments. */ - uip_stats_t recv; /**< Number of recived UDP segments. */ - uip_stats_t sent; /**< Number of sent UDP segments. */ - uip_stats_t chkerr; /**< Number of UDP segments with a bad - checksum. */ - } udp; /**< UDP statistics. */ - #endif /* UIP_UDP */ +struct uip_stats { + struct { + uip_stats_t drop; /**< Number of dropped packets at the IP + layer. */ + uip_stats_t recv; /**< Number of received packets at the IP + layer. */ + uip_stats_t sent; /**< Number of sent packets at the IP + layer. */ + uip_stats_t vhlerr; /**< Number of packets dropped due to wrong + IP version or header length. */ + uip_stats_t hblenerr; /**< Number of packets dropped due to wrong + IP length, high byte. */ + uip_stats_t lblenerr; /**< Number of packets dropped due to wrong + IP length, low byte. */ + uip_stats_t fragerr; /**< Number of packets dropped since they + were IP fragments. */ + uip_stats_t chkerr; /**< Number of packets dropped due to IP + checksum errors. */ + uip_stats_t protoerr; /**< Number of packets dropped since they + were neither ICMP, UDP nor TCP. */ + } ip; /**< IP statistics. */ + struct { + uip_stats_t drop; /**< Number of dropped ICMP packets. */ + uip_stats_t recv; /**< Number of received ICMP packets. */ + uip_stats_t sent; /**< Number of sent ICMP packets. */ + uip_stats_t typeerr; /**< Number of ICMP packets with a wrong + type. */ + } icmp; /**< ICMP statistics. */ + struct { + uip_stats_t drop; /**< Number of dropped TCP segments. */ + uip_stats_t recv; /**< Number of recived TCP segments. */ + uip_stats_t sent; /**< Number of sent TCP segments. */ + uip_stats_t chkerr; /**< Number of TCP segments with a bad + checksum. */ + uip_stats_t ackerr; /**< Number of TCP segments with a bad ACK + number. */ + uip_stats_t rst; /**< Number of recevied TCP RST (reset) segments. */ + uip_stats_t rexmit; /**< Number of retransmitted TCP segments. */ + uip_stats_t syndrop; /**< Number of dropped SYNs due to too few + connections was avaliable. */ + uip_stats_t synrst; /**< Number of SYNs for closed ports, + triggering a RST. */ + } tcp; /**< TCP statistics. */ +#if UIP_UDP + struct { + uip_stats_t drop; /**< Number of dropped UDP segments. */ + uip_stats_t recv; /**< Number of recived UDP segments. */ + uip_stats_t sent; /**< Number of sent UDP segments. */ + uip_stats_t chkerr; /**< Number of UDP segments with a bad + checksum. */ + } udp; /**< UDP statistics. */ +#endif /* UIP_UDP */ }; /** @@ -1358,6 +1290,7 @@ */ extern struct uip_stats uip_stat; + /*---------------------------------------------------------------------------*/ /* All the stuff below this point is internal to uIP and should not be * used directly by an application or by a device driver. @@ -1369,7 +1302,7 @@ * that are defined in this file. Please read below for more * infomation. */ -extern u8_t uip_flags; +extern u8_t uip_flags; /* The following flags may be set in the global variable uip_flags before calling the application callback. The UIP_ACKDATA, @@ -1378,46 +1311,40 @@ should *NOT* be accessed directly, but only through the uIP functions/macros. */ - #define UIP_ACKDATA 1 /* Signifies that the outstanding data was - acked and the application should send - out new data instead of retransmitting - the last data. */ - - #define UIP_NEWDATA 2 /* Flags the fact that the peer has sent - us new data. */ - - #define UIP_REXMIT 4 /* Tells the application to retransmit the - data that was last sent. */ - - #define UIP_POLL 8 /* Used for polling the application, to - check if the application has data that - it wants to send. */ - - #define UIP_CLOSE 16 /* The remote host has closed the - connection, thus the connection has - gone away. Or the application signals - that it wants to close the - connection. */ - - #define UIP_ABORT 32 /* The remote host has aborted the - connection, thus the connection has - gone away. Or the application signals - that it wants to abort the - connection. */ - - #define UIP_CONNECTED 64 /* We have got a connection from a remote +#define UIP_ACKDATA 1 /* Signifies that the outstanding data was + acked and the application should send + out new data instead of retransmitting + the last data. */ +#define UIP_NEWDATA 2 /* Flags the fact that the peer has sent + us new data. */ +#define UIP_REXMIT 4 /* Tells the application to retransmit the + data that was last sent. */ +#define UIP_POLL 8 /* Used for polling the application, to + check if the application has data that + it wants to send. */ +#define UIP_CLOSE 16 /* The remote host has closed the + connection, thus the connection has + gone away. Or the application signals + that it wants to close the + connection. */ +#define UIP_ABORT 32 /* The remote host has aborted the + connection, thus the connection has + gone away. Or the application signals + that it wants to abort the + connection. */ +#define UIP_CONNECTED 64 /* We have got a connection from a remote host and have set up a new connection for it, or an active connection has been successfully established. */ - #define UIP_TIMEDOUT 128 /* The connection has been aborted due to - too many retransmissions. */ +#define UIP_TIMEDOUT 128 /* The connection has been aborted due to + too many retransmissions. */ /* uip_process(flag): * * The actual uIP function which does all the work. */ -void uip_process(u8_t flag); +void uip_process(u8_t flag); /* The following flags are passed as an argument to the uip_process() function. They are used to distinguish between the two cases where @@ -1425,123 +1352,142 @@ incoming data that should be processed, or because the periodic timer has fired. These values are never used directly, but only in the macrose defined in this file. */ - - #define UIP_DATA 1 /* Tells uIP that there is incoming - data in the uip_buf buffer. The - length of the data is stored in the - global variable uip_len. */ - - #define UIP_TIMER 2 /* Tells uIP that the periodic timer - has fired. */ - - #define UIP_POLL_REQUEST 3 /* Tells uIP that a connection should - be polled. */ - - #define UIP_UDP_SEND_CONN 4 /* Tells uIP that a UDP datagram - should be constructed in the - uip_buf buffer. */ - - #if UIP_UDP - #define UIP_UDP_TIMER 5 - #endif /* UIP_UDP */ + +#define UIP_DATA 1 /* Tells uIP that there is incoming + data in the uip_buf buffer. The + length of the data is stored in the + global variable uip_len. */ +#define UIP_TIMER 2 /* Tells uIP that the periodic timer + has fired. */ +#define UIP_POLL_REQUEST 3 /* Tells uIP that a connection should + be polled. */ +#define UIP_UDP_SEND_CONN 4 /* Tells uIP that a UDP datagram + should be constructed in the + uip_buf buffer. */ +#if UIP_UDP +#define UIP_UDP_TIMER 5 +#endif /* UIP_UDP */ /* The TCP states used in the uip_conn->tcpstateflags. */ - - #define UIP_CLOSED 0 - #define UIP_SYN_RCVD 1 - #define UIP_SYN_SENT 2 - #define UIP_ESTABLISHED 3 - #define UIP_FIN_WAIT_1 4 - #define UIP_FIN_WAIT_2 5 - #define UIP_CLOSING 6 - #define UIP_TIME_WAIT 7 - #define UIP_LAST_ACK 8 - #define UIP_TS_MASK 15 - - #define UIP_STOPPED 16 +#define UIP_CLOSED 0 +#define UIP_SYN_RCVD 1 +#define UIP_SYN_SENT 2 +#define UIP_ESTABLISHED 3 +#define UIP_FIN_WAIT_1 4 +#define UIP_FIN_WAIT_2 5 +#define UIP_CLOSING 6 +#define UIP_TIME_WAIT 7 +#define UIP_LAST_ACK 8 +#define UIP_TS_MASK 15 + +#define UIP_STOPPED 16 /* The TCP and IP headers. */ -struct uip_tcpip_hdr -{ - #if UIP_CONF_IPV6 - /* IPv6 header. */ - u8_t vtc, tcflow; - u16_t flow; - u8_t len[2]; - u8_t proto, ttl; - uip_ip6addr_t srcipaddr, destipaddr; - #else /* UIP_CONF_IPV6 */ - /* IPv4 header. */ - - u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto; - u16_t ipchksum; - u16_t srcipaddr[2], destipaddr[2]; - #endif /* UIP_CONF_IPV6 */ - - /* TCP header. */ - - u16_t srcport, destport; - u8_t seqno[4], ackno[4], tcpoffset, flags, wnd[2]; - u16_t tcpchksum; - u8_t urgp[2]; - u8_t optdata[4]; +struct uip_tcpip_hdr { +#if UIP_CONF_IPV6 + /* IPv6 header. */ + u8_t vtc, + tcflow; + u16_t flow; + u8_t len[2]; + u8_t proto, ttl; + uip_ip6addr_t srcipaddr, destipaddr; +#else /* UIP_CONF_IPV6 */ + /* IPv4 header. */ + u8_t vhl, + tos, + len[2], + ipid[2], + ipoffset[2], + ttl, + proto; + u16_t ipchksum; + u16_t srcipaddr[2], + destipaddr[2]; +#endif /* UIP_CONF_IPV6 */ + + /* TCP header. */ + u16_t srcport, + destport; + u8_t seqno[4], + ackno[4], + tcpoffset, + flags, + wnd[2]; + u16_t tcpchksum; + u8_t urgp[2]; + u8_t optdata[4]; }; /* The ICMP and IP headers. */ -struct uip_icmpip_hdr -{ - #if UIP_CONF_IPV6 - /* IPv6 header. */ - u8_t vtc, tcf; - u16_t flow; - u8_t len[2]; - u8_t proto, ttl; - uip_ip6addr_t srcipaddr, destipaddr; - #else /* UIP_CONF_IPV6 */ - /* IPv4 header. */ - - u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto; - u16_t ipchksum; - u16_t srcipaddr[2], destipaddr[2]; - #endif /* UIP_CONF_IPV6 */ - - /* ICMP (echo) header. */ - - u8_t type, icode; - u16_t icmpchksum; - #if !UIP_CONF_IPV6 - u16_t id, seqno; - #else /* !UIP_CONF_IPV6 */ - u8_t flags, reserved1, reserved2, reserved3; - u8_t icmp6data[16]; - u8_t options[1]; - #endif /* !UIP_CONF_IPV6 */ +struct uip_icmpip_hdr { +#if UIP_CONF_IPV6 + /* IPv6 header. */ + u8_t vtc, + tcf; + u16_t flow; + u8_t len[2]; + u8_t proto, ttl; + uip_ip6addr_t srcipaddr, destipaddr; +#else /* UIP_CONF_IPV6 */ + /* IPv4 header. */ + u8_t vhl, + tos, + len[2], + ipid[2], + ipoffset[2], + ttl, + proto; + u16_t ipchksum; + u16_t srcipaddr[2], + destipaddr[2]; +#endif /* UIP_CONF_IPV6 */ + + /* ICMP (echo) header. */ + u8_t type, icode; + u16_t icmpchksum; +#if !UIP_CONF_IPV6 + u16_t id, seqno; +#else /* !UIP_CONF_IPV6 */ + u8_t flags, reserved1, reserved2, reserved3; + u8_t icmp6data[16]; + u8_t options[1]; +#endif /* !UIP_CONF_IPV6 */ }; + /* The UDP and IP headers. */ -struct uip_udpip_hdr -{ - #if UIP_CONF_IPV6 - /* IPv6 header. */ - u8_t vtc, tcf; - u16_t flow; - u8_t len[2]; - u8_t proto, ttl; - uip_ip6addr_t srcipaddr, destipaddr; - #else /* UIP_CONF_IPV6 */ - /* IP header. */ +struct uip_udpip_hdr { +#if UIP_CONF_IPV6 + /* IPv6 header. */ + u8_t vtc, + tcf; + u16_t flow; + u8_t len[2]; + u8_t proto, ttl; + uip_ip6addr_t srcipaddr, destipaddr; +#else /* UIP_CONF_IPV6 */ + /* IP header. */ + u8_t vhl, + tos, + len[2], + ipid[2], + ipoffset[2], + ttl, + proto; + u16_t ipchksum; + u16_t srcipaddr[2], + destipaddr[2]; +#endif /* UIP_CONF_IPV6 */ + + /* UDP header. */ + u16_t srcport, + destport; + u16_t udplen; + u16_t udpchksum; +}; - u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto; - u16_t ipchksum; - u16_t srcipaddr[2], destipaddr[2]; - #endif /* UIP_CONF_IPV6 */ - /* UDP header. */ - - u16_t srcport, destport; - u16_t udplen; - u16_t udpchksum; -}; /** * The buffer size available for user data in the \ref uip_buf buffer. @@ -1557,49 +1503,44 @@ * * \hideinitializer */ - #define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) - #define UIP_PROTO_ICMP 1 - #define UIP_PROTO_TCP 6 - #define UIP_PROTO_UDP 17 - #define UIP_PROTO_ICMP6 58 +#define UIP_APPDATA_SIZE (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) + + +#define UIP_PROTO_ICMP 1 +#define UIP_PROTO_TCP 6 +#define UIP_PROTO_UDP 17 +#define UIP_PROTO_ICMP6 58 /* Header sizes. */ - - #if UIP_CONF_IPV6 - #define UIP_IPH_LEN 40 - #else /* UIP_CONF_IPV6 */ - - #define UIP_IPH_LEN 20 /* Size of IP header */ - #endif /* UIP_CONF_IPV6 */ - - #define UIP_UDPH_LEN 8 /* Size of UDP header */ - - #define UIP_TCPH_LEN 20 /* Size of TCP header */ +#if UIP_CONF_IPV6 +#define UIP_IPH_LEN 40 +#else /* UIP_CONF_IPV6 */ +#define UIP_IPH_LEN 20 /* Size of IP header */ +#endif /* UIP_CONF_IPV6 */ +#define UIP_UDPH_LEN 8 /* Size of UDP header */ +#define UIP_TCPH_LEN 20 /* Size of TCP header */ +#define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN) /* Size of IP + + UDP + header */ +#define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN) /* Size of IP + + TCP + header */ +#define UIP_TCPIP_HLEN UIP_IPTCPH_LEN - #define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN) /* Size of IP + - UDP - header */ - - #define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN) /* Size of IP + - TCP - header */ - #define UIP_TCPIP_HLEN UIP_IPTCPH_LEN +#if UIP_FIXEDADDR +extern const uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr; +#else /* UIP_FIXEDADDR */ +extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr; +#endif /* UIP_FIXEDADDR */ - #if UIP_FIXEDADDR -extern const uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr; - #else /* UIP_FIXEDADDR */ -extern uip_ipaddr_t uip_hostaddr, uip_netmask, uip_draddr; - #endif /* UIP_FIXEDADDR */ /** * Representation of a 48-bit Ethernet address. */ - -struct uip_eth_addr -{ - u8_t addr[6]; +struct uip_eth_addr { + u8_t addr[6]; }; /** @@ -1618,7 +1559,7 @@ * * \return The Internet checksum of the buffer. */ -u16_t uip_chksum(u16_t* buf, u16_t len); +u16_t uip_chksum(u16_t *buf, u16_t len); /** * Calculate the IP header checksum of the packet header in uip_buf. @@ -1629,7 +1570,7 @@ * \return The IP header checksum of the IP header in the uip_buf * buffer. */ -u16_t uip_ipchksum(void); +u16_t uip_ipchksum(void); /** * Calculate the TCP checksum of the packet in uip_buf and uip_appdata. @@ -1640,7 +1581,7 @@ * \return The TCP checksum of the TCP segment in uip_buf and pointed * to by uip_appdata. */ -u16_t uip_tcpchksum(void); +u16_t uip_tcpchksum(void); /** * Calculate the UDP checksum of the packet in uip_buf and uip_appdata. @@ -1651,7 +1592,10 @@ * \return The UDP checksum of the UDP segment in uip_buf and pointed * to by uip_appdata. */ -u16_t uip_udpchksum(void); +u16_t uip_udpchksum(void); + + #endif /* __UIP_H__ */ + /** @} */