Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
net_mgmt.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
11
12#ifndef ZEPHYR_INCLUDE_NET_NET_MGMT_H_
13#define ZEPHYR_INCLUDE_NET_NET_MGMT_H_
14
15#include <zephyr/sys/__assert.h>
16#include <zephyr/net/net_core.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
31
32struct net_if;
33
38#define NET_MGMT_EVENT_MASK GENMASK64(63, 63) /* 0x8000000000000000 */
39#define NET_MGMT_ON_IFACE_MASK GENMASK64(62, 62) /* 0x4000000000000000 */
40#define NET_MGMT_LAYER_MASK GENMASK64(61, 60) /* 0x3000000000000000 */
41#define NET_MGMT_SYNC_EVENT_MASK GENMASK64(59, 59) /* 0x0800000000000000 */
42#define NET_MGMT_LAYER_CODE_MASK GENMASK64(58, 52) /* 0x07F0000000000000 */
43#define NET_MGMT_COMMAND_MASK GENMASK64(51, 0) /* 0x000FFFFFFFFFFFFF */
44
45#define NET_MGMT_MAX_COMMANDS 52 /* TODO: figure out the value from mask */
46
47#define NET_MGMT_EVENT_BIT BIT64(63)
48#define NET_MGMT_IFACE_BIT BIT64(62)
49#define NET_MGMT_SYNC_EVENT_BIT BIT64(59)
50
51#define NET_MGMT_LAYER(_layer) FIELD_PREP(NET_MGMT_LAYER_MASK, (_layer))
52#define NET_MGMT_LAYER_CODE(_code) FIELD_PREP(NET_MGMT_LAYER_CODE_MASK, (_code))
53
54#define NET_MGMT_EVENT(mgmt_request) FIELD_GET(NET_MGMT_EVENT_MASK, mgmt_request)
55#define NET_MGMT_ON_IFACE(mgmt_request) FIELD_GET(NET_MGMT_ON_IFACE_MASK, mgmt_request)
56#define NET_MGMT_EVENT_SYNCHRONOUS(mgmt_request) FIELD_GET(NET_MGMT_SYNC_EVENT_MASK, mgmt_request)
57#define NET_MGMT_GET_LAYER(mgmt_request) FIELD_GET(NET_MGMT_LAYER_MASK, mgmt_request)
58#define NET_MGMT_GET_LAYER_CODE(mgmt_request) FIELD_GET(NET_MGMT_LAYER_CODE_MASK, mgmt_request)
59#define NET_MGMT_GET_COMMAND(mgmt_request) FIELD_GET(NET_MGMT_COMMAND_MASK, mgmt_request)
60
61#define NET_MGMT_CMD(cmd) cmd = BIT64(cmd ##_VAL)
62
63/* Useful generic definitions */
64#define NET_MGMT_LAYER_L2 1
65#define NET_MGMT_LAYER_L3 2
66#define NET_MGMT_LAYER_L4 3
67
69
96
98
110typedef int (*net_mgmt_request_handler_t)(uint64_t mgmt_request,
111 struct net_if *iface,
112 void *data, size_t len);
113
122#define net_mgmt(_mgmt_request, _iface, _data, _len) \
123 net_mgmt_##_mgmt_request(_mgmt_request, _iface, _data, _len)
124
130#define NET_MGMT_DEFINE_REQUEST_HANDLER(_mgmt_request) \
131 extern int net_mgmt_##_mgmt_request(uint64_t mgmt_request, \
132 struct net_if *iface, \
133 void *data, size_t len)
134
141#define NET_MGMT_REGISTER_REQUEST_HANDLER(_mgmt_request, _func) \
142 FUNC_ALIAS(_func, net_mgmt_##_mgmt_request, int)
143
145
155 uint64_t mgmt_event,
156 struct net_if *iface);
157
169
170 union {
178 };
179
180#ifdef CONFIG_NET_MGMT_EVENT_INFO
181 const void *info;
182 size_t info_length;
183#endif
184
190 union {
204 };
205};
206
218typedef void (*net_mgmt_event_static_handler_t)(uint64_t mgmt_event,
219 struct net_if *iface,
220 void *info, size_t info_length,
221 void *user_data);
222
224
225/* Structure for event handler registered at compile time */
226struct net_mgmt_event_static_handler {
227 uint64_t event_mask;
229 void *user_data;
230};
231
233
247#define NET_MGMT_REGISTER_EVENT_HANDLER(_name, _event_mask, _func, _user_data) \
248 const STRUCT_SECTION_ITERABLE(net_mgmt_event_static_handler, _name) = { \
249 .event_mask = _event_mask, \
250 .handler = _func, \
251 .user_data = (void *)_user_data, \
252 }
253
260#ifdef CONFIG_NET_MGMT_EVENT
261static inline
264 uint64_t mgmt_event_mask)
265{
266 __ASSERT(cb, "Callback pointer should not be NULL");
267 __ASSERT(handler, "Handler pointer should not be NULL");
268
269 cb->handler = handler;
270 cb->event_mask = mgmt_event_mask;
271};
272#else
273#define net_mgmt_init_event_callback(...)
274#endif
275
280#ifdef CONFIG_NET_MGMT_EVENT
282#else
283#define net_mgmt_add_event_callback(...)
284#endif
285
290#ifdef CONFIG_NET_MGMT_EVENT
292#else
293#define net_mgmt_del_event_callback(...)
294#endif
295
296#if defined(CONFIG_NET_MGMT_EVENT) || defined(__DOXYGEN__)
310void net_mgmt_event_notify_with_info(uint64_t mgmt_event, struct net_if *iface,
311 const void *info, size_t length);
312#else
313static inline void net_mgmt_event_notify_with_info(uint64_t mgmt_event, struct net_if *iface,
314 const void *info, size_t length)
315{
316 ARG_UNUSED(mgmt_event);
317 ARG_UNUSED(iface);
318 ARG_UNUSED(info);
319 ARG_UNUSED(length);
320}
321#endif
322
323#if defined(CONFIG_NET_MGMT_EVENT) || defined(__DOXYGEN__)
330static inline void net_mgmt_event_notify(uint64_t mgmt_event,
331 struct net_if *iface)
332{
333 net_mgmt_event_notify_with_info(mgmt_event, iface, NULL, 0);
334}
335#else
336static inline void net_mgmt_event_notify(uint64_t mgmt_event,
337 struct net_if *iface)
338{
339 ARG_UNUSED(mgmt_event);
340 ARG_UNUSED(iface);
341}
342#endif
343
364#ifdef CONFIG_NET_MGMT_EVENT
365int net_mgmt_event_wait(uint64_t mgmt_event_mask,
366 uint64_t *raised_event,
367 struct net_if **iface,
368 const void **info,
369 size_t *info_length,
370 k_timeout_t timeout);
371#else
372static inline int net_mgmt_event_wait(uint64_t mgmt_event_mask,
373 uint64_t *raised_event,
374 struct net_if **iface,
375 const void **info,
376 size_t *info_length,
377 k_timeout_t timeout)
378{
379 ARG_UNUSED(mgmt_event_mask);
380 ARG_UNUSED(raised_event);
381 ARG_UNUSED(iface);
382 ARG_UNUSED(info);
383 ARG_UNUSED(info_length);
384 ARG_UNUSED(timeout);
385 return 0;
386}
387#endif
388
408#ifdef CONFIG_NET_MGMT_EVENT
410 uint64_t mgmt_event_mask,
411 uint64_t *raised_event,
412 const void **info,
413 size_t *info_length,
414 k_timeout_t timeout);
415#else
416static inline int net_mgmt_event_wait_on_iface(struct net_if *iface,
417 uint64_t mgmt_event_mask,
418 uint64_t *raised_event,
419 const void **info,
420 size_t *info_length,
421 k_timeout_t timeout)
422{
423 ARG_UNUSED(iface);
424 ARG_UNUSED(mgmt_event_mask);
425 ARG_UNUSED(raised_event);
426 ARG_UNUSED(info);
427 ARG_UNUSED(info_length);
428 ARG_UNUSED(timeout);
429 return 0;
430}
431#endif
432
437#ifdef CONFIG_NET_MGMT_EVENT
439#else
440#define net_mgmt_event_init(...)
441#endif /* CONFIG_NET_MGMT_EVENT */
442
446
447#ifdef __cplusplus
448}
449#endif
450
451#endif /* ZEPHYR_INCLUDE_NET_NET_MGMT_H_ */
void(* net_mgmt_event_handler_t)(struct net_mgmt_event_callback *cb, uint64_t mgmt_event, struct net_if *iface)
Define the user's callback handler function signature.
Definition net_mgmt.h:154
int net_mgmt_event_wait_on_iface(struct net_if *iface, uint64_t mgmt_event_mask, uint64_t *raised_event, const void **info, size_t *info_length, k_timeout_t timeout)
Used to wait synchronously on an event mask for a specific iface.
void net_mgmt_del_event_callback(struct net_mgmt_event_callback *cb)
Delete a user callback.
static void net_mgmt_init_event_callback(struct net_mgmt_event_callback *cb, net_mgmt_event_handler_t handler, uint64_t mgmt_event_mask)
Helper to initialize a struct net_mgmt_event_callback properly.
Definition net_mgmt.h:262
net_mgmt_layer_code
Central place the definition of the layer codes (7 bit value).
Definition net_mgmt.h:71
void net_mgmt_event_notify_with_info(uint64_t mgmt_event, struct net_if *iface, const void *info, size_t length)
Used by the system to notify an event.
int net_mgmt_event_wait(uint64_t mgmt_event_mask, uint64_t *raised_event, struct net_if **iface, const void **info, size_t *info_length, k_timeout_t timeout)
Used to wait synchronously on an event mask.
int(* net_mgmt_request_handler_t)(uint64_t mgmt_request, struct net_if *iface, void *data, size_t len)
Signature which all Net MGMT request handler need to follow.
Definition net_mgmt.h:110
void net_mgmt_event_init(void)
Used by the core of the network stack to initialize the network event processing.
static void net_mgmt_event_notify(uint64_t mgmt_event, struct net_if *iface)
Used by the system to notify an event without any additional information.
Definition net_mgmt.h:330
void net_mgmt_add_event_callback(struct net_mgmt_event_callback *cb)
Add a user callback.
void(* net_mgmt_event_static_handler_t)(uint64_t mgmt_event, struct net_if *iface, void *info, size_t info_length, void *user_data)
Define the user's callback handler function signature.
Definition net_mgmt.h:218
@ NET_MGMT_LAYER_CODE_HOSTAP
Hostap (wpa_supplicant) layer code.
Definition net_mgmt.h:80
@ NET_MGMT_LAYER_CODE_USER1
User layer code 1.
Definition net_mgmt.h:91
@ NET_MGMT_LAYER_CODE_IPV4
IPv4 layer code.
Definition net_mgmt.h:75
@ NET_MGMT_LAYER_CODE_IFACE
Network interface layer code.
Definition net_mgmt.h:73
@ NET_MGMT_LAYER_CODE_UNKNOWN
Unknown layer code, do not use.
Definition net_mgmt.h:72
@ NET_MGMT_LAYER_CODE_STATS
Statistics layer code.
Definition net_mgmt.h:79
@ NET_MGMT_LAYER_CODE_IEEE802514
IEEE 802.15.4 layer code.
Definition net_mgmt.h:82
@ NET_MGMT_LAYER_CODE_USER3
User layer code 3.
Definition net_mgmt.h:89
@ NET_MGMT_LAYER_CODE_PPP
PPP layer code.
Definition net_mgmt.h:83
@ NET_MGMT_LAYER_CODE_COAP
CoAP layer code.
Definition net_mgmt.h:78
@ NET_MGMT_LAYER_CODE_WIFI
Wi-Fi layer code.
Definition net_mgmt.h:85
@ NET_MGMT_LAYER_CODE_IPV6
IPv6 layer code.
Definition net_mgmt.h:76
@ NET_MGMT_LAYER_CODE_PACKET
Packet (L2) layer code.
Definition net_mgmt.h:86
@ NET_MGMT_LAYER_CODE_USER2
User layer code 2.
Definition net_mgmt.h:90
@ NET_MGMT_LAYER_CODE_L4
L4 layer code.
Definition net_mgmt.h:77
@ NET_MGMT_LAYER_CODE_CONN
Connectivity layer code.
Definition net_mgmt.h:74
@ NET_MGMT_LAYER_CODE_VIRTUAL
Virtual network interface layer code.
Definition net_mgmt.h:84
@ NET_MGMT_LAYER_CODE_RESERVED
Reserved layer code for future use.
Definition net_mgmt.h:94
@ NET_MGMT_LAYER_CODE_ETHERNET
Ethernet layer code.
Definition net_mgmt.h:81
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:44
Network core definitions.
Network Events code public header.
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
Semaphore structure.
Definition kernel.h:3807
Kernel timeout type.
Definition clock.h:65
Network Interface structure.
Definition net_if.h:764
Network Management event callback structure Used to register a callback into the network management e...
Definition net_mgmt.h:164
sys_snode_t node
Meant to be used internally, to insert the callback into a list.
Definition net_mgmt.h:168
uint64_t raised_event
Internal place holder when a synchronous event wait is successfully unlocked on a event.
Definition net_mgmt.h:203
struct k_sem * sync_call
Semaphore meant to be used internally for the synchronous net_mgmt_event_wait() function.
Definition net_mgmt.h:177
uint64_t event_mask
A mask of network events on which the above handler should be called in case those events come.
Definition net_mgmt.h:199
net_mgmt_event_handler_t handler
Actual callback function being used to notify the owner.
Definition net_mgmt.h:173
Iterable sections helpers.