Merge remote-tracking branch 'origin/master' into ieee802154

This commit is contained in:
Gregory Nutt 2017-04-19 18:11:17 -06:00
commit 9ef7d4830a
8 changed files with 238 additions and 5 deletions

View File

@ -117,7 +117,9 @@ int netlib_getmacaddr(FAR const char *ifname, FAR uint8_t *macaddr);
#ifdef CONFIG_NET_6LOWPAN
/* Get IEEE802.15.4 MAC driver node address */
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);
#endif

View File

@ -87,7 +87,8 @@ CSRCS += netlib_setmacaddr.c netlib_getmacaddr.c
endif
ifeq ($(CONFIG_NET_6LOWPAN),y)
CSRCS += netlib_setnodeaddr.c netlib_nodeaddrconv.c
CSRCS += netlib_getpanid.c netlib_setnodeaddr.c netlib_setpanid.c
CSRCS += netlib_nodeaddrconv.c
endif
# IGMP support

View File

@ -0,0 +1,109 @@
/****************************************************************************
* netutils/netlib/netlib_getpanid.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 <nuttx/config.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <netinet/in.h>
#include <net/if.h>
#include <nuttx/net/sixlowpan.h>
#include <nuttx/wireless/wireless.h>
#include "netutils/netlib.h"
#if defined(CONFIG_NET_6LOWPAN) && CONFIG_NSOCKET_DESCRIPTORS > 0
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: netlib_getpanid
*
* Description:
* Return the current PAN ID
*
* Parameters:
* ifname The name of the interface to use
* panid The location to return the current PAN ID
*
* Return:
* 0 on success; -1 on failure. errno will be set on failure.
*
****************************************************************************/
int netlib_getpanid(FAR const char *ifname, FAR uint16_t *panid)
{
int ret = ERROR;
if (ifname != NULL && panid != 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)
{
struct sixlowpan_req_s req;
/* Put the driver name into the request */
strncpy(req.ifr_name, ifname, IFNAMSIZ);
/* Perform the ioctl to get the current PAN ID */
ret = ioctl(sockfd, SIOCGWPANID, (unsigned long)((uintptr_t)&req));
close(sockfd);
/* Reuturn the current PAN ID */
*panid = req.u.panid.panid;
}
}
return ret;
}
#endif /* CONFIG_NET_6LOWPAN && CONFIG_NSOCKET_DESCRIPTORS */

View File

@ -96,7 +96,7 @@ int netlib_setnodeaddr(FAR const char *ifname, FAR const uint8_t *nodeaddr)
req.ifr_hwaddr.sa_family = AF_INET6;
memcpy(&req.ifr_hwaddr.sa_data, nodeaddr, NET_6LOWPAN_RIMEADDR_SIZE);
/* Perform the ioctl to set the MAC address */
/* Perform the ioctl to set the node address */
ret = ioctl(sockfd, SIOCSIFHWADDR, (unsigned long)&req);
close(sockfd);

View File

@ -0,0 +1,109 @@
/****************************************************************************
* netutils/netlib/netlib_setpanid.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 <nuttx/config.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <netinet/in.h>
#include <net/if.h>
#include <nuttx/net/sixlowpan.h>
#include <nuttx/wireless/wireless.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)
{
struct sixlowpan_req_s req;
/* Put the driver name into the request */
strncpy(req.ifr_name, ifname, IFNAMSIZ);
/* Put the new PAN ID into the request */
req.u.panid.panid = panid;
/* Perform the ioctl to set the new PAN ID */
ret = ioctl(sockfd, SIOCSWPANID, (unsigned long)((uintptr_t)&req));
close(sockfd);
}
}
return ret;
}
#endif /* CONFIG_NET_6LOWPAN && CONFIG_NSOCKET_DESCRIPTORS */

View File

@ -1456,6 +1456,15 @@ config NSH_MACADDR
MAC address must provided with this selection.
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.
endif # NSH_NETINIT
config NSH_MAX_ROUNDTRIP

View File

@ -314,9 +314,9 @@ static int cmd_codecs_proc(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv,
fullpath = nsh_getfullpath(vtbl, localfile);
/* Open the local file for writing */
/* Open the local file for reading */
fd = open(fullpath, O_RDONLY|O_TRUNC, 0644);
fd = open(fullpath, O_RDONLY);
if (fd < 0)
{
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);

View File

@ -295,8 +295,11 @@ static void nsh_netinit_configure(void)
/* Set the 6loWPAN node address */
netlib_setnodeaddr(NET_DEVNAME, nodeaddr);
(void)netlib_setnodeaddr(NET_DEVNAME, nodeaddr);
/* Set the 6loWPAN PAN ID */
(void)netlib_setpanid(NET_DEVNAME, CONFIG_NSH_PANID);
#endif /* CONFIG_NET_ETHERNET */
#endif /* CONFIG_NSH_NOMAC && HAVE_MAC */