[PATCH 11/24] P2P: Add a function to compute the group common freqs

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


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 at intel.com>
---
 src/p2p/p2p.h                   |   11 ++++++++++
 src/p2p/p2p_group.c             |   42 +++++++++++++++++++++++++++++++++++++++
 wpa_supplicant/p2p_supplicant.c |   34 +++++++++++++++++++++++++++++++
 3 files changed, 87 insertions(+)

diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h
index 2934bfa..bd125f3 100644
--- a/src/p2p/p2p.h
+++ b/src/p2p/p2p.h
@@ -1804,6 +1804,17 @@ const u8 * p2p_group_get_dev_addr(struct p2p_group *group, const u8 *addr);
 int p2p_group_is_client_connected(struct p2p_group *group, const u8 *dev_addr);
 
 /**
+ *  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);
+
+/**
  * p2p_get_peer_found - Get P2P peer info structure of a found peer
  * @p2p: P2P module context from p2p_init()
  * @addr: P2P Device Address of the peer or %NULL to indicate the first peer
diff --git a/src/p2p/p2p_group.c b/src/p2p/p2p_group.c
index 395ca08..f3eff67 100644
--- a/src/p2p/p2p_group.c
+++ b/src/p2p/p2p_group.c
@@ -1013,3 +1013,45 @@ int p2p_group_get_freq(struct p2p_group *group)
 {
 	return group->cfg->freq;
 }
+
+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 5954afe..bcdb1c1 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -2964,6 +2964,36 @@ 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.
@@ -8029,6 +8059,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
@@ -8056,6 +8088,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) {
-- 
1.7.10.4




More information about the Hostap mailing list