2 * hostapd / Initialization and configuration
3 * Copyright (c) 2002-2014, 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 "radius/radius_client.h"
16 #include "radius/radius_das.h"
17 #include "eap_server/tncs.h"
21 #include "accounting.h"
25 #include "ieee802_1x.h"
26 #include "ieee802_11_auth.h"
27 #include "vlan_init.h"
29 #include "wps_hostapd.h"
30 #include "hw_features.h"
31 #include "wpa_auth_glue.h"
32 #include "ap_drv_ops.h"
33 #include "ap_config.h"
34 #include "p2p_hostapd.h"
37 #include "ieee802_11.h"
40 #include "dhcp_snoop.h"
43 static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason);
44 static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd);
45 static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd);
46 static int setup_interface2(struct hostapd_iface *iface);
47 static void channel_list_update_timeout(void *eloop_ctx, void *timeout_ctx);
50 int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
51 int (*cb)(struct hostapd_iface *iface,
52 void *ctx), void *ctx)
57 for (i = 0; i < interfaces->count; i++) {
58 ret = cb(interfaces->iface[i], ctx);
67 static void hostapd_reload_bss(struct hostapd_data *hapd)
69 struct hostapd_ssid *ssid;
71 #ifndef CONFIG_NO_RADIUS
72 radius_client_reconfig(hapd->radius, hapd->conf->radius);
73 #endif /* CONFIG_NO_RADIUS */
75 ssid = &hapd->conf->ssid;
76 if (!ssid->wpa_psk_set && ssid->wpa_psk && !ssid->wpa_psk->next &&
77 ssid->wpa_passphrase_set && ssid->wpa_passphrase) {
79 * Force PSK to be derived again since SSID or passphrase may
82 os_free(ssid->wpa_psk);
85 if (hostapd_setup_wpa_psk(hapd->conf)) {
86 wpa_printf(MSG_ERROR, "Failed to re-configure WPA PSK "
87 "after reloading configuration");
90 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
91 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1);
93 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0);
95 if ((hapd->conf->wpa || hapd->conf->osen) && hapd->wpa_auth == NULL) {
96 hostapd_setup_wpa(hapd);
98 wpa_init_keys(hapd->wpa_auth);
99 } else if (hapd->conf->wpa) {
102 hostapd_reconfig_wpa(hapd);
103 wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
104 if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len))
105 wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
106 "the kernel driver.");
107 } else if (hapd->wpa_auth) {
108 wpa_deinit(hapd->wpa_auth);
109 hapd->wpa_auth = NULL;
110 hostapd_set_privacy(hapd, 0);
111 hostapd_setup_encryption(hapd->conf->iface, hapd);
112 hostapd_set_generic_elem(hapd, (u8 *) "", 0);
115 ieee802_11_set_beacon(hapd);
116 hostapd_update_wps(hapd);
118 if (hapd->conf->ssid.ssid_set &&
119 hostapd_set_ssid(hapd, hapd->conf->ssid.ssid,
120 hapd->conf->ssid.ssid_len)) {
121 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
122 /* try to continue */
124 wpa_printf(MSG_DEBUG, "Reconfigured interface %s", hapd->conf->iface);
128 static void hostapd_clear_old(struct hostapd_iface *iface)
133 * Deauthenticate all stations since the new configuration may not
134 * allow them to use the BSS anymore.
136 for (j = 0; j < iface->num_bss; j++) {
137 hostapd_flush_old_stations(iface->bss[j],
138 WLAN_REASON_PREV_AUTH_NOT_VALID);
139 hostapd_broadcast_wep_clear(iface->bss[j]);
141 #ifndef CONFIG_NO_RADIUS
142 /* TODO: update dynamic data based on changed configuration
143 * items (e.g., open/close sockets, etc.) */
144 radius_client_flush(iface->bss[j]->radius, 0);
145 #endif /* CONFIG_NO_RADIUS */
150 int hostapd_reload_config(struct hostapd_iface *iface)
152 struct hostapd_data *hapd = iface->bss[0];
153 struct hostapd_config *newconf, *oldconf;
156 if (iface->config_fname == NULL) {
157 /* Only in-memory config in use - assume it has been updated */
158 hostapd_clear_old(iface);
159 for (j = 0; j < iface->num_bss; j++)
160 hostapd_reload_bss(iface->bss[j]);
164 if (iface->interfaces == NULL ||
165 iface->interfaces->config_read_cb == NULL)
167 newconf = iface->interfaces->config_read_cb(iface->config_fname);
171 hostapd_clear_old(iface);
173 oldconf = hapd->iconf;
174 iface->conf = newconf;
176 for (j = 0; j < iface->num_bss; j++) {
177 hapd = iface->bss[j];
178 hapd->iconf = newconf;
179 hapd->iconf->channel = oldconf->channel;
180 hapd->iconf->secondary_channel = oldconf->secondary_channel;
181 hapd->iconf->ieee80211n = oldconf->ieee80211n;
182 hapd->iconf->ieee80211ac = oldconf->ieee80211ac;
183 hapd->iconf->ht_capab = oldconf->ht_capab;
184 hapd->iconf->vht_capab = oldconf->vht_capab;
185 hapd->iconf->vht_oper_chwidth = oldconf->vht_oper_chwidth;
186 hapd->iconf->vht_oper_centr_freq_seg0_idx =
187 oldconf->vht_oper_centr_freq_seg0_idx;
188 hapd->iconf->vht_oper_centr_freq_seg1_idx =
189 oldconf->vht_oper_centr_freq_seg1_idx;
190 hapd->conf = newconf->bss[j];
191 hostapd_reload_bss(hapd);
194 hostapd_config_free(oldconf);
201 static void hostapd_broadcast_key_clear_iface(struct hostapd_data *hapd,
206 for (i = 0; i < NUM_WEP_KEYS; i++) {
207 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE, NULL, i,
208 0, NULL, 0, NULL, 0)) {
209 wpa_printf(MSG_DEBUG, "Failed to clear default "
210 "encryption keys (ifname=%s keyidx=%d)",
214 #ifdef CONFIG_IEEE80211W
215 if (hapd->conf->ieee80211w) {
216 for (i = NUM_WEP_KEYS; i < NUM_WEP_KEYS + 2; i++) {
217 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE,
220 wpa_printf(MSG_DEBUG, "Failed to clear "
221 "default mgmt encryption keys "
222 "(ifname=%s keyidx=%d)", ifname, i);
226 #endif /* CONFIG_IEEE80211W */
230 static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd)
232 hostapd_broadcast_key_clear_iface(hapd, hapd->conf->iface);
237 static int hostapd_broadcast_wep_set(struct hostapd_data *hapd)
240 struct hostapd_ssid *ssid = &hapd->conf->ssid;
243 if (ssid->wep.default_len &&
244 hostapd_drv_set_key(hapd->conf->iface,
245 hapd, WPA_ALG_WEP, broadcast_ether_addr, idx,
246 1, NULL, 0, ssid->wep.key[idx],
247 ssid->wep.len[idx])) {
248 wpa_printf(MSG_WARNING, "Could not set WEP encryption.");
256 static void hostapd_free_hapd_data(struct hostapd_data *hapd)
258 if (!hapd->started) {
259 wpa_printf(MSG_ERROR, "%s: Interface %s wasn't started",
260 __func__, hapd->conf->iface);
265 wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
266 iapp_deinit(hapd->iapp);
268 accounting_deinit(hapd);
269 hostapd_deinit_wpa(hapd);
271 hostapd_acl_deinit(hapd);
272 #ifndef CONFIG_NO_RADIUS
273 radius_client_deinit(hapd->radius);
275 radius_das_deinit(hapd->radius_das);
276 hapd->radius_das = NULL;
277 #endif /* CONFIG_NO_RADIUS */
279 hostapd_deinit_wps(hapd);
281 authsrv_deinit(hapd);
283 if (hapd->interface_added) {
284 hapd->interface_added = 0;
285 if (hostapd_if_remove(hapd, WPA_IF_AP_BSS, hapd->conf->iface)) {
286 wpa_printf(MSG_WARNING,
287 "Failed to remove BSS interface %s",
289 hapd->interface_added = 1;
292 * Since this was a dynamically added interface, the
293 * driver wrapper may have removed its internal instance
294 * and hapd->drv_priv is not valid anymore.
296 hapd->drv_priv = NULL;
300 os_free(hapd->probereq_cb);
301 hapd->probereq_cb = NULL;
304 wpabuf_free(hapd->p2p_beacon_ie);
305 hapd->p2p_beacon_ie = NULL;
306 wpabuf_free(hapd->p2p_probe_resp_ie);
307 hapd->p2p_probe_resp_ie = NULL;
308 #endif /* CONFIG_P2P */
310 wpabuf_free(hapd->time_adv);
312 #ifdef CONFIG_INTERWORKING
313 gas_serv_deinit(hapd);
314 #endif /* CONFIG_INTERWORKING */
316 bss_load_update_deinit(hapd);
317 dhcp_snoop_deinit(hapd);
318 x_snoop_deinit(hapd);
321 bin_clear_free(hapd->tmp_eap_user.identity,
322 hapd->tmp_eap_user.identity_len);
323 bin_clear_free(hapd->tmp_eap_user.password,
324 hapd->tmp_eap_user.password_len);
325 #endif /* CONFIG_SQLITE */
330 * hostapd_cleanup - Per-BSS cleanup (deinitialization)
331 * @hapd: Pointer to BSS data
333 * This function is used to free all per-BSS data structures and resources.
334 * Most of the modules that are initialized in hostapd_setup_bss() are
335 * deinitialized here.
337 static void hostapd_cleanup(struct hostapd_data *hapd)
339 wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s))", __func__, hapd,
341 if (hapd->iface->interfaces &&
342 hapd->iface->interfaces->ctrl_iface_deinit)
343 hapd->iface->interfaces->ctrl_iface_deinit(hapd);
344 hostapd_free_hapd_data(hapd);
348 static void hostapd_cleanup_iface_partial(struct hostapd_iface *iface)
350 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
351 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
352 iface->hw_features = NULL;
353 os_free(iface->current_rates);
354 iface->current_rates = NULL;
355 os_free(iface->basic_rates);
356 iface->basic_rates = NULL;
357 ap_list_deinit(iface);
362 * hostapd_cleanup_iface - Complete per-interface cleanup
363 * @iface: Pointer to interface data
365 * This function is called after per-BSS data structures are deinitialized
366 * with hostapd_cleanup().
368 static void hostapd_cleanup_iface(struct hostapd_iface *iface)
370 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
371 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
373 hostapd_cleanup_iface_partial(iface);
374 hostapd_config_free(iface->conf);
377 os_free(iface->config_fname);
379 wpa_printf(MSG_DEBUG, "%s: free iface=%p", __func__, iface);
384 static void hostapd_clear_wep(struct hostapd_data *hapd)
386 if (hapd->drv_priv && !hapd->iface->driver_ap_teardown) {
387 hostapd_set_privacy(hapd, 0);
388 hostapd_broadcast_wep_clear(hapd);
393 static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd)
397 hostapd_broadcast_wep_set(hapd);
399 if (hapd->conf->ssid.wep.default_len) {
400 hostapd_set_privacy(hapd, 1);
405 * When IEEE 802.1X is not enabled, the driver may need to know how to
406 * set authentication algorithms for static WEP.
408 hostapd_drv_set_authmode(hapd, hapd->conf->auth_algs);
410 for (i = 0; i < 4; i++) {
411 if (hapd->conf->ssid.wep.key[i] &&
412 hostapd_drv_set_key(iface, hapd, WPA_ALG_WEP, NULL, i,
413 i == hapd->conf->ssid.wep.idx, NULL, 0,
414 hapd->conf->ssid.wep.key[i],
415 hapd->conf->ssid.wep.len[i])) {
416 wpa_printf(MSG_WARNING, "Could not set WEP "
420 if (hapd->conf->ssid.wep.key[i] &&
421 i == hapd->conf->ssid.wep.idx)
422 hostapd_set_privacy(hapd, 1);
429 static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason)
434 if (hostapd_drv_none(hapd) || hapd->drv_priv == NULL)
437 if (!hapd->iface->driver_ap_teardown) {
438 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
439 "Flushing old station entries");
441 if (hostapd_flush(hapd)) {
442 wpa_msg(hapd->msg_ctx, MSG_WARNING,
443 "Could not connect to kernel driver");
447 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "Deauthenticate all stations");
448 os_memset(addr, 0xff, ETH_ALEN);
449 hostapd_drv_sta_deauth(hapd, addr, reason);
450 hostapd_free_stas(hapd);
456 static void hostapd_bss_deinit_no_free(struct hostapd_data *hapd)
458 hostapd_free_stas(hapd);
459 hostapd_flush_old_stations(hapd, WLAN_REASON_DEAUTH_LEAVING);
460 hostapd_clear_wep(hapd);
465 * hostapd_validate_bssid_configuration - Validate BSSID configuration
466 * @iface: Pointer to interface data
467 * Returns: 0 on success, -1 on failure
469 * This function is used to validate that the configured BSSIDs are valid.
471 static int hostapd_validate_bssid_configuration(struct hostapd_iface *iface)
473 u8 mask[ETH_ALEN] = { 0 };
474 struct hostapd_data *hapd = iface->bss[0];
475 unsigned int i = iface->conf->num_bss, bits = 0, j;
478 if (hostapd_drv_none(hapd))
481 /* Generate BSSID mask that is large enough to cover the BSSIDs. */
483 /* Determine the bits necessary to cover the number of BSSIDs. */
484 for (i--; i; i >>= 1)
487 /* Determine the bits necessary to any configured BSSIDs,
488 if they are higher than the number of BSSIDs. */
489 for (j = 0; j < iface->conf->num_bss; j++) {
490 if (hostapd_mac_comp_empty(iface->conf->bss[j]->bssid) == 0) {
496 for (i = 0; i < ETH_ALEN; i++) {
498 iface->conf->bss[j]->bssid[i] ^
506 for (i = 0; i < ETH_ALEN && mask[i] == 0; i++)
512 while (mask[i] != 0) {
522 wpa_printf(MSG_ERROR, "Too many bits in the BSSID mask (%u)",
527 os_memset(mask, 0xff, ETH_ALEN);
529 for (i = 5; i > 5 - j; i--)
536 wpa_printf(MSG_DEBUG, "BSS count %lu, BSSID mask " MACSTR " (%d bits)",
537 (unsigned long) iface->conf->num_bss, MAC2STR(mask), bits);
542 for (i = 0; i < ETH_ALEN; i++) {
543 if ((hapd->own_addr[i] & mask[i]) != hapd->own_addr[i]) {
544 wpa_printf(MSG_ERROR, "Invalid BSSID mask " MACSTR
545 " for start address " MACSTR ".",
546 MAC2STR(mask), MAC2STR(hapd->own_addr));
547 wpa_printf(MSG_ERROR, "Start address must be the "
548 "first address in the block (i.e., addr "
549 "AND mask == addr).");
558 static int mac_in_conf(struct hostapd_config *conf, const void *a)
562 for (i = 0; i < conf->num_bss; i++) {
563 if (hostapd_mac_comp(conf->bss[i]->bssid, a) == 0) {
572 #ifndef CONFIG_NO_RADIUS
574 static int hostapd_das_nas_mismatch(struct hostapd_data *hapd,
575 struct radius_das_attrs *attr)
577 if (attr->nas_identifier &&
578 (!hapd->conf->nas_identifier ||
579 os_strlen(hapd->conf->nas_identifier) !=
580 attr->nas_identifier_len ||
581 os_memcmp(hapd->conf->nas_identifier, attr->nas_identifier,
582 attr->nas_identifier_len) != 0)) {
583 wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-Identifier mismatch");
587 if (attr->nas_ip_addr &&
588 (hapd->conf->own_ip_addr.af != AF_INET ||
589 os_memcmp(&hapd->conf->own_ip_addr.u.v4, attr->nas_ip_addr, 4) !=
591 wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-IP-Address mismatch");
596 if (attr->nas_ipv6_addr &&
597 (hapd->conf->own_ip_addr.af != AF_INET6 ||
598 os_memcmp(&hapd->conf->own_ip_addr.u.v6, attr->nas_ipv6_addr, 16)
600 wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-IPv6-Address mismatch");
603 #endif /* CONFIG_IPV6 */
609 static struct sta_info * hostapd_das_find_sta(struct hostapd_data *hapd,
610 struct radius_das_attrs *attr)
612 struct sta_info *sta = NULL;
616 sta = ap_get_sta(hapd, attr->sta_addr);
618 if (sta == NULL && attr->acct_session_id &&
619 attr->acct_session_id_len == 17) {
620 for (sta = hapd->sta_list; sta; sta = sta->next) {
621 os_snprintf(buf, sizeof(buf), "%08X-%08X",
622 sta->acct_session_id_hi,
623 sta->acct_session_id_lo);
624 if (os_memcmp(attr->acct_session_id, buf, 17) == 0)
629 if (sta == NULL && attr->cui) {
630 for (sta = hapd->sta_list; sta; sta = sta->next) {
632 cui = ieee802_1x_get_radius_cui(sta->eapol_sm);
633 if (cui && wpabuf_len(cui) == attr->cui_len &&
634 os_memcmp(wpabuf_head(cui), attr->cui,
640 if (sta == NULL && attr->user_name) {
641 for (sta = hapd->sta_list; sta; sta = sta->next) {
644 identity = ieee802_1x_get_identity(sta->eapol_sm,
647 identity_len == attr->user_name_len &&
648 os_memcmp(identity, attr->user_name, identity_len)
658 static enum radius_das_res
659 hostapd_das_disconnect(void *ctx, struct radius_das_attrs *attr)
661 struct hostapd_data *hapd = ctx;
662 struct sta_info *sta;
664 if (hostapd_das_nas_mismatch(hapd, attr))
665 return RADIUS_DAS_NAS_MISMATCH;
667 sta = hostapd_das_find_sta(hapd, attr);
669 return RADIUS_DAS_SESSION_NOT_FOUND;
671 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
673 hostapd_drv_sta_deauth(hapd, sta->addr,
674 WLAN_REASON_PREV_AUTH_NOT_VALID);
675 ap_sta_deauthenticate(hapd, sta, WLAN_REASON_PREV_AUTH_NOT_VALID);
677 return RADIUS_DAS_SUCCESS;
680 #endif /* CONFIG_NO_RADIUS */
684 * hostapd_setup_bss - Per-BSS setup (initialization)
685 * @hapd: Pointer to BSS data
686 * @first: Whether this BSS is the first BSS of an interface; -1 = not first,
687 * but interface may exist
689 * This function is used to initialize all per-BSS data structures and
690 * resources. This gets called in a loop for each BSS when an interface is
691 * initialized. Most of the modules that are initialized here will be
692 * deinitialized in hostapd_cleanup().
694 static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
696 struct hostapd_bss_config *conf = hapd->conf;
697 u8 ssid[HOSTAPD_MAX_SSID_LEN + 1];
698 int ssid_len, set_ssid;
699 char force_ifname[IFNAMSIZ];
700 u8 if_addr[ETH_ALEN];
701 int flush_old_stations = 1;
703 wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s), first=%d)",
704 __func__, hapd, conf->iface, first);
706 #ifdef EAP_SERVER_TNC
707 if (conf->tnc && tncs_global_init() < 0) {
708 wpa_printf(MSG_ERROR, "Failed to initialize TNCS");
711 #endif /* EAP_SERVER_TNC */
714 wpa_printf(MSG_ERROR, "%s: Interface %s was already started",
715 __func__, conf->iface);
720 if (!first || first == -1) {
721 if (hostapd_mac_comp_empty(conf->bssid) == 0) {
722 /* Allocate the next available BSSID. */
724 inc_byte_array(hapd->own_addr, ETH_ALEN);
725 } while (mac_in_conf(hapd->iconf, hapd->own_addr));
727 /* Allocate the configured BSSID. */
728 os_memcpy(hapd->own_addr, conf->bssid, ETH_ALEN);
730 if (hostapd_mac_comp(hapd->own_addr,
731 hapd->iface->bss[0]->own_addr) ==
733 wpa_printf(MSG_ERROR, "BSS '%s' may not have "
734 "BSSID set to the MAC address of "
735 "the radio", conf->iface);
740 hapd->interface_added = 1;
741 if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS,
742 conf->iface, hapd->own_addr, hapd,
743 &hapd->drv_priv, force_ifname, if_addr,
744 conf->bridge[0] ? conf->bridge : NULL,
746 wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
747 MACSTR ")", MAC2STR(hapd->own_addr));
748 hapd->interface_added = 0;
753 if (conf->wmm_enabled < 0)
754 conf->wmm_enabled = hapd->iconf->ieee80211n;
757 if (hapd->iface->mconf == NULL)
758 flush_old_stations = 0;
759 #endif /* CONFIG_MESH */
761 if (flush_old_stations)
762 hostapd_flush_old_stations(hapd,
763 WLAN_REASON_PREV_AUTH_NOT_VALID);
764 hostapd_set_privacy(hapd, 0);
766 hostapd_broadcast_wep_clear(hapd);
767 if (hostapd_setup_encryption(conf->iface, hapd))
771 * Fetch the SSID from the system and use it or,
772 * if one was specified in the config file, verify they
775 ssid_len = hostapd_get_ssid(hapd, ssid, sizeof(ssid));
777 wpa_printf(MSG_ERROR, "Could not read SSID from system");
780 if (conf->ssid.ssid_set) {
782 * If SSID is specified in the config file and it differs
783 * from what is being used then force installation of the
786 set_ssid = (conf->ssid.ssid_len != (size_t) ssid_len ||
787 os_memcmp(conf->ssid.ssid, ssid, ssid_len) != 0);
790 * No SSID in the config file; just use the one we got
794 conf->ssid.ssid_len = ssid_len;
795 os_memcpy(conf->ssid.ssid, ssid, conf->ssid.ssid_len);
798 if (!hostapd_drv_none(hapd)) {
799 wpa_printf(MSG_ERROR, "Using interface %s with hwaddr " MACSTR
801 conf->iface, MAC2STR(hapd->own_addr),
802 wpa_ssid_txt(conf->ssid.ssid, conf->ssid.ssid_len));
805 if (hostapd_setup_wpa_psk(conf)) {
806 wpa_printf(MSG_ERROR, "WPA-PSK setup failed.");
810 /* Set SSID for the kernel driver (to be used in beacon and probe
811 * response frames) */
812 if (set_ssid && hostapd_set_ssid(hapd, conf->ssid.ssid,
813 conf->ssid.ssid_len)) {
814 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
818 if (wpa_debug_level <= MSG_MSGDUMP)
819 conf->radius->msg_dumps = 1;
820 #ifndef CONFIG_NO_RADIUS
821 hapd->radius = radius_client_init(hapd, conf->radius);
822 if (hapd->radius == NULL) {
823 wpa_printf(MSG_ERROR, "RADIUS client initialization failed.");
827 if (conf->radius_das_port) {
828 struct radius_das_conf das_conf;
829 os_memset(&das_conf, 0, sizeof(das_conf));
830 das_conf.port = conf->radius_das_port;
831 das_conf.shared_secret = conf->radius_das_shared_secret;
832 das_conf.shared_secret_len =
833 conf->radius_das_shared_secret_len;
834 das_conf.client_addr = &conf->radius_das_client_addr;
835 das_conf.time_window = conf->radius_das_time_window;
836 das_conf.require_event_timestamp =
837 conf->radius_das_require_event_timestamp;
839 das_conf.disconnect = hostapd_das_disconnect;
840 hapd->radius_das = radius_das_init(&das_conf);
841 if (hapd->radius_das == NULL) {
842 wpa_printf(MSG_ERROR, "RADIUS DAS initialization "
847 #endif /* CONFIG_NO_RADIUS */
849 if (hostapd_acl_init(hapd)) {
850 wpa_printf(MSG_ERROR, "ACL initialization failed.");
853 if (hostapd_init_wps(hapd, conf))
856 if (authsrv_init(hapd) < 0)
859 if (ieee802_1x_init(hapd)) {
860 wpa_printf(MSG_ERROR, "IEEE 802.1X initialization failed.");
864 if ((conf->wpa || conf->osen) && hostapd_setup_wpa(hapd))
867 if (accounting_init(hapd)) {
868 wpa_printf(MSG_ERROR, "Accounting initialization failed.");
872 if (conf->ieee802_11f &&
873 (hapd->iapp = iapp_init(hapd, conf->iapp_iface)) == NULL) {
874 wpa_printf(MSG_ERROR, "IEEE 802.11F (IAPP) initialization "
879 #ifdef CONFIG_INTERWORKING
880 if (gas_serv_init(hapd)) {
881 wpa_printf(MSG_ERROR, "GAS server initialization failed");
885 if (conf->qos_map_set_len &&
886 hostapd_drv_set_qos_map(hapd, conf->qos_map_set,
887 conf->qos_map_set_len)) {
888 wpa_printf(MSG_ERROR, "Failed to initialize QoS Map");
891 #endif /* CONFIG_INTERWORKING */
893 if (conf->bss_load_update_period && bss_load_update_init(hapd)) {
894 wpa_printf(MSG_ERROR, "BSS Load initialization failed");
898 if (conf->proxy_arp) {
899 if (x_snoop_init(hapd)) {
900 wpa_printf(MSG_ERROR,
901 "Generic snooping infrastructure initialization failed");
905 if (dhcp_snoop_init(hapd)) {
906 wpa_printf(MSG_ERROR,
907 "DHCP snooping initialization failed");
912 if (!hostapd_drv_none(hapd) && vlan_init(hapd)) {
913 wpa_printf(MSG_ERROR, "VLAN initialization failed.");
917 if (!conf->start_disabled && ieee802_11_set_beacon(hapd) < 0)
920 if (hapd->wpa_auth && wpa_init_keys(hapd->wpa_auth) < 0)
923 if (hapd->driver && hapd->driver->set_operstate)
924 hapd->driver->set_operstate(hapd->drv_priv, 1);
930 static void hostapd_tx_queue_params(struct hostapd_iface *iface)
932 struct hostapd_data *hapd = iface->bss[0];
934 struct hostapd_tx_queue_params *p;
937 if (iface->mconf == NULL)
939 #endif /* CONFIG_MESH */
941 for (i = 0; i < NUM_TX_QUEUES; i++) {
942 p = &iface->conf->tx_queue[i];
944 if (hostapd_set_tx_queue_params(hapd, i, p->aifs, p->cwmin,
945 p->cwmax, p->burst)) {
946 wpa_printf(MSG_DEBUG, "Failed to set TX queue "
947 "parameters for queue %d.", i);
948 /* Continue anyway */
954 static int hostapd_set_acl_list(struct hostapd_data *hapd,
955 struct mac_acl_entry *mac_acl,
956 int n_entries, u8 accept_acl)
958 struct hostapd_acl_params *acl_params;
961 acl_params = os_zalloc(sizeof(*acl_params) +
962 (n_entries * sizeof(acl_params->mac_acl[0])));
966 for (i = 0; i < n_entries; i++)
967 os_memcpy(acl_params->mac_acl[i].addr, mac_acl[i].addr,
970 acl_params->acl_policy = accept_acl;
971 acl_params->num_mac_acl = n_entries;
973 err = hostapd_drv_set_acl(hapd, acl_params);
981 static void hostapd_set_acl(struct hostapd_data *hapd)
983 struct hostapd_config *conf = hapd->iconf;
987 if (hapd->iface->drv_max_acl_mac_addrs == 0)
990 if (conf->bss[0]->macaddr_acl == DENY_UNLESS_ACCEPTED) {
992 err = hostapd_set_acl_list(hapd, conf->bss[0]->accept_mac,
993 conf->bss[0]->num_accept_mac,
996 wpa_printf(MSG_DEBUG, "Failed to set accept acl");
999 } else if (conf->bss[0]->macaddr_acl == ACCEPT_UNLESS_DENIED) {
1001 err = hostapd_set_acl_list(hapd, conf->bss[0]->deny_mac,
1002 conf->bss[0]->num_deny_mac,
1005 wpa_printf(MSG_DEBUG, "Failed to set deny acl");
1012 static int start_ctrl_iface_bss(struct hostapd_data *hapd)
1014 if (!hapd->iface->interfaces ||
1015 !hapd->iface->interfaces->ctrl_iface_init)
1018 if (hapd->iface->interfaces->ctrl_iface_init(hapd)) {
1019 wpa_printf(MSG_ERROR,
1020 "Failed to setup control interface for %s",
1029 static int start_ctrl_iface(struct hostapd_iface *iface)
1033 if (!iface->interfaces || !iface->interfaces->ctrl_iface_init)
1036 for (i = 0; i < iface->num_bss; i++) {
1037 struct hostapd_data *hapd = iface->bss[i];
1038 if (iface->interfaces->ctrl_iface_init(hapd)) {
1039 wpa_printf(MSG_ERROR,
1040 "Failed to setup control interface for %s",
1050 static void channel_list_update_timeout(void *eloop_ctx, void *timeout_ctx)
1052 struct hostapd_iface *iface = eloop_ctx;
1054 if (!iface->wait_channel_update) {
1055 wpa_printf(MSG_INFO, "Channel list update timeout, but interface was not waiting for it");
1060 * It is possible that the existing channel list is acceptable, so try
1063 wpa_printf(MSG_DEBUG, "Channel list update timeout - try to continue anyway");
1064 setup_interface2(iface);
1068 void hostapd_channel_list_updated(struct hostapd_iface *iface, int initiator)
1070 if (!iface->wait_channel_update || initiator != REGDOM_SET_BY_USER)
1073 wpa_printf(MSG_DEBUG, "Channel list updated - continue setup");
1074 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
1075 setup_interface2(iface);
1079 static int setup_interface(struct hostapd_iface *iface)
1081 struct hostapd_data *hapd = iface->bss[0];
1085 * It is possible that setup_interface() is called after the interface
1086 * was disabled etc., in which case driver_ap_teardown is possibly set
1087 * to 1. Clear it here so any other key/station deletion, which is not
1088 * part of a teardown flow, would also call the relevant driver
1091 iface->driver_ap_teardown = 0;
1093 if (!iface->phy[0]) {
1094 const char *phy = hostapd_drv_get_radio_name(hapd);
1096 wpa_printf(MSG_DEBUG, "phy: %s", phy);
1097 os_strlcpy(iface->phy, phy, sizeof(iface->phy));
1102 * Make sure that all BSSes get configured with a pointer to the same
1105 for (i = 1; i < iface->num_bss; i++) {
1106 iface->bss[i]->driver = hapd->driver;
1107 iface->bss[i]->drv_priv = hapd->drv_priv;
1110 if (hostapd_validate_bssid_configuration(iface))
1114 * Initialize control interfaces early to allow external monitoring of
1115 * channel setup operations that may take considerable amount of time
1116 * especially for DFS cases.
1118 if (start_ctrl_iface(iface))
1121 if (hapd->iconf->country[0] && hapd->iconf->country[1]) {
1122 char country[4], previous_country[4];
1124 hostapd_set_state(iface, HAPD_IFACE_COUNTRY_UPDATE);
1125 if (hostapd_get_country(hapd, previous_country) < 0)
1126 previous_country[0] = '\0';
1128 os_memcpy(country, hapd->iconf->country, 3);
1130 if (hostapd_set_country(hapd, country) < 0) {
1131 wpa_printf(MSG_ERROR, "Failed to set country code");
1135 wpa_printf(MSG_DEBUG, "Previous country code %s, new country code %s",
1136 previous_country, country);
1138 if (os_strncmp(previous_country, country, 2) != 0) {
1139 wpa_printf(MSG_DEBUG, "Continue interface setup after channel list update");
1140 iface->wait_channel_update = 1;
1141 eloop_register_timeout(5, 0,
1142 channel_list_update_timeout,
1148 return setup_interface2(iface);
1152 static int setup_interface2(struct hostapd_iface *iface)
1154 iface->wait_channel_update = 0;
1156 if (hostapd_get_hw_features(iface)) {
1157 /* Not all drivers support this yet, so continue without hw
1160 int ret = hostapd_select_hw_mode(iface);
1162 wpa_printf(MSG_ERROR, "Could not select hw_mode and "
1163 "channel. (%d)", ret);
1167 wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback (ACS)");
1170 ret = hostapd_check_ht_capab(iface);
1174 wpa_printf(MSG_DEBUG, "Interface initialization will "
1175 "be completed in a callback");
1179 if (iface->conf->ieee80211h)
1180 wpa_printf(MSG_DEBUG, "DFS support is enabled");
1182 return hostapd_setup_interface_complete(iface, 0);
1185 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
1186 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
1187 if (iface->interfaces && iface->interfaces->terminate_on_error)
1194 * hostapd_setup_interface_complete - Complete interface setup
1196 * This function is called when previous steps in the interface setup has been
1197 * completed. This can also start operations, e.g., DFS, that will require
1198 * additional processing before interface is ready to be enabled. Such
1199 * operations will call this function from eloop callbacks when finished.
1201 int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err)
1203 struct hostapd_data *hapd = iface->bss[0];
1206 int delay_apply_cfg = 0;
1211 wpa_printf(MSG_DEBUG, "Completing interface initialization");
1212 if (iface->conf->channel) {
1215 #endif /* NEED_AP_MLME */
1217 iface->freq = hostapd_hw_get_freq(hapd, iface->conf->channel);
1218 wpa_printf(MSG_DEBUG, "Mode: %s Channel: %d "
1219 "Frequency: %d MHz",
1220 hostapd_hw_mode_txt(iface->conf->hw_mode),
1221 iface->conf->channel, iface->freq);
1224 /* Handle DFS only if it is not offloaded to the driver */
1225 if (!(iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)) {
1227 res = hostapd_handle_dfs(iface);
1234 #endif /* NEED_AP_MLME */
1237 if (iface->mconf != NULL) {
1238 wpa_printf(MSG_DEBUG,
1239 "%s: Mesh configuration will be applied while joining the mesh network",
1240 iface->bss[0]->conf->iface);
1241 delay_apply_cfg = 1;
1243 #endif /* CONFIG_MESH */
1245 if (!delay_apply_cfg &&
1246 hostapd_set_freq(hapd, hapd->iconf->hw_mode, iface->freq,
1247 hapd->iconf->channel,
1248 hapd->iconf->ieee80211n,
1249 hapd->iconf->ieee80211ac,
1250 hapd->iconf->secondary_channel,
1251 hapd->iconf->vht_oper_chwidth,
1252 hapd->iconf->vht_oper_centr_freq_seg0_idx,
1253 hapd->iconf->vht_oper_centr_freq_seg1_idx)) {
1254 wpa_printf(MSG_ERROR, "Could not set channel for "
1260 if (iface->current_mode) {
1261 if (hostapd_prepare_rates(iface, iface->current_mode)) {
1262 wpa_printf(MSG_ERROR, "Failed to prepare rates "
1264 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1265 HOSTAPD_LEVEL_WARNING,
1266 "Failed to prepare rates table.");
1271 if (hapd->iconf->rts_threshold > -1 &&
1272 hostapd_set_rts(hapd, hapd->iconf->rts_threshold)) {
1273 wpa_printf(MSG_ERROR, "Could not set RTS threshold for "
1278 if (hapd->iconf->fragm_threshold > -1 &&
1279 hostapd_set_frag(hapd, hapd->iconf->fragm_threshold)) {
1280 wpa_printf(MSG_ERROR, "Could not set fragmentation threshold "
1281 "for kernel driver");
1285 prev_addr = hapd->own_addr;
1287 for (j = 0; j < iface->num_bss; j++) {
1288 hapd = iface->bss[j];
1290 os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN);
1291 if (hostapd_setup_bss(hapd, j == 0)) {
1293 hapd = iface->bss[j];
1294 hostapd_bss_deinit_no_free(hapd);
1295 hostapd_free_hapd_data(hapd);
1299 if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0)
1300 prev_addr = hapd->own_addr;
1302 hapd = iface->bss[0];
1304 hostapd_tx_queue_params(iface);
1306 ap_list_init(iface);
1308 hostapd_set_acl(hapd);
1310 if (hostapd_driver_commit(hapd) < 0) {
1311 wpa_printf(MSG_ERROR, "%s: Failed to commit driver "
1312 "configuration", __func__);
1317 * WPS UPnP module can be initialized only when the "upnp_iface" is up.
1318 * If "interface" and "upnp_iface" are the same (e.g., non-bridge
1319 * mode), the interface is up only after driver_commit, so initialize
1320 * WPS after driver_commit.
1322 for (j = 0; j < iface->num_bss; j++) {
1323 if (hostapd_init_wps_complete(iface->bss[j]))
1327 hostapd_set_state(iface, HAPD_IFACE_ENABLED);
1328 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_ENABLED);
1329 if (hapd->setup_complete_cb)
1330 hapd->setup_complete_cb(hapd->setup_complete_cb_ctx);
1332 wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
1333 iface->bss[0]->conf->iface);
1334 if (iface->interfaces && iface->interfaces->terminate_on_error > 0)
1335 iface->interfaces->terminate_on_error--;
1340 wpa_printf(MSG_ERROR, "Interface initialization failed");
1341 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
1342 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
1343 if (iface->interfaces && iface->interfaces->terminate_on_error)
1350 * hostapd_setup_interface - Setup of an interface
1351 * @iface: Pointer to interface data.
1352 * Returns: 0 on success, -1 on failure
1354 * Initializes the driver interface, validates the configuration,
1355 * and sets driver parameters based on the configuration.
1356 * Flushes old stations, sets the channel, encryption,
1357 * beacons, and WDS links based on the configuration.
1359 * If interface setup requires more time, e.g., to perform HT co-ex scans, ACS,
1360 * or DFS operations, this function returns 0 before such operations have been
1361 * completed. The pending operations are registered into eloop and will be
1362 * completed from eloop callbacks. Those callbacks end up calling
1363 * hostapd_setup_interface_complete() once setup has been completed.
1365 int hostapd_setup_interface(struct hostapd_iface *iface)
1369 ret = setup_interface(iface);
1371 wpa_printf(MSG_ERROR, "%s: Unable to setup interface.",
1372 iface->bss[0]->conf->iface);
1381 * hostapd_alloc_bss_data - Allocate and initialize per-BSS data
1382 * @hapd_iface: Pointer to interface data
1383 * @conf: Pointer to per-interface configuration
1384 * @bss: Pointer to per-BSS configuration for this BSS
1385 * Returns: Pointer to allocated BSS data
1387 * This function is used to allocate per-BSS data structure. This data will be
1388 * freed after hostapd_cleanup() is called for it during interface
1391 struct hostapd_data *
1392 hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
1393 struct hostapd_config *conf,
1394 struct hostapd_bss_config *bss)
1396 struct hostapd_data *hapd;
1398 hapd = os_zalloc(sizeof(*hapd));
1402 hapd->new_assoc_sta_cb = hostapd_new_assoc_sta;
1405 hapd->iface = hapd_iface;
1406 hapd->driver = hapd->iconf->driver;
1407 hapd->ctrl_sock = -1;
1413 static void hostapd_bss_deinit(struct hostapd_data *hapd)
1415 wpa_printf(MSG_DEBUG, "%s: deinit bss %s", __func__,
1417 hostapd_bss_deinit_no_free(hapd);
1418 hostapd_cleanup(hapd);
1422 void hostapd_interface_deinit(struct hostapd_iface *iface)
1426 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
1430 #ifdef CONFIG_IEEE80211N
1432 hostapd_stop_setup_timers(iface);
1433 eloop_cancel_timeout(ap_ht2040_timeout, iface, NULL);
1434 #endif /* NEED_AP_MLME */
1435 #endif /* CONFIG_IEEE80211N */
1436 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
1437 iface->wait_channel_update = 0;
1439 for (j = iface->num_bss - 1; j >= 0; j--)
1440 hostapd_bss_deinit(iface->bss[j]);
1444 void hostapd_interface_free(struct hostapd_iface *iface)
1447 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
1448 for (j = 0; j < iface->num_bss; j++) {
1449 wpa_printf(MSG_DEBUG, "%s: free hapd %p",
1450 __func__, iface->bss[j]);
1451 os_free(iface->bss[j]);
1453 hostapd_cleanup_iface(iface);
1458 * hostapd_init - Allocate and initialize per-interface data
1459 * @config_file: Path to the configuration file
1460 * Returns: Pointer to the allocated interface data or %NULL on failure
1462 * This function is used to allocate main data structures for per-interface
1463 * data. The allocated data buffer will be freed by calling
1464 * hostapd_cleanup_iface().
1466 struct hostapd_iface * hostapd_init(struct hapd_interfaces *interfaces,
1467 const char *config_file)
1469 struct hostapd_iface *hapd_iface = NULL;
1470 struct hostapd_config *conf = NULL;
1471 struct hostapd_data *hapd;
1474 hapd_iface = os_zalloc(sizeof(*hapd_iface));
1475 if (hapd_iface == NULL)
1478 hapd_iface->config_fname = os_strdup(config_file);
1479 if (hapd_iface->config_fname == NULL)
1482 conf = interfaces->config_read_cb(hapd_iface->config_fname);
1485 hapd_iface->conf = conf;
1487 hapd_iface->num_bss = conf->num_bss;
1488 hapd_iface->bss = os_calloc(conf->num_bss,
1489 sizeof(struct hostapd_data *));
1490 if (hapd_iface->bss == NULL)
1493 for (i = 0; i < conf->num_bss; i++) {
1494 hapd = hapd_iface->bss[i] =
1495 hostapd_alloc_bss_data(hapd_iface, conf,
1499 hapd->msg_ctx = hapd;
1505 wpa_printf(MSG_ERROR, "Failed to set up interface with %s",
1508 hostapd_config_free(conf);
1510 os_free(hapd_iface->config_fname);
1511 os_free(hapd_iface->bss);
1512 wpa_printf(MSG_DEBUG, "%s: free iface %p",
1513 __func__, hapd_iface);
1514 os_free(hapd_iface);
1520 static int ifname_in_use(struct hapd_interfaces *interfaces, const char *ifname)
1524 for (i = 0; i < interfaces->count; i++) {
1525 struct hostapd_iface *iface = interfaces->iface[i];
1526 for (j = 0; j < iface->num_bss; j++) {
1527 struct hostapd_data *hapd = iface->bss[j];
1528 if (os_strcmp(ifname, hapd->conf->iface) == 0)
1538 * hostapd_interface_init_bss - Read configuration file and init BSS data
1540 * This function is used to parse configuration file for a BSS. This BSS is
1541 * added to an existing interface sharing the same radio (if any) or a new
1542 * interface is created if this is the first interface on a radio. This
1543 * allocate memory for the BSS. No actual driver operations are started.
1545 * This is similar to hostapd_interface_init(), but for a case where the
1546 * configuration is used to add a single BSS instead of all BSSes for a radio.
1548 struct hostapd_iface *
1549 hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy,
1550 const char *config_fname, int debug)
1552 struct hostapd_iface *new_iface = NULL, *iface = NULL;
1553 struct hostapd_data *hapd;
1560 for (i = 0; i < interfaces->count; i++) {
1561 if (os_strcmp(interfaces->iface[i]->phy, phy) == 0) {
1562 iface = interfaces->iface[i];
1567 wpa_printf(MSG_INFO, "Configuration file: %s (phy %s)%s",
1568 config_fname, phy, iface ? "" : " --> new PHY");
1570 struct hostapd_config *conf;
1571 struct hostapd_bss_config **tmp_conf;
1572 struct hostapd_data **tmp_bss;
1573 struct hostapd_bss_config *bss;
1576 /* Add new BSS to existing iface */
1577 conf = interfaces->config_read_cb(config_fname);
1580 if (conf->num_bss > 1) {
1581 wpa_printf(MSG_ERROR, "Multiple BSSes specified in BSS-config");
1582 hostapd_config_free(conf);
1586 ifname = conf->bss[0]->iface;
1587 if (ifname[0] != '\0' && ifname_in_use(interfaces, ifname)) {
1588 wpa_printf(MSG_ERROR,
1589 "Interface name %s already in use", ifname);
1590 hostapd_config_free(conf);
1594 tmp_conf = os_realloc_array(
1595 iface->conf->bss, iface->conf->num_bss + 1,
1596 sizeof(struct hostapd_bss_config *));
1597 tmp_bss = os_realloc_array(iface->bss, iface->num_bss + 1,
1598 sizeof(struct hostapd_data *));
1600 iface->bss = tmp_bss;
1602 iface->conf->bss = tmp_conf;
1603 iface->conf->last_bss = tmp_conf[0];
1605 if (tmp_bss == NULL || tmp_conf == NULL) {
1606 hostapd_config_free(conf);
1609 bss = iface->conf->bss[iface->conf->num_bss] = conf->bss[0];
1610 iface->conf->num_bss++;
1612 hapd = hostapd_alloc_bss_data(iface, iface->conf, bss);
1614 iface->conf->num_bss--;
1615 hostapd_config_free(conf);
1618 iface->conf->last_bss = bss;
1619 iface->bss[iface->num_bss] = hapd;
1620 hapd->msg_ctx = hapd;
1622 bss_idx = iface->num_bss++;
1624 conf->bss[0] = NULL;
1625 hostapd_config_free(conf);
1627 /* Add a new iface with the first BSS */
1628 new_iface = iface = hostapd_init(interfaces, config_fname);
1631 os_strlcpy(iface->phy, phy, sizeof(iface->phy));
1632 iface->interfaces = interfaces;
1636 for (k = 0; k < debug; k++) {
1637 if (iface->bss[bss_idx]->conf->logger_stdout_level > 0)
1638 iface->bss[bss_idx]->conf->logger_stdout_level--;
1641 if (iface->conf->bss[bss_idx]->iface[0] == '\0' &&
1642 !hostapd_drv_none(iface->bss[bss_idx])) {
1643 wpa_printf(MSG_ERROR, "Interface name not specified in %s",
1646 hostapd_interface_deinit_free(new_iface);
1654 void hostapd_interface_deinit_free(struct hostapd_iface *iface)
1656 const struct wpa_driver_ops *driver;
1659 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
1662 wpa_printf(MSG_DEBUG, "%s: num_bss=%u conf->num_bss=%u",
1663 __func__, (unsigned int) iface->num_bss,
1664 (unsigned int) iface->conf->num_bss);
1665 driver = iface->bss[0]->driver;
1666 drv_priv = iface->bss[0]->drv_priv;
1667 hostapd_interface_deinit(iface);
1668 wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
1669 __func__, driver, drv_priv);
1670 if (driver && driver->hapd_deinit && drv_priv) {
1671 driver->hapd_deinit(drv_priv);
1672 iface->bss[0]->drv_priv = NULL;
1674 hostapd_interface_free(iface);
1678 static void hostapd_deinit_driver(const struct wpa_driver_ops *driver,
1680 struct hostapd_iface *hapd_iface)
1684 wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
1685 __func__, driver, drv_priv);
1686 if (driver && driver->hapd_deinit && drv_priv) {
1687 driver->hapd_deinit(drv_priv);
1688 for (j = 0; j < hapd_iface->num_bss; j++) {
1689 wpa_printf(MSG_DEBUG, "%s:bss[%d]->drv_priv=%p",
1691 hapd_iface->bss[j]->drv_priv);
1692 if (hapd_iface->bss[j]->drv_priv == drv_priv)
1693 hapd_iface->bss[j]->drv_priv = NULL;
1699 int hostapd_enable_iface(struct hostapd_iface *hapd_iface)
1703 if (hapd_iface->bss[0]->drv_priv != NULL) {
1704 wpa_printf(MSG_ERROR, "Interface %s already enabled",
1705 hapd_iface->conf->bss[0]->iface);
1709 wpa_printf(MSG_DEBUG, "Enable interface %s",
1710 hapd_iface->conf->bss[0]->iface);
1712 for (j = 0; j < hapd_iface->num_bss; j++)
1713 hostapd_set_security_params(hapd_iface->conf->bss[j], 1);
1714 if (hostapd_config_check(hapd_iface->conf, 1) < 0) {
1715 wpa_printf(MSG_INFO, "Invalid configuration - cannot enable");
1719 if (hapd_iface->interfaces == NULL ||
1720 hapd_iface->interfaces->driver_init == NULL ||
1721 hapd_iface->interfaces->driver_init(hapd_iface))
1724 if (hostapd_setup_interface(hapd_iface)) {
1725 hostapd_deinit_driver(hapd_iface->bss[0]->driver,
1726 hapd_iface->bss[0]->drv_priv,
1735 int hostapd_reload_iface(struct hostapd_iface *hapd_iface)
1739 wpa_printf(MSG_DEBUG, "Reload interface %s",
1740 hapd_iface->conf->bss[0]->iface);
1741 for (j = 0; j < hapd_iface->num_bss; j++)
1742 hostapd_set_security_params(hapd_iface->conf->bss[j], 1);
1743 if (hostapd_config_check(hapd_iface->conf, 1) < 0) {
1744 wpa_printf(MSG_ERROR, "Updated configuration is invalid");
1747 hostapd_clear_old(hapd_iface);
1748 for (j = 0; j < hapd_iface->num_bss; j++)
1749 hostapd_reload_bss(hapd_iface->bss[j]);
1755 int hostapd_disable_iface(struct hostapd_iface *hapd_iface)
1758 const struct wpa_driver_ops *driver;
1761 if (hapd_iface == NULL)
1764 if (hapd_iface->bss[0]->drv_priv == NULL) {
1765 wpa_printf(MSG_INFO, "Interface %s already disabled",
1766 hapd_iface->conf->bss[0]->iface);
1770 wpa_msg(hapd_iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
1771 driver = hapd_iface->bss[0]->driver;
1772 drv_priv = hapd_iface->bss[0]->drv_priv;
1774 hapd_iface->driver_ap_teardown =
1775 !!(hapd_iface->drv_flags &
1776 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
1778 /* same as hostapd_interface_deinit without deinitializing ctrl-iface */
1779 for (j = 0; j < hapd_iface->num_bss; j++) {
1780 struct hostapd_data *hapd = hapd_iface->bss[j];
1781 hostapd_bss_deinit_no_free(hapd);
1782 hostapd_free_hapd_data(hapd);
1785 hostapd_deinit_driver(driver, drv_priv, hapd_iface);
1787 /* From hostapd_cleanup_iface: These were initialized in
1788 * hostapd_setup_interface and hostapd_setup_interface_complete
1790 hostapd_cleanup_iface_partial(hapd_iface);
1792 wpa_printf(MSG_DEBUG, "Interface %s disabled",
1793 hapd_iface->bss[0]->conf->iface);
1794 hostapd_set_state(hapd_iface, HAPD_IFACE_DISABLED);
1799 static struct hostapd_iface *
1800 hostapd_iface_alloc(struct hapd_interfaces *interfaces)
1802 struct hostapd_iface **iface, *hapd_iface;
1804 iface = os_realloc_array(interfaces->iface, interfaces->count + 1,
1805 sizeof(struct hostapd_iface *));
1808 interfaces->iface = iface;
1809 hapd_iface = interfaces->iface[interfaces->count] =
1810 os_zalloc(sizeof(*hapd_iface));
1811 if (hapd_iface == NULL) {
1812 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for "
1813 "the interface", __func__);
1816 interfaces->count++;
1817 hapd_iface->interfaces = interfaces;
1823 static struct hostapd_config *
1824 hostapd_config_alloc(struct hapd_interfaces *interfaces, const char *ifname,
1825 const char *ctrl_iface)
1827 struct hostapd_bss_config *bss;
1828 struct hostapd_config *conf;
1830 /* Allocates memory for bss and conf */
1831 conf = hostapd_config_defaults();
1833 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for "
1834 "configuration", __func__);
1838 conf->driver = wpa_drivers[0];
1839 if (conf->driver == NULL) {
1840 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
1841 hostapd_config_free(conf);
1845 bss = conf->last_bss = conf->bss[0];
1847 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
1848 bss->ctrl_interface = os_strdup(ctrl_iface);
1849 if (bss->ctrl_interface == NULL) {
1850 hostapd_config_free(conf);
1854 /* Reading configuration file skipped, will be done in SET!
1855 * From reading the configuration till the end has to be done in
1862 static struct hostapd_iface * hostapd_data_alloc(
1863 struct hapd_interfaces *interfaces, struct hostapd_config *conf)
1866 struct hostapd_iface *hapd_iface =
1867 interfaces->iface[interfaces->count - 1];
1868 struct hostapd_data *hapd;
1870 hapd_iface->conf = conf;
1871 hapd_iface->num_bss = conf->num_bss;
1873 hapd_iface->bss = os_zalloc(conf->num_bss *
1874 sizeof(struct hostapd_data *));
1875 if (hapd_iface->bss == NULL)
1878 for (i = 0; i < conf->num_bss; i++) {
1879 hapd = hapd_iface->bss[i] =
1880 hostapd_alloc_bss_data(hapd_iface, conf, conf->bss[i]);
1883 hapd->msg_ctx = hapd;
1886 hapd_iface->interfaces = interfaces;
1892 int hostapd_add_iface(struct hapd_interfaces *interfaces, char *buf)
1894 struct hostapd_config *conf = NULL;
1895 struct hostapd_iface *hapd_iface = NULL, *new_iface = NULL;
1896 struct hostapd_data *hapd;
1899 const char *conf_file = NULL, *phy_name = NULL;
1901 if (os_strncmp(buf, "bss_config=", 11) == 0) {
1903 phy_name = buf + 11;
1904 pos = os_strchr(phy_name, ':');
1909 if (!os_strlen(conf_file))
1912 hapd_iface = hostapd_interface_init_bss(interfaces, phy_name,
1916 for (j = 0; j < interfaces->count; j++) {
1917 if (interfaces->iface[j] == hapd_iface)
1920 if (j == interfaces->count) {
1921 struct hostapd_iface **tmp;
1922 tmp = os_realloc_array(interfaces->iface,
1923 interfaces->count + 1,
1924 sizeof(struct hostapd_iface *));
1926 hostapd_interface_deinit_free(hapd_iface);
1929 interfaces->iface = tmp;
1930 interfaces->iface[interfaces->count++] = hapd_iface;
1931 new_iface = hapd_iface;
1935 if (interfaces->driver_init(hapd_iface) ||
1936 hostapd_setup_interface(hapd_iface)) {
1937 interfaces->count--;
1941 /* Assign new BSS with bss[0]'s driver info */
1942 hapd = hapd_iface->bss[hapd_iface->num_bss - 1];
1943 hapd->driver = hapd_iface->bss[0]->driver;
1944 hapd->drv_priv = hapd_iface->bss[0]->drv_priv;
1945 os_memcpy(hapd->own_addr, hapd_iface->bss[0]->own_addr,
1948 if (start_ctrl_iface_bss(hapd) < 0 ||
1949 (hapd_iface->state == HAPD_IFACE_ENABLED &&
1950 hostapd_setup_bss(hapd, -1))) {
1951 hostapd_cleanup(hapd);
1952 hapd_iface->bss[hapd_iface->num_bss - 1] = NULL;
1953 hapd_iface->conf->num_bss--;
1954 hapd_iface->num_bss--;
1955 wpa_printf(MSG_DEBUG, "%s: free hapd %p %s",
1956 __func__, hapd, hapd->conf->iface);
1964 ptr = os_strchr(buf, ' ');
1969 if (os_strncmp(ptr, "config=", 7) == 0)
1970 conf_file = ptr + 7;
1972 for (i = 0; i < interfaces->count; i++) {
1973 if (!os_strcmp(interfaces->iface[i]->conf->bss[0]->iface,
1975 wpa_printf(MSG_INFO, "Cannot add interface - it "
1981 hapd_iface = hostapd_iface_alloc(interfaces);
1982 if (hapd_iface == NULL) {
1983 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
1984 "for interface", __func__);
1988 if (conf_file && interfaces->config_read_cb) {
1989 conf = interfaces->config_read_cb(conf_file);
1990 if (conf && conf->bss)
1991 os_strlcpy(conf->bss[0]->iface, buf,
1992 sizeof(conf->bss[0]->iface));
1994 conf = hostapd_config_alloc(interfaces, buf, ptr);
1995 if (conf == NULL || conf->bss == NULL) {
1996 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
1997 "for configuration", __func__);
2001 hapd_iface = hostapd_data_alloc(interfaces, conf);
2002 if (hapd_iface == NULL) {
2003 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
2004 "for hostapd", __func__);
2008 if (start_ctrl_iface(hapd_iface) < 0)
2011 wpa_printf(MSG_INFO, "Add interface '%s'", conf->bss[0]->iface);
2017 hostapd_config_free(conf);
2019 if (hapd_iface->bss) {
2020 for (i = 0; i < hapd_iface->num_bss; i++) {
2021 hapd = hapd_iface->bss[i];
2024 if (hapd_iface->interfaces &&
2025 hapd_iface->interfaces->ctrl_iface_deinit)
2026 hapd_iface->interfaces->
2027 ctrl_iface_deinit(hapd);
2028 wpa_printf(MSG_DEBUG, "%s: free hapd %p (%s)",
2029 __func__, hapd_iface->bss[i],
2032 hapd_iface->bss[i] = NULL;
2034 os_free(hapd_iface->bss);
2036 wpa_printf(MSG_DEBUG, "%s: free iface %p",
2037 __func__, hapd_iface);
2038 os_free(hapd_iface);
2044 static int hostapd_remove_bss(struct hostapd_iface *iface, unsigned int idx)
2048 wpa_printf(MSG_INFO, "Remove BSS '%s'", iface->conf->bss[idx]->iface);
2050 /* Remove hostapd_data only if it has already been initialized */
2051 if (idx < iface->num_bss) {
2052 struct hostapd_data *hapd = iface->bss[idx];
2054 hostapd_bss_deinit(hapd);
2055 wpa_printf(MSG_DEBUG, "%s: free hapd %p (%s)",
2056 __func__, hapd, hapd->conf->iface);
2057 hostapd_config_free_bss(hapd->conf);
2062 for (i = idx; i < iface->num_bss; i++)
2063 iface->bss[i] = iface->bss[i + 1];
2065 hostapd_config_free_bss(iface->conf->bss[idx]);
2066 iface->conf->bss[idx] = NULL;
2069 iface->conf->num_bss--;
2070 for (i = idx; i < iface->conf->num_bss; i++)
2071 iface->conf->bss[i] = iface->conf->bss[i + 1];
2077 int hostapd_remove_iface(struct hapd_interfaces *interfaces, char *buf)
2079 struct hostapd_iface *hapd_iface;
2082 for (i = 0; i < interfaces->count; i++) {
2083 hapd_iface = interfaces->iface[i];
2084 if (hapd_iface == NULL)
2086 if (!os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
2087 wpa_printf(MSG_INFO, "Remove interface '%s'", buf);
2088 hapd_iface->driver_ap_teardown =
2089 !!(hapd_iface->drv_flags &
2090 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
2092 hostapd_interface_deinit_free(hapd_iface);
2094 while (k < (interfaces->count - 1)) {
2095 interfaces->iface[k] =
2096 interfaces->iface[k + 1];
2099 interfaces->count--;
2103 for (j = 0; j < hapd_iface->conf->num_bss; j++) {
2104 if (!os_strcmp(hapd_iface->conf->bss[j]->iface, buf)) {
2105 hapd_iface->driver_ap_teardown =
2106 !(hapd_iface->drv_flags &
2107 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
2108 return hostapd_remove_bss(hapd_iface, j);
2117 * hostapd_new_assoc_sta - Notify that a new station associated with the AP
2118 * @hapd: Pointer to BSS data
2119 * @sta: Pointer to the associated STA data
2120 * @reassoc: 1 to indicate this was a re-association; 0 = first association
2122 * This function will be called whenever a station associates with the AP. It
2123 * can be called from ieee802_11.c for drivers that export MLME to hostapd and
2124 * from drv_callbacks.c based on driver events for drivers that take care of
2125 * management frames (IEEE 802.11 authentication and association) internally.
2127 void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
2130 if (hapd->tkip_countermeasures) {
2131 hostapd_drv_sta_deauth(hapd, sta->addr,
2132 WLAN_REASON_MICHAEL_MIC_FAILURE);
2136 hostapd_prune_associations(hapd, sta->addr);
2138 /* IEEE 802.11F (IAPP) */
2139 if (hapd->conf->ieee802_11f)
2140 iapp_new_station(hapd->iapp, sta);
2143 if (sta->p2p_ie == NULL && !sta->no_p2p_set) {
2144 sta->no_p2p_set = 1;
2145 hapd->num_sta_no_p2p++;
2146 if (hapd->num_sta_no_p2p == 1)
2147 hostapd_p2p_non_p2p_sta_connected(hapd);
2149 #endif /* CONFIG_P2P */
2151 /* Start accounting here, if IEEE 802.1X and WPA are not used.
2152 * IEEE 802.1X/WPA code will start accounting after the station has
2153 * been authorized. */
2154 if (!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) {
2155 ap_sta_set_authorized(hapd, sta, 1);
2156 os_get_reltime(&sta->connected_time);
2157 accounting_sta_start(hapd, sta);
2160 /* Start IEEE 802.1X authentication process for new stations */
2161 ieee802_1x_new_station(hapd, sta);
2163 if (sta->auth_alg != WLAN_AUTH_FT &&
2164 !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)))
2165 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH);
2167 wpa_auth_sta_associated(hapd->wpa_auth, sta->wpa_sm);
2169 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) {
2170 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
2171 "for " MACSTR " (%d seconds - ap_max_inactivity)",
2172 __func__, MAC2STR(sta->addr),
2173 hapd->conf->ap_max_inactivity);
2174 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
2175 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
2176 ap_handle_timer, hapd, sta);
2181 const char * hostapd_state_text(enum hostapd_iface_state s)
2184 case HAPD_IFACE_UNINITIALIZED:
2185 return "UNINITIALIZED";
2186 case HAPD_IFACE_DISABLED:
2188 case HAPD_IFACE_COUNTRY_UPDATE:
2189 return "COUNTRY_UPDATE";
2190 case HAPD_IFACE_ACS:
2192 case HAPD_IFACE_HT_SCAN:
2194 case HAPD_IFACE_DFS:
2196 case HAPD_IFACE_ENABLED:
2204 void hostapd_set_state(struct hostapd_iface *iface, enum hostapd_iface_state s)
2206 wpa_printf(MSG_INFO, "%s: interface state %s->%s",
2207 iface->conf->bss[0]->iface, hostapd_state_text(iface->state),
2208 hostapd_state_text(s));
2215 static void free_beacon_data(struct beacon_data *beacon)
2217 os_free(beacon->head);
2218 beacon->head = NULL;
2219 os_free(beacon->tail);
2220 beacon->tail = NULL;
2221 os_free(beacon->probe_resp);
2222 beacon->probe_resp = NULL;
2223 os_free(beacon->beacon_ies);
2224 beacon->beacon_ies = NULL;
2225 os_free(beacon->proberesp_ies);
2226 beacon->proberesp_ies = NULL;
2227 os_free(beacon->assocresp_ies);
2228 beacon->assocresp_ies = NULL;
2232 static int hostapd_build_beacon_data(struct hostapd_data *hapd,
2233 struct beacon_data *beacon)
2235 struct wpabuf *beacon_extra, *proberesp_extra, *assocresp_extra;
2236 struct wpa_driver_ap_params params;
2239 os_memset(beacon, 0, sizeof(*beacon));
2240 ret = ieee802_11_build_ap_params(hapd, ¶ms);
2244 ret = hostapd_build_ap_extra_ies(hapd, &beacon_extra,
2248 goto free_ap_params;
2251 beacon->head = os_malloc(params.head_len);
2253 goto free_ap_extra_ies;
2255 os_memcpy(beacon->head, params.head, params.head_len);
2256 beacon->head_len = params.head_len;
2258 beacon->tail = os_malloc(params.tail_len);
2262 os_memcpy(beacon->tail, params.tail, params.tail_len);
2263 beacon->tail_len = params.tail_len;
2265 if (params.proberesp != NULL) {
2266 beacon->probe_resp = os_malloc(params.proberesp_len);
2267 if (!beacon->probe_resp)
2270 os_memcpy(beacon->probe_resp, params.proberesp,
2271 params.proberesp_len);
2272 beacon->probe_resp_len = params.proberesp_len;
2275 /* copy the extra ies */
2277 beacon->beacon_ies = os_malloc(wpabuf_len(beacon_extra));
2278 if (!beacon->beacon_ies)
2281 os_memcpy(beacon->beacon_ies,
2282 beacon_extra->buf, wpabuf_len(beacon_extra));
2283 beacon->beacon_ies_len = wpabuf_len(beacon_extra);
2286 if (proberesp_extra) {
2287 beacon->proberesp_ies =
2288 os_malloc(wpabuf_len(proberesp_extra));
2289 if (!beacon->proberesp_ies)
2292 os_memcpy(beacon->proberesp_ies, proberesp_extra->buf,
2293 wpabuf_len(proberesp_extra));
2294 beacon->proberesp_ies_len = wpabuf_len(proberesp_extra);
2297 if (assocresp_extra) {
2298 beacon->assocresp_ies =
2299 os_malloc(wpabuf_len(assocresp_extra));
2300 if (!beacon->assocresp_ies)
2303 os_memcpy(beacon->assocresp_ies, assocresp_extra->buf,
2304 wpabuf_len(assocresp_extra));
2305 beacon->assocresp_ies_len = wpabuf_len(assocresp_extra);
2310 /* if the function fails, the caller should not free beacon data */
2312 free_beacon_data(beacon);
2315 hostapd_free_ap_extra_ies(hapd, beacon_extra, proberesp_extra,
2318 ieee802_11_free_ap_params(¶ms);
2324 * TODO: This flow currently supports only changing frequency within the
2325 * same hw_mode. Any other changes to MAC parameters or provided settings (even
2326 * width) are not supported.
2328 static int hostapd_change_config_freq(struct hostapd_data *hapd,
2329 struct hostapd_config *conf,
2330 struct hostapd_freq_params *params,
2331 struct hostapd_freq_params *old_params)
2335 if (!params->channel) {
2336 /* check if the new channel is supported by hw */
2337 params->channel = hostapd_hw_get_channel(hapd, params->freq);
2340 channel = params->channel;
2344 /* if a pointer to old_params is provided we save previous state */
2346 old_params->channel = conf->channel;
2347 old_params->ht_enabled = conf->ieee80211n;
2348 old_params->sec_channel_offset = conf->secondary_channel;
2351 conf->channel = channel;
2352 conf->ieee80211n = params->ht_enabled;
2353 conf->secondary_channel = params->sec_channel_offset;
2355 /* TODO: maybe call here hostapd_config_check here? */
2361 static int hostapd_fill_csa_settings(struct hostapd_data *hapd,
2362 struct csa_settings *settings)
2364 struct hostapd_iface *iface = hapd->iface;
2365 struct hostapd_freq_params old_freq;
2368 os_memset(&old_freq, 0, sizeof(old_freq));
2369 if (!iface || !iface->freq || hapd->csa_in_progress)
2372 ret = hostapd_change_config_freq(iface->bss[0], iface->conf,
2373 &settings->freq_params,
2378 ret = hostapd_build_beacon_data(hapd, &settings->beacon_after);
2380 /* change back the configuration */
2381 hostapd_change_config_freq(iface->bss[0], iface->conf,
2387 /* set channel switch parameters for csa ie */
2388 hapd->cs_freq_params = settings->freq_params;
2389 hapd->cs_count = settings->cs_count;
2390 hapd->cs_block_tx = settings->block_tx;
2392 ret = hostapd_build_beacon_data(hapd, &settings->beacon_csa);
2394 free_beacon_data(&settings->beacon_after);
2398 settings->counter_offset_beacon = hapd->cs_c_off_beacon;
2399 settings->counter_offset_presp = hapd->cs_c_off_proberesp;
2405 void hostapd_cleanup_cs_params(struct hostapd_data *hapd)
2407 os_memset(&hapd->cs_freq_params, 0, sizeof(hapd->cs_freq_params));
2409 hapd->cs_block_tx = 0;
2410 hapd->cs_c_off_beacon = 0;
2411 hapd->cs_c_off_proberesp = 0;
2412 hapd->csa_in_progress = 0;
2416 int hostapd_switch_channel(struct hostapd_data *hapd,
2417 struct csa_settings *settings)
2421 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA)) {
2422 wpa_printf(MSG_INFO, "CSA is not supported");
2426 ret = hostapd_fill_csa_settings(hapd, settings);
2430 ret = hostapd_drv_switch_channel(hapd, settings);
2431 free_beacon_data(&settings->beacon_csa);
2432 free_beacon_data(&settings->beacon_after);
2435 /* if we failed, clean cs parameters */
2436 hostapd_cleanup_cs_params(hapd);
2440 hapd->csa_in_progress = 1;
2446 hostapd_switch_channel_fallback(struct hostapd_iface *iface,
2447 const struct hostapd_freq_params *freq_params)
2449 int vht_seg0_idx = 0, vht_seg1_idx = 0, vht_bw = VHT_CHANWIDTH_USE_HT;
2452 wpa_printf(MSG_DEBUG, "Restarting all CSA-related BSSes");
2454 if (freq_params->center_freq1)
2455 vht_seg0_idx = 36 + (freq_params->center_freq1 - 5180) / 5;
2456 if (freq_params->center_freq2)
2457 vht_seg1_idx = 36 + (freq_params->center_freq2 - 5180) / 5;
2459 switch (freq_params->bandwidth) {
2463 vht_bw = VHT_CHANWIDTH_USE_HT;
2466 if (freq_params->center_freq2)
2467 vht_bw = VHT_CHANWIDTH_80P80MHZ;
2469 vht_bw = VHT_CHANWIDTH_80MHZ;
2472 vht_bw = VHT_CHANWIDTH_160MHZ;
2475 wpa_printf(MSG_WARNING, "Unknown CSA bandwidth: %d",
2476 freq_params->bandwidth);
2480 iface->freq = freq_params->freq;
2481 iface->conf->channel = freq_params->channel;
2482 iface->conf->secondary_channel = freq_params->sec_channel_offset;
2483 iface->conf->vht_oper_centr_freq_seg0_idx = vht_seg0_idx;
2484 iface->conf->vht_oper_centr_freq_seg1_idx = vht_seg1_idx;
2485 iface->conf->vht_oper_chwidth = vht_bw;
2486 iface->conf->ieee80211n = freq_params->ht_enabled;
2487 iface->conf->ieee80211ac = freq_params->vht_enabled;
2490 * cs_params must not be cleared earlier because the freq_params
2491 * argument may actually point to one of these.
2493 for (i = 0; i < iface->num_bss; i++)
2494 hostapd_cleanup_cs_params(iface->bss[i]);
2496 hostapd_disable_iface(iface);
2497 hostapd_enable_iface(iface);
2500 #endif /* NEED_AP_MLME */