1 /*
2  * Copyright (c) 2019 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef __CONN_MGR_PRV_H__
8 #define __CONN_MGR_PRV_H__
9 
10 #include <zephyr/net/conn_mgr_connectivity.h>
11 #include <zephyr/sys/iterable_sections.h>
12 
13 #if defined(CONFIG_NET_IPV6) && defined(CONFIG_NET_IPV4)
14 #define CONN_MGR_IFACE_MAX		MAX(CONFIG_NET_IF_MAX_IPV6_COUNT, \
15 					    CONFIG_NET_IF_MAX_IPV4_COUNT)
16 #elif defined(CONFIG_NET_IPV6)
17 #define CONN_MGR_IFACE_MAX		CONFIG_NET_IF_MAX_IPV6_COUNT
18 #else
19 #define CONN_MGR_IFACE_MAX		CONFIG_NET_IF_MAX_IPV4_COUNT
20 #endif
21 
22 /* External state flags */
23 #define CONN_MGR_IF_UP			BIT(0)
24 #define CONN_MGR_IF_IPV6_SET		BIT(1)
25 #define CONN_MGR_IF_IPV4_SET		BIT(2)
26 
27 /* Configuration flags */
28 #define CONN_MGR_IF_IGNORED		BIT(7)
29 
30 /* Internal state flags */
31 #define CONN_MGR_IF_READY		BIT(13)
32 #define CONN_MGR_IF_READY_IPV4		BIT(14)
33 #define CONN_MGR_IF_READY_IPV6		BIT(15)
34 
35 /* Special value indicating invalid state. */
36 #define CONN_MGR_IF_STATE_INVALID	0xFFFF
37 
38 /* NET_MGMT event masks */
39 #define CONN_MGR_IFACE_EVENTS_MASK	(NET_EVENT_IF_DOWN		| \
40 					 NET_EVENT_IF_UP)
41 
42 #define CONN_MGR_CONN_IFACE_EVENTS_MASK	(NET_EVENT_IF_ADMIN_UP		|\
43 					 NET_EVENT_IF_DOWN)
44 
45 #define CONN_MGR_CONN_SELF_EVENTS_MASK	(NET_EVENT_CONN_IF_TIMEOUT	| \
46 					 NET_EVENT_CONN_IF_FATAL_ERROR)
47 
48 #define CONN_MGR_IPV6_EVENTS_MASK	(NET_EVENT_IPV6_ADDR_ADD	| \
49 					 NET_EVENT_IPV6_ADDR_DEL	| \
50 					 NET_EVENT_IPV6_DAD_SUCCEED	| \
51 					 NET_EVENT_IPV6_DAD_FAILED)
52 
53 #define CONN_MGR_IPV4_EVENTS_MASK	(NET_EVENT_IPV4_ADDR_ADD	| \
54 					 NET_EVENT_IPV4_ADDR_DEL	| \
55 					 NET_EVENT_IPV4_ACD_SUCCEED	| \
56 					 NET_EVENT_IPV4_ACD_FAILED)
57 
58 extern struct k_sem conn_mgr_mon_updated;
59 extern struct k_mutex conn_mgr_mon_lock;
60 
61 void conn_mgr_init_events_handler(void);
62 
63 /* Cause conn_mgr_connectivity to Initialize all connectivity implementation bindings */
64 void conn_mgr_conn_init(void);
65 
66 /* Internal helper function to allow the shell net cm command to safely read conn_mgr state. */
67 uint16_t conn_mgr_if_state(struct net_if *iface);
68 
69 #endif /* __CONN_MGR_PRV_H__ */
70