diff --git a/examples/nettest/Makefile b/examples/nettest/Makefile index 6fc5a26af..a76a15d46 100644 --- a/examples/nettest/Makefile +++ b/examples/nettest/Makefile @@ -99,9 +99,6 @@ else INSTALL_DIR = $(BIN_DIR) endif -CONFIG_XYZ_PROGNAME ?= nettest$(EXEEXT) -PROGNAME = $(CONFIG_XYZ_PROGNAME) - ROOTDEPPATH = --dep-path . # NET test built-in application info diff --git a/examples/udpblaster/Kconfig b/examples/udpblaster/Kconfig index a65b41d81..d31683431 100644 --- a/examples/udpblaster/Kconfig +++ b/examples/udpblaster/Kconfig @@ -12,6 +12,22 @@ config EXAMPLES_UDPBLASTER if EXAMPLES_UDPBLASTER +config EXAMPLES_UDPBLASTER_PROGNAME + string "Program name" + default "nettest" + depends on BUILD_KERNEL + ---help--- + This is the name of the program that will be use when the Nettest + program is installed. + +config EXAMPLES_UDPBLASTER_STACKSIZE + int "Nettest stack size" + default 2048 + +config EXAMPLES_UDPBLASTER_PRIORITY + int "Nettest priority" + default 100 + config EXAMPLES_UDPBLASTER_HOSTRATE int "Host send rate (bits/second)" default 800000 @@ -153,87 +169,87 @@ config EXAMPLES_UDPBLASTER_TARGETIPv6_8 specified individually. This is the last of the 8-values. The default for all eight values is fc00::2. -comment "Router IPv6 address" +comment "Host IPv6 address" config EXAMPLES_UDPBLASTER_HOSTIPv6_1 hex "[0]" default 0xfc00 range 0x0 0xffff ---help--- - Default router IP address (aka, Gateway). This is a 16-bit integer - value in host order. Each of the eight values forming the full IP - address must be specified individually. This is the first of the - 8-values. The default for all eight values is fc00::1. + Host IP address. This is a 16-bit integer value in host order. + Each of the eight values forming the full IP address must be + specified individually. This is the first of the 8-values. + The default for all eight values is fc00::1. config EXAMPLES_UDPBLASTER_HOSTIPv6_2 hex "[1]" default 0x0000 range 0x0 0xffff ---help--- - Default router IP address (aka, Gateway). This is a 16-bit integer - value in host order. Each of the eight values forming the full IP - address must be specified individually. This is the second of the - 8-values. The default for all eight values is fc00::1. + Host IP address. This is a 16-bit integer value in host order. + Each of the eight values forming the full IP address must be + specified individually. This is the second of the 8-values. + The default for all eight values is fc00::1. config EXAMPLES_UDPBLASTER_HOSTIPv6_3 hex "[2]" default 0x0000 range 0x0 0xffff ---help--- - Default router IP address (aka, Gateway). This is a 16-bit integer - value in host order. Each of the eight values forming the full IP - address must be specified individually. This is the third of the - 8-values. The default for all eight values is fc00::1. + Host IP address. This is a 16-bit integer value in host order. + Each of the eight values forming the full IP address must be + specified individually. This is the third of the 8-values. + The default for all eight values is fc00::1. config EXAMPLES_UDPBLASTER_HOSTIPv6_4 hex "[3]" default 0x0000 range 0x0 0xffff ---help--- - Default router IP address (aka, Gateway). This is a 16-bit integer - value in host order. Each of the eight values forming the full IP - address must be specified individually. This is the fourth of the - 8-values. The default for all eight values is fc00::1. + Host IP address. This is a 16-bit integer value in host order. + Each of the eight values forming the full IP address must be + specified individually. This is the fourth of the 8-values. + The default for all eight values is fc00::1. config EXAMPLES_UDPBLASTER_HOSTIPv6_5 hex "[4]" default 0x0000 range 0x0 0xffff ---help--- - Default router IP address (aka, Gateway). This is a 16-bit integer - value in host order. Each of the eight values forming the full IP - address must be specified individually. This is the fifth of the - 8-values. The default for all eight values is fc00::1. + Host IP address. This is a 16-bit integer value in host order. + Each of the eight values forming the full IP address must be + specified individually. This is the fifth of the 8-values. + The default for all eight values is fc00::1. config EXAMPLES_UDPBLASTER_HOSTIPv6_6 hex "[5]" default 0x0000 range 0x0 0xffff ---help--- - Default router IP address (aka, Gateway). This is a 16-bit integer - value in host order. Each of the eight values forming the full IP - address must be specified individually. This is the sixth of the - 8-values. The default for all eight values is fc00::1. + Host IP address. This is a 16-bit integer value in host order. + Each of the eight values forming the full IP address must be + specified individually. This is the sixth of the 8-values. + The default for all eight values is fc00::1. config EXAMPLES_UDPBLASTER_HOSTIPv6_7 hex "[6]" default 0x0000 range 0x0 0xffff ---help--- - Default router IP address (aka, Gateway). This is a 16-bit integer - value in host order. Each of the eight values forming the full IP - address must be specified individually. This is the seventh of the - 8-values. The default for all eight values is fc00::1. + Host IP address. This is a 16-bit integer value in host order. + Each of the eight values forming the full IP address must be + specified individually. This is the seventh of the 8-values. + The default for all eight values is fc00::1. config EXAMPLES_UDPBLASTER_HOSTIPv6_8 hex "[7]" default 0x0001 range 0x0 0xffff ---help--- - Default router IP address (aka, Gateway). This is a 16-bit integer - value in host order. Each of the eight values forming the full IP - address must be specified individually. This is the last of the - 8-values. The default for all eight values is fc00::1. + Host IP address. This is a 16-bit integer value in host order. + Each of the eight values forming the full IP address must be + specified individually. This is the last of the 8-values. + The default for all eight values is fc00::1. if EXAMPLES_UDPBLASTER_INIT diff --git a/examples/udpblaster/Makefile b/examples/udpblaster/Makefile index f014d68fc..469c2a212 100644 --- a/examples/udpblaster/Makefile +++ b/examples/udpblaster/Makefile @@ -79,16 +79,19 @@ else INSTALL_DIR = $(BIN_DIR) endif -CONFIG_XYZ_PROGNAME ?= udpblaster$(EXEEXT) -PROGNAME = $(CONFIG_XYZ_PROGNAME) +CONFIG_UPBLASTER_PROGNAME ?= udpblaster$(EXEEXT) +PROGNAME = $(CONFIG_UPBLASTER_PROGNAME) ROOTDEPPATH = --dep-path . # NET test built-in application info +CONFIG_EXAMPLES_UDPBLASTER_STACKSIZE ?= 2048 +CONFIG_EXAMPLES_UDPBLASTER_PRIORITY ?= 100 + APPNAME = udpblaster -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 2048 +PRIORITY = $(CONFIG_EXAMPLES_UDPBLASTER_PRIORITY) +STACKSIZE = $(CONFIG_EXAMPLES_UDPBLASTER_STACKSIZE) # Common build diff --git a/examples/udpblaster/udpblaster.h b/examples/udpblaster/udpblaster.h index 6e2a21db3..8ae5cad5e 100644 --- a/examples/udpblaster/udpblaster.h +++ b/examples/udpblaster/udpblaster.h @@ -74,7 +74,13 @@ # define PF_INETX PF_INET #endif -#define UDPBLASTER_PORTNO 5471 +#ifdef CONFIG_NET_6LOWPAN +# define UDPBLASTER_HOST_PORTNO 0xf0b0 +# define UDPBLASTER_TARGET_PORTNO 0xf0b1 +#else +# define UDPBLASTER_HOST_PORTNO 5471 +# define UDPBLASTER_TARGET_PORTNO 5472 +#endif #define ETH_HDRLEN 14 /* Size of the Ethernet header */ #define IPv4_HDRLEN 20 /* Size of IPv4 header */ @@ -88,7 +94,6 @@ # else # define UDPBLASTER_MSS (UDPBLASTER_MTU - ETH_HDRLEN - IPv4_HDRLEN - UDP_HDRLEN) # endif -# #elif defined(CONFIG_NET_LOOPBACK) # define UDPBLASTER_MTU 1518 # ifdef CONFIG_EXAMPLES_UDPBLASTER_IPv6 @@ -96,6 +101,9 @@ # else # define UDPBLASTER_MSS (UDPBLASTER_MTU - IPv4_HDRLEN - UDP_HDRLEN) # endif +#elif defined(CONFIG_NET_6LOWPAN) +# define UDPBLASTER_MTU CONFIG_NET_6LOWPAN_MTU +# define UDPBLASTER_MSS (CONFIG_NET_6LOWPAN_MTU - IPv6_HDRLEN - UDP_HDRLEN) #elif defined(CONFIG_NET_SLIP) # define UDPBLASTER_MTU CONFIG_NET_SLIP_MTU # ifdef CONFIG_EXAMPLES_UDPBLASTER_IPv6 diff --git a/examples/udpblaster/udpblaster_host.c b/examples/udpblaster/udpblaster_host.c index c2dfcd201..67f3067d4 100644 --- a/examples/udpblaster/udpblaster_host.c +++ b/examples/udpblaster/udpblaster_host.c @@ -48,14 +48,6 @@ #include "udpblaster.h" -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - /**************************************************************************** * main ****************************************************************************/ @@ -77,7 +69,7 @@ int main(int argc, char **argv, char **envp) #ifdef CONFIG_EXAMPLES_UDPBLASTER_IPv4 target.sin_family = AF_INET; - target.sin_port = HTONS(UDPBLASTER_PORTNO); + target.sin_port = HTONS(UDPBLASTER_TARGET_PORTNO); target.sin_addr.s_addr = HTONL(CONFIG_EXAMPLES_UDPBLASTER_TARGETIP); addrlen = sizeof(struct sockaddr_in); @@ -90,15 +82,15 @@ int main(int argc, char **argv, char **envp) #else target.sin6_family = AF_INET6; - target.sin6_port = HTONS(UDPBLASTER_PORTNO); - target.sin6_addr.s6_addr16[0] = HTONL(EXAMPLES_UDPBLASTER_TARGETIPv6_1); - target.sin6_addr.s6_addr16[1] = HTONL(EXAMPLES_UDPBLASTER_TARGETIPv6_2); - target.sin6_addr.s6_addr16[2] = HTONL(EXAMPLES_UDPBLASTER_TARGETIPv6_3); - target.sin6_addr.s6_addr16[3] = HTONL(EXAMPLES_UDPBLASTER_TARGETIPv6_4); - target.sin6_addr.s6_addr16[4] = HTONL(EXAMPLES_UDPBLASTER_TARGETIPv6_5); - target.sin6_addr.s6_addr16[5] = HTONL(EXAMPLES_UDPBLASTER_TARGETIPv6_6); - target.sin6_addr.s6_addr16[6] = HTONL(EXAMPLES_UDPBLASTER_TARGETIPv6_7); - target.sin6_addr.s6_addr16[7] = HTONL(EXAMPLES_UDPBLASTER_TARGETIPv6_8); + target.sin6_port = HTONS(UDPBLASTER_TARGET_PORTNO); + target.sin6_addr.s6_addr16[0] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_TARGETIPv6_1); + target.sin6_addr.s6_addr16[1] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_TARGETIPv6_2); + target.sin6_addr.s6_addr16[2] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_TARGETIPv6_3); + target.sin6_addr.s6_addr16[3] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_TARGETIPv6_4); + target.sin6_addr.s6_addr16[4] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_TARGETIPv6_5); + target.sin6_addr.s6_addr16[5] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_TARGETIPv6_6); + target.sin6_addr.s6_addr16[6] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_TARGETIPv6_7); + target.sin6_addr.s6_addr16[7] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_TARGETIPv6_8); addrlen = sizeof(struct sockaddr_in6); sockfd = socket(PF_INET6, SOCK_DGRAM, 0); diff --git a/examples/udpblaster/udpblaster_target.c b/examples/udpblaster/udpblaster_target.c index a656f0090..7f0e286ba 100644 --- a/examples/udpblaster/udpblaster_target.c +++ b/examples/udpblaster/udpblaster_target.c @@ -192,8 +192,10 @@ int udpblaster_main(int argc, char *argv[]) { #ifdef CONFIG_EXAMPLES_UDPBLASTER_IPv4 struct sockaddr_in host; + struct sockaddr_in target; #else struct sockaddr_in6 host; + struct sockaddr_in6 target; #endif socklen_t addrlen; int npackets; @@ -209,10 +211,9 @@ int udpblaster_main(int argc, char *argv[]) #ifdef CONFIG_EXAMPLES_UDPBLASTER_IPv4 host.sin_family = AF_INET; - host.sin_port = HTONS(UDPBLASTER_PORTNO); + host.sin_port = HTONS(UDPBLASTER_HOST_PORTNO); host.sin_addr.s_addr = HTONL(CONFIG_EXAMPLES_UDPBLASTER_HOSTIP); - addrlen = sizeof(struct sockaddr_in); sockfd = socket(PF_INET, SOCK_DGRAM, 0); if (sockfd < 0) { @@ -220,23 +221,51 @@ int udpblaster_main(int argc, char *argv[]) return 1; } -#else - host.sin6_family = AF_INET6; - host.sin6_port = HTONS(UDPBLASTER_PORTNO); - host.sin6_addr.s6_addr16[0] = HTONL(EXAMPLES_UDPBLASTER_HOSTIPv6_1); - host.sin6_addr.s6_addr16[1] = HTONL(EXAMPLES_UDPBLASTER_HOSTIPv6_2); - host.sin6_addr.s6_addr16[2] = HTONL(EXAMPLES_UDPBLASTER_HOSTIPv6_3); - host.sin6_addr.s6_addr16[3] = HTONL(EXAMPLES_UDPBLASTER_HOSTIPv6_4); - host.sin6_addr.s6_addr16[4] = HTONL(EXAMPLES_UDPBLASTER_HOSTIPv6_5); - host.sin6_addr.s6_addr16[5] = HTONL(EXAMPLES_UDPBLASTER_HOSTIPv6_6); - host.sin6_addr.s6_addr16[6] = HTONL(EXAMPLES_UDPBLASTER_HOSTIPv6_7); - host.sin6_addr.s6_addr16[7] = HTONL(EXAMPLES_UDPBLASTER_HOSTIPv6_8); + target.sin_family = AF_INET; + target.sin_port = HTONS(UDPBLASTER_TARGET_PORTNO); + target.sin_addr.s_addr = HTONL(CONFIG_EXAMPLES_UDPBLASTER_TARGETIP); + addrlen = sizeof(struct sockaddr_in); - addrlen = sizeof(struct sockaddr_in6); - sockfd = socket(PF_INET6, SOCK_DGRAM, 0); + if (bind(sockfd, (struct sockaddr*)&target, addrlen) < 0) + { + printf("server: ERROR bind failure: %d\n", errno); + return 1; + } + +#else + host.sin6_family = AF_INET6; + host.sin6_port = HTONS(UDPBLASTER_HOST_PORTNO); + host.sin6_addr.s6_addr16[0] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_HOSTIPv6_1); + host.sin6_addr.s6_addr16[1] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_HOSTIPv6_2); + host.sin6_addr.s6_addr16[2] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_HOSTIPv6_3); + host.sin6_addr.s6_addr16[3] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_HOSTIPv6_4); + host.sin6_addr.s6_addr16[4] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_HOSTIPv6_5); + host.sin6_addr.s6_addr16[5] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_HOSTIPv6_6); + host.sin6_addr.s6_addr16[6] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_HOSTIPv6_7); + host.sin6_addr.s6_addr16[7] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_HOSTIPv6_8); + + sockfd = socket(PF_INET6, SOCK_DGRAM, 0); if (sockfd < 0) { - fprintf(stderr, "ERROR: socket() failed: %d\n", errno) + fprintf(stderr, "ERROR: socket() failed: %d\n", errno); + return 1; + } + + target.sin6_family = AF_INET6; + target.sin6_port = HTONS(UDPBLASTER_TARGET_PORTNO); + target.sin6_addr.s6_addr16[0] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_TARGETIPv6_1); + target.sin6_addr.s6_addr16[1] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_TARGETIPv6_2); + target.sin6_addr.s6_addr16[2] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_TARGETIPv6_3); + target.sin6_addr.s6_addr16[3] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_TARGETIPv6_4); + target.sin6_addr.s6_addr16[4] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_TARGETIPv6_5); + target.sin6_addr.s6_addr16[5] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_TARGETIPv6_6); + target.sin6_addr.s6_addr16[6] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_TARGETIPv6_7); + target.sin6_addr.s6_addr16[7] = HTONS(CONFIG_EXAMPLES_UDPBLASTER_TARGETIPv6_8); + addrlen = sizeof(struct sockaddr_in6); + + if (bind(sockfd, (struct sockaddr*)&target, addrlen) < 0) + { + printf("server: ERROR bind failure: %d\n", errno); return 1; } #endif diff --git a/include/netutils/netlib.h b/include/netutils/netlib.h index 7a67282d7..697d973c2 100644 --- a/include/netutils/netlib.h +++ b/include/netutils/netlib.h @@ -114,6 +114,12 @@ int netlib_setmacaddr(FAR const char *ifname, FAR const uint8_t *macaddr); int netlib_getmacaddr(FAR const char *ifname, FAR uint8_t *macaddr); #endif +#ifdef CONFIG_NET_ETHERNET +/* Get IEEE802.15.4 MAC driver node address */ + +int netlib_setnodeaddr(FAR const char *ifname, FAR const uint8_t *nodeaddr); +#endif + /* IP address support */ #ifdef CONFIG_NET_IPv4 diff --git a/netutils/netlib/Makefile b/netutils/netlib/Makefile index b17c97f59..35030cab5 100644 --- a/netutils/netlib/Makefile +++ b/netutils/netlib/Makefile @@ -37,7 +37,7 @@ -include $(TOPDIR)/Make.defs include $(APPDIR)/Make.defs -# UIP Library +# Network Library ASRCS = CSRCS = netlib_ipv4addrconv.c netlib_ethaddrconv.c netlib_parsehttpurl.c @@ -80,12 +80,16 @@ ifeq ($(CONFIG_NETDEV_WIRELESS_IOCTL),y) CSRCS += netlib_getessid.c netlib_setessid.c endif -# No MAC address support for SLIP (Ethernet only) +# MAC address support(Ethernet and 6loWPAN only) ifeq ($(CONFIG_NET_ETHERNET),y) CSRCS += netlib_setmacaddr.c netlib_getmacaddr.c endif +ifeq ($(CONFIG_NET_6LOWPAN),y) +CSRCS += netlib_setnodeaddr.c +endif + # IGMP support ifeq ($(CONFIG_NET_IGMP),y) diff --git a/netutils/netlib/netlib_setmacaddr.c b/netutils/netlib/netlib_setmacaddr.c index 8847ff6f8..d404c1af1 100644 --- a/netutils/netlib/netlib_setmacaddr.c +++ b/netutils/netlib/netlib_setmacaddr.c @@ -52,9 +52,6 @@ #include "netutils/netlib.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ diff --git a/netutils/netlib/netlib_setnodeaddr.c b/netutils/netlib/netlib_setnodeaddr.c new file mode 100644 index 000000000..942186070 --- /dev/null +++ b/netutils/netlib/netlib_setnodeaddr.c @@ -0,0 +1,107 @@ +/**************************************************************************** + * 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 "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 CONFIG_NET_6LOWPAN_RIMEADDR_SIZE + * + * 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, CONFIG_NET_6LOWPAN_RIMEADDR_SIZE); + + /* Perform the ioctl to set the MAC address */ + + ret = ioctl(sockfd, SIOCSIFHWADDR, (unsigned long)&req); + close(sockfd); + } + } + + return ret; +} + +#endif /* CONFIG_NET_6LOWPAN && CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nshlib/nsh_netinit.c b/nshlib/nsh_netinit.c index 8ee0958ef..38c862a30 100644 --- a/nshlib/nsh_netinit.c +++ b/nshlib/nsh_netinit.c @@ -84,6 +84,20 @@ * Pre-processor Definitions ****************************************************************************/ +/* Only Ethernet and 6loWPAN have MAC layer addresses */ + +#undef HAVE_MAC +#if defined(CONFIG_NET_ETHERNET) || defined(CONFIG_NET_6LOWPAN) +# define HAVE_MAC 1 +# if defined(CONFIG_NET_6LOWPAN) +# if (CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2) && CONFIG_NSH_MACADDR > 0xffff +# error Invalid 6loWPAN node address for SIZE == 2 +# elif (CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 8) && CONFIG_NSH_MACADDR > 0xffffffffffffffffull +# error Invalid 6loWPAN node address for SIZE == 8 +# endif +# endif +#endif + #if defined(CONFIG_NSH_DRIPADDR) && !defined(CONFIG_NSH_DNSIPADDR) # define CONFIG_NSH_DNSIPADDR CONFIG_NSH_DRIPADDR #endif @@ -226,19 +240,25 @@ static void nsh_netinit_configure(void) #ifdef CONFIG_NET_IPv4 struct in_addr addr; #endif + #if defined(CONFIG_NSH_DHCPC) FAR void *handle; #endif -#if (defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_NOMAC)) && \ - defined(CONFIG_NET_ETHERNET) + +#if (defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_NOMAC)) && defined(HAVE_MAC) +#if defined(CONFIG_NET_ETHERNET) uint8_t mac[IFHWADDRLEN]; +#elif defined(CONFIG_NET_6LOWPAN) + uint8_t nodeaddr[CONFIG_NET_6LOWPAN_RIMEADDR_SIZE]; +#endif #endif ninfo("Entry\n"); /* Many embedded network interfaces must have a software assigned MAC */ -#if defined(CONFIG_NSH_NOMAC) && defined(CONFIG_NET_ETHERNET) +#if defined(CONFIG_NSH_NOMAC) && defined(HAVE_MAC) +#if defined(CONFIG_NET_ETHERNET) /* Use the configured, fixed MAC address */ mac[0] = (CONFIG_NSH_MACADDR >> (8 * 5)) & 0xff; @@ -252,7 +272,29 @@ static void nsh_netinit_configure(void) netlib_setmacaddr(NET_DEVNAME, mac); -#endif /* CONFIG_NSH_NOMAC && CONFIG_NET_ETHERNET */ +#elif defined(CONFIG_NET_6LOWPAN) + /* Use the configured, fixed MAC address */ + +#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2 + nodeaddr[0] = (CONFIG_NSH_MACADDR >> (8 * 1)) & 0xff; + nodeaddr[1] = (CONFIG_NSH_MACADDR >> (8 * 0)) & 0xff; +#elif CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 8 + 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; +#endif + + /* Set the 6loWPAN node address */ + + netlib_setnodeaddr(NET_DEVNAME, nodeaddr); + +#endif /* CONFIG_NET_ETHERNET */ +#endif /* CONFIG_NSH_NOMAC && HAVE_MAC */ #ifdef CONFIG_NET_IPv4 /* Set up our host address */