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 const struct dummy_api *api = net_if_get_device(iface)->api;
21
22 if (api == NULL) {
23 return NET_DROP;
24 }
25
26 if (api->recv == NULL) {
27 return NET_CONTINUE;
28 }
29
30 return api->recv(iface, pkt);
31 }
32
dummy_send(struct net_if * iface,struct net_pkt * pkt)33 static inline int dummy_send(struct net_if *iface, struct net_pkt *pkt)
34 {
35 const struct dummy_api *api = net_if_get_device(iface)->api;
36 int ret;
37
38 if (!api) {
39 return -ENOENT;
40 }
41
42 ret = net_l2_send(api->send, net_if_get_device(iface), iface, pkt);
43 if (!ret) {
44 ret = net_pkt_get_len(pkt);
45 net_pkt_unref(pkt);
46 }
47
48 return ret;
49 }
50
dummy_enable(struct net_if * iface,bool state)51 static inline int dummy_enable(struct net_if *iface, bool state)
52 {
53 int ret = 0;
54 const struct dummy_api *api = net_if_get_device(iface)->api;
55
56 if (!api) {
57 return -ENOENT;
58 }
59
60 if (!state) {
61 if (api->stop) {
62 ret = api->stop(net_if_get_device(iface));
63 }
64 } else {
65 if (api->start) {
66 ret = api->start(net_if_get_device(iface));
67 }
68 }
69
70 return ret;
71 }
72
dummy_flags(struct net_if * iface)73 static enum net_l2_flags dummy_flags(struct net_if *iface)
74 {
75 return NET_L2_MULTICAST;
76 }
77
78 NET_L2_INIT(DUMMY_L2, dummy_recv, dummy_send, dummy_enable, dummy_flags);
79