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