From 523d7645c4ac02f79c793b536f93f58bd5452a4f Mon Sep 17 00:00:00 2001 From: Simon Piriou Date: Sun, 21 May 2017 16:24:49 +0200 Subject: [PATCH 1/8] wapi: add basic wapi_event_stream_extract implementation --- nshlib/Makefile | 2 ++ wireless/wapi/src/wireless.c | 59 ++++++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/nshlib/Makefile b/nshlib/Makefile index 6490d74ee..47ea7ab9f 100644 --- a/nshlib/Makefile +++ b/nshlib/Makefile @@ -75,8 +75,10 @@ endif ifeq ($(CONFIG_NET),y) CSRCS += nsh_netinit.c nsh_netcmds.c ifeq ($(CONFIG_WIRELESS_WAPI),y) +ifeq ($(CONFIG_NSH_NETINIT),y) CSRCS += nsh_associate.c endif +endif ifeq ($(CONFIG_NET_ROUTE),y) CSRCS += nsh_routecmds.c endif diff --git a/wireless/wapi/src/wireless.c b/wireless/wapi/src/wireless.c index f76cd250b..c45dea472 100644 --- a/wireless/wapi/src/wireless.c +++ b/wireless/wapi/src/wireless.c @@ -224,7 +224,57 @@ static int wapi_event_stream_extract(FAR struct wapi_event_stream_s *stream, { #warning Missing logic // return iw_extract_event_stream((struct stream_descr *)stream, iwe, 0); -return -ENOSYS; + + int ret; + struct iw_event *iwe_stream; + + if (stream->current + offsetof(struct iw_event, u) > stream->end) + { + /* Nothing to process */ + + return 0; + } + + iwe_stream = (struct iw_event*)stream->current; + + if (stream->current + iwe_stream->len > stream->end || + iwe_stream->len < offsetof(struct iw_event, u)) + { + return -1; + } + + ret = 1; + + switch (iwe_stream->cmd) + { + case SIOCGIWESSID: + case IWEVGENIE: + iwe->cmd = iwe_stream->cmd; + iwe->len = offsetof(struct iw_event, u) + sizeof(struct iw_point); + iwe->u.data.flags = iwe_stream->u.data.flags; + iwe->u.data.length = iwe_stream->u.data.length; + + iwe->u.data.pointer = (FAR void*)(stream->current + + offsetof(struct iw_event, u) + + (unsigned long)iwe_stream->u.data.pointer); + break; + + default: + if (iwe_stream->len > sizeof(*iwe)) + { + WAPI_ERROR("Unhandled event size 0x%x %d\n", iwe_stream->cmd, + iwe_stream->len); + iwe->cmd = 0; + iwe->len = offsetof(struct iw_event, u); + break; + } + memcpy(iwe, iwe_stream, iwe_stream->len); + } + + /* Update stream to next event */ + + stream->current += iwe_stream->len; + return ret; } /**************************************************************************** @@ -1113,6 +1163,8 @@ alloc: return -errcode; } + printf("got %d bytes\n", wrq.u.data.length); + /* We have the results, process them. */ if (wrq.u.data.length) @@ -1125,7 +1177,8 @@ alloc: { /* Get the next event from the stream */ - if ((ret = wapi_event_stream_extract(&stream, &iwe)) >= 0) + ret = wapi_event_stream_extract(&stream, &iwe); + if (ret > 0) { int eventret = wapi_scan_event(&iwe, aps); if (eventret < 0) @@ -1133,7 +1186,7 @@ alloc: ret = eventret; } } - else + else if (ret < 0) { WAPI_ERROR("ERROR: wapi_event_stream_extract() failed!\n"); } From 2984fa3911196de3d857fdaa16da54ed052e7293 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 21 May 2017 10:51:26 -0600 Subject: [PATCH 2/8] apps/system/dhcpc: Add a command to renew or establish a lease on an IPv4 address. --- examples/buttons/Kconfig | 6 +- netutils/dhcpc/dhcpc.c | 1 + system/dhcpc/.gitignore | 11 +++ system/dhcpc/Kconfig | 32 +++++++++ system/dhcpc/Make.defs | 40 +++++++++++ system/dhcpc/Makefile | 142 ++++++++++++++++++++++++++++++++++++++ system/dhcpc/dhcpc_main.c | 138 ++++++++++++++++++++++++++++++++++++ 7 files changed, 367 insertions(+), 3 deletions(-) create mode 100644 system/dhcpc/.gitignore create mode 100644 system/dhcpc/Kconfig create mode 100644 system/dhcpc/Make.defs create mode 100644 system/dhcpc/Makefile create mode 100644 system/dhcpc/dhcpc_main.c diff --git a/examples/buttons/Kconfig b/examples/buttons/Kconfig index 96910293c..32a9e5aed 100644 --- a/examples/buttons/Kconfig +++ b/examples/buttons/Kconfig @@ -21,15 +21,15 @@ config EXAMPLES_BUTTONS_PROGNAME program is installed. config EXAMPLES_BUTTONS_PRIORITY - int "LED task priority" + int "Button task priority" default 100 config EXAMPLES_BUTTONS_STACKSIZE - int "LED stack size" + int "Button stack size" default 2048 config EXAMPLES_BUTTONS_DEVPATH - string "LED device path" + string "Button device path" default "/dev/buttons" config EXAMPLES_BUTTONS_NAMES diff --git a/netutils/dhcpc/dhcpc.c b/netutils/dhcpc/dhcpc.c index 0f900df44..9f4c7e52d 100644 --- a/netutils/dhcpc/dhcpc.c +++ b/netutils/dhcpc/dhcpc.c @@ -541,6 +541,7 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult) { return ERROR; } + retries++; /* Get the ACK/NAK response to the REQUEST (or timeout) */ diff --git a/system/dhcpc/.gitignore b/system/dhcpc/.gitignore new file mode 100644 index 000000000..fa1ec7579 --- /dev/null +++ b/system/dhcpc/.gitignore @@ -0,0 +1,11 @@ +/Make.dep +/.depend +/.built +/*.asm +/*.obj +/*.rel +/*.lst +/*.sym +/*.adb +/*.lib +/*.src diff --git a/system/dhcpc/Kconfig b/system/dhcpc/Kconfig new file mode 100644 index 000000000..51d59bf22 --- /dev/null +++ b/system/dhcpc/Kconfig @@ -0,0 +1,32 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config SYSTEM_DHCPC + bool "DHCP Address Renewal" + default n + select NETUTILS_DHCPC + depends on NET_UDP && NET_BROADCAST && NET_IPv4 + ---help--- + Enble the DHCP client 'renew' command + +if SYSTEM_DHCPC + +config SYSTEM_DHCPC_PROGNAME + string "Program name" + default "renew" + depends on BUILD_KERNEL + ---help--- + This is the name of the program that will be use when the NSH ELF + program is installed. + +config SYSTEM_DHCPC_PRIORITY + int "DHCPC task priority" + default 100 + +config SYSTEM_DHCPC_STACKSIZE + int "DHCPC stack size" + default 2048 + +endif diff --git a/system/dhcpc/Make.defs b/system/dhcpc/Make.defs new file mode 100644 index 000000000..7e559c2a2 --- /dev/null +++ b/system/dhcpc/Make.defs @@ -0,0 +1,40 @@ +############################################################################ +# apps/system/dhcpc/Make.defs +# Adds selected applications to apps/ build +# +# Copyright (C) 2017 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ + +ifeq ($(CONFIG_SYSTEM_DHCPC),y) +CONFIGURED_APPS += system/dhcpc +endif + diff --git a/system/dhcpc/Makefile b/system/dhcpc/Makefile new file mode 100644 index 000000000..935277acf --- /dev/null +++ b/system/dhcpc/Makefile @@ -0,0 +1,142 @@ +############################################################################ +# apps/system/dhcpc/Makefile +# +# Copyright (C) 2017 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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 + +# DHCPC address renewal built-in application info + +CONFIG_SYSTEM_DHCPC_PRIORITY ?= SCHED_PRIORITY_DEFAULT +CONFIG_SYSTEM_DHCPC_STACKSIZE ?= 2048 + +APPNAME = renew +PRIORITY = $(CONFIG_SYSTEM_DHCPC_PRIORITY) +STACKSIZE = $(CONFIG_SYSTEM_DHCPC_STACKSIZE) + +CONFIG_SYSTEM_DHCPC_PROGNAME ?= renew$(EXEEXT) +PROGNAME = $(CONFIG_SYSTEM_DHCPC_PROGNAME) + +# DHCPC address renewal + +ASRCS = +CSRCS = +MAINSRC = dhcpc_main.c + +AOBJS = $(ASRCS:.S=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) +MAINOBJ = $(MAINSRC:.c=$(OBJEXT)) + +SRCS = $(ASRCS) $(CSRCS) $(MAINSRC) +OBJS = $(AOBJS) $(COBJS) + +ifneq ($(CONFIG_BUILD_KERNEL),y) + OBJS += $(MAINOBJ) +endif + +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + BIN = ..\..\libapps$(LIBEXT) +else +ifeq ($(WINTOOL),y) + BIN = ..\\..\\libapps$(LIBEXT) +else + BIN = ../../libapps$(LIBEXT) +endif +endif + +ifeq ($(WINTOOL),y) + INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}" +else + INSTALL_DIR = $(BIN_DIR) +endif + +ROOTDEPPATH = --dep-path . + +# Common build + +VPATH = + +all: .built +.PHONY: clean depend distclean + +$(AOBJS): %$(OBJEXT): %.S + $(call ASSEMBLE, $<, $@) + +$(COBJS) $(MAINOBJ): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +.built: $(OBJS) + $(call ARCHIVE, $(BIN), $(OBJS)) + @touch .built + +ifeq ($(CONFIG_BUILD_KERNEL),y) +$(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(MAINOBJ) + @echo "LD: $(PROGNAME)" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME) $(ARCHCRT0OBJ) $(MAINOBJ) $(LDLIBS) + $(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME) + +install: $(BIN_DIR)$(DELIM)$(PROGNAME) + +else +install: + +endif + +ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) +$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile + $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) + +context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat +else +context: +endif + +.depend: Makefile $(SRCS) + @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + @touch $@ + +depend: .depend + +clean: + $(call DELFILE, .built) + $(call CLEAN) + +distclean: clean + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) + +-include Make.dep +.PHONY: preconfig +preconfig: diff --git a/system/dhcpc/dhcpc_main.c b/system/dhcpc/dhcpc_main.c new file mode 100644 index 000000000..fd3deec1c --- /dev/null +++ b/system/dhcpc/dhcpc_main.c @@ -0,0 +1,138 @@ +/**************************************************************************** + * system/dhcpc/dhcpc_main.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#include "netutils/netlib.h" +#include "netutils/dhcpc.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * dhcpc_showusage + ****************************************************************************/ + +static void dhcpc_showusage(FAR const char *progname, int exitcode) +{ + fprintf(stderr, "Usage: %s \n"); + exit(exitcode); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * dhcpc_main + ****************************************************************************/ + +#ifdef CONFIG_BUILD_KERNEL +int main(int argc, FAR char *argv[]) +#else +int dhcpc_main(int argc, char *argv[]) +#endif +{ + FAR const char *devname; + FAR void *handle; + uint8_t mac[IFHWADDRLEN]; + struct dhcpc_state ds; + int ret; + + /* One and only one argument is expected: The network device name. */ + + if (argc != 2) + { + fprintf(stderr, "ERROR: Invalid number of arguments\n"); + dhcpc_showusage(argv[0], EXIT_FAILURE); + } + + devname = argv[1]; + + /* Get the MAC address of the NIC */ + + netlib_getmacaddr(devname, mac); + + /* Set up the DHCPC modules */ + + handle = dhcpc_open(devname, &mac, IFHWADDRLEN); + if (handle == NULL) + { + fprintf(stderr, "ERROR: dhcpc_open() for '%s' failed\n", devname); + return EXIT_FAILURE; + } + + /* Get an IP address. */ + + ret = dhcpc_request(handle, &ds); + if (ret < 0) + { + (void)dhcpc_close(handle); + fprintf(stderr, "ERROR: dhcpc_request() failed\n"); + return EXIT_FAILURE; + } + + /* Save the addresses that we obtained. */ + + netlib_set_ipv4addr(devname, &ds.ipaddr); + + if (ds.netmask.s_addr != 0) + { + netlib_set_ipv4netmask(devname, &ds.netmask); + } + + if (ds.default_router.s_addr != 0) + { + netlib_set_dripv4addr(devname, &ds.default_router); + } + + if (ds.dnsaddr.s_addr != 0) + { + netlib_set_ipv4dnsaddr(&ds.dnsaddr); + } + + dhcpc_close(handle); + return EXIT_SUCCESS; +} From da9f0421c002532d8a62197f5edc7a1ba7d6afdb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 21 May 2017 10:53:45 -0600 Subject: [PATCH 3/8] apps/system/dhcpc: Currently only works with IPv4 and Ethernet MAC. --- system/dhcpc/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/dhcpc/Kconfig b/system/dhcpc/Kconfig index 51d59bf22..9b88c0392 100644 --- a/system/dhcpc/Kconfig +++ b/system/dhcpc/Kconfig @@ -7,7 +7,7 @@ config SYSTEM_DHCPC bool "DHCP Address Renewal" default n select NETUTILS_DHCPC - depends on NET_UDP && NET_BROADCAST && NET_IPv4 + depends on NET_UDP && NET_BROADCAST && NET_IPv4 && NET_ETHERNET ---help--- Enble the DHCP client 'renew' command From c1a64d0cad68ab2da2b9948731aa1710fef250ab Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 21 May 2017 11:26:16 -0600 Subject: [PATCH 4/8] apps/system/ntpc: Add a command to start or stop the NTPC daemon. --- system/ntpc/.gitignore | 11 +++ system/ntpc/Kconfig | 25 ++++++ system/ntpc/Make.defs | 39 +++++++++ system/ntpc/Makefile | 155 +++++++++++++++++++++++++++++++++++ system/ntpc/ntpcstart_main.c | 70 ++++++++++++++++ system/ntpc/ntpcstop_main.c | 70 ++++++++++++++++ 6 files changed, 370 insertions(+) create mode 100644 system/ntpc/.gitignore create mode 100644 system/ntpc/Kconfig create mode 100644 system/ntpc/Make.defs create mode 100644 system/ntpc/Makefile create mode 100644 system/ntpc/ntpcstart_main.c create mode 100644 system/ntpc/ntpcstop_main.c diff --git a/system/ntpc/.gitignore b/system/ntpc/.gitignore new file mode 100644 index 000000000..fa1ec7579 --- /dev/null +++ b/system/ntpc/.gitignore @@ -0,0 +1,11 @@ +/Make.dep +/.depend +/.built +/*.asm +/*.obj +/*.rel +/*.lst +/*.sym +/*.adb +/*.lib +/*.src diff --git a/system/ntpc/Kconfig b/system/ntpc/Kconfig new file mode 100644 index 000000000..c9f6b52e3 --- /dev/null +++ b/system/ntpc/Kconfig @@ -0,0 +1,25 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config SYSTEM_NTPC + bool "NTP Daemon Commands" + default n + select NETUTILS_NTPCLIENT + depends on NET_UDP + ---help--- + Enble the NTP client 'start' and 'stop' commands + + +if SYSTEM_NTPC + +config SYSTEM_NTPC_PRIORITY + int "NTPC task priority" + default 100 + +config SYSTEM_NTPC_STACKSIZE + int "NTPC stack size" + default 2048 + +endif diff --git a/system/ntpc/Make.defs b/system/ntpc/Make.defs new file mode 100644 index 000000000..07ab398c9 --- /dev/null +++ b/system/ntpc/Make.defs @@ -0,0 +1,39 @@ +############################################################################ +# apps/system/ntpc/Make.defs +# Adds selected applications to apps/ build +# +# Copyright (C) 2017 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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. +# +############################################################################ + +ifeq ($(CONFIG_SYSTEM_NTPC),y) +CONFIGURED_APPS += system/ntpc +endif diff --git a/system/ntpc/Makefile b/system/ntpc/Makefile new file mode 100644 index 000000000..f30857d41 --- /dev/null +++ b/system/ntpc/Makefile @@ -0,0 +1,155 @@ +############################################################################ +# apps/system/ntpc/Makefile +# +# Copyright (C) 2017 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# 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 + +# NTPC address renewal built-in application info + +CONFIG_SYSTEM_NTPC_PRIORITY ?= SCHED_PRIORITY_DEFAULT +CONFIG_SYSTEM_NTPC_STACKSIZE ?= 2048 + +APPNAME1 = ntpstart +APPNAME2 = ntpstop +PRIORITY = $(CONFIG_SYSTEM_NTPC_PRIORITY) +STACKSIZE = $(CONFIG_SYSTEM_NTPC_STACKSIZE) + +PROGNAME1 = ntpstart$(EXEEXT) +PROGNAME2 = ntpstop$(EXEEXT) + +# NTPC address renewal + +ASRCS = +CSRCS = +MAINSRC1 = ntpcstart_main.c +MAINSRC2 = ntpcstop_main.c +MAINSRC = $(MAINSRC1) $(MAINSRC2) + +AOBJS = $(ASRCS:.S=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) +MAINOBJ1 = $(MAINSRC1:.c=$(OBJEXT)) +MAINOBJ2 = $(MAINSRC2:.c=$(OBJEXT)) +MAINOBJ = $(MAINOBJ1) $(MAINOBJ2) + +SRCS = $(ASRCS) $(CSRCS) $(MAINSRC) +OBJS = $(AOBJS) $(COBJS) + +ifneq ($(CONFIG_BUILD_KERNEL),y) + OBJS += $(MAINOBJ) +endif + +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + BIN = ..\..\libapps$(LIBEXT) +else +ifeq ($(WINTOOL),y) + BIN = ..\\..\\libapps$(LIBEXT) +else + BIN = ../../libapps$(LIBEXT) +endif +endif + +ifeq ($(WINTOOL),y) + INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}" +else + INSTALL_DIR = $(BIN_DIR) +endif + +ROOTDEPPATH = --dep-path . + +# Common build + +VPATH = + +all: .built +.PHONY: clean depend distclean + +$(AOBJS): %$(OBJEXT): %.S + $(call ASSEMBLE, $<, $@) + +$(COBJS) $(MAINOBJ): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +.built: $(OBJS) + $(call ARCHIVE, $(BIN), $(OBJS)) + @touch .built + +ifeq ($(CONFIG_BUILD_KERNEL),y) +$(BIN_DIR)$(DELIM)$(PROGNAME1): $(OBJS) $(MAINOBJ1) + @echo "LD: $(PROGNAME1)" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME1) $(ARCHCRT0OBJ) $(MAINOBJ1) $(LDLIBS) + $(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME1) + +$(BIN_DIR)$(DELIM)$(PROGNAME2): $(OBJS) $(MAINOBJ2) + @echo "LD: $(PROGNAME2)" + $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME2) $(ARCHCRT0OBJ) $(MAINOBJ2) $(LDLIBS) + $(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME2) + +install: $(BIN_DIR)$(DELIM)$(PROGNAME1) $(BIN_DIR)$(DELIM)$(PROGNAME2) + +else +install: + +endif + +ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) +$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME1)_main.bdat: $(DEPCONFIG) Makefile + $(call REGISTER,$(APPNAME1),$(PRIORITY),$(STACKSIZE),$(APPNAME1)_main) + +$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME2)_main.bdat: $(DEPCONFIG) Makefile + $(call REGISTER,$(APPNAME2),$(PRIORITY),$(STACKSIZE),$(APPNAME2)_main) + +context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME1)_main.bdat $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME2)_main.bdat +else +context: +endif + +.depend: Makefile $(SRCS) + @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + @touch $@ + +depend: .depend + +clean: + $(call DELFILE, .built) + $(call CLEAN) + +distclean: clean + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) + +-include Make.dep +.PHONY: preconfig +preconfig: diff --git a/system/ntpc/ntpcstart_main.c b/system/ntpc/ntpcstart_main.c new file mode 100644 index 000000000..43ae234c7 --- /dev/null +++ b/system/ntpc/ntpcstart_main.c @@ -0,0 +1,70 @@ +/**************************************************************************** + * system/ntpc/ntpcstart_main.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include "netutils/ntpclient.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * ntpcstart_main + ****************************************************************************/ + +#ifdef CONFIG_BUILD_KERNEL +int main(int argc, FAR char *argv[]) +#else +int ntpcstart_main(int argc, char *argv[]) +#endif +{ + int pid = ntpc_start(); + if (pid < 0) + { + fprintf(stderr, "ERROR: ntpc_start() failed\n"); + return EXIT_FAILURE; + } + + printf("Started the NTP daemon as PID=%d\n", pid); + return EXIT_SUCCESS; +} diff --git a/system/ntpc/ntpcstop_main.c b/system/ntpc/ntpcstop_main.c new file mode 100644 index 000000000..06627efaf --- /dev/null +++ b/system/ntpc/ntpcstop_main.c @@ -0,0 +1,70 @@ +/**************************************************************************** + * system/ntpc/ntpc_main.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include "netutils/ntpclient.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * ntpcstop_main + ****************************************************************************/ + +#ifdef CONFIG_BUILD_KERNEL +int main(int argc, FAR char *argv[]) +#else +int ntpcstop_main(int argc, char *argv[]) +#endif +{ + int ret = ntpc_stop(); + if (ret < 0) + { + fprintf(stderr, "ERROR: ntpc_stop() failed\n"); + return EXIT_FAILURE; + } + + printf("Stopped the NTP daemon\n"); + return EXIT_SUCCESS; +} From ccb6282f5b33e7c20aae3573f19801b4d37a27af Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 21 May 2017 11:32:07 -0600 Subject: [PATCH 5/8] apps/system/dhcpc: Add missing argument of fprintf. --- system/dhcpc/dhcpc_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/dhcpc/dhcpc_main.c b/system/dhcpc/dhcpc_main.c index fd3deec1c..496a9a0e8 100644 --- a/system/dhcpc/dhcpc_main.c +++ b/system/dhcpc/dhcpc_main.c @@ -57,7 +57,7 @@ static void dhcpc_showusage(FAR const char *progname, int exitcode) { - fprintf(stderr, "Usage: %s \n"); + fprintf(stderr, "Usage: %s \n", progname); exit(exitcode); } From 8c1446671c4310e6837830888c39d5c66839648b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 21 May 2017 12:00:55 -0600 Subject: [PATCH 6/8] apps/nshlib: Add a new option CONFIG_NSH_NETLOCAL that will suppress some built in operations and will support manual configuration of a wireless network --- nshlib/Kconfig | 26 +++++++++++++++++++++++++- nshlib/Makefile | 4 ++++ nshlib/nsh_netinit.c | 13 ++++++++----- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/nshlib/Kconfig b/nshlib/Kconfig index e3dd1fbae..deb9afa4c 100644 --- a/nshlib/Kconfig +++ b/nshlib/Kconfig @@ -1009,10 +1009,34 @@ config NSH_NETINIT if NSH_NETINIT +config NSH_NETLOCAL + bool "Local network initialization" + default n + ---help--- + If this option is selected, then NSH will only initialize the local + attributes of the network: The MAC address is needed and any IP + addresses as needed. More importantly, it will not do the following: + + - It will not bring the netup up. The can be done later with the + NSH ifup command. + - It will not associate any wireless devices to an access point. + - It will not attempt to obtain an IP address if DHCPC is selected. + This may be done later from the NSH command line with the + apps/system/dhcpc 'renew' command. + - It will not start the NTPC daemon. This may be done later from + the NSH command line with the apps/system/ntpc 'ntpcstart' command. + + This option permits you to divid the network configuration into two + parts: The local configuration of the network device and the dynamic + configuration of the device in the network. This may be important in + an environment when, for example, you need to manually scan for + available access points and associate the wireless driver with an + access point. + config NSH_NETINIT_THREAD bool "Network initialization thread" default n - depends on !DISABLE_PTHREAD + depends on !DISABLE_PTHREAD && !NSH_NETLOCAL ---help--- NSH is brought up through a series of sequential initialization steps. This includes networking. If the network is available on diff --git a/nshlib/Makefile b/nshlib/Makefile index 47ea7ab9f..50adedf40 100644 --- a/nshlib/Makefile +++ b/nshlib/Makefile @@ -74,11 +74,15 @@ endif ifeq ($(CONFIG_NET),y) CSRCS += nsh_netinit.c nsh_netcmds.c + ifeq ($(CONFIG_WIRELESS_WAPI),y) ifeq ($(CONFIG_NSH_NETINIT),y) +ifneq ($(CONFIG_NSH_NETLOCAL),y) CSRCS += nsh_associate.c endif endif +endif + ifeq ($(CONFIG_NET_ROUTE),y) CSRCS += nsh_routecmds.c endif diff --git a/nshlib/nsh_netinit.c b/nshlib/nsh_netinit.c index 00a952877..d030bf7d4 100644 --- a/nshlib/nsh_netinit.c +++ b/nshlib/nsh_netinit.c @@ -248,11 +248,12 @@ static void nsh_netinit_configure(void) struct in_addr addr; #endif -#if defined(CONFIG_NSH_DHCPC) +#if defined(CONFIG_NSH_DHCPC) && !defined(CONFIG_NSH_NETLOCAL) FAR void *handle; #endif -#if (defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_NOMAC)) && defined(HAVE_MAC) +#if (((defined(CONFIG_NSH_DHCPC) && !defined(CONFIG_NSH_NETLOCAL)) || \ + defined(CONFIG_NSH_NOMAC)) && defined(HAVE_MAC)) #if defined(CONFIG_NET_ETHERNET) uint8_t mac[IFHWADDRLEN]; #elif defined(CONFIG_NET_6LOWPAN) @@ -358,9 +359,10 @@ static void nsh_netinit_configure(void) netlib_set_ipv4dnsaddr(&addr); #endif - /* New versions of netlib_set_ipvXaddr will not bring the network up, - * So ensure the network is really up at this point. - */ + /* That completes the 'local' initialization of the network device. */ + +#ifndef CONFIG_NSH_NETLOCAL + /* Bring the network up. */ netlib_ifup("eth0"); @@ -413,6 +415,7 @@ static void nsh_netinit_configure(void) ntpc_start(); #endif +#endif /* CONFIG_NSH_NETLOCAL */ #endif /* NSH_HAVE_NETDEV */ ninfo("Exit\n"); From 4e7b17d78307c5b47d8b7e8a531d1378fd0e52df Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 21 May 2017 12:05:07 -0600 Subject: [PATCH 7/8] Fix some typos in comments. --- nshlib/Kconfig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nshlib/Kconfig b/nshlib/Kconfig index deb9afa4c..3337e2995 100644 --- a/nshlib/Kconfig +++ b/nshlib/Kconfig @@ -1014,10 +1014,10 @@ config NSH_NETLOCAL default n ---help--- If this option is selected, then NSH will only initialize the local - attributes of the network: The MAC address is needed and any IP + attributes of the network: The MAC address if needed and any IP addresses as needed. More importantly, it will not do the following: - - It will not bring the netup up. The can be done later with the + - It will not bring the network up. That can be done later with the NSH ifup command. - It will not associate any wireless devices to an access point. - It will not attempt to obtain an IP address if DHCPC is selected. @@ -1026,7 +1026,7 @@ config NSH_NETLOCAL - It will not start the NTPC daemon. This may be done later from the NSH command line with the apps/system/ntpc 'ntpcstart' command. - This option permits you to divid the network configuration into two + This option permits you to divide the network configuration into two parts: The local configuration of the network device and the dynamic configuration of the device in the network. This may be important in an environment when, for example, you need to manually scan for From d9805d38e2b98e75b3f03335ca6c5f9332ec2fcb Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 21 May 2017 12:12:45 -0600 Subject: [PATCH 8/8] apps/system/ramtest: Make stacksize and priority conigurable. --- system/ramtest/Kconfig | 20 ++++++++++++++++++++ system/ramtest/Makefile | 22 +++++++++++++--------- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/system/ramtest/Kconfig b/system/ramtest/Kconfig index b02a9bcdb..7c78efbb9 100644 --- a/system/ramtest/Kconfig +++ b/system/ramtest/Kconfig @@ -8,3 +8,23 @@ config SYSTEM_RAMTEST default n ---help--- Enable a simple RAM test. + +if SYSTEM_RAMTEST + +config SYSTEM_RAMTEST_PROGNAME + string "Program name" + default "ramtest" + depends on BUILD_KERNEL + ---help--- + This is the name of the program that will be use when the NSH ELF + program is installed. + +config SYSTEM_RAMTEST_PRIORITY + int "RAM test task priority" + default 100 + +config SYSTEM_RAMTEST_STACKSIZE + int "RAM test stack size" + default 1024 + +endif diff --git a/system/ramtest/Makefile b/system/ramtest/Makefile index a771e57bc..bdace6b1a 100644 --- a/system/ramtest/Makefile +++ b/system/ramtest/Makefile @@ -1,7 +1,7 @@ ############################################################################ # apps/system/ramtest/Makefile # -# Copyright (C) 2013 Gregory Nutt. All rights reserved. +# Copyright (C) 2013, 2017 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -39,8 +39,15 @@ include $(APPDIR)/Make.defs # RAM test -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 768 +CONFIG_SYSTEM_RAMTEST_PRIORITY ?= SCHED_PRIORITY_DEFAULT +CONFIG_SYSTEM_RAMTEST_STACKSIZE ?= 1024 + +APPNAME = ramtest +PRIORITY = $(CONFIG_SYSTEM_RAMTEST_PRIORITY) +STACKSIZE = $(CONFIG_SYSTEM_RAMTEST_STACKSIZE) + +CONFIG_SYSTEM_RAMTEST_PROGNAME ?= ramtest$(EXEEXT) +PROGNAME = $(CONFIG_SYSTEM_RAMTEST_PROGNAME) ASRCS = CSRCS = @@ -73,9 +80,6 @@ else INSTALL_DIR = $(BIN_DIR) endif -CONFIG_XYZ_PROGNAME ?= ramtest$(EXEEXT) -PROGNAME = $(CONFIG_XYZ_PROGNAME) - ROOTDEPPATH = --dep-path . # Common build @@ -111,10 +115,10 @@ endif # Register application ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) -$(BUILTIN_REGISTRY)$(DELIM)ramtest.bdat: $(DEPCONFIG) Makefile - $(call REGISTER,"ramtest",$(PRIORITY),$(STACKSIZE),ramtest_main) +$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME).bdat: $(DEPCONFIG) Makefile + $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) -context: $(BUILTIN_REGISTRY)$(DELIM)ramtest.bdat +context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME).bdat else context: endif