From a1fb5692af634ea5b1d60bce5f8825c00182ac20 Mon Sep 17 00:00:00 2001 From: Kyeyoon Park Date: Tue, 29 Oct 2013 16:29:49 +0200 Subject: [PATCH] hostapd: Make hostapd_interface_init_bss() available externally Signed-hostap: Jouni Malinen --- hostapd/main.c | 97 ------------------------------------------------ src/ap/hostapd.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++ src/ap/hostapd.h | 3 ++ 3 files changed, 100 insertions(+), 97 deletions(-) diff --git a/hostapd/main.c b/hostapd/main.c index 29afec9da..d6f9258bc 100644 --- a/hostapd/main.c +++ b/hostapd/main.c @@ -273,103 +273,6 @@ hostapd_interface_init(struct hapd_interfaces *interfaces, } -static struct hostapd_iface * -hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy, - const char *config_fname, int debug) -{ - struct hostapd_iface *new_iface = NULL, *iface = NULL; - struct hostapd_data *hapd; - int k; - size_t i, bss_idx; - - if (!phy || !*phy) - return NULL; - - for (i = 0; i < interfaces->count; i++) { - if (os_strcmp(interfaces->iface[i]->phy, phy) == 0) { - iface = interfaces->iface[i]; - break; - } - } - - wpa_printf(MSG_ERROR, "Configuration file: %s (phy %s)%s", - config_fname, phy, iface ? "" : " --> new PHY"); - if (iface) { - struct hostapd_config *conf; - struct hostapd_bss_config **tmp_conf; - struct hostapd_data **tmp_bss; - struct hostapd_bss_config *bss; - - /* Add new BSS to existing iface */ - conf = hostapd_config_read(config_fname); - if (conf == NULL) - return NULL; - if (conf->num_bss > 1) { - wpa_printf(MSG_ERROR, "Multiple BSSes specified in BSS-config"); - hostapd_config_free(conf); - return NULL; - } - - tmp_conf = os_realloc_array( - iface->conf->bss, iface->conf->num_bss + 1, - sizeof(struct hostapd_bss_config *)); - tmp_bss = os_realloc_array(iface->bss, iface->num_bss + 1, - sizeof(struct hostapd_data *)); - if (tmp_bss) - iface->bss = tmp_bss; - if (tmp_conf) { - iface->conf->bss = tmp_conf; - iface->conf->last_bss = tmp_conf[0]; - } - if (tmp_bss == NULL || tmp_conf == NULL) { - hostapd_config_free(conf); - return NULL; - } - bss = iface->conf->bss[iface->conf->num_bss] = conf->bss[0]; - iface->conf->num_bss++; - - hapd = hostapd_alloc_bss_data(iface, iface->conf, bss); - if (hapd == NULL) { - iface->conf->num_bss--; - hostapd_config_free(conf); - return NULL; - } - iface->conf->last_bss = bss; - iface->bss[iface->num_bss] = hapd; - hapd->msg_ctx = hapd; - - bss_idx = iface->num_bss++; - conf->num_bss--; - conf->bss[0] = NULL; - hostapd_config_free(conf); - } else { - /* Add a new iface with the first BSS */ - new_iface = iface = hostapd_init(interfaces, config_fname); - if (!iface) - return NULL; - os_strlcpy(iface->phy, phy, sizeof(iface->phy)); - iface->interfaces = interfaces; - bss_idx = 0; - } - - for (k = 0; k < debug; k++) { - if (iface->bss[bss_idx]->conf->logger_stdout_level > 0) - iface->bss[bss_idx]->conf->logger_stdout_level--; - } - - if (iface->conf->bss[bss_idx]->iface[0] == '\0' && - !hostapd_drv_none(iface->bss[bss_idx])) { - wpa_printf(MSG_ERROR, "Interface name not specified in %s", - config_fname); - if (new_iface) - hostapd_interface_deinit_free(new_iface); - return NULL; - } - - return iface; -} - - static int hostapd_interface_init2(struct hostapd_iface *iface) { if (iface->init_done) diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c index 89cdc528b..88e44f537 100644 --- a/src/ap/hostapd.c +++ b/src/ap/hostapd.c @@ -1212,6 +1212,103 @@ fail: } +struct hostapd_iface * +hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy, + const char *config_fname, int debug) +{ + struct hostapd_iface *new_iface = NULL, *iface = NULL; + struct hostapd_data *hapd; + int k; + size_t i, bss_idx; + + if (!phy || !*phy) + return NULL; + + for (i = 0; i < interfaces->count; i++) { + if (os_strcmp(interfaces->iface[i]->phy, phy) == 0) { + iface = interfaces->iface[i]; + break; + } + } + + wpa_printf(MSG_ERROR, "Configuration file: %s (phy %s)%s", + config_fname, phy, iface ? "" : " --> new PHY"); + if (iface) { + struct hostapd_config *conf; + struct hostapd_bss_config **tmp_conf; + struct hostapd_data **tmp_bss; + struct hostapd_bss_config *bss; + + /* Add new BSS to existing iface */ + conf = interfaces->config_read_cb(config_fname); + if (conf == NULL) + return NULL; + if (conf->num_bss > 1) { + wpa_printf(MSG_ERROR, "Multiple BSSes specified in BSS-config"); + hostapd_config_free(conf); + return NULL; + } + + tmp_conf = os_realloc_array( + iface->conf->bss, iface->conf->num_bss + 1, + sizeof(struct hostapd_bss_config *)); + tmp_bss = os_realloc_array(iface->bss, iface->num_bss + 1, + sizeof(struct hostapd_data *)); + if (tmp_bss) + iface->bss = tmp_bss; + if (tmp_conf) { + iface->conf->bss = tmp_conf; + iface->conf->last_bss = tmp_conf[0]; + } + if (tmp_bss == NULL || tmp_conf == NULL) { + hostapd_config_free(conf); + return NULL; + } + bss = iface->conf->bss[iface->conf->num_bss] = conf->bss[0]; + iface->conf->num_bss++; + + hapd = hostapd_alloc_bss_data(iface, iface->conf, bss); + if (hapd == NULL) { + iface->conf->num_bss--; + hostapd_config_free(conf); + return NULL; + } + iface->conf->last_bss = bss; + iface->bss[iface->num_bss] = hapd; + hapd->msg_ctx = hapd; + + bss_idx = iface->num_bss++; + conf->num_bss--; + conf->bss[0] = NULL; + hostapd_config_free(conf); + } else { + /* Add a new iface with the first BSS */ + new_iface = iface = hostapd_init(interfaces, config_fname); + if (!iface) + return NULL; + os_strlcpy(iface->phy, phy, sizeof(iface->phy)); + iface->interfaces = interfaces; + bss_idx = 0; + } + + for (k = 0; k < debug; k++) { + if (iface->bss[bss_idx]->conf->logger_stdout_level > 0) + iface->bss[bss_idx]->conf->logger_stdout_level--; + } + + if (iface->conf->bss[bss_idx]->iface[0] == '\0' && + !hostapd_drv_none(iface->bss[bss_idx])) { + wpa_printf(MSG_ERROR, "Interface name not specified in %s", + config_fname); + if (new_iface) + hostapd_interface_deinit_free(new_iface); + return NULL; + } + + return iface; +} + + void hostapd_interface_deinit_free(struct hostapd_iface *iface) { const struct wpa_driver_ops *driver; diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h index 35317c23a..bae4d0b11 100644 --- a/src/ap/hostapd.h +++ b/src/ap/hostapd.h @@ -351,6 +351,9 @@ 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); +struct hostapd_iface * +hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy, + const char *config_fname, int debug); void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta, int reassoc); void hostapd_interface_deinit_free(struct hostapd_iface *iface);