[PATCH v2 03/12] P2PS: Add channel policy to PD Request

Ilan Peer ilan.peer
Thu Oct 8 02:35:58 PDT 2015


Add operating channel selection and channel list processing similar to
that done when building GO Negotiation Request, i.e., consider the currently
used channels, configured channels, etc.

P2PS introduces a flow where a responder needs to provide channel data
without being previously aware of the current constraints, i.e., the
channels currently in use by other interfaces. To handle this, extend
the get_group_capability() callback to also handle channel selection
aspects of group capabilities.

In case that there is an active P2P GO that is going to be used
for the P2PS PD, force its current operating frequency in the PD
attributes.

Signed-off-by: Ilan Peer <ilan.peer at intel.com>
---
 src/p2p/p2p.c                   |  8 ++---
 src/p2p/p2p.h                   | 32 +++++++++++++-----
 src/p2p/p2p_pd.c                | 72 +++++++++++++++++++++++++----------------
 wpa_supplicant/p2p_supplicant.c | 60 +++++++++++++++++++++-------------
 4 files changed, 110 insertions(+), 62 deletions(-)

diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c
index 6984cb4..d861519 100644
--- a/src/p2p/p2p.c
+++ b/src/p2p/p2p.c
@@ -1459,7 +1459,7 @@ static void p2p_prepare_channel_best(struct p2p_data *p2p)
 
 
 /**
- * p2p_prepare_channel - Select operating channel for GO Negotiation
+ * p2p_prepare_channel - Select operating channel for GO Negotiation or P2PS PD
  * @p2p: P2P module context from p2p_init()
  * @dev: Selected peer device
  * @force_freq: Forced frequency in MHz or 0 if not forced
@@ -1468,9 +1468,9 @@ static void p2p_prepare_channel_best(struct p2p_data *p2p)
  * Returns: 0 on success, -1 on failure (channel not supported for P2P)
  *
  * This function is used to do initial operating channel selection for GO
- * Negotiation prior to having received peer information. The selected channel
- * may be further optimized in p2p_reselect_channel() once the peer information
- * is available.
+ * Negotiation prior to having received peer information or for P2PS PD
+ * signalling. The selected channel may be further optimized in
+ * p2p_reselect_channel() once the peer information is available.
  */
 int p2p_prepare_channel(struct p2p_data *p2p, struct p2p_device *dev,
 			unsigned int force_freq, unsigned int pref_freq, int go)
diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h
index b4060be..8457dbb 100644
--- a/src/p2p/p2p.h
+++ b/src/p2p/p2p.h
@@ -224,6 +224,16 @@ struct p2ps_provision {
 	u8 cpt_priority[P2PS_FEATURE_CAPAB_CPT_MAX + 1];
 
 	/**
+	 * force_freq - the only allowed channel frequency in MHz or 0.
+	 */
+	int force_freq;
+
+	/**
+	 * pref_freq - preferred operating frequency in MHz or 0.
+	 */
+	int pref_freq;
+
+	/**
 	 * info - Vendor defined extra Provisioning information
 	 */
 	char info[0];
@@ -1024,14 +1034,16 @@ struct p2p_config {
 	 * @ssid_len: Buffer for returning length of @ssid
 	 * @group_iface: Buffer for returning whether a separate group interface
 	 *	would be used
+	 * @freq: if a currently running P2P GO is to be used, its current freq
+	 *      would be used
 	 * Returns: 1 if GO info found, 0 otherwise
 	 *
 	 * This is used to compose New Group settings (SSID, and intended
 	 * address) during P2PS provisioning if results of provisioning *might*
 	 * result in our being an autonomous GO.
 	 */
-	int (*get_go_info)(void *ctx, u8 *intended_addr,
-			   u8 *ssid, size_t *ssid_len, int *group_iface);
+	int (*get_go_info)(void *ctx, u8 *intended_addr, u8 *ssid,
+			   size_t *ssid_len, int *group_iface, int *freq);
 
 	/**
 	 * remove_stale_groups - Remove stale P2PS groups
@@ -1070,14 +1082,18 @@ struct p2p_config {
 
 	/**
 	 * p2ps_group_capability - Determine group capability
+	 * @incoming: peer requested roles, expressed with P2PS_SETUP* bitmap.
+	 * @role: local roles, expressed with P2PS_SETUP* bitmap.
+	 * @force_freq: variable for returning forced frequency for the group.
+	 * @pref_freq: variable for returning preferred frequency for the group.
+	 * Returns: P2PS_SETUP_* bitmap of group capability result.
 	 *
-	 * This function can be used to determine group capability based on
-	 * information from P2PS PD exchange and the current state of ongoing
-	 * groups and driver capabilities.
-	 *
-	 * P2PS_SETUP_* bitmap is used as the parameters and return value.
+	 * This function can be used to determine group capability and
+	 * frequencies based on information from P2PS PD exchange and the
+	 * current state of ongoing groups and driver capabilities.
 	 */
-	u8 (*p2ps_group_capability)(void *ctx, u8 incoming, u8 role);
+	u8 (*p2ps_group_capability)(void *ctx, u8 incoming, u8 role,
+				    int *force_freq, int *pref_freq);
 
 	/**
 	 * get_pref_freq_list - Get preferred frequency list for an interface
diff --git a/src/p2p/p2p_pd.c b/src/p2p/p2p_pd.c
index b94f96e..ca8c70d 100644
--- a/src/p2p/p2p_pd.c
+++ b/src/p2p/p2p_pd.c
@@ -40,21 +40,30 @@ static void p2p_build_wps_ie_config_methods(struct wpabuf *buf,
 }
 
 
-static void p2ps_add_new_group_info(struct p2p_data *p2p, struct wpabuf *buf)
+static void p2ps_add_new_group_info(struct p2p_data *p2p,
+				    struct p2p_device *dev,
+				    struct wpabuf *buf)
 {
 	int found;
 	u8 intended_addr[ETH_ALEN];
 	u8 ssid[SSID_MAX_LEN];
 	size_t ssid_len;
 	int group_iface;
+	int force_freq;
 
 	if (!p2p->cfg->get_go_info)
 		return;
 
 	found = p2p->cfg->get_go_info(
 		p2p->cfg->cb_ctx, intended_addr, ssid,
-		&ssid_len, &group_iface);
+		&ssid_len, &group_iface, &force_freq);
 	if (found) {
+		if (force_freq > 0) {
+			p2p->p2ps_prov->force_freq = force_freq;
+			p2p->p2ps_prov->pref_freq = 0;
+
+			p2p_prepare_channel(p2p, dev, force_freq, 0, 0);
+		}
 		p2p_buf_add_group_id(buf, p2p->cfg->dev_addr,
 				     ssid, ssid_len);
 
@@ -96,7 +105,7 @@ static void p2ps_add_pd_req_attrs(struct p2p_data *p2p, struct p2p_device *dev,
 	/* If we might be explicite group owner, add GO details */
 	if (prov->conncap & (P2PS_SETUP_GROUP_OWNER |
 			     P2PS_SETUP_NEW))
-		p2ps_add_new_group_info(p2p, buf);
+		p2ps_add_new_group_info(p2p, dev, buf);
 
 	if (prov->status >= 0)
 		p2p_buf_add_status(buf, (u8) prov->status);
@@ -109,25 +118,18 @@ static void p2ps_add_pd_req_attrs(struct p2p_data *p2p, struct p2p_device *dev,
 			go_dev_addr, ssid, &ssid_len, intended_addr);
 	}
 
-	/* Add Operating Channel if conncap includes GO */
 	if (shared_group ||
-	    (prov->conncap & (P2PS_SETUP_GROUP_OWNER |
-			      P2PS_SETUP_NEW))) {
-		u8 tmp;
-
-		p2p_go_select_channel(p2p, dev, &tmp);
-
-		if (p2p->op_reg_class && p2p->op_channel)
-			p2p_buf_add_operating_channel(buf, p2p->cfg->country,
-						      p2p->op_reg_class,
-						      p2p->op_channel);
-		else
-			p2p_buf_add_operating_channel(buf, p2p->cfg->country,
-						      p2p->cfg->op_reg_class,
-						      p2p->cfg->op_channel);
-	}
+	    (prov->conncap & P2PS_SETUP_CLIENT) ||
+	    (prov->conncap & P2PS_SETUP_NEW))
+		p2p_buf_add_channel_list(buf, p2p->cfg->country,
+					 &p2p->channels);
 
-	p2p_buf_add_channel_list(buf, p2p->cfg->country, &p2p->cfg->channels);
+	if ((shared_group && !is_zero_ether_addr(intended_addr)) ||
+	    (prov->conncap & P2PS_SETUP_GROUP_OWNER) ||
+	    (prov->conncap & P2PS_SETUP_NEW))
+		p2p_buf_add_operating_channel(buf, p2p->cfg->country,
+					      p2p->op_reg_class,
+					      p2p->op_channel);
 
 	if (prov->info[0])
 		p2p_buf_add_session_info(buf, prov->info);
@@ -328,7 +330,7 @@ static struct wpabuf * p2p_build_prov_disc_resp(struct p2p_data *p2p,
 		}
 
 		if (!persist && (prov->conncap & P2PS_SETUP_GROUP_OWNER))
-			p2ps_add_new_group_info(p2p, buf);
+			p2ps_add_new_group_info(p2p, dev, buf);
 
 		/* Add Operating Channel if conncap indicates GO */
 		if (persist || (prov->conncap & P2PS_SETUP_GROUP_OWNER)) {
@@ -350,7 +352,7 @@ static struct wpabuf * p2p_build_prov_disc_resp(struct p2p_data *p2p,
 		}
 
 		p2p_buf_add_channel_list(buf, p2p->cfg->country,
-					 &p2p->cfg->channels);
+					 &p2p->channels);
 
 		if (!persist && (status == P2P_SC_SUCCESS ||
 				 status == P2P_SC_SUCCESS_DEFERRED))
@@ -707,9 +709,15 @@ void p2p_process_prov_disc_req(struct p2p_data *p2p, const u8 *sa,
 	}
 
 	if (p2ps_adv) {
+		int forced_freq, pref_freq;
+
 		auto_accept = p2ps_adv->auto_accept;
 		conncap = p2p->cfg->p2ps_group_capability(p2p->cfg->cb_ctx,
-							  conncap, auto_accept);
+							  conncap, auto_accept,
+							  &forced_freq,
+							  &pref_freq);
+
+		p2p_prepare_channel(p2p, dev, forced_freq, pref_freq, 0);
 
 		p2p_dbg(p2p, "Conncap: local:%d remote:%d result:%d",
 			auto_accept, remote_conncap, conncap);
@@ -756,6 +764,8 @@ void p2p_process_prov_disc_req(struct p2p_data *p2p, const u8 *sa,
 			}
 
 			tmp = p2p->p2ps_prov;
+			tmp->force_freq = forced_freq;
+			tmp->pref_freq = pref_freq;
 			if (conncap) {
 				tmp->conncap = conncap;
 				tmp->status = P2P_SC_SUCCESS;
@@ -818,10 +828,9 @@ void p2p_process_prov_disc_req(struct p2p_data *p2p, const u8 *sa,
 
 	conncap = p2p->cfg->p2ps_group_capability(p2p->cfg->cb_ctx,
 						  remote_conncap,
-						  p2p->p2ps_prov->conncap);
-
-	p2p_dbg(p2p, "Conncap: local:%d remote:%d result:%d",
-		p2p->p2ps_prov->conncap, remote_conncap, conncap);
+						  p2p->p2ps_prov->conncap,
+						  &p2p->p2ps_prov->force_freq,
+						  &p2p->p2ps_prov->pref_freq);
 
 	resp_fcap.cpt = p2ps_own_preferred_cpt(p2p->p2ps_prov->cpt_priority,
 					       req_fcap->cpt);
@@ -829,6 +838,11 @@ void p2p_process_prov_disc_req(struct p2p_data *p2p, const u8 *sa,
 	p2p_dbg(p2p, "cpt: local:0x%x remote:0x%x result:0x%x",
 		p2p->p2ps_prov->cpt_mask, req_fcap->cpt, resp_fcap.cpt);
 
+	p2p_prepare_channel(p2p, dev,
+			    p2p->p2ps_prov->force_freq,
+			    p2p->p2ps_prov->pref_freq,
+			    0);
+
 	/*
 	 * Ensure that if we asked for PIN originally, our method is consistent
 	 * with original request.
@@ -1465,6 +1479,10 @@ int p2p_send_prov_disc_req(struct p2p_data *p2p, struct p2p_device *dev,
 			"Building PD Request based on P2PS config method 0x%x status %d --> req_config_methods 0x%x",
 			p2p->p2ps_prov->method, p2p->p2ps_prov->status,
 			dev->req_config_methods);
+
+		if (p2p_prepare_channel(p2p, dev, p2p->p2ps_prov->force_freq,
+					p2p->p2ps_prov->pref_freq, 1) < 0)
+			return -1;
 	}
 
 	req = p2p_build_prov_disc_req(p2p, dev, join);
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index 809c455..ac77964 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -124,6 +124,10 @@ wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated,
 			 int go);
 static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s, int freq,
 			       const u8 *ssid, size_t ssid_len);
+static int wpas_p2p_setup_freqs(struct wpa_supplicant *wpa_s, int freq,
+				int *force_freq, int *pref_freq, int go,
+				unsigned int *pref_freq_list,
+				unsigned int *num_pref_freq);
 static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq,
 				   const u8 *ssid, size_t ssid_len);
 static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx);
@@ -605,20 +609,6 @@ wpas_p2p_get_cli_group(struct wpa_supplicant *wpa_s)
 }
 
 
-/* Find an active P2P group where we are the GO */
-static struct wpa_ssid * wpas_p2p_group_go_ssid(struct wpa_supplicant *wpa_s,
-						u8 *bssid)
-{
-	struct wpa_supplicant *go = wpas_p2p_get_go_group(wpa_s);
-
-	if (!go)
-		return NULL;
-
-	os_memcpy(bssid, go->own_addr, ETH_ALEN);
-	return go->current_ssid;
-}
-
-
 /* Find a persistent group where we are the GO */
 static struct wpa_ssid *
 wpas_p2p_get_persistent_go(struct wpa_supplicant *wpa_s)
@@ -634,7 +624,8 @@ wpas_p2p_get_persistent_go(struct wpa_supplicant *wpa_s)
 }
 
 
-static u8 p2ps_group_capability(void *ctx, u8 incoming, u8 role)
+static u8 p2ps_group_capability(void *ctx, u8 incoming, u8 role,
+				int *force_freq, int *pref_freq)
 {
 	struct wpa_supplicant *wpa_s = ctx;
 	struct wpa_ssid *s;
@@ -646,6 +637,19 @@ static u8 p2ps_group_capability(void *ctx, u8 incoming, u8 role)
 
 	wpa_printf(MSG_DEBUG, "P2P: Conncap - in:%d role:%d", incoming, role);
 
+	if (force_freq && pref_freq) {
+		unsigned int pref_freq_list[P2P_MAX_PREF_CHANNELS], size;
+		*force_freq = 0;
+		*pref_freq = 0;
+
+		if (!wpas_p2p_setup_freqs(wpa_s, 0, force_freq, pref_freq, 0,
+					  pref_freq_list, &size))
+			wpas_p2p_set_own_freq_preference(wpa_s,
+							 *force_freq ?
+							 *force_freq :
+							 *pref_freq);
+	}
+
 	/*
 	 * For non-concurrent capable devices:
 	 * If persistent_go, then no new.
@@ -3684,12 +3688,12 @@ static int wpas_get_persistent_group(void *ctx, const u8 *addr, const u8 *ssid,
 }
 
 
-static int wpas_get_go_info(void *ctx, u8 *intended_addr,
-			    u8 *ssid, size_t *ssid_len, int *group_iface)
+static int wpas_get_go_info(void *ctx, u8 *intended_addr, u8 *ssid,
+			    size_t *ssid_len, int *group_iface, int *freq)
 {
 	struct wpa_supplicant *wpa_s = ctx;
+	struct wpa_supplicant *go;
 	struct wpa_ssid *s;
-	u8 bssid[ETH_ALEN];
 
 	/*
 	 * group_iface will be set to 1 only if a dedicated interface for P2P
@@ -3699,17 +3703,25 @@ static int wpas_get_go_info(void *ctx, u8 *intended_addr,
 	 * that the pending interface should be used.
 	 */
 	*group_iface = 0;
-	s = wpas_p2p_group_go_ssid(wpa_s, bssid);
-	if (!s) {
+
+	if (freq)
+		*freq = 0;
+
+	go = wpas_p2p_get_go_group(wpa_s);
+	if (!go) {
 		s = wpas_p2p_get_persistent_go(wpa_s);
 		*group_iface = wpas_p2p_create_iface(wpa_s);
 		if (s)
-			os_memcpy(bssid, s->bssid, ETH_ALEN);
+			os_memcpy(intended_addr, s->bssid, ETH_ALEN);
 		else
 			return 0;
+	} else {
+		s = go->current_ssid;
+		os_memcpy(intended_addr, go->own_addr, ETH_ALEN);
+		if (freq)
+			*freq = go->assoc_freq;
 	}
 
-	os_memcpy(intended_addr, bssid, ETH_ALEN);
 	os_memcpy(ssid, s->ssid, s->ssid_len);
 	*ssid_len = s->ssid_len;
 
@@ -6235,7 +6247,9 @@ int wpas_p2p_prov_disc(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
 	wpa_s->pending_pd_use = NORMAL_PD;
 	if (p2ps_prov && use == WPAS_P2P_PD_FOR_ASP) {
 		p2ps_prov->conncap = p2ps_group_capability(
-			wpa_s, P2PS_SETUP_NONE, p2ps_prov->role);
+			wpa_s, P2PS_SETUP_NONE, p2ps_prov->role,
+			&p2ps_prov->force_freq, &p2ps_prov->pref_freq);
+
 		wpa_printf(MSG_DEBUG,
 			   "P2P: %s conncap: %d - ASP parsed: %x %x %d %s",
 			   __func__, p2ps_prov->conncap,
-- 
1.9.1




More information about the Hostap mailing list