[PATCH] WPS: Send the credential when learning AP params in registrar role

Olivier Sobrie olivier
Tue Aug 9 15:02:02 PDT 2011


When the supplicant acts as a registrar to learn the access point
parameters then send the credentials to the wpa_cli interface after
receiving the 7th message.
When setting the option 'wps_cred_processing' to 1 or 2 in the
wpa_supplicant.conf you should receive the credential through the
wpa control interface.

Without this patch, after the 7th message you got the WPS-CRED-RECEIVED
notification without the credentials. This was because the cred_attr and
cred_attr_len were not filled in in the wps structure.

Signed-off-by: Olivier Sobrie <olivier at sobrie.be>
---
 src/wps/wps_registrar.c |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/src/wps/wps_registrar.c b/src/wps/wps_registrar.c
index 2d7f632..1f964e7 100644
--- a/src/wps/wps_registrar.c
+++ b/src/wps/wps_registrar.c
@@ -1592,6 +1592,29 @@ static int wps_build_ap_settings(struct wps_data *wps, struct wpabuf *msg)
 	return 0;
 }
 
+static int wps_build_ap_cred(struct wps_data *wps, struct wpabuf *msg)
+{
+	struct wpabuf *plain;
+
+	plain = wpabuf_alloc(200);
+	if (plain == NULL)
+		return -1;
+
+	if (wps_build_ap_settings(wps, plain)) {
+		wpabuf_free(plain);
+		return -1;
+	}
+
+	wpabuf_put_be16(msg, ATTR_CRED);
+	wpabuf_put_be16(msg, wpabuf_len(plain));
+	wpabuf_put_buf(msg, plain);
+	wpabuf_free(plain);
+
+	wps->cred.cred_attr = wpabuf_head(msg);
+	wps->cred.cred_attr_len = wpabuf_len(msg);
+
+	return 0;
+}
 
 static struct wpabuf * wps_build_m2(struct wps_data *wps)
 {
@@ -2551,6 +2574,8 @@ static void wps_cred_update(struct wps_credential *dst,
 static int wps_process_ap_settings_r(struct wps_data *wps,
 				     struct wps_parse_attr *attr)
 {
+	struct wpabuf *msg;
+
 	if (wps->wps->ap || wps->er)
 		return 0;
 
@@ -2577,12 +2602,23 @@ static int wps_process_ap_settings_r(struct wps_data *wps,
 		 */
 		wps_registrar_pin_completed(wps->wps->registrar);
 
+		msg = wpabuf_alloc(1000);
+		if (msg == NULL)
+			return -1;
+
+		if (wps_build_ap_cred(wps, msg)) {
+			wpabuf_free(msg);
+			return -1;
+		}
+
 		if (wps->ap_settings_cb) {
 			wps->ap_settings_cb(wps->ap_settings_cb_ctx,
 					    &wps->cred);
+			wpabuf_free(msg);
 			return 1;
 		}
 		wps_sta_cred_cb(wps);
+		wpabuf_free(msg);
 		return 1;
 	}
 }
-- 
1.7.6




More information about the Hostap mailing list