]> git.ipfire.org Git - thirdparty/hostap.git/blob - src/ap/hostapd.c
FT: Replace inter-AP protocol with use of OUI Extended Ethertype
[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 "hw_features.h"
35 #include "wpa_auth_glue.h"
36 #include "ap_drv_ops.h"
37 #include "ap_config.h"
38 #include "p2p_hostapd.h"
39 #include "gas_serv.h"
40 #include "dfs.h"
41 #include "ieee802_11.h"
42 #include "bss_load.h"
43 #include "x_snoop.h"
44 #include "dhcp_snoop.h"
45 #include "ndisc_snoop.h"
46 #include "neighbor_db.h"
47 #include "rrm.h"
48 #include "fils_hlp.h"
49 #include "acs.h"
50
51
52 static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason);
53 static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd);
54 static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd);
55 static int setup_interface2(struct hostapd_iface *iface);
56 static void channel_list_update_timeout(void *eloop_ctx, void *timeout_ctx);
57
58
59 int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
60 int (*cb)(struct hostapd_iface *iface,
61 void *ctx), void *ctx)
62 {
63 size_t i;
64 int ret;
65
66 for (i = 0; i < interfaces->count; i++) {
67 ret = cb(interfaces->iface[i], ctx);
68 if (ret)
69 return ret;
70 }
71
72 return 0;
73 }
74
75
76 static void hostapd_reload_bss(struct hostapd_data *hapd)
77 {
78 struct hostapd_ssid *ssid;
79
80 if (!hapd->started)
81 return;
82
83 #ifndef CONFIG_NO_RADIUS
84 radius_client_reconfig(hapd->radius, hapd->conf->radius);
85 #endif /* CONFIG_NO_RADIUS */
86
87 ssid = &hapd->conf->ssid;
88 if (!ssid->wpa_psk_set && ssid->wpa_psk && !ssid->wpa_psk->next &&
89 ssid->wpa_passphrase_set && ssid->wpa_passphrase) {
90 /*
91 * Force PSK to be derived again since SSID or passphrase may
92 * have changed.
93 */
94 hostapd_config_clear_wpa_psk(&hapd->conf->ssid.wpa_psk);
95 }
96 if (hostapd_setup_wpa_psk(hapd->conf)) {
97 wpa_printf(MSG_ERROR, "Failed to re-configure WPA PSK "
98 "after reloading configuration");
99 }
100
101 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
102 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1);
103 else
104 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0);
105
106 if ((hapd->conf->wpa || hapd->conf->osen) && hapd->wpa_auth == NULL) {
107 hostapd_setup_wpa(hapd);
108 if (hapd->wpa_auth)
109 wpa_init_keys(hapd->wpa_auth);
110 } else if (hapd->conf->wpa) {
111 const u8 *wpa_ie;
112 size_t wpa_ie_len;
113 hostapd_reconfig_wpa(hapd);
114 wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
115 if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len))
116 wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
117 "the kernel driver.");
118 } else if (hapd->wpa_auth) {
119 wpa_deinit(hapd->wpa_auth);
120 hapd->wpa_auth = NULL;
121 hostapd_set_privacy(hapd, 0);
122 hostapd_setup_encryption(hapd->conf->iface, hapd);
123 hostapd_set_generic_elem(hapd, (u8 *) "", 0);
124 }
125
126 ieee802_11_set_beacon(hapd);
127 hostapd_update_wps(hapd);
128
129 if (hapd->conf->ssid.ssid_set &&
130 hostapd_set_ssid(hapd, hapd->conf->ssid.ssid,
131 hapd->conf->ssid.ssid_len)) {
132 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
133 /* try to continue */
134 }
135 wpa_printf(MSG_DEBUG, "Reconfigured interface %s", hapd->conf->iface);
136 }
137
138
139 static void hostapd_clear_old(struct hostapd_iface *iface)
140 {
141 size_t j;
142
143 /*
144 * Deauthenticate all stations since the new configuration may not
145 * allow them to use the BSS anymore.
146 */
147 for (j = 0; j < iface->num_bss; j++) {
148 hostapd_flush_old_stations(iface->bss[j],
149 WLAN_REASON_PREV_AUTH_NOT_VALID);
150 hostapd_broadcast_wep_clear(iface->bss[j]);
151
152 #ifndef CONFIG_NO_RADIUS
153 /* TODO: update dynamic data based on changed configuration
154 * items (e.g., open/close sockets, etc.) */
155 radius_client_flush(iface->bss[j]->radius, 0);
156 #endif /* CONFIG_NO_RADIUS */
157 }
158 }
159
160
161 int hostapd_reload_config(struct hostapd_iface *iface)
162 {
163 struct hostapd_data *hapd = iface->bss[0];
164 struct hostapd_config *newconf, *oldconf;
165 size_t j;
166
167 if (iface->config_fname == NULL) {
168 /* Only in-memory config in use - assume it has been updated */
169 hostapd_clear_old(iface);
170 for (j = 0; j < iface->num_bss; j++)
171 hostapd_reload_bss(iface->bss[j]);
172 return 0;
173 }
174
175 if (iface->interfaces == NULL ||
176 iface->interfaces->config_read_cb == NULL)
177 return -1;
178 newconf = iface->interfaces->config_read_cb(iface->config_fname);
179 if (newconf == NULL)
180 return -1;
181
182 hostapd_clear_old(iface);
183
184 oldconf = hapd->iconf;
185 iface->conf = newconf;
186
187 for (j = 0; j < iface->num_bss; j++) {
188 hapd = iface->bss[j];
189 hapd->iconf = newconf;
190 hapd->iconf->channel = oldconf->channel;
191 hapd->iconf->acs = oldconf->acs;
192 hapd->iconf->secondary_channel = oldconf->secondary_channel;
193 hapd->iconf->ieee80211n = oldconf->ieee80211n;
194 hapd->iconf->ieee80211ac = oldconf->ieee80211ac;
195 hapd->iconf->ht_capab = oldconf->ht_capab;
196 hapd->iconf->vht_capab = oldconf->vht_capab;
197 hapd->iconf->vht_oper_chwidth = oldconf->vht_oper_chwidth;
198 hapd->iconf->vht_oper_centr_freq_seg0_idx =
199 oldconf->vht_oper_centr_freq_seg0_idx;
200 hapd->iconf->vht_oper_centr_freq_seg1_idx =
201 oldconf->vht_oper_centr_freq_seg1_idx;
202 hapd->conf = newconf->bss[j];
203 hostapd_reload_bss(hapd);
204 }
205
206 hostapd_config_free(oldconf);
207
208
209 return 0;
210 }
211
212
213 static void hostapd_broadcast_key_clear_iface(struct hostapd_data *hapd,
214 const char *ifname)
215 {
216 int i;
217
218 if (!ifname || !hapd->drv_priv)
219 return;
220 for (i = 0; i < NUM_WEP_KEYS; i++) {
221 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE, NULL, i,
222 0, NULL, 0, NULL, 0)) {
223 wpa_printf(MSG_DEBUG, "Failed to clear default "
224 "encryption keys (ifname=%s keyidx=%d)",
225 ifname, i);
226 }
227 }
228 #ifdef CONFIG_IEEE80211W
229 if (hapd->conf->ieee80211w) {
230 for (i = NUM_WEP_KEYS; i < NUM_WEP_KEYS + 2; i++) {
231 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE,
232 NULL, i, 0, NULL,
233 0, NULL, 0)) {
234 wpa_printf(MSG_DEBUG, "Failed to clear "
235 "default mgmt encryption keys "
236 "(ifname=%s keyidx=%d)", ifname, i);
237 }
238 }
239 }
240 #endif /* CONFIG_IEEE80211W */
241 }
242
243
244 static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd)
245 {
246 hostapd_broadcast_key_clear_iface(hapd, hapd->conf->iface);
247 return 0;
248 }
249
250
251 static int hostapd_broadcast_wep_set(struct hostapd_data *hapd)
252 {
253 int errors = 0, idx;
254 struct hostapd_ssid *ssid = &hapd->conf->ssid;
255
256 idx = ssid->wep.idx;
257 if (ssid->wep.default_len &&
258 hostapd_drv_set_key(hapd->conf->iface,
259 hapd, WPA_ALG_WEP, broadcast_ether_addr, idx,
260 1, NULL, 0, ssid->wep.key[idx],
261 ssid->wep.len[idx])) {
262 wpa_printf(MSG_WARNING, "Could not set WEP encryption.");
263 errors++;
264 }
265
266 return errors;
267 }
268
269
270 static void hostapd_free_hapd_data(struct hostapd_data *hapd)
271 {
272 os_free(hapd->probereq_cb);
273 hapd->probereq_cb = NULL;
274 hapd->num_probereq_cb = 0;
275
276 #ifdef CONFIG_P2P
277 wpabuf_free(hapd->p2p_beacon_ie);
278 hapd->p2p_beacon_ie = NULL;
279 wpabuf_free(hapd->p2p_probe_resp_ie);
280 hapd->p2p_probe_resp_ie = NULL;
281 #endif /* CONFIG_P2P */
282
283 if (!hapd->started) {
284 wpa_printf(MSG_ERROR, "%s: Interface %s wasn't started",
285 __func__, hapd->conf->iface);
286 return;
287 }
288 hapd->started = 0;
289
290 wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
291 iapp_deinit(hapd->iapp);
292 hapd->iapp = NULL;
293 accounting_deinit(hapd);
294 hostapd_deinit_wpa(hapd);
295 vlan_deinit(hapd);
296 hostapd_acl_deinit(hapd);
297 #ifndef CONFIG_NO_RADIUS
298 radius_client_deinit(hapd->radius);
299 hapd->radius = NULL;
300 radius_das_deinit(hapd->radius_das);
301 hapd->radius_das = NULL;
302 #endif /* CONFIG_NO_RADIUS */
303
304 hostapd_deinit_wps(hapd);
305
306 authsrv_deinit(hapd);
307
308 if (hapd->interface_added) {
309 hapd->interface_added = 0;
310 if (hostapd_if_remove(hapd, WPA_IF_AP_BSS, hapd->conf->iface)) {
311 wpa_printf(MSG_WARNING,
312 "Failed to remove BSS interface %s",
313 hapd->conf->iface);
314 hapd->interface_added = 1;
315 } else {
316 /*
317 * Since this was a dynamically added interface, the
318 * driver wrapper may have removed its internal instance
319 * and hapd->drv_priv is not valid anymore.
320 */
321 hapd->drv_priv = NULL;
322 }
323 }
324
325 wpabuf_free(hapd->time_adv);
326
327 #ifdef CONFIG_INTERWORKING
328 gas_serv_deinit(hapd);
329 #endif /* CONFIG_INTERWORKING */
330
331 bss_load_update_deinit(hapd);
332 ndisc_snoop_deinit(hapd);
333 dhcp_snoop_deinit(hapd);
334 x_snoop_deinit(hapd);
335
336 #ifdef CONFIG_SQLITE
337 bin_clear_free(hapd->tmp_eap_user.identity,
338 hapd->tmp_eap_user.identity_len);
339 bin_clear_free(hapd->tmp_eap_user.password,
340 hapd->tmp_eap_user.password_len);
341 #endif /* CONFIG_SQLITE */
342
343 #ifdef CONFIG_MESH
344 wpabuf_free(hapd->mesh_pending_auth);
345 hapd->mesh_pending_auth = NULL;
346 #endif /* CONFIG_MESH */
347
348 hostapd_clean_rrm(hapd);
349 fils_hlp_deinit(hapd);
350 }
351
352
353 /**
354 * hostapd_cleanup - Per-BSS cleanup (deinitialization)
355 * @hapd: Pointer to BSS data
356 *
357 * This function is used to free all per-BSS data structures and resources.
358 * Most of the modules that are initialized in hostapd_setup_bss() are
359 * deinitialized here.
360 */
361 static void hostapd_cleanup(struct hostapd_data *hapd)
362 {
363 wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s))", __func__, hapd,
364 hapd->conf->iface);
365 if (hapd->iface->interfaces &&
366 hapd->iface->interfaces->ctrl_iface_deinit) {
367 wpa_msg(hapd->msg_ctx, MSG_INFO, WPA_EVENT_TERMINATING);
368 hapd->iface->interfaces->ctrl_iface_deinit(hapd);
369 }
370 hostapd_free_hapd_data(hapd);
371 }
372
373
374 static void sta_track_deinit(struct hostapd_iface *iface)
375 {
376 struct hostapd_sta_info *info;
377
378 if (!iface->num_sta_seen)
379 return;
380
381 while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
382 list))) {
383 dl_list_del(&info->list);
384 iface->num_sta_seen--;
385 sta_track_del(info);
386 }
387 }
388
389
390 static void hostapd_cleanup_iface_partial(struct hostapd_iface *iface)
391 {
392 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
393 #ifdef CONFIG_IEEE80211N
394 #ifdef NEED_AP_MLME
395 hostapd_stop_setup_timers(iface);
396 #endif /* NEED_AP_MLME */
397 #endif /* CONFIG_IEEE80211N */
398 if (iface->current_mode)
399 acs_cleanup(iface);
400 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
401 iface->hw_features = NULL;
402 iface->current_mode = NULL;
403 os_free(iface->current_rates);
404 iface->current_rates = NULL;
405 os_free(iface->basic_rates);
406 iface->basic_rates = NULL;
407 ap_list_deinit(iface);
408 sta_track_deinit(iface);
409 }
410
411
412 /**
413 * hostapd_cleanup_iface - Complete per-interface cleanup
414 * @iface: Pointer to interface data
415 *
416 * This function is called after per-BSS data structures are deinitialized
417 * with hostapd_cleanup().
418 */
419 static void hostapd_cleanup_iface(struct hostapd_iface *iface)
420 {
421 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
422 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
423
424 hostapd_cleanup_iface_partial(iface);
425 hostapd_config_free(iface->conf);
426 iface->conf = NULL;
427
428 os_free(iface->config_fname);
429 os_free(iface->bss);
430 wpa_printf(MSG_DEBUG, "%s: free iface=%p", __func__, iface);
431 os_free(iface);
432 }
433
434
435 static void hostapd_clear_wep(struct hostapd_data *hapd)
436 {
437 if (hapd->drv_priv && !hapd->iface->driver_ap_teardown) {
438 hostapd_set_privacy(hapd, 0);
439 hostapd_broadcast_wep_clear(hapd);
440 }
441 }
442
443
444 static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd)
445 {
446 int i;
447
448 hostapd_broadcast_wep_set(hapd);
449
450 if (hapd->conf->ssid.wep.default_len) {
451 hostapd_set_privacy(hapd, 1);
452 return 0;
453 }
454
455 /*
456 * When IEEE 802.1X is not enabled, the driver may need to know how to
457 * set authentication algorithms for static WEP.
458 */
459 hostapd_drv_set_authmode(hapd, hapd->conf->auth_algs);
460
461 for (i = 0; i < 4; i++) {
462 if (hapd->conf->ssid.wep.key[i] &&
463 hostapd_drv_set_key(iface, hapd, WPA_ALG_WEP, NULL, i,
464 i == hapd->conf->ssid.wep.idx, NULL, 0,
465 hapd->conf->ssid.wep.key[i],
466 hapd->conf->ssid.wep.len[i])) {
467 wpa_printf(MSG_WARNING, "Could not set WEP "
468 "encryption.");
469 return -1;
470 }
471 if (hapd->conf->ssid.wep.key[i] &&
472 i == hapd->conf->ssid.wep.idx)
473 hostapd_set_privacy(hapd, 1);
474 }
475
476 return 0;
477 }
478
479
480 static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason)
481 {
482 int ret = 0;
483 u8 addr[ETH_ALEN];
484
485 if (hostapd_drv_none(hapd) || hapd->drv_priv == NULL)
486 return 0;
487
488 if (!hapd->iface->driver_ap_teardown) {
489 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
490 "Flushing old station entries");
491
492 if (hostapd_flush(hapd)) {
493 wpa_msg(hapd->msg_ctx, MSG_WARNING,
494 "Could not connect to kernel driver");
495 ret = -1;
496 }
497 }
498 if (hapd->conf && hapd->conf->broadcast_deauth) {
499 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
500 "Deauthenticate all stations");
501 os_memset(addr, 0xff, ETH_ALEN);
502 hostapd_drv_sta_deauth(hapd, addr, reason);
503 }
504 hostapd_free_stas(hapd);
505
506 return ret;
507 }
508
509
510 static void hostapd_bss_deinit_no_free(struct hostapd_data *hapd)
511 {
512 hostapd_free_stas(hapd);
513 hostapd_flush_old_stations(hapd, WLAN_REASON_DEAUTH_LEAVING);
514 hostapd_clear_wep(hapd);
515 }
516
517
518 /**
519 * hostapd_validate_bssid_configuration - Validate BSSID configuration
520 * @iface: Pointer to interface data
521 * Returns: 0 on success, -1 on failure
522 *
523 * This function is used to validate that the configured BSSIDs are valid.
524 */
525 static int hostapd_validate_bssid_configuration(struct hostapd_iface *iface)
526 {
527 u8 mask[ETH_ALEN] = { 0 };
528 struct hostapd_data *hapd = iface->bss[0];
529 unsigned int i = iface->conf->num_bss, bits = 0, j;
530 int auto_addr = 0;
531
532 if (hostapd_drv_none(hapd))
533 return 0;
534
535 if (iface->conf->use_driver_iface_addr)
536 return 0;
537
538 /* Generate BSSID mask that is large enough to cover the BSSIDs. */
539
540 /* Determine the bits necessary to cover the number of BSSIDs. */
541 for (i--; i; i >>= 1)
542 bits++;
543
544 /* Determine the bits necessary to any configured BSSIDs,
545 if they are higher than the number of BSSIDs. */
546 for (j = 0; j < iface->conf->num_bss; j++) {
547 if (is_zero_ether_addr(iface->conf->bss[j]->bssid)) {
548 if (j)
549 auto_addr++;
550 continue;
551 }
552
553 for (i = 0; i < ETH_ALEN; i++) {
554 mask[i] |=
555 iface->conf->bss[j]->bssid[i] ^
556 hapd->own_addr[i];
557 }
558 }
559
560 if (!auto_addr)
561 goto skip_mask_ext;
562
563 for (i = 0; i < ETH_ALEN && mask[i] == 0; i++)
564 ;
565 j = 0;
566 if (i < ETH_ALEN) {
567 j = (5 - i) * 8;
568
569 while (mask[i] != 0) {
570 mask[i] >>= 1;
571 j++;
572 }
573 }
574
575 if (bits < j)
576 bits = j;
577
578 if (bits > 40) {
579 wpa_printf(MSG_ERROR, "Too many bits in the BSSID mask (%u)",
580 bits);
581 return -1;
582 }
583
584 os_memset(mask, 0xff, ETH_ALEN);
585 j = bits / 8;
586 for (i = 5; i > 5 - j; i--)
587 mask[i] = 0;
588 j = bits % 8;
589 while (j--)
590 mask[i] <<= 1;
591
592 skip_mask_ext:
593 wpa_printf(MSG_DEBUG, "BSS count %lu, BSSID mask " MACSTR " (%d bits)",
594 (unsigned long) iface->conf->num_bss, MAC2STR(mask), bits);
595
596 if (!auto_addr)
597 return 0;
598
599 for (i = 0; i < ETH_ALEN; i++) {
600 if ((hapd->own_addr[i] & mask[i]) != hapd->own_addr[i]) {
601 wpa_printf(MSG_ERROR, "Invalid BSSID mask " MACSTR
602 " for start address " MACSTR ".",
603 MAC2STR(mask), MAC2STR(hapd->own_addr));
604 wpa_printf(MSG_ERROR, "Start address must be the "
605 "first address in the block (i.e., addr "
606 "AND mask == addr).");
607 return -1;
608 }
609 }
610
611 return 0;
612 }
613
614
615 static int mac_in_conf(struct hostapd_config *conf, const void *a)
616 {
617 size_t i;
618
619 for (i = 0; i < conf->num_bss; i++) {
620 if (hostapd_mac_comp(conf->bss[i]->bssid, a) == 0) {
621 return 1;
622 }
623 }
624
625 return 0;
626 }
627
628
629 #ifndef CONFIG_NO_RADIUS
630
631 static int hostapd_das_nas_mismatch(struct hostapd_data *hapd,
632 struct radius_das_attrs *attr)
633 {
634 if (attr->nas_identifier &&
635 (!hapd->conf->nas_identifier ||
636 os_strlen(hapd->conf->nas_identifier) !=
637 attr->nas_identifier_len ||
638 os_memcmp(hapd->conf->nas_identifier, attr->nas_identifier,
639 attr->nas_identifier_len) != 0)) {
640 wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-Identifier mismatch");
641 return 1;
642 }
643
644 if (attr->nas_ip_addr &&
645 (hapd->conf->own_ip_addr.af != AF_INET ||
646 os_memcmp(&hapd->conf->own_ip_addr.u.v4, attr->nas_ip_addr, 4) !=
647 0)) {
648 wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-IP-Address mismatch");
649 return 1;
650 }
651
652 #ifdef CONFIG_IPV6
653 if (attr->nas_ipv6_addr &&
654 (hapd->conf->own_ip_addr.af != AF_INET6 ||
655 os_memcmp(&hapd->conf->own_ip_addr.u.v6, attr->nas_ipv6_addr, 16)
656 != 0)) {
657 wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-IPv6-Address mismatch");
658 return 1;
659 }
660 #endif /* CONFIG_IPV6 */
661
662 return 0;
663 }
664
665
666 static struct sta_info * hostapd_das_find_sta(struct hostapd_data *hapd,
667 struct radius_das_attrs *attr,
668 int *multi)
669 {
670 struct sta_info *selected, *sta;
671 char buf[128];
672 int num_attr = 0;
673 int count;
674
675 *multi = 0;
676
677 for (sta = hapd->sta_list; sta; sta = sta->next)
678 sta->radius_das_match = 1;
679
680 if (attr->sta_addr) {
681 num_attr++;
682 sta = ap_get_sta(hapd, attr->sta_addr);
683 if (!sta) {
684 wpa_printf(MSG_DEBUG,
685 "RADIUS DAS: No Calling-Station-Id match");
686 return NULL;
687 }
688
689 selected = sta;
690 for (sta = hapd->sta_list; sta; sta = sta->next) {
691 if (sta != selected)
692 sta->radius_das_match = 0;
693 }
694 wpa_printf(MSG_DEBUG, "RADIUS DAS: Calling-Station-Id match");
695 }
696
697 if (attr->acct_session_id) {
698 num_attr++;
699 if (attr->acct_session_id_len != 16) {
700 wpa_printf(MSG_DEBUG,
701 "RADIUS DAS: Acct-Session-Id cannot match");
702 return NULL;
703 }
704 count = 0;
705
706 for (sta = hapd->sta_list; sta; sta = sta->next) {
707 if (!sta->radius_das_match)
708 continue;
709 os_snprintf(buf, sizeof(buf), "%016llX",
710 (unsigned long long) sta->acct_session_id);
711 if (os_memcmp(attr->acct_session_id, buf, 16) != 0)
712 sta->radius_das_match = 0;
713 else
714 count++;
715 }
716
717 if (count == 0) {
718 wpa_printf(MSG_DEBUG,
719 "RADIUS DAS: No matches remaining after Acct-Session-Id check");
720 return NULL;
721 }
722 wpa_printf(MSG_DEBUG, "RADIUS DAS: Acct-Session-Id match");
723 }
724
725 if (attr->acct_multi_session_id) {
726 num_attr++;
727 if (attr->acct_multi_session_id_len != 16) {
728 wpa_printf(MSG_DEBUG,
729 "RADIUS DAS: Acct-Multi-Session-Id cannot match");
730 return NULL;
731 }
732 count = 0;
733
734 for (sta = hapd->sta_list; sta; sta = sta->next) {
735 if (!sta->radius_das_match)
736 continue;
737 if (!sta->eapol_sm ||
738 !sta->eapol_sm->acct_multi_session_id) {
739 sta->radius_das_match = 0;
740 continue;
741 }
742 os_snprintf(buf, sizeof(buf), "%016llX",
743 (unsigned long long)
744 sta->eapol_sm->acct_multi_session_id);
745 if (os_memcmp(attr->acct_multi_session_id, buf, 16) !=
746 0)
747 sta->radius_das_match = 0;
748 else
749 count++;
750 }
751
752 if (count == 0) {
753 wpa_printf(MSG_DEBUG,
754 "RADIUS DAS: No matches remaining after Acct-Multi-Session-Id check");
755 return NULL;
756 }
757 wpa_printf(MSG_DEBUG,
758 "RADIUS DAS: Acct-Multi-Session-Id match");
759 }
760
761 if (attr->cui) {
762 num_attr++;
763 count = 0;
764
765 for (sta = hapd->sta_list; sta; sta = sta->next) {
766 struct wpabuf *cui;
767
768 if (!sta->radius_das_match)
769 continue;
770 cui = ieee802_1x_get_radius_cui(sta->eapol_sm);
771 if (!cui || wpabuf_len(cui) != attr->cui_len ||
772 os_memcmp(wpabuf_head(cui), attr->cui,
773 attr->cui_len) != 0)
774 sta->radius_das_match = 0;
775 else
776 count++;
777 }
778
779 if (count == 0) {
780 wpa_printf(MSG_DEBUG,
781 "RADIUS DAS: No matches remaining after Chargeable-User-Identity check");
782 return NULL;
783 }
784 wpa_printf(MSG_DEBUG,
785 "RADIUS DAS: Chargeable-User-Identity match");
786 }
787
788 if (attr->user_name) {
789 num_attr++;
790 count = 0;
791
792 for (sta = hapd->sta_list; sta; sta = sta->next) {
793 u8 *identity;
794 size_t identity_len;
795
796 if (!sta->radius_das_match)
797 continue;
798 identity = ieee802_1x_get_identity(sta->eapol_sm,
799 &identity_len);
800 if (!identity ||
801 identity_len != attr->user_name_len ||
802 os_memcmp(identity, attr->user_name, identity_len)
803 != 0)
804 sta->radius_das_match = 0;
805 else
806 count++;
807 }
808
809 if (count == 0) {
810 wpa_printf(MSG_DEBUG,
811 "RADIUS DAS: No matches remaining after User-Name check");
812 return NULL;
813 }
814 wpa_printf(MSG_DEBUG,
815 "RADIUS DAS: User-Name match");
816 }
817
818 if (num_attr == 0) {
819 /*
820 * In theory, we could match all current associations, but it
821 * seems safer to just reject requests that do not include any
822 * session identification attributes.
823 */
824 wpa_printf(MSG_DEBUG,
825 "RADIUS DAS: No session identification attributes included");
826 return NULL;
827 }
828
829 selected = NULL;
830 for (sta = hapd->sta_list; sta; sta = sta->next) {
831 if (sta->radius_das_match) {
832 if (selected) {
833 *multi = 1;
834 return NULL;
835 }
836 selected = sta;
837 }
838 }
839
840 return selected;
841 }
842
843
844 static int hostapd_das_disconnect_pmksa(struct hostapd_data *hapd,
845 struct radius_das_attrs *attr)
846 {
847 if (!hapd->wpa_auth)
848 return -1;
849 return wpa_auth_radius_das_disconnect_pmksa(hapd->wpa_auth, attr);
850 }
851
852
853 static enum radius_das_res
854 hostapd_das_disconnect(void *ctx, struct radius_das_attrs *attr)
855 {
856 struct hostapd_data *hapd = ctx;
857 struct sta_info *sta;
858 int multi;
859
860 if (hostapd_das_nas_mismatch(hapd, attr))
861 return RADIUS_DAS_NAS_MISMATCH;
862
863 sta = hostapd_das_find_sta(hapd, attr, &multi);
864 if (sta == NULL) {
865 if (multi) {
866 wpa_printf(MSG_DEBUG,
867 "RADIUS DAS: Multiple sessions match - not supported");
868 return RADIUS_DAS_MULTI_SESSION_MATCH;
869 }
870 if (hostapd_das_disconnect_pmksa(hapd, attr) == 0) {
871 wpa_printf(MSG_DEBUG,
872 "RADIUS DAS: PMKSA cache entry matched");
873 return RADIUS_DAS_SUCCESS;
874 }
875 wpa_printf(MSG_DEBUG, "RADIUS DAS: No matching session found");
876 return RADIUS_DAS_SESSION_NOT_FOUND;
877 }
878
879 wpa_printf(MSG_DEBUG, "RADIUS DAS: Found a matching session " MACSTR
880 " - disconnecting", MAC2STR(sta->addr));
881 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
882
883 hostapd_drv_sta_deauth(hapd, sta->addr,
884 WLAN_REASON_PREV_AUTH_NOT_VALID);
885 ap_sta_deauthenticate(hapd, sta, WLAN_REASON_PREV_AUTH_NOT_VALID);
886
887 return RADIUS_DAS_SUCCESS;
888 }
889
890 #endif /* CONFIG_NO_RADIUS */
891
892
893 /**
894 * hostapd_setup_bss - Per-BSS setup (initialization)
895 * @hapd: Pointer to BSS data
896 * @first: Whether this BSS is the first BSS of an interface; -1 = not first,
897 * but interface may exist
898 *
899 * This function is used to initialize all per-BSS data structures and
900 * resources. This gets called in a loop for each BSS when an interface is
901 * initialized. Most of the modules that are initialized here will be
902 * deinitialized in hostapd_cleanup().
903 */
904 static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
905 {
906 struct hostapd_bss_config *conf = hapd->conf;
907 u8 ssid[SSID_MAX_LEN + 1];
908 int ssid_len, set_ssid;
909 char force_ifname[IFNAMSIZ];
910 u8 if_addr[ETH_ALEN];
911 int flush_old_stations = 1;
912
913 wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s), first=%d)",
914 __func__, hapd, conf->iface, first);
915
916 #ifdef EAP_SERVER_TNC
917 if (conf->tnc && tncs_global_init() < 0) {
918 wpa_printf(MSG_ERROR, "Failed to initialize TNCS");
919 return -1;
920 }
921 #endif /* EAP_SERVER_TNC */
922
923 if (hapd->started) {
924 wpa_printf(MSG_ERROR, "%s: Interface %s was already started",
925 __func__, conf->iface);
926 return -1;
927 }
928 hapd->started = 1;
929
930 if (!first || first == -1) {
931 u8 *addr = hapd->own_addr;
932
933 if (!is_zero_ether_addr(conf->bssid)) {
934 /* Allocate the configured BSSID. */
935 os_memcpy(hapd->own_addr, conf->bssid, ETH_ALEN);
936
937 if (hostapd_mac_comp(hapd->own_addr,
938 hapd->iface->bss[0]->own_addr) ==
939 0) {
940 wpa_printf(MSG_ERROR, "BSS '%s' may not have "
941 "BSSID set to the MAC address of "
942 "the radio", conf->iface);
943 return -1;
944 }
945 } else if (hapd->iconf->use_driver_iface_addr) {
946 addr = NULL;
947 } else {
948 /* Allocate the next available BSSID. */
949 do {
950 inc_byte_array(hapd->own_addr, ETH_ALEN);
951 } while (mac_in_conf(hapd->iconf, hapd->own_addr));
952 }
953
954 hapd->interface_added = 1;
955 if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS,
956 conf->iface, addr, hapd,
957 &hapd->drv_priv, force_ifname, if_addr,
958 conf->bridge[0] ? conf->bridge : NULL,
959 first == -1)) {
960 wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
961 MACSTR ")", MAC2STR(hapd->own_addr));
962 hapd->interface_added = 0;
963 return -1;
964 }
965
966 if (!addr)
967 os_memcpy(hapd->own_addr, if_addr, ETH_ALEN);
968 }
969
970 if (conf->wmm_enabled < 0)
971 conf->wmm_enabled = hapd->iconf->ieee80211n;
972
973 #ifdef CONFIG_IEEE80211R_AP
974 if (is_zero_ether_addr(conf->r1_key_holder))
975 os_memcpy(conf->r1_key_holder, hapd->own_addr, ETH_ALEN);
976 #endif /* CONFIG_IEEE80211R_AP */
977
978 #ifdef CONFIG_MESH
979 if ((hapd->conf->mesh & MESH_ENABLED) && hapd->iface->mconf == NULL)
980 flush_old_stations = 0;
981 #endif /* CONFIG_MESH */
982
983 if (flush_old_stations)
984 hostapd_flush_old_stations(hapd,
985 WLAN_REASON_PREV_AUTH_NOT_VALID);
986 hostapd_set_privacy(hapd, 0);
987
988 hostapd_broadcast_wep_clear(hapd);
989 if (hostapd_setup_encryption(conf->iface, hapd))
990 return -1;
991
992 /*
993 * Fetch the SSID from the system and use it or,
994 * if one was specified in the config file, verify they
995 * match.
996 */
997 ssid_len = hostapd_get_ssid(hapd, ssid, sizeof(ssid));
998 if (ssid_len < 0) {
999 wpa_printf(MSG_ERROR, "Could not read SSID from system");
1000 return -1;
1001 }
1002 if (conf->ssid.ssid_set) {
1003 /*
1004 * If SSID is specified in the config file and it differs
1005 * from what is being used then force installation of the
1006 * new SSID.
1007 */
1008 set_ssid = (conf->ssid.ssid_len != (size_t) ssid_len ||
1009 os_memcmp(conf->ssid.ssid, ssid, ssid_len) != 0);
1010 } else {
1011 /*
1012 * No SSID in the config file; just use the one we got
1013 * from the system.
1014 */
1015 set_ssid = 0;
1016 conf->ssid.ssid_len = ssid_len;
1017 os_memcpy(conf->ssid.ssid, ssid, conf->ssid.ssid_len);
1018 }
1019
1020 if (!hostapd_drv_none(hapd)) {
1021 wpa_printf(MSG_ERROR, "Using interface %s with hwaddr " MACSTR
1022 " and ssid \"%s\"",
1023 conf->iface, MAC2STR(hapd->own_addr),
1024 wpa_ssid_txt(conf->ssid.ssid, conf->ssid.ssid_len));
1025 }
1026
1027 if (hostapd_setup_wpa_psk(conf)) {
1028 wpa_printf(MSG_ERROR, "WPA-PSK setup failed.");
1029 return -1;
1030 }
1031
1032 /* Set SSID for the kernel driver (to be used in beacon and probe
1033 * response frames) */
1034 if (set_ssid && hostapd_set_ssid(hapd, conf->ssid.ssid,
1035 conf->ssid.ssid_len)) {
1036 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
1037 return -1;
1038 }
1039
1040 if (wpa_debug_level <= MSG_MSGDUMP)
1041 conf->radius->msg_dumps = 1;
1042 #ifndef CONFIG_NO_RADIUS
1043 hapd->radius = radius_client_init(hapd, conf->radius);
1044 if (hapd->radius == NULL) {
1045 wpa_printf(MSG_ERROR, "RADIUS client initialization failed.");
1046 return -1;
1047 }
1048
1049 if (conf->radius_das_port) {
1050 struct radius_das_conf das_conf;
1051 os_memset(&das_conf, 0, sizeof(das_conf));
1052 das_conf.port = conf->radius_das_port;
1053 das_conf.shared_secret = conf->radius_das_shared_secret;
1054 das_conf.shared_secret_len =
1055 conf->radius_das_shared_secret_len;
1056 das_conf.client_addr = &conf->radius_das_client_addr;
1057 das_conf.time_window = conf->radius_das_time_window;
1058 das_conf.require_event_timestamp =
1059 conf->radius_das_require_event_timestamp;
1060 das_conf.require_message_authenticator =
1061 conf->radius_das_require_message_authenticator;
1062 das_conf.ctx = hapd;
1063 das_conf.disconnect = hostapd_das_disconnect;
1064 hapd->radius_das = radius_das_init(&das_conf);
1065 if (hapd->radius_das == NULL) {
1066 wpa_printf(MSG_ERROR, "RADIUS DAS initialization "
1067 "failed.");
1068 return -1;
1069 }
1070 }
1071 #endif /* CONFIG_NO_RADIUS */
1072
1073 if (hostapd_acl_init(hapd)) {
1074 wpa_printf(MSG_ERROR, "ACL initialization failed.");
1075 return -1;
1076 }
1077 if (hostapd_init_wps(hapd, conf))
1078 return -1;
1079
1080 if (authsrv_init(hapd) < 0)
1081 return -1;
1082
1083 if (ieee802_1x_init(hapd)) {
1084 wpa_printf(MSG_ERROR, "IEEE 802.1X initialization failed.");
1085 return -1;
1086 }
1087
1088 if ((conf->wpa || conf->osen) && hostapd_setup_wpa(hapd))
1089 return -1;
1090
1091 if (accounting_init(hapd)) {
1092 wpa_printf(MSG_ERROR, "Accounting initialization failed.");
1093 return -1;
1094 }
1095
1096 if (conf->ieee802_11f &&
1097 (hapd->iapp = iapp_init(hapd, conf->iapp_iface)) == NULL) {
1098 wpa_printf(MSG_ERROR, "IEEE 802.11F (IAPP) initialization "
1099 "failed.");
1100 return -1;
1101 }
1102
1103 #ifdef CONFIG_INTERWORKING
1104 if (gas_serv_init(hapd)) {
1105 wpa_printf(MSG_ERROR, "GAS server initialization failed");
1106 return -1;
1107 }
1108
1109 if (conf->qos_map_set_len &&
1110 hostapd_drv_set_qos_map(hapd, conf->qos_map_set,
1111 conf->qos_map_set_len)) {
1112 wpa_printf(MSG_ERROR, "Failed to initialize QoS Map");
1113 return -1;
1114 }
1115 #endif /* CONFIG_INTERWORKING */
1116
1117 if (conf->bss_load_update_period && bss_load_update_init(hapd)) {
1118 wpa_printf(MSG_ERROR, "BSS Load initialization failed");
1119 return -1;
1120 }
1121
1122 if (conf->proxy_arp) {
1123 if (x_snoop_init(hapd)) {
1124 wpa_printf(MSG_ERROR,
1125 "Generic snooping infrastructure initialization failed");
1126 return -1;
1127 }
1128
1129 if (dhcp_snoop_init(hapd)) {
1130 wpa_printf(MSG_ERROR,
1131 "DHCP snooping initialization failed");
1132 return -1;
1133 }
1134
1135 if (ndisc_snoop_init(hapd)) {
1136 wpa_printf(MSG_ERROR,
1137 "Neighbor Discovery snooping initialization failed");
1138 return -1;
1139 }
1140 }
1141
1142 if (!hostapd_drv_none(hapd) && vlan_init(hapd)) {
1143 wpa_printf(MSG_ERROR, "VLAN initialization failed.");
1144 return -1;
1145 }
1146
1147 if (!conf->start_disabled && ieee802_11_set_beacon(hapd) < 0)
1148 return -1;
1149
1150 if (hapd->wpa_auth && wpa_init_keys(hapd->wpa_auth) < 0)
1151 return -1;
1152
1153 if (hapd->driver && hapd->driver->set_operstate)
1154 hapd->driver->set_operstate(hapd->drv_priv, 1);
1155
1156 return 0;
1157 }
1158
1159
1160 static void hostapd_tx_queue_params(struct hostapd_iface *iface)
1161 {
1162 struct hostapd_data *hapd = iface->bss[0];
1163 int i;
1164 struct hostapd_tx_queue_params *p;
1165
1166 #ifdef CONFIG_MESH
1167 if ((hapd->conf->mesh & MESH_ENABLED) && iface->mconf == NULL)
1168 return;
1169 #endif /* CONFIG_MESH */
1170
1171 for (i = 0; i < NUM_TX_QUEUES; i++) {
1172 p = &iface->conf->tx_queue[i];
1173
1174 if (hostapd_set_tx_queue_params(hapd, i, p->aifs, p->cwmin,
1175 p->cwmax, p->burst)) {
1176 wpa_printf(MSG_DEBUG, "Failed to set TX queue "
1177 "parameters for queue %d.", i);
1178 /* Continue anyway */
1179 }
1180 }
1181 }
1182
1183
1184 static int hostapd_set_acl_list(struct hostapd_data *hapd,
1185 struct mac_acl_entry *mac_acl,
1186 int n_entries, u8 accept_acl)
1187 {
1188 struct hostapd_acl_params *acl_params;
1189 int i, err;
1190
1191 acl_params = os_zalloc(sizeof(*acl_params) +
1192 (n_entries * sizeof(acl_params->mac_acl[0])));
1193 if (!acl_params)
1194 return -ENOMEM;
1195
1196 for (i = 0; i < n_entries; i++)
1197 os_memcpy(acl_params->mac_acl[i].addr, mac_acl[i].addr,
1198 ETH_ALEN);
1199
1200 acl_params->acl_policy = accept_acl;
1201 acl_params->num_mac_acl = n_entries;
1202
1203 err = hostapd_drv_set_acl(hapd, acl_params);
1204
1205 os_free(acl_params);
1206
1207 return err;
1208 }
1209
1210
1211 static void hostapd_set_acl(struct hostapd_data *hapd)
1212 {
1213 struct hostapd_config *conf = hapd->iconf;
1214 int err;
1215 u8 accept_acl;
1216
1217 if (hapd->iface->drv_max_acl_mac_addrs == 0)
1218 return;
1219
1220 if (conf->bss[0]->macaddr_acl == DENY_UNLESS_ACCEPTED) {
1221 accept_acl = 1;
1222 err = hostapd_set_acl_list(hapd, conf->bss[0]->accept_mac,
1223 conf->bss[0]->num_accept_mac,
1224 accept_acl);
1225 if (err) {
1226 wpa_printf(MSG_DEBUG, "Failed to set accept acl");
1227 return;
1228 }
1229 } else if (conf->bss[0]->macaddr_acl == ACCEPT_UNLESS_DENIED) {
1230 accept_acl = 0;
1231 err = hostapd_set_acl_list(hapd, conf->bss[0]->deny_mac,
1232 conf->bss[0]->num_deny_mac,
1233 accept_acl);
1234 if (err) {
1235 wpa_printf(MSG_DEBUG, "Failed to set deny acl");
1236 return;
1237 }
1238 }
1239 }
1240
1241
1242 static int start_ctrl_iface_bss(struct hostapd_data *hapd)
1243 {
1244 if (!hapd->iface->interfaces ||
1245 !hapd->iface->interfaces->ctrl_iface_init)
1246 return 0;
1247
1248 if (hapd->iface->interfaces->ctrl_iface_init(hapd)) {
1249 wpa_printf(MSG_ERROR,
1250 "Failed to setup control interface for %s",
1251 hapd->conf->iface);
1252 return -1;
1253 }
1254
1255 return 0;
1256 }
1257
1258
1259 static int start_ctrl_iface(struct hostapd_iface *iface)
1260 {
1261 size_t i;
1262
1263 if (!iface->interfaces || !iface->interfaces->ctrl_iface_init)
1264 return 0;
1265
1266 for (i = 0; i < iface->num_bss; i++) {
1267 struct hostapd_data *hapd = iface->bss[i];
1268 if (iface->interfaces->ctrl_iface_init(hapd)) {
1269 wpa_printf(MSG_ERROR,
1270 "Failed to setup control interface for %s",
1271 hapd->conf->iface);
1272 return -1;
1273 }
1274 }
1275
1276 return 0;
1277 }
1278
1279
1280 static void channel_list_update_timeout(void *eloop_ctx, void *timeout_ctx)
1281 {
1282 struct hostapd_iface *iface = eloop_ctx;
1283
1284 if (!iface->wait_channel_update) {
1285 wpa_printf(MSG_INFO, "Channel list update timeout, but interface was not waiting for it");
1286 return;
1287 }
1288
1289 /*
1290 * It is possible that the existing channel list is acceptable, so try
1291 * to proceed.
1292 */
1293 wpa_printf(MSG_DEBUG, "Channel list update timeout - try to continue anyway");
1294 setup_interface2(iface);
1295 }
1296
1297
1298 void hostapd_channel_list_updated(struct hostapd_iface *iface, int initiator)
1299 {
1300 if (!iface->wait_channel_update || initiator != REGDOM_SET_BY_USER)
1301 return;
1302
1303 wpa_printf(MSG_DEBUG, "Channel list updated - continue setup");
1304 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
1305 setup_interface2(iface);
1306 }
1307
1308
1309 static int setup_interface(struct hostapd_iface *iface)
1310 {
1311 struct hostapd_data *hapd = iface->bss[0];
1312 size_t i;
1313
1314 /*
1315 * It is possible that setup_interface() is called after the interface
1316 * was disabled etc., in which case driver_ap_teardown is possibly set
1317 * to 1. Clear it here so any other key/station deletion, which is not
1318 * part of a teardown flow, would also call the relevant driver
1319 * callbacks.
1320 */
1321 iface->driver_ap_teardown = 0;
1322
1323 if (!iface->phy[0]) {
1324 const char *phy = hostapd_drv_get_radio_name(hapd);
1325 if (phy) {
1326 wpa_printf(MSG_DEBUG, "phy: %s", phy);
1327 os_strlcpy(iface->phy, phy, sizeof(iface->phy));
1328 }
1329 }
1330
1331 /*
1332 * Make sure that all BSSes get configured with a pointer to the same
1333 * driver interface.
1334 */
1335 for (i = 1; i < iface->num_bss; i++) {
1336 iface->bss[i]->driver = hapd->driver;
1337 iface->bss[i]->drv_priv = hapd->drv_priv;
1338 }
1339
1340 if (hostapd_validate_bssid_configuration(iface))
1341 return -1;
1342
1343 /*
1344 * Initialize control interfaces early to allow external monitoring of
1345 * channel setup operations that may take considerable amount of time
1346 * especially for DFS cases.
1347 */
1348 if (start_ctrl_iface(iface))
1349 return -1;
1350
1351 if (hapd->iconf->country[0] && hapd->iconf->country[1]) {
1352 char country[4], previous_country[4];
1353
1354 hostapd_set_state(iface, HAPD_IFACE_COUNTRY_UPDATE);
1355 if (hostapd_get_country(hapd, previous_country) < 0)
1356 previous_country[0] = '\0';
1357
1358 os_memcpy(country, hapd->iconf->country, 3);
1359 country[3] = '\0';
1360 if (hostapd_set_country(hapd, country) < 0) {
1361 wpa_printf(MSG_ERROR, "Failed to set country code");
1362 return -1;
1363 }
1364
1365 wpa_printf(MSG_DEBUG, "Previous country code %s, new country code %s",
1366 previous_country, country);
1367
1368 if (os_strncmp(previous_country, country, 2) != 0) {
1369 wpa_printf(MSG_DEBUG, "Continue interface setup after channel list update");
1370 iface->wait_channel_update = 1;
1371 eloop_register_timeout(5, 0,
1372 channel_list_update_timeout,
1373 iface, NULL);
1374 return 0;
1375 }
1376 }
1377
1378 return setup_interface2(iface);
1379 }
1380
1381
1382 static int setup_interface2(struct hostapd_iface *iface)
1383 {
1384 iface->wait_channel_update = 0;
1385
1386 if (hostapd_get_hw_features(iface)) {
1387 /* Not all drivers support this yet, so continue without hw
1388 * feature data. */
1389 } else {
1390 int ret = hostapd_select_hw_mode(iface);
1391 if (ret < 0) {
1392 wpa_printf(MSG_ERROR, "Could not select hw_mode and "
1393 "channel. (%d)", ret);
1394 goto fail;
1395 }
1396 if (ret == 1) {
1397 wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback (ACS)");
1398 return 0;
1399 }
1400 ret = hostapd_check_ht_capab(iface);
1401 if (ret < 0)
1402 goto fail;
1403 if (ret == 1) {
1404 wpa_printf(MSG_DEBUG, "Interface initialization will "
1405 "be completed in a callback");
1406 return 0;
1407 }
1408
1409 if (iface->conf->ieee80211h)
1410 wpa_printf(MSG_DEBUG, "DFS support is enabled");
1411 }
1412 return hostapd_setup_interface_complete(iface, 0);
1413
1414 fail:
1415 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
1416 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
1417 if (iface->interfaces && iface->interfaces->terminate_on_error)
1418 eloop_terminate();
1419 return -1;
1420 }
1421
1422
1423 #ifdef CONFIG_FST
1424
1425 static const u8 * fst_hostapd_get_bssid_cb(void *ctx)
1426 {
1427 struct hostapd_data *hapd = ctx;
1428
1429 return hapd->own_addr;
1430 }
1431
1432
1433 static void fst_hostapd_get_channel_info_cb(void *ctx,
1434 enum hostapd_hw_mode *hw_mode,
1435 u8 *channel)
1436 {
1437 struct hostapd_data *hapd = ctx;
1438
1439 *hw_mode = ieee80211_freq_to_chan(hapd->iface->freq, channel);
1440 }
1441
1442
1443 static void fst_hostapd_set_ies_cb(void *ctx, const struct wpabuf *fst_ies)
1444 {
1445 struct hostapd_data *hapd = ctx;
1446
1447 if (hapd->iface->fst_ies != fst_ies) {
1448 hapd->iface->fst_ies = fst_ies;
1449 if (ieee802_11_set_beacon(hapd))
1450 wpa_printf(MSG_WARNING, "FST: Cannot set beacon");
1451 }
1452 }
1453
1454
1455 static int fst_hostapd_send_action_cb(void *ctx, const u8 *da,
1456 struct wpabuf *buf)
1457 {
1458 struct hostapd_data *hapd = ctx;
1459
1460 return hostapd_drv_send_action(hapd, hapd->iface->freq, 0, da,
1461 wpabuf_head(buf), wpabuf_len(buf));
1462 }
1463
1464
1465 static const struct wpabuf * fst_hostapd_get_mb_ie_cb(void *ctx, const u8 *addr)
1466 {
1467 struct hostapd_data *hapd = ctx;
1468 struct sta_info *sta = ap_get_sta(hapd, addr);
1469
1470 return sta ? sta->mb_ies : NULL;
1471 }
1472
1473
1474 static void fst_hostapd_update_mb_ie_cb(void *ctx, const u8 *addr,
1475 const u8 *buf, size_t size)
1476 {
1477 struct hostapd_data *hapd = ctx;
1478 struct sta_info *sta = ap_get_sta(hapd, addr);
1479
1480 if (sta) {
1481 struct mb_ies_info info;
1482
1483 if (!mb_ies_info_by_ies(&info, buf, size)) {
1484 wpabuf_free(sta->mb_ies);
1485 sta->mb_ies = mb_ies_by_info(&info);
1486 }
1487 }
1488 }
1489
1490
1491 static const u8 * fst_hostapd_get_sta(struct fst_get_peer_ctx **get_ctx,
1492 Boolean mb_only)
1493 {
1494 struct sta_info *s = (struct sta_info *) *get_ctx;
1495
1496 if (mb_only) {
1497 for (; s && !s->mb_ies; s = s->next)
1498 ;
1499 }
1500
1501 if (s) {
1502 *get_ctx = (struct fst_get_peer_ctx *) s->next;
1503
1504 return s->addr;
1505 }
1506
1507 *get_ctx = NULL;
1508 return NULL;
1509 }
1510
1511
1512 static const u8 * fst_hostapd_get_peer_first(void *ctx,
1513 struct fst_get_peer_ctx **get_ctx,
1514 Boolean mb_only)
1515 {
1516 struct hostapd_data *hapd = ctx;
1517
1518 *get_ctx = (struct fst_get_peer_ctx *) hapd->sta_list;
1519
1520 return fst_hostapd_get_sta(get_ctx, mb_only);
1521 }
1522
1523
1524 static const u8 * fst_hostapd_get_peer_next(void *ctx,
1525 struct fst_get_peer_ctx **get_ctx,
1526 Boolean mb_only)
1527 {
1528 return fst_hostapd_get_sta(get_ctx, mb_only);
1529 }
1530
1531
1532 void fst_hostapd_fill_iface_obj(struct hostapd_data *hapd,
1533 struct fst_wpa_obj *iface_obj)
1534 {
1535 iface_obj->ctx = hapd;
1536 iface_obj->get_bssid = fst_hostapd_get_bssid_cb;
1537 iface_obj->get_channel_info = fst_hostapd_get_channel_info_cb;
1538 iface_obj->set_ies = fst_hostapd_set_ies_cb;
1539 iface_obj->send_action = fst_hostapd_send_action_cb;
1540 iface_obj->get_mb_ie = fst_hostapd_get_mb_ie_cb;
1541 iface_obj->update_mb_ie = fst_hostapd_update_mb_ie_cb;
1542 iface_obj->get_peer_first = fst_hostapd_get_peer_first;
1543 iface_obj->get_peer_next = fst_hostapd_get_peer_next;
1544 }
1545
1546 #endif /* CONFIG_FST */
1547
1548
1549 #ifdef NEED_AP_MLME
1550 static enum nr_chan_width hostapd_get_nr_chan_width(struct hostapd_data *hapd,
1551 int ht, int vht)
1552 {
1553 if (!ht && !vht)
1554 return NR_CHAN_WIDTH_20;
1555 if (!hapd->iconf->secondary_channel)
1556 return NR_CHAN_WIDTH_20;
1557 if (!vht || hapd->iconf->vht_oper_chwidth == VHT_CHANWIDTH_USE_HT)
1558 return NR_CHAN_WIDTH_40;
1559 if (hapd->iconf->vht_oper_chwidth == VHT_CHANWIDTH_80MHZ)
1560 return NR_CHAN_WIDTH_80;
1561 if (hapd->iconf->vht_oper_chwidth == VHT_CHANWIDTH_160MHZ)
1562 return NR_CHAN_WIDTH_160;
1563 if (hapd->iconf->vht_oper_chwidth == VHT_CHANWIDTH_80P80MHZ)
1564 return NR_CHAN_WIDTH_80P80;
1565 return NR_CHAN_WIDTH_20;
1566 }
1567 #endif /* NEED_AP_MLME */
1568
1569
1570 static void hostapd_set_own_neighbor_report(struct hostapd_data *hapd)
1571 {
1572 #ifdef NEED_AP_MLME
1573 u16 capab = hostapd_own_capab_info(hapd);
1574 int ht = hapd->iconf->ieee80211n && !hapd->conf->disable_11n;
1575 int vht = hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac;
1576 struct wpa_ssid_value ssid;
1577 u8 channel, op_class;
1578 u8 center_freq1_idx = 0, center_freq2_idx = 0;
1579 enum nr_chan_width width;
1580 u32 bssid_info;
1581 struct wpabuf *nr;
1582
1583 if (!(hapd->conf->radio_measurements[0] &
1584 WLAN_RRM_CAPS_NEIGHBOR_REPORT))
1585 return;
1586
1587 bssid_info = 3; /* AP is reachable */
1588 bssid_info |= NEI_REP_BSSID_INFO_SECURITY; /* "same as the AP" */
1589 bssid_info |= NEI_REP_BSSID_INFO_KEY_SCOPE; /* "same as the AP" */
1590
1591 if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT)
1592 bssid_info |= NEI_REP_BSSID_INFO_SPECTRUM_MGMT;
1593
1594 bssid_info |= NEI_REP_BSSID_INFO_RM; /* RRM is supported */
1595
1596 if (hapd->conf->wmm_enabled) {
1597 bssid_info |= NEI_REP_BSSID_INFO_QOS;
1598
1599 if (hapd->conf->wmm_uapsd &&
1600 (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
1601 bssid_info |= NEI_REP_BSSID_INFO_APSD;
1602 }
1603
1604 if (ht) {
1605 bssid_info |= NEI_REP_BSSID_INFO_HT |
1606 NEI_REP_BSSID_INFO_DELAYED_BA;
1607
1608 /* VHT bit added in IEEE P802.11-REVmc/D4.3 */
1609 if (vht)
1610 bssid_info |= NEI_REP_BSSID_INFO_VHT;
1611 }
1612
1613 /* TODO: Set NEI_REP_BSSID_INFO_MOBILITY_DOMAIN if MDE is set */
1614
1615 if (ieee80211_freq_to_channel_ext(hapd->iface->freq,
1616 hapd->iconf->secondary_channel,
1617 hapd->iconf->vht_oper_chwidth,
1618 &op_class, &channel) ==
1619 NUM_HOSTAPD_MODES)
1620 return;
1621 width = hostapd_get_nr_chan_width(hapd, ht, vht);
1622 if (vht) {
1623 center_freq1_idx = hapd->iconf->vht_oper_centr_freq_seg0_idx;
1624 if (width == NR_CHAN_WIDTH_80P80)
1625 center_freq2_idx =
1626 hapd->iconf->vht_oper_centr_freq_seg1_idx;
1627 } else if (ht) {
1628 ieee80211_freq_to_chan(hapd->iface->freq +
1629 10 * hapd->iconf->secondary_channel,
1630 &center_freq1_idx);
1631 }
1632
1633 ssid.ssid_len = hapd->conf->ssid.ssid_len;
1634 os_memcpy(ssid.ssid, hapd->conf->ssid.ssid, ssid.ssid_len);
1635
1636 /*
1637 * Neighbor Report element size = BSSID + BSSID info + op_class + chan +
1638 * phy type + wide bandwidth channel subelement.
1639 */
1640 nr = wpabuf_alloc(ETH_ALEN + 4 + 1 + 1 + 1 + 5);
1641 if (!nr)
1642 return;
1643
1644 wpabuf_put_data(nr, hapd->own_addr, ETH_ALEN);
1645 wpabuf_put_le32(nr, bssid_info);
1646 wpabuf_put_u8(nr, op_class);
1647 wpabuf_put_u8(nr, channel);
1648 wpabuf_put_u8(nr, ieee80211_get_phy_type(hapd->iface->freq, ht, vht));
1649
1650 /*
1651 * Wide Bandwidth Channel subelement may be needed to allow the
1652 * receiving STA to send packets to the AP. See IEEE P802.11-REVmc/D5.0
1653 * Figure 9-301.
1654 */
1655 wpabuf_put_u8(nr, WNM_NEIGHBOR_WIDE_BW_CHAN);
1656 wpabuf_put_u8(nr, 3);
1657 wpabuf_put_u8(nr, width);
1658 wpabuf_put_u8(nr, center_freq1_idx);
1659 wpabuf_put_u8(nr, center_freq2_idx);
1660
1661 hostapd_neighbor_set(hapd, hapd->own_addr, &ssid, nr, hapd->iconf->lci,
1662 hapd->iconf->civic, hapd->iconf->stationary_ap);
1663
1664 wpabuf_free(nr);
1665 #endif /* NEED_AP_MLME */
1666 }
1667
1668
1669 static int hostapd_setup_interface_complete_sync(struct hostapd_iface *iface,
1670 int err)
1671 {
1672 struct hostapd_data *hapd = iface->bss[0];
1673 size_t j;
1674 u8 *prev_addr;
1675 int delay_apply_cfg = 0;
1676 int res_dfs_offload = 0;
1677
1678 if (err)
1679 goto fail;
1680
1681 wpa_printf(MSG_DEBUG, "Completing interface initialization");
1682 if (iface->conf->channel) {
1683 #ifdef NEED_AP_MLME
1684 int res;
1685 #endif /* NEED_AP_MLME */
1686
1687 iface->freq = hostapd_hw_get_freq(hapd, iface->conf->channel);
1688 wpa_printf(MSG_DEBUG, "Mode: %s Channel: %d "
1689 "Frequency: %d MHz",
1690 hostapd_hw_mode_txt(iface->conf->hw_mode),
1691 iface->conf->channel, iface->freq);
1692
1693 #ifdef NEED_AP_MLME
1694 /* Handle DFS only if it is not offloaded to the driver */
1695 if (!(iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)) {
1696 /* Check DFS */
1697 res = hostapd_handle_dfs(iface);
1698 if (res <= 0) {
1699 if (res < 0)
1700 goto fail;
1701 return res;
1702 }
1703 } else {
1704 /* If DFS is offloaded to the driver */
1705 res_dfs_offload = hostapd_handle_dfs_offload(iface);
1706 if (res_dfs_offload <= 0) {
1707 if (res_dfs_offload < 0)
1708 goto fail;
1709 } else {
1710 wpa_printf(MSG_DEBUG,
1711 "Proceed with AP/channel setup");
1712 /*
1713 * If this is a DFS channel, move to completing
1714 * AP setup.
1715 */
1716 if (res_dfs_offload == 1)
1717 goto dfs_offload;
1718 /* Otherwise fall through. */
1719 }
1720 }
1721 #endif /* NEED_AP_MLME */
1722
1723 #ifdef CONFIG_MESH
1724 if (iface->mconf != NULL) {
1725 wpa_printf(MSG_DEBUG,
1726 "%s: Mesh configuration will be applied while joining the mesh network",
1727 iface->bss[0]->conf->iface);
1728 delay_apply_cfg = 1;
1729 }
1730 #endif /* CONFIG_MESH */
1731
1732 if (!delay_apply_cfg &&
1733 hostapd_set_freq(hapd, hapd->iconf->hw_mode, iface->freq,
1734 hapd->iconf->channel,
1735 hapd->iconf->ieee80211n,
1736 hapd->iconf->ieee80211ac,
1737 hapd->iconf->secondary_channel,
1738 hapd->iconf->vht_oper_chwidth,
1739 hapd->iconf->vht_oper_centr_freq_seg0_idx,
1740 hapd->iconf->vht_oper_centr_freq_seg1_idx)) {
1741 wpa_printf(MSG_ERROR, "Could not set channel for "
1742 "kernel driver");
1743 goto fail;
1744 }
1745 }
1746
1747 if (iface->current_mode) {
1748 if (hostapd_prepare_rates(iface, iface->current_mode)) {
1749 wpa_printf(MSG_ERROR, "Failed to prepare rates "
1750 "table.");
1751 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1752 HOSTAPD_LEVEL_WARNING,
1753 "Failed to prepare rates table.");
1754 goto fail;
1755 }
1756 }
1757
1758 if (hapd->iconf->rts_threshold > -1 &&
1759 hostapd_set_rts(hapd, hapd->iconf->rts_threshold)) {
1760 wpa_printf(MSG_ERROR, "Could not set RTS threshold for "
1761 "kernel driver");
1762 goto fail;
1763 }
1764
1765 if (hapd->iconf->fragm_threshold > -1 &&
1766 hostapd_set_frag(hapd, hapd->iconf->fragm_threshold)) {
1767 wpa_printf(MSG_ERROR, "Could not set fragmentation threshold "
1768 "for kernel driver");
1769 goto fail;
1770 }
1771
1772 prev_addr = hapd->own_addr;
1773
1774 for (j = 0; j < iface->num_bss; j++) {
1775 hapd = iface->bss[j];
1776 if (j)
1777 os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN);
1778 if (hostapd_setup_bss(hapd, j == 0)) {
1779 do {
1780 hapd = iface->bss[j];
1781 hostapd_bss_deinit_no_free(hapd);
1782 hostapd_free_hapd_data(hapd);
1783 } while (j-- > 0);
1784 goto fail;
1785 }
1786 if (is_zero_ether_addr(hapd->conf->bssid))
1787 prev_addr = hapd->own_addr;
1788 }
1789 hapd = iface->bss[0];
1790
1791 hostapd_tx_queue_params(iface);
1792
1793 ap_list_init(iface);
1794
1795 hostapd_set_acl(hapd);
1796
1797 if (hostapd_driver_commit(hapd) < 0) {
1798 wpa_printf(MSG_ERROR, "%s: Failed to commit driver "
1799 "configuration", __func__);
1800 goto fail;
1801 }
1802
1803 /*
1804 * WPS UPnP module can be initialized only when the "upnp_iface" is up.
1805 * If "interface" and "upnp_iface" are the same (e.g., non-bridge
1806 * mode), the interface is up only after driver_commit, so initialize
1807 * WPS after driver_commit.
1808 */
1809 for (j = 0; j < iface->num_bss; j++) {
1810 if (hostapd_init_wps_complete(iface->bss[j]))
1811 goto fail;
1812 }
1813
1814 if ((iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) &&
1815 !res_dfs_offload) {
1816 /*
1817 * If freq is DFS, and DFS is offloaded to the driver, then wait
1818 * for CAC to complete.
1819 */
1820 wpa_printf(MSG_DEBUG, "%s: Wait for CAC to complete", __func__);
1821 return res_dfs_offload;
1822 }
1823
1824 #ifdef NEED_AP_MLME
1825 dfs_offload:
1826 #endif /* NEED_AP_MLME */
1827
1828 #ifdef CONFIG_FST
1829 if (hapd->iconf->fst_cfg.group_id[0]) {
1830 struct fst_wpa_obj iface_obj;
1831
1832 fst_hostapd_fill_iface_obj(hapd, &iface_obj);
1833 iface->fst = fst_attach(hapd->conf->iface, hapd->own_addr,
1834 &iface_obj, &hapd->iconf->fst_cfg);
1835 if (!iface->fst) {
1836 wpa_printf(MSG_ERROR, "Could not attach to FST %s",
1837 hapd->iconf->fst_cfg.group_id);
1838 goto fail;
1839 }
1840 }
1841 #endif /* CONFIG_FST */
1842
1843 hostapd_set_state(iface, HAPD_IFACE_ENABLED);
1844 wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_ENABLED);
1845 if (hapd->setup_complete_cb)
1846 hapd->setup_complete_cb(hapd->setup_complete_cb_ctx);
1847
1848 wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
1849 iface->bss[0]->conf->iface);
1850 if (iface->interfaces && iface->interfaces->terminate_on_error > 0)
1851 iface->interfaces->terminate_on_error--;
1852
1853 for (j = 0; j < iface->num_bss; j++)
1854 hostapd_set_own_neighbor_report(iface->bss[j]);
1855
1856 return 0;
1857
1858 fail:
1859 wpa_printf(MSG_ERROR, "Interface initialization failed");
1860 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
1861 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
1862 #ifdef CONFIG_FST
1863 if (iface->fst) {
1864 fst_detach(iface->fst);
1865 iface->fst = NULL;
1866 }
1867 #endif /* CONFIG_FST */
1868 if (iface->interfaces && iface->interfaces->terminate_on_error)
1869 eloop_terminate();
1870 return -1;
1871 }
1872
1873
1874 /**
1875 * hostapd_setup_interface_complete - Complete interface setup
1876 *
1877 * This function is called when previous steps in the interface setup has been
1878 * completed. This can also start operations, e.g., DFS, that will require
1879 * additional processing before interface is ready to be enabled. Such
1880 * operations will call this function from eloop callbacks when finished.
1881 */
1882 int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err)
1883 {
1884 struct hapd_interfaces *interfaces = iface->interfaces;
1885 struct hostapd_data *hapd = iface->bss[0];
1886 unsigned int i;
1887 int not_ready_in_sync_ifaces = 0;
1888
1889 if (!iface->need_to_start_in_sync)
1890 return hostapd_setup_interface_complete_sync(iface, err);
1891
1892 if (err) {
1893 wpa_printf(MSG_ERROR, "Interface initialization failed");
1894 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
1895 iface->need_to_start_in_sync = 0;
1896 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
1897 if (interfaces && interfaces->terminate_on_error)
1898 eloop_terminate();
1899 return -1;
1900 }
1901
1902 if (iface->ready_to_start_in_sync) {
1903 /* Already in ready and waiting. should never happpen */
1904 return 0;
1905 }
1906
1907 for (i = 0; i < interfaces->count; i++) {
1908 if (interfaces->iface[i]->need_to_start_in_sync &&
1909 !interfaces->iface[i]->ready_to_start_in_sync)
1910 not_ready_in_sync_ifaces++;
1911 }
1912
1913 /*
1914 * Check if this is the last interface, if yes then start all the other
1915 * waiting interfaces. If not, add this interface to the waiting list.
1916 */
1917 if (not_ready_in_sync_ifaces > 1 && iface->state == HAPD_IFACE_DFS) {
1918 /*
1919 * If this interface went through CAC, do not synchronize, just
1920 * start immediately.
1921 */
1922 iface->need_to_start_in_sync = 0;
1923 wpa_printf(MSG_INFO,
1924 "%s: Finished CAC - bypass sync and start interface",
1925 iface->bss[0]->conf->iface);
1926 return hostapd_setup_interface_complete_sync(iface, err);
1927 }
1928
1929 if (not_ready_in_sync_ifaces > 1) {
1930 /* need to wait as there are other interfaces still coming up */
1931 iface->ready_to_start_in_sync = 1;
1932 wpa_printf(MSG_INFO,
1933 "%s: Interface waiting to sync with other interfaces",
1934 iface->bss[0]->conf->iface);
1935 return 0;
1936 }
1937
1938 wpa_printf(MSG_INFO,
1939 "%s: Last interface to sync - starting all interfaces",
1940 iface->bss[0]->conf->iface);
1941 iface->need_to_start_in_sync = 0;
1942 hostapd_setup_interface_complete_sync(iface, err);
1943 for (i = 0; i < interfaces->count; i++) {
1944 if (interfaces->iface[i]->need_to_start_in_sync &&
1945 interfaces->iface[i]->ready_to_start_in_sync) {
1946 hostapd_setup_interface_complete_sync(
1947 interfaces->iface[i], 0);
1948 /* Only once the interfaces are sync started */
1949 interfaces->iface[i]->need_to_start_in_sync = 0;
1950 }
1951 }
1952
1953 return 0;
1954 }
1955
1956
1957 /**
1958 * hostapd_setup_interface - Setup of an interface
1959 * @iface: Pointer to interface data.
1960 * Returns: 0 on success, -1 on failure
1961 *
1962 * Initializes the driver interface, validates the configuration,
1963 * and sets driver parameters based on the configuration.
1964 * Flushes old stations, sets the channel, encryption,
1965 * beacons, and WDS links based on the configuration.
1966 *
1967 * If interface setup requires more time, e.g., to perform HT co-ex scans, ACS,
1968 * or DFS operations, this function returns 0 before such operations have been
1969 * completed. The pending operations are registered into eloop and will be
1970 * completed from eloop callbacks. Those callbacks end up calling
1971 * hostapd_setup_interface_complete() once setup has been completed.
1972 */
1973 int hostapd_setup_interface(struct hostapd_iface *iface)
1974 {
1975 int ret;
1976
1977 ret = setup_interface(iface);
1978 if (ret) {
1979 wpa_printf(MSG_ERROR, "%s: Unable to setup interface.",
1980 iface->bss[0]->conf->iface);
1981 return -1;
1982 }
1983
1984 return 0;
1985 }
1986
1987
1988 /**
1989 * hostapd_alloc_bss_data - Allocate and initialize per-BSS data
1990 * @hapd_iface: Pointer to interface data
1991 * @conf: Pointer to per-interface configuration
1992 * @bss: Pointer to per-BSS configuration for this BSS
1993 * Returns: Pointer to allocated BSS data
1994 *
1995 * This function is used to allocate per-BSS data structure. This data will be
1996 * freed after hostapd_cleanup() is called for it during interface
1997 * deinitialization.
1998 */
1999 struct hostapd_data *
2000 hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
2001 struct hostapd_config *conf,
2002 struct hostapd_bss_config *bss)
2003 {
2004 struct hostapd_data *hapd;
2005
2006 hapd = os_zalloc(sizeof(*hapd));
2007 if (hapd == NULL)
2008 return NULL;
2009
2010 hapd->new_assoc_sta_cb = hostapd_new_assoc_sta;
2011 hapd->iconf = conf;
2012 hapd->conf = bss;
2013 hapd->iface = hapd_iface;
2014 if (conf)
2015 hapd->driver = conf->driver;
2016 hapd->ctrl_sock = -1;
2017 dl_list_init(&hapd->ctrl_dst);
2018 dl_list_init(&hapd->nr_db);
2019 hapd->dhcp_sock = -1;
2020 #ifdef CONFIG_IEEE80211R_AP
2021 dl_list_init(&hapd->l2_queue);
2022 dl_list_init(&hapd->l2_oui_queue);
2023 #endif /* CONFIG_IEEE80211R_AP */
2024
2025 return hapd;
2026 }
2027
2028
2029 static void hostapd_bss_deinit(struct hostapd_data *hapd)
2030 {
2031 if (!hapd)
2032 return;
2033 wpa_printf(MSG_DEBUG, "%s: deinit bss %s", __func__,
2034 hapd->conf->iface);
2035 hostapd_bss_deinit_no_free(hapd);
2036 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
2037 hostapd_cleanup(hapd);
2038 }
2039
2040
2041 void hostapd_interface_deinit(struct hostapd_iface *iface)
2042 {
2043 int j;
2044
2045 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
2046 if (iface == NULL)
2047 return;
2048
2049 hostapd_set_state(iface, HAPD_IFACE_DISABLED);
2050
2051 #ifdef CONFIG_IEEE80211N
2052 #ifdef NEED_AP_MLME
2053 hostapd_stop_setup_timers(iface);
2054 eloop_cancel_timeout(ap_ht2040_timeout, iface, NULL);
2055 #endif /* NEED_AP_MLME */
2056 #endif /* CONFIG_IEEE80211N */
2057 eloop_cancel_timeout(channel_list_update_timeout, iface, NULL);
2058 iface->wait_channel_update = 0;
2059
2060 #ifdef CONFIG_FST
2061 if (iface->fst) {
2062 fst_detach(iface->fst);
2063 iface->fst = NULL;
2064 }
2065 #endif /* CONFIG_FST */
2066
2067 for (j = iface->num_bss - 1; j >= 0; j--) {
2068 if (!iface->bss)
2069 break;
2070 hostapd_bss_deinit(iface->bss[j]);
2071 }
2072 }
2073
2074
2075 void hostapd_interface_free(struct hostapd_iface *iface)
2076 {
2077 size_t j;
2078 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
2079 for (j = 0; j < iface->num_bss; j++) {
2080 if (!iface->bss)
2081 break;
2082 wpa_printf(MSG_DEBUG, "%s: free hapd %p",
2083 __func__, iface->bss[j]);
2084 os_free(iface->bss[j]);
2085 }
2086 hostapd_cleanup_iface(iface);
2087 }
2088
2089
2090 struct hostapd_iface * hostapd_alloc_iface(void)
2091 {
2092 struct hostapd_iface *hapd_iface;
2093
2094 hapd_iface = os_zalloc(sizeof(*hapd_iface));
2095 if (!hapd_iface)
2096 return NULL;
2097
2098 dl_list_init(&hapd_iface->sta_seen);
2099
2100 return hapd_iface;
2101 }
2102
2103
2104 /**
2105 * hostapd_init - Allocate and initialize per-interface data
2106 * @config_file: Path to the configuration file
2107 * Returns: Pointer to the allocated interface data or %NULL on failure
2108 *
2109 * This function is used to allocate main data structures for per-interface
2110 * data. The allocated data buffer will be freed by calling
2111 * hostapd_cleanup_iface().
2112 */
2113 struct hostapd_iface * hostapd_init(struct hapd_interfaces *interfaces,
2114 const char *config_file)
2115 {
2116 struct hostapd_iface *hapd_iface = NULL;
2117 struct hostapd_config *conf = NULL;
2118 struct hostapd_data *hapd;
2119 size_t i;
2120
2121 hapd_iface = hostapd_alloc_iface();
2122 if (hapd_iface == NULL)
2123 goto fail;
2124
2125 hapd_iface->config_fname = os_strdup(config_file);
2126 if (hapd_iface->config_fname == NULL)
2127 goto fail;
2128
2129 conf = interfaces->config_read_cb(hapd_iface->config_fname);
2130 if (conf == NULL)
2131 goto fail;
2132 hapd_iface->conf = conf;
2133
2134 hapd_iface->num_bss = conf->num_bss;
2135 hapd_iface->bss = os_calloc(conf->num_bss,
2136 sizeof(struct hostapd_data *));
2137 if (hapd_iface->bss == NULL)
2138 goto fail;
2139
2140 for (i = 0; i < conf->num_bss; i++) {
2141 hapd = hapd_iface->bss[i] =
2142 hostapd_alloc_bss_data(hapd_iface, conf,
2143 conf->bss[i]);
2144 if (hapd == NULL)
2145 goto fail;
2146 hapd->msg_ctx = hapd;
2147 }
2148
2149 return hapd_iface;
2150
2151 fail:
2152 wpa_printf(MSG_ERROR, "Failed to set up interface with %s",
2153 config_file);
2154 if (conf)
2155 hostapd_config_free(conf);
2156 if (hapd_iface) {
2157 os_free(hapd_iface->config_fname);
2158 os_free(hapd_iface->bss);
2159 wpa_printf(MSG_DEBUG, "%s: free iface %p",
2160 __func__, hapd_iface);
2161 os_free(hapd_iface);
2162 }
2163 return NULL;
2164 }
2165
2166
2167 static int ifname_in_use(struct hapd_interfaces *interfaces, const char *ifname)
2168 {
2169 size_t i, j;
2170
2171 for (i = 0; i < interfaces->count; i++) {
2172 struct hostapd_iface *iface = interfaces->iface[i];
2173 for (j = 0; j < iface->num_bss; j++) {
2174 struct hostapd_data *hapd = iface->bss[j];
2175 if (os_strcmp(ifname, hapd->conf->iface) == 0)
2176 return 1;
2177 }
2178 }
2179
2180 return 0;
2181 }
2182
2183
2184 /**
2185 * hostapd_interface_init_bss - Read configuration file and init BSS data
2186 *
2187 * This function is used to parse configuration file for a BSS. This BSS is
2188 * added to an existing interface sharing the same radio (if any) or a new
2189 * interface is created if this is the first interface on a radio. This
2190 * allocate memory for the BSS. No actual driver operations are started.
2191 *
2192 * This is similar to hostapd_interface_init(), but for a case where the
2193 * configuration is used to add a single BSS instead of all BSSes for a radio.
2194 */
2195 struct hostapd_iface *
2196 hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy,
2197 const char *config_fname, int debug)
2198 {
2199 struct hostapd_iface *new_iface = NULL, *iface = NULL;
2200 struct hostapd_data *hapd;
2201 int k;
2202 size_t i, bss_idx;
2203
2204 if (!phy || !*phy)
2205 return NULL;
2206
2207 for (i = 0; i < interfaces->count; i++) {
2208 if (os_strcmp(interfaces->iface[i]->phy, phy) == 0) {
2209 iface = interfaces->iface[i];
2210 break;
2211 }
2212 }
2213
2214 wpa_printf(MSG_INFO, "Configuration file: %s (phy %s)%s",
2215 config_fname, phy, iface ? "" : " --> new PHY");
2216 if (iface) {
2217 struct hostapd_config *conf;
2218 struct hostapd_bss_config **tmp_conf;
2219 struct hostapd_data **tmp_bss;
2220 struct hostapd_bss_config *bss;
2221 const char *ifname;
2222
2223 /* Add new BSS to existing iface */
2224 conf = interfaces->config_read_cb(config_fname);
2225 if (conf == NULL)
2226 return NULL;
2227 if (conf->num_bss > 1) {
2228 wpa_printf(MSG_ERROR, "Multiple BSSes specified in BSS-config");
2229 hostapd_config_free(conf);
2230 return NULL;
2231 }
2232
2233 ifname = conf->bss[0]->iface;
2234 if (ifname[0] != '\0' && ifname_in_use(interfaces, ifname)) {
2235 wpa_printf(MSG_ERROR,
2236 "Interface name %s already in use", ifname);
2237 hostapd_config_free(conf);
2238 return NULL;
2239 }
2240
2241 tmp_conf = os_realloc_array(
2242 iface->conf->bss, iface->conf->num_bss + 1,
2243 sizeof(struct hostapd_bss_config *));
2244 tmp_bss = os_realloc_array(iface->bss, iface->num_bss + 1,
2245 sizeof(struct hostapd_data *));
2246 if (tmp_bss)
2247 iface->bss = tmp_bss;
2248 if (tmp_conf) {
2249 iface->conf->bss = tmp_conf;
2250 iface->conf->last_bss = tmp_conf[0];
2251 }
2252 if (tmp_bss == NULL || tmp_conf == NULL) {
2253 hostapd_config_free(conf);
2254 return NULL;
2255 }
2256 bss = iface->conf->bss[iface->conf->num_bss] = conf->bss[0];
2257 iface->conf->num_bss++;
2258
2259 hapd = hostapd_alloc_bss_data(iface, iface->conf, bss);
2260 if (hapd == NULL) {
2261 iface->conf->num_bss--;
2262 hostapd_config_free(conf);
2263 return NULL;
2264 }
2265 iface->conf->last_bss = bss;
2266 iface->bss[iface->num_bss] = hapd;
2267 hapd->msg_ctx = hapd;
2268
2269 bss_idx = iface->num_bss++;
2270 conf->num_bss--;
2271 conf->bss[0] = NULL;
2272 hostapd_config_free(conf);
2273 } else {
2274 /* Add a new iface with the first BSS */
2275 new_iface = iface = hostapd_init(interfaces, config_fname);
2276 if (!iface)
2277 return NULL;
2278 os_strlcpy(iface->phy, phy, sizeof(iface->phy));
2279 iface->interfaces = interfaces;
2280 bss_idx = 0;
2281 }
2282
2283 for (k = 0; k < debug; k++) {
2284 if (iface->bss[bss_idx]->conf->logger_stdout_level > 0)
2285 iface->bss[bss_idx]->conf->logger_stdout_level--;
2286 }
2287
2288 if (iface->conf->bss[bss_idx]->iface[0] == '\0' &&
2289 !hostapd_drv_none(iface->bss[bss_idx])) {
2290 wpa_printf(MSG_ERROR, "Interface name not specified in %s",
2291 config_fname);
2292 if (new_iface)
2293 hostapd_interface_deinit_free(new_iface);
2294 return NULL;
2295 }
2296
2297 return iface;
2298 }
2299
2300
2301 void hostapd_interface_deinit_free(struct hostapd_iface *iface)
2302 {
2303 const struct wpa_driver_ops *driver;
2304 void *drv_priv;
2305
2306 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
2307 if (iface == NULL)
2308 return;
2309 wpa_printf(MSG_DEBUG, "%s: num_bss=%u conf->num_bss=%u",
2310 __func__, (unsigned int) iface->num_bss,
2311 (unsigned int) iface->conf->num_bss);
2312 driver = iface->bss[0]->driver;
2313 drv_priv = iface->bss[0]->drv_priv;
2314 hostapd_interface_deinit(iface);
2315 wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
2316 __func__, driver, drv_priv);
2317 if (driver && driver->hapd_deinit && drv_priv) {
2318 driver->hapd_deinit(drv_priv);
2319 iface->bss[0]->drv_priv = NULL;
2320 }
2321 hostapd_interface_free(iface);
2322 }
2323
2324
2325 static void hostapd_deinit_driver(const struct wpa_driver_ops *driver,
2326 void *drv_priv,
2327 struct hostapd_iface *hapd_iface)
2328 {
2329 size_t j;
2330
2331 wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
2332 __func__, driver, drv_priv);
2333 if (driver && driver->hapd_deinit && drv_priv) {
2334 driver->hapd_deinit(drv_priv);
2335 for (j = 0; j < hapd_iface->num_bss; j++) {
2336 wpa_printf(MSG_DEBUG, "%s:bss[%d]->drv_priv=%p",
2337 __func__, (int) j,
2338 hapd_iface->bss[j]->drv_priv);
2339 if (hapd_iface->bss[j]->drv_priv == drv_priv)
2340 hapd_iface->bss[j]->drv_priv = NULL;
2341 }
2342 }
2343 }
2344
2345
2346 int hostapd_enable_iface(struct hostapd_iface *hapd_iface)
2347 {
2348 size_t j;
2349
2350 if (hapd_iface->bss[0]->drv_priv != NULL) {
2351 wpa_printf(MSG_ERROR, "Interface %s already enabled",
2352 hapd_iface->conf->bss[0]->iface);
2353 return -1;
2354 }
2355
2356 wpa_printf(MSG_DEBUG, "Enable interface %s",
2357 hapd_iface->conf->bss[0]->iface);
2358
2359 for (j = 0; j < hapd_iface->num_bss; j++)
2360 hostapd_set_security_params(hapd_iface->conf->bss[j], 1);
2361 if (hostapd_config_check(hapd_iface->conf, 1) < 0) {
2362 wpa_printf(MSG_INFO, "Invalid configuration - cannot enable");
2363 return -1;
2364 }
2365
2366 if (hapd_iface->interfaces == NULL ||
2367 hapd_iface->interfaces->driver_init == NULL ||
2368 hapd_iface->interfaces->driver_init(hapd_iface))
2369 return -1;
2370
2371 if (hostapd_setup_interface(hapd_iface)) {
2372 hostapd_deinit_driver(hapd_iface->bss[0]->driver,
2373 hapd_iface->bss[0]->drv_priv,
2374 hapd_iface);
2375 return -1;
2376 }
2377
2378 return 0;
2379 }
2380
2381
2382 int hostapd_reload_iface(struct hostapd_iface *hapd_iface)
2383 {
2384 size_t j;
2385
2386 wpa_printf(MSG_DEBUG, "Reload interface %s",
2387 hapd_iface->conf->bss[0]->iface);
2388 for (j = 0; j < hapd_iface->num_bss; j++)
2389 hostapd_set_security_params(hapd_iface->conf->bss[j], 1);
2390 if (hostapd_config_check(hapd_iface->conf, 1) < 0) {
2391 wpa_printf(MSG_ERROR, "Updated configuration is invalid");
2392 return -1;
2393 }
2394 hostapd_clear_old(hapd_iface);
2395 for (j = 0; j < hapd_iface->num_bss; j++)
2396 hostapd_reload_bss(hapd_iface->bss[j]);
2397
2398 return 0;
2399 }
2400
2401
2402 int hostapd_disable_iface(struct hostapd_iface *hapd_iface)
2403 {
2404 size_t j;
2405 const struct wpa_driver_ops *driver;
2406 void *drv_priv;
2407
2408 if (hapd_iface == NULL)
2409 return -1;
2410
2411 if (hapd_iface->bss[0]->drv_priv == NULL) {
2412 wpa_printf(MSG_INFO, "Interface %s already disabled",
2413 hapd_iface->conf->bss[0]->iface);
2414 return -1;
2415 }
2416
2417 wpa_msg(hapd_iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
2418 driver = hapd_iface->bss[0]->driver;
2419 drv_priv = hapd_iface->bss[0]->drv_priv;
2420
2421 hapd_iface->driver_ap_teardown =
2422 !!(hapd_iface->drv_flags &
2423 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
2424
2425 /* same as hostapd_interface_deinit without deinitializing ctrl-iface */
2426 for (j = 0; j < hapd_iface->num_bss; j++) {
2427 struct hostapd_data *hapd = hapd_iface->bss[j];
2428 hostapd_bss_deinit_no_free(hapd);
2429 hostapd_free_hapd_data(hapd);
2430 }
2431
2432 hostapd_deinit_driver(driver, drv_priv, hapd_iface);
2433
2434 /* From hostapd_cleanup_iface: These were initialized in
2435 * hostapd_setup_interface and hostapd_setup_interface_complete
2436 */
2437 hostapd_cleanup_iface_partial(hapd_iface);
2438
2439 wpa_printf(MSG_DEBUG, "Interface %s disabled",
2440 hapd_iface->bss[0]->conf->iface);
2441 hostapd_set_state(hapd_iface, HAPD_IFACE_DISABLED);
2442 return 0;
2443 }
2444
2445
2446 static struct hostapd_iface *
2447 hostapd_iface_alloc(struct hapd_interfaces *interfaces)
2448 {
2449 struct hostapd_iface **iface, *hapd_iface;
2450
2451 iface = os_realloc_array(interfaces->iface, interfaces->count + 1,
2452 sizeof(struct hostapd_iface *));
2453 if (iface == NULL)
2454 return NULL;
2455 interfaces->iface = iface;
2456 hapd_iface = interfaces->iface[interfaces->count] =
2457 hostapd_alloc_iface();
2458 if (hapd_iface == NULL) {
2459 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for "
2460 "the interface", __func__);
2461 return NULL;
2462 }
2463 interfaces->count++;
2464 hapd_iface->interfaces = interfaces;
2465
2466 return hapd_iface;
2467 }
2468
2469
2470 static struct hostapd_config *
2471 hostapd_config_alloc(struct hapd_interfaces *interfaces, const char *ifname,
2472 const char *ctrl_iface, const char *driver)
2473 {
2474 struct hostapd_bss_config *bss;
2475 struct hostapd_config *conf;
2476
2477 /* Allocates memory for bss and conf */
2478 conf = hostapd_config_defaults();
2479 if (conf == NULL) {
2480 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for "
2481 "configuration", __func__);
2482 return NULL;
2483 }
2484
2485 if (driver) {
2486 int j;
2487
2488 for (j = 0; wpa_drivers[j]; j++) {
2489 if (os_strcmp(driver, wpa_drivers[j]->name) == 0) {
2490 conf->driver = wpa_drivers[j];
2491 goto skip;
2492 }
2493 }
2494
2495 wpa_printf(MSG_ERROR,
2496 "Invalid/unknown driver '%s' - registering the default driver",
2497 driver);
2498 }
2499
2500 conf->driver = wpa_drivers[0];
2501 if (conf->driver == NULL) {
2502 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
2503 hostapd_config_free(conf);
2504 return NULL;
2505 }
2506
2507 skip:
2508 bss = conf->last_bss = conf->bss[0];
2509
2510 os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
2511 bss->ctrl_interface = os_strdup(ctrl_iface);
2512 if (bss->ctrl_interface == NULL) {
2513 hostapd_config_free(conf);
2514 return NULL;
2515 }
2516
2517 /* Reading configuration file skipped, will be done in SET!
2518 * From reading the configuration till the end has to be done in
2519 * SET
2520 */
2521 return conf;
2522 }
2523
2524
2525 static int hostapd_data_alloc(struct hostapd_iface *hapd_iface,
2526 struct hostapd_config *conf)
2527 {
2528 size_t i;
2529 struct hostapd_data *hapd;
2530
2531 hapd_iface->bss = os_calloc(conf->num_bss,
2532 sizeof(struct hostapd_data *));
2533 if (hapd_iface->bss == NULL)
2534 return -1;
2535
2536 for (i = 0; i < conf->num_bss; i++) {
2537 hapd = hapd_iface->bss[i] =
2538 hostapd_alloc_bss_data(hapd_iface, conf, conf->bss[i]);
2539 if (hapd == NULL) {
2540 while (i > 0) {
2541 i--;
2542 os_free(hapd_iface->bss[i]);
2543 hapd_iface->bss[i] = NULL;
2544 }
2545 os_free(hapd_iface->bss);
2546 hapd_iface->bss = NULL;
2547 return -1;
2548 }
2549 hapd->msg_ctx = hapd;
2550 }
2551
2552 hapd_iface->conf = conf;
2553 hapd_iface->num_bss = conf->num_bss;
2554
2555 return 0;
2556 }
2557
2558
2559 int hostapd_add_iface(struct hapd_interfaces *interfaces, char *buf)
2560 {
2561 struct hostapd_config *conf = NULL;
2562 struct hostapd_iface *hapd_iface = NULL, *new_iface = NULL;
2563 struct hostapd_data *hapd;
2564 char *ptr;
2565 size_t i, j;
2566 const char *conf_file = NULL, *phy_name = NULL;
2567
2568 if (os_strncmp(buf, "bss_config=", 11) == 0) {
2569 char *pos;
2570 phy_name = buf + 11;
2571 pos = os_strchr(phy_name, ':');
2572 if (!pos)
2573 return -1;
2574 *pos++ = '\0';
2575 conf_file = pos;
2576 if (!os_strlen(conf_file))
2577 return -1;
2578
2579 hapd_iface = hostapd_interface_init_bss(interfaces, phy_name,
2580 conf_file, 0);
2581 if (!hapd_iface)
2582 return -1;
2583 for (j = 0; j < interfaces->count; j++) {
2584 if (interfaces->iface[j] == hapd_iface)
2585 break;
2586 }
2587 if (j == interfaces->count) {
2588 struct hostapd_iface **tmp;
2589 tmp = os_realloc_array(interfaces->iface,
2590 interfaces->count + 1,
2591 sizeof(struct hostapd_iface *));
2592 if (!tmp) {
2593 hostapd_interface_deinit_free(hapd_iface);
2594 return -1;
2595 }
2596 interfaces->iface = tmp;
2597 interfaces->iface[interfaces->count++] = hapd_iface;
2598 new_iface = hapd_iface;
2599 }
2600
2601 if (new_iface) {
2602 if (interfaces->driver_init(hapd_iface))
2603 goto fail;
2604
2605 if (hostapd_setup_interface(hapd_iface)) {
2606 hostapd_deinit_driver(
2607 hapd_iface->bss[0]->driver,
2608 hapd_iface->bss[0]->drv_priv,
2609 hapd_iface);
2610 goto fail;
2611 }
2612 } else {
2613 /* Assign new BSS with bss[0]'s driver info */
2614 hapd = hapd_iface->bss[hapd_iface->num_bss - 1];
2615 hapd->driver = hapd_iface->bss[0]->driver;
2616 hapd->drv_priv = hapd_iface->bss[0]->drv_priv;
2617 os_memcpy(hapd->own_addr, hapd_iface->bss[0]->own_addr,
2618 ETH_ALEN);
2619
2620 if (start_ctrl_iface_bss(hapd) < 0 ||
2621 (hapd_iface->state == HAPD_IFACE_ENABLED &&
2622 hostapd_setup_bss(hapd, -1))) {
2623 hostapd_cleanup(hapd);
2624 hapd_iface->bss[hapd_iface->num_bss - 1] = NULL;
2625 hapd_iface->conf->num_bss--;
2626 hapd_iface->num_bss--;
2627 wpa_printf(MSG_DEBUG, "%s: free hapd %p %s",
2628 __func__, hapd, hapd->conf->iface);
2629 hostapd_config_free_bss(hapd->conf);
2630 hapd->conf = NULL;
2631 os_free(hapd);
2632 return -1;
2633 }
2634 }
2635 return 0;
2636 }
2637
2638 ptr = os_strchr(buf, ' ');
2639 if (ptr == NULL)
2640 return -1;
2641 *ptr++ = '\0';
2642
2643 if (os_strncmp(ptr, "config=", 7) == 0)
2644 conf_file = ptr + 7;
2645
2646 for (i = 0; i < interfaces->count; i++) {
2647 if (!os_strcmp(interfaces->iface[i]->conf->bss[0]->iface,
2648 buf)) {
2649 wpa_printf(MSG_INFO, "Cannot add interface - it "
2650 "already exists");
2651 return -1;
2652 }
2653 }
2654
2655 hapd_iface = hostapd_iface_alloc(interfaces);
2656 if (hapd_iface == NULL) {
2657 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
2658 "for interface", __func__);
2659 goto fail;
2660 }
2661 new_iface = hapd_iface;
2662
2663 if (conf_file && interfaces->config_read_cb) {
2664 conf = interfaces->config_read_cb(conf_file);
2665 if (conf && conf->bss)
2666 os_strlcpy(conf->bss[0]->iface, buf,
2667 sizeof(conf->bss[0]->iface));
2668 } else {
2669 char *driver = os_strchr(ptr, ' ');
2670
2671 if (driver)
2672 *driver++ = '\0';
2673 conf = hostapd_config_alloc(interfaces, buf, ptr, driver);
2674 }
2675
2676 if (conf == NULL || conf->bss == NULL) {
2677 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
2678 "for configuration", __func__);
2679 goto fail;
2680 }
2681
2682 if (hostapd_data_alloc(hapd_iface, conf) < 0) {
2683 wpa_printf(MSG_ERROR, "%s: Failed to allocate memory "
2684 "for hostapd", __func__);
2685 goto fail;
2686 }
2687 conf = NULL;
2688
2689 if (start_ctrl_iface(hapd_iface) < 0)
2690 goto fail;
2691
2692 wpa_printf(MSG_INFO, "Add interface '%s'",
2693 hapd_iface->conf->bss[0]->iface);
2694
2695 return 0;
2696
2697 fail:
2698 if (conf)
2699 hostapd_config_free(conf);
2700 if (hapd_iface) {
2701 if (hapd_iface->bss) {
2702 for (i = 0; i < hapd_iface->num_bss; i++) {
2703 hapd = hapd_iface->bss[i];
2704 if (!hapd)
2705 continue;
2706 if (hapd_iface->interfaces &&
2707 hapd_iface->interfaces->ctrl_iface_deinit)
2708 hapd_iface->interfaces->
2709 ctrl_iface_deinit(hapd);
2710 wpa_printf(MSG_DEBUG, "%s: free hapd %p (%s)",
2711 __func__, hapd_iface->bss[i],
2712 hapd->conf->iface);
2713 hostapd_cleanup(hapd);
2714 os_free(hapd);
2715 hapd_iface->bss[i] = NULL;
2716 }
2717 os_free(hapd_iface->bss);
2718 hapd_iface->bss = NULL;
2719 }
2720 if (new_iface) {
2721 interfaces->count--;
2722 interfaces->iface[interfaces->count] = NULL;
2723 }
2724 hostapd_cleanup_iface(hapd_iface);
2725 }
2726 return -1;
2727 }
2728
2729
2730 static int hostapd_remove_bss(struct hostapd_iface *iface, unsigned int idx)
2731 {
2732 size_t i;
2733
2734 wpa_printf(MSG_INFO, "Remove BSS '%s'", iface->conf->bss[idx]->iface);
2735
2736 /* Remove hostapd_data only if it has already been initialized */
2737 if (idx < iface->num_bss) {
2738 struct hostapd_data *hapd = iface->bss[idx];
2739
2740 hostapd_bss_deinit(hapd);
2741 wpa_printf(MSG_DEBUG, "%s: free hapd %p (%s)",
2742 __func__, hapd, hapd->conf->iface);
2743 hostapd_config_free_bss(hapd->conf);
2744 hapd->conf = NULL;
2745 os_free(hapd);
2746
2747 iface->num_bss--;
2748
2749 for (i = idx; i < iface->num_bss; i++)
2750 iface->bss[i] = iface->bss[i + 1];
2751 } else {
2752 hostapd_config_free_bss(iface->conf->bss[idx]);
2753 iface->conf->bss[idx] = NULL;
2754 }
2755
2756 iface->conf->num_bss--;
2757 for (i = idx; i < iface->conf->num_bss; i++)
2758 iface->conf->bss[i] = iface->conf->bss[i + 1];
2759
2760 return 0;
2761 }
2762
2763
2764 int hostapd_remove_iface(struct hapd_interfaces *interfaces, char *buf)
2765 {
2766 struct hostapd_iface *hapd_iface;
2767 size_t i, j, k = 0;
2768
2769 for (i = 0; i < interfaces->count; i++) {
2770 hapd_iface = interfaces->iface[i];
2771 if (hapd_iface == NULL)
2772 return -1;
2773 if (!os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
2774 wpa_printf(MSG_INFO, "Remove interface '%s'", buf);
2775 hapd_iface->driver_ap_teardown =
2776 !!(hapd_iface->drv_flags &
2777 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
2778
2779 hostapd_interface_deinit_free(hapd_iface);
2780 k = i;
2781 while (k < (interfaces->count - 1)) {
2782 interfaces->iface[k] =
2783 interfaces->iface[k + 1];
2784 k++;
2785 }
2786 interfaces->count--;
2787 return 0;
2788 }
2789
2790 for (j = 0; j < hapd_iface->conf->num_bss; j++) {
2791 if (!os_strcmp(hapd_iface->conf->bss[j]->iface, buf)) {
2792 hapd_iface->driver_ap_teardown =
2793 !(hapd_iface->drv_flags &
2794 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
2795 return hostapd_remove_bss(hapd_iface, j);
2796 }
2797 }
2798 }
2799 return -1;
2800 }
2801
2802
2803 /**
2804 * hostapd_new_assoc_sta - Notify that a new station associated with the AP
2805 * @hapd: Pointer to BSS data
2806 * @sta: Pointer to the associated STA data
2807 * @reassoc: 1 to indicate this was a re-association; 0 = first association
2808 *
2809 * This function will be called whenever a station associates with the AP. It
2810 * can be called from ieee802_11.c for drivers that export MLME to hostapd and
2811 * from drv_callbacks.c based on driver events for drivers that take care of
2812 * management frames (IEEE 802.11 authentication and association) internally.
2813 */
2814 void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
2815 int reassoc)
2816 {
2817 if (hapd->tkip_countermeasures) {
2818 hostapd_drv_sta_deauth(hapd, sta->addr,
2819 WLAN_REASON_MICHAEL_MIC_FAILURE);
2820 return;
2821 }
2822
2823 hostapd_prune_associations(hapd, sta->addr);
2824 ap_sta_clear_disconnect_timeouts(hapd, sta);
2825
2826 /* IEEE 802.11F (IAPP) */
2827 if (hapd->conf->ieee802_11f)
2828 iapp_new_station(hapd->iapp, sta);
2829
2830 #ifdef CONFIG_P2P
2831 if (sta->p2p_ie == NULL && !sta->no_p2p_set) {
2832 sta->no_p2p_set = 1;
2833 hapd->num_sta_no_p2p++;
2834 if (hapd->num_sta_no_p2p == 1)
2835 hostapd_p2p_non_p2p_sta_connected(hapd);
2836 }
2837 #endif /* CONFIG_P2P */
2838
2839 /* Start accounting here, if IEEE 802.1X and WPA are not used.
2840 * IEEE 802.1X/WPA code will start accounting after the station has
2841 * been authorized. */
2842 if (!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) {
2843 ap_sta_set_authorized(hapd, sta, 1);
2844 os_get_reltime(&sta->connected_time);
2845 accounting_sta_start(hapd, sta);
2846 }
2847
2848 /* Start IEEE 802.1X authentication process for new stations */
2849 ieee802_1x_new_station(hapd, sta);
2850 if (reassoc) {
2851 if (sta->auth_alg != WLAN_AUTH_FT &&
2852 !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)))
2853 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH);
2854 } else
2855 wpa_auth_sta_associated(hapd->wpa_auth, sta->wpa_sm);
2856
2857 if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_WIRED) {
2858 if (eloop_cancel_timeout(ap_handle_timer, hapd, sta) > 0) {
2859 wpa_printf(MSG_DEBUG,
2860 "%s: %s: canceled wired ap_handle_timer timeout for "
2861 MACSTR,
2862 hapd->conf->iface, __func__,
2863 MAC2STR(sta->addr));
2864 }
2865 } else if (!(hapd->iface->drv_flags &
2866 WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) {
2867 wpa_printf(MSG_DEBUG,
2868 "%s: %s: reschedule ap_handle_timer timeout for "
2869 MACSTR " (%d seconds - ap_max_inactivity)",
2870 hapd->conf->iface, __func__, MAC2STR(sta->addr),
2871 hapd->conf->ap_max_inactivity);
2872 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
2873 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
2874 ap_handle_timer, hapd, sta);
2875 }
2876 }
2877
2878
2879 const char * hostapd_state_text(enum hostapd_iface_state s)
2880 {
2881 switch (s) {
2882 case HAPD_IFACE_UNINITIALIZED:
2883 return "UNINITIALIZED";
2884 case HAPD_IFACE_DISABLED:
2885 return "DISABLED";
2886 case HAPD_IFACE_COUNTRY_UPDATE:
2887 return "COUNTRY_UPDATE";
2888 case HAPD_IFACE_ACS:
2889 return "ACS";
2890 case HAPD_IFACE_HT_SCAN:
2891 return "HT_SCAN";
2892 case HAPD_IFACE_DFS:
2893 return "DFS";
2894 case HAPD_IFACE_ENABLED:
2895 return "ENABLED";
2896 }
2897
2898 return "UNKNOWN";
2899 }
2900
2901
2902 void hostapd_set_state(struct hostapd_iface *iface, enum hostapd_iface_state s)
2903 {
2904 wpa_printf(MSG_INFO, "%s: interface state %s->%s",
2905 iface->conf ? iface->conf->bss[0]->iface : "N/A",
2906 hostapd_state_text(iface->state), hostapd_state_text(s));
2907 iface->state = s;
2908 }
2909
2910
2911 int hostapd_csa_in_progress(struct hostapd_iface *iface)
2912 {
2913 unsigned int i;
2914
2915 for (i = 0; i < iface->num_bss; i++)
2916 if (iface->bss[i]->csa_in_progress)
2917 return 1;
2918 return 0;
2919 }
2920
2921
2922 #ifdef NEED_AP_MLME
2923
2924 static void free_beacon_data(struct beacon_data *beacon)
2925 {
2926 os_free(beacon->head);
2927 beacon->head = NULL;
2928 os_free(beacon->tail);
2929 beacon->tail = NULL;
2930 os_free(beacon->probe_resp);
2931 beacon->probe_resp = NULL;
2932 os_free(beacon->beacon_ies);
2933 beacon->beacon_ies = NULL;
2934 os_free(beacon->proberesp_ies);
2935 beacon->proberesp_ies = NULL;
2936 os_free(beacon->assocresp_ies);
2937 beacon->assocresp_ies = NULL;
2938 }
2939
2940
2941 static int hostapd_build_beacon_data(struct hostapd_data *hapd,
2942 struct beacon_data *beacon)
2943 {
2944 struct wpabuf *beacon_extra, *proberesp_extra, *assocresp_extra;
2945 struct wpa_driver_ap_params params;
2946 int ret;
2947
2948 os_memset(beacon, 0, sizeof(*beacon));
2949 ret = ieee802_11_build_ap_params(hapd, &params);
2950 if (ret < 0)
2951 return ret;
2952
2953 ret = hostapd_build_ap_extra_ies(hapd, &beacon_extra,
2954 &proberesp_extra,
2955 &assocresp_extra);
2956 if (ret)
2957 goto free_ap_params;
2958
2959 ret = -1;
2960 beacon->head = os_memdup(params.head, params.head_len);
2961 if (!beacon->head)
2962 goto free_ap_extra_ies;
2963
2964 beacon->head_len = params.head_len;
2965
2966 beacon->tail = os_memdup(params.tail, params.tail_len);
2967 if (!beacon->tail)
2968 goto free_beacon;
2969
2970 beacon->tail_len = params.tail_len;
2971
2972 if (params.proberesp != NULL) {
2973 beacon->probe_resp = os_memdup(params.proberesp,
2974 params.proberesp_len);
2975 if (!beacon->probe_resp)
2976 goto free_beacon;
2977
2978 beacon->probe_resp_len = params.proberesp_len;
2979 }
2980
2981 /* copy the extra ies */
2982 if (beacon_extra) {
2983 beacon->beacon_ies = os_memdup(beacon_extra->buf,
2984 wpabuf_len(beacon_extra));
2985 if (!beacon->beacon_ies)
2986 goto free_beacon;
2987
2988 beacon->beacon_ies_len = wpabuf_len(beacon_extra);
2989 }
2990
2991 if (proberesp_extra) {
2992 beacon->proberesp_ies = os_memdup(proberesp_extra->buf,
2993 wpabuf_len(proberesp_extra));
2994 if (!beacon->proberesp_ies)
2995 goto free_beacon;
2996
2997 beacon->proberesp_ies_len = wpabuf_len(proberesp_extra);
2998 }
2999
3000 if (assocresp_extra) {
3001 beacon->assocresp_ies = os_memdup(assocresp_extra->buf,
3002 wpabuf_len(assocresp_extra));
3003 if (!beacon->assocresp_ies)
3004 goto free_beacon;
3005
3006 beacon->assocresp_ies_len = wpabuf_len(assocresp_extra);
3007 }
3008
3009 ret = 0;
3010 free_beacon:
3011 /* if the function fails, the caller should not free beacon data */
3012 if (ret)
3013 free_beacon_data(beacon);
3014
3015 free_ap_extra_ies:
3016 hostapd_free_ap_extra_ies(hapd, beacon_extra, proberesp_extra,
3017 assocresp_extra);
3018 free_ap_params:
3019 ieee802_11_free_ap_params(&params);
3020 return ret;
3021 }
3022
3023
3024 /*
3025 * TODO: This flow currently supports only changing channel and width within
3026 * the same hw_mode. Any other changes to MAC parameters or provided settings
3027 * are not supported.
3028 */
3029 static int hostapd_change_config_freq(struct hostapd_data *hapd,
3030 struct hostapd_config *conf,
3031 struct hostapd_freq_params *params,
3032 struct hostapd_freq_params *old_params)
3033 {
3034 int channel;
3035
3036 if (!params->channel) {
3037 /* check if the new channel is supported by hw */
3038 params->channel = hostapd_hw_get_channel(hapd, params->freq);
3039 }
3040
3041 channel = params->channel;
3042 if (!channel)
3043 return -1;
3044
3045 /* if a pointer to old_params is provided we save previous state */
3046 if (old_params &&
3047 hostapd_set_freq_params(old_params, conf->hw_mode,
3048 hostapd_hw_get_freq(hapd, conf->channel),
3049 conf->channel, conf->ieee80211n,
3050 conf->ieee80211ac,
3051 conf->secondary_channel,
3052 conf->vht_oper_chwidth,
3053 conf->vht_oper_centr_freq_seg0_idx,
3054 conf->vht_oper_centr_freq_seg1_idx,
3055 conf->vht_capab))
3056 return -1;
3057
3058 switch (params->bandwidth) {
3059 case 0:
3060 case 20:
3061 case 40:
3062 conf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT;
3063 break;
3064 case 80:
3065 if (params->center_freq2)
3066 conf->vht_oper_chwidth = VHT_CHANWIDTH_80P80MHZ;
3067 else
3068 conf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ;
3069 break;
3070 case 160:
3071 conf->vht_oper_chwidth = VHT_CHANWIDTH_160MHZ;
3072 break;
3073 default:
3074 return -1;
3075 }
3076
3077 conf->channel = channel;
3078 conf->ieee80211n = params->ht_enabled;
3079 conf->secondary_channel = params->sec_channel_offset;
3080 ieee80211_freq_to_chan(params->center_freq1,
3081 &conf->vht_oper_centr_freq_seg0_idx);
3082 ieee80211_freq_to_chan(params->center_freq2,
3083 &conf->vht_oper_centr_freq_seg1_idx);
3084
3085 /* TODO: maybe call here hostapd_config_check here? */
3086
3087 return 0;
3088 }
3089
3090
3091 static int hostapd_fill_csa_settings(struct hostapd_data *hapd,
3092 struct csa_settings *settings)
3093 {
3094 struct hostapd_iface *iface = hapd->iface;
3095 struct hostapd_freq_params old_freq;
3096 int ret;
3097 u8 chan, vht_bandwidth;
3098
3099 os_memset(&old_freq, 0, sizeof(old_freq));
3100 if (!iface || !iface->freq || hapd->csa_in_progress)
3101 return -1;
3102
3103 switch (settings->freq_params.bandwidth) {
3104 case 80:
3105 if (settings->freq_params.center_freq2)
3106 vht_bandwidth = VHT_CHANWIDTH_80P80MHZ;
3107 else
3108 vht_bandwidth = VHT_CHANWIDTH_80MHZ;
3109 break;
3110 case 160:
3111 vht_bandwidth = VHT_CHANWIDTH_160MHZ;
3112 break;
3113 default:
3114 vht_bandwidth = VHT_CHANWIDTH_USE_HT;
3115 break;
3116 }
3117
3118 if (ieee80211_freq_to_channel_ext(
3119 settings->freq_params.freq,
3120 settings->freq_params.sec_channel_offset,
3121 vht_bandwidth,
3122 &hapd->iface->cs_oper_class,
3123 &chan) == NUM_HOSTAPD_MODES) {
3124 wpa_printf(MSG_DEBUG,
3125 "invalid frequency for channel switch (freq=%d, sec_channel_offset=%d, vht_enabled=%d)",
3126 settings->freq_params.freq,
3127 settings->freq_params.sec_channel_offset,
3128 settings->freq_params.vht_enabled);
3129 return -1;
3130 }
3131
3132 settings->freq_params.channel = chan;
3133
3134 ret = hostapd_change_config_freq(iface->bss[0], iface->conf,
3135 &settings->freq_params,
3136 &old_freq);
3137 if (ret)
3138 return ret;
3139
3140 ret = hostapd_build_beacon_data(hapd, &settings->beacon_after);
3141
3142 /* change back the configuration */
3143 hostapd_change_config_freq(iface->bss[0], iface->conf,
3144 &old_freq, NULL);
3145
3146 if (ret)
3147 return ret;
3148
3149 /* set channel switch parameters for csa ie */
3150 hapd->cs_freq_params = settings->freq_params;
3151 hapd->cs_count = settings->cs_count;
3152 hapd->cs_block_tx = settings->block_tx;
3153
3154 ret = hostapd_build_beacon_data(hapd, &settings->beacon_csa);
3155 if (ret) {
3156 free_beacon_data(&settings->beacon_after);
3157 return ret;
3158 }
3159
3160 settings->counter_offset_beacon[0] = hapd->cs_c_off_beacon;
3161 settings->counter_offset_presp[0] = hapd->cs_c_off_proberesp;
3162 settings->counter_offset_beacon[1] = hapd->cs_c_off_ecsa_beacon;
3163 settings->counter_offset_presp[1] = hapd->cs_c_off_ecsa_proberesp;
3164
3165 return 0;
3166 }
3167
3168
3169 void hostapd_cleanup_cs_params(struct hostapd_data *hapd)
3170 {
3171 os_memset(&hapd->cs_freq_params, 0, sizeof(hapd->cs_freq_params));
3172 hapd->cs_count = 0;
3173 hapd->cs_block_tx = 0;
3174 hapd->cs_c_off_beacon = 0;
3175 hapd->cs_c_off_proberesp = 0;
3176 hapd->csa_in_progress = 0;
3177 hapd->cs_c_off_ecsa_beacon = 0;
3178 hapd->cs_c_off_ecsa_proberesp = 0;
3179 }
3180
3181
3182 int hostapd_switch_channel(struct hostapd_data *hapd,
3183 struct csa_settings *settings)
3184 {
3185 int ret;
3186
3187 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA)) {
3188 wpa_printf(MSG_INFO, "CSA is not supported");
3189 return -1;
3190 }
3191
3192 ret = hostapd_fill_csa_settings(hapd, settings);
3193 if (ret)
3194 return ret;
3195
3196 ret = hostapd_drv_switch_channel(hapd, settings);
3197 free_beacon_data(&settings->beacon_csa);
3198 free_beacon_data(&settings->beacon_after);
3199
3200 if (ret) {
3201 /* if we failed, clean cs parameters */
3202 hostapd_cleanup_cs_params(hapd);
3203 return ret;
3204 }
3205
3206 hapd->csa_in_progress = 1;
3207 return 0;
3208 }
3209
3210
3211 void
3212 hostapd_switch_channel_fallback(struct hostapd_iface *iface,
3213 const struct hostapd_freq_params *freq_params)
3214 {
3215 int vht_seg0_idx = 0, vht_seg1_idx = 0, vht_bw = VHT_CHANWIDTH_USE_HT;
3216 unsigned int i;
3217
3218 wpa_printf(MSG_DEBUG, "Restarting all CSA-related BSSes");
3219
3220 if (freq_params->center_freq1)
3221 vht_seg0_idx = 36 + (freq_params->center_freq1 - 5180) / 5;
3222 if (freq_params->center_freq2)
3223 vht_seg1_idx = 36 + (freq_params->center_freq2 - 5180) / 5;
3224
3225 switch (freq_params->bandwidth) {
3226 case 0:
3227 case 20:
3228 case 40:
3229 vht_bw = VHT_CHANWIDTH_USE_HT;
3230 break;
3231 case 80:
3232 if (freq_params->center_freq2)
3233 vht_bw = VHT_CHANWIDTH_80P80MHZ;
3234 else
3235 vht_bw = VHT_CHANWIDTH_80MHZ;
3236 break;
3237 case 160:
3238 vht_bw = VHT_CHANWIDTH_160MHZ;
3239 break;
3240 default:
3241 wpa_printf(MSG_WARNING, "Unknown CSA bandwidth: %d",
3242 freq_params->bandwidth);
3243 break;
3244 }
3245
3246 iface->freq = freq_params->freq;
3247 iface->conf->channel = freq_params->channel;
3248 iface->conf->secondary_channel = freq_params->sec_channel_offset;
3249 iface->conf->vht_oper_centr_freq_seg0_idx = vht_seg0_idx;
3250 iface->conf->vht_oper_centr_freq_seg1_idx = vht_seg1_idx;
3251 iface->conf->vht_oper_chwidth = vht_bw;
3252 iface->conf->ieee80211n = freq_params->ht_enabled;
3253 iface->conf->ieee80211ac = freq_params->vht_enabled;
3254
3255 /*
3256 * cs_params must not be cleared earlier because the freq_params
3257 * argument may actually point to one of these.
3258 */
3259 for (i = 0; i < iface->num_bss; i++)
3260 hostapd_cleanup_cs_params(iface->bss[i]);
3261
3262 hostapd_disable_iface(iface);
3263 hostapd_enable_iface(iface);
3264 }
3265
3266 #endif /* NEED_AP_MLME */
3267
3268
3269 struct hostapd_data * hostapd_get_iface(struct hapd_interfaces *interfaces,
3270 const char *ifname)
3271 {
3272 size_t i, j;
3273
3274 for (i = 0; i < interfaces->count; i++) {
3275 struct hostapd_iface *iface = interfaces->iface[i];
3276
3277 for (j = 0; j < iface->num_bss; j++) {
3278 struct hostapd_data *hapd = iface->bss[j];
3279
3280 if (os_strcmp(ifname, hapd->conf->iface) == 0)
3281 return hapd;
3282 }
3283 }
3284
3285 return NULL;
3286 }
3287
3288
3289 void hostapd_periodic_iface(struct hostapd_iface *iface)
3290 {
3291 size_t i;
3292
3293 ap_list_timer(iface);
3294
3295 for (i = 0; i < iface->num_bss; i++) {
3296 struct hostapd_data *hapd = iface->bss[i];
3297
3298 if (!hapd->started)
3299 continue;
3300
3301 #ifndef CONFIG_NO_RADIUS
3302 hostapd_acl_expire(hapd);
3303 #endif /* CONFIG_NO_RADIUS */
3304 }
3305 }