2 * hostapd / WPA authenticator glue code
3 * Copyright (c) 2002-2012, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "utils/list.h"
14 #include "common/ieee802_11_defs.h"
15 #include "common/sae.h"
16 #include "common/wpa_ctrl.h"
17 #include "crypto/sha1.h"
18 #include "eapol_auth/eapol_auth_sm.h"
19 #include "eapol_auth/eapol_auth_sm_i.h"
20 #include "eap_server/eap.h"
21 #include "l2_packet/l2_packet.h"
22 #include "eth_p_oui.h"
24 #include "ieee802_1x.h"
25 #include "preauth_auth.h"
27 #include "tkip_countermeasures.h"
28 #include "ap_drv_ops.h"
29 #include "ap_config.h"
30 #include "ieee802_11.h"
31 #include "pmksa_cache_auth.h"
33 #include "wpa_auth_glue.h"
36 static void hostapd_wpa_auth_conf(struct hostapd_bss_config
*conf
,
37 struct hostapd_config
*iconf
,
38 struct wpa_auth_config
*wconf
)
42 os_memset(wconf
, 0, sizeof(*wconf
));
43 wconf
->wpa
= conf
->wpa
;
44 wconf
->extended_key_id
= conf
->extended_key_id
;
45 wconf
->wpa_key_mgmt
= conf
->wpa_key_mgmt
;
46 wconf
->wpa_pairwise
= conf
->wpa_pairwise
;
47 wconf
->wpa_group
= conf
->wpa_group
;
48 wconf
->wpa_group_rekey
= conf
->wpa_group_rekey
;
49 wconf
->wpa_strict_rekey
= conf
->wpa_strict_rekey
;
50 wconf
->wpa_gmk_rekey
= conf
->wpa_gmk_rekey
;
51 wconf
->wpa_ptk_rekey
= conf
->wpa_ptk_rekey
;
52 wconf
->wpa_group_update_count
= conf
->wpa_group_update_count
;
53 wconf
->wpa_disable_eapol_key_retries
=
54 conf
->wpa_disable_eapol_key_retries
;
55 wconf
->wpa_pairwise_update_count
= conf
->wpa_pairwise_update_count
;
56 wconf
->rsn_pairwise
= conf
->rsn_pairwise
;
57 wconf
->rsn_preauth
= conf
->rsn_preauth
;
58 wconf
->eapol_version
= conf
->eapol_version
;
60 if (wconf
->eapol_version
> 2)
61 wconf
->eapol_version
= 2;
62 #endif /* CONFIG_MACSEC */
63 wconf
->wmm_enabled
= conf
->wmm_enabled
;
64 wconf
->wmm_uapsd
= conf
->wmm_uapsd
;
65 wconf
->disable_pmksa_caching
= conf
->disable_pmksa_caching
;
67 wconf
->ocv
= conf
->ocv
;
68 #endif /* CONFIG_OCV */
69 wconf
->okc
= conf
->okc
;
70 wconf
->ieee80211w
= conf
->ieee80211w
;
71 wconf
->beacon_prot
= conf
->beacon_prot
;
72 wconf
->group_mgmt_cipher
= conf
->group_mgmt_cipher
;
73 wconf
->sae_require_mfp
= conf
->sae_require_mfp
;
74 #ifdef CONFIG_IEEE80211R_AP
75 wconf
->ssid_len
= conf
->ssid
.ssid_len
;
76 if (wconf
->ssid_len
> SSID_MAX_LEN
)
77 wconf
->ssid_len
= SSID_MAX_LEN
;
78 os_memcpy(wconf
->ssid
, conf
->ssid
.ssid
, wconf
->ssid_len
);
79 os_memcpy(wconf
->mobility_domain
, conf
->mobility_domain
,
80 MOBILITY_DOMAIN_ID_LEN
);
81 if (conf
->nas_identifier
&&
82 os_strlen(conf
->nas_identifier
) <= FT_R0KH_ID_MAX_LEN
) {
83 wconf
->r0_key_holder_len
= os_strlen(conf
->nas_identifier
);
84 os_memcpy(wconf
->r0_key_holder
, conf
->nas_identifier
,
85 wconf
->r0_key_holder_len
);
87 os_memcpy(wconf
->r1_key_holder
, conf
->r1_key_holder
, FT_R1KH_ID_LEN
);
88 wconf
->r0_key_lifetime
= conf
->r0_key_lifetime
;
89 wconf
->r1_max_key_lifetime
= conf
->r1_max_key_lifetime
;
90 wconf
->reassociation_deadline
= conf
->reassociation_deadline
;
91 wconf
->rkh_pos_timeout
= conf
->rkh_pos_timeout
;
92 wconf
->rkh_neg_timeout
= conf
->rkh_neg_timeout
;
93 wconf
->rkh_pull_timeout
= conf
->rkh_pull_timeout
;
94 wconf
->rkh_pull_retries
= conf
->rkh_pull_retries
;
95 wconf
->r0kh_list
= &conf
->r0kh_list
;
96 wconf
->r1kh_list
= &conf
->r1kh_list
;
97 wconf
->pmk_r1_push
= conf
->pmk_r1_push
;
98 wconf
->ft_over_ds
= conf
->ft_over_ds
;
99 wconf
->ft_psk_generate_local
= conf
->ft_psk_generate_local
;
100 #endif /* CONFIG_IEEE80211R_AP */
102 wconf
->disable_gtk
= conf
->disable_dgaf
;
104 wconf
->disable_gtk
= 1;
105 wconf
->wpa
= WPA_PROTO_OSEN
;
106 wconf
->wpa_key_mgmt
= WPA_KEY_MGMT_OSEN
;
107 wconf
->wpa_pairwise
= 0;
108 wconf
->wpa_group
= WPA_CIPHER_CCMP
;
109 wconf
->rsn_pairwise
= WPA_CIPHER_CCMP
;
110 wconf
->rsn_preauth
= 0;
111 wconf
->disable_pmksa_caching
= 1;
112 wconf
->ieee80211w
= 1;
114 #endif /* CONFIG_HS20 */
115 #ifdef CONFIG_TESTING_OPTIONS
116 wconf
->corrupt_gtk_rekey_mic_probability
=
117 iconf
->corrupt_gtk_rekey_mic_probability
;
118 if (conf
->own_ie_override
&&
119 wpabuf_len(conf
->own_ie_override
) <= MAX_OWN_IE_OVERRIDE
) {
120 wconf
->own_ie_override_len
= wpabuf_len(conf
->own_ie_override
);
121 os_memcpy(wconf
->own_ie_override
,
122 wpabuf_head(conf
->own_ie_override
),
123 wconf
->own_ie_override_len
);
125 if (conf
->rsne_override_eapol
&&
126 wpabuf_len(conf
->rsne_override_eapol
) <= MAX_OWN_IE_OVERRIDE
) {
127 wconf
->rsne_override_eapol_set
= 1;
128 wconf
->rsne_override_eapol_len
=
129 wpabuf_len(conf
->rsne_override_eapol
);
130 os_memcpy(wconf
->rsne_override_eapol
,
131 wpabuf_head(conf
->rsne_override_eapol
),
132 wconf
->rsne_override_eapol_len
);
134 if (conf
->rsnxe_override_eapol
&&
135 wpabuf_len(conf
->rsnxe_override_eapol
) <= MAX_OWN_IE_OVERRIDE
) {
136 wconf
->rsnxe_override_eapol_set
= 1;
137 wconf
->rsnxe_override_eapol_len
=
138 wpabuf_len(conf
->rsnxe_override_eapol
);
139 os_memcpy(wconf
->rsnxe_override_eapol
,
140 wpabuf_head(conf
->rsnxe_override_eapol
),
141 wconf
->rsnxe_override_eapol_len
);
143 if (conf
->rsne_override_ft
&&
144 wpabuf_len(conf
->rsne_override_ft
) <= MAX_OWN_IE_OVERRIDE
) {
145 wconf
->rsne_override_ft_set
= 1;
146 wconf
->rsne_override_ft_len
=
147 wpabuf_len(conf
->rsne_override_ft
);
148 os_memcpy(wconf
->rsne_override_ft
,
149 wpabuf_head(conf
->rsne_override_ft
),
150 wconf
->rsne_override_ft_len
);
152 if (conf
->rsnxe_override_ft
&&
153 wpabuf_len(conf
->rsnxe_override_ft
) <= MAX_OWN_IE_OVERRIDE
) {
154 wconf
->rsnxe_override_ft_set
= 1;
155 wconf
->rsnxe_override_ft_len
=
156 wpabuf_len(conf
->rsnxe_override_ft
);
157 os_memcpy(wconf
->rsnxe_override_ft
,
158 wpabuf_head(conf
->rsnxe_override_ft
),
159 wconf
->rsnxe_override_ft_len
);
161 if (conf
->gtk_rsc_override
&&
162 wpabuf_len(conf
->gtk_rsc_override
) > 0 &&
163 wpabuf_len(conf
->gtk_rsc_override
) <= WPA_KEY_RSC_LEN
) {
164 os_memcpy(wconf
->gtk_rsc_override
,
165 wpabuf_head(conf
->gtk_rsc_override
),
166 wpabuf_len(conf
->gtk_rsc_override
));
167 wconf
->gtk_rsc_override_set
= 1;
169 if (conf
->igtk_rsc_override
&&
170 wpabuf_len(conf
->igtk_rsc_override
) > 0 &&
171 wpabuf_len(conf
->igtk_rsc_override
) <= WPA_KEY_RSC_LEN
) {
172 os_memcpy(wconf
->igtk_rsc_override
,
173 wpabuf_head(conf
->igtk_rsc_override
),
174 wpabuf_len(conf
->igtk_rsc_override
));
175 wconf
->igtk_rsc_override_set
= 1;
177 #endif /* CONFIG_TESTING_OPTIONS */
179 os_memcpy(wconf
->ip_addr_go
, conf
->ip_addr_go
, 4);
180 os_memcpy(wconf
->ip_addr_mask
, conf
->ip_addr_mask
, 4);
181 os_memcpy(wconf
->ip_addr_start
, conf
->ip_addr_start
, 4);
182 os_memcpy(wconf
->ip_addr_end
, conf
->ip_addr_end
, 4);
183 #endif /* CONFIG_P2P */
185 wconf
->fils_cache_id_set
= conf
->fils_cache_id_set
;
186 os_memcpy(wconf
->fils_cache_id
, conf
->fils_cache_id
,
188 #endif /* CONFIG_FILS */
189 wconf
->sae_pwe
= conf
->sae_pwe
;
190 sae_pw_id
= hostapd_sae_pw_id_in_use(conf
);
191 if (sae_pw_id
== 2 && wconf
->sae_pwe
!= 3)
193 else if (sae_pw_id
== 1 && wconf
->sae_pwe
== 0)
196 wconf
->owe_ptk_workaround
= conf
->owe_ptk_workaround
;
197 #endif /* CONFIG_OWE */
198 wconf
->transition_disable
= conf
->transition_disable
;
200 wconf
->dpp_pfs
= conf
->dpp_pfs
;
201 #endif /* CONFIG_DPP2 */
205 static void hostapd_wpa_auth_logger(void *ctx
, const u8
*addr
,
206 logger_level level
, const char *txt
)
208 #ifndef CONFIG_NO_HOSTAPD_LOGGER
209 struct hostapd_data
*hapd
= ctx
;
214 hlevel
= HOSTAPD_LEVEL_WARNING
;
217 hlevel
= HOSTAPD_LEVEL_INFO
;
221 hlevel
= HOSTAPD_LEVEL_DEBUG
;
225 hostapd_logger(hapd
, addr
, HOSTAPD_MODULE_WPA
, hlevel
, "%s", txt
);
226 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
230 static void hostapd_wpa_auth_disconnect(void *ctx
, const u8
*addr
,
233 struct hostapd_data
*hapd
= ctx
;
234 wpa_printf(MSG_DEBUG
, "%s: WPA authenticator requests disconnect: "
235 "STA " MACSTR
" reason %d",
236 __func__
, MAC2STR(addr
), reason
);
237 ap_sta_disconnect(hapd
, NULL
, addr
, reason
);
241 static int hostapd_wpa_auth_mic_failure_report(void *ctx
, const u8
*addr
)
243 struct hostapd_data
*hapd
= ctx
;
244 return michael_mic_failure(hapd
, addr
, 0);
248 static void hostapd_wpa_auth_psk_failure_report(void *ctx
, const u8
*addr
)
250 struct hostapd_data
*hapd
= ctx
;
251 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR
,
256 static void hostapd_wpa_auth_set_eapol(void *ctx
, const u8
*addr
,
257 wpa_eapol_variable var
, int value
)
259 struct hostapd_data
*hapd
= ctx
;
260 struct sta_info
*sta
= ap_get_sta(hapd
, addr
);
264 case WPA_EAPOL_portEnabled
:
265 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, value
);
267 case WPA_EAPOL_portValid
:
268 ieee802_1x_notify_port_valid(sta
->eapol_sm
, value
);
270 case WPA_EAPOL_authorized
:
271 ieee802_1x_set_sta_authorized(hapd
, sta
, value
);
273 case WPA_EAPOL_portControl_Auto
:
275 sta
->eapol_sm
->portControl
= Auto
;
277 case WPA_EAPOL_keyRun
:
279 sta
->eapol_sm
->keyRun
= value
? TRUE
: FALSE
;
281 case WPA_EAPOL_keyAvailable
:
283 sta
->eapol_sm
->eap_if
->eapKeyAvailable
=
284 value
? TRUE
: FALSE
;
286 case WPA_EAPOL_keyDone
:
288 sta
->eapol_sm
->keyDone
= value
? TRUE
: FALSE
;
290 case WPA_EAPOL_inc_EapolFramesTx
:
292 sta
->eapol_sm
->dot1xAuthEapolFramesTx
++;
298 static int hostapd_wpa_auth_get_eapol(void *ctx
, const u8
*addr
,
299 wpa_eapol_variable var
)
301 struct hostapd_data
*hapd
= ctx
;
302 struct sta_info
*sta
= ap_get_sta(hapd
, addr
);
303 if (sta
== NULL
|| sta
->eapol_sm
== NULL
)
306 case WPA_EAPOL_keyRun
:
307 return sta
->eapol_sm
->keyRun
;
308 case WPA_EAPOL_keyAvailable
:
309 return sta
->eapol_sm
->eap_if
->eapKeyAvailable
;
316 static const u8
* hostapd_wpa_auth_get_psk(void *ctx
, const u8
*addr
,
317 const u8
*p2p_dev_addr
,
318 const u8
*prev_psk
, size_t *psk_len
,
321 struct hostapd_data
*hapd
= ctx
;
322 struct sta_info
*sta
= ap_get_sta(hapd
, addr
);
331 if (sta
&& sta
->auth_alg
== WLAN_AUTH_SAE
) {
332 if (!sta
->sae
|| prev_psk
)
334 return sta
->sae
->pmk
;
336 if (sta
&& wpa_auth_uses_sae(sta
->wpa_sm
)) {
337 wpa_printf(MSG_DEBUG
,
338 "No PSK for STA trying to use SAE with PMKSA caching");
341 #endif /* CONFIG_SAE */
344 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) &&
345 sta
&& sta
->owe_pmk
) {
347 *psk_len
= sta
->owe_pmk_len
;
350 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) && sta
) {
351 struct rsn_pmksa_cache_entry
*sa
;
353 sa
= wpa_auth_sta_get_pmksa(sta
->wpa_sm
);
354 if (sa
&& sa
->akmp
== WPA_KEY_MGMT_OWE
) {
356 *psk_len
= sa
->pmk_len
;
360 #endif /* CONFIG_OWE */
362 psk
= hostapd_get_psk(hapd
->conf
, addr
, p2p_dev_addr
, prev_psk
,
365 * This is about to iterate over all psks, prev_psk gives the last
366 * returned psk which should not be returned again.
367 * logic list (all hostapd_get_psk; all sta->psk)
369 if (sta
&& sta
->psk
&& !psk
) {
370 struct hostapd_sta_wpa_psk_short
*pos
;
375 for (pos
= sta
->psk
; pos
; pos
= pos
->next
) {
376 if (pos
->is_passphrase
) {
377 pbkdf2_sha1(pos
->passphrase
,
378 hapd
->conf
->ssid
.ssid
,
379 hapd
->conf
->ssid
.ssid_len
, 4096,
381 pos
->is_passphrase
= 0;
383 if (pos
->psk
== prev_psk
) {
384 psk
= pos
->next
? pos
->next
->psk
: NULL
;
393 static int hostapd_wpa_auth_get_msk(void *ctx
, const u8
*addr
, u8
*msk
,
396 struct hostapd_data
*hapd
= ctx
;
399 struct sta_info
*sta
;
401 sta
= ap_get_sta(hapd
, addr
);
403 wpa_printf(MSG_DEBUG
, "AUTH_GET_MSK: Cannot find STA");
407 key
= ieee802_1x_get_key(sta
->eapol_sm
, &keylen
);
409 wpa_printf(MSG_DEBUG
, "AUTH_GET_MSK: Key is null, eapol_sm: %p",
416 os_memcpy(msk
, key
, keylen
);
423 static int hostapd_wpa_auth_set_key(void *ctx
, int vlan_id
, enum wpa_alg alg
,
424 const u8
*addr
, int idx
, u8
*key
,
425 size_t key_len
, enum key_flag key_flag
)
427 struct hostapd_data
*hapd
= ctx
;
428 const char *ifname
= hapd
->conf
->iface
;
431 ifname
= hostapd_get_vlan_id_ifname(hapd
->conf
->vlan
, vlan_id
);
433 if (!(hapd
->iface
->drv_flags
&
434 WPA_DRIVER_FLAGS_VLAN_OFFLOAD
))
436 ifname
= hapd
->conf
->iface
;
440 #ifdef CONFIG_TESTING_OPTIONS
441 if (key_flag
& KEY_FLAG_MODIFY
) {
442 /* We are updating an already installed key. Don't overwrite
443 * the already stored key information with zeros.
445 } else if (addr
&& !is_broadcast_ether_addr(addr
)) {
446 struct sta_info
*sta
;
448 sta
= ap_get_sta(hapd
, addr
);
450 sta
->last_tk_alg
= alg
;
451 sta
->last_tk_key_idx
= idx
;
453 os_memcpy(sta
->last_tk
, key
, key_len
);
454 sta
->last_tk_len
= key_len
;
456 } else if (alg
== WPA_ALG_IGTK
||
457 alg
== WPA_ALG_BIP_GMAC_128
||
458 alg
== WPA_ALG_BIP_GMAC_256
||
459 alg
== WPA_ALG_BIP_CMAC_256
) {
460 hapd
->last_igtk_alg
= alg
;
461 hapd
->last_igtk_key_idx
= idx
;
463 os_memcpy(hapd
->last_igtk
, key
, key_len
);
464 hapd
->last_igtk_len
= key_len
;
466 hapd
->last_gtk_alg
= alg
;
467 hapd
->last_gtk_key_idx
= idx
;
469 os_memcpy(hapd
->last_gtk
, key
, key_len
);
470 hapd
->last_gtk_len
= key_len
;
472 #endif /* CONFIG_TESTING_OPTIONS */
473 return hostapd_drv_set_key(ifname
, hapd
, alg
, addr
, idx
, vlan_id
, 1,
474 NULL
, 0, key
, key_len
, key_flag
);
478 static int hostapd_wpa_auth_get_seqnum(void *ctx
, const u8
*addr
, int idx
,
481 struct hostapd_data
*hapd
= ctx
;
482 return hostapd_get_seqnum(hapd
->conf
->iface
, hapd
, addr
, idx
, seq
);
486 static int hostapd_wpa_auth_send_eapol(void *ctx
, const u8
*addr
,
487 const u8
*data
, size_t data_len
,
490 struct hostapd_data
*hapd
= ctx
;
491 struct sta_info
*sta
;
494 #ifdef CONFIG_TESTING_OPTIONS
495 if (hapd
->ext_eapol_frame_io
) {
496 size_t hex_len
= 2 * data_len
+ 1;
497 char *hex
= os_malloc(hex_len
);
501 wpa_snprintf_hex(hex
, hex_len
, data
, data_len
);
502 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, "EAPOL-TX " MACSTR
" %s",
507 #endif /* CONFIG_TESTING_OPTIONS */
509 sta
= ap_get_sta(hapd
, addr
);
511 flags
= hostapd_sta_flags_to_drv(sta
->flags
);
513 return hostapd_drv_hapd_send_eapol(hapd
, addr
, data
, data_len
,
518 static int hostapd_wpa_auth_for_each_sta(
519 void *ctx
, int (*cb
)(struct wpa_state_machine
*sm
, void *ctx
),
522 struct hostapd_data
*hapd
= ctx
;
523 struct sta_info
*sta
;
525 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
526 if (sta
->wpa_sm
&& cb(sta
->wpa_sm
, cb_ctx
))
533 struct wpa_auth_iface_iter_data
{
534 int (*cb
)(struct wpa_authenticator
*sm
, void *ctx
);
538 static int wpa_auth_iface_iter(struct hostapd_iface
*iface
, void *ctx
)
540 struct wpa_auth_iface_iter_data
*data
= ctx
;
542 for (i
= 0; i
< iface
->num_bss
; i
++) {
543 if (iface
->bss
[i
]->wpa_auth
&&
544 data
->cb(iface
->bss
[i
]->wpa_auth
, data
->cb_ctx
))
551 static int hostapd_wpa_auth_for_each_auth(
552 void *ctx
, int (*cb
)(struct wpa_authenticator
*sm
, void *ctx
),
555 struct hostapd_data
*hapd
= ctx
;
556 struct wpa_auth_iface_iter_data data
;
557 if (hapd
->iface
->interfaces
== NULL
||
558 hapd
->iface
->interfaces
->for_each_interface
== NULL
)
561 data
.cb_ctx
= cb_ctx
;
562 return hapd
->iface
->interfaces
->for_each_interface(
563 hapd
->iface
->interfaces
, wpa_auth_iface_iter
, &data
);
567 #ifdef CONFIG_IEEE80211R_AP
569 struct wpa_ft_rrb_rx_later_data
{
573 /* followed by data_len octets of data */
576 static void hostapd_wpa_ft_rrb_rx_later(void *eloop_ctx
, void *timeout_ctx
)
578 struct hostapd_data
*hapd
= eloop_ctx
;
579 struct wpa_ft_rrb_rx_later_data
*data
, *n
;
581 dl_list_for_each_safe(data
, n
, &hapd
->l2_queue
,
582 struct wpa_ft_rrb_rx_later_data
, list
) {
583 if (hapd
->wpa_auth
) {
584 wpa_ft_rrb_rx(hapd
->wpa_auth
, data
->addr
,
585 (const u8
*) (data
+ 1),
588 dl_list_del(&data
->list
);
594 struct wpa_auth_ft_iface_iter_data
{
595 struct hostapd_data
*src_hapd
;
602 static int hostapd_wpa_auth_ft_iter(struct hostapd_iface
*iface
, void *ctx
)
604 struct wpa_auth_ft_iface_iter_data
*idata
= ctx
;
605 struct wpa_ft_rrb_rx_later_data
*data
;
606 struct hostapd_data
*hapd
;
609 for (j
= 0; j
< iface
->num_bss
; j
++) {
610 hapd
= iface
->bss
[j
];
611 if (hapd
== idata
->src_hapd
||
613 os_memcmp(hapd
->own_addr
, idata
->dst
, ETH_ALEN
) != 0)
616 wpa_printf(MSG_DEBUG
,
617 "FT: Send RRB data directly to locally managed BSS "
618 MACSTR
"@%s -> " MACSTR
"@%s",
619 MAC2STR(idata
->src_hapd
->own_addr
),
620 idata
->src_hapd
->conf
->iface
,
621 MAC2STR(hapd
->own_addr
), hapd
->conf
->iface
);
623 /* Defer wpa_ft_rrb_rx() until next eloop step as this is
624 * when it would be triggered when reading from a socket.
626 * hapd0:send -> hapd1:recv -> hapd1:send -> hapd0:recv,
627 * that is calling hapd0:recv handler from within
628 * hapd0:send directly.
630 data
= os_zalloc(sizeof(*data
) + idata
->data_len
);
634 os_memcpy(data
->addr
, idata
->src_hapd
->own_addr
, ETH_ALEN
);
635 os_memcpy(data
+ 1, idata
->data
, idata
->data_len
);
636 data
->data_len
= idata
->data_len
;
638 dl_list_add(&hapd
->l2_queue
, &data
->list
);
640 if (!eloop_is_timeout_registered(hostapd_wpa_ft_rrb_rx_later
,
642 eloop_register_timeout(0, 0,
643 hostapd_wpa_ft_rrb_rx_later
,
652 #endif /* CONFIG_IEEE80211R_AP */
655 static int hostapd_wpa_auth_send_ether(void *ctx
, const u8
*dst
, u16 proto
,
656 const u8
*data
, size_t data_len
)
658 struct hostapd_data
*hapd
= ctx
;
659 struct l2_ethhdr
*buf
;
662 #ifdef CONFIG_TESTING_OPTIONS
663 if (hapd
->ext_eapol_frame_io
&& proto
== ETH_P_EAPOL
) {
664 size_t hex_len
= 2 * data_len
+ 1;
665 char *hex
= os_malloc(hex_len
);
669 wpa_snprintf_hex(hex
, hex_len
, data
, data_len
);
670 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, "EAPOL-TX " MACSTR
" %s",
675 #endif /* CONFIG_TESTING_OPTIONS */
677 #ifdef CONFIG_IEEE80211R_AP
678 if (proto
== ETH_P_RRB
&& hapd
->iface
->interfaces
&&
679 hapd
->iface
->interfaces
->for_each_interface
) {
681 struct wpa_auth_ft_iface_iter_data idata
;
682 idata
.src_hapd
= hapd
;
685 idata
.data_len
= data_len
;
686 res
= hapd
->iface
->interfaces
->for_each_interface(
687 hapd
->iface
->interfaces
, hostapd_wpa_auth_ft_iter
,
692 #endif /* CONFIG_IEEE80211R_AP */
694 if (hapd
->l2
== NULL
)
697 buf
= os_malloc(sizeof(*buf
) + data_len
);
700 os_memcpy(buf
->h_dest
, dst
, ETH_ALEN
);
701 os_memcpy(buf
->h_source
, hapd
->own_addr
, ETH_ALEN
);
702 buf
->h_proto
= host_to_be16(proto
);
703 os_memcpy(buf
+ 1, data
, data_len
);
704 ret
= l2_packet_send(hapd
->l2
, dst
, proto
, (u8
*) buf
,
705 sizeof(*buf
) + data_len
);
711 #ifdef CONFIG_ETH_P_OUI
712 static struct eth_p_oui_ctx
* hostapd_wpa_get_oui(struct hostapd_data
*hapd
,
715 switch (oui_suffix
) {
716 #ifdef CONFIG_IEEE80211R_AP
717 case FT_PACKET_R0KH_R1KH_PULL
:
718 return hapd
->oui_pull
;
719 case FT_PACKET_R0KH_R1KH_RESP
:
720 return hapd
->oui_resp
;
721 case FT_PACKET_R0KH_R1KH_PUSH
:
722 return hapd
->oui_push
;
723 case FT_PACKET_R0KH_R1KH_SEQ_REQ
:
724 return hapd
->oui_sreq
;
725 case FT_PACKET_R0KH_R1KH_SEQ_RESP
:
726 return hapd
->oui_sresp
;
727 #endif /* CONFIG_IEEE80211R_AP */
732 #endif /* CONFIG_ETH_P_OUI */
735 #ifdef CONFIG_IEEE80211R_AP
737 struct oui_deliver_later_data
{
739 u8 src_addr
[ETH_ALEN
];
740 u8 dst_addr
[ETH_ALEN
];
743 /* followed by data_len octets of data */
746 static void hostapd_oui_deliver_later(void *eloop_ctx
, void *timeout_ctx
)
748 struct hostapd_data
*hapd
= eloop_ctx
;
749 struct oui_deliver_later_data
*data
, *n
;
750 struct eth_p_oui_ctx
*oui_ctx
;
752 dl_list_for_each_safe(data
, n
, &hapd
->l2_oui_queue
,
753 struct oui_deliver_later_data
, list
) {
754 oui_ctx
= hostapd_wpa_get_oui(hapd
, data
->oui_suffix
);
755 wpa_printf(MSG_DEBUG
, "RRB(%s): %s src=" MACSTR
" dst=" MACSTR
756 " oui_suffix=%u data_len=%u data=%p",
757 hapd
->conf
->iface
, __func__
,
758 MAC2STR(data
->src_addr
), MAC2STR(data
->dst_addr
),
759 data
->oui_suffix
, (unsigned int) data
->data_len
,
761 if (hapd
->wpa_auth
&& oui_ctx
) {
762 eth_p_oui_deliver(oui_ctx
, data
->src_addr
,
764 (const u8
*) (data
+ 1),
767 dl_list_del(&data
->list
);
773 struct wpa_auth_oui_iface_iter_data
{
774 struct hostapd_data
*src_hapd
;
781 static int hostapd_wpa_auth_oui_iter(struct hostapd_iface
*iface
, void *ctx
)
783 struct wpa_auth_oui_iface_iter_data
*idata
= ctx
;
784 struct oui_deliver_later_data
*data
;
785 struct hostapd_data
*hapd
, *src_hapd
= idata
->src_hapd
;
788 for (j
= 0; j
< iface
->num_bss
; j
++) {
789 hapd
= iface
->bss
[j
];
790 if (hapd
== src_hapd
)
791 continue; /* don't deliver back to same interface */
792 if (!wpa_key_mgmt_ft(hapd
->conf
->wpa_key_mgmt
) ||
793 hapd
->conf
->ssid
.ssid_len
!=
794 src_hapd
->conf
->ssid
.ssid_len
||
795 os_memcmp(hapd
->conf
->ssid
.ssid
,
796 src_hapd
->conf
->ssid
.ssid
,
797 hapd
->conf
->ssid
.ssid_len
) != 0 ||
798 os_memcmp(hapd
->conf
->mobility_domain
,
799 src_hapd
->conf
->mobility_domain
,
800 MOBILITY_DOMAIN_ID_LEN
) != 0)
801 continue; /* no matching FT SSID/mobility domain */
802 if (!is_multicast_ether_addr(idata
->dst_addr
) &&
803 os_memcmp(hapd
->own_addr
, idata
->dst_addr
, ETH_ALEN
) != 0)
804 continue; /* destination address does not match */
806 /* defer eth_p_oui_deliver until next eloop step as this is
807 * when it would be triggerd from reading from sock
809 * hapd0:send -> hapd1:recv -> hapd1:send -> hapd0:recv,
810 * that is calling hapd0:recv handler from within
811 * hapd0:send directly.
813 data
= os_zalloc(sizeof(*data
) + idata
->data_len
);
816 wpa_printf(MSG_DEBUG
,
817 "RRB(%s): local delivery to %s dst=" MACSTR
818 " oui_suffix=%u data_len=%u data=%p",
819 src_hapd
->conf
->iface
, hapd
->conf
->iface
,
820 MAC2STR(idata
->dst_addr
), idata
->oui_suffix
,
821 (unsigned int) idata
->data_len
, data
);
823 os_memcpy(data
->src_addr
, src_hapd
->own_addr
, ETH_ALEN
);
824 os_memcpy(data
->dst_addr
, idata
->dst_addr
, ETH_ALEN
);
825 os_memcpy(data
+ 1, idata
->data
, idata
->data_len
);
826 data
->data_len
= idata
->data_len
;
827 data
->oui_suffix
= idata
->oui_suffix
;
829 dl_list_add_tail(&hapd
->l2_oui_queue
, &data
->list
);
831 if (!eloop_is_timeout_registered(hostapd_oui_deliver_later
,
833 eloop_register_timeout(0, 0,
834 hostapd_oui_deliver_later
,
837 /* If dst_addr is a multicast address, do not return any
838 * non-zero value here. Otherwise, the iteration of
839 * for_each_interface() will be stopped. */
840 if (!is_multicast_ether_addr(idata
->dst_addr
))
847 #endif /* CONFIG_IEEE80211R_AP */
850 static int hostapd_wpa_auth_send_oui(void *ctx
, const u8
*dst
, u8 oui_suffix
,
851 const u8
*data
, size_t data_len
)
853 #ifdef CONFIG_ETH_P_OUI
854 struct hostapd_data
*hapd
= ctx
;
855 struct eth_p_oui_ctx
*oui_ctx
;
857 wpa_printf(MSG_DEBUG
, "RRB(%s): send to dst=" MACSTR
858 " oui_suffix=%u data_len=%u",
859 hapd
->conf
->iface
, MAC2STR(dst
), oui_suffix
,
860 (unsigned int) data_len
);
861 #ifdef CONFIG_IEEE80211R_AP
862 if (hapd
->iface
->interfaces
&&
863 hapd
->iface
->interfaces
->for_each_interface
) {
864 struct wpa_auth_oui_iface_iter_data idata
;
867 idata
.src_hapd
= hapd
;
868 idata
.dst_addr
= dst
;
870 idata
.data_len
= data_len
;
871 idata
.oui_suffix
= oui_suffix
;
872 res
= hapd
->iface
->interfaces
->for_each_interface(
873 hapd
->iface
->interfaces
, hostapd_wpa_auth_oui_iter
,
878 #endif /* CONFIG_IEEE80211R_AP */
880 oui_ctx
= hostapd_wpa_get_oui(hapd
, oui_suffix
);
884 return eth_p_oui_send(oui_ctx
, hapd
->own_addr
, dst
, data
, data_len
);
885 #else /* CONFIG_ETH_P_OUI */
887 #endif /* CONFIG_ETH_P_OUI */
891 static int hostapd_channel_info(void *ctx
, struct wpa_channel_info
*ci
)
893 struct hostapd_data
*hapd
= ctx
;
895 return hostapd_drv_channel_info(hapd
, ci
);
899 static int hostapd_wpa_auth_update_vlan(void *ctx
, const u8
*addr
, int vlan_id
)
901 #ifndef CONFIG_NO_VLAN
902 struct hostapd_data
*hapd
= ctx
;
903 struct sta_info
*sta
;
905 sta
= ap_get_sta(hapd
, addr
);
909 if (!(hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_VLAN_OFFLOAD
)) {
910 struct vlan_description vlan_desc
;
912 os_memset(&vlan_desc
, 0, sizeof(vlan_desc
));
913 vlan_desc
.notempty
= 1;
914 vlan_desc
.untagged
= vlan_id
;
915 if (!hostapd_vlan_valid(hapd
->conf
->vlan
, &vlan_desc
)) {
917 "Invalid VLAN ID %d in wpa_psk_file",
922 if (ap_sta_set_vlan(hapd
, sta
, &vlan_desc
) < 0) {
924 "Failed to assign VLAN ID %d from wpa_psk_file to "
925 MACSTR
, vlan_id
, MAC2STR(sta
->addr
));
929 sta
->vlan_id
= vlan_id
;
933 "Assigned VLAN ID %d from wpa_psk_file to " MACSTR
,
934 vlan_id
, MAC2STR(sta
->addr
));
935 if ((sta
->flags
& WLAN_STA_ASSOC
) &&
936 ap_sta_bind_vlan(hapd
, sta
) < 0)
938 #endif /* CONFIG_NO_VLAN */
945 static int hostapd_get_sta_tx_params(void *ctx
, const u8
*addr
,
946 int ap_max_chanwidth
, int ap_seg1_idx
,
947 int *bandwidth
, int *seg1_idx
)
949 struct hostapd_data
*hapd
= ctx
;
950 struct sta_info
*sta
;
952 sta
= ap_get_sta(hapd
, addr
);
954 hostapd_wpa_auth_logger(hapd
, addr
, LOGGER_INFO
,
955 "Failed to get STA info to validate received OCI");
959 return get_tx_parameters(sta
, ap_max_chanwidth
, ap_seg1_idx
, bandwidth
,
962 #endif /* CONFIG_OCV */
965 #ifdef CONFIG_IEEE80211R_AP
967 static int hostapd_wpa_auth_send_ft_action(void *ctx
, const u8
*dst
,
968 const u8
*data
, size_t data_len
)
970 struct hostapd_data
*hapd
= ctx
;
972 struct ieee80211_mgmt
*m
;
974 struct sta_info
*sta
;
976 sta
= ap_get_sta(hapd
, dst
);
977 if (sta
== NULL
|| sta
->wpa_sm
== NULL
)
980 m
= os_zalloc(sizeof(*m
) + data_len
);
983 mlen
= ((u8
*) &m
->u
- (u8
*) m
) + data_len
;
984 m
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
985 WLAN_FC_STYPE_ACTION
);
986 os_memcpy(m
->da
, dst
, ETH_ALEN
);
987 os_memcpy(m
->sa
, hapd
->own_addr
, ETH_ALEN
);
988 os_memcpy(m
->bssid
, hapd
->own_addr
, ETH_ALEN
);
989 os_memcpy(&m
->u
, data
, data_len
);
991 res
= hostapd_drv_send_mlme(hapd
, (u8
*) m
, mlen
, 0, NULL
, 0, 0);
997 static struct wpa_state_machine
*
998 hostapd_wpa_auth_add_sta(void *ctx
, const u8
*sta_addr
)
1000 struct hostapd_data
*hapd
= ctx
;
1001 struct sta_info
*sta
;
1004 wpa_printf(MSG_DEBUG
, "Add station entry for " MACSTR
1005 " based on WPA authenticator callback",
1007 ret
= hostapd_add_sta_node(hapd
, sta_addr
, WLAN_AUTH_FT
);
1010 * The expected return values from hostapd_add_sta_node() are
1011 * 0: successfully added STA entry
1012 * -EOPNOTSUPP: driver or driver wrapper does not support/need this
1014 * any other negative value: error in adding the STA entry */
1015 if (ret
< 0 && ret
!= -EOPNOTSUPP
)
1018 sta
= ap_sta_add(hapd
, sta_addr
);
1022 sta
->added_unassoc
= 1;
1024 sta
->ft_over_ds
= 1;
1026 sta
->auth_alg
= WLAN_AUTH_FT
;
1030 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
, sta
->addr
, NULL
);
1031 if (sta
->wpa_sm
== NULL
) {
1032 ap_free_sta(hapd
, sta
);
1035 sta
->auth_alg
= WLAN_AUTH_FT
;
1041 static int hostapd_wpa_auth_add_sta_ft(void *ctx
, const u8
*sta_addr
)
1043 struct hostapd_data
*hapd
= ctx
;
1044 struct sta_info
*sta
;
1046 sta
= ap_get_sta(hapd
, sta_addr
);
1050 if (FULL_AP_CLIENT_STATE_SUPP(hapd
->iface
->drv_flags
) &&
1051 (sta
->flags
& WLAN_STA_MFP
) && ap_sta_is_authorized(sta
) &&
1052 !(hapd
->conf
->mesh
& MESH_ENABLED
) && !(sta
->added_unassoc
)) {
1053 /* We could not do this in handle_auth() since there was a
1054 * PMF-enabled association for the STA and the new
1055 * authentication attempt was not yet fully processed. Now that
1056 * we are ready to configure the TK to the driver,
1057 * authentication has succeeded and we can clean up the driver
1058 * STA entry to avoid issues with any maintained state from the
1059 * previous association. */
1060 wpa_printf(MSG_DEBUG
,
1061 "FT: Remove and re-add driver STA entry after successful FT authentication");
1062 return ap_sta_re_add(hapd
, sta
);
1069 static int hostapd_wpa_auth_set_vlan(void *ctx
, const u8
*sta_addr
,
1070 struct vlan_description
*vlan
)
1072 struct hostapd_data
*hapd
= ctx
;
1073 struct sta_info
*sta
;
1075 sta
= ap_get_sta(hapd
, sta_addr
);
1076 if (!sta
|| !sta
->wpa_sm
)
1079 if (vlan
->notempty
&&
1080 !hostapd_vlan_valid(hapd
->conf
->vlan
, vlan
)) {
1081 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1083 "Invalid VLAN %d%s received from FT",
1084 vlan
->untagged
, vlan
->tagged
[0] ? "+" : "");
1088 if (ap_sta_set_vlan(hapd
, sta
, vlan
) < 0)
1090 /* Configure wpa_group for GTK but ignore error due to driver not
1091 * knowing this STA. */
1092 ap_sta_bind_vlan(hapd
, sta
);
1095 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
1096 HOSTAPD_LEVEL_INFO
, "VLAN ID %d", sta
->vlan_id
);
1102 static int hostapd_wpa_auth_get_vlan(void *ctx
, const u8
*sta_addr
,
1103 struct vlan_description
*vlan
)
1105 struct hostapd_data
*hapd
= ctx
;
1106 struct sta_info
*sta
;
1108 sta
= ap_get_sta(hapd
, sta_addr
);
1113 *vlan
= *sta
->vlan_desc
;
1115 os_memset(vlan
, 0, sizeof(*vlan
));
1122 hostapd_wpa_auth_set_identity(void *ctx
, const u8
*sta_addr
,
1123 const u8
*identity
, size_t identity_len
)
1125 struct hostapd_data
*hapd
= ctx
;
1126 struct sta_info
*sta
;
1128 sta
= ap_get_sta(hapd
, sta_addr
);
1132 os_free(sta
->identity
);
1133 sta
->identity
= NULL
;
1135 if (sta
->eapol_sm
) {
1136 os_free(sta
->eapol_sm
->identity
);
1137 sta
->eapol_sm
->identity
= NULL
;
1138 sta
->eapol_sm
->identity_len
= 0;
1144 /* sta->identity is NULL terminated */
1145 sta
->identity
= os_zalloc(identity_len
+ 1);
1148 os_memcpy(sta
->identity
, identity
, identity_len
);
1150 if (sta
->eapol_sm
) {
1151 sta
->eapol_sm
->identity
= os_zalloc(identity_len
);
1152 if (!sta
->eapol_sm
->identity
)
1154 os_memcpy(sta
->eapol_sm
->identity
, identity
, identity_len
);
1155 sta
->eapol_sm
->identity_len
= identity_len
;
1163 hostapd_wpa_auth_get_identity(void *ctx
, const u8
*sta_addr
, const u8
**buf
)
1165 struct hostapd_data
*hapd
= ctx
;
1166 struct sta_info
*sta
;
1170 sta
= ap_get_sta(hapd
, sta_addr
);
1174 *buf
= ieee802_1x_get_identity(sta
->eapol_sm
, &len
);
1178 if (!sta
->identity
) {
1183 identity
= sta
->identity
;
1184 len
= os_strlen(identity
);
1185 *buf
= (u8
*) identity
;
1192 hostapd_wpa_auth_set_radius_cui(void *ctx
, const u8
*sta_addr
,
1193 const u8
*radius_cui
, size_t radius_cui_len
)
1195 struct hostapd_data
*hapd
= ctx
;
1196 struct sta_info
*sta
;
1198 sta
= ap_get_sta(hapd
, sta_addr
);
1202 os_free(sta
->radius_cui
);
1203 sta
->radius_cui
= NULL
;
1205 if (sta
->eapol_sm
) {
1206 wpabuf_free(sta
->eapol_sm
->radius_cui
);
1207 sta
->eapol_sm
->radius_cui
= NULL
;
1213 /* sta->radius_cui is NULL terminated */
1214 sta
->radius_cui
= os_zalloc(radius_cui_len
+ 1);
1215 if (!sta
->radius_cui
)
1217 os_memcpy(sta
->radius_cui
, radius_cui
, radius_cui_len
);
1219 if (sta
->eapol_sm
) {
1220 sta
->eapol_sm
->radius_cui
= wpabuf_alloc_copy(radius_cui
,
1222 if (!sta
->eapol_sm
->radius_cui
)
1231 hostapd_wpa_auth_get_radius_cui(void *ctx
, const u8
*sta_addr
, const u8
**buf
)
1233 struct hostapd_data
*hapd
= ctx
;
1234 struct sta_info
*sta
;
1239 sta
= ap_get_sta(hapd
, sta_addr
);
1243 b
= ieee802_1x_get_radius_cui(sta
->eapol_sm
);
1245 len
= wpabuf_len(b
);
1246 *buf
= wpabuf_head(b
);
1250 if (!sta
->radius_cui
) {
1255 radius_cui
= sta
->radius_cui
;
1256 len
= os_strlen(radius_cui
);
1257 *buf
= (u8
*) radius_cui
;
1263 static void hostapd_wpa_auth_set_session_timeout(void *ctx
, const u8
*sta_addr
,
1264 int session_timeout
)
1266 struct hostapd_data
*hapd
= ctx
;
1267 struct sta_info
*sta
;
1269 sta
= ap_get_sta(hapd
, sta_addr
);
1273 if (session_timeout
) {
1274 os_get_reltime(&sta
->session_timeout
);
1275 sta
->session_timeout
.sec
+= session_timeout
;
1276 sta
->session_timeout_set
= 1;
1277 ap_sta_session_timeout(hapd
, sta
, session_timeout
);
1279 sta
->session_timeout_set
= 0;
1280 ap_sta_no_session_timeout(hapd
, sta
);
1285 static int hostapd_wpa_auth_get_session_timeout(void *ctx
, const u8
*sta_addr
)
1287 struct hostapd_data
*hapd
= ctx
;
1288 struct sta_info
*sta
;
1289 struct os_reltime now
, remaining
;
1291 sta
= ap_get_sta(hapd
, sta_addr
);
1292 if (!sta
|| !sta
->session_timeout_set
)
1295 os_get_reltime(&now
);
1296 if (os_reltime_before(&sta
->session_timeout
, &now
)) {
1297 /* already expired, return >0 as timeout was set */
1301 os_reltime_sub(&sta
->session_timeout
, &now
, &remaining
);
1303 return (remaining
.sec
> 0) ? remaining
.sec
: 1;
1307 static void hostapd_rrb_receive(void *ctx
, const u8
*src_addr
, const u8
*buf
,
1310 struct hostapd_data
*hapd
= ctx
;
1311 struct l2_ethhdr
*ethhdr
;
1312 if (len
< sizeof(*ethhdr
))
1314 ethhdr
= (struct l2_ethhdr
*) buf
;
1315 wpa_printf(MSG_DEBUG
, "FT: RRB received packet " MACSTR
" -> "
1316 MACSTR
, MAC2STR(ethhdr
->h_source
), MAC2STR(ethhdr
->h_dest
));
1317 if (!is_multicast_ether_addr(ethhdr
->h_dest
) &&
1318 os_memcmp(hapd
->own_addr
, ethhdr
->h_dest
, ETH_ALEN
) != 0)
1320 wpa_ft_rrb_rx(hapd
->wpa_auth
, ethhdr
->h_source
, buf
+ sizeof(*ethhdr
),
1321 len
- sizeof(*ethhdr
));
1325 static void hostapd_rrb_oui_receive(void *ctx
, const u8
*src_addr
,
1326 const u8
*dst_addr
, u8 oui_suffix
,
1327 const u8
*buf
, size_t len
)
1329 struct hostapd_data
*hapd
= ctx
;
1331 wpa_printf(MSG_DEBUG
, "FT: RRB received packet " MACSTR
" -> "
1332 MACSTR
, MAC2STR(src_addr
), MAC2STR(dst_addr
));
1333 if (!is_multicast_ether_addr(dst_addr
) &&
1334 os_memcmp(hapd
->own_addr
, dst_addr
, ETH_ALEN
) != 0)
1336 wpa_ft_rrb_oui_rx(hapd
->wpa_auth
, src_addr
, dst_addr
, oui_suffix
, buf
,
1341 static int hostapd_wpa_auth_add_tspec(void *ctx
, const u8
*sta_addr
,
1342 u8
*tspec_ie
, size_t tspec_ielen
)
1344 struct hostapd_data
*hapd
= ctx
;
1345 return hostapd_add_tspec(hapd
, sta_addr
, tspec_ie
, tspec_ielen
);
1350 static int hostapd_wpa_register_ft_oui(struct hostapd_data
*hapd
,
1351 const char *ft_iface
)
1353 hapd
->oui_pull
= eth_p_oui_register(hapd
, ft_iface
,
1354 FT_PACKET_R0KH_R1KH_PULL
,
1355 hostapd_rrb_oui_receive
, hapd
);
1356 if (!hapd
->oui_pull
)
1359 hapd
->oui_resp
= eth_p_oui_register(hapd
, ft_iface
,
1360 FT_PACKET_R0KH_R1KH_RESP
,
1361 hostapd_rrb_oui_receive
, hapd
);
1362 if (!hapd
->oui_resp
)
1365 hapd
->oui_push
= eth_p_oui_register(hapd
, ft_iface
,
1366 FT_PACKET_R0KH_R1KH_PUSH
,
1367 hostapd_rrb_oui_receive
, hapd
);
1368 if (!hapd
->oui_push
)
1371 hapd
->oui_sreq
= eth_p_oui_register(hapd
, ft_iface
,
1372 FT_PACKET_R0KH_R1KH_SEQ_REQ
,
1373 hostapd_rrb_oui_receive
, hapd
);
1374 if (!hapd
->oui_sreq
)
1377 hapd
->oui_sresp
= eth_p_oui_register(hapd
, ft_iface
,
1378 FT_PACKET_R0KH_R1KH_SEQ_RESP
,
1379 hostapd_rrb_oui_receive
, hapd
);
1380 if (!hapd
->oui_sresp
)
1387 static void hostapd_wpa_unregister_ft_oui(struct hostapd_data
*hapd
)
1389 eth_p_oui_unregister(hapd
->oui_pull
);
1390 hapd
->oui_pull
= NULL
;
1391 eth_p_oui_unregister(hapd
->oui_resp
);
1392 hapd
->oui_resp
= NULL
;
1393 eth_p_oui_unregister(hapd
->oui_push
);
1394 hapd
->oui_push
= NULL
;
1395 eth_p_oui_unregister(hapd
->oui_sreq
);
1396 hapd
->oui_sreq
= NULL
;
1397 eth_p_oui_unregister(hapd
->oui_sresp
);
1398 hapd
->oui_sresp
= NULL
;
1400 #endif /* CONFIG_IEEE80211R_AP */
1403 int hostapd_setup_wpa(struct hostapd_data
*hapd
)
1405 struct wpa_auth_config _conf
;
1406 static const struct wpa_auth_callbacks cb
= {
1407 .logger
= hostapd_wpa_auth_logger
,
1408 .disconnect
= hostapd_wpa_auth_disconnect
,
1409 .mic_failure_report
= hostapd_wpa_auth_mic_failure_report
,
1410 .psk_failure_report
= hostapd_wpa_auth_psk_failure_report
,
1411 .set_eapol
= hostapd_wpa_auth_set_eapol
,
1412 .get_eapol
= hostapd_wpa_auth_get_eapol
,
1413 .get_psk
= hostapd_wpa_auth_get_psk
,
1414 .get_msk
= hostapd_wpa_auth_get_msk
,
1415 .set_key
= hostapd_wpa_auth_set_key
,
1416 .get_seqnum
= hostapd_wpa_auth_get_seqnum
,
1417 .send_eapol
= hostapd_wpa_auth_send_eapol
,
1418 .for_each_sta
= hostapd_wpa_auth_for_each_sta
,
1419 .for_each_auth
= hostapd_wpa_auth_for_each_auth
,
1420 .send_ether
= hostapd_wpa_auth_send_ether
,
1421 .send_oui
= hostapd_wpa_auth_send_oui
,
1422 .channel_info
= hostapd_channel_info
,
1423 .update_vlan
= hostapd_wpa_auth_update_vlan
,
1425 .get_sta_tx_params
= hostapd_get_sta_tx_params
,
1426 #endif /* CONFIG_OCV */
1427 #ifdef CONFIG_IEEE80211R_AP
1428 .send_ft_action
= hostapd_wpa_auth_send_ft_action
,
1429 .add_sta
= hostapd_wpa_auth_add_sta
,
1430 .add_sta_ft
= hostapd_wpa_auth_add_sta_ft
,
1431 .add_tspec
= hostapd_wpa_auth_add_tspec
,
1432 .set_vlan
= hostapd_wpa_auth_set_vlan
,
1433 .get_vlan
= hostapd_wpa_auth_get_vlan
,
1434 .set_identity
= hostapd_wpa_auth_set_identity
,
1435 .get_identity
= hostapd_wpa_auth_get_identity
,
1436 .set_radius_cui
= hostapd_wpa_auth_set_radius_cui
,
1437 .get_radius_cui
= hostapd_wpa_auth_get_radius_cui
,
1438 .set_session_timeout
= hostapd_wpa_auth_set_session_timeout
,
1439 .get_session_timeout
= hostapd_wpa_auth_get_session_timeout
,
1440 #endif /* CONFIG_IEEE80211R_AP */
1445 hostapd_wpa_auth_conf(hapd
->conf
, hapd
->iconf
, &_conf
);
1446 if (hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
)
1447 _conf
.tx_status
= 1;
1448 if (hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_AP_MLME
)
1451 if (!(hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
) &&
1452 (hapd
->conf
->wpa_deny_ptk0_rekey
== PTK0_REKEY_ALLOW_NEVER
||
1453 (hapd
->conf
->wpa_deny_ptk0_rekey
== PTK0_REKEY_ALLOW_LOCAL_OK
&&
1454 !(hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_SAFE_PTK0_REKEYS
)))) {
1455 wpa_msg(hapd
->msg_ctx
, MSG_INFO
,
1456 "Disable PTK0 rekey support - replaced with disconnect");
1457 _conf
.wpa_deny_ptk0_rekey
= 1;
1460 if (_conf
.extended_key_id
&&
1461 (hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_EXTENDED_KEY_ID
))
1462 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "Extended Key ID supported");
1464 _conf
.extended_key_id
= 0;
1466 hapd
->wpa_auth
= wpa_init(hapd
->own_addr
, &_conf
, &cb
, hapd
);
1467 if (hapd
->wpa_auth
== NULL
) {
1468 wpa_printf(MSG_ERROR
, "WPA initialization failed.");
1472 if (hostapd_set_privacy(hapd
, 1)) {
1473 wpa_printf(MSG_ERROR
, "Could not set PrivacyInvoked "
1474 "for interface %s", hapd
->conf
->iface
);
1478 wpa_ie
= wpa_auth_get_wpa_ie(hapd
->wpa_auth
, &wpa_ie_len
);
1479 if (hostapd_set_generic_elem(hapd
, wpa_ie
, wpa_ie_len
)) {
1480 wpa_printf(MSG_ERROR
, "Failed to configure WPA IE for "
1481 "the kernel driver.");
1485 if (rsn_preauth_iface_init(hapd
)) {
1486 wpa_printf(MSG_ERROR
, "Initialization of RSN "
1487 "pre-authentication failed.");
1491 #ifdef CONFIG_IEEE80211R_AP
1492 if (!hostapd_drv_none(hapd
) &&
1493 wpa_key_mgmt_ft(hapd
->conf
->wpa_key_mgmt
)) {
1494 const char *ft_iface
;
1496 ft_iface
= hapd
->conf
->bridge
[0] ? hapd
->conf
->bridge
:
1498 hapd
->l2
= l2_packet_init(ft_iface
, NULL
, ETH_P_RRB
,
1499 hostapd_rrb_receive
, hapd
, 1);
1501 wpa_printf(MSG_ERROR
, "Failed to open l2_packet "
1506 if (hostapd_wpa_register_ft_oui(hapd
, ft_iface
)) {
1507 wpa_printf(MSG_ERROR
,
1508 "Failed to open ETH_P_OUI interface");
1512 #endif /* CONFIG_IEEE80211R_AP */
1519 void hostapd_reconfig_wpa(struct hostapd_data
*hapd
)
1521 struct wpa_auth_config wpa_auth_conf
;
1522 hostapd_wpa_auth_conf(hapd
->conf
, hapd
->iconf
, &wpa_auth_conf
);
1523 wpa_reconfig(hapd
->wpa_auth
, &wpa_auth_conf
);
1527 void hostapd_deinit_wpa(struct hostapd_data
*hapd
)
1529 ieee80211_tkip_countermeasures_deinit(hapd
);
1530 rsn_preauth_iface_deinit(hapd
);
1531 if (hapd
->wpa_auth
) {
1532 wpa_deinit(hapd
->wpa_auth
);
1533 hapd
->wpa_auth
= NULL
;
1535 if (hapd
->drv_priv
&& hostapd_set_privacy(hapd
, 0)) {
1536 wpa_printf(MSG_DEBUG
, "Could not disable "
1537 "PrivacyInvoked for interface %s",
1541 if (hapd
->drv_priv
&&
1542 hostapd_set_generic_elem(hapd
, (u8
*) "", 0)) {
1543 wpa_printf(MSG_DEBUG
, "Could not remove generic "
1544 "information element from interface %s",
1548 ieee802_1x_deinit(hapd
);
1550 #ifdef CONFIG_IEEE80211R_AP
1551 eloop_cancel_timeout(hostapd_wpa_ft_rrb_rx_later
, hapd
, ELOOP_ALL_CTX
);
1552 hostapd_wpa_ft_rrb_rx_later(hapd
, NULL
); /* flush without delivering */
1553 eloop_cancel_timeout(hostapd_oui_deliver_later
, hapd
, ELOOP_ALL_CTX
);
1554 hostapd_oui_deliver_later(hapd
, NULL
); /* flush without delivering */
1555 l2_packet_deinit(hapd
->l2
);
1557 hostapd_wpa_unregister_ft_oui(hapd
);
1558 #endif /* CONFIG_IEEE80211R_AP */