Verify that beacon setup succeeds before proceeding
authorJouni Malinen <j@w1.fi>
Tue, 24 Dec 2013 20:46:20 +0000 (22:46 +0200)
committerJouni Malinen <j@w1.fi>
Tue, 24 Dec 2013 20:46:20 +0000 (22:46 +0200)
There is no point in starting the AP operations unless
the driver can be successfully configured to beacon.

Signed-hostap: Jouni Malinen <j@w1.fi>

src/ap/beacon.c
src/ap/beacon.h
src/ap/hostapd.c

index afadcad..24e9a0b 100644 (file)
@@ -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, &params) < 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, &params))
-               wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
+       res = hostapd_drv_set_ap(hapd, &params);
        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(&params);
+       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 */
index a04a829..ecbab65 100644 (file)
@@ -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);
index 0d669f9..69459f7 100644 (file)
@@ -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;