Patchwork dbus: add boolean AllowRoam option to Scan() method options dictionary

login
register
mail settings
Submitter Dan Williams
Date Oct. 7, 2013, 3:46 p.m.
Message ID <1381160807.5850.1.camel@dcbw.foobar.com>
Download mbox | patch
Permalink /patch/281170/
State Accepted
Commit 538922a628d4f5403b9a96b171a59235bcb3d921
Headers show

Comments

Dan Williams - Oct. 7, 2013, 3:46 p.m.
To disallow roaming when a scan request's results are read, callers
of the D-Bus Scan() method may add a new "AllowRoam" boolean key
to the scan options dictionary and set that key's value to FALSE.

Signed-hostap: Dan Williams <dcbw@redhat.com>
---
 wpa_supplicant/dbus/dbus_new_handlers.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
Jouni Malinen - Oct. 22, 2013, 1:25 p.m.
On Mon, Oct 07, 2013 at 10:46:47AM -0500, Dan Williams wrote:
> To disallow roaming when a scan request's results are read, callers
> of the D-Bus Scan() method may add a new "AllowRoam" boolean key
> to the scan options dictionary and set that key's value to FALSE.

Thanks, applied. Care to update the interface documentation in
doc/dbus.doxygen as well?

Patch

diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c
index 478d02f..9c3dcd5 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers.c
+++ b/wpa_supplicant/dbus/dbus_new_handlers.c
@@ -1231,14 +1231,29 @@  static int wpas_dbus_get_scan_channels(DBusMessage *message,
 	}
 	freqs[freqs_num] = 0;
 
 	params->freqs = freqs;
 	return 0;
 }
 
+static int wpas_dbus_get_scan_allow_roam(DBusMessage *message,
+					 DBusMessageIter *var,
+					 dbus_bool_t *allow,
+					 DBusMessage **reply)
+{
+	if (dbus_message_iter_get_arg_type(var) != DBUS_TYPE_BOOLEAN) {
+		wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
+			   "Type must be a boolean");
+		*reply = wpas_dbus_error_invalid_args(
+			message, "Wrong Type value type. Boolean required");
+		return -1;
+	}
+	dbus_message_iter_get_basic(var, allow);
+	return 0;
+}
 
 /**
  * wpas_dbus_handler_scan - Request a wireless scan on an interface
  * @message: Pointer to incoming dbus message
  * @wpa_s: wpa_supplicant structure for a network interface
  * Returns: NULL indicating success or DBus error message on failure
  *
@@ -1250,14 +1265,15 @@  DBusMessage * wpas_dbus_handler_scan(DBusMessage *message,
 				     struct wpa_supplicant *wpa_s)
 {
 	DBusMessage *reply = NULL;
 	DBusMessageIter iter, dict_iter, entry_iter, variant_iter;
 	char *key = NULL, *type = NULL;
 	struct wpa_driver_scan_params params;
 	size_t i;
+	dbus_bool_t allow_roam = 1;
 
 	os_memset(&params, 0, sizeof(params));
 
 	dbus_message_iter_init(message, &iter);
 
 	dbus_message_iter_recurse(&iter, &dict_iter);
 
@@ -1280,14 +1296,20 @@  DBusMessage * wpas_dbus_handler_scan(DBusMessage *message,
 			if (wpas_dbus_get_scan_ies(message, &variant_iter,
 						   &params, &reply) < 0)
 				goto out;
 		} else if (os_strcmp(key, "Channels") == 0) {
 			if (wpas_dbus_get_scan_channels(message, &variant_iter,
 							&params, &reply) < 0)
 				goto out;
+		} else if (os_strcmp(key, "AllowRoam") == 0) {
+			if (wpas_dbus_get_scan_allow_roam(message,
+			                                  &variant_iter,
+							  &allow_roam,
+							  &reply) < 0)
+				goto out;
 		} else {
 			wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
 				   "Unknown argument %s", key);
 			reply = wpas_dbus_error_invalid_args(message, key);
 			goto out;
 		}
 
@@ -1328,14 +1350,17 @@  DBusMessage * wpas_dbus_handler_scan(DBusMessage *message,
 		wpa_printf(MSG_DEBUG, "wpas_dbus_handler_scan[dbus]: "
 			   "Unknown scan type: %s", type);
 		reply = wpas_dbus_error_invalid_args(message,
 						     "Wrong scan type");
 		goto out;
 	}
 
+	if (!allow_roam)
+		wpa_s->scan_res_handler = scan_only_handler;
+
 out:
 	for (i = 0; i < WPAS_MAX_SCAN_SSIDS; i++)
 		os_free((u8 *) params.ssids[i].ssid);
 	os_free((u8 *) params.extra_ies);
 	os_free(params.freqs);
 	return reply;
 }