From 9969e5a46a4671a6c75dfc6c2952296e170bf50b Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sat, 19 Dec 2009 19:07:31 +0200 Subject: [PATCH] Make hostapd_for_each_interface() take context pointer as argument This removes need for using eloop_get_user_data(). --- hostapd/drv_callbacks.c | 3 ++- hostapd/hostapd.c | 4 +++- hostapd/hostapd.h | 5 ++++- hostapd/main.c | 19 ++++++++++++------- wpa_supplicant/ap.c | 9 ++++++++- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/hostapd/drv_callbacks.c b/hostapd/drv_callbacks.c index 29c86c85c..e1a7e4c01 100644 --- a/hostapd/drv_callbacks.c +++ b/hostapd/drv_callbacks.c @@ -69,7 +69,8 @@ static void hostapd_prune_associations(struct hostapd_data *hapd, struct prune_data data; data.hapd = hapd; data.addr = sta->addr; - hostapd_for_each_interface(prune_associations, &data); + hostapd_for_each_interface(hapd->iface->interfaces, + prune_associations, &data); } diff --git a/hostapd/hostapd.c b/hostapd/hostapd.c index 701703c7e..f3d1e4cb6 100644 --- a/hostapd/hostapd.c +++ b/hostapd/hostapd.c @@ -660,10 +660,12 @@ static int hostapd_wpa_auth_for_each_auth( void *ctx, int (*cb)(struct wpa_authenticator *sm, void *ctx), void *cb_ctx) { + struct hostapd_data *hapd = ctx; struct wpa_auth_iface_iter_data data; data.cb = cb; data.cb_ctx = cb_ctx; - return hostapd_for_each_interface(wpa_auth_iface_iter, &data); + return hostapd_for_each_interface(hapd->iface->interfaces, + wpa_auth_iface_iter, &data); } diff --git a/hostapd/hostapd.h b/hostapd/hostapd.h index e6d564ca7..c9ee3ddc5 100644 --- a/hostapd/hostapd.h +++ b/hostapd/hostapd.h @@ -21,6 +21,7 @@ struct wpa_driver_ops; struct wpa_ctrl_dst; struct radius_server_data; struct upnp_wps_device_sm; +struct hapd_interfaces; #ifdef CONFIG_FULL_DYNAMIC_VLAN struct full_dynamic_vlan; @@ -119,6 +120,7 @@ struct hostapd_data { * struct hostapd_iface - hostapd per-interface data structure */ struct hostapd_iface { + struct hapd_interfaces *interfaces; void *owner; char *config_fname; struct hostapd_config *conf; @@ -180,7 +182,8 @@ void hostapd_interface_deinit(struct hostapd_iface *iface); int handle_reload_iface(struct hostapd_iface *iface, void *ctx); int handle_dump_state_iface(struct hostapd_iface *iface, void *ctx); -int hostapd_for_each_interface(int (*cb)(struct hostapd_iface *iface, +int hostapd_for_each_interface(struct hapd_interfaces *interfaces, + int (*cb)(struct hostapd_iface *iface, void *ctx), void *ctx); int hostapd_register_probereq_cb(struct hostapd_data *hapd, diff --git a/hostapd/main.c b/hostapd/main.c index 20efca092..689248367 100644 --- a/hostapd/main.c +++ b/hostapd/main.c @@ -38,10 +38,10 @@ struct hapd_interfaces { }; -int hostapd_for_each_interface(int (*cb)(struct hostapd_iface *iface, +int hostapd_for_each_interface(struct hapd_interfaces *interfaces, + int (*cb)(struct hostapd_iface *iface, void *ctx), void *ctx) { - struct hapd_interfaces *interfaces = eloop_get_user_data(); size_t i; int ret; @@ -221,8 +221,9 @@ fail: } -static struct hostapd_iface * hostapd_interface_init(const char *config_fname, - int debug) +static struct hostapd_iface * +hostapd_interface_init(struct hapd_interfaces *interfaces, + const char *config_fname, int debug) { struct hostapd_iface *iface; int k; @@ -231,6 +232,7 @@ static struct hostapd_iface * hostapd_interface_init(const char *config_fname, iface = hostapd_init(config_fname); if (!iface) return NULL; + iface->interfaces = interfaces; for (k = 0; k < debug; k++) { if (iface->bss[0]->conf->logger_stdout_level > 0) @@ -262,16 +264,18 @@ static void handle_term(int sig, void *eloop_ctx, void *signal_ctx) */ static void handle_reload(int sig, void *eloop_ctx, void *signal_ctx) { + struct hapd_interfaces *interfaces = eloop_ctx; wpa_printf(MSG_DEBUG, "Signal %d received - reloading configuration", sig); - hostapd_for_each_interface(handle_reload_iface, NULL); + hostapd_for_each_interface(interfaces, handle_reload_iface, NULL); } static void handle_dump_state(int sig, void *eloop_ctx, void *signal_ctx) { #ifdef HOSTAPD_DUMP_STATE - hostapd_for_each_interface(handle_dump_state_iface, NULL); + struct hapd_interfaces *interfaces = eloop_ctx; + hostapd_for_each_interface(interfaces, handle_dump_state_iface, NULL); #endif /* HOSTAPD_DUMP_STATE */ } #endif /* CONFIG_NATIVE_WINDOWS */ @@ -449,7 +453,8 @@ int main(int argc, char *argv[]) /* Initialize interfaces */ for (i = 0; i < interfaces.count; i++) { - interfaces.iface[i] = hostapd_interface_init(argv[optind + i], + interfaces.iface[i] = hostapd_interface_init(&interfaces, + argv[optind + i], debug); if (!interfaces.iface[i]) goto out; diff --git a/wpa_supplicant/ap.c b/wpa_supplicant/ap.c index 9dbe719a3..cf681938b 100644 --- a/wpa_supplicant/ap.c +++ b/wpa_supplicant/ap.c @@ -33,7 +33,14 @@ #include "ap.h" -int hostapd_for_each_interface(int (*cb)(struct hostapd_iface *iface, +struct hapd_interfaces { + size_t count; + struct hostapd_iface **iface; +}; + + +int hostapd_for_each_interface(struct hapd_interfaces *interfaces, + int (*cb)(struct hostapd_iface *iface, void *ctx), void *ctx) { /* TODO */