mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-18 03:53:33 +08:00
Merge branch 'master' into nuttx-merge-5447
This commit is contained in:
+59
-15
@@ -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:
|
||||
|
||||
|
||||
+37
-4
@@ -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, ¶m);
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,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 +127,7 @@ int mem_parse(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv,
|
||||
{
|
||||
mem->dm_count = 1;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
+307
-20
@@ -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;
|
||||
}
|
||||
|
||||
@@ -468,6 +506,54 @@ int cmd_get(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
#endif
|
||||
#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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ip = addr.s_addr = inet_addr(argv[2]);
|
||||
uip_sethostaddr(argv[1], &addr);
|
||||
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);
|
||||
}
|
||||
|
||||
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 = HTONL(ip);
|
||||
uip_setdraddr(argv[1], &addr);
|
||||
addr.s_addr = gip;
|
||||
}
|
||||
|
||||
/* Set netmask */
|
||||
uip_setdraddr(intf, &addr);
|
||||
|
||||
addr.s_addr = inet_addr("255.255.255.0");
|
||||
uip_setnetmask(argv[1], &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);
|
||||
|
||||
#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;
|
||||
|
||||
(void)dhcpc_request(handle, &ds);
|
||||
uip_sethostaddr("eth0", &ds.ipaddr);
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -148,7 +148,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);
|
||||
|
||||
+49
-14
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user