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