diff mbox

[v2,05/12] P2PS: Process channels in PD response

Message ID 1444296967-20844-6-git-send-email-ilan.peer@intel.com
State Accepted
Headers show

Commit Message

Ilan Peer Oct. 8, 2015, 9:36 a.m. UTC
In case that the P2PS PD response includes the P2P channel
list attribute, update the peer device supported channels
and verify that the local device has common channels with
the peer (only a sanity check).

If the operating channel attribute is included in the
response, check that it is included in the intersection
and store it as the peer's operating frequency (so it
could later be used in the join flow etc.).

Signed-off-by: Ilan Peer <ilan.peer@intel.com>
---
 src/p2p/p2p_pd.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/src/p2p/p2p_pd.c b/src/p2p/p2p_pd.c
index 4505808..0d262d1 100644
--- a/src/p2p/p2p_pd.c
+++ b/src/p2p/p2p_pd.c
@@ -1376,10 +1376,52 @@  void p2p_process_prov_disc_resp(struct p2p_data *p2p, const u8 *sa,
 		passwd_id = DEV_PW_P2PS_DEFAULT;
 	}
 
-	if ((msg.conn_cap || msg.persistent_dev) &&
-	    (status == P2P_SC_SUCCESS || status == P2P_SC_SUCCESS_DEFERRED) &&
+	if ((status == P2P_SC_SUCCESS || status == P2P_SC_SUCCESS_DEFERRED) &&
 	    p2p->p2ps_prov) {
+		dev->oper_freq = 0;
+
+		/* Save the reported channel list and operating frequency.
+		 * Note that the spec mandates that the responder should
+		 * include in the channel list only channels reported by the
+		 * initiator, so this is only a sanity check, and if this
+		 * fails the flow would continue, although it would probably
+		 * fail. Same is true for the operating channel.
+		 */
+		if (msg.channel_list && msg.channel_list_len &&
+		    p2p_peer_channels_check(p2p, &p2p->channels, dev,
+					    msg.channel_list,
+					    msg.channel_list_len) < 0)
+			p2p_dbg(p2p, "P2PS PD resp - No common channels");
+
+		if (msg.operating_channel) {
+			if (p2p_channels_includes(&p2p->channels,
+						  msg.operating_channel[3],
+						  msg.operating_channel[4]) &&
+			    p2p_channels_includes(&dev->channels,
+						  msg.operating_channel[3],
+						  msg.operating_channel[4])) {
+				dev->oper_freq =
+					p2p_channel_to_freq(msg.operating_channel[3],
+							    msg.operating_channel[4]);
+			}  else {
+				p2p_dbg(p2p,
+					"P2PS PD resp - invalid operating channel");
+			}
+		}
+
 		if (p2p->cfg->p2ps_prov_complete) {
+			if (conncap == P2PS_SETUP_GROUP_OWNER) {
+				u8 tmp;
+
+				/* Re-select the oprating channel as it is
+				 * possible that original channel is no longer
+				 * valid. This should not really fail
+				 */
+				if (p2p_go_select_channel(p2p, dev, &tmp) < 0)
+					p2p_dbg(p2p,
+						"P2PS PD channel selection failed");
+			}
+
 			p2p->cfg->p2ps_prov_complete(
 				p2p->cfg->cb_ctx, status, sa, adv_mac,
 				p2p->p2ps_prov->session_mac,