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"
30 #include "wps_supplicant.h"
31 #include "dh_groups.h"
33 #define WPS_PIN_SCAN_IGNORE_SEL_REG 3
35 static void wpas_wps_timeout(void *eloop_ctx, void *timeout_ctx);
36 static void wpas_clear_wps(struct wpa_supplicant *wpa_s);
39 int wpas_wps_eapol_cb(struct wpa_supplicant *wpa_s)
41 if (!wpa_s->wps_success &&
42 wpa_s->current_ssid &&
43 eap_is_wps_pin_enrollee(&wpa_s->current_ssid->eap)) {
44 const u8 *bssid = wpa_s->bssid;
45 if (is_zero_ether_addr(bssid))
46 bssid = wpa_s->pending_bssid;
48 wpa_printf(MSG_DEBUG, "WPS: PIN registration with " MACSTR
49 " did not succeed - continue trying to find "
50 "suitable AP", MAC2STR(bssid));
51 wpa_blacklist_add(wpa_s, bssid);
53 wpa_supplicant_deauthenticate(wpa_s,
54 WLAN_REASON_DEAUTH_LEAVING);
55 wpa_s->reassociate = 1;
56 wpa_supplicant_req_scan(wpa_s,
57 wpa_s->blacklist_cleared ? 5 : 0, 0);
58 wpa_s->blacklist_cleared = 0;
62 eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
64 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && wpa_s->current_ssid &&
65 !(wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
66 wpa_printf(MSG_DEBUG, "WPS: Network configuration replaced - "
67 "try to associate with the received credential");
68 wpa_supplicant_deauthenticate(wpa_s,
69 WLAN_REASON_DEAUTH_LEAVING);
70 wpa_s->reassociate = 1;
71 wpa_supplicant_req_scan(wpa_s, 0, 0);
75 if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && wpa_s->current_ssid) {
76 wpa_printf(MSG_DEBUG, "WPS: Registration completed - waiting "
77 "for external credential processing");
78 wpas_clear_wps(wpa_s);
79 wpa_supplicant_deauthenticate(wpa_s,
80 WLAN_REASON_DEAUTH_LEAVING);
88 static void wpas_wps_security_workaround(struct wpa_supplicant *wpa_s,
89 struct wpa_ssid *ssid,
90 const struct wps_credential *cred)
92 struct wpa_driver_capa capa;
94 struct wpa_scan_res *bss;
96 struct wpa_ie_data adv;
97 int wpa2 = 0, ccmp = 0;
100 * Many existing WPS APs do not know how to negotiate WPA2 or CCMP in
101 * case they are configured for mixed mode operation (WPA+WPA2 and
102 * TKIP+CCMP). Try to use scan results to figure out whether the AP
103 * actually supports stronger security and select that if the client
104 * has support for it, too.
107 if (wpa_drv_get_capa(wpa_s, &capa))
108 return; /* Unknown what driver supports */
110 if (wpa_supplicant_get_scan_results(wpa_s) || wpa_s->scan_res == NULL)
111 return; /* Could not get scan results for checking advertised
114 for (i = 0; i < wpa_s->scan_res->num; i++) {
115 bss = wpa_s->scan_res->res[i];
116 if (os_memcmp(bss->bssid, cred->mac_addr, ETH_ALEN) != 0)
118 ie = wpa_scan_get_ie(bss, WLAN_EID_SSID);
121 if (ie[1] != ssid->ssid_len || ssid->ssid == NULL ||
122 os_memcmp(ie + 2, ssid->ssid, ssid->ssid_len) != 0)
125 wpa_printf(MSG_DEBUG, "WPS: AP found from scan results");
129 if (i == wpa_s->scan_res->num) {
130 wpa_printf(MSG_DEBUG, "WPS: The AP was not found from scan "
131 "results - use credential as-is");
135 ie = wpa_scan_get_ie(bss, WLAN_EID_RSN);
136 if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0) {
138 if (adv.pairwise_cipher & WPA_CIPHER_CCMP)
141 ie = wpa_scan_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
142 if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0 &&
143 adv.pairwise_cipher & WPA_CIPHER_CCMP)
147 if (ie == NULL && (ssid->proto & WPA_PROTO_WPA) &&
148 (ssid->pairwise_cipher & WPA_CIPHER_TKIP)) {
150 * TODO: This could be the initial AP configuration and the
151 * Beacon contents could change shortly. Should request a new
152 * scan and delay addition of the network until the updated
153 * scan results are available.
155 wpa_printf(MSG_DEBUG, "WPS: The AP did not yet advertise WPA "
156 "support - use credential as-is");
160 if (ccmp && !(ssid->pairwise_cipher & WPA_CIPHER_CCMP) &&
161 (ssid->pairwise_cipher & WPA_CIPHER_TKIP) &&
162 (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
163 wpa_printf(MSG_DEBUG, "WPS: Add CCMP into the credential "
164 "based on scan results");
165 if (wpa_s->conf->ap_scan == 1)
166 ssid->pairwise_cipher |= WPA_CIPHER_CCMP;
168 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
171 if (wpa2 && !(ssid->proto & WPA_PROTO_RSN) &&
172 (ssid->proto & WPA_PROTO_WPA) &&
173 (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP)) {
174 wpa_printf(MSG_DEBUG, "WPS: Add WPA2 into the credential "
175 "based on scan results");
176 if (wpa_s->conf->ap_scan == 1)
177 ssid->proto |= WPA_PROTO_RSN;
179 ssid->proto = WPA_PROTO_RSN;
184 static int wpa_supplicant_wps_cred(void *ctx,
185 const struct wps_credential *cred)
187 struct wpa_supplicant *wpa_s = ctx;
188 struct wpa_ssid *ssid = wpa_s->current_ssid;
191 if ((wpa_s->conf->wps_cred_processing == 1 ||
192 wpa_s->conf->wps_cred_processing == 2) && cred->cred_attr) {
193 size_t blen = cred->cred_attr_len * 2 + 1;
194 char *buf = os_malloc(blen);
196 wpa_snprintf_hex(buf, blen,
197 cred->cred_attr, cred->cred_attr_len);
198 wpa_msg(wpa_s, MSG_INFO, "%s%s",
199 WPS_EVENT_CRED_RECEIVED, buf);
202 wpa_supplicant_dbus_notify_wps_cred(wpa_s, cred);
204 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_CRED_RECEIVED);
206 wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
207 cred->cred_attr, cred->cred_attr_len);
209 if (wpa_s->conf->wps_cred_processing == 1)
212 if (cred->auth_type != WPS_AUTH_OPEN &&
213 cred->auth_type != WPS_AUTH_SHARED &&
214 cred->auth_type != WPS_AUTH_WPAPSK &&
215 cred->auth_type != WPS_AUTH_WPA2PSK) {
216 wpa_printf(MSG_DEBUG, "WPS: Ignored credentials for "
217 "unsupported authentication type %d",
222 if (ssid && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) {
223 wpa_printf(MSG_DEBUG, "WPS: Replace WPS network block based "
224 "on the received credential");
225 os_free(ssid->eap.identity);
226 ssid->eap.identity = NULL;
227 ssid->eap.identity_len = 0;
228 os_free(ssid->eap.phase1);
229 ssid->eap.phase1 = NULL;
230 os_free(ssid->eap.eap_methods);
231 ssid->eap.eap_methods = NULL;
233 wpa_printf(MSG_DEBUG, "WPS: Create a new network based on the "
234 "received credential");
235 ssid = wpa_config_add_network(wpa_s->conf);
240 wpa_config_set_network_defaults(ssid);
243 ssid->ssid = os_malloc(cred->ssid_len);
245 os_memcpy(ssid->ssid, cred->ssid, cred->ssid_len);
246 ssid->ssid_len = cred->ssid_len;
249 switch (cred->encr_type) {
253 if (cred->key_len <= 0)
255 if (cred->key_len != 5 && cred->key_len != 13 &&
256 cred->key_len != 10 && cred->key_len != 26) {
257 wpa_printf(MSG_ERROR, "WPS: Invalid WEP Key length "
258 "%lu", (unsigned long) cred->key_len);
261 if (cred->key_idx > NUM_WEP_KEYS) {
262 wpa_printf(MSG_ERROR, "WPS: Invalid WEP Key index %d",
267 key_idx = cred->key_idx - 1;
268 if (cred->key_len == 10 || cred->key_len == 26) {
269 if (hexstr2bin((char *) cred->key,
270 ssid->wep_key[key_idx],
271 cred->key_len / 2) < 0) {
272 wpa_printf(MSG_ERROR, "WPS: Invalid WEP Key "
276 ssid->wep_key_len[key_idx] = cred->key_len / 2;
278 os_memcpy(ssid->wep_key[key_idx], cred->key,
280 ssid->wep_key_len[key_idx] = cred->key_len;
282 ssid->wep_tx_keyidx = key_idx;
285 ssid->pairwise_cipher = WPA_CIPHER_TKIP;
288 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
292 switch (cred->auth_type) {
294 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
295 ssid->key_mgmt = WPA_KEY_MGMT_NONE;
298 case WPS_AUTH_SHARED:
299 ssid->auth_alg = WPA_AUTH_ALG_SHARED;
300 ssid->key_mgmt = WPA_KEY_MGMT_NONE;
303 case WPS_AUTH_WPAPSK:
304 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
305 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
306 ssid->proto = WPA_PROTO_WPA;
309 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
310 ssid->key_mgmt = WPA_KEY_MGMT_IEEE8021X;
311 ssid->proto = WPA_PROTO_WPA;
314 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
315 ssid->key_mgmt = WPA_KEY_MGMT_IEEE8021X;
316 ssid->proto = WPA_PROTO_RSN;
318 case WPS_AUTH_WPA2PSK:
319 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
320 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
321 ssid->proto = WPA_PROTO_RSN;
325 if (ssid->key_mgmt == WPA_KEY_MGMT_PSK) {
326 if (cred->key_len == 2 * PMK_LEN) {
327 if (hexstr2bin((const char *) cred->key, ssid->psk,
329 wpa_printf(MSG_ERROR, "WPS: Invalid Network "
334 } else if (cred->key_len >= 8 && cred->key_len < 2 * PMK_LEN) {
335 os_free(ssid->passphrase);
336 ssid->passphrase = os_malloc(cred->key_len + 1);
337 if (ssid->passphrase == NULL)
339 os_memcpy(ssid->passphrase, cred->key, cred->key_len);
340 ssid->passphrase[cred->key_len] = '\0';
341 wpa_config_update_psk(ssid);
343 wpa_printf(MSG_ERROR, "WPS: Invalid Network Key "
345 (unsigned long) cred->key_len);
350 wpas_wps_security_workaround(wpa_s, ssid, cred);
352 #ifndef CONFIG_NO_CONFIG_WRITE
353 if (wpa_s->conf->update_config &&
354 wpa_config_write(wpa_s->confname, wpa_s->conf)) {
355 wpa_printf(MSG_DEBUG, "WPS: Failed to update configuration");
358 #endif /* CONFIG_NO_CONFIG_WRITE */
364 static void wpa_supplicant_wps_event_m2d(struct wpa_supplicant *wpa_s,
365 struct wps_event_m2d *m2d)
367 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_M2D
368 "dev_password_id=%d config_error=%d",
369 m2d->dev_password_id, m2d->config_error);
373 static void wpa_supplicant_wps_event_fail(struct wpa_supplicant *wpa_s,
374 struct wps_event_fail *fail)
376 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_FAIL "msg=%d", fail->msg);
377 wpas_clear_wps(wpa_s);
381 static void wpa_supplicant_wps_event_success(struct wpa_supplicant *wpa_s)
383 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_SUCCESS);
384 wpa_s->wps_success = 1;
388 static void wpa_supplicant_wps_event(void *ctx, enum wps_event event,
389 union wps_event_data *data)
391 struct wpa_supplicant *wpa_s = ctx;
394 wpa_supplicant_wps_event_m2d(wpa_s, &data->m2d);
397 wpa_supplicant_wps_event_fail(wpa_s, &data->fail);
400 wpa_supplicant_wps_event_success(wpa_s);
402 case WPS_EV_PWD_AUTH_FAIL:
408 enum wps_request_type wpas_wps_get_req_type(struct wpa_ssid *ssid)
410 if (eap_is_wps_pbc_enrollee(&ssid->eap) ||
411 eap_is_wps_pin_enrollee(&ssid->eap))
412 return WPS_REQ_ENROLLEE;
414 return WPS_REQ_REGISTRAR;
418 static void wpas_clear_wps(struct wpa_supplicant *wpa_s)
421 struct wpa_ssid *ssid;
423 eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
425 /* Remove any existing WPS network from configuration */
426 ssid = wpa_s->conf->ssid;
428 if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
429 if (ssid == wpa_s->current_ssid)
430 wpa_s->current_ssid = NULL;
436 wpa_config_remove_network(wpa_s->conf, id);
441 static void wpas_wps_timeout(void *eloop_ctx, void *timeout_ctx)
443 struct wpa_supplicant *wpa_s = eloop_ctx;
444 wpa_printf(MSG_INFO, WPS_EVENT_TIMEOUT "Requested operation timed "
446 wpas_clear_wps(wpa_s);
450 static struct wpa_ssid * wpas_wps_add_network(struct wpa_supplicant *wpa_s,
451 int registrar, const u8 *bssid)
453 struct wpa_ssid *ssid;
455 ssid = wpa_config_add_network(wpa_s->conf);
458 wpa_config_set_network_defaults(ssid);
459 if (wpa_config_set(ssid, "key_mgmt", "WPS", 0) < 0 ||
460 wpa_config_set(ssid, "eap", "WSC", 0) < 0 ||
461 wpa_config_set(ssid, "identity", registrar ?
462 "\"" WSC_ID_REGISTRAR "\"" :
463 "\"" WSC_ID_ENROLLEE "\"", 0) < 0) {
464 wpa_config_remove_network(wpa_s->conf, ssid->id);
470 struct wpa_scan_res *res;
472 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
475 /* Try to get SSID from scan results */
476 if (wpa_s->scan_res == NULL &&
477 wpa_supplicant_get_scan_results(wpa_s) < 0)
478 return ssid; /* Could not find any scan results */
480 for (i = 0; i < wpa_s->scan_res->num; i++) {
483 res = wpa_s->scan_res->res[i];
484 if (os_memcmp(bssid, res->bssid, ETH_ALEN) != 0)
487 ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
491 ssid->ssid = os_malloc(ie[1]);
492 if (ssid->ssid == NULL)
494 os_memcpy(ssid->ssid, ie + 2, ie[1]);
495 ssid->ssid_len = ie[1];
504 static void wpas_wps_reassoc(struct wpa_supplicant *wpa_s,
505 struct wpa_ssid *selected)
507 struct wpa_ssid *ssid;
509 /* Mark all other networks disabled and trigger reassociation */
510 ssid = wpa_s->conf->ssid;
512 ssid->disabled = ssid != selected;
515 wpa_s->disconnected = 0;
516 wpa_s->reassociate = 1;
517 wpa_s->scan_runs = 0;
518 wpa_s->wps_success = 0;
519 wpa_s->blacklist_cleared = 0;
520 wpa_supplicant_req_scan(wpa_s, 0, 0);
524 int wpas_wps_start_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid)
526 struct wpa_ssid *ssid;
527 wpas_clear_wps(wpa_s);
528 ssid = wpas_wps_add_network(wpa_s, 0, bssid);
531 wpa_config_set(ssid, "phase1", "\"pbc=1\"", 0);
532 eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
534 wpas_wps_reassoc(wpa_s, ssid);
539 int wpas_wps_start_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
542 struct wpa_ssid *ssid;
544 unsigned int rpin = 0;
546 wpas_clear_wps(wpa_s);
547 ssid = wpas_wps_add_network(wpa_s, 0, bssid);
551 os_snprintf(val, sizeof(val), "\"pin=%s\"", pin);
553 rpin = wps_generate_pin();
554 os_snprintf(val, sizeof(val), "\"pin=%08d\"", rpin);
556 wpa_config_set(ssid, "phase1", val, 0);
557 eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
559 wpas_wps_reassoc(wpa_s, ssid);
564 #ifdef CONFIG_WPS_OOB
565 int wpas_wps_start_oob(struct wpa_supplicant *wpa_s, char *device_type,
566 char *path, char *method)
568 struct wps_context *wps = wpa_s->wps;
569 struct oob_device_data *oob_dev;
571 oob_dev = wps_get_oob_device(device_type);
574 oob_dev->device_path = path;
575 wps->oob_conf.oob_method = wps_get_oob_method(method);
577 if (wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E) {
579 * Use pre-configured DH keys in order to be able to write the
580 * key hash into the OOB file.
582 wpabuf_free(wps->dh_pubkey);
583 wpabuf_free(wps->dh_privkey);
584 wps->dh_privkey = NULL;
585 wps->dh_pubkey = dh_init(dh_groups_get(WPS_DH_GROUP),
587 wps->dh_pubkey = wpabuf_zeropad(wps->dh_pubkey, 192);
588 if (wps->dh_pubkey == NULL) {
589 wpa_printf(MSG_ERROR, "WPS: Failed to initialize "
590 "Diffie-Hellman handshake");
595 if (wps->oob_conf.oob_method == OOB_METHOD_CRED)
596 wpas_clear_wps(wpa_s);
598 if (wps_process_oob(wps, oob_dev, 0) < 0)
601 if ((wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E ||
602 wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_R) &&
603 wpas_wps_start_pin(wpa_s, NULL,
604 wpabuf_head(wps->oob_conf.dev_password)) < 0)
609 #endif /* CONFIG_WPS_OOB */
612 int wpas_wps_start_reg(struct wpa_supplicant *wpa_s, const u8 *bssid,
615 struct wpa_ssid *ssid;
620 wpas_clear_wps(wpa_s);
621 ssid = wpas_wps_add_network(wpa_s, 1, bssid);
624 os_snprintf(val, sizeof(val), "\"pin=%s\"", pin);
625 wpa_config_set(ssid, "phase1", val, 0);
626 eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout,
628 wpas_wps_reassoc(wpa_s, ssid);
633 static int wpas_wps_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *psk,
636 wpa_printf(MSG_DEBUG, "WPS: Received new WPA/WPA2-PSK from WPS for "
637 "STA " MACSTR, MAC2STR(mac_addr));
638 wpa_hexdump_key(MSG_DEBUG, "Per-device PSK", psk, psk_len);
646 static void wpas_wps_pin_needed_cb(void *ctx, const u8 *uuid_e,
647 const struct wps_device_data *dev)
649 char uuid[40], txt[400];
651 if (uuid_bin2str(uuid_e, uuid, sizeof(uuid)))
653 wpa_printf(MSG_DEBUG, "WPS: PIN needed for UUID-E %s", uuid);
654 len = os_snprintf(txt, sizeof(txt), "WPS-EVENT-PIN-NEEDED %s " MACSTR
655 " [%s|%s|%s|%s|%s|%d-%08X-%d]",
656 uuid, MAC2STR(dev->mac_addr), dev->device_name,
657 dev->manufacturer, dev->model_name,
658 dev->model_number, dev->serial_number,
659 dev->categ, dev->oui, dev->sub_categ);
660 if (len > 0 && len < (int) sizeof(txt))
661 wpa_printf(MSG_INFO, "%s", txt);
665 int wpas_wps_init(struct wpa_supplicant *wpa_s)
667 struct wps_context *wps;
668 struct wps_registrar_config rcfg;
670 wps = os_zalloc(sizeof(*wps));
674 wps->cred_cb = wpa_supplicant_wps_cred;
675 wps->event_cb = wpa_supplicant_wps_event;
678 wps->dev.device_name = wpa_s->conf->device_name;
679 wps->dev.manufacturer = wpa_s->conf->manufacturer;
680 wps->dev.model_name = wpa_s->conf->model_name;
681 wps->dev.model_number = wpa_s->conf->model_number;
682 wps->dev.serial_number = wpa_s->conf->serial_number;
683 if (wpa_s->conf->device_type) {
686 /* <categ>-<OUI>-<subcateg> */
687 wps->dev.categ = atoi(wpa_s->conf->device_type);
688 pos = os_strchr(wpa_s->conf->device_type, '-');
690 wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
695 if (hexstr2bin(pos, oui, 4)) {
696 wpa_printf(MSG_ERROR, "WPS: Invalid device_type OUI");
700 wps->dev.oui = WPA_GET_BE32(oui);
701 pos = os_strchr(pos, '-');
703 wpa_printf(MSG_ERROR, "WPS: Invalid device_type");
708 wps->dev.sub_categ = atoi(pos);
710 wps->dev.os_version = WPA_GET_BE32(wpa_s->conf->os_version);
711 wps->dev.rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ; /* TODO: config */
712 os_memcpy(wps->dev.mac_addr, wpa_s->own_addr, ETH_ALEN);
713 if (is_nil_uuid(wpa_s->conf->uuid)) {
714 uuid_gen_mac_addr(wpa_s->own_addr, wps->uuid);
715 wpa_hexdump(MSG_DEBUG, "WPS: UUID based on MAC address",
716 wps->uuid, WPS_UUID_LEN);
718 os_memcpy(wps->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
720 wps->auth_types = WPS_AUTH_WPA2PSK | WPS_AUTH_WPAPSK;
721 wps->encr_types = WPS_ENCR_AES | WPS_ENCR_TKIP;
723 os_memset(&rcfg, 0, sizeof(rcfg));
724 rcfg.new_psk_cb = wpas_wps_new_psk_cb;
725 rcfg.pin_needed_cb = wpas_wps_pin_needed_cb;
728 wps->registrar = wps_registrar_init(wps, &rcfg);
729 if (wps->registrar == NULL) {
730 wpa_printf(MSG_DEBUG, "Failed to initialize WPS Registrar");
741 void wpas_wps_deinit(struct wpa_supplicant *wpa_s)
743 eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL);
745 if (wpa_s->wps == NULL)
748 wps_registrar_deinit(wpa_s->wps->registrar);
749 wpabuf_free(wpa_s->wps->dh_pubkey);
750 wpabuf_free(wpa_s->wps->dh_privkey);
751 wpabuf_free(wpa_s->wps->oob_conf.pubkey_hash);
752 wpabuf_free(wpa_s->wps->oob_conf.dev_password);
753 os_free(wpa_s->wps->network_key);
759 int wpas_wps_ssid_bss_match(struct wpa_supplicant *wpa_s,
760 struct wpa_ssid *ssid, struct wpa_scan_res *bss)
762 struct wpabuf *wps_ie;
764 if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS))
767 wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
768 if (eap_is_wps_pbc_enrollee(&ssid->eap)) {
770 wpa_printf(MSG_DEBUG, " skip - non-WPS AP");
774 if (!wps_is_selected_pbc_registrar(wps_ie)) {
775 wpa_printf(MSG_DEBUG, " skip - WPS AP "
776 "without active PBC Registrar");
781 /* TODO: overlap detection */
782 wpa_printf(MSG_DEBUG, " selected based on WPS IE "
788 if (eap_is_wps_pin_enrollee(&ssid->eap)) {
790 wpa_printf(MSG_DEBUG, " skip - non-WPS AP");
795 * Start with WPS APs that advertise active PIN Registrar and
796 * allow any WPS AP after third scan since some APs do not set
797 * Selected Registrar attribute properly when using external
800 if (!wps_is_selected_pin_registrar(wps_ie)) {
801 if (wpa_s->scan_runs < WPS_PIN_SCAN_IGNORE_SEL_REG) {
802 wpa_printf(MSG_DEBUG, " skip - WPS AP "
803 "without active PIN Registrar");
807 wpa_printf(MSG_DEBUG, " selected based on WPS IE");
809 wpa_printf(MSG_DEBUG, " selected based on WPS IE "
817 wpa_printf(MSG_DEBUG, " selected based on WPS IE");
826 int wpas_wps_ssid_wildcard_ok(struct wpa_supplicant *wpa_s,
827 struct wpa_ssid *ssid,
828 struct wpa_scan_res *bss)
830 struct wpabuf *wps_ie = NULL;
833 if (eap_is_wps_pbc_enrollee(&ssid->eap)) {
834 wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
835 if (wps_ie && wps_is_selected_pbc_registrar(wps_ie)) {
836 /* allow wildcard SSID for WPS PBC */
839 } else if (eap_is_wps_pin_enrollee(&ssid->eap)) {
840 wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
842 (wps_is_selected_pin_registrar(wps_ie) ||
843 wpa_s->scan_runs >= WPS_PIN_SCAN_IGNORE_SEL_REG)) {
844 /* allow wildcard SSID for WPS PIN */
849 if (!ret && ssid->bssid_set &&
850 os_memcmp(ssid->bssid, bss->bssid, ETH_ALEN) == 0) {
851 /* allow wildcard SSID due to hardcoded BSSID match */
861 int wpas_wps_scan_pbc_overlap(struct wpa_supplicant *wpa_s,
862 struct wpa_scan_res *selected,
863 struct wpa_ssid *ssid)
865 const u8 *sel_uuid, *uuid;
867 struct wpabuf *wps_ie;
870 if (!eap_is_wps_pbc_enrollee(&ssid->eap))
873 /* Make sure that only one AP is in active PBC mode */
874 wps_ie = wpa_scan_get_vendor_ie_multi(selected, WPS_IE_VENDOR_TYPE);
876 sel_uuid = wps_get_uuid_e(wps_ie);
880 for (i = 0; i < wpa_s->scan_res->num; i++) {
881 struct wpa_scan_res *bss = wpa_s->scan_res->res[i];
885 ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
888 if (!wps_is_selected_pbc_registrar(ie)) {
892 uuid = wps_get_uuid_e(ie);
893 if (sel_uuid == NULL || uuid == NULL ||
894 os_memcmp(sel_uuid, uuid, 16) != 0) {
895 ret = 1; /* PBC overlap */
900 /* TODO: verify that this is reasonable dual-band situation */
911 void wpas_wps_notify_scan_results(struct wpa_supplicant *wpa_s)
915 if (wpa_s->disconnected || wpa_s->wpa_state >= WPA_ASSOCIATED)
918 for (i = 0; i < wpa_s->scan_res->num; i++) {
919 struct wpa_scan_res *bss = wpa_s->scan_res->res[i];
921 ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
924 if (wps_is_selected_pbc_registrar(ie))
925 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PBC);
926 else if (wps_is_selected_pin_registrar(ie))
927 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PIN);
929 wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE);
936 int wpas_wps_searching(struct wpa_supplicant *wpa_s)
938 struct wpa_ssid *ssid;
940 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
941 if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && !ssid->disabled)