Allow hostapd config file for dynamically added interface

This extends hostapd global control interface command "ADD" to use a
configuration file instead of requiring configuration to be built using
SET command.

The command format is now following:
ADD <ifname> <control path|config=<path to config>>

For example:

ADD wlan0 /var/run/hostapd
ADD wlan0 config=/tmp/hostapd.conf

When using the configuration file option, ctrl_interface parameter in
the file needs to be set to allow ENABLE command to be issued on the new
interface.

Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>
This commit is contained in:
Jouni Malinen 2013-09-25 19:07:29 +03:00 committed by Jouni Malinen
parent 97bacf7cf6
commit ed1bf011da

View file

@ -1323,12 +1323,16 @@ int hostapd_add_iface(struct hapd_interfaces *interfaces, char *buf)
struct hostapd_iface *hapd_iface = NULL; struct hostapd_iface *hapd_iface = NULL;
char *ptr; char *ptr;
size_t i; size_t i;
const char *conf_file = NULL;
ptr = os_strchr(buf, ' '); ptr = os_strchr(buf, ' ');
if (ptr == NULL) if (ptr == NULL)
return -1; return -1;
*ptr++ = '\0'; *ptr++ = '\0';
if (os_strncmp(ptr, "config=", 7) == 0)
conf_file = ptr + 7;
for (i = 0; i < interfaces->count; i++) { for (i = 0; i < interfaces->count; i++) {
if (!os_strcmp(interfaces->iface[i]->conf->bss[0].iface, if (!os_strcmp(interfaces->iface[i]->conf->bss[0].iface,
buf)) { buf)) {
@ -1345,8 +1349,14 @@ int hostapd_add_iface(struct hapd_interfaces *interfaces, char *buf)
goto fail; goto fail;
} }
conf = hostapd_config_alloc(interfaces, buf, ptr); if (conf_file && interfaces->config_read_cb) {
if (conf == NULL) { conf = interfaces->config_read_cb(conf_file);
if (conf && conf->bss)
os_strlcpy(conf->bss->iface, buf,
sizeof(conf->bss->iface));
} else
conf = hostapd_config_alloc(interfaces, buf, ptr);
if (conf == NULL || conf->bss == NULL) {
wpa_printf(MSG_ERROR, "%s: Failed to allocate memory " wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
"for configuration", __func__); "for configuration", __func__);
goto fail; goto fail;