hostapd: Make hostapd_interface_init_bss() available externally

Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>
This commit is contained in:
Kyeyoon Park 2013-10-29 16:29:49 +02:00 committed by Jouni Malinen
parent 66936c6af8
commit a1fb5692af
3 changed files with 100 additions and 97 deletions

View file

@ -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) static int hostapd_interface_init2(struct hostapd_iface *iface)
{ {
if (iface->init_done) if (iface->init_done)

View file

@ -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) void hostapd_interface_deinit_free(struct hostapd_iface *iface)
{ {
const struct wpa_driver_ops *driver; const struct wpa_driver_ops *driver;

View file

@ -351,6 +351,9 @@ void hostapd_interface_deinit(struct hostapd_iface *iface);
void hostapd_interface_free(struct hostapd_iface *iface); void hostapd_interface_free(struct hostapd_iface *iface);
struct hostapd_iface * hostapd_init(struct hapd_interfaces *interfaces, struct hostapd_iface * hostapd_init(struct hapd_interfaces *interfaces,
const char *config_file); 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, void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
int reassoc); int reassoc);
void hostapd_interface_deinit_free(struct hostapd_iface *iface); void hostapd_interface_deinit_free(struct hostapd_iface *iface);