#include "common.h"
#include "ieee802_11_defs.h"
+#include "ieee802_11_common.h"
#include "wpa_common.h"
#include "config.h"
#include "eap_peer/eap.h"
#include "wpa_supplicant_i.h"
+#include "driver_i.h"
#include "eloop.h"
#include "uuid.h"
#include "wpa_ctrl.h"
-#include "ctrl_iface_dbus.h"
+#include "notify.h"
#include "eap_common/eap_wsc_common.h"
#include "blacklist.h"
+#include "wpa.h"
#include "wps_supplicant.h"
+#include "dh_group5.h"
#define WPS_PIN_SCAN_IGNORE_SEL_REG 3
}
+static void wpas_wps_security_workaround(struct wpa_supplicant *wpa_s,
+ struct wpa_ssid *ssid,
+ const struct wps_credential *cred)
+{
+ struct wpa_driver_capa capa;
+ size_t i;
+ struct wpa_scan_res *bss;
+ const u8 *ie;
+ struct wpa_ie_data adv;
+ int wpa2 = 0, ccmp = 0;
+
+ /*
+ * Many existing WPS APs do not know how to negotiate WPA2 or CCMP in
+ * case they are configured for mixed mode operation (WPA+WPA2 and
+ * TKIP+CCMP). Try to use scan results to figure out whether the AP
+ * actually supports stronger security and select that if the client
+ * has support for it, too.
+ */
+
+ if (wpa_drv_get_capa(wpa_s, &capa))
+ return; /* Unknown what driver supports */
+
+ if (wpa_supplicant_get_scan_results(wpa_s) || wpa_s->scan_res == NULL)
+ return; /* Could not get scan results for checking advertised
+ * parameters */
+
+ for (i = 0; i < wpa_s->scan_res->num; i++) {
+ bss = wpa_s->scan_res->res[i];
+ if (os_memcmp(bss->bssid, cred->mac_addr, ETH_ALEN) != 0)
+ continue;
+ ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
+ if (ie == NULL)
+ continue;
+ if (ie[1] != ssid->ssid_len || ssid->ssid == NULL ||
+ os_memcmp(ie + 2, ssid->ssid, ssid->ssid_len) != 0)
+ continue;
+
+ wpa_printf(MSG_DEBUG, "WPS: AP found from scan results");
+ break;
+ }
+
+ if (i == wpa_s->scan_res->num) {
+ wpa_printf(MSG_DEBUG, "WPS: The AP was not found from scan "
+ "results - use credential as-is");
+ return;
+ }
+
+ ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
+ if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0) {
+ wpa2 = 1;
+ if (adv.pairwise_cipher & WPA_CIPHER_CCMP)
+ ccmp = 1;
+ } else {
+ ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
+ if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0 &&
+ adv.pairwise_cipher & WPA_CIPHER_CCMP)
+ ccmp = 1;
+ }
+
+ if (ie == NULL && (ssid->proto & WPA_PROTO_WPA) &&
+ (ssid->pairwise_cipher & WPA_CIPHER_TKIP)) {
+ /*
+ * TODO: This could be the initial AP configuration and the
+ * Beacon contents could change shortly. Should request a new
+ * scan and delay addition of the network until the updated
+ * scan results are available.
+ */
+ wpa_printf(MSG_DEBUG, "WPS: The AP did not yet advertise WPA "
+ "support - use credential as-is");
+ return;
+ }
+
+ if (ccmp && !(ssid->pairwise_cipher & WPA_CIPHER_CCMP) &&
+ (ssid->pairwise_cipher & WPA_CIPHER_TKIP) &&
+ (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
+ wpa_printf(MSG_DEBUG, "WPS: Add CCMP into the credential "
+ "based on scan results");
+ if (wpa_s->conf->ap_scan == 1)
+ ssid->pairwise_cipher |= WPA_CIPHER_CCMP;
+ else
+ ssid->pairwise_cipher = WPA_CIPHER_CCMP;
+ }
+
+ if (wpa2 && !(ssid->proto & WPA_PROTO_RSN) &&
+ (ssid->proto & WPA_PROTO_WPA) &&
+ (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP)) {
+ wpa_printf(MSG_DEBUG, "WPS: Add WPA2 into the credential "
+ "based on scan results");
+ if (wpa_s->conf->ap_scan == 1)
+ ssid->proto |= WPA_PROTO_RSN;
+ else
+ ssid->proto = WPA_PROTO_RSN;
+ }
+}
+
+
static int wpa_supplicant_wps_cred(void *ctx,
const struct wps_credential *cred)
{
struct wpa_supplicant *wpa_s = ctx;
struct wpa_ssid *ssid = wpa_s->current_ssid;
+ u8 key_idx = 0;
+ u16 auth_type;
if ((wpa_s->conf->wps_cred_processing == 1 ||
wpa_s->conf->wps_cred_processing == 2) && cred->cred_attr) {
WPS_EVENT_CRED_RECEIVED, buf);
os_free(buf);
}
- wpa_supplicant_dbus_notify_wps_cred(wpa_s, cred);
+
+ wpas_notify_wps_credential(wpa_s, cred);
} else
wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_CRED_RECEIVED);
if (wpa_s->conf->wps_cred_processing == 1)
return 0;
- if (cred->auth_type != WPS_AUTH_OPEN &&
- cred->auth_type != WPS_AUTH_SHARED &&
- cred->auth_type != WPS_AUTH_WPAPSK &&
- cred->auth_type != WPS_AUTH_WPA2PSK) {
+ wpa_hexdump_ascii(MSG_DEBUG, "WPS: SSID", cred->ssid, cred->ssid_len);
+ wpa_printf(MSG_DEBUG, "WPS: Authentication Type 0x%x",
+ cred->auth_type);
+ wpa_printf(MSG_DEBUG, "WPS: Encryption Type 0x%x", cred->encr_type);
+ wpa_printf(MSG_DEBUG, "WPS: Network Key Index %d", cred->key_idx);
+ wpa_hexdump_key(MSG_DEBUG, "WPS: Network Key",
+ cred->key, cred->key_len);
+ wpa_printf(MSG_DEBUG, "WPS: MAC Address " MACSTR,
+ MAC2STR(cred->mac_addr));
+
+ auth_type = cred->auth_type;
+ if (auth_type == (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) {
+ wpa_printf(MSG_DEBUG, "WPS: Workaround - convert mixed-mode "
+ "auth_type into WPA2PSK");
+ auth_type = WPS_AUTH_WPA2PSK;
+ }
+
+ if (auth_type != WPS_AUTH_OPEN &&
+ auth_type != WPS_AUTH_SHARED &&
+ auth_type != WPS_AUTH_WPAPSK &&
+ auth_type != WPS_AUTH_WPA2PSK) {
wpa_printf(MSG_DEBUG, "WPS: Ignored credentials for "
- "unsupported authentication type %d",
- cred->auth_type);
+ "unsupported authentication type 0x%x",
+ auth_type);
return 0;
}
ssid = wpa_config_add_network(wpa_s->conf);
if (ssid == NULL)
return -1;
+ wpas_notify_network_added(wpa_s, ssid);
}
wpa_config_set_network_defaults(ssid);
case WPS_ENCR_NONE:
break;
case WPS_ENCR_WEP:
- if (cred->key_len > 0 && cred->key_len <= MAX_WEP_KEY_LEN &&
- cred->key_idx < NUM_WEP_KEYS) {
- os_memcpy(ssid->wep_key[cred->key_idx], cred->key,
+ if (cred->key_len <= 0)
+ break;
+ if (cred->key_len != 5 && cred->key_len != 13 &&
+ cred->key_len != 10 && cred->key_len != 26) {
+ wpa_printf(MSG_ERROR, "WPS: Invalid WEP Key length "
+ "%lu", (unsigned long) cred->key_len);
+ return -1;
+ }
+ if (cred->key_idx > NUM_WEP_KEYS) {
+ wpa_printf(MSG_ERROR, "WPS: Invalid WEP Key index %d",
+ cred->key_idx);
+ return -1;
+ }
+ if (cred->key_idx)
+ key_idx = cred->key_idx - 1;
+ if (cred->key_len == 10 || cred->key_len == 26) {
+ if (hexstr2bin((char *) cred->key,
+ ssid->wep_key[key_idx],
+ cred->key_len / 2) < 0) {
+ wpa_printf(MSG_ERROR, "WPS: Invalid WEP Key "
+ "%d", key_idx);
+ return -1;
+ }
+ ssid->wep_key_len[key_idx] = cred->key_len / 2;
+ } else {
+ os_memcpy(ssid->wep_key[key_idx], cred->key,
cred->key_len);
- ssid->wep_key_len[cred->key_idx] = cred->key_len;
- ssid->wep_tx_keyidx = cred->key_idx;
+ ssid->wep_key_len[key_idx] = cred->key_len;
}
+ ssid->wep_tx_keyidx = key_idx;
break;
case WPS_ENCR_TKIP:
ssid->pairwise_cipher = WPA_CIPHER_TKIP;
break;
}
- switch (cred->auth_type) {
+ switch (auth_type) {
case WPS_AUTH_OPEN:
ssid->auth_alg = WPA_AUTH_ALG_OPEN;
ssid->key_mgmt = WPA_KEY_MGMT_NONE;
}
}
+ wpas_wps_security_workaround(wpa_s, ssid, cred);
+
#ifndef CONFIG_NO_CONFIG_WRITE
if (wpa_s->conf->update_config &&
wpa_config_write(wpa_s->confname, wpa_s->conf)) {
wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_M2D
"dev_password_id=%d config_error=%d",
m2d->dev_password_id, m2d->config_error);
+ wpas_notify_wps_event_m2d(wpa_s, m2d);
}
{
wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_FAIL "msg=%d", fail->msg);
wpas_clear_wps(wpa_s);
+ wpas_notify_wps_event_fail(wpa_s, fail);
}
{
wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_SUCCESS);
wpa_s->wps_success = 1;
+ wpas_notify_wps_event_success(wpa_s);
}
case WPS_EV_SUCCESS:
wpa_supplicant_wps_event_success(wpa_s);
break;
+ case WPS_EV_PWD_AUTH_FAIL:
+ break;
+ case WPS_EV_PBC_OVERLAP:
+ break;
+ case WPS_EV_PBC_TIMEOUT:
+ break;
}
}
static void wpas_clear_wps(struct wpa_supplicant *wpa_s)
{
int id;
- struct wpa_ssid *ssid;
+ struct wpa_ssid *ssid, *remove_ssid = NULL;
eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
ssid = wpa_s->conf->ssid;
while (ssid) {
if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
- if (ssid == wpa_s->current_ssid)
+ if (ssid == wpa_s->current_ssid) {
wpa_s->current_ssid = NULL;
+ if (ssid != NULL)
+ wpas_notify_network_changed(wpa_s);
+ }
id = ssid->id;
+ remove_ssid = ssid;
} else
id = -1;
ssid = ssid->next;
- if (id >= 0)
+ if (id >= 0) {
+ wpas_notify_network_removed(wpa_s, remove_ssid);
wpa_config_remove_network(wpa_s->conf, id);
+ }
}
}
ssid = wpa_config_add_network(wpa_s->conf);
if (ssid == NULL)
return NULL;
+ wpas_notify_network_added(wpa_s, ssid);
wpa_config_set_network_defaults(ssid);
if (wpa_config_set(ssid, "key_mgmt", "WPS", 0) < 0 ||
wpa_config_set(ssid, "eap", "WSC", 0) < 0 ||
wpa_config_set(ssid, "identity", registrar ?
"\"" WSC_ID_REGISTRAR "\"" :
"\"" WSC_ID_ENROLLEE "\"", 0) < 0) {
+ wpas_notify_network_removed(wpa_s, ssid);
wpa_config_remove_network(wpa_s->conf, ssid->id);
return NULL;
}
/* Mark all other networks disabled and trigger reassociation */
ssid = wpa_s->conf->ssid;
while (ssid) {
+ int was_disabled = ssid->disabled;
ssid->disabled = ssid != selected;
+ if (was_disabled != ssid->disabled)
+ wpas_notify_network_enabled_changed(wpa_s, ssid);
ssid = ssid->next;
}
wpa_s->disconnected = 0;
const char *pin)
{
struct wpa_ssid *ssid;
- char val[30];
+ char val[128];
unsigned int rpin = 0;
wpas_clear_wps(wpa_s);
}
+#ifdef CONFIG_WPS_OOB
+int wpas_wps_start_oob(struct wpa_supplicant *wpa_s, char *device_type,
+ char *path, char *method, char *name)
+{
+ struct wps_context *wps = wpa_s->wps;
+ struct oob_device_data *oob_dev;
+
+ oob_dev = wps_get_oob_device(device_type);
+ if (oob_dev == NULL)
+ return -1;
+ oob_dev->device_path = path;
+ oob_dev->device_name = name;
+ wps->oob_conf.oob_method = wps_get_oob_method(method);
+
+ if (wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E) {
+ /*
+ * Use pre-configured DH keys in order to be able to write the
+ * key hash into the OOB file.
+ */
+ wpabuf_free(wps->dh_pubkey);
+ wpabuf_free(wps->dh_privkey);
+ wps->dh_privkey = NULL;
+ wps->dh_pubkey = NULL;
+ dh5_free(wps->dh_ctx);
+ wps->dh_ctx = dh5_init(&wps->dh_privkey, &wps->dh_pubkey);
+ wps->dh_pubkey = wpabuf_zeropad(wps->dh_pubkey, 192);
+ if (wps->dh_ctx == NULL || wps->dh_pubkey == NULL) {
+ wpa_printf(MSG_ERROR, "WPS: Failed to initialize "
+ "Diffie-Hellman handshake");
+ return -1;
+ }
+ }
+
+ if (wps->oob_conf.oob_method == OOB_METHOD_CRED)
+ wpas_clear_wps(wpa_s);
+
+ if (wps_process_oob(wps, oob_dev, 0) < 0)
+ return -1;
+
+ if ((wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E ||
+ wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_R) &&
+ wpas_wps_start_pin(wpa_s, NULL,
+ wpabuf_head(wps->oob_conf.dev_password)) < 0)
+ return -1;
+
+ return 0;
+}
+#endif /* CONFIG_WPS_OOB */
+
+
int wpas_wps_start_reg(struct wpa_supplicant *wpa_s, const u8 *bssid,
- const char *pin)
+ const char *pin, struct wps_new_ap_settings *settings)
{
struct wpa_ssid *ssid;
- char val[30];
+ char val[200];
+ char *pos, *end;
+ int res;
if (!pin)
return -1;
ssid = wpas_wps_add_network(wpa_s, 1, bssid);
if (ssid == NULL)
return -1;
- os_snprintf(val, sizeof(val), "\"pin=%s\"", pin);
+ pos = val;
+ end = pos + sizeof(val);
+ res = os_snprintf(pos, end - pos, "\"pin=%s", pin);
+ if (res < 0 || res >= end - pos)
+ return -1;
+ pos += res;
+ if (settings) {
+ res = os_snprintf(pos, end - pos, " new_ssid=%s new_auth=%s "
+ "new_encr=%s new_key=%s",
+ settings->ssid_hex, settings->auth,
+ settings->encr, settings->key_hex);
+ if (res < 0 || res >= end - pos)
+ return -1;
+ pos += res;
+ }
+ res = os_snprintf(pos, end - pos, "\"");
+ if (res < 0 || res >= end - pos)
+ return -1;
wpa_config_set(ssid, "phase1", val, 0);
eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
wpa_s, NULL);
}
+static void wpas_wps_set_sel_reg_cb(void *ctx, int sel_reg, u16 dev_passwd_id,
+ u16 sel_reg_config_methods)
+{
+#ifdef CONFIG_WPS_ER
+ struct wpa_supplicant *wpa_s = ctx;
+
+ if (wpa_s->wps_er == NULL)
+ return;
+ wps_er_set_sel_reg(wpa_s->wps_er, sel_reg, dev_passwd_id,
+ sel_reg_config_methods);
+#endif /* CONFIG_WPS_ER */
+}
+
+
int wpas_wps_init(struct wpa_supplicant *wpa_s)
{
struct wps_context *wps;
os_memset(&rcfg, 0, sizeof(rcfg));
rcfg.new_psk_cb = wpas_wps_new_psk_cb;
rcfg.pin_needed_cb = wpas_wps_pin_needed_cb;
+ rcfg.set_sel_reg_cb = wpas_wps_set_sel_reg_cb;
rcfg.cb_ctx = wpa_s;
wps->registrar = wps_registrar_init(wps, &rcfg);
return;
wps_registrar_deinit(wpa_s->wps->registrar);
+ wpabuf_free(wpa_s->wps->dh_pubkey);
+ wpabuf_free(wpa_s->wps->dh_privkey);
+ wpabuf_free(wpa_s->wps->oob_conf.pubkey_hash);
+ wpabuf_free(wpa_s->wps->oob_conf.dev_password);
os_free(wpa_s->wps->network_key);
os_free(wpa_s->wps);
wpa_s->wps = NULL;
+
+#ifdef CONFIG_WPS_ER
+ wps_er_deinit(wpa_s->wps_er);
+ wpa_s->wps_er = NULL;
+#endif /* CONFIG_WPS_ER */
}
return 0;
}
+
+
+int wpas_wps_scan_result_text(const u8 *ies, size_t ies_len, char *buf,
+ char *end)
+{
+ struct wpabuf *wps_ie;
+ int ret;
+
+ wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len, WPS_DEV_OUI_WFA);
+ if (wps_ie == NULL)
+ return 0;
+
+ ret = wps_attr_text(wps_ie, buf, end);
+ wpabuf_free(wps_ie);
+ return ret;
+}
+
+
+int wpas_wps_er_start(struct wpa_supplicant *wpa_s)
+{
+#ifdef CONFIG_WPS_ER
+ if (wpa_s->wps_er) {
+ /* TODO: re-send ctrl_iface events for current data? */
+ return 0;
+ }
+ wpa_s->wps_er = wps_er_init(wpa_s->wps, wpa_s->ifname);
+ if (wpa_s->wps_er == NULL)
+ return -1;
+ return 0;
+#else /* CONFIG_WPS_ER */
+ return 0;
+#endif /* CONFIG_WPS_ER */
+}
+
+
+int wpas_wps_er_stop(struct wpa_supplicant *wpa_s)
+{
+#ifdef CONFIG_WPS_ER
+ wps_er_deinit(wpa_s->wps_er);
+ wpa_s->wps_er = NULL;
+#endif /* CONFIG_WPS_ER */
+ return 0;
+}
+
+
+#ifdef CONFIG_WPS_ER
+int wpas_wps_er_add_pin(struct wpa_supplicant *wpa_s, const char *uuid,
+ const char *pin)
+{
+ u8 u[UUID_LEN];
+ int any = 0;
+
+ if (os_strcmp(uuid, "any") == 0)
+ any = 1;
+ else if (uuid_str2bin(uuid, u))
+ return -1;
+ return wps_registrar_add_pin(wpa_s->wps->registrar, any ? NULL : u,
+ (const u8 *) pin, os_strlen(pin), 300);
+}
+#endif /* CONFIG_WPS_ER */