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"
39 #include "dhcp_snoop.h"
42 static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason);
43 static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd);
44 static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd);
45 static int setup_interface2(struct hostapd_iface *iface);
46 static void channel_list_update_timeout(void *eloop_ctx, void *timeout_ctx);
49 int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
50 int (*cb)(struct hostapd_iface *iface,
51 void *ctx), void *ctx)
56 for (i = 0; i < interfaces->count; i++) {
57 ret = cb(interfaces->iface[i], ctx);
66 static void hostapd_reload_bss(struct hostapd_data *hapd)
68 struct hostapd_ssid *ssid;
70 #ifndef CONFIG_NO_RADIUS
71 radius_client_reconfig(hapd->radius, hapd->conf->radius);
72 #endif /* CONFIG_NO_RADIUS */
74 ssid = &hapd->conf->ssid;
75 if (!ssid->wpa_psk_set && ssid->wpa_psk && !ssid->wpa_psk->next &&
76 ssid->wpa_passphrase_set && ssid->wpa_passphrase) {
78 * Force PSK to be derived again since SSID or passphrase may
81 os_free(ssid->wpa_psk);
84 if (hostapd_setup_wpa_psk(hapd->conf)) {
85 wpa_printf(MSG_ERROR, "Failed to re-configure WPA PSK "
86 "after reloading configuration");
89 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
90 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1);
92 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0);
94 if ((hapd->conf->wpa || hapd->conf->osen) && hapd->wpa_auth == NULL) {
95 hostapd_setup_wpa(hapd);
97 wpa_init_keys(hapd->wpa_auth);
98 } else if (hapd->conf->wpa) {
101 hostapd_reconfig_wpa(hapd);
102 wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
103 if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len))
104 wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
105 "the kernel driver.");
106 } else if (hapd->wpa_auth) {
107 wpa_deinit(hapd->wpa_auth);
108 hapd->wpa_auth = NULL;
109 hostapd_set_privacy(hapd, 0);
110 hostapd_setup_encryption(hapd->conf->iface, hapd);
111 hostapd_set_generic_elem(hapd, (u8 *) "", 0);
114 ieee802_11_set_beacon(hapd);
115 hostapd_update_wps(hapd);
117 if (hapd->conf->ssid.ssid_set &&
118 hostapd_set_ssid(hapd, hapd->conf->ssid.ssid,
119 hapd->conf->ssid.ssid_len)) {
120 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
121 /* try to continue */
123 wpa_printf(MSG_DEBUG, "Reconfigured interface %s", hapd->conf->iface);
127 static void hostapd_clear_old(struct hostapd_iface *iface)
132 * Deauthenticate all stations since the new configuration may not
133 * allow them to use the BSS anymore.
135 for (j = 0; j < iface->num_bss; j++) {
136 hostapd_flush_old_stations(iface->bss[j],
137 WLAN_REASON_PREV_AUTH_NOT_VALID);
138 hostapd_broadcast_wep_clear(iface->bss[j]);
140 #ifndef CONFIG_NO_RADIUS
141 /* TODO: update dynamic data based on changed configuration
142 * items (e.g., open/close sockets, etc.) */
143 radius_client_flush(iface->bss[j]->radius, 0);
144 #endif /* CONFIG_NO_RADIUS */
149 int hostapd_reload_config(struct hostapd_iface *iface)
151 struct hostapd_data *hapd = iface->bss[0];
152 struct hostapd_config *newconf, *oldconf;
155 if (iface->config_fname == NULL) {
156 /* Only in-memory config in use - assume it has been updated */
157 hostapd_clear_old(iface);
158 for (j = 0; j < iface->num_bss; j++)
159 hostapd_reload_bss(iface->bss[j]);
163 if (iface->interfaces == NULL ||
164 iface->interfaces->config_read_cb == NULL)
166 newconf = iface->interfaces->config_read_cb(iface->config_fname);
170 hostapd_clear_old(iface);
172 oldconf = hapd->iconf;
173 iface->conf = newconf;
175 for (j = 0; j < iface->num_bss; j++) {
176 hapd = iface->bss[j];
177 hapd->iconf = newconf;
178 hapd->iconf->channel = oldconf->channel;
179 hapd->iconf->secondary_channel = oldconf->secondary_channel;
180 hapd->iconf->ieee80211n = oldconf->ieee80211n;
181 hapd->iconf->ieee80211ac = oldconf->ieee80211ac;
182 hapd->iconf->ht_capab = oldconf->ht_capab;
183 hapd->iconf->vht_capab = oldconf->vht_capab;
184 hapd->iconf->vht_oper_chwidth = oldconf->vht_oper_chwidth;
185 hapd->iconf->vht_oper_centr_freq_seg0_idx =
186 oldconf->vht_oper_centr_freq_seg0_idx;
187 hapd->iconf->vht_oper_centr_freq_seg1_idx =
188 oldconf->vht_oper_centr_freq_seg1_idx;
189 hapd->conf = newconf->bss[j];
190 hostapd_reload_bss(hapd);
193 hostapd_config_free(oldconf);
200 static void hostapd_broadcast_key_clear_iface(struct hostapd_data *hapd,
205 for (i = 0; i < NUM_WEP_KEYS; i++) {
206 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE, NULL, i,
207 0, NULL, 0, NULL, 0)) {
208 wpa_printf(MSG_DEBUG, "Failed to clear default "
209 "encryption keys (ifname=%s keyidx=%d)",
213 #ifdef CONFIG_IEEE80211W
214 if (hapd->conf->ieee80211w) {
215 for (i = NUM_WEP_KEYS; i < NUM_WEP_KEYS + 2; i++) {
216 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE,
219 wpa_printf(MSG_DEBUG, "Failed to clear "
220 "default mgmt encryption keys "
221 "(ifname=%s keyidx=%d)", ifname, i);
225 #endif /* CONFIG_IEEE80211W */
229 static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd)
231 hostapd_broadcast_key_clear_iface(hapd, hapd->conf->iface);
236 static int hostapd_broadcast_wep_set(struct hostapd_data *hapd)
239 struct hostapd_ssid *ssid = &hapd->conf->ssid;
242 if (ssid->wep.default_len &&
243 hostapd_drv_set_key(hapd->conf->iface,
244 hapd, WPA_ALG_WEP, broadcast_ether_addr, idx,
245 1, NULL, 0, ssid->wep.key[idx],
246 ssid->wep.len[idx])) {
247 wpa_printf(MSG_WARNING, "Could not set WEP encryption.");
255 static void hostapd_free_hapd_data(struct hostapd_data *hapd)
257 if (!hapd->started) {
258 wpa_printf(MSG_ERROR, "%s: Interface %s wasn't started",
259 __func__, hapd->conf->iface);
264 wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
265 iapp_deinit(hapd->iapp);
267 accounting_deinit(hapd);
268 hostapd_deinit_wpa(hapd);
270 hostapd_acl_deinit(hapd);
271 #ifndef CONFIG_NO_RADIUS
272 radius_client_deinit(hapd->radius);
274 radius_das_deinit(hapd->radius_das);
275 hapd->radius_das = NULL;
276 #endif /* CONFIG_NO_RADIUS */
278 hostapd_deinit_wps(hapd);
280 authsrv_deinit(hapd);
282 if (hapd->interface_added) {
283 hapd->interface_added = 0;
284 if (hostapd_if_remove(hapd, WPA_IF_AP_BSS, hapd->conf->iface)) {
285 wpa_printf(MSG_WARNING,
286 "Failed to remove BSS interface %s",
288 hapd->interface_added = 1;
291 * Since this was a dynamically added interface, the
292 * driver wrapper may have removed its internal instance
293 * and hapd->drv_priv is not valid anymore.
295 hapd->drv_priv = NULL;
299 os_free(hapd->probereq_cb);
300 hapd->probereq_cb = NULL;
303 wpabuf_free(hapd->p2p_beacon_ie);
304 hapd->p2p_beacon_ie = NULL;
305 wpabuf_free(hapd->p2p_probe_resp_ie);
306 hapd->p2p_probe_resp_ie = NULL;
307 #endif /* CONFIG_P2P */
309 wpabuf_free(hapd->time_adv);
311 #ifdef CONFIG_INTERWORKING
312 gas_serv_deinit(hapd);
313 #endif /* CONFIG_INTERWORKING */
315 bss_load_update_deinit(hapd);
316 dhcp_snoop_deinit(hapd);
319 bin_clear_free(hapd->tmp_eap_user.identity,
320 hapd->tmp_eap_user.identity_len);
321 bin_clear_free(hapd->tmp_eap_user.password,
322 hapd->tmp_eap_user.password_len);
323 #endif /* CONFIG_SQLITE */
328 * hostapd_cleanup - Per-BSS cleanup (deinitialization)
329 * @hapd: Pointer to BSS data
331 * This function is used to free all per-BSS data structures and resources.
332 * Most of the modules that are initialized in hostapd_setup_bss() are
333 * deinitialized here.
335 static void hostapd_cleanup(struct hostapd_data *hapd)
337 wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s))", __func__, hapd,
339 if (hapd->iface->interfaces &&
340 hapd->iface->interfaces->ctrl_iface_deinit)
341 hapd->iface->interfaces->ctrl_iface_deinit(hapd);
342 hostapd_free_hapd_data(hapd);
346 static void hostapd_cleanup_iface_partial(struct hostapd_iface *iface)
348 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
349 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
350 iface->hw_features = NULL;
351 os_free(iface->current_rates);
352 iface->current_rates = NULL;
353 os_free(iface->basic_rates);
354 iface->basic_rates = NULL;
355 ap_list_deinit(iface);
360 * hostapd_cleanup_iface - Complete per-interface cleanup
361 * @iface: Pointer to interface data
363 * This function is called after per-BSS data structures are deinitialized
364 * with hostapd_cleanup().
366 static void hostapd_cleanup_iface(struct hostapd_iface *iface)
368 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
369 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
371 hostapd_cleanup_iface_partial(iface);
372 hostapd_config_free(iface->conf);
375 os_free(iface->config_fname);
377 wpa_printf(MSG_DEBUG, "%s: free iface=%p", __func__, iface);
382 static void hostapd_clear_wep(struct hostapd_data *hapd)
384 if (hapd->drv_priv && !hapd->iface->driver_ap_teardown) {
385 hostapd_set_privacy(hapd, 0);
386 hostapd_broadcast_wep_clear(hapd);
391 static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd)
395 hostapd_broadcast_wep_set(hapd);
397 if (hapd->conf->ssid.wep.default_len) {
398 hostapd_set_privacy(hapd, 1);
403 * When IEEE 802.1X is not enabled, the driver may need to know how to
404 * set authentication algorithms for static WEP.
406 hostapd_drv_set_authmode(hapd, hapd->conf->auth_algs);
408 for (i = 0; i < 4; i++) {
409 if (hapd->conf->ssid.wep.key[i] &&
410 hostapd_drv_set_key(iface, hapd, WPA_ALG_WEP, NULL, i,
411 i == hapd->conf->ssid.wep.idx, NULL, 0,
412 hapd->conf->ssid.wep.key[i],
413 hapd->conf->ssid.wep.len[i])) {
414 wpa_printf(MSG_WARNING, "Could not set WEP "
418 if (hapd->conf->ssid.wep.key[i] &&
419 i == hapd->conf->ssid.wep.idx)
420 hostapd_set_privacy(hapd, 1);
427 static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason)
432 if (hostapd_drv_none(hapd) || hapd->drv_priv == NULL)
435 if (!hapd->iface->driver_ap_teardown) {
436 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
437 "Flushing old station entries");
439 if (hostapd_flush(hapd)) {
440 wpa_msg(hapd->msg_ctx, MSG_WARNING,
441 "Could not connect to kernel driver");
445 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "Deauthenticate all stations");
446 os_memset(addr, 0xff, ETH_ALEN);
447 hostapd_drv_sta_deauth(hapd, addr, reason);
448 hostapd_free_stas(hapd);
454 static void hostapd_bss_deinit_no_free(struct hostapd_data *hapd)
456 hostapd_free_stas(hapd);
457 hostapd_flush_old_stations(hapd, WLAN_REASON_DEAUTH_LEAVING);
458 hostapd_clear_wep(hapd);
463 * hostapd_validate_bssid_configuration - Validate BSSID configuration
464 * @iface: Pointer to interface data
465 * Returns: 0 on success, -1 on failure
467 * This function is used to validate that the configured BSSIDs are valid.
469 static int hostapd_validate_bssid_configuration(struct hostapd_iface *iface)
471 u8 mask[ETH_ALEN] = { 0 };
472 struct hostapd_data *hapd = iface->bss[0];
473 unsigned int i = iface->conf->num_bss, bits = 0, j;
476 if (hostapd_drv_none(hapd))
479 /* Generate BSSID mask that is large enough to cover the BSSIDs. */
481 /* Determine the bits necessary to cover the number of BSSIDs. */
482 for (i--; i; i >>= 1)
485 /* Determine the bits necessary to any configured BSSIDs,
486 if they are higher than the number of BSSIDs. */
487 for (j = 0; j < iface->conf->num_bss; j++) {
488 if (hostapd_mac_comp_empty(iface->conf->bss[j]->bssid) == 0) {
494 for (i = 0; i < ETH_ALEN; i++) {
496 iface->conf->bss[j]->bssid[i] ^
504 for (i = 0; i < ETH_ALEN && mask[i] == 0; i++)
510 while (mask[i] != 0) {
520 wpa_printf(MSG_ERROR, "Too many bits in the BSSID mask (%u)",
525 os_memset(mask, 0xff, ETH_ALEN);
527 for (i = 5; i > 5 - j; i--)
534 wpa_printf(MSG_DEBUG, "BSS count %lu, BSSID mask " MACSTR " (%d bits)",
535 (unsigned long) iface->conf->num_bss, MAC2STR(mask), bits);
540 for (i = 0; i < ETH_ALEN; i++) {
541 if ((hapd->own_addr[i] & mask[i]) != hapd->own_addr[i]) {
542 wpa_printf(MSG_ERROR, "Invalid BSSID mask " MACSTR
543 " for start address " MACSTR ".",
544 MAC2STR(mask), MAC2STR(hapd->own_addr));
545 wpa_printf(MSG_ERROR, "Start address must be the "
546 "first address in the block (i.e., addr "
547 "AND mask == addr).");
556 static int mac_in_conf(struct hostapd_config *conf, const void *a)
560 for (i = 0; i < conf->num_bss; i++) {
561 if (hostapd_mac_comp(conf->bss[i]->bssid, a) == 0) {
570 #ifndef CONFIG_NO_RADIUS
572 static int hostapd_das_nas_mismatch(struct hostapd_data *hapd,
573 struct radius_das_attrs *attr)
575 if (attr->nas_identifier &&
576 (!hapd->conf->nas_identifier ||
577 os_strlen(hapd->conf->nas_identifier) !=
578 attr->nas_identifier_len ||
579 os_memcmp(hapd->conf->nas_identifier, attr->nas_identifier,
580 attr->nas_identifier_len) != 0)) {
581 wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-Identifier mismatch");
585 if (attr->nas_ip_addr &&
586 (hapd->conf->own_ip_addr.af != AF_INET ||
587 os_memcmp(&hapd->conf->own_ip_addr.u.v4, attr->nas_ip_addr, 4) !=
589 wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-IP-Address mismatch");
594 if (attr->nas_ipv6_addr &&
595 (hapd->conf->own_ip_addr.af != AF_INET6 ||
596 os_memcmp(&hapd->conf->own_ip_addr.u.v6, attr->nas_ipv6_addr, 16)
598 wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-IPv6-Address mismatch");
601 #endif /* CONFIG_IPV6 */
607 static struct sta_info * hostapd_das_find_sta(struct hostapd_data *hapd,
608 struct radius_das_attrs *attr)
610 struct sta_info *sta = NULL;
614 sta = ap_get_sta(hapd, attr->sta_addr);
616 if (sta == NULL && attr->acct_session_id &&
617 attr->acct_session_id_len == 17) {
618 for (sta = hapd->sta_list; sta; sta = sta->next) {
619 os_snprintf(buf, sizeof(buf), "%08X-%08X",
620 sta->acct_session_id_hi,
621 sta->acct_session_id_lo);
622 if (os_memcmp(attr->acct_session_id, buf, 17) == 0)
627 if (sta == NULL && attr->cui) {
628 for (sta = hapd->sta_list; sta; sta = sta->next) {
630 cui = ieee802_1x_get_radius_cui(sta->eapol_sm);
631 if (cui && wpabuf_len(cui) == attr->cui_len &&
632 os_memcmp(wpabuf_head(cui), attr->cui,
638 if (sta == NULL && attr->user_name) {
639 for (sta = hapd->sta_list; sta; sta = sta->next) {
642 identity = ieee802_1x_get_identity(sta->eapol_sm,
645 identity_len == attr->user_name_len &&
646 os_memcmp(identity, attr->user_name, identity_len)
656 static enum radius_das_res
657 hostapd_das_disconnect(void *ctx, struct radius_das_attrs *attr)
659 struct hostapd_data *hapd = ctx;
660 struct sta_info *sta;
662 if (hostapd_das_nas_mismatch(hapd, attr))
663 return RADIUS_DAS_NAS_MISMATCH;
665 sta = hostapd_das_find_sta(hapd, attr);
667 return RADIUS_DAS_SESSION_NOT_FOUND;
669 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
671 hostapd_drv_sta_deauth(hapd, sta->addr,
672 WLAN_REASON_PREV_AUTH_NOT_VALID);
673 ap_sta_deauthenticate(hapd, sta, WLAN_REASON_PREV_AUTH_NOT_VALID);
675 return RADIUS_DAS_SUCCESS;
678 #endif /* CONFIG_NO_RADIUS */
682 * hostapd_setup_bss - Per-BSS setup (initialization)
683 * @hapd: Pointer to BSS data
684 * @first: Whether this BSS is the first BSS of an interface; -1 = not first,
685 * but interface may exist
687 * This function is used to initialize all per-BSS data structures and
688 * resources. This gets called in a loop for each BSS when an interface is
689 * initialized. Most of the modules that are initialized here will be
690 * deinitialized in hostapd_cleanup().
692 static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
694 struct hostapd_bss_config *conf = hapd->conf;
695 u8 ssid[HOSTAPD_MAX_SSID_LEN + 1];
696 int ssid_len, set_ssid;
697 char force_ifname[IFNAMSIZ];
698 u8 if_addr[ETH_ALEN];
699 int flush_old_stations = 1;
701 wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s), first=%d)",
702 __func__, hapd, conf->iface, first);
704 #ifdef EAP_SERVER_TNC
705 if (conf->tnc && tncs_global_init() < 0) {
706 wpa_printf(MSG_ERROR, "Failed to initialize TNCS");
709 #endif /* EAP_SERVER_TNC */
712 wpa_printf(MSG_ERROR, "%s: Interface %s was already started",
713 __func__, conf->iface);
718 if (!first || first == -1) {
719 if (hostapd_mac_comp_empty(conf->bssid) == 0) {
720 /* Allocate the next available BSSID. */
722 inc_byte_array(hapd->own_addr, ETH_ALEN);
723 } while (mac_in_conf(hapd->iconf, hapd->own_addr));
725 /* Allocate the configured BSSID. */
726 os_memcpy(hapd->own_addr, conf->bssid, ETH_ALEN);
728 if (hostapd_mac_comp(hapd->own_addr,
729 hapd->iface->bss[0]->own_addr) ==
731 wpa_printf(MSG_ERROR, "BSS '%s' may not have "
732 "BSSID set to the MAC address of "
733 "the radio", conf->iface);
738 hapd->interface_added = 1;
739 if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS,
740 conf->iface, hapd->own_addr, hapd,
741 &hapd->drv_priv, force_ifname, if_addr,
742 conf->bridge[0] ? conf->bridge : NULL,
744 wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
745 MACSTR ")", MAC2STR(hapd->own_addr));
746 hapd->interface_added = 0;
751 if (conf->wmm_enabled < 0)
752 conf->wmm_enabled = hapd->iconf->ieee80211n;
755 if (hapd->iface->mconf == NULL)
756 flush_old_stations = 0;
757 #endif /* CONFIG_MESH */
759 if (flush_old_stations)
760 hostapd_flush_old_stations(hapd,
761 WLAN_REASON_PREV_AUTH_NOT_VALID);
762 hostapd_set_privacy(hapd, 0);
764 hostapd_broadcast_wep_clear(hapd);
765 if (hostapd_setup_encryption(conf->iface, hapd))
769 * Fetch the SSID from the system and use it or,
770 * if one was specified in the config file, verify they
773 ssid_len = hostapd_get_ssid(hapd, ssid, sizeof(ssid));
775 wpa_printf(MSG_ERROR, "Could not read SSID from system");
778 if (conf->ssid.ssid_set) {
780 * If SSID is specified in the config file and it differs
781 * from what is being used then force installation of the
784 set_ssid = (conf->ssid.ssid_len != (size_t) ssid_len ||
785 os_memcmp(conf->ssid.ssid, ssid, ssid_len) != 0);
788 * No SSID in the config file; just use the one we got
792 conf->ssid.ssid_len = ssid_len;
793 os_memcpy(conf->ssid.ssid, ssid, conf->ssid.ssid_len);
796 if (!hostapd_drv_none(hapd)) {
797 wpa_printf(MSG_ERROR, "Using interface %s with hwaddr " MACSTR
799 conf->iface, MAC2STR(hapd->own_addr),
800 wpa_ssid_txt(conf->ssid.ssid, conf->ssid.ssid_len));
803 if (hostapd_setup_wpa_psk(conf)) {
804 wpa_printf(MSG_ERROR, "WPA-PSK setup failed.");
808 /* Set SSID for the kernel driver (to be used in beacon and probe
809 * response frames) */
810 if (set_ssid && hostapd_set_ssid(hapd, conf->ssid.ssid,
811 conf->ssid.ssid_len)) {
812 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
816 if (wpa_debug_level <= MSG_MSGDUMP)
817 conf->radius->msg_dumps = 1;
818 #ifndef CONFIG_NO_RADIUS
819 hapd->radius = radius_client_init(hapd, conf->radius);
820 if (hapd->radius == NULL) {
821 wpa_printf(MSG_ERROR, "RADIUS client initialization failed.");
825 if (conf->radius_das_port) {
826 struct radius_das_conf das_conf;
827 os_memset(&das_conf, 0, sizeof(das_conf));
828 das_conf.port = conf->radius_das_port;
829 das_conf.shared_secret = conf->radius_das_shared_secret;
830 das_conf.shared_secret_len =
831 conf->radius_das_shared_secret_len;
832 das_conf.client_addr = &conf->radius_das_client_addr;
833 das_conf.time_window = conf->radius_das_time_window;
834 das_conf.require_event_timestamp =
835 conf->radius_das_require_event_timestamp;
837 das_conf.disconnect = hostapd_das_disconnect;
838 hapd->radius_das = radius_das_init(&das_conf);
839 if (hapd->radius_das == NULL) {
840 wpa_printf(MSG_ERROR, "RADIUS DAS initialization "
845 #endif /* CONFIG_NO_RADIUS */
847 if (hostapd_acl_init(hapd)) {
848 wpa_printf(MSG_ERROR, "ACL initialization failed.");
851 if (hostapd_init_wps(hapd, conf))
854 if (authsrv_init(hapd) < 0)
857 if (ieee802_1x_init(hapd)) {
858 wpa_printf(MSG_ERROR, "IEEE 802.1X initialization failed.");
862 if ((conf->wpa || conf->osen) && hostapd_setup_wpa(hapd))
865 if (accounting_init(hapd)) {
866 wpa_printf(MSG_ERROR, "Accounting initialization failed.");
870 if (conf->ieee802_11f &&
871 (hapd->iapp = iapp_init(hapd, conf->iapp_iface)) == NULL) {
872 wpa_printf(MSG_ERROR, "IEEE 802.11F (IAPP) initialization "
877 #ifdef CONFIG_INTERWORKING
878 if (gas_serv_init(hapd)) {
879 wpa_printf(MSG_ERROR, "GAS server initialization failed");
883 if (conf->qos_map_set_len &&
884 hostapd_drv_set_qos_map(hapd, conf->qos_map_set,
885 conf->qos_map_set_len)) {
886 wpa_printf(MSG_ERROR, "Failed to initialize QoS Map");
889 #endif /* CONFIG_INTERWORKING */
891 if (conf->bss_load_update_period && bss_load_update_init(hapd)) {
892 wpa_printf(MSG_ERROR, "BSS Load initialization failed");
896 if (conf->proxy_arp && dhcp_snoop_init(hapd)) {
897 wpa_printf(MSG_ERROR, "DHCP snooping initialization failed");
901 if (!hostapd_drv_none(hapd) && vlan_init(hapd)) {
902 wpa_printf(MSG_ERROR, "VLAN initialization failed.");
906 if (!conf->start_disabled && ieee802_11_set_beacon(hapd) < 0)
909 if (hapd->wpa_auth && wpa_init_keys(hapd->wpa_auth) < 0)
912 if (hapd->driver && hapd->driver->set_operstate)
913 hapd->driver->set_operstate(hapd->drv_priv, 1);
919 static void hostapd_tx_queue_params(struct hostapd_iface *iface)
921 struct hostapd_data *hapd = iface->bss[0];
923 struct hostapd_tx_queue_params *p;
926 if (iface->mconf == NULL)
928 #endif /* CONFIG_MESH */
930 for (i = 0; i < NUM_TX_QUEUES; i++) {
931 p = &iface->conf->tx_queue[i];
933 if (hostapd_set_tx_queue_params(hapd, i, p->aifs, p->cwmin,
934 p->cwmax, p->burst)) {
935 wpa_printf(MSG_DEBUG, "Failed to set TX queue "
936 "parameters for queue %d.", i);
937 /* Continue anyway */
943 static int hostapd_set_acl_list(struct hostapd_data *hapd,
944 struct mac_acl_entry *mac_acl,
945 int n_entries, u8 accept_acl)
947 struct hostapd_acl_params *acl_params;
950 acl_params = os_zalloc(sizeof(*acl_params) +
951 (n_entries * sizeof(acl_params->mac_acl[0])));
955 for (i = 0; i < n_entries; i++)
956 os_memcpy(acl_params->mac_acl[i].addr, mac_acl[i].addr,
959 acl_params->acl_policy = accept_acl;
960 acl_params->num_mac_acl = n_entries;
962 err = hostapd_drv_set_acl(hapd, acl_params);
970 static void hostapd_set_acl(struct hostapd_data *hapd)
972 struct hostapd_config *conf = hapd->iconf;
976 if (hapd->iface->drv_max_acl_mac_addrs == 0)
979 if (conf->bss[0]->macaddr_acl == DENY_UNLESS_ACCEPTED) {
981 err = hostapd_set_acl_list(hapd, conf->bss[0]->accept_mac,
982 conf->bss[0]->num_accept_mac,
985 wpa_printf(MSG_DEBUG, "Failed to set accept acl");
988 } else if (conf->bss[0]->macaddr_acl == ACCEPT_UNLESS_DENIED) {
990 err = hostapd_set_acl_list(hapd, conf->bss[0]->deny_mac,
991 conf->bss[0]->num_deny_mac,
994 wpa_printf(MSG_DEBUG, "Failed to set deny acl");
1001 static int start_ctrl_iface_bss(struct hostapd_data *hapd)
1003 if (!hapd->iface->interfaces ||
1004 !hapd->iface->interfaces->ctrl_iface_init)
1007 if (hapd->iface->interfaces->ctrl_iface_init(hapd)) {
1008 wpa_printf(MSG_ERROR,
1009 "Failed to setup control interface for %s",
1018 static int start_ctrl_iface(struct hostapd_iface *iface)
1022 if (!iface->interfaces || !iface->interfaces->ctrl_iface_init)
1025 for (i = 0; i < iface->num_bss; i++) {
1026 struct hostapd_data *hapd = iface->bss[i];
1027 if (iface->interfaces->ctrl_iface_init(hapd)) {
1028 wpa_printf(MSG_ERROR,
1029 "Failed to setup control interface for %s",
1039 static void channel_list_update_timeout(void *eloop_ctx, void *timeout_ctx)
1041 struct hostapd_iface *iface = eloop_ctx;
1043 if (!iface->wait_channel_update) {
1044 wpa_printf(MSG_INFO, "Channel list update timeout, but interface was not waiting for it");
1049 * It is possible that the existing channel list is acceptable, so try
1052 wpa_printf(MSG_DEBUG, "Channel list update timeout - try to continue anyway");
1053 setup_interface2(iface);
1057 void hostapd_channel_list_updated(struct hostapd_iface *iface, int initiator)
1059 if (!iface->wait_channel_update || initiator != REGDOM_SET_BY_USER)
1062 wpa_printf(MSG_DEBUG, "Channel list updated - continue setup");
1063 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
1064 setup_interface2(iface);
1068 static int setup_interface(struct hostapd_iface *iface)
1070 struct hostapd_data *hapd = iface->bss[0];
1074 * It is possible that setup_interface() is called after the interface
1075 * was disabled etc., in which case driver_ap_teardown is possibly set
1076 * to 1. Clear it here so any other key/station deletion, which is not
1077 * part of a teardown flow, would also call the relevant driver
1080 iface->driver_ap_teardown = 0;
1082 if (!iface->phy[0]) {
1083 const char *phy = hostapd_drv_get_radio_name(hapd);
1085 wpa_printf(MSG_DEBUG, "phy: %s", phy);
1086 os_strlcpy(iface->phy, phy, sizeof(iface->phy));
1091 * Make sure that all BSSes get configured with a pointer to the same
1094 for (i = 1; i < iface->num_bss; i++) {
1095 iface->bss[i]->driver = hapd->driver;
1096 iface->bss[i]->drv_priv = hapd->drv_priv;
1099 if (hostapd_validate_bssid_configuration(iface))
1103 * Initialize control interfaces early to allow external monitoring of
1104 * channel setup operations that may take considerable amount of time
1105 * especially for DFS cases.
1107 if (start_ctrl_iface(iface))
1110 if (hapd->iconf->country[0] && hapd->iconf->country[1]) {
1111 char country[4], previous_country[4];
1113 hostapd_set_state(iface, HAPD_IFACE_COUNTRY_UPDATE);
1114 if (hostapd_get_country(hapd, previous_country) < 0)
1115 previous_country[0] = '\0';
1117 os_memcpy(country, hapd->iconf->country, 3);
1119 if (hostapd_set_country(hapd, country) < 0) {
1120 wpa_printf(MSG_ERROR, "Failed to set country code");
1124 wpa_printf(MSG_DEBUG, "Previous country code %s, new country code %s",
1125 previous_country, country);
1127 if (os_strncmp(previous_country, country, 2) != 0) {
1128 wpa_printf(MSG_DEBUG, "Continue interface setup after channel list update");
1129 iface->wait_channel_update = 1;
1130 eloop_register_timeout(5, 0,
1131 channel_list_update_timeout,
1137 return setup_interface2(iface);
1141 static int setup_interface2(struct hostapd_iface *iface)
1143 iface->wait_channel_update = 0;
1145 if (hostapd_get_hw_features(iface)) {
1146 /* Not all drivers support this yet, so continue without hw
1149 int ret = hostapd_select_hw_mode(iface);
1151 wpa_printf(MSG_ERROR, "Could not select hw_mode and "
1152 "channel. (%d)", ret);
1156 wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback (ACS)");
1159 ret = hostapd_check_ht_capab(iface);
1163 wpa_printf(MSG_DEBUG, "Interface initialization will "
1164 "be completed in a callback");
1168 if (iface->conf->ieee80211h)
1169 wpa_printf(MSG_DEBUG, "DFS support is enabled");
1171 return hostapd_setup_interface_complete(iface, 0);
1174 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
1175 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
1176 if (iface->interfaces && iface->interfaces->terminate_on_error)
1183 * hostapd_setup_interface_complete - Complete interface setup
1185 * This function is called when previous steps in the interface setup has been
1186 * completed. This can also start operations, e.g., DFS, that will require
1187 * additional processing before interface is ready to be enabled. Such
1188 * operations will call this function from eloop callbacks when finished.
1190 int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err)
1192 struct hostapd_data *hapd = iface->bss[0];
1195 int delay_apply_cfg = 0;
1200 wpa_printf(MSG_DEBUG, "Completing interface initialization");
1201 if (iface->conf->channel) {
1204 #endif /* NEED_AP_MLME */
1206 iface->freq = hostapd_hw_get_freq(hapd, iface->conf->channel);
1207 wpa_printf(MSG_DEBUG, "Mode: %s Channel: %d "
1208 "Frequency: %d MHz",
1209 hostapd_hw_mode_txt(iface->conf->hw_mode),
1210 iface->conf->channel, iface->freq);
1213 /* Handle DFS only if it is not offloaded to the driver */
1214 if (!(iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)) {
1216 res = hostapd_handle_dfs(iface);
1223 #endif /* NEED_AP_MLME */
1226 if (iface->mconf != NULL) {
1227 wpa_printf(MSG_DEBUG,
1228 "%s: Mesh configuration will be applied while joining the mesh network",
1229 iface->bss[0]->conf->iface);
1230 delay_apply_cfg = 1;
1232 #endif /* CONFIG_MESH */
1234 if (!delay_apply_cfg &&
1235 hostapd_set_freq(hapd, hapd->iconf->hw_mode, iface->freq,
1236 hapd->iconf->channel,
1237 hapd->iconf->ieee80211n,
1238 hapd->iconf->ieee80211ac,
1239 hapd->iconf->secondary_channel,
1240 hapd->iconf->vht_oper_chwidth,
1241 hapd->iconf->vht_oper_centr_freq_seg0_idx,
1242 hapd->iconf->vht_oper_centr_freq_seg1_idx)) {
1243 wpa_printf(MSG_ERROR, "Could not set channel for "
1249 if (iface->current_mode) {
1250 if (hostapd_prepare_rates(iface, iface->current_mode)) {
1251 wpa_printf(MSG_ERROR, "Failed to prepare rates "
1253 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1254 HOSTAPD_LEVEL_WARNING,
1255 "Failed to prepare rates table.");
1260 if (hapd->iconf->rts_threshold > -1 &&
1261 hostapd_set_rts(hapd, hapd->iconf->rts_threshold)) {
1262 wpa_printf(MSG_ERROR, "Could not set RTS threshold for "
1267 if (hapd->iconf->fragm_threshold > -1 &&
1268 hostapd_set_frag(hapd, hapd->iconf->fragm_threshold)) {
1269 wpa_printf(MSG_ERROR, "Could not set fragmentation threshold "
1270 "for kernel driver");
1274 prev_addr = hapd->own_addr;
1276 for (j = 0; j < iface->num_bss; j++) {
1277 hapd = iface->bss[j];
1279 os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN);
1280 if (hostapd_setup_bss(hapd, j == 0)) {
1282 hapd = iface->bss[j];
1283 hostapd_bss_deinit_no_free(hapd);
1284 hostapd_free_hapd_data(hapd);
1288 if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0)
1289 prev_addr = hapd->own_addr;
1291 hapd = iface->bss[0];
1293 hostapd_tx_queue_params(iface);
1295 ap_list_init(iface);
1297 hostapd_set_acl(hapd);
1299 if (hostapd_driver_commit(hapd) < 0) {
1300 wpa_printf(MSG_ERROR, "%s: Failed to commit driver "
1301 "configuration", __func__);
1306 * WPS UPnP module can be initialized only when the "upnp_iface" is up.
1307 * If "interface" and "upnp_iface" are the same (e.g., non-bridge
1308 * mode), the interface is up only after driver_commit, so initialize
1309 * WPS after driver_commit.
1311 for (j = 0; j < iface->num_bss; j++) {
1312 if (hostapd_init_wps_complete(iface->bss[j]))
1316 hostapd_set_state(iface, HAPD_IFACE_ENABLED);
1317 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_ENABLED);
1318 if (hapd->setup_complete_cb)
1319 hapd->setup_complete_cb(hapd->setup_complete_cb_ctx);
1321 wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
1322 iface->bss[0]->conf->iface);
1323 if (iface->interfaces && iface->interfaces->terminate_on_error > 0)
1324 iface->interfaces->terminate_on_error--;
1329 wpa_printf(MSG_ERROR, "Interface initialization failed");
1330 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
1331 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
1332 if (iface->interfaces && iface->interfaces->terminate_on_error)
1339 * hostapd_setup_interface - Setup of an interface
1340 * @iface: Pointer to interface data.
1341 * Returns: 0 on success, -1 on failure
1343 * Initializes the driver interface, validates the configuration,
1344 * and sets driver parameters based on the configuration.
1345 * Flushes old stations, sets the channel, encryption,
1346 * beacons, and WDS links based on the configuration.
1348 * If interface setup requires more time, e.g., to perform HT co-ex scans, ACS,
1349 * or DFS operations, this function returns 0 before such operations have been
1350 * completed. The pending operations are registered into eloop and will be
1351 * completed from eloop callbacks. Those callbacks end up calling
1352 * hostapd_setup_interface_complete() once setup has been completed.
1354 int hostapd_setup_interface(struct hostapd_iface *iface)
1358 ret = setup_interface(iface);
1360 wpa_printf(MSG_ERROR, "%s: Unable to setup interface.",
1361 iface->bss[0]->conf->iface);
1370 * hostapd_alloc_bss_data - Allocate and initialize per-BSS data
1371 * @hapd_iface: Pointer to interface data
1372 * @conf: Pointer to per-interface configuration
1373 * @bss: Pointer to per-BSS configuration for this BSS
1374 * Returns: Pointer to allocated BSS data
1376 * This function is used to allocate per-BSS data structure. This data will be
1377 * freed after hostapd_cleanup() is called for it during interface
1380 struct hostapd_data *
1381 hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
1382 struct hostapd_config *conf,
1383 struct hostapd_bss_config *bss)
1385 struct hostapd_data *hapd;
1387 hapd = os_zalloc(sizeof(*hapd));
1391 hapd->new_assoc_sta_cb = hostapd_new_assoc_sta;
1394 hapd->iface = hapd_iface;
1395 hapd->driver = hapd->iconf->driver;
1396 hapd->ctrl_sock = -1;
1402 static void hostapd_bss_deinit(struct hostapd_data *hapd)
1404 wpa_printf(MSG_DEBUG, "%s: deinit bss %s", __func__,
1406 hostapd_bss_deinit_no_free(hapd);
1407 hostapd_cleanup(hapd);
1411 void hostapd_interface_deinit(struct hostapd_iface *iface)
1415 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
1419 #ifdef CONFIG_IEEE80211N
1421 hostapd_stop_setup_timers(iface);
1422 eloop_cancel_timeout(ap_ht2040_timeout, iface, NULL);
1423 #endif /* NEED_AP_MLME */
1424 #endif /* CONFIG_IEEE80211N */
1425 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
1426 iface->wait_channel_update = 0;
1428 for (j = iface->num_bss - 1; j >= 0; j--)
1429 hostapd_bss_deinit(iface->bss[j]);
1433 void hostapd_interface_free(struct hostapd_iface *iface)
1436 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
1437 for (j = 0; j < iface->num_bss; j++) {
1438 wpa_printf(MSG_DEBUG, "%s: free hapd %p",
1439 __func__, iface->bss[j]);
1440 os_free(iface->bss[j]);
1442 hostapd_cleanup_iface(iface);
1447 * hostapd_init - Allocate and initialize per-interface data
1448 * @config_file: Path to the configuration file
1449 * Returns: Pointer to the allocated interface data or %NULL on failure
1451 * This function is used to allocate main data structures for per-interface
1452 * data. The allocated data buffer will be freed by calling
1453 * hostapd_cleanup_iface().
1455 struct hostapd_iface * hostapd_init(struct hapd_interfaces *interfaces,
1456 const char *config_file)
1458 struct hostapd_iface *hapd_iface = NULL;
1459 struct hostapd_config *conf = NULL;
1460 struct hostapd_data *hapd;
1463 hapd_iface = os_zalloc(sizeof(*hapd_iface));
1464 if (hapd_iface == NULL)
1467 hapd_iface->config_fname = os_strdup(config_file);
1468 if (hapd_iface->config_fname == NULL)
1471 conf = interfaces->config_read_cb(hapd_iface->config_fname);
1474 hapd_iface->conf = conf;
1476 hapd_iface->num_bss = conf->num_bss;
1477 hapd_iface->bss = os_calloc(conf->num_bss,
1478 sizeof(struct hostapd_data *));
1479 if (hapd_iface->bss == NULL)
1482 for (i = 0; i < conf->num_bss; i++) {
1483 hapd = hapd_iface->bss[i] =
1484 hostapd_alloc_bss_data(hapd_iface, conf,
1488 hapd->msg_ctx = hapd;
1494 wpa_printf(MSG_ERROR, "Failed to set up interface with %s",
1497 hostapd_config_free(conf);
1499 os_free(hapd_iface->config_fname);
1500 os_free(hapd_iface->bss);
1501 wpa_printf(MSG_DEBUG, "%s: free iface %p",
1502 __func__, hapd_iface);
1503 os_free(hapd_iface);
1509 static int ifname_in_use(struct hapd_interfaces *interfaces, const char *ifname)
1513 for (i = 0; i < interfaces->count; i++) {
1514 struct hostapd_iface *iface = interfaces->iface[i];
1515 for (j = 0; j < iface->num_bss; j++) {
1516 struct hostapd_data *hapd = iface->bss[j];
1517 if (os_strcmp(ifname, hapd->conf->iface) == 0)
1527 * hostapd_interface_init_bss - Read configuration file and init BSS data
1529 * This function is used to parse configuration file for a BSS. This BSS is
1530 * added to an existing interface sharing the same radio (if any) or a new
1531 * interface is created if this is the first interface on a radio. This
1532 * allocate memory for the BSS. No actual driver operations are started.
1534 * This is similar to hostapd_interface_init(), but for a case where the
1535 * configuration is used to add a single BSS instead of all BSSes for a radio.
1537 struct hostapd_iface *
1538 hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy,
1539 const char *config_fname, int debug)
1541 struct hostapd_iface *new_iface = NULL, *iface = NULL;
1542 struct hostapd_data *hapd;
1549 for (i = 0; i < interfaces->count; i++) {
1550 if (os_strcmp(interfaces->iface[i]->phy, phy) == 0) {
1551 iface = interfaces->iface[i];
1556 wpa_printf(MSG_INFO, "Configuration file: %s (phy %s)%s",
1557 config_fname, phy, iface ? "" : " --> new PHY");
1559 struct hostapd_config *conf;
1560 struct hostapd_bss_config **tmp_conf;
1561 struct hostapd_data **tmp_bss;
1562 struct hostapd_bss_config *bss;
1565 /* Add new BSS to existing iface */
1566 conf = interfaces->config_read_cb(config_fname);
1569 if (conf->num_bss > 1) {
1570 wpa_printf(MSG_ERROR, "Multiple BSSes specified in BSS-config");
1571 hostapd_config_free(conf);
1575 ifname = conf->bss[0]->iface;
1576 if (ifname[0] != '\0' && ifname_in_use(interfaces, ifname)) {
1577 wpa_printf(MSG_ERROR,
1578 "Interface name %s already in use", ifname);
1579 hostapd_config_free(conf);
1583 tmp_conf = os_realloc_array(
1584 iface->conf->bss, iface->conf->num_bss + 1,
1585 sizeof(struct hostapd_bss_config *));
1586 tmp_bss = os_realloc_array(iface->bss, iface->num_bss + 1,
1587 sizeof(struct hostapd_data *));
1589 iface->bss = tmp_bss;
1591 iface->conf->bss = tmp_conf;
1592 iface->conf->last_bss = tmp_conf[0];
1594 if (tmp_bss == NULL || tmp_conf == NULL) {
1595 hostapd_config_free(conf);
1598 bss = iface->conf->bss[iface->conf->num_bss] = conf->bss[0];
1599 iface->conf->num_bss++;
1601 hapd = hostapd_alloc_bss_data(iface, iface->conf, bss);
1603 iface->conf->num_bss--;
1604 hostapd_config_free(conf);
1607 iface->conf->last_bss = bss;
1608 iface->bss[iface->num_bss] = hapd;
1609 hapd->msg_ctx = hapd;
1611 bss_idx = iface->num_bss++;
1613 conf->bss[0] = NULL;
1614 hostapd_config_free(conf);
1616 /* Add a new iface with the first BSS */
1617 new_iface = iface = hostapd_init(interfaces, config_fname);
1620 os_strlcpy(iface->phy, phy, sizeof(iface->phy));
1621 iface->interfaces = interfaces;
1625 for (k = 0; k < debug; k++) {
1626 if (iface->bss[bss_idx]->conf->logger_stdout_level > 0)
1627 iface->bss[bss_idx]->conf->logger_stdout_level--;
1630 if (iface->conf->bss[bss_idx]->iface[0] == '\0' &&
1631 !hostapd_drv_none(iface->bss[bss_idx])) {
1632 wpa_printf(MSG_ERROR, "Interface name not specified in %s",
1635 hostapd_interface_deinit_free(new_iface);
1643 void hostapd_interface_deinit_free(struct hostapd_iface *iface)
1645 const struct wpa_driver_ops *driver;
1648 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
1651 wpa_printf(MSG_DEBUG, "%s: num_bss=%u conf->num_bss=%u",
1652 __func__, (unsigned int) iface->num_bss,
1653 (unsigned int) iface->conf->num_bss);
1654 driver = iface->bss[0]->driver;
1655 drv_priv = iface->bss[0]->drv_priv;
1656 hostapd_interface_deinit(iface);
1657 wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
1658 __func__, driver, drv_priv);
1659 if (driver && driver->hapd_deinit && drv_priv) {
1660 driver->hapd_deinit(drv_priv);
1661 iface->bss[0]->drv_priv = NULL;
1663 hostapd_interface_free(iface);
1667 static void hostapd_deinit_driver(const struct wpa_driver_ops *driver,
1669 struct hostapd_iface *hapd_iface)
1673 wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
1674 __func__, driver, drv_priv);
1675 if (driver && driver->hapd_deinit && drv_priv) {
1676 driver->hapd_deinit(drv_priv);
1677 for (j = 0; j < hapd_iface->num_bss; j++) {
1678 wpa_printf(MSG_DEBUG, "%s:bss[%d]->drv_priv=%p",
1680 hapd_iface->bss[j]->drv_priv);
1681 if (hapd_iface->bss[j]->drv_priv == drv_priv)
1682 hapd_iface->bss[j]->drv_priv = NULL;
1688 int hostapd_enable_iface(struct hostapd_iface *hapd_iface)
1692 if (hapd_iface->bss[0]->drv_priv != NULL) {
1693 wpa_printf(MSG_ERROR, "Interface %s already enabled",
1694 hapd_iface->conf->bss[0]->iface);
1698 wpa_printf(MSG_DEBUG, "Enable interface %s",
1699 hapd_iface->conf->bss[0]->iface);
1701 for (j = 0; j < hapd_iface->num_bss; j++)
1702 hostapd_set_security_params(hapd_iface->conf->bss[j], 1);
1703 if (hostapd_config_check(hapd_iface->conf, 1) < 0) {
1704 wpa_printf(MSG_INFO, "Invalid configuration - cannot enable");
1708 if (hapd_iface->interfaces == NULL ||
1709 hapd_iface->interfaces->driver_init == NULL ||
1710 hapd_iface->interfaces->driver_init(hapd_iface))
1713 if (hostapd_setup_interface(hapd_iface)) {
1714 hostapd_deinit_driver(hapd_iface->bss[0]->driver,
1715 hapd_iface->bss[0]->drv_priv,
1724 int hostapd_reload_iface(struct hostapd_iface *hapd_iface)
1728 wpa_printf(MSG_DEBUG, "Reload interface %s",
1729 hapd_iface->conf->bss[0]->iface);
1730 for (j = 0; j < hapd_iface->num_bss; j++)
1731 hostapd_set_security_params(hapd_iface->conf->bss[j], 1);
1732 if (hostapd_config_check(hapd_iface->conf, 1) < 0) {
1733 wpa_printf(MSG_ERROR, "Updated configuration is invalid");
1736 hostapd_clear_old(hapd_iface);
1737 for (j = 0; j < hapd_iface->num_bss; j++)
1738 hostapd_reload_bss(hapd_iface->bss[j]);
1744 int hostapd_disable_iface(struct hostapd_iface *hapd_iface)
1747 const struct wpa_driver_ops *driver;
1750 if (hapd_iface == NULL)
1753 if (hapd_iface->bss[0]->drv_priv == NULL) {
1754 wpa_printf(MSG_INFO, "Interface %s already disabled",
1755 hapd_iface->conf->bss[0]->iface);
1759 wpa_msg(hapd_iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
1760 driver = hapd_iface->bss[0]->driver;
1761 drv_priv = hapd_iface->bss[0]->drv_priv;
1763 hapd_iface->driver_ap_teardown =
1764 !!(hapd_iface->drv_flags &
1765 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
1767 /* same as hostapd_interface_deinit without deinitializing ctrl-iface */
1768 for (j = 0; j < hapd_iface->num_bss; j++) {
1769 struct hostapd_data *hapd = hapd_iface->bss[j];
1770 hostapd_bss_deinit_no_free(hapd);
1771 hostapd_free_hapd_data(hapd);
1774 hostapd_deinit_driver(driver, drv_priv, hapd_iface);
1776 /* From hostapd_cleanup_iface: These were initialized in
1777 * hostapd_setup_interface and hostapd_setup_interface_complete
1779 hostapd_cleanup_iface_partial(hapd_iface);
1781 wpa_printf(MSG_DEBUG, "Interface %s disabled",
1782 hapd_iface->bss[0]->conf->iface);
1783 hostapd_set_state(hapd_iface, HAPD_IFACE_DISABLED);
1788 static struct hostapd_iface *
1789 hostapd_iface_alloc(struct hapd_interfaces *interfaces)
1791 struct hostapd_iface **iface, *hapd_iface;
1793 iface = os_realloc_array(interfaces->iface, interfaces->count + 1,
1794 sizeof(struct hostapd_iface *));
1797 interfaces->iface = iface;
1798 hapd_iface = interfaces->iface[interfaces->count] =
1799 os_zalloc(sizeof(*hapd_iface));
1800 if (hapd_iface == NULL) {
1801 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for "
1802 "the interface", __func__);
1805 interfaces->count++;
1806 hapd_iface->interfaces = interfaces;
1812 static struct hostapd_config *
1813 hostapd_config_alloc(struct hapd_interfaces *interfaces, const char *ifname,
1814 const char *ctrl_iface)
1816 struct hostapd_bss_config *bss;
1817 struct hostapd_config *conf;
1819 /* Allocates memory for bss and conf */
1820 conf = hostapd_config_defaults();
1822 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for "
1823 "configuration", __func__);
1827 conf->driver = wpa_drivers[0];
1828 if (conf->driver == NULL) {
1829 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
1830 hostapd_config_free(conf);
1834 bss = conf->last_bss = conf->bss[0];
1836 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
1837 bss->ctrl_interface = os_strdup(ctrl_iface);
1838 if (bss->ctrl_interface == NULL) {
1839 hostapd_config_free(conf);
1843 /* Reading configuration file skipped, will be done in SET!
1844 * From reading the configuration till the end has to be done in
1851 static struct hostapd_iface * hostapd_data_alloc(
1852 struct hapd_interfaces *interfaces, struct hostapd_config *conf)
1855 struct hostapd_iface *hapd_iface =
1856 interfaces->iface[interfaces->count - 1];
1857 struct hostapd_data *hapd;
1859 hapd_iface->conf = conf;
1860 hapd_iface->num_bss = conf->num_bss;
1862 hapd_iface->bss = os_zalloc(conf->num_bss *
1863 sizeof(struct hostapd_data *));
1864 if (hapd_iface->bss == NULL)
1867 for (i = 0; i < conf->num_bss; i++) {
1868 hapd = hapd_iface->bss[i] =
1869 hostapd_alloc_bss_data(hapd_iface, conf, conf->bss[i]);
1872 hapd->msg_ctx = hapd;
1875 hapd_iface->interfaces = interfaces;
1881 int hostapd_add_iface(struct hapd_interfaces *interfaces, char *buf)
1883 struct hostapd_config *conf = NULL;
1884 struct hostapd_iface *hapd_iface = NULL, *new_iface = NULL;
1885 struct hostapd_data *hapd;
1888 const char *conf_file = NULL, *phy_name = NULL;
1890 if (os_strncmp(buf, "bss_config=", 11) == 0) {
1892 phy_name = buf + 11;
1893 pos = os_strchr(phy_name, ':');
1898 if (!os_strlen(conf_file))
1901 hapd_iface = hostapd_interface_init_bss(interfaces, phy_name,
1905 for (j = 0; j < interfaces->count; j++) {
1906 if (interfaces->iface[j] == hapd_iface)
1909 if (j == interfaces->count) {
1910 struct hostapd_iface **tmp;
1911 tmp = os_realloc_array(interfaces->iface,
1912 interfaces->count + 1,
1913 sizeof(struct hostapd_iface *));
1915 hostapd_interface_deinit_free(hapd_iface);
1918 interfaces->iface = tmp;
1919 interfaces->iface[interfaces->count++] = hapd_iface;
1920 new_iface = hapd_iface;
1924 if (interfaces->driver_init(hapd_iface) ||
1925 hostapd_setup_interface(hapd_iface)) {
1926 interfaces->count--;
1930 /* Assign new BSS with bss[0]'s driver info */
1931 hapd = hapd_iface->bss[hapd_iface->num_bss - 1];
1932 hapd->driver = hapd_iface->bss[0]->driver;
1933 hapd->drv_priv = hapd_iface->bss[0]->drv_priv;
1934 os_memcpy(hapd->own_addr, hapd_iface->bss[0]->own_addr,
1937 if (start_ctrl_iface_bss(hapd) < 0 ||
1938 (hapd_iface->state == HAPD_IFACE_ENABLED &&
1939 hostapd_setup_bss(hapd, -1))) {
1940 hostapd_cleanup(hapd);
1941 hapd_iface->bss[hapd_iface->num_bss - 1] = NULL;
1942 hapd_iface->conf->num_bss--;
1943 hapd_iface->num_bss--;
1944 wpa_printf(MSG_DEBUG, "%s: free hapd %p %s",
1945 __func__, hapd, hapd->conf->iface);
1953 ptr = os_strchr(buf, ' ');
1958 if (os_strncmp(ptr, "config=", 7) == 0)
1959 conf_file = ptr + 7;
1961 for (i = 0; i < interfaces->count; i++) {
1962 if (!os_strcmp(interfaces->iface[i]->conf->bss[0]->iface,
1964 wpa_printf(MSG_INFO, "Cannot add interface - it "
1970 hapd_iface = hostapd_iface_alloc(interfaces);
1971 if (hapd_iface == NULL) {
1972 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
1973 "for interface", __func__);
1977 if (conf_file && interfaces->config_read_cb) {
1978 conf = interfaces->config_read_cb(conf_file);
1979 if (conf && conf->bss)
1980 os_strlcpy(conf->bss[0]->iface, buf,
1981 sizeof(conf->bss[0]->iface));
1983 conf = hostapd_config_alloc(interfaces, buf, ptr);
1984 if (conf == NULL || conf->bss == NULL) {
1985 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
1986 "for configuration", __func__);
1990 hapd_iface = hostapd_data_alloc(interfaces, conf);
1991 if (hapd_iface == NULL) {
1992 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
1993 "for hostapd", __func__);
1997 if (start_ctrl_iface(hapd_iface) < 0)
2000 wpa_printf(MSG_INFO, "Add interface '%s'", conf->bss[0]->iface);
2006 hostapd_config_free(conf);
2008 if (hapd_iface->bss) {
2009 for (i = 0; i < hapd_iface->num_bss; i++) {
2010 hapd = hapd_iface->bss[i];
2013 if (hapd_iface->interfaces &&
2014 hapd_iface->interfaces->ctrl_iface_deinit)
2015 hapd_iface->interfaces->
2016 ctrl_iface_deinit(hapd);
2017 wpa_printf(MSG_DEBUG, "%s: free hapd %p (%s)",
2018 __func__, hapd_iface->bss[i],
2021 hapd_iface->bss[i] = NULL;
2023 os_free(hapd_iface->bss);
2025 wpa_printf(MSG_DEBUG, "%s: free iface %p",
2026 __func__, hapd_iface);
2027 os_free(hapd_iface);
2033 static int hostapd_remove_bss(struct hostapd_iface *iface, unsigned int idx)
2037 wpa_printf(MSG_INFO, "Remove BSS '%s'", iface->conf->bss[idx]->iface);
2039 /* Remove hostapd_data only if it has already been initialized */
2040 if (idx < iface->num_bss) {
2041 struct hostapd_data *hapd = iface->bss[idx];
2043 hostapd_bss_deinit(hapd);
2044 wpa_printf(MSG_DEBUG, "%s: free hapd %p (%s)",
2045 __func__, hapd, hapd->conf->iface);
2046 hostapd_config_free_bss(hapd->conf);
2051 for (i = idx; i < iface->num_bss; i++)
2052 iface->bss[i] = iface->bss[i + 1];
2054 hostapd_config_free_bss(iface->conf->bss[idx]);
2055 iface->conf->bss[idx] = NULL;
2058 iface->conf->num_bss--;
2059 for (i = idx; i < iface->conf->num_bss; i++)
2060 iface->conf->bss[i] = iface->conf->bss[i + 1];
2066 int hostapd_remove_iface(struct hapd_interfaces *interfaces, char *buf)
2068 struct hostapd_iface *hapd_iface;
2071 for (i = 0; i < interfaces->count; i++) {
2072 hapd_iface = interfaces->iface[i];
2073 if (hapd_iface == NULL)
2075 if (!os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
2076 wpa_printf(MSG_INFO, "Remove interface '%s'", buf);
2077 hapd_iface->driver_ap_teardown =
2078 !!(hapd_iface->drv_flags &
2079 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
2081 hostapd_interface_deinit_free(hapd_iface);
2083 while (k < (interfaces->count - 1)) {
2084 interfaces->iface[k] =
2085 interfaces->iface[k + 1];
2088 interfaces->count--;
2092 for (j = 0; j < hapd_iface->conf->num_bss; j++) {
2093 if (!os_strcmp(hapd_iface->conf->bss[j]->iface, buf)) {
2094 hapd_iface->driver_ap_teardown =
2095 !(hapd_iface->drv_flags &
2096 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
2097 return hostapd_remove_bss(hapd_iface, j);
2106 * hostapd_new_assoc_sta - Notify that a new station associated with the AP
2107 * @hapd: Pointer to BSS data
2108 * @sta: Pointer to the associated STA data
2109 * @reassoc: 1 to indicate this was a re-association; 0 = first association
2111 * This function will be called whenever a station associates with the AP. It
2112 * can be called from ieee802_11.c for drivers that export MLME to hostapd and
2113 * from drv_callbacks.c based on driver events for drivers that take care of
2114 * management frames (IEEE 802.11 authentication and association) internally.
2116 void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
2119 if (hapd->tkip_countermeasures) {
2120 hostapd_drv_sta_deauth(hapd, sta->addr,
2121 WLAN_REASON_MICHAEL_MIC_FAILURE);
2125 hostapd_prune_associations(hapd, sta->addr);
2127 /* IEEE 802.11F (IAPP) */
2128 if (hapd->conf->ieee802_11f)
2129 iapp_new_station(hapd->iapp, sta);
2132 if (sta->p2p_ie == NULL && !sta->no_p2p_set) {
2133 sta->no_p2p_set = 1;
2134 hapd->num_sta_no_p2p++;
2135 if (hapd->num_sta_no_p2p == 1)
2136 hostapd_p2p_non_p2p_sta_connected(hapd);
2138 #endif /* CONFIG_P2P */
2140 /* Start accounting here, if IEEE 802.1X and WPA are not used.
2141 * IEEE 802.1X/WPA code will start accounting after the station has
2142 * been authorized. */
2143 if (!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) {
2144 ap_sta_set_authorized(hapd, sta, 1);
2145 os_get_reltime(&sta->connected_time);
2146 accounting_sta_start(hapd, sta);
2149 /* Start IEEE 802.1X authentication process for new stations */
2150 ieee802_1x_new_station(hapd, sta);
2152 if (sta->auth_alg != WLAN_AUTH_FT &&
2153 !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)))
2154 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH);
2156 wpa_auth_sta_associated(hapd->wpa_auth, sta->wpa_sm);
2158 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) {
2159 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
2160 "for " MACSTR " (%d seconds - ap_max_inactivity)",
2161 __func__, MAC2STR(sta->addr),
2162 hapd->conf->ap_max_inactivity);
2163 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
2164 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
2165 ap_handle_timer, hapd, sta);
2170 const char * hostapd_state_text(enum hostapd_iface_state s)
2173 case HAPD_IFACE_UNINITIALIZED:
2174 return "UNINITIALIZED";
2175 case HAPD_IFACE_DISABLED:
2177 case HAPD_IFACE_COUNTRY_UPDATE:
2178 return "COUNTRY_UPDATE";
2179 case HAPD_IFACE_ACS:
2181 case HAPD_IFACE_HT_SCAN:
2183 case HAPD_IFACE_DFS:
2185 case HAPD_IFACE_ENABLED:
2193 void hostapd_set_state(struct hostapd_iface *iface, enum hostapd_iface_state s)
2195 wpa_printf(MSG_INFO, "%s: interface state %s->%s",
2196 iface->conf->bss[0]->iface, hostapd_state_text(iface->state),
2197 hostapd_state_text(s));
2204 static void free_beacon_data(struct beacon_data *beacon)
2206 os_free(beacon->head);
2207 beacon->head = NULL;
2208 os_free(beacon->tail);
2209 beacon->tail = NULL;
2210 os_free(beacon->probe_resp);
2211 beacon->probe_resp = NULL;
2212 os_free(beacon->beacon_ies);
2213 beacon->beacon_ies = NULL;
2214 os_free(beacon->proberesp_ies);
2215 beacon->proberesp_ies = NULL;
2216 os_free(beacon->assocresp_ies);
2217 beacon->assocresp_ies = NULL;
2221 static int hostapd_build_beacon_data(struct hostapd_data *hapd,
2222 struct beacon_data *beacon)
2224 struct wpabuf *beacon_extra, *proberesp_extra, *assocresp_extra;
2225 struct wpa_driver_ap_params params;
2228 os_memset(beacon, 0, sizeof(*beacon));
2229 ret = ieee802_11_build_ap_params(hapd, ¶ms);
2233 ret = hostapd_build_ap_extra_ies(hapd, &beacon_extra,
2237 goto free_ap_params;
2240 beacon->head = os_malloc(params.head_len);
2242 goto free_ap_extra_ies;
2244 os_memcpy(beacon->head, params.head, params.head_len);
2245 beacon->head_len = params.head_len;
2247 beacon->tail = os_malloc(params.tail_len);
2251 os_memcpy(beacon->tail, params.tail, params.tail_len);
2252 beacon->tail_len = params.tail_len;
2254 if (params.proberesp != NULL) {
2255 beacon->probe_resp = os_malloc(params.proberesp_len);
2256 if (!beacon->probe_resp)
2259 os_memcpy(beacon->probe_resp, params.proberesp,
2260 params.proberesp_len);
2261 beacon->probe_resp_len = params.proberesp_len;
2264 /* copy the extra ies */
2266 beacon->beacon_ies = os_malloc(wpabuf_len(beacon_extra));
2267 if (!beacon->beacon_ies)
2270 os_memcpy(beacon->beacon_ies,
2271 beacon_extra->buf, wpabuf_len(beacon_extra));
2272 beacon->beacon_ies_len = wpabuf_len(beacon_extra);
2275 if (proberesp_extra) {
2276 beacon->proberesp_ies =
2277 os_malloc(wpabuf_len(proberesp_extra));
2278 if (!beacon->proberesp_ies)
2281 os_memcpy(beacon->proberesp_ies, proberesp_extra->buf,
2282 wpabuf_len(proberesp_extra));
2283 beacon->proberesp_ies_len = wpabuf_len(proberesp_extra);
2286 if (assocresp_extra) {
2287 beacon->assocresp_ies =
2288 os_malloc(wpabuf_len(assocresp_extra));
2289 if (!beacon->assocresp_ies)
2292 os_memcpy(beacon->assocresp_ies, assocresp_extra->buf,
2293 wpabuf_len(assocresp_extra));
2294 beacon->assocresp_ies_len = wpabuf_len(assocresp_extra);
2299 /* if the function fails, the caller should not free beacon data */
2301 free_beacon_data(beacon);
2304 hostapd_free_ap_extra_ies(hapd, beacon_extra, proberesp_extra,
2307 ieee802_11_free_ap_params(¶ms);
2313 * TODO: This flow currently supports only changing frequency within the
2314 * same hw_mode. Any other changes to MAC parameters or provided settings (even
2315 * width) are not supported.
2317 static int hostapd_change_config_freq(struct hostapd_data *hapd,
2318 struct hostapd_config *conf,
2319 struct hostapd_freq_params *params,
2320 struct hostapd_freq_params *old_params)
2324 if (!params->channel) {
2325 /* check if the new channel is supported by hw */
2326 params->channel = hostapd_hw_get_channel(hapd, params->freq);
2329 channel = params->channel;
2333 /* if a pointer to old_params is provided we save previous state */
2335 old_params->channel = conf->channel;
2336 old_params->ht_enabled = conf->ieee80211n;
2337 old_params->sec_channel_offset = conf->secondary_channel;
2340 conf->channel = channel;
2341 conf->ieee80211n = params->ht_enabled;
2342 conf->secondary_channel = params->sec_channel_offset;
2344 /* TODO: maybe call here hostapd_config_check here? */
2350 static int hostapd_fill_csa_settings(struct hostapd_data *hapd,
2351 struct csa_settings *settings)
2353 struct hostapd_iface *iface = hapd->iface;
2354 struct hostapd_freq_params old_freq;
2357 os_memset(&old_freq, 0, sizeof(old_freq));
2358 if (!iface || !iface->freq || hapd->csa_in_progress)
2361 ret = hostapd_change_config_freq(iface->bss[0], iface->conf,
2362 &settings->freq_params,
2367 ret = hostapd_build_beacon_data(hapd, &settings->beacon_after);
2369 /* change back the configuration */
2370 hostapd_change_config_freq(iface->bss[0], iface->conf,
2376 /* set channel switch parameters for csa ie */
2377 hapd->cs_freq_params = settings->freq_params;
2378 hapd->cs_count = settings->cs_count;
2379 hapd->cs_block_tx = settings->block_tx;
2381 ret = hostapd_build_beacon_data(hapd, &settings->beacon_csa);
2383 free_beacon_data(&settings->beacon_after);
2387 settings->counter_offset_beacon = hapd->cs_c_off_beacon;
2388 settings->counter_offset_presp = hapd->cs_c_off_proberesp;
2394 void hostapd_cleanup_cs_params(struct hostapd_data *hapd)
2396 os_memset(&hapd->cs_freq_params, 0, sizeof(hapd->cs_freq_params));
2398 hapd->cs_block_tx = 0;
2399 hapd->cs_c_off_beacon = 0;
2400 hapd->cs_c_off_proberesp = 0;
2401 hapd->csa_in_progress = 0;
2405 int hostapd_switch_channel(struct hostapd_data *hapd,
2406 struct csa_settings *settings)
2410 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA)) {
2411 wpa_printf(MSG_INFO, "CSA is not supported");
2415 ret = hostapd_fill_csa_settings(hapd, settings);
2419 ret = hostapd_drv_switch_channel(hapd, settings);
2420 free_beacon_data(&settings->beacon_csa);
2421 free_beacon_data(&settings->beacon_after);
2424 /* if we failed, clean cs parameters */
2425 hostapd_cleanup_cs_params(hapd);
2429 hapd->csa_in_progress = 1;
2435 hostapd_switch_channel_fallback(struct hostapd_iface *iface,
2436 const struct hostapd_freq_params *freq_params)
2438 int vht_seg0_idx = 0, vht_seg1_idx = 0, vht_bw = VHT_CHANWIDTH_USE_HT;
2441 wpa_printf(MSG_DEBUG, "Restarting all CSA-related BSSes");
2443 if (freq_params->center_freq1)
2444 vht_seg0_idx = 36 + (freq_params->center_freq1 - 5180) / 5;
2445 if (freq_params->center_freq2)
2446 vht_seg1_idx = 36 + (freq_params->center_freq2 - 5180) / 5;
2448 switch (freq_params->bandwidth) {
2452 vht_bw = VHT_CHANWIDTH_USE_HT;
2455 if (freq_params->center_freq2)
2456 vht_bw = VHT_CHANWIDTH_80P80MHZ;
2458 vht_bw = VHT_CHANWIDTH_80MHZ;
2461 vht_bw = VHT_CHANWIDTH_160MHZ;
2464 wpa_printf(MSG_WARNING, "Unknown CSA bandwidth: %d",
2465 freq_params->bandwidth);
2469 iface->freq = freq_params->freq;
2470 iface->conf->channel = freq_params->channel;
2471 iface->conf->secondary_channel = freq_params->sec_channel_offset;
2472 iface->conf->vht_oper_centr_freq_seg0_idx = vht_seg0_idx;
2473 iface->conf->vht_oper_centr_freq_seg1_idx = vht_seg1_idx;
2474 iface->conf->vht_oper_chwidth = vht_bw;
2475 iface->conf->ieee80211n = freq_params->ht_enabled;
2476 iface->conf->ieee80211ac = freq_params->vht_enabled;
2479 * cs_params must not be cleared earlier because the freq_params
2480 * argument may actually point to one of these.
2482 for (i = 0; i < iface->num_bss; i++)
2483 hostapd_cleanup_cs_params(iface->bss[i]);
2485 hostapd_disable_iface(iface);
2486 hostapd_enable_iface(iface);
2489 #endif /* NEED_AP_MLME */