From 033b42789b8757056612191c9615cb9d2c9811e8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 17 Jun 2017 10:04:18 -0600 Subject: [PATCH 1/4] NSH: Fix some ieee 802.15.4 initialization logic. It should not set the saddr or panid; those cannot be hard-coded but must come from the coordinator. --- include/netutils/netlib.h | 7 +- netutils/netlib/Makefile | 3 +- ...tlib_nodeaddrconv.c => netlib_eaddrconv.c} | 12 +- netutils/netlib/netlib_setnodeaddr.c | 109 ------------------ netutils/netlib/netlib_setpanid.c | 94 --------------- nshlib/Kconfig | 13 +-- nshlib/nsh_netcmds.c | 6 +- nshlib/nsh_netinit.c | 39 ++----- 8 files changed, 28 insertions(+), 255 deletions(-) rename netutils/netlib/{netlib_nodeaddrconv.c => netlib_eaddrconv.c} (91%) delete mode 100644 netutils/netlib/netlib_setnodeaddr.c delete mode 100644 netutils/netlib/netlib_setpanid.c diff --git a/include/netutils/netlib.h b/include/netutils/netlib.h index 46225819c..0f30da4ee 100644 --- a/include/netutils/netlib.h +++ b/include/netutils/netlib.h @@ -115,12 +115,11 @@ int netlib_getmacaddr(FAR const char *ifname, FAR uint8_t *macaddr); #endif #ifdef CONFIG_NET_6LOWPAN -/* Get IEEE802.15.4 MAC driver node address */ +/* Set IEEE 802.15.4 extended address. */ +int netlib_seteaddr(FAR const char *ifname, FAR const uint8_t *eaddr); int netlib_getpanid(FAR const char *ifname, FAR uint16_t *panid); -int netlib_setnodeaddr(FAR const char *ifname, FAR const uint8_t *nodeaddr); -int netlib_setpanid(FAR const char *ifname, uint16_t panid); -bool netlib_nodeaddrconv(FAR const char *hwstr, FAR uint8_t *hw); +bool netlib_eaddrconv(FAR const char *hwstr, FAR uint8_t *hw); #endif /* IP address support */ diff --git a/netutils/netlib/Makefile b/netutils/netlib/Makefile index a2233036e..a36c6f844 100644 --- a/netutils/netlib/Makefile +++ b/netutils/netlib/Makefile @@ -87,8 +87,7 @@ CSRCS += netlib_setmacaddr.c netlib_getmacaddr.c endif ifeq ($(CONFIG_NET_6LOWPAN),y) -CSRCS += netlib_getpanid.c netlib_setnodeaddr.c netlib_setpanid.c -CSRCS += netlib_nodeaddrconv.c +CSRCS += netlib_seteaddr.c netlib_getpanid.c netlib_eaddrconv.c endif # IGMP support diff --git a/netutils/netlib/netlib_nodeaddrconv.c b/netutils/netlib/netlib_eaddrconv.c similarity index 91% rename from netutils/netlib/netlib_nodeaddrconv.c rename to netutils/netlib/netlib_eaddrconv.c index 4cb6760e4..a618e9818 100644 --- a/netutils/netlib/netlib_nodeaddrconv.c +++ b/netutils/netlib/netlib_eaddrconv.c @@ -1,5 +1,5 @@ /**************************************************************************** - * netutils/netlib/netlib_nodeaddrconv.c + * netutils/netlib/netlib_eaddrconv.c * * Copyright (C) 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -50,26 +50,26 @@ ****************************************************************************/ /**************************************************************************** - * Name: netlib_nodeaddrconv + * Name: netlib_eaddrconv ****************************************************************************/ -bool netlib_nodeaddrconv(FAR const char *hwstr, FAR uint8_t *hw) +bool netlib_eaddrconv(FAR const char *hwstr, FAR uint8_t *hw) { unsigned char tmp; unsigned char i; unsigned char j; char ch; - /* Form xx:xx or xx:xx:xx:xx:xx:xx:xx:xx for extended Rime address */ + /* Extended Address Form: xx:xx:xx:xx:xx:xx:xx:xx */ - if (strlen(hwstr) != 3 * NET_6LOWPAN_ADDRSIZE - 1) + if (strlen(hwstr) != 3 * 8 - 1) { return false; } tmp = 0; - for (i = 0; i < NET_6LOWPAN_ADDRSIZE; ++i) + for (i = 0; i < 8; ++i) { j = 0; do diff --git a/netutils/netlib/netlib_setnodeaddr.c b/netutils/netlib/netlib_setnodeaddr.c deleted file mode 100644 index e88ca727b..000000000 --- a/netutils/netlib/netlib_setnodeaddr.c +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** - * netutils/netlib/netlib_setnodeaddr.c - * - * Copyright (C) 2017 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include "netutils/netlib.h" - -#if defined(CONFIG_NET_6LOWPAN) && CONFIG_NSOCKET_DESCRIPTORS > 0 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: netlib_setnodeaddr - * - * Description: - * Set the 6loWPAN IEEE802.15.4 MAC network driver node address - * - * Parameters: - * ifname The name of the interface to use - * nodeaddr Node address to set, size must be NET_6LOWPAN_ADDRSIZE - * - * Return: - * 0 on success; -1 on failure - * - ****************************************************************************/ - -int netlib_setnodeaddr(FAR const char *ifname, FAR const uint8_t *nodeaddr) -{ - int ret = ERROR; - - if (ifname && nodeaddr) - { - /* Get a socket (only so that we get access to the INET subsystem) */ - - int sockfd = socket(PF_INET6, NETLIB_SOCK_IOCTL, 0); - if (sockfd >= 0) - { - struct ifreq req; - - /* Put the driver name into the request */ - - strncpy(req.ifr_name, ifname, IFNAMSIZ); - - /* Put the new MAC address into the request */ - - req.ifr_hwaddr.sa_family = AF_INET6; - memcpy(&req.ifr_hwaddr.sa_data, nodeaddr, NET_6LOWPAN_ADDRSIZE); - - /* Perform the ioctl to set the node address */ - - ret = ioctl(sockfd, SIOCSIFHWADDR, (unsigned long)&req); - close(sockfd); - } - } - - return ret; -} - -#endif /* CONFIG_NET_6LOWPAN && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/netutils/netlib/netlib_setpanid.c b/netutils/netlib/netlib_setpanid.c deleted file mode 100644 index a99d6eee2..000000000 --- a/netutils/netlib/netlib_setpanid.c +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** - * netutils/netlib/netlib_setpanid.c - * - * Copyright (C) 2017 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include - -#include "wireless/ieee802154.h" -#include "netutils/netlib.h" - -#if defined(CONFIG_NET_6LOWPAN) && CONFIG_NSOCKET_DESCRIPTORS > 0 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: netlib_setpanid - * - * Description: - * Join the specified PAN ID - * - * Parameters: - * ifname The name of the interface to use - * panid The PAN ID to join - * - * Return: - * 0 on success; -1 on failure. errno will be set on failure. - * - ****************************************************************************/ - -int netlib_setpanid(FAR const char *ifname, uint16_t panid) -{ - int ret = ERROR; - - if (ifname != NULL) - { - /* Get a socket (only so that we get access to the INET subsystem) */ - - int sockfd = socket(PF_INET6, NETLIB_SOCK_IOCTL, 0); - if (sockfd >= 0) - { - /* Use the helper provided in libmac */ - - ret = sixlowpan_setpanid(sockfd, ifname, panid); - close(sockfd); - } - } - - return ret; -} - -#endif /* CONFIG_NET_6LOWPAN && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nshlib/Kconfig b/nshlib/Kconfig index 3337e2995..8c7cb30f4 100644 --- a/nshlib/Kconfig +++ b/nshlib/Kconfig @@ -1472,8 +1472,9 @@ endchoice # MAC address selection config NSH_MACADDR hex "Fixed MAC address" - default 0x00e0deadbeef - depends on NSH_SWMAC + default 0x00e0deadbeef if NET_ETHERNET + default 0x00fade00deadbeef if !NET_ETHERNET && NET_6LOWPAN + depends on NSH_SWMAC && (NET_ETHERNET || NET_6LOWPAN) ---help--- If the hardware has no built-in MAC address and if the NSH_SWMAC option is selected, then the fixed, software-assigned MAC address @@ -1481,14 +1482,6 @@ config NSH_MACADDR endif # NSH_NOMAC -config NSH_PANID - hex "6loWPAN PAN ID" - default 0xface - depends on NET_6LOWPAN - range 0x0000 0xffff - ---help--- - Select the PAN ID to join upon initialization. - menu "WAPI Configuration" depends on NET && WIRELESS_WAPI diff --git a/nshlib/nsh_netcmds.c b/nshlib/nsh_netcmds.c index d80ef1a10..f57a71a73 100644 --- a/nshlib/nsh_netcmds.c +++ b/nshlib/nsh_netcmds.c @@ -762,7 +762,7 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) uint8_t mac[IFHWADDRLEN]; #endif #ifdef CONFIG_NET_6LOWPAN - uint8_t nodeaddr[NET_6LOWPAN_ADDRSIZE]; + uint8_t eaddr[8]; #endif #if defined(CONFIG_NSH_DHCPC) FAR void *handle; @@ -862,7 +862,7 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) #ifdef CONFIG_NET_ETHERNET badarg = !netlib_ethaddrconv(hw, mac); #else - badarg = !netlib_nodeaddrconv(hw, nodeaddr); + badarg = !netlib_eaddrconv(hw, eaddr); #endif } else @@ -906,7 +906,7 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) #ifdef CONFIG_NET_ETHERNET netlib_setmacaddr(intf, mac); #else - netlib_setnodeaddr(intf, nodeaddr); + netlib_seteaddr(intf, eaddr); #endif } #endif diff --git a/nshlib/nsh_netinit.c b/nshlib/nsh_netinit.c index d030bf7d4..85720eef9 100644 --- a/nshlib/nsh_netinit.c +++ b/nshlib/nsh_netinit.c @@ -93,13 +93,6 @@ #undef HAVE_MAC #if defined(CONFIG_NET_ETHERNET) || defined(CONFIG_NET_6LOWPAN) # define HAVE_MAC 1 -# if defined(CONFIG_NET_6LOWPAN) -# if !defined(CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED) && CONFIG_NSH_MACADDR > 0xffff -# error Invalid 6loWPAN node address for SIZE == 2 -# elif defined(CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED) && CONFIG_NSH_MACADDR > 0xffffffffffffffffull -# error Invalid 6loWPAN node address for SIZE == 8 -# endif -# endif #endif #if defined(CONFIG_NSH_DRIPADDR) && !defined(CONFIG_NSH_DNSIPADDR) @@ -257,7 +250,7 @@ static void nsh_netinit_configure(void) #if defined(CONFIG_NET_ETHERNET) uint8_t mac[IFHWADDRLEN]; #elif defined(CONFIG_NET_6LOWPAN) - uint8_t nodeaddr[NET_6LOWPAN_ADDRSIZE]; + uint8_t eaddr[NET_6LOWPAN_ADDRSIZE]; #endif #endif @@ -281,29 +274,21 @@ static void nsh_netinit_configure(void) netlib_setmacaddr(NET_DEVNAME, mac); #elif defined(CONFIG_NET_6LOWPAN) - /* Use the configured, fixed MAC address */ + /* Use the configured, fixed extended address */ -#ifdef CONFIG_NET_6LOWPAN_RIMEADDR_EXTENDED - nodeaddr[0] = (CONFIG_NSH_MACADDR >> (8 * 7)) & 0xff; - nodeaddr[1] = (CONFIG_NSH_MACADDR >> (8 * 6)) & 0xff; - nodeaddr[2] = (CONFIG_NSH_MACADDR >> (8 * 5)) & 0xff; - nodeaddr[3] = (CONFIG_NSH_MACADDR >> (8 * 4)) & 0xff; - nodeaddr[4] = (CONFIG_NSH_MACADDR >> (8 * 3)) & 0xff; - nodeaddr[5] = (CONFIG_NSH_MACADDR >> (8 * 2)) & 0xff; - nodeaddr[6] = (CONFIG_NSH_MACADDR >> (8 * 1)) & 0xff; - nodeaddr[7] = (CONFIG_NSH_MACADDR >> (8 * 0)) & 0xff; -#else - nodeaddr[0] = (CONFIG_NSH_MACADDR >> (8 * 1)) & 0xff; - nodeaddr[1] = (CONFIG_NSH_MACADDR >> (8 * 0)) & 0xff; -#endif + eaddr[0] = (CONFIG_NSH_MACADDR >> (8 * 7)) & 0xff; + eaddr[1] = (CONFIG_NSH_MACADDR >> (8 * 6)) & 0xff; + eaddr[2] = (CONFIG_NSH_MACADDR >> (8 * 5)) & 0xff; + eaddr[3] = (CONFIG_NSH_MACADDR >> (8 * 4)) & 0xff; + eaddr[4] = (CONFIG_NSH_MACADDR >> (8 * 3)) & 0xff; + eaddr[5] = (CONFIG_NSH_MACADDR >> (8 * 2)) & 0xff; + eaddr[6] = (CONFIG_NSH_MACADDR >> (8 * 1)) & 0xff; + eaddr[7] = (CONFIG_NSH_MACADDR >> (8 * 0)) & 0xff; - /* Set the 6loWPAN node address */ + /* Set the 6loWPAN extended address */ - (void)netlib_setnodeaddr(NET_DEVNAME, nodeaddr); + (void)netlib_seteaddr(NET_DEVNAME, eaddr); - /* Set the 6loWPAN PAN ID */ - - (void)netlib_setpanid(NET_DEVNAME, CONFIG_NSH_PANID); #endif /* CONFIG_NET_ETHERNET */ #endif /* CONFIG_NSH_NOMAC && HAVE_MAC */ From 22d9c69d878988d66d64e061b778756c9bbe07fa Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 17 Jun 2017 10:37:31 -0600 Subject: [PATCH 2/4] NSH network configuration: Re-factor a function that has gotten too big and too complex. --- nshlib/nsh_netinit.c | 104 ++++++++++++++++++++++++++++++++----------- 1 file changed, 79 insertions(+), 25 deletions(-) diff --git a/nshlib/nsh_netinit.c b/nshlib/nsh_netinit.c index 85720eef9..940c93e23 100644 --- a/nshlib/nsh_netinit.c +++ b/nshlib/nsh_netinit.c @@ -95,6 +95,12 @@ # define HAVE_MAC 1 #endif +/* If both are defined, behave as though only Ethernet is available */ + +#ifdef CONFIG_NET_ETHERNET +# undef CONFIG_NET_6LOWPAN +#endif + #if defined(CONFIG_NSH_DRIPADDR) && !defined(CONFIG_NSH_DNSIPADDR) # define CONFIG_NSH_DNSIPADDR CONFIG_NSH_DRIPADDR #endif @@ -227,38 +233,25 @@ static const uint16_t g_ipv6_netmask[8] = ****************************************************************************/ /**************************************************************************** - * Name: nsh_netinit_configure + * Name: nsh_set_macaddr * * Description: - * Initialize the network per the selected NuttX configuration + * Set the hardware MAC address if the hardware is not capable of doing + * that for itself. * ****************************************************************************/ -static void nsh_netinit_configure(void) +#if defined(NSH_HAVE_NETDEV) && defined(CONFIG_NSH_NOMAC) && defined(HAVE_MAC) +static void nsh_set_macaddr(void) { -#ifdef NSH_HAVE_NETDEV -#ifdef CONFIG_NET_IPv4 - struct in_addr addr; -#endif - -#if defined(CONFIG_NSH_DHCPC) && !defined(CONFIG_NSH_NETLOCAL) - FAR void *handle; -#endif - -#if (((defined(CONFIG_NSH_DHCPC) && !defined(CONFIG_NSH_NETLOCAL)) || \ - defined(CONFIG_NSH_NOMAC)) && defined(HAVE_MAC)) #if defined(CONFIG_NET_ETHERNET) uint8_t mac[IFHWADDRLEN]; #elif defined(CONFIG_NET_6LOWPAN) uint8_t eaddr[NET_6LOWPAN_ADDRSIZE]; #endif -#endif - - ninfo("Entry\n"); /* Many embedded network interfaces must have a software assigned MAC */ -#if defined(CONFIG_NSH_NOMAC) && defined(HAVE_MAC) #if defined(CONFIG_NET_ETHERNET) /* Use the configured, fixed MAC address */ @@ -290,9 +283,25 @@ static void nsh_netinit_configure(void) (void)netlib_seteaddr(NET_DEVNAME, eaddr); #endif /* CONFIG_NET_ETHERNET */ -#endif /* CONFIG_NSH_NOMAC && HAVE_MAC */ +} +#else +# define nsh_set_macaddr() +#endif +/**************************************************************************** + * Name: nsh_set_ipaddrs + * + * Description: + * Setup IP addresses. + * + ****************************************************************************/ + +#if defined(NSH_HAVE_NETDEV) +static void nsh_set_ipaddrs(void) +{ #ifdef CONFIG_NET_IPv4 + struct in_addr addr; + /* Set up our host address */ #ifndef CONFIG_NSH_DHCPC @@ -343,13 +352,30 @@ static void nsh_netinit_configure(void) addr.s_addr = HTONL(CONFIG_NSH_DNSIPADDR); netlib_set_ipv4dnsaddr(&addr); #endif +} +#else +# define nsh_set_ipaddrs() +#endif - /* That completes the 'local' initialization of the network device. */ +/**************************************************************************** + * Name: nsh_net_bringup() + * + * Description: + * Bring up the configured network + * + ****************************************************************************/ + +#if defined(NSH_HAVE_NETDEV) && !defined(CONFIG_NSH_NETLOCAL) +static void nsh_net_bringup(void) +{ +#ifdef CONFIG_NSH_DHCPC + uint8_t mac[IFHWADDRLEN]; + FAR void *handle; +#endif -#ifndef CONFIG_NSH_NETLOCAL /* Bring the network up. */ - netlib_ifup("eth0"); + netlib_ifup(NET_DEVNAME); #ifdef CONFIG_WIRELESS_WAPI /* Associate the wlan with an access point. */ @@ -400,10 +426,38 @@ static void nsh_netinit_configure(void) ntpc_start(); #endif -#endif /* CONFIG_NSH_NETLOCAL */ -#endif /* NSH_HAVE_NETDEV */ +} +#else +# define nsh_net_bringup() +#endif - ninfo("Exit\n"); +/**************************************************************************** + * Name: nsh_netinit_configure + * + * Description: + * Initialize the network per the selected NuttX configuration + * + ****************************************************************************/ + +static void nsh_netinit_configure(void) +{ +#ifdef NSH_HAVE_NETDEV + /* Many embedded network interfaces must have a software assigned MAC */ + + nsh_set_macaddr(); + + /* Set up IP addresses */ + + nsh_set_ipaddrs(); + + /* That completes the 'local' initialization of the network device. */ + +#ifndef CONFIG_NSH_NETLOCAL + /* Bring the network up. */ + + nsh_net_bringup(); +#endif +#endif /* NSH_HAVE_NETDEV */ } /**************************************************************************** From 9485744265aaf2bef76c28cb49396163951cbbc0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 17 Jun 2017 11:31:04 -0600 Subject: [PATCH 3/4] NSH network initialization: Do not set the IP address for 6loWPAN. The 6loWPAN stack uses IP address that derive from the ieee 802.15.4 addressing and cannot be (safely) configured by the user. --- nshlib/Kconfig | 5 ++++- nshlib/nsh_netinit.c | 49 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/nshlib/Kconfig b/nshlib/Kconfig index 8c7cb30f4..cabfd52b2 100644 --- a/nshlib/Kconfig +++ b/nshlib/Kconfig @@ -1129,7 +1129,10 @@ config NSH_NETINIT_DEBUG or CONFIG_DEBUG_INFO are not selected. This allows for focused, unit- level debug of the NSH network initialization logic. +# No IP address if 6LOWPAN selected; but Ethernet has precedence. + menu "IP Address Configuration" + depends on NET_ETHERNET || !NET_6LOWPAN config NSH_DHCPC bool "Use DHCP to get IP address" @@ -1426,7 +1429,7 @@ config NSH_IPv6NETMASK_8 individually. This is the eighth of the 8-values. The default for all eight values is fe00::0. -endif #NET_IPv6 && !NET_ICMPv6_AUTOCONF +endif # NET_IPv6 && !NET_ICMPv6_AUTOCONF endmenu # IP Address Configuration config NSH_DNS diff --git a/nshlib/nsh_netinit.c b/nshlib/nsh_netinit.c index 940c93e23..674c8c036 100644 --- a/nshlib/nsh_netinit.c +++ b/nshlib/nsh_netinit.c @@ -88,6 +88,39 @@ * Pre-processor Definitions ****************************************************************************/ +/* Pick one and at most one supported link layer so that all decisions are + * made consistently. + */ + +#if defined(CONFIG_NET_ETHERNET) +# undef CONFIG_NET_6LOWPAN +# undef CONFIG_NET_SLIP +# undef CONFIG_NET_TUN +# undef CONFIG_NET_LOCAL +# undef CONFIG_NET_USRSOCK +# undef CONFIG_NET_LOOPBACK +#elif defined(CONFIG_NET_6LOWPAN) +# undef CONFIG_NET_SLIP +# undef CONFIG_NET_TUN +# undef CONFIG_NET_LOCAL +# undef CONFIG_NET_USRSOCK +# undef CONFIG_NET_LOOPBACK +#elif defined(CONFIG_NET_SLIP) +# undef CONFIG_NET_TUN +# undef CONFIG_NET_LOCAL +# undef CONFIG_NET_USRSOCK +# undef CONFIG_NET_LOOPBACK +#elif defined(CONFIG_NET_TUN) +# undef CONFIG_NET_LOCAL +# undef CONFIG_NET_USRSOCK +# undef CONFIG_NET_LOOPBACK +#elif defined(CONFIG_NET_LOCAL) +# undef CONFIG_NET_USRSOCK +# undef CONFIG_NET_LOOPBACK +#elif defined(CONFIG_NET_USRSOCK) +# undef CONFIG_NET_LOOPBACK +#endif + /* Only Ethernet and 6loWPAN have MAC layer addresses */ #undef HAVE_MAC @@ -95,11 +128,7 @@ # define HAVE_MAC 1 #endif -/* If both are defined, behave as though only Ethernet is available */ - -#ifdef CONFIG_NET_ETHERNET -# undef CONFIG_NET_6LOWPAN -#endif +/* Provide a default DNS address */ #if defined(CONFIG_NSH_DRIPADDR) && !defined(CONFIG_NSH_DNSIPADDR) # define CONFIG_NSH_DNSIPADDR CONFIG_NSH_DRIPADDR @@ -184,7 +213,8 @@ static sem_t g_notify_sem; #endif -#if defined(CONFIG_NET_IPv6) && !defined(CONFIG_NET_ICMPv6_AUTOCONF) +#if defined(CONFIG_NET_IPv6) && !defined(CONFIG_NET_ICMPv6_AUTOCONF) && \ + !defined(CONFIG_NET_6LOWPAN) /* Host IPv6 address */ static const uint16_t g_ipv6_hostaddr[8] = @@ -226,7 +256,7 @@ static const uint16_t g_ipv6_netmask[8] = HTONS(CONFIG_NSH_IPv6NETMASK_7), HTONS(CONFIG_NSH_IPv6NETMASK_8), }; -#endif /* CONFIG_NET_IPv6 && !CONFIG_NET_ICMPv6_AUTOCONF */ +#endif /* CONFIG_NET_IPv6 && !CONFIG_NET_ICMPv6_AUTOCONF && !CONFIG_NET_6LOWPAN */ /**************************************************************************** * Private Functions @@ -294,9 +324,12 @@ static void nsh_set_macaddr(void) * Description: * Setup IP addresses. * + * For 6loWPAN, the IP address derives from the MAC address. Setting it + * to any user provided value is asking for trouble. + * ****************************************************************************/ -#if defined(NSH_HAVE_NETDEV) +#if defined(NSH_HAVE_NETDEV) && !defined(CONFIG_NET_6LOWPAN) static void nsh_set_ipaddrs(void) { #ifdef CONFIG_NET_IPv4 From 14b10bffef84d707fe6a1b22a69baab773341a4c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 17 Jun 2017 11:32:00 -0600 Subject: [PATCH 4/4] Add missing that I forgot to add in a previous commit. --- netutils/netlib/netlib_seteaddr.c | 94 +++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 netutils/netlib/netlib_seteaddr.c diff --git a/netutils/netlib/netlib_seteaddr.c b/netutils/netlib/netlib_seteaddr.c new file mode 100644 index 000000000..251653b22 --- /dev/null +++ b/netutils/netlib/netlib_seteaddr.c @@ -0,0 +1,94 @@ +/**************************************************************************** + * netutils/netlib/netlib_seteaddr.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include + +#include "wireless/ieee802154.h" +#include "netutils/netlib.h" + +#if defined(CONFIG_NET_6LOWPAN) && CONFIG_NSOCKET_DESCRIPTORS > 0 + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: netlib_seteaddr + * + * Description: + * Set the IEEE802.15.4 extended MAC address + * + * Parameters: + * ifname The name of the interface to use + * eaddr The new extended address + * + * Return: + * 0 on success; -1 on failure. errno will be set on failure. + * + ****************************************************************************/ + +int netlib_seteaddr(FAR const char *ifname, FAR const uint8_t *eaddr) +{ + int ret = ERROR; + + if (ifname != NULL) + { + /* Get a socket (only so that we get access to the INET subsystem) */ + + int sockfd = socket(PF_INET6, NETLIB_SOCK_IOCTL, 0); + if (sockfd >= 0) + { + /* Use the helper provided in libmac */ + + ret = sixlowpan_seteaddr(sockfd, ifname, eaddr); + close(sockfd); + } + } + + return ret; +} + +#endif /* CONFIG_NET_6LOWPAN && CONFIG_NSOCKET_DESCRIPTORS */