Patchwork [11/23] P2P: Add a function to compute the group common freqs

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

Comments

Ilan Peer - July 7, 2014, 11:21 a.m.
Add a function to compute the group common frequencies, and
use if to update the group_common_frequencies as part of the
channel switch flows.

Signed-off-by: Ilan Peer <ilan.peer@intel.com>
---
 src/p2p/p2p.h                   |   11 ++++++++++
 src/p2p/p2p_group.c             |   45 +++++++++++++++++++++++++++++++++++++++
 wpa_supplicant/p2p_supplicant.c |   33 ++++++++++++++++++++++++++++
 3 files changed, 89 insertions(+)

Patch

diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h
index 2c4b86d..0651358 100644
--- a/src/p2p/p2p.h
+++ b/src/p2p/p2p.h
@@ -1997,4 +1997,15 @@  void p2p_loop_on_known_peers(struct p2p_data *p2p,
 						   void *user_data),
 			     void *user_data);
 
+/**
+ *  p2p_group_get_common_freqs - get the group common frequencies
+ * @group: P2P group context from p2p_group_init()
+ * @common_freqs: on return will hold the group common frequencies
+ * @num: on return will hold the number of group common frequencies
+ * Returns: 0 on success, -1 otherwise
+ */
+int p2p_group_get_common_freqs(struct p2p_group *group,
+			       int *common_freqs,
+			       unsigned int *num);
+
 #endif /* P2P_H */
diff --git a/src/p2p/p2p_group.c b/src/p2p/p2p_group.c
index aa075bd..cdaa7ef 100644
--- a/src/p2p/p2p_group.c
+++ b/src/p2p/p2p_group.c
@@ -1033,3 +1033,48 @@  void p2p_loop_on_all_groups(struct p2p_data *p2p,
 			break;
 	}
 }
+
+
+
+int p2p_group_get_common_freqs(struct p2p_group *group,
+			       int *common_freqs,
+			       unsigned int *num)
+
+{
+	struct p2p_channels intersect, res;
+	struct p2p_group_member *m;
+
+	if (!group || !common_freqs || !num)
+		return -1;
+
+	os_memset(&intersect, 0, sizeof(intersect));
+	os_memset(&res, 0, sizeof(res));
+
+	p2p_channels_union(&intersect, &group->p2p->cfg->channels,
+			   &intersect);
+
+	p2p_channels_dump(group->p2p,
+			  "Group Common freqs before iterating members",
+			  &intersect);
+
+	for (m = group->members; m; m = m->next) {
+		struct p2p_device *dev;
+
+		dev = p2p_get_device(group->p2p, m->dev_addr);
+		if (!dev)
+			continue;
+
+		p2p_channels_intersect(&intersect,
+				       &dev->channels,
+				       &res);
+		intersect = res;
+	}
+
+	p2p_channels_dump(group->p2p, "Group Common Channels", &intersect);
+
+	os_memset(common_freqs, 0, *num * sizeof(int));
+	*num = p2p_channels_to_freqs(&intersect, common_freqs, *num);
+
+	return 0;
+}
+
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index 5b4b59c..0f9cdf7 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -2968,6 +2968,35 @@  static int freq_included(const struct p2p_channels *channels, unsigned int freq)
 }
 
 
+static void wpas_p2p_go_update_common_freqs(struct wpa_supplicant *wpa_s)
+{
+	unsigned int num = P2P_MAX_CHANNELS;
+	int *common_freqs;
+	int ret;
+
+	p2p_go_dump_common_freqs(wpa_s);
+	common_freqs = os_zalloc(num * sizeof(int));
+	if (!common_freqs)
+		return;
+
+	ret = p2p_group_get_common_freqs(wpa_s->p2p_group,
+					 common_freqs,
+					 &num);
+
+	if (ret < 0) {
+		wpa_dbg(wpa_s, MSG_DEBUG,
+			"Failed to get group common freqs");
+		os_free(common_freqs);
+		return;
+	}
+
+	os_free(wpa_s->p2p_group_common_freqs);
+	wpa_s->p2p_group_common_freqs = common_freqs;
+	wpa_s->p2p_group_common_freqs_num = num;
+	p2p_go_dump_common_freqs(wpa_s);
+}
+
+
 /*
  * Check if the given frequency is one of the possible operating frequencies
  * set after the completion of the GoN.
@@ -8085,6 +8114,8 @@  static void wpas_p2p_move_go(void *eloop_ctx, void *timeout_ctx)
 	if (!wpa_s->ap_iface || !wpa_s->current_ssid)
 		return;
 
+	wpas_p2p_go_update_common_freqs(wpa_s);
+
 	/*
 	 * first try a channel switch flow, if it is not supported or fails,
 	 * perform take down the GO and bring it up again
@@ -8113,6 +8144,8 @@  static void wpas_p2p_consider_moving_one_go(struct wpa_supplicant *wpa_s,
 	unsigned int timeout;
 	int freq;
 
+	wpas_p2p_go_update_common_freqs(wpa_s);
+
 	freq = wpa_s->current_ssid->frequency;
 	for (i = 0, invalid_freq = 0; i < num; i++) {
 		if (freqs[i].freq == freq) {