Skip to content
Permalink
Browse files

net: mgmt: Add info length to event wait API

The info parameter is difficult to use if the caller does not
get information how long the info struct is. So add info_length
parameter to net_mgmt_event_wait_on_iface() and
net_mgmt_event_wait() APIs.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
  • Loading branch information...
jukkar authored and andrewboie committed Jun 11, 2019
1 parent f3f3dc8 commit 02b3826fa07928d8c52e30e5b5ec9b36c12fe6c0
Showing with 24 additions and 4 deletions.
  1. +9 −0 include/net/net_mgmt.h
  2. +13 −2 subsys/net/ip/net_mgmt.c
  3. +2 −2 tests/net/mgmt/src/mgmt.c
@@ -140,6 +140,7 @@ struct net_mgmt_event_callback {

#ifdef CONFIG_NET_MGMT_EVENT_INFO
const void *info;
size_t info_length;
#endif

/** A mask of network events on which the above handler should be
@@ -242,6 +243,8 @@ static inline void net_mgmt_event_notify(u32_t mgmt_event, struct net_if *iface)
* the caller wants to listen to.
* @param info a valid pointer if user wants to get the information the
* event might bring along. NULL otherwise.
* @param info_length tells how long the info memory area is. Only valid if
* the info is not NULL.
* @param timeout a delay in milliseconds. K_FOREVER can be used to wait
* indefinitely.
*
@@ -254,12 +257,14 @@ int net_mgmt_event_wait(u32_t mgmt_event_mask,
u32_t *raised_event,
struct net_if **iface,
const void **info,
size_t *info_length,
int timeout);
#else
static inline int net_mgmt_event_wait(u32_t mgmt_event_mask,
u32_t *raised_event,
struct net_if **iface,
const void **info,
size_t *info_length,
int timeout)
{
return 0;
@@ -277,6 +282,8 @@ static inline int net_mgmt_event_wait(u32_t mgmt_event_mask,
* interested in that information.
* @param info a valid pointer if user wants to get the information the
* event might bring along. NULL otherwise.
* @param info_length tells how long the info memory area is. Only valid if
* the info is not NULL.
* @param timeout a delay in milliseconds. K_FOREVER can be used to wait
* indefinitely.
*
@@ -289,12 +296,14 @@ int net_mgmt_event_wait_on_iface(struct net_if *iface,
u32_t mgmt_event_mask,
u32_t *raised_event,
const void **info,
size_t *info_length,
int timeout);
#else
static inline int net_mgmt_event_wait_on_iface(struct net_if *iface,
u32_t mgmt_event_mask,
u32_t *raised_event,
const void **info,
size_t *info_length,
int timeout)
{
return 0;
@@ -181,8 +181,10 @@ static inline void mgmt_run_callbacks(struct mgmt_event_entry *mgmt_event)
#ifdef CONFIG_NET_MGMT_EVENT_INFO
if (mgmt_event->info_length) {
cb->info = (void *)mgmt_event->info;
cb->info_length = mgmt_event->info_length;
} else {
cb->info = NULL;
cb->info_length = 0;
}
#endif /* CONFIG_NET_MGMT_EVENT_INFO */

@@ -260,6 +262,7 @@ static int mgmt_event_wait_call(struct net_if *iface,
u32_t *raised_event,
struct net_if **event_iface,
const void **info,
size_t *info_length,
int timeout)
{
struct mgmt_event_wait sync_data = {
@@ -295,6 +298,10 @@ static int mgmt_event_wait_call(struct net_if *iface,
#ifdef CONFIG_NET_MGMT_EVENT_INFO
if (info) {
*info = sync.info;

if (info_length) {
*info_length = sync.info_length;
}
}
#endif /* CONFIG_NET_MGMT_EVENT_INFO */
}
@@ -347,23 +354,27 @@ int net_mgmt_event_wait(u32_t mgmt_event_mask,
u32_t *raised_event,
struct net_if **iface,
const void **info,
size_t *info_length,
int timeout)
{
return mgmt_event_wait_call(NULL, mgmt_event_mask,
raised_event, iface, info, timeout);
raised_event, iface, info, info_length,
timeout);
}

int net_mgmt_event_wait_on_iface(struct net_if *iface,
u32_t mgmt_event_mask,
u32_t *raised_event,
const void **info,
size_t *info_length,
int timeout)
{
NET_ASSERT(NET_MGMT_ON_IFACE(mgmt_event_mask));
NET_ASSERT(iface);

return mgmt_event_wait_call(iface, mgmt_event_mask,
raised_event, NULL, info, timeout);
raised_event, NULL, info, info_length,
timeout);
}

void net_mgmt_event_init(void)
@@ -201,9 +201,9 @@ static int test_synchronous_event_listener(u32_t times, bool on_iface)
if (on_iface) {
ret = net_mgmt_event_wait_on_iface(net_if_get_default(),
event_mask, NULL, NULL,
K_SECONDS(1));
NULL, K_SECONDS(1));
} else {
ret = net_mgmt_event_wait(event_mask, NULL, NULL, NULL,
ret = net_mgmt_event_wait(event_mask, NULL, NULL, NULL, NULL,
K_SECONDS(1));
}

0 comments on commit 02b3826

Please sign in to comment.
You can’t perform that action at this time.