diff mbox

[2/2] P2P: Add support for freq option in p2p_find

Message ID 1415187309-12742-2-git-send-email-daichi.ueura@sonymobile.com
State Accepted
Headers show

Commit Message

Daichi Ueura Nov. 5, 2014, 11:35 a.m. UTC
From: Daisuke Niwa <daisuke.x.niwa@sonymobile.com>

This allows a channel to be specified for the p2p_find.

Signed-off-by: Daichi Ueura <daichi.ueura@sonymobile.com>
---
 src/p2p/p2p.c                               |  8 +++++++-
 src/p2p/p2p.h                               |  5 ++++-
 wpa_supplicant/ctrl_iface.c                 | 11 ++++++++++-
 wpa_supplicant/dbus/dbus_new_handlers_p2p.c |  2 +-
 wpa_supplicant/p2p_supplicant.c             |  4 ++--
 wpa_supplicant/p2p_supplicant.h             |  2 +-
 6 files changed, 25 insertions(+), 7 deletions(-)

Comments

Jouni Malinen Nov. 15, 2014, 9:36 a.m. UTC | #1
On Wed, Nov 05, 2014 at 08:35:09PM +0900, Daichi Ueura wrote:
> This allows a channel to be specified for the p2p_find.

What is the use case and expected behavior for this? The current design
would run only the first scan iteration on the specified channel
followed by continuous scans of the P2P social channels. Was that
expected? Or was this supposed to continue scanning the single specified
frequency multiple times?

> diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
> @@ -4091,8 +4092,16 @@ static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
>  	} else
>  		search_delay = wpas_p2p_search_delay(wpa_s);
>  
> +	pos = os_strstr(cmd, "freq=");
> +	if (pos) {
> +		pos += 6;
> +		freq = atoi(pos);

That is off-by-one, i.e., the first digit of the freq value is dropped
which will make the scan fail due to an invalid frequency parameter.
Daichi Ueura Dec. 6, 2014, 5:34 a.m. UTC | #2
Hi Jouni,

> That is off-by-one
I am sorry to send the patch that contains the issue.

> What is the use case and expected behavior for this?
The purpose is to reduce a time of scan phase when a client of
wpa_supplicant already knows operating channel* of peer(AutoGO), i.e.
we would like to scan a specified operating channel at first. So that
p2p connection time can be reduced. (e.g. several seconds can be
saved.)
*) Especially except for 1/6/11

> The current design would run only the first scan iteration on the specified channel followed by continuous scans of the P2P social channels.
Yes, this is what we expect. We would like to do single channel scan
(not full scan) at first.

Thank you,
Daichi

On Sat, Nov 15, 2014 at 6:36 PM, Jouni Malinen <j@w1.fi> wrote:
> On Wed, Nov 05, 2014 at 08:35:09PM +0900, Daichi Ueura wrote:
>> This allows a channel to be specified for the p2p_find.
>
> What is the use case and expected behavior for this? The current design
> would run only the first scan iteration on the specified channel
> followed by continuous scans of the P2P social channels. Was that
> expected? Or was this supposed to continue scanning the single specified
> frequency multiple times?
>
>> diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
>> @@ -4091,8 +4092,16 @@ static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
>>       } else
>>               search_delay = wpas_p2p_search_delay(wpa_s);
>>
>> +     pos = os_strstr(cmd, "freq=");
>> +     if (pos) {
>> +             pos += 6;
>> +             freq = atoi(pos);
>
> That is off-by-one, i.e., the first digit of the freq value is dropped
> which will make the scan fail due to an invalid frequency parameter.
>
> --
> Jouni Malinen                                            PGP id EFC895FA
Jouni Malinen Feb. 28, 2015, 8:18 p.m. UTC | #3
On Sat, Dec 06, 2014 at 02:34:58PM +0900, Daichi Ueura wrote:
> The purpose is to reduce a time of scan phase when a client of
> wpa_supplicant already knows operating channel* of peer(AutoGO), i.e.
> we would like to scan a specified operating channel at first. So that
> p2p connection time can be reduced. (e.g. several seconds can be
> saved.)
> *) Especially except for 1/6/11

> Yes, this is what we expect. We would like to do single channel scan
> (not full scan) at first.

Thanks. I applied this with some cleanup and description of this use
case.
diff mbox

Patch

diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c
index d17f70d..e67a4e6 100644
--- a/src/p2p/p2p.c
+++ b/src/p2p/p2p.c
@@ -1080,7 +1080,7 @@  static void p2p_free_req_dev_types(struct p2p_data *p2p)
 int p2p_find(struct p2p_data *p2p, unsigned int timeout,
 	     enum p2p_discovery_type type,
 	     unsigned int num_req_dev_types, const u8 *req_dev_types,
-	     const u8 *dev_id, unsigned int search_delay)
+	     const u8 *dev_id, unsigned int search_delay, int freq)
 {
 	int res;
 
@@ -1122,6 +1122,12 @@  int p2p_find(struct p2p_data *p2p, unsigned int timeout,
 				       p2p, NULL);
 	switch (type) {
 	case P2P_FIND_START_WITH_FULL:
+		if (freq > 0) {
+			res = p2p->cfg->p2p_scan(p2p->cfg->cb_ctx, P2P_SCAN_SPECIFIC, freq,
+						 p2p->num_req_dev_types,
+						 p2p->req_dev_types, dev_id, DEV_PW_DEFAULT);
+			break;
+		}
 	case P2P_FIND_PROGRESSIVE:
 		res = p2p->cfg->p2p_scan(p2p->cfg->cb_ctx, P2P_SCAN_FULL, 0,
 					 p2p->num_req_dev_types,
diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h
index dcd3027..ba4dcb7 100644
--- a/src/p2p/p2p.h
+++ b/src/p2p/p2p.h
@@ -943,12 +943,15 @@  enum p2p_discovery_type {
  *	requested device types.
  * @dev_id: Device ID to search for or %NULL to find all devices
  * @search_delay: Extra delay in milliseconds between search iterations
+ * @freq: Requested frequency for P2P_SCAN_SPECIFIC.
+ *	If p2p_find is already in progress,
+ *	this parameter is ignored and full scan will be executed.
  * Returns: 0 on success, -1 on failure
  */
 int p2p_find(struct p2p_data *p2p, unsigned int timeout,
 	     enum p2p_discovery_type type,
 	     unsigned int num_req_dev_types, const u8 *req_dev_types,
-	     const u8 *dev_id, unsigned int search_delay);
+	     const u8 *dev_id, unsigned int search_delay, int freq);
 
 /**
  * p2p_notify_scan_trigger_status - Indicate scan trigger status
diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index 58480a7..f2c21a2 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -4057,6 +4057,7 @@  static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
 	u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
 	char *pos;
 	unsigned int search_delay;
+	int freq = 0;
 
 	if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
 		wpa_dbg(wpa_s, MSG_INFO,
@@ -4091,8 +4092,16 @@  static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
 	} else
 		search_delay = wpas_p2p_search_delay(wpa_s);
 
+	pos = os_strstr(cmd, "freq=");
+	if (pos) {
+		pos += 6;
+		freq = atoi(pos);
+		if (freq <= 0)
+			return -1;
+	}
+
 	return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
-			     _dev_id, search_delay);
+			     _dev_id, search_delay, freq);
 }
 
 
diff --git a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
index f006887..767c58d 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
+++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
@@ -131,7 +131,7 @@  DBusMessage * wpas_dbus_handler_p2p_find(DBusMessage *message,
 		wpa_s = wpa_s->p2p_dev;
 
 	wpas_p2p_find(wpa_s, timeout, type, num_req_dev_types, req_dev_types,
-		      NULL, 0);
+		      NULL, 0, 0);
 	os_free(req_dev_types);
 	return reply;
 
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index 931200d..605f58a 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -5890,7 +5890,7 @@  static void wpas_p2p_clear_pending_action_tx(struct wpa_supplicant *wpa_s)
 int wpas_p2p_find(struct wpa_supplicant *wpa_s, unsigned int timeout,
 		  enum p2p_discovery_type type,
 		  unsigned int num_req_dev_types, const u8 *req_dev_types,
-		  const u8 *dev_id, unsigned int search_delay)
+		  const u8 *dev_id, unsigned int search_delay, int freq)
 {
 	wpas_p2p_clear_pending_action_tx(wpa_s);
 	wpa_s->p2p_long_listen = 0;
@@ -5903,7 +5903,7 @@  int wpas_p2p_find(struct wpa_supplicant *wpa_s, unsigned int timeout,
 
 	return p2p_find(wpa_s->global->p2p, timeout, type,
 			num_req_dev_types, req_dev_types, dev_id,
-			search_delay);
+			search_delay, freq);
 }
 
 
diff --git a/wpa_supplicant/p2p_supplicant.h b/wpa_supplicant/p2p_supplicant.h
index 4bc90fb..8381a32 100644
--- a/wpa_supplicant/p2p_supplicant.h
+++ b/wpa_supplicant/p2p_supplicant.h
@@ -55,7 +55,7 @@  enum p2p_discovery_type;
 int wpas_p2p_find(struct wpa_supplicant *wpa_s, unsigned int timeout,
 		  enum p2p_discovery_type type,
 		  unsigned int num_req_dev_types, const u8 *req_dev_types,
-		  const u8 *dev_id, unsigned int search_delay);
+		  const u8 *dev_id, unsigned int search_delay, int freq);
 void wpas_p2p_stop_find(struct wpa_supplicant *wpa_s);
 int wpas_p2p_listen(struct wpa_supplicant *wpa_s, unsigned int timeout);
 int wpas_p2p_assoc_req_ie(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,