From: Jouni Malinen Date: Mon, 7 Jan 2013 22:34:08 +0000 (+0200) Subject: nl80211: Restore previous nlmode if set_freq for AP mode fails X-Git-Tag: hostap_2_0~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=708bc8e0e41f17b8f976a3dc5c9ac9776c8fad1f;p=thirdparty%2Fhostap.git nl80211: Restore previous nlmode if set_freq for AP mode fails 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 --- diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c index dc339775c..37b6be995 100644 --- a/src/drivers/driver_nl80211.c +++ b/src/drivers/driver_nl80211.c @@ -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; }