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