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