static enum wps_process_res wps_process_wsc_ack(struct wps_data *wps,
                        const struct wpabuf *msg)
{
    struct wps_parse_attr attr;

    wpa_printf(MSG_DEBUG, "WPS: Received WSC_ACK");

    if (wps_parse_msg(msg, &attr) < 0)
        return WPS_FAILURE;

    if (!wps_version_supported(attr.version)) {
        wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
               attr.version ? *attr.version : 0);
        return WPS_FAILURE;
    }

    if (attr.msg_type == NULL) {
        wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
        return WPS_FAILURE;
    }

    if (*attr.msg_type != WPS_WSC_ACK) {
        wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
               *attr.msg_type);
        return WPS_FAILURE;
    }

    if (attr.registrar_nonce == NULL ||
        os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN != 0))
    {
        wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
        return WPS_FAILURE;
    }

    if (attr.enrollee_nonce == NULL ||
        os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN != 0)) {
        wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
        return WPS_FAILURE;
    }

    if (wps->state == RECV_ACK && wps->wps->ap) {
        wpa_printf(MSG_DEBUG, "WPS: External Registrar registration "
               "completed successfully");
        wps_success_event(wps->wps);
        wps->state = WPS_FINISHED;
        return WPS_DONE;
    }

    return WPS_FAILURE;
}
Beispiel #2
0
int upnp_er_set_selected_registrar(struct wps_registrar *reg,
				   struct subscription *s,
				   const struct wpabuf *msg)
{
	struct wps_parse_attr attr;

	wpa_hexdump_buf(MSG_MSGDUMP, "WPS: SetSelectedRegistrar attributes",
			msg);

	if (wps_parse_msg(msg, &attr) < 0)
		return -1;
	if (!wps_version_supported(attr.version)) {
		wpa_printf(MSG_DEBUG, "WPS: Unsupported SetSelectedRegistrar "
			   "version 0x%x", attr.version ? *attr.version : 0);
		return -1;
	}

	s->reg = reg;
	eloop_cancel_timeout(upnp_er_set_selected_timeout, s, NULL);

	if (attr.selected_registrar == NULL || *attr.selected_registrar == 0) {
		wpa_printf(MSG_DEBUG, "WPS: SetSelectedRegistrar: Disable "
			   "Selected Registrar");
		s->selected_registrar = 0;
	} else {
		s->selected_registrar = 1;
		s->dev_password_id = attr.dev_password_id ?
			WPA_GET_BE16(attr.dev_password_id) : DEV_PW_DEFAULT;
		s->config_methods = attr.sel_reg_config_methods ?
			WPA_GET_BE16(attr.sel_reg_config_methods) : -1;
		eloop_register_timeout(WPS_PBC_WALK_TIME, 0,
				       upnp_er_set_selected_timeout, s, NULL);
	}

	wps_registrar_selected_registrar_changed(reg);

	return 0;
}
static enum wps_process_res wps_process_wsc_msg(struct wps_data *wps,
                        const struct wpabuf *msg)
{
    struct wps_parse_attr attr;
    enum wps_process_res ret = WPS_CONTINUE;

    wpa_printf(MSG_DEBUG, "WPS: Received WSC_MSG");

    if (wps_parse_msg(msg, &attr) < 0)
        return WPS_FAILURE;

    if (!wps_version_supported(attr.version)) {
        wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
               attr.version ? *attr.version : 0);
        return WPS_FAILURE;
    }

    if (attr.enrollee_nonce == NULL ||
        os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN != 0)) {
        wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
        return WPS_FAILURE;
    }

    if (attr.msg_type == NULL) {
        wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
        return WPS_FAILURE;
    }

    switch (*attr.msg_type) {
    case WPS_M2:
        ret = wps_process_m2(wps, msg, &attr);
        break;
    case WPS_M2D:
        ret = wps_process_m2d(wps, &attr);
        break;
    case WPS_M4:
        ret = wps_process_m4(wps, msg, &attr);
        if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
            wps_fail_event(wps->wps, WPS_M4);
        break;
    case WPS_M6:
        ret = wps_process_m6(wps, msg, &attr);
        if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
            wps_fail_event(wps->wps, WPS_M6);
        break;
    case WPS_M8:
        ret = wps_process_m8(wps, msg, &attr);
        if (ret == WPS_FAILURE || wps->state == SEND_WSC_NACK)
            wps_fail_event(wps->wps, WPS_M8);
        break;
    default:
        wpa_printf(MSG_DEBUG, "WPS: Unsupported Message Type %d",
               *attr.msg_type);
        return WPS_FAILURE;
    }

    /*
     * Save a copy of the last message for Authenticator derivation if we
     * are continuing. However, skip M2D since it is not authenticated and
     * neither is the ACK/NACK response frame. This allows the possibly
     * following M2 to be processed correctly by using the previously sent
     * M1 in Authenticator derivation.
     */
    if (ret == WPS_CONTINUE && *attr.msg_type != WPS_M2D) {
        /* Save a copy of the last message for Authenticator derivation
         */
        wpabuf_free(wps->last_msg);
        wps->last_msg = wpabuf_dup(msg);
    }

    return ret;
}
static enum wps_process_res wps_process_wsc_nack(struct wps_data *wps,
                         const struct wpabuf *msg)
{
    struct wps_parse_attr attr;

    wpa_printf(MSG_DEBUG, "WPS: Received WSC_NACK");

    if (wps_parse_msg(msg, &attr) < 0)
        return WPS_FAILURE;

    if (!wps_version_supported(attr.version)) {
        wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
               attr.version ? *attr.version : 0);
        return WPS_FAILURE;
    }

    if (attr.msg_type == NULL) {
        wpa_printf(MSG_DEBUG, "WPS: No Message Type attribute");
        return WPS_FAILURE;
    }

    if (*attr.msg_type != WPS_WSC_NACK) {
        wpa_printf(MSG_DEBUG, "WPS: Invalid Message Type %d",
               *attr.msg_type);
        return WPS_FAILURE;
    }

    if (attr.registrar_nonce == NULL ||
        os_memcmp(wps->nonce_r, attr.registrar_nonce, WPS_NONCE_LEN != 0))
    {
        wpa_printf(MSG_DEBUG, "WPS: Mismatch in registrar nonce");
        wpa_hexdump(MSG_DEBUG, "WPS: Received Registrar Nonce",
                attr.registrar_nonce, WPS_NONCE_LEN);
        wpa_hexdump(MSG_DEBUG, "WPS: Expected Registrar Nonce",
                wps->nonce_r, WPS_NONCE_LEN);
        return WPS_FAILURE;
    }

    if (attr.enrollee_nonce == NULL ||
        os_memcmp(wps->nonce_e, attr.enrollee_nonce, WPS_NONCE_LEN != 0)) {
        wpa_printf(MSG_DEBUG, "WPS: Mismatch in enrollee nonce");
        wpa_hexdump(MSG_DEBUG, "WPS: Received Enrollee Nonce",
                attr.enrollee_nonce, WPS_NONCE_LEN);
        wpa_hexdump(MSG_DEBUG, "WPS: Expected Enrollee Nonce",
                wps->nonce_e, WPS_NONCE_LEN);
        return WPS_FAILURE;
    }

    if (attr.config_error == NULL) {
        wpa_printf(MSG_DEBUG, "WPS: No Configuration Error attribute "
               "in WSC_NACK");
        return WPS_FAILURE;
    }

    wpa_printf(MSG_DEBUG, "WPS: Registrar terminated negotiation with "
           "Configuration Error %d", WPA_GET_BE16(attr.config_error));

    switch (wps->state) {
    case RECV_M4:
        wps_fail_event(wps->wps, WPS_M3);
        break;
    case RECV_M6:
        wps_fail_event(wps->wps, WPS_M5);
        break;
    case RECV_M8:
        wps_fail_event(wps->wps, WPS_M7);
        break;
    default:
        break;
    }

    /* Followed by NACK if Enrollee is Supplicant or EAP-Failure if
     * Enrollee is Authenticator */
    wps->state = SEND_WSC_NACK;

    return WPS_FAILURE;
}