]> git.ipfire.org Git - thirdparty/hostap.git/blame - wpa_supplicant/wpas_glue.c
DPP2: Connection status result (Enrollee)
[thirdparty/hostap.git] / wpa_supplicant / wpas_glue.c
CommitLineData
6fc6879b
JM
1/*
2 * WPA Supplicant - Glue code to setup EAPOL and RSN modules
98cd3d1c 3 * Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi>
6fc6879b 4 *
0f3d578e
JM
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
6fc6879b
JM
7 */
8
9#include "includes.h"
10
11#include "common.h"
12#include "eapol_supp/eapol_supp_sm.h"
c167662d 13#include "eap_peer/eap.h"
3acb5005 14#include "rsn_supp/wpa.h"
6fc6879b
JM
15#include "eloop.h"
16#include "config.h"
17#include "l2_packet/l2_packet.h"
90973fb2 18#include "common/wpa_common.h"
6fc6879b 19#include "wpa_supplicant_i.h"
2d5b792d 20#include "driver_i.h"
3acb5005 21#include "rsn_supp/pmksa_cache.h"
c2a04078 22#include "sme.h"
90973fb2
JM
23#include "common/ieee802_11_defs.h"
24#include "common/wpa_ctrl.h"
6fc6879b 25#include "wpas_glue.h"
fa201b69 26#include "wps_supplicant.h"
e48f0fb6 27#include "bss.h"
9ba9fa07 28#include "scan.h"
ade74830 29#include "notify.h"
dd10abcc 30#include "wpas_kay.h"
6fc6879b
JM
31
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);
c08b9180
JM
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 }
6fc6879b
JM
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{
9d4ff04a
JM
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
6fc6879b
JM
115 if (wpa_s->l2) {
116 return l2_packet_send(wpa_s->l2, dest, proto, buf, len);
117 }
118
2961bfa8 119 return -1;
6fc6879b
JM
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 */
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
56586197 148 if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
a1ea1b45 149 wpa_s->key_mgmt == WPA_KEY_MGMT_OWE ||
567da5bb 150 wpa_s->key_mgmt == WPA_KEY_MGMT_DPP ||
6fc6879b
JM
151 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) {
76db5b6b
JM
163 /*
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 }
6fc6879b
JM
186 }
187
a8e16edc 188 if (is_zero_ether_addr(wpa_s->bssid)) {
6fc6879b
JM
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 &&
a8e16edc 192 !is_zero_ether_addr(bssid)) {
6fc6879b
JM
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,
0382097e 244 unicast ? wpa_s->bssid : NULL,
da64c266 245 keyidx, unicast, NULL, 0, key, keylen);
6fc6879b
JM
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
c60ba9f7
JM
256static 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,
6fc6879b
JM
272 void *ctx)
273{
274 struct wpa_supplicant *wpa_s = ctx;
275 int res, pmk_len;
276 u8 pmk[PMK_LEN];
277
c60ba9f7
JM
278 wpa_printf(MSG_DEBUG, "EAPOL authentication completed - result=%s",
279 result_str(result));
6fc6879b 280
fa201b69 281 if (wpas_wps_eapol_cb(wpa_s) > 0)
ad08c363 282 return;
ad08c363 283
c60ba9f7
JM
284 wpa_s->eap_expected_failure = result ==
285 EAPOL_SUPP_RESULT_EXPECTED_FAILURE;
286
287 if (result != EAPOL_SUPP_RESULT_SUCCESS) {
0930209d
JM
288 /*
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);
dd10abcc
HW
294 } else {
295 ieee802_1x_notify_create_actor(wpa_s, wpa_s->last_eapol_src);
0930209d
JM
296 }
297
c60ba9f7 298 if (result != EAPOL_SUPP_RESULT_SUCCESS ||
436ee2fd 299 !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X))
6fc6879b
JM
300 return;
301
56586197 302 if (!wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt))
6fc6879b
JM
303 return;
304
305 wpa_printf(MSG_DEBUG, "Configure PMK for driver-based RSN 4-way "
306 "handshake");
307
308 pmk_len = PMK_LEN;
09c395b4
JM
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 }
6fc6879b
JM
332 }
333
334 if (res) {
335 wpa_printf(MSG_DEBUG, "Failed to get PMK from EAPOL state "
336 "machines");
337 return;
338 }
339
09c395b4
JM
340 wpa_hexdump_key(MSG_DEBUG, "RSN: Configure PMK for driver-based 4-way "
341 "handshake", pmk, pmk_len);
342
6fc6879b
JM
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");
56586197 359 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
6fc6879b
JM
360 wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE);
361 } else {
6fc6879b
JM
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{
6fc6879b 374 int ret = 0;
e48f0fb6 375 struct wpa_bss *curr = NULL, *bss;
6fc6879b
JM
376 struct wpa_ssid *ssid = wpa_s->current_ssid;
377 const u8 *ie;
378
e48f0fb6
JM
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)
6fc6879b 381 continue;
6fc6879b 382 if (ssid == NULL ||
e48f0fb6
JM
383 ((bss->ssid_len == ssid->ssid_len &&
384 os_memcmp(bss->ssid, ssid->ssid, ssid->ssid_len) == 0) ||
6fc6879b 385 ssid->ssid_len == 0)) {
e48f0fb6 386 curr = bss;
6fc6879b
JM
387 break;
388 }
389 }
390
391 if (curr) {
e48f0fb6 392 ie = wpa_bss_get_vendor_ie(curr, WPA_IE_VENDOR_TYPE);
6fc6879b
JM
393 if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
394 ret = -1;
395
e48f0fb6 396 ie = wpa_bss_get_ie(curr, WLAN_EID_RSN);
6fc6879b
JM
397 if (wpa_sm_set_ap_rsn_ie(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0))
398 ret = -1;
399 } else {
400 ret = -1;
401 }
402
403 return ret;
404}
405
406
407static int wpa_supplicant_get_beacon_ie(void *ctx)
408{
409 struct wpa_supplicant *wpa_s = ctx;
410 if (wpa_get_beacon_ie(wpa_s) == 0) {
411 return 0;
412 }
413
414 /* No WPA/RSN IE found in the cached scan results. Try to get updated
415 * scan results from the driver. */
a1fd2ce5 416 if (wpa_supplicant_update_scan_results(wpa_s) < 0)
6fc6879b 417 return -1;
6fc6879b
JM
418
419 return wpa_get_beacon_ie(wpa_s);
420}
421
422
423static u8 * _wpa_alloc_eapol(void *wpa_s, u8 type,
424 const void *data, u16 data_len,
425 size_t *msg_len, void **data_pos)
426{
427 return wpa_alloc_eapol(wpa_s, type, data, data_len, msg_len, data_pos);
428}
429
430
431static int _wpa_ether_send(void *wpa_s, const u8 *dest, u16 proto,
432 const u8 *buf, size_t len)
433{
434 return wpa_ether_send(wpa_s, dest, proto, buf, len);
435}
436
437
6fc6879b
JM
438static void _wpa_supplicant_cancel_auth_timeout(void *wpa_s)
439{
440 wpa_supplicant_cancel_auth_timeout(wpa_s);
441}
442
443
71934751 444static void _wpa_supplicant_set_state(void *wpa_s, enum wpa_states state)
6fc6879b
JM
445{
446 wpa_supplicant_set_state(wpa_s, state);
447}
448
449
450/**
451 * wpa_supplicant_get_state - Get the connection state
452 * @wpa_s: Pointer to wpa_supplicant data
453 * Returns: The current connection state (WPA_*)
454 */
71934751 455static enum wpa_states wpa_supplicant_get_state(struct wpa_supplicant *wpa_s)
6fc6879b
JM
456{
457 return wpa_s->wpa_state;
458}
459
460
71934751 461static enum wpa_states _wpa_supplicant_get_state(void *wpa_s)
6fc6879b
JM
462{
463 return wpa_supplicant_get_state(wpa_s);
464}
465
466
4be17ffb 467static void _wpa_supplicant_deauthenticate(void *wpa_s, u16 reason_code)
6fc6879b
JM
468{
469 wpa_supplicant_deauthenticate(wpa_s, reason_code);
3e2ad1b9 470 /* Schedule a scan to make sure we continue looking for networks */
83935317 471 wpa_supplicant_req_scan(wpa_s, 5, 0);
6fc6879b
JM
472}
473
474
475static void * wpa_supplicant_get_network_ctx(void *wpa_s)
476{
477 return wpa_supplicant_get_ssid(wpa_s);
478}
479
480
481static int wpa_supplicant_get_bssid(void *ctx, u8 *bssid)
482{
483 struct wpa_supplicant *wpa_s = ctx;
6fc6879b
JM
484 return wpa_drv_get_bssid(wpa_s, bssid);
485}
486
487
71934751 488static int wpa_supplicant_set_key(void *_wpa_s, enum wpa_alg alg,
6fc6879b
JM
489 const u8 *addr, int key_idx, int set_tx,
490 const u8 *seq, size_t seq_len,
491 const u8 *key, size_t key_len)
492{
46690a3b
JM
493 struct wpa_supplicant *wpa_s = _wpa_s;
494 if (alg == WPA_ALG_TKIP && key_idx == 0 && key_len == 32) {
495 /* Clear the MIC error counter when setting a new PTK. */
496 wpa_s->mic_errors_seen = 0;
497 }
fa7ae950
JM
498#ifdef CONFIG_TESTING_GET_GTK
499 if (key_idx > 0 && addr && is_broadcast_ether_addr(addr) &&
500 alg != WPA_ALG_NONE && key_len <= sizeof(wpa_s->last_gtk)) {
501 os_memcpy(wpa_s->last_gtk, key, key_len);
502 wpa_s->last_gtk_len = key_len;
503 }
504#endif /* CONFIG_TESTING_GET_GTK */
16579769
JM
505#ifdef CONFIG_TESTING_OPTIONS
506 if (addr && !is_broadcast_ether_addr(addr)) {
507 wpa_s->last_tk_alg = alg;
508 os_memcpy(wpa_s->last_tk_addr, addr, ETH_ALEN);
509 wpa_s->last_tk_key_idx = key_idx;
510 if (key)
511 os_memcpy(wpa_s->last_tk, key, key_len);
512 wpa_s->last_tk_len = key_len;
513 }
514#endif /* CONFIG_TESTING_OPTIONS */
6fc6879b
JM
515 return wpa_drv_set_key(wpa_s, alg, addr, key_idx, set_tx, seq, seq_len,
516 key, key_len);
517}
518
519
520static int wpa_supplicant_mlme_setprotection(void *wpa_s, const u8 *addr,
521 int protection_type,
522 int key_type)
523{
524 return wpa_drv_mlme_setprotection(wpa_s, addr, protection_type,
525 key_type);
526}
527
528
c5793127
JM
529static struct wpa_ssid * wpas_get_network_ctx(struct wpa_supplicant *wpa_s,
530 void *network_ctx)
531{
532 struct wpa_ssid *ssid;
533
534 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
535 if (network_ctx == ssid)
536 return ssid;
537 }
538
539 return NULL;
540}
541
542
543static int wpa_supplicant_add_pmkid(void *_wpa_s, void *network_ctx,
42e69bda
VK
544 const u8 *bssid, const u8 *pmkid,
545 const u8 *fils_cache_id,
546 const u8 *pmk, size_t pmk_len)
6fc6879b 547{
c5793127
JM
548 struct wpa_supplicant *wpa_s = _wpa_s;
549 struct wpa_ssid *ssid;
6fbb5414 550 struct wpa_pmkid_params params;
c5793127 551
6fbb5414 552 os_memset(&params, 0, sizeof(params));
c5793127
JM
553 ssid = wpas_get_network_ctx(wpa_s, network_ctx);
554 if (ssid)
555 wpa_msg(wpa_s, MSG_INFO, PMKSA_CACHE_ADDED MACSTR " %d",
556 MAC2STR(bssid), ssid->id);
42e69bda
VK
557 if (ssid && fils_cache_id) {
558 params.ssid = ssid->ssid;
559 params.ssid_len = ssid->ssid_len;
560 params.fils_cache_id = fils_cache_id;
561 } else {
562 params.bssid = bssid;
563 }
564
6fbb5414 565 params.pmkid = pmkid;
42e69bda
VK
566 params.pmk = pmk;
567 params.pmk_len = pmk_len;
6fbb5414
VK
568
569 return wpa_drv_add_pmkid(wpa_s, &params);
6fc6879b
JM
570}
571
572
c5793127 573static int wpa_supplicant_remove_pmkid(void *_wpa_s, void *network_ctx,
42e69bda
VK
574 const u8 *bssid, const u8 *pmkid,
575 const u8 *fils_cache_id)
6fc6879b 576{
c5793127
JM
577 struct wpa_supplicant *wpa_s = _wpa_s;
578 struct wpa_ssid *ssid;
6fbb5414 579 struct wpa_pmkid_params params;
c5793127 580
6fbb5414 581 os_memset(&params, 0, sizeof(params));
c5793127
JM
582 ssid = wpas_get_network_ctx(wpa_s, network_ctx);
583 if (ssid)
584 wpa_msg(wpa_s, MSG_INFO, PMKSA_CACHE_REMOVED MACSTR " %d",
585 MAC2STR(bssid), ssid->id);
42e69bda
VK
586 if (ssid && fils_cache_id) {
587 params.ssid = ssid->ssid;
588 params.ssid_len = ssid->ssid_len;
589 params.fils_cache_id = fils_cache_id;
590 } else {
591 params.bssid = bssid;
592 }
6fbb5414 593
6fbb5414
VK
594 params.pmkid = pmkid;
595
596 return wpa_drv_remove_pmkid(wpa_s, &params);
6fc6879b
JM
597}
598
599
600#ifdef CONFIG_IEEE80211R
601static int wpa_supplicant_update_ft_ies(void *ctx, const u8 *md,
602 const u8 *ies, size_t ies_len)
603{
604 struct wpa_supplicant *wpa_s = ctx;
c2a04078
JM
605 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)
606 return sme_update_ft_ies(wpa_s, md, ies, ies_len);
6fc6879b
JM
607 return wpa_drv_update_ft_ies(wpa_s, md, ies, ies_len);
608}
609
610
611static int wpa_supplicant_send_ft_action(void *ctx, u8 action,
612 const u8 *target_ap,
613 const u8 *ies, size_t ies_len)
614{
615 struct wpa_supplicant *wpa_s = ctx;
8105821b
JM
616 int ret;
617 u8 *data, *pos;
618 size_t data_len;
619
620 if (action != 1) {
621 wpa_printf(MSG_ERROR, "Unsupported send_ft_action action %d",
622 action);
623 return -1;
624 }
625
626 /*
627 * Action frame payload:
628 * Category[1] = 6 (Fast BSS Transition)
629 * Action[1] = 1 (Fast BSS Transition Request)
630 * STA Address
631 * Target AP Address
632 * FT IEs
633 */
634
635 data_len = 2 + 2 * ETH_ALEN + ies_len;
636 data = os_malloc(data_len);
637 if (data == NULL)
638 return -1;
639 pos = data;
640 *pos++ = 0x06; /* FT Action category */
641 *pos++ = action;
642 os_memcpy(pos, wpa_s->own_addr, ETH_ALEN);
643 pos += ETH_ALEN;
644 os_memcpy(pos, target_ap, ETH_ALEN);
645 pos += ETH_ALEN;
646 os_memcpy(pos, ies, ies_len);
647
648 ret = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0,
649 wpa_s->bssid, wpa_s->own_addr, wpa_s->bssid,
650 data, data_len, 0);
651 os_free(data);
652
653 return ret;
6fc6879b 654}
2a7e7f4e
JM
655
656
657static int wpa_supplicant_mark_authenticated(void *ctx, const u8 *target_ap)
658{
659 struct wpa_supplicant *wpa_s = ctx;
660 struct wpa_driver_auth_params params;
661 struct wpa_bss *bss;
662
2a7e7f4e
JM
663 bss = wpa_bss_get_bssid(wpa_s, target_ap);
664 if (bss == NULL)
665 return -1;
666
667 os_memset(&params, 0, sizeof(params));
668 params.bssid = target_ap;
669 params.freq = bss->freq;
670 params.ssid = bss->ssid;
671 params.ssid_len = bss->ssid_len;
672 params.auth_alg = WPA_AUTH_ALG_FT;
673 params.local_state_change = 1;
674 return wpa_drv_authenticate(wpa_s, &params);
675}
6fc6879b
JM
676#endif /* CONFIG_IEEE80211R */
677
6fc6879b 678
281ff0aa
GP
679#ifdef CONFIG_TDLS
680
c58ab8f2 681static int wpa_supplicant_tdls_get_capa(void *ctx, int *tdls_supported,
4daa5729
AN
682 int *tdls_ext_setup,
683 int *tdls_chan_switch)
c58ab8f2
AN
684{
685 struct wpa_supplicant *wpa_s = ctx;
686
687 *tdls_supported = 0;
688 *tdls_ext_setup = 0;
4daa5729 689 *tdls_chan_switch = 0;
c58ab8f2
AN
690
691 if (!wpa_s->drv_capa_known)
692 return -1;
693
694 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)
695 *tdls_supported = 1;
696
697 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP)
698 *tdls_ext_setup = 1;
699
4daa5729
AN
700 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)
701 *tdls_chan_switch = 1;
702
c58ab8f2
AN
703 return 0;
704}
705
706
281ff0aa
GP
707static int wpa_supplicant_send_tdls_mgmt(void *ctx, const u8 *dst,
708 u8 action_code, u8 dialog_token,
96ecea5e 709 u16 status_code, u32 peer_capab,
984dadc2
AN
710 int initiator, const u8 *buf,
711 size_t len)
281ff0aa
GP
712{
713 struct wpa_supplicant *wpa_s = ctx;
714 return wpa_drv_send_tdls_mgmt(wpa_s, dst, action_code, dialog_token,
984dadc2
AN
715 status_code, peer_capab, initiator, buf,
716 len);
281ff0aa
GP
717}
718
719
720static int wpa_supplicant_tdls_oper(void *ctx, int oper, const u8 *peer)
721{
722 struct wpa_supplicant *wpa_s = ctx;
723 return wpa_drv_tdls_oper(wpa_s, oper, peer);
724}
725
45b722f1
AN
726
727static int wpa_supplicant_tdls_peer_addset(
78533699 728 void *ctx, const u8 *peer, int add, u16 aid, u16 capability,
ff4178d5
SD
729 const u8 *supp_rates, size_t supp_rates_len,
730 const struct ieee80211_ht_capabilities *ht_capab,
f8361e3d 731 const struct ieee80211_vht_capabilities *vht_capab,
08d7665c 732 u8 qosinfo, int wmm, const u8 *ext_capab, size_t ext_capab_len,
3ed97271
SD
733 const u8 *supp_channels, size_t supp_channels_len,
734 const u8 *supp_oper_classes, size_t supp_oper_classes_len)
45b722f1
AN
735{
736 struct wpa_supplicant *wpa_s = ctx;
737 struct hostapd_sta_add_params params;
738
b8df43de
JM
739 os_memset(&params, 0, sizeof(params));
740
45b722f1 741 params.addr = peer;
f11b72c3 742 params.aid = aid;
45b722f1
AN
743 params.capability = capability;
744 params.flags = WPA_STA_TDLS_PEER | WPA_STA_AUTHORIZED;
ff4178d5
SD
745
746 /*
08d7665c
AN
747 * Don't rely only on qosinfo for WMM capability. It may be 0 even when
748 * present. Allow the WMM IE to also indicate QoS support.
ff4178d5 749 */
08d7665c 750 if (wmm || qosinfo)
ff4178d5
SD
751 params.flags |= WPA_STA_WMM;
752
753 params.ht_capabilities = ht_capab;
f8361e3d 754 params.vht_capabilities = vht_capab;
ff4178d5 755 params.qosinfo = qosinfo;
45b722f1
AN
756 params.listen_interval = 0;
757 params.supp_rates = supp_rates;
758 params.supp_rates_len = supp_rates_len;
759 params.set = !add;
d16531c4
SD
760 params.ext_capab = ext_capab;
761 params.ext_capab_len = ext_capab_len;
3ed97271
SD
762 params.supp_channels = supp_channels;
763 params.supp_channels_len = supp_channels_len;
764 params.supp_oper_classes = supp_oper_classes;
765 params.supp_oper_classes_len = supp_oper_classes_len;
45b722f1
AN
766
767 return wpa_drv_sta_add(wpa_s, &params);
768}
769
6b90deae
AN
770
771static int wpa_supplicant_tdls_enable_channel_switch(
772 void *ctx, const u8 *addr, u8 oper_class,
773 const struct hostapd_freq_params *params)
774{
775 struct wpa_supplicant *wpa_s = ctx;
776
777 return wpa_drv_tdls_enable_channel_switch(wpa_s, addr, oper_class,
778 params);
779}
780
781
782static int wpa_supplicant_tdls_disable_channel_switch(void *ctx, const u8 *addr)
783{
784 struct wpa_supplicant *wpa_s = ctx;
785
786 return wpa_drv_tdls_disable_channel_switch(wpa_s, addr);
787}
788
281ff0aa
GP
789#endif /* CONFIG_TDLS */
790
9aaa6955
JM
791#endif /* CONFIG_NO_WPA */
792
281ff0aa 793
81c57e22
DW
794enum wpa_ctrl_req_type wpa_supplicant_ctrl_req_from_string(const char *field)
795{
796 if (os_strcmp(field, "IDENTITY") == 0)
797 return WPA_CTRL_REQ_EAP_IDENTITY;
798 else if (os_strcmp(field, "PASSWORD") == 0)
799 return WPA_CTRL_REQ_EAP_PASSWORD;
800 else if (os_strcmp(field, "NEW_PASSWORD") == 0)
801 return WPA_CTRL_REQ_EAP_NEW_PASSWORD;
802 else if (os_strcmp(field, "PIN") == 0)
803 return WPA_CTRL_REQ_EAP_PIN;
804 else if (os_strcmp(field, "OTP") == 0)
805 return WPA_CTRL_REQ_EAP_OTP;
806 else if (os_strcmp(field, "PASSPHRASE") == 0)
807 return WPA_CTRL_REQ_EAP_PASSPHRASE;
a5d44ac0
JM
808 else if (os_strcmp(field, "SIM") == 0)
809 return WPA_CTRL_REQ_SIM;
a52410c2
JM
810 else if (os_strcmp(field, "PSK_PASSPHRASE") == 0)
811 return WPA_CTRL_REQ_PSK_PASSPHRASE;
3c108b75
JM
812 else if (os_strcmp(field, "EXT_CERT_CHECK") == 0)
813 return WPA_CTRL_REQ_EXT_CERT_CHECK;
81c57e22
DW
814 return WPA_CTRL_REQ_UNKNOWN;
815}
816
817
9ef1aaae
DW
818const char * wpa_supplicant_ctrl_req_to_string(enum wpa_ctrl_req_type field,
819 const char *default_txt,
820 const char **txt)
821{
822 const char *ret = NULL;
823
824 *txt = default_txt;
825
826 switch (field) {
827 case WPA_CTRL_REQ_EAP_IDENTITY:
828 *txt = "Identity";
829 ret = "IDENTITY";
830 break;
831 case WPA_CTRL_REQ_EAP_PASSWORD:
832 *txt = "Password";
833 ret = "PASSWORD";
834 break;
835 case WPA_CTRL_REQ_EAP_NEW_PASSWORD:
836 *txt = "New Password";
837 ret = "NEW_PASSWORD";
838 break;
839 case WPA_CTRL_REQ_EAP_PIN:
840 *txt = "PIN";
841 ret = "PIN";
842 break;
843 case WPA_CTRL_REQ_EAP_OTP:
844 ret = "OTP";
845 break;
846 case WPA_CTRL_REQ_EAP_PASSPHRASE:
847 *txt = "Private key passphrase";
848 ret = "PASSPHRASE";
849 break;
a5d44ac0
JM
850 case WPA_CTRL_REQ_SIM:
851 ret = "SIM";
852 break;
a52410c2
JM
853 case WPA_CTRL_REQ_PSK_PASSPHRASE:
854 *txt = "PSK or passphrase";
855 ret = "PSK_PASSPHRASE";
856 break;
3c108b75
JM
857 case WPA_CTRL_REQ_EXT_CERT_CHECK:
858 *txt = "External server certificate validation";
859 ret = "EXT_CERT_CHECK";
860 break;
9ef1aaae
DW
861 default:
862 break;
863 }
864
865 /* txt needs to be something */
866 if (*txt == NULL) {
867 wpa_printf(MSG_WARNING, "No message for request %d", field);
868 ret = NULL;
869 }
870
871 return ret;
872}
873
a52410c2
JM
874
875void wpas_send_ctrl_req(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
876 const char *field_name, const char *txt)
877{
878 char *buf;
879 size_t buflen;
880 int len;
881
882 buflen = 100 + os_strlen(txt) + ssid->ssid_len;
883 buf = os_malloc(buflen);
884 if (buf == NULL)
885 return;
886 len = os_snprintf(buf, buflen, "%s-%d:%s needed for SSID ",
887 field_name, ssid->id, txt);
888 if (os_snprintf_error(buflen, len)) {
889 os_free(buf);
890 return;
891 }
892 if (ssid->ssid && buflen > len + ssid->ssid_len) {
893 os_memcpy(buf + len, ssid->ssid, ssid->ssid_len);
894 len += ssid->ssid_len;
895 buf[len] = '\0';
896 }
897 buf[buflen - 1] = '\0';
898 wpa_msg(wpa_s, MSG_INFO, WPA_CTRL_REQ "%s", buf);
899 os_free(buf);
900}
901
902
b1491202 903#ifdef IEEE8021X_EAPOL
6fc6879b 904#if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG)
9ef1aaae
DW
905static void wpa_supplicant_eap_param_needed(void *ctx,
906 enum wpa_ctrl_req_type field,
907 const char *default_txt)
6fc6879b
JM
908{
909 struct wpa_supplicant *wpa_s = ctx;
910 struct wpa_ssid *ssid = wpa_s->current_ssid;
9ef1aaae 911 const char *field_name, *txt = NULL;
6fc6879b
JM
912
913 if (ssid == NULL)
914 return;
915
3c108b75
JM
916 if (field == WPA_CTRL_REQ_EXT_CERT_CHECK)
917 ssid->eap.pending_ext_cert_check = PENDING_CHECK;
a9022616
DW
918 wpas_notify_network_request(wpa_s, ssid, field, default_txt);
919
9ef1aaae
DW
920 field_name = wpa_supplicant_ctrl_req_to_string(field, default_txt,
921 &txt);
922 if (field_name == NULL) {
923 wpa_printf(MSG_WARNING, "Unhandled EAP param %d needed",
924 field);
925 return;
926 }
927
93c7e332
PS
928 wpas_notify_eap_status(wpa_s, "eap parameter needed", field_name);
929
a52410c2 930 wpas_send_ctrl_req(wpa_s, ssid, field_name, txt);
6fc6879b
JM
931}
932#else /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
933#define wpa_supplicant_eap_param_needed NULL
934#endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */
935
936
dd5c155e 937#ifdef CONFIG_EAP_PROXY
a6f3761f 938
dd5c155e
SD
939static void wpa_supplicant_eap_proxy_cb(void *ctx)
940{
941 struct wpa_supplicant *wpa_s = ctx;
942 size_t len;
943
b5db6e5d 944 wpa_s->mnc_len = eapol_sm_get_eap_proxy_imsi(wpa_s->eapol, -1,
dd5c155e
SD
945 wpa_s->imsi, &len);
946 if (wpa_s->mnc_len > 0) {
947 wpa_s->imsi[len] = '\0';
948 wpa_printf(MSG_DEBUG, "eap_proxy: IMSI %s (MNC length %d)",
949 wpa_s->imsi, wpa_s->mnc_len);
950 } else {
951 wpa_printf(MSG_DEBUG, "eap_proxy: IMSI not available");
952 }
953}
a6f3761f
PK
954
955
c167662d
PK
956static void wpa_sm_sim_state_error_handler(struct wpa_supplicant *wpa_s)
957{
958 int i;
959 struct wpa_ssid *ssid;
960 const struct eap_method_type *eap_methods;
961
962 if (!wpa_s->conf)
963 return;
964
965 for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) {
966 eap_methods = ssid->eap.eap_methods;
967 if (!eap_methods)
968 continue;
969
970 for (i = 0; eap_methods[i].method != EAP_TYPE_NONE; i++) {
971 if (eap_methods[i].vendor == EAP_VENDOR_IETF &&
972 (eap_methods[i].method == EAP_TYPE_SIM ||
973 eap_methods[i].method == EAP_TYPE_AKA ||
974 eap_methods[i].method == EAP_TYPE_AKA_PRIME)) {
975 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
976 break;
977 }
978 }
979 }
980}
981
982
a6f3761f
PK
983static void
984wpa_supplicant_eap_proxy_notify_sim_status(void *ctx,
985 enum eap_proxy_sim_state sim_state)
986{
987 struct wpa_supplicant *wpa_s = ctx;
988
989 wpa_printf(MSG_DEBUG, "eap_proxy: SIM card status %u", sim_state);
990 switch (sim_state) {
991 case SIM_STATE_ERROR:
c167662d 992 wpa_sm_sim_state_error_handler(wpa_s);
a6f3761f
PK
993 break;
994 default:
995 wpa_printf(MSG_DEBUG, "eap_proxy: SIM card status unknown");
996 break;
997 }
998}
999
dd5c155e
SD
1000#endif /* CONFIG_EAP_PROXY */
1001
1002
4bc181ec
JM
1003static void wpa_supplicant_port_cb(void *ctx, int authorized)
1004{
1005 struct wpa_supplicant *wpa_s = ctx;
69a6b47a
JM
1006#ifdef CONFIG_AP
1007 if (wpa_s->ap_iface) {
1008 wpa_printf(MSG_DEBUG, "AP mode active - skip EAPOL Supplicant "
1009 "port status: %s",
1010 authorized ? "Authorized" : "Unauthorized");
1011 return;
1012 }
1013#endif /* CONFIG_AP */
4bc181ec
JM
1014 wpa_printf(MSG_DEBUG, "EAPOL: Supplicant port status: %s",
1015 authorized ? "Authorized" : "Unauthorized");
1016 wpa_drv_set_supp_port(wpa_s, authorized);
1017}
ade74830
MC
1018
1019
bc0634da
JM
1020static void wpa_supplicant_cert_cb(void *ctx, struct tls_cert_data *cert,
1021 const char *cert_hash)
ade74830
MC
1022{
1023 struct wpa_supplicant *wpa_s = ctx;
1024
bc0634da 1025 wpas_notify_certification(wpa_s, cert, cert_hash);
ade74830 1026}
dd7fec1f
PS
1027
1028
1029static void wpa_supplicant_status_cb(void *ctx, const char *status,
1030 const char *parameter)
1031{
1032 struct wpa_supplicant *wpa_s = ctx;
1033
1034 wpas_notify_eap_status(wpa_s, status, parameter);
1035}
e026159a
JM
1036
1037
45f7574d
AE
1038static void wpa_supplicant_eap_error_cb(void *ctx, int error_code)
1039{
1040 struct wpa_supplicant *wpa_s = ctx;
1041
1042 wpas_notify_eap_error(wpa_s, error_code);
1043}
1044
1045
e026159a
JM
1046static void wpa_supplicant_set_anon_id(void *ctx, const u8 *id, size_t len)
1047{
1048 struct wpa_supplicant *wpa_s = ctx;
1049 char *str;
1050 int res;
1051
1052 wpa_hexdump_ascii(MSG_DEBUG, "EAP method updated anonymous_identity",
1053 id, len);
1054
1055 if (wpa_s->current_ssid == NULL)
1056 return;
1057
1058 if (id == NULL) {
1059 if (wpa_config_set(wpa_s->current_ssid, "anonymous_identity",
1060 "NULL", 0) < 0)
1061 return;
1062 } else {
1063 str = os_malloc(len * 2 + 1);
1064 if (str == NULL)
1065 return;
1066 wpa_snprintf_hex(str, len * 2 + 1, id, len);
1067 res = wpa_config_set(wpa_s->current_ssid, "anonymous_identity",
1068 str, 0);
1069 os_free(str);
1070 if (res < 0)
1071 return;
1072 }
1073
1074 if (wpa_s->conf->update_config) {
1075 res = wpa_config_write(wpa_s->confname, wpa_s->conf);
1076 if (res) {
1077 wpa_printf(MSG_DEBUG, "Failed to update config after "
1078 "anonymous_id update");
1079 }
1080 }
1081}
b1491202 1082#endif /* IEEE8021X_EAPOL */
4bc181ec
JM
1083
1084
6fc6879b
JM
1085int wpa_supplicant_init_eapol(struct wpa_supplicant *wpa_s)
1086{
1087#ifdef IEEE8021X_EAPOL
1088 struct eapol_ctx *ctx;
1089 ctx = os_zalloc(sizeof(*ctx));
1090 if (ctx == NULL) {
1091 wpa_printf(MSG_ERROR, "Failed to allocate EAPOL context.");
1092 return -1;
1093 }
1094
1095 ctx->ctx = wpa_s;
1096 ctx->msg_ctx = wpa_s;
1097 ctx->eapol_send_ctx = wpa_s;
1098 ctx->preauth = 0;
1099 ctx->eapol_done_cb = wpa_supplicant_notify_eapol_done;
1100 ctx->eapol_send = wpa_supplicant_eapol_send;
1101 ctx->set_wep_key = wpa_eapol_set_wep_key;
21f01a8e 1102#ifndef CONFIG_NO_CONFIG_BLOBS
6fc6879b
JM
1103 ctx->set_config_blob = wpa_supplicant_set_config_blob;
1104 ctx->get_config_blob = wpa_supplicant_get_config_blob;
21f01a8e 1105#endif /* CONFIG_NO_CONFIG_BLOBS */
6fc6879b 1106 ctx->aborted_cached = wpa_supplicant_aborted_cached;
6fc6879b
JM
1107 ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path;
1108 ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
1109 ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
07e2de31 1110 ctx->openssl_ciphers = wpa_s->conf->openssl_ciphers;
116654ce 1111 ctx->wps = wpa_s->wps;
6fc6879b 1112 ctx->eap_param_needed = wpa_supplicant_eap_param_needed;
dd5c155e
SD
1113#ifdef CONFIG_EAP_PROXY
1114 ctx->eap_proxy_cb = wpa_supplicant_eap_proxy_cb;
a6f3761f
PK
1115 ctx->eap_proxy_notify_sim_status =
1116 wpa_supplicant_eap_proxy_notify_sim_status;
dd5c155e 1117#endif /* CONFIG_EAP_PROXY */
4bc181ec 1118 ctx->port_cb = wpa_supplicant_port_cb;
6fc6879b 1119 ctx->cb = wpa_supplicant_eapol_cb;
ade74830 1120 ctx->cert_cb = wpa_supplicant_cert_cb;
483dd6a5 1121 ctx->cert_in_cb = wpa_s->conf->cert_in_cb;
dd7fec1f 1122 ctx->status_cb = wpa_supplicant_status_cb;
45f7574d 1123 ctx->eap_error_cb = wpa_supplicant_eap_error_cb;
e026159a 1124 ctx->set_anon_id = wpa_supplicant_set_anon_id;
6fc6879b
JM
1125 ctx->cb_ctx = wpa_s;
1126 wpa_s->eapol = eapol_sm_init(ctx);
1127 if (wpa_s->eapol == NULL) {
1128 os_free(ctx);
1129 wpa_printf(MSG_ERROR, "Failed to initialize EAPOL state "
1130 "machines.");
1131 return -1;
1132 }
1133#endif /* IEEE8021X_EAPOL */
1134
1135 return 0;
1136}
1137
1138
77d7b090 1139#ifndef CONFIG_NO_WPA
124ddfa1 1140
98cd3d1c
JM
1141static void wpa_supplicant_set_rekey_offload(void *ctx,
1142 const u8 *kek, size_t kek_len,
1143 const u8 *kck, size_t kck_len,
b14a210c
JB
1144 const u8 *replay_ctr)
1145{
1146 struct wpa_supplicant *wpa_s = ctx;
1147
98cd3d1c 1148 wpa_drv_set_rekey_info(wpa_s, kek, kek_len, kck, kck_len, replay_ctr);
b14a210c
JB
1149}
1150
1151
b41f2684
CL
1152static int wpa_supplicant_key_mgmt_set_pmk(void *ctx, const u8 *pmk,
1153 size_t pmk_len)
1154{
1155 struct wpa_supplicant *wpa_s = ctx;
1156
a250722f
JM
1157 if (wpa_s->conf->key_mgmt_offload &&
1158 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD))
b41f2684
CL
1159 return wpa_drv_set_key(wpa_s, WPA_ALG_PMK, NULL, 0, 0,
1160 NULL, 0, pmk, pmk_len);
1161 else
1162 return 0;
1163}
124ddfa1
JM
1164
1165
1166static void wpa_supplicant_fils_hlp_rx(void *ctx, const u8 *dst, const u8 *src,
1167 const u8 *pkt, size_t pkt_len)
1168{
1169 struct wpa_supplicant *wpa_s = ctx;
1170 char *hex;
1171 size_t hexlen;
1172
1173 hexlen = pkt_len * 2 + 1;
1174 hex = os_malloc(hexlen);
1175 if (!hex)
1176 return;
1177 wpa_snprintf_hex(hex, hexlen, pkt, pkt_len);
1178 wpa_msg(wpa_s, MSG_INFO, FILS_HLP_RX "dst=" MACSTR " src=" MACSTR
1179 " frame=%s", MAC2STR(dst), MAC2STR(src), hex);
1180 os_free(hex);
1181}
1182
4b62b52e
MV
1183
1184static int wpa_supplicant_channel_info(void *_wpa_s,
1185 struct wpa_channel_info *ci)
1186{
1187 struct wpa_supplicant *wpa_s = _wpa_s;
1188
1189 return wpa_drv_channel_info(wpa_s, ci);
1190}
1191
9e68742e 1192#endif /* CONFIG_NO_WPA */
b41f2684
CL
1193
1194
6fc6879b
JM
1195int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s)
1196{
1197#ifndef CONFIG_NO_WPA
1198 struct wpa_sm_ctx *ctx;
1199 ctx = os_zalloc(sizeof(*ctx));
1200 if (ctx == NULL) {
1201 wpa_printf(MSG_ERROR, "Failed to allocate WPA context.");
1202 return -1;
1203 }
1204
1205 ctx->ctx = wpa_s;
0f057fb2 1206 ctx->msg_ctx = wpa_s;
6fc6879b
JM
1207 ctx->set_state = _wpa_supplicant_set_state;
1208 ctx->get_state = _wpa_supplicant_get_state;
6fc6879b 1209 ctx->deauthenticate = _wpa_supplicant_deauthenticate;
6fc6879b
JM
1210 ctx->set_key = wpa_supplicant_set_key;
1211 ctx->get_network_ctx = wpa_supplicant_get_network_ctx;
1212 ctx->get_bssid = wpa_supplicant_get_bssid;
1213 ctx->ether_send = _wpa_ether_send;
1214 ctx->get_beacon_ie = wpa_supplicant_get_beacon_ie;
1215 ctx->alloc_eapol = _wpa_alloc_eapol;
1216 ctx->cancel_auth_timeout = _wpa_supplicant_cancel_auth_timeout;
1217 ctx->add_pmkid = wpa_supplicant_add_pmkid;
1218 ctx->remove_pmkid = wpa_supplicant_remove_pmkid;
1219#ifndef CONFIG_NO_CONFIG_BLOBS
1220 ctx->set_config_blob = wpa_supplicant_set_config_blob;
1221 ctx->get_config_blob = wpa_supplicant_get_config_blob;
1222#endif /* CONFIG_NO_CONFIG_BLOBS */
1223 ctx->mlme_setprotection = wpa_supplicant_mlme_setprotection;
1224#ifdef CONFIG_IEEE80211R
1225 ctx->update_ft_ies = wpa_supplicant_update_ft_ies;
1226 ctx->send_ft_action = wpa_supplicant_send_ft_action;
2a7e7f4e 1227 ctx->mark_authenticated = wpa_supplicant_mark_authenticated;
6fc6879b 1228#endif /* CONFIG_IEEE80211R */
281ff0aa 1229#ifdef CONFIG_TDLS
c58ab8f2 1230 ctx->tdls_get_capa = wpa_supplicant_tdls_get_capa;
281ff0aa
GP
1231 ctx->send_tdls_mgmt = wpa_supplicant_send_tdls_mgmt;
1232 ctx->tdls_oper = wpa_supplicant_tdls_oper;
45b722f1 1233 ctx->tdls_peer_addset = wpa_supplicant_tdls_peer_addset;
6b90deae
AN
1234 ctx->tdls_enable_channel_switch =
1235 wpa_supplicant_tdls_enable_channel_switch;
1236 ctx->tdls_disable_channel_switch =
1237 wpa_supplicant_tdls_disable_channel_switch;
281ff0aa 1238#endif /* CONFIG_TDLS */
b14a210c 1239 ctx->set_rekey_offload = wpa_supplicant_set_rekey_offload;
b41f2684 1240 ctx->key_mgmt_set_pmk = wpa_supplicant_key_mgmt_set_pmk;
124ddfa1 1241 ctx->fils_hlp_rx = wpa_supplicant_fils_hlp_rx;
4b62b52e 1242 ctx->channel_info = wpa_supplicant_channel_info;
6fc6879b
JM
1243
1244 wpa_s->wpa = wpa_sm_init(ctx);
1245 if (wpa_s->wpa == NULL) {
1246 wpa_printf(MSG_ERROR, "Failed to initialize WPA state "
1247 "machine");
ef035578 1248 os_free(ctx);
6fc6879b
JM
1249 return -1;
1250 }
1251#endif /* CONFIG_NO_WPA */
1252
1253 return 0;
1254}
1255
1256
1257void wpa_supplicant_rsn_supp_set_config(struct wpa_supplicant *wpa_s,
1258 struct wpa_ssid *ssid)
1259{
1260 struct rsn_supp_config conf;
1261 if (ssid) {
1262 os_memset(&conf, 0, sizeof(conf));
886a807f 1263 conf.network_ctx = ssid;
6fc6879b 1264 conf.allowed_pairwise_cipher = ssid->pairwise_cipher;
a6a89fea 1265#ifdef IEEE8021X_EAPOL
6e202021
JM
1266 conf.proactive_key_caching = ssid->proactive_key_caching < 0 ?
1267 wpa_s->conf->okc : ssid->proactive_key_caching;
6fc6879b
JM
1268 conf.eap_workaround = ssid->eap_workaround;
1269 conf.eap_conf_ctx = &ssid->eap;
a6a89fea 1270#endif /* IEEE8021X_EAPOL */
6fc6879b
JM
1271 conf.ssid = ssid->ssid;
1272 conf.ssid_len = ssid->ssid_len;
581a8cde 1273 conf.wpa_ptk_rekey = ssid->wpa_ptk_rekey;
25ef8529 1274#ifdef CONFIG_P2P
201b0f5f
JM
1275 if (ssid->p2p_group && wpa_s->current_bss &&
1276 !wpa_s->p2p_disable_ip_addr_req) {
25ef8529
JM
1277 struct wpabuf *p2p;
1278 p2p = wpa_bss_get_vendor_ie_multi(wpa_s->current_bss,
1279 P2P_IE_VENDOR_TYPE);
1280 if (p2p) {
1281 u8 group_capab;
1282 group_capab = p2p_get_group_capab(p2p);
1283 if (group_capab &
1284 P2P_GROUP_CAPAB_IP_ADDR_ALLOCATION)
1285 conf.p2p = 1;
1286 wpabuf_free(p2p);
1287 }
1288 }
1289#endif /* CONFIG_P2P */
73ed03f3 1290 conf.wpa_rsc_relaxation = wpa_s->conf->wpa_rsc_relaxation;
869af307
JM
1291#ifdef CONFIG_FILS
1292 if (wpa_key_mgmt_fils(wpa_s->key_mgmt))
1293 conf.fils_cache_id =
1294 wpa_bss_get_fils_cache_id(wpa_s->current_bss);
1295#endif /* CONFIG_FILS */
6fc6879b
JM
1296 }
1297 wpa_sm_set_config(wpa_s->wpa, ssid ? &conf : NULL);
1298}