From 7bc85ab91e1fb03844cf47bafbd4400ff06fc7b1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 27 Jun 2014 12:46:54 -0600 Subject: NSH: Networking features modified to handle the case of SLIP networks. --- apps/nshlib/nsh_netcmds.c | 17 ++++++++++++++++- apps/nshlib/nsh_netinit.c | 42 +++++++++++++++++++++++++++++++----------- 2 files changed, 47 insertions(+), 12 deletions(-) (limited to 'apps/nshlib') diff --git a/apps/nshlib/nsh_netcmds.c b/apps/nshlib/nsh_netcmds.c index 1e0ac3222..d6acad88b 100644 --- a/apps/nshlib/nsh_netcmds.c +++ b/apps/nshlib/nsh_netcmds.c @@ -1,7 +1,7 @@ /**************************************************************************** * 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 * * 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"; } +#ifdef CONFIG_NET_ETHERNET + /* REVISIT: How will we handle Ethernet and SLIP networks together? */ + nsh_output(vtbl, "%s\tHWaddr %s at %s\n", dev->d_ifname, ether_ntoa(&dev->d_mac), status); +#endif addr.s_addr = dev->d_ipaddr; 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 *mask = NULL; FAR char *tmp = NULL; +#ifndef CONFIG_NET_SLIP FAR char *hw = NULL; +#endif #if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS) FAR char *dns = NULL; #endif @@ -656,6 +662,10 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) badarg = true; } } + +#ifndef CONFIG_NET_SLIP + /* REVISIT: How will we handle Ethernet and SLIP networks together? */ + else if (!strcmp(tmp, "hw")) { if (argc-1>=i+1) @@ -669,6 +679,8 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) badarg = true; } } +#endif + #if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_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; } +#ifndef CONFIG_NET_SLIP /* Set Hardware Ethernet MAC address */ + /* REVISIT: How will we handle Ethernet and SLIP networks together? */ if (hw) { ndbg("HW MAC: %s\n", hw); uip_setmacaddr(intf, mac); } +#endif #if defined(CONFIG_NSH_DHCPC) if (!strcmp(hostip, "dhcp")) diff --git a/apps/nshlib/nsh_netinit.c b/apps/nshlib/nsh_netinit.c index 5afa4b56c..8461df7db 100644 --- a/apps/nshlib/nsh_netinit.c +++ b/apps/nshlib/nsh_netinit.c @@ -1,7 +1,7 @@ /**************************************************************************** * 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 * * This is influenced by similar logic from uIP: @@ -64,6 +64,22 @@ # define CONFIG_NSH_DNSIPADDR CONFIG_NSH_DRIPADDR #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 ****************************************************************************/ @@ -94,20 +110,20 @@ int nsh_netinit(void) #if defined(CONFIG_NSH_DHCPC) FAR void *handle; #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]; #endif /* 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[1] = 0xe0; mac[2] = 0xde; mac[3] = 0xad; mac[4] = 0xbe; mac[5] = 0xef; - uip_setmacaddr("eth0", mac); + uip_setmacaddr(NET_DEVNAME, mac); #endif /* Set up our host address */ @@ -117,17 +133,17 @@ int nsh_netinit(void) #else addr.s_addr = 0; #endif - uip_sethostaddr("eth0", &addr); + uip_sethostaddr(NET_DEVNAME, &addr); /* Set up the default router address */ addr.s_addr = HTONL(CONFIG_NSH_DRIPADDR); - uip_setdraddr("eth0", &addr); + uip_setdraddr(NET_DEVNAME, &addr); /* Setup the subnet mask */ 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) /* Set up the resolver */ @@ -142,7 +158,7 @@ int nsh_netinit(void) #if defined(CONFIG_NSH_DHCPC) /* Get the MAC address of the NIC */ - uip_getmacaddr("eth0", mac); + uip_getmacaddr(NET_DEVNAME, mac); /* Set up the DHCPC modules */ @@ -156,19 +172,23 @@ int nsh_netinit(void) { struct dhcpc_state ds; (void)dhcpc_request(handle, &ds); - uip_sethostaddr("eth0", &ds.ipaddr); + uip_sethostaddr(NET_DEVNAME, &ds.ipaddr); + if (ds.netmask.s_addr != 0) { - uip_setnetmask("eth0", &ds.netmask); + uip_setnetmask(NET_DEVNAME, &ds.netmask); } + 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) { dns_setserver(&ds.dnsaddr); } + dhcpc_close(handle); } #endif -- cgit v1.2.3