Ejemplo n.º 1
0
int wps_process_oob(struct wps_context *wps, struct oob_device_data *oob_dev,
		    int registrar)
{
	struct wpabuf *data;
	int ret, write_f, oob_method = wps->oob_conf.oob_method;
	void *oob_priv;

	write_f = oob_method == OOB_METHOD_DEV_PWD_E ? !registrar : registrar;

	oob_priv = oob_dev->init_func(wps, oob_dev, registrar);
	if (oob_priv == NULL) {
		wpa_printf(MSG_ERROR, "WPS: Failed to initialize OOB device");
		return -1;
	}

	if (write_f) {
		if (oob_method == OOB_METHOD_CRED)
			data = wps_get_oob_cred(wps);
		else
			data = wps_get_oob_dev_pwd(wps);

		ret = 0;
		if (data == NULL || oob_dev->write_func(oob_priv, data) < 0)
			ret = -1;
	} else {
		data = oob_dev->read_func(oob_priv);
		if (data == NULL)
			ret = -1;
		else {
			if (oob_method == OOB_METHOD_CRED)
				ret = wps_parse_oob_cred(wps, data);
			else
				ret = wps_parse_oob_dev_pwd(wps, data);
		}
	}
	wpabuf_free(data);
	oob_dev->deinit_func(oob_priv);

	if (ret < 0) {
		wpa_printf(MSG_ERROR, "WPS: Failed to process OOB data");
		return -1;
	}

	return 0;
}
struct wpabuf * hostapd_wps_nfc_config_token(struct hostapd_data *hapd,
					     int ndef)
{
	struct wpabuf *ret;

	if (hapd->wps == NULL)
		return NULL;

	ret = wps_get_oob_cred(hapd->wps);
	if (ndef && ret) {
		struct wpabuf *tmp;
		tmp = ndef_build_wifi(ret);
		wpabuf_free(ret);
		if (tmp == NULL)
			return NULL;
		ret = tmp;
	}

	return ret;
}