1 /*
2 * Copyright (c) 2019 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/logging/log.h>
8 LOG_MODULE_REGISTER(net_l2_canbus, LOG_LEVEL_NONE);
9
10 #include <zephyr/net/net_core.h>
11 #include <zephyr/net/net_l2.h>
12 #include <zephyr/net/net_if.h>
13 #include <zephyr/net/net_pkt.h>
14 #include <zephyr/net/canbus.h>
15
canbus_recv(struct net_if * iface,struct net_pkt * pkt)16 static inline enum net_verdict canbus_recv(struct net_if *iface,
17 struct net_pkt *pkt)
18 {
19 net_pkt_lladdr_src(pkt)->addr = NULL;
20 net_pkt_lladdr_src(pkt)->len = 0U;
21 net_pkt_lladdr_src(pkt)->type = NET_LINK_CANBUS_RAW;
22 net_pkt_lladdr_dst(pkt)->addr = NULL;
23 net_pkt_lladdr_dst(pkt)->len = 0U;
24 net_pkt_lladdr_dst(pkt)->type = NET_LINK_CANBUS_RAW;
25
26 net_pkt_set_family(pkt, AF_CAN);
27
28 return NET_CONTINUE;
29 }
30
canbus_send(struct net_if * iface,struct net_pkt * pkt)31 static inline int canbus_send(struct net_if *iface, struct net_pkt *pkt)
32 {
33 const struct canbus_api *api = net_if_get_device(iface)->api;
34 int ret;
35
36 if (!api) {
37 return -ENOENT;
38 }
39
40 ret = net_l2_send(api->send, net_if_get_device(iface), iface, pkt);
41 if (!ret) {
42 ret = net_pkt_get_len(pkt);
43 net_pkt_unref(pkt);
44 }
45
46 return ret;
47 }
48
49 NET_L2_INIT(CANBUS_RAW_L2, canbus_recv, canbus_send, NULL, NULL);
50