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 "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" 18 #include "hostapd.h" 19 #include "ieee802_1x.h" 20 #include "preauth_auth.h" 21 #include "sta_info.h" 22 #include "tkip_countermeasures.h" 23 #include "ap_drv_ops.h" 24 #include "ap_config.h" 25 #include "wpa_auth.h" 26 #include "wpa_auth_glue.h" 27 28 29 static void hostapd_wpa_auth_conf(struct hostapd_bss_config *conf, 30 struct hostapd_config *iconf, 31 struct wpa_auth_config *wconf) 32 { 33 os_memset(wconf, 0, sizeof(*wconf)); 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; 47 wconf->wmm_uapsd = conf->wmm_uapsd; 48 wconf->disable_pmksa_caching = conf->disable_pmksa_caching; 49 wconf->okc = conf->okc; 50 #ifdef CONFIG_IEEE80211W 51 wconf->ieee80211w = conf->ieee80211w; 52 wconf->group_mgmt_cipher = conf->group_mgmt_cipher; 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; 73 wconf->ft_over_ds = conf->ft_over_ds; 74 #endif /* CONFIG_IEEE80211R */ 75 #ifdef CONFIG_HS20 76 wconf->disable_gtk = conf->disable_dgaf; 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 } 90 #endif /* CONFIG_HS20 */ 91 #ifdef CONFIG_TESTING_OPTIONS 92 wconf->corrupt_gtk_rekey_mic_probability = 93 iconf->corrupt_gtk_rekey_mic_probability; 94 #endif /* CONFIG_TESTING_OPTIONS */ 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 */ 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 140 static int hostapd_wpa_auth_mic_failure_report(void *ctx, const u8 *addr) 141 { 142 struct hostapd_data *hapd = ctx; 143 return michael_mic_failure(hapd, addr, 0); 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, 208 const u8 *p2p_dev_addr, 209 const u8 *prev_psk) 210 { 211 struct hostapd_data *hapd = ctx; 212 struct sta_info *sta = ap_get_sta(hapd, addr); 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 223 psk = hostapd_get_psk(hapd->conf, addr, p2p_dev_addr, prev_psk); 224 /* 225 * This is about to iterate over all psks, prev_psk gives the last 226 * returned psk which should not be returned again. 227 * logic list (all hostapd_get_psk; all sta->psk) 228 */ 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 } 239 return psk; 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 wpa_printf(MSG_DEBUG, "AUTH_GET_MSK: Cannot find STA"); 254 return -1; 255 } 256 257 key = ieee802_1x_get_key(sta->eapol_sm, &keylen); 258 if (key == NULL) { 259 wpa_printf(MSG_DEBUG, "AUTH_GET_MSK: Key is null, eapol_sm: %p", 260 sta->eapol_sm); 261 return -1; 262 } 263 264 if (keylen > *len) 265 keylen = *len; 266 os_memcpy(msk, key, keylen); 267 *len = keylen; 268 269 return 0; 270 } 271 272 273 static int hostapd_wpa_auth_set_key(void *ctx, int vlan_id, enum wpa_alg alg, 274 const u8 *addr, int idx, u8 *key, 275 size_t key_len) 276 { 277 struct hostapd_data *hapd = ctx; 278 const char *ifname = hapd->conf->iface; 279 280 if (vlan_id > 0) { 281 ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan, vlan_id); 282 if (ifname == NULL) 283 return -1; 284 } 285 286 return hostapd_drv_set_key(ifname, hapd, alg, addr, idx, 1, NULL, 0, 287 key, key_len); 288 } 289 290 291 static int hostapd_wpa_auth_get_seqnum(void *ctx, const u8 *addr, int idx, 292 u8 *seq) 293 { 294 struct hostapd_data *hapd = ctx; 295 return hostapd_get_seqnum(hapd->conf->iface, hapd, addr, idx, seq); 296 } 297 298 299 static int hostapd_wpa_auth_send_eapol(void *ctx, const u8 *addr, 300 const u8 *data, size_t data_len, 301 int encrypt) 302 { 303 struct hostapd_data *hapd = ctx; 304 struct sta_info *sta; 305 u32 flags = 0; 306 307 #ifdef CONFIG_TESTING_OPTIONS 308 if (hapd->ext_eapol_frame_io) { 309 size_t hex_len = 2 * data_len + 1; 310 char *hex = os_malloc(hex_len); 311 312 if (hex == NULL) 313 return -1; 314 wpa_snprintf_hex(hex, hex_len, data, data_len); 315 wpa_msg(hapd->msg_ctx, MSG_INFO, "EAPOL-TX " MACSTR " %s", 316 MAC2STR(addr), hex); 317 os_free(hex); 318 return 0; 319 } 320 #endif /* CONFIG_TESTING_OPTIONS */ 321 322 sta = ap_get_sta(hapd, addr); 323 if (sta) 324 flags = hostapd_sta_flags_to_drv(sta->flags); 325 326 return hostapd_drv_hapd_send_eapol(hapd, addr, data, data_len, 327 encrypt, flags); 328 } 329 330 331 static int hostapd_wpa_auth_for_each_sta( 332 void *ctx, int (*cb)(struct wpa_state_machine *sm, void *ctx), 333 void *cb_ctx) 334 { 335 struct hostapd_data *hapd = ctx; 336 struct sta_info *sta; 337 338 for (sta = hapd->sta_list; sta; sta = sta->next) { 339 if (sta->wpa_sm && cb(sta->wpa_sm, cb_ctx)) 340 return 1; 341 } 342 return 0; 343 } 344 345 346 struct wpa_auth_iface_iter_data { 347 int (*cb)(struct wpa_authenticator *sm, void *ctx); 348 void *cb_ctx; 349 }; 350 351 static int wpa_auth_iface_iter(struct hostapd_iface *iface, void *ctx) 352 { 353 struct wpa_auth_iface_iter_data *data = ctx; 354 size_t i; 355 for (i = 0; i < iface->num_bss; i++) { 356 if (iface->bss[i]->wpa_auth && 357 data->cb(iface->bss[i]->wpa_auth, data->cb_ctx)) 358 return 1; 359 } 360 return 0; 361 } 362 363 364 static int hostapd_wpa_auth_for_each_auth( 365 void *ctx, int (*cb)(struct wpa_authenticator *sm, void *ctx), 366 void *cb_ctx) 367 { 368 struct hostapd_data *hapd = ctx; 369 struct wpa_auth_iface_iter_data data; 370 if (hapd->iface->interfaces == NULL || 371 hapd->iface->interfaces->for_each_interface == NULL) 372 return -1; 373 data.cb = cb; 374 data.cb_ctx = cb_ctx; 375 return hapd->iface->interfaces->for_each_interface( 376 hapd->iface->interfaces, wpa_auth_iface_iter, &data); 377 } 378 379 380 #ifdef CONFIG_IEEE80211R 381 382 struct wpa_auth_ft_iface_iter_data { 383 struct hostapd_data *src_hapd; 384 const u8 *dst; 385 const u8 *data; 386 size_t data_len; 387 }; 388 389 390 static int hostapd_wpa_auth_ft_iter(struct hostapd_iface *iface, void *ctx) 391 { 392 struct wpa_auth_ft_iface_iter_data *idata = ctx; 393 struct hostapd_data *hapd; 394 size_t j; 395 396 for (j = 0; j < iface->num_bss; j++) { 397 hapd = iface->bss[j]; 398 if (hapd == idata->src_hapd) 399 continue; 400 if (os_memcmp(hapd->own_addr, idata->dst, ETH_ALEN) == 0) { 401 wpa_printf(MSG_DEBUG, "FT: Send RRB data directly to " 402 "locally managed BSS " MACSTR "@%s -> " 403 MACSTR "@%s", 404 MAC2STR(idata->src_hapd->own_addr), 405 idata->src_hapd->conf->iface, 406 MAC2STR(hapd->own_addr), hapd->conf->iface); 407 wpa_ft_rrb_rx(hapd->wpa_auth, 408 idata->src_hapd->own_addr, 409 idata->data, idata->data_len); 410 return 1; 411 } 412 } 413 414 return 0; 415 } 416 417 #endif /* CONFIG_IEEE80211R */ 418 419 420 static int hostapd_wpa_auth_send_ether(void *ctx, const u8 *dst, u16 proto, 421 const u8 *data, size_t data_len) 422 { 423 struct hostapd_data *hapd = ctx; 424 struct l2_ethhdr *buf; 425 int ret; 426 427 #ifdef CONFIG_TESTING_OPTIONS 428 if (hapd->ext_eapol_frame_io && proto == ETH_P_EAPOL) { 429 size_t hex_len = 2 * data_len + 1; 430 char *hex = os_malloc(hex_len); 431 432 if (hex == NULL) 433 return -1; 434 wpa_snprintf_hex(hex, hex_len, data, data_len); 435 wpa_msg(hapd->msg_ctx, MSG_INFO, "EAPOL-TX " MACSTR " %s", 436 MAC2STR(dst), hex); 437 os_free(hex); 438 return 0; 439 } 440 #endif /* CONFIG_TESTING_OPTIONS */ 441 442 #ifdef CONFIG_IEEE80211R 443 if (proto == ETH_P_RRB && hapd->iface->interfaces && 444 hapd->iface->interfaces->for_each_interface) { 445 int res; 446 struct wpa_auth_ft_iface_iter_data idata; 447 idata.src_hapd = hapd; 448 idata.dst = dst; 449 idata.data = data; 450 idata.data_len = data_len; 451 res = hapd->iface->interfaces->for_each_interface( 452 hapd->iface->interfaces, hostapd_wpa_auth_ft_iter, 453 &idata); 454 if (res == 1) 455 return data_len; 456 } 457 #endif /* CONFIG_IEEE80211R */ 458 459 if (hapd->driver && hapd->driver->send_ether) 460 return hapd->driver->send_ether(hapd->drv_priv, dst, 461 hapd->own_addr, proto, 462 data, data_len); 463 if (hapd->l2 == NULL) 464 return -1; 465 466 buf = os_malloc(sizeof(*buf) + data_len); 467 if (buf == NULL) 468 return -1; 469 os_memcpy(buf->h_dest, dst, ETH_ALEN); 470 os_memcpy(buf->h_source, hapd->own_addr, ETH_ALEN); 471 buf->h_proto = host_to_be16(proto); 472 os_memcpy(buf + 1, data, data_len); 473 ret = l2_packet_send(hapd->l2, dst, proto, (u8 *) buf, 474 sizeof(*buf) + data_len); 475 os_free(buf); 476 return ret; 477 } 478 479 480 #ifdef CONFIG_IEEE80211R 481 482 static int hostapd_wpa_auth_send_ft_action(void *ctx, const u8 *dst, 483 const u8 *data, size_t data_len) 484 { 485 struct hostapd_data *hapd = ctx; 486 int res; 487 struct ieee80211_mgmt *m; 488 size_t mlen; 489 struct sta_info *sta; 490 491 sta = ap_get_sta(hapd, dst); 492 if (sta == NULL || sta->wpa_sm == NULL) 493 return -1; 494 495 m = os_zalloc(sizeof(*m) + data_len); 496 if (m == NULL) 497 return -1; 498 mlen = ((u8 *) &m->u - (u8 *) m) + data_len; 499 m->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, 500 WLAN_FC_STYPE_ACTION); 501 os_memcpy(m->da, dst, ETH_ALEN); 502 os_memcpy(m->sa, hapd->own_addr, ETH_ALEN); 503 os_memcpy(m->bssid, hapd->own_addr, ETH_ALEN); 504 os_memcpy(&m->u, data, data_len); 505 506 res = hostapd_drv_send_mlme(hapd, (u8 *) m, mlen, 0); 507 os_free(m); 508 return res; 509 } 510 511 512 static struct wpa_state_machine * 513 hostapd_wpa_auth_add_sta(void *ctx, const u8 *sta_addr) 514 { 515 struct hostapd_data *hapd = ctx; 516 struct sta_info *sta; 517 518 if (hostapd_add_sta_node(hapd, sta_addr, WLAN_AUTH_FT) < 0) 519 return NULL; 520 521 sta = ap_sta_add(hapd, sta_addr); 522 if (sta == NULL) 523 return NULL; 524 if (sta->wpa_sm) { 525 sta->auth_alg = WLAN_AUTH_FT; 526 return sta->wpa_sm; 527 } 528 529 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, sta->addr, NULL); 530 if (sta->wpa_sm == NULL) { 531 ap_free_sta(hapd, sta); 532 return NULL; 533 } 534 sta->auth_alg = WLAN_AUTH_FT; 535 536 return sta->wpa_sm; 537 } 538 539 540 static void hostapd_rrb_receive(void *ctx, const u8 *src_addr, const u8 *buf, 541 size_t len) 542 { 543 struct hostapd_data *hapd = ctx; 544 struct l2_ethhdr *ethhdr; 545 if (len < sizeof(*ethhdr)) 546 return; 547 ethhdr = (struct l2_ethhdr *) buf; 548 wpa_printf(MSG_DEBUG, "FT: RRB received packet " MACSTR " -> " 549 MACSTR, MAC2STR(ethhdr->h_source), MAC2STR(ethhdr->h_dest)); 550 wpa_ft_rrb_rx(hapd->wpa_auth, ethhdr->h_source, buf + sizeof(*ethhdr), 551 len - sizeof(*ethhdr)); 552 } 553 554 555 static int hostapd_wpa_auth_add_tspec(void *ctx, const u8 *sta_addr, 556 u8 *tspec_ie, size_t tspec_ielen) 557 { 558 struct hostapd_data *hapd = ctx; 559 return hostapd_add_tspec(hapd, sta_addr, tspec_ie, tspec_ielen); 560 } 561 562 #endif /* CONFIG_IEEE80211R */ 563 564 565 int hostapd_setup_wpa(struct hostapd_data *hapd) 566 { 567 struct wpa_auth_config _conf; 568 struct wpa_auth_callbacks cb; 569 const u8 *wpa_ie; 570 size_t wpa_ie_len; 571 572 hostapd_wpa_auth_conf(hapd->conf, hapd->iconf, &_conf); 573 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_EAPOL_TX_STATUS) 574 _conf.tx_status = 1; 575 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_MLME) 576 _conf.ap_mlme = 1; 577 os_memset(&cb, 0, sizeof(cb)); 578 cb.ctx = hapd; 579 cb.logger = hostapd_wpa_auth_logger; 580 cb.disconnect = hostapd_wpa_auth_disconnect; 581 cb.mic_failure_report = hostapd_wpa_auth_mic_failure_report; 582 cb.set_eapol = hostapd_wpa_auth_set_eapol; 583 cb.get_eapol = hostapd_wpa_auth_get_eapol; 584 cb.get_psk = hostapd_wpa_auth_get_psk; 585 cb.get_msk = hostapd_wpa_auth_get_msk; 586 cb.set_key = hostapd_wpa_auth_set_key; 587 cb.get_seqnum = hostapd_wpa_auth_get_seqnum; 588 cb.send_eapol = hostapd_wpa_auth_send_eapol; 589 cb.for_each_sta = hostapd_wpa_auth_for_each_sta; 590 cb.for_each_auth = hostapd_wpa_auth_for_each_auth; 591 cb.send_ether = hostapd_wpa_auth_send_ether; 592 #ifdef CONFIG_IEEE80211R 593 cb.send_ft_action = hostapd_wpa_auth_send_ft_action; 594 cb.add_sta = hostapd_wpa_auth_add_sta; 595 cb.add_tspec = hostapd_wpa_auth_add_tspec; 596 #endif /* CONFIG_IEEE80211R */ 597 hapd->wpa_auth = wpa_init(hapd->own_addr, &_conf, &cb); 598 if (hapd->wpa_auth == NULL) { 599 wpa_printf(MSG_ERROR, "WPA initialization failed."); 600 return -1; 601 } 602 603 if (hostapd_set_privacy(hapd, 1)) { 604 wpa_printf(MSG_ERROR, "Could not set PrivacyInvoked " 605 "for interface %s", hapd->conf->iface); 606 return -1; 607 } 608 609 wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len); 610 if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len)) { 611 wpa_printf(MSG_ERROR, "Failed to configure WPA IE for " 612 "the kernel driver."); 613 return -1; 614 } 615 616 if (rsn_preauth_iface_init(hapd)) { 617 wpa_printf(MSG_ERROR, "Initialization of RSN " 618 "pre-authentication failed."); 619 return -1; 620 } 621 622 #ifdef CONFIG_IEEE80211R 623 if (!hostapd_drv_none(hapd)) { 624 hapd->l2 = l2_packet_init(hapd->conf->bridge[0] ? 625 hapd->conf->bridge : 626 hapd->conf->iface, NULL, ETH_P_RRB, 627 hostapd_rrb_receive, hapd, 1); 628 if (hapd->l2 == NULL && 629 (hapd->driver == NULL || 630 hapd->driver->send_ether == NULL)) { 631 wpa_printf(MSG_ERROR, "Failed to open l2_packet " 632 "interface"); 633 return -1; 634 } 635 } 636 #endif /* CONFIG_IEEE80211R */ 637 638 return 0; 639 640 } 641 642 643 void hostapd_reconfig_wpa(struct hostapd_data *hapd) 644 { 645 struct wpa_auth_config wpa_auth_conf; 646 hostapd_wpa_auth_conf(hapd->conf, hapd->iconf, &wpa_auth_conf); 647 wpa_reconfig(hapd->wpa_auth, &wpa_auth_conf); 648 } 649 650 651 void hostapd_deinit_wpa(struct hostapd_data *hapd) 652 { 653 ieee80211_tkip_countermeasures_deinit(hapd); 654 rsn_preauth_iface_deinit(hapd); 655 if (hapd->wpa_auth) { 656 wpa_deinit(hapd->wpa_auth); 657 hapd->wpa_auth = NULL; 658 659 if (hostapd_set_privacy(hapd, 0)) { 660 wpa_printf(MSG_DEBUG, "Could not disable " 661 "PrivacyInvoked for interface %s", 662 hapd->conf->iface); 663 } 664 665 if (hostapd_set_generic_elem(hapd, (u8 *) "", 0)) { 666 wpa_printf(MSG_DEBUG, "Could not remove generic " 667 "information element from interface %s", 668 hapd->conf->iface); 669 } 670 } 671 ieee802_1x_deinit(hapd); 672 673 #ifdef CONFIG_IEEE80211R 674 l2_packet_deinit(hapd->l2); 675 hapd->l2 = NULL; 676 #endif /* CONFIG_IEEE80211R */ 677 } 678