2017-08-02 20:40:50 +02:00
|
|
|
/****************************************************************************
|
2021-06-16 10:26:22 +02:00
|
|
|
* apps/netutils/netlib/netlib_setnodnodeaddr.c
|
2017-08-02 20:40:50 +02:00
|
|
|
*
|
2021-06-11 06:22:42 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2017-08-02 20:40:50 +02:00
|
|
|
*
|
2021-06-11 06:22:42 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2017-08-02 20:40:50 +02:00
|
|
|
*
|
2021-06-11 06:22:42 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2017-08-02 20:40:50 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "nuttx/wireless/pktradio.h"
|
|
|
|
#include "netutils/netlib.h"
|
|
|
|
|
2019-02-11 23:23:55 +01:00
|
|
|
#if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_IEEE802154)
|
2017-08-02 20:40:50 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netlib_setnodnodeaddr
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set the non-IEEE802.15.4 packet radio node address
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* ifname - The name of the interface to use
|
|
|
|
* nodeadd - The new node address
|
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* 0 on success; -1 on failure. errno will be set on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int netlib_setnodeaddr(FAR const char *ifname,
|
|
|
|
FAR const struct pktradio_addr_s *nodeaddr)
|
|
|
|
{
|
|
|
|
struct pktradio_ifreq_s req;
|
|
|
|
int ret = ERROR;
|
|
|
|
|
|
|
|
DEBUGASSERT(ifname != NULL && nodeaddr != NULL);
|
|
|
|
if (ifname != NULL)
|
|
|
|
{
|
|
|
|
/* Get a socket (only so that we get access to the INET subsystem) */
|
|
|
|
|
2017-10-30 21:16:37 +01:00
|
|
|
int sockfd = socket(PF_INET6, NETLIB_SOCK_TYPE, 0);
|
2017-08-02 20:40:50 +02:00
|
|
|
if (sockfd >= 0)
|
|
|
|
{
|
|
|
|
/* Copy the network interface name */
|
|
|
|
|
|
|
|
strncpy(req.pifr_name, ifname, IFNAMSIZ);
|
|
|
|
|
|
|
|
/* Copy the node address into the request */
|
|
|
|
|
|
|
|
memcpy(&req.pifr_hwaddr, nodeaddr, sizeof(struct pktradio_addr_s));
|
|
|
|
|
|
|
|
/* And perform the IOCTL command */
|
|
|
|
|
|
|
|
ret = ioctl(sockfd, SIOCPKTRADIOSNODE,
|
|
|
|
(unsigned long)((uintptr_t)&req));
|
|
|
|
close(sockfd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-02-11 23:23:55 +01:00
|
|
|
#endif /* CONFIG_NET_6LOWPAN || CONFIG_NET_IEEE802154 */
|