xref: /freebsd/contrib/wpa/src/ap/wpa_auth_glue.c (revision 49b49cda41feabe3439f7318e8bf40e3896c7bf4)
1 /*
2  * hostapd / WPA authenticator glue code
3  * Copyright (c) 2002-2012, Jouni Malinen <j@w1.fi>
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8 
9 #include "utils/includes.h"
10 
11 #include "utils/common.h"
12 #include "common/ieee802_11_defs.h"
13 #include "common/sae.h"
14 #include "common/wpa_ctrl.h"
15 #include "eapol_auth/eapol_auth_sm.h"
16 #include "eapol_auth/eapol_auth_sm_i.h"
17 #include "eap_server/eap.h"
18 #include "l2_packet/l2_packet.h"
19 #include "hostapd.h"
20 #include "ieee802_1x.h"
21 #include "preauth_auth.h"
22 #include "sta_info.h"
23 #include "tkip_countermeasures.h"
24 #include "ap_drv_ops.h"
25 #include "ap_config.h"
26 #include "wpa_auth.h"
27 #include "wpa_auth_glue.h"
28 
29 
30 static void hostapd_wpa_auth_conf(struct hostapd_bss_config *conf,
31 				  struct hostapd_config *iconf,
32 				  struct wpa_auth_config *wconf)
33 {
34 	os_memset(wconf, 0, sizeof(*wconf));
35 	wconf->wpa = conf->wpa;
36 	wconf->wpa_key_mgmt = conf->wpa_key_mgmt;
37 	wconf->wpa_pairwise = conf->wpa_pairwise;
38 	wconf->wpa_group = conf->wpa_group;
39 	wconf->wpa_group_rekey = conf->wpa_group_rekey;
40 	wconf->wpa_strict_rekey = conf->wpa_strict_rekey;
41 	wconf->wpa_gmk_rekey = conf->wpa_gmk_rekey;
42 	wconf->wpa_ptk_rekey = conf->wpa_ptk_rekey;
43 	wconf->rsn_pairwise = conf->rsn_pairwise;
44 	wconf->rsn_preauth = conf->rsn_preauth;
45 	wconf->eapol_version = conf->eapol_version;
46 	wconf->peerkey = conf->peerkey;
47 	wconf->wmm_enabled = conf->wmm_enabled;
48 	wconf->wmm_uapsd = conf->wmm_uapsd;
49 	wconf->disable_pmksa_caching = conf->disable_pmksa_caching;
50 	wconf->okc = conf->okc;
51 #ifdef CONFIG_IEEE80211W
52 	wconf->ieee80211w = conf->ieee80211w;
53 	wconf->group_mgmt_cipher = conf->group_mgmt_cipher;
54 #endif /* CONFIG_IEEE80211W */
55 #ifdef CONFIG_IEEE80211R
56 	wconf->ssid_len = conf->ssid.ssid_len;
57 	if (wconf->ssid_len > SSID_MAX_LEN)
58 		wconf->ssid_len = SSID_MAX_LEN;
59 	os_memcpy(wconf->ssid, conf->ssid.ssid, wconf->ssid_len);
60 	os_memcpy(wconf->mobility_domain, conf->mobility_domain,
61 		  MOBILITY_DOMAIN_ID_LEN);
62 	if (conf->nas_identifier &&
63 	    os_strlen(conf->nas_identifier) <= FT_R0KH_ID_MAX_LEN) {
64 		wconf->r0_key_holder_len = os_strlen(conf->nas_identifier);
65 		os_memcpy(wconf->r0_key_holder, conf->nas_identifier,
66 			  wconf->r0_key_holder_len);
67 	}
68 	os_memcpy(wconf->r1_key_holder, conf->r1_key_holder, FT_R1KH_ID_LEN);
69 	wconf->r0_key_lifetime = conf->r0_key_lifetime;
70 	wconf->reassociation_deadline = conf->reassociation_deadline;
71 	wconf->r0kh_list = conf->r0kh_list;
72 	wconf->r1kh_list = conf->r1kh_list;
73 	wconf->pmk_r1_push = conf->pmk_r1_push;
74 	wconf->ft_over_ds = conf->ft_over_ds;
75 #endif /* CONFIG_IEEE80211R */
76 #ifdef CONFIG_HS20
77 	wconf->disable_gtk = conf->disable_dgaf;
78 	if (conf->osen) {
79 		wconf->disable_gtk = 1;
80 		wconf->wpa = WPA_PROTO_OSEN;
81 		wconf->wpa_key_mgmt = WPA_KEY_MGMT_OSEN;
82 		wconf->wpa_pairwise = 0;
83 		wconf->wpa_group = WPA_CIPHER_CCMP;
84 		wconf->rsn_pairwise = WPA_CIPHER_CCMP;
85 		wconf->rsn_preauth = 0;
86 		wconf->disable_pmksa_caching = 1;
87 #ifdef CONFIG_IEEE80211W
88 		wconf->ieee80211w = 1;
89 #endif /* CONFIG_IEEE80211W */
90 	}
91 #endif /* CONFIG_HS20 */
92 #ifdef CONFIG_TESTING_OPTIONS
93 	wconf->corrupt_gtk_rekey_mic_probability =
94 		iconf->corrupt_gtk_rekey_mic_probability;
95 	if (conf->own_ie_override &&
96 	    wpabuf_len(conf->own_ie_override) <= MAX_OWN_IE_OVERRIDE) {
97 		wconf->own_ie_override_len = wpabuf_len(conf->own_ie_override);
98 		os_memcpy(wconf->own_ie_override,
99 			  wpabuf_head(conf->own_ie_override),
100 			  wconf->own_ie_override_len);
101 	}
102 #endif /* CONFIG_TESTING_OPTIONS */
103 #ifdef CONFIG_P2P
104 	os_memcpy(wconf->ip_addr_go, conf->ip_addr_go, 4);
105 	os_memcpy(wconf->ip_addr_mask, conf->ip_addr_mask, 4);
106 	os_memcpy(wconf->ip_addr_start, conf->ip_addr_start, 4);
107 	os_memcpy(wconf->ip_addr_end, conf->ip_addr_end, 4);
108 #endif /* CONFIG_P2P */
109 }
110 
111 
112 static void hostapd_wpa_auth_logger(void *ctx, const u8 *addr,
113 				    logger_level level, const char *txt)
114 {
115 #ifndef CONFIG_NO_HOSTAPD_LOGGER
116 	struct hostapd_data *hapd = ctx;
117 	int hlevel;
118 
119 	switch (level) {
120 	case LOGGER_WARNING:
121 		hlevel = HOSTAPD_LEVEL_WARNING;
122 		break;
123 	case LOGGER_INFO:
124 		hlevel = HOSTAPD_LEVEL_INFO;
125 		break;
126 	case LOGGER_DEBUG:
127 	default:
128 		hlevel = HOSTAPD_LEVEL_DEBUG;
129 		break;
130 	}
131 
132 	hostapd_logger(hapd, addr, HOSTAPD_MODULE_WPA, hlevel, "%s", txt);
133 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
134 }
135 
136 
137 static void hostapd_wpa_auth_disconnect(void *ctx, const u8 *addr,
138 					u16 reason)
139 {
140 	struct hostapd_data *hapd = ctx;
141 	wpa_printf(MSG_DEBUG, "%s: WPA authenticator requests disconnect: "
142 		   "STA " MACSTR " reason %d",
143 		   __func__, MAC2STR(addr), reason);
144 	ap_sta_disconnect(hapd, NULL, addr, reason);
145 }
146 
147 
148 static int hostapd_wpa_auth_mic_failure_report(void *ctx, const u8 *addr)
149 {
150 	struct hostapd_data *hapd = ctx;
151 	return michael_mic_failure(hapd, addr, 0);
152 }
153 
154 
155 static void hostapd_wpa_auth_psk_failure_report(void *ctx, const u8 *addr)
156 {
157 	struct hostapd_data *hapd = ctx;
158 	wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
159 		MAC2STR(addr));
160 }
161 
162 
163 static void hostapd_wpa_auth_set_eapol(void *ctx, const u8 *addr,
164 				       wpa_eapol_variable var, int value)
165 {
166 	struct hostapd_data *hapd = ctx;
167 	struct sta_info *sta = ap_get_sta(hapd, addr);
168 	if (sta == NULL)
169 		return;
170 	switch (var) {
171 	case WPA_EAPOL_portEnabled:
172 		ieee802_1x_notify_port_enabled(sta->eapol_sm, value);
173 		break;
174 	case WPA_EAPOL_portValid:
175 		ieee802_1x_notify_port_valid(sta->eapol_sm, value);
176 		break;
177 	case WPA_EAPOL_authorized:
178 		ieee802_1x_set_sta_authorized(hapd, sta, value);
179 		break;
180 	case WPA_EAPOL_portControl_Auto:
181 		if (sta->eapol_sm)
182 			sta->eapol_sm->portControl = Auto;
183 		break;
184 	case WPA_EAPOL_keyRun:
185 		if (sta->eapol_sm)
186 			sta->eapol_sm->keyRun = value ? TRUE : FALSE;
187 		break;
188 	case WPA_EAPOL_keyAvailable:
189 		if (sta->eapol_sm)
190 			sta->eapol_sm->eap_if->eapKeyAvailable =
191 				value ? TRUE : FALSE;
192 		break;
193 	case WPA_EAPOL_keyDone:
194 		if (sta->eapol_sm)
195 			sta->eapol_sm->keyDone = value ? TRUE : FALSE;
196 		break;
197 	case WPA_EAPOL_inc_EapolFramesTx:
198 		if (sta->eapol_sm)
199 			sta->eapol_sm->dot1xAuthEapolFramesTx++;
200 		break;
201 	}
202 }
203 
204 
205 static int hostapd_wpa_auth_get_eapol(void *ctx, const u8 *addr,
206 				      wpa_eapol_variable var)
207 {
208 	struct hostapd_data *hapd = ctx;
209 	struct sta_info *sta = ap_get_sta(hapd, addr);
210 	if (sta == NULL || sta->eapol_sm == NULL)
211 		return -1;
212 	switch (var) {
213 	case WPA_EAPOL_keyRun:
214 		return sta->eapol_sm->keyRun;
215 	case WPA_EAPOL_keyAvailable:
216 		return sta->eapol_sm->eap_if->eapKeyAvailable;
217 	default:
218 		return -1;
219 	}
220 }
221 
222 
223 static const u8 * hostapd_wpa_auth_get_psk(void *ctx, const u8 *addr,
224 					   const u8 *p2p_dev_addr,
225 					   const u8 *prev_psk)
226 {
227 	struct hostapd_data *hapd = ctx;
228 	struct sta_info *sta = ap_get_sta(hapd, addr);
229 	const u8 *psk;
230 
231 #ifdef CONFIG_SAE
232 	if (sta && sta->auth_alg == WLAN_AUTH_SAE) {
233 		if (!sta->sae || prev_psk)
234 			return NULL;
235 		return sta->sae->pmk;
236 	}
237 #endif /* CONFIG_SAE */
238 
239 	psk = hostapd_get_psk(hapd->conf, addr, p2p_dev_addr, prev_psk);
240 	/*
241 	 * This is about to iterate over all psks, prev_psk gives the last
242 	 * returned psk which should not be returned again.
243 	 * logic list (all hostapd_get_psk; all sta->psk)
244 	 */
245 	if (sta && sta->psk && !psk) {
246 		struct hostapd_sta_wpa_psk_short *pos;
247 		psk = sta->psk->psk;
248 		for (pos = sta->psk; pos; pos = pos->next) {
249 			if (pos->psk == prev_psk) {
250 				psk = pos->next ? pos->next->psk : NULL;
251 				break;
252 			}
253 		}
254 	}
255 	return psk;
256 }
257 
258 
259 static int hostapd_wpa_auth_get_msk(void *ctx, const u8 *addr, u8 *msk,
260 				    size_t *len)
261 {
262 	struct hostapd_data *hapd = ctx;
263 	const u8 *key;
264 	size_t keylen;
265 	struct sta_info *sta;
266 
267 	sta = ap_get_sta(hapd, addr);
268 	if (sta == NULL) {
269 		wpa_printf(MSG_DEBUG, "AUTH_GET_MSK: Cannot find STA");
270 		return -1;
271 	}
272 
273 	key = ieee802_1x_get_key(sta->eapol_sm, &keylen);
274 	if (key == NULL) {
275 		wpa_printf(MSG_DEBUG, "AUTH_GET_MSK: Key is null, eapol_sm: %p",
276 			   sta->eapol_sm);
277 		return -1;
278 	}
279 
280 	if (keylen > *len)
281 		keylen = *len;
282 	os_memcpy(msk, key, keylen);
283 	*len = keylen;
284 
285 	return 0;
286 }
287 
288 
289 static int hostapd_wpa_auth_set_key(void *ctx, int vlan_id, enum wpa_alg alg,
290 				    const u8 *addr, int idx, u8 *key,
291 				    size_t key_len)
292 {
293 	struct hostapd_data *hapd = ctx;
294 	const char *ifname = hapd->conf->iface;
295 
296 	if (vlan_id > 0) {
297 		ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan, vlan_id);
298 		if (ifname == NULL)
299 			return -1;
300 	}
301 
302 	return hostapd_drv_set_key(ifname, hapd, alg, addr, idx, 1, NULL, 0,
303 				   key, key_len);
304 }
305 
306 
307 static int hostapd_wpa_auth_get_seqnum(void *ctx, const u8 *addr, int idx,
308 				       u8 *seq)
309 {
310 	struct hostapd_data *hapd = ctx;
311 	return hostapd_get_seqnum(hapd->conf->iface, hapd, addr, idx, seq);
312 }
313 
314 
315 static int hostapd_wpa_auth_send_eapol(void *ctx, const u8 *addr,
316 				       const u8 *data, size_t data_len,
317 				       int encrypt)
318 {
319 	struct hostapd_data *hapd = ctx;
320 	struct sta_info *sta;
321 	u32 flags = 0;
322 
323 #ifdef CONFIG_TESTING_OPTIONS
324 	if (hapd->ext_eapol_frame_io) {
325 		size_t hex_len = 2 * data_len + 1;
326 		char *hex = os_malloc(hex_len);
327 
328 		if (hex == NULL)
329 			return -1;
330 		wpa_snprintf_hex(hex, hex_len, data, data_len);
331 		wpa_msg(hapd->msg_ctx, MSG_INFO, "EAPOL-TX " MACSTR " %s",
332 			MAC2STR(addr), hex);
333 		os_free(hex);
334 		return 0;
335 	}
336 #endif /* CONFIG_TESTING_OPTIONS */
337 
338 	sta = ap_get_sta(hapd, addr);
339 	if (sta)
340 		flags = hostapd_sta_flags_to_drv(sta->flags);
341 
342 	return hostapd_drv_hapd_send_eapol(hapd, addr, data, data_len,
343 					   encrypt, flags);
344 }
345 
346 
347 static int hostapd_wpa_auth_for_each_sta(
348 	void *ctx, int (*cb)(struct wpa_state_machine *sm, void *ctx),
349 	void *cb_ctx)
350 {
351 	struct hostapd_data *hapd = ctx;
352 	struct sta_info *sta;
353 
354 	for (sta = hapd->sta_list; sta; sta = sta->next) {
355 		if (sta->wpa_sm && cb(sta->wpa_sm, cb_ctx))
356 			return 1;
357 	}
358 	return 0;
359 }
360 
361 
362 struct wpa_auth_iface_iter_data {
363 	int (*cb)(struct wpa_authenticator *sm, void *ctx);
364 	void *cb_ctx;
365 };
366 
367 static int wpa_auth_iface_iter(struct hostapd_iface *iface, void *ctx)
368 {
369 	struct wpa_auth_iface_iter_data *data = ctx;
370 	size_t i;
371 	for (i = 0; i < iface->num_bss; i++) {
372 		if (iface->bss[i]->wpa_auth &&
373 		    data->cb(iface->bss[i]->wpa_auth, data->cb_ctx))
374 			return 1;
375 	}
376 	return 0;
377 }
378 
379 
380 static int hostapd_wpa_auth_for_each_auth(
381 	void *ctx, int (*cb)(struct wpa_authenticator *sm, void *ctx),
382 	void *cb_ctx)
383 {
384 	struct hostapd_data *hapd = ctx;
385 	struct wpa_auth_iface_iter_data data;
386 	if (hapd->iface->interfaces == NULL ||
387 	    hapd->iface->interfaces->for_each_interface == NULL)
388 		return -1;
389 	data.cb = cb;
390 	data.cb_ctx = cb_ctx;
391 	return hapd->iface->interfaces->for_each_interface(
392 		hapd->iface->interfaces, wpa_auth_iface_iter, &data);
393 }
394 
395 
396 #ifdef CONFIG_IEEE80211R
397 
398 struct wpa_auth_ft_iface_iter_data {
399 	struct hostapd_data *src_hapd;
400 	const u8 *dst;
401 	const u8 *data;
402 	size_t data_len;
403 };
404 
405 
406 static int hostapd_wpa_auth_ft_iter(struct hostapd_iface *iface, void *ctx)
407 {
408 	struct wpa_auth_ft_iface_iter_data *idata = ctx;
409 	struct hostapd_data *hapd;
410 	size_t j;
411 
412 	for (j = 0; j < iface->num_bss; j++) {
413 		hapd = iface->bss[j];
414 		if (hapd == idata->src_hapd)
415 			continue;
416 		if (os_memcmp(hapd->own_addr, idata->dst, ETH_ALEN) == 0) {
417 			wpa_printf(MSG_DEBUG, "FT: Send RRB data directly to "
418 				   "locally managed BSS " MACSTR "@%s -> "
419 				   MACSTR "@%s",
420 				   MAC2STR(idata->src_hapd->own_addr),
421 				   idata->src_hapd->conf->iface,
422 				   MAC2STR(hapd->own_addr), hapd->conf->iface);
423 			wpa_ft_rrb_rx(hapd->wpa_auth,
424 				      idata->src_hapd->own_addr,
425 				      idata->data, idata->data_len);
426 			return 1;
427 		}
428 	}
429 
430 	return 0;
431 }
432 
433 #endif /* CONFIG_IEEE80211R */
434 
435 
436 static int hostapd_wpa_auth_send_ether(void *ctx, const u8 *dst, u16 proto,
437 				       const u8 *data, size_t data_len)
438 {
439 	struct hostapd_data *hapd = ctx;
440 	struct l2_ethhdr *buf;
441 	int ret;
442 
443 #ifdef CONFIG_TESTING_OPTIONS
444 	if (hapd->ext_eapol_frame_io && proto == ETH_P_EAPOL) {
445 		size_t hex_len = 2 * data_len + 1;
446 		char *hex = os_malloc(hex_len);
447 
448 		if (hex == NULL)
449 			return -1;
450 		wpa_snprintf_hex(hex, hex_len, data, data_len);
451 		wpa_msg(hapd->msg_ctx, MSG_INFO, "EAPOL-TX " MACSTR " %s",
452 			MAC2STR(dst), hex);
453 		os_free(hex);
454 		return 0;
455 	}
456 #endif /* CONFIG_TESTING_OPTIONS */
457 
458 #ifdef CONFIG_IEEE80211R
459 	if (proto == ETH_P_RRB && hapd->iface->interfaces &&
460 	    hapd->iface->interfaces->for_each_interface) {
461 		int res;
462 		struct wpa_auth_ft_iface_iter_data idata;
463 		idata.src_hapd = hapd;
464 		idata.dst = dst;
465 		idata.data = data;
466 		idata.data_len = data_len;
467 		res = hapd->iface->interfaces->for_each_interface(
468 			hapd->iface->interfaces, hostapd_wpa_auth_ft_iter,
469 			&idata);
470 		if (res == 1)
471 			return data_len;
472 	}
473 #endif /* CONFIG_IEEE80211R */
474 
475 	if (hapd->driver && hapd->driver->send_ether)
476 		return hapd->driver->send_ether(hapd->drv_priv, dst,
477 						hapd->own_addr, proto,
478 						data, data_len);
479 	if (hapd->l2 == NULL)
480 		return -1;
481 
482 	buf = os_malloc(sizeof(*buf) + data_len);
483 	if (buf == NULL)
484 		return -1;
485 	os_memcpy(buf->h_dest, dst, ETH_ALEN);
486 	os_memcpy(buf->h_source, hapd->own_addr, ETH_ALEN);
487 	buf->h_proto = host_to_be16(proto);
488 	os_memcpy(buf + 1, data, data_len);
489 	ret = l2_packet_send(hapd->l2, dst, proto, (u8 *) buf,
490 			     sizeof(*buf) + data_len);
491 	os_free(buf);
492 	return ret;
493 }
494 
495 
496 #ifdef CONFIG_IEEE80211R
497 
498 static int hostapd_wpa_auth_send_ft_action(void *ctx, const u8 *dst,
499 					   const u8 *data, size_t data_len)
500 {
501 	struct hostapd_data *hapd = ctx;
502 	int res;
503 	struct ieee80211_mgmt *m;
504 	size_t mlen;
505 	struct sta_info *sta;
506 
507 	sta = ap_get_sta(hapd, dst);
508 	if (sta == NULL || sta->wpa_sm == NULL)
509 		return -1;
510 
511 	m = os_zalloc(sizeof(*m) + data_len);
512 	if (m == NULL)
513 		return -1;
514 	mlen = ((u8 *) &m->u - (u8 *) m) + data_len;
515 	m->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
516 					WLAN_FC_STYPE_ACTION);
517 	os_memcpy(m->da, dst, ETH_ALEN);
518 	os_memcpy(m->sa, hapd->own_addr, ETH_ALEN);
519 	os_memcpy(m->bssid, hapd->own_addr, ETH_ALEN);
520 	os_memcpy(&m->u, data, data_len);
521 
522 	res = hostapd_drv_send_mlme(hapd, (u8 *) m, mlen, 0);
523 	os_free(m);
524 	return res;
525 }
526 
527 
528 static struct wpa_state_machine *
529 hostapd_wpa_auth_add_sta(void *ctx, const u8 *sta_addr)
530 {
531 	struct hostapd_data *hapd = ctx;
532 	struct sta_info *sta;
533 
534 	if (hostapd_add_sta_node(hapd, sta_addr, WLAN_AUTH_FT) < 0)
535 		return NULL;
536 
537 	sta = ap_sta_add(hapd, sta_addr);
538 	if (sta == NULL)
539 		return NULL;
540 	if (sta->wpa_sm) {
541 		sta->auth_alg = WLAN_AUTH_FT;
542 		return sta->wpa_sm;
543 	}
544 
545 	sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, sta->addr, NULL);
546 	if (sta->wpa_sm == NULL) {
547 		ap_free_sta(hapd, sta);
548 		return NULL;
549 	}
550 	sta->auth_alg = WLAN_AUTH_FT;
551 
552 	return sta->wpa_sm;
553 }
554 
555 
556 static void hostapd_rrb_receive(void *ctx, const u8 *src_addr, const u8 *buf,
557 				size_t len)
558 {
559 	struct hostapd_data *hapd = ctx;
560 	struct l2_ethhdr *ethhdr;
561 	if (len < sizeof(*ethhdr))
562 		return;
563 	ethhdr = (struct l2_ethhdr *) buf;
564 	wpa_printf(MSG_DEBUG, "FT: RRB received packet " MACSTR " -> "
565 		   MACSTR, MAC2STR(ethhdr->h_source), MAC2STR(ethhdr->h_dest));
566 	wpa_ft_rrb_rx(hapd->wpa_auth, ethhdr->h_source, buf + sizeof(*ethhdr),
567 		      len - sizeof(*ethhdr));
568 }
569 
570 
571 static int hostapd_wpa_auth_add_tspec(void *ctx, const u8 *sta_addr,
572 				      u8 *tspec_ie, size_t tspec_ielen)
573 {
574 	struct hostapd_data *hapd = ctx;
575 	return hostapd_add_tspec(hapd, sta_addr, tspec_ie, tspec_ielen);
576 }
577 
578 #endif /* CONFIG_IEEE80211R */
579 
580 
581 int hostapd_setup_wpa(struct hostapd_data *hapd)
582 {
583 	struct wpa_auth_config _conf;
584 	struct wpa_auth_callbacks cb;
585 	const u8 *wpa_ie;
586 	size_t wpa_ie_len;
587 
588 	hostapd_wpa_auth_conf(hapd->conf, hapd->iconf, &_conf);
589 	if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_EAPOL_TX_STATUS)
590 		_conf.tx_status = 1;
591 	if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_MLME)
592 		_conf.ap_mlme = 1;
593 	os_memset(&cb, 0, sizeof(cb));
594 	cb.ctx = hapd;
595 	cb.logger = hostapd_wpa_auth_logger;
596 	cb.disconnect = hostapd_wpa_auth_disconnect;
597 	cb.mic_failure_report = hostapd_wpa_auth_mic_failure_report;
598 	cb.psk_failure_report = hostapd_wpa_auth_psk_failure_report;
599 	cb.set_eapol = hostapd_wpa_auth_set_eapol;
600 	cb.get_eapol = hostapd_wpa_auth_get_eapol;
601 	cb.get_psk = hostapd_wpa_auth_get_psk;
602 	cb.get_msk = hostapd_wpa_auth_get_msk;
603 	cb.set_key = hostapd_wpa_auth_set_key;
604 	cb.get_seqnum = hostapd_wpa_auth_get_seqnum;
605 	cb.send_eapol = hostapd_wpa_auth_send_eapol;
606 	cb.for_each_sta = hostapd_wpa_auth_for_each_sta;
607 	cb.for_each_auth = hostapd_wpa_auth_for_each_auth;
608 	cb.send_ether = hostapd_wpa_auth_send_ether;
609 #ifdef CONFIG_IEEE80211R
610 	cb.send_ft_action = hostapd_wpa_auth_send_ft_action;
611 	cb.add_sta = hostapd_wpa_auth_add_sta;
612 	cb.add_tspec = hostapd_wpa_auth_add_tspec;
613 #endif /* CONFIG_IEEE80211R */
614 	hapd->wpa_auth = wpa_init(hapd->own_addr, &_conf, &cb);
615 	if (hapd->wpa_auth == NULL) {
616 		wpa_printf(MSG_ERROR, "WPA initialization failed.");
617 		return -1;
618 	}
619 
620 	if (hostapd_set_privacy(hapd, 1)) {
621 		wpa_printf(MSG_ERROR, "Could not set PrivacyInvoked "
622 			   "for interface %s", hapd->conf->iface);
623 		return -1;
624 	}
625 
626 	wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
627 	if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len)) {
628 		wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
629 			   "the kernel driver.");
630 		return -1;
631 	}
632 
633 	if (rsn_preauth_iface_init(hapd)) {
634 		wpa_printf(MSG_ERROR, "Initialization of RSN "
635 			   "pre-authentication failed.");
636 		return -1;
637 	}
638 
639 #ifdef CONFIG_IEEE80211R
640 	if (!hostapd_drv_none(hapd) && hapd->conf->ft_over_ds &&
641 	    wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt)) {
642 		hapd->l2 = l2_packet_init(hapd->conf->bridge[0] ?
643 					  hapd->conf->bridge :
644 					  hapd->conf->iface, NULL, ETH_P_RRB,
645 					  hostapd_rrb_receive, hapd, 1);
646 		if (hapd->l2 == NULL &&
647 		    (hapd->driver == NULL ||
648 		     hapd->driver->send_ether == NULL)) {
649 			wpa_printf(MSG_ERROR, "Failed to open l2_packet "
650 				   "interface");
651 			return -1;
652 		}
653 	}
654 #endif /* CONFIG_IEEE80211R */
655 
656 	return 0;
657 
658 }
659 
660 
661 void hostapd_reconfig_wpa(struct hostapd_data *hapd)
662 {
663 	struct wpa_auth_config wpa_auth_conf;
664 	hostapd_wpa_auth_conf(hapd->conf, hapd->iconf, &wpa_auth_conf);
665 	wpa_reconfig(hapd->wpa_auth, &wpa_auth_conf);
666 }
667 
668 
669 void hostapd_deinit_wpa(struct hostapd_data *hapd)
670 {
671 	ieee80211_tkip_countermeasures_deinit(hapd);
672 	rsn_preauth_iface_deinit(hapd);
673 	if (hapd->wpa_auth) {
674 		wpa_deinit(hapd->wpa_auth);
675 		hapd->wpa_auth = NULL;
676 
677 		if (hostapd_set_privacy(hapd, 0)) {
678 			wpa_printf(MSG_DEBUG, "Could not disable "
679 				   "PrivacyInvoked for interface %s",
680 				   hapd->conf->iface);
681 		}
682 
683 		if (hostapd_set_generic_elem(hapd, (u8 *) "", 0)) {
684 			wpa_printf(MSG_DEBUG, "Could not remove generic "
685 				   "information element from interface %s",
686 				   hapd->conf->iface);
687 		}
688 	}
689 	ieee802_1x_deinit(hapd);
690 
691 #ifdef CONFIG_IEEE80211R
692 	l2_packet_deinit(hapd->l2);
693 	hapd->l2 = NULL;
694 #endif /* CONFIG_IEEE80211R */
695 }
696