Zephyr API Documentation  3.7.0-rc1
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
31struct net_if;
32
37#define NET_MGMT_EVENT_MASK 0x80000000
38#define NET_MGMT_ON_IFACE_MASK 0x40000000
39#define NET_MGMT_LAYER_MASK 0x30000000
40#define NET_MGMT_SYNC_EVENT_MASK 0x08000000
41#define NET_MGMT_LAYER_CODE_MASK 0x07FF0000
42#define NET_MGMT_COMMAND_MASK 0x0000FFFF
43
44#define NET_MGMT_EVENT_BIT BIT(31)
45#define NET_MGMT_IFACE_BIT BIT(30)
46#define NET_MGMT_SYNC_EVENT_BIT BIT(27)
47
48#define NET_MGMT_LAYER(_layer) (_layer << 28)
49#define NET_MGMT_LAYER_CODE(_code) (_code << 16)
50
51#define NET_MGMT_EVENT(mgmt_request) \
52 (mgmt_request & NET_MGMT_EVENT_MASK)
53
54#define NET_MGMT_ON_IFACE(mgmt_request) \
55 (mgmt_request & NET_MGMT_ON_IFACE_MASK)
56
57#define NET_MGMT_EVENT_SYNCHRONOUS(mgmt_request) \
58 (mgmt_request & NET_MGMT_SYNC_EVENT_MASK)
59
60#define NET_MGMT_GET_LAYER(mgmt_request) \
61 ((mgmt_request & NET_MGMT_LAYER_MASK) >> 28)
62
63#define NET_MGMT_GET_LAYER_CODE(mgmt_request) \
64 ((mgmt_request & NET_MGMT_LAYER_CODE_MASK) >> 16)
65
66#define NET_MGMT_GET_COMMAND(mgmt_request) \
67 (mgmt_request & NET_MGMT_COMMAND_MASK)
68
69
70/* Useful generic definitions */
71#define NET_MGMT_LAYER_L2 1
72#define NET_MGMT_LAYER_L3 2
73#define NET_MGMT_LAYER_L4 3
74
89typedef int (*net_mgmt_request_handler_t)(uint32_t mgmt_request,
90 struct net_if *iface,
91 void *data, size_t len);
92
101#define net_mgmt(_mgmt_request, _iface, _data, _len) \
102 net_mgmt_##_mgmt_request(_mgmt_request, _iface, _data, _len)
103
109#define NET_MGMT_DEFINE_REQUEST_HANDLER(_mgmt_request) \
110 extern int net_mgmt_##_mgmt_request(uint32_t mgmt_request, \
111 struct net_if *iface, \
112 void *data, size_t len)
113
120#define NET_MGMT_REGISTER_REQUEST_HANDLER(_mgmt_request, _func) \
121 FUNC_ALIAS(_func, net_mgmt_##_mgmt_request, int)
122
124
134 uint32_t mgmt_event,
135 struct net_if *iface);
136
148
149 union {
156 struct k_sem *sync_call;
157 };
158
159#ifdef CONFIG_NET_MGMT_EVENT_INFO
160 const void *info;
161 size_t info_length;
162#endif
163
169 union {
183 };
184};
185
197typedef void (*net_mgmt_event_static_handler_t)(uint32_t mgmt_event,
198 struct net_if *iface,
199 void *info, size_t info_length,
200 void *user_data);
201
204/* Structure for event handler registered at compile time */
205struct net_mgmt_event_static_handler {
206 uint32_t event_mask;
208 void *user_data;
209};
210
226#define NET_MGMT_REGISTER_EVENT_HANDLER(_name, _event_mask, _func, _user_data) \
227 const STRUCT_SECTION_ITERABLE(net_mgmt_event_static_handler, _name) = { \
228 .event_mask = _event_mask, \
229 .handler = _func, \
230 .user_data = (void *)_user_data, \
231 }
232
239#ifdef CONFIG_NET_MGMT_EVENT
240static inline
243 uint32_t mgmt_event_mask)
244{
245 __ASSERT(cb, "Callback pointer should not be NULL");
246 __ASSERT(handler, "Handler pointer should not be NULL");
247
248 cb->handler = handler;
249 cb->event_mask = mgmt_event_mask;
250};
251#else
252#define net_mgmt_init_event_callback(...)
253#endif
254
259#ifdef CONFIG_NET_MGMT_EVENT
261#else
262#define net_mgmt_add_event_callback(...)
263#endif
264
269#ifdef CONFIG_NET_MGMT_EVENT
271#else
272#define net_mgmt_del_event_callback(...)
273#endif
274
288#if defined(CONFIG_NET_MGMT_EVENT)
289void net_mgmt_event_notify_with_info(uint32_t mgmt_event, struct net_if *iface,
290 const void *info, size_t length);
291#else
292#define net_mgmt_event_notify_with_info(...)
293#endif
294
301#if defined(CONFIG_NET_MGMT_EVENT)
302static inline void net_mgmt_event_notify(uint32_t mgmt_event,
303 struct net_if *iface)
304{
305 net_mgmt_event_notify_with_info(mgmt_event, iface, NULL, 0);
306}
307#else
308#define net_mgmt_event_notify(...)
309#endif
310
331#ifdef CONFIG_NET_MGMT_EVENT
332int net_mgmt_event_wait(uint32_t mgmt_event_mask,
333 uint32_t *raised_event,
334 struct net_if **iface,
335 const void **info,
336 size_t *info_length,
337 k_timeout_t timeout);
338#else
339static inline int net_mgmt_event_wait(uint32_t mgmt_event_mask,
340 uint32_t *raised_event,
341 struct net_if **iface,
342 const void **info,
343 size_t *info_length,
344 k_timeout_t timeout)
345{
346 return 0;
347}
348#endif
349
369#ifdef CONFIG_NET_MGMT_EVENT
371 uint32_t mgmt_event_mask,
372 uint32_t *raised_event,
373 const void **info,
374 size_t *info_length,
375 k_timeout_t timeout);
376#else
377static inline int net_mgmt_event_wait_on_iface(struct net_if *iface,
378 uint32_t mgmt_event_mask,
379 uint32_t *raised_event,
380 const void **info,
381 size_t *info_length,
382 k_timeout_t timeout)
383{
384 return 0;
385}
386#endif
387
392#ifdef CONFIG_NET_MGMT_EVENT
394#else
395#define net_mgmt_event_init(...)
396#endif /* CONFIG_NET_MGMT_EVENT */
397
402#ifdef __cplusplus
403}
404#endif
405
406#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:133
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:302
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:241
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:89
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:197
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:678
Network Management event callback structure Used to register a callback into the network management e...
Definition: net_mgmt.h:143
sys_snode_t node
Meant to be used internally, to insert the callback into a list.
Definition: net_mgmt.h:147
struct k_sem * sync_call
Semaphore meant to be used internally for the synchronous net_mgmt_event_wait() function.
Definition: net_mgmt.h:156
uint32_t raised_event
Internal place holder when a synchronous event wait is successfully unlocked on a event.
Definition: net_mgmt.h:182
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:178
net_mgmt_event_handler_t handler
Actual callback function being used to notify the owner.
Definition: net_mgmt.h:152