]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
nl80211: Restore previous nlmode if set_freq for AP mode fails
authorJouni Malinen <jouni@qca.qualcomm.com>
Mon, 7 Jan 2013 22:34:08 +0000 (00:34 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 7 Jan 2013 22:34:08 +0000 (00:34 +0200)
wpa_driver_nl80211_ap() returned error if set_freq failed, but left the
previously set nlmode to GO/AP. While this should not be issue for most
purposes, it leaves the interface in somewhat unexpected state and could
potentially affect operations prior to next connection attempt. Address
this by restoring the previous nlmode if AP mode cannot be started for
some reason.

Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>

src/drivers/driver_nl80211.c

index dc339775c064690c3d5e0cf29e7408d1f51d5322..37b6be9951f4cbf379bb9210496ef78a71407785 100644 (file)
@@ -6604,7 +6604,7 @@ static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr,
 static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv,
                                 struct wpa_driver_associate_params *params)
 {
-       enum nl80211_iftype nlmode;
+       enum nl80211_iftype nlmode, old_mode;
 
        if (params->p2p) {
                wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P "
@@ -6613,8 +6613,15 @@ static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv,
        } else
                nlmode = NL80211_IFTYPE_AP;
 
-       if (wpa_driver_nl80211_set_mode(&drv->first_bss, nlmode) ||
-           wpa_driver_nl80211_set_freq(&drv->first_bss, params->freq, 0, 0)) {
+       old_mode = drv->nlmode;
+       if (wpa_driver_nl80211_set_mode(&drv->first_bss, nlmode)) {
+               nl80211_remove_monitor_interface(drv);
+               return -1;
+       }
+
+       if (wpa_driver_nl80211_set_freq(&drv->first_bss, params->freq, 0, 0)) {
+               if (old_mode != nlmode)
+                       wpa_driver_nl80211_set_mode(&drv->first_bss, old_mode);
                nl80211_remove_monitor_interface(drv);
                return -1;
        }