]> git.ipfire.org Git - thirdparty/hostap.git/blob - src/ap/hostapd.c
DPP: Integration for hostapd
[thirdparty/hostap.git] / src / ap / hostapd.c
1 /*
2 * hostapd / Initialization and configuration
3 * Copyright (c) 2002-2014, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9 #include "utils/includes.h"
10
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "common/ieee802_11_defs.h"
14 #include "common/wpa_ctrl.h"
15 #include "common/hw_features_common.h"
16 #include "radius/radius_client.h"
17 #include "radius/radius_das.h"
18 #include "eap_server/tncs.h"
19 #include "eapol_auth/eapol_auth_sm.h"
20 #include "eapol_auth/eapol_auth_sm_i.h"
21 #include "fst/fst.h"
22 #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"
34 #include "dpp_hostapd.h"
35 #include "gas_query_ap.h"
36 #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"
41 #include "gas_serv.h"
42 #include "dfs.h"
43 #include "ieee802_11.h"
44 #include "bss_load.h"
45 #include "x_snoop.h"
46 #include "dhcp_snoop.h"
47 #include "ndisc_snoop.h"
48 #include "neighbor_db.h"
49 #include "rrm.h"
50 #include "fils_hlp.h"
51 #include "acs.h"
52
53
54 static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason);
55 static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd);
56 static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd);
57 static int setup_interface2(struct hostapd_iface *iface);
58 static void channel_list_update_timeout(void *eloop_ctx, void *timeout_ctx);
59
60
61 int 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
78 static void hostapd_reload_bss(struct hostapd_data *hapd)
79 {
80 struct hostapd_ssid *ssid;
81
82 if (!hapd->started)
83 return;
84
85 #ifndef CONFIG_NO_RADIUS
86 radius_client_reconfig(hapd->radius, hapd->conf->radius);
87 #endif /* CONFIG_NO_RADIUS */
88
89 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 */
96 hostapd_config_clear_wpa_psk(&hapd->conf->ssid.wpa_psk);
97 }
98 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
108 if ((hapd->conf->wpa || hapd->conf->osen) && hapd->wpa_auth == NULL) {
109 hostapd_setup_wpa(hapd);
110 if (hapd->wpa_auth)
111 wpa_init_keys(hapd->wpa_auth);
112 } else if (hapd->conf->wpa) {
113 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 &&
132 hostapd_set_ssid(hapd, hapd->conf->ssid.ssid,
133 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
141 static void hostapd_clear_old(struct hostapd_iface *iface)
142 {
143 size_t j;
144
145 /*
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++) {
150 hostapd_flush_old_stations(iface->bss[j],
151 WLAN_REASON_PREV_AUTH_NOT_VALID);
152 hostapd_broadcast_wep_clear(iface->bss[j]);
153
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 }
160 }
161
162
163 int 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);
185
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;
192 hapd->iconf->channel = oldconf->channel;
193 hapd->iconf->acs = oldconf->acs;
194 hapd->iconf->secondary_channel = oldconf->secondary_channel;
195 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;
204 hapd->conf = newconf->bss[j];
205 hostapd_reload_bss(hapd);
206 }
207
208 hostapd_config_free(oldconf);
209
210
211 return 0;
212 }
213
214
215 static void hostapd_broadcast_key_clear_iface(struct hostapd_data *hapd,
216 const char *ifname)
217 {
218 int i;
219
220 if (!ifname || !hapd->drv_priv)
221 return;
222 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
246 static 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
253 static 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
268 return errors;
269 }
270
271
272 static void hostapd_free_hapd_data(struct hostapd_data *hapd)
273 {
274 os_free(hapd->probereq_cb);
275 hapd->probereq_cb = NULL;
276 hapd->num_probereq_cb = 0;
277
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
285 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
292 wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
293 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;
302 radius_das_deinit(hapd->radius_das);
303 hapd->radius_das = NULL;
304 #endif /* CONFIG_NO_RADIUS */
305
306 hostapd_deinit_wps(hapd);
307 #ifdef CONFIG_DPP
308 hostapd_dpp_deinit(hapd);
309 gas_query_ap_deinit(hapd->gas);
310 #endif /* CONFIG_DPP */
311
312 authsrv_deinit(hapd);
313
314 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 }
329 }
330
331 wpabuf_free(hapd->time_adv);
332
333 #ifdef CONFIG_INTERWORKING
334 gas_serv_deinit(hapd);
335 #endif /* CONFIG_INTERWORKING */
336
337 bss_load_update_deinit(hapd);
338 ndisc_snoop_deinit(hapd);
339 dhcp_snoop_deinit(hapd);
340 x_snoop_deinit(hapd);
341
342 #ifdef CONFIG_SQLITE
343 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);
347 #endif /* CONFIG_SQLITE */
348
349 #ifdef CONFIG_MESH
350 wpabuf_free(hapd->mesh_pending_auth);
351 hapd->mesh_pending_auth = NULL;
352 #endif /* CONFIG_MESH */
353
354 hostapd_clean_rrm(hapd);
355 fils_hlp_deinit(hapd);
356 }
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.
364 * Most of the modules that are initialized in hostapd_setup_bss() are
365 * deinitialized here.
366 */
367 static void hostapd_cleanup(struct hostapd_data *hapd)
368 {
369 wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s))", __func__, hapd,
370 hapd->conf->iface);
371 if (hapd->iface->interfaces &&
372 hapd->iface->interfaces->ctrl_iface_deinit) {
373 wpa_msg(hapd->msg_ctx, MSG_INFO, WPA_EVENT_TERMINATING);
374 hapd->iface->interfaces->ctrl_iface_deinit(hapd);
375 }
376 hostapd_free_hapd_data(hapd);
377 }
378
379
380 static 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--;
391 sta_track_del(info);
392 }
393 }
394
395
396 static void hostapd_cleanup_iface_partial(struct hostapd_iface *iface)
397 {
398 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
399 #ifdef CONFIG_IEEE80211N
400 #ifdef NEED_AP_MLME
401 hostapd_stop_setup_timers(iface);
402 #endif /* NEED_AP_MLME */
403 #endif /* CONFIG_IEEE80211N */
404 if (iface->current_mode)
405 acs_cleanup(iface);
406 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
407 iface->hw_features = NULL;
408 iface->current_mode = NULL;
409 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);
414 sta_track_deinit(iface);
415 }
416
417
418 /**
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 */
425 static void hostapd_cleanup_iface(struct hostapd_iface *iface)
426 {
427 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
428 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
429
430 hostapd_cleanup_iface_partial(iface);
431 hostapd_config_free(iface->conf);
432 iface->conf = NULL;
433
434 os_free(iface->config_fname);
435 os_free(iface->bss);
436 wpa_printf(MSG_DEBUG, "%s: free iface=%p", __func__, iface);
437 os_free(iface);
438 }
439
440
441 static void hostapd_clear_wep(struct hostapd_data *hapd)
442 {
443 if (hapd->drv_priv && !hapd->iface->driver_ap_teardown) {
444 hostapd_set_privacy(hapd, 0);
445 hostapd_broadcast_wep_clear(hapd);
446 }
447 }
448
449
450 static 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
461 /*
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
467 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
486 static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason)
487 {
488 int ret = 0;
489 u8 addr[ETH_ALEN];
490
491 if (hostapd_drv_none(hapd) || hapd->drv_priv == NULL)
492 return 0;
493
494 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 }
503 }
504 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 }
510 hostapd_free_stas(hapd);
511
512 return ret;
513 }
514
515
516 static 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
524 /**
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 */
531 static 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;
536 int auto_addr = 0;
537
538 if (hostapd_drv_none(hapd))
539 return 0;
540
541 if (iface->conf->use_driver_iface_addr)
542 return 0;
543
544 /* 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++) {
553 if (is_zero_ether_addr(iface->conf->bss[j]->bssid)) {
554 if (j)
555 auto_addr++;
556 continue;
557 }
558
559 for (i = 0; i < ETH_ALEN; i++) {
560 mask[i] |=
561 iface->conf->bss[j]->bssid[i] ^
562 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
598 skip_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
602 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
621 static 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++) {
626 if (hostapd_mac_comp(conf->bss[i]->bssid, a) == 0) {
627 return 1;
628 }
629 }
630
631 return 0;
632 }
633
634
635 #ifndef CONFIG_NO_RADIUS
636
637 static int hostapd_das_nas_mismatch(struct hostapd_data *hapd,
638 struct radius_das_attrs *attr)
639 {
640 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
668 return 0;
669 }
670
671
672 static struct sta_info * hostapd_das_find_sta(struct hostapd_data *hapd,
673 struct radius_das_attrs *attr,
674 int *multi)
675 {
676 struct sta_info *selected, *sta;
677 char buf[128];
678 int num_attr = 0;
679 int count;
680
681 *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++;
688 sta = ap_get_sta(hapd, attr->sta_addr);
689 if (!sta) {
690 wpa_printf(MSG_DEBUG,
691 "RADIUS DAS: No Calling-Station-Id match");
692 return NULL;
693 }
694
695 selected = sta;
696 for (sta = hapd->sta_list; sta; sta = sta->next) {
697 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++;
705 if (attr->acct_session_id_len != 16) {
706 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;
715 os_snprintf(buf, sizeof(buf), "%016llX",
716 (unsigned long long) sta->acct_session_id);
717 if (os_memcmp(attr->acct_session_id, buf, 16) != 0)
718 sta->radius_das_match = 0;
719 else
720 count++;
721 }
722
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");
729 }
730
731 if (attr->acct_multi_session_id) {
732 num_attr++;
733 if (attr->acct_multi_session_id_len != 16) {
734 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 ||
744 !sta->eapol_sm->acct_multi_session_id) {
745 sta->radius_das_match = 0;
746 continue;
747 }
748 os_snprintf(buf, sizeof(buf), "%016llX",
749 (unsigned long long)
750 sta->eapol_sm->acct_multi_session_id);
751 if (os_memcmp(attr->acct_multi_session_id, buf, 16) !=
752 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
771 for (sta = hapd->sta_list; sta; sta = sta->next) {
772 struct wpabuf *cui;
773
774 if (!sta->radius_das_match)
775 continue;
776 cui = ieee802_1x_get_radius_cui(sta->eapol_sm);
777 if (!cui || wpabuf_len(cui) != attr->cui_len ||
778 os_memcmp(wpabuf_head(cui), attr->cui,
779 attr->cui_len) != 0)
780 sta->radius_das_match = 0;
781 else
782 count++;
783 }
784
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");
792 }
793
794 if (attr->user_name) {
795 num_attr++;
796 count = 0;
797
798 for (sta = hapd->sta_list; sta; sta = sta->next) {
799 u8 *identity;
800 size_t identity_len;
801
802 if (!sta->radius_das_match)
803 continue;
804 identity = ieee802_1x_get_identity(sta->eapol_sm,
805 &identity_len);
806 if (!identity ||
807 identity_len != attr->user_name_len ||
808 os_memcmp(identity, attr->user_name, identity_len)
809 != 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;
843 }
844 }
845
846 return selected;
847 }
848
849
850 static 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);
856 }
857
858
859 static enum radius_das_res
860 hostapd_das_disconnect(void *ctx, struct radius_das_attrs *attr)
861 {
862 struct hostapd_data *hapd = ctx;
863 struct sta_info *sta;
864 int multi;
865
866 if (hostapd_das_nas_mismatch(hapd, attr))
867 return RADIUS_DAS_NAS_MISMATCH;
868
869 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");
882 return RADIUS_DAS_SESSION_NOT_FOUND;
883 }
884
885 wpa_printf(MSG_DEBUG, "RADIUS DAS: Found a matching session " MACSTR
886 " - disconnecting", MAC2STR(sta->addr));
887 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
888
889 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 */
897
898
899 /**
900 * hostapd_setup_bss - Per-BSS setup (initialization)
901 * @hapd: Pointer to BSS data
902 * @first: Whether this BSS is the first BSS of an interface; -1 = not first,
903 * but interface may exist
904 *
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 */
910 static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
911 {
912 struct hostapd_bss_config *conf = hapd->conf;
913 u8 ssid[SSID_MAX_LEN + 1];
914 int ssid_len, set_ssid;
915 char force_ifname[IFNAMSIZ];
916 u8 if_addr[ETH_ALEN];
917 int flush_old_stations = 1;
918
919 wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s), first=%d)",
920 __func__, hapd, conf->iface, first);
921
922 #ifdef EAP_SERVER_TNC
923 if (conf->tnc && tncs_global_init() < 0) {
924 wpa_printf(MSG_ERROR, "Failed to initialize TNCS");
925 return -1;
926 }
927 #endif /* EAP_SERVER_TNC */
928
929 if (hapd->started) {
930 wpa_printf(MSG_ERROR, "%s: Interface %s was already started",
931 __func__, conf->iface);
932 return -1;
933 }
934 hapd->started = 1;
935
936 if (!first || first == -1) {
937 u8 *addr = hapd->own_addr;
938
939 if (!is_zero_ether_addr(conf->bssid)) {
940 /* Allocate the configured BSSID. */
941 os_memcpy(hapd->own_addr, conf->bssid, ETH_ALEN);
942
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 "
948 "the radio", conf->iface);
949 return -1;
950 }
951 } 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));
958 }
959
960 hapd->interface_added = 1;
961 if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS,
962 conf->iface, addr, hapd,
963 &hapd->drv_priv, force_ifname, if_addr,
964 conf->bridge[0] ? conf->bridge : NULL,
965 first == -1)) {
966 wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
967 MACSTR ")", MAC2STR(hapd->own_addr));
968 hapd->interface_added = 0;
969 return -1;
970 }
971
972 if (!addr)
973 os_memcpy(hapd->own_addr, if_addr, ETH_ALEN);
974 }
975
976 if (conf->wmm_enabled < 0)
977 conf->wmm_enabled = hapd->iconf->ieee80211n;
978
979 #ifdef CONFIG_IEEE80211R_AP
980 if (is_zero_ether_addr(conf->r1_key_holder))
981 os_memcpy(conf->r1_key_holder, hapd->own_addr, ETH_ALEN);
982 #endif /* CONFIG_IEEE80211R_AP */
983
984 #ifdef CONFIG_MESH
985 if ((hapd->conf->mesh & MESH_ENABLED) && hapd->iface->mconf == NULL)
986 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);
992 hostapd_set_privacy(hapd, 0);
993
994 hostapd_broadcast_wep_clear(hapd);
995 if (hostapd_setup_encryption(conf->iface, hapd))
996 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);
1024 }
1025
1026 if (!hostapd_drv_none(hapd)) {
1027 wpa_printf(MSG_ERROR, "Using interface %s with hwaddr " MACSTR
1028 " and ssid \"%s\"",
1029 conf->iface, MAC2STR(hapd->own_addr),
1030 wpa_ssid_txt(conf->ssid.ssid, conf->ssid.ssid_len));
1031 }
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) */
1040 if (set_ssid && hostapd_set_ssid(hapd, conf->ssid.ssid,
1041 conf->ssid.ssid_len)) {
1042 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
1043 return -1;
1044 }
1045
1046 if (wpa_debug_level <= MSG_MSGDUMP)
1047 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 }
1054
1055 if (conf->radius_das_port) {
1056 struct radius_das_conf das_conf;
1057 os_memset(&das_conf, 0, sizeof(das_conf));
1058 das_conf.port = conf->radius_das_port;
1059 das_conf.shared_secret = conf->radius_das_shared_secret;
1060 das_conf.shared_secret_len =
1061 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;
1064 das_conf.require_event_timestamp =
1065 conf->radius_das_require_event_timestamp;
1066 das_conf.require_message_authenticator =
1067 conf->radius_das_require_message_authenticator;
1068 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 }
1077 #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
1086 #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
1094 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
1102 if ((conf->wpa || conf->osen) && hostapd_setup_wpa(hapd))
1103 return -1;
1104
1105 if (accounting_init(hapd)) {
1106 wpa_printf(MSG_ERROR, "Accounting initialization failed.");
1107 return -1;
1108 }
1109
1110 if (conf->ieee802_11f &&
1111 (hapd->iapp = iapp_init(hapd, conf->iapp_iface)) == NULL) {
1112 wpa_printf(MSG_ERROR, "IEEE 802.11F (IAPP) initialization "
1113 "failed.");
1114 return -1;
1115 }
1116
1117 #ifdef CONFIG_INTERWORKING
1118 if (gas_serv_init(hapd)) {
1119 wpa_printf(MSG_ERROR, "GAS server initialization failed");
1120 return -1;
1121 }
1122
1123 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");
1127 return -1;
1128 }
1129 #endif /* CONFIG_INTERWORKING */
1130
1131 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
1156 if (!hostapd_drv_none(hapd) && vlan_init(hapd)) {
1157 wpa_printf(MSG_ERROR, "VLAN initialization failed.");
1158 return -1;
1159 }
1160
1161 if (!conf->start_disabled && ieee802_11_set_beacon(hapd) < 0)
1162 return -1;
1163
1164 if (hapd->wpa_auth && wpa_init_keys(hapd->wpa_auth) < 0)
1165 return -1;
1166
1167 if (hapd->driver && hapd->driver->set_operstate)
1168 hapd->driver->set_operstate(hapd->drv_priv, 1);
1169
1170 return 0;
1171 }
1172
1173
1174 static 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
1180 #ifdef CONFIG_MESH
1181 if ((hapd->conf->mesh & MESH_ENABLED) && iface->mconf == NULL)
1182 return;
1183 #endif /* CONFIG_MESH */
1184
1185 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
1198 static 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
1225 static 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;
1233
1234 if (conf->bss[0]->macaddr_acl == DENY_UNLESS_ACCEPTED) {
1235 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;
1242 }
1243 } else if (conf->bss[0]->macaddr_acl == ACCEPT_UNLESS_DENIED) {
1244 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;
1251 }
1252 }
1253 }
1254
1255
1256 static 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
1273 static 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
1294 static 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
1312 void hostapd_channel_list_updated(struct hostapd_iface *iface, int initiator)
1313 {
1314 if (!iface->wait_channel_update || initiator != REGDOM_SET_BY_USER)
1315 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
1323 static int setup_interface(struct hostapd_iface *iface)
1324 {
1325 struct hostapd_data *hapd = iface->bss[0];
1326 size_t i;
1327
1328 /*
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
1337 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 }
1344
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
1357 /*
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
1365 if (hapd->iconf->country[0] && hapd->iconf->country[1]) {
1366 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
1372 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 }
1378
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;
1385 eloop_register_timeout(5, 0,
1386 channel_list_update_timeout,
1387 iface, NULL);
1388 return 0;
1389 }
1390 }
1391
1392 return setup_interface2(iface);
1393 }
1394
1395
1396 static int setup_interface2(struct hostapd_iface *iface)
1397 {
1398 iface->wait_channel_update = 0;
1399
1400 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);
1408 goto fail;
1409 }
1410 if (ret == 1) {
1411 wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback (ACS)");
1412 return 0;
1413 }
1414 ret = hostapd_check_ht_capab(iface);
1415 if (ret < 0)
1416 goto fail;
1417 if (ret == 1) {
1418 wpa_printf(MSG_DEBUG, "Interface initialization will "
1419 "be completed in a callback");
1420 return 0;
1421 }
1422
1423 if (iface->conf->ieee80211h)
1424 wpa_printf(MSG_DEBUG, "DFS support is enabled");
1425 }
1426 return hostapd_setup_interface_complete(iface, 0);
1427
1428 fail:
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;
1434 }
1435
1436
1437 #ifdef CONFIG_FST
1438
1439 static 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
1447 static 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
1457 static 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
1469 static 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
1479 static 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
1488 static 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
1505 static 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
1526 static 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
1538 static 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
1546 void 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
1563 #ifdef NEED_AP_MLME
1564 static 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
1584 static 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;
1592 u8 center_freq1_idx = 0, center_freq2_idx = 0;
1593 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
1629 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;
1635 width = hostapd_get_nr_chan_width(hapd, ht, vht);
1636 if (vht) {
1637 center_freq1_idx = hapd->iconf->vht_oper_centr_freq_seg0_idx;
1638 if (width == NR_CHAN_WIDTH_80P80)
1639 center_freq2_idx =
1640 hapd->iconf->vht_oper_centr_freq_seg1_idx;
1641 } else if (ht) {
1642 ieee80211_freq_to_chan(hapd->iface->freq +
1643 10 * hapd->iconf->secondary_channel,
1644 &center_freq1_idx);
1645 }
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);
1672 wpabuf_put_u8(nr, center_freq1_idx);
1673 wpabuf_put_u8(nr, center_freq2_idx);
1674
1675 hostapd_neighbor_set(hapd, hapd->own_addr, &ssid, nr, hapd->iconf->lci,
1676 hapd->iconf->civic, hapd->iconf->stationary_ap);
1677
1678 wpabuf_free(nr);
1679 #endif /* NEED_AP_MLME */
1680 }
1681
1682
1683 static int hostapd_setup_interface_complete_sync(struct hostapd_iface *iface,
1684 int err)
1685 {
1686 struct hostapd_data *hapd = iface->bss[0];
1687 size_t j;
1688 u8 *prev_addr;
1689 int delay_apply_cfg = 0;
1690 int res_dfs_offload = 0;
1691
1692 if (err)
1693 goto fail;
1694
1695 wpa_printf(MSG_DEBUG, "Completing interface initialization");
1696 if (iface->conf->channel) {
1697 #ifdef NEED_AP_MLME
1698 int res;
1699 #endif /* NEED_AP_MLME */
1700
1701 iface->freq = hostapd_hw_get_freq(hapd, iface->conf->channel);
1702 wpa_printf(MSG_DEBUG, "Mode: %s Channel: %d "
1703 "Frequency: %d MHz",
1704 hostapd_hw_mode_txt(iface->conf->hw_mode),
1705 iface->conf->channel, iface->freq);
1706
1707 #ifdef NEED_AP_MLME
1708 /* Handle DFS only if it is not offloaded to the driver */
1709 if (!(iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)) {
1710 /* Check DFS */
1711 res = hostapd_handle_dfs(iface);
1712 if (res <= 0) {
1713 if (res < 0)
1714 goto fail;
1715 return res;
1716 }
1717 } else {
1718 /* If DFS is offloaded to the driver */
1719 res_dfs_offload = hostapd_handle_dfs_offload(iface);
1720 if (res_dfs_offload <= 0) {
1721 if (res_dfs_offload < 0)
1722 goto fail;
1723 } else {
1724 wpa_printf(MSG_DEBUG,
1725 "Proceed with AP/channel setup");
1726 /*
1727 * If this is a DFS channel, move to completing
1728 * AP setup.
1729 */
1730 if (res_dfs_offload == 1)
1731 goto dfs_offload;
1732 /* Otherwise fall through. */
1733 }
1734 }
1735 #endif /* NEED_AP_MLME */
1736
1737 #ifdef CONFIG_MESH
1738 if (iface->mconf != NULL) {
1739 wpa_printf(MSG_DEBUG,
1740 "%s: Mesh configuration will be applied while joining the mesh network",
1741 iface->bss[0]->conf->iface);
1742 delay_apply_cfg = 1;
1743 }
1744 #endif /* CONFIG_MESH */
1745
1746 if (!delay_apply_cfg &&
1747 hostapd_set_freq(hapd, hapd->iconf->hw_mode, iface->freq,
1748 hapd->iconf->channel,
1749 hapd->iconf->ieee80211n,
1750 hapd->iconf->ieee80211ac,
1751 hapd->iconf->secondary_channel,
1752 hapd->iconf->vht_oper_chwidth,
1753 hapd->iconf->vht_oper_centr_freq_seg0_idx,
1754 hapd->iconf->vht_oper_centr_freq_seg1_idx)) {
1755 wpa_printf(MSG_ERROR, "Could not set channel for "
1756 "kernel driver");
1757 goto fail;
1758 }
1759 }
1760
1761 if (iface->current_mode) {
1762 if (hostapd_prepare_rates(iface, iface->current_mode)) {
1763 wpa_printf(MSG_ERROR, "Failed to prepare rates "
1764 "table.");
1765 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1766 HOSTAPD_LEVEL_WARNING,
1767 "Failed to prepare rates table.");
1768 goto fail;
1769 }
1770 }
1771
1772 if (hapd->iconf->rts_threshold > -1 &&
1773 hostapd_set_rts(hapd, hapd->iconf->rts_threshold)) {
1774 wpa_printf(MSG_ERROR, "Could not set RTS threshold for "
1775 "kernel driver");
1776 goto fail;
1777 }
1778
1779 if (hapd->iconf->fragm_threshold > -1 &&
1780 hostapd_set_frag(hapd, hapd->iconf->fragm_threshold)) {
1781 wpa_printf(MSG_ERROR, "Could not set fragmentation threshold "
1782 "for kernel driver");
1783 goto fail;
1784 }
1785
1786 prev_addr = hapd->own_addr;
1787
1788 for (j = 0; j < iface->num_bss; j++) {
1789 hapd = iface->bss[j];
1790 if (j)
1791 os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN);
1792 if (hostapd_setup_bss(hapd, j == 0)) {
1793 do {
1794 hapd = iface->bss[j];
1795 hostapd_bss_deinit_no_free(hapd);
1796 hostapd_free_hapd_data(hapd);
1797 } while (j-- > 0);
1798 goto fail;
1799 }
1800 if (is_zero_ether_addr(hapd->conf->bssid))
1801 prev_addr = hapd->own_addr;
1802 }
1803 hapd = iface->bss[0];
1804
1805 hostapd_tx_queue_params(iface);
1806
1807 ap_list_init(iface);
1808
1809 hostapd_set_acl(hapd);
1810
1811 if (hostapd_driver_commit(hapd) < 0) {
1812 wpa_printf(MSG_ERROR, "%s: Failed to commit driver "
1813 "configuration", __func__);
1814 goto fail;
1815 }
1816
1817 /*
1818 * WPS UPnP module can be initialized only when the "upnp_iface" is up.
1819 * If "interface" and "upnp_iface" are the same (e.g., non-bridge
1820 * mode), the interface is up only after driver_commit, so initialize
1821 * WPS after driver_commit.
1822 */
1823 for (j = 0; j < iface->num_bss; j++) {
1824 if (hostapd_init_wps_complete(iface->bss[j]))
1825 goto fail;
1826 }
1827
1828 if ((iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) &&
1829 !res_dfs_offload) {
1830 /*
1831 * If freq is DFS, and DFS is offloaded to the driver, then wait
1832 * for CAC to complete.
1833 */
1834 wpa_printf(MSG_DEBUG, "%s: Wait for CAC to complete", __func__);
1835 return res_dfs_offload;
1836 }
1837
1838 #ifdef NEED_AP_MLME
1839 dfs_offload:
1840 #endif /* NEED_AP_MLME */
1841
1842 #ifdef CONFIG_FST
1843 if (hapd->iconf->fst_cfg.group_id[0]) {
1844 struct fst_wpa_obj iface_obj;
1845
1846 fst_hostapd_fill_iface_obj(hapd, &iface_obj);
1847 iface->fst = fst_attach(hapd->conf->iface, hapd->own_addr,
1848 &iface_obj, &hapd->iconf->fst_cfg);
1849 if (!iface->fst) {
1850 wpa_printf(MSG_ERROR, "Could not attach to FST %s",
1851 hapd->iconf->fst_cfg.group_id);
1852 goto fail;
1853 }
1854 }
1855 #endif /* CONFIG_FST */
1856
1857 hostapd_set_state(iface, HAPD_IFACE_ENABLED);
1858 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_ENABLED);
1859 if (hapd->setup_complete_cb)
1860 hapd->setup_complete_cb(hapd->setup_complete_cb_ctx);
1861
1862 wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
1863 iface->bss[0]->conf->iface);
1864 if (iface->interfaces && iface->interfaces->terminate_on_error > 0)
1865 iface->interfaces->terminate_on_error--;
1866
1867 for (j = 0; j < iface->num_bss; j++)
1868 hostapd_set_own_neighbor_report(iface->bss[j]);
1869
1870 return 0;
1871
1872 fail:
1873 wpa_printf(MSG_ERROR, "Interface initialization failed");
1874 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
1875 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
1876 #ifdef CONFIG_FST
1877 if (iface->fst) {
1878 fst_detach(iface->fst);
1879 iface->fst = NULL;
1880 }
1881 #endif /* CONFIG_FST */
1882 if (iface->interfaces && iface->interfaces->terminate_on_error)
1883 eloop_terminate();
1884 return -1;
1885 }
1886
1887
1888 /**
1889 * hostapd_setup_interface_complete - Complete interface setup
1890 *
1891 * This function is called when previous steps in the interface setup has been
1892 * completed. This can also start operations, e.g., DFS, that will require
1893 * additional processing before interface is ready to be enabled. Such
1894 * operations will call this function from eloop callbacks when finished.
1895 */
1896 int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err)
1897 {
1898 struct hapd_interfaces *interfaces = iface->interfaces;
1899 struct hostapd_data *hapd = iface->bss[0];
1900 unsigned int i;
1901 int not_ready_in_sync_ifaces = 0;
1902
1903 if (!iface->need_to_start_in_sync)
1904 return hostapd_setup_interface_complete_sync(iface, err);
1905
1906 if (err) {
1907 wpa_printf(MSG_ERROR, "Interface initialization failed");
1908 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
1909 iface->need_to_start_in_sync = 0;
1910 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
1911 if (interfaces && interfaces->terminate_on_error)
1912 eloop_terminate();
1913 return -1;
1914 }
1915
1916 if (iface->ready_to_start_in_sync) {
1917 /* Already in ready and waiting. should never happpen */
1918 return 0;
1919 }
1920
1921 for (i = 0; i < interfaces->count; i++) {
1922 if (interfaces->iface[i]->need_to_start_in_sync &&
1923 !interfaces->iface[i]->ready_to_start_in_sync)
1924 not_ready_in_sync_ifaces++;
1925 }
1926
1927 /*
1928 * Check if this is the last interface, if yes then start all the other
1929 * waiting interfaces. If not, add this interface to the waiting list.
1930 */
1931 if (not_ready_in_sync_ifaces > 1 && iface->state == HAPD_IFACE_DFS) {
1932 /*
1933 * If this interface went through CAC, do not synchronize, just
1934 * start immediately.
1935 */
1936 iface->need_to_start_in_sync = 0;
1937 wpa_printf(MSG_INFO,
1938 "%s: Finished CAC - bypass sync and start interface",
1939 iface->bss[0]->conf->iface);
1940 return hostapd_setup_interface_complete_sync(iface, err);
1941 }
1942
1943 if (not_ready_in_sync_ifaces > 1) {
1944 /* need to wait as there are other interfaces still coming up */
1945 iface->ready_to_start_in_sync = 1;
1946 wpa_printf(MSG_INFO,
1947 "%s: Interface waiting to sync with other interfaces",
1948 iface->bss[0]->conf->iface);
1949 return 0;
1950 }
1951
1952 wpa_printf(MSG_INFO,
1953 "%s: Last interface to sync - starting all interfaces",
1954 iface->bss[0]->conf->iface);
1955 iface->need_to_start_in_sync = 0;
1956 hostapd_setup_interface_complete_sync(iface, err);
1957 for (i = 0; i < interfaces->count; i++) {
1958 if (interfaces->iface[i]->need_to_start_in_sync &&
1959 interfaces->iface[i]->ready_to_start_in_sync) {
1960 hostapd_setup_interface_complete_sync(
1961 interfaces->iface[i], 0);
1962 /* Only once the interfaces are sync started */
1963 interfaces->iface[i]->need_to_start_in_sync = 0;
1964 }
1965 }
1966
1967 return 0;
1968 }
1969
1970
1971 /**
1972 * hostapd_setup_interface - Setup of an interface
1973 * @iface: Pointer to interface data.
1974 * Returns: 0 on success, -1 on failure
1975 *
1976 * Initializes the driver interface, validates the configuration,
1977 * and sets driver parameters based on the configuration.
1978 * Flushes old stations, sets the channel, encryption,
1979 * beacons, and WDS links based on the configuration.
1980 *
1981 * If interface setup requires more time, e.g., to perform HT co-ex scans, ACS,
1982 * or DFS operations, this function returns 0 before such operations have been
1983 * completed. The pending operations are registered into eloop and will be
1984 * completed from eloop callbacks. Those callbacks end up calling
1985 * hostapd_setup_interface_complete() once setup has been completed.
1986 */
1987 int hostapd_setup_interface(struct hostapd_iface *iface)
1988 {
1989 int ret;
1990
1991 ret = setup_interface(iface);
1992 if (ret) {
1993 wpa_printf(MSG_ERROR, "%s: Unable to setup interface.",
1994 iface->bss[0]->conf->iface);
1995 return -1;
1996 }
1997
1998 return 0;
1999 }
2000
2001
2002 /**
2003 * hostapd_alloc_bss_data - Allocate and initialize per-BSS data
2004 * @hapd_iface: Pointer to interface data
2005 * @conf: Pointer to per-interface configuration
2006 * @bss: Pointer to per-BSS configuration for this BSS
2007 * Returns: Pointer to allocated BSS data
2008 *
2009 * This function is used to allocate per-BSS data structure. This data will be
2010 * freed after hostapd_cleanup() is called for it during interface
2011 * deinitialization.
2012 */
2013 struct hostapd_data *
2014 hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
2015 struct hostapd_config *conf,
2016 struct hostapd_bss_config *bss)
2017 {
2018 struct hostapd_data *hapd;
2019
2020 hapd = os_zalloc(sizeof(*hapd));
2021 if (hapd == NULL)
2022 return NULL;
2023
2024 hapd->new_assoc_sta_cb = hostapd_new_assoc_sta;
2025 hapd->iconf = conf;
2026 hapd->conf = bss;
2027 hapd->iface = hapd_iface;
2028 if (conf)
2029 hapd->driver = conf->driver;
2030 hapd->ctrl_sock = -1;
2031 dl_list_init(&hapd->ctrl_dst);
2032 dl_list_init(&hapd->nr_db);
2033 hapd->dhcp_sock = -1;
2034 #ifdef CONFIG_IEEE80211R_AP
2035 dl_list_init(&hapd->l2_queue);
2036 dl_list_init(&hapd->l2_oui_queue);
2037 #endif /* CONFIG_IEEE80211R_AP */
2038
2039 return hapd;
2040 }
2041
2042
2043 static void hostapd_bss_deinit(struct hostapd_data *hapd)
2044 {
2045 if (!hapd)
2046 return;
2047 wpa_printf(MSG_DEBUG, "%s: deinit bss %s", __func__,
2048 hapd->conf->iface);
2049 hostapd_bss_deinit_no_free(hapd);
2050 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
2051 hostapd_cleanup(hapd);
2052 }
2053
2054
2055 void hostapd_interface_deinit(struct hostapd_iface *iface)
2056 {
2057 int j;
2058
2059 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
2060 if (iface == NULL)
2061 return;
2062
2063 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
2064
2065 #ifdef CONFIG_IEEE80211N
2066 #ifdef NEED_AP_MLME
2067 hostapd_stop_setup_timers(iface);
2068 eloop_cancel_timeout(ap_ht2040_timeout, iface, NULL);
2069 #endif /* NEED_AP_MLME */
2070 #endif /* CONFIG_IEEE80211N */
2071 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
2072 iface->wait_channel_update = 0;
2073
2074 #ifdef CONFIG_FST
2075 if (iface->fst) {
2076 fst_detach(iface->fst);
2077 iface->fst = NULL;
2078 }
2079 #endif /* CONFIG_FST */
2080
2081 for (j = iface->num_bss - 1; j >= 0; j--) {
2082 if (!iface->bss)
2083 break;
2084 hostapd_bss_deinit(iface->bss[j]);
2085 }
2086 }
2087
2088
2089 void hostapd_interface_free(struct hostapd_iface *iface)
2090 {
2091 size_t j;
2092 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
2093 for (j = 0; j < iface->num_bss; j++) {
2094 if (!iface->bss)
2095 break;
2096 wpa_printf(MSG_DEBUG, "%s: free hapd %p",
2097 __func__, iface->bss[j]);
2098 os_free(iface->bss[j]);
2099 }
2100 hostapd_cleanup_iface(iface);
2101 }
2102
2103
2104 struct hostapd_iface * hostapd_alloc_iface(void)
2105 {
2106 struct hostapd_iface *hapd_iface;
2107
2108 hapd_iface = os_zalloc(sizeof(*hapd_iface));
2109 if (!hapd_iface)
2110 return NULL;
2111
2112 dl_list_init(&hapd_iface->sta_seen);
2113
2114 return hapd_iface;
2115 }
2116
2117
2118 /**
2119 * hostapd_init - Allocate and initialize per-interface data
2120 * @config_file: Path to the configuration file
2121 * Returns: Pointer to the allocated interface data or %NULL on failure
2122 *
2123 * This function is used to allocate main data structures for per-interface
2124 * data. The allocated data buffer will be freed by calling
2125 * hostapd_cleanup_iface().
2126 */
2127 struct hostapd_iface * hostapd_init(struct hapd_interfaces *interfaces,
2128 const char *config_file)
2129 {
2130 struct hostapd_iface *hapd_iface = NULL;
2131 struct hostapd_config *conf = NULL;
2132 struct hostapd_data *hapd;
2133 size_t i;
2134
2135 hapd_iface = hostapd_alloc_iface();
2136 if (hapd_iface == NULL)
2137 goto fail;
2138
2139 hapd_iface->config_fname = os_strdup(config_file);
2140 if (hapd_iface->config_fname == NULL)
2141 goto fail;
2142
2143 conf = interfaces->config_read_cb(hapd_iface->config_fname);
2144 if (conf == NULL)
2145 goto fail;
2146 hapd_iface->conf = conf;
2147
2148 hapd_iface->num_bss = conf->num_bss;
2149 hapd_iface->bss = os_calloc(conf->num_bss,
2150 sizeof(struct hostapd_data *));
2151 if (hapd_iface->bss == NULL)
2152 goto fail;
2153
2154 for (i = 0; i < conf->num_bss; i++) {
2155 hapd = hapd_iface->bss[i] =
2156 hostapd_alloc_bss_data(hapd_iface, conf,
2157 conf->bss[i]);
2158 if (hapd == NULL)
2159 goto fail;
2160 hapd->msg_ctx = hapd;
2161 }
2162
2163 return hapd_iface;
2164
2165 fail:
2166 wpa_printf(MSG_ERROR, "Failed to set up interface with %s",
2167 config_file);
2168 if (conf)
2169 hostapd_config_free(conf);
2170 if (hapd_iface) {
2171 os_free(hapd_iface->config_fname);
2172 os_free(hapd_iface->bss);
2173 wpa_printf(MSG_DEBUG, "%s: free iface %p",
2174 __func__, hapd_iface);
2175 os_free(hapd_iface);
2176 }
2177 return NULL;
2178 }
2179
2180
2181 static int ifname_in_use(struct hapd_interfaces *interfaces, const char *ifname)
2182 {
2183 size_t i, j;
2184
2185 for (i = 0; i < interfaces->count; i++) {
2186 struct hostapd_iface *iface = interfaces->iface[i];
2187 for (j = 0; j < iface->num_bss; j++) {
2188 struct hostapd_data *hapd = iface->bss[j];
2189 if (os_strcmp(ifname, hapd->conf->iface) == 0)
2190 return 1;
2191 }
2192 }
2193
2194 return 0;
2195 }
2196
2197
2198 /**
2199 * hostapd_interface_init_bss - Read configuration file and init BSS data
2200 *
2201 * This function is used to parse configuration file for a BSS. This BSS is
2202 * added to an existing interface sharing the same radio (if any) or a new
2203 * interface is created if this is the first interface on a radio. This
2204 * allocate memory for the BSS. No actual driver operations are started.
2205 *
2206 * This is similar to hostapd_interface_init(), but for a case where the
2207 * configuration is used to add a single BSS instead of all BSSes for a radio.
2208 */
2209 struct hostapd_iface *
2210 hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy,
2211 const char *config_fname, int debug)
2212 {
2213 struct hostapd_iface *new_iface = NULL, *iface = NULL;
2214 struct hostapd_data *hapd;
2215 int k;
2216 size_t i, bss_idx;
2217
2218 if (!phy || !*phy)
2219 return NULL;
2220
2221 for (i = 0; i < interfaces->count; i++) {
2222 if (os_strcmp(interfaces->iface[i]->phy, phy) == 0) {
2223 iface = interfaces->iface[i];
2224 break;
2225 }
2226 }
2227
2228 wpa_printf(MSG_INFO, "Configuration file: %s (phy %s)%s",
2229 config_fname, phy, iface ? "" : " --> new PHY");
2230 if (iface) {
2231 struct hostapd_config *conf;
2232 struct hostapd_bss_config **tmp_conf;
2233 struct hostapd_data **tmp_bss;
2234 struct hostapd_bss_config *bss;
2235 const char *ifname;
2236
2237 /* Add new BSS to existing iface */
2238 conf = interfaces->config_read_cb(config_fname);
2239 if (conf == NULL)
2240 return NULL;
2241 if (conf->num_bss > 1) {
2242 wpa_printf(MSG_ERROR, "Multiple BSSes specified in BSS-config");
2243 hostapd_config_free(conf);
2244 return NULL;
2245 }
2246
2247 ifname = conf->bss[0]->iface;
2248 if (ifname[0] != '\0' && ifname_in_use(interfaces, ifname)) {
2249 wpa_printf(MSG_ERROR,
2250 "Interface name %s already in use", ifname);
2251 hostapd_config_free(conf);
2252 return NULL;
2253 }
2254
2255 tmp_conf = os_realloc_array(
2256 iface->conf->bss, iface->conf->num_bss + 1,
2257 sizeof(struct hostapd_bss_config *));
2258 tmp_bss = os_realloc_array(iface->bss, iface->num_bss + 1,
2259 sizeof(struct hostapd_data *));
2260 if (tmp_bss)
2261 iface->bss = tmp_bss;
2262 if (tmp_conf) {
2263 iface->conf->bss = tmp_conf;
2264 iface->conf->last_bss = tmp_conf[0];
2265 }
2266 if (tmp_bss == NULL || tmp_conf == NULL) {
2267 hostapd_config_free(conf);
2268 return NULL;
2269 }
2270 bss = iface->conf->bss[iface->conf->num_bss] = conf->bss[0];
2271 iface->conf->num_bss++;
2272
2273 hapd = hostapd_alloc_bss_data(iface, iface->conf, bss);
2274 if (hapd == NULL) {
2275 iface->conf->num_bss--;
2276 hostapd_config_free(conf);
2277 return NULL;
2278 }
2279 iface->conf->last_bss = bss;
2280 iface->bss[iface->num_bss] = hapd;
2281 hapd->msg_ctx = hapd;
2282
2283 bss_idx = iface->num_bss++;
2284 conf->num_bss--;
2285 conf->bss[0] = NULL;
2286 hostapd_config_free(conf);
2287 } else {
2288 /* Add a new iface with the first BSS */
2289 new_iface = iface = hostapd_init(interfaces, config_fname);
2290 if (!iface)
2291 return NULL;
2292 os_strlcpy(iface->phy, phy, sizeof(iface->phy));
2293 iface->interfaces = interfaces;
2294 bss_idx = 0;
2295 }
2296
2297 for (k = 0; k < debug; k++) {
2298 if (iface->bss[bss_idx]->conf->logger_stdout_level > 0)
2299 iface->bss[bss_idx]->conf->logger_stdout_level--;
2300 }
2301
2302 if (iface->conf->bss[bss_idx]->iface[0] == '\0' &&
2303 !hostapd_drv_none(iface->bss[bss_idx])) {
2304 wpa_printf(MSG_ERROR, "Interface name not specified in %s",
2305 config_fname);
2306 if (new_iface)
2307 hostapd_interface_deinit_free(new_iface);
2308 return NULL;
2309 }
2310
2311 return iface;
2312 }
2313
2314
2315 void hostapd_interface_deinit_free(struct hostapd_iface *iface)
2316 {
2317 const struct wpa_driver_ops *driver;
2318 void *drv_priv;
2319
2320 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
2321 if (iface == NULL)
2322 return;
2323 wpa_printf(MSG_DEBUG, "%s: num_bss=%u conf->num_bss=%u",
2324 __func__, (unsigned int) iface->num_bss,
2325 (unsigned int) iface->conf->num_bss);
2326 driver = iface->bss[0]->driver;
2327 drv_priv = iface->bss[0]->drv_priv;
2328 hostapd_interface_deinit(iface);
2329 wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
2330 __func__, driver, drv_priv);
2331 if (driver && driver->hapd_deinit && drv_priv) {
2332 driver->hapd_deinit(drv_priv);
2333 iface->bss[0]->drv_priv = NULL;
2334 }
2335 hostapd_interface_free(iface);
2336 }
2337
2338
2339 static void hostapd_deinit_driver(const struct wpa_driver_ops *driver,
2340 void *drv_priv,
2341 struct hostapd_iface *hapd_iface)
2342 {
2343 size_t j;
2344
2345 wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
2346 __func__, driver, drv_priv);
2347 if (driver && driver->hapd_deinit && drv_priv) {
2348 driver->hapd_deinit(drv_priv);
2349 for (j = 0; j < hapd_iface->num_bss; j++) {
2350 wpa_printf(MSG_DEBUG, "%s:bss[%d]->drv_priv=%p",
2351 __func__, (int) j,
2352 hapd_iface->bss[j]->drv_priv);
2353 if (hapd_iface->bss[j]->drv_priv == drv_priv)
2354 hapd_iface->bss[j]->drv_priv = NULL;
2355 }
2356 }
2357 }
2358
2359
2360 int hostapd_enable_iface(struct hostapd_iface *hapd_iface)
2361 {
2362 size_t j;
2363
2364 if (hapd_iface->bss[0]->drv_priv != NULL) {
2365 wpa_printf(MSG_ERROR, "Interface %s already enabled",
2366 hapd_iface->conf->bss[0]->iface);
2367 return -1;
2368 }
2369
2370 wpa_printf(MSG_DEBUG, "Enable interface %s",
2371 hapd_iface->conf->bss[0]->iface);
2372
2373 for (j = 0; j < hapd_iface->num_bss; j++)
2374 hostapd_set_security_params(hapd_iface->conf->bss[j], 1);
2375 if (hostapd_config_check(hapd_iface->conf, 1) < 0) {
2376 wpa_printf(MSG_INFO, "Invalid configuration - cannot enable");
2377 return -1;
2378 }
2379
2380 if (hapd_iface->interfaces == NULL ||
2381 hapd_iface->interfaces->driver_init == NULL ||
2382 hapd_iface->interfaces->driver_init(hapd_iface))
2383 return -1;
2384
2385 if (hostapd_setup_interface(hapd_iface)) {
2386 hostapd_deinit_driver(hapd_iface->bss[0]->driver,
2387 hapd_iface->bss[0]->drv_priv,
2388 hapd_iface);
2389 return -1;
2390 }
2391
2392 return 0;
2393 }
2394
2395
2396 int hostapd_reload_iface(struct hostapd_iface *hapd_iface)
2397 {
2398 size_t j;
2399
2400 wpa_printf(MSG_DEBUG, "Reload interface %s",
2401 hapd_iface->conf->bss[0]->iface);
2402 for (j = 0; j < hapd_iface->num_bss; j++)
2403 hostapd_set_security_params(hapd_iface->conf->bss[j], 1);
2404 if (hostapd_config_check(hapd_iface->conf, 1) < 0) {
2405 wpa_printf(MSG_ERROR, "Updated configuration is invalid");
2406 return -1;
2407 }
2408 hostapd_clear_old(hapd_iface);
2409 for (j = 0; j < hapd_iface->num_bss; j++)
2410 hostapd_reload_bss(hapd_iface->bss[j]);
2411
2412 return 0;
2413 }
2414
2415
2416 int hostapd_disable_iface(struct hostapd_iface *hapd_iface)
2417 {
2418 size_t j;
2419 const struct wpa_driver_ops *driver;
2420 void *drv_priv;
2421
2422 if (hapd_iface == NULL)
2423 return -1;
2424
2425 if (hapd_iface->bss[0]->drv_priv == NULL) {
2426 wpa_printf(MSG_INFO, "Interface %s already disabled",
2427 hapd_iface->conf->bss[0]->iface);
2428 return -1;
2429 }
2430
2431 wpa_msg(hapd_iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
2432 driver = hapd_iface->bss[0]->driver;
2433 drv_priv = hapd_iface->bss[0]->drv_priv;
2434
2435 hapd_iface->driver_ap_teardown =
2436 !!(hapd_iface->drv_flags &
2437 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
2438
2439 /* same as hostapd_interface_deinit without deinitializing ctrl-iface */
2440 for (j = 0; j < hapd_iface->num_bss; j++) {
2441 struct hostapd_data *hapd = hapd_iface->bss[j];
2442 hostapd_bss_deinit_no_free(hapd);
2443 hostapd_free_hapd_data(hapd);
2444 }
2445
2446 hostapd_deinit_driver(driver, drv_priv, hapd_iface);
2447
2448 /* From hostapd_cleanup_iface: These were initialized in
2449 * hostapd_setup_interface and hostapd_setup_interface_complete
2450 */
2451 hostapd_cleanup_iface_partial(hapd_iface);
2452
2453 wpa_printf(MSG_DEBUG, "Interface %s disabled",
2454 hapd_iface->bss[0]->conf->iface);
2455 hostapd_set_state(hapd_iface, HAPD_IFACE_DISABLED);
2456 return 0;
2457 }
2458
2459
2460 static struct hostapd_iface *
2461 hostapd_iface_alloc(struct hapd_interfaces *interfaces)
2462 {
2463 struct hostapd_iface **iface, *hapd_iface;
2464
2465 iface = os_realloc_array(interfaces->iface, interfaces->count + 1,
2466 sizeof(struct hostapd_iface *));
2467 if (iface == NULL)
2468 return NULL;
2469 interfaces->iface = iface;
2470 hapd_iface = interfaces->iface[interfaces->count] =
2471 hostapd_alloc_iface();
2472 if (hapd_iface == NULL) {
2473 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for "
2474 "the interface", __func__);
2475 return NULL;
2476 }
2477 interfaces->count++;
2478 hapd_iface->interfaces = interfaces;
2479
2480 return hapd_iface;
2481 }
2482
2483
2484 static struct hostapd_config *
2485 hostapd_config_alloc(struct hapd_interfaces *interfaces, const char *ifname,
2486 const char *ctrl_iface, const char *driver)
2487 {
2488 struct hostapd_bss_config *bss;
2489 struct hostapd_config *conf;
2490
2491 /* Allocates memory for bss and conf */
2492 conf = hostapd_config_defaults();
2493 if (conf == NULL) {
2494 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for "
2495 "configuration", __func__);
2496 return NULL;
2497 }
2498
2499 if (driver) {
2500 int j;
2501
2502 for (j = 0; wpa_drivers[j]; j++) {
2503 if (os_strcmp(driver, wpa_drivers[j]->name) == 0) {
2504 conf->driver = wpa_drivers[j];
2505 goto skip;
2506 }
2507 }
2508
2509 wpa_printf(MSG_ERROR,
2510 "Invalid/unknown driver '%s' - registering the default driver",
2511 driver);
2512 }
2513
2514 conf->driver = wpa_drivers[0];
2515 if (conf->driver == NULL) {
2516 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
2517 hostapd_config_free(conf);
2518 return NULL;
2519 }
2520
2521 skip:
2522 bss = conf->last_bss = conf->bss[0];
2523
2524 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
2525 bss->ctrl_interface = os_strdup(ctrl_iface);
2526 if (bss->ctrl_interface == NULL) {
2527 hostapd_config_free(conf);
2528 return NULL;
2529 }
2530
2531 /* Reading configuration file skipped, will be done in SET!
2532 * From reading the configuration till the end has to be done in
2533 * SET
2534 */
2535 return conf;
2536 }
2537
2538
2539 static int hostapd_data_alloc(struct hostapd_iface *hapd_iface,
2540 struct hostapd_config *conf)
2541 {
2542 size_t i;
2543 struct hostapd_data *hapd;
2544
2545 hapd_iface->bss = os_calloc(conf->num_bss,
2546 sizeof(struct hostapd_data *));
2547 if (hapd_iface->bss == NULL)
2548 return -1;
2549
2550 for (i = 0; i < conf->num_bss; i++) {
2551 hapd = hapd_iface->bss[i] =
2552 hostapd_alloc_bss_data(hapd_iface, conf, conf->bss[i]);
2553 if (hapd == NULL) {
2554 while (i > 0) {
2555 i--;
2556 os_free(hapd_iface->bss[i]);
2557 hapd_iface->bss[i] = NULL;
2558 }
2559 os_free(hapd_iface->bss);
2560 hapd_iface->bss = NULL;
2561 return -1;
2562 }
2563 hapd->msg_ctx = hapd;
2564 }
2565
2566 hapd_iface->conf = conf;
2567 hapd_iface->num_bss = conf->num_bss;
2568
2569 return 0;
2570 }
2571
2572
2573 int hostapd_add_iface(struct hapd_interfaces *interfaces, char *buf)
2574 {
2575 struct hostapd_config *conf = NULL;
2576 struct hostapd_iface *hapd_iface = NULL, *new_iface = NULL;
2577 struct hostapd_data *hapd;
2578 char *ptr;
2579 size_t i, j;
2580 const char *conf_file = NULL, *phy_name = NULL;
2581
2582 if (os_strncmp(buf, "bss_config=", 11) == 0) {
2583 char *pos;
2584 phy_name = buf + 11;
2585 pos = os_strchr(phy_name, ':');
2586 if (!pos)
2587 return -1;
2588 *pos++ = '\0';
2589 conf_file = pos;
2590 if (!os_strlen(conf_file))
2591 return -1;
2592
2593 hapd_iface = hostapd_interface_init_bss(interfaces, phy_name,
2594 conf_file, 0);
2595 if (!hapd_iface)
2596 return -1;
2597 for (j = 0; j < interfaces->count; j++) {
2598 if (interfaces->iface[j] == hapd_iface)
2599 break;
2600 }
2601 if (j == interfaces->count) {
2602 struct hostapd_iface **tmp;
2603 tmp = os_realloc_array(interfaces->iface,
2604 interfaces->count + 1,
2605 sizeof(struct hostapd_iface *));
2606 if (!tmp) {
2607 hostapd_interface_deinit_free(hapd_iface);
2608 return -1;
2609 }
2610 interfaces->iface = tmp;
2611 interfaces->iface[interfaces->count++] = hapd_iface;
2612 new_iface = hapd_iface;
2613 }
2614
2615 if (new_iface) {
2616 if (interfaces->driver_init(hapd_iface))
2617 goto fail;
2618
2619 if (hostapd_setup_interface(hapd_iface)) {
2620 hostapd_deinit_driver(
2621 hapd_iface->bss[0]->driver,
2622 hapd_iface->bss[0]->drv_priv,
2623 hapd_iface);
2624 goto fail;
2625 }
2626 } else {
2627 /* Assign new BSS with bss[0]'s driver info */
2628 hapd = hapd_iface->bss[hapd_iface->num_bss - 1];
2629 hapd->driver = hapd_iface->bss[0]->driver;
2630 hapd->drv_priv = hapd_iface->bss[0]->drv_priv;
2631 os_memcpy(hapd->own_addr, hapd_iface->bss[0]->own_addr,
2632 ETH_ALEN);
2633
2634 if (start_ctrl_iface_bss(hapd) < 0 ||
2635 (hapd_iface->state == HAPD_IFACE_ENABLED &&
2636 hostapd_setup_bss(hapd, -1))) {
2637 hostapd_cleanup(hapd);
2638 hapd_iface->bss[hapd_iface->num_bss - 1] = NULL;
2639 hapd_iface->conf->num_bss--;
2640 hapd_iface->num_bss--;
2641 wpa_printf(MSG_DEBUG, "%s: free hapd %p %s",
2642 __func__, hapd, hapd->conf->iface);
2643 hostapd_config_free_bss(hapd->conf);
2644 hapd->conf = NULL;
2645 os_free(hapd);
2646 return -1;
2647 }
2648 }
2649 return 0;
2650 }
2651
2652 ptr = os_strchr(buf, ' ');
2653 if (ptr == NULL)
2654 return -1;
2655 *ptr++ = '\0';
2656
2657 if (os_strncmp(ptr, "config=", 7) == 0)
2658 conf_file = ptr + 7;
2659
2660 for (i = 0; i < interfaces->count; i++) {
2661 if (!os_strcmp(interfaces->iface[i]->conf->bss[0]->iface,
2662 buf)) {
2663 wpa_printf(MSG_INFO, "Cannot add interface - it "
2664 "already exists");
2665 return -1;
2666 }
2667 }
2668
2669 hapd_iface = hostapd_iface_alloc(interfaces);
2670 if (hapd_iface == NULL) {
2671 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
2672 "for interface", __func__);
2673 goto fail;
2674 }
2675 new_iface = hapd_iface;
2676
2677 if (conf_file && interfaces->config_read_cb) {
2678 conf = interfaces->config_read_cb(conf_file);
2679 if (conf && conf->bss)
2680 os_strlcpy(conf->bss[0]->iface, buf,
2681 sizeof(conf->bss[0]->iface));
2682 } else {
2683 char *driver = os_strchr(ptr, ' ');
2684
2685 if (driver)
2686 *driver++ = '\0';
2687 conf = hostapd_config_alloc(interfaces, buf, ptr, driver);
2688 }
2689
2690 if (conf == NULL || conf->bss == NULL) {
2691 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
2692 "for configuration", __func__);
2693 goto fail;
2694 }
2695
2696 if (hostapd_data_alloc(hapd_iface, conf) < 0) {
2697 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
2698 "for hostapd", __func__);
2699 goto fail;
2700 }
2701 conf = NULL;
2702
2703 if (start_ctrl_iface(hapd_iface) < 0)
2704 goto fail;
2705
2706 wpa_printf(MSG_INFO, "Add interface '%s'",
2707 hapd_iface->conf->bss[0]->iface);
2708
2709 return 0;
2710
2711 fail:
2712 if (conf)
2713 hostapd_config_free(conf);
2714 if (hapd_iface) {
2715 if (hapd_iface->bss) {
2716 for (i = 0; i < hapd_iface->num_bss; i++) {
2717 hapd = hapd_iface->bss[i];
2718 if (!hapd)
2719 continue;
2720 if (hapd_iface->interfaces &&
2721 hapd_iface->interfaces->ctrl_iface_deinit)
2722 hapd_iface->interfaces->
2723 ctrl_iface_deinit(hapd);
2724 wpa_printf(MSG_DEBUG, "%s: free hapd %p (%s)",
2725 __func__, hapd_iface->bss[i],
2726 hapd->conf->iface);
2727 hostapd_cleanup(hapd);
2728 os_free(hapd);
2729 hapd_iface->bss[i] = NULL;
2730 }
2731 os_free(hapd_iface->bss);
2732 hapd_iface->bss = NULL;
2733 }
2734 if (new_iface) {
2735 interfaces->count--;
2736 interfaces->iface[interfaces->count] = NULL;
2737 }
2738 hostapd_cleanup_iface(hapd_iface);
2739 }
2740 return -1;
2741 }
2742
2743
2744 static int hostapd_remove_bss(struct hostapd_iface *iface, unsigned int idx)
2745 {
2746 size_t i;
2747
2748 wpa_printf(MSG_INFO, "Remove BSS '%s'", iface->conf->bss[idx]->iface);
2749
2750 /* Remove hostapd_data only if it has already been initialized */
2751 if (idx < iface->num_bss) {
2752 struct hostapd_data *hapd = iface->bss[idx];
2753
2754 hostapd_bss_deinit(hapd);
2755 wpa_printf(MSG_DEBUG, "%s: free hapd %p (%s)",
2756 __func__, hapd, hapd->conf->iface);
2757 hostapd_config_free_bss(hapd->conf);
2758 hapd->conf = NULL;
2759 os_free(hapd);
2760
2761 iface->num_bss--;
2762
2763 for (i = idx; i < iface->num_bss; i++)
2764 iface->bss[i] = iface->bss[i + 1];
2765 } else {
2766 hostapd_config_free_bss(iface->conf->bss[idx]);
2767 iface->conf->bss[idx] = NULL;
2768 }
2769
2770 iface->conf->num_bss--;
2771 for (i = idx; i < iface->conf->num_bss; i++)
2772 iface->conf->bss[i] = iface->conf->bss[i + 1];
2773
2774 return 0;
2775 }
2776
2777
2778 int hostapd_remove_iface(struct hapd_interfaces *interfaces, char *buf)
2779 {
2780 struct hostapd_iface *hapd_iface;
2781 size_t i, j, k = 0;
2782
2783 for (i = 0; i < interfaces->count; i++) {
2784 hapd_iface = interfaces->iface[i];
2785 if (hapd_iface == NULL)
2786 return -1;
2787 if (!os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
2788 wpa_printf(MSG_INFO, "Remove interface '%s'", buf);
2789 hapd_iface->driver_ap_teardown =
2790 !!(hapd_iface->drv_flags &
2791 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
2792
2793 hostapd_interface_deinit_free(hapd_iface);
2794 k = i;
2795 while (k < (interfaces->count - 1)) {
2796 interfaces->iface[k] =
2797 interfaces->iface[k + 1];
2798 k++;
2799 }
2800 interfaces->count--;
2801 return 0;
2802 }
2803
2804 for (j = 0; j < hapd_iface->conf->num_bss; j++) {
2805 if (!os_strcmp(hapd_iface->conf->bss[j]->iface, buf)) {
2806 hapd_iface->driver_ap_teardown =
2807 !(hapd_iface->drv_flags &
2808 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
2809 return hostapd_remove_bss(hapd_iface, j);
2810 }
2811 }
2812 }
2813 return -1;
2814 }
2815
2816
2817 /**
2818 * hostapd_new_assoc_sta - Notify that a new station associated with the AP
2819 * @hapd: Pointer to BSS data
2820 * @sta: Pointer to the associated STA data
2821 * @reassoc: 1 to indicate this was a re-association; 0 = first association
2822 *
2823 * This function will be called whenever a station associates with the AP. It
2824 * can be called from ieee802_11.c for drivers that export MLME to hostapd and
2825 * from drv_callbacks.c based on driver events for drivers that take care of
2826 * management frames (IEEE 802.11 authentication and association) internally.
2827 */
2828 void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
2829 int reassoc)
2830 {
2831 if (hapd->tkip_countermeasures) {
2832 hostapd_drv_sta_deauth(hapd, sta->addr,
2833 WLAN_REASON_MICHAEL_MIC_FAILURE);
2834 return;
2835 }
2836
2837 hostapd_prune_associations(hapd, sta->addr);
2838 ap_sta_clear_disconnect_timeouts(hapd, sta);
2839
2840 /* IEEE 802.11F (IAPP) */
2841 if (hapd->conf->ieee802_11f)
2842 iapp_new_station(hapd->iapp, sta);
2843
2844 #ifdef CONFIG_P2P
2845 if (sta->p2p_ie == NULL && !sta->no_p2p_set) {
2846 sta->no_p2p_set = 1;
2847 hapd->num_sta_no_p2p++;
2848 if (hapd->num_sta_no_p2p == 1)
2849 hostapd_p2p_non_p2p_sta_connected(hapd);
2850 }
2851 #endif /* CONFIG_P2P */
2852
2853 /* Start accounting here, if IEEE 802.1X and WPA are not used.
2854 * IEEE 802.1X/WPA code will start accounting after the station has
2855 * been authorized. */
2856 if (!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) {
2857 ap_sta_set_authorized(hapd, sta, 1);
2858 os_get_reltime(&sta->connected_time);
2859 accounting_sta_start(hapd, sta);
2860 }
2861
2862 /* Start IEEE 802.1X authentication process for new stations */
2863 ieee802_1x_new_station(hapd, sta);
2864 if (reassoc) {
2865 if (sta->auth_alg != WLAN_AUTH_FT &&
2866 !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)))
2867 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH);
2868 } else
2869 wpa_auth_sta_associated(hapd->wpa_auth, sta->wpa_sm);
2870
2871 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_WIRED) {
2872 if (eloop_cancel_timeout(ap_handle_timer, hapd, sta) > 0) {
2873 wpa_printf(MSG_DEBUG,
2874 "%s: %s: canceled wired ap_handle_timer timeout for "
2875 MACSTR,
2876 hapd->conf->iface, __func__,
2877 MAC2STR(sta->addr));
2878 }
2879 } else if (!(hapd->iface->drv_flags &
2880 WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) {
2881 wpa_printf(MSG_DEBUG,
2882 "%s: %s: reschedule ap_handle_timer timeout for "
2883 MACSTR " (%d seconds - ap_max_inactivity)",
2884 hapd->conf->iface, __func__, MAC2STR(sta->addr),
2885 hapd->conf->ap_max_inactivity);
2886 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
2887 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
2888 ap_handle_timer, hapd, sta);
2889 }
2890 }
2891
2892
2893 const char * hostapd_state_text(enum hostapd_iface_state s)
2894 {
2895 switch (s) {
2896 case HAPD_IFACE_UNINITIALIZED:
2897 return "UNINITIALIZED";
2898 case HAPD_IFACE_DISABLED:
2899 return "DISABLED";
2900 case HAPD_IFACE_COUNTRY_UPDATE:
2901 return "COUNTRY_UPDATE";
2902 case HAPD_IFACE_ACS:
2903 return "ACS";
2904 case HAPD_IFACE_HT_SCAN:
2905 return "HT_SCAN";
2906 case HAPD_IFACE_DFS:
2907 return "DFS";
2908 case HAPD_IFACE_ENABLED:
2909 return "ENABLED";
2910 }
2911
2912 return "UNKNOWN";
2913 }
2914
2915
2916 void hostapd_set_state(struct hostapd_iface *iface, enum hostapd_iface_state s)
2917 {
2918 wpa_printf(MSG_INFO, "%s: interface state %s->%s",
2919 iface->conf ? iface->conf->bss[0]->iface : "N/A",
2920 hostapd_state_text(iface->state), hostapd_state_text(s));
2921 iface->state = s;
2922 }
2923
2924
2925 int hostapd_csa_in_progress(struct hostapd_iface *iface)
2926 {
2927 unsigned int i;
2928
2929 for (i = 0; i < iface->num_bss; i++)
2930 if (iface->bss[i]->csa_in_progress)
2931 return 1;
2932 return 0;
2933 }
2934
2935
2936 #ifdef NEED_AP_MLME
2937
2938 static void free_beacon_data(struct beacon_data *beacon)
2939 {
2940 os_free(beacon->head);
2941 beacon->head = NULL;
2942 os_free(beacon->tail);
2943 beacon->tail = NULL;
2944 os_free(beacon->probe_resp);
2945 beacon->probe_resp = NULL;
2946 os_free(beacon->beacon_ies);
2947 beacon->beacon_ies = NULL;
2948 os_free(beacon->proberesp_ies);
2949 beacon->proberesp_ies = NULL;
2950 os_free(beacon->assocresp_ies);
2951 beacon->assocresp_ies = NULL;
2952 }
2953
2954
2955 static int hostapd_build_beacon_data(struct hostapd_data *hapd,
2956 struct beacon_data *beacon)
2957 {
2958 struct wpabuf *beacon_extra, *proberesp_extra, *assocresp_extra;
2959 struct wpa_driver_ap_params params;
2960 int ret;
2961
2962 os_memset(beacon, 0, sizeof(*beacon));
2963 ret = ieee802_11_build_ap_params(hapd, &params);
2964 if (ret < 0)
2965 return ret;
2966
2967 ret = hostapd_build_ap_extra_ies(hapd, &beacon_extra,
2968 &proberesp_extra,
2969 &assocresp_extra);
2970 if (ret)
2971 goto free_ap_params;
2972
2973 ret = -1;
2974 beacon->head = os_memdup(params.head, params.head_len);
2975 if (!beacon->head)
2976 goto free_ap_extra_ies;
2977
2978 beacon->head_len = params.head_len;
2979
2980 beacon->tail = os_memdup(params.tail, params.tail_len);
2981 if (!beacon->tail)
2982 goto free_beacon;
2983
2984 beacon->tail_len = params.tail_len;
2985
2986 if (params.proberesp != NULL) {
2987 beacon->probe_resp = os_memdup(params.proberesp,
2988 params.proberesp_len);
2989 if (!beacon->probe_resp)
2990 goto free_beacon;
2991
2992 beacon->probe_resp_len = params.proberesp_len;
2993 }
2994
2995 /* copy the extra ies */
2996 if (beacon_extra) {
2997 beacon->beacon_ies = os_memdup(beacon_extra->buf,
2998 wpabuf_len(beacon_extra));
2999 if (!beacon->beacon_ies)
3000 goto free_beacon;
3001
3002 beacon->beacon_ies_len = wpabuf_len(beacon_extra);
3003 }
3004
3005 if (proberesp_extra) {
3006 beacon->proberesp_ies = os_memdup(proberesp_extra->buf,
3007 wpabuf_len(proberesp_extra));
3008 if (!beacon->proberesp_ies)
3009 goto free_beacon;
3010
3011 beacon->proberesp_ies_len = wpabuf_len(proberesp_extra);
3012 }
3013
3014 if (assocresp_extra) {
3015 beacon->assocresp_ies = os_memdup(assocresp_extra->buf,
3016 wpabuf_len(assocresp_extra));
3017 if (!beacon->assocresp_ies)
3018 goto free_beacon;
3019
3020 beacon->assocresp_ies_len = wpabuf_len(assocresp_extra);
3021 }
3022
3023 ret = 0;
3024 free_beacon:
3025 /* if the function fails, the caller should not free beacon data */
3026 if (ret)
3027 free_beacon_data(beacon);
3028
3029 free_ap_extra_ies:
3030 hostapd_free_ap_extra_ies(hapd, beacon_extra, proberesp_extra,
3031 assocresp_extra);
3032 free_ap_params:
3033 ieee802_11_free_ap_params(&params);
3034 return ret;
3035 }
3036
3037
3038 /*
3039 * TODO: This flow currently supports only changing channel and width within
3040 * the same hw_mode. Any other changes to MAC parameters or provided settings
3041 * are not supported.
3042 */
3043 static int hostapd_change_config_freq(struct hostapd_data *hapd,
3044 struct hostapd_config *conf,
3045 struct hostapd_freq_params *params,
3046 struct hostapd_freq_params *old_params)
3047 {
3048 int channel;
3049
3050 if (!params->channel) {
3051 /* check if the new channel is supported by hw */
3052 params->channel = hostapd_hw_get_channel(hapd, params->freq);
3053 }
3054
3055 channel = params->channel;
3056 if (!channel)
3057 return -1;
3058
3059 /* if a pointer to old_params is provided we save previous state */
3060 if (old_params &&
3061 hostapd_set_freq_params(old_params, conf->hw_mode,
3062 hostapd_hw_get_freq(hapd, conf->channel),
3063 conf->channel, conf->ieee80211n,
3064 conf->ieee80211ac,
3065 conf->secondary_channel,
3066 conf->vht_oper_chwidth,
3067 conf->vht_oper_centr_freq_seg0_idx,
3068 conf->vht_oper_centr_freq_seg1_idx,
3069 conf->vht_capab))
3070 return -1;
3071
3072 switch (params->bandwidth) {
3073 case 0:
3074 case 20:
3075 case 40:
3076 conf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT;
3077 break;
3078 case 80:
3079 if (params->center_freq2)
3080 conf->vht_oper_chwidth = VHT_CHANWIDTH_80P80MHZ;
3081 else
3082 conf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ;
3083 break;
3084 case 160:
3085 conf->vht_oper_chwidth = VHT_CHANWIDTH_160MHZ;
3086 break;
3087 default:
3088 return -1;
3089 }
3090
3091 conf->channel = channel;
3092 conf->ieee80211n = params->ht_enabled;
3093 conf->secondary_channel = params->sec_channel_offset;
3094 ieee80211_freq_to_chan(params->center_freq1,
3095 &conf->vht_oper_centr_freq_seg0_idx);
3096 ieee80211_freq_to_chan(params->center_freq2,
3097 &conf->vht_oper_centr_freq_seg1_idx);
3098
3099 /* TODO: maybe call here hostapd_config_check here? */
3100
3101 return 0;
3102 }
3103
3104
3105 static int hostapd_fill_csa_settings(struct hostapd_data *hapd,
3106 struct csa_settings *settings)
3107 {
3108 struct hostapd_iface *iface = hapd->iface;
3109 struct hostapd_freq_params old_freq;
3110 int ret;
3111 u8 chan, vht_bandwidth;
3112
3113 os_memset(&old_freq, 0, sizeof(old_freq));
3114 if (!iface || !iface->freq || hapd->csa_in_progress)
3115 return -1;
3116
3117 switch (settings->freq_params.bandwidth) {
3118 case 80:
3119 if (settings->freq_params.center_freq2)
3120 vht_bandwidth = VHT_CHANWIDTH_80P80MHZ;
3121 else
3122 vht_bandwidth = VHT_CHANWIDTH_80MHZ;
3123 break;
3124 case 160:
3125 vht_bandwidth = VHT_CHANWIDTH_160MHZ;
3126 break;
3127 default:
3128 vht_bandwidth = VHT_CHANWIDTH_USE_HT;
3129 break;
3130 }
3131
3132 if (ieee80211_freq_to_channel_ext(
3133 settings->freq_params.freq,
3134 settings->freq_params.sec_channel_offset,
3135 vht_bandwidth,
3136 &hapd->iface->cs_oper_class,
3137 &chan) == NUM_HOSTAPD_MODES) {
3138 wpa_printf(MSG_DEBUG,
3139 "invalid frequency for channel switch (freq=%d, sec_channel_offset=%d, vht_enabled=%d)",
3140 settings->freq_params.freq,
3141 settings->freq_params.sec_channel_offset,
3142 settings->freq_params.vht_enabled);
3143 return -1;
3144 }
3145
3146 settings->freq_params.channel = chan;
3147
3148 ret = hostapd_change_config_freq(iface->bss[0], iface->conf,
3149 &settings->freq_params,
3150 &old_freq);
3151 if (ret)
3152 return ret;
3153
3154 ret = hostapd_build_beacon_data(hapd, &settings->beacon_after);
3155
3156 /* change back the configuration */
3157 hostapd_change_config_freq(iface->bss[0], iface->conf,
3158 &old_freq, NULL);
3159
3160 if (ret)
3161 return ret;
3162
3163 /* set channel switch parameters for csa ie */
3164 hapd->cs_freq_params = settings->freq_params;
3165 hapd->cs_count = settings->cs_count;
3166 hapd->cs_block_tx = settings->block_tx;
3167
3168 ret = hostapd_build_beacon_data(hapd, &settings->beacon_csa);
3169 if (ret) {
3170 free_beacon_data(&settings->beacon_after);
3171 return ret;
3172 }
3173
3174 settings->counter_offset_beacon[0] = hapd->cs_c_off_beacon;
3175 settings->counter_offset_presp[0] = hapd->cs_c_off_proberesp;
3176 settings->counter_offset_beacon[1] = hapd->cs_c_off_ecsa_beacon;
3177 settings->counter_offset_presp[1] = hapd->cs_c_off_ecsa_proberesp;
3178
3179 return 0;
3180 }
3181
3182
3183 void hostapd_cleanup_cs_params(struct hostapd_data *hapd)
3184 {
3185 os_memset(&hapd->cs_freq_params, 0, sizeof(hapd->cs_freq_params));
3186 hapd->cs_count = 0;
3187 hapd->cs_block_tx = 0;
3188 hapd->cs_c_off_beacon = 0;
3189 hapd->cs_c_off_proberesp = 0;
3190 hapd->csa_in_progress = 0;
3191 hapd->cs_c_off_ecsa_beacon = 0;
3192 hapd->cs_c_off_ecsa_proberesp = 0;
3193 }
3194
3195
3196 int hostapd_switch_channel(struct hostapd_data *hapd,
3197 struct csa_settings *settings)
3198 {
3199 int ret;
3200
3201 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA)) {
3202 wpa_printf(MSG_INFO, "CSA is not supported");
3203 return -1;
3204 }
3205
3206 ret = hostapd_fill_csa_settings(hapd, settings);
3207 if (ret)
3208 return ret;
3209
3210 ret = hostapd_drv_switch_channel(hapd, settings);
3211 free_beacon_data(&settings->beacon_csa);
3212 free_beacon_data(&settings->beacon_after);
3213
3214 if (ret) {
3215 /* if we failed, clean cs parameters */
3216 hostapd_cleanup_cs_params(hapd);
3217 return ret;
3218 }
3219
3220 hapd->csa_in_progress = 1;
3221 return 0;
3222 }
3223
3224
3225 void
3226 hostapd_switch_channel_fallback(struct hostapd_iface *iface,
3227 const struct hostapd_freq_params *freq_params)
3228 {
3229 int vht_seg0_idx = 0, vht_seg1_idx = 0, vht_bw = VHT_CHANWIDTH_USE_HT;
3230 unsigned int i;
3231
3232 wpa_printf(MSG_DEBUG, "Restarting all CSA-related BSSes");
3233
3234 if (freq_params->center_freq1)
3235 vht_seg0_idx = 36 + (freq_params->center_freq1 - 5180) / 5;
3236 if (freq_params->center_freq2)
3237 vht_seg1_idx = 36 + (freq_params->center_freq2 - 5180) / 5;
3238
3239 switch (freq_params->bandwidth) {
3240 case 0:
3241 case 20:
3242 case 40:
3243 vht_bw = VHT_CHANWIDTH_USE_HT;
3244 break;
3245 case 80:
3246 if (freq_params->center_freq2)
3247 vht_bw = VHT_CHANWIDTH_80P80MHZ;
3248 else
3249 vht_bw = VHT_CHANWIDTH_80MHZ;
3250 break;
3251 case 160:
3252 vht_bw = VHT_CHANWIDTH_160MHZ;
3253 break;
3254 default:
3255 wpa_printf(MSG_WARNING, "Unknown CSA bandwidth: %d",
3256 freq_params->bandwidth);
3257 break;
3258 }
3259
3260 iface->freq = freq_params->freq;
3261 iface->conf->channel = freq_params->channel;
3262 iface->conf->secondary_channel = freq_params->sec_channel_offset;
3263 iface->conf->vht_oper_centr_freq_seg0_idx = vht_seg0_idx;
3264 iface->conf->vht_oper_centr_freq_seg1_idx = vht_seg1_idx;
3265 iface->conf->vht_oper_chwidth = vht_bw;
3266 iface->conf->ieee80211n = freq_params->ht_enabled;
3267 iface->conf->ieee80211ac = freq_params->vht_enabled;
3268
3269 /*
3270 * cs_params must not be cleared earlier because the freq_params
3271 * argument may actually point to one of these.
3272 */
3273 for (i = 0; i < iface->num_bss; i++)
3274 hostapd_cleanup_cs_params(iface->bss[i]);
3275
3276 hostapd_disable_iface(iface);
3277 hostapd_enable_iface(iface);
3278 }
3279
3280 #endif /* NEED_AP_MLME */
3281
3282
3283 struct hostapd_data * hostapd_get_iface(struct hapd_interfaces *interfaces,
3284 const char *ifname)
3285 {
3286 size_t i, j;
3287
3288 for (i = 0; i < interfaces->count; i++) {
3289 struct hostapd_iface *iface = interfaces->iface[i];
3290
3291 for (j = 0; j < iface->num_bss; j++) {
3292 struct hostapd_data *hapd = iface->bss[j];
3293
3294 if (os_strcmp(ifname, hapd->conf->iface) == 0)
3295 return hapd;
3296 }
3297 }
3298
3299 return NULL;
3300 }
3301
3302
3303 void hostapd_periodic_iface(struct hostapd_iface *iface)
3304 {
3305 size_t i;
3306
3307 ap_list_timer(iface);
3308
3309 for (i = 0; i < iface->num_bss; i++) {
3310 struct hostapd_data *hapd = iface->bss[i];
3311
3312 if (!hapd->started)
3313 continue;
3314
3315 #ifndef CONFIG_NO_RADIUS
3316 hostapd_acl_expire(hapd);
3317 #endif /* CONFIG_NO_RADIUS */
3318 }
3319 }