2 * hostapd / Initialization and configuration
3 * Copyright (c) 2002-2014, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "common/ieee802_11_defs.h"
14 #include "common/wpa_ctrl.h"
15 #include "common/hw_features_common.h"
16 #include "radius/radius_client.h"
17 #include "radius/radius_das.h"
18 #include "eap_server/tncs.h"
19 #include "eapol_auth/eapol_auth_sm.h"
20 #include "eapol_auth/eapol_auth_sm_i.h"
25 #include "accounting.h"
29 #include "ieee802_1x.h"
30 #include "ieee802_11_auth.h"
31 #include "vlan_init.h"
33 #include "wps_hostapd.h"
34 #include "hw_features.h"
35 #include "wpa_auth_glue.h"
36 #include "ap_drv_ops.h"
37 #include "ap_config.h"
38 #include "p2p_hostapd.h"
41 #include "ieee802_11.h"
44 #include "dhcp_snoop.h"
45 #include "ndisc_snoop.h"
46 #include "neighbor_db.h"
52 static int hostapd_flush_old_stations(struct hostapd_data
*hapd
, u16 reason
);
53 static int hostapd_setup_encryption(char *iface
, struct hostapd_data
*hapd
);
54 static int hostapd_broadcast_wep_clear(struct hostapd_data
*hapd
);
55 static int setup_interface2(struct hostapd_iface
*iface
);
56 static void channel_list_update_timeout(void *eloop_ctx
, void *timeout_ctx
);
59 int hostapd_for_each_interface(struct hapd_interfaces
*interfaces
,
60 int (*cb
)(struct hostapd_iface
*iface
,
61 void *ctx
), void *ctx
)
66 for (i
= 0; i
< interfaces
->count
; i
++) {
67 ret
= cb(interfaces
->iface
[i
], ctx
);
76 static void hostapd_reload_bss(struct hostapd_data
*hapd
)
78 struct hostapd_ssid
*ssid
;
83 #ifndef CONFIG_NO_RADIUS
84 radius_client_reconfig(hapd
->radius
, hapd
->conf
->radius
);
85 #endif /* CONFIG_NO_RADIUS */
87 ssid
= &hapd
->conf
->ssid
;
88 if (!ssid
->wpa_psk_set
&& ssid
->wpa_psk
&& !ssid
->wpa_psk
->next
&&
89 ssid
->wpa_passphrase_set
&& ssid
->wpa_passphrase
) {
91 * Force PSK to be derived again since SSID or passphrase may
94 hostapd_config_clear_wpa_psk(&hapd
->conf
->ssid
.wpa_psk
);
96 if (hostapd_setup_wpa_psk(hapd
->conf
)) {
97 wpa_printf(MSG_ERROR
, "Failed to re-configure WPA PSK "
98 "after reloading configuration");
101 if (hapd
->conf
->ieee802_1x
|| hapd
->conf
->wpa
)
102 hostapd_set_drv_ieee8021x(hapd
, hapd
->conf
->iface
, 1);
104 hostapd_set_drv_ieee8021x(hapd
, hapd
->conf
->iface
, 0);
106 if ((hapd
->conf
->wpa
|| hapd
->conf
->osen
) && hapd
->wpa_auth
== NULL
) {
107 hostapd_setup_wpa(hapd
);
109 wpa_init_keys(hapd
->wpa_auth
);
110 } else if (hapd
->conf
->wpa
) {
113 hostapd_reconfig_wpa(hapd
);
114 wpa_ie
= wpa_auth_get_wpa_ie(hapd
->wpa_auth
, &wpa_ie_len
);
115 if (hostapd_set_generic_elem(hapd
, wpa_ie
, wpa_ie_len
))
116 wpa_printf(MSG_ERROR
, "Failed to configure WPA IE for "
117 "the kernel driver.");
118 } else if (hapd
->wpa_auth
) {
119 wpa_deinit(hapd
->wpa_auth
);
120 hapd
->wpa_auth
= NULL
;
121 hostapd_set_privacy(hapd
, 0);
122 hostapd_setup_encryption(hapd
->conf
->iface
, hapd
);
123 hostapd_set_generic_elem(hapd
, (u8
*) "", 0);
126 ieee802_11_set_beacon(hapd
);
127 hostapd_update_wps(hapd
);
129 if (hapd
->conf
->ssid
.ssid_set
&&
130 hostapd_set_ssid(hapd
, hapd
->conf
->ssid
.ssid
,
131 hapd
->conf
->ssid
.ssid_len
)) {
132 wpa_printf(MSG_ERROR
, "Could not set SSID for kernel driver");
133 /* try to continue */
135 wpa_printf(MSG_DEBUG
, "Reconfigured interface %s", hapd
->conf
->iface
);
139 static void hostapd_clear_old(struct hostapd_iface
*iface
)
144 * Deauthenticate all stations since the new configuration may not
145 * allow them to use the BSS anymore.
147 for (j
= 0; j
< iface
->num_bss
; j
++) {
148 hostapd_flush_old_stations(iface
->bss
[j
],
149 WLAN_REASON_PREV_AUTH_NOT_VALID
);
150 hostapd_broadcast_wep_clear(iface
->bss
[j
]);
152 #ifndef CONFIG_NO_RADIUS
153 /* TODO: update dynamic data based on changed configuration
154 * items (e.g., open/close sockets, etc.) */
155 radius_client_flush(iface
->bss
[j
]->radius
, 0);
156 #endif /* CONFIG_NO_RADIUS */
161 int hostapd_reload_config(struct hostapd_iface
*iface
)
163 struct hostapd_data
*hapd
= iface
->bss
[0];
164 struct hostapd_config
*newconf
, *oldconf
;
167 if (iface
->config_fname
== NULL
) {
168 /* Only in-memory config in use - assume it has been updated */
169 hostapd_clear_old(iface
);
170 for (j
= 0; j
< iface
->num_bss
; j
++)
171 hostapd_reload_bss(iface
->bss
[j
]);
175 if (iface
->interfaces
== NULL
||
176 iface
->interfaces
->config_read_cb
== NULL
)
178 newconf
= iface
->interfaces
->config_read_cb(iface
->config_fname
);
182 hostapd_clear_old(iface
);
184 oldconf
= hapd
->iconf
;
185 iface
->conf
= newconf
;
187 for (j
= 0; j
< iface
->num_bss
; j
++) {
188 hapd
= iface
->bss
[j
];
189 hapd
->iconf
= newconf
;
190 hapd
->iconf
->channel
= oldconf
->channel
;
191 hapd
->iconf
->acs
= oldconf
->acs
;
192 hapd
->iconf
->secondary_channel
= oldconf
->secondary_channel
;
193 hapd
->iconf
->ieee80211n
= oldconf
->ieee80211n
;
194 hapd
->iconf
->ieee80211ac
= oldconf
->ieee80211ac
;
195 hapd
->iconf
->ht_capab
= oldconf
->ht_capab
;
196 hapd
->iconf
->vht_capab
= oldconf
->vht_capab
;
197 hapd
->iconf
->vht_oper_chwidth
= oldconf
->vht_oper_chwidth
;
198 hapd
->iconf
->vht_oper_centr_freq_seg0_idx
=
199 oldconf
->vht_oper_centr_freq_seg0_idx
;
200 hapd
->iconf
->vht_oper_centr_freq_seg1_idx
=
201 oldconf
->vht_oper_centr_freq_seg1_idx
;
202 hapd
->conf
= newconf
->bss
[j
];
203 hostapd_reload_bss(hapd
);
206 hostapd_config_free(oldconf
);
213 static void hostapd_broadcast_key_clear_iface(struct hostapd_data
*hapd
,
218 if (!ifname
|| !hapd
->drv_priv
)
220 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
221 if (hostapd_drv_set_key(ifname
, hapd
, WPA_ALG_NONE
, NULL
, i
,
222 0, NULL
, 0, NULL
, 0)) {
223 wpa_printf(MSG_DEBUG
, "Failed to clear default "
224 "encryption keys (ifname=%s keyidx=%d)",
228 #ifdef CONFIG_IEEE80211W
229 if (hapd
->conf
->ieee80211w
) {
230 for (i
= NUM_WEP_KEYS
; i
< NUM_WEP_KEYS
+ 2; i
++) {
231 if (hostapd_drv_set_key(ifname
, hapd
, WPA_ALG_NONE
,
234 wpa_printf(MSG_DEBUG
, "Failed to clear "
235 "default mgmt encryption keys "
236 "(ifname=%s keyidx=%d)", ifname
, i
);
240 #endif /* CONFIG_IEEE80211W */
244 static int hostapd_broadcast_wep_clear(struct hostapd_data
*hapd
)
246 hostapd_broadcast_key_clear_iface(hapd
, hapd
->conf
->iface
);
251 static int hostapd_broadcast_wep_set(struct hostapd_data
*hapd
)
254 struct hostapd_ssid
*ssid
= &hapd
->conf
->ssid
;
257 if (ssid
->wep
.default_len
&&
258 hostapd_drv_set_key(hapd
->conf
->iface
,
259 hapd
, WPA_ALG_WEP
, broadcast_ether_addr
, idx
,
260 1, NULL
, 0, ssid
->wep
.key
[idx
],
261 ssid
->wep
.len
[idx
])) {
262 wpa_printf(MSG_WARNING
, "Could not set WEP encryption.");
270 static void hostapd_free_hapd_data(struct hostapd_data
*hapd
)
272 os_free(hapd
->probereq_cb
);
273 hapd
->probereq_cb
= NULL
;
274 hapd
->num_probereq_cb
= 0;
277 wpabuf_free(hapd
->p2p_beacon_ie
);
278 hapd
->p2p_beacon_ie
= NULL
;
279 wpabuf_free(hapd
->p2p_probe_resp_ie
);
280 hapd
->p2p_probe_resp_ie
= NULL
;
281 #endif /* CONFIG_P2P */
283 if (!hapd
->started
) {
284 wpa_printf(MSG_ERROR
, "%s: Interface %s wasn't started",
285 __func__
, hapd
->conf
->iface
);
290 wpa_printf(MSG_DEBUG
, "%s(%s)", __func__
, hapd
->conf
->iface
);
291 iapp_deinit(hapd
->iapp
);
293 accounting_deinit(hapd
);
294 hostapd_deinit_wpa(hapd
);
296 hostapd_acl_deinit(hapd
);
297 #ifndef CONFIG_NO_RADIUS
298 radius_client_deinit(hapd
->radius
);
300 radius_das_deinit(hapd
->radius_das
);
301 hapd
->radius_das
= NULL
;
302 #endif /* CONFIG_NO_RADIUS */
304 hostapd_deinit_wps(hapd
);
306 authsrv_deinit(hapd
);
308 if (hapd
->interface_added
) {
309 hapd
->interface_added
= 0;
310 if (hostapd_if_remove(hapd
, WPA_IF_AP_BSS
, hapd
->conf
->iface
)) {
311 wpa_printf(MSG_WARNING
,
312 "Failed to remove BSS interface %s",
314 hapd
->interface_added
= 1;
317 * Since this was a dynamically added interface, the
318 * driver wrapper may have removed its internal instance
319 * and hapd->drv_priv is not valid anymore.
321 hapd
->drv_priv
= NULL
;
325 wpabuf_free(hapd
->time_adv
);
327 #ifdef CONFIG_INTERWORKING
328 gas_serv_deinit(hapd
);
329 #endif /* CONFIG_INTERWORKING */
331 bss_load_update_deinit(hapd
);
332 ndisc_snoop_deinit(hapd
);
333 dhcp_snoop_deinit(hapd
);
334 x_snoop_deinit(hapd
);
337 bin_clear_free(hapd
->tmp_eap_user
.identity
,
338 hapd
->tmp_eap_user
.identity_len
);
339 bin_clear_free(hapd
->tmp_eap_user
.password
,
340 hapd
->tmp_eap_user
.password_len
);
341 #endif /* CONFIG_SQLITE */
344 wpabuf_free(hapd
->mesh_pending_auth
);
345 hapd
->mesh_pending_auth
= NULL
;
346 #endif /* CONFIG_MESH */
348 hostapd_clean_rrm(hapd
);
349 fils_hlp_deinit(hapd
);
354 * hostapd_cleanup - Per-BSS cleanup (deinitialization)
355 * @hapd: Pointer to BSS data
357 * This function is used to free all per-BSS data structures and resources.
358 * Most of the modules that are initialized in hostapd_setup_bss() are
359 * deinitialized here.
361 static void hostapd_cleanup(struct hostapd_data
*hapd
)
363 wpa_printf(MSG_DEBUG
, "%s(hapd=%p (%s))", __func__
, hapd
,
365 if (hapd
->iface
->interfaces
&&
366 hapd
->iface
->interfaces
->ctrl_iface_deinit
) {
367 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, WPA_EVENT_TERMINATING
);
368 hapd
->iface
->interfaces
->ctrl_iface_deinit(hapd
);
370 hostapd_free_hapd_data(hapd
);
374 static void sta_track_deinit(struct hostapd_iface
*iface
)
376 struct hostapd_sta_info
*info
;
378 if (!iface
->num_sta_seen
)
381 while ((info
= dl_list_first(&iface
->sta_seen
, struct hostapd_sta_info
,
383 dl_list_del(&info
->list
);
384 iface
->num_sta_seen
--;
390 static void hostapd_cleanup_iface_partial(struct hostapd_iface
*iface
)
392 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
393 #ifdef CONFIG_IEEE80211N
395 hostapd_stop_setup_timers(iface
);
396 #endif /* NEED_AP_MLME */
397 #endif /* CONFIG_IEEE80211N */
398 if (iface
->current_mode
)
400 hostapd_free_hw_features(iface
->hw_features
, iface
->num_hw_features
);
401 iface
->hw_features
= NULL
;
402 iface
->current_mode
= NULL
;
403 os_free(iface
->current_rates
);
404 iface
->current_rates
= NULL
;
405 os_free(iface
->basic_rates
);
406 iface
->basic_rates
= NULL
;
407 ap_list_deinit(iface
);
408 sta_track_deinit(iface
);
413 * hostapd_cleanup_iface - Complete per-interface cleanup
414 * @iface: Pointer to interface data
416 * This function is called after per-BSS data structures are deinitialized
417 * with hostapd_cleanup().
419 static void hostapd_cleanup_iface(struct hostapd_iface
*iface
)
421 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
422 eloop_cancel_timeout(channel_list_update_timeout
, iface
, NULL
);
424 hostapd_cleanup_iface_partial(iface
);
425 hostapd_config_free(iface
->conf
);
428 os_free(iface
->config_fname
);
430 wpa_printf(MSG_DEBUG
, "%s: free iface=%p", __func__
, iface
);
435 static void hostapd_clear_wep(struct hostapd_data
*hapd
)
437 if (hapd
->drv_priv
&& !hapd
->iface
->driver_ap_teardown
) {
438 hostapd_set_privacy(hapd
, 0);
439 hostapd_broadcast_wep_clear(hapd
);
444 static int hostapd_setup_encryption(char *iface
, struct hostapd_data
*hapd
)
448 hostapd_broadcast_wep_set(hapd
);
450 if (hapd
->conf
->ssid
.wep
.default_len
) {
451 hostapd_set_privacy(hapd
, 1);
456 * When IEEE 802.1X is not enabled, the driver may need to know how to
457 * set authentication algorithms for static WEP.
459 hostapd_drv_set_authmode(hapd
, hapd
->conf
->auth_algs
);
461 for (i
= 0; i
< 4; i
++) {
462 if (hapd
->conf
->ssid
.wep
.key
[i
] &&
463 hostapd_drv_set_key(iface
, hapd
, WPA_ALG_WEP
, NULL
, i
,
464 i
== hapd
->conf
->ssid
.wep
.idx
, NULL
, 0,
465 hapd
->conf
->ssid
.wep
.key
[i
],
466 hapd
->conf
->ssid
.wep
.len
[i
])) {
467 wpa_printf(MSG_WARNING
, "Could not set WEP "
471 if (hapd
->conf
->ssid
.wep
.key
[i
] &&
472 i
== hapd
->conf
->ssid
.wep
.idx
)
473 hostapd_set_privacy(hapd
, 1);
480 static int hostapd_flush_old_stations(struct hostapd_data
*hapd
, u16 reason
)
485 if (hostapd_drv_none(hapd
) || hapd
->drv_priv
== NULL
)
488 if (!hapd
->iface
->driver_ap_teardown
) {
489 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
,
490 "Flushing old station entries");
492 if (hostapd_flush(hapd
)) {
493 wpa_msg(hapd
->msg_ctx
, MSG_WARNING
,
494 "Could not connect to kernel driver");
498 if (hapd
->conf
&& hapd
->conf
->broadcast_deauth
) {
499 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
,
500 "Deauthenticate all stations");
501 os_memset(addr
, 0xff, ETH_ALEN
);
502 hostapd_drv_sta_deauth(hapd
, addr
, reason
);
504 hostapd_free_stas(hapd
);
510 static void hostapd_bss_deinit_no_free(struct hostapd_data
*hapd
)
512 hostapd_free_stas(hapd
);
513 hostapd_flush_old_stations(hapd
, WLAN_REASON_DEAUTH_LEAVING
);
514 hostapd_clear_wep(hapd
);
519 * hostapd_validate_bssid_configuration - Validate BSSID configuration
520 * @iface: Pointer to interface data
521 * Returns: 0 on success, -1 on failure
523 * This function is used to validate that the configured BSSIDs are valid.
525 static int hostapd_validate_bssid_configuration(struct hostapd_iface
*iface
)
527 u8 mask
[ETH_ALEN
] = { 0 };
528 struct hostapd_data
*hapd
= iface
->bss
[0];
529 unsigned int i
= iface
->conf
->num_bss
, bits
= 0, j
;
532 if (hostapd_drv_none(hapd
))
535 if (iface
->conf
->use_driver_iface_addr
)
538 /* Generate BSSID mask that is large enough to cover the BSSIDs. */
540 /* Determine the bits necessary to cover the number of BSSIDs. */
541 for (i
--; i
; i
>>= 1)
544 /* Determine the bits necessary to any configured BSSIDs,
545 if they are higher than the number of BSSIDs. */
546 for (j
= 0; j
< iface
->conf
->num_bss
; j
++) {
547 if (is_zero_ether_addr(iface
->conf
->bss
[j
]->bssid
)) {
553 for (i
= 0; i
< ETH_ALEN
; i
++) {
555 iface
->conf
->bss
[j
]->bssid
[i
] ^
563 for (i
= 0; i
< ETH_ALEN
&& mask
[i
] == 0; i
++)
569 while (mask
[i
] != 0) {
579 wpa_printf(MSG_ERROR
, "Too many bits in the BSSID mask (%u)",
584 os_memset(mask
, 0xff, ETH_ALEN
);
586 for (i
= 5; i
> 5 - j
; i
--)
593 wpa_printf(MSG_DEBUG
, "BSS count %lu, BSSID mask " MACSTR
" (%d bits)",
594 (unsigned long) iface
->conf
->num_bss
, MAC2STR(mask
), bits
);
599 for (i
= 0; i
< ETH_ALEN
; i
++) {
600 if ((hapd
->own_addr
[i
] & mask
[i
]) != hapd
->own_addr
[i
]) {
601 wpa_printf(MSG_ERROR
, "Invalid BSSID mask " MACSTR
602 " for start address " MACSTR
".",
603 MAC2STR(mask
), MAC2STR(hapd
->own_addr
));
604 wpa_printf(MSG_ERROR
, "Start address must be the "
605 "first address in the block (i.e., addr "
606 "AND mask == addr).");
615 static int mac_in_conf(struct hostapd_config
*conf
, const void *a
)
619 for (i
= 0; i
< conf
->num_bss
; i
++) {
620 if (hostapd_mac_comp(conf
->bss
[i
]->bssid
, a
) == 0) {
629 #ifndef CONFIG_NO_RADIUS
631 static int hostapd_das_nas_mismatch(struct hostapd_data
*hapd
,
632 struct radius_das_attrs
*attr
)
634 if (attr
->nas_identifier
&&
635 (!hapd
->conf
->nas_identifier
||
636 os_strlen(hapd
->conf
->nas_identifier
) !=
637 attr
->nas_identifier_len
||
638 os_memcmp(hapd
->conf
->nas_identifier
, attr
->nas_identifier
,
639 attr
->nas_identifier_len
) != 0)) {
640 wpa_printf(MSG_DEBUG
, "RADIUS DAS: NAS-Identifier mismatch");
644 if (attr
->nas_ip_addr
&&
645 (hapd
->conf
->own_ip_addr
.af
!= AF_INET
||
646 os_memcmp(&hapd
->conf
->own_ip_addr
.u
.v4
, attr
->nas_ip_addr
, 4) !=
648 wpa_printf(MSG_DEBUG
, "RADIUS DAS: NAS-IP-Address mismatch");
653 if (attr
->nas_ipv6_addr
&&
654 (hapd
->conf
->own_ip_addr
.af
!= AF_INET6
||
655 os_memcmp(&hapd
->conf
->own_ip_addr
.u
.v6
, attr
->nas_ipv6_addr
, 16)
657 wpa_printf(MSG_DEBUG
, "RADIUS DAS: NAS-IPv6-Address mismatch");
660 #endif /* CONFIG_IPV6 */
666 static struct sta_info
* hostapd_das_find_sta(struct hostapd_data
*hapd
,
667 struct radius_das_attrs
*attr
,
670 struct sta_info
*selected
, *sta
;
677 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
)
678 sta
->radius_das_match
= 1;
680 if (attr
->sta_addr
) {
682 sta
= ap_get_sta(hapd
, attr
->sta_addr
);
684 wpa_printf(MSG_DEBUG
,
685 "RADIUS DAS: No Calling-Station-Id match");
690 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
692 sta
->radius_das_match
= 0;
694 wpa_printf(MSG_DEBUG
, "RADIUS DAS: Calling-Station-Id match");
697 if (attr
->acct_session_id
) {
699 if (attr
->acct_session_id_len
!= 16) {
700 wpa_printf(MSG_DEBUG
,
701 "RADIUS DAS: Acct-Session-Id cannot match");
706 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
707 if (!sta
->radius_das_match
)
709 os_snprintf(buf
, sizeof(buf
), "%016llX",
710 (unsigned long long) sta
->acct_session_id
);
711 if (os_memcmp(attr
->acct_session_id
, buf
, 16) != 0)
712 sta
->radius_das_match
= 0;
718 wpa_printf(MSG_DEBUG
,
719 "RADIUS DAS: No matches remaining after Acct-Session-Id check");
722 wpa_printf(MSG_DEBUG
, "RADIUS DAS: Acct-Session-Id match");
725 if (attr
->acct_multi_session_id
) {
727 if (attr
->acct_multi_session_id_len
!= 16) {
728 wpa_printf(MSG_DEBUG
,
729 "RADIUS DAS: Acct-Multi-Session-Id cannot match");
734 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
735 if (!sta
->radius_das_match
)
737 if (!sta
->eapol_sm
||
738 !sta
->eapol_sm
->acct_multi_session_id
) {
739 sta
->radius_das_match
= 0;
742 os_snprintf(buf
, sizeof(buf
), "%016llX",
744 sta
->eapol_sm
->acct_multi_session_id
);
745 if (os_memcmp(attr
->acct_multi_session_id
, buf
, 16) !=
747 sta
->radius_das_match
= 0;
753 wpa_printf(MSG_DEBUG
,
754 "RADIUS DAS: No matches remaining after Acct-Multi-Session-Id check");
757 wpa_printf(MSG_DEBUG
,
758 "RADIUS DAS: Acct-Multi-Session-Id match");
765 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
768 if (!sta
->radius_das_match
)
770 cui
= ieee802_1x_get_radius_cui(sta
->eapol_sm
);
771 if (!cui
|| wpabuf_len(cui
) != attr
->cui_len
||
772 os_memcmp(wpabuf_head(cui
), attr
->cui
,
774 sta
->radius_das_match
= 0;
780 wpa_printf(MSG_DEBUG
,
781 "RADIUS DAS: No matches remaining after Chargeable-User-Identity check");
784 wpa_printf(MSG_DEBUG
,
785 "RADIUS DAS: Chargeable-User-Identity match");
788 if (attr
->user_name
) {
792 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
796 if (!sta
->radius_das_match
)
798 identity
= ieee802_1x_get_identity(sta
->eapol_sm
,
801 identity_len
!= attr
->user_name_len
||
802 os_memcmp(identity
, attr
->user_name
, identity_len
)
804 sta
->radius_das_match
= 0;
810 wpa_printf(MSG_DEBUG
,
811 "RADIUS DAS: No matches remaining after User-Name check");
814 wpa_printf(MSG_DEBUG
,
815 "RADIUS DAS: User-Name match");
820 * In theory, we could match all current associations, but it
821 * seems safer to just reject requests that do not include any
822 * session identification attributes.
824 wpa_printf(MSG_DEBUG
,
825 "RADIUS DAS: No session identification attributes included");
830 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
831 if (sta
->radius_das_match
) {
844 static int hostapd_das_disconnect_pmksa(struct hostapd_data
*hapd
,
845 struct radius_das_attrs
*attr
)
849 return wpa_auth_radius_das_disconnect_pmksa(hapd
->wpa_auth
, attr
);
853 static enum radius_das_res
854 hostapd_das_disconnect(void *ctx
, struct radius_das_attrs
*attr
)
856 struct hostapd_data
*hapd
= ctx
;
857 struct sta_info
*sta
;
860 if (hostapd_das_nas_mismatch(hapd
, attr
))
861 return RADIUS_DAS_NAS_MISMATCH
;
863 sta
= hostapd_das_find_sta(hapd
, attr
, &multi
);
866 wpa_printf(MSG_DEBUG
,
867 "RADIUS DAS: Multiple sessions match - not supported");
868 return RADIUS_DAS_MULTI_SESSION_MATCH
;
870 if (hostapd_das_disconnect_pmksa(hapd
, attr
) == 0) {
871 wpa_printf(MSG_DEBUG
,
872 "RADIUS DAS: PMKSA cache entry matched");
873 return RADIUS_DAS_SUCCESS
;
875 wpa_printf(MSG_DEBUG
, "RADIUS DAS: No matching session found");
876 return RADIUS_DAS_SESSION_NOT_FOUND
;
879 wpa_printf(MSG_DEBUG
, "RADIUS DAS: Found a matching session " MACSTR
880 " - disconnecting", MAC2STR(sta
->addr
));
881 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
883 hostapd_drv_sta_deauth(hapd
, sta
->addr
,
884 WLAN_REASON_PREV_AUTH_NOT_VALID
);
885 ap_sta_deauthenticate(hapd
, sta
, WLAN_REASON_PREV_AUTH_NOT_VALID
);
887 return RADIUS_DAS_SUCCESS
;
890 #endif /* CONFIG_NO_RADIUS */
894 * hostapd_setup_bss - Per-BSS setup (initialization)
895 * @hapd: Pointer to BSS data
896 * @first: Whether this BSS is the first BSS of an interface; -1 = not first,
897 * but interface may exist
899 * This function is used to initialize all per-BSS data structures and
900 * resources. This gets called in a loop for each BSS when an interface is
901 * initialized. Most of the modules that are initialized here will be
902 * deinitialized in hostapd_cleanup().
904 static int hostapd_setup_bss(struct hostapd_data
*hapd
, int first
)
906 struct hostapd_bss_config
*conf
= hapd
->conf
;
907 u8 ssid
[SSID_MAX_LEN
+ 1];
908 int ssid_len
, set_ssid
;
909 char force_ifname
[IFNAMSIZ
];
910 u8 if_addr
[ETH_ALEN
];
911 int flush_old_stations
= 1;
913 wpa_printf(MSG_DEBUG
, "%s(hapd=%p (%s), first=%d)",
914 __func__
, hapd
, conf
->iface
, first
);
916 #ifdef EAP_SERVER_TNC
917 if (conf
->tnc
&& tncs_global_init() < 0) {
918 wpa_printf(MSG_ERROR
, "Failed to initialize TNCS");
921 #endif /* EAP_SERVER_TNC */
924 wpa_printf(MSG_ERROR
, "%s: Interface %s was already started",
925 __func__
, conf
->iface
);
930 if (!first
|| first
== -1) {
931 u8
*addr
= hapd
->own_addr
;
933 if (!is_zero_ether_addr(conf
->bssid
)) {
934 /* Allocate the configured BSSID. */
935 os_memcpy(hapd
->own_addr
, conf
->bssid
, ETH_ALEN
);
937 if (hostapd_mac_comp(hapd
->own_addr
,
938 hapd
->iface
->bss
[0]->own_addr
) ==
940 wpa_printf(MSG_ERROR
, "BSS '%s' may not have "
941 "BSSID set to the MAC address of "
942 "the radio", conf
->iface
);
945 } else if (hapd
->iconf
->use_driver_iface_addr
) {
948 /* Allocate the next available BSSID. */
950 inc_byte_array(hapd
->own_addr
, ETH_ALEN
);
951 } while (mac_in_conf(hapd
->iconf
, hapd
->own_addr
));
954 hapd
->interface_added
= 1;
955 if (hostapd_if_add(hapd
->iface
->bss
[0], WPA_IF_AP_BSS
,
956 conf
->iface
, addr
, hapd
,
957 &hapd
->drv_priv
, force_ifname
, if_addr
,
958 conf
->bridge
[0] ? conf
->bridge
: NULL
,
960 wpa_printf(MSG_ERROR
, "Failed to add BSS (BSSID="
961 MACSTR
")", MAC2STR(hapd
->own_addr
));
962 hapd
->interface_added
= 0;
967 os_memcpy(hapd
->own_addr
, if_addr
, ETH_ALEN
);
970 if (conf
->wmm_enabled
< 0)
971 conf
->wmm_enabled
= hapd
->iconf
->ieee80211n
;
973 #ifdef CONFIG_IEEE80211R_AP
974 if (is_zero_ether_addr(conf
->r1_key_holder
))
975 os_memcpy(conf
->r1_key_holder
, hapd
->own_addr
, ETH_ALEN
);
976 #endif /* CONFIG_IEEE80211R_AP */
979 if ((hapd
->conf
->mesh
& MESH_ENABLED
) && hapd
->iface
->mconf
== NULL
)
980 flush_old_stations
= 0;
981 #endif /* CONFIG_MESH */
983 if (flush_old_stations
)
984 hostapd_flush_old_stations(hapd
,
985 WLAN_REASON_PREV_AUTH_NOT_VALID
);
986 hostapd_set_privacy(hapd
, 0);
988 hostapd_broadcast_wep_clear(hapd
);
989 if (hostapd_setup_encryption(conf
->iface
, hapd
))
993 * Fetch the SSID from the system and use it or,
994 * if one was specified in the config file, verify they
997 ssid_len
= hostapd_get_ssid(hapd
, ssid
, sizeof(ssid
));
999 wpa_printf(MSG_ERROR
, "Could not read SSID from system");
1002 if (conf
->ssid
.ssid_set
) {
1004 * If SSID is specified in the config file and it differs
1005 * from what is being used then force installation of the
1008 set_ssid
= (conf
->ssid
.ssid_len
!= (size_t) ssid_len
||
1009 os_memcmp(conf
->ssid
.ssid
, ssid
, ssid_len
) != 0);
1012 * No SSID in the config file; just use the one we got
1016 conf
->ssid
.ssid_len
= ssid_len
;
1017 os_memcpy(conf
->ssid
.ssid
, ssid
, conf
->ssid
.ssid_len
);
1020 if (!hostapd_drv_none(hapd
)) {
1021 wpa_printf(MSG_ERROR
, "Using interface %s with hwaddr " MACSTR
1023 conf
->iface
, MAC2STR(hapd
->own_addr
),
1024 wpa_ssid_txt(conf
->ssid
.ssid
, conf
->ssid
.ssid_len
));
1027 if (hostapd_setup_wpa_psk(conf
)) {
1028 wpa_printf(MSG_ERROR
, "WPA-PSK setup failed.");
1032 /* Set SSID for the kernel driver (to be used in beacon and probe
1033 * response frames) */
1034 if (set_ssid
&& hostapd_set_ssid(hapd
, conf
->ssid
.ssid
,
1035 conf
->ssid
.ssid_len
)) {
1036 wpa_printf(MSG_ERROR
, "Could not set SSID for kernel driver");
1040 if (wpa_debug_level
<= MSG_MSGDUMP
)
1041 conf
->radius
->msg_dumps
= 1;
1042 #ifndef CONFIG_NO_RADIUS
1043 hapd
->radius
= radius_client_init(hapd
, conf
->radius
);
1044 if (hapd
->radius
== NULL
) {
1045 wpa_printf(MSG_ERROR
, "RADIUS client initialization failed.");
1049 if (conf
->radius_das_port
) {
1050 struct radius_das_conf das_conf
;
1051 os_memset(&das_conf
, 0, sizeof(das_conf
));
1052 das_conf
.port
= conf
->radius_das_port
;
1053 das_conf
.shared_secret
= conf
->radius_das_shared_secret
;
1054 das_conf
.shared_secret_len
=
1055 conf
->radius_das_shared_secret_len
;
1056 das_conf
.client_addr
= &conf
->radius_das_client_addr
;
1057 das_conf
.time_window
= conf
->radius_das_time_window
;
1058 das_conf
.require_event_timestamp
=
1059 conf
->radius_das_require_event_timestamp
;
1060 das_conf
.require_message_authenticator
=
1061 conf
->radius_das_require_message_authenticator
;
1062 das_conf
.ctx
= hapd
;
1063 das_conf
.disconnect
= hostapd_das_disconnect
;
1064 hapd
->radius_das
= radius_das_init(&das_conf
);
1065 if (hapd
->radius_das
== NULL
) {
1066 wpa_printf(MSG_ERROR
, "RADIUS DAS initialization "
1071 #endif /* CONFIG_NO_RADIUS */
1073 if (hostapd_acl_init(hapd
)) {
1074 wpa_printf(MSG_ERROR
, "ACL initialization failed.");
1077 if (hostapd_init_wps(hapd
, conf
))
1080 if (authsrv_init(hapd
) < 0)
1083 if (ieee802_1x_init(hapd
)) {
1084 wpa_printf(MSG_ERROR
, "IEEE 802.1X initialization failed.");
1088 if ((conf
->wpa
|| conf
->osen
) && hostapd_setup_wpa(hapd
))
1091 if (accounting_init(hapd
)) {
1092 wpa_printf(MSG_ERROR
, "Accounting initialization failed.");
1096 if (conf
->ieee802_11f
&&
1097 (hapd
->iapp
= iapp_init(hapd
, conf
->iapp_iface
)) == NULL
) {
1098 wpa_printf(MSG_ERROR
, "IEEE 802.11F (IAPP) initialization "
1103 #ifdef CONFIG_INTERWORKING
1104 if (gas_serv_init(hapd
)) {
1105 wpa_printf(MSG_ERROR
, "GAS server initialization failed");
1109 if (conf
->qos_map_set_len
&&
1110 hostapd_drv_set_qos_map(hapd
, conf
->qos_map_set
,
1111 conf
->qos_map_set_len
)) {
1112 wpa_printf(MSG_ERROR
, "Failed to initialize QoS Map");
1115 #endif /* CONFIG_INTERWORKING */
1117 if (conf
->bss_load_update_period
&& bss_load_update_init(hapd
)) {
1118 wpa_printf(MSG_ERROR
, "BSS Load initialization failed");
1122 if (conf
->proxy_arp
) {
1123 if (x_snoop_init(hapd
)) {
1124 wpa_printf(MSG_ERROR
,
1125 "Generic snooping infrastructure initialization failed");
1129 if (dhcp_snoop_init(hapd
)) {
1130 wpa_printf(MSG_ERROR
,
1131 "DHCP snooping initialization failed");
1135 if (ndisc_snoop_init(hapd
)) {
1136 wpa_printf(MSG_ERROR
,
1137 "Neighbor Discovery snooping initialization failed");
1142 if (!hostapd_drv_none(hapd
) && vlan_init(hapd
)) {
1143 wpa_printf(MSG_ERROR
, "VLAN initialization failed.");
1147 if (!conf
->start_disabled
&& ieee802_11_set_beacon(hapd
) < 0)
1150 if (hapd
->wpa_auth
&& wpa_init_keys(hapd
->wpa_auth
) < 0)
1153 if (hapd
->driver
&& hapd
->driver
->set_operstate
)
1154 hapd
->driver
->set_operstate(hapd
->drv_priv
, 1);
1160 static void hostapd_tx_queue_params(struct hostapd_iface
*iface
)
1162 struct hostapd_data
*hapd
= iface
->bss
[0];
1164 struct hostapd_tx_queue_params
*p
;
1167 if ((hapd
->conf
->mesh
& MESH_ENABLED
) && iface
->mconf
== NULL
)
1169 #endif /* CONFIG_MESH */
1171 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
1172 p
= &iface
->conf
->tx_queue
[i
];
1174 if (hostapd_set_tx_queue_params(hapd
, i
, p
->aifs
, p
->cwmin
,
1175 p
->cwmax
, p
->burst
)) {
1176 wpa_printf(MSG_DEBUG
, "Failed to set TX queue "
1177 "parameters for queue %d.", i
);
1178 /* Continue anyway */
1184 static int hostapd_set_acl_list(struct hostapd_data
*hapd
,
1185 struct mac_acl_entry
*mac_acl
,
1186 int n_entries
, u8 accept_acl
)
1188 struct hostapd_acl_params
*acl_params
;
1191 acl_params
= os_zalloc(sizeof(*acl_params
) +
1192 (n_entries
* sizeof(acl_params
->mac_acl
[0])));
1196 for (i
= 0; i
< n_entries
; i
++)
1197 os_memcpy(acl_params
->mac_acl
[i
].addr
, mac_acl
[i
].addr
,
1200 acl_params
->acl_policy
= accept_acl
;
1201 acl_params
->num_mac_acl
= n_entries
;
1203 err
= hostapd_drv_set_acl(hapd
, acl_params
);
1205 os_free(acl_params
);
1211 static void hostapd_set_acl(struct hostapd_data
*hapd
)
1213 struct hostapd_config
*conf
= hapd
->iconf
;
1217 if (hapd
->iface
->drv_max_acl_mac_addrs
== 0)
1220 if (conf
->bss
[0]->macaddr_acl
== DENY_UNLESS_ACCEPTED
) {
1222 err
= hostapd_set_acl_list(hapd
, conf
->bss
[0]->accept_mac
,
1223 conf
->bss
[0]->num_accept_mac
,
1226 wpa_printf(MSG_DEBUG
, "Failed to set accept acl");
1229 } else if (conf
->bss
[0]->macaddr_acl
== ACCEPT_UNLESS_DENIED
) {
1231 err
= hostapd_set_acl_list(hapd
, conf
->bss
[0]->deny_mac
,
1232 conf
->bss
[0]->num_deny_mac
,
1235 wpa_printf(MSG_DEBUG
, "Failed to set deny acl");
1242 static int start_ctrl_iface_bss(struct hostapd_data
*hapd
)
1244 if (!hapd
->iface
->interfaces
||
1245 !hapd
->iface
->interfaces
->ctrl_iface_init
)
1248 if (hapd
->iface
->interfaces
->ctrl_iface_init(hapd
)) {
1249 wpa_printf(MSG_ERROR
,
1250 "Failed to setup control interface for %s",
1259 static int start_ctrl_iface(struct hostapd_iface
*iface
)
1263 if (!iface
->interfaces
|| !iface
->interfaces
->ctrl_iface_init
)
1266 for (i
= 0; i
< iface
->num_bss
; i
++) {
1267 struct hostapd_data
*hapd
= iface
->bss
[i
];
1268 if (iface
->interfaces
->ctrl_iface_init(hapd
)) {
1269 wpa_printf(MSG_ERROR
,
1270 "Failed to setup control interface for %s",
1280 static void channel_list_update_timeout(void *eloop_ctx
, void *timeout_ctx
)
1282 struct hostapd_iface
*iface
= eloop_ctx
;
1284 if (!iface
->wait_channel_update
) {
1285 wpa_printf(MSG_INFO
, "Channel list update timeout, but interface was not waiting for it");
1290 * It is possible that the existing channel list is acceptable, so try
1293 wpa_printf(MSG_DEBUG
, "Channel list update timeout - try to continue anyway");
1294 setup_interface2(iface
);
1298 void hostapd_channel_list_updated(struct hostapd_iface
*iface
, int initiator
)
1300 if (!iface
->wait_channel_update
|| initiator
!= REGDOM_SET_BY_USER
)
1303 wpa_printf(MSG_DEBUG
, "Channel list updated - continue setup");
1304 eloop_cancel_timeout(channel_list_update_timeout
, iface
, NULL
);
1305 setup_interface2(iface
);
1309 static int setup_interface(struct hostapd_iface
*iface
)
1311 struct hostapd_data
*hapd
= iface
->bss
[0];
1315 * It is possible that setup_interface() is called after the interface
1316 * was disabled etc., in which case driver_ap_teardown is possibly set
1317 * to 1. Clear it here so any other key/station deletion, which is not
1318 * part of a teardown flow, would also call the relevant driver
1321 iface
->driver_ap_teardown
= 0;
1323 if (!iface
->phy
[0]) {
1324 const char *phy
= hostapd_drv_get_radio_name(hapd
);
1326 wpa_printf(MSG_DEBUG
, "phy: %s", phy
);
1327 os_strlcpy(iface
->phy
, phy
, sizeof(iface
->phy
));
1332 * Make sure that all BSSes get configured with a pointer to the same
1335 for (i
= 1; i
< iface
->num_bss
; i
++) {
1336 iface
->bss
[i
]->driver
= hapd
->driver
;
1337 iface
->bss
[i
]->drv_priv
= hapd
->drv_priv
;
1340 if (hostapd_validate_bssid_configuration(iface
))
1344 * Initialize control interfaces early to allow external monitoring of
1345 * channel setup operations that may take considerable amount of time
1346 * especially for DFS cases.
1348 if (start_ctrl_iface(iface
))
1351 if (hapd
->iconf
->country
[0] && hapd
->iconf
->country
[1]) {
1352 char country
[4], previous_country
[4];
1354 hostapd_set_state(iface
, HAPD_IFACE_COUNTRY_UPDATE
);
1355 if (hostapd_get_country(hapd
, previous_country
) < 0)
1356 previous_country
[0] = '\0';
1358 os_memcpy(country
, hapd
->iconf
->country
, 3);
1360 if (hostapd_set_country(hapd
, country
) < 0) {
1361 wpa_printf(MSG_ERROR
, "Failed to set country code");
1365 wpa_printf(MSG_DEBUG
, "Previous country code %s, new country code %s",
1366 previous_country
, country
);
1368 if (os_strncmp(previous_country
, country
, 2) != 0) {
1369 wpa_printf(MSG_DEBUG
, "Continue interface setup after channel list update");
1370 iface
->wait_channel_update
= 1;
1371 eloop_register_timeout(5, 0,
1372 channel_list_update_timeout
,
1378 return setup_interface2(iface
);
1382 static int setup_interface2(struct hostapd_iface
*iface
)
1384 iface
->wait_channel_update
= 0;
1386 if (hostapd_get_hw_features(iface
)) {
1387 /* Not all drivers support this yet, so continue without hw
1390 int ret
= hostapd_select_hw_mode(iface
);
1392 wpa_printf(MSG_ERROR
, "Could not select hw_mode and "
1393 "channel. (%d)", ret
);
1397 wpa_printf(MSG_DEBUG
, "Interface initialization will be completed in a callback (ACS)");
1400 ret
= hostapd_check_ht_capab(iface
);
1404 wpa_printf(MSG_DEBUG
, "Interface initialization will "
1405 "be completed in a callback");
1409 if (iface
->conf
->ieee80211h
)
1410 wpa_printf(MSG_DEBUG
, "DFS support is enabled");
1412 return hostapd_setup_interface_complete(iface
, 0);
1415 hostapd_set_state(iface
, HAPD_IFACE_DISABLED
);
1416 wpa_msg(iface
->bss
[0]->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
1417 if (iface
->interfaces
&& iface
->interfaces
->terminate_on_error
)
1425 static const u8
* fst_hostapd_get_bssid_cb(void *ctx
)
1427 struct hostapd_data
*hapd
= ctx
;
1429 return hapd
->own_addr
;
1433 static void fst_hostapd_get_channel_info_cb(void *ctx
,
1434 enum hostapd_hw_mode
*hw_mode
,
1437 struct hostapd_data
*hapd
= ctx
;
1439 *hw_mode
= ieee80211_freq_to_chan(hapd
->iface
->freq
, channel
);
1443 static void fst_hostapd_set_ies_cb(void *ctx
, const struct wpabuf
*fst_ies
)
1445 struct hostapd_data
*hapd
= ctx
;
1447 if (hapd
->iface
->fst_ies
!= fst_ies
) {
1448 hapd
->iface
->fst_ies
= fst_ies
;
1449 if (ieee802_11_set_beacon(hapd
))
1450 wpa_printf(MSG_WARNING
, "FST: Cannot set beacon");
1455 static int fst_hostapd_send_action_cb(void *ctx
, const u8
*da
,
1458 struct hostapd_data
*hapd
= ctx
;
1460 return hostapd_drv_send_action(hapd
, hapd
->iface
->freq
, 0, da
,
1461 wpabuf_head(buf
), wpabuf_len(buf
));
1465 static const struct wpabuf
* fst_hostapd_get_mb_ie_cb(void *ctx
, const u8
*addr
)
1467 struct hostapd_data
*hapd
= ctx
;
1468 struct sta_info
*sta
= ap_get_sta(hapd
, addr
);
1470 return sta
? sta
->mb_ies
: NULL
;
1474 static void fst_hostapd_update_mb_ie_cb(void *ctx
, const u8
*addr
,
1475 const u8
*buf
, size_t size
)
1477 struct hostapd_data
*hapd
= ctx
;
1478 struct sta_info
*sta
= ap_get_sta(hapd
, addr
);
1481 struct mb_ies_info info
;
1483 if (!mb_ies_info_by_ies(&info
, buf
, size
)) {
1484 wpabuf_free(sta
->mb_ies
);
1485 sta
->mb_ies
= mb_ies_by_info(&info
);
1491 static const u8
* fst_hostapd_get_sta(struct fst_get_peer_ctx
**get_ctx
,
1494 struct sta_info
*s
= (struct sta_info
*) *get_ctx
;
1497 for (; s
&& !s
->mb_ies
; s
= s
->next
)
1502 *get_ctx
= (struct fst_get_peer_ctx
*) s
->next
;
1512 static const u8
* fst_hostapd_get_peer_first(void *ctx
,
1513 struct fst_get_peer_ctx
**get_ctx
,
1516 struct hostapd_data
*hapd
= ctx
;
1518 *get_ctx
= (struct fst_get_peer_ctx
*) hapd
->sta_list
;
1520 return fst_hostapd_get_sta(get_ctx
, mb_only
);
1524 static const u8
* fst_hostapd_get_peer_next(void *ctx
,
1525 struct fst_get_peer_ctx
**get_ctx
,
1528 return fst_hostapd_get_sta(get_ctx
, mb_only
);
1532 void fst_hostapd_fill_iface_obj(struct hostapd_data
*hapd
,
1533 struct fst_wpa_obj
*iface_obj
)
1535 iface_obj
->ctx
= hapd
;
1536 iface_obj
->get_bssid
= fst_hostapd_get_bssid_cb
;
1537 iface_obj
->get_channel_info
= fst_hostapd_get_channel_info_cb
;
1538 iface_obj
->set_ies
= fst_hostapd_set_ies_cb
;
1539 iface_obj
->send_action
= fst_hostapd_send_action_cb
;
1540 iface_obj
->get_mb_ie
= fst_hostapd_get_mb_ie_cb
;
1541 iface_obj
->update_mb_ie
= fst_hostapd_update_mb_ie_cb
;
1542 iface_obj
->get_peer_first
= fst_hostapd_get_peer_first
;
1543 iface_obj
->get_peer_next
= fst_hostapd_get_peer_next
;
1546 #endif /* CONFIG_FST */
1550 static enum nr_chan_width
hostapd_get_nr_chan_width(struct hostapd_data
*hapd
,
1554 return NR_CHAN_WIDTH_20
;
1555 if (!hapd
->iconf
->secondary_channel
)
1556 return NR_CHAN_WIDTH_20
;
1557 if (!vht
|| hapd
->iconf
->vht_oper_chwidth
== VHT_CHANWIDTH_USE_HT
)
1558 return NR_CHAN_WIDTH_40
;
1559 if (hapd
->iconf
->vht_oper_chwidth
== VHT_CHANWIDTH_80MHZ
)
1560 return NR_CHAN_WIDTH_80
;
1561 if (hapd
->iconf
->vht_oper_chwidth
== VHT_CHANWIDTH_160MHZ
)
1562 return NR_CHAN_WIDTH_160
;
1563 if (hapd
->iconf
->vht_oper_chwidth
== VHT_CHANWIDTH_80P80MHZ
)
1564 return NR_CHAN_WIDTH_80P80
;
1565 return NR_CHAN_WIDTH_20
;
1567 #endif /* NEED_AP_MLME */
1570 static void hostapd_set_own_neighbor_report(struct hostapd_data
*hapd
)
1573 u16 capab
= hostapd_own_capab_info(hapd
);
1574 int ht
= hapd
->iconf
->ieee80211n
&& !hapd
->conf
->disable_11n
;
1575 int vht
= hapd
->iconf
->ieee80211ac
&& !hapd
->conf
->disable_11ac
;
1576 struct wpa_ssid_value ssid
;
1577 u8 channel
, op_class
;
1578 u8 center_freq1_idx
= 0, center_freq2_idx
= 0;
1579 enum nr_chan_width width
;
1583 if (!(hapd
->conf
->radio_measurements
[0] &
1584 WLAN_RRM_CAPS_NEIGHBOR_REPORT
))
1587 bssid_info
= 3; /* AP is reachable */
1588 bssid_info
|= NEI_REP_BSSID_INFO_SECURITY
; /* "same as the AP" */
1589 bssid_info
|= NEI_REP_BSSID_INFO_KEY_SCOPE
; /* "same as the AP" */
1591 if (capab
& WLAN_CAPABILITY_SPECTRUM_MGMT
)
1592 bssid_info
|= NEI_REP_BSSID_INFO_SPECTRUM_MGMT
;
1594 bssid_info
|= NEI_REP_BSSID_INFO_RM
; /* RRM is supported */
1596 if (hapd
->conf
->wmm_enabled
) {
1597 bssid_info
|= NEI_REP_BSSID_INFO_QOS
;
1599 if (hapd
->conf
->wmm_uapsd
&&
1600 (hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_AP_UAPSD
))
1601 bssid_info
|= NEI_REP_BSSID_INFO_APSD
;
1605 bssid_info
|= NEI_REP_BSSID_INFO_HT
|
1606 NEI_REP_BSSID_INFO_DELAYED_BA
;
1608 /* VHT bit added in IEEE P802.11-REVmc/D4.3 */
1610 bssid_info
|= NEI_REP_BSSID_INFO_VHT
;
1613 /* TODO: Set NEI_REP_BSSID_INFO_MOBILITY_DOMAIN if MDE is set */
1615 if (ieee80211_freq_to_channel_ext(hapd
->iface
->freq
,
1616 hapd
->iconf
->secondary_channel
,
1617 hapd
->iconf
->vht_oper_chwidth
,
1618 &op_class
, &channel
) ==
1621 width
= hostapd_get_nr_chan_width(hapd
, ht
, vht
);
1623 center_freq1_idx
= hapd
->iconf
->vht_oper_centr_freq_seg0_idx
;
1624 if (width
== NR_CHAN_WIDTH_80P80
)
1626 hapd
->iconf
->vht_oper_centr_freq_seg1_idx
;
1628 ieee80211_freq_to_chan(hapd
->iface
->freq
+
1629 10 * hapd
->iconf
->secondary_channel
,
1633 ssid
.ssid_len
= hapd
->conf
->ssid
.ssid_len
;
1634 os_memcpy(ssid
.ssid
, hapd
->conf
->ssid
.ssid
, ssid
.ssid_len
);
1637 * Neighbor Report element size = BSSID + BSSID info + op_class + chan +
1638 * phy type + wide bandwidth channel subelement.
1640 nr
= wpabuf_alloc(ETH_ALEN
+ 4 + 1 + 1 + 1 + 5);
1644 wpabuf_put_data(nr
, hapd
->own_addr
, ETH_ALEN
);
1645 wpabuf_put_le32(nr
, bssid_info
);
1646 wpabuf_put_u8(nr
, op_class
);
1647 wpabuf_put_u8(nr
, channel
);
1648 wpabuf_put_u8(nr
, ieee80211_get_phy_type(hapd
->iface
->freq
, ht
, vht
));
1651 * Wide Bandwidth Channel subelement may be needed to allow the
1652 * receiving STA to send packets to the AP. See IEEE P802.11-REVmc/D5.0
1655 wpabuf_put_u8(nr
, WNM_NEIGHBOR_WIDE_BW_CHAN
);
1656 wpabuf_put_u8(nr
, 3);
1657 wpabuf_put_u8(nr
, width
);
1658 wpabuf_put_u8(nr
, center_freq1_idx
);
1659 wpabuf_put_u8(nr
, center_freq2_idx
);
1661 hostapd_neighbor_set(hapd
, hapd
->own_addr
, &ssid
, nr
, hapd
->iconf
->lci
,
1662 hapd
->iconf
->civic
, hapd
->iconf
->stationary_ap
);
1665 #endif /* NEED_AP_MLME */
1669 static int hostapd_setup_interface_complete_sync(struct hostapd_iface
*iface
,
1672 struct hostapd_data
*hapd
= iface
->bss
[0];
1675 int delay_apply_cfg
= 0;
1676 int res_dfs_offload
= 0;
1681 wpa_printf(MSG_DEBUG
, "Completing interface initialization");
1682 if (iface
->conf
->channel
) {
1685 #endif /* NEED_AP_MLME */
1687 iface
->freq
= hostapd_hw_get_freq(hapd
, iface
->conf
->channel
);
1688 wpa_printf(MSG_DEBUG
, "Mode: %s Channel: %d "
1689 "Frequency: %d MHz",
1690 hostapd_hw_mode_txt(iface
->conf
->hw_mode
),
1691 iface
->conf
->channel
, iface
->freq
);
1694 /* Handle DFS only if it is not offloaded to the driver */
1695 if (!(iface
->drv_flags
& WPA_DRIVER_FLAGS_DFS_OFFLOAD
)) {
1697 res
= hostapd_handle_dfs(iface
);
1704 /* If DFS is offloaded to the driver */
1705 res_dfs_offload
= hostapd_handle_dfs_offload(iface
);
1706 if (res_dfs_offload
<= 0) {
1707 if (res_dfs_offload
< 0)
1710 wpa_printf(MSG_DEBUG
,
1711 "Proceed with AP/channel setup");
1713 * If this is a DFS channel, move to completing
1716 if (res_dfs_offload
== 1)
1718 /* Otherwise fall through. */
1721 #endif /* NEED_AP_MLME */
1724 if (iface
->mconf
!= NULL
) {
1725 wpa_printf(MSG_DEBUG
,
1726 "%s: Mesh configuration will be applied while joining the mesh network",
1727 iface
->bss
[0]->conf
->iface
);
1728 delay_apply_cfg
= 1;
1730 #endif /* CONFIG_MESH */
1732 if (!delay_apply_cfg
&&
1733 hostapd_set_freq(hapd
, hapd
->iconf
->hw_mode
, iface
->freq
,
1734 hapd
->iconf
->channel
,
1735 hapd
->iconf
->ieee80211n
,
1736 hapd
->iconf
->ieee80211ac
,
1737 hapd
->iconf
->secondary_channel
,
1738 hapd
->iconf
->vht_oper_chwidth
,
1739 hapd
->iconf
->vht_oper_centr_freq_seg0_idx
,
1740 hapd
->iconf
->vht_oper_centr_freq_seg1_idx
)) {
1741 wpa_printf(MSG_ERROR
, "Could not set channel for "
1747 if (iface
->current_mode
) {
1748 if (hostapd_prepare_rates(iface
, iface
->current_mode
)) {
1749 wpa_printf(MSG_ERROR
, "Failed to prepare rates "
1751 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE80211
,
1752 HOSTAPD_LEVEL_WARNING
,
1753 "Failed to prepare rates table.");
1758 if (hapd
->iconf
->rts_threshold
> -1 &&
1759 hostapd_set_rts(hapd
, hapd
->iconf
->rts_threshold
)) {
1760 wpa_printf(MSG_ERROR
, "Could not set RTS threshold for "
1765 if (hapd
->iconf
->fragm_threshold
> -1 &&
1766 hostapd_set_frag(hapd
, hapd
->iconf
->fragm_threshold
)) {
1767 wpa_printf(MSG_ERROR
, "Could not set fragmentation threshold "
1768 "for kernel driver");
1772 prev_addr
= hapd
->own_addr
;
1774 for (j
= 0; j
< iface
->num_bss
; j
++) {
1775 hapd
= iface
->bss
[j
];
1777 os_memcpy(hapd
->own_addr
, prev_addr
, ETH_ALEN
);
1778 if (hostapd_setup_bss(hapd
, j
== 0)) {
1780 hapd
= iface
->bss
[j
];
1781 hostapd_bss_deinit_no_free(hapd
);
1782 hostapd_free_hapd_data(hapd
);
1786 if (is_zero_ether_addr(hapd
->conf
->bssid
))
1787 prev_addr
= hapd
->own_addr
;
1789 hapd
= iface
->bss
[0];
1791 hostapd_tx_queue_params(iface
);
1793 ap_list_init(iface
);
1795 hostapd_set_acl(hapd
);
1797 if (hostapd_driver_commit(hapd
) < 0) {
1798 wpa_printf(MSG_ERROR
, "%s: Failed to commit driver "
1799 "configuration", __func__
);
1804 * WPS UPnP module can be initialized only when the "upnp_iface" is up.
1805 * If "interface" and "upnp_iface" are the same (e.g., non-bridge
1806 * mode), the interface is up only after driver_commit, so initialize
1807 * WPS after driver_commit.
1809 for (j
= 0; j
< iface
->num_bss
; j
++) {
1810 if (hostapd_init_wps_complete(iface
->bss
[j
]))
1814 if ((iface
->drv_flags
& WPA_DRIVER_FLAGS_DFS_OFFLOAD
) &&
1817 * If freq is DFS, and DFS is offloaded to the driver, then wait
1818 * for CAC to complete.
1820 wpa_printf(MSG_DEBUG
, "%s: Wait for CAC to complete", __func__
);
1821 return res_dfs_offload
;
1826 #endif /* NEED_AP_MLME */
1829 if (hapd
->iconf
->fst_cfg
.group_id
[0]) {
1830 struct fst_wpa_obj iface_obj
;
1832 fst_hostapd_fill_iface_obj(hapd
, &iface_obj
);
1833 iface
->fst
= fst_attach(hapd
->conf
->iface
, hapd
->own_addr
,
1834 &iface_obj
, &hapd
->iconf
->fst_cfg
);
1836 wpa_printf(MSG_ERROR
, "Could not attach to FST %s",
1837 hapd
->iconf
->fst_cfg
.group_id
);
1841 #endif /* CONFIG_FST */
1843 hostapd_set_state(iface
, HAPD_IFACE_ENABLED
);
1844 wpa_msg(iface
->bss
[0]->msg_ctx
, MSG_INFO
, AP_EVENT_ENABLED
);
1845 if (hapd
->setup_complete_cb
)
1846 hapd
->setup_complete_cb(hapd
->setup_complete_cb_ctx
);
1848 wpa_printf(MSG_DEBUG
, "%s: Setup of interface done.",
1849 iface
->bss
[0]->conf
->iface
);
1850 if (iface
->interfaces
&& iface
->interfaces
->terminate_on_error
> 0)
1851 iface
->interfaces
->terminate_on_error
--;
1853 for (j
= 0; j
< iface
->num_bss
; j
++)
1854 hostapd_set_own_neighbor_report(iface
->bss
[j
]);
1859 wpa_printf(MSG_ERROR
, "Interface initialization failed");
1860 hostapd_set_state(iface
, HAPD_IFACE_DISABLED
);
1861 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
1864 fst_detach(iface
->fst
);
1867 #endif /* CONFIG_FST */
1868 if (iface
->interfaces
&& iface
->interfaces
->terminate_on_error
)
1875 * hostapd_setup_interface_complete - Complete interface setup
1877 * This function is called when previous steps in the interface setup has been
1878 * completed. This can also start operations, e.g., DFS, that will require
1879 * additional processing before interface is ready to be enabled. Such
1880 * operations will call this function from eloop callbacks when finished.
1882 int hostapd_setup_interface_complete(struct hostapd_iface
*iface
, int err
)
1884 struct hapd_interfaces
*interfaces
= iface
->interfaces
;
1885 struct hostapd_data
*hapd
= iface
->bss
[0];
1887 int not_ready_in_sync_ifaces
= 0;
1889 if (!iface
->need_to_start_in_sync
)
1890 return hostapd_setup_interface_complete_sync(iface
, err
);
1893 wpa_printf(MSG_ERROR
, "Interface initialization failed");
1894 hostapd_set_state(iface
, HAPD_IFACE_DISABLED
);
1895 iface
->need_to_start_in_sync
= 0;
1896 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
1897 if (interfaces
&& interfaces
->terminate_on_error
)
1902 if (iface
->ready_to_start_in_sync
) {
1903 /* Already in ready and waiting. should never happpen */
1907 for (i
= 0; i
< interfaces
->count
; i
++) {
1908 if (interfaces
->iface
[i
]->need_to_start_in_sync
&&
1909 !interfaces
->iface
[i
]->ready_to_start_in_sync
)
1910 not_ready_in_sync_ifaces
++;
1914 * Check if this is the last interface, if yes then start all the other
1915 * waiting interfaces. If not, add this interface to the waiting list.
1917 if (not_ready_in_sync_ifaces
> 1 && iface
->state
== HAPD_IFACE_DFS
) {
1919 * If this interface went through CAC, do not synchronize, just
1920 * start immediately.
1922 iface
->need_to_start_in_sync
= 0;
1923 wpa_printf(MSG_INFO
,
1924 "%s: Finished CAC - bypass sync and start interface",
1925 iface
->bss
[0]->conf
->iface
);
1926 return hostapd_setup_interface_complete_sync(iface
, err
);
1929 if (not_ready_in_sync_ifaces
> 1) {
1930 /* need to wait as there are other interfaces still coming up */
1931 iface
->ready_to_start_in_sync
= 1;
1932 wpa_printf(MSG_INFO
,
1933 "%s: Interface waiting to sync with other interfaces",
1934 iface
->bss
[0]->conf
->iface
);
1938 wpa_printf(MSG_INFO
,
1939 "%s: Last interface to sync - starting all interfaces",
1940 iface
->bss
[0]->conf
->iface
);
1941 iface
->need_to_start_in_sync
= 0;
1942 hostapd_setup_interface_complete_sync(iface
, err
);
1943 for (i
= 0; i
< interfaces
->count
; i
++) {
1944 if (interfaces
->iface
[i
]->need_to_start_in_sync
&&
1945 interfaces
->iface
[i
]->ready_to_start_in_sync
) {
1946 hostapd_setup_interface_complete_sync(
1947 interfaces
->iface
[i
], 0);
1948 /* Only once the interfaces are sync started */
1949 interfaces
->iface
[i
]->need_to_start_in_sync
= 0;
1958 * hostapd_setup_interface - Setup of an interface
1959 * @iface: Pointer to interface data.
1960 * Returns: 0 on success, -1 on failure
1962 * Initializes the driver interface, validates the configuration,
1963 * and sets driver parameters based on the configuration.
1964 * Flushes old stations, sets the channel, encryption,
1965 * beacons, and WDS links based on the configuration.
1967 * If interface setup requires more time, e.g., to perform HT co-ex scans, ACS,
1968 * or DFS operations, this function returns 0 before such operations have been
1969 * completed. The pending operations are registered into eloop and will be
1970 * completed from eloop callbacks. Those callbacks end up calling
1971 * hostapd_setup_interface_complete() once setup has been completed.
1973 int hostapd_setup_interface(struct hostapd_iface
*iface
)
1977 ret
= setup_interface(iface
);
1979 wpa_printf(MSG_ERROR
, "%s: Unable to setup interface.",
1980 iface
->bss
[0]->conf
->iface
);
1989 * hostapd_alloc_bss_data - Allocate and initialize per-BSS data
1990 * @hapd_iface: Pointer to interface data
1991 * @conf: Pointer to per-interface configuration
1992 * @bss: Pointer to per-BSS configuration for this BSS
1993 * Returns: Pointer to allocated BSS data
1995 * This function is used to allocate per-BSS data structure. This data will be
1996 * freed after hostapd_cleanup() is called for it during interface
1999 struct hostapd_data
*
2000 hostapd_alloc_bss_data(struct hostapd_iface
*hapd_iface
,
2001 struct hostapd_config
*conf
,
2002 struct hostapd_bss_config
*bss
)
2004 struct hostapd_data
*hapd
;
2006 hapd
= os_zalloc(sizeof(*hapd
));
2010 hapd
->new_assoc_sta_cb
= hostapd_new_assoc_sta
;
2013 hapd
->iface
= hapd_iface
;
2015 hapd
->driver
= conf
->driver
;
2016 hapd
->ctrl_sock
= -1;
2017 dl_list_init(&hapd
->ctrl_dst
);
2018 dl_list_init(&hapd
->nr_db
);
2019 hapd
->dhcp_sock
= -1;
2020 #ifdef CONFIG_IEEE80211R_AP
2021 dl_list_init(&hapd
->l2_queue
);
2022 dl_list_init(&hapd
->l2_oui_queue
);
2023 #endif /* CONFIG_IEEE80211R_AP */
2029 static void hostapd_bss_deinit(struct hostapd_data
*hapd
)
2033 wpa_printf(MSG_DEBUG
, "%s: deinit bss %s", __func__
,
2035 hostapd_bss_deinit_no_free(hapd
);
2036 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
2037 hostapd_cleanup(hapd
);
2041 void hostapd_interface_deinit(struct hostapd_iface
*iface
)
2045 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
2049 hostapd_set_state(iface
, HAPD_IFACE_DISABLED
);
2051 #ifdef CONFIG_IEEE80211N
2053 hostapd_stop_setup_timers(iface
);
2054 eloop_cancel_timeout(ap_ht2040_timeout
, iface
, NULL
);
2055 #endif /* NEED_AP_MLME */
2056 #endif /* CONFIG_IEEE80211N */
2057 eloop_cancel_timeout(channel_list_update_timeout
, iface
, NULL
);
2058 iface
->wait_channel_update
= 0;
2062 fst_detach(iface
->fst
);
2065 #endif /* CONFIG_FST */
2067 for (j
= iface
->num_bss
- 1; j
>= 0; j
--) {
2070 hostapd_bss_deinit(iface
->bss
[j
]);
2075 void hostapd_interface_free(struct hostapd_iface
*iface
)
2078 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
2079 for (j
= 0; j
< iface
->num_bss
; j
++) {
2082 wpa_printf(MSG_DEBUG
, "%s: free hapd %p",
2083 __func__
, iface
->bss
[j
]);
2084 os_free(iface
->bss
[j
]);
2086 hostapd_cleanup_iface(iface
);
2090 struct hostapd_iface
* hostapd_alloc_iface(void)
2092 struct hostapd_iface
*hapd_iface
;
2094 hapd_iface
= os_zalloc(sizeof(*hapd_iface
));
2098 dl_list_init(&hapd_iface
->sta_seen
);
2105 * hostapd_init - Allocate and initialize per-interface data
2106 * @config_file: Path to the configuration file
2107 * Returns: Pointer to the allocated interface data or %NULL on failure
2109 * This function is used to allocate main data structures for per-interface
2110 * data. The allocated data buffer will be freed by calling
2111 * hostapd_cleanup_iface().
2113 struct hostapd_iface
* hostapd_init(struct hapd_interfaces
*interfaces
,
2114 const char *config_file
)
2116 struct hostapd_iface
*hapd_iface
= NULL
;
2117 struct hostapd_config
*conf
= NULL
;
2118 struct hostapd_data
*hapd
;
2121 hapd_iface
= hostapd_alloc_iface();
2122 if (hapd_iface
== NULL
)
2125 hapd_iface
->config_fname
= os_strdup(config_file
);
2126 if (hapd_iface
->config_fname
== NULL
)
2129 conf
= interfaces
->config_read_cb(hapd_iface
->config_fname
);
2132 hapd_iface
->conf
= conf
;
2134 hapd_iface
->num_bss
= conf
->num_bss
;
2135 hapd_iface
->bss
= os_calloc(conf
->num_bss
,
2136 sizeof(struct hostapd_data
*));
2137 if (hapd_iface
->bss
== NULL
)
2140 for (i
= 0; i
< conf
->num_bss
; i
++) {
2141 hapd
= hapd_iface
->bss
[i
] =
2142 hostapd_alloc_bss_data(hapd_iface
, conf
,
2146 hapd
->msg_ctx
= hapd
;
2152 wpa_printf(MSG_ERROR
, "Failed to set up interface with %s",
2155 hostapd_config_free(conf
);
2157 os_free(hapd_iface
->config_fname
);
2158 os_free(hapd_iface
->bss
);
2159 wpa_printf(MSG_DEBUG
, "%s: free iface %p",
2160 __func__
, hapd_iface
);
2161 os_free(hapd_iface
);
2167 static int ifname_in_use(struct hapd_interfaces
*interfaces
, const char *ifname
)
2171 for (i
= 0; i
< interfaces
->count
; i
++) {
2172 struct hostapd_iface
*iface
= interfaces
->iface
[i
];
2173 for (j
= 0; j
< iface
->num_bss
; j
++) {
2174 struct hostapd_data
*hapd
= iface
->bss
[j
];
2175 if (os_strcmp(ifname
, hapd
->conf
->iface
) == 0)
2185 * hostapd_interface_init_bss - Read configuration file and init BSS data
2187 * This function is used to parse configuration file for a BSS. This BSS is
2188 * added to an existing interface sharing the same radio (if any) or a new
2189 * interface is created if this is the first interface on a radio. This
2190 * allocate memory for the BSS. No actual driver operations are started.
2192 * This is similar to hostapd_interface_init(), but for a case where the
2193 * configuration is used to add a single BSS instead of all BSSes for a radio.
2195 struct hostapd_iface
*
2196 hostapd_interface_init_bss(struct hapd_interfaces
*interfaces
, const char *phy
,
2197 const char *config_fname
, int debug
)
2199 struct hostapd_iface
*new_iface
= NULL
, *iface
= NULL
;
2200 struct hostapd_data
*hapd
;
2207 for (i
= 0; i
< interfaces
->count
; i
++) {
2208 if (os_strcmp(interfaces
->iface
[i
]->phy
, phy
) == 0) {
2209 iface
= interfaces
->iface
[i
];
2214 wpa_printf(MSG_INFO
, "Configuration file: %s (phy %s)%s",
2215 config_fname
, phy
, iface
? "" : " --> new PHY");
2217 struct hostapd_config
*conf
;
2218 struct hostapd_bss_config
**tmp_conf
;
2219 struct hostapd_data
**tmp_bss
;
2220 struct hostapd_bss_config
*bss
;
2223 /* Add new BSS to existing iface */
2224 conf
= interfaces
->config_read_cb(config_fname
);
2227 if (conf
->num_bss
> 1) {
2228 wpa_printf(MSG_ERROR
, "Multiple BSSes specified in BSS-config");
2229 hostapd_config_free(conf
);
2233 ifname
= conf
->bss
[0]->iface
;
2234 if (ifname
[0] != '\0' && ifname_in_use(interfaces
, ifname
)) {
2235 wpa_printf(MSG_ERROR
,
2236 "Interface name %s already in use", ifname
);
2237 hostapd_config_free(conf
);
2241 tmp_conf
= os_realloc_array(
2242 iface
->conf
->bss
, iface
->conf
->num_bss
+ 1,
2243 sizeof(struct hostapd_bss_config
*));
2244 tmp_bss
= os_realloc_array(iface
->bss
, iface
->num_bss
+ 1,
2245 sizeof(struct hostapd_data
*));
2247 iface
->bss
= tmp_bss
;
2249 iface
->conf
->bss
= tmp_conf
;
2250 iface
->conf
->last_bss
= tmp_conf
[0];
2252 if (tmp_bss
== NULL
|| tmp_conf
== NULL
) {
2253 hostapd_config_free(conf
);
2256 bss
= iface
->conf
->bss
[iface
->conf
->num_bss
] = conf
->bss
[0];
2257 iface
->conf
->num_bss
++;
2259 hapd
= hostapd_alloc_bss_data(iface
, iface
->conf
, bss
);
2261 iface
->conf
->num_bss
--;
2262 hostapd_config_free(conf
);
2265 iface
->conf
->last_bss
= bss
;
2266 iface
->bss
[iface
->num_bss
] = hapd
;
2267 hapd
->msg_ctx
= hapd
;
2269 bss_idx
= iface
->num_bss
++;
2271 conf
->bss
[0] = NULL
;
2272 hostapd_config_free(conf
);
2274 /* Add a new iface with the first BSS */
2275 new_iface
= iface
= hostapd_init(interfaces
, config_fname
);
2278 os_strlcpy(iface
->phy
, phy
, sizeof(iface
->phy
));
2279 iface
->interfaces
= interfaces
;
2283 for (k
= 0; k
< debug
; k
++) {
2284 if (iface
->bss
[bss_idx
]->conf
->logger_stdout_level
> 0)
2285 iface
->bss
[bss_idx
]->conf
->logger_stdout_level
--;
2288 if (iface
->conf
->bss
[bss_idx
]->iface
[0] == '\0' &&
2289 !hostapd_drv_none(iface
->bss
[bss_idx
])) {
2290 wpa_printf(MSG_ERROR
, "Interface name not specified in %s",
2293 hostapd_interface_deinit_free(new_iface
);
2301 void hostapd_interface_deinit_free(struct hostapd_iface
*iface
)
2303 const struct wpa_driver_ops
*driver
;
2306 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
2309 wpa_printf(MSG_DEBUG
, "%s: num_bss=%u conf->num_bss=%u",
2310 __func__
, (unsigned int) iface
->num_bss
,
2311 (unsigned int) iface
->conf
->num_bss
);
2312 driver
= iface
->bss
[0]->driver
;
2313 drv_priv
= iface
->bss
[0]->drv_priv
;
2314 hostapd_interface_deinit(iface
);
2315 wpa_printf(MSG_DEBUG
, "%s: driver=%p drv_priv=%p -> hapd_deinit",
2316 __func__
, driver
, drv_priv
);
2317 if (driver
&& driver
->hapd_deinit
&& drv_priv
) {
2318 driver
->hapd_deinit(drv_priv
);
2319 iface
->bss
[0]->drv_priv
= NULL
;
2321 hostapd_interface_free(iface
);
2325 static void hostapd_deinit_driver(const struct wpa_driver_ops
*driver
,
2327 struct hostapd_iface
*hapd_iface
)
2331 wpa_printf(MSG_DEBUG
, "%s: driver=%p drv_priv=%p -> hapd_deinit",
2332 __func__
, driver
, drv_priv
);
2333 if (driver
&& driver
->hapd_deinit
&& drv_priv
) {
2334 driver
->hapd_deinit(drv_priv
);
2335 for (j
= 0; j
< hapd_iface
->num_bss
; j
++) {
2336 wpa_printf(MSG_DEBUG
, "%s:bss[%d]->drv_priv=%p",
2338 hapd_iface
->bss
[j
]->drv_priv
);
2339 if (hapd_iface
->bss
[j
]->drv_priv
== drv_priv
)
2340 hapd_iface
->bss
[j
]->drv_priv
= NULL
;
2346 int hostapd_enable_iface(struct hostapd_iface
*hapd_iface
)
2350 if (hapd_iface
->bss
[0]->drv_priv
!= NULL
) {
2351 wpa_printf(MSG_ERROR
, "Interface %s already enabled",
2352 hapd_iface
->conf
->bss
[0]->iface
);
2356 wpa_printf(MSG_DEBUG
, "Enable interface %s",
2357 hapd_iface
->conf
->bss
[0]->iface
);
2359 for (j
= 0; j
< hapd_iface
->num_bss
; j
++)
2360 hostapd_set_security_params(hapd_iface
->conf
->bss
[j
], 1);
2361 if (hostapd_config_check(hapd_iface
->conf
, 1) < 0) {
2362 wpa_printf(MSG_INFO
, "Invalid configuration - cannot enable");
2366 if (hapd_iface
->interfaces
== NULL
||
2367 hapd_iface
->interfaces
->driver_init
== NULL
||
2368 hapd_iface
->interfaces
->driver_init(hapd_iface
))
2371 if (hostapd_setup_interface(hapd_iface
)) {
2372 hostapd_deinit_driver(hapd_iface
->bss
[0]->driver
,
2373 hapd_iface
->bss
[0]->drv_priv
,
2382 int hostapd_reload_iface(struct hostapd_iface
*hapd_iface
)
2386 wpa_printf(MSG_DEBUG
, "Reload interface %s",
2387 hapd_iface
->conf
->bss
[0]->iface
);
2388 for (j
= 0; j
< hapd_iface
->num_bss
; j
++)
2389 hostapd_set_security_params(hapd_iface
->conf
->bss
[j
], 1);
2390 if (hostapd_config_check(hapd_iface
->conf
, 1) < 0) {
2391 wpa_printf(MSG_ERROR
, "Updated configuration is invalid");
2394 hostapd_clear_old(hapd_iface
);
2395 for (j
= 0; j
< hapd_iface
->num_bss
; j
++)
2396 hostapd_reload_bss(hapd_iface
->bss
[j
]);
2402 int hostapd_disable_iface(struct hostapd_iface
*hapd_iface
)
2405 const struct wpa_driver_ops
*driver
;
2408 if (hapd_iface
== NULL
)
2411 if (hapd_iface
->bss
[0]->drv_priv
== NULL
) {
2412 wpa_printf(MSG_INFO
, "Interface %s already disabled",
2413 hapd_iface
->conf
->bss
[0]->iface
);
2417 wpa_msg(hapd_iface
->bss
[0]->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
2418 driver
= hapd_iface
->bss
[0]->driver
;
2419 drv_priv
= hapd_iface
->bss
[0]->drv_priv
;
2421 hapd_iface
->driver_ap_teardown
=
2422 !!(hapd_iface
->drv_flags
&
2423 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT
);
2425 /* same as hostapd_interface_deinit without deinitializing ctrl-iface */
2426 for (j
= 0; j
< hapd_iface
->num_bss
; j
++) {
2427 struct hostapd_data
*hapd
= hapd_iface
->bss
[j
];
2428 hostapd_bss_deinit_no_free(hapd
);
2429 hostapd_free_hapd_data(hapd
);
2432 hostapd_deinit_driver(driver
, drv_priv
, hapd_iface
);
2434 /* From hostapd_cleanup_iface: These were initialized in
2435 * hostapd_setup_interface and hostapd_setup_interface_complete
2437 hostapd_cleanup_iface_partial(hapd_iface
);
2439 wpa_printf(MSG_DEBUG
, "Interface %s disabled",
2440 hapd_iface
->bss
[0]->conf
->iface
);
2441 hostapd_set_state(hapd_iface
, HAPD_IFACE_DISABLED
);
2446 static struct hostapd_iface
*
2447 hostapd_iface_alloc(struct hapd_interfaces
*interfaces
)
2449 struct hostapd_iface
**iface
, *hapd_iface
;
2451 iface
= os_realloc_array(interfaces
->iface
, interfaces
->count
+ 1,
2452 sizeof(struct hostapd_iface
*));
2455 interfaces
->iface
= iface
;
2456 hapd_iface
= interfaces
->iface
[interfaces
->count
] =
2457 hostapd_alloc_iface();
2458 if (hapd_iface
== NULL
) {
2459 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory for "
2460 "the interface", __func__
);
2463 interfaces
->count
++;
2464 hapd_iface
->interfaces
= interfaces
;
2470 static struct hostapd_config
*
2471 hostapd_config_alloc(struct hapd_interfaces
*interfaces
, const char *ifname
,
2472 const char *ctrl_iface
, const char *driver
)
2474 struct hostapd_bss_config
*bss
;
2475 struct hostapd_config
*conf
;
2477 /* Allocates memory for bss and conf */
2478 conf
= hostapd_config_defaults();
2480 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory for "
2481 "configuration", __func__
);
2488 for (j
= 0; wpa_drivers
[j
]; j
++) {
2489 if (os_strcmp(driver
, wpa_drivers
[j
]->name
) == 0) {
2490 conf
->driver
= wpa_drivers
[j
];
2495 wpa_printf(MSG_ERROR
,
2496 "Invalid/unknown driver '%s' - registering the default driver",
2500 conf
->driver
= wpa_drivers
[0];
2501 if (conf
->driver
== NULL
) {
2502 wpa_printf(MSG_ERROR
, "No driver wrappers registered!");
2503 hostapd_config_free(conf
);
2508 bss
= conf
->last_bss
= conf
->bss
[0];
2510 os_strlcpy(bss
->iface
, ifname
, sizeof(bss
->iface
));
2511 bss
->ctrl_interface
= os_strdup(ctrl_iface
);
2512 if (bss
->ctrl_interface
== NULL
) {
2513 hostapd_config_free(conf
);
2517 /* Reading configuration file skipped, will be done in SET!
2518 * From reading the configuration till the end has to be done in
2525 static int hostapd_data_alloc(struct hostapd_iface
*hapd_iface
,
2526 struct hostapd_config
*conf
)
2529 struct hostapd_data
*hapd
;
2531 hapd_iface
->bss
= os_calloc(conf
->num_bss
,
2532 sizeof(struct hostapd_data
*));
2533 if (hapd_iface
->bss
== NULL
)
2536 for (i
= 0; i
< conf
->num_bss
; i
++) {
2537 hapd
= hapd_iface
->bss
[i
] =
2538 hostapd_alloc_bss_data(hapd_iface
, conf
, conf
->bss
[i
]);
2542 os_free(hapd_iface
->bss
[i
]);
2543 hapd_iface
->bss
[i
] = NULL
;
2545 os_free(hapd_iface
->bss
);
2546 hapd_iface
->bss
= NULL
;
2549 hapd
->msg_ctx
= hapd
;
2552 hapd_iface
->conf
= conf
;
2553 hapd_iface
->num_bss
= conf
->num_bss
;
2559 int hostapd_add_iface(struct hapd_interfaces
*interfaces
, char *buf
)
2561 struct hostapd_config
*conf
= NULL
;
2562 struct hostapd_iface
*hapd_iface
= NULL
, *new_iface
= NULL
;
2563 struct hostapd_data
*hapd
;
2566 const char *conf_file
= NULL
, *phy_name
= NULL
;
2568 if (os_strncmp(buf
, "bss_config=", 11) == 0) {
2570 phy_name
= buf
+ 11;
2571 pos
= os_strchr(phy_name
, ':');
2576 if (!os_strlen(conf_file
))
2579 hapd_iface
= hostapd_interface_init_bss(interfaces
, phy_name
,
2583 for (j
= 0; j
< interfaces
->count
; j
++) {
2584 if (interfaces
->iface
[j
] == hapd_iface
)
2587 if (j
== interfaces
->count
) {
2588 struct hostapd_iface
**tmp
;
2589 tmp
= os_realloc_array(interfaces
->iface
,
2590 interfaces
->count
+ 1,
2591 sizeof(struct hostapd_iface
*));
2593 hostapd_interface_deinit_free(hapd_iface
);
2596 interfaces
->iface
= tmp
;
2597 interfaces
->iface
[interfaces
->count
++] = hapd_iface
;
2598 new_iface
= hapd_iface
;
2602 if (interfaces
->driver_init(hapd_iface
))
2605 if (hostapd_setup_interface(hapd_iface
)) {
2606 hostapd_deinit_driver(
2607 hapd_iface
->bss
[0]->driver
,
2608 hapd_iface
->bss
[0]->drv_priv
,
2613 /* Assign new BSS with bss[0]'s driver info */
2614 hapd
= hapd_iface
->bss
[hapd_iface
->num_bss
- 1];
2615 hapd
->driver
= hapd_iface
->bss
[0]->driver
;
2616 hapd
->drv_priv
= hapd_iface
->bss
[0]->drv_priv
;
2617 os_memcpy(hapd
->own_addr
, hapd_iface
->bss
[0]->own_addr
,
2620 if (start_ctrl_iface_bss(hapd
) < 0 ||
2621 (hapd_iface
->state
== HAPD_IFACE_ENABLED
&&
2622 hostapd_setup_bss(hapd
, -1))) {
2623 hostapd_cleanup(hapd
);
2624 hapd_iface
->bss
[hapd_iface
->num_bss
- 1] = NULL
;
2625 hapd_iface
->conf
->num_bss
--;
2626 hapd_iface
->num_bss
--;
2627 wpa_printf(MSG_DEBUG
, "%s: free hapd %p %s",
2628 __func__
, hapd
, hapd
->conf
->iface
);
2629 hostapd_config_free_bss(hapd
->conf
);
2638 ptr
= os_strchr(buf
, ' ');
2643 if (os_strncmp(ptr
, "config=", 7) == 0)
2644 conf_file
= ptr
+ 7;
2646 for (i
= 0; i
< interfaces
->count
; i
++) {
2647 if (!os_strcmp(interfaces
->iface
[i
]->conf
->bss
[0]->iface
,
2649 wpa_printf(MSG_INFO
, "Cannot add interface - it "
2655 hapd_iface
= hostapd_iface_alloc(interfaces
);
2656 if (hapd_iface
== NULL
) {
2657 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory "
2658 "for interface", __func__
);
2661 new_iface
= hapd_iface
;
2663 if (conf_file
&& interfaces
->config_read_cb
) {
2664 conf
= interfaces
->config_read_cb(conf_file
);
2665 if (conf
&& conf
->bss
)
2666 os_strlcpy(conf
->bss
[0]->iface
, buf
,
2667 sizeof(conf
->bss
[0]->iface
));
2669 char *driver
= os_strchr(ptr
, ' ');
2673 conf
= hostapd_config_alloc(interfaces
, buf
, ptr
, driver
);
2676 if (conf
== NULL
|| conf
->bss
== NULL
) {
2677 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory "
2678 "for configuration", __func__
);
2682 if (hostapd_data_alloc(hapd_iface
, conf
) < 0) {
2683 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory "
2684 "for hostapd", __func__
);
2689 if (start_ctrl_iface(hapd_iface
) < 0)
2692 wpa_printf(MSG_INFO
, "Add interface '%s'",
2693 hapd_iface
->conf
->bss
[0]->iface
);
2699 hostapd_config_free(conf
);
2701 if (hapd_iface
->bss
) {
2702 for (i
= 0; i
< hapd_iface
->num_bss
; i
++) {
2703 hapd
= hapd_iface
->bss
[i
];
2706 if (hapd_iface
->interfaces
&&
2707 hapd_iface
->interfaces
->ctrl_iface_deinit
)
2708 hapd_iface
->interfaces
->
2709 ctrl_iface_deinit(hapd
);
2710 wpa_printf(MSG_DEBUG
, "%s: free hapd %p (%s)",
2711 __func__
, hapd_iface
->bss
[i
],
2713 hostapd_cleanup(hapd
);
2715 hapd_iface
->bss
[i
] = NULL
;
2717 os_free(hapd_iface
->bss
);
2718 hapd_iface
->bss
= NULL
;
2721 interfaces
->count
--;
2722 interfaces
->iface
[interfaces
->count
] = NULL
;
2724 hostapd_cleanup_iface(hapd_iface
);
2730 static int hostapd_remove_bss(struct hostapd_iface
*iface
, unsigned int idx
)
2734 wpa_printf(MSG_INFO
, "Remove BSS '%s'", iface
->conf
->bss
[idx
]->iface
);
2736 /* Remove hostapd_data only if it has already been initialized */
2737 if (idx
< iface
->num_bss
) {
2738 struct hostapd_data
*hapd
= iface
->bss
[idx
];
2740 hostapd_bss_deinit(hapd
);
2741 wpa_printf(MSG_DEBUG
, "%s: free hapd %p (%s)",
2742 __func__
, hapd
, hapd
->conf
->iface
);
2743 hostapd_config_free_bss(hapd
->conf
);
2749 for (i
= idx
; i
< iface
->num_bss
; i
++)
2750 iface
->bss
[i
] = iface
->bss
[i
+ 1];
2752 hostapd_config_free_bss(iface
->conf
->bss
[idx
]);
2753 iface
->conf
->bss
[idx
] = NULL
;
2756 iface
->conf
->num_bss
--;
2757 for (i
= idx
; i
< iface
->conf
->num_bss
; i
++)
2758 iface
->conf
->bss
[i
] = iface
->conf
->bss
[i
+ 1];
2764 int hostapd_remove_iface(struct hapd_interfaces
*interfaces
, char *buf
)
2766 struct hostapd_iface
*hapd_iface
;
2769 for (i
= 0; i
< interfaces
->count
; i
++) {
2770 hapd_iface
= interfaces
->iface
[i
];
2771 if (hapd_iface
== NULL
)
2773 if (!os_strcmp(hapd_iface
->conf
->bss
[0]->iface
, buf
)) {
2774 wpa_printf(MSG_INFO
, "Remove interface '%s'", buf
);
2775 hapd_iface
->driver_ap_teardown
=
2776 !!(hapd_iface
->drv_flags
&
2777 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT
);
2779 hostapd_interface_deinit_free(hapd_iface
);
2781 while (k
< (interfaces
->count
- 1)) {
2782 interfaces
->iface
[k
] =
2783 interfaces
->iface
[k
+ 1];
2786 interfaces
->count
--;
2790 for (j
= 0; j
< hapd_iface
->conf
->num_bss
; j
++) {
2791 if (!os_strcmp(hapd_iface
->conf
->bss
[j
]->iface
, buf
)) {
2792 hapd_iface
->driver_ap_teardown
=
2793 !(hapd_iface
->drv_flags
&
2794 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT
);
2795 return hostapd_remove_bss(hapd_iface
, j
);
2804 * hostapd_new_assoc_sta - Notify that a new station associated with the AP
2805 * @hapd: Pointer to BSS data
2806 * @sta: Pointer to the associated STA data
2807 * @reassoc: 1 to indicate this was a re-association; 0 = first association
2809 * This function will be called whenever a station associates with the AP. It
2810 * can be called from ieee802_11.c for drivers that export MLME to hostapd and
2811 * from drv_callbacks.c based on driver events for drivers that take care of
2812 * management frames (IEEE 802.11 authentication and association) internally.
2814 void hostapd_new_assoc_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2817 if (hapd
->tkip_countermeasures
) {
2818 hostapd_drv_sta_deauth(hapd
, sta
->addr
,
2819 WLAN_REASON_MICHAEL_MIC_FAILURE
);
2823 hostapd_prune_associations(hapd
, sta
->addr
);
2824 ap_sta_clear_disconnect_timeouts(hapd
, sta
);
2826 /* IEEE 802.11F (IAPP) */
2827 if (hapd
->conf
->ieee802_11f
)
2828 iapp_new_station(hapd
->iapp
, sta
);
2831 if (sta
->p2p_ie
== NULL
&& !sta
->no_p2p_set
) {
2832 sta
->no_p2p_set
= 1;
2833 hapd
->num_sta_no_p2p
++;
2834 if (hapd
->num_sta_no_p2p
== 1)
2835 hostapd_p2p_non_p2p_sta_connected(hapd
);
2837 #endif /* CONFIG_P2P */
2839 /* Start accounting here, if IEEE 802.1X and WPA are not used.
2840 * IEEE 802.1X/WPA code will start accounting after the station has
2841 * been authorized. */
2842 if (!hapd
->conf
->ieee802_1x
&& !hapd
->conf
->wpa
&& !hapd
->conf
->osen
) {
2843 ap_sta_set_authorized(hapd
, sta
, 1);
2844 os_get_reltime(&sta
->connected_time
);
2845 accounting_sta_start(hapd
, sta
);
2848 /* Start IEEE 802.1X authentication process for new stations */
2849 ieee802_1x_new_station(hapd
, sta
);
2851 if (sta
->auth_alg
!= WLAN_AUTH_FT
&&
2852 !(sta
->flags
& (WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
)))
2853 wpa_auth_sm_event(sta
->wpa_sm
, WPA_REAUTH
);
2855 wpa_auth_sta_associated(hapd
->wpa_auth
, sta
->wpa_sm
);
2857 if (hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_WIRED
) {
2858 if (eloop_cancel_timeout(ap_handle_timer
, hapd
, sta
) > 0) {
2859 wpa_printf(MSG_DEBUG
,
2860 "%s: %s: canceled wired ap_handle_timer timeout for "
2862 hapd
->conf
->iface
, __func__
,
2863 MAC2STR(sta
->addr
));
2865 } else if (!(hapd
->iface
->drv_flags
&
2866 WPA_DRIVER_FLAGS_INACTIVITY_TIMER
)) {
2867 wpa_printf(MSG_DEBUG
,
2868 "%s: %s: reschedule ap_handle_timer timeout for "
2869 MACSTR
" (%d seconds - ap_max_inactivity)",
2870 hapd
->conf
->iface
, __func__
, MAC2STR(sta
->addr
),
2871 hapd
->conf
->ap_max_inactivity
);
2872 eloop_cancel_timeout(ap_handle_timer
, hapd
, sta
);
2873 eloop_register_timeout(hapd
->conf
->ap_max_inactivity
, 0,
2874 ap_handle_timer
, hapd
, sta
);
2879 const char * hostapd_state_text(enum hostapd_iface_state s
)
2882 case HAPD_IFACE_UNINITIALIZED
:
2883 return "UNINITIALIZED";
2884 case HAPD_IFACE_DISABLED
:
2886 case HAPD_IFACE_COUNTRY_UPDATE
:
2887 return "COUNTRY_UPDATE";
2888 case HAPD_IFACE_ACS
:
2890 case HAPD_IFACE_HT_SCAN
:
2892 case HAPD_IFACE_DFS
:
2894 case HAPD_IFACE_ENABLED
:
2902 void hostapd_set_state(struct hostapd_iface
*iface
, enum hostapd_iface_state s
)
2904 wpa_printf(MSG_INFO
, "%s: interface state %s->%s",
2905 iface
->conf
? iface
->conf
->bss
[0]->iface
: "N/A",
2906 hostapd_state_text(iface
->state
), hostapd_state_text(s
));
2911 int hostapd_csa_in_progress(struct hostapd_iface
*iface
)
2915 for (i
= 0; i
< iface
->num_bss
; i
++)
2916 if (iface
->bss
[i
]->csa_in_progress
)
2924 static void free_beacon_data(struct beacon_data
*beacon
)
2926 os_free(beacon
->head
);
2927 beacon
->head
= NULL
;
2928 os_free(beacon
->tail
);
2929 beacon
->tail
= NULL
;
2930 os_free(beacon
->probe_resp
);
2931 beacon
->probe_resp
= NULL
;
2932 os_free(beacon
->beacon_ies
);
2933 beacon
->beacon_ies
= NULL
;
2934 os_free(beacon
->proberesp_ies
);
2935 beacon
->proberesp_ies
= NULL
;
2936 os_free(beacon
->assocresp_ies
);
2937 beacon
->assocresp_ies
= NULL
;
2941 static int hostapd_build_beacon_data(struct hostapd_data
*hapd
,
2942 struct beacon_data
*beacon
)
2944 struct wpabuf
*beacon_extra
, *proberesp_extra
, *assocresp_extra
;
2945 struct wpa_driver_ap_params params
;
2948 os_memset(beacon
, 0, sizeof(*beacon
));
2949 ret
= ieee802_11_build_ap_params(hapd
, ¶ms
);
2953 ret
= hostapd_build_ap_extra_ies(hapd
, &beacon_extra
,
2957 goto free_ap_params
;
2960 beacon
->head
= os_memdup(params
.head
, params
.head_len
);
2962 goto free_ap_extra_ies
;
2964 beacon
->head_len
= params
.head_len
;
2966 beacon
->tail
= os_memdup(params
.tail
, params
.tail_len
);
2970 beacon
->tail_len
= params
.tail_len
;
2972 if (params
.proberesp
!= NULL
) {
2973 beacon
->probe_resp
= os_memdup(params
.proberesp
,
2974 params
.proberesp_len
);
2975 if (!beacon
->probe_resp
)
2978 beacon
->probe_resp_len
= params
.proberesp_len
;
2981 /* copy the extra ies */
2983 beacon
->beacon_ies
= os_memdup(beacon_extra
->buf
,
2984 wpabuf_len(beacon_extra
));
2985 if (!beacon
->beacon_ies
)
2988 beacon
->beacon_ies_len
= wpabuf_len(beacon_extra
);
2991 if (proberesp_extra
) {
2992 beacon
->proberesp_ies
= os_memdup(proberesp_extra
->buf
,
2993 wpabuf_len(proberesp_extra
));
2994 if (!beacon
->proberesp_ies
)
2997 beacon
->proberesp_ies_len
= wpabuf_len(proberesp_extra
);
3000 if (assocresp_extra
) {
3001 beacon
->assocresp_ies
= os_memdup(assocresp_extra
->buf
,
3002 wpabuf_len(assocresp_extra
));
3003 if (!beacon
->assocresp_ies
)
3006 beacon
->assocresp_ies_len
= wpabuf_len(assocresp_extra
);
3011 /* if the function fails, the caller should not free beacon data */
3013 free_beacon_data(beacon
);
3016 hostapd_free_ap_extra_ies(hapd
, beacon_extra
, proberesp_extra
,
3019 ieee802_11_free_ap_params(¶ms
);
3025 * TODO: This flow currently supports only changing channel and width within
3026 * the same hw_mode. Any other changes to MAC parameters or provided settings
3027 * are not supported.
3029 static int hostapd_change_config_freq(struct hostapd_data
*hapd
,
3030 struct hostapd_config
*conf
,
3031 struct hostapd_freq_params
*params
,
3032 struct hostapd_freq_params
*old_params
)
3036 if (!params
->channel
) {
3037 /* check if the new channel is supported by hw */
3038 params
->channel
= hostapd_hw_get_channel(hapd
, params
->freq
);
3041 channel
= params
->channel
;
3045 /* if a pointer to old_params is provided we save previous state */
3047 hostapd_set_freq_params(old_params
, conf
->hw_mode
,
3048 hostapd_hw_get_freq(hapd
, conf
->channel
),
3049 conf
->channel
, conf
->ieee80211n
,
3051 conf
->secondary_channel
,
3052 conf
->vht_oper_chwidth
,
3053 conf
->vht_oper_centr_freq_seg0_idx
,
3054 conf
->vht_oper_centr_freq_seg1_idx
,
3058 switch (params
->bandwidth
) {
3062 conf
->vht_oper_chwidth
= VHT_CHANWIDTH_USE_HT
;
3065 if (params
->center_freq2
)
3066 conf
->vht_oper_chwidth
= VHT_CHANWIDTH_80P80MHZ
;
3068 conf
->vht_oper_chwidth
= VHT_CHANWIDTH_80MHZ
;
3071 conf
->vht_oper_chwidth
= VHT_CHANWIDTH_160MHZ
;
3077 conf
->channel
= channel
;
3078 conf
->ieee80211n
= params
->ht_enabled
;
3079 conf
->secondary_channel
= params
->sec_channel_offset
;
3080 ieee80211_freq_to_chan(params
->center_freq1
,
3081 &conf
->vht_oper_centr_freq_seg0_idx
);
3082 ieee80211_freq_to_chan(params
->center_freq2
,
3083 &conf
->vht_oper_centr_freq_seg1_idx
);
3085 /* TODO: maybe call here hostapd_config_check here? */
3091 static int hostapd_fill_csa_settings(struct hostapd_data
*hapd
,
3092 struct csa_settings
*settings
)
3094 struct hostapd_iface
*iface
= hapd
->iface
;
3095 struct hostapd_freq_params old_freq
;
3097 u8 chan
, vht_bandwidth
;
3099 os_memset(&old_freq
, 0, sizeof(old_freq
));
3100 if (!iface
|| !iface
->freq
|| hapd
->csa_in_progress
)
3103 switch (settings
->freq_params
.bandwidth
) {
3105 if (settings
->freq_params
.center_freq2
)
3106 vht_bandwidth
= VHT_CHANWIDTH_80P80MHZ
;
3108 vht_bandwidth
= VHT_CHANWIDTH_80MHZ
;
3111 vht_bandwidth
= VHT_CHANWIDTH_160MHZ
;
3114 vht_bandwidth
= VHT_CHANWIDTH_USE_HT
;
3118 if (ieee80211_freq_to_channel_ext(
3119 settings
->freq_params
.freq
,
3120 settings
->freq_params
.sec_channel_offset
,
3122 &hapd
->iface
->cs_oper_class
,
3123 &chan
) == NUM_HOSTAPD_MODES
) {
3124 wpa_printf(MSG_DEBUG
,
3125 "invalid frequency for channel switch (freq=%d, sec_channel_offset=%d, vht_enabled=%d)",
3126 settings
->freq_params
.freq
,
3127 settings
->freq_params
.sec_channel_offset
,
3128 settings
->freq_params
.vht_enabled
);
3132 settings
->freq_params
.channel
= chan
;
3134 ret
= hostapd_change_config_freq(iface
->bss
[0], iface
->conf
,
3135 &settings
->freq_params
,
3140 ret
= hostapd_build_beacon_data(hapd
, &settings
->beacon_after
);
3142 /* change back the configuration */
3143 hostapd_change_config_freq(iface
->bss
[0], iface
->conf
,
3149 /* set channel switch parameters for csa ie */
3150 hapd
->cs_freq_params
= settings
->freq_params
;
3151 hapd
->cs_count
= settings
->cs_count
;
3152 hapd
->cs_block_tx
= settings
->block_tx
;
3154 ret
= hostapd_build_beacon_data(hapd
, &settings
->beacon_csa
);
3156 free_beacon_data(&settings
->beacon_after
);
3160 settings
->counter_offset_beacon
[0] = hapd
->cs_c_off_beacon
;
3161 settings
->counter_offset_presp
[0] = hapd
->cs_c_off_proberesp
;
3162 settings
->counter_offset_beacon
[1] = hapd
->cs_c_off_ecsa_beacon
;
3163 settings
->counter_offset_presp
[1] = hapd
->cs_c_off_ecsa_proberesp
;
3169 void hostapd_cleanup_cs_params(struct hostapd_data
*hapd
)
3171 os_memset(&hapd
->cs_freq_params
, 0, sizeof(hapd
->cs_freq_params
));
3173 hapd
->cs_block_tx
= 0;
3174 hapd
->cs_c_off_beacon
= 0;
3175 hapd
->cs_c_off_proberesp
= 0;
3176 hapd
->csa_in_progress
= 0;
3177 hapd
->cs_c_off_ecsa_beacon
= 0;
3178 hapd
->cs_c_off_ecsa_proberesp
= 0;
3182 int hostapd_switch_channel(struct hostapd_data
*hapd
,
3183 struct csa_settings
*settings
)
3187 if (!(hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_AP_CSA
)) {
3188 wpa_printf(MSG_INFO
, "CSA is not supported");
3192 ret
= hostapd_fill_csa_settings(hapd
, settings
);
3196 ret
= hostapd_drv_switch_channel(hapd
, settings
);
3197 free_beacon_data(&settings
->beacon_csa
);
3198 free_beacon_data(&settings
->beacon_after
);
3201 /* if we failed, clean cs parameters */
3202 hostapd_cleanup_cs_params(hapd
);
3206 hapd
->csa_in_progress
= 1;
3212 hostapd_switch_channel_fallback(struct hostapd_iface
*iface
,
3213 const struct hostapd_freq_params
*freq_params
)
3215 int vht_seg0_idx
= 0, vht_seg1_idx
= 0, vht_bw
= VHT_CHANWIDTH_USE_HT
;
3218 wpa_printf(MSG_DEBUG
, "Restarting all CSA-related BSSes");
3220 if (freq_params
->center_freq1
)
3221 vht_seg0_idx
= 36 + (freq_params
->center_freq1
- 5180) / 5;
3222 if (freq_params
->center_freq2
)
3223 vht_seg1_idx
= 36 + (freq_params
->center_freq2
- 5180) / 5;
3225 switch (freq_params
->bandwidth
) {
3229 vht_bw
= VHT_CHANWIDTH_USE_HT
;
3232 if (freq_params
->center_freq2
)
3233 vht_bw
= VHT_CHANWIDTH_80P80MHZ
;
3235 vht_bw
= VHT_CHANWIDTH_80MHZ
;
3238 vht_bw
= VHT_CHANWIDTH_160MHZ
;
3241 wpa_printf(MSG_WARNING
, "Unknown CSA bandwidth: %d",
3242 freq_params
->bandwidth
);
3246 iface
->freq
= freq_params
->freq
;
3247 iface
->conf
->channel
= freq_params
->channel
;
3248 iface
->conf
->secondary_channel
= freq_params
->sec_channel_offset
;
3249 iface
->conf
->vht_oper_centr_freq_seg0_idx
= vht_seg0_idx
;
3250 iface
->conf
->vht_oper_centr_freq_seg1_idx
= vht_seg1_idx
;
3251 iface
->conf
->vht_oper_chwidth
= vht_bw
;
3252 iface
->conf
->ieee80211n
= freq_params
->ht_enabled
;
3253 iface
->conf
->ieee80211ac
= freq_params
->vht_enabled
;
3256 * cs_params must not be cleared earlier because the freq_params
3257 * argument may actually point to one of these.
3259 for (i
= 0; i
< iface
->num_bss
; i
++)
3260 hostapd_cleanup_cs_params(iface
->bss
[i
]);
3262 hostapd_disable_iface(iface
);
3263 hostapd_enable_iface(iface
);
3266 #endif /* NEED_AP_MLME */
3269 struct hostapd_data
* hostapd_get_iface(struct hapd_interfaces
*interfaces
,
3274 for (i
= 0; i
< interfaces
->count
; i
++) {
3275 struct hostapd_iface
*iface
= interfaces
->iface
[i
];
3277 for (j
= 0; j
< iface
->num_bss
; j
++) {
3278 struct hostapd_data
*hapd
= iface
->bss
[j
];
3280 if (os_strcmp(ifname
, hapd
->conf
->iface
) == 0)
3289 void hostapd_periodic_iface(struct hostapd_iface
*iface
)
3293 ap_list_timer(iface
);
3295 for (i
= 0; i
< iface
->num_bss
; i
++) {
3296 struct hostapd_data
*hapd
= iface
->bss
[i
];
3301 #ifndef CONFIG_NO_RADIUS
3302 hostapd_acl_expire(hapd
);
3303 #endif /* CONFIG_NO_RADIUS */