From e1c5faf007a8cd866b151b15cc72f8ec30d88d93 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sun, 3 Nov 2013 17:25:05 +0200 Subject: [PATCH] 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 --- src/ap/acs.c | 1 + src/ap/dfs.c | 1 + src/ap/hostapd.c | 36 ++++++++++++++++++++++++++++++++++++ src/ap/hostapd.h | 11 +++++++++++ src/ap/hw_features.c | 1 + 5 files changed, 50 insertions(+) diff --git a/src/ap/acs.c b/src/ap/acs.c index 12b955c72..9ef221ed9 100644 --- a/src/ap/acs.c +++ b/src/ap/acs.c @@ -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; diff --git a/src/ap/dfs.c b/src/ap/dfs.c index 202076a18..0ecd2527b 100644 --- a/src/ap/dfs.c +++ b/src/ap/dfs.c @@ -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", diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c index f41cb145b..afad8efaa 100644 --- a/src/ap/hostapd.c +++ b/src/ap/hostapd.c @@ -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; +} diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h index dacdfa7da..02f45af6e 100644 --- a/src/ap/hostapd.h +++ b/src/ap/hostapd.h @@ -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, diff --git a/src/ap/hw_features.c b/src/ap/hw_features.c index 908d91ebd..7c4ef12ca 100644 --- a/src/ap/hw_features.c +++ b/src/ap/hw_features.c @@ -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(¶ms, 0, sizeof(params));