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
This commit is contained in:
patacongo
2012-09-17 18:18:44 +00:00
commit 57623d42eb
5691 changed files with 1361853 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
#
# For a description of the syntax of this configuration file,
# see misc/tools/kconfig-language.txt.
#
config EXAMPLES_FTPD
bool "FTP server example"
default n
---help---
Enable the FTP server example
if EXAMPLES_FTPD
endif
+101
View File
@@ -0,0 +1,101 @@
############################################################################
# apps/examples/ftpd/Makefile
#
# 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.
#
############################################################################
-include $(TOPDIR)/.config
-include $(TOPDIR)/Make.defs
include $(APPDIR)/Make.defs
# Hello, World! Example
ASRCS =
CSRCS = ftpd_main.c
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
else
BIN = "$(APPDIR)/libapps$(LIBEXT)"
endif
ROOTDEPPATH = --dep-path .
# Common build
VPATH =
all: .built
.PHONY: context clean depend distclean
$(AOBJS): %$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
@( for obj in $(OBJS) ; do \
$(call ARCHIVE, $(BIN), $${obj}); \
done ; )
@touch .built
.context:
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
$(call REGISTER,ftpd_start,SCHED_PRIORITY_DEFAULT,2048,ftpd_start)
$(call REGISTER,ftpd_stop,SCHED_PRIORITY_DEFAULT,2048,ftpd_stop)
@touch $@
endif
context: .context
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
@rm -f *.o *~ .*.swp .built
$(call CLEAN)
distclean: clean
@rm -f Make.dep .depend
-include Make.dep
+157
View File
@@ -0,0 +1,157 @@
/****************************************************************************
* apps/examples/ftpd/ftpd.h
* Interface for the Contiki ftpd.
*
* 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. 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_EXAMPLES_FTPD_FTPD_H
#define __APPS_EXAMPLES_FTPD_FTPD_H
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* CONFIG_EXAMPLES_FTPD_PRIO - Priority of the FTP daemon.
* Default: SCHED_PRIORITY_DEFAULT
* CONFIG_EXAMPLES_FTPD_STACKSIZE - Stack size allocated for the
* FTP daemon. Default: 2048
* CONFIG_EXAMPLES_FTPD_NONETINIT - Define to suppress configuration of the
* network by apps/examples/ftpd. You would need to suppress network
* configuration if the network is configuration prior to running the
* example.
*
* If CONFIG_EXAMPLES_FTPD_NONETINIT is not defined, then the following may
* be specified to customized the network configuration:
*
* CONFIG_EXAMPLE_FTPD_NOMAC - If the hardware has no MAC address of its
* own, define this =y to provide a bogus address for testing.
* CONFIG_EXAMPLE_FTPD_IPADDR - The target IP address. Default 10.0.0.2
* CONFIG_EXAMPLE_FTPD_DRIPADDR - The default router address. Default
* 10.0.0.1
* CONFIG_EXAMPLE_FTPD_NETMASK - The network mask. Default: 255.255.255.0
*/
#ifndef CONFIG_EXAMPLES_FTPD_PRIO
# define CONFIG_EXAMPLES_FTPD_PRIO SCHED_PRIORITY_DEFAULT
#endif
#ifndef CONFIG_EXAMPLES_FTPD_STACKSIZE
# define CONFIG_EXAMPLES_FTPD_STACKSIZE 2048
#endif
#ifndef CONFIG_EXAMPLES_FTPD_CLIENTPRIO
# define CONFIG_EXAMPLES_FTPD_CLIENTPRIO SCHED_PRIORITY_DEFAULT
#endif
#ifndef CONFIG_EXAMPLES_FTPD_CLIENTSTACKSIZE
# define CONFIG_EXAMPLES_FTPD_CLIENTSTACKSIZE 2048
#endif
/* NSH always initializes the network */
#if defined(CONFIG_NSH_BUILTIN_APPS) && !defined(CONFIG_EXAMPLES_FTPD_NONETINIT)
# define CONFIG_EXAMPLES_FTPD_NONETINIT 1
#endif
#ifdef CONFIG_EXAMPLES_FTPD_NONETINIT
# undef CONFIG_EXAMPLE_FTPD_IPADDR
# undef CONFIG_EXAMPLE_FTPD_DRIPADDR
# undef CONFIG_EXAMPLE_FTPD_NETMASK
#else
# ifndef CONFIG_EXAMPLE_FTPD_IPADDR
# define CONFIG_EXAMPLE_FTPD_IPADDR 0x0a000002
# endif
# ifndef CONFIG_EXAMPLE_FTPD_DRIPADDR
# define CONFIG_EXAMPLE_FTPD_DRIPADDR 0x0a000001
# endif
# ifndef CONFIG_EXAMPLE_FTPD_NETMASK
# define CONFIG_EXAMPLE_FTPD_NETMASK 0xffffff00
# endif
#endif
/****************************************************************************
* Public Types
****************************************************************************/
/* This structure describes one entry in a table of accounts */
struct fptd_account_s
{
uint8_t flags;
FAR const char *user;
FAR const char *password;
FAR const char *home;
};
/* To minimize the probability of name collisitions, all FTPD example
* global data is maintained in single structure.
*/
struct ftpd_globals_s
{
bool initialized; /* True: Networking is initialized. The
* network must be initialized only once.
*/
#ifdef CONFIG_NSH_BUILTIN_APPS
volatile bool stop; /* True: Request daemon to exit */
volatile bool running; /* True: The daemon is running */
#endif
pid_t pid; /* Task ID of the FTPD daemon. The value
* -1 is a redundant indication that the
* daemon is not running.
*/
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/* To minimize the probability of name collisitions, all FTPD example
* global data is maintained in a single instance of a structure.
*/
extern struct ftpd_globals_s g_ftpdglob;
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#endif /* __APPS_EXAMPLES_FTPD_FTPD_H */
+292
View File
@@ -0,0 +1,292 @@
/****************************************************************************
* examples/telnetd/shell.c
*
* 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 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.
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sched.h>
#include <errno.h>
#include <debug.h>
#include <netinet/in.h>
#include <apps/netutils/uiplib.h>
#include <apps/netutils/ftpd.h>
#include "ftpd.h"
/****************************************************************************
* Private Data
****************************************************************************/
static const struct fptd_account_s g_ftpdaccounts[] =
{
{ FTPD_ACCOUNTFLAG_SYSTEM, "root", "abc123", NULL },
{ FTPD_ACCOUNTFLAG_GUEST, "ftp", NULL, NULL },
{ FTPD_ACCOUNTFLAG_GUEST, "anonymous", NULL, NULL },
};
#define NACCOUNTS (sizeof(g_ftpdaccounts) / sizeof(struct fptd_account_s))
/****************************************************************************
* Public Data
****************************************************************************/
/* To minimize the probability of name collisitions, all FTPD example
* global data is maintained in a single instance of a structure.
*/
struct ftpd_globals_s g_ftpdglob;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: fptd_netinit
****************************************************************************/
static void fptd_netinit(void)
{
#ifndef CONFIG_EXAMPLES_FTPD_NONETINIT
struct in_addr addr;
#ifdef CONFIG_EXAMPLE_FTPD_NOMAC
uint8_t mac[IFHWADDRLEN];
#endif
/* Many embedded network interfaces must have a software assigned MAC */
#ifdef CONFIG_EXAMPLE_FTPD_NOMAC
mac[0] = 0x00;
mac[1] = 0xe0;
mac[2] = 0xde;
mac[3] = 0xad;
mac[4] = 0xbe;
mac[5] = 0xef;
uip_setmacaddr("eth0", mac);
#endif
/* Set up our host address */
addr.s_addr = HTONL(CONFIG_EXAMPLE_FTPD_IPADDR);
uip_sethostaddr("eth0", &addr);
/* Set up the default router address */
addr.s_addr = HTONL(CONFIG_EXAMPLE_FTPD_DRIPADDR);
uip_setdraddr("eth0", &addr);
/* Setup the subnet mask */
addr.s_addr = HTONL(CONFIG_EXAMPLE_FTPD_NETMASK);
uip_setnetmask("eth0", &addr);
#endif /* CONFIG_EXAMPLES_FTPD_NONETINIT */
}
/****************************************************************************
* Name: ftpd_accounts
****************************************************************************/
static void ftpd_accounts(FTPD_SESSION handle)
{
FAR const struct fptd_account_s *account;
int i;
printf("Adding accounts:\n");
for (i = 0; i < NACCOUNTS; i++)
{
account = &g_ftpdaccounts[i];
printf("%d. %s account: USER=%s PASSWORD=%s HOME=%s\n", i+1,
(account->flags & FTPD_ACCOUNTFLAG_SYSTEM) != 0 ? "Root" : "User",
(!account->user) ? "(none)" : account->user,
(!account->password) ? "(none)" : account->password,
(!account->home) ? "(none)" : account->home);
ftpd_adduser(handle, account->flags, account->user,
account->password, account->home);
}
}
/****************************************************************************
* Name: ftpd_daemon
****************************************************************************/
int ftpd_daemon(int s_argc, char **s_argv)
{
FTPD_SESSION handle;
int ret;
/* The FTPD daemon has been started */
#ifdef CONFIG_NSH_BUILTIN_APPS
g_ftpdglob.running = true;
#endif
printf("FTP daemon [%d] started\n", g_ftpdglob.pid);
/* Open FTPD */
handle = ftpd_open();
if (!handle)
{
printf("FTP daemon [%d] failed to open FTPD\n", g_ftpdglob.pid);
#ifdef CONFIG_NSH_BUILTIN_APPS
g_ftpdglob.running = false;
g_ftpdglob.stop = false;
#endif
g_ftpdglob.pid = -1;
return EXIT_FAILURE;
}
/* Configure acounts */
(void)ftpd_accounts(handle);
/* Then drive the FTPD server. */
#ifdef CONFIG_NSH_BUILTIN_APPS
while (g_ftpdglob.stop == 0)
#else
for (;;)
#endif
{
/* If ftpd_session returns success, it means that a new FTP session
* has been started.
*/
ret = ftpd_session(handle, 5000);
/* If any interesting happened (i.e., any thing other than a timeout),
* then report the interesting event.
*/
if (ret != -ETIMEDOUT)
{
printf("FTP daemon [%d] ftpd_session returned %d\n", g_ftpdglob.pid, ret);
}
}
/* Close the FTPD server and exit (we can get here only if
* CONFIG_NSH_BUILTIN_APPS is defined).
*/
#ifdef CONFIG_NSH_BUILTIN_APPS
printf("FTP daemon [%d] stopping\n", g_ftpdglob.pid);
g_ftpdglob.running = false;
g_ftpdglob.stop = false;
g_ftpdglob.pid = -1;
ftpd_close(handle);
#endif
return EXIT_SUCCESS;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: ftpd_main
****************************************************************************/
int ftpd_main(int s_argc, char **s_argv)
{
/* Check if we have already initialized the network */
if (!g_ftpdglob.initialized)
{
/* Bring up the network */
printf("Initializing the network\n");
fptd_netinit();
/* Initialize daemon state */
g_ftpdglob.initialized = true;
g_ftpdglob.pid = -1;
#ifdef CONFIG_NSH_BUILTIN_APPS
g_ftpdglob.stop = false;
g_ftpdglob.running = false;
#endif
}
/* Then start the new daemon (if it is not already running) */
#ifdef CONFIG_NSH_BUILTIN_APPS
if (g_ftpdglob.stop && g_ftpdglob.running)
{
printf("Waiting for FTP daemon [%d] to stop\n", g_ftpdglob.pid);
return EXIT_FAILURE;
}
else
#endif
if (!g_ftpdglob.running)
{
printf("Starting the FTP daemon\n");
g_ftpdglob.pid = TASK_CREATE("FTP daemon", CONFIG_EXAMPLES_FTPD_PRIO,
CONFIG_EXAMPLES_FTPD_STACKSIZE,
ftpd_daemon, NULL);
if (g_ftpdglob.pid < 0)
{
printf("Failed to start the FTP daemon: %d\n", errno);
return EXIT_FAILURE;
}
}
else
{
printf("FTP daemon [%d] is running\n", g_ftpdglob.pid);
}
return EXIT_SUCCESS;
}
/****************************************************************************
* Name: ftpd_stop
****************************************************************************/
#ifdef CONFIG_NSH_BUILTIN_APPS
int ftpd_stop(int s_argc, char **s_argv)
{
if (!g_ftpdglob.initialized || !g_ftpdglob.running)
{
printf("The FTP daemon not running\n");
return EXIT_FAILURE;
}
printf("Stopping the FTP daemon, pid=%d\n", g_ftpdglob.pid);
g_ftpdglob.stop = true;
return EXIT_SUCCESS;
}
#endif