1 /*
2 * Copyright (c) 2016 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/logging/log.h>
8 LOG_MODULE_REGISTER(net_l2_dummy, 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
15 #include <zephyr/net/dummy.h>
16
dummy_recv(struct net_if * iface,struct net_pkt * pkt)17 static inline enum net_verdict dummy_recv(struct net_if *iface,
18 struct net_pkt *pkt)
19 {
20 net_pkt_lladdr_src(pkt)->addr = NULL;
21 net_pkt_lladdr_src(pkt)->len = 0U;
22 net_pkt_lladdr_src(pkt)->type = NET_LINK_DUMMY;
23 net_pkt_lladdr_dst(pkt)->addr = NULL;
24 net_pkt_lladdr_dst(pkt)->len = 0U;
25 net_pkt_lladdr_dst(pkt)->type = NET_LINK_DUMMY;
26
27 return NET_CONTINUE;
28 }
29
dummy_send(struct net_if * iface,struct net_pkt * pkt)30 static inline int dummy_send(struct net_if *iface, struct net_pkt *pkt)
31 {
32 const struct dummy_api *api = net_if_get_device(iface)->api;
33 int ret;
34
35 if (!api) {
36 return -ENOENT;
37 }
38
39 ret = net_l2_send(api->send, net_if_get_device(iface), iface, pkt);
40 if (!ret) {
41 ret = net_pkt_get_len(pkt);
42 net_pkt_unref(pkt);
43 }
44
45 return ret;
46 }
47
dummy_enable(struct net_if * iface,bool state)48 static inline int dummy_enable(struct net_if *iface, bool state)
49 {
50 int ret = 0;
51 const struct dummy_api *api = net_if_get_device(iface)->api;
52
53 if (!api) {
54 return -ENOENT;
55 }
56
57 if (!state) {
58 if (api->stop) {
59 ret = api->stop(net_if_get_device(iface));
60 }
61 } else {
62 if (api->start) {
63 ret = api->start(net_if_get_device(iface));
64 }
65 }
66
67 return ret;
68 }
69
dummy_flags(struct net_if * iface)70 static enum net_l2_flags dummy_flags(struct net_if *iface)
71 {
72 return NET_L2_MULTICAST;
73 }
74
75 NET_L2_INIT(DUMMY_L2, dummy_recv, dummy_send, dummy_enable, dummy_flags);
76