1 /* 2 * hostapd / Callback functions for driver wrappers 3 * Copyright (c) 2002-2013, Jouni Malinen <j (at) 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 "utils/eloop.h" 13 #include "radius/radius.h" 14 #include "drivers/driver.h" 15 #include "common/ieee802_11_defs.h" 16 #include "common/ieee802_11_common.h" 17 #include "common/wpa_ctrl.h" 18 #include "crypto/random.h" 19 #include "p2p/p2p.h" 20 #include "wps/wps.h" 21 #include "wnm_ap.h" 22 #include "hostapd.h" 23 #include "ieee802_11.h" 24 #include "sta_info.h" 25 #include "accounting.h" 26 #include "tkip_countermeasures.h" 27 #include "ieee802_1x.h" 28 #include "wpa_auth.h" 29 #include "wps_hostapd.h" 30 #include "ap_drv_ops.h" 31 #include "ap_config.h" 32 #include "hw_features.h" 33 #include "dfs.h" 34 #include "beacon.h" 35 36 37 int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr, 38 const u8 *req_ies, size_t req_ies_len, int reassoc) 39 { 40 struct sta_info *sta; 41 int new_assoc, res; 42 struct ieee802_11_elems elems; 43 const u8 *ie; 44 size_t ielen; 45 #ifdef CONFIG_IEEE80211R 46 u8 buf[sizeof(struct ieee80211_mgmt) + 1024]; 47 u8 *p = buf; 48 #endif /* CONFIG_IEEE80211R */ 49 u16 reason = WLAN_REASON_UNSPECIFIED; 50 u16 status = WLAN_STATUS_SUCCESS; 51 const u8 *p2p_dev_addr = NULL; 52 53 if (addr == NULL) { 54 /* 55 * This could potentially happen with unexpected event from the 56 * driver wrapper. This was seen at least in one case where the 57 * driver ended up being set to station mode while hostapd was 58 * running, so better make sure we stop processing such an 59 * event here. 60 */ 61 wpa_printf(MSG_DEBUG, "hostapd_notif_assoc: Skip event with " 62 "no address"); 63 return -1; 64 } 65 random_add_randomness(addr, ETH_ALEN); 66 67 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, 68 HOSTAPD_LEVEL_INFO, "associated"); 69 70 ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0); 71 if (elems.wps_ie) { 72 ie = elems.wps_ie - 2; 73 ielen = elems.wps_ie_len + 2; 74 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq"); 75 } else if (elems.rsn_ie) { 76 ie = elems.rsn_ie - 2; 77 ielen = elems.rsn_ie_len + 2; 78 wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq"); 79 } else if (elems.wpa_ie) { 80 ie = elems.wpa_ie - 2; 81 ielen = elems.wpa_ie_len + 2; 82 wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq"); 83 #ifdef CONFIG_HS20 84 } else if (elems.osen) { 85 ie = elems.osen - 2; 86 ielen = elems.osen_len + 2; 87 wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq"); 88 #endif /* CONFIG_HS20 */ 89 } else { 90 ie = NULL; 91 ielen = 0; 92 wpa_printf(MSG_DEBUG, "STA did not include WPS/RSN/WPA IE in " 93 "(Re)AssocReq"); 94 } 95 96 sta = ap_get_sta(hapd, addr); 97 if (sta) { 98 ap_sta_no_session_timeout(hapd, sta); 99 accounting_sta_stop(hapd, sta); 100 101 /* 102 * Make sure that the previously registered inactivity timer 103 * will not remove the STA immediately. 104 */ 105 sta->timeout_next = STA_NULLFUNC; 106 } else { 107 sta = ap_sta_add(hapd, addr); 108 if (sta == NULL) { 109 hostapd_drv_sta_disassoc(hapd, addr, 110 WLAN_REASON_DISASSOC_AP_BUSY); 111 return -1; 112 } 113 } 114 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2); 115 116 #ifdef CONFIG_P2P 117 if (elems.p2p) { 118 wpabuf_free(sta->p2p_ie); 119 sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len, 120 P2P_IE_VENDOR_TYPE); 121 if (sta->p2p_ie) 122 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie); 123 } 124 #endif /* CONFIG_P2P */ 125 126 #ifdef CONFIG_IEEE80211N 127 #ifdef NEED_AP_MLME 128 if (elems.ht_capabilities && 129 (hapd->iface->conf->ht_capab & 130 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) { 131 struct ieee80211_ht_capabilities *ht_cap = 132 (struct ieee80211_ht_capabilities *) 133 elems.ht_capabilities; 134 135 if (le_to_host16(ht_cap->ht_capabilities_info) & 136 HT_CAP_INFO_40MHZ_INTOLERANT) 137 ht40_intolerant_add(hapd->iface, sta); 138 } 139 #endif /* NEED_AP_MLME */ 140 #endif /* CONFIG_IEEE80211N */ 141 142 #ifdef CONFIG_INTERWORKING 143 if (elems.ext_capab && elems.ext_capab_len > 4) { 144 if (elems.ext_capab[4] & 0x01) 145 sta->qos_map_enabled = 1; 146 } 147 #endif /* CONFIG_INTERWORKING */ 148 149 #ifdef CONFIG_HS20 150 wpabuf_free(sta->hs20_ie); 151 if (elems.hs20 && elems.hs20_len > 4) { 152 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4, 153 elems.hs20_len - 4); 154 } else 155 sta->hs20_ie = NULL; 156 #endif /* CONFIG_HS20 */ 157 158 if (hapd->conf->wpa) { 159 if (ie == NULL || ielen == 0) { 160 #ifdef CONFIG_WPS 161 if (hapd->conf->wps_state) { 162 wpa_printf(MSG_DEBUG, "STA did not include " 163 "WPA/RSN IE in (Re)Association " 164 "Request - possible WPS use"); 165 sta->flags |= WLAN_STA_MAYBE_WPS; 166 goto skip_wpa_check; 167 } 168 #endif /* CONFIG_WPS */ 169 170 wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA"); 171 return -1; 172 } 173 #ifdef CONFIG_WPS 174 if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 && 175 os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) { 176 struct wpabuf *wps; 177 sta->flags |= WLAN_STA_WPS; 178 wps = ieee802_11_vendor_ie_concat(ie, ielen, 179 WPS_IE_VENDOR_TYPE); 180 if (wps) { 181 if (wps_is_20(wps)) { 182 wpa_printf(MSG_DEBUG, "WPS: STA " 183 "supports WPS 2.0"); 184 sta->flags |= WLAN_STA_WPS2; 185 } 186 wpabuf_free(wps); 187 } 188 goto skip_wpa_check; 189 } 190 #endif /* CONFIG_WPS */ 191 192 if (sta->wpa_sm == NULL) 193 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, 194 sta->addr, 195 p2p_dev_addr); 196 if (sta->wpa_sm == NULL) { 197 wpa_printf(MSG_ERROR, "Failed to initialize WPA state " 198 "machine"); 199 return -1; 200 } 201 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm, 202 ie, ielen, 203 elems.mdie, elems.mdie_len); 204 if (res != WPA_IE_OK) { 205 wpa_printf(MSG_DEBUG, "WPA/RSN information element " 206 "rejected? (res %u)", res); 207 wpa_hexdump(MSG_DEBUG, "IE", ie, ielen); 208 if (res == WPA_INVALID_GROUP) { 209 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID; 210 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID; 211 } else if (res == WPA_INVALID_PAIRWISE) { 212 reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID; 213 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID; 214 } else if (res == WPA_INVALID_AKMP) { 215 reason = WLAN_REASON_AKMP_NOT_VALID; 216 status = WLAN_STATUS_AKMP_NOT_VALID; 217 } 218 #ifdef CONFIG_IEEE80211W 219 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) { 220 reason = WLAN_REASON_INVALID_IE; 221 status = WLAN_STATUS_INVALID_IE; 222 } else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) { 223 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID; 224 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID; 225 } 226 #endif /* CONFIG_IEEE80211W */ 227 else { 228 reason = WLAN_REASON_INVALID_IE; 229 status = WLAN_STATUS_INVALID_IE; 230 } 231 goto fail; 232 } 233 #ifdef CONFIG_IEEE80211W 234 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out && 235 sta->sa_query_count > 0) 236 ap_check_sa_query_timeout(hapd, sta); 237 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out && 238 (sta->auth_alg != WLAN_AUTH_FT)) { 239 /* 240 * STA has already been associated with MFP and SA 241 * Query timeout has not been reached. Reject the 242 * association attempt temporarily and start SA Query, 243 * if one is not pending. 244 */ 245 246 if (sta->sa_query_count == 0) 247 ap_sta_start_sa_query(hapd, sta); 248 249 #ifdef CONFIG_IEEE80211R 250 status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY; 251 252 p = hostapd_eid_assoc_comeback_time(hapd, sta, p); 253 254 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, 255 p - buf); 256 #endif /* CONFIG_IEEE80211R */ 257 return 0; 258 } 259 260 if (wpa_auth_uses_mfp(sta->wpa_sm)) 261 sta->flags |= WLAN_STA_MFP; 262 else 263 sta->flags &= ~WLAN_STA_MFP; 264 #endif /* CONFIG_IEEE80211W */ 265 266 #ifdef CONFIG_IEEE80211R 267 if (sta->auth_alg == WLAN_AUTH_FT) { 268 status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies, 269 req_ies_len); 270 if (status != WLAN_STATUS_SUCCESS) { 271 if (status == WLAN_STATUS_INVALID_PMKID) 272 reason = WLAN_REASON_INVALID_IE; 273 if (status == WLAN_STATUS_INVALID_MDIE) 274 reason = WLAN_REASON_INVALID_IE; 275 if (status == WLAN_STATUS_INVALID_FTIE) 276 reason = WLAN_REASON_INVALID_IE; 277 goto fail; 278 } 279 } 280 #endif /* CONFIG_IEEE80211R */ 281 } else if (hapd->conf->wps_state) { 282 #ifdef CONFIG_WPS 283 struct wpabuf *wps; 284 if (req_ies) 285 wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len, 286 WPS_IE_VENDOR_TYPE); 287 else 288 wps = NULL; 289 #ifdef CONFIG_WPS_STRICT 290 if (wps && wps_validate_assoc_req(wps) < 0) { 291 reason = WLAN_REASON_INVALID_IE; 292 status = WLAN_STATUS_INVALID_IE; 293 wpabuf_free(wps); 294 goto fail; 295 } 296 #endif /* CONFIG_WPS_STRICT */ 297 if (wps) { 298 sta->flags |= WLAN_STA_WPS; 299 if (wps_is_20(wps)) { 300 wpa_printf(MSG_DEBUG, "WPS: STA supports " 301 "WPS 2.0"); 302 sta->flags |= WLAN_STA_WPS2; 303 } 304 } else 305 sta->flags |= WLAN_STA_MAYBE_WPS; 306 wpabuf_free(wps); 307 #endif /* CONFIG_WPS */ 308 #ifdef CONFIG_HS20 309 } else if (hapd->conf->osen) { 310 if (elems.osen == NULL) { 311 hostapd_logger( 312 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, 313 HOSTAPD_LEVEL_INFO, 314 "No HS 2.0 OSEN element in association request"); 315 return WLAN_STATUS_INVALID_IE; 316 } 317 318 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association"); 319 if (sta->wpa_sm == NULL) 320 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, 321 sta->addr, NULL); 322 if (sta->wpa_sm == NULL) { 323 wpa_printf(MSG_WARNING, "Failed to initialize WPA " 324 "state machine"); 325 return WLAN_STATUS_UNSPECIFIED_FAILURE; 326 } 327 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm, 328 elems.osen - 2, elems.osen_len + 2) < 0) 329 return WLAN_STATUS_INVALID_IE; 330 #endif /* CONFIG_HS20 */ 331 } 332 #ifdef CONFIG_WPS 333 skip_wpa_check: 334 #endif /* CONFIG_WPS */ 335 336 #ifdef CONFIG_IEEE80211R 337 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf), 338 sta->auth_alg, req_ies, req_ies_len); 339 340 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf); 341 342 if (sta->auth_alg == WLAN_AUTH_FT) 343 ap_sta_set_authorized(hapd, sta, 1); 344 #else /* CONFIG_IEEE80211R */ 345 /* Keep compiler silent about unused variables */ 346 if (status) { 347 } 348 #endif /* CONFIG_IEEE80211R */ 349 350 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0; 351 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC; 352 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE; 353 354 hostapd_set_sta_flags(hapd, sta); 355 356 if (reassoc && (sta->auth_alg == WLAN_AUTH_FT)) 357 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT); 358 else 359 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC); 360 361 hostapd_new_assoc_sta(hapd, sta, !new_assoc); 362 363 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1); 364 365 #ifdef CONFIG_P2P 366 if (req_ies) { 367 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, 368 req_ies, req_ies_len); 369 } 370 #endif /* CONFIG_P2P */ 371 372 return 0; 373 374 fail: 375 #ifdef CONFIG_IEEE80211R 376 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf); 377 #endif /* CONFIG_IEEE80211R */ 378 hostapd_drv_sta_disassoc(hapd, sta->addr, reason); 379 ap_free_sta(hapd, sta); 380 return -1; 381 } 382 383 384 void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr) 385 { 386 struct sta_info *sta; 387 388 if (addr == NULL) { 389 /* 390 * This could potentially happen with unexpected event from the 391 * driver wrapper. This was seen at least in one case where the 392 * driver ended up reporting a station mode event while hostapd 393 * was running, so better make sure we stop processing such an 394 * event here. 395 */ 396 wpa_printf(MSG_DEBUG, "hostapd_notif_disassoc: Skip event " 397 "with no address"); 398 return; 399 } 400 401 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, 402 HOSTAPD_LEVEL_INFO, "disassociated"); 403 404 sta = ap_get_sta(hapd, addr); 405 if (sta == NULL) { 406 wpa_printf(MSG_DEBUG, "Disassociation notification for " 407 "unknown STA " MACSTR, MAC2STR(addr)); 408 return; 409 } 410 411 ap_sta_set_authorized(hapd, sta, 0); 412 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC); 413 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC); 414 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST; 415 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); 416 ap_free_sta(hapd, sta); 417 } 418 419 420 void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr) 421 { 422 struct sta_info *sta = ap_get_sta(hapd, addr); 423 424 if (!sta || !hapd->conf->disassoc_low_ack) 425 return; 426 427 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211, 428 HOSTAPD_LEVEL_INFO, "disconnected due to excessive " 429 "missing ACKs"); 430 hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK); 431 if (sta) 432 ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK); 433 } 434 435 436 void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht, 437 int offset, int width, int cf1, int cf2) 438 { 439 #ifdef NEED_AP_MLME 440 int channel, chwidth, seg0_idx = 0, seg1_idx = 0, is_dfs; 441 442 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, 443 HOSTAPD_LEVEL_INFO, 444 "driver had channel switch: freq=%d, ht=%d, offset=%d, width=%d (%s), cf1=%d, cf2=%d", 445 freq, ht, offset, width, channel_width_to_string(width), 446 cf1, cf2); 447 448 hapd->iface->freq = freq; 449 450 channel = hostapd_hw_get_channel(hapd, freq); 451 if (!channel) { 452 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, 453 HOSTAPD_LEVEL_WARNING, "driver switched to " 454 "bad channel!"); 455 return; 456 } 457 458 switch (width) { 459 case CHAN_WIDTH_80: 460 chwidth = VHT_CHANWIDTH_80MHZ; 461 break; 462 case CHAN_WIDTH_80P80: 463 chwidth = VHT_CHANWIDTH_80P80MHZ; 464 break; 465 case CHAN_WIDTH_160: 466 chwidth = VHT_CHANWIDTH_160MHZ; 467 break; 468 case CHAN_WIDTH_20_NOHT: 469 case CHAN_WIDTH_20: 470 case CHAN_WIDTH_40: 471 default: 472 chwidth = VHT_CHANWIDTH_USE_HT; 473 break; 474 } 475 476 switch (hapd->iface->current_mode->mode) { 477 case HOSTAPD_MODE_IEEE80211A: 478 if (cf1 > 5000) 479 seg0_idx = (cf1 - 5000) / 5; 480 if (cf2 > 5000) 481 seg1_idx = (cf2 - 5000) / 5; 482 break; 483 default: 484 seg0_idx = hostapd_hw_get_channel(hapd, cf1); 485 seg1_idx = hostapd_hw_get_channel(hapd, cf2); 486 break; 487 } 488 489 hapd->iconf->channel = channel; 490 hapd->iconf->ieee80211n = ht; 491 if (!ht) 492 hapd->iconf->ieee80211ac = 0; 493 hapd->iconf->secondary_channel = offset; 494 hapd->iconf->vht_oper_chwidth = chwidth; 495 hapd->iconf->vht_oper_centr_freq_seg0_idx = seg0_idx; 496 hapd->iconf->vht_oper_centr_freq_seg1_idx = seg1_idx; 497 498 is_dfs = ieee80211_is_dfs(freq); 499 500 if (hapd->csa_in_progress && 501 freq == hapd->cs_freq_params.freq) { 502 hostapd_cleanup_cs_params(hapd); 503 ieee802_11_set_beacon(hapd); 504 505 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED 506 "freq=%d dfs=%d", freq, is_dfs); 507 } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) { 508 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED 509 "freq=%d dfs=%d", freq, is_dfs); 510 } 511 #endif /* NEED_AP_MLME */ 512 } 513 514 515 void hostapd_event_connect_failed_reason(struct hostapd_data *hapd, 516 const u8 *addr, int reason_code) 517 { 518 switch (reason_code) { 519 case MAX_CLIENT_REACHED: 520 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR, 521 MAC2STR(addr)); 522 break; 523 case BLOCKED_CLIENT: 524 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR, 525 MAC2STR(addr)); 526 break; 527 } 528 } 529 530 531 #ifdef CONFIG_ACS 532 static void hostapd_acs_channel_selected(struct hostapd_data *hapd, 533 struct acs_selected_channels *acs_res) 534 { 535 int ret, i; 536 537 if (hapd->iconf->channel) { 538 wpa_printf(MSG_INFO, "ACS: Channel was already set to %d", 539 hapd->iconf->channel); 540 return; 541 } 542 543 if (!hapd->iface->current_mode) { 544 for (i = 0; i < hapd->iface->num_hw_features; i++) { 545 struct hostapd_hw_modes *mode = 546 &hapd->iface->hw_features[i]; 547 548 if (mode->mode == acs_res->hw_mode) { 549 hapd->iface->current_mode = mode; 550 break; 551 } 552 } 553 if (!hapd->iface->current_mode) { 554 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, 555 HOSTAPD_LEVEL_WARNING, 556 "driver selected to bad hw_mode"); 557 return; 558 } 559 } 560 561 hapd->iface->freq = hostapd_hw_get_freq(hapd, acs_res->pri_channel); 562 563 if (!acs_res->pri_channel) { 564 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, 565 HOSTAPD_LEVEL_WARNING, 566 "driver switched to bad channel"); 567 return; 568 } 569 570 hapd->iconf->channel = acs_res->pri_channel; 571 hapd->iconf->acs = 1; 572 573 if (acs_res->sec_channel == 0) 574 hapd->iconf->secondary_channel = 0; 575 else if (acs_res->sec_channel < acs_res->pri_channel) 576 hapd->iconf->secondary_channel = -1; 577 else if (acs_res->sec_channel > acs_res->pri_channel) 578 hapd->iconf->secondary_channel = 1; 579 else { 580 wpa_printf(MSG_ERROR, "Invalid secondary channel!"); 581 return; 582 } 583 584 if (hapd->iface->conf->ieee80211ac) { 585 /* set defaults for backwards compatibility */ 586 hapd->iconf->vht_oper_centr_freq_seg1_idx = 0; 587 hapd->iconf->vht_oper_centr_freq_seg0_idx = 0; 588 hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT; 589 if (acs_res->ch_width == 80) { 590 hapd->iconf->vht_oper_centr_freq_seg0_idx = 591 acs_res->vht_seg0_center_ch; 592 hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ; 593 } else if (acs_res->ch_width == 160) { 594 if (acs_res->vht_seg1_center_ch == 0) { 595 hapd->iconf->vht_oper_centr_freq_seg0_idx = 596 acs_res->vht_seg0_center_ch; 597 hapd->iconf->vht_oper_chwidth = 598 VHT_CHANWIDTH_160MHZ; 599 } else { 600 hapd->iconf->vht_oper_centr_freq_seg0_idx = 601 acs_res->vht_seg0_center_ch; 602 hapd->iconf->vht_oper_centr_freq_seg1_idx = 603 acs_res->vht_seg1_center_ch; 604 hapd->iconf->vht_oper_chwidth = 605 VHT_CHANWIDTH_80P80MHZ; 606 } 607 } 608 } 609 610 ret = hostapd_acs_completed(hapd->iface, 0); 611 if (ret) { 612 wpa_printf(MSG_ERROR, 613 "ACS: Possibly channel configuration is invalid"); 614 } 615 } 616 #endif /* CONFIG_ACS */ 617 618 619 int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da, 620 const u8 *bssid, const u8 *ie, size_t ie_len, 621 int ssi_signal) 622 { 623 size_t i; 624 int ret = 0; 625 626 if (sa == NULL || ie == NULL) 627 return -1; 628 629 random_add_randomness(sa, ETH_ALEN); 630 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) { 631 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx, 632 sa, da, bssid, ie, ie_len, 633 ssi_signal) > 0) { 634 ret = 1; 635 break; 636 } 637 } 638 return ret; 639 } 640 641 642 #ifdef HOSTAPD 643 644 #ifdef CONFIG_IEEE80211R 645 static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst, 646 const u8 *bssid, 647 u16 auth_transaction, u16 status, 648 const u8 *ies, size_t ies_len) 649 { 650 struct hostapd_data *hapd = ctx; 651 struct sta_info *sta; 652 653 sta = ap_get_sta(hapd, dst); 654 if (sta == NULL) 655 return; 656 657 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211, 658 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)"); 659 sta->flags |= WLAN_STA_AUTH; 660 661 hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len); 662 } 663 #endif /* CONFIG_IEEE80211R */ 664 665 666 static void hostapd_notif_auth(struct hostapd_data *hapd, 667 struct auth_info *rx_auth) 668 { 669 struct sta_info *sta; 670 u16 status = WLAN_STATUS_SUCCESS; 671 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN]; 672 size_t resp_ies_len = 0; 673 674 sta = ap_get_sta(hapd, rx_auth->peer); 675 if (!sta) { 676 sta = ap_sta_add(hapd, rx_auth->peer); 677 if (sta == NULL) { 678 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; 679 goto fail; 680 } 681 } 682 sta->flags &= ~WLAN_STA_PREAUTH; 683 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0); 684 #ifdef CONFIG_IEEE80211R 685 if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) { 686 sta->auth_alg = WLAN_AUTH_FT; 687 if (sta->wpa_sm == NULL) 688 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, 689 sta->addr, NULL); 690 if (sta->wpa_sm == NULL) { 691 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA " 692 "state machine"); 693 status = WLAN_STATUS_UNSPECIFIED_FAILURE; 694 goto fail; 695 } 696 wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid, 697 rx_auth->auth_transaction, rx_auth->ies, 698 rx_auth->ies_len, 699 hostapd_notify_auth_ft_finish, hapd); 700 return; 701 } 702 #endif /* CONFIG_IEEE80211R */ 703 fail: 704 hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1, 705 status, resp_ies, resp_ies_len); 706 } 707 708 709 static void hostapd_action_rx(struct hostapd_data *hapd, 710 struct rx_mgmt *drv_mgmt) 711 { 712 struct ieee80211_mgmt *mgmt; 713 struct sta_info *sta; 714 size_t plen __maybe_unused; 715 u16 fc; 716 717 if (drv_mgmt->frame_len < 24 + 1) 718 return; 719 720 plen = drv_mgmt->frame_len - 24 - 1; 721 722 mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame; 723 fc = le_to_host16(mgmt->frame_control); 724 if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION) 725 return; /* handled by the driver */ 726 727 wpa_printf(MSG_DEBUG, "RX_ACTION cat %d action plen %d", 728 mgmt->u.action.category, (int) plen); 729 730 sta = ap_get_sta(hapd, mgmt->sa); 731 if (sta == NULL) { 732 wpa_printf(MSG_DEBUG, "%s: station not found", __func__); 733 return; 734 } 735 #ifdef CONFIG_IEEE80211R 736 if (mgmt->u.action.category == WLAN_ACTION_FT) { 737 const u8 *payload = drv_mgmt->frame + 24 + 1; 738 wpa_ft_action_rx(sta->wpa_sm, payload, plen); 739 } 740 #endif /* CONFIG_IEEE80211R */ 741 #ifdef CONFIG_IEEE80211W 742 if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY && plen >= 4) { 743 ieee802_11_sa_query_action( 744 hapd, mgmt->sa, 745 mgmt->u.action.u.sa_query_resp.action, 746 mgmt->u.action.u.sa_query_resp.trans_id); 747 } 748 #endif /* CONFIG_IEEE80211W */ 749 #ifdef CONFIG_WNM 750 if (mgmt->u.action.category == WLAN_ACTION_WNM) { 751 ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len); 752 } 753 #endif /* CONFIG_WNM */ 754 } 755 756 757 #ifdef NEED_AP_MLME 758 759 #define HAPD_BROADCAST ((struct hostapd_data *) -1) 760 761 static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface, 762 const u8 *bssid) 763 { 764 size_t i; 765 766 if (bssid == NULL) 767 return NULL; 768 if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff && 769 bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff) 770 return HAPD_BROADCAST; 771 772 for (i = 0; i < iface->num_bss; i++) { 773 if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0) 774 return iface->bss[i]; 775 } 776 777 return NULL; 778 } 779 780 781 static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd, 782 const u8 *bssid, const u8 *addr, 783 int wds) 784 { 785 hapd = get_hapd_bssid(hapd->iface, bssid); 786 if (hapd == NULL || hapd == HAPD_BROADCAST) 787 return; 788 789 ieee802_11_rx_from_unknown(hapd, addr, wds); 790 } 791 792 793 static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt) 794 { 795 struct hostapd_iface *iface = hapd->iface; 796 const struct ieee80211_hdr *hdr; 797 const u8 *bssid; 798 struct hostapd_frame_info fi; 799 int ret; 800 801 #ifdef CONFIG_TESTING_OPTIONS 802 if (hapd->ext_mgmt_frame_handling) { 803 size_t hex_len = 2 * rx_mgmt->frame_len + 1; 804 char *hex = os_malloc(hex_len); 805 if (hex) { 806 wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame, 807 rx_mgmt->frame_len); 808 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex); 809 os_free(hex); 810 } 811 return 1; 812 } 813 #endif /* CONFIG_TESTING_OPTIONS */ 814 815 hdr = (const struct ieee80211_hdr *) rx_mgmt->frame; 816 bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len); 817 if (bssid == NULL) 818 return 0; 819 820 hapd = get_hapd_bssid(iface, bssid); 821 if (hapd == NULL) { 822 u16 fc; 823 fc = le_to_host16(hdr->frame_control); 824 825 /* 826 * Drop frames to unknown BSSIDs except for Beacon frames which 827 * could be used to update neighbor information. 828 */ 829 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && 830 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) 831 hapd = iface->bss[0]; 832 else 833 return 0; 834 } 835 836 os_memset(&fi, 0, sizeof(fi)); 837 fi.datarate = rx_mgmt->datarate; 838 fi.ssi_signal = rx_mgmt->ssi_signal; 839 840 if (hapd == HAPD_BROADCAST) { 841 size_t i; 842 ret = 0; 843 for (i = 0; i < iface->num_bss; i++) { 844 /* if bss is set, driver will call this function for 845 * each bss individually. */ 846 if (rx_mgmt->drv_priv && 847 (iface->bss[i]->drv_priv != rx_mgmt->drv_priv)) 848 continue; 849 850 if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame, 851 rx_mgmt->frame_len, &fi) > 0) 852 ret = 1; 853 } 854 } else 855 ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len, 856 &fi); 857 858 random_add_randomness(&fi, sizeof(fi)); 859 860 return ret; 861 } 862 863 864 static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf, 865 size_t len, u16 stype, int ok) 866 { 867 struct ieee80211_hdr *hdr; 868 hdr = (struct ieee80211_hdr *) buf; 869 hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len)); 870 if (hapd == NULL || hapd == HAPD_BROADCAST) 871 return; 872 ieee802_11_mgmt_cb(hapd, buf, len, stype, ok); 873 } 874 875 #endif /* NEED_AP_MLME */ 876 877 878 static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr) 879 { 880 struct sta_info *sta = ap_get_sta(hapd, addr); 881 if (sta) 882 return 0; 883 884 wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR 885 " - adding a new STA", MAC2STR(addr)); 886 sta = ap_sta_add(hapd, addr); 887 if (sta) { 888 hostapd_new_assoc_sta(hapd, sta, 0); 889 } else { 890 wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR, 891 MAC2STR(addr)); 892 return -1; 893 } 894 895 return 0; 896 } 897 898 899 static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src, 900 const u8 *data, size_t data_len) 901 { 902 struct hostapd_iface *iface = hapd->iface; 903 struct sta_info *sta; 904 size_t j; 905 906 for (j = 0; j < iface->num_bss; j++) { 907 if ((sta = ap_get_sta(iface->bss[j], src))) { 908 if (sta->flags & WLAN_STA_ASSOC) { 909 hapd = iface->bss[j]; 910 break; 911 } 912 } 913 } 914 915 ieee802_1x_receive(hapd, src, data, data_len); 916 } 917 918 919 static struct hostapd_channel_data * hostapd_get_mode_channel( 920 struct hostapd_iface *iface, unsigned int freq) 921 { 922 int i; 923 struct hostapd_channel_data *chan; 924 925 for (i = 0; i < iface->current_mode->num_channels; i++) { 926 chan = &iface->current_mode->channels[i]; 927 if (!chan) 928 return NULL; 929 if ((unsigned int) chan->freq == freq) 930 return chan; 931 } 932 933 return NULL; 934 } 935 936 937 static void hostapd_update_nf(struct hostapd_iface *iface, 938 struct hostapd_channel_data *chan, 939 struct freq_survey *survey) 940 { 941 if (!iface->chans_surveyed) { 942 chan->min_nf = survey->nf; 943 iface->lowest_nf = survey->nf; 944 } else { 945 if (dl_list_empty(&chan->survey_list)) 946 chan->min_nf = survey->nf; 947 else if (survey->nf < chan->min_nf) 948 chan->min_nf = survey->nf; 949 if (survey->nf < iface->lowest_nf) 950 iface->lowest_nf = survey->nf; 951 } 952 } 953 954 955 static void hostapd_single_channel_get_survey(struct hostapd_iface *iface, 956 struct survey_results *survey_res) 957 { 958 struct hostapd_channel_data *chan; 959 struct freq_survey *survey; 960 u64 divisor, dividend; 961 962 survey = dl_list_first(&survey_res->survey_list, struct freq_survey, 963 list); 964 if (!survey || !survey->freq) 965 return; 966 967 chan = hostapd_get_mode_channel(iface, survey->freq); 968 if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED) 969 return; 970 971 wpa_printf(MSG_DEBUG, "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)", 972 survey->freq, 973 (unsigned long int) survey->channel_time, 974 (unsigned long int) survey->channel_time_busy); 975 976 if (survey->channel_time > iface->last_channel_time && 977 survey->channel_time > survey->channel_time_busy) { 978 dividend = survey->channel_time_busy - 979 iface->last_channel_time_busy; 980 divisor = survey->channel_time - iface->last_channel_time; 981 982 iface->channel_utilization = dividend * 255 / divisor; 983 wpa_printf(MSG_DEBUG, "Channel Utilization: %d", 984 iface->channel_utilization); 985 } 986 iface->last_channel_time = survey->channel_time; 987 iface->last_channel_time_busy = survey->channel_time_busy; 988 } 989 990 991 static void hostapd_event_get_survey(struct hostapd_data *hapd, 992 struct survey_results *survey_results) 993 { 994 struct hostapd_iface *iface = hapd->iface; 995 struct freq_survey *survey, *tmp; 996 struct hostapd_channel_data *chan; 997 998 if (dl_list_empty(&survey_results->survey_list)) { 999 wpa_printf(MSG_DEBUG, "No survey data received"); 1000 return; 1001 } 1002 1003 if (survey_results->freq_filter) { 1004 hostapd_single_channel_get_survey(iface, survey_results); 1005 return; 1006 } 1007 1008 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, 1009 struct freq_survey, list) { 1010 chan = hostapd_get_mode_channel(iface, survey->freq); 1011 if (!chan) 1012 continue; 1013 if (chan->flag & HOSTAPD_CHAN_DISABLED) 1014 continue; 1015 1016 dl_list_del(&survey->list); 1017 dl_list_add_tail(&chan->survey_list, &survey->list); 1018 1019 hostapd_update_nf(iface, chan, survey); 1020 1021 iface->chans_surveyed++; 1022 } 1023 } 1024 1025 1026 #ifdef NEED_AP_MLME 1027 1028 static void hostapd_event_iface_unavailable(struct hostapd_data *hapd) 1029 { 1030 wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped", 1031 hapd->conf->iface); 1032 1033 if (hapd->csa_in_progress) { 1034 wpa_printf(MSG_INFO, "CSA failed (%s was stopped)", 1035 hapd->conf->iface); 1036 hostapd_switch_channel_fallback(hapd->iface, 1037 &hapd->cs_freq_params); 1038 } 1039 } 1040 1041 1042 static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd, 1043 struct dfs_event *radar) 1044 { 1045 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq); 1046 hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled, 1047 radar->chan_offset, radar->chan_width, 1048 radar->cf1, radar->cf2); 1049 } 1050 1051 1052 static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd, 1053 struct dfs_event *radar) 1054 { 1055 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq); 1056 hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled, 1057 radar->chan_offset, radar->chan_width, 1058 radar->cf1, radar->cf2); 1059 } 1060 1061 1062 static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd, 1063 struct dfs_event *radar) 1064 { 1065 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq); 1066 hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled, 1067 radar->chan_offset, radar->chan_width, 1068 radar->cf1, radar->cf2); 1069 } 1070 1071 1072 static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd, 1073 struct dfs_event *radar) 1074 { 1075 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq); 1076 hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled, 1077 radar->chan_offset, radar->chan_width, 1078 radar->cf1, radar->cf2); 1079 } 1080 1081 1082 static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd, 1083 struct dfs_event *radar) 1084 { 1085 wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq); 1086 hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled, 1087 radar->chan_offset, radar->chan_width, 1088 radar->cf1, radar->cf2); 1089 } 1090 1091 #endif /* NEED_AP_MLME */ 1092 1093 1094 void wpa_supplicant_event(void *ctx, enum wpa_event_type event, 1095 union wpa_event_data *data) 1096 { 1097 struct hostapd_data *hapd = ctx; 1098 #ifndef CONFIG_NO_STDOUT_DEBUG 1099 int level = MSG_DEBUG; 1100 1101 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame && 1102 data->rx_mgmt.frame_len >= 24) { 1103 const struct ieee80211_hdr *hdr; 1104 u16 fc; 1105 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame; 1106 fc = le_to_host16(hdr->frame_control); 1107 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && 1108 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) 1109 level = MSG_EXCESSIVE; 1110 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && 1111 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ) 1112 level = MSG_EXCESSIVE; 1113 } 1114 1115 wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received", 1116 event_to_string(event), event); 1117 #endif /* CONFIG_NO_STDOUT_DEBUG */ 1118 1119 switch (event) { 1120 case EVENT_MICHAEL_MIC_FAILURE: 1121 michael_mic_failure(hapd, data->michael_mic_failure.src, 1); 1122 break; 1123 case EVENT_SCAN_RESULTS: 1124 if (hapd->iface->scan_cb) 1125 hapd->iface->scan_cb(hapd->iface); 1126 break; 1127 case EVENT_WPS_BUTTON_PUSHED: 1128 hostapd_wps_button_pushed(hapd, NULL); 1129 break; 1130 #ifdef NEED_AP_MLME 1131 case EVENT_TX_STATUS: 1132 switch (data->tx_status.type) { 1133 case WLAN_FC_TYPE_MGMT: 1134 hostapd_mgmt_tx_cb(hapd, data->tx_status.data, 1135 data->tx_status.data_len, 1136 data->tx_status.stype, 1137 data->tx_status.ack); 1138 break; 1139 case WLAN_FC_TYPE_DATA: 1140 hostapd_tx_status(hapd, data->tx_status.dst, 1141 data->tx_status.data, 1142 data->tx_status.data_len, 1143 data->tx_status.ack); 1144 break; 1145 } 1146 break; 1147 case EVENT_EAPOL_TX_STATUS: 1148 hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst, 1149 data->eapol_tx_status.data, 1150 data->eapol_tx_status.data_len, 1151 data->eapol_tx_status.ack); 1152 break; 1153 case EVENT_DRIVER_CLIENT_POLL_OK: 1154 hostapd_client_poll_ok(hapd, data->client_poll.addr); 1155 break; 1156 case EVENT_RX_FROM_UNKNOWN: 1157 hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid, 1158 data->rx_from_unknown.addr, 1159 data->rx_from_unknown.wds); 1160 break; 1161 #endif /* NEED_AP_MLME */ 1162 case EVENT_RX_MGMT: 1163 if (!data->rx_mgmt.frame) 1164 break; 1165 #ifdef NEED_AP_MLME 1166 if (hostapd_mgmt_rx(hapd, &data->rx_mgmt) > 0) 1167 break; 1168 #endif /* NEED_AP_MLME */ 1169 hostapd_action_rx(hapd, &data->rx_mgmt); 1170 break; 1171 case EVENT_RX_PROBE_REQ: 1172 if (data->rx_probe_req.sa == NULL || 1173 data->rx_probe_req.ie == NULL) 1174 break; 1175 hostapd_probe_req_rx(hapd, data->rx_probe_req.sa, 1176 data->rx_probe_req.da, 1177 data->rx_probe_req.bssid, 1178 data->rx_probe_req.ie, 1179 data->rx_probe_req.ie_len, 1180 data->rx_probe_req.ssi_signal); 1181 break; 1182 case EVENT_NEW_STA: 1183 hostapd_event_new_sta(hapd, data->new_sta.addr); 1184 break; 1185 case EVENT_EAPOL_RX: 1186 hostapd_event_eapol_rx(hapd, data->eapol_rx.src, 1187 data->eapol_rx.data, 1188 data->eapol_rx.data_len); 1189 break; 1190 case EVENT_ASSOC: 1191 if (!data) 1192 return; 1193 hostapd_notif_assoc(hapd, data->assoc_info.addr, 1194 data->assoc_info.req_ies, 1195 data->assoc_info.req_ies_len, 1196 data->assoc_info.reassoc); 1197 break; 1198 case EVENT_DISASSOC: 1199 if (data) 1200 hostapd_notif_disassoc(hapd, data->disassoc_info.addr); 1201 break; 1202 case EVENT_DEAUTH: 1203 if (data) 1204 hostapd_notif_disassoc(hapd, data->deauth_info.addr); 1205 break; 1206 case EVENT_STATION_LOW_ACK: 1207 if (!data) 1208 break; 1209 hostapd_event_sta_low_ack(hapd, data->low_ack.addr); 1210 break; 1211 case EVENT_AUTH: 1212 hostapd_notif_auth(hapd, &data->auth); 1213 break; 1214 case EVENT_CH_SWITCH: 1215 if (!data) 1216 break; 1217 hostapd_event_ch_switch(hapd, data->ch_switch.freq, 1218 data->ch_switch.ht_enabled, 1219 data->ch_switch.ch_offset, 1220 data->ch_switch.ch_width, 1221 data->ch_switch.cf1, 1222 data->ch_switch.cf2); 1223 break; 1224 case EVENT_CONNECT_FAILED_REASON: 1225 if (!data) 1226 break; 1227 hostapd_event_connect_failed_reason( 1228 hapd, data->connect_failed_reason.addr, 1229 data->connect_failed_reason.code); 1230 break; 1231 case EVENT_SURVEY: 1232 hostapd_event_get_survey(hapd, &data->survey_results); 1233 break; 1234 #ifdef NEED_AP_MLME 1235 case EVENT_INTERFACE_UNAVAILABLE: 1236 hostapd_event_iface_unavailable(hapd); 1237 break; 1238 case EVENT_DFS_RADAR_DETECTED: 1239 if (!data) 1240 break; 1241 hostapd_event_dfs_radar_detected(hapd, &data->dfs_event); 1242 break; 1243 case EVENT_DFS_CAC_FINISHED: 1244 if (!data) 1245 break; 1246 hostapd_event_dfs_cac_finished(hapd, &data->dfs_event); 1247 break; 1248 case EVENT_DFS_CAC_ABORTED: 1249 if (!data) 1250 break; 1251 hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event); 1252 break; 1253 case EVENT_DFS_NOP_FINISHED: 1254 if (!data) 1255 break; 1256 hostapd_event_dfs_nop_finished(hapd, &data->dfs_event); 1257 break; 1258 case EVENT_CHANNEL_LIST_CHANGED: 1259 /* channel list changed (regulatory?), update channel list */ 1260 /* TODO: check this. hostapd_get_hw_features() initializes 1261 * too much stuff. */ 1262 /* hostapd_get_hw_features(hapd->iface); */ 1263 hostapd_channel_list_updated( 1264 hapd->iface, data->channel_list_changed.initiator); 1265 break; 1266 case EVENT_DFS_CAC_STARTED: 1267 if (!data) 1268 break; 1269 hostapd_event_dfs_cac_started(hapd, &data->dfs_event); 1270 break; 1271 #endif /* NEED_AP_MLME */ 1272 case EVENT_INTERFACE_ENABLED: 1273 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED); 1274 if (hapd->disabled && hapd->started) { 1275 hapd->disabled = 0; 1276 /* 1277 * Try to re-enable interface if the driver stopped it 1278 * when the interface got disabled. 1279 */ 1280 wpa_auth_reconfig_group_keys(hapd->wpa_auth); 1281 hapd->reenable_beacon = 1; 1282 ieee802_11_set_beacon(hapd); 1283 } 1284 break; 1285 case EVENT_INTERFACE_DISABLED: 1286 hostapd_free_stas(hapd); 1287 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED); 1288 hapd->disabled = 1; 1289 break; 1290 #ifdef CONFIG_ACS 1291 case EVENT_ACS_CHANNEL_SELECTED: 1292 hostapd_acs_channel_selected(hapd, 1293 &data->acs_selected_channels); 1294 break; 1295 #endif /* CONFIG_ACS */ 1296 default: 1297 wpa_printf(MSG_DEBUG, "Unknown event %d", event); 1298 break; 1299 } 1300 } 1301 1302 #endif /* HOSTAPD */ 1303