diff mbox

[2/3] P2P: Rejecting Go Negotiation request for single p2p interface device (GO or GC).

Message ID 1626052641.466781438763544659.JavaMail.weblogic@epmlwas08c
State Rejected
Headers show

Commit Message

Avichal Agarwal Aug. 5, 2015, 8:32 a.m. UTC
From 4a2602f9c1c79621731f82e036cde55309e181b9 Mon Sep 17 00:00:00 2001
From: Avichal Agarwal <avichal.a@samsung.com>
Date: Wed, 5 Aug 2015 12:21:40 +0530
Subject: [PATCH 2/3] P2P: Rejecting Go Negotiation request for single p2p
-interface device (GO or GC).

This patch works when there is only single p2p interface which act as GC and GO.
It rejects Go Negotiation request when p2p interface is already connected.

Signed-off-by: Avichal Agarwal <avichal.a@samsung.com>
Signed-off-by: Kyeong-Chae Lim <kcya.lim@samsung.com>
---
 src/p2p/p2p_go_neg.c |   35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

Comments

Jouni Malinen Aug. 5, 2015, 9:44 a.m. UTC | #1
On Wed, Aug 05, 2015 at 08:32:24AM +0000, Avichal Agarwal wrote:
> This patch works when there is only single p2p interface which act as GC and GO.
> It rejects Go Negotiation request when p2p interface is already connected.

Same comments as for the patch 1/3 apply for this change. I don't see
any point in hardcoding user rejection for GO Negotiation Request when
there is no room for a new concurrent group. The current behavior is
there by design, i.e., decision on what to do with a GO Negotiation
Request should be left for upper layers (user can terminate the existing
group to allow new group to be formed or explicitly decide to reject the
new request).
diff mbox

Patch

diff --git a/src/p2p/p2p_go_neg.c b/src/p2p/p2p_go_neg.c
index 4322bbb..5e3deec 100644
--- a/src/p2p/p2p_go_neg.c
+++ b/src/p2p/p2p_go_neg.c
@@ -737,16 +737,41 @@  static void p2p_check_pref_chan(struct p2p_data *p2p, int go,
 void p2p_process_go_neg_req(struct p2p_data *p2p, const u8 *sa,
 			    const u8 *data, size_t len, int rx_freq)
 {
-	struct p2p_device *dev = NULL;
+	struct p2p_device *dev = NULL,*n;
 	struct wpabuf *resp;
 	struct p2p_message msg;
 	u8 status = P2P_SC_FAIL_INVALID_PARAMS;
 	int tie_breaker = 0;
-	int freq;
+	int freq,failflag=0,i;
 
 	p2p_dbg(p2p, "Received GO Negotiation Request from " MACSTR "(freq=%d)",
 		MAC2STR(sa), rx_freq);
 
+	#ifdef SINGLE_P2P_INTERFACE
+	dl_list_for_each_safe(dev, n, &p2p->devices, struct p2p_device, list) 
+	{
+		if (p2p->cfg->go_connected &&
+		    p2p->cfg->go_connected(p2p->cfg->cb_ctx,
+			   dev->info.p2p_device_addr)) {
+				p2p_dbg(p2p, "Alraedy Conncted GO-NEG-REQ IGNORED\n");
+				status = P2P_SC_FAIL_REJECTED_BY_USER;
+				failflag=1;
+				break;
+		}
+		for (i = 0; i < p2p->num_groups; i++) {
+			if (p2p_group_is_client_connected(
+			    p2p->groups[i], dev->info.p2p_device_addr))
+				break;
+		}
+		if (i < p2p->num_groups) {
+			p2p_dbg(p2p, "Alraedy Conncted GO-NEG-REQ IGNORED\n");
+			status = P2P_SC_FAIL_REJECTED_BY_USER;
+			failflag=1;
+			break;
+		}
+	}
+	#endif
+
 	if (p2p_parse(data, len, &msg))
 		return;
 
@@ -802,6 +827,9 @@  void p2p_process_go_neg_req(struct p2p_data *p2p, const u8 *sa,
 	}
 
 	dev = p2p_get_device(p2p, sa);
+	
+	if(dev && failflag)
+		goto fail;
 
 	if (msg.status && *msg.status) {
 		p2p_dbg(p2p, "Unexpected Status attribute (%d) in GO Negotiation Request",
@@ -844,6 +872,9 @@  void p2p_process_go_neg_req(struct p2p_data *p2p, const u8 *sa,
 			MAC2STR(dev->info.p2p_device_addr));
 		p2p_add_dev_info(p2p, sa, dev, &msg);
 	}
+	
+	if(failflag)
+		goto fail;
 
 	if (p2p->go_neg_peer && p2p->go_neg_peer == dev)
 		eloop_cancel_timeout(p2p_go_neg_wait_timeout, p2p, NULL);