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 "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"
54 static int hostapd_flush_old_stations(struct hostapd_data
*hapd
, u16 reason
);
55 static int hostapd_setup_encryption(char *iface
, struct hostapd_data
*hapd
);
56 static int hostapd_broadcast_wep_clear(struct hostapd_data
*hapd
);
57 static int setup_interface2(struct hostapd_iface
*iface
);
58 static void channel_list_update_timeout(void *eloop_ctx
, void *timeout_ctx
);
61 int hostapd_for_each_interface(struct hapd_interfaces
*interfaces
,
62 int (*cb
)(struct hostapd_iface
*iface
,
63 void *ctx
), void *ctx
)
68 for (i
= 0; i
< interfaces
->count
; i
++) {
69 ret
= cb(interfaces
->iface
[i
], ctx
);
78 static void hostapd_reload_bss(struct hostapd_data
*hapd
)
80 struct hostapd_ssid
*ssid
;
85 #ifndef CONFIG_NO_RADIUS
86 radius_client_reconfig(hapd
->radius
, hapd
->conf
->radius
);
87 #endif /* CONFIG_NO_RADIUS */
89 ssid
= &hapd
->conf
->ssid
;
90 if (!ssid
->wpa_psk_set
&& ssid
->wpa_psk
&& !ssid
->wpa_psk
->next
&&
91 ssid
->wpa_passphrase_set
&& ssid
->wpa_passphrase
) {
93 * Force PSK to be derived again since SSID or passphrase may
96 hostapd_config_clear_wpa_psk(&hapd
->conf
->ssid
.wpa_psk
);
98 if (hostapd_setup_wpa_psk(hapd
->conf
)) {
99 wpa_printf(MSG_ERROR
, "Failed to re-configure WPA PSK "
100 "after reloading configuration");
103 if (hapd
->conf
->ieee802_1x
|| hapd
->conf
->wpa
)
104 hostapd_set_drv_ieee8021x(hapd
, hapd
->conf
->iface
, 1);
106 hostapd_set_drv_ieee8021x(hapd
, hapd
->conf
->iface
, 0);
108 if ((hapd
->conf
->wpa
|| hapd
->conf
->osen
) && hapd
->wpa_auth
== NULL
) {
109 hostapd_setup_wpa(hapd
);
111 wpa_init_keys(hapd
->wpa_auth
);
112 } else if (hapd
->conf
->wpa
) {
115 hostapd_reconfig_wpa(hapd
);
116 wpa_ie
= wpa_auth_get_wpa_ie(hapd
->wpa_auth
, &wpa_ie_len
);
117 if (hostapd_set_generic_elem(hapd
, wpa_ie
, wpa_ie_len
))
118 wpa_printf(MSG_ERROR
, "Failed to configure WPA IE for "
119 "the kernel driver.");
120 } else if (hapd
->wpa_auth
) {
121 wpa_deinit(hapd
->wpa_auth
);
122 hapd
->wpa_auth
= NULL
;
123 hostapd_set_privacy(hapd
, 0);
124 hostapd_setup_encryption(hapd
->conf
->iface
, hapd
);
125 hostapd_set_generic_elem(hapd
, (u8
*) "", 0);
128 ieee802_11_set_beacon(hapd
);
129 hostapd_update_wps(hapd
);
131 if (hapd
->conf
->ssid
.ssid_set
&&
132 hostapd_set_ssid(hapd
, hapd
->conf
->ssid
.ssid
,
133 hapd
->conf
->ssid
.ssid_len
)) {
134 wpa_printf(MSG_ERROR
, "Could not set SSID for kernel driver");
135 /* try to continue */
137 wpa_printf(MSG_DEBUG
, "Reconfigured interface %s", hapd
->conf
->iface
);
141 static void hostapd_clear_old(struct hostapd_iface
*iface
)
146 * Deauthenticate all stations since the new configuration may not
147 * allow them to use the BSS anymore.
149 for (j
= 0; j
< iface
->num_bss
; j
++) {
150 hostapd_flush_old_stations(iface
->bss
[j
],
151 WLAN_REASON_PREV_AUTH_NOT_VALID
);
152 hostapd_broadcast_wep_clear(iface
->bss
[j
]);
154 #ifndef CONFIG_NO_RADIUS
155 /* TODO: update dynamic data based on changed configuration
156 * items (e.g., open/close sockets, etc.) */
157 radius_client_flush(iface
->bss
[j
]->radius
, 0);
158 #endif /* CONFIG_NO_RADIUS */
163 int hostapd_reload_config(struct hostapd_iface
*iface
)
165 struct hostapd_data
*hapd
= iface
->bss
[0];
166 struct hostapd_config
*newconf
, *oldconf
;
169 if (iface
->config_fname
== NULL
) {
170 /* Only in-memory config in use - assume it has been updated */
171 hostapd_clear_old(iface
);
172 for (j
= 0; j
< iface
->num_bss
; j
++)
173 hostapd_reload_bss(iface
->bss
[j
]);
177 if (iface
->interfaces
== NULL
||
178 iface
->interfaces
->config_read_cb
== NULL
)
180 newconf
= iface
->interfaces
->config_read_cb(iface
->config_fname
);
184 hostapd_clear_old(iface
);
186 oldconf
= hapd
->iconf
;
187 iface
->conf
= newconf
;
189 for (j
= 0; j
< iface
->num_bss
; j
++) {
190 hapd
= iface
->bss
[j
];
191 hapd
->iconf
= newconf
;
192 hapd
->iconf
->channel
= oldconf
->channel
;
193 hapd
->iconf
->acs
= oldconf
->acs
;
194 hapd
->iconf
->secondary_channel
= oldconf
->secondary_channel
;
195 hapd
->iconf
->ieee80211n
= oldconf
->ieee80211n
;
196 hapd
->iconf
->ieee80211ac
= oldconf
->ieee80211ac
;
197 hapd
->iconf
->ht_capab
= oldconf
->ht_capab
;
198 hapd
->iconf
->vht_capab
= oldconf
->vht_capab
;
199 hapd
->iconf
->vht_oper_chwidth
= oldconf
->vht_oper_chwidth
;
200 hapd
->iconf
->vht_oper_centr_freq_seg0_idx
=
201 oldconf
->vht_oper_centr_freq_seg0_idx
;
202 hapd
->iconf
->vht_oper_centr_freq_seg1_idx
=
203 oldconf
->vht_oper_centr_freq_seg1_idx
;
204 hapd
->conf
= newconf
->bss
[j
];
205 hostapd_reload_bss(hapd
);
208 hostapd_config_free(oldconf
);
215 static void hostapd_broadcast_key_clear_iface(struct hostapd_data
*hapd
,
220 if (!ifname
|| !hapd
->drv_priv
)
222 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
223 if (hostapd_drv_set_key(ifname
, hapd
, WPA_ALG_NONE
, NULL
, i
,
224 0, NULL
, 0, NULL
, 0)) {
225 wpa_printf(MSG_DEBUG
, "Failed to clear default "
226 "encryption keys (ifname=%s keyidx=%d)",
230 #ifdef CONFIG_IEEE80211W
231 if (hapd
->conf
->ieee80211w
) {
232 for (i
= NUM_WEP_KEYS
; i
< NUM_WEP_KEYS
+ 2; i
++) {
233 if (hostapd_drv_set_key(ifname
, hapd
, WPA_ALG_NONE
,
236 wpa_printf(MSG_DEBUG
, "Failed to clear "
237 "default mgmt encryption keys "
238 "(ifname=%s keyidx=%d)", ifname
, i
);
242 #endif /* CONFIG_IEEE80211W */
246 static int hostapd_broadcast_wep_clear(struct hostapd_data
*hapd
)
248 hostapd_broadcast_key_clear_iface(hapd
, hapd
->conf
->iface
);
253 static int hostapd_broadcast_wep_set(struct hostapd_data
*hapd
)
256 struct hostapd_ssid
*ssid
= &hapd
->conf
->ssid
;
259 if (ssid
->wep
.default_len
&&
260 hostapd_drv_set_key(hapd
->conf
->iface
,
261 hapd
, WPA_ALG_WEP
, broadcast_ether_addr
, idx
,
262 1, NULL
, 0, ssid
->wep
.key
[idx
],
263 ssid
->wep
.len
[idx
])) {
264 wpa_printf(MSG_WARNING
, "Could not set WEP encryption.");
272 static void hostapd_free_hapd_data(struct hostapd_data
*hapd
)
274 os_free(hapd
->probereq_cb
);
275 hapd
->probereq_cb
= NULL
;
276 hapd
->num_probereq_cb
= 0;
279 wpabuf_free(hapd
->p2p_beacon_ie
);
280 hapd
->p2p_beacon_ie
= NULL
;
281 wpabuf_free(hapd
->p2p_probe_resp_ie
);
282 hapd
->p2p_probe_resp_ie
= NULL
;
283 #endif /* CONFIG_P2P */
285 if (!hapd
->started
) {
286 wpa_printf(MSG_ERROR
, "%s: Interface %s wasn't started",
287 __func__
, hapd
->conf
->iface
);
292 wpa_printf(MSG_DEBUG
, "%s(%s)", __func__
, hapd
->conf
->iface
);
293 iapp_deinit(hapd
->iapp
);
295 accounting_deinit(hapd
);
296 hostapd_deinit_wpa(hapd
);
298 hostapd_acl_deinit(hapd
);
299 #ifndef CONFIG_NO_RADIUS
300 radius_client_deinit(hapd
->radius
);
302 radius_das_deinit(hapd
->radius_das
);
303 hapd
->radius_das
= NULL
;
304 #endif /* CONFIG_NO_RADIUS */
306 hostapd_deinit_wps(hapd
);
308 hostapd_dpp_deinit(hapd
);
309 gas_query_ap_deinit(hapd
->gas
);
310 #endif /* CONFIG_DPP */
312 authsrv_deinit(hapd
);
314 if (hapd
->interface_added
) {
315 hapd
->interface_added
= 0;
316 if (hostapd_if_remove(hapd
, WPA_IF_AP_BSS
, hapd
->conf
->iface
)) {
317 wpa_printf(MSG_WARNING
,
318 "Failed to remove BSS interface %s",
320 hapd
->interface_added
= 1;
323 * Since this was a dynamically added interface, the
324 * driver wrapper may have removed its internal instance
325 * and hapd->drv_priv is not valid anymore.
327 hapd
->drv_priv
= NULL
;
331 wpabuf_free(hapd
->time_adv
);
333 #ifdef CONFIG_INTERWORKING
334 gas_serv_deinit(hapd
);
335 #endif /* CONFIG_INTERWORKING */
337 bss_load_update_deinit(hapd
);
338 ndisc_snoop_deinit(hapd
);
339 dhcp_snoop_deinit(hapd
);
340 x_snoop_deinit(hapd
);
343 bin_clear_free(hapd
->tmp_eap_user
.identity
,
344 hapd
->tmp_eap_user
.identity_len
);
345 bin_clear_free(hapd
->tmp_eap_user
.password
,
346 hapd
->tmp_eap_user
.password_len
);
347 #endif /* CONFIG_SQLITE */
350 wpabuf_free(hapd
->mesh_pending_auth
);
351 hapd
->mesh_pending_auth
= NULL
;
352 #endif /* CONFIG_MESH */
354 hostapd_clean_rrm(hapd
);
355 fils_hlp_deinit(hapd
);
360 * hostapd_cleanup - Per-BSS cleanup (deinitialization)
361 * @hapd: Pointer to BSS data
363 * This function is used to free all per-BSS data structures and resources.
364 * Most of the modules that are initialized in hostapd_setup_bss() are
365 * deinitialized here.
367 static void hostapd_cleanup(struct hostapd_data
*hapd
)
369 wpa_printf(MSG_DEBUG
, "%s(hapd=%p (%s))", __func__
, hapd
,
371 if (hapd
->iface
->interfaces
&&
372 hapd
->iface
->interfaces
->ctrl_iface_deinit
) {
373 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, WPA_EVENT_TERMINATING
);
374 hapd
->iface
->interfaces
->ctrl_iface_deinit(hapd
);
376 hostapd_free_hapd_data(hapd
);
380 static void sta_track_deinit(struct hostapd_iface
*iface
)
382 struct hostapd_sta_info
*info
;
384 if (!iface
->num_sta_seen
)
387 while ((info
= dl_list_first(&iface
->sta_seen
, struct hostapd_sta_info
,
389 dl_list_del(&info
->list
);
390 iface
->num_sta_seen
--;
396 static void hostapd_cleanup_iface_partial(struct hostapd_iface
*iface
)
398 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
399 #ifdef CONFIG_IEEE80211N
401 hostapd_stop_setup_timers(iface
);
402 #endif /* NEED_AP_MLME */
403 #endif /* CONFIG_IEEE80211N */
404 if (iface
->current_mode
)
406 hostapd_free_hw_features(iface
->hw_features
, iface
->num_hw_features
);
407 iface
->hw_features
= NULL
;
408 iface
->current_mode
= NULL
;
409 os_free(iface
->current_rates
);
410 iface
->current_rates
= NULL
;
411 os_free(iface
->basic_rates
);
412 iface
->basic_rates
= NULL
;
413 ap_list_deinit(iface
);
414 sta_track_deinit(iface
);
419 * hostapd_cleanup_iface - Complete per-interface cleanup
420 * @iface: Pointer to interface data
422 * This function is called after per-BSS data structures are deinitialized
423 * with hostapd_cleanup().
425 static void hostapd_cleanup_iface(struct hostapd_iface
*iface
)
427 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
428 eloop_cancel_timeout(channel_list_update_timeout
, iface
, NULL
);
430 hostapd_cleanup_iface_partial(iface
);
431 hostapd_config_free(iface
->conf
);
434 os_free(iface
->config_fname
);
436 wpa_printf(MSG_DEBUG
, "%s: free iface=%p", __func__
, iface
);
441 static void hostapd_clear_wep(struct hostapd_data
*hapd
)
443 if (hapd
->drv_priv
&& !hapd
->iface
->driver_ap_teardown
) {
444 hostapd_set_privacy(hapd
, 0);
445 hostapd_broadcast_wep_clear(hapd
);
450 static int hostapd_setup_encryption(char *iface
, struct hostapd_data
*hapd
)
454 hostapd_broadcast_wep_set(hapd
);
456 if (hapd
->conf
->ssid
.wep
.default_len
) {
457 hostapd_set_privacy(hapd
, 1);
462 * When IEEE 802.1X is not enabled, the driver may need to know how to
463 * set authentication algorithms for static WEP.
465 hostapd_drv_set_authmode(hapd
, hapd
->conf
->auth_algs
);
467 for (i
= 0; i
< 4; i
++) {
468 if (hapd
->conf
->ssid
.wep
.key
[i
] &&
469 hostapd_drv_set_key(iface
, hapd
, WPA_ALG_WEP
, NULL
, i
,
470 i
== hapd
->conf
->ssid
.wep
.idx
, NULL
, 0,
471 hapd
->conf
->ssid
.wep
.key
[i
],
472 hapd
->conf
->ssid
.wep
.len
[i
])) {
473 wpa_printf(MSG_WARNING
, "Could not set WEP "
477 if (hapd
->conf
->ssid
.wep
.key
[i
] &&
478 i
== hapd
->conf
->ssid
.wep
.idx
)
479 hostapd_set_privacy(hapd
, 1);
486 static int hostapd_flush_old_stations(struct hostapd_data
*hapd
, u16 reason
)
491 if (hostapd_drv_none(hapd
) || hapd
->drv_priv
== NULL
)
494 if (!hapd
->iface
->driver_ap_teardown
) {
495 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
,
496 "Flushing old station entries");
498 if (hostapd_flush(hapd
)) {
499 wpa_msg(hapd
->msg_ctx
, MSG_WARNING
,
500 "Could not connect to kernel driver");
504 if (hapd
->conf
&& hapd
->conf
->broadcast_deauth
) {
505 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
,
506 "Deauthenticate all stations");
507 os_memset(addr
, 0xff, ETH_ALEN
);
508 hostapd_drv_sta_deauth(hapd
, addr
, reason
);
510 hostapd_free_stas(hapd
);
516 static void hostapd_bss_deinit_no_free(struct hostapd_data
*hapd
)
518 hostapd_free_stas(hapd
);
519 hostapd_flush_old_stations(hapd
, WLAN_REASON_DEAUTH_LEAVING
);
520 hostapd_clear_wep(hapd
);
525 * hostapd_validate_bssid_configuration - Validate BSSID configuration
526 * @iface: Pointer to interface data
527 * Returns: 0 on success, -1 on failure
529 * This function is used to validate that the configured BSSIDs are valid.
531 static int hostapd_validate_bssid_configuration(struct hostapd_iface
*iface
)
533 u8 mask
[ETH_ALEN
] = { 0 };
534 struct hostapd_data
*hapd
= iface
->bss
[0];
535 unsigned int i
= iface
->conf
->num_bss
, bits
= 0, j
;
538 if (hostapd_drv_none(hapd
))
541 if (iface
->conf
->use_driver_iface_addr
)
544 /* Generate BSSID mask that is large enough to cover the BSSIDs. */
546 /* Determine the bits necessary to cover the number of BSSIDs. */
547 for (i
--; i
; i
>>= 1)
550 /* Determine the bits necessary to any configured BSSIDs,
551 if they are higher than the number of BSSIDs. */
552 for (j
= 0; j
< iface
->conf
->num_bss
; j
++) {
553 if (is_zero_ether_addr(iface
->conf
->bss
[j
]->bssid
)) {
559 for (i
= 0; i
< ETH_ALEN
; i
++) {
561 iface
->conf
->bss
[j
]->bssid
[i
] ^
569 for (i
= 0; i
< ETH_ALEN
&& mask
[i
] == 0; i
++)
575 while (mask
[i
] != 0) {
585 wpa_printf(MSG_ERROR
, "Too many bits in the BSSID mask (%u)",
590 os_memset(mask
, 0xff, ETH_ALEN
);
592 for (i
= 5; i
> 5 - j
; i
--)
599 wpa_printf(MSG_DEBUG
, "BSS count %lu, BSSID mask " MACSTR
" (%d bits)",
600 (unsigned long) iface
->conf
->num_bss
, MAC2STR(mask
), bits
);
605 for (i
= 0; i
< ETH_ALEN
; i
++) {
606 if ((hapd
->own_addr
[i
] & mask
[i
]) != hapd
->own_addr
[i
]) {
607 wpa_printf(MSG_ERROR
, "Invalid BSSID mask " MACSTR
608 " for start address " MACSTR
".",
609 MAC2STR(mask
), MAC2STR(hapd
->own_addr
));
610 wpa_printf(MSG_ERROR
, "Start address must be the "
611 "first address in the block (i.e., addr "
612 "AND mask == addr).");
621 static int mac_in_conf(struct hostapd_config
*conf
, const void *a
)
625 for (i
= 0; i
< conf
->num_bss
; i
++) {
626 if (hostapd_mac_comp(conf
->bss
[i
]->bssid
, a
) == 0) {
635 #ifndef CONFIG_NO_RADIUS
637 static int hostapd_das_nas_mismatch(struct hostapd_data
*hapd
,
638 struct radius_das_attrs
*attr
)
640 if (attr
->nas_identifier
&&
641 (!hapd
->conf
->nas_identifier
||
642 os_strlen(hapd
->conf
->nas_identifier
) !=
643 attr
->nas_identifier_len
||
644 os_memcmp(hapd
->conf
->nas_identifier
, attr
->nas_identifier
,
645 attr
->nas_identifier_len
) != 0)) {
646 wpa_printf(MSG_DEBUG
, "RADIUS DAS: NAS-Identifier mismatch");
650 if (attr
->nas_ip_addr
&&
651 (hapd
->conf
->own_ip_addr
.af
!= AF_INET
||
652 os_memcmp(&hapd
->conf
->own_ip_addr
.u
.v4
, attr
->nas_ip_addr
, 4) !=
654 wpa_printf(MSG_DEBUG
, "RADIUS DAS: NAS-IP-Address mismatch");
659 if (attr
->nas_ipv6_addr
&&
660 (hapd
->conf
->own_ip_addr
.af
!= AF_INET6
||
661 os_memcmp(&hapd
->conf
->own_ip_addr
.u
.v6
, attr
->nas_ipv6_addr
, 16)
663 wpa_printf(MSG_DEBUG
, "RADIUS DAS: NAS-IPv6-Address mismatch");
666 #endif /* CONFIG_IPV6 */
672 static struct sta_info
* hostapd_das_find_sta(struct hostapd_data
*hapd
,
673 struct radius_das_attrs
*attr
,
676 struct sta_info
*selected
, *sta
;
683 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
)
684 sta
->radius_das_match
= 1;
686 if (attr
->sta_addr
) {
688 sta
= ap_get_sta(hapd
, attr
->sta_addr
);
690 wpa_printf(MSG_DEBUG
,
691 "RADIUS DAS: No Calling-Station-Id match");
696 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
698 sta
->radius_das_match
= 0;
700 wpa_printf(MSG_DEBUG
, "RADIUS DAS: Calling-Station-Id match");
703 if (attr
->acct_session_id
) {
705 if (attr
->acct_session_id_len
!= 16) {
706 wpa_printf(MSG_DEBUG
,
707 "RADIUS DAS: Acct-Session-Id cannot match");
712 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
713 if (!sta
->radius_das_match
)
715 os_snprintf(buf
, sizeof(buf
), "%016llX",
716 (unsigned long long) sta
->acct_session_id
);
717 if (os_memcmp(attr
->acct_session_id
, buf
, 16) != 0)
718 sta
->radius_das_match
= 0;
724 wpa_printf(MSG_DEBUG
,
725 "RADIUS DAS: No matches remaining after Acct-Session-Id check");
728 wpa_printf(MSG_DEBUG
, "RADIUS DAS: Acct-Session-Id match");
731 if (attr
->acct_multi_session_id
) {
733 if (attr
->acct_multi_session_id_len
!= 16) {
734 wpa_printf(MSG_DEBUG
,
735 "RADIUS DAS: Acct-Multi-Session-Id cannot match");
740 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
741 if (!sta
->radius_das_match
)
743 if (!sta
->eapol_sm
||
744 !sta
->eapol_sm
->acct_multi_session_id
) {
745 sta
->radius_das_match
= 0;
748 os_snprintf(buf
, sizeof(buf
), "%016llX",
750 sta
->eapol_sm
->acct_multi_session_id
);
751 if (os_memcmp(attr
->acct_multi_session_id
, buf
, 16) !=
753 sta
->radius_das_match
= 0;
759 wpa_printf(MSG_DEBUG
,
760 "RADIUS DAS: No matches remaining after Acct-Multi-Session-Id check");
763 wpa_printf(MSG_DEBUG
,
764 "RADIUS DAS: Acct-Multi-Session-Id match");
771 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
774 if (!sta
->radius_das_match
)
776 cui
= ieee802_1x_get_radius_cui(sta
->eapol_sm
);
777 if (!cui
|| wpabuf_len(cui
) != attr
->cui_len
||
778 os_memcmp(wpabuf_head(cui
), attr
->cui
,
780 sta
->radius_das_match
= 0;
786 wpa_printf(MSG_DEBUG
,
787 "RADIUS DAS: No matches remaining after Chargeable-User-Identity check");
790 wpa_printf(MSG_DEBUG
,
791 "RADIUS DAS: Chargeable-User-Identity match");
794 if (attr
->user_name
) {
798 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
802 if (!sta
->radius_das_match
)
804 identity
= ieee802_1x_get_identity(sta
->eapol_sm
,
807 identity_len
!= attr
->user_name_len
||
808 os_memcmp(identity
, attr
->user_name
, identity_len
)
810 sta
->radius_das_match
= 0;
816 wpa_printf(MSG_DEBUG
,
817 "RADIUS DAS: No matches remaining after User-Name check");
820 wpa_printf(MSG_DEBUG
,
821 "RADIUS DAS: User-Name match");
826 * In theory, we could match all current associations, but it
827 * seems safer to just reject requests that do not include any
828 * session identification attributes.
830 wpa_printf(MSG_DEBUG
,
831 "RADIUS DAS: No session identification attributes included");
836 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
837 if (sta
->radius_das_match
) {
850 static int hostapd_das_disconnect_pmksa(struct hostapd_data
*hapd
,
851 struct radius_das_attrs
*attr
)
855 return wpa_auth_radius_das_disconnect_pmksa(hapd
->wpa_auth
, attr
);
859 static enum radius_das_res
860 hostapd_das_disconnect(void *ctx
, struct radius_das_attrs
*attr
)
862 struct hostapd_data
*hapd
= ctx
;
863 struct sta_info
*sta
;
866 if (hostapd_das_nas_mismatch(hapd
, attr
))
867 return RADIUS_DAS_NAS_MISMATCH
;
869 sta
= hostapd_das_find_sta(hapd
, attr
, &multi
);
872 wpa_printf(MSG_DEBUG
,
873 "RADIUS DAS: Multiple sessions match - not supported");
874 return RADIUS_DAS_MULTI_SESSION_MATCH
;
876 if (hostapd_das_disconnect_pmksa(hapd
, attr
) == 0) {
877 wpa_printf(MSG_DEBUG
,
878 "RADIUS DAS: PMKSA cache entry matched");
879 return RADIUS_DAS_SUCCESS
;
881 wpa_printf(MSG_DEBUG
, "RADIUS DAS: No matching session found");
882 return RADIUS_DAS_SESSION_NOT_FOUND
;
885 wpa_printf(MSG_DEBUG
, "RADIUS DAS: Found a matching session " MACSTR
886 " - disconnecting", MAC2STR(sta
->addr
));
887 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
889 hostapd_drv_sta_deauth(hapd
, sta
->addr
,
890 WLAN_REASON_PREV_AUTH_NOT_VALID
);
891 ap_sta_deauthenticate(hapd
, sta
, WLAN_REASON_PREV_AUTH_NOT_VALID
);
893 return RADIUS_DAS_SUCCESS
;
896 #endif /* CONFIG_NO_RADIUS */
900 * hostapd_setup_bss - Per-BSS setup (initialization)
901 * @hapd: Pointer to BSS data
902 * @first: Whether this BSS is the first BSS of an interface; -1 = not first,
903 * but interface may exist
905 * This function is used to initialize all per-BSS data structures and
906 * resources. This gets called in a loop for each BSS when an interface is
907 * initialized. Most of the modules that are initialized here will be
908 * deinitialized in hostapd_cleanup().
910 static int hostapd_setup_bss(struct hostapd_data
*hapd
, int first
)
912 struct hostapd_bss_config
*conf
= hapd
->conf
;
913 u8 ssid
[SSID_MAX_LEN
+ 1];
914 int ssid_len
, set_ssid
;
915 char force_ifname
[IFNAMSIZ
];
916 u8 if_addr
[ETH_ALEN
];
917 int flush_old_stations
= 1;
919 wpa_printf(MSG_DEBUG
, "%s(hapd=%p (%s), first=%d)",
920 __func__
, hapd
, conf
->iface
, first
);
922 #ifdef EAP_SERVER_TNC
923 if (conf
->tnc
&& tncs_global_init() < 0) {
924 wpa_printf(MSG_ERROR
, "Failed to initialize TNCS");
927 #endif /* EAP_SERVER_TNC */
930 wpa_printf(MSG_ERROR
, "%s: Interface %s was already started",
931 __func__
, conf
->iface
);
936 if (!first
|| first
== -1) {
937 u8
*addr
= hapd
->own_addr
;
939 if (!is_zero_ether_addr(conf
->bssid
)) {
940 /* Allocate the configured BSSID. */
941 os_memcpy(hapd
->own_addr
, conf
->bssid
, ETH_ALEN
);
943 if (hostapd_mac_comp(hapd
->own_addr
,
944 hapd
->iface
->bss
[0]->own_addr
) ==
946 wpa_printf(MSG_ERROR
, "BSS '%s' may not have "
947 "BSSID set to the MAC address of "
948 "the radio", conf
->iface
);
951 } else if (hapd
->iconf
->use_driver_iface_addr
) {
954 /* Allocate the next available BSSID. */
956 inc_byte_array(hapd
->own_addr
, ETH_ALEN
);
957 } while (mac_in_conf(hapd
->iconf
, hapd
->own_addr
));
960 hapd
->interface_added
= 1;
961 if (hostapd_if_add(hapd
->iface
->bss
[0], WPA_IF_AP_BSS
,
962 conf
->iface
, addr
, hapd
,
963 &hapd
->drv_priv
, force_ifname
, if_addr
,
964 conf
->bridge
[0] ? conf
->bridge
: NULL
,
966 wpa_printf(MSG_ERROR
, "Failed to add BSS (BSSID="
967 MACSTR
")", MAC2STR(hapd
->own_addr
));
968 hapd
->interface_added
= 0;
973 os_memcpy(hapd
->own_addr
, if_addr
, ETH_ALEN
);
976 if (conf
->wmm_enabled
< 0)
977 conf
->wmm_enabled
= hapd
->iconf
->ieee80211n
;
979 #ifdef CONFIG_IEEE80211R_AP
980 if (is_zero_ether_addr(conf
->r1_key_holder
))
981 os_memcpy(conf
->r1_key_holder
, hapd
->own_addr
, ETH_ALEN
);
982 #endif /* CONFIG_IEEE80211R_AP */
985 if ((hapd
->conf
->mesh
& MESH_ENABLED
) && hapd
->iface
->mconf
== NULL
)
986 flush_old_stations
= 0;
987 #endif /* CONFIG_MESH */
989 if (flush_old_stations
)
990 hostapd_flush_old_stations(hapd
,
991 WLAN_REASON_PREV_AUTH_NOT_VALID
);
992 hostapd_set_privacy(hapd
, 0);
994 hostapd_broadcast_wep_clear(hapd
);
995 if (hostapd_setup_encryption(conf
->iface
, hapd
))
999 * Fetch the SSID from the system and use it or,
1000 * if one was specified in the config file, verify they
1003 ssid_len
= hostapd_get_ssid(hapd
, ssid
, sizeof(ssid
));
1005 wpa_printf(MSG_ERROR
, "Could not read SSID from system");
1008 if (conf
->ssid
.ssid_set
) {
1010 * If SSID is specified in the config file and it differs
1011 * from what is being used then force installation of the
1014 set_ssid
= (conf
->ssid
.ssid_len
!= (size_t) ssid_len
||
1015 os_memcmp(conf
->ssid
.ssid
, ssid
, ssid_len
) != 0);
1018 * No SSID in the config file; just use the one we got
1022 conf
->ssid
.ssid_len
= ssid_len
;
1023 os_memcpy(conf
->ssid
.ssid
, ssid
, conf
->ssid
.ssid_len
);
1026 if (!hostapd_drv_none(hapd
)) {
1027 wpa_printf(MSG_ERROR
, "Using interface %s with hwaddr " MACSTR
1029 conf
->iface
, MAC2STR(hapd
->own_addr
),
1030 wpa_ssid_txt(conf
->ssid
.ssid
, conf
->ssid
.ssid_len
));
1033 if (hostapd_setup_wpa_psk(conf
)) {
1034 wpa_printf(MSG_ERROR
, "WPA-PSK setup failed.");
1038 /* Set SSID for the kernel driver (to be used in beacon and probe
1039 * response frames) */
1040 if (set_ssid
&& hostapd_set_ssid(hapd
, conf
->ssid
.ssid
,
1041 conf
->ssid
.ssid_len
)) {
1042 wpa_printf(MSG_ERROR
, "Could not set SSID for kernel driver");
1046 if (wpa_debug_level
<= MSG_MSGDUMP
)
1047 conf
->radius
->msg_dumps
= 1;
1048 #ifndef CONFIG_NO_RADIUS
1049 hapd
->radius
= radius_client_init(hapd
, conf
->radius
);
1050 if (hapd
->radius
== NULL
) {
1051 wpa_printf(MSG_ERROR
, "RADIUS client initialization failed.");
1055 if (conf
->radius_das_port
) {
1056 struct radius_das_conf das_conf
;
1057 os_memset(&das_conf
, 0, sizeof(das_conf
));
1058 das_conf
.port
= conf
->radius_das_port
;
1059 das_conf
.shared_secret
= conf
->radius_das_shared_secret
;
1060 das_conf
.shared_secret_len
=
1061 conf
->radius_das_shared_secret_len
;
1062 das_conf
.client_addr
= &conf
->radius_das_client_addr
;
1063 das_conf
.time_window
= conf
->radius_das_time_window
;
1064 das_conf
.require_event_timestamp
=
1065 conf
->radius_das_require_event_timestamp
;
1066 das_conf
.require_message_authenticator
=
1067 conf
->radius_das_require_message_authenticator
;
1068 das_conf
.ctx
= hapd
;
1069 das_conf
.disconnect
= hostapd_das_disconnect
;
1070 hapd
->radius_das
= radius_das_init(&das_conf
);
1071 if (hapd
->radius_das
== NULL
) {
1072 wpa_printf(MSG_ERROR
, "RADIUS DAS initialization "
1077 #endif /* CONFIG_NO_RADIUS */
1079 if (hostapd_acl_init(hapd
)) {
1080 wpa_printf(MSG_ERROR
, "ACL initialization failed.");
1083 if (hostapd_init_wps(hapd
, conf
))
1087 hapd
->gas
= gas_query_ap_init(hapd
, hapd
->msg_ctx
);
1090 if (hostapd_dpp_init(hapd
))
1092 #endif /* CONFIG_DPP */
1094 if (authsrv_init(hapd
) < 0)
1097 if (ieee802_1x_init(hapd
)) {
1098 wpa_printf(MSG_ERROR
, "IEEE 802.1X initialization failed.");
1102 if ((conf
->wpa
|| conf
->osen
) && hostapd_setup_wpa(hapd
))
1105 if (accounting_init(hapd
)) {
1106 wpa_printf(MSG_ERROR
, "Accounting initialization failed.");
1110 if (conf
->ieee802_11f
&&
1111 (hapd
->iapp
= iapp_init(hapd
, conf
->iapp_iface
)) == NULL
) {
1112 wpa_printf(MSG_ERROR
, "IEEE 802.11F (IAPP) initialization "
1117 #ifdef CONFIG_INTERWORKING
1118 if (gas_serv_init(hapd
)) {
1119 wpa_printf(MSG_ERROR
, "GAS server initialization failed");
1123 if (conf
->qos_map_set_len
&&
1124 hostapd_drv_set_qos_map(hapd
, conf
->qos_map_set
,
1125 conf
->qos_map_set_len
)) {
1126 wpa_printf(MSG_ERROR
, "Failed to initialize QoS Map");
1129 #endif /* CONFIG_INTERWORKING */
1131 if (conf
->bss_load_update_period
&& bss_load_update_init(hapd
)) {
1132 wpa_printf(MSG_ERROR
, "BSS Load initialization failed");
1136 if (conf
->proxy_arp
) {
1137 if (x_snoop_init(hapd
)) {
1138 wpa_printf(MSG_ERROR
,
1139 "Generic snooping infrastructure initialization failed");
1143 if (dhcp_snoop_init(hapd
)) {
1144 wpa_printf(MSG_ERROR
,
1145 "DHCP snooping initialization failed");
1149 if (ndisc_snoop_init(hapd
)) {
1150 wpa_printf(MSG_ERROR
,
1151 "Neighbor Discovery snooping initialization failed");
1156 if (!hostapd_drv_none(hapd
) && vlan_init(hapd
)) {
1157 wpa_printf(MSG_ERROR
, "VLAN initialization failed.");
1161 if (!conf
->start_disabled
&& ieee802_11_set_beacon(hapd
) < 0)
1164 if (hapd
->wpa_auth
&& wpa_init_keys(hapd
->wpa_auth
) < 0)
1167 if (hapd
->driver
&& hapd
->driver
->set_operstate
)
1168 hapd
->driver
->set_operstate(hapd
->drv_priv
, 1);
1174 static void hostapd_tx_queue_params(struct hostapd_iface
*iface
)
1176 struct hostapd_data
*hapd
= iface
->bss
[0];
1178 struct hostapd_tx_queue_params
*p
;
1181 if ((hapd
->conf
->mesh
& MESH_ENABLED
) && iface
->mconf
== NULL
)
1183 #endif /* CONFIG_MESH */
1185 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
1186 p
= &iface
->conf
->tx_queue
[i
];
1188 if (hostapd_set_tx_queue_params(hapd
, i
, p
->aifs
, p
->cwmin
,
1189 p
->cwmax
, p
->burst
)) {
1190 wpa_printf(MSG_DEBUG
, "Failed to set TX queue "
1191 "parameters for queue %d.", i
);
1192 /* Continue anyway */
1198 static int hostapd_set_acl_list(struct hostapd_data
*hapd
,
1199 struct mac_acl_entry
*mac_acl
,
1200 int n_entries
, u8 accept_acl
)
1202 struct hostapd_acl_params
*acl_params
;
1205 acl_params
= os_zalloc(sizeof(*acl_params
) +
1206 (n_entries
* sizeof(acl_params
->mac_acl
[0])));
1210 for (i
= 0; i
< n_entries
; i
++)
1211 os_memcpy(acl_params
->mac_acl
[i
].addr
, mac_acl
[i
].addr
,
1214 acl_params
->acl_policy
= accept_acl
;
1215 acl_params
->num_mac_acl
= n_entries
;
1217 err
= hostapd_drv_set_acl(hapd
, acl_params
);
1219 os_free(acl_params
);
1225 static void hostapd_set_acl(struct hostapd_data
*hapd
)
1227 struct hostapd_config
*conf
= hapd
->iconf
;
1231 if (hapd
->iface
->drv_max_acl_mac_addrs
== 0)
1234 if (conf
->bss
[0]->macaddr_acl
== DENY_UNLESS_ACCEPTED
) {
1236 err
= hostapd_set_acl_list(hapd
, conf
->bss
[0]->accept_mac
,
1237 conf
->bss
[0]->num_accept_mac
,
1240 wpa_printf(MSG_DEBUG
, "Failed to set accept acl");
1243 } else if (conf
->bss
[0]->macaddr_acl
== ACCEPT_UNLESS_DENIED
) {
1245 err
= hostapd_set_acl_list(hapd
, conf
->bss
[0]->deny_mac
,
1246 conf
->bss
[0]->num_deny_mac
,
1249 wpa_printf(MSG_DEBUG
, "Failed to set deny acl");
1256 static int start_ctrl_iface_bss(struct hostapd_data
*hapd
)
1258 if (!hapd
->iface
->interfaces
||
1259 !hapd
->iface
->interfaces
->ctrl_iface_init
)
1262 if (hapd
->iface
->interfaces
->ctrl_iface_init(hapd
)) {
1263 wpa_printf(MSG_ERROR
,
1264 "Failed to setup control interface for %s",
1273 static int start_ctrl_iface(struct hostapd_iface
*iface
)
1277 if (!iface
->interfaces
|| !iface
->interfaces
->ctrl_iface_init
)
1280 for (i
= 0; i
< iface
->num_bss
; i
++) {
1281 struct hostapd_data
*hapd
= iface
->bss
[i
];
1282 if (iface
->interfaces
->ctrl_iface_init(hapd
)) {
1283 wpa_printf(MSG_ERROR
,
1284 "Failed to setup control interface for %s",
1294 static void channel_list_update_timeout(void *eloop_ctx
, void *timeout_ctx
)
1296 struct hostapd_iface
*iface
= eloop_ctx
;
1298 if (!iface
->wait_channel_update
) {
1299 wpa_printf(MSG_INFO
, "Channel list update timeout, but interface was not waiting for it");
1304 * It is possible that the existing channel list is acceptable, so try
1307 wpa_printf(MSG_DEBUG
, "Channel list update timeout - try to continue anyway");
1308 setup_interface2(iface
);
1312 void hostapd_channel_list_updated(struct hostapd_iface
*iface
, int initiator
)
1314 if (!iface
->wait_channel_update
|| initiator
!= REGDOM_SET_BY_USER
)
1317 wpa_printf(MSG_DEBUG
, "Channel list updated - continue setup");
1318 eloop_cancel_timeout(channel_list_update_timeout
, iface
, NULL
);
1319 setup_interface2(iface
);
1323 static int setup_interface(struct hostapd_iface
*iface
)
1325 struct hostapd_data
*hapd
= iface
->bss
[0];
1329 * It is possible that setup_interface() is called after the interface
1330 * was disabled etc., in which case driver_ap_teardown is possibly set
1331 * to 1. Clear it here so any other key/station deletion, which is not
1332 * part of a teardown flow, would also call the relevant driver
1335 iface
->driver_ap_teardown
= 0;
1337 if (!iface
->phy
[0]) {
1338 const char *phy
= hostapd_drv_get_radio_name(hapd
);
1340 wpa_printf(MSG_DEBUG
, "phy: %s", phy
);
1341 os_strlcpy(iface
->phy
, phy
, sizeof(iface
->phy
));
1346 * Make sure that all BSSes get configured with a pointer to the same
1349 for (i
= 1; i
< iface
->num_bss
; i
++) {
1350 iface
->bss
[i
]->driver
= hapd
->driver
;
1351 iface
->bss
[i
]->drv_priv
= hapd
->drv_priv
;
1354 if (hostapd_validate_bssid_configuration(iface
))
1358 * Initialize control interfaces early to allow external monitoring of
1359 * channel setup operations that may take considerable amount of time
1360 * especially for DFS cases.
1362 if (start_ctrl_iface(iface
))
1365 if (hapd
->iconf
->country
[0] && hapd
->iconf
->country
[1]) {
1366 char country
[4], previous_country
[4];
1368 hostapd_set_state(iface
, HAPD_IFACE_COUNTRY_UPDATE
);
1369 if (hostapd_get_country(hapd
, previous_country
) < 0)
1370 previous_country
[0] = '\0';
1372 os_memcpy(country
, hapd
->iconf
->country
, 3);
1374 if (hostapd_set_country(hapd
, country
) < 0) {
1375 wpa_printf(MSG_ERROR
, "Failed to set country code");
1379 wpa_printf(MSG_DEBUG
, "Previous country code %s, new country code %s",
1380 previous_country
, country
);
1382 if (os_strncmp(previous_country
, country
, 2) != 0) {
1383 wpa_printf(MSG_DEBUG
, "Continue interface setup after channel list update");
1384 iface
->wait_channel_update
= 1;
1385 eloop_register_timeout(5, 0,
1386 channel_list_update_timeout
,
1392 return setup_interface2(iface
);
1396 static int setup_interface2(struct hostapd_iface
*iface
)
1398 iface
->wait_channel_update
= 0;
1400 if (hostapd_get_hw_features(iface
)) {
1401 /* Not all drivers support this yet, so continue without hw
1404 int ret
= hostapd_select_hw_mode(iface
);
1406 wpa_printf(MSG_ERROR
, "Could not select hw_mode and "
1407 "channel. (%d)", ret
);
1411 wpa_printf(MSG_DEBUG
, "Interface initialization will be completed in a callback (ACS)");
1414 ret
= hostapd_check_ht_capab(iface
);
1418 wpa_printf(MSG_DEBUG
, "Interface initialization will "
1419 "be completed in a callback");
1423 if (iface
->conf
->ieee80211h
)
1424 wpa_printf(MSG_DEBUG
, "DFS support is enabled");
1426 return hostapd_setup_interface_complete(iface
, 0);
1429 hostapd_set_state(iface
, HAPD_IFACE_DISABLED
);
1430 wpa_msg(iface
->bss
[0]->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
1431 if (iface
->interfaces
&& iface
->interfaces
->terminate_on_error
)
1439 static const u8
* fst_hostapd_get_bssid_cb(void *ctx
)
1441 struct hostapd_data
*hapd
= ctx
;
1443 return hapd
->own_addr
;
1447 static void fst_hostapd_get_channel_info_cb(void *ctx
,
1448 enum hostapd_hw_mode
*hw_mode
,
1451 struct hostapd_data
*hapd
= ctx
;
1453 *hw_mode
= ieee80211_freq_to_chan(hapd
->iface
->freq
, channel
);
1457 static void fst_hostapd_set_ies_cb(void *ctx
, const struct wpabuf
*fst_ies
)
1459 struct hostapd_data
*hapd
= ctx
;
1461 if (hapd
->iface
->fst_ies
!= fst_ies
) {
1462 hapd
->iface
->fst_ies
= fst_ies
;
1463 if (ieee802_11_set_beacon(hapd
))
1464 wpa_printf(MSG_WARNING
, "FST: Cannot set beacon");
1469 static int fst_hostapd_send_action_cb(void *ctx
, const u8
*da
,
1472 struct hostapd_data
*hapd
= ctx
;
1474 return hostapd_drv_send_action(hapd
, hapd
->iface
->freq
, 0, da
,
1475 wpabuf_head(buf
), wpabuf_len(buf
));
1479 static const struct wpabuf
* fst_hostapd_get_mb_ie_cb(void *ctx
, const u8
*addr
)
1481 struct hostapd_data
*hapd
= ctx
;
1482 struct sta_info
*sta
= ap_get_sta(hapd
, addr
);
1484 return sta
? sta
->mb_ies
: NULL
;
1488 static void fst_hostapd_update_mb_ie_cb(void *ctx
, const u8
*addr
,
1489 const u8
*buf
, size_t size
)
1491 struct hostapd_data
*hapd
= ctx
;
1492 struct sta_info
*sta
= ap_get_sta(hapd
, addr
);
1495 struct mb_ies_info info
;
1497 if (!mb_ies_info_by_ies(&info
, buf
, size
)) {
1498 wpabuf_free(sta
->mb_ies
);
1499 sta
->mb_ies
= mb_ies_by_info(&info
);
1505 static const u8
* fst_hostapd_get_sta(struct fst_get_peer_ctx
**get_ctx
,
1508 struct sta_info
*s
= (struct sta_info
*) *get_ctx
;
1511 for (; s
&& !s
->mb_ies
; s
= s
->next
)
1516 *get_ctx
= (struct fst_get_peer_ctx
*) s
->next
;
1526 static const u8
* fst_hostapd_get_peer_first(void *ctx
,
1527 struct fst_get_peer_ctx
**get_ctx
,
1530 struct hostapd_data
*hapd
= ctx
;
1532 *get_ctx
= (struct fst_get_peer_ctx
*) hapd
->sta_list
;
1534 return fst_hostapd_get_sta(get_ctx
, mb_only
);
1538 static const u8
* fst_hostapd_get_peer_next(void *ctx
,
1539 struct fst_get_peer_ctx
**get_ctx
,
1542 return fst_hostapd_get_sta(get_ctx
, mb_only
);
1546 void fst_hostapd_fill_iface_obj(struct hostapd_data
*hapd
,
1547 struct fst_wpa_obj
*iface_obj
)
1549 iface_obj
->ctx
= hapd
;
1550 iface_obj
->get_bssid
= fst_hostapd_get_bssid_cb
;
1551 iface_obj
->get_channel_info
= fst_hostapd_get_channel_info_cb
;
1552 iface_obj
->set_ies
= fst_hostapd_set_ies_cb
;
1553 iface_obj
->send_action
= fst_hostapd_send_action_cb
;
1554 iface_obj
->get_mb_ie
= fst_hostapd_get_mb_ie_cb
;
1555 iface_obj
->update_mb_ie
= fst_hostapd_update_mb_ie_cb
;
1556 iface_obj
->get_peer_first
= fst_hostapd_get_peer_first
;
1557 iface_obj
->get_peer_next
= fst_hostapd_get_peer_next
;
1560 #endif /* CONFIG_FST */
1564 static enum nr_chan_width
hostapd_get_nr_chan_width(struct hostapd_data
*hapd
,
1568 return NR_CHAN_WIDTH_20
;
1569 if (!hapd
->iconf
->secondary_channel
)
1570 return NR_CHAN_WIDTH_20
;
1571 if (!vht
|| hapd
->iconf
->vht_oper_chwidth
== VHT_CHANWIDTH_USE_HT
)
1572 return NR_CHAN_WIDTH_40
;
1573 if (hapd
->iconf
->vht_oper_chwidth
== VHT_CHANWIDTH_80MHZ
)
1574 return NR_CHAN_WIDTH_80
;
1575 if (hapd
->iconf
->vht_oper_chwidth
== VHT_CHANWIDTH_160MHZ
)
1576 return NR_CHAN_WIDTH_160
;
1577 if (hapd
->iconf
->vht_oper_chwidth
== VHT_CHANWIDTH_80P80MHZ
)
1578 return NR_CHAN_WIDTH_80P80
;
1579 return NR_CHAN_WIDTH_20
;
1581 #endif /* NEED_AP_MLME */
1584 static void hostapd_set_own_neighbor_report(struct hostapd_data
*hapd
)
1587 u16 capab
= hostapd_own_capab_info(hapd
);
1588 int ht
= hapd
->iconf
->ieee80211n
&& !hapd
->conf
->disable_11n
;
1589 int vht
= hapd
->iconf
->ieee80211ac
&& !hapd
->conf
->disable_11ac
;
1590 struct wpa_ssid_value ssid
;
1591 u8 channel
, op_class
;
1592 u8 center_freq1_idx
= 0, center_freq2_idx
= 0;
1593 enum nr_chan_width width
;
1597 if (!(hapd
->conf
->radio_measurements
[0] &
1598 WLAN_RRM_CAPS_NEIGHBOR_REPORT
))
1601 bssid_info
= 3; /* AP is reachable */
1602 bssid_info
|= NEI_REP_BSSID_INFO_SECURITY
; /* "same as the AP" */
1603 bssid_info
|= NEI_REP_BSSID_INFO_KEY_SCOPE
; /* "same as the AP" */
1605 if (capab
& WLAN_CAPABILITY_SPECTRUM_MGMT
)
1606 bssid_info
|= NEI_REP_BSSID_INFO_SPECTRUM_MGMT
;
1608 bssid_info
|= NEI_REP_BSSID_INFO_RM
; /* RRM is supported */
1610 if (hapd
->conf
->wmm_enabled
) {
1611 bssid_info
|= NEI_REP_BSSID_INFO_QOS
;
1613 if (hapd
->conf
->wmm_uapsd
&&
1614 (hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_AP_UAPSD
))
1615 bssid_info
|= NEI_REP_BSSID_INFO_APSD
;
1619 bssid_info
|= NEI_REP_BSSID_INFO_HT
|
1620 NEI_REP_BSSID_INFO_DELAYED_BA
;
1622 /* VHT bit added in IEEE P802.11-REVmc/D4.3 */
1624 bssid_info
|= NEI_REP_BSSID_INFO_VHT
;
1627 /* TODO: Set NEI_REP_BSSID_INFO_MOBILITY_DOMAIN if MDE is set */
1629 if (ieee80211_freq_to_channel_ext(hapd
->iface
->freq
,
1630 hapd
->iconf
->secondary_channel
,
1631 hapd
->iconf
->vht_oper_chwidth
,
1632 &op_class
, &channel
) ==
1635 width
= hostapd_get_nr_chan_width(hapd
, ht
, vht
);
1637 center_freq1_idx
= hapd
->iconf
->vht_oper_centr_freq_seg0_idx
;
1638 if (width
== NR_CHAN_WIDTH_80P80
)
1640 hapd
->iconf
->vht_oper_centr_freq_seg1_idx
;
1642 ieee80211_freq_to_chan(hapd
->iface
->freq
+
1643 10 * hapd
->iconf
->secondary_channel
,
1647 ssid
.ssid_len
= hapd
->conf
->ssid
.ssid_len
;
1648 os_memcpy(ssid
.ssid
, hapd
->conf
->ssid
.ssid
, ssid
.ssid_len
);
1651 * Neighbor Report element size = BSSID + BSSID info + op_class + chan +
1652 * phy type + wide bandwidth channel subelement.
1654 nr
= wpabuf_alloc(ETH_ALEN
+ 4 + 1 + 1 + 1 + 5);
1658 wpabuf_put_data(nr
, hapd
->own_addr
, ETH_ALEN
);
1659 wpabuf_put_le32(nr
, bssid_info
);
1660 wpabuf_put_u8(nr
, op_class
);
1661 wpabuf_put_u8(nr
, channel
);
1662 wpabuf_put_u8(nr
, ieee80211_get_phy_type(hapd
->iface
->freq
, ht
, vht
));
1665 * Wide Bandwidth Channel subelement may be needed to allow the
1666 * receiving STA to send packets to the AP. See IEEE P802.11-REVmc/D5.0
1669 wpabuf_put_u8(nr
, WNM_NEIGHBOR_WIDE_BW_CHAN
);
1670 wpabuf_put_u8(nr
, 3);
1671 wpabuf_put_u8(nr
, width
);
1672 wpabuf_put_u8(nr
, center_freq1_idx
);
1673 wpabuf_put_u8(nr
, center_freq2_idx
);
1675 hostapd_neighbor_set(hapd
, hapd
->own_addr
, &ssid
, nr
, hapd
->iconf
->lci
,
1676 hapd
->iconf
->civic
, hapd
->iconf
->stationary_ap
);
1679 #endif /* NEED_AP_MLME */
1683 static int hostapd_setup_interface_complete_sync(struct hostapd_iface
*iface
,
1686 struct hostapd_data
*hapd
= iface
->bss
[0];
1689 int delay_apply_cfg
= 0;
1690 int res_dfs_offload
= 0;
1695 wpa_printf(MSG_DEBUG
, "Completing interface initialization");
1696 if (iface
->conf
->channel
) {
1699 #endif /* NEED_AP_MLME */
1701 iface
->freq
= hostapd_hw_get_freq(hapd
, iface
->conf
->channel
);
1702 wpa_printf(MSG_DEBUG
, "Mode: %s Channel: %d "
1703 "Frequency: %d MHz",
1704 hostapd_hw_mode_txt(iface
->conf
->hw_mode
),
1705 iface
->conf
->channel
, iface
->freq
);
1708 /* Handle DFS only if it is not offloaded to the driver */
1709 if (!(iface
->drv_flags
& WPA_DRIVER_FLAGS_DFS_OFFLOAD
)) {
1711 res
= hostapd_handle_dfs(iface
);
1718 /* If DFS is offloaded to the driver */
1719 res_dfs_offload
= hostapd_handle_dfs_offload(iface
);
1720 if (res_dfs_offload
<= 0) {
1721 if (res_dfs_offload
< 0)
1724 wpa_printf(MSG_DEBUG
,
1725 "Proceed with AP/channel setup");
1727 * If this is a DFS channel, move to completing
1730 if (res_dfs_offload
== 1)
1732 /* Otherwise fall through. */
1735 #endif /* NEED_AP_MLME */
1738 if (iface
->mconf
!= NULL
) {
1739 wpa_printf(MSG_DEBUG
,
1740 "%s: Mesh configuration will be applied while joining the mesh network",
1741 iface
->bss
[0]->conf
->iface
);
1742 delay_apply_cfg
= 1;
1744 #endif /* CONFIG_MESH */
1746 if (!delay_apply_cfg
&&
1747 hostapd_set_freq(hapd
, hapd
->iconf
->hw_mode
, iface
->freq
,
1748 hapd
->iconf
->channel
,
1749 hapd
->iconf
->ieee80211n
,
1750 hapd
->iconf
->ieee80211ac
,
1751 hapd
->iconf
->secondary_channel
,
1752 hapd
->iconf
->vht_oper_chwidth
,
1753 hapd
->iconf
->vht_oper_centr_freq_seg0_idx
,
1754 hapd
->iconf
->vht_oper_centr_freq_seg1_idx
)) {
1755 wpa_printf(MSG_ERROR
, "Could not set channel for "
1761 if (iface
->current_mode
) {
1762 if (hostapd_prepare_rates(iface
, iface
->current_mode
)) {
1763 wpa_printf(MSG_ERROR
, "Failed to prepare rates "
1765 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE80211
,
1766 HOSTAPD_LEVEL_WARNING
,
1767 "Failed to prepare rates table.");
1772 if (hapd
->iconf
->rts_threshold
> -1 &&
1773 hostapd_set_rts(hapd
, hapd
->iconf
->rts_threshold
)) {
1774 wpa_printf(MSG_ERROR
, "Could not set RTS threshold for "
1779 if (hapd
->iconf
->fragm_threshold
> -1 &&
1780 hostapd_set_frag(hapd
, hapd
->iconf
->fragm_threshold
)) {
1781 wpa_printf(MSG_ERROR
, "Could not set fragmentation threshold "
1782 "for kernel driver");
1786 prev_addr
= hapd
->own_addr
;
1788 for (j
= 0; j
< iface
->num_bss
; j
++) {
1789 hapd
= iface
->bss
[j
];
1791 os_memcpy(hapd
->own_addr
, prev_addr
, ETH_ALEN
);
1792 if (hostapd_setup_bss(hapd
, j
== 0)) {
1794 hapd
= iface
->bss
[j
];
1795 hostapd_bss_deinit_no_free(hapd
);
1796 hostapd_free_hapd_data(hapd
);
1800 if (is_zero_ether_addr(hapd
->conf
->bssid
))
1801 prev_addr
= hapd
->own_addr
;
1803 hapd
= iface
->bss
[0];
1805 hostapd_tx_queue_params(iface
);
1807 ap_list_init(iface
);
1809 hostapd_set_acl(hapd
);
1811 if (hostapd_driver_commit(hapd
) < 0) {
1812 wpa_printf(MSG_ERROR
, "%s: Failed to commit driver "
1813 "configuration", __func__
);
1818 * WPS UPnP module can be initialized only when the "upnp_iface" is up.
1819 * If "interface" and "upnp_iface" are the same (e.g., non-bridge
1820 * mode), the interface is up only after driver_commit, so initialize
1821 * WPS after driver_commit.
1823 for (j
= 0; j
< iface
->num_bss
; j
++) {
1824 if (hostapd_init_wps_complete(iface
->bss
[j
]))
1828 if ((iface
->drv_flags
& WPA_DRIVER_FLAGS_DFS_OFFLOAD
) &&
1831 * If freq is DFS, and DFS is offloaded to the driver, then wait
1832 * for CAC to complete.
1834 wpa_printf(MSG_DEBUG
, "%s: Wait for CAC to complete", __func__
);
1835 return res_dfs_offload
;
1840 #endif /* NEED_AP_MLME */
1843 if (hapd
->iconf
->fst_cfg
.group_id
[0]) {
1844 struct fst_wpa_obj iface_obj
;
1846 fst_hostapd_fill_iface_obj(hapd
, &iface_obj
);
1847 iface
->fst
= fst_attach(hapd
->conf
->iface
, hapd
->own_addr
,
1848 &iface_obj
, &hapd
->iconf
->fst_cfg
);
1850 wpa_printf(MSG_ERROR
, "Could not attach to FST %s",
1851 hapd
->iconf
->fst_cfg
.group_id
);
1855 #endif /* CONFIG_FST */
1857 hostapd_set_state(iface
, HAPD_IFACE_ENABLED
);
1858 wpa_msg(iface
->bss
[0]->msg_ctx
, MSG_INFO
, AP_EVENT_ENABLED
);
1859 if (hapd
->setup_complete_cb
)
1860 hapd
->setup_complete_cb(hapd
->setup_complete_cb_ctx
);
1862 wpa_printf(MSG_DEBUG
, "%s: Setup of interface done.",
1863 iface
->bss
[0]->conf
->iface
);
1864 if (iface
->interfaces
&& iface
->interfaces
->terminate_on_error
> 0)
1865 iface
->interfaces
->terminate_on_error
--;
1867 for (j
= 0; j
< iface
->num_bss
; j
++)
1868 hostapd_set_own_neighbor_report(iface
->bss
[j
]);
1873 wpa_printf(MSG_ERROR
, "Interface initialization failed");
1874 hostapd_set_state(iface
, HAPD_IFACE_DISABLED
);
1875 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
1878 fst_detach(iface
->fst
);
1881 #endif /* CONFIG_FST */
1882 if (iface
->interfaces
&& iface
->interfaces
->terminate_on_error
)
1889 * hostapd_setup_interface_complete - Complete interface setup
1891 * This function is called when previous steps in the interface setup has been
1892 * completed. This can also start operations, e.g., DFS, that will require
1893 * additional processing before interface is ready to be enabled. Such
1894 * operations will call this function from eloop callbacks when finished.
1896 int hostapd_setup_interface_complete(struct hostapd_iface
*iface
, int err
)
1898 struct hapd_interfaces
*interfaces
= iface
->interfaces
;
1899 struct hostapd_data
*hapd
= iface
->bss
[0];
1901 int not_ready_in_sync_ifaces
= 0;
1903 if (!iface
->need_to_start_in_sync
)
1904 return hostapd_setup_interface_complete_sync(iface
, err
);
1907 wpa_printf(MSG_ERROR
, "Interface initialization failed");
1908 hostapd_set_state(iface
, HAPD_IFACE_DISABLED
);
1909 iface
->need_to_start_in_sync
= 0;
1910 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
1911 if (interfaces
&& interfaces
->terminate_on_error
)
1916 if (iface
->ready_to_start_in_sync
) {
1917 /* Already in ready and waiting. should never happpen */
1921 for (i
= 0; i
< interfaces
->count
; i
++) {
1922 if (interfaces
->iface
[i
]->need_to_start_in_sync
&&
1923 !interfaces
->iface
[i
]->ready_to_start_in_sync
)
1924 not_ready_in_sync_ifaces
++;
1928 * Check if this is the last interface, if yes then start all the other
1929 * waiting interfaces. If not, add this interface to the waiting list.
1931 if (not_ready_in_sync_ifaces
> 1 && iface
->state
== HAPD_IFACE_DFS
) {
1933 * If this interface went through CAC, do not synchronize, just
1934 * start immediately.
1936 iface
->need_to_start_in_sync
= 0;
1937 wpa_printf(MSG_INFO
,
1938 "%s: Finished CAC - bypass sync and start interface",
1939 iface
->bss
[0]->conf
->iface
);
1940 return hostapd_setup_interface_complete_sync(iface
, err
);
1943 if (not_ready_in_sync_ifaces
> 1) {
1944 /* need to wait as there are other interfaces still coming up */
1945 iface
->ready_to_start_in_sync
= 1;
1946 wpa_printf(MSG_INFO
,
1947 "%s: Interface waiting to sync with other interfaces",
1948 iface
->bss
[0]->conf
->iface
);
1952 wpa_printf(MSG_INFO
,
1953 "%s: Last interface to sync - starting all interfaces",
1954 iface
->bss
[0]->conf
->iface
);
1955 iface
->need_to_start_in_sync
= 0;
1956 hostapd_setup_interface_complete_sync(iface
, err
);
1957 for (i
= 0; i
< interfaces
->count
; i
++) {
1958 if (interfaces
->iface
[i
]->need_to_start_in_sync
&&
1959 interfaces
->iface
[i
]->ready_to_start_in_sync
) {
1960 hostapd_setup_interface_complete_sync(
1961 interfaces
->iface
[i
], 0);
1962 /* Only once the interfaces are sync started */
1963 interfaces
->iface
[i
]->need_to_start_in_sync
= 0;
1972 * hostapd_setup_interface - Setup of an interface
1973 * @iface: Pointer to interface data.
1974 * Returns: 0 on success, -1 on failure
1976 * Initializes the driver interface, validates the configuration,
1977 * and sets driver parameters based on the configuration.
1978 * Flushes old stations, sets the channel, encryption,
1979 * beacons, and WDS links based on the configuration.
1981 * If interface setup requires more time, e.g., to perform HT co-ex scans, ACS,
1982 * or DFS operations, this function returns 0 before such operations have been
1983 * completed. The pending operations are registered into eloop and will be
1984 * completed from eloop callbacks. Those callbacks end up calling
1985 * hostapd_setup_interface_complete() once setup has been completed.
1987 int hostapd_setup_interface(struct hostapd_iface
*iface
)
1991 ret
= setup_interface(iface
);
1993 wpa_printf(MSG_ERROR
, "%s: Unable to setup interface.",
1994 iface
->bss
[0]->conf
->iface
);
2003 * hostapd_alloc_bss_data - Allocate and initialize per-BSS data
2004 * @hapd_iface: Pointer to interface data
2005 * @conf: Pointer to per-interface configuration
2006 * @bss: Pointer to per-BSS configuration for this BSS
2007 * Returns: Pointer to allocated BSS data
2009 * This function is used to allocate per-BSS data structure. This data will be
2010 * freed after hostapd_cleanup() is called for it during interface
2013 struct hostapd_data
*
2014 hostapd_alloc_bss_data(struct hostapd_iface
*hapd_iface
,
2015 struct hostapd_config
*conf
,
2016 struct hostapd_bss_config
*bss
)
2018 struct hostapd_data
*hapd
;
2020 hapd
= os_zalloc(sizeof(*hapd
));
2024 hapd
->new_assoc_sta_cb
= hostapd_new_assoc_sta
;
2027 hapd
->iface
= hapd_iface
;
2029 hapd
->driver
= conf
->driver
;
2030 hapd
->ctrl_sock
= -1;
2031 dl_list_init(&hapd
->ctrl_dst
);
2032 dl_list_init(&hapd
->nr_db
);
2033 hapd
->dhcp_sock
= -1;
2034 #ifdef CONFIG_IEEE80211R_AP
2035 dl_list_init(&hapd
->l2_queue
);
2036 dl_list_init(&hapd
->l2_oui_queue
);
2037 #endif /* CONFIG_IEEE80211R_AP */
2043 static void hostapd_bss_deinit(struct hostapd_data
*hapd
)
2047 wpa_printf(MSG_DEBUG
, "%s: deinit bss %s", __func__
,
2049 hostapd_bss_deinit_no_free(hapd
);
2050 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
2051 hostapd_cleanup(hapd
);
2055 void hostapd_interface_deinit(struct hostapd_iface
*iface
)
2059 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
2063 hostapd_set_state(iface
, HAPD_IFACE_DISABLED
);
2065 #ifdef CONFIG_IEEE80211N
2067 hostapd_stop_setup_timers(iface
);
2068 eloop_cancel_timeout(ap_ht2040_timeout
, iface
, NULL
);
2069 #endif /* NEED_AP_MLME */
2070 #endif /* CONFIG_IEEE80211N */
2071 eloop_cancel_timeout(channel_list_update_timeout
, iface
, NULL
);
2072 iface
->wait_channel_update
= 0;
2076 fst_detach(iface
->fst
);
2079 #endif /* CONFIG_FST */
2081 for (j
= iface
->num_bss
- 1; j
>= 0; j
--) {
2084 hostapd_bss_deinit(iface
->bss
[j
]);
2089 void hostapd_interface_free(struct hostapd_iface
*iface
)
2092 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
2093 for (j
= 0; j
< iface
->num_bss
; j
++) {
2096 wpa_printf(MSG_DEBUG
, "%s: free hapd %p",
2097 __func__
, iface
->bss
[j
]);
2098 os_free(iface
->bss
[j
]);
2100 hostapd_cleanup_iface(iface
);
2104 struct hostapd_iface
* hostapd_alloc_iface(void)
2106 struct hostapd_iface
*hapd_iface
;
2108 hapd_iface
= os_zalloc(sizeof(*hapd_iface
));
2112 dl_list_init(&hapd_iface
->sta_seen
);
2119 * hostapd_init - Allocate and initialize per-interface data
2120 * @config_file: Path to the configuration file
2121 * Returns: Pointer to the allocated interface data or %NULL on failure
2123 * This function is used to allocate main data structures for per-interface
2124 * data. The allocated data buffer will be freed by calling
2125 * hostapd_cleanup_iface().
2127 struct hostapd_iface
* hostapd_init(struct hapd_interfaces
*interfaces
,
2128 const char *config_file
)
2130 struct hostapd_iface
*hapd_iface
= NULL
;
2131 struct hostapd_config
*conf
= NULL
;
2132 struct hostapd_data
*hapd
;
2135 hapd_iface
= hostapd_alloc_iface();
2136 if (hapd_iface
== NULL
)
2139 hapd_iface
->config_fname
= os_strdup(config_file
);
2140 if (hapd_iface
->config_fname
== NULL
)
2143 conf
= interfaces
->config_read_cb(hapd_iface
->config_fname
);
2146 hapd_iface
->conf
= conf
;
2148 hapd_iface
->num_bss
= conf
->num_bss
;
2149 hapd_iface
->bss
= os_calloc(conf
->num_bss
,
2150 sizeof(struct hostapd_data
*));
2151 if (hapd_iface
->bss
== NULL
)
2154 for (i
= 0; i
< conf
->num_bss
; i
++) {
2155 hapd
= hapd_iface
->bss
[i
] =
2156 hostapd_alloc_bss_data(hapd_iface
, conf
,
2160 hapd
->msg_ctx
= hapd
;
2166 wpa_printf(MSG_ERROR
, "Failed to set up interface with %s",
2169 hostapd_config_free(conf
);
2171 os_free(hapd_iface
->config_fname
);
2172 os_free(hapd_iface
->bss
);
2173 wpa_printf(MSG_DEBUG
, "%s: free iface %p",
2174 __func__
, hapd_iface
);
2175 os_free(hapd_iface
);
2181 static int ifname_in_use(struct hapd_interfaces
*interfaces
, const char *ifname
)
2185 for (i
= 0; i
< interfaces
->count
; i
++) {
2186 struct hostapd_iface
*iface
= interfaces
->iface
[i
];
2187 for (j
= 0; j
< iface
->num_bss
; j
++) {
2188 struct hostapd_data
*hapd
= iface
->bss
[j
];
2189 if (os_strcmp(ifname
, hapd
->conf
->iface
) == 0)
2199 * hostapd_interface_init_bss - Read configuration file and init BSS data
2201 * This function is used to parse configuration file for a BSS. This BSS is
2202 * added to an existing interface sharing the same radio (if any) or a new
2203 * interface is created if this is the first interface on a radio. This
2204 * allocate memory for the BSS. No actual driver operations are started.
2206 * This is similar to hostapd_interface_init(), but for a case where the
2207 * configuration is used to add a single BSS instead of all BSSes for a radio.
2209 struct hostapd_iface
*
2210 hostapd_interface_init_bss(struct hapd_interfaces
*interfaces
, const char *phy
,
2211 const char *config_fname
, int debug
)
2213 struct hostapd_iface
*new_iface
= NULL
, *iface
= NULL
;
2214 struct hostapd_data
*hapd
;
2221 for (i
= 0; i
< interfaces
->count
; i
++) {
2222 if (os_strcmp(interfaces
->iface
[i
]->phy
, phy
) == 0) {
2223 iface
= interfaces
->iface
[i
];
2228 wpa_printf(MSG_INFO
, "Configuration file: %s (phy %s)%s",
2229 config_fname
, phy
, iface
? "" : " --> new PHY");
2231 struct hostapd_config
*conf
;
2232 struct hostapd_bss_config
**tmp_conf
;
2233 struct hostapd_data
**tmp_bss
;
2234 struct hostapd_bss_config
*bss
;
2237 /* Add new BSS to existing iface */
2238 conf
= interfaces
->config_read_cb(config_fname
);
2241 if (conf
->num_bss
> 1) {
2242 wpa_printf(MSG_ERROR
, "Multiple BSSes specified in BSS-config");
2243 hostapd_config_free(conf
);
2247 ifname
= conf
->bss
[0]->iface
;
2248 if (ifname
[0] != '\0' && ifname_in_use(interfaces
, ifname
)) {
2249 wpa_printf(MSG_ERROR
,
2250 "Interface name %s already in use", ifname
);
2251 hostapd_config_free(conf
);
2255 tmp_conf
= os_realloc_array(
2256 iface
->conf
->bss
, iface
->conf
->num_bss
+ 1,
2257 sizeof(struct hostapd_bss_config
*));
2258 tmp_bss
= os_realloc_array(iface
->bss
, iface
->num_bss
+ 1,
2259 sizeof(struct hostapd_data
*));
2261 iface
->bss
= tmp_bss
;
2263 iface
->conf
->bss
= tmp_conf
;
2264 iface
->conf
->last_bss
= tmp_conf
[0];
2266 if (tmp_bss
== NULL
|| tmp_conf
== NULL
) {
2267 hostapd_config_free(conf
);
2270 bss
= iface
->conf
->bss
[iface
->conf
->num_bss
] = conf
->bss
[0];
2271 iface
->conf
->num_bss
++;
2273 hapd
= hostapd_alloc_bss_data(iface
, iface
->conf
, bss
);
2275 iface
->conf
->num_bss
--;
2276 hostapd_config_free(conf
);
2279 iface
->conf
->last_bss
= bss
;
2280 iface
->bss
[iface
->num_bss
] = hapd
;
2281 hapd
->msg_ctx
= hapd
;
2283 bss_idx
= iface
->num_bss
++;
2285 conf
->bss
[0] = NULL
;
2286 hostapd_config_free(conf
);
2288 /* Add a new iface with the first BSS */
2289 new_iface
= iface
= hostapd_init(interfaces
, config_fname
);
2292 os_strlcpy(iface
->phy
, phy
, sizeof(iface
->phy
));
2293 iface
->interfaces
= interfaces
;
2297 for (k
= 0; k
< debug
; k
++) {
2298 if (iface
->bss
[bss_idx
]->conf
->logger_stdout_level
> 0)
2299 iface
->bss
[bss_idx
]->conf
->logger_stdout_level
--;
2302 if (iface
->conf
->bss
[bss_idx
]->iface
[0] == '\0' &&
2303 !hostapd_drv_none(iface
->bss
[bss_idx
])) {
2304 wpa_printf(MSG_ERROR
, "Interface name not specified in %s",
2307 hostapd_interface_deinit_free(new_iface
);
2315 void hostapd_interface_deinit_free(struct hostapd_iface
*iface
)
2317 const struct wpa_driver_ops
*driver
;
2320 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
2323 wpa_printf(MSG_DEBUG
, "%s: num_bss=%u conf->num_bss=%u",
2324 __func__
, (unsigned int) iface
->num_bss
,
2325 (unsigned int) iface
->conf
->num_bss
);
2326 driver
= iface
->bss
[0]->driver
;
2327 drv_priv
= iface
->bss
[0]->drv_priv
;
2328 hostapd_interface_deinit(iface
);
2329 wpa_printf(MSG_DEBUG
, "%s: driver=%p drv_priv=%p -> hapd_deinit",
2330 __func__
, driver
, drv_priv
);
2331 if (driver
&& driver
->hapd_deinit
&& drv_priv
) {
2332 driver
->hapd_deinit(drv_priv
);
2333 iface
->bss
[0]->drv_priv
= NULL
;
2335 hostapd_interface_free(iface
);
2339 static void hostapd_deinit_driver(const struct wpa_driver_ops
*driver
,
2341 struct hostapd_iface
*hapd_iface
)
2345 wpa_printf(MSG_DEBUG
, "%s: driver=%p drv_priv=%p -> hapd_deinit",
2346 __func__
, driver
, drv_priv
);
2347 if (driver
&& driver
->hapd_deinit
&& drv_priv
) {
2348 driver
->hapd_deinit(drv_priv
);
2349 for (j
= 0; j
< hapd_iface
->num_bss
; j
++) {
2350 wpa_printf(MSG_DEBUG
, "%s:bss[%d]->drv_priv=%p",
2352 hapd_iface
->bss
[j
]->drv_priv
);
2353 if (hapd_iface
->bss
[j
]->drv_priv
== drv_priv
)
2354 hapd_iface
->bss
[j
]->drv_priv
= NULL
;
2360 int hostapd_enable_iface(struct hostapd_iface
*hapd_iface
)
2364 if (hapd_iface
->bss
[0]->drv_priv
!= NULL
) {
2365 wpa_printf(MSG_ERROR
, "Interface %s already enabled",
2366 hapd_iface
->conf
->bss
[0]->iface
);
2370 wpa_printf(MSG_DEBUG
, "Enable interface %s",
2371 hapd_iface
->conf
->bss
[0]->iface
);
2373 for (j
= 0; j
< hapd_iface
->num_bss
; j
++)
2374 hostapd_set_security_params(hapd_iface
->conf
->bss
[j
], 1);
2375 if (hostapd_config_check(hapd_iface
->conf
, 1) < 0) {
2376 wpa_printf(MSG_INFO
, "Invalid configuration - cannot enable");
2380 if (hapd_iface
->interfaces
== NULL
||
2381 hapd_iface
->interfaces
->driver_init
== NULL
||
2382 hapd_iface
->interfaces
->driver_init(hapd_iface
))
2385 if (hostapd_setup_interface(hapd_iface
)) {
2386 hostapd_deinit_driver(hapd_iface
->bss
[0]->driver
,
2387 hapd_iface
->bss
[0]->drv_priv
,
2396 int hostapd_reload_iface(struct hostapd_iface
*hapd_iface
)
2400 wpa_printf(MSG_DEBUG
, "Reload interface %s",
2401 hapd_iface
->conf
->bss
[0]->iface
);
2402 for (j
= 0; j
< hapd_iface
->num_bss
; j
++)
2403 hostapd_set_security_params(hapd_iface
->conf
->bss
[j
], 1);
2404 if (hostapd_config_check(hapd_iface
->conf
, 1) < 0) {
2405 wpa_printf(MSG_ERROR
, "Updated configuration is invalid");
2408 hostapd_clear_old(hapd_iface
);
2409 for (j
= 0; j
< hapd_iface
->num_bss
; j
++)
2410 hostapd_reload_bss(hapd_iface
->bss
[j
]);
2416 int hostapd_disable_iface(struct hostapd_iface
*hapd_iface
)
2419 const struct wpa_driver_ops
*driver
;
2422 if (hapd_iface
== NULL
)
2425 if (hapd_iface
->bss
[0]->drv_priv
== NULL
) {
2426 wpa_printf(MSG_INFO
, "Interface %s already disabled",
2427 hapd_iface
->conf
->bss
[0]->iface
);
2431 wpa_msg(hapd_iface
->bss
[0]->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
2432 driver
= hapd_iface
->bss
[0]->driver
;
2433 drv_priv
= hapd_iface
->bss
[0]->drv_priv
;
2435 hapd_iface
->driver_ap_teardown
=
2436 !!(hapd_iface
->drv_flags
&
2437 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT
);
2439 /* same as hostapd_interface_deinit without deinitializing ctrl-iface */
2440 for (j
= 0; j
< hapd_iface
->num_bss
; j
++) {
2441 struct hostapd_data
*hapd
= hapd_iface
->bss
[j
];
2442 hostapd_bss_deinit_no_free(hapd
);
2443 hostapd_free_hapd_data(hapd
);
2446 hostapd_deinit_driver(driver
, drv_priv
, hapd_iface
);
2448 /* From hostapd_cleanup_iface: These were initialized in
2449 * hostapd_setup_interface and hostapd_setup_interface_complete
2451 hostapd_cleanup_iface_partial(hapd_iface
);
2453 wpa_printf(MSG_DEBUG
, "Interface %s disabled",
2454 hapd_iface
->bss
[0]->conf
->iface
);
2455 hostapd_set_state(hapd_iface
, HAPD_IFACE_DISABLED
);
2460 static struct hostapd_iface
*
2461 hostapd_iface_alloc(struct hapd_interfaces
*interfaces
)
2463 struct hostapd_iface
**iface
, *hapd_iface
;
2465 iface
= os_realloc_array(interfaces
->iface
, interfaces
->count
+ 1,
2466 sizeof(struct hostapd_iface
*));
2469 interfaces
->iface
= iface
;
2470 hapd_iface
= interfaces
->iface
[interfaces
->count
] =
2471 hostapd_alloc_iface();
2472 if (hapd_iface
== NULL
) {
2473 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory for "
2474 "the interface", __func__
);
2477 interfaces
->count
++;
2478 hapd_iface
->interfaces
= interfaces
;
2484 static struct hostapd_config
*
2485 hostapd_config_alloc(struct hapd_interfaces
*interfaces
, const char *ifname
,
2486 const char *ctrl_iface
, const char *driver
)
2488 struct hostapd_bss_config
*bss
;
2489 struct hostapd_config
*conf
;
2491 /* Allocates memory for bss and conf */
2492 conf
= hostapd_config_defaults();
2494 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory for "
2495 "configuration", __func__
);
2502 for (j
= 0; wpa_drivers
[j
]; j
++) {
2503 if (os_strcmp(driver
, wpa_drivers
[j
]->name
) == 0) {
2504 conf
->driver
= wpa_drivers
[j
];
2509 wpa_printf(MSG_ERROR
,
2510 "Invalid/unknown driver '%s' - registering the default driver",
2514 conf
->driver
= wpa_drivers
[0];
2515 if (conf
->driver
== NULL
) {
2516 wpa_printf(MSG_ERROR
, "No driver wrappers registered!");
2517 hostapd_config_free(conf
);
2522 bss
= conf
->last_bss
= conf
->bss
[0];
2524 os_strlcpy(bss
->iface
, ifname
, sizeof(bss
->iface
));
2525 bss
->ctrl_interface
= os_strdup(ctrl_iface
);
2526 if (bss
->ctrl_interface
== NULL
) {
2527 hostapd_config_free(conf
);
2531 /* Reading configuration file skipped, will be done in SET!
2532 * From reading the configuration till the end has to be done in
2539 static int hostapd_data_alloc(struct hostapd_iface
*hapd_iface
,
2540 struct hostapd_config
*conf
)
2543 struct hostapd_data
*hapd
;
2545 hapd_iface
->bss
= os_calloc(conf
->num_bss
,
2546 sizeof(struct hostapd_data
*));
2547 if (hapd_iface
->bss
== NULL
)
2550 for (i
= 0; i
< conf
->num_bss
; i
++) {
2551 hapd
= hapd_iface
->bss
[i
] =
2552 hostapd_alloc_bss_data(hapd_iface
, conf
, conf
->bss
[i
]);
2556 os_free(hapd_iface
->bss
[i
]);
2557 hapd_iface
->bss
[i
] = NULL
;
2559 os_free(hapd_iface
->bss
);
2560 hapd_iface
->bss
= NULL
;
2563 hapd
->msg_ctx
= hapd
;
2566 hapd_iface
->conf
= conf
;
2567 hapd_iface
->num_bss
= conf
->num_bss
;
2573 int hostapd_add_iface(struct hapd_interfaces
*interfaces
, char *buf
)
2575 struct hostapd_config
*conf
= NULL
;
2576 struct hostapd_iface
*hapd_iface
= NULL
, *new_iface
= NULL
;
2577 struct hostapd_data
*hapd
;
2580 const char *conf_file
= NULL
, *phy_name
= NULL
;
2582 if (os_strncmp(buf
, "bss_config=", 11) == 0) {
2584 phy_name
= buf
+ 11;
2585 pos
= os_strchr(phy_name
, ':');
2590 if (!os_strlen(conf_file
))
2593 hapd_iface
= hostapd_interface_init_bss(interfaces
, phy_name
,
2597 for (j
= 0; j
< interfaces
->count
; j
++) {
2598 if (interfaces
->iface
[j
] == hapd_iface
)
2601 if (j
== interfaces
->count
) {
2602 struct hostapd_iface
**tmp
;
2603 tmp
= os_realloc_array(interfaces
->iface
,
2604 interfaces
->count
+ 1,
2605 sizeof(struct hostapd_iface
*));
2607 hostapd_interface_deinit_free(hapd_iface
);
2610 interfaces
->iface
= tmp
;
2611 interfaces
->iface
[interfaces
->count
++] = hapd_iface
;
2612 new_iface
= hapd_iface
;
2616 if (interfaces
->driver_init(hapd_iface
))
2619 if (hostapd_setup_interface(hapd_iface
)) {
2620 hostapd_deinit_driver(
2621 hapd_iface
->bss
[0]->driver
,
2622 hapd_iface
->bss
[0]->drv_priv
,
2627 /* Assign new BSS with bss[0]'s driver info */
2628 hapd
= hapd_iface
->bss
[hapd_iface
->num_bss
- 1];
2629 hapd
->driver
= hapd_iface
->bss
[0]->driver
;
2630 hapd
->drv_priv
= hapd_iface
->bss
[0]->drv_priv
;
2631 os_memcpy(hapd
->own_addr
, hapd_iface
->bss
[0]->own_addr
,
2634 if (start_ctrl_iface_bss(hapd
) < 0 ||
2635 (hapd_iface
->state
== HAPD_IFACE_ENABLED
&&
2636 hostapd_setup_bss(hapd
, -1))) {
2637 hostapd_cleanup(hapd
);
2638 hapd_iface
->bss
[hapd_iface
->num_bss
- 1] = NULL
;
2639 hapd_iface
->conf
->num_bss
--;
2640 hapd_iface
->num_bss
--;
2641 wpa_printf(MSG_DEBUG
, "%s: free hapd %p %s",
2642 __func__
, hapd
, hapd
->conf
->iface
);
2643 hostapd_config_free_bss(hapd
->conf
);
2652 ptr
= os_strchr(buf
, ' ');
2657 if (os_strncmp(ptr
, "config=", 7) == 0)
2658 conf_file
= ptr
+ 7;
2660 for (i
= 0; i
< interfaces
->count
; i
++) {
2661 if (!os_strcmp(interfaces
->iface
[i
]->conf
->bss
[0]->iface
,
2663 wpa_printf(MSG_INFO
, "Cannot add interface - it "
2669 hapd_iface
= hostapd_iface_alloc(interfaces
);
2670 if (hapd_iface
== NULL
) {
2671 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory "
2672 "for interface", __func__
);
2675 new_iface
= hapd_iface
;
2677 if (conf_file
&& interfaces
->config_read_cb
) {
2678 conf
= interfaces
->config_read_cb(conf_file
);
2679 if (conf
&& conf
->bss
)
2680 os_strlcpy(conf
->bss
[0]->iface
, buf
,
2681 sizeof(conf
->bss
[0]->iface
));
2683 char *driver
= os_strchr(ptr
, ' ');
2687 conf
= hostapd_config_alloc(interfaces
, buf
, ptr
, driver
);
2690 if (conf
== NULL
|| conf
->bss
== NULL
) {
2691 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory "
2692 "for configuration", __func__
);
2696 if (hostapd_data_alloc(hapd_iface
, conf
) < 0) {
2697 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory "
2698 "for hostapd", __func__
);
2703 if (start_ctrl_iface(hapd_iface
) < 0)
2706 wpa_printf(MSG_INFO
, "Add interface '%s'",
2707 hapd_iface
->conf
->bss
[0]->iface
);
2713 hostapd_config_free(conf
);
2715 if (hapd_iface
->bss
) {
2716 for (i
= 0; i
< hapd_iface
->num_bss
; i
++) {
2717 hapd
= hapd_iface
->bss
[i
];
2720 if (hapd_iface
->interfaces
&&
2721 hapd_iface
->interfaces
->ctrl_iface_deinit
)
2722 hapd_iface
->interfaces
->
2723 ctrl_iface_deinit(hapd
);
2724 wpa_printf(MSG_DEBUG
, "%s: free hapd %p (%s)",
2725 __func__
, hapd_iface
->bss
[i
],
2727 hostapd_cleanup(hapd
);
2729 hapd_iface
->bss
[i
] = NULL
;
2731 os_free(hapd_iface
->bss
);
2732 hapd_iface
->bss
= NULL
;
2735 interfaces
->count
--;
2736 interfaces
->iface
[interfaces
->count
] = NULL
;
2738 hostapd_cleanup_iface(hapd_iface
);
2744 static int hostapd_remove_bss(struct hostapd_iface
*iface
, unsigned int idx
)
2748 wpa_printf(MSG_INFO
, "Remove BSS '%s'", iface
->conf
->bss
[idx
]->iface
);
2750 /* Remove hostapd_data only if it has already been initialized */
2751 if (idx
< iface
->num_bss
) {
2752 struct hostapd_data
*hapd
= iface
->bss
[idx
];
2754 hostapd_bss_deinit(hapd
);
2755 wpa_printf(MSG_DEBUG
, "%s: free hapd %p (%s)",
2756 __func__
, hapd
, hapd
->conf
->iface
);
2757 hostapd_config_free_bss(hapd
->conf
);
2763 for (i
= idx
; i
< iface
->num_bss
; i
++)
2764 iface
->bss
[i
] = iface
->bss
[i
+ 1];
2766 hostapd_config_free_bss(iface
->conf
->bss
[idx
]);
2767 iface
->conf
->bss
[idx
] = NULL
;
2770 iface
->conf
->num_bss
--;
2771 for (i
= idx
; i
< iface
->conf
->num_bss
; i
++)
2772 iface
->conf
->bss
[i
] = iface
->conf
->bss
[i
+ 1];
2778 int hostapd_remove_iface(struct hapd_interfaces
*interfaces
, char *buf
)
2780 struct hostapd_iface
*hapd_iface
;
2783 for (i
= 0; i
< interfaces
->count
; i
++) {
2784 hapd_iface
= interfaces
->iface
[i
];
2785 if (hapd_iface
== NULL
)
2787 if (!os_strcmp(hapd_iface
->conf
->bss
[0]->iface
, buf
)) {
2788 wpa_printf(MSG_INFO
, "Remove interface '%s'", buf
);
2789 hapd_iface
->driver_ap_teardown
=
2790 !!(hapd_iface
->drv_flags
&
2791 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT
);
2793 hostapd_interface_deinit_free(hapd_iface
);
2795 while (k
< (interfaces
->count
- 1)) {
2796 interfaces
->iface
[k
] =
2797 interfaces
->iface
[k
+ 1];
2800 interfaces
->count
--;
2804 for (j
= 0; j
< hapd_iface
->conf
->num_bss
; j
++) {
2805 if (!os_strcmp(hapd_iface
->conf
->bss
[j
]->iface
, buf
)) {
2806 hapd_iface
->driver_ap_teardown
=
2807 !(hapd_iface
->drv_flags
&
2808 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT
);
2809 return hostapd_remove_bss(hapd_iface
, j
);
2818 * hostapd_new_assoc_sta - Notify that a new station associated with the AP
2819 * @hapd: Pointer to BSS data
2820 * @sta: Pointer to the associated STA data
2821 * @reassoc: 1 to indicate this was a re-association; 0 = first association
2823 * This function will be called whenever a station associates with the AP. It
2824 * can be called from ieee802_11.c for drivers that export MLME to hostapd and
2825 * from drv_callbacks.c based on driver events for drivers that take care of
2826 * management frames (IEEE 802.11 authentication and association) internally.
2828 void hostapd_new_assoc_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2831 if (hapd
->tkip_countermeasures
) {
2832 hostapd_drv_sta_deauth(hapd
, sta
->addr
,
2833 WLAN_REASON_MICHAEL_MIC_FAILURE
);
2837 hostapd_prune_associations(hapd
, sta
->addr
);
2838 ap_sta_clear_disconnect_timeouts(hapd
, sta
);
2840 /* IEEE 802.11F (IAPP) */
2841 if (hapd
->conf
->ieee802_11f
)
2842 iapp_new_station(hapd
->iapp
, sta
);
2845 if (sta
->p2p_ie
== NULL
&& !sta
->no_p2p_set
) {
2846 sta
->no_p2p_set
= 1;
2847 hapd
->num_sta_no_p2p
++;
2848 if (hapd
->num_sta_no_p2p
== 1)
2849 hostapd_p2p_non_p2p_sta_connected(hapd
);
2851 #endif /* CONFIG_P2P */
2853 /* Start accounting here, if IEEE 802.1X and WPA are not used.
2854 * IEEE 802.1X/WPA code will start accounting after the station has
2855 * been authorized. */
2856 if (!hapd
->conf
->ieee802_1x
&& !hapd
->conf
->wpa
&& !hapd
->conf
->osen
) {
2857 ap_sta_set_authorized(hapd
, sta
, 1);
2858 os_get_reltime(&sta
->connected_time
);
2859 accounting_sta_start(hapd
, sta
);
2862 /* Start IEEE 802.1X authentication process for new stations */
2863 ieee802_1x_new_station(hapd
, sta
);
2865 if (sta
->auth_alg
!= WLAN_AUTH_FT
&&
2866 !(sta
->flags
& (WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
)))
2867 wpa_auth_sm_event(sta
->wpa_sm
, WPA_REAUTH
);
2869 wpa_auth_sta_associated(hapd
->wpa_auth
, sta
->wpa_sm
);
2871 if (hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
) {
2872 if (eloop_cancel_timeout(ap_handle_timer
, hapd
, sta
) > 0) {
2873 wpa_printf(MSG_DEBUG
,
2874 "%s: %s: canceled wired ap_handle_timer timeout for "
2876 hapd
->conf
->iface
, __func__
,
2877 MAC2STR(sta
->addr
));
2879 } else if (!(hapd
->iface
->drv_flags
&
2880 WPA_DRIVER_FLAGS_INACTIVITY_TIMER
)) {
2881 wpa_printf(MSG_DEBUG
,
2882 "%s: %s: reschedule ap_handle_timer timeout for "
2883 MACSTR
" (%d seconds - ap_max_inactivity)",
2884 hapd
->conf
->iface
, __func__
, MAC2STR(sta
->addr
),
2885 hapd
->conf
->ap_max_inactivity
);
2886 eloop_cancel_timeout(ap_handle_timer
, hapd
, sta
);
2887 eloop_register_timeout(hapd
->conf
->ap_max_inactivity
, 0,
2888 ap_handle_timer
, hapd
, sta
);
2893 const char * hostapd_state_text(enum hostapd_iface_state s
)
2896 case HAPD_IFACE_UNINITIALIZED
:
2897 return "UNINITIALIZED";
2898 case HAPD_IFACE_DISABLED
:
2900 case HAPD_IFACE_COUNTRY_UPDATE
:
2901 return "COUNTRY_UPDATE";
2902 case HAPD_IFACE_ACS
:
2904 case HAPD_IFACE_HT_SCAN
:
2906 case HAPD_IFACE_DFS
:
2908 case HAPD_IFACE_ENABLED
:
2916 void hostapd_set_state(struct hostapd_iface
*iface
, enum hostapd_iface_state s
)
2918 wpa_printf(MSG_INFO
, "%s: interface state %s->%s",
2919 iface
->conf
? iface
->conf
->bss
[0]->iface
: "N/A",
2920 hostapd_state_text(iface
->state
), hostapd_state_text(s
));
2925 int hostapd_csa_in_progress(struct hostapd_iface
*iface
)
2929 for (i
= 0; i
< iface
->num_bss
; i
++)
2930 if (iface
->bss
[i
]->csa_in_progress
)
2938 static void free_beacon_data(struct beacon_data
*beacon
)
2940 os_free(beacon
->head
);
2941 beacon
->head
= NULL
;
2942 os_free(beacon
->tail
);
2943 beacon
->tail
= NULL
;
2944 os_free(beacon
->probe_resp
);
2945 beacon
->probe_resp
= NULL
;
2946 os_free(beacon
->beacon_ies
);
2947 beacon
->beacon_ies
= NULL
;
2948 os_free(beacon
->proberesp_ies
);
2949 beacon
->proberesp_ies
= NULL
;
2950 os_free(beacon
->assocresp_ies
);
2951 beacon
->assocresp_ies
= NULL
;
2955 static int hostapd_build_beacon_data(struct hostapd_data
*hapd
,
2956 struct beacon_data
*beacon
)
2958 struct wpabuf
*beacon_extra
, *proberesp_extra
, *assocresp_extra
;
2959 struct wpa_driver_ap_params params
;
2962 os_memset(beacon
, 0, sizeof(*beacon
));
2963 ret
= ieee802_11_build_ap_params(hapd
, ¶ms
);
2967 ret
= hostapd_build_ap_extra_ies(hapd
, &beacon_extra
,
2971 goto free_ap_params
;
2974 beacon
->head
= os_memdup(params
.head
, params
.head_len
);
2976 goto free_ap_extra_ies
;
2978 beacon
->head_len
= params
.head_len
;
2980 beacon
->tail
= os_memdup(params
.tail
, params
.tail_len
);
2984 beacon
->tail_len
= params
.tail_len
;
2986 if (params
.proberesp
!= NULL
) {
2987 beacon
->probe_resp
= os_memdup(params
.proberesp
,
2988 params
.proberesp_len
);
2989 if (!beacon
->probe_resp
)
2992 beacon
->probe_resp_len
= params
.proberesp_len
;
2995 /* copy the extra ies */
2997 beacon
->beacon_ies
= os_memdup(beacon_extra
->buf
,
2998 wpabuf_len(beacon_extra
));
2999 if (!beacon
->beacon_ies
)
3002 beacon
->beacon_ies_len
= wpabuf_len(beacon_extra
);
3005 if (proberesp_extra
) {
3006 beacon
->proberesp_ies
= os_memdup(proberesp_extra
->buf
,
3007 wpabuf_len(proberesp_extra
));
3008 if (!beacon
->proberesp_ies
)
3011 beacon
->proberesp_ies_len
= wpabuf_len(proberesp_extra
);
3014 if (assocresp_extra
) {
3015 beacon
->assocresp_ies
= os_memdup(assocresp_extra
->buf
,
3016 wpabuf_len(assocresp_extra
));
3017 if (!beacon
->assocresp_ies
)
3020 beacon
->assocresp_ies_len
= wpabuf_len(assocresp_extra
);
3025 /* if the function fails, the caller should not free beacon data */
3027 free_beacon_data(beacon
);
3030 hostapd_free_ap_extra_ies(hapd
, beacon_extra
, proberesp_extra
,
3033 ieee802_11_free_ap_params(¶ms
);
3039 * TODO: This flow currently supports only changing channel and width within
3040 * the same hw_mode. Any other changes to MAC parameters or provided settings
3041 * are not supported.
3043 static int hostapd_change_config_freq(struct hostapd_data
*hapd
,
3044 struct hostapd_config
*conf
,
3045 struct hostapd_freq_params
*params
,
3046 struct hostapd_freq_params
*old_params
)
3050 if (!params
->channel
) {
3051 /* check if the new channel is supported by hw */
3052 params
->channel
= hostapd_hw_get_channel(hapd
, params
->freq
);
3055 channel
= params
->channel
;
3059 /* if a pointer to old_params is provided we save previous state */
3061 hostapd_set_freq_params(old_params
, conf
->hw_mode
,
3062 hostapd_hw_get_freq(hapd
, conf
->channel
),
3063 conf
->channel
, conf
->ieee80211n
,
3065 conf
->secondary_channel
,
3066 conf
->vht_oper_chwidth
,
3067 conf
->vht_oper_centr_freq_seg0_idx
,
3068 conf
->vht_oper_centr_freq_seg1_idx
,
3072 switch (params
->bandwidth
) {
3076 conf
->vht_oper_chwidth
= VHT_CHANWIDTH_USE_HT
;
3079 if (params
->center_freq2
)
3080 conf
->vht_oper_chwidth
= VHT_CHANWIDTH_80P80MHZ
;
3082 conf
->vht_oper_chwidth
= VHT_CHANWIDTH_80MHZ
;
3085 conf
->vht_oper_chwidth
= VHT_CHANWIDTH_160MHZ
;
3091 conf
->channel
= channel
;
3092 conf
->ieee80211n
= params
->ht_enabled
;
3093 conf
->secondary_channel
= params
->sec_channel_offset
;
3094 ieee80211_freq_to_chan(params
->center_freq1
,
3095 &conf
->vht_oper_centr_freq_seg0_idx
);
3096 ieee80211_freq_to_chan(params
->center_freq2
,
3097 &conf
->vht_oper_centr_freq_seg1_idx
);
3099 /* TODO: maybe call here hostapd_config_check here? */
3105 static int hostapd_fill_csa_settings(struct hostapd_data
*hapd
,
3106 struct csa_settings
*settings
)
3108 struct hostapd_iface
*iface
= hapd
->iface
;
3109 struct hostapd_freq_params old_freq
;
3111 u8 chan
, vht_bandwidth
;
3113 os_memset(&old_freq
, 0, sizeof(old_freq
));
3114 if (!iface
|| !iface
->freq
|| hapd
->csa_in_progress
)
3117 switch (settings
->freq_params
.bandwidth
) {
3119 if (settings
->freq_params
.center_freq2
)
3120 vht_bandwidth
= VHT_CHANWIDTH_80P80MHZ
;
3122 vht_bandwidth
= VHT_CHANWIDTH_80MHZ
;
3125 vht_bandwidth
= VHT_CHANWIDTH_160MHZ
;
3128 vht_bandwidth
= VHT_CHANWIDTH_USE_HT
;
3132 if (ieee80211_freq_to_channel_ext(
3133 settings
->freq_params
.freq
,
3134 settings
->freq_params
.sec_channel_offset
,
3136 &hapd
->iface
->cs_oper_class
,
3137 &chan
) == NUM_HOSTAPD_MODES
) {
3138 wpa_printf(MSG_DEBUG
,
3139 "invalid frequency for channel switch (freq=%d, sec_channel_offset=%d, vht_enabled=%d)",
3140 settings
->freq_params
.freq
,
3141 settings
->freq_params
.sec_channel_offset
,
3142 settings
->freq_params
.vht_enabled
);
3146 settings
->freq_params
.channel
= chan
;
3148 ret
= hostapd_change_config_freq(iface
->bss
[0], iface
->conf
,
3149 &settings
->freq_params
,
3154 ret
= hostapd_build_beacon_data(hapd
, &settings
->beacon_after
);
3156 /* change back the configuration */
3157 hostapd_change_config_freq(iface
->bss
[0], iface
->conf
,
3163 /* set channel switch parameters for csa ie */
3164 hapd
->cs_freq_params
= settings
->freq_params
;
3165 hapd
->cs_count
= settings
->cs_count
;
3166 hapd
->cs_block_tx
= settings
->block_tx
;
3168 ret
= hostapd_build_beacon_data(hapd
, &settings
->beacon_csa
);
3170 free_beacon_data(&settings
->beacon_after
);
3174 settings
->counter_offset_beacon
[0] = hapd
->cs_c_off_beacon
;
3175 settings
->counter_offset_presp
[0] = hapd
->cs_c_off_proberesp
;
3176 settings
->counter_offset_beacon
[1] = hapd
->cs_c_off_ecsa_beacon
;
3177 settings
->counter_offset_presp
[1] = hapd
->cs_c_off_ecsa_proberesp
;
3183 void hostapd_cleanup_cs_params(struct hostapd_data
*hapd
)
3185 os_memset(&hapd
->cs_freq_params
, 0, sizeof(hapd
->cs_freq_params
));
3187 hapd
->cs_block_tx
= 0;
3188 hapd
->cs_c_off_beacon
= 0;
3189 hapd
->cs_c_off_proberesp
= 0;
3190 hapd
->csa_in_progress
= 0;
3191 hapd
->cs_c_off_ecsa_beacon
= 0;
3192 hapd
->cs_c_off_ecsa_proberesp
= 0;
3196 int hostapd_switch_channel(struct hostapd_data
*hapd
,
3197 struct csa_settings
*settings
)
3201 if (!(hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_AP_CSA
)) {
3202 wpa_printf(MSG_INFO
, "CSA is not supported");
3206 ret
= hostapd_fill_csa_settings(hapd
, settings
);
3210 ret
= hostapd_drv_switch_channel(hapd
, settings
);
3211 free_beacon_data(&settings
->beacon_csa
);
3212 free_beacon_data(&settings
->beacon_after
);
3215 /* if we failed, clean cs parameters */
3216 hostapd_cleanup_cs_params(hapd
);
3220 hapd
->csa_in_progress
= 1;
3226 hostapd_switch_channel_fallback(struct hostapd_iface
*iface
,
3227 const struct hostapd_freq_params
*freq_params
)
3229 int vht_seg0_idx
= 0, vht_seg1_idx
= 0, vht_bw
= VHT_CHANWIDTH_USE_HT
;
3232 wpa_printf(MSG_DEBUG
, "Restarting all CSA-related BSSes");
3234 if (freq_params
->center_freq1
)
3235 vht_seg0_idx
= 36 + (freq_params
->center_freq1
- 5180) / 5;
3236 if (freq_params
->center_freq2
)
3237 vht_seg1_idx
= 36 + (freq_params
->center_freq2
- 5180) / 5;
3239 switch (freq_params
->bandwidth
) {
3243 vht_bw
= VHT_CHANWIDTH_USE_HT
;
3246 if (freq_params
->center_freq2
)
3247 vht_bw
= VHT_CHANWIDTH_80P80MHZ
;
3249 vht_bw
= VHT_CHANWIDTH_80MHZ
;
3252 vht_bw
= VHT_CHANWIDTH_160MHZ
;
3255 wpa_printf(MSG_WARNING
, "Unknown CSA bandwidth: %d",
3256 freq_params
->bandwidth
);
3260 iface
->freq
= freq_params
->freq
;
3261 iface
->conf
->channel
= freq_params
->channel
;
3262 iface
->conf
->secondary_channel
= freq_params
->sec_channel_offset
;
3263 iface
->conf
->vht_oper_centr_freq_seg0_idx
= vht_seg0_idx
;
3264 iface
->conf
->vht_oper_centr_freq_seg1_idx
= vht_seg1_idx
;
3265 iface
->conf
->vht_oper_chwidth
= vht_bw
;
3266 iface
->conf
->ieee80211n
= freq_params
->ht_enabled
;
3267 iface
->conf
->ieee80211ac
= freq_params
->vht_enabled
;
3270 * cs_params must not be cleared earlier because the freq_params
3271 * argument may actually point to one of these.
3273 for (i
= 0; i
< iface
->num_bss
; i
++)
3274 hostapd_cleanup_cs_params(iface
->bss
[i
]);
3276 hostapd_disable_iface(iface
);
3277 hostapd_enable_iface(iface
);
3280 #endif /* NEED_AP_MLME */
3283 struct hostapd_data
* hostapd_get_iface(struct hapd_interfaces
*interfaces
,
3288 for (i
= 0; i
< interfaces
->count
; i
++) {
3289 struct hostapd_iface
*iface
= interfaces
->iface
[i
];
3291 for (j
= 0; j
< iface
->num_bss
; j
++) {
3292 struct hostapd_data
*hapd
= iface
->bss
[j
];
3294 if (os_strcmp(ifname
, hapd
->conf
->iface
) == 0)
3303 void hostapd_periodic_iface(struct hostapd_iface
*iface
)
3307 ap_list_timer(iface
);
3309 for (i
= 0; i
< iface
->num_bss
; i
++) {
3310 struct hostapd_data
*hapd
= iface
->bss
[i
];
3315 #ifndef CONFIG_NO_RADIUS
3316 hostapd_acl_expire(hapd
);
3317 #endif /* CONFIG_NO_RADIUS */