Patchwork [16/23] P2P: consider channel optimizations for additional cases

login
register
mail settings
Submitter Ilan Peer
Date July 7, 2014, 11:21 a.m.
Message ID <1404732076-32252-17-git-send-email-ilan.peer@intel.com>
Download mbox | patch
Permalink /patch/367519/
State New
Headers show

Comments

Ilan Peer - July 7, 2014, 11:21 a.m.
Re-factor the code, so channel optimizations would be also triggered
upon the following changes: channel updates from the kernel,
disallow_freq interface etc.

Signed-off-by: Ilan Peer <ilan.peer@intel.com>
---
 wpa_supplicant/p2p_supplicant.c |   82 ++++++++++++++-------------------------
 1 file changed, 30 insertions(+), 52 deletions(-)

Patch

diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index ca6c84e..3a6ae75 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -130,7 +130,13 @@  static int wpas_p2p_stop_find_oper(struct wpa_supplicant *wpa_s);
 static void wpas_stop_listen(void *ctx);
 static void wpas_p2p_psk_failure_removal(void *eloop_ctx, void *timeout_ctx);
 static void wpas_p2p_group_deinit(struct wpa_supplicant *wpa_s);
+static void wpas_p2p_optimize_listen_channel(struct wpa_supplicant *wpa_s,
+					     struct wpa_used_freq_data *freqs,
+					     unsigned int num);
 static void wpas_p2p_move_go(void *eloop_ctx, void *timeout_ctx);
+static void wpas_p2p_consider_moving_gos(struct wpa_supplicant *wpa_s,
+					 struct wpa_used_freq_data *freqs,
+					 unsigned int num);
 
 /*
  * Get the number of concurrent channels that the HW can operate, but that are
@@ -3752,12 +3758,12 @@  static enum chan_allowed wpas_p2p_verify_channel(struct wpa_supplicant *wpa_s,
 static int wpas_p2p_setup_channels(struct wpa_supplicant *wpa_s,
 				   struct p2p_channels *chan,
 				   struct p2p_channels *cli_chan,
-				   struct p2p_channels *ind_chan)
+				   struct p2p_channels *ind_chan,
+				   struct wpa_used_freq_data *freqs,
+				   unsigned int num)
 {
 	struct hostapd_hw_modes *mode;
 	int cla, op, cli_cla, ind_cla;
-	struct wpa_used_freq_data *freqs;
-	unsigned int num = wpa_s->num_multichan_concurrent;
 
 	if (wpa_s->hw.modes == NULL) {
 		wpa_printf(MSG_DEBUG, "P2P: Driver did not support fetching "
@@ -3767,10 +3773,6 @@  static int wpas_p2p_setup_channels(struct wpa_supplicant *wpa_s,
 						 ind_chan);
 	}
 
-	/* Note: the flow can still be handled even if the allocation fails */
-	freqs = os_calloc(num, sizeof(struct wpa_used_freq_data));
-	num = get_shared_radio_freqs_data(wpa_s, freqs, num);
-
 	cla = cli_cla = ind_cla = 0;
 
 	for (op = 0; op_class[op].op_class; op++) {
@@ -3840,7 +3842,6 @@  static int wpas_p2p_setup_channels(struct wpa_supplicant *wpa_s,
 	cli_chan->reg_classes = cli_cla;
 	ind_chan->reg_classes = ind_cla;
 
-	os_free(freqs);
 	return 0;
 }
 
@@ -4179,7 +4180,7 @@  int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s)
 		os_memcpy(p2p.country, "XX\x04", 3);
 
 	if (wpas_p2p_setup_channels(wpa_s, &p2p.channels, &p2p.cli_channels,
-				    &p2p.indoor_channels)) {
+				    &p2p.indoor_channels, NULL, 0)) {
 		wpa_printf(MSG_ERROR, "P2P: Failed to configure supported "
 			   "channel list");
 		return -1;
@@ -6800,15 +6801,23 @@  void wpas_p2p_pbc_overlap_cb(void *eloop_ctx, void *timeout_ctx)
 void wpas_p2p_update_channel_list(struct wpa_supplicant *wpa_s)
 {
 	struct p2p_channels chan, cli_chan, ind_chan;
-	struct wpa_supplicant *ifs;
+	struct wpa_used_freq_data *freqs = NULL;
+	unsigned int num = wpa_s->num_multichan_concurrent;
 
 	if (wpa_s->global == NULL || wpa_s->global->p2p == NULL)
 		return;
 
+	freqs = os_calloc(num, sizeof(struct wpa_used_freq_data));
+	if (!freqs)
+		return;
+
+	num = get_shared_radio_freqs_data(wpa_s, freqs, num);
+
 	os_memset(&chan, 0, sizeof(chan));
 	os_memset(&cli_chan, 0, sizeof(cli_chan));
 	os_memset(&ind_chan, 0, sizeof(ind_chan));
-	if (wpas_p2p_setup_channels(wpa_s, &chan, &cli_chan, &ind_chan)) {
+	if (wpas_p2p_setup_channels(wpa_s, &chan, &cli_chan, &ind_chan, freqs,
+				    num)) {
 		wpa_printf(MSG_ERROR, "P2P: Failed to update supported "
 			   "channel list");
 		return;
@@ -6817,27 +6826,17 @@  void wpas_p2p_update_channel_list(struct wpa_supplicant *wpa_s)
 	p2p_update_channel_list(wpa_s->global->p2p, &chan, &cli_chan,
 				&ind_chan);
 
-	for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
-		int freq;
-		if (!ifs->current_ssid ||
-		    !ifs->current_ssid->p2p_group ||
-		    (ifs->current_ssid->mode != WPAS_MODE_P2P_GO &&
-		     ifs->current_ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION))
-				continue;
-		freq = ifs->current_ssid->frequency;
-		if (wpas_freq_included(ifs, &chan, freq)) {
-			wpa_dbg(ifs, MSG_DEBUG,
-				"P2P GO operating frequency %d MHz in valid range",
-				freq);
-			continue;
-		}
+	wpas_p2p_optimize_listen_channel(wpa_s, freqs, num);
 
-		wpa_dbg(ifs, MSG_DEBUG,
-			"P2P GO operating in invalid frequency %d MHz",	freq);
-		/* TODO: Consider using CSA or removing the group within
-		 * wpa_supplicant */
-		wpa_msg(ifs, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP);
-	}
+	/*
+	 * The used frequencies map changed, so it is possible that a GO is
+	 * using an channel that is no longer valid for P2P use, or it is also
+	 * possible that due to policy consideration, it would preferable to
+	 * move it to a frequency already used by other station interfaces
+	 */
+	wpas_p2p_consider_moving_gos(wpa_s, freqs, num);
+
+	os_free(freqs);
 }
 
 
@@ -8274,9 +8273,6 @@  static void wpas_p2p_consider_moving_gos(struct wpa_supplicant *wpa_s,
 
 void wpas_p2p_indicate_state_change(struct wpa_supplicant *wpa_s)
 {
-	struct wpa_used_freq_data *freqs;
-	unsigned int num = wpa_s->num_multichan_concurrent;
-
 	if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
 		return;
 
@@ -8294,24 +8290,6 @@  void wpas_p2p_indicate_state_change(struct wpa_supplicant *wpa_s)
 	}
 
 	wpas_p2p_update_channel_list(wpa_s);
-
-	freqs = os_calloc(num, sizeof(struct wpa_used_freq_data));
-	if (!freqs)
-		return;
-
-	num = get_shared_radio_freqs_data(wpa_s, freqs, num);
-
-	wpas_p2p_optimize_listen_channel(wpa_s, freqs, num);
-
-	/*
-	 * The used frequencies map changed, so it is possible that a GO is
-	 * using an channel that is no longer valid for P2P use, or it is also
-	 * possible that due to policy consideration, it would preferable to
-	 * move it to a frequency already used by other station interfaces
-	 */
-	wpas_p2p_consider_moving_gos(wpa_s, freqs, num);
-
-	os_free(freqs);
 }