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 "common/hw_features_common.h"
16 #include "radius/radius_client.h"
17 #include "radius/radius_das.h"
18 #include "eap_server/tncs.h"
19 #include "eapol_auth/eapol_auth_sm.h"
20 #include "eapol_auth/eapol_auth_sm_i.h"
25 #include "accounting.h"
29 #include "ieee802_1x.h"
30 #include "ieee802_11_auth.h"
31 #include "vlan_init.h"
33 #include "wps_hostapd.h"
34 #include "hw_features.h"
35 #include "wpa_auth_glue.h"
36 #include "ap_drv_ops.h"
37 #include "ap_config.h"
38 #include "p2p_hostapd.h"
41 #include "ieee802_11.h"
44 #include "dhcp_snoop.h"
45 #include "ndisc_snoop.h"
46 #include "neighbor_db.h"
50 static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason);
51 static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd);
52 static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd);
53 static int setup_interface2(struct hostapd_iface *iface);
54 static void channel_list_update_timeout(void *eloop_ctx, void *timeout_ctx);
57 int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
58 int (*cb)(struct hostapd_iface *iface,
59 void *ctx), void *ctx)
64 for (i = 0; i < interfaces->count; i++) {
65 ret = cb(interfaces->iface[i], ctx);
74 static void hostapd_reload_bss(struct hostapd_data *hapd)
76 struct hostapd_ssid *ssid;
78 #ifndef CONFIG_NO_RADIUS
79 radius_client_reconfig(hapd->radius, hapd->conf->radius);
80 #endif /* CONFIG_NO_RADIUS */
82 ssid = &hapd->conf->ssid;
83 if (!ssid->wpa_psk_set && ssid->wpa_psk && !ssid->wpa_psk->next &&
84 ssid->wpa_passphrase_set && ssid->wpa_passphrase) {
86 * Force PSK to be derived again since SSID or passphrase may
89 hostapd_config_clear_wpa_psk(&hapd->conf->ssid.wpa_psk);
91 if (hostapd_setup_wpa_psk(hapd->conf)) {
92 wpa_printf(MSG_ERROR, "Failed to re-configure WPA PSK "
93 "after reloading configuration");
96 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
97 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1);
99 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0);
101 if ((hapd->conf->wpa || hapd->conf->osen) && hapd->wpa_auth == NULL) {
102 hostapd_setup_wpa(hapd);
104 wpa_init_keys(hapd->wpa_auth);
105 } else if (hapd->conf->wpa) {
108 hostapd_reconfig_wpa(hapd);
109 wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
110 if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len))
111 wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
112 "the kernel driver.");
113 } else if (hapd->wpa_auth) {
114 wpa_deinit(hapd->wpa_auth);
115 hapd->wpa_auth = NULL;
116 hostapd_set_privacy(hapd, 0);
117 hostapd_setup_encryption(hapd->conf->iface, hapd);
118 hostapd_set_generic_elem(hapd, (u8 *) "", 0);
121 ieee802_11_set_beacon(hapd);
122 hostapd_update_wps(hapd);
124 if (hapd->conf->ssid.ssid_set &&
125 hostapd_set_ssid(hapd, hapd->conf->ssid.ssid,
126 hapd->conf->ssid.ssid_len)) {
127 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
128 /* try to continue */
130 wpa_printf(MSG_DEBUG, "Reconfigured interface %s", hapd->conf->iface);
134 static void hostapd_clear_old(struct hostapd_iface *iface)
139 * Deauthenticate all stations since the new configuration may not
140 * allow them to use the BSS anymore.
142 for (j = 0; j < iface->num_bss; j++) {
143 hostapd_flush_old_stations(iface->bss[j],
144 WLAN_REASON_PREV_AUTH_NOT_VALID);
145 hostapd_broadcast_wep_clear(iface->bss[j]);
147 #ifndef CONFIG_NO_RADIUS
148 /* TODO: update dynamic data based on changed configuration
149 * items (e.g., open/close sockets, etc.) */
150 radius_client_flush(iface->bss[j]->radius, 0);
151 #endif /* CONFIG_NO_RADIUS */
156 int hostapd_reload_config(struct hostapd_iface *iface)
158 struct hostapd_data *hapd = iface->bss[0];
159 struct hostapd_config *newconf, *oldconf;
162 if (iface->config_fname == NULL) {
163 /* Only in-memory config in use - assume it has been updated */
164 hostapd_clear_old(iface);
165 for (j = 0; j < iface->num_bss; j++)
166 hostapd_reload_bss(iface->bss[j]);
170 if (iface->interfaces == NULL ||
171 iface->interfaces->config_read_cb == NULL)
173 newconf = iface->interfaces->config_read_cb(iface->config_fname);
177 hostapd_clear_old(iface);
179 oldconf = hapd->iconf;
180 iface->conf = newconf;
182 for (j = 0; j < iface->num_bss; j++) {
183 hapd = iface->bss[j];
184 hapd->iconf = newconf;
185 hapd->iconf->channel = oldconf->channel;
186 hapd->iconf->acs = oldconf->acs;
187 hapd->iconf->secondary_channel = oldconf->secondary_channel;
188 hapd->iconf->ieee80211n = oldconf->ieee80211n;
189 hapd->iconf->ieee80211ac = oldconf->ieee80211ac;
190 hapd->iconf->ht_capab = oldconf->ht_capab;
191 hapd->iconf->vht_capab = oldconf->vht_capab;
192 hapd->iconf->vht_oper_chwidth = oldconf->vht_oper_chwidth;
193 hapd->iconf->vht_oper_centr_freq_seg0_idx =
194 oldconf->vht_oper_centr_freq_seg0_idx;
195 hapd->iconf->vht_oper_centr_freq_seg1_idx =
196 oldconf->vht_oper_centr_freq_seg1_idx;
197 hapd->conf = newconf->bss[j];
198 hostapd_reload_bss(hapd);
201 hostapd_config_free(oldconf);
208 static void hostapd_broadcast_key_clear_iface(struct hostapd_data *hapd,
213 for (i = 0; i < NUM_WEP_KEYS; i++) {
214 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE, NULL, i,
215 0, NULL, 0, NULL, 0)) {
216 wpa_printf(MSG_DEBUG, "Failed to clear default "
217 "encryption keys (ifname=%s keyidx=%d)",
221 #ifdef CONFIG_IEEE80211W
222 if (hapd->conf->ieee80211w) {
223 for (i = NUM_WEP_KEYS; i < NUM_WEP_KEYS + 2; i++) {
224 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE,
227 wpa_printf(MSG_DEBUG, "Failed to clear "
228 "default mgmt encryption keys "
229 "(ifname=%s keyidx=%d)", ifname, i);
233 #endif /* CONFIG_IEEE80211W */
237 static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd)
239 hostapd_broadcast_key_clear_iface(hapd, hapd->conf->iface);
244 static int hostapd_broadcast_wep_set(struct hostapd_data *hapd)
247 struct hostapd_ssid *ssid = &hapd->conf->ssid;
250 if (ssid->wep.default_len &&
251 hostapd_drv_set_key(hapd->conf->iface,
252 hapd, WPA_ALG_WEP, broadcast_ether_addr, idx,
253 1, NULL, 0, ssid->wep.key[idx],
254 ssid->wep.len[idx])) {
255 wpa_printf(MSG_WARNING, "Could not set WEP encryption.");
263 static void hostapd_free_hapd_data(struct hostapd_data *hapd)
265 os_free(hapd->probereq_cb);
266 hapd->probereq_cb = NULL;
267 hapd->num_probereq_cb = 0;
270 wpabuf_free(hapd->p2p_beacon_ie);
271 hapd->p2p_beacon_ie = NULL;
272 wpabuf_free(hapd->p2p_probe_resp_ie);
273 hapd->p2p_probe_resp_ie = NULL;
274 #endif /* CONFIG_P2P */
276 if (!hapd->started) {
277 wpa_printf(MSG_ERROR, "%s: Interface %s wasn't started",
278 __func__, hapd->conf->iface);
283 wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
284 iapp_deinit(hapd->iapp);
286 accounting_deinit(hapd);
287 hostapd_deinit_wpa(hapd);
289 hostapd_acl_deinit(hapd);
290 #ifndef CONFIG_NO_RADIUS
291 radius_client_deinit(hapd->radius);
293 radius_das_deinit(hapd->radius_das);
294 hapd->radius_das = NULL;
295 #endif /* CONFIG_NO_RADIUS */
297 hostapd_deinit_wps(hapd);
299 authsrv_deinit(hapd);
301 if (hapd->interface_added) {
302 hapd->interface_added = 0;
303 if (hostapd_if_remove(hapd, WPA_IF_AP_BSS, hapd->conf->iface)) {
304 wpa_printf(MSG_WARNING,
305 "Failed to remove BSS interface %s",
307 hapd->interface_added = 1;
310 * Since this was a dynamically added interface, the
311 * driver wrapper may have removed its internal instance
312 * and hapd->drv_priv is not valid anymore.
314 hapd->drv_priv = NULL;
318 wpabuf_free(hapd->time_adv);
320 #ifdef CONFIG_INTERWORKING
321 gas_serv_deinit(hapd);
322 #endif /* CONFIG_INTERWORKING */
324 bss_load_update_deinit(hapd);
325 ndisc_snoop_deinit(hapd);
326 dhcp_snoop_deinit(hapd);
327 x_snoop_deinit(hapd);
330 bin_clear_free(hapd->tmp_eap_user.identity,
331 hapd->tmp_eap_user.identity_len);
332 bin_clear_free(hapd->tmp_eap_user.password,
333 hapd->tmp_eap_user.password_len);
334 #endif /* CONFIG_SQLITE */
337 wpabuf_free(hapd->mesh_pending_auth);
338 hapd->mesh_pending_auth = NULL;
339 #endif /* CONFIG_MESH */
341 hostapd_clean_rrm(hapd);
346 * hostapd_cleanup - Per-BSS cleanup (deinitialization)
347 * @hapd: Pointer to BSS data
349 * This function is used to free all per-BSS data structures and resources.
350 * Most of the modules that are initialized in hostapd_setup_bss() are
351 * deinitialized here.
353 static void hostapd_cleanup(struct hostapd_data *hapd)
355 wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s))", __func__, hapd,
357 if (hapd->iface->interfaces &&
358 hapd->iface->interfaces->ctrl_iface_deinit)
359 hapd->iface->interfaces->ctrl_iface_deinit(hapd);
360 hostapd_free_hapd_data(hapd);
364 static void sta_track_deinit(struct hostapd_iface *iface)
366 struct hostapd_sta_info *info;
368 if (!iface->num_sta_seen)
371 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
373 dl_list_del(&info->list);
374 iface->num_sta_seen--;
380 static void hostapd_cleanup_iface_partial(struct hostapd_iface *iface)
382 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
383 #ifdef CONFIG_IEEE80211N
385 hostapd_stop_setup_timers(iface);
386 #endif /* NEED_AP_MLME */
387 #endif /* CONFIG_IEEE80211N */
388 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
389 iface->hw_features = NULL;
390 os_free(iface->current_rates);
391 iface->current_rates = NULL;
392 os_free(iface->basic_rates);
393 iface->basic_rates = NULL;
394 ap_list_deinit(iface);
395 sta_track_deinit(iface);
400 * hostapd_cleanup_iface - Complete per-interface cleanup
401 * @iface: Pointer to interface data
403 * This function is called after per-BSS data structures are deinitialized
404 * with hostapd_cleanup().
406 static void hostapd_cleanup_iface(struct hostapd_iface *iface)
408 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
409 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
411 hostapd_cleanup_iface_partial(iface);
412 hostapd_config_free(iface->conf);
415 os_free(iface->config_fname);
417 wpa_printf(MSG_DEBUG, "%s: free iface=%p", __func__, iface);
422 static void hostapd_clear_wep(struct hostapd_data *hapd)
424 if (hapd->drv_priv && !hapd->iface->driver_ap_teardown) {
425 hostapd_set_privacy(hapd, 0);
426 hostapd_broadcast_wep_clear(hapd);
431 static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd)
435 hostapd_broadcast_wep_set(hapd);
437 if (hapd->conf->ssid.wep.default_len) {
438 hostapd_set_privacy(hapd, 1);
443 * When IEEE 802.1X is not enabled, the driver may need to know how to
444 * set authentication algorithms for static WEP.
446 hostapd_drv_set_authmode(hapd, hapd->conf->auth_algs);
448 for (i = 0; i < 4; i++) {
449 if (hapd->conf->ssid.wep.key[i] &&
450 hostapd_drv_set_key(iface, hapd, WPA_ALG_WEP, NULL, i,
451 i == hapd->conf->ssid.wep.idx, NULL, 0,
452 hapd->conf->ssid.wep.key[i],
453 hapd->conf->ssid.wep.len[i])) {
454 wpa_printf(MSG_WARNING, "Could not set WEP "
458 if (hapd->conf->ssid.wep.key[i] &&
459 i == hapd->conf->ssid.wep.idx)
460 hostapd_set_privacy(hapd, 1);
467 static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason)
472 if (hostapd_drv_none(hapd) || hapd->drv_priv == NULL)
475 if (!hapd->iface->driver_ap_teardown) {
476 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
477 "Flushing old station entries");
479 if (hostapd_flush(hapd)) {
480 wpa_msg(hapd->msg_ctx, MSG_WARNING,
481 "Could not connect to kernel driver");
485 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "Deauthenticate all stations");
486 os_memset(addr, 0xff, ETH_ALEN);
487 hostapd_drv_sta_deauth(hapd, addr, reason);
488 hostapd_free_stas(hapd);
494 static void hostapd_bss_deinit_no_free(struct hostapd_data *hapd)
496 hostapd_free_stas(hapd);
497 hostapd_flush_old_stations(hapd, WLAN_REASON_DEAUTH_LEAVING);
498 hostapd_clear_wep(hapd);
503 * hostapd_validate_bssid_configuration - Validate BSSID configuration
504 * @iface: Pointer to interface data
505 * Returns: 0 on success, -1 on failure
507 * This function is used to validate that the configured BSSIDs are valid.
509 static int hostapd_validate_bssid_configuration(struct hostapd_iface *iface)
511 u8 mask[ETH_ALEN] = { 0 };
512 struct hostapd_data *hapd = iface->bss[0];
513 unsigned int i = iface->conf->num_bss, bits = 0, j;
516 if (hostapd_drv_none(hapd))
519 if (iface->conf->use_driver_iface_addr)
522 /* Generate BSSID mask that is large enough to cover the BSSIDs. */
524 /* Determine the bits necessary to cover the number of BSSIDs. */
525 for (i--; i; i >>= 1)
528 /* Determine the bits necessary to any configured BSSIDs,
529 if they are higher than the number of BSSIDs. */
530 for (j = 0; j < iface->conf->num_bss; j++) {
531 if (is_zero_ether_addr(iface->conf->bss[j]->bssid)) {
537 for (i = 0; i < ETH_ALEN; i++) {
539 iface->conf->bss[j]->bssid[i] ^
547 for (i = 0; i < ETH_ALEN && mask[i] == 0; i++)
553 while (mask[i] != 0) {
563 wpa_printf(MSG_ERROR, "Too many bits in the BSSID mask (%u)",
568 os_memset(mask, 0xff, ETH_ALEN);
570 for (i = 5; i > 5 - j; i--)
577 wpa_printf(MSG_DEBUG, "BSS count %lu, BSSID mask " MACSTR " (%d bits)",
578 (unsigned long) iface->conf->num_bss, MAC2STR(mask), bits);
583 for (i = 0; i < ETH_ALEN; i++) {
584 if ((hapd->own_addr[i] & mask[i]) != hapd->own_addr[i]) {
585 wpa_printf(MSG_ERROR, "Invalid BSSID mask " MACSTR
586 " for start address " MACSTR ".",
587 MAC2STR(mask), MAC2STR(hapd->own_addr));
588 wpa_printf(MSG_ERROR, "Start address must be the "
589 "first address in the block (i.e., addr "
590 "AND mask == addr).");
599 static int mac_in_conf(struct hostapd_config *conf, const void *a)
603 for (i = 0; i < conf->num_bss; i++) {
604 if (hostapd_mac_comp(conf->bss[i]->bssid, a) == 0) {
613 #ifndef CONFIG_NO_RADIUS
615 static int hostapd_das_nas_mismatch(struct hostapd_data *hapd,
616 struct radius_das_attrs *attr)
618 if (attr->nas_identifier &&
619 (!hapd->conf->nas_identifier ||
620 os_strlen(hapd->conf->nas_identifier) !=
621 attr->nas_identifier_len ||
622 os_memcmp(hapd->conf->nas_identifier, attr->nas_identifier,
623 attr->nas_identifier_len) != 0)) {
624 wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-Identifier mismatch");
628 if (attr->nas_ip_addr &&
629 (hapd->conf->own_ip_addr.af != AF_INET ||
630 os_memcmp(&hapd->conf->own_ip_addr.u.v4, attr->nas_ip_addr, 4) !=
632 wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-IP-Address mismatch");
637 if (attr->nas_ipv6_addr &&
638 (hapd->conf->own_ip_addr.af != AF_INET6 ||
639 os_memcmp(&hapd->conf->own_ip_addr.u.v6, attr->nas_ipv6_addr, 16)
641 wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-IPv6-Address mismatch");
644 #endif /* CONFIG_IPV6 */
650 static struct sta_info * hostapd_das_find_sta(struct hostapd_data *hapd,
651 struct radius_das_attrs *attr,
654 struct sta_info *selected, *sta;
661 for (sta = hapd->sta_list; sta; sta = sta->next)
662 sta->radius_das_match = 1;
664 if (attr->sta_addr) {
666 sta = ap_get_sta(hapd, attr->sta_addr);
668 wpa_printf(MSG_DEBUG,
669 "RADIUS DAS: No Calling-Station-Id match");
674 for (sta = hapd->sta_list; sta; sta = sta->next) {
676 sta->radius_das_match = 0;
678 wpa_printf(MSG_DEBUG, "RADIUS DAS: Calling-Station-Id match");
681 if (attr->acct_session_id) {
683 if (attr->acct_session_id_len != 16) {
684 wpa_printf(MSG_DEBUG,
685 "RADIUS DAS: Acct-Session-Id cannot match");
690 for (sta = hapd->sta_list; sta; sta = sta->next) {
691 if (!sta->radius_das_match)
693 os_snprintf(buf, sizeof(buf), "%016llX",
694 (unsigned long long) sta->acct_session_id);
695 if (os_memcmp(attr->acct_session_id, buf, 16) != 0)
696 sta->radius_das_match = 0;
702 wpa_printf(MSG_DEBUG,
703 "RADIUS DAS: No matches remaining after Acct-Session-Id check");
706 wpa_printf(MSG_DEBUG, "RADIUS DAS: Acct-Session-Id match");
709 if (attr->acct_multi_session_id) {
711 if (attr->acct_multi_session_id_len != 16) {
712 wpa_printf(MSG_DEBUG,
713 "RADIUS DAS: Acct-Multi-Session-Id cannot match");
718 for (sta = hapd->sta_list; sta; sta = sta->next) {
719 if (!sta->radius_das_match)
721 if (!sta->eapol_sm ||
722 !sta->eapol_sm->acct_multi_session_id) {
723 sta->radius_das_match = 0;
726 os_snprintf(buf, sizeof(buf), "%016llX",
728 sta->eapol_sm->acct_multi_session_id);
729 if (os_memcmp(attr->acct_multi_session_id, buf, 16) !=
731 sta->radius_das_match = 0;
737 wpa_printf(MSG_DEBUG,
738 "RADIUS DAS: No matches remaining after Acct-Multi-Session-Id check");
741 wpa_printf(MSG_DEBUG,
742 "RADIUS DAS: Acct-Multi-Session-Id match");
749 for (sta = hapd->sta_list; sta; sta = sta->next) {
752 if (!sta->radius_das_match)
754 cui = ieee802_1x_get_radius_cui(sta->eapol_sm);
755 if (!cui || wpabuf_len(cui) != attr->cui_len ||
756 os_memcmp(wpabuf_head(cui), attr->cui,
758 sta->radius_das_match = 0;
764 wpa_printf(MSG_DEBUG,
765 "RADIUS DAS: No matches remaining after Chargeable-User-Identity check");
768 wpa_printf(MSG_DEBUG,
769 "RADIUS DAS: Chargeable-User-Identity match");
772 if (attr->user_name) {
776 for (sta = hapd->sta_list; sta; sta = sta->next) {
780 if (!sta->radius_das_match)
782 identity = ieee802_1x_get_identity(sta->eapol_sm,
785 identity_len != attr->user_name_len ||
786 os_memcmp(identity, attr->user_name, identity_len)
788 sta->radius_das_match = 0;
794 wpa_printf(MSG_DEBUG,
795 "RADIUS DAS: No matches remaining after User-Name check");
798 wpa_printf(MSG_DEBUG,
799 "RADIUS DAS: User-Name match");
804 * In theory, we could match all current associations, but it
805 * seems safer to just reject requests that do not include any
806 * session identification attributes.
808 wpa_printf(MSG_DEBUG,
809 "RADIUS DAS: No session identification attributes included");
814 for (sta = hapd->sta_list; sta; sta = sta->next) {
815 if (sta->radius_das_match) {
828 static int hostapd_das_disconnect_pmksa(struct hostapd_data *hapd,
829 struct radius_das_attrs *attr)
833 return wpa_auth_radius_das_disconnect_pmksa(hapd->wpa_auth, attr);
837 static enum radius_das_res
838 hostapd_das_disconnect(void *ctx, struct radius_das_attrs *attr)
840 struct hostapd_data *hapd = ctx;
841 struct sta_info *sta;
844 if (hostapd_das_nas_mismatch(hapd, attr))
845 return RADIUS_DAS_NAS_MISMATCH;
847 sta = hostapd_das_find_sta(hapd, attr, &multi);
850 wpa_printf(MSG_DEBUG,
851 "RADIUS DAS: Multiple sessions match - not supported");
852 return RADIUS_DAS_MULTI_SESSION_MATCH;
854 if (hostapd_das_disconnect_pmksa(hapd, attr) == 0) {
855 wpa_printf(MSG_DEBUG,
856 "RADIUS DAS: PMKSA cache entry matched");
857 return RADIUS_DAS_SUCCESS;
859 wpa_printf(MSG_DEBUG, "RADIUS DAS: No matching session found");
860 return RADIUS_DAS_SESSION_NOT_FOUND;
863 wpa_printf(MSG_DEBUG, "RADIUS DAS: Found a matching session " MACSTR
864 " - disconnecting", MAC2STR(sta->addr));
865 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
867 hostapd_drv_sta_deauth(hapd, sta->addr,
868 WLAN_REASON_PREV_AUTH_NOT_VALID);
869 ap_sta_deauthenticate(hapd, sta, WLAN_REASON_PREV_AUTH_NOT_VALID);
871 return RADIUS_DAS_SUCCESS;
874 #endif /* CONFIG_NO_RADIUS */
878 * hostapd_setup_bss - Per-BSS setup (initialization)
879 * @hapd: Pointer to BSS data
880 * @first: Whether this BSS is the first BSS of an interface; -1 = not first,
881 * but interface may exist
883 * This function is used to initialize all per-BSS data structures and
884 * resources. This gets called in a loop for each BSS when an interface is
885 * initialized. Most of the modules that are initialized here will be
886 * deinitialized in hostapd_cleanup().
888 static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
890 struct hostapd_bss_config *conf = hapd->conf;
891 u8 ssid[SSID_MAX_LEN + 1];
892 int ssid_len, set_ssid;
893 char force_ifname[IFNAMSIZ];
894 u8 if_addr[ETH_ALEN];
895 int flush_old_stations = 1;
897 wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s), first=%d)",
898 __func__, hapd, conf->iface, first);
900 #ifdef EAP_SERVER_TNC
901 if (conf->tnc && tncs_global_init() < 0) {
902 wpa_printf(MSG_ERROR, "Failed to initialize TNCS");
905 #endif /* EAP_SERVER_TNC */
908 wpa_printf(MSG_ERROR, "%s: Interface %s was already started",
909 __func__, conf->iface);
913 dl_list_init(&hapd->nr_db);
915 if (!first || first == -1) {
916 u8 *addr = hapd->own_addr;
918 if (!is_zero_ether_addr(conf->bssid)) {
919 /* Allocate the configured BSSID. */
920 os_memcpy(hapd->own_addr, conf->bssid, ETH_ALEN);
922 if (hostapd_mac_comp(hapd->own_addr,
923 hapd->iface->bss[0]->own_addr) ==
925 wpa_printf(MSG_ERROR, "BSS '%s' may not have "
926 "BSSID set to the MAC address of "
927 "the radio", conf->iface);
930 } else if (hapd->iconf->use_driver_iface_addr) {
933 /* Allocate the next available BSSID. */
935 inc_byte_array(hapd->own_addr, ETH_ALEN);
936 } while (mac_in_conf(hapd->iconf, hapd->own_addr));
939 hapd->interface_added = 1;
940 if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS,
941 conf->iface, addr, hapd,
942 &hapd->drv_priv, force_ifname, if_addr,
943 conf->bridge[0] ? conf->bridge : NULL,
945 wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
946 MACSTR ")", MAC2STR(hapd->own_addr));
947 hapd->interface_added = 0;
952 os_memcpy(hapd->own_addr, if_addr, ETH_ALEN);
955 if (conf->wmm_enabled < 0)
956 conf->wmm_enabled = hapd->iconf->ieee80211n;
958 #ifdef CONFIG_IEEE80211R
959 if (is_zero_ether_addr(conf->r1_key_holder))
960 os_memcpy(conf->r1_key_holder, hapd->own_addr, ETH_ALEN);
961 #endif /* CONFIG_IEEE80211R */
964 if (hapd->iface->mconf == NULL)
965 flush_old_stations = 0;
966 #endif /* CONFIG_MESH */
968 if (flush_old_stations)
969 hostapd_flush_old_stations(hapd,
970 WLAN_REASON_PREV_AUTH_NOT_VALID);
971 hostapd_set_privacy(hapd, 0);
973 hostapd_broadcast_wep_clear(hapd);
974 if (hostapd_setup_encryption(conf->iface, hapd))
978 * Fetch the SSID from the system and use it or,
979 * if one was specified in the config file, verify they
982 ssid_len = hostapd_get_ssid(hapd, ssid, sizeof(ssid));
984 wpa_printf(MSG_ERROR, "Could not read SSID from system");
987 if (conf->ssid.ssid_set) {
989 * If SSID is specified in the config file and it differs
990 * from what is being used then force installation of the
993 set_ssid = (conf->ssid.ssid_len != (size_t) ssid_len ||
994 os_memcmp(conf->ssid.ssid, ssid, ssid_len) != 0);
997 * No SSID in the config file; just use the one we got
1001 conf->ssid.ssid_len = ssid_len;
1002 os_memcpy(conf->ssid.ssid, ssid, conf->ssid.ssid_len);
1005 if (!hostapd_drv_none(hapd)) {
1006 wpa_printf(MSG_ERROR, "Using interface %s with hwaddr " MACSTR
1008 conf->iface, MAC2STR(hapd->own_addr),
1009 wpa_ssid_txt(conf->ssid.ssid, conf->ssid.ssid_len));
1012 if (hostapd_setup_wpa_psk(conf)) {
1013 wpa_printf(MSG_ERROR, "WPA-PSK setup failed.");
1017 /* Set SSID for the kernel driver (to be used in beacon and probe
1018 * response frames) */
1019 if (set_ssid && hostapd_set_ssid(hapd, conf->ssid.ssid,
1020 conf->ssid.ssid_len)) {
1021 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
1025 if (wpa_debug_level <= MSG_MSGDUMP)
1026 conf->radius->msg_dumps = 1;
1027 #ifndef CONFIG_NO_RADIUS
1028 hapd->radius = radius_client_init(hapd, conf->radius);
1029 if (hapd->radius == NULL) {
1030 wpa_printf(MSG_ERROR, "RADIUS client initialization failed.");
1034 if (conf->radius_das_port) {
1035 struct radius_das_conf das_conf;
1036 os_memset(&das_conf, 0, sizeof(das_conf));
1037 das_conf.port = conf->radius_das_port;
1038 das_conf.shared_secret = conf->radius_das_shared_secret;
1039 das_conf.shared_secret_len =
1040 conf->radius_das_shared_secret_len;
1041 das_conf.client_addr = &conf->radius_das_client_addr;
1042 das_conf.time_window = conf->radius_das_time_window;
1043 das_conf.require_event_timestamp =
1044 conf->radius_das_require_event_timestamp;
1045 das_conf.ctx = hapd;
1046 das_conf.disconnect = hostapd_das_disconnect;
1047 hapd->radius_das = radius_das_init(&das_conf);
1048 if (hapd->radius_das == NULL) {
1049 wpa_printf(MSG_ERROR, "RADIUS DAS initialization "
1054 #endif /* CONFIG_NO_RADIUS */
1056 if (hostapd_acl_init(hapd)) {
1057 wpa_printf(MSG_ERROR, "ACL initialization failed.");
1060 if (hostapd_init_wps(hapd, conf))
1063 if (authsrv_init(hapd) < 0)
1066 if (ieee802_1x_init(hapd)) {
1067 wpa_printf(MSG_ERROR, "IEEE 802.1X initialization failed.");
1071 if ((conf->wpa || conf->osen) && hostapd_setup_wpa(hapd))
1074 if (accounting_init(hapd)) {
1075 wpa_printf(MSG_ERROR, "Accounting initialization failed.");
1079 if (conf->ieee802_11f &&
1080 (hapd->iapp = iapp_init(hapd, conf->iapp_iface)) == NULL) {
1081 wpa_printf(MSG_ERROR, "IEEE 802.11F (IAPP) initialization "
1086 #ifdef CONFIG_INTERWORKING
1087 if (gas_serv_init(hapd)) {
1088 wpa_printf(MSG_ERROR, "GAS server initialization failed");
1092 if (conf->qos_map_set_len &&
1093 hostapd_drv_set_qos_map(hapd, conf->qos_map_set,
1094 conf->qos_map_set_len)) {
1095 wpa_printf(MSG_ERROR, "Failed to initialize QoS Map");
1098 #endif /* CONFIG_INTERWORKING */
1100 if (conf->bss_load_update_period && bss_load_update_init(hapd)) {
1101 wpa_printf(MSG_ERROR, "BSS Load initialization failed");
1105 if (conf->proxy_arp) {
1106 if (x_snoop_init(hapd)) {
1107 wpa_printf(MSG_ERROR,
1108 "Generic snooping infrastructure initialization failed");
1112 if (dhcp_snoop_init(hapd)) {
1113 wpa_printf(MSG_ERROR,
1114 "DHCP snooping initialization failed");
1118 if (ndisc_snoop_init(hapd)) {
1119 wpa_printf(MSG_ERROR,
1120 "Neighbor Discovery snooping initialization failed");
1125 if (!hostapd_drv_none(hapd) && vlan_init(hapd)) {
1126 wpa_printf(MSG_ERROR, "VLAN initialization failed.");
1130 if (!conf->start_disabled && ieee802_11_set_beacon(hapd) < 0)
1133 if (hapd->wpa_auth && wpa_init_keys(hapd->wpa_auth) < 0)
1136 if (hapd->driver && hapd->driver->set_operstate)
1137 hapd->driver->set_operstate(hapd->drv_priv, 1);
1143 static void hostapd_tx_queue_params(struct hostapd_iface *iface)
1145 struct hostapd_data *hapd = iface->bss[0];
1147 struct hostapd_tx_queue_params *p;
1150 if (iface->mconf == NULL)
1152 #endif /* CONFIG_MESH */
1154 for (i = 0; i < NUM_TX_QUEUES; i++) {
1155 p = &iface->conf->tx_queue[i];
1157 if (hostapd_set_tx_queue_params(hapd, i, p->aifs, p->cwmin,
1158 p->cwmax, p->burst)) {
1159 wpa_printf(MSG_DEBUG, "Failed to set TX queue "
1160 "parameters for queue %d.", i);
1161 /* Continue anyway */
1167 static int hostapd_set_acl_list(struct hostapd_data *hapd,
1168 struct mac_acl_entry *mac_acl,
1169 int n_entries, u8 accept_acl)
1171 struct hostapd_acl_params *acl_params;
1174 acl_params = os_zalloc(sizeof(*acl_params) +
1175 (n_entries * sizeof(acl_params->mac_acl[0])));
1179 for (i = 0; i < n_entries; i++)
1180 os_memcpy(acl_params->mac_acl[i].addr, mac_acl[i].addr,
1183 acl_params->acl_policy = accept_acl;
1184 acl_params->num_mac_acl = n_entries;
1186 err = hostapd_drv_set_acl(hapd, acl_params);
1188 os_free(acl_params);
1194 static void hostapd_set_acl(struct hostapd_data *hapd)
1196 struct hostapd_config *conf = hapd->iconf;
1200 if (hapd->iface->drv_max_acl_mac_addrs == 0)
1203 if (conf->bss[0]->macaddr_acl == DENY_UNLESS_ACCEPTED) {
1205 err = hostapd_set_acl_list(hapd, conf->bss[0]->accept_mac,
1206 conf->bss[0]->num_accept_mac,
1209 wpa_printf(MSG_DEBUG, "Failed to set accept acl");
1212 } else if (conf->bss[0]->macaddr_acl == ACCEPT_UNLESS_DENIED) {
1214 err = hostapd_set_acl_list(hapd, conf->bss[0]->deny_mac,
1215 conf->bss[0]->num_deny_mac,
1218 wpa_printf(MSG_DEBUG, "Failed to set deny acl");
1225 static int start_ctrl_iface_bss(struct hostapd_data *hapd)
1227 if (!hapd->iface->interfaces ||
1228 !hapd->iface->interfaces->ctrl_iface_init)
1231 if (hapd->iface->interfaces->ctrl_iface_init(hapd)) {
1232 wpa_printf(MSG_ERROR,
1233 "Failed to setup control interface for %s",
1242 static int start_ctrl_iface(struct hostapd_iface *iface)
1246 if (!iface->interfaces || !iface->interfaces->ctrl_iface_init)
1249 for (i = 0; i < iface->num_bss; i++) {
1250 struct hostapd_data *hapd = iface->bss[i];
1251 if (iface->interfaces->ctrl_iface_init(hapd)) {
1252 wpa_printf(MSG_ERROR,
1253 "Failed to setup control interface for %s",
1263 static void channel_list_update_timeout(void *eloop_ctx, void *timeout_ctx)
1265 struct hostapd_iface *iface = eloop_ctx;
1267 if (!iface->wait_channel_update) {
1268 wpa_printf(MSG_INFO, "Channel list update timeout, but interface was not waiting for it");
1273 * It is possible that the existing channel list is acceptable, so try
1276 wpa_printf(MSG_DEBUG, "Channel list update timeout - try to continue anyway");
1277 setup_interface2(iface);
1281 void hostapd_channel_list_updated(struct hostapd_iface *iface, int initiator)
1283 if (!iface->wait_channel_update || initiator != REGDOM_SET_BY_USER)
1286 wpa_printf(MSG_DEBUG, "Channel list updated - continue setup");
1287 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
1288 setup_interface2(iface);
1292 static int setup_interface(struct hostapd_iface *iface)
1294 struct hostapd_data *hapd = iface->bss[0];
1298 * It is possible that setup_interface() is called after the interface
1299 * was disabled etc., in which case driver_ap_teardown is possibly set
1300 * to 1. Clear it here so any other key/station deletion, which is not
1301 * part of a teardown flow, would also call the relevant driver
1304 iface->driver_ap_teardown = 0;
1306 if (!iface->phy[0]) {
1307 const char *phy = hostapd_drv_get_radio_name(hapd);
1309 wpa_printf(MSG_DEBUG, "phy: %s", phy);
1310 os_strlcpy(iface->phy, phy, sizeof(iface->phy));
1315 * Make sure that all BSSes get configured with a pointer to the same
1318 for (i = 1; i < iface->num_bss; i++) {
1319 iface->bss[i]->driver = hapd->driver;
1320 iface->bss[i]->drv_priv = hapd->drv_priv;
1323 if (hostapd_validate_bssid_configuration(iface))
1327 * Initialize control interfaces early to allow external monitoring of
1328 * channel setup operations that may take considerable amount of time
1329 * especially for DFS cases.
1331 if (start_ctrl_iface(iface))
1334 if (hapd->iconf->country[0] && hapd->iconf->country[1]) {
1335 char country[4], previous_country[4];
1337 hostapd_set_state(iface, HAPD_IFACE_COUNTRY_UPDATE);
1338 if (hostapd_get_country(hapd, previous_country) < 0)
1339 previous_country[0] = '\0';
1341 os_memcpy(country, hapd->iconf->country, 3);
1343 if (hostapd_set_country(hapd, country) < 0) {
1344 wpa_printf(MSG_ERROR, "Failed to set country code");
1348 wpa_printf(MSG_DEBUG, "Previous country code %s, new country code %s",
1349 previous_country, country);
1351 if (os_strncmp(previous_country, country, 2) != 0) {
1352 wpa_printf(MSG_DEBUG, "Continue interface setup after channel list update");
1353 iface->wait_channel_update = 1;
1354 eloop_register_timeout(5, 0,
1355 channel_list_update_timeout,
1361 return setup_interface2(iface);
1365 static int setup_interface2(struct hostapd_iface *iface)
1367 iface->wait_channel_update = 0;
1369 if (hostapd_get_hw_features(iface)) {
1370 /* Not all drivers support this yet, so continue without hw
1373 int ret = hostapd_select_hw_mode(iface);
1375 wpa_printf(MSG_ERROR, "Could not select hw_mode and "
1376 "channel. (%d)", ret);
1380 wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback (ACS)");
1383 ret = hostapd_check_ht_capab(iface);
1387 wpa_printf(MSG_DEBUG, "Interface initialization will "
1388 "be completed in a callback");
1392 if (iface->conf->ieee80211h)
1393 wpa_printf(MSG_DEBUG, "DFS support is enabled");
1395 return hostapd_setup_interface_complete(iface, 0);
1398 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
1399 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
1400 if (iface->interfaces && iface->interfaces->terminate_on_error)
1408 static const u8 * fst_hostapd_get_bssid_cb(void *ctx)
1410 struct hostapd_data *hapd = ctx;
1412 return hapd->own_addr;
1416 static void fst_hostapd_get_channel_info_cb(void *ctx,
1417 enum hostapd_hw_mode *hw_mode,
1420 struct hostapd_data *hapd = ctx;
1422 *hw_mode = ieee80211_freq_to_chan(hapd->iface->freq, channel);
1426 static void fst_hostapd_set_ies_cb(void *ctx, const struct wpabuf *fst_ies)
1428 struct hostapd_data *hapd = ctx;
1430 if (hapd->iface->fst_ies != fst_ies) {
1431 hapd->iface->fst_ies = fst_ies;
1432 if (ieee802_11_set_beacon(hapd))
1433 wpa_printf(MSG_WARNING, "FST: Cannot set beacon");
1438 static int fst_hostapd_send_action_cb(void *ctx, const u8 *da,
1441 struct hostapd_data *hapd = ctx;
1443 return hostapd_drv_send_action(hapd, hapd->iface->freq, 0, da,
1444 wpabuf_head(buf), wpabuf_len(buf));
1448 static const struct wpabuf * fst_hostapd_get_mb_ie_cb(void *ctx, const u8 *addr)
1450 struct hostapd_data *hapd = ctx;
1451 struct sta_info *sta = ap_get_sta(hapd, addr);
1453 return sta ? sta->mb_ies : NULL;
1457 static void fst_hostapd_update_mb_ie_cb(void *ctx, const u8 *addr,
1458 const u8 *buf, size_t size)
1460 struct hostapd_data *hapd = ctx;
1461 struct sta_info *sta = ap_get_sta(hapd, addr);
1464 struct mb_ies_info info;
1466 if (!mb_ies_info_by_ies(&info, buf, size)) {
1467 wpabuf_free(sta->mb_ies);
1468 sta->mb_ies = mb_ies_by_info(&info);
1474 static const u8 * fst_hostapd_get_sta(struct fst_get_peer_ctx **get_ctx,
1477 struct sta_info *s = (struct sta_info *) *get_ctx;
1480 for (; s && !s->mb_ies; s = s->next)
1485 *get_ctx = (struct fst_get_peer_ctx *) s->next;
1495 static const u8 * fst_hostapd_get_peer_first(void *ctx,
1496 struct fst_get_peer_ctx **get_ctx,
1499 struct hostapd_data *hapd = ctx;
1501 *get_ctx = (struct fst_get_peer_ctx *) hapd->sta_list;
1503 return fst_hostapd_get_sta(get_ctx, mb_only);
1507 static const u8 * fst_hostapd_get_peer_next(void *ctx,
1508 struct fst_get_peer_ctx **get_ctx,
1511 return fst_hostapd_get_sta(get_ctx, mb_only);
1515 void fst_hostapd_fill_iface_obj(struct hostapd_data *hapd,
1516 struct fst_wpa_obj *iface_obj)
1518 iface_obj->ctx = hapd;
1519 iface_obj->get_bssid = fst_hostapd_get_bssid_cb;
1520 iface_obj->get_channel_info = fst_hostapd_get_channel_info_cb;
1521 iface_obj->set_ies = fst_hostapd_set_ies_cb;
1522 iface_obj->send_action = fst_hostapd_send_action_cb;
1523 iface_obj->get_mb_ie = fst_hostapd_get_mb_ie_cb;
1524 iface_obj->update_mb_ie = fst_hostapd_update_mb_ie_cb;
1525 iface_obj->get_peer_first = fst_hostapd_get_peer_first;
1526 iface_obj->get_peer_next = fst_hostapd_get_peer_next;
1529 #endif /* CONFIG_FST */
1533 static enum nr_chan_width hostapd_get_nr_chan_width(struct hostapd_data *hapd,
1537 return NR_CHAN_WIDTH_20;
1538 if (!hapd->iconf->secondary_channel)
1539 return NR_CHAN_WIDTH_20;
1540 if (!vht || hapd->iconf->vht_oper_chwidth == VHT_CHANWIDTH_USE_HT)
1541 return NR_CHAN_WIDTH_40;
1542 if (hapd->iconf->vht_oper_chwidth == VHT_CHANWIDTH_80MHZ)
1543 return NR_CHAN_WIDTH_80;
1544 if (hapd->iconf->vht_oper_chwidth == VHT_CHANWIDTH_160MHZ)
1545 return NR_CHAN_WIDTH_160;
1546 if (hapd->iconf->vht_oper_chwidth == VHT_CHANWIDTH_80P80MHZ)
1547 return NR_CHAN_WIDTH_80P80;
1548 return NR_CHAN_WIDTH_20;
1550 #endif /* NEED_AP_MLME */
1553 static void hostapd_set_own_neighbor_report(struct hostapd_data *hapd)
1556 u16 capab = hostapd_own_capab_info(hapd);
1557 int ht = hapd->iconf->ieee80211n && !hapd->conf->disable_11n;
1558 int vht = hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac;
1559 struct wpa_ssid_value ssid;
1560 u8 channel, op_class;
1561 int center_freq1 = 0, center_freq2 = 0;
1562 enum nr_chan_width width;
1566 if (!(hapd->conf->radio_measurements[0] &
1567 WLAN_RRM_CAPS_NEIGHBOR_REPORT))
1570 bssid_info = 3; /* AP is reachable */
1571 bssid_info |= NEI_REP_BSSID_INFO_SECURITY; /* "same as the AP" */
1572 bssid_info |= NEI_REP_BSSID_INFO_KEY_SCOPE; /* "same as the AP" */
1574 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT)
1575 bssid_info |= NEI_REP_BSSID_INFO_SPECTRUM_MGMT;
1577 bssid_info |= NEI_REP_BSSID_INFO_RM; /* RRM is supported */
1579 if (hapd->conf->wmm_enabled) {
1580 bssid_info |= NEI_REP_BSSID_INFO_QOS;
1582 if (hapd->conf->wmm_uapsd &&
1583 (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
1584 bssid_info |= NEI_REP_BSSID_INFO_APSD;
1588 bssid_info |= NEI_REP_BSSID_INFO_HT |
1589 NEI_REP_BSSID_INFO_DELAYED_BA;
1591 /* VHT bit added in IEEE P802.11-REVmc/D4.3 */
1593 bssid_info |= NEI_REP_BSSID_INFO_VHT;
1596 /* TODO: Set NEI_REP_BSSID_INFO_MOBILITY_DOMAIN if MDE is set */
1598 ieee80211_freq_to_channel_ext(hapd->iface->freq,
1599 hapd->iconf->secondary_channel,
1600 hapd->iconf->vht_oper_chwidth,
1601 &op_class, &channel);
1602 width = hostapd_get_nr_chan_width(hapd, ht, vht);
1604 center_freq1 = ieee80211_chan_to_freq(
1606 hapd->iconf->vht_oper_centr_freq_seg0_idx);
1607 if (width == NR_CHAN_WIDTH_80P80)
1608 center_freq2 = ieee80211_chan_to_freq(
1610 hapd->iconf->vht_oper_centr_freq_seg1_idx);
1612 center_freq1 = hapd->iface->freq +
1613 10 * hapd->iconf->secondary_channel;
1616 ssid.ssid_len = hapd->conf->ssid.ssid_len;
1617 os_memcpy(ssid.ssid, hapd->conf->ssid.ssid, ssid.ssid_len);
1620 * Neighbor Report element size = BSSID + BSSID info + op_class + chan +
1621 * phy type + wide bandwidth channel subelement.
1623 nr = wpabuf_alloc(ETH_ALEN + 4 + 1 + 1 + 1 + 5);
1627 wpabuf_put_data(nr, hapd->own_addr, ETH_ALEN);
1628 wpabuf_put_le32(nr, bssid_info);
1629 wpabuf_put_u8(nr, op_class);
1630 wpabuf_put_u8(nr, channel);
1631 wpabuf_put_u8(nr, ieee80211_get_phy_type(hapd->iface->freq, ht, vht));
1634 * Wide Bandwidth Channel subelement may be needed to allow the
1635 * receiving STA to send packets to the AP. See IEEE P802.11-REVmc/D5.0
1638 wpabuf_put_u8(nr, WNM_NEIGHBOR_WIDE_BW_CHAN);
1639 wpabuf_put_u8(nr, 3);
1640 wpabuf_put_u8(nr, width);
1641 wpabuf_put_u8(nr, center_freq1);
1642 wpabuf_put_u8(nr, center_freq2);
1644 hostapd_neighbor_set(hapd, hapd->own_addr, &ssid, nr, hapd->iconf->lci,
1645 hapd->iconf->civic);
1648 #endif /* NEED_AP_MLME */
1652 static int hostapd_setup_interface_complete_sync(struct hostapd_iface *iface,
1655 struct hostapd_data *hapd = iface->bss[0];
1658 int delay_apply_cfg = 0;
1659 int res_dfs_offload = 0;
1664 wpa_printf(MSG_DEBUG, "Completing interface initialization");
1665 if (iface->conf->channel) {
1668 #endif /* NEED_AP_MLME */
1670 iface->freq = hostapd_hw_get_freq(hapd, iface->conf->channel);
1671 wpa_printf(MSG_DEBUG, "Mode: %s Channel: %d "
1672 "Frequency: %d MHz",
1673 hostapd_hw_mode_txt(iface->conf->hw_mode),
1674 iface->conf->channel, iface->freq);
1677 /* Handle DFS only if it is not offloaded to the driver */
1678 if (!(iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)) {
1680 res = hostapd_handle_dfs(iface);
1687 /* If DFS is offloaded to the driver */
1688 res_dfs_offload = hostapd_handle_dfs_offload(iface);
1689 if (res_dfs_offload <= 0) {
1690 if (res_dfs_offload < 0)
1693 wpa_printf(MSG_DEBUG,
1694 "Proceed with AP/channel setup");
1696 * If this is a DFS channel, move to completing
1699 if (res_dfs_offload == 1)
1701 /* Otherwise fall through. */
1704 #endif /* NEED_AP_MLME */
1707 if (iface->mconf != NULL) {
1708 wpa_printf(MSG_DEBUG,
1709 "%s: Mesh configuration will be applied while joining the mesh network",
1710 iface->bss[0]->conf->iface);
1711 delay_apply_cfg = 1;
1713 #endif /* CONFIG_MESH */
1715 if (!delay_apply_cfg &&
1716 hostapd_set_freq(hapd, hapd->iconf->hw_mode, iface->freq,
1717 hapd->iconf->channel,
1718 hapd->iconf->ieee80211n,
1719 hapd->iconf->ieee80211ac,
1720 hapd->iconf->secondary_channel,
1721 hapd->iconf->vht_oper_chwidth,
1722 hapd->iconf->vht_oper_centr_freq_seg0_idx,
1723 hapd->iconf->vht_oper_centr_freq_seg1_idx)) {
1724 wpa_printf(MSG_ERROR, "Could not set channel for "
1730 if (iface->current_mode) {
1731 if (hostapd_prepare_rates(iface, iface->current_mode)) {
1732 wpa_printf(MSG_ERROR, "Failed to prepare rates "
1734 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1735 HOSTAPD_LEVEL_WARNING,
1736 "Failed to prepare rates table.");
1741 if (hapd->iconf->rts_threshold > -1 &&
1742 hostapd_set_rts(hapd, hapd->iconf->rts_threshold)) {
1743 wpa_printf(MSG_ERROR, "Could not set RTS threshold for "
1748 if (hapd->iconf->fragm_threshold > -1 &&
1749 hostapd_set_frag(hapd, hapd->iconf->fragm_threshold)) {
1750 wpa_printf(MSG_ERROR, "Could not set fragmentation threshold "
1751 "for kernel driver");
1755 prev_addr = hapd->own_addr;
1757 for (j = 0; j < iface->num_bss; j++) {
1758 hapd = iface->bss[j];
1760 os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN);
1761 if (hostapd_setup_bss(hapd, j == 0)) {
1763 hapd = iface->bss[j];
1764 hostapd_bss_deinit_no_free(hapd);
1765 hostapd_free_hapd_data(hapd);
1769 if (is_zero_ether_addr(hapd->conf->bssid))
1770 prev_addr = hapd->own_addr;
1772 hapd = iface->bss[0];
1774 hostapd_tx_queue_params(iface);
1776 ap_list_init(iface);
1777 dl_list_init(&iface->sta_seen);
1779 hostapd_set_acl(hapd);
1781 if (hostapd_driver_commit(hapd) < 0) {
1782 wpa_printf(MSG_ERROR, "%s: Failed to commit driver "
1783 "configuration", __func__);
1788 * WPS UPnP module can be initialized only when the "upnp_iface" is up.
1789 * If "interface" and "upnp_iface" are the same (e.g., non-bridge
1790 * mode), the interface is up only after driver_commit, so initialize
1791 * WPS after driver_commit.
1793 for (j = 0; j < iface->num_bss; j++) {
1794 if (hostapd_init_wps_complete(iface->bss[j]))
1798 if ((iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) &&
1801 * If freq is DFS, and DFS is offloaded to the driver, then wait
1802 * for CAC to complete.
1804 wpa_printf(MSG_DEBUG, "%s: Wait for CAC to complete", __func__);
1805 return res_dfs_offload;
1810 #endif /* NEED_AP_MLME */
1813 if (hapd->iconf->fst_cfg.group_id[0]) {
1814 struct fst_wpa_obj iface_obj;
1816 fst_hostapd_fill_iface_obj(hapd, &iface_obj);
1817 iface->fst = fst_attach(hapd->conf->iface, hapd->own_addr,
1818 &iface_obj, &hapd->iconf->fst_cfg);
1820 wpa_printf(MSG_ERROR, "Could not attach to FST %s",
1821 hapd->iconf->fst_cfg.group_id);
1825 #endif /* CONFIG_FST */
1827 hostapd_set_state(iface, HAPD_IFACE_ENABLED);
1828 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_ENABLED);
1829 if (hapd->setup_complete_cb)
1830 hapd->setup_complete_cb(hapd->setup_complete_cb_ctx);
1832 wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
1833 iface->bss[0]->conf->iface);
1834 if (iface->interfaces && iface->interfaces->terminate_on_error > 0)
1835 iface->interfaces->terminate_on_error--;
1837 for (j = 0; j < iface->num_bss; j++)
1838 hostapd_set_own_neighbor_report(iface->bss[j]);
1843 wpa_printf(MSG_ERROR, "Interface initialization failed");
1844 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
1845 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
1848 fst_detach(iface->fst);
1851 #endif /* CONFIG_FST */
1852 if (iface->interfaces && iface->interfaces->terminate_on_error)
1859 * hostapd_setup_interface_complete - Complete interface setup
1861 * This function is called when previous steps in the interface setup has been
1862 * completed. This can also start operations, e.g., DFS, that will require
1863 * additional processing before interface is ready to be enabled. Such
1864 * operations will call this function from eloop callbacks when finished.
1866 int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err)
1868 struct hapd_interfaces *interfaces = iface->interfaces;
1869 struct hostapd_data *hapd = iface->bss[0];
1871 int not_ready_in_sync_ifaces = 0;
1873 if (!iface->need_to_start_in_sync)
1874 return hostapd_setup_interface_complete_sync(iface, err);
1877 wpa_printf(MSG_ERROR, "Interface initialization failed");
1878 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
1879 iface->need_to_start_in_sync = 0;
1880 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
1881 if (interfaces && interfaces->terminate_on_error)
1886 if (iface->ready_to_start_in_sync) {
1887 /* Already in ready and waiting. should never happpen */
1891 for (i = 0; i < interfaces->count; i++) {
1892 if (interfaces->iface[i]->need_to_start_in_sync &&
1893 !interfaces->iface[i]->ready_to_start_in_sync)
1894 not_ready_in_sync_ifaces++;
1898 * Check if this is the last interface, if yes then start all the other
1899 * waiting interfaces. If not, add this interface to the waiting list.
1901 if (not_ready_in_sync_ifaces > 1 && iface->state == HAPD_IFACE_DFS) {
1903 * If this interface went through CAC, do not synchronize, just
1904 * start immediately.
1906 iface->need_to_start_in_sync = 0;
1907 wpa_printf(MSG_INFO,
1908 "%s: Finished CAC - bypass sync and start interface",
1909 iface->bss[0]->conf->iface);
1910 return hostapd_setup_interface_complete_sync(iface, err);
1913 if (not_ready_in_sync_ifaces > 1) {
1914 /* need to wait as there are other interfaces still coming up */
1915 iface->ready_to_start_in_sync = 1;
1916 wpa_printf(MSG_INFO,
1917 "%s: Interface waiting to sync with other interfaces",
1918 iface->bss[0]->conf->iface);
1922 wpa_printf(MSG_INFO,
1923 "%s: Last interface to sync - starting all interfaces",
1924 iface->bss[0]->conf->iface);
1925 iface->need_to_start_in_sync = 0;
1926 hostapd_setup_interface_complete_sync(iface, err);
1927 for (i = 0; i < interfaces->count; i++) {
1928 if (interfaces->iface[i]->need_to_start_in_sync &&
1929 interfaces->iface[i]->ready_to_start_in_sync) {
1930 hostapd_setup_interface_complete_sync(
1931 interfaces->iface[i], 0);
1932 /* Only once the interfaces are sync started */
1933 interfaces->iface[i]->need_to_start_in_sync = 0;
1942 * hostapd_setup_interface - Setup of an interface
1943 * @iface: Pointer to interface data.
1944 * Returns: 0 on success, -1 on failure
1946 * Initializes the driver interface, validates the configuration,
1947 * and sets driver parameters based on the configuration.
1948 * Flushes old stations, sets the channel, encryption,
1949 * beacons, and WDS links based on the configuration.
1951 * If interface setup requires more time, e.g., to perform HT co-ex scans, ACS,
1952 * or DFS operations, this function returns 0 before such operations have been
1953 * completed. The pending operations are registered into eloop and will be
1954 * completed from eloop callbacks. Those callbacks end up calling
1955 * hostapd_setup_interface_complete() once setup has been completed.
1957 int hostapd_setup_interface(struct hostapd_iface *iface)
1961 ret = setup_interface(iface);
1963 wpa_printf(MSG_ERROR, "%s: Unable to setup interface.",
1964 iface->bss[0]->conf->iface);
1973 * hostapd_alloc_bss_data - Allocate and initialize per-BSS data
1974 * @hapd_iface: Pointer to interface data
1975 * @conf: Pointer to per-interface configuration
1976 * @bss: Pointer to per-BSS configuration for this BSS
1977 * Returns: Pointer to allocated BSS data
1979 * This function is used to allocate per-BSS data structure. This data will be
1980 * freed after hostapd_cleanup() is called for it during interface
1983 struct hostapd_data *
1984 hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
1985 struct hostapd_config *conf,
1986 struct hostapd_bss_config *bss)
1988 struct hostapd_data *hapd;
1990 hapd = os_zalloc(sizeof(*hapd));
1994 hapd->new_assoc_sta_cb = hostapd_new_assoc_sta;
1997 hapd->iface = hapd_iface;
1998 hapd->driver = hapd->iconf->driver;
1999 hapd->ctrl_sock = -1;
2000 dl_list_init(&hapd->ctrl_dst);
2006 static void hostapd_bss_deinit(struct hostapd_data *hapd)
2008 wpa_printf(MSG_DEBUG, "%s: deinit bss %s", __func__,
2010 hostapd_bss_deinit_no_free(hapd);
2011 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
2012 hostapd_cleanup(hapd);
2016 void hostapd_interface_deinit(struct hostapd_iface *iface)
2020 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
2024 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
2026 #ifdef CONFIG_IEEE80211N
2028 hostapd_stop_setup_timers(iface);
2029 eloop_cancel_timeout(ap_ht2040_timeout, iface, NULL);
2030 #endif /* NEED_AP_MLME */
2031 #endif /* CONFIG_IEEE80211N */
2032 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
2033 iface->wait_channel_update = 0;
2037 fst_detach(iface->fst);
2040 #endif /* CONFIG_FST */
2042 for (j = iface->num_bss - 1; j >= 0; j--)
2043 hostapd_bss_deinit(iface->bss[j]);
2047 void hostapd_interface_free(struct hostapd_iface *iface)
2050 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
2051 for (j = 0; j < iface->num_bss; j++) {
2052 wpa_printf(MSG_DEBUG, "%s: free hapd %p",
2053 __func__, iface->bss[j]);
2054 os_free(iface->bss[j]);
2056 hostapd_cleanup_iface(iface);
2061 * hostapd_init - Allocate and initialize per-interface data
2062 * @config_file: Path to the configuration file
2063 * Returns: Pointer to the allocated interface data or %NULL on failure
2065 * This function is used to allocate main data structures for per-interface
2066 * data. The allocated data buffer will be freed by calling
2067 * hostapd_cleanup_iface().
2069 struct hostapd_iface * hostapd_init(struct hapd_interfaces *interfaces,
2070 const char *config_file)
2072 struct hostapd_iface *hapd_iface = NULL;
2073 struct hostapd_config *conf = NULL;
2074 struct hostapd_data *hapd;
2077 hapd_iface = os_zalloc(sizeof(*hapd_iface));
2078 if (hapd_iface == NULL)
2081 hapd_iface->config_fname = os_strdup(config_file);
2082 if (hapd_iface->config_fname == NULL)
2085 conf = interfaces->config_read_cb(hapd_iface->config_fname);
2088 hapd_iface->conf = conf;
2090 hapd_iface->num_bss = conf->num_bss;
2091 hapd_iface->bss = os_calloc(conf->num_bss,
2092 sizeof(struct hostapd_data *));
2093 if (hapd_iface->bss == NULL)
2096 for (i = 0; i < conf->num_bss; i++) {
2097 hapd = hapd_iface->bss[i] =
2098 hostapd_alloc_bss_data(hapd_iface, conf,
2102 hapd->msg_ctx = hapd;
2108 wpa_printf(MSG_ERROR, "Failed to set up interface with %s",
2111 hostapd_config_free(conf);
2113 os_free(hapd_iface->config_fname);
2114 os_free(hapd_iface->bss);
2115 wpa_printf(MSG_DEBUG, "%s: free iface %p",
2116 __func__, hapd_iface);
2117 os_free(hapd_iface);
2123 static int ifname_in_use(struct hapd_interfaces *interfaces, const char *ifname)
2127 for (i = 0; i < interfaces->count; i++) {
2128 struct hostapd_iface *iface = interfaces->iface[i];
2129 for (j = 0; j < iface->num_bss; j++) {
2130 struct hostapd_data *hapd = iface->bss[j];
2131 if (os_strcmp(ifname, hapd->conf->iface) == 0)
2141 * hostapd_interface_init_bss - Read configuration file and init BSS data
2143 * This function is used to parse configuration file for a BSS. This BSS is
2144 * added to an existing interface sharing the same radio (if any) or a new
2145 * interface is created if this is the first interface on a radio. This
2146 * allocate memory for the BSS. No actual driver operations are started.
2148 * This is similar to hostapd_interface_init(), but for a case where the
2149 * configuration is used to add a single BSS instead of all BSSes for a radio.
2151 struct hostapd_iface *
2152 hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy,
2153 const char *config_fname, int debug)
2155 struct hostapd_iface *new_iface = NULL, *iface = NULL;
2156 struct hostapd_data *hapd;
2163 for (i = 0; i < interfaces->count; i++) {
2164 if (os_strcmp(interfaces->iface[i]->phy, phy) == 0) {
2165 iface = interfaces->iface[i];
2170 wpa_printf(MSG_INFO, "Configuration file: %s (phy %s)%s",
2171 config_fname, phy, iface ? "" : " --> new PHY");
2173 struct hostapd_config *conf;
2174 struct hostapd_bss_config **tmp_conf;
2175 struct hostapd_data **tmp_bss;
2176 struct hostapd_bss_config *bss;
2179 /* Add new BSS to existing iface */
2180 conf = interfaces->config_read_cb(config_fname);
2183 if (conf->num_bss > 1) {
2184 wpa_printf(MSG_ERROR, "Multiple BSSes specified in BSS-config");
2185 hostapd_config_free(conf);
2189 ifname = conf->bss[0]->iface;
2190 if (ifname[0] != '\0' && ifname_in_use(interfaces, ifname)) {
2191 wpa_printf(MSG_ERROR,
2192 "Interface name %s already in use", ifname);
2193 hostapd_config_free(conf);
2197 tmp_conf = os_realloc_array(
2198 iface->conf->bss, iface->conf->num_bss + 1,
2199 sizeof(struct hostapd_bss_config *));
2200 tmp_bss = os_realloc_array(iface->bss, iface->num_bss + 1,
2201 sizeof(struct hostapd_data *));
2203 iface->bss = tmp_bss;
2205 iface->conf->bss = tmp_conf;
2206 iface->conf->last_bss = tmp_conf[0];
2208 if (tmp_bss == NULL || tmp_conf == NULL) {
2209 hostapd_config_free(conf);
2212 bss = iface->conf->bss[iface->conf->num_bss] = conf->bss[0];
2213 iface->conf->num_bss++;
2215 hapd = hostapd_alloc_bss_data(iface, iface->conf, bss);
2217 iface->conf->num_bss--;
2218 hostapd_config_free(conf);
2221 iface->conf->last_bss = bss;
2222 iface->bss[iface->num_bss] = hapd;
2223 hapd->msg_ctx = hapd;
2225 bss_idx = iface->num_bss++;
2227 conf->bss[0] = NULL;
2228 hostapd_config_free(conf);
2230 /* Add a new iface with the first BSS */
2231 new_iface = iface = hostapd_init(interfaces, config_fname);
2234 os_strlcpy(iface->phy, phy, sizeof(iface->phy));
2235 iface->interfaces = interfaces;
2239 for (k = 0; k < debug; k++) {
2240 if (iface->bss[bss_idx]->conf->logger_stdout_level > 0)
2241 iface->bss[bss_idx]->conf->logger_stdout_level--;
2244 if (iface->conf->bss[bss_idx]->iface[0] == '\0' &&
2245 !hostapd_drv_none(iface->bss[bss_idx])) {
2246 wpa_printf(MSG_ERROR, "Interface name not specified in %s",
2249 hostapd_interface_deinit_free(new_iface);
2257 void hostapd_interface_deinit_free(struct hostapd_iface *iface)
2259 const struct wpa_driver_ops *driver;
2262 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
2265 wpa_printf(MSG_DEBUG, "%s: num_bss=%u conf->num_bss=%u",
2266 __func__, (unsigned int) iface->num_bss,
2267 (unsigned int) iface->conf->num_bss);
2268 driver = iface->bss[0]->driver;
2269 drv_priv = iface->bss[0]->drv_priv;
2270 hostapd_interface_deinit(iface);
2271 wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
2272 __func__, driver, drv_priv);
2273 if (driver && driver->hapd_deinit && drv_priv) {
2274 driver->hapd_deinit(drv_priv);
2275 iface->bss[0]->drv_priv = NULL;
2277 hostapd_interface_free(iface);
2281 static void hostapd_deinit_driver(const struct wpa_driver_ops *driver,
2283 struct hostapd_iface *hapd_iface)
2287 wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
2288 __func__, driver, drv_priv);
2289 if (driver && driver->hapd_deinit && drv_priv) {
2290 driver->hapd_deinit(drv_priv);
2291 for (j = 0; j < hapd_iface->num_bss; j++) {
2292 wpa_printf(MSG_DEBUG, "%s:bss[%d]->drv_priv=%p",
2294 hapd_iface->bss[j]->drv_priv);
2295 if (hapd_iface->bss[j]->drv_priv == drv_priv)
2296 hapd_iface->bss[j]->drv_priv = NULL;
2302 int hostapd_enable_iface(struct hostapd_iface *hapd_iface)
2306 if (hapd_iface->bss[0]->drv_priv != NULL) {
2307 wpa_printf(MSG_ERROR, "Interface %s already enabled",
2308 hapd_iface->conf->bss[0]->iface);
2312 wpa_printf(MSG_DEBUG, "Enable interface %s",
2313 hapd_iface->conf->bss[0]->iface);
2315 for (j = 0; j < hapd_iface->num_bss; j++)
2316 hostapd_set_security_params(hapd_iface->conf->bss[j], 1);
2317 if (hostapd_config_check(hapd_iface->conf, 1) < 0) {
2318 wpa_printf(MSG_INFO, "Invalid configuration - cannot enable");
2322 if (hapd_iface->interfaces == NULL ||
2323 hapd_iface->interfaces->driver_init == NULL ||
2324 hapd_iface->interfaces->driver_init(hapd_iface))
2327 if (hostapd_setup_interface(hapd_iface)) {
2328 hostapd_deinit_driver(hapd_iface->bss[0]->driver,
2329 hapd_iface->bss[0]->drv_priv,
2338 int hostapd_reload_iface(struct hostapd_iface *hapd_iface)
2342 wpa_printf(MSG_DEBUG, "Reload interface %s",
2343 hapd_iface->conf->bss[0]->iface);
2344 for (j = 0; j < hapd_iface->num_bss; j++)
2345 hostapd_set_security_params(hapd_iface->conf->bss[j], 1);
2346 if (hostapd_config_check(hapd_iface->conf, 1) < 0) {
2347 wpa_printf(MSG_ERROR, "Updated configuration is invalid");
2350 hostapd_clear_old(hapd_iface);
2351 for (j = 0; j < hapd_iface->num_bss; j++)
2352 hostapd_reload_bss(hapd_iface->bss[j]);
2358 int hostapd_disable_iface(struct hostapd_iface *hapd_iface)
2361 const struct wpa_driver_ops *driver;
2364 if (hapd_iface == NULL)
2367 if (hapd_iface->bss[0]->drv_priv == NULL) {
2368 wpa_printf(MSG_INFO, "Interface %s already disabled",
2369 hapd_iface->conf->bss[0]->iface);
2373 wpa_msg(hapd_iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
2374 driver = hapd_iface->bss[0]->driver;
2375 drv_priv = hapd_iface->bss[0]->drv_priv;
2377 hapd_iface->driver_ap_teardown =
2378 !!(hapd_iface->drv_flags &
2379 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
2381 /* same as hostapd_interface_deinit without deinitializing ctrl-iface */
2382 for (j = 0; j < hapd_iface->num_bss; j++) {
2383 struct hostapd_data *hapd = hapd_iface->bss[j];
2384 hostapd_bss_deinit_no_free(hapd);
2385 hostapd_free_hapd_data(hapd);
2388 hostapd_deinit_driver(driver, drv_priv, hapd_iface);
2390 /* From hostapd_cleanup_iface: These were initialized in
2391 * hostapd_setup_interface and hostapd_setup_interface_complete
2393 hostapd_cleanup_iface_partial(hapd_iface);
2395 wpa_printf(MSG_DEBUG, "Interface %s disabled",
2396 hapd_iface->bss[0]->conf->iface);
2397 hostapd_set_state(hapd_iface, HAPD_IFACE_DISABLED);
2402 static struct hostapd_iface *
2403 hostapd_iface_alloc(struct hapd_interfaces *interfaces)
2405 struct hostapd_iface **iface, *hapd_iface;
2407 iface = os_realloc_array(interfaces->iface, interfaces->count + 1,
2408 sizeof(struct hostapd_iface *));
2411 interfaces->iface = iface;
2412 hapd_iface = interfaces->iface[interfaces->count] =
2413 os_zalloc(sizeof(*hapd_iface));
2414 if (hapd_iface == NULL) {
2415 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for "
2416 "the interface", __func__);
2419 interfaces->count++;
2420 hapd_iface->interfaces = interfaces;
2426 static struct hostapd_config *
2427 hostapd_config_alloc(struct hapd_interfaces *interfaces, const char *ifname,
2428 const char *ctrl_iface, const char *driver)
2430 struct hostapd_bss_config *bss;
2431 struct hostapd_config *conf;
2433 /* Allocates memory for bss and conf */
2434 conf = hostapd_config_defaults();
2436 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for "
2437 "configuration", __func__);
2444 for (j = 0; wpa_drivers[j]; j++) {
2445 if (os_strcmp(driver, wpa_drivers[j]->name) == 0) {
2446 conf->driver = wpa_drivers[j];
2451 wpa_printf(MSG_ERROR,
2452 "Invalid/unknown driver '%s' - registering the default driver",
2456 conf->driver = wpa_drivers[0];
2457 if (conf->driver == NULL) {
2458 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
2459 hostapd_config_free(conf);
2464 bss = conf->last_bss = conf->bss[0];
2466 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
2467 bss->ctrl_interface = os_strdup(ctrl_iface);
2468 if (bss->ctrl_interface == NULL) {
2469 hostapd_config_free(conf);
2473 /* Reading configuration file skipped, will be done in SET!
2474 * From reading the configuration till the end has to be done in
2481 static int hostapd_data_alloc(struct hostapd_iface *hapd_iface,
2482 struct hostapd_config *conf)
2485 struct hostapd_data *hapd;
2487 hapd_iface->bss = os_calloc(conf->num_bss,
2488 sizeof(struct hostapd_data *));
2489 if (hapd_iface->bss == NULL)
2492 for (i = 0; i < conf->num_bss; i++) {
2493 hapd = hapd_iface->bss[i] =
2494 hostapd_alloc_bss_data(hapd_iface, conf, conf->bss[i]);
2498 os_free(hapd_iface->bss[i]);
2499 hapd_iface->bss[i] = NULL;
2501 os_free(hapd_iface->bss);
2502 hapd_iface->bss = NULL;
2505 hapd->msg_ctx = hapd;
2508 hapd_iface->conf = conf;
2509 hapd_iface->num_bss = conf->num_bss;
2515 int hostapd_add_iface(struct hapd_interfaces *interfaces, char *buf)
2517 struct hostapd_config *conf = NULL;
2518 struct hostapd_iface *hapd_iface = NULL, *new_iface = NULL;
2519 struct hostapd_data *hapd;
2522 const char *conf_file = NULL, *phy_name = NULL;
2524 if (os_strncmp(buf, "bss_config=", 11) == 0) {
2526 phy_name = buf + 11;
2527 pos = os_strchr(phy_name, ':');
2532 if (!os_strlen(conf_file))
2535 hapd_iface = hostapd_interface_init_bss(interfaces, phy_name,
2539 for (j = 0; j < interfaces->count; j++) {
2540 if (interfaces->iface[j] == hapd_iface)
2543 if (j == interfaces->count) {
2544 struct hostapd_iface **tmp;
2545 tmp = os_realloc_array(interfaces->iface,
2546 interfaces->count + 1,
2547 sizeof(struct hostapd_iface *));
2549 hostapd_interface_deinit_free(hapd_iface);
2552 interfaces->iface = tmp;
2553 interfaces->iface[interfaces->count++] = hapd_iface;
2554 new_iface = hapd_iface;
2558 if (interfaces->driver_init(hapd_iface))
2561 if (hostapd_setup_interface(hapd_iface)) {
2562 hostapd_deinit_driver(
2563 hapd_iface->bss[0]->driver,
2564 hapd_iface->bss[0]->drv_priv,
2569 /* Assign new BSS with bss[0]'s driver info */
2570 hapd = hapd_iface->bss[hapd_iface->num_bss - 1];
2571 hapd->driver = hapd_iface->bss[0]->driver;
2572 hapd->drv_priv = hapd_iface->bss[0]->drv_priv;
2573 os_memcpy(hapd->own_addr, hapd_iface->bss[0]->own_addr,
2576 if (start_ctrl_iface_bss(hapd) < 0 ||
2577 (hapd_iface->state == HAPD_IFACE_ENABLED &&
2578 hostapd_setup_bss(hapd, -1))) {
2579 hostapd_cleanup(hapd);
2580 hapd_iface->bss[hapd_iface->num_bss - 1] = NULL;
2581 hapd_iface->conf->num_bss--;
2582 hapd_iface->num_bss--;
2583 wpa_printf(MSG_DEBUG, "%s: free hapd %p %s",
2584 __func__, hapd, hapd->conf->iface);
2585 hostapd_config_free_bss(hapd->conf);
2594 ptr = os_strchr(buf, ' ');
2599 if (os_strncmp(ptr, "config=", 7) == 0)
2600 conf_file = ptr + 7;
2602 for (i = 0; i < interfaces->count; i++) {
2603 if (!os_strcmp(interfaces->iface[i]->conf->bss[0]->iface,
2605 wpa_printf(MSG_INFO, "Cannot add interface - it "
2611 hapd_iface = hostapd_iface_alloc(interfaces);
2612 if (hapd_iface == NULL) {
2613 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
2614 "for interface", __func__);
2617 new_iface = hapd_iface;
2619 if (conf_file && interfaces->config_read_cb) {
2620 conf = interfaces->config_read_cb(conf_file);
2621 if (conf && conf->bss)
2622 os_strlcpy(conf->bss[0]->iface, buf,
2623 sizeof(conf->bss[0]->iface));
2625 char *driver = os_strchr(ptr, ' ');
2629 conf = hostapd_config_alloc(interfaces, buf, ptr, driver);
2632 if (conf == NULL || conf->bss == NULL) {
2633 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
2634 "for configuration", __func__);
2638 if (hostapd_data_alloc(hapd_iface, conf) < 0) {
2639 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
2640 "for hostapd", __func__);
2645 if (start_ctrl_iface(hapd_iface) < 0)
2648 wpa_printf(MSG_INFO, "Add interface '%s'",
2649 hapd_iface->conf->bss[0]->iface);
2655 hostapd_config_free(conf);
2657 if (hapd_iface->bss) {
2658 for (i = 0; i < hapd_iface->num_bss; i++) {
2659 hapd = hapd_iface->bss[i];
2662 if (hapd_iface->interfaces &&
2663 hapd_iface->interfaces->ctrl_iface_deinit)
2664 hapd_iface->interfaces->
2665 ctrl_iface_deinit(hapd);
2666 wpa_printf(MSG_DEBUG, "%s: free hapd %p (%s)",
2667 __func__, hapd_iface->bss[i],
2669 hostapd_cleanup(hapd);
2671 hapd_iface->bss[i] = NULL;
2673 os_free(hapd_iface->bss);
2674 hapd_iface->bss = NULL;
2677 interfaces->count--;
2678 interfaces->iface[interfaces->count] = NULL;
2680 hostapd_cleanup_iface(hapd_iface);
2686 static int hostapd_remove_bss(struct hostapd_iface *iface, unsigned int idx)
2690 wpa_printf(MSG_INFO, "Remove BSS '%s'", iface->conf->bss[idx]->iface);
2692 /* Remove hostapd_data only if it has already been initialized */
2693 if (idx < iface->num_bss) {
2694 struct hostapd_data *hapd = iface->bss[idx];
2696 hostapd_bss_deinit(hapd);
2697 wpa_printf(MSG_DEBUG, "%s: free hapd %p (%s)",
2698 __func__, hapd, hapd->conf->iface);
2699 hostapd_config_free_bss(hapd->conf);
2705 for (i = idx; i < iface->num_bss; i++)
2706 iface->bss[i] = iface->bss[i + 1];
2708 hostapd_config_free_bss(iface->conf->bss[idx]);
2709 iface->conf->bss[idx] = NULL;
2712 iface->conf->num_bss--;
2713 for (i = idx; i < iface->conf->num_bss; i++)
2714 iface->conf->bss[i] = iface->conf->bss[i + 1];
2720 int hostapd_remove_iface(struct hapd_interfaces *interfaces, char *buf)
2722 struct hostapd_iface *hapd_iface;
2725 for (i = 0; i < interfaces->count; i++) {
2726 hapd_iface = interfaces->iface[i];
2727 if (hapd_iface == NULL)
2729 if (!os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
2730 wpa_printf(MSG_INFO, "Remove interface '%s'", buf);
2731 hapd_iface->driver_ap_teardown =
2732 !!(hapd_iface->drv_flags &
2733 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
2735 hostapd_interface_deinit_free(hapd_iface);
2737 while (k < (interfaces->count - 1)) {
2738 interfaces->iface[k] =
2739 interfaces->iface[k + 1];
2742 interfaces->count--;
2746 for (j = 0; j < hapd_iface->conf->num_bss; j++) {
2747 if (!os_strcmp(hapd_iface->conf->bss[j]->iface, buf)) {
2748 hapd_iface->driver_ap_teardown =
2749 !(hapd_iface->drv_flags &
2750 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
2751 return hostapd_remove_bss(hapd_iface, j);
2760 * hostapd_new_assoc_sta - Notify that a new station associated with the AP
2761 * @hapd: Pointer to BSS data
2762 * @sta: Pointer to the associated STA data
2763 * @reassoc: 1 to indicate this was a re-association; 0 = first association
2765 * This function will be called whenever a station associates with the AP. It
2766 * can be called from ieee802_11.c for drivers that export MLME to hostapd and
2767 * from drv_callbacks.c based on driver events for drivers that take care of
2768 * management frames (IEEE 802.11 authentication and association) internally.
2770 void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
2773 if (hapd->tkip_countermeasures) {
2774 hostapd_drv_sta_deauth(hapd, sta->addr,
2775 WLAN_REASON_MICHAEL_MIC_FAILURE);
2779 hostapd_prune_associations(hapd, sta->addr);
2780 ap_sta_clear_disconnect_timeouts(hapd, sta);
2782 /* IEEE 802.11F (IAPP) */
2783 if (hapd->conf->ieee802_11f)
2784 iapp_new_station(hapd->iapp, sta);
2787 if (sta->p2p_ie == NULL && !sta->no_p2p_set) {
2788 sta->no_p2p_set = 1;
2789 hapd->num_sta_no_p2p++;
2790 if (hapd->num_sta_no_p2p == 1)
2791 hostapd_p2p_non_p2p_sta_connected(hapd);
2793 #endif /* CONFIG_P2P */
2795 /* Start accounting here, if IEEE 802.1X and WPA are not used.
2796 * IEEE 802.1X/WPA code will start accounting after the station has
2797 * been authorized. */
2798 if (!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) {
2799 ap_sta_set_authorized(hapd, sta, 1);
2800 os_get_reltime(&sta->connected_time);
2801 accounting_sta_start(hapd, sta);
2804 /* Start IEEE 802.1X authentication process for new stations */
2805 ieee802_1x_new_station(hapd, sta);
2807 if (sta->auth_alg != WLAN_AUTH_FT &&
2808 !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)))
2809 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH);
2811 wpa_auth_sta_associated(hapd->wpa_auth, sta->wpa_sm);
2813 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) {
2814 wpa_printf(MSG_DEBUG,
2815 "%s: %s: reschedule ap_handle_timer timeout for "
2816 MACSTR " (%d seconds - ap_max_inactivity)",
2817 hapd->conf->iface, __func__, MAC2STR(sta->addr),
2818 hapd->conf->ap_max_inactivity);
2819 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
2820 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
2821 ap_handle_timer, hapd, sta);
2826 const char * hostapd_state_text(enum hostapd_iface_state s)
2829 case HAPD_IFACE_UNINITIALIZED:
2830 return "UNINITIALIZED";
2831 case HAPD_IFACE_DISABLED:
2833 case HAPD_IFACE_COUNTRY_UPDATE:
2834 return "COUNTRY_UPDATE";
2835 case HAPD_IFACE_ACS:
2837 case HAPD_IFACE_HT_SCAN:
2839 case HAPD_IFACE_DFS:
2841 case HAPD_IFACE_ENABLED:
2849 void hostapd_set_state(struct hostapd_iface *iface, enum hostapd_iface_state s)
2851 wpa_printf(MSG_INFO, "%s: interface state %s->%s",
2852 iface->conf->bss[0]->iface, hostapd_state_text(iface->state),
2853 hostapd_state_text(s));
2858 int hostapd_csa_in_progress(struct hostapd_iface *iface)
2862 for (i = 0; i < iface->num_bss; i++)
2863 if (iface->bss[i]->csa_in_progress)
2871 static void free_beacon_data(struct beacon_data *beacon)
2873 os_free(beacon->head);
2874 beacon->head = NULL;
2875 os_free(beacon->tail);
2876 beacon->tail = NULL;
2877 os_free(beacon->probe_resp);
2878 beacon->probe_resp = NULL;
2879 os_free(beacon->beacon_ies);
2880 beacon->beacon_ies = NULL;
2881 os_free(beacon->proberesp_ies);
2882 beacon->proberesp_ies = NULL;
2883 os_free(beacon->assocresp_ies);
2884 beacon->assocresp_ies = NULL;
2888 static int hostapd_build_beacon_data(struct hostapd_data *hapd,
2889 struct beacon_data *beacon)
2891 struct wpabuf *beacon_extra, *proberesp_extra, *assocresp_extra;
2892 struct wpa_driver_ap_params params;
2895 os_memset(beacon, 0, sizeof(*beacon));
2896 ret = ieee802_11_build_ap_params(hapd, ¶ms);
2900 ret = hostapd_build_ap_extra_ies(hapd, &beacon_extra,
2904 goto free_ap_params;
2907 beacon->head = os_malloc(params.head_len);
2909 goto free_ap_extra_ies;
2911 os_memcpy(beacon->head, params.head, params.head_len);
2912 beacon->head_len = params.head_len;
2914 beacon->tail = os_malloc(params.tail_len);
2918 os_memcpy(beacon->tail, params.tail, params.tail_len);
2919 beacon->tail_len = params.tail_len;
2921 if (params.proberesp != NULL) {
2922 beacon->probe_resp = os_malloc(params.proberesp_len);
2923 if (!beacon->probe_resp)
2926 os_memcpy(beacon->probe_resp, params.proberesp,
2927 params.proberesp_len);
2928 beacon->probe_resp_len = params.proberesp_len;
2931 /* copy the extra ies */
2933 beacon->beacon_ies = os_malloc(wpabuf_len(beacon_extra));
2934 if (!beacon->beacon_ies)
2937 os_memcpy(beacon->beacon_ies,
2938 beacon_extra->buf, wpabuf_len(beacon_extra));
2939 beacon->beacon_ies_len = wpabuf_len(beacon_extra);
2942 if (proberesp_extra) {
2943 beacon->proberesp_ies =
2944 os_malloc(wpabuf_len(proberesp_extra));
2945 if (!beacon->proberesp_ies)
2948 os_memcpy(beacon->proberesp_ies, proberesp_extra->buf,
2949 wpabuf_len(proberesp_extra));
2950 beacon->proberesp_ies_len = wpabuf_len(proberesp_extra);
2953 if (assocresp_extra) {
2954 beacon->assocresp_ies =
2955 os_malloc(wpabuf_len(assocresp_extra));
2956 if (!beacon->assocresp_ies)
2959 os_memcpy(beacon->assocresp_ies, assocresp_extra->buf,
2960 wpabuf_len(assocresp_extra));
2961 beacon->assocresp_ies_len = wpabuf_len(assocresp_extra);
2966 /* if the function fails, the caller should not free beacon data */
2968 free_beacon_data(beacon);
2971 hostapd_free_ap_extra_ies(hapd, beacon_extra, proberesp_extra,
2974 ieee802_11_free_ap_params(¶ms);
2980 * TODO: This flow currently supports only changing channel and width within
2981 * the same hw_mode. Any other changes to MAC parameters or provided settings
2982 * are not supported.
2984 static int hostapd_change_config_freq(struct hostapd_data *hapd,
2985 struct hostapd_config *conf,
2986 struct hostapd_freq_params *params,
2987 struct hostapd_freq_params *old_params)
2991 if (!params->channel) {
2992 /* check if the new channel is supported by hw */
2993 params->channel = hostapd_hw_get_channel(hapd, params->freq);
2996 channel = params->channel;
3000 /* if a pointer to old_params is provided we save previous state */
3002 hostapd_set_freq_params(old_params, conf->hw_mode,
3003 hostapd_hw_get_freq(hapd, conf->channel),
3004 conf->channel, conf->ieee80211n,
3006 conf->secondary_channel,
3007 conf->vht_oper_chwidth,
3008 conf->vht_oper_centr_freq_seg0_idx,
3009 conf->vht_oper_centr_freq_seg1_idx,
3013 switch (params->bandwidth) {
3017 conf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT;
3020 if (params->center_freq2)
3021 conf->vht_oper_chwidth = VHT_CHANWIDTH_80P80MHZ;
3023 conf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ;
3026 conf->vht_oper_chwidth = VHT_CHANWIDTH_160MHZ;
3032 conf->channel = channel;
3033 conf->ieee80211n = params->ht_enabled;
3034 conf->secondary_channel = params->sec_channel_offset;
3035 ieee80211_freq_to_chan(params->center_freq1,
3036 &conf->vht_oper_centr_freq_seg0_idx);
3037 ieee80211_freq_to_chan(params->center_freq2,
3038 &conf->vht_oper_centr_freq_seg1_idx);
3040 /* TODO: maybe call here hostapd_config_check here? */
3046 static int hostapd_fill_csa_settings(struct hostapd_data *hapd,
3047 struct csa_settings *settings)
3049 struct hostapd_iface *iface = hapd->iface;
3050 struct hostapd_freq_params old_freq;
3052 u8 chan, vht_bandwidth;
3054 os_memset(&old_freq, 0, sizeof(old_freq));
3055 if (!iface || !iface->freq || hapd->csa_in_progress)
3058 switch (settings->freq_params.bandwidth) {
3060 if (settings->freq_params.center_freq2)
3061 vht_bandwidth = VHT_CHANWIDTH_80P80MHZ;
3063 vht_bandwidth = VHT_CHANWIDTH_80MHZ;
3066 vht_bandwidth = VHT_CHANWIDTH_160MHZ;
3069 vht_bandwidth = VHT_CHANWIDTH_USE_HT;
3073 if (ieee80211_freq_to_channel_ext(
3074 settings->freq_params.freq,
3075 settings->freq_params.sec_channel_offset,
3077 &hapd->iface->cs_oper_class,
3078 &chan) == NUM_HOSTAPD_MODES) {
3079 wpa_printf(MSG_DEBUG,
3080 "invalid frequency for channel switch (freq=%d, sec_channel_offset=%d, vht_enabled=%d)",
3081 settings->freq_params.freq,
3082 settings->freq_params.sec_channel_offset,
3083 settings->freq_params.vht_enabled);
3087 settings->freq_params.channel = chan;
3089 ret = hostapd_change_config_freq(iface->bss[0], iface->conf,
3090 &settings->freq_params,
3095 ret = hostapd_build_beacon_data(hapd, &settings->beacon_after);
3097 /* change back the configuration */
3098 hostapd_change_config_freq(iface->bss[0], iface->conf,
3104 /* set channel switch parameters for csa ie */
3105 hapd->cs_freq_params = settings->freq_params;
3106 hapd->cs_count = settings->cs_count;
3107 hapd->cs_block_tx = settings->block_tx;
3109 ret = hostapd_build_beacon_data(hapd, &settings->beacon_csa);
3111 free_beacon_data(&settings->beacon_after);
3115 settings->counter_offset_beacon[0] = hapd->cs_c_off_beacon;
3116 settings->counter_offset_presp[0] = hapd->cs_c_off_proberesp;
3117 settings->counter_offset_beacon[1] = hapd->cs_c_off_ecsa_beacon;
3118 settings->counter_offset_presp[1] = hapd->cs_c_off_ecsa_proberesp;
3124 void hostapd_cleanup_cs_params(struct hostapd_data *hapd)
3126 os_memset(&hapd->cs_freq_params, 0, sizeof(hapd->cs_freq_params));
3128 hapd->cs_block_tx = 0;
3129 hapd->cs_c_off_beacon = 0;
3130 hapd->cs_c_off_proberesp = 0;
3131 hapd->csa_in_progress = 0;
3132 hapd->cs_c_off_ecsa_beacon = 0;
3133 hapd->cs_c_off_ecsa_proberesp = 0;
3137 int hostapd_switch_channel(struct hostapd_data *hapd,
3138 struct csa_settings *settings)
3142 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA)) {
3143 wpa_printf(MSG_INFO, "CSA is not supported");
3147 ret = hostapd_fill_csa_settings(hapd, settings);
3151 ret = hostapd_drv_switch_channel(hapd, settings);
3152 free_beacon_data(&settings->beacon_csa);
3153 free_beacon_data(&settings->beacon_after);
3156 /* if we failed, clean cs parameters */
3157 hostapd_cleanup_cs_params(hapd);
3161 hapd->csa_in_progress = 1;
3167 hostapd_switch_channel_fallback(struct hostapd_iface *iface,
3168 const struct hostapd_freq_params *freq_params)
3170 int vht_seg0_idx = 0, vht_seg1_idx = 0, vht_bw = VHT_CHANWIDTH_USE_HT;
3173 wpa_printf(MSG_DEBUG, "Restarting all CSA-related BSSes");
3175 if (freq_params->center_freq1)
3176 vht_seg0_idx = 36 + (freq_params->center_freq1 - 5180) / 5;
3177 if (freq_params->center_freq2)
3178 vht_seg1_idx = 36 + (freq_params->center_freq2 - 5180) / 5;
3180 switch (freq_params->bandwidth) {
3184 vht_bw = VHT_CHANWIDTH_USE_HT;
3187 if (freq_params->center_freq2)
3188 vht_bw = VHT_CHANWIDTH_80P80MHZ;
3190 vht_bw = VHT_CHANWIDTH_80MHZ;
3193 vht_bw = VHT_CHANWIDTH_160MHZ;
3196 wpa_printf(MSG_WARNING, "Unknown CSA bandwidth: %d",
3197 freq_params->bandwidth);
3201 iface->freq = freq_params->freq;
3202 iface->conf->channel = freq_params->channel;
3203 iface->conf->secondary_channel = freq_params->sec_channel_offset;
3204 iface->conf->vht_oper_centr_freq_seg0_idx = vht_seg0_idx;
3205 iface->conf->vht_oper_centr_freq_seg1_idx = vht_seg1_idx;
3206 iface->conf->vht_oper_chwidth = vht_bw;
3207 iface->conf->ieee80211n = freq_params->ht_enabled;
3208 iface->conf->ieee80211ac = freq_params->vht_enabled;
3211 * cs_params must not be cleared earlier because the freq_params
3212 * argument may actually point to one of these.
3214 for (i = 0; i < iface->num_bss; i++)
3215 hostapd_cleanup_cs_params(iface->bss[i]);
3217 hostapd_disable_iface(iface);
3218 hostapd_enable_iface(iface);
3221 #endif /* NEED_AP_MLME */
3224 struct hostapd_data * hostapd_get_iface(struct hapd_interfaces *interfaces,
3229 for (i = 0; i < interfaces->count; i++) {
3230 struct hostapd_iface *iface = interfaces->iface[i];
3232 for (j = 0; j < iface->num_bss; j++) {
3233 struct hostapd_data *hapd = iface->bss[j];
3235 if (os_strcmp(ifname, hapd->conf->iface) == 0)
3244 void hostapd_periodic_iface(struct hostapd_iface *iface)
3248 ap_list_timer(iface);
3250 for (i = 0; i < iface->num_bss; i++) {
3251 struct hostapd_data *hapd = iface->bss[i];
3256 #ifndef CONFIG_NO_RADIUS
3257 hostapd_acl_expire(hapd);
3258 #endif /* CONFIG_NO_RADIUS */