2 * WPA Supplicant - Glue code to setup EAPOL and RSN modules
3 * Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
12 #include "eapol_supp/eapol_supp_sm.h"
13 #include "eap_peer/eap.h"
14 #include "rsn_supp/wpa.h"
17 #include "l2_packet/l2_packet.h"
18 #include "common/wpa_common.h"
19 #include "wpa_supplicant_i.h"
21 #include "rsn_supp/pmksa_cache.h"
23 #include "common/ieee802_11_defs.h"
24 #include "common/wpa_ctrl.h"
25 #include "wpas_glue.h"
26 #include "wps_supplicant.h"
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
)
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
);
43 wpa_printf(MSG_DEBUG
, "Failed to update config after "
50 static const struct wpa_config_blob
*
51 wpa_supplicant_get_config_blob(void *ctx
, const char *name
)
53 struct wpa_supplicant
*wpa_s
= ctx
;
54 return wpa_config_get_blob(wpa_s
->conf
, name
);
56 #endif /* defined(IEEE8021X_EAPOL) || !defined(CONFIG_NO_WPA) */
57 #endif /* CONFIG_NO_CONFIG_BLOBS */
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
)
65 struct ieee802_1x_hdr
*hdr
;
67 *msg_len
= sizeof(*hdr
) + data_len
;
68 hdr
= os_malloc(*msg_len
);
72 hdr
->version
= wpa_s
->conf
->eapol_version
;
74 hdr
->length
= host_to_be16(data_len
);
77 os_memcpy(hdr
+ 1, data
, data_len
);
79 os_memset(hdr
+ 1, 0, data_len
);
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
97 static int wpa_ether_send(struct wpa_supplicant
*wpa_s
, const u8
*dest
,
98 u16 proto
, const u8
*buf
, size_t len
)
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
);
107 wpa_snprintf_hex(hex
, hex_len
, buf
, len
);
108 wpa_msg(wpa_s
, MSG_INFO
, "EAPOL-TX " MACSTR
" %s",
113 #endif /* CONFIG_TESTING_OPTIONS */
116 return l2_packet_send(wpa_s
->l2
, dest
, proto
, buf
, len
);
121 #endif /* IEEE8021X_EAPOL || !CONFIG_NO_WPA */
124 #ifdef IEEE8021X_EAPOL
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
134 * This function adds Ethernet and IEEE 802.1X header and sends the EAPOL frame
135 * to the current Authenticator.
137 static int wpa_supplicant_eapol_send(void *ctx
, int type
, const u8
*buf
,
140 struct wpa_supplicant
*wpa_s
= ctx
;
141 u8
*msg
, *dst
, bssid
[ETH_ALEN
];
145 /* TODO: could add l2_packet_sendmsg that allows fragments to avoid
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
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
);
160 if (pmksa_cache_get_current(wpa_s
->wpa
) &&
161 type
== IEEE802_1X_TYPE_EAPOL_START
) {
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.
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");
181 wpa_printf(MSG_DEBUG
,
182 "RSN: PMKSA caching - do not send EAPOL-Start");
187 if (is_zero_ether_addr(wpa_s
->bssid
)) {
188 wpa_printf(MSG_DEBUG
, "BSSID not set when trying to send an "
190 if (wpa_drv_get_bssid(wpa_s
, bssid
) == 0 &&
191 !is_zero_ether_addr(bssid
)) {
193 wpa_printf(MSG_DEBUG
, "Using current BSSID " MACSTR
194 " from the driver as the EAPOL destination",
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",
204 /* BSSID was already set (from (Re)Assoc event, so use it as
205 * the EAPOL destination. */
209 msg
= wpa_alloc_eapol(wpa_s
, type
, buf
, len
, &msglen
, NULL
);
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
);
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.
230 static int wpa_eapol_set_wep_key(void *ctx
, int unicast
, int keyidx
,
231 const u8
*key
, size_t keylen
)
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
:
238 wpa_s
->pairwise_cipher
= cipher
;
240 wpa_s
->group_cipher
= cipher
;
242 return wpa_drv_set_key(wpa_s
, WPA_ALG_WEP
,
243 unicast
? wpa_s
->bssid
: NULL
,
244 keyidx
, unicast
, NULL
, 0, key
, keylen
);
248 static void wpa_supplicant_aborted_cached(void *ctx
)
250 struct wpa_supplicant
*wpa_s
= ctx
;
251 wpa_sm_aborted_cached(wpa_s
->wpa
);
255 static const char * result_str(enum eapol_supp_result result
)
258 case EAPOL_SUPP_RESULT_FAILURE
:
260 case EAPOL_SUPP_RESULT_SUCCESS
:
262 case EAPOL_SUPP_RESULT_EXPECTED_FAILURE
:
263 return "EXPECTED_FAILURE";
269 static void wpa_supplicant_eapol_cb(struct eapol_sm
*eapol
,
270 enum eapol_supp_result result
,
273 struct wpa_supplicant
*wpa_s
= ctx
;
277 wpa_printf(MSG_DEBUG
, "EAPOL authentication completed - result=%s",
280 if (wpas_wps_eapol_cb(wpa_s
) > 0)
283 wpa_s
->eap_expected_failure
= result
==
284 EAPOL_SUPP_RESULT_EXPECTED_FAILURE
;
286 if (result
!= EAPOL_SUPP_RESULT_SUCCESS
) {
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.
292 wpa_supplicant_req_auth_timeout(wpa_s
, 2, 0);
294 ieee802_1x_notify_create_actor(wpa_s
, wpa_s
->last_eapol_src
);
297 if (result
!= EAPOL_SUPP_RESULT_SUCCESS
||
298 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_4WAY_HANDSHAKE
))
301 if (!wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
))
304 wpa_printf(MSG_DEBUG
, "Configure PMK for driver-based RSN 4-way "
308 if (wpa_key_mgmt_ft(wpa_s
->key_mgmt
)) {
309 #ifdef CONFIG_IEEE80211R
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
);
315 os_memcpy(pmk
, buf
+ PMK_LEN
, PMK_LEN
);
316 os_memset(buf
, 0, sizeof(buf
));
318 #else /* CONFIG_IEEE80211R */
320 #endif /* CONFIG_IEEE80211R */
322 res
= eapol_sm_get_key(eapol
, pmk
, PMK_LEN
);
325 * EAP-LEAP is an exception from other EAP methods: it
326 * uses only 16-byte PMK.
328 res
= eapol_sm_get_key(eapol
, pmk
, 16);
334 wpa_printf(MSG_DEBUG
, "Failed to get PMK from EAPOL state "
339 wpa_hexdump_key(MSG_DEBUG
, "RSN: Configure PMK for driver-based 4-way "
340 "handshake", pmk
, pmk_len
);
342 if (wpa_drv_set_key(wpa_s
, WPA_ALG_PMK
, NULL
, 0, 0, NULL
, 0, pmk
,
344 wpa_printf(MSG_DEBUG
, "Failed to set PMK to the driver");
347 wpa_supplicant_cancel_scan(wpa_s
);
348 wpa_supplicant_cancel_auth_timeout(wpa_s
);
349 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
354 static void wpa_supplicant_notify_eapol_done(void *ctx
)
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
);
361 wpa_supplicant_cancel_auth_timeout(wpa_s
);
362 wpa_supplicant_set_state(wpa_s
, WPA_COMPLETED
);
366 #endif /* IEEE8021X_EAPOL */
369 #ifndef CONFIG_NO_WPA
371 static int wpa_get_beacon_ie(struct wpa_supplicant
*wpa_s
)
374 struct wpa_bss
*curr
= NULL
, *bss
;
375 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
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)
382 ((bss
->ssid_len
== ssid
->ssid_len
&&
383 os_memcmp(bss
->ssid
, ssid
->ssid
, ssid
->ssid_len
) == 0) ||
384 ssid
->ssid_len
== 0)) {
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))
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))
406 static int wpa_supplicant_get_beacon_ie(void *ctx
)
408 struct wpa_supplicant
*wpa_s
= ctx
;
409 if (wpa_get_beacon_ie(wpa_s
) == 0) {
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)
418 return wpa_get_beacon_ie(wpa_s
);
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
)
426 return wpa_alloc_eapol(wpa_s
, type
, data
, data_len
, msg_len
, data_pos
);
430 static int _wpa_ether_send(void *wpa_s
, const u8
*dest
, u16 proto
,
431 const u8
*buf
, size_t len
)
433 return wpa_ether_send(wpa_s
, dest
, proto
, buf
, len
);
437 static void _wpa_supplicant_cancel_auth_timeout(void *wpa_s
)
439 wpa_supplicant_cancel_auth_timeout(wpa_s
);
443 static void _wpa_supplicant_set_state(void *wpa_s
, enum wpa_states state
)
445 wpa_supplicant_set_state(wpa_s
, state
);
450 * wpa_supplicant_get_state - Get the connection state
451 * @wpa_s: Pointer to wpa_supplicant data
452 * Returns: The current connection state (WPA_*)
454 static enum wpa_states
wpa_supplicant_get_state(struct wpa_supplicant
*wpa_s
)
456 return wpa_s
->wpa_state
;
460 static enum wpa_states
_wpa_supplicant_get_state(void *wpa_s
)
462 return wpa_supplicant_get_state(wpa_s
);
466 static void _wpa_supplicant_deauthenticate(void *wpa_s
, int reason_code
)
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);
474 static void * wpa_supplicant_get_network_ctx(void *wpa_s
)
476 return wpa_supplicant_get_ssid(wpa_s
);
480 static int wpa_supplicant_get_bssid(void *ctx
, u8
*bssid
)
482 struct wpa_supplicant
*wpa_s
= ctx
;
483 return wpa_drv_get_bssid(wpa_s
, bssid
);
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
)
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;
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
;
503 #endif /* CONFIG_TESTING_GET_GTK */
504 return wpa_drv_set_key(wpa_s
, alg
, addr
, key_idx
, set_tx
, seq
, seq_len
,
509 static int wpa_supplicant_mlme_setprotection(void *wpa_s
, const u8
*addr
,
513 return wpa_drv_mlme_setprotection(wpa_s
, addr
, protection_type
,
518 static struct wpa_ssid
* wpas_get_network_ctx(struct wpa_supplicant
*wpa_s
,
521 struct wpa_ssid
*ssid
;
523 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
524 if (network_ctx
== ssid
)
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
)
537 struct wpa_supplicant
*wpa_s
= _wpa_s
;
538 struct wpa_ssid
*ssid
;
539 struct wpa_pmkid_params params
;
541 os_memset(¶ms
, 0, sizeof(params
));
542 ssid
= wpas_get_network_ctx(wpa_s
, network_ctx
);
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
;
551 params
.bssid
= bssid
;
554 params
.pmkid
= pmkid
;
556 params
.pmk_len
= pmk_len
;
558 return wpa_drv_add_pmkid(wpa_s
, ¶ms
);
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
)
566 struct wpa_supplicant
*wpa_s
= _wpa_s
;
567 struct wpa_ssid
*ssid
;
568 struct wpa_pmkid_params params
;
570 os_memset(¶ms
, 0, sizeof(params
));
571 ssid
= wpas_get_network_ctx(wpa_s
, network_ctx
);
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
;
580 params
.bssid
= bssid
;
583 params
.pmkid
= pmkid
;
585 return wpa_drv_remove_pmkid(wpa_s
, ¶ms
);
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
)
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
);
600 static int wpa_supplicant_send_ft_action(void *ctx
, u8 action
,
602 const u8
*ies
, size_t ies_len
)
604 struct wpa_supplicant
*wpa_s
= ctx
;
610 wpa_printf(MSG_ERROR
, "Unsupported send_ft_action action %d",
616 * Action frame payload:
617 * Category[1] = 6 (Fast BSS Transition)
618 * Action[1] = 1 (Fast BSS Transition Request)
624 data_len
= 2 + 2 * ETH_ALEN
+ ies_len
;
625 data
= os_malloc(data_len
);
629 *pos
++ = 0x06; /* FT Action category */
631 os_memcpy(pos
, wpa_s
->own_addr
, ETH_ALEN
);
633 os_memcpy(pos
, target_ap
, ETH_ALEN
);
635 os_memcpy(pos
, ies
, ies_len
);
637 ret
= wpa_drv_send_action(wpa_s
, wpa_s
->assoc_freq
, 0,
638 wpa_s
->bssid
, wpa_s
->own_addr
, wpa_s
->bssid
,
646 static int wpa_supplicant_mark_authenticated(void *ctx
, const u8
*target_ap
)
648 struct wpa_supplicant
*wpa_s
= ctx
;
649 struct wpa_driver_auth_params params
;
652 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
656 os_memset(¶ms
, 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
, ¶ms
);
665 #endif /* CONFIG_IEEE80211R */
670 static int wpa_supplicant_tdls_get_capa(void *ctx
, int *tdls_supported
,
672 int *tdls_chan_switch
)
674 struct wpa_supplicant
*wpa_s
= ctx
;
678 *tdls_chan_switch
= 0;
680 if (!wpa_s
->drv_capa_known
)
683 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
)
686 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
)
689 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH
)
690 *tdls_chan_switch
= 1;
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
,
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
,
709 static int wpa_supplicant_tdls_oper(void *ctx
, int oper
, const u8
*peer
)
711 struct wpa_supplicant
*wpa_s
= ctx
;
712 return wpa_drv_tdls_oper(wpa_s
, oper
, peer
);
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
)
725 struct wpa_supplicant
*wpa_s
= ctx
;
726 struct hostapd_sta_add_params params
;
728 os_memset(¶ms
, 0, sizeof(params
));
732 params
.capability
= capability
;
733 params
.flags
= WPA_STA_TDLS_PEER
| WPA_STA_AUTHORIZED
;
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.
740 params
.flags
|= WPA_STA_WMM
;
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
;
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
;
756 return wpa_drv_sta_add(wpa_s
, ¶ms
);
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
)
764 struct wpa_supplicant
*wpa_s
= ctx
;
766 return wpa_drv_tdls_enable_channel_switch(wpa_s
, addr
, oper_class
,
771 static int wpa_supplicant_tdls_disable_channel_switch(void *ctx
, const u8
*addr
)
773 struct wpa_supplicant
*wpa_s
= ctx
;
775 return wpa_drv_tdls_disable_channel_switch(wpa_s
, addr
);
778 #endif /* CONFIG_TDLS */
780 #endif /* CONFIG_NO_WPA */
783 enum wpa_ctrl_req_type
wpa_supplicant_ctrl_req_from_string(const char *field
)
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
;
807 const char * wpa_supplicant_ctrl_req_to_string(enum wpa_ctrl_req_type field
,
808 const char *default_txt
,
811 const char *ret
= NULL
;
816 case WPA_CTRL_REQ_EAP_IDENTITY
:
820 case WPA_CTRL_REQ_EAP_PASSWORD
:
824 case WPA_CTRL_REQ_EAP_NEW_PASSWORD
:
825 *txt
= "New Password";
826 ret
= "NEW_PASSWORD";
828 case WPA_CTRL_REQ_EAP_PIN
:
832 case WPA_CTRL_REQ_EAP_OTP
:
835 case WPA_CTRL_REQ_EAP_PASSPHRASE
:
836 *txt
= "Private key passphrase";
839 case WPA_CTRL_REQ_SIM
:
842 case WPA_CTRL_REQ_PSK_PASSPHRASE
:
843 *txt
= "PSK or passphrase";
844 ret
= "PSK_PASSPHRASE";
846 case WPA_CTRL_REQ_EXT_CERT_CHECK
:
847 *txt
= "External server certificate validation";
848 ret
= "EXT_CERT_CHECK";
854 /* txt needs to be something */
856 wpa_printf(MSG_WARNING
, "No message for request %d", field
);
864 void wpas_send_ctrl_req(struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
865 const char *field_name
, const char *txt
)
871 buflen
= 100 + os_strlen(txt
) + ssid
->ssid_len
;
872 buf
= os_malloc(buflen
);
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
)) {
881 if (ssid
->ssid
&& buflen
> len
+ ssid
->ssid_len
) {
882 os_memcpy(buf
+ len
, ssid
->ssid
, ssid
->ssid_len
);
883 len
+= ssid
->ssid_len
;
886 buf
[buflen
- 1] = '\0';
887 wpa_msg(wpa_s
, MSG_INFO
, WPA_CTRL_REQ
"%s", buf
);
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
)
898 struct wpa_supplicant
*wpa_s
= ctx
;
899 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
900 const char *field_name
, *txt
= NULL
;
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
);
909 field_name
= wpa_supplicant_ctrl_req_to_string(field
, default_txt
,
911 if (field_name
== NULL
) {
912 wpa_printf(MSG_WARNING
, "Unhandled EAP param %d needed",
917 wpas_notify_eap_status(wpa_s
, "eap parameter needed", field_name
);
919 wpas_send_ctrl_req(wpa_s
, ssid
, field_name
, txt
);
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 */
926 #ifdef CONFIG_EAP_PROXY
928 static void wpa_supplicant_eap_proxy_cb(void *ctx
)
930 struct wpa_supplicant
*wpa_s
= ctx
;
933 wpa_s
->mnc_len
= eapol_sm_get_eap_proxy_imsi(wpa_s
->eapol
, -1,
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
);
940 wpa_printf(MSG_DEBUG
, "eap_proxy: IMSI not available");
945 static void wpa_sm_sim_state_error_handler(struct wpa_supplicant
*wpa_s
)
948 struct wpa_ssid
*ssid
;
949 const struct eap_method_type
*eap_methods
;
954 for (ssid
= wpa_s
->conf
->ssid
; ssid
; ssid
= ssid
->next
) {
955 eap_methods
= ssid
->eap
.eap_methods
;
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
);
973 wpa_supplicant_eap_proxy_notify_sim_status(void *ctx
,
974 enum eap_proxy_sim_state sim_state
)
976 struct wpa_supplicant
*wpa_s
= ctx
;
978 wpa_printf(MSG_DEBUG
, "eap_proxy: SIM card status %u", sim_state
);
980 case SIM_STATE_ERROR
:
981 wpa_sm_sim_state_error_handler(wpa_s
);
984 wpa_printf(MSG_DEBUG
, "eap_proxy: SIM card status unknown");
989 #endif /* CONFIG_EAP_PROXY */
992 static void wpa_supplicant_port_cb(void *ctx
, int authorized
)
994 struct wpa_supplicant
*wpa_s
= ctx
;
996 if (wpa_s
->ap_iface
) {
997 wpa_printf(MSG_DEBUG
, "AP mode active - skip EAPOL Supplicant "
999 authorized
? "Authorized" : "Unauthorized");
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
);
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
)
1014 struct wpa_supplicant
*wpa_s
= ctx
;
1016 wpas_notify_certification(wpa_s
, depth
, subject
, altsubject
,
1017 num_altsubject
, cert_hash
, cert
);
1021 static void wpa_supplicant_status_cb(void *ctx
, const char *status
,
1022 const char *parameter
)
1024 struct wpa_supplicant
*wpa_s
= ctx
;
1026 wpas_notify_eap_status(wpa_s
, status
, parameter
);
1030 static void wpa_supplicant_set_anon_id(void *ctx
, const u8
*id
, size_t len
)
1032 struct wpa_supplicant
*wpa_s
= ctx
;
1036 wpa_hexdump_ascii(MSG_DEBUG
, "EAP method updated anonymous_identity",
1039 if (wpa_s
->current_ssid
== NULL
)
1043 if (wpa_config_set(wpa_s
->current_ssid
, "anonymous_identity",
1047 str
= os_malloc(len
* 2 + 1);
1050 wpa_snprintf_hex(str
, len
* 2 + 1, id
, len
);
1051 res
= wpa_config_set(wpa_s
->current_ssid
, "anonymous_identity",
1058 if (wpa_s
->conf
->update_config
) {
1059 res
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
1061 wpa_printf(MSG_DEBUG
, "Failed to update config after "
1062 "anonymous_id update");
1066 #endif /* IEEE8021X_EAPOL */
1069 int wpa_supplicant_init_eapol(struct wpa_supplicant
*wpa_s
)
1071 #ifdef IEEE8021X_EAPOL
1072 struct eapol_ctx
*ctx
;
1073 ctx
= os_zalloc(sizeof(*ctx
));
1075 wpa_printf(MSG_ERROR
, "Failed to allocate EAPOL context.");
1080 ctx
->msg_ctx
= wpa_s
;
1081 ctx
->eapol_send_ctx
= wpa_s
;
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
) {
1112 wpa_printf(MSG_ERROR
, "Failed to initialize EAPOL state "
1116 #endif /* IEEE8021X_EAPOL */
1122 #ifndef CONFIG_NO_WPA
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
)
1129 struct wpa_supplicant
*wpa_s
= ctx
;
1131 wpa_drv_set_rekey_info(wpa_s
, kek
, kek_len
, kck
, kck_len
, replay_ctr
);
1135 static int wpa_supplicant_key_mgmt_set_pmk(void *ctx
, const u8
*pmk
,
1138 struct wpa_supplicant
*wpa_s
= ctx
;
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
);
1149 static void wpa_supplicant_fils_hlp_rx(void *ctx
, const u8
*dst
, const u8
*src
,
1150 const u8
*pkt
, size_t pkt_len
)
1152 struct wpa_supplicant
*wpa_s
= ctx
;
1156 hexlen
= pkt_len
* 2 + 1;
1157 hex
= os_malloc(hexlen
);
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
);
1166 #endif /* CONFIG_NO_WPA */
1169 int wpa_supplicant_init_wpa(struct wpa_supplicant
*wpa_s
)
1171 #ifndef CONFIG_NO_WPA
1172 struct wpa_sm_ctx
*ctx
;
1173 ctx
= os_zalloc(sizeof(*ctx
));
1175 wpa_printf(MSG_ERROR
, "Failed to allocate WPA context.");
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 */
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
;
1217 wpa_s
->wpa
= wpa_sm_init(ctx
);
1218 if (wpa_s
->wpa
== NULL
) {
1219 wpa_printf(MSG_ERROR
, "Failed to initialize WPA state "
1224 #endif /* CONFIG_NO_WPA */
1230 void wpa_supplicant_rsn_supp_set_config(struct wpa_supplicant
*wpa_s
,
1231 struct wpa_ssid
*ssid
)
1233 struct rsn_supp_config conf
;
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
;
1249 if (ssid
->p2p_group
&& wpa_s
->current_bss
&&
1250 !wpa_s
->p2p_disable_ip_addr_req
) {
1252 p2p
= wpa_bss_get_vendor_ie_multi(wpa_s
->current_bss
,
1253 P2P_IE_VENDOR_TYPE
);
1256 group_capab
= p2p_get_group_capab(p2p
);
1258 P2P_GROUP_CAPAB_IP_ADDR_ALLOCATION
)
1263 #endif /* CONFIG_P2P */
1264 conf
.wpa_rsc_relaxation
= wpa_s
->conf
->wpa_rsc_relaxation
;
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 */
1271 wpa_sm_set_config(wpa_s
->wpa
, ssid
? &conf
: NULL
);