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