]> git.ipfire.org Git - thirdparty/hostap.git/blob - src/ap/wpa_auth_glue.c
c0786cee5208fc9e33bb87f4231149cb5fd227be
[thirdparty/hostap.git] / src / ap / wpa_auth_glue.c
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 "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"
23 #include "hostapd.h"
24 #include "ieee802_1x.h"
25 #include "preauth_auth.h"
26 #include "sta_info.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"
32 #include "wpa_auth.h"
33 #include "wpa_auth_glue.h"
34
35
36 static void hostapd_wpa_auth_conf(struct hostapd_bss_config *conf,
37 struct hostapd_config *iconf,
38 struct wpa_auth_config *wconf)
39 {
40 os_memset(wconf, 0, sizeof(*wconf));
41 wconf->wpa = conf->wpa;
42 wconf->wpa_key_mgmt = conf->wpa_key_mgmt;
43 wconf->wpa_pairwise = conf->wpa_pairwise;
44 wconf->wpa_group = conf->wpa_group;
45 wconf->wpa_group_rekey = conf->wpa_group_rekey;
46 wconf->wpa_strict_rekey = conf->wpa_strict_rekey;
47 wconf->wpa_gmk_rekey = conf->wpa_gmk_rekey;
48 wconf->wpa_ptk_rekey = conf->wpa_ptk_rekey;
49 wconf->wpa_group_update_count = conf->wpa_group_update_count;
50 wconf->wpa_disable_eapol_key_retries =
51 conf->wpa_disable_eapol_key_retries;
52 wconf->wpa_pairwise_update_count = conf->wpa_pairwise_update_count;
53 wconf->rsn_pairwise = conf->rsn_pairwise;
54 wconf->rsn_preauth = conf->rsn_preauth;
55 wconf->eapol_version = conf->eapol_version;
56 #ifdef CONFIG_MACSEC
57 if (wconf->eapol_version > 2)
58 wconf->eapol_version = 2;
59 #endif /* CONFIG_MACSEC */
60 wconf->wmm_enabled = conf->wmm_enabled;
61 wconf->wmm_uapsd = conf->wmm_uapsd;
62 wconf->disable_pmksa_caching = conf->disable_pmksa_caching;
63 #ifdef CONFIG_OCV
64 wconf->ocv = conf->ocv;
65 #endif /* CONFIG_OCV */
66 wconf->okc = conf->okc;
67 wconf->ieee80211w = conf->ieee80211w;
68 wconf->group_mgmt_cipher = conf->group_mgmt_cipher;
69 wconf->sae_require_mfp = conf->sae_require_mfp;
70 #ifdef CONFIG_IEEE80211R_AP
71 wconf->ssid_len = conf->ssid.ssid_len;
72 if (wconf->ssid_len > SSID_MAX_LEN)
73 wconf->ssid_len = SSID_MAX_LEN;
74 os_memcpy(wconf->ssid, conf->ssid.ssid, wconf->ssid_len);
75 os_memcpy(wconf->mobility_domain, conf->mobility_domain,
76 MOBILITY_DOMAIN_ID_LEN);
77 if (conf->nas_identifier &&
78 os_strlen(conf->nas_identifier) <= FT_R0KH_ID_MAX_LEN) {
79 wconf->r0_key_holder_len = os_strlen(conf->nas_identifier);
80 os_memcpy(wconf->r0_key_holder, conf->nas_identifier,
81 wconf->r0_key_holder_len);
82 }
83 os_memcpy(wconf->r1_key_holder, conf->r1_key_holder, FT_R1KH_ID_LEN);
84 wconf->r0_key_lifetime = conf->r0_key_lifetime;
85 wconf->r1_max_key_lifetime = conf->r1_max_key_lifetime;
86 wconf->reassociation_deadline = conf->reassociation_deadline;
87 wconf->rkh_pos_timeout = conf->rkh_pos_timeout;
88 wconf->rkh_neg_timeout = conf->rkh_neg_timeout;
89 wconf->rkh_pull_timeout = conf->rkh_pull_timeout;
90 wconf->rkh_pull_retries = conf->rkh_pull_retries;
91 wconf->r0kh_list = &conf->r0kh_list;
92 wconf->r1kh_list = &conf->r1kh_list;
93 wconf->pmk_r1_push = conf->pmk_r1_push;
94 wconf->ft_over_ds = conf->ft_over_ds;
95 wconf->ft_psk_generate_local = conf->ft_psk_generate_local;
96 #endif /* CONFIG_IEEE80211R_AP */
97 #ifdef CONFIG_HS20
98 wconf->disable_gtk = conf->disable_dgaf;
99 if (conf->osen) {
100 wconf->disable_gtk = 1;
101 wconf->wpa = WPA_PROTO_OSEN;
102 wconf->wpa_key_mgmt = WPA_KEY_MGMT_OSEN;
103 wconf->wpa_pairwise = 0;
104 wconf->wpa_group = WPA_CIPHER_CCMP;
105 wconf->rsn_pairwise = WPA_CIPHER_CCMP;
106 wconf->rsn_preauth = 0;
107 wconf->disable_pmksa_caching = 1;
108 wconf->ieee80211w = 1;
109 }
110 #endif /* CONFIG_HS20 */
111 #ifdef CONFIG_TESTING_OPTIONS
112 wconf->corrupt_gtk_rekey_mic_probability =
113 iconf->corrupt_gtk_rekey_mic_probability;
114 if (conf->own_ie_override &&
115 wpabuf_len(conf->own_ie_override) <= MAX_OWN_IE_OVERRIDE) {
116 wconf->own_ie_override_len = wpabuf_len(conf->own_ie_override);
117 os_memcpy(wconf->own_ie_override,
118 wpabuf_head(conf->own_ie_override),
119 wconf->own_ie_override_len);
120 }
121 #endif /* CONFIG_TESTING_OPTIONS */
122 #ifdef CONFIG_P2P
123 os_memcpy(wconf->ip_addr_go, conf->ip_addr_go, 4);
124 os_memcpy(wconf->ip_addr_mask, conf->ip_addr_mask, 4);
125 os_memcpy(wconf->ip_addr_start, conf->ip_addr_start, 4);
126 os_memcpy(wconf->ip_addr_end, conf->ip_addr_end, 4);
127 #endif /* CONFIG_P2P */
128 #ifdef CONFIG_FILS
129 wconf->fils_cache_id_set = conf->fils_cache_id_set;
130 os_memcpy(wconf->fils_cache_id, conf->fils_cache_id,
131 FILS_CACHE_ID_LEN);
132 #endif /* CONFIG_FILS */
133 }
134
135
136 static void hostapd_wpa_auth_logger(void *ctx, const u8 *addr,
137 logger_level level, const char *txt)
138 {
139 #ifndef CONFIG_NO_HOSTAPD_LOGGER
140 struct hostapd_data *hapd = ctx;
141 int hlevel;
142
143 switch (level) {
144 case LOGGER_WARNING:
145 hlevel = HOSTAPD_LEVEL_WARNING;
146 break;
147 case LOGGER_INFO:
148 hlevel = HOSTAPD_LEVEL_INFO;
149 break;
150 case LOGGER_DEBUG:
151 default:
152 hlevel = HOSTAPD_LEVEL_DEBUG;
153 break;
154 }
155
156 hostapd_logger(hapd, addr, HOSTAPD_MODULE_WPA, hlevel, "%s", txt);
157 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
158 }
159
160
161 static void hostapd_wpa_auth_disconnect(void *ctx, const u8 *addr,
162 u16 reason)
163 {
164 struct hostapd_data *hapd = ctx;
165 wpa_printf(MSG_DEBUG, "%s: WPA authenticator requests disconnect: "
166 "STA " MACSTR " reason %d",
167 __func__, MAC2STR(addr), reason);
168 ap_sta_disconnect(hapd, NULL, addr, reason);
169 }
170
171
172 static int hostapd_wpa_auth_mic_failure_report(void *ctx, const u8 *addr)
173 {
174 struct hostapd_data *hapd = ctx;
175 return michael_mic_failure(hapd, addr, 0);
176 }
177
178
179 static void hostapd_wpa_auth_psk_failure_report(void *ctx, const u8 *addr)
180 {
181 struct hostapd_data *hapd = ctx;
182 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
183 MAC2STR(addr));
184 }
185
186
187 static void hostapd_wpa_auth_set_eapol(void *ctx, const u8 *addr,
188 wpa_eapol_variable var, int value)
189 {
190 struct hostapd_data *hapd = ctx;
191 struct sta_info *sta = ap_get_sta(hapd, addr);
192 if (sta == NULL)
193 return;
194 switch (var) {
195 case WPA_EAPOL_portEnabled:
196 ieee802_1x_notify_port_enabled(sta->eapol_sm, value);
197 break;
198 case WPA_EAPOL_portValid:
199 ieee802_1x_notify_port_valid(sta->eapol_sm, value);
200 break;
201 case WPA_EAPOL_authorized:
202 ieee802_1x_set_sta_authorized(hapd, sta, value);
203 break;
204 case WPA_EAPOL_portControl_Auto:
205 if (sta->eapol_sm)
206 sta->eapol_sm->portControl = Auto;
207 break;
208 case WPA_EAPOL_keyRun:
209 if (sta->eapol_sm)
210 sta->eapol_sm->keyRun = value ? TRUE : FALSE;
211 break;
212 case WPA_EAPOL_keyAvailable:
213 if (sta->eapol_sm)
214 sta->eapol_sm->eap_if->eapKeyAvailable =
215 value ? TRUE : FALSE;
216 break;
217 case WPA_EAPOL_keyDone:
218 if (sta->eapol_sm)
219 sta->eapol_sm->keyDone = value ? TRUE : FALSE;
220 break;
221 case WPA_EAPOL_inc_EapolFramesTx:
222 if (sta->eapol_sm)
223 sta->eapol_sm->dot1xAuthEapolFramesTx++;
224 break;
225 }
226 }
227
228
229 static int hostapd_wpa_auth_get_eapol(void *ctx, const u8 *addr,
230 wpa_eapol_variable var)
231 {
232 struct hostapd_data *hapd = ctx;
233 struct sta_info *sta = ap_get_sta(hapd, addr);
234 if (sta == NULL || sta->eapol_sm == NULL)
235 return -1;
236 switch (var) {
237 case WPA_EAPOL_keyRun:
238 return sta->eapol_sm->keyRun;
239 case WPA_EAPOL_keyAvailable:
240 return sta->eapol_sm->eap_if->eapKeyAvailable;
241 default:
242 return -1;
243 }
244 }
245
246
247 static const u8 * hostapd_wpa_auth_get_psk(void *ctx, const u8 *addr,
248 const u8 *p2p_dev_addr,
249 const u8 *prev_psk, size_t *psk_len,
250 int *vlan_id)
251 {
252 struct hostapd_data *hapd = ctx;
253 struct sta_info *sta = ap_get_sta(hapd, addr);
254 const u8 *psk;
255
256 if (vlan_id)
257 *vlan_id = 0;
258 if (psk_len)
259 *psk_len = PMK_LEN;
260
261 #ifdef CONFIG_SAE
262 if (sta && sta->auth_alg == WLAN_AUTH_SAE) {
263 if (!sta->sae || prev_psk)
264 return NULL;
265 return sta->sae->pmk;
266 }
267 if (sta && wpa_auth_uses_sae(sta->wpa_sm)) {
268 wpa_printf(MSG_DEBUG,
269 "No PSK for STA trying to use SAE with PMKSA caching");
270 return NULL;
271 }
272 #endif /* CONFIG_SAE */
273
274 #ifdef CONFIG_OWE
275 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
276 sta && sta->owe_pmk) {
277 if (psk_len)
278 *psk_len = sta->owe_pmk_len;
279 return sta->owe_pmk;
280 }
281 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) && sta) {
282 struct rsn_pmksa_cache_entry *sa;
283
284 sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
285 if (sa && sa->akmp == WPA_KEY_MGMT_OWE) {
286 if (psk_len)
287 *psk_len = sa->pmk_len;
288 return sa->pmk;
289 }
290 }
291 #endif /* CONFIG_OWE */
292
293 psk = hostapd_get_psk(hapd->conf, addr, p2p_dev_addr, prev_psk,
294 vlan_id);
295 /*
296 * This is about to iterate over all psks, prev_psk gives the last
297 * returned psk which should not be returned again.
298 * logic list (all hostapd_get_psk; all sta->psk)
299 */
300 if (sta && sta->psk && !psk) {
301 struct hostapd_sta_wpa_psk_short *pos;
302
303 if (vlan_id)
304 *vlan_id = 0;
305 psk = sta->psk->psk;
306 for (pos = sta->psk; pos; pos = pos->next) {
307 if (pos->is_passphrase) {
308 pbkdf2_sha1(pos->passphrase,
309 hapd->conf->ssid.ssid,
310 hapd->conf->ssid.ssid_len, 4096,
311 pos->psk, PMK_LEN);
312 pos->is_passphrase = 0;
313 }
314 if (pos->psk == prev_psk) {
315 psk = pos->next ? pos->next->psk : NULL;
316 break;
317 }
318 }
319 }
320 return psk;
321 }
322
323
324 static int hostapd_wpa_auth_get_msk(void *ctx, const u8 *addr, u8 *msk,
325 size_t *len)
326 {
327 struct hostapd_data *hapd = ctx;
328 const u8 *key;
329 size_t keylen;
330 struct sta_info *sta;
331
332 sta = ap_get_sta(hapd, addr);
333 if (sta == NULL) {
334 wpa_printf(MSG_DEBUG, "AUTH_GET_MSK: Cannot find STA");
335 return -1;
336 }
337
338 key = ieee802_1x_get_key(sta->eapol_sm, &keylen);
339 if (key == NULL) {
340 wpa_printf(MSG_DEBUG, "AUTH_GET_MSK: Key is null, eapol_sm: %p",
341 sta->eapol_sm);
342 return -1;
343 }
344
345 if (keylen > *len)
346 keylen = *len;
347 os_memcpy(msk, key, keylen);
348 *len = keylen;
349
350 return 0;
351 }
352
353
354 static int hostapd_wpa_auth_set_key(void *ctx, int vlan_id, enum wpa_alg alg,
355 const u8 *addr, int idx, u8 *key,
356 size_t key_len)
357 {
358 struct hostapd_data *hapd = ctx;
359 const char *ifname = hapd->conf->iface;
360
361 if (vlan_id > 0) {
362 ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan, vlan_id);
363 if (ifname == NULL)
364 return -1;
365 }
366
367 #ifdef CONFIG_TESTING_OPTIONS
368 if (addr && !is_broadcast_ether_addr(addr)) {
369 struct sta_info *sta;
370
371 sta = ap_get_sta(hapd, addr);
372 if (sta) {
373 sta->last_tk_alg = alg;
374 sta->last_tk_key_idx = idx;
375 if (key)
376 os_memcpy(sta->last_tk, key, key_len);
377 sta->last_tk_len = key_len;
378 }
379 } else if (alg == WPA_ALG_IGTK ||
380 alg == WPA_ALG_BIP_GMAC_128 ||
381 alg == WPA_ALG_BIP_GMAC_256 ||
382 alg == WPA_ALG_BIP_CMAC_256) {
383 hapd->last_igtk_alg = alg;
384 hapd->last_igtk_key_idx = idx;
385 if (key)
386 os_memcpy(hapd->last_igtk, key, key_len);
387 hapd->last_igtk_len = key_len;
388 } else {
389 hapd->last_gtk_alg = alg;
390 hapd->last_gtk_key_idx = idx;
391 if (key)
392 os_memcpy(hapd->last_gtk, key, key_len);
393 hapd->last_gtk_len = key_len;
394 }
395 #endif /* CONFIG_TESTING_OPTIONS */
396 return hostapd_drv_set_key(ifname, hapd, alg, addr, idx, 1, NULL, 0,
397 key, key_len);
398 }
399
400
401 static int hostapd_wpa_auth_get_seqnum(void *ctx, const u8 *addr, int idx,
402 u8 *seq)
403 {
404 struct hostapd_data *hapd = ctx;
405 return hostapd_get_seqnum(hapd->conf->iface, hapd, addr, idx, seq);
406 }
407
408
409 static int hostapd_wpa_auth_send_eapol(void *ctx, const u8 *addr,
410 const u8 *data, size_t data_len,
411 int encrypt)
412 {
413 struct hostapd_data *hapd = ctx;
414 struct sta_info *sta;
415 u32 flags = 0;
416
417 #ifdef CONFIG_TESTING_OPTIONS
418 if (hapd->ext_eapol_frame_io) {
419 size_t hex_len = 2 * data_len + 1;
420 char *hex = os_malloc(hex_len);
421
422 if (hex == NULL)
423 return -1;
424 wpa_snprintf_hex(hex, hex_len, data, data_len);
425 wpa_msg(hapd->msg_ctx, MSG_INFO, "EAPOL-TX " MACSTR " %s",
426 MAC2STR(addr), hex);
427 os_free(hex);
428 return 0;
429 }
430 #endif /* CONFIG_TESTING_OPTIONS */
431
432 sta = ap_get_sta(hapd, addr);
433 if (sta)
434 flags = hostapd_sta_flags_to_drv(sta->flags);
435
436 return hostapd_drv_hapd_send_eapol(hapd, addr, data, data_len,
437 encrypt, flags);
438 }
439
440
441 static int hostapd_wpa_auth_for_each_sta(
442 void *ctx, int (*cb)(struct wpa_state_machine *sm, void *ctx),
443 void *cb_ctx)
444 {
445 struct hostapd_data *hapd = ctx;
446 struct sta_info *sta;
447
448 for (sta = hapd->sta_list; sta; sta = sta->next) {
449 if (sta->wpa_sm && cb(sta->wpa_sm, cb_ctx))
450 return 1;
451 }
452 return 0;
453 }
454
455
456 struct wpa_auth_iface_iter_data {
457 int (*cb)(struct wpa_authenticator *sm, void *ctx);
458 void *cb_ctx;
459 };
460
461 static int wpa_auth_iface_iter(struct hostapd_iface *iface, void *ctx)
462 {
463 struct wpa_auth_iface_iter_data *data = ctx;
464 size_t i;
465 for (i = 0; i < iface->num_bss; i++) {
466 if (iface->bss[i]->wpa_auth &&
467 data->cb(iface->bss[i]->wpa_auth, data->cb_ctx))
468 return 1;
469 }
470 return 0;
471 }
472
473
474 static int hostapd_wpa_auth_for_each_auth(
475 void *ctx, int (*cb)(struct wpa_authenticator *sm, void *ctx),
476 void *cb_ctx)
477 {
478 struct hostapd_data *hapd = ctx;
479 struct wpa_auth_iface_iter_data data;
480 if (hapd->iface->interfaces == NULL ||
481 hapd->iface->interfaces->for_each_interface == NULL)
482 return -1;
483 data.cb = cb;
484 data.cb_ctx = cb_ctx;
485 return hapd->iface->interfaces->for_each_interface(
486 hapd->iface->interfaces, wpa_auth_iface_iter, &data);
487 }
488
489
490 #ifdef CONFIG_IEEE80211R_AP
491
492 struct wpa_ft_rrb_rx_later_data {
493 struct dl_list list;
494 u8 addr[ETH_ALEN];
495 size_t data_len;
496 /* followed by data_len octets of data */
497 };
498
499 static void hostapd_wpa_ft_rrb_rx_later(void *eloop_ctx, void *timeout_ctx)
500 {
501 struct hostapd_data *hapd = eloop_ctx;
502 struct wpa_ft_rrb_rx_later_data *data, *n;
503
504 dl_list_for_each_safe(data, n, &hapd->l2_queue,
505 struct wpa_ft_rrb_rx_later_data, list) {
506 if (hapd->wpa_auth) {
507 wpa_ft_rrb_rx(hapd->wpa_auth, data->addr,
508 (const u8 *) (data + 1),
509 data->data_len);
510 }
511 dl_list_del(&data->list);
512 os_free(data);
513 }
514 }
515
516
517 struct wpa_auth_ft_iface_iter_data {
518 struct hostapd_data *src_hapd;
519 const u8 *dst;
520 const u8 *data;
521 size_t data_len;
522 };
523
524
525 static int hostapd_wpa_auth_ft_iter(struct hostapd_iface *iface, void *ctx)
526 {
527 struct wpa_auth_ft_iface_iter_data *idata = ctx;
528 struct wpa_ft_rrb_rx_later_data *data;
529 struct hostapd_data *hapd;
530 size_t j;
531
532 for (j = 0; j < iface->num_bss; j++) {
533 hapd = iface->bss[j];
534 if (hapd == idata->src_hapd ||
535 !hapd->wpa_auth ||
536 os_memcmp(hapd->own_addr, idata->dst, ETH_ALEN) != 0)
537 continue;
538
539 wpa_printf(MSG_DEBUG,
540 "FT: Send RRB data directly to locally managed BSS "
541 MACSTR "@%s -> " MACSTR "@%s",
542 MAC2STR(idata->src_hapd->own_addr),
543 idata->src_hapd->conf->iface,
544 MAC2STR(hapd->own_addr), hapd->conf->iface);
545
546 /* Defer wpa_ft_rrb_rx() until next eloop step as this is
547 * when it would be triggered when reading from a socket.
548 * This avoids
549 * hapd0:send -> hapd1:recv -> hapd1:send -> hapd0:recv,
550 * that is calling hapd0:recv handler from within
551 * hapd0:send directly.
552 */
553 data = os_zalloc(sizeof(*data) + idata->data_len);
554 if (!data)
555 return 1;
556
557 os_memcpy(data->addr, idata->src_hapd->own_addr, ETH_ALEN);
558 os_memcpy(data + 1, idata->data, idata->data_len);
559 data->data_len = idata->data_len;
560
561 dl_list_add(&hapd->l2_queue, &data->list);
562
563 if (!eloop_is_timeout_registered(hostapd_wpa_ft_rrb_rx_later,
564 hapd, NULL))
565 eloop_register_timeout(0, 0,
566 hostapd_wpa_ft_rrb_rx_later,
567 hapd, NULL);
568
569 return 1;
570 }
571
572 return 0;
573 }
574
575 #endif /* CONFIG_IEEE80211R_AP */
576
577
578 static int hostapd_wpa_auth_send_ether(void *ctx, const u8 *dst, u16 proto,
579 const u8 *data, size_t data_len)
580 {
581 struct hostapd_data *hapd = ctx;
582 struct l2_ethhdr *buf;
583 int ret;
584
585 #ifdef CONFIG_TESTING_OPTIONS
586 if (hapd->ext_eapol_frame_io && proto == ETH_P_EAPOL) {
587 size_t hex_len = 2 * data_len + 1;
588 char *hex = os_malloc(hex_len);
589
590 if (hex == NULL)
591 return -1;
592 wpa_snprintf_hex(hex, hex_len, data, data_len);
593 wpa_msg(hapd->msg_ctx, MSG_INFO, "EAPOL-TX " MACSTR " %s",
594 MAC2STR(dst), hex);
595 os_free(hex);
596 return 0;
597 }
598 #endif /* CONFIG_TESTING_OPTIONS */
599
600 #ifdef CONFIG_IEEE80211R_AP
601 if (proto == ETH_P_RRB && hapd->iface->interfaces &&
602 hapd->iface->interfaces->for_each_interface) {
603 int res;
604 struct wpa_auth_ft_iface_iter_data idata;
605 idata.src_hapd = hapd;
606 idata.dst = dst;
607 idata.data = data;
608 idata.data_len = data_len;
609 res = hapd->iface->interfaces->for_each_interface(
610 hapd->iface->interfaces, hostapd_wpa_auth_ft_iter,
611 &idata);
612 if (res == 1)
613 return data_len;
614 }
615 #endif /* CONFIG_IEEE80211R_AP */
616
617 if (hapd->driver && hapd->driver->send_ether)
618 return hapd->driver->send_ether(hapd->drv_priv, dst,
619 hapd->own_addr, proto,
620 data, data_len);
621 if (hapd->l2 == NULL)
622 return -1;
623
624 buf = os_malloc(sizeof(*buf) + data_len);
625 if (buf == NULL)
626 return -1;
627 os_memcpy(buf->h_dest, dst, ETH_ALEN);
628 os_memcpy(buf->h_source, hapd->own_addr, ETH_ALEN);
629 buf->h_proto = host_to_be16(proto);
630 os_memcpy(buf + 1, data, data_len);
631 ret = l2_packet_send(hapd->l2, dst, proto, (u8 *) buf,
632 sizeof(*buf) + data_len);
633 os_free(buf);
634 return ret;
635 }
636
637
638 #ifdef CONFIG_ETH_P_OUI
639 static struct eth_p_oui_ctx * hostapd_wpa_get_oui(struct hostapd_data *hapd,
640 u8 oui_suffix)
641 {
642 switch (oui_suffix) {
643 #ifdef CONFIG_IEEE80211R_AP
644 case FT_PACKET_R0KH_R1KH_PULL:
645 return hapd->oui_pull;
646 case FT_PACKET_R0KH_R1KH_RESP:
647 return hapd->oui_resp;
648 case FT_PACKET_R0KH_R1KH_PUSH:
649 return hapd->oui_push;
650 case FT_PACKET_R0KH_R1KH_SEQ_REQ:
651 return hapd->oui_sreq;
652 case FT_PACKET_R0KH_R1KH_SEQ_RESP:
653 return hapd->oui_sresp;
654 #endif /* CONFIG_IEEE80211R_AP */
655 default:
656 return NULL;
657 }
658 }
659 #endif /* CONFIG_ETH_P_OUI */
660
661
662 #ifdef CONFIG_IEEE80211R_AP
663
664 struct oui_deliver_later_data {
665 struct dl_list list;
666 u8 src_addr[ETH_ALEN];
667 u8 dst_addr[ETH_ALEN];
668 size_t data_len;
669 u8 oui_suffix;
670 /* followed by data_len octets of data */
671 };
672
673 static void hostapd_oui_deliver_later(void *eloop_ctx, void *timeout_ctx)
674 {
675 struct hostapd_data *hapd = eloop_ctx;
676 struct oui_deliver_later_data *data, *n;
677 struct eth_p_oui_ctx *oui_ctx;
678
679 dl_list_for_each_safe(data, n, &hapd->l2_oui_queue,
680 struct oui_deliver_later_data, list) {
681 oui_ctx = hostapd_wpa_get_oui(hapd, data->oui_suffix);
682 if (hapd->wpa_auth && oui_ctx) {
683 eth_p_oui_deliver(oui_ctx, data->src_addr,
684 data->dst_addr,
685 (const u8 *) (data + 1),
686 data->data_len);
687 }
688 dl_list_del(&data->list);
689 os_free(data);
690 }
691 }
692
693
694 struct wpa_auth_oui_iface_iter_data {
695 struct hostapd_data *src_hapd;
696 const u8 *dst_addr;
697 const u8 *data;
698 size_t data_len;
699 u8 oui_suffix;
700 };
701
702 static int hostapd_wpa_auth_oui_iter(struct hostapd_iface *iface, void *ctx)
703 {
704 struct wpa_auth_oui_iface_iter_data *idata = ctx;
705 struct oui_deliver_later_data *data;
706 struct hostapd_data *hapd;
707 size_t j;
708
709 for (j = 0; j < iface->num_bss; j++) {
710 hapd = iface->bss[j];
711 if (hapd == idata->src_hapd)
712 continue;
713 if (!is_multicast_ether_addr(idata->dst_addr) &&
714 os_memcmp(hapd->own_addr, idata->dst_addr, ETH_ALEN) != 0)
715 continue;
716
717 /* defer eth_p_oui_deliver until next eloop step as this is
718 * when it would be triggerd from reading from sock
719 * This avoids
720 * hapd0:send -> hapd1:recv -> hapd1:send -> hapd0:recv,
721 * that is calling hapd0:recv handler from within
722 * hapd0:send directly.
723 */
724 data = os_zalloc(sizeof(*data) + idata->data_len);
725 if (!data)
726 return 1;
727
728 os_memcpy(data->src_addr, idata->src_hapd->own_addr, ETH_ALEN);
729 os_memcpy(data->dst_addr, idata->dst_addr, ETH_ALEN);
730 os_memcpy(data + 1, idata->data, idata->data_len);
731 data->data_len = idata->data_len;
732 data->oui_suffix = idata->oui_suffix;
733
734 dl_list_add(&hapd->l2_oui_queue, &data->list);
735
736 if (!eloop_is_timeout_registered(hostapd_oui_deliver_later,
737 hapd, NULL))
738 eloop_register_timeout(0, 0,
739 hostapd_oui_deliver_later,
740 hapd, NULL);
741
742 return 1;
743 }
744
745 return 0;
746 }
747
748 #endif /* CONFIG_IEEE80211R_AP */
749
750
751 static int hostapd_wpa_auth_send_oui(void *ctx, const u8 *dst, u8 oui_suffix,
752 const u8 *data, size_t data_len)
753 {
754 #ifdef CONFIG_ETH_P_OUI
755 struct hostapd_data *hapd = ctx;
756 struct eth_p_oui_ctx *oui_ctx;
757
758 #ifdef CONFIG_IEEE80211R_AP
759 if (hapd->iface->interfaces &&
760 hapd->iface->interfaces->for_each_interface) {
761 struct wpa_auth_oui_iface_iter_data idata;
762 int res;
763
764 idata.src_hapd = hapd;
765 idata.dst_addr = dst;
766 idata.data = data;
767 idata.data_len = data_len;
768 idata.oui_suffix = oui_suffix;
769 res = hapd->iface->interfaces->for_each_interface(
770 hapd->iface->interfaces, hostapd_wpa_auth_oui_iter,
771 &idata);
772 if (res == 1)
773 return data_len;
774 }
775 #endif /* CONFIG_IEEE80211R_AP */
776
777 oui_ctx = hostapd_wpa_get_oui(hapd, oui_suffix);
778 if (!oui_ctx)
779 return -1;
780
781 return eth_p_oui_send(oui_ctx, hapd->own_addr, dst, data, data_len);
782 #else /* CONFIG_ETH_P_OUI */
783 return -1;
784 #endif /* CONFIG_ETH_P_OUI */
785 }
786
787
788 static int hostapd_channel_info(void *ctx, struct wpa_channel_info *ci)
789 {
790 struct hostapd_data *hapd = ctx;
791
792 return hostapd_drv_channel_info(hapd, ci);
793 }
794
795
796 static int hostapd_wpa_auth_update_vlan(void *ctx, const u8 *addr, int vlan_id)
797 {
798 #ifndef CONFIG_NO_VLAN
799 struct hostapd_data *hapd = ctx;
800 struct sta_info *sta;
801 struct vlan_description vlan_desc;
802
803 sta = ap_get_sta(hapd, addr);
804 if (!sta)
805 return -1;
806
807 os_memset(&vlan_desc, 0, sizeof(vlan_desc));
808 vlan_desc.notempty = 1;
809 vlan_desc.untagged = vlan_id;
810 if (!hostapd_vlan_valid(hapd->conf->vlan, &vlan_desc)) {
811 wpa_printf(MSG_INFO, "Invalid VLAN ID %d in wpa_psk_file",
812 vlan_id);
813 return -1;
814 }
815
816 if (ap_sta_set_vlan(hapd, sta, &vlan_desc) < 0) {
817 wpa_printf(MSG_INFO,
818 "Failed to assign VLAN ID %d from wpa_psk_file to "
819 MACSTR, vlan_id, MAC2STR(sta->addr));
820 return -1;
821 }
822
823 wpa_printf(MSG_INFO,
824 "Assigned VLAN ID %d from wpa_psk_file to " MACSTR,
825 vlan_id, MAC2STR(sta->addr));
826 if ((sta->flags & WLAN_STA_ASSOC) &&
827 ap_sta_bind_vlan(hapd, sta) < 0)
828 return -1;
829 #endif /* CONFIG_NO_VLAN */
830
831 return 0;
832 }
833
834
835 #ifdef CONFIG_OCV
836 static int hostapd_get_sta_tx_params(void *ctx, const u8 *addr,
837 int ap_max_chanwidth, int ap_seg1_idx,
838 int *bandwidth, int *seg1_idx)
839 {
840 struct hostapd_data *hapd = ctx;
841 struct sta_info *sta;
842
843 sta = ap_get_sta(hapd, addr);
844 if (!sta) {
845 hostapd_wpa_auth_logger(hapd, addr, LOGGER_INFO,
846 "Failed to get STA info to validate received OCI");
847 return -1;
848 }
849
850 return get_tx_parameters(sta, ap_max_chanwidth, ap_seg1_idx, bandwidth,
851 seg1_idx);
852 }
853 #endif /* CONFIG_OCV */
854
855
856 #ifdef CONFIG_IEEE80211R_AP
857
858 static int hostapd_wpa_auth_send_ft_action(void *ctx, const u8 *dst,
859 const u8 *data, size_t data_len)
860 {
861 struct hostapd_data *hapd = ctx;
862 int res;
863 struct ieee80211_mgmt *m;
864 size_t mlen;
865 struct sta_info *sta;
866
867 sta = ap_get_sta(hapd, dst);
868 if (sta == NULL || sta->wpa_sm == NULL)
869 return -1;
870
871 m = os_zalloc(sizeof(*m) + data_len);
872 if (m == NULL)
873 return -1;
874 mlen = ((u8 *) &m->u - (u8 *) m) + data_len;
875 m->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
876 WLAN_FC_STYPE_ACTION);
877 os_memcpy(m->da, dst, ETH_ALEN);
878 os_memcpy(m->sa, hapd->own_addr, ETH_ALEN);
879 os_memcpy(m->bssid, hapd->own_addr, ETH_ALEN);
880 os_memcpy(&m->u, data, data_len);
881
882 res = hostapd_drv_send_mlme(hapd, (u8 *) m, mlen, 0);
883 os_free(m);
884 return res;
885 }
886
887
888 static struct wpa_state_machine *
889 hostapd_wpa_auth_add_sta(void *ctx, const u8 *sta_addr)
890 {
891 struct hostapd_data *hapd = ctx;
892 struct sta_info *sta;
893
894 wpa_printf(MSG_DEBUG, "Add station entry for " MACSTR
895 " based on WPA authenticator callback",
896 MAC2STR(sta_addr));
897 if (hostapd_add_sta_node(hapd, sta_addr, WLAN_AUTH_FT) < 0)
898 return NULL;
899
900 sta = ap_sta_add(hapd, sta_addr);
901 if (sta == NULL)
902 return NULL;
903 if (hapd->driver && hapd->driver->add_sta_node)
904 sta->added_unassoc = 1;
905 sta->ft_over_ds = 1;
906 if (sta->wpa_sm) {
907 sta->auth_alg = WLAN_AUTH_FT;
908 return sta->wpa_sm;
909 }
910
911 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, sta->addr, NULL);
912 if (sta->wpa_sm == NULL) {
913 ap_free_sta(hapd, sta);
914 return NULL;
915 }
916 sta->auth_alg = WLAN_AUTH_FT;
917
918 return sta->wpa_sm;
919 }
920
921
922 static int hostapd_wpa_auth_set_vlan(void *ctx, const u8 *sta_addr,
923 struct vlan_description *vlan)
924 {
925 struct hostapd_data *hapd = ctx;
926 struct sta_info *sta;
927
928 sta = ap_get_sta(hapd, sta_addr);
929 if (!sta || !sta->wpa_sm)
930 return -1;
931
932 if (vlan->notempty &&
933 !hostapd_vlan_valid(hapd->conf->vlan, vlan)) {
934 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
935 HOSTAPD_LEVEL_INFO,
936 "Invalid VLAN %d%s received from FT",
937 vlan->untagged, vlan->tagged[0] ? "+" : "");
938 return -1;
939 }
940
941 if (ap_sta_set_vlan(hapd, sta, vlan) < 0)
942 return -1;
943 /* Configure wpa_group for GTK but ignore error due to driver not
944 * knowing this STA. */
945 ap_sta_bind_vlan(hapd, sta);
946
947 if (sta->vlan_id)
948 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
949 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
950
951 return 0;
952 }
953
954
955 static int hostapd_wpa_auth_get_vlan(void *ctx, const u8 *sta_addr,
956 struct vlan_description *vlan)
957 {
958 struct hostapd_data *hapd = ctx;
959 struct sta_info *sta;
960
961 sta = ap_get_sta(hapd, sta_addr);
962 if (!sta)
963 return -1;
964
965 if (sta->vlan_desc)
966 *vlan = *sta->vlan_desc;
967 else
968 os_memset(vlan, 0, sizeof(*vlan));
969
970 return 0;
971 }
972
973
974 static int
975 hostapd_wpa_auth_set_identity(void *ctx, const u8 *sta_addr,
976 const u8 *identity, size_t identity_len)
977 {
978 struct hostapd_data *hapd = ctx;
979 struct sta_info *sta;
980
981 sta = ap_get_sta(hapd, sta_addr);
982 if (!sta)
983 return -1;
984
985 os_free(sta->identity);
986 sta->identity = NULL;
987
988 if (sta->eapol_sm) {
989 os_free(sta->eapol_sm->identity);
990 sta->eapol_sm->identity = NULL;
991 sta->eapol_sm->identity_len = 0;
992 }
993
994 if (!identity_len)
995 return 0;
996
997 /* sta->identity is NULL terminated */
998 sta->identity = os_zalloc(identity_len + 1);
999 if (!sta->identity)
1000 return -1;
1001 os_memcpy(sta->identity, identity, identity_len);
1002
1003 if (sta->eapol_sm) {
1004 sta->eapol_sm->identity = os_zalloc(identity_len);
1005 if (!sta->eapol_sm->identity)
1006 return -1;
1007 os_memcpy(sta->eapol_sm->identity, identity, identity_len);
1008 sta->eapol_sm->identity_len = identity_len;
1009 }
1010
1011 return 0;
1012 }
1013
1014
1015 static size_t
1016 hostapd_wpa_auth_get_identity(void *ctx, const u8 *sta_addr, const u8 **buf)
1017 {
1018 struct hostapd_data *hapd = ctx;
1019 struct sta_info *sta;
1020 size_t len;
1021 char *identity;
1022
1023 sta = ap_get_sta(hapd, sta_addr);
1024 if (!sta)
1025 return 0;
1026
1027 *buf = ieee802_1x_get_identity(sta->eapol_sm, &len);
1028 if (*buf && len)
1029 return len;
1030
1031 if (!sta->identity) {
1032 *buf = NULL;
1033 return 0;
1034 }
1035
1036 identity = sta->identity;
1037 len = os_strlen(identity);
1038 *buf = (u8 *) identity;
1039
1040 return len;
1041 }
1042
1043
1044 static int
1045 hostapd_wpa_auth_set_radius_cui(void *ctx, const u8 *sta_addr,
1046 const u8 *radius_cui, size_t radius_cui_len)
1047 {
1048 struct hostapd_data *hapd = ctx;
1049 struct sta_info *sta;
1050
1051 sta = ap_get_sta(hapd, sta_addr);
1052 if (!sta)
1053 return -1;
1054
1055 os_free(sta->radius_cui);
1056 sta->radius_cui = NULL;
1057
1058 if (sta->eapol_sm) {
1059 wpabuf_free(sta->eapol_sm->radius_cui);
1060 sta->eapol_sm->radius_cui = NULL;
1061 }
1062
1063 if (!radius_cui)
1064 return 0;
1065
1066 /* sta->radius_cui is NULL terminated */
1067 sta->radius_cui = os_zalloc(radius_cui_len + 1);
1068 if (!sta->radius_cui)
1069 return -1;
1070 os_memcpy(sta->radius_cui, radius_cui, radius_cui_len);
1071
1072 if (sta->eapol_sm) {
1073 sta->eapol_sm->radius_cui = wpabuf_alloc_copy(radius_cui,
1074 radius_cui_len);
1075 if (!sta->eapol_sm->radius_cui)
1076 return -1;
1077 }
1078
1079 return 0;
1080 }
1081
1082
1083 static size_t
1084 hostapd_wpa_auth_get_radius_cui(void *ctx, const u8 *sta_addr, const u8 **buf)
1085 {
1086 struct hostapd_data *hapd = ctx;
1087 struct sta_info *sta;
1088 struct wpabuf *b;
1089 size_t len;
1090 char *radius_cui;
1091
1092 sta = ap_get_sta(hapd, sta_addr);
1093 if (!sta)
1094 return 0;
1095
1096 b = ieee802_1x_get_radius_cui(sta->eapol_sm);
1097 if (b) {
1098 len = wpabuf_len(b);
1099 *buf = wpabuf_head(b);
1100 return len;
1101 }
1102
1103 if (!sta->radius_cui) {
1104 *buf = NULL;
1105 return 0;
1106 }
1107
1108 radius_cui = sta->radius_cui;
1109 len = os_strlen(radius_cui);
1110 *buf = (u8 *) radius_cui;
1111
1112 return len;
1113 }
1114
1115
1116 static void hostapd_wpa_auth_set_session_timeout(void *ctx, const u8 *sta_addr,
1117 int session_timeout)
1118 {
1119 struct hostapd_data *hapd = ctx;
1120 struct sta_info *sta;
1121
1122 sta = ap_get_sta(hapd, sta_addr);
1123 if (!sta)
1124 return;
1125
1126 if (session_timeout) {
1127 os_get_reltime(&sta->session_timeout);
1128 sta->session_timeout.sec += session_timeout;
1129 sta->session_timeout_set = 1;
1130 ap_sta_session_timeout(hapd, sta, session_timeout);
1131 } else {
1132 sta->session_timeout_set = 0;
1133 ap_sta_no_session_timeout(hapd, sta);
1134 }
1135 }
1136
1137
1138 static int hostapd_wpa_auth_get_session_timeout(void *ctx, const u8 *sta_addr)
1139 {
1140 struct hostapd_data *hapd = ctx;
1141 struct sta_info *sta;
1142 struct os_reltime now, remaining;
1143
1144 sta = ap_get_sta(hapd, sta_addr);
1145 if (!sta || !sta->session_timeout_set)
1146 return 0;
1147
1148 os_get_reltime(&now);
1149 if (os_reltime_before(&sta->session_timeout, &now)) {
1150 /* already expired, return >0 as timeout was set */
1151 return 1;
1152 }
1153
1154 os_reltime_sub(&sta->session_timeout, &now, &remaining);
1155
1156 return (remaining.sec > 0) ? remaining.sec : 1;
1157 }
1158
1159
1160 static void hostapd_rrb_receive(void *ctx, const u8 *src_addr, const u8 *buf,
1161 size_t len)
1162 {
1163 struct hostapd_data *hapd = ctx;
1164 struct l2_ethhdr *ethhdr;
1165 if (len < sizeof(*ethhdr))
1166 return;
1167 ethhdr = (struct l2_ethhdr *) buf;
1168 wpa_printf(MSG_DEBUG, "FT: RRB received packet " MACSTR " -> "
1169 MACSTR, MAC2STR(ethhdr->h_source), MAC2STR(ethhdr->h_dest));
1170 if (!is_multicast_ether_addr(ethhdr->h_dest) &&
1171 os_memcmp(hapd->own_addr, ethhdr->h_dest, ETH_ALEN) != 0)
1172 return;
1173 wpa_ft_rrb_rx(hapd->wpa_auth, ethhdr->h_source, buf + sizeof(*ethhdr),
1174 len - sizeof(*ethhdr));
1175 }
1176
1177
1178 static void hostapd_rrb_oui_receive(void *ctx, const u8 *src_addr,
1179 const u8 *dst_addr, u8 oui_suffix,
1180 const u8 *buf, size_t len)
1181 {
1182 struct hostapd_data *hapd = ctx;
1183
1184 wpa_printf(MSG_DEBUG, "FT: RRB received packet " MACSTR " -> "
1185 MACSTR, MAC2STR(src_addr), MAC2STR(dst_addr));
1186 if (!is_multicast_ether_addr(dst_addr) &&
1187 os_memcmp(hapd->own_addr, dst_addr, ETH_ALEN) != 0)
1188 return;
1189 wpa_ft_rrb_oui_rx(hapd->wpa_auth, src_addr, dst_addr, oui_suffix, buf,
1190 len);
1191 }
1192
1193
1194 static int hostapd_wpa_auth_add_tspec(void *ctx, const u8 *sta_addr,
1195 u8 *tspec_ie, size_t tspec_ielen)
1196 {
1197 struct hostapd_data *hapd = ctx;
1198 return hostapd_add_tspec(hapd, sta_addr, tspec_ie, tspec_ielen);
1199 }
1200
1201
1202
1203 static int hostapd_wpa_register_ft_oui(struct hostapd_data *hapd,
1204 const char *ft_iface)
1205 {
1206 hapd->oui_pull = eth_p_oui_register(hapd, ft_iface,
1207 FT_PACKET_R0KH_R1KH_PULL,
1208 hostapd_rrb_oui_receive, hapd);
1209 if (!hapd->oui_pull)
1210 return -1;
1211
1212 hapd->oui_resp = eth_p_oui_register(hapd, ft_iface,
1213 FT_PACKET_R0KH_R1KH_RESP,
1214 hostapd_rrb_oui_receive, hapd);
1215 if (!hapd->oui_resp)
1216 return -1;
1217
1218 hapd->oui_push = eth_p_oui_register(hapd, ft_iface,
1219 FT_PACKET_R0KH_R1KH_PUSH,
1220 hostapd_rrb_oui_receive, hapd);
1221 if (!hapd->oui_push)
1222 return -1;
1223
1224 hapd->oui_sreq = eth_p_oui_register(hapd, ft_iface,
1225 FT_PACKET_R0KH_R1KH_SEQ_REQ,
1226 hostapd_rrb_oui_receive, hapd);
1227 if (!hapd->oui_sreq)
1228 return -1;
1229
1230 hapd->oui_sresp = eth_p_oui_register(hapd, ft_iface,
1231 FT_PACKET_R0KH_R1KH_SEQ_RESP,
1232 hostapd_rrb_oui_receive, hapd);
1233 if (!hapd->oui_sresp)
1234 return -1;
1235
1236 return 0;
1237 }
1238
1239
1240 static void hostapd_wpa_unregister_ft_oui(struct hostapd_data *hapd)
1241 {
1242 eth_p_oui_unregister(hapd->oui_pull);
1243 hapd->oui_pull = NULL;
1244 eth_p_oui_unregister(hapd->oui_resp);
1245 hapd->oui_resp = NULL;
1246 eth_p_oui_unregister(hapd->oui_push);
1247 hapd->oui_push = NULL;
1248 eth_p_oui_unregister(hapd->oui_sreq);
1249 hapd->oui_sreq = NULL;
1250 eth_p_oui_unregister(hapd->oui_sresp);
1251 hapd->oui_sresp = NULL;
1252 }
1253 #endif /* CONFIG_IEEE80211R_AP */
1254
1255
1256 int hostapd_setup_wpa(struct hostapd_data *hapd)
1257 {
1258 struct wpa_auth_config _conf;
1259 static const struct wpa_auth_callbacks cb = {
1260 .logger = hostapd_wpa_auth_logger,
1261 .disconnect = hostapd_wpa_auth_disconnect,
1262 .mic_failure_report = hostapd_wpa_auth_mic_failure_report,
1263 .psk_failure_report = hostapd_wpa_auth_psk_failure_report,
1264 .set_eapol = hostapd_wpa_auth_set_eapol,
1265 .get_eapol = hostapd_wpa_auth_get_eapol,
1266 .get_psk = hostapd_wpa_auth_get_psk,
1267 .get_msk = hostapd_wpa_auth_get_msk,
1268 .set_key = hostapd_wpa_auth_set_key,
1269 .get_seqnum = hostapd_wpa_auth_get_seqnum,
1270 .send_eapol = hostapd_wpa_auth_send_eapol,
1271 .for_each_sta = hostapd_wpa_auth_for_each_sta,
1272 .for_each_auth = hostapd_wpa_auth_for_each_auth,
1273 .send_ether = hostapd_wpa_auth_send_ether,
1274 .send_oui = hostapd_wpa_auth_send_oui,
1275 .channel_info = hostapd_channel_info,
1276 .update_vlan = hostapd_wpa_auth_update_vlan,
1277 #ifdef CONFIG_OCV
1278 .get_sta_tx_params = hostapd_get_sta_tx_params,
1279 #endif /* CONFIG_OCV */
1280 #ifdef CONFIG_IEEE80211R_AP
1281 .send_ft_action = hostapd_wpa_auth_send_ft_action,
1282 .add_sta = hostapd_wpa_auth_add_sta,
1283 .add_tspec = hostapd_wpa_auth_add_tspec,
1284 .set_vlan = hostapd_wpa_auth_set_vlan,
1285 .get_vlan = hostapd_wpa_auth_get_vlan,
1286 .set_identity = hostapd_wpa_auth_set_identity,
1287 .get_identity = hostapd_wpa_auth_get_identity,
1288 .set_radius_cui = hostapd_wpa_auth_set_radius_cui,
1289 .get_radius_cui = hostapd_wpa_auth_get_radius_cui,
1290 .set_session_timeout = hostapd_wpa_auth_set_session_timeout,
1291 .get_session_timeout = hostapd_wpa_auth_get_session_timeout,
1292 #endif /* CONFIG_IEEE80211R_AP */
1293 };
1294 const u8 *wpa_ie;
1295 size_t wpa_ie_len;
1296
1297 hostapd_wpa_auth_conf(hapd->conf, hapd->iconf, &_conf);
1298 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_EAPOL_TX_STATUS)
1299 _conf.tx_status = 1;
1300 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_MLME)
1301 _conf.ap_mlme = 1;
1302 hapd->wpa_auth = wpa_init(hapd->own_addr, &_conf, &cb, hapd);
1303 if (hapd->wpa_auth == NULL) {
1304 wpa_printf(MSG_ERROR, "WPA initialization failed.");
1305 return -1;
1306 }
1307
1308 if (hostapd_set_privacy(hapd, 1)) {
1309 wpa_printf(MSG_ERROR, "Could not set PrivacyInvoked "
1310 "for interface %s", hapd->conf->iface);
1311 return -1;
1312 }
1313
1314 wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
1315 if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len)) {
1316 wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
1317 "the kernel driver.");
1318 return -1;
1319 }
1320
1321 if (rsn_preauth_iface_init(hapd)) {
1322 wpa_printf(MSG_ERROR, "Initialization of RSN "
1323 "pre-authentication failed.");
1324 return -1;
1325 }
1326
1327 #ifdef CONFIG_IEEE80211R_AP
1328 if (!hostapd_drv_none(hapd) &&
1329 wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt)) {
1330 const char *ft_iface;
1331
1332 ft_iface = hapd->conf->bridge[0] ? hapd->conf->bridge :
1333 hapd->conf->iface;
1334 hapd->l2 = l2_packet_init(ft_iface, NULL, ETH_P_RRB,
1335 hostapd_rrb_receive, hapd, 1);
1336 if (hapd->l2 == NULL &&
1337 (hapd->driver == NULL ||
1338 hapd->driver->send_ether == NULL)) {
1339 wpa_printf(MSG_ERROR, "Failed to open l2_packet "
1340 "interface");
1341 return -1;
1342 }
1343
1344 if (hostapd_wpa_register_ft_oui(hapd, ft_iface)) {
1345 wpa_printf(MSG_ERROR,
1346 "Failed to open ETH_P_OUI interface");
1347 return -1;
1348 }
1349 }
1350 #endif /* CONFIG_IEEE80211R_AP */
1351
1352 return 0;
1353
1354 }
1355
1356
1357 void hostapd_reconfig_wpa(struct hostapd_data *hapd)
1358 {
1359 struct wpa_auth_config wpa_auth_conf;
1360 hostapd_wpa_auth_conf(hapd->conf, hapd->iconf, &wpa_auth_conf);
1361 wpa_reconfig(hapd->wpa_auth, &wpa_auth_conf);
1362 }
1363
1364
1365 void hostapd_deinit_wpa(struct hostapd_data *hapd)
1366 {
1367 ieee80211_tkip_countermeasures_deinit(hapd);
1368 rsn_preauth_iface_deinit(hapd);
1369 if (hapd->wpa_auth) {
1370 wpa_deinit(hapd->wpa_auth);
1371 hapd->wpa_auth = NULL;
1372
1373 if (hapd->drv_priv && hostapd_set_privacy(hapd, 0)) {
1374 wpa_printf(MSG_DEBUG, "Could not disable "
1375 "PrivacyInvoked for interface %s",
1376 hapd->conf->iface);
1377 }
1378
1379 if (hapd->drv_priv &&
1380 hostapd_set_generic_elem(hapd, (u8 *) "", 0)) {
1381 wpa_printf(MSG_DEBUG, "Could not remove generic "
1382 "information element from interface %s",
1383 hapd->conf->iface);
1384 }
1385 }
1386 ieee802_1x_deinit(hapd);
1387
1388 #ifdef CONFIG_IEEE80211R_AP
1389 eloop_cancel_timeout(hostapd_wpa_ft_rrb_rx_later, hapd, ELOOP_ALL_CTX);
1390 hostapd_wpa_ft_rrb_rx_later(hapd, NULL); /* flush without delivering */
1391 eloop_cancel_timeout(hostapd_oui_deliver_later, hapd, ELOOP_ALL_CTX);
1392 hostapd_oui_deliver_later(hapd, NULL); /* flush without delivering */
1393 l2_packet_deinit(hapd->l2);
1394 hapd->l2 = NULL;
1395 hostapd_wpa_unregister_ft_oui(hapd);
1396 #endif /* CONFIG_IEEE80211R_AP */
1397 }