2 * hostapd / Initialization and configuration
3 * Copyright (c) 2002-2014, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "common/ieee802_11_defs.h"
14 #include "common/wpa_ctrl.h"
15 #include "radius/radius_client.h"
16 #include "radius/radius_das.h"
17 #include "eap_server/tncs.h"
21 #include "accounting.h"
25 #include "ieee802_1x.h"
26 #include "ieee802_11_auth.h"
27 #include "vlan_init.h"
29 #include "wps_hostapd.h"
30 #include "hw_features.h"
31 #include "wpa_auth_glue.h"
32 #include "ap_drv_ops.h"
33 #include "ap_config.h"
34 #include "p2p_hostapd.h"
37 #include "ieee802_11.h"
40 static int hostapd_flush_old_stations(struct hostapd_data
*hapd
, u16 reason
);
41 static int hostapd_setup_encryption(char *iface
, struct hostapd_data
*hapd
);
42 static int hostapd_broadcast_wep_clear(struct hostapd_data
*hapd
);
43 static int setup_interface2(struct hostapd_iface
*iface
);
44 static void channel_list_update_timeout(void *eloop_ctx
, void *timeout_ctx
);
47 int hostapd_for_each_interface(struct hapd_interfaces
*interfaces
,
48 int (*cb
)(struct hostapd_iface
*iface
,
49 void *ctx
), void *ctx
)
54 for (i
= 0; i
< interfaces
->count
; i
++) {
55 ret
= cb(interfaces
->iface
[i
], ctx
);
64 static void hostapd_reload_bss(struct hostapd_data
*hapd
)
66 struct hostapd_ssid
*ssid
;
68 #ifndef CONFIG_NO_RADIUS
69 radius_client_reconfig(hapd
->radius
, hapd
->conf
->radius
);
70 #endif /* CONFIG_NO_RADIUS */
72 ssid
= &hapd
->conf
->ssid
;
73 if (!ssid
->wpa_psk_set
&& ssid
->wpa_psk
&& !ssid
->wpa_psk
->next
&&
74 ssid
->wpa_passphrase_set
&& ssid
->wpa_passphrase
) {
76 * Force PSK to be derived again since SSID or passphrase may
79 os_free(ssid
->wpa_psk
);
82 if (hostapd_setup_wpa_psk(hapd
->conf
)) {
83 wpa_printf(MSG_ERROR
, "Failed to re-configure WPA PSK "
84 "after reloading configuration");
87 if (hapd
->conf
->ieee802_1x
|| hapd
->conf
->wpa
)
88 hostapd_set_drv_ieee8021x(hapd
, hapd
->conf
->iface
, 1);
90 hostapd_set_drv_ieee8021x(hapd
, hapd
->conf
->iface
, 0);
92 if ((hapd
->conf
->wpa
|| hapd
->conf
->osen
) && hapd
->wpa_auth
== NULL
) {
93 hostapd_setup_wpa(hapd
);
95 wpa_init_keys(hapd
->wpa_auth
);
96 } else if (hapd
->conf
->wpa
) {
99 hostapd_reconfig_wpa(hapd
);
100 wpa_ie
= wpa_auth_get_wpa_ie(hapd
->wpa_auth
, &wpa_ie_len
);
101 if (hostapd_set_generic_elem(hapd
, wpa_ie
, wpa_ie_len
))
102 wpa_printf(MSG_ERROR
, "Failed to configure WPA IE for "
103 "the kernel driver.");
104 } else if (hapd
->wpa_auth
) {
105 wpa_deinit(hapd
->wpa_auth
);
106 hapd
->wpa_auth
= NULL
;
107 hostapd_set_privacy(hapd
, 0);
108 hostapd_setup_encryption(hapd
->conf
->iface
, hapd
);
109 hostapd_set_generic_elem(hapd
, (u8
*) "", 0);
112 ieee802_11_set_beacon(hapd
);
113 hostapd_update_wps(hapd
);
115 if (hapd
->conf
->ssid
.ssid_set
&&
116 hostapd_set_ssid(hapd
, hapd
->conf
->ssid
.ssid
,
117 hapd
->conf
->ssid
.ssid_len
)) {
118 wpa_printf(MSG_ERROR
, "Could not set SSID for kernel driver");
119 /* try to continue */
121 wpa_printf(MSG_DEBUG
, "Reconfigured interface %s", hapd
->conf
->iface
);
125 static void hostapd_clear_old(struct hostapd_iface
*iface
)
130 * Deauthenticate all stations since the new configuration may not
131 * allow them to use the BSS anymore.
133 for (j
= 0; j
< iface
->num_bss
; j
++) {
134 hostapd_flush_old_stations(iface
->bss
[j
],
135 WLAN_REASON_PREV_AUTH_NOT_VALID
);
136 hostapd_broadcast_wep_clear(iface
->bss
[j
]);
138 #ifndef CONFIG_NO_RADIUS
139 /* TODO: update dynamic data based on changed configuration
140 * items (e.g., open/close sockets, etc.) */
141 radius_client_flush(iface
->bss
[j
]->radius
, 0);
142 #endif /* CONFIG_NO_RADIUS */
147 int hostapd_reload_config(struct hostapd_iface
*iface
)
149 struct hostapd_data
*hapd
= iface
->bss
[0];
150 struct hostapd_config
*newconf
, *oldconf
;
153 if (iface
->config_fname
== NULL
) {
154 /* Only in-memory config in use - assume it has been updated */
155 hostapd_clear_old(iface
);
156 for (j
= 0; j
< iface
->num_bss
; j
++)
157 hostapd_reload_bss(iface
->bss
[j
]);
161 if (iface
->interfaces
== NULL
||
162 iface
->interfaces
->config_read_cb
== NULL
)
164 newconf
= iface
->interfaces
->config_read_cb(iface
->config_fname
);
168 hostapd_clear_old(iface
);
170 oldconf
= hapd
->iconf
;
171 iface
->conf
= newconf
;
173 for (j
= 0; j
< iface
->num_bss
; j
++) {
174 hapd
= iface
->bss
[j
];
175 hapd
->iconf
= newconf
;
176 hapd
->iconf
->channel
= oldconf
->channel
;
177 hapd
->iconf
->secondary_channel
= oldconf
->secondary_channel
;
178 hapd
->iconf
->ieee80211n
= oldconf
->ieee80211n
;
179 hapd
->iconf
->ieee80211ac
= oldconf
->ieee80211ac
;
180 hapd
->iconf
->ht_capab
= oldconf
->ht_capab
;
181 hapd
->iconf
->vht_capab
= oldconf
->vht_capab
;
182 hapd
->iconf
->vht_oper_chwidth
= oldconf
->vht_oper_chwidth
;
183 hapd
->iconf
->vht_oper_centr_freq_seg0_idx
=
184 oldconf
->vht_oper_centr_freq_seg0_idx
;
185 hapd
->iconf
->vht_oper_centr_freq_seg1_idx
=
186 oldconf
->vht_oper_centr_freq_seg1_idx
;
187 hapd
->conf
= newconf
->bss
[j
];
188 hostapd_reload_bss(hapd
);
191 hostapd_config_free(oldconf
);
198 static void hostapd_broadcast_key_clear_iface(struct hostapd_data
*hapd
,
203 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
204 if (hostapd_drv_set_key(ifname
, hapd
, WPA_ALG_NONE
, NULL
, i
,
205 0, NULL
, 0, NULL
, 0)) {
206 wpa_printf(MSG_DEBUG
, "Failed to clear default "
207 "encryption keys (ifname=%s keyidx=%d)",
211 #ifdef CONFIG_IEEE80211W
212 if (hapd
->conf
->ieee80211w
) {
213 for (i
= NUM_WEP_KEYS
; i
< NUM_WEP_KEYS
+ 2; i
++) {
214 if (hostapd_drv_set_key(ifname
, hapd
, WPA_ALG_NONE
,
217 wpa_printf(MSG_DEBUG
, "Failed to clear "
218 "default mgmt encryption keys "
219 "(ifname=%s keyidx=%d)", ifname
, i
);
223 #endif /* CONFIG_IEEE80211W */
227 static int hostapd_broadcast_wep_clear(struct hostapd_data
*hapd
)
229 hostapd_broadcast_key_clear_iface(hapd
, hapd
->conf
->iface
);
234 static int hostapd_broadcast_wep_set(struct hostapd_data
*hapd
)
237 struct hostapd_ssid
*ssid
= &hapd
->conf
->ssid
;
240 if (ssid
->wep
.default_len
&&
241 hostapd_drv_set_key(hapd
->conf
->iface
,
242 hapd
, WPA_ALG_WEP
, broadcast_ether_addr
, idx
,
243 1, NULL
, 0, ssid
->wep
.key
[idx
],
244 ssid
->wep
.len
[idx
])) {
245 wpa_printf(MSG_WARNING
, "Could not set WEP encryption.");
253 static void hostapd_free_hapd_data(struct hostapd_data
*hapd
)
255 if (!hapd
->started
) {
256 wpa_printf(MSG_ERROR
, "%s: Interface %s wasn't started",
257 __func__
, hapd
->conf
->iface
);
262 wpa_printf(MSG_DEBUG
, "%s(%s)", __func__
, hapd
->conf
->iface
);
263 iapp_deinit(hapd
->iapp
);
265 accounting_deinit(hapd
);
266 hostapd_deinit_wpa(hapd
);
268 hostapd_acl_deinit(hapd
);
269 #ifndef CONFIG_NO_RADIUS
270 radius_client_deinit(hapd
->radius
);
272 radius_das_deinit(hapd
->radius_das
);
273 hapd
->radius_das
= NULL
;
274 #endif /* CONFIG_NO_RADIUS */
276 hostapd_deinit_wps(hapd
);
278 authsrv_deinit(hapd
);
280 if (hapd
->interface_added
&&
281 hostapd_if_remove(hapd
, WPA_IF_AP_BSS
, hapd
->conf
->iface
)) {
282 wpa_printf(MSG_WARNING
, "Failed to remove BSS interface %s",
286 os_free(hapd
->probereq_cb
);
287 hapd
->probereq_cb
= NULL
;
290 wpabuf_free(hapd
->p2p_beacon_ie
);
291 hapd
->p2p_beacon_ie
= NULL
;
292 wpabuf_free(hapd
->p2p_probe_resp_ie
);
293 hapd
->p2p_probe_resp_ie
= NULL
;
294 #endif /* CONFIG_P2P */
296 wpabuf_free(hapd
->time_adv
);
298 #ifdef CONFIG_INTERWORKING
299 gas_serv_deinit(hapd
);
300 #endif /* CONFIG_INTERWORKING */
303 os_free(hapd
->tmp_eap_user
.identity
);
304 os_free(hapd
->tmp_eap_user
.password
);
305 #endif /* CONFIG_SQLITE */
310 * hostapd_cleanup - Per-BSS cleanup (deinitialization)
311 * @hapd: Pointer to BSS data
313 * This function is used to free all per-BSS data structures and resources.
314 * Most of the modules that are initialized in hostapd_setup_bss() are
315 * deinitialized here.
317 static void hostapd_cleanup(struct hostapd_data
*hapd
)
319 wpa_printf(MSG_DEBUG
, "%s(hapd=%p (%s))", __func__
, hapd
,
321 if (hapd
->iface
->interfaces
&&
322 hapd
->iface
->interfaces
->ctrl_iface_deinit
)
323 hapd
->iface
->interfaces
->ctrl_iface_deinit(hapd
);
324 hostapd_free_hapd_data(hapd
);
328 static void hostapd_cleanup_iface_partial(struct hostapd_iface
*iface
)
330 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
331 hostapd_free_hw_features(iface
->hw_features
, iface
->num_hw_features
);
332 iface
->hw_features
= NULL
;
333 os_free(iface
->current_rates
);
334 iface
->current_rates
= NULL
;
335 os_free(iface
->basic_rates
);
336 iface
->basic_rates
= NULL
;
337 ap_list_deinit(iface
);
342 * hostapd_cleanup_iface - Complete per-interface cleanup
343 * @iface: Pointer to interface data
345 * This function is called after per-BSS data structures are deinitialized
346 * with hostapd_cleanup().
348 static void hostapd_cleanup_iface(struct hostapd_iface
*iface
)
350 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
351 eloop_cancel_timeout(channel_list_update_timeout
, iface
, NULL
);
353 hostapd_cleanup_iface_partial(iface
);
354 hostapd_config_free(iface
->conf
);
357 os_free(iface
->config_fname
);
359 wpa_printf(MSG_DEBUG
, "%s: free iface=%p", __func__
, iface
);
364 static void hostapd_clear_wep(struct hostapd_data
*hapd
)
366 if (hapd
->drv_priv
&& !hapd
->iface
->driver_ap_teardown
) {
367 hostapd_set_privacy(hapd
, 0);
368 hostapd_broadcast_wep_clear(hapd
);
373 static int hostapd_setup_encryption(char *iface
, struct hostapd_data
*hapd
)
377 hostapd_broadcast_wep_set(hapd
);
379 if (hapd
->conf
->ssid
.wep
.default_len
) {
380 hostapd_set_privacy(hapd
, 1);
385 * When IEEE 802.1X is not enabled, the driver may need to know how to
386 * set authentication algorithms for static WEP.
388 hostapd_drv_set_authmode(hapd
, hapd
->conf
->auth_algs
);
390 for (i
= 0; i
< 4; i
++) {
391 if (hapd
->conf
->ssid
.wep
.key
[i
] &&
392 hostapd_drv_set_key(iface
, hapd
, WPA_ALG_WEP
, NULL
, i
,
393 i
== hapd
->conf
->ssid
.wep
.idx
, NULL
, 0,
394 hapd
->conf
->ssid
.wep
.key
[i
],
395 hapd
->conf
->ssid
.wep
.len
[i
])) {
396 wpa_printf(MSG_WARNING
, "Could not set WEP "
400 if (hapd
->conf
->ssid
.wep
.key
[i
] &&
401 i
== hapd
->conf
->ssid
.wep
.idx
)
402 hostapd_set_privacy(hapd
, 1);
409 static int hostapd_flush_old_stations(struct hostapd_data
*hapd
, u16 reason
)
414 if (hostapd_drv_none(hapd
) || hapd
->drv_priv
== NULL
)
417 if (!hapd
->iface
->driver_ap_teardown
) {
418 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
,
419 "Flushing old station entries");
421 if (hostapd_flush(hapd
)) {
422 wpa_msg(hapd
->msg_ctx
, MSG_WARNING
,
423 "Could not connect to kernel driver");
427 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "Deauthenticate all stations");
428 os_memset(addr
, 0xff, ETH_ALEN
);
429 hostapd_drv_sta_deauth(hapd
, addr
, reason
);
430 hostapd_free_stas(hapd
);
437 * hostapd_validate_bssid_configuration - Validate BSSID configuration
438 * @iface: Pointer to interface data
439 * Returns: 0 on success, -1 on failure
441 * This function is used to validate that the configured BSSIDs are valid.
443 static int hostapd_validate_bssid_configuration(struct hostapd_iface
*iface
)
445 u8 mask
[ETH_ALEN
] = { 0 };
446 struct hostapd_data
*hapd
= iface
->bss
[0];
447 unsigned int i
= iface
->conf
->num_bss
, bits
= 0, j
;
450 if (hostapd_drv_none(hapd
))
453 /* Generate BSSID mask that is large enough to cover the BSSIDs. */
455 /* Determine the bits necessary to cover the number of BSSIDs. */
456 for (i
--; i
; i
>>= 1)
459 /* Determine the bits necessary to any configured BSSIDs,
460 if they are higher than the number of BSSIDs. */
461 for (j
= 0; j
< iface
->conf
->num_bss
; j
++) {
462 if (hostapd_mac_comp_empty(iface
->conf
->bss
[j
]->bssid
) == 0) {
468 for (i
= 0; i
< ETH_ALEN
; i
++) {
470 iface
->conf
->bss
[j
]->bssid
[i
] ^
478 for (i
= 0; i
< ETH_ALEN
&& mask
[i
] == 0; i
++)
484 while (mask
[i
] != 0) {
494 wpa_printf(MSG_ERROR
, "Too many bits in the BSSID mask (%u)",
499 os_memset(mask
, 0xff, ETH_ALEN
);
501 for (i
= 5; i
> 5 - j
; i
--)
508 wpa_printf(MSG_DEBUG
, "BSS count %lu, BSSID mask " MACSTR
" (%d bits)",
509 (unsigned long) iface
->conf
->num_bss
, MAC2STR(mask
), bits
);
514 for (i
= 0; i
< ETH_ALEN
; i
++) {
515 if ((hapd
->own_addr
[i
] & mask
[i
]) != hapd
->own_addr
[i
]) {
516 wpa_printf(MSG_ERROR
, "Invalid BSSID mask " MACSTR
517 " for start address " MACSTR
".",
518 MAC2STR(mask
), MAC2STR(hapd
->own_addr
));
519 wpa_printf(MSG_ERROR
, "Start address must be the "
520 "first address in the block (i.e., addr "
521 "AND mask == addr).");
530 static int mac_in_conf(struct hostapd_config
*conf
, const void *a
)
534 for (i
= 0; i
< conf
->num_bss
; i
++) {
535 if (hostapd_mac_comp(conf
->bss
[i
]->bssid
, a
) == 0) {
544 #ifndef CONFIG_NO_RADIUS
546 static int hostapd_das_nas_mismatch(struct hostapd_data
*hapd
,
547 struct radius_das_attrs
*attr
)
549 if (attr
->nas_identifier
&&
550 (!hapd
->conf
->nas_identifier
||
551 os_strlen(hapd
->conf
->nas_identifier
) !=
552 attr
->nas_identifier_len
||
553 os_memcmp(hapd
->conf
->nas_identifier
, attr
->nas_identifier
,
554 attr
->nas_identifier_len
) != 0)) {
555 wpa_printf(MSG_DEBUG
, "RADIUS DAS: NAS-Identifier mismatch");
559 if (attr
->nas_ip_addr
&&
560 (hapd
->conf
->own_ip_addr
.af
!= AF_INET
||
561 os_memcmp(&hapd
->conf
->own_ip_addr
.u
.v4
, attr
->nas_ip_addr
, 4) !=
563 wpa_printf(MSG_DEBUG
, "RADIUS DAS: NAS-IP-Address mismatch");
568 if (attr
->nas_ipv6_addr
&&
569 (hapd
->conf
->own_ip_addr
.af
!= AF_INET6
||
570 os_memcmp(&hapd
->conf
->own_ip_addr
.u
.v6
, attr
->nas_ipv6_addr
, 16)
572 wpa_printf(MSG_DEBUG
, "RADIUS DAS: NAS-IPv6-Address mismatch");
575 #endif /* CONFIG_IPV6 */
581 static struct sta_info
* hostapd_das_find_sta(struct hostapd_data
*hapd
,
582 struct radius_das_attrs
*attr
)
584 struct sta_info
*sta
= NULL
;
588 sta
= ap_get_sta(hapd
, attr
->sta_addr
);
590 if (sta
== NULL
&& attr
->acct_session_id
&&
591 attr
->acct_session_id_len
== 17) {
592 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
593 os_snprintf(buf
, sizeof(buf
), "%08X-%08X",
594 sta
->acct_session_id_hi
,
595 sta
->acct_session_id_lo
);
596 if (os_memcmp(attr
->acct_session_id
, buf
, 17) == 0)
601 if (sta
== NULL
&& attr
->cui
) {
602 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
604 cui
= ieee802_1x_get_radius_cui(sta
->eapol_sm
);
605 if (cui
&& wpabuf_len(cui
) == attr
->cui_len
&&
606 os_memcmp(wpabuf_head(cui
), attr
->cui
,
612 if (sta
== NULL
&& attr
->user_name
) {
613 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
616 identity
= ieee802_1x_get_identity(sta
->eapol_sm
,
619 identity_len
== attr
->user_name_len
&&
620 os_memcmp(identity
, attr
->user_name
, identity_len
)
630 static enum radius_das_res
631 hostapd_das_disconnect(void *ctx
, struct radius_das_attrs
*attr
)
633 struct hostapd_data
*hapd
= ctx
;
634 struct sta_info
*sta
;
636 if (hostapd_das_nas_mismatch(hapd
, attr
))
637 return RADIUS_DAS_NAS_MISMATCH
;
639 sta
= hostapd_das_find_sta(hapd
, attr
);
641 return RADIUS_DAS_SESSION_NOT_FOUND
;
643 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
645 hostapd_drv_sta_deauth(hapd
, sta
->addr
,
646 WLAN_REASON_PREV_AUTH_NOT_VALID
);
647 ap_sta_deauthenticate(hapd
, sta
, WLAN_REASON_PREV_AUTH_NOT_VALID
);
649 return RADIUS_DAS_SUCCESS
;
652 #endif /* CONFIG_NO_RADIUS */
656 * hostapd_setup_bss - Per-BSS setup (initialization)
657 * @hapd: Pointer to BSS data
658 * @first: Whether this BSS is the first BSS of an interface; -1 = not first,
659 * but interface may exist
661 * This function is used to initialize all per-BSS data structures and
662 * resources. This gets called in a loop for each BSS when an interface is
663 * initialized. Most of the modules that are initialized here will be
664 * deinitialized in hostapd_cleanup().
666 static int hostapd_setup_bss(struct hostapd_data
*hapd
, int first
)
668 struct hostapd_bss_config
*conf
= hapd
->conf
;
669 u8 ssid
[HOSTAPD_MAX_SSID_LEN
+ 1];
670 int ssid_len
, set_ssid
;
671 char force_ifname
[IFNAMSIZ
];
672 u8 if_addr
[ETH_ALEN
];
674 wpa_printf(MSG_DEBUG
, "%s(hapd=%p (%s), first=%d)",
675 __func__
, hapd
, hapd
->conf
->iface
, first
);
677 #ifdef EAP_SERVER_TNC
678 if (hapd
->conf
->tnc
&& tncs_global_init() < 0) {
679 wpa_printf(MSG_ERROR
, "Failed to initialize TNCS");
682 #endif /* EAP_SERVER_TNC */
685 wpa_printf(MSG_ERROR
, "%s: Interface %s was already started",
686 __func__
, hapd
->conf
->iface
);
691 if (!first
|| first
== -1) {
692 if (hostapd_mac_comp_empty(hapd
->conf
->bssid
) == 0) {
693 /* Allocate the next available BSSID. */
695 inc_byte_array(hapd
->own_addr
, ETH_ALEN
);
696 } while (mac_in_conf(hapd
->iconf
, hapd
->own_addr
));
698 /* Allocate the configured BSSID. */
699 os_memcpy(hapd
->own_addr
, hapd
->conf
->bssid
, ETH_ALEN
);
701 if (hostapd_mac_comp(hapd
->own_addr
,
702 hapd
->iface
->bss
[0]->own_addr
) ==
704 wpa_printf(MSG_ERROR
, "BSS '%s' may not have "
705 "BSSID set to the MAC address of "
706 "the radio", hapd
->conf
->iface
);
711 hapd
->interface_added
= 1;
712 if (hostapd_if_add(hapd
->iface
->bss
[0], WPA_IF_AP_BSS
,
713 hapd
->conf
->iface
, hapd
->own_addr
, hapd
,
714 &hapd
->drv_priv
, force_ifname
, if_addr
,
715 hapd
->conf
->bridge
[0] ? hapd
->conf
->bridge
:
716 NULL
, first
== -1)) {
717 wpa_printf(MSG_ERROR
, "Failed to add BSS (BSSID="
718 MACSTR
")", MAC2STR(hapd
->own_addr
));
719 hapd
->interface_added
= 0;
724 if (conf
->wmm_enabled
< 0)
725 conf
->wmm_enabled
= hapd
->iconf
->ieee80211n
;
727 hostapd_flush_old_stations(hapd
, WLAN_REASON_PREV_AUTH_NOT_VALID
);
728 hostapd_set_privacy(hapd
, 0);
730 hostapd_broadcast_wep_clear(hapd
);
731 if (hostapd_setup_encryption(hapd
->conf
->iface
, hapd
))
735 * Fetch the SSID from the system and use it or,
736 * if one was specified in the config file, verify they
739 ssid_len
= hostapd_get_ssid(hapd
, ssid
, sizeof(ssid
));
741 wpa_printf(MSG_ERROR
, "Could not read SSID from system");
744 if (conf
->ssid
.ssid_set
) {
746 * If SSID is specified in the config file and it differs
747 * from what is being used then force installation of the
750 set_ssid
= (conf
->ssid
.ssid_len
!= (size_t) ssid_len
||
751 os_memcmp(conf
->ssid
.ssid
, ssid
, ssid_len
) != 0);
754 * No SSID in the config file; just use the one we got
758 conf
->ssid
.ssid_len
= ssid_len
;
759 os_memcpy(conf
->ssid
.ssid
, ssid
, conf
->ssid
.ssid_len
);
762 if (!hostapd_drv_none(hapd
)) {
763 wpa_printf(MSG_ERROR
, "Using interface %s with hwaddr " MACSTR
765 hapd
->conf
->iface
, MAC2STR(hapd
->own_addr
),
766 wpa_ssid_txt(hapd
->conf
->ssid
.ssid
,
767 hapd
->conf
->ssid
.ssid_len
));
770 if (hostapd_setup_wpa_psk(conf
)) {
771 wpa_printf(MSG_ERROR
, "WPA-PSK setup failed.");
775 /* Set SSID for the kernel driver (to be used in beacon and probe
776 * response frames) */
777 if (set_ssid
&& hostapd_set_ssid(hapd
, conf
->ssid
.ssid
,
778 conf
->ssid
.ssid_len
)) {
779 wpa_printf(MSG_ERROR
, "Could not set SSID for kernel driver");
783 if (wpa_debug_level
<= MSG_MSGDUMP
)
784 conf
->radius
->msg_dumps
= 1;
785 #ifndef CONFIG_NO_RADIUS
786 hapd
->radius
= radius_client_init(hapd
, conf
->radius
);
787 if (hapd
->radius
== NULL
) {
788 wpa_printf(MSG_ERROR
, "RADIUS client initialization failed.");
792 if (hapd
->conf
->radius_das_port
) {
793 struct radius_das_conf das_conf
;
794 os_memset(&das_conf
, 0, sizeof(das_conf
));
795 das_conf
.port
= hapd
->conf
->radius_das_port
;
796 das_conf
.shared_secret
= hapd
->conf
->radius_das_shared_secret
;
797 das_conf
.shared_secret_len
=
798 hapd
->conf
->radius_das_shared_secret_len
;
799 das_conf
.client_addr
= &hapd
->conf
->radius_das_client_addr
;
800 das_conf
.time_window
= hapd
->conf
->radius_das_time_window
;
801 das_conf
.require_event_timestamp
=
802 hapd
->conf
->radius_das_require_event_timestamp
;
804 das_conf
.disconnect
= hostapd_das_disconnect
;
805 hapd
->radius_das
= radius_das_init(&das_conf
);
806 if (hapd
->radius_das
== NULL
) {
807 wpa_printf(MSG_ERROR
, "RADIUS DAS initialization "
812 #endif /* CONFIG_NO_RADIUS */
814 if (hostapd_acl_init(hapd
)) {
815 wpa_printf(MSG_ERROR
, "ACL initialization failed.");
818 if (hostapd_init_wps(hapd
, conf
))
821 if (authsrv_init(hapd
) < 0)
824 if (ieee802_1x_init(hapd
)) {
825 wpa_printf(MSG_ERROR
, "IEEE 802.1X initialization failed.");
829 if ((hapd
->conf
->wpa
|| hapd
->conf
->osen
) && hostapd_setup_wpa(hapd
))
832 if (accounting_init(hapd
)) {
833 wpa_printf(MSG_ERROR
, "Accounting initialization failed.");
837 if (hapd
->conf
->ieee802_11f
&&
838 (hapd
->iapp
= iapp_init(hapd
, hapd
->conf
->iapp_iface
)) == NULL
) {
839 wpa_printf(MSG_ERROR
, "IEEE 802.11F (IAPP) initialization "
844 #ifdef CONFIG_INTERWORKING
845 if (gas_serv_init(hapd
)) {
846 wpa_printf(MSG_ERROR
, "GAS server initialization failed");
850 if (conf
->qos_map_set_len
&&
851 hostapd_drv_set_qos_map(hapd
, conf
->qos_map_set
,
852 conf
->qos_map_set_len
)) {
853 wpa_printf(MSG_ERROR
, "Failed to initialize QoS Map");
856 #endif /* CONFIG_INTERWORKING */
858 if (!hostapd_drv_none(hapd
) && vlan_init(hapd
)) {
859 wpa_printf(MSG_ERROR
, "VLAN initialization failed.");
863 if (!hapd
->conf
->start_disabled
&& ieee802_11_set_beacon(hapd
) < 0)
866 if (hapd
->wpa_auth
&& wpa_init_keys(hapd
->wpa_auth
) < 0)
869 if (hapd
->driver
&& hapd
->driver
->set_operstate
)
870 hapd
->driver
->set_operstate(hapd
->drv_priv
, 1);
876 static void hostapd_tx_queue_params(struct hostapd_iface
*iface
)
878 struct hostapd_data
*hapd
= iface
->bss
[0];
880 struct hostapd_tx_queue_params
*p
;
882 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
883 p
= &iface
->conf
->tx_queue
[i
];
885 if (hostapd_set_tx_queue_params(hapd
, i
, p
->aifs
, p
->cwmin
,
886 p
->cwmax
, p
->burst
)) {
887 wpa_printf(MSG_DEBUG
, "Failed to set TX queue "
888 "parameters for queue %d.", i
);
889 /* Continue anyway */
895 static int hostapd_set_acl_list(struct hostapd_data
*hapd
,
896 struct mac_acl_entry
*mac_acl
,
897 int n_entries
, u8 accept_acl
)
899 struct hostapd_acl_params
*acl_params
;
902 acl_params
= os_zalloc(sizeof(*acl_params
) +
903 (n_entries
* sizeof(acl_params
->mac_acl
[0])));
907 for (i
= 0; i
< n_entries
; i
++)
908 os_memcpy(acl_params
->mac_acl
[i
].addr
, mac_acl
[i
].addr
,
911 acl_params
->acl_policy
= accept_acl
;
912 acl_params
->num_mac_acl
= n_entries
;
914 err
= hostapd_drv_set_acl(hapd
, acl_params
);
922 static void hostapd_set_acl(struct hostapd_data
*hapd
)
924 struct hostapd_config
*conf
= hapd
->iconf
;
928 if (hapd
->iface
->drv_max_acl_mac_addrs
== 0)
930 if (!(conf
->bss
[0]->num_accept_mac
|| conf
->bss
[0]->num_deny_mac
))
933 if (conf
->bss
[0]->macaddr_acl
== DENY_UNLESS_ACCEPTED
) {
934 if (conf
->bss
[0]->num_accept_mac
) {
936 err
= hostapd_set_acl_list(hapd
,
937 conf
->bss
[0]->accept_mac
,
938 conf
->bss
[0]->num_accept_mac
,
941 wpa_printf(MSG_DEBUG
, "Failed to set accept acl");
945 wpa_printf(MSG_DEBUG
, "Mismatch between ACL Policy & Accept/deny lists file");
947 } else if (conf
->bss
[0]->macaddr_acl
== ACCEPT_UNLESS_DENIED
) {
948 if (conf
->bss
[0]->num_deny_mac
) {
950 err
= hostapd_set_acl_list(hapd
, conf
->bss
[0]->deny_mac
,
951 conf
->bss
[0]->num_deny_mac
,
954 wpa_printf(MSG_DEBUG
, "Failed to set deny acl");
958 wpa_printf(MSG_DEBUG
, "Mismatch between ACL Policy & Accept/deny lists file");
964 static int start_ctrl_iface_bss(struct hostapd_data
*hapd
)
966 if (!hapd
->iface
->interfaces
||
967 !hapd
->iface
->interfaces
->ctrl_iface_init
)
970 if (hapd
->iface
->interfaces
->ctrl_iface_init(hapd
)) {
971 wpa_printf(MSG_ERROR
,
972 "Failed to setup control interface for %s",
981 static int start_ctrl_iface(struct hostapd_iface
*iface
)
985 if (!iface
->interfaces
|| !iface
->interfaces
->ctrl_iface_init
)
988 for (i
= 0; i
< iface
->num_bss
; i
++) {
989 struct hostapd_data
*hapd
= iface
->bss
[i
];
990 if (iface
->interfaces
->ctrl_iface_init(hapd
)) {
991 wpa_printf(MSG_ERROR
,
992 "Failed to setup control interface for %s",
1002 static void channel_list_update_timeout(void *eloop_ctx
, void *timeout_ctx
)
1004 struct hostapd_iface
*iface
= eloop_ctx
;
1006 if (!iface
->wait_channel_update
) {
1007 wpa_printf(MSG_INFO
, "Channel list update timeout, but interface was not waiting for it");
1012 * It is possible that the existing channel list is acceptable, so try
1015 wpa_printf(MSG_DEBUG
, "Channel list update timeout - try to continue anyway");
1016 setup_interface2(iface
);
1020 void hostapd_channel_list_updated(struct hostapd_iface
*iface
, int initiator
)
1022 if (!iface
->wait_channel_update
|| initiator
!= REGDOM_SET_BY_USER
)
1025 wpa_printf(MSG_DEBUG
, "Channel list updated - continue setup");
1026 eloop_cancel_timeout(channel_list_update_timeout
, iface
, NULL
);
1027 setup_interface2(iface
);
1031 static int setup_interface(struct hostapd_iface
*iface
)
1033 struct hostapd_data
*hapd
= iface
->bss
[0];
1037 * It is possible that setup_interface() is called after the interface
1038 * was disabled etc., in which case driver_ap_teardown is possibly set
1039 * to 1. Clear it here so any other key/station deletion, which is not
1040 * part of a teardown flow, would also call the relevant driver
1043 iface
->driver_ap_teardown
= 0;
1045 if (!iface
->phy
[0]) {
1046 const char *phy
= hostapd_drv_get_radio_name(hapd
);
1048 wpa_printf(MSG_DEBUG
, "phy: %s", phy
);
1049 os_strlcpy(iface
->phy
, phy
, sizeof(iface
->phy
));
1054 * Make sure that all BSSes get configured with a pointer to the same
1057 for (i
= 1; i
< iface
->num_bss
; i
++) {
1058 iface
->bss
[i
]->driver
= hapd
->driver
;
1059 iface
->bss
[i
]->drv_priv
= hapd
->drv_priv
;
1062 if (hostapd_validate_bssid_configuration(iface
))
1066 * Initialize control interfaces early to allow external monitoring of
1067 * channel setup operations that may take considerable amount of time
1068 * especially for DFS cases.
1070 if (start_ctrl_iface(iface
))
1073 if (hapd
->iconf
->country
[0] && hapd
->iconf
->country
[1]) {
1074 char country
[4], previous_country
[4];
1076 hostapd_set_state(iface
, HAPD_IFACE_COUNTRY_UPDATE
);
1077 if (hostapd_get_country(hapd
, previous_country
) < 0)
1078 previous_country
[0] = '\0';
1080 os_memcpy(country
, hapd
->iconf
->country
, 3);
1082 if (hostapd_set_country(hapd
, country
) < 0) {
1083 wpa_printf(MSG_ERROR
, "Failed to set country code");
1087 wpa_printf(MSG_DEBUG
, "Previous country code %s, new country code %s",
1088 previous_country
, country
);
1090 if (os_strncmp(previous_country
, country
, 2) != 0) {
1091 wpa_printf(MSG_DEBUG
, "Continue interface setup after channel list update");
1092 iface
->wait_channel_update
= 1;
1093 eloop_register_timeout(5, 0,
1094 channel_list_update_timeout
,
1100 return setup_interface2(iface
);
1104 static int setup_interface2(struct hostapd_iface
*iface
)
1106 iface
->wait_channel_update
= 0;
1108 if (hostapd_get_hw_features(iface
)) {
1109 /* Not all drivers support this yet, so continue without hw
1112 int ret
= hostapd_select_hw_mode(iface
);
1114 wpa_printf(MSG_ERROR
, "Could not select hw_mode and "
1115 "channel. (%d)", ret
);
1119 wpa_printf(MSG_DEBUG
, "Interface initialization will be completed in a callback (ACS)");
1122 ret
= hostapd_check_ht_capab(iface
);
1126 wpa_printf(MSG_DEBUG
, "Interface initialization will "
1127 "be completed in a callback");
1131 if (iface
->conf
->ieee80211h
)
1132 wpa_printf(MSG_DEBUG
, "DFS support is enabled");
1134 return hostapd_setup_interface_complete(iface
, 0);
1137 hostapd_set_state(iface
, HAPD_IFACE_DISABLED
);
1138 wpa_msg(iface
->bss
[0]->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
1139 if (iface
->interfaces
&& iface
->interfaces
->terminate_on_error
)
1146 * hostapd_setup_interface_complete - Complete interface setup
1148 * This function is called when previous steps in the interface setup has been
1149 * completed. This can also start operations, e.g., DFS, that will require
1150 * additional processing before interface is ready to be enabled. Such
1151 * operations will call this function from eloop callbacks when finished.
1153 int hostapd_setup_interface_complete(struct hostapd_iface
*iface
, int err
)
1155 struct hostapd_data
*hapd
= iface
->bss
[0];
1162 wpa_printf(MSG_DEBUG
, "Completing interface initialization");
1163 if (iface
->conf
->channel
) {
1166 #endif /* NEED_AP_MLME */
1168 iface
->freq
= hostapd_hw_get_freq(hapd
, iface
->conf
->channel
);
1169 wpa_printf(MSG_DEBUG
, "Mode: %s Channel: %d "
1170 "Frequency: %d MHz",
1171 hostapd_hw_mode_txt(iface
->conf
->hw_mode
),
1172 iface
->conf
->channel
, iface
->freq
);
1176 res
= hostapd_handle_dfs(iface
);
1182 #endif /* NEED_AP_MLME */
1184 if (hostapd_set_freq(hapd
, hapd
->iconf
->hw_mode
, iface
->freq
,
1185 hapd
->iconf
->channel
,
1186 hapd
->iconf
->ieee80211n
,
1187 hapd
->iconf
->ieee80211ac
,
1188 hapd
->iconf
->secondary_channel
,
1189 hapd
->iconf
->vht_oper_chwidth
,
1190 hapd
->iconf
->vht_oper_centr_freq_seg0_idx
,
1191 hapd
->iconf
->vht_oper_centr_freq_seg1_idx
)) {
1192 wpa_printf(MSG_ERROR
, "Could not set channel for "
1198 if (iface
->current_mode
) {
1199 if (hostapd_prepare_rates(iface
, iface
->current_mode
)) {
1200 wpa_printf(MSG_ERROR
, "Failed to prepare rates "
1202 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE80211
,
1203 HOSTAPD_LEVEL_WARNING
,
1204 "Failed to prepare rates table.");
1209 if (hapd
->iconf
->rts_threshold
> -1 &&
1210 hostapd_set_rts(hapd
, hapd
->iconf
->rts_threshold
)) {
1211 wpa_printf(MSG_ERROR
, "Could not set RTS threshold for "
1216 if (hapd
->iconf
->fragm_threshold
> -1 &&
1217 hostapd_set_frag(hapd
, hapd
->iconf
->fragm_threshold
)) {
1218 wpa_printf(MSG_ERROR
, "Could not set fragmentation threshold "
1219 "for kernel driver");
1223 prev_addr
= hapd
->own_addr
;
1225 for (j
= 0; j
< iface
->num_bss
; j
++) {
1226 hapd
= iface
->bss
[j
];
1228 os_memcpy(hapd
->own_addr
, prev_addr
, ETH_ALEN
);
1229 if (hostapd_setup_bss(hapd
, j
== 0))
1231 if (hostapd_mac_comp_empty(hapd
->conf
->bssid
) == 0)
1232 prev_addr
= hapd
->own_addr
;
1234 hapd
= iface
->bss
[0];
1236 hostapd_tx_queue_params(iface
);
1238 ap_list_init(iface
);
1240 hostapd_set_acl(hapd
);
1242 if (hostapd_driver_commit(hapd
) < 0) {
1243 wpa_printf(MSG_ERROR
, "%s: Failed to commit driver "
1244 "configuration", __func__
);
1249 * WPS UPnP module can be initialized only when the "upnp_iface" is up.
1250 * If "interface" and "upnp_iface" are the same (e.g., non-bridge
1251 * mode), the interface is up only after driver_commit, so initialize
1252 * WPS after driver_commit.
1254 for (j
= 0; j
< iface
->num_bss
; j
++) {
1255 if (hostapd_init_wps_complete(iface
->bss
[j
]))
1259 hostapd_set_state(iface
, HAPD_IFACE_ENABLED
);
1260 wpa_msg(iface
->bss
[0]->msg_ctx
, MSG_INFO
, AP_EVENT_ENABLED
);
1261 if (hapd
->setup_complete_cb
)
1262 hapd
->setup_complete_cb(hapd
->setup_complete_cb_ctx
);
1264 wpa_printf(MSG_DEBUG
, "%s: Setup of interface done.",
1265 iface
->bss
[0]->conf
->iface
);
1266 if (iface
->interfaces
&& iface
->interfaces
->terminate_on_error
> 0)
1267 iface
->interfaces
->terminate_on_error
--;
1272 wpa_printf(MSG_ERROR
, "Interface initialization failed");
1273 hostapd_set_state(iface
, HAPD_IFACE_DISABLED
);
1274 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
1275 if (iface
->interfaces
&& iface
->interfaces
->terminate_on_error
)
1282 * hostapd_setup_interface - Setup of an interface
1283 * @iface: Pointer to interface data.
1284 * Returns: 0 on success, -1 on failure
1286 * Initializes the driver interface, validates the configuration,
1287 * and sets driver parameters based on the configuration.
1288 * Flushes old stations, sets the channel, encryption,
1289 * beacons, and WDS links based on the configuration.
1291 * If interface setup requires more time, e.g., to perform HT co-ex scans, ACS,
1292 * or DFS operations, this function returns 0 before such operations have been
1293 * completed. The pending operations are registered into eloop and will be
1294 * completed from eloop callbacks. Those callbacks end up calling
1295 * hostapd_setup_interface_complete() once setup has been completed.
1297 int hostapd_setup_interface(struct hostapd_iface
*iface
)
1301 ret
= setup_interface(iface
);
1303 wpa_printf(MSG_ERROR
, "%s: Unable to setup interface.",
1304 iface
->bss
[0]->conf
->iface
);
1313 * hostapd_alloc_bss_data - Allocate and initialize per-BSS data
1314 * @hapd_iface: Pointer to interface data
1315 * @conf: Pointer to per-interface configuration
1316 * @bss: Pointer to per-BSS configuration for this BSS
1317 * Returns: Pointer to allocated BSS data
1319 * This function is used to allocate per-BSS data structure. This data will be
1320 * freed after hostapd_cleanup() is called for it during interface
1323 struct hostapd_data
*
1324 hostapd_alloc_bss_data(struct hostapd_iface
*hapd_iface
,
1325 struct hostapd_config
*conf
,
1326 struct hostapd_bss_config
*bss
)
1328 struct hostapd_data
*hapd
;
1330 hapd
= os_zalloc(sizeof(*hapd
));
1334 hapd
->new_assoc_sta_cb
= hostapd_new_assoc_sta
;
1337 hapd
->iface
= hapd_iface
;
1338 hapd
->driver
= hapd
->iconf
->driver
;
1339 hapd
->ctrl_sock
= -1;
1345 static void hostapd_bss_deinit(struct hostapd_data
*hapd
)
1347 wpa_printf(MSG_DEBUG
, "%s: deinit bss %s", __func__
,
1349 hostapd_free_stas(hapd
);
1350 hostapd_flush_old_stations(hapd
, WLAN_REASON_DEAUTH_LEAVING
);
1351 hostapd_clear_wep(hapd
);
1352 hostapd_cleanup(hapd
);
1356 void hostapd_interface_deinit(struct hostapd_iface
*iface
)
1360 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
1364 #ifdef CONFIG_IEEE80211N
1366 hostapd_stop_setup_timers(iface
);
1367 eloop_cancel_timeout(ap_ht2040_timeout
, iface
, NULL
);
1368 #endif /* NEED_AP_MLME */
1369 #endif /* CONFIG_IEEE80211N */
1370 eloop_cancel_timeout(channel_list_update_timeout
, iface
, NULL
);
1371 iface
->wait_channel_update
= 0;
1373 for (j
= iface
->num_bss
- 1; j
>= 0; j
--)
1374 hostapd_bss_deinit(iface
->bss
[j
]);
1378 void hostapd_interface_free(struct hostapd_iface
*iface
)
1381 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
1382 for (j
= 0; j
< iface
->num_bss
; j
++) {
1383 wpa_printf(MSG_DEBUG
, "%s: free hapd %p",
1384 __func__
, iface
->bss
[j
]);
1385 os_free(iface
->bss
[j
]);
1387 hostapd_cleanup_iface(iface
);
1392 * hostapd_init - Allocate and initialize per-interface data
1393 * @config_file: Path to the configuration file
1394 * Returns: Pointer to the allocated interface data or %NULL on failure
1396 * This function is used to allocate main data structures for per-interface
1397 * data. The allocated data buffer will be freed by calling
1398 * hostapd_cleanup_iface().
1400 struct hostapd_iface
* hostapd_init(struct hapd_interfaces
*interfaces
,
1401 const char *config_file
)
1403 struct hostapd_iface
*hapd_iface
= NULL
;
1404 struct hostapd_config
*conf
= NULL
;
1405 struct hostapd_data
*hapd
;
1408 hapd_iface
= os_zalloc(sizeof(*hapd_iface
));
1409 if (hapd_iface
== NULL
)
1412 hapd_iface
->config_fname
= os_strdup(config_file
);
1413 if (hapd_iface
->config_fname
== NULL
)
1416 conf
= interfaces
->config_read_cb(hapd_iface
->config_fname
);
1419 hapd_iface
->conf
= conf
;
1421 hapd_iface
->num_bss
= conf
->num_bss
;
1422 hapd_iface
->bss
= os_calloc(conf
->num_bss
,
1423 sizeof(struct hostapd_data
*));
1424 if (hapd_iface
->bss
== NULL
)
1427 for (i
= 0; i
< conf
->num_bss
; i
++) {
1428 hapd
= hapd_iface
->bss
[i
] =
1429 hostapd_alloc_bss_data(hapd_iface
, conf
,
1433 hapd
->msg_ctx
= hapd
;
1439 wpa_printf(MSG_ERROR
, "Failed to set up interface with %s",
1442 hostapd_config_free(conf
);
1444 os_free(hapd_iface
->config_fname
);
1445 os_free(hapd_iface
->bss
);
1446 wpa_printf(MSG_DEBUG
, "%s: free iface %p",
1447 __func__
, hapd_iface
);
1448 os_free(hapd_iface
);
1454 static int ifname_in_use(struct hapd_interfaces
*interfaces
, const char *ifname
)
1458 for (i
= 0; i
< interfaces
->count
; i
++) {
1459 struct hostapd_iface
*iface
= interfaces
->iface
[i
];
1460 for (j
= 0; j
< iface
->num_bss
; j
++) {
1461 struct hostapd_data
*hapd
= iface
->bss
[j
];
1462 if (os_strcmp(ifname
, hapd
->conf
->iface
) == 0)
1472 * hostapd_interface_init_bss - Read configuration file and init BSS data
1474 * This function is used to parse configuration file for a BSS. This BSS is
1475 * added to an existing interface sharing the same radio (if any) or a new
1476 * interface is created if this is the first interface on a radio. This
1477 * allocate memory for the BSS. No actual driver operations are started.
1479 * This is similar to hostapd_interface_init(), but for a case where the
1480 * configuration is used to add a single BSS instead of all BSSes for a radio.
1482 struct hostapd_iface
*
1483 hostapd_interface_init_bss(struct hapd_interfaces
*interfaces
, const char *phy
,
1484 const char *config_fname
, int debug
)
1486 struct hostapd_iface
*new_iface
= NULL
, *iface
= NULL
;
1487 struct hostapd_data
*hapd
;
1494 for (i
= 0; i
< interfaces
->count
; i
++) {
1495 if (os_strcmp(interfaces
->iface
[i
]->phy
, phy
) == 0) {
1496 iface
= interfaces
->iface
[i
];
1501 wpa_printf(MSG_INFO
, "Configuration file: %s (phy %s)%s",
1502 config_fname
, phy
, iface
? "" : " --> new PHY");
1504 struct hostapd_config
*conf
;
1505 struct hostapd_bss_config
**tmp_conf
;
1506 struct hostapd_data
**tmp_bss
;
1507 struct hostapd_bss_config
*bss
;
1510 /* Add new BSS to existing iface */
1511 conf
= interfaces
->config_read_cb(config_fname
);
1514 if (conf
->num_bss
> 1) {
1515 wpa_printf(MSG_ERROR
, "Multiple BSSes specified in BSS-config");
1516 hostapd_config_free(conf
);
1520 ifname
= conf
->bss
[0]->iface
;
1521 if (ifname
[0] != '\0' && ifname_in_use(interfaces
, ifname
)) {
1522 wpa_printf(MSG_ERROR
,
1523 "Interface name %s already in use", ifname
);
1524 hostapd_config_free(conf
);
1528 tmp_conf
= os_realloc_array(
1529 iface
->conf
->bss
, iface
->conf
->num_bss
+ 1,
1530 sizeof(struct hostapd_bss_config
*));
1531 tmp_bss
= os_realloc_array(iface
->bss
, iface
->num_bss
+ 1,
1532 sizeof(struct hostapd_data
*));
1534 iface
->bss
= tmp_bss
;
1536 iface
->conf
->bss
= tmp_conf
;
1537 iface
->conf
->last_bss
= tmp_conf
[0];
1539 if (tmp_bss
== NULL
|| tmp_conf
== NULL
) {
1540 hostapd_config_free(conf
);
1543 bss
= iface
->conf
->bss
[iface
->conf
->num_bss
] = conf
->bss
[0];
1544 iface
->conf
->num_bss
++;
1546 hapd
= hostapd_alloc_bss_data(iface
, iface
->conf
, bss
);
1548 iface
->conf
->num_bss
--;
1549 hostapd_config_free(conf
);
1552 iface
->conf
->last_bss
= bss
;
1553 iface
->bss
[iface
->num_bss
] = hapd
;
1554 hapd
->msg_ctx
= hapd
;
1556 bss_idx
= iface
->num_bss
++;
1558 conf
->bss
[0] = NULL
;
1559 hostapd_config_free(conf
);
1561 /* Add a new iface with the first BSS */
1562 new_iface
= iface
= hostapd_init(interfaces
, config_fname
);
1565 os_strlcpy(iface
->phy
, phy
, sizeof(iface
->phy
));
1566 iface
->interfaces
= interfaces
;
1570 for (k
= 0; k
< debug
; k
++) {
1571 if (iface
->bss
[bss_idx
]->conf
->logger_stdout_level
> 0)
1572 iface
->bss
[bss_idx
]->conf
->logger_stdout_level
--;
1575 if (iface
->conf
->bss
[bss_idx
]->iface
[0] == '\0' &&
1576 !hostapd_drv_none(iface
->bss
[bss_idx
])) {
1577 wpa_printf(MSG_ERROR
, "Interface name not specified in %s",
1580 hostapd_interface_deinit_free(new_iface
);
1588 void hostapd_interface_deinit_free(struct hostapd_iface
*iface
)
1590 const struct wpa_driver_ops
*driver
;
1593 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
1596 wpa_printf(MSG_DEBUG
, "%s: num_bss=%u conf->num_bss=%u",
1597 __func__
, (unsigned int) iface
->num_bss
,
1598 (unsigned int) iface
->conf
->num_bss
);
1599 driver
= iface
->bss
[0]->driver
;
1600 drv_priv
= iface
->bss
[0]->drv_priv
;
1601 hostapd_interface_deinit(iface
);
1602 wpa_printf(MSG_DEBUG
, "%s: driver=%p drv_priv=%p -> hapd_deinit",
1603 __func__
, driver
, drv_priv
);
1604 if (driver
&& driver
->hapd_deinit
&& drv_priv
)
1605 driver
->hapd_deinit(drv_priv
);
1606 hostapd_interface_free(iface
);
1610 static void hostapd_deinit_driver(const struct wpa_driver_ops
*driver
,
1612 struct hostapd_iface
*hapd_iface
)
1616 wpa_printf(MSG_DEBUG
, "%s: driver=%p drv_priv=%p -> hapd_deinit",
1617 __func__
, driver
, drv_priv
);
1618 if (driver
&& driver
->hapd_deinit
&& drv_priv
) {
1619 driver
->hapd_deinit(drv_priv
);
1620 for (j
= 0; j
< hapd_iface
->num_bss
; j
++) {
1621 wpa_printf(MSG_DEBUG
, "%s:bss[%d]->drv_priv=%p",
1623 hapd_iface
->bss
[j
]->drv_priv
);
1624 if (hapd_iface
->bss
[j
]->drv_priv
== drv_priv
)
1625 hapd_iface
->bss
[j
]->drv_priv
= NULL
;
1631 int hostapd_enable_iface(struct hostapd_iface
*hapd_iface
)
1633 if (hapd_iface
->bss
[0]->drv_priv
!= NULL
) {
1634 wpa_printf(MSG_ERROR
, "Interface %s already enabled",
1635 hapd_iface
->conf
->bss
[0]->iface
);
1639 wpa_printf(MSG_DEBUG
, "Enable interface %s",
1640 hapd_iface
->conf
->bss
[0]->iface
);
1642 if (hostapd_config_check(hapd_iface
->conf
, 1) < 0) {
1643 wpa_printf(MSG_INFO
, "Invalid configuration - cannot enable");
1647 if (hapd_iface
->interfaces
== NULL
||
1648 hapd_iface
->interfaces
->driver_init
== NULL
||
1649 hapd_iface
->interfaces
->driver_init(hapd_iface
))
1652 if (hostapd_setup_interface(hapd_iface
)) {
1653 hostapd_deinit_driver(hapd_iface
->bss
[0]->driver
,
1654 hapd_iface
->bss
[0]->drv_priv
,
1663 int hostapd_reload_iface(struct hostapd_iface
*hapd_iface
)
1667 wpa_printf(MSG_DEBUG
, "Reload interface %s",
1668 hapd_iface
->conf
->bss
[0]->iface
);
1669 for (j
= 0; j
< hapd_iface
->num_bss
; j
++)
1670 hostapd_set_security_params(hapd_iface
->conf
->bss
[j
]);
1671 if (hostapd_config_check(hapd_iface
->conf
, 1) < 0) {
1672 wpa_printf(MSG_ERROR
, "Updated configuration is invalid");
1675 hostapd_clear_old(hapd_iface
);
1676 for (j
= 0; j
< hapd_iface
->num_bss
; j
++)
1677 hostapd_reload_bss(hapd_iface
->bss
[j
]);
1683 int hostapd_disable_iface(struct hostapd_iface
*hapd_iface
)
1686 const struct wpa_driver_ops
*driver
;
1689 if (hapd_iface
== NULL
)
1691 wpa_msg(hapd_iface
->bss
[0]->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
1692 driver
= hapd_iface
->bss
[0]->driver
;
1693 drv_priv
= hapd_iface
->bss
[0]->drv_priv
;
1695 hapd_iface
->driver_ap_teardown
=
1696 !!(hapd_iface
->drv_flags
&
1697 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT
);
1699 /* same as hostapd_interface_deinit without deinitializing ctrl-iface */
1700 for (j
= 0; j
< hapd_iface
->num_bss
; j
++) {
1701 struct hostapd_data
*hapd
= hapd_iface
->bss
[j
];
1702 hostapd_free_stas(hapd
);
1703 hostapd_flush_old_stations(hapd
, WLAN_REASON_DEAUTH_LEAVING
);
1704 hostapd_clear_wep(hapd
);
1705 hostapd_free_hapd_data(hapd
);
1708 hostapd_deinit_driver(driver
, drv_priv
, hapd_iface
);
1710 /* From hostapd_cleanup_iface: These were initialized in
1711 * hostapd_setup_interface and hostapd_setup_interface_complete
1713 hostapd_cleanup_iface_partial(hapd_iface
);
1715 wpa_printf(MSG_DEBUG
, "Interface %s disabled",
1716 hapd_iface
->bss
[0]->conf
->iface
);
1717 hostapd_set_state(hapd_iface
, HAPD_IFACE_DISABLED
);
1722 static struct hostapd_iface
*
1723 hostapd_iface_alloc(struct hapd_interfaces
*interfaces
)
1725 struct hostapd_iface
**iface
, *hapd_iface
;
1727 iface
= os_realloc_array(interfaces
->iface
, interfaces
->count
+ 1,
1728 sizeof(struct hostapd_iface
*));
1731 interfaces
->iface
= iface
;
1732 hapd_iface
= interfaces
->iface
[interfaces
->count
] =
1733 os_zalloc(sizeof(*hapd_iface
));
1734 if (hapd_iface
== NULL
) {
1735 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory for "
1736 "the interface", __func__
);
1739 interfaces
->count
++;
1740 hapd_iface
->interfaces
= interfaces
;
1746 static struct hostapd_config
*
1747 hostapd_config_alloc(struct hapd_interfaces
*interfaces
, const char *ifname
,
1748 const char *ctrl_iface
)
1750 struct hostapd_bss_config
*bss
;
1751 struct hostapd_config
*conf
;
1753 /* Allocates memory for bss and conf */
1754 conf
= hostapd_config_defaults();
1756 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory for "
1757 "configuration", __func__
);
1761 conf
->driver
= wpa_drivers
[0];
1762 if (conf
->driver
== NULL
) {
1763 wpa_printf(MSG_ERROR
, "No driver wrappers registered!");
1764 hostapd_config_free(conf
);
1768 bss
= conf
->last_bss
= conf
->bss
[0];
1770 os_strlcpy(bss
->iface
, ifname
, sizeof(bss
->iface
));
1771 bss
->ctrl_interface
= os_strdup(ctrl_iface
);
1772 if (bss
->ctrl_interface
== NULL
) {
1773 hostapd_config_free(conf
);
1777 /* Reading configuration file skipped, will be done in SET!
1778 * From reading the configuration till the end has to be done in
1785 static struct hostapd_iface
* hostapd_data_alloc(
1786 struct hapd_interfaces
*interfaces
, struct hostapd_config
*conf
)
1789 struct hostapd_iface
*hapd_iface
=
1790 interfaces
->iface
[interfaces
->count
- 1];
1791 struct hostapd_data
*hapd
;
1793 hapd_iface
->conf
= conf
;
1794 hapd_iface
->num_bss
= conf
->num_bss
;
1796 hapd_iface
->bss
= os_zalloc(conf
->num_bss
*
1797 sizeof(struct hostapd_data
*));
1798 if (hapd_iface
->bss
== NULL
)
1801 for (i
= 0; i
< conf
->num_bss
; i
++) {
1802 hapd
= hapd_iface
->bss
[i
] =
1803 hostapd_alloc_bss_data(hapd_iface
, conf
, conf
->bss
[i
]);
1806 hapd
->msg_ctx
= hapd
;
1809 hapd_iface
->interfaces
= interfaces
;
1815 int hostapd_add_iface(struct hapd_interfaces
*interfaces
, char *buf
)
1817 struct hostapd_config
*conf
= NULL
;
1818 struct hostapd_iface
*hapd_iface
= NULL
, *new_iface
= NULL
;
1819 struct hostapd_data
*hapd
;
1822 const char *conf_file
= NULL
, *phy_name
= NULL
;
1824 if (os_strncmp(buf
, "bss_config=", 11) == 0) {
1826 phy_name
= buf
+ 11;
1827 pos
= os_strchr(phy_name
, ':');
1832 if (!os_strlen(conf_file
))
1835 hapd_iface
= hostapd_interface_init_bss(interfaces
, phy_name
,
1839 for (j
= 0; j
< interfaces
->count
; j
++) {
1840 if (interfaces
->iface
[j
] == hapd_iface
)
1843 if (j
== interfaces
->count
) {
1844 struct hostapd_iface
**tmp
;
1845 tmp
= os_realloc_array(interfaces
->iface
,
1846 interfaces
->count
+ 1,
1847 sizeof(struct hostapd_iface
*));
1849 hostapd_interface_deinit_free(hapd_iface
);
1852 interfaces
->iface
= tmp
;
1853 interfaces
->iface
[interfaces
->count
++] = hapd_iface
;
1854 new_iface
= hapd_iface
;
1858 if (interfaces
->driver_init(hapd_iface
) ||
1859 hostapd_setup_interface(hapd_iface
)) {
1860 interfaces
->count
--;
1864 /* Assign new BSS with bss[0]'s driver info */
1865 hapd
= hapd_iface
->bss
[hapd_iface
->num_bss
- 1];
1866 hapd
->driver
= hapd_iface
->bss
[0]->driver
;
1867 hapd
->drv_priv
= hapd_iface
->bss
[0]->drv_priv
;
1868 os_memcpy(hapd
->own_addr
, hapd_iface
->bss
[0]->own_addr
,
1871 if (start_ctrl_iface_bss(hapd
) < 0 ||
1872 (hapd_iface
->state
== HAPD_IFACE_ENABLED
&&
1873 hostapd_setup_bss(hapd
, -1))) {
1874 hostapd_cleanup(hapd
);
1875 hapd_iface
->bss
[hapd_iface
->num_bss
- 1] = NULL
;
1876 hapd_iface
->conf
->num_bss
--;
1877 hapd_iface
->num_bss
--;
1878 wpa_printf(MSG_DEBUG
, "%s: free hapd %p %s",
1879 __func__
, hapd
, hapd
->conf
->iface
);
1887 ptr
= os_strchr(buf
, ' ');
1892 if (os_strncmp(ptr
, "config=", 7) == 0)
1893 conf_file
= ptr
+ 7;
1895 for (i
= 0; i
< interfaces
->count
; i
++) {
1896 if (!os_strcmp(interfaces
->iface
[i
]->conf
->bss
[0]->iface
,
1898 wpa_printf(MSG_INFO
, "Cannot add interface - it "
1904 hapd_iface
= hostapd_iface_alloc(interfaces
);
1905 if (hapd_iface
== NULL
) {
1906 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory "
1907 "for interface", __func__
);
1911 if (conf_file
&& interfaces
->config_read_cb
) {
1912 conf
= interfaces
->config_read_cb(conf_file
);
1913 if (conf
&& conf
->bss
)
1914 os_strlcpy(conf
->bss
[0]->iface
, buf
,
1915 sizeof(conf
->bss
[0]->iface
));
1917 conf
= hostapd_config_alloc(interfaces
, buf
, ptr
);
1918 if (conf
== NULL
|| conf
->bss
== NULL
) {
1919 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory "
1920 "for configuration", __func__
);
1924 hapd_iface
= hostapd_data_alloc(interfaces
, conf
);
1925 if (hapd_iface
== NULL
) {
1926 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory "
1927 "for hostapd", __func__
);
1931 if (start_ctrl_iface(hapd_iface
) < 0)
1934 wpa_printf(MSG_INFO
, "Add interface '%s'", conf
->bss
[0]->iface
);
1940 hostapd_config_free(conf
);
1942 if (hapd_iface
->bss
) {
1943 for (i
= 0; i
< hapd_iface
->num_bss
; i
++) {
1944 hapd
= hapd_iface
->bss
[i
];
1947 if (hapd_iface
->interfaces
&&
1948 hapd_iface
->interfaces
->ctrl_iface_deinit
)
1949 hapd_iface
->interfaces
->
1950 ctrl_iface_deinit(hapd
);
1951 wpa_printf(MSG_DEBUG
, "%s: free hapd %p (%s)",
1952 __func__
, hapd_iface
->bss
[i
],
1955 hapd_iface
->bss
[i
] = NULL
;
1957 os_free(hapd_iface
->bss
);
1959 wpa_printf(MSG_DEBUG
, "%s: free iface %p",
1960 __func__
, hapd_iface
);
1961 os_free(hapd_iface
);
1967 static int hostapd_remove_bss(struct hostapd_iface
*iface
, unsigned int idx
)
1971 wpa_printf(MSG_INFO
, "Remove BSS '%s'", iface
->conf
->bss
[idx
]->iface
);
1973 /* Remove hostapd_data only if it has already been initialized */
1974 if (idx
< iface
->num_bss
) {
1975 struct hostapd_data
*hapd
= iface
->bss
[idx
];
1977 hostapd_bss_deinit(hapd
);
1978 wpa_printf(MSG_DEBUG
, "%s: free hapd %p (%s)",
1979 __func__
, hapd
, hapd
->conf
->iface
);
1980 hostapd_config_free_bss(hapd
->conf
);
1985 for (i
= idx
; i
< iface
->num_bss
; i
++)
1986 iface
->bss
[i
] = iface
->bss
[i
+ 1];
1988 hostapd_config_free_bss(iface
->conf
->bss
[idx
]);
1989 iface
->conf
->bss
[idx
] = NULL
;
1992 iface
->conf
->num_bss
--;
1993 for (i
= idx
; i
< iface
->conf
->num_bss
; i
++)
1994 iface
->conf
->bss
[i
] = iface
->conf
->bss
[i
+ 1];
2000 int hostapd_remove_iface(struct hapd_interfaces
*interfaces
, char *buf
)
2002 struct hostapd_iface
*hapd_iface
;
2005 for (i
= 0; i
< interfaces
->count
; i
++) {
2006 hapd_iface
= interfaces
->iface
[i
];
2007 if (hapd_iface
== NULL
)
2009 if (!os_strcmp(hapd_iface
->conf
->bss
[0]->iface
, buf
)) {
2010 wpa_printf(MSG_INFO
, "Remove interface '%s'", buf
);
2011 hapd_iface
->driver_ap_teardown
=
2012 !!(hapd_iface
->drv_flags
&
2013 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT
);
2015 hostapd_interface_deinit_free(hapd_iface
);
2017 while (k
< (interfaces
->count
- 1)) {
2018 interfaces
->iface
[k
] =
2019 interfaces
->iface
[k
+ 1];
2022 interfaces
->count
--;
2026 for (j
= 0; j
< hapd_iface
->conf
->num_bss
; j
++) {
2027 if (!os_strcmp(hapd_iface
->conf
->bss
[j
]->iface
, buf
)) {
2028 hapd_iface
->driver_ap_teardown
=
2029 !(hapd_iface
->drv_flags
&
2030 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT
);
2031 return hostapd_remove_bss(hapd_iface
, j
);
2040 * hostapd_new_assoc_sta - Notify that a new station associated with the AP
2041 * @hapd: Pointer to BSS data
2042 * @sta: Pointer to the associated STA data
2043 * @reassoc: 1 to indicate this was a re-association; 0 = first association
2045 * This function will be called whenever a station associates with the AP. It
2046 * can be called from ieee802_11.c for drivers that export MLME to hostapd and
2047 * from drv_callbacks.c based on driver events for drivers that take care of
2048 * management frames (IEEE 802.11 authentication and association) internally.
2050 void hostapd_new_assoc_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2053 if (hapd
->tkip_countermeasures
) {
2054 hostapd_drv_sta_deauth(hapd
, sta
->addr
,
2055 WLAN_REASON_MICHAEL_MIC_FAILURE
);
2059 hostapd_prune_associations(hapd
, sta
->addr
);
2061 /* IEEE 802.11F (IAPP) */
2062 if (hapd
->conf
->ieee802_11f
)
2063 iapp_new_station(hapd
->iapp
, sta
);
2066 if (sta
->p2p_ie
== NULL
&& !sta
->no_p2p_set
) {
2067 sta
->no_p2p_set
= 1;
2068 hapd
->num_sta_no_p2p
++;
2069 if (hapd
->num_sta_no_p2p
== 1)
2070 hostapd_p2p_non_p2p_sta_connected(hapd
);
2072 #endif /* CONFIG_P2P */
2074 /* Start accounting here, if IEEE 802.1X and WPA are not used.
2075 * IEEE 802.1X/WPA code will start accounting after the station has
2076 * been authorized. */
2077 if (!hapd
->conf
->ieee802_1x
&& !hapd
->conf
->wpa
&& !hapd
->conf
->osen
) {
2078 ap_sta_set_authorized(hapd
, sta
, 1);
2079 os_get_reltime(&sta
->connected_time
);
2080 accounting_sta_start(hapd
, sta
);
2083 /* Start IEEE 802.1X authentication process for new stations */
2084 ieee802_1x_new_station(hapd
, sta
);
2086 if (sta
->auth_alg
!= WLAN_AUTH_FT
&&
2087 !(sta
->flags
& (WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
)))
2088 wpa_auth_sm_event(sta
->wpa_sm
, WPA_REAUTH
);
2090 wpa_auth_sta_associated(hapd
->wpa_auth
, sta
->wpa_sm
);
2092 if (!(hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_INACTIVITY_TIMER
)) {
2093 wpa_printf(MSG_DEBUG
, "%s: reschedule ap_handle_timer timeout "
2094 "for " MACSTR
" (%d seconds - ap_max_inactivity)",
2095 __func__
, MAC2STR(sta
->addr
),
2096 hapd
->conf
->ap_max_inactivity
);
2097 eloop_cancel_timeout(ap_handle_timer
, hapd
, sta
);
2098 eloop_register_timeout(hapd
->conf
->ap_max_inactivity
, 0,
2099 ap_handle_timer
, hapd
, sta
);
2104 const char * hostapd_state_text(enum hostapd_iface_state s
)
2107 case HAPD_IFACE_UNINITIALIZED
:
2108 return "UNINITIALIZED";
2109 case HAPD_IFACE_DISABLED
:
2111 case HAPD_IFACE_COUNTRY_UPDATE
:
2112 return "COUNTRY_UPDATE";
2113 case HAPD_IFACE_ACS
:
2115 case HAPD_IFACE_HT_SCAN
:
2117 case HAPD_IFACE_DFS
:
2119 case HAPD_IFACE_ENABLED
:
2127 void hostapd_set_state(struct hostapd_iface
*iface
, enum hostapd_iface_state s
)
2129 wpa_printf(MSG_INFO
, "%s: interface state %s->%s",
2130 iface
->conf
->bss
[0]->iface
, hostapd_state_text(iface
->state
),
2131 hostapd_state_text(s
));
2138 static void free_beacon_data(struct beacon_data
*beacon
)
2140 os_free(beacon
->head
);
2141 beacon
->head
= NULL
;
2142 os_free(beacon
->tail
);
2143 beacon
->tail
= NULL
;
2144 os_free(beacon
->probe_resp
);
2145 beacon
->probe_resp
= NULL
;
2146 os_free(beacon
->beacon_ies
);
2147 beacon
->beacon_ies
= NULL
;
2148 os_free(beacon
->proberesp_ies
);
2149 beacon
->proberesp_ies
= NULL
;
2150 os_free(beacon
->assocresp_ies
);
2151 beacon
->assocresp_ies
= NULL
;
2155 static int hostapd_build_beacon_data(struct hostapd_iface
*iface
,
2156 struct beacon_data
*beacon
)
2158 struct wpabuf
*beacon_extra
, *proberesp_extra
, *assocresp_extra
;
2159 struct wpa_driver_ap_params params
;
2161 struct hostapd_data
*hapd
= iface
->bss
[0];
2163 os_memset(beacon
, 0, sizeof(*beacon
));
2164 ret
= ieee802_11_build_ap_params(hapd
, ¶ms
);
2168 ret
= hostapd_build_ap_extra_ies(hapd
, &beacon_extra
,
2172 goto free_ap_params
;
2175 beacon
->head
= os_malloc(params
.head_len
);
2177 goto free_ap_extra_ies
;
2179 os_memcpy(beacon
->head
, params
.head
, params
.head_len
);
2180 beacon
->head_len
= params
.head_len
;
2182 beacon
->tail
= os_malloc(params
.tail_len
);
2186 os_memcpy(beacon
->tail
, params
.tail
, params
.tail_len
);
2187 beacon
->tail_len
= params
.tail_len
;
2189 if (params
.proberesp
!= NULL
) {
2190 beacon
->probe_resp
= os_malloc(params
.proberesp_len
);
2191 if (!beacon
->probe_resp
)
2194 os_memcpy(beacon
->probe_resp
, params
.proberesp
,
2195 params
.proberesp_len
);
2196 beacon
->probe_resp_len
= params
.proberesp_len
;
2199 /* copy the extra ies */
2201 beacon
->beacon_ies
= os_malloc(wpabuf_len(beacon_extra
));
2202 if (!beacon
->beacon_ies
)
2205 os_memcpy(beacon
->beacon_ies
,
2206 beacon_extra
->buf
, wpabuf_len(beacon_extra
));
2207 beacon
->beacon_ies_len
= wpabuf_len(beacon_extra
);
2210 if (proberesp_extra
) {
2211 beacon
->proberesp_ies
=
2212 os_malloc(wpabuf_len(proberesp_extra
));
2213 if (!beacon
->proberesp_ies
)
2216 os_memcpy(beacon
->proberesp_ies
, proberesp_extra
->buf
,
2217 wpabuf_len(proberesp_extra
));
2218 beacon
->proberesp_ies_len
= wpabuf_len(proberesp_extra
);
2221 if (assocresp_extra
) {
2222 beacon
->assocresp_ies
=
2223 os_malloc(wpabuf_len(assocresp_extra
));
2224 if (!beacon
->assocresp_ies
)
2227 os_memcpy(beacon
->assocresp_ies
, assocresp_extra
->buf
,
2228 wpabuf_len(assocresp_extra
));
2229 beacon
->assocresp_ies_len
= wpabuf_len(assocresp_extra
);
2234 /* if the function fails, the caller should not free beacon data */
2236 free_beacon_data(beacon
);
2239 hostapd_free_ap_extra_ies(hapd
, beacon_extra
, proberesp_extra
,
2242 ieee802_11_free_ap_params(¶ms
);
2248 * TODO: This flow currently supports only changing frequency within the
2249 * same hw_mode. Any other changes to MAC parameters or provided settings (even
2250 * width) are not supported.
2252 static int hostapd_change_config_freq(struct hostapd_data
*hapd
,
2253 struct hostapd_config
*conf
,
2254 struct hostapd_freq_params
*params
,
2255 struct hostapd_freq_params
*old_params
)
2259 if (!params
->channel
) {
2260 /* check if the new channel is supported by hw */
2261 channel
= hostapd_hw_get_channel(hapd
, params
->freq
);
2265 channel
= params
->channel
;
2268 /* if a pointer to old_params is provided we save previous state */
2270 old_params
->channel
= conf
->channel
;
2271 old_params
->ht_enabled
= conf
->ieee80211n
;
2272 old_params
->sec_channel_offset
= conf
->secondary_channel
;
2275 conf
->channel
= channel
;
2276 conf
->ieee80211n
= params
->ht_enabled
;
2277 conf
->secondary_channel
= params
->sec_channel_offset
;
2279 /* TODO: maybe call here hostapd_config_check here? */
2285 static int hostapd_fill_csa_settings(struct hostapd_iface
*iface
,
2286 struct csa_settings
*settings
)
2288 struct hostapd_freq_params old_freq
;
2291 os_memset(&old_freq
, 0, sizeof(old_freq
));
2292 if (!iface
|| !iface
->freq
|| iface
->csa_in_progress
)
2295 ret
= hostapd_change_config_freq(iface
->bss
[0], iface
->conf
,
2296 &settings
->freq_params
,
2301 ret
= hostapd_build_beacon_data(iface
, &settings
->beacon_after
);
2303 /* change back the configuration */
2304 hostapd_change_config_freq(iface
->bss
[0], iface
->conf
,
2310 /* set channel switch parameters for csa ie */
2311 iface
->cs_freq_params
= settings
->freq_params
;
2312 iface
->cs_count
= settings
->cs_count
;
2313 iface
->cs_block_tx
= settings
->block_tx
;
2315 ret
= hostapd_build_beacon_data(iface
, &settings
->beacon_csa
);
2317 free_beacon_data(&settings
->beacon_after
);
2321 settings
->counter_offset_beacon
= iface
->cs_c_off_beacon
;
2322 settings
->counter_offset_presp
= iface
->cs_c_off_proberesp
;
2328 void hostapd_cleanup_cs_params(struct hostapd_data
*hapd
)
2330 os_memset(&hapd
->iface
->cs_freq_params
, 0,
2331 sizeof(hapd
->iface
->cs_freq_params
));
2332 hapd
->iface
->cs_count
= 0;
2333 hapd
->iface
->cs_block_tx
= 0;
2334 hapd
->iface
->cs_c_off_beacon
= 0;
2335 hapd
->iface
->cs_c_off_proberesp
= 0;
2336 hapd
->iface
->csa_in_progress
= 0;
2340 int hostapd_switch_channel(struct hostapd_data
*hapd
,
2341 struct csa_settings
*settings
)
2344 ret
= hostapd_fill_csa_settings(hapd
->iface
, settings
);
2348 ret
= hostapd_drv_switch_channel(hapd
, settings
);
2349 free_beacon_data(&settings
->beacon_csa
);
2350 free_beacon_data(&settings
->beacon_after
);
2353 /* if we failed, clean cs parameters */
2354 hostapd_cleanup_cs_params(hapd
);
2358 hapd
->iface
->csa_in_progress
= 1;
2362 #endif /* NEED_AP_MLME */