blob: d80b8f28dda4e0b9fb0f6e17bdf137dae75f0abb [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Glue code to setup EAPOL and RSN modules
Dmitry Shmidt807291d2015-01-27 13:40:23 -08003 * Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "includes.h"
10
11#include "common.h"
12#include "eapol_supp/eapol_supp_sm.h"
Dmitry Shmidt29333592017-01-09 12:27:11 -080013#include "eap_peer/eap.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014#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 Shmidt8d520ff2011-05-09 14:06:53 -070022#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 Shmidtc55524a2011-07-07 11:18:38 -070029#include "notify.h"
Dmitry Shmidt5a1480c2014-05-12 09:46:02 -070030#include "wpas_kay.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070031
32
33#ifndef CONFIG_NO_CONFIG_BLOBS
34#if defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA)
35static 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
50static const struct wpa_config_blob *
51wpa_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)
61static 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 */
97static int wpa_ether_send(struct wpa_supplicant *wpa_s, const u8 *dest,
98 u16 proto, const u8 *buf, size_t len)
99{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800100#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 Shmidt8d520ff2011-05-09 14:06:53 -0700115 if (wpa_s->l2) {
116 return l2_packet_send(wpa_s->l2, dest, proto, buf, len);
117 }
118
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800119 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700120}
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 */
137static 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) ||
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700149 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
150 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700151 wpa_s->key_mgmt == WPA_KEY_MGMT_NONE) {
152 /* Current SSID is not using IEEE 802.1X/EAP, so drop possible
153 * EAPOL frames (mainly, EAPOL-Start) from EAPOL state
154 * machines. */
155 wpa_printf(MSG_DEBUG, "WPA: drop TX EAPOL in non-IEEE 802.1X "
156 "mode (type=%d len=%lu)", type,
157 (unsigned long) len);
158 return -1;
159 }
160
161 if (pmksa_cache_get_current(wpa_s->wpa) &&
162 type == IEEE802_1X_TYPE_EAPOL_START) {
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700163 /*
164 * We were trying to use PMKSA caching and sending EAPOL-Start
165 * would abort that and trigger full EAPOL authentication.
166 * However, we've already waited for the AP/Authenticator to
167 * start 4-way handshake or EAP authentication, and apparently
168 * it has not done so since the startWhen timer has reached zero
169 * to get the state machine sending EAPOL-Start. This is not
170 * really supposed to happen, but an interoperability issue with
171 * a deployed AP has been identified where the connection fails
172 * due to that AP failing to operate correctly if PMKID is
173 * included in the Association Request frame. To work around
174 * this, assume PMKSA caching failed and try to initiate full
175 * EAP authentication.
176 */
177 if (!wpa_s->current_ssid ||
178 wpa_s->current_ssid->eap_workaround) {
179 wpa_printf(MSG_DEBUG,
180 "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");
181 } else {
182 wpa_printf(MSG_DEBUG,
183 "RSN: PMKSA caching - do not send EAPOL-Start");
184 return -1;
185 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700186 }
187
188 if (is_zero_ether_addr(wpa_s->bssid)) {
189 wpa_printf(MSG_DEBUG, "BSSID not set when trying to send an "
190 "EAPOL frame");
191 if (wpa_drv_get_bssid(wpa_s, bssid) == 0 &&
192 !is_zero_ether_addr(bssid)) {
193 dst = bssid;
194 wpa_printf(MSG_DEBUG, "Using current BSSID " MACSTR
195 " from the driver as the EAPOL destination",
196 MAC2STR(dst));
197 } else {
198 dst = wpa_s->last_eapol_src;
199 wpa_printf(MSG_DEBUG, "Using the source address of the"
200 " last received EAPOL frame " MACSTR " as "
201 "the EAPOL destination",
202 MAC2STR(dst));
203 }
204 } else {
205 /* BSSID was already set (from (Re)Assoc event, so use it as
206 * the EAPOL destination. */
207 dst = wpa_s->bssid;
208 }
209
210 msg = wpa_alloc_eapol(wpa_s, type, buf, len, &msglen, NULL);
211 if (msg == NULL)
212 return -1;
213
214 wpa_printf(MSG_DEBUG, "TX EAPOL: dst=" MACSTR, MAC2STR(dst));
215 wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", msg, msglen);
216 res = wpa_ether_send(wpa_s, dst, ETH_P_EAPOL, msg, msglen);
217 os_free(msg);
218 return res;
219}
220
221
222/**
223 * wpa_eapol_set_wep_key - set WEP key for the driver
224 * @ctx: Pointer to wpa_supplicant data (wpa_s)
225 * @unicast: 1 = individual unicast key, 0 = broadcast key
226 * @keyidx: WEP key index (0..3)
227 * @key: Pointer to key data
228 * @keylen: Key length in bytes
229 * Returns: 0 on success or < 0 on error.
230 */
231static int wpa_eapol_set_wep_key(void *ctx, int unicast, int keyidx,
232 const u8 *key, size_t keylen)
233{
234 struct wpa_supplicant *wpa_s = ctx;
235 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
236 int cipher = (keylen == 5) ? WPA_CIPHER_WEP40 :
237 WPA_CIPHER_WEP104;
238 if (unicast)
239 wpa_s->pairwise_cipher = cipher;
240 else
241 wpa_s->group_cipher = cipher;
242 }
243 return wpa_drv_set_key(wpa_s, WPA_ALG_WEP,
244 unicast ? wpa_s->bssid : NULL,
245 keyidx, unicast, NULL, 0, key, keylen);
246}
247
248
249static void wpa_supplicant_aborted_cached(void *ctx)
250{
251 struct wpa_supplicant *wpa_s = ctx;
252 wpa_sm_aborted_cached(wpa_s->wpa);
253}
254
255
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800256static const char * result_str(enum eapol_supp_result result)
257{
258 switch (result) {
259 case EAPOL_SUPP_RESULT_FAILURE:
260 return "FAILURE";
261 case EAPOL_SUPP_RESULT_SUCCESS:
262 return "SUCCESS";
263 case EAPOL_SUPP_RESULT_EXPECTED_FAILURE:
264 return "EXPECTED_FAILURE";
265 }
266 return "?";
267}
268
269
270static void wpa_supplicant_eapol_cb(struct eapol_sm *eapol,
271 enum eapol_supp_result result,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700272 void *ctx)
273{
274 struct wpa_supplicant *wpa_s = ctx;
275 int res, pmk_len;
276 u8 pmk[PMK_LEN];
277
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800278 wpa_printf(MSG_DEBUG, "EAPOL authentication completed - result=%s",
279 result_str(result));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700280
281 if (wpas_wps_eapol_cb(wpa_s) > 0)
282 return;
283
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800284 wpa_s->eap_expected_failure = result ==
285 EAPOL_SUPP_RESULT_EXPECTED_FAILURE;
286
287 if (result != EAPOL_SUPP_RESULT_SUCCESS) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700288 /*
289 * Make sure we do not get stuck here waiting for long EAPOL
290 * timeout if the AP does not disconnect in case of
291 * authentication failure.
292 */
293 wpa_supplicant_req_auth_timeout(wpa_s, 2, 0);
Dmitry Shmidt5a1480c2014-05-12 09:46:02 -0700294 } else {
295 ieee802_1x_notify_create_actor(wpa_s, wpa_s->last_eapol_src);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700296 }
297
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800298 if (result != EAPOL_SUPP_RESULT_SUCCESS ||
Hai Shalom74f70d42019-02-11 14:42:39 -0800299 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700300 return;
301
302 if (!wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt))
303 return;
304
305 wpa_printf(MSG_DEBUG, "Configure PMK for driver-based RSN 4-way "
306 "handshake");
307
308 pmk_len = PMK_LEN;
309 if (wpa_key_mgmt_ft(wpa_s->key_mgmt)) {
310#ifdef CONFIG_IEEE80211R
311 u8 buf[2 * PMK_LEN];
312 wpa_printf(MSG_DEBUG, "RSN: Use FT XXKey as PMK for "
313 "driver-based 4-way hs and FT");
314 res = eapol_sm_get_key(eapol, buf, 2 * PMK_LEN);
315 if (res == 0) {
316 os_memcpy(pmk, buf + PMK_LEN, PMK_LEN);
317 os_memset(buf, 0, sizeof(buf));
318 }
319#else /* CONFIG_IEEE80211R */
320 res = -1;
321#endif /* CONFIG_IEEE80211R */
322 } else {
323 res = eapol_sm_get_key(eapol, pmk, PMK_LEN);
324 if (res) {
325 /*
326 * EAP-LEAP is an exception from other EAP methods: it
327 * uses only 16-byte PMK.
328 */
329 res = eapol_sm_get_key(eapol, pmk, 16);
330 pmk_len = 16;
331 }
332 }
333
334 if (res) {
335 wpa_printf(MSG_DEBUG, "Failed to get PMK from EAPOL state "
336 "machines");
337 return;
338 }
339
340 wpa_hexdump_key(MSG_DEBUG, "RSN: Configure PMK for driver-based 4-way "
341 "handshake", pmk, pmk_len);
342
343 if (wpa_drv_set_key(wpa_s, WPA_ALG_PMK, NULL, 0, 0, NULL, 0, pmk,
344 pmk_len)) {
345 wpa_printf(MSG_DEBUG, "Failed to set PMK to the driver");
346 }
347
348 wpa_supplicant_cancel_scan(wpa_s);
349 wpa_supplicant_cancel_auth_timeout(wpa_s);
350 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
351
352}
353
354
355static void wpa_supplicant_notify_eapol_done(void *ctx)
356{
357 struct wpa_supplicant *wpa_s = ctx;
358 wpa_msg(wpa_s, MSG_DEBUG, "WPA: EAPOL processing complete");
359 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
360 wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE);
361 } else {
362 wpa_supplicant_cancel_auth_timeout(wpa_s);
363 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
364 }
365}
366
367#endif /* IEEE8021X_EAPOL */
368
369
370#ifndef CONFIG_NO_WPA
371
372static int wpa_get_beacon_ie(struct wpa_supplicant *wpa_s)
373{
374 int ret = 0;
375 struct wpa_bss *curr = NULL, *bss;
376 struct wpa_ssid *ssid = wpa_s->current_ssid;
377 const u8 *ie;
378
379 dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
380 if (os_memcmp(bss->bssid, wpa_s->bssid, ETH_ALEN) != 0)
381 continue;
382 if (ssid == NULL ||
383 ((bss->ssid_len == ssid->ssid_len &&
384 os_memcmp(bss->ssid, ssid->ssid, ssid->ssid_len) == 0) ||
385 ssid->ssid_len == 0)) {
386 curr = bss;
387 break;
388 }
389 }
390
391 if (curr) {
392 ie = wpa_bss_get_vendor_ie(curr, WPA_IE_VENDOR_TYPE);
393 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
394 ret = -1;
395
396 ie = wpa_bss_get_ie(curr, WLAN_EID_RSN);
397 if (wpa_sm_set_ap_rsn_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
398 ret = -1;
Hai Shalomc3565922019-10-28 11:58:20 -0700399
400 ie = wpa_bss_get_ie(curr, WLAN_EID_RSNX);
401 if (wpa_sm_set_ap_rsnxe(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
402 ret = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700403 } else {
404 ret = -1;
405 }
406
407 return ret;
408}
409
410
411static int wpa_supplicant_get_beacon_ie(void *ctx)
412{
413 struct wpa_supplicant *wpa_s = ctx;
414 if (wpa_get_beacon_ie(wpa_s) == 0) {
415 return 0;
416 }
417
418 /* No WPA/RSN IE found in the cached scan results. Try to get updated
419 * scan results from the driver. */
420 if (wpa_supplicant_update_scan_results(wpa_s) < 0)
421 return -1;
422
423 return wpa_get_beacon_ie(wpa_s);
424}
425
426
427static u8 * _wpa_alloc_eapol(void *wpa_s, u8 type,
428 const void *data, u16 data_len,
429 size_t *msg_len, void **data_pos)
430{
431 return wpa_alloc_eapol(wpa_s, type, data, data_len, msg_len, data_pos);
432}
433
434
435static int _wpa_ether_send(void *wpa_s, const u8 *dest, u16 proto,
436 const u8 *buf, size_t len)
437{
438 return wpa_ether_send(wpa_s, dest, proto, buf, len);
439}
440
441
442static void _wpa_supplicant_cancel_auth_timeout(void *wpa_s)
443{
444 wpa_supplicant_cancel_auth_timeout(wpa_s);
445}
446
447
448static void _wpa_supplicant_set_state(void *wpa_s, enum wpa_states state)
449{
450 wpa_supplicant_set_state(wpa_s, state);
451}
452
453
454/**
455 * wpa_supplicant_get_state - Get the connection state
456 * @wpa_s: Pointer to wpa_supplicant data
457 * Returns: The current connection state (WPA_*)
458 */
459static enum wpa_states wpa_supplicant_get_state(struct wpa_supplicant *wpa_s)
460{
461 return wpa_s->wpa_state;
462}
463
464
465static enum wpa_states _wpa_supplicant_get_state(void *wpa_s)
466{
467 return wpa_supplicant_get_state(wpa_s);
468}
469
470
Hai Shalom81f62d82019-07-22 12:10:00 -0700471static void _wpa_supplicant_deauthenticate(void *wpa_s, u16 reason_code)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700472{
473 wpa_supplicant_deauthenticate(wpa_s, reason_code);
474 /* Schedule a scan to make sure we continue looking for networks */
475 wpa_supplicant_req_scan(wpa_s, 5, 0);
476}
477
478
479static void * wpa_supplicant_get_network_ctx(void *wpa_s)
480{
481 return wpa_supplicant_get_ssid(wpa_s);
482}
483
484
485static int wpa_supplicant_get_bssid(void *ctx, u8 *bssid)
486{
487 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700488 return wpa_drv_get_bssid(wpa_s, bssid);
489}
490
491
492static int wpa_supplicant_set_key(void *_wpa_s, enum wpa_alg alg,
493 const u8 *addr, int key_idx, int set_tx,
494 const u8 *seq, size_t seq_len,
495 const u8 *key, size_t key_len)
496{
497 struct wpa_supplicant *wpa_s = _wpa_s;
498 if (alg == WPA_ALG_TKIP && key_idx == 0 && key_len == 32) {
499 /* Clear the MIC error counter when setting a new PTK. */
500 wpa_s->mic_errors_seen = 0;
501 }
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700502#ifdef CONFIG_TESTING_GET_GTK
503 if (key_idx > 0 && addr && is_broadcast_ether_addr(addr) &&
504 alg != WPA_ALG_NONE && key_len <= sizeof(wpa_s->last_gtk)) {
505 os_memcpy(wpa_s->last_gtk, key, key_len);
506 wpa_s->last_gtk_len = key_len;
507 }
508#endif /* CONFIG_TESTING_GET_GTK */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700509#ifdef CONFIG_TESTING_OPTIONS
510 if (addr && !is_broadcast_ether_addr(addr)) {
511 wpa_s->last_tk_alg = alg;
512 os_memcpy(wpa_s->last_tk_addr, addr, ETH_ALEN);
513 wpa_s->last_tk_key_idx = key_idx;
514 if (key)
515 os_memcpy(wpa_s->last_tk, key, key_len);
516 wpa_s->last_tk_len = key_len;
517 }
518#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700519 return wpa_drv_set_key(wpa_s, alg, addr, key_idx, set_tx, seq, seq_len,
520 key, key_len);
521}
522
523
524static int wpa_supplicant_mlme_setprotection(void *wpa_s, const u8 *addr,
525 int protection_type,
526 int key_type)
527{
528 return wpa_drv_mlme_setprotection(wpa_s, addr, protection_type,
529 key_type);
530}
531
532
Dmitry Shmidt29333592017-01-09 12:27:11 -0800533static struct wpa_ssid * wpas_get_network_ctx(struct wpa_supplicant *wpa_s,
534 void *network_ctx)
535{
536 struct wpa_ssid *ssid;
537
538 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
539 if (network_ctx == ssid)
540 return ssid;
541 }
542
543 return NULL;
544}
545
546
547static int wpa_supplicant_add_pmkid(void *_wpa_s, void *network_ctx,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700548 const u8 *bssid, const u8 *pmkid,
549 const u8 *fils_cache_id,
550 const u8 *pmk, size_t pmk_len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700551{
Dmitry Shmidt29333592017-01-09 12:27:11 -0800552 struct wpa_supplicant *wpa_s = _wpa_s;
553 struct wpa_ssid *ssid;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700554 struct wpa_pmkid_params params;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800555
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700556 os_memset(&params, 0, sizeof(params));
Dmitry Shmidt29333592017-01-09 12:27:11 -0800557 ssid = wpas_get_network_ctx(wpa_s, network_ctx);
558 if (ssid)
559 wpa_msg(wpa_s, MSG_INFO, PMKSA_CACHE_ADDED MACSTR " %d",
560 MAC2STR(bssid), ssid->id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700561 if (ssid && fils_cache_id) {
562 params.ssid = ssid->ssid;
563 params.ssid_len = ssid->ssid_len;
564 params.fils_cache_id = fils_cache_id;
565 } else {
566 params.bssid = bssid;
567 }
568
569 params.pmkid = pmkid;
570 params.pmk = pmk;
571 params.pmk_len = pmk_len;
572
573 return wpa_drv_add_pmkid(wpa_s, &params);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700574}
575
576
Dmitry Shmidt29333592017-01-09 12:27:11 -0800577static int wpa_supplicant_remove_pmkid(void *_wpa_s, void *network_ctx,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700578 const u8 *bssid, const u8 *pmkid,
579 const u8 *fils_cache_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700580{
Dmitry Shmidt29333592017-01-09 12:27:11 -0800581 struct wpa_supplicant *wpa_s = _wpa_s;
582 struct wpa_ssid *ssid;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700583 struct wpa_pmkid_params params;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800584
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700585 os_memset(&params, 0, sizeof(params));
Dmitry Shmidt29333592017-01-09 12:27:11 -0800586 ssid = wpas_get_network_ctx(wpa_s, network_ctx);
587 if (ssid)
588 wpa_msg(wpa_s, MSG_INFO, PMKSA_CACHE_REMOVED MACSTR " %d",
589 MAC2STR(bssid), ssid->id);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700590 if (ssid && fils_cache_id) {
591 params.ssid = ssid->ssid;
592 params.ssid_len = ssid->ssid_len;
593 params.fils_cache_id = fils_cache_id;
594 } else {
595 params.bssid = bssid;
596 }
597
598 params.pmkid = pmkid;
599
600 return wpa_drv_remove_pmkid(wpa_s, &params);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700601}
602
603
604#ifdef CONFIG_IEEE80211R
605static int wpa_supplicant_update_ft_ies(void *ctx, const u8 *md,
606 const u8 *ies, size_t ies_len)
607{
608 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700609 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
610 return sme_update_ft_ies(wpa_s, md, ies, ies_len);
611 return wpa_drv_update_ft_ies(wpa_s, md, ies, ies_len);
612}
613
614
615static int wpa_supplicant_send_ft_action(void *ctx, u8 action,
616 const u8 *target_ap,
617 const u8 *ies, size_t ies_len)
618{
619 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800620 int ret;
621 u8 *data, *pos;
622 size_t data_len;
623
624 if (action != 1) {
625 wpa_printf(MSG_ERROR, "Unsupported send_ft_action action %d",
626 action);
627 return -1;
628 }
629
630 /*
631 * Action frame payload:
632 * Category[1] = 6 (Fast BSS Transition)
633 * Action[1] = 1 (Fast BSS Transition Request)
634 * STA Address
635 * Target AP Address
636 * FT IEs
637 */
638
639 data_len = 2 + 2 * ETH_ALEN + ies_len;
640 data = os_malloc(data_len);
641 if (data == NULL)
642 return -1;
643 pos = data;
644 *pos++ = 0x06; /* FT Action category */
645 *pos++ = action;
646 os_memcpy(pos, wpa_s->own_addr, ETH_ALEN);
647 pos += ETH_ALEN;
648 os_memcpy(pos, target_ap, ETH_ALEN);
649 pos += ETH_ALEN;
650 os_memcpy(pos, ies, ies_len);
651
652 ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0,
653 wpa_s->bssid, wpa_s->own_addr, wpa_s->bssid,
654 data, data_len, 0);
655 os_free(data);
656
657 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700658}
659
660
661static int wpa_supplicant_mark_authenticated(void *ctx, const u8 *target_ap)
662{
663 struct wpa_supplicant *wpa_s = ctx;
664 struct wpa_driver_auth_params params;
665 struct wpa_bss *bss;
666
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700667 bss = wpa_bss_get_bssid(wpa_s, target_ap);
668 if (bss == NULL)
669 return -1;
670
671 os_memset(&params, 0, sizeof(params));
672 params.bssid = target_ap;
673 params.freq = bss->freq;
674 params.ssid = bss->ssid;
675 params.ssid_len = bss->ssid_len;
676 params.auth_alg = WPA_AUTH_ALG_FT;
677 params.local_state_change = 1;
678 return wpa_drv_authenticate(wpa_s, &params);
679}
680#endif /* CONFIG_IEEE80211R */
681
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700682
683#ifdef CONFIG_TDLS
684
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800685static int wpa_supplicant_tdls_get_capa(void *ctx, int *tdls_supported,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800686 int *tdls_ext_setup,
687 int *tdls_chan_switch)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800688{
689 struct wpa_supplicant *wpa_s = ctx;
690
691 *tdls_supported = 0;
692 *tdls_ext_setup = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800693 *tdls_chan_switch = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800694
695 if (!wpa_s->drv_capa_known)
696 return -1;
697
698 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)
699 *tdls_supported = 1;
700
701 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP)
702 *tdls_ext_setup = 1;
703
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800704 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)
705 *tdls_chan_switch = 1;
706
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800707 return 0;
708}
709
710
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700711static int wpa_supplicant_send_tdls_mgmt(void *ctx, const u8 *dst,
712 u8 action_code, u8 dialog_token,
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700713 u16 status_code, u32 peer_capab,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700714 int initiator, const u8 *buf,
715 size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700716{
717 struct wpa_supplicant *wpa_s = ctx;
718 return wpa_drv_send_tdls_mgmt(wpa_s, dst, action_code, dialog_token,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700719 status_code, peer_capab, initiator, buf,
720 len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700721}
722
723
724static int wpa_supplicant_tdls_oper(void *ctx, int oper, const u8 *peer)
725{
726 struct wpa_supplicant *wpa_s = ctx;
727 return wpa_drv_tdls_oper(wpa_s, oper, peer);
728}
729
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800730
731static int wpa_supplicant_tdls_peer_addset(
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -0700732 void *ctx, const u8 *peer, int add, u16 aid, u16 capability,
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800733 const u8 *supp_rates, size_t supp_rates_len,
734 const struct ieee80211_ht_capabilities *ht_capab,
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -0800735 const struct ieee80211_vht_capabilities *vht_capab,
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700736 u8 qosinfo, int wmm, const u8 *ext_capab, size_t ext_capab_len,
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800737 const u8 *supp_channels, size_t supp_channels_len,
738 const u8 *supp_oper_classes, size_t supp_oper_classes_len)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800739{
740 struct wpa_supplicant *wpa_s = ctx;
741 struct hostapd_sta_add_params params;
742
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800743 os_memset(&params, 0, sizeof(params));
744
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800745 params.addr = peer;
Dmitry Shmidt51b6ea82013-05-08 10:42:09 -0700746 params.aid = aid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800747 params.capability = capability;
748 params.flags = WPA_STA_TDLS_PEER | WPA_STA_AUTHORIZED;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800749
750 /*
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700751 * Don't rely only on qosinfo for WMM capability. It may be 0 even when
752 * present. Allow the WMM IE to also indicate QoS support.
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800753 */
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700754 if (wmm || qosinfo)
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800755 params.flags |= WPA_STA_WMM;
756
757 params.ht_capabilities = ht_capab;
Dmitry Shmidt33e38bf2013-02-27 12:56:00 -0800758 params.vht_capabilities = vht_capab;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800759 params.qosinfo = qosinfo;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800760 params.listen_interval = 0;
761 params.supp_rates = supp_rates;
762 params.supp_rates_len = supp_rates_len;
763 params.set = !add;
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800764 params.ext_capab = ext_capab;
765 params.ext_capab_len = ext_capab_len;
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800766 params.supp_channels = supp_channels;
767 params.supp_channels_len = supp_channels_len;
768 params.supp_oper_classes = supp_oper_classes;
769 params.supp_oper_classes_len = supp_oper_classes_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800770
771 return wpa_drv_sta_add(wpa_s, &params);
772}
773
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800774
775static int wpa_supplicant_tdls_enable_channel_switch(
776 void *ctx, const u8 *addr, u8 oper_class,
777 const struct hostapd_freq_params *params)
778{
779 struct wpa_supplicant *wpa_s = ctx;
780
781 return wpa_drv_tdls_enable_channel_switch(wpa_s, addr, oper_class,
782 params);
783}
784
785
786static int wpa_supplicant_tdls_disable_channel_switch(void *ctx, const u8 *addr)
787{
788 struct wpa_supplicant *wpa_s = ctx;
789
790 return wpa_drv_tdls_disable_channel_switch(wpa_s, addr);
791}
792
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700793#endif /* CONFIG_TDLS */
794
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700795#endif /* CONFIG_NO_WPA */
796
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700797
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800798enum wpa_ctrl_req_type wpa_supplicant_ctrl_req_from_string(const char *field)
799{
800 if (os_strcmp(field, "IDENTITY") == 0)
801 return WPA_CTRL_REQ_EAP_IDENTITY;
802 else if (os_strcmp(field, "PASSWORD") == 0)
803 return WPA_CTRL_REQ_EAP_PASSWORD;
804 else if (os_strcmp(field, "NEW_PASSWORD") == 0)
805 return WPA_CTRL_REQ_EAP_NEW_PASSWORD;
806 else if (os_strcmp(field, "PIN") == 0)
807 return WPA_CTRL_REQ_EAP_PIN;
808 else if (os_strcmp(field, "OTP") == 0)
809 return WPA_CTRL_REQ_EAP_OTP;
810 else if (os_strcmp(field, "PASSPHRASE") == 0)
811 return WPA_CTRL_REQ_EAP_PASSPHRASE;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700812 else if (os_strcmp(field, "SIM") == 0)
813 return WPA_CTRL_REQ_SIM;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700814 else if (os_strcmp(field, "PSK_PASSPHRASE") == 0)
815 return WPA_CTRL_REQ_PSK_PASSPHRASE;
Dmitry Shmidt1b467752015-12-14 12:45:46 -0800816 else if (os_strcmp(field, "EXT_CERT_CHECK") == 0)
817 return WPA_CTRL_REQ_EXT_CERT_CHECK;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800818 return WPA_CTRL_REQ_UNKNOWN;
819}
820
821
822const char * wpa_supplicant_ctrl_req_to_string(enum wpa_ctrl_req_type field,
823 const char *default_txt,
824 const char **txt)
825{
826 const char *ret = NULL;
827
828 *txt = default_txt;
829
830 switch (field) {
831 case WPA_CTRL_REQ_EAP_IDENTITY:
832 *txt = "Identity";
833 ret = "IDENTITY";
834 break;
835 case WPA_CTRL_REQ_EAP_PASSWORD:
836 *txt = "Password";
837 ret = "PASSWORD";
838 break;
839 case WPA_CTRL_REQ_EAP_NEW_PASSWORD:
840 *txt = "New Password";
841 ret = "NEW_PASSWORD";
842 break;
843 case WPA_CTRL_REQ_EAP_PIN:
844 *txt = "PIN";
845 ret = "PIN";
846 break;
847 case WPA_CTRL_REQ_EAP_OTP:
848 ret = "OTP";
849 break;
850 case WPA_CTRL_REQ_EAP_PASSPHRASE:
851 *txt = "Private key passphrase";
852 ret = "PASSPHRASE";
853 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700854 case WPA_CTRL_REQ_SIM:
855 ret = "SIM";
856 break;
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700857 case WPA_CTRL_REQ_PSK_PASSPHRASE:
858 *txt = "PSK or passphrase";
859 ret = "PSK_PASSPHRASE";
860 break;
Dmitry Shmidt1b467752015-12-14 12:45:46 -0800861 case WPA_CTRL_REQ_EXT_CERT_CHECK:
862 *txt = "External server certificate validation";
863 ret = "EXT_CERT_CHECK";
864 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800865 default:
866 break;
867 }
868
869 /* txt needs to be something */
870 if (*txt == NULL) {
871 wpa_printf(MSG_WARNING, "No message for request %d", field);
872 ret = NULL;
873 }
874
875 return ret;
876}
877
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700878
879void wpas_send_ctrl_req(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
880 const char *field_name, const char *txt)
881{
882 char *buf;
883 size_t buflen;
884 int len;
885
886 buflen = 100 + os_strlen(txt) + ssid->ssid_len;
887 buf = os_malloc(buflen);
888 if (buf == NULL)
889 return;
890 len = os_snprintf(buf, buflen, "%s-%d:%s needed for SSID ",
891 field_name, ssid->id, txt);
892 if (os_snprintf_error(buflen, len)) {
893 os_free(buf);
894 return;
895 }
896 if (ssid->ssid && buflen > len + ssid->ssid_len) {
897 os_memcpy(buf + len, ssid->ssid, ssid->ssid_len);
898 len += ssid->ssid_len;
899 buf[len] = '\0';
900 }
901 buf[buflen - 1] = '\0';
902 wpa_msg(wpa_s, MSG_INFO, WPA_CTRL_REQ "%s", buf);
903 os_free(buf);
904}
905
906
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700907#ifdef IEEE8021X_EAPOL
908#if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800909static void wpa_supplicant_eap_param_needed(void *ctx,
910 enum wpa_ctrl_req_type field,
911 const char *default_txt)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700912{
913 struct wpa_supplicant *wpa_s = ctx;
914 struct wpa_ssid *ssid = wpa_s->current_ssid;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800915 const char *field_name, *txt = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700916
917 if (ssid == NULL)
918 return;
919
Dmitry Shmidt1b467752015-12-14 12:45:46 -0800920 if (field == WPA_CTRL_REQ_EXT_CERT_CHECK)
921 ssid->eap.pending_ext_cert_check = PENDING_CHECK;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800922 wpas_notify_network_request(wpa_s, ssid, field, default_txt);
923
924 field_name = wpa_supplicant_ctrl_req_to_string(field, default_txt,
925 &txt);
926 if (field_name == NULL) {
927 wpa_printf(MSG_WARNING, "Unhandled EAP param %d needed",
928 field);
929 return;
930 }
931
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800932 wpas_notify_eap_status(wpa_s, "eap parameter needed", field_name);
933
Dmitry Shmidt912c6ec2015-03-30 13:16:51 -0700934 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700935}
936#else /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
937#define wpa_supplicant_eap_param_needed NULL
938#endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
939
940
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800941#ifdef CONFIG_EAP_PROXY
Dmitry Shmidt29333592017-01-09 12:27:11 -0800942
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800943static void wpa_supplicant_eap_proxy_cb(void *ctx)
944{
945 struct wpa_supplicant *wpa_s = ctx;
946 size_t len;
947
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700948 wpa_s->mnc_len = eapol_sm_get_eap_proxy_imsi(wpa_s->eapol, -1,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800949 wpa_s->imsi, &len);
950 if (wpa_s->mnc_len > 0) {
951 wpa_s->imsi[len] = '\0';
952 wpa_printf(MSG_DEBUG, "eap_proxy: IMSI %s (MNC length %d)",
953 wpa_s->imsi, wpa_s->mnc_len);
954 } else {
955 wpa_printf(MSG_DEBUG, "eap_proxy: IMSI not available");
956 }
957}
Dmitry Shmidt29333592017-01-09 12:27:11 -0800958
959
960static void wpa_sm_sim_state_error_handler(struct wpa_supplicant *wpa_s)
961{
962 int i;
963 struct wpa_ssid *ssid;
964 const struct eap_method_type *eap_methods;
965
966 if (!wpa_s->conf)
967 return;
968
969 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
970 eap_methods = ssid->eap.eap_methods;
971 if (!eap_methods)
972 continue;
973
974 for (i = 0; eap_methods[i].method != EAP_TYPE_NONE; i++) {
975 if (eap_methods[i].vendor == EAP_VENDOR_IETF &&
976 (eap_methods[i].method == EAP_TYPE_SIM ||
977 eap_methods[i].method == EAP_TYPE_AKA ||
978 eap_methods[i].method == EAP_TYPE_AKA_PRIME)) {
979 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
980 break;
981 }
982 }
983 }
984}
985
986
987static void
988wpa_supplicant_eap_proxy_notify_sim_status(void *ctx,
989 enum eap_proxy_sim_state sim_state)
990{
991 struct wpa_supplicant *wpa_s = ctx;
992
993 wpa_printf(MSG_DEBUG, "eap_proxy: SIM card status %u", sim_state);
994 switch (sim_state) {
995 case SIM_STATE_ERROR:
996 wpa_sm_sim_state_error_handler(wpa_s);
997 break;
998 default:
999 wpa_printf(MSG_DEBUG, "eap_proxy: SIM card status unknown");
1000 break;
1001 }
1002}
1003
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001004#endif /* CONFIG_EAP_PROXY */
1005
1006
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001007static void wpa_supplicant_port_cb(void *ctx, int authorized)
1008{
1009 struct wpa_supplicant *wpa_s = ctx;
1010#ifdef CONFIG_AP
1011 if (wpa_s->ap_iface) {
1012 wpa_printf(MSG_DEBUG, "AP mode active - skip EAPOL Supplicant "
1013 "port status: %s",
1014 authorized ? "Authorized" : "Unauthorized");
1015 return;
1016 }
1017#endif /* CONFIG_AP */
1018 wpa_printf(MSG_DEBUG, "EAPOL: Supplicant port status: %s",
1019 authorized ? "Authorized" : "Unauthorized");
1020 wpa_drv_set_supp_port(wpa_s, authorized);
1021}
Dmitry Shmidtc55524a2011-07-07 11:18:38 -07001022
1023
Hai Shalom81f62d82019-07-22 12:10:00 -07001024static void wpa_supplicant_cert_cb(void *ctx, struct tls_cert_data *cert,
1025 const char *cert_hash)
Dmitry Shmidtc55524a2011-07-07 11:18:38 -07001026{
1027 struct wpa_supplicant *wpa_s = ctx;
1028
Hai Shalom81f62d82019-07-22 12:10:00 -07001029 wpas_notify_certification(wpa_s, cert, cert_hash);
Dmitry Shmidtc55524a2011-07-07 11:18:38 -07001030}
Dmitry Shmidt04949592012-07-19 12:16:46 -07001031
1032
1033static void wpa_supplicant_status_cb(void *ctx, const char *status,
1034 const char *parameter)
1035{
1036 struct wpa_supplicant *wpa_s = ctx;
1037
1038 wpas_notify_eap_status(wpa_s, status, parameter);
1039}
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001040
Roshan Pius3a1667e2018-07-03 15:17:14 -07001041
Ahmed ElArabawy9c86a7f2018-03-15 09:00:10 -07001042static void wpa_supplicant_eap_error_cb(void *ctx, int error_code)
1043{
1044 struct wpa_supplicant *wpa_s = ctx;
1045
1046 wpas_notify_eap_error(wpa_s, error_code);
1047}
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001048
Roshan Pius3a1667e2018-07-03 15:17:14 -07001049
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001050static void wpa_supplicant_set_anon_id(void *ctx, const u8 *id, size_t len)
1051{
1052 struct wpa_supplicant *wpa_s = ctx;
1053 char *str;
1054 int res;
1055
1056 wpa_hexdump_ascii(MSG_DEBUG, "EAP method updated anonymous_identity",
1057 id, len);
1058
1059 if (wpa_s->current_ssid == NULL)
1060 return;
1061
1062 if (id == NULL) {
1063 if (wpa_config_set(wpa_s->current_ssid, "anonymous_identity",
1064 "NULL", 0) < 0)
1065 return;
1066 } else {
1067 str = os_malloc(len * 2 + 1);
1068 if (str == NULL)
1069 return;
1070 wpa_snprintf_hex(str, len * 2 + 1, id, len);
1071 res = wpa_config_set(wpa_s->current_ssid, "anonymous_identity",
1072 str, 0);
1073 os_free(str);
1074 if (res < 0)
1075 return;
1076 }
1077
1078 if (wpa_s->conf->update_config) {
1079 res = wpa_config_write(wpa_s->confname, wpa_s->conf);
1080 if (res) {
1081 wpa_printf(MSG_DEBUG, "Failed to update config after "
1082 "anonymous_id update");
1083 }
1084 }
1085}
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001086#endif /* IEEE8021X_EAPOL */
1087
1088
1089int wpa_supplicant_init_eapol(struct wpa_supplicant *wpa_s)
1090{
1091#ifdef IEEE8021X_EAPOL
1092 struct eapol_ctx *ctx;
1093 ctx = os_zalloc(sizeof(*ctx));
1094 if (ctx == NULL) {
1095 wpa_printf(MSG_ERROR, "Failed to allocate EAPOL context.");
1096 return -1;
1097 }
1098
1099 ctx->ctx = wpa_s;
1100 ctx->msg_ctx = wpa_s;
1101 ctx->eapol_send_ctx = wpa_s;
1102 ctx->preauth = 0;
1103 ctx->eapol_done_cb = wpa_supplicant_notify_eapol_done;
1104 ctx->eapol_send = wpa_supplicant_eapol_send;
1105 ctx->set_wep_key = wpa_eapol_set_wep_key;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001106#ifndef CONFIG_NO_CONFIG_BLOBS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001107 ctx->set_config_blob = wpa_supplicant_set_config_blob;
1108 ctx->get_config_blob = wpa_supplicant_get_config_blob;
Dmitry Shmidt700a1372013-03-15 14:14:44 -07001109#endif /* CONFIG_NO_CONFIG_BLOBS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001110 ctx->aborted_cached = wpa_supplicant_aborted_cached;
1111 ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path;
1112 ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
1113 ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001114 ctx->openssl_ciphers = wpa_s->conf->openssl_ciphers;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001115 ctx->wps = wpa_s->wps;
1116 ctx->eap_param_needed = wpa_supplicant_eap_param_needed;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001117#ifdef CONFIG_EAP_PROXY
1118 ctx->eap_proxy_cb = wpa_supplicant_eap_proxy_cb;
Dmitry Shmidt29333592017-01-09 12:27:11 -08001119 ctx->eap_proxy_notify_sim_status =
1120 wpa_supplicant_eap_proxy_notify_sim_status;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001121#endif /* CONFIG_EAP_PROXY */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001122 ctx->port_cb = wpa_supplicant_port_cb;
1123 ctx->cb = wpa_supplicant_eapol_cb;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -07001124 ctx->cert_cb = wpa_supplicant_cert_cb;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001125 ctx->cert_in_cb = wpa_s->conf->cert_in_cb;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001126 ctx->status_cb = wpa_supplicant_status_cb;
Ahmed ElArabawy9c86a7f2018-03-15 09:00:10 -07001127 ctx->eap_error_cb = wpa_supplicant_eap_error_cb;
Dmitry Shmidt4530cfd2012-09-09 15:20:40 -07001128 ctx->set_anon_id = wpa_supplicant_set_anon_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001129 ctx->cb_ctx = wpa_s;
1130 wpa_s->eapol = eapol_sm_init(ctx);
1131 if (wpa_s->eapol == NULL) {
1132 os_free(ctx);
1133 wpa_printf(MSG_ERROR, "Failed to initialize EAPOL state "
1134 "machines.");
1135 return -1;
1136 }
1137#endif /* IEEE8021X_EAPOL */
1138
1139 return 0;
1140}
1141
1142
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001143#ifndef CONFIG_NO_WPA
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001144
Dmitry Shmidt807291d2015-01-27 13:40:23 -08001145static void wpa_supplicant_set_rekey_offload(void *ctx,
1146 const u8 *kek, size_t kek_len,
1147 const u8 *kck, size_t kck_len,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001148 const u8 *replay_ctr)
1149{
1150 struct wpa_supplicant *wpa_s = ctx;
1151
Dmitry Shmidt807291d2015-01-27 13:40:23 -08001152 wpa_drv_set_rekey_info(wpa_s, kek, kek_len, kck, kck_len, replay_ctr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001153}
1154
1155
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001156static int wpa_supplicant_key_mgmt_set_pmk(void *ctx, const u8 *pmk,
1157 size_t pmk_len)
1158{
1159 struct wpa_supplicant *wpa_s = ctx;
1160
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001161 if (wpa_s->conf->key_mgmt_offload &&
1162 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001163 return wpa_drv_set_key(wpa_s, WPA_ALG_PMK, NULL, 0, 0,
1164 NULL, 0, pmk, pmk_len);
1165 else
1166 return 0;
1167}
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001168
1169
1170static void wpa_supplicant_fils_hlp_rx(void *ctx, const u8 *dst, const u8 *src,
1171 const u8 *pkt, size_t pkt_len)
1172{
1173 struct wpa_supplicant *wpa_s = ctx;
1174 char *hex;
1175 size_t hexlen;
1176
1177 hexlen = pkt_len * 2 + 1;
1178 hex = os_malloc(hexlen);
1179 if (!hex)
1180 return;
1181 wpa_snprintf_hex(hex, hexlen, pkt, pkt_len);
1182 wpa_msg(wpa_s, MSG_INFO, FILS_HLP_RX "dst=" MACSTR " src=" MACSTR
1183 " frame=%s", MAC2STR(dst), MAC2STR(src), hex);
1184 os_free(hex);
1185}
1186
Hai Shalom74f70d42019-02-11 14:42:39 -08001187
1188static int wpa_supplicant_channel_info(void *_wpa_s,
1189 struct wpa_channel_info *ci)
1190{
1191 struct wpa_supplicant *wpa_s = _wpa_s;
1192
1193 return wpa_drv_channel_info(wpa_s, ci);
1194}
1195
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -08001196#endif /* CONFIG_NO_WPA */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001197
1198
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001199int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s)
1200{
1201#ifndef CONFIG_NO_WPA
1202 struct wpa_sm_ctx *ctx;
1203 ctx = os_zalloc(sizeof(*ctx));
1204 if (ctx == NULL) {
1205 wpa_printf(MSG_ERROR, "Failed to allocate WPA context.");
1206 return -1;
1207 }
1208
1209 ctx->ctx = wpa_s;
1210 ctx->msg_ctx = wpa_s;
1211 ctx->set_state = _wpa_supplicant_set_state;
1212 ctx->get_state = _wpa_supplicant_get_state;
1213 ctx->deauthenticate = _wpa_supplicant_deauthenticate;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001214 ctx->set_key = wpa_supplicant_set_key;
1215 ctx->get_network_ctx = wpa_supplicant_get_network_ctx;
1216 ctx->get_bssid = wpa_supplicant_get_bssid;
1217 ctx->ether_send = _wpa_ether_send;
1218 ctx->get_beacon_ie = wpa_supplicant_get_beacon_ie;
1219 ctx->alloc_eapol = _wpa_alloc_eapol;
1220 ctx->cancel_auth_timeout = _wpa_supplicant_cancel_auth_timeout;
1221 ctx->add_pmkid = wpa_supplicant_add_pmkid;
1222 ctx->remove_pmkid = wpa_supplicant_remove_pmkid;
1223#ifndef CONFIG_NO_CONFIG_BLOBS
1224 ctx->set_config_blob = wpa_supplicant_set_config_blob;
1225 ctx->get_config_blob = wpa_supplicant_get_config_blob;
1226#endif /* CONFIG_NO_CONFIG_BLOBS */
1227 ctx->mlme_setprotection = wpa_supplicant_mlme_setprotection;
1228#ifdef CONFIG_IEEE80211R
1229 ctx->update_ft_ies = wpa_supplicant_update_ft_ies;
1230 ctx->send_ft_action = wpa_supplicant_send_ft_action;
1231 ctx->mark_authenticated = wpa_supplicant_mark_authenticated;
1232#endif /* CONFIG_IEEE80211R */
1233#ifdef CONFIG_TDLS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001234 ctx->tdls_get_capa = wpa_supplicant_tdls_get_capa;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001235 ctx->send_tdls_mgmt = wpa_supplicant_send_tdls_mgmt;
1236 ctx->tdls_oper = wpa_supplicant_tdls_oper;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001237 ctx->tdls_peer_addset = wpa_supplicant_tdls_peer_addset;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001238 ctx->tdls_enable_channel_switch =
1239 wpa_supplicant_tdls_enable_channel_switch;
1240 ctx->tdls_disable_channel_switch =
1241 wpa_supplicant_tdls_disable_channel_switch;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001242#endif /* CONFIG_TDLS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001243 ctx->set_rekey_offload = wpa_supplicant_set_rekey_offload;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001244 ctx->key_mgmt_set_pmk = wpa_supplicant_key_mgmt_set_pmk;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08001245 ctx->fils_hlp_rx = wpa_supplicant_fils_hlp_rx;
Hai Shalom74f70d42019-02-11 14:42:39 -08001246 ctx->channel_info = wpa_supplicant_channel_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001247
1248 wpa_s->wpa = wpa_sm_init(ctx);
1249 if (wpa_s->wpa == NULL) {
1250 wpa_printf(MSG_ERROR, "Failed to initialize WPA state "
1251 "machine");
Dmitry Shmidtff787d52015-01-12 13:01:47 -08001252 os_free(ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001253 return -1;
1254 }
1255#endif /* CONFIG_NO_WPA */
1256
1257 return 0;
1258}
1259
1260
1261void wpa_supplicant_rsn_supp_set_config(struct wpa_supplicant *wpa_s,
1262 struct wpa_ssid *ssid)
1263{
1264 struct rsn_supp_config conf;
1265 if (ssid) {
1266 os_memset(&conf, 0, sizeof(conf));
1267 conf.network_ctx = ssid;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001268 conf.allowed_pairwise_cipher = ssid->pairwise_cipher;
1269#ifdef IEEE8021X_EAPOL
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001270 conf.proactive_key_caching = ssid->proactive_key_caching < 0 ?
1271 wpa_s->conf->okc : ssid->proactive_key_caching;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001272 conf.eap_workaround = ssid->eap_workaround;
1273 conf.eap_conf_ctx = &ssid->eap;
1274#endif /* IEEE8021X_EAPOL */
1275 conf.ssid = ssid->ssid;
1276 conf.ssid_len = ssid->ssid_len;
1277 conf.wpa_ptk_rekey = ssid->wpa_ptk_rekey;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001278#ifdef CONFIG_P2P
1279 if (ssid->p2p_group && wpa_s->current_bss &&
1280 !wpa_s->p2p_disable_ip_addr_req) {
1281 struct wpabuf *p2p;
1282 p2p = wpa_bss_get_vendor_ie_multi(wpa_s->current_bss,
1283 P2P_IE_VENDOR_TYPE);
1284 if (p2p) {
1285 u8 group_capab;
1286 group_capab = p2p_get_group_capab(p2p);
1287 if (group_capab &
1288 P2P_GROUP_CAPAB_IP_ADDR_ALLOCATION)
1289 conf.p2p = 1;
1290 wpabuf_free(p2p);
1291 }
1292 }
1293#endif /* CONFIG_P2P */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001294 conf.wpa_rsc_relaxation = wpa_s->conf->wpa_rsc_relaxation;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001295#ifdef CONFIG_FILS
1296 if (wpa_key_mgmt_fils(wpa_s->key_mgmt))
1297 conf.fils_cache_id =
1298 wpa_bss_get_fils_cache_id(wpa_s->current_bss);
1299#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001300 }
1301 wpa_sm_set_config(wpa_s->wpa, ssid ? &conf : NULL);
1302}