forked from nuttx/nuttx-update
Networking: Add support for IPv6 ioctls
This commit is contained in:
parent
babe9cf08e
commit
7d68c22d7f
4 changed files with 273 additions and 138 deletions
|
@ -1,7 +1,7 @@
|
|||
/*******************************************************************************************
|
||||
* include/net/if.h
|
||||
*
|
||||
* Copyright (C) 2007, 2008, 2012 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007, 2008, 2012, 2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -84,8 +84,11 @@ struct mii_ioctl_data_s
|
|||
uint16_t val_out; /* PHY output data */
|
||||
};
|
||||
|
||||
/* This is the newer form if the I/F request structure that can be used with both IPv4
|
||||
* and IPv6.
|
||||
/* There are two forms of the I/F request structure. One for IPv6 and one for IPv4.
|
||||
* Notice that they are (and must be) cast compatible and really different only
|
||||
* in the size of the structure allocation.
|
||||
*
|
||||
* This is the I/F request that should be used with IPv6.
|
||||
*/
|
||||
|
||||
struct lifreq
|
||||
|
@ -122,12 +125,8 @@ struct lifreq
|
|||
#define lifr_mii_val_in lifr_ifru.lifru_mii_data.val_in /* PHY input data */
|
||||
#define lifr_mii_val_out lifr_ifru.lifru_mii_data.val_out /* PHY output data */
|
||||
|
||||
/* This is the older I/F request that should only be used with IPv4. However, since
|
||||
* NuttX only supports IPv4 or 6 (not both), we can force the older structure to
|
||||
* be compatible when IPv6 is enabled.
|
||||
*/
|
||||
/* This is the I/F request that should be used with IPv4. */
|
||||
|
||||
#ifndef CONFIG_NET_IPv6
|
||||
struct ifreq
|
||||
{
|
||||
char ifr_name[IFNAMSIZ]; /* Network device name (e.g. "eth0") */
|
||||
|
@ -162,25 +161,6 @@ struct ifreq
|
|||
#define ifr_mii_val_in ifr_ifru.ifru_mii_data.val_in /* PHY input data */
|
||||
#define ifr_mii_val_out ifr_ifru.ifru_mii_data.val_out /* PHY output data */
|
||||
|
||||
#else /* CONFIG_NET_IPv6 */
|
||||
|
||||
#define ifreq lifreq /* Replace ifreq with lifreq */
|
||||
#define ifr_name lifr_name /* Network device name */
|
||||
#define ifr_addr lifr_ifru.lifru_addr /* IP address */
|
||||
#define ifr_dstaddr lifr_ifru.lifru_dstaddr /* P-to-P Address */
|
||||
#define ifr_broadaddr lifr_ifru.lifru_broadaddr /* Broadcast address */
|
||||
#define ifr_netmask lifr_ifru.lifru_netmask /* Interface net mask */
|
||||
#define ifr_hwaddr lifr_ifru.lifru_hwaddr /* MAC address */
|
||||
#define ifr_mtu lifr_ifru.lifru_mtu /* MTU */
|
||||
#define ifr_count lifr_ifru.lifru_count /* Number of devices */
|
||||
#define ifr_flags lifr_ifru.lifru_flags /* interface flags */
|
||||
#define ifr_mii_phy_id lifr_ifru.lifru_mii_data.phy_id /* PHY device address */
|
||||
#define ifr_mii_reg_num lifr_ifru.lifru_mii_data.reg_num /* PHY register address */
|
||||
#define ifr_mii_val_in lifr_ifru.lifru_mii_data.val_in /* PHY input data */
|
||||
#define ifr_mii_val_out lifr_ifru.lifru_mii_data.val_out /* PHY output data */
|
||||
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/*******************************************************************************************
|
||||
* Public Function Prototypes
|
||||
*******************************************************************************************/
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
* include/nuttx/net/ioctl.h
|
||||
*
|
||||
* Copyright (C) 2007-2008, 2010-2013 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007-2008, 2010-2013, 2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -43,7 +43,7 @@
|
|||
#include <nuttx/fs/ioctl.h> /* _SIOCBASE, etc. */
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* These are ioctl commands to use with a socket FD. At present, commands
|
||||
|
@ -54,7 +54,7 @@
|
|||
#define _SIOCVALID(c) (_IOC_TYPE(c)==_SIOCBASE)
|
||||
#define _SIOC(nr) _IOC(_SIOCBASE,nr)
|
||||
|
||||
/* Interface control operations */
|
||||
/* IPv4 interface control operations */
|
||||
|
||||
#define SIOCGIFADDR _SIOC(0x0001) /* Get IP address */
|
||||
#define SIOCSIFADDR _SIOC(0x0002) /* Set IP address */
|
||||
|
@ -65,108 +65,109 @@
|
|||
#define SIOCGIFNETMASK _SIOC(0x0007) /* Get network mask */
|
||||
#define SIOCSIFNETMASK _SIOC(0x0008) /* Set network mask */
|
||||
#define SIOCGIFMTU _SIOC(0x0009) /* Get MTU size */
|
||||
#define SIOCGIFHWADDR _SIOC(0x000a) /* Get hardware address */
|
||||
#define SIOCSIFHWADDR _SIOC(0x000b) /* Set hardware address */
|
||||
#define SIOCDIFADDR _SIOC(0x000c) /* Delete IP address */
|
||||
#define SIOCGIFCOUNT _SIOC(0x000d) /* Get number of devices */
|
||||
|
||||
/* Newer interface ioctls that use the struct lifreq. Can be used for
|
||||
* both IPv4 and IPv6.
|
||||
*/
|
||||
/* IPv6 interface control operations */
|
||||
|
||||
#define SIOCGLIFADDR SIOCGIFADDR /* Get IP address */
|
||||
#define SIOCSLIFADDR SIOCSIFADDR /* Set IP address */
|
||||
#define SIOCGLIFDSTADDR SIOCSIFDSTADDR /* Get P-to-P address */
|
||||
#define SIOCSLIFDSTADDR SIOCSIFDSTADDR /* Set P-to-P address */
|
||||
#define SIOCGLIFBRDADDR SIOCGIFBRDADDR /* Get broadcast IP address */
|
||||
#define SIOCSLIFBRDADDR SIOCSIFBRDADDR /* Set broadcast IP address */
|
||||
#define SIOCGLIFNETMASK SIOCGIFNETMASK /* Get network mask */
|
||||
#define SIOCSLIFNETMASK SIOCSIFNETMASK /* Set network mask */
|
||||
#define SIOCGLIFMTU SIOCGIFMTU /* Get MTU size */
|
||||
#define SIOCGLIFADDR _SIOC(0x000a) /* Get IP address */
|
||||
#define SIOCSLIFADDR _SIOC(0x000b) /* Set IP address */
|
||||
#define SIOCGLIFDSTADDR _SIOC(0x000c) /* Get P-to-P address */
|
||||
#define SIOCSLIFDSTADDR _SIOC(0x000d) /* Set P-to-P address */
|
||||
#define SIOCGLIFBRDADDR _SIOC(0x000e) /* Get broadcast IP address */
|
||||
#define SIOCSLIFBRDADDR _SIOC(0x000f) /* Set broadcast IP address */
|
||||
#define SIOCGLIFNETMASK _SIOC(0x0010) /* Get network mask */
|
||||
#define SIOCSLIFNETMASK _SIOC(0x0011) /* Set network mask */
|
||||
#define SIOCGLIFMTU _SIOC(0x0012) /* Get MTU size */
|
||||
|
||||
/* Common interface control operations */
|
||||
|
||||
#define SIOCGIFHWADDR _SIOC(0x0013) /* Get hardware address */
|
||||
#define SIOCSIFHWADDR _SIOC(0x0014) /* Set hardware address */
|
||||
#define SIOCDIFADDR _SIOC(0x0015) /* Delete IP address */
|
||||
#define SIOCGIFCOUNT _SIOC(0x0016) /* Get number of devices */
|
||||
|
||||
/* Interface flags */
|
||||
|
||||
#define SIOCSIFFLAGS _SIOC(0x000e) /* Sets the interface flags */
|
||||
#define SIOCGIFFLAGS _SIOC(0x000f) /* Gets the interface flags */
|
||||
#define SIOCSIFFLAGS _SIOC(0x0017) /* Sets the interface flags */
|
||||
#define SIOCGIFFLAGS _SIOC(0x0018) /* Gets the interface flags */
|
||||
|
||||
#define SIOCGIPMSFILTER _SIOC(0x0010) /* Retrieve source filter addresses */
|
||||
#define SIOCSIPMSFILTER _SIOC(0x0011) /* Set source filter content */
|
||||
#define SIOCGIPMSFILTER _SIOC(0x0019) /* Retrieve source filter addresses */
|
||||
#define SIOCSIPMSFILTER _SIOC(0x001a) /* Set source filter content */
|
||||
|
||||
/* Routing table. Argument is a reference to struct rtentry as defined in
|
||||
* include/net/route.h
|
||||
*/
|
||||
|
||||
#define SIOCADDRT _SIOC(0x0012) /* Add an entry to the routing table */
|
||||
#define SIOCDELRT _SIOC(0x0013) /* Delete an entry from the routing table */
|
||||
#define SIOCADDRT _SIOC(0x001b) /* Add an entry to the routing table */
|
||||
#define SIOCDELRT _SIOC(0x001c) /* Delete an entry from the routing table */
|
||||
|
||||
/* Wireless ioctl commands **************************************************/
|
||||
|
||||
#define SIOCSIWCOMMIT _SIOC(0x0014) /* Commit pending changes to driver */
|
||||
#define SIOCGIWNAME _SIOC(0x0015) /* Get name of wireless protocol */
|
||||
#define SIOCSIWCOMMIT _SIOC(0x001d) /* Commit pending changes to driver */
|
||||
#define SIOCGIWNAME _SIOC(0x001e) /* Get name of wireless protocol */
|
||||
|
||||
#define SIOCSIWNWID _SIOC(0x0016) /* Set network ID (pre-802.11) */
|
||||
#define SIOCGIWNWID _SIOC(0x0017) /* Get network ID (the cell) */
|
||||
#define SIOCSIWFREQ _SIOC(0x0018) /* Set channel/frequency (Hz) */
|
||||
#define SIOCGIWFREQ _SIOC(0x0019) /* Get channel/frequency (Hz) */
|
||||
#define SIOCSIWMODE _SIOC(0x001a) /* Set operation mode */
|
||||
#define SIOCGIWMODE _SIOC(0x001b) /* Get operation mode */
|
||||
#define SIOCSIWSENS _SIOC(0x001c) /* Set sensitivity (dBm) */
|
||||
#define SIOCGIWSENS _SIOC(0x001d) /* Get sensitivity (dBm) */
|
||||
#define SIOCSIWNWID _SIOC(0x001f) /* Set network ID (pre-802.11) */
|
||||
#define SIOCGIWNWID _SIOC(0x0020) /* Get network ID (the cell) */
|
||||
#define SIOCSIWFREQ _SIOC(0x0021) /* Set channel/frequency (Hz) */
|
||||
#define SIOCGIWFREQ _SIOC(0x0022) /* Get channel/frequency (Hz) */
|
||||
#define SIOCSIWMODE _SIOC(0x0023) /* Set operation mode */
|
||||
#define SIOCGIWMODE _SIOC(0x0024) /* Get operation mode */
|
||||
#define SIOCSIWSENS _SIOC(0x0025) /* Set sensitivity (dBm) */
|
||||
#define SIOCGIWSENS _SIOC(0x0026) /* Get sensitivity (dBm) */
|
||||
|
||||
#define SIOCGIWRANGE _SIOC(0x001e) /* Get range of parameters */
|
||||
#define SIOCGIWPRIV _SIOC(0x001f) /* Get private ioctl interface info */
|
||||
#define SIOCGIWSTATS _SIOC(0x0020) /* Get wireless stats */
|
||||
#define SIOCGIWRANGE _SIOC(0x0027) /* Get range of parameters */
|
||||
#define SIOCGIWPRIV _SIOC(0x0028) /* Get private ioctl interface info */
|
||||
#define SIOCGIWSTATS _SIOC(0x0029) /* Get wireless stats */
|
||||
|
||||
#define SIOCSIWSPY _SIOC(0x0021) /* Set spy addresses */
|
||||
#define SIOCGIWSPY _SIOC(0x0022) /* Get spy info (quality of link) */
|
||||
#define SIOCSIWTHRSPY _SIOC(0x0023) /* Set spy threshold (spy event) */
|
||||
#define SIOCGIWTHRSPY _SIOC(0x0024) /* Get spy threshold */
|
||||
#define SIOCSIWSPY _SIOC(0x002a) /* Set spy addresses */
|
||||
#define SIOCGIWSPY _SIOC(0x002b) /* Get spy info (quality of link) */
|
||||
#define SIOCSIWTHRSPY _SIOC(0x002c) /* Set spy threshold (spy event) */
|
||||
#define SIOCGIWTHRSPY _SIOC(0x002d) /* Get spy threshold */
|
||||
|
||||
#define SIOCSIWAP _SIOC(0x0025) /* Set access point MAC addresses */
|
||||
#define SIOCGIWAP _SIOC(0x0026) /* Get access point MAC addresses */
|
||||
#define SIOCGIWAPLIST _SIOC(0x0027) /* Deprecated in favor of scanning */
|
||||
#define SIOCSIWSCAN _SIOC(0x0028) /* Trigger scanning (list cells) */
|
||||
#define SIOCGIWSCAN _SIOC(0x0029) /* Get scanning results */
|
||||
#define SIOCSIWAP _SIOC(0x002e) /* Set access point MAC addresses */
|
||||
#define SIOCGIWAP _SIOC(0x002f) /* Get access point MAC addresses */
|
||||
#define SIOCGIWAPLIST _SIOC(0x0030) /* Deprecated in favor of scanning */
|
||||
#define SIOCSIWSCAN _SIOC(0x0031) /* Trigger scanning (list cells) */
|
||||
#define SIOCGIWSCAN _SIOC(0x0032) /* Get scanning results */
|
||||
|
||||
#define SIOCSIWESSID _SIOC(0x002a) /* Set ESSID (network name) */
|
||||
#define SIOCGIWESSID _SIOC(0x002b) /* Get ESSID */
|
||||
#define SIOCSIWNICKN _SIOC(0x002c) /* Set node name/nickname */
|
||||
#define SIOCGIWNICKN _SIOC(0x002d) /* Get node name/nickname */
|
||||
#define SIOCSIWESSID _SIOC(0x0033) /* Set ESSID (network name) */
|
||||
#define SIOCGIWESSID _SIOC(0x0034) /* Get ESSID */
|
||||
#define SIOCSIWNICKN _SIOC(0x0035) /* Set node name/nickname */
|
||||
#define SIOCGIWNICKN _SIOC(0x0036) /* Get node name/nickname */
|
||||
|
||||
#define SIOCSIWRATE _SIOC(0x002e) /* Set default bit rate (bps) */
|
||||
#define SIOCGIWRATE _SIOC(0x002f) /* Get default bit rate (bps) */
|
||||
#define SIOCSIWRTS _SIOC(0x0030) /* Set RTS/CTS threshold (bytes) */
|
||||
#define SIOCGIWRTS _SIOC(0x0031) /* Get RTS/CTS threshold (bytes) */
|
||||
#define SIOCSIWFRAG _SIOC(0x0032) /* Set fragmentation thr (bytes) */
|
||||
#define SIOCGIWFRAG _SIOC(0x0033) /* Get fragmentation thr (bytes) */
|
||||
#define SIOCSIWTXPOW _SIOC(0x0034) /* Set transmit power (dBm) */
|
||||
#define SIOCGIWTXPOW _SIOC(0x0035) /* Get transmit power (dBm) */
|
||||
#define SIOCSIWRETRY _SIOC(0x0036) /* Set retry limits and lifetime */
|
||||
#define SIOCGIWRETRY _SIOC(0x0037) /* Get retry limits and lifetime */
|
||||
#define SIOCSIWRATE _SIOC(0x0037) /* Set default bit rate (bps) */
|
||||
#define SIOCGIWRATE _SIOC(0x0038) /* Get default bit rate (bps) */
|
||||
#define SIOCSIWRTS _SIOC(0x0039) /* Set RTS/CTS threshold (bytes) */
|
||||
#define SIOCGIWRTS _SIOC(0x003a) /* Get RTS/CTS threshold (bytes) */
|
||||
#define SIOCSIWFRAG _SIOC(0x003b) /* Set fragmentation thr (bytes) */
|
||||
#define SIOCGIWFRAG _SIOC(0x003c) /* Get fragmentation thr (bytes) */
|
||||
#define SIOCSIWTXPOW _SIOC(0x003d) /* Set transmit power (dBm) */
|
||||
#define SIOCGIWTXPOW _SIOC(0x003e) /* Get transmit power (dBm) */
|
||||
#define SIOCSIWRETRY _SIOC(0x003f) /* Set retry limits and lifetime */
|
||||
#define SIOCGIWRETRY _SIOC(0x0040) /* Get retry limits and lifetime */
|
||||
|
||||
#define SIOCSIWPOWER _SIOC(0x0038) /* Set Power Management settings */
|
||||
#define SIOCGIWPOWER _SIOC(0x0039) /* Get Power Management settings */
|
||||
#define SIOCSIWPOWER _SIOC(0x0041) /* Set Power Management settings */
|
||||
#define SIOCGIWPOWER _SIOC(0x0042) /* Get Power Management settings */
|
||||
|
||||
#define SIOCSIWGENIE _SIOC(0x003a) /* Set generic IE */
|
||||
#define SIOCGIWGENIE _SIOC(0x003b) /* Get generic IE */
|
||||
#define SIOCSIWGENIE _SIOC(0x0043) /* Set generic IE */
|
||||
#define SIOCGIWGENIE _SIOC(0x0044) /* Get generic IE */
|
||||
|
||||
#define SIOCSIWMLME _SIOC(0x003c) /* Request MLME operation */
|
||||
#define SIOCSIWMLME _SIOC(0x0045) /* Request MLME operation */
|
||||
|
||||
#define SIOCSIWAUTH _SIOC(0x003d) /* Set authentication mode params */
|
||||
#define SIOCGIWAUTH _SIOC(0x003e) /* Get authentication mode params */
|
||||
#define SIOCSIWAUTH _SIOC(0x0046) /* Set authentication mode params */
|
||||
#define SIOCGIWAUTH _SIOC(0x0047) /* Get authentication mode params */
|
||||
|
||||
#define SIOCSIWENCODEEXT _SIOC(0x003f) /* Set encoding token & mode */
|
||||
#define SIOCGIWENCODEEXT _SIOC(0x0040) /* Get encoding token & mode */
|
||||
#define SIOCSIWENCODEEXT _SIOC(0x0048) /* Set encoding token & mode */
|
||||
#define SIOCGIWENCODEEXT _SIOC(0x0049) /* Get encoding token & mode */
|
||||
|
||||
#define SIOCSIWPMKSA _SIOC(0x0041) /* PMKSA cache operation */
|
||||
#define SIOCSIWPMKSA _SIOC(0x004a) /* PMKSA cache operation */
|
||||
|
||||
/* MDIO/MCD *****************************************************************/
|
||||
|
||||
#define SIOCMIINOTIFY _SIOC(0x0042) /* Receive notificaion via signal on
|
||||
#define SIOCMIINOTIFY _SIOC(0x004b) /* Receive notificaion via signal on
|
||||
* PHY state change */
|
||||
#define SIOCGMIIPHY _SIOC(0x0043) /* Get address of MII PHY in use */
|
||||
#define SIOCGMIIREG _SIOC(0x0044) /* Get a MII register via MDIO */
|
||||
#define SIOCSMIIREG _SIOC(0x0045) /* Set a MII register via MDIO */
|
||||
#define SIOCGMIIPHY _SIOC(0x004c) /* Get address of MII PHY in use */
|
||||
#define SIOCGMIIREG _SIOC(0x004d) /* Get a MII register via MDIO */
|
||||
#define SIOCSMIIREG _SIOC(0x004e) /* Set a MII register via MDIO */
|
||||
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
|
|
|
@ -184,11 +184,13 @@ endmenu # Data link support
|
|||
source "net/socket/Kconfig"
|
||||
source "net/netdev/Kconfig"
|
||||
|
||||
#source "net/ipv4/Kconfig"
|
||||
# source "net/ipv4/Kconfig"
|
||||
# Currently cannot select both IPv4 and IPv6
|
||||
|
||||
config NET_IPv4
|
||||
bool
|
||||
default y
|
||||
default y if !NET_IPv6
|
||||
default n if NET_IPv6
|
||||
|
||||
source "net/ipv6/Kconfig"
|
||||
source "net/pkt/Kconfig"
|
||||
|
|
|
@ -83,36 +83,53 @@
|
|||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ioctl_getipaddr
|
||||
* Name: ioctl_getipv4addr
|
||||
*
|
||||
* Description:
|
||||
* Copy IP addresses from device structure to user memory.
|
||||
*
|
||||
* Input Parameters:
|
||||
* outaddr - Pointer to the user-provided memory to receive the address.
|
||||
* Actual type may be either 'struct sockaddr' (IPv4 only) or type
|
||||
* 'struct sockaddr_storage' (both IPv4 and IPv6).
|
||||
* inaddr - The source IP adress in the device structure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void ioctl_getipaddr(FAR void *outaddr, FAR const net_ipaddr_t *inaddr)
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
static void ioctl_getipv4addr(FAR struct sockaddr *outaddr,
|
||||
FAR const net_ipaddr_t *inaddr)
|
||||
{
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
FAR struct sockaddr_in6 *dest = (FAR struct sockaddr_in6 *)outaddr;
|
||||
dest->sin_family = AF_INET6;
|
||||
dest->sin_port = 0;
|
||||
memcpy(dest->sin6_addr.in6_u.u6_addr8, inaddr, 16);
|
||||
#else
|
||||
FAR struct sockaddr_in *dest = (FAR struct sockaddr_in *)outaddr;
|
||||
dest->sin_family = AF_INET;
|
||||
dest->sin_port = 0;
|
||||
dest->sin_addr.s_addr = *inaddr;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ioctl_setipaddr
|
||||
* Name: ioctl_getipv6addr
|
||||
*
|
||||
* Description:
|
||||
* Copy IP addresses from device structure to user memory.
|
||||
*
|
||||
* Input Parameters:
|
||||
* outaddr - Pointer to the user-provided memory to receive the address.
|
||||
* inaddr - The source IP adress in the device structure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
static void ioctl_getipv6addr(FAR struct sockaddr_storage *outaddr,
|
||||
FAR const net_ipaddr_t *inaddr)
|
||||
{
|
||||
FAR struct sockaddr_in6 *dest = (FAR struct sockaddr_in6 *)outaddr;
|
||||
dest->sin_family = AF_INET6;
|
||||
dest->sin_port = 0;
|
||||
memcpy(dest->sin6_addr.in6_u.u6_addr8, inaddr, 16);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ioctl_setipv4addr
|
||||
*
|
||||
* Description:
|
||||
* Copy IP addresses from user memory into the device structure
|
||||
|
@ -120,21 +137,40 @@ static void ioctl_getipaddr(FAR void *outaddr, FAR const net_ipaddr_t *inaddr)
|
|||
* Input Parameters:
|
||||
* outaddr - Pointer to the source IP address in the device structure.
|
||||
* inaddr - Pointer to the user-provided memory to containing the new IP
|
||||
* address. Actual type may be either 'struct sockaddr' (IPv4 only) or
|
||||
* type 'struct sockaddr_storage' (both IPv4 and IPv6).
|
||||
* address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void ioctl_setipaddr(FAR net_ipaddr_t *outaddr, FAR const void *inaddr)
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
static void ioctl_setipv4addr(FAR net_ipaddr_t *outaddr,
|
||||
FAR const struct sockaddr *inaddr)
|
||||
{
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
FAR const struct sockaddr_in6 *src = (FAR const struct sockaddr_in6 *)inaddr;
|
||||
memcpy(outaddr, src->sin6_addr.in6_u.u6_addr8, 16);
|
||||
#else
|
||||
FAR const struct sockaddr_in *src = (FAR const struct sockaddr_in *)inaddr;
|
||||
*outaddr = src->sin_addr.s_addr;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ioctl_setipv6addr
|
||||
*
|
||||
* Description:
|
||||
* Copy IP addresses from user memory into the device structure
|
||||
*
|
||||
* Input Parameters:
|
||||
* outaddr - Pointer to the source IP address in the device structure.
|
||||
* inaddr - Pointer to the user-provided memory to containing the new IP
|
||||
* address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
static void ioctl_setipv6addr(FAR net_ipaddr_t *outaddr,
|
||||
FAR const struct sockaddr_storage *inaddr)
|
||||
{
|
||||
FAR const struct sockaddr_in6 *src = (FAR const struct sockaddr_in6 *)inaddr;
|
||||
memcpy(outaddr, src->sin6_addr.in6_u.u6_addr8, 16);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ioctl_ifup / ioctl_ifdown
|
||||
|
@ -246,75 +282,198 @@ static int netdev_ifrioctl(FAR struct socket *psock, int cmd,
|
|||
|
||||
switch (cmd)
|
||||
{
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
case SIOCGIFADDR: /* Get IP address */
|
||||
{
|
||||
dev = netdev_ifrdev(req);
|
||||
if (dev)
|
||||
{
|
||||
ioctl_getipaddr(&req->ifr_addr, &dev->d_ipaddr);
|
||||
ioctl_getipv4addr(&req->ifr_addr, &dev->d_ipaddr);
|
||||
ret = OK;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
case SIOCSIFADDR: /* Set IP address */
|
||||
{
|
||||
dev = netdev_ifrdev(req);
|
||||
if (dev)
|
||||
{
|
||||
ioctl_ifdown(dev);
|
||||
ioctl_setipaddr(&dev->d_ipaddr, &req->ifr_addr);
|
||||
ioctl_setipv4addr(&dev->d_ipaddr, &req->ifr_addr);
|
||||
ioctl_ifup(dev);
|
||||
ret = OK;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
case SIOCGIFDSTADDR: /* Get P-to-P address */
|
||||
{
|
||||
dev = netdev_ifrdev(req);
|
||||
if (dev)
|
||||
{
|
||||
ioctl_getipaddr(&req->ifr_dstaddr, &dev->d_draddr);
|
||||
ioctl_getipv4addr(&req->ifr_dstaddr, &dev->d_draddr);
|
||||
ret = OK;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
case SIOCSIFDSTADDR: /* Set P-to-P address */
|
||||
{
|
||||
dev = netdev_ifrdev(req);
|
||||
if (dev)
|
||||
{
|
||||
ioctl_setipaddr(&dev->d_draddr, &req->ifr_dstaddr);
|
||||
ioctl_setipv4addr(&dev->d_draddr, &req->ifr_dstaddr);
|
||||
ret = OK;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
case SIOCGIFBRDADDR: /* Get broadcast IP address */
|
||||
case SIOCSIFBRDADDR: /* Set broadcast IP address */
|
||||
{
|
||||
ret = -ENOSYS;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
case SIOCGIFNETMASK: /* Get network mask */
|
||||
{
|
||||
dev = netdev_ifrdev(req);
|
||||
if (dev)
|
||||
{
|
||||
ioctl_getipaddr(&req->ifr_addr, &dev->d_netmask);
|
||||
ioctl_getipv4addr(&req->ifr_addr, &dev->d_netmask);
|
||||
ret = OK;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
case SIOCSIFNETMASK: /* Set network mask */
|
||||
{
|
||||
dev = netdev_ifrdev(req);
|
||||
if (dev)
|
||||
{
|
||||
ioctl_setipaddr(&dev->d_netmask, &req->ifr_addr);
|
||||
ioctl_setipv4addr(&dev->d_netmask, &req->ifr_addr);
|
||||
ret = OK;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
case SIOCGIFMTU: /* Get MTU size */
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
case SIOCGLIFADDR: /* Get IP address */
|
||||
{
|
||||
dev = netdev_ifrdev(req);
|
||||
if (dev)
|
||||
{
|
||||
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
||||
|
||||
ioctl_getipv6addr(&lreq->lifr_addr, &dev->d_ipaddr);
|
||||
ret = OK;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
case SIOCSLIFADDR: /* Set IP address */
|
||||
{
|
||||
dev = netdev_ifrdev(req);
|
||||
if (dev)
|
||||
{
|
||||
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
||||
|
||||
ioctl_ifdown(dev);
|
||||
ioctl_setipv6addr(&dev->d_ipaddr, &lreq->lifr_addr);
|
||||
ioctl_ifup(dev);
|
||||
ret = OK;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
case SIOCGLIFDSTADDR: /* Get P-to-P address */
|
||||
{
|
||||
dev = netdev_ifrdev(req);
|
||||
if (dev)
|
||||
{
|
||||
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
||||
|
||||
ioctl_getipv6addr(&lreq->lifr_dstaddr, &dev->d_draddr);
|
||||
ret = OK;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
case SIOCSLIFDSTADDR: /* Set P-to-P address */
|
||||
{
|
||||
dev = netdev_ifrdev(req);
|
||||
if (dev)
|
||||
{
|
||||
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
||||
|
||||
ioctl_setipv6addr(&dev->d_draddr, &lreq->lifr_dstaddr);
|
||||
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
|
||||
case SIOCGIFNETMASK: /* Get network mask */
|
||||
{
|
||||
dev = netdev_ifrdev(req);
|
||||
if (dev)
|
||||
{
|
||||
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
||||
|
||||
ioctl_getipv6addr(&lreq->lifr_addr, &dev->d_netmask);
|
||||
ret = OK;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
case SIOCSLIFNETMASK: /* Set network mask */
|
||||
{
|
||||
dev = netdev_ifrdev(req);
|
||||
if (dev)
|
||||
{
|
||||
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
||||
ioctl_setipv6addr(&dev->d_netmask, &lreq->lifr_addr);
|
||||
ret = OK;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
case SIOCGLIFMTU: /* Get MTU size */
|
||||
case SIOCGIFMTU: /* Get MTU size */
|
||||
{
|
||||
dev = netdev_ifrdev(req);
|
||||
if (dev)
|
||||
|
@ -414,13 +573,6 @@ static int netdev_ifrioctl(FAR struct socket *psock, int cmd,
|
|||
}
|
||||
break;
|
||||
|
||||
case SIOCGIFBRDADDR: /* Get broadcast IP address */
|
||||
case SIOCSIFBRDADDR: /* Set broadcast IP address */
|
||||
{
|
||||
ret = -ENOSYS;
|
||||
}
|
||||
break;
|
||||
|
||||
#ifdef CONFIG_NET_ARPIOCTLS
|
||||
case SIOCSARP: /* Set a ARP mapping */
|
||||
case SIOCDARP: /* Delete an ARP mapping */
|
||||
|
|
Loading…
Reference in a new issue