blob: 12911dfd46116bd3d42d52bdef59d0eadc5e34f9 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Initialization and configuration
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003 * Copyright (c) 2002-2014, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10
11#include "utils/common.h"
12#include "utils/eloop.h"
13#include "common/ieee802_11_defs.h"
Dmitry Shmidtcce06662013-11-04 18:44:24 -080014#include "common/wpa_ctrl.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080015#include "common/hw_features_common.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070016#include "radius/radius_client.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070017#include "radius/radius_das.h"
Dmitry Shmidt50b691d2014-05-21 14:01:45 -070018#include "eap_server/tncs.h"
Dmitry Shmidt2f74e362015-01-21 13:19:05 -080019#include "eapol_auth/eapol_auth_sm.h"
20#include "eapol_auth/eapol_auth_sm_i.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080021#include "fst/fst.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070022#include "hostapd.h"
23#include "authsrv.h"
24#include "sta_info.h"
25#include "accounting.h"
26#include "ap_list.h"
27#include "beacon.h"
28#include "iapp.h"
29#include "ieee802_1x.h"
30#include "ieee802_11_auth.h"
31#include "vlan_init.h"
32#include "wpa_auth.h"
33#include "wps_hostapd.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070034#include "dpp_hostapd.h"
35#include "gas_query_ap.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070036#include "hw_features.h"
37#include "wpa_auth_glue.h"
38#include "ap_drv_ops.h"
39#include "ap_config.h"
40#include "p2p_hostapd.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070041#include "gas_serv.h"
Dmitry Shmidt051af732013-10-22 13:52:46 -070042#include "dfs.h"
Dmitry Shmidt7832adb2014-04-29 10:53:02 -070043#include "ieee802_11.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080044#include "bss_load.h"
45#include "x_snoop.h"
46#include "dhcp_snoop.h"
47#include "ndisc_snoop.h"
Dmitry Shmidt849734c2016-05-27 09:59:01 -070048#include "neighbor_db.h"
49#include "rrm.h"
Dmitry Shmidtebd93af2017-02-21 13:40:44 -080050#include "fils_hlp.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070051#include "acs.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070052
53
Dmitry Shmidt04949592012-07-19 12:16:46 -070054static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070055static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd);
Dmitry Shmidtc55524a2011-07-07 11:18:38 -070056static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd);
Dmitry Shmidtcce06662013-11-04 18:44:24 -080057static int setup_interface2(struct hostapd_iface *iface);
58static void channel_list_update_timeout(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070059
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070060
Dmitry Shmidt04949592012-07-19 12:16:46 -070061int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
62 int (*cb)(struct hostapd_iface *iface,
63 void *ctx), void *ctx)
64{
65 size_t i;
66 int ret;
67
68 for (i = 0; i < interfaces->count; i++) {
69 ret = cb(interfaces->iface[i], ctx);
70 if (ret)
71 return ret;
72 }
73
74 return 0;
75}
76
77
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070078static void hostapd_reload_bss(struct hostapd_data *hapd)
79{
Dmitry Shmidtcce06662013-11-04 18:44:24 -080080 struct hostapd_ssid *ssid;
81
Dmitry Shmidt29333592017-01-09 12:27:11 -080082 if (!hapd->started)
83 return;
84
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070085#ifndef CONFIG_NO_RADIUS
86 radius_client_reconfig(hapd->radius, hapd->conf->radius);
87#endif /* CONFIG_NO_RADIUS */
88
Dmitry Shmidtcce06662013-11-04 18:44:24 -080089 ssid = &hapd->conf->ssid;
90 if (!ssid->wpa_psk_set && ssid->wpa_psk && !ssid->wpa_psk->next &&
91 ssid->wpa_passphrase_set && ssid->wpa_passphrase) {
92 /*
93 * Force PSK to be derived again since SSID or passphrase may
94 * have changed.
95 */
Dmitry Shmidt7f656022015-02-25 14:36:37 -080096 hostapd_config_clear_wpa_psk(&hapd->conf->ssid.wpa_psk);
Dmitry Shmidtcce06662013-11-04 18:44:24 -080097 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070098 if (hostapd_setup_wpa_psk(hapd->conf)) {
99 wpa_printf(MSG_ERROR, "Failed to re-configure WPA PSK "
100 "after reloading configuration");
101 }
102
103 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
104 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1);
105 else
106 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0);
107
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800108 if ((hapd->conf->wpa || hapd->conf->osen) && hapd->wpa_auth == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700109 hostapd_setup_wpa(hapd);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800110 if (hapd->wpa_auth)
111 wpa_init_keys(hapd->wpa_auth);
112 } else if (hapd->conf->wpa) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700113 const u8 *wpa_ie;
114 size_t wpa_ie_len;
115 hostapd_reconfig_wpa(hapd);
116 wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
117 if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len))
118 wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
119 "the kernel driver.");
120 } else if (hapd->wpa_auth) {
121 wpa_deinit(hapd->wpa_auth);
122 hapd->wpa_auth = NULL;
123 hostapd_set_privacy(hapd, 0);
124 hostapd_setup_encryption(hapd->conf->iface, hapd);
125 hostapd_set_generic_elem(hapd, (u8 *) "", 0);
126 }
127
128 ieee802_11_set_beacon(hapd);
129 hostapd_update_wps(hapd);
130
131 if (hapd->conf->ssid.ssid_set &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700132 hostapd_set_ssid(hapd, hapd->conf->ssid.ssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700133 hapd->conf->ssid.ssid_len)) {
134 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
135 /* try to continue */
136 }
137 wpa_printf(MSG_DEBUG, "Reconfigured interface %s", hapd->conf->iface);
138}
139
140
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700141static void hostapd_clear_old(struct hostapd_iface *iface)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700142{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700143 size_t j;
144
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700145 /*
146 * Deauthenticate all stations since the new configuration may not
147 * allow them to use the BSS anymore.
148 */
149 for (j = 0; j < iface->num_bss; j++) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700150 hostapd_flush_old_stations(iface->bss[j],
151 WLAN_REASON_PREV_AUTH_NOT_VALID);
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700152 hostapd_broadcast_wep_clear(iface->bss[j]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700153
154#ifndef CONFIG_NO_RADIUS
155 /* TODO: update dynamic data based on changed configuration
156 * items (e.g., open/close sockets, etc.) */
157 radius_client_flush(iface->bss[j]->radius, 0);
158#endif /* CONFIG_NO_RADIUS */
159 }
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700160}
161
162
163int hostapd_reload_config(struct hostapd_iface *iface)
164{
165 struct hostapd_data *hapd = iface->bss[0];
166 struct hostapd_config *newconf, *oldconf;
167 size_t j;
168
169 if (iface->config_fname == NULL) {
170 /* Only in-memory config in use - assume it has been updated */
171 hostapd_clear_old(iface);
172 for (j = 0; j < iface->num_bss; j++)
173 hostapd_reload_bss(iface->bss[j]);
174 return 0;
175 }
176
177 if (iface->interfaces == NULL ||
178 iface->interfaces->config_read_cb == NULL)
179 return -1;
180 newconf = iface->interfaces->config_read_cb(iface->config_fname);
181 if (newconf == NULL)
182 return -1;
183
184 hostapd_clear_old(iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700185
186 oldconf = hapd->iconf;
187 iface->conf = newconf;
188
189 for (j = 0; j < iface->num_bss; j++) {
190 hapd = iface->bss[j];
191 hapd->iconf = newconf;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700192 hapd->iconf->channel = oldconf->channel;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700193 hapd->iconf->acs = oldconf->acs;
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700194 hapd->iconf->secondary_channel = oldconf->secondary_channel;
Dmitry Shmidtd11f0192014-03-24 12:09:47 -0700195 hapd->iconf->ieee80211n = oldconf->ieee80211n;
196 hapd->iconf->ieee80211ac = oldconf->ieee80211ac;
197 hapd->iconf->ht_capab = oldconf->ht_capab;
198 hapd->iconf->vht_capab = oldconf->vht_capab;
199 hapd->iconf->vht_oper_chwidth = oldconf->vht_oper_chwidth;
200 hapd->iconf->vht_oper_centr_freq_seg0_idx =
201 oldconf->vht_oper_centr_freq_seg0_idx;
202 hapd->iconf->vht_oper_centr_freq_seg1_idx =
203 oldconf->vht_oper_centr_freq_seg1_idx;
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800204 hapd->conf = newconf->bss[j];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700205 hostapd_reload_bss(hapd);
206 }
207
208 hostapd_config_free(oldconf);
209
210
211 return 0;
212}
213
214
215static void hostapd_broadcast_key_clear_iface(struct hostapd_data *hapd,
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700216 const char *ifname)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700217{
218 int i;
219
Dmitry Shmidt29333592017-01-09 12:27:11 -0800220 if (!ifname || !hapd->drv_priv)
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700221 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700222 for (i = 0; i < NUM_WEP_KEYS; i++) {
223 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE, NULL, i,
224 0, NULL, 0, NULL, 0)) {
225 wpa_printf(MSG_DEBUG, "Failed to clear default "
226 "encryption keys (ifname=%s keyidx=%d)",
227 ifname, i);
228 }
229 }
230#ifdef CONFIG_IEEE80211W
231 if (hapd->conf->ieee80211w) {
232 for (i = NUM_WEP_KEYS; i < NUM_WEP_KEYS + 2; i++) {
233 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE,
234 NULL, i, 0, NULL,
235 0, NULL, 0)) {
236 wpa_printf(MSG_DEBUG, "Failed to clear "
237 "default mgmt encryption keys "
238 "(ifname=%s keyidx=%d)", ifname, i);
239 }
240 }
241 }
242#endif /* CONFIG_IEEE80211W */
243}
244
245
246static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd)
247{
248 hostapd_broadcast_key_clear_iface(hapd, hapd->conf->iface);
249 return 0;
250}
251
252
253static int hostapd_broadcast_wep_set(struct hostapd_data *hapd)
254{
255 int errors = 0, idx;
256 struct hostapd_ssid *ssid = &hapd->conf->ssid;
257
258 idx = ssid->wep.idx;
259 if (ssid->wep.default_len &&
260 hostapd_drv_set_key(hapd->conf->iface,
261 hapd, WPA_ALG_WEP, broadcast_ether_addr, idx,
262 1, NULL, 0, ssid->wep.key[idx],
263 ssid->wep.len[idx])) {
264 wpa_printf(MSG_WARNING, "Could not set WEP encryption.");
265 errors++;
266 }
267
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700268 return errors;
269}
270
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700271
Dmitry Shmidt04949592012-07-19 12:16:46 -0700272static void hostapd_free_hapd_data(struct hostapd_data *hapd)
273{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800274 os_free(hapd->probereq_cb);
275 hapd->probereq_cb = NULL;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800276 hapd->num_probereq_cb = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800277
278#ifdef CONFIG_P2P
279 wpabuf_free(hapd->p2p_beacon_ie);
280 hapd->p2p_beacon_ie = NULL;
281 wpabuf_free(hapd->p2p_probe_resp_ie);
282 hapd->p2p_probe_resp_ie = NULL;
283#endif /* CONFIG_P2P */
284
Dmitry Shmidtfa3fc4a2013-11-21 13:34:38 -0800285 if (!hapd->started) {
286 wpa_printf(MSG_ERROR, "%s: Interface %s wasn't started",
287 __func__, hapd->conf->iface);
288 return;
289 }
290 hapd->started = 0;
291
Dmitry Shmidt54605472013-11-08 11:10:19 -0800292 wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700293 iapp_deinit(hapd->iapp);
294 hapd->iapp = NULL;
295 accounting_deinit(hapd);
296 hostapd_deinit_wpa(hapd);
297 vlan_deinit(hapd);
298 hostapd_acl_deinit(hapd);
299#ifndef CONFIG_NO_RADIUS
300 radius_client_deinit(hapd->radius);
301 hapd->radius = NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700302 radius_das_deinit(hapd->radius_das);
303 hapd->radius_das = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700304#endif /* CONFIG_NO_RADIUS */
305
306 hostapd_deinit_wps(hapd);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700307#ifdef CONFIG_DPP
308 hostapd_dpp_deinit(hapd);
309 gas_query_ap_deinit(hapd->gas);
310#endif /* CONFIG_DPP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700311
312 authsrv_deinit(hapd);
313
Dmitry Shmidt71757432014-06-02 13:50:35 -0700314 if (hapd->interface_added) {
315 hapd->interface_added = 0;
316 if (hostapd_if_remove(hapd, WPA_IF_AP_BSS, hapd->conf->iface)) {
317 wpa_printf(MSG_WARNING,
318 "Failed to remove BSS interface %s",
319 hapd->conf->iface);
320 hapd->interface_added = 1;
321 } else {
322 /*
323 * Since this was a dynamically added interface, the
324 * driver wrapper may have removed its internal instance
325 * and hapd->drv_priv is not valid anymore.
326 */
327 hapd->drv_priv = NULL;
328 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700329 }
330
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800331 wpabuf_free(hapd->time_adv);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700332
333#ifdef CONFIG_INTERWORKING
334 gas_serv_deinit(hapd);
335#endif /* CONFIG_INTERWORKING */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800336
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800337 bss_load_update_deinit(hapd);
338 ndisc_snoop_deinit(hapd);
339 dhcp_snoop_deinit(hapd);
340 x_snoop_deinit(hapd);
341
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800342#ifdef CONFIG_SQLITE
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700343 bin_clear_free(hapd->tmp_eap_user.identity,
344 hapd->tmp_eap_user.identity_len);
345 bin_clear_free(hapd->tmp_eap_user.password,
346 hapd->tmp_eap_user.password_len);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800347#endif /* CONFIG_SQLITE */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800348
349#ifdef CONFIG_MESH
350 wpabuf_free(hapd->mesh_pending_auth);
351 hapd->mesh_pending_auth = NULL;
352#endif /* CONFIG_MESH */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700353
354 hostapd_clean_rrm(hapd);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800355 fils_hlp_deinit(hapd);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700356}
357
358
359/**
360 * hostapd_cleanup - Per-BSS cleanup (deinitialization)
361 * @hapd: Pointer to BSS data
362 *
363 * This function is used to free all per-BSS data structures and resources.
Dmitry Shmidt54605472013-11-08 11:10:19 -0800364 * Most of the modules that are initialized in hostapd_setup_bss() are
365 * deinitialized here.
Dmitry Shmidt04949592012-07-19 12:16:46 -0700366 */
367static void hostapd_cleanup(struct hostapd_data *hapd)
368{
Dmitry Shmidt54605472013-11-08 11:10:19 -0800369 wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s))", __func__, hapd,
370 hapd->conf->iface);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700371 if (hapd->iface->interfaces &&
Dmitry Shmidt29333592017-01-09 12:27:11 -0800372 hapd->iface->interfaces->ctrl_iface_deinit) {
373 wpa_msg(hapd->msg_ctx, MSG_INFO, WPA_EVENT_TERMINATING);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700374 hapd->iface->interfaces->ctrl_iface_deinit(hapd);
Dmitry Shmidt29333592017-01-09 12:27:11 -0800375 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700376 hostapd_free_hapd_data(hapd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700377}
378
379
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800380static void sta_track_deinit(struct hostapd_iface *iface)
381{
382 struct hostapd_sta_info *info;
383
384 if (!iface->num_sta_seen)
385 return;
386
387 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
388 list))) {
389 dl_list_del(&info->list);
390 iface->num_sta_seen--;
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700391 sta_track_del(info);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800392 }
393}
394
395
Dmitry Shmidt04949592012-07-19 12:16:46 -0700396static void hostapd_cleanup_iface_partial(struct hostapd_iface *iface)
397{
Dmitry Shmidt54605472013-11-08 11:10:19 -0800398 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800399#ifdef CONFIG_IEEE80211N
400#ifdef NEED_AP_MLME
401 hostapd_stop_setup_timers(iface);
402#endif /* NEED_AP_MLME */
403#endif /* CONFIG_IEEE80211N */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700404 if (iface->current_mode)
405 acs_cleanup(iface);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700406 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
407 iface->hw_features = NULL;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700408 iface->current_mode = NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700409 os_free(iface->current_rates);
410 iface->current_rates = NULL;
411 os_free(iface->basic_rates);
412 iface->basic_rates = NULL;
413 ap_list_deinit(iface);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800414 sta_track_deinit(iface);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700415}
416
417
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700418/**
419 * hostapd_cleanup_iface - Complete per-interface cleanup
420 * @iface: Pointer to interface data
421 *
422 * This function is called after per-BSS data structures are deinitialized
423 * with hostapd_cleanup().
424 */
425static void hostapd_cleanup_iface(struct hostapd_iface *iface)
426{
Dmitry Shmidt54605472013-11-08 11:10:19 -0800427 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800428 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
429
Dmitry Shmidt04949592012-07-19 12:16:46 -0700430 hostapd_cleanup_iface_partial(iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700431 hostapd_config_free(iface->conf);
432 iface->conf = NULL;
433
434 os_free(iface->config_fname);
435 os_free(iface->bss);
Dmitry Shmidt54605472013-11-08 11:10:19 -0800436 wpa_printf(MSG_DEBUG, "%s: free iface=%p", __func__, iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700437 os_free(iface);
438}
439
440
Dmitry Shmidt04949592012-07-19 12:16:46 -0700441static void hostapd_clear_wep(struct hostapd_data *hapd)
442{
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800443 if (hapd->drv_priv && !hapd->iface->driver_ap_teardown) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700444 hostapd_set_privacy(hapd, 0);
445 hostapd_broadcast_wep_clear(hapd);
446 }
447}
448
449
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700450static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd)
451{
452 int i;
453
454 hostapd_broadcast_wep_set(hapd);
455
456 if (hapd->conf->ssid.wep.default_len) {
457 hostapd_set_privacy(hapd, 1);
458 return 0;
459 }
460
Jouni Malinen75ecf522011-06-27 15:19:46 -0700461 /*
462 * When IEEE 802.1X is not enabled, the driver may need to know how to
463 * set authentication algorithms for static WEP.
464 */
465 hostapd_drv_set_authmode(hapd, hapd->conf->auth_algs);
466
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700467 for (i = 0; i < 4; i++) {
468 if (hapd->conf->ssid.wep.key[i] &&
469 hostapd_drv_set_key(iface, hapd, WPA_ALG_WEP, NULL, i,
470 i == hapd->conf->ssid.wep.idx, NULL, 0,
471 hapd->conf->ssid.wep.key[i],
472 hapd->conf->ssid.wep.len[i])) {
473 wpa_printf(MSG_WARNING, "Could not set WEP "
474 "encryption.");
475 return -1;
476 }
477 if (hapd->conf->ssid.wep.key[i] &&
478 i == hapd->conf->ssid.wep.idx)
479 hostapd_set_privacy(hapd, 1);
480 }
481
482 return 0;
483}
484
485
Dmitry Shmidt04949592012-07-19 12:16:46 -0700486static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700487{
488 int ret = 0;
489 u8 addr[ETH_ALEN];
490
491 if (hostapd_drv_none(hapd) || hapd->drv_priv == NULL)
492 return 0;
493
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800494 if (!hapd->iface->driver_ap_teardown) {
495 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
496 "Flushing old station entries");
497
498 if (hostapd_flush(hapd)) {
499 wpa_msg(hapd->msg_ctx, MSG_WARNING,
500 "Could not connect to kernel driver");
501 ret = -1;
502 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700503 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700504 if (hapd->conf && hapd->conf->broadcast_deauth) {
505 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
506 "Deauthenticate all stations");
507 os_memset(addr, 0xff, ETH_ALEN);
508 hostapd_drv_sta_deauth(hapd, addr, reason);
509 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700510 hostapd_free_stas(hapd);
511
512 return ret;
513}
514
515
Dmitry Shmidt71757432014-06-02 13:50:35 -0700516static void hostapd_bss_deinit_no_free(struct hostapd_data *hapd)
517{
518 hostapd_free_stas(hapd);
519 hostapd_flush_old_stations(hapd, WLAN_REASON_DEAUTH_LEAVING);
520 hostapd_clear_wep(hapd);
521}
522
523
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700524/**
525 * hostapd_validate_bssid_configuration - Validate BSSID configuration
526 * @iface: Pointer to interface data
527 * Returns: 0 on success, -1 on failure
528 *
529 * This function is used to validate that the configured BSSIDs are valid.
530 */
531static int hostapd_validate_bssid_configuration(struct hostapd_iface *iface)
532{
533 u8 mask[ETH_ALEN] = { 0 };
534 struct hostapd_data *hapd = iface->bss[0];
535 unsigned int i = iface->conf->num_bss, bits = 0, j;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700536 int auto_addr = 0;
537
538 if (hostapd_drv_none(hapd))
539 return 0;
540
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -0800541 if (iface->conf->use_driver_iface_addr)
542 return 0;
543
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700544 /* Generate BSSID mask that is large enough to cover the BSSIDs. */
545
546 /* Determine the bits necessary to cover the number of BSSIDs. */
547 for (i--; i; i >>= 1)
548 bits++;
549
550 /* Determine the bits necessary to any configured BSSIDs,
551 if they are higher than the number of BSSIDs. */
552 for (j = 0; j < iface->conf->num_bss; j++) {
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800553 if (is_zero_ether_addr(iface->conf->bss[j]->bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700554 if (j)
555 auto_addr++;
556 continue;
557 }
558
559 for (i = 0; i < ETH_ALEN; i++) {
560 mask[i] |=
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800561 iface->conf->bss[j]->bssid[i] ^
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700562 hapd->own_addr[i];
563 }
564 }
565
566 if (!auto_addr)
567 goto skip_mask_ext;
568
569 for (i = 0; i < ETH_ALEN && mask[i] == 0; i++)
570 ;
571 j = 0;
572 if (i < ETH_ALEN) {
573 j = (5 - i) * 8;
574
575 while (mask[i] != 0) {
576 mask[i] >>= 1;
577 j++;
578 }
579 }
580
581 if (bits < j)
582 bits = j;
583
584 if (bits > 40) {
585 wpa_printf(MSG_ERROR, "Too many bits in the BSSID mask (%u)",
586 bits);
587 return -1;
588 }
589
590 os_memset(mask, 0xff, ETH_ALEN);
591 j = bits / 8;
592 for (i = 5; i > 5 - j; i--)
593 mask[i] = 0;
594 j = bits % 8;
595 while (j--)
596 mask[i] <<= 1;
597
598skip_mask_ext:
599 wpa_printf(MSG_DEBUG, "BSS count %lu, BSSID mask " MACSTR " (%d bits)",
600 (unsigned long) iface->conf->num_bss, MAC2STR(mask), bits);
601
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700602 if (!auto_addr)
603 return 0;
604
605 for (i = 0; i < ETH_ALEN; i++) {
606 if ((hapd->own_addr[i] & mask[i]) != hapd->own_addr[i]) {
607 wpa_printf(MSG_ERROR, "Invalid BSSID mask " MACSTR
608 " for start address " MACSTR ".",
609 MAC2STR(mask), MAC2STR(hapd->own_addr));
610 wpa_printf(MSG_ERROR, "Start address must be the "
611 "first address in the block (i.e., addr "
612 "AND mask == addr).");
613 return -1;
614 }
615 }
616
617 return 0;
618}
619
620
621static int mac_in_conf(struct hostapd_config *conf, const void *a)
622{
623 size_t i;
624
625 for (i = 0; i < conf->num_bss; i++) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800626 if (hostapd_mac_comp(conf->bss[i]->bssid, a) == 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700627 return 1;
628 }
629 }
630
631 return 0;
632}
633
634
Dmitry Shmidt04949592012-07-19 12:16:46 -0700635#ifndef CONFIG_NO_RADIUS
636
637static int hostapd_das_nas_mismatch(struct hostapd_data *hapd,
638 struct radius_das_attrs *attr)
639{
Dmitry Shmidt13ca8d82014-02-20 10:18:40 -0800640 if (attr->nas_identifier &&
641 (!hapd->conf->nas_identifier ||
642 os_strlen(hapd->conf->nas_identifier) !=
643 attr->nas_identifier_len ||
644 os_memcmp(hapd->conf->nas_identifier, attr->nas_identifier,
645 attr->nas_identifier_len) != 0)) {
646 wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-Identifier mismatch");
647 return 1;
648 }
649
650 if (attr->nas_ip_addr &&
651 (hapd->conf->own_ip_addr.af != AF_INET ||
652 os_memcmp(&hapd->conf->own_ip_addr.u.v4, attr->nas_ip_addr, 4) !=
653 0)) {
654 wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-IP-Address mismatch");
655 return 1;
656 }
657
658#ifdef CONFIG_IPV6
659 if (attr->nas_ipv6_addr &&
660 (hapd->conf->own_ip_addr.af != AF_INET6 ||
661 os_memcmp(&hapd->conf->own_ip_addr.u.v6, attr->nas_ipv6_addr, 16)
662 != 0)) {
663 wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-IPv6-Address mismatch");
664 return 1;
665 }
666#endif /* CONFIG_IPV6 */
667
Dmitry Shmidt04949592012-07-19 12:16:46 -0700668 return 0;
669}
670
671
672static struct sta_info * hostapd_das_find_sta(struct hostapd_data *hapd,
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800673 struct radius_das_attrs *attr,
674 int *multi)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700675{
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800676 struct sta_info *selected, *sta;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700677 char buf[128];
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800678 int num_attr = 0;
679 int count;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700680
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800681 *multi = 0;
682
683 for (sta = hapd->sta_list; sta; sta = sta->next)
684 sta->radius_das_match = 1;
685
686 if (attr->sta_addr) {
687 num_attr++;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700688 sta = ap_get_sta(hapd, attr->sta_addr);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800689 if (!sta) {
690 wpa_printf(MSG_DEBUG,
691 "RADIUS DAS: No Calling-Station-Id match");
692 return NULL;
693 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700694
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800695 selected = sta;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700696 for (sta = hapd->sta_list; sta; sta = sta->next) {
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800697 if (sta != selected)
698 sta->radius_das_match = 0;
699 }
700 wpa_printf(MSG_DEBUG, "RADIUS DAS: Calling-Station-Id match");
701 }
702
703 if (attr->acct_session_id) {
704 num_attr++;
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800705 if (attr->acct_session_id_len != 16) {
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800706 wpa_printf(MSG_DEBUG,
707 "RADIUS DAS: Acct-Session-Id cannot match");
708 return NULL;
709 }
710 count = 0;
711
712 for (sta = hapd->sta_list; sta; sta = sta->next) {
713 if (!sta->radius_das_match)
714 continue;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800715 os_snprintf(buf, sizeof(buf), "%016llX",
716 (unsigned long long) sta->acct_session_id);
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800717 if (os_memcmp(attr->acct_session_id, buf, 16) != 0)
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800718 sta->radius_das_match = 0;
719 else
720 count++;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700721 }
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800722
723 if (count == 0) {
724 wpa_printf(MSG_DEBUG,
725 "RADIUS DAS: No matches remaining after Acct-Session-Id check");
726 return NULL;
727 }
728 wpa_printf(MSG_DEBUG, "RADIUS DAS: Acct-Session-Id match");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700729 }
730
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800731 if (attr->acct_multi_session_id) {
732 num_attr++;
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800733 if (attr->acct_multi_session_id_len != 16) {
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800734 wpa_printf(MSG_DEBUG,
735 "RADIUS DAS: Acct-Multi-Session-Id cannot match");
736 return NULL;
737 }
738 count = 0;
739
740 for (sta = hapd->sta_list; sta; sta = sta->next) {
741 if (!sta->radius_das_match)
742 continue;
743 if (!sta->eapol_sm ||
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800744 !sta->eapol_sm->acct_multi_session_id) {
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800745 sta->radius_das_match = 0;
746 continue;
747 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800748 os_snprintf(buf, sizeof(buf), "%016llX",
749 (unsigned long long)
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800750 sta->eapol_sm->acct_multi_session_id);
751 if (os_memcmp(attr->acct_multi_session_id, buf, 16) !=
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800752 0)
753 sta->radius_das_match = 0;
754 else
755 count++;
756 }
757
758 if (count == 0) {
759 wpa_printf(MSG_DEBUG,
760 "RADIUS DAS: No matches remaining after Acct-Multi-Session-Id check");
761 return NULL;
762 }
763 wpa_printf(MSG_DEBUG,
764 "RADIUS DAS: Acct-Multi-Session-Id match");
765 }
766
767 if (attr->cui) {
768 num_attr++;
769 count = 0;
770
Dmitry Shmidt04949592012-07-19 12:16:46 -0700771 for (sta = hapd->sta_list; sta; sta = sta->next) {
772 struct wpabuf *cui;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800773
774 if (!sta->radius_das_match)
775 continue;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700776 cui = ieee802_1x_get_radius_cui(sta->eapol_sm);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800777 if (!cui || wpabuf_len(cui) != attr->cui_len ||
Dmitry Shmidt04949592012-07-19 12:16:46 -0700778 os_memcmp(wpabuf_head(cui), attr->cui,
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800779 attr->cui_len) != 0)
780 sta->radius_das_match = 0;
781 else
782 count++;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700783 }
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800784
785 if (count == 0) {
786 wpa_printf(MSG_DEBUG,
787 "RADIUS DAS: No matches remaining after Chargeable-User-Identity check");
788 return NULL;
789 }
790 wpa_printf(MSG_DEBUG,
791 "RADIUS DAS: Chargeable-User-Identity match");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700792 }
793
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800794 if (attr->user_name) {
795 num_attr++;
796 count = 0;
797
Dmitry Shmidt04949592012-07-19 12:16:46 -0700798 for (sta = hapd->sta_list; sta; sta = sta->next) {
799 u8 *identity;
800 size_t identity_len;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800801
802 if (!sta->radius_das_match)
803 continue;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700804 identity = ieee802_1x_get_identity(sta->eapol_sm,
805 &identity_len);
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800806 if (!identity ||
807 identity_len != attr->user_name_len ||
Dmitry Shmidt04949592012-07-19 12:16:46 -0700808 os_memcmp(identity, attr->user_name, identity_len)
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800809 != 0)
810 sta->radius_das_match = 0;
811 else
812 count++;
813 }
814
815 if (count == 0) {
816 wpa_printf(MSG_DEBUG,
817 "RADIUS DAS: No matches remaining after User-Name check");
818 return NULL;
819 }
820 wpa_printf(MSG_DEBUG,
821 "RADIUS DAS: User-Name match");
822 }
823
824 if (num_attr == 0) {
825 /*
826 * In theory, we could match all current associations, but it
827 * seems safer to just reject requests that do not include any
828 * session identification attributes.
829 */
830 wpa_printf(MSG_DEBUG,
831 "RADIUS DAS: No session identification attributes included");
832 return NULL;
833 }
834
835 selected = NULL;
836 for (sta = hapd->sta_list; sta; sta = sta->next) {
837 if (sta->radius_das_match) {
838 if (selected) {
839 *multi = 1;
840 return NULL;
841 }
842 selected = sta;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700843 }
844 }
845
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800846 return selected;
847}
848
849
850static int hostapd_das_disconnect_pmksa(struct hostapd_data *hapd,
851 struct radius_das_attrs *attr)
852{
853 if (!hapd->wpa_auth)
854 return -1;
855 return wpa_auth_radius_das_disconnect_pmksa(hapd->wpa_auth, attr);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700856}
857
858
859static enum radius_das_res
860hostapd_das_disconnect(void *ctx, struct radius_das_attrs *attr)
861{
862 struct hostapd_data *hapd = ctx;
863 struct sta_info *sta;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800864 int multi;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700865
866 if (hostapd_das_nas_mismatch(hapd, attr))
867 return RADIUS_DAS_NAS_MISMATCH;
868
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800869 sta = hostapd_das_find_sta(hapd, attr, &multi);
870 if (sta == NULL) {
871 if (multi) {
872 wpa_printf(MSG_DEBUG,
873 "RADIUS DAS: Multiple sessions match - not supported");
874 return RADIUS_DAS_MULTI_SESSION_MATCH;
875 }
876 if (hostapd_das_disconnect_pmksa(hapd, attr) == 0) {
877 wpa_printf(MSG_DEBUG,
878 "RADIUS DAS: PMKSA cache entry matched");
879 return RADIUS_DAS_SUCCESS;
880 }
881 wpa_printf(MSG_DEBUG, "RADIUS DAS: No matching session found");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700882 return RADIUS_DAS_SESSION_NOT_FOUND;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800883 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700884
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800885 wpa_printf(MSG_DEBUG, "RADIUS DAS: Found a matching session " MACSTR
886 " - disconnecting", MAC2STR(sta->addr));
Dmitry Shmidt13ca8d82014-02-20 10:18:40 -0800887 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
888
Dmitry Shmidt04949592012-07-19 12:16:46 -0700889 hostapd_drv_sta_deauth(hapd, sta->addr,
890 WLAN_REASON_PREV_AUTH_NOT_VALID);
891 ap_sta_deauthenticate(hapd, sta, WLAN_REASON_PREV_AUTH_NOT_VALID);
892
893 return RADIUS_DAS_SUCCESS;
894}
895
896#endif /* CONFIG_NO_RADIUS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700897
898
899/**
900 * hostapd_setup_bss - Per-BSS setup (initialization)
901 * @hapd: Pointer to BSS data
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800902 * @first: Whether this BSS is the first BSS of an interface; -1 = not first,
903 * but interface may exist
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700904 *
905 * This function is used to initialize all per-BSS data structures and
906 * resources. This gets called in a loop for each BSS when an interface is
907 * initialized. Most of the modules that are initialized here will be
908 * deinitialized in hostapd_cleanup().
909 */
910static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
911{
912 struct hostapd_bss_config *conf = hapd->conf;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700913 u8 ssid[SSID_MAX_LEN + 1];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700914 int ssid_len, set_ssid;
915 char force_ifname[IFNAMSIZ];
916 u8 if_addr[ETH_ALEN];
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800917 int flush_old_stations = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700918
Dmitry Shmidt54605472013-11-08 11:10:19 -0800919 wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s), first=%d)",
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700920 __func__, hapd, conf->iface, first);
Dmitry Shmidt54605472013-11-08 11:10:19 -0800921
Dmitry Shmidt50b691d2014-05-21 14:01:45 -0700922#ifdef EAP_SERVER_TNC
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700923 if (conf->tnc && tncs_global_init() < 0) {
Dmitry Shmidt50b691d2014-05-21 14:01:45 -0700924 wpa_printf(MSG_ERROR, "Failed to initialize TNCS");
925 return -1;
926 }
927#endif /* EAP_SERVER_TNC */
928
Dmitry Shmidt54605472013-11-08 11:10:19 -0800929 if (hapd->started) {
930 wpa_printf(MSG_ERROR, "%s: Interface %s was already started",
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700931 __func__, conf->iface);
Dmitry Shmidt54605472013-11-08 11:10:19 -0800932 return -1;
933 }
934 hapd->started = 1;
935
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800936 if (!first || first == -1) {
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -0800937 u8 *addr = hapd->own_addr;
938
939 if (!is_zero_ether_addr(conf->bssid)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700940 /* Allocate the configured BSSID. */
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700941 os_memcpy(hapd->own_addr, conf->bssid, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700942
943 if (hostapd_mac_comp(hapd->own_addr,
944 hapd->iface->bss[0]->own_addr) ==
945 0) {
946 wpa_printf(MSG_ERROR, "BSS '%s' may not have "
947 "BSSID set to the MAC address of "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700948 "the radio", conf->iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700949 return -1;
950 }
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -0800951 } else if (hapd->iconf->use_driver_iface_addr) {
952 addr = NULL;
953 } else {
954 /* Allocate the next available BSSID. */
955 do {
956 inc_byte_array(hapd->own_addr, ETH_ALEN);
957 } while (mac_in_conf(hapd->iconf, hapd->own_addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700958 }
959
Dmitry Shmidt54605472013-11-08 11:10:19 -0800960 hapd->interface_added = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700961 if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS,
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -0800962 conf->iface, addr, hapd,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700963 &hapd->drv_priv, force_ifname, if_addr,
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700964 conf->bridge[0] ? conf->bridge : NULL,
965 first == -1)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700966 wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
967 MACSTR ")", MAC2STR(hapd->own_addr));
Dmitry Shmidt3cf6f792013-12-18 13:12:19 -0800968 hapd->interface_added = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700969 return -1;
970 }
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -0800971
972 if (!addr)
973 os_memcpy(hapd->own_addr, if_addr, ETH_ALEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700974 }
975
976 if (conf->wmm_enabled < 0)
977 conf->wmm_enabled = hapd->iconf->ieee80211n;
978
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800979#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800980 if (is_zero_ether_addr(conf->r1_key_holder))
981 os_memcpy(conf->r1_key_holder, hapd->own_addr, ETH_ALEN);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800982#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800983
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800984#ifdef CONFIG_MESH
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700985 if ((hapd->conf->mesh & MESH_ENABLED) && hapd->iface->mconf == NULL)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800986 flush_old_stations = 0;
987#endif /* CONFIG_MESH */
988
989 if (flush_old_stations)
990 hostapd_flush_old_stations(hapd,
991 WLAN_REASON_PREV_AUTH_NOT_VALID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700992 hostapd_set_privacy(hapd, 0);
993
994 hostapd_broadcast_wep_clear(hapd);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700995 if (hostapd_setup_encryption(conf->iface, hapd))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700996 return -1;
997
998 /*
999 * Fetch the SSID from the system and use it or,
1000 * if one was specified in the config file, verify they
1001 * match.
1002 */
1003 ssid_len = hostapd_get_ssid(hapd, ssid, sizeof(ssid));
1004 if (ssid_len < 0) {
1005 wpa_printf(MSG_ERROR, "Could not read SSID from system");
1006 return -1;
1007 }
1008 if (conf->ssid.ssid_set) {
1009 /*
1010 * If SSID is specified in the config file and it differs
1011 * from what is being used then force installation of the
1012 * new SSID.
1013 */
1014 set_ssid = (conf->ssid.ssid_len != (size_t) ssid_len ||
1015 os_memcmp(conf->ssid.ssid, ssid, ssid_len) != 0);
1016 } else {
1017 /*
1018 * No SSID in the config file; just use the one we got
1019 * from the system.
1020 */
1021 set_ssid = 0;
1022 conf->ssid.ssid_len = ssid_len;
1023 os_memcpy(conf->ssid.ssid, ssid, conf->ssid.ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001024 }
1025
1026 if (!hostapd_drv_none(hapd)) {
1027 wpa_printf(MSG_ERROR, "Using interface %s with hwaddr " MACSTR
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001028 " and ssid \"%s\"",
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001029 conf->iface, MAC2STR(hapd->own_addr),
1030 wpa_ssid_txt(conf->ssid.ssid, conf->ssid.ssid_len));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001031 }
1032
1033 if (hostapd_setup_wpa_psk(conf)) {
1034 wpa_printf(MSG_ERROR, "WPA-PSK setup failed.");
1035 return -1;
1036 }
1037
1038 /* Set SSID for the kernel driver (to be used in beacon and probe
1039 * response frames) */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001040 if (set_ssid && hostapd_set_ssid(hapd, conf->ssid.ssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001041 conf->ssid.ssid_len)) {
1042 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
1043 return -1;
1044 }
1045
Dmitry Shmidt818ea482014-03-10 13:15:21 -07001046 if (wpa_debug_level <= MSG_MSGDUMP)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001047 conf->radius->msg_dumps = 1;
1048#ifndef CONFIG_NO_RADIUS
1049 hapd->radius = radius_client_init(hapd, conf->radius);
1050 if (hapd->radius == NULL) {
1051 wpa_printf(MSG_ERROR, "RADIUS client initialization failed.");
1052 return -1;
1053 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001054
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001055 if (conf->radius_das_port) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001056 struct radius_das_conf das_conf;
1057 os_memset(&das_conf, 0, sizeof(das_conf));
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001058 das_conf.port = conf->radius_das_port;
1059 das_conf.shared_secret = conf->radius_das_shared_secret;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001060 das_conf.shared_secret_len =
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001061 conf->radius_das_shared_secret_len;
1062 das_conf.client_addr = &conf->radius_das_client_addr;
1063 das_conf.time_window = conf->radius_das_time_window;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001064 das_conf.require_event_timestamp =
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001065 conf->radius_das_require_event_timestamp;
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001066 das_conf.require_message_authenticator =
1067 conf->radius_das_require_message_authenticator;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001068 das_conf.ctx = hapd;
1069 das_conf.disconnect = hostapd_das_disconnect;
1070 hapd->radius_das = radius_das_init(&das_conf);
1071 if (hapd->radius_das == NULL) {
1072 wpa_printf(MSG_ERROR, "RADIUS DAS initialization "
1073 "failed.");
1074 return -1;
1075 }
1076 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001077#endif /* CONFIG_NO_RADIUS */
1078
1079 if (hostapd_acl_init(hapd)) {
1080 wpa_printf(MSG_ERROR, "ACL initialization failed.");
1081 return -1;
1082 }
1083 if (hostapd_init_wps(hapd, conf))
1084 return -1;
1085
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001086#ifdef CONFIG_DPP
1087 hapd->gas = gas_query_ap_init(hapd, hapd->msg_ctx);
1088 if (!hapd->gas)
1089 return -1;
1090 if (hostapd_dpp_init(hapd))
1091 return -1;
1092#endif /* CONFIG_DPP */
1093
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001094 if (authsrv_init(hapd) < 0)
1095 return -1;
1096
1097 if (ieee802_1x_init(hapd)) {
1098 wpa_printf(MSG_ERROR, "IEEE 802.1X initialization failed.");
1099 return -1;
1100 }
1101
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001102 if ((conf->wpa || conf->osen) && hostapd_setup_wpa(hapd))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001103 return -1;
1104
1105 if (accounting_init(hapd)) {
1106 wpa_printf(MSG_ERROR, "Accounting initialization failed.");
1107 return -1;
1108 }
1109
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001110 if (conf->ieee802_11f &&
1111 (hapd->iapp = iapp_init(hapd, conf->iapp_iface)) == NULL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001112 wpa_printf(MSG_ERROR, "IEEE 802.11F (IAPP) initialization "
1113 "failed.");
1114 return -1;
1115 }
1116
Dmitry Shmidt04949592012-07-19 12:16:46 -07001117#ifdef CONFIG_INTERWORKING
1118 if (gas_serv_init(hapd)) {
1119 wpa_printf(MSG_ERROR, "GAS server initialization failed");
1120 return -1;
1121 }
Dmitry Shmidt04949592012-07-19 12:16:46 -07001122
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001123 if (conf->qos_map_set_len &&
1124 hostapd_drv_set_qos_map(hapd, conf->qos_map_set,
1125 conf->qos_map_set_len)) {
1126 wpa_printf(MSG_ERROR, "Failed to initialize QoS Map");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001127 return -1;
1128 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001129#endif /* CONFIG_INTERWORKING */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001130
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001131 if (conf->bss_load_update_period && bss_load_update_init(hapd)) {
1132 wpa_printf(MSG_ERROR, "BSS Load initialization failed");
1133 return -1;
1134 }
1135
1136 if (conf->proxy_arp) {
1137 if (x_snoop_init(hapd)) {
1138 wpa_printf(MSG_ERROR,
1139 "Generic snooping infrastructure initialization failed");
1140 return -1;
1141 }
1142
1143 if (dhcp_snoop_init(hapd)) {
1144 wpa_printf(MSG_ERROR,
1145 "DHCP snooping initialization failed");
1146 return -1;
1147 }
1148
1149 if (ndisc_snoop_init(hapd)) {
1150 wpa_printf(MSG_ERROR,
1151 "Neighbor Discovery snooping initialization failed");
1152 return -1;
1153 }
1154 }
1155
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001156 if (!hostapd_drv_none(hapd) && vlan_init(hapd)) {
1157 wpa_printf(MSG_ERROR, "VLAN initialization failed.");
1158 return -1;
1159 }
1160
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001161 if (!conf->start_disabled && ieee802_11_set_beacon(hapd) < 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001162 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001163
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001164 if (hapd->wpa_auth && wpa_init_keys(hapd->wpa_auth) < 0)
1165 return -1;
1166
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001167 if (hapd->driver && hapd->driver->set_operstate)
1168 hapd->driver->set_operstate(hapd->drv_priv, 1);
1169
1170 return 0;
1171}
1172
1173
1174static void hostapd_tx_queue_params(struct hostapd_iface *iface)
1175{
1176 struct hostapd_data *hapd = iface->bss[0];
1177 int i;
1178 struct hostapd_tx_queue_params *p;
1179
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001180#ifdef CONFIG_MESH
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001181 if ((hapd->conf->mesh & MESH_ENABLED) && iface->mconf == NULL)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001182 return;
1183#endif /* CONFIG_MESH */
1184
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001185 for (i = 0; i < NUM_TX_QUEUES; i++) {
1186 p = &iface->conf->tx_queue[i];
1187
1188 if (hostapd_set_tx_queue_params(hapd, i, p->aifs, p->cwmin,
1189 p->cwmax, p->burst)) {
1190 wpa_printf(MSG_DEBUG, "Failed to set TX queue "
1191 "parameters for queue %d.", i);
1192 /* Continue anyway */
1193 }
1194 }
1195}
1196
1197
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07001198static int hostapd_set_acl_list(struct hostapd_data *hapd,
1199 struct mac_acl_entry *mac_acl,
1200 int n_entries, u8 accept_acl)
1201{
1202 struct hostapd_acl_params *acl_params;
1203 int i, err;
1204
1205 acl_params = os_zalloc(sizeof(*acl_params) +
1206 (n_entries * sizeof(acl_params->mac_acl[0])));
1207 if (!acl_params)
1208 return -ENOMEM;
1209
1210 for (i = 0; i < n_entries; i++)
1211 os_memcpy(acl_params->mac_acl[i].addr, mac_acl[i].addr,
1212 ETH_ALEN);
1213
1214 acl_params->acl_policy = accept_acl;
1215 acl_params->num_mac_acl = n_entries;
1216
1217 err = hostapd_drv_set_acl(hapd, acl_params);
1218
1219 os_free(acl_params);
1220
1221 return err;
1222}
1223
1224
1225static void hostapd_set_acl(struct hostapd_data *hapd)
1226{
1227 struct hostapd_config *conf = hapd->iconf;
1228 int err;
1229 u8 accept_acl;
1230
1231 if (hapd->iface->drv_max_acl_mac_addrs == 0)
1232 return;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07001233
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001234 if (conf->bss[0]->macaddr_acl == DENY_UNLESS_ACCEPTED) {
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07001235 accept_acl = 1;
1236 err = hostapd_set_acl_list(hapd, conf->bss[0]->accept_mac,
1237 conf->bss[0]->num_accept_mac,
1238 accept_acl);
1239 if (err) {
1240 wpa_printf(MSG_DEBUG, "Failed to set accept acl");
1241 return;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07001242 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001243 } else if (conf->bss[0]->macaddr_acl == ACCEPT_UNLESS_DENIED) {
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07001244 accept_acl = 0;
1245 err = hostapd_set_acl_list(hapd, conf->bss[0]->deny_mac,
1246 conf->bss[0]->num_deny_mac,
1247 accept_acl);
1248 if (err) {
1249 wpa_printf(MSG_DEBUG, "Failed to set deny acl");
1250 return;
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07001251 }
1252 }
1253}
1254
1255
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001256static int start_ctrl_iface_bss(struct hostapd_data *hapd)
1257{
1258 if (!hapd->iface->interfaces ||
1259 !hapd->iface->interfaces->ctrl_iface_init)
1260 return 0;
1261
1262 if (hapd->iface->interfaces->ctrl_iface_init(hapd)) {
1263 wpa_printf(MSG_ERROR,
1264 "Failed to setup control interface for %s",
1265 hapd->conf->iface);
1266 return -1;
1267 }
1268
1269 return 0;
1270}
1271
1272
1273static int start_ctrl_iface(struct hostapd_iface *iface)
1274{
1275 size_t i;
1276
1277 if (!iface->interfaces || !iface->interfaces->ctrl_iface_init)
1278 return 0;
1279
1280 for (i = 0; i < iface->num_bss; i++) {
1281 struct hostapd_data *hapd = iface->bss[i];
1282 if (iface->interfaces->ctrl_iface_init(hapd)) {
1283 wpa_printf(MSG_ERROR,
1284 "Failed to setup control interface for %s",
1285 hapd->conf->iface);
1286 return -1;
1287 }
1288 }
1289
1290 return 0;
1291}
1292
1293
1294static void channel_list_update_timeout(void *eloop_ctx, void *timeout_ctx)
1295{
1296 struct hostapd_iface *iface = eloop_ctx;
1297
1298 if (!iface->wait_channel_update) {
1299 wpa_printf(MSG_INFO, "Channel list update timeout, but interface was not waiting for it");
1300 return;
1301 }
1302
1303 /*
1304 * It is possible that the existing channel list is acceptable, so try
1305 * to proceed.
1306 */
1307 wpa_printf(MSG_DEBUG, "Channel list update timeout - try to continue anyway");
1308 setup_interface2(iface);
1309}
1310
1311
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001312void hostapd_channel_list_updated(struct hostapd_iface *iface, int initiator)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001313{
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001314 if (!iface->wait_channel_update || initiator != REGDOM_SET_BY_USER)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001315 return;
1316
1317 wpa_printf(MSG_DEBUG, "Channel list updated - continue setup");
1318 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
1319 setup_interface2(iface);
1320}
1321
1322
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001323static int setup_interface(struct hostapd_iface *iface)
1324{
1325 struct hostapd_data *hapd = iface->bss[0];
1326 size_t i;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001327
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001328 /*
1329 * It is possible that setup_interface() is called after the interface
1330 * was disabled etc., in which case driver_ap_teardown is possibly set
1331 * to 1. Clear it here so any other key/station deletion, which is not
1332 * part of a teardown flow, would also call the relevant driver
1333 * callbacks.
1334 */
1335 iface->driver_ap_teardown = 0;
1336
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001337 if (!iface->phy[0]) {
1338 const char *phy = hostapd_drv_get_radio_name(hapd);
1339 if (phy) {
1340 wpa_printf(MSG_DEBUG, "phy: %s", phy);
1341 os_strlcpy(iface->phy, phy, sizeof(iface->phy));
1342 }
1343 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001344
1345 /*
1346 * Make sure that all BSSes get configured with a pointer to the same
1347 * driver interface.
1348 */
1349 for (i = 1; i < iface->num_bss; i++) {
1350 iface->bss[i]->driver = hapd->driver;
1351 iface->bss[i]->drv_priv = hapd->drv_priv;
1352 }
1353
1354 if (hostapd_validate_bssid_configuration(iface))
1355 return -1;
1356
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001357 /*
1358 * Initialize control interfaces early to allow external monitoring of
1359 * channel setup operations that may take considerable amount of time
1360 * especially for DFS cases.
1361 */
1362 if (start_ctrl_iface(iface))
1363 return -1;
1364
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001365 if (hapd->iconf->country[0] && hapd->iconf->country[1]) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001366 char country[4], previous_country[4];
1367
1368 hostapd_set_state(iface, HAPD_IFACE_COUNTRY_UPDATE);
1369 if (hostapd_get_country(hapd, previous_country) < 0)
1370 previous_country[0] = '\0';
1371
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001372 os_memcpy(country, hapd->iconf->country, 3);
1373 country[3] = '\0';
1374 if (hostapd_set_country(hapd, country) < 0) {
1375 wpa_printf(MSG_ERROR, "Failed to set country code");
1376 return -1;
1377 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001378
1379 wpa_printf(MSG_DEBUG, "Previous country code %s, new country code %s",
1380 previous_country, country);
1381
1382 if (os_strncmp(previous_country, country, 2) != 0) {
1383 wpa_printf(MSG_DEBUG, "Continue interface setup after channel list update");
1384 iface->wait_channel_update = 1;
Dmitry Shmidt97672262014-02-03 13:02:54 -08001385 eloop_register_timeout(5, 0,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001386 channel_list_update_timeout,
1387 iface, NULL);
1388 return 0;
1389 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001390 }
1391
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001392 return setup_interface2(iface);
1393}
1394
1395
1396static int setup_interface2(struct hostapd_iface *iface)
1397{
1398 iface->wait_channel_update = 0;
1399
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001400 if (hostapd_get_hw_features(iface)) {
1401 /* Not all drivers support this yet, so continue without hw
1402 * feature data. */
1403 } else {
1404 int ret = hostapd_select_hw_mode(iface);
1405 if (ret < 0) {
1406 wpa_printf(MSG_ERROR, "Could not select hw_mode and "
1407 "channel. (%d)", ret);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001408 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001409 }
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001410 if (ret == 1) {
1411 wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback (ACS)");
1412 return 0;
1413 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001414 ret = hostapd_check_ht_capab(iface);
1415 if (ret < 0)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001416 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001417 if (ret == 1) {
1418 wpa_printf(MSG_DEBUG, "Interface initialization will "
1419 "be completed in a callback");
1420 return 0;
1421 }
Dmitry Shmidt051af732013-10-22 13:52:46 -07001422
1423 if (iface->conf->ieee80211h)
1424 wpa_printf(MSG_DEBUG, "DFS support is enabled");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001425 }
1426 return hostapd_setup_interface_complete(iface, 0);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001427
1428fail:
1429 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
1430 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
1431 if (iface->interfaces && iface->interfaces->terminate_on_error)
1432 eloop_terminate();
1433 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001434}
1435
1436
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001437#ifdef CONFIG_FST
1438
1439static const u8 * fst_hostapd_get_bssid_cb(void *ctx)
1440{
1441 struct hostapd_data *hapd = ctx;
1442
1443 return hapd->own_addr;
1444}
1445
1446
1447static void fst_hostapd_get_channel_info_cb(void *ctx,
1448 enum hostapd_hw_mode *hw_mode,
1449 u8 *channel)
1450{
1451 struct hostapd_data *hapd = ctx;
1452
1453 *hw_mode = ieee80211_freq_to_chan(hapd->iface->freq, channel);
1454}
1455
1456
1457static void fst_hostapd_set_ies_cb(void *ctx, const struct wpabuf *fst_ies)
1458{
1459 struct hostapd_data *hapd = ctx;
1460
1461 if (hapd->iface->fst_ies != fst_ies) {
1462 hapd->iface->fst_ies = fst_ies;
1463 if (ieee802_11_set_beacon(hapd))
1464 wpa_printf(MSG_WARNING, "FST: Cannot set beacon");
1465 }
1466}
1467
1468
1469static int fst_hostapd_send_action_cb(void *ctx, const u8 *da,
1470 struct wpabuf *buf)
1471{
1472 struct hostapd_data *hapd = ctx;
1473
1474 return hostapd_drv_send_action(hapd, hapd->iface->freq, 0, da,
1475 wpabuf_head(buf), wpabuf_len(buf));
1476}
1477
1478
1479static const struct wpabuf * fst_hostapd_get_mb_ie_cb(void *ctx, const u8 *addr)
1480{
1481 struct hostapd_data *hapd = ctx;
1482 struct sta_info *sta = ap_get_sta(hapd, addr);
1483
1484 return sta ? sta->mb_ies : NULL;
1485}
1486
1487
1488static void fst_hostapd_update_mb_ie_cb(void *ctx, const u8 *addr,
1489 const u8 *buf, size_t size)
1490{
1491 struct hostapd_data *hapd = ctx;
1492 struct sta_info *sta = ap_get_sta(hapd, addr);
1493
1494 if (sta) {
1495 struct mb_ies_info info;
1496
1497 if (!mb_ies_info_by_ies(&info, buf, size)) {
1498 wpabuf_free(sta->mb_ies);
1499 sta->mb_ies = mb_ies_by_info(&info);
1500 }
1501 }
1502}
1503
1504
1505static const u8 * fst_hostapd_get_sta(struct fst_get_peer_ctx **get_ctx,
1506 Boolean mb_only)
1507{
1508 struct sta_info *s = (struct sta_info *) *get_ctx;
1509
1510 if (mb_only) {
1511 for (; s && !s->mb_ies; s = s->next)
1512 ;
1513 }
1514
1515 if (s) {
1516 *get_ctx = (struct fst_get_peer_ctx *) s->next;
1517
1518 return s->addr;
1519 }
1520
1521 *get_ctx = NULL;
1522 return NULL;
1523}
1524
1525
1526static const u8 * fst_hostapd_get_peer_first(void *ctx,
1527 struct fst_get_peer_ctx **get_ctx,
1528 Boolean mb_only)
1529{
1530 struct hostapd_data *hapd = ctx;
1531
1532 *get_ctx = (struct fst_get_peer_ctx *) hapd->sta_list;
1533
1534 return fst_hostapd_get_sta(get_ctx, mb_only);
1535}
1536
1537
1538static const u8 * fst_hostapd_get_peer_next(void *ctx,
1539 struct fst_get_peer_ctx **get_ctx,
1540 Boolean mb_only)
1541{
1542 return fst_hostapd_get_sta(get_ctx, mb_only);
1543}
1544
1545
1546void fst_hostapd_fill_iface_obj(struct hostapd_data *hapd,
1547 struct fst_wpa_obj *iface_obj)
1548{
1549 iface_obj->ctx = hapd;
1550 iface_obj->get_bssid = fst_hostapd_get_bssid_cb;
1551 iface_obj->get_channel_info = fst_hostapd_get_channel_info_cb;
1552 iface_obj->set_ies = fst_hostapd_set_ies_cb;
1553 iface_obj->send_action = fst_hostapd_send_action_cb;
1554 iface_obj->get_mb_ie = fst_hostapd_get_mb_ie_cb;
1555 iface_obj->update_mb_ie = fst_hostapd_update_mb_ie_cb;
1556 iface_obj->get_peer_first = fst_hostapd_get_peer_first;
1557 iface_obj->get_peer_next = fst_hostapd_get_peer_next;
1558}
1559
1560#endif /* CONFIG_FST */
1561
1562
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001563#ifdef NEED_AP_MLME
1564static enum nr_chan_width hostapd_get_nr_chan_width(struct hostapd_data *hapd,
1565 int ht, int vht)
1566{
1567 if (!ht && !vht)
1568 return NR_CHAN_WIDTH_20;
1569 if (!hapd->iconf->secondary_channel)
1570 return NR_CHAN_WIDTH_20;
1571 if (!vht || hapd->iconf->vht_oper_chwidth == VHT_CHANWIDTH_USE_HT)
1572 return NR_CHAN_WIDTH_40;
1573 if (hapd->iconf->vht_oper_chwidth == VHT_CHANWIDTH_80MHZ)
1574 return NR_CHAN_WIDTH_80;
1575 if (hapd->iconf->vht_oper_chwidth == VHT_CHANWIDTH_160MHZ)
1576 return NR_CHAN_WIDTH_160;
1577 if (hapd->iconf->vht_oper_chwidth == VHT_CHANWIDTH_80P80MHZ)
1578 return NR_CHAN_WIDTH_80P80;
1579 return NR_CHAN_WIDTH_20;
1580}
1581#endif /* NEED_AP_MLME */
1582
1583
1584static void hostapd_set_own_neighbor_report(struct hostapd_data *hapd)
1585{
1586#ifdef NEED_AP_MLME
1587 u16 capab = hostapd_own_capab_info(hapd);
1588 int ht = hapd->iconf->ieee80211n && !hapd->conf->disable_11n;
1589 int vht = hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac;
1590 struct wpa_ssid_value ssid;
1591 u8 channel, op_class;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001592 u8 center_freq1_idx = 0, center_freq2_idx = 0;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001593 enum nr_chan_width width;
1594 u32 bssid_info;
1595 struct wpabuf *nr;
1596
1597 if (!(hapd->conf->radio_measurements[0] &
1598 WLAN_RRM_CAPS_NEIGHBOR_REPORT))
1599 return;
1600
1601 bssid_info = 3; /* AP is reachable */
1602 bssid_info |= NEI_REP_BSSID_INFO_SECURITY; /* "same as the AP" */
1603 bssid_info |= NEI_REP_BSSID_INFO_KEY_SCOPE; /* "same as the AP" */
1604
1605 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT)
1606 bssid_info |= NEI_REP_BSSID_INFO_SPECTRUM_MGMT;
1607
1608 bssid_info |= NEI_REP_BSSID_INFO_RM; /* RRM is supported */
1609
1610 if (hapd->conf->wmm_enabled) {
1611 bssid_info |= NEI_REP_BSSID_INFO_QOS;
1612
1613 if (hapd->conf->wmm_uapsd &&
1614 (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
1615 bssid_info |= NEI_REP_BSSID_INFO_APSD;
1616 }
1617
1618 if (ht) {
1619 bssid_info |= NEI_REP_BSSID_INFO_HT |
1620 NEI_REP_BSSID_INFO_DELAYED_BA;
1621
1622 /* VHT bit added in IEEE P802.11-REVmc/D4.3 */
1623 if (vht)
1624 bssid_info |= NEI_REP_BSSID_INFO_VHT;
1625 }
1626
1627 /* TODO: Set NEI_REP_BSSID_INFO_MOBILITY_DOMAIN if MDE is set */
1628
Dmitry Shmidt29333592017-01-09 12:27:11 -08001629 if (ieee80211_freq_to_channel_ext(hapd->iface->freq,
1630 hapd->iconf->secondary_channel,
1631 hapd->iconf->vht_oper_chwidth,
1632 &op_class, &channel) ==
1633 NUM_HOSTAPD_MODES)
1634 return;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001635 width = hostapd_get_nr_chan_width(hapd, ht, vht);
1636 if (vht) {
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001637 center_freq1_idx = hapd->iconf->vht_oper_centr_freq_seg0_idx;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001638 if (width == NR_CHAN_WIDTH_80P80)
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001639 center_freq2_idx =
1640 hapd->iconf->vht_oper_centr_freq_seg1_idx;
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001641 } else if (ht) {
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001642 ieee80211_freq_to_chan(hapd->iface->freq +
1643 10 * hapd->iconf->secondary_channel,
1644 &center_freq1_idx);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001645 }
1646
1647 ssid.ssid_len = hapd->conf->ssid.ssid_len;
1648 os_memcpy(ssid.ssid, hapd->conf->ssid.ssid, ssid.ssid_len);
1649
1650 /*
1651 * Neighbor Report element size = BSSID + BSSID info + op_class + chan +
1652 * phy type + wide bandwidth channel subelement.
1653 */
1654 nr = wpabuf_alloc(ETH_ALEN + 4 + 1 + 1 + 1 + 5);
1655 if (!nr)
1656 return;
1657
1658 wpabuf_put_data(nr, hapd->own_addr, ETH_ALEN);
1659 wpabuf_put_le32(nr, bssid_info);
1660 wpabuf_put_u8(nr, op_class);
1661 wpabuf_put_u8(nr, channel);
1662 wpabuf_put_u8(nr, ieee80211_get_phy_type(hapd->iface->freq, ht, vht));
1663
1664 /*
1665 * Wide Bandwidth Channel subelement may be needed to allow the
1666 * receiving STA to send packets to the AP. See IEEE P802.11-REVmc/D5.0
1667 * Figure 9-301.
1668 */
1669 wpabuf_put_u8(nr, WNM_NEIGHBOR_WIDE_BW_CHAN);
1670 wpabuf_put_u8(nr, 3);
1671 wpabuf_put_u8(nr, width);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001672 wpabuf_put_u8(nr, center_freq1_idx);
1673 wpabuf_put_u8(nr, center_freq2_idx);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001674
1675 hostapd_neighbor_set(hapd, hapd->own_addr, &ssid, nr, hapd->iconf->lci,
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001676 hapd->iconf->civic, hapd->iconf->stationary_ap);
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001677
1678 wpabuf_free(nr);
1679#endif /* NEED_AP_MLME */
1680}
1681
1682
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001683#ifdef CONFIG_OWE
1684
1685static int hostapd_owe_iface_iter(struct hostapd_iface *iface, void *ctx)
1686{
1687 struct hostapd_data *hapd = ctx;
1688 size_t i;
1689
1690 for (i = 0; i < iface->num_bss; i++) {
1691 struct hostapd_data *bss = iface->bss[i];
1692
1693 if (os_strcmp(hapd->conf->owe_transition_ifname,
1694 bss->conf->iface) != 0)
1695 continue;
1696
1697 wpa_printf(MSG_DEBUG,
1698 "OWE: ifname=%s found transition mode ifname=%s BSSID "
1699 MACSTR " SSID %s",
1700 hapd->conf->iface, bss->conf->iface,
1701 MAC2STR(bss->own_addr),
1702 wpa_ssid_txt(bss->conf->ssid.ssid,
1703 bss->conf->ssid.ssid_len));
1704 if (!bss->conf->ssid.ssid_set || !bss->conf->ssid.ssid_len ||
1705 is_zero_ether_addr(bss->own_addr))
1706 continue;
1707
1708 os_memcpy(hapd->conf->owe_transition_bssid, bss->own_addr,
1709 ETH_ALEN);
1710 os_memcpy(hapd->conf->owe_transition_ssid,
1711 bss->conf->ssid.ssid, bss->conf->ssid.ssid_len);
1712 hapd->conf->owe_transition_ssid_len = bss->conf->ssid.ssid_len;
1713 wpa_printf(MSG_DEBUG,
1714 "OWE: Copied transition mode information");
1715 return 1;
1716 }
1717
1718 return 0;
1719}
1720
1721
1722int hostapd_owe_trans_get_info(struct hostapd_data *hapd)
1723{
1724 if (hapd->conf->owe_transition_ssid_len > 0 &&
1725 !is_zero_ether_addr(hapd->conf->owe_transition_bssid))
1726 return 0;
1727
1728 /* Find transition mode SSID/BSSID information from a BSS operated by
1729 * this hostapd instance. */
1730 if (!hapd->iface->interfaces ||
1731 !hapd->iface->interfaces->for_each_interface)
1732 return hostapd_owe_iface_iter(hapd->iface, hapd);
1733 else
1734 return hapd->iface->interfaces->for_each_interface(
1735 hapd->iface->interfaces, hostapd_owe_iface_iter, hapd);
1736}
1737
1738
1739static int hostapd_owe_iface_iter2(struct hostapd_iface *iface, void *ctx)
1740{
1741 size_t i;
1742
1743 for (i = 0; i < iface->num_bss; i++) {
1744 struct hostapd_data *bss = iface->bss[i];
1745 int res;
1746
1747 if (!bss->conf->owe_transition_ifname[0])
1748 continue;
1749 res = hostapd_owe_trans_get_info(bss);
1750 if (res == 0)
1751 continue;
1752 wpa_printf(MSG_DEBUG,
1753 "OWE: Matching transition mode interface enabled - update beacon data for %s",
1754 bss->conf->iface);
1755 ieee802_11_set_beacon(bss);
1756 }
1757
1758 return 0;
1759}
1760
1761#endif /* CONFIG_OWE */
1762
1763
1764static void hostapd_owe_update_trans(struct hostapd_iface *iface)
1765{
1766#ifdef CONFIG_OWE
1767 /* Check whether the enabled BSS can complete OWE transition mode
1768 * configuration for any pending interface. */
1769 if (!iface->interfaces ||
1770 !iface->interfaces->for_each_interface)
1771 hostapd_owe_iface_iter2(iface, NULL);
1772 else
1773 iface->interfaces->for_each_interface(
1774 iface->interfaces, hostapd_owe_iface_iter2, NULL);
1775#endif /* CONFIG_OWE */
1776}
1777
1778
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001779static int hostapd_setup_interface_complete_sync(struct hostapd_iface *iface,
1780 int err)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001781{
1782 struct hostapd_data *hapd = iface->bss[0];
1783 size_t j;
1784 u8 *prev_addr;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001785 int delay_apply_cfg = 0;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001786 int res_dfs_offload = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001787
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001788 if (err)
1789 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001790
1791 wpa_printf(MSG_DEBUG, "Completing interface initialization");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001792 if (iface->conf->channel) {
Dmitry Shmidt051af732013-10-22 13:52:46 -07001793#ifdef NEED_AP_MLME
1794 int res;
1795#endif /* NEED_AP_MLME */
1796
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001797 iface->freq = hostapd_hw_get_freq(hapd, iface->conf->channel);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001798 wpa_printf(MSG_DEBUG, "Mode: %s Channel: %d "
1799 "Frequency: %d MHz",
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001800 hostapd_hw_mode_txt(iface->conf->hw_mode),
1801 iface->conf->channel, iface->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001802
Dmitry Shmidt051af732013-10-22 13:52:46 -07001803#ifdef NEED_AP_MLME
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001804 /* Handle DFS only if it is not offloaded to the driver */
1805 if (!(iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)) {
1806 /* Check DFS */
1807 res = hostapd_handle_dfs(iface);
1808 if (res <= 0) {
1809 if (res < 0)
1810 goto fail;
1811 return res;
1812 }
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001813 } else {
1814 /* If DFS is offloaded to the driver */
1815 res_dfs_offload = hostapd_handle_dfs_offload(iface);
1816 if (res_dfs_offload <= 0) {
1817 if (res_dfs_offload < 0)
1818 goto fail;
1819 } else {
1820 wpa_printf(MSG_DEBUG,
1821 "Proceed with AP/channel setup");
1822 /*
1823 * If this is a DFS channel, move to completing
1824 * AP setup.
1825 */
1826 if (res_dfs_offload == 1)
1827 goto dfs_offload;
1828 /* Otherwise fall through. */
1829 }
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001830 }
Dmitry Shmidt051af732013-10-22 13:52:46 -07001831#endif /* NEED_AP_MLME */
1832
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001833#ifdef CONFIG_MESH
1834 if (iface->mconf != NULL) {
1835 wpa_printf(MSG_DEBUG,
1836 "%s: Mesh configuration will be applied while joining the mesh network",
1837 iface->bss[0]->conf->iface);
1838 delay_apply_cfg = 1;
1839 }
1840#endif /* CONFIG_MESH */
1841
1842 if (!delay_apply_cfg &&
1843 hostapd_set_freq(hapd, hapd->iconf->hw_mode, iface->freq,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001844 hapd->iconf->channel,
1845 hapd->iconf->ieee80211n,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001846 hapd->iconf->ieee80211ac,
1847 hapd->iconf->secondary_channel,
1848 hapd->iconf->vht_oper_chwidth,
1849 hapd->iconf->vht_oper_centr_freq_seg0_idx,
1850 hapd->iconf->vht_oper_centr_freq_seg1_idx)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001851 wpa_printf(MSG_ERROR, "Could not set channel for "
1852 "kernel driver");
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001853 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001854 }
1855 }
1856
1857 if (iface->current_mode) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001858 if (hostapd_prepare_rates(iface, iface->current_mode)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001859 wpa_printf(MSG_ERROR, "Failed to prepare rates "
1860 "table.");
1861 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1862 HOSTAPD_LEVEL_WARNING,
1863 "Failed to prepare rates table.");
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001864 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001865 }
1866 }
1867
1868 if (hapd->iconf->rts_threshold > -1 &&
1869 hostapd_set_rts(hapd, hapd->iconf->rts_threshold)) {
1870 wpa_printf(MSG_ERROR, "Could not set RTS threshold for "
1871 "kernel driver");
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001872 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001873 }
1874
1875 if (hapd->iconf->fragm_threshold > -1 &&
1876 hostapd_set_frag(hapd, hapd->iconf->fragm_threshold)) {
1877 wpa_printf(MSG_ERROR, "Could not set fragmentation threshold "
1878 "for kernel driver");
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001879 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001880 }
1881
1882 prev_addr = hapd->own_addr;
1883
1884 for (j = 0; j < iface->num_bss; j++) {
1885 hapd = iface->bss[j];
1886 if (j)
1887 os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN);
Dmitry Shmidt71757432014-06-02 13:50:35 -07001888 if (hostapd_setup_bss(hapd, j == 0)) {
1889 do {
1890 hapd = iface->bss[j];
1891 hostapd_bss_deinit_no_free(hapd);
1892 hostapd_free_hapd_data(hapd);
1893 } while (j-- > 0);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001894 goto fail;
Dmitry Shmidt71757432014-06-02 13:50:35 -07001895 }
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001896 if (is_zero_ether_addr(hapd->conf->bssid))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001897 prev_addr = hapd->own_addr;
1898 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001899 hapd = iface->bss[0];
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001900
1901 hostapd_tx_queue_params(iface);
1902
1903 ap_list_init(iface);
1904
Dmitry Shmidt8bae4132013-06-06 11:25:10 -07001905 hostapd_set_acl(hapd);
1906
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001907 if (hostapd_driver_commit(hapd) < 0) {
1908 wpa_printf(MSG_ERROR, "%s: Failed to commit driver "
1909 "configuration", __func__);
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001910 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001911 }
1912
Jouni Malinen87fd2792011-05-16 18:35:42 +03001913 /*
1914 * WPS UPnP module can be initialized only when the "upnp_iface" is up.
1915 * If "interface" and "upnp_iface" are the same (e.g., non-bridge
1916 * mode), the interface is up only after driver_commit, so initialize
1917 * WPS after driver_commit.
1918 */
1919 for (j = 0; j < iface->num_bss; j++) {
1920 if (hostapd_init_wps_complete(iface->bss[j]))
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001921 goto fail;
Jouni Malinen87fd2792011-05-16 18:35:42 +03001922 }
1923
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001924 if ((iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) &&
1925 !res_dfs_offload) {
1926 /*
1927 * If freq is DFS, and DFS is offloaded to the driver, then wait
1928 * for CAC to complete.
1929 */
1930 wpa_printf(MSG_DEBUG, "%s: Wait for CAC to complete", __func__);
1931 return res_dfs_offload;
1932 }
1933
1934#ifdef NEED_AP_MLME
1935dfs_offload:
1936#endif /* NEED_AP_MLME */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001937
1938#ifdef CONFIG_FST
1939 if (hapd->iconf->fst_cfg.group_id[0]) {
1940 struct fst_wpa_obj iface_obj;
1941
1942 fst_hostapd_fill_iface_obj(hapd, &iface_obj);
1943 iface->fst = fst_attach(hapd->conf->iface, hapd->own_addr,
1944 &iface_obj, &hapd->iconf->fst_cfg);
1945 if (!iface->fst) {
1946 wpa_printf(MSG_ERROR, "Could not attach to FST %s",
1947 hapd->iconf->fst_cfg.group_id);
1948 goto fail;
1949 }
1950 }
1951#endif /* CONFIG_FST */
1952
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001953 hostapd_set_state(iface, HAPD_IFACE_ENABLED);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001954 hostapd_owe_update_trans(iface);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001955 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_ENABLED);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001956 if (hapd->setup_complete_cb)
1957 hapd->setup_complete_cb(hapd->setup_complete_cb_ctx);
1958
1959 wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
1960 iface->bss[0]->conf->iface);
Dmitry Shmidtb96dad42013-11-05 10:07:29 -08001961 if (iface->interfaces && iface->interfaces->terminate_on_error > 0)
1962 iface->interfaces->terminate_on_error--;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001963
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001964 for (j = 0; j < iface->num_bss; j++)
1965 hostapd_set_own_neighbor_report(iface->bss[j]);
1966
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001967 return 0;
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001968
1969fail:
1970 wpa_printf(MSG_ERROR, "Interface initialization failed");
1971 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
1972 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001973#ifdef CONFIG_FST
1974 if (iface->fst) {
1975 fst_detach(iface->fst);
1976 iface->fst = NULL;
1977 }
1978#endif /* CONFIG_FST */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001979 if (iface->interfaces && iface->interfaces->terminate_on_error)
1980 eloop_terminate();
1981 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001982}
1983
1984
1985/**
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001986 * hostapd_setup_interface_complete - Complete interface setup
1987 *
1988 * This function is called when previous steps in the interface setup has been
1989 * completed. This can also start operations, e.g., DFS, that will require
1990 * additional processing before interface is ready to be enabled. Such
1991 * operations will call this function from eloop callbacks when finished.
1992 */
1993int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err)
1994{
1995 struct hapd_interfaces *interfaces = iface->interfaces;
1996 struct hostapd_data *hapd = iface->bss[0];
1997 unsigned int i;
1998 int not_ready_in_sync_ifaces = 0;
1999
2000 if (!iface->need_to_start_in_sync)
2001 return hostapd_setup_interface_complete_sync(iface, err);
2002
2003 if (err) {
2004 wpa_printf(MSG_ERROR, "Interface initialization failed");
2005 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
2006 iface->need_to_start_in_sync = 0;
2007 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
2008 if (interfaces && interfaces->terminate_on_error)
2009 eloop_terminate();
2010 return -1;
2011 }
2012
2013 if (iface->ready_to_start_in_sync) {
2014 /* Already in ready and waiting. should never happpen */
2015 return 0;
2016 }
2017
2018 for (i = 0; i < interfaces->count; i++) {
2019 if (interfaces->iface[i]->need_to_start_in_sync &&
2020 !interfaces->iface[i]->ready_to_start_in_sync)
2021 not_ready_in_sync_ifaces++;
2022 }
2023
2024 /*
2025 * Check if this is the last interface, if yes then start all the other
2026 * waiting interfaces. If not, add this interface to the waiting list.
2027 */
2028 if (not_ready_in_sync_ifaces > 1 && iface->state == HAPD_IFACE_DFS) {
2029 /*
2030 * If this interface went through CAC, do not synchronize, just
2031 * start immediately.
2032 */
2033 iface->need_to_start_in_sync = 0;
2034 wpa_printf(MSG_INFO,
2035 "%s: Finished CAC - bypass sync and start interface",
2036 iface->bss[0]->conf->iface);
2037 return hostapd_setup_interface_complete_sync(iface, err);
2038 }
2039
2040 if (not_ready_in_sync_ifaces > 1) {
2041 /* need to wait as there are other interfaces still coming up */
2042 iface->ready_to_start_in_sync = 1;
2043 wpa_printf(MSG_INFO,
2044 "%s: Interface waiting to sync with other interfaces",
2045 iface->bss[0]->conf->iface);
2046 return 0;
2047 }
2048
2049 wpa_printf(MSG_INFO,
2050 "%s: Last interface to sync - starting all interfaces",
2051 iface->bss[0]->conf->iface);
2052 iface->need_to_start_in_sync = 0;
2053 hostapd_setup_interface_complete_sync(iface, err);
2054 for (i = 0; i < interfaces->count; i++) {
2055 if (interfaces->iface[i]->need_to_start_in_sync &&
2056 interfaces->iface[i]->ready_to_start_in_sync) {
2057 hostapd_setup_interface_complete_sync(
2058 interfaces->iface[i], 0);
2059 /* Only once the interfaces are sync started */
2060 interfaces->iface[i]->need_to_start_in_sync = 0;
2061 }
2062 }
2063
2064 return 0;
2065}
2066
2067
2068/**
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002069 * hostapd_setup_interface - Setup of an interface
2070 * @iface: Pointer to interface data.
2071 * Returns: 0 on success, -1 on failure
2072 *
2073 * Initializes the driver interface, validates the configuration,
2074 * and sets driver parameters based on the configuration.
2075 * Flushes old stations, sets the channel, encryption,
2076 * beacons, and WDS links based on the configuration.
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002077 *
2078 * If interface setup requires more time, e.g., to perform HT co-ex scans, ACS,
2079 * or DFS operations, this function returns 0 before such operations have been
2080 * completed. The pending operations are registered into eloop and will be
2081 * completed from eloop callbacks. Those callbacks end up calling
2082 * hostapd_setup_interface_complete() once setup has been completed.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002083 */
2084int hostapd_setup_interface(struct hostapd_iface *iface)
2085{
2086 int ret;
2087
2088 ret = setup_interface(iface);
2089 if (ret) {
2090 wpa_printf(MSG_ERROR, "%s: Unable to setup interface.",
2091 iface->bss[0]->conf->iface);
2092 return -1;
2093 }
2094
2095 return 0;
2096}
2097
2098
2099/**
2100 * hostapd_alloc_bss_data - Allocate and initialize per-BSS data
2101 * @hapd_iface: Pointer to interface data
2102 * @conf: Pointer to per-interface configuration
2103 * @bss: Pointer to per-BSS configuration for this BSS
2104 * Returns: Pointer to allocated BSS data
2105 *
2106 * This function is used to allocate per-BSS data structure. This data will be
2107 * freed after hostapd_cleanup() is called for it during interface
2108 * deinitialization.
2109 */
2110struct hostapd_data *
2111hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
2112 struct hostapd_config *conf,
2113 struct hostapd_bss_config *bss)
2114{
2115 struct hostapd_data *hapd;
2116
2117 hapd = os_zalloc(sizeof(*hapd));
2118 if (hapd == NULL)
2119 return NULL;
2120
2121 hapd->new_assoc_sta_cb = hostapd_new_assoc_sta;
2122 hapd->iconf = conf;
2123 hapd->conf = bss;
2124 hapd->iface = hapd_iface;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002125 if (conf)
2126 hapd->driver = conf->driver;
Dmitry Shmidt04949592012-07-19 12:16:46 -07002127 hapd->ctrl_sock = -1;
Dmitry Shmidt31a29cc2016-03-09 15:58:17 -08002128 dl_list_init(&hapd->ctrl_dst);
Dmitry Shmidt7d175302016-09-06 13:11:34 -07002129 dl_list_init(&hapd->nr_db);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -08002130 hapd->dhcp_sock = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002131#ifdef CONFIG_IEEE80211R_AP
2132 dl_list_init(&hapd->l2_queue);
2133 dl_list_init(&hapd->l2_oui_queue);
2134#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002135
2136 return hapd;
2137}
2138
2139
Dmitry Shmidt54605472013-11-08 11:10:19 -08002140static void hostapd_bss_deinit(struct hostapd_data *hapd)
2141{
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07002142 if (!hapd)
2143 return;
Dmitry Shmidt54605472013-11-08 11:10:19 -08002144 wpa_printf(MSG_DEBUG, "%s: deinit bss %s", __func__,
2145 hapd->conf->iface);
Dmitry Shmidt71757432014-06-02 13:50:35 -07002146 hostapd_bss_deinit_no_free(hapd);
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07002147 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
Dmitry Shmidt54605472013-11-08 11:10:19 -08002148 hostapd_cleanup(hapd);
2149}
2150
2151
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002152void hostapd_interface_deinit(struct hostapd_iface *iface)
2153{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002154 int j;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002155
Dmitry Shmidt54605472013-11-08 11:10:19 -08002156 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002157 if (iface == NULL)
2158 return;
2159
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07002160 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
2161
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07002162#ifdef CONFIG_IEEE80211N
2163#ifdef NEED_AP_MLME
2164 hostapd_stop_setup_timers(iface);
2165 eloop_cancel_timeout(ap_ht2040_timeout, iface, NULL);
2166#endif /* NEED_AP_MLME */
2167#endif /* CONFIG_IEEE80211N */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002168 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
2169 iface->wait_channel_update = 0;
2170
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002171#ifdef CONFIG_FST
2172 if (iface->fst) {
2173 fst_detach(iface->fst);
2174 iface->fst = NULL;
2175 }
2176#endif /* CONFIG_FST */
2177
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07002178 for (j = iface->num_bss - 1; j >= 0; j--) {
2179 if (!iface->bss)
2180 break;
Dmitry Shmidt54605472013-11-08 11:10:19 -08002181 hostapd_bss_deinit(iface->bss[j]);
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07002182 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002183}
2184
2185
2186void hostapd_interface_free(struct hostapd_iface *iface)
2187{
2188 size_t j;
Dmitry Shmidt54605472013-11-08 11:10:19 -08002189 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
2190 for (j = 0; j < iface->num_bss; j++) {
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07002191 if (!iface->bss)
2192 break;
Dmitry Shmidt54605472013-11-08 11:10:19 -08002193 wpa_printf(MSG_DEBUG, "%s: free hapd %p",
2194 __func__, iface->bss[j]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002195 os_free(iface->bss[j]);
Dmitry Shmidt54605472013-11-08 11:10:19 -08002196 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002197 hostapd_cleanup_iface(iface);
2198}
2199
2200
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07002201struct hostapd_iface * hostapd_alloc_iface(void)
2202{
2203 struct hostapd_iface *hapd_iface;
2204
2205 hapd_iface = os_zalloc(sizeof(*hapd_iface));
2206 if (!hapd_iface)
2207 return NULL;
2208
2209 dl_list_init(&hapd_iface->sta_seen);
2210
2211 return hapd_iface;
2212}
2213
2214
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002215/**
2216 * hostapd_init - Allocate and initialize per-interface data
2217 * @config_file: Path to the configuration file
2218 * Returns: Pointer to the allocated interface data or %NULL on failure
2219 *
2220 * This function is used to allocate main data structures for per-interface
2221 * data. The allocated data buffer will be freed by calling
2222 * hostapd_cleanup_iface().
2223 */
2224struct hostapd_iface * hostapd_init(struct hapd_interfaces *interfaces,
2225 const char *config_file)
2226{
2227 struct hostapd_iface *hapd_iface = NULL;
2228 struct hostapd_config *conf = NULL;
2229 struct hostapd_data *hapd;
2230 size_t i;
2231
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07002232 hapd_iface = hostapd_alloc_iface();
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002233 if (hapd_iface == NULL)
2234 goto fail;
2235
2236 hapd_iface->config_fname = os_strdup(config_file);
2237 if (hapd_iface->config_fname == NULL)
2238 goto fail;
2239
2240 conf = interfaces->config_read_cb(hapd_iface->config_fname);
2241 if (conf == NULL)
2242 goto fail;
2243 hapd_iface->conf = conf;
2244
2245 hapd_iface->num_bss = conf->num_bss;
2246 hapd_iface->bss = os_calloc(conf->num_bss,
2247 sizeof(struct hostapd_data *));
2248 if (hapd_iface->bss == NULL)
2249 goto fail;
2250
2251 for (i = 0; i < conf->num_bss; i++) {
2252 hapd = hapd_iface->bss[i] =
2253 hostapd_alloc_bss_data(hapd_iface, conf,
2254 conf->bss[i]);
2255 if (hapd == NULL)
2256 goto fail;
2257 hapd->msg_ctx = hapd;
2258 }
2259
2260 return hapd_iface;
2261
2262fail:
2263 wpa_printf(MSG_ERROR, "Failed to set up interface with %s",
2264 config_file);
2265 if (conf)
2266 hostapd_config_free(conf);
2267 if (hapd_iface) {
2268 os_free(hapd_iface->config_fname);
2269 os_free(hapd_iface->bss);
Dmitry Shmidt54605472013-11-08 11:10:19 -08002270 wpa_printf(MSG_DEBUG, "%s: free iface %p",
2271 __func__, hapd_iface);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002272 os_free(hapd_iface);
2273 }
2274 return NULL;
2275}
2276
2277
2278static int ifname_in_use(struct hapd_interfaces *interfaces, const char *ifname)
2279{
2280 size_t i, j;
2281
2282 for (i = 0; i < interfaces->count; i++) {
2283 struct hostapd_iface *iface = interfaces->iface[i];
2284 for (j = 0; j < iface->num_bss; j++) {
2285 struct hostapd_data *hapd = iface->bss[j];
2286 if (os_strcmp(ifname, hapd->conf->iface) == 0)
2287 return 1;
2288 }
2289 }
2290
2291 return 0;
2292}
2293
2294
2295/**
2296 * hostapd_interface_init_bss - Read configuration file and init BSS data
2297 *
2298 * This function is used to parse configuration file for a BSS. This BSS is
2299 * added to an existing interface sharing the same radio (if any) or a new
2300 * interface is created if this is the first interface on a radio. This
2301 * allocate memory for the BSS. No actual driver operations are started.
2302 *
2303 * This is similar to hostapd_interface_init(), but for a case where the
2304 * configuration is used to add a single BSS instead of all BSSes for a radio.
2305 */
2306struct hostapd_iface *
2307hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy,
2308 const char *config_fname, int debug)
2309{
2310 struct hostapd_iface *new_iface = NULL, *iface = NULL;
2311 struct hostapd_data *hapd;
2312 int k;
2313 size_t i, bss_idx;
2314
2315 if (!phy || !*phy)
2316 return NULL;
2317
2318 for (i = 0; i < interfaces->count; i++) {
2319 if (os_strcmp(interfaces->iface[i]->phy, phy) == 0) {
2320 iface = interfaces->iface[i];
2321 break;
2322 }
2323 }
2324
2325 wpa_printf(MSG_INFO, "Configuration file: %s (phy %s)%s",
2326 config_fname, phy, iface ? "" : " --> new PHY");
2327 if (iface) {
2328 struct hostapd_config *conf;
2329 struct hostapd_bss_config **tmp_conf;
2330 struct hostapd_data **tmp_bss;
2331 struct hostapd_bss_config *bss;
2332 const char *ifname;
2333
2334 /* Add new BSS to existing iface */
2335 conf = interfaces->config_read_cb(config_fname);
2336 if (conf == NULL)
2337 return NULL;
2338 if (conf->num_bss > 1) {
2339 wpa_printf(MSG_ERROR, "Multiple BSSes specified in BSS-config");
2340 hostapd_config_free(conf);
2341 return NULL;
2342 }
2343
2344 ifname = conf->bss[0]->iface;
2345 if (ifname[0] != '\0' && ifname_in_use(interfaces, ifname)) {
2346 wpa_printf(MSG_ERROR,
2347 "Interface name %s already in use", ifname);
2348 hostapd_config_free(conf);
2349 return NULL;
2350 }
2351
2352 tmp_conf = os_realloc_array(
2353 iface->conf->bss, iface->conf->num_bss + 1,
2354 sizeof(struct hostapd_bss_config *));
2355 tmp_bss = os_realloc_array(iface->bss, iface->num_bss + 1,
2356 sizeof(struct hostapd_data *));
2357 if (tmp_bss)
2358 iface->bss = tmp_bss;
2359 if (tmp_conf) {
2360 iface->conf->bss = tmp_conf;
2361 iface->conf->last_bss = tmp_conf[0];
2362 }
2363 if (tmp_bss == NULL || tmp_conf == NULL) {
2364 hostapd_config_free(conf);
2365 return NULL;
2366 }
2367 bss = iface->conf->bss[iface->conf->num_bss] = conf->bss[0];
2368 iface->conf->num_bss++;
2369
2370 hapd = hostapd_alloc_bss_data(iface, iface->conf, bss);
2371 if (hapd == NULL) {
2372 iface->conf->num_bss--;
2373 hostapd_config_free(conf);
2374 return NULL;
2375 }
2376 iface->conf->last_bss = bss;
2377 iface->bss[iface->num_bss] = hapd;
2378 hapd->msg_ctx = hapd;
2379
2380 bss_idx = iface->num_bss++;
2381 conf->num_bss--;
2382 conf->bss[0] = NULL;
2383 hostapd_config_free(conf);
2384 } else {
2385 /* Add a new iface with the first BSS */
2386 new_iface = iface = hostapd_init(interfaces, config_fname);
2387 if (!iface)
2388 return NULL;
2389 os_strlcpy(iface->phy, phy, sizeof(iface->phy));
2390 iface->interfaces = interfaces;
2391 bss_idx = 0;
2392 }
2393
2394 for (k = 0; k < debug; k++) {
2395 if (iface->bss[bss_idx]->conf->logger_stdout_level > 0)
2396 iface->bss[bss_idx]->conf->logger_stdout_level--;
2397 }
2398
2399 if (iface->conf->bss[bss_idx]->iface[0] == '\0' &&
2400 !hostapd_drv_none(iface->bss[bss_idx])) {
2401 wpa_printf(MSG_ERROR, "Interface name not specified in %s",
2402 config_fname);
2403 if (new_iface)
2404 hostapd_interface_deinit_free(new_iface);
2405 return NULL;
2406 }
2407
2408 return iface;
2409}
2410
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002411
2412void hostapd_interface_deinit_free(struct hostapd_iface *iface)
2413{
2414 const struct wpa_driver_ops *driver;
2415 void *drv_priv;
Dmitry Shmidt54605472013-11-08 11:10:19 -08002416
2417 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002418 if (iface == NULL)
2419 return;
Dmitry Shmidt54605472013-11-08 11:10:19 -08002420 wpa_printf(MSG_DEBUG, "%s: num_bss=%u conf->num_bss=%u",
2421 __func__, (unsigned int) iface->num_bss,
2422 (unsigned int) iface->conf->num_bss);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002423 driver = iface->bss[0]->driver;
2424 drv_priv = iface->bss[0]->drv_priv;
2425 hostapd_interface_deinit(iface);
Dmitry Shmidt54605472013-11-08 11:10:19 -08002426 wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
2427 __func__, driver, drv_priv);
Dmitry Shmidt71757432014-06-02 13:50:35 -07002428 if (driver && driver->hapd_deinit && drv_priv) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002429 driver->hapd_deinit(drv_priv);
Dmitry Shmidt71757432014-06-02 13:50:35 -07002430 iface->bss[0]->drv_priv = NULL;
2431 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002432 hostapd_interface_free(iface);
2433}
2434
2435
Dmitry Shmidt15907092014-03-25 10:42:57 -07002436static void hostapd_deinit_driver(const struct wpa_driver_ops *driver,
2437 void *drv_priv,
2438 struct hostapd_iface *hapd_iface)
2439{
2440 size_t j;
2441
2442 wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
2443 __func__, driver, drv_priv);
2444 if (driver && driver->hapd_deinit && drv_priv) {
2445 driver->hapd_deinit(drv_priv);
2446 for (j = 0; j < hapd_iface->num_bss; j++) {
2447 wpa_printf(MSG_DEBUG, "%s:bss[%d]->drv_priv=%p",
2448 __func__, (int) j,
2449 hapd_iface->bss[j]->drv_priv);
2450 if (hapd_iface->bss[j]->drv_priv == drv_priv)
2451 hapd_iface->bss[j]->drv_priv = NULL;
2452 }
2453 }
2454}
2455
2456
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002457int hostapd_enable_iface(struct hostapd_iface *hapd_iface)
2458{
Dmitry Shmidt71757432014-06-02 13:50:35 -07002459 size_t j;
2460
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002461 if (hapd_iface->bss[0]->drv_priv != NULL) {
2462 wpa_printf(MSG_ERROR, "Interface %s already enabled",
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002463 hapd_iface->conf->bss[0]->iface);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002464 return -1;
2465 }
2466
2467 wpa_printf(MSG_DEBUG, "Enable interface %s",
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002468 hapd_iface->conf->bss[0]->iface);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002469
Dmitry Shmidt71757432014-06-02 13:50:35 -07002470 for (j = 0; j < hapd_iface->num_bss; j++)
2471 hostapd_set_security_params(hapd_iface->conf->bss[j], 1);
Dmitry Shmidt344abd32014-01-14 13:17:00 -08002472 if (hostapd_config_check(hapd_iface->conf, 1) < 0) {
2473 wpa_printf(MSG_INFO, "Invalid configuration - cannot enable");
2474 return -1;
2475 }
2476
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002477 if (hapd_iface->interfaces == NULL ||
2478 hapd_iface->interfaces->driver_init == NULL ||
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002479 hapd_iface->interfaces->driver_init(hapd_iface))
2480 return -1;
2481
2482 if (hostapd_setup_interface(hapd_iface)) {
Dmitry Shmidt15907092014-03-25 10:42:57 -07002483 hostapd_deinit_driver(hapd_iface->bss[0]->driver,
2484 hapd_iface->bss[0]->drv_priv,
2485 hapd_iface);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002486 return -1;
2487 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002488
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002489 return 0;
2490}
2491
2492
2493int hostapd_reload_iface(struct hostapd_iface *hapd_iface)
2494{
2495 size_t j;
2496
2497 wpa_printf(MSG_DEBUG, "Reload interface %s",
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002498 hapd_iface->conf->bss[0]->iface);
2499 for (j = 0; j < hapd_iface->num_bss; j++)
Dmitry Shmidt71757432014-06-02 13:50:35 -07002500 hostapd_set_security_params(hapd_iface->conf->bss[j], 1);
Dmitry Shmidt344abd32014-01-14 13:17:00 -08002501 if (hostapd_config_check(hapd_iface->conf, 1) < 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002502 wpa_printf(MSG_ERROR, "Updated configuration is invalid");
2503 return -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002504 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002505 hostapd_clear_old(hapd_iface);
2506 for (j = 0; j < hapd_iface->num_bss; j++)
2507 hostapd_reload_bss(hapd_iface->bss[j]);
2508
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002509 return 0;
2510}
2511
2512
2513int hostapd_disable_iface(struct hostapd_iface *hapd_iface)
2514{
2515 size_t j;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002516 const struct wpa_driver_ops *driver;
2517 void *drv_priv;
2518
2519 if (hapd_iface == NULL)
2520 return -1;
Dmitry Shmidt71757432014-06-02 13:50:35 -07002521
2522 if (hapd_iface->bss[0]->drv_priv == NULL) {
2523 wpa_printf(MSG_INFO, "Interface %s already disabled",
2524 hapd_iface->conf->bss[0]->iface);
2525 return -1;
2526 }
2527
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002528 wpa_msg(hapd_iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002529 driver = hapd_iface->bss[0]->driver;
2530 drv_priv = hapd_iface->bss[0]->drv_priv;
2531
Dmitry Shmidta38abf92014-03-06 13:38:44 -08002532 hapd_iface->driver_ap_teardown =
2533 !!(hapd_iface->drv_flags &
2534 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
2535
2536 /* same as hostapd_interface_deinit without deinitializing ctrl-iface */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002537 for (j = 0; j < hapd_iface->num_bss; j++) {
2538 struct hostapd_data *hapd = hapd_iface->bss[j];
Dmitry Shmidt71757432014-06-02 13:50:35 -07002539 hostapd_bss_deinit_no_free(hapd);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002540 hostapd_free_hapd_data(hapd);
2541 }
2542
Dmitry Shmidt15907092014-03-25 10:42:57 -07002543 hostapd_deinit_driver(driver, drv_priv, hapd_iface);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002544
2545 /* From hostapd_cleanup_iface: These were initialized in
2546 * hostapd_setup_interface and hostapd_setup_interface_complete
2547 */
2548 hostapd_cleanup_iface_partial(hapd_iface);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002549
Dmitry Shmidt56052862013-10-04 10:23:25 -07002550 wpa_printf(MSG_DEBUG, "Interface %s disabled",
2551 hapd_iface->bss[0]->conf->iface);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002552 hostapd_set_state(hapd_iface, HAPD_IFACE_DISABLED);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002553 return 0;
2554}
2555
2556
2557static struct hostapd_iface *
2558hostapd_iface_alloc(struct hapd_interfaces *interfaces)
2559{
2560 struct hostapd_iface **iface, *hapd_iface;
2561
2562 iface = os_realloc_array(interfaces->iface, interfaces->count + 1,
2563 sizeof(struct hostapd_iface *));
2564 if (iface == NULL)
2565 return NULL;
2566 interfaces->iface = iface;
2567 hapd_iface = interfaces->iface[interfaces->count] =
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07002568 hostapd_alloc_iface();
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002569 if (hapd_iface == NULL) {
2570 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for "
2571 "the interface", __func__);
2572 return NULL;
2573 }
2574 interfaces->count++;
2575 hapd_iface->interfaces = interfaces;
2576
2577 return hapd_iface;
2578}
2579
2580
2581static struct hostapd_config *
2582hostapd_config_alloc(struct hapd_interfaces *interfaces, const char *ifname,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002583 const char *ctrl_iface, const char *driver)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002584{
2585 struct hostapd_bss_config *bss;
2586 struct hostapd_config *conf;
2587
2588 /* Allocates memory for bss and conf */
2589 conf = hostapd_config_defaults();
2590 if (conf == NULL) {
2591 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for "
2592 "configuration", __func__);
2593 return NULL;
2594 }
2595
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002596 if (driver) {
2597 int j;
2598
2599 for (j = 0; wpa_drivers[j]; j++) {
2600 if (os_strcmp(driver, wpa_drivers[j]->name) == 0) {
2601 conf->driver = wpa_drivers[j];
2602 goto skip;
2603 }
2604 }
2605
2606 wpa_printf(MSG_ERROR,
2607 "Invalid/unknown driver '%s' - registering the default driver",
2608 driver);
2609 }
2610
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002611 conf->driver = wpa_drivers[0];
2612 if (conf->driver == NULL) {
2613 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
2614 hostapd_config_free(conf);
2615 return NULL;
2616 }
2617
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002618skip:
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002619 bss = conf->last_bss = conf->bss[0];
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002620
2621 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
2622 bss->ctrl_interface = os_strdup(ctrl_iface);
2623 if (bss->ctrl_interface == NULL) {
2624 hostapd_config_free(conf);
2625 return NULL;
2626 }
2627
2628 /* Reading configuration file skipped, will be done in SET!
2629 * From reading the configuration till the end has to be done in
2630 * SET
2631 */
2632 return conf;
2633}
2634
2635
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002636static int hostapd_data_alloc(struct hostapd_iface *hapd_iface,
2637 struct hostapd_config *conf)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002638{
2639 size_t i;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002640 struct hostapd_data *hapd;
2641
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002642 hapd_iface->bss = os_calloc(conf->num_bss,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002643 sizeof(struct hostapd_data *));
2644 if (hapd_iface->bss == NULL)
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002645 return -1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002646
2647 for (i = 0; i < conf->num_bss; i++) {
2648 hapd = hapd_iface->bss[i] =
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002649 hostapd_alloc_bss_data(hapd_iface, conf, conf->bss[i]);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002650 if (hapd == NULL) {
2651 while (i > 0) {
2652 i--;
2653 os_free(hapd_iface->bss[i]);
2654 hapd_iface->bss[i] = NULL;
2655 }
2656 os_free(hapd_iface->bss);
2657 hapd_iface->bss = NULL;
2658 return -1;
2659 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002660 hapd->msg_ctx = hapd;
2661 }
2662
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002663 hapd_iface->conf = conf;
2664 hapd_iface->num_bss = conf->num_bss;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002665
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002666 return 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002667}
2668
2669
2670int hostapd_add_iface(struct hapd_interfaces *interfaces, char *buf)
2671{
2672 struct hostapd_config *conf = NULL;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002673 struct hostapd_iface *hapd_iface = NULL, *new_iface = NULL;
2674 struct hostapd_data *hapd;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002675 char *ptr;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002676 size_t i, j;
2677 const char *conf_file = NULL, *phy_name = NULL;
2678
2679 if (os_strncmp(buf, "bss_config=", 11) == 0) {
2680 char *pos;
2681 phy_name = buf + 11;
2682 pos = os_strchr(phy_name, ':');
2683 if (!pos)
2684 return -1;
2685 *pos++ = '\0';
2686 conf_file = pos;
2687 if (!os_strlen(conf_file))
2688 return -1;
2689
2690 hapd_iface = hostapd_interface_init_bss(interfaces, phy_name,
2691 conf_file, 0);
2692 if (!hapd_iface)
2693 return -1;
2694 for (j = 0; j < interfaces->count; j++) {
2695 if (interfaces->iface[j] == hapd_iface)
2696 break;
2697 }
2698 if (j == interfaces->count) {
2699 struct hostapd_iface **tmp;
2700 tmp = os_realloc_array(interfaces->iface,
2701 interfaces->count + 1,
2702 sizeof(struct hostapd_iface *));
2703 if (!tmp) {
2704 hostapd_interface_deinit_free(hapd_iface);
2705 return -1;
2706 }
2707 interfaces->iface = tmp;
2708 interfaces->iface[interfaces->count++] = hapd_iface;
2709 new_iface = hapd_iface;
2710 }
2711
2712 if (new_iface) {
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002713 if (interfaces->driver_init(hapd_iface))
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002714 goto fail;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002715
2716 if (hostapd_setup_interface(hapd_iface)) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002717 hostapd_deinit_driver(
2718 hapd_iface->bss[0]->driver,
2719 hapd_iface->bss[0]->drv_priv,
2720 hapd_iface);
2721 goto fail;
2722 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002723 } else {
2724 /* Assign new BSS with bss[0]'s driver info */
2725 hapd = hapd_iface->bss[hapd_iface->num_bss - 1];
2726 hapd->driver = hapd_iface->bss[0]->driver;
2727 hapd->drv_priv = hapd_iface->bss[0]->drv_priv;
2728 os_memcpy(hapd->own_addr, hapd_iface->bss[0]->own_addr,
2729 ETH_ALEN);
2730
2731 if (start_ctrl_iface_bss(hapd) < 0 ||
Dmitry Shmidt54605472013-11-08 11:10:19 -08002732 (hapd_iface->state == HAPD_IFACE_ENABLED &&
2733 hostapd_setup_bss(hapd, -1))) {
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002734 hostapd_cleanup(hapd);
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002735 hapd_iface->bss[hapd_iface->num_bss - 1] = NULL;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002736 hapd_iface->conf->num_bss--;
2737 hapd_iface->num_bss--;
Dmitry Shmidt54605472013-11-08 11:10:19 -08002738 wpa_printf(MSG_DEBUG, "%s: free hapd %p %s",
2739 __func__, hapd, hapd->conf->iface);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002740 hostapd_config_free_bss(hapd->conf);
2741 hapd->conf = NULL;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002742 os_free(hapd);
2743 return -1;
2744 }
2745 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002746 hostapd_owe_update_trans(hapd_iface);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002747 return 0;
2748 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002749
2750 ptr = os_strchr(buf, ' ');
2751 if (ptr == NULL)
2752 return -1;
2753 *ptr++ = '\0';
2754
Dmitry Shmidt56052862013-10-04 10:23:25 -07002755 if (os_strncmp(ptr, "config=", 7) == 0)
2756 conf_file = ptr + 7;
2757
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002758 for (i = 0; i < interfaces->count; i++) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002759 if (!os_strcmp(interfaces->iface[i]->conf->bss[0]->iface,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002760 buf)) {
2761 wpa_printf(MSG_INFO, "Cannot add interface - it "
2762 "already exists");
2763 return -1;
2764 }
2765 }
2766
2767 hapd_iface = hostapd_iface_alloc(interfaces);
2768 if (hapd_iface == NULL) {
2769 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
2770 "for interface", __func__);
2771 goto fail;
2772 }
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002773 new_iface = hapd_iface;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002774
Dmitry Shmidt56052862013-10-04 10:23:25 -07002775 if (conf_file && interfaces->config_read_cb) {
2776 conf = interfaces->config_read_cb(conf_file);
2777 if (conf && conf->bss)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002778 os_strlcpy(conf->bss[0]->iface, buf,
2779 sizeof(conf->bss[0]->iface));
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002780 } else {
2781 char *driver = os_strchr(ptr, ' ');
2782
2783 if (driver)
2784 *driver++ = '\0';
2785 conf = hostapd_config_alloc(interfaces, buf, ptr, driver);
2786 }
2787
Dmitry Shmidt56052862013-10-04 10:23:25 -07002788 if (conf == NULL || conf->bss == NULL) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002789 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
2790 "for configuration", __func__);
2791 goto fail;
2792 }
2793
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002794 if (hostapd_data_alloc(hapd_iface, conf) < 0) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002795 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
2796 "for hostapd", __func__);
2797 goto fail;
2798 }
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002799 conf = NULL;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002800
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002801 if (start_ctrl_iface(hapd_iface) < 0)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002802 goto fail;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002803
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002804 wpa_printf(MSG_INFO, "Add interface '%s'",
2805 hapd_iface->conf->bss[0]->iface);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002806
2807 return 0;
2808
2809fail:
2810 if (conf)
2811 hostapd_config_free(conf);
2812 if (hapd_iface) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002813 if (hapd_iface->bss) {
Dmitry Shmidt54605472013-11-08 11:10:19 -08002814 for (i = 0; i < hapd_iface->num_bss; i++) {
2815 hapd = hapd_iface->bss[i];
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002816 if (!hapd)
2817 continue;
2818 if (hapd_iface->interfaces &&
Dmitry Shmidt54605472013-11-08 11:10:19 -08002819 hapd_iface->interfaces->ctrl_iface_deinit)
2820 hapd_iface->interfaces->
2821 ctrl_iface_deinit(hapd);
2822 wpa_printf(MSG_DEBUG, "%s: free hapd %p (%s)",
2823 __func__, hapd_iface->bss[i],
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002824 hapd->conf->iface);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002825 hostapd_cleanup(hapd);
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08002826 os_free(hapd);
2827 hapd_iface->bss[i] = NULL;
Dmitry Shmidt54605472013-11-08 11:10:19 -08002828 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002829 os_free(hapd_iface->bss);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002830 hapd_iface->bss = NULL;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002831 }
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002832 if (new_iface) {
2833 interfaces->count--;
2834 interfaces->iface[interfaces->count] = NULL;
2835 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002836 hostapd_cleanup_iface(hapd_iface);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002837 }
2838 return -1;
2839}
2840
2841
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002842static int hostapd_remove_bss(struct hostapd_iface *iface, unsigned int idx)
2843{
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002844 size_t i;
2845
Dmitry Shmidt54605472013-11-08 11:10:19 -08002846 wpa_printf(MSG_INFO, "Remove BSS '%s'", iface->conf->bss[idx]->iface);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002847
Dmitry Shmidt54605472013-11-08 11:10:19 -08002848 /* Remove hostapd_data only if it has already been initialized */
2849 if (idx < iface->num_bss) {
2850 struct hostapd_data *hapd = iface->bss[idx];
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002851
Dmitry Shmidt54605472013-11-08 11:10:19 -08002852 hostapd_bss_deinit(hapd);
2853 wpa_printf(MSG_DEBUG, "%s: free hapd %p (%s)",
2854 __func__, hapd, hapd->conf->iface);
2855 hostapd_config_free_bss(hapd->conf);
Dmitry Shmidtff787d52015-01-12 13:01:47 -08002856 hapd->conf = NULL;
Dmitry Shmidt54605472013-11-08 11:10:19 -08002857 os_free(hapd);
2858
2859 iface->num_bss--;
2860
2861 for (i = idx; i < iface->num_bss; i++)
2862 iface->bss[i] = iface->bss[i + 1];
2863 } else {
2864 hostapd_config_free_bss(iface->conf->bss[idx]);
2865 iface->conf->bss[idx] = NULL;
2866 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002867
2868 iface->conf->num_bss--;
Dmitry Shmidt54605472013-11-08 11:10:19 -08002869 for (i = idx; i < iface->conf->num_bss; i++)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002870 iface->conf->bss[i] = iface->conf->bss[i + 1];
2871
2872 return 0;
2873}
2874
2875
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002876int hostapd_remove_iface(struct hapd_interfaces *interfaces, char *buf)
2877{
2878 struct hostapd_iface *hapd_iface;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002879 size_t i, j, k = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002880
2881 for (i = 0; i < interfaces->count; i++) {
2882 hapd_iface = interfaces->iface[i];
2883 if (hapd_iface == NULL)
2884 return -1;
Dmitry Shmidt54605472013-11-08 11:10:19 -08002885 if (!os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002886 wpa_printf(MSG_INFO, "Remove interface '%s'", buf);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08002887 hapd_iface->driver_ap_teardown =
2888 !!(hapd_iface->drv_flags &
2889 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
2890
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002891 hostapd_interface_deinit_free(hapd_iface);
2892 k = i;
2893 while (k < (interfaces->count - 1)) {
2894 interfaces->iface[k] =
2895 interfaces->iface[k + 1];
2896 k++;
2897 }
2898 interfaces->count--;
2899 return 0;
2900 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002901
2902 for (j = 0; j < hapd_iface->conf->num_bss; j++) {
Dmitry Shmidta38abf92014-03-06 13:38:44 -08002903 if (!os_strcmp(hapd_iface->conf->bss[j]->iface, buf)) {
2904 hapd_iface->driver_ap_teardown =
2905 !(hapd_iface->drv_flags &
2906 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002907 return hostapd_remove_bss(hapd_iface, j);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08002908 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002909 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002910 }
2911 return -1;
2912}
2913
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07002914
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002915/**
2916 * hostapd_new_assoc_sta - Notify that a new station associated with the AP
2917 * @hapd: Pointer to BSS data
2918 * @sta: Pointer to the associated STA data
2919 * @reassoc: 1 to indicate this was a re-association; 0 = first association
2920 *
2921 * This function will be called whenever a station associates with the AP. It
2922 * can be called from ieee802_11.c for drivers that export MLME to hostapd and
2923 * from drv_callbacks.c based on driver events for drivers that take care of
2924 * management frames (IEEE 802.11 authentication and association) internally.
2925 */
2926void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
2927 int reassoc)
2928{
2929 if (hapd->tkip_countermeasures) {
2930 hostapd_drv_sta_deauth(hapd, sta->addr,
2931 WLAN_REASON_MICHAEL_MIC_FAILURE);
2932 return;
2933 }
2934
2935 hostapd_prune_associations(hapd, sta->addr);
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08002936 ap_sta_clear_disconnect_timeouts(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002937
2938 /* IEEE 802.11F (IAPP) */
2939 if (hapd->conf->ieee802_11f)
2940 iapp_new_station(hapd->iapp, sta);
2941
2942#ifdef CONFIG_P2P
2943 if (sta->p2p_ie == NULL && !sta->no_p2p_set) {
2944 sta->no_p2p_set = 1;
2945 hapd->num_sta_no_p2p++;
2946 if (hapd->num_sta_no_p2p == 1)
2947 hostapd_p2p_non_p2p_sta_connected(hapd);
2948 }
2949#endif /* CONFIG_P2P */
2950
2951 /* Start accounting here, if IEEE 802.1X and WPA are not used.
2952 * IEEE 802.1X/WPA code will start accounting after the station has
2953 * been authorized. */
Dmitry Shmidt2ac5f602014-03-07 10:08:21 -08002954 if (!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) {
2955 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08002956 os_get_reltime(&sta->connected_time);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002957 accounting_sta_start(hapd, sta);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08002958 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002959
2960 /* Start IEEE 802.1X authentication process for new stations */
2961 ieee802_1x_new_station(hapd, sta);
2962 if (reassoc) {
2963 if (sta->auth_alg != WLAN_AUTH_FT &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07002964 sta->auth_alg != WLAN_AUTH_FILS_SK &&
2965 sta->auth_alg != WLAN_AUTH_FILS_SK_PFS &&
2966 sta->auth_alg != WLAN_AUTH_FILS_PK &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002967 !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)))
2968 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH);
2969 } else
2970 wpa_auth_sta_associated(hapd->wpa_auth, sta->wpa_sm);
Dmitry Shmidt04949592012-07-19 12:16:46 -07002971
Dmitry Shmidtabb90a32016-12-05 15:34:39 -08002972 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_WIRED) {
2973 if (eloop_cancel_timeout(ap_handle_timer, hapd, sta) > 0) {
2974 wpa_printf(MSG_DEBUG,
2975 "%s: %s: canceled wired ap_handle_timer timeout for "
2976 MACSTR,
2977 hapd->conf->iface, __func__,
2978 MAC2STR(sta->addr));
2979 }
2980 } else if (!(hapd->iface->drv_flags &
2981 WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) {
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08002982 wpa_printf(MSG_DEBUG,
2983 "%s: %s: reschedule ap_handle_timer timeout for "
2984 MACSTR " (%d seconds - ap_max_inactivity)",
2985 hapd->conf->iface, __func__, MAC2STR(sta->addr),
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08002986 hapd->conf->ap_max_inactivity);
2987 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
2988 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
2989 ap_handle_timer, hapd, sta);
2990 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002991}
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002992
2993
2994const char * hostapd_state_text(enum hostapd_iface_state s)
2995{
2996 switch (s) {
2997 case HAPD_IFACE_UNINITIALIZED:
2998 return "UNINITIALIZED";
2999 case HAPD_IFACE_DISABLED:
3000 return "DISABLED";
3001 case HAPD_IFACE_COUNTRY_UPDATE:
3002 return "COUNTRY_UPDATE";
3003 case HAPD_IFACE_ACS:
3004 return "ACS";
3005 case HAPD_IFACE_HT_SCAN:
3006 return "HT_SCAN";
3007 case HAPD_IFACE_DFS:
3008 return "DFS";
3009 case HAPD_IFACE_ENABLED:
3010 return "ENABLED";
3011 }
3012
3013 return "UNKNOWN";
3014}
3015
3016
3017void hostapd_set_state(struct hostapd_iface *iface, enum hostapd_iface_state s)
3018{
3019 wpa_printf(MSG_INFO, "%s: interface state %s->%s",
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07003020 iface->conf ? iface->conf->bss[0]->iface : "N/A",
3021 hostapd_state_text(iface->state), hostapd_state_text(s));
Dmitry Shmidtcce06662013-11-04 18:44:24 -08003022 iface->state = s;
3023}
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003024
3025
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003026int hostapd_csa_in_progress(struct hostapd_iface *iface)
3027{
3028 unsigned int i;
3029
3030 for (i = 0; i < iface->num_bss; i++)
3031 if (iface->bss[i]->csa_in_progress)
3032 return 1;
3033 return 0;
3034}
3035
3036
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003037#ifdef NEED_AP_MLME
3038
3039static void free_beacon_data(struct beacon_data *beacon)
3040{
3041 os_free(beacon->head);
3042 beacon->head = NULL;
3043 os_free(beacon->tail);
3044 beacon->tail = NULL;
3045 os_free(beacon->probe_resp);
3046 beacon->probe_resp = NULL;
3047 os_free(beacon->beacon_ies);
3048 beacon->beacon_ies = NULL;
3049 os_free(beacon->proberesp_ies);
3050 beacon->proberesp_ies = NULL;
3051 os_free(beacon->assocresp_ies);
3052 beacon->assocresp_ies = NULL;
3053}
3054
3055
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07003056static int hostapd_build_beacon_data(struct hostapd_data *hapd,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003057 struct beacon_data *beacon)
3058{
3059 struct wpabuf *beacon_extra, *proberesp_extra, *assocresp_extra;
3060 struct wpa_driver_ap_params params;
3061 int ret;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003062
Dmitry Shmidt01904cf2013-12-05 11:08:35 -08003063 os_memset(beacon, 0, sizeof(*beacon));
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003064 ret = ieee802_11_build_ap_params(hapd, &params);
3065 if (ret < 0)
3066 return ret;
3067
3068 ret = hostapd_build_ap_extra_ies(hapd, &beacon_extra,
3069 &proberesp_extra,
3070 &assocresp_extra);
3071 if (ret)
3072 goto free_ap_params;
3073
3074 ret = -1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003075 beacon->head = os_memdup(params.head, params.head_len);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003076 if (!beacon->head)
3077 goto free_ap_extra_ies;
3078
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003079 beacon->head_len = params.head_len;
3080
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003081 beacon->tail = os_memdup(params.tail, params.tail_len);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003082 if (!beacon->tail)
3083 goto free_beacon;
3084
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003085 beacon->tail_len = params.tail_len;
3086
3087 if (params.proberesp != NULL) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003088 beacon->probe_resp = os_memdup(params.proberesp,
3089 params.proberesp_len);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003090 if (!beacon->probe_resp)
3091 goto free_beacon;
3092
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003093 beacon->probe_resp_len = params.proberesp_len;
3094 }
3095
3096 /* copy the extra ies */
3097 if (beacon_extra) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003098 beacon->beacon_ies = os_memdup(beacon_extra->buf,
3099 wpabuf_len(beacon_extra));
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003100 if (!beacon->beacon_ies)
3101 goto free_beacon;
3102
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003103 beacon->beacon_ies_len = wpabuf_len(beacon_extra);
3104 }
3105
3106 if (proberesp_extra) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003107 beacon->proberesp_ies = os_memdup(proberesp_extra->buf,
3108 wpabuf_len(proberesp_extra));
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003109 if (!beacon->proberesp_ies)
3110 goto free_beacon;
3111
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003112 beacon->proberesp_ies_len = wpabuf_len(proberesp_extra);
3113 }
3114
3115 if (assocresp_extra) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07003116 beacon->assocresp_ies = os_memdup(assocresp_extra->buf,
3117 wpabuf_len(assocresp_extra));
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003118 if (!beacon->assocresp_ies)
3119 goto free_beacon;
3120
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003121 beacon->assocresp_ies_len = wpabuf_len(assocresp_extra);
3122 }
3123
3124 ret = 0;
3125free_beacon:
3126 /* if the function fails, the caller should not free beacon data */
3127 if (ret)
3128 free_beacon_data(beacon);
3129
3130free_ap_extra_ies:
3131 hostapd_free_ap_extra_ies(hapd, beacon_extra, proberesp_extra,
3132 assocresp_extra);
3133free_ap_params:
3134 ieee802_11_free_ap_params(&params);
3135 return ret;
3136}
3137
3138
3139/*
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003140 * TODO: This flow currently supports only changing channel and width within
3141 * the same hw_mode. Any other changes to MAC parameters or provided settings
3142 * are not supported.
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003143 */
3144static int hostapd_change_config_freq(struct hostapd_data *hapd,
3145 struct hostapd_config *conf,
3146 struct hostapd_freq_params *params,
3147 struct hostapd_freq_params *old_params)
3148{
3149 int channel;
3150
3151 if (!params->channel) {
3152 /* check if the new channel is supported by hw */
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07003153 params->channel = hostapd_hw_get_channel(hapd, params->freq);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003154 }
3155
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07003156 channel = params->channel;
3157 if (!channel)
3158 return -1;
3159
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003160 /* if a pointer to old_params is provided we save previous state */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003161 if (old_params &&
3162 hostapd_set_freq_params(old_params, conf->hw_mode,
3163 hostapd_hw_get_freq(hapd, conf->channel),
3164 conf->channel, conf->ieee80211n,
3165 conf->ieee80211ac,
3166 conf->secondary_channel,
3167 conf->vht_oper_chwidth,
3168 conf->vht_oper_centr_freq_seg0_idx,
3169 conf->vht_oper_centr_freq_seg1_idx,
3170 conf->vht_capab))
3171 return -1;
3172
3173 switch (params->bandwidth) {
3174 case 0:
3175 case 20:
3176 case 40:
3177 conf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT;
3178 break;
3179 case 80:
3180 if (params->center_freq2)
3181 conf->vht_oper_chwidth = VHT_CHANWIDTH_80P80MHZ;
3182 else
3183 conf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ;
3184 break;
3185 case 160:
3186 conf->vht_oper_chwidth = VHT_CHANWIDTH_160MHZ;
3187 break;
3188 default:
3189 return -1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003190 }
3191
3192 conf->channel = channel;
3193 conf->ieee80211n = params->ht_enabled;
3194 conf->secondary_channel = params->sec_channel_offset;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003195 ieee80211_freq_to_chan(params->center_freq1,
3196 &conf->vht_oper_centr_freq_seg0_idx);
3197 ieee80211_freq_to_chan(params->center_freq2,
3198 &conf->vht_oper_centr_freq_seg1_idx);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003199
3200 /* TODO: maybe call here hostapd_config_check here? */
3201
3202 return 0;
3203}
3204
3205
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07003206static int hostapd_fill_csa_settings(struct hostapd_data *hapd,
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003207 struct csa_settings *settings)
3208{
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07003209 struct hostapd_iface *iface = hapd->iface;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003210 struct hostapd_freq_params old_freq;
3211 int ret;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003212 u8 chan, vht_bandwidth;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003213
3214 os_memset(&old_freq, 0, sizeof(old_freq));
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07003215 if (!iface || !iface->freq || hapd->csa_in_progress)
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003216 return -1;
3217
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003218 switch (settings->freq_params.bandwidth) {
3219 case 80:
3220 if (settings->freq_params.center_freq2)
3221 vht_bandwidth = VHT_CHANWIDTH_80P80MHZ;
3222 else
3223 vht_bandwidth = VHT_CHANWIDTH_80MHZ;
3224 break;
3225 case 160:
3226 vht_bandwidth = VHT_CHANWIDTH_160MHZ;
3227 break;
3228 default:
3229 vht_bandwidth = VHT_CHANWIDTH_USE_HT;
3230 break;
3231 }
3232
3233 if (ieee80211_freq_to_channel_ext(
3234 settings->freq_params.freq,
3235 settings->freq_params.sec_channel_offset,
3236 vht_bandwidth,
3237 &hapd->iface->cs_oper_class,
3238 &chan) == NUM_HOSTAPD_MODES) {
3239 wpa_printf(MSG_DEBUG,
3240 "invalid frequency for channel switch (freq=%d, sec_channel_offset=%d, vht_enabled=%d)",
3241 settings->freq_params.freq,
3242 settings->freq_params.sec_channel_offset,
3243 settings->freq_params.vht_enabled);
3244 return -1;
3245 }
3246
3247 settings->freq_params.channel = chan;
3248
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003249 ret = hostapd_change_config_freq(iface->bss[0], iface->conf,
3250 &settings->freq_params,
3251 &old_freq);
3252 if (ret)
3253 return ret;
3254
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07003255 ret = hostapd_build_beacon_data(hapd, &settings->beacon_after);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003256
3257 /* change back the configuration */
3258 hostapd_change_config_freq(iface->bss[0], iface->conf,
3259 &old_freq, NULL);
3260
3261 if (ret)
3262 return ret;
3263
3264 /* set channel switch parameters for csa ie */
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07003265 hapd->cs_freq_params = settings->freq_params;
3266 hapd->cs_count = settings->cs_count;
3267 hapd->cs_block_tx = settings->block_tx;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003268
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07003269 ret = hostapd_build_beacon_data(hapd, &settings->beacon_csa);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003270 if (ret) {
3271 free_beacon_data(&settings->beacon_after);
3272 return ret;
3273 }
3274
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003275 settings->counter_offset_beacon[0] = hapd->cs_c_off_beacon;
3276 settings->counter_offset_presp[0] = hapd->cs_c_off_proberesp;
3277 settings->counter_offset_beacon[1] = hapd->cs_c_off_ecsa_beacon;
3278 settings->counter_offset_presp[1] = hapd->cs_c_off_ecsa_proberesp;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003279
3280 return 0;
3281}
3282
3283
3284void hostapd_cleanup_cs_params(struct hostapd_data *hapd)
3285{
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07003286 os_memset(&hapd->cs_freq_params, 0, sizeof(hapd->cs_freq_params));
3287 hapd->cs_count = 0;
3288 hapd->cs_block_tx = 0;
3289 hapd->cs_c_off_beacon = 0;
3290 hapd->cs_c_off_proberesp = 0;
3291 hapd->csa_in_progress = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003292 hapd->cs_c_off_ecsa_beacon = 0;
3293 hapd->cs_c_off_ecsa_proberesp = 0;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003294}
3295
3296
3297int hostapd_switch_channel(struct hostapd_data *hapd,
3298 struct csa_settings *settings)
3299{
3300 int ret;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08003301
3302 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA)) {
3303 wpa_printf(MSG_INFO, "CSA is not supported");
3304 return -1;
3305 }
3306
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07003307 ret = hostapd_fill_csa_settings(hapd, settings);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003308 if (ret)
3309 return ret;
3310
3311 ret = hostapd_drv_switch_channel(hapd, settings);
3312 free_beacon_data(&settings->beacon_csa);
3313 free_beacon_data(&settings->beacon_after);
3314
3315 if (ret) {
3316 /* if we failed, clean cs parameters */
3317 hostapd_cleanup_cs_params(hapd);
3318 return ret;
3319 }
3320
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07003321 hapd->csa_in_progress = 1;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08003322 return 0;
3323}
3324
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07003325
3326void
3327hostapd_switch_channel_fallback(struct hostapd_iface *iface,
3328 const struct hostapd_freq_params *freq_params)
3329{
3330 int vht_seg0_idx = 0, vht_seg1_idx = 0, vht_bw = VHT_CHANWIDTH_USE_HT;
3331 unsigned int i;
3332
3333 wpa_printf(MSG_DEBUG, "Restarting all CSA-related BSSes");
3334
3335 if (freq_params->center_freq1)
3336 vht_seg0_idx = 36 + (freq_params->center_freq1 - 5180) / 5;
3337 if (freq_params->center_freq2)
3338 vht_seg1_idx = 36 + (freq_params->center_freq2 - 5180) / 5;
3339
3340 switch (freq_params->bandwidth) {
3341 case 0:
3342 case 20:
3343 case 40:
3344 vht_bw = VHT_CHANWIDTH_USE_HT;
3345 break;
3346 case 80:
3347 if (freq_params->center_freq2)
3348 vht_bw = VHT_CHANWIDTH_80P80MHZ;
3349 else
3350 vht_bw = VHT_CHANWIDTH_80MHZ;
3351 break;
3352 case 160:
3353 vht_bw = VHT_CHANWIDTH_160MHZ;
3354 break;
3355 default:
3356 wpa_printf(MSG_WARNING, "Unknown CSA bandwidth: %d",
3357 freq_params->bandwidth);
3358 break;
3359 }
3360
3361 iface->freq = freq_params->freq;
3362 iface->conf->channel = freq_params->channel;
3363 iface->conf->secondary_channel = freq_params->sec_channel_offset;
3364 iface->conf->vht_oper_centr_freq_seg0_idx = vht_seg0_idx;
3365 iface->conf->vht_oper_centr_freq_seg1_idx = vht_seg1_idx;
3366 iface->conf->vht_oper_chwidth = vht_bw;
3367 iface->conf->ieee80211n = freq_params->ht_enabled;
3368 iface->conf->ieee80211ac = freq_params->vht_enabled;
3369
3370 /*
3371 * cs_params must not be cleared earlier because the freq_params
3372 * argument may actually point to one of these.
3373 */
3374 for (i = 0; i < iface->num_bss; i++)
3375 hostapd_cleanup_cs_params(iface->bss[i]);
3376
3377 hostapd_disable_iface(iface);
3378 hostapd_enable_iface(iface);
3379}
3380
Dmitry Shmidte4663042016-04-04 10:07:49 -07003381#endif /* NEED_AP_MLME */
3382
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003383
3384struct hostapd_data * hostapd_get_iface(struct hapd_interfaces *interfaces,
3385 const char *ifname)
3386{
3387 size_t i, j;
3388
3389 for (i = 0; i < interfaces->count; i++) {
3390 struct hostapd_iface *iface = interfaces->iface[i];
3391
3392 for (j = 0; j < iface->num_bss; j++) {
3393 struct hostapd_data *hapd = iface->bss[j];
3394
3395 if (os_strcmp(ifname, hapd->conf->iface) == 0)
3396 return hapd;
3397 }
3398 }
3399
3400 return NULL;
3401}
3402
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08003403
3404void hostapd_periodic_iface(struct hostapd_iface *iface)
3405{
3406 size_t i;
3407
3408 ap_list_timer(iface);
3409
3410 for (i = 0; i < iface->num_bss; i++) {
3411 struct hostapd_data *hapd = iface->bss[i];
3412
3413 if (!hapd->started)
3414 continue;
3415
3416#ifndef CONFIG_NO_RADIUS
3417 hostapd_acl_expire(hapd);
3418#endif /* CONFIG_NO_RADIUS */
3419 }
3420}