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