[PATCH] DBus: allow "Get" paramter in Start [WPS] to get a valid random pin

Purushottam Kushwaha p.kushwaha
Tue Jun 23 22:02:47 PDT 2015


This is equivalent to "wps_pin get" on control interface. It will
facilitate dbus applications in getting a valid random pin to start wps.

Signed-off-by: Purushottam Kushwaha <p.kushwaha at samsung.com>
Signed-off-by: Dilshad Ahmad <dilshad.a at samsung.com>
---
 doc/dbus.doxygen                            |  1 +
 wpa_supplicant/dbus/dbus_new_handlers_wps.c | 39 +++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/doc/dbus.doxygen b/doc/dbus.doxygen
index 3a08ad7..46bea84 100644
--- a/doc/dbus.doxygen
+++ b/doc/dbus.doxygen
@@ -863,6 +863,7 @@ Interface for performing WPS (Wi-Fi Simple Config) operations.
 	      <tr><th>Key</th><th>Value type</th><th>Description</th><th>Required</th>
 	      <tr><td>Role</td><td>s</td><td>The device's role. Possible values are "enrollee" and "registrar".</td><td>Yes</td>
 	      <tr><td>Type</td><td>s</td><td>WPS authentication type. Applies only for enrollee role. Possible values are "pin" and "pbc".</td><td>Yes, for enrollee role; otherwise no</td>
+	      <tr><td>Get</td><td>s</td><td>Get a valid random pin. Possible value is "pin".</td><td>No</td>
 	      <tr><td>Pin</td><td>s</td><td>WPS Pin.</td><td>Yes, for registrar role; otherwise optional</td>
 	      <tr><td>Bssid</td><td>ay</td><td>Note: This is used to specify the peer MAC address when authorizing WPS connection in AP or P2P GO role.</td><td>No</td>
 	      <tr><td>P2PDeviceAddress</td><td>ay</td><td>P2P Device Address of a peer to authorize for PBC connection. Used only in P2P GO role.</td><td>No</td>
diff --git a/wpa_supplicant/dbus/dbus_new_handlers_wps.c b/wpa_supplicant/dbus/dbus_new_handlers_wps.c
index dcae0a9..40b79a2 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers_wps.c
+++ b/wpa_supplicant/dbus/dbus_new_handlers_wps.c
@@ -24,6 +24,7 @@
 struct wps_start_params {
 	int role; /* 0 - not set, 1 - enrollee, 2 - registrar */
 	int type; /* 0 - not set, 1 - pin,      2 - pbc       */
+	int get;  /* 0 - not set, 1 - pin	*/
 	u8 *bssid;
 	char *pin;
 	u8 *p2p_dev_addr;
@@ -92,6 +93,35 @@ static int wpas_dbus_handler_wps_type(DBusMessage *message,
 }
 
 
+static int wpas_dbus_handler_wps_get(DBusMessage *message,
+				      DBusMessageIter *entry_iter,
+				      struct wps_start_params *params,
+				      DBusMessage **reply)
+{
+	DBusMessageIter variant_iter;
+	char *val;
+
+	dbus_message_iter_recurse(entry_iter, &variant_iter);
+	if (dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_STRING) {
+		wpa_printf(MSG_DEBUG,
+			   "dbus: WPS.Start - Wrong Get type, string required");
+		*reply = wpas_dbus_error_invalid_args(message,
+						      "Get must be a string");
+		return -1;
+	}
+	dbus_message_iter_get_basic(&variant_iter, &val);
+	if (os_strcmp(val, "pin") == 0)
+		params->get = 1;
+	else {
+		wpa_printf(MSG_DEBUG, "dbus: WPS.Start - Unknown get %s",
+			   val);
+		*reply = wpas_dbus_error_invalid_args(message, val);
+		return -1;
+	}
+	return 0;
+}
+
+
 static int wpas_dbus_handler_wps_bssid(DBusMessage *message,
 				       DBusMessageIter *entry_iter,
 				       struct wps_start_params *params,
@@ -189,6 +219,9 @@ static int wpas_dbus_handler_wps_start_entry(DBusMessage *message, char *key,
 	else if (os_strcmp(key, "Type") == 0)
 		return wpas_dbus_handler_wps_type(message, entry_iter,
 						  params, reply);
+	else if (os_strcmp(key, "Get") == 0)
+		return wpas_dbus_handler_wps_get(message, entry_iter,
+						 params, reply);
 	else if (os_strcmp(key, "Bssid") == 0)
 		return wpas_dbus_handler_wps_bssid(message, entry_iter,
 						   params, reply);
@@ -247,6 +280,11 @@ DBusMessage * wpas_dbus_handler_wps_start(DBusMessage *message,
 		dbus_message_iter_next(&dict_iter);
 	}
 
+	if(params.get == 1) {
+		os_snprintf(npin, sizeof(npin), "%08d", wps_generate_pin());
+		goto done;
+	}
+
 #ifdef CONFIG_AP
 	if (wpa_s->ap_iface && params.type == 1) {
 		if (params.pin == NULL) {
@@ -302,6 +340,7 @@ DBusMessage * wpas_dbus_handler_wps_start(DBusMessage *message,
 						     "WPS start failed");
 	}
 
+done:
 	reply = dbus_message_new_method_return(message);
 	if (!reply)
 		return wpas_dbus_error_no_memory(message);
-- 
1.9.1



More information about the Hostap mailing list