Patchwork [08/18] driver_nl80211: move AP SME setup to mode change

login
register
mail settings
Submitter Johannes Berg
Date Nov. 4, 2011, 10:37 a.m.
Message ID <20111104103810.324394160@sipsolutions.net>
Download mbox | patch
Permalink /patch/123593/
State Superseded
Headers show

Comments

Johannes Berg - Nov. 4, 2011, 10:37 a.m.
From: Johannes Berg <johannes.berg@intel.com>

Signed-hostap: Johannes Berg <johannes.berg@intel.com>
---
 src/drivers/driver_nl80211.c |   84 ++++++++++++++++++++++++++---------------
 1 files changed, 53 insertions(+), 31 deletions(-)

Patch

diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index 9362c59..31fd147 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -242,6 +242,7 @@  struct wpa_driver_nl80211_data {
 
 	int monitor_sock;
 	int monitor_ifidx;
+	int monitor_refcount;
 
 	unsigned int disabled_11b_rates:1;
 	unsigned int pending_remain_on_chan:1;
@@ -5148,6 +5149,10 @@  static int add_monitor_filter(int s)
 static void nl80211_remove_monitor_interface(
 	struct wpa_driver_nl80211_data *drv)
 {
+	drv->monitor_refcount--;
+	if (drv->monitor_refcount > 0)
+		return;
+
 	if (drv->monitor_ifidx >= 0) {
 		nl80211_remove_iface(drv, drv->monitor_ifidx);
 		drv->monitor_ifidx = -1;
@@ -5168,6 +5173,11 @@  nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv)
 	int optval;
 	socklen_t optlen;
 
+	if (drv->monitor_ifidx > 0) {
+		drv->monitor_refcount++;
+		return 0;
+	}
+
 	if (os_strncmp(drv->first_bss.ifname, "p2p-", 4) == 0) {
 		/*
 		 * P2P interface name is of the format p2p-%s-%d. For monitor
@@ -5246,6 +5256,38 @@  nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv)
 }
 
 
+static int nl80211_setup_ap(struct i802_bss *bss)
+{
+	struct wpa_driver_nl80211_data *drv = bss->drv;
+
+	if (!drv->device_ap_sme &&
+	    nl80211_create_monitor_interface(drv) &&
+	    !drv->device_ap_sme)
+		return -1;
+
+	if (drv->device_ap_sme &&
+	    wpa_driver_nl80211_probe_req_report(bss, 1) < 0) {
+		wpa_printf(MSG_DEBUG, "nl80211: Failed to enable "
+			   "Probe Request frame reporting in AP mode");
+		/* Try to survive without this */
+	}
+
+	return 0;
+}
+
+
+static void nl80211_teardown_ap(struct i802_bss *bss)
+{
+	struct wpa_driver_nl80211_data *drv = bss->drv;
+
+	if (drv->device_ap_sme)
+		wpa_driver_nl80211_probe_req_report(bss, 0);
+	else
+		nl80211_remove_monitor_interface(drv);
+	bss->beacon_set = 0;
+}
+
+
 static int nl80211_send_eapol_data(struct i802_bss *bss,
 				   const u8 *addr, const u8 *data,
 				   size_t data_len)
@@ -5417,15 +5459,6 @@  static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv,
 		return -1;
 	}
 
-	if (drv->device_ap_sme) {
-		if (wpa_driver_nl80211_probe_req_report(&drv->first_bss, 1) < 0)
-		{
-			wpa_printf(MSG_DEBUG, "nl80211: Failed to enable "
-				   "Probe Request frame reporting in AP mode");
-			/* Try to survive without this */
-		}
-	}
-
 	drv->ap_oper_freq = params->freq;
 
 	return 0;
@@ -5976,33 +6009,22 @@  static int wpa_driver_nl80211_set_mode(struct i802_bss *bss,
 	}
 
 done:
-	if (!ret && is_ap_interface(nlmode)) {
+	if (ret) {
+		wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d "
+			   "from %d failed", nlmode, drv->nlmode);
+		return ret;
+	}
+
+	if (is_ap_interface(nlmode)) {
 		/* Setup additional AP mode functionality if needed */
-		if (!drv->device_ap_sme && drv->monitor_ifidx < 0 &&
-		    nl80211_create_monitor_interface(drv) &&
-		    !drv->device_ap_sme)
+		if (nl80211_setup_ap(bss))
 			return -1;
-	} else if (!ret && !is_ap_interface(nlmode)) {
+	} else if (was_ap) {
 		/* Remove additional AP mode functionality */
-		if (was_ap && drv->device_ap_sme)
-			wpa_driver_nl80211_probe_req_report(bss, 0);
-		nl80211_remove_monitor_interface(drv);
-		bss->beacon_set = 0;
-	}
-
-	if (!ret && is_p2p_interface(drv->nlmode)) {
-		nl80211_disable_11b_rates(drv, drv->ifindex, 1);
-		drv->disabled_11b_rates = 1;
-	} else if (!ret && drv->disabled_11b_rates) {
-		nl80211_disable_11b_rates(drv, drv->ifindex, 0);
-		drv->disabled_11b_rates = 0;
+		nl80211_teardown_ap(bss);
 	}
 
-	if (ret)
-		wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d "
-			   "from %d failed", nlmode, drv->nlmode);
-
-	return ret;
+	return 0;
 }