2 * hostapd / Initialization and configuration
3 * Copyright (c) 2002-2019, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "common/ieee802_11_defs.h"
14 #include "common/wpa_ctrl.h"
15 #include "common/hw_features_common.h"
16 #include "radius/radius_client.h"
17 #include "radius/radius_das.h"
18 #include "eap_server/tncs.h"
19 #include "eapol_auth/eapol_auth_sm.h"
20 #include "eapol_auth/eapol_auth_sm_i.h"
25 #include "accounting.h"
29 #include "ieee802_1x.h"
30 #include "ieee802_11_auth.h"
31 #include "vlan_init.h"
33 #include "wps_hostapd.h"
34 #include "dpp_hostapd.h"
35 #include "gas_query_ap.h"
36 #include "hw_features.h"
37 #include "wpa_auth_glue.h"
38 #include "ap_drv_ops.h"
39 #include "ap_config.h"
40 #include "p2p_hostapd.h"
43 #include "ieee802_11.h"
46 #include "dhcp_snoop.h"
47 #include "ndisc_snoop.h"
48 #include "neighbor_db.h"
53 #include "airtime_policy.h"
54 #include "wpa_auth_kay.h"
57 static int hostapd_flush_old_stations(struct hostapd_data
*hapd
, u16 reason
);
58 static int hostapd_setup_encryption(char *iface
, struct hostapd_data
*hapd
);
59 static int hostapd_broadcast_wep_clear(struct hostapd_data
*hapd
);
60 static int setup_interface2(struct hostapd_iface
*iface
);
61 static void channel_list_update_timeout(void *eloop_ctx
, void *timeout_ctx
);
62 static void hostapd_interface_setup_failure_handler(void *eloop_ctx
,
66 int hostapd_for_each_interface(struct hapd_interfaces
*interfaces
,
67 int (*cb
)(struct hostapd_iface
*iface
,
68 void *ctx
), void *ctx
)
73 for (i
= 0; i
< interfaces
->count
; i
++) {
74 ret
= cb(interfaces
->iface
[i
], ctx
);
83 void hostapd_reconfig_encryption(struct hostapd_data
*hapd
)
88 hostapd_set_privacy(hapd
, 0);
89 hostapd_setup_encryption(hapd
->conf
->iface
, hapd
);
93 static void hostapd_reload_bss(struct hostapd_data
*hapd
)
95 struct hostapd_ssid
*ssid
;
100 if (hapd
->conf
->wmm_enabled
< 0)
101 hapd
->conf
->wmm_enabled
= hapd
->iconf
->ieee80211n
;
103 #ifndef CONFIG_NO_RADIUS
104 radius_client_reconfig(hapd
->radius
, hapd
->conf
->radius
);
105 #endif /* CONFIG_NO_RADIUS */
107 ssid
= &hapd
->conf
->ssid
;
108 if (!ssid
->wpa_psk_set
&& ssid
->wpa_psk
&& !ssid
->wpa_psk
->next
&&
109 ssid
->wpa_passphrase_set
&& ssid
->wpa_passphrase
) {
111 * Force PSK to be derived again since SSID or passphrase may
114 hostapd_config_clear_wpa_psk(&hapd
->conf
->ssid
.wpa_psk
);
116 if (hostapd_setup_wpa_psk(hapd
->conf
)) {
117 wpa_printf(MSG_ERROR
, "Failed to re-configure WPA PSK "
118 "after reloading configuration");
121 if (hapd
->conf
->ieee802_1x
|| hapd
->conf
->wpa
)
122 hostapd_set_drv_ieee8021x(hapd
, hapd
->conf
->iface
, 1);
124 hostapd_set_drv_ieee8021x(hapd
, hapd
->conf
->iface
, 0);
126 if ((hapd
->conf
->wpa
|| hapd
->conf
->osen
) && hapd
->wpa_auth
== NULL
) {
127 hostapd_setup_wpa(hapd
);
129 wpa_init_keys(hapd
->wpa_auth
);
130 } else if (hapd
->conf
->wpa
) {
133 hostapd_reconfig_wpa(hapd
);
134 wpa_ie
= wpa_auth_get_wpa_ie(hapd
->wpa_auth
, &wpa_ie_len
);
135 if (hostapd_set_generic_elem(hapd
, wpa_ie
, wpa_ie_len
))
136 wpa_printf(MSG_ERROR
, "Failed to configure WPA IE for "
137 "the kernel driver.");
138 } else if (hapd
->wpa_auth
) {
139 wpa_deinit(hapd
->wpa_auth
);
140 hapd
->wpa_auth
= NULL
;
141 hostapd_set_privacy(hapd
, 0);
142 hostapd_setup_encryption(hapd
->conf
->iface
, hapd
);
143 hostapd_set_generic_elem(hapd
, (u8
*) "", 0);
146 ieee802_11_set_beacon(hapd
);
147 hostapd_update_wps(hapd
);
149 if (hapd
->conf
->ssid
.ssid_set
&&
150 hostapd_set_ssid(hapd
, hapd
->conf
->ssid
.ssid
,
151 hapd
->conf
->ssid
.ssid_len
)) {
152 wpa_printf(MSG_ERROR
, "Could not set SSID for kernel driver");
153 /* try to continue */
155 wpa_printf(MSG_DEBUG
, "Reconfigured interface %s", hapd
->conf
->iface
);
159 static void hostapd_clear_old(struct hostapd_iface
*iface
)
164 * Deauthenticate all stations since the new configuration may not
165 * allow them to use the BSS anymore.
167 for (j
= 0; j
< iface
->num_bss
; j
++) {
168 hostapd_flush_old_stations(iface
->bss
[j
],
169 WLAN_REASON_PREV_AUTH_NOT_VALID
);
170 hostapd_broadcast_wep_clear(iface
->bss
[j
]);
172 #ifndef CONFIG_NO_RADIUS
173 /* TODO: update dynamic data based on changed configuration
174 * items (e.g., open/close sockets, etc.) */
175 radius_client_flush(iface
->bss
[j
]->radius
, 0);
176 #endif /* CONFIG_NO_RADIUS */
181 static int hostapd_iface_conf_changed(struct hostapd_config
*newconf
,
182 struct hostapd_config
*oldconf
)
186 if (newconf
->num_bss
!= oldconf
->num_bss
)
189 for (i
= 0; i
< newconf
->num_bss
; i
++) {
190 if (os_strcmp(newconf
->bss
[i
]->iface
,
191 oldconf
->bss
[i
]->iface
) != 0)
199 int hostapd_reload_config(struct hostapd_iface
*iface
)
201 struct hapd_interfaces
*interfaces
= iface
->interfaces
;
202 struct hostapd_data
*hapd
= iface
->bss
[0];
203 struct hostapd_config
*newconf
, *oldconf
;
206 if (iface
->config_fname
== NULL
) {
207 /* Only in-memory config in use - assume it has been updated */
208 hostapd_clear_old(iface
);
209 for (j
= 0; j
< iface
->num_bss
; j
++)
210 hostapd_reload_bss(iface
->bss
[j
]);
214 if (iface
->interfaces
== NULL
||
215 iface
->interfaces
->config_read_cb
== NULL
)
217 newconf
= iface
->interfaces
->config_read_cb(iface
->config_fname
);
221 hostapd_clear_old(iface
);
223 oldconf
= hapd
->iconf
;
224 if (hostapd_iface_conf_changed(newconf
, oldconf
)) {
228 wpa_printf(MSG_DEBUG
,
229 "Configuration changes include interface/BSS modification - force full disable+enable sequence");
230 fname
= os_strdup(iface
->config_fname
);
232 hostapd_config_free(newconf
);
235 hostapd_remove_iface(interfaces
, hapd
->conf
->iface
);
236 iface
= hostapd_init(interfaces
, fname
);
238 hostapd_config_free(newconf
);
240 wpa_printf(MSG_ERROR
,
241 "Failed to initialize interface on config reload");
244 iface
->interfaces
= interfaces
;
245 interfaces
->iface
[interfaces
->count
] = iface
;
247 res
= hostapd_enable_iface(iface
);
249 wpa_printf(MSG_ERROR
,
250 "Failed to enable interface on config reload");
253 iface
->conf
= newconf
;
255 for (j
= 0; j
< iface
->num_bss
; j
++) {
256 hapd
= iface
->bss
[j
];
257 hapd
->iconf
= newconf
;
258 hapd
->iconf
->channel
= oldconf
->channel
;
259 hapd
->iconf
->acs
= oldconf
->acs
;
260 hapd
->iconf
->secondary_channel
= oldconf
->secondary_channel
;
261 hapd
->iconf
->ieee80211n
= oldconf
->ieee80211n
;
262 hapd
->iconf
->ieee80211ac
= oldconf
->ieee80211ac
;
263 hapd
->iconf
->ht_capab
= oldconf
->ht_capab
;
264 hapd
->iconf
->vht_capab
= oldconf
->vht_capab
;
265 hostapd_set_oper_chwidth(hapd
->iconf
,
266 hostapd_get_oper_chwidth(oldconf
));
267 hostapd_set_oper_centr_freq_seg0_idx(
269 hostapd_get_oper_centr_freq_seg0_idx(oldconf
));
270 hostapd_set_oper_centr_freq_seg1_idx(
272 hostapd_get_oper_centr_freq_seg1_idx(oldconf
));
273 hapd
->conf
= newconf
->bss
[j
];
274 hostapd_reload_bss(hapd
);
277 hostapd_config_free(oldconf
);
284 static void hostapd_broadcast_key_clear_iface(struct hostapd_data
*hapd
,
289 if (!ifname
|| !hapd
->drv_priv
)
291 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
292 if (hostapd_drv_set_key(ifname
, hapd
, WPA_ALG_NONE
, NULL
, i
,
293 0, NULL
, 0, NULL
, 0)) {
294 wpa_printf(MSG_DEBUG
, "Failed to clear default "
295 "encryption keys (ifname=%s keyidx=%d)",
299 #ifdef CONFIG_IEEE80211W
300 if (hapd
->conf
->ieee80211w
) {
301 for (i
= NUM_WEP_KEYS
; i
< NUM_WEP_KEYS
+ 2; i
++) {
302 if (hostapd_drv_set_key(ifname
, hapd
, WPA_ALG_NONE
,
305 wpa_printf(MSG_DEBUG
, "Failed to clear "
306 "default mgmt encryption keys "
307 "(ifname=%s keyidx=%d)", ifname
, i
);
311 #endif /* CONFIG_IEEE80211W */
315 static int hostapd_broadcast_wep_clear(struct hostapd_data
*hapd
)
317 hostapd_broadcast_key_clear_iface(hapd
, hapd
->conf
->iface
);
322 static int hostapd_broadcast_wep_set(struct hostapd_data
*hapd
)
325 struct hostapd_ssid
*ssid
= &hapd
->conf
->ssid
;
328 if (ssid
->wep
.default_len
&&
329 hostapd_drv_set_key(hapd
->conf
->iface
,
330 hapd
, WPA_ALG_WEP
, broadcast_ether_addr
, idx
,
331 1, NULL
, 0, ssid
->wep
.key
[idx
],
332 ssid
->wep
.len
[idx
])) {
333 wpa_printf(MSG_WARNING
, "Could not set WEP encryption.");
341 static void hostapd_free_hapd_data(struct hostapd_data
*hapd
)
343 os_free(hapd
->probereq_cb
);
344 hapd
->probereq_cb
= NULL
;
345 hapd
->num_probereq_cb
= 0;
348 wpabuf_free(hapd
->p2p_beacon_ie
);
349 hapd
->p2p_beacon_ie
= NULL
;
350 wpabuf_free(hapd
->p2p_probe_resp_ie
);
351 hapd
->p2p_probe_resp_ie
= NULL
;
352 #endif /* CONFIG_P2P */
354 if (!hapd
->started
) {
355 wpa_printf(MSG_ERROR
, "%s: Interface %s wasn't started",
356 __func__
, hapd
->conf
? hapd
->conf
->iface
: "N/A");
360 hapd
->beacon_set_done
= 0;
362 wpa_printf(MSG_DEBUG
, "%s(%s)", __func__
, hapd
->conf
->iface
);
363 iapp_deinit(hapd
->iapp
);
365 accounting_deinit(hapd
);
366 hostapd_deinit_wpa(hapd
);
368 hostapd_acl_deinit(hapd
);
369 #ifndef CONFIG_NO_RADIUS
370 radius_client_deinit(hapd
->radius
);
372 radius_das_deinit(hapd
->radius_das
);
373 hapd
->radius_das
= NULL
;
374 #endif /* CONFIG_NO_RADIUS */
376 hostapd_deinit_wps(hapd
);
377 ieee802_1x_dealloc_kay_sm_hapd(hapd
);
379 hostapd_dpp_deinit(hapd
);
380 gas_query_ap_deinit(hapd
->gas
);
381 #endif /* CONFIG_DPP */
383 authsrv_deinit(hapd
);
385 if (hapd
->interface_added
) {
386 hapd
->interface_added
= 0;
387 if (hostapd_if_remove(hapd
, WPA_IF_AP_BSS
, hapd
->conf
->iface
)) {
388 wpa_printf(MSG_WARNING
,
389 "Failed to remove BSS interface %s",
391 hapd
->interface_added
= 1;
394 * Since this was a dynamically added interface, the
395 * driver wrapper may have removed its internal instance
396 * and hapd->drv_priv is not valid anymore.
398 hapd
->drv_priv
= NULL
;
402 wpabuf_free(hapd
->time_adv
);
404 #ifdef CONFIG_INTERWORKING
405 gas_serv_deinit(hapd
);
406 #endif /* CONFIG_INTERWORKING */
408 bss_load_update_deinit(hapd
);
409 ndisc_snoop_deinit(hapd
);
410 dhcp_snoop_deinit(hapd
);
411 x_snoop_deinit(hapd
);
414 bin_clear_free(hapd
->tmp_eap_user
.identity
,
415 hapd
->tmp_eap_user
.identity_len
);
416 bin_clear_free(hapd
->tmp_eap_user
.password
,
417 hapd
->tmp_eap_user
.password_len
);
418 #endif /* CONFIG_SQLITE */
421 wpabuf_free(hapd
->mesh_pending_auth
);
422 hapd
->mesh_pending_auth
= NULL
;
423 #endif /* CONFIG_MESH */
425 hostapd_clean_rrm(hapd
);
426 fils_hlp_deinit(hapd
);
430 struct hostapd_sae_commit_queue
*q
;
432 while ((q
= dl_list_first(&hapd
->sae_commit_queue
,
433 struct hostapd_sae_commit_queue
,
435 dl_list_del(&q
->list
);
439 eloop_cancel_timeout(auth_sae_process_commit
, hapd
, NULL
);
440 #endif /* CONFIG_SAE */
445 * hostapd_cleanup - Per-BSS cleanup (deinitialization)
446 * @hapd: Pointer to BSS data
448 * This function is used to free all per-BSS data structures and resources.
449 * Most of the modules that are initialized in hostapd_setup_bss() are
450 * deinitialized here.
452 static void hostapd_cleanup(struct hostapd_data
*hapd
)
454 wpa_printf(MSG_DEBUG
, "%s(hapd=%p (%s))", __func__
, hapd
,
455 hapd
->conf
? hapd
->conf
->iface
: "N/A");
456 if (hapd
->iface
->interfaces
&&
457 hapd
->iface
->interfaces
->ctrl_iface_deinit
) {
458 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, WPA_EVENT_TERMINATING
);
459 hapd
->iface
->interfaces
->ctrl_iface_deinit(hapd
);
461 hostapd_free_hapd_data(hapd
);
465 static void sta_track_deinit(struct hostapd_iface
*iface
)
467 struct hostapd_sta_info
*info
;
469 if (!iface
->num_sta_seen
)
472 while ((info
= dl_list_first(&iface
->sta_seen
, struct hostapd_sta_info
,
474 dl_list_del(&info
->list
);
475 iface
->num_sta_seen
--;
481 static void hostapd_cleanup_iface_partial(struct hostapd_iface
*iface
)
483 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
484 #ifdef CONFIG_IEEE80211N
486 hostapd_stop_setup_timers(iface
);
487 #endif /* NEED_AP_MLME */
488 #endif /* CONFIG_IEEE80211N */
489 if (iface
->current_mode
)
491 hostapd_free_hw_features(iface
->hw_features
, iface
->num_hw_features
);
492 iface
->hw_features
= NULL
;
493 iface
->current_mode
= NULL
;
494 os_free(iface
->current_rates
);
495 iface
->current_rates
= NULL
;
496 os_free(iface
->basic_rates
);
497 iface
->basic_rates
= NULL
;
498 ap_list_deinit(iface
);
499 sta_track_deinit(iface
);
500 airtime_policy_update_deinit(iface
);
505 * hostapd_cleanup_iface - Complete per-interface cleanup
506 * @iface: Pointer to interface data
508 * This function is called after per-BSS data structures are deinitialized
509 * with hostapd_cleanup().
511 static void hostapd_cleanup_iface(struct hostapd_iface
*iface
)
513 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
514 eloop_cancel_timeout(channel_list_update_timeout
, iface
, NULL
);
515 eloop_cancel_timeout(hostapd_interface_setup_failure_handler
, iface
,
518 hostapd_cleanup_iface_partial(iface
);
519 hostapd_config_free(iface
->conf
);
522 os_free(iface
->config_fname
);
524 wpa_printf(MSG_DEBUG
, "%s: free iface=%p", __func__
, iface
);
529 static void hostapd_clear_wep(struct hostapd_data
*hapd
)
531 if (hapd
->drv_priv
&& !hapd
->iface
->driver_ap_teardown
&& hapd
->conf
) {
532 hostapd_set_privacy(hapd
, 0);
533 hostapd_broadcast_wep_clear(hapd
);
538 static int hostapd_setup_encryption(char *iface
, struct hostapd_data
*hapd
)
542 hostapd_broadcast_wep_set(hapd
);
544 if (hapd
->conf
->ssid
.wep
.default_len
) {
545 hostapd_set_privacy(hapd
, 1);
550 * When IEEE 802.1X is not enabled, the driver may need to know how to
551 * set authentication algorithms for static WEP.
553 hostapd_drv_set_authmode(hapd
, hapd
->conf
->auth_algs
);
555 for (i
= 0; i
< 4; i
++) {
556 if (hapd
->conf
->ssid
.wep
.key
[i
] &&
557 hostapd_drv_set_key(iface
, hapd
, WPA_ALG_WEP
, NULL
, i
,
558 i
== hapd
->conf
->ssid
.wep
.idx
, NULL
, 0,
559 hapd
->conf
->ssid
.wep
.key
[i
],
560 hapd
->conf
->ssid
.wep
.len
[i
])) {
561 wpa_printf(MSG_WARNING
, "Could not set WEP "
565 if (hapd
->conf
->ssid
.wep
.key
[i
] &&
566 i
== hapd
->conf
->ssid
.wep
.idx
)
567 hostapd_set_privacy(hapd
, 1);
574 static int hostapd_flush_old_stations(struct hostapd_data
*hapd
, u16 reason
)
579 if (hostapd_drv_none(hapd
) || hapd
->drv_priv
== NULL
)
582 if (!hapd
->iface
->driver_ap_teardown
) {
583 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
,
584 "Flushing old station entries");
586 if (hostapd_flush(hapd
)) {
587 wpa_msg(hapd
->msg_ctx
, MSG_WARNING
,
588 "Could not connect to kernel driver");
592 if (hapd
->conf
&& hapd
->conf
->broadcast_deauth
) {
593 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
,
594 "Deauthenticate all stations");
595 os_memset(addr
, 0xff, ETH_ALEN
);
596 hostapd_drv_sta_deauth(hapd
, addr
, reason
);
598 hostapd_free_stas(hapd
);
604 static void hostapd_bss_deinit_no_free(struct hostapd_data
*hapd
)
606 hostapd_free_stas(hapd
);
607 hostapd_flush_old_stations(hapd
, WLAN_REASON_DEAUTH_LEAVING
);
608 hostapd_clear_wep(hapd
);
613 * hostapd_validate_bssid_configuration - Validate BSSID configuration
614 * @iface: Pointer to interface data
615 * Returns: 0 on success, -1 on failure
617 * This function is used to validate that the configured BSSIDs are valid.
619 static int hostapd_validate_bssid_configuration(struct hostapd_iface
*iface
)
621 u8 mask
[ETH_ALEN
] = { 0 };
622 struct hostapd_data
*hapd
= iface
->bss
[0];
623 unsigned int i
= iface
->conf
->num_bss
, bits
= 0, j
;
626 if (hostapd_drv_none(hapd
))
629 if (iface
->conf
->use_driver_iface_addr
)
632 /* Generate BSSID mask that is large enough to cover the BSSIDs. */
634 /* Determine the bits necessary to cover the number of BSSIDs. */
635 for (i
--; i
; i
>>= 1)
638 /* Determine the bits necessary to any configured BSSIDs,
639 if they are higher than the number of BSSIDs. */
640 for (j
= 0; j
< iface
->conf
->num_bss
; j
++) {
641 if (is_zero_ether_addr(iface
->conf
->bss
[j
]->bssid
)) {
647 for (i
= 0; i
< ETH_ALEN
; i
++) {
649 iface
->conf
->bss
[j
]->bssid
[i
] ^
657 for (i
= 0; i
< ETH_ALEN
&& mask
[i
] == 0; i
++)
663 while (mask
[i
] != 0) {
673 wpa_printf(MSG_ERROR
, "Too many bits in the BSSID mask (%u)",
678 os_memset(mask
, 0xff, ETH_ALEN
);
680 for (i
= 5; i
> 5 - j
; i
--)
689 wpa_printf(MSG_DEBUG
, "BSS count %lu, BSSID mask " MACSTR
" (%d bits)",
690 (unsigned long) iface
->conf
->num_bss
, MAC2STR(mask
), bits
);
695 for (i
= 0; i
< ETH_ALEN
; i
++) {
696 if ((hapd
->own_addr
[i
] & mask
[i
]) != hapd
->own_addr
[i
]) {
697 wpa_printf(MSG_ERROR
, "Invalid BSSID mask " MACSTR
698 " for start address " MACSTR
".",
699 MAC2STR(mask
), MAC2STR(hapd
->own_addr
));
700 wpa_printf(MSG_ERROR
, "Start address must be the "
701 "first address in the block (i.e., addr "
702 "AND mask == addr).");
711 static int mac_in_conf(struct hostapd_config
*conf
, const void *a
)
715 for (i
= 0; i
< conf
->num_bss
; i
++) {
716 if (hostapd_mac_comp(conf
->bss
[i
]->bssid
, a
) == 0) {
725 #ifndef CONFIG_NO_RADIUS
727 static int hostapd_das_nas_mismatch(struct hostapd_data
*hapd
,
728 struct radius_das_attrs
*attr
)
730 if (attr
->nas_identifier
&&
731 (!hapd
->conf
->nas_identifier
||
732 os_strlen(hapd
->conf
->nas_identifier
) !=
733 attr
->nas_identifier_len
||
734 os_memcmp(hapd
->conf
->nas_identifier
, attr
->nas_identifier
,
735 attr
->nas_identifier_len
) != 0)) {
736 wpa_printf(MSG_DEBUG
, "RADIUS DAS: NAS-Identifier mismatch");
740 if (attr
->nas_ip_addr
&&
741 (hapd
->conf
->own_ip_addr
.af
!= AF_INET
||
742 os_memcmp(&hapd
->conf
->own_ip_addr
.u
.v4
, attr
->nas_ip_addr
, 4) !=
744 wpa_printf(MSG_DEBUG
, "RADIUS DAS: NAS-IP-Address mismatch");
749 if (attr
->nas_ipv6_addr
&&
750 (hapd
->conf
->own_ip_addr
.af
!= AF_INET6
||
751 os_memcmp(&hapd
->conf
->own_ip_addr
.u
.v6
, attr
->nas_ipv6_addr
, 16)
753 wpa_printf(MSG_DEBUG
, "RADIUS DAS: NAS-IPv6-Address mismatch");
756 #endif /* CONFIG_IPV6 */
762 static struct sta_info
* hostapd_das_find_sta(struct hostapd_data
*hapd
,
763 struct radius_das_attrs
*attr
,
766 struct sta_info
*selected
, *sta
;
773 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
)
774 sta
->radius_das_match
= 1;
776 if (attr
->sta_addr
) {
778 sta
= ap_get_sta(hapd
, attr
->sta_addr
);
780 wpa_printf(MSG_DEBUG
,
781 "RADIUS DAS: No Calling-Station-Id match");
786 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
788 sta
->radius_das_match
= 0;
790 wpa_printf(MSG_DEBUG
, "RADIUS DAS: Calling-Station-Id match");
793 if (attr
->acct_session_id
) {
795 if (attr
->acct_session_id_len
!= 16) {
796 wpa_printf(MSG_DEBUG
,
797 "RADIUS DAS: Acct-Session-Id cannot match");
802 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
803 if (!sta
->radius_das_match
)
805 os_snprintf(buf
, sizeof(buf
), "%016llX",
806 (unsigned long long) sta
->acct_session_id
);
807 if (os_memcmp(attr
->acct_session_id
, buf
, 16) != 0)
808 sta
->radius_das_match
= 0;
814 wpa_printf(MSG_DEBUG
,
815 "RADIUS DAS: No matches remaining after Acct-Session-Id check");
818 wpa_printf(MSG_DEBUG
, "RADIUS DAS: Acct-Session-Id match");
821 if (attr
->acct_multi_session_id
) {
823 if (attr
->acct_multi_session_id_len
!= 16) {
824 wpa_printf(MSG_DEBUG
,
825 "RADIUS DAS: Acct-Multi-Session-Id cannot match");
830 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
831 if (!sta
->radius_das_match
)
833 if (!sta
->eapol_sm
||
834 !sta
->eapol_sm
->acct_multi_session_id
) {
835 sta
->radius_das_match
= 0;
838 os_snprintf(buf
, sizeof(buf
), "%016llX",
840 sta
->eapol_sm
->acct_multi_session_id
);
841 if (os_memcmp(attr
->acct_multi_session_id
, buf
, 16) !=
843 sta
->radius_das_match
= 0;
849 wpa_printf(MSG_DEBUG
,
850 "RADIUS DAS: No matches remaining after Acct-Multi-Session-Id check");
853 wpa_printf(MSG_DEBUG
,
854 "RADIUS DAS: Acct-Multi-Session-Id match");
861 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
864 if (!sta
->radius_das_match
)
866 cui
= ieee802_1x_get_radius_cui(sta
->eapol_sm
);
867 if (!cui
|| wpabuf_len(cui
) != attr
->cui_len
||
868 os_memcmp(wpabuf_head(cui
), attr
->cui
,
870 sta
->radius_das_match
= 0;
876 wpa_printf(MSG_DEBUG
,
877 "RADIUS DAS: No matches remaining after Chargeable-User-Identity check");
880 wpa_printf(MSG_DEBUG
,
881 "RADIUS DAS: Chargeable-User-Identity match");
884 if (attr
->user_name
) {
888 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
892 if (!sta
->radius_das_match
)
894 identity
= ieee802_1x_get_identity(sta
->eapol_sm
,
897 identity_len
!= attr
->user_name_len
||
898 os_memcmp(identity
, attr
->user_name
, identity_len
)
900 sta
->radius_das_match
= 0;
906 wpa_printf(MSG_DEBUG
,
907 "RADIUS DAS: No matches remaining after User-Name check");
910 wpa_printf(MSG_DEBUG
,
911 "RADIUS DAS: User-Name match");
916 * In theory, we could match all current associations, but it
917 * seems safer to just reject requests that do not include any
918 * session identification attributes.
920 wpa_printf(MSG_DEBUG
,
921 "RADIUS DAS: No session identification attributes included");
926 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
927 if (sta
->radius_das_match
) {
940 static int hostapd_das_disconnect_pmksa(struct hostapd_data
*hapd
,
941 struct radius_das_attrs
*attr
)
945 return wpa_auth_radius_das_disconnect_pmksa(hapd
->wpa_auth
, attr
);
949 static enum radius_das_res
950 hostapd_das_disconnect(void *ctx
, struct radius_das_attrs
*attr
)
952 struct hostapd_data
*hapd
= ctx
;
953 struct sta_info
*sta
;
956 if (hostapd_das_nas_mismatch(hapd
, attr
))
957 return RADIUS_DAS_NAS_MISMATCH
;
959 sta
= hostapd_das_find_sta(hapd
, attr
, &multi
);
962 wpa_printf(MSG_DEBUG
,
963 "RADIUS DAS: Multiple sessions match - not supported");
964 return RADIUS_DAS_MULTI_SESSION_MATCH
;
966 if (hostapd_das_disconnect_pmksa(hapd
, attr
) == 0) {
967 wpa_printf(MSG_DEBUG
,
968 "RADIUS DAS: PMKSA cache entry matched");
969 return RADIUS_DAS_SUCCESS
;
971 wpa_printf(MSG_DEBUG
, "RADIUS DAS: No matching session found");
972 return RADIUS_DAS_SESSION_NOT_FOUND
;
975 wpa_printf(MSG_DEBUG
, "RADIUS DAS: Found a matching session " MACSTR
976 " - disconnecting", MAC2STR(sta
->addr
));
977 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
979 hostapd_drv_sta_deauth(hapd
, sta
->addr
,
980 WLAN_REASON_PREV_AUTH_NOT_VALID
);
981 ap_sta_deauthenticate(hapd
, sta
, WLAN_REASON_PREV_AUTH_NOT_VALID
);
983 return RADIUS_DAS_SUCCESS
;
988 static enum radius_das_res
989 hostapd_das_coa(void *ctx
, struct radius_das_attrs
*attr
)
991 struct hostapd_data
*hapd
= ctx
;
992 struct sta_info
*sta
;
995 if (hostapd_das_nas_mismatch(hapd
, attr
))
996 return RADIUS_DAS_NAS_MISMATCH
;
998 sta
= hostapd_das_find_sta(hapd
, attr
, &multi
);
1001 wpa_printf(MSG_DEBUG
,
1002 "RADIUS DAS: Multiple sessions match - not supported");
1003 return RADIUS_DAS_MULTI_SESSION_MATCH
;
1005 wpa_printf(MSG_DEBUG
, "RADIUS DAS: No matching session found");
1006 return RADIUS_DAS_SESSION_NOT_FOUND
;
1009 wpa_printf(MSG_DEBUG
, "RADIUS DAS: Found a matching session " MACSTR
1010 " - CoA", MAC2STR(sta
->addr
));
1012 if (attr
->hs20_t_c_filtering
) {
1013 if (attr
->hs20_t_c_filtering
[0] & BIT(0)) {
1014 wpa_printf(MSG_DEBUG
,
1015 "HS 2.0: Unexpected Terms and Conditions filtering required in CoA-Request");
1016 return RADIUS_DAS_COA_FAILED
;
1019 hs20_t_c_filtering(hapd
, sta
, 0);
1022 return RADIUS_DAS_SUCCESS
;
1024 #else /* CONFIG_HS20 */
1025 #define hostapd_das_coa NULL
1026 #endif /* CONFIG_HS20 */
1028 #endif /* CONFIG_NO_RADIUS */
1032 * hostapd_setup_bss - Per-BSS setup (initialization)
1033 * @hapd: Pointer to BSS data
1034 * @first: Whether this BSS is the first BSS of an interface; -1 = not first,
1035 * but interface may exist
1037 * This function is used to initialize all per-BSS data structures and
1038 * resources. This gets called in a loop for each BSS when an interface is
1039 * initialized. Most of the modules that are initialized here will be
1040 * deinitialized in hostapd_cleanup().
1042 static int hostapd_setup_bss(struct hostapd_data
*hapd
, int first
)
1044 struct hostapd_bss_config
*conf
= hapd
->conf
;
1045 u8 ssid
[SSID_MAX_LEN
+ 1];
1046 int ssid_len
, set_ssid
;
1047 char force_ifname
[IFNAMSIZ
];
1048 u8 if_addr
[ETH_ALEN
];
1049 int flush_old_stations
= 1;
1051 wpa_printf(MSG_DEBUG
, "%s(hapd=%p (%s), first=%d)",
1052 __func__
, hapd
, conf
->iface
, first
);
1054 #ifdef EAP_SERVER_TNC
1055 if (conf
->tnc
&& tncs_global_init() < 0) {
1056 wpa_printf(MSG_ERROR
, "Failed to initialize TNCS");
1059 #endif /* EAP_SERVER_TNC */
1061 if (hapd
->started
) {
1062 wpa_printf(MSG_ERROR
, "%s: Interface %s was already started",
1063 __func__
, conf
->iface
);
1068 if (!first
|| first
== -1) {
1069 u8
*addr
= hapd
->own_addr
;
1071 if (!is_zero_ether_addr(conf
->bssid
)) {
1072 /* Allocate the configured BSSID. */
1073 os_memcpy(hapd
->own_addr
, conf
->bssid
, ETH_ALEN
);
1075 if (hostapd_mac_comp(hapd
->own_addr
,
1076 hapd
->iface
->bss
[0]->own_addr
) ==
1078 wpa_printf(MSG_ERROR
, "BSS '%s' may not have "
1079 "BSSID set to the MAC address of "
1080 "the radio", conf
->iface
);
1083 } else if (hapd
->iconf
->use_driver_iface_addr
) {
1086 /* Allocate the next available BSSID. */
1088 inc_byte_array(hapd
->own_addr
, ETH_ALEN
);
1089 } while (mac_in_conf(hapd
->iconf
, hapd
->own_addr
));
1092 hapd
->interface_added
= 1;
1093 if (hostapd_if_add(hapd
->iface
->bss
[0], WPA_IF_AP_BSS
,
1094 conf
->iface
, addr
, hapd
,
1095 &hapd
->drv_priv
, force_ifname
, if_addr
,
1096 conf
->bridge
[0] ? conf
->bridge
: NULL
,
1098 wpa_printf(MSG_ERROR
, "Failed to add BSS (BSSID="
1099 MACSTR
")", MAC2STR(hapd
->own_addr
));
1100 hapd
->interface_added
= 0;
1105 os_memcpy(hapd
->own_addr
, if_addr
, ETH_ALEN
);
1108 if (conf
->wmm_enabled
< 0)
1109 conf
->wmm_enabled
= hapd
->iconf
->ieee80211n
;
1111 #ifdef CONFIG_IEEE80211R_AP
1112 if (is_zero_ether_addr(conf
->r1_key_holder
))
1113 os_memcpy(conf
->r1_key_holder
, hapd
->own_addr
, ETH_ALEN
);
1114 #endif /* CONFIG_IEEE80211R_AP */
1117 if ((hapd
->conf
->mesh
& MESH_ENABLED
) && hapd
->iface
->mconf
== NULL
)
1118 flush_old_stations
= 0;
1119 #endif /* CONFIG_MESH */
1121 if (flush_old_stations
)
1122 hostapd_flush_old_stations(hapd
,
1123 WLAN_REASON_PREV_AUTH_NOT_VALID
);
1124 hostapd_set_privacy(hapd
, 0);
1126 hostapd_broadcast_wep_clear(hapd
);
1127 if (hostapd_setup_encryption(conf
->iface
, hapd
))
1131 * Fetch the SSID from the system and use it or,
1132 * if one was specified in the config file, verify they
1135 ssid_len
= hostapd_get_ssid(hapd
, ssid
, sizeof(ssid
));
1137 wpa_printf(MSG_ERROR
, "Could not read SSID from system");
1140 if (conf
->ssid
.ssid_set
) {
1142 * If SSID is specified in the config file and it differs
1143 * from what is being used then force installation of the
1146 set_ssid
= (conf
->ssid
.ssid_len
!= (size_t) ssid_len
||
1147 os_memcmp(conf
->ssid
.ssid
, ssid
, ssid_len
) != 0);
1150 * No SSID in the config file; just use the one we got
1154 conf
->ssid
.ssid_len
= ssid_len
;
1155 os_memcpy(conf
->ssid
.ssid
, ssid
, conf
->ssid
.ssid_len
);
1158 if (!hostapd_drv_none(hapd
)) {
1159 wpa_printf(MSG_ERROR
, "Using interface %s with hwaddr " MACSTR
1161 conf
->iface
, MAC2STR(hapd
->own_addr
),
1162 wpa_ssid_txt(conf
->ssid
.ssid
, conf
->ssid
.ssid_len
));
1165 if (hostapd_setup_wpa_psk(conf
)) {
1166 wpa_printf(MSG_ERROR
, "WPA-PSK setup failed.");
1170 /* Set SSID for the kernel driver (to be used in beacon and probe
1171 * response frames) */
1172 if (set_ssid
&& hostapd_set_ssid(hapd
, conf
->ssid
.ssid
,
1173 conf
->ssid
.ssid_len
)) {
1174 wpa_printf(MSG_ERROR
, "Could not set SSID for kernel driver");
1178 if (wpa_debug_level
<= MSG_MSGDUMP
)
1179 conf
->radius
->msg_dumps
= 1;
1180 #ifndef CONFIG_NO_RADIUS
1181 hapd
->radius
= radius_client_init(hapd
, conf
->radius
);
1182 if (hapd
->radius
== NULL
) {
1183 wpa_printf(MSG_ERROR
, "RADIUS client initialization failed.");
1187 if (conf
->radius_das_port
) {
1188 struct radius_das_conf das_conf
;
1189 os_memset(&das_conf
, 0, sizeof(das_conf
));
1190 das_conf
.port
= conf
->radius_das_port
;
1191 das_conf
.shared_secret
= conf
->radius_das_shared_secret
;
1192 das_conf
.shared_secret_len
=
1193 conf
->radius_das_shared_secret_len
;
1194 das_conf
.client_addr
= &conf
->radius_das_client_addr
;
1195 das_conf
.time_window
= conf
->radius_das_time_window
;
1196 das_conf
.require_event_timestamp
=
1197 conf
->radius_das_require_event_timestamp
;
1198 das_conf
.require_message_authenticator
=
1199 conf
->radius_das_require_message_authenticator
;
1200 das_conf
.ctx
= hapd
;
1201 das_conf
.disconnect
= hostapd_das_disconnect
;
1202 das_conf
.coa
= hostapd_das_coa
;
1203 hapd
->radius_das
= radius_das_init(&das_conf
);
1204 if (hapd
->radius_das
== NULL
) {
1205 wpa_printf(MSG_ERROR
, "RADIUS DAS initialization "
1210 #endif /* CONFIG_NO_RADIUS */
1212 if (hostapd_acl_init(hapd
)) {
1213 wpa_printf(MSG_ERROR
, "ACL initialization failed.");
1216 if (hostapd_init_wps(hapd
, conf
))
1220 hapd
->gas
= gas_query_ap_init(hapd
, hapd
->msg_ctx
);
1223 if (hostapd_dpp_init(hapd
))
1225 #endif /* CONFIG_DPP */
1227 if (authsrv_init(hapd
) < 0)
1230 if (ieee802_1x_init(hapd
)) {
1231 wpa_printf(MSG_ERROR
, "IEEE 802.1X initialization failed.");
1235 if ((conf
->wpa
|| conf
->osen
) && hostapd_setup_wpa(hapd
))
1238 if (accounting_init(hapd
)) {
1239 wpa_printf(MSG_ERROR
, "Accounting initialization failed.");
1243 if (conf
->ieee802_11f
&&
1244 (hapd
->iapp
= iapp_init(hapd
, conf
->iapp_iface
)) == NULL
) {
1245 wpa_printf(MSG_ERROR
, "IEEE 802.11F (IAPP) initialization "
1250 #ifdef CONFIG_INTERWORKING
1251 if (gas_serv_init(hapd
)) {
1252 wpa_printf(MSG_ERROR
, "GAS server initialization failed");
1256 if (conf
->qos_map_set_len
&&
1257 hostapd_drv_set_qos_map(hapd
, conf
->qos_map_set
,
1258 conf
->qos_map_set_len
)) {
1259 wpa_printf(MSG_ERROR
, "Failed to initialize QoS Map");
1262 #endif /* CONFIG_INTERWORKING */
1264 if (conf
->bss_load_update_period
&& bss_load_update_init(hapd
)) {
1265 wpa_printf(MSG_ERROR
, "BSS Load initialization failed");
1269 if (conf
->proxy_arp
) {
1270 if (x_snoop_init(hapd
)) {
1271 wpa_printf(MSG_ERROR
,
1272 "Generic snooping infrastructure initialization failed");
1276 if (dhcp_snoop_init(hapd
)) {
1277 wpa_printf(MSG_ERROR
,
1278 "DHCP snooping initialization failed");
1282 if (ndisc_snoop_init(hapd
)) {
1283 wpa_printf(MSG_ERROR
,
1284 "Neighbor Discovery snooping initialization failed");
1289 if (!hostapd_drv_none(hapd
) && vlan_init(hapd
)) {
1290 wpa_printf(MSG_ERROR
, "VLAN initialization failed.");
1294 if (!conf
->start_disabled
&& ieee802_11_set_beacon(hapd
) < 0)
1297 if (hapd
->wpa_auth
&& wpa_init_keys(hapd
->wpa_auth
) < 0)
1300 if (hapd
->driver
&& hapd
->driver
->set_operstate
)
1301 hapd
->driver
->set_operstate(hapd
->drv_priv
, 1);
1307 static void hostapd_tx_queue_params(struct hostapd_iface
*iface
)
1309 struct hostapd_data
*hapd
= iface
->bss
[0];
1311 struct hostapd_tx_queue_params
*p
;
1314 if ((hapd
->conf
->mesh
& MESH_ENABLED
) && iface
->mconf
== NULL
)
1316 #endif /* CONFIG_MESH */
1318 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
1319 p
= &iface
->conf
->tx_queue
[i
];
1321 if (hostapd_set_tx_queue_params(hapd
, i
, p
->aifs
, p
->cwmin
,
1322 p
->cwmax
, p
->burst
)) {
1323 wpa_printf(MSG_DEBUG
, "Failed to set TX queue "
1324 "parameters for queue %d.", i
);
1325 /* Continue anyway */
1331 static int hostapd_set_acl_list(struct hostapd_data
*hapd
,
1332 struct mac_acl_entry
*mac_acl
,
1333 int n_entries
, u8 accept_acl
)
1335 struct hostapd_acl_params
*acl_params
;
1338 acl_params
= os_zalloc(sizeof(*acl_params
) +
1339 (n_entries
* sizeof(acl_params
->mac_acl
[0])));
1343 for (i
= 0; i
< n_entries
; i
++)
1344 os_memcpy(acl_params
->mac_acl
[i
].addr
, mac_acl
[i
].addr
,
1347 acl_params
->acl_policy
= accept_acl
;
1348 acl_params
->num_mac_acl
= n_entries
;
1350 err
= hostapd_drv_set_acl(hapd
, acl_params
);
1352 os_free(acl_params
);
1358 static void hostapd_set_acl(struct hostapd_data
*hapd
)
1360 struct hostapd_config
*conf
= hapd
->iconf
;
1364 if (hapd
->iface
->drv_max_acl_mac_addrs
== 0)
1367 if (conf
->bss
[0]->macaddr_acl
== DENY_UNLESS_ACCEPTED
) {
1369 err
= hostapd_set_acl_list(hapd
, conf
->bss
[0]->accept_mac
,
1370 conf
->bss
[0]->num_accept_mac
,
1373 wpa_printf(MSG_DEBUG
, "Failed to set accept acl");
1376 } else if (conf
->bss
[0]->macaddr_acl
== ACCEPT_UNLESS_DENIED
) {
1378 err
= hostapd_set_acl_list(hapd
, conf
->bss
[0]->deny_mac
,
1379 conf
->bss
[0]->num_deny_mac
,
1382 wpa_printf(MSG_DEBUG
, "Failed to set deny acl");
1389 static int start_ctrl_iface_bss(struct hostapd_data
*hapd
)
1391 if (!hapd
->iface
->interfaces
||
1392 !hapd
->iface
->interfaces
->ctrl_iface_init
)
1395 if (hapd
->iface
->interfaces
->ctrl_iface_init(hapd
)) {
1396 wpa_printf(MSG_ERROR
,
1397 "Failed to setup control interface for %s",
1406 static int start_ctrl_iface(struct hostapd_iface
*iface
)
1410 if (!iface
->interfaces
|| !iface
->interfaces
->ctrl_iface_init
)
1413 for (i
= 0; i
< iface
->num_bss
; i
++) {
1414 struct hostapd_data
*hapd
= iface
->bss
[i
];
1415 if (iface
->interfaces
->ctrl_iface_init(hapd
)) {
1416 wpa_printf(MSG_ERROR
,
1417 "Failed to setup control interface for %s",
1427 static void channel_list_update_timeout(void *eloop_ctx
, void *timeout_ctx
)
1429 struct hostapd_iface
*iface
= eloop_ctx
;
1431 if (!iface
->wait_channel_update
) {
1432 wpa_printf(MSG_INFO
, "Channel list update timeout, but interface was not waiting for it");
1437 * It is possible that the existing channel list is acceptable, so try
1440 wpa_printf(MSG_DEBUG
, "Channel list update timeout - try to continue anyway");
1441 setup_interface2(iface
);
1445 void hostapd_channel_list_updated(struct hostapd_iface
*iface
, int initiator
)
1447 if (!iface
->wait_channel_update
|| initiator
!= REGDOM_SET_BY_USER
)
1450 wpa_printf(MSG_DEBUG
, "Channel list updated - continue setup");
1451 eloop_cancel_timeout(channel_list_update_timeout
, iface
, NULL
);
1452 setup_interface2(iface
);
1456 static int setup_interface(struct hostapd_iface
*iface
)
1458 struct hostapd_data
*hapd
= iface
->bss
[0];
1462 * It is possible that setup_interface() is called after the interface
1463 * was disabled etc., in which case driver_ap_teardown is possibly set
1464 * to 1. Clear it here so any other key/station deletion, which is not
1465 * part of a teardown flow, would also call the relevant driver
1468 iface
->driver_ap_teardown
= 0;
1470 if (!iface
->phy
[0]) {
1471 const char *phy
= hostapd_drv_get_radio_name(hapd
);
1473 wpa_printf(MSG_DEBUG
, "phy: %s", phy
);
1474 os_strlcpy(iface
->phy
, phy
, sizeof(iface
->phy
));
1479 * Make sure that all BSSes get configured with a pointer to the same
1482 for (i
= 1; i
< iface
->num_bss
; i
++) {
1483 iface
->bss
[i
]->driver
= hapd
->driver
;
1484 iface
->bss
[i
]->drv_priv
= hapd
->drv_priv
;
1487 if (hostapd_validate_bssid_configuration(iface
))
1491 * Initialize control interfaces early to allow external monitoring of
1492 * channel setup operations that may take considerable amount of time
1493 * especially for DFS cases.
1495 if (start_ctrl_iface(iface
))
1498 if (hapd
->iconf
->country
[0] && hapd
->iconf
->country
[1]) {
1499 char country
[4], previous_country
[4];
1501 hostapd_set_state(iface
, HAPD_IFACE_COUNTRY_UPDATE
);
1502 if (hostapd_get_country(hapd
, previous_country
) < 0)
1503 previous_country
[0] = '\0';
1505 os_memcpy(country
, hapd
->iconf
->country
, 3);
1507 if (hostapd_set_country(hapd
, country
) < 0) {
1508 wpa_printf(MSG_ERROR
, "Failed to set country code");
1512 wpa_printf(MSG_DEBUG
, "Previous country code %s, new country code %s",
1513 previous_country
, country
);
1515 if (os_strncmp(previous_country
, country
, 2) != 0) {
1516 wpa_printf(MSG_DEBUG
, "Continue interface setup after channel list update");
1517 iface
->wait_channel_update
= 1;
1518 eloop_register_timeout(5, 0,
1519 channel_list_update_timeout
,
1525 return setup_interface2(iface
);
1529 static int setup_interface2(struct hostapd_iface
*iface
)
1531 iface
->wait_channel_update
= 0;
1533 if (hostapd_get_hw_features(iface
)) {
1534 /* Not all drivers support this yet, so continue without hw
1537 int ret
= hostapd_select_hw_mode(iface
);
1539 wpa_printf(MSG_ERROR
, "Could not select hw_mode and "
1540 "channel. (%d)", ret
);
1544 wpa_printf(MSG_DEBUG
, "Interface initialization will be completed in a callback (ACS)");
1547 ret
= hostapd_check_ht_capab(iface
);
1551 wpa_printf(MSG_DEBUG
, "Interface initialization will "
1552 "be completed in a callback");
1556 if (iface
->conf
->ieee80211h
)
1557 wpa_printf(MSG_DEBUG
, "DFS support is enabled");
1559 return hostapd_setup_interface_complete(iface
, 0);
1562 hostapd_set_state(iface
, HAPD_IFACE_DISABLED
);
1563 wpa_msg(iface
->bss
[0]->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
1564 if (iface
->interfaces
&& iface
->interfaces
->terminate_on_error
)
1572 static const u8
* fst_hostapd_get_bssid_cb(void *ctx
)
1574 struct hostapd_data
*hapd
= ctx
;
1576 return hapd
->own_addr
;
1580 static void fst_hostapd_get_channel_info_cb(void *ctx
,
1581 enum hostapd_hw_mode
*hw_mode
,
1584 struct hostapd_data
*hapd
= ctx
;
1586 *hw_mode
= ieee80211_freq_to_chan(hapd
->iface
->freq
, channel
);
1590 static void fst_hostapd_set_ies_cb(void *ctx
, const struct wpabuf
*fst_ies
)
1592 struct hostapd_data
*hapd
= ctx
;
1594 if (hapd
->iface
->fst_ies
!= fst_ies
) {
1595 hapd
->iface
->fst_ies
= fst_ies
;
1596 if (ieee802_11_set_beacon(hapd
))
1597 wpa_printf(MSG_WARNING
, "FST: Cannot set beacon");
1602 static int fst_hostapd_send_action_cb(void *ctx
, const u8
*da
,
1605 struct hostapd_data
*hapd
= ctx
;
1607 return hostapd_drv_send_action(hapd
, hapd
->iface
->freq
, 0, da
,
1608 wpabuf_head(buf
), wpabuf_len(buf
));
1612 static const struct wpabuf
* fst_hostapd_get_mb_ie_cb(void *ctx
, const u8
*addr
)
1614 struct hostapd_data
*hapd
= ctx
;
1615 struct sta_info
*sta
= ap_get_sta(hapd
, addr
);
1617 return sta
? sta
->mb_ies
: NULL
;
1621 static void fst_hostapd_update_mb_ie_cb(void *ctx
, const u8
*addr
,
1622 const u8
*buf
, size_t size
)
1624 struct hostapd_data
*hapd
= ctx
;
1625 struct sta_info
*sta
= ap_get_sta(hapd
, addr
);
1628 struct mb_ies_info info
;
1630 if (!mb_ies_info_by_ies(&info
, buf
, size
)) {
1631 wpabuf_free(sta
->mb_ies
);
1632 sta
->mb_ies
= mb_ies_by_info(&info
);
1638 static const u8
* fst_hostapd_get_sta(struct fst_get_peer_ctx
**get_ctx
,
1641 struct sta_info
*s
= (struct sta_info
*) *get_ctx
;
1644 for (; s
&& !s
->mb_ies
; s
= s
->next
)
1649 *get_ctx
= (struct fst_get_peer_ctx
*) s
->next
;
1659 static const u8
* fst_hostapd_get_peer_first(void *ctx
,
1660 struct fst_get_peer_ctx
**get_ctx
,
1663 struct hostapd_data
*hapd
= ctx
;
1665 *get_ctx
= (struct fst_get_peer_ctx
*) hapd
->sta_list
;
1667 return fst_hostapd_get_sta(get_ctx
, mb_only
);
1671 static const u8
* fst_hostapd_get_peer_next(void *ctx
,
1672 struct fst_get_peer_ctx
**get_ctx
,
1675 return fst_hostapd_get_sta(get_ctx
, mb_only
);
1679 void fst_hostapd_fill_iface_obj(struct hostapd_data
*hapd
,
1680 struct fst_wpa_obj
*iface_obj
)
1682 iface_obj
->ctx
= hapd
;
1683 iface_obj
->get_bssid
= fst_hostapd_get_bssid_cb
;
1684 iface_obj
->get_channel_info
= fst_hostapd_get_channel_info_cb
;
1685 iface_obj
->set_ies
= fst_hostapd_set_ies_cb
;
1686 iface_obj
->send_action
= fst_hostapd_send_action_cb
;
1687 iface_obj
->get_mb_ie
= fst_hostapd_get_mb_ie_cb
;
1688 iface_obj
->update_mb_ie
= fst_hostapd_update_mb_ie_cb
;
1689 iface_obj
->get_peer_first
= fst_hostapd_get_peer_first
;
1690 iface_obj
->get_peer_next
= fst_hostapd_get_peer_next
;
1693 #endif /* CONFIG_FST */
1697 static int hostapd_owe_iface_iter(struct hostapd_iface
*iface
, void *ctx
)
1699 struct hostapd_data
*hapd
= ctx
;
1702 for (i
= 0; i
< iface
->num_bss
; i
++) {
1703 struct hostapd_data
*bss
= iface
->bss
[i
];
1705 if (os_strcmp(hapd
->conf
->owe_transition_ifname
,
1706 bss
->conf
->iface
) != 0)
1709 wpa_printf(MSG_DEBUG
,
1710 "OWE: ifname=%s found transition mode ifname=%s BSSID "
1712 hapd
->conf
->iface
, bss
->conf
->iface
,
1713 MAC2STR(bss
->own_addr
),
1714 wpa_ssid_txt(bss
->conf
->ssid
.ssid
,
1715 bss
->conf
->ssid
.ssid_len
));
1716 if (!bss
->conf
->ssid
.ssid_set
|| !bss
->conf
->ssid
.ssid_len
||
1717 is_zero_ether_addr(bss
->own_addr
))
1720 os_memcpy(hapd
->conf
->owe_transition_bssid
, bss
->own_addr
,
1722 os_memcpy(hapd
->conf
->owe_transition_ssid
,
1723 bss
->conf
->ssid
.ssid
, bss
->conf
->ssid
.ssid_len
);
1724 hapd
->conf
->owe_transition_ssid_len
= bss
->conf
->ssid
.ssid_len
;
1725 wpa_printf(MSG_DEBUG
,
1726 "OWE: Copied transition mode information");
1734 int hostapd_owe_trans_get_info(struct hostapd_data
*hapd
)
1736 if (hapd
->conf
->owe_transition_ssid_len
> 0 &&
1737 !is_zero_ether_addr(hapd
->conf
->owe_transition_bssid
))
1740 /* Find transition mode SSID/BSSID information from a BSS operated by
1741 * this hostapd instance. */
1742 if (!hapd
->iface
->interfaces
||
1743 !hapd
->iface
->interfaces
->for_each_interface
)
1744 return hostapd_owe_iface_iter(hapd
->iface
, hapd
);
1746 return hapd
->iface
->interfaces
->for_each_interface(
1747 hapd
->iface
->interfaces
, hostapd_owe_iface_iter
, hapd
);
1751 static int hostapd_owe_iface_iter2(struct hostapd_iface
*iface
, void *ctx
)
1755 for (i
= 0; i
< iface
->num_bss
; i
++) {
1756 struct hostapd_data
*bss
= iface
->bss
[i
];
1759 if (!bss
->conf
->owe_transition_ifname
[0])
1761 res
= hostapd_owe_trans_get_info(bss
);
1764 wpa_printf(MSG_DEBUG
,
1765 "OWE: Matching transition mode interface enabled - update beacon data for %s",
1767 ieee802_11_set_beacon(bss
);
1773 #endif /* CONFIG_OWE */
1776 static void hostapd_owe_update_trans(struct hostapd_iface
*iface
)
1779 /* Check whether the enabled BSS can complete OWE transition mode
1780 * configuration for any pending interface. */
1781 if (!iface
->interfaces
||
1782 !iface
->interfaces
->for_each_interface
)
1783 hostapd_owe_iface_iter2(iface
, NULL
);
1785 iface
->interfaces
->for_each_interface(
1786 iface
->interfaces
, hostapd_owe_iface_iter2
, NULL
);
1787 #endif /* CONFIG_OWE */
1791 static void hostapd_interface_setup_failure_handler(void *eloop_ctx
,
1794 struct hostapd_iface
*iface
= eloop_ctx
;
1795 struct hostapd_data
*hapd
;
1797 if (iface
->num_bss
< 1 || !iface
->bss
|| !iface
->bss
[0])
1799 hapd
= iface
->bss
[0];
1800 if (hapd
->setup_complete_cb
)
1801 hapd
->setup_complete_cb(hapd
->setup_complete_cb_ctx
);
1805 static int hostapd_setup_interface_complete_sync(struct hostapd_iface
*iface
,
1808 struct hostapd_data
*hapd
= iface
->bss
[0];
1811 int delay_apply_cfg
= 0;
1812 int res_dfs_offload
= 0;
1817 wpa_printf(MSG_DEBUG
, "Completing interface initialization");
1818 if (iface
->conf
->channel
) {
1821 #endif /* NEED_AP_MLME */
1823 iface
->freq
= hostapd_hw_get_freq(hapd
, iface
->conf
->channel
);
1824 wpa_printf(MSG_DEBUG
, "Mode: %s Channel: %d "
1825 "Frequency: %d MHz",
1826 hostapd_hw_mode_txt(iface
->conf
->hw_mode
),
1827 iface
->conf
->channel
, iface
->freq
);
1830 /* Handle DFS only if it is not offloaded to the driver */
1831 if (!(iface
->drv_flags
& WPA_DRIVER_FLAGS_DFS_OFFLOAD
)) {
1833 res
= hostapd_handle_dfs(iface
);
1840 /* If DFS is offloaded to the driver */
1841 res_dfs_offload
= hostapd_handle_dfs_offload(iface
);
1842 if (res_dfs_offload
<= 0) {
1843 if (res_dfs_offload
< 0)
1846 wpa_printf(MSG_DEBUG
,
1847 "Proceed with AP/channel setup");
1849 * If this is a DFS channel, move to completing
1852 if (res_dfs_offload
== 1)
1854 /* Otherwise fall through. */
1857 #endif /* NEED_AP_MLME */
1860 if (iface
->mconf
!= NULL
) {
1861 wpa_printf(MSG_DEBUG
,
1862 "%s: Mesh configuration will be applied while joining the mesh network",
1863 iface
->bss
[0]->conf
->iface
);
1864 delay_apply_cfg
= 1;
1866 #endif /* CONFIG_MESH */
1868 if (!delay_apply_cfg
&&
1869 hostapd_set_freq(hapd
, hapd
->iconf
->hw_mode
, iface
->freq
,
1870 hapd
->iconf
->channel
,
1871 hapd
->iconf
->ieee80211n
,
1872 hapd
->iconf
->ieee80211ac
,
1873 hapd
->iconf
->ieee80211ax
,
1874 hapd
->iconf
->secondary_channel
,
1875 hostapd_get_oper_chwidth(hapd
->iconf
),
1876 hostapd_get_oper_centr_freq_seg0_idx(
1878 hostapd_get_oper_centr_freq_seg1_idx(
1880 wpa_printf(MSG_ERROR
, "Could not set channel for "
1886 if (iface
->current_mode
) {
1887 if (hostapd_prepare_rates(iface
, iface
->current_mode
)) {
1888 wpa_printf(MSG_ERROR
, "Failed to prepare rates "
1890 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE80211
,
1891 HOSTAPD_LEVEL_WARNING
,
1892 "Failed to prepare rates table.");
1897 if (hapd
->iconf
->rts_threshold
>= -1 &&
1898 hostapd_set_rts(hapd
, hapd
->iconf
->rts_threshold
) &&
1899 hapd
->iconf
->rts_threshold
>= -1) {
1900 wpa_printf(MSG_ERROR
, "Could not set RTS threshold for "
1905 if (hapd
->iconf
->fragm_threshold
>= -1 &&
1906 hostapd_set_frag(hapd
, hapd
->iconf
->fragm_threshold
) &&
1907 hapd
->iconf
->fragm_threshold
!= -1) {
1908 wpa_printf(MSG_ERROR
, "Could not set fragmentation threshold "
1909 "for kernel driver");
1913 prev_addr
= hapd
->own_addr
;
1915 for (j
= 0; j
< iface
->num_bss
; j
++) {
1916 hapd
= iface
->bss
[j
];
1918 os_memcpy(hapd
->own_addr
, prev_addr
, ETH_ALEN
);
1919 if (hostapd_setup_bss(hapd
, j
== 0)) {
1921 hapd
= iface
->bss
[j
];
1922 hostapd_bss_deinit_no_free(hapd
);
1923 hostapd_free_hapd_data(hapd
);
1930 if (is_zero_ether_addr(hapd
->conf
->bssid
))
1931 prev_addr
= hapd
->own_addr
;
1933 hapd
= iface
->bss
[0];
1935 hostapd_tx_queue_params(iface
);
1937 ap_list_init(iface
);
1939 hostapd_set_acl(hapd
);
1941 if (hostapd_driver_commit(hapd
) < 0) {
1942 wpa_printf(MSG_ERROR
, "%s: Failed to commit driver "
1943 "configuration", __func__
);
1948 * WPS UPnP module can be initialized only when the "upnp_iface" is up.
1949 * If "interface" and "upnp_iface" are the same (e.g., non-bridge
1950 * mode), the interface is up only after driver_commit, so initialize
1951 * WPS after driver_commit.
1953 for (j
= 0; j
< iface
->num_bss
; j
++) {
1954 if (hostapd_init_wps_complete(iface
->bss
[j
]))
1958 if ((iface
->drv_flags
& WPA_DRIVER_FLAGS_DFS_OFFLOAD
) &&
1961 * If freq is DFS, and DFS is offloaded to the driver, then wait
1962 * for CAC to complete.
1964 wpa_printf(MSG_DEBUG
, "%s: Wait for CAC to complete", __func__
);
1965 return res_dfs_offload
;
1970 #endif /* NEED_AP_MLME */
1973 if (hapd
->iconf
->fst_cfg
.group_id
[0]) {
1974 struct fst_wpa_obj iface_obj
;
1976 fst_hostapd_fill_iface_obj(hapd
, &iface_obj
);
1977 iface
->fst
= fst_attach(hapd
->conf
->iface
, hapd
->own_addr
,
1978 &iface_obj
, &hapd
->iconf
->fst_cfg
);
1980 wpa_printf(MSG_ERROR
, "Could not attach to FST %s",
1981 hapd
->iconf
->fst_cfg
.group_id
);
1985 #endif /* CONFIG_FST */
1987 hostapd_set_state(iface
, HAPD_IFACE_ENABLED
);
1988 hostapd_owe_update_trans(iface
);
1989 airtime_policy_update_init(iface
);
1990 wpa_msg(iface
->bss
[0]->msg_ctx
, MSG_INFO
, AP_EVENT_ENABLED
);
1991 if (hapd
->setup_complete_cb
)
1992 hapd
->setup_complete_cb(hapd
->setup_complete_cb_ctx
);
1994 wpa_printf(MSG_DEBUG
, "%s: Setup of interface done.",
1995 iface
->bss
[0]->conf
->iface
);
1996 if (iface
->interfaces
&& iface
->interfaces
->terminate_on_error
> 0)
1997 iface
->interfaces
->terminate_on_error
--;
1999 for (j
= 0; j
< iface
->num_bss
; j
++)
2000 hostapd_neighbor_set_own_report(iface
->bss
[j
]);
2005 wpa_printf(MSG_ERROR
, "Interface initialization failed");
2006 hostapd_set_state(iface
, HAPD_IFACE_DISABLED
);
2007 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
2010 fst_detach(iface
->fst
);
2013 #endif /* CONFIG_FST */
2015 if (iface
->interfaces
&& iface
->interfaces
->terminate_on_error
) {
2017 } else if (hapd
->setup_complete_cb
) {
2019 * Calling hapd->setup_complete_cb directly may cause iface
2020 * deinitialization which may be accessed later by the caller.
2022 eloop_register_timeout(0, 0,
2023 hostapd_interface_setup_failure_handler
,
2032 * hostapd_setup_interface_complete - Complete interface setup
2034 * This function is called when previous steps in the interface setup has been
2035 * completed. This can also start operations, e.g., DFS, that will require
2036 * additional processing before interface is ready to be enabled. Such
2037 * operations will call this function from eloop callbacks when finished.
2039 int hostapd_setup_interface_complete(struct hostapd_iface
*iface
, int err
)
2041 struct hapd_interfaces
*interfaces
= iface
->interfaces
;
2042 struct hostapd_data
*hapd
= iface
->bss
[0];
2044 int not_ready_in_sync_ifaces
= 0;
2046 if (!iface
->need_to_start_in_sync
)
2047 return hostapd_setup_interface_complete_sync(iface
, err
);
2050 wpa_printf(MSG_ERROR
, "Interface initialization failed");
2051 hostapd_set_state(iface
, HAPD_IFACE_DISABLED
);
2052 iface
->need_to_start_in_sync
= 0;
2053 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
2054 if (interfaces
&& interfaces
->terminate_on_error
)
2059 if (iface
->ready_to_start_in_sync
) {
2060 /* Already in ready and waiting. should never happpen */
2064 for (i
= 0; i
< interfaces
->count
; i
++) {
2065 if (interfaces
->iface
[i
]->need_to_start_in_sync
&&
2066 !interfaces
->iface
[i
]->ready_to_start_in_sync
)
2067 not_ready_in_sync_ifaces
++;
2071 * Check if this is the last interface, if yes then start all the other
2072 * waiting interfaces. If not, add this interface to the waiting list.
2074 if (not_ready_in_sync_ifaces
> 1 && iface
->state
== HAPD_IFACE_DFS
) {
2076 * If this interface went through CAC, do not synchronize, just
2077 * start immediately.
2079 iface
->need_to_start_in_sync
= 0;
2080 wpa_printf(MSG_INFO
,
2081 "%s: Finished CAC - bypass sync and start interface",
2082 iface
->bss
[0]->conf
->iface
);
2083 return hostapd_setup_interface_complete_sync(iface
, err
);
2086 if (not_ready_in_sync_ifaces
> 1) {
2087 /* need to wait as there are other interfaces still coming up */
2088 iface
->ready_to_start_in_sync
= 1;
2089 wpa_printf(MSG_INFO
,
2090 "%s: Interface waiting to sync with other interfaces",
2091 iface
->bss
[0]->conf
->iface
);
2095 wpa_printf(MSG_INFO
,
2096 "%s: Last interface to sync - starting all interfaces",
2097 iface
->bss
[0]->conf
->iface
);
2098 iface
->need_to_start_in_sync
= 0;
2099 hostapd_setup_interface_complete_sync(iface
, err
);
2100 for (i
= 0; i
< interfaces
->count
; i
++) {
2101 if (interfaces
->iface
[i
]->need_to_start_in_sync
&&
2102 interfaces
->iface
[i
]->ready_to_start_in_sync
) {
2103 hostapd_setup_interface_complete_sync(
2104 interfaces
->iface
[i
], 0);
2105 /* Only once the interfaces are sync started */
2106 interfaces
->iface
[i
]->need_to_start_in_sync
= 0;
2115 * hostapd_setup_interface - Setup of an interface
2116 * @iface: Pointer to interface data.
2117 * Returns: 0 on success, -1 on failure
2119 * Initializes the driver interface, validates the configuration,
2120 * and sets driver parameters based on the configuration.
2121 * Flushes old stations, sets the channel, encryption,
2122 * beacons, and WDS links based on the configuration.
2124 * If interface setup requires more time, e.g., to perform HT co-ex scans, ACS,
2125 * or DFS operations, this function returns 0 before such operations have been
2126 * completed. The pending operations are registered into eloop and will be
2127 * completed from eloop callbacks. Those callbacks end up calling
2128 * hostapd_setup_interface_complete() once setup has been completed.
2130 int hostapd_setup_interface(struct hostapd_iface
*iface
)
2134 ret
= setup_interface(iface
);
2136 wpa_printf(MSG_ERROR
, "%s: Unable to setup interface.",
2137 iface
->bss
[0]->conf
->iface
);
2146 * hostapd_alloc_bss_data - Allocate and initialize per-BSS data
2147 * @hapd_iface: Pointer to interface data
2148 * @conf: Pointer to per-interface configuration
2149 * @bss: Pointer to per-BSS configuration for this BSS
2150 * Returns: Pointer to allocated BSS data
2152 * This function is used to allocate per-BSS data structure. This data will be
2153 * freed after hostapd_cleanup() is called for it during interface
2156 struct hostapd_data
*
2157 hostapd_alloc_bss_data(struct hostapd_iface
*hapd_iface
,
2158 struct hostapd_config
*conf
,
2159 struct hostapd_bss_config
*bss
)
2161 struct hostapd_data
*hapd
;
2163 hapd
= os_zalloc(sizeof(*hapd
));
2167 hapd
->new_assoc_sta_cb
= hostapd_new_assoc_sta
;
2170 hapd
->iface
= hapd_iface
;
2172 hapd
->driver
= conf
->driver
;
2173 hapd
->ctrl_sock
= -1;
2174 dl_list_init(&hapd
->ctrl_dst
);
2175 dl_list_init(&hapd
->nr_db
);
2176 hapd
->dhcp_sock
= -1;
2177 #ifdef CONFIG_IEEE80211R_AP
2178 dl_list_init(&hapd
->l2_queue
);
2179 dl_list_init(&hapd
->l2_oui_queue
);
2180 #endif /* CONFIG_IEEE80211R_AP */
2182 dl_list_init(&hapd
->sae_commit_queue
);
2183 #endif /* CONFIG_SAE */
2189 static void hostapd_bss_deinit(struct hostapd_data
*hapd
)
2193 wpa_printf(MSG_DEBUG
, "%s: deinit bss %s", __func__
,
2194 hapd
->conf
? hapd
->conf
->iface
: "N/A");
2195 hostapd_bss_deinit_no_free(hapd
);
2196 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
2197 hostapd_cleanup(hapd
);
2201 void hostapd_interface_deinit(struct hostapd_iface
*iface
)
2205 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
2209 hostapd_set_state(iface
, HAPD_IFACE_DISABLED
);
2211 eloop_cancel_timeout(channel_list_update_timeout
, iface
, NULL
);
2212 iface
->wait_channel_update
= 0;
2216 fst_detach(iface
->fst
);
2219 #endif /* CONFIG_FST */
2221 for (j
= (int) iface
->num_bss
- 1; j
>= 0; j
--) {
2224 hostapd_bss_deinit(iface
->bss
[j
]);
2227 #ifdef CONFIG_IEEE80211N
2229 hostapd_stop_setup_timers(iface
);
2230 eloop_cancel_timeout(ap_ht2040_timeout
, iface
, NULL
);
2231 #endif /* NEED_AP_MLME */
2232 #endif /* CONFIG_IEEE80211N */
2236 void hostapd_interface_free(struct hostapd_iface
*iface
)
2239 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
2240 for (j
= 0; j
< iface
->num_bss
; j
++) {
2243 wpa_printf(MSG_DEBUG
, "%s: free hapd %p",
2244 __func__
, iface
->bss
[j
]);
2245 os_free(iface
->bss
[j
]);
2247 hostapd_cleanup_iface(iface
);
2251 struct hostapd_iface
* hostapd_alloc_iface(void)
2253 struct hostapd_iface
*hapd_iface
;
2255 hapd_iface
= os_zalloc(sizeof(*hapd_iface
));
2259 dl_list_init(&hapd_iface
->sta_seen
);
2266 * hostapd_init - Allocate and initialize per-interface data
2267 * @config_file: Path to the configuration file
2268 * Returns: Pointer to the allocated interface data or %NULL on failure
2270 * This function is used to allocate main data structures for per-interface
2271 * data. The allocated data buffer will be freed by calling
2272 * hostapd_cleanup_iface().
2274 struct hostapd_iface
* hostapd_init(struct hapd_interfaces
*interfaces
,
2275 const char *config_file
)
2277 struct hostapd_iface
*hapd_iface
= NULL
;
2278 struct hostapd_config
*conf
= NULL
;
2279 struct hostapd_data
*hapd
;
2282 hapd_iface
= hostapd_alloc_iface();
2283 if (hapd_iface
== NULL
)
2286 hapd_iface
->config_fname
= os_strdup(config_file
);
2287 if (hapd_iface
->config_fname
== NULL
)
2290 conf
= interfaces
->config_read_cb(hapd_iface
->config_fname
);
2293 hapd_iface
->conf
= conf
;
2295 hapd_iface
->num_bss
= conf
->num_bss
;
2296 hapd_iface
->bss
= os_calloc(conf
->num_bss
,
2297 sizeof(struct hostapd_data
*));
2298 if (hapd_iface
->bss
== NULL
)
2301 for (i
= 0; i
< conf
->num_bss
; i
++) {
2302 hapd
= hapd_iface
->bss
[i
] =
2303 hostapd_alloc_bss_data(hapd_iface
, conf
,
2307 hapd
->msg_ctx
= hapd
;
2313 wpa_printf(MSG_ERROR
, "Failed to set up interface with %s",
2316 hostapd_config_free(conf
);
2318 os_free(hapd_iface
->config_fname
);
2319 os_free(hapd_iface
->bss
);
2320 wpa_printf(MSG_DEBUG
, "%s: free iface %p",
2321 __func__
, hapd_iface
);
2322 os_free(hapd_iface
);
2328 static int ifname_in_use(struct hapd_interfaces
*interfaces
, const char *ifname
)
2332 for (i
= 0; i
< interfaces
->count
; i
++) {
2333 struct hostapd_iface
*iface
= interfaces
->iface
[i
];
2334 for (j
= 0; j
< iface
->num_bss
; j
++) {
2335 struct hostapd_data
*hapd
= iface
->bss
[j
];
2336 if (os_strcmp(ifname
, hapd
->conf
->iface
) == 0)
2346 * hostapd_interface_init_bss - Read configuration file and init BSS data
2348 * This function is used to parse configuration file for a BSS. This BSS is
2349 * added to an existing interface sharing the same radio (if any) or a new
2350 * interface is created if this is the first interface on a radio. This
2351 * allocate memory for the BSS. No actual driver operations are started.
2353 * This is similar to hostapd_interface_init(), but for a case where the
2354 * configuration is used to add a single BSS instead of all BSSes for a radio.
2356 struct hostapd_iface
*
2357 hostapd_interface_init_bss(struct hapd_interfaces
*interfaces
, const char *phy
,
2358 const char *config_fname
, int debug
)
2360 struct hostapd_iface
*new_iface
= NULL
, *iface
= NULL
;
2361 struct hostapd_data
*hapd
;
2368 for (i
= 0; i
< interfaces
->count
; i
++) {
2369 if (os_strcmp(interfaces
->iface
[i
]->phy
, phy
) == 0) {
2370 iface
= interfaces
->iface
[i
];
2375 wpa_printf(MSG_INFO
, "Configuration file: %s (phy %s)%s",
2376 config_fname
, phy
, iface
? "" : " --> new PHY");
2378 struct hostapd_config
*conf
;
2379 struct hostapd_bss_config
**tmp_conf
;
2380 struct hostapd_data
**tmp_bss
;
2381 struct hostapd_bss_config
*bss
;
2384 /* Add new BSS to existing iface */
2385 conf
= interfaces
->config_read_cb(config_fname
);
2388 if (conf
->num_bss
> 1) {
2389 wpa_printf(MSG_ERROR
, "Multiple BSSes specified in BSS-config");
2390 hostapd_config_free(conf
);
2394 ifname
= conf
->bss
[0]->iface
;
2395 if (ifname
[0] != '\0' && ifname_in_use(interfaces
, ifname
)) {
2396 wpa_printf(MSG_ERROR
,
2397 "Interface name %s already in use", ifname
);
2398 hostapd_config_free(conf
);
2402 tmp_conf
= os_realloc_array(
2403 iface
->conf
->bss
, iface
->conf
->num_bss
+ 1,
2404 sizeof(struct hostapd_bss_config
*));
2405 tmp_bss
= os_realloc_array(iface
->bss
, iface
->num_bss
+ 1,
2406 sizeof(struct hostapd_data
*));
2408 iface
->bss
= tmp_bss
;
2410 iface
->conf
->bss
= tmp_conf
;
2411 iface
->conf
->last_bss
= tmp_conf
[0];
2413 if (tmp_bss
== NULL
|| tmp_conf
== NULL
) {
2414 hostapd_config_free(conf
);
2417 bss
= iface
->conf
->bss
[iface
->conf
->num_bss
] = conf
->bss
[0];
2418 iface
->conf
->num_bss
++;
2420 hapd
= hostapd_alloc_bss_data(iface
, iface
->conf
, bss
);
2422 iface
->conf
->num_bss
--;
2423 hostapd_config_free(conf
);
2426 iface
->conf
->last_bss
= bss
;
2427 iface
->bss
[iface
->num_bss
] = hapd
;
2428 hapd
->msg_ctx
= hapd
;
2430 bss_idx
= iface
->num_bss
++;
2432 conf
->bss
[0] = NULL
;
2433 hostapd_config_free(conf
);
2435 /* Add a new iface with the first BSS */
2436 new_iface
= iface
= hostapd_init(interfaces
, config_fname
);
2439 os_strlcpy(iface
->phy
, phy
, sizeof(iface
->phy
));
2440 iface
->interfaces
= interfaces
;
2444 for (k
= 0; k
< debug
; k
++) {
2445 if (iface
->bss
[bss_idx
]->conf
->logger_stdout_level
> 0)
2446 iface
->bss
[bss_idx
]->conf
->logger_stdout_level
--;
2449 if (iface
->conf
->bss
[bss_idx
]->iface
[0] == '\0' &&
2450 !hostapd_drv_none(iface
->bss
[bss_idx
])) {
2451 wpa_printf(MSG_ERROR
, "Interface name not specified in %s",
2454 hostapd_interface_deinit_free(new_iface
);
2462 void hostapd_interface_deinit_free(struct hostapd_iface
*iface
)
2464 const struct wpa_driver_ops
*driver
;
2467 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
2470 wpa_printf(MSG_DEBUG
, "%s: num_bss=%u conf->num_bss=%u",
2471 __func__
, (unsigned int) iface
->num_bss
,
2472 (unsigned int) iface
->conf
->num_bss
);
2473 driver
= iface
->bss
[0]->driver
;
2474 drv_priv
= iface
->bss
[0]->drv_priv
;
2475 hostapd_interface_deinit(iface
);
2476 wpa_printf(MSG_DEBUG
, "%s: driver=%p drv_priv=%p -> hapd_deinit",
2477 __func__
, driver
, drv_priv
);
2478 if (driver
&& driver
->hapd_deinit
&& drv_priv
) {
2479 driver
->hapd_deinit(drv_priv
);
2480 iface
->bss
[0]->drv_priv
= NULL
;
2482 hostapd_interface_free(iface
);
2486 static void hostapd_deinit_driver(const struct wpa_driver_ops
*driver
,
2488 struct hostapd_iface
*hapd_iface
)
2492 wpa_printf(MSG_DEBUG
, "%s: driver=%p drv_priv=%p -> hapd_deinit",
2493 __func__
, driver
, drv_priv
);
2494 if (driver
&& driver
->hapd_deinit
&& drv_priv
) {
2495 driver
->hapd_deinit(drv_priv
);
2496 for (j
= 0; j
< hapd_iface
->num_bss
; j
++) {
2497 wpa_printf(MSG_DEBUG
, "%s:bss[%d]->drv_priv=%p",
2499 hapd_iface
->bss
[j
]->drv_priv
);
2500 if (hapd_iface
->bss
[j
]->drv_priv
== drv_priv
) {
2501 hapd_iface
->bss
[j
]->drv_priv
= NULL
;
2502 hapd_iface
->extended_capa
= NULL
;
2503 hapd_iface
->extended_capa_mask
= NULL
;
2504 hapd_iface
->extended_capa_len
= 0;
2511 int hostapd_enable_iface(struct hostapd_iface
*hapd_iface
)
2515 if (hapd_iface
->bss
[0]->drv_priv
!= NULL
) {
2516 wpa_printf(MSG_ERROR
, "Interface %s already enabled",
2517 hapd_iface
->conf
->bss
[0]->iface
);
2521 wpa_printf(MSG_DEBUG
, "Enable interface %s",
2522 hapd_iface
->conf
->bss
[0]->iface
);
2524 for (j
= 0; j
< hapd_iface
->num_bss
; j
++)
2525 hostapd_set_security_params(hapd_iface
->conf
->bss
[j
], 1);
2526 if (hostapd_config_check(hapd_iface
->conf
, 1) < 0) {
2527 wpa_printf(MSG_INFO
, "Invalid configuration - cannot enable");
2531 if (hapd_iface
->interfaces
== NULL
||
2532 hapd_iface
->interfaces
->driver_init
== NULL
||
2533 hapd_iface
->interfaces
->driver_init(hapd_iface
))
2536 if (hostapd_setup_interface(hapd_iface
)) {
2537 hostapd_deinit_driver(hapd_iface
->bss
[0]->driver
,
2538 hapd_iface
->bss
[0]->drv_priv
,
2547 int hostapd_reload_iface(struct hostapd_iface
*hapd_iface
)
2551 wpa_printf(MSG_DEBUG
, "Reload interface %s",
2552 hapd_iface
->conf
->bss
[0]->iface
);
2553 for (j
= 0; j
< hapd_iface
->num_bss
; j
++)
2554 hostapd_set_security_params(hapd_iface
->conf
->bss
[j
], 1);
2555 if (hostapd_config_check(hapd_iface
->conf
, 1) < 0) {
2556 wpa_printf(MSG_ERROR
, "Updated configuration is invalid");
2559 hostapd_clear_old(hapd_iface
);
2560 for (j
= 0; j
< hapd_iface
->num_bss
; j
++)
2561 hostapd_reload_bss(hapd_iface
->bss
[j
]);
2567 int hostapd_disable_iface(struct hostapd_iface
*hapd_iface
)
2570 const struct wpa_driver_ops
*driver
;
2573 if (hapd_iface
== NULL
)
2576 if (hapd_iface
->bss
[0]->drv_priv
== NULL
) {
2577 wpa_printf(MSG_INFO
, "Interface %s already disabled",
2578 hapd_iface
->conf
->bss
[0]->iface
);
2582 wpa_msg(hapd_iface
->bss
[0]->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
2583 driver
= hapd_iface
->bss
[0]->driver
;
2584 drv_priv
= hapd_iface
->bss
[0]->drv_priv
;
2586 hapd_iface
->driver_ap_teardown
=
2587 !!(hapd_iface
->drv_flags
&
2588 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT
);
2591 for (j
= 0; j
< hapd_iface
->num_bss
; j
++)
2592 hostapd_cleanup_cs_params(hapd_iface
->bss
[j
]);
2593 #endif /* NEED_AP_MLME */
2595 /* same as hostapd_interface_deinit without deinitializing ctrl-iface */
2596 for (j
= 0; j
< hapd_iface
->num_bss
; j
++) {
2597 struct hostapd_data
*hapd
= hapd_iface
->bss
[j
];
2598 hostapd_bss_deinit_no_free(hapd
);
2599 hostapd_free_hapd_data(hapd
);
2602 hostapd_deinit_driver(driver
, drv_priv
, hapd_iface
);
2604 /* From hostapd_cleanup_iface: These were initialized in
2605 * hostapd_setup_interface and hostapd_setup_interface_complete
2607 hostapd_cleanup_iface_partial(hapd_iface
);
2609 wpa_printf(MSG_DEBUG
, "Interface %s disabled",
2610 hapd_iface
->bss
[0]->conf
->iface
);
2611 hostapd_set_state(hapd_iface
, HAPD_IFACE_DISABLED
);
2616 static struct hostapd_iface
*
2617 hostapd_iface_alloc(struct hapd_interfaces
*interfaces
)
2619 struct hostapd_iface
**iface
, *hapd_iface
;
2621 iface
= os_realloc_array(interfaces
->iface
, interfaces
->count
+ 1,
2622 sizeof(struct hostapd_iface
*));
2625 interfaces
->iface
= iface
;
2626 hapd_iface
= interfaces
->iface
[interfaces
->count
] =
2627 hostapd_alloc_iface();
2628 if (hapd_iface
== NULL
) {
2629 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory for "
2630 "the interface", __func__
);
2633 interfaces
->count
++;
2634 hapd_iface
->interfaces
= interfaces
;
2640 static struct hostapd_config
*
2641 hostapd_config_alloc(struct hapd_interfaces
*interfaces
, const char *ifname
,
2642 const char *ctrl_iface
, const char *driver
)
2644 struct hostapd_bss_config
*bss
;
2645 struct hostapd_config
*conf
;
2647 /* Allocates memory for bss and conf */
2648 conf
= hostapd_config_defaults();
2650 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory for "
2651 "configuration", __func__
);
2658 for (j
= 0; wpa_drivers
[j
]; j
++) {
2659 if (os_strcmp(driver
, wpa_drivers
[j
]->name
) == 0) {
2660 conf
->driver
= wpa_drivers
[j
];
2665 wpa_printf(MSG_ERROR
,
2666 "Invalid/unknown driver '%s' - registering the default driver",
2670 conf
->driver
= wpa_drivers
[0];
2671 if (conf
->driver
== NULL
) {
2672 wpa_printf(MSG_ERROR
, "No driver wrappers registered!");
2673 hostapd_config_free(conf
);
2678 bss
= conf
->last_bss
= conf
->bss
[0];
2680 os_strlcpy(bss
->iface
, ifname
, sizeof(bss
->iface
));
2681 bss
->ctrl_interface
= os_strdup(ctrl_iface
);
2682 if (bss
->ctrl_interface
== NULL
) {
2683 hostapd_config_free(conf
);
2687 /* Reading configuration file skipped, will be done in SET!
2688 * From reading the configuration till the end has to be done in
2695 static int hostapd_data_alloc(struct hostapd_iface
*hapd_iface
,
2696 struct hostapd_config
*conf
)
2699 struct hostapd_data
*hapd
;
2701 hapd_iface
->bss
= os_calloc(conf
->num_bss
,
2702 sizeof(struct hostapd_data
*));
2703 if (hapd_iface
->bss
== NULL
)
2706 for (i
= 0; i
< conf
->num_bss
; i
++) {
2707 hapd
= hapd_iface
->bss
[i
] =
2708 hostapd_alloc_bss_data(hapd_iface
, conf
, conf
->bss
[i
]);
2712 os_free(hapd_iface
->bss
[i
]);
2713 hapd_iface
->bss
[i
] = NULL
;
2715 os_free(hapd_iface
->bss
);
2716 hapd_iface
->bss
= NULL
;
2719 hapd
->msg_ctx
= hapd
;
2722 hapd_iface
->conf
= conf
;
2723 hapd_iface
->num_bss
= conf
->num_bss
;
2729 int hostapd_add_iface(struct hapd_interfaces
*interfaces
, char *buf
)
2731 struct hostapd_config
*conf
= NULL
;
2732 struct hostapd_iface
*hapd_iface
= NULL
, *new_iface
= NULL
;
2733 struct hostapd_data
*hapd
;
2736 const char *conf_file
= NULL
, *phy_name
= NULL
;
2738 if (os_strncmp(buf
, "bss_config=", 11) == 0) {
2740 phy_name
= buf
+ 11;
2741 pos
= os_strchr(phy_name
, ':');
2746 if (!os_strlen(conf_file
))
2749 hapd_iface
= hostapd_interface_init_bss(interfaces
, phy_name
,
2753 for (j
= 0; j
< interfaces
->count
; j
++) {
2754 if (interfaces
->iface
[j
] == hapd_iface
)
2757 if (j
== interfaces
->count
) {
2758 struct hostapd_iface
**tmp
;
2759 tmp
= os_realloc_array(interfaces
->iface
,
2760 interfaces
->count
+ 1,
2761 sizeof(struct hostapd_iface
*));
2763 hostapd_interface_deinit_free(hapd_iface
);
2766 interfaces
->iface
= tmp
;
2767 interfaces
->iface
[interfaces
->count
++] = hapd_iface
;
2768 new_iface
= hapd_iface
;
2772 if (interfaces
->driver_init(hapd_iface
))
2775 if (hostapd_setup_interface(hapd_iface
)) {
2776 hostapd_deinit_driver(
2777 hapd_iface
->bss
[0]->driver
,
2778 hapd_iface
->bss
[0]->drv_priv
,
2783 /* Assign new BSS with bss[0]'s driver info */
2784 hapd
= hapd_iface
->bss
[hapd_iface
->num_bss
- 1];
2785 hapd
->driver
= hapd_iface
->bss
[0]->driver
;
2786 hapd
->drv_priv
= hapd_iface
->bss
[0]->drv_priv
;
2787 os_memcpy(hapd
->own_addr
, hapd_iface
->bss
[0]->own_addr
,
2790 if (start_ctrl_iface_bss(hapd
) < 0 ||
2791 (hapd_iface
->state
== HAPD_IFACE_ENABLED
&&
2792 hostapd_setup_bss(hapd
, -1))) {
2793 hostapd_cleanup(hapd
);
2794 hapd_iface
->bss
[hapd_iface
->num_bss
- 1] = NULL
;
2795 hapd_iface
->conf
->num_bss
--;
2796 hapd_iface
->num_bss
--;
2797 wpa_printf(MSG_DEBUG
, "%s: free hapd %p %s",
2798 __func__
, hapd
, hapd
->conf
->iface
);
2799 hostapd_config_free_bss(hapd
->conf
);
2805 hostapd_owe_update_trans(hapd_iface
);
2809 ptr
= os_strchr(buf
, ' ');
2814 if (os_strncmp(ptr
, "config=", 7) == 0)
2815 conf_file
= ptr
+ 7;
2817 for (i
= 0; i
< interfaces
->count
; i
++) {
2818 if (!os_strcmp(interfaces
->iface
[i
]->conf
->bss
[0]->iface
,
2820 wpa_printf(MSG_INFO
, "Cannot add interface - it "
2826 hapd_iface
= hostapd_iface_alloc(interfaces
);
2827 if (hapd_iface
== NULL
) {
2828 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory "
2829 "for interface", __func__
);
2832 new_iface
= hapd_iface
;
2834 if (conf_file
&& interfaces
->config_read_cb
) {
2835 conf
= interfaces
->config_read_cb(conf_file
);
2836 if (conf
&& conf
->bss
)
2837 os_strlcpy(conf
->bss
[0]->iface
, buf
,
2838 sizeof(conf
->bss
[0]->iface
));
2840 char *driver
= os_strchr(ptr
, ' ');
2844 conf
= hostapd_config_alloc(interfaces
, buf
, ptr
, driver
);
2847 if (conf
== NULL
|| conf
->bss
== NULL
) {
2848 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory "
2849 "for configuration", __func__
);
2853 if (hostapd_data_alloc(hapd_iface
, conf
) < 0) {
2854 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory "
2855 "for hostapd", __func__
);
2860 if (start_ctrl_iface(hapd_iface
) < 0)
2863 wpa_printf(MSG_INFO
, "Add interface '%s'",
2864 hapd_iface
->conf
->bss
[0]->iface
);
2870 hostapd_config_free(conf
);
2872 if (hapd_iface
->bss
) {
2873 for (i
= 0; i
< hapd_iface
->num_bss
; i
++) {
2874 hapd
= hapd_iface
->bss
[i
];
2877 if (hapd_iface
->interfaces
&&
2878 hapd_iface
->interfaces
->ctrl_iface_deinit
)
2879 hapd_iface
->interfaces
->
2880 ctrl_iface_deinit(hapd
);
2881 wpa_printf(MSG_DEBUG
, "%s: free hapd %p (%s)",
2882 __func__
, hapd_iface
->bss
[i
],
2884 hostapd_cleanup(hapd
);
2886 hapd_iface
->bss
[i
] = NULL
;
2888 os_free(hapd_iface
->bss
);
2889 hapd_iface
->bss
= NULL
;
2892 interfaces
->count
--;
2893 interfaces
->iface
[interfaces
->count
] = NULL
;
2895 hostapd_cleanup_iface(hapd_iface
);
2901 static int hostapd_remove_bss(struct hostapd_iface
*iface
, unsigned int idx
)
2905 wpa_printf(MSG_INFO
, "Remove BSS '%s'", iface
->conf
->bss
[idx
]->iface
);
2907 /* Remove hostapd_data only if it has already been initialized */
2908 if (idx
< iface
->num_bss
) {
2909 struct hostapd_data
*hapd
= iface
->bss
[idx
];
2911 hostapd_bss_deinit(hapd
);
2912 wpa_printf(MSG_DEBUG
, "%s: free hapd %p (%s)",
2913 __func__
, hapd
, hapd
->conf
->iface
);
2914 hostapd_config_free_bss(hapd
->conf
);
2920 for (i
= idx
; i
< iface
->num_bss
; i
++)
2921 iface
->bss
[i
] = iface
->bss
[i
+ 1];
2923 hostapd_config_free_bss(iface
->conf
->bss
[idx
]);
2924 iface
->conf
->bss
[idx
] = NULL
;
2927 iface
->conf
->num_bss
--;
2928 for (i
= idx
; i
< iface
->conf
->num_bss
; i
++)
2929 iface
->conf
->bss
[i
] = iface
->conf
->bss
[i
+ 1];
2935 int hostapd_remove_iface(struct hapd_interfaces
*interfaces
, char *buf
)
2937 struct hostapd_iface
*hapd_iface
;
2940 for (i
= 0; i
< interfaces
->count
; i
++) {
2941 hapd_iface
= interfaces
->iface
[i
];
2942 if (hapd_iface
== NULL
)
2944 if (!os_strcmp(hapd_iface
->conf
->bss
[0]->iface
, buf
)) {
2945 wpa_printf(MSG_INFO
, "Remove interface '%s'", buf
);
2946 hapd_iface
->driver_ap_teardown
=
2947 !!(hapd_iface
->drv_flags
&
2948 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT
);
2950 hostapd_interface_deinit_free(hapd_iface
);
2952 while (k
< (interfaces
->count
- 1)) {
2953 interfaces
->iface
[k
] =
2954 interfaces
->iface
[k
+ 1];
2957 interfaces
->count
--;
2961 for (j
= 0; j
< hapd_iface
->conf
->num_bss
; j
++) {
2962 if (!os_strcmp(hapd_iface
->conf
->bss
[j
]->iface
, buf
)) {
2963 hapd_iface
->driver_ap_teardown
=
2964 !(hapd_iface
->drv_flags
&
2965 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT
);
2966 return hostapd_remove_bss(hapd_iface
, j
);
2975 * hostapd_new_assoc_sta - Notify that a new station associated with the AP
2976 * @hapd: Pointer to BSS data
2977 * @sta: Pointer to the associated STA data
2978 * @reassoc: 1 to indicate this was a re-association; 0 = first association
2980 * This function will be called whenever a station associates with the AP. It
2981 * can be called from ieee802_11.c for drivers that export MLME to hostapd and
2982 * from drv_callbacks.c based on driver events for drivers that take care of
2983 * management frames (IEEE 802.11 authentication and association) internally.
2985 void hostapd_new_assoc_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2988 if (hapd
->tkip_countermeasures
) {
2989 hostapd_drv_sta_deauth(hapd
, sta
->addr
,
2990 WLAN_REASON_MICHAEL_MIC_FAILURE
);
2994 hostapd_prune_associations(hapd
, sta
->addr
);
2995 ap_sta_clear_disconnect_timeouts(hapd
, sta
);
2997 /* IEEE 802.11F (IAPP) */
2998 if (hapd
->conf
->ieee802_11f
)
2999 iapp_new_station(hapd
->iapp
, sta
);
3002 if (sta
->p2p_ie
== NULL
&& !sta
->no_p2p_set
) {
3003 sta
->no_p2p_set
= 1;
3004 hapd
->num_sta_no_p2p
++;
3005 if (hapd
->num_sta_no_p2p
== 1)
3006 hostapd_p2p_non_p2p_sta_connected(hapd
);
3008 #endif /* CONFIG_P2P */
3010 airtime_policy_new_sta(hapd
, sta
);
3012 /* Start accounting here, if IEEE 802.1X and WPA are not used.
3013 * IEEE 802.1X/WPA code will start accounting after the station has
3014 * been authorized. */
3015 if (!hapd
->conf
->ieee802_1x
&& !hapd
->conf
->wpa
&& !hapd
->conf
->osen
) {
3016 ap_sta_set_authorized(hapd
, sta
, 1);
3017 os_get_reltime(&sta
->connected_time
);
3018 accounting_sta_start(hapd
, sta
);
3021 /* Start IEEE 802.1X authentication process for new stations */
3022 ieee802_1x_new_station(hapd
, sta
);
3024 if (sta
->auth_alg
!= WLAN_AUTH_FT
&&
3025 sta
->auth_alg
!= WLAN_AUTH_FILS_SK
&&
3026 sta
->auth_alg
!= WLAN_AUTH_FILS_SK_PFS
&&
3027 sta
->auth_alg
!= WLAN_AUTH_FILS_PK
&&
3028 !(sta
->flags
& (WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
)))
3029 wpa_auth_sm_event(sta
->wpa_sm
, WPA_REAUTH
);
3031 wpa_auth_sta_associated(hapd
->wpa_auth
, sta
->wpa_sm
);
3033 if (hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
) {
3034 if (eloop_cancel_timeout(ap_handle_timer
, hapd
, sta
) > 0) {
3035 wpa_printf(MSG_DEBUG
,
3036 "%s: %s: canceled wired ap_handle_timer timeout for "
3038 hapd
->conf
->iface
, __func__
,
3039 MAC2STR(sta
->addr
));
3041 } else if (!(hapd
->iface
->drv_flags
&
3042 WPA_DRIVER_FLAGS_INACTIVITY_TIMER
)) {
3043 wpa_printf(MSG_DEBUG
,
3044 "%s: %s: reschedule ap_handle_timer timeout for "
3045 MACSTR
" (%d seconds - ap_max_inactivity)",
3046 hapd
->conf
->iface
, __func__
, MAC2STR(sta
->addr
),
3047 hapd
->conf
->ap_max_inactivity
);
3048 eloop_cancel_timeout(ap_handle_timer
, hapd
, sta
);
3049 eloop_register_timeout(hapd
->conf
->ap_max_inactivity
, 0,
3050 ap_handle_timer
, hapd
, sta
);
3053 #ifdef CONFIG_MACSEC
3054 if (hapd
->conf
->wpa_key_mgmt
== WPA_KEY_MGMT_NONE
&&
3055 hapd
->conf
->mka_psk_set
)
3056 ieee802_1x_create_preshared_mka_hapd(hapd
, sta
);
3058 ieee802_1x_alloc_kay_sm_hapd(hapd
, sta
);
3059 #endif /* CONFIG_MACSEC */
3063 const char * hostapd_state_text(enum hostapd_iface_state s
)
3066 case HAPD_IFACE_UNINITIALIZED
:
3067 return "UNINITIALIZED";
3068 case HAPD_IFACE_DISABLED
:
3070 case HAPD_IFACE_COUNTRY_UPDATE
:
3071 return "COUNTRY_UPDATE";
3072 case HAPD_IFACE_ACS
:
3074 case HAPD_IFACE_HT_SCAN
:
3076 case HAPD_IFACE_DFS
:
3078 case HAPD_IFACE_ENABLED
:
3086 void hostapd_set_state(struct hostapd_iface
*iface
, enum hostapd_iface_state s
)
3088 wpa_printf(MSG_INFO
, "%s: interface state %s->%s",
3089 iface
->conf
? iface
->conf
->bss
[0]->iface
: "N/A",
3090 hostapd_state_text(iface
->state
), hostapd_state_text(s
));
3095 int hostapd_csa_in_progress(struct hostapd_iface
*iface
)
3099 for (i
= 0; i
< iface
->num_bss
; i
++)
3100 if (iface
->bss
[i
]->csa_in_progress
)
3108 static void free_beacon_data(struct beacon_data
*beacon
)
3110 os_free(beacon
->head
);
3111 beacon
->head
= NULL
;
3112 os_free(beacon
->tail
);
3113 beacon
->tail
= NULL
;
3114 os_free(beacon
->probe_resp
);
3115 beacon
->probe_resp
= NULL
;
3116 os_free(beacon
->beacon_ies
);
3117 beacon
->beacon_ies
= NULL
;
3118 os_free(beacon
->proberesp_ies
);
3119 beacon
->proberesp_ies
= NULL
;
3120 os_free(beacon
->assocresp_ies
);
3121 beacon
->assocresp_ies
= NULL
;
3125 static int hostapd_build_beacon_data(struct hostapd_data
*hapd
,
3126 struct beacon_data
*beacon
)
3128 struct wpabuf
*beacon_extra
, *proberesp_extra
, *assocresp_extra
;
3129 struct wpa_driver_ap_params params
;
3132 os_memset(beacon
, 0, sizeof(*beacon
));
3133 ret
= ieee802_11_build_ap_params(hapd
, ¶ms
);
3137 ret
= hostapd_build_ap_extra_ies(hapd
, &beacon_extra
,
3141 goto free_ap_params
;
3144 beacon
->head
= os_memdup(params
.head
, params
.head_len
);
3146 goto free_ap_extra_ies
;
3148 beacon
->head_len
= params
.head_len
;
3150 beacon
->tail
= os_memdup(params
.tail
, params
.tail_len
);
3154 beacon
->tail_len
= params
.tail_len
;
3156 if (params
.proberesp
!= NULL
) {
3157 beacon
->probe_resp
= os_memdup(params
.proberesp
,
3158 params
.proberesp_len
);
3159 if (!beacon
->probe_resp
)
3162 beacon
->probe_resp_len
= params
.proberesp_len
;
3165 /* copy the extra ies */
3167 beacon
->beacon_ies
= os_memdup(beacon_extra
->buf
,
3168 wpabuf_len(beacon_extra
));
3169 if (!beacon
->beacon_ies
)
3172 beacon
->beacon_ies_len
= wpabuf_len(beacon_extra
);
3175 if (proberesp_extra
) {
3176 beacon
->proberesp_ies
= os_memdup(proberesp_extra
->buf
,
3177 wpabuf_len(proberesp_extra
));
3178 if (!beacon
->proberesp_ies
)
3181 beacon
->proberesp_ies_len
= wpabuf_len(proberesp_extra
);
3184 if (assocresp_extra
) {
3185 beacon
->assocresp_ies
= os_memdup(assocresp_extra
->buf
,
3186 wpabuf_len(assocresp_extra
));
3187 if (!beacon
->assocresp_ies
)
3190 beacon
->assocresp_ies_len
= wpabuf_len(assocresp_extra
);
3195 /* if the function fails, the caller should not free beacon data */
3197 free_beacon_data(beacon
);
3200 hostapd_free_ap_extra_ies(hapd
, beacon_extra
, proberesp_extra
,
3203 ieee802_11_free_ap_params(¶ms
);
3209 * TODO: This flow currently supports only changing channel and width within
3210 * the same hw_mode. Any other changes to MAC parameters or provided settings
3211 * are not supported.
3213 static int hostapd_change_config_freq(struct hostapd_data
*hapd
,
3214 struct hostapd_config
*conf
,
3215 struct hostapd_freq_params
*params
,
3216 struct hostapd_freq_params
*old_params
)
3220 struct hostapd_hw_modes
*mode
;
3222 if (!params
->channel
) {
3223 /* check if the new channel is supported by hw */
3224 params
->channel
= hostapd_hw_get_channel(hapd
, params
->freq
);
3227 channel
= params
->channel
;
3231 mode
= hapd
->iface
->current_mode
;
3233 /* if a pointer to old_params is provided we save previous state */
3235 hostapd_set_freq_params(old_params
, conf
->hw_mode
,
3236 hostapd_hw_get_freq(hapd
, conf
->channel
),
3237 conf
->channel
, conf
->ieee80211n
,
3238 conf
->ieee80211ac
, conf
->ieee80211ax
,
3239 conf
->secondary_channel
,
3240 hostapd_get_oper_chwidth(conf
),
3241 hostapd_get_oper_centr_freq_seg0_idx(conf
),
3242 hostapd_get_oper_centr_freq_seg1_idx(conf
),
3244 mode
? &mode
->he_capab
[IEEE80211_MODE_AP
] :
3248 switch (params
->bandwidth
) {
3252 hostapd_set_oper_chwidth(conf
, CHANWIDTH_USE_HT
);
3255 if (params
->center_freq2
)
3256 hostapd_set_oper_chwidth(conf
, CHANWIDTH_80P80MHZ
);
3258 hostapd_set_oper_chwidth(conf
, CHANWIDTH_80MHZ
);
3261 hostapd_set_oper_chwidth(conf
, CHANWIDTH_160MHZ
);
3267 conf
->channel
= channel
;
3268 conf
->ieee80211n
= params
->ht_enabled
;
3269 conf
->secondary_channel
= params
->sec_channel_offset
;
3270 ieee80211_freq_to_chan(params
->center_freq1
,
3272 ieee80211_freq_to_chan(params
->center_freq2
,
3274 hostapd_set_oper_centr_freq_seg0_idx(conf
, seg0
);
3275 hostapd_set_oper_centr_freq_seg1_idx(conf
, seg1
);
3277 /* TODO: maybe call here hostapd_config_check here? */
3283 static int hostapd_fill_csa_settings(struct hostapd_data
*hapd
,
3284 struct csa_settings
*settings
)
3286 struct hostapd_iface
*iface
= hapd
->iface
;
3287 struct hostapd_freq_params old_freq
;
3291 os_memset(&old_freq
, 0, sizeof(old_freq
));
3292 if (!iface
|| !iface
->freq
|| hapd
->csa_in_progress
)
3295 switch (settings
->freq_params
.bandwidth
) {
3297 if (settings
->freq_params
.center_freq2
)
3298 bandwidth
= CHANWIDTH_80P80MHZ
;
3300 bandwidth
= CHANWIDTH_80MHZ
;
3303 bandwidth
= CHANWIDTH_160MHZ
;
3306 bandwidth
= CHANWIDTH_USE_HT
;
3310 if (ieee80211_freq_to_channel_ext(
3311 settings
->freq_params
.freq
,
3312 settings
->freq_params
.sec_channel_offset
,
3314 &hapd
->iface
->cs_oper_class
,
3315 &chan
) == NUM_HOSTAPD_MODES
) {
3316 wpa_printf(MSG_DEBUG
,
3317 "invalid frequency for channel switch (freq=%d, sec_channel_offset=%d, vht_enabled=%d, he_enabled=%d)",
3318 settings
->freq_params
.freq
,
3319 settings
->freq_params
.sec_channel_offset
,
3320 settings
->freq_params
.vht_enabled
,
3321 settings
->freq_params
.he_enabled
);
3325 settings
->freq_params
.channel
= chan
;
3327 ret
= hostapd_change_config_freq(iface
->bss
[0], iface
->conf
,
3328 &settings
->freq_params
,
3333 ret
= hostapd_build_beacon_data(hapd
, &settings
->beacon_after
);
3335 /* change back the configuration */
3336 hostapd_change_config_freq(iface
->bss
[0], iface
->conf
,
3342 /* set channel switch parameters for csa ie */
3343 hapd
->cs_freq_params
= settings
->freq_params
;
3344 hapd
->cs_count
= settings
->cs_count
;
3345 hapd
->cs_block_tx
= settings
->block_tx
;
3347 ret
= hostapd_build_beacon_data(hapd
, &settings
->beacon_csa
);
3349 free_beacon_data(&settings
->beacon_after
);
3353 settings
->counter_offset_beacon
[0] = hapd
->cs_c_off_beacon
;
3354 settings
->counter_offset_presp
[0] = hapd
->cs_c_off_proberesp
;
3355 settings
->counter_offset_beacon
[1] = hapd
->cs_c_off_ecsa_beacon
;
3356 settings
->counter_offset_presp
[1] = hapd
->cs_c_off_ecsa_proberesp
;
3362 void hostapd_cleanup_cs_params(struct hostapd_data
*hapd
)
3364 os_memset(&hapd
->cs_freq_params
, 0, sizeof(hapd
->cs_freq_params
));
3366 hapd
->cs_block_tx
= 0;
3367 hapd
->cs_c_off_beacon
= 0;
3368 hapd
->cs_c_off_proberesp
= 0;
3369 hapd
->csa_in_progress
= 0;
3370 hapd
->cs_c_off_ecsa_beacon
= 0;
3371 hapd
->cs_c_off_ecsa_proberesp
= 0;
3375 void hostapd_chan_switch_vht_config(struct hostapd_data
*hapd
, int vht_enabled
)
3378 hapd
->iconf
->ch_switch_vht_config
|= CH_SWITCH_VHT_ENABLED
;
3380 hapd
->iconf
->ch_switch_vht_config
|= CH_SWITCH_VHT_DISABLED
;
3382 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE80211
,
3383 HOSTAPD_LEVEL_INFO
, "CHAN_SWITCH VHT CONFIG 0x%x",
3384 hapd
->iconf
->ch_switch_vht_config
);
3388 int hostapd_switch_channel(struct hostapd_data
*hapd
,
3389 struct csa_settings
*settings
)
3393 if (!(hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_AP_CSA
)) {
3394 wpa_printf(MSG_INFO
, "CSA is not supported");
3398 ret
= hostapd_fill_csa_settings(hapd
, settings
);
3402 ret
= hostapd_drv_switch_channel(hapd
, settings
);
3403 free_beacon_data(&settings
->beacon_csa
);
3404 free_beacon_data(&settings
->beacon_after
);
3407 /* if we failed, clean cs parameters */
3408 hostapd_cleanup_cs_params(hapd
);
3412 hapd
->csa_in_progress
= 1;
3418 hostapd_switch_channel_fallback(struct hostapd_iface
*iface
,
3419 const struct hostapd_freq_params
*freq_params
)
3421 int seg0_idx
= 0, seg1_idx
= 0, bw
= CHANWIDTH_USE_HT
;
3423 wpa_printf(MSG_DEBUG
, "Restarting all CSA-related BSSes");
3425 if (freq_params
->center_freq1
)
3426 seg0_idx
= 36 + (freq_params
->center_freq1
- 5180) / 5;
3427 if (freq_params
->center_freq2
)
3428 seg1_idx
= 36 + (freq_params
->center_freq2
- 5180) / 5;
3430 switch (freq_params
->bandwidth
) {
3434 bw
= CHANWIDTH_USE_HT
;
3437 if (freq_params
->center_freq2
)
3438 bw
= CHANWIDTH_80P80MHZ
;
3440 bw
= CHANWIDTH_80MHZ
;
3443 bw
= CHANWIDTH_160MHZ
;
3446 wpa_printf(MSG_WARNING
, "Unknown CSA bandwidth: %d",
3447 freq_params
->bandwidth
);
3451 iface
->freq
= freq_params
->freq
;
3452 iface
->conf
->channel
= freq_params
->channel
;
3453 iface
->conf
->secondary_channel
= freq_params
->sec_channel_offset
;
3454 hostapd_set_oper_centr_freq_seg0_idx(iface
->conf
, seg0_idx
);
3455 hostapd_set_oper_centr_freq_seg1_idx(iface
->conf
, seg1_idx
);
3456 hostapd_set_oper_chwidth(iface
->conf
, bw
);
3457 iface
->conf
->ieee80211n
= freq_params
->ht_enabled
;
3458 iface
->conf
->ieee80211ac
= freq_params
->vht_enabled
;
3459 iface
->conf
->ieee80211ax
= freq_params
->he_enabled
;
3462 * cs_params must not be cleared earlier because the freq_params
3463 * argument may actually point to one of these.
3464 * These params will be cleared during interface disable below.
3466 hostapd_disable_iface(iface
);
3467 hostapd_enable_iface(iface
);
3470 #endif /* NEED_AP_MLME */
3473 struct hostapd_data
* hostapd_get_iface(struct hapd_interfaces
*interfaces
,
3478 for (i
= 0; i
< interfaces
->count
; i
++) {
3479 struct hostapd_iface
*iface
= interfaces
->iface
[i
];
3481 for (j
= 0; j
< iface
->num_bss
; j
++) {
3482 struct hostapd_data
*hapd
= iface
->bss
[j
];
3484 if (os_strcmp(ifname
, hapd
->conf
->iface
) == 0)
3493 void hostapd_periodic_iface(struct hostapd_iface
*iface
)
3497 ap_list_timer(iface
);
3499 for (i
= 0; i
< iface
->num_bss
; i
++) {
3500 struct hostapd_data
*hapd
= iface
->bss
[i
];
3505 #ifndef CONFIG_NO_RADIUS
3506 hostapd_acl_expire(hapd
);
3507 #endif /* CONFIG_NO_RADIUS */