Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * WPA Supplicant - Glue code to setup EAPOL and RSN modules |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 3 | * Copyright (c) 2003-2015, 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 "eapol_supp/eapol_supp_sm.h" |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 13 | #include "eap_peer/eap.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14 | #include "rsn_supp/wpa.h" |
| 15 | #include "eloop.h" |
| 16 | #include "config.h" |
| 17 | #include "l2_packet/l2_packet.h" |
| 18 | #include "common/wpa_common.h" |
| 19 | #include "wpa_supplicant_i.h" |
| 20 | #include "driver_i.h" |
| 21 | #include "rsn_supp/pmksa_cache.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 22 | #include "sme.h" |
| 23 | #include "common/ieee802_11_defs.h" |
| 24 | #include "common/wpa_ctrl.h" |
| 25 | #include "wpas_glue.h" |
| 26 | #include "wps_supplicant.h" |
| 27 | #include "bss.h" |
| 28 | #include "scan.h" |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 29 | #include "notify.h" |
Dmitry Shmidt | 5a1480c | 2014-05-12 09:46:02 -0700 | [diff] [blame] | 30 | #include "wpas_kay.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 31 | |
| 32 | |
| 33 | #ifndef CONFIG_NO_CONFIG_BLOBS |
| 34 | #if defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA) |
| 35 | static void wpa_supplicant_set_config_blob(void *ctx, |
| 36 | struct wpa_config_blob *blob) |
| 37 | { |
| 38 | struct wpa_supplicant *wpa_s = ctx; |
| 39 | wpa_config_set_blob(wpa_s->conf, blob); |
| 40 | if (wpa_s->conf->update_config) { |
| 41 | int ret = wpa_config_write(wpa_s->confname, wpa_s->conf); |
| 42 | if (ret) { |
| 43 | wpa_printf(MSG_DEBUG, "Failed to update config after " |
| 44 | "blob set"); |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | |
| 50 | static const struct wpa_config_blob * |
| 51 | wpa_supplicant_get_config_blob(void *ctx, const char *name) |
| 52 | { |
| 53 | struct wpa_supplicant *wpa_s = ctx; |
| 54 | return wpa_config_get_blob(wpa_s->conf, name); |
| 55 | } |
| 56 | #endif /* defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA) */ |
| 57 | #endif /* CONFIG_NO_CONFIG_BLOBS */ |
| 58 | |
| 59 | |
| 60 | #if defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA) |
| 61 | static u8 * wpa_alloc_eapol(const struct wpa_supplicant *wpa_s, u8 type, |
| 62 | const void *data, u16 data_len, |
| 63 | size_t *msg_len, void **data_pos) |
| 64 | { |
| 65 | struct ieee802_1x_hdr *hdr; |
| 66 | |
| 67 | *msg_len = sizeof(*hdr) + data_len; |
| 68 | hdr = os_malloc(*msg_len); |
| 69 | if (hdr == NULL) |
| 70 | return NULL; |
| 71 | |
| 72 | hdr->version = wpa_s->conf->eapol_version; |
| 73 | hdr->type = type; |
| 74 | hdr->length = host_to_be16(data_len); |
| 75 | |
| 76 | if (data) |
| 77 | os_memcpy(hdr + 1, data, data_len); |
| 78 | else |
| 79 | os_memset(hdr + 1, 0, data_len); |
| 80 | |
| 81 | if (data_pos) |
| 82 | *data_pos = hdr + 1; |
| 83 | |
| 84 | return (u8 *) hdr; |
| 85 | } |
| 86 | |
| 87 | |
| 88 | /** |
| 89 | * wpa_ether_send - Send Ethernet frame |
| 90 | * @wpa_s: Pointer to wpa_supplicant data |
| 91 | * @dest: Destination MAC address |
| 92 | * @proto: Ethertype in host byte order |
| 93 | * @buf: Frame payload starting from IEEE 802.1X header |
| 94 | * @len: Frame payload length |
| 95 | * Returns: >=0 on success, <0 on failure |
| 96 | */ |
| 97 | static int wpa_ether_send(struct wpa_supplicant *wpa_s, const u8 *dest, |
| 98 | u16 proto, const u8 *buf, size_t len) |
| 99 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 100 | #ifdef CONFIG_TESTING_OPTIONS |
| 101 | if (wpa_s->ext_eapol_frame_io && proto == ETH_P_EAPOL) { |
| 102 | size_t hex_len = 2 * len + 1; |
| 103 | char *hex = os_malloc(hex_len); |
| 104 | |
| 105 | if (hex == NULL) |
| 106 | return -1; |
| 107 | wpa_snprintf_hex(hex, hex_len, buf, len); |
| 108 | wpa_msg(wpa_s, MSG_INFO, "EAPOL-TX " MACSTR " %s", |
| 109 | MAC2STR(dest), hex); |
| 110 | os_free(hex); |
| 111 | return 0; |
| 112 | } |
| 113 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 114 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 115 | if (wpa_s->l2) { |
| 116 | return l2_packet_send(wpa_s->l2, dest, proto, buf, len); |
| 117 | } |
| 118 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 119 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 120 | } |
| 121 | #endif /* IEEE8021X_EAPOL || !CONFIG_NO_WPA */ |
| 122 | |
| 123 | |
| 124 | #ifdef IEEE8021X_EAPOL |
| 125 | |
| 126 | /** |
| 127 | * wpa_supplicant_eapol_send - Send IEEE 802.1X EAPOL packet to Authenticator |
| 128 | * @ctx: Pointer to wpa_supplicant data (wpa_s) |
| 129 | * @type: IEEE 802.1X packet type (IEEE802_1X_TYPE_*) |
| 130 | * @buf: EAPOL payload (after IEEE 802.1X header) |
| 131 | * @len: EAPOL payload length |
| 132 | * Returns: >=0 on success, <0 on failure |
| 133 | * |
| 134 | * This function adds Ethernet and IEEE 802.1X header and sends the EAPOL frame |
| 135 | * to the current Authenticator. |
| 136 | */ |
| 137 | static int wpa_supplicant_eapol_send(void *ctx, int type, const u8 *buf, |
| 138 | size_t len) |
| 139 | { |
| 140 | struct wpa_supplicant *wpa_s = ctx; |
| 141 | u8 *msg, *dst, bssid[ETH_ALEN]; |
| 142 | size_t msglen; |
| 143 | int res; |
| 144 | |
| 145 | /* TODO: could add l2_packet_sendmsg that allows fragments to avoid |
| 146 | * extra copy here */ |
| 147 | |
| 148 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || |
| 149 | wpa_s->key_mgmt == WPA_KEY_MGMT_NONE) { |
| 150 | /* Current SSID is not using IEEE 802.1X/EAP, so drop possible |
| 151 | * EAPOL frames (mainly, EAPOL-Start) from EAPOL state |
| 152 | * machines. */ |
| 153 | wpa_printf(MSG_DEBUG, "WPA: drop TX EAPOL in non-IEEE 802.1X " |
| 154 | "mode (type=%d len=%lu)", type, |
| 155 | (unsigned long) len); |
| 156 | return -1; |
| 157 | } |
| 158 | |
| 159 | if (pmksa_cache_get_current(wpa_s->wpa) && |
| 160 | type == IEEE802_1X_TYPE_EAPOL_START) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 161 | /* |
| 162 | * We were trying to use PMKSA caching and sending EAPOL-Start |
| 163 | * would abort that and trigger full EAPOL authentication. |
| 164 | * However, we've already waited for the AP/Authenticator to |
| 165 | * start 4-way handshake or EAP authentication, and apparently |
| 166 | * it has not done so since the startWhen timer has reached zero |
| 167 | * to get the state machine sending EAPOL-Start. This is not |
| 168 | * really supposed to happen, but an interoperability issue with |
| 169 | * a deployed AP has been identified where the connection fails |
| 170 | * due to that AP failing to operate correctly if PMKID is |
| 171 | * included in the Association Request frame. To work around |
| 172 | * this, assume PMKSA caching failed and try to initiate full |
| 173 | * EAP authentication. |
| 174 | */ |
| 175 | if (!wpa_s->current_ssid || |
| 176 | wpa_s->current_ssid->eap_workaround) { |
| 177 | wpa_printf(MSG_DEBUG, |
| 178 | "RSN: Timeout on waiting for the AP to initiate 4-way handshake for PMKSA caching or EAP authentication - try to force it to start EAP authentication"); |
| 179 | } else { |
| 180 | wpa_printf(MSG_DEBUG, |
| 181 | "RSN: PMKSA caching - do not send EAPOL-Start"); |
| 182 | return -1; |
| 183 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | if (is_zero_ether_addr(wpa_s->bssid)) { |
| 187 | wpa_printf(MSG_DEBUG, "BSSID not set when trying to send an " |
| 188 | "EAPOL frame"); |
| 189 | if (wpa_drv_get_bssid(wpa_s, bssid) == 0 && |
| 190 | !is_zero_ether_addr(bssid)) { |
| 191 | dst = bssid; |
| 192 | wpa_printf(MSG_DEBUG, "Using current BSSID " MACSTR |
| 193 | " from the driver as the EAPOL destination", |
| 194 | MAC2STR(dst)); |
| 195 | } else { |
| 196 | dst = wpa_s->last_eapol_src; |
| 197 | wpa_printf(MSG_DEBUG, "Using the source address of the" |
| 198 | " last received EAPOL frame " MACSTR " as " |
| 199 | "the EAPOL destination", |
| 200 | MAC2STR(dst)); |
| 201 | } |
| 202 | } else { |
| 203 | /* BSSID was already set (from (Re)Assoc event, so use it as |
| 204 | * the EAPOL destination. */ |
| 205 | dst = wpa_s->bssid; |
| 206 | } |
| 207 | |
| 208 | msg = wpa_alloc_eapol(wpa_s, type, buf, len, &msglen, NULL); |
| 209 | if (msg == NULL) |
| 210 | return -1; |
| 211 | |
| 212 | wpa_printf(MSG_DEBUG, "TX EAPOL: dst=" MACSTR, MAC2STR(dst)); |
| 213 | wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", msg, msglen); |
| 214 | res = wpa_ether_send(wpa_s, dst, ETH_P_EAPOL, msg, msglen); |
| 215 | os_free(msg); |
| 216 | return res; |
| 217 | } |
| 218 | |
| 219 | |
| 220 | /** |
| 221 | * wpa_eapol_set_wep_key - set WEP key for the driver |
| 222 | * @ctx: Pointer to wpa_supplicant data (wpa_s) |
| 223 | * @unicast: 1 = individual unicast key, 0 = broadcast key |
| 224 | * @keyidx: WEP key index (0..3) |
| 225 | * @key: Pointer to key data |
| 226 | * @keylen: Key length in bytes |
| 227 | * Returns: 0 on success or < 0 on error. |
| 228 | */ |
| 229 | static int wpa_eapol_set_wep_key(void *ctx, int unicast, int keyidx, |
| 230 | const u8 *key, size_t keylen) |
| 231 | { |
| 232 | struct wpa_supplicant *wpa_s = ctx; |
| 233 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { |
| 234 | int cipher = (keylen == 5) ? WPA_CIPHER_WEP40 : |
| 235 | WPA_CIPHER_WEP104; |
| 236 | if (unicast) |
| 237 | wpa_s->pairwise_cipher = cipher; |
| 238 | else |
| 239 | wpa_s->group_cipher = cipher; |
| 240 | } |
| 241 | return wpa_drv_set_key(wpa_s, WPA_ALG_WEP, |
| 242 | unicast ? wpa_s->bssid : NULL, |
| 243 | keyidx, unicast, NULL, 0, key, keylen); |
| 244 | } |
| 245 | |
| 246 | |
| 247 | static void wpa_supplicant_aborted_cached(void *ctx) |
| 248 | { |
| 249 | struct wpa_supplicant *wpa_s = ctx; |
| 250 | wpa_sm_aborted_cached(wpa_s->wpa); |
| 251 | } |
| 252 | |
| 253 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 254 | static const char * result_str(enum eapol_supp_result result) |
| 255 | { |
| 256 | switch (result) { |
| 257 | case EAPOL_SUPP_RESULT_FAILURE: |
| 258 | return "FAILURE"; |
| 259 | case EAPOL_SUPP_RESULT_SUCCESS: |
| 260 | return "SUCCESS"; |
| 261 | case EAPOL_SUPP_RESULT_EXPECTED_FAILURE: |
| 262 | return "EXPECTED_FAILURE"; |
| 263 | } |
| 264 | return "?"; |
| 265 | } |
| 266 | |
| 267 | |
| 268 | static void wpa_supplicant_eapol_cb(struct eapol_sm *eapol, |
| 269 | enum eapol_supp_result result, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 270 | void *ctx) |
| 271 | { |
| 272 | struct wpa_supplicant *wpa_s = ctx; |
| 273 | int res, pmk_len; |
| 274 | u8 pmk[PMK_LEN]; |
| 275 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 276 | wpa_printf(MSG_DEBUG, "EAPOL authentication completed - result=%s", |
| 277 | result_str(result)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 278 | |
| 279 | if (wpas_wps_eapol_cb(wpa_s) > 0) |
| 280 | return; |
| 281 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 282 | wpa_s->eap_expected_failure = result == |
| 283 | EAPOL_SUPP_RESULT_EXPECTED_FAILURE; |
| 284 | |
| 285 | if (result != EAPOL_SUPP_RESULT_SUCCESS) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 286 | /* |
| 287 | * Make sure we do not get stuck here waiting for long EAPOL |
| 288 | * timeout if the AP does not disconnect in case of |
| 289 | * authentication failure. |
| 290 | */ |
| 291 | wpa_supplicant_req_auth_timeout(wpa_s, 2, 0); |
Dmitry Shmidt | 5a1480c | 2014-05-12 09:46:02 -0700 | [diff] [blame] | 292 | } else { |
| 293 | ieee802_1x_notify_create_actor(wpa_s, wpa_s->last_eapol_src); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 296 | if (result != EAPOL_SUPP_RESULT_SUCCESS || |
| 297 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 298 | return; |
| 299 | |
| 300 | if (!wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) |
| 301 | return; |
| 302 | |
| 303 | wpa_printf(MSG_DEBUG, "Configure PMK for driver-based RSN 4-way " |
| 304 | "handshake"); |
| 305 | |
| 306 | pmk_len = PMK_LEN; |
| 307 | if (wpa_key_mgmt_ft(wpa_s->key_mgmt)) { |
| 308 | #ifdef CONFIG_IEEE80211R |
| 309 | u8 buf[2 * PMK_LEN]; |
| 310 | wpa_printf(MSG_DEBUG, "RSN: Use FT XXKey as PMK for " |
| 311 | "driver-based 4-way hs and FT"); |
| 312 | res = eapol_sm_get_key(eapol, buf, 2 * PMK_LEN); |
| 313 | if (res == 0) { |
| 314 | os_memcpy(pmk, buf + PMK_LEN, PMK_LEN); |
| 315 | os_memset(buf, 0, sizeof(buf)); |
| 316 | } |
| 317 | #else /* CONFIG_IEEE80211R */ |
| 318 | res = -1; |
| 319 | #endif /* CONFIG_IEEE80211R */ |
| 320 | } else { |
| 321 | res = eapol_sm_get_key(eapol, pmk, PMK_LEN); |
| 322 | if (res) { |
| 323 | /* |
| 324 | * EAP-LEAP is an exception from other EAP methods: it |
| 325 | * uses only 16-byte PMK. |
| 326 | */ |
| 327 | res = eapol_sm_get_key(eapol, pmk, 16); |
| 328 | pmk_len = 16; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | if (res) { |
| 333 | wpa_printf(MSG_DEBUG, "Failed to get PMK from EAPOL state " |
| 334 | "machines"); |
| 335 | return; |
| 336 | } |
| 337 | |
| 338 | wpa_hexdump_key(MSG_DEBUG, "RSN: Configure PMK for driver-based 4-way " |
| 339 | "handshake", pmk, pmk_len); |
| 340 | |
| 341 | if (wpa_drv_set_key(wpa_s, WPA_ALG_PMK, NULL, 0, 0, NULL, 0, pmk, |
| 342 | pmk_len)) { |
| 343 | wpa_printf(MSG_DEBUG, "Failed to set PMK to the driver"); |
| 344 | } |
| 345 | |
| 346 | wpa_supplicant_cancel_scan(wpa_s); |
| 347 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
| 348 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); |
| 349 | |
| 350 | } |
| 351 | |
| 352 | |
| 353 | static void wpa_supplicant_notify_eapol_done(void *ctx) |
| 354 | { |
| 355 | struct wpa_supplicant *wpa_s = ctx; |
| 356 | wpa_msg(wpa_s, MSG_DEBUG, "WPA: EAPOL processing complete"); |
| 357 | if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { |
| 358 | wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE); |
| 359 | } else { |
| 360 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
| 361 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | #endif /* IEEE8021X_EAPOL */ |
| 366 | |
| 367 | |
| 368 | #ifndef CONFIG_NO_WPA |
| 369 | |
| 370 | static int wpa_get_beacon_ie(struct wpa_supplicant *wpa_s) |
| 371 | { |
| 372 | int ret = 0; |
| 373 | struct wpa_bss *curr = NULL, *bss; |
| 374 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 375 | const u8 *ie; |
| 376 | |
| 377 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
| 378 | if (os_memcmp(bss->bssid, wpa_s->bssid, ETH_ALEN) != 0) |
| 379 | continue; |
| 380 | if (ssid == NULL || |
| 381 | ((bss->ssid_len == ssid->ssid_len && |
| 382 | os_memcmp(bss->ssid, ssid->ssid, ssid->ssid_len) == 0) || |
| 383 | ssid->ssid_len == 0)) { |
| 384 | curr = bss; |
| 385 | break; |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | if (curr) { |
| 390 | ie = wpa_bss_get_vendor_ie(curr, WPA_IE_VENDOR_TYPE); |
| 391 | if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0)) |
| 392 | ret = -1; |
| 393 | |
| 394 | ie = wpa_bss_get_ie(curr, WLAN_EID_RSN); |
| 395 | if (wpa_sm_set_ap_rsn_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0)) |
| 396 | ret = -1; |
| 397 | } else { |
| 398 | ret = -1; |
| 399 | } |
| 400 | |
| 401 | return ret; |
| 402 | } |
| 403 | |
| 404 | |
| 405 | static int wpa_supplicant_get_beacon_ie(void *ctx) |
| 406 | { |
| 407 | struct wpa_supplicant *wpa_s = ctx; |
| 408 | if (wpa_get_beacon_ie(wpa_s) == 0) { |
| 409 | return 0; |
| 410 | } |
| 411 | |
| 412 | /* No WPA/RSN IE found in the cached scan results. Try to get updated |
| 413 | * scan results from the driver. */ |
| 414 | if (wpa_supplicant_update_scan_results(wpa_s) < 0) |
| 415 | return -1; |
| 416 | |
| 417 | return wpa_get_beacon_ie(wpa_s); |
| 418 | } |
| 419 | |
| 420 | |
| 421 | static u8 * _wpa_alloc_eapol(void *wpa_s, u8 type, |
| 422 | const void *data, u16 data_len, |
| 423 | size_t *msg_len, void **data_pos) |
| 424 | { |
| 425 | return wpa_alloc_eapol(wpa_s, type, data, data_len, msg_len, data_pos); |
| 426 | } |
| 427 | |
| 428 | |
| 429 | static int _wpa_ether_send(void *wpa_s, const u8 *dest, u16 proto, |
| 430 | const u8 *buf, size_t len) |
| 431 | { |
| 432 | return wpa_ether_send(wpa_s, dest, proto, buf, len); |
| 433 | } |
| 434 | |
| 435 | |
| 436 | static void _wpa_supplicant_cancel_auth_timeout(void *wpa_s) |
| 437 | { |
| 438 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
| 439 | } |
| 440 | |
| 441 | |
| 442 | static void _wpa_supplicant_set_state(void *wpa_s, enum wpa_states state) |
| 443 | { |
| 444 | wpa_supplicant_set_state(wpa_s, state); |
| 445 | } |
| 446 | |
| 447 | |
| 448 | /** |
| 449 | * wpa_supplicant_get_state - Get the connection state |
| 450 | * @wpa_s: Pointer to wpa_supplicant data |
| 451 | * Returns: The current connection state (WPA_*) |
| 452 | */ |
| 453 | static enum wpa_states wpa_supplicant_get_state(struct wpa_supplicant *wpa_s) |
| 454 | { |
| 455 | return wpa_s->wpa_state; |
| 456 | } |
| 457 | |
| 458 | |
| 459 | static enum wpa_states _wpa_supplicant_get_state(void *wpa_s) |
| 460 | { |
| 461 | return wpa_supplicant_get_state(wpa_s); |
| 462 | } |
| 463 | |
| 464 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 465 | static void _wpa_supplicant_deauthenticate(void *wpa_s, int reason_code) |
| 466 | { |
| 467 | wpa_supplicant_deauthenticate(wpa_s, reason_code); |
| 468 | /* Schedule a scan to make sure we continue looking for networks */ |
| 469 | wpa_supplicant_req_scan(wpa_s, 5, 0); |
| 470 | } |
| 471 | |
| 472 | |
| 473 | static void * wpa_supplicant_get_network_ctx(void *wpa_s) |
| 474 | { |
| 475 | return wpa_supplicant_get_ssid(wpa_s); |
| 476 | } |
| 477 | |
| 478 | |
| 479 | static int wpa_supplicant_get_bssid(void *ctx, u8 *bssid) |
| 480 | { |
| 481 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 482 | return wpa_drv_get_bssid(wpa_s, bssid); |
| 483 | } |
| 484 | |
| 485 | |
| 486 | static int wpa_supplicant_set_key(void *_wpa_s, enum wpa_alg alg, |
| 487 | const u8 *addr, int key_idx, int set_tx, |
| 488 | const u8 *seq, size_t seq_len, |
| 489 | const u8 *key, size_t key_len) |
| 490 | { |
| 491 | struct wpa_supplicant *wpa_s = _wpa_s; |
| 492 | if (alg == WPA_ALG_TKIP && key_idx == 0 && key_len == 32) { |
| 493 | /* Clear the MIC error counter when setting a new PTK. */ |
| 494 | wpa_s->mic_errors_seen = 0; |
| 495 | } |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 496 | #ifdef CONFIG_TESTING_GET_GTK |
| 497 | if (key_idx > 0 && addr && is_broadcast_ether_addr(addr) && |
| 498 | alg != WPA_ALG_NONE && key_len <= sizeof(wpa_s->last_gtk)) { |
| 499 | os_memcpy(wpa_s->last_gtk, key, key_len); |
| 500 | wpa_s->last_gtk_len = key_len; |
| 501 | } |
| 502 | #endif /* CONFIG_TESTING_GET_GTK */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 503 | return wpa_drv_set_key(wpa_s, alg, addr, key_idx, set_tx, seq, seq_len, |
| 504 | key, key_len); |
| 505 | } |
| 506 | |
| 507 | |
| 508 | static int wpa_supplicant_mlme_setprotection(void *wpa_s, const u8 *addr, |
| 509 | int protection_type, |
| 510 | int key_type) |
| 511 | { |
| 512 | return wpa_drv_mlme_setprotection(wpa_s, addr, protection_type, |
| 513 | key_type); |
| 514 | } |
| 515 | |
| 516 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 517 | static struct wpa_ssid * wpas_get_network_ctx(struct wpa_supplicant *wpa_s, |
| 518 | void *network_ctx) |
| 519 | { |
| 520 | struct wpa_ssid *ssid; |
| 521 | |
| 522 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 523 | if (network_ctx == ssid) |
| 524 | return ssid; |
| 525 | } |
| 526 | |
| 527 | return NULL; |
| 528 | } |
| 529 | |
| 530 | |
| 531 | static int wpa_supplicant_add_pmkid(void *_wpa_s, void *network_ctx, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 532 | const u8 *bssid, const u8 *pmkid) |
| 533 | { |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 534 | struct wpa_supplicant *wpa_s = _wpa_s; |
| 535 | struct wpa_ssid *ssid; |
| 536 | |
| 537 | ssid = wpas_get_network_ctx(wpa_s, network_ctx); |
| 538 | if (ssid) |
| 539 | wpa_msg(wpa_s, MSG_INFO, PMKSA_CACHE_ADDED MACSTR " %d", |
| 540 | MAC2STR(bssid), ssid->id); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 541 | return wpa_drv_add_pmkid(wpa_s, bssid, pmkid); |
| 542 | } |
| 543 | |
| 544 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 545 | static int wpa_supplicant_remove_pmkid(void *_wpa_s, void *network_ctx, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 546 | const u8 *bssid, const u8 *pmkid) |
| 547 | { |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 548 | struct wpa_supplicant *wpa_s = _wpa_s; |
| 549 | struct wpa_ssid *ssid; |
| 550 | |
| 551 | ssid = wpas_get_network_ctx(wpa_s, network_ctx); |
| 552 | if (ssid) |
| 553 | wpa_msg(wpa_s, MSG_INFO, PMKSA_CACHE_REMOVED MACSTR " %d", |
| 554 | MAC2STR(bssid), ssid->id); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 555 | return wpa_drv_remove_pmkid(wpa_s, bssid, pmkid); |
| 556 | } |
| 557 | |
| 558 | |
| 559 | #ifdef CONFIG_IEEE80211R |
| 560 | static int wpa_supplicant_update_ft_ies(void *ctx, const u8 *md, |
| 561 | const u8 *ies, size_t ies_len) |
| 562 | { |
| 563 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 564 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
| 565 | return sme_update_ft_ies(wpa_s, md, ies, ies_len); |
| 566 | return wpa_drv_update_ft_ies(wpa_s, md, ies, ies_len); |
| 567 | } |
| 568 | |
| 569 | |
| 570 | static int wpa_supplicant_send_ft_action(void *ctx, u8 action, |
| 571 | const u8 *target_ap, |
| 572 | const u8 *ies, size_t ies_len) |
| 573 | { |
| 574 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 575 | int ret; |
| 576 | u8 *data, *pos; |
| 577 | size_t data_len; |
| 578 | |
| 579 | if (action != 1) { |
| 580 | wpa_printf(MSG_ERROR, "Unsupported send_ft_action action %d", |
| 581 | action); |
| 582 | return -1; |
| 583 | } |
| 584 | |
| 585 | /* |
| 586 | * Action frame payload: |
| 587 | * Category[1] = 6 (Fast BSS Transition) |
| 588 | * Action[1] = 1 (Fast BSS Transition Request) |
| 589 | * STA Address |
| 590 | * Target AP Address |
| 591 | * FT IEs |
| 592 | */ |
| 593 | |
| 594 | data_len = 2 + 2 * ETH_ALEN + ies_len; |
| 595 | data = os_malloc(data_len); |
| 596 | if (data == NULL) |
| 597 | return -1; |
| 598 | pos = data; |
| 599 | *pos++ = 0x06; /* FT Action category */ |
| 600 | *pos++ = action; |
| 601 | os_memcpy(pos, wpa_s->own_addr, ETH_ALEN); |
| 602 | pos += ETH_ALEN; |
| 603 | os_memcpy(pos, target_ap, ETH_ALEN); |
| 604 | pos += ETH_ALEN; |
| 605 | os_memcpy(pos, ies, ies_len); |
| 606 | |
| 607 | ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, |
| 608 | wpa_s->bssid, wpa_s->own_addr, wpa_s->bssid, |
| 609 | data, data_len, 0); |
| 610 | os_free(data); |
| 611 | |
| 612 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | |
| 616 | static int wpa_supplicant_mark_authenticated(void *ctx, const u8 *target_ap) |
| 617 | { |
| 618 | struct wpa_supplicant *wpa_s = ctx; |
| 619 | struct wpa_driver_auth_params params; |
| 620 | struct wpa_bss *bss; |
| 621 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 622 | bss = wpa_bss_get_bssid(wpa_s, target_ap); |
| 623 | if (bss == NULL) |
| 624 | return -1; |
| 625 | |
| 626 | os_memset(¶ms, 0, sizeof(params)); |
| 627 | params.bssid = target_ap; |
| 628 | params.freq = bss->freq; |
| 629 | params.ssid = bss->ssid; |
| 630 | params.ssid_len = bss->ssid_len; |
| 631 | params.auth_alg = WPA_AUTH_ALG_FT; |
| 632 | params.local_state_change = 1; |
| 633 | return wpa_drv_authenticate(wpa_s, ¶ms); |
| 634 | } |
| 635 | #endif /* CONFIG_IEEE80211R */ |
| 636 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 637 | |
| 638 | #ifdef CONFIG_TDLS |
| 639 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 640 | static int wpa_supplicant_tdls_get_capa(void *ctx, int *tdls_supported, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 641 | int *tdls_ext_setup, |
| 642 | int *tdls_chan_switch) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 643 | { |
| 644 | struct wpa_supplicant *wpa_s = ctx; |
| 645 | |
| 646 | *tdls_supported = 0; |
| 647 | *tdls_ext_setup = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 648 | *tdls_chan_switch = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 649 | |
| 650 | if (!wpa_s->drv_capa_known) |
| 651 | return -1; |
| 652 | |
| 653 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) |
| 654 | *tdls_supported = 1; |
| 655 | |
| 656 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP) |
| 657 | *tdls_ext_setup = 1; |
| 658 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 659 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH) |
| 660 | *tdls_chan_switch = 1; |
| 661 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 662 | return 0; |
| 663 | } |
| 664 | |
| 665 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 666 | static int wpa_supplicant_send_tdls_mgmt(void *ctx, const u8 *dst, |
| 667 | u8 action_code, u8 dialog_token, |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 668 | u16 status_code, u32 peer_capab, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 669 | int initiator, const u8 *buf, |
| 670 | size_t len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 671 | { |
| 672 | struct wpa_supplicant *wpa_s = ctx; |
| 673 | return wpa_drv_send_tdls_mgmt(wpa_s, dst, action_code, dialog_token, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 674 | status_code, peer_capab, initiator, buf, |
| 675 | len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | |
| 679 | static int wpa_supplicant_tdls_oper(void *ctx, int oper, const u8 *peer) |
| 680 | { |
| 681 | struct wpa_supplicant *wpa_s = ctx; |
| 682 | return wpa_drv_tdls_oper(wpa_s, oper, peer); |
| 683 | } |
| 684 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 685 | |
| 686 | static int wpa_supplicant_tdls_peer_addset( |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 687 | void *ctx, const u8 *peer, int add, u16 aid, u16 capability, |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 688 | const u8 *supp_rates, size_t supp_rates_len, |
| 689 | const struct ieee80211_ht_capabilities *ht_capab, |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 690 | const struct ieee80211_vht_capabilities *vht_capab, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 691 | u8 qosinfo, int wmm, const u8 *ext_capab, size_t ext_capab_len, |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 692 | const u8 *supp_channels, size_t supp_channels_len, |
| 693 | const u8 *supp_oper_classes, size_t supp_oper_classes_len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 694 | { |
| 695 | struct wpa_supplicant *wpa_s = ctx; |
| 696 | struct hostapd_sta_add_params params; |
| 697 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 698 | os_memset(¶ms, 0, sizeof(params)); |
| 699 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 700 | params.addr = peer; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 701 | params.aid = aid; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 702 | params.capability = capability; |
| 703 | params.flags = WPA_STA_TDLS_PEER | WPA_STA_AUTHORIZED; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 704 | |
| 705 | /* |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 706 | * Don't rely only on qosinfo for WMM capability. It may be 0 even when |
| 707 | * present. Allow the WMM IE to also indicate QoS support. |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 708 | */ |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 709 | if (wmm || qosinfo) |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 710 | params.flags |= WPA_STA_WMM; |
| 711 | |
| 712 | params.ht_capabilities = ht_capab; |
Dmitry Shmidt | 33e38bf | 2013-02-27 12:56:00 -0800 | [diff] [blame] | 713 | params.vht_capabilities = vht_capab; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 714 | params.qosinfo = qosinfo; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 715 | params.listen_interval = 0; |
| 716 | params.supp_rates = supp_rates; |
| 717 | params.supp_rates_len = supp_rates_len; |
| 718 | params.set = !add; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 719 | params.ext_capab = ext_capab; |
| 720 | params.ext_capab_len = ext_capab_len; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 721 | params.supp_channels = supp_channels; |
| 722 | params.supp_channels_len = supp_channels_len; |
| 723 | params.supp_oper_classes = supp_oper_classes; |
| 724 | params.supp_oper_classes_len = supp_oper_classes_len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 725 | |
| 726 | return wpa_drv_sta_add(wpa_s, ¶ms); |
| 727 | } |
| 728 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 729 | |
| 730 | static int wpa_supplicant_tdls_enable_channel_switch( |
| 731 | void *ctx, const u8 *addr, u8 oper_class, |
| 732 | const struct hostapd_freq_params *params) |
| 733 | { |
| 734 | struct wpa_supplicant *wpa_s = ctx; |
| 735 | |
| 736 | return wpa_drv_tdls_enable_channel_switch(wpa_s, addr, oper_class, |
| 737 | params); |
| 738 | } |
| 739 | |
| 740 | |
| 741 | static int wpa_supplicant_tdls_disable_channel_switch(void *ctx, const u8 *addr) |
| 742 | { |
| 743 | struct wpa_supplicant *wpa_s = ctx; |
| 744 | |
| 745 | return wpa_drv_tdls_disable_channel_switch(wpa_s, addr); |
| 746 | } |
| 747 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 748 | #endif /* CONFIG_TDLS */ |
| 749 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 750 | #endif /* CONFIG_NO_WPA */ |
| 751 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 752 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 753 | enum wpa_ctrl_req_type wpa_supplicant_ctrl_req_from_string(const char *field) |
| 754 | { |
| 755 | if (os_strcmp(field, "IDENTITY") == 0) |
| 756 | return WPA_CTRL_REQ_EAP_IDENTITY; |
| 757 | else if (os_strcmp(field, "PASSWORD") == 0) |
| 758 | return WPA_CTRL_REQ_EAP_PASSWORD; |
| 759 | else if (os_strcmp(field, "NEW_PASSWORD") == 0) |
| 760 | return WPA_CTRL_REQ_EAP_NEW_PASSWORD; |
| 761 | else if (os_strcmp(field, "PIN") == 0) |
| 762 | return WPA_CTRL_REQ_EAP_PIN; |
| 763 | else if (os_strcmp(field, "OTP") == 0) |
| 764 | return WPA_CTRL_REQ_EAP_OTP; |
| 765 | else if (os_strcmp(field, "PASSPHRASE") == 0) |
| 766 | return WPA_CTRL_REQ_EAP_PASSPHRASE; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 767 | else if (os_strcmp(field, "SIM") == 0) |
| 768 | return WPA_CTRL_REQ_SIM; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 769 | else if (os_strcmp(field, "PSK_PASSPHRASE") == 0) |
| 770 | return WPA_CTRL_REQ_PSK_PASSPHRASE; |
Dmitry Shmidt | 1b46775 | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 771 | else if (os_strcmp(field, "EXT_CERT_CHECK") == 0) |
| 772 | return WPA_CTRL_REQ_EXT_CERT_CHECK; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 773 | return WPA_CTRL_REQ_UNKNOWN; |
| 774 | } |
| 775 | |
| 776 | |
| 777 | const char * wpa_supplicant_ctrl_req_to_string(enum wpa_ctrl_req_type field, |
| 778 | const char *default_txt, |
| 779 | const char **txt) |
| 780 | { |
| 781 | const char *ret = NULL; |
| 782 | |
| 783 | *txt = default_txt; |
| 784 | |
| 785 | switch (field) { |
| 786 | case WPA_CTRL_REQ_EAP_IDENTITY: |
| 787 | *txt = "Identity"; |
| 788 | ret = "IDENTITY"; |
| 789 | break; |
| 790 | case WPA_CTRL_REQ_EAP_PASSWORD: |
| 791 | *txt = "Password"; |
| 792 | ret = "PASSWORD"; |
| 793 | break; |
| 794 | case WPA_CTRL_REQ_EAP_NEW_PASSWORD: |
| 795 | *txt = "New Password"; |
| 796 | ret = "NEW_PASSWORD"; |
| 797 | break; |
| 798 | case WPA_CTRL_REQ_EAP_PIN: |
| 799 | *txt = "PIN"; |
| 800 | ret = "PIN"; |
| 801 | break; |
| 802 | case WPA_CTRL_REQ_EAP_OTP: |
| 803 | ret = "OTP"; |
| 804 | break; |
| 805 | case WPA_CTRL_REQ_EAP_PASSPHRASE: |
| 806 | *txt = "Private key passphrase"; |
| 807 | ret = "PASSPHRASE"; |
| 808 | break; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 809 | case WPA_CTRL_REQ_SIM: |
| 810 | ret = "SIM"; |
| 811 | break; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 812 | case WPA_CTRL_REQ_PSK_PASSPHRASE: |
| 813 | *txt = "PSK or passphrase"; |
| 814 | ret = "PSK_PASSPHRASE"; |
| 815 | break; |
Dmitry Shmidt | 1b46775 | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 816 | case WPA_CTRL_REQ_EXT_CERT_CHECK: |
| 817 | *txt = "External server certificate validation"; |
| 818 | ret = "EXT_CERT_CHECK"; |
| 819 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 820 | default: |
| 821 | break; |
| 822 | } |
| 823 | |
| 824 | /* txt needs to be something */ |
| 825 | if (*txt == NULL) { |
| 826 | wpa_printf(MSG_WARNING, "No message for request %d", field); |
| 827 | ret = NULL; |
| 828 | } |
| 829 | |
| 830 | return ret; |
| 831 | } |
| 832 | |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 833 | |
| 834 | void wpas_send_ctrl_req(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, |
| 835 | const char *field_name, const char *txt) |
| 836 | { |
| 837 | char *buf; |
| 838 | size_t buflen; |
| 839 | int len; |
| 840 | |
| 841 | buflen = 100 + os_strlen(txt) + ssid->ssid_len; |
| 842 | buf = os_malloc(buflen); |
| 843 | if (buf == NULL) |
| 844 | return; |
| 845 | len = os_snprintf(buf, buflen, "%s-%d:%s needed for SSID ", |
| 846 | field_name, ssid->id, txt); |
| 847 | if (os_snprintf_error(buflen, len)) { |
| 848 | os_free(buf); |
| 849 | return; |
| 850 | } |
| 851 | if (ssid->ssid && buflen > len + ssid->ssid_len) { |
| 852 | os_memcpy(buf + len, ssid->ssid, ssid->ssid_len); |
| 853 | len += ssid->ssid_len; |
| 854 | buf[len] = '\0'; |
| 855 | } |
| 856 | buf[buflen - 1] = '\0'; |
| 857 | wpa_msg(wpa_s, MSG_INFO, WPA_CTRL_REQ "%s", buf); |
| 858 | os_free(buf); |
| 859 | } |
| 860 | |
| 861 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 862 | #ifdef IEEE8021X_EAPOL |
| 863 | #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 864 | static void wpa_supplicant_eap_param_needed(void *ctx, |
| 865 | enum wpa_ctrl_req_type field, |
| 866 | const char *default_txt) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 867 | { |
| 868 | struct wpa_supplicant *wpa_s = ctx; |
| 869 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 870 | const char *field_name, *txt = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 871 | |
| 872 | if (ssid == NULL) |
| 873 | return; |
| 874 | |
Dmitry Shmidt | 1b46775 | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 875 | if (field == WPA_CTRL_REQ_EXT_CERT_CHECK) |
| 876 | ssid->eap.pending_ext_cert_check = PENDING_CHECK; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 877 | wpas_notify_network_request(wpa_s, ssid, field, default_txt); |
| 878 | |
| 879 | field_name = wpa_supplicant_ctrl_req_to_string(field, default_txt, |
| 880 | &txt); |
| 881 | if (field_name == NULL) { |
| 882 | wpa_printf(MSG_WARNING, "Unhandled EAP param %d needed", |
| 883 | field); |
| 884 | return; |
| 885 | } |
| 886 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 887 | wpas_notify_eap_status(wpa_s, "eap parameter needed", field_name); |
| 888 | |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 889 | wpas_send_ctrl_req(wpa_s, ssid, field_name, txt); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 890 | } |
| 891 | #else /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */ |
| 892 | #define wpa_supplicant_eap_param_needed NULL |
| 893 | #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */ |
| 894 | |
| 895 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 896 | #ifdef CONFIG_EAP_PROXY |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 897 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 898 | static void wpa_supplicant_eap_proxy_cb(void *ctx) |
| 899 | { |
| 900 | struct wpa_supplicant *wpa_s = ctx; |
| 901 | size_t len; |
| 902 | |
| 903 | wpa_s->mnc_len = eapol_sm_get_eap_proxy_imsi(wpa_s->eapol, |
| 904 | wpa_s->imsi, &len); |
| 905 | if (wpa_s->mnc_len > 0) { |
| 906 | wpa_s->imsi[len] = '\0'; |
| 907 | wpa_printf(MSG_DEBUG, "eap_proxy: IMSI %s (MNC length %d)", |
| 908 | wpa_s->imsi, wpa_s->mnc_len); |
| 909 | } else { |
| 910 | wpa_printf(MSG_DEBUG, "eap_proxy: IMSI not available"); |
| 911 | } |
| 912 | } |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 913 | |
| 914 | |
| 915 | static void wpa_sm_sim_state_error_handler(struct wpa_supplicant *wpa_s) |
| 916 | { |
| 917 | int i; |
| 918 | struct wpa_ssid *ssid; |
| 919 | const struct eap_method_type *eap_methods; |
| 920 | |
| 921 | if (!wpa_s->conf) |
| 922 | return; |
| 923 | |
| 924 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 925 | eap_methods = ssid->eap.eap_methods; |
| 926 | if (!eap_methods) |
| 927 | continue; |
| 928 | |
| 929 | for (i = 0; eap_methods[i].method != EAP_TYPE_NONE; i++) { |
| 930 | if (eap_methods[i].vendor == EAP_VENDOR_IETF && |
| 931 | (eap_methods[i].method == EAP_TYPE_SIM || |
| 932 | eap_methods[i].method == EAP_TYPE_AKA || |
| 933 | eap_methods[i].method == EAP_TYPE_AKA_PRIME)) { |
| 934 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); |
| 935 | break; |
| 936 | } |
| 937 | } |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | |
| 942 | static void |
| 943 | wpa_supplicant_eap_proxy_notify_sim_status(void *ctx, |
| 944 | enum eap_proxy_sim_state sim_state) |
| 945 | { |
| 946 | struct wpa_supplicant *wpa_s = ctx; |
| 947 | |
| 948 | wpa_printf(MSG_DEBUG, "eap_proxy: SIM card status %u", sim_state); |
| 949 | switch (sim_state) { |
| 950 | case SIM_STATE_ERROR: |
| 951 | wpa_sm_sim_state_error_handler(wpa_s); |
| 952 | break; |
| 953 | default: |
| 954 | wpa_printf(MSG_DEBUG, "eap_proxy: SIM card status unknown"); |
| 955 | break; |
| 956 | } |
| 957 | } |
| 958 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 959 | #endif /* CONFIG_EAP_PROXY */ |
| 960 | |
| 961 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 962 | static void wpa_supplicant_port_cb(void *ctx, int authorized) |
| 963 | { |
| 964 | struct wpa_supplicant *wpa_s = ctx; |
| 965 | #ifdef CONFIG_AP |
| 966 | if (wpa_s->ap_iface) { |
| 967 | wpa_printf(MSG_DEBUG, "AP mode active - skip EAPOL Supplicant " |
| 968 | "port status: %s", |
| 969 | authorized ? "Authorized" : "Unauthorized"); |
| 970 | return; |
| 971 | } |
| 972 | #endif /* CONFIG_AP */ |
| 973 | wpa_printf(MSG_DEBUG, "EAPOL: Supplicant port status: %s", |
| 974 | authorized ? "Authorized" : "Unauthorized"); |
| 975 | wpa_drv_set_supp_port(wpa_s, authorized); |
| 976 | } |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 977 | |
| 978 | |
| 979 | static void wpa_supplicant_cert_cb(void *ctx, int depth, const char *subject, |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 980 | const char *altsubject[], int num_altsubject, |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 981 | const char *cert_hash, |
| 982 | const struct wpabuf *cert) |
| 983 | { |
| 984 | struct wpa_supplicant *wpa_s = ctx; |
| 985 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 986 | wpas_notify_certification(wpa_s, depth, subject, altsubject, |
| 987 | num_altsubject, cert_hash, cert); |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 988 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 989 | |
| 990 | |
| 991 | static void wpa_supplicant_status_cb(void *ctx, const char *status, |
| 992 | const char *parameter) |
| 993 | { |
| 994 | struct wpa_supplicant *wpa_s = ctx; |
| 995 | |
| 996 | wpas_notify_eap_status(wpa_s, status, parameter); |
| 997 | } |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 998 | |
| 999 | |
| 1000 | static void wpa_supplicant_set_anon_id(void *ctx, const u8 *id, size_t len) |
| 1001 | { |
| 1002 | struct wpa_supplicant *wpa_s = ctx; |
| 1003 | char *str; |
| 1004 | int res; |
| 1005 | |
| 1006 | wpa_hexdump_ascii(MSG_DEBUG, "EAP method updated anonymous_identity", |
| 1007 | id, len); |
| 1008 | |
| 1009 | if (wpa_s->current_ssid == NULL) |
| 1010 | return; |
| 1011 | |
| 1012 | if (id == NULL) { |
| 1013 | if (wpa_config_set(wpa_s->current_ssid, "anonymous_identity", |
| 1014 | "NULL", 0) < 0) |
| 1015 | return; |
| 1016 | } else { |
| 1017 | str = os_malloc(len * 2 + 1); |
| 1018 | if (str == NULL) |
| 1019 | return; |
| 1020 | wpa_snprintf_hex(str, len * 2 + 1, id, len); |
| 1021 | res = wpa_config_set(wpa_s->current_ssid, "anonymous_identity", |
| 1022 | str, 0); |
| 1023 | os_free(str); |
| 1024 | if (res < 0) |
| 1025 | return; |
| 1026 | } |
| 1027 | |
| 1028 | if (wpa_s->conf->update_config) { |
| 1029 | res = wpa_config_write(wpa_s->confname, wpa_s->conf); |
| 1030 | if (res) { |
| 1031 | wpa_printf(MSG_DEBUG, "Failed to update config after " |
| 1032 | "anonymous_id update"); |
| 1033 | } |
| 1034 | } |
| 1035 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1036 | #endif /* IEEE8021X_EAPOL */ |
| 1037 | |
| 1038 | |
| 1039 | int wpa_supplicant_init_eapol(struct wpa_supplicant *wpa_s) |
| 1040 | { |
| 1041 | #ifdef IEEE8021X_EAPOL |
| 1042 | struct eapol_ctx *ctx; |
| 1043 | ctx = os_zalloc(sizeof(*ctx)); |
| 1044 | if (ctx == NULL) { |
| 1045 | wpa_printf(MSG_ERROR, "Failed to allocate EAPOL context."); |
| 1046 | return -1; |
| 1047 | } |
| 1048 | |
| 1049 | ctx->ctx = wpa_s; |
| 1050 | ctx->msg_ctx = wpa_s; |
| 1051 | ctx->eapol_send_ctx = wpa_s; |
| 1052 | ctx->preauth = 0; |
| 1053 | ctx->eapol_done_cb = wpa_supplicant_notify_eapol_done; |
| 1054 | ctx->eapol_send = wpa_supplicant_eapol_send; |
| 1055 | ctx->set_wep_key = wpa_eapol_set_wep_key; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 1056 | #ifndef CONFIG_NO_CONFIG_BLOBS |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1057 | ctx->set_config_blob = wpa_supplicant_set_config_blob; |
| 1058 | ctx->get_config_blob = wpa_supplicant_get_config_blob; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 1059 | #endif /* CONFIG_NO_CONFIG_BLOBS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1060 | ctx->aborted_cached = wpa_supplicant_aborted_cached; |
| 1061 | ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path; |
| 1062 | ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path; |
| 1063 | ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1064 | ctx->openssl_ciphers = wpa_s->conf->openssl_ciphers; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1065 | ctx->wps = wpa_s->wps; |
| 1066 | ctx->eap_param_needed = wpa_supplicant_eap_param_needed; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1067 | #ifdef CONFIG_EAP_PROXY |
| 1068 | ctx->eap_proxy_cb = wpa_supplicant_eap_proxy_cb; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 1069 | ctx->eap_proxy_notify_sim_status = |
| 1070 | wpa_supplicant_eap_proxy_notify_sim_status; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1071 | #endif /* CONFIG_EAP_PROXY */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1072 | ctx->port_cb = wpa_supplicant_port_cb; |
| 1073 | ctx->cb = wpa_supplicant_eapol_cb; |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 1074 | ctx->cert_cb = wpa_supplicant_cert_cb; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1075 | ctx->cert_in_cb = wpa_s->conf->cert_in_cb; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1076 | ctx->status_cb = wpa_supplicant_status_cb; |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 1077 | ctx->set_anon_id = wpa_supplicant_set_anon_id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1078 | ctx->cb_ctx = wpa_s; |
| 1079 | wpa_s->eapol = eapol_sm_init(ctx); |
| 1080 | if (wpa_s->eapol == NULL) { |
| 1081 | os_free(ctx); |
| 1082 | wpa_printf(MSG_ERROR, "Failed to initialize EAPOL state " |
| 1083 | "machines."); |
| 1084 | return -1; |
| 1085 | } |
| 1086 | #endif /* IEEE8021X_EAPOL */ |
| 1087 | |
| 1088 | return 0; |
| 1089 | } |
| 1090 | |
| 1091 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1092 | #ifndef CONFIG_NO_WPA |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame^] | 1093 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 1094 | static void wpa_supplicant_set_rekey_offload(void *ctx, |
| 1095 | const u8 *kek, size_t kek_len, |
| 1096 | const u8 *kck, size_t kck_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1097 | const u8 *replay_ctr) |
| 1098 | { |
| 1099 | struct wpa_supplicant *wpa_s = ctx; |
| 1100 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 1101 | wpa_drv_set_rekey_info(wpa_s, kek, kek_len, kck, kck_len, replay_ctr); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1105 | static int wpa_supplicant_key_mgmt_set_pmk(void *ctx, const u8 *pmk, |
| 1106 | size_t pmk_len) |
| 1107 | { |
| 1108 | struct wpa_supplicant *wpa_s = ctx; |
| 1109 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 1110 | if (wpa_s->conf->key_mgmt_offload && |
| 1111 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1112 | return wpa_drv_set_key(wpa_s, WPA_ALG_PMK, NULL, 0, 0, |
| 1113 | NULL, 0, pmk, pmk_len); |
| 1114 | else |
| 1115 | return 0; |
| 1116 | } |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame^] | 1117 | |
| 1118 | |
| 1119 | static void wpa_supplicant_fils_hlp_rx(void *ctx, const u8 *dst, const u8 *src, |
| 1120 | const u8 *pkt, size_t pkt_len) |
| 1121 | { |
| 1122 | struct wpa_supplicant *wpa_s = ctx; |
| 1123 | char *hex; |
| 1124 | size_t hexlen; |
| 1125 | |
| 1126 | hexlen = pkt_len * 2 + 1; |
| 1127 | hex = os_malloc(hexlen); |
| 1128 | if (!hex) |
| 1129 | return; |
| 1130 | wpa_snprintf_hex(hex, hexlen, pkt, pkt_len); |
| 1131 | wpa_msg(wpa_s, MSG_INFO, FILS_HLP_RX "dst=" MACSTR " src=" MACSTR |
| 1132 | " frame=%s", MAC2STR(dst), MAC2STR(src), hex); |
| 1133 | os_free(hex); |
| 1134 | } |
| 1135 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 1136 | #endif /* CONFIG_NO_WPA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1137 | |
| 1138 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1139 | int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s) |
| 1140 | { |
| 1141 | #ifndef CONFIG_NO_WPA |
| 1142 | struct wpa_sm_ctx *ctx; |
| 1143 | ctx = os_zalloc(sizeof(*ctx)); |
| 1144 | if (ctx == NULL) { |
| 1145 | wpa_printf(MSG_ERROR, "Failed to allocate WPA context."); |
| 1146 | return -1; |
| 1147 | } |
| 1148 | |
| 1149 | ctx->ctx = wpa_s; |
| 1150 | ctx->msg_ctx = wpa_s; |
| 1151 | ctx->set_state = _wpa_supplicant_set_state; |
| 1152 | ctx->get_state = _wpa_supplicant_get_state; |
| 1153 | ctx->deauthenticate = _wpa_supplicant_deauthenticate; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1154 | ctx->set_key = wpa_supplicant_set_key; |
| 1155 | ctx->get_network_ctx = wpa_supplicant_get_network_ctx; |
| 1156 | ctx->get_bssid = wpa_supplicant_get_bssid; |
| 1157 | ctx->ether_send = _wpa_ether_send; |
| 1158 | ctx->get_beacon_ie = wpa_supplicant_get_beacon_ie; |
| 1159 | ctx->alloc_eapol = _wpa_alloc_eapol; |
| 1160 | ctx->cancel_auth_timeout = _wpa_supplicant_cancel_auth_timeout; |
| 1161 | ctx->add_pmkid = wpa_supplicant_add_pmkid; |
| 1162 | ctx->remove_pmkid = wpa_supplicant_remove_pmkid; |
| 1163 | #ifndef CONFIG_NO_CONFIG_BLOBS |
| 1164 | ctx->set_config_blob = wpa_supplicant_set_config_blob; |
| 1165 | ctx->get_config_blob = wpa_supplicant_get_config_blob; |
| 1166 | #endif /* CONFIG_NO_CONFIG_BLOBS */ |
| 1167 | ctx->mlme_setprotection = wpa_supplicant_mlme_setprotection; |
| 1168 | #ifdef CONFIG_IEEE80211R |
| 1169 | ctx->update_ft_ies = wpa_supplicant_update_ft_ies; |
| 1170 | ctx->send_ft_action = wpa_supplicant_send_ft_action; |
| 1171 | ctx->mark_authenticated = wpa_supplicant_mark_authenticated; |
| 1172 | #endif /* CONFIG_IEEE80211R */ |
| 1173 | #ifdef CONFIG_TDLS |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1174 | ctx->tdls_get_capa = wpa_supplicant_tdls_get_capa; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1175 | ctx->send_tdls_mgmt = wpa_supplicant_send_tdls_mgmt; |
| 1176 | ctx->tdls_oper = wpa_supplicant_tdls_oper; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1177 | ctx->tdls_peer_addset = wpa_supplicant_tdls_peer_addset; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1178 | ctx->tdls_enable_channel_switch = |
| 1179 | wpa_supplicant_tdls_enable_channel_switch; |
| 1180 | ctx->tdls_disable_channel_switch = |
| 1181 | wpa_supplicant_tdls_disable_channel_switch; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1182 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1183 | ctx->set_rekey_offload = wpa_supplicant_set_rekey_offload; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1184 | ctx->key_mgmt_set_pmk = wpa_supplicant_key_mgmt_set_pmk; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame^] | 1185 | ctx->fils_hlp_rx = wpa_supplicant_fils_hlp_rx; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1186 | |
| 1187 | wpa_s->wpa = wpa_sm_init(ctx); |
| 1188 | if (wpa_s->wpa == NULL) { |
| 1189 | wpa_printf(MSG_ERROR, "Failed to initialize WPA state " |
| 1190 | "machine"); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1191 | os_free(ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1192 | return -1; |
| 1193 | } |
| 1194 | #endif /* CONFIG_NO_WPA */ |
| 1195 | |
| 1196 | return 0; |
| 1197 | } |
| 1198 | |
| 1199 | |
| 1200 | void wpa_supplicant_rsn_supp_set_config(struct wpa_supplicant *wpa_s, |
| 1201 | struct wpa_ssid *ssid) |
| 1202 | { |
| 1203 | struct rsn_supp_config conf; |
| 1204 | if (ssid) { |
| 1205 | os_memset(&conf, 0, sizeof(conf)); |
| 1206 | conf.network_ctx = ssid; |
| 1207 | conf.peerkey_enabled = ssid->peerkey; |
| 1208 | conf.allowed_pairwise_cipher = ssid->pairwise_cipher; |
| 1209 | #ifdef IEEE8021X_EAPOL |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1210 | conf.proactive_key_caching = ssid->proactive_key_caching < 0 ? |
| 1211 | wpa_s->conf->okc : ssid->proactive_key_caching; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1212 | conf.eap_workaround = ssid->eap_workaround; |
| 1213 | conf.eap_conf_ctx = &ssid->eap; |
| 1214 | #endif /* IEEE8021X_EAPOL */ |
| 1215 | conf.ssid = ssid->ssid; |
| 1216 | conf.ssid_len = ssid->ssid_len; |
| 1217 | conf.wpa_ptk_rekey = ssid->wpa_ptk_rekey; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1218 | #ifdef CONFIG_P2P |
| 1219 | if (ssid->p2p_group && wpa_s->current_bss && |
| 1220 | !wpa_s->p2p_disable_ip_addr_req) { |
| 1221 | struct wpabuf *p2p; |
| 1222 | p2p = wpa_bss_get_vendor_ie_multi(wpa_s->current_bss, |
| 1223 | P2P_IE_VENDOR_TYPE); |
| 1224 | if (p2p) { |
| 1225 | u8 group_capab; |
| 1226 | group_capab = p2p_get_group_capab(p2p); |
| 1227 | if (group_capab & |
| 1228 | P2P_GROUP_CAPAB_IP_ADDR_ALLOCATION) |
| 1229 | conf.p2p = 1; |
| 1230 | wpabuf_free(p2p); |
| 1231 | } |
| 1232 | } |
| 1233 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1234 | conf.wpa_rsc_relaxation = wpa_s->conf->wpa_rsc_relaxation; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1235 | } |
| 1236 | wpa_sm_set_config(wpa_s->wpa, ssid ? &conf : NULL); |
| 1237 | } |