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