Add shared periodic cleanup function for AP mode
authorJouni Malinen <jouni@qca.qualcomm.com>
Mon, 20 Jul 2015 10:33:30 +0000 (13:33 +0300)
committerJouni Malinen <j@w1.fi>
Mon, 20 Jul 2015 10:33:30 +0000 (13:33 +0300)
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 <jouni@qca.qualcomm.com>
hostapd/main.c
src/ap/hostapd.c
src/ap/hostapd.h
wpa_supplicant/ap.c
wpa_supplicant/ap.h
wpa_supplicant/wpa_supplicant.c

index 534f182..6c7406a 100644 (file)
@@ -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);
 
index bcd6ce0..5135d3e 100644 (file)
@@ -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)
+{
+}
index 38b35e5..d28a02a 100644 (file)
@@ -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,
index aaea524..ce09c57 100644 (file)
@@ -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);
+}
index 3f4151d..594168c 100644 (file)
@@ -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 */
index ac46ef7..3b107a1 100644 (file)
@@ -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 */
+       }
 }