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"
31 #include "wpa_auth_glue.h"
34 static void hostapd_wpa_auth_conf(struct hostapd_bss_config
*conf
,
35 struct hostapd_config
*iconf
,
36 struct wpa_auth_config
*wconf
)
38 os_memset(wconf
, 0, sizeof(*wconf
));
39 wconf
->wpa
= conf
->wpa
;
40 wconf
->wpa_key_mgmt
= conf
->wpa_key_mgmt
;
41 wconf
->wpa_pairwise
= conf
->wpa_pairwise
;
42 wconf
->wpa_group
= conf
->wpa_group
;
43 wconf
->wpa_group_rekey
= conf
->wpa_group_rekey
;
44 wconf
->wpa_strict_rekey
= conf
->wpa_strict_rekey
;
45 wconf
->wpa_gmk_rekey
= conf
->wpa_gmk_rekey
;
46 wconf
->wpa_ptk_rekey
= conf
->wpa_ptk_rekey
;
47 wconf
->wpa_group_update_count
= conf
->wpa_group_update_count
;
48 wconf
->wpa_pairwise_update_count
= conf
->wpa_pairwise_update_count
;
49 wconf
->rsn_pairwise
= conf
->rsn_pairwise
;
50 wconf
->rsn_preauth
= conf
->rsn_preauth
;
51 wconf
->eapol_version
= conf
->eapol_version
;
52 wconf
->peerkey
= conf
->peerkey
;
53 wconf
->wmm_enabled
= conf
->wmm_enabled
;
54 wconf
->wmm_uapsd
= conf
->wmm_uapsd
;
55 wconf
->disable_pmksa_caching
= conf
->disable_pmksa_caching
;
56 wconf
->okc
= conf
->okc
;
57 #ifdef CONFIG_IEEE80211W
58 wconf
->ieee80211w
= conf
->ieee80211w
;
59 wconf
->group_mgmt_cipher
= conf
->group_mgmt_cipher
;
60 #endif /* CONFIG_IEEE80211W */
61 #ifdef CONFIG_IEEE80211R_AP
62 wconf
->ssid_len
= conf
->ssid
.ssid_len
;
63 if (wconf
->ssid_len
> SSID_MAX_LEN
)
64 wconf
->ssid_len
= SSID_MAX_LEN
;
65 os_memcpy(wconf
->ssid
, conf
->ssid
.ssid
, wconf
->ssid_len
);
66 os_memcpy(wconf
->mobility_domain
, conf
->mobility_domain
,
67 MOBILITY_DOMAIN_ID_LEN
);
68 if (conf
->nas_identifier
&&
69 os_strlen(conf
->nas_identifier
) <= FT_R0KH_ID_MAX_LEN
) {
70 wconf
->r0_key_holder_len
= os_strlen(conf
->nas_identifier
);
71 os_memcpy(wconf
->r0_key_holder
, conf
->nas_identifier
,
72 wconf
->r0_key_holder_len
);
74 os_memcpy(wconf
->r1_key_holder
, conf
->r1_key_holder
, FT_R1KH_ID_LEN
);
75 wconf
->r0_key_lifetime
= conf
->r0_key_lifetime
;
76 wconf
->reassociation_deadline
= conf
->reassociation_deadline
;
77 wconf
->r0kh_list
= conf
->r0kh_list
;
78 wconf
->r1kh_list
= conf
->r1kh_list
;
79 wconf
->pmk_r1_push
= conf
->pmk_r1_push
;
80 wconf
->ft_over_ds
= conf
->ft_over_ds
;
81 wconf
->ft_psk_generate_local
= conf
->ft_psk_generate_local
;
82 #endif /* CONFIG_IEEE80211R_AP */
84 wconf
->disable_gtk
= conf
->disable_dgaf
;
86 wconf
->disable_gtk
= 1;
87 wconf
->wpa
= WPA_PROTO_OSEN
;
88 wconf
->wpa_key_mgmt
= WPA_KEY_MGMT_OSEN
;
89 wconf
->wpa_pairwise
= 0;
90 wconf
->wpa_group
= WPA_CIPHER_CCMP
;
91 wconf
->rsn_pairwise
= WPA_CIPHER_CCMP
;
92 wconf
->rsn_preauth
= 0;
93 wconf
->disable_pmksa_caching
= 1;
94 #ifdef CONFIG_IEEE80211W
95 wconf
->ieee80211w
= 1;
96 #endif /* CONFIG_IEEE80211W */
98 #endif /* CONFIG_HS20 */
99 #ifdef CONFIG_TESTING_OPTIONS
100 wconf
->corrupt_gtk_rekey_mic_probability
=
101 iconf
->corrupt_gtk_rekey_mic_probability
;
102 if (conf
->own_ie_override
&&
103 wpabuf_len(conf
->own_ie_override
) <= MAX_OWN_IE_OVERRIDE
) {
104 wconf
->own_ie_override_len
= wpabuf_len(conf
->own_ie_override
);
105 os_memcpy(wconf
->own_ie_override
,
106 wpabuf_head(conf
->own_ie_override
),
107 wconf
->own_ie_override_len
);
109 #endif /* CONFIG_TESTING_OPTIONS */
111 os_memcpy(wconf
->ip_addr_go
, conf
->ip_addr_go
, 4);
112 os_memcpy(wconf
->ip_addr_mask
, conf
->ip_addr_mask
, 4);
113 os_memcpy(wconf
->ip_addr_start
, conf
->ip_addr_start
, 4);
114 os_memcpy(wconf
->ip_addr_end
, conf
->ip_addr_end
, 4);
115 #endif /* CONFIG_P2P */
117 wconf
->fils_cache_id_set
= conf
->fils_cache_id_set
;
118 os_memcpy(wconf
->fils_cache_id
, conf
->fils_cache_id
,
120 #endif /* CONFIG_FILS */
124 static void hostapd_wpa_auth_logger(void *ctx
, const u8
*addr
,
125 logger_level level
, const char *txt
)
127 #ifndef CONFIG_NO_HOSTAPD_LOGGER
128 struct hostapd_data
*hapd
= ctx
;
133 hlevel
= HOSTAPD_LEVEL_WARNING
;
136 hlevel
= HOSTAPD_LEVEL_INFO
;
140 hlevel
= HOSTAPD_LEVEL_DEBUG
;
144 hostapd_logger(hapd
, addr
, HOSTAPD_MODULE_WPA
, hlevel
, "%s", txt
);
145 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
149 static void hostapd_wpa_auth_disconnect(void *ctx
, const u8
*addr
,
152 struct hostapd_data
*hapd
= ctx
;
153 wpa_printf(MSG_DEBUG
, "%s: WPA authenticator requests disconnect: "
154 "STA " MACSTR
" reason %d",
155 __func__
, MAC2STR(addr
), reason
);
156 ap_sta_disconnect(hapd
, NULL
, addr
, reason
);
160 static int hostapd_wpa_auth_mic_failure_report(void *ctx
, const u8
*addr
)
162 struct hostapd_data
*hapd
= ctx
;
163 return michael_mic_failure(hapd
, addr
, 0);
167 static void hostapd_wpa_auth_psk_failure_report(void *ctx
, const u8
*addr
)
169 struct hostapd_data
*hapd
= ctx
;
170 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR
,
175 static void hostapd_wpa_auth_set_eapol(void *ctx
, const u8
*addr
,
176 wpa_eapol_variable var
, int value
)
178 struct hostapd_data
*hapd
= ctx
;
179 struct sta_info
*sta
= ap_get_sta(hapd
, addr
);
183 case WPA_EAPOL_portEnabled
:
184 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, value
);
186 case WPA_EAPOL_portValid
:
187 ieee802_1x_notify_port_valid(sta
->eapol_sm
, value
);
189 case WPA_EAPOL_authorized
:
190 ieee802_1x_set_sta_authorized(hapd
, sta
, value
);
192 case WPA_EAPOL_portControl_Auto
:
194 sta
->eapol_sm
->portControl
= Auto
;
196 case WPA_EAPOL_keyRun
:
198 sta
->eapol_sm
->keyRun
= value
? TRUE
: FALSE
;
200 case WPA_EAPOL_keyAvailable
:
202 sta
->eapol_sm
->eap_if
->eapKeyAvailable
=
203 value
? TRUE
: FALSE
;
205 case WPA_EAPOL_keyDone
:
207 sta
->eapol_sm
->keyDone
= value
? TRUE
: FALSE
;
209 case WPA_EAPOL_inc_EapolFramesTx
:
211 sta
->eapol_sm
->dot1xAuthEapolFramesTx
++;
217 static int hostapd_wpa_auth_get_eapol(void *ctx
, const u8
*addr
,
218 wpa_eapol_variable var
)
220 struct hostapd_data
*hapd
= ctx
;
221 struct sta_info
*sta
= ap_get_sta(hapd
, addr
);
222 if (sta
== NULL
|| sta
->eapol_sm
== NULL
)
225 case WPA_EAPOL_keyRun
:
226 return sta
->eapol_sm
->keyRun
;
227 case WPA_EAPOL_keyAvailable
:
228 return sta
->eapol_sm
->eap_if
->eapKeyAvailable
;
235 static const u8
* hostapd_wpa_auth_get_psk(void *ctx
, const u8
*addr
,
236 const u8
*p2p_dev_addr
,
239 struct hostapd_data
*hapd
= ctx
;
240 struct sta_info
*sta
= ap_get_sta(hapd
, addr
);
244 if (sta
&& sta
->auth_alg
== WLAN_AUTH_SAE
) {
245 if (!sta
->sae
|| prev_psk
)
247 return sta
->sae
->pmk
;
249 #endif /* CONFIG_SAE */
252 if ((hapd
->conf
->wpa_key_mgmt
& WPA_KEY_MGMT_OWE
) &&
255 #endif /* CONFIG_OWE */
257 psk
= hostapd_get_psk(hapd
->conf
, addr
, p2p_dev_addr
, prev_psk
);
259 * This is about to iterate over all psks, prev_psk gives the last
260 * returned psk which should not be returned again.
261 * logic list (all hostapd_get_psk; all sta->psk)
263 if (sta
&& sta
->psk
&& !psk
) {
264 struct hostapd_sta_wpa_psk_short
*pos
;
266 for (pos
= sta
->psk
; pos
; pos
= pos
->next
) {
267 if (pos
->is_passphrase
) {
268 pbkdf2_sha1(pos
->passphrase
,
269 hapd
->conf
->ssid
.ssid
,
270 hapd
->conf
->ssid
.ssid_len
, 4096,
272 pos
->is_passphrase
= 0;
274 if (pos
->psk
== prev_psk
) {
275 psk
= pos
->next
? pos
->next
->psk
: NULL
;
284 static int hostapd_wpa_auth_get_msk(void *ctx
, const u8
*addr
, u8
*msk
,
287 struct hostapd_data
*hapd
= ctx
;
290 struct sta_info
*sta
;
292 sta
= ap_get_sta(hapd
, addr
);
294 wpa_printf(MSG_DEBUG
, "AUTH_GET_MSK: Cannot find STA");
298 key
= ieee802_1x_get_key(sta
->eapol_sm
, &keylen
);
300 wpa_printf(MSG_DEBUG
, "AUTH_GET_MSK: Key is null, eapol_sm: %p",
307 os_memcpy(msk
, key
, keylen
);
314 static int hostapd_wpa_auth_set_key(void *ctx
, int vlan_id
, enum wpa_alg alg
,
315 const u8
*addr
, int idx
, u8
*key
,
318 struct hostapd_data
*hapd
= ctx
;
319 const char *ifname
= hapd
->conf
->iface
;
322 ifname
= hostapd_get_vlan_id_ifname(hapd
->conf
->vlan
, vlan_id
);
327 return hostapd_drv_set_key(ifname
, hapd
, alg
, addr
, idx
, 1, NULL
, 0,
332 static int hostapd_wpa_auth_get_seqnum(void *ctx
, const u8
*addr
, int idx
,
335 struct hostapd_data
*hapd
= ctx
;
336 return hostapd_get_seqnum(hapd
->conf
->iface
, hapd
, addr
, idx
, seq
);
340 static int hostapd_wpa_auth_send_eapol(void *ctx
, const u8
*addr
,
341 const u8
*data
, size_t data_len
,
344 struct hostapd_data
*hapd
= ctx
;
345 struct sta_info
*sta
;
348 #ifdef CONFIG_TESTING_OPTIONS
349 if (hapd
->ext_eapol_frame_io
) {
350 size_t hex_len
= 2 * data_len
+ 1;
351 char *hex
= os_malloc(hex_len
);
355 wpa_snprintf_hex(hex
, hex_len
, data
, data_len
);
356 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, "EAPOL-TX " MACSTR
" %s",
361 #endif /* CONFIG_TESTING_OPTIONS */
363 sta
= ap_get_sta(hapd
, addr
);
365 flags
= hostapd_sta_flags_to_drv(sta
->flags
);
367 return hostapd_drv_hapd_send_eapol(hapd
, addr
, data
, data_len
,
372 static int hostapd_wpa_auth_for_each_sta(
373 void *ctx
, int (*cb
)(struct wpa_state_machine
*sm
, void *ctx
),
376 struct hostapd_data
*hapd
= ctx
;
377 struct sta_info
*sta
;
379 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
380 if (sta
->wpa_sm
&& cb(sta
->wpa_sm
, cb_ctx
))
387 struct wpa_auth_iface_iter_data
{
388 int (*cb
)(struct wpa_authenticator
*sm
, void *ctx
);
392 static int wpa_auth_iface_iter(struct hostapd_iface
*iface
, void *ctx
)
394 struct wpa_auth_iface_iter_data
*data
= ctx
;
396 for (i
= 0; i
< iface
->num_bss
; i
++) {
397 if (iface
->bss
[i
]->wpa_auth
&&
398 data
->cb(iface
->bss
[i
]->wpa_auth
, data
->cb_ctx
))
405 static int hostapd_wpa_auth_for_each_auth(
406 void *ctx
, int (*cb
)(struct wpa_authenticator
*sm
, void *ctx
),
409 struct hostapd_data
*hapd
= ctx
;
410 struct wpa_auth_iface_iter_data data
;
411 if (hapd
->iface
->interfaces
== NULL
||
412 hapd
->iface
->interfaces
->for_each_interface
== NULL
)
415 data
.cb_ctx
= cb_ctx
;
416 return hapd
->iface
->interfaces
->for_each_interface(
417 hapd
->iface
->interfaces
, wpa_auth_iface_iter
, &data
);
421 #ifdef CONFIG_IEEE80211R_AP
423 struct wpa_ft_rrb_rx_later_data
{
427 /* followed by data_len octets of data */
430 static void hostapd_wpa_ft_rrb_rx_later(void *eloop_ctx
, void *timeout_ctx
)
432 struct hostapd_data
*hapd
= eloop_ctx
;
433 struct wpa_ft_rrb_rx_later_data
*data
, *n
;
435 dl_list_for_each_safe(data
, n
, &hapd
->l2_queue
,
436 struct wpa_ft_rrb_rx_later_data
, list
) {
437 if (hapd
->wpa_auth
) {
438 wpa_ft_rrb_rx(hapd
->wpa_auth
, data
->addr
,
439 (const u8
*) (data
+ 1),
442 dl_list_del(&data
->list
);
448 struct wpa_auth_ft_iface_iter_data
{
449 struct hostapd_data
*src_hapd
;
456 static int hostapd_wpa_auth_ft_iter(struct hostapd_iface
*iface
, void *ctx
)
458 struct wpa_auth_ft_iface_iter_data
*idata
= ctx
;
459 struct wpa_ft_rrb_rx_later_data
*data
;
460 struct hostapd_data
*hapd
;
463 for (j
= 0; j
< iface
->num_bss
; j
++) {
464 hapd
= iface
->bss
[j
];
465 if (hapd
== idata
->src_hapd
||
467 os_memcmp(hapd
->own_addr
, idata
->dst
, ETH_ALEN
) != 0)
470 wpa_printf(MSG_DEBUG
,
471 "FT: Send RRB data directly to locally managed BSS "
472 MACSTR
"@%s -> " MACSTR
"@%s",
473 MAC2STR(idata
->src_hapd
->own_addr
),
474 idata
->src_hapd
->conf
->iface
,
475 MAC2STR(hapd
->own_addr
), hapd
->conf
->iface
);
477 /* Defer wpa_ft_rrb_rx() until next eloop step as this is
478 * when it would be triggered when reading from a socket.
480 * hapd0:send -> hapd1:recv -> hapd1:send -> hapd0:recv,
481 * that is calling hapd0:recv handler from within
482 * hapd0:send directly.
484 data
= os_zalloc(sizeof(*data
) + idata
->data_len
);
488 os_memcpy(data
->addr
, idata
->src_hapd
->own_addr
, ETH_ALEN
);
489 os_memcpy(data
+ 1, idata
->data
, idata
->data_len
);
490 data
->data_len
= idata
->data_len
;
492 dl_list_add(&hapd
->l2_queue
, &data
->list
);
494 if (!eloop_is_timeout_registered(hostapd_wpa_ft_rrb_rx_later
,
496 eloop_register_timeout(0, 0,
497 hostapd_wpa_ft_rrb_rx_later
,
506 #endif /* CONFIG_IEEE80211R_AP */
509 static int hostapd_wpa_auth_send_ether(void *ctx
, const u8
*dst
, u16 proto
,
510 const u8
*data
, size_t data_len
)
512 struct hostapd_data
*hapd
= ctx
;
513 struct l2_ethhdr
*buf
;
516 #ifdef CONFIG_TESTING_OPTIONS
517 if (hapd
->ext_eapol_frame_io
&& proto
== ETH_P_EAPOL
) {
518 size_t hex_len
= 2 * data_len
+ 1;
519 char *hex
= os_malloc(hex_len
);
523 wpa_snprintf_hex(hex
, hex_len
, data
, data_len
);
524 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, "EAPOL-TX " MACSTR
" %s",
529 #endif /* CONFIG_TESTING_OPTIONS */
531 #ifdef CONFIG_IEEE80211R_AP
532 if (proto
== ETH_P_RRB
&& hapd
->iface
->interfaces
&&
533 hapd
->iface
->interfaces
->for_each_interface
) {
535 struct wpa_auth_ft_iface_iter_data idata
;
536 idata
.src_hapd
= hapd
;
539 idata
.data_len
= data_len
;
540 res
= hapd
->iface
->interfaces
->for_each_interface(
541 hapd
->iface
->interfaces
, hostapd_wpa_auth_ft_iter
,
546 #endif /* CONFIG_IEEE80211R_AP */
548 if (hapd
->driver
&& hapd
->driver
->send_ether
)
549 return hapd
->driver
->send_ether(hapd
->drv_priv
, dst
,
550 hapd
->own_addr
, proto
,
552 if (hapd
->l2
== NULL
)
555 buf
= os_malloc(sizeof(*buf
) + data_len
);
558 os_memcpy(buf
->h_dest
, dst
, ETH_ALEN
);
559 os_memcpy(buf
->h_source
, hapd
->own_addr
, ETH_ALEN
);
560 buf
->h_proto
= host_to_be16(proto
);
561 os_memcpy(buf
+ 1, data
, data_len
);
562 ret
= l2_packet_send(hapd
->l2
, dst
, proto
, (u8
*) buf
,
563 sizeof(*buf
) + data_len
);
569 #ifdef CONFIG_ETH_P_OUI
570 static struct eth_p_oui_ctx
* hostapd_wpa_get_oui(struct hostapd_data
*hapd
,
573 switch (oui_suffix
) {
574 #ifdef CONFIG_IEEE80211R_AP
575 case FT_PACKET_R0KH_R1KH_PULL
:
576 return hapd
->oui_pull
;
577 case FT_PACKET_R0KH_R1KH_RESP
:
578 return hapd
->oui_resp
;
579 case FT_PACKET_R0KH_R1KH_PUSH
:
580 return hapd
->oui_push
;
581 #endif /* CONFIG_IEEE80211R_AP */
586 #endif /* CONFIG_ETH_P_OUI */
589 #ifdef CONFIG_IEEE80211R_AP
591 struct oui_deliver_later_data
{
593 u8 src_addr
[ETH_ALEN
];
594 u8 dst_addr
[ETH_ALEN
];
597 /* followed by data_len octets of data */
600 static void hostapd_oui_deliver_later(void *eloop_ctx
, void *timeout_ctx
)
602 struct hostapd_data
*hapd
= eloop_ctx
;
603 struct oui_deliver_later_data
*data
, *n
;
604 struct eth_p_oui_ctx
*oui_ctx
;
606 dl_list_for_each_safe(data
, n
, &hapd
->l2_oui_queue
,
607 struct oui_deliver_later_data
, list
) {
608 oui_ctx
= hostapd_wpa_get_oui(hapd
, data
->oui_suffix
);
609 if (hapd
->wpa_auth
&& oui_ctx
) {
610 eth_p_oui_deliver(oui_ctx
, data
->src_addr
,
612 (const u8
*) (data
+ 1),
615 dl_list_del(&data
->list
);
621 struct wpa_auth_oui_iface_iter_data
{
622 struct hostapd_data
*src_hapd
;
629 static int hostapd_wpa_auth_oui_iter(struct hostapd_iface
*iface
, void *ctx
)
631 struct wpa_auth_oui_iface_iter_data
*idata
= ctx
;
632 struct oui_deliver_later_data
*data
;
633 struct hostapd_data
*hapd
;
636 for (j
= 0; j
< iface
->num_bss
; j
++) {
637 hapd
= iface
->bss
[j
];
638 if (hapd
== idata
->src_hapd
)
640 if (!is_multicast_ether_addr(idata
->dst_addr
) &&
641 os_memcmp(hapd
->own_addr
, idata
->dst_addr
, ETH_ALEN
) != 0)
644 /* defer eth_p_oui_deliver until next eloop step as this is
645 * when it would be triggerd from reading from sock
647 * hapd0:send -> hapd1:recv -> hapd1:send -> hapd0:recv,
648 * that is calling hapd0:recv handler from within
649 * hapd0:send directly.
651 data
= os_zalloc(sizeof(*data
) + idata
->data_len
);
655 os_memcpy(data
->src_addr
, idata
->src_hapd
->own_addr
, ETH_ALEN
);
656 os_memcpy(data
->dst_addr
, idata
->dst_addr
, ETH_ALEN
);
657 os_memcpy(data
+ 1, idata
->data
, idata
->data_len
);
658 data
->data_len
= idata
->data_len
;
659 data
->oui_suffix
= idata
->oui_suffix
;
661 dl_list_add(&hapd
->l2_oui_queue
, &data
->list
);
663 if (!eloop_is_timeout_registered(hostapd_oui_deliver_later
,
665 eloop_register_timeout(0, 0,
666 hostapd_oui_deliver_later
,
675 #endif /* CONFIG_IEEE80211R_AP */
678 static int hostapd_wpa_auth_send_oui(void *ctx
, const u8
*dst
, u8 oui_suffix
,
679 const u8
*data
, size_t data_len
)
681 #ifdef CONFIG_ETH_P_OUI
682 struct hostapd_data
*hapd
= ctx
;
683 struct eth_p_oui_ctx
*oui_ctx
;
685 #ifdef CONFIG_IEEE80211R_AP
686 if (hapd
->iface
->interfaces
&&
687 hapd
->iface
->interfaces
->for_each_interface
) {
688 struct wpa_auth_oui_iface_iter_data idata
;
691 idata
.src_hapd
= hapd
;
692 idata
.dst_addr
= dst
;
694 idata
.data_len
= data_len
;
695 idata
.oui_suffix
= oui_suffix
;
696 res
= hapd
->iface
->interfaces
->for_each_interface(
697 hapd
->iface
->interfaces
, hostapd_wpa_auth_oui_iter
,
702 #endif /* CONFIG_IEEE80211R_AP */
704 oui_ctx
= hostapd_wpa_get_oui(hapd
, oui_suffix
);
708 return eth_p_oui_send(oui_ctx
, hapd
->own_addr
, dst
, data
, data_len
);
709 #else /* CONFIG_ETH_P_OUI */
711 #endif /* CONFIG_ETH_P_OUI */
715 #ifdef CONFIG_IEEE80211R_AP
717 static int hostapd_wpa_auth_send_ft_action(void *ctx
, const u8
*dst
,
718 const u8
*data
, size_t data_len
)
720 struct hostapd_data
*hapd
= ctx
;
722 struct ieee80211_mgmt
*m
;
724 struct sta_info
*sta
;
726 sta
= ap_get_sta(hapd
, dst
);
727 if (sta
== NULL
|| sta
->wpa_sm
== NULL
)
730 m
= os_zalloc(sizeof(*m
) + data_len
);
733 mlen
= ((u8
*) &m
->u
- (u8
*) m
) + data_len
;
734 m
->frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
735 WLAN_FC_STYPE_ACTION
);
736 os_memcpy(m
->da
, dst
, ETH_ALEN
);
737 os_memcpy(m
->sa
, hapd
->own_addr
, ETH_ALEN
);
738 os_memcpy(m
->bssid
, hapd
->own_addr
, ETH_ALEN
);
739 os_memcpy(&m
->u
, data
, data_len
);
741 res
= hostapd_drv_send_mlme(hapd
, (u8
*) m
, mlen
, 0);
747 static struct wpa_state_machine
*
748 hostapd_wpa_auth_add_sta(void *ctx
, const u8
*sta_addr
)
750 struct hostapd_data
*hapd
= ctx
;
751 struct sta_info
*sta
;
753 if (hostapd_add_sta_node(hapd
, sta_addr
, WLAN_AUTH_FT
) < 0)
756 sta
= ap_sta_add(hapd
, sta_addr
);
760 sta
->auth_alg
= WLAN_AUTH_FT
;
764 sta
->wpa_sm
= wpa_auth_sta_init(hapd
->wpa_auth
, sta
->addr
, NULL
);
765 if (sta
->wpa_sm
== NULL
) {
766 ap_free_sta(hapd
, sta
);
769 sta
->auth_alg
= WLAN_AUTH_FT
;
775 static void hostapd_rrb_receive(void *ctx
, const u8
*src_addr
, const u8
*buf
,
778 struct hostapd_data
*hapd
= ctx
;
779 struct l2_ethhdr
*ethhdr
;
780 if (len
< sizeof(*ethhdr
))
782 ethhdr
= (struct l2_ethhdr
*) buf
;
783 wpa_printf(MSG_DEBUG
, "FT: RRB received packet " MACSTR
" -> "
784 MACSTR
, MAC2STR(ethhdr
->h_source
), MAC2STR(ethhdr
->h_dest
));
785 if (!is_multicast_ether_addr(ethhdr
->h_dest
) &&
786 os_memcmp(hapd
->own_addr
, ethhdr
->h_dest
, ETH_ALEN
) != 0)
788 wpa_ft_rrb_rx(hapd
->wpa_auth
, ethhdr
->h_source
, buf
+ sizeof(*ethhdr
),
789 len
- sizeof(*ethhdr
));
793 static void hostapd_rrb_oui_receive(void *ctx
, const u8
*src_addr
,
794 const u8
*dst_addr
, u8 oui_suffix
,
795 const u8
*buf
, size_t len
)
797 struct hostapd_data
*hapd
= ctx
;
799 wpa_printf(MSG_DEBUG
, "FT: RRB received packet " MACSTR
" -> "
800 MACSTR
, MAC2STR(src_addr
), MAC2STR(dst_addr
));
801 if (!is_multicast_ether_addr(dst_addr
) &&
802 os_memcmp(hapd
->own_addr
, dst_addr
, ETH_ALEN
) != 0)
804 wpa_ft_rrb_oui_rx(hapd
->wpa_auth
, src_addr
, dst_addr
, oui_suffix
, buf
,
809 static int hostapd_wpa_auth_add_tspec(void *ctx
, const u8
*sta_addr
,
810 u8
*tspec_ie
, size_t tspec_ielen
)
812 struct hostapd_data
*hapd
= ctx
;
813 return hostapd_add_tspec(hapd
, sta_addr
, tspec_ie
, tspec_ielen
);
818 static int hostapd_wpa_register_ft_oui(struct hostapd_data
*hapd
,
819 const char *ft_iface
)
821 hapd
->oui_pull
= eth_p_oui_register(hapd
, ft_iface
,
822 FT_PACKET_R0KH_R1KH_PULL
,
823 hostapd_rrb_oui_receive
, hapd
);
827 hapd
->oui_resp
= eth_p_oui_register(hapd
, ft_iface
,
828 FT_PACKET_R0KH_R1KH_RESP
,
829 hostapd_rrb_oui_receive
, hapd
);
833 hapd
->oui_push
= eth_p_oui_register(hapd
, ft_iface
,
834 FT_PACKET_R0KH_R1KH_PUSH
,
835 hostapd_rrb_oui_receive
, hapd
);
843 static void hostapd_wpa_unregister_ft_oui(struct hostapd_data
*hapd
)
845 eth_p_oui_unregister(hapd
->oui_pull
);
846 hapd
->oui_pull
= NULL
;
847 eth_p_oui_unregister(hapd
->oui_resp
);
848 hapd
->oui_resp
= NULL
;
849 eth_p_oui_unregister(hapd
->oui_push
);
850 hapd
->oui_push
= NULL
;
852 #endif /* CONFIG_IEEE80211R_AP */
855 int hostapd_setup_wpa(struct hostapd_data
*hapd
)
857 struct wpa_auth_config _conf
;
858 static const struct wpa_auth_callbacks cb
= {
859 .logger
= hostapd_wpa_auth_logger
,
860 .disconnect
= hostapd_wpa_auth_disconnect
,
861 .mic_failure_report
= hostapd_wpa_auth_mic_failure_report
,
862 .psk_failure_report
= hostapd_wpa_auth_psk_failure_report
,
863 .set_eapol
= hostapd_wpa_auth_set_eapol
,
864 .get_eapol
= hostapd_wpa_auth_get_eapol
,
865 .get_psk
= hostapd_wpa_auth_get_psk
,
866 .get_msk
= hostapd_wpa_auth_get_msk
,
867 .set_key
= hostapd_wpa_auth_set_key
,
868 .get_seqnum
= hostapd_wpa_auth_get_seqnum
,
869 .send_eapol
= hostapd_wpa_auth_send_eapol
,
870 .for_each_sta
= hostapd_wpa_auth_for_each_sta
,
871 .for_each_auth
= hostapd_wpa_auth_for_each_auth
,
872 .send_ether
= hostapd_wpa_auth_send_ether
,
873 .send_oui
= hostapd_wpa_auth_send_oui
,
874 #ifdef CONFIG_IEEE80211R_AP
875 .send_ft_action
= hostapd_wpa_auth_send_ft_action
,
876 .add_sta
= hostapd_wpa_auth_add_sta
,
877 .add_tspec
= hostapd_wpa_auth_add_tspec
,
878 #endif /* CONFIG_IEEE80211R_AP */
883 hostapd_wpa_auth_conf(hapd
->conf
, hapd
->iconf
, &_conf
);
884 if (hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
)
886 if (hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_AP_MLME
)
888 hapd
->wpa_auth
= wpa_init(hapd
->own_addr
, &_conf
, &cb
, hapd
);
889 if (hapd
->wpa_auth
== NULL
) {
890 wpa_printf(MSG_ERROR
, "WPA initialization failed.");
894 if (hostapd_set_privacy(hapd
, 1)) {
895 wpa_printf(MSG_ERROR
, "Could not set PrivacyInvoked "
896 "for interface %s", hapd
->conf
->iface
);
900 wpa_ie
= wpa_auth_get_wpa_ie(hapd
->wpa_auth
, &wpa_ie_len
);
901 if (hostapd_set_generic_elem(hapd
, wpa_ie
, wpa_ie_len
)) {
902 wpa_printf(MSG_ERROR
, "Failed to configure WPA IE for "
903 "the kernel driver.");
907 if (rsn_preauth_iface_init(hapd
)) {
908 wpa_printf(MSG_ERROR
, "Initialization of RSN "
909 "pre-authentication failed.");
913 #ifdef CONFIG_IEEE80211R_AP
914 if (!hostapd_drv_none(hapd
) &&
915 wpa_key_mgmt_ft(hapd
->conf
->wpa_key_mgmt
)) {
916 const char *ft_iface
;
918 ft_iface
= hapd
->conf
->bridge
[0] ? hapd
->conf
->bridge
:
920 hapd
->l2
= l2_packet_init(ft_iface
, NULL
, ETH_P_RRB
,
921 hostapd_rrb_receive
, hapd
, 1);
922 if (hapd
->l2
== NULL
&&
923 (hapd
->driver
== NULL
||
924 hapd
->driver
->send_ether
== NULL
)) {
925 wpa_printf(MSG_ERROR
, "Failed to open l2_packet "
930 if (hostapd_wpa_register_ft_oui(hapd
, ft_iface
)) {
931 wpa_printf(MSG_ERROR
,
932 "Failed to open ETH_P_OUI interface");
936 #endif /* CONFIG_IEEE80211R_AP */
943 void hostapd_reconfig_wpa(struct hostapd_data
*hapd
)
945 struct wpa_auth_config wpa_auth_conf
;
946 hostapd_wpa_auth_conf(hapd
->conf
, hapd
->iconf
, &wpa_auth_conf
);
947 wpa_reconfig(hapd
->wpa_auth
, &wpa_auth_conf
);
951 void hostapd_deinit_wpa(struct hostapd_data
*hapd
)
953 ieee80211_tkip_countermeasures_deinit(hapd
);
954 rsn_preauth_iface_deinit(hapd
);
955 if (hapd
->wpa_auth
) {
956 wpa_deinit(hapd
->wpa_auth
);
957 hapd
->wpa_auth
= NULL
;
959 if (hapd
->drv_priv
&& hostapd_set_privacy(hapd
, 0)) {
960 wpa_printf(MSG_DEBUG
, "Could not disable "
961 "PrivacyInvoked for interface %s",
965 if (hapd
->drv_priv
&&
966 hostapd_set_generic_elem(hapd
, (u8
*) "", 0)) {
967 wpa_printf(MSG_DEBUG
, "Could not remove generic "
968 "information element from interface %s",
972 ieee802_1x_deinit(hapd
);
974 #ifdef CONFIG_IEEE80211R_AP
975 eloop_cancel_timeout(hostapd_wpa_ft_rrb_rx_later
, hapd
, ELOOP_ALL_CTX
);
976 hostapd_wpa_ft_rrb_rx_later(hapd
, NULL
); /* flush without delivering */
977 eloop_cancel_timeout(hostapd_oui_deliver_later
, hapd
, ELOOP_ALL_CTX
);
978 hostapd_oui_deliver_later(hapd
, NULL
); /* flush without delivering */
979 l2_packet_deinit(hapd
->l2
);
981 hostapd_wpa_unregister_ft_oui(hapd
);
982 #endif /* CONFIG_IEEE80211R_AP */