From c4771c4c5dbbe9db5941d7885c7864a4bafb4567 Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Thu, 15 Aug 2019 13:15:20 -0700 Subject: [PATCH] station: introduce station_network_foreach Iterates all networks for a given station object. --- src/station.c | 25 +++++++++++++++++++++++++ src/station.h | 5 +++++ 2 files changed, 30 insertions(+) diff --git a/src/station.c b/src/station.c index 2762a117..98b4b721 100644 --- a/src/station.c +++ b/src/station.c @@ -2932,6 +2932,31 @@ struct station *station_find(uint32_t ifindex) return NULL; } +struct network_foreach_data { + station_network_foreach_func_t func; + void *user_data; +}; + +static void network_foreach(const void *key, void *value, void *user_data) +{ + struct network_foreach_data *data = user_data; + struct network *network = value; + + data->func(network, data->user_data); +} + +void station_network_foreach(struct station *station, + station_network_foreach_func_t func, + void *user_data) +{ + struct network_foreach_data data = { + .func = func, + .user_data = user_data, + }; + + l_hashmap_foreach(station->networks, network_foreach, &data); +} + static struct station *station_create(struct netdev *netdev) { struct station *station; diff --git a/src/station.h b/src/station.h index e48d38c1..24ce8e3b 100644 --- a/src/station.h +++ b/src/station.h @@ -46,6 +46,7 @@ enum station_state { typedef void (*station_foreach_func_t)(struct station *, void *data); typedef void (*station_state_watch_func_t)(enum station_state, void *userdata); typedef void (*station_destroy_func_t)(void *userdata); +typedef void (*station_network_foreach_func_t)(struct network *, void *data); struct wiphy *station_get_wiphy(struct station *station); struct netdev *station_get_netdev(struct station *station); @@ -80,3 +81,7 @@ int station_disconnect(struct station *station); struct station *station_find(uint32_t ifindex); void station_foreach(station_foreach_func_t func, void *user_data); + +void station_network_foreach(struct station *station, + station_network_foreach_func_t func, + void *user_data);