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
|
|
|
*
|
2019-03-19 16:43:32 +01:00
|
|
|
* Copyright (C) 2007-2012, 2015-2019 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>
|
|
|
|
|
|
|
|
#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>
|
2017-08-20 15:10:48 +02:00
|
|
|
#include <nuttx/net/radiodev.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
|
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
#include <sys/sockio.h>
|
|
|
|
#include <nuttx/net/igmp.h>
|
2017-03-13 16:51:31 +01:00
|
|
|
|
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
|
|
|
|
|
2018-04-06 17:42:41 +02:00
|
|
|
#ifdef CONFIG_WIRELESS_BLUETOOTH
|
2018-04-29 20:43:09 +02:00
|
|
|
# include <nuttx/wireless/bluetooth/bt_ioctl.h>
|
2018-04-06 17:42:41 +02:00
|
|
|
#endif
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2018-04-06 17:42:41 +02:00
|
|
|
#ifdef CONFIG_WIRELESS_IEEE802154
|
|
|
|
# include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
|
|
|
#endif
|
2017-08-02 19:52:44 +02:00
|
|
|
|
2018-04-06 17:42:41 +02:00
|
|
|
#ifdef CONFIG_WIRELESS_PKTRADIO
|
|
|
|
# include <nuttx/wireless/pktradio.h>
|
2017-04-15 17:11:52 +02:00
|
|
|
#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"
|
2020-04-13 15:36:14 +02:00
|
|
|
#include "netlink/netlink.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
|
|
|
****************************************************************************/
|
2018-10-29 23:25:57 +01:00
|
|
|
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
/* Configuration */
|
|
|
|
|
|
|
|
#undef HAVE_WRITABLE_IPv4ROUTE
|
|
|
|
#undef HAVE_WRITABLE_IPv6ROUTE
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_ROUTE
|
|
|
|
# if defined(CONFIG_NET_IPv4) && !defined(CONFIG_ROUTE_IPv4_ROMROUTE)
|
|
|
|
# define HAVE_WRITABLE_IPv4ROUTE 1
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# if defined(CONFIG_NET_IPv6) && !defined(CONFIG_ROUTE_IPv6_ROMROUTE)
|
|
|
|
# define HAVE_WRITABLE_IPv6ROUTE 1
|
|
|
|
# endif
|
|
|
|
#endif
|
2007-09-17 00:12:04 +02:00
|
|
|
|
2018-04-06 17:42:41 +02:00
|
|
|
#undef HAVE_IEEE802154_IOCTL
|
|
|
|
#undef HAVE_PKTRADIO_IOCTL
|
|
|
|
#undef HAVE_BLUETOOTH_IOCTL
|
|
|
|
|
|
|
|
#ifdef CONFIG_NETDEV_IOCTL
|
|
|
|
/* IEEE 802.15.4 6LoWPAN or raw packet support */
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET_IEEE802154) || (defined(CONFIG_NET_6LOWPAN) && \
|
|
|
|
defined(CONFIG_WIRELESS_IEEE802154))
|
|
|
|
# define HAVE_IEEE802154_IOCTL 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* pktradio raw packet support not implemented */
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET_6LOWPAN) && defined(CONFIG_WIRELESS_PKTRADIO)
|
|
|
|
# define HAVE_PKTRADIO_IOCTL 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Bluetooth 6LoWPAN support not implemented */
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET_BLUETOOTH)
|
|
|
|
# define HAVE_BLUETOOTH_IOCTL 1
|
|
|
|
#endif
|
|
|
|
#endif /* CONFIG_NETDEV_IOCTL */
|
|
|
|
|
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
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#ifdef HAVE_WRITABLE_IPv4ROUTE
|
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;
|
|
|
|
|
2019-11-10 19:35:15 +01:00
|
|
|
addr = (FAR struct sockaddr_in *)&rtentry->rt_dst;
|
2015-01-16 19:30:18 +01:00
|
|
|
target = (in_addr_t)addr->sin_addr.s_addr;
|
|
|
|
|
2019-11-10 19:35:15 +01:00
|
|
|
addr = (FAR struct sockaddr_in *)&rtentry->rt_genmask;
|
2015-01-16 19:30:18 +01:00
|
|
|
netmask = (in_addr_t)addr->sin_addr.s_addr;
|
|
|
|
|
2019-11-10 19:35:15 +01:00
|
|
|
addr = (FAR struct sockaddr_in *)&rtentry->rt_gateway;
|
|
|
|
router = (in_addr_t)addr->sin_addr.s_addr;
|
2015-01-16 19:30:18 +01:00
|
|
|
|
2017-08-10 17:14:31 +02:00
|
|
|
return net_addroute_ipv4(target, netmask, router);
|
2015-01-16 19:30:18 +01:00
|
|
|
}
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#endif /* HAVE_WRITABLE_IPv4ROUTE */
|
2015-01-16 19:30:18 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2017-07-08 19:58:19 +02:00
|
|
|
* Name: ioctl_add_ipv6route
|
2015-01-16 19:30:18 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Add an IPv6 route to the routing table.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* rentry - Describes the route to be added
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#ifdef HAVE_WRITABLE_IPv6ROUTE
|
2017-07-08 19:58:19 +02:00
|
|
|
static int ioctl_add_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;
|
2019-11-10 19:35:15 +01:00
|
|
|
FAR struct sockaddr_in6 *gateway;
|
2015-01-16 19:30:18 +01:00
|
|
|
net_ipv6addr_t router;
|
|
|
|
|
2019-11-10 19:35:15 +01:00
|
|
|
target = (FAR struct sockaddr_in6 *)&rtentry->rt_dst;
|
|
|
|
netmask = (FAR struct sockaddr_in6 *)&rtentry->rt_genmask;
|
2015-01-16 19:30:18 +01:00
|
|
|
|
|
|
|
/* The router is an optional argument */
|
|
|
|
|
2019-11-10 19:35:15 +01:00
|
|
|
gateway = (FAR struct sockaddr_in6 *)&rtentry->rt_gateway;
|
|
|
|
net_ipv6addr_copy(router, gateway->sin6_addr.s6_addr16);
|
2015-01-16 19:30:18 +01:00
|
|
|
|
2019-10-25 19:31:42 +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
|
|
|
}
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#endif /* HAVE_WRITABLE_IPv6ROUTE */
|
2015-01-16 19:30:18 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
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
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#ifdef HAVE_WRITABLE_IPv4ROUTE
|
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;
|
|
|
|
|
2019-11-10 19:35:15 +01:00
|
|
|
addr = (FAR struct sockaddr_in *)&rtentry->rt_dst;
|
2015-01-16 19:30:18 +01:00
|
|
|
target = (in_addr_t)addr->sin_addr.s_addr;
|
|
|
|
|
2019-11-10 19:35:15 +01:00
|
|
|
addr = (FAR struct sockaddr_in *)&rtentry->rt_genmask;
|
2015-01-16 19:30:18 +01:00
|
|
|
netmask = (in_addr_t)addr->sin_addr.s_addr;
|
|
|
|
|
2017-08-10 17:14:31 +02:00
|
|
|
return net_delroute_ipv4(target, netmask);
|
2015-01-16 19:30:18 +01:00
|
|
|
}
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#endif /* HAVE_WRITABLE_IPv4ROUTE */
|
2015-01-16 19:30:18 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
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
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#ifdef HAVE_WRITABLE_IPv6ROUTE
|
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
|
|
|
|
2019-11-10 19:35:15 +01:00
|
|
|
target = (FAR struct sockaddr_in6 *)&rtentry->rt_dst;
|
|
|
|
netmask = (FAR struct sockaddr_in6 *)&rtentry->rt_genmask;
|
2015-01-16 19:30:18 +01:00
|
|
|
|
2019-11-10 19:35:15 +01:00
|
|
|
return net_delroute_ipv6(target->sin6_addr.s6_addr16,
|
|
|
|
netmask->sin6_addr.s6_addr16);
|
2015-01-16 19:30:18 +01:00
|
|
|
}
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#endif /* HAVE_WRITABLE_IPv6ROUTE */
|
2015-01-16 19:30:18 +01:00
|
|
|
|
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;
|
2020-02-25 15:53:39 +01:00
|
|
|
memset(dest->sin_zero, 0, sizeof(dest->sin_zero));
|
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-11-22 23:46:46 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: ioctl_get_ipv4broadcast
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Return the sub-net broadcast address to user memory.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* outaddr - Pointer to the user-provided memory to receive the address.
|
|
|
|
* inaddr - The source IP address in the device structure.
|
|
|
|
* netmask - The netmask address mask in the device structure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
2020-04-16 16:02:11 +02:00
|
|
|
static void ioctl_get_ipv4broadcast(FAR struct sockaddr *outaddr,
|
|
|
|
in_addr_t inaddr, in_addr_t netmask)
|
2017-11-22 23:46:46 +01:00
|
|
|
{
|
|
|
|
FAR struct sockaddr_in *dest = (FAR struct sockaddr_in *)outaddr;
|
|
|
|
dest->sin_family = AF_INET;
|
|
|
|
dest->sin_port = 0;
|
|
|
|
dest->sin_addr.s_addr = net_ipv4addr_broadcast(inaddr, netmask);
|
2020-02-25 15:53:39 +01:00
|
|
|
memset(dest->sin_zero, 0, sizeof(dest->sin_zero));
|
2017-11-22 23:46:46 +01: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.
|
2020-02-22 19:31:14 +01:00
|
|
|
* inaddr - The source IP address in the device structure.
|
2015-01-14 20:03:12 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#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.
|
2018-03-30 20:27:04 +02:00
|
|
|
* inaddr - Pointer to the user-provided memory to containing the new IP
|
2015-01-14 20:03:12 +01:00
|
|
|
* 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
|
|
|
{
|
2020-04-16 16:02:11 +02:00
|
|
|
FAR const struct sockaddr_in6 *src =
|
|
|
|
(FAR const struct sockaddr_in6 *)inaddr;
|
2015-01-14 20:03:12 +01:00
|
|
|
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
|
|
|
|
2018-03-31 22:55:03 +02:00
|
|
|
/****************************************************************************
|
2018-04-06 17:42:41 +02:00
|
|
|
* Name: netdev_bluetooth_ioctl
|
2018-03-31 22:55:03 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform Bluetooth network device specific operations.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* psock - Socket structure
|
|
|
|
* dev - Ethernet driver device structure
|
|
|
|
* cmd - The ioctl command
|
|
|
|
* req - The argument of the ioctl cmd
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
|
|
|
* Negated errno returned on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-04-06 17:42:41 +02:00
|
|
|
#ifdef HAVE_BLUETOOTH_IOCTL
|
|
|
|
static int netdev_bluetooth_ioctl(FAR struct socket *psock, int cmd,
|
2018-03-31 22:55:03 +02:00
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
FAR struct net_driver_s *dev;
|
|
|
|
FAR char *ifname;
|
2018-04-06 17:42:41 +02:00
|
|
|
int ret = -EINVAL;
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
if (arg != 0ul)
|
|
|
|
{
|
|
|
|
if (WL_IBLUETOOTHCMD(cmd))
|
|
|
|
{
|
|
|
|
/* Get the name of the Bluetooth device to receive the IOCTL
|
|
|
|
* command
|
|
|
|
*/
|
|
|
|
|
2018-04-06 17:42:41 +02:00
|
|
|
FAR struct btreq_s *btreq =
|
|
|
|
(FAR struct btreq_s *)((uintptr_t)arg);
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2018-04-06 17:42:41 +02:00
|
|
|
ifname = btreq->btr_name;
|
2018-03-31 22:55:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Not a Bluetooth IOCTL command */
|
|
|
|
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the device with this name */
|
|
|
|
|
|
|
|
dev = netdev_findbyname(ifname);
|
2018-04-06 17:42:41 +02:00
|
|
|
ret = -ENODEV;
|
|
|
|
|
2018-03-31 22:55:03 +02:00
|
|
|
if (dev != NULL && dev->d_lltype == NET_LL_BLUETOOTH)
|
|
|
|
{
|
|
|
|
/* Perform the device IOCTL */
|
|
|
|
|
|
|
|
ret = dev->d_ioctl(dev, cmd, arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-04-15 17:11:52 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netdev_iee802154_ioctl
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform IEEE802.15.4 network device specific operations.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2018-03-30 20:27:04 +02:00
|
|
|
* psock - Socket structure
|
|
|
|
* dev - Ethernet driver device structure
|
|
|
|
* cmd - The ioctl command
|
|
|
|
* req - The argument of the ioctl cmd
|
2017-04-15 17:11:52 +02:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2017-04-15 17:11:52 +02:00
|
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
|
|
|
* Negated errno returned on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-04-06 17:42:41 +02:00
|
|
|
#ifdef HAVE_IEEE802154_IOCTL
|
2017-04-15 17:11:52 +02:00
|
|
|
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
|
2017-08-02 19:52:44 +02:00
|
|
|
* command
|
2017-04-15 17:11:52 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
FAR struct ieee802154_netmac_s *netmac =
|
|
|
|
(FAR struct ieee802154_netmac_s *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
ifname = netmac->ifr_name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-02 19:52:44 +02:00
|
|
|
/* Not an EEE802.15.4 MAC IOCTL command */
|
2017-04-15 17:11:52 +02:00
|
|
|
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
|
|
|
|
2017-04-15 18:23:29 +02:00
|
|
|
/* Find the device with this name */
|
|
|
|
|
|
|
|
dev = netdev_findbyname(ifname);
|
2017-08-02 19:52:44 +02:00
|
|
|
if (dev != NULL && dev->d_lltype == NET_LL_IEEE802154)
|
|
|
|
{
|
|
|
|
/* Perform the device IOCTL */
|
|
|
|
|
|
|
|
ret = dev->d_ioctl(dev, cmd, arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2018-04-06 17:42:41 +02:00
|
|
|
#endif /* HAVE_IEEE802154_IOCTL */
|
2017-08-02 19:52:44 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: netdev_pktradio_ioctl
|
|
|
|
*
|
|
|
|
* Description:
|
2020-04-16 16:02:11 +02:00
|
|
|
* Perform non-IEEE802.15.4 packet radio network device specific operation.
|
2017-08-02 19:52:44 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2018-03-30 20:27:04 +02:00
|
|
|
* psock - Socket structure
|
|
|
|
* dev - Ethernet driver device structure
|
|
|
|
* cmd - The ioctl command
|
|
|
|
* req - The argument of the ioctl cmd
|
2017-08-02 19:52:44 +02:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2017-08-02 19:52:44 +02:00
|
|
|
* >=0 on success (positive non-zero values are cmd-specific)
|
|
|
|
* Negated errno returned on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-04-06 17:42:41 +02:00
|
|
|
#ifdef HAVE_PKTRADIO_IOCTL
|
2017-08-02 19:52:44 +02:00
|
|
|
static int netdev_pktradio_ioctl(FAR struct socket *psock, int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
FAR struct net_driver_s *dev;
|
|
|
|
FAR char *ifname;
|
|
|
|
int ret = -ENOTTY;
|
|
|
|
|
|
|
|
if (arg != 0ul)
|
|
|
|
{
|
|
|
|
if (WL_ISPKTRADIOCMD(cmd))
|
|
|
|
{
|
|
|
|
/* Get the packet radio device to receive the radio IOCTL
|
|
|
|
* command
|
|
|
|
*/
|
|
|
|
|
|
|
|
FAR struct pktradio_ifreq_s *cmddata =
|
|
|
|
(FAR struct pktradio_ifreq_s *)((uintptr_t)arg);
|
|
|
|
|
|
|
|
ifname = cmddata->pifr_name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Not a packet radio IOCTL command */
|
|
|
|
|
2017-08-02 22:28:17 +02:00
|
|
|
nwarn("WARNING: Not a packet radio IOCTL command: %d\n", cmd);
|
2017-08-02 19:52:44 +02:00
|
|
|
return -ENOTTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the device with this name */
|
|
|
|
|
|
|
|
dev = netdev_findbyname(ifname);
|
|
|
|
if (dev != NULL && dev->d_lltype == NET_LL_PKTRADIO)
|
2017-04-15 18:23:29 +02:00
|
|
|
{
|
|
|
|
/* 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;
|
|
|
|
}
|
2018-04-06 17:42:41 +02:00
|
|
|
#endif /* HAVE_PKTRADIO_IOCTL */
|
2017-04-15 17:11:52 +02:00
|
|
|
|
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.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-03-13 16:51:31 +01:00
|
|
|
* psock Socket structure
|
|
|
|
* dev Ethernet driver device structure
|
|
|
|
* cmd The ioctl command
|
|
|
|
* req The argument of the ioctl cmd
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2017-03-13 16:51:31 +01:00
|
|
|
* >=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
|
|
|
|
2020-04-16 16:02:11 +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.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-10-06 00:43:10 +02:00
|
|
|
* req - The argument of the ioctl cmd
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2013-10-06 00:43:10 +02:00
|
|
|
* 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.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input 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
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2007-09-16 19:46:25 +02:00
|
|
|
* >=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
|
|
|
|
|
|
|
|
#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 */
|
2017-11-22 23:46:46 +01:00
|
|
|
{
|
|
|
|
dev = netdev_ifr_dev(req);
|
|
|
|
if (dev)
|
|
|
|
{
|
|
|
|
ioctl_get_ipv4broadcast(&req->ifr_broadaddr, dev->d_ipaddr,
|
|
|
|
dev->d_netmask);
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
2015-01-14 20:03:12 +01:00
|
|
|
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)
|
|
|
|
{
|
2018-07-04 22:10:40 +02:00
|
|
|
req->ifr_mtu = NETDEV_PKTSIZE(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)
|
|
|
|
{
|
2019-09-20 20:45:05 +02:00
|
|
|
ret = icmpv6_autoconfig(dev);
|
2015-02-03 15:54:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
2018-04-26 16:10:23 +02:00
|
|
|
if (dev->d_lltype == NET_LL_ETHERNET ||
|
|
|
|
dev->d_lltype == NET_LL_IEEE80211)
|
2017-04-06 23:58:00 +02:00
|
|
|
{
|
|
|
|
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
|
2017-07-31 03:10:51 +02:00
|
|
|
if (dev->d_lltype == NET_LL_IEEE802154 ||
|
|
|
|
dev->d_lltype == NET_LL_PKTRADIO)
|
2017-04-06 23:58:00 +02:00
|
|
|
{
|
2017-07-31 03:10:51 +02:00
|
|
|
req->ifr_hwaddr.sa_family = AF_INETX;
|
|
|
|
memcpy(req->ifr_hwaddr.sa_data,
|
2017-08-19 16:48:52 +02:00
|
|
|
dev->d_mac.radio.nv_addr,
|
|
|
|
dev->d_mac.radio.nv_addrlen);
|
2017-07-31 03:10:51 +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;
|
|
|
|
|
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
|
2020-01-06 12:35:50 +01:00
|
|
|
if (dev->d_lltype == NET_LL_ETHERNET ||
|
|
|
|
dev->d_lltype == NET_LL_IEEE80211)
|
2017-04-06 23:58:00 +02:00
|
|
|
{
|
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
|
2017-07-31 03:10:51 +02:00
|
|
|
if (dev->d_lltype == NET_LL_IEEE802154 ||
|
|
|
|
dev->d_lltype == NET_LL_PKTRADIO)
|
2017-04-06 23:58:00 +02:00
|
|
|
{
|
2017-08-19 16:48:52 +02:00
|
|
|
FAR struct radio_driver_s *radio;
|
2017-08-20 15:10:48 +02:00
|
|
|
struct radiodev_properties_s properties;
|
2017-07-31 03:10:51 +02:00
|
|
|
|
|
|
|
/* Get the radio properties */
|
|
|
|
|
2017-08-19 16:48:52 +02:00
|
|
|
radio = (FAR struct radio_driver_s *)dev;
|
2017-07-31 03:10:51 +02:00
|
|
|
DEBUGASSERT(radio->r_properties != NULL);
|
|
|
|
|
|
|
|
ret = radio->r_properties(radio, &properties);
|
|
|
|
if (ret >= 0)
|
|
|
|
{
|
2017-08-19 16:48:52 +02:00
|
|
|
dev->d_mac.radio.nv_addrlen = properties.sp_addrlen;
|
|
|
|
memcpy(dev->d_mac.radio.nv_addr,
|
2017-07-31 03:10:51 +02:00
|
|
|
req->ifr_hwaddr.sa_data, 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;
|
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-09-19 22:17:05 +02:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
case SIOCGIFCONF: /* Return an interface list (IPv4) */
|
|
|
|
{
|
|
|
|
ret = netdev_ipv4_ifconf((FAR struct ifconf *)req);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
case SIOCGLIFCONF: /* Return an interface list (IPv6) */
|
|
|
|
{
|
|
|
|
ret = netdev_ipv6_ifconf((FAR struct lifconf *)req);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
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)
|
|
|
|
{
|
2020-04-16 16:02:11 +02:00
|
|
|
struct mii_ioctl_notify_s *notify =
|
|
|
|
&req->ifr_ifru.ifru_mii_notify;
|
|
|
|
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)
|
|
|
|
{
|
2020-04-16 16:02:11 +02:00
|
|
|
struct mii_ioctl_data_s *mii_data =
|
|
|
|
&req->ifr_ifru.ifru_mii_data;
|
|
|
|
ret = dev->d_ioctl(dev, cmd,
|
|
|
|
(unsigned long)(uintptr_t)mii_data);
|
2014-06-27 17:30:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2020-10-24 03:40:33 +02:00
|
|
|
#endif
|
2020-06-15 10:23:25 +02:00
|
|
|
|
|
|
|
#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NETDEV_CAN_BITRATE_IOCTL)
|
|
|
|
case SIOCGCANBITRATE: /* Get bitrate from a CAN controller */
|
|
|
|
case SIOCSCANBITRATE: /* Set bitrate of a CAN controller */
|
|
|
|
{
|
|
|
|
dev = netdev_ifr_dev(req);
|
|
|
|
if (dev && dev->d_ioctl)
|
|
|
|
{
|
|
|
|
struct can_ioctl_data_s *can_bitrate_data =
|
|
|
|
&req->ifr_ifru.ifru_can_data;
|
|
|
|
ret = dev->d_ioctl(dev, cmd,
|
|
|
|
(unsigned long)(uintptr_t)can_bitrate_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NETDEV_IFINDEX
|
|
|
|
case SIOCGIFNAME: /* Get interface name */
|
|
|
|
{
|
2020-06-15 14:09:26 +02:00
|
|
|
dev = netdev_findbyindex(req->ifr_ifindex);
|
2020-06-15 10:23:25 +02:00
|
|
|
if (dev != NULL)
|
|
|
|
{
|
|
|
|
strncpy(req->ifr_name, dev->d_ifname, IFNAMSIZ);
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -ENODEV;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIFINDEX: /* Index to name mapping */
|
|
|
|
{
|
2020-06-15 14:09:26 +02:00
|
|
|
dev = netdev_findbyname(req->ifr_name);
|
2020-06-15 10:23:25 +02:00
|
|
|
if (dev != NULL)
|
|
|
|
{
|
|
|
|
req->ifr_ifindex = dev->d_ifindex;
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = -ENODEV;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-06-27 17:30:41 +02:00
|
|
|
#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.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-10-06 00:43:10 +02:00
|
|
|
* req - The argument of the ioctl cmd
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2013-10-06 00:43:10 +02:00
|
|
|
* 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
|
|
|
{
|
2018-10-29 13:50:47 +01:00
|
|
|
if (imsf == NULL)
|
2013-10-06 00:43:10 +02:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-10-29 13:50:47 +01:00
|
|
|
/* Find the network device associated with the address of the IP address
|
|
|
|
* of the local device.
|
2013-10-06 00:43:10 +02:00
|
|
|
*/
|
|
|
|
|
2018-10-29 19:20:44 +01:00
|
|
|
return netdev_findby_lipv4addr(imsf->imsf_interface.s_addr);
|
2013-10-06 00:43:10 +02:00
|
|
|
}
|
|
|
|
#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.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2010-07-11 20:10:22 +02:00
|
|
|
* 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
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2010-07-11 20:10:22 +02:00
|
|
|
* >=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.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2016-02-08 18:17:22 +01:00
|
|
|
* psock Socket structure
|
|
|
|
* dev Ethernet driver device structure
|
|
|
|
* cmd The ioctl command
|
|
|
|
* req The argument of the ioctl cmd
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2016-02-08 18:17:22 +01:00
|
|
|
* >=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;
|
|
|
|
|
2020-04-16 16:02:11 +02:00
|
|
|
/* Find the existing ARP entry for this protocol address. */
|
2016-02-08 18:17:22 +01:00
|
|
|
|
2020-04-16 16:02:11 +02:00
|
|
|
FAR struct arp_entry_s *entry =
|
|
|
|
arp_lookup(addr->sin_addr.s_addr);
|
2016-02-08 18:17:22 +01:00
|
|
|
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;
|
|
|
|
|
2018-08-25 14:47:10 +02:00
|
|
|
/* Get the hardware address from an existing ARP table entry
|
|
|
|
* matching this protocol address.
|
|
|
|
*/
|
2016-02-08 18:17:22 +01:00
|
|
|
|
2018-08-25 14:47:10 +02:00
|
|
|
ret = arp_find(addr->sin_addr.s_addr,
|
|
|
|
(FAR struct ether_addr *)req->arp_ha.sa_data);
|
2018-08-25 01:36:08 +02:00
|
|
|
if (ret >= 0)
|
2016-02-08 18:17:22 +01:00
|
|
|
{
|
|
|
|
/* Return the mapped hardware address. */
|
|
|
|
|
|
|
|
req->arp_ha.sa_family = ARPHRD_ETHER;
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2013-10-02 18:51:48 +02:00
|
|
|
* psock Socket structure
|
|
|
|
* dev Ethernet driver device structure
|
|
|
|
* cmd The ioctl command
|
|
|
|
* rtentry The argument of the ioctl cmd
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2013-10-02 18:51:48 +02:00
|
|
|
* >=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
|
|
|
|
2019-11-10 19:35:15 +01:00
|
|
|
if (rtentry == NULL)
|
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
|
2019-11-10 19:35:15 +01:00
|
|
|
if (rtentry->rt_dst.ss_family == AF_INET)
|
2015-01-18 17:33:27 +01:00
|
|
|
#endif
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#ifdef HAVE_WRITABLE_IPv4ROUTE
|
2017-04-15 18:29:37 +02:00
|
|
|
ret = ioctl_add_ipv4route(rtentry);
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#else
|
|
|
|
ret = -EACCES;
|
|
|
|
#endif
|
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
|
|
|
{
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#ifdef HAVE_WRITABLE_IPv6ROUTE
|
2017-07-08 19:58:19 +02:00
|
|
|
ret = ioctl_add_ipv6route(rtentry);
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#else
|
|
|
|
ret = -EACCES;
|
|
|
|
#endif
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-11-10 19:35:15 +01:00
|
|
|
if (rtentry == 0)
|
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
|
2019-11-10 19:35:15 +01:00
|
|
|
if (rtentry->rt_dst.ss_family == AF_INET)
|
2015-01-18 17:33:27 +01:00
|
|
|
#endif
|
2015-01-16 19:30:18 +01:00
|
|
|
{
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#ifdef HAVE_WRITABLE_IPv4ROUTE
|
2017-04-15 18:29:37 +02:00
|
|
|
ret = ioctl_del_ipv4route(rtentry);
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#else
|
|
|
|
ret = -EACCES;
|
|
|
|
#endif
|
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
|
|
|
{
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#ifdef HAVE_WRITABLE_IPv6ROUTE
|
2017-04-15 18:29:37 +02:00
|
|
|
ret = ioctl_del_ipv6route(rtentry);
|
Addes support for read-only routing tables. Prior to this change, routing tables were only support in RAM and had to be initialized with explicit logic to add the necessary routes to the routing table. With this change, routes may be defined in the pre-initialized, read-only routing table provided by the board-specific logic
This would be particularly useful, for example, in the case where there is only a single network adaptor and you want all output packets to go to the single adaptor in all cases. So for that behavior you could add a read-only routing table to the board-specific long that contains a single entry, the default route: 0.0.0.0/0.
Squashed commit of the following:
net/route: RAM and ROM routing tables build correctly in all IPv4 and IPv6 configurations.
net/route: Verify IPv6 ROM route build; Make number of ROM routes a variable, not a configuration item.
net/route: Add initial support for ROM-base, read-only routing tables.
net/route: Adjust and generalize some structures, rename some functions, and add configuration and build support that will eventually support read-only routing tables.
net/route: Some initial though experiments on use of a fixe, read-only routing table
2017-09-28 17:04:31 +02:00
|
|
|
#else
|
|
|
|
ret = -EACCES;
|
|
|
|
#endif
|
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
|
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: netdev_usrsock_ioctl
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform user private ioctl operations.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* psock Socket structure
|
|
|
|
* cmd The ioctl command
|
|
|
|
* arg 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_USRSOCK
|
|
|
|
static int netdev_usrsock_ioctl(FAR struct socket *psock, int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
|
|
|
if (psock->s_sockif && psock->s_sockif->si_ioctl)
|
|
|
|
{
|
|
|
|
ssize_t arglen;
|
|
|
|
|
|
|
|
arglen = net_ioctl_arglen(cmd);
|
|
|
|
if (arglen < 0)
|
|
|
|
{
|
|
|
|
return arglen;
|
|
|
|
}
|
|
|
|
|
|
|
|
return psock->s_sockif->si_ioctl(psock, cmd, (FAR void *)arg, arglen);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#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
|
|
|
****************************************************************************/
|
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: net_ioctl_arglen
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Calculate the ioctl argument buffer length.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
*
|
|
|
|
* cmd The ioctl command
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* The argument buffer length, or error code.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_USRSOCK
|
|
|
|
ssize_t net_ioctl_arglen(int cmd)
|
|
|
|
{
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case SIOCGIFADDR:
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
case SIOCGIFDSTADDR:
|
|
|
|
case SIOCSIFDSTADDR:
|
|
|
|
case SIOCGIFBRDADDR:
|
|
|
|
case SIOCSIFBRDADDR:
|
|
|
|
case SIOCGIFNETMASK:
|
|
|
|
case SIOCSIFNETMASK:
|
|
|
|
case SIOCGIFMTU:
|
|
|
|
case SIOCGIFHWADDR:
|
|
|
|
case SIOCSIFHWADDR:
|
|
|
|
case SIOCDIFADDR:
|
|
|
|
case SIOCGIFCOUNT:
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
case SIOCGIFFLAGS:
|
|
|
|
return sizeof(struct ifreq);
|
2018-10-29 13:50:47 +01:00
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
case SIOCGLIFADDR:
|
|
|
|
case SIOCSLIFADDR:
|
|
|
|
case SIOCGLIFDSTADDR:
|
|
|
|
case SIOCSLIFDSTADDR:
|
|
|
|
case SIOCGLIFBRDADDR:
|
|
|
|
case SIOCSLIFBRDADDR:
|
|
|
|
case SIOCGLIFNETMASK:
|
|
|
|
case SIOCSLIFNETMASK:
|
|
|
|
case SIOCGLIFMTU:
|
|
|
|
case SIOCIFAUTOCONF:
|
|
|
|
return sizeof(struct lifreq);
|
2018-10-29 13:50:47 +01:00
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
case SIOCGIFCONF:
|
|
|
|
return sizeof(struct ifconf);
|
2018-10-29 13:50:47 +01:00
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
case SIOCGLIFCONF:
|
|
|
|
return sizeof(struct lifconf);
|
2018-10-29 13:50:47 +01:00
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
case SIOCGIPMSFILTER:
|
|
|
|
case SIOCSIPMSFILTER:
|
|
|
|
return sizeof(struct ip_msfilter);
|
2018-10-29 13:50:47 +01:00
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
case SIOCSARP:
|
|
|
|
case SIOCDARP:
|
|
|
|
case SIOCGARP:
|
|
|
|
return sizeof(struct arpreq);
|
2018-10-29 13:50:47 +01:00
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
case SIOCADDRT:
|
|
|
|
case SIOCDELRT:
|
|
|
|
return sizeof(struct rtentry);
|
2018-10-29 13:50:47 +01:00
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
case SIOCMIINOTIFY:
|
2019-01-27 23:42:18 +01:00
|
|
|
return sizeof(struct mii_ioctl_notify_s);
|
2018-10-29 13:50:47 +01:00
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
case SIOCGMIIPHY:
|
|
|
|
case SIOCGMIIREG:
|
|
|
|
case SIOCSMIIREG:
|
|
|
|
return sizeof(struct mii_ioctl_data_s);
|
2018-10-29 13:50:47 +01:00
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
default:
|
|
|
|
#ifdef CONFIG_NETDEV_IOCTL
|
|
|
|
# ifdef CONFIG_NETDEV_WIRELESS_IOCTL
|
|
|
|
if (_WLIOCVALID(cmd) && _IOC_NR(cmd) <= WL_NNETCMDS)
|
|
|
|
{
|
|
|
|
return sizeof(struct iwreq);
|
|
|
|
}
|
|
|
|
# endif
|
2019-10-25 19:31:42 +02:00
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
# ifdef CONFIG_WIRELESS_IEEE802154
|
|
|
|
if (_MAC802154IOCVALID(cmd))
|
|
|
|
{
|
|
|
|
return sizeof(struct ieee802154_netmac_s);
|
|
|
|
}
|
|
|
|
# endif
|
2019-10-25 19:31:42 +02:00
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
# ifdef CONFIG_WIRELESS_PKTRADIO
|
|
|
|
if (WL_ISPKTRADIOCMD(cmd))
|
|
|
|
{
|
|
|
|
return sizeof(struct pktradio_ifreq_s);
|
|
|
|
}
|
|
|
|
# endif
|
2019-10-25 19:31:42 +02:00
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
# ifdef CONFIG_WIRELESS_BLUETOOTH
|
|
|
|
if (WL_IBLUETOOTHCMD(cmd))
|
|
|
|
{
|
|
|
|
return sizeof(struct btreq_s);
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
#endif
|
2019-10-25 19:31:42 +02:00
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
return -ENOTTY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-07-11 20:10:22 +02:00
|
|
|
/****************************************************************************
|
2020-05-04 11:00:51 +02:00
|
|
|
* Name: psock_ioctl and psock_vioctl
|
2010-07-11 20:10:22 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform network device specific operations.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input 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
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2017-09-30 18:41:21 +02:00
|
|
|
* A non-negative value is returned on success; a negated errno value is
|
|
|
|
* returned on any failure to indicate the nature of the failure:
|
2010-07-11 20:10:22 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-05-04 11:00:51 +02:00
|
|
|
int psock_vioctl(FAR struct socket *psock, int cmd, va_list ap)
|
2010-07-11 20:10:22 +02:00
|
|
|
{
|
2020-05-04 11:00:51 +02:00
|
|
|
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
|
|
|
{
|
2017-09-30 18:41:21 +02:00
|
|
|
return -EBADF;
|
2010-07-11 20:10:22 +02:00
|
|
|
}
|
|
|
|
|
2020-05-04 11:00:51 +02:00
|
|
|
arg = va_arg(ap, unsigned long);
|
|
|
|
|
2018-08-26 22:54:26 +02:00
|
|
|
#ifdef CONFIG_NET_USRSOCK
|
|
|
|
/* Check for a USRSOCK ioctl command */
|
|
|
|
|
|
|
|
ret = netdev_usrsock_ioctl(psock, cmd, arg);
|
|
|
|
if (ret == -ENOTTY)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* Check for a standard network IOCTL command. */
|
|
|
|
|
2020-04-16 16:02:11 +02:00
|
|
|
ret = netdev_ifr_ioctl(psock, cmd, (FAR struct ifreq *)(uintptr_t)arg);
|
2018-08-26 22:54:26 +02:00
|
|
|
}
|
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
|
|
|
|
|
2018-04-06 17:42:41 +02:00
|
|
|
#ifdef HAVE_IEEE802154_IOCTL
|
|
|
|
/* Check for a IEEE802.15.4 network device IOCTL command */
|
2017-04-15 18:23:29 +02:00
|
|
|
|
|
|
|
if (ret == -ENOTTY)
|
|
|
|
{
|
|
|
|
ret = netdev_iee802154_ioctl(psock, cmd, arg);
|
|
|
|
}
|
|
|
|
#endif
|
2018-04-06 17:42:41 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_PKTRADIO_IOCTL
|
|
|
|
/* Check for a non-IEEE802.15.4 packet radio network device IOCTL command */
|
2017-08-02 19:52:44 +02:00
|
|
|
|
|
|
|
if (ret == -ENOTTY)
|
|
|
|
{
|
|
|
|
ret = netdev_pktradio_ioctl(psock, cmd, arg);
|
|
|
|
}
|
|
|
|
#endif
|
2018-04-06 17:42:41 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_BLUETOOTH_IOCTL
|
|
|
|
/* Check for Bluetooth network device IOCTL command */
|
|
|
|
|
|
|
|
if (ret == -ENOTTY)
|
|
|
|
{
|
|
|
|
ret = netdev_bluetooth_ioctl(psock, cmd, arg);
|
|
|
|
}
|
2017-08-02 19:52:44 +02:00
|
|
|
#endif
|
2017-04-15 18:23:29 +02:00
|
|
|
|
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,
|
2020-04-16 16:02:11 +02:00
|
|
|
(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,
|
2020-04-16 16:02:11 +02:00
|
|
|
(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,
|
2020-04-16 16:02:11 +02:00
|
|
|
(FAR struct rtentry *)(uintptr_t)arg);
|
2010-07-11 20:10:22 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-09-30 18:41:21 +02:00
|
|
|
return ret;
|
2007-09-16 19:46:25 +02:00
|
|
|
}
|
|
|
|
|
2020-05-04 11:00:51 +02:00
|
|
|
int psock_ioctl(FAR struct socket *psock, int cmd, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Setup to access the variable argument list */
|
|
|
|
|
|
|
|
va_start(ap, cmd);
|
|
|
|
|
|
|
|
/* Let psock_vfcntl() do the real work. The errno is not set on
|
|
|
|
* failures.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ret = psock_vioctl(psock, cmd, ap);
|
|
|
|
|
|
|
|
va_end(ap);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-07-06 15:30:09 +02:00
|
|
|
/****************************************************************************
|
2020-05-14 18:33:08 +02:00
|
|
|
* Name: netdev_vioctl
|
2016-07-06 15:30:09 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform network device specific operations.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2016-07-06 15:30:09 +02:00
|
|
|
* sockfd Socket descriptor of device
|
|
|
|
* cmd The ioctl command
|
2020-05-04 11:00:51 +02:00
|
|
|
* ap The argument of the ioctl cmd
|
2016-07-06 15:30:09 +02:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2017-09-30 18:41:21 +02:00
|
|
|
* A non-negative value is returned on success; a negated errno value is
|
|
|
|
* returned on any failure to indicate the nature of the failure:
|
2016-07-06 15:30:09 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-05-04 11:00:51 +02:00
|
|
|
int netdev_vioctl(int sockfd, int cmd, va_list ap)
|
2016-07-06 15:30:09 +02:00
|
|
|
{
|
|
|
|
FAR struct socket *psock = sockfd_socket(sockfd);
|
|
|
|
|
2020-05-09 02:11:13 +02:00
|
|
|
return psock_vioctl(psock, cmd, ap);
|
2016-07-06 15:30:09 +02:00
|
|
|
}
|
|
|
|
|
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;
|
2020-04-13 15:36:14 +02:00
|
|
|
|
|
|
|
/* Update the driver status */
|
|
|
|
|
|
|
|
netlink_device_notify(dev);
|
2015-02-03 22:40:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2020-04-13 15:36:14 +02:00
|
|
|
|
|
|
|
/* Update the driver status */
|
|
|
|
|
|
|
|
netlink_device_notify(dev);
|
2015-02-03 22:40:56 +01:00
|
|
|
}
|
|
|
|
}
|
2015-05-27 17:26:00 +02:00
|
|
|
|
|
|
|
/* Notify clients that the network has been taken down */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
devif_dev_event(dev, NULL, NETDEV_DOWN);
|
2018-09-09 18:39:25 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NETDOWN_NOTIFIER
|
|
|
|
/* Provide signal notifications to threads that want to be
|
|
|
|
* notified of the network down state via signal.
|
|
|
|
*/
|
|
|
|
|
|
|
|
netdown_notifier_signal(dev);
|
|
|
|
#endif
|
2015-02-03 22:40:56 +01:00
|
|
|
}
|
|
|
|
}
|