Merge driver ops set_wps_beacon_ie and set_wps_probe_resp_ie
[libeap.git] / hostapd / main.c
index 4f40356..164c214 100644 (file)
 #endif /* CONFIG_NATIVE_WINDOWS */
 
 #include "common.h"
-#include "hostapd.h"
 #include "eloop.h"
+#include "crypto/tls.h"
 #include "common/version.h"
-#include "config.h"
-#include "tls.h"
 #include "eap_server/eap.h"
 #include "eap_server/tncs.h"
+#include "hostapd.h"
+#include "config.h"
 
 
 extern int wpa_debug_level;
@@ -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)
@@ -249,7 +251,7 @@ static struct hostapd_iface * hostapd_interface_init(const char *config_fname,
 /**
  * handle_term - SIGINT and SIGTERM handler to terminate hostapd process
  */
-static void handle_term(int sig, void *eloop_ctx, void *signal_ctx)
+static void handle_term(int sig, void *signal_ctx)
 {
        wpa_printf(MSG_DEBUG, "Signal %d received - terminating", sig);
        eloop_terminate();
@@ -260,18 +262,20 @@ static void handle_term(int sig, void *eloop_ctx, void *signal_ctx)
 /**
  * handle_reload - SIGHUP handler to reload configuration
  */
-static void handle_reload(int sig, void *eloop_ctx, void *signal_ctx)
+static void handle_reload(int sig, void *signal_ctx)
 {
+       struct hapd_interfaces *interfaces = signal_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)
+static void handle_dump_state(int sig, void *signal_ctx)
 {
 #ifdef HOSTAPD_DUMP_STATE
-       hostapd_for_each_interface(handle_dump_state_iface, NULL);
+       struct hapd_interfaces *interfaces = signal_ctx;
+       hostapd_for_each_interface(interfaces, handle_dump_state_iface, NULL);
 #endif /* HOSTAPD_DUMP_STATE */
 }
 #endif /* CONFIG_NATIVE_WINDOWS */
@@ -286,16 +290,16 @@ static int hostapd_global_init(struct hapd_interfaces *interfaces)
                return -1;
        }
 
-       if (eloop_init(interfaces)) {
+       if (eloop_init()) {
                wpa_printf(MSG_ERROR, "Failed to initialize event loop");
                return -1;
        }
 
 #ifndef CONFIG_NATIVE_WINDOWS
-       eloop_register_signal(SIGHUP, handle_reload, NULL);
-       eloop_register_signal(SIGUSR1, handle_dump_state, NULL);
+       eloop_register_signal(SIGHUP, handle_reload, interfaces);
+       eloop_register_signal(SIGUSR1, handle_dump_state, interfaces);
 #endif /* CONFIG_NATIVE_WINDOWS */
-       eloop_register_signal_terminate(handle_term, NULL);
+       eloop_register_signal_terminate(handle_term, interfaces);
 
 #ifndef CONFIG_NATIVE_WINDOWS
        openlog("hostapd", 0, LOG_DAEMON);
@@ -396,6 +400,9 @@ int main(int argc, char *argv[])
        int c, debug = 0, daemonize = 0;
        char *pid_file = NULL;
 
+       if (os_program_init())
+               return -1;
+
        for (;;) {
                c = getopt(argc, argv, "BdhKP:tv");
                if (c < 0)
@@ -449,7 +456,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;
@@ -469,5 +477,7 @@ int main(int argc, char *argv[])
        hostapd_global_deinit(pid_file);
        os_free(pid_file);
 
+       os_program_deinit();
+
        return ret;
 }