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