[PATCH 1/2] main: Accept interface names as a parameter
Tim Kourt
tim.a.kourt at linux.intel.com
Fri Jun 10 11:04:25 PDT 2016
The introduction of a parameter ‘-i’ to override the value of
‘interface’ attribute in hostapd.conf files. This change enables
the reuse of the configuration files for the concurrent instances
of hostapd. An ability to dynamically assign the interface names
simplifies the usages of hostapd service in the automated
emulations of the wireless environments.
Signed-off-by: Tim Kourt <tim.a.kourt at linux.intel.com>
---
hostapd/main.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 52 insertions(+), 7 deletions(-)
diff --git a/hostapd/main.c b/hostapd/main.c
index 5f3f83b..35a21b4 100644
--- a/hostapd/main.c
+++ b/hostapd/main.c
@@ -251,7 +251,7 @@ static int hostapd_driver_init(struct hostapd_iface *iface)
* interfaces. No actiual driver operations are started.
*/
static struct hostapd_iface *
-hostapd_interface_init(struct hapd_interfaces *interfaces,
+hostapd_interface_init(struct hapd_interfaces *interfaces, const char *if_name,
const char *config_fname, int debug)
{
struct hostapd_iface *iface;
@@ -261,6 +261,12 @@ hostapd_interface_init(struct hapd_interfaces *interfaces,
iface = hostapd_init(interfaces, config_fname);
if (!iface)
return NULL;
+
+ if (if_name) {
+ strncpy(iface->conf->bss[0]->iface, if_name, strlen(if_name));
+ iface->conf->bss[0]->iface[strlen(if_name)] = '\0';
+ }
+
iface->interfaces = interfaces;
for (k = 0; k < debug; k++) {
@@ -270,8 +276,8 @@ hostapd_interface_init(struct hapd_interfaces *interfaces,
if (iface->conf->bss[0]->iface[0] == '\0' &&
!hostapd_drv_none(iface->bss[0])) {
- wpa_printf(MSG_ERROR, "Interface name not specified in %s",
- config_fname);
+ wpa_printf(MSG_ERROR, "Interface name not specified in %s, nor "
+ "by '-i' parameter", config_fname);
hostapd_interface_deinit_free(iface);
return NULL;
}
@@ -454,7 +460,8 @@ static void usage(void)
"\n"
"usage: hostapd [-hdBKtv] [-P <PID file>] [-e <entropy file>] "
"\\\n"
- " [-g <global ctrl_iface>] [-G <group>] \\\n"
+ " [-g <global ctrl_iface>] [-G <group>]\\\n"
+ " [-i <comma-separated list of interface names>]\\\n"
" <configuration file(s)>\n"
"\n"
"options:\n"
@@ -473,6 +480,7 @@ static void usage(void)
" -T = record to Linux tracing in addition to logging\n"
" (records all messages regardless of debug verbosity)\n"
#endif /* CONFIG_DEBUG_LINUX_TRACING */
+ " -i list of interface names to use\n"
" -S start all the interfaces synchronously\n"
" -t include timestamps in some debug messages\n"
" -v show hostapd version\n");
@@ -535,6 +543,27 @@ static int hostapd_get_ctrl_iface_group(struct hapd_interfaces *interfaces,
return 0;
}
+static int hostapd_get_interface_names(char ***if_names,
+ size_t *if_names_size,
+ char *optarg)
+{
+ char *if_name;
+
+ if_name = strtok(optarg, ",");
+
+ while (if_name) {
+ *if_names = os_realloc_array(*if_names, ++(*if_names_size),
+ sizeof(char *));
+ if (!(*if_names))
+ return -1;
+
+ (*if_names)[(*if_names_size) - 1] = os_strdup(if_name);
+ if_name = strtok(NULL, ",");
+ }
+
+ return 0;
+}
+
#ifdef CONFIG_WPS
static int gen_uuid(const char *txt_addr)
@@ -588,8 +617,8 @@ int main(int argc, char *argv[])
char *pid_file = NULL;
const char *log_file = NULL;
const char *entropy_file = NULL;
- char **bss_config = NULL, **tmp_bss;
- size_t num_bss_configs = 0;
+ char **bss_config = NULL, **tmp_bss, **if_names = NULL;
+ size_t num_bss_configs = 0, if_names_size = 0;
#ifdef CONFIG_DEBUG_LINUX_TRACING
int enable_trace_dbg = 0;
#endif /* CONFIG_DEBUG_LINUX_TRACING */
@@ -611,7 +640,7 @@ int main(int argc, char *argv[])
dl_list_init(&interfaces.global_ctrl_dst);
for (;;) {
- c = getopt(argc, argv, "b:Bde:f:hKP:STtu:vg:G:");
+ c = getopt(argc, argv, "b:Bde:f:hKP:STtu:vg:G:i:");
if (c < 0)
break;
switch (c) {
@@ -675,6 +704,11 @@ int main(int argc, char *argv[])
case 'u':
return gen_uuid(optarg);
#endif /* CONFIG_WPS */
+ case 'i':
+ if (hostapd_get_interface_names(&if_names,
+ &if_names_size, optarg))
+ goto out;
+ break;
default:
usage();
break;
@@ -732,7 +766,13 @@ int main(int argc, char *argv[])
/* Allocate and parse configuration for full interface files */
for (i = 0; i < interfaces.count; i++) {
+ char *if_name = NULL;
+
+ if (i < if_names_size)
+ if_name = if_names[i];
+
interfaces.iface[i] = hostapd_interface_init(&interfaces,
+ if_name,
argv[optind + i],
debug);
if (!interfaces.iface[i]) {
@@ -826,6 +866,11 @@ int main(int argc, char *argv[])
os_free(bss_config);
+ for (i = 0; i < if_names_size; i++)
+ os_free(if_names[i]);
+
+ os_free(if_names);
+
fst_global_deinit();
os_program_deinit();
--
2.5.5
More information about the Hostap
mailing list