[PATCH] Add support of Passphrase Param in P2P group add command

Maneesh Jain maneesh.jain
Sun Jun 7 21:18:52 PDT 2015


This patch is to add "passphrase" parameter in
"p2p_group_add" command. It helps application
to configure its own passphrase while creating
the group.
It is most usefull in p2p legacy connection

EP-65895668EA074D69A6D93488C7C4CDCA
Signed-off-by: Maneesh Jain <maneesh.jain at samsung.com>
---
 wpa_supplicant/ctrl_iface.c                 |   23 +++++++++++++++++++----
 wpa_supplicant/dbus/dbus_new_handlers_p2p.c |    2 +-
 wpa_supplicant/p2p_supplicant.c             |   11 ++++++++---
 wpa_supplicant/p2p_supplicant.h             |    2 +-
 4 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index faf683c..69d50d8 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -5523,6 +5523,7 @@ static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
 {
 	int freq = 0, ht40, vht;
 	char *pos;
+	char *passphrase = NULL;
 
 	pos = os_strstr(cmd, "freq=");
 	if (pos)
@@ -5532,16 +5533,30 @@ static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
 	ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
 		vht;
 
+	pos = os_strstr(cmd, "passphrase");
+	if(pos) {
+
+		wpa_printf(MSG_DEBUG, "pos : %s", pos);
+		passphrase = pos + 11;
+		pos = os_strchr(passphrase, ' ');
+		if(pos != NULL)
+			*pos = '\0';
+		wpa_printf(MSG_DEBUG, "passphrase : %s",passphrase);
+	}
+
 	if (os_strncmp(cmd, "persistent=", 11) == 0)
 		return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
 						     ht40, vht);
 	if (os_strcmp(cmd, "persistent") == 0 ||
 	    os_strncmp(cmd, "persistent ", 11) == 0)
-		return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
+		return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht, passphrase);
 	if (os_strncmp(cmd, "freq=", 5) == 0)
-		return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
+		return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht, passphrase);
 	if (ht40)
-		return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
+		return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht, passphrase);
+
+	if(passphrase)
+		return wpas_p2p_group_add(wpa_s, 0, freq, ht40,  vht, passphrase);
 
 	wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
 		   cmd);
@@ -8192,7 +8207,7 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
 		if (wpas_p2p_group_remove(wpa_s, buf + 17))
 			reply_len = -1;
 	} else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
-		if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
+		if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0, NULL))
 			reply_len = -1;
 	} else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
 		if (p2p_ctrl_group_add(wpa_s, buf + 14))
diff --git a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
index c8dd67b..c99f30f 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
+++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
@@ -370,7 +370,7 @@ DBusMessage * wpas_dbus_handler_p2p_group_add(DBusMessage *message,
 				"Failed to reinvoke a persistent group");
 			goto out;
 		}
-	} else if (wpas_p2p_group_add(wpa_s, persistent_group, freq, 0, 0))
+	} else if (wpas_p2p_group_add(wpa_s, persistent_group, freq, 0, 0, NULL))
 		goto inv_args;
 
 out:
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index 5c8a3b2..bf58303 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -3750,7 +3750,7 @@ static void wpas_p2ps_prov_complete(void *ctx, u8 status, const u8 *dev,
 					P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE :
 					0);
 			} else if (response_done) {
-				wpas_p2p_group_add(wpa_s, 1, 0, 0, 0);
+				wpas_p2p_group_add(wpa_s, 1, 0, 0, 0,NULL);
 			}
 
 			if (passwd_id == DEV_PW_P2PS_DEFAULT) {
@@ -3848,7 +3848,7 @@ static int wpas_prov_disc_resp_cb(void *ctx)
 			persistent_go->mode == WPAS_MODE_P2P_GO ?
 			P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : 0);
 	} else {
-		wpas_p2p_group_add(wpa_s, 1, 0, 0, 0);
+		wpas_p2p_group_add(wpa_s, 1, 0, 0, 0,NULL);
 	}
 
 	return 1;
@@ -5365,13 +5365,14 @@ wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated,
  * @freq: Frequency for the group or 0 to indicate no hardcoding
  * @ht40: Start GO with 40 MHz channel width
  * @vht:  Start GO with VHT support
+ * @passphrase : Start GO with assigned passphrase
  * Returns: 0 on success, -1 on failure
  *
  * This function creates a new P2P group with the local end as the Group Owner,
  * i.e., without using Group Owner Negotiation.
  */
 int wpas_p2p_group_add(struct wpa_supplicant *wpa_s, int persistent_group,
-		       int freq, int ht40, int vht)
+		       int freq, int ht40, int vht,  char *passphrase)
 {
 	struct p2p_go_neg_results params;
 
@@ -5412,6 +5413,10 @@ int wpas_p2p_group_add(struct wpa_supplicant *wpa_s, int persistent_group,
 	p2p_go_params(wpa_s->global->p2p, &params);
 	params.persistent_group = persistent_group;
 
+	if(passphrase != NULL) {
+		os_strlcpy(params.passphrase, passphrase, 64);
+	}
+
 	wpa_s = wpas_p2p_get_group_iface(wpa_s, 0, 1);
 	if (wpa_s == NULL)
 		return -1;
diff --git a/wpa_supplicant/p2p_supplicant.h b/wpa_supplicant/p2p_supplicant.h
index 0b9ebc0..1719f44 100644
--- a/wpa_supplicant/p2p_supplicant.h
+++ b/wpa_supplicant/p2p_supplicant.h
@@ -31,7 +31,7 @@ int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
 int wpas_p2p_handle_frequency_conflicts(struct wpa_supplicant *wpa_s,
                                           int freq, struct wpa_ssid *ssid);
 int wpas_p2p_group_add(struct wpa_supplicant *wpa_s, int persistent_group,
-		       int freq, int ht40, int vht);
+		       int freq, int ht40, int vht, char *passphrase);
 int wpas_p2p_group_add_persistent(struct wpa_supplicant *wpa_s,
 				  struct wpa_ssid *ssid, int addr_allocated,
 				  int force_freq, int neg_freq, int ht40,
-- 
1.7.9.5




More information about the Hostap mailing list