Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * wpa_supplicant / WPS integration |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3 | * Copyright (c) 2008-2014, Jouni Malinen <j@w1.fi> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4 | * |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5 | * This software may be distributed under the terms of the BSD license. |
| 6 | * See README for more details. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include "includes.h" |
| 10 | |
| 11 | #include "common.h" |
| 12 | #include "eloop.h" |
| 13 | #include "uuid.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 14 | #include "crypto/random.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 15 | #include "crypto/dh_group5.h" |
| 16 | #include "common/ieee802_11_defs.h" |
| 17 | #include "common/ieee802_11_common.h" |
| 18 | #include "common/wpa_common.h" |
| 19 | #include "common/wpa_ctrl.h" |
| 20 | #include "eap_common/eap_wsc_common.h" |
| 21 | #include "eap_peer/eap.h" |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 22 | #include "eapol_supp/eapol_supp_sm.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 23 | #include "rsn_supp/wpa.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 24 | #include "wps/wps_attr_parse.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 25 | #include "config.h" |
| 26 | #include "wpa_supplicant_i.h" |
| 27 | #include "driver_i.h" |
| 28 | #include "notify.h" |
| 29 | #include "blacklist.h" |
| 30 | #include "bss.h" |
| 31 | #include "scan.h" |
| 32 | #include "ap.h" |
| 33 | #include "p2p/p2p.h" |
| 34 | #include "p2p_supplicant.h" |
| 35 | #include "wps_supplicant.h" |
| 36 | |
| 37 | |
| 38 | #ifndef WPS_PIN_SCAN_IGNORE_SEL_REG |
| 39 | #define WPS_PIN_SCAN_IGNORE_SEL_REG 3 |
| 40 | #endif /* WPS_PIN_SCAN_IGNORE_SEL_REG */ |
| 41 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame^] | 42 | /* |
| 43 | * The minimum time in seconds before trying to associate to a WPS PIN AP that |
| 44 | * does not have Selected Registrar TRUE. |
| 45 | */ |
| 46 | #ifndef WPS_PIN_TIME_IGNORE_SEL_REG |
| 47 | #define WPS_PIN_TIME_IGNORE_SEL_REG 5 |
| 48 | #endif /* WPS_PIN_TIME_IGNORE_SEL_REG */ |
| 49 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 50 | static void wpas_wps_timeout(void *eloop_ctx, void *timeout_ctx); |
| 51 | static void wpas_clear_wps(struct wpa_supplicant *wpa_s); |
| 52 | |
| 53 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 54 | static void wpas_wps_clear_ap_info(struct wpa_supplicant *wpa_s) |
| 55 | { |
| 56 | os_free(wpa_s->wps_ap); |
| 57 | wpa_s->wps_ap = NULL; |
| 58 | wpa_s->num_wps_ap = 0; |
| 59 | wpa_s->wps_ap_iter = 0; |
| 60 | } |
| 61 | |
| 62 | |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 63 | static void wpas_wps_assoc_with_cred(void *eloop_ctx, void *timeout_ctx) |
| 64 | { |
| 65 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 66 | int use_fast_assoc = timeout_ctx != NULL; |
| 67 | |
| 68 | wpa_printf(MSG_DEBUG, "WPS: Continuing association after eapol_cb"); |
| 69 | if (!use_fast_assoc || |
| 70 | wpa_supplicant_fast_associate(wpa_s) != 1) |
| 71 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | static void wpas_wps_assoc_with_cred_cancel(struct wpa_supplicant *wpa_s) |
| 76 | { |
| 77 | eloop_cancel_timeout(wpas_wps_assoc_with_cred, wpa_s, (void *) 0); |
| 78 | eloop_cancel_timeout(wpas_wps_assoc_with_cred, wpa_s, (void *) 1); |
| 79 | } |
| 80 | |
| 81 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 82 | int wpas_wps_eapol_cb(struct wpa_supplicant *wpa_s) |
| 83 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 84 | if (wpas_p2p_wps_eapol_cb(wpa_s) > 0) |
| 85 | return 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 86 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 87 | if (!wpa_s->wps_success && |
| 88 | wpa_s->current_ssid && |
| 89 | eap_is_wps_pin_enrollee(&wpa_s->current_ssid->eap)) { |
| 90 | const u8 *bssid = wpa_s->bssid; |
| 91 | if (is_zero_ether_addr(bssid)) |
| 92 | bssid = wpa_s->pending_bssid; |
| 93 | |
| 94 | wpa_printf(MSG_DEBUG, "WPS: PIN registration with " MACSTR |
| 95 | " did not succeed - continue trying to find " |
| 96 | "suitable AP", MAC2STR(bssid)); |
| 97 | wpa_blacklist_add(wpa_s, bssid); |
| 98 | |
| 99 | wpa_supplicant_deauthenticate(wpa_s, |
| 100 | WLAN_REASON_DEAUTH_LEAVING); |
| 101 | wpa_s->reassociate = 1; |
| 102 | wpa_supplicant_req_scan(wpa_s, |
| 103 | wpa_s->blacklist_cleared ? 5 : 0, 0); |
| 104 | wpa_s->blacklist_cleared = 0; |
| 105 | return 1; |
| 106 | } |
| 107 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 108 | wpas_wps_clear_ap_info(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 109 | eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL); |
| 110 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && !wpa_s->wps_success) |
| 111 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_FAIL); |
| 112 | |
| 113 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && wpa_s->current_ssid && |
| 114 | !(wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS)) { |
| 115 | int disabled = wpa_s->current_ssid->disabled; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 116 | unsigned int freq = wpa_s->assoc_freq; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 117 | struct wpa_bss *bss; |
| 118 | struct wpa_ssid *ssid = NULL; |
| 119 | int use_fast_assoc = 0; |
| 120 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 121 | wpa_printf(MSG_DEBUG, "WPS: Network configuration replaced - " |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 122 | "try to associate with the received credential " |
| 123 | "(freq=%u)", freq); |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 124 | wpa_s->own_disconnect_req = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 125 | wpa_supplicant_deauthenticate(wpa_s, |
| 126 | WLAN_REASON_DEAUTH_LEAVING); |
| 127 | if (disabled) { |
| 128 | wpa_printf(MSG_DEBUG, "WPS: Current network is " |
| 129 | "disabled - wait for user to enable"); |
| 130 | return 1; |
| 131 | } |
| 132 | wpa_s->after_wps = 5; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 133 | wpa_s->wps_freq = freq; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 134 | wpa_s->normal_scans = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 135 | wpa_s->reassociate = 1; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 136 | |
| 137 | wpa_printf(MSG_DEBUG, "WPS: Checking whether fast association " |
| 138 | "without a new scan can be used"); |
| 139 | bss = wpa_supplicant_pick_network(wpa_s, &ssid); |
| 140 | if (bss) { |
| 141 | struct wpabuf *wps; |
| 142 | struct wps_parse_attr attr; |
| 143 | |
| 144 | wps = wpa_bss_get_vendor_ie_multi(bss, |
| 145 | WPS_IE_VENDOR_TYPE); |
| 146 | if (wps && wps_parse_msg(wps, &attr) == 0 && |
| 147 | attr.wps_state && |
| 148 | *attr.wps_state == WPS_STATE_CONFIGURED) |
| 149 | use_fast_assoc = 1; |
| 150 | wpabuf_free(wps); |
| 151 | } |
| 152 | |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 153 | /* |
| 154 | * Complete the next step from an eloop timeout to allow pending |
| 155 | * driver events related to the disconnection to be processed |
| 156 | * first. This makes it less likely for disconnection event to |
| 157 | * cause problems with the following connection. |
| 158 | */ |
| 159 | wpa_printf(MSG_DEBUG, "WPS: Continue association from timeout"); |
| 160 | wpas_wps_assoc_with_cred_cancel(wpa_s); |
| 161 | eloop_register_timeout(0, 10000, |
| 162 | wpas_wps_assoc_with_cred, wpa_s, |
| 163 | use_fast_assoc ? (void *) 1 : |
| 164 | (void *) 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 165 | return 1; |
| 166 | } |
| 167 | |
| 168 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS && wpa_s->current_ssid) { |
| 169 | wpa_printf(MSG_DEBUG, "WPS: Registration completed - waiting " |
| 170 | "for external credential processing"); |
| 171 | wpas_clear_wps(wpa_s); |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 172 | wpa_s->own_disconnect_req = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 173 | wpa_supplicant_deauthenticate(wpa_s, |
| 174 | WLAN_REASON_DEAUTH_LEAVING); |
| 175 | return 1; |
| 176 | } |
| 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | |
| 182 | static void wpas_wps_security_workaround(struct wpa_supplicant *wpa_s, |
| 183 | struct wpa_ssid *ssid, |
| 184 | const struct wps_credential *cred) |
| 185 | { |
| 186 | struct wpa_driver_capa capa; |
| 187 | struct wpa_bss *bss; |
| 188 | const u8 *ie; |
| 189 | struct wpa_ie_data adv; |
| 190 | int wpa2 = 0, ccmp = 0; |
| 191 | |
| 192 | /* |
| 193 | * Many existing WPS APs do not know how to negotiate WPA2 or CCMP in |
| 194 | * case they are configured for mixed mode operation (WPA+WPA2 and |
| 195 | * TKIP+CCMP). Try to use scan results to figure out whether the AP |
| 196 | * actually supports stronger security and select that if the client |
| 197 | * has support for it, too. |
| 198 | */ |
| 199 | |
| 200 | if (wpa_drv_get_capa(wpa_s, &capa)) |
| 201 | return; /* Unknown what driver supports */ |
| 202 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 203 | if (ssid->ssid == NULL) |
| 204 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 205 | bss = wpa_bss_get(wpa_s, cred->mac_addr, ssid->ssid, ssid->ssid_len); |
| 206 | if (bss == NULL) { |
| 207 | wpa_printf(MSG_DEBUG, "WPS: The AP was not found from BSS " |
| 208 | "table - use credential as-is"); |
| 209 | return; |
| 210 | } |
| 211 | |
| 212 | wpa_printf(MSG_DEBUG, "WPS: AP found from BSS table"); |
| 213 | |
| 214 | ie = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
| 215 | if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0) { |
| 216 | wpa2 = 1; |
| 217 | if (adv.pairwise_cipher & WPA_CIPHER_CCMP) |
| 218 | ccmp = 1; |
| 219 | } else { |
| 220 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
| 221 | if (ie && wpa_parse_wpa_ie(ie, 2 + ie[1], &adv) == 0 && |
| 222 | adv.pairwise_cipher & WPA_CIPHER_CCMP) |
| 223 | ccmp = 1; |
| 224 | } |
| 225 | |
| 226 | if (ie == NULL && (ssid->proto & WPA_PROTO_WPA) && |
| 227 | (ssid->pairwise_cipher & WPA_CIPHER_TKIP)) { |
| 228 | /* |
| 229 | * TODO: This could be the initial AP configuration and the |
| 230 | * Beacon contents could change shortly. Should request a new |
| 231 | * scan and delay addition of the network until the updated |
| 232 | * scan results are available. |
| 233 | */ |
| 234 | wpa_printf(MSG_DEBUG, "WPS: The AP did not yet advertise WPA " |
| 235 | "support - use credential as-is"); |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | if (ccmp && !(ssid->pairwise_cipher & WPA_CIPHER_CCMP) && |
| 240 | (ssid->pairwise_cipher & WPA_CIPHER_TKIP) && |
| 241 | (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) { |
| 242 | wpa_printf(MSG_DEBUG, "WPS: Add CCMP into the credential " |
| 243 | "based on scan results"); |
| 244 | if (wpa_s->conf->ap_scan == 1) |
| 245 | ssid->pairwise_cipher |= WPA_CIPHER_CCMP; |
| 246 | else |
| 247 | ssid->pairwise_cipher = WPA_CIPHER_CCMP; |
| 248 | } |
| 249 | |
| 250 | if (wpa2 && !(ssid->proto & WPA_PROTO_RSN) && |
| 251 | (ssid->proto & WPA_PROTO_WPA) && |
| 252 | (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP)) { |
| 253 | wpa_printf(MSG_DEBUG, "WPS: Add WPA2 into the credential " |
| 254 | "based on scan results"); |
| 255 | if (wpa_s->conf->ap_scan == 1) |
| 256 | ssid->proto |= WPA_PROTO_RSN; |
| 257 | else |
| 258 | ssid->proto = WPA_PROTO_RSN; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 263 | static void wpas_wps_remove_dup_network(struct wpa_supplicant *wpa_s, |
| 264 | struct wpa_ssid *new_ssid) |
| 265 | { |
| 266 | struct wpa_ssid *ssid, *next; |
| 267 | |
| 268 | for (ssid = wpa_s->conf->ssid, next = ssid ? ssid->next : NULL; ssid; |
| 269 | ssid = next, next = ssid ? ssid->next : NULL) { |
| 270 | /* |
| 271 | * new_ssid has already been added to the list in |
| 272 | * wpas_wps_add_network(), so skip it. |
| 273 | */ |
| 274 | if (ssid == new_ssid) |
| 275 | continue; |
| 276 | |
| 277 | if (ssid->bssid_set || new_ssid->bssid_set) { |
| 278 | if (ssid->bssid_set != new_ssid->bssid_set) |
| 279 | continue; |
| 280 | if (os_memcmp(ssid->bssid, new_ssid->bssid, ETH_ALEN) != |
| 281 | 0) |
| 282 | continue; |
| 283 | } |
| 284 | |
| 285 | /* compare SSID */ |
| 286 | if (ssid->ssid_len == 0 || ssid->ssid_len != new_ssid->ssid_len) |
| 287 | continue; |
| 288 | |
| 289 | if (ssid->ssid && new_ssid->ssid) { |
| 290 | if (os_memcmp(ssid->ssid, new_ssid->ssid, |
| 291 | ssid->ssid_len) != 0) |
| 292 | continue; |
| 293 | } else if (ssid->ssid || new_ssid->ssid) |
| 294 | continue; |
| 295 | |
| 296 | /* compare security parameters */ |
| 297 | if (ssid->auth_alg != new_ssid->auth_alg || |
| 298 | ssid->key_mgmt != new_ssid->key_mgmt || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 299 | (ssid->group_cipher != new_ssid->group_cipher && |
| 300 | !(ssid->group_cipher & new_ssid->group_cipher & |
| 301 | WPA_CIPHER_CCMP))) |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 302 | continue; |
| 303 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 304 | /* |
| 305 | * Some existing WPS APs will send two creds in case they are |
| 306 | * configured for mixed mode operation (WPA+WPA2 and TKIP+CCMP). |
| 307 | * Try to merge these two creds if they are received in the same |
| 308 | * M8 message. |
| 309 | */ |
| 310 | if (ssid->wps_run && ssid->wps_run == new_ssid->wps_run && |
| 311 | wpa_key_mgmt_wpa_psk(ssid->key_mgmt)) { |
| 312 | if (new_ssid->passphrase && ssid->passphrase && |
| 313 | os_strcmp(new_ssid->passphrase, ssid->passphrase) != |
| 314 | 0) { |
| 315 | wpa_printf(MSG_DEBUG, |
| 316 | "WPS: M8 Creds with different passphrase - do not merge"); |
| 317 | continue; |
| 318 | } |
| 319 | |
| 320 | if (new_ssid->psk_set && |
| 321 | (!ssid->psk_set || |
| 322 | os_memcmp(new_ssid->psk, ssid->psk, 32) != 0)) { |
| 323 | wpa_printf(MSG_DEBUG, |
| 324 | "WPS: M8 Creds with different PSK - do not merge"); |
| 325 | continue; |
| 326 | } |
| 327 | |
| 328 | if ((new_ssid->passphrase && !ssid->passphrase) || |
| 329 | (!new_ssid->passphrase && ssid->passphrase)) { |
| 330 | wpa_printf(MSG_DEBUG, |
| 331 | "WPS: M8 Creds with different passphrase/PSK type - do not merge"); |
| 332 | continue; |
| 333 | } |
| 334 | |
| 335 | wpa_printf(MSG_DEBUG, |
| 336 | "WPS: Workaround - merge likely WPA/WPA2-mixed mode creds in same M8 message"); |
| 337 | new_ssid->proto |= ssid->proto; |
| 338 | new_ssid->pairwise_cipher |= ssid->pairwise_cipher; |
| 339 | } else { |
| 340 | /* |
| 341 | * proto and pairwise_cipher difference matter for |
| 342 | * non-mixed-mode creds. |
| 343 | */ |
| 344 | if (ssid->proto != new_ssid->proto || |
| 345 | ssid->pairwise_cipher != new_ssid->pairwise_cipher) |
| 346 | continue; |
| 347 | } |
| 348 | |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 349 | /* Remove the duplicated older network entry. */ |
| 350 | wpa_printf(MSG_DEBUG, "Remove duplicate network %d", ssid->id); |
| 351 | wpas_notify_network_removed(wpa_s, ssid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 352 | if (wpa_s->current_ssid == ssid) |
| 353 | wpa_s->current_ssid = NULL; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 354 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 359 | static int wpa_supplicant_wps_cred(void *ctx, |
| 360 | const struct wps_credential *cred) |
| 361 | { |
| 362 | struct wpa_supplicant *wpa_s = ctx; |
| 363 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 364 | u16 auth_type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 365 | #ifdef CONFIG_WPS_REG_DISABLE_OPEN |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 366 | int registrar = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 367 | #endif /* CONFIG_WPS_REG_DISABLE_OPEN */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 368 | |
| 369 | if ((wpa_s->conf->wps_cred_processing == 1 || |
| 370 | wpa_s->conf->wps_cred_processing == 2) && cred->cred_attr) { |
| 371 | size_t blen = cred->cred_attr_len * 2 + 1; |
| 372 | char *buf = os_malloc(blen); |
| 373 | if (buf) { |
| 374 | wpa_snprintf_hex(buf, blen, |
| 375 | cred->cred_attr, cred->cred_attr_len); |
| 376 | wpa_msg(wpa_s, MSG_INFO, "%s%s", |
| 377 | WPS_EVENT_CRED_RECEIVED, buf); |
| 378 | os_free(buf); |
| 379 | } |
| 380 | |
| 381 | wpas_notify_wps_credential(wpa_s, cred); |
| 382 | } else |
| 383 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_CRED_RECEIVED); |
| 384 | |
| 385 | wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute", |
| 386 | cred->cred_attr, cred->cred_attr_len); |
| 387 | |
| 388 | if (wpa_s->conf->wps_cred_processing == 1) |
| 389 | return 0; |
| 390 | |
| 391 | wpa_hexdump_ascii(MSG_DEBUG, "WPS: SSID", cred->ssid, cred->ssid_len); |
| 392 | wpa_printf(MSG_DEBUG, "WPS: Authentication Type 0x%x", |
| 393 | cred->auth_type); |
| 394 | wpa_printf(MSG_DEBUG, "WPS: Encryption Type 0x%x", cred->encr_type); |
| 395 | wpa_printf(MSG_DEBUG, "WPS: Network Key Index %d", cred->key_idx); |
| 396 | wpa_hexdump_key(MSG_DEBUG, "WPS: Network Key", |
| 397 | cred->key, cred->key_len); |
| 398 | wpa_printf(MSG_DEBUG, "WPS: MAC Address " MACSTR, |
| 399 | MAC2STR(cred->mac_addr)); |
| 400 | |
| 401 | auth_type = cred->auth_type; |
| 402 | if (auth_type == (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) { |
| 403 | wpa_printf(MSG_DEBUG, "WPS: Workaround - convert mixed-mode " |
| 404 | "auth_type into WPA2PSK"); |
| 405 | auth_type = WPS_AUTH_WPA2PSK; |
| 406 | } |
| 407 | |
| 408 | if (auth_type != WPS_AUTH_OPEN && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 409 | auth_type != WPS_AUTH_WPAPSK && |
| 410 | auth_type != WPS_AUTH_WPA2PSK) { |
| 411 | wpa_printf(MSG_DEBUG, "WPS: Ignored credentials for " |
| 412 | "unsupported authentication type 0x%x", |
| 413 | auth_type); |
| 414 | return 0; |
| 415 | } |
| 416 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 417 | if (auth_type == WPS_AUTH_WPAPSK || auth_type == WPS_AUTH_WPA2PSK) { |
| 418 | if (cred->key_len < 8 || cred->key_len > 2 * PMK_LEN) { |
| 419 | wpa_printf(MSG_ERROR, "WPS: Reject PSK credential with " |
| 420 | "invalid Network Key length %lu", |
| 421 | (unsigned long) cred->key_len); |
| 422 | return -1; |
| 423 | } |
| 424 | } |
| 425 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 426 | if (ssid && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) { |
| 427 | wpa_printf(MSG_DEBUG, "WPS: Replace WPS network block based " |
| 428 | "on the received credential"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 429 | #ifdef CONFIG_WPS_REG_DISABLE_OPEN |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 430 | if (ssid->eap.identity && |
| 431 | ssid->eap.identity_len == WSC_ID_REGISTRAR_LEN && |
| 432 | os_memcmp(ssid->eap.identity, WSC_ID_REGISTRAR, |
| 433 | WSC_ID_REGISTRAR_LEN) == 0) |
| 434 | registrar = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 435 | #endif /* CONFIG_WPS_REG_DISABLE_OPEN */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 436 | os_free(ssid->eap.identity); |
| 437 | ssid->eap.identity = NULL; |
| 438 | ssid->eap.identity_len = 0; |
| 439 | os_free(ssid->eap.phase1); |
| 440 | ssid->eap.phase1 = NULL; |
| 441 | os_free(ssid->eap.eap_methods); |
| 442 | ssid->eap.eap_methods = NULL; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 443 | if (!ssid->p2p_group) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 444 | ssid->temporary = 0; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 445 | ssid->bssid_set = 0; |
| 446 | } |
| 447 | ssid->disabled_until.sec = 0; |
| 448 | ssid->disabled_until.usec = 0; |
| 449 | ssid->auth_failures = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 450 | } else { |
| 451 | wpa_printf(MSG_DEBUG, "WPS: Create a new network based on the " |
| 452 | "received credential"); |
| 453 | ssid = wpa_config_add_network(wpa_s->conf); |
| 454 | if (ssid == NULL) |
| 455 | return -1; |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 456 | if (wpa_s->current_ssid) { |
| 457 | /* |
| 458 | * Should the GO issue multiple credentials for some |
| 459 | * reason, each credential should be marked as a |
| 460 | * temporary P2P group similarly to the one that gets |
| 461 | * marked as such based on the pre-configured values |
| 462 | * used for the WPS network block. |
| 463 | */ |
| 464 | ssid->p2p_group = wpa_s->current_ssid->p2p_group; |
| 465 | ssid->temporary = wpa_s->current_ssid->temporary; |
| 466 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 467 | wpas_notify_network_added(wpa_s, ssid); |
| 468 | } |
| 469 | |
| 470 | wpa_config_set_network_defaults(ssid); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 471 | ssid->wps_run = wpa_s->wps_run; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 472 | |
| 473 | os_free(ssid->ssid); |
| 474 | ssid->ssid = os_malloc(cred->ssid_len); |
| 475 | if (ssid->ssid) { |
| 476 | os_memcpy(ssid->ssid, cred->ssid, cred->ssid_len); |
| 477 | ssid->ssid_len = cred->ssid_len; |
| 478 | } |
| 479 | |
| 480 | switch (cred->encr_type) { |
| 481 | case WPS_ENCR_NONE: |
| 482 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 483 | case WPS_ENCR_TKIP: |
| 484 | ssid->pairwise_cipher = WPA_CIPHER_TKIP; |
| 485 | break; |
| 486 | case WPS_ENCR_AES: |
| 487 | ssid->pairwise_cipher = WPA_CIPHER_CCMP; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 488 | if (wpa_s->drv_capa_known && |
| 489 | (wpa_s->drv_enc & WPA_DRIVER_CAPA_ENC_GCMP)) { |
| 490 | ssid->pairwise_cipher |= WPA_CIPHER_GCMP; |
| 491 | ssid->group_cipher |= WPA_CIPHER_GCMP; |
| 492 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 493 | break; |
| 494 | } |
| 495 | |
| 496 | switch (auth_type) { |
| 497 | case WPS_AUTH_OPEN: |
| 498 | ssid->auth_alg = WPA_AUTH_ALG_OPEN; |
| 499 | ssid->key_mgmt = WPA_KEY_MGMT_NONE; |
| 500 | ssid->proto = 0; |
| 501 | #ifdef CONFIG_WPS_REG_DISABLE_OPEN |
| 502 | if (registrar) { |
| 503 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OPEN_NETWORK |
| 504 | "id=%d - Credentials for an open " |
| 505 | "network disabled by default - use " |
| 506 | "'select_network %d' to enable", |
| 507 | ssid->id, ssid->id); |
| 508 | ssid->disabled = 1; |
| 509 | } |
| 510 | #endif /* CONFIG_WPS_REG_DISABLE_OPEN */ |
| 511 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 512 | case WPS_AUTH_WPAPSK: |
| 513 | ssid->auth_alg = WPA_AUTH_ALG_OPEN; |
| 514 | ssid->key_mgmt = WPA_KEY_MGMT_PSK; |
| 515 | ssid->proto = WPA_PROTO_WPA; |
| 516 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 517 | case WPS_AUTH_WPA2PSK: |
| 518 | ssid->auth_alg = WPA_AUTH_ALG_OPEN; |
| 519 | ssid->key_mgmt = WPA_KEY_MGMT_PSK; |
| 520 | ssid->proto = WPA_PROTO_RSN; |
| 521 | break; |
| 522 | } |
| 523 | |
| 524 | if (ssid->key_mgmt == WPA_KEY_MGMT_PSK) { |
| 525 | if (cred->key_len == 2 * PMK_LEN) { |
| 526 | if (hexstr2bin((const char *) cred->key, ssid->psk, |
| 527 | PMK_LEN)) { |
| 528 | wpa_printf(MSG_ERROR, "WPS: Invalid Network " |
| 529 | "Key"); |
| 530 | return -1; |
| 531 | } |
| 532 | ssid->psk_set = 1; |
| 533 | ssid->export_keys = 1; |
| 534 | } else if (cred->key_len >= 8 && cred->key_len < 2 * PMK_LEN) { |
| 535 | os_free(ssid->passphrase); |
| 536 | ssid->passphrase = os_malloc(cred->key_len + 1); |
| 537 | if (ssid->passphrase == NULL) |
| 538 | return -1; |
| 539 | os_memcpy(ssid->passphrase, cred->key, cred->key_len); |
| 540 | ssid->passphrase[cred->key_len] = '\0'; |
| 541 | wpa_config_update_psk(ssid); |
| 542 | ssid->export_keys = 1; |
| 543 | } else { |
| 544 | wpa_printf(MSG_ERROR, "WPS: Invalid Network Key " |
| 545 | "length %lu", |
| 546 | (unsigned long) cred->key_len); |
| 547 | return -1; |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | wpas_wps_security_workaround(wpa_s, ssid, cred); |
| 552 | |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 553 | wpas_wps_remove_dup_network(wpa_s, ssid); |
| 554 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 555 | #ifndef CONFIG_NO_CONFIG_WRITE |
| 556 | if (wpa_s->conf->update_config && |
| 557 | wpa_config_write(wpa_s->confname, wpa_s->conf)) { |
| 558 | wpa_printf(MSG_DEBUG, "WPS: Failed to update configuration"); |
| 559 | return -1; |
| 560 | } |
| 561 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 562 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 563 | /* |
| 564 | * Optimize the post-WPS scan based on the channel used during |
| 565 | * the provisioning in case EAP-Failure is not received. |
| 566 | */ |
| 567 | wpa_s->after_wps = 5; |
| 568 | wpa_s->wps_freq = wpa_s->assoc_freq; |
| 569 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 570 | return 0; |
| 571 | } |
| 572 | |
| 573 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 574 | static void wpa_supplicant_wps_event_m2d(struct wpa_supplicant *wpa_s, |
| 575 | struct wps_event_m2d *m2d) |
| 576 | { |
| 577 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_M2D |
| 578 | "dev_password_id=%d config_error=%d", |
| 579 | m2d->dev_password_id, m2d->config_error); |
| 580 | wpas_notify_wps_event_m2d(wpa_s, m2d); |
| 581 | #ifdef CONFIG_P2P |
| 582 | if (wpa_s->parent && wpa_s->parent != wpa_s) { |
| 583 | wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_M2D |
| 584 | "dev_password_id=%d config_error=%d", |
| 585 | m2d->dev_password_id, m2d->config_error); |
| 586 | } |
| 587 | if (m2d->config_error == WPS_CFG_MULTIPLE_PBC_DETECTED) { |
| 588 | /* |
| 589 | * Notify P2P from eloop timeout to avoid issues with the |
| 590 | * interface getting removed while processing a message. |
| 591 | */ |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 592 | eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb, wpa_s, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 593 | NULL); |
| 594 | } |
| 595 | #endif /* CONFIG_P2P */ |
| 596 | } |
| 597 | |
| 598 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 599 | static void wpas_wps_clear_timeout(void *eloop_ctx, void *timeout_ctx) |
| 600 | { |
| 601 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 602 | wpa_printf(MSG_DEBUG, "WPS: Clear WPS network from timeout"); |
| 603 | wpas_clear_wps(wpa_s); |
| 604 | } |
| 605 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 606 | |
| 607 | static void wpa_supplicant_wps_event_fail(struct wpa_supplicant *wpa_s, |
| 608 | struct wps_event_fail *fail) |
| 609 | { |
| 610 | if (fail->error_indication > 0 && |
| 611 | fail->error_indication < NUM_WPS_EI_VALUES) { |
| 612 | wpa_msg(wpa_s, MSG_INFO, |
| 613 | WPS_EVENT_FAIL "msg=%d config_error=%d reason=%d (%s)", |
| 614 | fail->msg, fail->config_error, fail->error_indication, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 615 | wps_ei_str(fail->error_indication)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 616 | if (wpa_s->parent && wpa_s->parent != wpa_s) |
| 617 | wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL |
| 618 | "msg=%d config_error=%d reason=%d (%s)", |
| 619 | fail->msg, fail->config_error, |
| 620 | fail->error_indication, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 621 | wps_ei_str(fail->error_indication)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 622 | } else { |
| 623 | wpa_msg(wpa_s, MSG_INFO, |
| 624 | WPS_EVENT_FAIL "msg=%d config_error=%d", |
| 625 | fail->msg, fail->config_error); |
| 626 | if (wpa_s->parent && wpa_s->parent != wpa_s) |
| 627 | wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL |
| 628 | "msg=%d config_error=%d", |
| 629 | fail->msg, fail->config_error); |
| 630 | } |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 631 | |
| 632 | /* |
| 633 | * Need to allow WPS processing to complete, e.g., by sending WSC_NACK. |
| 634 | */ |
| 635 | wpa_printf(MSG_DEBUG, "WPS: Register timeout to clear WPS network"); |
| 636 | eloop_cancel_timeout(wpas_wps_clear_timeout, wpa_s, NULL); |
| 637 | eloop_register_timeout(0, 100000, wpas_wps_clear_timeout, wpa_s, NULL); |
| 638 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 639 | wpas_notify_wps_event_fail(wpa_s, fail); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 640 | wpas_p2p_wps_failed(wpa_s, fail); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 644 | static void wpas_wps_reenable_networks_cb(void *eloop_ctx, void *timeout_ctx); |
| 645 | |
| 646 | static void wpas_wps_reenable_networks(struct wpa_supplicant *wpa_s) |
| 647 | { |
| 648 | struct wpa_ssid *ssid; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 649 | int changed = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 650 | |
| 651 | eloop_cancel_timeout(wpas_wps_reenable_networks_cb, wpa_s, NULL); |
| 652 | |
| 653 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 654 | if (ssid->disabled_for_connect && ssid->disabled) { |
| 655 | ssid->disabled_for_connect = 0; |
| 656 | ssid->disabled = 0; |
| 657 | wpas_notify_network_enabled_changed(wpa_s, ssid); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 658 | changed++; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 659 | } |
| 660 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 661 | |
| 662 | if (changed) { |
| 663 | #ifndef CONFIG_NO_CONFIG_WRITE |
| 664 | if (wpa_s->conf->update_config && |
| 665 | wpa_config_write(wpa_s->confname, wpa_s->conf)) { |
| 666 | wpa_printf(MSG_DEBUG, "WPS: Failed to update " |
| 667 | "configuration"); |
| 668 | } |
| 669 | #endif /* CONFIG_NO_CONFIG_WRITE */ |
| 670 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | |
| 674 | static void wpas_wps_reenable_networks_cb(void *eloop_ctx, void *timeout_ctx) |
| 675 | { |
| 676 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 677 | /* Enable the networks disabled during wpas_wps_reassoc */ |
| 678 | wpas_wps_reenable_networks(wpa_s); |
| 679 | } |
| 680 | |
| 681 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 682 | static void wpa_supplicant_wps_event_success(struct wpa_supplicant *wpa_s) |
| 683 | { |
| 684 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_SUCCESS); |
| 685 | wpa_s->wps_success = 1; |
| 686 | wpas_notify_wps_event_success(wpa_s); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 687 | if (wpa_s->current_ssid) |
| 688 | wpas_clear_temp_disabled(wpa_s, wpa_s->current_ssid, 1); |
| 689 | wpa_s->extra_blacklist_count = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 690 | |
| 691 | /* |
| 692 | * Enable the networks disabled during wpas_wps_reassoc after 10 |
| 693 | * seconds. The 10 seconds timer is to allow the data connection to be |
| 694 | * formed before allowing other networks to be selected. |
| 695 | */ |
| 696 | eloop_register_timeout(10, 0, wpas_wps_reenable_networks_cb, wpa_s, |
| 697 | NULL); |
| 698 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 699 | wpas_p2p_wps_success(wpa_s, wpa_s->bssid, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | |
| 703 | static void wpa_supplicant_wps_event_er_ap_add(struct wpa_supplicant *wpa_s, |
| 704 | struct wps_event_er_ap *ap) |
| 705 | { |
| 706 | char uuid_str[100]; |
| 707 | char dev_type[WPS_DEV_TYPE_BUFSIZE]; |
| 708 | |
| 709 | uuid_bin2str(ap->uuid, uuid_str, sizeof(uuid_str)); |
| 710 | if (ap->pri_dev_type) |
| 711 | wps_dev_type_bin2str(ap->pri_dev_type, dev_type, |
| 712 | sizeof(dev_type)); |
| 713 | else |
| 714 | dev_type[0] = '\0'; |
| 715 | |
| 716 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_ADD "%s " MACSTR |
| 717 | " pri_dev_type=%s wps_state=%d |%s|%s|%s|%s|%s|%s|", |
| 718 | uuid_str, MAC2STR(ap->mac_addr), dev_type, ap->wps_state, |
| 719 | ap->friendly_name ? ap->friendly_name : "", |
| 720 | ap->manufacturer ? ap->manufacturer : "", |
| 721 | ap->model_description ? ap->model_description : "", |
| 722 | ap->model_name ? ap->model_name : "", |
| 723 | ap->manufacturer_url ? ap->manufacturer_url : "", |
| 724 | ap->model_url ? ap->model_url : ""); |
| 725 | } |
| 726 | |
| 727 | |
| 728 | static void wpa_supplicant_wps_event_er_ap_remove(struct wpa_supplicant *wpa_s, |
| 729 | struct wps_event_er_ap *ap) |
| 730 | { |
| 731 | char uuid_str[100]; |
| 732 | uuid_bin2str(ap->uuid, uuid_str, sizeof(uuid_str)); |
| 733 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_REMOVE "%s", uuid_str); |
| 734 | } |
| 735 | |
| 736 | |
| 737 | static void wpa_supplicant_wps_event_er_enrollee_add( |
| 738 | struct wpa_supplicant *wpa_s, struct wps_event_er_enrollee *enrollee) |
| 739 | { |
| 740 | char uuid_str[100]; |
| 741 | char dev_type[WPS_DEV_TYPE_BUFSIZE]; |
| 742 | |
| 743 | uuid_bin2str(enrollee->uuid, uuid_str, sizeof(uuid_str)); |
| 744 | if (enrollee->pri_dev_type) |
| 745 | wps_dev_type_bin2str(enrollee->pri_dev_type, dev_type, |
| 746 | sizeof(dev_type)); |
| 747 | else |
| 748 | dev_type[0] = '\0'; |
| 749 | |
| 750 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_ENROLLEE_ADD "%s " MACSTR |
| 751 | " M1=%d config_methods=0x%x dev_passwd_id=%d pri_dev_type=%s " |
| 752 | "|%s|%s|%s|%s|%s|", |
| 753 | uuid_str, MAC2STR(enrollee->mac_addr), enrollee->m1_received, |
| 754 | enrollee->config_methods, enrollee->dev_passwd_id, dev_type, |
| 755 | enrollee->dev_name ? enrollee->dev_name : "", |
| 756 | enrollee->manufacturer ? enrollee->manufacturer : "", |
| 757 | enrollee->model_name ? enrollee->model_name : "", |
| 758 | enrollee->model_number ? enrollee->model_number : "", |
| 759 | enrollee->serial_number ? enrollee->serial_number : ""); |
| 760 | } |
| 761 | |
| 762 | |
| 763 | static void wpa_supplicant_wps_event_er_enrollee_remove( |
| 764 | struct wpa_supplicant *wpa_s, struct wps_event_er_enrollee *enrollee) |
| 765 | { |
| 766 | char uuid_str[100]; |
| 767 | uuid_bin2str(enrollee->uuid, uuid_str, sizeof(uuid_str)); |
| 768 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_ENROLLEE_REMOVE "%s " MACSTR, |
| 769 | uuid_str, MAC2STR(enrollee->mac_addr)); |
| 770 | } |
| 771 | |
| 772 | |
| 773 | static void wpa_supplicant_wps_event_er_ap_settings( |
| 774 | struct wpa_supplicant *wpa_s, |
| 775 | struct wps_event_er_ap_settings *ap_settings) |
| 776 | { |
| 777 | char uuid_str[100]; |
| 778 | char key_str[65]; |
| 779 | const struct wps_credential *cred = ap_settings->cred; |
| 780 | |
| 781 | key_str[0] = '\0'; |
| 782 | if (cred->auth_type & (WPS_AUTH_WPAPSK | WPS_AUTH_WPA2PSK)) { |
| 783 | if (cred->key_len >= 8 && cred->key_len <= 64) { |
| 784 | os_memcpy(key_str, cred->key, cred->key_len); |
| 785 | key_str[cred->key_len] = '\0'; |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | uuid_bin2str(ap_settings->uuid, uuid_str, sizeof(uuid_str)); |
| 790 | /* Use wpa_msg_ctrl to avoid showing the key in debug log */ |
| 791 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_ER_AP_SETTINGS |
| 792 | "uuid=%s ssid=%s auth_type=0x%04x encr_type=0x%04x " |
| 793 | "key=%s", |
| 794 | uuid_str, wpa_ssid_txt(cred->ssid, cred->ssid_len), |
| 795 | cred->auth_type, cred->encr_type, key_str); |
| 796 | } |
| 797 | |
| 798 | |
| 799 | static void wpa_supplicant_wps_event_er_set_sel_reg( |
| 800 | struct wpa_supplicant *wpa_s, |
| 801 | struct wps_event_er_set_selected_registrar *ev) |
| 802 | { |
| 803 | char uuid_str[100]; |
| 804 | |
| 805 | uuid_bin2str(ev->uuid, uuid_str, sizeof(uuid_str)); |
| 806 | switch (ev->state) { |
| 807 | case WPS_ER_SET_SEL_REG_START: |
| 808 | wpa_msg(wpa_s, MSG_DEBUG, WPS_EVENT_ER_SET_SEL_REG |
| 809 | "uuid=%s state=START sel_reg=%d dev_passwd_id=%u " |
| 810 | "sel_reg_config_methods=0x%x", |
| 811 | uuid_str, ev->sel_reg, ev->dev_passwd_id, |
| 812 | ev->sel_reg_config_methods); |
| 813 | break; |
| 814 | case WPS_ER_SET_SEL_REG_DONE: |
| 815 | wpa_msg(wpa_s, MSG_DEBUG, WPS_EVENT_ER_SET_SEL_REG |
| 816 | "uuid=%s state=DONE", uuid_str); |
| 817 | break; |
| 818 | case WPS_ER_SET_SEL_REG_FAILED: |
| 819 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ER_SET_SEL_REG |
| 820 | "uuid=%s state=FAILED", uuid_str); |
| 821 | break; |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | |
| 826 | static void wpa_supplicant_wps_event(void *ctx, enum wps_event event, |
| 827 | union wps_event_data *data) |
| 828 | { |
| 829 | struct wpa_supplicant *wpa_s = ctx; |
| 830 | switch (event) { |
| 831 | case WPS_EV_M2D: |
| 832 | wpa_supplicant_wps_event_m2d(wpa_s, &data->m2d); |
| 833 | break; |
| 834 | case WPS_EV_FAIL: |
| 835 | wpa_supplicant_wps_event_fail(wpa_s, &data->fail); |
| 836 | break; |
| 837 | case WPS_EV_SUCCESS: |
| 838 | wpa_supplicant_wps_event_success(wpa_s); |
| 839 | break; |
| 840 | case WPS_EV_PWD_AUTH_FAIL: |
| 841 | #ifdef CONFIG_AP |
| 842 | if (wpa_s->ap_iface && data->pwd_auth_fail.enrollee) |
| 843 | wpa_supplicant_ap_pwd_auth_fail(wpa_s); |
| 844 | #endif /* CONFIG_AP */ |
| 845 | break; |
| 846 | case WPS_EV_PBC_OVERLAP: |
| 847 | break; |
| 848 | case WPS_EV_PBC_TIMEOUT: |
| 849 | break; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 850 | case WPS_EV_PBC_ACTIVE: |
| 851 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_ACTIVE); |
| 852 | break; |
| 853 | case WPS_EV_PBC_DISABLE: |
| 854 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_DISABLE); |
| 855 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 856 | case WPS_EV_ER_AP_ADD: |
| 857 | wpa_supplicant_wps_event_er_ap_add(wpa_s, &data->ap); |
| 858 | break; |
| 859 | case WPS_EV_ER_AP_REMOVE: |
| 860 | wpa_supplicant_wps_event_er_ap_remove(wpa_s, &data->ap); |
| 861 | break; |
| 862 | case WPS_EV_ER_ENROLLEE_ADD: |
| 863 | wpa_supplicant_wps_event_er_enrollee_add(wpa_s, |
| 864 | &data->enrollee); |
| 865 | break; |
| 866 | case WPS_EV_ER_ENROLLEE_REMOVE: |
| 867 | wpa_supplicant_wps_event_er_enrollee_remove(wpa_s, |
| 868 | &data->enrollee); |
| 869 | break; |
| 870 | case WPS_EV_ER_AP_SETTINGS: |
| 871 | wpa_supplicant_wps_event_er_ap_settings(wpa_s, |
| 872 | &data->ap_settings); |
| 873 | break; |
| 874 | case WPS_EV_ER_SET_SELECTED_REGISTRAR: |
| 875 | wpa_supplicant_wps_event_er_set_sel_reg(wpa_s, |
| 876 | &data->set_sel_reg); |
| 877 | break; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 878 | case WPS_EV_AP_PIN_SUCCESS: |
| 879 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 880 | } |
| 881 | } |
| 882 | |
| 883 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 884 | static int wpa_supplicant_wps_rf_band(void *ctx) |
| 885 | { |
| 886 | struct wpa_supplicant *wpa_s = ctx; |
| 887 | |
| 888 | if (!wpa_s->current_ssid || !wpa_s->assoc_freq) |
| 889 | return 0; |
| 890 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame^] | 891 | return (wpa_s->assoc_freq > 50000) ? WPS_RF_60GHZ : |
| 892 | (wpa_s->assoc_freq > 2484) ? WPS_RF_50GHZ : WPS_RF_24GHZ; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 896 | enum wps_request_type wpas_wps_get_req_type(struct wpa_ssid *ssid) |
| 897 | { |
| 898 | if (eap_is_wps_pbc_enrollee(&ssid->eap) || |
| 899 | eap_is_wps_pin_enrollee(&ssid->eap)) |
| 900 | return WPS_REQ_ENROLLEE; |
| 901 | else |
| 902 | return WPS_REQ_REGISTRAR; |
| 903 | } |
| 904 | |
| 905 | |
| 906 | static void wpas_clear_wps(struct wpa_supplicant *wpa_s) |
| 907 | { |
| 908 | int id; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 909 | struct wpa_ssid *ssid, *remove_ssid = NULL, *prev_current; |
| 910 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 911 | wpa_s->after_wps = 0; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 912 | wpa_s->known_wps_freq = 0; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 913 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 914 | prev_current = wpa_s->current_ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 915 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 916 | /* Enable the networks disabled during wpas_wps_reassoc */ |
| 917 | wpas_wps_reenable_networks(wpa_s); |
| 918 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 919 | eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 920 | eloop_cancel_timeout(wpas_wps_clear_timeout, wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 921 | |
| 922 | /* Remove any existing WPS network from configuration */ |
| 923 | ssid = wpa_s->conf->ssid; |
| 924 | while (ssid) { |
| 925 | if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) { |
| 926 | if (ssid == wpa_s->current_ssid) { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 927 | wpa_s->own_disconnect_req = 1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 928 | wpa_supplicant_deauthenticate( |
| 929 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 930 | } |
| 931 | id = ssid->id; |
| 932 | remove_ssid = ssid; |
| 933 | } else |
| 934 | id = -1; |
| 935 | ssid = ssid->next; |
| 936 | if (id >= 0) { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 937 | if (prev_current == remove_ssid) { |
| 938 | wpa_sm_set_config(wpa_s->wpa, NULL); |
| 939 | eapol_sm_notify_config(wpa_s->eapol, NULL, |
| 940 | NULL); |
| 941 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 942 | wpas_notify_network_removed(wpa_s, remove_ssid); |
| 943 | wpa_config_remove_network(wpa_s->conf, id); |
| 944 | } |
| 945 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 946 | |
| 947 | wpas_wps_clear_ap_info(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | |
| 951 | static void wpas_wps_timeout(void *eloop_ctx, void *timeout_ctx) |
| 952 | { |
| 953 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 954 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_TIMEOUT "Requested operation timed " |
| 955 | "out"); |
| 956 | wpas_clear_wps(wpa_s); |
| 957 | } |
| 958 | |
| 959 | |
| 960 | static struct wpa_ssid * wpas_wps_add_network(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 961 | int registrar, const u8 *dev_addr, |
| 962 | const u8 *bssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 963 | { |
| 964 | struct wpa_ssid *ssid; |
| 965 | |
| 966 | ssid = wpa_config_add_network(wpa_s->conf); |
| 967 | if (ssid == NULL) |
| 968 | return NULL; |
| 969 | wpas_notify_network_added(wpa_s, ssid); |
| 970 | wpa_config_set_network_defaults(ssid); |
| 971 | ssid->temporary = 1; |
| 972 | if (wpa_config_set(ssid, "key_mgmt", "WPS", 0) < 0 || |
| 973 | wpa_config_set(ssid, "eap", "WSC", 0) < 0 || |
| 974 | wpa_config_set(ssid, "identity", registrar ? |
| 975 | "\"" WSC_ID_REGISTRAR "\"" : |
| 976 | "\"" WSC_ID_ENROLLEE "\"", 0) < 0) { |
| 977 | wpas_notify_network_removed(wpa_s, ssid); |
| 978 | wpa_config_remove_network(wpa_s->conf, ssid->id); |
| 979 | return NULL; |
| 980 | } |
| 981 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 982 | #ifdef CONFIG_P2P |
| 983 | if (dev_addr) |
| 984 | os_memcpy(ssid->go_p2p_dev_addr, dev_addr, ETH_ALEN); |
| 985 | #endif /* CONFIG_P2P */ |
| 986 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 987 | if (bssid) { |
| 988 | #ifndef CONFIG_P2P |
| 989 | struct wpa_bss *bss; |
| 990 | int count = 0; |
| 991 | #endif /* CONFIG_P2P */ |
| 992 | |
| 993 | os_memcpy(ssid->bssid, bssid, ETH_ALEN); |
| 994 | ssid->bssid_set = 1; |
| 995 | |
| 996 | /* |
| 997 | * Note: With P2P, the SSID may change at the time the WPS |
| 998 | * provisioning is started, so better not filter the AP based |
| 999 | * on the current SSID in the scan results. |
| 1000 | */ |
| 1001 | #ifndef CONFIG_P2P |
| 1002 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
| 1003 | if (os_memcmp(bssid, bss->bssid, ETH_ALEN) != 0) |
| 1004 | continue; |
| 1005 | |
| 1006 | os_free(ssid->ssid); |
| 1007 | ssid->ssid = os_malloc(bss->ssid_len); |
| 1008 | if (ssid->ssid == NULL) |
| 1009 | break; |
| 1010 | os_memcpy(ssid->ssid, bss->ssid, bss->ssid_len); |
| 1011 | ssid->ssid_len = bss->ssid_len; |
| 1012 | wpa_hexdump_ascii(MSG_DEBUG, "WPS: Picked SSID from " |
| 1013 | "scan results", |
| 1014 | ssid->ssid, ssid->ssid_len); |
| 1015 | count++; |
| 1016 | } |
| 1017 | |
| 1018 | if (count > 1) { |
| 1019 | wpa_printf(MSG_DEBUG, "WPS: More than one SSID found " |
| 1020 | "for the AP; use wildcard"); |
| 1021 | os_free(ssid->ssid); |
| 1022 | ssid->ssid = NULL; |
| 1023 | ssid->ssid_len = 0; |
| 1024 | } |
| 1025 | #endif /* CONFIG_P2P */ |
| 1026 | } |
| 1027 | |
| 1028 | return ssid; |
| 1029 | } |
| 1030 | |
| 1031 | |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1032 | static void wpas_wps_temp_disable(struct wpa_supplicant *wpa_s, |
| 1033 | struct wpa_ssid *selected) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1034 | { |
| 1035 | struct wpa_ssid *ssid; |
| 1036 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1037 | if (wpa_s->current_ssid) { |
| 1038 | wpa_s->own_disconnect_req = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1039 | wpa_supplicant_deauthenticate( |
| 1040 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1041 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1042 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1043 | /* Mark all other networks disabled and trigger reassociation */ |
| 1044 | ssid = wpa_s->conf->ssid; |
| 1045 | while (ssid) { |
| 1046 | int was_disabled = ssid->disabled; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1047 | ssid->disabled_for_connect = 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1048 | /* |
| 1049 | * In case the network object corresponds to a persistent group |
| 1050 | * then do not send out network disabled signal. In addition, |
| 1051 | * do not change disabled status of persistent network objects |
| 1052 | * from 2 to 1 should we connect to another network. |
| 1053 | */ |
| 1054 | if (was_disabled != 2) { |
| 1055 | ssid->disabled = ssid != selected; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1056 | if (was_disabled != ssid->disabled) { |
| 1057 | if (ssid->disabled) |
| 1058 | ssid->disabled_for_connect = 1; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1059 | wpas_notify_network_enabled_changed(wpa_s, |
| 1060 | ssid); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1061 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1062 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1063 | ssid = ssid->next; |
| 1064 | } |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | |
| 1068 | static void wpas_wps_reassoc(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1069 | struct wpa_ssid *selected, const u8 *bssid, |
| 1070 | int freq) |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1071 | { |
| 1072 | struct wpa_bss *bss; |
| 1073 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1074 | wpa_s->wps_run++; |
| 1075 | if (wpa_s->wps_run == 0) |
| 1076 | wpa_s->wps_run++; |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1077 | wpa_s->after_wps = 0; |
| 1078 | wpa_s->known_wps_freq = 0; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1079 | if (freq) { |
| 1080 | wpa_s->after_wps = 5; |
| 1081 | wpa_s->wps_freq = freq; |
| 1082 | } else if (bssid) { |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 1083 | bss = wpa_bss_get_bssid_latest(wpa_s, bssid); |
| 1084 | if (bss && bss->freq > 0) { |
| 1085 | wpa_s->known_wps_freq = 1; |
| 1086 | wpa_s->wps_freq = bss->freq; |
| 1087 | } |
| 1088 | } |
| 1089 | |
| 1090 | wpas_wps_temp_disable(wpa_s, selected); |
| 1091 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1092 | wpa_s->disconnected = 0; |
| 1093 | wpa_s->reassociate = 1; |
| 1094 | wpa_s->scan_runs = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1095 | wpa_s->normal_scans = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1096 | wpa_s->wps_success = 0; |
| 1097 | wpa_s->blacklist_cleared = 0; |
Dmitry Shmidt | fa3fc4a | 2013-11-21 13:34:38 -0800 | [diff] [blame] | 1098 | |
| 1099 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1100 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 1101 | } |
| 1102 | |
| 1103 | |
| 1104 | int wpas_wps_start_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid, |
| 1105 | int p2p_group) |
| 1106 | { |
| 1107 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1108 | |
| 1109 | #ifdef CONFIG_AP |
| 1110 | if (wpa_s->ap_iface) { |
| 1111 | wpa_printf(MSG_DEBUG, |
| 1112 | "WPS: Reject request to start Registrar(as station) operation while AP mode is enabled"); |
| 1113 | return -1; |
| 1114 | } |
| 1115 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1116 | wpas_clear_wps(wpa_s); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1117 | ssid = wpas_wps_add_network(wpa_s, 0, NULL, bssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1118 | if (ssid == NULL) |
| 1119 | return -1; |
| 1120 | ssid->temporary = 1; |
| 1121 | ssid->p2p_group = p2p_group; |
| 1122 | #ifdef CONFIG_P2P |
| 1123 | if (p2p_group && wpa_s->go_params && wpa_s->go_params->ssid_len) { |
| 1124 | ssid->ssid = os_zalloc(wpa_s->go_params->ssid_len + 1); |
| 1125 | if (ssid->ssid) { |
| 1126 | ssid->ssid_len = wpa_s->go_params->ssid_len; |
| 1127 | os_memcpy(ssid->ssid, wpa_s->go_params->ssid, |
| 1128 | ssid->ssid_len); |
| 1129 | wpa_hexdump_ascii(MSG_DEBUG, "WPS: Use specific AP " |
| 1130 | "SSID", ssid->ssid, ssid->ssid_len); |
| 1131 | } |
| 1132 | } |
| 1133 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1134 | if (wpa_config_set(ssid, "phase1", "\"pbc=1\"", 0) < 0) |
| 1135 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1136 | if (wpa_s->wps_fragment_size) |
| 1137 | ssid->eap.fragment_size = wpa_s->wps_fragment_size; |
| 1138 | eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout, |
| 1139 | wpa_s, NULL); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1140 | wpas_wps_reassoc(wpa_s, ssid, bssid, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1141 | return 0; |
| 1142 | } |
| 1143 | |
| 1144 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1145 | static int wpas_wps_start_dev_pw(struct wpa_supplicant *wpa_s, |
| 1146 | const u8 *dev_addr, const u8 *bssid, |
| 1147 | const char *pin, int p2p_group, u16 dev_pw_id, |
| 1148 | const u8 *peer_pubkey_hash, |
| 1149 | const u8 *ssid_val, size_t ssid_len, int freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1150 | { |
| 1151 | struct wpa_ssid *ssid; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1152 | char val[128 + 2 * WPS_OOB_PUBKEY_HASH_LEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1153 | unsigned int rpin = 0; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1154 | char hash[2 * WPS_OOB_PUBKEY_HASH_LEN + 10]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1155 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1156 | #ifdef CONFIG_AP |
| 1157 | if (wpa_s->ap_iface) { |
| 1158 | wpa_printf(MSG_DEBUG, |
| 1159 | "WPS: Reject request to start Registrar(as station) operation while AP mode is enabled"); |
| 1160 | return -1; |
| 1161 | } |
| 1162 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1163 | wpas_clear_wps(wpa_s); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1164 | if (bssid && is_zero_ether_addr(bssid)) |
| 1165 | bssid = NULL; |
| 1166 | ssid = wpas_wps_add_network(wpa_s, 0, dev_addr, bssid); |
| 1167 | if (ssid == NULL) { |
| 1168 | wpa_printf(MSG_DEBUG, "WPS: Could not add network"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1169 | return -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1170 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1171 | ssid->temporary = 1; |
| 1172 | ssid->p2p_group = p2p_group; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1173 | if (ssid_val) { |
| 1174 | ssid->ssid = os_malloc(ssid_len); |
| 1175 | if (ssid->ssid) { |
| 1176 | os_memcpy(ssid->ssid, ssid_val, ssid_len); |
| 1177 | ssid->ssid_len = ssid_len; |
| 1178 | } |
| 1179 | } |
| 1180 | if (peer_pubkey_hash) { |
| 1181 | os_memcpy(hash, " pkhash=", 8); |
| 1182 | wpa_snprintf_hex_uppercase(hash + 8, sizeof(hash) - 8, |
| 1183 | peer_pubkey_hash, |
| 1184 | WPS_OOB_PUBKEY_HASH_LEN); |
| 1185 | } else { |
| 1186 | hash[0] = '\0'; |
| 1187 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1188 | #ifdef CONFIG_P2P |
| 1189 | if (p2p_group && wpa_s->go_params && wpa_s->go_params->ssid_len) { |
| 1190 | ssid->ssid = os_zalloc(wpa_s->go_params->ssid_len + 1); |
| 1191 | if (ssid->ssid) { |
| 1192 | ssid->ssid_len = wpa_s->go_params->ssid_len; |
| 1193 | os_memcpy(ssid->ssid, wpa_s->go_params->ssid, |
| 1194 | ssid->ssid_len); |
| 1195 | wpa_hexdump_ascii(MSG_DEBUG, "WPS: Use specific AP " |
| 1196 | "SSID", ssid->ssid, ssid->ssid_len); |
| 1197 | } |
| 1198 | } |
| 1199 | #endif /* CONFIG_P2P */ |
| 1200 | if (pin) |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1201 | os_snprintf(val, sizeof(val), "\"pin=%s dev_pw_id=%u%s\"", |
| 1202 | pin, dev_pw_id, hash); |
| 1203 | else if (pin == NULL && dev_pw_id == DEV_PW_NFC_CONNECTION_HANDOVER) { |
| 1204 | os_snprintf(val, sizeof(val), "\"dev_pw_id=%u%s\"", |
| 1205 | dev_pw_id, hash); |
| 1206 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1207 | rpin = wps_generate_pin(); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1208 | os_snprintf(val, sizeof(val), "\"pin=%08d dev_pw_id=%u%s\"", |
| 1209 | rpin, dev_pw_id, hash); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1210 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1211 | if (wpa_config_set(ssid, "phase1", val, 0) < 0) { |
| 1212 | wpa_printf(MSG_DEBUG, "WPS: Failed to set phase1 '%s'", val); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1213 | return -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1214 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1215 | if (wpa_s->wps_fragment_size) |
| 1216 | ssid->eap.fragment_size = wpa_s->wps_fragment_size; |
| 1217 | eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout, |
| 1218 | wpa_s, NULL); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1219 | wpa_s->wps_ap_iter = 1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1220 | wpas_wps_reassoc(wpa_s, ssid, bssid, freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1221 | return rpin; |
| 1222 | } |
| 1223 | |
| 1224 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1225 | int wpas_wps_start_pin(struct wpa_supplicant *wpa_s, const u8 *bssid, |
| 1226 | const char *pin, int p2p_group, u16 dev_pw_id) |
| 1227 | { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame^] | 1228 | os_get_reltime(&wpa_s->wps_pin_start_time); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1229 | return wpas_wps_start_dev_pw(wpa_s, NULL, bssid, pin, p2p_group, |
| 1230 | dev_pw_id, NULL, NULL, 0, 0); |
| 1231 | } |
| 1232 | |
| 1233 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1234 | /* Cancel the wps pbc/pin requests */ |
| 1235 | int wpas_wps_cancel(struct wpa_supplicant *wpa_s) |
| 1236 | { |
| 1237 | #ifdef CONFIG_AP |
| 1238 | if (wpa_s->ap_iface) { |
| 1239 | wpa_printf(MSG_DEBUG, "WPS: Cancelling in AP mode"); |
| 1240 | return wpa_supplicant_ap_wps_cancel(wpa_s); |
| 1241 | } |
| 1242 | #endif /* CONFIG_AP */ |
| 1243 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1244 | if (wpa_s->wpa_state == WPA_SCANNING || |
| 1245 | wpa_s->wpa_state == WPA_DISCONNECTED) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1246 | wpa_printf(MSG_DEBUG, "WPS: Cancel operation - cancel scan"); |
| 1247 | wpa_supplicant_cancel_scan(wpa_s); |
| 1248 | wpas_clear_wps(wpa_s); |
| 1249 | } else if (wpa_s->wpa_state >= WPA_ASSOCIATED) { |
| 1250 | wpa_printf(MSG_DEBUG, "WPS: Cancel operation - " |
| 1251 | "deauthenticate"); |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1252 | wpa_s->own_disconnect_req = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1253 | wpa_supplicant_deauthenticate(wpa_s, |
| 1254 | WLAN_REASON_DEAUTH_LEAVING); |
| 1255 | wpas_clear_wps(wpa_s); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1256 | } else { |
| 1257 | wpas_wps_reenable_networks(wpa_s); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1258 | wpas_wps_clear_ap_info(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1259 | if (eloop_cancel_timeout(wpas_wps_clear_timeout, wpa_s, NULL) > |
| 1260 | 0) |
| 1261 | wpas_clear_wps(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1264 | wpa_s->after_wps = 0; |
| 1265 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1266 | return 0; |
| 1267 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1268 | |
| 1269 | |
| 1270 | int wpas_wps_start_reg(struct wpa_supplicant *wpa_s, const u8 *bssid, |
| 1271 | const char *pin, struct wps_new_ap_settings *settings) |
| 1272 | { |
| 1273 | struct wpa_ssid *ssid; |
| 1274 | char val[200]; |
| 1275 | char *pos, *end; |
| 1276 | int res; |
| 1277 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1278 | #ifdef CONFIG_AP |
| 1279 | if (wpa_s->ap_iface) { |
| 1280 | wpa_printf(MSG_DEBUG, |
| 1281 | "WPS: Reject request to start Registrar(as station) operation while AP mode is enabled"); |
| 1282 | return -1; |
| 1283 | } |
| 1284 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1285 | if (!pin) |
| 1286 | return -1; |
| 1287 | wpas_clear_wps(wpa_s); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1288 | ssid = wpas_wps_add_network(wpa_s, 1, NULL, bssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1289 | if (ssid == NULL) |
| 1290 | return -1; |
| 1291 | ssid->temporary = 1; |
| 1292 | pos = val; |
| 1293 | end = pos + sizeof(val); |
| 1294 | res = os_snprintf(pos, end - pos, "\"pin=%s", pin); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1295 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1296 | return -1; |
| 1297 | pos += res; |
| 1298 | if (settings) { |
| 1299 | res = os_snprintf(pos, end - pos, " new_ssid=%s new_auth=%s " |
| 1300 | "new_encr=%s new_key=%s", |
| 1301 | settings->ssid_hex, settings->auth, |
| 1302 | settings->encr, settings->key_hex); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1303 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1304 | return -1; |
| 1305 | pos += res; |
| 1306 | } |
| 1307 | res = os_snprintf(pos, end - pos, "\""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1308 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1309 | return -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1310 | if (wpa_config_set(ssid, "phase1", val, 0) < 0) |
| 1311 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1312 | if (wpa_s->wps_fragment_size) |
| 1313 | ssid->eap.fragment_size = wpa_s->wps_fragment_size; |
| 1314 | eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wpas_wps_timeout, |
| 1315 | wpa_s, NULL); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1316 | wpas_wps_reassoc(wpa_s, ssid, bssid, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1317 | return 0; |
| 1318 | } |
| 1319 | |
| 1320 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1321 | static int wpas_wps_new_psk_cb(void *ctx, const u8 *mac_addr, |
| 1322 | const u8 *p2p_dev_addr, const u8 *psk, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1323 | size_t psk_len) |
| 1324 | { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1325 | if (is_zero_ether_addr(p2p_dev_addr)) { |
| 1326 | wpa_printf(MSG_DEBUG, |
| 1327 | "Received new WPA/WPA2-PSK from WPS for STA " MACSTR, |
| 1328 | MAC2STR(mac_addr)); |
| 1329 | } else { |
| 1330 | wpa_printf(MSG_DEBUG, |
| 1331 | "Received new WPA/WPA2-PSK from WPS for STA " MACSTR |
| 1332 | " P2P Device Addr " MACSTR, |
| 1333 | MAC2STR(mac_addr), MAC2STR(p2p_dev_addr)); |
| 1334 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1335 | wpa_hexdump_key(MSG_DEBUG, "Per-device PSK", psk, psk_len); |
| 1336 | |
| 1337 | /* TODO */ |
| 1338 | |
| 1339 | return 0; |
| 1340 | } |
| 1341 | |
| 1342 | |
| 1343 | static void wpas_wps_pin_needed_cb(void *ctx, const u8 *uuid_e, |
| 1344 | const struct wps_device_data *dev) |
| 1345 | { |
| 1346 | char uuid[40], txt[400]; |
| 1347 | int len; |
| 1348 | char devtype[WPS_DEV_TYPE_BUFSIZE]; |
| 1349 | if (uuid_bin2str(uuid_e, uuid, sizeof(uuid))) |
| 1350 | return; |
| 1351 | wpa_printf(MSG_DEBUG, "WPS: PIN needed for UUID-E %s", uuid); |
| 1352 | len = os_snprintf(txt, sizeof(txt), "WPS-EVENT-PIN-NEEDED %s " MACSTR |
| 1353 | " [%s|%s|%s|%s|%s|%s]", |
| 1354 | uuid, MAC2STR(dev->mac_addr), dev->device_name, |
| 1355 | dev->manufacturer, dev->model_name, |
| 1356 | dev->model_number, dev->serial_number, |
| 1357 | wps_dev_type_bin2str(dev->pri_dev_type, devtype, |
| 1358 | sizeof(devtype))); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1359 | if (!os_snprintf_error(sizeof(txt), len)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1360 | wpa_printf(MSG_INFO, "%s", txt); |
| 1361 | } |
| 1362 | |
| 1363 | |
| 1364 | static void wpas_wps_set_sel_reg_cb(void *ctx, int sel_reg, u16 dev_passwd_id, |
| 1365 | u16 sel_reg_config_methods) |
| 1366 | { |
| 1367 | #ifdef CONFIG_WPS_ER |
| 1368 | struct wpa_supplicant *wpa_s = ctx; |
| 1369 | |
| 1370 | if (wpa_s->wps_er == NULL) |
| 1371 | return; |
| 1372 | wpa_printf(MSG_DEBUG, "WPS ER: SetSelectedRegistrar - sel_reg=%d " |
| 1373 | "dev_password_id=%u sel_reg_config_methods=0x%x", |
| 1374 | sel_reg, dev_passwd_id, sel_reg_config_methods); |
| 1375 | wps_er_set_sel_reg(wpa_s->wps_er, sel_reg, dev_passwd_id, |
| 1376 | sel_reg_config_methods); |
| 1377 | #endif /* CONFIG_WPS_ER */ |
| 1378 | } |
| 1379 | |
| 1380 | |
| 1381 | static u16 wps_fix_config_methods(u16 config_methods) |
| 1382 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1383 | if ((config_methods & |
| 1384 | (WPS_CONFIG_DISPLAY | WPS_CONFIG_VIRT_DISPLAY | |
| 1385 | WPS_CONFIG_PHY_DISPLAY)) == WPS_CONFIG_DISPLAY) { |
| 1386 | wpa_printf(MSG_INFO, "WPS: Converting display to " |
| 1387 | "virtual_display for WPS 2.0 compliance"); |
| 1388 | config_methods |= WPS_CONFIG_VIRT_DISPLAY; |
| 1389 | } |
| 1390 | if ((config_methods & |
| 1391 | (WPS_CONFIG_PUSHBUTTON | WPS_CONFIG_VIRT_PUSHBUTTON | |
| 1392 | WPS_CONFIG_PHY_PUSHBUTTON)) == WPS_CONFIG_PUSHBUTTON) { |
| 1393 | wpa_printf(MSG_INFO, "WPS: Converting push_button to " |
| 1394 | "virtual_push_button for WPS 2.0 compliance"); |
| 1395 | config_methods |= WPS_CONFIG_VIRT_PUSHBUTTON; |
| 1396 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1397 | |
| 1398 | return config_methods; |
| 1399 | } |
| 1400 | |
| 1401 | |
| 1402 | static void wpas_wps_set_uuid(struct wpa_supplicant *wpa_s, |
| 1403 | struct wps_context *wps) |
| 1404 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1405 | char buf[50]; |
| 1406 | const char *src; |
| 1407 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1408 | if (is_nil_uuid(wpa_s->conf->uuid)) { |
| 1409 | struct wpa_supplicant *first; |
| 1410 | first = wpa_s->global->ifaces; |
| 1411 | while (first && first->next) |
| 1412 | first = first->next; |
| 1413 | if (first && first != wpa_s) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1414 | if (wps != wpa_s->global->ifaces->wps) |
| 1415 | os_memcpy(wps->uuid, |
| 1416 | wpa_s->global->ifaces->wps->uuid, |
| 1417 | WPS_UUID_LEN); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1418 | src = "from the first interface"; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1419 | } else { |
| 1420 | uuid_gen_mac_addr(wpa_s->own_addr, wps->uuid); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1421 | src = "based on MAC address"; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1422 | } |
| 1423 | } else { |
| 1424 | os_memcpy(wps->uuid, wpa_s->conf->uuid, WPS_UUID_LEN); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1425 | src = "based on configuration"; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1426 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1427 | |
| 1428 | uuid_bin2str(wps->uuid, buf, sizeof(buf)); |
| 1429 | wpa_dbg(wpa_s, MSG_DEBUG, "WPS: UUID %s: %s", src, buf); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1433 | static void wpas_wps_set_vendor_ext_m1(struct wpa_supplicant *wpa_s, |
| 1434 | struct wps_context *wps) |
| 1435 | { |
| 1436 | wpabuf_free(wps->dev.vendor_ext_m1); |
| 1437 | wps->dev.vendor_ext_m1 = NULL; |
| 1438 | |
| 1439 | if (wpa_s->conf->wps_vendor_ext_m1) { |
| 1440 | wps->dev.vendor_ext_m1 = |
| 1441 | wpabuf_dup(wpa_s->conf->wps_vendor_ext_m1); |
| 1442 | if (!wps->dev.vendor_ext_m1) { |
| 1443 | wpa_printf(MSG_ERROR, "WPS: Cannot " |
| 1444 | "allocate memory for vendor_ext_m1"); |
| 1445 | } |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1450 | int wpas_wps_init(struct wpa_supplicant *wpa_s) |
| 1451 | { |
| 1452 | struct wps_context *wps; |
| 1453 | struct wps_registrar_config rcfg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1454 | struct hostapd_hw_modes *modes; |
| 1455 | u16 m; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1456 | |
| 1457 | wps = os_zalloc(sizeof(*wps)); |
| 1458 | if (wps == NULL) |
| 1459 | return -1; |
| 1460 | |
| 1461 | wps->cred_cb = wpa_supplicant_wps_cred; |
| 1462 | wps->event_cb = wpa_supplicant_wps_event; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1463 | wps->rf_band_cb = wpa_supplicant_wps_rf_band; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1464 | wps->cb_ctx = wpa_s; |
| 1465 | |
| 1466 | wps->dev.device_name = wpa_s->conf->device_name; |
| 1467 | wps->dev.manufacturer = wpa_s->conf->manufacturer; |
| 1468 | wps->dev.model_name = wpa_s->conf->model_name; |
| 1469 | wps->dev.model_number = wpa_s->conf->model_number; |
| 1470 | wps->dev.serial_number = wpa_s->conf->serial_number; |
| 1471 | wps->config_methods = |
| 1472 | wps_config_methods_str2bin(wpa_s->conf->config_methods); |
| 1473 | if ((wps->config_methods & (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) == |
| 1474 | (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) { |
| 1475 | wpa_printf(MSG_ERROR, "WPS: Both Label and Display config " |
| 1476 | "methods are not allowed at the same time"); |
| 1477 | os_free(wps); |
| 1478 | return -1; |
| 1479 | } |
| 1480 | wps->config_methods = wps_fix_config_methods(wps->config_methods); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1481 | wps->dev.config_methods = wps->config_methods; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1482 | os_memcpy(wps->dev.pri_dev_type, wpa_s->conf->device_type, |
| 1483 | WPS_DEV_TYPE_LEN); |
| 1484 | |
| 1485 | wps->dev.num_sec_dev_types = wpa_s->conf->num_sec_device_types; |
| 1486 | os_memcpy(wps->dev.sec_dev_type, wpa_s->conf->sec_device_type, |
| 1487 | WPS_DEV_TYPE_LEN * wps->dev.num_sec_dev_types); |
| 1488 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1489 | wpas_wps_set_vendor_ext_m1(wpa_s, wps); |
| 1490 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1491 | wps->dev.os_version = WPA_GET_BE32(wpa_s->conf->os_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1492 | modes = wpa_s->hw.modes; |
| 1493 | if (modes) { |
| 1494 | for (m = 0; m < wpa_s->hw.num_modes; m++) { |
| 1495 | if (modes[m].mode == HOSTAPD_MODE_IEEE80211B || |
| 1496 | modes[m].mode == HOSTAPD_MODE_IEEE80211G) |
| 1497 | wps->dev.rf_bands |= WPS_RF_24GHZ; |
| 1498 | else if (modes[m].mode == HOSTAPD_MODE_IEEE80211A) |
| 1499 | wps->dev.rf_bands |= WPS_RF_50GHZ; |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame^] | 1500 | else if (modes[m].mode == HOSTAPD_MODE_IEEE80211AD) |
| 1501 | wps->dev.rf_bands |= WPS_RF_60GHZ; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1502 | } |
| 1503 | } |
| 1504 | if (wps->dev.rf_bands == 0) { |
| 1505 | /* |
| 1506 | * Default to claiming support for both bands if the driver |
| 1507 | * does not provide support for fetching supported bands. |
| 1508 | */ |
| 1509 | wps->dev.rf_bands = WPS_RF_24GHZ | WPS_RF_50GHZ; |
| 1510 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1511 | os_memcpy(wps->dev.mac_addr, wpa_s->own_addr, ETH_ALEN); |
| 1512 | wpas_wps_set_uuid(wpa_s, wps); |
| 1513 | |
| 1514 | wps->auth_types = WPS_AUTH_WPA2PSK | WPS_AUTH_WPAPSK; |
| 1515 | wps->encr_types = WPS_ENCR_AES | WPS_ENCR_TKIP; |
| 1516 | |
| 1517 | os_memset(&rcfg, 0, sizeof(rcfg)); |
| 1518 | rcfg.new_psk_cb = wpas_wps_new_psk_cb; |
| 1519 | rcfg.pin_needed_cb = wpas_wps_pin_needed_cb; |
| 1520 | rcfg.set_sel_reg_cb = wpas_wps_set_sel_reg_cb; |
| 1521 | rcfg.cb_ctx = wpa_s; |
| 1522 | |
| 1523 | wps->registrar = wps_registrar_init(wps, &rcfg); |
| 1524 | if (wps->registrar == NULL) { |
| 1525 | wpa_printf(MSG_DEBUG, "Failed to initialize WPS Registrar"); |
| 1526 | os_free(wps); |
| 1527 | return -1; |
| 1528 | } |
| 1529 | |
| 1530 | wpa_s->wps = wps; |
| 1531 | |
| 1532 | return 0; |
| 1533 | } |
| 1534 | |
| 1535 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1536 | #ifdef CONFIG_WPS_ER |
| 1537 | static void wpas_wps_nfc_clear(struct wps_context *wps) |
| 1538 | { |
| 1539 | wps->ap_nfc_dev_pw_id = 0; |
| 1540 | wpabuf_free(wps->ap_nfc_dh_pubkey); |
| 1541 | wps->ap_nfc_dh_pubkey = NULL; |
| 1542 | wpabuf_free(wps->ap_nfc_dh_privkey); |
| 1543 | wps->ap_nfc_dh_privkey = NULL; |
| 1544 | wpabuf_free(wps->ap_nfc_dev_pw); |
| 1545 | wps->ap_nfc_dev_pw = NULL; |
| 1546 | } |
| 1547 | #endif /* CONFIG_WPS_ER */ |
| 1548 | |
| 1549 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1550 | void wpas_wps_deinit(struct wpa_supplicant *wpa_s) |
| 1551 | { |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 1552 | wpas_wps_assoc_with_cred_cancel(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1553 | eloop_cancel_timeout(wpas_wps_timeout, wpa_s, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1554 | eloop_cancel_timeout(wpas_wps_clear_timeout, wpa_s, NULL); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1555 | eloop_cancel_timeout(wpas_wps_reenable_networks_cb, wpa_s, NULL); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1556 | wpas_wps_clear_ap_info(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1557 | |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 1558 | #ifdef CONFIG_P2P |
| 1559 | eloop_cancel_timeout(wpas_p2p_pbc_overlap_cb, wpa_s, NULL); |
| 1560 | #endif /* CONFIG_P2P */ |
| 1561 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1562 | if (wpa_s->wps == NULL) |
| 1563 | return; |
| 1564 | |
| 1565 | #ifdef CONFIG_WPS_ER |
| 1566 | wps_er_deinit(wpa_s->wps_er, NULL, NULL); |
| 1567 | wpa_s->wps_er = NULL; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1568 | wpas_wps_nfc_clear(wpa_s->wps); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1569 | #endif /* CONFIG_WPS_ER */ |
| 1570 | |
| 1571 | wps_registrar_deinit(wpa_s->wps->registrar); |
| 1572 | wpabuf_free(wpa_s->wps->dh_pubkey); |
| 1573 | wpabuf_free(wpa_s->wps->dh_privkey); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1574 | wpabuf_free(wpa_s->wps->dev.vendor_ext_m1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1575 | os_free(wpa_s->wps->network_key); |
| 1576 | os_free(wpa_s->wps); |
| 1577 | wpa_s->wps = NULL; |
| 1578 | } |
| 1579 | |
| 1580 | |
| 1581 | int wpas_wps_ssid_bss_match(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1582 | struct wpa_ssid *ssid, struct wpa_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1583 | { |
| 1584 | struct wpabuf *wps_ie; |
| 1585 | |
| 1586 | if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS)) |
| 1587 | return -1; |
| 1588 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1589 | wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1590 | if (eap_is_wps_pbc_enrollee(&ssid->eap)) { |
| 1591 | if (!wps_ie) { |
| 1592 | wpa_printf(MSG_DEBUG, " skip - non-WPS AP"); |
| 1593 | return 0; |
| 1594 | } |
| 1595 | |
| 1596 | if (!wps_is_selected_pbc_registrar(wps_ie)) { |
| 1597 | wpa_printf(MSG_DEBUG, " skip - WPS AP " |
| 1598 | "without active PBC Registrar"); |
| 1599 | wpabuf_free(wps_ie); |
| 1600 | return 0; |
| 1601 | } |
| 1602 | |
| 1603 | /* TODO: overlap detection */ |
| 1604 | wpa_printf(MSG_DEBUG, " selected based on WPS IE " |
| 1605 | "(Active PBC)"); |
| 1606 | wpabuf_free(wps_ie); |
| 1607 | return 1; |
| 1608 | } |
| 1609 | |
| 1610 | if (eap_is_wps_pin_enrollee(&ssid->eap)) { |
| 1611 | if (!wps_ie) { |
| 1612 | wpa_printf(MSG_DEBUG, " skip - non-WPS AP"); |
| 1613 | return 0; |
| 1614 | } |
| 1615 | |
| 1616 | /* |
| 1617 | * Start with WPS APs that advertise our address as an |
| 1618 | * authorized MAC (v2.0) or active PIN Registrar (v1.0) and |
| 1619 | * allow any WPS AP after couple of scans since some APs do not |
| 1620 | * set Selected Registrar attribute properly when using |
| 1621 | * external Registrar. |
| 1622 | */ |
| 1623 | if (!wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1)) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame^] | 1624 | struct os_reltime age; |
| 1625 | |
| 1626 | os_reltime_age(&wpa_s->wps_pin_start_time, &age); |
| 1627 | |
| 1628 | if (wpa_s->scan_runs < WPS_PIN_SCAN_IGNORE_SEL_REG || |
| 1629 | age.sec < WPS_PIN_TIME_IGNORE_SEL_REG) { |
| 1630 | wpa_printf(MSG_DEBUG, |
| 1631 | " skip - WPS AP without active PIN Registrar (scan_runs=%d age=%d)", |
| 1632 | wpa_s->scan_runs, (int) age.sec); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1633 | wpabuf_free(wps_ie); |
| 1634 | return 0; |
| 1635 | } |
| 1636 | wpa_printf(MSG_DEBUG, " selected based on WPS IE"); |
| 1637 | } else { |
| 1638 | wpa_printf(MSG_DEBUG, " selected based on WPS IE " |
| 1639 | "(Authorized MAC or Active PIN)"); |
| 1640 | } |
| 1641 | wpabuf_free(wps_ie); |
| 1642 | return 1; |
| 1643 | } |
| 1644 | |
| 1645 | if (wps_ie) { |
| 1646 | wpa_printf(MSG_DEBUG, " selected based on WPS IE"); |
| 1647 | wpabuf_free(wps_ie); |
| 1648 | return 1; |
| 1649 | } |
| 1650 | |
| 1651 | return -1; |
| 1652 | } |
| 1653 | |
| 1654 | |
| 1655 | int wpas_wps_ssid_wildcard_ok(struct wpa_supplicant *wpa_s, |
| 1656 | struct wpa_ssid *ssid, |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1657 | struct wpa_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1658 | { |
| 1659 | struct wpabuf *wps_ie = NULL; |
| 1660 | int ret = 0; |
| 1661 | |
| 1662 | if (eap_is_wps_pbc_enrollee(&ssid->eap)) { |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1663 | wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1664 | if (wps_ie && wps_is_selected_pbc_registrar(wps_ie)) { |
| 1665 | /* allow wildcard SSID for WPS PBC */ |
| 1666 | ret = 1; |
| 1667 | } |
| 1668 | } else if (eap_is_wps_pin_enrollee(&ssid->eap)) { |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1669 | wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1670 | if (wps_ie && |
| 1671 | (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1) || |
| 1672 | wpa_s->scan_runs >= WPS_PIN_SCAN_IGNORE_SEL_REG)) { |
| 1673 | /* allow wildcard SSID for WPS PIN */ |
| 1674 | ret = 1; |
| 1675 | } |
| 1676 | } |
| 1677 | |
| 1678 | if (!ret && ssid->bssid_set && |
| 1679 | os_memcmp(ssid->bssid, bss->bssid, ETH_ALEN) == 0) { |
| 1680 | /* allow wildcard SSID due to hardcoded BSSID match */ |
| 1681 | ret = 1; |
| 1682 | } |
| 1683 | |
| 1684 | #ifdef CONFIG_WPS_STRICT |
| 1685 | if (wps_ie) { |
| 1686 | if (wps_validate_beacon_probe_resp(wps_ie, bss->beacon_ie_len > |
| 1687 | 0, bss->bssid) < 0) |
| 1688 | ret = 0; |
| 1689 | if (bss->beacon_ie_len) { |
| 1690 | struct wpabuf *bcn_wps; |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1691 | bcn_wps = wpa_bss_get_vendor_ie_multi_beacon( |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1692 | bss, WPS_IE_VENDOR_TYPE); |
| 1693 | if (bcn_wps == NULL) { |
| 1694 | wpa_printf(MSG_DEBUG, "WPS: Mandatory WPS IE " |
| 1695 | "missing from AP Beacon"); |
| 1696 | ret = 0; |
| 1697 | } else { |
| 1698 | if (wps_validate_beacon(wps_ie) < 0) |
| 1699 | ret = 0; |
| 1700 | wpabuf_free(bcn_wps); |
| 1701 | } |
| 1702 | } |
| 1703 | } |
| 1704 | #endif /* CONFIG_WPS_STRICT */ |
| 1705 | |
| 1706 | wpabuf_free(wps_ie); |
| 1707 | |
| 1708 | return ret; |
| 1709 | } |
| 1710 | |
| 1711 | |
| 1712 | int wpas_wps_scan_pbc_overlap(struct wpa_supplicant *wpa_s, |
| 1713 | struct wpa_bss *selected, struct wpa_ssid *ssid) |
| 1714 | { |
| 1715 | const u8 *sel_uuid, *uuid; |
| 1716 | struct wpabuf *wps_ie; |
| 1717 | int ret = 0; |
| 1718 | struct wpa_bss *bss; |
| 1719 | |
| 1720 | if (!eap_is_wps_pbc_enrollee(&ssid->eap)) |
| 1721 | return 0; |
| 1722 | |
| 1723 | wpa_printf(MSG_DEBUG, "WPS: Check whether PBC session overlap is " |
| 1724 | "present in scan results; selected BSSID " MACSTR, |
| 1725 | MAC2STR(selected->bssid)); |
| 1726 | |
| 1727 | /* Make sure that only one AP is in active PBC mode */ |
| 1728 | wps_ie = wpa_bss_get_vendor_ie_multi(selected, WPS_IE_VENDOR_TYPE); |
| 1729 | if (wps_ie) { |
| 1730 | sel_uuid = wps_get_uuid_e(wps_ie); |
| 1731 | wpa_hexdump(MSG_DEBUG, "WPS: UUID of the selected BSS", |
| 1732 | sel_uuid, UUID_LEN); |
| 1733 | } else { |
| 1734 | wpa_printf(MSG_DEBUG, "WPS: Selected BSS does not include " |
| 1735 | "WPS IE?!"); |
| 1736 | sel_uuid = NULL; |
| 1737 | } |
| 1738 | |
| 1739 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
| 1740 | struct wpabuf *ie; |
| 1741 | if (bss == selected) |
| 1742 | continue; |
| 1743 | ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); |
| 1744 | if (!ie) |
| 1745 | continue; |
| 1746 | if (!wps_is_selected_pbc_registrar(ie)) { |
| 1747 | wpabuf_free(ie); |
| 1748 | continue; |
| 1749 | } |
| 1750 | wpa_printf(MSG_DEBUG, "WPS: Another BSS in active PBC mode: " |
| 1751 | MACSTR, MAC2STR(bss->bssid)); |
| 1752 | uuid = wps_get_uuid_e(ie); |
| 1753 | wpa_hexdump(MSG_DEBUG, "WPS: UUID of the other BSS", |
| 1754 | uuid, UUID_LEN); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1755 | if (os_memcmp(selected->bssid, bss->bssid, ETH_ALEN) == 0) { |
| 1756 | wpabuf_free(ie); |
| 1757 | continue; |
| 1758 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1759 | if (sel_uuid == NULL || uuid == NULL || |
| 1760 | os_memcmp(sel_uuid, uuid, UUID_LEN) != 0) { |
| 1761 | ret = 1; /* PBC overlap */ |
| 1762 | wpa_msg(wpa_s, MSG_INFO, "WPS: PBC overlap detected: " |
| 1763 | MACSTR " and " MACSTR, |
| 1764 | MAC2STR(selected->bssid), |
| 1765 | MAC2STR(bss->bssid)); |
| 1766 | wpabuf_free(ie); |
| 1767 | break; |
| 1768 | } |
| 1769 | |
| 1770 | /* TODO: verify that this is reasonable dual-band situation */ |
| 1771 | |
| 1772 | wpabuf_free(ie); |
| 1773 | } |
| 1774 | |
| 1775 | wpabuf_free(wps_ie); |
| 1776 | |
| 1777 | return ret; |
| 1778 | } |
| 1779 | |
| 1780 | |
| 1781 | void wpas_wps_notify_scan_results(struct wpa_supplicant *wpa_s) |
| 1782 | { |
| 1783 | struct wpa_bss *bss; |
| 1784 | unsigned int pbc = 0, auth = 0, pin = 0, wps = 0; |
| 1785 | |
| 1786 | if (wpa_s->disconnected || wpa_s->wpa_state >= WPA_ASSOCIATED) |
| 1787 | return; |
| 1788 | |
| 1789 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
| 1790 | struct wpabuf *ie; |
| 1791 | ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE); |
| 1792 | if (!ie) |
| 1793 | continue; |
| 1794 | if (wps_is_selected_pbc_registrar(ie)) |
| 1795 | pbc++; |
| 1796 | else if (wps_is_addr_authorized(ie, wpa_s->own_addr, 0)) |
| 1797 | auth++; |
| 1798 | else if (wps_is_selected_pin_registrar(ie)) |
| 1799 | pin++; |
| 1800 | else |
| 1801 | wps++; |
| 1802 | wpabuf_free(ie); |
| 1803 | } |
| 1804 | |
| 1805 | if (pbc) |
| 1806 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PBC); |
| 1807 | else if (auth) |
| 1808 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_AUTH); |
| 1809 | else if (pin) |
| 1810 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE_PIN); |
| 1811 | else if (wps) |
| 1812 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPS_EVENT_AP_AVAILABLE); |
| 1813 | } |
| 1814 | |
| 1815 | |
| 1816 | int wpas_wps_searching(struct wpa_supplicant *wpa_s) |
| 1817 | { |
| 1818 | struct wpa_ssid *ssid; |
| 1819 | |
| 1820 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 1821 | if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && !ssid->disabled) |
| 1822 | return 1; |
| 1823 | } |
| 1824 | |
| 1825 | return 0; |
| 1826 | } |
| 1827 | |
| 1828 | |
| 1829 | int wpas_wps_scan_result_text(const u8 *ies, size_t ies_len, char *buf, |
| 1830 | char *end) |
| 1831 | { |
| 1832 | struct wpabuf *wps_ie; |
| 1833 | int ret; |
| 1834 | |
| 1835 | wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len, WPS_DEV_OUI_WFA); |
| 1836 | if (wps_ie == NULL) |
| 1837 | return 0; |
| 1838 | |
| 1839 | ret = wps_attr_text(wps_ie, buf, end); |
| 1840 | wpabuf_free(wps_ie); |
| 1841 | return ret; |
| 1842 | } |
| 1843 | |
| 1844 | |
| 1845 | int wpas_wps_er_start(struct wpa_supplicant *wpa_s, const char *filter) |
| 1846 | { |
| 1847 | #ifdef CONFIG_WPS_ER |
| 1848 | if (wpa_s->wps_er) { |
| 1849 | wps_er_refresh(wpa_s->wps_er); |
| 1850 | return 0; |
| 1851 | } |
| 1852 | wpa_s->wps_er = wps_er_init(wpa_s->wps, wpa_s->ifname, filter); |
| 1853 | if (wpa_s->wps_er == NULL) |
| 1854 | return -1; |
| 1855 | return 0; |
| 1856 | #else /* CONFIG_WPS_ER */ |
| 1857 | return 0; |
| 1858 | #endif /* CONFIG_WPS_ER */ |
| 1859 | } |
| 1860 | |
| 1861 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1862 | void wpas_wps_er_stop(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1863 | { |
| 1864 | #ifdef CONFIG_WPS_ER |
| 1865 | wps_er_deinit(wpa_s->wps_er, NULL, NULL); |
| 1866 | wpa_s->wps_er = NULL; |
| 1867 | #endif /* CONFIG_WPS_ER */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1868 | } |
| 1869 | |
| 1870 | |
| 1871 | #ifdef CONFIG_WPS_ER |
| 1872 | int wpas_wps_er_add_pin(struct wpa_supplicant *wpa_s, const u8 *addr, |
| 1873 | const char *uuid, const char *pin) |
| 1874 | { |
| 1875 | u8 u[UUID_LEN]; |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1876 | const u8 *use_uuid = NULL; |
| 1877 | u8 addr_buf[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1878 | |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1879 | if (os_strcmp(uuid, "any") == 0) { |
| 1880 | } else if (uuid_str2bin(uuid, u) == 0) { |
| 1881 | use_uuid = u; |
| 1882 | } else if (hwaddr_aton(uuid, addr_buf) == 0) { |
| 1883 | use_uuid = wps_er_get_sta_uuid(wpa_s->wps_er, addr_buf); |
| 1884 | if (use_uuid == NULL) |
| 1885 | return -1; |
| 1886 | } else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1887 | return -1; |
| 1888 | return wps_registrar_add_pin(wpa_s->wps->registrar, addr, |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1889 | use_uuid, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1890 | (const u8 *) pin, os_strlen(pin), 300); |
| 1891 | } |
| 1892 | |
| 1893 | |
| 1894 | int wpas_wps_er_pbc(struct wpa_supplicant *wpa_s, const char *uuid) |
| 1895 | { |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1896 | u8 u[UUID_LEN], *use_uuid = NULL; |
| 1897 | u8 addr[ETH_ALEN], *use_addr = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1898 | |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1899 | if (uuid_str2bin(uuid, u) == 0) |
| 1900 | use_uuid = u; |
| 1901 | else if (hwaddr_aton(uuid, addr) == 0) |
| 1902 | use_addr = addr; |
| 1903 | else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1904 | return -1; |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1905 | return wps_er_pbc(wpa_s->wps_er, use_uuid, use_addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1906 | } |
| 1907 | |
| 1908 | |
| 1909 | int wpas_wps_er_learn(struct wpa_supplicant *wpa_s, const char *uuid, |
| 1910 | const char *pin) |
| 1911 | { |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1912 | u8 u[UUID_LEN], *use_uuid = NULL; |
| 1913 | u8 addr[ETH_ALEN], *use_addr = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1914 | |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1915 | if (uuid_str2bin(uuid, u) == 0) |
| 1916 | use_uuid = u; |
| 1917 | else if (hwaddr_aton(uuid, addr) == 0) |
| 1918 | use_addr = addr; |
| 1919 | else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1920 | return -1; |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1921 | |
| 1922 | return wps_er_learn(wpa_s->wps_er, use_uuid, use_addr, (const u8 *) pin, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1923 | os_strlen(pin)); |
| 1924 | } |
| 1925 | |
| 1926 | |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1927 | static int wpas_wps_network_to_cred(struct wpa_ssid *ssid, |
| 1928 | struct wps_credential *cred) |
| 1929 | { |
| 1930 | os_memset(cred, 0, sizeof(*cred)); |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 1931 | if (ssid->ssid_len > SSID_MAX_LEN) |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1932 | return -1; |
| 1933 | os_memcpy(cred->ssid, ssid->ssid, ssid->ssid_len); |
| 1934 | cred->ssid_len = ssid->ssid_len; |
| 1935 | if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) { |
| 1936 | cred->auth_type = (ssid->proto & WPA_PROTO_RSN) ? |
| 1937 | WPS_AUTH_WPA2PSK : WPS_AUTH_WPAPSK; |
| 1938 | if (ssid->pairwise_cipher & WPA_CIPHER_CCMP) |
| 1939 | cred->encr_type = WPS_ENCR_AES; |
| 1940 | else |
| 1941 | cred->encr_type = WPS_ENCR_TKIP; |
| 1942 | if (ssid->passphrase) { |
| 1943 | cred->key_len = os_strlen(ssid->passphrase); |
| 1944 | if (cred->key_len >= 64) |
| 1945 | return -1; |
| 1946 | os_memcpy(cred->key, ssid->passphrase, cred->key_len); |
| 1947 | } else if (ssid->psk_set) { |
| 1948 | cred->key_len = 32; |
| 1949 | os_memcpy(cred->key, ssid->psk, 32); |
| 1950 | } else |
| 1951 | return -1; |
| 1952 | } else { |
| 1953 | cred->auth_type = WPS_AUTH_OPEN; |
| 1954 | cred->encr_type = WPS_ENCR_NONE; |
| 1955 | } |
| 1956 | |
| 1957 | return 0; |
| 1958 | } |
| 1959 | |
| 1960 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1961 | int wpas_wps_er_set_config(struct wpa_supplicant *wpa_s, const char *uuid, |
| 1962 | int id) |
| 1963 | { |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1964 | u8 u[UUID_LEN], *use_uuid = NULL; |
| 1965 | u8 addr[ETH_ALEN], *use_addr = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1966 | struct wpa_ssid *ssid; |
| 1967 | struct wps_credential cred; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1968 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1969 | |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1970 | if (uuid_str2bin(uuid, u) == 0) |
| 1971 | use_uuid = u; |
| 1972 | else if (hwaddr_aton(uuid, addr) == 0) |
| 1973 | use_addr = addr; |
| 1974 | else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1975 | return -1; |
| 1976 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 1977 | if (ssid == NULL || ssid->ssid == NULL) |
| 1978 | return -1; |
| 1979 | |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1980 | if (wpas_wps_network_to_cred(ssid, &cred) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1981 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1982 | ret = wps_er_set_config(wpa_s->wps_er, use_uuid, use_addr, &cred); |
| 1983 | os_memset(&cred, 0, sizeof(cred)); |
| 1984 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | |
| 1988 | int wpas_wps_er_config(struct wpa_supplicant *wpa_s, const char *uuid, |
| 1989 | const char *pin, struct wps_new_ap_settings *settings) |
| 1990 | { |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1991 | u8 u[UUID_LEN], *use_uuid = NULL; |
| 1992 | u8 addr[ETH_ALEN], *use_addr = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1993 | struct wps_credential cred; |
| 1994 | size_t len; |
| 1995 | |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 1996 | if (uuid_str2bin(uuid, u) == 0) |
| 1997 | use_uuid = u; |
| 1998 | else if (hwaddr_aton(uuid, addr) == 0) |
| 1999 | use_addr = addr; |
| 2000 | else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2001 | return -1; |
| 2002 | if (settings->ssid_hex == NULL || settings->auth == NULL || |
| 2003 | settings->encr == NULL || settings->key_hex == NULL) |
| 2004 | return -1; |
| 2005 | |
| 2006 | os_memset(&cred, 0, sizeof(cred)); |
| 2007 | len = os_strlen(settings->ssid_hex); |
| 2008 | if ((len & 1) || len > 2 * sizeof(cred.ssid) || |
| 2009 | hexstr2bin(settings->ssid_hex, cred.ssid, len / 2)) |
| 2010 | return -1; |
| 2011 | cred.ssid_len = len / 2; |
| 2012 | |
| 2013 | len = os_strlen(settings->key_hex); |
| 2014 | if ((len & 1) || len > 2 * sizeof(cred.key) || |
| 2015 | hexstr2bin(settings->key_hex, cred.key, len / 2)) |
| 2016 | return -1; |
| 2017 | cred.key_len = len / 2; |
| 2018 | |
| 2019 | if (os_strcmp(settings->auth, "OPEN") == 0) |
| 2020 | cred.auth_type = WPS_AUTH_OPEN; |
| 2021 | else if (os_strcmp(settings->auth, "WPAPSK") == 0) |
| 2022 | cred.auth_type = WPS_AUTH_WPAPSK; |
| 2023 | else if (os_strcmp(settings->auth, "WPA2PSK") == 0) |
| 2024 | cred.auth_type = WPS_AUTH_WPA2PSK; |
| 2025 | else |
| 2026 | return -1; |
| 2027 | |
| 2028 | if (os_strcmp(settings->encr, "NONE") == 0) |
| 2029 | cred.encr_type = WPS_ENCR_NONE; |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 2030 | #ifdef CONFIG_TESTING_OPTIONS |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2031 | else if (os_strcmp(settings->encr, "WEP") == 0) |
| 2032 | cred.encr_type = WPS_ENCR_WEP; |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 2033 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2034 | else if (os_strcmp(settings->encr, "TKIP") == 0) |
| 2035 | cred.encr_type = WPS_ENCR_TKIP; |
| 2036 | else if (os_strcmp(settings->encr, "CCMP") == 0) |
| 2037 | cred.encr_type = WPS_ENCR_AES; |
| 2038 | else |
| 2039 | return -1; |
| 2040 | |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 2041 | return wps_er_config(wpa_s->wps_er, use_uuid, use_addr, |
| 2042 | (const u8 *) pin, os_strlen(pin), &cred); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2046 | #ifdef CONFIG_WPS_NFC |
| 2047 | struct wpabuf * wpas_wps_er_nfc_config_token(struct wpa_supplicant *wpa_s, |
| 2048 | int ndef, const char *uuid) |
| 2049 | { |
| 2050 | struct wpabuf *ret; |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 2051 | u8 u[UUID_LEN], *use_uuid = NULL; |
| 2052 | u8 addr[ETH_ALEN], *use_addr = NULL; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2053 | |
| 2054 | if (!wpa_s->wps_er) |
| 2055 | return NULL; |
| 2056 | |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 2057 | if (uuid_str2bin(uuid, u) == 0) |
| 2058 | use_uuid = u; |
| 2059 | else if (hwaddr_aton(uuid, addr) == 0) |
| 2060 | use_addr = addr; |
| 2061 | else |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2062 | return NULL; |
| 2063 | |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 2064 | ret = wps_er_nfc_config_token(wpa_s->wps_er, use_uuid, use_addr); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2065 | if (ndef && ret) { |
| 2066 | struct wpabuf *tmp; |
| 2067 | tmp = ndef_build_wifi(ret); |
| 2068 | wpabuf_free(ret); |
| 2069 | if (tmp == NULL) |
| 2070 | return NULL; |
| 2071 | ret = tmp; |
| 2072 | } |
| 2073 | |
| 2074 | return ret; |
| 2075 | } |
| 2076 | #endif /* CONFIG_WPS_NFC */ |
| 2077 | |
| 2078 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2079 | static int callbacks_pending = 0; |
| 2080 | |
| 2081 | static void wpas_wps_terminate_cb(void *ctx) |
| 2082 | { |
| 2083 | wpa_printf(MSG_DEBUG, "WPS ER: Terminated"); |
| 2084 | if (--callbacks_pending <= 0) |
| 2085 | eloop_terminate(); |
| 2086 | } |
| 2087 | #endif /* CONFIG_WPS_ER */ |
| 2088 | |
| 2089 | |
| 2090 | int wpas_wps_terminate_pending(struct wpa_supplicant *wpa_s) |
| 2091 | { |
| 2092 | #ifdef CONFIG_WPS_ER |
| 2093 | if (wpa_s->wps_er) { |
| 2094 | callbacks_pending++; |
| 2095 | wps_er_deinit(wpa_s->wps_er, wpas_wps_terminate_cb, wpa_s); |
| 2096 | wpa_s->wps_er = NULL; |
| 2097 | return 1; |
| 2098 | } |
| 2099 | #endif /* CONFIG_WPS_ER */ |
| 2100 | return 0; |
| 2101 | } |
| 2102 | |
| 2103 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2104 | void wpas_wps_update_config(struct wpa_supplicant *wpa_s) |
| 2105 | { |
| 2106 | struct wps_context *wps = wpa_s->wps; |
| 2107 | |
| 2108 | if (wps == NULL) |
| 2109 | return; |
| 2110 | |
| 2111 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_CONFIG_METHODS) { |
| 2112 | wps->config_methods = wps_config_methods_str2bin( |
| 2113 | wpa_s->conf->config_methods); |
| 2114 | if ((wps->config_methods & |
| 2115 | (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) == |
| 2116 | (WPS_CONFIG_DISPLAY | WPS_CONFIG_LABEL)) { |
| 2117 | wpa_printf(MSG_ERROR, "WPS: Both Label and Display " |
| 2118 | "config methods are not allowed at the " |
| 2119 | "same time"); |
| 2120 | wps->config_methods &= ~WPS_CONFIG_LABEL; |
| 2121 | } |
| 2122 | } |
| 2123 | wps->config_methods = wps_fix_config_methods(wps->config_methods); |
jim1_lin | ff2bda6 | 2012-06-26 11:04:38 +0800 | [diff] [blame] | 2124 | wps->dev.config_methods = wps->config_methods; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2125 | |
| 2126 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_TYPE) |
| 2127 | os_memcpy(wps->dev.pri_dev_type, wpa_s->conf->device_type, |
| 2128 | WPS_DEV_TYPE_LEN); |
| 2129 | |
| 2130 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_SEC_DEVICE_TYPE) { |
| 2131 | wps->dev.num_sec_dev_types = wpa_s->conf->num_sec_device_types; |
| 2132 | os_memcpy(wps->dev.sec_dev_type, wpa_s->conf->sec_device_type, |
| 2133 | wps->dev.num_sec_dev_types * WPS_DEV_TYPE_LEN); |
| 2134 | } |
| 2135 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2136 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_VENDOR_EXTENSION) |
| 2137 | wpas_wps_set_vendor_ext_m1(wpa_s, wps); |
| 2138 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2139 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_OS_VERSION) |
| 2140 | wps->dev.os_version = WPA_GET_BE32(wpa_s->conf->os_version); |
| 2141 | |
| 2142 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_UUID) |
| 2143 | wpas_wps_set_uuid(wpa_s, wps); |
| 2144 | |
| 2145 | if (wpa_s->conf->changed_parameters & |
| 2146 | (CFG_CHANGED_DEVICE_NAME | CFG_CHANGED_WPS_STRING)) { |
| 2147 | /* Update pointers to make sure they refer current values */ |
| 2148 | wps->dev.device_name = wpa_s->conf->device_name; |
| 2149 | wps->dev.manufacturer = wpa_s->conf->manufacturer; |
| 2150 | wps->dev.model_name = wpa_s->conf->model_name; |
| 2151 | wps->dev.model_number = wpa_s->conf->model_number; |
| 2152 | wps->dev.serial_number = wpa_s->conf->serial_number; |
| 2153 | } |
| 2154 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2155 | |
| 2156 | |
| 2157 | #ifdef CONFIG_WPS_NFC |
| 2158 | |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 2159 | #ifdef CONFIG_WPS_ER |
| 2160 | static struct wpabuf * |
| 2161 | wpas_wps_network_config_token(struct wpa_supplicant *wpa_s, int ndef, |
| 2162 | struct wpa_ssid *ssid) |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 2163 | { |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 2164 | struct wpabuf *ret; |
| 2165 | struct wps_credential cred; |
| 2166 | |
| 2167 | if (wpas_wps_network_to_cred(ssid, &cred) < 0) |
| 2168 | return NULL; |
| 2169 | |
| 2170 | ret = wps_er_config_token_from_cred(wpa_s->wps, &cred); |
| 2171 | |
| 2172 | if (ndef && ret) { |
| 2173 | struct wpabuf *tmp; |
| 2174 | tmp = ndef_build_wifi(ret); |
| 2175 | wpabuf_free(ret); |
| 2176 | if (tmp == NULL) |
| 2177 | return NULL; |
| 2178 | ret = tmp; |
| 2179 | } |
| 2180 | |
| 2181 | return ret; |
| 2182 | } |
| 2183 | #endif /* CONFIG_WPS_ER */ |
| 2184 | |
| 2185 | |
| 2186 | struct wpabuf * wpas_wps_nfc_config_token(struct wpa_supplicant *wpa_s, |
| 2187 | int ndef, const char *id_str) |
| 2188 | { |
| 2189 | #ifdef CONFIG_WPS_ER |
| 2190 | if (id_str) { |
| 2191 | int id; |
| 2192 | char *end = NULL; |
| 2193 | struct wpa_ssid *ssid; |
| 2194 | |
| 2195 | id = strtol(id_str, &end, 10); |
| 2196 | if (end && *end) |
| 2197 | return NULL; |
| 2198 | |
| 2199 | ssid = wpa_config_get_network(wpa_s->conf, id); |
| 2200 | if (ssid == NULL) |
| 2201 | return NULL; |
| 2202 | return wpas_wps_network_config_token(wpa_s, ndef, ssid); |
| 2203 | } |
| 2204 | #endif /* CONFIG_WPS_ER */ |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 2205 | #ifdef CONFIG_AP |
| 2206 | if (wpa_s->ap_iface) |
| 2207 | return wpas_ap_wps_nfc_config_token(wpa_s, ndef); |
| 2208 | #endif /* CONFIG_AP */ |
| 2209 | return NULL; |
| 2210 | } |
| 2211 | |
| 2212 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2213 | struct wpabuf * wpas_wps_nfc_token(struct wpa_supplicant *wpa_s, int ndef) |
| 2214 | { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 2215 | if (wpa_s->conf->wps_nfc_pw_from_config) { |
| 2216 | return wps_nfc_token_build(ndef, |
| 2217 | wpa_s->conf->wps_nfc_dev_pw_id, |
| 2218 | wpa_s->conf->wps_nfc_dh_pubkey, |
| 2219 | wpa_s->conf->wps_nfc_dev_pw); |
| 2220 | } |
| 2221 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2222 | return wps_nfc_token_gen(ndef, &wpa_s->conf->wps_nfc_dev_pw_id, |
| 2223 | &wpa_s->conf->wps_nfc_dh_pubkey, |
| 2224 | &wpa_s->conf->wps_nfc_dh_privkey, |
| 2225 | &wpa_s->conf->wps_nfc_dev_pw); |
| 2226 | } |
| 2227 | |
| 2228 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2229 | int wpas_wps_start_nfc(struct wpa_supplicant *wpa_s, const u8 *go_dev_addr, |
| 2230 | const u8 *bssid, |
| 2231 | const struct wpabuf *dev_pw, u16 dev_pw_id, |
| 2232 | int p2p_group, const u8 *peer_pubkey_hash, |
| 2233 | const u8 *ssid, size_t ssid_len, int freq) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2234 | { |
| 2235 | struct wps_context *wps = wpa_s->wps; |
| 2236 | char pw[32 * 2 + 1]; |
| 2237 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2238 | if (dev_pw_id != DEV_PW_NFC_CONNECTION_HANDOVER && dev_pw == NULL) { |
| 2239 | dev_pw = wpa_s->conf->wps_nfc_dev_pw; |
| 2240 | dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id; |
| 2241 | } |
| 2242 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2243 | if (wpa_s->conf->wps_nfc_dh_pubkey == NULL || |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2244 | wpa_s->conf->wps_nfc_dh_privkey == NULL) { |
| 2245 | wpa_printf(MSG_DEBUG, "WPS: Missing DH params - " |
| 2246 | "cannot start NFC-triggered connection"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2247 | return -1; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2248 | } |
| 2249 | |
| 2250 | if (dev_pw_id != DEV_PW_NFC_CONNECTION_HANDOVER && dev_pw == NULL) { |
| 2251 | wpa_printf(MSG_DEBUG, "WPS: Missing Device Password (id=%u) - " |
| 2252 | "cannot start NFC-triggered connection", dev_pw_id); |
| 2253 | return -1; |
| 2254 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2255 | |
| 2256 | dh5_free(wps->dh_ctx); |
| 2257 | wpabuf_free(wps->dh_pubkey); |
| 2258 | wpabuf_free(wps->dh_privkey); |
| 2259 | wps->dh_privkey = wpabuf_dup(wpa_s->conf->wps_nfc_dh_privkey); |
| 2260 | wps->dh_pubkey = wpabuf_dup(wpa_s->conf->wps_nfc_dh_pubkey); |
| 2261 | if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) { |
| 2262 | wps->dh_ctx = NULL; |
| 2263 | wpabuf_free(wps->dh_pubkey); |
| 2264 | wps->dh_pubkey = NULL; |
| 2265 | wpabuf_free(wps->dh_privkey); |
| 2266 | wps->dh_privkey = NULL; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2267 | wpa_printf(MSG_DEBUG, "WPS: Failed to get DH priv/pub key"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2268 | return -1; |
| 2269 | } |
| 2270 | wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey); |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 2271 | if (wps->dh_ctx == NULL) { |
| 2272 | wpabuf_free(wps->dh_pubkey); |
| 2273 | wps->dh_pubkey = NULL; |
| 2274 | wpabuf_free(wps->dh_privkey); |
| 2275 | wps->dh_privkey = NULL; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2276 | wpa_printf(MSG_DEBUG, "WPS: Failed to initialize DH context"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2277 | return -1; |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 2278 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2279 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2280 | if (dev_pw) { |
| 2281 | wpa_snprintf_hex_uppercase(pw, sizeof(pw), |
| 2282 | wpabuf_head(dev_pw), |
| 2283 | wpabuf_len(dev_pw)); |
| 2284 | } |
| 2285 | return wpas_wps_start_dev_pw(wpa_s, go_dev_addr, bssid, |
| 2286 | dev_pw ? pw : NULL, |
| 2287 | p2p_group, dev_pw_id, peer_pubkey_hash, |
| 2288 | ssid, ssid_len, freq); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2289 | } |
| 2290 | |
| 2291 | |
| 2292 | static int wpas_wps_use_cred(struct wpa_supplicant *wpa_s, |
| 2293 | struct wps_parse_attr *attr) |
| 2294 | { |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 2295 | /* |
| 2296 | * Disable existing networks temporarily to allow the newly learned |
| 2297 | * credential to be preferred. Enable the temporarily disabled networks |
| 2298 | * after 10 seconds. |
| 2299 | */ |
| 2300 | wpas_wps_temp_disable(wpa_s, NULL); |
| 2301 | eloop_register_timeout(10, 0, wpas_wps_reenable_networks_cb, wpa_s, |
| 2302 | NULL); |
| 2303 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2304 | if (wps_oob_use_cred(wpa_s->wps, attr) < 0) |
| 2305 | return -1; |
| 2306 | |
| 2307 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
| 2308 | return 0; |
| 2309 | |
Dmitry Shmidt | 3c47937 | 2014-02-04 10:50:36 -0800 | [diff] [blame] | 2310 | if (attr->ap_channel) { |
| 2311 | u16 chan = WPA_GET_BE16(attr->ap_channel); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2312 | int freq = 0; |
| 2313 | |
| 2314 | if (chan >= 1 && chan <= 13) |
| 2315 | freq = 2407 + 5 * chan; |
| 2316 | else if (chan == 14) |
| 2317 | freq = 2484; |
| 2318 | else if (chan >= 30) |
| 2319 | freq = 5000 + 5 * chan; |
| 2320 | |
| 2321 | if (freq) { |
Dmitry Shmidt | 3c47937 | 2014-02-04 10:50:36 -0800 | [diff] [blame] | 2322 | wpa_printf(MSG_DEBUG, "WPS: Credential container indicated AP channel %u -> %u MHz", |
| 2323 | chan, freq); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2324 | wpa_s->after_wps = 5; |
| 2325 | wpa_s->wps_freq = freq; |
| 2326 | } |
| 2327 | } |
Dmitry Shmidt | 3c47937 | 2014-02-04 10:50:36 -0800 | [diff] [blame] | 2328 | |
| 2329 | wpa_printf(MSG_DEBUG, "WPS: Request reconnection with new network " |
| 2330 | "based on the received credential added"); |
| 2331 | wpa_s->normal_scans = 0; |
| 2332 | wpa_supplicant_reinit_autoscan(wpa_s); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2333 | wpa_s->disconnected = 0; |
| 2334 | wpa_s->reassociate = 1; |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 2335 | |
| 2336 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2337 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 2338 | |
| 2339 | return 0; |
| 2340 | } |
| 2341 | |
| 2342 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2343 | #ifdef CONFIG_WPS_ER |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2344 | static int wpas_wps_add_nfc_password_token(struct wpa_supplicant *wpa_s, |
| 2345 | struct wps_parse_attr *attr) |
| 2346 | { |
| 2347 | return wps_registrar_add_nfc_password_token( |
| 2348 | wpa_s->wps->registrar, attr->oob_dev_password, |
| 2349 | attr->oob_dev_password_len); |
| 2350 | } |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 2351 | #endif /* CONFIG_WPS_ER */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2352 | |
| 2353 | |
| 2354 | static int wpas_wps_nfc_tag_process(struct wpa_supplicant *wpa_s, |
| 2355 | const struct wpabuf *wps) |
| 2356 | { |
| 2357 | struct wps_parse_attr attr; |
| 2358 | |
| 2359 | wpa_hexdump_buf(MSG_DEBUG, "WPS: Received NFC tag payload", wps); |
| 2360 | |
| 2361 | if (wps_parse_msg(wps, &attr)) { |
| 2362 | wpa_printf(MSG_DEBUG, "WPS: Ignore invalid data from NFC tag"); |
| 2363 | return -1; |
| 2364 | } |
| 2365 | |
| 2366 | if (attr.num_cred) |
| 2367 | return wpas_wps_use_cred(wpa_s, &attr); |
| 2368 | |
| 2369 | #ifdef CONFIG_WPS_ER |
| 2370 | if (attr.oob_dev_password) |
| 2371 | return wpas_wps_add_nfc_password_token(wpa_s, &attr); |
| 2372 | #endif /* CONFIG_WPS_ER */ |
| 2373 | |
| 2374 | wpa_printf(MSG_DEBUG, "WPS: Ignore unrecognized NFC tag"); |
| 2375 | return -1; |
| 2376 | } |
| 2377 | |
| 2378 | |
| 2379 | int wpas_wps_nfc_tag_read(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2380 | const struct wpabuf *data, int forced_freq) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2381 | { |
| 2382 | const struct wpabuf *wps = data; |
| 2383 | struct wpabuf *tmp = NULL; |
| 2384 | int ret; |
| 2385 | |
| 2386 | if (wpabuf_len(data) < 4) |
| 2387 | return -1; |
| 2388 | |
| 2389 | if (*wpabuf_head_u8(data) != 0x10) { |
| 2390 | /* Assume this contains full NDEF record */ |
| 2391 | tmp = ndef_parse_wifi(data); |
| 2392 | if (tmp == NULL) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2393 | #ifdef CONFIG_P2P |
| 2394 | tmp = ndef_parse_p2p(data); |
| 2395 | if (tmp) { |
| 2396 | ret = wpas_p2p_nfc_tag_process(wpa_s, tmp, |
| 2397 | forced_freq); |
| 2398 | wpabuf_free(tmp); |
| 2399 | return ret; |
| 2400 | } |
| 2401 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2402 | wpa_printf(MSG_DEBUG, "WPS: Could not parse NDEF"); |
| 2403 | return -1; |
| 2404 | } |
| 2405 | wps = tmp; |
| 2406 | } |
| 2407 | |
| 2408 | ret = wpas_wps_nfc_tag_process(wpa_s, wps); |
| 2409 | wpabuf_free(tmp); |
| 2410 | return ret; |
| 2411 | } |
| 2412 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2413 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2414 | struct wpabuf * wpas_wps_nfc_handover_req(struct wpa_supplicant *wpa_s, |
| 2415 | int ndef) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2416 | { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2417 | struct wpabuf *ret; |
| 2418 | |
| 2419 | if (wpa_s->conf->wps_nfc_dh_pubkey == NULL && |
| 2420 | wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey, |
| 2421 | &wpa_s->conf->wps_nfc_dh_privkey) < 0) |
| 2422 | return NULL; |
| 2423 | |
| 2424 | ret = wps_build_nfc_handover_req(wpa_s->wps, |
| 2425 | wpa_s->conf->wps_nfc_dh_pubkey); |
| 2426 | |
| 2427 | if (ndef && ret) { |
| 2428 | struct wpabuf *tmp; |
| 2429 | tmp = ndef_build_wifi(ret); |
| 2430 | wpabuf_free(ret); |
| 2431 | if (tmp == NULL) |
| 2432 | return NULL; |
| 2433 | ret = tmp; |
| 2434 | } |
| 2435 | |
| 2436 | return ret; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2437 | } |
| 2438 | |
| 2439 | |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 2440 | #ifdef CONFIG_WPS_NFC |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2441 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2442 | static struct wpabuf * |
| 2443 | wpas_wps_er_nfc_handover_sel(struct wpa_supplicant *wpa_s, int ndef, |
| 2444 | const char *uuid) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2445 | { |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2446 | #ifdef CONFIG_WPS_ER |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 2447 | struct wpabuf *ret; |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 2448 | u8 u[UUID_LEN], *use_uuid = NULL; |
| 2449 | u8 addr[ETH_ALEN], *use_addr = NULL; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2450 | struct wps_context *wps = wpa_s->wps; |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 2451 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2452 | if (wps == NULL) |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 2453 | return NULL; |
| 2454 | |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 2455 | if (uuid == NULL) |
| 2456 | return NULL; |
| 2457 | if (uuid_str2bin(uuid, u) == 0) |
| 2458 | use_uuid = u; |
| 2459 | else if (hwaddr_aton(uuid, addr) == 0) |
| 2460 | use_addr = addr; |
| 2461 | else |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 2462 | return NULL; |
| 2463 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2464 | if (wpa_s->conf->wps_nfc_dh_pubkey == NULL) { |
| 2465 | if (wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey, |
| 2466 | &wpa_s->conf->wps_nfc_dh_privkey) < 0) |
| 2467 | return NULL; |
| 2468 | } |
| 2469 | |
| 2470 | wpas_wps_nfc_clear(wps); |
| 2471 | wps->ap_nfc_dev_pw_id = DEV_PW_NFC_CONNECTION_HANDOVER; |
| 2472 | wps->ap_nfc_dh_pubkey = wpabuf_dup(wpa_s->conf->wps_nfc_dh_pubkey); |
| 2473 | wps->ap_nfc_dh_privkey = wpabuf_dup(wpa_s->conf->wps_nfc_dh_privkey); |
| 2474 | if (!wps->ap_nfc_dh_pubkey || !wps->ap_nfc_dh_privkey) { |
| 2475 | wpas_wps_nfc_clear(wps); |
| 2476 | return NULL; |
| 2477 | } |
| 2478 | |
| 2479 | ret = wps_er_nfc_handover_sel(wpa_s->wps_er, wpa_s->wps, use_uuid, |
| 2480 | use_addr, wpa_s->conf->wps_nfc_dh_pubkey); |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 2481 | if (ndef && ret) { |
| 2482 | struct wpabuf *tmp; |
| 2483 | tmp = ndef_build_wifi(ret); |
| 2484 | wpabuf_free(ret); |
| 2485 | if (tmp == NULL) |
| 2486 | return NULL; |
| 2487 | ret = tmp; |
| 2488 | } |
| 2489 | |
| 2490 | return ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2491 | #else /* CONFIG_WPS_ER */ |
| 2492 | return NULL; |
| 2493 | #endif /* CONFIG_WPS_ER */ |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 2494 | } |
| 2495 | #endif /* CONFIG_WPS_NFC */ |
| 2496 | |
| 2497 | |
| 2498 | struct wpabuf * wpas_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s, |
| 2499 | int ndef, int cr, const char *uuid) |
| 2500 | { |
| 2501 | struct wpabuf *ret; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 2502 | if (!cr) |
| 2503 | return NULL; |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 2504 | ret = wpas_ap_wps_nfc_handover_sel(wpa_s, ndef); |
| 2505 | if (ret) |
| 2506 | return ret; |
| 2507 | return wpas_wps_er_nfc_handover_sel(wpa_s, ndef, uuid); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2508 | } |
| 2509 | |
| 2510 | |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 2511 | static int wpas_wps_nfc_rx_handover_sel(struct wpa_supplicant *wpa_s, |
| 2512 | const struct wpabuf *data) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2513 | { |
| 2514 | struct wpabuf *wps; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2515 | int ret = -1; |
| 2516 | u16 wsc_len; |
| 2517 | const u8 *pos; |
| 2518 | struct wpabuf msg; |
| 2519 | struct wps_parse_attr attr; |
| 2520 | u16 dev_pw_id; |
| 2521 | const u8 *bssid = NULL; |
| 2522 | int freq = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2523 | |
| 2524 | wps = ndef_parse_wifi(data); |
| 2525 | if (wps == NULL) |
| 2526 | return -1; |
| 2527 | wpa_printf(MSG_DEBUG, "WPS: Received application/vnd.wfa.wsc " |
| 2528 | "payload from NFC connection handover"); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2529 | wpa_hexdump_buf(MSG_DEBUG, "WPS: NFC payload", wps); |
| 2530 | if (wpabuf_len(wps) < 2) { |
| 2531 | wpa_printf(MSG_DEBUG, "WPS: Too short Wi-Fi Handover Select " |
| 2532 | "Message"); |
| 2533 | goto out; |
| 2534 | } |
| 2535 | pos = wpabuf_head(wps); |
| 2536 | wsc_len = WPA_GET_BE16(pos); |
| 2537 | if (wsc_len > wpabuf_len(wps) - 2) { |
| 2538 | wpa_printf(MSG_DEBUG, "WPS: Invalid WSC attribute length (%u) " |
| 2539 | "in Wi-Fi Handover Select Message", wsc_len); |
| 2540 | goto out; |
| 2541 | } |
| 2542 | pos += 2; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2543 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2544 | wpa_hexdump(MSG_DEBUG, |
| 2545 | "WPS: WSC attributes in Wi-Fi Handover Select Message", |
| 2546 | pos, wsc_len); |
| 2547 | if (wsc_len < wpabuf_len(wps) - 2) { |
| 2548 | wpa_hexdump(MSG_DEBUG, |
| 2549 | "WPS: Ignore extra data after WSC attributes", |
| 2550 | pos + wsc_len, wpabuf_len(wps) - 2 - wsc_len); |
| 2551 | } |
| 2552 | |
| 2553 | wpabuf_set(&msg, pos, wsc_len); |
| 2554 | ret = wps_parse_msg(&msg, &attr); |
| 2555 | if (ret < 0) { |
| 2556 | wpa_printf(MSG_DEBUG, "WPS: Could not parse WSC attributes in " |
| 2557 | "Wi-Fi Handover Select Message"); |
| 2558 | goto out; |
| 2559 | } |
| 2560 | |
| 2561 | if (attr.oob_dev_password == NULL || |
| 2562 | attr.oob_dev_password_len < WPS_OOB_PUBKEY_HASH_LEN + 2) { |
| 2563 | wpa_printf(MSG_DEBUG, "WPS: No Out-of-Band Device Password " |
| 2564 | "included in Wi-Fi Handover Select Message"); |
| 2565 | ret = -1; |
| 2566 | goto out; |
| 2567 | } |
| 2568 | |
| 2569 | if (attr.ssid == NULL) { |
| 2570 | wpa_printf(MSG_DEBUG, "WPS: No SSID included in Wi-Fi Handover " |
| 2571 | "Select Message"); |
| 2572 | ret = -1; |
| 2573 | goto out; |
| 2574 | } |
| 2575 | |
| 2576 | wpa_hexdump_ascii(MSG_DEBUG, "WPS: SSID", attr.ssid, attr.ssid_len); |
| 2577 | |
| 2578 | if (attr.mac_addr) { |
| 2579 | bssid = attr.mac_addr; |
| 2580 | wpa_printf(MSG_DEBUG, "WPS: MAC Address (BSSID): " MACSTR, |
| 2581 | MAC2STR(bssid)); |
| 2582 | } |
| 2583 | |
| 2584 | if (attr.rf_bands) |
| 2585 | wpa_printf(MSG_DEBUG, "WPS: RF Bands: %d", *attr.rf_bands); |
| 2586 | |
| 2587 | if (attr.ap_channel) { |
| 2588 | u16 chan = WPA_GET_BE16(attr.ap_channel); |
| 2589 | |
| 2590 | wpa_printf(MSG_DEBUG, "WPS: AP Channel: %d", chan); |
| 2591 | |
| 2592 | if (chan >= 1 && chan <= 13 && |
| 2593 | (attr.rf_bands == NULL || *attr.rf_bands & WPS_RF_24GHZ)) |
| 2594 | freq = 2407 + 5 * chan; |
| 2595 | else if (chan == 14 && |
| 2596 | (attr.rf_bands == NULL || |
| 2597 | *attr.rf_bands & WPS_RF_24GHZ)) |
| 2598 | freq = 2484; |
| 2599 | else if (chan >= 30 && |
| 2600 | (attr.rf_bands == NULL || |
| 2601 | *attr.rf_bands & WPS_RF_50GHZ)) |
| 2602 | freq = 5000 + 5 * chan; |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame^] | 2603 | else if (chan >= 1 && chan <= 4 && |
| 2604 | (attr.rf_bands == NULL || |
| 2605 | *attr.rf_bands & WPS_RF_60GHZ)) |
| 2606 | freq = 56160 + 2160 * chan; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2607 | |
| 2608 | if (freq) { |
| 2609 | wpa_printf(MSG_DEBUG, |
| 2610 | "WPS: AP indicated channel %u -> %u MHz", |
| 2611 | chan, freq); |
| 2612 | } |
| 2613 | } |
| 2614 | |
| 2615 | wpa_hexdump(MSG_DEBUG, "WPS: Out-of-Band Device Password", |
| 2616 | attr.oob_dev_password, attr.oob_dev_password_len); |
| 2617 | dev_pw_id = WPA_GET_BE16(attr.oob_dev_password + |
| 2618 | WPS_OOB_PUBKEY_HASH_LEN); |
| 2619 | if (dev_pw_id != DEV_PW_NFC_CONNECTION_HANDOVER) { |
| 2620 | wpa_printf(MSG_DEBUG, "WPS: Unexpected OOB Device Password ID " |
| 2621 | "%u in Wi-Fi Handover Select Message", dev_pw_id); |
| 2622 | ret = -1; |
| 2623 | goto out; |
| 2624 | } |
| 2625 | wpa_hexdump(MSG_DEBUG, "WPS: AP Public Key hash", |
| 2626 | attr.oob_dev_password, WPS_OOB_PUBKEY_HASH_LEN); |
| 2627 | |
| 2628 | ret = wpas_wps_start_nfc(wpa_s, NULL, bssid, NULL, dev_pw_id, 0, |
| 2629 | attr.oob_dev_password, |
| 2630 | attr.ssid, attr.ssid_len, freq); |
| 2631 | |
| 2632 | out: |
| 2633 | wpabuf_free(wps); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2634 | return ret; |
| 2635 | } |
| 2636 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 2637 | |
| 2638 | int wpas_wps_nfc_report_handover(struct wpa_supplicant *wpa_s, |
| 2639 | const struct wpabuf *req, |
| 2640 | const struct wpabuf *sel) |
| 2641 | { |
| 2642 | wpa_printf(MSG_DEBUG, "NFC: WPS connection handover reported"); |
| 2643 | wpa_hexdump_buf_key(MSG_DEBUG, "WPS: Carrier record in request", req); |
| 2644 | wpa_hexdump_buf_key(MSG_DEBUG, "WPS: Carrier record in select", sel); |
| 2645 | return wpas_wps_nfc_rx_handover_sel(wpa_s, sel); |
| 2646 | } |
| 2647 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2648 | |
| 2649 | int wpas_er_wps_nfc_report_handover(struct wpa_supplicant *wpa_s, |
| 2650 | const struct wpabuf *req, |
| 2651 | const struct wpabuf *sel) |
| 2652 | { |
| 2653 | struct wpabuf *wps; |
| 2654 | int ret = -1; |
| 2655 | u16 wsc_len; |
| 2656 | const u8 *pos; |
| 2657 | struct wpabuf msg; |
| 2658 | struct wps_parse_attr attr; |
| 2659 | u16 dev_pw_id; |
| 2660 | |
| 2661 | /* |
| 2662 | * Enrollee/station is always initiator of the NFC connection handover, |
| 2663 | * so use the request message here to find Enrollee public key hash. |
| 2664 | */ |
| 2665 | wps = ndef_parse_wifi(req); |
| 2666 | if (wps == NULL) |
| 2667 | return -1; |
| 2668 | wpa_printf(MSG_DEBUG, "WPS: Received application/vnd.wfa.wsc " |
| 2669 | "payload from NFC connection handover"); |
| 2670 | wpa_hexdump_buf(MSG_DEBUG, "WPS: NFC payload", wps); |
| 2671 | if (wpabuf_len(wps) < 2) { |
| 2672 | wpa_printf(MSG_DEBUG, "WPS: Too short Wi-Fi Handover Request " |
| 2673 | "Message"); |
| 2674 | goto out; |
| 2675 | } |
| 2676 | pos = wpabuf_head(wps); |
| 2677 | wsc_len = WPA_GET_BE16(pos); |
| 2678 | if (wsc_len > wpabuf_len(wps) - 2) { |
| 2679 | wpa_printf(MSG_DEBUG, "WPS: Invalid WSC attribute length (%u) " |
| 2680 | "in rt Wi-Fi Handover Request Message", wsc_len); |
| 2681 | goto out; |
| 2682 | } |
| 2683 | pos += 2; |
| 2684 | |
| 2685 | wpa_hexdump(MSG_DEBUG, |
| 2686 | "WPS: WSC attributes in Wi-Fi Handover Request Message", |
| 2687 | pos, wsc_len); |
| 2688 | if (wsc_len < wpabuf_len(wps) - 2) { |
| 2689 | wpa_hexdump(MSG_DEBUG, |
| 2690 | "WPS: Ignore extra data after WSC attributes", |
| 2691 | pos + wsc_len, wpabuf_len(wps) - 2 - wsc_len); |
| 2692 | } |
| 2693 | |
| 2694 | wpabuf_set(&msg, pos, wsc_len); |
| 2695 | ret = wps_parse_msg(&msg, &attr); |
| 2696 | if (ret < 0) { |
| 2697 | wpa_printf(MSG_DEBUG, "WPS: Could not parse WSC attributes in " |
| 2698 | "Wi-Fi Handover Request Message"); |
| 2699 | goto out; |
| 2700 | } |
| 2701 | |
| 2702 | if (attr.oob_dev_password == NULL || |
| 2703 | attr.oob_dev_password_len < WPS_OOB_PUBKEY_HASH_LEN + 2) { |
| 2704 | wpa_printf(MSG_DEBUG, "WPS: No Out-of-Band Device Password " |
| 2705 | "included in Wi-Fi Handover Request Message"); |
| 2706 | ret = -1; |
| 2707 | goto out; |
| 2708 | } |
| 2709 | |
| 2710 | if (attr.uuid_e == NULL) { |
| 2711 | wpa_printf(MSG_DEBUG, "WPS: No UUID-E included in Wi-Fi " |
| 2712 | "Handover Request Message"); |
| 2713 | ret = -1; |
| 2714 | goto out; |
| 2715 | } |
| 2716 | |
| 2717 | wpa_hexdump(MSG_DEBUG, "WPS: UUID-E", attr.uuid_e, WPS_UUID_LEN); |
| 2718 | |
| 2719 | wpa_hexdump(MSG_DEBUG, "WPS: Out-of-Band Device Password", |
| 2720 | attr.oob_dev_password, attr.oob_dev_password_len); |
| 2721 | dev_pw_id = WPA_GET_BE16(attr.oob_dev_password + |
| 2722 | WPS_OOB_PUBKEY_HASH_LEN); |
| 2723 | if (dev_pw_id != DEV_PW_NFC_CONNECTION_HANDOVER) { |
| 2724 | wpa_printf(MSG_DEBUG, "WPS: Unexpected OOB Device Password ID " |
| 2725 | "%u in Wi-Fi Handover Request Message", dev_pw_id); |
| 2726 | ret = -1; |
| 2727 | goto out; |
| 2728 | } |
| 2729 | wpa_hexdump(MSG_DEBUG, "WPS: Enrollee Public Key hash", |
| 2730 | attr.oob_dev_password, WPS_OOB_PUBKEY_HASH_LEN); |
| 2731 | |
| 2732 | ret = wps_registrar_add_nfc_pw_token(wpa_s->wps->registrar, |
| 2733 | attr.oob_dev_password, |
| 2734 | DEV_PW_NFC_CONNECTION_HANDOVER, |
| 2735 | NULL, 0, 1); |
| 2736 | |
| 2737 | out: |
| 2738 | wpabuf_free(wps); |
| 2739 | return ret; |
| 2740 | } |
| 2741 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2742 | #endif /* CONFIG_WPS_NFC */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2743 | |
| 2744 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2745 | static void wpas_wps_dump_ap_info(struct wpa_supplicant *wpa_s) |
| 2746 | { |
| 2747 | size_t i; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2748 | struct os_reltime now; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2749 | |
| 2750 | if (wpa_debug_level > MSG_DEBUG) |
| 2751 | return; |
| 2752 | |
| 2753 | if (wpa_s->wps_ap == NULL) |
| 2754 | return; |
| 2755 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2756 | os_get_reltime(&now); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2757 | |
| 2758 | for (i = 0; i < wpa_s->num_wps_ap; i++) { |
| 2759 | struct wps_ap_info *ap = &wpa_s->wps_ap[i]; |
| 2760 | struct wpa_blacklist *e = wpa_blacklist_get(wpa_s, ap->bssid); |
| 2761 | |
| 2762 | wpa_printf(MSG_DEBUG, "WPS: AP[%d] " MACSTR " type=%d " |
| 2763 | "tries=%d last_attempt=%d sec ago blacklist=%d", |
| 2764 | (int) i, MAC2STR(ap->bssid), ap->type, ap->tries, |
| 2765 | ap->last_attempt.sec > 0 ? |
| 2766 | (int) now.sec - (int) ap->last_attempt.sec : -1, |
| 2767 | e ? e->count : 0); |
| 2768 | } |
| 2769 | } |
| 2770 | |
| 2771 | |
| 2772 | static struct wps_ap_info * wpas_wps_get_ap_info(struct wpa_supplicant *wpa_s, |
| 2773 | const u8 *bssid) |
| 2774 | { |
| 2775 | size_t i; |
| 2776 | |
| 2777 | if (wpa_s->wps_ap == NULL) |
| 2778 | return NULL; |
| 2779 | |
| 2780 | for (i = 0; i < wpa_s->num_wps_ap; i++) { |
| 2781 | struct wps_ap_info *ap = &wpa_s->wps_ap[i]; |
| 2782 | if (os_memcmp(ap->bssid, bssid, ETH_ALEN) == 0) |
| 2783 | return ap; |
| 2784 | } |
| 2785 | |
| 2786 | return NULL; |
| 2787 | } |
| 2788 | |
| 2789 | |
| 2790 | static void wpas_wps_update_ap_info_bss(struct wpa_supplicant *wpa_s, |
| 2791 | struct wpa_scan_res *res) |
| 2792 | { |
| 2793 | struct wpabuf *wps; |
| 2794 | enum wps_ap_info_type type; |
| 2795 | struct wps_ap_info *ap; |
| 2796 | int r; |
| 2797 | |
| 2798 | if (wpa_scan_get_vendor_ie(res, WPS_IE_VENDOR_TYPE) == NULL) |
| 2799 | return; |
| 2800 | |
| 2801 | wps = wpa_scan_get_vendor_ie_multi(res, WPS_IE_VENDOR_TYPE); |
| 2802 | if (wps == NULL) |
| 2803 | return; |
| 2804 | |
| 2805 | r = wps_is_addr_authorized(wps, wpa_s->own_addr, 1); |
| 2806 | if (r == 2) |
| 2807 | type = WPS_AP_SEL_REG_OUR; |
| 2808 | else if (r == 1) |
| 2809 | type = WPS_AP_SEL_REG; |
| 2810 | else |
| 2811 | type = WPS_AP_NOT_SEL_REG; |
| 2812 | |
| 2813 | wpabuf_free(wps); |
| 2814 | |
| 2815 | ap = wpas_wps_get_ap_info(wpa_s, res->bssid); |
| 2816 | if (ap) { |
| 2817 | if (ap->type != type) { |
| 2818 | wpa_printf(MSG_DEBUG, "WPS: AP " MACSTR |
| 2819 | " changed type %d -> %d", |
| 2820 | MAC2STR(res->bssid), ap->type, type); |
| 2821 | ap->type = type; |
| 2822 | if (type != WPS_AP_NOT_SEL_REG) |
| 2823 | wpa_blacklist_del(wpa_s, ap->bssid); |
| 2824 | } |
| 2825 | return; |
| 2826 | } |
| 2827 | |
| 2828 | ap = os_realloc_array(wpa_s->wps_ap, wpa_s->num_wps_ap + 1, |
| 2829 | sizeof(struct wps_ap_info)); |
| 2830 | if (ap == NULL) |
| 2831 | return; |
| 2832 | |
| 2833 | wpa_s->wps_ap = ap; |
| 2834 | ap = &wpa_s->wps_ap[wpa_s->num_wps_ap]; |
| 2835 | wpa_s->num_wps_ap++; |
| 2836 | |
| 2837 | os_memset(ap, 0, sizeof(*ap)); |
| 2838 | os_memcpy(ap->bssid, res->bssid, ETH_ALEN); |
| 2839 | ap->type = type; |
| 2840 | wpa_printf(MSG_DEBUG, "WPS: AP " MACSTR " type %d added", |
| 2841 | MAC2STR(ap->bssid), ap->type); |
| 2842 | } |
| 2843 | |
| 2844 | |
| 2845 | void wpas_wps_update_ap_info(struct wpa_supplicant *wpa_s, |
| 2846 | struct wpa_scan_results *scan_res) |
| 2847 | { |
| 2848 | size_t i; |
| 2849 | |
| 2850 | for (i = 0; i < scan_res->num; i++) |
| 2851 | wpas_wps_update_ap_info_bss(wpa_s, scan_res->res[i]); |
| 2852 | |
| 2853 | wpas_wps_dump_ap_info(wpa_s); |
| 2854 | } |
| 2855 | |
| 2856 | |
| 2857 | void wpas_wps_notify_assoc(struct wpa_supplicant *wpa_s, const u8 *bssid) |
| 2858 | { |
| 2859 | struct wps_ap_info *ap; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2860 | |
| 2861 | wpa_s->after_wps = 0; |
| 2862 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2863 | if (!wpa_s->wps_ap_iter) |
| 2864 | return; |
| 2865 | ap = wpas_wps_get_ap_info(wpa_s, bssid); |
| 2866 | if (ap == NULL) |
| 2867 | return; |
| 2868 | ap->tries++; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2869 | os_get_reltime(&ap->last_attempt); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2870 | } |