WPS: Add WPS-FAIL ctrl_interface event for hostapd
[mech_eap.git] / src / ap / wps_hostapd.c
index 115f2d4..38ac937 100644 (file)
@@ -75,10 +75,10 @@ static int hostapd_wps_for_each(struct hostapd_data *hapd,
 {
        struct hostapd_iface *iface = hapd->iface;
        struct wps_for_each_data data;
-       if (iface->for_each_interface == NULL)
-               return -1;
        data.func = func;
        data.ctx = ctx;
+       if (iface->for_each_interface == NULL)
+               return wps_for_each(iface, &data);
        return iface->for_each_interface(iface->interfaces, wps_for_each,
                                         &data);
 }
@@ -239,9 +239,9 @@ static void wps_reload_config(void *eloop_data, void *user_ctx)
 }
 
 
-static int hostapd_wps_cred_cb(void *ctx, const struct wps_credential *cred)
+static int hapd_wps_cred_cb(struct hostapd_data *hapd, void *ctx)
 {
-       struct hostapd_data *hapd = ctx;
+       const struct wps_credential *cred = ctx;
        FILE *oconf, *nconf;
        size_t len, i;
        char *tmp_fname;
@@ -249,6 +249,9 @@ static int hostapd_wps_cred_cb(void *ctx, const struct wps_credential *cred)
        int multi_bss;
        int wpa;
 
+       if (hapd->wps == NULL)
+               return 0;
+
        wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
                        cred->cred_attr, cred->cred_attr_len);
 
@@ -453,14 +456,19 @@ static int hostapd_wps_cred_cb(void *ctx, const struct wps_credential *cred)
        eloop_register_timeout(0, 100000, wps_reload_config, hapd->iface,
                               NULL);
 
-       /* TODO: dualband AP may need to update multiple configuration files */
-
        wpa_printf(MSG_DEBUG, "WPS: AP configuration updated");
 
        return 0;
 }
 
 
+static int hostapd_wps_cred_cb(void *ctx, const struct wps_credential *cred)
+{
+       struct hostapd_data *hapd = ctx;
+       return hostapd_wps_for_each(hapd, hapd_wps_cred_cb, (void *) cred);
+}
+
+
 static void hostapd_wps_reenable_ap_pin(void *eloop_data, void *user_ctx)
 {
        struct hostapd_data *hapd = eloop_data;
@@ -524,13 +532,46 @@ static void hostapd_pwd_auth_fail(struct hostapd_data *hapd,
 }
 
 
+static void hostapd_wps_event_fail(struct hostapd_data *hapd,
+                                  struct wps_event_fail *fail)
+{
+       wpa_msg(hapd->msg_ctx, MSG_INFO,
+               WPS_EVENT_FAIL "msg=%d config_error=%d",
+               fail->msg, fail->config_error);
+}
+
+
 static void hostapd_wps_event_cb(void *ctx, enum wps_event event,
                                 union wps_event_data *data)
 {
        struct hostapd_data *hapd = ctx;
 
-       if (event == WPS_EV_PWD_AUTH_FAIL)
+       switch (event) {
+       case WPS_EV_M2D:
+               break;
+       case WPS_EV_FAIL:
+               hostapd_wps_event_fail(hapd, &data->fail);
+               break;
+       case WPS_EV_SUCCESS:
+               break;
+       case WPS_EV_PWD_AUTH_FAIL:
                hostapd_pwd_auth_fail(hapd, &data->pwd_auth_fail);
+               break;
+       case WPS_EV_PBC_OVERLAP:
+               break;
+       case WPS_EV_PBC_TIMEOUT:
+               break;
+       case WPS_EV_ER_AP_ADD:
+               break;
+       case WPS_EV_ER_AP_REMOVE:
+               break;
+       case WPS_EV_ER_ENROLLEE_ADD:
+               break;
+       case WPS_EV_ER_ENROLLEE_REMOVE:
+               break;
+       case WPS_EV_ER_AP_SETTINGS:
+               break;
+       }
 }