1 /*
2 * Copyright (c) 2023 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/net/net_if.h>
8 #include <zephyr/net/dummy.h>
9 #include <zephyr/net/conn_mgr_connectivity.h>
10 #include "test_conn_impl.h"
11 #include "test_ifaces.h"
12
13 /* Create test ifaces */
14
15 /* Generic iface initializer, shared by all three ifaces */
test_iface_init(struct net_if * iface)16 static void test_iface_init(struct net_if *iface)
17 {
18 /* Fake link layer address is needed to silence assertions inside the net core */
19 static uint8_t fake_lladdr[] = { 0x01 };
20
21 net_if_set_link_addr(iface, fake_lladdr, sizeof(fake_lladdr), NET_LINK_DUMMY);
22
23 /* Do not automatically start the iface */
24 net_if_flag_set(iface, NET_IF_NO_AUTO_START);
25 }
26
27 static struct dummy_api test_iface_api = {
28 .iface_api.init = test_iface_init,
29 };
30
31 /* Create three ifaces, a1, a2, b such that:
32 * iface a1 and a2 share L2 connectivity implementation a
33 * iface b uses connectivity implementation b
34 */
35 NET_DEVICE_INIT(test_iface_a1,
36 "test_iface_a1",
37 NULL,
38 NULL,
39 NULL,
40 NULL,
41 CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
42 &test_iface_api,
43 DUMMY_L2,
44 NET_L2_GET_CTX_TYPE(DUMMY_L2),
45 127);
46 NET_DEVICE_INIT(test_iface_a2,
47 "test_iface_a2",
48 NULL,
49 NULL,
50 NULL,
51 NULL,
52 CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
53 &test_iface_api,
54 DUMMY_L2,
55 NET_L2_GET_CTX_TYPE(DUMMY_L2),
56 127);
57 NET_DEVICE_INIT(test_iface_b,
58 "test_iface_b",
59 NULL,
60 NULL,
61 NULL,
62 NULL,
63 CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
64 &test_iface_api,
65 DUMMY_L2,
66 NET_L2_GET_CTX_TYPE(DUMMY_L2),
67 127);
68
69 /* Create an ifaces with NULL implementation, NULL init, and no connectivity at all */
70 NET_DEVICE_INIT(test_iface_null,
71 "test_iface_null",
72 NULL,
73 NULL,
74 NULL,
75 NULL,
76 CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
77 &test_iface_api,
78 DUMMY_L2,
79 NET_L2_GET_CTX_TYPE(DUMMY_L2),
80 127);
81 NET_DEVICE_INIT(test_iface_ni,
82 "test_iface_ni",
83 NULL,
84 NULL,
85 NULL,
86 NULL,
87 CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
88 &test_iface_api,
89 DUMMY_L2,
90 NET_L2_GET_CTX_TYPE(DUMMY_L2),
91 127);
92 NET_DEVICE_INIT(test_iface_none,
93 "test_iface_none",
94 NULL,
95 NULL,
96 NULL,
97 NULL,
98 CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
99 &test_iface_api,
100 DUMMY_L2,
101 NET_L2_GET_CTX_TYPE(DUMMY_L2),
102 127);
103
104 /* Bind L2 connectivity implementations to ifaces */
105 CONN_MGR_BIND_CONN(test_iface_a1, TEST_L2_CONN_IMPL_A);
106 CONN_MGR_BIND_CONN(test_iface_a2, TEST_L2_CONN_IMPL_A);
107 CONN_MGR_BIND_CONN(test_iface_b, TEST_L2_CONN_IMPL_B);
108
109 /* Bind edge-case L2 connectivity implementations to ifaces */
110 CONN_MGR_BIND_CONN(test_iface_null, TEST_L2_CONN_IMPL_N);
111 CONN_MGR_BIND_CONN(test_iface_ni, TEST_L2_CONN_IMPL_NI);
112
113 /* Public accessors for static iface structs */
114 struct net_if *ifa1 = NET_IF_GET(test_iface_a1, 0);
115 struct net_if *ifa2 = NET_IF_GET(test_iface_a2, 0);
116 struct net_if *ifb = NET_IF_GET(test_iface_b, 0);
117 struct net_if *ifni = NET_IF_GET(test_iface_ni, 0);
118 struct net_if *ifnull = NET_IF_GET(test_iface_null, 0);
119 struct net_if *ifnone = NET_IF_GET(test_iface_none, 0);
120