Move hostapd_init() into main.c

This commit is contained in:
Jouni Malinen 2009-03-26 19:23:41 +02:00 committed by Jouni Malinen
parent 3067ac2bb8
commit b6a7859d15
3 changed files with 69 additions and 65 deletions

View File

@ -1476,7 +1476,7 @@ int hostapd_setup_interface(struct hostapd_iface *iface)
* freed after hostapd_cleanup() is called for it during interface
* deinitialization.
*/
static struct hostapd_data *
struct hostapd_data *
hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
struct hostapd_config *conf,
struct hostapd_bss_config *bss)
@ -1554,69 +1554,6 @@ fail:
}
/**
* 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(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_zalloc(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;
}
return hapd_iface;
fail:
if (conf)
hostapd_config_free(conf);
if (hapd_iface) {
for (i = 0; hapd_iface->bss && i < hapd_iface->num_bss; i++) {
hapd = hapd_iface->bss[i];
if (hapd && hapd->ssl_ctx)
tls_deinit(hapd->ssl_ctx);
}
os_free(hapd_iface->config_fname);
os_free(hapd_iface->bss);
os_free(hapd_iface);
}
return NULL;
}
void hostapd_interface_deinit(struct hostapd_iface *iface)
{
size_t j;

View File

@ -159,7 +159,10 @@ struct hostapd_iface {
};
int hostapd_reload_config(struct hostapd_iface *iface);
struct hostapd_iface * hostapd_init(const char *config_file);
struct hostapd_data *
hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
struct hostapd_config *conf,
struct hostapd_bss_config *bss);
int hostapd_setup_interface(struct hostapd_iface *iface);
void hostapd_interface_deinit(struct hostapd_iface *iface);
int handle_reload_iface(struct hostapd_iface *iface, void *ctx);

View File

@ -21,6 +21,7 @@
#include "hostapd.h"
#include "version.h"
#include "config.h"
#include "tls.h"
#include "eap_server/eap.h"
#include "eap_server/tncs.h"
@ -156,6 +157,69 @@ 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_zalloc(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;
}
return hapd_iface;
fail:
if (conf)
hostapd_config_free(conf);
if (hapd_iface) {
for (i = 0; hapd_iface->bss && i < hapd_iface->num_bss; i++) {
hapd = hapd_iface->bss[i];
if (hapd && hapd->ssl_ctx)
tls_deinit(hapd->ssl_ctx);
}
os_free(hapd_iface->config_fname);
os_free(hapd_iface->bss);
os_free(hapd_iface);
}
return NULL;
}
static struct hostapd_iface * hostapd_interface_init(const char *config_fname,
int debug)
{