aboutsummaryrefslogtreecommitdiff
path: root/apps/include
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-09-17 18:18:44 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-09-17 18:18:44 +0000
commit57623d42ebb04f0a0b9e6eb7c0847a3ece2aa0ff (patch)
tree25d07d14e920d31c0b1947c9ca586f2a01fc32d8 /apps/include
downloadpx4-firmware-57623d42ebb04f0a0b9e6eb7c0847a3ece2aa0ff.tar.gz
px4-firmware-57623d42ebb04f0a0b9e6eb7c0847a3ece2aa0ff.tar.bz2
px4-firmware-57623d42ebb04f0a0b9e6eb7c0847a3ece2aa0ff.zip
Resync new repository with old repo r5166
git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5153 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/include')
-rw-r--r--apps/include/apps.h149
-rw-r--r--apps/include/ftpc.h225
-rw-r--r--apps/include/modbus/mb.h418
-rw-r--r--apps/include/modbus/mbframe.h87
-rw-r--r--apps/include/modbus/mbfunc.h80
-rw-r--r--apps/include/modbus/mbport.h132
-rw-r--r--apps/include/modbus/mbproto.h83
-rw-r--r--apps/include/modbus/mbutils.h108
-rw-r--r--apps/include/netutils/dhcpc.h85
-rw-r--r--apps/include/netutils/dhcpd.h71
-rw-r--r--apps/include/netutils/discover.h58
-rw-r--r--apps/include/netutils/ftpd.h217
-rw-r--r--apps/include/netutils/httpd.h185
-rw-r--r--apps/include/netutils/ipmsfilter.h101
-rw-r--r--apps/include/netutils/resolv.h82
-rw-r--r--apps/include/netutils/smtp.h78
-rw-r--r--apps/include/netutils/telnetd.h127
-rw-r--r--apps/include/netutils/tftp.h73
-rw-r--r--apps/include/netutils/thttpd.h101
-rw-r--r--apps/include/netutils/uiplib.h143
-rw-r--r--apps/include/netutils/webclient.h149
-rw-r--r--apps/include/netutils/xmlrpc.h123
-rw-r--r--apps/include/nsh.h121
-rw-r--r--apps/include/readline.h100
-rw-r--r--apps/include/tiff.h465
25 files changed, 3561 insertions, 0 deletions
diff --git a/apps/include/apps.h b/apps/include/apps.h
new file mode 100644
index 000000000..520128203
--- /dev/null
+++ b/apps/include/apps.h
@@ -0,0 +1,149 @@
+/****************************************************************************
+ * apps/include/apps.h
+ *
+ * Copyright(C) 2011 Uros Platise. All rights reserved.
+ * Author: Uros Platise <uros.platise@isotel.eu>
+ *
+ * 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 __APPS_INCLUDE_APPS_H
+#define __APPS_INCLUDE_APPS_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <sys/types.h>
+#include <stdint.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+struct namedapp_s
+{
+ const char *name; /* Invocation name and as seen under /sbin/ */
+ int priority; /* Use: SCHED_PRIORITY_DEFAULT */
+ int stacksize; /* Desired stack size */
+ main_t main; /* Entry point: main(int argc, char *argv[]) */
+};
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/* The "bindir" is file system that supports access to the named applications.
+ * It is typically mounted under /bin.
+ */
+
+#ifdef CONFIG_APPS_BINDIR
+struct mountpt_operations;
+extern const struct mountpt_operations binfs_operations;
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Name: namedapp_isavail
+ *
+ * Description:
+ * Checks for availabiliy of application registerred during compile time.
+ *
+ * Input Parameter:
+ * filename - Name of the linked-in binary to be started.
+ *
+ * Returned Value:
+ * This is an end-user function, so it follows the normal convention:
+ * Returns index of builtin application. If it is not found then it
+ * returns -1 (ERROR) and sets errno appropriately.
+ *
+ ****************************************************************************/
+
+EXTERN int namedapp_isavail(FAR const char *appname);
+
+/****************************************************************************
+ * Name: namedapp_getname
+ *
+ * Description:
+ * Returns pointer to a name of built-in application pointed by the
+ * index.
+ *
+ * Input Parameter:
+ * index, from 0 and on ...
+ *
+ * Returned Value:
+ * Returns valid pointer pointing to the app name if index is valid.
+ * Otherwise NULL is returned.
+ *
+ ****************************************************************************/
+
+EXTERN const char *namedapp_getname(int index);
+
+/****************************************************************************
+ * Name: exec_namedapp
+ *
+ * Description:
+ * Executes builtin named application registered during compile time.
+ * New application is run in a separate task context (and thread).
+ *
+ * Input Parameter:
+ * filename - Name of the linked-in binary to be started.
+ * argv - Argument list
+ *
+ * Returned Value:
+ * This is an end-user function, so it follows the normal convention:
+ * Returns the PID of the exec'ed module. On failure, it.returns
+ * -1 (ERROR) and sets errno appropriately.
+ *
+ ****************************************************************************/
+
+EXTERN int exec_namedapp(FAR const char *appname, FAR const char **argv);
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __APPS_INCLUDE_APPS_H */
diff --git a/apps/include/ftpc.h b/apps/include/ftpc.h
new file mode 100644
index 000000000..f9a73676a
--- /dev/null
+++ b/apps/include/ftpc.h
@@ -0,0 +1,225 @@
+/****************************************************************************
+ * apps/include/ftpc.h
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * 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 __APPS_INCLUDE_FTPC_H
+#define __APPS_INCLUDE_FTPC_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdbool.h>
+#include <signal.h>
+#include <time.h>
+
+#include <netinet/in.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+/* Configuration ************************************************************/
+
+#ifndef CONFIG_FTP_DEFTIMEO
+# define CONFIG_FTP_DEFTIMEO 30
+#endif
+
+#ifndef CONFIG_FTP_ANONPWD
+# define CONFIG_FTP_ANONPWD ""
+#endif
+
+#ifndef CONFIG_FTP_DEFPORT
+# define CONFIG_FTP_DEFPORT 21
+#endif
+
+#ifndef CONFIG_FTP_MAXREPLY
+# define CONFIG_FTP_MAXREPLY 256
+#endif
+
+#ifndef CONFIG_FTP_TMPDIR
+# define CONFIG_FTP_TMPDIR "/tmp"
+#endif
+
+#ifndef CONFIG_FTP_BUFSIZE
+# define CONFIG_FTP_BUFSIZE 1024
+#endif
+
+#ifndef CONFIG_FTP_MAXPATH
+# define CONFIG_FTP_MAXPATH 256
+#endif
+
+#ifndef CONFIG_FTP_SIGNAL
+# define CONFIG_FTP_SIGNAL SIGUSR1
+#endif
+
+/* Interface arguments ******************************************************/
+/* These definitions describe how a put operation should be performed */
+
+#define FTPC_PUT_NORMAL 0 /* Just PUT the file on the server */
+#define FTPC_PUT_APPEND 1 /* Append file to an existing file on the server */
+#define FTPC_PUT_UNIQUE 2 /* Create a uniquely named file on the server */
+#define FTPC_PUT_RESUME 3 /* Resume a previously started PUT transfer */
+
+/* These definitions describe how a get operation should be performed */
+
+#define FTPC_GET_NORMAL 0 /* Just GET the file from the server */
+#define FTPC_GET_APPEND 1 /* Append new file to an existing file */
+#define FTPC_GET_RESUME 3 /* Resume a previously started GET transfer */
+
+/* Transfer mode encoding */
+
+#define FTPC_XFRMODE_UNKNOWN 0 /* Nothing has been transferred yet */
+#define FTPC_XFRMODE_ASCII 1 /* Last transfer was ASCII mode */
+#define FTPC_XFRMODE_BINARY 2 /* Last transfer was binary mode */
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+/* This "handle" describes the FTP session */
+
+typedef FAR void *SESSION;
+
+/* This structure provides information to connect to a host FTP server.
+ *
+ * addr - The IPv4 address of the FTP server (or the proxy) for the FTP
+ * server.
+ * port - The port number on the FTP server to connect to (in host byte
+ * order). This is usually port 21 for FTP. You may set this
+ * value to zero to let FTPC select the default port number for
+ * you (it will use CONFIG_FTP_DEFPORT).
+ */
+
+struct ftpc_connect_s
+{
+ struct in_addr addr; /* Server/proxy IP address */
+ uint16_t port; /* Server/proxy port number (usually 21) in network order */
+};
+
+/* This structure provides FTP login information */
+
+struct ftpc_login_s
+{
+ FAR const char *uname; /* Login uname */
+ FAR const char *pwd; /* Login pwd */
+ FAR const char *rdir; /* Initial remote directory */
+ bool pasv; /* true: passive connection mode */
+};
+
+/* This structure describes one simple directory listing. The directory
+ * list container as well the individual filename strings are allocated.
+ * The number of names in tha actual allocated array is variable, given
+ * by the nnames field.
+ *
+ * Since the structure and file names are allocated, they must be freed
+ * by calling ftpc_dirfree() when they are no longer needed. Allocated
+ * name strings maby be "stolen" from the array but the pointer int the
+ * array should be nullified so that the string is not freed by
+ * ftpc_dirfree().
+ */
+
+struct ftpc_dirlist_s
+{
+ unsigned int nnames; /* Number of entries in name[] array */
+ FAR char *name[1]; /* Filename with absolute path */
+};
+
+#define SIZEOF_FTPC_DIRLIST(n) \
+ (sizeof(struct ftpc_dirlist_s) + ((n)-1)*sizeof(FAR char *))
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+/* Connection management ****************************************************/
+
+EXTERN SESSION ftpc_connect(FAR struct ftpc_connect_s *server);
+EXTERN void ftpc_disconnect(SESSION handle);
+
+/* FTP commands *************************************************************/
+
+EXTERN int ftpc_login(SESSION handle, FAR struct ftpc_login_s *login);
+EXTERN int ftpc_quit(SESSION handle);
+
+EXTERN int ftpc_chdir(SESSION handle, FAR const char *path);
+EXTERN FAR char *ftpc_rpwd(SESSION handle);
+EXTERN int ftpc_cdup(SESSION handle);
+EXTERN int ftpc_mkdir(SESSION handle, FAR const char *path);
+EXTERN int ftpc_rmdir(SESSION handle, FAR const char *path);
+
+EXTERN int ftpc_unlink(SESSION handle, FAR const char *path);
+EXTERN int ftpc_chmod(SESSION handle, FAR const char *path, FAR const char *mode);
+EXTERN int ftpc_rename(SESSION handle, FAR const char *oldname, FAR const char *newname);
+EXTERN off_t ftpc_filesize(SESSION handle, FAR const char *path);
+EXTERN time_t ftpc_filetime(SESSION handle, FAR const char *filename);
+
+EXTERN int ftpc_idle(SESSION handle, unsigned int idletime);
+EXTERN int ftpc_noop(SESSION handle);
+EXTERN int ftpc_help(SESSION handle, FAR const char *arg);
+
+/* Directory listings *******************************************************/
+
+EXTERN FAR struct ftpc_dirlist_s *ftpc_listdir(SESSION handle,
+ FAR const char *dirpath);
+EXTERN void ftpc_dirfree(FAR struct ftpc_dirlist_s *dirlist);
+
+/* File transfers ***********************************************************/
+
+EXTERN int ftpc_getfile(SESSION handle, FAR const char *rname,
+ FAR const char *lname, uint8_t how, uint8_t xfrmode);
+EXTERN int ftp_putfile(SESSION handle, FAR const char *lname,
+ FAR const char *rname, uint8_t how, uint8_t xfrmode);
+
+/* FTP response *************************************************************/
+
+EXTERN FAR char *ftpc_response(SESSION handle);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __APPS_INCLUDE_FTPC_H */
diff --git a/apps/include/modbus/mb.h b/apps/include/modbus/mb.h
new file mode 100644
index 000000000..be7c0df90
--- /dev/null
+++ b/apps/include/modbus/mb.h
@@ -0,0 +1,418 @@
+/*
+ * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
+ * Copyright (c) 2006 Christian Walter <wolti@sil.at>
+ * 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.
+ *
+ * File: $Id: mb.h,v 1.17 2006/12/07 22:10:34 wolti Exp $
+ */
+
+#ifndef _MB_H
+#define _MB_H
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <termios.h>
+
+#ifdef __cplusplus
+PR_BEGIN_EXTERN_C
+#endif
+
+#include "mbport.h"
+#include "mbproto.h"
+
+/*! \defgroup modbus Modbus
+ * \code #include "mb.h" \endcode
+ *
+ * This module defines the interface for the application. It contains
+ * the basic functions and types required to use the Modbus protocol stack.
+ * A typical application will want to call eMBInit() first. If the device
+ * is ready to answer network requests it must then call eMBEnable() to activate
+ * the protocol stack. In the main loop the function eMBPoll() must be called
+ * periodically. The time interval between pooling depends on the configured
+ * Modbus timeout. If an RTOS is available a separate task should be created
+ * and the task should always call the function eMBPoll().
+ *
+ * \code
+ * // Initialize protocol stack in RTU mode for a slave with address 10 = 0x0A
+ * eMBInit( MB_RTU, 0x0A, 38400, MB_PAR_EVEN );
+ * // Enable the Modbus Protocol Stack.
+ * eMBEnable( );
+ * for( ;; )
+ * {
+ * // Call the main polling loop of the Modbus protocol stack.
+ * eMBPoll( );
+ * ...
+ * }
+ * \endcode
+ */
+
+/* ----------------------- Defines ------------------------------------------*/
+
+/*! \ingroup modbus
+ * \brief Use the default Modbus TCP port (502)
+ */
+#define MB_TCP_PORT_USE_DEFAULT 0
+
+/* ----------------------- Type definitions ---------------------------------*/
+
+/*! \ingroup modbus
+ * \brief Modbus serial transmission modes (RTU/ASCII).
+ *
+ * Modbus serial supports two transmission modes. Either ASCII or RTU. RTU
+ * is faster but has more hardware requirements and requires a network with
+ * a low jitter. ASCII is slower and more reliable on slower links (E.g. modems)
+ */
+ typedef enum
+{
+ MB_RTU, /*!< RTU transmission mode. */
+ MB_ASCII, /*!< ASCII transmission mode. */
+ MB_TCP /*!< TCP mode. */
+} eMBMode;
+
+/*! \ingroup modbus
+ * \brief If register should be written or read.
+ *
+ * This value is passed to the callback functions which support either
+ * reading or writing register values. Writing means that the application
+ * registers should be updated and reading means that the modbus protocol
+ * stack needs to know the current register values.
+ *
+ * \see eMBRegHoldingCB( ), eMBRegCoilsCB( ), eMBRegDiscreteCB( ) and
+ * eMBRegInputCB( ).
+ */
+typedef enum
+{
+ MB_REG_READ, /*!< Read register values and pass to protocol stack. */
+ MB_REG_WRITE /*!< Update register values. */
+} eMBRegisterMode;
+
+/*! \ingroup modbus
+ * \brief Errorcodes used by all function in the protocol stack.
+ */
+typedef enum
+{
+ MB_ENOERR, /*!< no error. */
+ MB_ENOREG, /*!< illegal register address. */
+ MB_EINVAL, /*!< illegal argument. */
+ MB_EPORTERR, /*!< porting layer error. */
+ MB_ENORES, /*!< insufficient resources. */
+ MB_EIO, /*!< I/O error. */
+ MB_EILLSTATE, /*!< protocol stack in illegal state. */
+ MB_ETIMEDOUT /*!< timeout error occurred. */
+} eMBErrorCode;
+
+/* ----------------------- Function prototypes ------------------------------*/
+/*! \ingroup modbus
+ * \brief Initialize the Modbus protocol stack.
+ *
+ * This functions initializes the ASCII or RTU module and calls the
+ * init functions of the porting layer to prepare the hardware. Please
+ * note that the receiver is still disabled and no Modbus frames are
+ * processed until eMBEnable( ) has been called.
+ *
+ * \param eMode If ASCII or RTU mode should be used.
+ * \param ucSlaveAddress The slave address. Only frames sent to this
+ * address or to the broadcast address are processed.
+ * \param ucPort The port to use. E.g. 1 for COM1 on windows. This value
+ * is platform dependent and some ports simply choose to ignore it.
+ * \param ulBaudRate The baudrate. E.g. B19200. Supported baudrates depend
+ * on the porting layer.
+ * \param eParity Parity used for serial transmission.
+ *
+ * \return If no error occurs the function returns eMBErrorCode::MB_ENOERR.
+ * The protocol is then in the disabled state and ready for activation
+ * by calling eMBEnable( ). Otherwise one of the following error codes
+ * is returned:
+ * - eMBErrorCode::MB_EINVAL If the slave address was not valid. Valid
+ * slave addresses are in the range 1 - 247.
+ * - eMBErrorCode::MB_EPORTERR IF the porting layer returned an error.
+ */
+eMBErrorCode eMBInit( eMBMode eMode, uint8_t ucSlaveAddress,
+ uint8_t ucPort, speed_t ulBaudRate, eMBParity eParity );
+
+/*! \ingroup modbus
+ * \brief Initialize the Modbus protocol stack for Modbus TCP.
+ *
+ * This function initializes the Modbus TCP Module. Please note that
+ * frame processing is still disabled until eMBEnable( ) is called.
+ *
+ * \param usTCPPort The TCP port to listen on.
+ * \return If the protocol stack has been initialized correctly the function
+ * returns eMBErrorCode::MB_ENOERR. Otherwise one of the following error
+ * codes is returned:
+ * - eMBErrorCode::MB_EINVAL If the slave address was not valid. Valid
+ * slave addresses are in the range 1 - 247.
+ * - eMBErrorCode::MB_EPORTERR IF the porting layer returned an error.
+ */
+eMBErrorCode eMBTCPInit( uint16_t usTCPPort );
+
+/*! \ingroup modbus
+ * \brief Release resources used by the protocol stack.
+ *
+ * This function disables the Modbus protocol stack and release all
+ * hardware resources. It must only be called when the protocol stack
+ * is disabled.
+ *
+ * \note Note all ports implement this function. A port which wants to
+ * get an callback must define the macro MB_PORT_HAS_CLOSE to 1.
+ *
+ * \return If the resources where released it return eMBErrorCode::MB_ENOERR.
+ * If the protocol stack is not in the disabled state it returns
+ * eMBErrorCode::MB_EILLSTATE.
+ */
+eMBErrorCode eMBClose( void );
+
+/*! \ingroup modbus
+ * \brief Enable the Modbus protocol stack.
+ *
+ * This function enables processing of Modbus frames. Enabling the protocol
+ * stack is only possible if it is in the disabled state.
+ *
+ * \return If the protocol stack is now in the state enabled it returns
+ * eMBErrorCode::MB_ENOERR. If it was not in the disabled state it
+ * return eMBErrorCode::MB_EILLSTATE.
+ */
+eMBErrorCode eMBEnable( void );
+
+/*! \ingroup modbus
+ * \brief Disable the Modbus protocol stack.
+ *
+ * This function disables processing of Modbus frames.
+ *
+ * \return If the protocol stack has been disabled it returns
+ * eMBErrorCode::MB_ENOERR. If it was not in the enabled state it returns
+ * eMBErrorCode::MB_EILLSTATE.
+ */
+eMBErrorCode eMBDisable( void );
+
+/*! \ingroup modbus
+ * \brief The main pooling loop of the Modbus protocol stack.
+ *
+ * This function must be called periodically. The timer interval required
+ * is given by the application dependent Modbus slave timeout. Internally the
+ * function calls xMBPortEventGet() and waits for an event from the receiver or
+ * transmitter state machines.
+ *
+ * \return If the protocol stack is not in the enabled state the function
+ * returns eMBErrorCode::MB_EILLSTATE. Otherwise it returns
+ * eMBErrorCode::MB_ENOERR.
+ */
+eMBErrorCode eMBPoll( void );
+
+/*! \ingroup modbus
+ * \brief Configure the slave id of the device.
+ *
+ * This function should be called when the Modbus function <em>Report Slave ID</em>
+ * is enabled (By defining CONFIG_MB_FUNC_OTHER_REP_SLAVEID_ENABLED in .config ).
+ *
+ * \param ucSlaveID Values is returned in the <em>Slave ID</em> byte of the
+ * <em>Report Slave ID</em> response.
+ * \param xIsRunning If true the <em>Run Indicator Status</em> byte is set to 0xFF.
+ * otherwise the <em>Run Indicator Status</em> is 0x00.
+ * \param pucAdditional Values which should be returned in the <em>Additional</em>
+ * bytes of the <em> Report Slave ID</em> response.
+ * \param usAdditionalLen Length of the buffer <code>pucAdditonal</code>.
+ *
+ * \return If the static buffer defined by CONFIG_MB_FUNC_OTHER_REP_SLAVEID_BUF
+ * is too small it returns eMBErrorCode::MB_ENORES. Otherwise
+ * it returns eMBErrorCode::MB_ENOERR.
+ */
+eMBErrorCode eMBSetSlaveID( uint8_t ucSlaveID, bool xIsRunning,
+ uint8_t const *pucAdditional,
+ uint16_t usAdditionalLen );
+
+/*! \ingroup modbus
+ * \brief Registers a callback handler for a given function code.
+ *
+ * This function registers a new callback handler for a given function code.
+ * The callback handler supplied is responsible for interpreting the Modbus PDU and
+ * the creation of an appropriate response. In case of an error it should return
+ * one of the possible Modbus exceptions which results in a Modbus exception frame
+ * sent by the protocol stack.
+ *
+ * \param ucFunctionCode The Modbus function code for which this handler should
+ * be registers. Valid function codes are in the range 1 to 127.
+ * \param pxHandler The function handler which should be called in case
+ * such a frame is received. If \c NULL a previously registered function handler
+ * for this function code is removed.
+ *
+ * \return eMBErrorCode::MB_ENOERR if the handler has been installed. If no
+ * more resources are available it returns eMBErrorCode::MB_ENORES. In this
+ * case the values in config.h should be adjusted. If the argument was not
+ * valid it returns eMBErrorCode::MB_EINVAL.
+ */
+eMBErrorCode eMBRegisterCB( uint8_t ucFunctionCode,
+ pxMBFunctionHandler pxHandler );
+
+/* ----------------------- Callback -----------------------------------------*/
+
+/*! \defgroup modbus_registers Modbus Registers
+ * \code #include "mb.h" \endcode
+ * The protocol stack does not internally allocate any memory for the
+ * registers. This makes the protocol stack very small and also usable on
+ * low end targets. In addition the values don't have to be in the memory
+ * and could for example be stored in a flash.<br>
+ * Whenever the protocol stack requires a value it calls one of the callback
+ * function with the register address and the number of registers to read
+ * as an argument. The application should then read the actual register values
+ * (for example the ADC voltage) and should store the result in the supplied
+ * buffer.<br>
+ * If the protocol stack wants to update a register value because a write
+ * register function was received a buffer with the new register values is
+ * passed to the callback function. The function should then use these values
+ * to update the application register values.
+ */
+
+/*! \ingroup modbus_registers
+ * \brief Callback function used if the value of a <em>Input Register</em>
+ * is required by the protocol stack. The starting register address is given
+ * by \c usAddress and the last register is given by <tt>usAddress +
+ * usNRegs - 1</tt>.
+ *
+ * \param pucRegBuffer A buffer where the callback function should write
+ * the current value of the modbus registers to.
+ * \param usAddress The starting address of the register. Input registers
+ * are in the range 1 - 65535.
+ * \param usNRegs Number of registers the callback function must supply.
+ *
+ * \return The function must return one of the following error codes:
+ * - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
+ * Modbus response is sent.
+ * - eMBErrorCode::MB_ENOREG If the application can not supply values
+ * for registers within this range. In this case a
+ * <b>ILLEGAL DATA ADDRESS</b> exception frame is sent as a response.
+ * - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
+ * currently not available and the application dependent response
+ * timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
+ * exception is sent as a response.
+ * - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
+ * a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
+ */
+eMBErrorCode eMBRegInputCB( uint8_t * pucRegBuffer, uint16_t usAddress,
+ uint16_t usNRegs );
+
+/*! \ingroup modbus_registers
+ * \brief Callback function used if a <em>Holding Register</em> value is
+ * read or written by the protocol stack. The starting register address
+ * is given by \c usAddress and the last register is given by
+ * <tt>usAddress + usNRegs - 1</tt>.
+ *
+ * \param pucRegBuffer If the application registers values should be updated the
+ * buffer points to the new registers values. If the protocol stack needs
+ * to now the current values the callback function should write them into
+ * this buffer.
+ * \param usAddress The starting address of the register.
+ * \param usNRegs Number of registers to read or write.
+ * \param eMode If eMBRegisterMode::MB_REG_WRITE the application register
+ * values should be updated from the values in the buffer. For example
+ * this would be the case when the Modbus master has issued an
+ * <b>WRITE SINGLE REGISTER</b> command.
+ * If the value eMBRegisterMode::MB_REG_READ the application should copy
+ * the current values into the buffer \c pucRegBuffer.
+ *
+ * \return The function must return one of the following error codes:
+ * - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
+ * Modbus response is sent.
+ * - eMBErrorCode::MB_ENOREG If the application can not supply values
+ * for registers within this range. In this case a
+ * <b>ILLEGAL DATA ADDRESS</b> exception frame is sent as a response.
+ * - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
+ * currently not available and the application dependent response
+ * timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
+ * exception is sent as a response.
+ * - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
+ * a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
+ */
+eMBErrorCode eMBRegHoldingCB( uint8_t * pucRegBuffer, uint16_t usAddress,
+ uint16_t usNRegs, eMBRegisterMode eMode );
+
+/*! \ingroup modbus_registers
+ * \brief Callback function used if a <em>Coil Register</em> value is
+ * read or written by the protocol stack. If you are going to use
+ * this function you might use the functions xMBUtilSetBits( ) and
+ * xMBUtilGetBits( ) for working with bitfields.
+ *
+ * \param pucRegBuffer The bits are packed in bytes where the first coil
+ * starting at address \c usAddress is stored in the LSB of the
+ * first byte in the buffer <code>pucRegBuffer</code>.
+ * If the buffer should be written by the callback function unused
+ * coil values (I.e. if not a multiple of eight coils is used) should be set
+ * to zero.
+ * \param usAddress The first coil number.
+ * \param usNCoils Number of coil values requested.
+ * \param eMode If eMBRegisterMode::MB_REG_WRITE the application values should
+ * be updated from the values supplied in the buffer \c pucRegBuffer.
+ * If eMBRegisterMode::MB_REG_READ the application should store the current
+ * values in the buffer \c pucRegBuffer.
+ *
+ * \return The function must return one of the following error codes:
+ * - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
+ * Modbus response is sent.
+ * - eMBErrorCode::MB_ENOREG If the application does not map an coils
+ * within the requested address range. In this case a
+ * <b>ILLEGAL DATA ADDRESS</b> is sent as a response.
+ * - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
+ * currently not available and the application dependent response
+ * timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
+ * exception is sent as a response.
+ * - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
+ * a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
+ */
+eMBErrorCode eMBRegCoilsCB( uint8_t * pucRegBuffer, uint16_t usAddress,
+ uint16_t usNCoils, eMBRegisterMode eMode );
+
+/*! \ingroup modbus_registers
+ * \brief Callback function used if a <em>Input Discrete Register</em> value is
+ * read by the protocol stack.
+ *
+ * If you are going to use his function you might use the functions
+ * xMBUtilSetBits( ) and xMBUtilGetBits( ) for working with bitfields.
+ *
+ * \param pucRegBuffer The buffer should be updated with the current
+ * coil values. The first discrete input starting at \c usAddress must be
+ * stored at the LSB of the first byte in the buffer. If the requested number
+ * is not a multiple of eight the remaining bits should be set to zero.
+ * \param usAddress The starting address of the first discrete input.
+ * \param usNDiscrete Number of discrete input values.
+ * \return The function must return one of the following error codes:
+ * - eMBErrorCode::MB_ENOERR If no error occurred. In this case a normal
+ * Modbus response is sent.
+ * - eMBErrorCode::MB_ENOREG If no such discrete inputs exists.
+ * In this case a <b>ILLEGAL DATA ADDRESS</b> exception frame is sent
+ * as a response.
+ * - eMBErrorCode::MB_ETIMEDOUT If the requested register block is
+ * currently not available and the application dependent response
+ * timeout would be violated. In this case a <b>SLAVE DEVICE BUSY</b>
+ * exception is sent as a response.
+ * - eMBErrorCode::MB_EIO If an unrecoverable error occurred. In this case
+ * a <b>SLAVE DEVICE FAILURE</b> exception is sent as a response.
+ */
+eMBErrorCode eMBRegDiscreteCB( uint8_t * pucRegBuffer, uint16_t usAddress,
+ uint16_t usNDiscrete );
+
+#ifdef __cplusplus
+PR_END_EXTERN_C
+#endif
+#endif
diff --git a/apps/include/modbus/mbframe.h b/apps/include/modbus/mbframe.h
new file mode 100644
index 000000000..0f701e6e5
--- /dev/null
+++ b/apps/include/modbus/mbframe.h
@@ -0,0 +1,87 @@
+/*
+ * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
+ * Copyright (c) 2006 Christian Walter <wolti@sil.at>
+ * 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.
+ *
+ * File: $Id: mbframe.h,v 1.9 2006/12/07 22:10:34 wolti Exp $
+ */
+
+#ifndef _MB_FRAME_H
+#define _MB_FRAME_H
+
+#ifdef __cplusplus
+PR_BEGIN_EXTERN_C
+#endif
+
+/*!
+ * Constants which defines the format of a modbus frame. The example is
+ * shown for a Modbus RTU/ASCII frame. Note that the Modbus PDU is not
+ * dependent on the underlying transport.
+ *
+ * <code>
+ * <------------------------ MODBUS SERIAL LINE PDU (1) ------------------->
+ * <----------- MODBUS PDU (1') ---------------->
+ * +-----------+---------------+----------------------------+-------------+
+ * | Address | Function Code | Data | CRC/LRC |
+ * +-----------+---------------+----------------------------+-------------+
+ * | | | |
+ * (2) (3/2') (3') (4)
+ *
+ * (1) ... MB_SER_PDU_SIZE_MAX = 256
+ * (2) ... MB_SER_PDU_ADDR_OFF = 0
+ * (3) ... MB_SER_PDU_PDU_OFF = 1
+ * (4) ... MB_SER_PDU_SIZE_CRC = 2
+ *
+ * (1') ... MB_PDU_SIZE_MAX = 253
+ * (2') ... MB_PDU_FUNC_OFF = 0
+ * (3') ... MB_PDU_DATA_OFF = 1
+ * </code>
+ */
+
+/* ----------------------- Defines ------------------------------------------*/
+#define MB_PDU_SIZE_MAX 253 /*!< Maximum size of a PDU. */
+#define MB_PDU_SIZE_MIN 1 /*!< Function Code */
+#define MB_PDU_FUNC_OFF 0 /*!< Offset of function code in PDU. */
+#define MB_PDU_DATA_OFF 1 /*!< Offset for response data in PDU. */
+
+/* ----------------------- Prototypes 0-------------------------------------*/
+typedef void ( *pvMBFrameStart ) ( void );
+
+typedef void ( *pvMBFrameStop ) ( void );
+
+typedef eMBErrorCode( *peMBFrameReceive ) ( uint8_t * pucRcvAddress,
+ uint8_t ** pucFrame,
+ uint16_t * pusLength );
+
+typedef eMBErrorCode( *peMBFrameSend ) ( uint8_t slaveAddress,
+ const uint8_t * pucFrame,
+ uint16_t usLength );
+
+typedef void( *pvMBFrameClose ) ( void );
+
+#ifdef __cplusplus
+PR_END_EXTERN_C
+#endif
+#endif
diff --git a/apps/include/modbus/mbfunc.h b/apps/include/modbus/mbfunc.h
new file mode 100644
index 000000000..68ccdb1d9
--- /dev/null
+++ b/apps/include/modbus/mbfunc.h
@@ -0,0 +1,80 @@
+/*
+ * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
+ * Copyright (c) 2006 Christian Walter <wolti@sil.at>
+ * 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.
+ *
+ * File: $Id: mbfunc.h,v 1.12 2006/12/07 22:10:34 wolti Exp $
+ */
+
+#ifndef _MB_FUNC_H
+#define _MB_FUNC_H
+
+#ifdef __cplusplus
+PR_BEGIN_EXTERN_C
+#endif
+#ifdef CONFIG_MB_FUNC_OTHER_REP_SLAVEID_BUF
+ eMBException eMBFuncReportSlaveID( uint8_t * pucFrame, uint16_t * usLen );
+#endif
+
+#ifdef CONFIG_MB_FUNC_READ_INPUT_ENABLED
+eMBException eMBFuncReadInputRegister( uint8_t * pucFrame, uint16_t * usLen );
+#endif
+
+#ifdef CONFIG_MB_FUNC_READ_HOLDING_ENABLED
+eMBException eMBFuncReadHoldingRegister( uint8_t * pucFrame, uint16_t * usLen );
+#endif
+
+#ifdef CONFIG_MB_FUNC_WRITE_HOLDING_ENABLED
+eMBException eMBFuncWriteHoldingRegister( uint8_t * pucFrame, uint16_t * usLen );
+#endif
+
+#ifdef CONFIG_MB_FUNC_WRITE_MULTIPLE_HOLDING_ENABLED
+eMBException eMBFuncWriteMultipleHoldingRegister( uint8_t * pucFrame, uint16_t * usLen );
+#endif
+
+#ifdef CONFIG_MB_FUNC_READ_COILS_ENABLED
+eMBException eMBFuncReadCoils( uint8_t * pucFrame, uint16_t * usLen );
+#endif
+
+#ifdef CONFIG_MB_FUNC_WRITE_COIL_ENABLED
+eMBException eMBFuncWriteCoil( uint8_t * pucFrame, uint16_t * usLen );
+#endif
+
+#ifdef CONFIG_MB_FUNC_WRITE_MULTIPLE_COILS_ENABLED
+eMBException eMBFuncWriteMultipleCoils( uint8_t * pucFrame, uint16_t * usLen );
+#endif
+
+#ifdef CONFIG_MB_FUNC_READ_DISCRETE_INPUTS_ENABLED
+eMBException eMBFuncReadDiscreteInputs( uint8_t * pucFrame, uint16_t * usLen );
+#endif
+
+#ifdef CONFIG_MB_FUNC_READWRITE_HOLDING_ENABLED
+eMBException eMBFuncReadWriteMultipleHoldingRegister( uint8_t * pucFrame, uint16_t * usLen );
+#endif
+
+#ifdef __cplusplus
+PR_END_EXTERN_C
+#endif
+#endif
diff --git a/apps/include/modbus/mbport.h b/apps/include/modbus/mbport.h
new file mode 100644
index 000000000..9301d8c90
--- /dev/null
+++ b/apps/include/modbus/mbport.h
@@ -0,0 +1,132 @@
+/*
+ * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
+ * Copyright (c) 2006 Christian Walter <wolti@sil.at>
+ * 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.
+ *
+ * File: $Id: mbport.h,v 1.19 2010/06/06 13:54:40 wolti Exp $
+ */
+
+#ifndef _MB_PORT_H
+#define _MB_PORT_H
+
+#include <stdint.h>
+#include <stdbool.h>
+
+#ifdef __cplusplus
+PR_BEGIN_EXTERN_C
+#endif
+
+/* ----------------------- Type definitions ---------------------------------*/
+
+typedef enum
+{
+ EV_READY, /*!< Startup finished. */
+ EV_FRAME_RECEIVED, /*!< Frame received. */
+ EV_EXECUTE, /*!< Execute function. */
+ EV_FRAME_SENT /*!< Frame sent. */
+} eMBEventType;
+
+/*! \ingroup modbus
+ * \brief Parity used for characters in serial mode.
+ *
+ * The parity which should be applied to the characters sent over the serial
+ * link. Please note that this values are actually passed to the porting
+ * layer and therefore not all parity modes might be available.
+ */
+typedef enum
+{
+ MB_PAR_NONE, /*!< No parity. */
+ MB_PAR_ODD, /*!< Odd parity. */
+ MB_PAR_EVEN /*!< Even parity. */
+} eMBParity;
+
+/* ----------------------- Supporting functions -----------------------------*/
+bool xMBPortEventInit( void );
+
+bool xMBPortEventPost( eMBEventType eEvent );
+
+bool xMBPortEventGet( /*@out@ */ eMBEventType * eEvent );
+
+/* ----------------------- Serial port functions ----------------------------*/
+
+bool xMBPortSerialInit( uint8_t ucPort, speed_t ulBaudRate,
+ uint8_t ucDataBits, eMBParity eParity );
+
+void vMBPortClose( void );
+
+void xMBPortSerialClose( void );
+
+void vMBPortSerialEnable( bool xRxEnable, bool xTxEnable );
+
+bool xMBPortSerialGetByte( int8_t * pucByte );
+
+bool xMBPortSerialPutByte( int8_t ucByte );
+
+/* ----------------------- Timers functions ---------------------------------*/
+bool xMBPortTimersInit( uint16_t usTimeOut50us );
+
+void xMBPortTimersClose( void );
+
+void vMBPortTimersEnable( void );
+
+void vMBPortTimersDisable( void );
+
+void vMBPortTimersDelay( uint16_t usTimeOutMS );
+
+/* ----------------------- Callback for the protocol stack ------------------*/
+
+/*!
+ * \brief Callback function for the porting layer when a new byte is
+ * available.
+ *
+ * Depending upon the mode this callback function is used by the RTU or
+ * ASCII transmission layers. In any case a call to xMBPortSerialGetByte()
+ * must immediately return a new character.
+ *
+ * \return <code>true</code> if a event was posted to the queue because
+ * a new byte was received. The port implementation should wake up the
+ * tasks which are currently blocked on the eventqueue.
+ */
+extern bool( *pxMBFrameCBByteReceived ) ( void );
+
+extern bool( *pxMBFrameCBTransmitterEmpty ) ( void );
+
+extern bool( *pxMBPortCBTimerExpired ) ( void );
+
+/* ----------------------- TCP port functions -------------------------------*/
+bool xMBTCPPortInit( uint16_t usTCPPort );
+
+void vMBTCPPortClose( void );
+
+void vMBTCPPortDisable( void );
+
+bool xMBTCPPortGetRequest( uint8_t **ppucMBTCPFrame, uint16_t * usTCPLength );
+
+bool xMBTCPPortSendResponse( const uint8_t *pucMBTCPFrame, uint16_t usTCPLength );
+
+#ifdef __cplusplus
+PR_END_EXTERN_C
+#endif
+#endif
diff --git a/apps/include/modbus/mbproto.h b/apps/include/modbus/mbproto.h
new file mode 100644
index 000000000..24b0c98e7
--- /dev/null
+++ b/apps/include/modbus/mbproto.h
@@ -0,0 +1,83 @@
+/*
+ * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
+ * Copyright (c) 2006 Christian Walter <wolti@sil.at>
+ * 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.
+ *
+ * File: $Id: mbproto.h,v 1.14 2006/12/07 22:10:34 wolti Exp $
+ */
+
+#ifndef _MB_PROTO_H
+#define _MB_PROTO_H
+
+#ifdef __cplusplus
+PR_BEGIN_EXTERN_C
+#endif
+/* ----------------------- Defines ------------------------------------------*/
+#define MB_ADDRESS_BROADCAST ( 0 ) /*! Modbus broadcast address. */
+#define MB_ADDRESS_MIN ( 1 ) /*! Smallest possible slave address. */
+#define MB_ADDRESS_MAX ( 247 ) /*! Biggest possible slave address. */
+#define MB_FUNC_NONE ( 0 )
+#define MB_FUNC_READ_COILS ( 1 )
+#define MB_FUNC_READ_DISCRETE_INPUTS ( 2 )
+#define MB_FUNC_WRITE_SINGLE_COIL ( 5 )
+#define MB_FUNC_WRITE_MULTIPLE_COILS ( 15 )
+#define MB_FUNC_READ_HOLDING_REGISTER ( 3 )
+#define MB_FUNC_READ_INPUT_REGISTER ( 4 )
+#define MB_FUNC_WRITE_REGISTER ( 6 )
+#define MB_FUNC_WRITE_MULTIPLE_REGISTERS ( 16 )
+#define MB_FUNC_READWRITE_MULTIPLE_REGISTERS ( 23 )
+#define MB_FUNC_DIAG_READ_EXCEPTION ( 7 )
+#define MB_FUNC_DIAG_DIAGNOSTIC ( 8 )
+#define MB_FUNC_DIAG_GET_COM_EVENT_CNT ( 11 )
+#define MB_FUNC_DIAG_GET_COM_EVENT_LOG ( 12 )
+#define MB_FUNC_OTHER_REPORT_SLAVEID ( 17 )
+#define MB_FUNC_ERROR ( 128 )
+/* ----------------------- Type definitions ---------------------------------*/
+ typedef enum
+{
+ MB_EX_NONE = 0x00,
+ MB_EX_ILLEGAL_FUNCTION = 0x01,
+ MB_EX_ILLEGAL_DATA_ADDRESS = 0x02,
+ MB_EX_ILLEGAL_DATA_VALUE = 0x03,
+ MB_EX_SLAVE_DEVICE_FAILURE = 0x04,
+ MB_EX_ACKNOWLEDGE = 0x05,
+ MB_EX_SLAVE_BUSY = 0x06,
+ MB_EX_MEMORY_PARITY_ERROR = 0x08,
+ MB_EX_GATEWAY_PATH_FAILED = 0x0A,
+ MB_EX_GATEWAY_TGT_FAILED = 0x0B
+} eMBException;
+
+typedef eMBException( *pxMBFunctionHandler ) ( uint8_t * pucFrame, uint16_t * pusLength );
+
+typedef struct
+{
+ uint8_t ucFunctionCode;
+ pxMBFunctionHandler pxHandler;
+} xMBFunctionHandler;
+
+#ifdef __cplusplus
+PR_END_EXTERN_C
+#endif
+#endif
diff --git a/apps/include/modbus/mbutils.h b/apps/include/modbus/mbutils.h
new file mode 100644
index 000000000..5f17376cc
--- /dev/null
+++ b/apps/include/modbus/mbutils.h
@@ -0,0 +1,108 @@
+/*
+ * FreeModbus Libary: A portable Modbus implementation for Modbus ASCII/RTU.
+ * Copyright (c) 2006 Christian Walter <wolti@sil.at>
+ * 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.
+ *
+ * File: $Id: mbutils.h,v 1.5 2006/12/07 22:10:34 wolti Exp $
+ */
+
+#ifndef _MB_UTILS_H
+#define _MB_UTILS_H
+
+#ifdef __cplusplus
+PR_BEGIN_EXTERN_C
+#endif
+/*! \defgroup modbus_utils Utilities
+ *
+ * This module contains some utility functions which can be used by
+ * the application. It includes some special functions for working with
+ * bitfields backed by a character array buffer.
+ *
+ */
+/*! \addtogroup modbus_utils
+ * @{
+ */
+/*! \brief Function to set bits in a byte buffer.
+ *
+ * This function allows the efficient use of an array to implement bitfields.
+ * The array used for storing the bits must always be a multiple of two
+ * bytes. Up to eight bits can be set or cleared in one operation.
+ *
+ * \param ucByteBuf A buffer where the bit values are stored. Must be a
+ * multiple of 2 bytes. No length checking is performed and if
+ * usBitOffset / 8 is greater than the size of the buffer memory contents
+ * is overwritten.
+ * \param usBitOffset The starting address of the bits to set. The first
+ * bit has the offset 0.
+ * \param ucNBits Number of bits to modify. The value must always be smaller
+ * than 8.
+ * \param ucValues Thew new values for the bits. The value for the first bit
+ * starting at <code>usBitOffset</code> is the LSB of the value
+ * <code>ucValues</code>
+ *
+ * \code
+ * ucBits[2] = {0, 0};
+ *
+ * // Set bit 4 to 1 (read: set 1 bit starting at bit offset 4 to value 1)
+ * xMBUtilSetBits( ucBits, 4, 1, 1 );
+ *
+ * // Set bit 7 to 1 and bit 8 to 0.
+ * xMBUtilSetBits( ucBits, 7, 2, 0x01 );
+ *
+ * // Set bits 8 - 11 to 0x05 and bits 12 - 15 to 0x0A;
+ * xMBUtilSetBits( ucBits, 8, 8, 0x5A);
+ * \endcode
+ */
+void xMBUtilSetBits( uint8_t * ucByteBuf, uint16_t usBitOffset,
+ uint8_t ucNBits, uint8_t ucValues );
+
+/*! \brief Function to read bits in a byte buffer.
+ *
+ * This function is used to extract up bit values from an array. Up to eight
+ * bit values can be extracted in one step.
+ *
+ * \param ucByteBuf A buffer where the bit values are stored.
+ * \param usBitOffset The starting address of the bits to set. The first
+ * bit has the offset 0.
+ * \param ucNBits Number of bits to modify. The value must always be smaller
+ * than 8.
+ *
+ * \code
+ * uint8_t ucBits[2] = {0, 0};
+ * uint8_t ucResult;
+ *
+ * // Extract the bits 3 - 10.
+ * ucResult = xMBUtilGetBits( ucBits, 3, 8 );
+ * \endcode
+ */
+uint8_t xMBUtilGetBits( uint8_t * ucByteBuf, uint16_t usBitOffset,
+ uint8_t ucNBits );
+
+/*! @} */
+
+#ifdef __cplusplus
+PR_END_EXTERN_C
+#endif
+#endif
diff --git a/apps/include/netutils/dhcpc.h b/apps/include/netutils/dhcpc.h
new file mode 100644
index 000000000..a6c53dc30
--- /dev/null
+++ b/apps/include/netutils/dhcpc.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+ * apps/include/netutils/dhcpc.h
+ *
+ * Copyright (C) 2007, 2009-2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * This logic was leveraged from uIP which also has a BSD-style license:
+ *
+ * Copyright (c) 2005, 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.
+ */
+
+#ifndef __APPS_INCLUDE_NETUTILS_DHCPC_H
+#define __APPS_INCLUDE_NETUTILS_DHCPC_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdint.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+struct dhcpc_state
+{
+ struct in_addr serverid;
+ struct in_addr ipaddr;
+ struct in_addr netmask;
+ struct in_addr dnsaddr;
+ struct in_addr default_router;
+ uint32_t lease_time; /* Lease expires in this number of seconds */
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+EXTERN void *dhcpc_open(const void *mac_addr, int mac_len);
+EXTERN int dhcpc_request(void *handle, struct dhcpc_state *presult);
+EXTERN void dhcpc_close(void *handle);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __APPS_INCLUDE_NETUTILS_DHCPC_H */
diff --git a/apps/include/netutils/dhcpd.h b/apps/include/netutils/dhcpd.h
new file mode 100644
index 000000000..f997fac30
--- /dev/null
+++ b/apps/include/netutils/dhcpd.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+ * apps/include/netutils/dhcpd.h
+ *
+ * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * This logic was leveraged from uIP which also has a BSD-style license:
+ *
+ * Copyright (c) 2005, 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.
+ */
+
+#ifndef __APPS_INCLUDE_NETUTILS_DHCPD_H
+#define __APPS_INCLUDE_NETUTILS_DHCPD_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+EXTERN int dhcpd_run(void);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __APPS_INCLUDE_NETUTILS_DHCPD_H */
diff --git a/apps/include/netutils/discover.h b/apps/include/netutils/discover.h
new file mode 100644
index 000000000..c2226918d
--- /dev/null
+++ b/apps/include/netutils/discover.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+ * apps/include/netutils/discover.h
+ *
+ * Copyright (C) 2012 Max Holtzberg. All rights reserved.
+ * Author: Max Holtzberg <mh@uvc.de>
+ *
+ * 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 __APPS_INCLUDE_NETUTILS_DISCOVER_H
+#define __APPS_INCLUDE_NETUTILS_DISCOVER_H
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: discover_start
+ *
+ * Description:
+ * Start the discover daemon.
+ *
+ * Return:
+ * The process ID (pid) of the new discover daemon is returned on
+ * success; A negated errno is returned if the daemon was not successfully
+ * started.
+ *
+ ****************************************************************************/
+
+int discover_start(void);
+
+#endif /* __APPS_INCLUDE_NETUTILS_DISCOVER_H */
diff --git a/apps/include/netutils/ftpd.h b/apps/include/netutils/ftpd.h
new file mode 100644
index 000000000..71a2096bb
--- /dev/null
+++ b/apps/include/netutils/ftpd.h
@@ -0,0 +1,217 @@
+/****************************************************************************
+ * apps/include/netutils/ftpd.h
+ *
+ * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * 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 __APPS_INCLUDE_NETUTILS_FTPD_H
+#define __APPS_INCLUDE_NETUTILS_FTPD_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+/* Configuration ************************************************************/
+/* Required configuration settings: Of course TCP networking support is
+ * required. But here are a couple that are less obvious:
+ *
+ * CONFIG_DISABLE_PTHREAD - pthread support is required
+ * CONFIG_DISABLE_POLL - poll() support is required
+ *
+ * Other FTPD configuration options thay may be of interest:
+ *
+ * CONFIG_FTPD_VENDORID - The vendor name to use in FTP communications.
+ * Default: "NuttX"
+ * CONFIG_FTPD_SERVERID - The server name to use in FTP communications.
+ * Default: "NuttX FTP Server"
+ * CONFIG_FTPD_CMDBUFFERSIZE - The maximum size of one command. Default:
+ * 128 bytes.
+ * CONFIG_FTPD_DATABUFFERSIZE - The size of the I/O buffer for data
+ * transfers. Default: 512 bytes.
+ * CONFIG_FTPD_WORKERSTACKSIZE - The stacksize to allocate for each
+ * FTP daemon worker thread. Default: 2048 bytes.
+ */
+
+#ifdef CONFIG_DISABLE_PTHREAD
+# error "pthread support is required (CONFIG_DISABLE_PTHREAD=n)"
+#endif
+
+#ifdef CONFIG_DISABLE_POLL
+# error "poll() support is required (CONFIG_DISABLE_POLL=n)"
+#endif
+
+#ifndef CONFIG_FTPD_VENDORID
+# define CONFIG_FTPD_VENDORID "NuttX"
+#endif
+
+#ifndef CONFIG_FTPD_SERVERID
+# define CONFIG_FTPD_SERVERID "NuttX FTP Server"
+#endif
+
+#ifndef CONFIG_FTPD_CMDBUFFERSIZE
+# define CONFIG_FTPD_CMDBUFFERSIZE 128
+#endif
+
+#ifndef CONFIG_FTPD_DATABUFFERSIZE
+# define CONFIG_FTPD_DATABUFFERSIZE 512
+#endif
+
+#ifndef CONFIG_FTPD_WORKERSTACKSIZE
+# define CONFIG_FTPD_WORKERSTACKSIZE 2048
+#endif
+
+/* Interface definitions ****************************************************/
+
+#define FTPD_ACCOUNTFLAG_NONE (0)
+#define FTPD_ACCOUNTFLAG_ADMIN (1 << 0)
+#define FTPD_ACCOUNTFLAG_SYSTEM (1 << 1)
+#define FTPD_ACCOUNTFLAG_GUEST (1 << 2)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* This "handle" describes the FTP session */
+
+typedef FAR void *FTPD_SESSION;
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: ftpd_open
+ *
+ * Description:
+ * Create an instance of the FTPD server and return a handle that can be
+ * used to run the server.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * On success, a non-NULL handle is returned that can be used to reference
+ * the server instance.
+ *
+ ****************************************************************************/
+
+EXTERN FTPD_SESSION ftpd_open(void);
+
+/****************************************************************************
+ * Name: ftpd_adduser
+ *
+ * Description:
+ * Add one FTP user.
+ *
+ * Input Parameters:
+ * handle - A handle previously returned by ftpd_open
+ * accountflags - The characteristics of this user (see FTPD_ACCOUNTFLAGS_*
+ * definitions above).
+ * user - The user login name. May be NULL indicating that no login is
+ * required.
+ * passwd - The user password. May be NULL indicating that no password
+ * is required.
+ * home - The user home directory. May be NULL.
+ *
+ * Returned Value:
+ * Zero is returned on success. A negated errno value is return on
+ * failure.
+ *
+ ****************************************************************************/
+
+EXTERN int ftpd_adduser(FTPD_SESSION handle, uint8_t accountflags,
+ FAR const char *user, FAR const char *passwd,
+ FAR const char *home);
+
+/****************************************************************************
+ * Name: ftpd_session
+ *
+ * Description:
+ * Execute the FTPD server. This thread does not return until either (1)
+ * the timeout expires with no connection, (2) some other error occurs, or
+ * (2) a connection was accepted and an FTP worker thread was started to
+ * service the session. Each call to ftpd_session creates on session.
+ *
+ * Input Parameters:
+ * handle - A handle previously returned by ftpd_open
+ * timeout - A time in milliseconds to wait for a connection. If this
+ * time elapses with no connected, the -ETIMEDOUT error will be returned.
+ *
+ * Returned Value:
+ * Zero is returned if the FTP worker was started. On failure, a negated
+ * errno value is returned to indicate why the servier terminated.
+ * -ETIMEDOUT indicates that the user-provided timeout elapsed with no
+ * connection.
+ *
+ ****************************************************************************/
+
+EXTERN int ftpd_session(FTPD_SESSION handle, int timeout);
+
+/****************************************************************************
+ * Name: ftpd_close
+ *
+ * Description:
+ * Close and destroy the handle created by ftpd_open.
+ *
+ * Input Parameters:
+ * handle - A handle previously returned by ftpd_open
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+EXTERN void ftpd_close(FTPD_SESSION handle);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+#endif /* __APPS_INCLUDE_NETUTILS_FTPD_H */
diff --git a/apps/include/netutils/httpd.h b/apps/include/netutils/httpd.h
new file mode 100644
index 000000000..8ba9e2f7b
--- /dev/null
+++ b/apps/include/netutils/httpd.h
@@ -0,0 +1,185 @@
+/****************************************************************************
+ * apps/include/netutils/httpd.h
+ *
+ * Copyright (C) 2007, 2009, 2011-2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Based on uIP which also has a BSD style license:
+ *
+ * Author: Adam Dunkels <adam@sics.se>
+ * 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 __APPS_INCLUDE_NETUTILS_HTTPD_H
+#define __APPS_INCLUDE_NETUTILS_HTTPD_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/net/uip/uip.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifdef __cplusplus
+# define EXTERN extern "C"
+extern "C" {
+#else
+# define EXTERN extern
+#endif
+
+/* As threads are created to handle each request, a stack must be allocated
+ * for the thread. Use a default if the user provided no stacksize.
+ */
+
+#ifndef CONFIG_NETUTILS_HTTPDSTACKSIZE
+# define CONFIG_NETUTILS_HTTPDSTACKSIZE 4096
+#endif
+
+#ifndef CONFIG_NETUTILS_HTTPDFSSTATS
+# define CONFIG_NETUTILS_HTTPDFSSTATS
+#endif
+
+#ifndef CONFIG_NETUTILS_HTTPDFILESTATS
+# define CONFIG_NETUTILS_HTTPDFILESTATS
+#endif
+
+#ifndef CONFIG_NET_STATISTICS
+# undef CONFIG_NETUTILS_HTTPDNETSTATS
+#endif
+
+/* For efficiency reasons, the size of the IO buffer should be a multiple
+ * of the TCP MSS value. Also, the current design requires that the IO
+ * buffer be sufficiently large to contain the entire GET request.
+ */
+
+#define HTTPD_IOBUFFER_SIZE (3*UIP_TCP_MSS)
+
+/* This is the maximum size of a file path */
+
+#if defined(CONFIG_NETUTILS_HTTPD_MMAP) || defined(CONFIG_NETUTILS_HTTPD_SENDFILE)
+#define HTTPD_MAX_FILENAME PATH_MAX
+#else
+#define HTTPD_MAX_FILENAME 20
+#endif
+
+/****************************************************************************
+ * Public types
+ ****************************************************************************/
+
+struct httpd_fs_file
+{
+ char *data;
+ int len;
+#if defined(CONFIG_NETUTILS_HTTPD_MMAP) || defined(CONFIG_NETUTILS_HTTPD_SENDFILE)
+ int fd;
+#endif
+};
+
+struct httpd_state
+{
+ char ht_buffer[HTTPD_IOBUFFER_SIZE]; /* recv()/send() buffer */
+ char ht_filename[HTTPD_MAX_FILENAME]; /* filename from GET command */
+ struct httpd_fs_file ht_file; /* Fake file data to send */
+ int ht_sockfd; /* The socket descriptor from accept() */
+ char *ht_scriptptr;
+ uint16_t ht_scriptlen;
+ uint16_t ht_sndlen;
+};
+
+struct httpd_fsdata_file
+{
+ const struct httpd_fsdata_file *next;
+ FAR const uint8_t *name;
+ FAR const uint8_t *data;
+ int len;
+#ifdef CONFIG_NETUTILS_HTTPDFSSTATS
+ uint16_t count;
+#endif
+};
+
+struct httpd_fsdata_file_noconst
+{
+ FAR struct httpd_fsdata_file *next;
+ FAR char *name;
+ FAR char *data;
+ int len;
+#ifdef CONFIG_NETUTILS_HTTPDFSSTATS
+ uint16_t count;
+#endif
+};
+
+typedef void (*httpd_cgifunction)(struct httpd_state *, char *);
+
+struct httpd_cgi_call
+{
+ struct httpd_cgi_call *next;
+ const char *name;
+ httpd_cgifunction function;
+};
+
+/* HTTPD CGI function declaration
+ *
+ * Description:
+ * This macro is used for declaring a HTTPD CGI function. This function is
+ * then added to the list of HTTPD CGI functions with the httpd_cgi_register()
+ * function.
+
+ * Input Paramters:
+ *
+ * name The C variable name of the function
+ * str The string name of the function, used in the script file
+ * function A pointer to the function that implements it
+ */
+
+#define HTTPD_CGI_CALL(name, str, function) \
+static void function(struct httpd_state *, char *); \
+static struct httpd_cgi_call name = {NULL, str, function}
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+EXTERN void httpd_init(void);
+EXTERN int httpd_listen(void);
+EXTERN void httpd_cgi_register(struct httpd_cgi_call *cgi_call);
+EXTERN uint16_t httpd_fs_count(char *name);
+
+EXTERN const struct httpd_fsdata_file g_httpdfs_root[];
+EXTERN const int g_httpd_numfiles;
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __APPS_INCLUDE_NETUTILS_HTTPD_H */
diff --git a/apps/include/netutils/ipmsfilter.h b/apps/include/netutils/ipmsfilter.h
new file mode 100644
index 000000000..2dcffa4a1
--- /dev/null
+++ b/apps/include/netutils/ipmsfilter.h
@@ -0,0 +1,101 @@
+/****************************************************************************
+ * apps/include/netutils/ipmsfilter.h
+ * User interface to add/remove IP multicast address
+ *
+ * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * 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 __APPS_INCLUDE_NETUTILS_IPMSFILTER_H
+#define __APPS_INCLUDE_NETUTILS_IPMSFILTER_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <netinet/in.h>
+
+#ifdef CONFIG_NET_IGMP
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifdef CONFIG_NET_IPv6
+# error "IGMP for IPv6 not supported"
+#endif
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: ipmsfilter
+ *
+ * Description:
+ * Add or remove an IP address from a multicast filter set.
+ * (See netutils/uiplib/uip_ipmsfilter.c)
+ *
+ * Parameters:
+ * ifname The name of the interface to use, size must less than IMSFNAMSIZ
+ * multiaddr Multicast group address to add/remove
+ * fmode MCAST_INCLUDE: Add multicast address
+ * MCAST_EXCLUDE: Remove multicast address
+ *
+ * Return:
+ * 0 on sucess; Negated errno on failure
+ *
+ ****************************************************************************/
+
+EXTERN int ipmsfilter(FAR const char *ifname,
+ FAR const struct in_addr *multiaddr,
+ uint32_t fmode);
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* CONFIG_NET_IGMP */
+#endif /* __APPS_INCLUDE_NETUTILS_IPMSFILTER_H */
diff --git a/apps/include/netutils/resolv.h b/apps/include/netutils/resolv.h
new file mode 100644
index 000000000..bf71e3b6e
--- /dev/null
+++ b/apps/include/netutils/resolv.h
@@ -0,0 +1,82 @@
+/****************************************************************************
+ * apps/include/netutils/resolv.h
+ * DNS resolver code header file.
+ * Author Adam Dunkels <adam@dunkels.com>
+ *
+ * Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Inspired by/based on uIP logic by Adam Dunkels:
+ *
+ * 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 __APPS_INCLUDE_NETUTILS_RESOLVE_H
+#define __APPS_INCLUDE_NETUTILS_RESOLVE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/net/uip/uipopt.h>
+
+#include <netinet/in.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/* Functions. */
+
+EXTERN int resolv_init(void);
+
+#ifdef CONFIG_NET_IPv6
+EXTERN void resolv_conf(FAR const struct in6_addr *dnsserver);
+EXTERN void resolv_getserver(FAR const struct in_addr *dnsserver);
+EXTERN int resolv_query(FAR const char *name, FAR struct sockaddr_in6 *addr);
+#else
+EXTERN void resolv_conf(FAR const struct in_addr *dnsserver);
+EXTERN void resolv_getserver(FAR struct in_addr *dnsserver);
+EXTERN int resolv_query(FAR const char *name, FAR struct sockaddr_in *addr);
+#endif
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __APPS_INCLUDE_NETUTILS_RESOLVE_H */
diff --git a/apps/include/netutils/smtp.h b/apps/include/netutils/smtp.h
new file mode 100644
index 000000000..1bb0cc16f
--- /dev/null
+++ b/apps/include/netutils/smtp.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+ * apps/include/netutils/smtp.h
+ * SMTP header file
+ *
+ * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Heavily leveraged from uIP 1.0 which also has a BSD-like license:
+ *
+ * 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 __APPS_INCLUDE_NETUTILS_SMTP_H
+#define __APPS_INCLUDE_NETUTILS_SMTP_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/net/uip/uipopt.h>
+#include <nuttx/net/uip/uip.h>
+
+/****************************************************************************
+ * Type Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+EXTERN void *smtp_open(void);
+EXTERN void smtp_configure(void *handle, const char *localhostname,
+ const uip_ipaddr_t *paddr);
+EXTERN int smtp_send(void *handle, const char *to, const char *cc,
+ const char *from, const char *subject,
+ const char *msg, int msglen);
+EXTERN void smtp_close(void *handle);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __APPS_INCLUDE_NETUTILS_SMTP_H */
diff --git a/apps/include/netutils/telnetd.h b/apps/include/netutils/telnetd.h
new file mode 100644
index 000000000..98721c023
--- /dev/null
+++ b/apps/include/netutils/telnetd.h
@@ -0,0 +1,127 @@
+/****************************************************************************
+ * apps/include/netutils/telnetd.h
+ *
+ * Copyright (C) 2007, 2011-2012 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * 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 Gregory Nutt 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 __APPS_INCLUDE_NETUTILS_TELNETD_H
+#define __APPS_INCLUDE_NETUTILS_TELNETD_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+/* CONFIG_TELNETD_CONSOLE - Use the first telnet session as the default
+ * console.
+ * CONFIG_TELNETD_RXBUFFER_SIZE - The size of the telnet receive buffer.
+ * Default: 256 bytes.
+ * CONFIG_TELNETD_TXBUFFER_SIZE - The size of the telnet transmit buffer.
+ * Default: 256 bytes.
+ * CONFIG_TELNETD_DUMPBUFFER - dumping of all input/output buffers.
+ */
+
+#ifndef CONFIG_TELNETD_RXBUFFER_SIZE
+# define CONFIG_TELNETD_RXBUFFER_SIZE 256
+#endif
+
+#ifndef CONFIG_TELNETD_TXBUFFER_SIZE
+# define CONFIG_TELNETD_TXBUFFER_SIZE 256
+#endif
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+ /* An instance of the struct telnetd_config_s structure must be passed to
+ * telnetd_start in order to configure the new telnet daemon.
+ */
+
+struct telnetd_config_s
+{
+ /* These fields describe the telnet daemon */
+
+ int d_port; /* The port to listen on (in network byte order) */
+ int d_priority; /* The execution priority of the telnet daemon task */
+ int d_stacksize; /* The stack size needed by the telnet daemon task */
+
+ /* These fields describe the priority of each thread created by the telnet
+ * daemon.
+ */
+
+ int t_priority; /* The execution priority of the spawned task, */
+ int t_stacksize; /* The stack size needed by the spawned task */
+ main_t t_entry; /* The entrypoint of the task to spawn when a new
+ * connection is accepted. */
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Name: telnetd_start
+ *
+ * Description:
+ * Start the telnet daemon.
+ *
+ * Parameters:
+ * config A pointer to a configuration structure that characterizes the
+ * telnet daemon. This configuration structure may be defined
+ * on the caller's stack because it is not retained by the
+ * daemon.
+ *
+ * Return:
+ * The process ID (pid) of the new telnet daemon is returned on
+ * success; A negated errno is returned if the daemon was not successfully
+ * started.
+ *
+ ****************************************************************************/
+
+EXTERN int telnetd_start(FAR struct telnetd_config_s *config);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+#endif /* __APPS_INCLUDE_NETUTILS_TELNETD_H */
diff --git a/apps/include/netutils/tftp.h b/apps/include/netutils/tftp.h
new file mode 100644
index 000000000..276073aad
--- /dev/null
+++ b/apps/include/netutils/tftp.h
@@ -0,0 +1,73 @@
+/****************************************************************************
+ * apps/include/netutils/tftp.h
+ *
+ * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * 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 __APPS_INCLUDE_NETUTILS_TFTP_H
+#define __APPS_INCLUDE_NETUTILS_TFTP_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdbool.h>
+#include <arpa/inet.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+EXTERN int tftpget(const char *remote, const char *local, in_addr_t addr, bool binary);
+EXTERN int tftpput(const char *local, const char *remote, in_addr_t addr, bool binary);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __APPS_INCLUDE_NETUTILS_TFTP_H */
diff --git a/apps/include/netutils/thttpd.h b/apps/include/netutils/thttpd.h
new file mode 100644
index 000000000..92ed7ba97
--- /dev/null
+++ b/apps/include/netutils/thttpd.h
@@ -0,0 +1,101 @@
+/****************************************************************************
+ * apps/include/netutils/thttpd.h
+ *
+ * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * 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 __APPS_INCLUDE_NETUTILS_THTTPD_H
+#define __APPS_INCLUDE_NETUTILS_THTTPD_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <nuttx/symtab.h>
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/* These values must be provided by the user before the THTTPD task daemon
+ * is started:
+ *
+ * g_thttpdsymtab: A symbol table describing all of the symbols exported
+ * from the base system. These symbols are used to bind address references
+ * in CGI programs to NuttX.
+ * g_nsymbols: The number of symbols in g_thttpdsymtab[].
+ *
+ * (See examples/nxflat and examples/thttpd for examples of how such a symbol
+ * table may be created.)
+ */
+
+EXTERN FAR const struct symtab_s *g_thttpdsymtab;
+EXTERN int g_thttpdnsymbols;
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Function: thttpd_main
+ *
+ * Description:
+ * This function is the entrypoint into the THTTPD server. It does not
+ * return. It may be called, the normal mechanism for starting the server
+ * is:
+ *
+ * 1) Set is g_thttpdsymtab and g_thttpdnsymbols. The user is required
+ * to provide a symbol table to use for binding CGI programs (if CGI
+ * is enabled. See examples/nxflat and examples/thttpd for examples of
+ * how such a symbol table may be created.)
+ * 2) Call task_create() to start thttpd_main()
+ *
+ ****************************************************************************/
+
+EXTERN int thttpd_main(int argc, char **argv);
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __APPS_INCLUDE_NETUTILS_THTTPD_H */
diff --git a/apps/include/netutils/uiplib.h b/apps/include/netutils/uiplib.h
new file mode 100644
index 000000000..b99417362
--- /dev/null
+++ b/apps/include/netutils/uiplib.h
@@ -0,0 +1,143 @@
+/****************************************************************************
+ * apps/include/netutils/uiplib.h
+ * Various non-standard APIs to support netutils. All non-standard and
+ * intended only for internal use.
+ *
+ * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Some of these APIs derive from uIP but all of them use the uip_ prefix
+ * to identify them as members of this library. uIP also has a BSD style
+ * license:
+ *
+ * Author: Adam Dunkels <adam@sics.se>
+ * 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 __APPS_INCLUDE_NETUTILS_UIPLIB_H
+#define __APPS_INCLUDE_NETUTILS_UIPLIB_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <pthread.h>
+
+#include <netinet/in.h>
+#include <nuttx/net/uip/uipopt.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* SOCK_DGRAM is the preferred socket type to use when we just want a
+ * socket for performing drive ioctls. However, we can't use SOCK_DRAM
+ * if UDP is disabled.
+ */
+
+#ifdef CONFIG_NET_UDP
+# define UIPLIB_SOCK_IOCTL SOCK_DGRAM
+#else
+# define UIPLIB_SOCK_IOCTL SOCK_STREAM
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/* Convert a textual representation of an IP address to a numerical representation.
+ *
+ * This function takes a textual representation of an IP address in
+ * the form a.b.c.d and converts it into a 4-byte array that can be
+ * used by other uIP functions.
+ *
+ * addrstr A pointer to a string containing the IP address in
+ * textual form.
+ *
+ * addr A pointer to a 4-byte array that will be filled in with
+ * the numerical representation of the address.
+ *
+ * Return: 0 If the IP address could not be parsed.
+ * Return: Non-zero If the IP address was parsed.
+ */
+
+EXTERN bool uiplib_ipaddrconv(const char *addrstr, uint8_t *addr);
+
+/* Get and set IP/MAC addresses (Ethernet L2 only) */
+
+#ifdef CONFIG_NET_ETHERNET
+EXTERN int uip_setmacaddr(const char *ifname, const uint8_t *macaddr);
+EXTERN int uip_getmacaddr(const char *ifname, uint8_t *macaddr);
+#endif
+
+/* IP address support */
+
+#ifdef CONFIG_NET_IPv6
+EXTERN int uip_gethostaddr(const char *ifname, struct in6_addr *addr);
+EXTERN int uip_sethostaddr(const char *ifname, const struct in6_addr *addr);
+EXTERN int uip_setdraddr(const char *ifname, const struct in6_addr *addr);
+EXTERN int uip_setnetmask(const char *ifname, const struct in6_addr *addr);
+#else
+EXTERN int uip_gethostaddr(const char *ifname, struct in_addr *addr);
+EXTERN int uip_sethostaddr(const char *ifname, const struct in_addr *addr);
+EXTERN int uip_setdraddr(const char *ifname, const struct in_addr *addr);
+EXTERN int uip_setnetmask(const char *ifname, const struct in_addr *addr);
+#endif
+
+/* HTTP support */
+
+EXTERN int uip_parsehttpurl(const char *url, uint16_t *port,
+ char *hostname, int hostlen,
+ char *filename, int namelen);
+
+/* Generic server logic */
+
+EXTERN int uip_listenon(uint16_t portno);
+EXTERN void uip_server(uint16_t portno, pthread_startroutine_t handler, int stacksize);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __APPS_INCLUDE_NETUTILS_UIPLIB_H */
diff --git a/apps/include/netutils/webclient.h b/apps/include/netutils/webclient.h
new file mode 100644
index 000000000..5c07f20ab
--- /dev/null
+++ b/apps/include/netutils/webclient.h
@@ -0,0 +1,149 @@
+/****************************************************************************
+ * apps/include/netutils/webclient.h
+ * Header file for the HTTP client
+ *
+ * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Based remotely on the uIP webclient which also has a BSD style license:
+ *
+ * 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 __APPS_INCLUDE_NETUTILS_WEBCLIENT_H
+#define __APPS_INCLUDE_NETUTILS_WEBCLIENT_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#ifndef CONFIG_WEBCLIENT_HOST
+# include <nuttx/config.h>
+#endif
+#include <sys/types.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifndef CONFIG_WEBCLIENT_MAXHTTPLINE
+# define CONFIG_WEBCLIENT_MAXHTTPLINE 200
+#endif
+
+#ifndef CONFIG_WEBCLIENT_MAXMIMESIZE
+# define CONFIG_WEBCLIENT_MAXMIMESIZE 32
+#endif
+
+#ifndef CONFIG_WEBCLIENT_MAXHOSTNAME
+# define CONFIG_WEBCLIENT_MAXHOSTNAME 40
+#endif
+
+#ifndef CONFIG_WEBCLIENT_MAXFILENAME
+# define CONFIG_WEBCLIENT_MAXFILENAME 100
+#endif
+
+/****************************************************************************
+ * Public types
+ ****************************************************************************/
+
+/* wget calls a user provided function of the follwoing type to process
+ * each received chuck of the incoming file data. If the system has a file
+ * system, then it may just write the data to a file. Or it may buffer the
+ * file in memory. To facilitate this latter case, the caller may modify
+ * the buffer address in this callback by writing to buffer and buflen. This
+ * may be used, for example, to implement double buffering.
+ *
+ * Input Parameters:
+ * buffer - A pointer to a pointer to a buffer. If the callee wishes to
+ * change the buffer address, it may do so in the callback by writing
+ * to buffer.
+ * offset - Offset to the beginning of valid data in the buffer. Offset
+ * is used to skip over any HTTP header info that may be at the
+ * beginning of the buffer.
+ * datend - The end+1 offset of valid data in the buffer. The total number
+ * of valid bytes is datend - offset.
+ * buflen - A pointer to the length of the buffer. If the callee wishes
+ * to change the size of the buffer, it may write to buflen.
+ */
+
+typedef void (*wget_callback_t)(FAR char **buffer, int offset,
+ int datend, FAR int *buflen, FAR void *arg);
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Name: wget
+ *
+ * Description:
+ * Obtain the requested file from an HTTP server using the GET method.
+ *
+ * Note: If the function is passed a host name, it must already be in
+ * the resolver cache in order for the function to connect to the web
+ * server. It is therefore up to the calling module to implement the
+ * resolver calls and the signal handler used for reporting a resolv
+ * query answer.
+ *
+ * Input Parameters
+ * url - A pointer to a string containing either the full URL to
+ * the file to get (e.g., http://www.nutt.org/index.html, or
+ * http://192.168.23.1:80/index.html).
+ * buffer - A user provided buffer to receive the file data (also
+ * used for the outgoing GET request
+ * buflen - The size of the user provided buffer
+ * callback - As data is obtained from the host, this function is
+ * to dispose of each block of file data as it is received.
+ * arg - User argument passed to callback.
+ *
+ * Returned Value:
+ * 0: if the GET operation completed successfully;
+ * -1: On a failure with errno set appropriately
+ *
+ ****************************************************************************/
+
+EXTERN int wget(FAR const char *url, FAR char *buffer, int buflen,
+ wget_callback_t callback, FAR void *arg);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __APPS_INCLUDE_NETUTILS_WEBCLIENT_H */
diff --git a/apps/include/netutils/xmlrpc.h b/apps/include/netutils/xmlrpc.h
new file mode 100644
index 000000000..3136e35ef
--- /dev/null
+++ b/apps/include/netutils/xmlrpc.h
@@ -0,0 +1,123 @@
+/****************************************************************************
+ * apps/include/netutils/xmlrpc.h
+ *
+ * Copyright (C) 2012 Max Holtzberg. All rights reserved.
+ * Author: Max Holtzberg <mh@uvc.de>
+ *
+ * Based on the embeddable lightweight XML-RPC server code discussed
+ * in the article at: http://www.drdobbs.com/web-development/\
+ * an-embeddable-lightweight-xml-rpc-server/184405364
+ *
+ * Copyright (c) 2002 Cogito LLC. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, is hereby granted without fee 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 Cogito LLC 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 COGITO LLC AND CONTRIBUTERS 'AS IS'
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COGITO LLC
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARAY, 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.
+ ****************************************************************************/
+
+/*
+ * Lightweight Embedded XML-RPC Server Types and Definitions
+ *
+ * mtj@cogitollc.com
+ *
+ */
+
+#ifndef __APPS_INCLUDE_NETUTILS_XMLRPC_H
+#define __APPS_INCLUDE_NETUTILS_XMLRPC_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Error definitions. */
+
+#define XMLRPC_NO_ERROR (0)
+#define XMLRPC_PARSE_ERROR (-1)
+#define XMLRPC_NO_SUCH_FUNCTION (-2)
+#define XMLRPC_UNEXPECTED_INTEGER_ARG (-3)
+#define XMLRPC_UNEXPECTED_BOOLEAN_ARG (-4)
+#define XMLRPC_UNEXPECTED_DOUBLE_ARG (-5)
+#define XMLRPC_UNEXPECTED_STRING_ARG (-6)
+#define XMLRPC_BAD_RESPONSE_ARG (-7)
+#define XMLRPC_INTERNAL_ERROR (-99)
+
+#define MAX_ARGS 10
+#define MAX_RESPONSE 2048
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+struct xmlrpc_arg_s
+{
+ union
+ {
+ int i;
+ char boolean;
+ double d;
+ char string[CONFIG_XMLRPC_STRINGSIZE+1];
+ } u;
+};
+
+struct xmlrpc_s
+{
+ char name[CONFIG_XMLRPC_STRINGSIZE+1];
+ struct xmlrpc_arg_s arguments[MAX_ARGS];
+ char args[MAX_ARGS];
+ int argsize;
+ int arg;
+ char response[MAX_RESPONSE];
+ int error;
+};
+
+struct xmlrpc_entry_s
+{
+ struct xmlrpc_entry_s *next;
+ int (*func)(struct xmlrpc_s*);
+ char *name;
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+void xmlrpc_register(struct xmlrpc_entry_s *call);
+int xmlrpc_parse(int sock, char *buffer);
+int xmlrpc_getinteger(struct xmlrpc_s *xmlcall, int *arg);
+int xmlrpc_getbool(struct xmlrpc_s *xmlcall, int *arg);
+int xmlrpc_getdouble(struct xmlrpc_s *xmlcall, double *arg);
+int xmlrpc_getstring(struct xmlrpc_s *xmlcall, char *arg);
+int xmlrpc_buildresponse(struct xmlrpc_s *, char *, ...);
+
+#endif /* __APPS_INCLUDE_NETUTILS_XMLRPC_H */
diff --git a/apps/include/nsh.h b/apps/include/nsh.h
new file mode 100644
index 000000000..4b5a3cd31
--- /dev/null
+++ b/apps/include/nsh.h
@@ -0,0 +1,121 @@
+/****************************************************************************
+ * apps/include/nsh.h
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * 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 __APPS_INCLUDE_NSH_H
+#define __APPS_INCLUDE_NSH_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/****************************************************************************
+ * Pre-Processor Definitions
+ ****************************************************************************/
+
+#if CONFIG_RR_INTERVAL > 0
+# define SCHED_NSH SCHED_RR
+#else
+# define SCHED_NSH SCHED_FIFO
+#endif
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nsh_initialize
+ *
+ * Description:
+ * This nterfaces is used to initialize the NuttShell (NSH).
+ * nsh_initialize() should be called one during application start-up prior
+ * to executing either nsh_consolemain() or nsh_telnetstart().
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+EXTERN void nsh_initialize(void);
+
+/****************************************************************************
+ * Name: nsh_consolemain
+ *
+ * Description:
+ * This interfaces maybe to called or started with task_start to start a
+ * single an NSH instance that operates on stdin and stdout (/dev/console).
+ * This function does not return.
+ *
+ * Input Parameters:
+ * Standard task start-up arguements. These are not used. argc may be
+ * zero and argv may be NULL.
+ *
+ * Returned Values:
+ * This function does not normally return. exit() is usually called to
+ * terminate the NSH session. This function will return in the event of
+ * an error. In that case, a nonzero value is returned (1).
+ *
+ ****************************************************************************/
+
+EXTERN int nsh_consolemain(int argc, char *argv[]);
+
+/* nsh_telnetstart() starts a telnet daemon that will allow multiple
+ * NSH connections via telnet. This function returns immediately after
+ * the daemon has been started.
+ */
+
+EXTERN int nsh_telnetstart(void);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __APPS_INCLUDE_NSH_H */
diff --git a/apps/include/readline.h b/apps/include/readline.h
new file mode 100644
index 000000000..647778210
--- /dev/null
+++ b/apps/include/readline.h
@@ -0,0 +1,100 @@
+/****************************************************************************
+ * apps/include/readline.h
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * 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 __APPS_INCLUDE_READLINE_H
+#define __APPS_INCLUDE_READLINE_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/****************************************************************************
+ * Pre-Processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: readline
+ *
+ * readline() reads in at most one less than 'buflen' characters from
+ * 'instream' and stores them into the buffer pointed to by 'buf'.
+ * Characters are echoed on 'outstream'. Reading stops after an EOF or a
+ * newline. If a newline is read, it is stored into the buffer. A null
+ * terminator is stored after the last character in the buffer.
+ *
+ * This version of realine assumes that we are reading and writing to
+ * a VT100 console. This will not work well if 'instream' or 'outstream'
+ * corresponds to a raw byte steam.
+ *
+ * This function is inspired by the GNU readline but is an entirely
+ * different creature.
+ *
+ * Input Parameters:
+ * buf - The user allocated buffer to be filled.
+ * buflen - the size of the buffer.
+ * instream - The stream to read characters from
+ * outstream - The stream to each characters to.
+ *
+ * Returned values:
+ * On success, the (positive) number of bytes transferred is returned.
+ * A length of zero would indicated an end of file condition. An failure,
+ * a negated errno value is returned.
+ *
+ **************************************************************************/
+
+EXTERN ssize_t readline(FAR char *buf, int buflen, FILE *instream, FILE *outstream);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __APPS_INCLUDE_READLINE_H */
diff --git a/apps/include/tiff.h b/apps/include/tiff.h
new file mode 100644
index 000000000..378af9fe0
--- /dev/null
+++ b/apps/include/tiff.h
@@ -0,0 +1,465 @@
+/************************************************************************************
+ * apps/include/tiff.h
+ *
+ * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Reference:
+ * "TIFF, Revision 6.0, Final," June 3, 1992, Adobe Developers Association.
+ *
+ * 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 __APPS_INCLUDE_TIFF_H
+#define __APPS_INCLUDE_TIFF_H
+
+/************************************************************************************
+ * Included Files
+ ************************************************************************************/
+
+#include <nuttx/config.h>
+#include <sys/types.h>
+#include <nuttx/nx/nxglib.h>
+
+/************************************************************************************
+ * Pre-Processor Definitions
+ ************************************************************************************/
+/* Configuration ********************************************************************/
+
+/* TIFF File Format Definitions *****************************************************/
+/* Values for the IFD field type */
+
+#define IFD_FIELD_BYTE 1 /* 8-bit unsigned integer */
+#define IFD_FIELD_ASCII 2 /* 8-bit byte that contains a 7-bit ASCII code.
+ * The last byte must be NUL */
+#define IFD_FIELD_SHORT 3 /* 16-bit (2-byte) unsigned integer */
+#define IFD_FIELD_LONG 4 /* 32-bit (4-byte) unsigned integer */
+#define IFD_FIELD_RATIONAL 5 /* Two LONGs: the first represents the
+ * numerator of a fraction, the second the
+ * denominator */
+#define IFD_FIELD_SBYTE 6 /* An 8-bit signed (twos-complement) integer */
+#define IFD_FIELD_UNDEFINED 7 /* An 8-bit byte that may contain anything,
+ * depending on the definition of the field */
+#define IFD_FIELD_SSHORT 8 /* A 16-bit (2-byte) signed (twos-complement)
+ * integer */
+#define IFD_FIELD_SLONG 9 /* A 32-bit (4-byte) signed (twos-complement)
+ * integer */
+#define IFD_FIELD_SRATIONAL 10 /* Two SLONG’s: the first represents the
+ * numerator of a fraction, the second the
+ * denominator */
+#define IFD_FIELD_FLOAT 11 /* Single precision (4-byte) IEEE format */
+#define IFD_FIELD_DOUBLE 12 /* Double precision (8-byte) IEEE format */
+
+/* Values for the IFD tag type */
+
+#define IFD_TAG_NEWSUBFILETYPE 254 /* NewSubfileType, LONG */
+# define TAG_NEWSUBFILETYPE_REDUCED (1 << 0) /* Bit 0: Reduced resolution verson of image */
+# define TAG_NEWSUBFILETYPE_SINGLE (1 << 1) /* Bit 1: Single page of a multi-page image */
+# define TAG_NEWSUBFILETYPE_TRANSP (1 << 2) /* Bit 2: Defines a transparency mask for image */
+#define IFD_TAG_SUBFILETYPE 255 /* SubfileType, SHORT */
+# define TAG_SUBFILETYPE_FULL 1 /* Full-resolution image data */
+# define TAG_SUBFILETYPE_REDUCED 2 /* Reduced-resolution image data */
+# define TAG_SUBFILETYPE_SINGLE 3 /* Single page of a multi-page image */
+#define IFD_TAG_IMAGEWIDTH 256 /* ImageLength, SHORT or LONG (Required) */
+#define IFD_TAG_IMAGELENGTH 257 /* ImageWidth, SHORT or LONG (Required) */
+#define IFD_TAG_BITSPERSAMPLE 258 /* BitsPerSample, SHORT (Required
+ * in greyscale and pallette-color image files) */
+#define IFD_TAG_COMPRESSION 259 /* Compression, SHORT (Required) */
+# define TAG_COMP_NONE 1 /* No compression */
+# define TAG_COMP_CCITT 2 /* CCITT Group 3 1-Dimensional Modified Huffman
+ * run length encoding */
+# define TAG_COMP_T4 3 /* CCITT T.4 bi-level encoding */
+# define TAG_COMP_T6 4 /* CCITT T.6 bi-level encoding */
+# define TAG_COMP_LZW 5 /* LZW */
+# define TAG_COMP_JPEG 6 /* LZW */
+# define TAG_COMP_PACKBITS 32773 /* PackBits compression */
+#define IFD_TAG_PMI 262 /* PhotometricInterpretation, SHORT (Required) */
+# define TAG_PMI_WHITE 0 /* WhiteIsZero */
+# define TAG_PMI_BLACK 1 /* BlackIsZero */
+# define TAG_PMI_RGB 2 /* RGB */
+# define TAG_PMI_PALETTE 3 /* Palette color */
+# define TAG_PMI_TRANSP 4 /* Transparency mask */
+# define TAG_PMI_CMYK 5 /* CMYK */
+# define TAG_PMI_YCbCr 6 /* YCbCr */
+# define TAG_PMI_CIELAB 8 /* 1976 CIE L*a*b* */
+#define IFD_TAG_THRESHHOLDING 263 /* Threshholding, SHORT */
+# define TAG_THRESHHOLD_NONE 1 /* No dithering or halftoning has been applied */
+# define TAG_THRESHHOLD_ORDERED 2 /* Ordered dither or halftone technique has been applied */
+# define TAG_THRESHHOLD_RANDOM 3 /* Randomized process has been applied */
+#define IFD_TAG_CELLWIDTH 264 /* CellWidth, SHORT */
+#define IFD_TAG_CELLLENGTH 265 /* CellLength, SHORT */
+#define IFD_TAG_FILLORDER 266 /* FillOrder, SHORT */
+# define TAG_FILLORDER_HIGH 1 /* Lower column values are stored in the
+ * higher-order bits */
+# define TAG_FILLORDER_LOW 2 /* Lower column values are stored in the
+ * lower-order bits */
+#define IFD_TAG_DOCUMENTNAME 269 /* DocumentName, ASCII */
+#define IFD_TAG_IMAGEDESCRIPTION 270 /* ImageDescription, ASCII */
+#define IFD_TAG_MAKE 271 /* Make, ASCII */
+#define IFD_TAG_MODEL 272 /* Model, ASCII */
+#define IFD_TAG_STRIPOFFSETS 273 /* StripOffsets, SHORT or LONG (Required) */
+#define IFD_TAG_ORIENTATION 274 /* Orientation, SHORT */
+# define TAG_ORIENTATION_TL 1 /* (0,0)=top left */
+# define TAG_ORIENTATION_TR 2 /* (0,0)=top right */
+# define TAG_ORIENTATION_BR 3 /* (0,0)=bottom right */
+# define TAG_ORIENTATION_BL 4 /* (0,0)=bottom left */
+# define TAG_ORIENTATION_LT 5 /* (0,0)=left top */
+# define TAG_ORIENTATION_RT 6 /* (0,0)=right top */
+# define TAG_ORIENTATION_RB 7 /* (0,0)=right bottom */
+# define TAG_ORIENTATION_LB 8 /* (0,0)=left bottom */
+#define IFD_TAG_SAMPLESPERPIXEL 277 /* SamplesPerPixel, SHORT (Required in
+ * RGB full color files) */
+#define IFD_TAG_ROWSPERSTRIP 278 /* RowsPerStrip, SHORT or LONG (Required) */
+#define IFD_TAG_STRIPCOUNTS 279 /* StripByteCounts, SHORT or LONG (Required) */
+#define IFD_TAG_MINSAMPLEVALUE 280 /* MinSampleValue, SHORT */
+#define IFD_TAG_MAXSAMPLEVALUE 281 /* MaxSampleValue, SHORT */
+#define IFD_TAG_XRESOLUTION 282 /* XResolution, RATIONAL (Required) */
+#define IFD_TAG_YRESOLUTION 283 /* YResolution, RATIONAL (Required) */
+#define IFD_TAG_PLANARCONFIG 284 /* PlanarConfiguration, SHORT */
+# define TAG_PLCONFIG_CHUNKY 1 /* Chunky format */
+# define TAG_PLCONFIG_PLANAR 2 /* Planar format */
+#define IFD_TAG_PAGENAME 285 /* PageName, ASCII */
+#define IFD_TAG_XPOSITION 286 /* XPosition, RATIONAL */
+#define IFD_TAG_YPOSITION 287 /* YPosition, RATIONAL */
+#define IFD_TAG_FREEOFFSETS 288 /* FreeOffsets, LONG */
+#define IFD_TAG_FREEBYTECOUNTS 289 /* FreeByteCounts, LONG */
+#define IFD_TAG_GRAYRESPONSEUNIT 290 /* GrayResponseUnit, SHORT */
+# define TAG_GRAYRESPUNIT_10THS 1 /* Number represents tenths of a unit */
+# define TAG_GRAYRESPUNIT_100THS 2 /* Number represents hundredths of a unit */
+# define TAG_GRAYRESPUNIT_1KTHS 3 /* Number represents thousandths of a unit */
+# define TAG_GRAYRESPUNIT_10KTHS 4 /* Number represents ten-thousandths of a unit */
+# define TAG_GRAYRESPUNIT_100KTHS 5 /* Number represents hundred-thousandths of a unit */
+#define IFD_TAG_GRAYRESPONSECURVE 291 /* GrayResponseCurve, SHORT */
+#define IFD_TAG_T4OPTIONS 292 /* T4Options, LONG */
+# define TAG_T4OPTIONS_2D (1 << 0) /* 2-dimensional coding */
+# define TAG_T4OPTIONS_NONE (1 << 1) /* Uncompressed mode */
+# define TAG_T4OPTIONS_FILL (1 << 2) /* Fill bits have been added */
+#define IFD_TAG_T6OPTIONS 293 /* T6Options, LONG */
+# define TAG_T6OPTIONS_NONE (1 << 1) /* Uncompressed mode allowed */
+#define IFD_TAG_RESUNIT 296 /* ResolutionUnit, SHORT (Required) */
+# define TAG_RESUNIT_NONE 1 /* No absolute unit of measurement */
+# define TAG_RESUNIT_INCH 2 /* Inch (default) */
+# define TAG_RESUNIT_CENTIMETER 3 /* Centimeter */
+#define IFD_TAG_PAGENUMBER 297 /* PageNumber, SHORT */
+#define IFD_TAG_TRANSFERFUNCTION 301 /* TransferFunction, SHORT */
+#define IFD_TAG_SOFTWARE 305 /* Software, ASCII */
+#define IFD_TAG_DATETIME 306 /* DateTime, ASCII */
+#define IFD_TAG_ARTIST 315 /* Artist, ASCII */
+#define IFD_TAG_HOSTCOMPUTER 316 /* HostComputer, ASCII */
+#define IFD_TAG_PREDICTOR 317 /* Predictor SHORT */
+# define TAG_PREDICTOR_NONE 1 /* No prediction scheme used before coding */
+# define TAG_PREDICTOR_HORIZ 2 /* Horizontal differencing */
+#define IFD_TAG_WHITEPOINT 318 /* WhitePoint, RATIONAL */
+#define IFD_TAG_PRIMARYCHROMA 319 /* PrimaryChromaticities, RATIONAL */
+#define IFD_TAG_COLORMAP 320 /* ColorMap, SHORT (Required in palette
+ * color image files) */
+#define IFD_TAG_HALFTONEHINTS 321 /* HalftoneHints, SHORT */
+#define IFD_TAG_TILEWIDTH 322 /* TileWidth, SHORT or LONG */
+#define IFD_TAG_TILELENGTH 323 /* TileLength, SHORT or LONG */
+#define IFD_TAG_TILEOFFSETS 324 /* TileOffsets, LONG */
+#define IFD_TAG_TILEBYTECOUNTS 325 /* TileByteCounts, SHORT or LONG */
+#define IFD_TAG_INKSET 332 /* InkSet, SHORT */
+# define TAG_INKSET_CMYK 1 /* CMYK */
+# define TAG_INKSET_OTHER 2 /* Not CMYK */
+#define IFD_TAG_INKNAMES 333 /* InkNames, ASCII */
+#define IFD_TAG_NUMBEROFINKS 334 /* NumberOfInks, SHORT */
+#define IFD_TAG_DOTRANGE 336 /* DotRange, BYTE or SHORT */
+#define IFD_TAG_TARGETPRINTER 337 /* TargetPrinter, ASCII */
+#define IFD_TAG_EXTRASAMPLES 338 /* ExtraSamples, SHORT */
+# define TAG_EXTSAMP_UNSPEC 0 /* Unspecified */
+# define TAG_EXTSAMP_ASSOCALPHA 1 /* Associated alpha data */
+# define TAG_EXTSAMP_UNASSALPHA 2 /* Unassociated alpha data */
+#define IFD_TAG_SAMPLEFORMAT 339 /* SampleFormat, SHORT */
+# define TAG_SAMPLEFMT_UNSIGED 1 /* Unsigned integer data */
+# define TAG_SAMPLEFMT_SIGNED 2 /* Two’s complement signed integer data */
+# define TAG_SAMPLEFMT_FLOAT 3 /* IEEE floating point data */
+# define TAG_SAMPLEFMT_UNDEFINED 4 /* Undefined data format */
+#define IFD_TAG_SMINSAMPLEVALUE 340 /* SMinSampleValue, type matches sample data */
+#define IFD_TAG_SMAXSAMPLEVALUE 341 /* SMaxSampleValue, type matches sample data */
+#define IFD_TAG_TRANSFERRANGE 342 /* TransferRange, SHORT */
+#define IFD_TAG_JPEGPROC 512 /* JPEGProc, SHORT */
+#define IFD_TAG_JPEGFMT 513 /* JPEGInterchangeFormat, LONG */
+#define IFD_TAG_JPEGLENGTH 514 /* JPEGInterchangeFormatLength, LONG */
+#define IFD_TAG_JPEGRESTART 515 /* JPEGRestartInterval, SHORT */
+#define IFD_TAG_JPEGLLPREDICTORS 517 /* JPEGLosslessPredictors, SHORT */
+#define IFD_TAG_JPEGPOINTXFORMS 518 /* JPEGPointTransforms, SHORT */
+#define IFD_TAG_JPEGQTABLES 519 /* JPEGQTables, LONG */
+#define IFD_TAG_JPEGDCTABLES 520 /* JPEGDCTables, LONG */
+#define IFD_TAG_JPEGACTABLES 521 /* JPEGACTables, LONG */
+#define IFD_TAG_YCbCrCOEFFS 529 /* YCbCrCoefficients, RATIONAL */
+#define IFD_TAG_YCbCrSUBSAMPLING 530 /* YCbCrSubSampling, SHORT */
+#define IFD_TAG_YCbCrPOSITIONING 531 /* YCbCrPositioning, SHORT */
+#define IFD_TAG_REFERENCEBW 532 /* ReferenceBlackWhite, RATIONAL */
+#define IFD_TAG_COPYRIGHT 33432 /* Copyright, ASCII */
+
+/************************************************************************************
+ * Public Types
+ ************************************************************************************/
+/* TIFF File Format Structure *******************************************************/
+/* "A TIFF file begins with an 8-byte image file header that points to an
+ * image file directory (IFD). An image file directory contains information
+ * about the image, as well as pointers to the actual image data."
+ */
+
+struct tiff_header_s
+{
+ uint8_t order[2]; /* 0-1: Byte order: "II"=little endian, "MM"=big endian */
+ uint8_t magic[2]; /* 2-3: 42 in appropriate byte order */
+ uint8_t offset[4]; /* 4-7: Offset to the first IFD */
+};
+#define SIZEOF_TIFF_HEADER 8
+
+/* "An Image File Directory (IFD) consists of a 2-byte count of the number
+ * of directory entries (i.e., the number of fields), followed by a sequence
+ * of 12-byte field entries, followed by a 4-byte offset of the next IFD (or
+ * 0 if none).
+ *
+ * Each 12-byte IFD entry has the following format:
+ */
+
+struct tiff_ifdentry_s
+{
+ uint8_t tag[2]; /* 0-1: The Tag that identifies the field */
+ uint8_t type[2]; /* 2-3 The field Type */
+ uint8_t count[4]; /* 4-7: The number of values of the indicated type */
+ uint8_t offset[4]; /* 8-11: The Value Offset (or the value itself) */
+};
+#define SIZEOF_IFD_ENTRY 12
+
+/************************************************************************************/
+/* Structures needed to interface with the TIFF file creation library )and also
+ * structures used only internally by the TIFF file creation library).
+ */
+
+/* This structure describes on strip in tmpfile2 */
+
+struct tiff_strip_s
+{
+ uint32_t offset; /* Offset to the strip data in tmpfile1 */
+ uint32_t count; /* Count of pixels in the strip */
+};
+
+/* This structure is used only internally by the TIFF file creation library to
+ * manage file offsets.
+ */
+
+struct tiff_filefmt_s
+{
+ uint16_t nifdentries; /* Number of IFD entries */
+ uint16_t soifdoffset; /* Offset to StripOffset IFD entry */
+ uint16_t sbcifdoffset; /* Offset to StripByteCount IFD entry */
+ uint16_t valoffset; /* Offset to first values */
+ uint16_t xresoffset; /* Offset to XResolution values */
+ uint16_t yresoffset; /* Offset to yResolution values */
+ uint16_t swoffset; /* Offset to Software string */
+ uint16_t dateoffset; /* Offset to DateTime string */
+ uint16_t sbcoffset; /* Offset to StripByteCount values */
+};
+
+/* These type is used to hold information about the TIFF file under
+ * construction
+ */
+
+struct tiff_info_s
+{
+ /* The first fields are used to pass information to the TIFF file creation
+ * logic via tiff_initialize().
+ *
+ * Filenames. Three file names are required. (1) path to the final
+ * output file and (2) two paths to temporary files. One temporary file
+ * (tmpfile1) will be used to hold the strip image data and the other
+ * (tmpfile2) will be used to hold strip offset and count information.
+ *
+ * colorfmt - Specifies the form of the color data that will be provided
+ * in the strip data. These are the FB_FMT_* definitions
+ * provided in include/nuttx/fb.h. Only the following values
+ * are supported:
+ *
+ * FB_FMT_Y1 BPP=1, monochrome, 0=black
+ * FB_FMT_Y4 BPP=4, 4-bit greyscale, 0=black
+ * FB_FMT_Y8 BPP=8, 8-bit greyscale, 0=black
+ * FB_FMT_RGB16_565 BPP=16 R=6, G=6, B=5
+ * FB_FMT_RGB24 BPP=24 R=8, G=8, B=8
+ *
+ * rps - TIFF RowsPerStrip
+ * imgwidth - TIFF ImageWidth, Number of columns in the image
+ * imgheight - TIFF ImageLength, Number of rows in the image
+ */
+
+ FAR const char *outfile; /* Full path to the final output file name */
+ FAR const char *tmpfile1; /* Full path to first temporary file */
+ FAR const char *tmpfile2; /* Full path to second temporary file */
+
+ uint8_t colorfmt; /* See FB_FMT_* definitions in include/nuttx/fb.h */
+ nxgl_coord_t rps; /* TIFF RowsPerStrip */
+ nxgl_coord_t imgwidth; /* TIFF ImageWidth, Number of columns in the image */
+ nxgl_coord_t imgheight; /* TIFF ImageLength, Number of rows in the image */
+
+ /* The caller must provide an I/O buffer as well. This I/O buffer will
+ * used for color conversions and as the intermediate buffer for copying
+ * files. The larger the buffer, the better the performance.
+ */
+
+ FAR uint8_t *iobuffer; /* IO buffer allocated by the caller */
+ unsigned int iosize; /* The size of the I/O buffer in bytes */
+
+ /* The second set of fields are used only internally by the TIFF file
+ * creation logic. These fields must be set to zero initially by the
+ * caller of tiff_initialize(). User logic should not depend upon any
+ * definitions in the following -- they are subject to change without
+ * notice. They are only exposed here so that the caller can allocate
+ * memory for their storage.
+ */
+
+ uint8_t imgflags; /* Bit-encoded image flags */
+ nxgl_coord_t nstrips; /* Number of strips in tmpfile3 */
+ size_t pps; /* Pixels per strip */
+ size_t bps; /* Bytes per strip */
+ int outfd; /* outfile file descriptor */
+ int tmp1fd; /* tmpfile1 file descriptor */
+ int tmp2fd; /* tmpfile2 file descriptor */
+ off_t outsize; /* Current size of outfile */
+ off_t tmp1size; /* Current size of tmpfile1 */
+ off_t tmp2size; /* Current size of tmpfile2 */
+
+ /* Points to an internal constant structure of file offsets */
+
+ FAR const struct tiff_filefmt_s *filefmt;
+};
+
+/************************************************************************************
+ * Public Function Prototypes
+ ************************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
+/************************************************************************************
+ * Name: tiff_initialize
+ *
+ * Description:
+ * Setup to create a new TIFF file. The overall steps to creating a TIFF file are
+ * as follows:
+ *
+ * 1) Create an initialize a struct tiff_info_s instance
+ * 2) Call tiff_initialize() to setup the file creation
+ * 3) Call tiff_addstrip() repeatedly to add strips to the graphic image
+ * 4) Call tiff_finalize() to complete the file creation.
+ *
+ * Input Parameters:
+ * info - A pointer to the caller allocated parameter passing/TIFF state instance.
+ *
+ * Returned Value:
+ * Zero (OK) on success. A negated errno value on failure.
+ *
+ ************************************************************************************/
+
+EXTERN int tiff_initialize(FAR struct tiff_info_s *info);
+
+/************************************************************************************
+ * Name: tiff_addstrip
+ *
+ * Description:
+ * Add an image data strip. The size of the strip in pixels must be equal to
+ * the RowsPerStrip x ImageWidth values that were provided to tiff_initialize().
+ *
+ * Input Parameters:
+ * info - A pointer to the caller allocated parameter passing/TIFF state instance.
+ * buffer - A buffer containing a single row of data.
+ *
+ * Returned Value:
+ * Zero (OK) on success. A negated errno value on failure.
+ *
+ ************************************************************************************/
+
+EXTERN int tiff_addstrip(FAR struct tiff_info_s *info, FAR const uint8_t *strip);
+
+/************************************************************************************
+ * Name: tiff_finalize
+ *
+ * Description:
+ * Finalize the TIFF output file, completing the TIFF file creation steps.
+ *
+ * Input Parameters:
+ * info - A pointer to the caller allocated parameter passing/TIFF state instance.
+ *
+ * Returned Value:
+ * Zero (OK) on success. A negated errno value on failure.
+ *
+ ************************************************************************************/
+
+EXTERN int tiff_finalize(FAR struct tiff_info_s *info);
+
+/************************************************************************************
+ * Name: tiff_abort
+ *
+ * Description:
+ * Abort the TIFF file creation and create-up resources.
+ *
+ * Input Parameters:
+ * info - A pointer to the caller allocated parameter passing/TIFF state instance.
+ *
+ * Returned Value:
+ * None
+ *
+ ************************************************************************************/
+
+EXTERN void tiff_abort(FAR struct tiff_info_s *info);
+
+/************************************************************************************
+ * Name: tiff_put/get16/32
+ *
+ * Description:
+ * Put and get 16 and 32 values in the correct byte order at the specified position.
+ *
+ * Input Parameters:
+ * dest - The location to store the multi-byte data (put only)
+ * src - The location to get the multi-byte data (get only)
+ *
+ * Returned Value:
+ * None (put)
+ * The extracted value (get)
+ *
+ ************************************************************************************/
+
+EXTERN void tiff_put16(FAR uint8_t *dest, uint16_t value);
+EXTERN void tiff_put32(FAR uint8_t *dest, uint32_t value);
+EXTERN uint16_t tiff_get16(FAR uint8_t *dest);
+EXTERN uint32_t tiff_get32(FAR uint8_t *dest);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __APPS_INCLUDE_TIFF_H */