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"
20 #include "accounting.h"
24 #include "ieee802_1x.h"
25 #include "ieee802_11_auth.h"
26 #include "vlan_init.h"
28 #include "wps_hostapd.h"
29 #include "hw_features.h"
30 #include "wpa_auth_glue.h"
31 #include "ap_drv_ops.h"
32 #include "ap_config.h"
33 #include "p2p_hostapd.h"
38 static int hostapd_flush_old_stations(struct hostapd_data
*hapd
, u16 reason
);
39 static int hostapd_setup_encryption(char *iface
, struct hostapd_data
*hapd
);
40 static int hostapd_broadcast_wep_clear(struct hostapd_data
*hapd
);
41 static int setup_interface2(struct hostapd_iface
*iface
);
42 static void channel_list_update_timeout(void *eloop_ctx
, void *timeout_ctx
);
45 int hostapd_for_each_interface(struct hapd_interfaces
*interfaces
,
46 int (*cb
)(struct hostapd_iface
*iface
,
47 void *ctx
), void *ctx
)
52 for (i
= 0; i
< interfaces
->count
; i
++) {
53 ret
= cb(interfaces
->iface
[i
], ctx
);
62 static void hostapd_reload_bss(struct hostapd_data
*hapd
)
64 struct hostapd_ssid
*ssid
;
66 #ifndef CONFIG_NO_RADIUS
67 radius_client_reconfig(hapd
->radius
, hapd
->conf
->radius
);
68 #endif /* CONFIG_NO_RADIUS */
70 ssid
= &hapd
->conf
->ssid
;
71 if (!ssid
->wpa_psk_set
&& ssid
->wpa_psk
&& !ssid
->wpa_psk
->next
&&
72 ssid
->wpa_passphrase_set
&& ssid
->wpa_passphrase
) {
74 * Force PSK to be derived again since SSID or passphrase may
77 os_free(ssid
->wpa_psk
);
80 if (hostapd_setup_wpa_psk(hapd
->conf
)) {
81 wpa_printf(MSG_ERROR
, "Failed to re-configure WPA PSK "
82 "after reloading configuration");
85 if (hapd
->conf
->ieee802_1x
|| hapd
->conf
->wpa
)
86 hostapd_set_drv_ieee8021x(hapd
, hapd
->conf
->iface
, 1);
88 hostapd_set_drv_ieee8021x(hapd
, hapd
->conf
->iface
, 0);
90 if ((hapd
->conf
->wpa
|| hapd
->conf
->osen
) && hapd
->wpa_auth
== NULL
) {
91 hostapd_setup_wpa(hapd
);
93 wpa_init_keys(hapd
->wpa_auth
);
94 } else if (hapd
->conf
->wpa
) {
97 hostapd_reconfig_wpa(hapd
);
98 wpa_ie
= wpa_auth_get_wpa_ie(hapd
->wpa_auth
, &wpa_ie_len
);
99 if (hostapd_set_generic_elem(hapd
, wpa_ie
, wpa_ie_len
))
100 wpa_printf(MSG_ERROR
, "Failed to configure WPA IE for "
101 "the kernel driver.");
102 } else if (hapd
->wpa_auth
) {
103 wpa_deinit(hapd
->wpa_auth
);
104 hapd
->wpa_auth
= NULL
;
105 hostapd_set_privacy(hapd
, 0);
106 hostapd_setup_encryption(hapd
->conf
->iface
, hapd
);
107 hostapd_set_generic_elem(hapd
, (u8
*) "", 0);
110 ieee802_11_set_beacon(hapd
);
111 hostapd_update_wps(hapd
);
113 if (hapd
->conf
->ssid
.ssid_set
&&
114 hostapd_set_ssid(hapd
, hapd
->conf
->ssid
.ssid
,
115 hapd
->conf
->ssid
.ssid_len
)) {
116 wpa_printf(MSG_ERROR
, "Could not set SSID for kernel driver");
117 /* try to continue */
119 wpa_printf(MSG_DEBUG
, "Reconfigured interface %s", hapd
->conf
->iface
);
123 static void hostapd_clear_old(struct hostapd_iface
*iface
)
128 * Deauthenticate all stations since the new configuration may not
129 * allow them to use the BSS anymore.
131 for (j
= 0; j
< iface
->num_bss
; j
++) {
132 hostapd_flush_old_stations(iface
->bss
[j
],
133 WLAN_REASON_PREV_AUTH_NOT_VALID
);
134 hostapd_broadcast_wep_clear(iface
->bss
[j
]);
136 #ifndef CONFIG_NO_RADIUS
137 /* TODO: update dynamic data based on changed configuration
138 * items (e.g., open/close sockets, etc.) */
139 radius_client_flush(iface
->bss
[j
]->radius
, 0);
140 #endif /* CONFIG_NO_RADIUS */
145 int hostapd_reload_config(struct hostapd_iface
*iface
)
147 struct hostapd_data
*hapd
= iface
->bss
[0];
148 struct hostapd_config
*newconf
, *oldconf
;
151 if (iface
->config_fname
== NULL
) {
152 /* Only in-memory config in use - assume it has been updated */
153 hostapd_clear_old(iface
);
154 for (j
= 0; j
< iface
->num_bss
; j
++)
155 hostapd_reload_bss(iface
->bss
[j
]);
159 if (iface
->interfaces
== NULL
||
160 iface
->interfaces
->config_read_cb
== NULL
)
162 newconf
= iface
->interfaces
->config_read_cb(iface
->config_fname
);
166 hostapd_clear_old(iface
);
168 oldconf
= hapd
->iconf
;
169 iface
->conf
= newconf
;
171 for (j
= 0; j
< iface
->num_bss
; j
++) {
172 hapd
= iface
->bss
[j
];
173 hapd
->iconf
= newconf
;
174 hapd
->iconf
->channel
= oldconf
->channel
;
175 hapd
->iconf
->ieee80211n
= oldconf
->ieee80211n
;
176 hapd
->iconf
->ieee80211ac
= oldconf
->ieee80211ac
;
177 hapd
->iconf
->ht_capab
= oldconf
->ht_capab
;
178 hapd
->iconf
->vht_capab
= oldconf
->vht_capab
;
179 hapd
->iconf
->vht_oper_chwidth
= oldconf
->vht_oper_chwidth
;
180 hapd
->iconf
->vht_oper_centr_freq_seg0_idx
=
181 oldconf
->vht_oper_centr_freq_seg0_idx
;
182 hapd
->iconf
->vht_oper_centr_freq_seg1_idx
=
183 oldconf
->vht_oper_centr_freq_seg1_idx
;
184 hapd
->conf
= newconf
->bss
[j
];
185 hostapd_reload_bss(hapd
);
188 hostapd_config_free(oldconf
);
195 static void hostapd_broadcast_key_clear_iface(struct hostapd_data
*hapd
,
200 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
201 if (hostapd_drv_set_key(ifname
, hapd
, WPA_ALG_NONE
, NULL
, i
,
202 0, NULL
, 0, NULL
, 0)) {
203 wpa_printf(MSG_DEBUG
, "Failed to clear default "
204 "encryption keys (ifname=%s keyidx=%d)",
208 #ifdef CONFIG_IEEE80211W
209 if (hapd
->conf
->ieee80211w
) {
210 for (i
= NUM_WEP_KEYS
; i
< NUM_WEP_KEYS
+ 2; i
++) {
211 if (hostapd_drv_set_key(ifname
, hapd
, WPA_ALG_NONE
,
214 wpa_printf(MSG_DEBUG
, "Failed to clear "
215 "default mgmt encryption keys "
216 "(ifname=%s keyidx=%d)", ifname
, i
);
220 #endif /* CONFIG_IEEE80211W */
224 static int hostapd_broadcast_wep_clear(struct hostapd_data
*hapd
)
226 hostapd_broadcast_key_clear_iface(hapd
, hapd
->conf
->iface
);
231 static int hostapd_broadcast_wep_set(struct hostapd_data
*hapd
)
234 struct hostapd_ssid
*ssid
= &hapd
->conf
->ssid
;
237 if (ssid
->wep
.default_len
&&
238 hostapd_drv_set_key(hapd
->conf
->iface
,
239 hapd
, WPA_ALG_WEP
, broadcast_ether_addr
, idx
,
240 1, NULL
, 0, ssid
->wep
.key
[idx
],
241 ssid
->wep
.len
[idx
])) {
242 wpa_printf(MSG_WARNING
, "Could not set WEP encryption.");
250 static void hostapd_free_hapd_data(struct hostapd_data
*hapd
)
252 if (!hapd
->started
) {
253 wpa_printf(MSG_ERROR
, "%s: Interface %s wasn't started",
254 __func__
, hapd
->conf
->iface
);
259 wpa_printf(MSG_DEBUG
, "%s(%s)", __func__
, hapd
->conf
->iface
);
260 iapp_deinit(hapd
->iapp
);
262 accounting_deinit(hapd
);
263 hostapd_deinit_wpa(hapd
);
265 hostapd_acl_deinit(hapd
);
266 #ifndef CONFIG_NO_RADIUS
267 radius_client_deinit(hapd
->radius
);
269 radius_das_deinit(hapd
->radius_das
);
270 hapd
->radius_das
= NULL
;
271 #endif /* CONFIG_NO_RADIUS */
273 hostapd_deinit_wps(hapd
);
275 authsrv_deinit(hapd
);
277 if (hapd
->interface_added
&&
278 hostapd_if_remove(hapd
, WPA_IF_AP_BSS
, hapd
->conf
->iface
)) {
279 wpa_printf(MSG_WARNING
, "Failed to remove BSS interface %s",
283 os_free(hapd
->probereq_cb
);
284 hapd
->probereq_cb
= NULL
;
287 wpabuf_free(hapd
->p2p_beacon_ie
);
288 hapd
->p2p_beacon_ie
= NULL
;
289 wpabuf_free(hapd
->p2p_probe_resp_ie
);
290 hapd
->p2p_probe_resp_ie
= NULL
;
291 #endif /* CONFIG_P2P */
293 wpabuf_free(hapd
->time_adv
);
295 #ifdef CONFIG_INTERWORKING
296 gas_serv_deinit(hapd
);
297 #endif /* CONFIG_INTERWORKING */
300 os_free(hapd
->tmp_eap_user
.identity
);
301 os_free(hapd
->tmp_eap_user
.password
);
302 #endif /* CONFIG_SQLITE */
307 * hostapd_cleanup - Per-BSS cleanup (deinitialization)
308 * @hapd: Pointer to BSS data
310 * This function is used to free all per-BSS data structures and resources.
311 * Most of the modules that are initialized in hostapd_setup_bss() are
312 * deinitialized here.
314 static void hostapd_cleanup(struct hostapd_data
*hapd
)
316 wpa_printf(MSG_DEBUG
, "%s(hapd=%p (%s))", __func__
, hapd
,
318 if (hapd
->iface
->interfaces
&&
319 hapd
->iface
->interfaces
->ctrl_iface_deinit
)
320 hapd
->iface
->interfaces
->ctrl_iface_deinit(hapd
);
321 hostapd_free_hapd_data(hapd
);
325 static void hostapd_cleanup_iface_partial(struct hostapd_iface
*iface
)
327 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
328 hostapd_free_hw_features(iface
->hw_features
, iface
->num_hw_features
);
329 iface
->hw_features
= NULL
;
330 os_free(iface
->current_rates
);
331 iface
->current_rates
= NULL
;
332 os_free(iface
->basic_rates
);
333 iface
->basic_rates
= NULL
;
334 ap_list_deinit(iface
);
339 * hostapd_cleanup_iface - Complete per-interface cleanup
340 * @iface: Pointer to interface data
342 * This function is called after per-BSS data structures are deinitialized
343 * with hostapd_cleanup().
345 static void hostapd_cleanup_iface(struct hostapd_iface
*iface
)
347 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
348 eloop_cancel_timeout(channel_list_update_timeout
, iface
, NULL
);
350 hostapd_cleanup_iface_partial(iface
);
351 hostapd_config_free(iface
->conf
);
354 os_free(iface
->config_fname
);
356 wpa_printf(MSG_DEBUG
, "%s: free iface=%p", __func__
, iface
);
361 static void hostapd_clear_wep(struct hostapd_data
*hapd
)
363 if (hapd
->drv_priv
&& !hapd
->iface
->driver_ap_teardown
) {
364 hostapd_set_privacy(hapd
, 0);
365 hostapd_broadcast_wep_clear(hapd
);
370 static int hostapd_setup_encryption(char *iface
, struct hostapd_data
*hapd
)
374 hostapd_broadcast_wep_set(hapd
);
376 if (hapd
->conf
->ssid
.wep
.default_len
) {
377 hostapd_set_privacy(hapd
, 1);
382 * When IEEE 802.1X is not enabled, the driver may need to know how to
383 * set authentication algorithms for static WEP.
385 hostapd_drv_set_authmode(hapd
, hapd
->conf
->auth_algs
);
387 for (i
= 0; i
< 4; i
++) {
388 if (hapd
->conf
->ssid
.wep
.key
[i
] &&
389 hostapd_drv_set_key(iface
, hapd
, WPA_ALG_WEP
, NULL
, i
,
390 i
== hapd
->conf
->ssid
.wep
.idx
, NULL
, 0,
391 hapd
->conf
->ssid
.wep
.key
[i
],
392 hapd
->conf
->ssid
.wep
.len
[i
])) {
393 wpa_printf(MSG_WARNING
, "Could not set WEP "
397 if (hapd
->conf
->ssid
.wep
.key
[i
] &&
398 i
== hapd
->conf
->ssid
.wep
.idx
)
399 hostapd_set_privacy(hapd
, 1);
406 static int hostapd_flush_old_stations(struct hostapd_data
*hapd
, u16 reason
)
411 if (hostapd_drv_none(hapd
) || hapd
->drv_priv
== NULL
)
414 if (!hapd
->iface
->driver_ap_teardown
) {
415 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
,
416 "Flushing old station entries");
418 if (hostapd_flush(hapd
)) {
419 wpa_msg(hapd
->msg_ctx
, MSG_WARNING
,
420 "Could not connect to kernel driver");
424 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "Deauthenticate all stations");
425 os_memset(addr
, 0xff, ETH_ALEN
);
426 hostapd_drv_sta_deauth(hapd
, addr
, reason
);
427 hostapd_free_stas(hapd
);
434 * hostapd_validate_bssid_configuration - Validate BSSID configuration
435 * @iface: Pointer to interface data
436 * Returns: 0 on success, -1 on failure
438 * This function is used to validate that the configured BSSIDs are valid.
440 static int hostapd_validate_bssid_configuration(struct hostapd_iface
*iface
)
442 u8 mask
[ETH_ALEN
] = { 0 };
443 struct hostapd_data
*hapd
= iface
->bss
[0];
444 unsigned int i
= iface
->conf
->num_bss
, bits
= 0, j
;
447 if (hostapd_drv_none(hapd
))
450 /* Generate BSSID mask that is large enough to cover the BSSIDs. */
452 /* Determine the bits necessary to cover the number of BSSIDs. */
453 for (i
--; i
; i
>>= 1)
456 /* Determine the bits necessary to any configured BSSIDs,
457 if they are higher than the number of BSSIDs. */
458 for (j
= 0; j
< iface
->conf
->num_bss
; j
++) {
459 if (hostapd_mac_comp_empty(iface
->conf
->bss
[j
]->bssid
) == 0) {
465 for (i
= 0; i
< ETH_ALEN
; i
++) {
467 iface
->conf
->bss
[j
]->bssid
[i
] ^
475 for (i
= 0; i
< ETH_ALEN
&& mask
[i
] == 0; i
++)
481 while (mask
[i
] != 0) {
491 wpa_printf(MSG_ERROR
, "Too many bits in the BSSID mask (%u)",
496 os_memset(mask
, 0xff, ETH_ALEN
);
498 for (i
= 5; i
> 5 - j
; i
--)
505 wpa_printf(MSG_DEBUG
, "BSS count %lu, BSSID mask " MACSTR
" (%d bits)",
506 (unsigned long) iface
->conf
->num_bss
, MAC2STR(mask
), bits
);
511 for (i
= 0; i
< ETH_ALEN
; i
++) {
512 if ((hapd
->own_addr
[i
] & mask
[i
]) != hapd
->own_addr
[i
]) {
513 wpa_printf(MSG_ERROR
, "Invalid BSSID mask " MACSTR
514 " for start address " MACSTR
".",
515 MAC2STR(mask
), MAC2STR(hapd
->own_addr
));
516 wpa_printf(MSG_ERROR
, "Start address must be the "
517 "first address in the block (i.e., addr "
518 "AND mask == addr).");
527 static int mac_in_conf(struct hostapd_config
*conf
, const void *a
)
531 for (i
= 0; i
< conf
->num_bss
; i
++) {
532 if (hostapd_mac_comp(conf
->bss
[i
]->bssid
, a
) == 0) {
541 #ifndef CONFIG_NO_RADIUS
543 static int hostapd_das_nas_mismatch(struct hostapd_data
*hapd
,
544 struct radius_das_attrs
*attr
)
546 if (attr
->nas_identifier
&&
547 (!hapd
->conf
->nas_identifier
||
548 os_strlen(hapd
->conf
->nas_identifier
) !=
549 attr
->nas_identifier_len
||
550 os_memcmp(hapd
->conf
->nas_identifier
, attr
->nas_identifier
,
551 attr
->nas_identifier_len
) != 0)) {
552 wpa_printf(MSG_DEBUG
, "RADIUS DAS: NAS-Identifier mismatch");
556 if (attr
->nas_ip_addr
&&
557 (hapd
->conf
->own_ip_addr
.af
!= AF_INET
||
558 os_memcmp(&hapd
->conf
->own_ip_addr
.u
.v4
, attr
->nas_ip_addr
, 4) !=
560 wpa_printf(MSG_DEBUG
, "RADIUS DAS: NAS-IP-Address mismatch");
565 if (attr
->nas_ipv6_addr
&&
566 (hapd
->conf
->own_ip_addr
.af
!= AF_INET6
||
567 os_memcmp(&hapd
->conf
->own_ip_addr
.u
.v6
, attr
->nas_ipv6_addr
, 16)
569 wpa_printf(MSG_DEBUG
, "RADIUS DAS: NAS-IPv6-Address mismatch");
572 #endif /* CONFIG_IPV6 */
578 static struct sta_info
* hostapd_das_find_sta(struct hostapd_data
*hapd
,
579 struct radius_das_attrs
*attr
)
581 struct sta_info
*sta
= NULL
;
585 sta
= ap_get_sta(hapd
, attr
->sta_addr
);
587 if (sta
== NULL
&& attr
->acct_session_id
&&
588 attr
->acct_session_id_len
== 17) {
589 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
590 os_snprintf(buf
, sizeof(buf
), "%08X-%08X",
591 sta
->acct_session_id_hi
,
592 sta
->acct_session_id_lo
);
593 if (os_memcmp(attr
->acct_session_id
, buf
, 17) == 0)
598 if (sta
== NULL
&& attr
->cui
) {
599 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
601 cui
= ieee802_1x_get_radius_cui(sta
->eapol_sm
);
602 if (cui
&& wpabuf_len(cui
) == attr
->cui_len
&&
603 os_memcmp(wpabuf_head(cui
), attr
->cui
,
609 if (sta
== NULL
&& attr
->user_name
) {
610 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
613 identity
= ieee802_1x_get_identity(sta
->eapol_sm
,
616 identity_len
== attr
->user_name_len
&&
617 os_memcmp(identity
, attr
->user_name
, identity_len
)
627 static enum radius_das_res
628 hostapd_das_disconnect(void *ctx
, struct radius_das_attrs
*attr
)
630 struct hostapd_data
*hapd
= ctx
;
631 struct sta_info
*sta
;
633 if (hostapd_das_nas_mismatch(hapd
, attr
))
634 return RADIUS_DAS_NAS_MISMATCH
;
636 sta
= hostapd_das_find_sta(hapd
, attr
);
638 return RADIUS_DAS_SESSION_NOT_FOUND
;
640 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
642 hostapd_drv_sta_deauth(hapd
, sta
->addr
,
643 WLAN_REASON_PREV_AUTH_NOT_VALID
);
644 ap_sta_deauthenticate(hapd
, sta
, WLAN_REASON_PREV_AUTH_NOT_VALID
);
646 return RADIUS_DAS_SUCCESS
;
649 #endif /* CONFIG_NO_RADIUS */
653 * hostapd_setup_bss - Per-BSS setup (initialization)
654 * @hapd: Pointer to BSS data
655 * @first: Whether this BSS is the first BSS of an interface; -1 = not first,
656 * but interface may exist
658 * This function is used to initialize all per-BSS data structures and
659 * resources. This gets called in a loop for each BSS when an interface is
660 * initialized. Most of the modules that are initialized here will be
661 * deinitialized in hostapd_cleanup().
663 static int hostapd_setup_bss(struct hostapd_data
*hapd
, int first
)
665 struct hostapd_bss_config
*conf
= hapd
->conf
;
666 u8 ssid
[HOSTAPD_MAX_SSID_LEN
+ 1];
667 int ssid_len
, set_ssid
;
668 char force_ifname
[IFNAMSIZ
];
669 u8 if_addr
[ETH_ALEN
];
671 wpa_printf(MSG_DEBUG
, "%s(hapd=%p (%s), first=%d)",
672 __func__
, hapd
, hapd
->conf
->iface
, first
);
675 wpa_printf(MSG_ERROR
, "%s: Interface %s was already started",
676 __func__
, hapd
->conf
->iface
);
681 if (!first
|| first
== -1) {
682 if (hostapd_mac_comp_empty(hapd
->conf
->bssid
) == 0) {
683 /* Allocate the next available BSSID. */
685 inc_byte_array(hapd
->own_addr
, ETH_ALEN
);
686 } while (mac_in_conf(hapd
->iconf
, hapd
->own_addr
));
688 /* Allocate the configured BSSID. */
689 os_memcpy(hapd
->own_addr
, hapd
->conf
->bssid
, ETH_ALEN
);
691 if (hostapd_mac_comp(hapd
->own_addr
,
692 hapd
->iface
->bss
[0]->own_addr
) ==
694 wpa_printf(MSG_ERROR
, "BSS '%s' may not have "
695 "BSSID set to the MAC address of "
696 "the radio", hapd
->conf
->iface
);
701 hapd
->interface_added
= 1;
702 if (hostapd_if_add(hapd
->iface
->bss
[0], WPA_IF_AP_BSS
,
703 hapd
->conf
->iface
, hapd
->own_addr
, hapd
,
704 &hapd
->drv_priv
, force_ifname
, if_addr
,
705 hapd
->conf
->bridge
[0] ? hapd
->conf
->bridge
:
706 NULL
, first
== -1)) {
707 wpa_printf(MSG_ERROR
, "Failed to add BSS (BSSID="
708 MACSTR
")", MAC2STR(hapd
->own_addr
));
709 hapd
->interface_added
= 0;
714 if (conf
->wmm_enabled
< 0)
715 conf
->wmm_enabled
= hapd
->iconf
->ieee80211n
;
717 hostapd_flush_old_stations(hapd
, WLAN_REASON_PREV_AUTH_NOT_VALID
);
718 hostapd_set_privacy(hapd
, 0);
720 hostapd_broadcast_wep_clear(hapd
);
721 if (hostapd_setup_encryption(hapd
->conf
->iface
, hapd
))
725 * Fetch the SSID from the system and use it or,
726 * if one was specified in the config file, verify they
729 ssid_len
= hostapd_get_ssid(hapd
, ssid
, sizeof(ssid
));
731 wpa_printf(MSG_ERROR
, "Could not read SSID from system");
734 if (conf
->ssid
.ssid_set
) {
736 * If SSID is specified in the config file and it differs
737 * from what is being used then force installation of the
740 set_ssid
= (conf
->ssid
.ssid_len
!= (size_t) ssid_len
||
741 os_memcmp(conf
->ssid
.ssid
, ssid
, ssid_len
) != 0);
744 * No SSID in the config file; just use the one we got
748 conf
->ssid
.ssid_len
= ssid_len
;
749 os_memcpy(conf
->ssid
.ssid
, ssid
, conf
->ssid
.ssid_len
);
752 if (!hostapd_drv_none(hapd
)) {
753 wpa_printf(MSG_ERROR
, "Using interface %s with hwaddr " MACSTR
755 hapd
->conf
->iface
, MAC2STR(hapd
->own_addr
),
756 wpa_ssid_txt(hapd
->conf
->ssid
.ssid
,
757 hapd
->conf
->ssid
.ssid_len
));
760 if (hostapd_setup_wpa_psk(conf
)) {
761 wpa_printf(MSG_ERROR
, "WPA-PSK setup failed.");
765 /* Set SSID for the kernel driver (to be used in beacon and probe
766 * response frames) */
767 if (set_ssid
&& hostapd_set_ssid(hapd
, conf
->ssid
.ssid
,
768 conf
->ssid
.ssid_len
)) {
769 wpa_printf(MSG_ERROR
, "Could not set SSID for kernel driver");
773 if (wpa_debug_level
<= MSG_MSGDUMP
)
774 conf
->radius
->msg_dumps
= 1;
775 #ifndef CONFIG_NO_RADIUS
776 hapd
->radius
= radius_client_init(hapd
, conf
->radius
);
777 if (hapd
->radius
== NULL
) {
778 wpa_printf(MSG_ERROR
, "RADIUS client initialization failed.");
782 if (hapd
->conf
->radius_das_port
) {
783 struct radius_das_conf das_conf
;
784 os_memset(&das_conf
, 0, sizeof(das_conf
));
785 das_conf
.port
= hapd
->conf
->radius_das_port
;
786 das_conf
.shared_secret
= hapd
->conf
->radius_das_shared_secret
;
787 das_conf
.shared_secret_len
=
788 hapd
->conf
->radius_das_shared_secret_len
;
789 das_conf
.client_addr
= &hapd
->conf
->radius_das_client_addr
;
790 das_conf
.time_window
= hapd
->conf
->radius_das_time_window
;
791 das_conf
.require_event_timestamp
=
792 hapd
->conf
->radius_das_require_event_timestamp
;
794 das_conf
.disconnect
= hostapd_das_disconnect
;
795 hapd
->radius_das
= radius_das_init(&das_conf
);
796 if (hapd
->radius_das
== NULL
) {
797 wpa_printf(MSG_ERROR
, "RADIUS DAS initialization "
802 #endif /* CONFIG_NO_RADIUS */
804 if (hostapd_acl_init(hapd
)) {
805 wpa_printf(MSG_ERROR
, "ACL initialization failed.");
808 if (hostapd_init_wps(hapd
, conf
))
811 if (authsrv_init(hapd
) < 0)
814 if (ieee802_1x_init(hapd
)) {
815 wpa_printf(MSG_ERROR
, "IEEE 802.1X initialization failed.");
819 if ((hapd
->conf
->wpa
|| hapd
->conf
->osen
) && hostapd_setup_wpa(hapd
))
822 if (accounting_init(hapd
)) {
823 wpa_printf(MSG_ERROR
, "Accounting initialization failed.");
827 if (hapd
->conf
->ieee802_11f
&&
828 (hapd
->iapp
= iapp_init(hapd
, hapd
->conf
->iapp_iface
)) == NULL
) {
829 wpa_printf(MSG_ERROR
, "IEEE 802.11F (IAPP) initialization "
834 #ifdef CONFIG_INTERWORKING
835 if (gas_serv_init(hapd
)) {
836 wpa_printf(MSG_ERROR
, "GAS server initialization failed");
840 if (conf
->qos_map_set_len
&&
841 hostapd_drv_set_qos_map(hapd
, conf
->qos_map_set
,
842 conf
->qos_map_set_len
)) {
843 wpa_printf(MSG_ERROR
, "Failed to initialize QoS Map");
846 #endif /* CONFIG_INTERWORKING */
848 if (!hostapd_drv_none(hapd
) && vlan_init(hapd
)) {
849 wpa_printf(MSG_ERROR
, "VLAN initialization failed.");
853 if (!hapd
->conf
->start_disabled
&& ieee802_11_set_beacon(hapd
) < 0)
856 if (hapd
->wpa_auth
&& wpa_init_keys(hapd
->wpa_auth
) < 0)
859 if (hapd
->driver
&& hapd
->driver
->set_operstate
)
860 hapd
->driver
->set_operstate(hapd
->drv_priv
, 1);
866 static void hostapd_tx_queue_params(struct hostapd_iface
*iface
)
868 struct hostapd_data
*hapd
= iface
->bss
[0];
870 struct hostapd_tx_queue_params
*p
;
872 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
873 p
= &iface
->conf
->tx_queue
[i
];
875 if (hostapd_set_tx_queue_params(hapd
, i
, p
->aifs
, p
->cwmin
,
876 p
->cwmax
, p
->burst
)) {
877 wpa_printf(MSG_DEBUG
, "Failed to set TX queue "
878 "parameters for queue %d.", i
);
879 /* Continue anyway */
885 static int hostapd_set_acl_list(struct hostapd_data
*hapd
,
886 struct mac_acl_entry
*mac_acl
,
887 int n_entries
, u8 accept_acl
)
889 struct hostapd_acl_params
*acl_params
;
892 acl_params
= os_zalloc(sizeof(*acl_params
) +
893 (n_entries
* sizeof(acl_params
->mac_acl
[0])));
897 for (i
= 0; i
< n_entries
; i
++)
898 os_memcpy(acl_params
->mac_acl
[i
].addr
, mac_acl
[i
].addr
,
901 acl_params
->acl_policy
= accept_acl
;
902 acl_params
->num_mac_acl
= n_entries
;
904 err
= hostapd_drv_set_acl(hapd
, acl_params
);
912 static void hostapd_set_acl(struct hostapd_data
*hapd
)
914 struct hostapd_config
*conf
= hapd
->iconf
;
918 if (hapd
->iface
->drv_max_acl_mac_addrs
== 0)
920 if (!(conf
->bss
[0]->num_accept_mac
|| conf
->bss
[0]->num_deny_mac
))
923 if (conf
->bss
[0]->macaddr_acl
== DENY_UNLESS_ACCEPTED
) {
924 if (conf
->bss
[0]->num_accept_mac
) {
926 err
= hostapd_set_acl_list(hapd
,
927 conf
->bss
[0]->accept_mac
,
928 conf
->bss
[0]->num_accept_mac
,
931 wpa_printf(MSG_DEBUG
, "Failed to set accept acl");
935 wpa_printf(MSG_DEBUG
, "Mismatch between ACL Policy & Accept/deny lists file");
937 } else if (conf
->bss
[0]->macaddr_acl
== ACCEPT_UNLESS_DENIED
) {
938 if (conf
->bss
[0]->num_deny_mac
) {
940 err
= hostapd_set_acl_list(hapd
, conf
->bss
[0]->deny_mac
,
941 conf
->bss
[0]->num_deny_mac
,
944 wpa_printf(MSG_DEBUG
, "Failed to set deny acl");
948 wpa_printf(MSG_DEBUG
, "Mismatch between ACL Policy & Accept/deny lists file");
954 static int start_ctrl_iface_bss(struct hostapd_data
*hapd
)
956 if (!hapd
->iface
->interfaces
||
957 !hapd
->iface
->interfaces
->ctrl_iface_init
)
960 if (hapd
->iface
->interfaces
->ctrl_iface_init(hapd
)) {
961 wpa_printf(MSG_ERROR
,
962 "Failed to setup control interface for %s",
971 static int start_ctrl_iface(struct hostapd_iface
*iface
)
975 if (!iface
->interfaces
|| !iface
->interfaces
->ctrl_iface_init
)
978 for (i
= 0; i
< iface
->num_bss
; i
++) {
979 struct hostapd_data
*hapd
= iface
->bss
[i
];
980 if (iface
->interfaces
->ctrl_iface_init(hapd
)) {
981 wpa_printf(MSG_ERROR
,
982 "Failed to setup control interface for %s",
992 static void channel_list_update_timeout(void *eloop_ctx
, void *timeout_ctx
)
994 struct hostapd_iface
*iface
= eloop_ctx
;
996 if (!iface
->wait_channel_update
) {
997 wpa_printf(MSG_INFO
, "Channel list update timeout, but interface was not waiting for it");
1002 * It is possible that the existing channel list is acceptable, so try
1005 wpa_printf(MSG_DEBUG
, "Channel list update timeout - try to continue anyway");
1006 setup_interface2(iface
);
1010 void hostapd_channel_list_updated(struct hostapd_iface
*iface
, int initiator
)
1012 if (!iface
->wait_channel_update
|| initiator
!= REGDOM_SET_BY_USER
)
1015 wpa_printf(MSG_DEBUG
, "Channel list updated - continue setup");
1016 eloop_cancel_timeout(channel_list_update_timeout
, iface
, NULL
);
1017 setup_interface2(iface
);
1021 static int setup_interface(struct hostapd_iface
*iface
)
1023 struct hostapd_data
*hapd
= iface
->bss
[0];
1027 * It is possible that setup_interface() is called after the interface
1028 * was disabled etc., in which case driver_ap_teardown is possibly set
1029 * to 1. Clear it here so any other key/station deletion, which is not
1030 * part of a teardown flow, would also call the relevant driver
1033 iface
->driver_ap_teardown
= 0;
1035 if (!iface
->phy
[0]) {
1036 const char *phy
= hostapd_drv_get_radio_name(hapd
);
1038 wpa_printf(MSG_DEBUG
, "phy: %s", phy
);
1039 os_strlcpy(iface
->phy
, phy
, sizeof(iface
->phy
));
1044 * Make sure that all BSSes get configured with a pointer to the same
1047 for (i
= 1; i
< iface
->num_bss
; i
++) {
1048 iface
->bss
[i
]->driver
= hapd
->driver
;
1049 iface
->bss
[i
]->drv_priv
= hapd
->drv_priv
;
1052 if (hostapd_validate_bssid_configuration(iface
))
1056 * Initialize control interfaces early to allow external monitoring of
1057 * channel setup operations that may take considerable amount of time
1058 * especially for DFS cases.
1060 if (start_ctrl_iface(iface
))
1063 if (hapd
->iconf
->country
[0] && hapd
->iconf
->country
[1]) {
1064 char country
[4], previous_country
[4];
1066 hostapd_set_state(iface
, HAPD_IFACE_COUNTRY_UPDATE
);
1067 if (hostapd_get_country(hapd
, previous_country
) < 0)
1068 previous_country
[0] = '\0';
1070 os_memcpy(country
, hapd
->iconf
->country
, 3);
1072 if (hostapd_set_country(hapd
, country
) < 0) {
1073 wpa_printf(MSG_ERROR
, "Failed to set country code");
1077 wpa_printf(MSG_DEBUG
, "Previous country code %s, new country code %s",
1078 previous_country
, country
);
1080 if (os_strncmp(previous_country
, country
, 2) != 0) {
1081 wpa_printf(MSG_DEBUG
, "Continue interface setup after channel list update");
1082 iface
->wait_channel_update
= 1;
1083 eloop_register_timeout(5, 0,
1084 channel_list_update_timeout
,
1090 return setup_interface2(iface
);
1094 static int setup_interface2(struct hostapd_iface
*iface
)
1096 iface
->wait_channel_update
= 0;
1098 if (hostapd_get_hw_features(iface
)) {
1099 /* Not all drivers support this yet, so continue without hw
1102 int ret
= hostapd_select_hw_mode(iface
);
1104 wpa_printf(MSG_ERROR
, "Could not select hw_mode and "
1105 "channel. (%d)", ret
);
1109 wpa_printf(MSG_DEBUG
, "Interface initialization will be completed in a callback (ACS)");
1112 ret
= hostapd_check_ht_capab(iface
);
1116 wpa_printf(MSG_DEBUG
, "Interface initialization will "
1117 "be completed in a callback");
1121 if (iface
->conf
->ieee80211h
)
1122 wpa_printf(MSG_DEBUG
, "DFS support is enabled");
1124 return hostapd_setup_interface_complete(iface
, 0);
1127 hostapd_set_state(iface
, HAPD_IFACE_DISABLED
);
1128 wpa_msg(iface
->bss
[0]->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
1129 if (iface
->interfaces
&& iface
->interfaces
->terminate_on_error
)
1136 * hostapd_setup_interface_complete - Complete interface setup
1138 * This function is called when previous steps in the interface setup has been
1139 * completed. This can also start operations, e.g., DFS, that will require
1140 * additional processing before interface is ready to be enabled. Such
1141 * operations will call this function from eloop callbacks when finished.
1143 int hostapd_setup_interface_complete(struct hostapd_iface
*iface
, int err
)
1145 struct hostapd_data
*hapd
= iface
->bss
[0];
1152 wpa_printf(MSG_DEBUG
, "Completing interface initialization");
1153 if (iface
->conf
->channel
) {
1156 #endif /* NEED_AP_MLME */
1158 iface
->freq
= hostapd_hw_get_freq(hapd
, iface
->conf
->channel
);
1159 wpa_printf(MSG_DEBUG
, "Mode: %s Channel: %d "
1160 "Frequency: %d MHz",
1161 hostapd_hw_mode_txt(iface
->conf
->hw_mode
),
1162 iface
->conf
->channel
, iface
->freq
);
1166 res
= hostapd_handle_dfs(iface
);
1172 #endif /* NEED_AP_MLME */
1174 if (hostapd_set_freq(hapd
, hapd
->iconf
->hw_mode
, iface
->freq
,
1175 hapd
->iconf
->channel
,
1176 hapd
->iconf
->ieee80211n
,
1177 hapd
->iconf
->ieee80211ac
,
1178 hapd
->iconf
->secondary_channel
,
1179 hapd
->iconf
->vht_oper_chwidth
,
1180 hapd
->iconf
->vht_oper_centr_freq_seg0_idx
,
1181 hapd
->iconf
->vht_oper_centr_freq_seg1_idx
)) {
1182 wpa_printf(MSG_ERROR
, "Could not set channel for "
1188 if (iface
->current_mode
) {
1189 if (hostapd_prepare_rates(iface
, iface
->current_mode
)) {
1190 wpa_printf(MSG_ERROR
, "Failed to prepare rates "
1192 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE80211
,
1193 HOSTAPD_LEVEL_WARNING
,
1194 "Failed to prepare rates table.");
1199 if (hapd
->iconf
->rts_threshold
> -1 &&
1200 hostapd_set_rts(hapd
, hapd
->iconf
->rts_threshold
)) {
1201 wpa_printf(MSG_ERROR
, "Could not set RTS threshold for "
1206 if (hapd
->iconf
->fragm_threshold
> -1 &&
1207 hostapd_set_frag(hapd
, hapd
->iconf
->fragm_threshold
)) {
1208 wpa_printf(MSG_ERROR
, "Could not set fragmentation threshold "
1209 "for kernel driver");
1213 prev_addr
= hapd
->own_addr
;
1215 for (j
= 0; j
< iface
->num_bss
; j
++) {
1216 hapd
= iface
->bss
[j
];
1218 os_memcpy(hapd
->own_addr
, prev_addr
, ETH_ALEN
);
1219 if (hostapd_setup_bss(hapd
, j
== 0))
1221 if (hostapd_mac_comp_empty(hapd
->conf
->bssid
) == 0)
1222 prev_addr
= hapd
->own_addr
;
1224 hapd
= iface
->bss
[0];
1226 hostapd_tx_queue_params(iface
);
1228 ap_list_init(iface
);
1230 hostapd_set_acl(hapd
);
1232 if (hostapd_driver_commit(hapd
) < 0) {
1233 wpa_printf(MSG_ERROR
, "%s: Failed to commit driver "
1234 "configuration", __func__
);
1239 * WPS UPnP module can be initialized only when the "upnp_iface" is up.
1240 * If "interface" and "upnp_iface" are the same (e.g., non-bridge
1241 * mode), the interface is up only after driver_commit, so initialize
1242 * WPS after driver_commit.
1244 for (j
= 0; j
< iface
->num_bss
; j
++) {
1245 if (hostapd_init_wps_complete(iface
->bss
[j
]))
1249 hostapd_set_state(iface
, HAPD_IFACE_ENABLED
);
1250 wpa_msg(iface
->bss
[0]->msg_ctx
, MSG_INFO
, AP_EVENT_ENABLED
);
1251 if (hapd
->setup_complete_cb
)
1252 hapd
->setup_complete_cb(hapd
->setup_complete_cb_ctx
);
1254 wpa_printf(MSG_DEBUG
, "%s: Setup of interface done.",
1255 iface
->bss
[0]->conf
->iface
);
1256 if (iface
->interfaces
&& iface
->interfaces
->terminate_on_error
> 0)
1257 iface
->interfaces
->terminate_on_error
--;
1262 wpa_printf(MSG_ERROR
, "Interface initialization failed");
1263 hostapd_set_state(iface
, HAPD_IFACE_DISABLED
);
1264 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
1265 if (iface
->interfaces
&& iface
->interfaces
->terminate_on_error
)
1272 * hostapd_setup_interface - Setup of an interface
1273 * @iface: Pointer to interface data.
1274 * Returns: 0 on success, -1 on failure
1276 * Initializes the driver interface, validates the configuration,
1277 * and sets driver parameters based on the configuration.
1278 * Flushes old stations, sets the channel, encryption,
1279 * beacons, and WDS links based on the configuration.
1281 * If interface setup requires more time, e.g., to perform HT co-ex scans, ACS,
1282 * or DFS operations, this function returns 0 before such operations have been
1283 * completed. The pending operations are registered into eloop and will be
1284 * completed from eloop callbacks. Those callbacks end up calling
1285 * hostapd_setup_interface_complete() once setup has been completed.
1287 int hostapd_setup_interface(struct hostapd_iface
*iface
)
1291 ret
= setup_interface(iface
);
1293 wpa_printf(MSG_ERROR
, "%s: Unable to setup interface.",
1294 iface
->bss
[0]->conf
->iface
);
1303 * hostapd_alloc_bss_data - Allocate and initialize per-BSS data
1304 * @hapd_iface: Pointer to interface data
1305 * @conf: Pointer to per-interface configuration
1306 * @bss: Pointer to per-BSS configuration for this BSS
1307 * Returns: Pointer to allocated BSS data
1309 * This function is used to allocate per-BSS data structure. This data will be
1310 * freed after hostapd_cleanup() is called for it during interface
1313 struct hostapd_data
*
1314 hostapd_alloc_bss_data(struct hostapd_iface
*hapd_iface
,
1315 struct hostapd_config
*conf
,
1316 struct hostapd_bss_config
*bss
)
1318 struct hostapd_data
*hapd
;
1320 hapd
= os_zalloc(sizeof(*hapd
));
1324 hapd
->new_assoc_sta_cb
= hostapd_new_assoc_sta
;
1327 hapd
->iface
= hapd_iface
;
1328 hapd
->driver
= hapd
->iconf
->driver
;
1329 hapd
->ctrl_sock
= -1;
1335 static void hostapd_bss_deinit(struct hostapd_data
*hapd
)
1337 wpa_printf(MSG_DEBUG
, "%s: deinit bss %s", __func__
,
1339 hostapd_free_stas(hapd
);
1340 hostapd_flush_old_stations(hapd
, WLAN_REASON_DEAUTH_LEAVING
);
1341 hostapd_clear_wep(hapd
);
1342 hostapd_cleanup(hapd
);
1346 void hostapd_interface_deinit(struct hostapd_iface
*iface
)
1350 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
1354 eloop_cancel_timeout(channel_list_update_timeout
, iface
, NULL
);
1355 iface
->wait_channel_update
= 0;
1357 for (j
= iface
->num_bss
- 1; j
>= 0; j
--)
1358 hostapd_bss_deinit(iface
->bss
[j
]);
1362 void hostapd_interface_free(struct hostapd_iface
*iface
)
1365 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
1366 for (j
= 0; j
< iface
->num_bss
; j
++) {
1367 wpa_printf(MSG_DEBUG
, "%s: free hapd %p",
1368 __func__
, iface
->bss
[j
]);
1369 os_free(iface
->bss
[j
]);
1371 hostapd_cleanup_iface(iface
);
1376 * hostapd_init - Allocate and initialize per-interface data
1377 * @config_file: Path to the configuration file
1378 * Returns: Pointer to the allocated interface data or %NULL on failure
1380 * This function is used to allocate main data structures for per-interface
1381 * data. The allocated data buffer will be freed by calling
1382 * hostapd_cleanup_iface().
1384 struct hostapd_iface
* hostapd_init(struct hapd_interfaces
*interfaces
,
1385 const char *config_file
)
1387 struct hostapd_iface
*hapd_iface
= NULL
;
1388 struct hostapd_config
*conf
= NULL
;
1389 struct hostapd_data
*hapd
;
1392 hapd_iface
= os_zalloc(sizeof(*hapd_iface
));
1393 if (hapd_iface
== NULL
)
1396 hapd_iface
->config_fname
= os_strdup(config_file
);
1397 if (hapd_iface
->config_fname
== NULL
)
1400 conf
= interfaces
->config_read_cb(hapd_iface
->config_fname
);
1403 hapd_iface
->conf
= conf
;
1405 hapd_iface
->num_bss
= conf
->num_bss
;
1406 hapd_iface
->bss
= os_calloc(conf
->num_bss
,
1407 sizeof(struct hostapd_data
*));
1408 if (hapd_iface
->bss
== NULL
)
1411 for (i
= 0; i
< conf
->num_bss
; i
++) {
1412 hapd
= hapd_iface
->bss
[i
] =
1413 hostapd_alloc_bss_data(hapd_iface
, conf
,
1417 hapd
->msg_ctx
= hapd
;
1423 wpa_printf(MSG_ERROR
, "Failed to set up interface with %s",
1426 hostapd_config_free(conf
);
1428 os_free(hapd_iface
->config_fname
);
1429 os_free(hapd_iface
->bss
);
1430 wpa_printf(MSG_DEBUG
, "%s: free iface %p",
1431 __func__
, hapd_iface
);
1432 os_free(hapd_iface
);
1438 static int ifname_in_use(struct hapd_interfaces
*interfaces
, const char *ifname
)
1442 for (i
= 0; i
< interfaces
->count
; i
++) {
1443 struct hostapd_iface
*iface
= interfaces
->iface
[i
];
1444 for (j
= 0; j
< iface
->num_bss
; j
++) {
1445 struct hostapd_data
*hapd
= iface
->bss
[j
];
1446 if (os_strcmp(ifname
, hapd
->conf
->iface
) == 0)
1456 * hostapd_interface_init_bss - Read configuration file and init BSS data
1458 * This function is used to parse configuration file for a BSS. This BSS is
1459 * added to an existing interface sharing the same radio (if any) or a new
1460 * interface is created if this is the first interface on a radio. This
1461 * allocate memory for the BSS. No actual driver operations are started.
1463 * This is similar to hostapd_interface_init(), but for a case where the
1464 * configuration is used to add a single BSS instead of all BSSes for a radio.
1466 struct hostapd_iface
*
1467 hostapd_interface_init_bss(struct hapd_interfaces
*interfaces
, const char *phy
,
1468 const char *config_fname
, int debug
)
1470 struct hostapd_iface
*new_iface
= NULL
, *iface
= NULL
;
1471 struct hostapd_data
*hapd
;
1478 for (i
= 0; i
< interfaces
->count
; i
++) {
1479 if (os_strcmp(interfaces
->iface
[i
]->phy
, phy
) == 0) {
1480 iface
= interfaces
->iface
[i
];
1485 wpa_printf(MSG_INFO
, "Configuration file: %s (phy %s)%s",
1486 config_fname
, phy
, iface
? "" : " --> new PHY");
1488 struct hostapd_config
*conf
;
1489 struct hostapd_bss_config
**tmp_conf
;
1490 struct hostapd_data
**tmp_bss
;
1491 struct hostapd_bss_config
*bss
;
1494 /* Add new BSS to existing iface */
1495 conf
= interfaces
->config_read_cb(config_fname
);
1498 if (conf
->num_bss
> 1) {
1499 wpa_printf(MSG_ERROR
, "Multiple BSSes specified in BSS-config");
1500 hostapd_config_free(conf
);
1504 ifname
= conf
->bss
[0]->iface
;
1505 if (ifname
[0] != '\0' && ifname_in_use(interfaces
, ifname
)) {
1506 wpa_printf(MSG_ERROR
,
1507 "Interface name %s already in use", ifname
);
1508 hostapd_config_free(conf
);
1512 tmp_conf
= os_realloc_array(
1513 iface
->conf
->bss
, iface
->conf
->num_bss
+ 1,
1514 sizeof(struct hostapd_bss_config
*));
1515 tmp_bss
= os_realloc_array(iface
->bss
, iface
->num_bss
+ 1,
1516 sizeof(struct hostapd_data
*));
1518 iface
->bss
= tmp_bss
;
1520 iface
->conf
->bss
= tmp_conf
;
1521 iface
->conf
->last_bss
= tmp_conf
[0];
1523 if (tmp_bss
== NULL
|| tmp_conf
== NULL
) {
1524 hostapd_config_free(conf
);
1527 bss
= iface
->conf
->bss
[iface
->conf
->num_bss
] = conf
->bss
[0];
1528 iface
->conf
->num_bss
++;
1530 hapd
= hostapd_alloc_bss_data(iface
, iface
->conf
, bss
);
1532 iface
->conf
->num_bss
--;
1533 hostapd_config_free(conf
);
1536 iface
->conf
->last_bss
= bss
;
1537 iface
->bss
[iface
->num_bss
] = hapd
;
1538 hapd
->msg_ctx
= hapd
;
1540 bss_idx
= iface
->num_bss
++;
1542 conf
->bss
[0] = NULL
;
1543 hostapd_config_free(conf
);
1545 /* Add a new iface with the first BSS */
1546 new_iface
= iface
= hostapd_init(interfaces
, config_fname
);
1549 os_strlcpy(iface
->phy
, phy
, sizeof(iface
->phy
));
1550 iface
->interfaces
= interfaces
;
1554 for (k
= 0; k
< debug
; k
++) {
1555 if (iface
->bss
[bss_idx
]->conf
->logger_stdout_level
> 0)
1556 iface
->bss
[bss_idx
]->conf
->logger_stdout_level
--;
1559 if (iface
->conf
->bss
[bss_idx
]->iface
[0] == '\0' &&
1560 !hostapd_drv_none(iface
->bss
[bss_idx
])) {
1561 wpa_printf(MSG_ERROR
, "Interface name not specified in %s",
1564 hostapd_interface_deinit_free(new_iface
);
1572 void hostapd_interface_deinit_free(struct hostapd_iface
*iface
)
1574 const struct wpa_driver_ops
*driver
;
1577 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
1580 wpa_printf(MSG_DEBUG
, "%s: num_bss=%u conf->num_bss=%u",
1581 __func__
, (unsigned int) iface
->num_bss
,
1582 (unsigned int) iface
->conf
->num_bss
);
1583 driver
= iface
->bss
[0]->driver
;
1584 drv_priv
= iface
->bss
[0]->drv_priv
;
1585 hostapd_interface_deinit(iface
);
1586 wpa_printf(MSG_DEBUG
, "%s: driver=%p drv_priv=%p -> hapd_deinit",
1587 __func__
, driver
, drv_priv
);
1588 if (driver
&& driver
->hapd_deinit
&& drv_priv
)
1589 driver
->hapd_deinit(drv_priv
);
1590 hostapd_interface_free(iface
);
1594 int hostapd_enable_iface(struct hostapd_iface
*hapd_iface
)
1596 if (hapd_iface
->bss
[0]->drv_priv
!= NULL
) {
1597 wpa_printf(MSG_ERROR
, "Interface %s already enabled",
1598 hapd_iface
->conf
->bss
[0]->iface
);
1602 wpa_printf(MSG_DEBUG
, "Enable interface %s",
1603 hapd_iface
->conf
->bss
[0]->iface
);
1605 if (hostapd_config_check(hapd_iface
->conf
, 1) < 0) {
1606 wpa_printf(MSG_INFO
, "Invalid configuration - cannot enable");
1610 if (hapd_iface
->interfaces
== NULL
||
1611 hapd_iface
->interfaces
->driver_init
== NULL
||
1612 hapd_iface
->interfaces
->driver_init(hapd_iface
))
1615 if (hostapd_setup_interface(hapd_iface
)) {
1616 const struct wpa_driver_ops
*driver
;
1619 driver
= hapd_iface
->bss
[0]->driver
;
1620 drv_priv
= hapd_iface
->bss
[0]->drv_priv
;
1621 wpa_printf(MSG_DEBUG
, "%s: driver=%p drv_priv=%p -> hapd_deinit",
1622 __func__
, driver
, drv_priv
);
1623 if (driver
&& driver
->hapd_deinit
&& drv_priv
) {
1624 driver
->hapd_deinit(drv_priv
);
1625 hapd_iface
->bss
[0]->drv_priv
= NULL
;
1634 int hostapd_reload_iface(struct hostapd_iface
*hapd_iface
)
1638 wpa_printf(MSG_DEBUG
, "Reload interface %s",
1639 hapd_iface
->conf
->bss
[0]->iface
);
1640 for (j
= 0; j
< hapd_iface
->num_bss
; j
++)
1641 hostapd_set_security_params(hapd_iface
->conf
->bss
[j
]);
1642 if (hostapd_config_check(hapd_iface
->conf
, 1) < 0) {
1643 wpa_printf(MSG_ERROR
, "Updated configuration is invalid");
1646 hostapd_clear_old(hapd_iface
);
1647 for (j
= 0; j
< hapd_iface
->num_bss
; j
++)
1648 hostapd_reload_bss(hapd_iface
->bss
[j
]);
1654 int hostapd_disable_iface(struct hostapd_iface
*hapd_iface
)
1657 const struct wpa_driver_ops
*driver
;
1660 if (hapd_iface
== NULL
)
1662 wpa_msg(hapd_iface
->bss
[0]->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
1663 driver
= hapd_iface
->bss
[0]->driver
;
1664 drv_priv
= hapd_iface
->bss
[0]->drv_priv
;
1666 hapd_iface
->driver_ap_teardown
=
1667 !!(hapd_iface
->drv_flags
&
1668 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT
);
1670 /* same as hostapd_interface_deinit without deinitializing ctrl-iface */
1671 for (j
= 0; j
< hapd_iface
->num_bss
; j
++) {
1672 struct hostapd_data
*hapd
= hapd_iface
->bss
[j
];
1673 hostapd_free_stas(hapd
);
1674 hostapd_flush_old_stations(hapd
, WLAN_REASON_DEAUTH_LEAVING
);
1675 hostapd_clear_wep(hapd
);
1676 hostapd_free_hapd_data(hapd
);
1679 wpa_printf(MSG_DEBUG
, "%s: driver=%p drv_priv=%p -> hapd_deinit",
1680 __func__
, driver
, drv_priv
);
1681 if (driver
&& driver
->hapd_deinit
&& drv_priv
) {
1682 driver
->hapd_deinit(drv_priv
);
1683 hapd_iface
->bss
[0]->drv_priv
= NULL
;
1686 /* From hostapd_cleanup_iface: These were initialized in
1687 * hostapd_setup_interface and hostapd_setup_interface_complete
1689 hostapd_cleanup_iface_partial(hapd_iface
);
1691 wpa_printf(MSG_DEBUG
, "Interface %s disabled",
1692 hapd_iface
->bss
[0]->conf
->iface
);
1693 hostapd_set_state(hapd_iface
, HAPD_IFACE_DISABLED
);
1698 static struct hostapd_iface
*
1699 hostapd_iface_alloc(struct hapd_interfaces
*interfaces
)
1701 struct hostapd_iface
**iface
, *hapd_iface
;
1703 iface
= os_realloc_array(interfaces
->iface
, interfaces
->count
+ 1,
1704 sizeof(struct hostapd_iface
*));
1707 interfaces
->iface
= iface
;
1708 hapd_iface
= interfaces
->iface
[interfaces
->count
] =
1709 os_zalloc(sizeof(*hapd_iface
));
1710 if (hapd_iface
== NULL
) {
1711 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory for "
1712 "the interface", __func__
);
1715 interfaces
->count
++;
1716 hapd_iface
->interfaces
= interfaces
;
1722 static struct hostapd_config
*
1723 hostapd_config_alloc(struct hapd_interfaces
*interfaces
, const char *ifname
,
1724 const char *ctrl_iface
)
1726 struct hostapd_bss_config
*bss
;
1727 struct hostapd_config
*conf
;
1729 /* Allocates memory for bss and conf */
1730 conf
= hostapd_config_defaults();
1732 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory for "
1733 "configuration", __func__
);
1737 conf
->driver
= wpa_drivers
[0];
1738 if (conf
->driver
== NULL
) {
1739 wpa_printf(MSG_ERROR
, "No driver wrappers registered!");
1740 hostapd_config_free(conf
);
1744 bss
= conf
->last_bss
= conf
->bss
[0];
1746 os_strlcpy(bss
->iface
, ifname
, sizeof(bss
->iface
));
1747 bss
->ctrl_interface
= os_strdup(ctrl_iface
);
1748 if (bss
->ctrl_interface
== NULL
) {
1749 hostapd_config_free(conf
);
1753 /* Reading configuration file skipped, will be done in SET!
1754 * From reading the configuration till the end has to be done in
1761 static struct hostapd_iface
* hostapd_data_alloc(
1762 struct hapd_interfaces
*interfaces
, struct hostapd_config
*conf
)
1765 struct hostapd_iface
*hapd_iface
=
1766 interfaces
->iface
[interfaces
->count
- 1];
1767 struct hostapd_data
*hapd
;
1769 hapd_iface
->conf
= conf
;
1770 hapd_iface
->num_bss
= conf
->num_bss
;
1772 hapd_iface
->bss
= os_zalloc(conf
->num_bss
*
1773 sizeof(struct hostapd_data
*));
1774 if (hapd_iface
->bss
== NULL
)
1777 for (i
= 0; i
< conf
->num_bss
; i
++) {
1778 hapd
= hapd_iface
->bss
[i
] =
1779 hostapd_alloc_bss_data(hapd_iface
, conf
, conf
->bss
[i
]);
1782 hapd
->msg_ctx
= hapd
;
1785 hapd_iface
->interfaces
= interfaces
;
1791 int hostapd_add_iface(struct hapd_interfaces
*interfaces
, char *buf
)
1793 struct hostapd_config
*conf
= NULL
;
1794 struct hostapd_iface
*hapd_iface
= NULL
, *new_iface
= NULL
;
1795 struct hostapd_data
*hapd
;
1798 const char *conf_file
= NULL
, *phy_name
= NULL
;
1800 if (os_strncmp(buf
, "bss_config=", 11) == 0) {
1802 phy_name
= buf
+ 11;
1803 pos
= os_strchr(phy_name
, ':');
1808 if (!os_strlen(conf_file
))
1811 hapd_iface
= hostapd_interface_init_bss(interfaces
, phy_name
,
1815 for (j
= 0; j
< interfaces
->count
; j
++) {
1816 if (interfaces
->iface
[j
] == hapd_iface
)
1819 if (j
== interfaces
->count
) {
1820 struct hostapd_iface
**tmp
;
1821 tmp
= os_realloc_array(interfaces
->iface
,
1822 interfaces
->count
+ 1,
1823 sizeof(struct hostapd_iface
*));
1825 hostapd_interface_deinit_free(hapd_iface
);
1828 interfaces
->iface
= tmp
;
1829 interfaces
->iface
[interfaces
->count
++] = hapd_iface
;
1830 new_iface
= hapd_iface
;
1834 if (interfaces
->driver_init(hapd_iface
) ||
1835 hostapd_setup_interface(hapd_iface
)) {
1836 interfaces
->count
--;
1840 /* Assign new BSS with bss[0]'s driver info */
1841 hapd
= hapd_iface
->bss
[hapd_iface
->num_bss
- 1];
1842 hapd
->driver
= hapd_iface
->bss
[0]->driver
;
1843 hapd
->drv_priv
= hapd_iface
->bss
[0]->drv_priv
;
1844 os_memcpy(hapd
->own_addr
, hapd_iface
->bss
[0]->own_addr
,
1847 if (start_ctrl_iface_bss(hapd
) < 0 ||
1848 (hapd_iface
->state
== HAPD_IFACE_ENABLED
&&
1849 hostapd_setup_bss(hapd
, -1))) {
1850 hostapd_cleanup(hapd
);
1851 hapd_iface
->bss
[hapd_iface
->num_bss
- 1] = NULL
;
1852 hapd_iface
->conf
->num_bss
--;
1853 hapd_iface
->num_bss
--;
1854 wpa_printf(MSG_DEBUG
, "%s: free hapd %p %s",
1855 __func__
, hapd
, hapd
->conf
->iface
);
1863 ptr
= os_strchr(buf
, ' ');
1868 if (os_strncmp(ptr
, "config=", 7) == 0)
1869 conf_file
= ptr
+ 7;
1871 for (i
= 0; i
< interfaces
->count
; i
++) {
1872 if (!os_strcmp(interfaces
->iface
[i
]->conf
->bss
[0]->iface
,
1874 wpa_printf(MSG_INFO
, "Cannot add interface - it "
1880 hapd_iface
= hostapd_iface_alloc(interfaces
);
1881 if (hapd_iface
== NULL
) {
1882 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory "
1883 "for interface", __func__
);
1887 if (conf_file
&& interfaces
->config_read_cb
) {
1888 conf
= interfaces
->config_read_cb(conf_file
);
1889 if (conf
&& conf
->bss
)
1890 os_strlcpy(conf
->bss
[0]->iface
, buf
,
1891 sizeof(conf
->bss
[0]->iface
));
1893 conf
= hostapd_config_alloc(interfaces
, buf
, ptr
);
1894 if (conf
== NULL
|| conf
->bss
== NULL
) {
1895 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory "
1896 "for configuration", __func__
);
1900 hapd_iface
= hostapd_data_alloc(interfaces
, conf
);
1901 if (hapd_iface
== NULL
) {
1902 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory "
1903 "for hostapd", __func__
);
1907 if (start_ctrl_iface(hapd_iface
) < 0)
1910 wpa_printf(MSG_INFO
, "Add interface '%s'", conf
->bss
[0]->iface
);
1916 hostapd_config_free(conf
);
1918 if (hapd_iface
->bss
) {
1919 for (i
= 0; i
< hapd_iface
->num_bss
; i
++) {
1920 hapd
= hapd_iface
->bss
[i
];
1923 if (hapd_iface
->interfaces
&&
1924 hapd_iface
->interfaces
->ctrl_iface_deinit
)
1925 hapd_iface
->interfaces
->
1926 ctrl_iface_deinit(hapd
);
1927 wpa_printf(MSG_DEBUG
, "%s: free hapd %p (%s)",
1928 __func__
, hapd_iface
->bss
[i
],
1931 hapd_iface
->bss
[i
] = NULL
;
1933 os_free(hapd_iface
->bss
);
1935 wpa_printf(MSG_DEBUG
, "%s: free iface %p",
1936 __func__
, hapd_iface
);
1937 os_free(hapd_iface
);
1943 static int hostapd_remove_bss(struct hostapd_iface
*iface
, unsigned int idx
)
1947 wpa_printf(MSG_INFO
, "Remove BSS '%s'", iface
->conf
->bss
[idx
]->iface
);
1949 /* Remove hostapd_data only if it has already been initialized */
1950 if (idx
< iface
->num_bss
) {
1951 struct hostapd_data
*hapd
= iface
->bss
[idx
];
1953 hostapd_bss_deinit(hapd
);
1954 wpa_printf(MSG_DEBUG
, "%s: free hapd %p (%s)",
1955 __func__
, hapd
, hapd
->conf
->iface
);
1956 hostapd_config_free_bss(hapd
->conf
);
1961 for (i
= idx
; i
< iface
->num_bss
; i
++)
1962 iface
->bss
[i
] = iface
->bss
[i
+ 1];
1964 hostapd_config_free_bss(iface
->conf
->bss
[idx
]);
1965 iface
->conf
->bss
[idx
] = NULL
;
1968 iface
->conf
->num_bss
--;
1969 for (i
= idx
; i
< iface
->conf
->num_bss
; i
++)
1970 iface
->conf
->bss
[i
] = iface
->conf
->bss
[i
+ 1];
1976 int hostapd_remove_iface(struct hapd_interfaces
*interfaces
, char *buf
)
1978 struct hostapd_iface
*hapd_iface
;
1981 for (i
= 0; i
< interfaces
->count
; i
++) {
1982 hapd_iface
= interfaces
->iface
[i
];
1983 if (hapd_iface
== NULL
)
1985 if (!os_strcmp(hapd_iface
->conf
->bss
[0]->iface
, buf
)) {
1986 wpa_printf(MSG_INFO
, "Remove interface '%s'", buf
);
1987 hapd_iface
->driver_ap_teardown
=
1988 !!(hapd_iface
->drv_flags
&
1989 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT
);
1991 hostapd_interface_deinit_free(hapd_iface
);
1993 while (k
< (interfaces
->count
- 1)) {
1994 interfaces
->iface
[k
] =
1995 interfaces
->iface
[k
+ 1];
1998 interfaces
->count
--;
2002 for (j
= 0; j
< hapd_iface
->conf
->num_bss
; j
++) {
2003 if (!os_strcmp(hapd_iface
->conf
->bss
[j
]->iface
, buf
)) {
2004 hapd_iface
->driver_ap_teardown
=
2005 !(hapd_iface
->drv_flags
&
2006 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT
);
2007 return hostapd_remove_bss(hapd_iface
, j
);
2016 * hostapd_new_assoc_sta - Notify that a new station associated with the AP
2017 * @hapd: Pointer to BSS data
2018 * @sta: Pointer to the associated STA data
2019 * @reassoc: 1 to indicate this was a re-association; 0 = first association
2021 * This function will be called whenever a station associates with the AP. It
2022 * can be called from ieee802_11.c for drivers that export MLME to hostapd and
2023 * from drv_callbacks.c based on driver events for drivers that take care of
2024 * management frames (IEEE 802.11 authentication and association) internally.
2026 void hostapd_new_assoc_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2029 if (hapd
->tkip_countermeasures
) {
2030 hostapd_drv_sta_deauth(hapd
, sta
->addr
,
2031 WLAN_REASON_MICHAEL_MIC_FAILURE
);
2035 hostapd_prune_associations(hapd
, sta
->addr
);
2037 /* IEEE 802.11F (IAPP) */
2038 if (hapd
->conf
->ieee802_11f
)
2039 iapp_new_station(hapd
->iapp
, sta
);
2042 if (sta
->p2p_ie
== NULL
&& !sta
->no_p2p_set
) {
2043 sta
->no_p2p_set
= 1;
2044 hapd
->num_sta_no_p2p
++;
2045 if (hapd
->num_sta_no_p2p
== 1)
2046 hostapd_p2p_non_p2p_sta_connected(hapd
);
2048 #endif /* CONFIG_P2P */
2050 /* Start accounting here, if IEEE 802.1X and WPA are not used.
2051 * IEEE 802.1X/WPA code will start accounting after the station has
2052 * been authorized. */
2053 if (!hapd
->conf
->ieee802_1x
&& !hapd
->conf
->wpa
&& !hapd
->conf
->osen
) {
2054 ap_sta_set_authorized(hapd
, sta
, 1);
2055 os_get_reltime(&sta
->connected_time
);
2056 accounting_sta_start(hapd
, sta
);
2059 /* Start IEEE 802.1X authentication process for new stations */
2060 ieee802_1x_new_station(hapd
, sta
);
2062 if (sta
->auth_alg
!= WLAN_AUTH_FT
&&
2063 !(sta
->flags
& (WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
)))
2064 wpa_auth_sm_event(sta
->wpa_sm
, WPA_REAUTH
);
2066 wpa_auth_sta_associated(hapd
->wpa_auth
, sta
->wpa_sm
);
2068 if (!(hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_INACTIVITY_TIMER
)) {
2069 wpa_printf(MSG_DEBUG
, "%s: reschedule ap_handle_timer timeout "
2070 "for " MACSTR
" (%d seconds - ap_max_inactivity)",
2071 __func__
, MAC2STR(sta
->addr
),
2072 hapd
->conf
->ap_max_inactivity
);
2073 eloop_cancel_timeout(ap_handle_timer
, hapd
, sta
);
2074 eloop_register_timeout(hapd
->conf
->ap_max_inactivity
, 0,
2075 ap_handle_timer
, hapd
, sta
);
2080 const char * hostapd_state_text(enum hostapd_iface_state s
)
2083 case HAPD_IFACE_UNINITIALIZED
:
2084 return "UNINITIALIZED";
2085 case HAPD_IFACE_DISABLED
:
2087 case HAPD_IFACE_COUNTRY_UPDATE
:
2088 return "COUNTRY_UPDATE";
2089 case HAPD_IFACE_ACS
:
2091 case HAPD_IFACE_HT_SCAN
:
2093 case HAPD_IFACE_DFS
:
2095 case HAPD_IFACE_ENABLED
:
2103 void hostapd_set_state(struct hostapd_iface
*iface
, enum hostapd_iface_state s
)
2105 wpa_printf(MSG_INFO
, "%s: interface state %s->%s",
2106 iface
->conf
->bss
[0]->iface
, hostapd_state_text(iface
->state
),
2107 hostapd_state_text(s
));
2114 static void free_beacon_data(struct beacon_data
*beacon
)
2116 os_free(beacon
->head
);
2117 beacon
->head
= NULL
;
2118 os_free(beacon
->tail
);
2119 beacon
->tail
= NULL
;
2120 os_free(beacon
->probe_resp
);
2121 beacon
->probe_resp
= NULL
;
2122 os_free(beacon
->beacon_ies
);
2123 beacon
->beacon_ies
= NULL
;
2124 os_free(beacon
->proberesp_ies
);
2125 beacon
->proberesp_ies
= NULL
;
2126 os_free(beacon
->assocresp_ies
);
2127 beacon
->assocresp_ies
= NULL
;
2131 static int hostapd_build_beacon_data(struct hostapd_iface
*iface
,
2132 struct beacon_data
*beacon
)
2134 struct wpabuf
*beacon_extra
, *proberesp_extra
, *assocresp_extra
;
2135 struct wpa_driver_ap_params params
;
2137 struct hostapd_data
*hapd
= iface
->bss
[0];
2139 os_memset(beacon
, 0, sizeof(*beacon
));
2140 ret
= ieee802_11_build_ap_params(hapd
, ¶ms
);
2144 ret
= hostapd_build_ap_extra_ies(hapd
, &beacon_extra
,
2148 goto free_ap_params
;
2151 beacon
->head
= os_malloc(params
.head_len
);
2153 goto free_ap_extra_ies
;
2155 os_memcpy(beacon
->head
, params
.head
, params
.head_len
);
2156 beacon
->head_len
= params
.head_len
;
2158 beacon
->tail
= os_malloc(params
.tail_len
);
2162 os_memcpy(beacon
->tail
, params
.tail
, params
.tail_len
);
2163 beacon
->tail_len
= params
.tail_len
;
2165 if (params
.proberesp
!= NULL
) {
2166 beacon
->probe_resp
= os_malloc(params
.proberesp_len
);
2167 if (!beacon
->probe_resp
)
2170 os_memcpy(beacon
->probe_resp
, params
.proberesp
,
2171 params
.proberesp_len
);
2172 beacon
->probe_resp_len
= params
.proberesp_len
;
2175 /* copy the extra ies */
2177 beacon
->beacon_ies
= os_malloc(wpabuf_len(beacon_extra
));
2178 if (!beacon
->beacon_ies
)
2181 os_memcpy(beacon
->beacon_ies
,
2182 beacon_extra
->buf
, wpabuf_len(beacon_extra
));
2183 beacon
->beacon_ies_len
= wpabuf_len(beacon_extra
);
2186 if (proberesp_extra
) {
2187 beacon
->proberesp_ies
=
2188 os_malloc(wpabuf_len(proberesp_extra
));
2189 if (!beacon
->proberesp_ies
)
2192 os_memcpy(beacon
->proberesp_ies
, proberesp_extra
->buf
,
2193 wpabuf_len(proberesp_extra
));
2194 beacon
->proberesp_ies_len
= wpabuf_len(proberesp_extra
);
2197 if (assocresp_extra
) {
2198 beacon
->assocresp_ies
=
2199 os_malloc(wpabuf_len(assocresp_extra
));
2200 if (!beacon
->assocresp_ies
)
2203 os_memcpy(beacon
->assocresp_ies
, assocresp_extra
->buf
,
2204 wpabuf_len(assocresp_extra
));
2205 beacon
->assocresp_ies_len
= wpabuf_len(assocresp_extra
);
2210 /* if the function fails, the caller should not free beacon data */
2212 free_beacon_data(beacon
);
2215 hostapd_free_ap_extra_ies(hapd
, beacon_extra
, proberesp_extra
,
2218 ieee802_11_free_ap_params(¶ms
);
2224 * TODO: This flow currently supports only changing frequency within the
2225 * same hw_mode. Any other changes to MAC parameters or provided settings (even
2226 * width) are not supported.
2228 static int hostapd_change_config_freq(struct hostapd_data
*hapd
,
2229 struct hostapd_config
*conf
,
2230 struct hostapd_freq_params
*params
,
2231 struct hostapd_freq_params
*old_params
)
2235 if (!params
->channel
) {
2236 /* check if the new channel is supported by hw */
2237 channel
= hostapd_hw_get_channel(hapd
, params
->freq
);
2241 channel
= params
->channel
;
2244 /* if a pointer to old_params is provided we save previous state */
2246 old_params
->channel
= conf
->channel
;
2247 old_params
->ht_enabled
= conf
->ieee80211n
;
2248 old_params
->sec_channel_offset
= conf
->secondary_channel
;
2251 conf
->channel
= channel
;
2252 conf
->ieee80211n
= params
->ht_enabled
;
2253 conf
->secondary_channel
= params
->sec_channel_offset
;
2255 /* TODO: maybe call here hostapd_config_check here? */
2261 static int hostapd_fill_csa_settings(struct hostapd_iface
*iface
,
2262 struct csa_settings
*settings
)
2264 struct hostapd_freq_params old_freq
;
2267 os_memset(&old_freq
, 0, sizeof(old_freq
));
2268 if (!iface
|| !iface
->freq
|| iface
->csa_in_progress
)
2271 ret
= hostapd_change_config_freq(iface
->bss
[0], iface
->conf
,
2272 &settings
->freq_params
,
2277 ret
= hostapd_build_beacon_data(iface
, &settings
->beacon_after
);
2279 /* change back the configuration */
2280 hostapd_change_config_freq(iface
->bss
[0], iface
->conf
,
2286 /* set channel switch parameters for csa ie */
2287 iface
->cs_freq_params
= settings
->freq_params
;
2288 iface
->cs_count
= settings
->cs_count
;
2289 iface
->cs_block_tx
= settings
->block_tx
;
2291 ret
= hostapd_build_beacon_data(iface
, &settings
->beacon_csa
);
2293 free_beacon_data(&settings
->beacon_after
);
2297 settings
->counter_offset_beacon
= iface
->cs_c_off_beacon
;
2298 settings
->counter_offset_presp
= iface
->cs_c_off_proberesp
;
2304 void hostapd_cleanup_cs_params(struct hostapd_data
*hapd
)
2306 os_memset(&hapd
->iface
->cs_freq_params
, 0,
2307 sizeof(hapd
->iface
->cs_freq_params
));
2308 hapd
->iface
->cs_count
= 0;
2309 hapd
->iface
->cs_block_tx
= 0;
2310 hapd
->iface
->cs_c_off_beacon
= 0;
2311 hapd
->iface
->cs_c_off_proberesp
= 0;
2312 hapd
->iface
->csa_in_progress
= 0;
2316 int hostapd_switch_channel(struct hostapd_data
*hapd
,
2317 struct csa_settings
*settings
)
2320 ret
= hostapd_fill_csa_settings(hapd
->iface
, settings
);
2324 ret
= hostapd_drv_switch_channel(hapd
, settings
);
2325 free_beacon_data(&settings
->beacon_csa
);
2326 free_beacon_data(&settings
->beacon_after
);
2329 /* if we failed, clean cs parameters */
2330 hostapd_cleanup_cs_params(hapd
);
2334 hapd
->iface
->csa_in_progress
= 1;
2338 #endif /* NEED_AP_MLME */