From 033b42789b8757056612191c9615cb9d2c9811e8 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 17 Jun 2017 10:04:18 -0600 Subject: [PATCH] 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 */