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