hostapd: Make hostapd_init() available externally
authorKyeyoon Park <kyeyoonp@qca.qualcomm.com>
Tue, 29 Oct 2013 14:27:30 +0000 (16:27 +0200)
committerJouni Malinen <j@w1.fi>
Thu, 31 Oct 2013 20:00:31 +0000 (22:00 +0200)
Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>

hostapd/main.c
src/ap/hostapd.c
src/ap/hostapd.h

index 6041799..29afec9 100644 (file)
@@ -147,66 +147,6 @@ static void hostapd_logger_cb(void *ctx, const u8 *addr, unsigned int module,
 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
 
 
-/**
- * hostapd_init - Allocate and initialize per-interface data
- * @config_file: Path to the configuration file
- * Returns: Pointer to the allocated interface data or %NULL on failure
- *
- * This function is used to allocate main data structures for per-interface
- * data. The allocated data buffer will be freed by calling
- * hostapd_cleanup_iface().
- */
-static struct hostapd_iface * hostapd_init(const char *config_file)
-{
-       struct hostapd_iface *hapd_iface = NULL;
-       struct hostapd_config *conf = NULL;
-       struct hostapd_data *hapd;
-       size_t i;
-
-       hapd_iface = os_zalloc(sizeof(*hapd_iface));
-       if (hapd_iface == NULL)
-               goto fail;
-
-       hapd_iface->config_fname = os_strdup(config_file);
-       if (hapd_iface->config_fname == NULL)
-               goto fail;
-
-       conf = hostapd_config_read(hapd_iface->config_fname);
-       if (conf == NULL)
-               goto fail;
-       hapd_iface->conf = conf;
-
-       hapd_iface->num_bss = conf->num_bss;
-       hapd_iface->bss = os_calloc(conf->num_bss,
-                                   sizeof(struct hostapd_data *));
-       if (hapd_iface->bss == NULL)
-               goto fail;
-
-       for (i = 0; i < conf->num_bss; i++) {
-               hapd = hapd_iface->bss[i] =
-                       hostapd_alloc_bss_data(hapd_iface, conf,
-                                              conf->bss[i]);
-               if (hapd == NULL)
-                       goto fail;
-               hapd->msg_ctx = hapd;
-       }
-
-       return hapd_iface;
-
-fail:
-       wpa_printf(MSG_ERROR, "Failed to set up interface with %s",
-                  config_file);
-       if (conf)
-               hostapd_config_free(conf);
-       if (hapd_iface) {
-               os_free(hapd_iface->config_fname);
-               os_free(hapd_iface->bss);
-               os_free(hapd_iface);
-       }
-       return NULL;
-}
-
-
 static int hostapd_driver_init(struct hostapd_iface *iface)
 {
        struct wpa_init_params params;
@@ -303,7 +243,7 @@ hostapd_interface_init(struct hapd_interfaces *interfaces,
        int k;
 
        wpa_printf(MSG_ERROR, "Configuration file: %s", config_fname);
-       iface = hostapd_init(config_fname);
+       iface = hostapd_init(interfaces, config_fname);
        if (!iface)
                return NULL;
        iface->interfaces = interfaces;
@@ -404,7 +344,7 @@ hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy,
                hostapd_config_free(conf);
        } else {
                /* Add a new iface with the first BSS */
-               new_iface = iface = hostapd_init(config_fname);
+               new_iface = iface = hostapd_init(interfaces, config_fname);
                if (!iface)
                        return NULL;
                os_strlcpy(iface->phy, phy, sizeof(iface->phy));
index be15779..89cdc52 100644 (file)
@@ -1151,6 +1151,67 @@ void hostapd_interface_free(struct hostapd_iface *iface)
 }
 
 
+/**
+ * hostapd_init - Allocate and initialize per-interface data
+ * @config_file: Path to the configuration file
+ * Returns: Pointer to the allocated interface data or %NULL on failure
+ *
+ * This function is used to allocate main data structures for per-interface
+ * data. The allocated data buffer will be freed by calling
+ * hostapd_cleanup_iface().
+ */
+struct hostapd_iface * hostapd_init(struct hapd_interfaces *interfaces,
+                                   const char *config_file)
+{
+       struct hostapd_iface *hapd_iface = NULL;
+       struct hostapd_config *conf = NULL;
+       struct hostapd_data *hapd;
+       size_t i;
+
+       hapd_iface = os_zalloc(sizeof(*hapd_iface));
+       if (hapd_iface == NULL)
+               goto fail;
+
+       hapd_iface->config_fname = os_strdup(config_file);
+       if (hapd_iface->config_fname == NULL)
+               goto fail;
+
+       conf = interfaces->config_read_cb(hapd_iface->config_fname);
+       if (conf == NULL)
+               goto fail;
+       hapd_iface->conf = conf;
+
+       hapd_iface->num_bss = conf->num_bss;
+       hapd_iface->bss = os_calloc(conf->num_bss,
+                                   sizeof(struct hostapd_data *));
+       if (hapd_iface->bss == NULL)
+               goto fail;
+
+       for (i = 0; i < conf->num_bss; i++) {
+               hapd = hapd_iface->bss[i] =
+                       hostapd_alloc_bss_data(hapd_iface, conf,
+                                              conf->bss[i]);
+               if (hapd == NULL)
+                       goto fail;
+               hapd->msg_ctx = hapd;
+       }
+
+       return hapd_iface;
+
+fail:
+       wpa_printf(MSG_ERROR, "Failed to set up interface with %s",
+                  config_file);
+       if (conf)
+               hostapd_config_free(conf);
+       if (hapd_iface) {
+               os_free(hapd_iface->config_fname);
+               os_free(hapd_iface->bss);
+               os_free(hapd_iface);
+       }
+       return NULL;
+}
+
+
 void hostapd_interface_deinit_free(struct hostapd_iface *iface)
 {
        const struct wpa_driver_ops *driver;
index f167a02..35317c2 100644 (file)
@@ -349,6 +349,8 @@ int hostapd_setup_interface(struct hostapd_iface *iface);
 int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err);
 void hostapd_interface_deinit(struct hostapd_iface *iface);
 void hostapd_interface_free(struct hostapd_iface *iface);
+struct hostapd_iface * hostapd_init(struct hapd_interfaces *interfaces,
+                                   const char *config_file);
 void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
                           int reassoc);
 void hostapd_interface_deinit_free(struct hostapd_iface *iface);