2 * wpa_supplicant / WPS integration
3 * Copyright (c) 2008-2014, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
14 #include "crypto/random.h"
15 #include "crypto/dh_group5.h"
16 #include "common/ieee802_11_defs.h"
17 #include "common/ieee802_11_common.h"
18 #include "common/wpa_common.h"
19 #include "common/wpa_ctrl.h"
20 #include "eap_common/eap_wsc_common.h"
21 #include "eap_peer/eap.h"
22 #include "eapol_supp/eapol_supp_sm.h"
23 #include "rsn_supp/wpa.h"
24 #include "wps/wps_attr_parse.h"
26 #include "wpa_supplicant_i.h"
29 #include "blacklist.h"
34 #include "p2p_supplicant.h"
35 #include "wps_supplicant.h"
38 #ifndef WPS_PIN_SCAN_IGNORE_SEL_REG
39 #define WPS_PIN_SCAN_IGNORE_SEL_REG 3
40 #endif /* WPS_PIN_SCAN_IGNORE_SEL_REG */
42 static void wpas_wps_timeout(void *eloop_ctx, void *timeout_ctx);
43 static void wpas_clear_wps(struct wpa_supplicant *wpa_s);
46 static void wpas_wps_clear_ap_info(struct wpa_supplicant *wpa_s)
48 os_free(wpa_s->wps_ap);
50 wpa_s->num_wps_ap = 0;
51 wpa_s->wps_ap_iter = 0;
55 static void wpas_wps_assoc_with_cred(void *eloop_ctx, void *timeout_ctx)
57 struct wpa_supplicant *wpa_s = eloop_ctx;
58 int use_fast_assoc = timeout_ctx != NULL;
60 wpa_printf(MSG_DEBUG, "WPS: Continuing association after eapol_cb");
61 if (!use_fast_assoc ||
62 wpa_supplicant_fast_associate(wpa_s) != 1)
63 wpa_supplicant_req_scan(wpa_s, 0, 0);
67 static void wpas_wps_assoc_with_cred_cancel(struct wpa_supplicant *wpa_s)
69 eloop_cancel_timeout(wpas_wps_assoc_with_cred, wpa_s, (void *) 0);
70 eloop_cancel_timeout(wpas_wps_assoc_with_cred, wpa_s, (void *) 1);
74 int wpas_wps_eapol_cb(struct wpa_supplicant *wpa_s)
76 if (wpas_p2p_wps_eapol_cb(wpa_s) > 0)
79 if (!wpa_s->wps_success &&
80 wpa_s->current_ssid &&
81 eap_is_wps_pin_enrollee(&wpa_s->current_ssid->eap)) {
82 const u8 *bssid = wpa_s->bssid;
83 if (is_zero_ether_addr(bssid))
84 bssid = wpa_s->pending_bssid;
86 wpa_printf(MSG_DEBUG, "WPS: PIN registration with " MACSTR
87 " did not succeed - continue trying to find "
88 "suitable AP", MAC2STR(bssid));
89 wpa_blacklist_add(wpa_s, bssid);
91 wpa_supplicant_deauthenticate(wpa_s,
92 WLAN_REASON_DEAUTH_LEAVING);
93 wpa_s->reassociate = 1;
94 wpa_supplicant_req_scan(wpa_s,
95 wpa_s->blacklist_cleared ? 5 : 0, 0);
96 wpa_s->blacklist_cleared = 0;
100 wpas_wps_clear_ap_info(wpa_s);
101 eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
102 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && !wpa_s->wps_success)
103 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_FAIL);
105 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && wpa_s->current_ssid &&
106 !(wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
107 int disabled = wpa_s->current_ssid->disabled;
108 unsigned int freq = wpa_s->assoc_freq;
110 struct wpa_ssid *ssid = NULL;
111 int use_fast_assoc = 0;
113 wpa_printf(MSG_DEBUG, "WPS: Network configuration replaced - "
114 "try to associate with the received credential "
116 wpa_s->own_disconnect_req = 1;
117 wpa_supplicant_deauthenticate(wpa_s,
118 WLAN_REASON_DEAUTH_LEAVING);
120 wpa_printf(MSG_DEBUG, "WPS: Current network is "
121 "disabled - wait for user to enable");
124 wpa_s->after_wps = 5;
125 wpa_s->wps_freq = freq;
126 wpa_s->normal_scans = 0;
127 wpa_s->reassociate = 1;
129 wpa_printf(MSG_DEBUG, "WPS: Checking whether fast association "
130 "without a new scan can be used");
131 bss = wpa_supplicant_pick_network(wpa_s, &ssid);
134 struct wps_parse_attr attr;
136 wps = wpa_bss_get_vendor_ie_multi(bss,
138 if (wps && wps_parse_msg(wps, &attr) == 0 &&
140 *attr.wps_state == WPS_STATE_CONFIGURED)
146 * Complete the next step from an eloop timeout to allow pending
147 * driver events related to the disconnection to be processed
148 * first. This makes it less likely for disconnection event to
149 * cause problems with the following connection.
151 wpa_printf(MSG_DEBUG, "WPS: Continue association from timeout");
152 wpas_wps_assoc_with_cred_cancel(wpa_s);
153 eloop_register_timeout(0, 10000,
154 wpas_wps_assoc_with_cred, wpa_s,
155 use_fast_assoc ? (void *) 1 :
160 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && wpa_s->current_ssid) {
161 wpa_printf(MSG_DEBUG, "WPS: Registration completed - waiting "
162 "for external credential processing");
163 wpas_clear_wps(wpa_s);
164 wpa_s->own_disconnect_req = 1;
165 wpa_supplicant_deauthenticate(wpa_s,
166 WLAN_REASON_DEAUTH_LEAVING);
174 static void wpas_wps_security_workaround(struct wpa_supplicant *wpa_s,
175 struct wpa_ssid *ssid,
176 const struct wps_credential *cred)
178 struct wpa_driver_capa capa;
181 struct wpa_ie_data adv;
182 int wpa2 = 0, ccmp = 0;
185 * Many existing WPS APs do not know how to negotiate WPA2 or CCMP in
186 * case they are configured for mixed mode operation (WPA+WPA2 and
187 * TKIP+CCMP). Try to use scan results to figure out whether the AP
188 * actually supports stronger security and select that if the client
189 * has support for it, too.
192 if (wpa_drv_get_capa(wpa_s, &capa))
193 return; /* Unknown what driver supports */
195 if (ssid->ssid == NULL)
197 bss = wpa_bss_get(wpa_s, cred->mac_addr, ssid->ssid, ssid->ssid_len);
199 wpa_printf(MSG_DEBUG, "WPS: The AP was not found from BSS "
200 "table - use credential as-is");
204 wpa_printf(MSG_DEBUG, "WPS: AP found from BSS table");
206 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
207 if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0) {
209 if (adv.pairwise_cipher & WPA_CIPHER_CCMP)
212 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
213 if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0 &&
214 adv.pairwise_cipher & WPA_CIPHER_CCMP)
218 if (ie == NULL && (ssid->proto & WPA_PROTO_WPA) &&
219 (ssid->pairwise_cipher & WPA_CIPHER_TKIP)) {
221 * TODO: This could be the initial AP configuration and the
222 * Beacon contents could change shortly. Should request a new
223 * scan and delay addition of the network until the updated
224 * scan results are available.
226 wpa_printf(MSG_DEBUG, "WPS: The AP did not yet advertise WPA "
227 "support - use credential as-is");
231 if (ccmp && !(ssid->pairwise_cipher & WPA_CIPHER_CCMP) &&
232 (ssid->pairwise_cipher & WPA_CIPHER_TKIP) &&
233 (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
234 wpa_printf(MSG_DEBUG, "WPS: Add CCMP into the credential "
235 "based on scan results");
236 if (wpa_s->conf->ap_scan == 1)
237 ssid->pairwise_cipher |= WPA_CIPHER_CCMP;
239 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
242 if (wpa2 && !(ssid->proto & WPA_PROTO_RSN) &&
243 (ssid->proto & WPA_PROTO_WPA) &&
244 (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP)) {
245 wpa_printf(MSG_DEBUG, "WPS: Add WPA2 into the credential "
246 "based on scan results");
247 if (wpa_s->conf->ap_scan == 1)
248 ssid->proto |= WPA_PROTO_RSN;
250 ssid->proto = WPA_PROTO_RSN;
255 static void wpas_wps_remove_dup_network(struct wpa_supplicant *wpa_s,
256 struct wpa_ssid *new_ssid)
258 struct wpa_ssid *ssid, *next;
260 for (ssid = wpa_s->conf->ssid, next = ssid ? ssid->next : NULL; ssid;
261 ssid = next, next = ssid ? ssid->next : NULL) {
263 * new_ssid has already been added to the list in
264 * wpas_wps_add_network(), so skip it.
266 if (ssid == new_ssid)
269 if (ssid->bssid_set || new_ssid->bssid_set) {
270 if (ssid->bssid_set != new_ssid->bssid_set)
272 if (os_memcmp(ssid->bssid, new_ssid->bssid, ETH_ALEN) !=
278 if (ssid->ssid_len == 0 || ssid->ssid_len != new_ssid->ssid_len)
281 if (ssid->ssid && new_ssid->ssid) {
282 if (os_memcmp(ssid->ssid, new_ssid->ssid,
283 ssid->ssid_len) != 0)
285 } else if (ssid->ssid || new_ssid->ssid)
288 /* compare security parameters */
289 if (ssid->auth_alg != new_ssid->auth_alg ||
290 ssid->key_mgmt != new_ssid->key_mgmt ||
291 (ssid->group_cipher != new_ssid->group_cipher &&
292 !(ssid->group_cipher & new_ssid->group_cipher &
297 * Some existing WPS APs will send two creds in case they are
298 * configured for mixed mode operation (WPA+WPA2 and TKIP+CCMP).
299 * Try to merge these two creds if they are received in the same
302 if (ssid->wps_run && ssid->wps_run == new_ssid->wps_run &&
303 wpa_key_mgmt_wpa_psk(ssid->key_mgmt)) {
304 if (new_ssid->passphrase && ssid->passphrase &&
305 os_strcmp(new_ssid->passphrase, ssid->passphrase) !=
307 wpa_printf(MSG_DEBUG,
308 "WPS: M8 Creds with different passphrase - do not merge");
312 if (new_ssid->psk_set &&
314 os_memcmp(new_ssid->psk, ssid->psk, 32) != 0)) {
315 wpa_printf(MSG_DEBUG,
316 "WPS: M8 Creds with different PSK - do not merge");
320 if ((new_ssid->passphrase && !ssid->passphrase) ||
321 (!new_ssid->passphrase && ssid->passphrase)) {
322 wpa_printf(MSG_DEBUG,
323 "WPS: M8 Creds with different passphrase/PSK type - do not merge");
327 wpa_printf(MSG_DEBUG,
328 "WPS: Workaround - merge likely WPA/WPA2-mixed mode creds in same M8 message");
329 new_ssid->proto |= ssid->proto;
330 new_ssid->pairwise_cipher |= ssid->pairwise_cipher;
333 * proto and pairwise_cipher difference matter for
334 * non-mixed-mode creds.
336 if (ssid->proto != new_ssid->proto ||
337 ssid->pairwise_cipher != new_ssid->pairwise_cipher)
341 /* Remove the duplicated older network entry. */
342 wpa_printf(MSG_DEBUG, "Remove duplicate network %d", ssid->id);
343 wpas_notify_network_removed(wpa_s, ssid);
344 if (wpa_s->current_ssid == ssid)
345 wpa_s->current_ssid = NULL;
346 wpa_config_remove_network(wpa_s->conf, ssid->id);
351 static int wpa_supplicant_wps_cred(void *ctx,
352 const struct wps_credential *cred)
354 struct wpa_supplicant *wpa_s = ctx;
355 struct wpa_ssid *ssid = wpa_s->current_ssid;
357 #ifdef CONFIG_WPS_REG_DISABLE_OPEN
359 #endif /* CONFIG_WPS_REG_DISABLE_OPEN */
361 if ((wpa_s->conf->wps_cred_processing == 1 ||
362 wpa_s->conf->wps_cred_processing == 2) && cred->cred_attr) {
363 size_t blen = cred->cred_attr_len * 2 + 1;
364 char *buf = os_malloc(blen);
366 wpa_snprintf_hex(buf, blen,
367 cred->cred_attr, cred->cred_attr_len);
368 wpa_msg(wpa_s, MSG_INFO, "%s%s",
369 WPS_EVENT_CRED_RECEIVED, buf);
373 wpas_notify_wps_credential(wpa_s, cred);
375 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_CRED_RECEIVED);
377 wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
378 cred->cred_attr, cred->cred_attr_len);
380 if (wpa_s->conf->wps_cred_processing == 1)
383 wpa_hexdump_ascii(MSG_DEBUG, "WPS: SSID", cred->ssid, cred->ssid_len);
384 wpa_printf(MSG_DEBUG, "WPS: Authentication Type 0x%x",
386 wpa_printf(MSG_DEBUG, "WPS: Encryption Type 0x%x", cred->encr_type);
387 wpa_printf(MSG_DEBUG, "WPS: Network Key Index %d", cred->key_idx);
388 wpa_hexdump_key(MSG_DEBUG, "WPS: Network Key",
389 cred->key, cred->key_len);
390 wpa_printf(MSG_DEBUG, "WPS: MAC Address " MACSTR,
391 MAC2STR(cred->mac_addr));
393 auth_type = cred->auth_type;
394 if (auth_type == (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) {
395 wpa_printf(MSG_DEBUG, "WPS: Workaround - convert mixed-mode "
396 "auth_type into WPA2PSK");
397 auth_type = WPS_AUTH_WPA2PSK;
400 if (auth_type != WPS_AUTH_OPEN &&
401 auth_type != WPS_AUTH_WPAPSK &&
402 auth_type != WPS_AUTH_WPA2PSK) {
403 wpa_printf(MSG_DEBUG, "WPS: Ignored credentials for "
404 "unsupported authentication type 0x%x",
409 if (auth_type == WPS_AUTH_WPAPSK || auth_type == WPS_AUTH_WPA2PSK) {
410 if (cred->key_len < 8 || cred->key_len > 2 * PMK_LEN) {
411 wpa_printf(MSG_ERROR, "WPS: Reject PSK credential with "
412 "invalid Network Key length %lu",
413 (unsigned long) cred->key_len);
418 if (ssid && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
419 wpa_printf(MSG_DEBUG, "WPS: Replace WPS network block based "
420 "on the received credential");
421 #ifdef CONFIG_WPS_REG_DISABLE_OPEN
422 if (ssid->eap.identity &&
423 ssid->eap.identity_len == WSC_ID_REGISTRAR_LEN &&
424 os_memcmp(ssid->eap.identity, WSC_ID_REGISTRAR,
425 WSC_ID_REGISTRAR_LEN) == 0)
427 #endif /* CONFIG_WPS_REG_DISABLE_OPEN */
428 os_free(ssid->eap.identity);
429 ssid->eap.identity = NULL;
430 ssid->eap.identity_len = 0;
431 os_free(ssid->eap.phase1);
432 ssid->eap.phase1 = NULL;
433 os_free(ssid->eap.eap_methods);
434 ssid->eap.eap_methods = NULL;
435 if (!ssid->p2p_group) {
439 ssid->disabled_until.sec = 0;
440 ssid->disabled_until.usec = 0;
441 ssid->auth_failures = 0;
443 wpa_printf(MSG_DEBUG, "WPS: Create a new network based on the "
444 "received credential");
445 ssid = wpa_config_add_network(wpa_s->conf);
448 if (wpa_s->current_ssid) {
450 * Should the GO issue multiple credentials for some
451 * reason, each credential should be marked as a
452 * temporary P2P group similarly to the one that gets
453 * marked as such based on the pre-configured values
454 * used for the WPS network block.
456 ssid->p2p_group = wpa_s->current_ssid->p2p_group;
457 ssid->temporary = wpa_s->current_ssid->temporary;
459 wpas_notify_network_added(wpa_s, ssid);
462 wpa_config_set_network_defaults(ssid);
463 ssid->wps_run = wpa_s->wps_run;
466 ssid->ssid = os_malloc(cred->ssid_len);
468 os_memcpy(ssid->ssid, cred->ssid, cred->ssid_len);
469 ssid->ssid_len = cred->ssid_len;
472 switch (cred->encr_type) {
476 ssid->pairwise_cipher = WPA_CIPHER_TKIP;
479 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
480 if (wpa_s->drv_capa_known &&
481 (wpa_s->drv_enc & WPA_DRIVER_CAPA_ENC_GCMP)) {
482 ssid->pairwise_cipher |= WPA_CIPHER_GCMP;
483 ssid->group_cipher |= WPA_CIPHER_GCMP;
490 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
491 ssid->key_mgmt = WPA_KEY_MGMT_NONE;
493 #ifdef CONFIG_WPS_REG_DISABLE_OPEN
495 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OPEN_NETWORK
496 "id=%d - Credentials for an open "
497 "network disabled by default - use "
498 "'select_network %d' to enable",
502 #endif /* CONFIG_WPS_REG_DISABLE_OPEN */
504 case WPS_AUTH_WPAPSK:
505 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
506 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
507 ssid->proto = WPA_PROTO_WPA;
509 case WPS_AUTH_WPA2PSK:
510 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
511 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
512 ssid->proto = WPA_PROTO_RSN;
516 if (ssid->key_mgmt == WPA_KEY_MGMT_PSK) {
517 if (cred->key_len == 2 * PMK_LEN) {
518 if (hexstr2bin((const char *) cred->key, ssid->psk,
520 wpa_printf(MSG_ERROR, "WPS: Invalid Network "
525 ssid->export_keys = 1;
526 } else if (cred->key_len >= 8 && cred->key_len < 2 * PMK_LEN) {
527 os_free(ssid->passphrase);
528 ssid->passphrase = os_malloc(cred->key_len + 1);
529 if (ssid->passphrase == NULL)
531 os_memcpy(ssid->passphrase, cred->key, cred->key_len);
532 ssid->passphrase[cred->key_len] = '\0';
533 wpa_config_update_psk(ssid);
534 ssid->export_keys = 1;
536 wpa_printf(MSG_ERROR, "WPS: Invalid Network Key "
538 (unsigned long) cred->key_len);
543 wpas_wps_security_workaround(wpa_s, ssid, cred);
545 wpas_wps_remove_dup_network(wpa_s, ssid);
547 #ifndef CONFIG_NO_CONFIG_WRITE
548 if (wpa_s->conf->update_config &&
549 wpa_config_write(wpa_s->confname, wpa_s->conf)) {
550 wpa_printf(MSG_DEBUG, "WPS: Failed to update configuration");
553 #endif /* CONFIG_NO_CONFIG_WRITE */
556 * Optimize the post-WPS scan based on the channel used during
557 * the provisioning in case EAP-Failure is not received.
559 wpa_s->after_wps = 5;
560 wpa_s->wps_freq = wpa_s->assoc_freq;
566 static void wpa_supplicant_wps_event_m2d(struct wpa_supplicant *wpa_s,
567 struct wps_event_m2d *m2d)
569 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_M2D
570 "dev_password_id=%d config_error=%d",
571 m2d->dev_password_id, m2d->config_error);
572 wpas_notify_wps_event_m2d(wpa_s, m2d);
574 if (wpa_s->parent && wpa_s->parent != wpa_s) {
575 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_M2D
576 "dev_password_id=%d config_error=%d",
577 m2d->dev_password_id, m2d->config_error);
579 if (m2d->config_error == WPS_CFG_MULTIPLE_PBC_DETECTED) {
581 * Notify P2P from eloop timeout to avoid issues with the
582 * interface getting removed while processing a message.
584 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb, wpa_s,
587 #endif /* CONFIG_P2P */
591 static void wpas_wps_clear_timeout(void *eloop_ctx, void *timeout_ctx)
593 struct wpa_supplicant *wpa_s = eloop_ctx;
594 wpa_printf(MSG_DEBUG, "WPS: Clear WPS network from timeout");
595 wpas_clear_wps(wpa_s);
599 static void wpa_supplicant_wps_event_fail(struct wpa_supplicant *wpa_s,
600 struct wps_event_fail *fail)
602 if (fail->error_indication > 0 &&
603 fail->error_indication < NUM_WPS_EI_VALUES) {
604 wpa_msg(wpa_s, MSG_INFO,
605 WPS_EVENT_FAIL "msg=%d config_error=%d reason=%d (%s)",
606 fail->msg, fail->config_error, fail->error_indication,
607 wps_ei_str(fail->error_indication));
608 if (wpa_s->parent && wpa_s->parent != wpa_s)
609 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
610 "msg=%d config_error=%d reason=%d (%s)",
611 fail->msg, fail->config_error,
612 fail->error_indication,
613 wps_ei_str(fail->error_indication));
615 wpa_msg(wpa_s, MSG_INFO,
616 WPS_EVENT_FAIL "msg=%d config_error=%d",
617 fail->msg, fail->config_error);
618 if (wpa_s->parent && wpa_s->parent != wpa_s)
619 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
620 "msg=%d config_error=%d",
621 fail->msg, fail->config_error);
625 * Need to allow WPS processing to complete, e.g., by sending WSC_NACK.
627 wpa_printf(MSG_DEBUG, "WPS: Register timeout to clear WPS network");
628 eloop_cancel_timeout(wpas_wps_clear_timeout, wpa_s, NULL);
629 eloop_register_timeout(0, 100000, wpas_wps_clear_timeout, wpa_s, NULL);
631 wpas_notify_wps_event_fail(wpa_s, fail);
632 wpas_p2p_wps_failed(wpa_s, fail);
636 static void wpas_wps_reenable_networks_cb(void *eloop_ctx, void *timeout_ctx);
638 static void wpas_wps_reenable_networks(struct wpa_supplicant *wpa_s)
640 struct wpa_ssid *ssid;
643 eloop_cancel_timeout(wpas_wps_reenable_networks_cb, wpa_s, NULL);
645 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
646 if (ssid->disabled_for_connect && ssid->disabled) {
647 ssid->disabled_for_connect = 0;
649 wpas_notify_network_enabled_changed(wpa_s, ssid);
655 #ifndef CONFIG_NO_CONFIG_WRITE
656 if (wpa_s->conf->update_config &&
657 wpa_config_write(wpa_s->confname, wpa_s->conf)) {
658 wpa_printf(MSG_DEBUG, "WPS: Failed to update "
661 #endif /* CONFIG_NO_CONFIG_WRITE */
666 static void wpas_wps_reenable_networks_cb(void *eloop_ctx, void *timeout_ctx)
668 struct wpa_supplicant *wpa_s = eloop_ctx;
669 /* Enable the networks disabled during wpas_wps_reassoc */
670 wpas_wps_reenable_networks(wpa_s);
674 static void wpa_supplicant_wps_event_success(struct wpa_supplicant *wpa_s)
676 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_SUCCESS);
677 wpa_s->wps_success = 1;
678 wpas_notify_wps_event_success(wpa_s);
679 if (wpa_s->current_ssid)
680 wpas_clear_temp_disabled(wpa_s, wpa_s->current_ssid, 1);
681 wpa_s->extra_blacklist_count = 0;
684 * Enable the networks disabled during wpas_wps_reassoc after 10
685 * seconds. The 10 seconds timer is to allow the data connection to be
686 * formed before allowing other networks to be selected.
688 eloop_register_timeout(10, 0, wpas_wps_reenable_networks_cb, wpa_s,
691 wpas_p2p_wps_success(wpa_s, wpa_s->bssid, 0);
695 static void wpa_supplicant_wps_event_er_ap_add(struct wpa_supplicant *wpa_s,
696 struct wps_event_er_ap *ap)
699 char dev_type[WPS_DEV_TYPE_BUFSIZE];
701 uuid_bin2str(ap->uuid, uuid_str, sizeof(uuid_str));
702 if (ap->pri_dev_type)
703 wps_dev_type_bin2str(ap->pri_dev_type, dev_type,
708 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_ADD "%s " MACSTR
709 " pri_dev_type=%s wps_state=%d |%s|%s|%s|%s|%s|%s|",
710 uuid_str, MAC2STR(ap->mac_addr), dev_type, ap->wps_state,
711 ap->friendly_name ? ap->friendly_name : "",
712 ap->manufacturer ? ap->manufacturer : "",
713 ap->model_description ? ap->model_description : "",
714 ap->model_name ? ap->model_name : "",
715 ap->manufacturer_url ? ap->manufacturer_url : "",
716 ap->model_url ? ap->model_url : "");
720 static void wpa_supplicant_wps_event_er_ap_remove(struct wpa_supplicant *wpa_s,
721 struct wps_event_er_ap *ap)
724 uuid_bin2str(ap->uuid, uuid_str, sizeof(uuid_str));
725 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_REMOVE "%s", uuid_str);
729 static void wpa_supplicant_wps_event_er_enrollee_add(
730 struct wpa_supplicant *wpa_s, struct wps_event_er_enrollee *enrollee)
733 char dev_type[WPS_DEV_TYPE_BUFSIZE];
735 uuid_bin2str(enrollee->uuid, uuid_str, sizeof(uuid_str));
736 if (enrollee->pri_dev_type)
737 wps_dev_type_bin2str(enrollee->pri_dev_type, dev_type,
742 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_ENROLLEE_ADD "%s " MACSTR
743 " M1=%d config_methods=0x%x dev_passwd_id=%d pri_dev_type=%s "
745 uuid_str, MAC2STR(enrollee->mac_addr), enrollee->m1_received,
746 enrollee->config_methods, enrollee->dev_passwd_id, dev_type,
747 enrollee->dev_name ? enrollee->dev_name : "",
748 enrollee->manufacturer ? enrollee->manufacturer : "",
749 enrollee->model_name ? enrollee->model_name : "",
750 enrollee->model_number ? enrollee->model_number : "",
751 enrollee->serial_number ? enrollee->serial_number : "");
755 static void wpa_supplicant_wps_event_er_enrollee_remove(
756 struct wpa_supplicant *wpa_s, struct wps_event_er_enrollee *enrollee)
759 uuid_bin2str(enrollee->uuid, uuid_str, sizeof(uuid_str));
760 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_ENROLLEE_REMOVE "%s " MACSTR,
761 uuid_str, MAC2STR(enrollee->mac_addr));
765 static void wpa_supplicant_wps_event_er_ap_settings(
766 struct wpa_supplicant *wpa_s,
767 struct wps_event_er_ap_settings *ap_settings)
771 const struct wps_credential *cred = ap_settings->cred;
774 if (cred->auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) {
775 if (cred->key_len >= 8 && cred->key_len <= 64) {
776 os_memcpy(key_str, cred->key, cred->key_len);
777 key_str[cred->key_len] = '\0';
781 uuid_bin2str(ap_settings->uuid, uuid_str, sizeof(uuid_str));
782 /* Use wpa_msg_ctrl to avoid showing the key in debug log */
783 wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_SETTINGS
784 "uuid=%s ssid=%s auth_type=0x%04x encr_type=0x%04x "
786 uuid_str, wpa_ssid_txt(cred->ssid, cred->ssid_len),
787 cred->auth_type, cred->encr_type, key_str);
791 static void wpa_supplicant_wps_event_er_set_sel_reg(
792 struct wpa_supplicant *wpa_s,
793 struct wps_event_er_set_selected_registrar *ev)
797 uuid_bin2str(ev->uuid, uuid_str, sizeof(uuid_str));
799 case WPS_ER_SET_SEL_REG_START:
800 wpa_msg(wpa_s, MSG_DEBUG, WPS_EVENT_ER_SET_SEL_REG
801 "uuid=%s state=START sel_reg=%d dev_passwd_id=%u "
802 "sel_reg_config_methods=0x%x",
803 uuid_str, ev->sel_reg, ev->dev_passwd_id,
804 ev->sel_reg_config_methods);
806 case WPS_ER_SET_SEL_REG_DONE:
807 wpa_msg(wpa_s, MSG_DEBUG, WPS_EVENT_ER_SET_SEL_REG
808 "uuid=%s state=DONE", uuid_str);
810 case WPS_ER_SET_SEL_REG_FAILED:
811 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_SET_SEL_REG
812 "uuid=%s state=FAILED", uuid_str);
818 static void wpa_supplicant_wps_event(void *ctx, enum wps_event event,
819 union wps_event_data *data)
821 struct wpa_supplicant *wpa_s = ctx;
824 wpa_supplicant_wps_event_m2d(wpa_s, &data->m2d);
827 wpa_supplicant_wps_event_fail(wpa_s, &data->fail);
830 wpa_supplicant_wps_event_success(wpa_s);
832 case WPS_EV_PWD_AUTH_FAIL:
834 if (wpa_s->ap_iface && data->pwd_auth_fail.enrollee)
835 wpa_supplicant_ap_pwd_auth_fail(wpa_s);
836 #endif /* CONFIG_AP */
838 case WPS_EV_PBC_OVERLAP:
840 case WPS_EV_PBC_TIMEOUT:
842 case WPS_EV_PBC_ACTIVE:
843 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ACTIVE);
845 case WPS_EV_PBC_DISABLE:
846 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_DISABLE);
848 case WPS_EV_ER_AP_ADD:
849 wpa_supplicant_wps_event_er_ap_add(wpa_s, &data->ap);
851 case WPS_EV_ER_AP_REMOVE:
852 wpa_supplicant_wps_event_er_ap_remove(wpa_s, &data->ap);
854 case WPS_EV_ER_ENROLLEE_ADD:
855 wpa_supplicant_wps_event_er_enrollee_add(wpa_s,
858 case WPS_EV_ER_ENROLLEE_REMOVE:
859 wpa_supplicant_wps_event_er_enrollee_remove(wpa_s,
862 case WPS_EV_ER_AP_SETTINGS:
863 wpa_supplicant_wps_event_er_ap_settings(wpa_s,
866 case WPS_EV_ER_SET_SELECTED_REGISTRAR:
867 wpa_supplicant_wps_event_er_set_sel_reg(wpa_s,
870 case WPS_EV_AP_PIN_SUCCESS:
876 static int wpa_supplicant_wps_rf_band(void *ctx)
878 struct wpa_supplicant *wpa_s = ctx;
880 if (!wpa_s->current_ssid || !wpa_s->assoc_freq)
883 return (wpa_s->assoc_freq > 2484) ? WPS_RF_50GHZ : WPS_RF_24GHZ;
887 enum wps_request_type wpas_wps_get_req_type(struct wpa_ssid *ssid)
889 if (eap_is_wps_pbc_enrollee(&ssid->eap) ||
890 eap_is_wps_pin_enrollee(&ssid->eap))
891 return WPS_REQ_ENROLLEE;
893 return WPS_REQ_REGISTRAR;
897 static void wpas_clear_wps(struct wpa_supplicant *wpa_s)
900 struct wpa_ssid *ssid, *remove_ssid = NULL, *prev_current;
902 wpa_s->after_wps = 0;
903 wpa_s->known_wps_freq = 0;
905 prev_current = wpa_s->current_ssid;
907 /* Enable the networks disabled during wpas_wps_reassoc */
908 wpas_wps_reenable_networks(wpa_s);
910 eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
911 eloop_cancel_timeout(wpas_wps_clear_timeout, wpa_s, NULL);
913 /* Remove any existing WPS network from configuration */
914 ssid = wpa_s->conf->ssid;
916 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
917 if (ssid == wpa_s->current_ssid) {
918 wpa_s->own_disconnect_req = 1;
919 wpa_supplicant_deauthenticate(
920 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
928 if (prev_current == remove_ssid) {
929 wpa_sm_set_config(wpa_s->wpa, NULL);
930 eapol_sm_notify_config(wpa_s->eapol, NULL,
933 wpas_notify_network_removed(wpa_s, remove_ssid);
934 wpa_config_remove_network(wpa_s->conf, id);
938 wpas_wps_clear_ap_info(wpa_s);
942 static void wpas_wps_timeout(void *eloop_ctx, void *timeout_ctx)
944 struct wpa_supplicant *wpa_s = eloop_ctx;
945 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_TIMEOUT "Requested operation timed "
947 wpas_clear_wps(wpa_s);
951 static struct wpa_ssid * wpas_wps_add_network(struct wpa_supplicant *wpa_s,
952 int registrar, const u8 *dev_addr,
955 struct wpa_ssid *ssid;
957 ssid = wpa_config_add_network(wpa_s->conf);
960 wpas_notify_network_added(wpa_s, ssid);
961 wpa_config_set_network_defaults(ssid);
963 if (wpa_config_set(ssid, "key_mgmt", "WPS", 0) < 0 ||
964 wpa_config_set(ssid, "eap", "WSC", 0) < 0 ||
965 wpa_config_set(ssid, "identity", registrar ?
966 "\"" WSC_ID_REGISTRAR "\"" :
967 "\"" WSC_ID_ENROLLEE "\"", 0) < 0) {
968 wpas_notify_network_removed(wpa_s, ssid);
969 wpa_config_remove_network(wpa_s->conf, ssid->id);
975 os_memcpy(ssid->go_p2p_dev_addr, dev_addr, ETH_ALEN);
976 #endif /* CONFIG_P2P */
982 #endif /* CONFIG_P2P */
984 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
988 * Note: With P2P, the SSID may change at the time the WPS
989 * provisioning is started, so better not filter the AP based
990 * on the current SSID in the scan results.
993 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
994 if (os_memcmp(bssid, bss->bssid, ETH_ALEN) != 0)
998 ssid->ssid = os_malloc(bss->ssid_len);
999 if (ssid->ssid == NULL)
1001 os_memcpy(ssid->ssid, bss->ssid, bss->ssid_len);
1002 ssid->ssid_len = bss->ssid_len;
1003 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Picked SSID from "
1005 ssid->ssid, ssid->ssid_len);
1010 wpa_printf(MSG_DEBUG, "WPS: More than one SSID found "
1011 "for the AP; use wildcard");
1012 os_free(ssid->ssid);
1016 #endif /* CONFIG_P2P */
1023 static void wpas_wps_temp_disable(struct wpa_supplicant *wpa_s,
1024 struct wpa_ssid *selected)
1026 struct wpa_ssid *ssid;
1028 if (wpa_s->current_ssid) {
1029 wpa_s->own_disconnect_req = 1;
1030 wpa_supplicant_deauthenticate(
1031 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1034 /* Mark all other networks disabled and trigger reassociation */
1035 ssid = wpa_s->conf->ssid;
1037 int was_disabled = ssid->disabled;
1038 ssid->disabled_for_connect = 0;
1040 * In case the network object corresponds to a persistent group
1041 * then do not send out network disabled signal. In addition,
1042 * do not change disabled status of persistent network objects
1043 * from 2 to 1 should we connect to another network.
1045 if (was_disabled != 2) {
1046 ssid->disabled = ssid != selected;
1047 if (was_disabled != ssid->disabled) {
1049 ssid->disabled_for_connect = 1;
1050 wpas_notify_network_enabled_changed(wpa_s,
1059 static void wpas_wps_reassoc(struct wpa_supplicant *wpa_s,
1060 struct wpa_ssid *selected, const u8 *bssid,
1063 struct wpa_bss *bss;
1066 if (wpa_s->wps_run == 0)
1068 wpa_s->after_wps = 0;
1069 wpa_s->known_wps_freq = 0;
1071 wpa_s->after_wps = 5;
1072 wpa_s->wps_freq = freq;
1074 bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
1075 if (bss && bss->freq > 0) {
1076 wpa_s->known_wps_freq = 1;
1077 wpa_s->wps_freq = bss->freq;
1081 wpas_wps_temp_disable(wpa_s, selected);
1083 wpa_s->disconnected = 0;
1084 wpa_s->reassociate = 1;
1085 wpa_s->scan_runs = 0;
1086 wpa_s->normal_scans = 0;
1087 wpa_s->wps_success = 0;
1088 wpa_s->blacklist_cleared = 0;
1090 wpa_supplicant_cancel_sched_scan(wpa_s);
1091 wpa_supplicant_req_scan(wpa_s, 0, 0);
1095 int wpas_wps_start_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
1098 struct wpa_ssid *ssid;
1101 if (wpa_s->ap_iface) {
1102 wpa_printf(MSG_DEBUG,
1103 "WPS: Reject request to start Registrar(as station) operation while AP mode is enabled");
1106 #endif /* CONFIG_AP */
1107 wpas_clear_wps(wpa_s);
1108 ssid = wpas_wps_add_network(wpa_s, 0, NULL, bssid);
1111 ssid->temporary = 1;
1112 ssid->p2p_group = p2p_group;
1114 if (p2p_group && wpa_s->go_params && wpa_s->go_params->ssid_len) {
1115 ssid->ssid = os_zalloc(wpa_s->go_params->ssid_len + 1);
1117 ssid->ssid_len = wpa_s->go_params->ssid_len;
1118 os_memcpy(ssid->ssid, wpa_s->go_params->ssid,
1120 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Use specific AP "
1121 "SSID", ssid->ssid, ssid->ssid_len);
1124 #endif /* CONFIG_P2P */
1125 if (wpa_config_set(ssid, "phase1", "\"pbc=1\"", 0) < 0)
1127 if (wpa_s->wps_fragment_size)
1128 ssid->eap.fragment_size = wpa_s->wps_fragment_size;
1129 eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
1131 wpas_wps_reassoc(wpa_s, ssid, bssid, 0);
1136 static int wpas_wps_start_dev_pw(struct wpa_supplicant *wpa_s,
1137 const u8 *dev_addr, const u8 *bssid,
1138 const char *pin, int p2p_group, u16 dev_pw_id,
1139 const u8 *peer_pubkey_hash,
1140 const u8 *ssid_val, size_t ssid_len, int freq)
1142 struct wpa_ssid *ssid;
1143 char val[128 + 2 * WPS_OOB_PUBKEY_HASH_LEN];
1144 unsigned int rpin = 0;
1145 char hash[2 * WPS_OOB_PUBKEY_HASH_LEN + 10];
1148 if (wpa_s->ap_iface) {
1149 wpa_printf(MSG_DEBUG,
1150 "WPS: Reject request to start Registrar(as station) operation while AP mode is enabled");
1153 #endif /* CONFIG_AP */
1154 wpas_clear_wps(wpa_s);
1155 if (bssid && is_zero_ether_addr(bssid))
1157 ssid = wpas_wps_add_network(wpa_s, 0, dev_addr, bssid);
1159 wpa_printf(MSG_DEBUG, "WPS: Could not add network");
1162 ssid->temporary = 1;
1163 ssid->p2p_group = p2p_group;
1165 ssid->ssid = os_malloc(ssid_len);
1167 os_memcpy(ssid->ssid, ssid_val, ssid_len);
1168 ssid->ssid_len = ssid_len;
1171 if (peer_pubkey_hash) {
1172 os_memcpy(hash, " pkhash=", 8);
1173 wpa_snprintf_hex_uppercase(hash + 8, sizeof(hash) - 8,
1175 WPS_OOB_PUBKEY_HASH_LEN);
1180 if (p2p_group && wpa_s->go_params && wpa_s->go_params->ssid_len) {
1181 ssid->ssid = os_zalloc(wpa_s->go_params->ssid_len + 1);
1183 ssid->ssid_len = wpa_s->go_params->ssid_len;
1184 os_memcpy(ssid->ssid, wpa_s->go_params->ssid,
1186 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Use specific AP "
1187 "SSID", ssid->ssid, ssid->ssid_len);
1190 #endif /* CONFIG_P2P */
1192 os_snprintf(val, sizeof(val), "\"pin=%s dev_pw_id=%u%s\"",
1193 pin, dev_pw_id, hash);
1194 else if (pin == NULL && dev_pw_id == DEV_PW_NFC_CONNECTION_HANDOVER) {
1195 os_snprintf(val, sizeof(val), "\"dev_pw_id=%u%s\"",
1198 rpin = wps_generate_pin();
1199 os_snprintf(val, sizeof(val), "\"pin=%08d dev_pw_id=%u%s\"",
1200 rpin, dev_pw_id, hash);
1202 if (wpa_config_set(ssid, "phase1", val, 0) < 0) {
1203 wpa_printf(MSG_DEBUG, "WPS: Failed to set phase1 '%s'", val);
1206 if (wpa_s->wps_fragment_size)
1207 ssid->eap.fragment_size = wpa_s->wps_fragment_size;
1208 eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
1210 wpa_s->wps_ap_iter = 1;
1211 wpas_wps_reassoc(wpa_s, ssid, bssid, freq);
1216 int wpas_wps_start_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
1217 const char *pin, int p2p_group, u16 dev_pw_id)
1219 return wpas_wps_start_dev_pw(wpa_s, NULL, bssid, pin, p2p_group,
1220 dev_pw_id, NULL, NULL, 0, 0);
1224 /* Cancel the wps pbc/pin requests */
1225 int wpas_wps_cancel(struct wpa_supplicant *wpa_s)
1228 if (wpa_s->ap_iface) {
1229 wpa_printf(MSG_DEBUG, "WPS: Cancelling in AP mode");
1230 return wpa_supplicant_ap_wps_cancel(wpa_s);
1232 #endif /* CONFIG_AP */
1234 if (wpa_s->wpa_state == WPA_SCANNING ||
1235 wpa_s->wpa_state == WPA_DISCONNECTED) {
1236 wpa_printf(MSG_DEBUG, "WPS: Cancel operation - cancel scan");
1237 wpa_supplicant_cancel_scan(wpa_s);
1238 wpas_clear_wps(wpa_s);
1239 } else if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1240 wpa_printf(MSG_DEBUG, "WPS: Cancel operation - "
1242 wpa_s->own_disconnect_req = 1;
1243 wpa_supplicant_deauthenticate(wpa_s,
1244 WLAN_REASON_DEAUTH_LEAVING);
1245 wpas_clear_wps(wpa_s);
1247 wpas_wps_reenable_networks(wpa_s);
1248 wpas_wps_clear_ap_info(wpa_s);
1249 if (eloop_cancel_timeout(wpas_wps_clear_timeout, wpa_s, NULL) >
1251 wpas_clear_wps(wpa_s);
1254 wpa_s->after_wps = 0;
1260 int wpas_wps_start_reg(struct wpa_supplicant *wpa_s, const u8 *bssid,
1261 const char *pin, struct wps_new_ap_settings *settings)
1263 struct wpa_ssid *ssid;
1269 if (wpa_s->ap_iface) {
1270 wpa_printf(MSG_DEBUG,
1271 "WPS: Reject request to start Registrar(as station) operation while AP mode is enabled");
1274 #endif /* CONFIG_AP */
1277 wpas_clear_wps(wpa_s);
1278 ssid = wpas_wps_add_network(wpa_s, 1, NULL, bssid);
1281 ssid->temporary = 1;
1283 end = pos + sizeof(val);
1284 res = os_snprintf(pos, end - pos, "\"pin=%s", pin);
1285 if (os_snprintf_error(end - pos, res))
1289 res = os_snprintf(pos, end - pos, " new_ssid=%s new_auth=%s "
1290 "new_encr=%s new_key=%s",
1291 settings->ssid_hex, settings->auth,
1292 settings->encr, settings->key_hex);
1293 if (os_snprintf_error(end - pos, res))
1297 res = os_snprintf(pos, end - pos, "\"");
1298 if (os_snprintf_error(end - pos, res))
1300 if (wpa_config_set(ssid, "phase1", val, 0) < 0)
1302 if (wpa_s->wps_fragment_size)
1303 ssid->eap.fragment_size = wpa_s->wps_fragment_size;
1304 eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
1306 wpas_wps_reassoc(wpa_s, ssid, bssid, 0);
1311 static int wpas_wps_new_psk_cb(void *ctx, const u8 *mac_addr,
1312 const u8 *p2p_dev_addr, const u8 *psk,
1315 if (is_zero_ether_addr(p2p_dev_addr)) {
1316 wpa_printf(MSG_DEBUG,
1317 "Received new WPA/WPA2-PSK from WPS for STA " MACSTR,
1320 wpa_printf(MSG_DEBUG,
1321 "Received new WPA/WPA2-PSK from WPS for STA " MACSTR
1322 " P2P Device Addr " MACSTR,
1323 MAC2STR(mac_addr), MAC2STR(p2p_dev_addr));
1325 wpa_hexdump_key(MSG_DEBUG, "Per-device PSK", psk, psk_len);
1333 static void wpas_wps_pin_needed_cb(void *ctx, const u8 *uuid_e,
1334 const struct wps_device_data *dev)
1336 char uuid[40], txt[400];
1338 char devtype[WPS_DEV_TYPE_BUFSIZE];
1339 if (uuid_bin2str(uuid_e, uuid, sizeof(uuid)))
1341 wpa_printf(MSG_DEBUG, "WPS: PIN needed for UUID-E %s", uuid);
1342 len = os_snprintf(txt, sizeof(txt), "WPS-EVENT-PIN-NEEDED %s " MACSTR
1343 " [%s|%s|%s|%s|%s|%s]",
1344 uuid, MAC2STR(dev->mac_addr), dev->device_name,
1345 dev->manufacturer, dev->model_name,
1346 dev->model_number, dev->serial_number,
1347 wps_dev_type_bin2str(dev->pri_dev_type, devtype,
1349 if (!os_snprintf_error(sizeof(txt), len))
1350 wpa_printf(MSG_INFO, "%s", txt);
1354 static void wpas_wps_set_sel_reg_cb(void *ctx, int sel_reg, u16 dev_passwd_id,
1355 u16 sel_reg_config_methods)
1357 #ifdef CONFIG_WPS_ER
1358 struct wpa_supplicant *wpa_s = ctx;
1360 if (wpa_s->wps_er == NULL)
1362 wpa_printf(MSG_DEBUG, "WPS ER: SetSelectedRegistrar - sel_reg=%d "
1363 "dev_password_id=%u sel_reg_config_methods=0x%x",
1364 sel_reg, dev_passwd_id, sel_reg_config_methods);
1365 wps_er_set_sel_reg(wpa_s->wps_er, sel_reg, dev_passwd_id,
1366 sel_reg_config_methods);
1367 #endif /* CONFIG_WPS_ER */
1371 static u16 wps_fix_config_methods(u16 config_methods)
1373 if ((config_methods &
1374 (WPS_CONFIG_DISPLAY | WPS_CONFIG_VIRT_DISPLAY |
1375 WPS_CONFIG_PHY_DISPLAY)) == WPS_CONFIG_DISPLAY) {
1376 wpa_printf(MSG_INFO, "WPS: Converting display to "
1377 "virtual_display for WPS 2.0 compliance");
1378 config_methods |= WPS_CONFIG_VIRT_DISPLAY;
1380 if ((config_methods &
1381 (WPS_CONFIG_PUSHBUTTON | WPS_CONFIG_VIRT_PUSHBUTTON |
1382 WPS_CONFIG_PHY_PUSHBUTTON)) == WPS_CONFIG_PUSHBUTTON) {
1383 wpa_printf(MSG_INFO, "WPS: Converting push_button to "
1384 "virtual_push_button for WPS 2.0 compliance");
1385 config_methods |= WPS_CONFIG_VIRT_PUSHBUTTON;
1388 return config_methods;
1392 static void wpas_wps_set_uuid(struct wpa_supplicant *wpa_s,
1393 struct wps_context *wps)
1398 if (is_nil_uuid(wpa_s->conf->uuid)) {
1399 struct wpa_supplicant *first;
1400 first = wpa_s->global->ifaces;
1401 while (first && first->next)
1402 first = first->next;
1403 if (first && first != wpa_s) {
1404 if (wps != wpa_s->global->ifaces->wps)
1405 os_memcpy(wps->uuid,
1406 wpa_s->global->ifaces->wps->uuid,
1408 src = "from the first interface";
1410 uuid_gen_mac_addr(wpa_s->own_addr, wps->uuid);
1411 src = "based on MAC address";
1414 os_memcpy(wps->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
1415 src = "based on configuration";
1418 uuid_bin2str(wps->uuid, buf, sizeof(buf));
1419 wpa_dbg(wpa_s, MSG_DEBUG, "WPS: UUID %s: %s", src, buf);
1423 static void wpas_wps_set_vendor_ext_m1(struct wpa_supplicant *wpa_s,
1424 struct wps_context *wps)
1426 wpabuf_free(wps->dev.vendor_ext_m1);
1427 wps->dev.vendor_ext_m1 = NULL;
1429 if (wpa_s->conf->wps_vendor_ext_m1) {
1430 wps->dev.vendor_ext_m1 =
1431 wpabuf_dup(wpa_s->conf->wps_vendor_ext_m1);
1432 if (!wps->dev.vendor_ext_m1) {
1433 wpa_printf(MSG_ERROR, "WPS: Cannot "
1434 "allocate memory for vendor_ext_m1");
1440 int wpas_wps_init(struct wpa_supplicant *wpa_s)
1442 struct wps_context *wps;
1443 struct wps_registrar_config rcfg;
1444 struct hostapd_hw_modes *modes;
1447 wps = os_zalloc(sizeof(*wps));
1451 wps->cred_cb = wpa_supplicant_wps_cred;
1452 wps->event_cb = wpa_supplicant_wps_event;
1453 wps->rf_band_cb = wpa_supplicant_wps_rf_band;
1454 wps->cb_ctx = wpa_s;
1456 wps->dev.device_name = wpa_s->conf->device_name;
1457 wps->dev.manufacturer = wpa_s->conf->manufacturer;
1458 wps->dev.model_name = wpa_s->conf->model_name;
1459 wps->dev.model_number = wpa_s->conf->model_number;
1460 wps->dev.serial_number = wpa_s->conf->serial_number;
1461 wps->config_methods =
1462 wps_config_methods_str2bin(wpa_s->conf->config_methods);
1463 if ((wps->config_methods & (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) ==
1464 (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) {
1465 wpa_printf(MSG_ERROR, "WPS: Both Label and Display config "
1466 "methods are not allowed at the same time");
1470 wps->config_methods = wps_fix_config_methods(wps->config_methods);
1471 wps->dev.config_methods = wps->config_methods;
1472 os_memcpy(wps->dev.pri_dev_type, wpa_s->conf->device_type,
1475 wps->dev.num_sec_dev_types = wpa_s->conf->num_sec_device_types;
1476 os_memcpy(wps->dev.sec_dev_type, wpa_s->conf->sec_device_type,
1477 WPS_DEV_TYPE_LEN * wps->dev.num_sec_dev_types);
1479 wpas_wps_set_vendor_ext_m1(wpa_s, wps);
1481 wps->dev.os_version = WPA_GET_BE32(wpa_s->conf->os_version);
1482 modes = wpa_s->hw.modes;
1484 for (m = 0; m < wpa_s->hw.num_modes; m++) {
1485 if (modes[m].mode == HOSTAPD_MODE_IEEE80211B ||
1486 modes[m].mode == HOSTAPD_MODE_IEEE80211G)
1487 wps->dev.rf_bands |= WPS_RF_24GHZ;
1488 else if (modes[m].mode == HOSTAPD_MODE_IEEE80211A)
1489 wps->dev.rf_bands |= WPS_RF_50GHZ;
1492 if (wps->dev.rf_bands == 0) {
1494 * Default to claiming support for both bands if the driver
1495 * does not provide support for fetching supported bands.
1497 wps->dev.rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ;
1499 os_memcpy(wps->dev.mac_addr, wpa_s->own_addr, ETH_ALEN);
1500 wpas_wps_set_uuid(wpa_s, wps);
1502 wps->auth_types = WPS_AUTH_WPA2PSK | WPS_AUTH_WPAPSK;
1503 wps->encr_types = WPS_ENCR_AES | WPS_ENCR_TKIP;
1505 os_memset(&rcfg, 0, sizeof(rcfg));
1506 rcfg.new_psk_cb = wpas_wps_new_psk_cb;
1507 rcfg.pin_needed_cb = wpas_wps_pin_needed_cb;
1508 rcfg.set_sel_reg_cb = wpas_wps_set_sel_reg_cb;
1509 rcfg.cb_ctx = wpa_s;
1511 wps->registrar = wps_registrar_init(wps, &rcfg);
1512 if (wps->registrar == NULL) {
1513 wpa_printf(MSG_DEBUG, "Failed to initialize WPS Registrar");
1524 #ifdef CONFIG_WPS_ER
1525 static void wpas_wps_nfc_clear(struct wps_context *wps)
1527 wps->ap_nfc_dev_pw_id = 0;
1528 wpabuf_free(wps->ap_nfc_dh_pubkey);
1529 wps->ap_nfc_dh_pubkey = NULL;
1530 wpabuf_free(wps->ap_nfc_dh_privkey);
1531 wps->ap_nfc_dh_privkey = NULL;
1532 wpabuf_free(wps->ap_nfc_dev_pw);
1533 wps->ap_nfc_dev_pw = NULL;
1535 #endif /* CONFIG_WPS_ER */
1538 void wpas_wps_deinit(struct wpa_supplicant *wpa_s)
1540 wpas_wps_assoc_with_cred_cancel(wpa_s);
1541 eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
1542 eloop_cancel_timeout(wpas_wps_clear_timeout, wpa_s, NULL);
1543 eloop_cancel_timeout(wpas_wps_reenable_networks_cb, wpa_s, NULL);
1544 wpas_wps_clear_ap_info(wpa_s);
1547 eloop_cancel_timeout(wpas_p2p_pbc_overlap_cb, wpa_s, NULL);
1548 #endif /* CONFIG_P2P */
1550 if (wpa_s->wps == NULL)
1553 #ifdef CONFIG_WPS_ER
1554 wps_er_deinit(wpa_s->wps_er, NULL, NULL);
1555 wpa_s->wps_er = NULL;
1556 wpas_wps_nfc_clear(wpa_s->wps);
1557 #endif /* CONFIG_WPS_ER */
1559 wps_registrar_deinit(wpa_s->wps->registrar);
1560 wpabuf_free(wpa_s->wps->dh_pubkey);
1561 wpabuf_free(wpa_s->wps->dh_privkey);
1562 wpabuf_free(wpa_s->wps->dev.vendor_ext_m1);
1563 os_free(wpa_s->wps->network_key);
1564 os_free(wpa_s->wps);
1569 int wpas_wps_ssid_bss_match(struct wpa_supplicant *wpa_s,
1570 struct wpa_ssid *ssid, struct wpa_bss *bss)
1572 struct wpabuf *wps_ie;
1574 if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS))
1577 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1578 if (eap_is_wps_pbc_enrollee(&ssid->eap)) {
1580 wpa_printf(MSG_DEBUG, " skip - non-WPS AP");
1584 if (!wps_is_selected_pbc_registrar(wps_ie)) {
1585 wpa_printf(MSG_DEBUG, " skip - WPS AP "
1586 "without active PBC Registrar");
1587 wpabuf_free(wps_ie);
1591 /* TODO: overlap detection */
1592 wpa_printf(MSG_DEBUG, " selected based on WPS IE "
1594 wpabuf_free(wps_ie);
1598 if (eap_is_wps_pin_enrollee(&ssid->eap)) {
1600 wpa_printf(MSG_DEBUG, " skip - non-WPS AP");
1605 * Start with WPS APs that advertise our address as an
1606 * authorized MAC (v2.0) or active PIN Registrar (v1.0) and
1607 * allow any WPS AP after couple of scans since some APs do not
1608 * set Selected Registrar attribute properly when using
1609 * external Registrar.
1611 if (!wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1)) {
1612 if (wpa_s->scan_runs < WPS_PIN_SCAN_IGNORE_SEL_REG) {
1613 wpa_printf(MSG_DEBUG, " skip - WPS AP "
1614 "without active PIN Registrar");
1615 wpabuf_free(wps_ie);
1618 wpa_printf(MSG_DEBUG, " selected based on WPS IE");
1620 wpa_printf(MSG_DEBUG, " selected based on WPS IE "
1621 "(Authorized MAC or Active PIN)");
1623 wpabuf_free(wps_ie);
1628 wpa_printf(MSG_DEBUG, " selected based on WPS IE");
1629 wpabuf_free(wps_ie);
1637 int wpas_wps_ssid_wildcard_ok(struct wpa_supplicant *wpa_s,
1638 struct wpa_ssid *ssid,
1639 struct wpa_bss *bss)
1641 struct wpabuf *wps_ie = NULL;
1644 if (eap_is_wps_pbc_enrollee(&ssid->eap)) {
1645 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1646 if (wps_ie && wps_is_selected_pbc_registrar(wps_ie)) {
1647 /* allow wildcard SSID for WPS PBC */
1650 } else if (eap_is_wps_pin_enrollee(&ssid->eap)) {
1651 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1653 (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1) ||
1654 wpa_s->scan_runs >= WPS_PIN_SCAN_IGNORE_SEL_REG)) {
1655 /* allow wildcard SSID for WPS PIN */
1660 if (!ret && ssid->bssid_set &&
1661 os_memcmp(ssid->bssid, bss->bssid, ETH_ALEN) == 0) {
1662 /* allow wildcard SSID due to hardcoded BSSID match */
1666 #ifdef CONFIG_WPS_STRICT
1668 if (wps_validate_beacon_probe_resp(wps_ie, bss->beacon_ie_len >
1671 if (bss->beacon_ie_len) {
1672 struct wpabuf *bcn_wps;
1673 bcn_wps = wpa_bss_get_vendor_ie_multi_beacon(
1674 bss, WPS_IE_VENDOR_TYPE);
1675 if (bcn_wps == NULL) {
1676 wpa_printf(MSG_DEBUG, "WPS: Mandatory WPS IE "
1677 "missing from AP Beacon");
1680 if (wps_validate_beacon(wps_ie) < 0)
1682 wpabuf_free(bcn_wps);
1686 #endif /* CONFIG_WPS_STRICT */
1688 wpabuf_free(wps_ie);
1694 int wpas_wps_scan_pbc_overlap(struct wpa_supplicant *wpa_s,
1695 struct wpa_bss *selected, struct wpa_ssid *ssid)
1697 const u8 *sel_uuid, *uuid;
1698 struct wpabuf *wps_ie;
1700 struct wpa_bss *bss;
1702 if (!eap_is_wps_pbc_enrollee(&ssid->eap))
1705 wpa_printf(MSG_DEBUG, "WPS: Check whether PBC session overlap is "
1706 "present in scan results; selected BSSID " MACSTR,
1707 MAC2STR(selected->bssid));
1709 /* Make sure that only one AP is in active PBC mode */
1710 wps_ie = wpa_bss_get_vendor_ie_multi(selected, WPS_IE_VENDOR_TYPE);
1712 sel_uuid = wps_get_uuid_e(wps_ie);
1713 wpa_hexdump(MSG_DEBUG, "WPS: UUID of the selected BSS",
1714 sel_uuid, UUID_LEN);
1716 wpa_printf(MSG_DEBUG, "WPS: Selected BSS does not include "
1721 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1723 if (bss == selected)
1725 ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1728 if (!wps_is_selected_pbc_registrar(ie)) {
1732 wpa_printf(MSG_DEBUG, "WPS: Another BSS in active PBC mode: "
1733 MACSTR, MAC2STR(bss->bssid));
1734 uuid = wps_get_uuid_e(ie);
1735 wpa_hexdump(MSG_DEBUG, "WPS: UUID of the other BSS",
1737 if (os_memcmp(selected->bssid, bss->bssid, ETH_ALEN) == 0) {
1741 if (sel_uuid == NULL || uuid == NULL ||
1742 os_memcmp(sel_uuid, uuid, UUID_LEN) != 0) {
1743 ret = 1; /* PBC overlap */
1744 wpa_msg(wpa_s, MSG_INFO, "WPS: PBC overlap detected: "
1745 MACSTR " and " MACSTR,
1746 MAC2STR(selected->bssid),
1747 MAC2STR(bss->bssid));
1752 /* TODO: verify that this is reasonable dual-band situation */
1757 wpabuf_free(wps_ie);
1763 void wpas_wps_notify_scan_results(struct wpa_supplicant *wpa_s)
1765 struct wpa_bss *bss;
1766 unsigned int pbc = 0, auth = 0, pin = 0, wps = 0;
1768 if (wpa_s->disconnected || wpa_s->wpa_state >= WPA_ASSOCIATED)
1771 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1773 ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1776 if (wps_is_selected_pbc_registrar(ie))
1778 else if (wps_is_addr_authorized(ie, wpa_s->own_addr, 0))
1780 else if (wps_is_selected_pin_registrar(ie))
1788 wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PBC);
1790 wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_AUTH);
1792 wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PIN);
1794 wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE);
1798 int wpas_wps_searching(struct wpa_supplicant *wpa_s)
1800 struct wpa_ssid *ssid;
1802 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1803 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && !ssid->disabled)
1811 int wpas_wps_scan_result_text(const u8 *ies, size_t ies_len, char *buf,
1814 struct wpabuf *wps_ie;
1817 wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len, WPS_DEV_OUI_WFA);
1821 ret = wps_attr_text(wps_ie, buf, end);
1822 wpabuf_free(wps_ie);
1827 int wpas_wps_er_start(struct wpa_supplicant *wpa_s, const char *filter)
1829 #ifdef CONFIG_WPS_ER
1830 if (wpa_s->wps_er) {
1831 wps_er_refresh(wpa_s->wps_er);
1834 wpa_s->wps_er = wps_er_init(wpa_s->wps, wpa_s->ifname, filter);
1835 if (wpa_s->wps_er == NULL)
1838 #else /* CONFIG_WPS_ER */
1840 #endif /* CONFIG_WPS_ER */
1844 void wpas_wps_er_stop(struct wpa_supplicant *wpa_s)
1846 #ifdef CONFIG_WPS_ER
1847 wps_er_deinit(wpa_s->wps_er, NULL, NULL);
1848 wpa_s->wps_er = NULL;
1849 #endif /* CONFIG_WPS_ER */
1853 #ifdef CONFIG_WPS_ER
1854 int wpas_wps_er_add_pin(struct wpa_supplicant *wpa_s, const u8 *addr,
1855 const char *uuid, const char *pin)
1858 const u8 *use_uuid = NULL;
1859 u8 addr_buf[ETH_ALEN];
1861 if (os_strcmp(uuid, "any") == 0) {
1862 } else if (uuid_str2bin(uuid, u) == 0) {
1864 } else if (hwaddr_aton(uuid, addr_buf) == 0) {
1865 use_uuid = wps_er_get_sta_uuid(wpa_s->wps_er, addr_buf);
1866 if (use_uuid == NULL)
1870 return wps_registrar_add_pin(wpa_s->wps->registrar, addr,
1872 (const u8 *) pin, os_strlen(pin), 300);
1876 int wpas_wps_er_pbc(struct wpa_supplicant *wpa_s, const char *uuid)
1878 u8 u[UUID_LEN], *use_uuid = NULL;
1879 u8 addr[ETH_ALEN], *use_addr = NULL;
1881 if (uuid_str2bin(uuid, u) == 0)
1883 else if (hwaddr_aton(uuid, addr) == 0)
1887 return wps_er_pbc(wpa_s->wps_er, use_uuid, use_addr);
1891 int wpas_wps_er_learn(struct wpa_supplicant *wpa_s, const char *uuid,
1894 u8 u[UUID_LEN], *use_uuid = NULL;
1895 u8 addr[ETH_ALEN], *use_addr = NULL;
1897 if (uuid_str2bin(uuid, u) == 0)
1899 else if (hwaddr_aton(uuid, addr) == 0)
1904 return wps_er_learn(wpa_s->wps_er, use_uuid, use_addr, (const u8 *) pin,
1909 static int wpas_wps_network_to_cred(struct wpa_ssid *ssid,
1910 struct wps_credential *cred)
1912 os_memset(cred, 0, sizeof(*cred));
1913 if (ssid->ssid_len > SSID_MAX_LEN)
1915 os_memcpy(cred->ssid, ssid->ssid, ssid->ssid_len);
1916 cred->ssid_len = ssid->ssid_len;
1917 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) {
1918 cred->auth_type = (ssid->proto & WPA_PROTO_RSN) ?
1919 WPS_AUTH_WPA2PSK : WPS_AUTH_WPAPSK;
1920 if (ssid->pairwise_cipher & WPA_CIPHER_CCMP)
1921 cred->encr_type = WPS_ENCR_AES;
1923 cred->encr_type = WPS_ENCR_TKIP;
1924 if (ssid->passphrase) {
1925 cred->key_len = os_strlen(ssid->passphrase);
1926 if (cred->key_len >= 64)
1928 os_memcpy(cred->key, ssid->passphrase, cred->key_len);
1929 } else if (ssid->psk_set) {
1931 os_memcpy(cred->key, ssid->psk, 32);
1935 cred->auth_type = WPS_AUTH_OPEN;
1936 cred->encr_type = WPS_ENCR_NONE;
1943 int wpas_wps_er_set_config(struct wpa_supplicant *wpa_s, const char *uuid,
1946 u8 u[UUID_LEN], *use_uuid = NULL;
1947 u8 addr[ETH_ALEN], *use_addr = NULL;
1948 struct wpa_ssid *ssid;
1949 struct wps_credential cred;
1952 if (uuid_str2bin(uuid, u) == 0)
1954 else if (hwaddr_aton(uuid, addr) == 0)
1958 ssid = wpa_config_get_network(wpa_s->conf, id);
1959 if (ssid == NULL || ssid->ssid == NULL)
1962 if (wpas_wps_network_to_cred(ssid, &cred) < 0)
1964 ret = wps_er_set_config(wpa_s->wps_er, use_uuid, use_addr, &cred);
1965 os_memset(&cred, 0, sizeof(cred));
1970 int wpas_wps_er_config(struct wpa_supplicant *wpa_s, const char *uuid,
1971 const char *pin, struct wps_new_ap_settings *settings)
1973 u8 u[UUID_LEN], *use_uuid = NULL;
1974 u8 addr[ETH_ALEN], *use_addr = NULL;
1975 struct wps_credential cred;
1978 if (uuid_str2bin(uuid, u) == 0)
1980 else if (hwaddr_aton(uuid, addr) == 0)
1984 if (settings->ssid_hex == NULL || settings->auth == NULL ||
1985 settings->encr == NULL || settings->key_hex == NULL)
1988 os_memset(&cred, 0, sizeof(cred));
1989 len = os_strlen(settings->ssid_hex);
1990 if ((len & 1) || len > 2 * sizeof(cred.ssid) ||
1991 hexstr2bin(settings->ssid_hex, cred.ssid, len / 2))
1993 cred.ssid_len = len / 2;
1995 len = os_strlen(settings->key_hex);
1996 if ((len & 1) || len > 2 * sizeof(cred.key) ||
1997 hexstr2bin(settings->key_hex, cred.key, len / 2))
1999 cred.key_len = len / 2;
2001 if (os_strcmp(settings->auth, "OPEN") == 0)
2002 cred.auth_type = WPS_AUTH_OPEN;
2003 else if (os_strcmp(settings->auth, "WPAPSK") == 0)
2004 cred.auth_type = WPS_AUTH_WPAPSK;
2005 else if (os_strcmp(settings->auth, "WPA2PSK") == 0)
2006 cred.auth_type = WPS_AUTH_WPA2PSK;
2010 if (os_strcmp(settings->encr, "NONE") == 0)
2011 cred.encr_type = WPS_ENCR_NONE;
2012 #ifdef CONFIG_TESTING_OPTIONS
2013 else if (os_strcmp(settings->encr, "WEP") == 0)
2014 cred.encr_type = WPS_ENCR_WEP;
2015 #endif /* CONFIG_TESTING_OPTIONS */
2016 else if (os_strcmp(settings->encr, "TKIP") == 0)
2017 cred.encr_type = WPS_ENCR_TKIP;
2018 else if (os_strcmp(settings->encr, "CCMP") == 0)
2019 cred.encr_type = WPS_ENCR_AES;
2023 return wps_er_config(wpa_s->wps_er, use_uuid, use_addr,
2024 (const u8 *) pin, os_strlen(pin), &cred);
2028 #ifdef CONFIG_WPS_NFC
2029 struct wpabuf * wpas_wps_er_nfc_config_token(struct wpa_supplicant *wpa_s,
2030 int ndef, const char *uuid)
2033 u8 u[UUID_LEN], *use_uuid = NULL;
2034 u8 addr[ETH_ALEN], *use_addr = NULL;
2039 if (uuid_str2bin(uuid, u) == 0)
2041 else if (hwaddr_aton(uuid, addr) == 0)
2046 ret = wps_er_nfc_config_token(wpa_s->wps_er, use_uuid, use_addr);
2049 tmp = ndef_build_wifi(ret);
2058 #endif /* CONFIG_WPS_NFC */
2061 static int callbacks_pending = 0;
2063 static void wpas_wps_terminate_cb(void *ctx)
2065 wpa_printf(MSG_DEBUG, "WPS ER: Terminated");
2066 if (--callbacks_pending <= 0)
2069 #endif /* CONFIG_WPS_ER */
2072 int wpas_wps_terminate_pending(struct wpa_supplicant *wpa_s)
2074 #ifdef CONFIG_WPS_ER
2075 if (wpa_s->wps_er) {
2076 callbacks_pending++;
2077 wps_er_deinit(wpa_s->wps_er, wpas_wps_terminate_cb, wpa_s);
2078 wpa_s->wps_er = NULL;
2081 #endif /* CONFIG_WPS_ER */
2086 void wpas_wps_update_config(struct wpa_supplicant *wpa_s)
2088 struct wps_context *wps = wpa_s->wps;
2093 if (wpa_s->conf->changed_parameters & CFG_CHANGED_CONFIG_METHODS) {
2094 wps->config_methods = wps_config_methods_str2bin(
2095 wpa_s->conf->config_methods);
2096 if ((wps->config_methods &
2097 (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) ==
2098 (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) {
2099 wpa_printf(MSG_ERROR, "WPS: Both Label and Display "
2100 "config methods are not allowed at the "
2102 wps->config_methods &= ~WPS_CONFIG_LABEL;
2105 wps->config_methods = wps_fix_config_methods(wps->config_methods);
2106 wps->dev.config_methods = wps->config_methods;
2108 if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_TYPE)
2109 os_memcpy(wps->dev.pri_dev_type, wpa_s->conf->device_type,
2112 if (wpa_s->conf->changed_parameters & CFG_CHANGED_SEC_DEVICE_TYPE) {
2113 wps->dev.num_sec_dev_types = wpa_s->conf->num_sec_device_types;
2114 os_memcpy(wps->dev.sec_dev_type, wpa_s->conf->sec_device_type,
2115 wps->dev.num_sec_dev_types * WPS_DEV_TYPE_LEN);
2118 if (wpa_s->conf->changed_parameters & CFG_CHANGED_VENDOR_EXTENSION)
2119 wpas_wps_set_vendor_ext_m1(wpa_s, wps);
2121 if (wpa_s->conf->changed_parameters & CFG_CHANGED_OS_VERSION)
2122 wps->dev.os_version = WPA_GET_BE32(wpa_s->conf->os_version);
2124 if (wpa_s->conf->changed_parameters & CFG_CHANGED_UUID)
2125 wpas_wps_set_uuid(wpa_s, wps);
2127 if (wpa_s->conf->changed_parameters &
2128 (CFG_CHANGED_DEVICE_NAME | CFG_CHANGED_WPS_STRING)) {
2129 /* Update pointers to make sure they refer current values */
2130 wps->dev.device_name = wpa_s->conf->device_name;
2131 wps->dev.manufacturer = wpa_s->conf->manufacturer;
2132 wps->dev.model_name = wpa_s->conf->model_name;
2133 wps->dev.model_number = wpa_s->conf->model_number;
2134 wps->dev.serial_number = wpa_s->conf->serial_number;
2139 #ifdef CONFIG_WPS_NFC
2141 #ifdef CONFIG_WPS_ER
2142 static struct wpabuf *
2143 wpas_wps_network_config_token(struct wpa_supplicant *wpa_s, int ndef,
2144 struct wpa_ssid *ssid)
2147 struct wps_credential cred;
2149 if (wpas_wps_network_to_cred(ssid, &cred) < 0)
2152 ret = wps_er_config_token_from_cred(wpa_s->wps, &cred);
2156 tmp = ndef_build_wifi(ret);
2165 #endif /* CONFIG_WPS_ER */
2168 struct wpabuf * wpas_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
2169 int ndef, const char *id_str)
2171 #ifdef CONFIG_WPS_ER
2175 struct wpa_ssid *ssid;
2177 id = strtol(id_str, &end, 10);
2181 ssid = wpa_config_get_network(wpa_s->conf, id);
2184 return wpas_wps_network_config_token(wpa_s, ndef, ssid);
2186 #endif /* CONFIG_WPS_ER */
2188 if (wpa_s->ap_iface)
2189 return wpas_ap_wps_nfc_config_token(wpa_s, ndef);
2190 #endif /* CONFIG_AP */
2195 struct wpabuf * wpas_wps_nfc_token(struct wpa_supplicant *wpa_s, int ndef)
2197 if (wpa_s->conf->wps_nfc_pw_from_config) {
2198 return wps_nfc_token_build(ndef,
2199 wpa_s->conf->wps_nfc_dev_pw_id,
2200 wpa_s->conf->wps_nfc_dh_pubkey,
2201 wpa_s->conf->wps_nfc_dev_pw);
2204 return wps_nfc_token_gen(ndef, &wpa_s->conf->wps_nfc_dev_pw_id,
2205 &wpa_s->conf->wps_nfc_dh_pubkey,
2206 &wpa_s->conf->wps_nfc_dh_privkey,
2207 &wpa_s->conf->wps_nfc_dev_pw);
2211 int wpas_wps_start_nfc(struct wpa_supplicant *wpa_s, const u8 *go_dev_addr,
2213 const struct wpabuf *dev_pw, u16 dev_pw_id,
2214 int p2p_group, const u8 *peer_pubkey_hash,
2215 const u8 *ssid, size_t ssid_len, int freq)
2217 struct wps_context *wps = wpa_s->wps;
2218 char pw[32 * 2 + 1];
2220 if (dev_pw_id != DEV_PW_NFC_CONNECTION_HANDOVER && dev_pw == NULL) {
2221 dev_pw = wpa_s->conf->wps_nfc_dev_pw;
2222 dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id;
2225 if (wpa_s->conf->wps_nfc_dh_pubkey == NULL ||
2226 wpa_s->conf->wps_nfc_dh_privkey == NULL) {
2227 wpa_printf(MSG_DEBUG, "WPS: Missing DH params - "
2228 "cannot start NFC-triggered connection");
2232 if (dev_pw_id != DEV_PW_NFC_CONNECTION_HANDOVER && dev_pw == NULL) {
2233 wpa_printf(MSG_DEBUG, "WPS: Missing Device Password (id=%u) - "
2234 "cannot start NFC-triggered connection", dev_pw_id);
2238 dh5_free(wps->dh_ctx);
2239 wpabuf_free(wps->dh_pubkey);
2240 wpabuf_free(wps->dh_privkey);
2241 wps->dh_privkey = wpabuf_dup(wpa_s->conf->wps_nfc_dh_privkey);
2242 wps->dh_pubkey = wpabuf_dup(wpa_s->conf->wps_nfc_dh_pubkey);
2243 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
2245 wpabuf_free(wps->dh_pubkey);
2246 wps->dh_pubkey = NULL;
2247 wpabuf_free(wps->dh_privkey);
2248 wps->dh_privkey = NULL;
2249 wpa_printf(MSG_DEBUG, "WPS: Failed to get DH priv/pub key");
2252 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
2253 if (wps->dh_ctx == NULL) {
2254 wpabuf_free(wps->dh_pubkey);
2255 wps->dh_pubkey = NULL;
2256 wpabuf_free(wps->dh_privkey);
2257 wps->dh_privkey = NULL;
2258 wpa_printf(MSG_DEBUG, "WPS: Failed to initialize DH context");
2263 wpa_snprintf_hex_uppercase(pw, sizeof(pw),
2264 wpabuf_head(dev_pw),
2265 wpabuf_len(dev_pw));
2267 return wpas_wps_start_dev_pw(wpa_s, go_dev_addr, bssid,
2269 p2p_group, dev_pw_id, peer_pubkey_hash,
2270 ssid, ssid_len, freq);
2274 static int wpas_wps_use_cred(struct wpa_supplicant *wpa_s,
2275 struct wps_parse_attr *attr)
2278 * Disable existing networks temporarily to allow the newly learned
2279 * credential to be preferred. Enable the temporarily disabled networks
2282 wpas_wps_temp_disable(wpa_s, NULL);
2283 eloop_register_timeout(10, 0, wpas_wps_reenable_networks_cb, wpa_s,
2286 if (wps_oob_use_cred(wpa_s->wps, attr) < 0)
2289 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2292 if (attr->ap_channel) {
2293 u16 chan = WPA_GET_BE16(attr->ap_channel);
2296 if (chan >= 1 && chan <= 13)
2297 freq = 2407 + 5 * chan;
2298 else if (chan == 14)
2300 else if (chan >= 30)
2301 freq = 5000 + 5 * chan;
2304 wpa_printf(MSG_DEBUG, "WPS: Credential container indicated AP channel %u -> %u MHz",
2306 wpa_s->after_wps = 5;
2307 wpa_s->wps_freq = freq;
2311 wpa_printf(MSG_DEBUG, "WPS: Request reconnection with new network "
2312 "based on the received credential added");
2313 wpa_s->normal_scans = 0;
2314 wpa_supplicant_reinit_autoscan(wpa_s);
2315 wpa_s->disconnected = 0;
2316 wpa_s->reassociate = 1;
2318 wpa_supplicant_cancel_sched_scan(wpa_s);
2319 wpa_supplicant_req_scan(wpa_s, 0, 0);
2325 #ifdef CONFIG_WPS_ER
2326 static int wpas_wps_add_nfc_password_token(struct wpa_supplicant *wpa_s,
2327 struct wps_parse_attr *attr)
2329 return wps_registrar_add_nfc_password_token(
2330 wpa_s->wps->registrar, attr->oob_dev_password,
2331 attr->oob_dev_password_len);
2333 #endif /* CONFIG_WPS_ER */
2336 static int wpas_wps_nfc_tag_process(struct wpa_supplicant *wpa_s,
2337 const struct wpabuf *wps)
2339 struct wps_parse_attr attr;
2341 wpa_hexdump_buf(MSG_DEBUG, "WPS: Received NFC tag payload", wps);
2343 if (wps_parse_msg(wps, &attr)) {
2344 wpa_printf(MSG_DEBUG, "WPS: Ignore invalid data from NFC tag");
2349 return wpas_wps_use_cred(wpa_s, &attr);
2351 #ifdef CONFIG_WPS_ER
2352 if (attr.oob_dev_password)
2353 return wpas_wps_add_nfc_password_token(wpa_s, &attr);
2354 #endif /* CONFIG_WPS_ER */
2356 wpa_printf(MSG_DEBUG, "WPS: Ignore unrecognized NFC tag");
2361 int wpas_wps_nfc_tag_read(struct wpa_supplicant *wpa_s,
2362 const struct wpabuf *data, int forced_freq)
2364 const struct wpabuf *wps = data;
2365 struct wpabuf *tmp = NULL;
2368 if (wpabuf_len(data) < 4)
2371 if (*wpabuf_head_u8(data) != 0x10) {
2372 /* Assume this contains full NDEF record */
2373 tmp = ndef_parse_wifi(data);
2376 tmp = ndef_parse_p2p(data);
2378 ret = wpas_p2p_nfc_tag_process(wpa_s, tmp,
2383 #endif /* CONFIG_P2P */
2384 wpa_printf(MSG_DEBUG, "WPS: Could not parse NDEF");
2390 ret = wpas_wps_nfc_tag_process(wpa_s, wps);
2396 struct wpabuf * wpas_wps_nfc_handover_req(struct wpa_supplicant *wpa_s,
2401 if (wpa_s->conf->wps_nfc_dh_pubkey == NULL &&
2402 wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey,
2403 &wpa_s->conf->wps_nfc_dh_privkey) < 0)
2406 ret = wps_build_nfc_handover_req(wpa_s->wps,
2407 wpa_s->conf->wps_nfc_dh_pubkey);
2411 tmp = ndef_build_wifi(ret);
2422 #ifdef CONFIG_WPS_NFC
2424 static struct wpabuf *
2425 wpas_wps_er_nfc_handover_sel(struct wpa_supplicant *wpa_s, int ndef,
2428 #ifdef CONFIG_WPS_ER
2430 u8 u[UUID_LEN], *use_uuid = NULL;
2431 u8 addr[ETH_ALEN], *use_addr = NULL;
2432 struct wps_context *wps = wpa_s->wps;
2439 if (uuid_str2bin(uuid, u) == 0)
2441 else if (hwaddr_aton(uuid, addr) == 0)
2446 if (wpa_s->conf->wps_nfc_dh_pubkey == NULL) {
2447 if (wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey,
2448 &wpa_s->conf->wps_nfc_dh_privkey) < 0)
2452 wpas_wps_nfc_clear(wps);
2453 wps->ap_nfc_dev_pw_id = DEV_PW_NFC_CONNECTION_HANDOVER;
2454 wps->ap_nfc_dh_pubkey = wpabuf_dup(wpa_s->conf->wps_nfc_dh_pubkey);
2455 wps->ap_nfc_dh_privkey = wpabuf_dup(wpa_s->conf->wps_nfc_dh_privkey);
2456 if (!wps->ap_nfc_dh_pubkey || !wps->ap_nfc_dh_privkey) {
2457 wpas_wps_nfc_clear(wps);
2461 ret = wps_er_nfc_handover_sel(wpa_s->wps_er, wpa_s->wps, use_uuid,
2462 use_addr, wpa_s->conf->wps_nfc_dh_pubkey);
2465 tmp = ndef_build_wifi(ret);
2473 #else /* CONFIG_WPS_ER */
2475 #endif /* CONFIG_WPS_ER */
2477 #endif /* CONFIG_WPS_NFC */
2480 struct wpabuf * wpas_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
2481 int ndef, int cr, const char *uuid)
2486 ret = wpas_ap_wps_nfc_handover_sel(wpa_s, ndef);
2489 return wpas_wps_er_nfc_handover_sel(wpa_s, ndef, uuid);
2493 static int wpas_wps_nfc_rx_handover_sel(struct wpa_supplicant *wpa_s,
2494 const struct wpabuf *data)
2501 struct wps_parse_attr attr;
2503 const u8 *bssid = NULL;
2506 wps = ndef_parse_wifi(data);
2509 wpa_printf(MSG_DEBUG, "WPS: Received application/vnd.wfa.wsc "
2510 "payload from NFC connection handover");
2511 wpa_hexdump_buf(MSG_DEBUG, "WPS: NFC payload", wps);
2512 if (wpabuf_len(wps) < 2) {
2513 wpa_printf(MSG_DEBUG, "WPS: Too short Wi-Fi Handover Select "
2517 pos = wpabuf_head(wps);
2518 wsc_len = WPA_GET_BE16(pos);
2519 if (wsc_len > wpabuf_len(wps) - 2) {
2520 wpa_printf(MSG_DEBUG, "WPS: Invalid WSC attribute length (%u) "
2521 "in Wi-Fi Handover Select Message", wsc_len);
2526 wpa_hexdump(MSG_DEBUG,
2527 "WPS: WSC attributes in Wi-Fi Handover Select Message",
2529 if (wsc_len < wpabuf_len(wps) - 2) {
2530 wpa_hexdump(MSG_DEBUG,
2531 "WPS: Ignore extra data after WSC attributes",
2532 pos + wsc_len, wpabuf_len(wps) - 2 - wsc_len);
2535 wpabuf_set(&msg, pos, wsc_len);
2536 ret = wps_parse_msg(&msg, &attr);
2538 wpa_printf(MSG_DEBUG, "WPS: Could not parse WSC attributes in "
2539 "Wi-Fi Handover Select Message");
2543 if (attr.oob_dev_password == NULL ||
2544 attr.oob_dev_password_len < WPS_OOB_PUBKEY_HASH_LEN + 2) {
2545 wpa_printf(MSG_DEBUG, "WPS: No Out-of-Band Device Password "
2546 "included in Wi-Fi Handover Select Message");
2551 if (attr.ssid == NULL) {
2552 wpa_printf(MSG_DEBUG, "WPS: No SSID included in Wi-Fi Handover "
2558 wpa_hexdump_ascii(MSG_DEBUG, "WPS: SSID", attr.ssid, attr.ssid_len);
2560 if (attr.mac_addr) {
2561 bssid = attr.mac_addr;
2562 wpa_printf(MSG_DEBUG, "WPS: MAC Address (BSSID): " MACSTR,
2567 wpa_printf(MSG_DEBUG, "WPS: RF Bands: %d", *attr.rf_bands);
2569 if (attr.ap_channel) {
2570 u16 chan = WPA_GET_BE16(attr.ap_channel);
2572 wpa_printf(MSG_DEBUG, "WPS: AP Channel: %d", chan);
2574 if (chan >= 1 && chan <= 13 &&
2575 (attr.rf_bands == NULL || *attr.rf_bands & WPS_RF_24GHZ))
2576 freq = 2407 + 5 * chan;
2577 else if (chan == 14 &&
2578 (attr.rf_bands == NULL ||
2579 *attr.rf_bands & WPS_RF_24GHZ))
2581 else if (chan >= 30 &&
2582 (attr.rf_bands == NULL ||
2583 *attr.rf_bands & WPS_RF_50GHZ))
2584 freq = 5000 + 5 * chan;
2587 wpa_printf(MSG_DEBUG,
2588 "WPS: AP indicated channel %u -> %u MHz",
2593 wpa_hexdump(MSG_DEBUG, "WPS: Out-of-Band Device Password",
2594 attr.oob_dev_password, attr.oob_dev_password_len);
2595 dev_pw_id = WPA_GET_BE16(attr.oob_dev_password +
2596 WPS_OOB_PUBKEY_HASH_LEN);
2597 if (dev_pw_id != DEV_PW_NFC_CONNECTION_HANDOVER) {
2598 wpa_printf(MSG_DEBUG, "WPS: Unexpected OOB Device Password ID "
2599 "%u in Wi-Fi Handover Select Message", dev_pw_id);
2603 wpa_hexdump(MSG_DEBUG, "WPS: AP Public Key hash",
2604 attr.oob_dev_password, WPS_OOB_PUBKEY_HASH_LEN);
2606 ret = wpas_wps_start_nfc(wpa_s, NULL, bssid, NULL, dev_pw_id, 0,
2607 attr.oob_dev_password,
2608 attr.ssid, attr.ssid_len, freq);
2616 int wpas_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
2617 const struct wpabuf *req,
2618 const struct wpabuf *sel)
2620 wpa_printf(MSG_DEBUG, "NFC: WPS connection handover reported");
2621 wpa_hexdump_buf_key(MSG_DEBUG, "WPS: Carrier record in request", req);
2622 wpa_hexdump_buf_key(MSG_DEBUG, "WPS: Carrier record in select", sel);
2623 return wpas_wps_nfc_rx_handover_sel(wpa_s, sel);
2627 int wpas_er_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
2628 const struct wpabuf *req,
2629 const struct wpabuf *sel)
2636 struct wps_parse_attr attr;
2640 * Enrollee/station is always initiator of the NFC connection handover,
2641 * so use the request message here to find Enrollee public key hash.
2643 wps = ndef_parse_wifi(req);
2646 wpa_printf(MSG_DEBUG, "WPS: Received application/vnd.wfa.wsc "
2647 "payload from NFC connection handover");
2648 wpa_hexdump_buf(MSG_DEBUG, "WPS: NFC payload", wps);
2649 if (wpabuf_len(wps) < 2) {
2650 wpa_printf(MSG_DEBUG, "WPS: Too short Wi-Fi Handover Request "
2654 pos = wpabuf_head(wps);
2655 wsc_len = WPA_GET_BE16(pos);
2656 if (wsc_len > wpabuf_len(wps) - 2) {
2657 wpa_printf(MSG_DEBUG, "WPS: Invalid WSC attribute length (%u) "
2658 "in rt Wi-Fi Handover Request Message", wsc_len);
2663 wpa_hexdump(MSG_DEBUG,
2664 "WPS: WSC attributes in Wi-Fi Handover Request Message",
2666 if (wsc_len < wpabuf_len(wps) - 2) {
2667 wpa_hexdump(MSG_DEBUG,
2668 "WPS: Ignore extra data after WSC attributes",
2669 pos + wsc_len, wpabuf_len(wps) - 2 - wsc_len);
2672 wpabuf_set(&msg, pos, wsc_len);
2673 ret = wps_parse_msg(&msg, &attr);
2675 wpa_printf(MSG_DEBUG, "WPS: Could not parse WSC attributes in "
2676 "Wi-Fi Handover Request Message");
2680 if (attr.oob_dev_password == NULL ||
2681 attr.oob_dev_password_len < WPS_OOB_PUBKEY_HASH_LEN + 2) {
2682 wpa_printf(MSG_DEBUG, "WPS: No Out-of-Band Device Password "
2683 "included in Wi-Fi Handover Request Message");
2688 if (attr.uuid_e == NULL) {
2689 wpa_printf(MSG_DEBUG, "WPS: No UUID-E included in Wi-Fi "
2690 "Handover Request Message");
2695 wpa_hexdump(MSG_DEBUG, "WPS: UUID-E", attr.uuid_e, WPS_UUID_LEN);
2697 wpa_hexdump(MSG_DEBUG, "WPS: Out-of-Band Device Password",
2698 attr.oob_dev_password, attr.oob_dev_password_len);
2699 dev_pw_id = WPA_GET_BE16(attr.oob_dev_password +
2700 WPS_OOB_PUBKEY_HASH_LEN);
2701 if (dev_pw_id != DEV_PW_NFC_CONNECTION_HANDOVER) {
2702 wpa_printf(MSG_DEBUG, "WPS: Unexpected OOB Device Password ID "
2703 "%u in Wi-Fi Handover Request Message", dev_pw_id);
2707 wpa_hexdump(MSG_DEBUG, "WPS: Enrollee Public Key hash",
2708 attr.oob_dev_password, WPS_OOB_PUBKEY_HASH_LEN);
2710 ret = wps_registrar_add_nfc_pw_token(wpa_s->wps->registrar,
2711 attr.oob_dev_password,
2712 DEV_PW_NFC_CONNECTION_HANDOVER,
2720 #endif /* CONFIG_WPS_NFC */
2723 static void wpas_wps_dump_ap_info(struct wpa_supplicant *wpa_s)
2726 struct os_reltime now;
2728 if (wpa_debug_level > MSG_DEBUG)
2731 if (wpa_s->wps_ap == NULL)
2734 os_get_reltime(&now);
2736 for (i = 0; i < wpa_s->num_wps_ap; i++) {
2737 struct wps_ap_info *ap = &wpa_s->wps_ap[i];
2738 struct wpa_blacklist *e = wpa_blacklist_get(wpa_s, ap->bssid);
2740 wpa_printf(MSG_DEBUG, "WPS: AP[%d] " MACSTR " type=%d "
2741 "tries=%d last_attempt=%d sec ago blacklist=%d",
2742 (int) i, MAC2STR(ap->bssid), ap->type, ap->tries,
2743 ap->last_attempt.sec > 0 ?
2744 (int) now.sec - (int) ap->last_attempt.sec : -1,
2750 static struct wps_ap_info * wpas_wps_get_ap_info(struct wpa_supplicant *wpa_s,
2755 if (wpa_s->wps_ap == NULL)
2758 for (i = 0; i < wpa_s->num_wps_ap; i++) {
2759 struct wps_ap_info *ap = &wpa_s->wps_ap[i];
2760 if (os_memcmp(ap->bssid, bssid, ETH_ALEN) == 0)
2768 static void wpas_wps_update_ap_info_bss(struct wpa_supplicant *wpa_s,
2769 struct wpa_scan_res *res)
2772 enum wps_ap_info_type type;
2773 struct wps_ap_info *ap;
2776 if (wpa_scan_get_vendor_ie(res, WPS_IE_VENDOR_TYPE) == NULL)
2779 wps = wpa_scan_get_vendor_ie_multi(res, WPS_IE_VENDOR_TYPE);
2783 r = wps_is_addr_authorized(wps, wpa_s->own_addr, 1);
2785 type = WPS_AP_SEL_REG_OUR;
2787 type = WPS_AP_SEL_REG;
2789 type = WPS_AP_NOT_SEL_REG;
2793 ap = wpas_wps_get_ap_info(wpa_s, res->bssid);
2795 if (ap->type != type) {
2796 wpa_printf(MSG_DEBUG, "WPS: AP " MACSTR
2797 " changed type %d -> %d",
2798 MAC2STR(res->bssid), ap->type, type);
2800 if (type != WPS_AP_NOT_SEL_REG)
2801 wpa_blacklist_del(wpa_s, ap->bssid);
2806 ap = os_realloc_array(wpa_s->wps_ap, wpa_s->num_wps_ap + 1,
2807 sizeof(struct wps_ap_info));
2812 ap = &wpa_s->wps_ap[wpa_s->num_wps_ap];
2813 wpa_s->num_wps_ap++;
2815 os_memset(ap, 0, sizeof(*ap));
2816 os_memcpy(ap->bssid, res->bssid, ETH_ALEN);
2818 wpa_printf(MSG_DEBUG, "WPS: AP " MACSTR " type %d added",
2819 MAC2STR(ap->bssid), ap->type);
2823 void wpas_wps_update_ap_info(struct wpa_supplicant *wpa_s,
2824 struct wpa_scan_results *scan_res)
2828 for (i = 0; i < scan_res->num; i++)
2829 wpas_wps_update_ap_info_bss(wpa_s, scan_res->res[i]);
2831 wpas_wps_dump_ap_info(wpa_s);
2835 void wpas_wps_notify_assoc(struct wpa_supplicant *wpa_s, const u8 *bssid)
2837 struct wps_ap_info *ap;
2839 wpa_s->after_wps = 0;
2841 if (!wpa_s->wps_ap_iter)
2843 ap = wpas_wps_get_ap_info(wpa_s, bssid);
2847 os_get_reltime(&ap->last_attempt);