Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 1 | /* |
| 2 | * wpa_supplicant / WPS integration |
Jouni Malinen | 6fa81a3 | 2010-01-02 16:16:02 +0200 | [diff] [blame] | 3 | * Copyright (c) 2008-2010, Jouni Malinen <j@w1.fi> |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 4 | * |
| 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. |
| 8 | * |
| 9 | * Alternatively, this software may be distributed under the terms of BSD |
| 10 | * license. |
| 11 | * |
| 12 | * See README and COPYING for more details. |
| 13 | */ |
| 14 | |
| 15 | #include "includes.h" |
| 16 | |
| 17 | #include "common.h" |
Jouni Malinen | 03da66b | 2009-11-29 23:04:43 +0200 | [diff] [blame] | 18 | #include "eloop.h" |
| 19 | #include "uuid.h" |
| 20 | #include "crypto/dh_group5.h" |
Jouni Malinen | 90973fb | 2009-11-29 17:51:55 +0200 | [diff] [blame] | 21 | #include "common/ieee802_11_defs.h" |
| 22 | #include "common/ieee802_11_common.h" |
| 23 | #include "common/wpa_common.h" |
Jouni Malinen | 03da66b | 2009-11-29 23:04:43 +0200 | [diff] [blame] | 24 | #include "common/wpa_ctrl.h" |
| 25 | #include "eap_common/eap_wsc_common.h" |
Jouni Malinen | b01c18a | 2008-11-29 13:38:03 +0200 | [diff] [blame] | 26 | #include "eap_peer/eap.h" |
Jouni Malinen | 03da66b | 2009-11-29 23:04:43 +0200 | [diff] [blame] | 27 | #include "rsn_supp/wpa.h" |
| 28 | #include "config.h" |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 29 | #include "wpa_supplicant_i.h" |
Jouni Malinen | 2d5b792 | 2009-03-26 20:37:05 +0200 | [diff] [blame] | 30 | #include "driver_i.h" |
Jouni Malinen | 8bac466 | 2009-09-13 20:53:32 +0300 | [diff] [blame] | 31 | #include "notify.h" |
Jouni Malinen | a609915 | 2009-01-23 13:10:58 +0200 | [diff] [blame] | 32 | #include "blacklist.h" |
Jouni Malinen | 59f2caa | 2010-01-02 13:36:12 +0200 | [diff] [blame] | 33 | #include "bss.h" |
Jouni Malinen | 9ba9fa0 | 2010-01-03 18:48:11 +0200 | [diff] [blame] | 34 | #include "scan.h" |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 35 | #include "wps_supplicant.h" |
| 36 | |
Jouni Malinen | f7e5436 | 2009-12-28 16:07:15 +0200 | [diff] [blame] | 37 | |
Jouni Malinen | 31fcea9 | 2009-12-12 16:40:10 +0200 | [diff] [blame] | 38 | #ifndef WPS_PIN_SCAN_IGNORE_SEL_REG |
Jouni Malinen | a609915 | 2009-01-23 13:10:58 +0200 | [diff] [blame] | 39 | #define WPS_PIN_SCAN_IGNORE_SEL_REG 3 |
Jouni Malinen | 31fcea9 | 2009-12-12 16:40:10 +0200 | [diff] [blame] | 40 | #endif /* WPS_PIN_SCAN_IGNORE_SEL_REG */ |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 41 | |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 42 | static void wpas_wps_timeout(void *eloop_ctx, void *timeout_ctx); |
Jouni Malinen | 469fc3a | 2008-12-19 22:19:41 +0200 | [diff] [blame] | 43 | static void wpas_clear_wps(struct wpa_supplicant *wpa_s); |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 44 | |
| 45 | |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 46 | int wpas_wps_eapol_cb(struct wpa_supplicant *wpa_s) |
| 47 | { |
Jouni Malinen | a609915 | 2009-01-23 13:10:58 +0200 | [diff] [blame] | 48 | if (!wpa_s->wps_success && |
| 49 | wpa_s->current_ssid && |
| 50 | eap_is_wps_pin_enrollee(&wpa_s->current_ssid->eap)) { |
| 51 | const u8 *bssid = wpa_s->bssid; |
| 52 | if (is_zero_ether_addr(bssid)) |
| 53 | bssid = wpa_s->pending_bssid; |
| 54 | |
| 55 | wpa_printf(MSG_DEBUG, "WPS: PIN registration with " MACSTR |
| 56 | " did not succeed - continue trying to find " |
| 57 | "suitable AP", MAC2STR(bssid)); |
| 58 | wpa_blacklist_add(wpa_s, bssid); |
| 59 | |
| 60 | wpa_supplicant_deauthenticate(wpa_s, |
| 61 | WLAN_REASON_DEAUTH_LEAVING); |
| 62 | wpa_s->reassociate = 1; |
| 63 | wpa_supplicant_req_scan(wpa_s, |
| 64 | wpa_s->blacklist_cleared ? 5 : 0, 0); |
| 65 | wpa_s->blacklist_cleared = 0; |
| 66 | return 1; |
| 67 | } |
| 68 | |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 69 | eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL); |
| 70 | |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 71 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && wpa_s->current_ssid && |
| 72 | !(wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS)) { |
| 73 | wpa_printf(MSG_DEBUG, "WPS: Network configuration replaced - " |
| 74 | "try to associate with the received credential"); |
| 75 | wpa_supplicant_deauthenticate(wpa_s, |
| 76 | WLAN_REASON_DEAUTH_LEAVING); |
Jouni Malinen | 17a4734 | 2010-04-11 19:06:42 +0300 | [diff] [blame] | 77 | wpa_s->after_wps = 5; |
| 78 | wpa_s->wps_freq = wpa_s->assoc_freq; |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 79 | wpa_s->reassociate = 1; |
| 80 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 81 | return 1; |
| 82 | } |
| 83 | |
Jouni Malinen | 4766216 | 2009-01-18 12:27:12 +0200 | [diff] [blame] | 84 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && wpa_s->current_ssid) { |
| 85 | wpa_printf(MSG_DEBUG, "WPS: Registration completed - waiting " |
| 86 | "for external credential processing"); |
| 87 | wpas_clear_wps(wpa_s); |
| 88 | wpa_supplicant_deauthenticate(wpa_s, |
| 89 | WLAN_REASON_DEAUTH_LEAVING); |
| 90 | return 1; |
| 91 | } |
| 92 | |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | |
Jouni Malinen | 7cc1b6c | 2009-03-05 21:39:39 +0200 | [diff] [blame] | 97 | static void wpas_wps_security_workaround(struct wpa_supplicant *wpa_s, |
| 98 | struct wpa_ssid *ssid, |
| 99 | const struct wps_credential *cred) |
| 100 | { |
| 101 | struct wpa_driver_capa capa; |
Jouni Malinen | 59f2caa | 2010-01-02 13:36:12 +0200 | [diff] [blame] | 102 | struct wpa_bss *bss; |
Jouni Malinen | 7cc1b6c | 2009-03-05 21:39:39 +0200 | [diff] [blame] | 103 | const u8 *ie; |
| 104 | struct wpa_ie_data adv; |
| 105 | int wpa2 = 0, ccmp = 0; |
| 106 | |
| 107 | /* |
| 108 | * Many existing WPS APs do not know how to negotiate WPA2 or CCMP in |
| 109 | * case they are configured for mixed mode operation (WPA+WPA2 and |
| 110 | * TKIP+CCMP). Try to use scan results to figure out whether the AP |
| 111 | * actually supports stronger security and select that if the client |
| 112 | * has support for it, too. |
| 113 | */ |
| 114 | |
| 115 | if (wpa_drv_get_capa(wpa_s, &capa)) |
| 116 | return; /* Unknown what driver supports */ |
| 117 | |
Jouni Malinen | 59f2caa | 2010-01-02 13:36:12 +0200 | [diff] [blame] | 118 | bss = wpa_bss_get(wpa_s, cred->mac_addr, ssid->ssid, ssid->ssid_len); |
| 119 | if (bss == NULL) { |
| 120 | wpa_printf(MSG_DEBUG, "WPS: The AP was not found from BSS " |
| 121 | "table - use credential as-is"); |
Jouni Malinen | 7cc1b6c | 2009-03-05 21:39:39 +0200 | [diff] [blame] | 122 | return; |
| 123 | } |
| 124 | |
Jouni Malinen | 59f2caa | 2010-01-02 13:36:12 +0200 | [diff] [blame] | 125 | wpa_printf(MSG_DEBUG, "WPS: AP found from BSS table"); |
| 126 | |
| 127 | ie = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
Jouni Malinen | 7cc1b6c | 2009-03-05 21:39:39 +0200 | [diff] [blame] | 128 | if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0) { |
| 129 | wpa2 = 1; |
| 130 | if (adv.pairwise_cipher & WPA_CIPHER_CCMP) |
| 131 | ccmp = 1; |
| 132 | } else { |
Jouni Malinen | 59f2caa | 2010-01-02 13:36:12 +0200 | [diff] [blame] | 133 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
Jouni Malinen | 7cc1b6c | 2009-03-05 21:39:39 +0200 | [diff] [blame] | 134 | if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0 && |
| 135 | adv.pairwise_cipher & WPA_CIPHER_CCMP) |
| 136 | ccmp = 1; |
| 137 | } |
| 138 | |
| 139 | if (ie == NULL && (ssid->proto & WPA_PROTO_WPA) && |
| 140 | (ssid->pairwise_cipher & WPA_CIPHER_TKIP)) { |
| 141 | /* |
| 142 | * TODO: This could be the initial AP configuration and the |
| 143 | * Beacon contents could change shortly. Should request a new |
| 144 | * scan and delay addition of the network until the updated |
| 145 | * scan results are available. |
| 146 | */ |
| 147 | wpa_printf(MSG_DEBUG, "WPS: The AP did not yet advertise WPA " |
| 148 | "support - use credential as-is"); |
| 149 | return; |
| 150 | } |
| 151 | |
| 152 | if (ccmp && !(ssid->pairwise_cipher & WPA_CIPHER_CCMP) && |
| 153 | (ssid->pairwise_cipher & WPA_CIPHER_TKIP) && |
| 154 | (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { |
| 155 | wpa_printf(MSG_DEBUG, "WPS: Add CCMP into the credential " |
| 156 | "based on scan results"); |
| 157 | if (wpa_s->conf->ap_scan == 1) |
| 158 | ssid->pairwise_cipher |= WPA_CIPHER_CCMP; |
| 159 | else |
| 160 | ssid->pairwise_cipher = WPA_CIPHER_CCMP; |
| 161 | } |
| 162 | |
| 163 | if (wpa2 && !(ssid->proto & WPA_PROTO_RSN) && |
| 164 | (ssid->proto & WPA_PROTO_WPA) && |
| 165 | (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP)) { |
| 166 | wpa_printf(MSG_DEBUG, "WPS: Add WPA2 into the credential " |
| 167 | "based on scan results"); |
| 168 | if (wpa_s->conf->ap_scan == 1) |
| 169 | ssid->proto |= WPA_PROTO_RSN; |
| 170 | else |
| 171 | ssid->proto = WPA_PROTO_RSN; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | |
Jouni Malinen | bcbbc7a | 2008-11-28 20:02:32 +0200 | [diff] [blame] | 176 | static int wpa_supplicant_wps_cred(void *ctx, |
| 177 | const struct wps_credential *cred) |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 178 | { |
| 179 | struct wpa_supplicant *wpa_s = ctx; |
| 180 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
Andriy Tkachuk | 522b5b6 | 2009-02-18 19:58:44 +0200 | [diff] [blame] | 181 | u8 key_idx = 0; |
Jouni Malinen | 49eba5f | 2009-08-15 20:40:45 +0300 | [diff] [blame] | 182 | u16 auth_type; |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 183 | |
Jouni Malinen | 4766216 | 2009-01-18 12:27:12 +0200 | [diff] [blame] | 184 | if ((wpa_s->conf->wps_cred_processing == 1 || |
| 185 | wpa_s->conf->wps_cred_processing == 2) && cred->cred_attr) { |
| 186 | size_t blen = cred->cred_attr_len * 2 + 1; |
| 187 | char *buf = os_malloc(blen); |
| 188 | if (buf) { |
| 189 | wpa_snprintf_hex(buf, blen, |
| 190 | cred->cred_attr, cred->cred_attr_len); |
| 191 | wpa_msg(wpa_s, MSG_INFO, "%s%s", |
| 192 | WPS_EVENT_CRED_RECEIVED, buf); |
| 193 | os_free(buf); |
| 194 | } |
Jouni Malinen | 8bac466 | 2009-09-13 20:53:32 +0300 | [diff] [blame] | 195 | |
| 196 | wpas_notify_wps_credential(wpa_s, cred); |
Jouni Malinen | 4766216 | 2009-01-18 12:27:12 +0200 | [diff] [blame] | 197 | } else |
| 198 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_CRED_RECEIVED); |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 199 | |
Jouni Malinen | eca6e0a | 2009-01-17 22:17:12 +0200 | [diff] [blame] | 200 | wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute", |
| 201 | cred->cred_attr, cred->cred_attr_len); |
| 202 | |
Jouni Malinen | 4766216 | 2009-01-18 12:27:12 +0200 | [diff] [blame] | 203 | if (wpa_s->conf->wps_cred_processing == 1) |
| 204 | return 0; |
| 205 | |
Jouni Malinen | 73267b9 | 2009-03-30 19:00:55 +0300 | [diff] [blame] | 206 | wpa_hexdump_ascii(MSG_DEBUG, "WPS: SSID", cred->ssid, cred->ssid_len); |
| 207 | wpa_printf(MSG_DEBUG, "WPS: Authentication Type 0x%x", |
| 208 | cred->auth_type); |
| 209 | wpa_printf(MSG_DEBUG, "WPS: Encryption Type 0x%x", cred->encr_type); |
| 210 | wpa_printf(MSG_DEBUG, "WPS: Network Key Index %d", cred->key_idx); |
| 211 | wpa_hexdump_key(MSG_DEBUG, "WPS: Network Key", |
| 212 | cred->key, cred->key_len); |
| 213 | wpa_printf(MSG_DEBUG, "WPS: MAC Address " MACSTR, |
| 214 | MAC2STR(cred->mac_addr)); |
| 215 | |
Jouni Malinen | 49eba5f | 2009-08-15 20:40:45 +0300 | [diff] [blame] | 216 | auth_type = cred->auth_type; |
| 217 | if (auth_type == (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) { |
| 218 | wpa_printf(MSG_DEBUG, "WPS: Workaround - convert mixed-mode " |
| 219 | "auth_type into WPA2PSK"); |
| 220 | auth_type = WPS_AUTH_WPA2PSK; |
| 221 | } |
| 222 | |
| 223 | if (auth_type != WPS_AUTH_OPEN && |
| 224 | auth_type != WPS_AUTH_SHARED && |
| 225 | auth_type != WPS_AUTH_WPAPSK && |
| 226 | auth_type != WPS_AUTH_WPA2PSK) { |
Jouni Malinen | f286077 | 2009-01-17 21:45:51 +0200 | [diff] [blame] | 227 | wpa_printf(MSG_DEBUG, "WPS: Ignored credentials for " |
Jouni Malinen | 49eba5f | 2009-08-15 20:40:45 +0300 | [diff] [blame] | 228 | "unsupported authentication type 0x%x", |
| 229 | auth_type); |
Jouni Malinen | f286077 | 2009-01-17 21:45:51 +0200 | [diff] [blame] | 230 | return 0; |
| 231 | } |
| 232 | |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 233 | if (ssid && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) { |
| 234 | wpa_printf(MSG_DEBUG, "WPS: Replace WPS network block based " |
| 235 | "on the received credential"); |
| 236 | os_free(ssid->eap.identity); |
| 237 | ssid->eap.identity = NULL; |
| 238 | ssid->eap.identity_len = 0; |
| 239 | os_free(ssid->eap.phase1); |
| 240 | ssid->eap.phase1 = NULL; |
| 241 | os_free(ssid->eap.eap_methods); |
| 242 | ssid->eap.eap_methods = NULL; |
| 243 | } else { |
| 244 | wpa_printf(MSG_DEBUG, "WPS: Create a new network based on the " |
| 245 | "received credential"); |
| 246 | ssid = wpa_config_add_network(wpa_s->conf); |
| 247 | if (ssid == NULL) |
| 248 | return -1; |
Jouni Malinen | 8bac466 | 2009-09-13 20:53:32 +0300 | [diff] [blame] | 249 | wpas_notify_network_added(wpa_s, ssid); |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | wpa_config_set_network_defaults(ssid); |
| 253 | |
| 254 | os_free(ssid->ssid); |
| 255 | ssid->ssid = os_malloc(cred->ssid_len); |
| 256 | if (ssid->ssid) { |
| 257 | os_memcpy(ssid->ssid, cred->ssid, cred->ssid_len); |
| 258 | ssid->ssid_len = cred->ssid_len; |
| 259 | } |
| 260 | |
| 261 | switch (cred->encr_type) { |
| 262 | case WPS_ENCR_NONE: |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 263 | break; |
| 264 | case WPS_ENCR_WEP: |
Andriy Tkachuk | 4b195a1 | 2009-02-17 10:30:43 +0200 | [diff] [blame] | 265 | if (cred->key_len <= 0) |
| 266 | break; |
| 267 | if (cred->key_len != 5 && cred->key_len != 13 && |
| 268 | cred->key_len != 10 && cred->key_len != 26) { |
| 269 | wpa_printf(MSG_ERROR, "WPS: Invalid WEP Key length " |
| 270 | "%lu", (unsigned long) cred->key_len); |
| 271 | return -1; |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 272 | } |
Andriy Tkachuk | 522b5b6 | 2009-02-18 19:58:44 +0200 | [diff] [blame] | 273 | if (cred->key_idx > NUM_WEP_KEYS) { |
Andriy Tkachuk | 4b195a1 | 2009-02-17 10:30:43 +0200 | [diff] [blame] | 274 | wpa_printf(MSG_ERROR, "WPS: Invalid WEP Key index %d", |
| 275 | cred->key_idx); |
| 276 | return -1; |
| 277 | } |
Andriy Tkachuk | 522b5b6 | 2009-02-18 19:58:44 +0200 | [diff] [blame] | 278 | if (cred->key_idx) |
| 279 | key_idx = cred->key_idx - 1; |
Andriy Tkachuk | 4b195a1 | 2009-02-17 10:30:43 +0200 | [diff] [blame] | 280 | if (cred->key_len == 10 || cred->key_len == 26) { |
| 281 | if (hexstr2bin((char *) cred->key, |
| 282 | ssid->wep_key[key_idx], |
| 283 | cred->key_len / 2) < 0) { |
| 284 | wpa_printf(MSG_ERROR, "WPS: Invalid WEP Key " |
| 285 | "%d", key_idx); |
| 286 | return -1; |
| 287 | } |
| 288 | ssid->wep_key_len[key_idx] = cred->key_len / 2; |
| 289 | } else { |
| 290 | os_memcpy(ssid->wep_key[key_idx], cred->key, |
| 291 | cred->key_len); |
| 292 | ssid->wep_key_len[key_idx] = cred->key_len; |
| 293 | } |
| 294 | ssid->wep_tx_keyidx = key_idx; |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 295 | break; |
| 296 | case WPS_ENCR_TKIP: |
| 297 | ssid->pairwise_cipher = WPA_CIPHER_TKIP; |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 298 | break; |
| 299 | case WPS_ENCR_AES: |
| 300 | ssid->pairwise_cipher = WPA_CIPHER_CCMP; |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 301 | break; |
| 302 | } |
| 303 | |
Jouni Malinen | 49eba5f | 2009-08-15 20:40:45 +0300 | [diff] [blame] | 304 | switch (auth_type) { |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 305 | case WPS_AUTH_OPEN: |
| 306 | ssid->auth_alg = WPA_AUTH_ALG_OPEN; |
| 307 | ssid->key_mgmt = WPA_KEY_MGMT_NONE; |
| 308 | ssid->proto = 0; |
| 309 | break; |
| 310 | case WPS_AUTH_SHARED: |
| 311 | ssid->auth_alg = WPA_AUTH_ALG_SHARED; |
| 312 | ssid->key_mgmt = WPA_KEY_MGMT_NONE; |
| 313 | ssid->proto = 0; |
| 314 | break; |
| 315 | case WPS_AUTH_WPAPSK: |
| 316 | ssid->auth_alg = WPA_AUTH_ALG_OPEN; |
| 317 | ssid->key_mgmt = WPA_KEY_MGMT_PSK; |
| 318 | ssid->proto = WPA_PROTO_WPA; |
| 319 | break; |
| 320 | case WPS_AUTH_WPA: |
| 321 | ssid->auth_alg = WPA_AUTH_ALG_OPEN; |
| 322 | ssid->key_mgmt = WPA_KEY_MGMT_IEEE8021X; |
| 323 | ssid->proto = WPA_PROTO_WPA; |
| 324 | break; |
| 325 | case WPS_AUTH_WPA2: |
| 326 | ssid->auth_alg = WPA_AUTH_ALG_OPEN; |
| 327 | ssid->key_mgmt = WPA_KEY_MGMT_IEEE8021X; |
| 328 | ssid->proto = WPA_PROTO_RSN; |
| 329 | break; |
| 330 | case WPS_AUTH_WPA2PSK: |
| 331 | ssid->auth_alg = WPA_AUTH_ALG_OPEN; |
| 332 | ssid->key_mgmt = WPA_KEY_MGMT_PSK; |
| 333 | ssid->proto = WPA_PROTO_RSN; |
| 334 | break; |
| 335 | } |
| 336 | |
| 337 | if (ssid->key_mgmt == WPA_KEY_MGMT_PSK) { |
| 338 | if (cred->key_len == 2 * PMK_LEN) { |
| 339 | if (hexstr2bin((const char *) cred->key, ssid->psk, |
| 340 | PMK_LEN)) { |
| 341 | wpa_printf(MSG_ERROR, "WPS: Invalid Network " |
| 342 | "Key"); |
| 343 | return -1; |
| 344 | } |
| 345 | ssid->psk_set = 1; |
| 346 | } else if (cred->key_len >= 8 && cred->key_len < 2 * PMK_LEN) { |
| 347 | os_free(ssid->passphrase); |
| 348 | ssid->passphrase = os_malloc(cred->key_len + 1); |
| 349 | if (ssid->passphrase == NULL) |
| 350 | return -1; |
| 351 | os_memcpy(ssid->passphrase, cred->key, cred->key_len); |
| 352 | ssid->passphrase[cred->key_len] = '\0'; |
| 353 | wpa_config_update_psk(ssid); |
| 354 | } else { |
| 355 | wpa_printf(MSG_ERROR, "WPS: Invalid Network Key " |
| 356 | "length %lu", |
| 357 | (unsigned long) cred->key_len); |
| 358 | return -1; |
| 359 | } |
| 360 | } |
| 361 | |
Jouni Malinen | 7cc1b6c | 2009-03-05 21:39:39 +0200 | [diff] [blame] | 362 | wpas_wps_security_workaround(wpa_s, ssid, cred); |
| 363 | |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 364 | #ifndef CONFIG_NO_CONFIG_WRITE |
| 365 | if (wpa_s->conf->update_config && |
| 366 | wpa_config_write(wpa_s->confname, wpa_s->conf)) { |
| 367 | wpa_printf(MSG_DEBUG, "WPS: Failed to update configuration"); |
| 368 | return -1; |
| 369 | } |
| 370 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 371 | |
| 372 | return 0; |
| 373 | } |
| 374 | |
| 375 | |
Jouni Malinen | 4b68290 | 2008-12-18 21:58:42 +0200 | [diff] [blame] | 376 | static void wpa_supplicant_wps_event_m2d(struct wpa_supplicant *wpa_s, |
| 377 | struct wps_event_m2d *m2d) |
| 378 | { |
| 379 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_M2D |
| 380 | "dev_password_id=%d config_error=%d", |
| 381 | m2d->dev_password_id, m2d->config_error); |
Jouni Malinen | 8bac466 | 2009-09-13 20:53:32 +0300 | [diff] [blame] | 382 | wpas_notify_wps_event_m2d(wpa_s, m2d); |
Jouni Malinen | 4b68290 | 2008-12-18 21:58:42 +0200 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | |
Jouni Malinen | 469fc3a | 2008-12-19 22:19:41 +0200 | [diff] [blame] | 386 | static void wpa_supplicant_wps_event_fail(struct wpa_supplicant *wpa_s, |
| 387 | struct wps_event_fail *fail) |
| 388 | { |
| 389 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_FAIL "msg=%d", fail->msg); |
| 390 | wpas_clear_wps(wpa_s); |
Jouni Malinen | 8bac466 | 2009-09-13 20:53:32 +0300 | [diff] [blame] | 391 | wpas_notify_wps_event_fail(wpa_s, fail); |
Jouni Malinen | 469fc3a | 2008-12-19 22:19:41 +0200 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | |
Jouni Malinen | ad5302a | 2008-12-19 22:34:18 +0200 | [diff] [blame] | 395 | static void wpa_supplicant_wps_event_success(struct wpa_supplicant *wpa_s) |
| 396 | { |
| 397 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_SUCCESS); |
Jouni Malinen | a609915 | 2009-01-23 13:10:58 +0200 | [diff] [blame] | 398 | wpa_s->wps_success = 1; |
Jouni Malinen | 8bac466 | 2009-09-13 20:53:32 +0300 | [diff] [blame] | 399 | wpas_notify_wps_event_success(wpa_s); |
Jouni Malinen | ad5302a | 2008-12-19 22:34:18 +0200 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | |
Jouni Malinen | b78bc3a | 2009-11-15 12:07:27 +0200 | [diff] [blame] | 403 | static void wpa_supplicant_wps_event_er_ap_add(struct wpa_supplicant *wpa_s, |
| 404 | struct wps_event_er_ap *ap) |
| 405 | { |
| 406 | char uuid_str[100]; |
Jouni Malinen | ed45947 | 2009-11-26 11:54:37 +0200 | [diff] [blame] | 407 | char dev_type[WPS_DEV_TYPE_BUFSIZE]; |
Jouni Malinen | e694b34 | 2009-11-21 13:34:23 +0200 | [diff] [blame] | 408 | |
Jouni Malinen | b78bc3a | 2009-11-15 12:07:27 +0200 | [diff] [blame] | 409 | uuid_bin2str(ap->uuid, uuid_str, sizeof(uuid_str)); |
Jouni Malinen | e694b34 | 2009-11-21 13:34:23 +0200 | [diff] [blame] | 410 | if (ap->pri_dev_type) |
Jouni Malinen | ed45947 | 2009-11-26 11:54:37 +0200 | [diff] [blame] | 411 | wps_dev_type_bin2str(ap->pri_dev_type, dev_type, |
| 412 | sizeof(dev_type)); |
Jouni Malinen | e694b34 | 2009-11-21 13:34:23 +0200 | [diff] [blame] | 413 | else |
| 414 | dev_type[0] = '\0'; |
| 415 | |
| 416 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_ADD "%s " MACSTR |
| 417 | " pri_dev_type=%s wps_state=%d |%s|%s|%s|%s|%s|%s|", |
| 418 | uuid_str, MAC2STR(ap->mac_addr), dev_type, ap->wps_state, |
Jouni Malinen | b78bc3a | 2009-11-15 12:07:27 +0200 | [diff] [blame] | 419 | ap->friendly_name ? ap->friendly_name : "", |
| 420 | ap->manufacturer ? ap->manufacturer : "", |
| 421 | ap->model_description ? ap->model_description : "", |
| 422 | ap->model_name ? ap->model_name : "", |
| 423 | ap->manufacturer_url ? ap->manufacturer_url : "", |
| 424 | ap->model_url ? ap->model_url : ""); |
| 425 | } |
| 426 | |
| 427 | |
| 428 | static void wpa_supplicant_wps_event_er_ap_remove(struct wpa_supplicant *wpa_s, |
| 429 | struct wps_event_er_ap *ap) |
| 430 | { |
| 431 | char uuid_str[100]; |
| 432 | uuid_bin2str(ap->uuid, uuid_str, sizeof(uuid_str)); |
| 433 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_REMOVE "%s", uuid_str); |
| 434 | } |
| 435 | |
| 436 | |
| 437 | static void wpa_supplicant_wps_event_er_enrollee_add( |
| 438 | struct wpa_supplicant *wpa_s, struct wps_event_er_enrollee *enrollee) |
| 439 | { |
| 440 | char uuid_str[100]; |
Jouni Malinen | ed45947 | 2009-11-26 11:54:37 +0200 | [diff] [blame] | 441 | char dev_type[WPS_DEV_TYPE_BUFSIZE]; |
Jouni Malinen | b78bc3a | 2009-11-15 12:07:27 +0200 | [diff] [blame] | 442 | |
| 443 | uuid_bin2str(enrollee->uuid, uuid_str, sizeof(uuid_str)); |
| 444 | if (enrollee->pri_dev_type) |
Jouni Malinen | ed45947 | 2009-11-26 11:54:37 +0200 | [diff] [blame] | 445 | wps_dev_type_bin2str(enrollee->pri_dev_type, dev_type, |
| 446 | sizeof(dev_type)); |
Jouni Malinen | b78bc3a | 2009-11-15 12:07:27 +0200 | [diff] [blame] | 447 | else |
| 448 | dev_type[0] = '\0'; |
| 449 | |
| 450 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_ENROLLEE_ADD "%s " MACSTR |
| 451 | " M1=%d config_methods=0x%x dev_passwd_id=%d pri_dev_type=%s " |
| 452 | "|%s|%s|%s|%s|%s|", |
| 453 | uuid_str, MAC2STR(enrollee->mac_addr), enrollee->m1_received, |
| 454 | enrollee->config_methods, enrollee->dev_passwd_id, dev_type, |
| 455 | enrollee->dev_name ? enrollee->dev_name : "", |
| 456 | enrollee->manufacturer ? enrollee->manufacturer : "", |
| 457 | enrollee->model_name ? enrollee->model_name : "", |
| 458 | enrollee->model_number ? enrollee->model_number : "", |
| 459 | enrollee->serial_number ? enrollee->serial_number : ""); |
| 460 | } |
| 461 | |
| 462 | |
| 463 | static void wpa_supplicant_wps_event_er_enrollee_remove( |
| 464 | struct wpa_supplicant *wpa_s, struct wps_event_er_enrollee *enrollee) |
| 465 | { |
| 466 | char uuid_str[100]; |
| 467 | uuid_bin2str(enrollee->uuid, uuid_str, sizeof(uuid_str)); |
| 468 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_ENROLLEE_REMOVE "%s " MACSTR, |
| 469 | uuid_str, MAC2STR(enrollee->mac_addr)); |
| 470 | } |
| 471 | |
| 472 | |
Jouni Malinen | 15dbf12 | 2010-05-27 15:24:45 +0300 | [diff] [blame] | 473 | static void wpa_supplicant_wps_event_er_ap_settings( |
| 474 | struct wpa_supplicant *wpa_s, |
| 475 | struct wps_event_er_ap_settings *ap_settings) |
| 476 | { |
| 477 | char uuid_str[100]; |
| 478 | char key_str[65]; |
| 479 | const struct wps_credential *cred = ap_settings->cred; |
| 480 | |
| 481 | key_str[0] = '\0'; |
| 482 | if (cred->auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) { |
| 483 | if (cred->key_len >= 8 && cred->key_len <= 64) { |
| 484 | os_memcpy(key_str, cred->key, cred->key_len); |
| 485 | key_str[cred->key_len] = '\0'; |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | uuid_bin2str(ap_settings->uuid, uuid_str, sizeof(uuid_str)); |
| 490 | /* Use wpa_msg_ctrl to avoid showing the key in debug log */ |
| 491 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_SETTINGS |
| 492 | "uuid=%s ssid=%s auth_type=0x%04x encr_type=0x%04x " |
| 493 | "key=%s", |
| 494 | uuid_str, wpa_ssid_txt(cred->ssid, cred->ssid_len), |
| 495 | cred->auth_type, cred->encr_type, key_str); |
| 496 | } |
| 497 | |
| 498 | |
Jouni Malinen | 4b68290 | 2008-12-18 21:58:42 +0200 | [diff] [blame] | 499 | static void wpa_supplicant_wps_event(void *ctx, enum wps_event event, |
| 500 | union wps_event_data *data) |
| 501 | { |
| 502 | struct wpa_supplicant *wpa_s = ctx; |
| 503 | switch (event) { |
| 504 | case WPS_EV_M2D: |
| 505 | wpa_supplicant_wps_event_m2d(wpa_s, &data->m2d); |
| 506 | break; |
Jouni Malinen | 469fc3a | 2008-12-19 22:19:41 +0200 | [diff] [blame] | 507 | case WPS_EV_FAIL: |
| 508 | wpa_supplicant_wps_event_fail(wpa_s, &data->fail); |
| 509 | break; |
Jouni Malinen | ad5302a | 2008-12-19 22:34:18 +0200 | [diff] [blame] | 510 | case WPS_EV_SUCCESS: |
| 511 | wpa_supplicant_wps_event_success(wpa_s); |
| 512 | break; |
Jouni Malinen | 3b2cf80 | 2009-01-23 21:57:43 +0200 | [diff] [blame] | 513 | case WPS_EV_PWD_AUTH_FAIL: |
| 514 | break; |
Oleg Kravtsov | 63330c6 | 2009-11-01 21:26:13 +0200 | [diff] [blame] | 515 | case WPS_EV_PBC_OVERLAP: |
| 516 | break; |
| 517 | case WPS_EV_PBC_TIMEOUT: |
| 518 | break; |
Jouni Malinen | b78bc3a | 2009-11-15 12:07:27 +0200 | [diff] [blame] | 519 | case WPS_EV_ER_AP_ADD: |
| 520 | wpa_supplicant_wps_event_er_ap_add(wpa_s, &data->ap); |
| 521 | break; |
| 522 | case WPS_EV_ER_AP_REMOVE: |
| 523 | wpa_supplicant_wps_event_er_ap_remove(wpa_s, &data->ap); |
| 524 | break; |
| 525 | case WPS_EV_ER_ENROLLEE_ADD: |
| 526 | wpa_supplicant_wps_event_er_enrollee_add(wpa_s, |
| 527 | &data->enrollee); |
| 528 | break; |
| 529 | case WPS_EV_ER_ENROLLEE_REMOVE: |
| 530 | wpa_supplicant_wps_event_er_enrollee_remove(wpa_s, |
| 531 | &data->enrollee); |
| 532 | break; |
Jouni Malinen | 15dbf12 | 2010-05-27 15:24:45 +0300 | [diff] [blame] | 533 | case WPS_EV_ER_AP_SETTINGS: |
| 534 | wpa_supplicant_wps_event_er_ap_settings(wpa_s, |
| 535 | &data->ap_settings); |
| 536 | break; |
Jouni Malinen | 4b68290 | 2008-12-18 21:58:42 +0200 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | |
| 540 | |
Jouni Malinen | f90c86d | 2009-01-03 19:50:49 +0200 | [diff] [blame] | 541 | enum wps_request_type wpas_wps_get_req_type(struct wpa_ssid *ssid) |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 542 | { |
Jouni Malinen | b01c18a | 2008-11-29 13:38:03 +0200 | [diff] [blame] | 543 | if (eap_is_wps_pbc_enrollee(&ssid->eap) || |
| 544 | eap_is_wps_pin_enrollee(&ssid->eap)) |
| 545 | return WPS_REQ_ENROLLEE; |
| 546 | else |
| 547 | return WPS_REQ_REGISTRAR; |
Jouni Malinen | fa201b6 | 2008-11-28 19:46:22 +0200 | [diff] [blame] | 548 | } |
Jouni Malinen | 116654c | 2008-11-28 20:32:13 +0200 | [diff] [blame] | 549 | |
| 550 | |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 551 | static void wpas_clear_wps(struct wpa_supplicant *wpa_s) |
| 552 | { |
| 553 | int id; |
Jouni Malinen | 8bac466 | 2009-09-13 20:53:32 +0300 | [diff] [blame] | 554 | struct wpa_ssid *ssid, *remove_ssid = NULL; |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 555 | |
| 556 | eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL); |
| 557 | |
| 558 | /* Remove any existing WPS network from configuration */ |
| 559 | ssid = wpa_s->conf->ssid; |
| 560 | while (ssid) { |
Jouni Malinen | f047720 | 2008-12-18 01:06:06 +0200 | [diff] [blame] | 561 | if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) { |
Jouni Malinen | 8bac466 | 2009-09-13 20:53:32 +0300 | [diff] [blame] | 562 | if (ssid == wpa_s->current_ssid) { |
Jouni Malinen | f047720 | 2008-12-18 01:06:06 +0200 | [diff] [blame] | 563 | wpa_s->current_ssid = NULL; |
Jouni Malinen | 8bac466 | 2009-09-13 20:53:32 +0300 | [diff] [blame] | 564 | if (ssid != NULL) |
| 565 | wpas_notify_network_changed(wpa_s); |
| 566 | } |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 567 | id = ssid->id; |
Jouni Malinen | 8bac466 | 2009-09-13 20:53:32 +0300 | [diff] [blame] | 568 | remove_ssid = ssid; |
Jouni Malinen | f047720 | 2008-12-18 01:06:06 +0200 | [diff] [blame] | 569 | } else |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 570 | id = -1; |
| 571 | ssid = ssid->next; |
Jouni Malinen | 8bac466 | 2009-09-13 20:53:32 +0300 | [diff] [blame] | 572 | if (id >= 0) { |
| 573 | wpas_notify_network_removed(wpa_s, remove_ssid); |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 574 | wpa_config_remove_network(wpa_s->conf, id); |
Jouni Malinen | 8bac466 | 2009-09-13 20:53:32 +0300 | [diff] [blame] | 575 | } |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 576 | } |
| 577 | } |
| 578 | |
| 579 | |
| 580 | static void wpas_wps_timeout(void *eloop_ctx, void *timeout_ctx) |
| 581 | { |
| 582 | struct wpa_supplicant *wpa_s = eloop_ctx; |
Jouni Malinen | a609915 | 2009-01-23 13:10:58 +0200 | [diff] [blame] | 583 | wpa_printf(MSG_INFO, WPS_EVENT_TIMEOUT "Requested operation timed " |
| 584 | "out"); |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 585 | wpas_clear_wps(wpa_s); |
| 586 | } |
| 587 | |
| 588 | |
| 589 | static struct wpa_ssid * wpas_wps_add_network(struct wpa_supplicant *wpa_s, |
| 590 | int registrar, const u8 *bssid) |
| 591 | { |
| 592 | struct wpa_ssid *ssid; |
| 593 | |
| 594 | ssid = wpa_config_add_network(wpa_s->conf); |
| 595 | if (ssid == NULL) |
| 596 | return NULL; |
Jouni Malinen | 8bac466 | 2009-09-13 20:53:32 +0300 | [diff] [blame] | 597 | wpas_notify_network_added(wpa_s, ssid); |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 598 | wpa_config_set_network_defaults(ssid); |
| 599 | if (wpa_config_set(ssid, "key_mgmt", "WPS", 0) < 0 || |
| 600 | wpa_config_set(ssid, "eap", "WSC", 0) < 0 || |
| 601 | wpa_config_set(ssid, "identity", registrar ? |
| 602 | "\"" WSC_ID_REGISTRAR "\"" : |
| 603 | "\"" WSC_ID_ENROLLEE "\"", 0) < 0) { |
Jouni Malinen | 8bac466 | 2009-09-13 20:53:32 +0300 | [diff] [blame] | 604 | wpas_notify_network_removed(wpa_s, ssid); |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 605 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 606 | return NULL; |
| 607 | } |
| 608 | |
| 609 | if (bssid) { |
Jouni Malinen | 59f2caa | 2010-01-02 13:36:12 +0200 | [diff] [blame] | 610 | struct wpa_bss *bss; |
Jouni Malinen | f7e5436 | 2009-12-28 16:07:15 +0200 | [diff] [blame] | 611 | int count = 0; |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 612 | |
| 613 | os_memcpy(ssid->bssid, bssid, ETH_ALEN); |
Jouni Malinen | 24c23d1 | 2008-12-20 22:55:02 +0200 | [diff] [blame] | 614 | ssid->bssid_set = 1; |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 615 | |
Jouni Malinen | 59f2caa | 2010-01-02 13:36:12 +0200 | [diff] [blame] | 616 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
| 617 | if (os_memcmp(bssid, bss->bssid, ETH_ALEN) != 0) |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 618 | continue; |
| 619 | |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 620 | os_free(ssid->ssid); |
Jouni Malinen | 59f2caa | 2010-01-02 13:36:12 +0200 | [diff] [blame] | 621 | ssid->ssid = os_malloc(bss->ssid_len); |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 622 | if (ssid->ssid == NULL) |
| 623 | break; |
Jouni Malinen | 59f2caa | 2010-01-02 13:36:12 +0200 | [diff] [blame] | 624 | os_memcpy(ssid->ssid, bss->ssid, bss->ssid_len); |
| 625 | ssid->ssid_len = bss->ssid_len; |
Jouni Malinen | f7e5436 | 2009-12-28 16:07:15 +0200 | [diff] [blame] | 626 | wpa_hexdump_ascii(MSG_DEBUG, "WPS: Picked SSID from " |
| 627 | "scan results", |
| 628 | ssid->ssid, ssid->ssid_len); |
| 629 | count++; |
| 630 | } |
| 631 | |
| 632 | if (count > 1) { |
| 633 | wpa_printf(MSG_DEBUG, "WPS: More than one SSID found " |
| 634 | "for the AP; use wildcard"); |
| 635 | os_free(ssid->ssid); |
| 636 | ssid->ssid = NULL; |
| 637 | ssid->ssid_len = 0; |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 638 | } |
| 639 | } |
| 640 | |
| 641 | return ssid; |
| 642 | } |
| 643 | |
| 644 | |
| 645 | static void wpas_wps_reassoc(struct wpa_supplicant *wpa_s, |
| 646 | struct wpa_ssid *selected) |
| 647 | { |
| 648 | struct wpa_ssid *ssid; |
| 649 | |
| 650 | /* Mark all other networks disabled and trigger reassociation */ |
| 651 | ssid = wpa_s->conf->ssid; |
| 652 | while (ssid) { |
Jouni Malinen | 8bac466 | 2009-09-13 20:53:32 +0300 | [diff] [blame] | 653 | int was_disabled = ssid->disabled; |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 654 | ssid->disabled = ssid != selected; |
Jouni Malinen | 8bac466 | 2009-09-13 20:53:32 +0300 | [diff] [blame] | 655 | if (was_disabled != ssid->disabled) |
| 656 | wpas_notify_network_enabled_changed(wpa_s, ssid); |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 657 | ssid = ssid->next; |
| 658 | } |
| 659 | wpa_s->disconnected = 0; |
| 660 | wpa_s->reassociate = 1; |
Jouni Malinen | a609915 | 2009-01-23 13:10:58 +0200 | [diff] [blame] | 661 | wpa_s->scan_runs = 0; |
| 662 | wpa_s->wps_success = 0; |
| 663 | wpa_s->blacklist_cleared = 0; |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 664 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 665 | } |
| 666 | |
| 667 | |
| 668 | int wpas_wps_start_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid) |
| 669 | { |
| 670 | struct wpa_ssid *ssid; |
| 671 | wpas_clear_wps(wpa_s); |
| 672 | ssid = wpas_wps_add_network(wpa_s, 0, bssid); |
| 673 | if (ssid == NULL) |
| 674 | return -1; |
| 675 | wpa_config_set(ssid, "phase1", "\"pbc=1\"", 0); |
Jouni Malinen | 42f5026 | 2010-07-22 10:24:23 -0700 | [diff] [blame^] | 676 | if (wpa_s->wps_fragment_size) |
| 677 | ssid->eap.fragment_size = wpa_s->wps_fragment_size; |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 678 | eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout, |
| 679 | wpa_s, NULL); |
| 680 | wpas_wps_reassoc(wpa_s, ssid); |
| 681 | return 0; |
| 682 | } |
| 683 | |
| 684 | |
| 685 | int wpas_wps_start_pin(struct wpa_supplicant *wpa_s, const u8 *bssid, |
| 686 | const char *pin) |
| 687 | { |
| 688 | struct wpa_ssid *ssid; |
Masashi Honma | 46bdb83 | 2009-02-26 21:57:38 +0200 | [diff] [blame] | 689 | char val[128]; |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 690 | unsigned int rpin = 0; |
| 691 | |
| 692 | wpas_clear_wps(wpa_s); |
| 693 | ssid = wpas_wps_add_network(wpa_s, 0, bssid); |
| 694 | if (ssid == NULL) |
| 695 | return -1; |
| 696 | if (pin) |
| 697 | os_snprintf(val, sizeof(val), "\"pin=%s\"", pin); |
| 698 | else { |
| 699 | rpin = wps_generate_pin(); |
| 700 | os_snprintf(val, sizeof(val), "\"pin=%08d\"", rpin); |
| 701 | } |
| 702 | wpa_config_set(ssid, "phase1", val, 0); |
Jouni Malinen | 42f5026 | 2010-07-22 10:24:23 -0700 | [diff] [blame^] | 703 | if (wpa_s->wps_fragment_size) |
| 704 | ssid->eap.fragment_size = wpa_s->wps_fragment_size; |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 705 | eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout, |
| 706 | wpa_s, NULL); |
| 707 | wpas_wps_reassoc(wpa_s, ssid); |
| 708 | return rpin; |
| 709 | } |
| 710 | |
| 711 | |
Jouni Malinen | 116f7bb | 2009-02-26 22:10:21 +0200 | [diff] [blame] | 712 | #ifdef CONFIG_WPS_OOB |
Masashi Honma | 46bdb83 | 2009-02-26 21:57:38 +0200 | [diff] [blame] | 713 | int wpas_wps_start_oob(struct wpa_supplicant *wpa_s, char *device_type, |
Masashi Honma | e1ee6b6 | 2009-03-06 16:16:22 +0200 | [diff] [blame] | 714 | char *path, char *method, char *name) |
Masashi Honma | 46bdb83 | 2009-02-26 21:57:38 +0200 | [diff] [blame] | 715 | { |
| 716 | struct wps_context *wps = wpa_s->wps; |
Jouni Malinen | 7cbf51b | 2009-02-26 22:07:55 +0200 | [diff] [blame] | 717 | struct oob_device_data *oob_dev; |
Masashi Honma | 46bdb83 | 2009-02-26 21:57:38 +0200 | [diff] [blame] | 718 | |
Jouni Malinen | 7cbf51b | 2009-02-26 22:07:55 +0200 | [diff] [blame] | 719 | oob_dev = wps_get_oob_device(device_type); |
| 720 | if (oob_dev == NULL) |
Masashi Honma | 46bdb83 | 2009-02-26 21:57:38 +0200 | [diff] [blame] | 721 | return -1; |
Jouni Malinen | 7cbf51b | 2009-02-26 22:07:55 +0200 | [diff] [blame] | 722 | oob_dev->device_path = path; |
Masashi Honma | e1ee6b6 | 2009-03-06 16:16:22 +0200 | [diff] [blame] | 723 | oob_dev->device_name = name; |
Masashi Honma | 46bdb83 | 2009-02-26 21:57:38 +0200 | [diff] [blame] | 724 | wps->oob_conf.oob_method = wps_get_oob_method(method); |
| 725 | |
Jouni Malinen | d5e2b2d | 2009-02-26 22:09:35 +0200 | [diff] [blame] | 726 | if (wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E) { |
| 727 | /* |
| 728 | * Use pre-configured DH keys in order to be able to write the |
| 729 | * key hash into the OOB file. |
| 730 | */ |
| 731 | wpabuf_free(wps->dh_pubkey); |
| 732 | wpabuf_free(wps->dh_privkey); |
| 733 | wps->dh_privkey = NULL; |
Jouni Malinen | f042122 | 2009-10-11 19:17:22 +0300 | [diff] [blame] | 734 | wps->dh_pubkey = NULL; |
| 735 | dh5_free(wps->dh_ctx); |
| 736 | wps->dh_ctx = dh5_init(&wps->dh_privkey, &wps->dh_pubkey); |
Jouni Malinen | d5e2b2d | 2009-02-26 22:09:35 +0200 | [diff] [blame] | 737 | wps->dh_pubkey = wpabuf_zeropad(wps->dh_pubkey, 192); |
Jouni Malinen | f042122 | 2009-10-11 19:17:22 +0300 | [diff] [blame] | 738 | if (wps->dh_ctx == NULL || wps->dh_pubkey == NULL) { |
Jouni Malinen | d5e2b2d | 2009-02-26 22:09:35 +0200 | [diff] [blame] | 739 | wpa_printf(MSG_ERROR, "WPS: Failed to initialize " |
| 740 | "Diffie-Hellman handshake"); |
| 741 | return -1; |
| 742 | } |
| 743 | } |
| 744 | |
Masashi Honma | 46bdb83 | 2009-02-26 21:57:38 +0200 | [diff] [blame] | 745 | if (wps->oob_conf.oob_method == OOB_METHOD_CRED) |
| 746 | wpas_clear_wps(wpa_s); |
| 747 | |
Jouni Malinen | 7cbf51b | 2009-02-26 22:07:55 +0200 | [diff] [blame] | 748 | if (wps_process_oob(wps, oob_dev, 0) < 0) |
Masashi Honma | 46bdb83 | 2009-02-26 21:57:38 +0200 | [diff] [blame] | 749 | return -1; |
| 750 | |
| 751 | if ((wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_E || |
| 752 | wps->oob_conf.oob_method == OOB_METHOD_DEV_PWD_R) && |
| 753 | wpas_wps_start_pin(wpa_s, NULL, |
| 754 | wpabuf_head(wps->oob_conf.dev_password)) < 0) |
| 755 | return -1; |
| 756 | |
| 757 | return 0; |
| 758 | } |
Jouni Malinen | 116f7bb | 2009-02-26 22:10:21 +0200 | [diff] [blame] | 759 | #endif /* CONFIG_WPS_OOB */ |
Masashi Honma | 46bdb83 | 2009-02-26 21:57:38 +0200 | [diff] [blame] | 760 | |
| 761 | |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 762 | int wpas_wps_start_reg(struct wpa_supplicant *wpa_s, const u8 *bssid, |
Jouni Malinen | 52eb293 | 2009-09-06 13:58:15 +0300 | [diff] [blame] | 763 | const char *pin, struct wps_new_ap_settings *settings) |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 764 | { |
| 765 | struct wpa_ssid *ssid; |
Jouni Malinen | 52eb293 | 2009-09-06 13:58:15 +0300 | [diff] [blame] | 766 | char val[200]; |
| 767 | char *pos, *end; |
| 768 | int res; |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 769 | |
| 770 | if (!pin) |
| 771 | return -1; |
| 772 | wpas_clear_wps(wpa_s); |
| 773 | ssid = wpas_wps_add_network(wpa_s, 1, bssid); |
| 774 | if (ssid == NULL) |
| 775 | return -1; |
Jouni Malinen | 52eb293 | 2009-09-06 13:58:15 +0300 | [diff] [blame] | 776 | pos = val; |
| 777 | end = pos + sizeof(val); |
| 778 | res = os_snprintf(pos, end - pos, "\"pin=%s", pin); |
| 779 | if (res < 0 || res >= end - pos) |
| 780 | return -1; |
| 781 | pos += res; |
| 782 | if (settings) { |
| 783 | res = os_snprintf(pos, end - pos, " new_ssid=%s new_auth=%s " |
| 784 | "new_encr=%s new_key=%s", |
| 785 | settings->ssid_hex, settings->auth, |
| 786 | settings->encr, settings->key_hex); |
| 787 | if (res < 0 || res >= end - pos) |
| 788 | return -1; |
| 789 | pos += res; |
| 790 | } |
| 791 | res = os_snprintf(pos, end - pos, "\""); |
| 792 | if (res < 0 || res >= end - pos) |
| 793 | return -1; |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 794 | wpa_config_set(ssid, "phase1", val, 0); |
Jouni Malinen | 42f5026 | 2010-07-22 10:24:23 -0700 | [diff] [blame^] | 795 | if (wpa_s->wps_fragment_size) |
| 796 | ssid->eap.fragment_size = wpa_s->wps_fragment_size; |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 797 | eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout, |
| 798 | wpa_s, NULL); |
| 799 | wpas_wps_reassoc(wpa_s, ssid); |
| 800 | return 0; |
| 801 | } |
| 802 | |
| 803 | |
Jouni Malinen | c5adf52 | 2009-01-03 20:18:35 +0200 | [diff] [blame] | 804 | static int wpas_wps_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *psk, |
| 805 | size_t psk_len) |
| 806 | { |
| 807 | wpa_printf(MSG_DEBUG, "WPS: Received new WPA/WPA2-PSK from WPS for " |
| 808 | "STA " MACSTR, MAC2STR(mac_addr)); |
| 809 | wpa_hexdump_key(MSG_DEBUG, "Per-device PSK", psk, psk_len); |
| 810 | |
| 811 | /* TODO */ |
| 812 | |
| 813 | return 0; |
| 814 | } |
| 815 | |
| 816 | |
| 817 | static void wpas_wps_pin_needed_cb(void *ctx, const u8 *uuid_e, |
| 818 | const struct wps_device_data *dev) |
| 819 | { |
| 820 | char uuid[40], txt[400]; |
| 821 | int len; |
Jouni Malinen | 96750ea | 2009-11-26 11:39:29 +0200 | [diff] [blame] | 822 | char devtype[WPS_DEV_TYPE_BUFSIZE]; |
Jouni Malinen | c5adf52 | 2009-01-03 20:18:35 +0200 | [diff] [blame] | 823 | if (uuid_bin2str(uuid_e, uuid, sizeof(uuid))) |
| 824 | return; |
| 825 | wpa_printf(MSG_DEBUG, "WPS: PIN needed for UUID-E %s", uuid); |
| 826 | len = os_snprintf(txt, sizeof(txt), "WPS-EVENT-PIN-NEEDED %s " MACSTR |
Jouni Malinen | 96750ea | 2009-11-26 11:39:29 +0200 | [diff] [blame] | 827 | " [%s|%s|%s|%s|%s|%s]", |
Jouni Malinen | c5adf52 | 2009-01-03 20:18:35 +0200 | [diff] [blame] | 828 | uuid, MAC2STR(dev->mac_addr), dev->device_name, |
| 829 | dev->manufacturer, dev->model_name, |
| 830 | dev->model_number, dev->serial_number, |
Jouni Malinen | 96750ea | 2009-11-26 11:39:29 +0200 | [diff] [blame] | 831 | wps_dev_type_bin2str(dev->pri_dev_type, devtype, |
| 832 | sizeof(devtype))); |
Jouni Malinen | c5adf52 | 2009-01-03 20:18:35 +0200 | [diff] [blame] | 833 | if (len > 0 && len < (int) sizeof(txt)) |
| 834 | wpa_printf(MSG_INFO, "%s", txt); |
| 835 | } |
| 836 | |
| 837 | |
Jouni Malinen | 72df2f5 | 2009-11-13 22:07:11 +0200 | [diff] [blame] | 838 | static void wpas_wps_set_sel_reg_cb(void *ctx, int sel_reg, u16 dev_passwd_id, |
| 839 | u16 sel_reg_config_methods) |
| 840 | { |
| 841 | #ifdef CONFIG_WPS_ER |
| 842 | struct wpa_supplicant *wpa_s = ctx; |
| 843 | |
| 844 | if (wpa_s->wps_er == NULL) |
| 845 | return; |
Jouni Malinen | ad47411 | 2010-07-18 22:53:15 -0700 | [diff] [blame] | 846 | wpa_printf(MSG_DEBUG, "WPS ER: SetSelectedRegistrar - sel_reg=%d " |
| 847 | "dev_password_id=%u sel_reg_config_methods=0x%x", |
| 848 | sel_reg, dev_passwd_id, sel_reg_config_methods); |
Jouni Malinen | 72df2f5 | 2009-11-13 22:07:11 +0200 | [diff] [blame] | 849 | wps_er_set_sel_reg(wpa_s->wps_er, sel_reg, dev_passwd_id, |
| 850 | sel_reg_config_methods); |
| 851 | #endif /* CONFIG_WPS_ER */ |
| 852 | } |
| 853 | |
| 854 | |
Jouni Malinen | 116654c | 2008-11-28 20:32:13 +0200 | [diff] [blame] | 855 | int wpas_wps_init(struct wpa_supplicant *wpa_s) |
| 856 | { |
| 857 | struct wps_context *wps; |
Jouni Malinen | c5adf52 | 2009-01-03 20:18:35 +0200 | [diff] [blame] | 858 | struct wps_registrar_config rcfg; |
Jouni Malinen | 116654c | 2008-11-28 20:32:13 +0200 | [diff] [blame] | 859 | |
| 860 | wps = os_zalloc(sizeof(*wps)); |
| 861 | if (wps == NULL) |
| 862 | return -1; |
| 863 | |
| 864 | wps->cred_cb = wpa_supplicant_wps_cred; |
Jouni Malinen | 4b68290 | 2008-12-18 21:58:42 +0200 | [diff] [blame] | 865 | wps->event_cb = wpa_supplicant_wps_event; |
Jouni Malinen | 116654c | 2008-11-28 20:32:13 +0200 | [diff] [blame] | 866 | wps->cb_ctx = wpa_s; |
| 867 | |
Jouni Malinen | 3c0b7aa | 2008-12-13 17:20:46 +0200 | [diff] [blame] | 868 | wps->dev.device_name = wpa_s->conf->device_name; |
| 869 | wps->dev.manufacturer = wpa_s->conf->manufacturer; |
| 870 | wps->dev.model_name = wpa_s->conf->model_name; |
| 871 | wps->dev.model_number = wpa_s->conf->model_number; |
| 872 | wps->dev.serial_number = wpa_s->conf->serial_number; |
Jouni Malinen | c0e4dd9 | 2009-12-21 15:59:25 +0200 | [diff] [blame] | 873 | wps->config_methods = |
| 874 | wps_config_methods_str2bin(wpa_s->conf->config_methods); |
Jouni Malinen | 979b988 | 2010-07-17 20:30:49 -0700 | [diff] [blame] | 875 | if ((wps->config_methods & (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) == |
| 876 | (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) { |
| 877 | wpa_printf(MSG_ERROR, "WPS: Both Label and Display config " |
| 878 | "methods are not allowed at the same time"); |
| 879 | os_free(wps); |
| 880 | return -1; |
| 881 | } |
Jouni Malinen | 96750ea | 2009-11-26 11:39:29 +0200 | [diff] [blame] | 882 | if (wpa_s->conf->device_type && |
| 883 | wps_dev_type_str2bin(wpa_s->conf->device_type, |
| 884 | wps->dev.pri_dev_type) < 0) { |
| 885 | wpa_printf(MSG_ERROR, "WPS: Invalid device_type"); |
| 886 | os_free(wps); |
| 887 | return -1; |
Jouni Malinen | 3c0b7aa | 2008-12-13 17:20:46 +0200 | [diff] [blame] | 888 | } |
| 889 | wps->dev.os_version = WPA_GET_BE32(wpa_s->conf->os_version); |
| 890 | wps->dev.rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ; /* TODO: config */ |
Jouni Malinen | 398cfbf | 2008-11-28 20:44:47 +0200 | [diff] [blame] | 891 | os_memcpy(wps->dev.mac_addr, wpa_s->own_addr, ETH_ALEN); |
Jouni Malinen | 79da74a | 2009-01-01 22:56:52 +0200 | [diff] [blame] | 892 | if (is_nil_uuid(wpa_s->conf->uuid)) { |
| 893 | uuid_gen_mac_addr(wpa_s->own_addr, wps->uuid); |
| 894 | wpa_hexdump(MSG_DEBUG, "WPS: UUID based on MAC address", |
| 895 | wps->uuid, WPS_UUID_LEN); |
| 896 | } else |
| 897 | os_memcpy(wps->uuid, wpa_s->conf->uuid, WPS_UUID_LEN); |
Jouni Malinen | 116654c | 2008-11-28 20:32:13 +0200 | [diff] [blame] | 898 | |
Jouni Malinen | c5adf52 | 2009-01-03 20:18:35 +0200 | [diff] [blame] | 899 | wps->auth_types = WPS_AUTH_WPA2PSK | WPS_AUTH_WPAPSK; |
| 900 | wps->encr_types = WPS_ENCR_AES | WPS_ENCR_TKIP; |
| 901 | |
| 902 | os_memset(&rcfg, 0, sizeof(rcfg)); |
| 903 | rcfg.new_psk_cb = wpas_wps_new_psk_cb; |
| 904 | rcfg.pin_needed_cb = wpas_wps_pin_needed_cb; |
Jouni Malinen | 72df2f5 | 2009-11-13 22:07:11 +0200 | [diff] [blame] | 905 | rcfg.set_sel_reg_cb = wpas_wps_set_sel_reg_cb; |
Jouni Malinen | c5adf52 | 2009-01-03 20:18:35 +0200 | [diff] [blame] | 906 | rcfg.cb_ctx = wpa_s; |
| 907 | |
| 908 | wps->registrar = wps_registrar_init(wps, &rcfg); |
| 909 | if (wps->registrar == NULL) { |
| 910 | wpa_printf(MSG_DEBUG, "Failed to initialize WPS Registrar"); |
| 911 | os_free(wps); |
| 912 | return -1; |
| 913 | } |
| 914 | |
Jouni Malinen | 116654c | 2008-11-28 20:32:13 +0200 | [diff] [blame] | 915 | wpa_s->wps = wps; |
| 916 | |
| 917 | return 0; |
| 918 | } |
| 919 | |
| 920 | |
| 921 | void wpas_wps_deinit(struct wpa_supplicant *wpa_s) |
| 922 | { |
Jouni Malinen | fcc60db | 2008-11-29 20:59:45 +0200 | [diff] [blame] | 923 | eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL); |
| 924 | |
Jouni Malinen | 116654c | 2008-11-28 20:32:13 +0200 | [diff] [blame] | 925 | if (wpa_s->wps == NULL) |
| 926 | return; |
| 927 | |
Jouni Malinen | a6b6307 | 2009-11-15 22:52:17 +0200 | [diff] [blame] | 928 | #ifdef CONFIG_WPS_ER |
Jouni Malinen | 1a1bf00 | 2009-12-19 23:47:54 +0200 | [diff] [blame] | 929 | wps_er_deinit(wpa_s->wps_er, NULL, NULL); |
Jouni Malinen | a6b6307 | 2009-11-15 22:52:17 +0200 | [diff] [blame] | 930 | wpa_s->wps_er = NULL; |
| 931 | #endif /* CONFIG_WPS_ER */ |
| 932 | |
Jouni Malinen | c5adf52 | 2009-01-03 20:18:35 +0200 | [diff] [blame] | 933 | wps_registrar_deinit(wpa_s->wps->registrar); |
Masashi Honma | 46bdb83 | 2009-02-26 21:57:38 +0200 | [diff] [blame] | 934 | wpabuf_free(wpa_s->wps->dh_pubkey); |
| 935 | wpabuf_free(wpa_s->wps->dh_privkey); |
| 936 | wpabuf_free(wpa_s->wps->oob_conf.pubkey_hash); |
| 937 | wpabuf_free(wpa_s->wps->oob_conf.dev_password); |
Jouni Malinen | 116654c | 2008-11-28 20:32:13 +0200 | [diff] [blame] | 938 | os_free(wpa_s->wps->network_key); |
| 939 | os_free(wpa_s->wps); |
| 940 | wpa_s->wps = NULL; |
| 941 | } |
Jouni Malinen | 351f09a | 2008-11-29 22:06:34 +0200 | [diff] [blame] | 942 | |
| 943 | |
Jouni Malinen | a609915 | 2009-01-23 13:10:58 +0200 | [diff] [blame] | 944 | int wpas_wps_ssid_bss_match(struct wpa_supplicant *wpa_s, |
| 945 | struct wpa_ssid *ssid, struct wpa_scan_res *bss) |
Jouni Malinen | 351f09a | 2008-11-29 22:06:34 +0200 | [diff] [blame] | 946 | { |
| 947 | struct wpabuf *wps_ie; |
| 948 | |
| 949 | if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS)) |
| 950 | return -1; |
| 951 | |
| 952 | wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); |
| 953 | if (eap_is_wps_pbc_enrollee(&ssid->eap)) { |
| 954 | if (!wps_ie) { |
| 955 | wpa_printf(MSG_DEBUG, " skip - non-WPS AP"); |
| 956 | return 0; |
| 957 | } |
| 958 | |
| 959 | if (!wps_is_selected_pbc_registrar(wps_ie)) { |
| 960 | wpa_printf(MSG_DEBUG, " skip - WPS AP " |
| 961 | "without active PBC Registrar"); |
| 962 | wpabuf_free(wps_ie); |
| 963 | return 0; |
| 964 | } |
| 965 | |
| 966 | /* TODO: overlap detection */ |
| 967 | wpa_printf(MSG_DEBUG, " selected based on WPS IE " |
| 968 | "(Active PBC)"); |
| 969 | wpabuf_free(wps_ie); |
| 970 | return 1; |
| 971 | } |
| 972 | |
| 973 | if (eap_is_wps_pin_enrollee(&ssid->eap)) { |
| 974 | if (!wps_ie) { |
| 975 | wpa_printf(MSG_DEBUG, " skip - non-WPS AP"); |
| 976 | return 0; |
| 977 | } |
| 978 | |
Jouni Malinen | a609915 | 2009-01-23 13:10:58 +0200 | [diff] [blame] | 979 | /* |
Jouni Malinen | 31fcea9 | 2009-12-12 16:40:10 +0200 | [diff] [blame] | 980 | * Start with WPS APs that advertise our address as an |
| 981 | * authorized MAC (v2.0) or active PIN Registrar (v1.0) and |
| 982 | * allow any WPS AP after couple of scans since some APs do not |
| 983 | * set Selected Registrar attribute properly when using |
| 984 | * external Registrar. |
Jouni Malinen | a609915 | 2009-01-23 13:10:58 +0200 | [diff] [blame] | 985 | */ |
Jouni Malinen | 31fcea9 | 2009-12-12 16:40:10 +0200 | [diff] [blame] | 986 | if (!wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1)) { |
Jouni Malinen | a609915 | 2009-01-23 13:10:58 +0200 | [diff] [blame] | 987 | if (wpa_s->scan_runs < WPS_PIN_SCAN_IGNORE_SEL_REG) { |
| 988 | wpa_printf(MSG_DEBUG, " skip - WPS AP " |
| 989 | "without active PIN Registrar"); |
| 990 | wpabuf_free(wps_ie); |
| 991 | return 0; |
| 992 | } |
| 993 | wpa_printf(MSG_DEBUG, " selected based on WPS IE"); |
| 994 | } else { |
| 995 | wpa_printf(MSG_DEBUG, " selected based on WPS IE " |
Jouni Malinen | 31fcea9 | 2009-12-12 16:40:10 +0200 | [diff] [blame] | 996 | "(Authorized MAC or Active PIN)"); |
Jouni Malinen | 351f09a | 2008-11-29 22:06:34 +0200 | [diff] [blame] | 997 | } |
Jouni Malinen | 351f09a | 2008-11-29 22:06:34 +0200 | [diff] [blame] | 998 | wpabuf_free(wps_ie); |
| 999 | return 1; |
| 1000 | } |
| 1001 | |
| 1002 | if (wps_ie) { |
| 1003 | wpa_printf(MSG_DEBUG, " selected based on WPS IE"); |
| 1004 | wpabuf_free(wps_ie); |
| 1005 | return 1; |
| 1006 | } |
| 1007 | |
| 1008 | return -1; |
| 1009 | } |
| 1010 | |
| 1011 | |
Jouni Malinen | a609915 | 2009-01-23 13:10:58 +0200 | [diff] [blame] | 1012 | int wpas_wps_ssid_wildcard_ok(struct wpa_supplicant *wpa_s, |
| 1013 | struct wpa_ssid *ssid, |
Jouni Malinen | 351f09a | 2008-11-29 22:06:34 +0200 | [diff] [blame] | 1014 | struct wpa_scan_res *bss) |
| 1015 | { |
| 1016 | struct wpabuf *wps_ie = NULL; |
| 1017 | int ret = 0; |
| 1018 | |
| 1019 | if (eap_is_wps_pbc_enrollee(&ssid->eap)) { |
| 1020 | wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); |
| 1021 | if (wps_ie && wps_is_selected_pbc_registrar(wps_ie)) { |
| 1022 | /* allow wildcard SSID for WPS PBC */ |
| 1023 | ret = 1; |
| 1024 | } |
| 1025 | } else if (eap_is_wps_pin_enrollee(&ssid->eap)) { |
| 1026 | wps_ie = wpa_scan_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); |
Jouni Malinen | a609915 | 2009-01-23 13:10:58 +0200 | [diff] [blame] | 1027 | if (wps_ie && |
Jouni Malinen | 31fcea9 | 2009-12-12 16:40:10 +0200 | [diff] [blame] | 1028 | (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1) || |
Jouni Malinen | a609915 | 2009-01-23 13:10:58 +0200 | [diff] [blame] | 1029 | wpa_s->scan_runs >= WPS_PIN_SCAN_IGNORE_SEL_REG)) { |
Jouni Malinen | 351f09a | 2008-11-29 22:06:34 +0200 | [diff] [blame] | 1030 | /* allow wildcard SSID for WPS PIN */ |
| 1031 | ret = 1; |
| 1032 | } |
| 1033 | } |
| 1034 | |
Jouni Malinen | 24c23d1 | 2008-12-20 22:55:02 +0200 | [diff] [blame] | 1035 | if (!ret && ssid->bssid_set && |
| 1036 | os_memcmp(ssid->bssid, bss->bssid, ETH_ALEN) == 0) { |
| 1037 | /* allow wildcard SSID due to hardcoded BSSID match */ |
| 1038 | ret = 1; |
| 1039 | } |
| 1040 | |
Jouni Malinen | 54f489b | 2010-05-26 17:16:14 +0300 | [diff] [blame] | 1041 | #ifdef CONFIG_WPS_STRICT |
| 1042 | if (wps_ie) { |
| 1043 | if (wps_validate_beacon_probe_resp(wps_ie, bss->beacon_ie_len > |
| 1044 | 0) < 0) |
| 1045 | ret = 0; |
| 1046 | if (bss->beacon_ie_len) { |
| 1047 | struct wpabuf *bcn_wps; |
| 1048 | bcn_wps = wpa_scan_get_vendor_ie_multi_beacon( |
| 1049 | bss, WPS_IE_VENDOR_TYPE); |
| 1050 | if (bcn_wps == NULL) { |
| 1051 | wpa_printf(MSG_DEBUG, "WPS: Mandatory WPS IE " |
| 1052 | "missing from AP Beacon"); |
| 1053 | ret = 0; |
| 1054 | } else { |
| 1055 | if (wps_validate_beacon(wps_ie) < 0) |
| 1056 | ret = 0; |
| 1057 | wpabuf_free(bcn_wps); |
| 1058 | } |
| 1059 | } |
| 1060 | } |
| 1061 | #endif /* CONFIG_WPS_STRICT */ |
| 1062 | |
Jouni Malinen | 351f09a | 2008-11-29 22:06:34 +0200 | [diff] [blame] | 1063 | wpabuf_free(wps_ie); |
| 1064 | |
| 1065 | return ret; |
| 1066 | } |
| 1067 | |
| 1068 | |
| 1069 | int wpas_wps_scan_pbc_overlap(struct wpa_supplicant *wpa_s, |
Jouni Malinen | 6fa81a3 | 2010-01-02 16:16:02 +0200 | [diff] [blame] | 1070 | struct wpa_bss *selected, struct wpa_ssid *ssid) |
Jouni Malinen | 351f09a | 2008-11-29 22:06:34 +0200 | [diff] [blame] | 1071 | { |
| 1072 | const u8 *sel_uuid, *uuid; |
Jouni Malinen | 351f09a | 2008-11-29 22:06:34 +0200 | [diff] [blame] | 1073 | struct wpabuf *wps_ie; |
| 1074 | int ret = 0; |
Jouni Malinen | 6fa81a3 | 2010-01-02 16:16:02 +0200 | [diff] [blame] | 1075 | struct wpa_bss *bss; |
Jouni Malinen | 351f09a | 2008-11-29 22:06:34 +0200 | [diff] [blame] | 1076 | |
| 1077 | if (!eap_is_wps_pbc_enrollee(&ssid->eap)) |
| 1078 | return 0; |
| 1079 | |
| 1080 | /* Make sure that only one AP is in active PBC mode */ |
Jouni Malinen | 6fa81a3 | 2010-01-02 16:16:02 +0200 | [diff] [blame] | 1081 | wps_ie = wpa_bss_get_vendor_ie_multi(selected, WPS_IE_VENDOR_TYPE); |
Jouni Malinen | 351f09a | 2008-11-29 22:06:34 +0200 | [diff] [blame] | 1082 | if (wps_ie) |
| 1083 | sel_uuid = wps_get_uuid_e(wps_ie); |
| 1084 | else |
| 1085 | sel_uuid = NULL; |
Jouni Malinen | 351f09a | 2008-11-29 22:06:34 +0200 | [diff] [blame] | 1086 | |
Jouni Malinen | 6fa81a3 | 2010-01-02 16:16:02 +0200 | [diff] [blame] | 1087 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
Jouni Malinen | 351f09a | 2008-11-29 22:06:34 +0200 | [diff] [blame] | 1088 | struct wpabuf *ie; |
| 1089 | if (bss == selected) |
| 1090 | continue; |
Jouni Malinen | 6fa81a3 | 2010-01-02 16:16:02 +0200 | [diff] [blame] | 1091 | ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); |
Jouni Malinen | 351f09a | 2008-11-29 22:06:34 +0200 | [diff] [blame] | 1092 | if (!ie) |
| 1093 | continue; |
| 1094 | if (!wps_is_selected_pbc_registrar(ie)) { |
| 1095 | wpabuf_free(ie); |
| 1096 | continue; |
| 1097 | } |
| 1098 | uuid = wps_get_uuid_e(ie); |
Jouni Malinen | 44cd430 | 2008-12-21 17:28:01 +0200 | [diff] [blame] | 1099 | if (sel_uuid == NULL || uuid == NULL || |
| 1100 | os_memcmp(sel_uuid, uuid, 16) != 0) { |
Jouni Malinen | 351f09a | 2008-11-29 22:06:34 +0200 | [diff] [blame] | 1101 | ret = 1; /* PBC overlap */ |
| 1102 | wpabuf_free(ie); |
| 1103 | break; |
| 1104 | } |
| 1105 | |
| 1106 | /* TODO: verify that this is reasonable dual-band situation */ |
Jouni Malinen | 484957a | 2008-12-15 19:50:53 +0200 | [diff] [blame] | 1107 | |
| 1108 | wpabuf_free(ie); |
Jouni Malinen | 351f09a | 2008-11-29 22:06:34 +0200 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | wpabuf_free(wps_ie); |
| 1112 | |
| 1113 | return ret; |
| 1114 | } |
Jouni Malinen | a524f05 | 2008-12-15 20:09:57 +0200 | [diff] [blame] | 1115 | |
| 1116 | |
| 1117 | void wpas_wps_notify_scan_results(struct wpa_supplicant *wpa_s) |
| 1118 | { |
Jouni Malinen | 6fa81a3 | 2010-01-02 16:16:02 +0200 | [diff] [blame] | 1119 | struct wpa_bss *bss; |
Jouni Malinen | a524f05 | 2008-12-15 20:09:57 +0200 | [diff] [blame] | 1120 | |
| 1121 | if (wpa_s->disconnected || wpa_s->wpa_state >= WPA_ASSOCIATED) |
| 1122 | return; |
| 1123 | |
Jouni Malinen | 6fa81a3 | 2010-01-02 16:16:02 +0200 | [diff] [blame] | 1124 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
Jouni Malinen | a524f05 | 2008-12-15 20:09:57 +0200 | [diff] [blame] | 1125 | struct wpabuf *ie; |
Jouni Malinen | 6fa81a3 | 2010-01-02 16:16:02 +0200 | [diff] [blame] | 1126 | ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); |
Jouni Malinen | a524f05 | 2008-12-15 20:09:57 +0200 | [diff] [blame] | 1127 | if (!ie) |
| 1128 | continue; |
| 1129 | if (wps_is_selected_pbc_registrar(ie)) |
Jouni Malinen | 332d630 | 2009-12-28 00:44:10 +0200 | [diff] [blame] | 1130 | wpa_msg_ctrl(wpa_s, MSG_INFO, |
| 1131 | WPS_EVENT_AP_AVAILABLE_PBC); |
Jouni Malinen | 31fcea9 | 2009-12-12 16:40:10 +0200 | [diff] [blame] | 1132 | else if (wps_is_addr_authorized(ie, wpa_s->own_addr, 0)) |
| 1133 | wpa_msg_ctrl(wpa_s, MSG_INFO, |
| 1134 | WPS_EVENT_AP_AVAILABLE_AUTH); |
Jouni Malinen | a524f05 | 2008-12-15 20:09:57 +0200 | [diff] [blame] | 1135 | else if (wps_is_selected_pin_registrar(ie)) |
Jouni Malinen | 332d630 | 2009-12-28 00:44:10 +0200 | [diff] [blame] | 1136 | wpa_msg_ctrl(wpa_s, MSG_INFO, |
| 1137 | WPS_EVENT_AP_AVAILABLE_PIN); |
Jouni Malinen | a524f05 | 2008-12-15 20:09:57 +0200 | [diff] [blame] | 1138 | else |
Jouni Malinen | 332d630 | 2009-12-28 00:44:10 +0200 | [diff] [blame] | 1139 | wpa_msg_ctrl(wpa_s, MSG_INFO, |
| 1140 | WPS_EVENT_AP_AVAILABLE); |
Jouni Malinen | a524f05 | 2008-12-15 20:09:57 +0200 | [diff] [blame] | 1141 | wpabuf_free(ie); |
| 1142 | break; |
| 1143 | } |
| 1144 | } |
Jouni Malinen | 24c23d1 | 2008-12-20 22:55:02 +0200 | [diff] [blame] | 1145 | |
| 1146 | |
| 1147 | int wpas_wps_searching(struct wpa_supplicant *wpa_s) |
| 1148 | { |
| 1149 | struct wpa_ssid *ssid; |
| 1150 | |
| 1151 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 1152 | if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && !ssid->disabled) |
| 1153 | return 1; |
| 1154 | } |
| 1155 | |
| 1156 | return 0; |
| 1157 | } |
Jouni Malinen | 611ed49 | 2009-09-11 17:14:49 +0300 | [diff] [blame] | 1158 | |
| 1159 | |
| 1160 | int wpas_wps_scan_result_text(const u8 *ies, size_t ies_len, char *buf, |
| 1161 | char *end) |
| 1162 | { |
| 1163 | struct wpabuf *wps_ie; |
| 1164 | int ret; |
| 1165 | |
| 1166 | wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len, WPS_DEV_OUI_WFA); |
| 1167 | if (wps_ie == NULL) |
| 1168 | return 0; |
| 1169 | |
| 1170 | ret = wps_attr_text(wps_ie, buf, end); |
| 1171 | wpabuf_free(wps_ie); |
| 1172 | return ret; |
| 1173 | } |
Jouni Malinen | e9bcfeb | 2009-11-07 12:41:01 +0200 | [diff] [blame] | 1174 | |
| 1175 | |
Jouni Malinen | 0848668 | 2010-05-27 15:23:55 +0300 | [diff] [blame] | 1176 | int wpas_wps_er_start(struct wpa_supplicant *wpa_s, const char *filter) |
Jouni Malinen | e9bcfeb | 2009-11-07 12:41:01 +0200 | [diff] [blame] | 1177 | { |
| 1178 | #ifdef CONFIG_WPS_ER |
| 1179 | if (wpa_s->wps_er) { |
Jouni Malinen | b3f371c | 2009-11-20 21:57:30 +0200 | [diff] [blame] | 1180 | wps_er_refresh(wpa_s->wps_er); |
Jouni Malinen | e9bcfeb | 2009-11-07 12:41:01 +0200 | [diff] [blame] | 1181 | return 0; |
| 1182 | } |
Jouni Malinen | 0848668 | 2010-05-27 15:23:55 +0300 | [diff] [blame] | 1183 | wpa_s->wps_er = wps_er_init(wpa_s->wps, wpa_s->ifname, filter); |
Jouni Malinen | e9bcfeb | 2009-11-07 12:41:01 +0200 | [diff] [blame] | 1184 | if (wpa_s->wps_er == NULL) |
| 1185 | return -1; |
| 1186 | return 0; |
| 1187 | #else /* CONFIG_WPS_ER */ |
| 1188 | return 0; |
| 1189 | #endif /* CONFIG_WPS_ER */ |
| 1190 | } |
| 1191 | |
| 1192 | |
| 1193 | int wpas_wps_er_stop(struct wpa_supplicant *wpa_s) |
| 1194 | { |
| 1195 | #ifdef CONFIG_WPS_ER |
Jouni Malinen | 1a1bf00 | 2009-12-19 23:47:54 +0200 | [diff] [blame] | 1196 | wps_er_deinit(wpa_s->wps_er, NULL, NULL); |
Jouni Malinen | e9bcfeb | 2009-11-07 12:41:01 +0200 | [diff] [blame] | 1197 | wpa_s->wps_er = NULL; |
| 1198 | #endif /* CONFIG_WPS_ER */ |
| 1199 | return 0; |
| 1200 | } |
Jouni Malinen | 72df2f5 | 2009-11-13 22:07:11 +0200 | [diff] [blame] | 1201 | |
| 1202 | |
| 1203 | #ifdef CONFIG_WPS_ER |
Jouni Malinen | 31fcea9 | 2009-12-12 16:40:10 +0200 | [diff] [blame] | 1204 | int wpas_wps_er_add_pin(struct wpa_supplicant *wpa_s, const u8 *addr, |
| 1205 | const char *uuid, const char *pin) |
Jouni Malinen | 72df2f5 | 2009-11-13 22:07:11 +0200 | [diff] [blame] | 1206 | { |
| 1207 | u8 u[UUID_LEN]; |
| 1208 | int any = 0; |
| 1209 | |
| 1210 | if (os_strcmp(uuid, "any") == 0) |
| 1211 | any = 1; |
| 1212 | else if (uuid_str2bin(uuid, u)) |
| 1213 | return -1; |
Jouni Malinen | 31fcea9 | 2009-12-12 16:40:10 +0200 | [diff] [blame] | 1214 | return wps_registrar_add_pin(wpa_s->wps->registrar, addr, |
| 1215 | any ? NULL : u, |
Jouni Malinen | 72df2f5 | 2009-11-13 22:07:11 +0200 | [diff] [blame] | 1216 | (const u8 *) pin, os_strlen(pin), 300); |
| 1217 | } |
Jouni Malinen | 564cd7f | 2009-11-15 18:46:03 +0200 | [diff] [blame] | 1218 | |
| 1219 | |
| 1220 | int wpas_wps_er_pbc(struct wpa_supplicant *wpa_s, const char *uuid) |
| 1221 | { |
| 1222 | u8 u[UUID_LEN]; |
| 1223 | |
| 1224 | if (uuid_str2bin(uuid, u)) |
| 1225 | return -1; |
| 1226 | return wps_er_pbc(wpa_s->wps_er, u); |
| 1227 | } |
Jouni Malinen | e64dcfd | 2009-11-15 22:27:06 +0200 | [diff] [blame] | 1228 | |
| 1229 | |
| 1230 | int wpas_wps_er_learn(struct wpa_supplicant *wpa_s, const char *uuid, |
| 1231 | const char *pin) |
| 1232 | { |
| 1233 | u8 u[UUID_LEN]; |
| 1234 | |
| 1235 | if (uuid_str2bin(uuid, u)) |
| 1236 | return -1; |
| 1237 | return wps_er_learn(wpa_s->wps_er, u, (const u8 *) pin, |
| 1238 | os_strlen(pin)); |
| 1239 | } |
Jouni Malinen | 1a1bf00 | 2009-12-19 23:47:54 +0200 | [diff] [blame] | 1240 | |
| 1241 | |
Jouni Malinen | 7d6640a | 2010-05-28 00:01:48 +0300 | [diff] [blame] | 1242 | int wpas_wps_er_config(struct wpa_supplicant *wpa_s, const char *uuid, |
| 1243 | const char *pin, struct wps_new_ap_settings *settings) |
| 1244 | { |
| 1245 | u8 u[UUID_LEN]; |
| 1246 | struct wps_credential cred; |
| 1247 | size_t len; |
| 1248 | |
| 1249 | if (uuid_str2bin(uuid, u)) |
| 1250 | return -1; |
| 1251 | if (settings->ssid_hex == NULL || settings->auth == NULL || |
| 1252 | settings->encr == NULL || settings->key_hex == NULL) |
| 1253 | return -1; |
| 1254 | |
| 1255 | os_memset(&cred, 0, sizeof(cred)); |
| 1256 | len = os_strlen(settings->ssid_hex); |
| 1257 | if ((len & 1) || len > 2 * sizeof(cred.ssid) || |
| 1258 | hexstr2bin(settings->ssid_hex, cred.ssid, len / 2)) |
| 1259 | return -1; |
| 1260 | cred.ssid_len = len / 2; |
| 1261 | |
| 1262 | len = os_strlen(settings->key_hex); |
| 1263 | if ((len & 1) || len > 2 * sizeof(cred.key) || |
| 1264 | hexstr2bin(settings->key_hex, cred.key, len / 2)) |
| 1265 | return -1; |
| 1266 | cred.key_len = len / 2; |
| 1267 | |
| 1268 | if (os_strcmp(settings->auth, "OPEN") == 0) |
| 1269 | cred.auth_type = WPS_AUTH_OPEN; |
| 1270 | else if (os_strcmp(settings->auth, "WPAPSK") == 0) |
| 1271 | cred.auth_type = WPS_AUTH_WPAPSK; |
| 1272 | else if (os_strcmp(settings->auth, "WPA2PSK") == 0) |
| 1273 | cred.auth_type = WPS_AUTH_WPA2PSK; |
| 1274 | else |
| 1275 | return -1; |
| 1276 | |
| 1277 | if (os_strcmp(settings->encr, "NONE") == 0) |
| 1278 | cred.encr_type = WPS_ENCR_NONE; |
| 1279 | else if (os_strcmp(settings->encr, "WEP") == 0) |
| 1280 | cred.encr_type = WPS_ENCR_WEP; |
| 1281 | else if (os_strcmp(settings->encr, "TKIP") == 0) |
| 1282 | cred.encr_type = WPS_ENCR_TKIP; |
| 1283 | else if (os_strcmp(settings->encr, "CCMP") == 0) |
| 1284 | cred.encr_type = WPS_ENCR_AES; |
| 1285 | else |
| 1286 | return -1; |
| 1287 | |
| 1288 | return wps_er_config(wpa_s->wps_er, u, (const u8 *) pin, |
| 1289 | os_strlen(pin), &cred); |
| 1290 | } |
| 1291 | |
| 1292 | |
Jouni Malinen | 1a1bf00 | 2009-12-19 23:47:54 +0200 | [diff] [blame] | 1293 | static void wpas_wps_terminate_cb(void *ctx) |
| 1294 | { |
| 1295 | wpa_printf(MSG_DEBUG, "WPS ER: Terminated"); |
| 1296 | eloop_terminate(); |
| 1297 | } |
Jouni Malinen | 72df2f5 | 2009-11-13 22:07:11 +0200 | [diff] [blame] | 1298 | #endif /* CONFIG_WPS_ER */ |
Jouni Malinen | 1a1bf00 | 2009-12-19 23:47:54 +0200 | [diff] [blame] | 1299 | |
| 1300 | |
| 1301 | int wpas_wps_terminate_pending(struct wpa_supplicant *wpa_s) |
| 1302 | { |
| 1303 | #ifdef CONFIG_WPS_ER |
| 1304 | if (wpa_s->wps_er) { |
| 1305 | wps_er_deinit(wpa_s->wps_er, wpas_wps_terminate_cb, wpa_s); |
| 1306 | wpa_s->wps_er = NULL; |
| 1307 | return 1; |
| 1308 | } |
| 1309 | #endif /* CONFIG_WPS_ER */ |
| 1310 | return 0; |
| 1311 | } |
Jouni Malinen | 41e650a | 2010-06-11 13:50:13 -0700 | [diff] [blame] | 1312 | |
| 1313 | |
| 1314 | int wpas_wps_in_progress(struct wpa_supplicant *wpa_s) |
| 1315 | { |
| 1316 | struct wpa_ssid *ssid; |
| 1317 | |
| 1318 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 1319 | if (!ssid->disabled && ssid->key_mgmt == WPA_KEY_MGMT_WPS) |
| 1320 | return 1; |
| 1321 | } |
| 1322 | |
| 1323 | return 0; |
| 1324 | } |