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