diff mbox

Add support of Passphrase Param in P2P group add command

Message ID 1433737132-4715-1-git-send-email-maneesh.jain@samsung.com
State Changes Requested
Headers show

Commit Message

Maneesh Jain June 8, 2015, 4:18 a.m. UTC
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@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(-)

Comments

Jouni Malinen June 10, 2015, 5:03 p.m. UTC | #1
On Mon, Jun 08, 2015 at 09:48:52AM +0530, Maneesh Jain wrote:
> 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

> diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
> @@ -5532,16 +5533,30 @@ static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
> +	pos = os_strstr(cmd, "passphrase");

I'd assume that should be "passphrase=".

> +		passphrase = pos + 11;
> +		pos = os_strchr(passphrase, ' ');

Please note that ' ' is a valid character in a passphrase.. This type of
parsing would not work for such a case.

> +		if(pos != NULL)
> +			*pos = '\0';

This termination of the string can break the following steps:

>  	if (os_strncmp(cmd, "persistent=", 11) == 0)
...

This argument could have been after the passphrase= parameter.

> diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
> @@ -5365,13 +5365,14 @@ wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated,
> + * @passphrase : Start GO with assigned passphrase

>  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)

That should be "const char *".

> @@ -5412,6 +5413,10 @@ int wpas_p2p_group_add(struct wpa_supplicant *wpa_s, int persistent_group,
> +	if(passphrase != NULL) {
> +		os_strlcpy(params.passphrase, passphrase, 64);

sizeof(params.passphrase) would be better than 64 here. In addition, it
would be good to verify somewhere (likely here) that
os_strlen(passphrase) is 8..63.
Jouni Malinen June 10, 2015, 9:06 p.m. UTC | #2
On Mon, Jun 08, 2015 at 09:48:52AM +0530, Maneesh Jain wrote:
> 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

In addition to my previous comments on the proposed changes, please note
that it is already possible to set the passphrase by adding a persistent
group profile separately. As such, it may not be necessary to extend
p2p_group_add for this.

For example:

ADD_NETWORK
SET_NETWORK 0 ssid "DIRECT-ab"
SET_NETWORK 0 psk "passphrase here"
SET_NETWORK 0 mode 3
SET_NETWORK 0 disabled 2
P2P_GROUP_ADD persistent=0 freq=2412
diff mbox

Patch

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,