1 /*
2  * Copyright (c) 2016 Intel Corporation.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief Network Events code public header
10  */
11 
12 #ifndef ZEPHYR_INCLUDE_NET_NET_EVENT_H_
13 #define ZEPHYR_INCLUDE_NET_NET_EVENT_H_
14 
15 #include <zephyr/net/net_ip.h>
16 #include <zephyr/net/hostname.h>
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 /**
23  * @addtogroup net_mgmt
24  * @{
25  */
26 
27 /** @cond INTERNAL_HIDDEN */
28 
29 /* Network Interface events */
30 #define _NET_IF_LAYER		NET_MGMT_LAYER_L2
31 #define _NET_IF_CORE_CODE	0x001
32 #define _NET_EVENT_IF_BASE	(NET_MGMT_EVENT_BIT |			\
33 				 NET_MGMT_IFACE_BIT |			\
34 				 NET_MGMT_LAYER(_NET_IF_LAYER) |	\
35 				 NET_MGMT_LAYER_CODE(_NET_IF_CORE_CODE))
36 
37 enum net_event_if_cmd {
38 	NET_EVENT_IF_CMD_DOWN = 1,
39 	NET_EVENT_IF_CMD_UP,
40 	NET_EVENT_IF_CMD_ADMIN_DOWN,
41 	NET_EVENT_IF_CMD_ADMIN_UP,
42 };
43 
44 #define NET_EVENT_IF_DOWN				\
45 	(_NET_EVENT_IF_BASE | NET_EVENT_IF_CMD_DOWN)
46 
47 #define NET_EVENT_IF_UP					\
48 	(_NET_EVENT_IF_BASE | NET_EVENT_IF_CMD_UP)
49 
50 #define NET_EVENT_IF_ADMIN_DOWN				\
51 	(_NET_EVENT_IF_BASE | NET_EVENT_IF_CMD_ADMIN_DOWN)
52 
53 #define NET_EVENT_IF_ADMIN_UP				\
54 	(_NET_EVENT_IF_BASE | NET_EVENT_IF_CMD_ADMIN_UP)
55 
56 /* IPv6 Events */
57 #define _NET_IPV6_LAYER		NET_MGMT_LAYER_L3
58 #define _NET_IPV6_CORE_CODE	0x060
59 #define _NET_EVENT_IPV6_BASE	(NET_MGMT_EVENT_BIT |			\
60 				 NET_MGMT_IFACE_BIT |			\
61 				 NET_MGMT_LAYER(_NET_IPV6_LAYER) |	\
62 				 NET_MGMT_LAYER_CODE(_NET_IPV6_CORE_CODE))
63 
64 enum net_event_ipv6_cmd {
65 	NET_EVENT_IPV6_CMD_ADDR_ADD	= 1,
66 	NET_EVENT_IPV6_CMD_ADDR_DEL,
67 	NET_EVENT_IPV6_CMD_MADDR_ADD,
68 	NET_EVENT_IPV6_CMD_MADDR_DEL,
69 	NET_EVENT_IPV6_CMD_PREFIX_ADD,
70 	NET_EVENT_IPV6_CMD_PREFIX_DEL,
71 	NET_EVENT_IPV6_CMD_MCAST_JOIN,
72 	NET_EVENT_IPV6_CMD_MCAST_LEAVE,
73 	NET_EVENT_IPV6_CMD_ROUTER_ADD,
74 	NET_EVENT_IPV6_CMD_ROUTER_DEL,
75 	NET_EVENT_IPV6_CMD_ROUTE_ADD,
76 	NET_EVENT_IPV6_CMD_ROUTE_DEL,
77 	NET_EVENT_IPV6_CMD_DAD_SUCCEED,
78 	NET_EVENT_IPV6_CMD_DAD_FAILED,
79 	NET_EVENT_IPV6_CMD_NBR_ADD,
80 	NET_EVENT_IPV6_CMD_NBR_DEL,
81 	NET_EVENT_IPV6_CMD_DHCP_START,
82 	NET_EVENT_IPV6_CMD_DHCP_BOUND,
83 	NET_EVENT_IPV6_CMD_DHCP_STOP,
84 };
85 
86 #define NET_EVENT_IPV6_ADDR_ADD					\
87 	(_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_ADDR_ADD)
88 
89 #define NET_EVENT_IPV6_ADDR_DEL					\
90 	(_NET_EVENT_IPV6_BASE |	NET_EVENT_IPV6_CMD_ADDR_DEL)
91 
92 #define NET_EVENT_IPV6_MADDR_ADD				\
93 	(_NET_EVENT_IPV6_BASE |	NET_EVENT_IPV6_CMD_MADDR_ADD)
94 
95 #define NET_EVENT_IPV6_MADDR_DEL				\
96 	(_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_MADDR_DEL)
97 
98 #define NET_EVENT_IPV6_PREFIX_ADD				\
99 	(_NET_EVENT_IPV6_BASE |	NET_EVENT_IPV6_CMD_PREFIX_ADD)
100 
101 #define NET_EVENT_IPV6_PREFIX_DEL				\
102 	(_NET_EVENT_IPV6_BASE |	NET_EVENT_IPV6_CMD_PREFIX_DEL)
103 
104 #define NET_EVENT_IPV6_MCAST_JOIN				\
105 	(_NET_EVENT_IPV6_BASE |	NET_EVENT_IPV6_CMD_MCAST_JOIN)
106 
107 #define NET_EVENT_IPV6_MCAST_LEAVE				\
108 	(_NET_EVENT_IPV6_BASE |	NET_EVENT_IPV6_CMD_MCAST_LEAVE)
109 
110 #define NET_EVENT_IPV6_ROUTER_ADD				\
111 	(_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_ROUTER_ADD)
112 
113 #define NET_EVENT_IPV6_ROUTER_DEL				\
114 	(_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_ROUTER_DEL)
115 
116 #define NET_EVENT_IPV6_ROUTE_ADD				\
117 	(_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_ROUTE_ADD)
118 
119 #define NET_EVENT_IPV6_ROUTE_DEL				\
120 	(_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_ROUTE_DEL)
121 
122 #define NET_EVENT_IPV6_DAD_SUCCEED				\
123 	(_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_DAD_SUCCEED)
124 
125 #define NET_EVENT_IPV6_DAD_FAILED				\
126 	(_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_DAD_FAILED)
127 
128 #define NET_EVENT_IPV6_NBR_ADD					\
129 	(_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_NBR_ADD)
130 
131 #define NET_EVENT_IPV6_NBR_DEL					\
132 	(_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_NBR_DEL)
133 
134 #define NET_EVENT_IPV6_DHCP_START				\
135 	(_NET_EVENT_IPV4_BASE |	NET_EVENT_IPV6_CMD_DHCP_START)
136 
137 #define NET_EVENT_IPV6_DHCP_BOUND				\
138 	(_NET_EVENT_IPV4_BASE |	NET_EVENT_IPV6_CMD_DHCP_BOUND)
139 
140 #define NET_EVENT_IPV6_DHCP_STOP				\
141 	(_NET_EVENT_IPV4_BASE |	NET_EVENT_IPV6_CMD_DHCP_STOP)
142 
143 /* IPv4 Events*/
144 #define _NET_IPV4_LAYER		NET_MGMT_LAYER_L3
145 #define _NET_IPV4_CORE_CODE	0x004
146 #define _NET_EVENT_IPV4_BASE	(NET_MGMT_EVENT_BIT |			\
147 				 NET_MGMT_IFACE_BIT |			\
148 				 NET_MGMT_LAYER(_NET_IPV4_LAYER) |	\
149 				 NET_MGMT_LAYER_CODE(_NET_IPV4_CORE_CODE))
150 
151 enum net_event_ipv4_cmd {
152 	NET_EVENT_IPV4_CMD_ADDR_ADD	= 1,
153 	NET_EVENT_IPV4_CMD_ADDR_DEL,
154 	NET_EVENT_IPV4_CMD_MADDR_ADD,
155 	NET_EVENT_IPV4_CMD_MADDR_DEL,
156 	NET_EVENT_IPV4_CMD_ROUTER_ADD,
157 	NET_EVENT_IPV4_CMD_ROUTER_DEL,
158 	NET_EVENT_IPV4_CMD_DHCP_START,
159 	NET_EVENT_IPV4_CMD_DHCP_BOUND,
160 	NET_EVENT_IPV4_CMD_DHCP_STOP,
161 	NET_EVENT_IPV4_CMD_MCAST_JOIN,
162 	NET_EVENT_IPV4_CMD_MCAST_LEAVE,
163 };
164 
165 #define NET_EVENT_IPV4_ADDR_ADD					\
166 	(_NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_ADDR_ADD)
167 
168 #define NET_EVENT_IPV4_ADDR_DEL					\
169 	(_NET_EVENT_IPV4_BASE |	NET_EVENT_IPV4_CMD_ADDR_DEL)
170 
171 #define NET_EVENT_IPV4_MADDR_ADD				\
172 	(_NET_EVENT_IPV4_BASE |	NET_EVENT_IPV4_CMD_MADDR_ADD)
173 
174 #define NET_EVENT_IPV4_MADDR_DEL				\
175 	(_NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_MADDR_DEL)
176 
177 #define NET_EVENT_IPV4_ROUTER_ADD				\
178 	(_NET_EVENT_IPV4_BASE |	NET_EVENT_IPV4_CMD_ROUTER_ADD)
179 
180 #define NET_EVENT_IPV4_ROUTER_DEL				\
181 	(_NET_EVENT_IPV4_BASE |	NET_EVENT_IPV4_CMD_ROUTER_DEL)
182 
183 #define NET_EVENT_IPV4_DHCP_START				\
184 	(_NET_EVENT_IPV4_BASE |	NET_EVENT_IPV4_CMD_DHCP_START)
185 
186 #define NET_EVENT_IPV4_DHCP_BOUND				\
187 	(_NET_EVENT_IPV4_BASE |	NET_EVENT_IPV4_CMD_DHCP_BOUND)
188 
189 #define NET_EVENT_IPV4_DHCP_STOP				\
190 	(_NET_EVENT_IPV4_BASE |	NET_EVENT_IPV4_CMD_DHCP_STOP)
191 
192 #define NET_EVENT_IPV4_MCAST_JOIN				\
193 	(_NET_EVENT_IPV4_BASE |	NET_EVENT_IPV4_CMD_MCAST_JOIN)
194 
195 #define NET_EVENT_IPV4_MCAST_LEAVE				\
196 	(_NET_EVENT_IPV4_BASE |	NET_EVENT_IPV4_CMD_MCAST_LEAVE)
197 
198 
199 /* L4 network events */
200 #define _NET_L4_LAYER		NET_MGMT_LAYER_L4
201 #define _NET_L4_CORE_CODE	0x114
202 #define _NET_EVENT_L4_BASE	(NET_MGMT_EVENT_BIT |			\
203 				 NET_MGMT_IFACE_BIT |			\
204 				 NET_MGMT_LAYER(_NET_L4_LAYER) |	\
205 				 NET_MGMT_LAYER_CODE(_NET_L4_CORE_CODE))
206 
207 enum net_event_l4_cmd {
208 	NET_EVENT_L4_CMD_CONNECTED = 1,
209 	NET_EVENT_L4_CMD_DISCONNECTED,
210 	NET_EVENT_L4_CMD_DNS_SERVER_ADD,
211 	NET_EVENT_L4_CMD_DNS_SERVER_DEL,
212 	NET_EVENT_L4_CMD_HOSTNAME_CHANGED,
213 };
214 
215 #define NET_EVENT_L4_CONNECTED				\
216 	(_NET_EVENT_L4_BASE | NET_EVENT_L4_CMD_CONNECTED)
217 
218 #define NET_EVENT_L4_DISCONNECTED			\
219 	(_NET_EVENT_L4_BASE | NET_EVENT_L4_CMD_DISCONNECTED)
220 
221 #define NET_EVENT_DNS_SERVER_ADD			\
222 	(_NET_EVENT_L4_BASE | NET_EVENT_L4_CMD_DNS_SERVER_ADD)
223 
224 #define NET_EVENT_DNS_SERVER_DEL			\
225 	(_NET_EVENT_L4_BASE | NET_EVENT_L4_CMD_DNS_SERVER_DEL)
226 
227 #define NET_EVENT_HOSTNAME_CHANGED			\
228 	(_NET_EVENT_L4_BASE | NET_EVENT_L4_CMD_HOSTNAME_CHANGED)
229 
230 /** @endcond */
231 
232 /**
233  * @brief Network Management event information structure
234  * Used to pass information on network events like
235  *   NET_EVENT_IPV6_ADDR_ADD,
236  *   NET_EVENT_IPV6_ADDR_DEL,
237  *   NET_EVENT_IPV6_MADDR_ADD and
238  *   NET_EVENT_IPV6_MADDR_DEL
239  * when CONFIG_NET_MGMT_EVENT_INFO enabled and event generator pass the
240  * information.
241  */
242 struct net_event_ipv6_addr {
243 	struct in6_addr addr;
244 };
245 
246 /**
247  * @brief Network Management event information structure
248  * Used to pass information on network events like
249  *   NET_EVENT_IPV6_NBR_ADD and
250  *   NET_EVENT_IPV6_NBR_DEL
251  * when CONFIG_NET_MGMT_EVENT_INFO enabled and event generator pass the
252  * information.
253  * @note: idx will be '-1' in case of NET_EVENT_IPV6_NBR_DEL event.
254  */
255 struct net_event_ipv6_nbr {
256 	struct in6_addr addr;
257 	int idx; /* NBR index*/
258 };
259 
260 /**
261  * @brief Network Management event information structure
262  * Used to pass information on network events like
263  *   NET_EVENT_IPV6_ROUTE_ADD and
264  *   NET_EVENT_IPV6_ROUTE_DEL
265  * when CONFIG_NET_MGMT_EVENT_INFO enabled and event generator pass the
266  * information.
267  */
268 struct net_event_ipv6_route {
269 	struct in6_addr nexthop;
270 	struct in6_addr addr; /* addr/prefix */
271 	uint8_t prefix_len;
272 };
273 
274 /**
275  * @brief Network Management event information structure
276  * Used to pass information on network events like
277  *   NET_EVENT_IPV6_PREFIX_ADD and
278  *   NET_EVENT_IPV6_PREFIX_DEL
279  * when CONFIG_NET_MGMT_EVENT_INFO is enabled and event generator pass the
280  * information.
281  */
282 struct net_event_ipv6_prefix {
283 	struct in6_addr addr; /* prefix */
284 	uint8_t len;
285 	uint32_t lifetime;
286 };
287 
288 /**
289  * @brief Network Management event information structure
290  * Used to pass information on NET_EVENT_HOSTNAME_CHANGED event when
291  * CONFIG_NET_MGMT_EVENT_INFO is enabled and event generator pass the
292  * information.
293  */
294 struct net_event_l4_hostname {
295 	char hostname[NET_HOSTNAME_SIZE];
296 };
297 
298 #ifdef __cplusplus
299 }
300 #endif
301 
302 /**
303  * @}
304  */
305 
306 #endif /* ZEPHYR_INCLUDE_NET_NET_EVENT_H_ */
307