WPS: Add Config Error into WPS-FAIL events
[libeap.git] / src / wps / wps_registrar.c
index 0d8c72e..7da374a 100644 (file)
@@ -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);
@@ -1273,7 +1274,7 @@ static int wps_build_r_snonce2(struct wps_data *wps, struct wpabuf *msg)
 static int wps_build_cred_network_idx(struct wpabuf *msg,
                                      const struct wps_credential *cred)
 {
-       wpa_printf(MSG_DEBUG, "WPS:  * Network Index");
+       wpa_printf(MSG_DEBUG, "WPS:  * Network Index (1)");
        wpabuf_put_be16(msg, ATTR_NETWORK_INDEX);
        wpabuf_put_be16(msg, 1);
        wpabuf_put_u8(msg, 1);
@@ -1285,6 +1286,8 @@ static int wps_build_cred_ssid(struct wpabuf *msg,
                               const struct wps_credential *cred)
 {
        wpa_printf(MSG_DEBUG, "WPS:  * SSID");
+       wpa_hexdump_ascii(MSG_DEBUG, "WPS: SSID for Credential",
+                         cred->ssid, cred->ssid_len);
        wpabuf_put_be16(msg, ATTR_SSID);
        wpabuf_put_be16(msg, cred->ssid_len);
        wpabuf_put_data(msg, cred->ssid, cred->ssid_len);
@@ -1321,6 +1324,8 @@ static int wps_build_cred_network_key(struct wpabuf *msg,
 {
        wpa_printf(MSG_DEBUG, "WPS:  * Network Key (len=%d)",
                   (int) cred->key_len);
+       wpa_hexdump_key(MSG_DEBUG, "WPS: Network Key",
+                       cred->key, cred->key_len);
        wpabuf_put_be16(msg, ATTR_NETWORK_KEY);
        wpabuf_put_be16(msg, cred->key_len);
        wpabuf_put_data(msg, cred->key, cred->key_len);
@@ -2426,7 +2431,7 @@ static enum wps_process_res wps_process_m5(struct wps_data *wps,
                return WPS_CONTINUE;
        }
 
-       if (wps_validate_m5_encr(decrypted) < 0) {
+       if (wps_validate_m5_encr(decrypted, attr->version2 != NULL) < 0) {
                wpabuf_free(decrypted);
                wps->state = SEND_WSC_NACK;
                return WPS_CONTINUE;
@@ -2505,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);
@@ -2555,7 +2567,8 @@ static enum wps_process_res wps_process_m7(struct wps_data *wps,
                return WPS_CONTINUE;
        }
 
-       if (wps_validate_m7_encr(decrypted, wps->wps->ap || wps->er) < 0) {
+       if (wps_validate_m7_encr(decrypted, wps->wps->ap || wps->er,
+                                attr->version2 != NULL) < 0) {
                wpabuf_free(decrypted);
                wps->state = SEND_WSC_NACK;
                return WPS_CONTINUE;
@@ -2625,21 +2638,21 @@ static enum wps_process_res wps_process_wsc_msg(struct wps_data *wps,
                        return WPS_FAILURE;
                ret = wps_process_m3(wps, msg, &attr);
                if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
-                       wps_fail_event(wps->wps, WPS_M3);
+                       wps_fail_event(wps->wps, WPS_M3, wps->config_error);
                break;
        case WPS_M5:
                if (wps_validate_m5(msg) < 0)
                        return WPS_FAILURE;
                ret = wps_process_m5(wps, msg, &attr);
                if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
-                       wps_fail_event(wps->wps, WPS_M5);
+                       wps_fail_event(wps->wps, WPS_M5, wps->config_error);
                break;
        case WPS_M7:
                if (wps_validate_m7(msg) < 0)
                        return WPS_FAILURE;
                ret = wps_process_m7(wps, msg, &attr);
                if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
-                       wps_fail_event(wps->wps, WPS_M7);
+                       wps_fail_event(wps->wps, WPS_M7, wps->config_error);
                break;
        default:
                wpa_printf(MSG_DEBUG, "WPS: Unsupported Message Type %d",
@@ -2730,6 +2743,7 @@ static enum wps_process_res wps_process_wsc_nack(struct wps_data *wps,
 {
        struct wps_parse_attr attr;
        int old_state;
+       u16 config_error;
 
        wpa_printf(MSG_DEBUG, "WPS: Received WSC_NACK");
 
@@ -2777,21 +2791,22 @@ static enum wps_process_res wps_process_wsc_nack(struct wps_data *wps,
                return WPS_FAILURE;
        }
 
+       config_error = WPA_GET_BE16(attr.config_error);
        wpa_printf(MSG_DEBUG, "WPS: Enrollee terminated negotiation with "
-                  "Configuration Error %d", WPA_GET_BE16(attr.config_error));
+                  "Configuration Error %d", config_error);
 
        switch (old_state) {
        case RECV_M3:
-               wps_fail_event(wps->wps, WPS_M2);
+               wps_fail_event(wps->wps, WPS_M2, config_error);
                break;
        case RECV_M5:
-               wps_fail_event(wps->wps, WPS_M4);
+               wps_fail_event(wps->wps, WPS_M4, config_error);
                break;
        case RECV_M7:
-               wps_fail_event(wps->wps, WPS_M6);
+               wps_fail_event(wps->wps, WPS_M6, config_error);
                break;
        case RECV_DONE:
-               wps_fail_event(wps->wps, WPS_M8);
+               wps_fail_event(wps->wps, WPS_M8, config_error);
                break;
        default:
                break;
@@ -2974,7 +2989,8 @@ enum wps_process_res wps_registrar_process_msg(struct wps_data *wps,
                ret = wps_process_wsc_done(wps, msg);
                if (ret == WPS_FAILURE) {
                        wps->state = SEND_WSC_NACK;
-                       wps_fail_event(wps->wps, WPS_WSC_DONE);
+                       wps_fail_event(wps->wps, WPS_WSC_DONE,
+                                      wps->config_error);
                }
                return ret;
        default: