WPS ER: Fix debug message for protocol run done case
[libeap.git] / src / wps / wps_er.c
index fdcc1cb..4726e52 100644 (file)
@@ -763,6 +763,7 @@ static void wps_er_process_wlanevent_probe_req(struct wps_er_ap *ap,
        }
 
        wps_er_add_sta_data(ap, addr, &attr, 1);
+       wps_registrar_probe_req_rx(ap->er->wps->registrar, addr, msg, 0);
 }
 
 
@@ -1349,21 +1350,43 @@ static int wps_er_build_sel_reg_config_methods(struct wpabuf *msg,
 }
 
 
+static int wps_er_build_uuid_r(struct wpabuf *msg, const u8 *uuid_r)
+{
+#ifdef CONFIG_WPS2
+       wpabuf_put_be16(msg, ATTR_UUID_R);
+       wpabuf_put_be16(msg, WPS_UUID_LEN);
+       wpabuf_put_data(msg, uuid_r, WPS_UUID_LEN);
+#endif /* CONFIG_WPS2 */
+       return 0;
+}
+
+
 void wps_er_set_sel_reg(struct wps_er *er, int sel_reg, u16 dev_passwd_id,
                        u16 sel_reg_config_methods)
 {
        struct wpabuf *msg;
        struct wps_er_ap *ap;
+       struct wps_registrar *reg = er->wps->registrar;
+       const u8 *auth_macs;
+       size_t count;
+
+       if (er->skip_set_sel_reg) {
+               wpa_printf(MSG_DEBUG, "WPS ER: Skip SetSelectedRegistrar");
+               return;
+       }
 
        msg = wpabuf_alloc(500);
        if (msg == NULL)
                return;
 
+       auth_macs = wps_authorized_macs(reg, &count);
+
        if (wps_build_version(msg) ||
            wps_er_build_selected_registrar(msg, sel_reg) ||
            wps_er_build_dev_password_id(msg, dev_passwd_id) ||
            wps_er_build_sel_reg_config_methods(msg, sel_reg_config_methods) ||
-           wps_build_version2(msg)) {
+           wps_build_wfa_ext(msg, 0, auth_macs, count) ||
+           wps_er_build_uuid_r(msg, er->wps->uuid)) {
                wpabuf_free(msg);
                return;
        }
@@ -1380,6 +1403,12 @@ int wps_er_pbc(struct wps_er *er, const u8 *uuid)
        if (er == NULL || er->wps == NULL)
                return -1;
 
+       if (wps_registrar_pbc_overlap(er->wps->registrar, NULL, NULL)) {
+               wpa_printf(MSG_DEBUG, "WPS ER: PBC overlap - do not start PBC "
+                          "mode");
+               return -1;
+       }
+
        /*
         * TODO: Should enable PBC mode only in a single AP based on which AP
         * the Enrollee (uuid) is using. Now, we may end up enabling multiple
@@ -1534,6 +1563,10 @@ static void wps_er_ap_process(struct wps_er_ap *ap, struct wpabuf *msg)
                        wps_deinit(ap->wps);
                        ap->wps = NULL;
                }
+       } else if (res == WPS_DONE) {
+               wpa_printf(MSG_DEBUG, "WPS ER: Protocol run done");
+               wps_deinit(ap->wps);
+               ap->wps = NULL;
        } else {
                wpa_printf(MSG_DEBUG, "WPS ER: Failed to process message from "
                           "AP (res=%d)", res);
@@ -1689,8 +1722,9 @@ int wps_er_learn(struct wps_er *er, const u8 *uuid, const u8 *pin,
        if (wps_er_send_get_device_info(ap, wps_er_ap_learn_m1) < 0)
                return -1;
 
-       /* TODO: add PIN without SetSelectedRegistrar trigger to all APs */
-       wps_registrar_add_pin(er->wps->registrar, uuid, pin, pin_len, 0);
+       er->skip_set_sel_reg = 1;
+       wps_registrar_add_pin(er->wps->registrar, NULL, uuid, pin, pin_len, 0);
+       er->skip_set_sel_reg = 0;
 
        return 0;
 }
@@ -1750,8 +1784,9 @@ int wps_er_config(struct wps_er *er, const u8 *uuid, const u8 *pin,
        if (wps_er_send_get_device_info(ap, wps_er_ap_config_m1) < 0)
                return -1;
 
-       /* TODO: add PIN without SetSelectedRegistrar trigger to all APs */
-       wps_registrar_add_pin(er->wps->registrar, uuid, pin, pin_len, 0);
+       er->skip_set_sel_reg = 1;
+       wps_registrar_add_pin(er->wps->registrar, NULL, uuid, pin, pin_len, 0);
+       er->skip_set_sel_reg = 0;
 
        return 0;
 }