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_supplicant_deauthenticate(wpa_s,
117 WLAN_REASON_DEAUTH_LEAVING);
119 wpa_printf(MSG_DEBUG, "WPS: Current network is "
120 "disabled - wait for user to enable");
123 wpa_s->after_wps = 5;
124 wpa_s->wps_freq = freq;
125 wpa_s->normal_scans = 0;
126 wpa_s->reassociate = 1;
128 wpa_printf(MSG_DEBUG, "WPS: Checking whether fast association "
129 "without a new scan can be used");
130 bss = wpa_supplicant_pick_network(wpa_s, &ssid);
133 struct wps_parse_attr attr;
135 wps = wpa_bss_get_vendor_ie_multi(bss,
137 if (wps && wps_parse_msg(wps, &attr) == 0 &&
139 *attr.wps_state == WPS_STATE_CONFIGURED)
145 * Complete the next step from an eloop timeout to allow pending
146 * driver events related to the disconnection to be processed
147 * first. This makes it less likely for disconnection event to
148 * cause problems with the following connection.
150 wpa_printf(MSG_DEBUG, "WPS: Continue association from timeout");
151 wpas_wps_assoc_with_cred_cancel(wpa_s);
152 eloop_register_timeout(0, 10000,
153 wpas_wps_assoc_with_cred, wpa_s,
154 use_fast_assoc ? (void *) 1 :
159 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && wpa_s->current_ssid) {
160 wpa_printf(MSG_DEBUG, "WPS: Registration completed - waiting "
161 "for external credential processing");
162 wpas_clear_wps(wpa_s);
163 wpa_supplicant_deauthenticate(wpa_s,
164 WLAN_REASON_DEAUTH_LEAVING);
172 static void wpas_wps_security_workaround(struct wpa_supplicant *wpa_s,
173 struct wpa_ssid *ssid,
174 const struct wps_credential *cred)
176 struct wpa_driver_capa capa;
179 struct wpa_ie_data adv;
180 int wpa2 = 0, ccmp = 0;
183 * Many existing WPS APs do not know how to negotiate WPA2 or CCMP in
184 * case they are configured for mixed mode operation (WPA+WPA2 and
185 * TKIP+CCMP). Try to use scan results to figure out whether the AP
186 * actually supports stronger security and select that if the client
187 * has support for it, too.
190 if (wpa_drv_get_capa(wpa_s, &capa))
191 return; /* Unknown what driver supports */
193 if (ssid->ssid == NULL)
195 bss = wpa_bss_get(wpa_s, cred->mac_addr, ssid->ssid, ssid->ssid_len);
197 wpa_printf(MSG_DEBUG, "WPS: The AP was not found from BSS "
198 "table - use credential as-is");
202 wpa_printf(MSG_DEBUG, "WPS: AP found from BSS table");
204 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
205 if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0) {
207 if (adv.pairwise_cipher & WPA_CIPHER_CCMP)
210 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
211 if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0 &&
212 adv.pairwise_cipher & WPA_CIPHER_CCMP)
216 if (ie == NULL && (ssid->proto & WPA_PROTO_WPA) &&
217 (ssid->pairwise_cipher & WPA_CIPHER_TKIP)) {
219 * TODO: This could be the initial AP configuration and the
220 * Beacon contents could change shortly. Should request a new
221 * scan and delay addition of the network until the updated
222 * scan results are available.
224 wpa_printf(MSG_DEBUG, "WPS: The AP did not yet advertise WPA "
225 "support - use credential as-is");
229 if (ccmp && !(ssid->pairwise_cipher & WPA_CIPHER_CCMP) &&
230 (ssid->pairwise_cipher & WPA_CIPHER_TKIP) &&
231 (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
232 wpa_printf(MSG_DEBUG, "WPS: Add CCMP into the credential "
233 "based on scan results");
234 if (wpa_s->conf->ap_scan == 1)
235 ssid->pairwise_cipher |= WPA_CIPHER_CCMP;
237 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
240 if (wpa2 && !(ssid->proto & WPA_PROTO_RSN) &&
241 (ssid->proto & WPA_PROTO_WPA) &&
242 (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP)) {
243 wpa_printf(MSG_DEBUG, "WPS: Add WPA2 into the credential "
244 "based on scan results");
245 if (wpa_s->conf->ap_scan == 1)
246 ssid->proto |= WPA_PROTO_RSN;
248 ssid->proto = WPA_PROTO_RSN;
253 static void wpas_wps_remove_dup_network(struct wpa_supplicant *wpa_s,
254 struct wpa_ssid *new_ssid)
256 struct wpa_ssid *ssid, *next;
258 for (ssid = wpa_s->conf->ssid, next = ssid ? ssid->next : NULL; ssid;
259 ssid = next, next = ssid ? ssid->next : NULL) {
261 * new_ssid has already been added to the list in
262 * wpas_wps_add_network(), so skip it.
264 if (ssid == new_ssid)
267 if (ssid->bssid_set || new_ssid->bssid_set) {
268 if (ssid->bssid_set != new_ssid->bssid_set)
270 if (os_memcmp(ssid->bssid, new_ssid->bssid, ETH_ALEN) !=
276 if (ssid->ssid_len == 0 || ssid->ssid_len != new_ssid->ssid_len)
279 if (ssid->ssid && new_ssid->ssid) {
280 if (os_memcmp(ssid->ssid, new_ssid->ssid,
281 ssid->ssid_len) != 0)
283 } else if (ssid->ssid || new_ssid->ssid)
286 /* compare security parameters */
287 if (ssid->auth_alg != new_ssid->auth_alg ||
288 ssid->key_mgmt != new_ssid->key_mgmt ||
289 (ssid->group_cipher != new_ssid->group_cipher &&
290 !(ssid->group_cipher & new_ssid->group_cipher &
295 * Some existing WPS APs will send two creds in case they are
296 * configured for mixed mode operation (WPA+WPA2 and TKIP+CCMP).
297 * Try to merge these two creds if they are received in the same
300 if (ssid->wps_run && ssid->wps_run == new_ssid->wps_run &&
301 wpa_key_mgmt_wpa_psk(ssid->key_mgmt)) {
302 if (new_ssid->passphrase && ssid->passphrase &&
303 os_strcmp(new_ssid->passphrase, ssid->passphrase) !=
305 wpa_printf(MSG_DEBUG,
306 "WPS: M8 Creds with different passphrase - do not merge");
310 if (new_ssid->psk_set &&
312 os_memcmp(new_ssid->psk, ssid->psk, 32) != 0)) {
313 wpa_printf(MSG_DEBUG,
314 "WPS: M8 Creds with different PSK - do not merge");
318 if ((new_ssid->passphrase && !ssid->passphrase) ||
319 (!new_ssid->passphrase && ssid->passphrase)) {
320 wpa_printf(MSG_DEBUG,
321 "WPS: M8 Creds with different passphrase/PSK type - do not merge");
325 wpa_printf(MSG_DEBUG,
326 "WPS: Workaround - merge likely WPA/WPA2-mixed mode creds in same M8 message");
327 new_ssid->proto |= ssid->proto;
328 new_ssid->pairwise_cipher |= ssid->pairwise_cipher;
331 * proto and pairwise_cipher difference matter for
332 * non-mixed-mode creds.
334 if (ssid->proto != new_ssid->proto ||
335 ssid->pairwise_cipher != new_ssid->pairwise_cipher)
339 /* Remove the duplicated older network entry. */
340 wpa_printf(MSG_DEBUG, "Remove duplicate network %d", ssid->id);
341 wpas_notify_network_removed(wpa_s, ssid);
342 if (wpa_s->current_ssid == ssid)
343 wpa_s->current_ssid = NULL;
344 wpa_config_remove_network(wpa_s->conf, ssid->id);
349 static int wpa_supplicant_wps_cred(void *ctx,
350 const struct wps_credential *cred)
352 struct wpa_supplicant *wpa_s = ctx;
353 struct wpa_ssid *ssid = wpa_s->current_ssid;
355 #ifdef CONFIG_WPS_REG_DISABLE_OPEN
357 #endif /* CONFIG_WPS_REG_DISABLE_OPEN */
359 if ((wpa_s->conf->wps_cred_processing == 1 ||
360 wpa_s->conf->wps_cred_processing == 2) && cred->cred_attr) {
361 size_t blen = cred->cred_attr_len * 2 + 1;
362 char *buf = os_malloc(blen);
364 wpa_snprintf_hex(buf, blen,
365 cred->cred_attr, cred->cred_attr_len);
366 wpa_msg(wpa_s, MSG_INFO, "%s%s",
367 WPS_EVENT_CRED_RECEIVED, buf);
371 wpas_notify_wps_credential(wpa_s, cred);
373 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_CRED_RECEIVED);
375 wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
376 cred->cred_attr, cred->cred_attr_len);
378 if (wpa_s->conf->wps_cred_processing == 1)
381 wpa_hexdump_ascii(MSG_DEBUG, "WPS: SSID", cred->ssid, cred->ssid_len);
382 wpa_printf(MSG_DEBUG, "WPS: Authentication Type 0x%x",
384 wpa_printf(MSG_DEBUG, "WPS: Encryption Type 0x%x", cred->encr_type);
385 wpa_printf(MSG_DEBUG, "WPS: Network Key Index %d", cred->key_idx);
386 wpa_hexdump_key(MSG_DEBUG, "WPS: Network Key",
387 cred->key, cred->key_len);
388 wpa_printf(MSG_DEBUG, "WPS: MAC Address " MACSTR,
389 MAC2STR(cred->mac_addr));
391 auth_type = cred->auth_type;
392 if (auth_type == (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) {
393 wpa_printf(MSG_DEBUG, "WPS: Workaround - convert mixed-mode "
394 "auth_type into WPA2PSK");
395 auth_type = WPS_AUTH_WPA2PSK;
398 if (auth_type != WPS_AUTH_OPEN &&
399 auth_type != WPS_AUTH_WPAPSK &&
400 auth_type != WPS_AUTH_WPA2PSK) {
401 wpa_printf(MSG_DEBUG, "WPS: Ignored credentials for "
402 "unsupported authentication type 0x%x",
407 if (auth_type == WPS_AUTH_WPAPSK || auth_type == WPS_AUTH_WPA2PSK) {
408 if (cred->key_len < 8 || cred->key_len > 2 * PMK_LEN) {
409 wpa_printf(MSG_ERROR, "WPS: Reject PSK credential with "
410 "invalid Network Key length %lu",
411 (unsigned long) cred->key_len);
416 if (ssid && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
417 wpa_printf(MSG_DEBUG, "WPS: Replace WPS network block based "
418 "on the received credential");
419 #ifdef CONFIG_WPS_REG_DISABLE_OPEN
420 if (ssid->eap.identity &&
421 ssid->eap.identity_len == WSC_ID_REGISTRAR_LEN &&
422 os_memcmp(ssid->eap.identity, WSC_ID_REGISTRAR,
423 WSC_ID_REGISTRAR_LEN) == 0)
425 #endif /* CONFIG_WPS_REG_DISABLE_OPEN */
426 os_free(ssid->eap.identity);
427 ssid->eap.identity = NULL;
428 ssid->eap.identity_len = 0;
429 os_free(ssid->eap.phase1);
430 ssid->eap.phase1 = NULL;
431 os_free(ssid->eap.eap_methods);
432 ssid->eap.eap_methods = NULL;
433 if (!ssid->p2p_group) {
437 ssid->disabled_until.sec = 0;
438 ssid->disabled_until.usec = 0;
439 ssid->auth_failures = 0;
441 wpa_printf(MSG_DEBUG, "WPS: Create a new network based on the "
442 "received credential");
443 ssid = wpa_config_add_network(wpa_s->conf);
446 if (wpa_s->current_ssid) {
448 * Should the GO issue multiple credentials for some
449 * reason, each credential should be marked as a
450 * temporary P2P group similarly to the one that gets
451 * marked as such based on the pre-configured values
452 * used for the WPS network block.
454 ssid->p2p_group = wpa_s->current_ssid->p2p_group;
455 ssid->temporary = wpa_s->current_ssid->temporary;
457 wpas_notify_network_added(wpa_s, ssid);
460 wpa_config_set_network_defaults(ssid);
461 ssid->wps_run = wpa_s->wps_run;
464 ssid->ssid = os_malloc(cred->ssid_len);
466 os_memcpy(ssid->ssid, cred->ssid, cred->ssid_len);
467 ssid->ssid_len = cred->ssid_len;
470 switch (cred->encr_type) {
474 ssid->pairwise_cipher = WPA_CIPHER_TKIP;
477 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
478 if (wpa_s->drv_capa_known &&
479 (wpa_s->drv_enc & WPA_DRIVER_CAPA_ENC_GCMP)) {
480 ssid->pairwise_cipher |= WPA_CIPHER_GCMP;
481 ssid->group_cipher |= WPA_CIPHER_GCMP;
488 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
489 ssid->key_mgmt = WPA_KEY_MGMT_NONE;
491 #ifdef CONFIG_WPS_REG_DISABLE_OPEN
493 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OPEN_NETWORK
494 "id=%d - Credentials for an open "
495 "network disabled by default - use "
496 "'select_network %d' to enable",
500 #endif /* CONFIG_WPS_REG_DISABLE_OPEN */
502 case WPS_AUTH_WPAPSK:
503 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
504 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
505 ssid->proto = WPA_PROTO_WPA;
507 case WPS_AUTH_WPA2PSK:
508 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
509 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
510 ssid->proto = WPA_PROTO_RSN;
514 if (ssid->key_mgmt == WPA_KEY_MGMT_PSK) {
515 if (cred->key_len == 2 * PMK_LEN) {
516 if (hexstr2bin((const char *) cred->key, ssid->psk,
518 wpa_printf(MSG_ERROR, "WPS: Invalid Network "
523 ssid->export_keys = 1;
524 } else if (cred->key_len >= 8 && cred->key_len < 2 * PMK_LEN) {
525 os_free(ssid->passphrase);
526 ssid->passphrase = os_malloc(cred->key_len + 1);
527 if (ssid->passphrase == NULL)
529 os_memcpy(ssid->passphrase, cred->key, cred->key_len);
530 ssid->passphrase[cred->key_len] = '\0';
531 wpa_config_update_psk(ssid);
532 ssid->export_keys = 1;
534 wpa_printf(MSG_ERROR, "WPS: Invalid Network Key "
536 (unsigned long) cred->key_len);
541 wpas_wps_security_workaround(wpa_s, ssid, cred);
543 wpas_wps_remove_dup_network(wpa_s, ssid);
545 #ifndef CONFIG_NO_CONFIG_WRITE
546 if (wpa_s->conf->update_config &&
547 wpa_config_write(wpa_s->confname, wpa_s->conf)) {
548 wpa_printf(MSG_DEBUG, "WPS: Failed to update configuration");
551 #endif /* CONFIG_NO_CONFIG_WRITE */
554 * Optimize the post-WPS scan based on the channel used during
555 * the provisioning in case EAP-Failure is not received.
557 wpa_s->after_wps = 5;
558 wpa_s->wps_freq = wpa_s->assoc_freq;
564 static void wpa_supplicant_wps_event_m2d(struct wpa_supplicant *wpa_s,
565 struct wps_event_m2d *m2d)
567 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_M2D
568 "dev_password_id=%d config_error=%d",
569 m2d->dev_password_id, m2d->config_error);
570 wpas_notify_wps_event_m2d(wpa_s, m2d);
572 if (wpa_s->parent && wpa_s->parent != wpa_s) {
573 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_M2D
574 "dev_password_id=%d config_error=%d",
575 m2d->dev_password_id, m2d->config_error);
577 if (m2d->config_error == WPS_CFG_MULTIPLE_PBC_DETECTED) {
579 * Notify P2P from eloop timeout to avoid issues with the
580 * interface getting removed while processing a message.
582 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb, wpa_s,
585 #endif /* CONFIG_P2P */
589 static void wpas_wps_clear_timeout(void *eloop_ctx, void *timeout_ctx)
591 struct wpa_supplicant *wpa_s = eloop_ctx;
592 wpa_printf(MSG_DEBUG, "WPS: Clear WPS network from timeout");
593 wpas_clear_wps(wpa_s);
597 static void wpa_supplicant_wps_event_fail(struct wpa_supplicant *wpa_s,
598 struct wps_event_fail *fail)
600 if (fail->error_indication > 0 &&
601 fail->error_indication < NUM_WPS_EI_VALUES) {
602 wpa_msg(wpa_s, MSG_INFO,
603 WPS_EVENT_FAIL "msg=%d config_error=%d reason=%d (%s)",
604 fail->msg, fail->config_error, fail->error_indication,
605 wps_ei_str(fail->error_indication));
606 if (wpa_s->parent && wpa_s->parent != wpa_s)
607 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
608 "msg=%d config_error=%d reason=%d (%s)",
609 fail->msg, fail->config_error,
610 fail->error_indication,
611 wps_ei_str(fail->error_indication));
613 wpa_msg(wpa_s, MSG_INFO,
614 WPS_EVENT_FAIL "msg=%d config_error=%d",
615 fail->msg, fail->config_error);
616 if (wpa_s->parent && wpa_s->parent != wpa_s)
617 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
618 "msg=%d config_error=%d",
619 fail->msg, fail->config_error);
623 * Need to allow WPS processing to complete, e.g., by sending WSC_NACK.
625 wpa_printf(MSG_DEBUG, "WPS: Register timeout to clear WPS network");
626 eloop_cancel_timeout(wpas_wps_clear_timeout, wpa_s, NULL);
627 eloop_register_timeout(0, 100000, wpas_wps_clear_timeout, wpa_s, NULL);
629 wpas_notify_wps_event_fail(wpa_s, fail);
630 wpas_p2p_wps_failed(wpa_s, fail);
634 static void wpas_wps_reenable_networks_cb(void *eloop_ctx, void *timeout_ctx);
636 static void wpas_wps_reenable_networks(struct wpa_supplicant *wpa_s)
638 struct wpa_ssid *ssid;
641 eloop_cancel_timeout(wpas_wps_reenable_networks_cb, wpa_s, NULL);
643 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
644 if (ssid->disabled_for_connect && ssid->disabled) {
645 ssid->disabled_for_connect = 0;
647 wpas_notify_network_enabled_changed(wpa_s, ssid);
653 #ifndef CONFIG_NO_CONFIG_WRITE
654 if (wpa_s->conf->update_config &&
655 wpa_config_write(wpa_s->confname, wpa_s->conf)) {
656 wpa_printf(MSG_DEBUG, "WPS: Failed to update "
659 #endif /* CONFIG_NO_CONFIG_WRITE */
664 static void wpas_wps_reenable_networks_cb(void *eloop_ctx, void *timeout_ctx)
666 struct wpa_supplicant *wpa_s = eloop_ctx;
667 /* Enable the networks disabled during wpas_wps_reassoc */
668 wpas_wps_reenable_networks(wpa_s);
672 static void wpa_supplicant_wps_event_success(struct wpa_supplicant *wpa_s)
674 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_SUCCESS);
675 wpa_s->wps_success = 1;
676 wpas_notify_wps_event_success(wpa_s);
677 if (wpa_s->current_ssid)
678 wpas_clear_temp_disabled(wpa_s, wpa_s->current_ssid, 1);
679 wpa_s->extra_blacklist_count = 0;
682 * Enable the networks disabled during wpas_wps_reassoc after 10
683 * seconds. The 10 seconds timer is to allow the data connection to be
684 * formed before allowing other networks to be selected.
686 eloop_register_timeout(10, 0, wpas_wps_reenable_networks_cb, wpa_s,
689 wpas_p2p_wps_success(wpa_s, wpa_s->bssid, 0);
693 static void wpa_supplicant_wps_event_er_ap_add(struct wpa_supplicant *wpa_s,
694 struct wps_event_er_ap *ap)
697 char dev_type[WPS_DEV_TYPE_BUFSIZE];
699 uuid_bin2str(ap->uuid, uuid_str, sizeof(uuid_str));
700 if (ap->pri_dev_type)
701 wps_dev_type_bin2str(ap->pri_dev_type, dev_type,
706 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_ADD "%s " MACSTR
707 " pri_dev_type=%s wps_state=%d |%s|%s|%s|%s|%s|%s|",
708 uuid_str, MAC2STR(ap->mac_addr), dev_type, ap->wps_state,
709 ap->friendly_name ? ap->friendly_name : "",
710 ap->manufacturer ? ap->manufacturer : "",
711 ap->model_description ? ap->model_description : "",
712 ap->model_name ? ap->model_name : "",
713 ap->manufacturer_url ? ap->manufacturer_url : "",
714 ap->model_url ? ap->model_url : "");
718 static void wpa_supplicant_wps_event_er_ap_remove(struct wpa_supplicant *wpa_s,
719 struct wps_event_er_ap *ap)
722 uuid_bin2str(ap->uuid, uuid_str, sizeof(uuid_str));
723 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_REMOVE "%s", uuid_str);
727 static void wpa_supplicant_wps_event_er_enrollee_add(
728 struct wpa_supplicant *wpa_s, struct wps_event_er_enrollee *enrollee)
731 char dev_type[WPS_DEV_TYPE_BUFSIZE];
733 uuid_bin2str(enrollee->uuid, uuid_str, sizeof(uuid_str));
734 if (enrollee->pri_dev_type)
735 wps_dev_type_bin2str(enrollee->pri_dev_type, dev_type,
740 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_ENROLLEE_ADD "%s " MACSTR
741 " M1=%d config_methods=0x%x dev_passwd_id=%d pri_dev_type=%s "
743 uuid_str, MAC2STR(enrollee->mac_addr), enrollee->m1_received,
744 enrollee->config_methods, enrollee->dev_passwd_id, dev_type,
745 enrollee->dev_name ? enrollee->dev_name : "",
746 enrollee->manufacturer ? enrollee->manufacturer : "",
747 enrollee->model_name ? enrollee->model_name : "",
748 enrollee->model_number ? enrollee->model_number : "",
749 enrollee->serial_number ? enrollee->serial_number : "");
753 static void wpa_supplicant_wps_event_er_enrollee_remove(
754 struct wpa_supplicant *wpa_s, struct wps_event_er_enrollee *enrollee)
757 uuid_bin2str(enrollee->uuid, uuid_str, sizeof(uuid_str));
758 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_ENROLLEE_REMOVE "%s " MACSTR,
759 uuid_str, MAC2STR(enrollee->mac_addr));
763 static void wpa_supplicant_wps_event_er_ap_settings(
764 struct wpa_supplicant *wpa_s,
765 struct wps_event_er_ap_settings *ap_settings)
769 const struct wps_credential *cred = ap_settings->cred;
772 if (cred->auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) {
773 if (cred->key_len >= 8 && cred->key_len <= 64) {
774 os_memcpy(key_str, cred->key, cred->key_len);
775 key_str[cred->key_len] = '\0';
779 uuid_bin2str(ap_settings->uuid, uuid_str, sizeof(uuid_str));
780 /* Use wpa_msg_ctrl to avoid showing the key in debug log */
781 wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_SETTINGS
782 "uuid=%s ssid=%s auth_type=0x%04x encr_type=0x%04x "
784 uuid_str, wpa_ssid_txt(cred->ssid, cred->ssid_len),
785 cred->auth_type, cred->encr_type, key_str);
789 static void wpa_supplicant_wps_event_er_set_sel_reg(
790 struct wpa_supplicant *wpa_s,
791 struct wps_event_er_set_selected_registrar *ev)
795 uuid_bin2str(ev->uuid, uuid_str, sizeof(uuid_str));
797 case WPS_ER_SET_SEL_REG_START:
798 wpa_msg(wpa_s, MSG_DEBUG, WPS_EVENT_ER_SET_SEL_REG
799 "uuid=%s state=START sel_reg=%d dev_passwd_id=%u "
800 "sel_reg_config_methods=0x%x",
801 uuid_str, ev->sel_reg, ev->dev_passwd_id,
802 ev->sel_reg_config_methods);
804 case WPS_ER_SET_SEL_REG_DONE:
805 wpa_msg(wpa_s, MSG_DEBUG, WPS_EVENT_ER_SET_SEL_REG
806 "uuid=%s state=DONE", uuid_str);
808 case WPS_ER_SET_SEL_REG_FAILED:
809 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_SET_SEL_REG
810 "uuid=%s state=FAILED", uuid_str);
816 static void wpa_supplicant_wps_event(void *ctx, enum wps_event event,
817 union wps_event_data *data)
819 struct wpa_supplicant *wpa_s = ctx;
822 wpa_supplicant_wps_event_m2d(wpa_s, &data->m2d);
825 wpa_supplicant_wps_event_fail(wpa_s, &data->fail);
828 wpa_supplicant_wps_event_success(wpa_s);
830 case WPS_EV_PWD_AUTH_FAIL:
832 if (wpa_s->ap_iface && data->pwd_auth_fail.enrollee)
833 wpa_supplicant_ap_pwd_auth_fail(wpa_s);
834 #endif /* CONFIG_AP */
836 case WPS_EV_PBC_OVERLAP:
838 case WPS_EV_PBC_TIMEOUT:
840 case WPS_EV_PBC_ACTIVE:
841 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ACTIVE);
843 case WPS_EV_PBC_DISABLE:
844 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_DISABLE);
846 case WPS_EV_ER_AP_ADD:
847 wpa_supplicant_wps_event_er_ap_add(wpa_s, &data->ap);
849 case WPS_EV_ER_AP_REMOVE:
850 wpa_supplicant_wps_event_er_ap_remove(wpa_s, &data->ap);
852 case WPS_EV_ER_ENROLLEE_ADD:
853 wpa_supplicant_wps_event_er_enrollee_add(wpa_s,
856 case WPS_EV_ER_ENROLLEE_REMOVE:
857 wpa_supplicant_wps_event_er_enrollee_remove(wpa_s,
860 case WPS_EV_ER_AP_SETTINGS:
861 wpa_supplicant_wps_event_er_ap_settings(wpa_s,
864 case WPS_EV_ER_SET_SELECTED_REGISTRAR:
865 wpa_supplicant_wps_event_er_set_sel_reg(wpa_s,
868 case WPS_EV_AP_PIN_SUCCESS:
874 static int wpa_supplicant_wps_rf_band(void *ctx)
876 struct wpa_supplicant *wpa_s = ctx;
878 if (!wpa_s->current_ssid || !wpa_s->assoc_freq)
881 return (wpa_s->assoc_freq > 2484) ? WPS_RF_50GHZ : WPS_RF_24GHZ;
885 enum wps_request_type wpas_wps_get_req_type(struct wpa_ssid *ssid)
887 if (eap_is_wps_pbc_enrollee(&ssid->eap) ||
888 eap_is_wps_pin_enrollee(&ssid->eap))
889 return WPS_REQ_ENROLLEE;
891 return WPS_REQ_REGISTRAR;
895 static void wpas_clear_wps(struct wpa_supplicant *wpa_s)
898 struct wpa_ssid *ssid, *remove_ssid = NULL, *prev_current;
900 wpa_s->after_wps = 0;
901 wpa_s->known_wps_freq = 0;
903 prev_current = wpa_s->current_ssid;
905 /* Enable the networks disabled during wpas_wps_reassoc */
906 wpas_wps_reenable_networks(wpa_s);
908 eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
909 eloop_cancel_timeout(wpas_wps_clear_timeout, wpa_s, NULL);
911 /* Remove any existing WPS network from configuration */
912 ssid = wpa_s->conf->ssid;
914 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
915 if (ssid == wpa_s->current_ssid) {
916 wpa_supplicant_deauthenticate(
917 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
925 if (prev_current == remove_ssid) {
926 wpa_sm_set_config(wpa_s->wpa, NULL);
927 eapol_sm_notify_config(wpa_s->eapol, NULL,
930 wpas_notify_network_removed(wpa_s, remove_ssid);
931 wpa_config_remove_network(wpa_s->conf, id);
935 wpas_wps_clear_ap_info(wpa_s);
939 static void wpas_wps_timeout(void *eloop_ctx, void *timeout_ctx)
941 struct wpa_supplicant *wpa_s = eloop_ctx;
942 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_TIMEOUT "Requested operation timed "
944 wpas_clear_wps(wpa_s);
948 static struct wpa_ssid * wpas_wps_add_network(struct wpa_supplicant *wpa_s,
949 int registrar, const u8 *dev_addr,
952 struct wpa_ssid *ssid;
954 ssid = wpa_config_add_network(wpa_s->conf);
957 wpas_notify_network_added(wpa_s, ssid);
958 wpa_config_set_network_defaults(ssid);
960 if (wpa_config_set(ssid, "key_mgmt", "WPS", 0) < 0 ||
961 wpa_config_set(ssid, "eap", "WSC", 0) < 0 ||
962 wpa_config_set(ssid, "identity", registrar ?
963 "\"" WSC_ID_REGISTRAR "\"" :
964 "\"" WSC_ID_ENROLLEE "\"", 0) < 0) {
965 wpas_notify_network_removed(wpa_s, ssid);
966 wpa_config_remove_network(wpa_s->conf, ssid->id);
972 os_memcpy(ssid->go_p2p_dev_addr, dev_addr, ETH_ALEN);
973 #endif /* CONFIG_P2P */
979 #endif /* CONFIG_P2P */
981 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
985 * Note: With P2P, the SSID may change at the time the WPS
986 * provisioning is started, so better not filter the AP based
987 * on the current SSID in the scan results.
990 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
991 if (os_memcmp(bssid, bss->bssid, ETH_ALEN) != 0)
995 ssid->ssid = os_malloc(bss->ssid_len);
996 if (ssid->ssid == NULL)
998 os_memcpy(ssid->ssid, bss->ssid, bss->ssid_len);
999 ssid->ssid_len = bss->ssid_len;
1000 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Picked SSID from "
1002 ssid->ssid, ssid->ssid_len);
1007 wpa_printf(MSG_DEBUG, "WPS: More than one SSID found "
1008 "for the AP; use wildcard");
1009 os_free(ssid->ssid);
1013 #endif /* CONFIG_P2P */
1020 static void wpas_wps_temp_disable(struct wpa_supplicant *wpa_s,
1021 struct wpa_ssid *selected)
1023 struct wpa_ssid *ssid;
1025 if (wpa_s->current_ssid)
1026 wpa_supplicant_deauthenticate(
1027 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1029 /* Mark all other networks disabled and trigger reassociation */
1030 ssid = wpa_s->conf->ssid;
1032 int was_disabled = ssid->disabled;
1033 ssid->disabled_for_connect = 0;
1035 * In case the network object corresponds to a persistent group
1036 * then do not send out network disabled signal. In addition,
1037 * do not change disabled status of persistent network objects
1038 * from 2 to 1 should we connect to another network.
1040 if (was_disabled != 2) {
1041 ssid->disabled = ssid != selected;
1042 if (was_disabled != ssid->disabled) {
1044 ssid->disabled_for_connect = 1;
1045 wpas_notify_network_enabled_changed(wpa_s,
1054 static void wpas_wps_reassoc(struct wpa_supplicant *wpa_s,
1055 struct wpa_ssid *selected, const u8 *bssid,
1058 struct wpa_bss *bss;
1061 if (wpa_s->wps_run == 0)
1063 wpa_s->after_wps = 0;
1064 wpa_s->known_wps_freq = 0;
1066 wpa_s->after_wps = 5;
1067 wpa_s->wps_freq = freq;
1069 bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
1070 if (bss && bss->freq > 0) {
1071 wpa_s->known_wps_freq = 1;
1072 wpa_s->wps_freq = bss->freq;
1076 wpas_wps_temp_disable(wpa_s, selected);
1078 wpa_s->disconnected = 0;
1079 wpa_s->reassociate = 1;
1080 wpa_s->scan_runs = 0;
1081 wpa_s->normal_scans = 0;
1082 wpa_s->wps_success = 0;
1083 wpa_s->blacklist_cleared = 0;
1085 wpa_supplicant_cancel_sched_scan(wpa_s);
1086 wpa_supplicant_req_scan(wpa_s, 0, 0);
1090 int wpas_wps_start_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
1093 struct wpa_ssid *ssid;
1096 if (wpa_s->ap_iface) {
1097 wpa_printf(MSG_DEBUG,
1098 "WPS: Reject request to start Registrar(as station) operation while AP mode is enabled");
1101 #endif /* CONFIG_AP */
1102 wpas_clear_wps(wpa_s);
1103 ssid = wpas_wps_add_network(wpa_s, 0, NULL, bssid);
1106 ssid->temporary = 1;
1107 ssid->p2p_group = p2p_group;
1109 if (p2p_group && wpa_s->go_params && wpa_s->go_params->ssid_len) {
1110 ssid->ssid = os_zalloc(wpa_s->go_params->ssid_len + 1);
1112 ssid->ssid_len = wpa_s->go_params->ssid_len;
1113 os_memcpy(ssid->ssid, wpa_s->go_params->ssid,
1115 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Use specific AP "
1116 "SSID", ssid->ssid, ssid->ssid_len);
1119 #endif /* CONFIG_P2P */
1120 if (wpa_config_set(ssid, "phase1", "\"pbc=1\"", 0) < 0)
1122 if (wpa_s->wps_fragment_size)
1123 ssid->eap.fragment_size = wpa_s->wps_fragment_size;
1124 eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
1126 wpas_wps_reassoc(wpa_s, ssid, bssid, 0);
1131 static int wpas_wps_start_dev_pw(struct wpa_supplicant *wpa_s,
1132 const u8 *dev_addr, const u8 *bssid,
1133 const char *pin, int p2p_group, u16 dev_pw_id,
1134 const u8 *peer_pubkey_hash,
1135 const u8 *ssid_val, size_t ssid_len, int freq)
1137 struct wpa_ssid *ssid;
1138 char val[128 + 2 * WPS_OOB_PUBKEY_HASH_LEN];
1139 unsigned int rpin = 0;
1140 char hash[2 * WPS_OOB_PUBKEY_HASH_LEN + 10];
1143 if (wpa_s->ap_iface) {
1144 wpa_printf(MSG_DEBUG,
1145 "WPS: Reject request to start Registrar(as station) operation while AP mode is enabled");
1148 #endif /* CONFIG_AP */
1149 wpas_clear_wps(wpa_s);
1150 if (bssid && is_zero_ether_addr(bssid))
1152 ssid = wpas_wps_add_network(wpa_s, 0, dev_addr, bssid);
1154 wpa_printf(MSG_DEBUG, "WPS: Could not add network");
1157 ssid->temporary = 1;
1158 ssid->p2p_group = p2p_group;
1160 ssid->ssid = os_malloc(ssid_len);
1162 os_memcpy(ssid->ssid, ssid_val, ssid_len);
1163 ssid->ssid_len = ssid_len;
1166 if (peer_pubkey_hash) {
1167 os_memcpy(hash, " pkhash=", 8);
1168 wpa_snprintf_hex_uppercase(hash + 8, sizeof(hash) - 8,
1170 WPS_OOB_PUBKEY_HASH_LEN);
1175 if (p2p_group && wpa_s->go_params && wpa_s->go_params->ssid_len) {
1176 ssid->ssid = os_zalloc(wpa_s->go_params->ssid_len + 1);
1178 ssid->ssid_len = wpa_s->go_params->ssid_len;
1179 os_memcpy(ssid->ssid, wpa_s->go_params->ssid,
1181 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Use specific AP "
1182 "SSID", ssid->ssid, ssid->ssid_len);
1185 #endif /* CONFIG_P2P */
1187 os_snprintf(val, sizeof(val), "\"pin=%s dev_pw_id=%u%s\"",
1188 pin, dev_pw_id, hash);
1189 else if (pin == NULL && dev_pw_id == DEV_PW_NFC_CONNECTION_HANDOVER) {
1190 os_snprintf(val, sizeof(val), "\"dev_pw_id=%u%s\"",
1193 rpin = wps_generate_pin();
1194 os_snprintf(val, sizeof(val), "\"pin=%08d dev_pw_id=%u%s\"",
1195 rpin, dev_pw_id, hash);
1197 if (wpa_config_set(ssid, "phase1", val, 0) < 0) {
1198 wpa_printf(MSG_DEBUG, "WPS: Failed to set phase1 '%s'", val);
1201 if (wpa_s->wps_fragment_size)
1202 ssid->eap.fragment_size = wpa_s->wps_fragment_size;
1203 eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
1205 wpa_s->wps_ap_iter = 1;
1206 wpas_wps_reassoc(wpa_s, ssid, bssid, freq);
1211 int wpas_wps_start_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
1212 const char *pin, int p2p_group, u16 dev_pw_id)
1214 return wpas_wps_start_dev_pw(wpa_s, NULL, bssid, pin, p2p_group,
1215 dev_pw_id, NULL, NULL, 0, 0);
1219 /* Cancel the wps pbc/pin requests */
1220 int wpas_wps_cancel(struct wpa_supplicant *wpa_s)
1223 if (wpa_s->ap_iface) {
1224 wpa_printf(MSG_DEBUG, "WPS: Cancelling in AP mode");
1225 return wpa_supplicant_ap_wps_cancel(wpa_s);
1227 #endif /* CONFIG_AP */
1229 if (wpa_s->wpa_state == WPA_SCANNING ||
1230 wpa_s->wpa_state == WPA_DISCONNECTED) {
1231 wpa_printf(MSG_DEBUG, "WPS: Cancel operation - cancel scan");
1232 wpa_supplicant_cancel_scan(wpa_s);
1233 wpas_clear_wps(wpa_s);
1234 } else if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1235 wpa_printf(MSG_DEBUG, "WPS: Cancel operation - "
1237 wpa_supplicant_deauthenticate(wpa_s,
1238 WLAN_REASON_DEAUTH_LEAVING);
1239 wpas_clear_wps(wpa_s);
1241 wpas_wps_reenable_networks(wpa_s);
1242 wpas_wps_clear_ap_info(wpa_s);
1243 if (eloop_cancel_timeout(wpas_wps_clear_timeout, wpa_s, NULL) >
1245 wpas_clear_wps(wpa_s);
1248 wpa_s->after_wps = 0;
1254 int wpas_wps_start_reg(struct wpa_supplicant *wpa_s, const u8 *bssid,
1255 const char *pin, struct wps_new_ap_settings *settings)
1257 struct wpa_ssid *ssid;
1263 if (wpa_s->ap_iface) {
1264 wpa_printf(MSG_DEBUG,
1265 "WPS: Reject request to start Registrar(as station) operation while AP mode is enabled");
1268 #endif /* CONFIG_AP */
1271 wpas_clear_wps(wpa_s);
1272 ssid = wpas_wps_add_network(wpa_s, 1, NULL, bssid);
1275 ssid->temporary = 1;
1277 end = pos + sizeof(val);
1278 res = os_snprintf(pos, end - pos, "\"pin=%s", pin);
1279 if (os_snprintf_error(end - pos, res))
1283 res = os_snprintf(pos, end - pos, " new_ssid=%s new_auth=%s "
1284 "new_encr=%s new_key=%s",
1285 settings->ssid_hex, settings->auth,
1286 settings->encr, settings->key_hex);
1287 if (os_snprintf_error(end - pos, res))
1291 res = os_snprintf(pos, end - pos, "\"");
1292 if (os_snprintf_error(end - pos, res))
1294 if (wpa_config_set(ssid, "phase1", val, 0) < 0)
1296 if (wpa_s->wps_fragment_size)
1297 ssid->eap.fragment_size = wpa_s->wps_fragment_size;
1298 eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
1300 wpas_wps_reassoc(wpa_s, ssid, bssid, 0);
1305 static int wpas_wps_new_psk_cb(void *ctx, const u8 *mac_addr,
1306 const u8 *p2p_dev_addr, const u8 *psk,
1309 if (is_zero_ether_addr(p2p_dev_addr)) {
1310 wpa_printf(MSG_DEBUG,
1311 "Received new WPA/WPA2-PSK from WPS for STA " MACSTR,
1314 wpa_printf(MSG_DEBUG,
1315 "Received new WPA/WPA2-PSK from WPS for STA " MACSTR
1316 " P2P Device Addr " MACSTR,
1317 MAC2STR(mac_addr), MAC2STR(p2p_dev_addr));
1319 wpa_hexdump_key(MSG_DEBUG, "Per-device PSK", psk, psk_len);
1327 static void wpas_wps_pin_needed_cb(void *ctx, const u8 *uuid_e,
1328 const struct wps_device_data *dev)
1330 char uuid[40], txt[400];
1332 char devtype[WPS_DEV_TYPE_BUFSIZE];
1333 if (uuid_bin2str(uuid_e, uuid, sizeof(uuid)))
1335 wpa_printf(MSG_DEBUG, "WPS: PIN needed for UUID-E %s", uuid);
1336 len = os_snprintf(txt, sizeof(txt), "WPS-EVENT-PIN-NEEDED %s " MACSTR
1337 " [%s|%s|%s|%s|%s|%s]",
1338 uuid, MAC2STR(dev->mac_addr), dev->device_name,
1339 dev->manufacturer, dev->model_name,
1340 dev->model_number, dev->serial_number,
1341 wps_dev_type_bin2str(dev->pri_dev_type, devtype,
1343 if (!os_snprintf_error(sizeof(txt), len))
1344 wpa_printf(MSG_INFO, "%s", txt);
1348 static void wpas_wps_set_sel_reg_cb(void *ctx, int sel_reg, u16 dev_passwd_id,
1349 u16 sel_reg_config_methods)
1351 #ifdef CONFIG_WPS_ER
1352 struct wpa_supplicant *wpa_s = ctx;
1354 if (wpa_s->wps_er == NULL)
1356 wpa_printf(MSG_DEBUG, "WPS ER: SetSelectedRegistrar - sel_reg=%d "
1357 "dev_password_id=%u sel_reg_config_methods=0x%x",
1358 sel_reg, dev_passwd_id, sel_reg_config_methods);
1359 wps_er_set_sel_reg(wpa_s->wps_er, sel_reg, dev_passwd_id,
1360 sel_reg_config_methods);
1361 #endif /* CONFIG_WPS_ER */
1365 static u16 wps_fix_config_methods(u16 config_methods)
1367 if ((config_methods &
1368 (WPS_CONFIG_DISPLAY | WPS_CONFIG_VIRT_DISPLAY |
1369 WPS_CONFIG_PHY_DISPLAY)) == WPS_CONFIG_DISPLAY) {
1370 wpa_printf(MSG_INFO, "WPS: Converting display to "
1371 "virtual_display for WPS 2.0 compliance");
1372 config_methods |= WPS_CONFIG_VIRT_DISPLAY;
1374 if ((config_methods &
1375 (WPS_CONFIG_PUSHBUTTON | WPS_CONFIG_VIRT_PUSHBUTTON |
1376 WPS_CONFIG_PHY_PUSHBUTTON)) == WPS_CONFIG_PUSHBUTTON) {
1377 wpa_printf(MSG_INFO, "WPS: Converting push_button to "
1378 "virtual_push_button for WPS 2.0 compliance");
1379 config_methods |= WPS_CONFIG_VIRT_PUSHBUTTON;
1382 return config_methods;
1386 static void wpas_wps_set_uuid(struct wpa_supplicant *wpa_s,
1387 struct wps_context *wps)
1392 if (is_nil_uuid(wpa_s->conf->uuid)) {
1393 struct wpa_supplicant *first;
1394 first = wpa_s->global->ifaces;
1395 while (first && first->next)
1396 first = first->next;
1397 if (first && first != wpa_s) {
1398 if (wps != wpa_s->global->ifaces->wps)
1399 os_memcpy(wps->uuid,
1400 wpa_s->global->ifaces->wps->uuid,
1402 src = "from the first interface";
1404 uuid_gen_mac_addr(wpa_s->own_addr, wps->uuid);
1405 src = "based on MAC address";
1408 os_memcpy(wps->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
1409 src = "based on configuration";
1412 uuid_bin2str(wps->uuid, buf, sizeof(buf));
1413 wpa_dbg(wpa_s, MSG_DEBUG, "WPS: UUID %s: %s", src, buf);
1417 static void wpas_wps_set_vendor_ext_m1(struct wpa_supplicant *wpa_s,
1418 struct wps_context *wps)
1420 wpabuf_free(wps->dev.vendor_ext_m1);
1421 wps->dev.vendor_ext_m1 = NULL;
1423 if (wpa_s->conf->wps_vendor_ext_m1) {
1424 wps->dev.vendor_ext_m1 =
1425 wpabuf_dup(wpa_s->conf->wps_vendor_ext_m1);
1426 if (!wps->dev.vendor_ext_m1) {
1427 wpa_printf(MSG_ERROR, "WPS: Cannot "
1428 "allocate memory for vendor_ext_m1");
1434 int wpas_wps_init(struct wpa_supplicant *wpa_s)
1436 struct wps_context *wps;
1437 struct wps_registrar_config rcfg;
1438 struct hostapd_hw_modes *modes;
1441 wps = os_zalloc(sizeof(*wps));
1445 wps->cred_cb = wpa_supplicant_wps_cred;
1446 wps->event_cb = wpa_supplicant_wps_event;
1447 wps->rf_band_cb = wpa_supplicant_wps_rf_band;
1448 wps->cb_ctx = wpa_s;
1450 wps->dev.device_name = wpa_s->conf->device_name;
1451 wps->dev.manufacturer = wpa_s->conf->manufacturer;
1452 wps->dev.model_name = wpa_s->conf->model_name;
1453 wps->dev.model_number = wpa_s->conf->model_number;
1454 wps->dev.serial_number = wpa_s->conf->serial_number;
1455 wps->config_methods =
1456 wps_config_methods_str2bin(wpa_s->conf->config_methods);
1457 if ((wps->config_methods & (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) ==
1458 (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) {
1459 wpa_printf(MSG_ERROR, "WPS: Both Label and Display config "
1460 "methods are not allowed at the same time");
1464 wps->config_methods = wps_fix_config_methods(wps->config_methods);
1465 wps->dev.config_methods = wps->config_methods;
1466 os_memcpy(wps->dev.pri_dev_type, wpa_s->conf->device_type,
1469 wps->dev.num_sec_dev_types = wpa_s->conf->num_sec_device_types;
1470 os_memcpy(wps->dev.sec_dev_type, wpa_s->conf->sec_device_type,
1471 WPS_DEV_TYPE_LEN * wps->dev.num_sec_dev_types);
1473 wpas_wps_set_vendor_ext_m1(wpa_s, wps);
1475 wps->dev.os_version = WPA_GET_BE32(wpa_s->conf->os_version);
1476 modes = wpa_s->hw.modes;
1478 for (m = 0; m < wpa_s->hw.num_modes; m++) {
1479 if (modes[m].mode == HOSTAPD_MODE_IEEE80211B ||
1480 modes[m].mode == HOSTAPD_MODE_IEEE80211G)
1481 wps->dev.rf_bands |= WPS_RF_24GHZ;
1482 else if (modes[m].mode == HOSTAPD_MODE_IEEE80211A)
1483 wps->dev.rf_bands |= WPS_RF_50GHZ;
1486 if (wps->dev.rf_bands == 0) {
1488 * Default to claiming support for both bands if the driver
1489 * does not provide support for fetching supported bands.
1491 wps->dev.rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ;
1493 os_memcpy(wps->dev.mac_addr, wpa_s->own_addr, ETH_ALEN);
1494 wpas_wps_set_uuid(wpa_s, wps);
1496 wps->auth_types = WPS_AUTH_WPA2PSK | WPS_AUTH_WPAPSK;
1497 wps->encr_types = WPS_ENCR_AES | WPS_ENCR_TKIP;
1499 os_memset(&rcfg, 0, sizeof(rcfg));
1500 rcfg.new_psk_cb = wpas_wps_new_psk_cb;
1501 rcfg.pin_needed_cb = wpas_wps_pin_needed_cb;
1502 rcfg.set_sel_reg_cb = wpas_wps_set_sel_reg_cb;
1503 rcfg.cb_ctx = wpa_s;
1505 wps->registrar = wps_registrar_init(wps, &rcfg);
1506 if (wps->registrar == NULL) {
1507 wpa_printf(MSG_DEBUG, "Failed to initialize WPS Registrar");
1518 #ifdef CONFIG_WPS_ER
1519 static void wpas_wps_nfc_clear(struct wps_context *wps)
1521 wps->ap_nfc_dev_pw_id = 0;
1522 wpabuf_free(wps->ap_nfc_dh_pubkey);
1523 wps->ap_nfc_dh_pubkey = NULL;
1524 wpabuf_free(wps->ap_nfc_dh_privkey);
1525 wps->ap_nfc_dh_privkey = NULL;
1526 wpabuf_free(wps->ap_nfc_dev_pw);
1527 wps->ap_nfc_dev_pw = NULL;
1529 #endif /* CONFIG_WPS_ER */
1532 void wpas_wps_deinit(struct wpa_supplicant *wpa_s)
1534 wpas_wps_assoc_with_cred_cancel(wpa_s);
1535 eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
1536 eloop_cancel_timeout(wpas_wps_clear_timeout, wpa_s, NULL);
1537 eloop_cancel_timeout(wpas_wps_reenable_networks_cb, wpa_s, NULL);
1538 wpas_wps_clear_ap_info(wpa_s);
1541 eloop_cancel_timeout(wpas_p2p_pbc_overlap_cb, wpa_s, NULL);
1542 #endif /* CONFIG_P2P */
1544 if (wpa_s->wps == NULL)
1547 #ifdef CONFIG_WPS_ER
1548 wps_er_deinit(wpa_s->wps_er, NULL, NULL);
1549 wpa_s->wps_er = NULL;
1550 wpas_wps_nfc_clear(wpa_s->wps);
1551 #endif /* CONFIG_WPS_ER */
1553 wps_registrar_deinit(wpa_s->wps->registrar);
1554 wpabuf_free(wpa_s->wps->dh_pubkey);
1555 wpabuf_free(wpa_s->wps->dh_privkey);
1556 wpabuf_free(wpa_s->wps->dev.vendor_ext_m1);
1557 os_free(wpa_s->wps->network_key);
1558 os_free(wpa_s->wps);
1563 int wpas_wps_ssid_bss_match(struct wpa_supplicant *wpa_s,
1564 struct wpa_ssid *ssid, struct wpa_bss *bss)
1566 struct wpabuf *wps_ie;
1568 if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS))
1571 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1572 if (eap_is_wps_pbc_enrollee(&ssid->eap)) {
1574 wpa_printf(MSG_DEBUG, " skip - non-WPS AP");
1578 if (!wps_is_selected_pbc_registrar(wps_ie)) {
1579 wpa_printf(MSG_DEBUG, " skip - WPS AP "
1580 "without active PBC Registrar");
1581 wpabuf_free(wps_ie);
1585 /* TODO: overlap detection */
1586 wpa_printf(MSG_DEBUG, " selected based on WPS IE "
1588 wpabuf_free(wps_ie);
1592 if (eap_is_wps_pin_enrollee(&ssid->eap)) {
1594 wpa_printf(MSG_DEBUG, " skip - non-WPS AP");
1599 * Start with WPS APs that advertise our address as an
1600 * authorized MAC (v2.0) or active PIN Registrar (v1.0) and
1601 * allow any WPS AP after couple of scans since some APs do not
1602 * set Selected Registrar attribute properly when using
1603 * external Registrar.
1605 if (!wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1)) {
1606 if (wpa_s->scan_runs < WPS_PIN_SCAN_IGNORE_SEL_REG) {
1607 wpa_printf(MSG_DEBUG, " skip - WPS AP "
1608 "without active PIN Registrar");
1609 wpabuf_free(wps_ie);
1612 wpa_printf(MSG_DEBUG, " selected based on WPS IE");
1614 wpa_printf(MSG_DEBUG, " selected based on WPS IE "
1615 "(Authorized MAC or Active PIN)");
1617 wpabuf_free(wps_ie);
1622 wpa_printf(MSG_DEBUG, " selected based on WPS IE");
1623 wpabuf_free(wps_ie);
1631 int wpas_wps_ssid_wildcard_ok(struct wpa_supplicant *wpa_s,
1632 struct wpa_ssid *ssid,
1633 struct wpa_bss *bss)
1635 struct wpabuf *wps_ie = NULL;
1638 if (eap_is_wps_pbc_enrollee(&ssid->eap)) {
1639 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1640 if (wps_ie && wps_is_selected_pbc_registrar(wps_ie)) {
1641 /* allow wildcard SSID for WPS PBC */
1644 } else if (eap_is_wps_pin_enrollee(&ssid->eap)) {
1645 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1647 (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1) ||
1648 wpa_s->scan_runs >= WPS_PIN_SCAN_IGNORE_SEL_REG)) {
1649 /* allow wildcard SSID for WPS PIN */
1654 if (!ret && ssid->bssid_set &&
1655 os_memcmp(ssid->bssid, bss->bssid, ETH_ALEN) == 0) {
1656 /* allow wildcard SSID due to hardcoded BSSID match */
1660 #ifdef CONFIG_WPS_STRICT
1662 if (wps_validate_beacon_probe_resp(wps_ie, bss->beacon_ie_len >
1665 if (bss->beacon_ie_len) {
1666 struct wpabuf *bcn_wps;
1667 bcn_wps = wpa_bss_get_vendor_ie_multi_beacon(
1668 bss, WPS_IE_VENDOR_TYPE);
1669 if (bcn_wps == NULL) {
1670 wpa_printf(MSG_DEBUG, "WPS: Mandatory WPS IE "
1671 "missing from AP Beacon");
1674 if (wps_validate_beacon(wps_ie) < 0)
1676 wpabuf_free(bcn_wps);
1680 #endif /* CONFIG_WPS_STRICT */
1682 wpabuf_free(wps_ie);
1688 int wpas_wps_scan_pbc_overlap(struct wpa_supplicant *wpa_s,
1689 struct wpa_bss *selected, struct wpa_ssid *ssid)
1691 const u8 *sel_uuid, *uuid;
1692 struct wpabuf *wps_ie;
1694 struct wpa_bss *bss;
1696 if (!eap_is_wps_pbc_enrollee(&ssid->eap))
1699 wpa_printf(MSG_DEBUG, "WPS: Check whether PBC session overlap is "
1700 "present in scan results; selected BSSID " MACSTR,
1701 MAC2STR(selected->bssid));
1703 /* Make sure that only one AP is in active PBC mode */
1704 wps_ie = wpa_bss_get_vendor_ie_multi(selected, WPS_IE_VENDOR_TYPE);
1706 sel_uuid = wps_get_uuid_e(wps_ie);
1707 wpa_hexdump(MSG_DEBUG, "WPS: UUID of the selected BSS",
1708 sel_uuid, UUID_LEN);
1710 wpa_printf(MSG_DEBUG, "WPS: Selected BSS does not include "
1715 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1717 if (bss == selected)
1719 ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1722 if (!wps_is_selected_pbc_registrar(ie)) {
1726 wpa_printf(MSG_DEBUG, "WPS: Another BSS in active PBC mode: "
1727 MACSTR, MAC2STR(bss->bssid));
1728 uuid = wps_get_uuid_e(ie);
1729 wpa_hexdump(MSG_DEBUG, "WPS: UUID of the other BSS",
1731 if (os_memcmp(selected->bssid, bss->bssid, ETH_ALEN) == 0) {
1735 if (sel_uuid == NULL || uuid == NULL ||
1736 os_memcmp(sel_uuid, uuid, UUID_LEN) != 0) {
1737 ret = 1; /* PBC overlap */
1738 wpa_msg(wpa_s, MSG_INFO, "WPS: PBC overlap detected: "
1739 MACSTR " and " MACSTR,
1740 MAC2STR(selected->bssid),
1741 MAC2STR(bss->bssid));
1746 /* TODO: verify that this is reasonable dual-band situation */
1751 wpabuf_free(wps_ie);
1757 void wpas_wps_notify_scan_results(struct wpa_supplicant *wpa_s)
1759 struct wpa_bss *bss;
1760 unsigned int pbc = 0, auth = 0, pin = 0, wps = 0;
1762 if (wpa_s->disconnected || wpa_s->wpa_state >= WPA_ASSOCIATED)
1765 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1767 ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1770 if (wps_is_selected_pbc_registrar(ie))
1772 else if (wps_is_addr_authorized(ie, wpa_s->own_addr, 0))
1774 else if (wps_is_selected_pin_registrar(ie))
1782 wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PBC);
1784 wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_AUTH);
1786 wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PIN);
1788 wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE);
1792 int wpas_wps_searching(struct wpa_supplicant *wpa_s)
1794 struct wpa_ssid *ssid;
1796 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1797 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && !ssid->disabled)
1805 int wpas_wps_scan_result_text(const u8 *ies, size_t ies_len, char *buf,
1808 struct wpabuf *wps_ie;
1811 wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len, WPS_DEV_OUI_WFA);
1815 ret = wps_attr_text(wps_ie, buf, end);
1816 wpabuf_free(wps_ie);
1821 int wpas_wps_er_start(struct wpa_supplicant *wpa_s, const char *filter)
1823 #ifdef CONFIG_WPS_ER
1824 if (wpa_s->wps_er) {
1825 wps_er_refresh(wpa_s->wps_er);
1828 wpa_s->wps_er = wps_er_init(wpa_s->wps, wpa_s->ifname, filter);
1829 if (wpa_s->wps_er == NULL)
1832 #else /* CONFIG_WPS_ER */
1834 #endif /* CONFIG_WPS_ER */
1838 void wpas_wps_er_stop(struct wpa_supplicant *wpa_s)
1840 #ifdef CONFIG_WPS_ER
1841 wps_er_deinit(wpa_s->wps_er, NULL, NULL);
1842 wpa_s->wps_er = NULL;
1843 #endif /* CONFIG_WPS_ER */
1847 #ifdef CONFIG_WPS_ER
1848 int wpas_wps_er_add_pin(struct wpa_supplicant *wpa_s, const u8 *addr,
1849 const char *uuid, const char *pin)
1852 const u8 *use_uuid = NULL;
1853 u8 addr_buf[ETH_ALEN];
1855 if (os_strcmp(uuid, "any") == 0) {
1856 } else if (uuid_str2bin(uuid, u) == 0) {
1858 } else if (hwaddr_aton(uuid, addr_buf) == 0) {
1859 use_uuid = wps_er_get_sta_uuid(wpa_s->wps_er, addr_buf);
1860 if (use_uuid == NULL)
1864 return wps_registrar_add_pin(wpa_s->wps->registrar, addr,
1866 (const u8 *) pin, os_strlen(pin), 300);
1870 int wpas_wps_er_pbc(struct wpa_supplicant *wpa_s, const char *uuid)
1872 u8 u[UUID_LEN], *use_uuid = NULL;
1873 u8 addr[ETH_ALEN], *use_addr = NULL;
1875 if (uuid_str2bin(uuid, u) == 0)
1877 else if (hwaddr_aton(uuid, addr) == 0)
1881 return wps_er_pbc(wpa_s->wps_er, use_uuid, use_addr);
1885 int wpas_wps_er_learn(struct wpa_supplicant *wpa_s, const char *uuid,
1888 u8 u[UUID_LEN], *use_uuid = NULL;
1889 u8 addr[ETH_ALEN], *use_addr = NULL;
1891 if (uuid_str2bin(uuid, u) == 0)
1893 else if (hwaddr_aton(uuid, addr) == 0)
1898 return wps_er_learn(wpa_s->wps_er, use_uuid, use_addr, (const u8 *) pin,
1903 static int wpas_wps_network_to_cred(struct wpa_ssid *ssid,
1904 struct wps_credential *cred)
1906 os_memset(cred, 0, sizeof(*cred));
1907 if (ssid->ssid_len > 32)
1909 os_memcpy(cred->ssid, ssid->ssid, ssid->ssid_len);
1910 cred->ssid_len = ssid->ssid_len;
1911 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) {
1912 cred->auth_type = (ssid->proto & WPA_PROTO_RSN) ?
1913 WPS_AUTH_WPA2PSK : WPS_AUTH_WPAPSK;
1914 if (ssid->pairwise_cipher & WPA_CIPHER_CCMP)
1915 cred->encr_type = WPS_ENCR_AES;
1917 cred->encr_type = WPS_ENCR_TKIP;
1918 if (ssid->passphrase) {
1919 cred->key_len = os_strlen(ssid->passphrase);
1920 if (cred->key_len >= 64)
1922 os_memcpy(cred->key, ssid->passphrase, cred->key_len);
1923 } else if (ssid->psk_set) {
1925 os_memcpy(cred->key, ssid->psk, 32);
1929 cred->auth_type = WPS_AUTH_OPEN;
1930 cred->encr_type = WPS_ENCR_NONE;
1937 int wpas_wps_er_set_config(struct wpa_supplicant *wpa_s, const char *uuid,
1940 u8 u[UUID_LEN], *use_uuid = NULL;
1941 u8 addr[ETH_ALEN], *use_addr = NULL;
1942 struct wpa_ssid *ssid;
1943 struct wps_credential cred;
1946 if (uuid_str2bin(uuid, u) == 0)
1948 else if (hwaddr_aton(uuid, addr) == 0)
1952 ssid = wpa_config_get_network(wpa_s->conf, id);
1953 if (ssid == NULL || ssid->ssid == NULL)
1956 if (wpas_wps_network_to_cred(ssid, &cred) < 0)
1958 ret = wps_er_set_config(wpa_s->wps_er, use_uuid, use_addr, &cred);
1959 os_memset(&cred, 0, sizeof(cred));
1964 int wpas_wps_er_config(struct wpa_supplicant *wpa_s, const char *uuid,
1965 const char *pin, struct wps_new_ap_settings *settings)
1967 u8 u[UUID_LEN], *use_uuid = NULL;
1968 u8 addr[ETH_ALEN], *use_addr = NULL;
1969 struct wps_credential cred;
1972 if (uuid_str2bin(uuid, u) == 0)
1974 else if (hwaddr_aton(uuid, addr) == 0)
1978 if (settings->ssid_hex == NULL || settings->auth == NULL ||
1979 settings->encr == NULL || settings->key_hex == NULL)
1982 os_memset(&cred, 0, sizeof(cred));
1983 len = os_strlen(settings->ssid_hex);
1984 if ((len & 1) || len > 2 * sizeof(cred.ssid) ||
1985 hexstr2bin(settings->ssid_hex, cred.ssid, len / 2))
1987 cred.ssid_len = len / 2;
1989 len = os_strlen(settings->key_hex);
1990 if ((len & 1) || len > 2 * sizeof(cred.key) ||
1991 hexstr2bin(settings->key_hex, cred.key, len / 2))
1993 cred.key_len = len / 2;
1995 if (os_strcmp(settings->auth, "OPEN") == 0)
1996 cred.auth_type = WPS_AUTH_OPEN;
1997 else if (os_strcmp(settings->auth, "WPAPSK") == 0)
1998 cred.auth_type = WPS_AUTH_WPAPSK;
1999 else if (os_strcmp(settings->auth, "WPA2PSK") == 0)
2000 cred.auth_type = WPS_AUTH_WPA2PSK;
2004 if (os_strcmp(settings->encr, "NONE") == 0)
2005 cred.encr_type = WPS_ENCR_NONE;
2006 #ifdef CONFIG_TESTING_OPTIONS
2007 else if (os_strcmp(settings->encr, "WEP") == 0)
2008 cred.encr_type = WPS_ENCR_WEP;
2009 #endif /* CONFIG_TESTING_OPTIONS */
2010 else if (os_strcmp(settings->encr, "TKIP") == 0)
2011 cred.encr_type = WPS_ENCR_TKIP;
2012 else if (os_strcmp(settings->encr, "CCMP") == 0)
2013 cred.encr_type = WPS_ENCR_AES;
2017 return wps_er_config(wpa_s->wps_er, use_uuid, use_addr,
2018 (const u8 *) pin, os_strlen(pin), &cred);
2022 #ifdef CONFIG_WPS_NFC
2023 struct wpabuf * wpas_wps_er_nfc_config_token(struct wpa_supplicant *wpa_s,
2024 int ndef, const char *uuid)
2027 u8 u[UUID_LEN], *use_uuid = NULL;
2028 u8 addr[ETH_ALEN], *use_addr = NULL;
2033 if (uuid_str2bin(uuid, u) == 0)
2035 else if (hwaddr_aton(uuid, addr) == 0)
2040 ret = wps_er_nfc_config_token(wpa_s->wps_er, use_uuid, use_addr);
2043 tmp = ndef_build_wifi(ret);
2052 #endif /* CONFIG_WPS_NFC */
2055 static int callbacks_pending = 0;
2057 static void wpas_wps_terminate_cb(void *ctx)
2059 wpa_printf(MSG_DEBUG, "WPS ER: Terminated");
2060 if (--callbacks_pending <= 0)
2063 #endif /* CONFIG_WPS_ER */
2066 int wpas_wps_terminate_pending(struct wpa_supplicant *wpa_s)
2068 #ifdef CONFIG_WPS_ER
2069 if (wpa_s->wps_er) {
2070 callbacks_pending++;
2071 wps_er_deinit(wpa_s->wps_er, wpas_wps_terminate_cb, wpa_s);
2072 wpa_s->wps_er = NULL;
2075 #endif /* CONFIG_WPS_ER */
2080 void wpas_wps_update_config(struct wpa_supplicant *wpa_s)
2082 struct wps_context *wps = wpa_s->wps;
2087 if (wpa_s->conf->changed_parameters & CFG_CHANGED_CONFIG_METHODS) {
2088 wps->config_methods = wps_config_methods_str2bin(
2089 wpa_s->conf->config_methods);
2090 if ((wps->config_methods &
2091 (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) ==
2092 (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) {
2093 wpa_printf(MSG_ERROR, "WPS: Both Label and Display "
2094 "config methods are not allowed at the "
2096 wps->config_methods &= ~WPS_CONFIG_LABEL;
2099 wps->config_methods = wps_fix_config_methods(wps->config_methods);
2100 wps->dev.config_methods = wps->config_methods;
2102 if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_TYPE)
2103 os_memcpy(wps->dev.pri_dev_type, wpa_s->conf->device_type,
2106 if (wpa_s->conf->changed_parameters & CFG_CHANGED_SEC_DEVICE_TYPE) {
2107 wps->dev.num_sec_dev_types = wpa_s->conf->num_sec_device_types;
2108 os_memcpy(wps->dev.sec_dev_type, wpa_s->conf->sec_device_type,
2109 wps->dev.num_sec_dev_types * WPS_DEV_TYPE_LEN);
2112 if (wpa_s->conf->changed_parameters & CFG_CHANGED_VENDOR_EXTENSION)
2113 wpas_wps_set_vendor_ext_m1(wpa_s, wps);
2115 if (wpa_s->conf->changed_parameters & CFG_CHANGED_OS_VERSION)
2116 wps->dev.os_version = WPA_GET_BE32(wpa_s->conf->os_version);
2118 if (wpa_s->conf->changed_parameters & CFG_CHANGED_UUID)
2119 wpas_wps_set_uuid(wpa_s, wps);
2121 if (wpa_s->conf->changed_parameters &
2122 (CFG_CHANGED_DEVICE_NAME | CFG_CHANGED_WPS_STRING)) {
2123 /* Update pointers to make sure they refer current values */
2124 wps->dev.device_name = wpa_s->conf->device_name;
2125 wps->dev.manufacturer = wpa_s->conf->manufacturer;
2126 wps->dev.model_name = wpa_s->conf->model_name;
2127 wps->dev.model_number = wpa_s->conf->model_number;
2128 wps->dev.serial_number = wpa_s->conf->serial_number;
2133 #ifdef CONFIG_WPS_NFC
2135 #ifdef CONFIG_WPS_ER
2136 static struct wpabuf *
2137 wpas_wps_network_config_token(struct wpa_supplicant *wpa_s, int ndef,
2138 struct wpa_ssid *ssid)
2141 struct wps_credential cred;
2143 if (wpas_wps_network_to_cred(ssid, &cred) < 0)
2146 ret = wps_er_config_token_from_cred(wpa_s->wps, &cred);
2150 tmp = ndef_build_wifi(ret);
2159 #endif /* CONFIG_WPS_ER */
2162 struct wpabuf * wpas_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
2163 int ndef, const char *id_str)
2165 #ifdef CONFIG_WPS_ER
2169 struct wpa_ssid *ssid;
2171 id = strtol(id_str, &end, 10);
2175 ssid = wpa_config_get_network(wpa_s->conf, id);
2178 return wpas_wps_network_config_token(wpa_s, ndef, ssid);
2180 #endif /* CONFIG_WPS_ER */
2182 if (wpa_s->ap_iface)
2183 return wpas_ap_wps_nfc_config_token(wpa_s, ndef);
2184 #endif /* CONFIG_AP */
2189 struct wpabuf * wpas_wps_nfc_token(struct wpa_supplicant *wpa_s, int ndef)
2191 if (wpa_s->conf->wps_nfc_pw_from_config) {
2192 return wps_nfc_token_build(ndef,
2193 wpa_s->conf->wps_nfc_dev_pw_id,
2194 wpa_s->conf->wps_nfc_dh_pubkey,
2195 wpa_s->conf->wps_nfc_dev_pw);
2198 return wps_nfc_token_gen(ndef, &wpa_s->conf->wps_nfc_dev_pw_id,
2199 &wpa_s->conf->wps_nfc_dh_pubkey,
2200 &wpa_s->conf->wps_nfc_dh_privkey,
2201 &wpa_s->conf->wps_nfc_dev_pw);
2205 int wpas_wps_start_nfc(struct wpa_supplicant *wpa_s, const u8 *go_dev_addr,
2207 const struct wpabuf *dev_pw, u16 dev_pw_id,
2208 int p2p_group, const u8 *peer_pubkey_hash,
2209 const u8 *ssid, size_t ssid_len, int freq)
2211 struct wps_context *wps = wpa_s->wps;
2212 char pw[32 * 2 + 1];
2214 if (dev_pw_id != DEV_PW_NFC_CONNECTION_HANDOVER && dev_pw == NULL) {
2215 dev_pw = wpa_s->conf->wps_nfc_dev_pw;
2216 dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id;
2219 if (wpa_s->conf->wps_nfc_dh_pubkey == NULL ||
2220 wpa_s->conf->wps_nfc_dh_privkey == NULL) {
2221 wpa_printf(MSG_DEBUG, "WPS: Missing DH params - "
2222 "cannot start NFC-triggered connection");
2226 if (dev_pw_id != DEV_PW_NFC_CONNECTION_HANDOVER && dev_pw == NULL) {
2227 wpa_printf(MSG_DEBUG, "WPS: Missing Device Password (id=%u) - "
2228 "cannot start NFC-triggered connection", dev_pw_id);
2232 dh5_free(wps->dh_ctx);
2233 wpabuf_free(wps->dh_pubkey);
2234 wpabuf_free(wps->dh_privkey);
2235 wps->dh_privkey = wpabuf_dup(wpa_s->conf->wps_nfc_dh_privkey);
2236 wps->dh_pubkey = wpabuf_dup(wpa_s->conf->wps_nfc_dh_pubkey);
2237 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
2239 wpabuf_free(wps->dh_pubkey);
2240 wps->dh_pubkey = NULL;
2241 wpabuf_free(wps->dh_privkey);
2242 wps->dh_privkey = NULL;
2243 wpa_printf(MSG_DEBUG, "WPS: Failed to get DH priv/pub key");
2246 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
2247 if (wps->dh_ctx == NULL) {
2248 wpabuf_free(wps->dh_pubkey);
2249 wps->dh_pubkey = NULL;
2250 wpabuf_free(wps->dh_privkey);
2251 wps->dh_privkey = NULL;
2252 wpa_printf(MSG_DEBUG, "WPS: Failed to initialize DH context");
2257 wpa_snprintf_hex_uppercase(pw, sizeof(pw),
2258 wpabuf_head(dev_pw),
2259 wpabuf_len(dev_pw));
2261 return wpas_wps_start_dev_pw(wpa_s, go_dev_addr, bssid,
2263 p2p_group, dev_pw_id, peer_pubkey_hash,
2264 ssid, ssid_len, freq);
2268 static int wpas_wps_use_cred(struct wpa_supplicant *wpa_s,
2269 struct wps_parse_attr *attr)
2272 * Disable existing networks temporarily to allow the newly learned
2273 * credential to be preferred. Enable the temporarily disabled networks
2276 wpas_wps_temp_disable(wpa_s, NULL);
2277 eloop_register_timeout(10, 0, wpas_wps_reenable_networks_cb, wpa_s,
2280 if (wps_oob_use_cred(wpa_s->wps, attr) < 0)
2283 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2286 if (attr->ap_channel) {
2287 u16 chan = WPA_GET_BE16(attr->ap_channel);
2290 if (chan >= 1 && chan <= 13)
2291 freq = 2407 + 5 * chan;
2292 else if (chan == 14)
2294 else if (chan >= 30)
2295 freq = 5000 + 5 * chan;
2298 wpa_printf(MSG_DEBUG, "WPS: Credential container indicated AP channel %u -> %u MHz",
2300 wpa_s->after_wps = 5;
2301 wpa_s->wps_freq = freq;
2305 wpa_printf(MSG_DEBUG, "WPS: Request reconnection with new network "
2306 "based on the received credential added");
2307 wpa_s->normal_scans = 0;
2308 wpa_supplicant_reinit_autoscan(wpa_s);
2309 wpa_s->disconnected = 0;
2310 wpa_s->reassociate = 1;
2312 wpa_supplicant_cancel_sched_scan(wpa_s);
2313 wpa_supplicant_req_scan(wpa_s, 0, 0);
2319 #ifdef CONFIG_WPS_ER
2320 static int wpas_wps_add_nfc_password_token(struct wpa_supplicant *wpa_s,
2321 struct wps_parse_attr *attr)
2323 return wps_registrar_add_nfc_password_token(
2324 wpa_s->wps->registrar, attr->oob_dev_password,
2325 attr->oob_dev_password_len);
2327 #endif /* CONFIG_WPS_ER */
2330 static int wpas_wps_nfc_tag_process(struct wpa_supplicant *wpa_s,
2331 const struct wpabuf *wps)
2333 struct wps_parse_attr attr;
2335 wpa_hexdump_buf(MSG_DEBUG, "WPS: Received NFC tag payload", wps);
2337 if (wps_parse_msg(wps, &attr)) {
2338 wpa_printf(MSG_DEBUG, "WPS: Ignore invalid data from NFC tag");
2343 return wpas_wps_use_cred(wpa_s, &attr);
2345 #ifdef CONFIG_WPS_ER
2346 if (attr.oob_dev_password)
2347 return wpas_wps_add_nfc_password_token(wpa_s, &attr);
2348 #endif /* CONFIG_WPS_ER */
2350 wpa_printf(MSG_DEBUG, "WPS: Ignore unrecognized NFC tag");
2355 int wpas_wps_nfc_tag_read(struct wpa_supplicant *wpa_s,
2356 const struct wpabuf *data, int forced_freq)
2358 const struct wpabuf *wps = data;
2359 struct wpabuf *tmp = NULL;
2362 if (wpabuf_len(data) < 4)
2365 if (*wpabuf_head_u8(data) != 0x10) {
2366 /* Assume this contains full NDEF record */
2367 tmp = ndef_parse_wifi(data);
2370 tmp = ndef_parse_p2p(data);
2372 ret = wpas_p2p_nfc_tag_process(wpa_s, tmp,
2377 #endif /* CONFIG_P2P */
2378 wpa_printf(MSG_DEBUG, "WPS: Could not parse NDEF");
2384 ret = wpas_wps_nfc_tag_process(wpa_s, wps);
2390 struct wpabuf * wpas_wps_nfc_handover_req(struct wpa_supplicant *wpa_s,
2395 if (wpa_s->conf->wps_nfc_dh_pubkey == NULL &&
2396 wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey,
2397 &wpa_s->conf->wps_nfc_dh_privkey) < 0)
2400 ret = wps_build_nfc_handover_req(wpa_s->wps,
2401 wpa_s->conf->wps_nfc_dh_pubkey);
2405 tmp = ndef_build_wifi(ret);
2416 #ifdef CONFIG_WPS_NFC
2418 static struct wpabuf *
2419 wpas_wps_er_nfc_handover_sel(struct wpa_supplicant *wpa_s, int ndef,
2422 #ifdef CONFIG_WPS_ER
2424 u8 u[UUID_LEN], *use_uuid = NULL;
2425 u8 addr[ETH_ALEN], *use_addr = NULL;
2426 struct wps_context *wps = wpa_s->wps;
2433 if (uuid_str2bin(uuid, u) == 0)
2435 else if (hwaddr_aton(uuid, addr) == 0)
2440 if (wpa_s->conf->wps_nfc_dh_pubkey == NULL) {
2441 if (wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey,
2442 &wpa_s->conf->wps_nfc_dh_privkey) < 0)
2446 wpas_wps_nfc_clear(wps);
2447 wps->ap_nfc_dev_pw_id = DEV_PW_NFC_CONNECTION_HANDOVER;
2448 wps->ap_nfc_dh_pubkey = wpabuf_dup(wpa_s->conf->wps_nfc_dh_pubkey);
2449 wps->ap_nfc_dh_privkey = wpabuf_dup(wpa_s->conf->wps_nfc_dh_privkey);
2450 if (!wps->ap_nfc_dh_pubkey || !wps->ap_nfc_dh_privkey) {
2451 wpas_wps_nfc_clear(wps);
2455 ret = wps_er_nfc_handover_sel(wpa_s->wps_er, wpa_s->wps, use_uuid,
2456 use_addr, wpa_s->conf->wps_nfc_dh_pubkey);
2459 tmp = ndef_build_wifi(ret);
2467 #else /* CONFIG_WPS_ER */
2469 #endif /* CONFIG_WPS_ER */
2471 #endif /* CONFIG_WPS_NFC */
2474 struct wpabuf * wpas_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
2475 int ndef, int cr, const char *uuid)
2480 ret = wpas_ap_wps_nfc_handover_sel(wpa_s, ndef);
2483 return wpas_wps_er_nfc_handover_sel(wpa_s, ndef, uuid);
2487 static int wpas_wps_nfc_rx_handover_sel(struct wpa_supplicant *wpa_s,
2488 const struct wpabuf *data)
2495 struct wps_parse_attr attr;
2497 const u8 *bssid = NULL;
2500 wps = ndef_parse_wifi(data);
2503 wpa_printf(MSG_DEBUG, "WPS: Received application/vnd.wfa.wsc "
2504 "payload from NFC connection handover");
2505 wpa_hexdump_buf(MSG_DEBUG, "WPS: NFC payload", wps);
2506 if (wpabuf_len(wps) < 2) {
2507 wpa_printf(MSG_DEBUG, "WPS: Too short Wi-Fi Handover Select "
2511 pos = wpabuf_head(wps);
2512 wsc_len = WPA_GET_BE16(pos);
2513 if (wsc_len > wpabuf_len(wps) - 2) {
2514 wpa_printf(MSG_DEBUG, "WPS: Invalid WSC attribute length (%u) "
2515 "in Wi-Fi Handover Select Message", wsc_len);
2520 wpa_hexdump(MSG_DEBUG,
2521 "WPS: WSC attributes in Wi-Fi Handover Select Message",
2523 if (wsc_len < wpabuf_len(wps) - 2) {
2524 wpa_hexdump(MSG_DEBUG,
2525 "WPS: Ignore extra data after WSC attributes",
2526 pos + wsc_len, wpabuf_len(wps) - 2 - wsc_len);
2529 wpabuf_set(&msg, pos, wsc_len);
2530 ret = wps_parse_msg(&msg, &attr);
2532 wpa_printf(MSG_DEBUG, "WPS: Could not parse WSC attributes in "
2533 "Wi-Fi Handover Select Message");
2537 if (attr.oob_dev_password == NULL ||
2538 attr.oob_dev_password_len < WPS_OOB_PUBKEY_HASH_LEN + 2) {
2539 wpa_printf(MSG_DEBUG, "WPS: No Out-of-Band Device Password "
2540 "included in Wi-Fi Handover Select Message");
2545 if (attr.ssid == NULL) {
2546 wpa_printf(MSG_DEBUG, "WPS: No SSID included in Wi-Fi Handover "
2552 wpa_hexdump_ascii(MSG_DEBUG, "WPS: SSID", attr.ssid, attr.ssid_len);
2554 if (attr.mac_addr) {
2555 bssid = attr.mac_addr;
2556 wpa_printf(MSG_DEBUG, "WPS: MAC Address (BSSID): " MACSTR,
2561 wpa_printf(MSG_DEBUG, "WPS: RF Bands: %d", *attr.rf_bands);
2563 if (attr.ap_channel) {
2564 u16 chan = WPA_GET_BE16(attr.ap_channel);
2566 wpa_printf(MSG_DEBUG, "WPS: AP Channel: %d", chan);
2568 if (chan >= 1 && chan <= 13 &&
2569 (attr.rf_bands == NULL || *attr.rf_bands & WPS_RF_24GHZ))
2570 freq = 2407 + 5 * chan;
2571 else if (chan == 14 &&
2572 (attr.rf_bands == NULL ||
2573 *attr.rf_bands & WPS_RF_24GHZ))
2575 else if (chan >= 30 &&
2576 (attr.rf_bands == NULL ||
2577 *attr.rf_bands & WPS_RF_50GHZ))
2578 freq = 5000 + 5 * chan;
2581 wpa_printf(MSG_DEBUG,
2582 "WPS: AP indicated channel %u -> %u MHz",
2587 wpa_hexdump(MSG_DEBUG, "WPS: Out-of-Band Device Password",
2588 attr.oob_dev_password, attr.oob_dev_password_len);
2589 dev_pw_id = WPA_GET_BE16(attr.oob_dev_password +
2590 WPS_OOB_PUBKEY_HASH_LEN);
2591 if (dev_pw_id != DEV_PW_NFC_CONNECTION_HANDOVER) {
2592 wpa_printf(MSG_DEBUG, "WPS: Unexpected OOB Device Password ID "
2593 "%u in Wi-Fi Handover Select Message", dev_pw_id);
2597 wpa_hexdump(MSG_DEBUG, "WPS: AP Public Key hash",
2598 attr.oob_dev_password, WPS_OOB_PUBKEY_HASH_LEN);
2600 ret = wpas_wps_start_nfc(wpa_s, NULL, bssid, NULL, dev_pw_id, 0,
2601 attr.oob_dev_password,
2602 attr.ssid, attr.ssid_len, freq);
2610 int wpas_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
2611 const struct wpabuf *req,
2612 const struct wpabuf *sel)
2614 wpa_printf(MSG_DEBUG, "NFC: WPS connection handover reported");
2615 wpa_hexdump_buf_key(MSG_DEBUG, "WPS: Carrier record in request", req);
2616 wpa_hexdump_buf_key(MSG_DEBUG, "WPS: Carrier record in select", sel);
2617 return wpas_wps_nfc_rx_handover_sel(wpa_s, sel);
2621 int wpas_er_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
2622 const struct wpabuf *req,
2623 const struct wpabuf *sel)
2630 struct wps_parse_attr attr;
2634 * Enrollee/station is always initiator of the NFC connection handover,
2635 * so use the request message here to find Enrollee public key hash.
2637 wps = ndef_parse_wifi(req);
2640 wpa_printf(MSG_DEBUG, "WPS: Received application/vnd.wfa.wsc "
2641 "payload from NFC connection handover");
2642 wpa_hexdump_buf(MSG_DEBUG, "WPS: NFC payload", wps);
2643 if (wpabuf_len(wps) < 2) {
2644 wpa_printf(MSG_DEBUG, "WPS: Too short Wi-Fi Handover Request "
2648 pos = wpabuf_head(wps);
2649 wsc_len = WPA_GET_BE16(pos);
2650 if (wsc_len > wpabuf_len(wps) - 2) {
2651 wpa_printf(MSG_DEBUG, "WPS: Invalid WSC attribute length (%u) "
2652 "in rt Wi-Fi Handover Request Message", wsc_len);
2657 wpa_hexdump(MSG_DEBUG,
2658 "WPS: WSC attributes in Wi-Fi Handover Request Message",
2660 if (wsc_len < wpabuf_len(wps) - 2) {
2661 wpa_hexdump(MSG_DEBUG,
2662 "WPS: Ignore extra data after WSC attributes",
2663 pos + wsc_len, wpabuf_len(wps) - 2 - wsc_len);
2666 wpabuf_set(&msg, pos, wsc_len);
2667 ret = wps_parse_msg(&msg, &attr);
2669 wpa_printf(MSG_DEBUG, "WPS: Could not parse WSC attributes in "
2670 "Wi-Fi Handover Request Message");
2674 if (attr.oob_dev_password == NULL ||
2675 attr.oob_dev_password_len < WPS_OOB_PUBKEY_HASH_LEN + 2) {
2676 wpa_printf(MSG_DEBUG, "WPS: No Out-of-Band Device Password "
2677 "included in Wi-Fi Handover Request Message");
2682 if (attr.uuid_e == NULL) {
2683 wpa_printf(MSG_DEBUG, "WPS: No UUID-E included in Wi-Fi "
2684 "Handover Request Message");
2689 wpa_hexdump(MSG_DEBUG, "WPS: UUID-E", attr.uuid_e, WPS_UUID_LEN);
2691 wpa_hexdump(MSG_DEBUG, "WPS: Out-of-Band Device Password",
2692 attr.oob_dev_password, attr.oob_dev_password_len);
2693 dev_pw_id = WPA_GET_BE16(attr.oob_dev_password +
2694 WPS_OOB_PUBKEY_HASH_LEN);
2695 if (dev_pw_id != DEV_PW_NFC_CONNECTION_HANDOVER) {
2696 wpa_printf(MSG_DEBUG, "WPS: Unexpected OOB Device Password ID "
2697 "%u in Wi-Fi Handover Request Message", dev_pw_id);
2701 wpa_hexdump(MSG_DEBUG, "WPS: Enrollee Public Key hash",
2702 attr.oob_dev_password, WPS_OOB_PUBKEY_HASH_LEN);
2704 ret = wps_registrar_add_nfc_pw_token(wpa_s->wps->registrar,
2705 attr.oob_dev_password,
2706 DEV_PW_NFC_CONNECTION_HANDOVER,
2714 #endif /* CONFIG_WPS_NFC */
2717 static void wpas_wps_dump_ap_info(struct wpa_supplicant *wpa_s)
2720 struct os_reltime now;
2722 if (wpa_debug_level > MSG_DEBUG)
2725 if (wpa_s->wps_ap == NULL)
2728 os_get_reltime(&now);
2730 for (i = 0; i < wpa_s->num_wps_ap; i++) {
2731 struct wps_ap_info *ap = &wpa_s->wps_ap[i];
2732 struct wpa_blacklist *e = wpa_blacklist_get(wpa_s, ap->bssid);
2734 wpa_printf(MSG_DEBUG, "WPS: AP[%d] " MACSTR " type=%d "
2735 "tries=%d last_attempt=%d sec ago blacklist=%d",
2736 (int) i, MAC2STR(ap->bssid), ap->type, ap->tries,
2737 ap->last_attempt.sec > 0 ?
2738 (int) now.sec - (int) ap->last_attempt.sec : -1,
2744 static struct wps_ap_info * wpas_wps_get_ap_info(struct wpa_supplicant *wpa_s,
2749 if (wpa_s->wps_ap == NULL)
2752 for (i = 0; i < wpa_s->num_wps_ap; i++) {
2753 struct wps_ap_info *ap = &wpa_s->wps_ap[i];
2754 if (os_memcmp(ap->bssid, bssid, ETH_ALEN) == 0)
2762 static void wpas_wps_update_ap_info_bss(struct wpa_supplicant *wpa_s,
2763 struct wpa_scan_res *res)
2766 enum wps_ap_info_type type;
2767 struct wps_ap_info *ap;
2770 if (wpa_scan_get_vendor_ie(res, WPS_IE_VENDOR_TYPE) == NULL)
2773 wps = wpa_scan_get_vendor_ie_multi(res, WPS_IE_VENDOR_TYPE);
2777 r = wps_is_addr_authorized(wps, wpa_s->own_addr, 1);
2779 type = WPS_AP_SEL_REG_OUR;
2781 type = WPS_AP_SEL_REG;
2783 type = WPS_AP_NOT_SEL_REG;
2787 ap = wpas_wps_get_ap_info(wpa_s, res->bssid);
2789 if (ap->type != type) {
2790 wpa_printf(MSG_DEBUG, "WPS: AP " MACSTR
2791 " changed type %d -> %d",
2792 MAC2STR(res->bssid), ap->type, type);
2794 if (type != WPS_AP_NOT_SEL_REG)
2795 wpa_blacklist_del(wpa_s, ap->bssid);
2800 ap = os_realloc_array(wpa_s->wps_ap, wpa_s->num_wps_ap + 1,
2801 sizeof(struct wps_ap_info));
2806 ap = &wpa_s->wps_ap[wpa_s->num_wps_ap];
2807 wpa_s->num_wps_ap++;
2809 os_memset(ap, 0, sizeof(*ap));
2810 os_memcpy(ap->bssid, res->bssid, ETH_ALEN);
2812 wpa_printf(MSG_DEBUG, "WPS: AP " MACSTR " type %d added",
2813 MAC2STR(ap->bssid), ap->type);
2817 void wpas_wps_update_ap_info(struct wpa_supplicant *wpa_s,
2818 struct wpa_scan_results *scan_res)
2822 for (i = 0; i < scan_res->num; i++)
2823 wpas_wps_update_ap_info_bss(wpa_s, scan_res->res[i]);
2825 wpas_wps_dump_ap_info(wpa_s);
2829 void wpas_wps_notify_assoc(struct wpa_supplicant *wpa_s, const u8 *bssid)
2831 struct wps_ap_info *ap;
2833 wpa_s->after_wps = 0;
2835 if (!wpa_s->wps_ap_iter)
2837 ap = wpas_wps_get_ap_info(wpa_s, bssid);
2841 os_get_reltime(&ap->last_attempt);