hostapd: Accept interface names as a command line parameter
This introduces an optinal command line parameter '-i' to override the value of the '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@linux.intel.com>
This commit is contained in:
parent
cc27c8e680
commit
40f6282aed
1 changed files with 67 additions and 4 deletions
|
@ -251,7 +251,7 @@ static int hostapd_driver_init(struct hostapd_iface *iface)
|
||||||
* interfaces. No actiual driver operations are started.
|
* interfaces. No actiual driver operations are started.
|
||||||
*/
|
*/
|
||||||
static struct hostapd_iface *
|
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)
|
const char *config_fname, int debug)
|
||||||
{
|
{
|
||||||
struct hostapd_iface *iface;
|
struct hostapd_iface *iface;
|
||||||
|
@ -261,6 +261,12 @@ hostapd_interface_init(struct hapd_interfaces *interfaces,
|
||||||
iface = hostapd_init(interfaces, config_fname);
|
iface = hostapd_init(interfaces, config_fname);
|
||||||
if (!iface)
|
if (!iface)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (if_name) {
|
||||||
|
os_strlcpy(iface->conf->bss[0]->iface, if_name,
|
||||||
|
sizeof(iface->conf->bss[0]->iface));
|
||||||
|
}
|
||||||
|
|
||||||
iface->interfaces = interfaces;
|
iface->interfaces = interfaces;
|
||||||
|
|
||||||
for (k = 0; k < debug; k++) {
|
for (k = 0; k < debug; k++) {
|
||||||
|
@ -270,7 +276,8 @@ hostapd_interface_init(struct hapd_interfaces *interfaces,
|
||||||
|
|
||||||
if (iface->conf->bss[0]->iface[0] == '\0' &&
|
if (iface->conf->bss[0]->iface[0] == '\0' &&
|
||||||
!hostapd_drv_none(iface->bss[0])) {
|
!hostapd_drv_none(iface->bss[0])) {
|
||||||
wpa_printf(MSG_ERROR, "Interface name not specified in %s",
|
wpa_printf(MSG_ERROR,
|
||||||
|
"Interface name not specified in %s, nor by '-i' parameter",
|
||||||
config_fname);
|
config_fname);
|
||||||
hostapd_interface_deinit_free(iface);
|
hostapd_interface_deinit_free(iface);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -456,7 +463,8 @@ static void usage(void)
|
||||||
"\n"
|
"\n"
|
||||||
"usage: hostapd [-hdBKtv] [-P <PID file>] [-e <entropy file>] "
|
"usage: hostapd [-hdBKtv] [-P <PID file>] [-e <entropy file>] "
|
||||||
"\\\n"
|
"\\\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"
|
" <configuration file(s)>\n"
|
||||||
"\n"
|
"\n"
|
||||||
"options:\n"
|
"options:\n"
|
||||||
|
@ -475,6 +483,7 @@ static void usage(void)
|
||||||
" -T = record to Linux tracing in addition to logging\n"
|
" -T = record to Linux tracing in addition to logging\n"
|
||||||
" (records all messages regardless of debug verbosity)\n"
|
" (records all messages regardless of debug verbosity)\n"
|
||||||
#endif /* CONFIG_DEBUG_LINUX_TRACING */
|
#endif /* CONFIG_DEBUG_LINUX_TRACING */
|
||||||
|
" -i list of interface names to use\n"
|
||||||
" -S start all the interfaces synchronously\n"
|
" -S start all the interfaces synchronously\n"
|
||||||
" -t include timestamps in some debug messages\n"
|
" -t include timestamps in some debug messages\n"
|
||||||
" -v show hostapd version\n");
|
" -v show hostapd version\n");
|
||||||
|
@ -538,6 +547,43 @@ static int hostapd_get_ctrl_iface_group(struct hapd_interfaces *interfaces,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int hostapd_get_interface_names(char ***if_names,
|
||||||
|
size_t *if_names_size,
|
||||||
|
char *optarg)
|
||||||
|
{
|
||||||
|
char *if_name, *tmp, **nnames;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
if (!optarg)
|
||||||
|
return -1;
|
||||||
|
if_name = strtok_r(optarg, ",", &tmp);
|
||||||
|
|
||||||
|
while (if_name) {
|
||||||
|
nnames = os_realloc_array(*if_names, 1 + *if_names_size,
|
||||||
|
sizeof(char *));
|
||||||
|
if (!nnames)
|
||||||
|
goto fail;
|
||||||
|
*if_names = nnames;
|
||||||
|
|
||||||
|
(*if_names)[*if_names_size] = os_strdup(if_name);
|
||||||
|
if (!(*if_names)[*if_names_size])
|
||||||
|
goto fail;
|
||||||
|
(*if_names_size)++;
|
||||||
|
if_name = strtok_r(NULL, ",", &tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
for (i = 0; i < *if_names_size; i++)
|
||||||
|
os_free((*if_names)[i]);
|
||||||
|
os_free(*if_names);
|
||||||
|
*if_names = NULL;
|
||||||
|
*if_names_size = 0;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef CONFIG_WPS
|
#ifdef CONFIG_WPS
|
||||||
static int gen_uuid(const char *txt_addr)
|
static int gen_uuid(const char *txt_addr)
|
||||||
{
|
{
|
||||||
|
@ -596,6 +642,8 @@ int main(int argc, char *argv[])
|
||||||
int enable_trace_dbg = 0;
|
int enable_trace_dbg = 0;
|
||||||
#endif /* CONFIG_DEBUG_LINUX_TRACING */
|
#endif /* CONFIG_DEBUG_LINUX_TRACING */
|
||||||
int start_ifaces_in_sync = 0;
|
int start_ifaces_in_sync = 0;
|
||||||
|
char **if_names = NULL;
|
||||||
|
size_t if_names_size = 0;
|
||||||
|
|
||||||
if (os_program_init())
|
if (os_program_init())
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -613,7 +661,7 @@ int main(int argc, char *argv[])
|
||||||
dl_list_init(&interfaces.global_ctrl_dst);
|
dl_list_init(&interfaces.global_ctrl_dst);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
c = getopt(argc, argv, "b:Bde:f:hKP:STtu:vg:G:");
|
c = getopt(argc, argv, "b:Bde:f:hi:KP:STtu:vg:G:");
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
break;
|
break;
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
@ -677,6 +725,11 @@ int main(int argc, char *argv[])
|
||||||
case 'u':
|
case 'u':
|
||||||
return gen_uuid(optarg);
|
return gen_uuid(optarg);
|
||||||
#endif /* CONFIG_WPS */
|
#endif /* CONFIG_WPS */
|
||||||
|
case 'i':
|
||||||
|
if (hostapd_get_interface_names(&if_names,
|
||||||
|
&if_names_size, optarg))
|
||||||
|
goto out;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
break;
|
break;
|
||||||
|
@ -734,7 +787,13 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
/* Allocate and parse configuration for full interface files */
|
/* Allocate and parse configuration for full interface files */
|
||||||
for (i = 0; i < interfaces.count; i++) {
|
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,
|
interfaces.iface[i] = hostapd_interface_init(&interfaces,
|
||||||
|
if_name,
|
||||||
argv[optind + i],
|
argv[optind + i],
|
||||||
debug);
|
debug);
|
||||||
if (!interfaces.iface[i]) {
|
if (!interfaces.iface[i]) {
|
||||||
|
@ -829,6 +888,10 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
os_free(bss_config);
|
os_free(bss_config);
|
||||||
|
|
||||||
|
for (i = 0; i < if_names_size; i++)
|
||||||
|
os_free(if_names[i]);
|
||||||
|
os_free(if_names);
|
||||||
|
|
||||||
fst_global_deinit();
|
fst_global_deinit();
|
||||||
|
|
||||||
os_program_deinit();
|
os_program_deinit();
|
||||||
|
|
Loading…
Reference in a new issue