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