diff --git a/nshlib/Kconfig b/nshlib/Kconfig index dc3dfa14a..24e42e5a2 100644 --- a/nshlib/Kconfig +++ b/nshlib/Kconfig @@ -487,6 +487,11 @@ config NSH_DISABLE_ROUTE default y if DEFAULT_SMALL default n if !DEFAULT_SMALL +config NSH_DISABLE_RPTUN + bool "Disable rptun" + default n + depends on RPTUN + config NSH_DISABLE_SET bool "Disable set" default n diff --git a/nshlib/nsh.h b/nshlib/nsh.h index 5e4bfa3c2..64e4a2a07 100644 --- a/nshlib/nsh.h +++ b/nshlib/nsh.h @@ -1167,6 +1167,10 @@ int cmd_irqinfo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); int cmd_reboot(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); #endif +#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN) + int cmd_rptun(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + #if (defined(CONFIG_BOARDCTL_POWEROFF) || defined(CONFIG_BOARDCTL_RESET)) && \ !defined(CONFIG_NSH_DISABLE_SHUTDOWN) int cmd_shutdown(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c index 735c603cf..2084516ec 100644 --- a/nshlib/nsh_command.c +++ b/nshlib/nsh_command.c @@ -436,6 +436,10 @@ static const struct cmdmap_s g_cmdmap[] = #endif #endif +#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN) + { "rptun", cmd_rptun, 3, 3, " " }, +#endif + #ifndef CONFIG_NSH_DISABLE_SET #ifdef CONFIG_NSH_VARS # if !defined(CONFIG_DISABLE_ENVIRON) && !defined(CONFIG_NSH_DISABLESCRIPT) diff --git a/nshlib/nsh_syscmds.c b/nshlib/nsh_syscmds.c index 055e139c0..7bf89de02 100644 --- a/nshlib/nsh_syscmds.c +++ b/nshlib/nsh_syscmds.c @@ -39,8 +39,11 @@ #include +#include #include +#include #include +#include #include #include #include @@ -238,6 +241,49 @@ int cmd_reboot(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) } #endif +/**************************************************************************** + * Name: cmd_rptun + ****************************************************************************/ + +#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN) +int cmd_rptun(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + int fd, cmd; + + if (argc < 3) + { + nsh_output(vtbl, g_fmtargrequired, argv[0]); + return ERROR; + } + + if (strcmp(argv[1], "start") == 0) + { + cmd = RPTUNIOC_START; + } + else if (strcmp(argv[1], "stop") == 0) + { + cmd = RPTUNIOC_STOP; + } + else + { + nsh_output(vtbl, g_fmtarginvalid, argv[1]); + return ERROR; + } + + fd = open(argv[2], 0); + if (fd < 0) + { + nsh_output(vtbl, g_fmtarginvalid, argv[2]); + return ERROR; + } + + ioctl(fd, cmd, 0); + + close(fd); + return 0; +} +#endif + /**************************************************************************** * Name: cmd_uname ****************************************************************************/