From 3188aabaf1b04ac40c5baa8270cee72862568205 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Mon, 20 Jul 2015 13:33:30 +0300 Subject: [PATCH] Add shared periodic cleanup function for AP mode This new mechanism can be used to combine multiple periodic AP (including P2P GO) task into a single eloop timeout to minimize number of wakeups for the process. hostapd gets its own periodic caller and wpa_supplicant uses the previously added timer to trigger these calls. Signed-off-by: Jouni Malinen --- hostapd/main.c | 26 ++++++++++++++++++++++++++ src/ap/hostapd.c | 5 +++++ src/ap/hostapd.h | 1 + wpa_supplicant/ap.c | 7 +++++++ wpa_supplicant/ap.h | 2 ++ wpa_supplicant/wpa_supplicant.c | 6 +++++- 6 files changed, 46 insertions(+), 1 deletion(-) diff --git a/hostapd/main.c b/hostapd/main.c index 534f18235..6c7406af4 100644 --- a/hostapd/main.c +++ b/hostapd/main.c @@ -534,6 +534,28 @@ static int gen_uuid(const char *txt_addr) #endif /* CONFIG_WPS */ +#ifndef HOSTAPD_CLEANUP_INTERVAL +#define HOSTAPD_CLEANUP_INTERVAL 10 +#endif /* HOSTAPD_CLEANUP_INTERVAL */ + +static int hostapd_periodic_call(struct hostapd_iface *iface, void *ctx) +{ + hostapd_periodic_iface(iface); + return 0; +} + + +/* Periodic cleanup tasks */ +static void hostapd_periodic(void *eloop_ctx, void *timeout_ctx) +{ + struct hapd_interfaces *interfaces = eloop_ctx; + + eloop_register_timeout(HOSTAPD_CLEANUP_INTERVAL, 0, + hostapd_periodic, interfaces, NULL); + hostapd_for_each_interface(interfaces, hostapd_periodic_call, NULL); +} + + int main(int argc, char *argv[]) { struct hapd_interfaces interfaces; @@ -667,6 +689,9 @@ int main(int argc, char *argv[]) return -1; } + eloop_register_timeout(HOSTAPD_CLEANUP_INTERVAL, 0, + hostapd_periodic, &interfaces, NULL); + if (fst_global_init()) { wpa_printf(MSG_ERROR, "Failed to initialize global FST context"); @@ -762,6 +787,7 @@ int main(int argc, char *argv[]) } os_free(interfaces.iface); + eloop_cancel_timeout(hostapd_periodic, &interfaces, NULL); hostapd_global_deinit(pid_file); os_free(pid_file); diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c index bcd6ce003..5135d3e06 100644 --- a/src/ap/hostapd.c +++ b/src/ap/hostapd.c @@ -2922,3 +2922,8 @@ struct hostapd_data * hostapd_get_iface(struct hapd_interfaces *interfaces, } #endif /* NEED_AP_MLME */ + + +void hostapd_periodic_iface(struct hostapd_iface *iface) +{ +} diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h index 38b35e50e..d28a02a53 100644 --- a/src/ap/hostapd.h +++ b/src/ap/hostapd.h @@ -445,6 +445,7 @@ void hostapd_switch_channel_fallback(struct hostapd_iface *iface, const struct hostapd_freq_params *freq_params); void hostapd_cleanup_cs_params(struct hostapd_data *hapd); +void hostapd_periodic_iface(struct hostapd_iface *iface); /* utils.c */ int hostapd_register_probereq_cb(struct hostapd_data *hapd, diff --git a/wpa_supplicant/ap.c b/wpa_supplicant/ap.c index aaea52428..ce09c5763 100644 --- a/wpa_supplicant/ap.c +++ b/wpa_supplicant/ap.c @@ -1369,3 +1369,10 @@ void wpas_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s, radar->chan_width, radar->cf1, radar->cf2); } #endif /* NEED_AP_MLME */ + + +void ap_periodic(struct wpa_supplicant *wpa_s) +{ + if (wpa_s->ap_iface) + hostapd_periodic_iface(wpa_s->ap_iface); +} diff --git a/wpa_supplicant/ap.h b/wpa_supplicant/ap.h index 3f4151d8c..594168cf1 100644 --- a/wpa_supplicant/ap.h +++ b/wpa_supplicant/ap.h @@ -93,4 +93,6 @@ void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s, void wpas_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s, struct dfs_event *radar); +void ap_periodic(struct wpa_supplicant *wpa_s); + #endif /* AP_H */ diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c index ac46ef73c..3b107a192 100644 --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c @@ -4760,8 +4760,12 @@ static void wpas_periodic(void *eloop_ctx, void *timeout_ctx) p2p_expire_peers(global->p2p); #endif /* CONFIG_P2P */ - for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) + for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { wpa_bss_flush_by_age(wpa_s, wpa_s->conf->bss_expiration_age); +#ifdef CONFIG_AP + ap_periodic(wpa_s); +#endif /* CONFIG_AP */ + } }