NSH: Networking features modified to handle the case of SLIP networks.

This commit is contained in:
Gregory Nutt
2014-06-27 12:46:54 -06:00
parent e55af8e312
commit a274d4232c
2 changed files with 47 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* apps/nshlib/nsh_netcmds.c * apps/nshlib/nsh_netcmds.c
* *
* Copyright (C) 2007-2012 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2012, 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -307,8 +307,12 @@ int ifconfig_callback(FAR struct uip_driver_s *dev, void *arg)
status = "DOWN"; status = "DOWN";
} }
#ifdef CONFIG_NET_ETHERNET
/* REVISIT: How will we handle Ethernet and SLIP networks together? */
nsh_output(vtbl, "%s\tHWaddr %s at %s\n", nsh_output(vtbl, "%s\tHWaddr %s at %s\n",
dev->d_ifname, ether_ntoa(&dev->d_mac), status); dev->d_ifname, ether_ntoa(&dev->d_mac), status);
#endif
addr.s_addr = dev->d_ipaddr; addr.s_addr = dev->d_ipaddr;
nsh_output(vtbl, "\tIPaddr:%s ", inet_ntoa(addr)); nsh_output(vtbl, "\tIPaddr:%s ", inet_ntoa(addr));
@@ -587,7 +591,9 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
FAR char *gwip = NULL; FAR char *gwip = NULL;
FAR char *mask = NULL; FAR char *mask = NULL;
FAR char *tmp = NULL; FAR char *tmp = NULL;
#ifndef CONFIG_NET_SLIP
FAR char *hw = NULL; FAR char *hw = NULL;
#endif
#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS) #if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS)
FAR char *dns = NULL; FAR char *dns = NULL;
#endif #endif
@@ -656,6 +662,10 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
badarg = true; badarg = true;
} }
} }
#ifndef CONFIG_NET_SLIP
/* REVISIT: How will we handle Ethernet and SLIP networks together? */
else if (!strcmp(tmp, "hw")) else if (!strcmp(tmp, "hw"))
{ {
if (argc-1>=i+1) if (argc-1>=i+1)
@@ -669,6 +679,8 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
badarg = true; badarg = true;
} }
} }
#endif
#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS) #if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS)
else if (!strcmp(tmp, "dns")) else if (!strcmp(tmp, "dns"))
{ {
@@ -693,13 +705,16 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
return ERROR; return ERROR;
} }
#ifndef CONFIG_NET_SLIP
/* Set Hardware Ethernet MAC address */ /* Set Hardware Ethernet MAC address */
/* REVISIT: How will we handle Ethernet and SLIP networks together? */
if (hw) if (hw)
{ {
ndbg("HW MAC: %s\n", hw); ndbg("HW MAC: %s\n", hw);
uip_setmacaddr(intf, mac); uip_setmacaddr(intf, mac);
} }
#endif
#if defined(CONFIG_NSH_DHCPC) #if defined(CONFIG_NSH_DHCPC)
if (!strcmp(hostip, "dhcp")) if (!strcmp(hostip, "dhcp"))

View File

@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* apps/nshlib/nsh_netinit.c * apps/nshlib/nsh_netinit.c
* *
* Copyright (C) 2010-2012 Gregory Nutt. All rights reserved. * Copyright (C) 2010-2012, 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* This is influenced by similar logic from uIP: * This is influenced by similar logic from uIP:
@@ -64,6 +64,22 @@
# define CONFIG_NSH_DNSIPADDR CONFIG_NSH_DRIPADDR # define CONFIG_NSH_DNSIPADDR CONFIG_NSH_DRIPADDR
#endif #endif
/* SLIP-specific configuration
*
* REVISIT: How will we handle Ethernet and SLIP networks together? In the
* future, NSH will need to be extended to handle multiple networks with
* mixed transports.
*/
#ifdef CONFIG_NET_SLIP
# define NET_DEVNAME "sl0"
# ifndef CONFIG_NSH_NOMAC
# error "CONFIG_NSH_NOMAC must be defined for SLIP"
# endif
#else
# define NET_DEVNAME "eth0"
#endif
/**************************************************************************** /****************************************************************************
* Private Types * Private Types
****************************************************************************/ ****************************************************************************/
@@ -94,20 +110,20 @@ int nsh_netinit(void)
#if defined(CONFIG_NSH_DHCPC) #if defined(CONFIG_NSH_DHCPC)
FAR void *handle; FAR void *handle;
#endif #endif
#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_NOMAC) #if (defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_NOMAC)) && !defined(CONFIG_NET_SLIP)
uint8_t mac[IFHWADDRLEN]; uint8_t mac[IFHWADDRLEN];
#endif #endif
/* Many embedded network interfaces must have a software assigned MAC */ /* Many embedded network interfaces must have a software assigned MAC */
#ifdef CONFIG_NSH_NOMAC #if defined(CONFIG_NSH_NOMAC) && !defined(CONFIG_NET_SLIP)
mac[0] = 0x00; mac[0] = 0x00;
mac[1] = 0xe0; mac[1] = 0xe0;
mac[2] = 0xde; mac[2] = 0xde;
mac[3] = 0xad; mac[3] = 0xad;
mac[4] = 0xbe; mac[4] = 0xbe;
mac[5] = 0xef; mac[5] = 0xef;
uip_setmacaddr("eth0", mac); uip_setmacaddr(NET_DEVNAME, mac);
#endif #endif
/* Set up our host address */ /* Set up our host address */
@@ -117,17 +133,17 @@ int nsh_netinit(void)
#else #else
addr.s_addr = 0; addr.s_addr = 0;
#endif #endif
uip_sethostaddr("eth0", &addr); uip_sethostaddr(NET_DEVNAME, &addr);
/* Set up the default router address */ /* Set up the default router address */
addr.s_addr = HTONL(CONFIG_NSH_DRIPADDR); addr.s_addr = HTONL(CONFIG_NSH_DRIPADDR);
uip_setdraddr("eth0", &addr); uip_setdraddr(NET_DEVNAME, &addr);
/* Setup the subnet mask */ /* Setup the subnet mask */
addr.s_addr = HTONL(CONFIG_NSH_NETMASK); addr.s_addr = HTONL(CONFIG_NSH_NETMASK);
uip_setnetmask("eth0", &addr); uip_setnetmask(NET_DEVNAME, &addr);
#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS) #if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS)
/* Set up the resolver */ /* Set up the resolver */
@@ -142,7 +158,7 @@ int nsh_netinit(void)
#if defined(CONFIG_NSH_DHCPC) #if defined(CONFIG_NSH_DHCPC)
/* Get the MAC address of the NIC */ /* Get the MAC address of the NIC */
uip_getmacaddr("eth0", mac); uip_getmacaddr(NET_DEVNAME, mac);
/* Set up the DHCPC modules */ /* Set up the DHCPC modules */
@@ -156,19 +172,23 @@ int nsh_netinit(void)
{ {
struct dhcpc_state ds; struct dhcpc_state ds;
(void)dhcpc_request(handle, &ds); (void)dhcpc_request(handle, &ds);
uip_sethostaddr("eth0", &ds.ipaddr); uip_sethostaddr(NET_DEVNAME, &ds.ipaddr);
if (ds.netmask.s_addr != 0) if (ds.netmask.s_addr != 0)
{ {
uip_setnetmask("eth0", &ds.netmask); uip_setnetmask(NET_DEVNAME, &ds.netmask);
} }
if (ds.default_router.s_addr != 0) if (ds.default_router.s_addr != 0)
{ {
uip_setdraddr("eth0", &ds.default_router); uip_setdraddr(NET_DEVNAME, &ds.default_router);
} }
if (ds.dnsaddr.s_addr != 0) if (ds.dnsaddr.s_addr != 0)
{ {
dns_setserver(&ds.dnsaddr); dns_setserver(&ds.dnsaddr);
} }
dhcpc_close(handle); dhcpc_close(handle);
} }
#endif #endif