Added Doxygen documentation for WPS code
[libeap.git] / src / eap_peer / eap_wsc.c
index f6e2400..6c45993 100644 (file)
 
 
 struct eap_wsc_data {
-       enum { WAIT_START, MSG, FRAG_ACK, WAIT_FRAG_ACK, DONE, FAIL } state;
+       enum { WAIT_START, MESG, FRAG_ACK, WAIT_FRAG_ACK, DONE, FAIL } state;
        int registrar;
        struct wpabuf *in_buf;
        struct wpabuf *out_buf;
-       u8 in_op_code, out_op_code;
+       enum wsc_op_code in_op_code, out_op_code;
        size_t out_used;
        size_t fragment_size;
        struct wps_data *wps;
@@ -40,8 +40,8 @@ static const char * eap_wsc_state_txt(int state)
        switch (state) {
        case WAIT_START:
                return "WAIT_START";
-       case MSG:
-               return "MSG";
+       case MESG:
+               return "MESG";
        case FRAG_ACK:
                return "FRAG_ACK";
        case WAIT_FRAG_ACK:
@@ -68,8 +68,6 @@ static void eap_wsc_state(struct eap_wsc_data *data, int state)
 static int eap_wsc_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *psk,
                              size_t psk_len)
 {
-       /* struct eap_wsc_data *data = ctx; */
-
        wpa_printf(MSG_DEBUG, "EAP-WSC: Received new WPA/WPA2-PSK from WPS for"
                   " STA " MACSTR, MAC2STR(mac_addr));
        wpa_hexdump_key(MSG_DEBUG, "Per-device PSK", psk, psk_len);
@@ -83,7 +81,6 @@ static int eap_wsc_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *psk,
 static void eap_wsc_pin_needed_cb(void *ctx, const u8 *uuid_e,
                                  const struct wps_device_data *dev)
 {
-       /* struct eap_wsc_data *data = ctx; */
        char uuid[40], txt[400];
        int len;
        if (uuid_bin2str(uuid_e, uuid, sizeof(uuid)))
@@ -109,7 +106,13 @@ static void * eap_wsc_init(struct eap_sm *sm)
        struct wps_config cfg;
        const char *pos;
        const char *phase1;
-       struct wps_context *wps = NULL;
+       struct wps_context *wps;
+
+       wps = sm->wps;
+       if (wps == NULL) {
+               wpa_printf(MSG_ERROR, "EAP-WSC: WPS context not available");
+               return NULL;
+       }
 
        identity = eap_get_config_identity(sm, &identity_len);
 
@@ -128,20 +131,13 @@ static void * eap_wsc_init(struct eap_sm *sm)
        data = os_zalloc(sizeof(*data));
        if (data == NULL)
                return NULL;
-       data->state = registrar ? MSG : WAIT_START;
+       data->state = registrar ? MESG : WAIT_START;
        data->registrar = registrar;
+       data->wps_ctx = wps;
 
        if (registrar) {
                struct wps_registrar_config rcfg;
 
-               wps = os_zalloc(sizeof(*wps));
-               if (wps == NULL) {
-                       os_free(data);
-                       return NULL;
-               }
-
-               wps->cb_ctx = data;
-
                wps->auth_types = WPS_AUTH_WPA2PSK | WPS_AUTH_WPAPSK;
                wps->encr_types = WPS_ENCR_AES | WPS_ENCR_TKIP;
 
@@ -160,14 +156,12 @@ static void * eap_wsc_init(struct eap_sm *sm)
                        return NULL;
                }
 
-               data->wps_ctx = wps;
        }
 
        os_memset(&cfg, 0, sizeof(cfg));
        cfg.authenticator = 0;
        cfg.wps = wps;
-       cfg.registrar = data->wps_ctx ? data->wps_ctx->registrar : NULL;
-       cfg.enrollee_mac_addr = sm->mac_addr;
+       cfg.registrar = registrar ? data->wps_ctx->registrar : NULL;
 
        phase1 = eap_get_config_phase1(sm);
        if (phase1 == NULL) {
@@ -197,12 +191,6 @@ static void * eap_wsc_init(struct eap_sm *sm)
                return NULL;
        }
 
-       if (registrar && wps)
-               os_memcpy(wps->uuid, sm->uuid, UUID_LEN);
-       else
-               cfg.uuid = sm->uuid;
-       cfg.wps_cred_cb = sm->eapol_cb->wps_cred;
-       cfg.cb_ctx = sm->eapol_ctx;
        data->wps = wps_init(&cfg);
        if (data->wps == NULL) {
                os_free(data);
@@ -210,15 +198,9 @@ static void * eap_wsc_init(struct eap_sm *sm)
        }
        data->fragment_size = WSC_FRAGMENT_SIZE;
 
-
-       if (registrar) {
-               /* Testing */
-               wpa_printf(MSG_INFO, "EAP-WSC: Registrar functionality not "
-                          "yet fully supported - using test values");
-               u8 uuid_e[UUID_LEN];
-               os_memset(uuid_e, 0, UUID_LEN);
-               wps_registrar_add_pin(data->wps_ctx->registrar, uuid_e,
-                                     (const u8 *) "12345670", 8);
+       if (registrar && cfg.pin) {
+               wps_registrar_add_pin(data->wps_ctx->registrar, NULL,
+                                     cfg.pin, cfg.pin_len);
        }
 
        return data;
@@ -231,11 +213,10 @@ static void eap_wsc_deinit(struct eap_sm *sm, void *priv)
        wpabuf_free(data->in_buf);
        wpabuf_free(data->out_buf);
        wps_deinit(data->wps);
-       if (data->wps_ctx) {
-               wps_registrar_deinit(data->wps_ctx->registrar);
-               os_free(data->wps_ctx->network_key);
-               os_free(data->wps_ctx);
-       }
+       wps_registrar_deinit(data->wps_ctx->registrar);
+       data->wps_ctx->registrar = NULL;
+       os_free(data->wps_ctx->network_key);
+       data->wps_ctx->network_key = NULL;
        os_free(data);
 }
 
@@ -294,7 +275,7 @@ static struct wpabuf * eap_wsc_build_msg(struct eap_wsc_data *data,
                        eap_wsc_state(data, FAIL);
                        ret->methodState = METHOD_DONE;
                } else
-                       eap_wsc_state(data, MSG);
+                       eap_wsc_state(data, MESG);
        } else {
                wpa_printf(MSG_DEBUG, "EAP-WSC: Sending out %lu bytes "
                           "(%lu more to send)", (unsigned long) send_len,
@@ -423,7 +404,7 @@ static struct wpabuf * eap_wsc_process(struct eap_sm *sm, void *priv,
                        return NULL;
                }
                wpa_printf(MSG_DEBUG, "EAP-WSC: Fragment acknowledged");
-               eap_wsc_state(data, MSG);
+               eap_wsc_state(data, MESG);
                return eap_wsc_build_msg(data, ret, id);
        }
 
@@ -443,7 +424,7 @@ static struct wpabuf * eap_wsc_process(struct eap_sm *sm, void *priv,
                        return NULL;
                }
                wpa_printf(MSG_DEBUG, "EAP-WSC: Received start");
-               eap_wsc_state(data, MSG);
+               eap_wsc_state(data, MESG);
                /* Start message has empty payload, skip processing */
                goto send_msg;
        } else if (op_code == WSC_Start) {
@@ -479,7 +460,7 @@ static struct wpabuf * eap_wsc_process(struct eap_sm *sm, void *priv,
                eap_wsc_state(data, FAIL);
                break;
        case WPS_CONTINUE:
-               eap_wsc_state(data, MSG);
+               eap_wsc_state(data, MESG);
                break;
        case WPS_FAILURE:
                wpa_printf(MSG_DEBUG, "EAP-WSC: WPS processing failed");
@@ -508,7 +489,7 @@ send_msg:
                data->out_used = 0;
        }
 
-       eap_wsc_state(data, MSG);
+       eap_wsc_state(data, MESG);
        return eap_wsc_build_msg(data, ret, id);
 }