From 708bc8e0e41f17b8f976a3dc5c9ac9776c8fad1f Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Tue, 8 Jan 2013 00:34:08 +0200 Subject: [PATCH] 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 --- src/drivers/driver_nl80211.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) 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; }