[PATCH 06/14] wpa_supplicant: Implement wpas_p2p_move_go_csa

Ilan Peer ilan.peer
Mon May 19 00:07:08 PDT 2014


From: Andrei Otcheretianski <andrei.otcheretianski at intel.com>

Use channel switch mechanism to move GO to a new channel, when required.
In order to be able to reconfigure the GO channel, split wpa_supplicant_conf_ap
function, so the frequency configuration part can be reused to find additional
CSA settings.

Signed-off-by: Andrei Otcheretianski <andrei.otcheretianski at intel.com>
---
 wpa_supplicant/ap.c             |   28 ++++++---
 wpa_supplicant/ap.h             |    4 ++
 wpa_supplicant/p2p_supplicant.c |  120 ++++++++++++++++++++++++++++++++++++++-
 3 files changed, 140 insertions(+), 12 deletions(-)

diff --git a/wpa_supplicant/ap.c b/wpa_supplicant/ap.c
index 945dc67..735260e 100644
--- a/wpa_supplicant/ap.c
+++ b/wpa_supplicant/ap.c
@@ -75,16 +75,10 @@ no_vht:
 #endif /* CONFIG_IEEE80211N */
 
 
-static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
-				  struct wpa_ssid *ssid,
-				  struct hostapd_config *conf)
+int wpas_conf_ap_freq(struct wpa_supplicant *wpa_s,
+		      struct wpa_ssid *ssid,
+		      struct hostapd_config *conf)
 {
-	struct hostapd_bss_config *bss = conf->bss[0];
-
-	conf->driver = wpa_s->driver;
-
-	os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
-
 	conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency,
 					       &conf->channel);
 	if (conf->hw_mode == NUM_HOSTAPD_MODES) {
@@ -156,6 +150,22 @@ static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
 	}
 #endif /* CONFIG_IEEE80211N */
 
+	return 0;
+}
+
+
+static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
+				  struct wpa_ssid *ssid,
+				  struct hostapd_config *conf)
+{
+	struct hostapd_bss_config *bss = conf->bss[0];
+
+	conf->driver = wpa_s->driver;
+	os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
+
+	if (wpas_conf_ap_freq(wpa_s, ssid, conf))
+		return -1;
+
 #ifdef CONFIG_P2P
 	if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
 	    (ssid->mode == WPAS_MODE_P2P_GO ||
diff --git a/wpa_supplicant/ap.h b/wpa_supplicant/ap.h
index 8aa5ffa..a91e286 100644
--- a/wpa_supplicant/ap.h
+++ b/wpa_supplicant/ap.h
@@ -10,8 +10,12 @@
 #ifndef AP_H
 #define AP_H
 
+struct hostapd_config;
 int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
 			     struct wpa_ssid *ssid);
+int wpas_conf_ap_freq(struct wpa_supplicant *wpa_s,
+		      struct wpa_ssid *ssid,
+		      struct hostapd_config *conf);
 void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s);
 void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
 				const u8 *src_addr, const u8 *buf, size_t len);
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index dabdf7a..7d5f98c 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -52,6 +52,13 @@
  */
 #define P2P_GO_FREQ_CHANGE_TIME 30
 
+/**
+ * Defines CSA parameters which are used when GO evacuates the no longer valid
+ * channel (and if the driver supports channel switch)
+ */
+#define P2P_GO_CSA_COUNT 7
+#define P2P_GO_CSA_BLOCK_TX 0
+
 #ifndef P2P_MAX_CLIENT_IDLE
 /*
  * How many seconds to try to reconnect to the GO when connection in P2P client
@@ -8110,14 +8117,121 @@ static void wpas_p2p_optimize_listen_channel(struct wpa_supplicant *wpa_s,
 
 static int wpas_p2p_move_go_csa(struct wpa_supplicant *wpa_s)
 {
+	struct hostapd_config *conf;
+	struct p2p_go_neg_results params;
+	struct csa_settings csa_settings;
+	struct wpa_ssid *current_ssid = wpa_s->current_ssid;
+	int old_freq = current_ssid->frequency;
+	int ret;
+	u8 chan;
+
 	if (!wpa_s->csa_supported) {
 		wpa_dbg(wpa_s, MSG_DEBUG, "CSA is not enabled");
 		return -1;
 	}
 
-	/* TODO: add csa support */
-	wpa_dbg(wpa_s, MSG_DEBUG, "Move GO with CSA is not implemented");
-	return -1;
+	/*
+	 * TODO: this function may not always work correctly. For example,
+	 * when we have a running GO and a BSS on a DFS channel.
+	 */
+	if (wpas_p2p_init_go_params(wpa_s, &params, 0, 0, 0, NULL)) {
+		wpa_dbg(wpa_s, MSG_DEBUG,
+			"P2P CSA: Failed to select new frequency for GO");
+		return -1;
+	}
+
+	if (current_ssid->frequency == params.freq) {
+		wpa_dbg(wpa_s, MSG_DEBUG,
+			"P2P CSA: Selected same freq. Not moving GO");
+		return 0;
+	}
+
+	conf = hostapd_config_defaults();
+	if (!conf) {
+		wpa_dbg(wpa_s, MSG_DEBUG,
+			"P2P CSA: Failed to allocate default config");
+		return -1;
+	}
+
+	current_ssid->frequency = params.freq;
+	if (wpas_conf_ap_freq(wpa_s, current_ssid, conf)) {
+		wpa_dbg(wpa_s, MSG_DEBUG,
+			"P2P CSA: Failed to create new GO config");
+		ret = -1;
+		goto out;
+	}
+
+	if (conf->hw_mode != wpa_s->ap_iface->current_mode->mode) {
+		wpa_dbg(wpa_s, MSG_DEBUG,
+			"P2P CSA: CSA to a different band is not supported");
+		ret = -1;
+		goto out;
+	}
+
+	os_memset(&csa_settings, 0, sizeof(csa_settings));
+	csa_settings.cs_count = P2P_GO_CSA_COUNT;
+	csa_settings.block_tx = P2P_GO_CSA_BLOCK_TX;
+	csa_settings.freq_params.freq = params.freq;
+
+	if (ieee80211_freq_to_channel_ext(params.freq,
+					  conf->secondary_channel,
+					  conf->ieee80211ac,
+					  &wpa_s->ap_iface->cs_oper_class,
+					  &chan) ==
+	    NUM_HOSTAPD_MODES) {
+		wpa_dbg(wpa_s, MSG_DEBUG,
+			"P2P CSA: Selected invalid frequency");
+		ret = -1;
+		goto out;
+	}
+
+	csa_settings.freq_params.channel = chan;
+	csa_settings.freq_params.sec_channel_offset = conf->secondary_channel;
+	csa_settings.freq_params.ht_enabled = conf->ieee80211n;
+
+	if (conf->ieee80211ac) {
+		int freq1 = 0, freq2 = 0;
+
+		if (conf->vht_oper_centr_freq_seg0_idx)
+			freq1 = ieee80211_channel_to_freq(
+					conf->vht_oper_centr_freq_seg0_idx,
+					wpa_s->ap_iface->cs_oper_class);
+
+		if (conf->vht_oper_centr_freq_seg1_idx)
+			freq2 = ieee80211_channel_to_freq(
+					conf->vht_oper_centr_freq_seg1_idx,
+					wpa_s->ap_iface->cs_oper_class);
+
+		if (freq1 < 0 || freq2 < 0) {
+			wpa_dbg(wpa_s, MSG_DEBUG,
+				"P2P CSA: Selected invalid vht center freqs");
+			ret = -1;
+			goto out;
+		}
+
+		csa_settings.freq_params.vht_enabled = conf->ieee80211ac;
+		csa_settings.freq_params.center_freq1 = freq1;
+		csa_settings.freq_params.center_freq2 = freq2;
+
+		switch (conf->vht_oper_chwidth) {
+		case VHT_CHANWIDTH_USE_HT:
+			csa_settings.freq_params.bandwidth = 40;
+			break;
+		case VHT_CHANWIDTH_80MHZ:
+		case VHT_CHANWIDTH_80P80MHZ:
+			csa_settings.freq_params.bandwidth = 80;
+			break;
+		case VHT_CHANWIDTH_160MHZ:
+			csa_settings.freq_params.bandwidth = 160;
+			break;
+		}
+	}
+
+	ret = ap_switch_channel(wpa_s, &csa_settings);
+out:
+	current_ssid->frequency = old_freq;
+	hostapd_config_free(conf);
+	return ret;
 }
 
 static void wpas_p2p_move_go_no_csa(struct wpa_supplicant *wpa_s)
-- 
1.7.10.4




More information about the Hostap mailing list