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 */
43 * The minimum time in seconds before trying to associate to a WPS PIN AP that
44 * does not have Selected Registrar TRUE.
46 #ifndef WPS_PIN_TIME_IGNORE_SEL_REG
47 #define WPS_PIN_TIME_IGNORE_SEL_REG 5
48 #endif /* WPS_PIN_TIME_IGNORE_SEL_REG */
50 static void wpas_wps_timeout(void *eloop_ctx, void *timeout_ctx);
51 static void wpas_clear_wps(struct wpa_supplicant *wpa_s);
54 static void wpas_wps_clear_ap_info(struct wpa_supplicant *wpa_s)
56 os_free(wpa_s->wps_ap);
58 wpa_s->num_wps_ap = 0;
59 wpa_s->wps_ap_iter = 0;
63 static void wpas_wps_assoc_with_cred(void *eloop_ctx, void *timeout_ctx)
65 struct wpa_supplicant *wpa_s = eloop_ctx;
66 int use_fast_assoc = timeout_ctx != NULL;
68 wpa_printf(MSG_DEBUG, "WPS: Continuing association after eapol_cb");
69 if (!use_fast_assoc ||
70 wpa_supplicant_fast_associate(wpa_s) != 1)
71 wpa_supplicant_req_scan(wpa_s, 0, 0);
75 static void wpas_wps_assoc_with_cred_cancel(struct wpa_supplicant *wpa_s)
77 eloop_cancel_timeout(wpas_wps_assoc_with_cred, wpa_s, (void *) 0);
78 eloop_cancel_timeout(wpas_wps_assoc_with_cred, wpa_s, (void *) 1);
82 int wpas_wps_eapol_cb(struct wpa_supplicant *wpa_s)
84 if (wpas_p2p_wps_eapol_cb(wpa_s) > 0)
87 if (!wpa_s->wps_success &&
88 wpa_s->current_ssid &&
89 eap_is_wps_pin_enrollee(&wpa_s->current_ssid->eap)) {
90 const u8 *bssid = wpa_s->bssid;
91 if (is_zero_ether_addr(bssid))
92 bssid = wpa_s->pending_bssid;
94 wpa_printf(MSG_DEBUG, "WPS: PIN registration with " MACSTR
95 " did not succeed - continue trying to find "
96 "suitable AP", MAC2STR(bssid));
97 wpa_blacklist_add(wpa_s, bssid);
99 wpa_supplicant_deauthenticate(wpa_s,
100 WLAN_REASON_DEAUTH_LEAVING);
101 wpa_s->reassociate = 1;
102 wpa_supplicant_req_scan(wpa_s,
103 wpa_s->blacklist_cleared ? 5 : 0, 0);
104 wpa_s->blacklist_cleared = 0;
108 wpas_wps_clear_ap_info(wpa_s);
109 eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
110 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && !wpa_s->wps_success)
111 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_FAIL);
113 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && wpa_s->current_ssid &&
114 !(wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
115 int disabled = wpa_s->current_ssid->disabled;
116 unsigned int freq = wpa_s->assoc_freq;
118 struct wpa_ssid *ssid = NULL;
119 int use_fast_assoc = 0;
121 wpa_printf(MSG_DEBUG, "WPS: Network configuration replaced - "
122 "try to associate with the received credential "
124 wpa_s->own_disconnect_req = 1;
125 wpa_supplicant_deauthenticate(wpa_s,
126 WLAN_REASON_DEAUTH_LEAVING);
128 wpa_printf(MSG_DEBUG, "WPS: Current network is "
129 "disabled - wait for user to enable");
132 wpa_s->after_wps = 5;
133 wpa_s->wps_freq = freq;
134 wpa_s->normal_scans = 0;
135 wpa_s->reassociate = 1;
137 wpa_printf(MSG_DEBUG, "WPS: Checking whether fast association "
138 "without a new scan can be used");
139 bss = wpa_supplicant_pick_network(wpa_s, &ssid);
142 struct wps_parse_attr attr;
144 wps = wpa_bss_get_vendor_ie_multi(bss,
146 if (wps && wps_parse_msg(wps, &attr) == 0 &&
148 *attr.wps_state == WPS_STATE_CONFIGURED)
154 * Complete the next step from an eloop timeout to allow pending
155 * driver events related to the disconnection to be processed
156 * first. This makes it less likely for disconnection event to
157 * cause problems with the following connection.
159 wpa_printf(MSG_DEBUG, "WPS: Continue association from timeout");
160 wpas_wps_assoc_with_cred_cancel(wpa_s);
161 eloop_register_timeout(0, 10000,
162 wpas_wps_assoc_with_cred, wpa_s,
163 use_fast_assoc ? (void *) 1 :
168 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && wpa_s->current_ssid) {
169 wpa_printf(MSG_DEBUG, "WPS: Registration completed - waiting "
170 "for external credential processing");
171 wpas_clear_wps(wpa_s);
172 wpa_s->own_disconnect_req = 1;
173 wpa_supplicant_deauthenticate(wpa_s,
174 WLAN_REASON_DEAUTH_LEAVING);
182 static void wpas_wps_security_workaround(struct wpa_supplicant *wpa_s,
183 struct wpa_ssid *ssid,
184 const struct wps_credential *cred)
186 struct wpa_driver_capa capa;
189 struct wpa_ie_data adv;
190 int wpa2 = 0, ccmp = 0;
193 * Many existing WPS APs do not know how to negotiate WPA2 or CCMP in
194 * case they are configured for mixed mode operation (WPA+WPA2 and
195 * TKIP+CCMP). Try to use scan results to figure out whether the AP
196 * actually supports stronger security and select that if the client
197 * has support for it, too.
200 if (wpa_drv_get_capa(wpa_s, &capa))
201 return; /* Unknown what driver supports */
203 if (ssid->ssid == NULL)
205 bss = wpa_bss_get(wpa_s, cred->mac_addr, ssid->ssid, ssid->ssid_len);
207 wpa_printf(MSG_DEBUG, "WPS: The AP was not found from BSS "
208 "table - use credential as-is");
212 wpa_printf(MSG_DEBUG, "WPS: AP found from BSS table");
214 ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
215 if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0) {
217 if (adv.pairwise_cipher & WPA_CIPHER_CCMP)
220 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
221 if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0 &&
222 adv.pairwise_cipher & WPA_CIPHER_CCMP)
226 if (ie == NULL && (ssid->proto & WPA_PROTO_WPA) &&
227 (ssid->pairwise_cipher & WPA_CIPHER_TKIP)) {
229 * TODO: This could be the initial AP configuration and the
230 * Beacon contents could change shortly. Should request a new
231 * scan and delay addition of the network until the updated
232 * scan results are available.
234 wpa_printf(MSG_DEBUG, "WPS: The AP did not yet advertise WPA "
235 "support - use credential as-is");
239 if (ccmp && !(ssid->pairwise_cipher & WPA_CIPHER_CCMP) &&
240 (ssid->pairwise_cipher & WPA_CIPHER_TKIP) &&
241 (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
242 wpa_printf(MSG_DEBUG, "WPS: Add CCMP into the credential "
243 "based on scan results");
244 if (wpa_s->conf->ap_scan == 1)
245 ssid->pairwise_cipher |= WPA_CIPHER_CCMP;
247 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
250 if (wpa2 && !(ssid->proto & WPA_PROTO_RSN) &&
251 (ssid->proto & WPA_PROTO_WPA) &&
252 (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP)) {
253 wpa_printf(MSG_DEBUG, "WPS: Add WPA2 into the credential "
254 "based on scan results");
255 if (wpa_s->conf->ap_scan == 1)
256 ssid->proto |= WPA_PROTO_RSN;
258 ssid->proto = WPA_PROTO_RSN;
263 static void wpas_wps_remove_dup_network(struct wpa_supplicant *wpa_s,
264 struct wpa_ssid *new_ssid)
266 struct wpa_ssid *ssid, *next;
268 for (ssid = wpa_s->conf->ssid, next = ssid ? ssid->next : NULL; ssid;
269 ssid = next, next = ssid ? ssid->next : NULL) {
271 * new_ssid has already been added to the list in
272 * wpas_wps_add_network(), so skip it.
274 if (ssid == new_ssid)
277 if (ssid->bssid_set || new_ssid->bssid_set) {
278 if (ssid->bssid_set != new_ssid->bssid_set)
280 if (os_memcmp(ssid->bssid, new_ssid->bssid, ETH_ALEN) !=
286 if (ssid->ssid_len == 0 || ssid->ssid_len != new_ssid->ssid_len)
289 if (ssid->ssid && new_ssid->ssid) {
290 if (os_memcmp(ssid->ssid, new_ssid->ssid,
291 ssid->ssid_len) != 0)
293 } else if (ssid->ssid || new_ssid->ssid)
296 /* compare security parameters */
297 if (ssid->auth_alg != new_ssid->auth_alg ||
298 ssid->key_mgmt != new_ssid->key_mgmt ||
299 (ssid->group_cipher != new_ssid->group_cipher &&
300 !(ssid->group_cipher & new_ssid->group_cipher &
305 * Some existing WPS APs will send two creds in case they are
306 * configured for mixed mode operation (WPA+WPA2 and TKIP+CCMP).
307 * Try to merge these two creds if they are received in the same
310 if (ssid->wps_run && ssid->wps_run == new_ssid->wps_run &&
311 wpa_key_mgmt_wpa_psk(ssid->key_mgmt)) {
312 if (new_ssid->passphrase && ssid->passphrase &&
313 os_strcmp(new_ssid->passphrase, ssid->passphrase) !=
315 wpa_printf(MSG_DEBUG,
316 "WPS: M8 Creds with different passphrase - do not merge");
320 if (new_ssid->psk_set &&
322 os_memcmp(new_ssid->psk, ssid->psk, 32) != 0)) {
323 wpa_printf(MSG_DEBUG,
324 "WPS: M8 Creds with different PSK - do not merge");
328 if ((new_ssid->passphrase && !ssid->passphrase) ||
329 (!new_ssid->passphrase && ssid->passphrase)) {
330 wpa_printf(MSG_DEBUG,
331 "WPS: M8 Creds with different passphrase/PSK type - do not merge");
335 wpa_printf(MSG_DEBUG,
336 "WPS: Workaround - merge likely WPA/WPA2-mixed mode creds in same M8 message");
337 new_ssid->proto |= ssid->proto;
338 new_ssid->pairwise_cipher |= ssid->pairwise_cipher;
341 * proto and pairwise_cipher difference matter for
342 * non-mixed-mode creds.
344 if (ssid->proto != new_ssid->proto ||
345 ssid->pairwise_cipher != new_ssid->pairwise_cipher)
349 /* Remove the duplicated older network entry. */
350 wpa_printf(MSG_DEBUG, "Remove duplicate network %d", ssid->id);
351 wpas_notify_network_removed(wpa_s, ssid);
352 if (wpa_s->current_ssid == ssid)
353 wpa_s->current_ssid = NULL;
354 wpa_config_remove_network(wpa_s->conf, ssid->id);
359 static int wpa_supplicant_wps_cred(void *ctx,
360 const struct wps_credential *cred)
362 struct wpa_supplicant *wpa_s = ctx;
363 struct wpa_ssid *ssid = wpa_s->current_ssid;
365 #ifdef CONFIG_WPS_REG_DISABLE_OPEN
367 #endif /* CONFIG_WPS_REG_DISABLE_OPEN */
369 if ((wpa_s->conf->wps_cred_processing == 1 ||
370 wpa_s->conf->wps_cred_processing == 2) && cred->cred_attr) {
371 size_t blen = cred->cred_attr_len * 2 + 1;
372 char *buf = os_malloc(blen);
374 wpa_snprintf_hex(buf, blen,
375 cred->cred_attr, cred->cred_attr_len);
376 wpa_msg(wpa_s, MSG_INFO, "%s%s",
377 WPS_EVENT_CRED_RECEIVED, buf);
381 wpas_notify_wps_credential(wpa_s, cred);
383 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_CRED_RECEIVED);
385 wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
386 cred->cred_attr, cred->cred_attr_len);
388 if (wpa_s->conf->wps_cred_processing == 1)
391 wpa_hexdump_ascii(MSG_DEBUG, "WPS: SSID", cred->ssid, cred->ssid_len);
392 wpa_printf(MSG_DEBUG, "WPS: Authentication Type 0x%x",
394 wpa_printf(MSG_DEBUG, "WPS: Encryption Type 0x%x", cred->encr_type);
395 wpa_printf(MSG_DEBUG, "WPS: Network Key Index %d", cred->key_idx);
396 wpa_hexdump_key(MSG_DEBUG, "WPS: Network Key",
397 cred->key, cred->key_len);
398 wpa_printf(MSG_DEBUG, "WPS: MAC Address " MACSTR,
399 MAC2STR(cred->mac_addr));
401 auth_type = cred->auth_type;
402 if (auth_type == (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) {
403 wpa_printf(MSG_DEBUG, "WPS: Workaround - convert mixed-mode "
404 "auth_type into WPA2PSK");
405 auth_type = WPS_AUTH_WPA2PSK;
408 if (auth_type != WPS_AUTH_OPEN &&
409 auth_type != WPS_AUTH_WPAPSK &&
410 auth_type != WPS_AUTH_WPA2PSK) {
411 wpa_printf(MSG_DEBUG, "WPS: Ignored credentials for "
412 "unsupported authentication type 0x%x",
417 if (auth_type == WPS_AUTH_WPAPSK || auth_type == WPS_AUTH_WPA2PSK) {
418 if (cred->key_len < 8 || cred->key_len > 2 * PMK_LEN) {
419 wpa_printf(MSG_ERROR, "WPS: Reject PSK credential with "
420 "invalid Network Key length %lu",
421 (unsigned long) cred->key_len);
426 if (ssid && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
427 wpa_printf(MSG_DEBUG, "WPS: Replace WPS network block based "
428 "on the received credential");
429 #ifdef CONFIG_WPS_REG_DISABLE_OPEN
430 if (ssid->eap.identity &&
431 ssid->eap.identity_len == WSC_ID_REGISTRAR_LEN &&
432 os_memcmp(ssid->eap.identity, WSC_ID_REGISTRAR,
433 WSC_ID_REGISTRAR_LEN) == 0)
435 #endif /* CONFIG_WPS_REG_DISABLE_OPEN */
436 os_free(ssid->eap.identity);
437 ssid->eap.identity = NULL;
438 ssid->eap.identity_len = 0;
439 os_free(ssid->eap.phase1);
440 ssid->eap.phase1 = NULL;
441 os_free(ssid->eap.eap_methods);
442 ssid->eap.eap_methods = NULL;
443 if (!ssid->p2p_group) {
447 ssid->disabled_until.sec = 0;
448 ssid->disabled_until.usec = 0;
449 ssid->auth_failures = 0;
451 wpa_printf(MSG_DEBUG, "WPS: Create a new network based on the "
452 "received credential");
453 ssid = wpa_config_add_network(wpa_s->conf);
456 if (wpa_s->current_ssid) {
458 * Should the GO issue multiple credentials for some
459 * reason, each credential should be marked as a
460 * temporary P2P group similarly to the one that gets
461 * marked as such based on the pre-configured values
462 * used for the WPS network block.
464 ssid->p2p_group = wpa_s->current_ssid->p2p_group;
465 ssid->temporary = wpa_s->current_ssid->temporary;
467 wpas_notify_network_added(wpa_s, ssid);
470 wpa_config_set_network_defaults(ssid);
471 ssid->wps_run = wpa_s->wps_run;
474 ssid->ssid = os_malloc(cred->ssid_len);
476 os_memcpy(ssid->ssid, cred->ssid, cred->ssid_len);
477 ssid->ssid_len = cred->ssid_len;
480 switch (cred->encr_type) {
484 ssid->pairwise_cipher = WPA_CIPHER_TKIP;
487 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
488 if (wpa_s->drv_capa_known &&
489 (wpa_s->drv_enc & WPA_DRIVER_CAPA_ENC_GCMP)) {
490 ssid->pairwise_cipher |= WPA_CIPHER_GCMP;
491 ssid->group_cipher |= WPA_CIPHER_GCMP;
498 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
499 ssid->key_mgmt = WPA_KEY_MGMT_NONE;
501 #ifdef CONFIG_WPS_REG_DISABLE_OPEN
503 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OPEN_NETWORK
504 "id=%d - Credentials for an open "
505 "network disabled by default - use "
506 "'select_network %d' to enable",
510 #endif /* CONFIG_WPS_REG_DISABLE_OPEN */
512 case WPS_AUTH_WPAPSK:
513 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
514 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
515 ssid->proto = WPA_PROTO_WPA;
517 case WPS_AUTH_WPA2PSK:
518 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
519 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
520 ssid->proto = WPA_PROTO_RSN;
524 if (ssid->key_mgmt == WPA_KEY_MGMT_PSK) {
525 if (cred->key_len == 2 * PMK_LEN) {
526 if (hexstr2bin((const char *) cred->key, ssid->psk,
528 wpa_printf(MSG_ERROR, "WPS: Invalid Network "
533 ssid->export_keys = 1;
534 } else if (cred->key_len >= 8 && cred->key_len < 2 * PMK_LEN) {
535 os_free(ssid->passphrase);
536 ssid->passphrase = os_malloc(cred->key_len + 1);
537 if (ssid->passphrase == NULL)
539 os_memcpy(ssid->passphrase, cred->key, cred->key_len);
540 ssid->passphrase[cred->key_len] = '\0';
541 wpa_config_update_psk(ssid);
542 ssid->export_keys = 1;
544 wpa_printf(MSG_ERROR, "WPS: Invalid Network Key "
546 (unsigned long) cred->key_len);
551 wpas_wps_security_workaround(wpa_s, ssid, cred);
553 wpas_wps_remove_dup_network(wpa_s, ssid);
555 #ifndef CONFIG_NO_CONFIG_WRITE
556 if (wpa_s->conf->update_config &&
557 wpa_config_write(wpa_s->confname, wpa_s->conf)) {
558 wpa_printf(MSG_DEBUG, "WPS: Failed to update configuration");
561 #endif /* CONFIG_NO_CONFIG_WRITE */
564 * Optimize the post-WPS scan based on the channel used during
565 * the provisioning in case EAP-Failure is not received.
567 wpa_s->after_wps = 5;
568 wpa_s->wps_freq = wpa_s->assoc_freq;
574 static void wpa_supplicant_wps_event_m2d(struct wpa_supplicant *wpa_s,
575 struct wps_event_m2d *m2d)
577 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_M2D
578 "dev_password_id=%d config_error=%d",
579 m2d->dev_password_id, m2d->config_error);
580 wpas_notify_wps_event_m2d(wpa_s, m2d);
582 if (wpa_s->parent && wpa_s->parent != wpa_s) {
583 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_M2D
584 "dev_password_id=%d config_error=%d",
585 m2d->dev_password_id, m2d->config_error);
587 if (m2d->config_error == WPS_CFG_MULTIPLE_PBC_DETECTED) {
589 * Notify P2P from eloop timeout to avoid issues with the
590 * interface getting removed while processing a message.
592 eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb, wpa_s,
595 #endif /* CONFIG_P2P */
599 static void wpas_wps_clear_timeout(void *eloop_ctx, void *timeout_ctx)
601 struct wpa_supplicant *wpa_s = eloop_ctx;
602 wpa_printf(MSG_DEBUG, "WPS: Clear WPS network from timeout");
603 wpas_clear_wps(wpa_s);
607 static void wpa_supplicant_wps_event_fail(struct wpa_supplicant *wpa_s,
608 struct wps_event_fail *fail)
610 if (fail->error_indication > 0 &&
611 fail->error_indication < NUM_WPS_EI_VALUES) {
612 wpa_msg(wpa_s, MSG_INFO,
613 WPS_EVENT_FAIL "msg=%d config_error=%d reason=%d (%s)",
614 fail->msg, fail->config_error, fail->error_indication,
615 wps_ei_str(fail->error_indication));
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 reason=%d (%s)",
619 fail->msg, fail->config_error,
620 fail->error_indication,
621 wps_ei_str(fail->error_indication));
623 wpa_msg(wpa_s, MSG_INFO,
624 WPS_EVENT_FAIL "msg=%d config_error=%d",
625 fail->msg, fail->config_error);
626 if (wpa_s->parent && wpa_s->parent != wpa_s)
627 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
628 "msg=%d config_error=%d",
629 fail->msg, fail->config_error);
633 * Need to allow WPS processing to complete, e.g., by sending WSC_NACK.
635 wpa_printf(MSG_DEBUG, "WPS: Register timeout to clear WPS network");
636 eloop_cancel_timeout(wpas_wps_clear_timeout, wpa_s, NULL);
637 eloop_register_timeout(0, 100000, wpas_wps_clear_timeout, wpa_s, NULL);
639 wpas_notify_wps_event_fail(wpa_s, fail);
640 wpas_p2p_wps_failed(wpa_s, fail);
644 static void wpas_wps_reenable_networks_cb(void *eloop_ctx, void *timeout_ctx);
646 static void wpas_wps_reenable_networks(struct wpa_supplicant *wpa_s)
648 struct wpa_ssid *ssid;
651 eloop_cancel_timeout(wpas_wps_reenable_networks_cb, wpa_s, NULL);
653 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
654 if (ssid->disabled_for_connect && ssid->disabled) {
655 ssid->disabled_for_connect = 0;
657 wpas_notify_network_enabled_changed(wpa_s, ssid);
663 #ifndef CONFIG_NO_CONFIG_WRITE
664 if (wpa_s->conf->update_config &&
665 wpa_config_write(wpa_s->confname, wpa_s->conf)) {
666 wpa_printf(MSG_DEBUG, "WPS: Failed to update "
669 #endif /* CONFIG_NO_CONFIG_WRITE */
674 static void wpas_wps_reenable_networks_cb(void *eloop_ctx, void *timeout_ctx)
676 struct wpa_supplicant *wpa_s = eloop_ctx;
677 /* Enable the networks disabled during wpas_wps_reassoc */
678 wpas_wps_reenable_networks(wpa_s);
682 static void wpa_supplicant_wps_event_success(struct wpa_supplicant *wpa_s)
684 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_SUCCESS);
685 wpa_s->wps_success = 1;
686 wpas_notify_wps_event_success(wpa_s);
687 if (wpa_s->current_ssid)
688 wpas_clear_temp_disabled(wpa_s, wpa_s->current_ssid, 1);
689 wpa_s->extra_blacklist_count = 0;
692 * Enable the networks disabled during wpas_wps_reassoc after 10
693 * seconds. The 10 seconds timer is to allow the data connection to be
694 * formed before allowing other networks to be selected.
696 eloop_register_timeout(10, 0, wpas_wps_reenable_networks_cb, wpa_s,
699 wpas_p2p_wps_success(wpa_s, wpa_s->bssid, 0);
703 static void wpa_supplicant_wps_event_er_ap_add(struct wpa_supplicant *wpa_s,
704 struct wps_event_er_ap *ap)
707 char dev_type[WPS_DEV_TYPE_BUFSIZE];
709 uuid_bin2str(ap->uuid, uuid_str, sizeof(uuid_str));
710 if (ap->pri_dev_type)
711 wps_dev_type_bin2str(ap->pri_dev_type, dev_type,
716 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_ADD "%s " MACSTR
717 " pri_dev_type=%s wps_state=%d |%s|%s|%s|%s|%s|%s|",
718 uuid_str, MAC2STR(ap->mac_addr), dev_type, ap->wps_state,
719 ap->friendly_name ? ap->friendly_name : "",
720 ap->manufacturer ? ap->manufacturer : "",
721 ap->model_description ? ap->model_description : "",
722 ap->model_name ? ap->model_name : "",
723 ap->manufacturer_url ? ap->manufacturer_url : "",
724 ap->model_url ? ap->model_url : "");
728 static void wpa_supplicant_wps_event_er_ap_remove(struct wpa_supplicant *wpa_s,
729 struct wps_event_er_ap *ap)
732 uuid_bin2str(ap->uuid, uuid_str, sizeof(uuid_str));
733 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_REMOVE "%s", uuid_str);
737 static void wpa_supplicant_wps_event_er_enrollee_add(
738 struct wpa_supplicant *wpa_s, struct wps_event_er_enrollee *enrollee)
741 char dev_type[WPS_DEV_TYPE_BUFSIZE];
743 uuid_bin2str(enrollee->uuid, uuid_str, sizeof(uuid_str));
744 if (enrollee->pri_dev_type)
745 wps_dev_type_bin2str(enrollee->pri_dev_type, dev_type,
750 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_ENROLLEE_ADD "%s " MACSTR
751 " M1=%d config_methods=0x%x dev_passwd_id=%d pri_dev_type=%s "
753 uuid_str, MAC2STR(enrollee->mac_addr), enrollee->m1_received,
754 enrollee->config_methods, enrollee->dev_passwd_id, dev_type,
755 enrollee->dev_name ? enrollee->dev_name : "",
756 enrollee->manufacturer ? enrollee->manufacturer : "",
757 enrollee->model_name ? enrollee->model_name : "",
758 enrollee->model_number ? enrollee->model_number : "",
759 enrollee->serial_number ? enrollee->serial_number : "");
763 static void wpa_supplicant_wps_event_er_enrollee_remove(
764 struct wpa_supplicant *wpa_s, struct wps_event_er_enrollee *enrollee)
767 uuid_bin2str(enrollee->uuid, uuid_str, sizeof(uuid_str));
768 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_ENROLLEE_REMOVE "%s " MACSTR,
769 uuid_str, MAC2STR(enrollee->mac_addr));
773 static void wpa_supplicant_wps_event_er_ap_settings(
774 struct wpa_supplicant *wpa_s,
775 struct wps_event_er_ap_settings *ap_settings)
779 const struct wps_credential *cred = ap_settings->cred;
782 if (cred->auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) {
783 if (cred->key_len >= 8 && cred->key_len <= 64) {
784 os_memcpy(key_str, cred->key, cred->key_len);
785 key_str[cred->key_len] = '\0';
789 uuid_bin2str(ap_settings->uuid, uuid_str, sizeof(uuid_str));
790 /* Use wpa_msg_ctrl to avoid showing the key in debug log */
791 wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_SETTINGS
792 "uuid=%s ssid=%s auth_type=0x%04x encr_type=0x%04x "
794 uuid_str, wpa_ssid_txt(cred->ssid, cred->ssid_len),
795 cred->auth_type, cred->encr_type, key_str);
799 static void wpa_supplicant_wps_event_er_set_sel_reg(
800 struct wpa_supplicant *wpa_s,
801 struct wps_event_er_set_selected_registrar *ev)
805 uuid_bin2str(ev->uuid, uuid_str, sizeof(uuid_str));
807 case WPS_ER_SET_SEL_REG_START:
808 wpa_msg(wpa_s, MSG_DEBUG, WPS_EVENT_ER_SET_SEL_REG
809 "uuid=%s state=START sel_reg=%d dev_passwd_id=%u "
810 "sel_reg_config_methods=0x%x",
811 uuid_str, ev->sel_reg, ev->dev_passwd_id,
812 ev->sel_reg_config_methods);
814 case WPS_ER_SET_SEL_REG_DONE:
815 wpa_msg(wpa_s, MSG_DEBUG, WPS_EVENT_ER_SET_SEL_REG
816 "uuid=%s state=DONE", uuid_str);
818 case WPS_ER_SET_SEL_REG_FAILED:
819 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_SET_SEL_REG
820 "uuid=%s state=FAILED", uuid_str);
826 static void wpa_supplicant_wps_event(void *ctx, enum wps_event event,
827 union wps_event_data *data)
829 struct wpa_supplicant *wpa_s = ctx;
832 wpa_supplicant_wps_event_m2d(wpa_s, &data->m2d);
835 wpa_supplicant_wps_event_fail(wpa_s, &data->fail);
838 wpa_supplicant_wps_event_success(wpa_s);
840 case WPS_EV_PWD_AUTH_FAIL:
842 if (wpa_s->ap_iface && data->pwd_auth_fail.enrollee)
843 wpa_supplicant_ap_pwd_auth_fail(wpa_s);
844 #endif /* CONFIG_AP */
846 case WPS_EV_PBC_OVERLAP:
848 case WPS_EV_PBC_TIMEOUT:
850 case WPS_EV_PBC_ACTIVE:
851 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ACTIVE);
853 case WPS_EV_PBC_DISABLE:
854 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_DISABLE);
856 case WPS_EV_ER_AP_ADD:
857 wpa_supplicant_wps_event_er_ap_add(wpa_s, &data->ap);
859 case WPS_EV_ER_AP_REMOVE:
860 wpa_supplicant_wps_event_er_ap_remove(wpa_s, &data->ap);
862 case WPS_EV_ER_ENROLLEE_ADD:
863 wpa_supplicant_wps_event_er_enrollee_add(wpa_s,
866 case WPS_EV_ER_ENROLLEE_REMOVE:
867 wpa_supplicant_wps_event_er_enrollee_remove(wpa_s,
870 case WPS_EV_ER_AP_SETTINGS:
871 wpa_supplicant_wps_event_er_ap_settings(wpa_s,
874 case WPS_EV_ER_SET_SELECTED_REGISTRAR:
875 wpa_supplicant_wps_event_er_set_sel_reg(wpa_s,
878 case WPS_EV_AP_PIN_SUCCESS:
884 static int wpa_supplicant_wps_rf_band(void *ctx)
886 struct wpa_supplicant *wpa_s = ctx;
888 if (!wpa_s->current_ssid || !wpa_s->assoc_freq)
891 return (wpa_s->assoc_freq > 2484) ? WPS_RF_50GHZ : WPS_RF_24GHZ;
895 enum wps_request_type wpas_wps_get_req_type(struct wpa_ssid *ssid)
897 if (eap_is_wps_pbc_enrollee(&ssid->eap) ||
898 eap_is_wps_pin_enrollee(&ssid->eap))
899 return WPS_REQ_ENROLLEE;
901 return WPS_REQ_REGISTRAR;
905 static void wpas_clear_wps(struct wpa_supplicant *wpa_s)
908 struct wpa_ssid *ssid, *remove_ssid = NULL, *prev_current;
910 wpa_s->after_wps = 0;
911 wpa_s->known_wps_freq = 0;
913 prev_current = wpa_s->current_ssid;
915 /* Enable the networks disabled during wpas_wps_reassoc */
916 wpas_wps_reenable_networks(wpa_s);
918 eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
919 eloop_cancel_timeout(wpas_wps_clear_timeout, wpa_s, NULL);
921 /* Remove any existing WPS network from configuration */
922 ssid = wpa_s->conf->ssid;
924 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
925 if (ssid == wpa_s->current_ssid) {
926 wpa_s->own_disconnect_req = 1;
927 wpa_supplicant_deauthenticate(
928 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
936 if (prev_current == remove_ssid) {
937 wpa_sm_set_config(wpa_s->wpa, NULL);
938 eapol_sm_notify_config(wpa_s->eapol, NULL,
941 wpas_notify_network_removed(wpa_s, remove_ssid);
942 wpa_config_remove_network(wpa_s->conf, id);
946 wpas_wps_clear_ap_info(wpa_s);
950 static void wpas_wps_timeout(void *eloop_ctx, void *timeout_ctx)
952 struct wpa_supplicant *wpa_s = eloop_ctx;
953 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_TIMEOUT "Requested operation timed "
955 wpas_clear_wps(wpa_s);
959 static struct wpa_ssid * wpas_wps_add_network(struct wpa_supplicant *wpa_s,
960 int registrar, const u8 *dev_addr,
963 struct wpa_ssid *ssid;
965 ssid = wpa_config_add_network(wpa_s->conf);
968 wpas_notify_network_added(wpa_s, ssid);
969 wpa_config_set_network_defaults(ssid);
971 if (wpa_config_set(ssid, "key_mgmt", "WPS", 0) < 0 ||
972 wpa_config_set(ssid, "eap", "WSC", 0) < 0 ||
973 wpa_config_set(ssid, "identity", registrar ?
974 "\"" WSC_ID_REGISTRAR "\"" :
975 "\"" WSC_ID_ENROLLEE "\"", 0) < 0) {
976 wpas_notify_network_removed(wpa_s, ssid);
977 wpa_config_remove_network(wpa_s->conf, ssid->id);
983 os_memcpy(ssid->go_p2p_dev_addr, dev_addr, ETH_ALEN);
984 #endif /* CONFIG_P2P */
990 #endif /* CONFIG_P2P */
992 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
996 * Note: With P2P, the SSID may change at the time the WPS
997 * provisioning is started, so better not filter the AP based
998 * on the current SSID in the scan results.
1001 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1002 if (os_memcmp(bssid, bss->bssid, ETH_ALEN) != 0)
1005 os_free(ssid->ssid);
1006 ssid->ssid = os_malloc(bss->ssid_len);
1007 if (ssid->ssid == NULL)
1009 os_memcpy(ssid->ssid, bss->ssid, bss->ssid_len);
1010 ssid->ssid_len = bss->ssid_len;
1011 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Picked SSID from "
1013 ssid->ssid, ssid->ssid_len);
1018 wpa_printf(MSG_DEBUG, "WPS: More than one SSID found "
1019 "for the AP; use wildcard");
1020 os_free(ssid->ssid);
1024 #endif /* CONFIG_P2P */
1031 static void wpas_wps_temp_disable(struct wpa_supplicant *wpa_s,
1032 struct wpa_ssid *selected)
1034 struct wpa_ssid *ssid;
1036 if (wpa_s->current_ssid) {
1037 wpa_s->own_disconnect_req = 1;
1038 wpa_supplicant_deauthenticate(
1039 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1042 /* Mark all other networks disabled and trigger reassociation */
1043 ssid = wpa_s->conf->ssid;
1045 int was_disabled = ssid->disabled;
1046 ssid->disabled_for_connect = 0;
1048 * In case the network object corresponds to a persistent group
1049 * then do not send out network disabled signal. In addition,
1050 * do not change disabled status of persistent network objects
1051 * from 2 to 1 should we connect to another network.
1053 if (was_disabled != 2) {
1054 ssid->disabled = ssid != selected;
1055 if (was_disabled != ssid->disabled) {
1057 ssid->disabled_for_connect = 1;
1058 wpas_notify_network_enabled_changed(wpa_s,
1067 static void wpas_wps_reassoc(struct wpa_supplicant *wpa_s,
1068 struct wpa_ssid *selected, const u8 *bssid,
1071 struct wpa_bss *bss;
1074 if (wpa_s->wps_run == 0)
1076 wpa_s->after_wps = 0;
1077 wpa_s->known_wps_freq = 0;
1079 wpa_s->after_wps = 5;
1080 wpa_s->wps_freq = freq;
1082 bss = wpa_bss_get_bssid_latest(wpa_s, bssid);
1083 if (bss && bss->freq > 0) {
1084 wpa_s->known_wps_freq = 1;
1085 wpa_s->wps_freq = bss->freq;
1089 wpas_wps_temp_disable(wpa_s, selected);
1091 wpa_s->disconnected = 0;
1092 wpa_s->reassociate = 1;
1093 wpa_s->scan_runs = 0;
1094 wpa_s->normal_scans = 0;
1095 wpa_s->wps_success = 0;
1096 wpa_s->blacklist_cleared = 0;
1098 wpa_supplicant_cancel_sched_scan(wpa_s);
1099 wpa_supplicant_req_scan(wpa_s, 0, 0);
1103 int wpas_wps_start_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
1106 struct wpa_ssid *ssid;
1109 if (wpa_s->ap_iface) {
1110 wpa_printf(MSG_DEBUG,
1111 "WPS: Reject request to start Registrar(as station) operation while AP mode is enabled");
1114 #endif /* CONFIG_AP */
1115 wpas_clear_wps(wpa_s);
1116 ssid = wpas_wps_add_network(wpa_s, 0, NULL, bssid);
1119 ssid->temporary = 1;
1120 ssid->p2p_group = p2p_group;
1122 if (p2p_group && wpa_s->go_params && wpa_s->go_params->ssid_len) {
1123 ssid->ssid = os_zalloc(wpa_s->go_params->ssid_len + 1);
1125 ssid->ssid_len = wpa_s->go_params->ssid_len;
1126 os_memcpy(ssid->ssid, wpa_s->go_params->ssid,
1128 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Use specific AP "
1129 "SSID", ssid->ssid, ssid->ssid_len);
1132 #endif /* CONFIG_P2P */
1133 if (wpa_config_set(ssid, "phase1", "\"pbc=1\"", 0) < 0)
1135 if (wpa_s->wps_fragment_size)
1136 ssid->eap.fragment_size = wpa_s->wps_fragment_size;
1137 eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
1139 wpas_wps_reassoc(wpa_s, ssid, bssid, 0);
1144 static int wpas_wps_start_dev_pw(struct wpa_supplicant *wpa_s,
1145 const u8 *dev_addr, const u8 *bssid,
1146 const char *pin, int p2p_group, u16 dev_pw_id,
1147 const u8 *peer_pubkey_hash,
1148 const u8 *ssid_val, size_t ssid_len, int freq)
1150 struct wpa_ssid *ssid;
1151 char val[128 + 2 * WPS_OOB_PUBKEY_HASH_LEN];
1152 unsigned int rpin = 0;
1153 char hash[2 * WPS_OOB_PUBKEY_HASH_LEN + 10];
1156 if (wpa_s->ap_iface) {
1157 wpa_printf(MSG_DEBUG,
1158 "WPS: Reject request to start Registrar(as station) operation while AP mode is enabled");
1161 #endif /* CONFIG_AP */
1162 wpas_clear_wps(wpa_s);
1163 if (bssid && is_zero_ether_addr(bssid))
1165 ssid = wpas_wps_add_network(wpa_s, 0, dev_addr, bssid);
1167 wpa_printf(MSG_DEBUG, "WPS: Could not add network");
1170 ssid->temporary = 1;
1171 ssid->p2p_group = p2p_group;
1173 ssid->ssid = os_malloc(ssid_len);
1175 os_memcpy(ssid->ssid, ssid_val, ssid_len);
1176 ssid->ssid_len = ssid_len;
1179 if (peer_pubkey_hash) {
1180 os_memcpy(hash, " pkhash=", 8);
1181 wpa_snprintf_hex_uppercase(hash + 8, sizeof(hash) - 8,
1183 WPS_OOB_PUBKEY_HASH_LEN);
1188 if (p2p_group && wpa_s->go_params && wpa_s->go_params->ssid_len) {
1189 ssid->ssid = os_zalloc(wpa_s->go_params->ssid_len + 1);
1191 ssid->ssid_len = wpa_s->go_params->ssid_len;
1192 os_memcpy(ssid->ssid, wpa_s->go_params->ssid,
1194 wpa_hexdump_ascii(MSG_DEBUG, "WPS: Use specific AP "
1195 "SSID", ssid->ssid, ssid->ssid_len);
1198 #endif /* CONFIG_P2P */
1200 os_snprintf(val, sizeof(val), "\"pin=%s dev_pw_id=%u%s\"",
1201 pin, dev_pw_id, hash);
1202 else if (pin == NULL && dev_pw_id == DEV_PW_NFC_CONNECTION_HANDOVER) {
1203 os_snprintf(val, sizeof(val), "\"dev_pw_id=%u%s\"",
1206 rpin = wps_generate_pin();
1207 os_snprintf(val, sizeof(val), "\"pin=%08d dev_pw_id=%u%s\"",
1208 rpin, dev_pw_id, hash);
1210 if (wpa_config_set(ssid, "phase1", val, 0) < 0) {
1211 wpa_printf(MSG_DEBUG, "WPS: Failed to set phase1 '%s'", val);
1214 if (wpa_s->wps_fragment_size)
1215 ssid->eap.fragment_size = wpa_s->wps_fragment_size;
1216 eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
1218 wpa_s->wps_ap_iter = 1;
1219 wpas_wps_reassoc(wpa_s, ssid, bssid, freq);
1224 int wpas_wps_start_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
1225 const char *pin, int p2p_group, u16 dev_pw_id)
1227 os_get_reltime(&wpa_s->wps_pin_start_time);
1228 return wpas_wps_start_dev_pw(wpa_s, NULL, bssid, pin, p2p_group,
1229 dev_pw_id, NULL, NULL, 0, 0);
1233 /* Cancel the wps pbc/pin requests */
1234 int wpas_wps_cancel(struct wpa_supplicant *wpa_s)
1237 if (wpa_s->ap_iface) {
1238 wpa_printf(MSG_DEBUG, "WPS: Cancelling in AP mode");
1239 return wpa_supplicant_ap_wps_cancel(wpa_s);
1241 #endif /* CONFIG_AP */
1243 if (wpa_s->wpa_state == WPA_SCANNING ||
1244 wpa_s->wpa_state == WPA_DISCONNECTED) {
1245 wpa_printf(MSG_DEBUG, "WPS: Cancel operation - cancel scan");
1246 wpa_supplicant_cancel_scan(wpa_s);
1247 wpas_clear_wps(wpa_s);
1248 } else if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1249 wpa_printf(MSG_DEBUG, "WPS: Cancel operation - "
1251 wpa_s->own_disconnect_req = 1;
1252 wpa_supplicant_deauthenticate(wpa_s,
1253 WLAN_REASON_DEAUTH_LEAVING);
1254 wpas_clear_wps(wpa_s);
1256 wpas_wps_reenable_networks(wpa_s);
1257 wpas_wps_clear_ap_info(wpa_s);
1258 if (eloop_cancel_timeout(wpas_wps_clear_timeout, wpa_s, NULL) >
1260 wpas_clear_wps(wpa_s);
1263 wpa_s->after_wps = 0;
1269 int wpas_wps_start_reg(struct wpa_supplicant *wpa_s, const u8 *bssid,
1270 const char *pin, struct wps_new_ap_settings *settings)
1272 struct wpa_ssid *ssid;
1278 if (wpa_s->ap_iface) {
1279 wpa_printf(MSG_DEBUG,
1280 "WPS: Reject request to start Registrar(as station) operation while AP mode is enabled");
1283 #endif /* CONFIG_AP */
1286 wpas_clear_wps(wpa_s);
1287 ssid = wpas_wps_add_network(wpa_s, 1, NULL, bssid);
1290 ssid->temporary = 1;
1292 end = pos + sizeof(val);
1293 res = os_snprintf(pos, end - pos, "\"pin=%s", pin);
1294 if (os_snprintf_error(end - pos, res))
1298 res = os_snprintf(pos, end - pos, " new_ssid=%s new_auth=%s "
1299 "new_encr=%s new_key=%s",
1300 settings->ssid_hex, settings->auth,
1301 settings->encr, settings->key_hex);
1302 if (os_snprintf_error(end - pos, res))
1306 res = os_snprintf(pos, end - pos, "\"");
1307 if (os_snprintf_error(end - pos, res))
1309 if (wpa_config_set(ssid, "phase1", val, 0) < 0)
1311 if (wpa_s->wps_fragment_size)
1312 ssid->eap.fragment_size = wpa_s->wps_fragment_size;
1313 eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
1315 wpas_wps_reassoc(wpa_s, ssid, bssid, 0);
1320 static int wpas_wps_new_psk_cb(void *ctx, const u8 *mac_addr,
1321 const u8 *p2p_dev_addr, const u8 *psk,
1324 if (is_zero_ether_addr(p2p_dev_addr)) {
1325 wpa_printf(MSG_DEBUG,
1326 "Received new WPA/WPA2-PSK from WPS for STA " MACSTR,
1329 wpa_printf(MSG_DEBUG,
1330 "Received new WPA/WPA2-PSK from WPS for STA " MACSTR
1331 " P2P Device Addr " MACSTR,
1332 MAC2STR(mac_addr), MAC2STR(p2p_dev_addr));
1334 wpa_hexdump_key(MSG_DEBUG, "Per-device PSK", psk, psk_len);
1342 static void wpas_wps_pin_needed_cb(void *ctx, const u8 *uuid_e,
1343 const struct wps_device_data *dev)
1345 char uuid[40], txt[400];
1347 char devtype[WPS_DEV_TYPE_BUFSIZE];
1348 if (uuid_bin2str(uuid_e, uuid, sizeof(uuid)))
1350 wpa_printf(MSG_DEBUG, "WPS: PIN needed for UUID-E %s", uuid);
1351 len = os_snprintf(txt, sizeof(txt), "WPS-EVENT-PIN-NEEDED %s " MACSTR
1352 " [%s|%s|%s|%s|%s|%s]",
1353 uuid, MAC2STR(dev->mac_addr), dev->device_name,
1354 dev->manufacturer, dev->model_name,
1355 dev->model_number, dev->serial_number,
1356 wps_dev_type_bin2str(dev->pri_dev_type, devtype,
1358 if (!os_snprintf_error(sizeof(txt), len))
1359 wpa_printf(MSG_INFO, "%s", txt);
1363 static void wpas_wps_set_sel_reg_cb(void *ctx, int sel_reg, u16 dev_passwd_id,
1364 u16 sel_reg_config_methods)
1366 #ifdef CONFIG_WPS_ER
1367 struct wpa_supplicant *wpa_s = ctx;
1369 if (wpa_s->wps_er == NULL)
1371 wpa_printf(MSG_DEBUG, "WPS ER: SetSelectedRegistrar - sel_reg=%d "
1372 "dev_password_id=%u sel_reg_config_methods=0x%x",
1373 sel_reg, dev_passwd_id, sel_reg_config_methods);
1374 wps_er_set_sel_reg(wpa_s->wps_er, sel_reg, dev_passwd_id,
1375 sel_reg_config_methods);
1376 #endif /* CONFIG_WPS_ER */
1380 static u16 wps_fix_config_methods(u16 config_methods)
1382 if ((config_methods &
1383 (WPS_CONFIG_DISPLAY | WPS_CONFIG_VIRT_DISPLAY |
1384 WPS_CONFIG_PHY_DISPLAY)) == WPS_CONFIG_DISPLAY) {
1385 wpa_printf(MSG_INFO, "WPS: Converting display to "
1386 "virtual_display for WPS 2.0 compliance");
1387 config_methods |= WPS_CONFIG_VIRT_DISPLAY;
1389 if ((config_methods &
1390 (WPS_CONFIG_PUSHBUTTON | WPS_CONFIG_VIRT_PUSHBUTTON |
1391 WPS_CONFIG_PHY_PUSHBUTTON)) == WPS_CONFIG_PUSHBUTTON) {
1392 wpa_printf(MSG_INFO, "WPS: Converting push_button to "
1393 "virtual_push_button for WPS 2.0 compliance");
1394 config_methods |= WPS_CONFIG_VIRT_PUSHBUTTON;
1397 return config_methods;
1401 static void wpas_wps_set_uuid(struct wpa_supplicant *wpa_s,
1402 struct wps_context *wps)
1407 if (is_nil_uuid(wpa_s->conf->uuid)) {
1408 struct wpa_supplicant *first;
1409 first = wpa_s->global->ifaces;
1410 while (first && first->next)
1411 first = first->next;
1412 if (first && first != wpa_s) {
1413 if (wps != wpa_s->global->ifaces->wps)
1414 os_memcpy(wps->uuid,
1415 wpa_s->global->ifaces->wps->uuid,
1417 src = "from the first interface";
1419 uuid_gen_mac_addr(wpa_s->own_addr, wps->uuid);
1420 src = "based on MAC address";
1423 os_memcpy(wps->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
1424 src = "based on configuration";
1427 uuid_bin2str(wps->uuid, buf, sizeof(buf));
1428 wpa_dbg(wpa_s, MSG_DEBUG, "WPS: UUID %s: %s", src, buf);
1432 static void wpas_wps_set_vendor_ext_m1(struct wpa_supplicant *wpa_s,
1433 struct wps_context *wps)
1435 wpabuf_free(wps->dev.vendor_ext_m1);
1436 wps->dev.vendor_ext_m1 = NULL;
1438 if (wpa_s->conf->wps_vendor_ext_m1) {
1439 wps->dev.vendor_ext_m1 =
1440 wpabuf_dup(wpa_s->conf->wps_vendor_ext_m1);
1441 if (!wps->dev.vendor_ext_m1) {
1442 wpa_printf(MSG_ERROR, "WPS: Cannot "
1443 "allocate memory for vendor_ext_m1");
1449 int wpas_wps_init(struct wpa_supplicant *wpa_s)
1451 struct wps_context *wps;
1452 struct wps_registrar_config rcfg;
1453 struct hostapd_hw_modes *modes;
1456 wps = os_zalloc(sizeof(*wps));
1460 wps->cred_cb = wpa_supplicant_wps_cred;
1461 wps->event_cb = wpa_supplicant_wps_event;
1462 wps->rf_band_cb = wpa_supplicant_wps_rf_band;
1463 wps->cb_ctx = wpa_s;
1465 wps->dev.device_name = wpa_s->conf->device_name;
1466 wps->dev.manufacturer = wpa_s->conf->manufacturer;
1467 wps->dev.model_name = wpa_s->conf->model_name;
1468 wps->dev.model_number = wpa_s->conf->model_number;
1469 wps->dev.serial_number = wpa_s->conf->serial_number;
1470 wps->config_methods =
1471 wps_config_methods_str2bin(wpa_s->conf->config_methods);
1472 if ((wps->config_methods & (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) ==
1473 (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) {
1474 wpa_printf(MSG_ERROR, "WPS: Both Label and Display config "
1475 "methods are not allowed at the same time");
1479 wps->config_methods = wps_fix_config_methods(wps->config_methods);
1480 wps->dev.config_methods = wps->config_methods;
1481 os_memcpy(wps->dev.pri_dev_type, wpa_s->conf->device_type,
1484 wps->dev.num_sec_dev_types = wpa_s->conf->num_sec_device_types;
1485 os_memcpy(wps->dev.sec_dev_type, wpa_s->conf->sec_device_type,
1486 WPS_DEV_TYPE_LEN * wps->dev.num_sec_dev_types);
1488 wpas_wps_set_vendor_ext_m1(wpa_s, wps);
1490 wps->dev.os_version = WPA_GET_BE32(wpa_s->conf->os_version);
1491 modes = wpa_s->hw.modes;
1493 for (m = 0; m < wpa_s->hw.num_modes; m++) {
1494 if (modes[m].mode == HOSTAPD_MODE_IEEE80211B ||
1495 modes[m].mode == HOSTAPD_MODE_IEEE80211G)
1496 wps->dev.rf_bands |= WPS_RF_24GHZ;
1497 else if (modes[m].mode == HOSTAPD_MODE_IEEE80211A)
1498 wps->dev.rf_bands |= WPS_RF_50GHZ;
1501 if (wps->dev.rf_bands == 0) {
1503 * Default to claiming support for both bands if the driver
1504 * does not provide support for fetching supported bands.
1506 wps->dev.rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ;
1508 os_memcpy(wps->dev.mac_addr, wpa_s->own_addr, ETH_ALEN);
1509 wpas_wps_set_uuid(wpa_s, wps);
1511 wps->auth_types = WPS_AUTH_WPA2PSK | WPS_AUTH_WPAPSK;
1512 wps->encr_types = WPS_ENCR_AES | WPS_ENCR_TKIP;
1514 os_memset(&rcfg, 0, sizeof(rcfg));
1515 rcfg.new_psk_cb = wpas_wps_new_psk_cb;
1516 rcfg.pin_needed_cb = wpas_wps_pin_needed_cb;
1517 rcfg.set_sel_reg_cb = wpas_wps_set_sel_reg_cb;
1518 rcfg.cb_ctx = wpa_s;
1520 wps->registrar = wps_registrar_init(wps, &rcfg);
1521 if (wps->registrar == NULL) {
1522 wpa_printf(MSG_DEBUG, "Failed to initialize WPS Registrar");
1533 #ifdef CONFIG_WPS_ER
1534 static void wpas_wps_nfc_clear(struct wps_context *wps)
1536 wps->ap_nfc_dev_pw_id = 0;
1537 wpabuf_free(wps->ap_nfc_dh_pubkey);
1538 wps->ap_nfc_dh_pubkey = NULL;
1539 wpabuf_free(wps->ap_nfc_dh_privkey);
1540 wps->ap_nfc_dh_privkey = NULL;
1541 wpabuf_free(wps->ap_nfc_dev_pw);
1542 wps->ap_nfc_dev_pw = NULL;
1544 #endif /* CONFIG_WPS_ER */
1547 void wpas_wps_deinit(struct wpa_supplicant *wpa_s)
1549 wpas_wps_assoc_with_cred_cancel(wpa_s);
1550 eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
1551 eloop_cancel_timeout(wpas_wps_clear_timeout, wpa_s, NULL);
1552 eloop_cancel_timeout(wpas_wps_reenable_networks_cb, wpa_s, NULL);
1553 wpas_wps_clear_ap_info(wpa_s);
1556 eloop_cancel_timeout(wpas_p2p_pbc_overlap_cb, wpa_s, NULL);
1557 #endif /* CONFIG_P2P */
1559 if (wpa_s->wps == NULL)
1562 #ifdef CONFIG_WPS_ER
1563 wps_er_deinit(wpa_s->wps_er, NULL, NULL);
1564 wpa_s->wps_er = NULL;
1565 wpas_wps_nfc_clear(wpa_s->wps);
1566 #endif /* CONFIG_WPS_ER */
1568 wps_registrar_deinit(wpa_s->wps->registrar);
1569 wpabuf_free(wpa_s->wps->dh_pubkey);
1570 wpabuf_free(wpa_s->wps->dh_privkey);
1571 wpabuf_free(wpa_s->wps->dev.vendor_ext_m1);
1572 os_free(wpa_s->wps->network_key);
1573 os_free(wpa_s->wps);
1578 int wpas_wps_ssid_bss_match(struct wpa_supplicant *wpa_s,
1579 struct wpa_ssid *ssid, struct wpa_bss *bss)
1581 struct wpabuf *wps_ie;
1583 if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS))
1586 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1587 if (eap_is_wps_pbc_enrollee(&ssid->eap)) {
1589 wpa_printf(MSG_DEBUG, " skip - non-WPS AP");
1593 if (!wps_is_selected_pbc_registrar(wps_ie)) {
1594 wpa_printf(MSG_DEBUG, " skip - WPS AP "
1595 "without active PBC Registrar");
1596 wpabuf_free(wps_ie);
1600 /* TODO: overlap detection */
1601 wpa_printf(MSG_DEBUG, " selected based on WPS IE "
1603 wpabuf_free(wps_ie);
1607 if (eap_is_wps_pin_enrollee(&ssid->eap)) {
1609 wpa_printf(MSG_DEBUG, " skip - non-WPS AP");
1614 * Start with WPS APs that advertise our address as an
1615 * authorized MAC (v2.0) or active PIN Registrar (v1.0) and
1616 * allow any WPS AP after couple of scans since some APs do not
1617 * set Selected Registrar attribute properly when using
1618 * external Registrar.
1620 if (!wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1)) {
1621 struct os_reltime age;
1623 os_reltime_age(&wpa_s->wps_pin_start_time, &age);
1625 if (wpa_s->scan_runs < WPS_PIN_SCAN_IGNORE_SEL_REG ||
1626 age.sec < WPS_PIN_TIME_IGNORE_SEL_REG) {
1627 wpa_printf(MSG_DEBUG,
1628 " skip - WPS AP without active PIN Registrar (scan_runs=%d age=%d)",
1629 wpa_s->scan_runs, (int) age.sec);
1630 wpabuf_free(wps_ie);
1633 wpa_printf(MSG_DEBUG, " selected based on WPS IE");
1635 wpa_printf(MSG_DEBUG, " selected based on WPS IE "
1636 "(Authorized MAC or Active PIN)");
1638 wpabuf_free(wps_ie);
1643 wpa_printf(MSG_DEBUG, " selected based on WPS IE");
1644 wpabuf_free(wps_ie);
1652 int wpas_wps_ssid_wildcard_ok(struct wpa_supplicant *wpa_s,
1653 struct wpa_ssid *ssid,
1654 struct wpa_bss *bss)
1656 struct wpabuf *wps_ie = NULL;
1659 if (eap_is_wps_pbc_enrollee(&ssid->eap)) {
1660 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1661 if (wps_ie && wps_is_selected_pbc_registrar(wps_ie)) {
1662 /* allow wildcard SSID for WPS PBC */
1665 } else if (eap_is_wps_pin_enrollee(&ssid->eap)) {
1666 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1668 (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1) ||
1669 wpa_s->scan_runs >= WPS_PIN_SCAN_IGNORE_SEL_REG)) {
1670 /* allow wildcard SSID for WPS PIN */
1675 if (!ret && ssid->bssid_set &&
1676 os_memcmp(ssid->bssid, bss->bssid, ETH_ALEN) == 0) {
1677 /* allow wildcard SSID due to hardcoded BSSID match */
1681 #ifdef CONFIG_WPS_STRICT
1683 if (wps_validate_beacon_probe_resp(wps_ie, bss->beacon_ie_len >
1686 if (bss->beacon_ie_len) {
1687 struct wpabuf *bcn_wps;
1688 bcn_wps = wpa_bss_get_vendor_ie_multi_beacon(
1689 bss, WPS_IE_VENDOR_TYPE);
1690 if (bcn_wps == NULL) {
1691 wpa_printf(MSG_DEBUG, "WPS: Mandatory WPS IE "
1692 "missing from AP Beacon");
1695 if (wps_validate_beacon(wps_ie) < 0)
1697 wpabuf_free(bcn_wps);
1701 #endif /* CONFIG_WPS_STRICT */
1703 wpabuf_free(wps_ie);
1709 int wpas_wps_scan_pbc_overlap(struct wpa_supplicant *wpa_s,
1710 struct wpa_bss *selected, struct wpa_ssid *ssid)
1712 const u8 *sel_uuid, *uuid;
1713 struct wpabuf *wps_ie;
1715 struct wpa_bss *bss;
1717 if (!eap_is_wps_pbc_enrollee(&ssid->eap))
1720 wpa_printf(MSG_DEBUG, "WPS: Check whether PBC session overlap is "
1721 "present in scan results; selected BSSID " MACSTR,
1722 MAC2STR(selected->bssid));
1724 /* Make sure that only one AP is in active PBC mode */
1725 wps_ie = wpa_bss_get_vendor_ie_multi(selected, WPS_IE_VENDOR_TYPE);
1727 sel_uuid = wps_get_uuid_e(wps_ie);
1728 wpa_hexdump(MSG_DEBUG, "WPS: UUID of the selected BSS",
1729 sel_uuid, UUID_LEN);
1731 wpa_printf(MSG_DEBUG, "WPS: Selected BSS does not include "
1736 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1738 if (bss == selected)
1740 ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1743 if (!wps_is_selected_pbc_registrar(ie)) {
1747 wpa_printf(MSG_DEBUG, "WPS: Another BSS in active PBC mode: "
1748 MACSTR, MAC2STR(bss->bssid));
1749 uuid = wps_get_uuid_e(ie);
1750 wpa_hexdump(MSG_DEBUG, "WPS: UUID of the other BSS",
1752 if (os_memcmp(selected->bssid, bss->bssid, ETH_ALEN) == 0) {
1756 if (sel_uuid == NULL || uuid == NULL ||
1757 os_memcmp(sel_uuid, uuid, UUID_LEN) != 0) {
1758 ret = 1; /* PBC overlap */
1759 wpa_msg(wpa_s, MSG_INFO, "WPS: PBC overlap detected: "
1760 MACSTR " and " MACSTR,
1761 MAC2STR(selected->bssid),
1762 MAC2STR(bss->bssid));
1767 /* TODO: verify that this is reasonable dual-band situation */
1772 wpabuf_free(wps_ie);
1778 void wpas_wps_notify_scan_results(struct wpa_supplicant *wpa_s)
1780 struct wpa_bss *bss;
1781 unsigned int pbc = 0, auth = 0, pin = 0, wps = 0;
1783 if (wpa_s->disconnected || wpa_s->wpa_state >= WPA_ASSOCIATED)
1786 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
1788 ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1791 if (wps_is_selected_pbc_registrar(ie))
1793 else if (wps_is_addr_authorized(ie, wpa_s->own_addr, 0))
1795 else if (wps_is_selected_pin_registrar(ie))
1803 wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PBC);
1805 wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_AUTH);
1807 wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PIN);
1809 wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE);
1813 int wpas_wps_searching(struct wpa_supplicant *wpa_s)
1815 struct wpa_ssid *ssid;
1817 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
1818 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && !ssid->disabled)
1826 int wpas_wps_scan_result_text(const u8 *ies, size_t ies_len, char *buf,
1829 struct wpabuf *wps_ie;
1832 wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len, WPS_DEV_OUI_WFA);
1836 ret = wps_attr_text(wps_ie, buf, end);
1837 wpabuf_free(wps_ie);
1842 int wpas_wps_er_start(struct wpa_supplicant *wpa_s, const char *filter)
1844 #ifdef CONFIG_WPS_ER
1845 if (wpa_s->wps_er) {
1846 wps_er_refresh(wpa_s->wps_er);
1849 wpa_s->wps_er = wps_er_init(wpa_s->wps, wpa_s->ifname, filter);
1850 if (wpa_s->wps_er == NULL)
1853 #else /* CONFIG_WPS_ER */
1855 #endif /* CONFIG_WPS_ER */
1859 void wpas_wps_er_stop(struct wpa_supplicant *wpa_s)
1861 #ifdef CONFIG_WPS_ER
1862 wps_er_deinit(wpa_s->wps_er, NULL, NULL);
1863 wpa_s->wps_er = NULL;
1864 #endif /* CONFIG_WPS_ER */
1868 #ifdef CONFIG_WPS_ER
1869 int wpas_wps_er_add_pin(struct wpa_supplicant *wpa_s, const u8 *addr,
1870 const char *uuid, const char *pin)
1873 const u8 *use_uuid = NULL;
1874 u8 addr_buf[ETH_ALEN];
1876 if (os_strcmp(uuid, "any") == 0) {
1877 } else if (uuid_str2bin(uuid, u) == 0) {
1879 } else if (hwaddr_aton(uuid, addr_buf) == 0) {
1880 use_uuid = wps_er_get_sta_uuid(wpa_s->wps_er, addr_buf);
1881 if (use_uuid == NULL)
1885 return wps_registrar_add_pin(wpa_s->wps->registrar, addr,
1887 (const u8 *) pin, os_strlen(pin), 300);
1891 int wpas_wps_er_pbc(struct wpa_supplicant *wpa_s, const char *uuid)
1893 u8 u[UUID_LEN], *use_uuid = NULL;
1894 u8 addr[ETH_ALEN], *use_addr = NULL;
1896 if (uuid_str2bin(uuid, u) == 0)
1898 else if (hwaddr_aton(uuid, addr) == 0)
1902 return wps_er_pbc(wpa_s->wps_er, use_uuid, use_addr);
1906 int wpas_wps_er_learn(struct wpa_supplicant *wpa_s, const char *uuid,
1909 u8 u[UUID_LEN], *use_uuid = NULL;
1910 u8 addr[ETH_ALEN], *use_addr = NULL;
1912 if (uuid_str2bin(uuid, u) == 0)
1914 else if (hwaddr_aton(uuid, addr) == 0)
1919 return wps_er_learn(wpa_s->wps_er, use_uuid, use_addr, (const u8 *) pin,
1924 static int wpas_wps_network_to_cred(struct wpa_ssid *ssid,
1925 struct wps_credential *cred)
1927 os_memset(cred, 0, sizeof(*cred));
1928 if (ssid->ssid_len > SSID_MAX_LEN)
1930 os_memcpy(cred->ssid, ssid->ssid, ssid->ssid_len);
1931 cred->ssid_len = ssid->ssid_len;
1932 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) {
1933 cred->auth_type = (ssid->proto & WPA_PROTO_RSN) ?
1934 WPS_AUTH_WPA2PSK : WPS_AUTH_WPAPSK;
1935 if (ssid->pairwise_cipher & WPA_CIPHER_CCMP)
1936 cred->encr_type = WPS_ENCR_AES;
1938 cred->encr_type = WPS_ENCR_TKIP;
1939 if (ssid->passphrase) {
1940 cred->key_len = os_strlen(ssid->passphrase);
1941 if (cred->key_len >= 64)
1943 os_memcpy(cred->key, ssid->passphrase, cred->key_len);
1944 } else if (ssid->psk_set) {
1946 os_memcpy(cred->key, ssid->psk, 32);
1950 cred->auth_type = WPS_AUTH_OPEN;
1951 cred->encr_type = WPS_ENCR_NONE;
1958 int wpas_wps_er_set_config(struct wpa_supplicant *wpa_s, const char *uuid,
1961 u8 u[UUID_LEN], *use_uuid = NULL;
1962 u8 addr[ETH_ALEN], *use_addr = NULL;
1963 struct wpa_ssid *ssid;
1964 struct wps_credential cred;
1967 if (uuid_str2bin(uuid, u) == 0)
1969 else if (hwaddr_aton(uuid, addr) == 0)
1973 ssid = wpa_config_get_network(wpa_s->conf, id);
1974 if (ssid == NULL || ssid->ssid == NULL)
1977 if (wpas_wps_network_to_cred(ssid, &cred) < 0)
1979 ret = wps_er_set_config(wpa_s->wps_er, use_uuid, use_addr, &cred);
1980 os_memset(&cred, 0, sizeof(cred));
1985 int wpas_wps_er_config(struct wpa_supplicant *wpa_s, const char *uuid,
1986 const char *pin, struct wps_new_ap_settings *settings)
1988 u8 u[UUID_LEN], *use_uuid = NULL;
1989 u8 addr[ETH_ALEN], *use_addr = NULL;
1990 struct wps_credential cred;
1993 if (uuid_str2bin(uuid, u) == 0)
1995 else if (hwaddr_aton(uuid, addr) == 0)
1999 if (settings->ssid_hex == NULL || settings->auth == NULL ||
2000 settings->encr == NULL || settings->key_hex == NULL)
2003 os_memset(&cred, 0, sizeof(cred));
2004 len = os_strlen(settings->ssid_hex);
2005 if ((len & 1) || len > 2 * sizeof(cred.ssid) ||
2006 hexstr2bin(settings->ssid_hex, cred.ssid, len / 2))
2008 cred.ssid_len = len / 2;
2010 len = os_strlen(settings->key_hex);
2011 if ((len & 1) || len > 2 * sizeof(cred.key) ||
2012 hexstr2bin(settings->key_hex, cred.key, len / 2))
2014 cred.key_len = len / 2;
2016 if (os_strcmp(settings->auth, "OPEN") == 0)
2017 cred.auth_type = WPS_AUTH_OPEN;
2018 else if (os_strcmp(settings->auth, "WPAPSK") == 0)
2019 cred.auth_type = WPS_AUTH_WPAPSK;
2020 else if (os_strcmp(settings->auth, "WPA2PSK") == 0)
2021 cred.auth_type = WPS_AUTH_WPA2PSK;
2025 if (os_strcmp(settings->encr, "NONE") == 0)
2026 cred.encr_type = WPS_ENCR_NONE;
2027 #ifdef CONFIG_TESTING_OPTIONS
2028 else if (os_strcmp(settings->encr, "WEP") == 0)
2029 cred.encr_type = WPS_ENCR_WEP;
2030 #endif /* CONFIG_TESTING_OPTIONS */
2031 else if (os_strcmp(settings->encr, "TKIP") == 0)
2032 cred.encr_type = WPS_ENCR_TKIP;
2033 else if (os_strcmp(settings->encr, "CCMP") == 0)
2034 cred.encr_type = WPS_ENCR_AES;
2038 return wps_er_config(wpa_s->wps_er, use_uuid, use_addr,
2039 (const u8 *) pin, os_strlen(pin), &cred);
2043 #ifdef CONFIG_WPS_NFC
2044 struct wpabuf * wpas_wps_er_nfc_config_token(struct wpa_supplicant *wpa_s,
2045 int ndef, const char *uuid)
2048 u8 u[UUID_LEN], *use_uuid = NULL;
2049 u8 addr[ETH_ALEN], *use_addr = NULL;
2054 if (uuid_str2bin(uuid, u) == 0)
2056 else if (hwaddr_aton(uuid, addr) == 0)
2061 ret = wps_er_nfc_config_token(wpa_s->wps_er, use_uuid, use_addr);
2064 tmp = ndef_build_wifi(ret);
2073 #endif /* CONFIG_WPS_NFC */
2076 static int callbacks_pending = 0;
2078 static void wpas_wps_terminate_cb(void *ctx)
2080 wpa_printf(MSG_DEBUG, "WPS ER: Terminated");
2081 if (--callbacks_pending <= 0)
2084 #endif /* CONFIG_WPS_ER */
2087 int wpas_wps_terminate_pending(struct wpa_supplicant *wpa_s)
2089 #ifdef CONFIG_WPS_ER
2090 if (wpa_s->wps_er) {
2091 callbacks_pending++;
2092 wps_er_deinit(wpa_s->wps_er, wpas_wps_terminate_cb, wpa_s);
2093 wpa_s->wps_er = NULL;
2096 #endif /* CONFIG_WPS_ER */
2101 void wpas_wps_update_config(struct wpa_supplicant *wpa_s)
2103 struct wps_context *wps = wpa_s->wps;
2108 if (wpa_s->conf->changed_parameters & CFG_CHANGED_CONFIG_METHODS) {
2109 wps->config_methods = wps_config_methods_str2bin(
2110 wpa_s->conf->config_methods);
2111 if ((wps->config_methods &
2112 (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) ==
2113 (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) {
2114 wpa_printf(MSG_ERROR, "WPS: Both Label and Display "
2115 "config methods are not allowed at the "
2117 wps->config_methods &= ~WPS_CONFIG_LABEL;
2120 wps->config_methods = wps_fix_config_methods(wps->config_methods);
2121 wps->dev.config_methods = wps->config_methods;
2123 if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_TYPE)
2124 os_memcpy(wps->dev.pri_dev_type, wpa_s->conf->device_type,
2127 if (wpa_s->conf->changed_parameters & CFG_CHANGED_SEC_DEVICE_TYPE) {
2128 wps->dev.num_sec_dev_types = wpa_s->conf->num_sec_device_types;
2129 os_memcpy(wps->dev.sec_dev_type, wpa_s->conf->sec_device_type,
2130 wps->dev.num_sec_dev_types * WPS_DEV_TYPE_LEN);
2133 if (wpa_s->conf->changed_parameters & CFG_CHANGED_VENDOR_EXTENSION)
2134 wpas_wps_set_vendor_ext_m1(wpa_s, wps);
2136 if (wpa_s->conf->changed_parameters & CFG_CHANGED_OS_VERSION)
2137 wps->dev.os_version = WPA_GET_BE32(wpa_s->conf->os_version);
2139 if (wpa_s->conf->changed_parameters & CFG_CHANGED_UUID)
2140 wpas_wps_set_uuid(wpa_s, wps);
2142 if (wpa_s->conf->changed_parameters &
2143 (CFG_CHANGED_DEVICE_NAME | CFG_CHANGED_WPS_STRING)) {
2144 /* Update pointers to make sure they refer current values */
2145 wps->dev.device_name = wpa_s->conf->device_name;
2146 wps->dev.manufacturer = wpa_s->conf->manufacturer;
2147 wps->dev.model_name = wpa_s->conf->model_name;
2148 wps->dev.model_number = wpa_s->conf->model_number;
2149 wps->dev.serial_number = wpa_s->conf->serial_number;
2154 #ifdef CONFIG_WPS_NFC
2156 #ifdef CONFIG_WPS_ER
2157 static struct wpabuf *
2158 wpas_wps_network_config_token(struct wpa_supplicant *wpa_s, int ndef,
2159 struct wpa_ssid *ssid)
2162 struct wps_credential cred;
2164 if (wpas_wps_network_to_cred(ssid, &cred) < 0)
2167 ret = wps_er_config_token_from_cred(wpa_s->wps, &cred);
2171 tmp = ndef_build_wifi(ret);
2180 #endif /* CONFIG_WPS_ER */
2183 struct wpabuf * wpas_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
2184 int ndef, const char *id_str)
2186 #ifdef CONFIG_WPS_ER
2190 struct wpa_ssid *ssid;
2192 id = strtol(id_str, &end, 10);
2196 ssid = wpa_config_get_network(wpa_s->conf, id);
2199 return wpas_wps_network_config_token(wpa_s, ndef, ssid);
2201 #endif /* CONFIG_WPS_ER */
2203 if (wpa_s->ap_iface)
2204 return wpas_ap_wps_nfc_config_token(wpa_s, ndef);
2205 #endif /* CONFIG_AP */
2210 struct wpabuf * wpas_wps_nfc_token(struct wpa_supplicant *wpa_s, int ndef)
2212 if (wpa_s->conf->wps_nfc_pw_from_config) {
2213 return wps_nfc_token_build(ndef,
2214 wpa_s->conf->wps_nfc_dev_pw_id,
2215 wpa_s->conf->wps_nfc_dh_pubkey,
2216 wpa_s->conf->wps_nfc_dev_pw);
2219 return wps_nfc_token_gen(ndef, &wpa_s->conf->wps_nfc_dev_pw_id,
2220 &wpa_s->conf->wps_nfc_dh_pubkey,
2221 &wpa_s->conf->wps_nfc_dh_privkey,
2222 &wpa_s->conf->wps_nfc_dev_pw);
2226 int wpas_wps_start_nfc(struct wpa_supplicant *wpa_s, const u8 *go_dev_addr,
2228 const struct wpabuf *dev_pw, u16 dev_pw_id,
2229 int p2p_group, const u8 *peer_pubkey_hash,
2230 const u8 *ssid, size_t ssid_len, int freq)
2232 struct wps_context *wps = wpa_s->wps;
2233 char pw[32 * 2 + 1];
2235 if (dev_pw_id != DEV_PW_NFC_CONNECTION_HANDOVER && dev_pw == NULL) {
2236 dev_pw = wpa_s->conf->wps_nfc_dev_pw;
2237 dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id;
2240 if (wpa_s->conf->wps_nfc_dh_pubkey == NULL ||
2241 wpa_s->conf->wps_nfc_dh_privkey == NULL) {
2242 wpa_printf(MSG_DEBUG, "WPS: Missing DH params - "
2243 "cannot start NFC-triggered connection");
2247 if (dev_pw_id != DEV_PW_NFC_CONNECTION_HANDOVER && dev_pw == NULL) {
2248 wpa_printf(MSG_DEBUG, "WPS: Missing Device Password (id=%u) - "
2249 "cannot start NFC-triggered connection", dev_pw_id);
2253 dh5_free(wps->dh_ctx);
2254 wpabuf_free(wps->dh_pubkey);
2255 wpabuf_free(wps->dh_privkey);
2256 wps->dh_privkey = wpabuf_dup(wpa_s->conf->wps_nfc_dh_privkey);
2257 wps->dh_pubkey = wpabuf_dup(wpa_s->conf->wps_nfc_dh_pubkey);
2258 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
2260 wpabuf_free(wps->dh_pubkey);
2261 wps->dh_pubkey = NULL;
2262 wpabuf_free(wps->dh_privkey);
2263 wps->dh_privkey = NULL;
2264 wpa_printf(MSG_DEBUG, "WPS: Failed to get DH priv/pub key");
2267 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
2268 if (wps->dh_ctx == NULL) {
2269 wpabuf_free(wps->dh_pubkey);
2270 wps->dh_pubkey = NULL;
2271 wpabuf_free(wps->dh_privkey);
2272 wps->dh_privkey = NULL;
2273 wpa_printf(MSG_DEBUG, "WPS: Failed to initialize DH context");
2278 wpa_snprintf_hex_uppercase(pw, sizeof(pw),
2279 wpabuf_head(dev_pw),
2280 wpabuf_len(dev_pw));
2282 return wpas_wps_start_dev_pw(wpa_s, go_dev_addr, bssid,
2284 p2p_group, dev_pw_id, peer_pubkey_hash,
2285 ssid, ssid_len, freq);
2289 static int wpas_wps_use_cred(struct wpa_supplicant *wpa_s,
2290 struct wps_parse_attr *attr)
2293 * Disable existing networks temporarily to allow the newly learned
2294 * credential to be preferred. Enable the temporarily disabled networks
2297 wpas_wps_temp_disable(wpa_s, NULL);
2298 eloop_register_timeout(10, 0, wpas_wps_reenable_networks_cb, wpa_s,
2301 if (wps_oob_use_cred(wpa_s->wps, attr) < 0)
2304 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2307 if (attr->ap_channel) {
2308 u16 chan = WPA_GET_BE16(attr->ap_channel);
2311 if (chan >= 1 && chan <= 13)
2312 freq = 2407 + 5 * chan;
2313 else if (chan == 14)
2315 else if (chan >= 30)
2316 freq = 5000 + 5 * chan;
2319 wpa_printf(MSG_DEBUG, "WPS: Credential container indicated AP channel %u -> %u MHz",
2321 wpa_s->after_wps = 5;
2322 wpa_s->wps_freq = freq;
2326 wpa_printf(MSG_DEBUG, "WPS: Request reconnection with new network "
2327 "based on the received credential added");
2328 wpa_s->normal_scans = 0;
2329 wpa_supplicant_reinit_autoscan(wpa_s);
2330 wpa_s->disconnected = 0;
2331 wpa_s->reassociate = 1;
2333 wpa_supplicant_cancel_sched_scan(wpa_s);
2334 wpa_supplicant_req_scan(wpa_s, 0, 0);
2340 #ifdef CONFIG_WPS_ER
2341 static int wpas_wps_add_nfc_password_token(struct wpa_supplicant *wpa_s,
2342 struct wps_parse_attr *attr)
2344 return wps_registrar_add_nfc_password_token(
2345 wpa_s->wps->registrar, attr->oob_dev_password,
2346 attr->oob_dev_password_len);
2348 #endif /* CONFIG_WPS_ER */
2351 static int wpas_wps_nfc_tag_process(struct wpa_supplicant *wpa_s,
2352 const struct wpabuf *wps)
2354 struct wps_parse_attr attr;
2356 wpa_hexdump_buf(MSG_DEBUG, "WPS: Received NFC tag payload", wps);
2358 if (wps_parse_msg(wps, &attr)) {
2359 wpa_printf(MSG_DEBUG, "WPS: Ignore invalid data from NFC tag");
2364 return wpas_wps_use_cred(wpa_s, &attr);
2366 #ifdef CONFIG_WPS_ER
2367 if (attr.oob_dev_password)
2368 return wpas_wps_add_nfc_password_token(wpa_s, &attr);
2369 #endif /* CONFIG_WPS_ER */
2371 wpa_printf(MSG_DEBUG, "WPS: Ignore unrecognized NFC tag");
2376 int wpas_wps_nfc_tag_read(struct wpa_supplicant *wpa_s,
2377 const struct wpabuf *data, int forced_freq)
2379 const struct wpabuf *wps = data;
2380 struct wpabuf *tmp = NULL;
2383 if (wpabuf_len(data) < 4)
2386 if (*wpabuf_head_u8(data) != 0x10) {
2387 /* Assume this contains full NDEF record */
2388 tmp = ndef_parse_wifi(data);
2391 tmp = ndef_parse_p2p(data);
2393 ret = wpas_p2p_nfc_tag_process(wpa_s, tmp,
2398 #endif /* CONFIG_P2P */
2399 wpa_printf(MSG_DEBUG, "WPS: Could not parse NDEF");
2405 ret = wpas_wps_nfc_tag_process(wpa_s, wps);
2411 struct wpabuf * wpas_wps_nfc_handover_req(struct wpa_supplicant *wpa_s,
2416 if (wpa_s->conf->wps_nfc_dh_pubkey == NULL &&
2417 wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey,
2418 &wpa_s->conf->wps_nfc_dh_privkey) < 0)
2421 ret = wps_build_nfc_handover_req(wpa_s->wps,
2422 wpa_s->conf->wps_nfc_dh_pubkey);
2426 tmp = ndef_build_wifi(ret);
2437 #ifdef CONFIG_WPS_NFC
2439 static struct wpabuf *
2440 wpas_wps_er_nfc_handover_sel(struct wpa_supplicant *wpa_s, int ndef,
2443 #ifdef CONFIG_WPS_ER
2445 u8 u[UUID_LEN], *use_uuid = NULL;
2446 u8 addr[ETH_ALEN], *use_addr = NULL;
2447 struct wps_context *wps = wpa_s->wps;
2454 if (uuid_str2bin(uuid, u) == 0)
2456 else if (hwaddr_aton(uuid, addr) == 0)
2461 if (wpa_s->conf->wps_nfc_dh_pubkey == NULL) {
2462 if (wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey,
2463 &wpa_s->conf->wps_nfc_dh_privkey) < 0)
2467 wpas_wps_nfc_clear(wps);
2468 wps->ap_nfc_dev_pw_id = DEV_PW_NFC_CONNECTION_HANDOVER;
2469 wps->ap_nfc_dh_pubkey = wpabuf_dup(wpa_s->conf->wps_nfc_dh_pubkey);
2470 wps->ap_nfc_dh_privkey = wpabuf_dup(wpa_s->conf->wps_nfc_dh_privkey);
2471 if (!wps->ap_nfc_dh_pubkey || !wps->ap_nfc_dh_privkey) {
2472 wpas_wps_nfc_clear(wps);
2476 ret = wps_er_nfc_handover_sel(wpa_s->wps_er, wpa_s->wps, use_uuid,
2477 use_addr, wpa_s->conf->wps_nfc_dh_pubkey);
2480 tmp = ndef_build_wifi(ret);
2488 #else /* CONFIG_WPS_ER */
2490 #endif /* CONFIG_WPS_ER */
2492 #endif /* CONFIG_WPS_NFC */
2495 struct wpabuf * wpas_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
2496 int ndef, int cr, const char *uuid)
2501 ret = wpas_ap_wps_nfc_handover_sel(wpa_s, ndef);
2504 return wpas_wps_er_nfc_handover_sel(wpa_s, ndef, uuid);
2508 static int wpas_wps_nfc_rx_handover_sel(struct wpa_supplicant *wpa_s,
2509 const struct wpabuf *data)
2516 struct wps_parse_attr attr;
2518 const u8 *bssid = NULL;
2521 wps = ndef_parse_wifi(data);
2524 wpa_printf(MSG_DEBUG, "WPS: Received application/vnd.wfa.wsc "
2525 "payload from NFC connection handover");
2526 wpa_hexdump_buf(MSG_DEBUG, "WPS: NFC payload", wps);
2527 if (wpabuf_len(wps) < 2) {
2528 wpa_printf(MSG_DEBUG, "WPS: Too short Wi-Fi Handover Select "
2532 pos = wpabuf_head(wps);
2533 wsc_len = WPA_GET_BE16(pos);
2534 if (wsc_len > wpabuf_len(wps) - 2) {
2535 wpa_printf(MSG_DEBUG, "WPS: Invalid WSC attribute length (%u) "
2536 "in Wi-Fi Handover Select Message", wsc_len);
2541 wpa_hexdump(MSG_DEBUG,
2542 "WPS: WSC attributes in Wi-Fi Handover Select Message",
2544 if (wsc_len < wpabuf_len(wps) - 2) {
2545 wpa_hexdump(MSG_DEBUG,
2546 "WPS: Ignore extra data after WSC attributes",
2547 pos + wsc_len, wpabuf_len(wps) - 2 - wsc_len);
2550 wpabuf_set(&msg, pos, wsc_len);
2551 ret = wps_parse_msg(&msg, &attr);
2553 wpa_printf(MSG_DEBUG, "WPS: Could not parse WSC attributes in "
2554 "Wi-Fi Handover Select Message");
2558 if (attr.oob_dev_password == NULL ||
2559 attr.oob_dev_password_len < WPS_OOB_PUBKEY_HASH_LEN + 2) {
2560 wpa_printf(MSG_DEBUG, "WPS: No Out-of-Band Device Password "
2561 "included in Wi-Fi Handover Select Message");
2566 if (attr.ssid == NULL) {
2567 wpa_printf(MSG_DEBUG, "WPS: No SSID included in Wi-Fi Handover "
2573 wpa_hexdump_ascii(MSG_DEBUG, "WPS: SSID", attr.ssid, attr.ssid_len);
2575 if (attr.mac_addr) {
2576 bssid = attr.mac_addr;
2577 wpa_printf(MSG_DEBUG, "WPS: MAC Address (BSSID): " MACSTR,
2582 wpa_printf(MSG_DEBUG, "WPS: RF Bands: %d", *attr.rf_bands);
2584 if (attr.ap_channel) {
2585 u16 chan = WPA_GET_BE16(attr.ap_channel);
2587 wpa_printf(MSG_DEBUG, "WPS: AP Channel: %d", chan);
2589 if (chan >= 1 && chan <= 13 &&
2590 (attr.rf_bands == NULL || *attr.rf_bands & WPS_RF_24GHZ))
2591 freq = 2407 + 5 * chan;
2592 else if (chan == 14 &&
2593 (attr.rf_bands == NULL ||
2594 *attr.rf_bands & WPS_RF_24GHZ))
2596 else if (chan >= 30 &&
2597 (attr.rf_bands == NULL ||
2598 *attr.rf_bands & WPS_RF_50GHZ))
2599 freq = 5000 + 5 * chan;
2602 wpa_printf(MSG_DEBUG,
2603 "WPS: AP indicated channel %u -> %u MHz",
2608 wpa_hexdump(MSG_DEBUG, "WPS: Out-of-Band Device Password",
2609 attr.oob_dev_password, attr.oob_dev_password_len);
2610 dev_pw_id = WPA_GET_BE16(attr.oob_dev_password +
2611 WPS_OOB_PUBKEY_HASH_LEN);
2612 if (dev_pw_id != DEV_PW_NFC_CONNECTION_HANDOVER) {
2613 wpa_printf(MSG_DEBUG, "WPS: Unexpected OOB Device Password ID "
2614 "%u in Wi-Fi Handover Select Message", dev_pw_id);
2618 wpa_hexdump(MSG_DEBUG, "WPS: AP Public Key hash",
2619 attr.oob_dev_password, WPS_OOB_PUBKEY_HASH_LEN);
2621 ret = wpas_wps_start_nfc(wpa_s, NULL, bssid, NULL, dev_pw_id, 0,
2622 attr.oob_dev_password,
2623 attr.ssid, attr.ssid_len, freq);
2631 int wpas_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
2632 const struct wpabuf *req,
2633 const struct wpabuf *sel)
2635 wpa_printf(MSG_DEBUG, "NFC: WPS connection handover reported");
2636 wpa_hexdump_buf_key(MSG_DEBUG, "WPS: Carrier record in request", req);
2637 wpa_hexdump_buf_key(MSG_DEBUG, "WPS: Carrier record in select", sel);
2638 return wpas_wps_nfc_rx_handover_sel(wpa_s, sel);
2642 int wpas_er_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
2643 const struct wpabuf *req,
2644 const struct wpabuf *sel)
2651 struct wps_parse_attr attr;
2655 * Enrollee/station is always initiator of the NFC connection handover,
2656 * so use the request message here to find Enrollee public key hash.
2658 wps = ndef_parse_wifi(req);
2661 wpa_printf(MSG_DEBUG, "WPS: Received application/vnd.wfa.wsc "
2662 "payload from NFC connection handover");
2663 wpa_hexdump_buf(MSG_DEBUG, "WPS: NFC payload", wps);
2664 if (wpabuf_len(wps) < 2) {
2665 wpa_printf(MSG_DEBUG, "WPS: Too short Wi-Fi Handover Request "
2669 pos = wpabuf_head(wps);
2670 wsc_len = WPA_GET_BE16(pos);
2671 if (wsc_len > wpabuf_len(wps) - 2) {
2672 wpa_printf(MSG_DEBUG, "WPS: Invalid WSC attribute length (%u) "
2673 "in rt Wi-Fi Handover Request Message", wsc_len);
2678 wpa_hexdump(MSG_DEBUG,
2679 "WPS: WSC attributes in Wi-Fi Handover Request Message",
2681 if (wsc_len < wpabuf_len(wps) - 2) {
2682 wpa_hexdump(MSG_DEBUG,
2683 "WPS: Ignore extra data after WSC attributes",
2684 pos + wsc_len, wpabuf_len(wps) - 2 - wsc_len);
2687 wpabuf_set(&msg, pos, wsc_len);
2688 ret = wps_parse_msg(&msg, &attr);
2690 wpa_printf(MSG_DEBUG, "WPS: Could not parse WSC attributes in "
2691 "Wi-Fi Handover Request Message");
2695 if (attr.oob_dev_password == NULL ||
2696 attr.oob_dev_password_len < WPS_OOB_PUBKEY_HASH_LEN + 2) {
2697 wpa_printf(MSG_DEBUG, "WPS: No Out-of-Band Device Password "
2698 "included in Wi-Fi Handover Request Message");
2703 if (attr.uuid_e == NULL) {
2704 wpa_printf(MSG_DEBUG, "WPS: No UUID-E included in Wi-Fi "
2705 "Handover Request Message");
2710 wpa_hexdump(MSG_DEBUG, "WPS: UUID-E", attr.uuid_e, WPS_UUID_LEN);
2712 wpa_hexdump(MSG_DEBUG, "WPS: Out-of-Band Device Password",
2713 attr.oob_dev_password, attr.oob_dev_password_len);
2714 dev_pw_id = WPA_GET_BE16(attr.oob_dev_password +
2715 WPS_OOB_PUBKEY_HASH_LEN);
2716 if (dev_pw_id != DEV_PW_NFC_CONNECTION_HANDOVER) {
2717 wpa_printf(MSG_DEBUG, "WPS: Unexpected OOB Device Password ID "
2718 "%u in Wi-Fi Handover Request Message", dev_pw_id);
2722 wpa_hexdump(MSG_DEBUG, "WPS: Enrollee Public Key hash",
2723 attr.oob_dev_password, WPS_OOB_PUBKEY_HASH_LEN);
2725 ret = wps_registrar_add_nfc_pw_token(wpa_s->wps->registrar,
2726 attr.oob_dev_password,
2727 DEV_PW_NFC_CONNECTION_HANDOVER,
2735 #endif /* CONFIG_WPS_NFC */
2738 static void wpas_wps_dump_ap_info(struct wpa_supplicant *wpa_s)
2741 struct os_reltime now;
2743 if (wpa_debug_level > MSG_DEBUG)
2746 if (wpa_s->wps_ap == NULL)
2749 os_get_reltime(&now);
2751 for (i = 0; i < wpa_s->num_wps_ap; i++) {
2752 struct wps_ap_info *ap = &wpa_s->wps_ap[i];
2753 struct wpa_blacklist *e = wpa_blacklist_get(wpa_s, ap->bssid);
2755 wpa_printf(MSG_DEBUG, "WPS: AP[%d] " MACSTR " type=%d "
2756 "tries=%d last_attempt=%d sec ago blacklist=%d",
2757 (int) i, MAC2STR(ap->bssid), ap->type, ap->tries,
2758 ap->last_attempt.sec > 0 ?
2759 (int) now.sec - (int) ap->last_attempt.sec : -1,
2765 static struct wps_ap_info * wpas_wps_get_ap_info(struct wpa_supplicant *wpa_s,
2770 if (wpa_s->wps_ap == NULL)
2773 for (i = 0; i < wpa_s->num_wps_ap; i++) {
2774 struct wps_ap_info *ap = &wpa_s->wps_ap[i];
2775 if (os_memcmp(ap->bssid, bssid, ETH_ALEN) == 0)
2783 static void wpas_wps_update_ap_info_bss(struct wpa_supplicant *wpa_s,
2784 struct wpa_scan_res *res)
2787 enum wps_ap_info_type type;
2788 struct wps_ap_info *ap;
2791 if (wpa_scan_get_vendor_ie(res, WPS_IE_VENDOR_TYPE) == NULL)
2794 wps = wpa_scan_get_vendor_ie_multi(res, WPS_IE_VENDOR_TYPE);
2798 r = wps_is_addr_authorized(wps, wpa_s->own_addr, 1);
2800 type = WPS_AP_SEL_REG_OUR;
2802 type = WPS_AP_SEL_REG;
2804 type = WPS_AP_NOT_SEL_REG;
2808 ap = wpas_wps_get_ap_info(wpa_s, res->bssid);
2810 if (ap->type != type) {
2811 wpa_printf(MSG_DEBUG, "WPS: AP " MACSTR
2812 " changed type %d -> %d",
2813 MAC2STR(res->bssid), ap->type, type);
2815 if (type != WPS_AP_NOT_SEL_REG)
2816 wpa_blacklist_del(wpa_s, ap->bssid);
2821 ap = os_realloc_array(wpa_s->wps_ap, wpa_s->num_wps_ap + 1,
2822 sizeof(struct wps_ap_info));
2827 ap = &wpa_s->wps_ap[wpa_s->num_wps_ap];
2828 wpa_s->num_wps_ap++;
2830 os_memset(ap, 0, sizeof(*ap));
2831 os_memcpy(ap->bssid, res->bssid, ETH_ALEN);
2833 wpa_printf(MSG_DEBUG, "WPS: AP " MACSTR " type %d added",
2834 MAC2STR(ap->bssid), ap->type);
2838 void wpas_wps_update_ap_info(struct wpa_supplicant *wpa_s,
2839 struct wpa_scan_results *scan_res)
2843 for (i = 0; i < scan_res->num; i++)
2844 wpas_wps_update_ap_info_bss(wpa_s, scan_res->res[i]);
2846 wpas_wps_dump_ap_info(wpa_s);
2850 void wpas_wps_notify_assoc(struct wpa_supplicant *wpa_s, const u8 *bssid)
2852 struct wps_ap_info *ap;
2854 wpa_s->after_wps = 0;
2856 if (!wpa_s->wps_ap_iter)
2858 ap = wpas_wps_get_ap_info(wpa_s, bssid);
2862 os_get_reltime(&ap->last_attempt);