aboutsummaryrefslogtreecommitdiff
path: root/apps/nshlib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/nshlib')
-rw-r--r--apps/nshlib/Kconfig100
-rw-r--r--apps/nshlib/Makefile61
-rw-r--r--apps/nshlib/README.txt74
-rw-r--r--apps/nshlib/nsh.h77
-rw-r--r--apps/nshlib/nsh_apps.c41
-rw-r--r--apps/nshlib/nsh_consolemain.c8
-rw-r--r--apps/nshlib/nsh_dbgcmds.c64
-rw-r--r--apps/nshlib/nsh_netcmds.c327
-rw-r--r--apps/nshlib/nsh_netinit.c14
-rw-r--r--apps/nshlib/nsh_parse.c63
10 files changed, 732 insertions, 97 deletions
diff --git a/apps/nshlib/Kconfig b/apps/nshlib/Kconfig
index d12a32973..17b107b8f 100644
--- a/apps/nshlib/Kconfig
+++ b/apps/nshlib/Kconfig
@@ -23,122 +23,194 @@ config NSH_BUILTIN_APPS
(NAMEDAPP).
menu "Disable Individual commands"
+
+config NSH_DISABLE_BASE64DEC
+ bool "Disable base64dec"
+ default n
+ depends on NETUTILS_CODECS && CODECS_BASE64
+
+config NSH_DISABLE_BASE64ENC
+ bool "Disable base64enc"
+ default n
+ depends on NETUTILS_CODECS && CODECS_BASE64
+
config NSH_DISABLE_CAT
bool "Disable cat"
default n
+
config NSH_DISABLE_CD
bool "Disable cd"
default n
+
config NSH_DISABLE_CP
bool "Disable cp"
default n
+
config NSH_DISABLE_DD
bool "Disable dd"
default n
+
config NSH_DISABLE_ECHO
bool "Disable echo"
default n
+
config NSH_DISABLE_EXEC
bool "Disable exec"
default n
+
config NSH_DISABLE_EXIT
bool "Disable exit"
default n
+
config NSH_DISABLE_FREE
bool "Disable free"
default n
+
config NSH_DISABLE_GET
bool "Disable get"
default n
+
config NSH_DISABLE_HELP
bool "Disable help"
default n
+
+config NSH_DISABLE_HEXDUMP
+ bool "Disable hexdump"
+ default n
+
config NSH_DISABLE_IFCONFIG
bool "Disable ifconfig"
default n
+
config NSH_DISABLE_KILL
bool "Disable kill"
default n
+
config NSH_DISABLE_LOSETUP
bool "Disable losetup"
default n
+
config NSH_DISABLE_LS
bool "Disable ls"
default n
+
config NSH_DISABLE_MB
bool "Disable mb"
default n
+
+config NSH_DISABLE_MD5
+ bool "Disable md5"
+ default n
+ depends on NETUTILS_CODECS && CODECS_HASH_MD5
+
config NSH_DISABLE_MKDIR
bool "Disable mkdir"
default n
+
config NSH_DISABLE_MKFATFS
bool "Disable mkfatfs"
default n
+
config NSH_DISABLE_MKFIFO
bool "Disable mkfifo"
default n
+
config NSH_DISABLE_MKRD
bool "Disable mkrd"
default n
+
config NSH_DISABLE_MH
bool "Disable mh"
default n
+
config NSH_DISABLE_MOUNT
bool "Disable mount"
default n
+
config NSH_DISABLE_MW
bool "Disable mw"
default n
+
config NSH_DISABLE_NSFMOUNT
bool "Disable nfsmount"
default n
+
config NSH_DISABLE_PS
bool "Disable ps"
default n
+
config NSH_DISABLE_PING
bool "Disable ping"
default n
+
config NSH_DISABLE_PUT
bool "Disable put"
default n
+
config NSH_DISABLE_PWD
bool "Disable pwd"
default n
+
config NSH_DISABLE_RM
bool "Disable rm"
default n
+
config NSH_DISABLE_RMDIR
bool "Disable rmdir"
default n
+
config NSH_DISABLE_SET
bool "Disable set"
default n
+
config NSH_DISABLE_SH
bool "Disable sh"
default n
+
config NSH_DISABLE_SLEEP
bool "Disable sleep"
default n
+
config NSH_DISABLE_TEST
bool "Disable test"
default n
+
config NSH_DISABLE_UMOUNT
bool "Disable umount"
default n
+
config NSH_DISABLE_UNSET
bool "Disable unset"
default n
+
+config NSH_DISABLE_URLDECODE
+ bool "Disable urldecode"
+ default n
+ depends on NETUTILS_CODECS && CODECS_URLCODE
+
+config NSH_DISABLE_URLENCODE
+ bool "Disable urlencode"
+ default n
+ depends on NETUTILS_CODECS && CODECS_URLCODE
+
config NSH_DISABLE_USLEEP
bool "Disable usleep"
default n
+
config NSH_DISABLE_WGET
bool "Disable wget"
default n
+
config NSH_DISABLE_XD
bool "Disable xd"
default n
+
endmenu
+config NSH_CODECS_BUFSIZE
+ int "File buffer size used by CODEC commands"
+ default 128
+
config NSH_FILEIOSIZE
int "NSH I/O buffer size"
default 1024
@@ -490,7 +562,7 @@ config NSH_DHCPC
config NSH_IPADDR
hex "Target IP address"
- default 0x10000002
+ default 0xa0000002
depends on NSH_LIBRARY && NET && !NSH_DHCPC
---help---
If NSH_DHCPC is NOT set, then the static IP address must be provided.
@@ -499,7 +571,7 @@ config NSH_IPADDR
config NSH_DRIPADDR
hex "Router IP address"
- default 0x10000001
+ default 0xa0000001
depends on NSH_LIBRARY && NET && !NSH_DHCPC
---help---
Default router IP address (aka, Gateway). This is a 32-bit integer
@@ -513,6 +585,21 @@ config NSH_NETMASK
Network mask. This is a 32-bit integer value in host order. So, as
an example, 0xffffff00 would be 255.255.255.0.
+config NSH_DNS
+ bool "Use DNS"
+ default n
+ depends on NSH_LIBRARY && NET && NET_UDP && NET_BROADCAST
+ ---help---
+ Configure to use a DNS.
+
+config NSH_DNSIPADDR
+ hex "DNS IP address"
+ default 0xa0000001
+ depends on NSH_DNS
+ ---help---
+ Configure the DNS address. This is a 32-bit integer value in host
+ order. So, as an example, 0xa0000001 would be 10.0.0.1.
+
config NSH_NOMAC
bool "Hardware has no MAC address"
default n
@@ -520,3 +607,12 @@ config NSH_NOMAC
---help---
Set if your ethernet hardware has no built-in MAC address.
If set, a bogus MAC will be assigned.
+
+config NSH_MAX_ROUNDTRIP
+ int "Max Ping Round-Trip (DSEC)"
+ default 20
+ depends on NSH_LIBRARY && NET && !NSH_DISABLE_PING
+ ---help---
+ This is the maximum round trip for a response to a ICMP ECHO request.
+ It is in units of deciseconds. The default is 20 (2 seconds).
+
diff --git a/apps/nshlib/Makefile b/apps/nshlib/Makefile
index f616374bf..73325e899 100644
--- a/apps/nshlib/Makefile
+++ b/apps/nshlib/Makefile
@@ -39,64 +39,72 @@ include $(APPDIR)/Make.defs
# NSH Library
-ASRCS =
-CSRCS = nsh_init.c nsh_parse.c nsh_console.c nsh_fscmds.c nsh_ddcmd.c \
+ASRCS =
+CSRCS = nsh_init.c nsh_parse.c nsh_console.c nsh_fscmds.c nsh_ddcmd.c \
nsh_proccmds.c nsh_mmcmds.c nsh_envcmds.c nsh_dbgcmds.c
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
-CSRCS += nsh_apps.c
+CSRCS += nsh_apps.c
endif
ifeq ($(CONFIG_NSH_ROMFSETC),y)
-CSRCS += nsh_romfsetc.c
+CSRCS += nsh_romfsetc.c
endif
ifeq ($(CONFIG_NET),y)
-CSRCS += nsh_netinit.c nsh_netcmds.c
+CSRCS += nsh_netinit.c nsh_netcmds.c
endif
ifeq ($(CONFIG_RTC),y)
-CSRCS += nsh_timcmds.c
+CSRCS += nsh_timcmds.c
endif
ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y)
-CSRCS += nsh_mntcmds.c
+CSRCS += nsh_mntcmds.c
endif
ifeq ($(CONFIG_NSH_CONSOLE),y)
-CSRCS += nsh_consolemain.c
+CSRCS += nsh_consolemain.c
endif
ifeq ($(CONFIG_NSH_TELNET),y)
-CSRCS += nsh_telnetd.c
+CSRCS += nsh_telnetd.c
endif
ifneq ($(CONFIG_NSH_DISABLESCRIPT),y)
-CSRCS += nsh_test.c
+CSRCS += nsh_test.c
endif
ifeq ($(CONFIG_USBDEV),y)
-CSRCS += nsh_usbdev.c
+CSRCS += nsh_usbdev.c
endif
-AOBJS = $(ASRCS:.S=$(OBJEXT))
-COBJS = $(CSRCS:.c=$(OBJEXT))
+ifeq ($(CONFIG_NETUTILS_CODECS),y)
+CSRCS += nsh_codeccmd.c
+endif
+
+AOBJS = $(ASRCS:.S=$(OBJEXT))
+COBJS = $(CSRCS:.c=$(OBJEXT))
-SRCS = $(ASRCS) $(CSRCS)
-OBJS = $(AOBJS) $(COBJS)
+SRCS = $(ASRCS) $(CSRCS)
+OBJS = $(AOBJS) $(COBJS)
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\libapps$(LIBEXT)
+else
ifeq ($(WINTOOL),y)
- BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
+ BIN = ..\\libapps$(LIBEXT)
else
- BIN = "$(APPDIR)/libapps$(LIBEXT)"
+ BIN = ../libapps$(LIBEXT)
+endif
endif
-ROOTDEPPATH = --dep-path .
-VPATH =
+ROOTDEPPATH = --dep-path .
+VPATH =
# Build targets
-all: .built
+all: .built
.PHONY: context .depend depend clean distclean
$(AOBJS): %$(OBJEXT): %.S
@@ -106,26 +114,25 @@ $(COBJS): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
.built: $(OBJS)
- @( for obj in $(OBJS) ; do \
- $(call ARCHIVE, $(BIN), $${obj}); \
- done ; )
+ $(call ARCHIVE, $(BIN), $(OBJS))
@touch .built
context:
.depend: Makefile $(SRCS)
- @$(MKDEP) $(ROOTDEPPATH) \
- $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
@touch $@
depend: .depend
clean:
- @rm -f *.o *~ .*.swp .built
+ $(call DELFILE, .built)
$(call CLEAN)
distclean: clean
- @rm -f Make.dep .depend
+ $(call DELFILE, .context)
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
-include Make.dep
diff --git a/apps/nshlib/README.txt b/apps/nshlib/README.txt
index 0f6aee759..bc626e699 100644
--- a/apps/nshlib/README.txt
+++ b/apps/nshlib/README.txt
@@ -235,6 +235,10 @@ o test <expression>
integer -gt integer | integer -le integer |
integer -lt integer | integer -ne integer
+o base64dec [-w] [-f] <string or filepath>
+
+o base64dec [-w] [-f] <string or filepath>
+
o cat <path> [<path> [<path> ...]]
This command copies and concatentates all of the files at <path>
@@ -381,7 +385,11 @@ o help [-v] [<cmd>]
<cmd>
Show full command usage only for this command
-o ifconfig
+o hexdump <file or device>
+
+ Dump data in hexadecimal format from a file or character device.
+
+o ifconfig [nic_name [<ip-address>|dhcp]] [dr|gw|gateway <dr-address>] [netmask <net-mask>] [dns <dns-address>] [hw <hw-mac>]
Show the current configuration of the network, for example:
@@ -392,6 +400,22 @@ o ifconfig
if uIP statistics are enabled (CONFIG_NET_STATISTICS), then
this command will also show the detailed state of uIP.
+o ifdown <nic-name>
+
+ Take down the interface identified by the name <nic-name>.
+
+ Example:
+
+ ifdown eth0
+
+o ifup <nic-name>
+
+ Bring up down the interface identified by the name <nic-name>.
+
+ Example:
+
+ ifup eth0
+
o kill -<signal> <pid>
Send the <signal> to the task identified by <pid>.
@@ -449,6 +473,8 @@ o ls [-lRs] <dir-path>
-l Show size and mode information along with the filenames
in the listing.
+o md5 [-f] <string or filepath>
+
o mb <hex-address>[=<hex-value>][ <hex-byte-count>]
o mh <hex-address>[=<hex-value>][ <hex-byte-count>]
o mw <hex-address>[=<hex-value>][ <hex-byte-count>]
@@ -781,6 +807,10 @@ o unset <name>
nsh>
+ o urldecode [-f] <string or filepath>
+
+ o urlencode [-f] <string or filepath>
+
o usleep <usec>
Pause execution (sleep) of <usec> microseconds.
@@ -826,6 +856,8 @@ Command Dependencies on Configuration Settings
Command Depends on Configuration
---------- --------------------------
[ !CONFIG_NSH_DISABLESCRIPT
+ base64dec CONFIG_NETUTILS_CODECS && CONFIG_CODECS_BASE64
+ base64enc CONFIG_NETUTILS_CODECS && CONFIG_CODECS_BASE64
cat CONFIG_NFILE_DESCRIPTORS > 0
cd !CONFIG_DISABLE_ENVIRON && CONFIG_NFILE_DESCRIPTORS > 0
cp CONFIG_NFILE_DESCRIPTORS > 0
@@ -837,10 +869,14 @@ Command Dependencies on Configuration Settings
free --
get CONFIG_NET && CONFIG_NET_UDP && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NET_BUFSIZE >= 558 (see note 1)
help --
+ hexdump CONFIG_NFILE_DESCRIPTORS > 0
ifconfig CONFIG_NET
+ ifdown CONFIG_NET
+ ifup CONFIG_NET
kill !CONFIG_DISABLE_SIGNALS
losetup !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0
ls CONFIG_NFILE_DESCRIPTORS > 0
+ md5 CONFIG_NETUTILS_CODECS && CONFIG_CODECS_HASH_MD5
mb,mh,mw ---
mkdir !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE (see note 4)
mkfatfs !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT
@@ -861,6 +897,8 @@ Command Dependencies on Configuration Settings
test !CONFIG_NSH_DISABLESCRIPT
umount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_READABLE
unset !CONFIG_DISABLE_ENVIRON
+ urldecode CONFIG_NETUTILS_CODECS && CONFIG_CODECS_URLCODE
+ urlencode CONFIG_NETUTILS_CODECS && CONFIG_CODECS_URLCODE
usleep !CONFIG_DISABLE_SIGNALS
get CONFIG_NET && CONFIG_NET_TCP && CONFIG_NFILE_DESCRIPTORS > 0
xd ---
@@ -880,20 +918,22 @@ In addition, each NSH command can be individually disabled via one of the follow
settings. All of these settings make the configuration of NSH potentially complex but
also allow it to squeeze into very small memory footprints.
- CONFIG_NSH_DISABLE_CAT, CONFIG_NSH_DISABLE_CD, CONFIG_NSH_DISABLE_CP,
- CONFIG_NSH_DISABLE_DD, CONFIG_NSH_DISABLE_DF, CONFIG_NSH_DISABLE_ECHO,
- CONFIG_NSH_DISABLE_EXEC, CONFIG_NSH_DISABLE_EXIT, CONFIG_NSH_DISABLE_FREE,
- CONFIG_NSH_DISABLE_GET, CONFIG_NSH_DISABLE_HELP, CONFIG_NSH_DISABLE_IFCONFIG,
- CONFIG_NSH_DISABLE_KILL, CONFIG_NSH_DISABLE_LOSETUP, CONFIG_NSH_DISABLE_LS,
- CONFIG_NSH_DISABLE_MB, CONFIG_NSH_DISABLE_MKDIR, CONFIG_NSH_DISABLE_MKFATFS,
- CONFIG_NSH_DISABLE_MKFIFO, CONFIG_NSH_DISABLE_MKRD, CONFIG_NSH_DISABLE_MH,
- CONFIG_NSH_DISABLE_MOUNT, CONFIG_NSH_DISABLE_MW, CONFIG_NSH_DISABLE_MV,
- CONFIG_NSH_DISABLE_NFSMOUNT, CONFIG_NSH_DISABLE_PS, CONFIG_NSH_DISABLE_PING,
- CONFIG_NSH_DISABLE_PUT, CONFIG_NSH_DISABLE_PWD, CONFIG_NSH_DISABLE_RM,
- CONFIG_NSH_DISABLE_RMDIR, CONFIG_NSH_DISABLE_SET, CONFIG_NSH_DISABLE_SH,
- CONFIG_NSH_DISABLE_SLEEP, CONFIG_NSH_DISABLE_TEST, CONFIG_NSH_DISABLE_UMOUNT,
- CONFIG_NSH_DISABLE_UNSET, CONFIG_NSH_DISABLE_USLEEP, CONFIG_NSH_DISABLE_WGET,
- CONFIG_NSH_DISABLE_XD
+ CONFIG_NSH_DISABLE_BASE64DEC, CONFIG_NSH_DISABLE_BASE64ENC, CONFIG_NSH_DISABLE_CAT,
+ CONFIG_NSH_DISABLE_CD, CONFIG_NSH_DISABLE_CP, CONFIG_NSH_DISABLE_DD,
+ CONFIG_NSH_DISABLE_DF, CONFIG_NSH_DISABLE_ECHO, CONFIG_NSH_DISABLE_EXEC,
+ CONFIG_NSH_DISABLE_EXIT, CONFIG_NSH_DISABLE_FREE, CONFIG_NSH_DISABLE_GET,
+ CONFIG_NSH_DISABLE_HELP, CONFIG_NSH_DISABLE_HEXDUMP, CONFIG_NSH_DISABLE_IFCONFIG,
+ CONFIG_NSH_DISABLE_IFUPDOWN, CONFIG_NSH_DISABLE_KILL, CONFIG_NSH_DISABLE_LOSETUP,
+ CONFIG_NSH_DISABLE_LS, CONFIG_NSH_DISABLE_MD5 CONFIG_NSH_DISABLE_MB,
+ CONFIG_NSH_DISABLE_MKDIR, CONFIG_NSH_DISABLE_MKFATFS, CONFIG_NSH_DISABLE_MKFIFO,
+ CONFIG_NSH_DISABLE_MKRD, CONFIG_NSH_DISABLE_MH, CONFIG_NSH_DISABLE_MOUNT,
+ CONFIG_NSH_DISABLE_MW, CONFIG_NSH_DISABLE_MV, CONFIG_NSH_DISABLE_NFSMOUNT,
+ CONFIG_NSH_DISABLE_PS, CONFIG_NSH_DISABLE_PING, CONFIG_NSH_DISABLE_PUT,
+ CONFIG_NSH_DISABLE_PWD, CONFIG_NSH_DISABLE_RM, CONFIG_NSH_DISABLE_RMDIR,
+ CONFIG_NSH_DISABLE_SET, CONFIG_NSH_DISABLE_SH, CONFIG_NSH_DISABLE_SLEEP,
+ CONFIG_NSH_DISABLE_TEST, CONFIG_NSH_DISABLE_UMOUNT, CONFIG_NSH_DISABLE_UNSET,
+ CONFIG_NSH_DISABLE_URLDECODE, CONFIG_NSH_DISABLE_URLENCODE, CONFIG_NSH_DISABLE_USLEEP,
+ CONFIG_NSH_DISABLE_WGET, CONFIG_NSH_DISABLE_XD
Verbose help output can be suppressed by defining CONFIG_NSH_HELP_TERSE. In that
case, the help command is still available but will be slightly smaller.
@@ -1084,6 +1124,10 @@ NSH-Specific Configuration Settings
Set if your ethernet hardware has no built-in MAC address.
If set, a bogus MAC will be assigned.
+ * CONFIG_NSH_MAX_ROUNDTRIP
+ This is the maximum round trip for a response to a ICMP ECHO request.
+ It is in units of deciseconds. The default is 20 (2 seconds).
+
If you use DHCPC, then some special configuration network options are
required. These include:
diff --git a/apps/nshlib/nsh.h b/apps/nshlib/nsh.h
index 7188477ce..a046a384f 100644
--- a/apps/nshlib/nsh.h
+++ b/apps/nshlib/nsh.h
@@ -47,6 +47,7 @@
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
+#include <unistd.h>
#include <errno.h>
#include <nuttx/usb/usbdev_trace.h>
@@ -215,6 +216,15 @@
#endif /* CONFIG_NSH_TELNET_LOGIN */
+/* CONFIG_NSH_MAX_ROUNDTRIP - This is the maximum round trip for a response to
+ * a ICMP ECHO request. It is in units of deciseconds. The default is 20
+ * (2 seconds).
+ */
+
+#ifndef CONFIG_NSH_MAX_ROUNDTRIP
+# define CONFIG_NSH_MAX_ROUNDTRIP 20
+#endif
+
/* Verify support for ROMFS /etc directory support options */
#ifdef CONFIG_NSH_ROMFSETC
@@ -258,12 +268,36 @@
# undef CONFIG_NSH_ROMFSSECTSIZE
#endif
-/* This is the maximum number of arguments that will be accepted for a command */
-#ifdef CONFIG_NSH_MAX_ARGUMENTS
-# define NSH_MAX_ARGUMENTS CONFIG_NSH_MAX_ARGUMENTS
-#else
-# define NSH_MAX_ARGUMENTS 10
+/* This is the maximum number of arguments that will be accepted for a
+ * command. Here we attempt to select the smallest number possible depending
+ * upon the of commands that are available. Most commands use six or fewer
+ * arguments, but there are a few that require more.
+ *
+ * This value is also configurable with CONFIG_NSH_MAXARGUMENTS. This
+ * configurability is necessary since there may also be external, "built-in"
+ * commands that require more commands than NSH is aware of.
+ */
+
+#ifndef CONFIG_NSH_MAXARGUMENTS
+# define CONFIG_NSH_MAXARGUMENTS 6
#endif
+
+#if CONFIG_NSH_MAXARGUMENTS < 11
+# if defined(CONFIG_NET) && !defined(CONFIG_NSH_DISABLE_IFCONFIG)
+# undef CONFIG_NSH_MAXARGUMENTS
+# define CONFIG_NSH_MAXARGUMENTS 11
+# endif
+#endif
+
+#if CONFIG_NSH_MAXARGUMENTS < 7
+# if defined(CONFIG_NET_UDP) && CONFIG_NFILE_DESCRIPTORS > 0
+# if !defined(CONFIG_NSH_DISABLE_GET) || !defined(CONFIG_NSH_DISABLE_PUT)
+# undef CONFIG_NSH_MAXARGUMENTS
+# define CONFIG_NSH_MAXARGUMENTS 7
+# endif
+# endif
+#endif
+
/* strerror() produces much nicer output but is, however, quite large and
* will only be used if CONFIG_NSH_STRERROR is defined. Note that the strerror
* interface must also have been enabled with CONFIG_LIBC_STRERROR.
@@ -507,7 +541,7 @@ void nsh_usbtrace(void);
#ifndef CONFIG_NSH_DISABLE_XD
int cmd_xd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
#endif
-
+
#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST)
int cmd_test(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
int cmd_lbracket(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
@@ -529,6 +563,9 @@ void nsh_usbtrace(void);
# ifndef CONFIG_NSH_DISABLE_DD
int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
# endif
+# ifndef CONFIG_NSH_DISABLE_HEXDUMP
+ int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+# endif
# ifndef CONFIG_NSH_DISABLE_LS
int cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
# endif
@@ -595,6 +632,10 @@ void nsh_usbtrace(void);
# ifndef CONFIG_NSH_DISABLE_IFCONFIG
int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
# endif
+# ifndef CONFIG_NSH_DISABLE_IFUPDOWN
+ int cmd_ifup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+ int cmd_ifdown(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+# endif
#if defined(CONFIG_NET_UDP) && CONFIG_NFILE_DESCRIPTORS > 0
# ifndef CONFIG_NSH_DISABLE_GET
int cmd_get(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
@@ -643,4 +684,28 @@ void nsh_usbtrace(void);
# endif
#endif /* CONFIG_DISABLE_SIGNALS */
+#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_BASE64)
+# ifndef CONFIG_NSH_DISABLE_BASE64DEC
+ int cmd_base64decode(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+# endif
+# ifndef CONFIG_NSH_DISABLE_BASE64ENC
+ int cmd_base64encode(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+# endif
+#endif
+
+#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_HASH_MD5)
+# ifndef CONFIG_NSH_DISABLE_MD5
+ int cmd_md5(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+# endif
+#endif
+
+#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_URLCODE)
+# ifndef CONFIG_NSH_DISABLE_URLDECODE
+ int cmd_urlencode(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+# endif
+# ifndef CONFIG_NSH_DISABLE_URLENCODE
+ int cmd_urldecode(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
+# endif
+#endif
+
#endif /* __APPS_NSHLIB_NSH_H */
diff --git a/apps/nshlib/nsh_apps.c b/apps/nshlib/nsh_apps.c
index e335c2e2c..7dbaf9ba8 100644
--- a/apps/nshlib/nsh_apps.c
+++ b/apps/nshlib/nsh_apps.c
@@ -122,13 +122,28 @@ int nsh_execapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
ret = exec_namedapp(cmd, (FAR const char **)argv);
if (ret >= 0)
{
- /* The application was successfully started (but still blocked because the
- * scheduler is locked). If the application was not backgrounded, then we
- * need to wait here for the application to exit.
+ /* The application was successfully started (but still blocked because
+ * the scheduler is locked). If the application was not backgrounded,
+ * then we need to wait here for the application to exit. These really
+ * only works works with the following options:
+ *
+ * - CONFIG_NSH_DISABLEBG - Do not run commands in background
+ * - CONFIG_SCHED_WAITPID - Required to run external commands in
+ * foreground
+ *
+ * These concepts do not apply cleanly to the external applications.
*/
#ifdef CONFIG_SCHED_WAITPID
+
+ /* CONFIG_SCHED_WAITPID is selected, so we may run the command in
+ * foreground unless we were specifically requested to run the command
+ * in background (and running commands in background is enabled).
+ */
+
+# ifndef CONFIG_NSH_DISABLEBG
if (vtbl->np.np_bg == false)
+# endif /* CONFIG_NSH_DISABLEBG */
{
int rc = 0;
@@ -155,8 +170,25 @@ int nsh_execapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
*/
}
}
+# ifndef CONFIG_NSH_DISABLEBG
else
-#endif
+# endif /* CONFIG_NSH_DISABLEBG */
+#endif /* CONFIG_SCHED_WAITPID */
+
+ /* We get here if either:
+ *
+ * - CONFIG_SCHED_WAITPID is not selected meaning that all commands
+ * have to be run in background, or
+ * - CONFIG_SCHED_WAITPID and CONFIG_NSH_DISABLEBG are both selected, but the
+ * user requested to run the command in background.
+ *
+ * NOTE that the case of a) CONFIG_SCHED_WAITPID is not selected and
+ * b) CONFIG_NSH_DISABLEBG selected cannot be supported. In that event, all
+ * commands will have to run in background. The waitpid() API must be
+ * available to support running the command in foreground.
+ */
+
+#if !defined(CONFIG_SCHED_WAITPID) || !defined(CONFIG_NSH_DISABLEBG)
{
struct sched_param param;
sched_getparam(0, &param);
@@ -168,6 +200,7 @@ int nsh_execapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
ret = OK;
}
+#endif /* !CONFIG_SCHED_WAITPID || !CONFIG_NSH_DISABLEBG */
}
sched_unlock();
diff --git a/apps/nshlib/nsh_consolemain.c b/apps/nshlib/nsh_consolemain.c
index 6b51be470..f05447a64 100644
--- a/apps/nshlib/nsh_consolemain.c
+++ b/apps/nshlib/nsh_consolemain.c
@@ -160,11 +160,11 @@ int nsh_consolemain(int argc, char *argv[])
}
}
- /* Clean up */
+ /* Clean up. We do not get here, but this is necessary to keep some
+ * compilers happy. But others will complain that this code is not
+ * reachable.
+ */
nsh_exit(&pstate->cn_vtbl, 0);
-
- /* We do not get here, but this is necessary to keep some compilers happy */
-
return OK;
}
diff --git a/apps/nshlib/nsh_dbgcmds.c b/apps/nshlib/nsh_dbgcmds.c
index 384b377f3..85a4ccb9c 100644
--- a/apps/nshlib/nsh_dbgcmds.c
+++ b/apps/nshlib/nsh_dbgcmds.c
@@ -46,6 +46,10 @@
#include <string.h>
#include <errno.h>
+#if CONFIG_NFILE_DESCRIPTORS > 0
+# include <fcntl.h>
+#endif
+
#include "nsh.h"
#include "nsh_console.h"
@@ -99,7 +103,7 @@ int mem_parse(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv,
pcvalue++;
lvalue = (unsigned long)strtol(pcvalue, NULL, 16);
- if (lvalue > 0xffffffff)
+ if (lvalue > 0xffffffffL)
{
return -EINVAL;
}
@@ -127,6 +131,7 @@ int mem_parse(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv,
{
mem->dm_count = 1;
}
+
return OK;
}
@@ -327,7 +332,7 @@ void nsh_dumpbuffer(FAR struct nsh_vtbl_s *vtbl, const char *msg,
}
/****************************************************************************
- * Name: cmd_xd
+ * Name: cmd_xd, hex dump of memory
****************************************************************************/
#ifndef CONFIG_NSH_DISABLE_XD
@@ -353,3 +358,58 @@ int cmd_xd(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
return OK;
}
#endif
+
+/****************************************************************************
+ * Name: cmd_hexdump, hex dump of files
+ ****************************************************************************/
+
+#if CONFIG_NFILE_DESCRIPTORS > 0
+#ifndef CONFIG_NSH_DISABLE_HEXDUMP
+int cmd_hexdump(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
+{
+ uint8_t buffer[IOBUFFERSIZE];
+ char msg[32];
+ int position;
+ int fd;
+ int ret = OK;
+
+ /* Open the file for reading */
+
+ fd = open(argv[1], O_RDONLY);
+ if (fd < 0)
+ {
+ nsh_output(vtbl, g_fmtcmdfailed, "hexdump", "open", NSH_ERRNO);
+ return ERROR;
+ }
+
+ position = 0;
+ for (;;)
+ {
+ int nbytesread = read(fd, buffer, IOBUFFERSIZE);
+
+ /* Check for read errors */
+
+ if (nbytesread < 0)
+ {
+ int errval = errno;
+ nsh_output(vtbl, g_fmtcmdfailed, "hexdump", "read", NSH_ERRNO_OF(errval));
+ ret = ERROR;
+ break;
+ }
+ else if (nbytesread > 0)
+ {
+ snprintf(msg, sizeof(msg), "%s at %08x", argv[1], position);
+ nsh_dumpbuffer(vtbl, msg, buffer, nbytesread);
+ position += nbytesread;
+ }
+ else
+ {
+ break; // EOF
+ }
+ }
+
+ (void)close(fd);
+ return ret;
+}
+#endif
+#endif
diff --git a/apps/nshlib/nsh_netcmds.c b/apps/nshlib/nsh_netcmds.c
index cfea5a08a..371d30460 100644
--- a/apps/nshlib/nsh_netcmds.c
+++ b/apps/nshlib/nsh_netcmds.c
@@ -51,6 +51,7 @@
#include <fcntl.h> /* Needed for open */
#include <libgen.h> /* Needed for basename */
#include <errno.h>
+#include <debug.h>
#include <nuttx/net/net.h>
#include <nuttx/clock.h>
@@ -80,6 +81,15 @@
# endif
#endif
+#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS)
+# ifdef CONFIG_HAVE_GETHOSTBYNAME
+# include <netdb.h>
+# else
+# include <apps/netutils/resolv.h>
+# endif
+# include <apps/netutils/dhcpc.h>
+#endif
+
#include "nsh.h"
#include "nsh_console.h"
@@ -87,8 +97,16 @@
* Definitions
****************************************************************************/
+/* Size of the ECHO data */
+
#define DEFAULT_PING_DATALEN 56
+/* Get the larger value */
+
+#ifndef MAX
+# define MAX(a,b) (a > b ? a : b)
+#endif
+
/****************************************************************************
* Private Types
****************************************************************************/
@@ -262,14 +280,34 @@ int ifconfig_callback(FAR struct uip_driver_s *dev, void *arg)
{
struct nsh_vtbl_s *vtbl = (struct nsh_vtbl_s*)arg;
struct in_addr addr;
+ bool is_running = false;
+ int ret;
+
+ ret = uip_getifstatus(dev->d_ifname,&is_running);
+ if (ret != OK)
+ {
+ nsh_output(vtbl, "\tGet %s interface flags error: %d\n",
+ dev->d_ifname, ret);
+ }
+
+ nsh_output(vtbl, "%s\tHWaddr %s at %s\n",
+ dev->d_ifname, ether_ntoa(&dev->d_mac), (is_running)?"UP":"DOWN");
- nsh_output(vtbl, "%s\tHWaddr %s\n", dev->d_ifname, ether_ntoa(&dev->d_mac));
addr.s_addr = dev->d_ipaddr;
nsh_output(vtbl, "\tIPaddr:%s ", inet_ntoa(addr));
+
addr.s_addr = dev->d_draddr;
nsh_output(vtbl, "DRaddr:%s ", inet_ntoa(addr));
+
addr.s_addr = dev->d_netmask;
- nsh_output(vtbl, "Mask:%s\n\n", inet_ntoa(addr));
+ nsh_output(vtbl, "Mask:%s\n", inet_ntoa(addr));
+
+#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS)
+ resolv_getserver(&addr);
+ nsh_output(vtbl, "\tDNSaddr:%s\n", inet_ntoa(addr));
+#endif
+
+ nsh_output(vtbl, "\n");
return OK;
}
@@ -469,6 +507,54 @@ int cmd_get(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
#endif
/****************************************************************************
+ * Name: cmd_ifup
+ ****************************************************************************/
+
+#ifndef CONFIG_NSH_DISABLE_IFUPDOWN
+int cmd_ifup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
+{
+ FAR char *intf = NULL;
+ int ret;
+
+ if (argc != 2)
+ {
+ nsh_output(vtbl, "Please select nic_name:\n");
+ netdev_foreach(ifconfig_callback, vtbl);
+ return OK;
+ }
+
+ intf = argv[1];
+ ret = uip_ifup(intf);
+ nsh_output(vtbl, "ifup %s...%s\n", intf, (ret == OK) ? "OK" : "Failed");
+ return ret;
+}
+#endif
+
+/****************************************************************************
+ * Name: cmd_ifdown
+ ****************************************************************************/
+
+#ifndef CONFIG_NSH_DISABLE_IFUPDOWN
+int cmd_ifdown(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
+{
+ FAR char *intf = NULL;
+ int ret;
+
+ if (argc != 2)
+ {
+ nsh_output(vtbl, "Please select nic_name:\n");
+ netdev_foreach(ifconfig_callback, vtbl);
+ return OK;
+ }
+
+ intf = argv[1];
+ ret = uip_ifdown(intf);
+ nsh_output(vtbl, "ifdown %s...%s\n", intf, (ret == OK) ? "OK" : "Failed");
+ return ret;
+}
+#endif
+
+/****************************************************************************
* Name: cmd_ifconfig
****************************************************************************/
@@ -476,7 +562,20 @@ int cmd_get(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
struct in_addr addr;
- in_addr_t ip;
+ in_addr_t gip;
+ int i;
+ FAR char *intf = NULL;
+ FAR char *hostip = NULL;
+ FAR char *gwip = NULL;
+ FAR char *mask = NULL;
+ FAR char *tmp = NULL;
+ FAR char *hw = NULL;
+ FAR char *dns = NULL;
+ bool badarg = false;
+ uint8_t mac[IFHWADDRLEN];
+#if defined(CONFIG_NSH_DHCPC)
+ FAR void *handle;
+#endif
/* With one or no arguments, ifconfig simply shows the status of ethernet
* device:
@@ -498,24 +597,201 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
* ifconfig nic_name ip_address
*/
- /* Set host ip address */
+ if (argc > 2)
+ {
+ for(i = 0; i < argc; i++)
+ {
+ if (i == 1)
+ {
+ intf = argv[i];
+ }
+ else if (i == 2)
+ {
+ hostip = argv[i];
+ }
+ else
+ {
+ tmp = argv[i];
+ if (!strcmp(tmp, "dr") || !strcmp(tmp, "gw") || !strcmp(tmp, "gateway"))
+ {
+ if (argc-1 >= i+1)
+ {
+ gwip = argv[i+1];
+ i++;
+ }
+ else
+ {
+ badarg = true;
+ }
+ }
+ else if(!strcmp(tmp, "netmask"))
+ {
+ if (argc-1 >= i+1)
+ {
+ mask = argv[i+1];
+ i++;
+ }
+ else
+ {
+ badarg = true;
+ }
+ }
+ else if(!strcmp(tmp, "hw"))
+ {
+ if (argc-1>=i+1)
+ {
+ hw = argv[i+1];
+ i++;
+ badarg = !uiplib_hwmacconv(hw, mac);
+ }
+ else
+ {
+ badarg = true;
+ }
+ }
+ else if(!strcmp(tmp, "dns"))
+ {
+ if (argc-1 >= i+1)
+ {
+ dns = argv[i+1];
+ i++;
+ }
+ else
+ {
+ badarg = true;
+ }
+ }
+ }
+ }
+ }
+
+ if (badarg)
+ {
+ nsh_output(vtbl, g_fmtargrequired, argv[0]);
+ return ERROR;
+ }
+
+ /* Set Hardware ethernet MAC addr */
+
+ if (hw)
+ {
+ ndbg("HW MAC: %s\n", hw);
+ uip_setmacaddr(intf, mac);
+ }
+
+#if defined(CONFIG_NSH_DHCPC)
+ if (!strcmp(hostip, "dhcp"))
+ {
+ /* Set DHCP addr */
+
+ ndbg("DHCPC Mode\n");
+ gip = addr.s_addr = 0;
+ }
+ else
+#endif
+ {
+ /* Set host IP address */
+
+ ndbg("Host IP: %s\n", hostip);
+ gip = addr.s_addr = inet_addr(hostip);
+ }
- ip = addr.s_addr = inet_addr(argv[2]);
- uip_sethostaddr(argv[1], &addr);
+ uip_sethostaddr(intf, &addr);
/* Set gateway */
- ip = NTOHL(ip);
- ip &= ~0x000000ff;
- ip |= 0x00000001;
+ if (gwip)
+ {
+ ndbg("Gateway: %s\n", gwip);
+ gip = addr.s_addr = inet_addr(gwip);
+ }
+ else
+ {
+ if (gip)
+ {
+ ndbg("Gateway: default\n");
+ gip = NTOHL(gip);
+ gip &= ~0x000000ff;
+ gip |= 0x00000001;
+ gip = HTONL(gip);
+ }
+
+ addr.s_addr = gip;
+ }
+
+ uip_setdraddr(intf, &addr);
+
+ /* Set network mask */
+
+ if (mask)
+ {
+ ndbg("Netmask: %s\n",mask);
+ addr.s_addr = inet_addr(mask);
+ }
+ else
+ {
+ ndbg("Netmask: Default\n");
+ addr.s_addr = inet_addr("255.255.255.0");
+ }
+
+ uip_setnetmask(intf, &addr);
- addr.s_addr = HTONL(ip);
- uip_setdraddr(argv[1], &addr);
+#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS)
+ if (dns)
+ {
+ ndbg("DNS: %s\n", dns);
+ addr.s_addr = inet_addr(dns);
+ }
+ else
+ {
+ ndbg("DNS: Default\n");
+ addr.s_addr = gip;
+ }
+
+ resolv_conf(&addr);
+#endif
+
+#if defined(CONFIG_NSH_DHCPC)
+ /* Get the MAC address of the NIC */
+
+ if (!gip)
+ {
+ uip_getmacaddr("eth0", mac);
+
+ /* Set up the DHCPC modules */
+
+ handle = dhcpc_open(&mac, IFHWADDRLEN);
+
+ /* Get an IP address. Note that there is no logic for renewing the IP address in this
+ * example. The address should be renewed in ds.lease_time/2 seconds.
+ */
+
+ if (handle)
+ {
+ struct dhcpc_state ds;
- /* Set netmask */
+ (void)dhcpc_request(handle, &ds);
+ uip_sethostaddr("eth0", &ds.ipaddr);
- addr.s_addr = inet_addr("255.255.255.0");
- uip_setnetmask(argv[1], &addr);
+ if (ds.netmask.s_addr != 0)
+ {
+ uip_setnetmask("eth0", &ds.netmask);
+ }
+
+ if (ds.default_router.s_addr != 0)
+ {
+ uip_setdraddr("eth0", &ds.default_router);
+ }
+
+ if (ds.dnsaddr.s_addr != 0)
+ {
+ resolv_conf(&ds.dnsaddr);
+ }
+
+ dhcpc_close(handle);
+ }
+ }
+#endif
return OK;
}
@@ -536,6 +812,7 @@ int cmd_ping(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
uint32_t start;
uint32_t next;
uint32_t dsec = 10;
+ uint32_t maxwait;
uint16_t id;
bool badarg = false;
int count = 10;
@@ -599,7 +876,7 @@ int cmd_ping(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (optind == argc-1)
{
staddr = argv[optind];
- if (!uiplib_ipaddrconv(staddr, (FAR unsigned char*)&ipaddr))
+ if (dns_gethostip(staddr, &ipaddr) < 0)
{
goto errout;
}
@@ -619,16 +896,26 @@ int cmd_ping(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
id = ping_newid();
+ /* The maximum wait for a response will be the larger of the inter-ping time and
+ * the configured maximum round-trip time.
+ */
+
+ maxwait = MAX(dsec, CONFIG_NSH_MAX_ROUNDTRIP);
+
/* Loop for the specified count */
- nsh_output(vtbl, "PING %s %d bytes of data\n", staddr, DEFAULT_PING_DATALEN);
+ nsh_output(vtbl, "PING %d.%d.%d.%d %d bytes of data\n",
+ (ipaddr ) & 0xff, (ipaddr >> 8 ) & 0xff,
+ (ipaddr >> 16 ) & 0xff, (ipaddr >> 24 ) & 0xff,
+ DEFAULT_PING_DATALEN);
+
start = g_system_timer;
for (i = 1; i <= count; i++)
{
/* Send the ECHO request and wait for the response */
next = g_system_timer;
- seqno = uip_ping(ipaddr, id, i, DEFAULT_PING_DATALEN, dsec);
+ seqno = uip_ping(ipaddr, id, i, DEFAULT_PING_DATALEN, maxwait);
/* Was any response returned? We can tell if a non-negative sequence
* number was returned.
@@ -636,7 +923,7 @@ int cmd_ping(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
if (seqno >= 0 && seqno <= i)
{
- /* Get the elpased time from the time that the request was
+ /* Get the elapsed time from the time that the request was
* sent until the response was received. If we got a response
* to an earlier request, then fudge the elpased time.
*/
@@ -644,7 +931,7 @@ int cmd_ping(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
elapsed = TICK2MSEC(g_system_timer - next);
if (seqno < i)
{
- elapsed += 100*dsec*(i - seqno);
+ elapsed += 100 * dsec * (i - seqno);
}
/* Report the receipt of the reply */
@@ -662,7 +949,7 @@ int cmd_ping(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
elapsed = TICK2DSEC(g_system_timer - next);
if (elapsed < dsec)
{
- usleep(100000*dsec);
+ usleep(100000 * (dsec - elapsed));
}
}
diff --git a/apps/nshlib/nsh_netinit.c b/apps/nshlib/nsh_netinit.c
index bc845c4ed..58d238312 100644
--- a/apps/nshlib/nsh_netinit.c
+++ b/apps/nshlib/nsh_netinit.c
@@ -47,7 +47,7 @@
#include <net/if.h>
#include <apps/netutils/uiplib.h>
-#if defined(CONFIG_NSH_DHCPC)
+#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS)
# include <apps/netutils/resolv.h>
# include <apps/netutils/dhcpc.h>
#endif
@@ -60,6 +60,10 @@
* Definitions
****************************************************************************/
+#if defined(CONFIG_NSH_DRIPADDR) && !defined(CONFIG_NSH_DNSIPADDR)
+# define CONFIG_NSH_DNSIPADDR CONFIG_NSH_DRIPADDR
+#endif
+
/****************************************************************************
* Private Types
****************************************************************************/
@@ -125,10 +129,14 @@ int nsh_netinit(void)
addr.s_addr = HTONL(CONFIG_NSH_NETMASK);
uip_setnetmask("eth0", &addr);
-#if defined(CONFIG_NSH_DHCPC)
+#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS)
/* Set up the resolver */
resolv_init();
+#if defined(CONFIG_NSH_DNS)
+ addr.s_addr = HTONL(CONFIG_NSH_DNSIPADDR);
+ resolv_conf(&addr);
+#endif
#endif
#if defined(CONFIG_NSH_DHCPC)
@@ -148,7 +156,7 @@ int nsh_netinit(void)
{
struct dhcpc_state ds;
(void)dhcpc_request(handle, &ds);
- uip_sethostaddr("eth1", &ds.ipaddr);
+ uip_sethostaddr("eth0", &ds.ipaddr);
if (ds.netmask.s_addr != 0)
{
uip_setnetmask("eth0", &ds.netmask);
diff --git a/apps/nshlib/nsh_parse.c b/apps/nshlib/nsh_parse.c
index df2f7c3e3..27068acff 100644
--- a/apps/nshlib/nsh_parse.c
+++ b/apps/nshlib/nsh_parse.c
@@ -73,19 +73,19 @@
/* Argument list size
*
* argv[0]: The command name.
- * argv[1]: The beginning of argument (up to NSH_MAX_ARGUMENTS)
+ * argv[1]: The beginning of argument (up to CONFIG_NSH_MAXARGUMENTS)
* argv[argc-3]: Possibly '>' or '>>'
* argv[argc-2]: Possibly <file>
* argv[argc-1]: Possibly '&' (if pthreads are enabled)
* argv[argc]: NULL terminating pointer
*
- * Maximum size is NSH_MAX_ARGUMENTS+5
+ * Maximum size is CONFIG_NSH_MAXARGUMENTS+5
*/
#ifndef CONFIG_NSH_DISABLEBG
-# define MAX_ARGV_ENTRIES (NSH_MAX_ARGUMENTS+5)
+# define MAX_ARGV_ENTRIES (CONFIG_NSH_MAXARGUMENTS+5)
#else
-# define MAX_ARGV_ENTRIES (NSH_MAX_ARGUMENTS+4)
+# define MAX_ARGV_ENTRIES (CONFIG_NSH_MAXARGUMENTS+4)
#endif
/* Help command summary layout */
@@ -146,16 +146,25 @@ static const char g_failure[] = "1";
static const struct cmdmap_s g_cmdmap[] =
{
#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST)
- { "[", cmd_lbracket, 4, NSH_MAX_ARGUMENTS, "<expression> ]" },
+ { "[", cmd_lbracket, 4, CONFIG_NSH_MAXARGUMENTS, "<expression> ]" },
#endif
#ifndef CONFIG_NSH_DISABLE_HELP
{ "?", cmd_help, 1, 1, NULL },
#endif
+#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_BASE64)
+# ifndef CONFIG_NSH_DISABLE_BASE64DEC
+ { "base64dec", cmd_base64decode, 2, 4, "[-w] [-f] <string or filepath>" },
+# endif
+# ifndef CONFIG_NSH_DISABLE_BASE64ENC
+ { "base64enc", cmd_base64encode, 2, 4, "[-w] [-f] <string or filepath>" },
+# endif
+#endif
+
#if CONFIG_NFILE_DESCRIPTORS > 0
# ifndef CONFIG_NSH_DISABLE_CAT
- { "cat", cmd_cat, 2, NSH_MAX_ARGUMENTS, "<path> [<path> [<path> ...]]" },
+ { "cat", cmd_cat, 2, CONFIG_NSH_MAXARGUMENTS, "<path> [<path> [<path> ...]]" },
# endif
#ifndef CONFIG_DISABLE_ENVIRON
# ifndef CONFIG_NSH_DISABLE_CD
@@ -187,9 +196,9 @@ static const struct cmdmap_s g_cmdmap[] =
#ifndef CONFIG_NSH_DISABLE_ECHO
# ifndef CONFIG_DISABLE_ENVIRON
- { "echo", cmd_echo, 0, NSH_MAX_ARGUMENTS, "[<string|$name> [<string|$name>...]]" },
+ { "echo", cmd_echo, 0, CONFIG_NSH_MAXARGUMENTS, "[<string|$name> [<string|$name>...]]" },
# else
- { "echo", cmd_echo, 0, NSH_MAX_ARGUMENTS, "[<string> [<string>...]]" },
+ { "echo", cmd_echo, 0, CONFIG_NSH_MAXARGUMENTS, "[<string> [<string>...]]" },
# endif
#endif
@@ -217,10 +226,20 @@ static const struct cmdmap_s g_cmdmap[] =
{ "help", cmd_help, 1, 3, "[-v] [<cmd>]" },
# endif
#endif
+
+#if CONFIG_NFILE_DESCRIPTORS > 0
+#ifndef CONFIG_NSH_DISABLE_HEXDUMP
+ { "hexdump", cmd_hexdump, 2, 2, "<file or device>" },
+#endif
+#endif
#ifdef CONFIG_NET
# ifndef CONFIG_NSH_DISABLE_IFCONFIG
- { "ifconfig", cmd_ifconfig, 1, 3, "[nic_name [ip]]" },
+ { "ifconfig", cmd_ifconfig, 1, 11, "[nic_name [<ip-address>|dhcp]] [dr|gw|gateway <dr-address>] [netmask <net-mask>] [dns <dns-address>] [hw <hw-mac>]" },
+# endif
+# ifndef CONFIG_NSH_DISABLE_IFUPDOWN
+ { "ifdown", cmd_ifdown, 2, 2, "<nic_name>" },
+ { "ifup", cmd_ifup, 2, 2, "<nic_name>" },
# endif
#endif
@@ -246,6 +265,12 @@ static const struct cmdmap_s g_cmdmap[] =
{ "mb", cmd_mb, 2, 3, "<hex-address>[=<hex-value>][ <hex-byte-count>]" },
#endif
+#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_HASH_MD5)
+# ifndef CONFIG_NSH_DISABLE_MD5
+ { "md5", cmd_md5, 2, 3, "[-f] <string or filepath>" },
+# endif
+#endif
+
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE)
# ifndef CONFIG_NSH_DISABLE_MKDIR
{ "mkdir", cmd_mkdir, 2, 2, "<path>" },
@@ -348,7 +373,7 @@ static const struct cmdmap_s g_cmdmap[] =
#endif
#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST)
- { "test", cmd_test, 3, NSH_MAX_ARGUMENTS, "<expression>" },
+ { "test", cmd_test, 3, CONFIG_NSH_MAXARGUMENTS, "<expression>" },
#endif
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_READABLE)
@@ -363,6 +388,15 @@ static const struct cmdmap_s g_cmdmap[] =
# endif
#endif
+#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_URLCODE)
+# ifndef CONFIG_NSH_DISABLE_URLDECODE
+ { "urldecode", cmd_urldecode, 2, 3, "[-f] <string or filepath>" },
+# endif
+# ifndef CONFIG_NSH_DISABLE_URLENCODE
+ { "urlencode", cmd_urlencode, 2, 3, "[-f] <string or filepath>" },
+# endif
+#endif
+
#ifndef CONFIG_DISABLE_SIGNALS
# ifndef CONFIG_NSH_DISABLE_USLEEP
{ "usleep", cmd_usleep, 2, 2, "<usec>" },
@@ -378,6 +412,7 @@ static const struct cmdmap_s g_cmdmap[] =
#ifndef CONFIG_NSH_DISABLE_XD
{ "xd", cmd_xd, 3, 3, "<hex-address> <byte-count>" },
#endif
+
{ NULL, NULL, 1, 1, NULL }
};
@@ -711,7 +746,7 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl, int argc, char *argv[])
*
* argv[0]: The command name. This is argv[0] when the arguments
* are, finally, received by the command vtblr
- * argv[1]: The beginning of argument (up to NSH_MAX_ARGUMENTS)
+ * argv[1]: The beginning of argument (up to CONFIG_NSH_MAXARGUMENTS)
* argv[argc]: NULL terminating pointer
*/
@@ -1318,13 +1353,13 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
* of argv is:
*
* argv[0]: The command name.
- * argv[1]: The beginning of argument (up to NSH_MAX_ARGUMENTS)
+ * argv[1]: The beginning of argument (up to CONFIG_NSH_MAXARGUMENTS)
* argv[argc-3]: Possibly '>' or '>>'
* argv[argc-2]: Possibly <file>
* argv[argc-1]: Possibly '&'
* argv[argc]: NULL terminating pointer
*
- * Maximum size is NSH_MAX_ARGUMENTS+5
+ * Maximum size is CONFIG_NSH_MAXARGUMENTS+5
*/
argv[0] = cmd;
@@ -1398,7 +1433,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
/* Check if the maximum number of arguments was exceeded */
- if (argc > NSH_MAX_ARGUMENTS)
+ if (argc > CONFIG_NSH_MAXARGUMENTS)
{
nsh_output(vtbl, g_fmttoomanyargs, cmd);
}