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 };
83 
84 #define NET_EVENT_IPV6_ADDR_ADD					\
85 	(_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_ADDR_ADD)
86 
87 #define NET_EVENT_IPV6_ADDR_DEL					\
88 	(_NET_EVENT_IPV6_BASE |	NET_EVENT_IPV6_CMD_ADDR_DEL)
89 
90 #define NET_EVENT_IPV6_MADDR_ADD				\
91 	(_NET_EVENT_IPV6_BASE |	NET_EVENT_IPV6_CMD_MADDR_ADD)
92 
93 #define NET_EVENT_IPV6_MADDR_DEL				\
94 	(_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_MADDR_DEL)
95 
96 #define NET_EVENT_IPV6_PREFIX_ADD				\
97 	(_NET_EVENT_IPV6_BASE |	NET_EVENT_IPV6_CMD_PREFIX_ADD)
98 
99 #define NET_EVENT_IPV6_PREFIX_DEL				\
100 	(_NET_EVENT_IPV6_BASE |	NET_EVENT_IPV6_CMD_PREFIX_DEL)
101 
102 #define NET_EVENT_IPV6_MCAST_JOIN				\
103 	(_NET_EVENT_IPV6_BASE |	NET_EVENT_IPV6_CMD_MCAST_JOIN)
104 
105 #define NET_EVENT_IPV6_MCAST_LEAVE				\
106 	(_NET_EVENT_IPV6_BASE |	NET_EVENT_IPV6_CMD_MCAST_LEAVE)
107 
108 #define NET_EVENT_IPV6_ROUTER_ADD				\
109 	(_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_ROUTER_ADD)
110 
111 #define NET_EVENT_IPV6_ROUTER_DEL				\
112 	(_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_ROUTER_DEL)
113 
114 #define NET_EVENT_IPV6_ROUTE_ADD				\
115 	(_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_ROUTE_ADD)
116 
117 #define NET_EVENT_IPV6_ROUTE_DEL				\
118 	(_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_ROUTE_DEL)
119 
120 #define NET_EVENT_IPV6_DAD_SUCCEED				\
121 	(_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_DAD_SUCCEED)
122 
123 #define NET_EVENT_IPV6_DAD_FAILED				\
124 	(_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_DAD_FAILED)
125 
126 #define NET_EVENT_IPV6_NBR_ADD					\
127 	(_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_NBR_ADD)
128 
129 #define NET_EVENT_IPV6_NBR_DEL					\
130 	(_NET_EVENT_IPV6_BASE | NET_EVENT_IPV6_CMD_NBR_DEL)
131 
132 /* IPv4 Events*/
133 #define _NET_IPV4_LAYER		NET_MGMT_LAYER_L3
134 #define _NET_IPV4_CORE_CODE	0x004
135 #define _NET_EVENT_IPV4_BASE	(NET_MGMT_EVENT_BIT |			\
136 				 NET_MGMT_IFACE_BIT |			\
137 				 NET_MGMT_LAYER(_NET_IPV4_LAYER) |	\
138 				 NET_MGMT_LAYER_CODE(_NET_IPV4_CORE_CODE))
139 
140 enum net_event_ipv4_cmd {
141 	NET_EVENT_IPV4_CMD_ADDR_ADD	= 1,
142 	NET_EVENT_IPV4_CMD_ADDR_DEL,
143 	NET_EVENT_IPV4_CMD_MADDR_ADD,
144 	NET_EVENT_IPV4_CMD_MADDR_DEL,
145 	NET_EVENT_IPV4_CMD_ROUTER_ADD,
146 	NET_EVENT_IPV4_CMD_ROUTER_DEL,
147 	NET_EVENT_IPV4_CMD_DHCP_START,
148 	NET_EVENT_IPV4_CMD_DHCP_BOUND,
149 	NET_EVENT_IPV4_CMD_DHCP_STOP,
150 	NET_EVENT_IPV4_CMD_MCAST_JOIN,
151 	NET_EVENT_IPV4_CMD_MCAST_LEAVE,
152 };
153 
154 #define NET_EVENT_IPV4_ADDR_ADD					\
155 	(_NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_ADDR_ADD)
156 
157 #define NET_EVENT_IPV4_ADDR_DEL					\
158 	(_NET_EVENT_IPV4_BASE |	NET_EVENT_IPV4_CMD_ADDR_DEL)
159 
160 #define NET_EVENT_IPV4_MADDR_ADD				\
161 	(_NET_EVENT_IPV4_BASE |	NET_EVENT_IPV4_CMD_MADDR_ADD)
162 
163 #define NET_EVENT_IPV4_MADDR_DEL				\
164 	(_NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_MADDR_DEL)
165 
166 #define NET_EVENT_IPV4_ROUTER_ADD				\
167 	(_NET_EVENT_IPV4_BASE |	NET_EVENT_IPV4_CMD_ROUTER_ADD)
168 
169 #define NET_EVENT_IPV4_ROUTER_DEL				\
170 	(_NET_EVENT_IPV4_BASE |	NET_EVENT_IPV4_CMD_ROUTER_DEL)
171 
172 #define NET_EVENT_IPV4_DHCP_START				\
173 	(_NET_EVENT_IPV4_BASE |	NET_EVENT_IPV4_CMD_DHCP_START)
174 
175 #define NET_EVENT_IPV4_DHCP_BOUND				\
176 	(_NET_EVENT_IPV4_BASE |	NET_EVENT_IPV4_CMD_DHCP_BOUND)
177 
178 #define NET_EVENT_IPV4_DHCP_STOP				\
179 	(_NET_EVENT_IPV4_BASE |	NET_EVENT_IPV4_CMD_DHCP_STOP)
180 
181 #define NET_EVENT_IPV4_MCAST_JOIN				\
182 	(_NET_EVENT_IPV4_BASE |	NET_EVENT_IPV4_CMD_MCAST_JOIN)
183 
184 #define NET_EVENT_IPV4_MCAST_LEAVE				\
185 	(_NET_EVENT_IPV4_BASE |	NET_EVENT_IPV4_CMD_MCAST_LEAVE)
186 
187 
188 /* L4 network events */
189 #define _NET_L4_LAYER		NET_MGMT_LAYER_L4
190 #define _NET_L4_CORE_CODE	0x114
191 #define _NET_EVENT_L4_BASE	(NET_MGMT_EVENT_BIT |			\
192 				 NET_MGMT_IFACE_BIT |			\
193 				 NET_MGMT_LAYER(_NET_L4_LAYER) |	\
194 				 NET_MGMT_LAYER_CODE(_NET_L4_CORE_CODE))
195 
196 enum net_event_l4_cmd {
197 	NET_EVENT_L4_CMD_CONNECTED = 1,
198 	NET_EVENT_L4_CMD_DISCONNECTED,
199 	NET_EVENT_L4_CMD_DNS_SERVER_ADD,
200 	NET_EVENT_L4_CMD_DNS_SERVER_DEL,
201 };
202 
203 #define NET_EVENT_L4_CONNECTED				\
204 	(_NET_EVENT_L4_BASE | NET_EVENT_L4_CMD_CONNECTED)
205 
206 #define NET_EVENT_L4_DISCONNECTED			\
207 	(_NET_EVENT_L4_BASE | NET_EVENT_L4_CMD_DISCONNECTED)
208 
209 #define NET_EVENT_DNS_SERVER_ADD			\
210 	(_NET_EVENT_L4_BASE | NET_EVENT_L4_CMD_DNS_SERVER_ADD)
211 
212 #define NET_EVENT_DNS_SERVER_DEL			\
213 	(_NET_EVENT_L4_BASE | NET_EVENT_L4_CMD_DNS_SERVER_DEL)
214 
215 /** @endcond */
216 
217 #ifdef CONFIG_NET_MGMT_EVENT_INFO
218 /**
219  * @brief Network Management event information structure
220  * Used to pass information on network events like
221  *   NET_EVENT_IPV6_ADDR_ADD,
222  *   NET_EVENT_IPV6_ADDR_DEL,
223  *   NET_EVENT_IPV6_MADDR_ADD and
224  *   NET_EVENT_IPV6_MADDR_DEL
225  * when CONFIG_NET_MGMT_EVENT_INFO enabled and event generator pass the
226  * information.
227  */
228 struct net_event_ipv6_addr {
229 	struct in6_addr addr;
230 };
231 
232 /**
233  * @brief Network Management event information structure
234  * Used to pass information on network events like
235  *   NET_EVENT_IPV6_NBR_ADD and
236  *   NET_EVENT_IPV6_NBR_DEL
237  * when CONFIG_NET_MGMT_EVENT_INFO enabled and event generator pass the
238  * information.
239  * @Note: idx will be '-1' in case of NET_EVENT_IPV6_NBR_DEL event.
240  */
241 struct net_event_ipv6_nbr {
242 	struct in6_addr addr;
243 	int idx; /* NBR index*/
244 };
245 
246 /**
247  * @brief Network Management event information structure
248  * Used to pass information on network events like
249  *   NET_EVENT_IPV6_ROUTE_ADD and
250  *   NET_EVENT_IPV6_ROUTE_DEL
251  * when CONFIG_NET_MGMT_EVENT_INFO enabled and event generator pass the
252  * information.
253  */
254 struct net_event_ipv6_route {
255 	struct in6_addr nexthop;
256 	struct in6_addr addr; /* addr/prefix */
257 	uint8_t prefix_len;
258 };
259 
260 #endif /* CONFIG_NET_MGMT_EVENT_INFO */
261 
262 #ifdef __cplusplus
263 }
264 #endif
265 
266 /**
267  * @}
268  */
269 
270 #endif /* ZEPHYR_INCLUDE_NET_NET_EVENT_H_ */
271