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