2 * wpa_supplicant / WPS integration
3 * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
18 #include "ieee802_11_defs.h"
19 #include "wpa_common.h"
21 #include "eap_peer/eap.h"
22 #include "wpa_supplicant_i.h"
26 #include "ctrl_iface_dbus.h"
27 #include "eap_common/eap_wsc_common.h"
28 #include "blacklist.h"
29 #include "wps_supplicant.h"
30 #include "dh_groups.h"
32 #define WPS_PIN_SCAN_IGNORE_SEL_REG 3
34 static void wpas_wps_timeout(void *eloop_ctx, void *timeout_ctx);
35 static void wpas_clear_wps(struct wpa_supplicant *wpa_s);
38 int wpas_wps_eapol_cb(struct wpa_supplicant *wpa_s)
40 if (!wpa_s->wps_success &&
41 wpa_s->current_ssid &&
42 eap_is_wps_pin_enrollee(&wpa_s->current_ssid->eap)) {
43 const u8 *bssid = wpa_s->bssid;
44 if (is_zero_ether_addr(bssid))
45 bssid = wpa_s->pending_bssid;
47 wpa_printf(MSG_DEBUG, "WPS: PIN registration with " MACSTR
48 " did not succeed - continue trying to find "
49 "suitable AP", MAC2STR(bssid));
50 wpa_blacklist_add(wpa_s, bssid);
52 wpa_supplicant_deauthenticate(wpa_s,
53 WLAN_REASON_DEAUTH_LEAVING);
54 wpa_s->reassociate = 1;
55 wpa_supplicant_req_scan(wpa_s,
56 wpa_s->blacklist_cleared ? 5 : 0, 0);
57 wpa_s->blacklist_cleared = 0;
61 eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
63 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && wpa_s->current_ssid &&
64 !(wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
65 wpa_printf(MSG_DEBUG, "WPS: Network configuration replaced - "
66 "try to associate with the received credential");
67 wpa_supplicant_deauthenticate(wpa_s,
68 WLAN_REASON_DEAUTH_LEAVING);
69 wpa_s->reassociate = 1;
70 wpa_supplicant_req_scan(wpa_s, 0, 0);
74 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && wpa_s->current_ssid) {
75 wpa_printf(MSG_DEBUG, "WPS: Registration completed - waiting "
76 "for external credential processing");
77 wpas_clear_wps(wpa_s);
78 wpa_supplicant_deauthenticate(wpa_s,
79 WLAN_REASON_DEAUTH_LEAVING);
87 static int wpa_supplicant_wps_cred(void *ctx,
88 const struct wps_credential *cred)
90 struct wpa_supplicant *wpa_s = ctx;
91 struct wpa_ssid *ssid = wpa_s->current_ssid;
94 if ((wpa_s->conf->wps_cred_processing == 1 ||
95 wpa_s->conf->wps_cred_processing == 2) && cred->cred_attr) {
96 size_t blen = cred->cred_attr_len * 2 + 1;
97 char *buf = os_malloc(blen);
99 wpa_snprintf_hex(buf, blen,
100 cred->cred_attr, cred->cred_attr_len);
101 wpa_msg(wpa_s, MSG_INFO, "%s%s",
102 WPS_EVENT_CRED_RECEIVED, buf);
105 wpa_supplicant_dbus_notify_wps_cred(wpa_s, cred);
107 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_CRED_RECEIVED);
109 wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
110 cred->cred_attr, cred->cred_attr_len);
112 if (wpa_s->conf->wps_cred_processing == 1)
115 if (cred->auth_type != WPS_AUTH_OPEN &&
116 cred->auth_type != WPS_AUTH_SHARED &&
117 cred->auth_type != WPS_AUTH_WPAPSK &&
118 cred->auth_type != WPS_AUTH_WPA2PSK) {
119 wpa_printf(MSG_DEBUG, "WPS: Ignored credentials for "
120 "unsupported authentication type %d",
125 if (ssid && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
126 wpa_printf(MSG_DEBUG, "WPS: Replace WPS network block based "
127 "on the received credential");
128 os_free(ssid->eap.identity);
129 ssid->eap.identity = NULL;
130 ssid->eap.identity_len = 0;
131 os_free(ssid->eap.phase1);
132 ssid->eap.phase1 = NULL;
133 os_free(ssid->eap.eap_methods);
134 ssid->eap.eap_methods = NULL;
136 wpa_printf(MSG_DEBUG, "WPS: Create a new network based on the "
137 "received credential");
138 ssid = wpa_config_add_network(wpa_s->conf);
143 wpa_config_set_network_defaults(ssid);
146 ssid->ssid = os_malloc(cred->ssid_len);
148 os_memcpy(ssid->ssid, cred->ssid, cred->ssid_len);
149 ssid->ssid_len = cred->ssid_len;
152 switch (cred->encr_type) {
156 if (cred->key_len <= 0)
158 if (cred->key_len != 5 && cred->key_len != 13 &&
159 cred->key_len != 10 && cred->key_len != 26) {
160 wpa_printf(MSG_ERROR, "WPS: Invalid WEP Key length "
161 "%lu", (unsigned long) cred->key_len);
164 if (cred->key_idx > NUM_WEP_KEYS) {
165 wpa_printf(MSG_ERROR, "WPS: Invalid WEP Key index %d",
170 key_idx = cred->key_idx - 1;
171 if (cred->key_len == 10 || cred->key_len == 26) {
172 if (hexstr2bin((char *) cred->key,
173 ssid->wep_key[key_idx],
174 cred->key_len / 2) < 0) {
175 wpa_printf(MSG_ERROR, "WPS: Invalid WEP Key "
179 ssid->wep_key_len[key_idx] = cred->key_len / 2;
181 os_memcpy(ssid->wep_key[key_idx], cred->key,
183 ssid->wep_key_len[key_idx] = cred->key_len;
185 ssid->wep_tx_keyidx = key_idx;
188 ssid->pairwise_cipher = WPA_CIPHER_TKIP;
191 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
195 switch (cred->auth_type) {
197 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
198 ssid->key_mgmt = WPA_KEY_MGMT_NONE;
201 case WPS_AUTH_SHARED:
202 ssid->auth_alg = WPA_AUTH_ALG_SHARED;
203 ssid->key_mgmt = WPA_KEY_MGMT_NONE;
206 case WPS_AUTH_WPAPSK:
207 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
208 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
209 ssid->proto = WPA_PROTO_WPA;
212 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
213 ssid->key_mgmt = WPA_KEY_MGMT_IEEE8021X;
214 ssid->proto = WPA_PROTO_WPA;
217 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
218 ssid->key_mgmt = WPA_KEY_MGMT_IEEE8021X;
219 ssid->proto = WPA_PROTO_RSN;
221 case WPS_AUTH_WPA2PSK:
222 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
223 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
224 ssid->proto = WPA_PROTO_RSN;
228 if (ssid->key_mgmt == WPA_KEY_MGMT_PSK) {
229 if (cred->key_len == 2 * PMK_LEN) {
230 if (hexstr2bin((const char *) cred->key, ssid->psk,
232 wpa_printf(MSG_ERROR, "WPS: Invalid Network "
237 } else if (cred->key_len >= 8 && cred->key_len < 2 * PMK_LEN) {
238 os_free(ssid->passphrase);
239 ssid->passphrase = os_malloc(cred->key_len + 1);
240 if (ssid->passphrase == NULL)
242 os_memcpy(ssid->passphrase, cred->key, cred->key_len);
243 ssid->passphrase[cred->key_len] = '\0';
244 wpa_config_update_psk(ssid);
246 wpa_printf(MSG_ERROR, "WPS: Invalid Network Key "
248 (unsigned long) cred->key_len);
253 #ifndef CONFIG_NO_CONFIG_WRITE
254 if (wpa_s->conf->update_config &&
255 wpa_config_write(wpa_s->confname, wpa_s->conf)) {
256 wpa_printf(MSG_DEBUG, "WPS: Failed to update configuration");
259 #endif /* CONFIG_NO_CONFIG_WRITE */
265 static void wpa_supplicant_wps_event_m2d(struct wpa_supplicant *wpa_s,
266 struct wps_event_m2d *m2d)
268 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_M2D
269 "dev_password_id=%d config_error=%d",
270 m2d->dev_password_id, m2d->config_error);
274 static void wpa_supplicant_wps_event_fail(struct wpa_supplicant *wpa_s,
275 struct wps_event_fail *fail)
277 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_FAIL "msg=%d", fail->msg);
278 wpas_clear_wps(wpa_s);
282 static void wpa_supplicant_wps_event_success(struct wpa_supplicant *wpa_s)
284 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_SUCCESS);
285 wpa_s->wps_success = 1;
289 static void wpa_supplicant_wps_event(void *ctx, enum wps_event event,
290 union wps_event_data *data)
292 struct wpa_supplicant *wpa_s = ctx;
295 wpa_supplicant_wps_event_m2d(wpa_s, &data->m2d);
298 wpa_supplicant_wps_event_fail(wpa_s, &data->fail);
301 wpa_supplicant_wps_event_success(wpa_s);
303 case WPS_EV_PWD_AUTH_FAIL:
309 enum wps_request_type wpas_wps_get_req_type(struct wpa_ssid *ssid)
311 if (eap_is_wps_pbc_enrollee(&ssid->eap) ||
312 eap_is_wps_pin_enrollee(&ssid->eap))
313 return WPS_REQ_ENROLLEE;
315 return WPS_REQ_REGISTRAR;
319 static void wpas_clear_wps(struct wpa_supplicant *wpa_s)
322 struct wpa_ssid *ssid;
324 eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
326 /* Remove any existing WPS network from configuration */
327 ssid = wpa_s->conf->ssid;
329 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
330 if (ssid == wpa_s->current_ssid)
331 wpa_s->current_ssid = NULL;
337 wpa_config_remove_network(wpa_s->conf, id);
342 static void wpas_wps_timeout(void *eloop_ctx, void *timeout_ctx)
344 struct wpa_supplicant *wpa_s = eloop_ctx;
345 wpa_printf(MSG_INFO, WPS_EVENT_TIMEOUT "Requested operation timed "
347 wpas_clear_wps(wpa_s);
351 static struct wpa_ssid * wpas_wps_add_network(struct wpa_supplicant *wpa_s,
352 int registrar, const u8 *bssid)
354 struct wpa_ssid *ssid;
356 ssid = wpa_config_add_network(wpa_s->conf);
359 wpa_config_set_network_defaults(ssid);
360 if (wpa_config_set(ssid, "key_mgmt", "WPS", 0) < 0 ||
361 wpa_config_set(ssid, "eap", "WSC", 0) < 0 ||
362 wpa_config_set(ssid, "identity", registrar ?
363 "\"" WSC_ID_REGISTRAR "\"" :
364 "\"" WSC_ID_ENROLLEE "\"", 0) < 0) {
365 wpa_config_remove_network(wpa_s->conf, ssid->id);
371 struct wpa_scan_res *res;
373 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
376 /* Try to get SSID from scan results */
377 if (wpa_s->scan_res == NULL &&
378 wpa_supplicant_get_scan_results(wpa_s) < 0)
379 return ssid; /* Could not find any scan results */
381 for (i = 0; i < wpa_s->scan_res->num; i++) {
384 res = wpa_s->scan_res->res[i];
385 if (os_memcmp(bssid, res->bssid, ETH_ALEN) != 0)
388 ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
392 ssid->ssid = os_malloc(ie[1]);
393 if (ssid->ssid == NULL)
395 os_memcpy(ssid->ssid, ie + 2, ie[1]);
396 ssid->ssid_len = ie[1];
405 static void wpas_wps_reassoc(struct wpa_supplicant *wpa_s,
406 struct wpa_ssid *selected)
408 struct wpa_ssid *ssid;
410 /* Mark all other networks disabled and trigger reassociation */
411 ssid = wpa_s->conf->ssid;
413 ssid->disabled = ssid != selected;
416 wpa_s->disconnected = 0;
417 wpa_s->reassociate = 1;
418 wpa_s->scan_runs = 0;
419 wpa_s->wps_success = 0;
420 wpa_s->blacklist_cleared = 0;
421 wpa_supplicant_req_scan(wpa_s, 0, 0);
425 int wpas_wps_start_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid)
427 struct wpa_ssid *ssid;
428 wpas_clear_wps(wpa_s);
429 ssid = wpas_wps_add_network(wpa_s, 0, bssid);
432 wpa_config_set(ssid, "phase1", "\"pbc=1\"", 0);
433 eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
435 wpas_wps_reassoc(wpa_s, ssid);
440 int wpas_wps_start_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
443 struct wpa_ssid *ssid;
445 unsigned int rpin = 0;
447 wpas_clear_wps(wpa_s);
448 ssid = wpas_wps_add_network(wpa_s, 0, bssid);
452 os_snprintf(val, sizeof(val), "\"pin=%s\"", pin);
454 rpin = wps_generate_pin();
455 os_snprintf(val, sizeof(val), "\"pin=%08d\"", rpin);
457 wpa_config_set(ssid, "phase1", val, 0);
458 eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
460 wpas_wps_reassoc(wpa_s, ssid);
465 int wpas_wps_start_oob(struct wpa_supplicant *wpa_s, char *device_type,
466 char *path, char *method)
468 struct wps_context *wps = wpa_s->wps;
469 struct oob_device_data *oob_dev;
471 oob_dev = wps_get_oob_device(device_type);
474 oob_dev->device_path = path;
475 wps->oob_conf.oob_method = wps_get_oob_method(method);
477 if (wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E) {
479 * Use pre-configured DH keys in order to be able to write the
480 * key hash into the OOB file.
482 wpabuf_free(wps->dh_pubkey);
483 wpabuf_free(wps->dh_privkey);
484 wps->dh_privkey = NULL;
485 wps->dh_pubkey = dh_init(dh_groups_get(WPS_DH_GROUP),
487 wps->dh_pubkey = wpabuf_zeropad(wps->dh_pubkey, 192);
488 if (wps->dh_pubkey == NULL) {
489 wpa_printf(MSG_ERROR, "WPS: Failed to initialize "
490 "Diffie-Hellman handshake");
495 if (wps->oob_conf.oob_method == OOB_METHOD_CRED)
496 wpas_clear_wps(wpa_s);
498 if (wps_process_oob(wps, oob_dev, 0) < 0)
501 if ((wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E ||
502 wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_R) &&
503 wpas_wps_start_pin(wpa_s, NULL,
504 wpabuf_head(wps->oob_conf.dev_password)) < 0)
511 int wpas_wps_start_reg(struct wpa_supplicant *wpa_s, const u8 *bssid,
514 struct wpa_ssid *ssid;
519 wpas_clear_wps(wpa_s);
520 ssid = wpas_wps_add_network(wpa_s, 1, bssid);
523 os_snprintf(val, sizeof(val), "\"pin=%s\"", pin);
524 wpa_config_set(ssid, "phase1", val, 0);
525 eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
527 wpas_wps_reassoc(wpa_s, ssid);
532 static int wpas_wps_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *psk,
535 wpa_printf(MSG_DEBUG, "WPS: Received new WPA/WPA2-PSK from WPS for "
536 "STA " MACSTR, MAC2STR(mac_addr));
537 wpa_hexdump_key(MSG_DEBUG, "Per-device PSK", psk, psk_len);
545 static void wpas_wps_pin_needed_cb(void *ctx, const u8 *uuid_e,
546 const struct wps_device_data *dev)
548 char uuid[40], txt[400];
550 if (uuid_bin2str(uuid_e, uuid, sizeof(uuid)))
552 wpa_printf(MSG_DEBUG, "WPS: PIN needed for UUID-E %s", uuid);
553 len = os_snprintf(txt, sizeof(txt), "WPS-EVENT-PIN-NEEDED %s " MACSTR
554 " [%s|%s|%s|%s|%s|%d-%08X-%d]",
555 uuid, MAC2STR(dev->mac_addr), dev->device_name,
556 dev->manufacturer, dev->model_name,
557 dev->model_number, dev->serial_number,
558 dev->categ, dev->oui, dev->sub_categ);
559 if (len > 0 && len < (int) sizeof(txt))
560 wpa_printf(MSG_INFO, "%s", txt);
564 int wpas_wps_init(struct wpa_supplicant *wpa_s)
566 struct wps_context *wps;
567 struct wps_registrar_config rcfg;
569 wps = os_zalloc(sizeof(*wps));
573 wps->cred_cb = wpa_supplicant_wps_cred;
574 wps->event_cb = wpa_supplicant_wps_event;
577 wps->dev.device_name = wpa_s->conf->device_name;
578 wps->dev.manufacturer = wpa_s->conf->manufacturer;
579 wps->dev.model_name = wpa_s->conf->model_name;
580 wps->dev.model_number = wpa_s->conf->model_number;
581 wps->dev.serial_number = wpa_s->conf->serial_number;
582 if (wpa_s->conf->device_type) {
585 /* <categ>-<OUI>-<subcateg> */
586 wps->dev.categ = atoi(wpa_s->conf->device_type);
587 pos = os_strchr(wpa_s->conf->device_type, '-');
589 wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
594 if (hexstr2bin(pos, oui, 4)) {
595 wpa_printf(MSG_ERROR, "WPS: Invalid device_type OUI");
599 wps->dev.oui = WPA_GET_BE32(oui);
600 pos = os_strchr(pos, '-');
602 wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
607 wps->dev.sub_categ = atoi(pos);
609 wps->dev.os_version = WPA_GET_BE32(wpa_s->conf->os_version);
610 wps->dev.rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ; /* TODO: config */
611 os_memcpy(wps->dev.mac_addr, wpa_s->own_addr, ETH_ALEN);
612 if (is_nil_uuid(wpa_s->conf->uuid)) {
613 uuid_gen_mac_addr(wpa_s->own_addr, wps->uuid);
614 wpa_hexdump(MSG_DEBUG, "WPS: UUID based on MAC address",
615 wps->uuid, WPS_UUID_LEN);
617 os_memcpy(wps->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
619 wps->auth_types = WPS_AUTH_WPA2PSK | WPS_AUTH_WPAPSK;
620 wps->encr_types = WPS_ENCR_AES | WPS_ENCR_TKIP;
622 os_memset(&rcfg, 0, sizeof(rcfg));
623 rcfg.new_psk_cb = wpas_wps_new_psk_cb;
624 rcfg.pin_needed_cb = wpas_wps_pin_needed_cb;
627 wps->registrar = wps_registrar_init(wps, &rcfg);
628 if (wps->registrar == NULL) {
629 wpa_printf(MSG_DEBUG, "Failed to initialize WPS Registrar");
640 void wpas_wps_deinit(struct wpa_supplicant *wpa_s)
642 eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
644 if (wpa_s->wps == NULL)
647 wps_registrar_deinit(wpa_s->wps->registrar);
648 wpabuf_free(wpa_s->wps->dh_pubkey);
649 wpabuf_free(wpa_s->wps->dh_privkey);
650 wpabuf_free(wpa_s->wps->oob_conf.pubkey_hash);
651 wpabuf_free(wpa_s->wps->oob_conf.dev_password);
652 os_free(wpa_s->wps->network_key);
658 int wpas_wps_ssid_bss_match(struct wpa_supplicant *wpa_s,
659 struct wpa_ssid *ssid, struct wpa_scan_res *bss)
661 struct wpabuf *wps_ie;
663 if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS))
666 wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
667 if (eap_is_wps_pbc_enrollee(&ssid->eap)) {
669 wpa_printf(MSG_DEBUG, " skip - non-WPS AP");
673 if (!wps_is_selected_pbc_registrar(wps_ie)) {
674 wpa_printf(MSG_DEBUG, " skip - WPS AP "
675 "without active PBC Registrar");
680 /* TODO: overlap detection */
681 wpa_printf(MSG_DEBUG, " selected based on WPS IE "
687 if (eap_is_wps_pin_enrollee(&ssid->eap)) {
689 wpa_printf(MSG_DEBUG, " skip - non-WPS AP");
694 * Start with WPS APs that advertise active PIN Registrar and
695 * allow any WPS AP after third scan since some APs do not set
696 * Selected Registrar attribute properly when using external
699 if (!wps_is_selected_pin_registrar(wps_ie)) {
700 if (wpa_s->scan_runs < WPS_PIN_SCAN_IGNORE_SEL_REG) {
701 wpa_printf(MSG_DEBUG, " skip - WPS AP "
702 "without active PIN Registrar");
706 wpa_printf(MSG_DEBUG, " selected based on WPS IE");
708 wpa_printf(MSG_DEBUG, " selected based on WPS IE "
716 wpa_printf(MSG_DEBUG, " selected based on WPS IE");
725 int wpas_wps_ssid_wildcard_ok(struct wpa_supplicant *wpa_s,
726 struct wpa_ssid *ssid,
727 struct wpa_scan_res *bss)
729 struct wpabuf *wps_ie = NULL;
732 if (eap_is_wps_pbc_enrollee(&ssid->eap)) {
733 wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
734 if (wps_ie && wps_is_selected_pbc_registrar(wps_ie)) {
735 /* allow wildcard SSID for WPS PBC */
738 } else if (eap_is_wps_pin_enrollee(&ssid->eap)) {
739 wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
741 (wps_is_selected_pin_registrar(wps_ie) ||
742 wpa_s->scan_runs >= WPS_PIN_SCAN_IGNORE_SEL_REG)) {
743 /* allow wildcard SSID for WPS PIN */
748 if (!ret && ssid->bssid_set &&
749 os_memcmp(ssid->bssid, bss->bssid, ETH_ALEN) == 0) {
750 /* allow wildcard SSID due to hardcoded BSSID match */
760 int wpas_wps_scan_pbc_overlap(struct wpa_supplicant *wpa_s,
761 struct wpa_scan_res *selected,
762 struct wpa_ssid *ssid)
764 const u8 *sel_uuid, *uuid;
766 struct wpabuf *wps_ie;
769 if (!eap_is_wps_pbc_enrollee(&ssid->eap))
772 /* Make sure that only one AP is in active PBC mode */
773 wps_ie = wpa_scan_get_vendor_ie_multi(selected, WPS_IE_VENDOR_TYPE);
775 sel_uuid = wps_get_uuid_e(wps_ie);
779 for (i = 0; i < wpa_s->scan_res->num; i++) {
780 struct wpa_scan_res *bss = wpa_s->scan_res->res[i];
784 ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
787 if (!wps_is_selected_pbc_registrar(ie)) {
791 uuid = wps_get_uuid_e(ie);
792 if (sel_uuid == NULL || uuid == NULL ||
793 os_memcmp(sel_uuid, uuid, 16) != 0) {
794 ret = 1; /* PBC overlap */
799 /* TODO: verify that this is reasonable dual-band situation */
810 void wpas_wps_notify_scan_results(struct wpa_supplicant *wpa_s)
814 if (wpa_s->disconnected || wpa_s->wpa_state >= WPA_ASSOCIATED)
817 for (i = 0; i < wpa_s->scan_res->num; i++) {
818 struct wpa_scan_res *bss = wpa_s->scan_res->res[i];
820 ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
823 if (wps_is_selected_pbc_registrar(ie))
824 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PBC);
825 else if (wps_is_selected_pin_registrar(ie))
826 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PIN);
828 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE);
835 int wpas_wps_searching(struct wpa_supplicant *wpa_s)
837 struct wpa_ssid *ssid;
839 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
840 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && !ssid->disabled)