Patchwork wpa_supplicant: Add 'SCAN TYPE=ONLY' functionality

login
register
mail settings
Submitter Dmitry Shmidt
Date Jan. 17, 2013, 6:32 p.m.
Message ID <20130117183921.457AF141EE2@ushik.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/213346/
State Accepted
Commit 66fe0f703cb4d360950c1c551dc2691c0788b442
Headers show

Comments

Dmitry Shmidt - Jan. 17, 2013, 6:32 p.m.
Usual manual scan request may cause reassociation due to several reasons.
New command is intended to perform pure scan.

Change-Id: I5f517a9f50f286482290e76ca1088abf6a1aeff9
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
---
 wpa_supplicant/ctrl_iface.c |    6 +++++-
 wpa_supplicant/events.c     |    3 ++-
 wpa_supplicant/scan.c       |   12 ++++++++++++
 wpa_supplicant/scan.h       |    2 ++
 wpa_supplicant/wpa_cli.c    |    2 ++
 5 files changed, 23 insertions(+), 2 deletions(-)
Jouni Malinen - Feb. 7, 2013, 4:12 p.m.
On Thu, Jan 17, 2013 at 10:32:35AM -0800, Dmitry Shmidt wrote:
> Usual manual scan request may cause reassociation due to several reasons.
> New command is intended to perform pure scan.

Thanks, applied with some small changes.

> diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c
> @@ -1583,3 +1584,14 @@ int wpa_supplicant_update_scan_results(struct wpa_supplicant *wpa_s)
> +void scan_only_handler(struct wpa_supplicant *wpa_s,
> +		       struct wpa_scan_results *scan_res)
> +{
> +	wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
> +	wpas_notify_scan_results(wpa_s);

I added a debug message and wpas_notify_scan_done() call here. The
latter is needed to keep D-Bus interface up-to-date with scans (and the
former to keep my sanity if I need to debug issues where a new scan does
not trigger something I might expect to happen there ;-).

> diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c
> @@ -1459,6 +1459,8 @@ static int wpa_cli_cmd_save_config(struct wpa_ctrl *ctrl, int argc,
>  static int wpa_cli_cmd_scan(struct wpa_ctrl *ctrl, int argc, char *argv[])
>  {
> +	if (argc > 0)
> +		return wpa_cli_cmd(ctrl, "SCAN", 1, argc, argv);
>  	return wpa_ctrl_command(ctrl, "SCAN");
>  }

This can use wpa_cli_cmd() unconditionally to make the implementation a
bit simpler.

Patch

diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index 3408a85..8c186bd 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -5161,10 +5161,14 @@  char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
 		wpa_supplicant_cancel_scan(wpa_s);
 		wpa_supplicant_deauthenticate(wpa_s,
 					      WLAN_REASON_DEAUTH_LEAVING);
-	} else if (os_strcmp(buf, "SCAN") == 0) {
+	} else if ((os_strcmp(buf, "SCAN") == 0) ||
+		   (os_strncmp(buf, "SCAN ", 5) == 0)) {
 		if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
 			reply_len = -1;
 		else {
+			if ((os_strlen(buf) > 4) &&
+			    (os_strncasecmp(buf + 5, "TYPE=ONLY", 9) == 0))
+				wpa_s->scan_res_handler = scan_only_handler;
 			if (!wpa_s->sched_scanning && !wpa_s->scanning &&
 			    ((wpa_s->wpa_state <= WPA_SCANNING) ||
 			     (wpa_s->wpa_state == WPA_COMPLETED))) {
diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c
index 3fefb48..2b62e6b 100644
--- a/wpa_supplicant/events.c
+++ b/wpa_supplicant/events.c
@@ -1109,7 +1109,8 @@  static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s,
 						   data ? &data->scan_info :
 						   NULL, 1);
 	if (scan_res == NULL) {
-		if (wpa_s->conf->ap_scan == 2 || ap)
+		if ((wpa_s->conf->ap_scan == 2 || ap) ||
+		    (wpa_s->scan_res_handler == scan_only_handler))
 			return -1;
 		wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try "
 			"scanning again");
diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c
index c59b8ba..4b2b9fd 100644
--- a/wpa_supplicant/scan.c
+++ b/wpa_supplicant/scan.c
@@ -11,6 +11,7 @@ 
 #include "utils/common.h"
 #include "utils/eloop.h"
 #include "common/ieee802_11_defs.h"
+#include "common/wpa_ctrl.h"
 #include "config.h"
 #include "wpa_supplicant_i.h"
 #include "driver_i.h"
@@ -1583,3 +1584,14 @@  int wpa_supplicant_update_scan_results(struct wpa_supplicant *wpa_s)
 
 	return 0;
 }
+
+
+/**
+ * scan_only_handler - Reports scan results
+ */
+void scan_only_handler(struct wpa_supplicant *wpa_s,
+		       struct wpa_scan_results *scan_res)
+{
+	wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS);
+	wpas_notify_scan_results(wpa_s);
+}
diff --git a/wpa_supplicant/scan.h b/wpa_supplicant/scan.h
index 5096287..098f0f3 100644
--- a/wpa_supplicant/scan.h
+++ b/wpa_supplicant/scan.h
@@ -32,5 +32,7 @@  struct wpabuf * wpa_scan_get_vendor_ie_multi(const struct wpa_scan_res *res,
 					     u32 vendor_type);
 int wpa_supplicant_filter_bssid_match(struct wpa_supplicant *wpa_s,
 				      const u8 *bssid);
+void scan_only_handler(struct wpa_supplicant *wpa_s,
+		       struct wpa_scan_results *scan_res);
 
 #endif /* SCAN_H */
diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c
index cc08009..2278138 100644
--- a/wpa_supplicant/wpa_cli.c
+++ b/wpa_supplicant/wpa_cli.c
@@ -1459,6 +1459,8 @@  static int wpa_cli_cmd_save_config(struct wpa_ctrl *ctrl, int argc,
 
 static int wpa_cli_cmd_scan(struct wpa_ctrl *ctrl, int argc, char *argv[])
 {
+	if (argc > 0)
+		return wpa_cli_cmd(ctrl, "SCAN", 1, argc, argv);
 	return wpa_ctrl_command(ctrl, "SCAN");
 }