diff options
Diffstat (limited to 'nuttx/include')
-rw-r--r-- | nuttx/include/net/uip/httpd.h | 78 | ||||
-rw-r--r-- | nuttx/include/net/uip/psock.h | 237 | ||||
-rw-r--r-- | nuttx/include/net/uip/resolv.h | 60 | ||||
-rw-r--r-- | nuttx/include/net/uip/smtp.h | 75 | ||||
-rw-r--r-- | nuttx/include/net/uip/uip-arch.h | 343 | ||||
-rw-r--r-- | nuttx/include/net/uip/uip-arp.h | 122 | ||||
-rw-r--r-- | nuttx/include/net/uip/uip.h | 1172 | ||||
-rw-r--r-- | nuttx/include/net/uip/uipopt.h | 423 |
8 files changed, 2510 insertions, 0 deletions
diff --git a/nuttx/include/net/uip/httpd.h b/nuttx/include/net/uip/httpd.h new file mode 100644 index 000000000..1c9420448 --- /dev/null +++ b/nuttx/include/net/uip/httpd.h @@ -0,0 +1,78 @@ +/* httpd.h + * + * Copyright (c) 2001-2005, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __HTTPD_H__ +#define __HTTPD_H__ + +#include <sys/types.h> +#include <net/uip/psock.h> + +#define HTTPD_FS_STATISTICS 1 + +struct httpd_fs_file +{ + char *data; + int len; +}; + +struct httpd_state +{ + unsigned char timer; + struct psock sin, sout; + char inputbuf[50]; + char filename[20]; + char state; + struct httpd_fs_file file; + int len; + char *scriptptr; + int scriptlen; + + unsigned short count; +}; + +#ifdef HTTPD_FS_STATISTICS +#if HTTPD_FS_STATISTICS == 1 +extern uint16 httpd_fs_count(char *name); +#endif /* HTTPD_FS_STATISTICS */ +#endif /* HTTPD_FS_STATISTICS */ + +void httpd_init(void); +void httpd_log(char *msg); +void httpd_log_file(uint16 *requester, char *file); + +/* file must be allocated by caller and will be filled in + * by the function. + */ + +int httpd_fs_open(const char *name, struct httpd_fs_file *file); +void httpd_fs_init(void); + + +#endif /* __HTTPD_H__ */ diff --git a/nuttx/include/net/uip/psock.h b/nuttx/include/net/uip/psock.h new file mode 100644 index 000000000..9e505c970 --- /dev/null +++ b/nuttx/include/net/uip/psock.h @@ -0,0 +1,237 @@ +/* psock.h + * Protosocket library header file + * Author: Adam Dunkels <adam@sics.se> + * + * Copyright (c) 2004, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* psock Protosockets library + * + * The protosocket library provides an interface to the uIP stack that is + * similar to the traditional BSD socket interface. Unlike programs + * written for the ordinary uIP event-driven interface, programs + * written with the protosocket library are executed in a sequential + * fashion and does not have to be implemented as explicit state + * machines. + * + * Protosockets only work with TCP connections. + * + * The protosocket library uses \ref pt protothreads to provide + * sequential control flow. This makes the protosockets lightweight in + * terms of memory, but also means that protosockets inherits the + * functional limitations of protothreads. Each protosocket lives only + * within a single function. Automatic variables (stack variables) are + * not retained across a protosocket library function call. + * + * \note Because the protosocket library uses protothreads, local + * variables will not always be saved across a call to a protosocket + * library function. It is therefore advised that local variables are + * used with extreme care. + * + * The protosocket library provides functions for sending data without + * having to deal with retransmissions and acknowledgements, as well + * as functions for reading data without having to deal with data + * being split across more than one TCP segment. + * + * Because each protosocket runs as a protothread, the protosocket has to be + * started with a call to PSOCK_BEGIN() at the start of the function + * in which the protosocket is used. Similarly, the protosocket protothread can + * be terminated by a call to PSOCK_EXIT(). + * + */ + +#ifndef __PSOCK_H__ +#define __PSOCK_H__ + +#include <sys/types.h> +#include <net/uip/uipopt.h> + +/* The structure that holds the state of a buffer. + * + * This structure holds the state of a uIP buffer. The structure has + * no user-visible elements, but is used through the functions + * provided by the library. + * + */ + +struct psock_buf +{ + uint8 *ptr; + unsigned short left; +}; + +/* The representation of a protosocket. + * + * The protosocket structrure is an opaque structure with no user-visible + * elements. + */ + +struct psock +{ + const uint8 *sendptr; /* Pointer to the next data to be sent. */ + uint8 *readptr; /* Pointer to the next data to be read. */ + uint8 *bufptr; /* Pointer to the buffer used for buffering incoming data. */ + uint16 sendlen; /* The number of bytes left to be sent. */ + uint16 readlen; /* The number of bytes left to be read. */ + struct psock_buf buf; /* The structure holding the state of the input buffer. */ + unsigned int bufsize; /* The size of the input buffer. */ + unsigned char state; /* The state of the protosocket. */ +}; + +/* Initialize a protosocket. + * + * Initializes a protosocket and must be called before the + * protosocket is used. The initialization also specifies the input buffer + * for the protosocket. + * + * psock (struct psock *) A pointer to the protosocket to be + * initialized + * + * buffer (char *) A pointer to the input buffer for the + * protosocket. + * + * buffersize (unsigned int) The size of the input buffer. + */ + +extern void psock_init(struct psock *psock, char *buffer, unsigned int buffersize); + +/* Send data. + * + * This macro sends data over a protosocket. The protosocket protothread blocks + * until all data has been sent and is known to have been received by + * the remote end of the TCP connection. + * + * psock (struct psock *) A pointer to the protosocket over which + * data is to be sent. + * + * data (char *) A pointer to the data that is to be sent. + * + * datalen (unsigned int) The length of the data that is to be + * sent. + */ + +extern void psock_send(struct psock *psock, const char *buf, unsigned int len); + +/*Send a null-terminated string. + * + * psock Pointer to the protosocket. + * str The string to be sent. + * + * This function sends a null-terminated string over the + * protosocket. + */ + +#define PSOCK_SEND_STR(psock, str) psock_send(psock, str, strlen(str)) + +/* Generate data with a function and send it + * + * psock Pointer to the protosocket. + * generator Pointer to the generator function + * arg Argument to the generator function + * + * This function generates data and sends it over the + * protosocket. This can be used to dynamically generate + * data for a transmission, instead of generating the data + * in a buffer beforehand. This function reduces the need for + * buffer memory. The generator function is implemented by + * the application, and a pointer to the function is given + * as an argument with the call to PSOCK_GENERATOR_SEND(). + * + * The generator function should place the generated data + * directly in the uip_appdata buffer, and return the + * length of the generated data. The generator function is + * called by the protosocket layer when the data first is + * sent, and once for every retransmission that is needed. + */ + +extern void psock_generator_send(struct psock *psock, unsigned short (*f)(void *), void *arg); + +/* Close a protosocket. + * + * This macro closes a protosocket and can only be called from within the + * protothread in which the protosocket lives. + * + * psock (struct psock *) A pointer to the protosocket that is to + * be closed. + */ + +#define PSOCK_CLOSE(psock) uip_close() + +/* Read data until the buffer is full. + * + * This macro will block waiting for data and read the data into the + * input buffer specified with the call to PSOCK_INIT(). Data is read + * until the buffer is full.. + * + * psock (struct psock *) A pointer to the protosocket from which + * data should be read. + */ + +extern void psock_readbuf(struct psock *psock); + +/* Read data up to a specified character. + * + * This macro will block waiting for data and read the data into the + * input buffer specified with the call to PSOCK_INIT(). Data is only + * read until the specifieed character appears in the data stream. + * + * psock (struct psock *) A pointer to the protosocket from which + * data should be read. + * + * c (char) The character at which to stop reading. + */ + +extern void psock_readto(struct psock *psock, unsigned char c); + +/* The length of the data that was previously read. + * + * Returns the length of the data that was previously read + * using PSOCK_READTO() or PSOCK_READ(). + * + * psock (struct psock *) A pointer to the protosocket holding the data. + */ + +extern uint16 psock_datalen(struct psock *psock); + +/* Check if there is new data has arrived on a protosocket without blocking + * + * psock (struct psock *) A pointer to the protosocket. + */ + +extern boolean psock_checknewdata(struct psock *s); + +/* Block until new data has arrived on a protosocket. + * + * psock (struct psock *) A pointer to the protosocket. + */ + +extern void psock_waitnewdata(struct psock *s); + +#endif /* __PSOCK_H__ */ + +/** @} */ diff --git a/nuttx/include/net/uip/resolv.h b/nuttx/include/net/uip/resolv.h new file mode 100644 index 000000000..3411966ea --- /dev/null +++ b/nuttx/include/net/uip/resolv.h @@ -0,0 +1,60 @@ +/* resolv.h + * DNS resolver code header file. + * Authtor Adam Dunkels <adam@dunkels.com> + * + * Copyright (c) 2002-2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __UIP_RESOLV_H__ +#define __UIP_RESOLV_H__ + +#include <sys/types.h> +#include <net/uip/uipopt.h> + +/* Callback function which is called when a hostname is found. + * + * This function must be implemented by the module that uses the DNS + * resolver. It is called when a hostname is found, or when a hostname + * was not found. + * + * name A pointer to the name that was looked up. \param + * ipaddr A pointer to a 4-byte array containing the IP address of the + * hostname, or NULL if the hostname could not be found. + */ + +extern void resolv_found(char *name, uint16 *ipaddr); + +/* Functions. */ + +extern void resolv_conf(uint16 *dnsserver); +extern uint16 *resolv_getserver(void); +extern void resolv_init(void); +extern uint16 *resolv_lookup(char *name); +extern void resolv_query(char *name); + +#endif /* __UIP_RESOLV_H__ */ diff --git a/nuttx/include/net/uip/smtp.h b/nuttx/include/net/uip/smtp.h new file mode 100644 index 000000000..da2683f65 --- /dev/null +++ b/nuttx/include/net/uip/smtp.h @@ -0,0 +1,75 @@ +/* smtp.h + * SMTP header file + * Author: Adam Dunkels <adam@dunkels.com> + * + * Copyright (c) 2002, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __SMTP_H__ +#define __SMTP_H__ + +#include <sys/types.h> + +#include <net/uip/uipopt.h> + +/* Error number that signifies a non-error condition. */ + +#define SMTP_ERR_OK 0 + +/* Callback function that is called when an e-mail transmission is + * done. + * + * This function must be implemented by the module that uses the SMTP + * module. + * + * error The number of the error if an error occured, or + * SMTP_ERR_OK. + */ + +void smtp_done(unsigned char error); + +void smtp_init(void); +void smtp_configure(char *localhostname, uint16 *smtpserver); +unsigned char smtp_send(char *to, char *from, + char *subject, char *msg, + uint16 msglen); + +struct smtp_state +{ + uint8 state; + char *to; + char *from; + char *subject; + char *msg; + uint16 msglen; + + uint16 sentlen, textlen; + uint16 sendptr; +}; + +#endif /* __SMTP_H__ */ diff --git a/nuttx/include/net/uip/uip-arch.h b/nuttx/include/net/uip/uip-arch.h new file mode 100644 index 000000000..f49448da2 --- /dev/null +++ b/nuttx/include/net/uip/uip-arch.h @@ -0,0 +1,343 @@ +/**************************************************************************** + * uip-arch.h + * Defines architecture-specific device driver interfaces to uIP + * + * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Derived largely from portions of uIP with has a similar BSD-styple license: + * + * Copyright (c) 2001-2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __UIP_ARCH_H +#define __UIP_ARCH_H + +#include <sys/types.h> +#include <net/uip/uip.h> + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <net/uip/uipopt.h> + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/* The following flags are passed as an argument to the uip_interrupt() + * function. They are used to distinguish between the two cases where + * uip_interrupt() is called. It can be called either because we have + * 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 */ + +/* uIP device driver functions + * + * These functions are used by a network device driver for interacting + * with uIP. + * + * Process an incoming packet. + * + * This function should be called when the device driver has received + * a packet from the network. The packet from the device driver must + * be present in the uip_buf buffer, and the length of the packet + * should be placed in the uip_len variable. + * + * When the function returns, there may be an outbound packet placed + * in the uip_buf packet buffer. If so, the uip_len variable is set to + * the length of the packet. If no packet is to be sent out, the + * uip_len variable is set to 0. + * + * The usual way of calling the function is presented by the source + * code below. + * + * uip_len = devicedriver_poll(); + * if(uip_len > 0) { + * uip_input(); + * if(uip_len > 0) { + * devicedriver_send(); + * } + * } + * + * Note: If you are writing a uIP device driver that needs ARP + * (Address Resolution Protocol), e.g., when running uIP over + * Ethernet, you will need to call the uIP ARP code before calling + * this function: + * + * #define BUF ((struct uip_eth_hdr *)&uip_buf[0]) + * uip_len = ethernet_devicedrver_poll(); + * if(uip_len > 0) { + * if(BUF->type == HTONS(UIP_ETHTYPE_IP)) { + * uip_arp_ipin(); + * uip_input(); + * if(uip_len > 0) { + * uip_arp_out(); + * ethernet_devicedriver_send(); + * } + * } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) { + * uip_arp_arpin(); + * if(uip_len > 0) { + * ethernet_devicedriver_send(); + * } + * } + */ + +#define uip_input() uip_interrupt(UIP_DATA) + +/* Periodic processing for a connection identified by its number. + * + * This function does the necessary periodic processing (timers, + * polling) for a uIP TCP conneciton, and should be called when the + * periodic uIP timer goes off. It should be called for every + * connection, regardless of whether they are open of closed. + * + * When the function returns, it may have an outbound packet waiting + * for service in the uIP packet buffer, and if so the uip_len + * variable is set to a value larger than zero. The device driver + * should be called to send out the packet. + * + * The ususal way of calling the function is through a for() loop like + * this: + * + * for(i = 0; i < UIP_CONNS; ++i) { + * uip_periodic(i); + * if(uip_len > 0) { + * devicedriver_send(); + * } + * } + * + * Note: If you are writing a uIP device driver that needs ARP + * (Address Resolution Protocol), e.g., when running uIP over + * Ethernet, you will need to call the uip_arp_out() function before + * calling the device driver: + * + * for(i = 0; i < UIP_CONNS; ++i) { + * uip_periodic(i); + * if(uip_len > 0) { + * uip_arp_out(); + * ethernet_devicedriver_send(); + * } + * } + * + * conn The number of the connection which is to be periodically polled. + */ + +#define uip_periodic(conn) do { uip_conn = &uip_conns[conn]; \ + uip_interrupt(UIP_TIMER); } while (0) + +#define uip_conn_active(conn) (uip_conns[conn].tcpstateflags != UIP_CLOSED) + +/* Perform periodic processing for a connection identified by a pointer + * to its structure. + * + * Same as uip_periodic() but takes a pointer to the actual uip_conn + * struct instead of an integer as its argument. This function can be + * used to force periodic processing of a specific connection. + * + * conn A pointer to the uip_conn struct for the connection to + * be processed. + */ + +#define uip_periodic_conn(conn) do { uip_conn = conn; uip_interrupt(UIP_TIMER); } while (0) + +/* Request that a particular connection should be polled. + * + * Similar to uip_periodic_conn() but does not perform any timer + * processing. The application is polled for new data. + * + * conn A pointer to the uip_conn struct for the connection to + * be processed. + */ + +#define uip_poll_conn(conn) do { uip_conn = conn; uip_interrupt(UIP_POLL_REQUEST); } while (0) + + +#if UIP_UDP +/* Periodic processing for a UDP connection identified by its number. + * + * This function is essentially the same as uip_periodic(), but for + * UDP connections. It is called in a similar fashion as the + * uip_periodic() function: + * + * for(i = 0; i < UIP_UDP_CONNS; i++) { + * uip_udp_periodic(i); + * if(uip_len > 0) { + * devicedriver_send(); + * } + * } + * + * Note: As for the uip_periodic() function, special care has to be + * taken when using uIP together with ARP and Ethernet: + * + * for(i = 0; i < UIP_UDP_CONNS; i++) { + * uip_udp_periodic(i); + * if(uip_len > 0) { + * uip_arp_out(); + * ethernet_devicedriver_send(); + * } + * } + * + * conn The number of the UDP connection to be processed. + */ + +#define uip_udp_periodic(conn) do { uip_udp_conn = &uip_udp_conns[conn]; \ + uip_interrupt(UIP_UDP_TIMER); } while (0) + +/* Periodic processing for a UDP connection identified by a pointer to + * its structure. + * + * Same as uip_udp_periodic() but takes a pointer to the actual + * uip_conn struct instead of an integer as its argument. This + * function can be used to force periodic processing of a specific + * connection. + * + * conn A pointer to the uip_udp_conn struct for the connection + * to be processed. + */ + +#define uip_udp_periodic_conn(conn) do { uip_udp_conn = conn; \ + uip_interrupt(UIP_UDP_TIMER); } while (0) + + +#endif /* UIP_UDP */ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Variables + ****************************************************************************/ + +/**************************************************************************** + * Pulblic Function Prototypes + ****************************************************************************/ + +/* Architecure support + * + * uip_interrupt(flag): + * + * The actual uIP function which does all the work. Called from the + * interrupt level by a device driver. + */ + +extern void uip_interrupt(uint8 flag); + +/* By defining UIP_ARCH_CHKSUM, the architecture can replace the following + * functions with hardware assisted solutions. + */ + +/* Carry out a 32-bit addition. + * + * Because not all architectures for which uIP is intended has native + * 32-bit arithmetic, uIP uses an external C function for doing the + * required 32-bit additions in the TCP protocol processing. This + * function should add the two arguments and place the result in the + * global variable uip_acc32. + * + * Note: The 32-bit integer pointed to by the op32 parameter and the + * result in the uip_acc32 variable are in network byte order (big + * endian). + * + * op32 A pointer to a 4-byte array representing a 32-bit + * integer in network byte order (big endian). + * + * op16 A 16-bit integer in host byte order. + */ + +#if UIP_ARCH_ADD32 +extern void uip_add32(uint8 *op32, uint16 op16); +#endif + +/* Calculate the Internet checksum over a buffer. + * + * The Internet checksum is the one's complement of the one's + * complement sum of all 16-bit words in the buffer. + * + * See RFC1071. + * + * Note: This function is not called in the current version of uIP, + * but future versions might make use of it. + * + * buf A pointer to the buffer over which the checksum is to be + * computed. + * + * len The length of the buffer over which the checksum is to + * be computed. + * + * Return: The Internet checksum of the buffer. + */ + +extern uint16 uip_chksum(uint16 *buf, uint16 len); + +/* Calculate the IP header checksum of the packet header in uip_buf. + * + * The IP header checksum is the Internet checksum of the 20 bytes of + * the IP header. + * + * Return: The IP header checksum of the IP header in the uip_buf + * buffer. + */ + +extern uint16 uip_ipchksum(void); + +/* Calculate the TCP checksum of the packet in uip_buf and uip_appdata. + * + * The TCP checksum is the Internet checksum of data contents of the + * TCP segment, and a pseudo-header as defined in RFC793. + * + * Note: The uip_appdata pointer that points to the packet data may + * point anywhere in memory, so it is not possible to simply calculate + * the Internet checksum of the contents of the uip_buf buffer. + * + * Return: The TCP checksum of the TCP segment in uip_buf and pointed + * to by uip_appdata. + */ + +extern uint16 uip_tcpchksum(void); + +extern uint16 uip_udpchksum(void); + +#endif /* __UIP_ARCH_H */ diff --git a/nuttx/include/net/uip/uip-arp.h b/nuttx/include/net/uip/uip-arp.h new file mode 100644 index 000000000..2f5148e1a --- /dev/null +++ b/nuttx/include/net/uip/uip-arp.h @@ -0,0 +1,122 @@ +/* uip-arp.h + * Macros and definitions for the ARP module. + * Author: Adam Dunkels <adam@dunkels.com> + * + * Copyright (c) 2001-2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __UIP_ARP_H__ +#define __UIP_ARP_H__ + +#include <sys/types.h> +#include <net/uip/uip.h> + +extern struct uip_eth_addr uip_ethaddr; + +/* The Ethernet header */ + +struct uip_eth_hdr +{ + struct uip_eth_addr dest; + struct uip_eth_addr src; + uint16 type; +}; + +#define UIP_ETHTYPE_ARP 0x0806 +#define UIP_ETHTYPE_IP 0x0800 +#define UIP_ETHTYPE_IP6 0x86dd + +/* The uip_arp_init() function must be called before any of the other + * ARP functions. + */ + +void uip_arp_init(void); + +/* The uip_arp_ipin() function should be called whenever an IP packet + * arrives from the Ethernet. This function refreshes the ARP table or + * inserts a new mapping if none exists. The function assumes that an + * IP packet with an Ethernet header is present in the uip_buf buffer + * and that the length of the packet is in the uip_len variable. + */ + +/*void uip_arp_ipin(void);*/ +#define uip_arp_ipin() + +/* The uip_arp_arpin() should be called when an ARP packet is received + * by the Ethernet driver. This function also assumes that the + * Ethernet frame is present in the uip_buf buffer. When the + * uip_arp_arpin() function returns, the contents of the uip_buf + * buffer should be sent out on the Ethernet if the uip_len variable + * is > 0. + */ + +void uip_arp_arpin(void); + +/* The uip_arp_out() function should be called when an IP packet + * should be sent out on the Ethernet. This function creates an + * Ethernet header before the IP header in the uip_buf buffer. The + * Ethernet header will have the correct Ethernet MAC destination + * address filled in if an ARP table entry for the destination IP + * address (or the IP address of the default router) is present. If no + * such table entry is found, the IP packet is overwritten with an ARP + * request and we rely on TCP to retransmit the packet that was + * overwritten. In any case, the uip_len variable holds the length of + * the Ethernet frame that should be transmitted. + */ + +void uip_arp_out(void); + +/* The uip_arp_timer() function should be called every ten seconds. It + * is responsible for flushing old entries in the ARP table. + */ + +void uip_arp_timer(void); + +/* Specifiy the Ethernet MAC address. + * + * The ARP code needs to know the MAC address of the Ethernet card in + * order to be able to respond to ARP queries and to generate working + * Ethernet headers. + * + * Note: This macro only specifies the Ethernet MAC address to the ARP + * code. It cannot be used to change the MAC address of the Ethernet + * card. + * + * eaddr A pointer to a struct uip_eth_addr containing the + * Ethernet MAC address of the Ethernet card. + */ + +#define uip_setethaddr(eaddr) do {uip_ethaddr.addr[0] = eaddr.addr[0]; \ + uip_ethaddr.addr[1] = eaddr.addr[1];\ + uip_ethaddr.addr[2] = eaddr.addr[2];\ + uip_ethaddr.addr[3] = eaddr.addr[3];\ + uip_ethaddr.addr[4] = eaddr.addr[4];\ + uip_ethaddr.addr[5] = eaddr.addr[5];} while(0) + +#endif /* __UIP_ARP_H__ */ diff --git a/nuttx/include/net/uip/uip.h b/nuttx/include/net/uip/uip.h new file mode 100644 index 000000000..0185a8da0 --- /dev/null +++ b/nuttx/include/net/uip/uip.h @@ -0,0 +1,1172 @@ +/** + * uip.h + * Header file for the uIP TCP/IP stack. + * author Adam Dunkels <adam@dunkels.com> + * + * The uIP TCP/IP stack header file contains definitions for a number + * of C macros that are used by uIP programs as well as internal uIP + * structures, TCP/IP header structures and function declarations. + * + * Copyright (c) 2001-2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the uIP TCP/IP stack. + * + * $Id: uip.h,v 1.1.1.1 2007-08-26 23:12:16 patacongo Exp $ + * + ****************************************************************************/ + +#ifndef __UIP_H__ +#define __UIP_H__ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> +#include <nuttx/config.h> +#include <net/uip/uipopt.h> + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/* The following flags may be set in the global variable uip_flags before + * calling the application callback. The UIP_ACKDATA, UIP_NEWDATA, and + * UIP_CLOSE flags may both be set at the same time, whereas the others are + * mutualy exclusive. Note that these flags should *NOT* be accessed directly, + * but only through the uIP functions/macros. + */ + +#define UIP_ACKDATA (1 << 0) /* Signifies that the outstanding data was acked and the + * application should send out new data instead of retransmitting + * the last data. */ +#define UIP_NEWDATA (1 << 1) /* Flags the fact that the peer has sent us new data. */ +#define UIP_REXMIT (1 << 2) /* Tells the application to retransmit the data that was last + * sent. */ +#define UIP_POLL (1 << 3) /* Used for polling the application, to check if the application + * has data that it wants to send. */ +#define UIP_CLOSE (1 << 4) /* 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 (1 << 5) /* 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 (1 << 6) /* 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 (1 << 7) /* The connection has been aborted due to too many retransmissions. */ +#define UIP_APPTIMEOUT (1 << 8) /* Application time limit has elapsed */ + +/* 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 + +/* The buffer size available for user data in the \ref uip_buf buffer. + * + * This macro holds the available size for user data in the \ref + * uip_buf buffer. The macro is intended to be used for checking + * bounds of available user data. + * + * Example: + * + * snprintf(uip_appdata, UIP_APPDATA_SIZE, "%u\n", i); + */ + +#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. */ +#ifdef CONFIG_NET_UIP_IPv6 +# define UIP_IPH_LEN 40 +#else /* CONFIG_NET_UIP_IPv6 */ +# define UIP_IPH_LEN 20 /* Size of IP header */ +#endif /* CONFIG_NET_UIP_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 + +/**************************************************************************** + * Public Type Definitions + ****************************************************************************/ + +/* Repressentation of an IP address. */ + +typedef uint16 uip_ip4addr_t[2]; +typedef uint16 uip_ip6addr_t[8]; + +#ifdef CONFIG_NET_UIP_IPv6 +typedef uip_ip6addr_t uip_ipaddr_t; +#else /* CONFIG_NET_UIP_IPv6 */ +typedef uip_ip4addr_t uip_ipaddr_t; +#endif /* CONFIG_NET_UIP_IPv6 */ + +/* Representation of a uIP TCP connection. + * + * The uip_conn structure is used for identifying a connection. All + * but one field in the structure are to be considered read-only by an + * application. The only exception is the "private: field whos purpose + * is to let the application store application-specific state (e.g., + * file pointers) for the connection. + */ + +struct uip_conn +{ + uip_ipaddr_t ripaddr; /* The IP address of the remote host. */ + + uint16 lport; /* The local TCP port, in network byte order. */ + uint16 rport; /* The local remote TCP port, in network byte + order. */ + + uint8 rcv_nxt[4]; /* The sequence number that we expect to + receive next. */ + uint8 snd_nxt[4]; /* The sequence number that was last sent by + us. */ + uint16 len; /* Length of the data that was previously sent. */ + uint16 mss; /* Current maximum segment size for the + connection. */ + uint16 initialmss; /* Initial maximum segment size for the + connection. */ + uint8 sa; /* Retransmission time-out calculation state + variable. */ + uint8 sv; /* Retransmission time-out calculation state + variable. */ + uint8 rto; /* Retransmission time-out. */ + uint8 tcpstateflags; /* TCP state and flags. */ + uint8 timer; /* The retransmission timer. */ + uint8 nrtx; /* The number of retransmissions for the last + segment sent. */ + + /* Higher level logic can retain application specific information + * in the following: + */ + + void *private; +}; + +#if UIP_UDP +/* Representation of a uIP UDP connection. */ + +struct uip_udp_conn +{ + uip_ipaddr_t ripaddr; /* The IP address of the remote peer. */ + uint16 lport; /* The local port number in network byte order. */ + uint16 rport; /* The remote port number in network byte order. */ + uint8 ttl; /* Default time-to-live. */ + + /* Higher level logic can retain application specific information + * in the following: + */ + + void *private; +}; +#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 */ +}; + +/* The TCP and IP headers. */ + +struct uip_tcpip_hdr { +#ifdef CONFIG_NET_UIP_IPv6 + /* IPv6 header. */ + + uint8 vtc, + tcflow; + uint16 flow; + uint8 len[2]; + uint8 proto, ttl; + uip_ip6addr_t srcipaddr, destipaddr; +#else /* CONFIG_NET_UIP_IPv6 */ + /* IPv4 header. */ + + uint8 vhl, + tos, + len[2], + ipid[2], + ipoffset[2], + ttl, + proto; + uint16 ipchksum; + uint16 srcipaddr[2], + destipaddr[2]; +#endif /* CONFIG_NET_UIP_IPv6 */ + + /* TCP header. */ + + uint16 srcport, + destport; + uint8 seqno[4], + ackno[4], + tcpoffset, + flags, + wnd[2]; + uint16 tcpchksum; + uint8 urgp[2]; + uint8 optdata[4]; +}; + +/* The ICMP and IP headers. */ + +struct uip_icmpip_hdr { +#ifdef CONFIG_NET_UIP_IPv6 + /* IPv6 header. */ + + uint8 vtc, + tcf; + uint16 flow; + uint8 len[2]; + uint8 proto, ttl; + uip_ip6addr_t srcipaddr, destipaddr; +#else /* CONFIG_NET_UIP_IPv6 */ + /* IPv4 header. */ + + uint8 vhl, + tos, + len[2], + ipid[2], + ipoffset[2], + ttl, + proto; + uint16 ipchksum; + uint16 srcipaddr[2], + destipaddr[2]; +#endif /* CONFIG_NET_UIP_IPv6 */ + + /* ICMP (echo) header. */ + uint8 type, icode; + uint16 icmpchksum; +#ifndef CONFIG_NET_UIP_IPv6 + uint16 id, seqno; +#else /* !CONFIG_NET_UIP_IPv6 */ + uint8 flags, reserved1, reserved2, reserved3; + uint8 icmp6data[16]; + uint8 options[1]; +#endif /* !CONFIG_NET_UIP_IPv6 */ +}; + +/* The UDP and IP headers. */ + +struct uip_udpip_hdr { +#ifdef CONFIG_NET_UIP_IPv6 + /* IPv6 header. */ + + uint8 vtc, + tcf; + uint16 flow; + uint8 len[2]; + uint8 proto, ttl; + uip_ip6addr_t srcipaddr, destipaddr; +#else /* CONFIG_NET_UIP_IPv6 */ + /* IP header. */ + + uint8 vhl, + tos, + len[2], + ipid[2], + ipoffset[2], + ttl, + proto; + uint16 ipchksum; + uint16 srcipaddr[2], + destipaddr[2]; +#endif /* CONFIG_NET_UIP_IPv6 */ + + /* UDP header. */ + + uint16 srcport, + destport; + uint16 udplen; + uint16 udpchksum; +}; + +/* Representation of a 48-bit Ethernet address. */ + +struct uip_eth_addr { + uint8 addr[6]; +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* The uIP packet buffer. + * + * The uip_buf array is used to hold incoming and outgoing + * packets. The device driver should place incoming data into this + * buffer. When sending data, the device driver should read the link + * level headers and the TCP/IP headers from this buffer. The size of + * the link level headers is configured by the UIP_LLH_LEN define. + * + * Note: The application data need not be placed in this buffer, so + * the device driver must read it from the place pointed to by the + * uip_appdata pointer as illustrated by the following example: + * + * void + * devicedriver_send(void) + * { + * hwsend(&uip_buf[0], UIP_LLH_LEN); + * if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN) { + * hwsend(&uip_buf[UIP_LLH_LEN], uip_len - UIP_LLH_LEN); + * } else { + * hwsend(&uip_buf[UIP_LLH_LEN], UIP_TCPIP_HLEN); + * hwsend(uip_appdata, uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN); + * } + * } + */ + +extern uint8 uip_buf[UIP_BUFSIZE+2]; + +/* Pointer to the application data in the packet buffer. + * + * This pointer points to the application data when the application is + * 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; + +#if UIP_URGDATA > 0 +/* uint8 *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 */ + + +/* Variables used in uIP device drivers + * + * uIP has a few global variables that are used in device drivers for + * uIP. + * + * The length of the packet in the uip_buf buffer. + * + * The global variable uip_len holds the length of the packet in the + * uip_buf buffer. + * + * When the network device driver calls the uIP input function, + * uip_len should be set to the length of the packet in the uip_buf + * buffer. + * + * When sending packets, the device driver should use the contents of + * the uip_len variable to determine the length of the outgoing + * packet. + * + */ + +extern uint16 uip_len; + +#if UIP_URGDATA > 0 +extern uint16 uip_urglen, uip_surglen; +#endif /* UIP_URGDATA > 0 */ + +/* 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; + +/* The array containing all uIP connections. */ +extern struct uip_conn uip_conns[UIP_CONNS]; + +/* 4-byte array used for the 32-bit sequence number calculations.*/ + +extern uint8 uip_acc32[4]; + +/* The current UDP connection. */ + +#if 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 uIP TCP/IP statistics. + * + * This is the variable in which the uIP TCP/IP statistics are gathered. + */ + +extern struct uip_stats uip_stat; + +/* uint16 uip_flags: + * + * When the application is called, uip_flags will contain the flags + * that are defined in this file. Please read below for more + * infomation. + */ + +extern uint16 uip_flags; + +#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 */ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/* uIP configuration functions + * + * The uIP configuration functions are used for setting run-time + * parameters in uIP such as IP addresses. + * + * Set the IP address of this host. + * + * The IP address is represented as a 4-byte array where the first + * octet of the IP address is put in the first member of the 4-byte + * array. + * + * Example: + * + * uip_ipaddr_t addr; + * + * uip_ipaddr(&addr, 192,168,1,2); + * uip_sethostaddr(&addr); + * + * addr A pointer to an IP address of type uip_ipaddr_t; + */ + +#define uip_sethostaddr(addr) uip_ipaddr_copy(uip_hostaddr, (addr)) + +/* Get the IP address of this host. + * + * The IP address is represented as a 4-byte array where the first + * octet of the IP address is put in the first member of the 4-byte + * array. + * + * Example: + * + * uip_ipaddr_t hostaddr; + * + * uip_gethostaddr(&hostaddr); + * + * addr A pointer to a uip_ipaddr_t variable that will be + * filled in with the currently configured IP address. + */ + +#define uip_gethostaddr(addr) uip_ipaddr_copy((addr), uip_hostaddr) + +/* Set the default router's IP address. + * + * addr A pointer to a uip_ipaddr_t variable containing the IP + * address of the default router. + */ + +#define uip_setdraddr(addr) uip_ipaddr_copy(uip_draddr, (addr)) + +/* Set the netmask. + * + * addr A pointer to a uip_ipaddr_t variable containing the IP + * address of the netmask. + */ + +#define uip_setnetmask(addr) uip_ipaddr_copy(uip_netmask, (addr)) + +/* Get the default router's IP address. + * + * addr A pointer to a uip_ipaddr_t variable that will be + * filled in with the IP address of the default router. + */ + +#define uip_getdraddr(addr) uip_ipaddr_copy((addr), uip_draddr) + +/* Get the netmask. + * + * addr A pointer to a uip_ipaddr_t variable that will be + * filled in with the value of the netmask. + */ + +#define uip_getnetmask(addr) uip_ipaddr_copy((addr), uip_netmask) + +/* uIP initialization functions + * + * The uIP initialization functions are used for booting uIP. + * + * This function should be called at boot up to initilize the uIP + * TCP/IP stack. + */ + +void uip_init(void); + +/* This function may be used at boot time to set the initial ip_id.*/ + +void uip_setipid(uint16 id); + +/* uIP application functions + * + * Functions used by an application running of top of uIP. This includes + * functions for opening and closing connections, sending and receiving + * data, etc. + * + * The following function must be provided by the application logic. It + * is called from the UIP interrupt handler when interesting events are + * detected that may be of interest to the application. + */ + +void uip_interrupt_event(void); +#if UIP_UDP +void uip_interrupt_udp_event(void); +#endif + +/* Start listening to the specified port. + * + * Note: Since this function expects the port number in network byte + * order, a conversion using HTONS() or htons() is necessary. + * + * port A 16-bit port number in network byte order. + */ + +void uip_listen(uint16 port); + +/* Stop listening to the specified port. + * + * Note: Since this function expects the port number in network byte + * order, a conversion using HTONS() or htons() is necessary. + * + * port A 16-bit port number in network byte order. + */ + +void uip_unlisten(uint16 port); + +/* Connect to a remote host using TCP. + * + * This function is used to start a new connection to the specified + * port on the specied host. It allocates a new connection identifier, + * sets the connection to the SYN_SENT state and sets the + * retransmission timer to 0. This will cause a TCP SYN segment to be + * sent out the next time this connection is periodically processed, + * which usually is done within 0.5 seconds after the call to + * uip_connect(). + * + * Note: This function is avaliable only if support for active open + * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h. + * + * Note: Since this function requires the port number to be in network + * byte order, a conversion using HTONS() or htons() is necessary. + * + * Example: + * + * uip_ipaddr_t ipaddr; + * + * uip_ipaddr(&ipaddr, 192,168,1,2); + * uip_connect(&ipaddr, HTONS(80)); + * + * ripaddr The IP address of the remote hot. + * + * port A 16-bit port number in network byte order. + * + * Return: A pointer to the uIP connection identifier for the new connection, + * or NULL if no connection could be allocated. + */ + +struct uip_conn *uip_connect(uip_ipaddr_t *ripaddr, uint16 port); + + +/* Check if a connection has outstanding (i.e., unacknowledged) data. + * + * conn A pointer to the uip_conn structure for the connection. + */ + +#define uip_outstanding(conn) ((conn)->len) + +/* Send data on the current connection. + * + * This function is used to send out a single segment of TCP + * data. Only applications that have been invoked by uIP for event + * processing can send data. + * + * The amount of data that actually is sent out after a call to this + * funcion is determined by the maximum amount of data TCP allows. uIP + * will automatically crop the data so that only the appropriate + * amount of data is sent. The function uip_mss() can be used to query + * uIP for the amount of data that actually will be sent. + * + * Note: This function does not guarantee that the sent data will + * arrive at the destination. If the data is lost in the network, the + * application will be invoked with the uip_rexmit() event being + * set. The application will then have to resend the data using this + * function. + * + * data A pointer to the data which is to be sent. + * + * len The maximum amount of data bytes to be sent. + */ + +void uip_send(const void *data, int len); + +/* The length of any incoming data that is currently avaliable (if avaliable) + * in the uip_appdata buffer. + * + * The test function uip_data() must first be used to check if there + * is any data available at all. + */ + +#define uip_datalen() uip_len + +/* The length of any out-of-band data (urgent data) that has arrived + * on the connection. + * + * Note: The configuration parameter UIP_URGDATA must be set for this + * function to be enabled. + */ + +#define uip_urgdatalen() uip_urglen + +/* Close the current connection. + * + * This function will close the current connection in a nice way. + */ + +#define uip_close() (uip_flags = UIP_CLOSE) + +/* Abort the current connection. + * + * This function will abort (reset) the current connection, and is + * usually used when an error has occured that prevents using the + * uip_close() function. + */ + +#define uip_abort() (uip_flags = UIP_ABORT) + +/* Tell the sending host to stop sending data. + * + * This function will close our receiver's window so that we stop + * receiving data for the current connection. + */ + +#define uip_stop() (uip_conn->tcpstateflags |= UIP_STOPPED) + +/* Find out if the current connection has been previously stopped with + * uip_stop(). + */ + +#define uip_stopped(conn) ((conn)->tcpstateflags & UIP_STOPPED) + +/* Restart the current connection, if is has previously been stopped + * with uip_stop(). + * + * This function will open the receiver's window again so that we + * start receiving data for the current connection. + */ + +#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 + * connection is, and what the application function should do. + * + * Is the current connection a UDP connection? + * + * This function checks whether the current connection is a UDP connection. + */ + +#define uip_udpconnection() (uip_conn == NULL) + +/* Is new incoming data available? + * + * Will reduce to non-zero if there is new data for the application + * present at the uip_appdata pointer. The size of the data is + * avaliable through the uip_len variable. + */ + +#define uip_newdata() (uip_flags & UIP_NEWDATA) + +/* Has previously sent data been acknowledged? + * + * Will reduce to non-zero if the previously sent data has been + * acknowledged by the remote host. This means that the application + * can send new data. + */ + +#define uip_acked() (uip_flags & UIP_ACKDATA) + +/* Has the connection just been connected? + * + * Reduces to non-zero if the current connection has been connected to + * a remote host. This will happen both if the connection has been + * actively opened (with uip_connect()) or passively opened (with + * uip_listen()). + */ + +#define uip_connected() (uip_flags & UIP_CONNECTED) + +/* Has the connection been closed by the other end? + * + * Is non-zero if the connection has been closed by the remote + * host. The application may then do the necessary clean-ups. + */ + +#define uip_closed() (uip_flags & UIP_CLOSE) + +/* Has the connection been aborted by the other end? + * + * Non-zero if the current connection has been aborted (reset) by the + * remote host. + */ + +#define uip_aborted() (uip_flags & UIP_ABORT) + +/* Has the connection timed out? + * + * Non-zero if the current connection has been aborted due to too many + * retransmissions. + */ + +#define uip_timedout() (uip_flags & UIP_TIMEDOUT) + +/* Do we need to retransmit previously data? + * + * Reduces to non-zero if the previously sent data has been lost in + * the network, and the application should retransmit it. The + * application should send the exact same data as it did the last + * time, using the uip_send() function. + */ + +#define uip_rexmit() (uip_flags & UIP_REXMIT) + +/* Is the connection being polled by uIP? + * + * Is non-zero if the reason the application is invoked is that the + * current connection has been idle for a while and should be + * polled. + * + * The polling event can be used for sending data without having to + * wait for the remote host to send data. + */ + +#define uip_poll() (uip_flags & UIP_POLL) + +/* Get the initial maxium segment size (MSS) of the current + * connection. + */ + +#define uip_initialmss() (uip_conn->initialmss) + +/* Get the current maxium segment size that can be sent on the current + * connection. + * + * The current maxiumum segment size that can be sent on the + * connection is computed from the receiver's window and the MSS of + * the connection (which also is available by calling + * uip_initialmss()). + */ + +#define uip_mss() (uip_conn->mss) + +/* Set up a new UDP connection. + * + * This function sets up a new UDP connection. The function will + * automatically allocate an unused local port for the new + * connection. However, another port can be chosen by using the + * uip_udp_bind() call, after the uip_udp_new() function has been + * called. + * + * Example: + * + * 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) { + * uip_udp_bind(c, HTONS(12344)); + * } + * + * ripaddr The IP address of the remote host. + * + * rport The remote port number in network byte order. + * + * 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, uint16 rport); + +/* Removed a UDP connection. + * + * conn A pointer to the uip_udp_conn structure for the connection. + */ + +#define uip_udp_remove(conn) (conn)->lport = 0 + +/* Bind a UDP connection to a local port. + * + * conn A pointer to the uip_udp_conn structure for the + * connection. + * + * port The local port number, in network byte order. + */ + +#define uip_udp_bind(conn, port) (conn)->lport = port + +/* Send a UDP datagram of length len on the current connection. + * + * This function can only be called in response to a UDP event (poll + * or newdata). The data must be present in the uip_buf buffer, at the + * place pointed to by the uip_appdata pointer. + * + * len The length of the data in the uip_buf buffer. + */ + +#define uip_udp_send(len) uip_send((char *)uip_appdata, len) + +/* uIP convenience and converting functions. + * + * These functions can be used for converting between different data + * formats used by uIP. + * + * Construct an IP address from four bytes. + * + * This function constructs an IP address of the type that uIP handles + * internally from four bytes. The function is handy for specifying IP + * addresses to use with e.g. the uip_connect() function. + * + * Example: + * + * uip_ipaddr_t ipaddr; + * struct uip_conn *c; + * + * uip_ipaddr(&ipaddr, 192,168,1,2); + * c = uip_connect(&ipaddr, HTONS(80)); + * + * addr A pointer to a uip_ipaddr_t variable that will be + * filled in with the IP address. + * + * addr0 The first octet of the IP address. + * addr1 The second octet of the IP address. + * addr2 The third octet of the IP address. + * addr3 The forth octet of the IP address. + */ + +#define uip_ipaddr(addr, addr0,addr1,addr2,addr3) do { \ + ((uint16 *)(addr))[0] = HTONS(((addr0) << 8) | (addr1)); \ + ((uint16 *)(addr))[1] = HTONS(((addr2) << 8) | (addr3)); \ + } while(0) + +/* Construct an IPv6 address from eight 16-bit words. + * + * This function constructs an IPv6 address. + */ + +#define uip_ip6addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) do { \ + ((uint16 *)(addr))[0] = HTONS((addr0)); \ + ((uint16 *)(addr))[1] = HTONS((addr1)); \ + ((uint16 *)(addr))[2] = HTONS((addr2)); \ + ((uint16 *)(addr))[3] = HTONS((addr3)); \ + ((uint16 *)(addr))[4] = HTONS((addr4)); \ + ((uint16 *)(addr))[5] = HTONS((addr5)); \ + ((uint16 *)(addr))[6] = HTONS((addr6)); \ + ((uint16 *)(addr))[7] = HTONS((addr7)); \ + } while(0) + +/* Copy an IP address to another IP address. + * + * Copies an IP address from one place to another. + * + * Example: + * + * uip_ipaddr_t ipaddr1, ipaddr2; + * + * uip_ipaddr(&ipaddr1, 192,16,1,2); + * uip_ipaddr_copy(&ipaddr2, &ipaddr1); + * + * dest The destination for the copy. + * src The source from where to copy. + */ + +#ifndef CONFIG_NET_UIP_IPv6 +#define uip_ipaddr_copy(dest, src) do { \ + ((uint16 *)dest)[0] = ((uint16 *)src)[0]; \ + ((uint16 *)dest)[1] = ((uint16 *)src)[1]; \ + } while(0) +#else /* !CONFIG_NET_UIP_IPv6 */ +#define uip_ipaddr_copy(dest, src) memcpy(dest, src, sizeof(uip_ip6addr_t)) +#endif /* !CONFIG_NET_UIP_IPv6 */ + +/* Compare two IP addresses + * + * Example: + * + * uip_ipaddr_t ipaddr1, ipaddr2; + * + * uip_ipaddr(&ipaddr1, 192,16,1,2); + * if(uip_ipaddr_cmp(&ipaddr2, &ipaddr1)) { + * printf("They are the same"); + * } + * + * addr1 The first IP address. + * addr2 The second IP address. + */ + +#ifndef CONFIG_NET_UIP_IPv6 +#define uip_ipaddr_cmp(addr1, addr2) (((uint16 *)addr1)[0] == ((uint16 *)addr2)[0] && \ + ((uint16 *)addr1)[1] == ((uint16 *)addr2)[1]) +#else /* !CONFIG_NET_UIP_IPv6 */ +#define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0) +#endif /* !CONFIG_NET_UIP_IPv6 */ + +/** + * Compare two IP addresses with netmasks + * + * Compares two IP addresses with netmasks. The masks are used to mask + * out the bits that are to be compared. + * + * Example: + * + * uip_ipaddr_t ipaddr1, ipaddr2, mask; + * + * uip_ipaddr(&mask, 255,255,255,0); + * uip_ipaddr(&ipaddr1, 192,16,1,2); + * uip_ipaddr(&ipaddr2, 192,16,1,3); + * if(uip_ipaddr_maskcmp(&ipaddr1, &ipaddr2, &mask)) { + * printf("They are the same"); + * } + * + * addr1 The first IP address. + * addr2 The second IP address. + * mask The netmask. + */ + +#define uip_ipaddr_maskcmp(addr1, addr2, mask) \ + (((((uint16 *)addr1)[0] & ((uint16 *)mask)[0]) == \ + (((uint16 *)addr2)[0] & ((uint16 *)mask)[0])) && \ + ((((uint16 *)addr1)[1] & ((uint16 *)mask)[1]) == \ + (((uint16 *)addr2)[1] & ((uint16 *)mask)[1]))) + + +/** + * Mask out the network part of an IP address. + * + * Masks out the network part of an IP address, given the address and + * the netmask. + * + * Example: + * + * uip_ipaddr_t ipaddr1, ipaddr2, netmask; + * + * uip_ipaddr(&ipaddr1, 192,16,1,2); + * uip_ipaddr(&netmask, 255,255,255,0); + * uip_ipaddr_mask(&ipaddr2, &ipaddr1, &netmask); + * + * In the example above, the variable "ipaddr2" will contain the IP + * address 192.168.1.0. + * + * dest Where the result is to be placed. + * src The IP address. + * mask The netmask. + */ + +#define uip_ipaddr_mask(dest, src, mask) do { \ + ((uint16 *)dest)[0] = ((uint16 *)src)[0] & ((uint16 *)mask)[0]; \ + ((uint16 *)dest)[1] = ((uint16 *)src)[1] & ((uint16 *)mask)[1]; \ + } while(0) + +/* Pick the first octet of an IP address. + * + * Picks out the first octet of an IP address. + * + * Example: + * + * uip_ipaddr_t ipaddr; + * uint8 octet; + * + * uip_ipaddr(&ipaddr, 1,2,3,4); + * octet = uip_ipaddr1(&ipaddr); + * + * In the example above, the variable "octet" will contain the value 1. + */ + +#define uip_ipaddr1(addr) (htons(((uint16 *)(addr))[0]) >> 8) + +/* Pick the second octet of an IP address. + * + * Picks out the second octet of an IP address. + * + * Example: + * + * uip_ipaddr_t ipaddr; + * uint8 octet; + * + * uip_ipaddr(&ipaddr, 1,2,3,4); + * octet = uip_ipaddr2(&ipaddr); + * + * In the example above, the variable "octet" will contain the value 2. + */ + +#define uip_ipaddr2(addr) (htons(((uint16 *)(addr))[0]) & 0xff) + +/* Pick the third octet of an IP address. + * + * Picks out the third octet of an IP address. + * + * Example: + * + * uip_ipaddr_t ipaddr; + * uint8 octet; + * + * uip_ipaddr(&ipaddr, 1,2,3,4); + * octet = uip_ipaddr3(&ipaddr); + * + * In the example above, the variable "octet" will contain the value 3. + */ + +#define uip_ipaddr3(addr) (htons(((uint16 *)(addr))[1]) >> 8) + +/* Pick the fourth octet of an IP address. + * + * Picks out the fourth octet of an IP address. + * + * Example: + * + * uip_ipaddr_t ipaddr; + * uint8 octet; + * + * uip_ipaddr(&ipaddr, 1,2,3,4); + * octet = uip_ipaddr4(&ipaddr); + * + * In the example above, the variable "octet" will contain the value 4. + */ + +#define uip_ipaddr4(addr) (htons(((uint16 *)(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 + * byte order to network byte order. For converting variables to + * network byte order, use the htons() function instead. + */ + +#ifndef HTONS +# if UIP_BYTE_ORDER == UIP_BIG_ENDIAN +# define HTONS(n) (n) +# else /* UIP_BYTE_ORDER == UIP_BIG_ENDIAN */ +# define HTONS(n) (uint16)((((uint16) (n)) << 8) | (((uint16) (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 +uint16 htons(uint16 val); +#endif /* htons */ +#ifndef ntohs +#define ntohs htons +#endif + +/* This function is called user code to set up the wait */ + +#define uip_event_wait(waitflags) uip_event_timedwait(waitflags,0) +extern int uip_event_timedwait(uint16 waitflags, int timeout); + +/* This function is called from uip_interrupt() to wake up any + * waiting threads/tasks. + */ + +extern void uip_event_signal(void); + +#endif /* __UIP_H__ */ diff --git a/nuttx/include/net/uip/uipopt.h b/nuttx/include/net/uip/uipopt.h new file mode 100644 index 000000000..1e468f6d8 --- /dev/null +++ b/nuttx/include/net/uip/uipopt.h @@ -0,0 +1,423 @@ +/**************************************************************************** + * uipopt.h + * Configuration options for uIP. + * author Adam Dunkels <adam@dunkels.com> + * + * This file is used for tweaking various configuration options for + * uIP. You should make a copy of this file into one of your project's + * directories instead of editing this example "uipopt.h" file that + * comes with the uIP distribution. + * + * uIP is configured using the per-project configuration file + * uipopt.h. This file contains all compile-time options for uIP and + * should be tweaked to match each specific project. The uIP + * distribution contains a documented example "uipopt.h" that can be + * copied and modified for each project. + * + * Note: Most of the configuration options in the uipopt.h should not + * be changed, but rather the per-project defconfig file. + * + * Copyright (c) 2001-2003, Adam Dunkels. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This file is part of the uIP TCP/IP stack. + * + * $Id: uipopt.h,v 1.1.1.1 2007-08-26 23:12:17 patacongo Exp $ + * + */ + +#ifndef __UIPOPT_H__ +#define __UIPOPT_H__ + +#include <sys/types.h> +#include <nuttx/config.h> + +/*------------------------------------------------------------------------------*/ + +/** + * \name Static configuration options + * + * These configuration options can be used for setting the IP address + * settings statically, but only if UIP_FIXEDADDR is set to 1. The + * configuration options for a specific node includes IP address, + * netmask and default router as well as the Ethernet address. The + * netmask, default router and Ethernet address are appliciable only + * if uIP should be run over Ethernet. + * + * All of these should be changed to suit your project. +*/ + +/** + * Statistics datatype + * + * This typedef defines the dataype used for keeping statistics in + * uIP. + */ +typedef uint16 uip_stats_t; + +/** + * Determines if uIP should use a fixed IP address or not. + * + * If uIP should use a fixed IP address, the settings are set in the + * uipopt.h file. If not, the macros uip_sethostaddr(), + * uip_setdraddr() and uip_setnetmask() should be used instead. + */ +#define UIP_FIXEDADDR 0 + +/** + * Ping IP address asignment. + * + * uIP uses a "ping" packets for setting its own IP address if this + * option is set. If so, uIP will start with an empty IP address and + * the destination IP address of the first incoming "ping" (ICMP echo) + * packet will be used for setting the hosts IP address. + * + * \note This works only if UIP_FIXEDADDR is 0. + */ + +#ifdef CONFIG_UIP_PINGADDRCONF +#define UIP_PINGADDRCONF CONFIG_UIP_PINGADDRCONF +#else /* CONFIG_UIP_PINGADDRCONF */ +#define UIP_PINGADDRCONF 0 +#endif /* CONFIG_UIP_PINGADDRCONF */ + +/** + * Specifies if the uIP ARP module should be compiled with a fixed + * Ethernet MAC address or not. + * + * If this configuration option is 0, the macro uip_setethaddr() can + * be used to specify the Ethernet address at run-time. + */ +#define UIP_FIXEDETHADDR 0 + +/*------------------------------------------------------------------------------*/ +/** + * \name IP configuration options + */ +/** + * The IP TTL (time to live) of IP packets sent by uIP. + * + * This should normally not be changed. + */ +#define UIP_TTL 64 + +/** + * Turn on support for IP packet reassembly. + * + * uIP supports reassembly of fragmented IP packets. This features + * requires an additonal amount of RAM to hold the reassembly buffer + * and the reassembly code size is approximately 700 bytes. The + * reassembly buffer is of the same size as the uip_buf buffer + * (configured by UIP_BUFSIZE). + * + * \note IP packet reassembly is not heavily tested. + */ +#define UIP_REASSEMBLY 0 + +/** + * The maximum time an IP fragment should wait in the reassembly + * buffer before it is dropped. + * + */ +#define UIP_REASS_MAXAGE 40 + +/*------------------------------------------------------------------------------*/ +/** + * \name UDP configuration options + */ + +/** + * Toggles wether UDP support should be compiled in or not. + */ +#ifdef CONFIG_UIP_UDP +# define UIP_UDP CONFIG_UIP_UDP +#else /* CONFIG_UIP_UDP */ +# define UIP_UDP 0 +#endif /* CONFIG_UIP_UDP */ + +/** + * Toggles if UDP checksums should be used or not. + * + * \note Support for UDP checksums is currently not included in uIP, + * so this option has no function. + */ +#ifdef CONFIG_UIP_UDP_CHECKSUMS +# define UIP_UDP_CHECKSUMS CONFIG_UIP_UDP_CHECKSUMS +#else +# define UIP_UDP_CHECKSUMS 0 +#endif + +/** + * The maximum amount of concurrent UDP connections. + */ +#ifdef CONFIG_UIP_UDP_CONNS +# define UIP_UDP_CONNS CONFIG_UIP_UDP_CONNS +#else /* CONFIG_UIP_UDP_CONNS */ +# define UIP_UDP_CONNS 10 +#endif /* CONFIG_UIP_UDP_CONNS */ + +/** + * The name of the function that should be called when UDP datagrams arrive. + */ + + +/*------------------------------------------------------------------------------*/ +/** + * \name TCP configuration options + */ + +/** + * Determines if support for opening connections from uIP should be + * compiled in. + * + * If the applications that are running on top of uIP for this project + * do not need to open outgoing TCP connections, this configration + * option can be turned off to reduce the code size of uIP. + */ +#define UIP_ACTIVE_OPEN 1 + +/** + * The maximum number of simultaneously open TCP connections. + * + * Since the TCP connections are statically allocated, turning this + * configuration knob down results in less RAM used. Each TCP + * connection requires approximatly 30 bytes of memory. + */ +#ifndef CONFIG_UIP_MAX_CONNECTIONS +# define UIP_CONNS 10 +#else /* CONFIG_UIP_MAX_CONNECTIONS */ +# define UIP_CONNS CONFIG_UIP_MAX_CONNECTIONS +#endif /* CONFIG_UIP_MAX_CONNECTIONS */ + +/** + * The maximum number of simultaneously listening TCP ports. + * + * Each listening TCP port requires 2 bytes of memory. + */ +#ifndef CONFIG_UIP_MAX_LISTENPORTS +# define UIP_LISTENPORTS 20 +#else /* CONFIG_UIP_MAX_LISTENPORTS */ +# define UIP_LISTENPORTS CONFIG_UIP_MAX_LISTENPORTS +#endif /* CONFIG_UIP_MAX_LISTENPORTS */ + +/** + * Determines if support for TCP urgent data notification should be + * compiled in. + * + * Urgent data (out-of-band data) is a rarely used TCP feature that + * very seldom would be required. + */ +#define UIP_URGDATA 0 + +/** + * The initial retransmission timeout counted in timer pulses. + * + * This should not be changed. + */ +#define UIP_RTO 3 + +/** + * The maximum number of times a segment should be retransmitted + * before the connection should be aborted. + * + * This should not be changed. + */ +#define UIP_MAXRTX 8 + +/** + * The maximum number of times a SYN segment should be retransmitted + * before a connection request should be deemed to have been + * unsuccessful. + * + * This should not need to be changed. + */ +#define UIP_MAXSYNRTX 5 + +/** + * The TCP maximum segment size. + * + * This is should not be to set to more than + * UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN. + */ +#define UIP_TCP_MSS (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) + +/** + * The size of the advertised receiver's window. + * + * Should be set low (i.e., to the size of the uip_buf buffer) is the + * application is slow to process incoming data, or high (32768 bytes) + * if the application processes data quickly. + */ +#ifndef CONFIG_UIP_RECEIVE_WINDOW +# define UIP_RECEIVE_WINDOW UIP_TCP_MSS +#else +# define UIP_RECEIVE_WINDOW CONFIG_UIP_RECEIVE_WINDOW +#endif + +/** + * How long a connection should stay in the TIME_WAIT state. + * + * This configiration option has no real implication, and it should be + * left untouched. + */ +#define UIP_TIME_WAIT_TIMEOUT 120 + + +/*------------------------------------------------------------------------------*/ +/** + * \name ARP configuration options + */ + +/** + * The size of the ARP table. + * + * This option should be set to a larger value if this uIP node will + * have many connections from the local network. + */ +#ifdef CONFIG_UIP_ARPTAB_SIZE +# define UIP_ARPTAB_SIZE CONFIG_UIP_ARPTAB_SIZE +#else +# define UIP_ARPTAB_SIZE 8 +#endif + +/** + * The maxium age of ARP table entries measured in 10ths of seconds. + * + * An UIP_ARP_MAXAGE of 120 corresponds to 20 minutes (BSD + * default). + */ +#define UIP_ARP_MAXAGE 120 + +/*------------------------------------------------------------------------------*/ + +/** + * \name General configuration options + */ + +/** + * The size of the uIP packet buffer. + * + * The uIP packet buffer should not be smaller than 60 bytes, and does + * not need to be larger than 1500 bytes. Lower size results in lower + * TCP throughput, larger size results in higher TCP throughput. + */ +#ifndef CONFIG_UIP_BUFFER_SIZE +# define UIP_BUFSIZE 400 +#else /* CONFIG_UIP_BUFFER_SIZE */ +# define UIP_BUFSIZE CONFIG_UIP_BUFFER_SIZE +#endif /* CONFIG_UIP_BUFFER_SIZE */ + + +/** + * Determines if statistics support should be compiled in. + * + * The statistics is useful for debugging and to show the user. + */ + +#ifndef CONFIG_UIP_STATISTICS +# define UIP_STATISTICS 0 +#else /* CONFIG_UIP_STATISTICS */ +# define UIP_STATISTICS CONFIG_UIP_STATISTICS +#endif /* CONFIG_UIP_STATISTICS */ + +/** + * Determines if logging of certain events should be compiled in. + * + * This is useful mostly for debugging. The function uip_log() + * must be implemented to suit the architecture of the project, if + * logging is turned on. + */ + +#ifndef CONFIG_UIP_LOGGING +# define UIP_LOGGING 0 +#else /* CONFIG_UIP_LOGGING */ +# define UIP_LOGGING CONFIG_UIP_LOGGING +#endif /* CONFIG_UIP_LOGGING */ + +/** + * Broadcast support. + * + * This flag configures IP broadcast support. This is useful only + * together with UDP. + */ + +#ifndef CONFIG_UIP_BROADCAST +# define UIP_BROADCAST 0 +#else /* CONFIG_UIP_BROADCAST */ +# define UIP_BROADCAST CONFIG_UIP_BROADCAST +#endif /* CONFIG_UIP_BROADCAST */ + +/** + * Print out a uIP log message. + * + * This function must be implemented by the module that uses uIP, and + * is called by uIP whenever a log message is generated. + */ +void uip_log(char *msg); + +/** + * The link level header length. + * + * This is the offset into the uip_buf where the IP header can be + * found. For Ethernet, this should be set to 14. For SLIP, this + * should be set to 0. + */ + +#ifdef CONFIG_UIP_LLH_LEN +# define UIP_LLH_LEN CONFIG_UIP_LLH_LEN +#else /* CONFIG_UIP_LLH_LEN */ +# define UIP_LLH_LEN 14 +#endif /* CONFIG_UIP_LLH_LEN */ + +/*------------------------------------------------------------------------------*/ +/** + * \name CPU architecture configuration + * + * The CPU architecture configuration is where the endianess of the + * CPU on which uIP is to be run is specified. Most CPUs today are + * little endian, and the most notable exception are the Motorolas + * which are big endian. The CONFIG_ENDIAN_BIG macro should be changed + * if uIP is to be run on a big endian architecture. + */ + +/** + * The byte order of the CPU architecture on which uIP is to be run. + * + * This option can be either CONFIG_ENDIAN_BIG (Motorola byte order) or + * default little endian byte order (Intel byte order). + */ + +#define UIP_BIG_ENDIAN 1234 +#define UIP_LITTLE_ENDIAN 3412 + +#ifdef CONFIG_ENDIAN_BIG +# define UIP_BYTE_ORDER UIP_BIG_ENDIAN +#else +# define UIP_BYTE_ORDER UIP_LITTLE_ENDIAN +#endif + +#endif /* __UIPOPT_H__ */ |