net: remove unmaintained 6LoCAN implementation
Remove the unmaintained, experimental 6LoCAN (IPv6 over CAN bus) implementation. Fixes: #42559 Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
parent
2331b76b9b
commit
e9c9caa80d
26 changed files with 3 additions and 2847 deletions
|
@ -16,4 +16,3 @@ zephyr_library_sources_ifdef(CONFIG_CAN_RCAR can_rcar.c)
|
||||||
|
|
||||||
zephyr_library_sources_ifdef(CONFIG_USERSPACE can_handlers.c)
|
zephyr_library_sources_ifdef(CONFIG_USERSPACE can_handlers.c)
|
||||||
zephyr_library_sources_ifdef(CONFIG_CAN_SHELL can_shell.c)
|
zephyr_library_sources_ifdef(CONFIG_CAN_SHELL can_shell.c)
|
||||||
zephyr_library_sources_ifdef(CONFIG_CAN_NET can_net.c)
|
|
||||||
|
|
|
@ -101,6 +101,5 @@ source "drivers/can/Kconfig.mcp2515"
|
||||||
source "drivers/can/Kconfig.mcan"
|
source "drivers/can/Kconfig.mcan"
|
||||||
source "drivers/can/Kconfig.rcar"
|
source "drivers/can/Kconfig.rcar"
|
||||||
source "drivers/can/Kconfig.loopback"
|
source "drivers/can/Kconfig.loopback"
|
||||||
source "drivers/can/Kconfig.net"
|
|
||||||
|
|
||||||
endif # CAN
|
endif # CAN
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
# Configuration options for IPv6 over CAN
|
|
||||||
|
|
||||||
# Copyright (c) 2019 Alexander Wachter
|
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
config CAN_NET
|
|
||||||
bool "6loCAN network interface [EXPERIMENTAL]"
|
|
||||||
select EXPERIMENTAL
|
|
||||||
help
|
|
||||||
Enable IPv6 Networking over can (6loCAN)
|
|
||||||
|
|
||||||
if CAN_NET
|
|
||||||
|
|
||||||
module = CAN_NET
|
|
||||||
module-dep = NET_LOG
|
|
||||||
module-str = Log level for Network CAN
|
|
||||||
module-help = Enables logging for CAN L2 networking
|
|
||||||
source "subsys/net/Kconfig.template.log_config.net"
|
|
||||||
|
|
||||||
config CAN_NET_NAME
|
|
||||||
string "Network device name"
|
|
||||||
default "NET_CAN"
|
|
||||||
help
|
|
||||||
Name of the network device driver for IPv6 over CAN.
|
|
||||||
|
|
||||||
config CAN_NET_INIT_PRIORITY
|
|
||||||
int "CAN NET driver init priority"
|
|
||||||
default 80
|
|
||||||
help
|
|
||||||
CAN NET device driver initialization priority.
|
|
||||||
Do not mess with it unless you know what you are doing.
|
|
||||||
Note that the priority needs to be lower than the net stack
|
|
||||||
so that it can start before the networking sub-system.
|
|
||||||
|
|
||||||
endif # CAN_NET
|
|
|
@ -1,407 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Alexander Wachter
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <net/can.h>
|
|
||||||
#include <net/net_pkt.h>
|
|
||||||
|
|
||||||
#include <logging/log.h>
|
|
||||||
LOG_MODULE_REGISTER(net_can, CONFIG_CAN_NET_LOG_LEVEL);
|
|
||||||
|
|
||||||
struct mcast_filter_mapping {
|
|
||||||
const struct in6_addr *addr;
|
|
||||||
int filter_id;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct net_can_context {
|
|
||||||
const struct device *can_dev;
|
|
||||||
struct net_if *iface;
|
|
||||||
int recv_filter_id;
|
|
||||||
struct mcast_filter_mapping mcast_mapping[NET_IF_MAX_IPV6_MADDR];
|
|
||||||
#ifdef CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR
|
|
||||||
int eth_bridge_filter_id;
|
|
||||||
int all_mcast_filter_id;
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct net_if_mcast_monitor mcast_monitor;
|
|
||||||
|
|
||||||
struct mcast_filter_mapping *can_get_mcast_filter(struct net_can_context *ctx,
|
|
||||||
const struct in6_addr *addr)
|
|
||||||
{
|
|
||||||
struct mcast_filter_mapping *map = ctx->mcast_mapping;
|
|
||||||
|
|
||||||
for (int i = 0; i < NET_IF_MAX_IPV6_MADDR; i++) {
|
|
||||||
if (map[i].addr == addr) {
|
|
||||||
return &map[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint8_t can_get_frame_datalength(struct zcan_frame *frame)
|
|
||||||
{
|
|
||||||
/* TODO: Needs update when CAN FD support is added */
|
|
||||||
return frame->dlc;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint16_t can_get_lladdr_src(struct zcan_frame *frame)
|
|
||||||
{
|
|
||||||
return (frame->id >> CAN_NET_IF_ADDR_SRC_POS) &
|
|
||||||
CAN_NET_IF_ADDR_MASK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint16_t can_get_lladdr_dest(struct zcan_frame *frame)
|
|
||||||
{
|
|
||||||
uint16_t addr = (frame->id >> CAN_NET_IF_ADDR_DEST_POS) &
|
|
||||||
CAN_NET_IF_ADDR_MASK;
|
|
||||||
|
|
||||||
if (frame->id & CAN_NET_IF_ADDR_MCAST_MASK) {
|
|
||||||
addr |= CAN_NET_IF_IS_MCAST_BIT;
|
|
||||||
}
|
|
||||||
|
|
||||||
return addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void can_set_lladdr(struct net_pkt *pkt, struct zcan_frame *frame)
|
|
||||||
{
|
|
||||||
struct net_buf *buf = pkt->buffer;
|
|
||||||
|
|
||||||
/* Put the destination at the beginning of the pkt.
|
|
||||||
* The net_canbus_lladdr has a size if 14 bits. To convert it to
|
|
||||||
* network byte order, we treat it as 16 bits here.
|
|
||||||
*/
|
|
||||||
net_pkt_lladdr_dst(pkt)->addr = buf->data;
|
|
||||||
net_pkt_lladdr_dst(pkt)->len = sizeof(struct net_canbus_lladdr);
|
|
||||||
net_pkt_lladdr_dst(pkt)->type = NET_LINK_CANBUS;
|
|
||||||
net_buf_add_be16(buf, can_get_lladdr_dest(frame));
|
|
||||||
net_buf_pull(buf, sizeof(uint16_t));
|
|
||||||
|
|
||||||
/* Do the same as above for the source address */
|
|
||||||
net_pkt_lladdr_src(pkt)->addr = buf->data;
|
|
||||||
net_pkt_lladdr_src(pkt)->len = sizeof(struct net_canbus_lladdr);
|
|
||||||
net_pkt_lladdr_src(pkt)->type = NET_LINK_CANBUS;
|
|
||||||
net_buf_add_be16(buf, can_get_lladdr_src(frame));
|
|
||||||
net_buf_pull(buf, sizeof(uint16_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
static int net_can_send(const struct device *dev,
|
|
||||||
const struct zcan_frame *frame,
|
|
||||||
can_tx_callback_t cb, void *cb_arg, k_timeout_t timeout)
|
|
||||||
{
|
|
||||||
struct net_can_context *ctx = dev->data;
|
|
||||||
|
|
||||||
NET_ASSERT(frame->id_type == CAN_EXTENDED_IDENTIFIER);
|
|
||||||
return can_send(ctx->can_dev, frame, timeout, cb, cb_arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void net_can_recv(struct zcan_frame *frame, void *arg)
|
|
||||||
{
|
|
||||||
struct net_can_context *ctx = (struct net_can_context *)arg;
|
|
||||||
size_t pkt_size = 2 * sizeof(struct net_canbus_lladdr) +
|
|
||||||
can_get_frame_datalength(frame);
|
|
||||||
struct net_pkt *pkt;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
NET_DBG("Frame with ID 0x%x received", frame->id);
|
|
||||||
pkt = net_pkt_rx_alloc_with_buffer(ctx->iface, pkt_size, AF_UNSPEC, 0,
|
|
||||||
K_NO_WAIT);
|
|
||||||
if (!pkt) {
|
|
||||||
LOG_ERR("Failed to obtain net_pkt with size of %d", pkt_size);
|
|
||||||
goto drop;
|
|
||||||
}
|
|
||||||
|
|
||||||
pkt->canbus_rx_ctx = NULL;
|
|
||||||
|
|
||||||
can_set_lladdr(pkt, frame);
|
|
||||||
net_pkt_cursor_init(pkt);
|
|
||||||
ret = net_pkt_write(pkt, frame->data, can_get_frame_datalength(frame));
|
|
||||||
if (ret) {
|
|
||||||
LOG_ERR("Failed to append frame data to net_pkt");
|
|
||||||
goto drop;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = net_recv_data(ctx->iface, pkt);
|
|
||||||
if (ret < 0) {
|
|
||||||
LOG_ERR("Packet dropped by NET stack");
|
|
||||||
goto drop;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
drop:
|
|
||||||
NET_INFO("pkt dropped");
|
|
||||||
|
|
||||||
if (pkt) {
|
|
||||||
net_pkt_unref(pkt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int add_mcast_filter(struct net_can_context *ctx,
|
|
||||||
const struct in6_addr *addr)
|
|
||||||
{
|
|
||||||
static struct zcan_filter filter = {
|
|
||||||
.id_type = CAN_EXTENDED_IDENTIFIER,
|
|
||||||
.rtr = CAN_DATAFRAME,
|
|
||||||
.rtr_mask = 1,
|
|
||||||
.id_mask = CAN_NET_IF_ADDR_MCAST_MASK |
|
|
||||||
CAN_NET_IF_ADDR_DEST_MASK
|
|
||||||
};
|
|
||||||
const uint16_t group =
|
|
||||||
sys_be16_to_cpu(UNALIGNED_GET((&addr->s6_addr16[7])));
|
|
||||||
int filter_id;
|
|
||||||
|
|
||||||
filter.id = CAN_NET_IF_ADDR_MCAST_MASK |
|
|
||||||
((group & CAN_NET_IF_ADDR_MASK) <<
|
|
||||||
CAN_NET_IF_ADDR_DEST_POS);
|
|
||||||
|
|
||||||
filter_id = can_add_rx_filter(ctx->can_dev, net_can_recv,
|
|
||||||
ctx, &filter);
|
|
||||||
if (filter_id == CAN_NET_FILTER_NOT_SET) {
|
|
||||||
return CAN_NET_FILTER_NOT_SET;
|
|
||||||
}
|
|
||||||
|
|
||||||
NET_DBG("Added mcast filter. Group 0x%04x. Filter:%d",
|
|
||||||
group, filter_id);
|
|
||||||
|
|
||||||
return filter_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mcast_cb(struct net_if *iface, const struct net_addr *addr,
|
|
||||||
bool is_joined)
|
|
||||||
{
|
|
||||||
const struct device *dev = net_if_get_device(iface);
|
|
||||||
struct net_can_context *ctx = dev->data;
|
|
||||||
struct mcast_filter_mapping *filter_mapping;
|
|
||||||
int filter_id;
|
|
||||||
|
|
||||||
if (addr->family != AF_INET6) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_joined) {
|
|
||||||
filter_mapping = can_get_mcast_filter(ctx, NULL);
|
|
||||||
if (!filter_mapping) {
|
|
||||||
NET_ERR("Can't get a free filter_mapping");
|
|
||||||
}
|
|
||||||
|
|
||||||
filter_id = add_mcast_filter(ctx, &addr->in6_addr);
|
|
||||||
if (filter_id < 0) {
|
|
||||||
NET_ERR("Can't add mcast filter");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
filter_mapping->addr = &addr->in6_addr;
|
|
||||||
filter_mapping->filter_id = filter_id;
|
|
||||||
} else {
|
|
||||||
filter_mapping = can_get_mcast_filter(ctx, &addr->in6_addr);
|
|
||||||
if (!filter_mapping) {
|
|
||||||
NET_ERR("No filter mapping found");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
can_remove_rx_filter(ctx->can_dev, filter_mapping->filter_id);
|
|
||||||
filter_mapping->addr = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void net_can_iface_init(struct net_if *iface)
|
|
||||||
{
|
|
||||||
const struct device *dev = net_if_get_device(iface);
|
|
||||||
struct net_can_context *ctx = dev->data;
|
|
||||||
|
|
||||||
ctx->iface = iface;
|
|
||||||
|
|
||||||
NET_DBG("Init CAN network interface %p dev %p", iface, dev);
|
|
||||||
|
|
||||||
net_6locan_init(iface);
|
|
||||||
|
|
||||||
net_if_mcast_mon_register(&mcast_monitor, iface, mcast_cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int net_can_add_rx_filter(const struct device *dev, can_rx_callback_t cb,
|
|
||||||
void *cb_arg, const struct zcan_filter *filter)
|
|
||||||
{
|
|
||||||
struct net_can_context *ctx = dev->data;
|
|
||||||
|
|
||||||
return can_add_rx_filter(ctx->can_dev, cb, cb_arg, filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void net_can_remove_rx_filter(const struct device *dev, int filter_id)
|
|
||||||
{
|
|
||||||
struct net_can_context *ctx = dev->data;
|
|
||||||
|
|
||||||
if (filter_id >= 0) {
|
|
||||||
can_remove_rx_filter(ctx->can_dev, filter_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int can_add_unicast_filter(struct net_can_context *ctx)
|
|
||||||
{
|
|
||||||
struct zcan_filter filter = {
|
|
||||||
.id_type = CAN_EXTENDED_IDENTIFIER,
|
|
||||||
.rtr = CAN_DATAFRAME,
|
|
||||||
.rtr_mask = 1,
|
|
||||||
.id_mask = CAN_NET_IF_ADDR_DEST_MASK
|
|
||||||
};
|
|
||||||
const uint8_t *link_addr = net_if_get_link_addr(ctx->iface)->addr;
|
|
||||||
const uint16_t dest = sys_be16_to_cpu(UNALIGNED_GET((uint16_t *) link_addr));
|
|
||||||
int filter_id;
|
|
||||||
|
|
||||||
filter.id = (dest << CAN_NET_IF_ADDR_DEST_POS);
|
|
||||||
|
|
||||||
filter_id = can_add_rx_filter(ctx->can_dev, net_can_recv,
|
|
||||||
ctx, &filter);
|
|
||||||
if (filter_id == CAN_NET_FILTER_NOT_SET) {
|
|
||||||
NET_ERR("Can't add FF filter");
|
|
||||||
return CAN_NET_FILTER_NOT_SET;
|
|
||||||
}
|
|
||||||
|
|
||||||
NET_DBG("Added FF filter %d", filter_id);
|
|
||||||
|
|
||||||
return filter_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR
|
|
||||||
static inline int can_add_eth_bridge_filter(struct net_can_context *ctx)
|
|
||||||
{
|
|
||||||
const struct zcan_filter filter = {
|
|
||||||
.id_type = CAN_EXTENDED_IDENTIFIER,
|
|
||||||
.rtr = CAN_DATAFRAME,
|
|
||||||
.rtr_mask = 1,
|
|
||||||
.id_mask = CAN_NET_IF_ADDR_DEST_MASK,
|
|
||||||
.id = (NET_CAN_ETH_TRANSLATOR_ADDR <<
|
|
||||||
CAN_NET_IF_ADDR_DEST_POS)
|
|
||||||
};
|
|
||||||
|
|
||||||
int filter_id;
|
|
||||||
|
|
||||||
filter_id = can_add_rx_filter(ctx->can_dev, net_can_recv,
|
|
||||||
ctx, &filter);
|
|
||||||
if (filter_id == CAN_NET_FILTER_NOT_SET) {
|
|
||||||
NET_ERR("Can't add ETH bridge filter");
|
|
||||||
return CAN_NET_FILTER_NOT_SET;
|
|
||||||
}
|
|
||||||
|
|
||||||
NET_DBG("Added ETH bridge filter %d", filter_id);
|
|
||||||
|
|
||||||
return filter_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int can_add_all_mcast_filter(struct net_can_context *ctx)
|
|
||||||
{
|
|
||||||
const struct zcan_filter filter = {
|
|
||||||
.id_type = CAN_EXTENDED_IDENTIFIER,
|
|
||||||
.rtr = CAN_DATAFRAME,
|
|
||||||
.rtr_mask = 1,
|
|
||||||
.id_mask = CAN_NET_IF_ADDR_MCAST_MASK,
|
|
||||||
.id = CAN_NET_IF_ADDR_MCAST_MASK
|
|
||||||
};
|
|
||||||
|
|
||||||
int filter_id;
|
|
||||||
|
|
||||||
filter_id = can_add_rx_filter(ctx->can_dev, net_can_recv,
|
|
||||||
ctx, &filter);
|
|
||||||
if (filter_id == CAN_NET_FILTER_NOT_SET) {
|
|
||||||
NET_ERR("Can't add all mcast filter");
|
|
||||||
return CAN_NET_FILTER_NOT_SET;
|
|
||||||
}
|
|
||||||
|
|
||||||
NET_DBG("Added all mcast filter %d", filter_id);
|
|
||||||
|
|
||||||
return filter_id;
|
|
||||||
}
|
|
||||||
#endif /*CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR*/
|
|
||||||
|
|
||||||
static int can_enable(const struct device *dev, bool enable)
|
|
||||||
{
|
|
||||||
struct net_can_context *ctx = dev->data;
|
|
||||||
|
|
||||||
if (enable) {
|
|
||||||
if (ctx->recv_filter_id == CAN_NET_FILTER_NOT_SET) {
|
|
||||||
ctx->recv_filter_id = can_add_unicast_filter(ctx);
|
|
||||||
if (ctx->recv_filter_id < 0) {
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR
|
|
||||||
if (ctx->eth_bridge_filter_id == CAN_NET_FILTER_NOT_SET) {
|
|
||||||
ctx->eth_bridge_filter_id = can_add_eth_bridge_filter(ctx);
|
|
||||||
if (ctx->eth_bridge_filter_id < 0) {
|
|
||||||
can_remove_rx_filter(ctx->can_dev, ctx->recv_filter_id);
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ctx->all_mcast_filter_id == CAN_NET_FILTER_NOT_SET) {
|
|
||||||
ctx->all_mcast_filter_id = can_add_all_mcast_filter(ctx);
|
|
||||||
if (ctx->all_mcast_filter_id < 0) {
|
|
||||||
can_remove_rx_filter(ctx->can_dev, ctx->recv_filter_id);
|
|
||||||
can_remove_rx_filter(ctx->can_dev, ctx->eth_bridge_filter_id);
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /*CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR*/
|
|
||||||
} else {
|
|
||||||
if (ctx->recv_filter_id != CAN_NET_FILTER_NOT_SET) {
|
|
||||||
can_remove_rx_filter(ctx->can_dev, ctx->recv_filter_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR
|
|
||||||
if (ctx->eth_bridge_filter_id != CAN_NET_FILTER_NOT_SET) {
|
|
||||||
can_remove_rx_filter(ctx->can_dev, ctx->eth_bridge_filter_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ctx->all_mcast_filter_id != CAN_NET_FILTER_NOT_SET) {
|
|
||||||
can_remove_rx_filter(ctx->can_dev, ctx->all_mcast_filter_id);
|
|
||||||
}
|
|
||||||
#endif /*CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR*/
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct net_can_api net_can_api_inst = {
|
|
||||||
.iface_api.init = net_can_iface_init,
|
|
||||||
|
|
||||||
.send = net_can_send,
|
|
||||||
.add_rx_filter = net_can_add_rx_filter,
|
|
||||||
.remove_rx_filter = net_can_remove_rx_filter,
|
|
||||||
.enable = can_enable,
|
|
||||||
};
|
|
||||||
|
|
||||||
static int net_can_init(const struct device *dev)
|
|
||||||
{
|
|
||||||
const struct device *can_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_canbus));
|
|
||||||
struct net_can_context *ctx = dev->data;
|
|
||||||
|
|
||||||
ctx->recv_filter_id = CAN_NET_FILTER_NOT_SET;
|
|
||||||
#ifdef CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR
|
|
||||||
ctx->eth_bridge_filter_id = CAN_NET_FILTER_NOT_SET;
|
|
||||||
ctx->all_mcast_filter_id = CAN_NET_FILTER_NOT_SET;
|
|
||||||
#endif /*CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR*/
|
|
||||||
|
|
||||||
if (!device_is_ready(can_dev)) {
|
|
||||||
NET_ERR("CAN device not ready");
|
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
|
|
||||||
NET_DBG("Init net CAN device %p (%s) for dev %p (%s)",
|
|
||||||
dev, dev->name, can_dev, can_dev->name);
|
|
||||||
|
|
||||||
ctx->can_dev = can_dev;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct net_can_context net_can_context_1;
|
|
||||||
|
|
||||||
NET_DEVICE_INIT(net_can_1, CONFIG_CAN_NET_NAME, net_can_init,
|
|
||||||
NULL, &net_can_context_1, NULL,
|
|
||||||
CONFIG_CAN_NET_INIT_PRIORITY,
|
|
||||||
&net_can_api_inst,
|
|
||||||
CANBUS_L2, NET_L2_GET_CTX_TYPE(CANBUS_L2), NET_CAN_MTU);
|
|
|
@ -93,35 +93,6 @@ static uint8_t dma_tx_buffer[ETH_TXBUFNB][ETH_TX_BUF_SIZE] __eth_stm32_buf;
|
||||||
static ETH_TxPacketConfig tx_config;
|
static ETH_TxPacketConfig tx_config;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR)
|
|
||||||
#include <net/can.h>
|
|
||||||
|
|
||||||
static void set_mac_to_translator_addr(uint8_t *mac_addr)
|
|
||||||
{
|
|
||||||
/* Set the last 14 bit to the translator link layer address to avoid
|
|
||||||
* address collissions with the 6LoCAN address range
|
|
||||||
*/
|
|
||||||
mac_addr[4] = (mac_addr[4] & 0xC0) | (NET_CAN_ETH_TRANSLATOR_ADDR >> 8);
|
|
||||||
mac_addr[5] = NET_CAN_ETH_TRANSLATOR_ADDR & 0xFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void enable_canbus_eth_translator_filter(ETH_HandleTypeDef *heth,
|
|
||||||
uint8_t *mac_addr)
|
|
||||||
{
|
|
||||||
heth->Instance->MACA1LR = (mac_addr[3] << 24U) | (mac_addr[2] << 16U) |
|
|
||||||
(mac_addr[1] << 8U) | mac_addr[0];
|
|
||||||
|
|
||||||
#if defined(CONFIG_SOC_SERIES_STM32H7X)
|
|
||||||
heth->Instance->MACA1HR = ETH_MACAHR_AE | ETH_MACAHR_MBC_HBITS15_8 |
|
|
||||||
ETH_MACAHR_MBC_HBITS7_0;
|
|
||||||
#else
|
|
||||||
/*enable filter 1 and ignore byte 5 and 6 for filtering*/
|
|
||||||
heth->Instance->MACA1HR = ETH_MACA1HR_AE | ETH_MACA1HR_MBC_HBits15_8 |
|
|
||||||
ETH_MACA1HR_MBC_HBits7_0;
|
|
||||||
#endif /* CONFIG_SOC_SERIES_STM32H7X */
|
|
||||||
}
|
|
||||||
#endif /*CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR*/
|
|
||||||
|
|
||||||
static HAL_StatusTypeDef read_eth_phy_register(ETH_HandleTypeDef *heth,
|
static HAL_StatusTypeDef read_eth_phy_register(ETH_HandleTypeDef *heth,
|
||||||
uint32_t PHYAddr,
|
uint32_t PHYAddr,
|
||||||
uint32_t PHYReg,
|
uint32_t PHYReg,
|
||||||
|
@ -839,10 +810,6 @@ static int eth_initialize(const struct device *dev)
|
||||||
#if defined(CONFIG_ETH_STM32_HAL_RANDOM_MAC)
|
#if defined(CONFIG_ETH_STM32_HAL_RANDOM_MAC)
|
||||||
generate_mac(dev_data->mac_addr);
|
generate_mac(dev_data->mac_addr);
|
||||||
#endif
|
#endif
|
||||||
#if defined(CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR)
|
|
||||||
set_mac_to_translator_addr(dev_data->mac_addr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
heth->Init.MACAddr = dev_data->mac_addr;
|
heth->Init.MACAddr = dev_data->mac_addr;
|
||||||
|
|
||||||
#if defined(CONFIG_SOC_SERIES_STM32H7X)
|
#if defined(CONFIG_SOC_SERIES_STM32H7X)
|
||||||
|
@ -927,10 +894,6 @@ static int eth_initialize(const struct device *dev)
|
||||||
|
|
||||||
disable_mcast_filter(heth);
|
disable_mcast_filter(heth);
|
||||||
|
|
||||||
#if defined(CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR)
|
|
||||||
enable_canbus_eth_translator_filter(heth, dev_data->mac_addr);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(CONFIG_SOC_SERIES_STM32H7X)
|
#if defined(CONFIG_SOC_SERIES_STM32H7X)
|
||||||
/* Adjust MDC clock range depending on HCLK frequency: */
|
/* Adjust MDC clock range depending on HCLK frequency: */
|
||||||
HAL_ETH_SetMDIOClockRange(heth);
|
HAL_ETH_SetMDIOClockRange(heth);
|
||||||
|
|
|
@ -1,244 +0,0 @@
|
||||||
/** @file
|
|
||||||
* @brief IPv6 Networking over CAN definitions.
|
|
||||||
*
|
|
||||||
* Definitions for IPv6 Networking over CAN support.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Alexander Wachter
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ZEPHYR_INCLUDE_NET_CAN_H_
|
|
||||||
#define ZEPHYR_INCLUDE_NET_CAN_H_
|
|
||||||
|
|
||||||
#include <zephyr/types.h>
|
|
||||||
#include <net/net_ip.h>
|
|
||||||
#include <net/net_if.h>
|
|
||||||
#include <drivers/can.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief IPv6 over CAN library
|
|
||||||
* @defgroup net_can Network Core Library
|
|
||||||
* @ingroup networking
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CAN L2 driver API. Used by 6loCAN.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Abbreviations
|
|
||||||
* BS Block Size
|
|
||||||
* CAN_DL CAN LL data size
|
|
||||||
* CF Consecutive Frame
|
|
||||||
* CTS Continue to send
|
|
||||||
* DLC Data length code
|
|
||||||
* FC Flow Control
|
|
||||||
* FF First Frame
|
|
||||||
* FS Flow Status
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @cond INTERNAL_HIDDEN */
|
|
||||||
|
|
||||||
#define NET_CAN_DL 8
|
|
||||||
#define NET_CAN_MTU 0x0FFF
|
|
||||||
|
|
||||||
/* 0x3DFF - bit 4 to 10 must not be zero. Also prevent stuffing bit*/
|
|
||||||
#define NET_CAN_MULTICAST_ADDR 0x3DFF
|
|
||||||
#define NET_CAN_DAD_ADDR 0x3DFE
|
|
||||||
#define NET_CAN_ETH_TRANSLATOR_ADDR 0x3DF0
|
|
||||||
#define NET_CAN_MAX_ADDR 0x3DEF
|
|
||||||
#define NET_CAN_MIN_ADDR 0x0100
|
|
||||||
|
|
||||||
#define CAN_NET_IF_ADDR_MASK 0x3FFF
|
|
||||||
#define CAN_NET_IF_ADDR_BYTE_LEN 2U
|
|
||||||
#define CAN_NET_IF_ADDR_DEST_POS 14U
|
|
||||||
#define CAN_NET_IF_ADDR_DEST_MASK (CAN_NET_IF_ADDR_MASK << CAN_NET_IF_ADDR_DEST_POS)
|
|
||||||
#define CAN_NET_IF_ADDR_SRC_POS 0U
|
|
||||||
#define CAN_NET_IF_ADDR_SRC_MASK (CAN_NET_IF_ADDR_MASK << CAN_NET_IF_ADDR_SRC_POS)
|
|
||||||
#define CAN_NET_IF_ADDR_MCAST_POS 28U
|
|
||||||
#define CAN_NET_IF_ADDR_MCAST_MASK (1UL << CAN_NET_IF_ADDR_MCAST_POS)
|
|
||||||
|
|
||||||
#define CAN_NET_IF_IS_MCAST_BIT (1U << 14)
|
|
||||||
|
|
||||||
#define CAN_NET_FILTER_NOT_SET -1
|
|
||||||
|
|
||||||
/** @endcond */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* +-----------+ +-----------+
|
|
||||||
* | | | |
|
|
||||||
* | IPv6 | | IPv6 |
|
|
||||||
* | 6LoCAN | | 6LoCAN |
|
|
||||||
* | | | |
|
|
||||||
* +----+-+----+ +----+-+----+
|
|
||||||
* | | | | +---+
|
|
||||||
* +----+ | | | | / \ +-+
|
|
||||||
* | | | | | | +--+ / \_/ \
|
|
||||||
* +++ +---+ +--+----+ +-------+ +--+----+ +--/ \_/ \
|
|
||||||
* | | \ / | \ / \ / | \ / / |
|
|
||||||
* | | X | X CAN X | X | Internet |
|
|
||||||
* | | / \ | / \ / \ | / \ \ /
|
|
||||||
* +++ +---+ +----+--+ +-------+ +----+--+ +--+ /
|
|
||||||
* | | +-------------------+
|
|
||||||
* +----+
|
|
||||||
*/
|
|
||||||
struct net_can_api {
|
|
||||||
/**
|
|
||||||
* The net_if_api must be placed in first position in this
|
|
||||||
* struct so that we are compatible with network interface API.
|
|
||||||
*/
|
|
||||||
struct net_if_api iface_api;
|
|
||||||
|
|
||||||
/** Send a single CAN frame */
|
|
||||||
int (*send)(const struct device *dev, const struct zcan_frame *frame,
|
|
||||||
can_tx_callback_t cb, void *cb_arg, k_timeout_t timeout);
|
|
||||||
/** Add a filter with its callback */
|
|
||||||
int (*add_rx_filter)(const struct device *dev, can_rx_callback_t cb,
|
|
||||||
void *cb_arg, const struct zcan_filter *filter);
|
|
||||||
/** Remove a filter */
|
|
||||||
void (*remove_rx_filter)(const struct device *dev, int filter_id);
|
|
||||||
/** Enable or disable the reception of frames for net CAN */
|
|
||||||
int (*enable)(const struct device *dev, bool enable);
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Make sure that the network interface API is properly setup inside
|
|
||||||
* net_can_api struct (it is the first one).
|
|
||||||
*/
|
|
||||||
BUILD_ASSERT(offsetof(struct net_can_api, iface_api) == 0);
|
|
||||||
|
|
||||||
/** @cond INTERNAL_HIDDEN */
|
|
||||||
|
|
||||||
#define CANBUS_L2_CTX_TYPE struct net_canbus_context *
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Context for canbus net device.
|
|
||||||
*/
|
|
||||||
struct canbus_net_ctx {
|
|
||||||
/** Filter ID for link layer duplicate address detection. */
|
|
||||||
int dad_filter_id;
|
|
||||||
/** Work item for responding to link layer DAD requests. */
|
|
||||||
struct k_work dad_work;
|
|
||||||
/** The interface associated with this device */
|
|
||||||
struct net_if *iface;
|
|
||||||
/** The link layer address chosen for this interface */
|
|
||||||
uint16_t ll_addr;
|
|
||||||
/** TX queue */
|
|
||||||
struct k_fifo tx_queue;
|
|
||||||
/** RX error queue */
|
|
||||||
struct k_fifo rx_err_queue;
|
|
||||||
/** Queue handler thread */
|
|
||||||
struct k_thread queue_handler;
|
|
||||||
/** Queue handler thread stack */
|
|
||||||
K_KERNEL_STACK_MEMBER(queue_stack, 512);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Canbus link layer addresses have a length of 14 bit for source and destination.
|
|
||||||
* Both together are 28 bit to fit a CAN extended identifier with 29 bit length.
|
|
||||||
*/
|
|
||||||
struct net_canbus_lladdr {
|
|
||||||
uint16_t addr : 14;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* STmin is split in two valid ranges:
|
|
||||||
* 0-127: 0ms-127ms
|
|
||||||
* 128-240: Reserved
|
|
||||||
* 241-249: 100us-900us (multiples of 100us)
|
|
||||||
* 250- : Reserved
|
|
||||||
*/
|
|
||||||
struct canbus_fc_opts {
|
|
||||||
/** Block size. Number of CF PDUs before next CF is sent */
|
|
||||||
uint8_t bs;
|
|
||||||
/**< Minimum separation time. Min time between frames */
|
|
||||||
uint8_t stmin;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Context for a transmission of messages that didn't fit in a single frame.
|
|
||||||
* These messages Start with a FF (First Frame) that is in case of unicast
|
|
||||||
* acknowledged by a FC (Frame Control). After that, one or more CF
|
|
||||||
* (Consecutive frames) carry the rest of the message.
|
|
||||||
*/
|
|
||||||
struct canbus_isotp_tx_ctx {
|
|
||||||
/** Pkt containing the data to transmit */
|
|
||||||
struct net_pkt *pkt;
|
|
||||||
/** Timeout for TX Timeout and separation time */
|
|
||||||
struct _timeout timeout;
|
|
||||||
/** Frame Control options received from FC frame */
|
|
||||||
struct canbus_fc_opts opts;
|
|
||||||
/** CAN destination address */
|
|
||||||
struct net_canbus_lladdr dest_addr;
|
|
||||||
/** Remaining data to transmit in bytes */
|
|
||||||
uint16_t rem_len;
|
|
||||||
/** Number of bytes in the tx queue */
|
|
||||||
int8_t tx_backlog;
|
|
||||||
/** State of the transmission */
|
|
||||||
uint8_t state;
|
|
||||||
/** Actual block number that is transmitted. Counts from BS to 0 */
|
|
||||||
uint8_t act_block_nr;
|
|
||||||
/** Number of WAIT frames received */
|
|
||||||
uint8_t wft;
|
|
||||||
/** Sequence number that is added to CF */
|
|
||||||
uint8_t sn : 4;
|
|
||||||
/** Transmission is multicast */
|
|
||||||
uint8_t is_mcast : 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Context for reception of messages that are not single frames.
|
|
||||||
* This is the counterpart of the canbus_isotp_tx_ctx.
|
|
||||||
*/
|
|
||||||
struct canbus_isotp_rx_ctx {
|
|
||||||
/** Pkt that is large enough to hold the entire message */
|
|
||||||
struct net_pkt *pkt;
|
|
||||||
/** Timeout for RX timeout*/
|
|
||||||
struct _timeout timeout;
|
|
||||||
/** Remaining data to receive. Goes from message length to zero */
|
|
||||||
uint16_t rem_len;
|
|
||||||
/** State of the reception */
|
|
||||||
uint8_t state;
|
|
||||||
/** Number of frames received in this block. Counts from BS to 0 */
|
|
||||||
uint8_t act_block_nr;
|
|
||||||
/** Number of WAIT frames transmitted */
|
|
||||||
uint8_t wft;
|
|
||||||
/** Expected sequence number in CF */
|
|
||||||
uint8_t sn : 4;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialization of the canbus L2.
|
|
||||||
*
|
|
||||||
* This function starts the TX workqueue and does some initialization.
|
|
||||||
*/
|
|
||||||
void net_6locan_init(struct net_if *iface);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ethernet frame input function for Ethernet to 6LoCAN translation
|
|
||||||
*
|
|
||||||
* This function checks the destination link layer address for addresses
|
|
||||||
* that has to be forwarded. Frames that need to be forwarded are forwarded here.
|
|
||||||
*/
|
|
||||||
enum net_verdict net_canbus_translate_eth_frame(struct net_if *iface,
|
|
||||||
struct net_pkt *pkt);
|
|
||||||
|
|
||||||
/** @endcond */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* ZEPHYR_INCLUDE_NET_CAN_H_ */
|
|
|
@ -1248,8 +1248,7 @@ static inline void net_ipv6_addr_create_iid(struct in6_addr *addr,
|
||||||
/* The generated IPv6 shall not toggle the
|
/* The generated IPv6 shall not toggle the
|
||||||
* Universal/Local bit. RFC 6282 ch 3.2.2
|
* Universal/Local bit. RFC 6282 ch 3.2.2
|
||||||
*/
|
*/
|
||||||
if (lladdr->type == NET_LINK_IEEE802154 ||
|
if (lladdr->type == NET_LINK_IEEE802154) {
|
||||||
lladdr->type == NET_LINK_CANBUS) {
|
|
||||||
UNALIGNED_PUT(0, &addr->s6_addr32[2]);
|
UNALIGNED_PUT(0, &addr->s6_addr32[2]);
|
||||||
addr->s6_addr[11] = 0xff;
|
addr->s6_addr[11] = 0xff;
|
||||||
addr->s6_addr[12] = 0xfe;
|
addr->s6_addr[12] = 0xfe;
|
||||||
|
|
|
@ -127,11 +127,6 @@ NET_L2_DECLARE_PUBLIC(OPENTHREAD_L2);
|
||||||
NET_L2_DECLARE_PUBLIC(CANBUS_RAW_L2);
|
NET_L2_DECLARE_PUBLIC(CANBUS_RAW_L2);
|
||||||
#endif /* CONFIG_NET_L2_CANBUS_RAW */
|
#endif /* CONFIG_NET_L2_CANBUS_RAW */
|
||||||
|
|
||||||
#ifdef CONFIG_NET_L2_CANBUS
|
|
||||||
#define CANBUS_L2 CANBUS
|
|
||||||
NET_L2_DECLARE_PUBLIC(CANBUS_L2);
|
|
||||||
#endif /* CONFIG_NET_L2_CANBUS */
|
|
||||||
|
|
||||||
#ifdef CONFIG_NET_L2_CUSTOM_IEEE802154
|
#ifdef CONFIG_NET_L2_CUSTOM_IEEE802154
|
||||||
#ifndef CUSTOM_IEEE802154_L2
|
#ifndef CUSTOM_IEEE802154_L2
|
||||||
#define CUSTOM_IEEE802154_L2 CUSTOM_IEEE802154
|
#define CUSTOM_IEEE802154_L2 CUSTOM_IEEE802154
|
||||||
|
|
|
@ -57,8 +57,6 @@ enum net_link_type {
|
||||||
NET_LINK_DUMMY,
|
NET_LINK_DUMMY,
|
||||||
/** CANBUS link address. */
|
/** CANBUS link address. */
|
||||||
NET_LINK_CANBUS_RAW,
|
NET_LINK_CANBUS_RAW,
|
||||||
/** 6loCAN link address. */
|
|
||||||
NET_LINK_CANBUS,
|
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,9 +41,6 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct net_context;
|
struct net_context;
|
||||||
struct canbus_net_isotp_tx_ctx;
|
|
||||||
struct canbus_net_isotp_rx_ctx;
|
|
||||||
|
|
||||||
|
|
||||||
/* buffer cursor used in net_pkt */
|
/* buffer cursor used in net_pkt */
|
||||||
struct net_pkt_cursor {
|
struct net_pkt_cursor {
|
||||||
|
@ -261,12 +258,6 @@ struct net_pkt {
|
||||||
uint32_t ieee802154_ack_fc; /* Frame counter set in the ACK */
|
uint32_t ieee802154_ack_fc; /* Frame counter set in the ACK */
|
||||||
uint8_t ieee802154_ack_keyid; /* Key index set in the ACK */
|
uint8_t ieee802154_ack_keyid; /* Key index set in the ACK */
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
#if defined(CONFIG_NET_L2_CANBUS)
|
|
||||||
union {
|
|
||||||
struct canbus_isotp_tx_ctx *canbus_tx_ctx;
|
|
||||||
struct canbus_isotp_rx_ctx *canbus_rx_ctx;
|
|
||||||
};
|
|
||||||
#endif
|
#endif
|
||||||
/* @endcond */
|
/* @endcond */
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
CONFIG_CAN=y
|
|
||||||
CONFIG_CAN_NET=y
|
|
||||||
CONFIG_CAN_MAX_FILTER=8
|
|
||||||
CONFIG_NET_L2_CANBUS=y
|
|
||||||
CONFIG_NET_L2_CANBUS_BS=8
|
|
||||||
CONFIG_NET_L2_CANBUS_STMIN=0
|
|
||||||
CONFIG_NET_IPV4=n
|
|
||||||
CONFIG_NET_IPV6=y
|
|
||||||
CONFIG_NET_CONFIG_NEED_IPV6=y
|
|
||||||
CONFIG_NET_CONFIG_NEED_IPV4=n
|
|
||||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR=""
|
|
||||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR=""
|
|
|
@ -11,9 +11,6 @@ tests:
|
||||||
sample.net.sockets.echo_client:
|
sample.net.sockets.echo_client:
|
||||||
platform_allow: qemu_x86 frdm_k64f sam_e70_xplained
|
platform_allow: qemu_x86 frdm_k64f sam_e70_xplained
|
||||||
qemu_cortex_m3 frdm_kw41z
|
qemu_cortex_m3 frdm_kw41z
|
||||||
sample.net.sockets.echo_client.6locan:
|
|
||||||
extra_args: OVERLAY_CONFIG="overlay-6locan.conf"
|
|
||||||
platform_allow: nucleo_f746zg
|
|
||||||
sample.net.sockets.echo_client.802154:
|
sample.net.sockets.echo_client.802154:
|
||||||
extra_args: OVERLAY_CONFIG="overlay-qemu_802154.conf"
|
extra_args: OVERLAY_CONFIG="overlay-qemu_802154.conf"
|
||||||
platform_allow: qemu_x86
|
platform_allow: qemu_x86
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
CONFIG_CAN=y
|
|
||||||
CONFIG_CAN_NET=y
|
|
||||||
CONFIG_CAN_MAX_FILTER=8
|
|
||||||
CONFIG_NET_L2_CANBUS=y
|
|
||||||
CONFIG_NET_L2_CANBUS_BS=8
|
|
||||||
CONFIG_NET_L2_CANBUS_STMIN=0
|
|
||||||
CONFIG_NET_IPV4=n
|
|
||||||
CONFIG_NET_IPV6=y
|
|
||||||
CONFIG_NET_CONFIG_NEED_IPV6=y
|
|
||||||
CONFIG_NET_CONFIG_NEED_IPV4=n
|
|
||||||
CONFIG_NET_CONFIG_MY_IPV4_ADDR=""
|
|
||||||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR=""
|
|
|
@ -11,9 +11,6 @@ tests:
|
||||||
sample.net.sockets.echo_server:
|
sample.net.sockets.echo_server:
|
||||||
platform_allow: qemu_x86 sam_e70_xplained frdm_k64f
|
platform_allow: qemu_x86 sam_e70_xplained frdm_k64f
|
||||||
qemu_cortex_m3 frdm_kw41z
|
qemu_cortex_m3 frdm_kw41z
|
||||||
sample.net.sockets.echo_server.6locan:
|
|
||||||
extra_args: OVERLAY_CONFIG="overlay-6locan.conf"
|
|
||||||
platform_allow: nucleo_f746zg
|
|
||||||
sample.net.sockets.echo_server.802154:
|
sample.net.sockets.echo_server.802154:
|
||||||
extra_args: OVERLAY_CONFIG="overlay-qemu_802154.conf"
|
extra_args: OVERLAY_CONFIG="overlay-qemu_802154.conf"
|
||||||
platform_allow: qemu_x86
|
platform_allow: qemu_x86
|
||||||
|
|
|
@ -64,7 +64,6 @@ NET_BUF_VARIABLE_DATA_SIZE,n,experimental
|
||||||
NET_CONNECTION_MANAGER,n,experimental
|
NET_CONNECTION_MANAGER,n,experimental
|
||||||
NET_GPTP,n,experimental
|
NET_GPTP,n,experimental
|
||||||
NET_IPV4_AUTO,n,experimental
|
NET_IPV4_AUTO,n,experimental
|
||||||
NET_L2_CANBUS,n,experimental
|
|
||||||
NET_L2_IEEE802154_SECURITY,n,experimental
|
NET_L2_IEEE802154_SECURITY,n,experimental
|
||||||
NET_L2_PPP,n,experimental
|
NET_L2_PPP,n,experimental
|
||||||
NET_L2_PTP,n,experimental
|
NET_L2_PTP,n,experimental
|
||||||
|
|
Can't render this file because it has a wrong number of fields in line 42.
|
|
@ -737,10 +737,6 @@ config NET_DEFAULT_IF_DUMMY
|
||||||
bool "Dummy testing interface"
|
bool "Dummy testing interface"
|
||||||
depends on NET_L2_DUMMY
|
depends on NET_L2_DUMMY
|
||||||
|
|
||||||
config NET_DEFAULT_IF_CANBUS
|
|
||||||
bool "6LoCAN (IPv6 over CAN) interface"
|
|
||||||
depends on NET_L2_CANBUS
|
|
||||||
|
|
||||||
config NET_DEFAULT_IF_CANBUS_RAW
|
config NET_DEFAULT_IF_CANBUS_RAW
|
||||||
bool "Socket CAN interface"
|
bool "Socket CAN interface"
|
||||||
depends on NET_L2_CANBUS_RAW
|
depends on NET_L2_CANBUS_RAW
|
||||||
|
|
|
@ -578,9 +578,6 @@ struct net_if *net_if_get_default(void)
|
||||||
#if defined(CONFIG_NET_DEFAULT_IF_CANBUS_RAW)
|
#if defined(CONFIG_NET_DEFAULT_IF_CANBUS_RAW)
|
||||||
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(CANBUS_RAW));
|
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(CANBUS_RAW));
|
||||||
#endif
|
#endif
|
||||||
#if defined(CONFIG_NET_DEFAULT_IF_CANBUS)
|
|
||||||
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(CANBUS));
|
|
||||||
#endif
|
|
||||||
#if defined(CONFIG_NET_DEFAULT_IF_PPP)
|
#if defined(CONFIG_NET_DEFAULT_IF_PPP)
|
||||||
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(PPP));
|
iface = net_if_get_first_by_type(&NET_L2_GET_NAME(PPP));
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -220,16 +220,6 @@ static const char *iface2str(struct net_if *iface, const char **extra)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_NET_L2_CANBUS
|
|
||||||
if (net_if_l2(iface) == &NET_L2_GET_NAME(CANBUS)) {
|
|
||||||
if (extra) {
|
|
||||||
*extra = "======";
|
|
||||||
}
|
|
||||||
|
|
||||||
return "CANBUS";
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_NET_L2_CANBUS_RAW
|
#ifdef CONFIG_NET_L2_CANBUS_RAW
|
||||||
if (net_if_l2(iface) == &NET_L2_GET_NAME(CANBUS_RAW)) {
|
if (net_if_l2(iface) == &NET_L2_GET_NAME(CANBUS_RAW)) {
|
||||||
if (extra) {
|
if (extra) {
|
||||||
|
@ -1446,11 +1436,6 @@ static void conn_handler_cb(struct net_conn *conn, void *user_data)
|
||||||
&net_sin(&conn->remote_addr)->sin_addr),
|
&net_sin(&conn->remote_addr)->sin_addr),
|
||||||
ntohs(net_sin(&conn->remote_addr)->sin_port));
|
ntohs(net_sin(&conn->remote_addr)->sin_port));
|
||||||
} else
|
} else
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_NET_L2_CANBUS
|
|
||||||
if (conn->local_addr.sa_family == AF_CAN) {
|
|
||||||
snprintk(addr_local, sizeof(addr_local), "-");
|
|
||||||
} else
|
|
||||||
#endif
|
#endif
|
||||||
if (conn->local_addr.sa_family == AF_UNSPEC) {
|
if (conn->local_addr.sa_family == AF_UNSPEC) {
|
||||||
snprintk(addr_local, sizeof(addr_local), "AF_UNSPEC");
|
snprintk(addr_local, sizeof(addr_local), "AF_UNSPEC");
|
||||||
|
|
|
@ -287,9 +287,7 @@ end:
|
||||||
((IS_ENABLED(CONFIG_NET_L2_BT) && \
|
((IS_ENABLED(CONFIG_NET_L2_BT) && \
|
||||||
net_pkt_lladdr_dst(pkt)->type == NET_LINK_BLUETOOTH) || \
|
net_pkt_lladdr_dst(pkt)->type == NET_LINK_BLUETOOTH) || \
|
||||||
(IS_ENABLED(CONFIG_NET_L2_IEEE802154) && \
|
(IS_ENABLED(CONFIG_NET_L2_IEEE802154) && \
|
||||||
net_pkt_lladdr_dst(pkt)->type == NET_LINK_IEEE802154) || \
|
net_pkt_lladdr_dst(pkt)->type == NET_LINK_IEEE802154)))
|
||||||
(IS_ENABLED(CONFIG_NET_L2_CANBUS) && \
|
|
||||||
net_pkt_lladdr_dst(pkt)->type == NET_LINK_CANBUS)))
|
|
||||||
|
|
||||||
static void tcp_send(struct net_pkt *pkt)
|
static void tcp_send(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,6 +32,6 @@ if(CONFIG_NET_L2_WIFI_MGMT OR CONFIG_NET_L2_WIFI_SHELL)
|
||||||
add_subdirectory(wifi)
|
add_subdirectory(wifi)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CONFIG_NET_L2_CANBUS OR CONFIG_NET_L2_CANBUS_RAW)
|
if(CONFIG_NET_L2_CANBUS_RAW)
|
||||||
add_subdirectory(canbus)
|
add_subdirectory(canbus)
|
||||||
endif()
|
endif()
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -7,4 +7,3 @@ zephyr_library_compile_definitions_ifdef(
|
||||||
)
|
)
|
||||||
|
|
||||||
zephyr_library_sources_ifdef(CONFIG_NET_L2_CANBUS_RAW canbus_raw.c)
|
zephyr_library_sources_ifdef(CONFIG_NET_L2_CANBUS_RAW canbus_raw.c)
|
||||||
zephyr_library_sources_ifdef(CONFIG_NET_L2_CANBUS 6locan.c)
|
|
||||||
|
|
|
@ -1,76 +1,6 @@
|
||||||
# Copyright (c) 2019 Alexander Wachter
|
# Copyright (c) 2019 Alexander Wachter
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
config NET_L2_CANBUS
|
|
||||||
bool "CANBUS L2 layer [EXPERIMENTAL]"
|
|
||||||
depends on CAN_NET
|
|
||||||
select NET_6LO
|
|
||||||
select EXPERIMENTAL
|
|
||||||
help
|
|
||||||
Add a CANBUS L2 layer driver. This is the layer for IPv6 over CAN
|
|
||||||
(6loCAN). It uses IPHC to compress the IP header and ISO-TP for
|
|
||||||
flow control and reassembling.
|
|
||||||
|
|
||||||
if NET_L2_CANBUS
|
|
||||||
|
|
||||||
config NET_L2_CANBUS_USE_FIXED_ADDR
|
|
||||||
bool "Use fixed L2 address"
|
|
||||||
help
|
|
||||||
Use a fixed L2 address for 6LoCAN instead of a random chosen one.
|
|
||||||
|
|
||||||
config NET_L2_CANBUS_FIXED_ADDR
|
|
||||||
hex "L2 address"
|
|
||||||
depends on NET_L2_CANBUS_USE_FIXED_ADDR
|
|
||||||
range 0x00FF 0x3DEF
|
|
||||||
|
|
||||||
config NET_L2_CANBUS_DAD_RETRIES
|
|
||||||
int "Number of DAD retries"
|
|
||||||
default 5
|
|
||||||
help
|
|
||||||
Number of retries for Duplicate Address Detection.
|
|
||||||
Greater than one only makes sense for random link layer addresses.
|
|
||||||
|
|
||||||
config NET_L2_CANBUS_STMIN
|
|
||||||
int "STmin"
|
|
||||||
default 0
|
|
||||||
range 0 127
|
|
||||||
help
|
|
||||||
Minimal separation time between frames in ms.
|
|
||||||
The timer starts when the frame is queued and the next frame is
|
|
||||||
transmitted after expiration.
|
|
||||||
STmin is chosen by the receiver and transmitted in the FC
|
|
||||||
(Flow Control) frame. See also: ISO 15765-2:2016
|
|
||||||
|
|
||||||
config NET_L2_CANBUS_BS
|
|
||||||
int "BS (Block Size)"
|
|
||||||
default 8
|
|
||||||
range 0 256
|
|
||||||
help
|
|
||||||
Number of CF (Contiguous Frame) PDUs before next FC (Flow Control)
|
|
||||||
frame is sent. Zero value means all frames are sent consecutive
|
|
||||||
without an additional FC frame.
|
|
||||||
A BS counter at the sender counts from one to BS. When BS is reached,
|
|
||||||
the sender waits for a FC frame again an BS is reset.
|
|
||||||
See also: ISO 15765-2:2016
|
|
||||||
|
|
||||||
config NET_L2_CANBUS_ETH_TRANSLATOR
|
|
||||||
bool "6LoCAN to Ethernet translator"
|
|
||||||
depends on NET_L2_ETHERNET
|
|
||||||
help
|
|
||||||
Enable a 6LoCAN Ethernet translator. With this translator it is
|
|
||||||
possible to connect a 6LoCAN network to a Ethernet network directly,
|
|
||||||
via a Switch or through a router. Messages that goes through the
|
|
||||||
translator have a special address and the MAC address is carried inline.
|
|
||||||
The packet is forwarded with uncompressed IPv6 header.
|
|
||||||
|
|
||||||
module = NET_L2_CANBUS
|
|
||||||
module-dep = NET_LOG
|
|
||||||
module-str = Log level for CANbus L2 layer
|
|
||||||
module-help = Enables CANbus L2 to output debug messages.
|
|
||||||
source "subsys/net/Kconfig.template.log_config.net"
|
|
||||||
|
|
||||||
endif # NET_L2_CANBUS
|
|
||||||
|
|
||||||
config NET_L2_CANBUS_RAW
|
config NET_L2_CANBUS_RAW
|
||||||
bool "CANBUS RAW l2 layer"
|
bool "CANBUS RAW l2 layer"
|
||||||
help
|
help
|
||||||
|
|
|
@ -1,98 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 Alexander Wachter
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef ZEPHYR_SUBSYS_NET_L2_CANBUS_INTERNAL_H_
|
|
||||||
#define ZEPHYR_SUBSYS_NET_L2_CANBUS_INTERNAL_H_
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef NET_CAN_USE_CAN_FD
|
|
||||||
#define NET_CAN_DL 64
|
|
||||||
#else
|
|
||||||
#define NET_CAN_DL 8
|
|
||||||
#endif/*NET_CAN_USE_CAN_FD*/
|
|
||||||
|
|
||||||
/* Protocol control information*/
|
|
||||||
#define NET_CAN_PCI_SF 0x00 /* Single frame*/
|
|
||||||
#define NET_CAN_PCI_FF 0x01 /* First frame */
|
|
||||||
#define NET_CAN_PCI_CF 0x02 /* Consecutive frame */
|
|
||||||
#define NET_CAN_PCI_FC 0x03 /* Flow control frame */
|
|
||||||
|
|
||||||
#define NET_CAN_PCI_TYPE_BYTE 0
|
|
||||||
#define NET_CAN_PCI_TYPE_POS 4
|
|
||||||
#define NET_CAN_PCI_TYPE_MASK 0xF0
|
|
||||||
#define NET_CAN_PCI_TYPE_SF (NET_CAN_PCI_SF << NET_CAN_PCI_TYPE_POS)
|
|
||||||
#define NET_CAN_PCI_TYPE_FF (NET_CAN_PCI_FF << NET_CAN_PCI_TYPE_POS)
|
|
||||||
#define NET_CAN_PCI_TYPE_CF (NET_CAN_PCI_CF << NET_CAN_PCI_TYPE_POS)
|
|
||||||
#define NET_CAN_PCI_TYPE_FC (NET_CAN_PCI_FC << NET_CAN_PCI_TYPE_POS)
|
|
||||||
|
|
||||||
#define NET_CAN_PCI_SF_DL_MASK 0x0F
|
|
||||||
|
|
||||||
#define NET_CAN_PCI_FF_DL_UPPER_BYTE 0
|
|
||||||
#define NET_CAN_PCI_FF_DL_UPPER_MASK 0x0F
|
|
||||||
#define NET_CAN_PCI_FF_DL_LOWER_BYTE 1
|
|
||||||
|
|
||||||
#define NET_CAN_PCI_FS_BYTE 0
|
|
||||||
#define NET_CAN_PCI_FS_MASK 0x0F
|
|
||||||
#define NET_CAN_PCI_BS_BYTE 1
|
|
||||||
#define NET_CAN_PCI_ST_MIN_BYTE 2
|
|
||||||
|
|
||||||
#define NET_CAN_PCI_FS_CTS 0x0
|
|
||||||
#define NET_CAN_PCI_FS_WAIT 0x1
|
|
||||||
#define NET_CAN_PCI_FS_OVFLW 0x2
|
|
||||||
|
|
||||||
#define NET_CAN_PCI_SN_MASK 0x0F
|
|
||||||
|
|
||||||
#define NET_CAN_FF_DL_MIN (NET_CAN_CAN_DL)
|
|
||||||
|
|
||||||
#define NET_CAN_WFT_FIRST 0xFF
|
|
||||||
|
|
||||||
#define NET_CAN_BS_TIME K_MSEC(1000)
|
|
||||||
#define NET_CAN_A_TIME K_MSEC(1000)
|
|
||||||
|
|
||||||
#define NET_CAN_FF_CF_TIME K_MSEC(1)
|
|
||||||
|
|
||||||
#define NET_CAN_STMIN_MAX 0xFA
|
|
||||||
#define NET_CAN_STMIN_MS_MAX 0x7F
|
|
||||||
#define NET_CAN_STMIN_US_BEGIN 0xF1
|
|
||||||
#define NET_CAN_STMIN_US_END 0xF9
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
enum net_can_isotp_tx_state {
|
|
||||||
NET_CAN_TX_STATE_UNUSED,
|
|
||||||
NET_CAN_TX_STATE_RESET,
|
|
||||||
NET_CAN_TX_STATE_WAIT_FC,
|
|
||||||
NET_CAN_TX_STATE_SEND_CF,
|
|
||||||
NET_CAN_TX_STATE_WAIT_ST,
|
|
||||||
NET_CAN_TX_STATE_WAIT_TX_BACKLOG,
|
|
||||||
NET_CAN_TX_STATE_FIN,
|
|
||||||
NET_CAN_TX_STATE_ERR
|
|
||||||
};
|
|
||||||
|
|
||||||
enum net_can_isotp_rx_state {
|
|
||||||
NET_CAN_RX_STATE_UNUSED,
|
|
||||||
NET_CAN_RX_STATE_RESET,
|
|
||||||
NET_CAN_RX_STATE_FF,
|
|
||||||
NET_CAN_RX_STATE_CF,
|
|
||||||
NET_CAN_RX_STATE_FIN,
|
|
||||||
NET_CAN_RX_STATE_TIMEOUT
|
|
||||||
};
|
|
||||||
|
|
||||||
struct canbus_l2_ctx {
|
|
||||||
struct canbus_isotp_tx_ctx tx_ctx[CONFIG_NET_PKT_TX_COUNT];
|
|
||||||
struct canbus_isotp_rx_ctx rx_ctx[CONFIG_NET_PKT_RX_COUNT];
|
|
||||||
struct k_mutex tx_ctx_mtx;
|
|
||||||
struct k_mutex rx_ctx_mtx;
|
|
||||||
struct k_sem tx_sem;
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* ZEPHYR_SUBSYS_NET_L2_CANBUS_INTERNAL_H_ */
|
|
|
@ -21,9 +21,6 @@ LOG_MODULE_REGISTER(net_ethernet, CONFIG_NET_L2_ETHERNET_LOG_LEVEL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <syscall_handler.h>
|
#include <syscall_handler.h>
|
||||||
#if defined(CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR)
|
|
||||||
#include <net/can.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "arp.h"
|
#include "arp.h"
|
||||||
#include "eth_stats.h"
|
#include "eth_stats.h"
|
||||||
|
@ -292,12 +289,6 @@ static enum net_verdict ethernet_recv(struct net_if *iface,
|
||||||
net_pkt_lladdr_dst(pkt));
|
net_pkt_lladdr_dst(pkt));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_NET_L2_CANBUS_ETH_TRANSLATOR)
|
|
||||||
if (net_canbus_translate_eth_frame(iface, pkt) == NET_OK) {
|
|
||||||
return NET_OK;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!net_eth_is_addr_broadcast((struct net_eth_addr *)lladdr->addr) &&
|
if (!net_eth_is_addr_broadcast((struct net_eth_addr *)lladdr->addr) &&
|
||||||
!net_eth_is_addr_multicast((struct net_eth_addr *)lladdr->addr) &&
|
!net_eth_is_addr_multicast((struct net_eth_addr *)lladdr->addr) &&
|
||||||
!net_eth_is_addr_lldp_multicast(
|
!net_eth_is_addr_lldp_multicast(
|
||||||
|
|
|
@ -89,7 +89,6 @@ CONFIG_NET_L2_IEEE802154_SECURITY=y
|
||||||
CONFIG_NET_L2_IEEE802154_SECURITY_CRYPTO_DEV_NAME="CRYPTO-DEV"
|
CONFIG_NET_L2_IEEE802154_SECURITY_CRYPTO_DEV_NAME="CRYPTO-DEV"
|
||||||
CONFIG_NET_L2_DUMMY=y
|
CONFIG_NET_L2_DUMMY=y
|
||||||
CONFIG_NET_L2_ETHERNET=y
|
CONFIG_NET_L2_ETHERNET=y
|
||||||
CONFIG_NET_L2_CANBUS=y
|
|
||||||
CONFIG_NET_L2_CANBUS_RAW=y
|
CONFIG_NET_L2_CANBUS_RAW=y
|
||||||
CONFIG_NET_L2_ETHERNET_MGMT=y
|
CONFIG_NET_L2_ETHERNET_MGMT=y
|
||||||
CONFIG_NET_L2_IEEE802154_RADIO_DFLT_TX_POWER=2
|
CONFIG_NET_L2_IEEE802154_RADIO_DFLT_TX_POWER=2
|
||||||
|
@ -370,7 +369,6 @@ CONFIG_NET_SOCKETS_TLS_MAX_CREDENTIALS=10
|
||||||
|
|
||||||
# Network interface defaults
|
# Network interface defaults
|
||||||
CONFIG_NET_DEFAULT_IF_BLUETOOTH=y
|
CONFIG_NET_DEFAULT_IF_BLUETOOTH=y
|
||||||
CONFIG_NET_DEFAULT_IF_CANBUS=y
|
|
||||||
CONFIG_NET_DEFAULT_IF_CANBUS_RAW=y
|
CONFIG_NET_DEFAULT_IF_CANBUS_RAW=y
|
||||||
CONFIG_NET_DEFAULT_IF_DUMMY=y
|
CONFIG_NET_DEFAULT_IF_DUMMY=y
|
||||||
CONFIG_NET_DEFAULT_IF_ETHERNET=y
|
CONFIG_NET_DEFAULT_IF_ETHERNET=y
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue