2 * wpa_supplicant / WPS integration
3 * Copyright (c) 2008-2010, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
20 #include "crypto/dh_group5.h"
21 #include "common/ieee802_11_defs.h"
22 #include "common/ieee802_11_common.h"
23 #include "common/wpa_common.h"
24 #include "common/wpa_ctrl.h"
25 #include "eap_common/eap_wsc_common.h"
26 #include "eap_peer/eap.h"
27 #include "rsn_supp/wpa.h"
29 #include "wpa_supplicant_i.h"
32 #include "blacklist.h"
37 #include "p2p_supplicant.h"
38 #include "wps_supplicant.h"
41 #ifndef WPS_PIN_SCAN_IGNORE_SEL_REG
42 #define WPS_PIN_SCAN_IGNORE_SEL_REG 3
43 #endif /* WPS_PIN_SCAN_IGNORE_SEL_REG */
45 static void wpas_wps_timeout(void *eloop_ctx, void *timeout_ctx);
46 static void wpas_clear_wps(struct wpa_supplicant *wpa_s);
49 int wpas_wps_eapol_cb(struct wpa_supplicant *wpa_s)
51 if (!wpa_s->wps_success &&
52 wpa_s->current_ssid &&
53 eap_is_wps_pin_enrollee(&wpa_s->current_ssid->eap)) {
54 const u8 *bssid = wpa_s->bssid;
55 if (is_zero_ether_addr(bssid))
56 bssid = wpa_s->pending_bssid;
58 wpa_printf(MSG_DEBUG, "WPS: PIN registration with " MACSTR
59 " did not succeed - continue trying to find "
60 "suitable AP", MAC2STR(bssid));
61 wpa_blacklist_add(wpa_s, bssid);
63 wpa_supplicant_deauthenticate(wpa_s,
64 WLAN_REASON_DEAUTH_LEAVING);
65 wpa_s->reassociate = 1;
66 wpa_supplicant_req_scan(wpa_s,
67 wpa_s->blacklist_cleared ? 5 : 0, 0);
68 wpa_s->blacklist_cleared = 0;
72 eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
74 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && wpa_s->current_ssid &&
75 !(wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
76 wpa_printf(MSG_DEBUG, "WPS: Network configuration replaced - "
77 "try to associate with the received credential");
78 wpa_supplicant_deauthenticate(wpa_s,
79 WLAN_REASON_DEAUTH_LEAVING);
81 wpa_s->wps_freq = wpa_s->assoc_freq;
82 wpa_s->reassociate = 1;
83 wpa_supplicant_req_scan(wpa_s, 0, 0);
87 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && wpa_s->current_ssid) {
88 wpa_printf(MSG_DEBUG, "WPS: Registration completed - waiting "
89 "for external credential processing");
90 wpas_clear_wps(wpa_s);
91 wpa_supplicant_deauthenticate(wpa_s,
92 WLAN_REASON_DEAUTH_LEAVING);
100 static void wpas_wps_security_workaround(struct wpa_supplicant *wpa_s,
101 struct wpa_ssid *ssid,
102 const struct wps_credential *cred)
104 struct wpa_driver_capa capa;
107 struct wpa_ie_data adv;
108 int wpa2 = 0, ccmp = 0;
111 * Many existing WPS APs do not know how to negotiate WPA2 or CCMP in
112 * case they are configured for mixed mode operation (WPA+WPA2 and
113 * TKIP+CCMP). Try to use scan results to figure out whether the AP
114 * actually supports stronger security and select that if the client
115 * has support for it, too.
118 if (wpa_drv_get_capa(wpa_s, &capa))
119 return; /* Unknown what driver supports */
121 bss = wpa_bss_get(wpa_s, cred->mac_addr, ssid->ssid, ssid->ssid_len);
123 wpa_printf(MSG_DEBUG, "WPS: The AP was not found from BSS "
124 "table - use credential as-is");
128 wpa_printf(MSG_DEBUG, "WPS: AP found from BSS table");
130 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
131 if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0) {
133 if (adv.pairwise_cipher & WPA_CIPHER_CCMP)
136 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
137 if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0 &&
138 adv.pairwise_cipher & WPA_CIPHER_CCMP)
142 if (ie == NULL && (ssid->proto & WPA_PROTO_WPA) &&
143 (ssid->pairwise_cipher & WPA_CIPHER_TKIP)) {
145 * TODO: This could be the initial AP configuration and the
146 * Beacon contents could change shortly. Should request a new
147 * scan and delay addition of the network until the updated
148 * scan results are available.
150 wpa_printf(MSG_DEBUG, "WPS: The AP did not yet advertise WPA "
151 "support - use credential as-is");
155 if (ccmp && !(ssid->pairwise_cipher & WPA_CIPHER_CCMP) &&
156 (ssid->pairwise_cipher & WPA_CIPHER_TKIP) &&
157 (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
158 wpa_printf(MSG_DEBUG, "WPS: Add CCMP into the credential "
159 "based on scan results");
160 if (wpa_s->conf->ap_scan == 1)
161 ssid->pairwise_cipher |= WPA_CIPHER_CCMP;
163 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
166 if (wpa2 && !(ssid->proto & WPA_PROTO_RSN) &&
167 (ssid->proto & WPA_PROTO_WPA) &&
168 (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP)) {
169 wpa_printf(MSG_DEBUG, "WPS: Add WPA2 into the credential "
170 "based on scan results");
171 if (wpa_s->conf->ap_scan == 1)
172 ssid->proto |= WPA_PROTO_RSN;
174 ssid->proto = WPA_PROTO_RSN;
179 static int wpa_supplicant_wps_cred(void *ctx,
180 const struct wps_credential *cred)
182 struct wpa_supplicant *wpa_s = ctx;
183 struct wpa_ssid *ssid = wpa_s->current_ssid;
187 if ((wpa_s->conf->wps_cred_processing == 1 ||
188 wpa_s->conf->wps_cred_processing == 2) && cred->cred_attr) {
189 size_t blen = cred->cred_attr_len * 2 + 1;
190 char *buf = os_malloc(blen);
192 wpa_snprintf_hex(buf, blen,
193 cred->cred_attr, cred->cred_attr_len);
194 wpa_msg(wpa_s, MSG_INFO, "%s%s",
195 WPS_EVENT_CRED_RECEIVED, buf);
199 wpas_notify_wps_credential(wpa_s, cred);
201 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_CRED_RECEIVED);
203 wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
204 cred->cred_attr, cred->cred_attr_len);
206 if (wpa_s->conf->wps_cred_processing == 1)
209 wpa_hexdump_ascii(MSG_DEBUG, "WPS: SSID", cred->ssid, cred->ssid_len);
210 wpa_printf(MSG_DEBUG, "WPS: Authentication Type 0x%x",
212 wpa_printf(MSG_DEBUG, "WPS: Encryption Type 0x%x", cred->encr_type);
213 wpa_printf(MSG_DEBUG, "WPS: Network Key Index %d", cred->key_idx);
214 wpa_hexdump_key(MSG_DEBUG, "WPS: Network Key",
215 cred->key, cred->key_len);
216 wpa_printf(MSG_DEBUG, "WPS: MAC Address " MACSTR,
217 MAC2STR(cred->mac_addr));
219 auth_type = cred->auth_type;
220 if (auth_type == (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) {
221 wpa_printf(MSG_DEBUG, "WPS: Workaround - convert mixed-mode "
222 "auth_type into WPA2PSK");
223 auth_type = WPS_AUTH_WPA2PSK;
226 if (auth_type != WPS_AUTH_OPEN &&
227 auth_type != WPS_AUTH_SHARED &&
228 auth_type != WPS_AUTH_WPAPSK &&
229 auth_type != WPS_AUTH_WPA2PSK) {
230 wpa_printf(MSG_DEBUG, "WPS: Ignored credentials for "
231 "unsupported authentication type 0x%x",
236 if (ssid && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
237 wpa_printf(MSG_DEBUG, "WPS: Replace WPS network block based "
238 "on the received credential");
239 os_free(ssid->eap.identity);
240 ssid->eap.identity = NULL;
241 ssid->eap.identity_len = 0;
242 os_free(ssid->eap.phase1);
243 ssid->eap.phase1 = NULL;
244 os_free(ssid->eap.eap_methods);
245 ssid->eap.eap_methods = NULL;
246 if (!ssid->p2p_group)
249 wpa_printf(MSG_DEBUG, "WPS: Create a new network based on the "
250 "received credential");
251 ssid = wpa_config_add_network(wpa_s->conf);
254 wpas_notify_network_added(wpa_s, ssid);
257 wpa_config_set_network_defaults(ssid);
260 ssid->ssid = os_malloc(cred->ssid_len);
262 os_memcpy(ssid->ssid, cred->ssid, cred->ssid_len);
263 ssid->ssid_len = cred->ssid_len;
266 switch (cred->encr_type) {
270 if (cred->key_len <= 0)
272 if (cred->key_len != 5 && cred->key_len != 13 &&
273 cred->key_len != 10 && cred->key_len != 26) {
274 wpa_printf(MSG_ERROR, "WPS: Invalid WEP Key length "
275 "%lu", (unsigned long) cred->key_len);
278 if (cred->key_idx > NUM_WEP_KEYS) {
279 wpa_printf(MSG_ERROR, "WPS: Invalid WEP Key index %d",
284 key_idx = cred->key_idx - 1;
285 if (cred->key_len == 10 || cred->key_len == 26) {
286 if (hexstr2bin((char *) cred->key,
287 ssid->wep_key[key_idx],
288 cred->key_len / 2) < 0) {
289 wpa_printf(MSG_ERROR, "WPS: Invalid WEP Key "
293 ssid->wep_key_len[key_idx] = cred->key_len / 2;
295 os_memcpy(ssid->wep_key[key_idx], cred->key,
297 ssid->wep_key_len[key_idx] = cred->key_len;
299 ssid->wep_tx_keyidx = key_idx;
302 ssid->pairwise_cipher = WPA_CIPHER_TKIP;
305 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
311 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
312 ssid->key_mgmt = WPA_KEY_MGMT_NONE;
315 case WPS_AUTH_SHARED:
316 ssid->auth_alg = WPA_AUTH_ALG_SHARED;
317 ssid->key_mgmt = WPA_KEY_MGMT_NONE;
320 case WPS_AUTH_WPAPSK:
321 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
322 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
323 ssid->proto = WPA_PROTO_WPA;
326 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
327 ssid->key_mgmt = WPA_KEY_MGMT_IEEE8021X;
328 ssid->proto = WPA_PROTO_WPA;
331 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
332 ssid->key_mgmt = WPA_KEY_MGMT_IEEE8021X;
333 ssid->proto = WPA_PROTO_RSN;
335 case WPS_AUTH_WPA2PSK:
336 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
337 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
338 ssid->proto = WPA_PROTO_RSN;
342 if (ssid->key_mgmt == WPA_KEY_MGMT_PSK) {
343 if (cred->key_len == 2 * PMK_LEN) {
344 if (hexstr2bin((const char *) cred->key, ssid->psk,
346 wpa_printf(MSG_ERROR, "WPS: Invalid Network "
351 } else if (cred->key_len >= 8 && cred->key_len < 2 * PMK_LEN) {
352 os_free(ssid->passphrase);
353 ssid->passphrase = os_malloc(cred->key_len + 1);
354 if (ssid->passphrase == NULL)
356 os_memcpy(ssid->passphrase, cred->key, cred->key_len);
357 ssid->passphrase[cred->key_len] = '\0';
358 wpa_config_update_psk(ssid);
360 wpa_printf(MSG_ERROR, "WPS: Invalid Network Key "
362 (unsigned long) cred->key_len);
367 wpas_wps_security_workaround(wpa_s, ssid, cred);
369 #ifndef CONFIG_NO_CONFIG_WRITE
370 if (wpa_s->conf->update_config &&
371 wpa_config_write(wpa_s->confname, wpa_s->conf)) {
372 wpa_printf(MSG_DEBUG, "WPS: Failed to update configuration");
375 #endif /* CONFIG_NO_CONFIG_WRITE */
381 static void wpa_supplicant_wps_event_m2d(struct wpa_supplicant *wpa_s,
382 struct wps_event_m2d *m2d)
384 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_M2D
385 "dev_password_id=%d config_error=%d",
386 m2d->dev_password_id, m2d->config_error);
387 wpas_notify_wps_event_m2d(wpa_s, m2d);
391 static void wpa_supplicant_wps_event_fail(struct wpa_supplicant *wpa_s,
392 struct wps_event_fail *fail)
394 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_FAIL "msg=%d config_error=%d",
395 fail->msg, fail->config_error);
396 if (wpa_s->parent && wpa_s->parent != wpa_s)
397 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
398 "msg=%d config_error=%d",
399 fail->msg, fail->config_error);
400 wpas_clear_wps(wpa_s);
401 wpas_notify_wps_event_fail(wpa_s, fail);
405 static void wpa_supplicant_wps_event_success(struct wpa_supplicant *wpa_s)
407 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_SUCCESS);
408 wpa_s->wps_success = 1;
409 wpas_notify_wps_event_success(wpa_s);
411 wpas_p2p_wps_success(wpa_s, wpa_s->bssid, 0);
412 #endif /* CONFIG_P2P */
416 static void wpa_supplicant_wps_event_er_ap_add(struct wpa_supplicant *wpa_s,
417 struct wps_event_er_ap *ap)
420 char dev_type[WPS_DEV_TYPE_BUFSIZE];
422 uuid_bin2str(ap->uuid, uuid_str, sizeof(uuid_str));
423 if (ap->pri_dev_type)
424 wps_dev_type_bin2str(ap->pri_dev_type, dev_type,
429 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_ADD "%s " MACSTR
430 " pri_dev_type=%s wps_state=%d |%s|%s|%s|%s|%s|%s|",
431 uuid_str, MAC2STR(ap->mac_addr), dev_type, ap->wps_state,
432 ap->friendly_name ? ap->friendly_name : "",
433 ap->manufacturer ? ap->manufacturer : "",
434 ap->model_description ? ap->model_description : "",
435 ap->model_name ? ap->model_name : "",
436 ap->manufacturer_url ? ap->manufacturer_url : "",
437 ap->model_url ? ap->model_url : "");
441 static void wpa_supplicant_wps_event_er_ap_remove(struct wpa_supplicant *wpa_s,
442 struct wps_event_er_ap *ap)
445 uuid_bin2str(ap->uuid, uuid_str, sizeof(uuid_str));
446 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_REMOVE "%s", uuid_str);
450 static void wpa_supplicant_wps_event_er_enrollee_add(
451 struct wpa_supplicant *wpa_s, struct wps_event_er_enrollee *enrollee)
454 char dev_type[WPS_DEV_TYPE_BUFSIZE];
456 uuid_bin2str(enrollee->uuid, uuid_str, sizeof(uuid_str));
457 if (enrollee->pri_dev_type)
458 wps_dev_type_bin2str(enrollee->pri_dev_type, dev_type,
463 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_ENROLLEE_ADD "%s " MACSTR
464 " M1=%d config_methods=0x%x dev_passwd_id=%d pri_dev_type=%s "
466 uuid_str, MAC2STR(enrollee->mac_addr), enrollee->m1_received,
467 enrollee->config_methods, enrollee->dev_passwd_id, dev_type,
468 enrollee->dev_name ? enrollee->dev_name : "",
469 enrollee->manufacturer ? enrollee->manufacturer : "",
470 enrollee->model_name ? enrollee->model_name : "",
471 enrollee->model_number ? enrollee->model_number : "",
472 enrollee->serial_number ? enrollee->serial_number : "");
476 static void wpa_supplicant_wps_event_er_enrollee_remove(
477 struct wpa_supplicant *wpa_s, struct wps_event_er_enrollee *enrollee)
480 uuid_bin2str(enrollee->uuid, uuid_str, sizeof(uuid_str));
481 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_ENROLLEE_REMOVE "%s " MACSTR,
482 uuid_str, MAC2STR(enrollee->mac_addr));
486 static void wpa_supplicant_wps_event_er_ap_settings(
487 struct wpa_supplicant *wpa_s,
488 struct wps_event_er_ap_settings *ap_settings)
492 const struct wps_credential *cred = ap_settings->cred;
495 if (cred->auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) {
496 if (cred->key_len >= 8 && cred->key_len <= 64) {
497 os_memcpy(key_str, cred->key, cred->key_len);
498 key_str[cred->key_len] = '\0';
502 uuid_bin2str(ap_settings->uuid, uuid_str, sizeof(uuid_str));
503 /* Use wpa_msg_ctrl to avoid showing the key in debug log */
504 wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_SETTINGS
505 "uuid=%s ssid=%s auth_type=0x%04x encr_type=0x%04x "
507 uuid_str, wpa_ssid_txt(cred->ssid, cred->ssid_len),
508 cred->auth_type, cred->encr_type, key_str);
512 static void wpa_supplicant_wps_event(void *ctx, enum wps_event event,
513 union wps_event_data *data)
515 struct wpa_supplicant *wpa_s = ctx;
518 wpa_supplicant_wps_event_m2d(wpa_s, &data->m2d);
521 wpa_supplicant_wps_event_fail(wpa_s, &data->fail);
524 wpa_supplicant_wps_event_success(wpa_s);
526 case WPS_EV_PWD_AUTH_FAIL:
528 case WPS_EV_PBC_OVERLAP:
530 case WPS_EV_PBC_TIMEOUT:
532 case WPS_EV_ER_AP_ADD:
533 wpa_supplicant_wps_event_er_ap_add(wpa_s, &data->ap);
535 case WPS_EV_ER_AP_REMOVE:
536 wpa_supplicant_wps_event_er_ap_remove(wpa_s, &data->ap);
538 case WPS_EV_ER_ENROLLEE_ADD:
539 wpa_supplicant_wps_event_er_enrollee_add(wpa_s,
542 case WPS_EV_ER_ENROLLEE_REMOVE:
543 wpa_supplicant_wps_event_er_enrollee_remove(wpa_s,
546 case WPS_EV_ER_AP_SETTINGS:
547 wpa_supplicant_wps_event_er_ap_settings(wpa_s,
554 enum wps_request_type wpas_wps_get_req_type(struct wpa_ssid *ssid)
556 if (eap_is_wps_pbc_enrollee(&ssid->eap) ||
557 eap_is_wps_pin_enrollee(&ssid->eap))
558 return WPS_REQ_ENROLLEE;
560 return WPS_REQ_REGISTRAR;
564 static void wpas_clear_wps(struct wpa_supplicant *wpa_s)
567 struct wpa_ssid *ssid, *remove_ssid = NULL;
569 eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
571 /* Remove any existing WPS network from configuration */
572 ssid = wpa_s->conf->ssid;
574 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
575 if (ssid == wpa_s->current_ssid) {
576 wpa_s->current_ssid = NULL;
578 wpas_notify_network_changed(wpa_s);
586 wpas_notify_network_removed(wpa_s, remove_ssid);
587 wpa_config_remove_network(wpa_s->conf, id);
593 static void wpas_wps_timeout(void *eloop_ctx, void *timeout_ctx)
595 struct wpa_supplicant *wpa_s = eloop_ctx;
596 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_TIMEOUT "Requested operation timed "
598 wpas_clear_wps(wpa_s);
602 static struct wpa_ssid * wpas_wps_add_network(struct wpa_supplicant *wpa_s,
603 int registrar, const u8 *bssid)
605 struct wpa_ssid *ssid;
607 ssid = wpa_config_add_network(wpa_s->conf);
610 wpas_notify_network_added(wpa_s, ssid);
611 wpa_config_set_network_defaults(ssid);
613 if (wpa_config_set(ssid, "key_mgmt", "WPS", 0) < 0 ||
614 wpa_config_set(ssid, "eap", "WSC", 0) < 0 ||
615 wpa_config_set(ssid, "identity", registrar ?
616 "\"" WSC_ID_REGISTRAR "\"" :
617 "\"" WSC_ID_ENROLLEE "\"", 0) < 0) {
618 wpas_notify_network_removed(wpa_s, ssid);
619 wpa_config_remove_network(wpa_s->conf, ssid->id);
627 #endif /* CONFIG_P2P */
629 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
633 * Note: With P2P, the SSID may change at the time the WPS
634 * provisioning is started, so better not filter the AP based
635 * on the current SSID in the scan results.
638 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
639 if (os_memcmp(bssid, bss->bssid, ETH_ALEN) != 0)
643 ssid->ssid = os_malloc(bss->ssid_len);
644 if (ssid->ssid == NULL)
646 os_memcpy(ssid->ssid, bss->ssid, bss->ssid_len);
647 ssid->ssid_len = bss->ssid_len;
648 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Picked SSID from "
650 ssid->ssid, ssid->ssid_len);
655 wpa_printf(MSG_DEBUG, "WPS: More than one SSID found "
656 "for the AP; use wildcard");
661 #endif /* CONFIG_P2P */
668 static void wpas_wps_reassoc(struct wpa_supplicant *wpa_s,
669 struct wpa_ssid *selected)
671 struct wpa_ssid *ssid;
673 /* Mark all other networks disabled and trigger reassociation */
674 ssid = wpa_s->conf->ssid;
676 int was_disabled = ssid->disabled;
677 ssid->disabled = ssid != selected;
678 if (was_disabled != ssid->disabled)
679 wpas_notify_network_enabled_changed(wpa_s, ssid);
682 wpa_s->disconnected = 0;
683 wpa_s->reassociate = 1;
684 wpa_s->scan_runs = 0;
685 wpa_s->wps_success = 0;
686 wpa_s->blacklist_cleared = 0;
687 wpa_supplicant_req_scan(wpa_s, 0, 0);
691 int wpas_wps_start_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
694 struct wpa_ssid *ssid;
695 wpas_clear_wps(wpa_s);
696 ssid = wpas_wps_add_network(wpa_s, 0, bssid);
700 ssid->p2p_group = p2p_group;
702 if (p2p_group && wpa_s->go_params && wpa_s->go_params->ssid_len) {
703 ssid->ssid = os_zalloc(wpa_s->go_params->ssid_len + 1);
705 ssid->ssid_len = wpa_s->go_params->ssid_len;
706 os_memcpy(ssid->ssid, wpa_s->go_params->ssid,
708 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Use specific AP "
709 "SSID", ssid->ssid, ssid->ssid_len);
712 #endif /* CONFIG_P2P */
713 wpa_config_set(ssid, "phase1", "\"pbc=1\"", 0);
714 if (wpa_s->wps_fragment_size)
715 ssid->eap.fragment_size = wpa_s->wps_fragment_size;
716 eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
718 wpas_wps_reassoc(wpa_s, ssid);
723 int wpas_wps_start_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
724 const char *pin, int p2p_group, u16 dev_pw_id)
726 struct wpa_ssid *ssid;
728 unsigned int rpin = 0;
730 wpas_clear_wps(wpa_s);
731 ssid = wpas_wps_add_network(wpa_s, 0, bssid);
735 ssid->p2p_group = p2p_group;
737 if (p2p_group && wpa_s->go_params && wpa_s->go_params->ssid_len) {
738 ssid->ssid = os_zalloc(wpa_s->go_params->ssid_len + 1);
740 ssid->ssid_len = wpa_s->go_params->ssid_len;
741 os_memcpy(ssid->ssid, wpa_s->go_params->ssid,
743 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Use specific AP "
744 "SSID", ssid->ssid, ssid->ssid_len);
747 #endif /* CONFIG_P2P */
749 os_snprintf(val, sizeof(val), "\"pin=%s dev_pw_id=%u\"",
752 rpin = wps_generate_pin();
753 os_snprintf(val, sizeof(val), "\"pin=%08d dev_pw_id=%u\"",
756 wpa_config_set(ssid, "phase1", val, 0);
757 if (wpa_s->wps_fragment_size)
758 ssid->eap.fragment_size = wpa_s->wps_fragment_size;
759 eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
761 wpas_wps_reassoc(wpa_s, ssid);
766 /* Cancel the wps pbc/pin requests */
767 int wpas_wps_cancel(struct wpa_supplicant *wpa_s)
770 if (wpa_s->ap_iface) {
771 wpa_printf(MSG_DEBUG, "WPS: Cancelling in AP mode");
772 return wpa_supplicant_ap_wps_cancel(wpa_s);
774 #endif /* CONFIG_AP */
776 if (wpa_s->wpa_state == WPA_SCANNING) {
777 wpa_printf(MSG_DEBUG, "WPS: Cancel operation - cancel scan");
778 wpa_supplicant_cancel_scan(wpa_s);
779 wpas_clear_wps(wpa_s);
780 } else if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
781 wpa_printf(MSG_DEBUG, "WPS: Cancel operation - "
783 wpa_supplicant_deauthenticate(wpa_s,
784 WLAN_REASON_DEAUTH_LEAVING);
785 wpas_clear_wps(wpa_s);
792 #ifdef CONFIG_WPS_OOB
793 int wpas_wps_start_oob(struct wpa_supplicant *wpa_s, char *device_type,
794 char *path, char *method, char *name)
796 struct wps_context *wps = wpa_s->wps;
797 struct oob_device_data *oob_dev;
799 oob_dev = wps_get_oob_device(device_type);
802 oob_dev->device_path = path;
803 oob_dev->device_name = name;
804 wps->oob_conf.oob_method = wps_get_oob_method(method);
806 if (wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E) {
808 * Use pre-configured DH keys in order to be able to write the
809 * key hash into the OOB file.
811 wpabuf_free(wps->dh_pubkey);
812 wpabuf_free(wps->dh_privkey);
813 wps->dh_privkey = NULL;
814 wps->dh_pubkey = NULL;
815 dh5_free(wps->dh_ctx);
816 wps->dh_ctx = dh5_init(&wps->dh_privkey, &wps->dh_pubkey);
817 wps->dh_pubkey = wpabuf_zeropad(wps->dh_pubkey, 192);
818 if (wps->dh_ctx == NULL || wps->dh_pubkey == NULL) {
819 wpa_printf(MSG_ERROR, "WPS: Failed to initialize "
820 "Diffie-Hellman handshake");
825 if (wps->oob_conf.oob_method == OOB_METHOD_CRED)
826 wpas_clear_wps(wpa_s);
828 if (wps_process_oob(wps, oob_dev, 0) < 0)
831 if ((wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E ||
832 wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_R) &&
833 wpas_wps_start_pin(wpa_s, NULL,
834 wpabuf_head(wps->oob_conf.dev_password), 0,
840 #endif /* CONFIG_WPS_OOB */
843 int wpas_wps_start_reg(struct wpa_supplicant *wpa_s, const u8 *bssid,
844 const char *pin, struct wps_new_ap_settings *settings)
846 struct wpa_ssid *ssid;
853 wpas_clear_wps(wpa_s);
854 ssid = wpas_wps_add_network(wpa_s, 1, bssid);
859 end = pos + sizeof(val);
860 res = os_snprintf(pos, end - pos, "\"pin=%s", pin);
861 if (res < 0 || res >= end - pos)
865 res = os_snprintf(pos, end - pos, " new_ssid=%s new_auth=%s "
866 "new_encr=%s new_key=%s",
867 settings->ssid_hex, settings->auth,
868 settings->encr, settings->key_hex);
869 if (res < 0 || res >= end - pos)
873 res = os_snprintf(pos, end - pos, "\"");
874 if (res < 0 || res >= end - pos)
876 wpa_config_set(ssid, "phase1", val, 0);
877 if (wpa_s->wps_fragment_size)
878 ssid->eap.fragment_size = wpa_s->wps_fragment_size;
879 eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
881 wpas_wps_reassoc(wpa_s, ssid);
886 static int wpas_wps_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *psk,
889 wpa_printf(MSG_DEBUG, "WPS: Received new WPA/WPA2-PSK from WPS for "
890 "STA " MACSTR, MAC2STR(mac_addr));
891 wpa_hexdump_key(MSG_DEBUG, "Per-device PSK", psk, psk_len);
899 static void wpas_wps_pin_needed_cb(void *ctx, const u8 *uuid_e,
900 const struct wps_device_data *dev)
902 char uuid[40], txt[400];
904 char devtype[WPS_DEV_TYPE_BUFSIZE];
905 if (uuid_bin2str(uuid_e, uuid, sizeof(uuid)))
907 wpa_printf(MSG_DEBUG, "WPS: PIN needed for UUID-E %s", uuid);
908 len = os_snprintf(txt, sizeof(txt), "WPS-EVENT-PIN-NEEDED %s " MACSTR
909 " [%s|%s|%s|%s|%s|%s]",
910 uuid, MAC2STR(dev->mac_addr), dev->device_name,
911 dev->manufacturer, dev->model_name,
912 dev->model_number, dev->serial_number,
913 wps_dev_type_bin2str(dev->pri_dev_type, devtype,
915 if (len > 0 && len < (int) sizeof(txt))
916 wpa_printf(MSG_INFO, "%s", txt);
920 static void wpas_wps_set_sel_reg_cb(void *ctx, int sel_reg, u16 dev_passwd_id,
921 u16 sel_reg_config_methods)
924 struct wpa_supplicant *wpa_s = ctx;
926 if (wpa_s->wps_er == NULL)
928 wpa_printf(MSG_DEBUG, "WPS ER: SetSelectedRegistrar - sel_reg=%d "
929 "dev_password_id=%u sel_reg_config_methods=0x%x",
930 sel_reg, dev_passwd_id, sel_reg_config_methods);
931 wps_er_set_sel_reg(wpa_s->wps_er, sel_reg, dev_passwd_id,
932 sel_reg_config_methods);
933 #endif /* CONFIG_WPS_ER */
937 static u16 wps_fix_config_methods(u16 config_methods)
940 if ((config_methods &
941 (WPS_CONFIG_DISPLAY | WPS_CONFIG_VIRT_DISPLAY |
942 WPS_CONFIG_PHY_DISPLAY)) == WPS_CONFIG_DISPLAY) {
943 wpa_printf(MSG_INFO, "WPS: Converting display to "
944 "virtual_display for WPS 2.0 compliance");
945 config_methods |= WPS_CONFIG_VIRT_DISPLAY;
947 if ((config_methods &
948 (WPS_CONFIG_PUSHBUTTON | WPS_CONFIG_VIRT_PUSHBUTTON |
949 WPS_CONFIG_PHY_PUSHBUTTON)) == WPS_CONFIG_PUSHBUTTON) {
950 wpa_printf(MSG_INFO, "WPS: Converting push_button to "
951 "virtual_push_button for WPS 2.0 compliance");
952 config_methods |= WPS_CONFIG_VIRT_PUSHBUTTON;
954 #endif /* CONFIG_WPS2 */
956 return config_methods;
960 int wpas_wps_init(struct wpa_supplicant *wpa_s)
962 struct wps_context *wps;
963 struct wps_registrar_config rcfg;
965 wps = os_zalloc(sizeof(*wps));
969 wps->cred_cb = wpa_supplicant_wps_cred;
970 wps->event_cb = wpa_supplicant_wps_event;
973 wps->dev.device_name = wpa_s->conf->device_name;
974 wps->dev.manufacturer = wpa_s->conf->manufacturer;
975 wps->dev.model_name = wpa_s->conf->model_name;
976 wps->dev.model_number = wpa_s->conf->model_number;
977 wps->dev.serial_number = wpa_s->conf->serial_number;
978 wps->config_methods =
979 wps_config_methods_str2bin(wpa_s->conf->config_methods);
980 if ((wps->config_methods & (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) ==
981 (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) {
982 wpa_printf(MSG_ERROR, "WPS: Both Label and Display config "
983 "methods are not allowed at the same time");
987 wps->config_methods = wps_fix_config_methods(wps->config_methods);
988 if (wpa_s->conf->device_type &&
989 wps_dev_type_str2bin(wpa_s->conf->device_type,
990 wps->dev.pri_dev_type) < 0) {
991 wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
995 wps->dev.os_version = WPA_GET_BE32(wpa_s->conf->os_version);
996 wps->dev.rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ; /* TODO: config */
997 os_memcpy(wps->dev.mac_addr, wpa_s->own_addr, ETH_ALEN);
998 if (is_nil_uuid(wpa_s->conf->uuid)) {
999 uuid_gen_mac_addr(wpa_s->own_addr, wps->uuid);
1000 wpa_hexdump(MSG_DEBUG, "WPS: UUID based on MAC address",
1001 wps->uuid, WPS_UUID_LEN);
1003 os_memcpy(wps->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
1005 wps->auth_types = WPS_AUTH_WPA2PSK | WPS_AUTH_WPAPSK;
1006 wps->encr_types = WPS_ENCR_AES | WPS_ENCR_TKIP;
1008 os_memset(&rcfg, 0, sizeof(rcfg));
1009 rcfg.new_psk_cb = wpas_wps_new_psk_cb;
1010 rcfg.pin_needed_cb = wpas_wps_pin_needed_cb;
1011 rcfg.set_sel_reg_cb = wpas_wps_set_sel_reg_cb;
1012 rcfg.cb_ctx = wpa_s;
1014 wps->registrar = wps_registrar_init(wps, &rcfg);
1015 if (wps->registrar == NULL) {
1016 wpa_printf(MSG_DEBUG, "Failed to initialize WPS Registrar");
1027 void wpas_wps_deinit(struct wpa_supplicant *wpa_s)
1029 eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
1031 if (wpa_s->wps == NULL)
1034 #ifdef CONFIG_WPS_ER
1035 wps_er_deinit(wpa_s->wps_er, NULL, NULL);
1036 wpa_s->wps_er = NULL;
1037 #endif /* CONFIG_WPS_ER */
1039 wps_registrar_deinit(wpa_s->wps->registrar);
1040 wpabuf_free(wpa_s->wps->dh_pubkey);
1041 wpabuf_free(wpa_s->wps->dh_privkey);
1042 wpabuf_free(wpa_s->wps->oob_conf.pubkey_hash);
1043 wpabuf_free(wpa_s->wps->oob_conf.dev_password);
1044 os_free(wpa_s->wps->network_key);
1045 os_free(wpa_s->wps);
1050 int wpas_wps_ssid_bss_match(struct wpa_supplicant *wpa_s,
1051 struct wpa_ssid *ssid, struct wpa_scan_res *bss)
1053 struct wpabuf *wps_ie;
1055 if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS))
1058 wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1059 if (eap_is_wps_pbc_enrollee(&ssid->eap)) {
1061 wpa_printf(MSG_DEBUG, " skip - non-WPS AP");
1065 if (!wps_is_selected_pbc_registrar(wps_ie)) {
1066 wpa_printf(MSG_DEBUG, " skip - WPS AP "
1067 "without active PBC Registrar");
1068 wpabuf_free(wps_ie);
1072 /* TODO: overlap detection */
1073 wpa_printf(MSG_DEBUG, " selected based on WPS IE "
1075 wpabuf_free(wps_ie);
1079 if (eap_is_wps_pin_enrollee(&ssid->eap)) {
1081 wpa_printf(MSG_DEBUG, " skip - non-WPS AP");
1086 * Start with WPS APs that advertise our address as an
1087 * authorized MAC (v2.0) or active PIN Registrar (v1.0) and
1088 * allow any WPS AP after couple of scans since some APs do not
1089 * set Selected Registrar attribute properly when using
1090 * external Registrar.
1092 if (!wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1)) {
1093 if (wpa_s->scan_runs < WPS_PIN_SCAN_IGNORE_SEL_REG) {
1094 wpa_printf(MSG_DEBUG, " skip - WPS AP "
1095 "without active PIN Registrar");
1096 wpabuf_free(wps_ie);
1099 wpa_printf(MSG_DEBUG, " selected based on WPS IE");
1101 wpa_printf(MSG_DEBUG, " selected based on WPS IE "
1102 "(Authorized MAC or Active PIN)");
1104 wpabuf_free(wps_ie);
1109 wpa_printf(MSG_DEBUG, " selected based on WPS IE");
1110 wpabuf_free(wps_ie);
1118 int wpas_wps_ssid_wildcard_ok(struct wpa_supplicant *wpa_s,
1119 struct wpa_ssid *ssid,
1120 struct wpa_scan_res *bss)
1122 struct wpabuf *wps_ie = NULL;
1125 if (eap_is_wps_pbc_enrollee(&ssid->eap)) {
1126 wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1127 if (wps_ie && wps_is_selected_pbc_registrar(wps_ie)) {
1128 /* allow wildcard SSID for WPS PBC */
1131 } else if (eap_is_wps_pin_enrollee(&ssid->eap)) {
1132 wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1134 (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1) ||
1135 wpa_s->scan_runs >= WPS_PIN_SCAN_IGNORE_SEL_REG)) {
1136 /* allow wildcard SSID for WPS PIN */
1141 if (!ret && ssid->bssid_set &&
1142 os_memcmp(ssid->bssid, bss->bssid, ETH_ALEN) == 0) {
1143 /* allow wildcard SSID due to hardcoded BSSID match */
1147 #ifdef CONFIG_WPS_STRICT
1149 if (wps_validate_beacon_probe_resp(wps_ie, bss->beacon_ie_len >
1152 if (bss->beacon_ie_len) {
1153 struct wpabuf *bcn_wps;
1154 bcn_wps = wpa_scan_get_vendor_ie_multi_beacon(
1155 bss, WPS_IE_VENDOR_TYPE);
1156 if (bcn_wps == NULL) {
1157 wpa_printf(MSG_DEBUG, "WPS: Mandatory WPS IE "
1158 "missing from AP Beacon");
1161 if (wps_validate_beacon(wps_ie) < 0)
1163 wpabuf_free(bcn_wps);
1167 #endif /* CONFIG_WPS_STRICT */
1169 wpabuf_free(wps_ie);
1175 int wpas_wps_scan_pbc_overlap(struct wpa_supplicant *wpa_s,
1176 struct wpa_bss *selected, struct wpa_ssid *ssid)
1178 const u8 *sel_uuid, *uuid;
1179 struct wpabuf *wps_ie;
1181 struct wpa_bss *bss;
1183 if (!eap_is_wps_pbc_enrollee(&ssid->eap))
1186 wpa_printf(MSG_DEBUG, "WPS: Check whether PBC session overlap is "
1187 "present in scan results; selected BSSID " MACSTR,
1188 MAC2STR(selected->bssid));
1190 /* Make sure that only one AP is in active PBC mode */
1191 wps_ie = wpa_bss_get_vendor_ie_multi(selected, WPS_IE_VENDOR_TYPE);
1193 sel_uuid = wps_get_uuid_e(wps_ie);
1194 wpa_hexdump(MSG_DEBUG, "WPS: UUID of the selected BSS",
1195 sel_uuid, UUID_LEN);
1197 wpa_printf(MSG_DEBUG, "WPS: Selected BSS does not include "
1202 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1204 if (bss == selected)
1206 ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1209 if (!wps_is_selected_pbc_registrar(ie)) {
1213 wpa_printf(MSG_DEBUG, "WPS: Another BSS in active PBC mode: "
1214 MACSTR, MAC2STR(bss->bssid));
1215 uuid = wps_get_uuid_e(ie);
1216 wpa_hexdump(MSG_DEBUG, "WPS: UUID of the other BSS",
1218 if (sel_uuid == NULL || uuid == NULL ||
1219 os_memcmp(sel_uuid, uuid, UUID_LEN) != 0) {
1220 ret = 1; /* PBC overlap */
1221 wpa_msg(wpa_s, MSG_INFO, "WPS: PBC overlap detected: "
1222 MACSTR " and " MACSTR,
1223 MAC2STR(selected->bssid),
1224 MAC2STR(bss->bssid));
1229 /* TODO: verify that this is reasonable dual-band situation */
1234 wpabuf_free(wps_ie);
1240 void wpas_wps_notify_scan_results(struct wpa_supplicant *wpa_s)
1242 struct wpa_bss *bss;
1244 if (wpa_s->disconnected || wpa_s->wpa_state >= WPA_ASSOCIATED)
1247 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1249 ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1252 if (wps_is_selected_pbc_registrar(ie))
1253 wpa_msg_ctrl(wpa_s, MSG_INFO,
1254 WPS_EVENT_AP_AVAILABLE_PBC);
1255 else if (wps_is_addr_authorized(ie, wpa_s->own_addr, 0))
1256 wpa_msg_ctrl(wpa_s, MSG_INFO,
1257 WPS_EVENT_AP_AVAILABLE_AUTH);
1258 else if (wps_is_selected_pin_registrar(ie))
1259 wpa_msg_ctrl(wpa_s, MSG_INFO,
1260 WPS_EVENT_AP_AVAILABLE_PIN);
1262 wpa_msg_ctrl(wpa_s, MSG_INFO,
1263 WPS_EVENT_AP_AVAILABLE);
1270 int wpas_wps_searching(struct wpa_supplicant *wpa_s)
1272 struct wpa_ssid *ssid;
1274 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1275 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && !ssid->disabled)
1283 int wpas_wps_scan_result_text(const u8 *ies, size_t ies_len, char *buf,
1286 struct wpabuf *wps_ie;
1289 wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len, WPS_DEV_OUI_WFA);
1293 ret = wps_attr_text(wps_ie, buf, end);
1294 wpabuf_free(wps_ie);
1299 int wpas_wps_er_start(struct wpa_supplicant *wpa_s, const char *filter)
1301 #ifdef CONFIG_WPS_ER
1302 if (wpa_s->wps_er) {
1303 wps_er_refresh(wpa_s->wps_er);
1306 wpa_s->wps_er = wps_er_init(wpa_s->wps, wpa_s->ifname, filter);
1307 if (wpa_s->wps_er == NULL)
1310 #else /* CONFIG_WPS_ER */
1312 #endif /* CONFIG_WPS_ER */
1316 int wpas_wps_er_stop(struct wpa_supplicant *wpa_s)
1318 #ifdef CONFIG_WPS_ER
1319 wps_er_deinit(wpa_s->wps_er, NULL, NULL);
1320 wpa_s->wps_er = NULL;
1321 #endif /* CONFIG_WPS_ER */
1326 #ifdef CONFIG_WPS_ER
1327 int wpas_wps_er_add_pin(struct wpa_supplicant *wpa_s, const u8 *addr,
1328 const char *uuid, const char *pin)
1333 if (os_strcmp(uuid, "any") == 0)
1335 else if (uuid_str2bin(uuid, u))
1337 return wps_registrar_add_pin(wpa_s->wps->registrar, addr,
1339 (const u8 *) pin, os_strlen(pin), 300);
1343 int wpas_wps_er_pbc(struct wpa_supplicant *wpa_s, const char *uuid)
1347 if (uuid_str2bin(uuid, u))
1349 return wps_er_pbc(wpa_s->wps_er, u);
1353 int wpas_wps_er_learn(struct wpa_supplicant *wpa_s, const char *uuid,
1358 if (uuid_str2bin(uuid, u))
1360 return wps_er_learn(wpa_s->wps_er, u, (const u8 *) pin,
1365 int wpas_wps_er_config(struct wpa_supplicant *wpa_s, const char *uuid,
1366 const char *pin, struct wps_new_ap_settings *settings)
1369 struct wps_credential cred;
1372 if (uuid_str2bin(uuid, u))
1374 if (settings->ssid_hex == NULL || settings->auth == NULL ||
1375 settings->encr == NULL || settings->key_hex == NULL)
1378 os_memset(&cred, 0, sizeof(cred));
1379 len = os_strlen(settings->ssid_hex);
1380 if ((len & 1) || len > 2 * sizeof(cred.ssid) ||
1381 hexstr2bin(settings->ssid_hex, cred.ssid, len / 2))
1383 cred.ssid_len = len / 2;
1385 len = os_strlen(settings->key_hex);
1386 if ((len & 1) || len > 2 * sizeof(cred.key) ||
1387 hexstr2bin(settings->key_hex, cred.key, len / 2))
1389 cred.key_len = len / 2;
1391 if (os_strcmp(settings->auth, "OPEN") == 0)
1392 cred.auth_type = WPS_AUTH_OPEN;
1393 else if (os_strcmp(settings->auth, "WPAPSK") == 0)
1394 cred.auth_type = WPS_AUTH_WPAPSK;
1395 else if (os_strcmp(settings->auth, "WPA2PSK") == 0)
1396 cred.auth_type = WPS_AUTH_WPA2PSK;
1400 if (os_strcmp(settings->encr, "NONE") == 0)
1401 cred.encr_type = WPS_ENCR_NONE;
1402 else if (os_strcmp(settings->encr, "WEP") == 0)
1403 cred.encr_type = WPS_ENCR_WEP;
1404 else if (os_strcmp(settings->encr, "TKIP") == 0)
1405 cred.encr_type = WPS_ENCR_TKIP;
1406 else if (os_strcmp(settings->encr, "CCMP") == 0)
1407 cred.encr_type = WPS_ENCR_AES;
1411 return wps_er_config(wpa_s->wps_er, u, (const u8 *) pin,
1412 os_strlen(pin), &cred);
1416 static void wpas_wps_terminate_cb(void *ctx)
1418 wpa_printf(MSG_DEBUG, "WPS ER: Terminated");
1421 #endif /* CONFIG_WPS_ER */
1424 int wpas_wps_terminate_pending(struct wpa_supplicant *wpa_s)
1426 #ifdef CONFIG_WPS_ER
1427 if (wpa_s->wps_er) {
1428 wps_er_deinit(wpa_s->wps_er, wpas_wps_terminate_cb, wpa_s);
1429 wpa_s->wps_er = NULL;
1432 #endif /* CONFIG_WPS_ER */
1437 int wpas_wps_in_progress(struct wpa_supplicant *wpa_s)
1439 struct wpa_ssid *ssid;
1441 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1442 if (!ssid->disabled && ssid->key_mgmt == WPA_KEY_MGMT_WPS)
1450 void wpas_wps_update_config(struct wpa_supplicant *wpa_s)
1452 struct wps_context *wps = wpa_s->wps;
1457 if (wpa_s->conf->changed_parameters & CFG_CHANGED_CONFIG_METHODS) {
1458 wps->config_methods = wps_config_methods_str2bin(
1459 wpa_s->conf->config_methods);
1460 if ((wps->config_methods &
1461 (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) ==
1462 (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) {
1463 wpa_printf(MSG_ERROR, "WPS: Both Label and Display "
1464 "config methods are not allowed at the "
1466 wps->config_methods &= ~WPS_CONFIG_LABEL;
1469 wps->config_methods = wps_fix_config_methods(wps->config_methods);
1471 if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_TYPE) {
1472 if (wpa_s->conf->device_type &&
1473 wps_dev_type_str2bin(wpa_s->conf->device_type,
1474 wps->dev.pri_dev_type) < 0)
1475 wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
1478 if (wpa_s->conf->changed_parameters & CFG_CHANGED_OS_VERSION)
1479 wps->dev.os_version = WPA_GET_BE32(wpa_s->conf->os_version);
1481 if (wpa_s->conf->changed_parameters & CFG_CHANGED_UUID) {
1482 if (is_nil_uuid(wpa_s->conf->uuid)) {
1483 uuid_gen_mac_addr(wpa_s->own_addr, wps->uuid);
1484 wpa_hexdump(MSG_DEBUG, "WPS: UUID based on MAC "
1485 "address", wps->uuid, WPS_UUID_LEN);
1487 os_memcpy(wps->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
1490 if (wpa_s->conf->changed_parameters &
1491 (CFG_CHANGED_DEVICE_NAME | CFG_CHANGED_WPS_STRING)) {
1492 /* Update pointers to make sure they refer current values */
1493 wps->dev.device_name = wpa_s->conf->device_name;
1494 wps->dev.manufacturer = wpa_s->conf->manufacturer;
1495 wps->dev.model_name = wpa_s->conf->model_name;
1496 wps->dev.model_number = wpa_s->conf->model_number;
1497 wps->dev.serial_number = wpa_s->conf->serial_number;