Zephyr Project API 4.0.0
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
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>
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
33struct net_if;
34
39#define NET_MGMT_EVENT_MASK 0x80000000
40#define NET_MGMT_ON_IFACE_MASK 0x40000000
41#define NET_MGMT_LAYER_MASK 0x30000000
42#define NET_MGMT_SYNC_EVENT_MASK 0x08000000
43#define NET_MGMT_LAYER_CODE_MASK 0x07FF0000
44#define NET_MGMT_COMMAND_MASK 0x0000FFFF
45
46#define NET_MGMT_EVENT_BIT BIT(31)
47#define NET_MGMT_IFACE_BIT BIT(30)
48#define NET_MGMT_SYNC_EVENT_BIT BIT(27)
49
50#define NET_MGMT_LAYER(_layer) (_layer << 28)
51#define NET_MGMT_LAYER_CODE(_code) (_code << 16)
52
53#define NET_MGMT_EVENT(mgmt_request) \
54 (mgmt_request & NET_MGMT_EVENT_MASK)
55
56#define NET_MGMT_ON_IFACE(mgmt_request) \
57 (mgmt_request & NET_MGMT_ON_IFACE_MASK)
58
59#define NET_MGMT_EVENT_SYNCHRONOUS(mgmt_request) \
60 (mgmt_request & NET_MGMT_SYNC_EVENT_MASK)
61
62#define NET_MGMT_GET_LAYER(mgmt_request) \
63 ((mgmt_request & NET_MGMT_LAYER_MASK) >> 28)
64
65#define NET_MGMT_GET_LAYER_CODE(mgmt_request) \
66 ((mgmt_request & NET_MGMT_LAYER_CODE_MASK) >> 16)
67
68#define NET_MGMT_GET_COMMAND(mgmt_request) \
69 (mgmt_request & NET_MGMT_COMMAND_MASK)
70
71
72/* Useful generic definitions */
73#define NET_MGMT_LAYER_L2 1
74#define NET_MGMT_LAYER_L3 2
75#define NET_MGMT_LAYER_L4 3
76
91typedef int (*net_mgmt_request_handler_t)(uint32_t mgmt_request,
92 struct net_if *iface,
93 void *data, size_t len);
94
103#define net_mgmt(_mgmt_request, _iface, _data, _len) \
104 net_mgmt_##_mgmt_request(_mgmt_request, _iface, _data, _len)
105
111#define NET_MGMT_DEFINE_REQUEST_HANDLER(_mgmt_request) \
112 extern int net_mgmt_##_mgmt_request(uint32_t mgmt_request, \
113 struct net_if *iface, \
114 void *data, size_t len)
115
122#define NET_MGMT_REGISTER_REQUEST_HANDLER(_mgmt_request, _func) \
123 FUNC_ALIAS(_func, net_mgmt_##_mgmt_request, int)
124
126
136 uint32_t mgmt_event,
137 struct net_if *iface);
138
150
151 union {
158 struct k_sem *sync_call;
159 };
160
161#ifdef CONFIG_NET_MGMT_EVENT_INFO
162 const void *info;
163 size_t info_length;
164#endif
165
171 union {
185 };
186};
187
199typedef void (*net_mgmt_event_static_handler_t)(uint32_t mgmt_event,
200 struct net_if *iface,
201 void *info, size_t info_length,
202 void *user_data);
203
206/* Structure for event handler registered at compile time */
207struct net_mgmt_event_static_handler {
208 uint32_t event_mask;
210 void *user_data;
211};
212
228#define NET_MGMT_REGISTER_EVENT_HANDLER(_name, _event_mask, _func, _user_data) \
229 const STRUCT_SECTION_ITERABLE(net_mgmt_event_static_handler, _name) = { \
230 .event_mask = _event_mask, \
231 .handler = _func, \
232 .user_data = (void *)_user_data, \
233 }
234
241#ifdef CONFIG_NET_MGMT_EVENT
242static inline
245 uint32_t mgmt_event_mask)
246{
247 __ASSERT(cb, "Callback pointer should not be NULL");
248 __ASSERT(handler, "Handler pointer should not be NULL");
249
250 cb->handler = handler;
251 cb->event_mask = mgmt_event_mask;
252};
253#else
254#define net_mgmt_init_event_callback(...)
255#endif
256
261#ifdef CONFIG_NET_MGMT_EVENT
263#else
264#define net_mgmt_add_event_callback(...)
265#endif
266
271#ifdef CONFIG_NET_MGMT_EVENT
273#else
274#define net_mgmt_del_event_callback(...)
275#endif
276
290#if defined(CONFIG_NET_MGMT_EVENT)
291void net_mgmt_event_notify_with_info(uint32_t mgmt_event, struct net_if *iface,
292 const void *info, size_t length);
293#else
294#define net_mgmt_event_notify_with_info(...)
295#endif
296
303#if defined(CONFIG_NET_MGMT_EVENT)
304static inline void net_mgmt_event_notify(uint32_t mgmt_event,
305 struct net_if *iface)
306{
307 net_mgmt_event_notify_with_info(mgmt_event, iface, NULL, 0);
308}
309#else
310#define net_mgmt_event_notify(...)
311#endif
312
333#ifdef CONFIG_NET_MGMT_EVENT
334int net_mgmt_event_wait(uint32_t mgmt_event_mask,
335 uint32_t *raised_event,
336 struct net_if **iface,
337 const void **info,
338 size_t *info_length,
339 k_timeout_t timeout);
340#else
341static inline int net_mgmt_event_wait(uint32_t mgmt_event_mask,
342 uint32_t *raised_event,
343 struct net_if **iface,
344 const void **info,
345 size_t *info_length,
346 k_timeout_t timeout)
347{
348 return 0;
349}
350#endif
351
371#ifdef CONFIG_NET_MGMT_EVENT
373 uint32_t mgmt_event_mask,
374 uint32_t *raised_event,
375 const void **info,
376 size_t *info_length,
377 k_timeout_t timeout);
378#else
379static inline int net_mgmt_event_wait_on_iface(struct net_if *iface,
380 uint32_t mgmt_event_mask,
381 uint32_t *raised_event,
382 const void **info,
383 size_t *info_length,
384 k_timeout_t timeout)
385{
386 return 0;
387}
388#endif
389
394#ifdef CONFIG_NET_MGMT_EVENT
396#else
397#define net_mgmt_event_init(...)
398#endif /* CONFIG_NET_MGMT_EVENT */
399
404#ifdef __cplusplus
405}
406#endif
407
408#endif /* ZEPHYR_INCLUDE_NET_NET_MGMT_H_ */
void(* net_mgmt_event_handler_t)(struct net_mgmt_event_callback *cb, uint32_t mgmt_event, struct net_if *iface)
Define the user's callback handler function signature.
Definition net_mgmt.h:135
int net_mgmt_event_wait_on_iface(struct net_if *iface, uint32_t mgmt_event_mask, uint32_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.
static void net_mgmt_event_notify(uint32_t mgmt_event, struct net_if *iface)
Used by the system to notify an event without any additional information.
Definition net_mgmt.h:304
void net_mgmt_event_notify_with_info(uint32_t mgmt_event, struct net_if *iface, const void *info, size_t length)
Used by the system to notify an event.
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, uint32_t mgmt_event_mask)
Helper to initialize a struct net_mgmt_event_callback properly.
Definition net_mgmt.h:243
void net_mgmt_event_init(void)
Used by the core of the network stack to initialize the network event processing.
int(* net_mgmt_request_handler_t)(uint32_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:91
int net_mgmt_event_wait(uint32_t mgmt_event_mask, uint32_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.
void(* net_mgmt_event_static_handler_t)(uint32_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:199
void net_mgmt_add_event_callback(struct net_mgmt_event_callback *cb)
Add a user callback.
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:39
Network core definitions.
Network Events code public header.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Kernel timeout type.
Definition sys_clock.h:65
Network Interface structure.
Definition net_if.h:680
Network Management event callback structure Used to register a callback into the network management e...
Definition net_mgmt.h:145
sys_snode_t node
Meant to be used internally, to insert the callback into a list.
Definition net_mgmt.h:149
struct k_sem * sync_call
Semaphore meant to be used internally for the synchronous net_mgmt_event_wait() function.
Definition net_mgmt.h:158
uint32_t raised_event
Internal place holder when a synchronous event wait is successfully unlocked on a event.
Definition net_mgmt.h:184
uint32_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:180
net_mgmt_event_handler_t handler
Actual callback function being used to notify the owner.
Definition net_mgmt.h:154