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