2007-09-16 19:46:25 +02:00
|
|
|
/****************************************************************************
|
2014-06-27 17:56:45 +02:00
|
|
|
* net/netdev/netdev_ioctl.c
|
2007-09-16 19:46:25 +02:00
|
|
|
*
|
2017-03-14 00:59:36 +01:00
|
|
|
* Copyright (C) 2007-2012, 2015-2017 Gregory Nutt. All rights reserved.
|
2012-03-04 00:18:34 +01:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2007-09-16 19:46:25 +02:00
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
|
|
|
|
|
|
|
|
#include <sys/socket.h>
|
2007-09-17 00:12:04 +02:00
|
|
|
#include <sys/ioctl.h>
|
2007-11-04 23:59:30 +01:00
|
|
|
|
2007-09-17 00:12:04 +02:00
|
|
|
#include <string.h>
|
2010-07-11 20:10:22 +02:00
|
|
|
#include <assert.h>
|
2007-09-16 19:46:25 +02:00
|
|
|
#include <errno.h>
|
2007-11-04 23:59:30 +01:00
|
|
|
#include <debug.h>
|
|
|
|
|
2012-03-04 00:18:34 +01:00
|
|
|
#include <nuttx/net/net.h>
|
2014-07-05 03:13:08 +02:00
|
|
|
#include <nuttx/net/ip.h>
|
2007-09-16 19:46:25 +02:00
|
|
|
|
2007-11-30 21:46:29 +01:00
|
|
|
#include <net/if.h>
|
2013-10-02 18:51:48 +02:00
|
|
|
#include <net/route.h>
|
2007-12-11 15:28:16 +01:00
|
|
|
#include <net/ethernet.h>
|
2013-10-02 18:51:48 +02:00
|
|
|
#include <netinet/in.h>
|
|
|
|
|
2014-06-24 17:28:44 +02:00
|
|
|
#include <nuttx/net/netdev.h>
|
2016-02-08 18:17:22 +01:00
|
|
|
#include <nuttx/net/arp.h>
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2017-04-06 23:58:00 +02:00
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
# include <nuttx/net/sixlowpan.h>
|
|
|
|
#endif
|
|
|
|
|
2010-07-11 20:10:22 +02:00
|
|
|
#ifdef CONFIG_NET_IGMP
|
2017-03-13 16:51:31 +01:00
|
|
|
# include <sys/sockio.h>
|
|
|
|
# include <nuttx/net/igmp.h>
|
|
|
|
#endif
|
|
|
|
|
2017-03-13 17:14:38 +01:00
|
|
|
#ifdef CONFIG_NETDEV_WIRELESS_IOCTL
|
2017-03-13 16:51:31 +01:00
|
|
|
# include <nuttx/wireless/wireless.h>
|
2017-04-15 18:23:29 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NET_6LOWPAN)
|
2017-04-15 17:11:52 +02:00
|
|
|
# include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
|
|
|
#endif
|
2010-07-11 20:10:22 +02:00
|
|
|
|
2016-02-08 18:17:22 +01:00
|
|
|
#include "arp/arp.h"
|
2014-06-29 01:25:18 +02:00
|
|
|
#include "socket/socket.h"
|
2014-06-27 17:56:45 +02:00
|
|
|
#include "netdev/netdev.h"
|
2015-05-27 17:26:00 +02:00
|
|
|
#include "devif/devif.h"
|
2014-07-05 23:15:40 +02:00
|
|
|
#include "igmp/igmp.h"
|
2015-02-03 15:54:42 +01:00
|
|
|
#include "icmpv6/icmpv6.h"
|
2014-06-26 21:02:08 +02:00
|
|
|
#include "route/route.h"
|
2007-09-16 19:46:25 +02:00
|
|
|
|
2007-09-17 00:12:04 +02:00
|
|
|
/****************************************************************************
|
2009-12-15 16:57:25 +01:00
|
|
|
* Pre-processor Definitions
|
2007-09-17 00:12:04 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-18 17:33:27 +01:00
|
|
|
/* This is really kind of bogus.. When asked for an IP address, this is
|
|
|
|
* family that is returned in the ifr structure. Probably could just skip
|
|
|
|
* this since the address family has nothing to do with the Ethernet address.
|
|
|
|
*/
|
|
|
|
|
2007-10-26 23:21:34 +02:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
2015-01-18 17:33:27 +01:00
|
|
|
# define AF_INETX AF_INET6
|
2007-10-26 23:21:34 +02:00
|
|
|
#else
|
2015-01-18 17:33:27 +01:00
|
|
|
# define AF_INETX AF_INET
|
2007-10-26 23:21:34 +02:00
|
|
|
#endif
|
|
|
|
|
2007-09-17 00:12:04 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-16 19:30:18 +01:00
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: ioctl_add_ipv4route
|
2015-01-16 19:30:18 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Add an IPv4 route to the routing table.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* rentry - Describes the route to be added
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET_ROUTE) && defined(CONFIG_NET_IPv4)
|
2017-04-15 18:29:37 +02:00
|
|
|
static int ioctl_add_ipv4route(FAR struct rtentry *rtentry)
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
|
|
|
FAR struct sockaddr_in *addr;
|
|
|
|
in_addr_t target;
|
|
|
|
in_addr_t netmask;
|
|
|
|
in_addr_t router;
|
|
|
|
|
|
|
|
addr = (FAR struct sockaddr_in *)rtentry->rt_target;
|
|
|
|
target = (in_addr_t)addr->sin_addr.s_addr;
|
|
|
|
|
|
|
|
addr = (FAR struct sockaddr_in *)rtentry->rt_netmask;
|
|
|
|
netmask = (in_addr_t)addr->sin_addr.s_addr;
|
|
|
|
|
|
|
|
/* The router is an optional argument */
|
|
|
|
|
|
|
|
if (rtentry->rt_router)
|
|
|
|
{
|
|
|
|
addr = (FAR struct sockaddr_in *)rtentry->rt_router;
|
|
|
|
router = (in_addr_t)addr->sin_addr.s_addr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
router = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return net_addroute(target, netmask, router);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NET_ROUTE && CONFIG_NET_IPv4 */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: ioctl_addipv6route
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Add an IPv6 route to the routing table.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* rentry - Describes the route to be added
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET_ROUTE) && defined(CONFIG_NET_IPv6)
|
2017-04-15 18:29:37 +02:00
|
|
|
static int ioctl_add_ipv4route(FAR struct rtentry *rtentry)
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
2015-05-13 15:22:02 +02:00
|
|
|
FAR struct sockaddr_in6 *target;
|
|
|
|
FAR struct sockaddr_in6 *netmask;
|
2015-01-16 19:30:18 +01:00
|
|
|
net_ipv6addr_t router;
|
|
|
|
|
2015-05-13 15:22:02 +02:00
|
|
|
target = (FAR struct sockaddr_in6 *)rtentry->rt_target;
|
|
|
|
netmask = (FAR struct sockaddr_in6 *)rtentry->rt_netmask;
|
2015-01-16 19:30:18 +01:00
|
|
|
|
|
|
|
/* The router is an optional argument */
|
|
|
|
|
|
|
|
if (rtentry->rt_router)
|
|
|
|
{
|
2015-05-13 15:22:02 +02:00
|
|
|
FAR struct sockaddr_in6 *addr;
|
|
|
|
addr = (FAR struct sockaddr_in6 *)rtentry->rt_router;
|
|
|
|
net_ipv6addr_copy(router, addr->sin6_addr.s6_addr16);
|
2015-01-16 19:30:18 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-13 15:22:02 +02:00
|
|
|
net_ipv6addr_copy(router, in6addr_any.s6_addr16);
|
2015-01-16 19:30:18 +01:00
|
|
|
}
|
|
|
|
|
2015-05-13 15:22:02 +02:00
|
|
|
return net_addroute_ipv6(target->sin6_addr.s6_addr16, netmask->sin6_addr.s6_addr16, router);
|
2015-01-16 19:30:18 +01:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_NET_ROUTE && CONFIG_NET_IPv6 */
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: ioctl_del_ipv4route
|
2015-01-16 19:30:18 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Delete an IPv4 route to the routing table.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* rentry - Describes the route to be deleted
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET_ROUTE) && defined(CONFIG_NET_IPv4)
|
2017-04-15 18:29:37 +02:00
|
|
|
static int ioctl_del_ipv4route(FAR struct rtentry *rtentry)
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
|
|
|
FAR struct sockaddr_in *addr;
|
|
|
|
in_addr_t target;
|
|
|
|
in_addr_t netmask;
|
|
|
|
|
|
|
|
addr = (FAR struct sockaddr_in *)rtentry->rt_target;
|
|
|
|
target = (in_addr_t)addr->sin_addr.s_addr;
|
|
|
|
|
|
|
|
addr = (FAR struct sockaddr_in *)rtentry->rt_netmask;
|
|
|
|
netmask = (in_addr_t)addr->sin_addr.s_addr;
|
|
|
|
|
|
|
|
return net_delroute(target, netmask);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NET_ROUTE && CONFIG_NET_IPv4 */
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: ioctl_del_ipv6route
|
2015-01-16 19:30:18 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Delete an IPv6 route to the routing table.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* rentry - Describes the route to be deleted
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET_ROUTE) && defined(CONFIG_NET_IPv6)
|
2017-04-15 18:29:37 +02:00
|
|
|
static int ioctl_del_ipv6route(FAR struct rtentry *rtentry)
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
2015-05-13 15:22:02 +02:00
|
|
|
FAR struct sockaddr_in6 *target;
|
|
|
|
FAR struct sockaddr_in6 *netmask;
|
2015-01-16 19:30:18 +01:00
|
|
|
|
2015-05-13 15:22:02 +02:00
|
|
|
target = (FAR struct sockaddr_in6 *)rtentry->rt_target;
|
|
|
|
netmask = (FAR struct sockaddr_in6 *)rtentry->rt_netmask;
|
2015-01-16 19:30:18 +01:00
|
|
|
|
2015-05-13 15:22:02 +02:00
|
|
|
return net_delroute_ipv6(target->sin6_addr.s6_addr16, netmask->sin6_addr.s6_addr16);
|
2015-01-16 19:30:18 +01:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_NET_ROUTE && CONFIG_NET_IPv6 */
|
|
|
|
|
2007-09-17 00:12:04 +02:00
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: ioctl_get_ipv4addr
|
2007-09-17 00:12:04 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2012-06-08 03:53:26 +02:00
|
|
|
* Copy IP addresses from device structure to user memory.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* outaddr - Pointer to the user-provided memory to receive the address.
|
2015-01-16 19:30:18 +01:00
|
|
|
* inaddr - The source IP address in the device structure.
|
2007-09-17 00:12:04 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-14 20:03:12 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2017-04-15 18:29:37 +02:00
|
|
|
static void ioctl_get_ipv4addr(FAR struct sockaddr *outaddr,
|
|
|
|
in_addr_t inaddr)
|
2007-09-17 00:12:04 +02:00
|
|
|
{
|
2012-06-08 03:53:26 +02:00
|
|
|
FAR struct sockaddr_in *dest = (FAR struct sockaddr_in *)outaddr;
|
|
|
|
dest->sin_family = AF_INET;
|
|
|
|
dest->sin_port = 0;
|
2015-01-15 20:08:28 +01:00
|
|
|
dest->sin_addr.s_addr = inaddr;
|
2015-01-14 20:03:12 +01:00
|
|
|
}
|
2007-09-17 00:12:04 +02:00
|
|
|
#endif
|
2015-01-14 20:03:12 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: ioctl_get_ipv6addr
|
2015-01-14 20:03:12 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Copy IP addresses from device structure to user memory.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* outaddr - Pointer to the user-provided memory to receive the address.
|
|
|
|
* inaddr - The source IP adress in the device structure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
2017-04-15 18:29:37 +02:00
|
|
|
static void ioctl_get_ipv6addr(FAR struct sockaddr_storage *outaddr,
|
|
|
|
FAR const net_ipv6addr_t inaddr)
|
2015-01-14 20:03:12 +01:00
|
|
|
{
|
|
|
|
FAR struct sockaddr_in6 *dest = (FAR struct sockaddr_in6 *)outaddr;
|
2015-01-21 01:14:09 +01:00
|
|
|
dest->sin6_family = AF_INET6;
|
|
|
|
dest->sin6_port = 0;
|
2015-01-14 20:03:12 +01:00
|
|
|
memcpy(dest->sin6_addr.in6_u.u6_addr8, inaddr, 16);
|
2007-09-17 00:12:04 +02:00
|
|
|
}
|
2015-01-14 20:03:12 +01:00
|
|
|
#endif
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2012-06-08 03:53:26 +02:00
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: ioctl_set_ipv4addr
|
2012-06-08 03:53:26 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Copy IP addresses from user memory into the device structure
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* outaddr - Pointer to the source IP address in the device structure.
|
|
|
|
* inaddr - Pointer to the user-provided memory to containing the new IP
|
2015-01-14 20:03:12 +01:00
|
|
|
* address.
|
2012-06-08 03:53:26 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-14 20:03:12 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2017-04-15 18:29:37 +02:00
|
|
|
static void ioctl_set_ipv4addr(FAR in_addr_t *outaddr,
|
|
|
|
FAR const struct sockaddr *inaddr)
|
2007-09-17 00:12:04 +02:00
|
|
|
{
|
2012-06-08 03:53:26 +02:00
|
|
|
FAR const struct sockaddr_in *src = (FAR const struct sockaddr_in *)inaddr;
|
2007-09-17 00:12:04 +02:00
|
|
|
*outaddr = src->sin_addr.s_addr;
|
2015-01-14 20:03:12 +01:00
|
|
|
}
|
2007-09-17 00:12:04 +02:00
|
|
|
#endif
|
2015-01-14 20:03:12 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: ioctl_set_ipv6addr
|
2015-01-14 20:03:12 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Copy IP addresses from user memory into the device structure
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* outaddr - Pointer to the source IP address in the device structure.
|
|
|
|
* inaddr - Pointer to the user-provided memory to containing the new IP
|
|
|
|
* address.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
2017-04-15 18:29:37 +02:00
|
|
|
static void ioctl_set_ipv6addr(FAR net_ipv6addr_t outaddr,
|
|
|
|
FAR const struct sockaddr_storage *inaddr)
|
2015-01-14 20:03:12 +01:00
|
|
|
{
|
|
|
|
FAR const struct sockaddr_in6 *src = (FAR const struct sockaddr_in6 *)inaddr;
|
|
|
|
memcpy(outaddr, src->sin6_addr.in6_u.u6_addr8, 16);
|
2007-09-17 00:12:04 +02:00
|
|
|
}
|
2015-01-14 20:03:12 +01:00
|
|
|
#endif
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2017-04-15 17:11:52 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netdev_iee802154_ioctl
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform IEEE802.15.4 network device specific operations.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* psock Socket structure
|
|
|
|
* dev Ethernet driver device structure
|
|
|
|
* cmd The ioctl command
|
|
|
|
* req The argument of the ioctl cmd
|
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
|
|
|
* Negated errno returned on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NET_6LOWPAN)
|
|
|
|
static int netdev_iee802154_ioctl(FAR struct socket *psock, int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
FAR struct net_driver_s *dev;
|
|
|
|
FAR char *ifname;
|
|
|
|
int ret = -ENOTTY;
|
|
|
|
|
2017-04-15 18:23:29 +02:00
|
|
|
if (arg != 0ul)
|
2017-04-15 17:11:52 +02:00
|
|
|
{
|
2017-05-05 17:15:28 +02:00
|
|
|
if (_MAC802154IOCVALID(cmd))
|
2017-04-15 17:11:52 +02:00
|
|
|
{
|
|
|
|
/* Get the IEEE802.15.4 MAC device to receive the radio IOCTL
|
|
|
|
* commdand
|
|
|
|
*/
|
|
|
|
|
|
|
|
FAR struct ieee802154_netmac_s *netmac =
|
|
|
|
(FAR struct ieee802154_netmac_s *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
ifname = netmac->ifr_name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The IOCTL command is neither */
|
|
|
|
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
|
|
|
|
2017-04-15 18:23:29 +02:00
|
|
|
/* Find the device with this name */
|
|
|
|
|
|
|
|
dev = netdev_findbyname(ifname);
|
|
|
|
if (dev != NULL)
|
|
|
|
{
|
|
|
|
/* Perform the device IOCTL */
|
2017-04-15 17:11:52 +02:00
|
|
|
|
2017-04-15 18:23:29 +02:00
|
|
|
ret = dev->d_ioctl(dev, cmd, arg);
|
|
|
|
}
|
2017-04-15 17:11:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-13 16:51:31 +01:00
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: netdev_wifr_ioctl
|
2017-03-13 16:51:31 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform wireless network device specific operations.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* psock Socket structure
|
|
|
|
* dev Ethernet driver device structure
|
|
|
|
* cmd The ioctl command
|
|
|
|
* req The argument of the ioctl cmd
|
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
|
|
|
* Negated errno returned on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-03-13 17:14:38 +01:00
|
|
|
#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NETDEV_WIRELESS_IOCTL)
|
2017-04-15 18:29:37 +02:00
|
|
|
static int netdev_wifr_ioctl(FAR struct socket *psock, int cmd,
|
|
|
|
FAR struct iwreq *req)
|
2017-03-13 16:51:31 +01:00
|
|
|
{
|
|
|
|
FAR struct net_driver_s *dev;
|
|
|
|
int ret = -ENOTTY;
|
|
|
|
|
|
|
|
/* Verify that this is a valid wireless network IOCTL command */
|
|
|
|
|
|
|
|
if (_WLIOCVALID(cmd) && (unsigned)_IOC_NR(cmd) <= WL_NNETCMDS)
|
|
|
|
{
|
|
|
|
/* Get the wireless device associated with the IOCTL command */
|
|
|
|
|
2017-04-26 20:31:13 +02:00
|
|
|
dev = netdev_findbyname(req->ifr_name);
|
2017-04-20 02:06:43 +02:00
|
|
|
if (dev != NULL)
|
2017-03-13 16:51:31 +01:00
|
|
|
{
|
2017-03-13 17:14:38 +01:00
|
|
|
/* Just forward the IOCTL to the wireless driver */
|
2017-03-13 16:51:31 +01:00
|
|
|
|
2017-04-15 17:33:27 +02:00
|
|
|
ret = dev->d_ioctl(dev, cmd, ((unsigned long)(uintptr_t)req));
|
2017-03-13 16:51:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-09-16 19:46:25 +02:00
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: netdev_ifr_dev
|
2013-10-06 00:43:10 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Verify the struct ifreq and get the Ethernet device.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* req - The argument of the ioctl cmd
|
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* A pointer to the driver structure on success; NULL on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-15 18:29:37 +02:00
|
|
|
static FAR struct net_driver_s *netdev_ifr_dev(FAR struct ifreq *req)
|
2013-10-06 00:43:10 +02:00
|
|
|
{
|
2017-03-13 16:51:31 +01:00
|
|
|
if (req != NULL)
|
2013-10-06 00:43:10 +02:00
|
|
|
{
|
2017-03-13 16:51:31 +01:00
|
|
|
/* Find the network device associated with the device name
|
|
|
|
* in the request data.
|
|
|
|
*/
|
2013-10-06 00:43:10 +02:00
|
|
|
|
2017-03-13 16:51:31 +01:00
|
|
|
return netdev_findbyname(req->ifr_name);
|
|
|
|
}
|
2013-10-06 00:43:10 +02:00
|
|
|
|
2017-03-13 16:51:31 +01:00
|
|
|
return NULL;
|
2013-10-06 00:43:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: netdev_ifr_ioctl
|
2007-09-16 19:46:25 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform network device specific operations.
|
|
|
|
*
|
|
|
|
* Parameters:
|
2010-07-11 20:10:22 +02:00
|
|
|
* psock Socket structure
|
2007-09-16 19:46:25 +02:00
|
|
|
* cmd The ioctl command
|
|
|
|
* req The argument of the ioctl cmd
|
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
2010-07-11 20:10:22 +02:00
|
|
|
* Negated errno returned on failure.
|
2007-09-16 19:46:25 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-15 18:29:37 +02:00
|
|
|
static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
|
|
|
|
FAR struct ifreq *req)
|
2007-09-16 19:46:25 +02:00
|
|
|
{
|
2014-06-28 00:48:12 +02:00
|
|
|
FAR struct net_driver_s *dev;
|
2013-10-06 00:43:10 +02:00
|
|
|
int ret = -EINVAL;
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("cmd: %d\n", cmd);
|
2007-09-17 00:12:04 +02:00
|
|
|
|
|
|
|
/* Execute the command */
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
2015-01-14 20:03:12 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2012-11-04 19:54:04 +01:00
|
|
|
case SIOCGIFADDR: /* Get IP address */
|
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
dev = netdev_ifr_dev(req);
|
2013-10-06 00:43:10 +02:00
|
|
|
if (dev)
|
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
ioctl_get_ipv4addr(&req->ifr_addr, dev->d_ipaddr);
|
2013-10-06 00:43:10 +02:00
|
|
|
ret = OK;
|
|
|
|
}
|
2012-11-04 19:54:04 +01:00
|
|
|
}
|
2007-09-17 00:12:04 +02:00
|
|
|
break;
|
2015-01-14 20:03:12 +01:00
|
|
|
#endif
|
|
|
|
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2015-01-14 20:03:12 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2012-11-04 19:54:04 +01:00
|
|
|
case SIOCSIFADDR: /* Set IP address */
|
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
dev = netdev_ifr_dev(req);
|
2013-10-06 00:43:10 +02:00
|
|
|
if (dev)
|
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
ioctl_set_ipv4addr(&dev->d_ipaddr, &req->ifr_addr);
|
2013-10-06 00:43:10 +02:00
|
|
|
ret = OK;
|
|
|
|
}
|
2012-11-04 19:54:04 +01:00
|
|
|
}
|
2007-09-17 00:12:04 +02:00
|
|
|
break;
|
2015-01-14 20:03:12 +01:00
|
|
|
#endif
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2015-01-14 20:03:12 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2007-09-17 00:12:04 +02:00
|
|
|
case SIOCGIFDSTADDR: /* Get P-to-P address */
|
2012-11-04 19:54:04 +01:00
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
dev = netdev_ifr_dev(req);
|
2013-10-06 00:43:10 +02:00
|
|
|
if (dev)
|
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
ioctl_get_ipv4addr(&req->ifr_dstaddr, dev->d_draddr);
|
2013-10-06 00:43:10 +02:00
|
|
|
ret = OK;
|
|
|
|
}
|
2012-11-04 19:54:04 +01:00
|
|
|
}
|
2007-09-17 00:12:04 +02:00
|
|
|
break;
|
2015-01-14 20:03:12 +01:00
|
|
|
#endif
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2015-01-14 20:03:12 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2007-09-17 00:12:04 +02:00
|
|
|
case SIOCSIFDSTADDR: /* Set P-to-P address */
|
2012-11-04 19:54:04 +01:00
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
dev = netdev_ifr_dev(req);
|
2013-10-06 00:43:10 +02:00
|
|
|
if (dev)
|
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
ioctl_set_ipv4addr(&dev->d_draddr, &req->ifr_dstaddr);
|
2013-10-06 00:43:10 +02:00
|
|
|
ret = OK;
|
|
|
|
}
|
2012-11-04 19:54:04 +01:00
|
|
|
}
|
2007-09-17 00:12:04 +02:00
|
|
|
break;
|
2015-01-14 20:03:12 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
case SIOCGIFBRDADDR: /* Get broadcast IP address */
|
|
|
|
case SIOCSIFBRDADDR: /* Set broadcast IP address */
|
|
|
|
{
|
|
|
|
ret = -ENOSYS;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2015-01-14 20:03:12 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2007-09-17 00:12:04 +02:00
|
|
|
case SIOCGIFNETMASK: /* Get network mask */
|
2012-11-04 19:54:04 +01:00
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
dev = netdev_ifr_dev(req);
|
2013-10-06 00:43:10 +02:00
|
|
|
if (dev)
|
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
ioctl_get_ipv4addr(&req->ifr_addr, dev->d_netmask);
|
2013-10-06 00:43:10 +02:00
|
|
|
ret = OK;
|
|
|
|
}
|
2012-11-04 19:54:04 +01:00
|
|
|
}
|
2007-09-17 00:12:04 +02:00
|
|
|
break;
|
2015-01-14 20:03:12 +01:00
|
|
|
#endif
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2015-01-14 20:03:12 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2007-09-17 00:12:04 +02:00
|
|
|
case SIOCSIFNETMASK: /* Set network mask */
|
2012-11-04 19:54:04 +01:00
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
dev = netdev_ifr_dev(req);
|
2013-10-06 00:43:10 +02:00
|
|
|
if (dev)
|
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
ioctl_set_ipv4addr(&dev->d_netmask, &req->ifr_addr);
|
2013-10-06 00:43:10 +02:00
|
|
|
ret = OK;
|
|
|
|
}
|
2012-11-04 19:54:04 +01:00
|
|
|
}
|
2007-09-17 00:12:04 +02:00
|
|
|
break;
|
2015-01-14 20:03:12 +01:00
|
|
|
#endif
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2015-01-14 20:03:12 +01:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
case SIOCGLIFADDR: /* Get IP address */
|
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
dev = netdev_ifr_dev(req);
|
2015-01-14 20:03:12 +01:00
|
|
|
if (dev)
|
|
|
|
{
|
|
|
|
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
|
|
|
|
2017-04-15 18:29:37 +02:00
|
|
|
ioctl_get_ipv6addr(&lreq->lifr_addr, dev->d_ipv6addr);
|
2015-01-14 20:03:12 +01:00
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
case SIOCSLIFADDR: /* Set IP address */
|
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
dev = netdev_ifr_dev(req);
|
2015-01-14 20:03:12 +01:00
|
|
|
if (dev)
|
|
|
|
{
|
|
|
|
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
|
|
|
|
2017-04-15 18:29:37 +02:00
|
|
|
ioctl_set_ipv6addr(dev->d_ipv6addr, &lreq->lifr_addr);
|
2015-01-14 20:03:12 +01:00
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
case SIOCGLIFDSTADDR: /* Get P-to-P address */
|
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
dev = netdev_ifr_dev(req);
|
2015-01-14 20:03:12 +01:00
|
|
|
if (dev)
|
|
|
|
{
|
|
|
|
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
|
|
|
|
2017-04-15 18:29:37 +02:00
|
|
|
ioctl_get_ipv6addr(&lreq->lifr_dstaddr, dev->d_ipv6draddr);
|
2015-01-14 20:03:12 +01:00
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
case SIOCSLIFDSTADDR: /* Set P-to-P address */
|
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
dev = netdev_ifr_dev(req);
|
2015-01-14 20:03:12 +01:00
|
|
|
if (dev)
|
|
|
|
{
|
|
|
|
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
|
|
|
|
2017-04-15 18:29:37 +02:00
|
|
|
ioctl_set_ipv6addr(dev->d_ipv6draddr, &lreq->lifr_dstaddr);
|
2015-01-14 20:03:12 +01:00
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
case SIOCGLIFBRDADDR: /* Get broadcast IP address */
|
|
|
|
case SIOCSLIFBRDADDR: /* Set broadcast IP address */
|
|
|
|
{
|
|
|
|
ret = -ENOSYS;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
2015-01-18 16:23:22 +01:00
|
|
|
case SIOCGLIFNETMASK: /* Get network mask */
|
2015-01-14 20:03:12 +01:00
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
dev = netdev_ifr_dev(req);
|
2015-01-14 20:03:12 +01:00
|
|
|
if (dev)
|
|
|
|
{
|
|
|
|
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
|
|
|
|
2017-04-15 18:29:37 +02:00
|
|
|
ioctl_get_ipv6addr(&lreq->lifr_addr, dev->d_ipv6netmask);
|
2015-01-14 20:03:12 +01:00
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
case SIOCSLIFNETMASK: /* Set network mask */
|
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
dev = netdev_ifr_dev(req);
|
2015-01-14 20:03:12 +01:00
|
|
|
if (dev)
|
|
|
|
{
|
|
|
|
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
2017-04-15 18:29:37 +02:00
|
|
|
ioctl_set_ipv6addr(dev->d_ipv6netmask, &lreq->lifr_addr);
|
2015-01-14 20:03:12 +01:00
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
case SIOCGLIFMTU: /* Get MTU size */
|
|
|
|
case SIOCGIFMTU: /* Get MTU size */
|
2012-11-04 19:54:04 +01:00
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
dev = netdev_ifr_dev(req);
|
2014-11-16 16:22:38 +01:00
|
|
|
if (dev)
|
|
|
|
{
|
2014-11-16 17:42:19 +01:00
|
|
|
req->ifr_mtu = NET_DEV_MTU(dev);
|
2014-11-16 16:22:38 +01:00
|
|
|
ret = OK;
|
|
|
|
}
|
2012-11-04 19:54:04 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-02-03 15:54:42 +01:00
|
|
|
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
|
|
|
case SIOCIFAUTOCONF: /* Perform ICMPv6 auto-configuration */
|
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
dev = netdev_ifr_dev(req);
|
2015-02-03 15:54:42 +01:00
|
|
|
if (dev)
|
|
|
|
{
|
|
|
|
ret = icmpv6_autoconfig(dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2012-11-04 19:54:04 +01:00
|
|
|
case SIOCSIFFLAGS: /* Sets the interface flags */
|
|
|
|
{
|
|
|
|
/* Is this a request to bring the interface up? */
|
|
|
|
|
2017-04-15 18:29:37 +02:00
|
|
|
dev = netdev_ifr_dev(req);
|
2013-10-06 00:43:10 +02:00
|
|
|
if (dev)
|
2012-11-04 19:54:04 +01:00
|
|
|
{
|
2015-05-31 19:35:28 +02:00
|
|
|
if ((req->ifr_flags & IFF_UP) != 0)
|
2013-10-06 00:43:10 +02:00
|
|
|
{
|
|
|
|
/* Yes.. bring the interface up */
|
2012-11-04 19:54:04 +01:00
|
|
|
|
2015-02-03 22:40:56 +01:00
|
|
|
netdev_ifup(dev);
|
2013-10-06 00:43:10 +02:00
|
|
|
}
|
2012-11-04 19:54:04 +01:00
|
|
|
|
2013-10-06 00:43:10 +02:00
|
|
|
/* Is this a request to take the interface down? */
|
2012-11-04 19:54:04 +01:00
|
|
|
|
2015-05-31 19:35:28 +02:00
|
|
|
else if ((req->ifr_flags & IFF_DOWN) != 0)
|
2013-10-06 00:43:10 +02:00
|
|
|
{
|
|
|
|
/* Yes.. take the interface down */
|
2012-11-04 19:54:04 +01:00
|
|
|
|
2015-02-03 22:40:56 +01:00
|
|
|
netdev_ifdown(dev);
|
2013-10-06 00:43:10 +02:00
|
|
|
}
|
2012-11-04 19:54:04 +01:00
|
|
|
}
|
2013-10-06 00:43:10 +02:00
|
|
|
|
|
|
|
ret = OK;
|
2012-11-04 19:54:04 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIFFLAGS: /* Gets the interface flags */
|
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
dev = netdev_ifr_dev(req);
|
2013-10-06 00:43:10 +02:00
|
|
|
if (dev)
|
|
|
|
{
|
2014-01-21 17:21:45 +01:00
|
|
|
req->ifr_flags = dev->d_flags;
|
2012-11-04 19:54:04 +01:00
|
|
|
}
|
2013-10-06 00:43:10 +02:00
|
|
|
|
|
|
|
ret = OK;
|
2012-11-04 19:54:04 +01:00
|
|
|
}
|
2007-09-17 00:12:04 +02:00
|
|
|
break;
|
|
|
|
|
2017-06-19 00:00:08 +02:00
|
|
|
/* MAC address operations only make sense if Ethernet or 6LoWPAN are
|
2017-04-22 02:31:05 +02:00
|
|
|
* supported.
|
|
|
|
*/
|
2011-03-12 16:36:28 +01:00
|
|
|
|
2017-04-06 23:58:00 +02:00
|
|
|
#if defined(CONFIG_NET_ETHERNET) || defined(CONFIG_NET_6LOWPAN)
|
2007-09-17 00:12:04 +02:00
|
|
|
case SIOCGIFHWADDR: /* Get hardware address */
|
2012-11-04 19:54:04 +01:00
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
dev = netdev_ifr_dev(req);
|
2013-10-06 00:43:10 +02:00
|
|
|
if (dev)
|
|
|
|
{
|
2017-04-06 23:58:00 +02:00
|
|
|
#ifdef CONFIG_NET_ETHERNET
|
|
|
|
#ifdef CONFIG_NET_MULTILINK
|
|
|
|
if (dev->d_lltype == NET_LL_ETHERNET)
|
|
|
|
#else
|
|
|
|
if (true)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
req->ifr_hwaddr.sa_family = AF_INETX;
|
|
|
|
memcpy(req->ifr_hwaddr.sa_data,
|
2017-04-22 19:10:30 +02:00
|
|
|
dev->d_mac.ether.ether_addr_octet, IFHWADDRLEN);
|
2017-04-06 23:58:00 +02:00
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
#ifdef CONFIG_NET_MULTILINK
|
|
|
|
if (dev->d_lltype == NET_LL_IEEE802154)
|
|
|
|
#else
|
|
|
|
if (true)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
req->ifr_hwaddr.sa_family = AF_INETX;
|
2017-04-22 19:52:45 +02:00
|
|
|
memcpy(req->ifr_hwaddr.sa_data,
|
2017-05-04 16:20:59 +02:00
|
|
|
dev->d_mac.ieee802154.u8, NET_6LOWPAN_ADDRSIZE);
|
2017-04-06 23:58:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
nerr("Unsupported link layer\n");
|
|
|
|
}
|
2013-10-06 00:43:10 +02:00
|
|
|
}
|
2012-11-04 19:54:04 +01:00
|
|
|
}
|
2007-09-17 00:12:04 +02:00
|
|
|
break;
|
|
|
|
|
2008-12-12 03:18:34 +01:00
|
|
|
case SIOCSIFHWADDR: /* Set hardware address -- will not take effect until ifup */
|
2012-11-04 19:54:04 +01:00
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
dev = netdev_ifr_dev(req);
|
2013-10-06 00:43:10 +02:00
|
|
|
if (dev)
|
|
|
|
{
|
2017-04-06 23:58:00 +02:00
|
|
|
#ifdef CONFIG_NET_ETHERNET
|
|
|
|
#ifdef CONFIG_NET_MULTILINK
|
|
|
|
if (dev->d_lltype == NET_LL_ETHERNET)
|
|
|
|
#else
|
|
|
|
if (true)
|
|
|
|
#endif
|
|
|
|
{
|
2017-04-22 19:10:30 +02:00
|
|
|
memcpy(dev->d_mac.ether.ether_addr_octet,
|
2017-04-06 23:58:00 +02:00
|
|
|
req->ifr_hwaddr.sa_data, IFHWADDRLEN);
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
#ifdef CONFIG_NET_MULTILINK
|
|
|
|
if (dev->d_lltype == NET_LL_IEEE802154)
|
|
|
|
#else
|
|
|
|
if (true)
|
|
|
|
#endif
|
|
|
|
{
|
2017-04-22 19:52:45 +02:00
|
|
|
memcpy(dev->d_mac.ieee802154.u8,
|
2017-05-04 16:20:59 +02:00
|
|
|
req->ifr_hwaddr.sa_data, NET_6LOWPAN_ADDRSIZE);
|
2017-04-22 19:52:45 +02:00
|
|
|
ret = OK;
|
2017-04-06 23:58:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
nerr("Unsupported link layer\n");
|
|
|
|
}
|
2013-10-06 00:43:10 +02:00
|
|
|
}
|
2012-11-04 19:54:04 +01:00
|
|
|
}
|
2007-09-17 00:12:04 +02:00
|
|
|
break;
|
2011-03-12 16:36:28 +01:00
|
|
|
#endif
|
2007-09-17 00:12:04 +02:00
|
|
|
|
|
|
|
case SIOCDIFADDR: /* Delete IP address */
|
2012-11-04 19:54:04 +01:00
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
dev = netdev_ifr_dev(req);
|
2013-10-06 00:43:10 +02:00
|
|
|
if (dev)
|
|
|
|
{
|
2015-01-15 20:08:28 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
dev->d_ipaddr = 0;
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
memset(&dev->d_ipv6addr, 0, sizeof(net_ipv6addr_t));
|
|
|
|
#endif
|
2013-10-06 00:43:10 +02:00
|
|
|
ret = OK;
|
|
|
|
}
|
2012-11-04 19:54:04 +01:00
|
|
|
}
|
2007-09-17 00:12:04 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIFCOUNT: /* Get number of devices */
|
2012-11-04 19:54:04 +01:00
|
|
|
{
|
|
|
|
req->ifr_count = netdev_count();
|
|
|
|
ret = -ENOSYS;
|
|
|
|
}
|
2010-07-11 20:10:22 +02:00
|
|
|
break;
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2017-03-13 16:51:31 +01:00
|
|
|
#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NETDEV_PHY_IOCTL)
|
2014-08-16 23:04:09 +02:00
|
|
|
#ifdef CONFIG_ARCH_PHY_INTERRUPT
|
|
|
|
case SIOCMIINOTIFY: /* Set up for PHY event notifications */
|
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
dev = netdev_ifr_dev(req);
|
2014-08-16 23:04:09 +02:00
|
|
|
if (dev && dev->d_ioctl)
|
|
|
|
{
|
|
|
|
struct mii_iotcl_notify_s *notify = &req->ifr_ifru.ifru_mii_notify;
|
2017-04-15 17:33:27 +02:00
|
|
|
ret = dev->d_ioctl(dev, cmd, ((unsigned long)(uintptr_t)notify));
|
2014-08-16 23:04:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2014-06-27 17:30:41 +02:00
|
|
|
case SIOCGMIIPHY: /* Get address of MII PHY in use */
|
|
|
|
case SIOCGMIIREG: /* Get MII register via MDIO */
|
|
|
|
case SIOCSMIIREG: /* Set MII register via MDIO */
|
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
dev = netdev_ifr_dev(req);
|
2014-06-27 17:30:41 +02:00
|
|
|
if (dev && dev->d_ioctl)
|
|
|
|
{
|
2014-08-16 22:08:04 +02:00
|
|
|
struct mii_ioctl_data_s *mii_data = &req->ifr_ifru.ifru_mii_data;
|
2017-04-15 17:33:27 +02:00
|
|
|
ret = dev->d_ioctl(dev, cmd, ((unsigned long)(uintptr_t)mii_data));
|
2014-06-27 17:30:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2007-09-17 00:12:04 +02:00
|
|
|
default:
|
2012-11-04 19:54:04 +01:00
|
|
|
{
|
2013-10-02 18:51:48 +02:00
|
|
|
ret = -ENOTTY;
|
2012-11-04 19:54:04 +01:00
|
|
|
}
|
2015-10-08 23:10:04 +02:00
|
|
|
break;
|
2010-07-11 20:10:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-10-06 00:43:10 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netdev_imsfdev
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Verify the struct ip_msfilter and get the Ethernet device.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* req - The argument of the ioctl cmd
|
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* A pointer to the driver structure on success; NULL on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IGMP
|
2014-06-28 00:48:12 +02:00
|
|
|
static FAR struct net_driver_s *netdev_imsfdev(FAR struct ip_msfilter *imsf)
|
2013-10-06 00:43:10 +02:00
|
|
|
{
|
|
|
|
if (!imsf)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the network device associated with the device name
|
|
|
|
* in the request data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return netdev_findbyname(imsf->imsf_name);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-07-11 20:10:22 +02:00
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: netdev_imsf_ioctl
|
2010-07-11 20:10:22 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform network device specific operations.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* psock Socket structure
|
|
|
|
* dev Ethernet driver device structure
|
|
|
|
* cmd The ioctl command
|
2014-03-24 16:34:17 +01:00
|
|
|
* imsf The argument of the ioctl cmd
|
2010-07-11 20:10:22 +02:00
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
|
|
|
* Negated errno returned on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IGMP
|
2017-04-15 18:29:37 +02:00
|
|
|
static int netdev_imsf_ioctl(FAR struct socket *psock, int cmd,
|
|
|
|
FAR struct ip_msfilter *imsf)
|
2010-07-11 20:10:22 +02:00
|
|
|
{
|
2014-06-28 00:48:12 +02:00
|
|
|
FAR struct net_driver_s *dev;
|
2013-10-06 00:43:10 +02:00
|
|
|
int ret = -EINVAL;
|
2010-07-11 20:10:22 +02:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("cmd: %d\n", cmd);
|
2010-07-11 20:10:22 +02:00
|
|
|
|
|
|
|
/* Execute the command */
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case SIOCSIPMSFILTER: /* Set source filter content */
|
|
|
|
{
|
2014-03-24 16:34:17 +01:00
|
|
|
dev = netdev_imsfdev(imsf);
|
2013-10-06 00:43:10 +02:00
|
|
|
if (dev)
|
2010-07-11 20:10:22 +02:00
|
|
|
{
|
2013-10-06 00:43:10 +02:00
|
|
|
if (imsf->imsf_fmode == MCAST_INCLUDE)
|
|
|
|
{
|
|
|
|
ret = igmp_joingroup(dev, &imsf->imsf_multiaddr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DEBUGASSERT(imsf->imsf_fmode == MCAST_EXCLUDE);
|
|
|
|
ret = igmp_leavegroup(dev, &imsf->imsf_multiaddr);
|
|
|
|
}
|
2010-07-11 20:10:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIPMSFILTER: /* Retrieve source filter addresses */
|
|
|
|
default:
|
2013-10-02 18:51:48 +02:00
|
|
|
ret = -ENOTTY;
|
2010-07-11 20:10:22 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-08 18:17:22 +01:00
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: netdev_arp_ioctl
|
2016-02-08 18:17:22 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform ARP table specific operations.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* psock Socket structure
|
|
|
|
* dev Ethernet driver device structure
|
|
|
|
* cmd The ioctl command
|
|
|
|
* req The argument of the ioctl cmd
|
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
|
|
|
* Negated errno returned on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_ARP
|
2017-04-15 18:29:37 +02:00
|
|
|
static int netdev_arp_ioctl(FAR struct socket *psock, int cmd,
|
|
|
|
FAR struct arpreq *req)
|
2016-02-08 18:17:22 +01:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Execute the command */
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case SIOCSARP: /* Set an ARP mapping */
|
|
|
|
{
|
|
|
|
if (req != NULL &&
|
2017-05-04 16:20:59 +02:00
|
|
|
req->arp_pa.sa_family == AF_INET &&
|
2016-02-08 18:17:22 +01:00
|
|
|
req->arp_ha.sa_family == ARPHRD_ETHER)
|
|
|
|
{
|
|
|
|
FAR struct sockaddr_in *addr =
|
|
|
|
(FAR struct sockaddr_in *)&req->arp_pa;
|
|
|
|
|
|
|
|
/* Update any existing ARP table entry for this protocol
|
|
|
|
* address -OR- add a new ARP table entry if there is not.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ret = arp_update(addr->sin_addr.s_addr,
|
|
|
|
(FAR uint8_t *)req->arp_ha.sa_data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCDARP: /* Delete an ARP mapping */
|
|
|
|
{
|
|
|
|
if (req != NULL && req->arp_pa.sa_family == AF_INET)
|
|
|
|
{
|
|
|
|
FAR struct sockaddr_in *addr =
|
|
|
|
(FAR struct sockaddr_in *)&req->arp_pa;
|
|
|
|
|
|
|
|
/* Find the existing ARP table entry for this protocol address. */
|
|
|
|
|
|
|
|
FAR struct arp_entry *entry = arp_find(addr->sin_addr.s_addr);
|
|
|
|
if (entry != NULL)
|
|
|
|
{
|
|
|
|
/* The ARP table is fixed size; an entry is deleted
|
|
|
|
* by nullifying its protocol address.
|
|
|
|
*/
|
|
|
|
|
|
|
|
entry->at_ipaddr = 0;
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -ENOENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGARP: /* Get an ARP mapping */
|
|
|
|
{
|
|
|
|
if (req != NULL && req->arp_pa.sa_family == AF_INET)
|
|
|
|
{
|
|
|
|
FAR struct sockaddr_in *addr =
|
|
|
|
(FAR struct sockaddr_in *)&req->arp_pa;
|
|
|
|
|
|
|
|
/* Find the existing ARP table entry for this protocol address. */
|
|
|
|
|
|
|
|
FAR struct arp_entry *entry = arp_find(addr->sin_addr.s_addr);
|
|
|
|
if (entry != NULL)
|
|
|
|
{
|
|
|
|
/* Return the mapped hardware address. */
|
|
|
|
|
|
|
|
req->arp_ha.sa_family = ARPHRD_ETHER;
|
|
|
|
memcpy(req->arp_ha.sa_data,
|
|
|
|
entry->at_ethaddr.ether_addr_octet,
|
|
|
|
ETHER_ADDR_LEN);
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -ENOENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ret = -ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-10-02 18:51:48 +02:00
|
|
|
/****************************************************************************
|
2017-04-15 18:29:37 +02:00
|
|
|
* Name: netdev_rt_ioctl
|
2013-10-02 18:51:48 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform routing table specific operations.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* psock Socket structure
|
|
|
|
* dev Ethernet driver device structure
|
|
|
|
* cmd The ioctl command
|
|
|
|
* rtentry The argument of the ioctl cmd
|
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
|
|
|
* Negated errno returned on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_ROUTE
|
2017-04-15 18:29:37 +02:00
|
|
|
static int netdev_rt_ioctl(FAR struct socket *psock, int cmd,
|
|
|
|
FAR struct rtentry *rtentry)
|
2013-10-02 18:51:48 +02:00
|
|
|
{
|
2015-01-18 17:33:27 +01:00
|
|
|
int ret = -EAFNOSUPPORT;
|
2013-10-02 18:51:48 +02:00
|
|
|
|
|
|
|
/* Execute the command */
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case SIOCADDRT: /* Add an entry to the routing table */
|
|
|
|
{
|
2015-01-16 19:30:18 +01:00
|
|
|
/* The target address and the netmask are required values */
|
2013-10-06 00:43:10 +02:00
|
|
|
|
2015-02-06 20:34:19 +01:00
|
|
|
if (!rtentry || !rtentry->rt_target || !rtentry->rt_netmask)
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2013-10-06 00:43:10 +02:00
|
|
|
|
2015-01-18 17:33:27 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
2015-02-06 20:34:19 +01:00
|
|
|
if (rtentry->rt_target->ss_family == AF_INET)
|
2015-01-18 17:33:27 +01:00
|
|
|
#endif
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
ret = ioctl_add_ipv4route(rtentry);
|
2015-01-16 19:30:18 +01:00
|
|
|
}
|
2015-01-18 17:33:27 +01:00
|
|
|
#endif /* CONFIG_NET_IPv4 */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
2015-02-06 20:34:19 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2015-01-16 19:30:18 +01:00
|
|
|
else
|
2015-01-18 17:33:27 +01:00
|
|
|
#endif
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
|
|
|
ret = ioctl_addipv6route(rtentry);
|
|
|
|
}
|
2015-02-06 20:34:19 +01:00
|
|
|
#endif /* CONFIG_NET_IPv6 */
|
2013-10-02 18:51:48 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCDELRT: /* Delete an entry from the routing table */
|
|
|
|
{
|
2015-01-16 19:30:18 +01:00
|
|
|
/* The target address and the netmask are required values */
|
2013-10-02 18:51:48 +02:00
|
|
|
|
2015-02-06 20:34:19 +01:00
|
|
|
if (!rtentry || !rtentry->rt_target || !rtentry->rt_netmask)
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2013-10-02 18:51:48 +02:00
|
|
|
|
2015-01-18 17:33:27 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
2015-02-06 20:34:19 +01:00
|
|
|
if (rtentry->rt_target->ss_family == AF_INET)
|
2015-01-18 17:33:27 +01:00
|
|
|
#endif
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
ret = ioctl_del_ipv4route(rtentry);
|
2015-01-16 19:30:18 +01:00
|
|
|
}
|
2015-01-18 17:33:27 +01:00
|
|
|
#endif /* CONFIG_NET_IPv4 */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
2015-02-06 20:34:19 +01:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
2015-01-16 19:30:18 +01:00
|
|
|
else
|
2015-01-18 17:33:27 +01:00
|
|
|
#endif
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
ret = ioctl_del_ipv6route(rtentry);
|
2015-01-16 19:30:18 +01:00
|
|
|
}
|
2015-02-06 20:34:19 +01:00
|
|
|
#endif /* CONFIG_NET_IPv6 */
|
2013-10-02 18:51:48 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ret = -ENOTTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-07-11 20:10:22 +02:00
|
|
|
/****************************************************************************
|
2015-01-19 23:02:56 +01:00
|
|
|
* Public Functions
|
2010-07-11 20:10:22 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2016-07-06 15:30:09 +02:00
|
|
|
* Name: psock_ioctl
|
2010-07-11 20:10:22 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform network device specific operations.
|
|
|
|
*
|
|
|
|
* Parameters:
|
2016-07-06 15:30:09 +02:00
|
|
|
* psock A pointer to a NuttX-specific, internal socket structure
|
2010-07-11 20:10:22 +02:00
|
|
|
* cmd The ioctl command
|
2013-10-02 18:51:48 +02:00
|
|
|
* arg The argument of the ioctl cmd
|
2010-07-11 20:10:22 +02:00
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
|
|
|
* On a failure, -1 is returned with errno set appropriately
|
|
|
|
*
|
|
|
|
* EBADF
|
2016-07-06 15:30:09 +02:00
|
|
|
* 'psock' is not a valid, connected socket structure.
|
2010-07-11 20:10:22 +02:00
|
|
|
* EFAULT
|
2013-10-02 18:51:48 +02:00
|
|
|
* 'arg' references an inaccessible memory area.
|
|
|
|
* ENOTTY
|
|
|
|
* 'cmd' not valid.
|
2010-07-11 20:10:22 +02:00
|
|
|
* EINVAL
|
2013-10-02 18:51:48 +02:00
|
|
|
* 'arg' is not valid.
|
2010-07-11 20:10:22 +02:00
|
|
|
* ENOTTY
|
|
|
|
* 'sockfd' is not associated with a network device.
|
|
|
|
* ENOTTY
|
|
|
|
* The specified request does not apply to the kind of object that the
|
|
|
|
* descriptor 'sockfd' references.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-07-06 15:30:09 +02:00
|
|
|
int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg)
|
2010-07-11 20:10:22 +02:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2016-07-06 15:30:09 +02:00
|
|
|
/* Verify that the psock corresponds to valid, allocated socket */
|
2010-07-11 20:10:22 +02:00
|
|
|
|
2016-07-06 15:30:09 +02:00
|
|
|
if (psock == NULL || psock->s_crefs <= 0)
|
2010-07-11 20:10:22 +02:00
|
|
|
{
|
|
|
|
ret = -EBADF;
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
2017-03-13 16:51:31 +01:00
|
|
|
/* Execute the command. First check for a standard network IOCTL command. */
|
2010-07-11 20:10:22 +02:00
|
|
|
|
2017-04-15 18:29:37 +02:00
|
|
|
ret = netdev_ifr_ioctl(psock, cmd, (FAR struct ifreq *)((uintptr_t)arg));
|
2016-02-25 02:02:51 +01:00
|
|
|
|
2017-03-13 17:14:38 +01:00
|
|
|
#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NETDEV_WIRELESS_IOCTL)
|
2017-04-15 18:23:29 +02:00
|
|
|
/* Check for a wireless network command */
|
2017-03-13 16:51:31 +01:00
|
|
|
|
|
|
|
if (ret == -ENOTTY)
|
|
|
|
{
|
2017-04-20 02:06:43 +02:00
|
|
|
FAR struct iwreq *wifrreq;
|
|
|
|
|
2017-04-22 02:42:13 +02:00
|
|
|
wifrreq = (FAR struct iwreq *)((uintptr_t)arg);
|
2017-04-20 02:06:43 +02:00
|
|
|
ret = netdev_wifr_ioctl(psock, cmd, wifrreq);
|
2017-03-13 16:51:31 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-04-15 18:23:29 +02:00
|
|
|
#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NET_6LOWPAN)
|
|
|
|
/* Check for a IEEE802.15.4 network device command */
|
|
|
|
|
|
|
|
if (ret == -ENOTTY)
|
|
|
|
{
|
|
|
|
ret = netdev_iee802154_ioctl(psock, cmd, arg);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-07-11 20:10:22 +02:00
|
|
|
#ifdef CONFIG_NET_IGMP
|
2016-02-25 02:02:51 +01:00
|
|
|
/* Check for address filtering commands */
|
|
|
|
|
2013-10-02 18:51:48 +02:00
|
|
|
if (ret == -ENOTTY)
|
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
ret = netdev_imsf_ioctl(psock, cmd,
|
|
|
|
(FAR struct ip_msfilter *)((uintptr_t)arg));
|
2013-10-02 18:51:48 +02:00
|
|
|
}
|
|
|
|
#endif
|
2016-02-08 18:17:22 +01:00
|
|
|
|
2016-02-25 02:02:51 +01:00
|
|
|
#ifdef CONFIG_NET_ARP
|
2016-02-08 18:17:22 +01:00
|
|
|
/* Check for ARP table IOCTL commands */
|
|
|
|
|
|
|
|
if (ret == -ENOTTY)
|
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
ret = netdev_arp_ioctl(psock, cmd,
|
|
|
|
(FAR struct arpreq *)((uintptr_t)arg));
|
2016-02-08 18:17:22 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-25 02:02:51 +01:00
|
|
|
#ifdef CONFIG_NET_ROUTE
|
2016-02-08 18:17:22 +01:00
|
|
|
/* Check for Routing table IOCTL commands */
|
|
|
|
|
2013-10-02 18:51:48 +02:00
|
|
|
if (ret == -ENOTTY)
|
2010-07-11 20:10:22 +02:00
|
|
|
{
|
2017-04-15 18:29:37 +02:00
|
|
|
ret = netdev_rt_ioctl(psock, cmd,
|
|
|
|
(FAR struct rtentry *)((uintptr_t)arg));
|
2010-07-11 20:10:22 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Check for success or failure */
|
|
|
|
|
|
|
|
if (ret >= 0)
|
|
|
|
{
|
|
|
|
return ret;
|
2007-09-17 00:12:04 +02:00
|
|
|
}
|
|
|
|
|
2010-07-11 20:10:22 +02:00
|
|
|
/* On failure, set the errno and return -1 */
|
2007-09-17 00:12:04 +02:00
|
|
|
|
|
|
|
errout:
|
2015-07-05 19:18:56 +02:00
|
|
|
set_errno(-ret);
|
2007-09-16 19:46:25 +02:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2016-07-06 15:30:09 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netdev_ioctl
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform network device specific operations.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* sockfd Socket descriptor of device
|
|
|
|
* cmd The ioctl command
|
|
|
|
* arg The argument of the ioctl cmd
|
|
|
|
*
|
|
|
|
* Return:
|
|
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
|
|
|
* On a failure, -1 is returned with errno set appropriately
|
|
|
|
*
|
|
|
|
* EBADF
|
|
|
|
* 'sockfd' is not a valid socket descriptor.
|
|
|
|
* EFAULT
|
|
|
|
* 'arg' references an inaccessible memory area.
|
|
|
|
* ENOTTY
|
|
|
|
* 'cmd' not valid.
|
|
|
|
* EINVAL
|
|
|
|
* 'arg' is not valid.
|
|
|
|
* ENOTTY
|
|
|
|
* 'sockfd' is not associated with a network device.
|
|
|
|
* ENOTTY
|
|
|
|
* The specified request does not apply to the kind of object that the
|
|
|
|
* descriptor 'sockfd' references.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int netdev_ioctl(int sockfd, int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
FAR struct socket *psock = sockfd_socket(sockfd);
|
|
|
|
|
|
|
|
return psock_ioctl(psock, cmd, arg);
|
|
|
|
}
|
|
|
|
|
2015-02-03 22:40:56 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netdev_ifup / netdev_ifdown
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Bring the interface up/down
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void netdev_ifup(FAR struct net_driver_s *dev)
|
|
|
|
{
|
|
|
|
/* Make sure that the device supports the d_ifup() method */
|
|
|
|
|
2017-03-14 00:59:36 +01:00
|
|
|
if (dev->d_ifup != NULL)
|
2015-02-03 22:40:56 +01:00
|
|
|
{
|
|
|
|
/* Is the interface already up? */
|
|
|
|
|
|
|
|
if ((dev->d_flags & IFF_UP) == 0)
|
|
|
|
{
|
|
|
|
/* No, bring the interface up now */
|
|
|
|
|
|
|
|
if (dev->d_ifup(dev) == OK)
|
|
|
|
{
|
|
|
|
/* Mark the interface as up */
|
|
|
|
|
|
|
|
dev->d_flags |= IFF_UP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void netdev_ifdown(FAR struct net_driver_s *dev)
|
|
|
|
{
|
2015-05-27 17:26:00 +02:00
|
|
|
/* Check sure that the device supports the d_ifdown() method */
|
2015-02-03 22:40:56 +01:00
|
|
|
|
2017-03-14 00:59:36 +01:00
|
|
|
if (dev->d_ifdown != NULL)
|
2015-02-03 22:40:56 +01:00
|
|
|
{
|
|
|
|
/* Is the interface already down? */
|
|
|
|
|
|
|
|
if ((dev->d_flags & IFF_UP) != 0)
|
|
|
|
{
|
|
|
|
/* No, take the interface down now */
|
|
|
|
|
|
|
|
if (dev->d_ifdown(dev) == OK)
|
|
|
|
{
|
|
|
|
/* Mark the interface as down */
|
|
|
|
|
|
|
|
dev->d_flags &= ~IFF_UP;
|
|
|
|
}
|
|
|
|
}
|
2015-05-27 17:26:00 +02:00
|
|
|
|
|
|
|
/* Notify clients that the network has been taken down */
|
|
|
|
|
2015-05-28 20:01:38 +02:00
|
|
|
(void)devif_dev_event(dev, NULL, NETDEV_DOWN);
|
2015-02-03 22:40:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-16 19:46:25 +02:00
|
|
|
#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */
|