From c423708f020054322066741686c6ba970bc6f02a Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Wed, 10 Oct 2012 17:22:35 +0300 Subject: [PATCH] WPS: Allow PIN timeout to be specified with wpa_supplicant AP/GO Extend the wpa_cli wps_pin command to support specification of the PIN expiration time in seconds similarly to hostapd_cli wps_pin command when using wpa_supplicant for AP mode (including P2P GO). Signed-hostap: Jouni Malinen --- wpa_supplicant/README-WPS | 6 ++++++ wpa_supplicant/ap.c | 5 +++-- wpa_supplicant/ap.h | 3 ++- wpa_supplicant/ctrl_iface.c | 16 ++++++++++++++-- wpa_supplicant/dbus/dbus_new_handlers_wps.c | 2 +- wpa_supplicant/p2p_supplicant.c | 2 +- 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/wpa_supplicant/README-WPS b/wpa_supplicant/README-WPS index 692d5f556..35be3576e 100644 --- a/wpa_supplicant/README-WPS +++ b/wpa_supplicant/README-WPS @@ -130,6 +130,12 @@ wpa_cli wps_pin any 12345670 This starts the WPS negotiation in the same way as above with the generated PIN. +When the wps_pin command is issued for an AP (including P2P GO) mode +interface, an optional timeout parameter can be used to specify +expiration timeout for the PIN in seconds. For example: + +wpa_cli wps_pin any 12345670 300 + If a random PIN is needed for a user interface, "wpa_cli wps_pin get" can be used to generate a new PIN without starting WPS negotiation. diff --git a/wpa_supplicant/ap.c b/wpa_supplicant/ap.c index 3798f5a63..088f57d34 100644 --- a/wpa_supplicant/ap.c +++ b/wpa_supplicant/ap.c @@ -724,7 +724,8 @@ int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s) int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid, - const char *pin, char *buf, size_t buflen) + const char *pin, char *buf, size_t buflen, + int timeout) { int ret, ret_len = 0; @@ -739,7 +740,7 @@ int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid, ret_len = os_snprintf(buf, buflen, "%s", pin); ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin, - 0); + timeout); if (ret) return -1; return ret_len; diff --git a/wpa_supplicant/ap.h b/wpa_supplicant/ap.h index bc953d9bc..536064f7c 100644 --- a/wpa_supplicant/ap.h +++ b/wpa_supplicant/ap.h @@ -18,7 +18,8 @@ void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s, int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid, const u8 *p2p_dev_addr); int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid, - const char *pin, char *buf, size_t buflen); + const char *pin, char *buf, size_t buflen, + int timeout); int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s); void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s); const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout); diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index 75e92a945..8038b9c28 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -664,9 +664,21 @@ static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s, } #ifdef CONFIG_AP - if (wpa_s->ap_iface) + if (wpa_s->ap_iface) { + int timeout = 0; + char *pos; + + if (pin) { + pos = os_strchr(pin, ' '); + if (pos) { + *pos++ = '\0'; + timeout = atoi(pos); + } + } + return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin, - buf, buflen); + buf, buflen, timeout); + } #endif /* CONFIG_AP */ if (pin) { diff --git a/wpa_supplicant/dbus/dbus_new_handlers_wps.c b/wpa_supplicant/dbus/dbus_new_handlers_wps.c index 8489ce77c..4ad5e7e0b 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers_wps.c +++ b/wpa_supplicant/dbus/dbus_new_handlers_wps.c @@ -273,7 +273,7 @@ DBusMessage * wpas_dbus_handler_wps_start(DBusMessage *message, ret = wpa_supplicant_ap_wps_pin(wpa_s, params.bssid, params.pin, - npin, sizeof(npin)); + npin, sizeof(npin), 0); else #endif /* CONFIG_AP */ { diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index 06cbaf584..39924b17e 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -837,7 +837,7 @@ static void p2p_go_configured(void *ctx, void *data) params->peer_device_addr); else if (wpa_s->p2p_pin[0]) wpa_supplicant_ap_wps_pin(wpa_s, params->peer_interface_addr, - wpa_s->p2p_pin, NULL, 0); + wpa_s->p2p_pin, NULL, 0, 0); os_free(wpa_s->go_params); wpa_s->go_params = NULL; }