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"
41 #include "ndisc_snoop.h"
44 static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason);
45 static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd);
46 static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd);
47 static int setup_interface2(struct hostapd_iface *iface);
48 static void channel_list_update_timeout(void *eloop_ctx, void *timeout_ctx);
51 int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
52 int (*cb)(struct hostapd_iface *iface,
53 void *ctx), void *ctx)
58 for (i = 0; i < interfaces->count; i++) {
59 ret = cb(interfaces->iface[i], ctx);
68 static void hostapd_reload_bss(struct hostapd_data *hapd)
70 struct hostapd_ssid *ssid;
72 #ifndef CONFIG_NO_RADIUS
73 radius_client_reconfig(hapd->radius, hapd->conf->radius);
74 #endif /* CONFIG_NO_RADIUS */
76 ssid = &hapd->conf->ssid;
77 if (!ssid->wpa_psk_set && ssid->wpa_psk && !ssid->wpa_psk->next &&
78 ssid->wpa_passphrase_set && ssid->wpa_passphrase) {
80 * Force PSK to be derived again since SSID or passphrase may
83 os_free(ssid->wpa_psk);
86 if (hostapd_setup_wpa_psk(hapd->conf)) {
87 wpa_printf(MSG_ERROR, "Failed to re-configure WPA PSK "
88 "after reloading configuration");
91 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
92 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1);
94 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0);
96 if ((hapd->conf->wpa || hapd->conf->osen) && hapd->wpa_auth == NULL) {
97 hostapd_setup_wpa(hapd);
99 wpa_init_keys(hapd->wpa_auth);
100 } else if (hapd->conf->wpa) {
103 hostapd_reconfig_wpa(hapd);
104 wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
105 if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len))
106 wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
107 "the kernel driver.");
108 } else if (hapd->wpa_auth) {
109 wpa_deinit(hapd->wpa_auth);
110 hapd->wpa_auth = NULL;
111 hostapd_set_privacy(hapd, 0);
112 hostapd_setup_encryption(hapd->conf->iface, hapd);
113 hostapd_set_generic_elem(hapd, (u8 *) "", 0);
116 ieee802_11_set_beacon(hapd);
117 hostapd_update_wps(hapd);
119 if (hapd->conf->ssid.ssid_set &&
120 hostapd_set_ssid(hapd, hapd->conf->ssid.ssid,
121 hapd->conf->ssid.ssid_len)) {
122 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
123 /* try to continue */
125 wpa_printf(MSG_DEBUG, "Reconfigured interface %s", hapd->conf->iface);
129 static void hostapd_clear_old(struct hostapd_iface *iface)
134 * Deauthenticate all stations since the new configuration may not
135 * allow them to use the BSS anymore.
137 for (j = 0; j < iface->num_bss; j++) {
138 hostapd_flush_old_stations(iface->bss[j],
139 WLAN_REASON_PREV_AUTH_NOT_VALID);
140 hostapd_broadcast_wep_clear(iface->bss[j]);
142 #ifndef CONFIG_NO_RADIUS
143 /* TODO: update dynamic data based on changed configuration
144 * items (e.g., open/close sockets, etc.) */
145 radius_client_flush(iface->bss[j]->radius, 0);
146 #endif /* CONFIG_NO_RADIUS */
151 int hostapd_reload_config(struct hostapd_iface *iface)
153 struct hostapd_data *hapd = iface->bss[0];
154 struct hostapd_config *newconf, *oldconf;
157 if (iface->config_fname == NULL) {
158 /* Only in-memory config in use - assume it has been updated */
159 hostapd_clear_old(iface);
160 for (j = 0; j < iface->num_bss; j++)
161 hostapd_reload_bss(iface->bss[j]);
165 if (iface->interfaces == NULL ||
166 iface->interfaces->config_read_cb == NULL)
168 newconf = iface->interfaces->config_read_cb(iface->config_fname);
172 hostapd_clear_old(iface);
174 oldconf = hapd->iconf;
175 iface->conf = newconf;
177 for (j = 0; j < iface->num_bss; j++) {
178 hapd = iface->bss[j];
179 hapd->iconf = newconf;
180 hapd->iconf->channel = oldconf->channel;
181 hapd->iconf->secondary_channel = oldconf->secondary_channel;
182 hapd->iconf->ieee80211n = oldconf->ieee80211n;
183 hapd->iconf->ieee80211ac = oldconf->ieee80211ac;
184 hapd->iconf->ht_capab = oldconf->ht_capab;
185 hapd->iconf->vht_capab = oldconf->vht_capab;
186 hapd->iconf->vht_oper_chwidth = oldconf->vht_oper_chwidth;
187 hapd->iconf->vht_oper_centr_freq_seg0_idx =
188 oldconf->vht_oper_centr_freq_seg0_idx;
189 hapd->iconf->vht_oper_centr_freq_seg1_idx =
190 oldconf->vht_oper_centr_freq_seg1_idx;
191 hapd->conf = newconf->bss[j];
192 hostapd_reload_bss(hapd);
195 hostapd_config_free(oldconf);
202 static void hostapd_broadcast_key_clear_iface(struct hostapd_data *hapd,
207 for (i = 0; i < NUM_WEP_KEYS; i++) {
208 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE, NULL, i,
209 0, NULL, 0, NULL, 0)) {
210 wpa_printf(MSG_DEBUG, "Failed to clear default "
211 "encryption keys (ifname=%s keyidx=%d)",
215 #ifdef CONFIG_IEEE80211W
216 if (hapd->conf->ieee80211w) {
217 for (i = NUM_WEP_KEYS; i < NUM_WEP_KEYS + 2; i++) {
218 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE,
221 wpa_printf(MSG_DEBUG, "Failed to clear "
222 "default mgmt encryption keys "
223 "(ifname=%s keyidx=%d)", ifname, i);
227 #endif /* CONFIG_IEEE80211W */
231 static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd)
233 hostapd_broadcast_key_clear_iface(hapd, hapd->conf->iface);
238 static int hostapd_broadcast_wep_set(struct hostapd_data *hapd)
241 struct hostapd_ssid *ssid = &hapd->conf->ssid;
244 if (ssid->wep.default_len &&
245 hostapd_drv_set_key(hapd->conf->iface,
246 hapd, WPA_ALG_WEP, broadcast_ether_addr, idx,
247 1, NULL, 0, ssid->wep.key[idx],
248 ssid->wep.len[idx])) {
249 wpa_printf(MSG_WARNING, "Could not set WEP encryption.");
257 static void hostapd_free_hapd_data(struct hostapd_data *hapd)
259 os_free(hapd->probereq_cb);
260 hapd->probereq_cb = NULL;
263 wpabuf_free(hapd->p2p_beacon_ie);
264 hapd->p2p_beacon_ie = NULL;
265 wpabuf_free(hapd->p2p_probe_resp_ie);
266 hapd->p2p_probe_resp_ie = NULL;
267 #endif /* CONFIG_P2P */
269 if (!hapd->started) {
270 wpa_printf(MSG_ERROR, "%s: Interface %s wasn't started",
271 __func__, hapd->conf->iface);
276 wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
277 iapp_deinit(hapd->iapp);
279 accounting_deinit(hapd);
280 hostapd_deinit_wpa(hapd);
282 hostapd_acl_deinit(hapd);
283 #ifndef CONFIG_NO_RADIUS
284 radius_client_deinit(hapd->radius);
286 radius_das_deinit(hapd->radius_das);
287 hapd->radius_das = NULL;
288 #endif /* CONFIG_NO_RADIUS */
290 hostapd_deinit_wps(hapd);
292 authsrv_deinit(hapd);
294 if (hapd->interface_added) {
295 hapd->interface_added = 0;
296 if (hostapd_if_remove(hapd, WPA_IF_AP_BSS, hapd->conf->iface)) {
297 wpa_printf(MSG_WARNING,
298 "Failed to remove BSS interface %s",
300 hapd->interface_added = 1;
303 * Since this was a dynamically added interface, the
304 * driver wrapper may have removed its internal instance
305 * and hapd->drv_priv is not valid anymore.
307 hapd->drv_priv = NULL;
311 wpabuf_free(hapd->time_adv);
313 #ifdef CONFIG_INTERWORKING
314 gas_serv_deinit(hapd);
315 #endif /* CONFIG_INTERWORKING */
317 bss_load_update_deinit(hapd);
318 ndisc_snoop_deinit(hapd);
319 dhcp_snoop_deinit(hapd);
320 x_snoop_deinit(hapd);
323 bin_clear_free(hapd->tmp_eap_user.identity,
324 hapd->tmp_eap_user.identity_len);
325 bin_clear_free(hapd->tmp_eap_user.password,
326 hapd->tmp_eap_user.password_len);
327 #endif /* CONFIG_SQLITE */
330 wpabuf_free(hapd->mesh_pending_auth);
331 hapd->mesh_pending_auth = NULL;
332 #endif /* CONFIG_MESH */
337 * hostapd_cleanup - Per-BSS cleanup (deinitialization)
338 * @hapd: Pointer to BSS data
340 * This function is used to free all per-BSS data structures and resources.
341 * Most of the modules that are initialized in hostapd_setup_bss() are
342 * deinitialized here.
344 static void hostapd_cleanup(struct hostapd_data *hapd)
346 wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s))", __func__, hapd,
348 if (hapd->iface->interfaces &&
349 hapd->iface->interfaces->ctrl_iface_deinit)
350 hapd->iface->interfaces->ctrl_iface_deinit(hapd);
351 hostapd_free_hapd_data(hapd);
355 static void hostapd_cleanup_iface_partial(struct hostapd_iface *iface)
357 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
358 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
359 iface->hw_features = NULL;
360 os_free(iface->current_rates);
361 iface->current_rates = NULL;
362 os_free(iface->basic_rates);
363 iface->basic_rates = NULL;
364 ap_list_deinit(iface);
369 * hostapd_cleanup_iface - Complete per-interface cleanup
370 * @iface: Pointer to interface data
372 * This function is called after per-BSS data structures are deinitialized
373 * with hostapd_cleanup().
375 static void hostapd_cleanup_iface(struct hostapd_iface *iface)
377 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
378 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
380 hostapd_cleanup_iface_partial(iface);
381 hostapd_config_free(iface->conf);
384 os_free(iface->config_fname);
386 wpa_printf(MSG_DEBUG, "%s: free iface=%p", __func__, iface);
391 static void hostapd_clear_wep(struct hostapd_data *hapd)
393 if (hapd->drv_priv && !hapd->iface->driver_ap_teardown) {
394 hostapd_set_privacy(hapd, 0);
395 hostapd_broadcast_wep_clear(hapd);
400 static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd)
404 hostapd_broadcast_wep_set(hapd);
406 if (hapd->conf->ssid.wep.default_len) {
407 hostapd_set_privacy(hapd, 1);
412 * When IEEE 802.1X is not enabled, the driver may need to know how to
413 * set authentication algorithms for static WEP.
415 hostapd_drv_set_authmode(hapd, hapd->conf->auth_algs);
417 for (i = 0; i < 4; i++) {
418 if (hapd->conf->ssid.wep.key[i] &&
419 hostapd_drv_set_key(iface, hapd, WPA_ALG_WEP, NULL, i,
420 i == hapd->conf->ssid.wep.idx, NULL, 0,
421 hapd->conf->ssid.wep.key[i],
422 hapd->conf->ssid.wep.len[i])) {
423 wpa_printf(MSG_WARNING, "Could not set WEP "
427 if (hapd->conf->ssid.wep.key[i] &&
428 i == hapd->conf->ssid.wep.idx)
429 hostapd_set_privacy(hapd, 1);
436 static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason)
441 if (hostapd_drv_none(hapd) || hapd->drv_priv == NULL)
444 if (!hapd->iface->driver_ap_teardown) {
445 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
446 "Flushing old station entries");
448 if (hostapd_flush(hapd)) {
449 wpa_msg(hapd->msg_ctx, MSG_WARNING,
450 "Could not connect to kernel driver");
454 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "Deauthenticate all stations");
455 os_memset(addr, 0xff, ETH_ALEN);
456 hostapd_drv_sta_deauth(hapd, addr, reason);
457 hostapd_free_stas(hapd);
463 static void hostapd_bss_deinit_no_free(struct hostapd_data *hapd)
465 hostapd_free_stas(hapd);
466 hostapd_flush_old_stations(hapd, WLAN_REASON_DEAUTH_LEAVING);
467 hostapd_clear_wep(hapd);
472 * hostapd_validate_bssid_configuration - Validate BSSID configuration
473 * @iface: Pointer to interface data
474 * Returns: 0 on success, -1 on failure
476 * This function is used to validate that the configured BSSIDs are valid.
478 static int hostapd_validate_bssid_configuration(struct hostapd_iface *iface)
480 u8 mask[ETH_ALEN] = { 0 };
481 struct hostapd_data *hapd = iface->bss[0];
482 unsigned int i = iface->conf->num_bss, bits = 0, j;
485 if (hostapd_drv_none(hapd))
488 /* Generate BSSID mask that is large enough to cover the BSSIDs. */
490 /* Determine the bits necessary to cover the number of BSSIDs. */
491 for (i--; i; i >>= 1)
494 /* Determine the bits necessary to any configured BSSIDs,
495 if they are higher than the number of BSSIDs. */
496 for (j = 0; j < iface->conf->num_bss; j++) {
497 if (hostapd_mac_comp_empty(iface->conf->bss[j]->bssid) == 0) {
503 for (i = 0; i < ETH_ALEN; i++) {
505 iface->conf->bss[j]->bssid[i] ^
513 for (i = 0; i < ETH_ALEN && mask[i] == 0; i++)
519 while (mask[i] != 0) {
529 wpa_printf(MSG_ERROR, "Too many bits in the BSSID mask (%u)",
534 os_memset(mask, 0xff, ETH_ALEN);
536 for (i = 5; i > 5 - j; i--)
543 wpa_printf(MSG_DEBUG, "BSS count %lu, BSSID mask " MACSTR " (%d bits)",
544 (unsigned long) iface->conf->num_bss, MAC2STR(mask), bits);
549 for (i = 0; i < ETH_ALEN; i++) {
550 if ((hapd->own_addr[i] & mask[i]) != hapd->own_addr[i]) {
551 wpa_printf(MSG_ERROR, "Invalid BSSID mask " MACSTR
552 " for start address " MACSTR ".",
553 MAC2STR(mask), MAC2STR(hapd->own_addr));
554 wpa_printf(MSG_ERROR, "Start address must be the "
555 "first address in the block (i.e., addr "
556 "AND mask == addr).");
565 static int mac_in_conf(struct hostapd_config *conf, const void *a)
569 for (i = 0; i < conf->num_bss; i++) {
570 if (hostapd_mac_comp(conf->bss[i]->bssid, a) == 0) {
579 #ifndef CONFIG_NO_RADIUS
581 static int hostapd_das_nas_mismatch(struct hostapd_data *hapd,
582 struct radius_das_attrs *attr)
584 if (attr->nas_identifier &&
585 (!hapd->conf->nas_identifier ||
586 os_strlen(hapd->conf->nas_identifier) !=
587 attr->nas_identifier_len ||
588 os_memcmp(hapd->conf->nas_identifier, attr->nas_identifier,
589 attr->nas_identifier_len) != 0)) {
590 wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-Identifier mismatch");
594 if (attr->nas_ip_addr &&
595 (hapd->conf->own_ip_addr.af != AF_INET ||
596 os_memcmp(&hapd->conf->own_ip_addr.u.v4, attr->nas_ip_addr, 4) !=
598 wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-IP-Address mismatch");
603 if (attr->nas_ipv6_addr &&
604 (hapd->conf->own_ip_addr.af != AF_INET6 ||
605 os_memcmp(&hapd->conf->own_ip_addr.u.v6, attr->nas_ipv6_addr, 16)
607 wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-IPv6-Address mismatch");
610 #endif /* CONFIG_IPV6 */
616 static struct sta_info * hostapd_das_find_sta(struct hostapd_data *hapd,
617 struct radius_das_attrs *attr)
619 struct sta_info *sta = NULL;
623 sta = ap_get_sta(hapd, attr->sta_addr);
625 if (sta == NULL && attr->acct_session_id &&
626 attr->acct_session_id_len == 17) {
627 for (sta = hapd->sta_list; sta; sta = sta->next) {
628 os_snprintf(buf, sizeof(buf), "%08X-%08X",
629 sta->acct_session_id_hi,
630 sta->acct_session_id_lo);
631 if (os_memcmp(attr->acct_session_id, buf, 17) == 0)
636 if (sta == NULL && attr->cui) {
637 for (sta = hapd->sta_list; sta; sta = sta->next) {
639 cui = ieee802_1x_get_radius_cui(sta->eapol_sm);
640 if (cui && wpabuf_len(cui) == attr->cui_len &&
641 os_memcmp(wpabuf_head(cui), attr->cui,
647 if (sta == NULL && attr->user_name) {
648 for (sta = hapd->sta_list; sta; sta = sta->next) {
651 identity = ieee802_1x_get_identity(sta->eapol_sm,
654 identity_len == attr->user_name_len &&
655 os_memcmp(identity, attr->user_name, identity_len)
665 static enum radius_das_res
666 hostapd_das_disconnect(void *ctx, struct radius_das_attrs *attr)
668 struct hostapd_data *hapd = ctx;
669 struct sta_info *sta;
671 if (hostapd_das_nas_mismatch(hapd, attr))
672 return RADIUS_DAS_NAS_MISMATCH;
674 sta = hostapd_das_find_sta(hapd, attr);
676 return RADIUS_DAS_SESSION_NOT_FOUND;
678 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
680 hostapd_drv_sta_deauth(hapd, sta->addr,
681 WLAN_REASON_PREV_AUTH_NOT_VALID);
682 ap_sta_deauthenticate(hapd, sta, WLAN_REASON_PREV_AUTH_NOT_VALID);
684 return RADIUS_DAS_SUCCESS;
687 #endif /* CONFIG_NO_RADIUS */
691 * hostapd_setup_bss - Per-BSS setup (initialization)
692 * @hapd: Pointer to BSS data
693 * @first: Whether this BSS is the first BSS of an interface; -1 = not first,
694 * but interface may exist
696 * This function is used to initialize all per-BSS data structures and
697 * resources. This gets called in a loop for each BSS when an interface is
698 * initialized. Most of the modules that are initialized here will be
699 * deinitialized in hostapd_cleanup().
701 static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
703 struct hostapd_bss_config *conf = hapd->conf;
704 u8 ssid[HOSTAPD_MAX_SSID_LEN + 1];
705 int ssid_len, set_ssid;
706 char force_ifname[IFNAMSIZ];
707 u8 if_addr[ETH_ALEN];
708 int flush_old_stations = 1;
710 wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s), first=%d)",
711 __func__, hapd, conf->iface, first);
713 #ifdef EAP_SERVER_TNC
714 if (conf->tnc && tncs_global_init() < 0) {
715 wpa_printf(MSG_ERROR, "Failed to initialize TNCS");
718 #endif /* EAP_SERVER_TNC */
721 wpa_printf(MSG_ERROR, "%s: Interface %s was already started",
722 __func__, conf->iface);
727 if (!first || first == -1) {
728 if (hostapd_mac_comp_empty(conf->bssid) == 0) {
729 /* Allocate the next available BSSID. */
731 inc_byte_array(hapd->own_addr, ETH_ALEN);
732 } while (mac_in_conf(hapd->iconf, hapd->own_addr));
734 /* Allocate the configured BSSID. */
735 os_memcpy(hapd->own_addr, conf->bssid, ETH_ALEN);
737 if (hostapd_mac_comp(hapd->own_addr,
738 hapd->iface->bss[0]->own_addr) ==
740 wpa_printf(MSG_ERROR, "BSS '%s' may not have "
741 "BSSID set to the MAC address of "
742 "the radio", conf->iface);
747 hapd->interface_added = 1;
748 if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS,
749 conf->iface, hapd->own_addr, hapd,
750 &hapd->drv_priv, force_ifname, if_addr,
751 conf->bridge[0] ? conf->bridge : NULL,
753 wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
754 MACSTR ")", MAC2STR(hapd->own_addr));
755 hapd->interface_added = 0;
760 if (conf->wmm_enabled < 0)
761 conf->wmm_enabled = hapd->iconf->ieee80211n;
764 if (hapd->iface->mconf == NULL)
765 flush_old_stations = 0;
766 #endif /* CONFIG_MESH */
768 if (flush_old_stations)
769 hostapd_flush_old_stations(hapd,
770 WLAN_REASON_PREV_AUTH_NOT_VALID);
771 hostapd_set_privacy(hapd, 0);
773 hostapd_broadcast_wep_clear(hapd);
774 if (hostapd_setup_encryption(conf->iface, hapd))
778 * Fetch the SSID from the system and use it or,
779 * if one was specified in the config file, verify they
782 ssid_len = hostapd_get_ssid(hapd, ssid, sizeof(ssid));
784 wpa_printf(MSG_ERROR, "Could not read SSID from system");
787 if (conf->ssid.ssid_set) {
789 * If SSID is specified in the config file and it differs
790 * from what is being used then force installation of the
793 set_ssid = (conf->ssid.ssid_len != (size_t) ssid_len ||
794 os_memcmp(conf->ssid.ssid, ssid, ssid_len) != 0);
797 * No SSID in the config file; just use the one we got
801 conf->ssid.ssid_len = ssid_len;
802 os_memcpy(conf->ssid.ssid, ssid, conf->ssid.ssid_len);
805 if (!hostapd_drv_none(hapd)) {
806 wpa_printf(MSG_ERROR, "Using interface %s with hwaddr " MACSTR
808 conf->iface, MAC2STR(hapd->own_addr),
809 wpa_ssid_txt(conf->ssid.ssid, conf->ssid.ssid_len));
812 if (hostapd_setup_wpa_psk(conf)) {
813 wpa_printf(MSG_ERROR, "WPA-PSK setup failed.");
817 /* Set SSID for the kernel driver (to be used in beacon and probe
818 * response frames) */
819 if (set_ssid && hostapd_set_ssid(hapd, conf->ssid.ssid,
820 conf->ssid.ssid_len)) {
821 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
825 if (wpa_debug_level <= MSG_MSGDUMP)
826 conf->radius->msg_dumps = 1;
827 #ifndef CONFIG_NO_RADIUS
828 hapd->radius = radius_client_init(hapd, conf->radius);
829 if (hapd->radius == NULL) {
830 wpa_printf(MSG_ERROR, "RADIUS client initialization failed.");
834 if (conf->radius_das_port) {
835 struct radius_das_conf das_conf;
836 os_memset(&das_conf, 0, sizeof(das_conf));
837 das_conf.port = conf->radius_das_port;
838 das_conf.shared_secret = conf->radius_das_shared_secret;
839 das_conf.shared_secret_len =
840 conf->radius_das_shared_secret_len;
841 das_conf.client_addr = &conf->radius_das_client_addr;
842 das_conf.time_window = conf->radius_das_time_window;
843 das_conf.require_event_timestamp =
844 conf->radius_das_require_event_timestamp;
846 das_conf.disconnect = hostapd_das_disconnect;
847 hapd->radius_das = radius_das_init(&das_conf);
848 if (hapd->radius_das == NULL) {
849 wpa_printf(MSG_ERROR, "RADIUS DAS initialization "
854 #endif /* CONFIG_NO_RADIUS */
856 if (hostapd_acl_init(hapd)) {
857 wpa_printf(MSG_ERROR, "ACL initialization failed.");
860 if (hostapd_init_wps(hapd, conf))
863 if (authsrv_init(hapd) < 0)
866 if (ieee802_1x_init(hapd)) {
867 wpa_printf(MSG_ERROR, "IEEE 802.1X initialization failed.");
871 if ((conf->wpa || conf->osen) && hostapd_setup_wpa(hapd))
874 if (accounting_init(hapd)) {
875 wpa_printf(MSG_ERROR, "Accounting initialization failed.");
879 if (conf->ieee802_11f &&
880 (hapd->iapp = iapp_init(hapd, conf->iapp_iface)) == NULL) {
881 wpa_printf(MSG_ERROR, "IEEE 802.11F (IAPP) initialization "
886 #ifdef CONFIG_INTERWORKING
887 if (gas_serv_init(hapd)) {
888 wpa_printf(MSG_ERROR, "GAS server initialization failed");
892 if (conf->qos_map_set_len &&
893 hostapd_drv_set_qos_map(hapd, conf->qos_map_set,
894 conf->qos_map_set_len)) {
895 wpa_printf(MSG_ERROR, "Failed to initialize QoS Map");
898 #endif /* CONFIG_INTERWORKING */
900 if (conf->bss_load_update_period && bss_load_update_init(hapd)) {
901 wpa_printf(MSG_ERROR, "BSS Load initialization failed");
905 if (conf->proxy_arp) {
906 if (x_snoop_init(hapd)) {
907 wpa_printf(MSG_ERROR,
908 "Generic snooping infrastructure initialization failed");
912 if (dhcp_snoop_init(hapd)) {
913 wpa_printf(MSG_ERROR,
914 "DHCP snooping initialization failed");
918 if (ndisc_snoop_init(hapd)) {
919 wpa_printf(MSG_ERROR,
920 "Neighbor Discovery snooping initialization failed");
925 if (!hostapd_drv_none(hapd) && vlan_init(hapd)) {
926 wpa_printf(MSG_ERROR, "VLAN initialization failed.");
930 if (!conf->start_disabled && ieee802_11_set_beacon(hapd) < 0)
933 if (hapd->wpa_auth && wpa_init_keys(hapd->wpa_auth) < 0)
936 if (hapd->driver && hapd->driver->set_operstate)
937 hapd->driver->set_operstate(hapd->drv_priv, 1);
943 static void hostapd_tx_queue_params(struct hostapd_iface *iface)
945 struct hostapd_data *hapd = iface->bss[0];
947 struct hostapd_tx_queue_params *p;
950 if (iface->mconf == NULL)
952 #endif /* CONFIG_MESH */
954 for (i = 0; i < NUM_TX_QUEUES; i++) {
955 p = &iface->conf->tx_queue[i];
957 if (hostapd_set_tx_queue_params(hapd, i, p->aifs, p->cwmin,
958 p->cwmax, p->burst)) {
959 wpa_printf(MSG_DEBUG, "Failed to set TX queue "
960 "parameters for queue %d.", i);
961 /* Continue anyway */
967 static int hostapd_set_acl_list(struct hostapd_data *hapd,
968 struct mac_acl_entry *mac_acl,
969 int n_entries, u8 accept_acl)
971 struct hostapd_acl_params *acl_params;
974 acl_params = os_zalloc(sizeof(*acl_params) +
975 (n_entries * sizeof(acl_params->mac_acl[0])));
979 for (i = 0; i < n_entries; i++)
980 os_memcpy(acl_params->mac_acl[i].addr, mac_acl[i].addr,
983 acl_params->acl_policy = accept_acl;
984 acl_params->num_mac_acl = n_entries;
986 err = hostapd_drv_set_acl(hapd, acl_params);
994 static void hostapd_set_acl(struct hostapd_data *hapd)
996 struct hostapd_config *conf = hapd->iconf;
1000 if (hapd->iface->drv_max_acl_mac_addrs == 0)
1003 if (conf->bss[0]->macaddr_acl == DENY_UNLESS_ACCEPTED) {
1005 err = hostapd_set_acl_list(hapd, conf->bss[0]->accept_mac,
1006 conf->bss[0]->num_accept_mac,
1009 wpa_printf(MSG_DEBUG, "Failed to set accept acl");
1012 } else if (conf->bss[0]->macaddr_acl == ACCEPT_UNLESS_DENIED) {
1014 err = hostapd_set_acl_list(hapd, conf->bss[0]->deny_mac,
1015 conf->bss[0]->num_deny_mac,
1018 wpa_printf(MSG_DEBUG, "Failed to set deny acl");
1025 static int start_ctrl_iface_bss(struct hostapd_data *hapd)
1027 if (!hapd->iface->interfaces ||
1028 !hapd->iface->interfaces->ctrl_iface_init)
1031 if (hapd->iface->interfaces->ctrl_iface_init(hapd)) {
1032 wpa_printf(MSG_ERROR,
1033 "Failed to setup control interface for %s",
1042 static int start_ctrl_iface(struct hostapd_iface *iface)
1046 if (!iface->interfaces || !iface->interfaces->ctrl_iface_init)
1049 for (i = 0; i < iface->num_bss; i++) {
1050 struct hostapd_data *hapd = iface->bss[i];
1051 if (iface->interfaces->ctrl_iface_init(hapd)) {
1052 wpa_printf(MSG_ERROR,
1053 "Failed to setup control interface for %s",
1063 static void channel_list_update_timeout(void *eloop_ctx, void *timeout_ctx)
1065 struct hostapd_iface *iface = eloop_ctx;
1067 if (!iface->wait_channel_update) {
1068 wpa_printf(MSG_INFO, "Channel list update timeout, but interface was not waiting for it");
1073 * It is possible that the existing channel list is acceptable, so try
1076 wpa_printf(MSG_DEBUG, "Channel list update timeout - try to continue anyway");
1077 setup_interface2(iface);
1081 void hostapd_channel_list_updated(struct hostapd_iface *iface, int initiator)
1083 if (!iface->wait_channel_update || initiator != REGDOM_SET_BY_USER)
1086 wpa_printf(MSG_DEBUG, "Channel list updated - continue setup");
1087 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
1088 setup_interface2(iface);
1092 static int setup_interface(struct hostapd_iface *iface)
1094 struct hostapd_data *hapd = iface->bss[0];
1098 * It is possible that setup_interface() is called after the interface
1099 * was disabled etc., in which case driver_ap_teardown is possibly set
1100 * to 1. Clear it here so any other key/station deletion, which is not
1101 * part of a teardown flow, would also call the relevant driver
1104 iface->driver_ap_teardown = 0;
1106 if (!iface->phy[0]) {
1107 const char *phy = hostapd_drv_get_radio_name(hapd);
1109 wpa_printf(MSG_DEBUG, "phy: %s", phy);
1110 os_strlcpy(iface->phy, phy, sizeof(iface->phy));
1115 * Make sure that all BSSes get configured with a pointer to the same
1118 for (i = 1; i < iface->num_bss; i++) {
1119 iface->bss[i]->driver = hapd->driver;
1120 iface->bss[i]->drv_priv = hapd->drv_priv;
1123 if (hostapd_validate_bssid_configuration(iface))
1127 * Initialize control interfaces early to allow external monitoring of
1128 * channel setup operations that may take considerable amount of time
1129 * especially for DFS cases.
1131 if (start_ctrl_iface(iface))
1134 if (hapd->iconf->country[0] && hapd->iconf->country[1]) {
1135 char country[4], previous_country[4];
1137 hostapd_set_state(iface, HAPD_IFACE_COUNTRY_UPDATE);
1138 if (hostapd_get_country(hapd, previous_country) < 0)
1139 previous_country[0] = '\0';
1141 os_memcpy(country, hapd->iconf->country, 3);
1143 if (hostapd_set_country(hapd, country) < 0) {
1144 wpa_printf(MSG_ERROR, "Failed to set country code");
1148 wpa_printf(MSG_DEBUG, "Previous country code %s, new country code %s",
1149 previous_country, country);
1151 if (os_strncmp(previous_country, country, 2) != 0) {
1152 wpa_printf(MSG_DEBUG, "Continue interface setup after channel list update");
1153 iface->wait_channel_update = 1;
1154 eloop_register_timeout(5, 0,
1155 channel_list_update_timeout,
1161 return setup_interface2(iface);
1165 static int setup_interface2(struct hostapd_iface *iface)
1167 iface->wait_channel_update = 0;
1169 if (hostapd_get_hw_features(iface)) {
1170 /* Not all drivers support this yet, so continue without hw
1173 int ret = hostapd_select_hw_mode(iface);
1175 wpa_printf(MSG_ERROR, "Could not select hw_mode and "
1176 "channel. (%d)", ret);
1180 wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback (ACS)");
1183 ret = hostapd_check_ht_capab(iface);
1187 wpa_printf(MSG_DEBUG, "Interface initialization will "
1188 "be completed in a callback");
1192 if (iface->conf->ieee80211h)
1193 wpa_printf(MSG_DEBUG, "DFS support is enabled");
1195 return hostapd_setup_interface_complete(iface, 0);
1198 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
1199 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
1200 if (iface->interfaces && iface->interfaces->terminate_on_error)
1207 * hostapd_setup_interface_complete - Complete interface setup
1209 * This function is called when previous steps in the interface setup has been
1210 * completed. This can also start operations, e.g., DFS, that will require
1211 * additional processing before interface is ready to be enabled. Such
1212 * operations will call this function from eloop callbacks when finished.
1214 int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err)
1216 struct hostapd_data *hapd = iface->bss[0];
1219 int delay_apply_cfg = 0;
1224 wpa_printf(MSG_DEBUG, "Completing interface initialization");
1225 if (iface->conf->channel) {
1228 #endif /* NEED_AP_MLME */
1230 iface->freq = hostapd_hw_get_freq(hapd, iface->conf->channel);
1231 wpa_printf(MSG_DEBUG, "Mode: %s Channel: %d "
1232 "Frequency: %d MHz",
1233 hostapd_hw_mode_txt(iface->conf->hw_mode),
1234 iface->conf->channel, iface->freq);
1237 /* Handle DFS only if it is not offloaded to the driver */
1238 if (!(iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)) {
1240 res = hostapd_handle_dfs(iface);
1247 #endif /* NEED_AP_MLME */
1250 if (iface->mconf != NULL) {
1251 wpa_printf(MSG_DEBUG,
1252 "%s: Mesh configuration will be applied while joining the mesh network",
1253 iface->bss[0]->conf->iface);
1254 delay_apply_cfg = 1;
1256 #endif /* CONFIG_MESH */
1258 if (!delay_apply_cfg &&
1259 hostapd_set_freq(hapd, hapd->iconf->hw_mode, iface->freq,
1260 hapd->iconf->channel,
1261 hapd->iconf->ieee80211n,
1262 hapd->iconf->ieee80211ac,
1263 hapd->iconf->secondary_channel,
1264 hapd->iconf->vht_oper_chwidth,
1265 hapd->iconf->vht_oper_centr_freq_seg0_idx,
1266 hapd->iconf->vht_oper_centr_freq_seg1_idx)) {
1267 wpa_printf(MSG_ERROR, "Could not set channel for "
1273 if (iface->current_mode) {
1274 if (hostapd_prepare_rates(iface, iface->current_mode)) {
1275 wpa_printf(MSG_ERROR, "Failed to prepare rates "
1277 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1278 HOSTAPD_LEVEL_WARNING,
1279 "Failed to prepare rates table.");
1284 if (hapd->iconf->rts_threshold > -1 &&
1285 hostapd_set_rts(hapd, hapd->iconf->rts_threshold)) {
1286 wpa_printf(MSG_ERROR, "Could not set RTS threshold for "
1291 if (hapd->iconf->fragm_threshold > -1 &&
1292 hostapd_set_frag(hapd, hapd->iconf->fragm_threshold)) {
1293 wpa_printf(MSG_ERROR, "Could not set fragmentation threshold "
1294 "for kernel driver");
1298 prev_addr = hapd->own_addr;
1300 for (j = 0; j < iface->num_bss; j++) {
1301 hapd = iface->bss[j];
1303 os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN);
1304 if (hostapd_setup_bss(hapd, j == 0)) {
1306 hapd = iface->bss[j];
1307 hostapd_bss_deinit_no_free(hapd);
1308 hostapd_free_hapd_data(hapd);
1312 if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0)
1313 prev_addr = hapd->own_addr;
1315 hapd = iface->bss[0];
1317 hostapd_tx_queue_params(iface);
1319 ap_list_init(iface);
1321 hostapd_set_acl(hapd);
1323 if (hostapd_driver_commit(hapd) < 0) {
1324 wpa_printf(MSG_ERROR, "%s: Failed to commit driver "
1325 "configuration", __func__);
1330 * WPS UPnP module can be initialized only when the "upnp_iface" is up.
1331 * If "interface" and "upnp_iface" are the same (e.g., non-bridge
1332 * mode), the interface is up only after driver_commit, so initialize
1333 * WPS after driver_commit.
1335 for (j = 0; j < iface->num_bss; j++) {
1336 if (hostapd_init_wps_complete(iface->bss[j]))
1340 hostapd_set_state(iface, HAPD_IFACE_ENABLED);
1341 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_ENABLED);
1342 if (hapd->setup_complete_cb)
1343 hapd->setup_complete_cb(hapd->setup_complete_cb_ctx);
1345 wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
1346 iface->bss[0]->conf->iface);
1347 if (iface->interfaces && iface->interfaces->terminate_on_error > 0)
1348 iface->interfaces->terminate_on_error--;
1353 wpa_printf(MSG_ERROR, "Interface initialization failed");
1354 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
1355 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
1356 if (iface->interfaces && iface->interfaces->terminate_on_error)
1363 * hostapd_setup_interface - Setup of an interface
1364 * @iface: Pointer to interface data.
1365 * Returns: 0 on success, -1 on failure
1367 * Initializes the driver interface, validates the configuration,
1368 * and sets driver parameters based on the configuration.
1369 * Flushes old stations, sets the channel, encryption,
1370 * beacons, and WDS links based on the configuration.
1372 * If interface setup requires more time, e.g., to perform HT co-ex scans, ACS,
1373 * or DFS operations, this function returns 0 before such operations have been
1374 * completed. The pending operations are registered into eloop and will be
1375 * completed from eloop callbacks. Those callbacks end up calling
1376 * hostapd_setup_interface_complete() once setup has been completed.
1378 int hostapd_setup_interface(struct hostapd_iface *iface)
1382 ret = setup_interface(iface);
1384 wpa_printf(MSG_ERROR, "%s: Unable to setup interface.",
1385 iface->bss[0]->conf->iface);
1394 * hostapd_alloc_bss_data - Allocate and initialize per-BSS data
1395 * @hapd_iface: Pointer to interface data
1396 * @conf: Pointer to per-interface configuration
1397 * @bss: Pointer to per-BSS configuration for this BSS
1398 * Returns: Pointer to allocated BSS data
1400 * This function is used to allocate per-BSS data structure. This data will be
1401 * freed after hostapd_cleanup() is called for it during interface
1404 struct hostapd_data *
1405 hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
1406 struct hostapd_config *conf,
1407 struct hostapd_bss_config *bss)
1409 struct hostapd_data *hapd;
1411 hapd = os_zalloc(sizeof(*hapd));
1415 hapd->new_assoc_sta_cb = hostapd_new_assoc_sta;
1418 hapd->iface = hapd_iface;
1419 hapd->driver = hapd->iconf->driver;
1420 hapd->ctrl_sock = -1;
1426 static void hostapd_bss_deinit(struct hostapd_data *hapd)
1428 wpa_printf(MSG_DEBUG, "%s: deinit bss %s", __func__,
1430 hostapd_bss_deinit_no_free(hapd);
1431 hostapd_cleanup(hapd);
1435 void hostapd_interface_deinit(struct hostapd_iface *iface)
1439 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
1443 #ifdef CONFIG_IEEE80211N
1445 hostapd_stop_setup_timers(iface);
1446 eloop_cancel_timeout(ap_ht2040_timeout, iface, NULL);
1447 #endif /* NEED_AP_MLME */
1448 #endif /* CONFIG_IEEE80211N */
1449 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
1450 iface->wait_channel_update = 0;
1452 for (j = iface->num_bss - 1; j >= 0; j--)
1453 hostapd_bss_deinit(iface->bss[j]);
1457 void hostapd_interface_free(struct hostapd_iface *iface)
1460 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
1461 for (j = 0; j < iface->num_bss; j++) {
1462 wpa_printf(MSG_DEBUG, "%s: free hapd %p",
1463 __func__, iface->bss[j]);
1464 os_free(iface->bss[j]);
1466 hostapd_cleanup_iface(iface);
1471 * hostapd_init - Allocate and initialize per-interface data
1472 * @config_file: Path to the configuration file
1473 * Returns: Pointer to the allocated interface data or %NULL on failure
1475 * This function is used to allocate main data structures for per-interface
1476 * data. The allocated data buffer will be freed by calling
1477 * hostapd_cleanup_iface().
1479 struct hostapd_iface * hostapd_init(struct hapd_interfaces *interfaces,
1480 const char *config_file)
1482 struct hostapd_iface *hapd_iface = NULL;
1483 struct hostapd_config *conf = NULL;
1484 struct hostapd_data *hapd;
1487 hapd_iface = os_zalloc(sizeof(*hapd_iface));
1488 if (hapd_iface == NULL)
1491 hapd_iface->config_fname = os_strdup(config_file);
1492 if (hapd_iface->config_fname == NULL)
1495 conf = interfaces->config_read_cb(hapd_iface->config_fname);
1498 hapd_iface->conf = conf;
1500 hapd_iface->num_bss = conf->num_bss;
1501 hapd_iface->bss = os_calloc(conf->num_bss,
1502 sizeof(struct hostapd_data *));
1503 if (hapd_iface->bss == NULL)
1506 for (i = 0; i < conf->num_bss; i++) {
1507 hapd = hapd_iface->bss[i] =
1508 hostapd_alloc_bss_data(hapd_iface, conf,
1512 hapd->msg_ctx = hapd;
1518 wpa_printf(MSG_ERROR, "Failed to set up interface with %s",
1521 hostapd_config_free(conf);
1523 os_free(hapd_iface->config_fname);
1524 os_free(hapd_iface->bss);
1525 wpa_printf(MSG_DEBUG, "%s: free iface %p",
1526 __func__, hapd_iface);
1527 os_free(hapd_iface);
1533 static int ifname_in_use(struct hapd_interfaces *interfaces, const char *ifname)
1537 for (i = 0; i < interfaces->count; i++) {
1538 struct hostapd_iface *iface = interfaces->iface[i];
1539 for (j = 0; j < iface->num_bss; j++) {
1540 struct hostapd_data *hapd = iface->bss[j];
1541 if (os_strcmp(ifname, hapd->conf->iface) == 0)
1551 * hostapd_interface_init_bss - Read configuration file and init BSS data
1553 * This function is used to parse configuration file for a BSS. This BSS is
1554 * added to an existing interface sharing the same radio (if any) or a new
1555 * interface is created if this is the first interface on a radio. This
1556 * allocate memory for the BSS. No actual driver operations are started.
1558 * This is similar to hostapd_interface_init(), but for a case where the
1559 * configuration is used to add a single BSS instead of all BSSes for a radio.
1561 struct hostapd_iface *
1562 hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy,
1563 const char *config_fname, int debug)
1565 struct hostapd_iface *new_iface = NULL, *iface = NULL;
1566 struct hostapd_data *hapd;
1573 for (i = 0; i < interfaces->count; i++) {
1574 if (os_strcmp(interfaces->iface[i]->phy, phy) == 0) {
1575 iface = interfaces->iface[i];
1580 wpa_printf(MSG_INFO, "Configuration file: %s (phy %s)%s",
1581 config_fname, phy, iface ? "" : " --> new PHY");
1583 struct hostapd_config *conf;
1584 struct hostapd_bss_config **tmp_conf;
1585 struct hostapd_data **tmp_bss;
1586 struct hostapd_bss_config *bss;
1589 /* Add new BSS to existing iface */
1590 conf = interfaces->config_read_cb(config_fname);
1593 if (conf->num_bss > 1) {
1594 wpa_printf(MSG_ERROR, "Multiple BSSes specified in BSS-config");
1595 hostapd_config_free(conf);
1599 ifname = conf->bss[0]->iface;
1600 if (ifname[0] != '\0' && ifname_in_use(interfaces, ifname)) {
1601 wpa_printf(MSG_ERROR,
1602 "Interface name %s already in use", ifname);
1603 hostapd_config_free(conf);
1607 tmp_conf = os_realloc_array(
1608 iface->conf->bss, iface->conf->num_bss + 1,
1609 sizeof(struct hostapd_bss_config *));
1610 tmp_bss = os_realloc_array(iface->bss, iface->num_bss + 1,
1611 sizeof(struct hostapd_data *));
1613 iface->bss = tmp_bss;
1615 iface->conf->bss = tmp_conf;
1616 iface->conf->last_bss = tmp_conf[0];
1618 if (tmp_bss == NULL || tmp_conf == NULL) {
1619 hostapd_config_free(conf);
1622 bss = iface->conf->bss[iface->conf->num_bss] = conf->bss[0];
1623 iface->conf->num_bss++;
1625 hapd = hostapd_alloc_bss_data(iface, iface->conf, bss);
1627 iface->conf->num_bss--;
1628 hostapd_config_free(conf);
1631 iface->conf->last_bss = bss;
1632 iface->bss[iface->num_bss] = hapd;
1633 hapd->msg_ctx = hapd;
1635 bss_idx = iface->num_bss++;
1637 conf->bss[0] = NULL;
1638 hostapd_config_free(conf);
1640 /* Add a new iface with the first BSS */
1641 new_iface = iface = hostapd_init(interfaces, config_fname);
1644 os_strlcpy(iface->phy, phy, sizeof(iface->phy));
1645 iface->interfaces = interfaces;
1649 for (k = 0; k < debug; k++) {
1650 if (iface->bss[bss_idx]->conf->logger_stdout_level > 0)
1651 iface->bss[bss_idx]->conf->logger_stdout_level--;
1654 if (iface->conf->bss[bss_idx]->iface[0] == '\0' &&
1655 !hostapd_drv_none(iface->bss[bss_idx])) {
1656 wpa_printf(MSG_ERROR, "Interface name not specified in %s",
1659 hostapd_interface_deinit_free(new_iface);
1667 void hostapd_interface_deinit_free(struct hostapd_iface *iface)
1669 const struct wpa_driver_ops *driver;
1672 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
1675 wpa_printf(MSG_DEBUG, "%s: num_bss=%u conf->num_bss=%u",
1676 __func__, (unsigned int) iface->num_bss,
1677 (unsigned int) iface->conf->num_bss);
1678 driver = iface->bss[0]->driver;
1679 drv_priv = iface->bss[0]->drv_priv;
1680 hostapd_interface_deinit(iface);
1681 wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
1682 __func__, driver, drv_priv);
1683 if (driver && driver->hapd_deinit && drv_priv) {
1684 driver->hapd_deinit(drv_priv);
1685 iface->bss[0]->drv_priv = NULL;
1687 hostapd_interface_free(iface);
1691 static void hostapd_deinit_driver(const struct wpa_driver_ops *driver,
1693 struct hostapd_iface *hapd_iface)
1697 wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
1698 __func__, driver, drv_priv);
1699 if (driver && driver->hapd_deinit && drv_priv) {
1700 driver->hapd_deinit(drv_priv);
1701 for (j = 0; j < hapd_iface->num_bss; j++) {
1702 wpa_printf(MSG_DEBUG, "%s:bss[%d]->drv_priv=%p",
1704 hapd_iface->bss[j]->drv_priv);
1705 if (hapd_iface->bss[j]->drv_priv == drv_priv)
1706 hapd_iface->bss[j]->drv_priv = NULL;
1712 int hostapd_enable_iface(struct hostapd_iface *hapd_iface)
1716 if (hapd_iface->bss[0]->drv_priv != NULL) {
1717 wpa_printf(MSG_ERROR, "Interface %s already enabled",
1718 hapd_iface->conf->bss[0]->iface);
1722 wpa_printf(MSG_DEBUG, "Enable interface %s",
1723 hapd_iface->conf->bss[0]->iface);
1725 for (j = 0; j < hapd_iface->num_bss; j++)
1726 hostapd_set_security_params(hapd_iface->conf->bss[j], 1);
1727 if (hostapd_config_check(hapd_iface->conf, 1) < 0) {
1728 wpa_printf(MSG_INFO, "Invalid configuration - cannot enable");
1732 if (hapd_iface->interfaces == NULL ||
1733 hapd_iface->interfaces->driver_init == NULL ||
1734 hapd_iface->interfaces->driver_init(hapd_iface))
1737 if (hostapd_setup_interface(hapd_iface)) {
1738 hostapd_deinit_driver(hapd_iface->bss[0]->driver,
1739 hapd_iface->bss[0]->drv_priv,
1748 int hostapd_reload_iface(struct hostapd_iface *hapd_iface)
1752 wpa_printf(MSG_DEBUG, "Reload interface %s",
1753 hapd_iface->conf->bss[0]->iface);
1754 for (j = 0; j < hapd_iface->num_bss; j++)
1755 hostapd_set_security_params(hapd_iface->conf->bss[j], 1);
1756 if (hostapd_config_check(hapd_iface->conf, 1) < 0) {
1757 wpa_printf(MSG_ERROR, "Updated configuration is invalid");
1760 hostapd_clear_old(hapd_iface);
1761 for (j = 0; j < hapd_iface->num_bss; j++)
1762 hostapd_reload_bss(hapd_iface->bss[j]);
1768 int hostapd_disable_iface(struct hostapd_iface *hapd_iface)
1771 const struct wpa_driver_ops *driver;
1774 if (hapd_iface == NULL)
1777 if (hapd_iface->bss[0]->drv_priv == NULL) {
1778 wpa_printf(MSG_INFO, "Interface %s already disabled",
1779 hapd_iface->conf->bss[0]->iface);
1783 wpa_msg(hapd_iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
1784 driver = hapd_iface->bss[0]->driver;
1785 drv_priv = hapd_iface->bss[0]->drv_priv;
1787 hapd_iface->driver_ap_teardown =
1788 !!(hapd_iface->drv_flags &
1789 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
1791 /* same as hostapd_interface_deinit without deinitializing ctrl-iface */
1792 for (j = 0; j < hapd_iface->num_bss; j++) {
1793 struct hostapd_data *hapd = hapd_iface->bss[j];
1794 hostapd_bss_deinit_no_free(hapd);
1795 hostapd_free_hapd_data(hapd);
1798 hostapd_deinit_driver(driver, drv_priv, hapd_iface);
1800 /* From hostapd_cleanup_iface: These were initialized in
1801 * hostapd_setup_interface and hostapd_setup_interface_complete
1803 hostapd_cleanup_iface_partial(hapd_iface);
1805 wpa_printf(MSG_DEBUG, "Interface %s disabled",
1806 hapd_iface->bss[0]->conf->iface);
1807 hostapd_set_state(hapd_iface, HAPD_IFACE_DISABLED);
1812 static struct hostapd_iface *
1813 hostapd_iface_alloc(struct hapd_interfaces *interfaces)
1815 struct hostapd_iface **iface, *hapd_iface;
1817 iface = os_realloc_array(interfaces->iface, interfaces->count + 1,
1818 sizeof(struct hostapd_iface *));
1821 interfaces->iface = iface;
1822 hapd_iface = interfaces->iface[interfaces->count] =
1823 os_zalloc(sizeof(*hapd_iface));
1824 if (hapd_iface == NULL) {
1825 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for "
1826 "the interface", __func__);
1829 interfaces->count++;
1830 hapd_iface->interfaces = interfaces;
1836 static struct hostapd_config *
1837 hostapd_config_alloc(struct hapd_interfaces *interfaces, const char *ifname,
1838 const char *ctrl_iface)
1840 struct hostapd_bss_config *bss;
1841 struct hostapd_config *conf;
1843 /* Allocates memory for bss and conf */
1844 conf = hostapd_config_defaults();
1846 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for "
1847 "configuration", __func__);
1851 conf->driver = wpa_drivers[0];
1852 if (conf->driver == NULL) {
1853 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
1854 hostapd_config_free(conf);
1858 bss = conf->last_bss = conf->bss[0];
1860 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
1861 bss->ctrl_interface = os_strdup(ctrl_iface);
1862 if (bss->ctrl_interface == NULL) {
1863 hostapd_config_free(conf);
1867 /* Reading configuration file skipped, will be done in SET!
1868 * From reading the configuration till the end has to be done in
1875 static struct hostapd_iface * hostapd_data_alloc(
1876 struct hapd_interfaces *interfaces, struct hostapd_config *conf)
1879 struct hostapd_iface *hapd_iface =
1880 interfaces->iface[interfaces->count - 1];
1881 struct hostapd_data *hapd;
1883 hapd_iface->conf = conf;
1884 hapd_iface->num_bss = conf->num_bss;
1886 hapd_iface->bss = os_calloc(conf->num_bss,
1887 sizeof(struct hostapd_data *));
1888 if (hapd_iface->bss == NULL)
1891 for (i = 0; i < conf->num_bss; i++) {
1892 hapd = hapd_iface->bss[i] =
1893 hostapd_alloc_bss_data(hapd_iface, conf, conf->bss[i]);
1896 hapd->msg_ctx = hapd;
1899 hapd_iface->interfaces = interfaces;
1905 int hostapd_add_iface(struct hapd_interfaces *interfaces, char *buf)
1907 struct hostapd_config *conf = NULL;
1908 struct hostapd_iface *hapd_iface = NULL, *new_iface = NULL;
1909 struct hostapd_data *hapd;
1912 const char *conf_file = NULL, *phy_name = NULL;
1914 if (os_strncmp(buf, "bss_config=", 11) == 0) {
1916 phy_name = buf + 11;
1917 pos = os_strchr(phy_name, ':');
1922 if (!os_strlen(conf_file))
1925 hapd_iface = hostapd_interface_init_bss(interfaces, phy_name,
1929 for (j = 0; j < interfaces->count; j++) {
1930 if (interfaces->iface[j] == hapd_iface)
1933 if (j == interfaces->count) {
1934 struct hostapd_iface **tmp;
1935 tmp = os_realloc_array(interfaces->iface,
1936 interfaces->count + 1,
1937 sizeof(struct hostapd_iface *));
1939 hostapd_interface_deinit_free(hapd_iface);
1942 interfaces->iface = tmp;
1943 interfaces->iface[interfaces->count++] = hapd_iface;
1944 new_iface = hapd_iface;
1948 if (interfaces->driver_init(hapd_iface)) {
1949 interfaces->count--;
1953 if (hostapd_setup_interface(hapd_iface)) {
1954 interfaces->count--;
1955 hostapd_deinit_driver(
1956 hapd_iface->bss[0]->driver,
1957 hapd_iface->bss[0]->drv_priv,
1962 /* Assign new BSS with bss[0]'s driver info */
1963 hapd = hapd_iface->bss[hapd_iface->num_bss - 1];
1964 hapd->driver = hapd_iface->bss[0]->driver;
1965 hapd->drv_priv = hapd_iface->bss[0]->drv_priv;
1966 os_memcpy(hapd->own_addr, hapd_iface->bss[0]->own_addr,
1969 if (start_ctrl_iface_bss(hapd) < 0 ||
1970 (hapd_iface->state == HAPD_IFACE_ENABLED &&
1971 hostapd_setup_bss(hapd, -1))) {
1972 hostapd_cleanup(hapd);
1973 hapd_iface->bss[hapd_iface->num_bss - 1] = NULL;
1974 hapd_iface->conf->num_bss--;
1975 hapd_iface->num_bss--;
1976 wpa_printf(MSG_DEBUG, "%s: free hapd %p %s",
1977 __func__, hapd, hapd->conf->iface);
1985 ptr = os_strchr(buf, ' ');
1990 if (os_strncmp(ptr, "config=", 7) == 0)
1991 conf_file = ptr + 7;
1993 for (i = 0; i < interfaces->count; i++) {
1994 if (!os_strcmp(interfaces->iface[i]->conf->bss[0]->iface,
1996 wpa_printf(MSG_INFO, "Cannot add interface - it "
2002 hapd_iface = hostapd_iface_alloc(interfaces);
2003 if (hapd_iface == NULL) {
2004 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
2005 "for interface", __func__);
2009 if (conf_file && interfaces->config_read_cb) {
2010 conf = interfaces->config_read_cb(conf_file);
2011 if (conf && conf->bss)
2012 os_strlcpy(conf->bss[0]->iface, buf,
2013 sizeof(conf->bss[0]->iface));
2015 conf = hostapd_config_alloc(interfaces, buf, ptr);
2016 if (conf == NULL || conf->bss == NULL) {
2017 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
2018 "for configuration", __func__);
2022 hapd_iface = hostapd_data_alloc(interfaces, conf);
2023 if (hapd_iface == NULL) {
2024 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
2025 "for hostapd", __func__);
2029 if (start_ctrl_iface(hapd_iface) < 0)
2032 wpa_printf(MSG_INFO, "Add interface '%s'", conf->bss[0]->iface);
2038 hostapd_config_free(conf);
2040 if (hapd_iface->bss) {
2041 for (i = 0; i < hapd_iface->num_bss; i++) {
2042 hapd = hapd_iface->bss[i];
2045 if (hapd_iface->interfaces &&
2046 hapd_iface->interfaces->ctrl_iface_deinit)
2047 hapd_iface->interfaces->
2048 ctrl_iface_deinit(hapd);
2049 wpa_printf(MSG_DEBUG, "%s: free hapd %p (%s)",
2050 __func__, hapd_iface->bss[i],
2052 hostapd_cleanup(hapd);
2054 hapd_iface->bss[i] = NULL;
2056 os_free(hapd_iface->bss);
2057 hapd_iface->bss = NULL;
2059 hostapd_cleanup_iface(hapd_iface);
2065 static int hostapd_remove_bss(struct hostapd_iface *iface, unsigned int idx)
2069 wpa_printf(MSG_INFO, "Remove BSS '%s'", iface->conf->bss[idx]->iface);
2071 /* Remove hostapd_data only if it has already been initialized */
2072 if (idx < iface->num_bss) {
2073 struct hostapd_data *hapd = iface->bss[idx];
2075 hostapd_bss_deinit(hapd);
2076 wpa_printf(MSG_DEBUG, "%s: free hapd %p (%s)",
2077 __func__, hapd, hapd->conf->iface);
2078 hostapd_config_free_bss(hapd->conf);
2083 for (i = idx; i < iface->num_bss; i++)
2084 iface->bss[i] = iface->bss[i + 1];
2086 hostapd_config_free_bss(iface->conf->bss[idx]);
2087 iface->conf->bss[idx] = NULL;
2090 iface->conf->num_bss--;
2091 for (i = idx; i < iface->conf->num_bss; i++)
2092 iface->conf->bss[i] = iface->conf->bss[i + 1];
2098 int hostapd_remove_iface(struct hapd_interfaces *interfaces, char *buf)
2100 struct hostapd_iface *hapd_iface;
2103 for (i = 0; i < interfaces->count; i++) {
2104 hapd_iface = interfaces->iface[i];
2105 if (hapd_iface == NULL)
2107 if (!os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
2108 wpa_printf(MSG_INFO, "Remove interface '%s'", buf);
2109 hapd_iface->driver_ap_teardown =
2110 !!(hapd_iface->drv_flags &
2111 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
2113 hostapd_interface_deinit_free(hapd_iface);
2115 while (k < (interfaces->count - 1)) {
2116 interfaces->iface[k] =
2117 interfaces->iface[k + 1];
2120 interfaces->count--;
2124 for (j = 0; j < hapd_iface->conf->num_bss; j++) {
2125 if (!os_strcmp(hapd_iface->conf->bss[j]->iface, buf)) {
2126 hapd_iface->driver_ap_teardown =
2127 !(hapd_iface->drv_flags &
2128 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
2129 return hostapd_remove_bss(hapd_iface, j);
2138 * hostapd_new_assoc_sta - Notify that a new station associated with the AP
2139 * @hapd: Pointer to BSS data
2140 * @sta: Pointer to the associated STA data
2141 * @reassoc: 1 to indicate this was a re-association; 0 = first association
2143 * This function will be called whenever a station associates with the AP. It
2144 * can be called from ieee802_11.c for drivers that export MLME to hostapd and
2145 * from drv_callbacks.c based on driver events for drivers that take care of
2146 * management frames (IEEE 802.11 authentication and association) internally.
2148 void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
2151 if (hapd->tkip_countermeasures) {
2152 hostapd_drv_sta_deauth(hapd, sta->addr,
2153 WLAN_REASON_MICHAEL_MIC_FAILURE);
2157 hostapd_prune_associations(hapd, sta->addr);
2159 /* IEEE 802.11F (IAPP) */
2160 if (hapd->conf->ieee802_11f)
2161 iapp_new_station(hapd->iapp, sta);
2164 if (sta->p2p_ie == NULL && !sta->no_p2p_set) {
2165 sta->no_p2p_set = 1;
2166 hapd->num_sta_no_p2p++;
2167 if (hapd->num_sta_no_p2p == 1)
2168 hostapd_p2p_non_p2p_sta_connected(hapd);
2170 #endif /* CONFIG_P2P */
2172 /* Start accounting here, if IEEE 802.1X and WPA are not used.
2173 * IEEE 802.1X/WPA code will start accounting after the station has
2174 * been authorized. */
2175 if (!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) {
2176 ap_sta_set_authorized(hapd, sta, 1);
2177 os_get_reltime(&sta->connected_time);
2178 accounting_sta_start(hapd, sta);
2181 /* Start IEEE 802.1X authentication process for new stations */
2182 ieee802_1x_new_station(hapd, sta);
2184 if (sta->auth_alg != WLAN_AUTH_FT &&
2185 !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)))
2186 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH);
2188 wpa_auth_sta_associated(hapd->wpa_auth, sta->wpa_sm);
2190 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) {
2191 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
2192 "for " MACSTR " (%d seconds - ap_max_inactivity)",
2193 __func__, MAC2STR(sta->addr),
2194 hapd->conf->ap_max_inactivity);
2195 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
2196 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
2197 ap_handle_timer, hapd, sta);
2202 const char * hostapd_state_text(enum hostapd_iface_state s)
2205 case HAPD_IFACE_UNINITIALIZED:
2206 return "UNINITIALIZED";
2207 case HAPD_IFACE_DISABLED:
2209 case HAPD_IFACE_COUNTRY_UPDATE:
2210 return "COUNTRY_UPDATE";
2211 case HAPD_IFACE_ACS:
2213 case HAPD_IFACE_HT_SCAN:
2215 case HAPD_IFACE_DFS:
2217 case HAPD_IFACE_ENABLED:
2225 void hostapd_set_state(struct hostapd_iface *iface, enum hostapd_iface_state s)
2227 wpa_printf(MSG_INFO, "%s: interface state %s->%s",
2228 iface->conf->bss[0]->iface, hostapd_state_text(iface->state),
2229 hostapd_state_text(s));
2236 static void free_beacon_data(struct beacon_data *beacon)
2238 os_free(beacon->head);
2239 beacon->head = NULL;
2240 os_free(beacon->tail);
2241 beacon->tail = NULL;
2242 os_free(beacon->probe_resp);
2243 beacon->probe_resp = NULL;
2244 os_free(beacon->beacon_ies);
2245 beacon->beacon_ies = NULL;
2246 os_free(beacon->proberesp_ies);
2247 beacon->proberesp_ies = NULL;
2248 os_free(beacon->assocresp_ies);
2249 beacon->assocresp_ies = NULL;
2253 static int hostapd_build_beacon_data(struct hostapd_data *hapd,
2254 struct beacon_data *beacon)
2256 struct wpabuf *beacon_extra, *proberesp_extra, *assocresp_extra;
2257 struct wpa_driver_ap_params params;
2260 os_memset(beacon, 0, sizeof(*beacon));
2261 ret = ieee802_11_build_ap_params(hapd, ¶ms);
2265 ret = hostapd_build_ap_extra_ies(hapd, &beacon_extra,
2269 goto free_ap_params;
2272 beacon->head = os_malloc(params.head_len);
2274 goto free_ap_extra_ies;
2276 os_memcpy(beacon->head, params.head, params.head_len);
2277 beacon->head_len = params.head_len;
2279 beacon->tail = os_malloc(params.tail_len);
2283 os_memcpy(beacon->tail, params.tail, params.tail_len);
2284 beacon->tail_len = params.tail_len;
2286 if (params.proberesp != NULL) {
2287 beacon->probe_resp = os_malloc(params.proberesp_len);
2288 if (!beacon->probe_resp)
2291 os_memcpy(beacon->probe_resp, params.proberesp,
2292 params.proberesp_len);
2293 beacon->probe_resp_len = params.proberesp_len;
2296 /* copy the extra ies */
2298 beacon->beacon_ies = os_malloc(wpabuf_len(beacon_extra));
2299 if (!beacon->beacon_ies)
2302 os_memcpy(beacon->beacon_ies,
2303 beacon_extra->buf, wpabuf_len(beacon_extra));
2304 beacon->beacon_ies_len = wpabuf_len(beacon_extra);
2307 if (proberesp_extra) {
2308 beacon->proberesp_ies =
2309 os_malloc(wpabuf_len(proberesp_extra));
2310 if (!beacon->proberesp_ies)
2313 os_memcpy(beacon->proberesp_ies, proberesp_extra->buf,
2314 wpabuf_len(proberesp_extra));
2315 beacon->proberesp_ies_len = wpabuf_len(proberesp_extra);
2318 if (assocresp_extra) {
2319 beacon->assocresp_ies =
2320 os_malloc(wpabuf_len(assocresp_extra));
2321 if (!beacon->assocresp_ies)
2324 os_memcpy(beacon->assocresp_ies, assocresp_extra->buf,
2325 wpabuf_len(assocresp_extra));
2326 beacon->assocresp_ies_len = wpabuf_len(assocresp_extra);
2331 /* if the function fails, the caller should not free beacon data */
2333 free_beacon_data(beacon);
2336 hostapd_free_ap_extra_ies(hapd, beacon_extra, proberesp_extra,
2339 ieee802_11_free_ap_params(¶ms);
2345 * TODO: This flow currently supports only changing frequency within the
2346 * same hw_mode. Any other changes to MAC parameters or provided settings (even
2347 * width) are not supported.
2349 static int hostapd_change_config_freq(struct hostapd_data *hapd,
2350 struct hostapd_config *conf,
2351 struct hostapd_freq_params *params,
2352 struct hostapd_freq_params *old_params)
2356 if (!params->channel) {
2357 /* check if the new channel is supported by hw */
2358 params->channel = hostapd_hw_get_channel(hapd, params->freq);
2361 channel = params->channel;
2365 /* if a pointer to old_params is provided we save previous state */
2367 old_params->channel = conf->channel;
2368 old_params->ht_enabled = conf->ieee80211n;
2369 old_params->sec_channel_offset = conf->secondary_channel;
2372 conf->channel = channel;
2373 conf->ieee80211n = params->ht_enabled;
2374 conf->secondary_channel = params->sec_channel_offset;
2376 /* TODO: maybe call here hostapd_config_check here? */
2382 static int hostapd_fill_csa_settings(struct hostapd_data *hapd,
2383 struct csa_settings *settings)
2385 struct hostapd_iface *iface = hapd->iface;
2386 struct hostapd_freq_params old_freq;
2389 os_memset(&old_freq, 0, sizeof(old_freq));
2390 if (!iface || !iface->freq || hapd->csa_in_progress)
2393 ret = hostapd_change_config_freq(iface->bss[0], iface->conf,
2394 &settings->freq_params,
2399 ret = hostapd_build_beacon_data(hapd, &settings->beacon_after);
2401 /* change back the configuration */
2402 hostapd_change_config_freq(iface->bss[0], iface->conf,
2408 /* set channel switch parameters for csa ie */
2409 hapd->cs_freq_params = settings->freq_params;
2410 hapd->cs_count = settings->cs_count;
2411 hapd->cs_block_tx = settings->block_tx;
2413 ret = hostapd_build_beacon_data(hapd, &settings->beacon_csa);
2415 free_beacon_data(&settings->beacon_after);
2419 settings->counter_offset_beacon = hapd->cs_c_off_beacon;
2420 settings->counter_offset_presp = hapd->cs_c_off_proberesp;
2426 void hostapd_cleanup_cs_params(struct hostapd_data *hapd)
2428 os_memset(&hapd->cs_freq_params, 0, sizeof(hapd->cs_freq_params));
2430 hapd->cs_block_tx = 0;
2431 hapd->cs_c_off_beacon = 0;
2432 hapd->cs_c_off_proberesp = 0;
2433 hapd->csa_in_progress = 0;
2437 int hostapd_switch_channel(struct hostapd_data *hapd,
2438 struct csa_settings *settings)
2442 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA)) {
2443 wpa_printf(MSG_INFO, "CSA is not supported");
2447 ret = hostapd_fill_csa_settings(hapd, settings);
2451 ret = hostapd_drv_switch_channel(hapd, settings);
2452 free_beacon_data(&settings->beacon_csa);
2453 free_beacon_data(&settings->beacon_after);
2456 /* if we failed, clean cs parameters */
2457 hostapd_cleanup_cs_params(hapd);
2461 hapd->csa_in_progress = 1;
2467 hostapd_switch_channel_fallback(struct hostapd_iface *iface,
2468 const struct hostapd_freq_params *freq_params)
2470 int vht_seg0_idx = 0, vht_seg1_idx = 0, vht_bw = VHT_CHANWIDTH_USE_HT;
2473 wpa_printf(MSG_DEBUG, "Restarting all CSA-related BSSes");
2475 if (freq_params->center_freq1)
2476 vht_seg0_idx = 36 + (freq_params->center_freq1 - 5180) / 5;
2477 if (freq_params->center_freq2)
2478 vht_seg1_idx = 36 + (freq_params->center_freq2 - 5180) / 5;
2480 switch (freq_params->bandwidth) {
2484 vht_bw = VHT_CHANWIDTH_USE_HT;
2487 if (freq_params->center_freq2)
2488 vht_bw = VHT_CHANWIDTH_80P80MHZ;
2490 vht_bw = VHT_CHANWIDTH_80MHZ;
2493 vht_bw = VHT_CHANWIDTH_160MHZ;
2496 wpa_printf(MSG_WARNING, "Unknown CSA bandwidth: %d",
2497 freq_params->bandwidth);
2501 iface->freq = freq_params->freq;
2502 iface->conf->channel = freq_params->channel;
2503 iface->conf->secondary_channel = freq_params->sec_channel_offset;
2504 iface->conf->vht_oper_centr_freq_seg0_idx = vht_seg0_idx;
2505 iface->conf->vht_oper_centr_freq_seg1_idx = vht_seg1_idx;
2506 iface->conf->vht_oper_chwidth = vht_bw;
2507 iface->conf->ieee80211n = freq_params->ht_enabled;
2508 iface->conf->ieee80211ac = freq_params->vht_enabled;
2511 * cs_params must not be cleared earlier because the freq_params
2512 * argument may actually point to one of these.
2514 for (i = 0; i < iface->num_bss; i++)
2515 hostapd_cleanup_cs_params(iface->bss[i]);
2517 hostapd_disable_iface(iface);
2518 hostapd_enable_iface(iface);
2521 #endif /* NEED_AP_MLME */