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