diff mbox

wpa_supplicant/dbus AP: Add support for WPS Internal Registrar.

Message ID CAPdpN3DJe36=XRE9ytfmcYgNrw_=PkLTCpFmRj_qyk3t1CGqBg@mail.gmail.com
State Accepted
Commit 19030351b95f48714007e425eaa2163d9122d788
Headers show

Commit Message

Gustavo Sverzut Barbieri Dec. 13, 2011, 3 p.m. UTC
Hi all,

Find attached a patch to make DBus API match the behavior of the
socket/ctl_iface for WPS start within the P2P case.

Whenever doing p2p the command "wps_pbc" may use the internal
registrar. But this path did not exist with the DBus version
WPS.Start(). See commit 3ec97afe571f159ea95213262c1c6b89965827d4 by
Jouni Malinen when this was added to the ctl_iface.

Remarks:

    +#include "../driver_i.h"

needed because ap.h uses structures defined in files pulled by it.
Keeping the same as ctl_iface.

     +               wpa_printf(MSG_DEBUG, "dbus: WPS.Start - Wrong "
     +                          "P2PDeviceAddress type, byte array required");

keeping the same debug as the other functions in this file, for consistency.

Regards,

Comments

Jouni Malinen Dec. 18, 2011, 3:08 p.m. UTC | #1
On Tue, Dec 13, 2011 at 01:00:02PM -0200, Gustavo Sverzut Barbieri wrote:
> Find attached a patch to make DBus API match the behavior of the
> socket/ctl_iface for WPS start within the P2P case.

Thanks! Applied.
diff mbox

Patch

From 3aad9018b31c7f4de6b594be25384c07b7654927 Mon Sep 17 00:00:00 2001
From: Gustavo Sverzut Barbieri <barbieri@profusion.mobi>
Date: Fri, 9 Dec 2011 16:32:53 -0200
Subject: [PATCH] wpa_supplicant/dbus AP: Add support for WPS Internal
 Registrar.

When in AP mode, wpa_supplicant is now enabling WPS (only Internal
Registrar). WPS.Start() call can be used to initiate WPS negotiation
similarly to how this is done in station mode.

This was done to ctrl_iface by Jouni Malinen on April 21, 2009 (commit
3ec97afe571f159ea95213262c1c6b89965827d4)

Signed-hostap: Gustavo Sverzut Barbieri <barbieri@profusion.mobi>
---
 wpa_supplicant/dbus/dbus_new_handlers_wps.c |   72 +++++++++++++++++++++++++--
 1 files changed, 67 insertions(+), 5 deletions(-)

diff --git a/wpa_supplicant/dbus/dbus_new_handlers_wps.c b/wpa_supplicant/dbus/dbus_new_handlers_wps.c
index d8b74d0..1f435a5 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers_wps.c
+++ b/wpa_supplicant/dbus/dbus_new_handlers_wps.c
@@ -19,6 +19,8 @@ 
 #include "../config.h"
 #include "../wpa_supplicant_i.h"
 #include "../wps_supplicant.h"
+#include "../driver_i.h"
+#include "../ap.h"
 #include "dbus_new_helpers.h"
 #include "dbus_new.h"
 #include "dbus_new_handlers.h"
@@ -30,6 +32,9 @@  struct wps_start_params {
 	int type; /* 0 - not set, 1 - pin,      2 - pbc       */
 	u8 *bssid;
 	char *pin;
+#ifdef CONFIG_P2P
+	u8 *p2p_dev_addr;
+#endif
 };
 
 
@@ -147,6 +152,39 @@  static int wpas_dbus_handler_wps_pin(DBusMessage *message,
 	return 0;
 }
 
+#ifdef CONFIG_P2P
+static int wpas_dbus_handler_wps_p2p_dev_addr(DBusMessage *message,
+					      DBusMessageIter *entry_iter,
+					      struct wps_start_params *params,
+					      DBusMessage **reply)
+{
+	DBusMessageIter variant_iter, array_iter;
+	int len;
+
+	dbus_message_iter_recurse(entry_iter, &variant_iter);
+	if (dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_ARRAY ||
+	    dbus_message_iter_get_element_type(&variant_iter) !=
+	    DBUS_TYPE_BYTE) {
+		wpa_printf(MSG_DEBUG, "dbus: WPS.Start - Wrong "
+			   "P2PDeviceAddress type, byte array required");
+		*reply = wpas_dbus_error_invalid_args(
+			message, "P2PDeviceAddress must be a byte array");
+		return -1;
+	}
+	dbus_message_iter_recurse(&variant_iter, &array_iter);
+	dbus_message_iter_get_fixed_array(&array_iter, &params->p2p_dev_addr,
+					  &len);
+	if (len != ETH_ALEN) {
+		wpa_printf(MSG_DEBUG, "dbus: WPS.Start - Wrong "
+			   "P2PDeviceAddress length %d", len);
+		*reply = wpas_dbus_error_invalid_args(message,
+						      "P2PDeviceAddress "
+						      "is wrong length");
+		return -1;
+	}
+	return 0;
+}
+#endif
 
 static int wpas_dbus_handler_wps_start_entry(DBusMessage *message, char *key,
 					     DBusMessageIter *entry_iter,
@@ -165,6 +203,11 @@  static int wpas_dbus_handler_wps_start_entry(DBusMessage *message, char *key,
 	else if (os_strcmp(key, "Pin") == 0)
 		return wpas_dbus_handler_wps_pin(message, entry_iter,
 						 params, reply);
+#ifdef CONFIG_P2P
+	else if (os_strcmp(key, "P2PDeviceAddress") == 0)
+		return wpas_dbus_handler_wps_p2p_dev_addr(message, entry_iter,
+							  params, reply);
+#endif
 
 	wpa_printf(MSG_DEBUG, "dbus: WPS.Start - unknown key %s", key);
 	*reply = wpas_dbus_error_invalid_args(message, key);
@@ -231,12 +274,31 @@  DBusMessage * wpas_dbus_handler_wps_start(DBusMessage *message,
 		ret = wpas_wps_start_reg(wpa_s, params.bssid, params.pin,
 					 NULL);
 	else if (params.type == 1) {
-		ret = wpas_wps_start_pin(wpa_s, params.bssid, params.pin, 0,
-					 DEV_PW_DEFAULT);
-		if (ret > 0)
-			os_snprintf(npin, sizeof(npin), "%08d", ret);
-	} else
+#if defined(CONFIG_AP) && defined(CONFIG_P2P)
+		if (wpa_s->ap_iface)
+			ret = wpa_supplicant_ap_wps_pin(wpa_s,
+							params.bssid,
+							params.pin,
+							npin, sizeof(npin));
+		else
+#endif /* CONFIG_AP */
+		{
+			ret = wpas_wps_start_pin(wpa_s, params.bssid,
+						 params.pin, 0,
+						 DEV_PW_DEFAULT);
+			if (ret > 0)
+				os_snprintf(npin, sizeof(npin), "%08d", ret);
+		}
+	} else {
+#if defined(CONFIG_AP) && defined(CONFIG_P2P)
+		if (wpa_s->ap_iface)
+			ret = wpa_supplicant_ap_wps_pbc(wpa_s,
+							params.bssid,
+							params.p2p_dev_addr);
+		else
+#endif /* CONFIG_AP */
 		ret = wpas_wps_start_pbc(wpa_s, params.bssid, 0);
+	}
 
 	if (ret < 0) {
 		wpa_printf(MSG_DEBUG, "dbus: WPS.Start wpas_wps_failed in "
-- 
1.7.8