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