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_flags(struct net_if * iface)48 static enum net_l2_flags dummy_flags(struct net_if *iface)
49 {
50 	return NET_L2_MULTICAST;
51 }
52 
53 NET_L2_INIT(DUMMY_L2, dummy_recv, dummy_send, NULL, dummy_flags);
54