net: Add SocketCAN support

This commit is contained in:
Peter van der Perk
2020-06-15 10:23:25 +02:00
committed by patacongo
parent a607e6257f
commit 55d9e5f7af
54 changed files with 5741 additions and 114 deletions
+8
View File
@@ -16,6 +16,14 @@ config NETDEV_PHY_IOCTL
---help---
Enable support for ioctl() commands to access PHY registers
config NETDEV_CAN_BITRATE_IOCTL
bool "Enable CAN bitrate ioctl()"
default n
select NETDEV_IOCTL
depends on NET_CAN
---help---
Enable support for ioctl() commands to change CAN bitrate
config NETDEV_WIRELESS_IOCTL
bool "Enable Wireless ioctl()"
default n
+48
View File
@@ -1088,6 +1088,54 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
}
}
break;
#endif
#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 */
{
struct net_driver_s *dev = netdev_findbyindex(req->ifr_ifindex);
if (dev != NULL)
{
strncpy(req->ifr_name, dev->d_ifname, IFNAMSIZ);
ret = OK;
}
else
{
ret = -ENODEV;
}
}
break;
case SIOCGIFINDEX: /* Index to name mapping */
{
struct net_driver_s *dev = netdev_findbyname(req->ifr_name);
if (dev != NULL)
{
req->ifr_ifindex = dev->d_ifindex;
ret = OK;
}
else
{
ret = -ENODEV;
}
}
break;
#endif
default:
+12
View File
@@ -37,6 +37,7 @@
#include <nuttx/net/netdev.h>
#include <nuttx/net/ethernet.h>
#include <nuttx/net/bluetooth.h>
#include <nuttx/net/can.h>
#include "utils/utils.h"
#include "igmp/igmp.h"
@@ -56,6 +57,7 @@
#define NETDEV_WLAN_FORMAT "wlan%d"
#define NETDEV_WPAN_FORMAT "wpan%d"
#define NETDEV_WWAN_FORMAT "wwan%d"
#define NETDEV_CAN_FORMAT "can%d"
#if defined(CONFIG_DRIVERS_IEEE80211) /* Usually also has CONFIG_NET_ETHERNET */
# define NETDEV_DEFAULT_FORMAT NETDEV_WLAN_FORMAT
@@ -67,6 +69,8 @@
# define NETDEV_DEFAULT_FORMAT NETDEV_SLIP_FORMAT
#elif defined(CONFIG_NET_TUN)
# define NETDEV_DEFAULT_FORMAT NETDEV_TUN_FORMAT
#elif defined(CONFIG_NET_CAN)
# define NETDEV_DEFAULT_FORMAT NETDEV_CAN_FORMAT
#else /* if defined(CONFIG_NET_LOOPBACK) */
# define NETDEV_DEFAULT_FORMAT NETDEV_LO_FORMAT
#endif
@@ -277,6 +281,14 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
break;
#endif
#ifdef CONFIG_NET_CAN
case NET_LL_CAN: /* CAN bus */
dev->d_llhdrlen = 0;
dev->d_pktsize = NET_CAN_PKTSIZE;
devfmt = NETDEV_CAN_FORMAT;
break;
#endif
#ifdef CONFIG_NET_BLUETOOTH
case NET_LL_BLUETOOTH: /* Bluetooth */
llhdrlen = BLUETOOTH_MAX_HDRLEN; /* Determined at runtime */