WPS: Add more debug details for Credential building
[libeap.git] / src / wps / wps_registrar.c
index 0b71484..67fe9d0 100644 (file)
@@ -126,6 +126,7 @@ struct wps_registrar {
        int sel_reg_dev_password_id_override;
        int sel_reg_config_methods_override;
        int static_wep_only;
+       int dualband;
 
        struct wps_registrar_device *devices;
 
@@ -430,6 +431,20 @@ static int wps_build_sel_reg_dev_password_id(struct wps_registrar *reg,
 }
 
 
+static int wps_build_sel_pbc_reg_uuid_e(struct wps_registrar *reg,
+                                       struct wpabuf *msg)
+{
+       u16 id = reg->pbc ? DEV_PW_PUSHBUTTON : DEV_PW_DEFAULT;
+       if (!reg->sel_reg_union)
+               return 0;
+       if (reg->sel_reg_dev_password_id_override >= 0)
+               id = reg->sel_reg_dev_password_id_override;
+       if (id != DEV_PW_PUSHBUTTON || !reg->dualband)
+               return 0;
+       return wps_build_uuid_e(msg, reg->wps->uuid);
+}
+
+
 static void wps_set_pushbutton(u16 *methods, u16 conf_methods)
 {
        *methods |= WPS_CONFIG_PUSHBUTTON;
@@ -572,6 +587,7 @@ wps_registrar_init(struct wps_context *wps,
        reg->sel_reg_dev_password_id_override = -1;
        reg->sel_reg_config_methods_override = -1;
        reg->static_wep_only = cfg->static_wep_only;
+       reg->dualband = cfg->dualband;
 
        if (wps_set_ie(reg)) {
                wps_registrar_deinit(reg);
@@ -1069,6 +1085,8 @@ static int wps_set_ie(struct wps_registrar *reg)
            wps_build_selected_registrar(reg, beacon) ||
            wps_build_sel_reg_dev_password_id(reg, beacon) ||
            wps_build_sel_reg_config_methods(reg, beacon) ||
+           wps_build_sel_pbc_reg_uuid_e(reg, beacon) ||
+           (reg->dualband && wps_build_rf_bands(&reg->wps->dev, beacon)) ||
            wps_build_wfa_ext(beacon, 0, auth_macs, count)) {
                wpabuf_free(beacon);
                wpabuf_free(probe);
@@ -1255,7 +1273,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);
@@ -1267,6 +1285,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);
@@ -1303,6 +1323,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);
@@ -1447,8 +1469,11 @@ int wps_build_cred(struct wps_data *wps, struct wpabuf *msg)
        }
 
 use_provided:
-#ifdef CONFIG_WPS_TESTING_EXTRA_CRED
-       cred = wpabuf_alloc(200);
+#ifdef CONFIG_WPS_TESTING
+       if (wps_testing_dummy_cred)
+               cred = wpabuf_alloc(200);
+       else
+               cred = NULL;
        if (cred) {
                struct wps_credential dummy;
                wpa_printf(MSG_DEBUG, "WPS: Add dummy credential");
@@ -1469,7 +1494,7 @@ use_provided:
 
                wpabuf_free(cred);
        }
-#endif /* CONFIG_WPS_TESTING_EXTRA_CRED */
+#endif /* CONFIG_WPS_TESTING */
 
        cred = wpabuf_alloc(200);
        if (cred == NULL)
@@ -2405,7 +2430,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;
@@ -2534,7 +2559,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;