From bad5cdf4911e722c9e5617ba134b0ff2cc6fbe3c Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Tue, 24 Dec 2013 22:46:20 +0200 Subject: [PATCH] Verify that beacon setup succeeds before proceeding There is no point in starting the AP operations unless the driver can be successfully configured to beacon. Signed-hostap: Jouni Malinen --- src/ap/beacon.c | 40 ++++++++++++++++++++++++++++------------ src/ap/beacon.h | 6 +++--- src/ap/hostapd.c | 4 ++-- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/ap/beacon.c b/src/ap/beacon.c index afadcad71..24e9a0b77 100644 --- a/src/ap/beacon.c +++ b/src/ap/beacon.c @@ -878,20 +878,21 @@ void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params) } -void ieee802_11_set_beacon(struct hostapd_data *hapd) +int ieee802_11_set_beacon(struct hostapd_data *hapd) { struct wpa_driver_ap_params params; struct wpabuf *beacon, *proberesp, *assocresp; + int res, ret = -1; if (hapd->iface->csa_in_progress) { wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period"); - return; + return -1; } hapd->beacon_set_done = 1; if (ieee802_11_build_ap_params(hapd, ¶ms) < 0) - return; + return -1; if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) < 0) @@ -901,31 +902,46 @@ void ieee802_11_set_beacon(struct hostapd_data *hapd) params.proberesp_ies = proberesp; params.assocresp_ies = assocresp; - if (hostapd_drv_set_ap(hapd, ¶ms)) - wpa_printf(MSG_ERROR, "Failed to set beacon parameters"); + res = hostapd_drv_set_ap(hapd, ¶ms); hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp); + if (res) + wpa_printf(MSG_ERROR, "Failed to set beacon parameters"); + else + ret = 0; fail: ieee802_11_free_ap_params(¶ms); + return ret; } -void ieee802_11_set_beacons(struct hostapd_iface *iface) +int ieee802_11_set_beacons(struct hostapd_iface *iface) { size_t i; + int ret = 0; + for (i = 0; i < iface->num_bss; i++) { - if (iface->bss[i]->started) - ieee802_11_set_beacon(iface->bss[i]); + if (iface->bss[i]->started && + ieee802_11_set_beacon(iface->bss[i]) < 0) + ret = -1; } + + return ret; } /* only update beacons if started */ -void ieee802_11_update_beacons(struct hostapd_iface *iface) +int ieee802_11_update_beacons(struct hostapd_iface *iface) { size_t i; - for (i = 0; i < iface->num_bss; i++) - if (iface->bss[i]->beacon_set_done && iface->bss[i]->started) - ieee802_11_set_beacon(iface->bss[i]); + int ret = 0; + + for (i = 0; i < iface->num_bss; i++) { + if (iface->bss[i]->beacon_set_done && iface->bss[i]->started && + ieee802_11_set_beacon(iface->bss[i]) < 0) + ret = -1; + } + + return ret; } #endif /* CONFIG_NATIVE_WINDOWS */ diff --git a/src/ap/beacon.h b/src/ap/beacon.h index a04a829cb..ecbab65df 100644 --- a/src/ap/beacon.h +++ b/src/ap/beacon.h @@ -21,9 +21,9 @@ struct ieee80211_mgmt; void handle_probe_req(struct hostapd_data *hapd, const struct ieee80211_mgmt *mgmt, size_t len, int ssi_signal); -void ieee802_11_set_beacon(struct hostapd_data *hapd); -void ieee802_11_set_beacons(struct hostapd_iface *iface); -void ieee802_11_update_beacons(struct hostapd_iface *iface); +int ieee802_11_set_beacon(struct hostapd_data *hapd); +int ieee802_11_set_beacons(struct hostapd_iface *iface); +int ieee802_11_update_beacons(struct hostapd_iface *iface); int ieee802_11_build_ap_params(struct hostapd_data *hapd, struct wpa_driver_ap_params *params); void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params); diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c index 0d669f9eb..69459f77d 100644 --- a/src/ap/hostapd.c +++ b/src/ap/hostapd.c @@ -810,8 +810,8 @@ static int hostapd_setup_bss(struct hostapd_data *hapd, int first) return -1; } - if (!hapd->conf->start_disabled) - ieee802_11_set_beacon(hapd); + if (!hapd->conf->start_disabled && ieee802_11_set_beacon(hapd) < 0) + return -1; if (hapd->wpa_auth && wpa_init_keys(hapd->wpa_auth) < 0) return -1;