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
->secondary_channel
= oldconf
->secondary_channel
;
176 hapd
->iconf
->ieee80211n
= oldconf
->ieee80211n
;
177 hapd
->iconf
->ieee80211ac
= oldconf
->ieee80211ac
;
178 hapd
->iconf
->ht_capab
= oldconf
->ht_capab
;
179 hapd
->iconf
->vht_capab
= oldconf
->vht_capab
;
180 hapd
->iconf
->vht_oper_chwidth
= oldconf
->vht_oper_chwidth
;
181 hapd
->iconf
->vht_oper_centr_freq_seg0_idx
=
182 oldconf
->vht_oper_centr_freq_seg0_idx
;
183 hapd
->iconf
->vht_oper_centr_freq_seg1_idx
=
184 oldconf
->vht_oper_centr_freq_seg1_idx
;
185 hapd
->conf
= newconf
->bss
[j
];
186 hostapd_reload_bss(hapd
);
189 hostapd_config_free(oldconf
);
196 static void hostapd_broadcast_key_clear_iface(struct hostapd_data
*hapd
,
201 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
202 if (hostapd_drv_set_key(ifname
, hapd
, WPA_ALG_NONE
, NULL
, i
,
203 0, NULL
, 0, NULL
, 0)) {
204 wpa_printf(MSG_DEBUG
, "Failed to clear default "
205 "encryption keys (ifname=%s keyidx=%d)",
209 #ifdef CONFIG_IEEE80211W
210 if (hapd
->conf
->ieee80211w
) {
211 for (i
= NUM_WEP_KEYS
; i
< NUM_WEP_KEYS
+ 2; i
++) {
212 if (hostapd_drv_set_key(ifname
, hapd
, WPA_ALG_NONE
,
215 wpa_printf(MSG_DEBUG
, "Failed to clear "
216 "default mgmt encryption keys "
217 "(ifname=%s keyidx=%d)", ifname
, i
);
221 #endif /* CONFIG_IEEE80211W */
225 static int hostapd_broadcast_wep_clear(struct hostapd_data
*hapd
)
227 hostapd_broadcast_key_clear_iface(hapd
, hapd
->conf
->iface
);
232 static int hostapd_broadcast_wep_set(struct hostapd_data
*hapd
)
235 struct hostapd_ssid
*ssid
= &hapd
->conf
->ssid
;
238 if (ssid
->wep
.default_len
&&
239 hostapd_drv_set_key(hapd
->conf
->iface
,
240 hapd
, WPA_ALG_WEP
, broadcast_ether_addr
, idx
,
241 1, NULL
, 0, ssid
->wep
.key
[idx
],
242 ssid
->wep
.len
[idx
])) {
243 wpa_printf(MSG_WARNING
, "Could not set WEP encryption.");
251 static void hostapd_free_hapd_data(struct hostapd_data
*hapd
)
253 if (!hapd
->started
) {
254 wpa_printf(MSG_ERROR
, "%s: Interface %s wasn't started",
255 __func__
, hapd
->conf
->iface
);
260 wpa_printf(MSG_DEBUG
, "%s(%s)", __func__
, hapd
->conf
->iface
);
261 iapp_deinit(hapd
->iapp
);
263 accounting_deinit(hapd
);
264 hostapd_deinit_wpa(hapd
);
266 hostapd_acl_deinit(hapd
);
267 #ifndef CONFIG_NO_RADIUS
268 radius_client_deinit(hapd
->radius
);
270 radius_das_deinit(hapd
->radius_das
);
271 hapd
->radius_das
= NULL
;
272 #endif /* CONFIG_NO_RADIUS */
274 hostapd_deinit_wps(hapd
);
276 authsrv_deinit(hapd
);
278 if (hapd
->interface_added
&&
279 hostapd_if_remove(hapd
, WPA_IF_AP_BSS
, hapd
->conf
->iface
)) {
280 wpa_printf(MSG_WARNING
, "Failed to remove BSS interface %s",
284 os_free(hapd
->probereq_cb
);
285 hapd
->probereq_cb
= NULL
;
288 wpabuf_free(hapd
->p2p_beacon_ie
);
289 hapd
->p2p_beacon_ie
= NULL
;
290 wpabuf_free(hapd
->p2p_probe_resp_ie
);
291 hapd
->p2p_probe_resp_ie
= NULL
;
292 #endif /* CONFIG_P2P */
294 wpabuf_free(hapd
->time_adv
);
296 #ifdef CONFIG_INTERWORKING
297 gas_serv_deinit(hapd
);
298 #endif /* CONFIG_INTERWORKING */
301 os_free(hapd
->tmp_eap_user
.identity
);
302 os_free(hapd
->tmp_eap_user
.password
);
303 #endif /* CONFIG_SQLITE */
308 * hostapd_cleanup - Per-BSS cleanup (deinitialization)
309 * @hapd: Pointer to BSS data
311 * This function is used to free all per-BSS data structures and resources.
312 * Most of the modules that are initialized in hostapd_setup_bss() are
313 * deinitialized here.
315 static void hostapd_cleanup(struct hostapd_data
*hapd
)
317 wpa_printf(MSG_DEBUG
, "%s(hapd=%p (%s))", __func__
, hapd
,
319 if (hapd
->iface
->interfaces
&&
320 hapd
->iface
->interfaces
->ctrl_iface_deinit
)
321 hapd
->iface
->interfaces
->ctrl_iface_deinit(hapd
);
322 hostapd_free_hapd_data(hapd
);
326 static void hostapd_cleanup_iface_partial(struct hostapd_iface
*iface
)
328 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
329 hostapd_free_hw_features(iface
->hw_features
, iface
->num_hw_features
);
330 iface
->hw_features
= NULL
;
331 os_free(iface
->current_rates
);
332 iface
->current_rates
= NULL
;
333 os_free(iface
->basic_rates
);
334 iface
->basic_rates
= NULL
;
335 ap_list_deinit(iface
);
340 * hostapd_cleanup_iface - Complete per-interface cleanup
341 * @iface: Pointer to interface data
343 * This function is called after per-BSS data structures are deinitialized
344 * with hostapd_cleanup().
346 static void hostapd_cleanup_iface(struct hostapd_iface
*iface
)
348 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
349 eloop_cancel_timeout(channel_list_update_timeout
, iface
, NULL
);
351 hostapd_cleanup_iface_partial(iface
);
352 hostapd_config_free(iface
->conf
);
355 os_free(iface
->config_fname
);
357 wpa_printf(MSG_DEBUG
, "%s: free iface=%p", __func__
, iface
);
362 static void hostapd_clear_wep(struct hostapd_data
*hapd
)
364 if (hapd
->drv_priv
&& !hapd
->iface
->driver_ap_teardown
) {
365 hostapd_set_privacy(hapd
, 0);
366 hostapd_broadcast_wep_clear(hapd
);
371 static int hostapd_setup_encryption(char *iface
, struct hostapd_data
*hapd
)
375 hostapd_broadcast_wep_set(hapd
);
377 if (hapd
->conf
->ssid
.wep
.default_len
) {
378 hostapd_set_privacy(hapd
, 1);
383 * When IEEE 802.1X is not enabled, the driver may need to know how to
384 * set authentication algorithms for static WEP.
386 hostapd_drv_set_authmode(hapd
, hapd
->conf
->auth_algs
);
388 for (i
= 0; i
< 4; i
++) {
389 if (hapd
->conf
->ssid
.wep
.key
[i
] &&
390 hostapd_drv_set_key(iface
, hapd
, WPA_ALG_WEP
, NULL
, i
,
391 i
== hapd
->conf
->ssid
.wep
.idx
, NULL
, 0,
392 hapd
->conf
->ssid
.wep
.key
[i
],
393 hapd
->conf
->ssid
.wep
.len
[i
])) {
394 wpa_printf(MSG_WARNING
, "Could not set WEP "
398 if (hapd
->conf
->ssid
.wep
.key
[i
] &&
399 i
== hapd
->conf
->ssid
.wep
.idx
)
400 hostapd_set_privacy(hapd
, 1);
407 static int hostapd_flush_old_stations(struct hostapd_data
*hapd
, u16 reason
)
412 if (hostapd_drv_none(hapd
) || hapd
->drv_priv
== NULL
)
415 if (!hapd
->iface
->driver_ap_teardown
) {
416 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
,
417 "Flushing old station entries");
419 if (hostapd_flush(hapd
)) {
420 wpa_msg(hapd
->msg_ctx
, MSG_WARNING
,
421 "Could not connect to kernel driver");
425 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
, "Deauthenticate all stations");
426 os_memset(addr
, 0xff, ETH_ALEN
);
427 hostapd_drv_sta_deauth(hapd
, addr
, reason
);
428 hostapd_free_stas(hapd
);
435 * hostapd_validate_bssid_configuration - Validate BSSID configuration
436 * @iface: Pointer to interface data
437 * Returns: 0 on success, -1 on failure
439 * This function is used to validate that the configured BSSIDs are valid.
441 static int hostapd_validate_bssid_configuration(struct hostapd_iface
*iface
)
443 u8 mask
[ETH_ALEN
] = { 0 };
444 struct hostapd_data
*hapd
= iface
->bss
[0];
445 unsigned int i
= iface
->conf
->num_bss
, bits
= 0, j
;
448 if (hostapd_drv_none(hapd
))
451 /* Generate BSSID mask that is large enough to cover the BSSIDs. */
453 /* Determine the bits necessary to cover the number of BSSIDs. */
454 for (i
--; i
; i
>>= 1)
457 /* Determine the bits necessary to any configured BSSIDs,
458 if they are higher than the number of BSSIDs. */
459 for (j
= 0; j
< iface
->conf
->num_bss
; j
++) {
460 if (hostapd_mac_comp_empty(iface
->conf
->bss
[j
]->bssid
) == 0) {
466 for (i
= 0; i
< ETH_ALEN
; i
++) {
468 iface
->conf
->bss
[j
]->bssid
[i
] ^
476 for (i
= 0; i
< ETH_ALEN
&& mask
[i
] == 0; i
++)
482 while (mask
[i
] != 0) {
492 wpa_printf(MSG_ERROR
, "Too many bits in the BSSID mask (%u)",
497 os_memset(mask
, 0xff, ETH_ALEN
);
499 for (i
= 5; i
> 5 - j
; i
--)
506 wpa_printf(MSG_DEBUG
, "BSS count %lu, BSSID mask " MACSTR
" (%d bits)",
507 (unsigned long) iface
->conf
->num_bss
, MAC2STR(mask
), bits
);
512 for (i
= 0; i
< ETH_ALEN
; i
++) {
513 if ((hapd
->own_addr
[i
] & mask
[i
]) != hapd
->own_addr
[i
]) {
514 wpa_printf(MSG_ERROR
, "Invalid BSSID mask " MACSTR
515 " for start address " MACSTR
".",
516 MAC2STR(mask
), MAC2STR(hapd
->own_addr
));
517 wpa_printf(MSG_ERROR
, "Start address must be the "
518 "first address in the block (i.e., addr "
519 "AND mask == addr).");
528 static int mac_in_conf(struct hostapd_config
*conf
, const void *a
)
532 for (i
= 0; i
< conf
->num_bss
; i
++) {
533 if (hostapd_mac_comp(conf
->bss
[i
]->bssid
, a
) == 0) {
542 #ifndef CONFIG_NO_RADIUS
544 static int hostapd_das_nas_mismatch(struct hostapd_data
*hapd
,
545 struct radius_das_attrs
*attr
)
547 if (attr
->nas_identifier
&&
548 (!hapd
->conf
->nas_identifier
||
549 os_strlen(hapd
->conf
->nas_identifier
) !=
550 attr
->nas_identifier_len
||
551 os_memcmp(hapd
->conf
->nas_identifier
, attr
->nas_identifier
,
552 attr
->nas_identifier_len
) != 0)) {
553 wpa_printf(MSG_DEBUG
, "RADIUS DAS: NAS-Identifier mismatch");
557 if (attr
->nas_ip_addr
&&
558 (hapd
->conf
->own_ip_addr
.af
!= AF_INET
||
559 os_memcmp(&hapd
->conf
->own_ip_addr
.u
.v4
, attr
->nas_ip_addr
, 4) !=
561 wpa_printf(MSG_DEBUG
, "RADIUS DAS: NAS-IP-Address mismatch");
566 if (attr
->nas_ipv6_addr
&&
567 (hapd
->conf
->own_ip_addr
.af
!= AF_INET6
||
568 os_memcmp(&hapd
->conf
->own_ip_addr
.u
.v6
, attr
->nas_ipv6_addr
, 16)
570 wpa_printf(MSG_DEBUG
, "RADIUS DAS: NAS-IPv6-Address mismatch");
573 #endif /* CONFIG_IPV6 */
579 static struct sta_info
* hostapd_das_find_sta(struct hostapd_data
*hapd
,
580 struct radius_das_attrs
*attr
)
582 struct sta_info
*sta
= NULL
;
586 sta
= ap_get_sta(hapd
, attr
->sta_addr
);
588 if (sta
== NULL
&& attr
->acct_session_id
&&
589 attr
->acct_session_id_len
== 17) {
590 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
591 os_snprintf(buf
, sizeof(buf
), "%08X-%08X",
592 sta
->acct_session_id_hi
,
593 sta
->acct_session_id_lo
);
594 if (os_memcmp(attr
->acct_session_id
, buf
, 17) == 0)
599 if (sta
== NULL
&& attr
->cui
) {
600 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
602 cui
= ieee802_1x_get_radius_cui(sta
->eapol_sm
);
603 if (cui
&& wpabuf_len(cui
) == attr
->cui_len
&&
604 os_memcmp(wpabuf_head(cui
), attr
->cui
,
610 if (sta
== NULL
&& attr
->user_name
) {
611 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
614 identity
= ieee802_1x_get_identity(sta
->eapol_sm
,
617 identity_len
== attr
->user_name_len
&&
618 os_memcmp(identity
, attr
->user_name
, identity_len
)
628 static enum radius_das_res
629 hostapd_das_disconnect(void *ctx
, struct radius_das_attrs
*attr
)
631 struct hostapd_data
*hapd
= ctx
;
632 struct sta_info
*sta
;
634 if (hostapd_das_nas_mismatch(hapd
, attr
))
635 return RADIUS_DAS_NAS_MISMATCH
;
637 sta
= hostapd_das_find_sta(hapd
, attr
);
639 return RADIUS_DAS_SESSION_NOT_FOUND
;
641 wpa_auth_pmksa_remove(hapd
->wpa_auth
, sta
->addr
);
643 hostapd_drv_sta_deauth(hapd
, sta
->addr
,
644 WLAN_REASON_PREV_AUTH_NOT_VALID
);
645 ap_sta_deauthenticate(hapd
, sta
, WLAN_REASON_PREV_AUTH_NOT_VALID
);
647 return RADIUS_DAS_SUCCESS
;
650 #endif /* CONFIG_NO_RADIUS */
654 * hostapd_setup_bss - Per-BSS setup (initialization)
655 * @hapd: Pointer to BSS data
656 * @first: Whether this BSS is the first BSS of an interface; -1 = not first,
657 * but interface may exist
659 * This function is used to initialize all per-BSS data structures and
660 * resources. This gets called in a loop for each BSS when an interface is
661 * initialized. Most of the modules that are initialized here will be
662 * deinitialized in hostapd_cleanup().
664 static int hostapd_setup_bss(struct hostapd_data
*hapd
, int first
)
666 struct hostapd_bss_config
*conf
= hapd
->conf
;
667 u8 ssid
[HOSTAPD_MAX_SSID_LEN
+ 1];
668 int ssid_len
, set_ssid
;
669 char force_ifname
[IFNAMSIZ
];
670 u8 if_addr
[ETH_ALEN
];
672 wpa_printf(MSG_DEBUG
, "%s(hapd=%p (%s), first=%d)",
673 __func__
, hapd
, hapd
->conf
->iface
, first
);
676 wpa_printf(MSG_ERROR
, "%s: Interface %s was already started",
677 __func__
, hapd
->conf
->iface
);
682 if (!first
|| first
== -1) {
683 if (hostapd_mac_comp_empty(hapd
->conf
->bssid
) == 0) {
684 /* Allocate the next available BSSID. */
686 inc_byte_array(hapd
->own_addr
, ETH_ALEN
);
687 } while (mac_in_conf(hapd
->iconf
, hapd
->own_addr
));
689 /* Allocate the configured BSSID. */
690 os_memcpy(hapd
->own_addr
, hapd
->conf
->bssid
, ETH_ALEN
);
692 if (hostapd_mac_comp(hapd
->own_addr
,
693 hapd
->iface
->bss
[0]->own_addr
) ==
695 wpa_printf(MSG_ERROR
, "BSS '%s' may not have "
696 "BSSID set to the MAC address of "
697 "the radio", hapd
->conf
->iface
);
702 hapd
->interface_added
= 1;
703 if (hostapd_if_add(hapd
->iface
->bss
[0], WPA_IF_AP_BSS
,
704 hapd
->conf
->iface
, hapd
->own_addr
, hapd
,
705 &hapd
->drv_priv
, force_ifname
, if_addr
,
706 hapd
->conf
->bridge
[0] ? hapd
->conf
->bridge
:
707 NULL
, first
== -1)) {
708 wpa_printf(MSG_ERROR
, "Failed to add BSS (BSSID="
709 MACSTR
")", MAC2STR(hapd
->own_addr
));
710 hapd
->interface_added
= 0;
715 if (conf
->wmm_enabled
< 0)
716 conf
->wmm_enabled
= hapd
->iconf
->ieee80211n
;
718 hostapd_flush_old_stations(hapd
, WLAN_REASON_PREV_AUTH_NOT_VALID
);
719 hostapd_set_privacy(hapd
, 0);
721 hostapd_broadcast_wep_clear(hapd
);
722 if (hostapd_setup_encryption(hapd
->conf
->iface
, hapd
))
726 * Fetch the SSID from the system and use it or,
727 * if one was specified in the config file, verify they
730 ssid_len
= hostapd_get_ssid(hapd
, ssid
, sizeof(ssid
));
732 wpa_printf(MSG_ERROR
, "Could not read SSID from system");
735 if (conf
->ssid
.ssid_set
) {
737 * If SSID is specified in the config file and it differs
738 * from what is being used then force installation of the
741 set_ssid
= (conf
->ssid
.ssid_len
!= (size_t) ssid_len
||
742 os_memcmp(conf
->ssid
.ssid
, ssid
, ssid_len
) != 0);
745 * No SSID in the config file; just use the one we got
749 conf
->ssid
.ssid_len
= ssid_len
;
750 os_memcpy(conf
->ssid
.ssid
, ssid
, conf
->ssid
.ssid_len
);
753 if (!hostapd_drv_none(hapd
)) {
754 wpa_printf(MSG_ERROR
, "Using interface %s with hwaddr " MACSTR
756 hapd
->conf
->iface
, MAC2STR(hapd
->own_addr
),
757 wpa_ssid_txt(hapd
->conf
->ssid
.ssid
,
758 hapd
->conf
->ssid
.ssid_len
));
761 if (hostapd_setup_wpa_psk(conf
)) {
762 wpa_printf(MSG_ERROR
, "WPA-PSK setup failed.");
766 /* Set SSID for the kernel driver (to be used in beacon and probe
767 * response frames) */
768 if (set_ssid
&& hostapd_set_ssid(hapd
, conf
->ssid
.ssid
,
769 conf
->ssid
.ssid_len
)) {
770 wpa_printf(MSG_ERROR
, "Could not set SSID for kernel driver");
774 if (wpa_debug_level
<= MSG_MSGDUMP
)
775 conf
->radius
->msg_dumps
= 1;
776 #ifndef CONFIG_NO_RADIUS
777 hapd
->radius
= radius_client_init(hapd
, conf
->radius
);
778 if (hapd
->radius
== NULL
) {
779 wpa_printf(MSG_ERROR
, "RADIUS client initialization failed.");
783 if (hapd
->conf
->radius_das_port
) {
784 struct radius_das_conf das_conf
;
785 os_memset(&das_conf
, 0, sizeof(das_conf
));
786 das_conf
.port
= hapd
->conf
->radius_das_port
;
787 das_conf
.shared_secret
= hapd
->conf
->radius_das_shared_secret
;
788 das_conf
.shared_secret_len
=
789 hapd
->conf
->radius_das_shared_secret_len
;
790 das_conf
.client_addr
= &hapd
->conf
->radius_das_client_addr
;
791 das_conf
.time_window
= hapd
->conf
->radius_das_time_window
;
792 das_conf
.require_event_timestamp
=
793 hapd
->conf
->radius_das_require_event_timestamp
;
795 das_conf
.disconnect
= hostapd_das_disconnect
;
796 hapd
->radius_das
= radius_das_init(&das_conf
);
797 if (hapd
->radius_das
== NULL
) {
798 wpa_printf(MSG_ERROR
, "RADIUS DAS initialization "
803 #endif /* CONFIG_NO_RADIUS */
805 if (hostapd_acl_init(hapd
)) {
806 wpa_printf(MSG_ERROR
, "ACL initialization failed.");
809 if (hostapd_init_wps(hapd
, conf
))
812 if (authsrv_init(hapd
) < 0)
815 if (ieee802_1x_init(hapd
)) {
816 wpa_printf(MSG_ERROR
, "IEEE 802.1X initialization failed.");
820 if ((hapd
->conf
->wpa
|| hapd
->conf
->osen
) && hostapd_setup_wpa(hapd
))
823 if (accounting_init(hapd
)) {
824 wpa_printf(MSG_ERROR
, "Accounting initialization failed.");
828 if (hapd
->conf
->ieee802_11f
&&
829 (hapd
->iapp
= iapp_init(hapd
, hapd
->conf
->iapp_iface
)) == NULL
) {
830 wpa_printf(MSG_ERROR
, "IEEE 802.11F (IAPP) initialization "
835 #ifdef CONFIG_INTERWORKING
836 if (gas_serv_init(hapd
)) {
837 wpa_printf(MSG_ERROR
, "GAS server initialization failed");
841 if (conf
->qos_map_set_len
&&
842 hostapd_drv_set_qos_map(hapd
, conf
->qos_map_set
,
843 conf
->qos_map_set_len
)) {
844 wpa_printf(MSG_ERROR
, "Failed to initialize QoS Map");
847 #endif /* CONFIG_INTERWORKING */
849 if (!hostapd_drv_none(hapd
) && vlan_init(hapd
)) {
850 wpa_printf(MSG_ERROR
, "VLAN initialization failed.");
854 if (!hapd
->conf
->start_disabled
&& ieee802_11_set_beacon(hapd
) < 0)
857 if (hapd
->wpa_auth
&& wpa_init_keys(hapd
->wpa_auth
) < 0)
860 if (hapd
->driver
&& hapd
->driver
->set_operstate
)
861 hapd
->driver
->set_operstate(hapd
->drv_priv
, 1);
867 static void hostapd_tx_queue_params(struct hostapd_iface
*iface
)
869 struct hostapd_data
*hapd
= iface
->bss
[0];
871 struct hostapd_tx_queue_params
*p
;
873 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
874 p
= &iface
->conf
->tx_queue
[i
];
876 if (hostapd_set_tx_queue_params(hapd
, i
, p
->aifs
, p
->cwmin
,
877 p
->cwmax
, p
->burst
)) {
878 wpa_printf(MSG_DEBUG
, "Failed to set TX queue "
879 "parameters for queue %d.", i
);
880 /* Continue anyway */
886 static int hostapd_set_acl_list(struct hostapd_data
*hapd
,
887 struct mac_acl_entry
*mac_acl
,
888 int n_entries
, u8 accept_acl
)
890 struct hostapd_acl_params
*acl_params
;
893 acl_params
= os_zalloc(sizeof(*acl_params
) +
894 (n_entries
* sizeof(acl_params
->mac_acl
[0])));
898 for (i
= 0; i
< n_entries
; i
++)
899 os_memcpy(acl_params
->mac_acl
[i
].addr
, mac_acl
[i
].addr
,
902 acl_params
->acl_policy
= accept_acl
;
903 acl_params
->num_mac_acl
= n_entries
;
905 err
= hostapd_drv_set_acl(hapd
, acl_params
);
913 static void hostapd_set_acl(struct hostapd_data
*hapd
)
915 struct hostapd_config
*conf
= hapd
->iconf
;
919 if (hapd
->iface
->drv_max_acl_mac_addrs
== 0)
921 if (!(conf
->bss
[0]->num_accept_mac
|| conf
->bss
[0]->num_deny_mac
))
924 if (conf
->bss
[0]->macaddr_acl
== DENY_UNLESS_ACCEPTED
) {
925 if (conf
->bss
[0]->num_accept_mac
) {
927 err
= hostapd_set_acl_list(hapd
,
928 conf
->bss
[0]->accept_mac
,
929 conf
->bss
[0]->num_accept_mac
,
932 wpa_printf(MSG_DEBUG
, "Failed to set accept acl");
936 wpa_printf(MSG_DEBUG
, "Mismatch between ACL Policy & Accept/deny lists file");
938 } else if (conf
->bss
[0]->macaddr_acl
== ACCEPT_UNLESS_DENIED
) {
939 if (conf
->bss
[0]->num_deny_mac
) {
941 err
= hostapd_set_acl_list(hapd
, conf
->bss
[0]->deny_mac
,
942 conf
->bss
[0]->num_deny_mac
,
945 wpa_printf(MSG_DEBUG
, "Failed to set deny acl");
949 wpa_printf(MSG_DEBUG
, "Mismatch between ACL Policy & Accept/deny lists file");
955 static int start_ctrl_iface_bss(struct hostapd_data
*hapd
)
957 if (!hapd
->iface
->interfaces
||
958 !hapd
->iface
->interfaces
->ctrl_iface_init
)
961 if (hapd
->iface
->interfaces
->ctrl_iface_init(hapd
)) {
962 wpa_printf(MSG_ERROR
,
963 "Failed to setup control interface for %s",
972 static int start_ctrl_iface(struct hostapd_iface
*iface
)
976 if (!iface
->interfaces
|| !iface
->interfaces
->ctrl_iface_init
)
979 for (i
= 0; i
< iface
->num_bss
; i
++) {
980 struct hostapd_data
*hapd
= iface
->bss
[i
];
981 if (iface
->interfaces
->ctrl_iface_init(hapd
)) {
982 wpa_printf(MSG_ERROR
,
983 "Failed to setup control interface for %s",
993 static void channel_list_update_timeout(void *eloop_ctx
, void *timeout_ctx
)
995 struct hostapd_iface
*iface
= eloop_ctx
;
997 if (!iface
->wait_channel_update
) {
998 wpa_printf(MSG_INFO
, "Channel list update timeout, but interface was not waiting for it");
1003 * It is possible that the existing channel list is acceptable, so try
1006 wpa_printf(MSG_DEBUG
, "Channel list update timeout - try to continue anyway");
1007 setup_interface2(iface
);
1011 void hostapd_channel_list_updated(struct hostapd_iface
*iface
, int initiator
)
1013 if (!iface
->wait_channel_update
|| initiator
!= REGDOM_SET_BY_USER
)
1016 wpa_printf(MSG_DEBUG
, "Channel list updated - continue setup");
1017 eloop_cancel_timeout(channel_list_update_timeout
, iface
, NULL
);
1018 setup_interface2(iface
);
1022 static int setup_interface(struct hostapd_iface
*iface
)
1024 struct hostapd_data
*hapd
= iface
->bss
[0];
1028 * It is possible that setup_interface() is called after the interface
1029 * was disabled etc., in which case driver_ap_teardown is possibly set
1030 * to 1. Clear it here so any other key/station deletion, which is not
1031 * part of a teardown flow, would also call the relevant driver
1034 iface
->driver_ap_teardown
= 0;
1036 if (!iface
->phy
[0]) {
1037 const char *phy
= hostapd_drv_get_radio_name(hapd
);
1039 wpa_printf(MSG_DEBUG
, "phy: %s", phy
);
1040 os_strlcpy(iface
->phy
, phy
, sizeof(iface
->phy
));
1045 * Make sure that all BSSes get configured with a pointer to the same
1048 for (i
= 1; i
< iface
->num_bss
; i
++) {
1049 iface
->bss
[i
]->driver
= hapd
->driver
;
1050 iface
->bss
[i
]->drv_priv
= hapd
->drv_priv
;
1053 if (hostapd_validate_bssid_configuration(iface
))
1057 * Initialize control interfaces early to allow external monitoring of
1058 * channel setup operations that may take considerable amount of time
1059 * especially for DFS cases.
1061 if (start_ctrl_iface(iface
))
1064 if (hapd
->iconf
->country
[0] && hapd
->iconf
->country
[1]) {
1065 char country
[4], previous_country
[4];
1067 hostapd_set_state(iface
, HAPD_IFACE_COUNTRY_UPDATE
);
1068 if (hostapd_get_country(hapd
, previous_country
) < 0)
1069 previous_country
[0] = '\0';
1071 os_memcpy(country
, hapd
->iconf
->country
, 3);
1073 if (hostapd_set_country(hapd
, country
) < 0) {
1074 wpa_printf(MSG_ERROR
, "Failed to set country code");
1078 wpa_printf(MSG_DEBUG
, "Previous country code %s, new country code %s",
1079 previous_country
, country
);
1081 if (os_strncmp(previous_country
, country
, 2) != 0) {
1082 wpa_printf(MSG_DEBUG
, "Continue interface setup after channel list update");
1083 iface
->wait_channel_update
= 1;
1084 eloop_register_timeout(5, 0,
1085 channel_list_update_timeout
,
1091 return setup_interface2(iface
);
1095 static int setup_interface2(struct hostapd_iface
*iface
)
1097 iface
->wait_channel_update
= 0;
1099 if (hostapd_get_hw_features(iface
)) {
1100 /* Not all drivers support this yet, so continue without hw
1103 int ret
= hostapd_select_hw_mode(iface
);
1105 wpa_printf(MSG_ERROR
, "Could not select hw_mode and "
1106 "channel. (%d)", ret
);
1110 wpa_printf(MSG_DEBUG
, "Interface initialization will be completed in a callback (ACS)");
1113 ret
= hostapd_check_ht_capab(iface
);
1117 wpa_printf(MSG_DEBUG
, "Interface initialization will "
1118 "be completed in a callback");
1122 if (iface
->conf
->ieee80211h
)
1123 wpa_printf(MSG_DEBUG
, "DFS support is enabled");
1125 return hostapd_setup_interface_complete(iface
, 0);
1128 hostapd_set_state(iface
, HAPD_IFACE_DISABLED
);
1129 wpa_msg(iface
->bss
[0]->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
1130 if (iface
->interfaces
&& iface
->interfaces
->terminate_on_error
)
1137 * hostapd_setup_interface_complete - Complete interface setup
1139 * This function is called when previous steps in the interface setup has been
1140 * completed. This can also start operations, e.g., DFS, that will require
1141 * additional processing before interface is ready to be enabled. Such
1142 * operations will call this function from eloop callbacks when finished.
1144 int hostapd_setup_interface_complete(struct hostapd_iface
*iface
, int err
)
1146 struct hostapd_data
*hapd
= iface
->bss
[0];
1153 wpa_printf(MSG_DEBUG
, "Completing interface initialization");
1154 if (iface
->conf
->channel
) {
1157 #endif /* NEED_AP_MLME */
1159 iface
->freq
= hostapd_hw_get_freq(hapd
, iface
->conf
->channel
);
1160 wpa_printf(MSG_DEBUG
, "Mode: %s Channel: %d "
1161 "Frequency: %d MHz",
1162 hostapd_hw_mode_txt(iface
->conf
->hw_mode
),
1163 iface
->conf
->channel
, iface
->freq
);
1167 res
= hostapd_handle_dfs(iface
);
1173 #endif /* NEED_AP_MLME */
1175 if (hostapd_set_freq(hapd
, hapd
->iconf
->hw_mode
, iface
->freq
,
1176 hapd
->iconf
->channel
,
1177 hapd
->iconf
->ieee80211n
,
1178 hapd
->iconf
->ieee80211ac
,
1179 hapd
->iconf
->secondary_channel
,
1180 hapd
->iconf
->vht_oper_chwidth
,
1181 hapd
->iconf
->vht_oper_centr_freq_seg0_idx
,
1182 hapd
->iconf
->vht_oper_centr_freq_seg1_idx
)) {
1183 wpa_printf(MSG_ERROR
, "Could not set channel for "
1189 if (iface
->current_mode
) {
1190 if (hostapd_prepare_rates(iface
, iface
->current_mode
)) {
1191 wpa_printf(MSG_ERROR
, "Failed to prepare rates "
1193 hostapd_logger(hapd
, NULL
, HOSTAPD_MODULE_IEEE80211
,
1194 HOSTAPD_LEVEL_WARNING
,
1195 "Failed to prepare rates table.");
1200 if (hapd
->iconf
->rts_threshold
> -1 &&
1201 hostapd_set_rts(hapd
, hapd
->iconf
->rts_threshold
)) {
1202 wpa_printf(MSG_ERROR
, "Could not set RTS threshold for "
1207 if (hapd
->iconf
->fragm_threshold
> -1 &&
1208 hostapd_set_frag(hapd
, hapd
->iconf
->fragm_threshold
)) {
1209 wpa_printf(MSG_ERROR
, "Could not set fragmentation threshold "
1210 "for kernel driver");
1214 prev_addr
= hapd
->own_addr
;
1216 for (j
= 0; j
< iface
->num_bss
; j
++) {
1217 hapd
= iface
->bss
[j
];
1219 os_memcpy(hapd
->own_addr
, prev_addr
, ETH_ALEN
);
1220 if (hostapd_setup_bss(hapd
, j
== 0))
1222 if (hostapd_mac_comp_empty(hapd
->conf
->bssid
) == 0)
1223 prev_addr
= hapd
->own_addr
;
1225 hapd
= iface
->bss
[0];
1227 hostapd_tx_queue_params(iface
);
1229 ap_list_init(iface
);
1231 hostapd_set_acl(hapd
);
1233 if (hostapd_driver_commit(hapd
) < 0) {
1234 wpa_printf(MSG_ERROR
, "%s: Failed to commit driver "
1235 "configuration", __func__
);
1240 * WPS UPnP module can be initialized only when the "upnp_iface" is up.
1241 * If "interface" and "upnp_iface" are the same (e.g., non-bridge
1242 * mode), the interface is up only after driver_commit, so initialize
1243 * WPS after driver_commit.
1245 for (j
= 0; j
< iface
->num_bss
; j
++) {
1246 if (hostapd_init_wps_complete(iface
->bss
[j
]))
1250 hostapd_set_state(iface
, HAPD_IFACE_ENABLED
);
1251 wpa_msg(iface
->bss
[0]->msg_ctx
, MSG_INFO
, AP_EVENT_ENABLED
);
1252 if (hapd
->setup_complete_cb
)
1253 hapd
->setup_complete_cb(hapd
->setup_complete_cb_ctx
);
1255 wpa_printf(MSG_DEBUG
, "%s: Setup of interface done.",
1256 iface
->bss
[0]->conf
->iface
);
1257 if (iface
->interfaces
&& iface
->interfaces
->terminate_on_error
> 0)
1258 iface
->interfaces
->terminate_on_error
--;
1263 wpa_printf(MSG_ERROR
, "Interface initialization failed");
1264 hostapd_set_state(iface
, HAPD_IFACE_DISABLED
);
1265 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
1266 if (iface
->interfaces
&& iface
->interfaces
->terminate_on_error
)
1273 * hostapd_setup_interface - Setup of an interface
1274 * @iface: Pointer to interface data.
1275 * Returns: 0 on success, -1 on failure
1277 * Initializes the driver interface, validates the configuration,
1278 * and sets driver parameters based on the configuration.
1279 * Flushes old stations, sets the channel, encryption,
1280 * beacons, and WDS links based on the configuration.
1282 * If interface setup requires more time, e.g., to perform HT co-ex scans, ACS,
1283 * or DFS operations, this function returns 0 before such operations have been
1284 * completed. The pending operations are registered into eloop and will be
1285 * completed from eloop callbacks. Those callbacks end up calling
1286 * hostapd_setup_interface_complete() once setup has been completed.
1288 int hostapd_setup_interface(struct hostapd_iface
*iface
)
1292 ret
= setup_interface(iface
);
1294 wpa_printf(MSG_ERROR
, "%s: Unable to setup interface.",
1295 iface
->bss
[0]->conf
->iface
);
1304 * hostapd_alloc_bss_data - Allocate and initialize per-BSS data
1305 * @hapd_iface: Pointer to interface data
1306 * @conf: Pointer to per-interface configuration
1307 * @bss: Pointer to per-BSS configuration for this BSS
1308 * Returns: Pointer to allocated BSS data
1310 * This function is used to allocate per-BSS data structure. This data will be
1311 * freed after hostapd_cleanup() is called for it during interface
1314 struct hostapd_data
*
1315 hostapd_alloc_bss_data(struct hostapd_iface
*hapd_iface
,
1316 struct hostapd_config
*conf
,
1317 struct hostapd_bss_config
*bss
)
1319 struct hostapd_data
*hapd
;
1321 hapd
= os_zalloc(sizeof(*hapd
));
1325 hapd
->new_assoc_sta_cb
= hostapd_new_assoc_sta
;
1328 hapd
->iface
= hapd_iface
;
1329 hapd
->driver
= hapd
->iconf
->driver
;
1330 hapd
->ctrl_sock
= -1;
1336 static void hostapd_bss_deinit(struct hostapd_data
*hapd
)
1338 wpa_printf(MSG_DEBUG
, "%s: deinit bss %s", __func__
,
1340 hostapd_free_stas(hapd
);
1341 hostapd_flush_old_stations(hapd
, WLAN_REASON_DEAUTH_LEAVING
);
1342 hostapd_clear_wep(hapd
);
1343 hostapd_cleanup(hapd
);
1347 void hostapd_interface_deinit(struct hostapd_iface
*iface
)
1351 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
1355 eloop_cancel_timeout(channel_list_update_timeout
, iface
, NULL
);
1356 iface
->wait_channel_update
= 0;
1358 for (j
= iface
->num_bss
- 1; j
>= 0; j
--)
1359 hostapd_bss_deinit(iface
->bss
[j
]);
1363 void hostapd_interface_free(struct hostapd_iface
*iface
)
1366 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
1367 for (j
= 0; j
< iface
->num_bss
; j
++) {
1368 wpa_printf(MSG_DEBUG
, "%s: free hapd %p",
1369 __func__
, iface
->bss
[j
]);
1370 os_free(iface
->bss
[j
]);
1372 hostapd_cleanup_iface(iface
);
1377 * hostapd_init - Allocate and initialize per-interface data
1378 * @config_file: Path to the configuration file
1379 * Returns: Pointer to the allocated interface data or %NULL on failure
1381 * This function is used to allocate main data structures for per-interface
1382 * data. The allocated data buffer will be freed by calling
1383 * hostapd_cleanup_iface().
1385 struct hostapd_iface
* hostapd_init(struct hapd_interfaces
*interfaces
,
1386 const char *config_file
)
1388 struct hostapd_iface
*hapd_iface
= NULL
;
1389 struct hostapd_config
*conf
= NULL
;
1390 struct hostapd_data
*hapd
;
1393 hapd_iface
= os_zalloc(sizeof(*hapd_iface
));
1394 if (hapd_iface
== NULL
)
1397 hapd_iface
->config_fname
= os_strdup(config_file
);
1398 if (hapd_iface
->config_fname
== NULL
)
1401 conf
= interfaces
->config_read_cb(hapd_iface
->config_fname
);
1404 hapd_iface
->conf
= conf
;
1406 hapd_iface
->num_bss
= conf
->num_bss
;
1407 hapd_iface
->bss
= os_calloc(conf
->num_bss
,
1408 sizeof(struct hostapd_data
*));
1409 if (hapd_iface
->bss
== NULL
)
1412 for (i
= 0; i
< conf
->num_bss
; i
++) {
1413 hapd
= hapd_iface
->bss
[i
] =
1414 hostapd_alloc_bss_data(hapd_iface
, conf
,
1418 hapd
->msg_ctx
= hapd
;
1424 wpa_printf(MSG_ERROR
, "Failed to set up interface with %s",
1427 hostapd_config_free(conf
);
1429 os_free(hapd_iface
->config_fname
);
1430 os_free(hapd_iface
->bss
);
1431 wpa_printf(MSG_DEBUG
, "%s: free iface %p",
1432 __func__
, hapd_iface
);
1433 os_free(hapd_iface
);
1439 static int ifname_in_use(struct hapd_interfaces
*interfaces
, const char *ifname
)
1443 for (i
= 0; i
< interfaces
->count
; i
++) {
1444 struct hostapd_iface
*iface
= interfaces
->iface
[i
];
1445 for (j
= 0; j
< iface
->num_bss
; j
++) {
1446 struct hostapd_data
*hapd
= iface
->bss
[j
];
1447 if (os_strcmp(ifname
, hapd
->conf
->iface
) == 0)
1457 * hostapd_interface_init_bss - Read configuration file and init BSS data
1459 * This function is used to parse configuration file for a BSS. This BSS is
1460 * added to an existing interface sharing the same radio (if any) or a new
1461 * interface is created if this is the first interface on a radio. This
1462 * allocate memory for the BSS. No actual driver operations are started.
1464 * This is similar to hostapd_interface_init(), but for a case where the
1465 * configuration is used to add a single BSS instead of all BSSes for a radio.
1467 struct hostapd_iface
*
1468 hostapd_interface_init_bss(struct hapd_interfaces
*interfaces
, const char *phy
,
1469 const char *config_fname
, int debug
)
1471 struct hostapd_iface
*new_iface
= NULL
, *iface
= NULL
;
1472 struct hostapd_data
*hapd
;
1479 for (i
= 0; i
< interfaces
->count
; i
++) {
1480 if (os_strcmp(interfaces
->iface
[i
]->phy
, phy
) == 0) {
1481 iface
= interfaces
->iface
[i
];
1486 wpa_printf(MSG_INFO
, "Configuration file: %s (phy %s)%s",
1487 config_fname
, phy
, iface
? "" : " --> new PHY");
1489 struct hostapd_config
*conf
;
1490 struct hostapd_bss_config
**tmp_conf
;
1491 struct hostapd_data
**tmp_bss
;
1492 struct hostapd_bss_config
*bss
;
1495 /* Add new BSS to existing iface */
1496 conf
= interfaces
->config_read_cb(config_fname
);
1499 if (conf
->num_bss
> 1) {
1500 wpa_printf(MSG_ERROR
, "Multiple BSSes specified in BSS-config");
1501 hostapd_config_free(conf
);
1505 ifname
= conf
->bss
[0]->iface
;
1506 if (ifname
[0] != '\0' && ifname_in_use(interfaces
, ifname
)) {
1507 wpa_printf(MSG_ERROR
,
1508 "Interface name %s already in use", ifname
);
1509 hostapd_config_free(conf
);
1513 tmp_conf
= os_realloc_array(
1514 iface
->conf
->bss
, iface
->conf
->num_bss
+ 1,
1515 sizeof(struct hostapd_bss_config
*));
1516 tmp_bss
= os_realloc_array(iface
->bss
, iface
->num_bss
+ 1,
1517 sizeof(struct hostapd_data
*));
1519 iface
->bss
= tmp_bss
;
1521 iface
->conf
->bss
= tmp_conf
;
1522 iface
->conf
->last_bss
= tmp_conf
[0];
1524 if (tmp_bss
== NULL
|| tmp_conf
== NULL
) {
1525 hostapd_config_free(conf
);
1528 bss
= iface
->conf
->bss
[iface
->conf
->num_bss
] = conf
->bss
[0];
1529 iface
->conf
->num_bss
++;
1531 hapd
= hostapd_alloc_bss_data(iface
, iface
->conf
, bss
);
1533 iface
->conf
->num_bss
--;
1534 hostapd_config_free(conf
);
1537 iface
->conf
->last_bss
= bss
;
1538 iface
->bss
[iface
->num_bss
] = hapd
;
1539 hapd
->msg_ctx
= hapd
;
1541 bss_idx
= iface
->num_bss
++;
1543 conf
->bss
[0] = NULL
;
1544 hostapd_config_free(conf
);
1546 /* Add a new iface with the first BSS */
1547 new_iface
= iface
= hostapd_init(interfaces
, config_fname
);
1550 os_strlcpy(iface
->phy
, phy
, sizeof(iface
->phy
));
1551 iface
->interfaces
= interfaces
;
1555 for (k
= 0; k
< debug
; k
++) {
1556 if (iface
->bss
[bss_idx
]->conf
->logger_stdout_level
> 0)
1557 iface
->bss
[bss_idx
]->conf
->logger_stdout_level
--;
1560 if (iface
->conf
->bss
[bss_idx
]->iface
[0] == '\0' &&
1561 !hostapd_drv_none(iface
->bss
[bss_idx
])) {
1562 wpa_printf(MSG_ERROR
, "Interface name not specified in %s",
1565 hostapd_interface_deinit_free(new_iface
);
1573 void hostapd_interface_deinit_free(struct hostapd_iface
*iface
)
1575 const struct wpa_driver_ops
*driver
;
1578 wpa_printf(MSG_DEBUG
, "%s(%p)", __func__
, iface
);
1581 wpa_printf(MSG_DEBUG
, "%s: num_bss=%u conf->num_bss=%u",
1582 __func__
, (unsigned int) iface
->num_bss
,
1583 (unsigned int) iface
->conf
->num_bss
);
1584 driver
= iface
->bss
[0]->driver
;
1585 drv_priv
= iface
->bss
[0]->drv_priv
;
1586 hostapd_interface_deinit(iface
);
1587 wpa_printf(MSG_DEBUG
, "%s: driver=%p drv_priv=%p -> hapd_deinit",
1588 __func__
, driver
, drv_priv
);
1589 if (driver
&& driver
->hapd_deinit
&& drv_priv
)
1590 driver
->hapd_deinit(drv_priv
);
1591 hostapd_interface_free(iface
);
1595 static void hostapd_deinit_driver(const struct wpa_driver_ops
*driver
,
1597 struct hostapd_iface
*hapd_iface
)
1601 wpa_printf(MSG_DEBUG
, "%s: driver=%p drv_priv=%p -> hapd_deinit",
1602 __func__
, driver
, drv_priv
);
1603 if (driver
&& driver
->hapd_deinit
&& drv_priv
) {
1604 driver
->hapd_deinit(drv_priv
);
1605 for (j
= 0; j
< hapd_iface
->num_bss
; j
++) {
1606 wpa_printf(MSG_DEBUG
, "%s:bss[%d]->drv_priv=%p",
1608 hapd_iface
->bss
[j
]->drv_priv
);
1609 if (hapd_iface
->bss
[j
]->drv_priv
== drv_priv
)
1610 hapd_iface
->bss
[j
]->drv_priv
= NULL
;
1616 int hostapd_enable_iface(struct hostapd_iface
*hapd_iface
)
1618 if (hapd_iface
->bss
[0]->drv_priv
!= NULL
) {
1619 wpa_printf(MSG_ERROR
, "Interface %s already enabled",
1620 hapd_iface
->conf
->bss
[0]->iface
);
1624 wpa_printf(MSG_DEBUG
, "Enable interface %s",
1625 hapd_iface
->conf
->bss
[0]->iface
);
1627 if (hostapd_config_check(hapd_iface
->conf
, 1) < 0) {
1628 wpa_printf(MSG_INFO
, "Invalid configuration - cannot enable");
1632 if (hapd_iface
->interfaces
== NULL
||
1633 hapd_iface
->interfaces
->driver_init
== NULL
||
1634 hapd_iface
->interfaces
->driver_init(hapd_iface
))
1637 if (hostapd_setup_interface(hapd_iface
)) {
1638 hostapd_deinit_driver(hapd_iface
->bss
[0]->driver
,
1639 hapd_iface
->bss
[0]->drv_priv
,
1648 int hostapd_reload_iface(struct hostapd_iface
*hapd_iface
)
1652 wpa_printf(MSG_DEBUG
, "Reload interface %s",
1653 hapd_iface
->conf
->bss
[0]->iface
);
1654 for (j
= 0; j
< hapd_iface
->num_bss
; j
++)
1655 hostapd_set_security_params(hapd_iface
->conf
->bss
[j
]);
1656 if (hostapd_config_check(hapd_iface
->conf
, 1) < 0) {
1657 wpa_printf(MSG_ERROR
, "Updated configuration is invalid");
1660 hostapd_clear_old(hapd_iface
);
1661 for (j
= 0; j
< hapd_iface
->num_bss
; j
++)
1662 hostapd_reload_bss(hapd_iface
->bss
[j
]);
1668 int hostapd_disable_iface(struct hostapd_iface
*hapd_iface
)
1671 const struct wpa_driver_ops
*driver
;
1674 if (hapd_iface
== NULL
)
1676 wpa_msg(hapd_iface
->bss
[0]->msg_ctx
, MSG_INFO
, AP_EVENT_DISABLED
);
1677 driver
= hapd_iface
->bss
[0]->driver
;
1678 drv_priv
= hapd_iface
->bss
[0]->drv_priv
;
1680 hapd_iface
->driver_ap_teardown
=
1681 !!(hapd_iface
->drv_flags
&
1682 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT
);
1684 /* same as hostapd_interface_deinit without deinitializing ctrl-iface */
1685 for (j
= 0; j
< hapd_iface
->num_bss
; j
++) {
1686 struct hostapd_data
*hapd
= hapd_iface
->bss
[j
];
1687 hostapd_free_stas(hapd
);
1688 hostapd_flush_old_stations(hapd
, WLAN_REASON_DEAUTH_LEAVING
);
1689 hostapd_clear_wep(hapd
);
1690 hostapd_free_hapd_data(hapd
);
1693 hostapd_deinit_driver(driver
, drv_priv
, hapd_iface
);
1695 /* From hostapd_cleanup_iface: These were initialized in
1696 * hostapd_setup_interface and hostapd_setup_interface_complete
1698 hostapd_cleanup_iface_partial(hapd_iface
);
1700 wpa_printf(MSG_DEBUG
, "Interface %s disabled",
1701 hapd_iface
->bss
[0]->conf
->iface
);
1702 hostapd_set_state(hapd_iface
, HAPD_IFACE_DISABLED
);
1707 static struct hostapd_iface
*
1708 hostapd_iface_alloc(struct hapd_interfaces
*interfaces
)
1710 struct hostapd_iface
**iface
, *hapd_iface
;
1712 iface
= os_realloc_array(interfaces
->iface
, interfaces
->count
+ 1,
1713 sizeof(struct hostapd_iface
*));
1716 interfaces
->iface
= iface
;
1717 hapd_iface
= interfaces
->iface
[interfaces
->count
] =
1718 os_zalloc(sizeof(*hapd_iface
));
1719 if (hapd_iface
== NULL
) {
1720 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory for "
1721 "the interface", __func__
);
1724 interfaces
->count
++;
1725 hapd_iface
->interfaces
= interfaces
;
1731 static struct hostapd_config
*
1732 hostapd_config_alloc(struct hapd_interfaces
*interfaces
, const char *ifname
,
1733 const char *ctrl_iface
)
1735 struct hostapd_bss_config
*bss
;
1736 struct hostapd_config
*conf
;
1738 /* Allocates memory for bss and conf */
1739 conf
= hostapd_config_defaults();
1741 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory for "
1742 "configuration", __func__
);
1746 conf
->driver
= wpa_drivers
[0];
1747 if (conf
->driver
== NULL
) {
1748 wpa_printf(MSG_ERROR
, "No driver wrappers registered!");
1749 hostapd_config_free(conf
);
1753 bss
= conf
->last_bss
= conf
->bss
[0];
1755 os_strlcpy(bss
->iface
, ifname
, sizeof(bss
->iface
));
1756 bss
->ctrl_interface
= os_strdup(ctrl_iface
);
1757 if (bss
->ctrl_interface
== NULL
) {
1758 hostapd_config_free(conf
);
1762 /* Reading configuration file skipped, will be done in SET!
1763 * From reading the configuration till the end has to be done in
1770 static struct hostapd_iface
* hostapd_data_alloc(
1771 struct hapd_interfaces
*interfaces
, struct hostapd_config
*conf
)
1774 struct hostapd_iface
*hapd_iface
=
1775 interfaces
->iface
[interfaces
->count
- 1];
1776 struct hostapd_data
*hapd
;
1778 hapd_iface
->conf
= conf
;
1779 hapd_iface
->num_bss
= conf
->num_bss
;
1781 hapd_iface
->bss
= os_zalloc(conf
->num_bss
*
1782 sizeof(struct hostapd_data
*));
1783 if (hapd_iface
->bss
== NULL
)
1786 for (i
= 0; i
< conf
->num_bss
; i
++) {
1787 hapd
= hapd_iface
->bss
[i
] =
1788 hostapd_alloc_bss_data(hapd_iface
, conf
, conf
->bss
[i
]);
1791 hapd
->msg_ctx
= hapd
;
1794 hapd_iface
->interfaces
= interfaces
;
1800 int hostapd_add_iface(struct hapd_interfaces
*interfaces
, char *buf
)
1802 struct hostapd_config
*conf
= NULL
;
1803 struct hostapd_iface
*hapd_iface
= NULL
, *new_iface
= NULL
;
1804 struct hostapd_data
*hapd
;
1807 const char *conf_file
= NULL
, *phy_name
= NULL
;
1809 if (os_strncmp(buf
, "bss_config=", 11) == 0) {
1811 phy_name
= buf
+ 11;
1812 pos
= os_strchr(phy_name
, ':');
1817 if (!os_strlen(conf_file
))
1820 hapd_iface
= hostapd_interface_init_bss(interfaces
, phy_name
,
1824 for (j
= 0; j
< interfaces
->count
; j
++) {
1825 if (interfaces
->iface
[j
] == hapd_iface
)
1828 if (j
== interfaces
->count
) {
1829 struct hostapd_iface
**tmp
;
1830 tmp
= os_realloc_array(interfaces
->iface
,
1831 interfaces
->count
+ 1,
1832 sizeof(struct hostapd_iface
*));
1834 hostapd_interface_deinit_free(hapd_iface
);
1837 interfaces
->iface
= tmp
;
1838 interfaces
->iface
[interfaces
->count
++] = hapd_iface
;
1839 new_iface
= hapd_iface
;
1843 if (interfaces
->driver_init(hapd_iface
) ||
1844 hostapd_setup_interface(hapd_iface
)) {
1845 interfaces
->count
--;
1849 /* Assign new BSS with bss[0]'s driver info */
1850 hapd
= hapd_iface
->bss
[hapd_iface
->num_bss
- 1];
1851 hapd
->driver
= hapd_iface
->bss
[0]->driver
;
1852 hapd
->drv_priv
= hapd_iface
->bss
[0]->drv_priv
;
1853 os_memcpy(hapd
->own_addr
, hapd_iface
->bss
[0]->own_addr
,
1856 if (start_ctrl_iface_bss(hapd
) < 0 ||
1857 (hapd_iface
->state
== HAPD_IFACE_ENABLED
&&
1858 hostapd_setup_bss(hapd
, -1))) {
1859 hostapd_cleanup(hapd
);
1860 hapd_iface
->bss
[hapd_iface
->num_bss
- 1] = NULL
;
1861 hapd_iface
->conf
->num_bss
--;
1862 hapd_iface
->num_bss
--;
1863 wpa_printf(MSG_DEBUG
, "%s: free hapd %p %s",
1864 __func__
, hapd
, hapd
->conf
->iface
);
1872 ptr
= os_strchr(buf
, ' ');
1877 if (os_strncmp(ptr
, "config=", 7) == 0)
1878 conf_file
= ptr
+ 7;
1880 for (i
= 0; i
< interfaces
->count
; i
++) {
1881 if (!os_strcmp(interfaces
->iface
[i
]->conf
->bss
[0]->iface
,
1883 wpa_printf(MSG_INFO
, "Cannot add interface - it "
1889 hapd_iface
= hostapd_iface_alloc(interfaces
);
1890 if (hapd_iface
== NULL
) {
1891 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory "
1892 "for interface", __func__
);
1896 if (conf_file
&& interfaces
->config_read_cb
) {
1897 conf
= interfaces
->config_read_cb(conf_file
);
1898 if (conf
&& conf
->bss
)
1899 os_strlcpy(conf
->bss
[0]->iface
, buf
,
1900 sizeof(conf
->bss
[0]->iface
));
1902 conf
= hostapd_config_alloc(interfaces
, buf
, ptr
);
1903 if (conf
== NULL
|| conf
->bss
== NULL
) {
1904 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory "
1905 "for configuration", __func__
);
1909 hapd_iface
= hostapd_data_alloc(interfaces
, conf
);
1910 if (hapd_iface
== NULL
) {
1911 wpa_printf(MSG_ERROR
, "%s: Failed to allocate memory "
1912 "for hostapd", __func__
);
1916 if (start_ctrl_iface(hapd_iface
) < 0)
1919 wpa_printf(MSG_INFO
, "Add interface '%s'", conf
->bss
[0]->iface
);
1925 hostapd_config_free(conf
);
1927 if (hapd_iface
->bss
) {
1928 for (i
= 0; i
< hapd_iface
->num_bss
; i
++) {
1929 hapd
= hapd_iface
->bss
[i
];
1932 if (hapd_iface
->interfaces
&&
1933 hapd_iface
->interfaces
->ctrl_iface_deinit
)
1934 hapd_iface
->interfaces
->
1935 ctrl_iface_deinit(hapd
);
1936 wpa_printf(MSG_DEBUG
, "%s: free hapd %p (%s)",
1937 __func__
, hapd_iface
->bss
[i
],
1940 hapd_iface
->bss
[i
] = NULL
;
1942 os_free(hapd_iface
->bss
);
1944 wpa_printf(MSG_DEBUG
, "%s: free iface %p",
1945 __func__
, hapd_iface
);
1946 os_free(hapd_iface
);
1952 static int hostapd_remove_bss(struct hostapd_iface
*iface
, unsigned int idx
)
1956 wpa_printf(MSG_INFO
, "Remove BSS '%s'", iface
->conf
->bss
[idx
]->iface
);
1958 /* Remove hostapd_data only if it has already been initialized */
1959 if (idx
< iface
->num_bss
) {
1960 struct hostapd_data
*hapd
= iface
->bss
[idx
];
1962 hostapd_bss_deinit(hapd
);
1963 wpa_printf(MSG_DEBUG
, "%s: free hapd %p (%s)",
1964 __func__
, hapd
, hapd
->conf
->iface
);
1965 hostapd_config_free_bss(hapd
->conf
);
1970 for (i
= idx
; i
< iface
->num_bss
; i
++)
1971 iface
->bss
[i
] = iface
->bss
[i
+ 1];
1973 hostapd_config_free_bss(iface
->conf
->bss
[idx
]);
1974 iface
->conf
->bss
[idx
] = NULL
;
1977 iface
->conf
->num_bss
--;
1978 for (i
= idx
; i
< iface
->conf
->num_bss
; i
++)
1979 iface
->conf
->bss
[i
] = iface
->conf
->bss
[i
+ 1];
1985 int hostapd_remove_iface(struct hapd_interfaces
*interfaces
, char *buf
)
1987 struct hostapd_iface
*hapd_iface
;
1990 for (i
= 0; i
< interfaces
->count
; i
++) {
1991 hapd_iface
= interfaces
->iface
[i
];
1992 if (hapd_iface
== NULL
)
1994 if (!os_strcmp(hapd_iface
->conf
->bss
[0]->iface
, buf
)) {
1995 wpa_printf(MSG_INFO
, "Remove interface '%s'", buf
);
1996 hapd_iface
->driver_ap_teardown
=
1997 !!(hapd_iface
->drv_flags
&
1998 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT
);
2000 hostapd_interface_deinit_free(hapd_iface
);
2002 while (k
< (interfaces
->count
- 1)) {
2003 interfaces
->iface
[k
] =
2004 interfaces
->iface
[k
+ 1];
2007 interfaces
->count
--;
2011 for (j
= 0; j
< hapd_iface
->conf
->num_bss
; j
++) {
2012 if (!os_strcmp(hapd_iface
->conf
->bss
[j
]->iface
, buf
)) {
2013 hapd_iface
->driver_ap_teardown
=
2014 !(hapd_iface
->drv_flags
&
2015 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT
);
2016 return hostapd_remove_bss(hapd_iface
, j
);
2025 * hostapd_new_assoc_sta - Notify that a new station associated with the AP
2026 * @hapd: Pointer to BSS data
2027 * @sta: Pointer to the associated STA data
2028 * @reassoc: 1 to indicate this was a re-association; 0 = first association
2030 * This function will be called whenever a station associates with the AP. It
2031 * can be called from ieee802_11.c for drivers that export MLME to hostapd and
2032 * from drv_callbacks.c based on driver events for drivers that take care of
2033 * management frames (IEEE 802.11 authentication and association) internally.
2035 void hostapd_new_assoc_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
,
2038 if (hapd
->tkip_countermeasures
) {
2039 hostapd_drv_sta_deauth(hapd
, sta
->addr
,
2040 WLAN_REASON_MICHAEL_MIC_FAILURE
);
2044 hostapd_prune_associations(hapd
, sta
->addr
);
2046 /* IEEE 802.11F (IAPP) */
2047 if (hapd
->conf
->ieee802_11f
)
2048 iapp_new_station(hapd
->iapp
, sta
);
2051 if (sta
->p2p_ie
== NULL
&& !sta
->no_p2p_set
) {
2052 sta
->no_p2p_set
= 1;
2053 hapd
->num_sta_no_p2p
++;
2054 if (hapd
->num_sta_no_p2p
== 1)
2055 hostapd_p2p_non_p2p_sta_connected(hapd
);
2057 #endif /* CONFIG_P2P */
2059 /* Start accounting here, if IEEE 802.1X and WPA are not used.
2060 * IEEE 802.1X/WPA code will start accounting after the station has
2061 * been authorized. */
2062 if (!hapd
->conf
->ieee802_1x
&& !hapd
->conf
->wpa
&& !hapd
->conf
->osen
) {
2063 ap_sta_set_authorized(hapd
, sta
, 1);
2064 os_get_reltime(&sta
->connected_time
);
2065 accounting_sta_start(hapd
, sta
);
2068 /* Start IEEE 802.1X authentication process for new stations */
2069 ieee802_1x_new_station(hapd
, sta
);
2071 if (sta
->auth_alg
!= WLAN_AUTH_FT
&&
2072 !(sta
->flags
& (WLAN_STA_WPS
| WLAN_STA_MAYBE_WPS
)))
2073 wpa_auth_sm_event(sta
->wpa_sm
, WPA_REAUTH
);
2075 wpa_auth_sta_associated(hapd
->wpa_auth
, sta
->wpa_sm
);
2077 if (!(hapd
->iface
->drv_flags
& WPA_DRIVER_FLAGS_INACTIVITY_TIMER
)) {
2078 wpa_printf(MSG_DEBUG
, "%s: reschedule ap_handle_timer timeout "
2079 "for " MACSTR
" (%d seconds - ap_max_inactivity)",
2080 __func__
, MAC2STR(sta
->addr
),
2081 hapd
->conf
->ap_max_inactivity
);
2082 eloop_cancel_timeout(ap_handle_timer
, hapd
, sta
);
2083 eloop_register_timeout(hapd
->conf
->ap_max_inactivity
, 0,
2084 ap_handle_timer
, hapd
, sta
);
2089 const char * hostapd_state_text(enum hostapd_iface_state s
)
2092 case HAPD_IFACE_UNINITIALIZED
:
2093 return "UNINITIALIZED";
2094 case HAPD_IFACE_DISABLED
:
2096 case HAPD_IFACE_COUNTRY_UPDATE
:
2097 return "COUNTRY_UPDATE";
2098 case HAPD_IFACE_ACS
:
2100 case HAPD_IFACE_HT_SCAN
:
2102 case HAPD_IFACE_DFS
:
2104 case HAPD_IFACE_ENABLED
:
2112 void hostapd_set_state(struct hostapd_iface
*iface
, enum hostapd_iface_state s
)
2114 wpa_printf(MSG_INFO
, "%s: interface state %s->%s",
2115 iface
->conf
->bss
[0]->iface
, hostapd_state_text(iface
->state
),
2116 hostapd_state_text(s
));
2123 static void free_beacon_data(struct beacon_data
*beacon
)
2125 os_free(beacon
->head
);
2126 beacon
->head
= NULL
;
2127 os_free(beacon
->tail
);
2128 beacon
->tail
= NULL
;
2129 os_free(beacon
->probe_resp
);
2130 beacon
->probe_resp
= NULL
;
2131 os_free(beacon
->beacon_ies
);
2132 beacon
->beacon_ies
= NULL
;
2133 os_free(beacon
->proberesp_ies
);
2134 beacon
->proberesp_ies
= NULL
;
2135 os_free(beacon
->assocresp_ies
);
2136 beacon
->assocresp_ies
= NULL
;
2140 static int hostapd_build_beacon_data(struct hostapd_iface
*iface
,
2141 struct beacon_data
*beacon
)
2143 struct wpabuf
*beacon_extra
, *proberesp_extra
, *assocresp_extra
;
2144 struct wpa_driver_ap_params params
;
2146 struct hostapd_data
*hapd
= iface
->bss
[0];
2148 os_memset(beacon
, 0, sizeof(*beacon
));
2149 ret
= ieee802_11_build_ap_params(hapd
, ¶ms
);
2153 ret
= hostapd_build_ap_extra_ies(hapd
, &beacon_extra
,
2157 goto free_ap_params
;
2160 beacon
->head
= os_malloc(params
.head_len
);
2162 goto free_ap_extra_ies
;
2164 os_memcpy(beacon
->head
, params
.head
, params
.head_len
);
2165 beacon
->head_len
= params
.head_len
;
2167 beacon
->tail
= os_malloc(params
.tail_len
);
2171 os_memcpy(beacon
->tail
, params
.tail
, params
.tail_len
);
2172 beacon
->tail_len
= params
.tail_len
;
2174 if (params
.proberesp
!= NULL
) {
2175 beacon
->probe_resp
= os_malloc(params
.proberesp_len
);
2176 if (!beacon
->probe_resp
)
2179 os_memcpy(beacon
->probe_resp
, params
.proberesp
,
2180 params
.proberesp_len
);
2181 beacon
->probe_resp_len
= params
.proberesp_len
;
2184 /* copy the extra ies */
2186 beacon
->beacon_ies
= os_malloc(wpabuf_len(beacon_extra
));
2187 if (!beacon
->beacon_ies
)
2190 os_memcpy(beacon
->beacon_ies
,
2191 beacon_extra
->buf
, wpabuf_len(beacon_extra
));
2192 beacon
->beacon_ies_len
= wpabuf_len(beacon_extra
);
2195 if (proberesp_extra
) {
2196 beacon
->proberesp_ies
=
2197 os_malloc(wpabuf_len(proberesp_extra
));
2198 if (!beacon
->proberesp_ies
)
2201 os_memcpy(beacon
->proberesp_ies
, proberesp_extra
->buf
,
2202 wpabuf_len(proberesp_extra
));
2203 beacon
->proberesp_ies_len
= wpabuf_len(proberesp_extra
);
2206 if (assocresp_extra
) {
2207 beacon
->assocresp_ies
=
2208 os_malloc(wpabuf_len(assocresp_extra
));
2209 if (!beacon
->assocresp_ies
)
2212 os_memcpy(beacon
->assocresp_ies
, assocresp_extra
->buf
,
2213 wpabuf_len(assocresp_extra
));
2214 beacon
->assocresp_ies_len
= wpabuf_len(assocresp_extra
);
2219 /* if the function fails, the caller should not free beacon data */
2221 free_beacon_data(beacon
);
2224 hostapd_free_ap_extra_ies(hapd
, beacon_extra
, proberesp_extra
,
2227 ieee802_11_free_ap_params(¶ms
);
2233 * TODO: This flow currently supports only changing frequency within the
2234 * same hw_mode. Any other changes to MAC parameters or provided settings (even
2235 * width) are not supported.
2237 static int hostapd_change_config_freq(struct hostapd_data
*hapd
,
2238 struct hostapd_config
*conf
,
2239 struct hostapd_freq_params
*params
,
2240 struct hostapd_freq_params
*old_params
)
2244 if (!params
->channel
) {
2245 /* check if the new channel is supported by hw */
2246 channel
= hostapd_hw_get_channel(hapd
, params
->freq
);
2250 channel
= params
->channel
;
2253 /* if a pointer to old_params is provided we save previous state */
2255 old_params
->channel
= conf
->channel
;
2256 old_params
->ht_enabled
= conf
->ieee80211n
;
2257 old_params
->sec_channel_offset
= conf
->secondary_channel
;
2260 conf
->channel
= channel
;
2261 conf
->ieee80211n
= params
->ht_enabled
;
2262 conf
->secondary_channel
= params
->sec_channel_offset
;
2264 /* TODO: maybe call here hostapd_config_check here? */
2270 static int hostapd_fill_csa_settings(struct hostapd_iface
*iface
,
2271 struct csa_settings
*settings
)
2273 struct hostapd_freq_params old_freq
;
2276 os_memset(&old_freq
, 0, sizeof(old_freq
));
2277 if (!iface
|| !iface
->freq
|| iface
->csa_in_progress
)
2280 ret
= hostapd_change_config_freq(iface
->bss
[0], iface
->conf
,
2281 &settings
->freq_params
,
2286 ret
= hostapd_build_beacon_data(iface
, &settings
->beacon_after
);
2288 /* change back the configuration */
2289 hostapd_change_config_freq(iface
->bss
[0], iface
->conf
,
2295 /* set channel switch parameters for csa ie */
2296 iface
->cs_freq_params
= settings
->freq_params
;
2297 iface
->cs_count
= settings
->cs_count
;
2298 iface
->cs_block_tx
= settings
->block_tx
;
2300 ret
= hostapd_build_beacon_data(iface
, &settings
->beacon_csa
);
2302 free_beacon_data(&settings
->beacon_after
);
2306 settings
->counter_offset_beacon
= iface
->cs_c_off_beacon
;
2307 settings
->counter_offset_presp
= iface
->cs_c_off_proberesp
;
2313 void hostapd_cleanup_cs_params(struct hostapd_data
*hapd
)
2315 os_memset(&hapd
->iface
->cs_freq_params
, 0,
2316 sizeof(hapd
->iface
->cs_freq_params
));
2317 hapd
->iface
->cs_count
= 0;
2318 hapd
->iface
->cs_block_tx
= 0;
2319 hapd
->iface
->cs_c_off_beacon
= 0;
2320 hapd
->iface
->cs_c_off_proberesp
= 0;
2321 hapd
->iface
->csa_in_progress
= 0;
2325 int hostapd_switch_channel(struct hostapd_data
*hapd
,
2326 struct csa_settings
*settings
)
2329 ret
= hostapd_fill_csa_settings(hapd
->iface
, settings
);
2333 ret
= hostapd_drv_switch_channel(hapd
, settings
);
2334 free_beacon_data(&settings
->beacon_csa
);
2335 free_beacon_data(&settings
->beacon_after
);
2338 /* if we failed, clean cs parameters */
2339 hostapd_cleanup_cs_params(hapd
);
2343 hapd
->iface
->csa_in_progress
= 1;
2347 #endif /* NEED_AP_MLME */