2 * hostapd / Initialization and configuration
3 * Copyright (c) 2002-2019, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "common/ieee802_11_defs.h"
14 #include "common/wpa_ctrl.h"
15 #include "common/hw_features_common.h"
16 #include "radius/radius_client.h"
17 #include "radius/radius_das.h"
18 #include "eap_server/tncs.h"
19 #include "eapol_auth/eapol_auth_sm.h"
20 #include "eapol_auth/eapol_auth_sm_i.h"
25 #include "accounting.h"
29 #include "ieee802_1x.h"
30 #include "ieee802_11_auth.h"
31 #include "vlan_init.h"
33 #include "wps_hostapd.h"
34 #include "dpp_hostapd.h"
35 #include "gas_query_ap.h"
36 #include "hw_features.h"
37 #include "wpa_auth_glue.h"
38 #include "ap_drv_ops.h"
39 #include "ap_config.h"
40 #include "p2p_hostapd.h"
43 #include "ieee802_11.h"
46 #include "dhcp_snoop.h"
47 #include "ndisc_snoop.h"
48 #include "neighbor_db.h"
55 static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason);
56 static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd);
57 static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd);
58 static int setup_interface2(struct hostapd_iface *iface);
59 static void channel_list_update_timeout(void *eloop_ctx, void *timeout_ctx);
60 static void hostapd_interface_setup_failure_handler(void *eloop_ctx,
64 int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
65 int (*cb)(struct hostapd_iface *iface,
66 void *ctx), void *ctx)
71 for (i = 0; i < interfaces->count; i++) {
72 ret = cb(interfaces->iface[i], ctx);
81 void hostapd_reconfig_encryption(struct hostapd_data *hapd)
86 hostapd_set_privacy(hapd, 0);
87 hostapd_setup_encryption(hapd->conf->iface, hapd);
91 static void hostapd_reload_bss(struct hostapd_data *hapd)
93 struct hostapd_ssid *ssid;
98 if (hapd->conf->wmm_enabled < 0)
99 hapd->conf->wmm_enabled = hapd->iconf->ieee80211n;
101 #ifndef CONFIG_NO_RADIUS
102 radius_client_reconfig(hapd->radius, hapd->conf->radius);
103 #endif /* CONFIG_NO_RADIUS */
105 ssid = &hapd->conf->ssid;
106 if (!ssid->wpa_psk_set && ssid->wpa_psk && !ssid->wpa_psk->next &&
107 ssid->wpa_passphrase_set && ssid->wpa_passphrase) {
109 * Force PSK to be derived again since SSID or passphrase may
112 hostapd_config_clear_wpa_psk(&hapd->conf->ssid.wpa_psk);
114 if (hostapd_setup_wpa_psk(hapd->conf)) {
115 wpa_printf(MSG_ERROR, "Failed to re-configure WPA PSK "
116 "after reloading configuration");
119 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
120 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1);
122 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0);
124 if ((hapd->conf->wpa || hapd->conf->osen) && hapd->wpa_auth == NULL) {
125 hostapd_setup_wpa(hapd);
127 wpa_init_keys(hapd->wpa_auth);
128 } else if (hapd->conf->wpa) {
131 hostapd_reconfig_wpa(hapd);
132 wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
133 if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len))
134 wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
135 "the kernel driver.");
136 } else if (hapd->wpa_auth) {
137 wpa_deinit(hapd->wpa_auth);
138 hapd->wpa_auth = NULL;
139 hostapd_set_privacy(hapd, 0);
140 hostapd_setup_encryption(hapd->conf->iface, hapd);
141 hostapd_set_generic_elem(hapd, (u8 *) "", 0);
144 ieee802_11_set_beacon(hapd);
145 hostapd_update_wps(hapd);
147 if (hapd->conf->ssid.ssid_set &&
148 hostapd_set_ssid(hapd, hapd->conf->ssid.ssid,
149 hapd->conf->ssid.ssid_len)) {
150 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
151 /* try to continue */
153 wpa_printf(MSG_DEBUG, "Reconfigured interface %s", hapd->conf->iface);
157 static void hostapd_clear_old(struct hostapd_iface *iface)
162 * Deauthenticate all stations since the new configuration may not
163 * allow them to use the BSS anymore.
165 for (j = 0; j < iface->num_bss; j++) {
166 hostapd_flush_old_stations(iface->bss[j],
167 WLAN_REASON_PREV_AUTH_NOT_VALID);
168 hostapd_broadcast_wep_clear(iface->bss[j]);
170 #ifndef CONFIG_NO_RADIUS
171 /* TODO: update dynamic data based on changed configuration
172 * items (e.g., open/close sockets, etc.) */
173 radius_client_flush(iface->bss[j]->radius, 0);
174 #endif /* CONFIG_NO_RADIUS */
179 static int hostapd_iface_conf_changed(struct hostapd_config *newconf,
180 struct hostapd_config *oldconf)
184 if (newconf->num_bss != oldconf->num_bss)
187 for (i = 0; i < newconf->num_bss; i++) {
188 if (os_strcmp(newconf->bss[i]->iface,
189 oldconf->bss[i]->iface) != 0)
197 int hostapd_reload_config(struct hostapd_iface *iface)
199 struct hapd_interfaces *interfaces = iface->interfaces;
200 struct hostapd_data *hapd = iface->bss[0];
201 struct hostapd_config *newconf, *oldconf;
204 if (iface->config_fname == NULL) {
205 /* Only in-memory config in use - assume it has been updated */
206 hostapd_clear_old(iface);
207 for (j = 0; j < iface->num_bss; j++)
208 hostapd_reload_bss(iface->bss[j]);
212 if (iface->interfaces == NULL ||
213 iface->interfaces->config_read_cb == NULL)
215 newconf = iface->interfaces->config_read_cb(iface->config_fname);
219 hostapd_clear_old(iface);
221 oldconf = hapd->iconf;
222 if (hostapd_iface_conf_changed(newconf, oldconf)) {
226 wpa_printf(MSG_DEBUG,
227 "Configuration changes include interface/BSS modification - force full disable+enable sequence");
228 fname = os_strdup(iface->config_fname);
230 hostapd_config_free(newconf);
233 hostapd_remove_iface(interfaces, hapd->conf->iface);
234 iface = hostapd_init(interfaces, fname);
236 hostapd_config_free(newconf);
238 wpa_printf(MSG_ERROR,
239 "Failed to initialize interface on config reload");
242 iface->interfaces = interfaces;
243 interfaces->iface[interfaces->count] = iface;
245 res = hostapd_enable_iface(iface);
247 wpa_printf(MSG_ERROR,
248 "Failed to enable interface on config reload");
251 iface->conf = newconf;
253 for (j = 0; j < iface->num_bss; j++) {
254 hapd = iface->bss[j];
255 hapd->iconf = newconf;
256 hapd->iconf->channel = oldconf->channel;
257 hapd->iconf->acs = oldconf->acs;
258 hapd->iconf->secondary_channel = oldconf->secondary_channel;
259 hapd->iconf->ieee80211n = oldconf->ieee80211n;
260 hapd->iconf->ieee80211ac = oldconf->ieee80211ac;
261 hapd->iconf->ht_capab = oldconf->ht_capab;
262 hapd->iconf->vht_capab = oldconf->vht_capab;
263 hapd->iconf->vht_oper_chwidth = oldconf->vht_oper_chwidth;
264 hapd->iconf->vht_oper_centr_freq_seg0_idx =
265 oldconf->vht_oper_centr_freq_seg0_idx;
266 hapd->iconf->vht_oper_centr_freq_seg1_idx =
267 oldconf->vht_oper_centr_freq_seg1_idx;
268 hapd->conf = newconf->bss[j];
269 hostapd_reload_bss(hapd);
272 hostapd_config_free(oldconf);
279 static void hostapd_broadcast_key_clear_iface(struct hostapd_data *hapd,
284 if (!ifname || !hapd->drv_priv)
286 for (i = 0; i < NUM_WEP_KEYS; i++) {
287 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE, NULL, i,
288 0, NULL, 0, NULL, 0)) {
289 wpa_printf(MSG_DEBUG, "Failed to clear default "
290 "encryption keys (ifname=%s keyidx=%d)",
294 #ifdef CONFIG_IEEE80211W
295 if (hapd->conf->ieee80211w) {
296 for (i = NUM_WEP_KEYS; i < NUM_WEP_KEYS + 2; i++) {
297 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE,
300 wpa_printf(MSG_DEBUG, "Failed to clear "
301 "default mgmt encryption keys "
302 "(ifname=%s keyidx=%d)", ifname, i);
306 #endif /* CONFIG_IEEE80211W */
310 static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd)
312 hostapd_broadcast_key_clear_iface(hapd, hapd->conf->iface);
317 static int hostapd_broadcast_wep_set(struct hostapd_data *hapd)
320 struct hostapd_ssid *ssid = &hapd->conf->ssid;
323 if (ssid->wep.default_len &&
324 hostapd_drv_set_key(hapd->conf->iface,
325 hapd, WPA_ALG_WEP, broadcast_ether_addr, idx,
326 1, NULL, 0, ssid->wep.key[idx],
327 ssid->wep.len[idx])) {
328 wpa_printf(MSG_WARNING, "Could not set WEP encryption.");
336 static void hostapd_free_hapd_data(struct hostapd_data *hapd)
338 os_free(hapd->probereq_cb);
339 hapd->probereq_cb = NULL;
340 hapd->num_probereq_cb = 0;
343 wpabuf_free(hapd->p2p_beacon_ie);
344 hapd->p2p_beacon_ie = NULL;
345 wpabuf_free(hapd->p2p_probe_resp_ie);
346 hapd->p2p_probe_resp_ie = NULL;
347 #endif /* CONFIG_P2P */
349 if (!hapd->started) {
350 wpa_printf(MSG_ERROR, "%s: Interface %s wasn't started",
351 __func__, hapd->conf ? hapd->conf->iface : "N/A");
355 hapd->beacon_set_done = 0;
357 wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
358 iapp_deinit(hapd->iapp);
360 accounting_deinit(hapd);
361 hostapd_deinit_wpa(hapd);
363 hostapd_acl_deinit(hapd);
364 #ifndef CONFIG_NO_RADIUS
365 radius_client_deinit(hapd->radius);
367 radius_das_deinit(hapd->radius_das);
368 hapd->radius_das = NULL;
369 #endif /* CONFIG_NO_RADIUS */
371 hostapd_deinit_wps(hapd);
373 hostapd_dpp_deinit(hapd);
374 gas_query_ap_deinit(hapd->gas);
375 #endif /* CONFIG_DPP */
377 authsrv_deinit(hapd);
379 if (hapd->interface_added) {
380 hapd->interface_added = 0;
381 if (hostapd_if_remove(hapd, WPA_IF_AP_BSS, hapd->conf->iface)) {
382 wpa_printf(MSG_WARNING,
383 "Failed to remove BSS interface %s",
385 hapd->interface_added = 1;
388 * Since this was a dynamically added interface, the
389 * driver wrapper may have removed its internal instance
390 * and hapd->drv_priv is not valid anymore.
392 hapd->drv_priv = NULL;
396 wpabuf_free(hapd->time_adv);
398 #ifdef CONFIG_INTERWORKING
399 gas_serv_deinit(hapd);
400 #endif /* CONFIG_INTERWORKING */
402 bss_load_update_deinit(hapd);
403 ndisc_snoop_deinit(hapd);
404 dhcp_snoop_deinit(hapd);
405 x_snoop_deinit(hapd);
408 bin_clear_free(hapd->tmp_eap_user.identity,
409 hapd->tmp_eap_user.identity_len);
410 bin_clear_free(hapd->tmp_eap_user.password,
411 hapd->tmp_eap_user.password_len);
412 #endif /* CONFIG_SQLITE */
415 wpabuf_free(hapd->mesh_pending_auth);
416 hapd->mesh_pending_auth = NULL;
417 #endif /* CONFIG_MESH */
419 hostapd_clean_rrm(hapd);
420 fils_hlp_deinit(hapd);
424 struct hostapd_sae_commit_queue *q;
426 while ((q = dl_list_first(&hapd->sae_commit_queue,
427 struct hostapd_sae_commit_queue,
429 dl_list_del(&q->list);
433 eloop_cancel_timeout(auth_sae_process_commit, hapd, NULL);
434 #endif /* CONFIG_SAE */
439 * hostapd_cleanup - Per-BSS cleanup (deinitialization)
440 * @hapd: Pointer to BSS data
442 * This function is used to free all per-BSS data structures and resources.
443 * Most of the modules that are initialized in hostapd_setup_bss() are
444 * deinitialized here.
446 static void hostapd_cleanup(struct hostapd_data *hapd)
448 wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s))", __func__, hapd,
449 hapd->conf ? hapd->conf->iface : "N/A");
450 if (hapd->iface->interfaces &&
451 hapd->iface->interfaces->ctrl_iface_deinit) {
452 wpa_msg(hapd->msg_ctx, MSG_INFO, WPA_EVENT_TERMINATING);
453 hapd->iface->interfaces->ctrl_iface_deinit(hapd);
455 hostapd_free_hapd_data(hapd);
459 static void sta_track_deinit(struct hostapd_iface *iface)
461 struct hostapd_sta_info *info;
463 if (!iface->num_sta_seen)
466 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
468 dl_list_del(&info->list);
469 iface->num_sta_seen--;
475 static void hostapd_cleanup_iface_partial(struct hostapd_iface *iface)
477 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
478 #ifdef CONFIG_IEEE80211N
480 hostapd_stop_setup_timers(iface);
481 #endif /* NEED_AP_MLME */
482 #endif /* CONFIG_IEEE80211N */
483 if (iface->current_mode)
485 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
486 iface->hw_features = NULL;
487 iface->current_mode = NULL;
488 os_free(iface->current_rates);
489 iface->current_rates = NULL;
490 os_free(iface->basic_rates);
491 iface->basic_rates = NULL;
492 ap_list_deinit(iface);
493 sta_track_deinit(iface);
498 * hostapd_cleanup_iface - Complete per-interface cleanup
499 * @iface: Pointer to interface data
501 * This function is called after per-BSS data structures are deinitialized
502 * with hostapd_cleanup().
504 static void hostapd_cleanup_iface(struct hostapd_iface *iface)
506 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
507 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
508 eloop_cancel_timeout(hostapd_interface_setup_failure_handler, iface,
511 hostapd_cleanup_iface_partial(iface);
512 hostapd_config_free(iface->conf);
515 os_free(iface->config_fname);
517 wpa_printf(MSG_DEBUG, "%s: free iface=%p", __func__, iface);
522 static void hostapd_clear_wep(struct hostapd_data *hapd)
524 if (hapd->drv_priv && !hapd->iface->driver_ap_teardown && hapd->conf) {
525 hostapd_set_privacy(hapd, 0);
526 hostapd_broadcast_wep_clear(hapd);
531 static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd)
535 hostapd_broadcast_wep_set(hapd);
537 if (hapd->conf->ssid.wep.default_len) {
538 hostapd_set_privacy(hapd, 1);
543 * When IEEE 802.1X is not enabled, the driver may need to know how to
544 * set authentication algorithms for static WEP.
546 hostapd_drv_set_authmode(hapd, hapd->conf->auth_algs);
548 for (i = 0; i < 4; i++) {
549 if (hapd->conf->ssid.wep.key[i] &&
550 hostapd_drv_set_key(iface, hapd, WPA_ALG_WEP, NULL, i,
551 i == hapd->conf->ssid.wep.idx, NULL, 0,
552 hapd->conf->ssid.wep.key[i],
553 hapd->conf->ssid.wep.len[i])) {
554 wpa_printf(MSG_WARNING, "Could not set WEP "
558 if (hapd->conf->ssid.wep.key[i] &&
559 i == hapd->conf->ssid.wep.idx)
560 hostapd_set_privacy(hapd, 1);
567 static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason)
572 if (hostapd_drv_none(hapd) || hapd->drv_priv == NULL)
575 if (!hapd->iface->driver_ap_teardown) {
576 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
577 "Flushing old station entries");
579 if (hostapd_flush(hapd)) {
580 wpa_msg(hapd->msg_ctx, MSG_WARNING,
581 "Could not connect to kernel driver");
585 if (hapd->conf && hapd->conf->broadcast_deauth) {
586 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
587 "Deauthenticate all stations");
588 os_memset(addr, 0xff, ETH_ALEN);
589 hostapd_drv_sta_deauth(hapd, addr, reason);
591 hostapd_free_stas(hapd);
597 static void hostapd_bss_deinit_no_free(struct hostapd_data *hapd)
599 hostapd_free_stas(hapd);
600 hostapd_flush_old_stations(hapd, WLAN_REASON_DEAUTH_LEAVING);
601 hostapd_clear_wep(hapd);
606 * hostapd_validate_bssid_configuration - Validate BSSID configuration
607 * @iface: Pointer to interface data
608 * Returns: 0 on success, -1 on failure
610 * This function is used to validate that the configured BSSIDs are valid.
612 static int hostapd_validate_bssid_configuration(struct hostapd_iface *iface)
614 u8 mask[ETH_ALEN] = { 0 };
615 struct hostapd_data *hapd = iface->bss[0];
616 unsigned int i = iface->conf->num_bss, bits = 0, j;
619 if (hostapd_drv_none(hapd))
622 if (iface->conf->use_driver_iface_addr)
625 /* Generate BSSID mask that is large enough to cover the BSSIDs. */
627 /* Determine the bits necessary to cover the number of BSSIDs. */
628 for (i--; i; i >>= 1)
631 /* Determine the bits necessary to any configured BSSIDs,
632 if they are higher than the number of BSSIDs. */
633 for (j = 0; j < iface->conf->num_bss; j++) {
634 if (is_zero_ether_addr(iface->conf->bss[j]->bssid)) {
640 for (i = 0; i < ETH_ALEN; i++) {
642 iface->conf->bss[j]->bssid[i] ^
650 for (i = 0; i < ETH_ALEN && mask[i] == 0; i++)
656 while (mask[i] != 0) {
666 wpa_printf(MSG_ERROR, "Too many bits in the BSSID mask (%u)",
671 os_memset(mask, 0xff, ETH_ALEN);
673 for (i = 5; i > 5 - j; i--)
682 wpa_printf(MSG_DEBUG, "BSS count %lu, BSSID mask " MACSTR " (%d bits)",
683 (unsigned long) iface->conf->num_bss, MAC2STR(mask), bits);
688 for (i = 0; i < ETH_ALEN; i++) {
689 if ((hapd->own_addr[i] & mask[i]) != hapd->own_addr[i]) {
690 wpa_printf(MSG_ERROR, "Invalid BSSID mask " MACSTR
691 " for start address " MACSTR ".",
692 MAC2STR(mask), MAC2STR(hapd->own_addr));
693 wpa_printf(MSG_ERROR, "Start address must be the "
694 "first address in the block (i.e., addr "
695 "AND mask == addr).");
704 static int mac_in_conf(struct hostapd_config *conf, const void *a)
708 for (i = 0; i < conf->num_bss; i++) {
709 if (hostapd_mac_comp(conf->bss[i]->bssid, a) == 0) {
718 #ifndef CONFIG_NO_RADIUS
720 static int hostapd_das_nas_mismatch(struct hostapd_data *hapd,
721 struct radius_das_attrs *attr)
723 if (attr->nas_identifier &&
724 (!hapd->conf->nas_identifier ||
725 os_strlen(hapd->conf->nas_identifier) !=
726 attr->nas_identifier_len ||
727 os_memcmp(hapd->conf->nas_identifier, attr->nas_identifier,
728 attr->nas_identifier_len) != 0)) {
729 wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-Identifier mismatch");
733 if (attr->nas_ip_addr &&
734 (hapd->conf->own_ip_addr.af != AF_INET ||
735 os_memcmp(&hapd->conf->own_ip_addr.u.v4, attr->nas_ip_addr, 4) !=
737 wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-IP-Address mismatch");
742 if (attr->nas_ipv6_addr &&
743 (hapd->conf->own_ip_addr.af != AF_INET6 ||
744 os_memcmp(&hapd->conf->own_ip_addr.u.v6, attr->nas_ipv6_addr, 16)
746 wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-IPv6-Address mismatch");
749 #endif /* CONFIG_IPV6 */
755 static struct sta_info * hostapd_das_find_sta(struct hostapd_data *hapd,
756 struct radius_das_attrs *attr,
759 struct sta_info *selected, *sta;
766 for (sta = hapd->sta_list; sta; sta = sta->next)
767 sta->radius_das_match = 1;
769 if (attr->sta_addr) {
771 sta = ap_get_sta(hapd, attr->sta_addr);
773 wpa_printf(MSG_DEBUG,
774 "RADIUS DAS: No Calling-Station-Id match");
779 for (sta = hapd->sta_list; sta; sta = sta->next) {
781 sta->radius_das_match = 0;
783 wpa_printf(MSG_DEBUG, "RADIUS DAS: Calling-Station-Id match");
786 if (attr->acct_session_id) {
788 if (attr->acct_session_id_len != 16) {
789 wpa_printf(MSG_DEBUG,
790 "RADIUS DAS: Acct-Session-Id cannot match");
795 for (sta = hapd->sta_list; sta; sta = sta->next) {
796 if (!sta->radius_das_match)
798 os_snprintf(buf, sizeof(buf), "%016llX",
799 (unsigned long long) sta->acct_session_id);
800 if (os_memcmp(attr->acct_session_id, buf, 16) != 0)
801 sta->radius_das_match = 0;
807 wpa_printf(MSG_DEBUG,
808 "RADIUS DAS: No matches remaining after Acct-Session-Id check");
811 wpa_printf(MSG_DEBUG, "RADIUS DAS: Acct-Session-Id match");
814 if (attr->acct_multi_session_id) {
816 if (attr->acct_multi_session_id_len != 16) {
817 wpa_printf(MSG_DEBUG,
818 "RADIUS DAS: Acct-Multi-Session-Id cannot match");
823 for (sta = hapd->sta_list; sta; sta = sta->next) {
824 if (!sta->radius_das_match)
826 if (!sta->eapol_sm ||
827 !sta->eapol_sm->acct_multi_session_id) {
828 sta->radius_das_match = 0;
831 os_snprintf(buf, sizeof(buf), "%016llX",
833 sta->eapol_sm->acct_multi_session_id);
834 if (os_memcmp(attr->acct_multi_session_id, buf, 16) !=
836 sta->radius_das_match = 0;
842 wpa_printf(MSG_DEBUG,
843 "RADIUS DAS: No matches remaining after Acct-Multi-Session-Id check");
846 wpa_printf(MSG_DEBUG,
847 "RADIUS DAS: Acct-Multi-Session-Id match");
854 for (sta = hapd->sta_list; sta; sta = sta->next) {
857 if (!sta->radius_das_match)
859 cui = ieee802_1x_get_radius_cui(sta->eapol_sm);
860 if (!cui || wpabuf_len(cui) != attr->cui_len ||
861 os_memcmp(wpabuf_head(cui), attr->cui,
863 sta->radius_das_match = 0;
869 wpa_printf(MSG_DEBUG,
870 "RADIUS DAS: No matches remaining after Chargeable-User-Identity check");
873 wpa_printf(MSG_DEBUG,
874 "RADIUS DAS: Chargeable-User-Identity match");
877 if (attr->user_name) {
881 for (sta = hapd->sta_list; sta; sta = sta->next) {
885 if (!sta->radius_das_match)
887 identity = ieee802_1x_get_identity(sta->eapol_sm,
890 identity_len != attr->user_name_len ||
891 os_memcmp(identity, attr->user_name, identity_len)
893 sta->radius_das_match = 0;
899 wpa_printf(MSG_DEBUG,
900 "RADIUS DAS: No matches remaining after User-Name check");
903 wpa_printf(MSG_DEBUG,
904 "RADIUS DAS: User-Name match");
909 * In theory, we could match all current associations, but it
910 * seems safer to just reject requests that do not include any
911 * session identification attributes.
913 wpa_printf(MSG_DEBUG,
914 "RADIUS DAS: No session identification attributes included");
919 for (sta = hapd->sta_list; sta; sta = sta->next) {
920 if (sta->radius_das_match) {
933 static int hostapd_das_disconnect_pmksa(struct hostapd_data *hapd,
934 struct radius_das_attrs *attr)
938 return wpa_auth_radius_das_disconnect_pmksa(hapd->wpa_auth, attr);
942 static enum radius_das_res
943 hostapd_das_disconnect(void *ctx, struct radius_das_attrs *attr)
945 struct hostapd_data *hapd = ctx;
946 struct sta_info *sta;
949 if (hostapd_das_nas_mismatch(hapd, attr))
950 return RADIUS_DAS_NAS_MISMATCH;
952 sta = hostapd_das_find_sta(hapd, attr, &multi);
955 wpa_printf(MSG_DEBUG,
956 "RADIUS DAS: Multiple sessions match - not supported");
957 return RADIUS_DAS_MULTI_SESSION_MATCH;
959 if (hostapd_das_disconnect_pmksa(hapd, attr) == 0) {
960 wpa_printf(MSG_DEBUG,
961 "RADIUS DAS: PMKSA cache entry matched");
962 return RADIUS_DAS_SUCCESS;
964 wpa_printf(MSG_DEBUG, "RADIUS DAS: No matching session found");
965 return RADIUS_DAS_SESSION_NOT_FOUND;
968 wpa_printf(MSG_DEBUG, "RADIUS DAS: Found a matching session " MACSTR
969 " - disconnecting", MAC2STR(sta->addr));
970 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
972 hostapd_drv_sta_deauth(hapd, sta->addr,
973 WLAN_REASON_PREV_AUTH_NOT_VALID);
974 ap_sta_deauthenticate(hapd, sta, WLAN_REASON_PREV_AUTH_NOT_VALID);
976 return RADIUS_DAS_SUCCESS;
981 static enum radius_das_res
982 hostapd_das_coa(void *ctx, struct radius_das_attrs *attr)
984 struct hostapd_data *hapd = ctx;
985 struct sta_info *sta;
988 if (hostapd_das_nas_mismatch(hapd, attr))
989 return RADIUS_DAS_NAS_MISMATCH;
991 sta = hostapd_das_find_sta(hapd, attr, &multi);
994 wpa_printf(MSG_DEBUG,
995 "RADIUS DAS: Multiple sessions match - not supported");
996 return RADIUS_DAS_MULTI_SESSION_MATCH;
998 wpa_printf(MSG_DEBUG, "RADIUS DAS: No matching session found");
999 return RADIUS_DAS_SESSION_NOT_FOUND;
1002 wpa_printf(MSG_DEBUG, "RADIUS DAS: Found a matching session " MACSTR
1003 " - CoA", MAC2STR(sta->addr));
1005 if (attr->hs20_t_c_filtering) {
1006 if (attr->hs20_t_c_filtering[0] & BIT(0)) {
1007 wpa_printf(MSG_DEBUG,
1008 "HS 2.0: Unexpected Terms and Conditions filtering required in CoA-Request");
1009 return RADIUS_DAS_COA_FAILED;
1012 hs20_t_c_filtering(hapd, sta, 0);
1015 return RADIUS_DAS_SUCCESS;
1017 #else /* CONFIG_HS20 */
1018 #define hostapd_das_coa NULL
1019 #endif /* CONFIG_HS20 */
1021 #endif /* CONFIG_NO_RADIUS */
1025 * hostapd_setup_bss - Per-BSS setup (initialization)
1026 * @hapd: Pointer to BSS data
1027 * @first: Whether this BSS is the first BSS of an interface; -1 = not first,
1028 * but interface may exist
1030 * This function is used to initialize all per-BSS data structures and
1031 * resources. This gets called in a loop for each BSS when an interface is
1032 * initialized. Most of the modules that are initialized here will be
1033 * deinitialized in hostapd_cleanup().
1035 static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
1037 struct hostapd_bss_config *conf = hapd->conf;
1038 u8 ssid[SSID_MAX_LEN + 1];
1039 int ssid_len, set_ssid;
1040 char force_ifname[IFNAMSIZ];
1041 u8 if_addr[ETH_ALEN];
1042 int flush_old_stations = 1;
1044 wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s), first=%d)",
1045 __func__, hapd, conf->iface, first);
1047 #ifdef EAP_SERVER_TNC
1048 if (conf->tnc && tncs_global_init() < 0) {
1049 wpa_printf(MSG_ERROR, "Failed to initialize TNCS");
1052 #endif /* EAP_SERVER_TNC */
1054 if (hapd->started) {
1055 wpa_printf(MSG_ERROR, "%s: Interface %s was already started",
1056 __func__, conf->iface);
1061 if (!first || first == -1) {
1062 u8 *addr = hapd->own_addr;
1064 if (!is_zero_ether_addr(conf->bssid)) {
1065 /* Allocate the configured BSSID. */
1066 os_memcpy(hapd->own_addr, conf->bssid, ETH_ALEN);
1068 if (hostapd_mac_comp(hapd->own_addr,
1069 hapd->iface->bss[0]->own_addr) ==
1071 wpa_printf(MSG_ERROR, "BSS '%s' may not have "
1072 "BSSID set to the MAC address of "
1073 "the radio", conf->iface);
1076 } else if (hapd->iconf->use_driver_iface_addr) {
1079 /* Allocate the next available BSSID. */
1081 inc_byte_array(hapd->own_addr, ETH_ALEN);
1082 } while (mac_in_conf(hapd->iconf, hapd->own_addr));
1085 hapd->interface_added = 1;
1086 if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS,
1087 conf->iface, addr, hapd,
1088 &hapd->drv_priv, force_ifname, if_addr,
1089 conf->bridge[0] ? conf->bridge : NULL,
1091 wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
1092 MACSTR ")", MAC2STR(hapd->own_addr));
1093 hapd->interface_added = 0;
1098 os_memcpy(hapd->own_addr, if_addr, ETH_ALEN);
1101 if (conf->wmm_enabled < 0)
1102 conf->wmm_enabled = hapd->iconf->ieee80211n;
1104 #ifdef CONFIG_IEEE80211R_AP
1105 if (is_zero_ether_addr(conf->r1_key_holder))
1106 os_memcpy(conf->r1_key_holder, hapd->own_addr, ETH_ALEN);
1107 #endif /* CONFIG_IEEE80211R_AP */
1110 if ((hapd->conf->mesh & MESH_ENABLED) && hapd->iface->mconf == NULL)
1111 flush_old_stations = 0;
1112 #endif /* CONFIG_MESH */
1114 if (flush_old_stations)
1115 hostapd_flush_old_stations(hapd,
1116 WLAN_REASON_PREV_AUTH_NOT_VALID);
1117 hostapd_set_privacy(hapd, 0);
1119 hostapd_broadcast_wep_clear(hapd);
1120 if (hostapd_setup_encryption(conf->iface, hapd))
1124 * Fetch the SSID from the system and use it or,
1125 * if one was specified in the config file, verify they
1128 ssid_len = hostapd_get_ssid(hapd, ssid, sizeof(ssid));
1130 wpa_printf(MSG_ERROR, "Could not read SSID from system");
1133 if (conf->ssid.ssid_set) {
1135 * If SSID is specified in the config file and it differs
1136 * from what is being used then force installation of the
1139 set_ssid = (conf->ssid.ssid_len != (size_t) ssid_len ||
1140 os_memcmp(conf->ssid.ssid, ssid, ssid_len) != 0);
1143 * No SSID in the config file; just use the one we got
1147 conf->ssid.ssid_len = ssid_len;
1148 os_memcpy(conf->ssid.ssid, ssid, conf->ssid.ssid_len);
1151 if (!hostapd_drv_none(hapd)) {
1152 wpa_printf(MSG_ERROR, "Using interface %s with hwaddr " MACSTR
1154 conf->iface, MAC2STR(hapd->own_addr),
1155 wpa_ssid_txt(conf->ssid.ssid, conf->ssid.ssid_len));
1158 if (hostapd_setup_wpa_psk(conf)) {
1159 wpa_printf(MSG_ERROR, "WPA-PSK setup failed.");
1163 /* Set SSID for the kernel driver (to be used in beacon and probe
1164 * response frames) */
1165 if (set_ssid && hostapd_set_ssid(hapd, conf->ssid.ssid,
1166 conf->ssid.ssid_len)) {
1167 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
1171 if (wpa_debug_level <= MSG_MSGDUMP)
1172 conf->radius->msg_dumps = 1;
1173 #ifndef CONFIG_NO_RADIUS
1174 hapd->radius = radius_client_init(hapd, conf->radius);
1175 if (hapd->radius == NULL) {
1176 wpa_printf(MSG_ERROR, "RADIUS client initialization failed.");
1180 if (conf->radius_das_port) {
1181 struct radius_das_conf das_conf;
1182 os_memset(&das_conf, 0, sizeof(das_conf));
1183 das_conf.port = conf->radius_das_port;
1184 das_conf.shared_secret = conf->radius_das_shared_secret;
1185 das_conf.shared_secret_len =
1186 conf->radius_das_shared_secret_len;
1187 das_conf.client_addr = &conf->radius_das_client_addr;
1188 das_conf.time_window = conf->radius_das_time_window;
1189 das_conf.require_event_timestamp =
1190 conf->radius_das_require_event_timestamp;
1191 das_conf.require_message_authenticator =
1192 conf->radius_das_require_message_authenticator;
1193 das_conf.ctx = hapd;
1194 das_conf.disconnect = hostapd_das_disconnect;
1195 das_conf.coa = hostapd_das_coa;
1196 hapd->radius_das = radius_das_init(&das_conf);
1197 if (hapd->radius_das == NULL) {
1198 wpa_printf(MSG_ERROR, "RADIUS DAS initialization "
1203 #endif /* CONFIG_NO_RADIUS */
1205 if (hostapd_acl_init(hapd)) {
1206 wpa_printf(MSG_ERROR, "ACL initialization failed.");
1209 if (hostapd_init_wps(hapd, conf))
1213 hapd->gas = gas_query_ap_init(hapd, hapd->msg_ctx);
1216 if (hostapd_dpp_init(hapd))
1218 #endif /* CONFIG_DPP */
1220 if (authsrv_init(hapd) < 0)
1223 if (ieee802_1x_init(hapd)) {
1224 wpa_printf(MSG_ERROR, "IEEE 802.1X initialization failed.");
1228 if ((conf->wpa || conf->osen) && hostapd_setup_wpa(hapd))
1231 if (accounting_init(hapd)) {
1232 wpa_printf(MSG_ERROR, "Accounting initialization failed.");
1236 if (conf->ieee802_11f &&
1237 (hapd->iapp = iapp_init(hapd, conf->iapp_iface)) == NULL) {
1238 wpa_printf(MSG_ERROR, "IEEE 802.11F (IAPP) initialization "
1243 #ifdef CONFIG_INTERWORKING
1244 if (gas_serv_init(hapd)) {
1245 wpa_printf(MSG_ERROR, "GAS server initialization failed");
1249 if (conf->qos_map_set_len &&
1250 hostapd_drv_set_qos_map(hapd, conf->qos_map_set,
1251 conf->qos_map_set_len)) {
1252 wpa_printf(MSG_ERROR, "Failed to initialize QoS Map");
1255 #endif /* CONFIG_INTERWORKING */
1257 if (conf->bss_load_update_period && bss_load_update_init(hapd)) {
1258 wpa_printf(MSG_ERROR, "BSS Load initialization failed");
1262 if (conf->proxy_arp) {
1263 if (x_snoop_init(hapd)) {
1264 wpa_printf(MSG_ERROR,
1265 "Generic snooping infrastructure initialization failed");
1269 if (dhcp_snoop_init(hapd)) {
1270 wpa_printf(MSG_ERROR,
1271 "DHCP snooping initialization failed");
1275 if (ndisc_snoop_init(hapd)) {
1276 wpa_printf(MSG_ERROR,
1277 "Neighbor Discovery snooping initialization failed");
1282 if (!hostapd_drv_none(hapd) && vlan_init(hapd)) {
1283 wpa_printf(MSG_ERROR, "VLAN initialization failed.");
1287 if (!conf->start_disabled && ieee802_11_set_beacon(hapd) < 0)
1290 if (hapd->wpa_auth && wpa_init_keys(hapd->wpa_auth) < 0)
1293 if (hapd->driver && hapd->driver->set_operstate)
1294 hapd->driver->set_operstate(hapd->drv_priv, 1);
1300 static void hostapd_tx_queue_params(struct hostapd_iface *iface)
1302 struct hostapd_data *hapd = iface->bss[0];
1304 struct hostapd_tx_queue_params *p;
1307 if ((hapd->conf->mesh & MESH_ENABLED) && iface->mconf == NULL)
1309 #endif /* CONFIG_MESH */
1311 for (i = 0; i < NUM_TX_QUEUES; i++) {
1312 p = &iface->conf->tx_queue[i];
1314 if (hostapd_set_tx_queue_params(hapd, i, p->aifs, p->cwmin,
1315 p->cwmax, p->burst)) {
1316 wpa_printf(MSG_DEBUG, "Failed to set TX queue "
1317 "parameters for queue %d.", i);
1318 /* Continue anyway */
1324 static int hostapd_set_acl_list(struct hostapd_data *hapd,
1325 struct mac_acl_entry *mac_acl,
1326 int n_entries, u8 accept_acl)
1328 struct hostapd_acl_params *acl_params;
1331 acl_params = os_zalloc(sizeof(*acl_params) +
1332 (n_entries * sizeof(acl_params->mac_acl[0])));
1336 for (i = 0; i < n_entries; i++)
1337 os_memcpy(acl_params->mac_acl[i].addr, mac_acl[i].addr,
1340 acl_params->acl_policy = accept_acl;
1341 acl_params->num_mac_acl = n_entries;
1343 err = hostapd_drv_set_acl(hapd, acl_params);
1345 os_free(acl_params);
1351 static void hostapd_set_acl(struct hostapd_data *hapd)
1353 struct hostapd_config *conf = hapd->iconf;
1357 if (hapd->iface->drv_max_acl_mac_addrs == 0)
1360 if (conf->bss[0]->macaddr_acl == DENY_UNLESS_ACCEPTED) {
1362 err = hostapd_set_acl_list(hapd, conf->bss[0]->accept_mac,
1363 conf->bss[0]->num_accept_mac,
1366 wpa_printf(MSG_DEBUG, "Failed to set accept acl");
1369 } else if (conf->bss[0]->macaddr_acl == ACCEPT_UNLESS_DENIED) {
1371 err = hostapd_set_acl_list(hapd, conf->bss[0]->deny_mac,
1372 conf->bss[0]->num_deny_mac,
1375 wpa_printf(MSG_DEBUG, "Failed to set deny acl");
1382 static int start_ctrl_iface_bss(struct hostapd_data *hapd)
1384 if (!hapd->iface->interfaces ||
1385 !hapd->iface->interfaces->ctrl_iface_init)
1388 if (hapd->iface->interfaces->ctrl_iface_init(hapd)) {
1389 wpa_printf(MSG_ERROR,
1390 "Failed to setup control interface for %s",
1399 static int start_ctrl_iface(struct hostapd_iface *iface)
1403 if (!iface->interfaces || !iface->interfaces->ctrl_iface_init)
1406 for (i = 0; i < iface->num_bss; i++) {
1407 struct hostapd_data *hapd = iface->bss[i];
1408 if (iface->interfaces->ctrl_iface_init(hapd)) {
1409 wpa_printf(MSG_ERROR,
1410 "Failed to setup control interface for %s",
1420 static void channel_list_update_timeout(void *eloop_ctx, void *timeout_ctx)
1422 struct hostapd_iface *iface = eloop_ctx;
1424 if (!iface->wait_channel_update) {
1425 wpa_printf(MSG_INFO, "Channel list update timeout, but interface was not waiting for it");
1430 * It is possible that the existing channel list is acceptable, so try
1433 wpa_printf(MSG_DEBUG, "Channel list update timeout - try to continue anyway");
1434 setup_interface2(iface);
1438 void hostapd_channel_list_updated(struct hostapd_iface *iface, int initiator)
1440 if (!iface->wait_channel_update || initiator != REGDOM_SET_BY_USER)
1443 wpa_printf(MSG_DEBUG, "Channel list updated - continue setup");
1444 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
1445 setup_interface2(iface);
1449 static int setup_interface(struct hostapd_iface *iface)
1451 struct hostapd_data *hapd = iface->bss[0];
1455 * It is possible that setup_interface() is called after the interface
1456 * was disabled etc., in which case driver_ap_teardown is possibly set
1457 * to 1. Clear it here so any other key/station deletion, which is not
1458 * part of a teardown flow, would also call the relevant driver
1461 iface->driver_ap_teardown = 0;
1463 if (!iface->phy[0]) {
1464 const char *phy = hostapd_drv_get_radio_name(hapd);
1466 wpa_printf(MSG_DEBUG, "phy: %s", phy);
1467 os_strlcpy(iface->phy, phy, sizeof(iface->phy));
1472 * Make sure that all BSSes get configured with a pointer to the same
1475 for (i = 1; i < iface->num_bss; i++) {
1476 iface->bss[i]->driver = hapd->driver;
1477 iface->bss[i]->drv_priv = hapd->drv_priv;
1480 if (hostapd_validate_bssid_configuration(iface))
1484 * Initialize control interfaces early to allow external monitoring of
1485 * channel setup operations that may take considerable amount of time
1486 * especially for DFS cases.
1488 if (start_ctrl_iface(iface))
1491 if (hapd->iconf->country[0] && hapd->iconf->country[1]) {
1492 char country[4], previous_country[4];
1494 hostapd_set_state(iface, HAPD_IFACE_COUNTRY_UPDATE);
1495 if (hostapd_get_country(hapd, previous_country) < 0)
1496 previous_country[0] = '\0';
1498 os_memcpy(country, hapd->iconf->country, 3);
1500 if (hostapd_set_country(hapd, country) < 0) {
1501 wpa_printf(MSG_ERROR, "Failed to set country code");
1505 wpa_printf(MSG_DEBUG, "Previous country code %s, new country code %s",
1506 previous_country, country);
1508 if (os_strncmp(previous_country, country, 2) != 0) {
1509 wpa_printf(MSG_DEBUG, "Continue interface setup after channel list update");
1510 iface->wait_channel_update = 1;
1511 eloop_register_timeout(5, 0,
1512 channel_list_update_timeout,
1518 return setup_interface2(iface);
1522 static int setup_interface2(struct hostapd_iface *iface)
1524 iface->wait_channel_update = 0;
1526 if (hostapd_get_hw_features(iface)) {
1527 /* Not all drivers support this yet, so continue without hw
1530 int ret = hostapd_select_hw_mode(iface);
1532 wpa_printf(MSG_ERROR, "Could not select hw_mode and "
1533 "channel. (%d)", ret);
1537 wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback (ACS)");
1540 ret = hostapd_check_ht_capab(iface);
1544 wpa_printf(MSG_DEBUG, "Interface initialization will "
1545 "be completed in a callback");
1549 if (iface->conf->ieee80211h)
1550 wpa_printf(MSG_DEBUG, "DFS support is enabled");
1552 return hostapd_setup_interface_complete(iface, 0);
1555 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
1556 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
1557 if (iface->interfaces && iface->interfaces->terminate_on_error)
1565 static const u8 * fst_hostapd_get_bssid_cb(void *ctx)
1567 struct hostapd_data *hapd = ctx;
1569 return hapd->own_addr;
1573 static void fst_hostapd_get_channel_info_cb(void *ctx,
1574 enum hostapd_hw_mode *hw_mode,
1577 struct hostapd_data *hapd = ctx;
1579 *hw_mode = ieee80211_freq_to_chan(hapd->iface->freq, channel);
1583 static void fst_hostapd_set_ies_cb(void *ctx, const struct wpabuf *fst_ies)
1585 struct hostapd_data *hapd = ctx;
1587 if (hapd->iface->fst_ies != fst_ies) {
1588 hapd->iface->fst_ies = fst_ies;
1589 if (ieee802_11_set_beacon(hapd))
1590 wpa_printf(MSG_WARNING, "FST: Cannot set beacon");
1595 static int fst_hostapd_send_action_cb(void *ctx, const u8 *da,
1598 struct hostapd_data *hapd = ctx;
1600 return hostapd_drv_send_action(hapd, hapd->iface->freq, 0, da,
1601 wpabuf_head(buf), wpabuf_len(buf));
1605 static const struct wpabuf * fst_hostapd_get_mb_ie_cb(void *ctx, const u8 *addr)
1607 struct hostapd_data *hapd = ctx;
1608 struct sta_info *sta = ap_get_sta(hapd, addr);
1610 return sta ? sta->mb_ies : NULL;
1614 static void fst_hostapd_update_mb_ie_cb(void *ctx, const u8 *addr,
1615 const u8 *buf, size_t size)
1617 struct hostapd_data *hapd = ctx;
1618 struct sta_info *sta = ap_get_sta(hapd, addr);
1621 struct mb_ies_info info;
1623 if (!mb_ies_info_by_ies(&info, buf, size)) {
1624 wpabuf_free(sta->mb_ies);
1625 sta->mb_ies = mb_ies_by_info(&info);
1631 static const u8 * fst_hostapd_get_sta(struct fst_get_peer_ctx **get_ctx,
1634 struct sta_info *s = (struct sta_info *) *get_ctx;
1637 for (; s && !s->mb_ies; s = s->next)
1642 *get_ctx = (struct fst_get_peer_ctx *) s->next;
1652 static const u8 * fst_hostapd_get_peer_first(void *ctx,
1653 struct fst_get_peer_ctx **get_ctx,
1656 struct hostapd_data *hapd = ctx;
1658 *get_ctx = (struct fst_get_peer_ctx *) hapd->sta_list;
1660 return fst_hostapd_get_sta(get_ctx, mb_only);
1664 static const u8 * fst_hostapd_get_peer_next(void *ctx,
1665 struct fst_get_peer_ctx **get_ctx,
1668 return fst_hostapd_get_sta(get_ctx, mb_only);
1672 void fst_hostapd_fill_iface_obj(struct hostapd_data *hapd,
1673 struct fst_wpa_obj *iface_obj)
1675 iface_obj->ctx = hapd;
1676 iface_obj->get_bssid = fst_hostapd_get_bssid_cb;
1677 iface_obj->get_channel_info = fst_hostapd_get_channel_info_cb;
1678 iface_obj->set_ies = fst_hostapd_set_ies_cb;
1679 iface_obj->send_action = fst_hostapd_send_action_cb;
1680 iface_obj->get_mb_ie = fst_hostapd_get_mb_ie_cb;
1681 iface_obj->update_mb_ie = fst_hostapd_update_mb_ie_cb;
1682 iface_obj->get_peer_first = fst_hostapd_get_peer_first;
1683 iface_obj->get_peer_next = fst_hostapd_get_peer_next;
1686 #endif /* CONFIG_FST */
1690 static int hostapd_owe_iface_iter(struct hostapd_iface *iface, void *ctx)
1692 struct hostapd_data *hapd = ctx;
1695 for (i = 0; i < iface->num_bss; i++) {
1696 struct hostapd_data *bss = iface->bss[i];
1698 if (os_strcmp(hapd->conf->owe_transition_ifname,
1699 bss->conf->iface) != 0)
1702 wpa_printf(MSG_DEBUG,
1703 "OWE: ifname=%s found transition mode ifname=%s BSSID "
1705 hapd->conf->iface, bss->conf->iface,
1706 MAC2STR(bss->own_addr),
1707 wpa_ssid_txt(bss->conf->ssid.ssid,
1708 bss->conf->ssid.ssid_len));
1709 if (!bss->conf->ssid.ssid_set || !bss->conf->ssid.ssid_len ||
1710 is_zero_ether_addr(bss->own_addr))
1713 os_memcpy(hapd->conf->owe_transition_bssid, bss->own_addr,
1715 os_memcpy(hapd->conf->owe_transition_ssid,
1716 bss->conf->ssid.ssid, bss->conf->ssid.ssid_len);
1717 hapd->conf->owe_transition_ssid_len = bss->conf->ssid.ssid_len;
1718 wpa_printf(MSG_DEBUG,
1719 "OWE: Copied transition mode information");
1727 int hostapd_owe_trans_get_info(struct hostapd_data *hapd)
1729 if (hapd->conf->owe_transition_ssid_len > 0 &&
1730 !is_zero_ether_addr(hapd->conf->owe_transition_bssid))
1733 /* Find transition mode SSID/BSSID information from a BSS operated by
1734 * this hostapd instance. */
1735 if (!hapd->iface->interfaces ||
1736 !hapd->iface->interfaces->for_each_interface)
1737 return hostapd_owe_iface_iter(hapd->iface, hapd);
1739 return hapd->iface->interfaces->for_each_interface(
1740 hapd->iface->interfaces, hostapd_owe_iface_iter, hapd);
1744 static int hostapd_owe_iface_iter2(struct hostapd_iface *iface, void *ctx)
1748 for (i = 0; i < iface->num_bss; i++) {
1749 struct hostapd_data *bss = iface->bss[i];
1752 if (!bss->conf->owe_transition_ifname[0])
1754 res = hostapd_owe_trans_get_info(bss);
1757 wpa_printf(MSG_DEBUG,
1758 "OWE: Matching transition mode interface enabled - update beacon data for %s",
1760 ieee802_11_set_beacon(bss);
1766 #endif /* CONFIG_OWE */
1769 static void hostapd_owe_update_trans(struct hostapd_iface *iface)
1772 /* Check whether the enabled BSS can complete OWE transition mode
1773 * configuration for any pending interface. */
1774 if (!iface->interfaces ||
1775 !iface->interfaces->for_each_interface)
1776 hostapd_owe_iface_iter2(iface, NULL);
1778 iface->interfaces->for_each_interface(
1779 iface->interfaces, hostapd_owe_iface_iter2, NULL);
1780 #endif /* CONFIG_OWE */
1784 static void hostapd_interface_setup_failure_handler(void *eloop_ctx,
1787 struct hostapd_iface *iface = eloop_ctx;
1788 struct hostapd_data *hapd;
1790 if (iface->num_bss < 1 || !iface->bss || !iface->bss[0])
1792 hapd = iface->bss[0];
1793 if (hapd->setup_complete_cb)
1794 hapd->setup_complete_cb(hapd->setup_complete_cb_ctx);
1798 static int hostapd_setup_interface_complete_sync(struct hostapd_iface *iface,
1801 struct hostapd_data *hapd = iface->bss[0];
1804 int delay_apply_cfg = 0;
1805 int res_dfs_offload = 0;
1810 wpa_printf(MSG_DEBUG, "Completing interface initialization");
1811 if (iface->conf->channel) {
1814 #endif /* NEED_AP_MLME */
1816 iface->freq = hostapd_hw_get_freq(hapd, iface->conf->channel);
1817 wpa_printf(MSG_DEBUG, "Mode: %s Channel: %d "
1818 "Frequency: %d MHz",
1819 hostapd_hw_mode_txt(iface->conf->hw_mode),
1820 iface->conf->channel, iface->freq);
1823 /* Handle DFS only if it is not offloaded to the driver */
1824 if (!(iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)) {
1826 res = hostapd_handle_dfs(iface);
1833 /* If DFS is offloaded to the driver */
1834 res_dfs_offload = hostapd_handle_dfs_offload(iface);
1835 if (res_dfs_offload <= 0) {
1836 if (res_dfs_offload < 0)
1839 wpa_printf(MSG_DEBUG,
1840 "Proceed with AP/channel setup");
1842 * If this is a DFS channel, move to completing
1845 if (res_dfs_offload == 1)
1847 /* Otherwise fall through. */
1850 #endif /* NEED_AP_MLME */
1853 if (iface->mconf != NULL) {
1854 wpa_printf(MSG_DEBUG,
1855 "%s: Mesh configuration will be applied while joining the mesh network",
1856 iface->bss[0]->conf->iface);
1857 delay_apply_cfg = 1;
1859 #endif /* CONFIG_MESH */
1861 if (!delay_apply_cfg &&
1862 hostapd_set_freq(hapd, hapd->iconf->hw_mode, iface->freq,
1863 hapd->iconf->channel,
1864 hapd->iconf->ieee80211n,
1865 hapd->iconf->ieee80211ac,
1866 hapd->iconf->secondary_channel,
1867 hapd->iconf->vht_oper_chwidth,
1868 hapd->iconf->vht_oper_centr_freq_seg0_idx,
1869 hapd->iconf->vht_oper_centr_freq_seg1_idx)) {
1870 wpa_printf(MSG_ERROR, "Could not set channel for "
1876 if (iface->current_mode) {
1877 if (hostapd_prepare_rates(iface, iface->current_mode)) {
1878 wpa_printf(MSG_ERROR, "Failed to prepare rates "
1880 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1881 HOSTAPD_LEVEL_WARNING,
1882 "Failed to prepare rates table.");
1887 if (hapd->iconf->rts_threshold >= -1 &&
1888 hostapd_set_rts(hapd, hapd->iconf->rts_threshold) &&
1889 hapd->iconf->rts_threshold >= -1) {
1890 wpa_printf(MSG_ERROR, "Could not set RTS threshold for "
1895 if (hapd->iconf->fragm_threshold >= -1 &&
1896 hostapd_set_frag(hapd, hapd->iconf->fragm_threshold) &&
1897 hapd->iconf->fragm_threshold != -1) {
1898 wpa_printf(MSG_ERROR, "Could not set fragmentation threshold "
1899 "for kernel driver");
1903 prev_addr = hapd->own_addr;
1905 for (j = 0; j < iface->num_bss; j++) {
1906 hapd = iface->bss[j];
1908 os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN);
1909 if (hostapd_setup_bss(hapd, j == 0)) {
1911 hapd = iface->bss[j];
1912 hostapd_bss_deinit_no_free(hapd);
1913 hostapd_free_hapd_data(hapd);
1920 if (is_zero_ether_addr(hapd->conf->bssid))
1921 prev_addr = hapd->own_addr;
1923 hapd = iface->bss[0];
1925 hostapd_tx_queue_params(iface);
1927 ap_list_init(iface);
1929 hostapd_set_acl(hapd);
1931 if (hostapd_driver_commit(hapd) < 0) {
1932 wpa_printf(MSG_ERROR, "%s: Failed to commit driver "
1933 "configuration", __func__);
1938 * WPS UPnP module can be initialized only when the "upnp_iface" is up.
1939 * If "interface" and "upnp_iface" are the same (e.g., non-bridge
1940 * mode), the interface is up only after driver_commit, so initialize
1941 * WPS after driver_commit.
1943 for (j = 0; j < iface->num_bss; j++) {
1944 if (hostapd_init_wps_complete(iface->bss[j]))
1948 if ((iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) &&
1951 * If freq is DFS, and DFS is offloaded to the driver, then wait
1952 * for CAC to complete.
1954 wpa_printf(MSG_DEBUG, "%s: Wait for CAC to complete", __func__);
1955 return res_dfs_offload;
1960 #endif /* NEED_AP_MLME */
1963 if (hapd->iconf->fst_cfg.group_id[0]) {
1964 struct fst_wpa_obj iface_obj;
1966 fst_hostapd_fill_iface_obj(hapd, &iface_obj);
1967 iface->fst = fst_attach(hapd->conf->iface, hapd->own_addr,
1968 &iface_obj, &hapd->iconf->fst_cfg);
1970 wpa_printf(MSG_ERROR, "Could not attach to FST %s",
1971 hapd->iconf->fst_cfg.group_id);
1975 #endif /* CONFIG_FST */
1977 hostapd_set_state(iface, HAPD_IFACE_ENABLED);
1978 hostapd_owe_update_trans(iface);
1979 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_ENABLED);
1980 if (hapd->setup_complete_cb)
1981 hapd->setup_complete_cb(hapd->setup_complete_cb_ctx);
1983 wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
1984 iface->bss[0]->conf->iface);
1985 if (iface->interfaces && iface->interfaces->terminate_on_error > 0)
1986 iface->interfaces->terminate_on_error--;
1988 for (j = 0; j < iface->num_bss; j++)
1989 hostapd_neighbor_set_own_report(iface->bss[j]);
1994 wpa_printf(MSG_ERROR, "Interface initialization failed");
1995 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
1996 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
1999 fst_detach(iface->fst);
2002 #endif /* CONFIG_FST */
2004 if (iface->interfaces && iface->interfaces->terminate_on_error) {
2006 } else if (hapd->setup_complete_cb) {
2008 * Calling hapd->setup_complete_cb directly may cause iface
2009 * deinitialization which may be accessed later by the caller.
2011 eloop_register_timeout(0, 0,
2012 hostapd_interface_setup_failure_handler,
2021 * hostapd_setup_interface_complete - Complete interface setup
2023 * This function is called when previous steps in the interface setup has been
2024 * completed. This can also start operations, e.g., DFS, that will require
2025 * additional processing before interface is ready to be enabled. Such
2026 * operations will call this function from eloop callbacks when finished.
2028 int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err)
2030 struct hapd_interfaces *interfaces = iface->interfaces;
2031 struct hostapd_data *hapd = iface->bss[0];
2033 int not_ready_in_sync_ifaces = 0;
2035 if (!iface->need_to_start_in_sync)
2036 return hostapd_setup_interface_complete_sync(iface, err);
2039 wpa_printf(MSG_ERROR, "Interface initialization failed");
2040 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
2041 iface->need_to_start_in_sync = 0;
2042 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
2043 if (interfaces && interfaces->terminate_on_error)
2048 if (iface->ready_to_start_in_sync) {
2049 /* Already in ready and waiting. should never happpen */
2053 for (i = 0; i < interfaces->count; i++) {
2054 if (interfaces->iface[i]->need_to_start_in_sync &&
2055 !interfaces->iface[i]->ready_to_start_in_sync)
2056 not_ready_in_sync_ifaces++;
2060 * Check if this is the last interface, if yes then start all the other
2061 * waiting interfaces. If not, add this interface to the waiting list.
2063 if (not_ready_in_sync_ifaces > 1 && iface->state == HAPD_IFACE_DFS) {
2065 * If this interface went through CAC, do not synchronize, just
2066 * start immediately.
2068 iface->need_to_start_in_sync = 0;
2069 wpa_printf(MSG_INFO,
2070 "%s: Finished CAC - bypass sync and start interface",
2071 iface->bss[0]->conf->iface);
2072 return hostapd_setup_interface_complete_sync(iface, err);
2075 if (not_ready_in_sync_ifaces > 1) {
2076 /* need to wait as there are other interfaces still coming up */
2077 iface->ready_to_start_in_sync = 1;
2078 wpa_printf(MSG_INFO,
2079 "%s: Interface waiting to sync with other interfaces",
2080 iface->bss[0]->conf->iface);
2084 wpa_printf(MSG_INFO,
2085 "%s: Last interface to sync - starting all interfaces",
2086 iface->bss[0]->conf->iface);
2087 iface->need_to_start_in_sync = 0;
2088 hostapd_setup_interface_complete_sync(iface, err);
2089 for (i = 0; i < interfaces->count; i++) {
2090 if (interfaces->iface[i]->need_to_start_in_sync &&
2091 interfaces->iface[i]->ready_to_start_in_sync) {
2092 hostapd_setup_interface_complete_sync(
2093 interfaces->iface[i], 0);
2094 /* Only once the interfaces are sync started */
2095 interfaces->iface[i]->need_to_start_in_sync = 0;
2104 * hostapd_setup_interface - Setup of an interface
2105 * @iface: Pointer to interface data.
2106 * Returns: 0 on success, -1 on failure
2108 * Initializes the driver interface, validates the configuration,
2109 * and sets driver parameters based on the configuration.
2110 * Flushes old stations, sets the channel, encryption,
2111 * beacons, and WDS links based on the configuration.
2113 * If interface setup requires more time, e.g., to perform HT co-ex scans, ACS,
2114 * or DFS operations, this function returns 0 before such operations have been
2115 * completed. The pending operations are registered into eloop and will be
2116 * completed from eloop callbacks. Those callbacks end up calling
2117 * hostapd_setup_interface_complete() once setup has been completed.
2119 int hostapd_setup_interface(struct hostapd_iface *iface)
2123 ret = setup_interface(iface);
2125 wpa_printf(MSG_ERROR, "%s: Unable to setup interface.",
2126 iface->bss[0]->conf->iface);
2135 * hostapd_alloc_bss_data - Allocate and initialize per-BSS data
2136 * @hapd_iface: Pointer to interface data
2137 * @conf: Pointer to per-interface configuration
2138 * @bss: Pointer to per-BSS configuration for this BSS
2139 * Returns: Pointer to allocated BSS data
2141 * This function is used to allocate per-BSS data structure. This data will be
2142 * freed after hostapd_cleanup() is called for it during interface
2145 struct hostapd_data *
2146 hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
2147 struct hostapd_config *conf,
2148 struct hostapd_bss_config *bss)
2150 struct hostapd_data *hapd;
2152 hapd = os_zalloc(sizeof(*hapd));
2156 hapd->new_assoc_sta_cb = hostapd_new_assoc_sta;
2159 hapd->iface = hapd_iface;
2161 hapd->driver = conf->driver;
2162 hapd->ctrl_sock = -1;
2163 dl_list_init(&hapd->ctrl_dst);
2164 dl_list_init(&hapd->nr_db);
2165 hapd->dhcp_sock = -1;
2166 #ifdef CONFIG_IEEE80211R_AP
2167 dl_list_init(&hapd->l2_queue);
2168 dl_list_init(&hapd->l2_oui_queue);
2169 #endif /* CONFIG_IEEE80211R_AP */
2171 dl_list_init(&hapd->sae_commit_queue);
2172 #endif /* CONFIG_SAE */
2178 static void hostapd_bss_deinit(struct hostapd_data *hapd)
2182 wpa_printf(MSG_DEBUG, "%s: deinit bss %s", __func__,
2183 hapd->conf ? hapd->conf->iface : "N/A");
2184 hostapd_bss_deinit_no_free(hapd);
2185 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
2186 hostapd_cleanup(hapd);
2190 void hostapd_interface_deinit(struct hostapd_iface *iface)
2194 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
2198 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
2200 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
2201 iface->wait_channel_update = 0;
2205 fst_detach(iface->fst);
2208 #endif /* CONFIG_FST */
2210 for (j = (int) iface->num_bss - 1; j >= 0; j--) {
2213 hostapd_bss_deinit(iface->bss[j]);
2216 #ifdef CONFIG_IEEE80211N
2218 hostapd_stop_setup_timers(iface);
2219 eloop_cancel_timeout(ap_ht2040_timeout, iface, NULL);
2220 #endif /* NEED_AP_MLME */
2221 #endif /* CONFIG_IEEE80211N */
2225 void hostapd_interface_free(struct hostapd_iface *iface)
2228 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
2229 for (j = 0; j < iface->num_bss; j++) {
2232 wpa_printf(MSG_DEBUG, "%s: free hapd %p",
2233 __func__, iface->bss[j]);
2234 os_free(iface->bss[j]);
2236 hostapd_cleanup_iface(iface);
2240 struct hostapd_iface * hostapd_alloc_iface(void)
2242 struct hostapd_iface *hapd_iface;
2244 hapd_iface = os_zalloc(sizeof(*hapd_iface));
2248 dl_list_init(&hapd_iface->sta_seen);
2255 * hostapd_init - Allocate and initialize per-interface data
2256 * @config_file: Path to the configuration file
2257 * Returns: Pointer to the allocated interface data or %NULL on failure
2259 * This function is used to allocate main data structures for per-interface
2260 * data. The allocated data buffer will be freed by calling
2261 * hostapd_cleanup_iface().
2263 struct hostapd_iface * hostapd_init(struct hapd_interfaces *interfaces,
2264 const char *config_file)
2266 struct hostapd_iface *hapd_iface = NULL;
2267 struct hostapd_config *conf = NULL;
2268 struct hostapd_data *hapd;
2271 hapd_iface = hostapd_alloc_iface();
2272 if (hapd_iface == NULL)
2275 hapd_iface->config_fname = os_strdup(config_file);
2276 if (hapd_iface->config_fname == NULL)
2279 conf = interfaces->config_read_cb(hapd_iface->config_fname);
2282 hapd_iface->conf = conf;
2284 hapd_iface->num_bss = conf->num_bss;
2285 hapd_iface->bss = os_calloc(conf->num_bss,
2286 sizeof(struct hostapd_data *));
2287 if (hapd_iface->bss == NULL)
2290 for (i = 0; i < conf->num_bss; i++) {
2291 hapd = hapd_iface->bss[i] =
2292 hostapd_alloc_bss_data(hapd_iface, conf,
2296 hapd->msg_ctx = hapd;
2302 wpa_printf(MSG_ERROR, "Failed to set up interface with %s",
2305 hostapd_config_free(conf);
2307 os_free(hapd_iface->config_fname);
2308 os_free(hapd_iface->bss);
2309 wpa_printf(MSG_DEBUG, "%s: free iface %p",
2310 __func__, hapd_iface);
2311 os_free(hapd_iface);
2317 static int ifname_in_use(struct hapd_interfaces *interfaces, const char *ifname)
2321 for (i = 0; i < interfaces->count; i++) {
2322 struct hostapd_iface *iface = interfaces->iface[i];
2323 for (j = 0; j < iface->num_bss; j++) {
2324 struct hostapd_data *hapd = iface->bss[j];
2325 if (os_strcmp(ifname, hapd->conf->iface) == 0)
2335 * hostapd_interface_init_bss - Read configuration file and init BSS data
2337 * This function is used to parse configuration file for a BSS. This BSS is
2338 * added to an existing interface sharing the same radio (if any) or a new
2339 * interface is created if this is the first interface on a radio. This
2340 * allocate memory for the BSS. No actual driver operations are started.
2342 * This is similar to hostapd_interface_init(), but for a case where the
2343 * configuration is used to add a single BSS instead of all BSSes for a radio.
2345 struct hostapd_iface *
2346 hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy,
2347 const char *config_fname, int debug)
2349 struct hostapd_iface *new_iface = NULL, *iface = NULL;
2350 struct hostapd_data *hapd;
2357 for (i = 0; i < interfaces->count; i++) {
2358 if (os_strcmp(interfaces->iface[i]->phy, phy) == 0) {
2359 iface = interfaces->iface[i];
2364 wpa_printf(MSG_INFO, "Configuration file: %s (phy %s)%s",
2365 config_fname, phy, iface ? "" : " --> new PHY");
2367 struct hostapd_config *conf;
2368 struct hostapd_bss_config **tmp_conf;
2369 struct hostapd_data **tmp_bss;
2370 struct hostapd_bss_config *bss;
2373 /* Add new BSS to existing iface */
2374 conf = interfaces->config_read_cb(config_fname);
2377 if (conf->num_bss > 1) {
2378 wpa_printf(MSG_ERROR, "Multiple BSSes specified in BSS-config");
2379 hostapd_config_free(conf);
2383 ifname = conf->bss[0]->iface;
2384 if (ifname[0] != '\0' && ifname_in_use(interfaces, ifname)) {
2385 wpa_printf(MSG_ERROR,
2386 "Interface name %s already in use", ifname);
2387 hostapd_config_free(conf);
2391 tmp_conf = os_realloc_array(
2392 iface->conf->bss, iface->conf->num_bss + 1,
2393 sizeof(struct hostapd_bss_config *));
2394 tmp_bss = os_realloc_array(iface->bss, iface->num_bss + 1,
2395 sizeof(struct hostapd_data *));
2397 iface->bss = tmp_bss;
2399 iface->conf->bss = tmp_conf;
2400 iface->conf->last_bss = tmp_conf[0];
2402 if (tmp_bss == NULL || tmp_conf == NULL) {
2403 hostapd_config_free(conf);
2406 bss = iface->conf->bss[iface->conf->num_bss] = conf->bss[0];
2407 iface->conf->num_bss++;
2409 hapd = hostapd_alloc_bss_data(iface, iface->conf, bss);
2411 iface->conf->num_bss--;
2412 hostapd_config_free(conf);
2415 iface->conf->last_bss = bss;
2416 iface->bss[iface->num_bss] = hapd;
2417 hapd->msg_ctx = hapd;
2419 bss_idx = iface->num_bss++;
2421 conf->bss[0] = NULL;
2422 hostapd_config_free(conf);
2424 /* Add a new iface with the first BSS */
2425 new_iface = iface = hostapd_init(interfaces, config_fname);
2428 os_strlcpy(iface->phy, phy, sizeof(iface->phy));
2429 iface->interfaces = interfaces;
2433 for (k = 0; k < debug; k++) {
2434 if (iface->bss[bss_idx]->conf->logger_stdout_level > 0)
2435 iface->bss[bss_idx]->conf->logger_stdout_level--;
2438 if (iface->conf->bss[bss_idx]->iface[0] == '\0' &&
2439 !hostapd_drv_none(iface->bss[bss_idx])) {
2440 wpa_printf(MSG_ERROR, "Interface name not specified in %s",
2443 hostapd_interface_deinit_free(new_iface);
2451 void hostapd_interface_deinit_free(struct hostapd_iface *iface)
2453 const struct wpa_driver_ops *driver;
2456 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
2459 wpa_printf(MSG_DEBUG, "%s: num_bss=%u conf->num_bss=%u",
2460 __func__, (unsigned int) iface->num_bss,
2461 (unsigned int) iface->conf->num_bss);
2462 driver = iface->bss[0]->driver;
2463 drv_priv = iface->bss[0]->drv_priv;
2464 hostapd_interface_deinit(iface);
2465 wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
2466 __func__, driver, drv_priv);
2467 if (driver && driver->hapd_deinit && drv_priv) {
2468 driver->hapd_deinit(drv_priv);
2469 iface->bss[0]->drv_priv = NULL;
2471 hostapd_interface_free(iface);
2475 static void hostapd_deinit_driver(const struct wpa_driver_ops *driver,
2477 struct hostapd_iface *hapd_iface)
2481 wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
2482 __func__, driver, drv_priv);
2483 if (driver && driver->hapd_deinit && drv_priv) {
2484 driver->hapd_deinit(drv_priv);
2485 for (j = 0; j < hapd_iface->num_bss; j++) {
2486 wpa_printf(MSG_DEBUG, "%s:bss[%d]->drv_priv=%p",
2488 hapd_iface->bss[j]->drv_priv);
2489 if (hapd_iface->bss[j]->drv_priv == drv_priv)
2490 hapd_iface->bss[j]->drv_priv = NULL;
2496 int hostapd_enable_iface(struct hostapd_iface *hapd_iface)
2500 if (hapd_iface->bss[0]->drv_priv != NULL) {
2501 wpa_printf(MSG_ERROR, "Interface %s already enabled",
2502 hapd_iface->conf->bss[0]->iface);
2506 wpa_printf(MSG_DEBUG, "Enable interface %s",
2507 hapd_iface->conf->bss[0]->iface);
2509 for (j = 0; j < hapd_iface->num_bss; j++)
2510 hostapd_set_security_params(hapd_iface->conf->bss[j], 1);
2511 if (hostapd_config_check(hapd_iface->conf, 1) < 0) {
2512 wpa_printf(MSG_INFO, "Invalid configuration - cannot enable");
2516 if (hapd_iface->interfaces == NULL ||
2517 hapd_iface->interfaces->driver_init == NULL ||
2518 hapd_iface->interfaces->driver_init(hapd_iface))
2521 if (hostapd_setup_interface(hapd_iface)) {
2522 hostapd_deinit_driver(hapd_iface->bss[0]->driver,
2523 hapd_iface->bss[0]->drv_priv,
2532 int hostapd_reload_iface(struct hostapd_iface *hapd_iface)
2536 wpa_printf(MSG_DEBUG, "Reload interface %s",
2537 hapd_iface->conf->bss[0]->iface);
2538 for (j = 0; j < hapd_iface->num_bss; j++)
2539 hostapd_set_security_params(hapd_iface->conf->bss[j], 1);
2540 if (hostapd_config_check(hapd_iface->conf, 1) < 0) {
2541 wpa_printf(MSG_ERROR, "Updated configuration is invalid");
2544 hostapd_clear_old(hapd_iface);
2545 for (j = 0; j < hapd_iface->num_bss; j++)
2546 hostapd_reload_bss(hapd_iface->bss[j]);
2552 int hostapd_disable_iface(struct hostapd_iface *hapd_iface)
2555 const struct wpa_driver_ops *driver;
2558 if (hapd_iface == NULL)
2561 if (hapd_iface->bss[0]->drv_priv == NULL) {
2562 wpa_printf(MSG_INFO, "Interface %s already disabled",
2563 hapd_iface->conf->bss[0]->iface);
2567 wpa_msg(hapd_iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
2568 driver = hapd_iface->bss[0]->driver;
2569 drv_priv = hapd_iface->bss[0]->drv_priv;
2571 hapd_iface->driver_ap_teardown =
2572 !!(hapd_iface->drv_flags &
2573 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
2576 for (j = 0; j < hapd_iface->num_bss; j++)
2577 hostapd_cleanup_cs_params(hapd_iface->bss[j]);
2578 #endif /* NEED_AP_MLME */
2580 /* same as hostapd_interface_deinit without deinitializing ctrl-iface */
2581 for (j = 0; j < hapd_iface->num_bss; j++) {
2582 struct hostapd_data *hapd = hapd_iface->bss[j];
2583 hostapd_bss_deinit_no_free(hapd);
2584 hostapd_free_hapd_data(hapd);
2587 hostapd_deinit_driver(driver, drv_priv, hapd_iface);
2589 /* From hostapd_cleanup_iface: These were initialized in
2590 * hostapd_setup_interface and hostapd_setup_interface_complete
2592 hostapd_cleanup_iface_partial(hapd_iface);
2594 wpa_printf(MSG_DEBUG, "Interface %s disabled",
2595 hapd_iface->bss[0]->conf->iface);
2596 hostapd_set_state(hapd_iface, HAPD_IFACE_DISABLED);
2601 static struct hostapd_iface *
2602 hostapd_iface_alloc(struct hapd_interfaces *interfaces)
2604 struct hostapd_iface **iface, *hapd_iface;
2606 iface = os_realloc_array(interfaces->iface, interfaces->count + 1,
2607 sizeof(struct hostapd_iface *));
2610 interfaces->iface = iface;
2611 hapd_iface = interfaces->iface[interfaces->count] =
2612 hostapd_alloc_iface();
2613 if (hapd_iface == NULL) {
2614 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for "
2615 "the interface", __func__);
2618 interfaces->count++;
2619 hapd_iface->interfaces = interfaces;
2625 static struct hostapd_config *
2626 hostapd_config_alloc(struct hapd_interfaces *interfaces, const char *ifname,
2627 const char *ctrl_iface, const char *driver)
2629 struct hostapd_bss_config *bss;
2630 struct hostapd_config *conf;
2632 /* Allocates memory for bss and conf */
2633 conf = hostapd_config_defaults();
2635 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for "
2636 "configuration", __func__);
2643 for (j = 0; wpa_drivers[j]; j++) {
2644 if (os_strcmp(driver, wpa_drivers[j]->name) == 0) {
2645 conf->driver = wpa_drivers[j];
2650 wpa_printf(MSG_ERROR,
2651 "Invalid/unknown driver '%s' - registering the default driver",
2655 conf->driver = wpa_drivers[0];
2656 if (conf->driver == NULL) {
2657 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
2658 hostapd_config_free(conf);
2663 bss = conf->last_bss = conf->bss[0];
2665 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
2666 bss->ctrl_interface = os_strdup(ctrl_iface);
2667 if (bss->ctrl_interface == NULL) {
2668 hostapd_config_free(conf);
2672 /* Reading configuration file skipped, will be done in SET!
2673 * From reading the configuration till the end has to be done in
2680 static int hostapd_data_alloc(struct hostapd_iface *hapd_iface,
2681 struct hostapd_config *conf)
2684 struct hostapd_data *hapd;
2686 hapd_iface->bss = os_calloc(conf->num_bss,
2687 sizeof(struct hostapd_data *));
2688 if (hapd_iface->bss == NULL)
2691 for (i = 0; i < conf->num_bss; i++) {
2692 hapd = hapd_iface->bss[i] =
2693 hostapd_alloc_bss_data(hapd_iface, conf, conf->bss[i]);
2697 os_free(hapd_iface->bss[i]);
2698 hapd_iface->bss[i] = NULL;
2700 os_free(hapd_iface->bss);
2701 hapd_iface->bss = NULL;
2704 hapd->msg_ctx = hapd;
2707 hapd_iface->conf = conf;
2708 hapd_iface->num_bss = conf->num_bss;
2714 int hostapd_add_iface(struct hapd_interfaces *interfaces, char *buf)
2716 struct hostapd_config *conf = NULL;
2717 struct hostapd_iface *hapd_iface = NULL, *new_iface = NULL;
2718 struct hostapd_data *hapd;
2721 const char *conf_file = NULL, *phy_name = NULL;
2723 if (os_strncmp(buf, "bss_config=", 11) == 0) {
2725 phy_name = buf + 11;
2726 pos = os_strchr(phy_name, ':');
2731 if (!os_strlen(conf_file))
2734 hapd_iface = hostapd_interface_init_bss(interfaces, phy_name,
2738 for (j = 0; j < interfaces->count; j++) {
2739 if (interfaces->iface[j] == hapd_iface)
2742 if (j == interfaces->count) {
2743 struct hostapd_iface **tmp;
2744 tmp = os_realloc_array(interfaces->iface,
2745 interfaces->count + 1,
2746 sizeof(struct hostapd_iface *));
2748 hostapd_interface_deinit_free(hapd_iface);
2751 interfaces->iface = tmp;
2752 interfaces->iface[interfaces->count++] = hapd_iface;
2753 new_iface = hapd_iface;
2757 if (interfaces->driver_init(hapd_iface))
2760 if (hostapd_setup_interface(hapd_iface)) {
2761 hostapd_deinit_driver(
2762 hapd_iface->bss[0]->driver,
2763 hapd_iface->bss[0]->drv_priv,
2768 /* Assign new BSS with bss[0]'s driver info */
2769 hapd = hapd_iface->bss[hapd_iface->num_bss - 1];
2770 hapd->driver = hapd_iface->bss[0]->driver;
2771 hapd->drv_priv = hapd_iface->bss[0]->drv_priv;
2772 os_memcpy(hapd->own_addr, hapd_iface->bss[0]->own_addr,
2775 if (start_ctrl_iface_bss(hapd) < 0 ||
2776 (hapd_iface->state == HAPD_IFACE_ENABLED &&
2777 hostapd_setup_bss(hapd, -1))) {
2778 hostapd_cleanup(hapd);
2779 hapd_iface->bss[hapd_iface->num_bss - 1] = NULL;
2780 hapd_iface->conf->num_bss--;
2781 hapd_iface->num_bss--;
2782 wpa_printf(MSG_DEBUG, "%s: free hapd %p %s",
2783 __func__, hapd, hapd->conf->iface);
2784 hostapd_config_free_bss(hapd->conf);
2790 hostapd_owe_update_trans(hapd_iface);
2794 ptr = os_strchr(buf, ' ');
2799 if (os_strncmp(ptr, "config=", 7) == 0)
2800 conf_file = ptr + 7;
2802 for (i = 0; i < interfaces->count; i++) {
2803 if (!os_strcmp(interfaces->iface[i]->conf->bss[0]->iface,
2805 wpa_printf(MSG_INFO, "Cannot add interface - it "
2811 hapd_iface = hostapd_iface_alloc(interfaces);
2812 if (hapd_iface == NULL) {
2813 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
2814 "for interface", __func__);
2817 new_iface = hapd_iface;
2819 if (conf_file && interfaces->config_read_cb) {
2820 conf = interfaces->config_read_cb(conf_file);
2821 if (conf && conf->bss)
2822 os_strlcpy(conf->bss[0]->iface, buf,
2823 sizeof(conf->bss[0]->iface));
2825 char *driver = os_strchr(ptr, ' ');
2829 conf = hostapd_config_alloc(interfaces, buf, ptr, driver);
2832 if (conf == NULL || conf->bss == NULL) {
2833 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
2834 "for configuration", __func__);
2838 if (hostapd_data_alloc(hapd_iface, conf) < 0) {
2839 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
2840 "for hostapd", __func__);
2845 if (start_ctrl_iface(hapd_iface) < 0)
2848 wpa_printf(MSG_INFO, "Add interface '%s'",
2849 hapd_iface->conf->bss[0]->iface);
2855 hostapd_config_free(conf);
2857 if (hapd_iface->bss) {
2858 for (i = 0; i < hapd_iface->num_bss; i++) {
2859 hapd = hapd_iface->bss[i];
2862 if (hapd_iface->interfaces &&
2863 hapd_iface->interfaces->ctrl_iface_deinit)
2864 hapd_iface->interfaces->
2865 ctrl_iface_deinit(hapd);
2866 wpa_printf(MSG_DEBUG, "%s: free hapd %p (%s)",
2867 __func__, hapd_iface->bss[i],
2869 hostapd_cleanup(hapd);
2871 hapd_iface->bss[i] = NULL;
2873 os_free(hapd_iface->bss);
2874 hapd_iface->bss = NULL;
2877 interfaces->count--;
2878 interfaces->iface[interfaces->count] = NULL;
2880 hostapd_cleanup_iface(hapd_iface);
2886 static int hostapd_remove_bss(struct hostapd_iface *iface, unsigned int idx)
2890 wpa_printf(MSG_INFO, "Remove BSS '%s'", iface->conf->bss[idx]->iface);
2892 /* Remove hostapd_data only if it has already been initialized */
2893 if (idx < iface->num_bss) {
2894 struct hostapd_data *hapd = iface->bss[idx];
2896 hostapd_bss_deinit(hapd);
2897 wpa_printf(MSG_DEBUG, "%s: free hapd %p (%s)",
2898 __func__, hapd, hapd->conf->iface);
2899 hostapd_config_free_bss(hapd->conf);
2905 for (i = idx; i < iface->num_bss; i++)
2906 iface->bss[i] = iface->bss[i + 1];
2908 hostapd_config_free_bss(iface->conf->bss[idx]);
2909 iface->conf->bss[idx] = NULL;
2912 iface->conf->num_bss--;
2913 for (i = idx; i < iface->conf->num_bss; i++)
2914 iface->conf->bss[i] = iface->conf->bss[i + 1];
2920 int hostapd_remove_iface(struct hapd_interfaces *interfaces, char *buf)
2922 struct hostapd_iface *hapd_iface;
2925 for (i = 0; i < interfaces->count; i++) {
2926 hapd_iface = interfaces->iface[i];
2927 if (hapd_iface == NULL)
2929 if (!os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
2930 wpa_printf(MSG_INFO, "Remove interface '%s'", buf);
2931 hapd_iface->driver_ap_teardown =
2932 !!(hapd_iface->drv_flags &
2933 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
2935 hostapd_interface_deinit_free(hapd_iface);
2937 while (k < (interfaces->count - 1)) {
2938 interfaces->iface[k] =
2939 interfaces->iface[k + 1];
2942 interfaces->count--;
2946 for (j = 0; j < hapd_iface->conf->num_bss; j++) {
2947 if (!os_strcmp(hapd_iface->conf->bss[j]->iface, buf)) {
2948 hapd_iface->driver_ap_teardown =
2949 !(hapd_iface->drv_flags &
2950 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
2951 return hostapd_remove_bss(hapd_iface, j);
2960 * hostapd_new_assoc_sta - Notify that a new station associated with the AP
2961 * @hapd: Pointer to BSS data
2962 * @sta: Pointer to the associated STA data
2963 * @reassoc: 1 to indicate this was a re-association; 0 = first association
2965 * This function will be called whenever a station associates with the AP. It
2966 * can be called from ieee802_11.c for drivers that export MLME to hostapd and
2967 * from drv_callbacks.c based on driver events for drivers that take care of
2968 * management frames (IEEE 802.11 authentication and association) internally.
2970 void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
2973 if (hapd->tkip_countermeasures) {
2974 hostapd_drv_sta_deauth(hapd, sta->addr,
2975 WLAN_REASON_MICHAEL_MIC_FAILURE);
2979 hostapd_prune_associations(hapd, sta->addr);
2980 ap_sta_clear_disconnect_timeouts(hapd, sta);
2982 /* IEEE 802.11F (IAPP) */
2983 if (hapd->conf->ieee802_11f)
2984 iapp_new_station(hapd->iapp, sta);
2987 if (sta->p2p_ie == NULL && !sta->no_p2p_set) {
2988 sta->no_p2p_set = 1;
2989 hapd->num_sta_no_p2p++;
2990 if (hapd->num_sta_no_p2p == 1)
2991 hostapd_p2p_non_p2p_sta_connected(hapd);
2993 #endif /* CONFIG_P2P */
2995 /* Start accounting here, if IEEE 802.1X and WPA are not used.
2996 * IEEE 802.1X/WPA code will start accounting after the station has
2997 * been authorized. */
2998 if (!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) {
2999 ap_sta_set_authorized(hapd, sta, 1);
3000 os_get_reltime(&sta->connected_time);
3001 accounting_sta_start(hapd, sta);
3004 /* Start IEEE 802.1X authentication process for new stations */
3005 ieee802_1x_new_station(hapd, sta);
3007 if (sta->auth_alg != WLAN_AUTH_FT &&
3008 sta->auth_alg != WLAN_AUTH_FILS_SK &&
3009 sta->auth_alg != WLAN_AUTH_FILS_SK_PFS &&
3010 sta->auth_alg != WLAN_AUTH_FILS_PK &&
3011 !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)))
3012 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH);
3014 wpa_auth_sta_associated(hapd->wpa_auth, sta->wpa_sm);
3016 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_WIRED) {
3017 if (eloop_cancel_timeout(ap_handle_timer, hapd, sta) > 0) {
3018 wpa_printf(MSG_DEBUG,
3019 "%s: %s: canceled wired ap_handle_timer timeout for "
3021 hapd->conf->iface, __func__,
3022 MAC2STR(sta->addr));
3024 } else if (!(hapd->iface->drv_flags &
3025 WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) {
3026 wpa_printf(MSG_DEBUG,
3027 "%s: %s: reschedule ap_handle_timer timeout for "
3028 MACSTR " (%d seconds - ap_max_inactivity)",
3029 hapd->conf->iface, __func__, MAC2STR(sta->addr),
3030 hapd->conf->ap_max_inactivity);
3031 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
3032 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
3033 ap_handle_timer, hapd, sta);
3038 const char * hostapd_state_text(enum hostapd_iface_state s)
3041 case HAPD_IFACE_UNINITIALIZED:
3042 return "UNINITIALIZED";
3043 case HAPD_IFACE_DISABLED:
3045 case HAPD_IFACE_COUNTRY_UPDATE:
3046 return "COUNTRY_UPDATE";
3047 case HAPD_IFACE_ACS:
3049 case HAPD_IFACE_HT_SCAN:
3051 case HAPD_IFACE_DFS:
3053 case HAPD_IFACE_ENABLED:
3061 void hostapd_set_state(struct hostapd_iface *iface, enum hostapd_iface_state s)
3063 wpa_printf(MSG_INFO, "%s: interface state %s->%s",
3064 iface->conf ? iface->conf->bss[0]->iface : "N/A",
3065 hostapd_state_text(iface->state), hostapd_state_text(s));
3070 int hostapd_csa_in_progress(struct hostapd_iface *iface)
3074 for (i = 0; i < iface->num_bss; i++)
3075 if (iface->bss[i]->csa_in_progress)
3083 static void free_beacon_data(struct beacon_data *beacon)
3085 os_free(beacon->head);
3086 beacon->head = NULL;
3087 os_free(beacon->tail);
3088 beacon->tail = NULL;
3089 os_free(beacon->probe_resp);
3090 beacon->probe_resp = NULL;
3091 os_free(beacon->beacon_ies);
3092 beacon->beacon_ies = NULL;
3093 os_free(beacon->proberesp_ies);
3094 beacon->proberesp_ies = NULL;
3095 os_free(beacon->assocresp_ies);
3096 beacon->assocresp_ies = NULL;
3100 static int hostapd_build_beacon_data(struct hostapd_data *hapd,
3101 struct beacon_data *beacon)
3103 struct wpabuf *beacon_extra, *proberesp_extra, *assocresp_extra;
3104 struct wpa_driver_ap_params params;
3107 os_memset(beacon, 0, sizeof(*beacon));
3108 ret = ieee802_11_build_ap_params(hapd, ¶ms);
3112 ret = hostapd_build_ap_extra_ies(hapd, &beacon_extra,
3116 goto free_ap_params;
3119 beacon->head = os_memdup(params.head, params.head_len);
3121 goto free_ap_extra_ies;
3123 beacon->head_len = params.head_len;
3125 beacon->tail = os_memdup(params.tail, params.tail_len);
3129 beacon->tail_len = params.tail_len;
3131 if (params.proberesp != NULL) {
3132 beacon->probe_resp = os_memdup(params.proberesp,
3133 params.proberesp_len);
3134 if (!beacon->probe_resp)
3137 beacon->probe_resp_len = params.proberesp_len;
3140 /* copy the extra ies */
3142 beacon->beacon_ies = os_memdup(beacon_extra->buf,
3143 wpabuf_len(beacon_extra));
3144 if (!beacon->beacon_ies)
3147 beacon->beacon_ies_len = wpabuf_len(beacon_extra);
3150 if (proberesp_extra) {
3151 beacon->proberesp_ies = os_memdup(proberesp_extra->buf,
3152 wpabuf_len(proberesp_extra));
3153 if (!beacon->proberesp_ies)
3156 beacon->proberesp_ies_len = wpabuf_len(proberesp_extra);
3159 if (assocresp_extra) {
3160 beacon->assocresp_ies = os_memdup(assocresp_extra->buf,
3161 wpabuf_len(assocresp_extra));
3162 if (!beacon->assocresp_ies)
3165 beacon->assocresp_ies_len = wpabuf_len(assocresp_extra);
3170 /* if the function fails, the caller should not free beacon data */
3172 free_beacon_data(beacon);
3175 hostapd_free_ap_extra_ies(hapd, beacon_extra, proberesp_extra,
3178 ieee802_11_free_ap_params(¶ms);
3184 * TODO: This flow currently supports only changing channel and width within
3185 * the same hw_mode. Any other changes to MAC parameters or provided settings
3186 * are not supported.
3188 static int hostapd_change_config_freq(struct hostapd_data *hapd,
3189 struct hostapd_config *conf,
3190 struct hostapd_freq_params *params,
3191 struct hostapd_freq_params *old_params)
3195 if (!params->channel) {
3196 /* check if the new channel is supported by hw */
3197 params->channel = hostapd_hw_get_channel(hapd, params->freq);
3200 channel = params->channel;
3204 /* if a pointer to old_params is provided we save previous state */
3206 hostapd_set_freq_params(old_params, conf->hw_mode,
3207 hostapd_hw_get_freq(hapd, conf->channel),
3208 conf->channel, conf->ieee80211n,
3210 conf->secondary_channel,
3211 conf->vht_oper_chwidth,
3212 conf->vht_oper_centr_freq_seg0_idx,
3213 conf->vht_oper_centr_freq_seg1_idx,
3217 switch (params->bandwidth) {
3221 conf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT;
3224 if (params->center_freq2)
3225 conf->vht_oper_chwidth = VHT_CHANWIDTH_80P80MHZ;
3227 conf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ;
3230 conf->vht_oper_chwidth = VHT_CHANWIDTH_160MHZ;
3236 conf->channel = channel;
3237 conf->ieee80211n = params->ht_enabled;
3238 conf->secondary_channel = params->sec_channel_offset;
3239 ieee80211_freq_to_chan(params->center_freq1,
3240 &conf->vht_oper_centr_freq_seg0_idx);
3241 ieee80211_freq_to_chan(params->center_freq2,
3242 &conf->vht_oper_centr_freq_seg1_idx);
3244 /* TODO: maybe call here hostapd_config_check here? */
3250 static int hostapd_fill_csa_settings(struct hostapd_data *hapd,
3251 struct csa_settings *settings)
3253 struct hostapd_iface *iface = hapd->iface;
3254 struct hostapd_freq_params old_freq;
3256 u8 chan, vht_bandwidth;
3258 os_memset(&old_freq, 0, sizeof(old_freq));
3259 if (!iface || !iface->freq || hapd->csa_in_progress)
3262 switch (settings->freq_params.bandwidth) {
3264 if (settings->freq_params.center_freq2)
3265 vht_bandwidth = VHT_CHANWIDTH_80P80MHZ;
3267 vht_bandwidth = VHT_CHANWIDTH_80MHZ;
3270 vht_bandwidth = VHT_CHANWIDTH_160MHZ;
3273 vht_bandwidth = VHT_CHANWIDTH_USE_HT;
3277 if (ieee80211_freq_to_channel_ext(
3278 settings->freq_params.freq,
3279 settings->freq_params.sec_channel_offset,
3281 &hapd->iface->cs_oper_class,
3282 &chan) == NUM_HOSTAPD_MODES) {
3283 wpa_printf(MSG_DEBUG,
3284 "invalid frequency for channel switch (freq=%d, sec_channel_offset=%d, vht_enabled=%d)",
3285 settings->freq_params.freq,
3286 settings->freq_params.sec_channel_offset,
3287 settings->freq_params.vht_enabled);
3291 settings->freq_params.channel = chan;
3293 ret = hostapd_change_config_freq(iface->bss[0], iface->conf,
3294 &settings->freq_params,
3299 ret = hostapd_build_beacon_data(hapd, &settings->beacon_after);
3301 /* change back the configuration */
3302 hostapd_change_config_freq(iface->bss[0], iface->conf,
3308 /* set channel switch parameters for csa ie */
3309 hapd->cs_freq_params = settings->freq_params;
3310 hapd->cs_count = settings->cs_count;
3311 hapd->cs_block_tx = settings->block_tx;
3313 ret = hostapd_build_beacon_data(hapd, &settings->beacon_csa);
3315 free_beacon_data(&settings->beacon_after);
3319 settings->counter_offset_beacon[0] = hapd->cs_c_off_beacon;
3320 settings->counter_offset_presp[0] = hapd->cs_c_off_proberesp;
3321 settings->counter_offset_beacon[1] = hapd->cs_c_off_ecsa_beacon;
3322 settings->counter_offset_presp[1] = hapd->cs_c_off_ecsa_proberesp;
3328 void hostapd_cleanup_cs_params(struct hostapd_data *hapd)
3330 os_memset(&hapd->cs_freq_params, 0, sizeof(hapd->cs_freq_params));
3332 hapd->cs_block_tx = 0;
3333 hapd->cs_c_off_beacon = 0;
3334 hapd->cs_c_off_proberesp = 0;
3335 hapd->csa_in_progress = 0;
3336 hapd->cs_c_off_ecsa_beacon = 0;
3337 hapd->cs_c_off_ecsa_proberesp = 0;
3341 void hostapd_chan_switch_vht_config(struct hostapd_data *hapd, int vht_enabled)
3344 hapd->iconf->ch_switch_vht_config |= CH_SWITCH_VHT_ENABLED;
3346 hapd->iconf->ch_switch_vht_config |= CH_SWITCH_VHT_DISABLED;
3348 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
3349 HOSTAPD_LEVEL_INFO, "CHAN_SWITCH VHT CONFIG 0x%x",
3350 hapd->iconf->ch_switch_vht_config);
3354 int hostapd_switch_channel(struct hostapd_data *hapd,
3355 struct csa_settings *settings)
3359 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA)) {
3360 wpa_printf(MSG_INFO, "CSA is not supported");
3364 ret = hostapd_fill_csa_settings(hapd, settings);
3368 ret = hostapd_drv_switch_channel(hapd, settings);
3369 free_beacon_data(&settings->beacon_csa);
3370 free_beacon_data(&settings->beacon_after);
3373 /* if we failed, clean cs parameters */
3374 hostapd_cleanup_cs_params(hapd);
3378 hapd->csa_in_progress = 1;
3384 hostapd_switch_channel_fallback(struct hostapd_iface *iface,
3385 const struct hostapd_freq_params *freq_params)
3387 int vht_seg0_idx = 0, vht_seg1_idx = 0, vht_bw = VHT_CHANWIDTH_USE_HT;
3389 wpa_printf(MSG_DEBUG, "Restarting all CSA-related BSSes");
3391 if (freq_params->center_freq1)
3392 vht_seg0_idx = 36 + (freq_params->center_freq1 - 5180) / 5;
3393 if (freq_params->center_freq2)
3394 vht_seg1_idx = 36 + (freq_params->center_freq2 - 5180) / 5;
3396 switch (freq_params->bandwidth) {
3400 vht_bw = VHT_CHANWIDTH_USE_HT;
3403 if (freq_params->center_freq2)
3404 vht_bw = VHT_CHANWIDTH_80P80MHZ;
3406 vht_bw = VHT_CHANWIDTH_80MHZ;
3409 vht_bw = VHT_CHANWIDTH_160MHZ;
3412 wpa_printf(MSG_WARNING, "Unknown CSA bandwidth: %d",
3413 freq_params->bandwidth);
3417 iface->freq = freq_params->freq;
3418 iface->conf->channel = freq_params->channel;
3419 iface->conf->secondary_channel = freq_params->sec_channel_offset;
3420 iface->conf->vht_oper_centr_freq_seg0_idx = vht_seg0_idx;
3421 iface->conf->vht_oper_centr_freq_seg1_idx = vht_seg1_idx;
3422 iface->conf->vht_oper_chwidth = vht_bw;
3423 iface->conf->ieee80211n = freq_params->ht_enabled;
3424 iface->conf->ieee80211ac = freq_params->vht_enabled;
3427 * cs_params must not be cleared earlier because the freq_params
3428 * argument may actually point to one of these.
3429 * These params will be cleared during interface disable below.
3431 hostapd_disable_iface(iface);
3432 hostapd_enable_iface(iface);
3435 #endif /* NEED_AP_MLME */
3438 struct hostapd_data * hostapd_get_iface(struct hapd_interfaces *interfaces,
3443 for (i = 0; i < interfaces->count; i++) {
3444 struct hostapd_iface *iface = interfaces->iface[i];
3446 for (j = 0; j < iface->num_bss; j++) {
3447 struct hostapd_data *hapd = iface->bss[j];
3449 if (os_strcmp(ifname, hapd->conf->iface) == 0)
3458 void hostapd_periodic_iface(struct hostapd_iface *iface)
3462 ap_list_timer(iface);
3464 for (i = 0; i < iface->num_bss; i++) {
3465 struct hostapd_data *hapd = iface->bss[i];
3470 #ifndef CONFIG_NO_RADIUS
3471 hostapd_acl_expire(hapd);
3472 #endif /* CONFIG_NO_RADIUS */