From a9d69254e30922136829be38179c924d1a632617 Mon Sep 17 00:00:00 2001
From: Jouni Malinen <jouni.malinen@atheros.com>
Date: Thu, 23 Sep 2010 14:45:55 -0700
Subject: [PATCH] WPS ER: Make sure PIN timeout does not interrupt PBC
 operation

We need to clear the selected registrar timeout from wps_er_learn
when stopping the protocol run at M7 (previously, this was done only
when WSC_Done was being processed). In addition, we need to cancel
the timeout when a new PBC operation is started.
---
 src/wps/wps_er.c        | 6 ++++++
 src/wps/wps_registrar.c | 8 ++++++++
 2 files changed, 14 insertions(+)

diff --git a/src/wps/wps_er.c b/src/wps/wps_er.c
index 4726e5261..c582f4c85 100644
--- a/src/wps/wps_er.c
+++ b/src/wps/wps_er.c
@@ -1301,6 +1301,12 @@ static void wps_er_send_set_sel_reg(struct wps_er_ap *ap, struct wpabuf *msg)
 		return;
 	}
 
+	if (ap->wps) {
+		wpa_printf(MSG_DEBUG, "WPS ER: Pending WPS operation for AP - "
+			   "skip SetSelectedRegistrar");
+		return;
+	}
+
 	url = http_client_url_parse(ap->control_url, &dst, &path);
 	if (url == NULL) {
 		wpa_printf(MSG_DEBUG, "WPS ER: Failed to parse controlURL");
diff --git a/src/wps/wps_registrar.c b/src/wps/wps_registrar.c
index 67fe9d0e3..1beea75e0 100644
--- a/src/wps/wps_registrar.c
+++ b/src/wps/wps_registrar.c
@@ -878,6 +878,7 @@ int wps_registrar_button_pushed(struct wps_registrar *reg)
 	reg->pbc = 1;
 	wps_registrar_selected_registrar_changed(reg);
 
+	eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
 	eloop_cancel_timeout(wps_registrar_pbc_timeout, reg, NULL);
 	eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wps_registrar_pbc_timeout,
 			       reg, NULL);
@@ -2509,6 +2510,13 @@ static int wps_process_ap_settings_r(struct wps_data *wps,
 		 * Use the AP PIN only to receive the current AP settings, not
 		 * to reconfigure the AP.
 		 */
+
+		/*
+		 * Clear selected registrar here since we do not get to
+		 * WSC_Done in this protocol run.
+		 */
+		wps_registrar_pin_completed(wps->wps->registrar);
+
 		if (wps->ap_settings_cb) {
 			wps->ap_settings_cb(wps->ap_settings_cb_ctx,
 					    &wps->cred);