Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
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 <sys/__assert.h>
16#include <net/net_core.h>
17#include <net/net_event.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
30struct net_if;
31
36#define NET_MGMT_EVENT_MASK 0x80000000
37#define NET_MGMT_ON_IFACE_MASK 0x40000000
38#define NET_MGMT_LAYER_MASK 0x30000000
39#define NET_MGMT_SYNC_EVENT_MASK 0x08000000
40#define NET_MGMT_LAYER_CODE_MASK 0x07FF0000
41#define NET_MGMT_COMMAND_MASK 0x0000FFFF
42
43#define NET_MGMT_EVENT_BIT BIT(31)
44#define NET_MGMT_IFACE_BIT BIT(30)
45#define NET_MGMT_SYNC_EVENT_BIT BIT(27)
46
47#define NET_MGMT_LAYER(_layer) (_layer << 28)
48#define NET_MGMT_LAYER_CODE(_code) (_code << 16)
49
50#define NET_MGMT_EVENT(mgmt_request) \
51 (mgmt_request & NET_MGMT_EVENT_MASK)
52
53#define NET_MGMT_ON_IFACE(mgmt_request) \
54 (mgmt_request & NET_MGMT_ON_IFACE_MASK)
55
56#define NET_MGMT_EVENT_SYNCHRONOUS(mgmt_request) \
57 (mgmt_request & NET_MGMT_SYNC_EVENT_MASK)
58
59#define NET_MGMT_GET_LAYER(mgmt_request) \
60 ((mgmt_request & NET_MGMT_LAYER_MASK) >> 28)
61
62#define NET_MGMT_GET_LAYER_CODE(mgmt_request) \
63 ((mgmt_request & NET_MGMT_LAYER_CODE_MASK) >> 16)
64
65#define NET_MGMT_GET_COMMAND(mgmt_request) \
66 (mgmt_request & NET_MGMT_COMMAND_MASK)
67
68
69/* Useful generic definitions */
70#define NET_MGMT_LAYER_L2 1
71#define NET_MGMT_LAYER_L3 2
72#define NET_MGMT_LAYER_L4 3
73
88typedef int (*net_mgmt_request_handler_t)(uint32_t mgmt_request,
89 struct net_if *iface,
90 void *data, size_t len);
91
92#define net_mgmt(_mgmt_request, _iface, _data, _len) \
93 net_mgmt_##_mgmt_request(_mgmt_request, _iface, _data, _len)
94
95#define NET_MGMT_DEFINE_REQUEST_HANDLER(_mgmt_request) \
96 extern int net_mgmt_##_mgmt_request(uint32_t mgmt_request, \
97 struct net_if *iface, \
98 void *data, size_t len)
99
100#define NET_MGMT_REGISTER_REQUEST_HANDLER(_mgmt_request, _func) \
101 FUNC_ALIAS(_func, net_mgmt_##_mgmt_request, int)
102
104
114 uint32_t mgmt_event,
115 struct net_if *iface);
116
128
129 union {
136 struct k_sem *sync_call;
137 };
138
139#ifdef CONFIG_NET_MGMT_EVENT_INFO
140 const void *info;
141 size_t info_length;
142#endif
143
149 union {
163 };
164};
165
172#ifdef CONFIG_NET_MGMT_EVENT
173static inline
176 uint32_t mgmt_event_mask)
177{
178 __ASSERT(cb, "Callback pointer should not be NULL");
179 __ASSERT(handler, "Handler pointer should not be NULL");
180
181 cb->handler = handler;
182 cb->event_mask = mgmt_event_mask;
183};
184#else
185#define net_mgmt_init_event_callback(...)
186#endif
187
192#ifdef CONFIG_NET_MGMT_EVENT
194#else
195#define net_mgmt_add_event_callback(...)
196#endif
197
202#ifdef CONFIG_NET_MGMT_EVENT
204#else
205#define net_mgmt_del_event_callback(...)
206#endif
207
221#ifdef CONFIG_NET_MGMT_EVENT
222void net_mgmt_event_notify_with_info(uint32_t mgmt_event, struct net_if *iface,
223 const void *info, size_t length);
224
225static inline void net_mgmt_event_notify(uint32_t mgmt_event,
226 struct net_if *iface)
227{
228 net_mgmt_event_notify_with_info(mgmt_event, iface, NULL, 0);
229}
230#else
231#define net_mgmt_event_notify(...)
232#define net_mgmt_event_notify_with_info(...)
233#endif
234
255#ifdef CONFIG_NET_MGMT_EVENT
256int net_mgmt_event_wait(uint32_t mgmt_event_mask,
257 uint32_t *raised_event,
258 struct net_if **iface,
259 const void **info,
260 size_t *info_length,
262#else
263static inline int net_mgmt_event_wait(uint32_t mgmt_event_mask,
264 uint32_t *raised_event,
265 struct net_if **iface,
266 const void **info,
267 size_t *info_length,
269{
270 return 0;
271}
272#endif
273
293#ifdef CONFIG_NET_MGMT_EVENT
295 uint32_t mgmt_event_mask,
296 uint32_t *raised_event,
297 const void **info,
298 size_t *info_length,
300#else
301static inline int net_mgmt_event_wait_on_iface(struct net_if *iface,
302 uint32_t mgmt_event_mask,
303 uint32_t *raised_event,
304 const void **info,
305 size_t *info_length,
307{
308 return 0;
309}
310#endif
311
316#ifdef CONFIG_NET_MGMT_EVENT
318#else
319#define net_mgmt_event_init(...)
320#endif /* CONFIG_NET_MGMT_EVENT */
321
326#ifdef __cplusplus
327}
328#endif
329
330#endif /* ZEPHYR_INCLUDE_NET_NET_MGMT_H_ */
ZTEST_BMEM int timeout
Definition: main.c:31
void
Definition: eswifi_shell.c:15
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:113
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)
Definition: net_mgmt.h:225
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:174
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:88
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_add_event_callback(struct net_mgmt_event_callback *cb)
Add a user callback.
Network core definitions.
Network Events code public header.
struct _snode sys_snode_t
Definition: slist.h:33
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
Kernel timeout type.
Definition: sys_clock.h:65
Network Interface structure.
Definition: net_if.h:468
Network Management event callback structure Used to register a callback into the network management e...
Definition: net_mgmt.h:123
sys_snode_t node
Definition: net_mgmt.h:127
struct k_sem * sync_call
Definition: net_mgmt.h:136
uint32_t raised_event
Definition: net_mgmt.h:162
uint32_t event_mask
Definition: net_mgmt.h:158
net_mgmt_event_handler_t handler
Definition: net_mgmt.h:132
static fdata_t data[2]
Definition: test_fifo_contexts.c:15
static void handler(struct k_timer *timer)
Definition: main.c:19