hostapd: Track interface state

The new hostapd_iface::state enum is used to track the current state of
the hostapd interface (a radio/wiphy).

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2013-11-03 17:25:05 +02:00
parent f0793bf191
commit e1c5faf007
5 changed files with 50 additions and 0 deletions

View File

@ -795,6 +795,7 @@ enum hostapd_chan_status acs_init(struct hostapd_iface *iface)
if (err < 0)
return HOSTAPD_CHAN_INVALID;
hostapd_set_state(iface, HAPD_IFACE_ACS);
wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_STARTED);
return HOSTAPD_CHAN_ACS;

View File

@ -568,6 +568,7 @@ int hostapd_handle_dfs(struct hostapd_data *hapd)
} while (res);
/* Finally start CAC */
hostapd_set_state(hapd->iface, HAPD_IFACE_DFS);
wpa_printf(MSG_DEBUG, "DFS start CAC on %d MHz", hapd->iface->freq);
wpa_msg(hapd->msg_ctx, MSG_INFO, DFS_EVENT_CAC_START
"freq=%d chan=%d sec_chan=%d",

View File

@ -987,6 +987,7 @@ static int setup_interface(struct hostapd_iface *iface)
if (hapd->iconf->country[0] && hapd->iconf->country[1]) {
char country[4], previous_country[4];
hostapd_set_state(iface, HAPD_IFACE_COUNTRY_UPDATE);
if (hostapd_get_country(hapd, previous_country) < 0)
previous_country[0] = '\0';
@ -1056,6 +1057,7 @@ int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err)
if (err) {
wpa_printf(MSG_ERROR, "Interface initialization failed");
hostapd_set_state(iface, HAPD_IFACE_DISABLED);
eloop_terminate();
return -1;
}
@ -1153,6 +1155,7 @@ int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err)
return -1;
}
hostapd_set_state(iface, HAPD_IFACE_ENABLED);
if (hapd->setup_complete_cb)
hapd->setup_complete_cb(hapd->setup_complete_cb_ctx);
@ -1535,6 +1538,7 @@ int hostapd_disable_iface(struct hostapd_iface *hapd_iface)
wpa_printf(MSG_DEBUG, "Interface %s disabled",
hapd_iface->bss[0]->conf->iface);
hostapd_set_state(hapd_iface, HAPD_IFACE_DISABLED);
return 0;
}
@ -1890,3 +1894,35 @@ void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
ap_handle_timer, hapd, sta);
}
static const char * hostapd_state_text(enum hostapd_iface_state s)
{
switch (s) {
case HAPD_IFACE_UNINITIALIZED:
return "UNINITIALIZED";
case HAPD_IFACE_DISABLED:
return "DISABLED";
case HAPD_IFACE_COUNTRY_UPDATE:
return "COUNTRY_UPDATE";
case HAPD_IFACE_ACS:
return "ACS";
case HAPD_IFACE_HT_SCAN:
return "HT_SCAN";
case HAPD_IFACE_DFS:
return "DFS";
case HAPD_IFACE_ENABLED:
return "ENABLED";
}
return "UNKNOWN";
}
void hostapd_set_state(struct hostapd_iface *iface, enum hostapd_iface_state s)
{
wpa_printf(MSG_INFO, "%s: interface state %s->%s",
iface->conf->bss[0]->iface, hostapd_state_text(iface->state),
hostapd_state_text(s));
iface->state = s;
}

View File

@ -251,6 +251,16 @@ struct hostapd_iface {
struct hostapd_config *conf;
char phy[16]; /* Name of the PHY (radio) */
enum hostapd_iface_state {
HAPD_IFACE_UNINITIALIZED,
HAPD_IFACE_DISABLED,
HAPD_IFACE_COUNTRY_UPDATE,
HAPD_IFACE_ACS,
HAPD_IFACE_HT_SCAN,
HAPD_IFACE_DFS,
HAPD_IFACE_ENABLED
} state;
size_t num_bss;
struct hostapd_data **bss;
@ -364,6 +374,7 @@ int hostapd_disable_iface(struct hostapd_iface *hapd_iface);
int hostapd_add_iface(struct hapd_interfaces *ifaces, char *buf);
int hostapd_remove_iface(struct hapd_interfaces *ifaces, char *buf);
void hostapd_channel_list_updated(struct hostapd_iface *iface);
void hostapd_set_state(struct hostapd_iface *iface, enum hostapd_iface_state s);
/* utils.c */
int hostapd_register_probereq_cb(struct hostapd_data *hapd,

View File

@ -539,6 +539,7 @@ static int ieee80211n_check_40mhz(struct hostapd_iface *iface)
if (!iface->conf->secondary_channel)
return 0; /* HT40 not used */
hostapd_set_state(iface, HAPD_IFACE_HT_SCAN);
wpa_printf(MSG_DEBUG, "Scan for neighboring BSSes prior to enabling "
"40 MHz channel");
os_memset(&params, 0, sizeof(params));