| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1 | /* |
| 2 | * WPA Supplicant - Basic AP mode support routines |
| 3 | * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi> |
| 4 | * Copyright (c) 2009, Atheros Communications |
| 5 | * |
| 6 | * This software may be distributed under the terms of the BSD license. |
| 7 | * See README for more details. |
| 8 | */ |
| 9 | |
| 10 | #include "utils/includes.h" |
| 11 | |
| 12 | #include "utils/common.h" |
| 13 | #include "utils/eloop.h" |
| 14 | #include "utils/uuid.h" |
| 15 | #include "common/ieee802_11_defs.h" |
| 16 | #include "common/wpa_ctrl.h" |
| 17 | #include "eapol_supp/eapol_supp_sm.h" |
| 18 | #include "crypto/dh_group5.h" |
| 19 | #include "ap/hostapd.h" |
| 20 | #include "ap/ap_config.h" |
| 21 | #include "ap/ap_drv_ops.h" |
| 22 | #ifdef NEED_AP_MLME |
| 23 | #include "ap/ieee802_11.h" |
| 24 | #endif /* NEED_AP_MLME */ |
| 25 | #include "ap/beacon.h" |
| 26 | #include "ap/ieee802_1x.h" |
| 27 | #include "ap/wps_hostapd.h" |
| 28 | #include "ap/ctrl_iface_ap.h" |
| 29 | #include "ap/dfs.h" |
| 30 | #include "wps/wps.h" |
| 31 | #include "common/ieee802_11_defs.h" |
| 32 | #include "config_ssid.h" |
| 33 | #include "config.h" |
| 34 | #include "wpa_supplicant_i.h" |
| 35 | #include "driver_i.h" |
| 36 | #include "p2p_supplicant.h" |
| 37 | #include "ap.h" |
| 38 | #include "ap/sta_info.h" |
| 39 | #include "notify.h" |
| 40 | |
| 41 | |
| 42 | #ifdef CONFIG_WPS |
| 43 | static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx); |
| 44 | #endif /* CONFIG_WPS */ |
| 45 | |
| 46 | |
| you.chen | 1dc0c26 | 2023-04-24 17:29:00 +0800 | [diff] [blame] | 47 | #ifdef CONFIG_P2P |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 48 | static bool is_chanwidth160_supported(struct hostapd_hw_modes *mode, |
| 49 | struct hostapd_config *conf) |
| 50 | { |
| 51 | #ifdef CONFIG_IEEE80211AX |
| 52 | if (conf->ieee80211ax) { |
| 53 | struct he_capabilities *he_cap; |
| 54 | |
| 55 | he_cap = &mode->he_capab[IEEE80211_MODE_AP]; |
| 56 | if (he_cap->phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX] & |
| 57 | (HE_PHYCAP_CHANNEL_WIDTH_SET_80PLUS80MHZ_IN_5G | |
| 58 | HE_PHYCAP_CHANNEL_WIDTH_SET_160MHZ_IN_5G)) |
| 59 | return true; |
| 60 | } |
| 61 | #endif /* CONFIG_IEEE80211AX */ |
| 62 | if (mode->vht_capab & (VHT_CAP_SUPP_CHAN_WIDTH_160MHZ | |
| 63 | VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)) |
| 64 | return true; |
| 65 | return false; |
| 66 | } |
| you.chen | 1dc0c26 | 2023-04-24 17:29:00 +0800 | [diff] [blame] | 67 | #endif /* CONFIG_P2P */ |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 68 | |
| 69 | |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 70 | static void wpas_conf_ap_vht(struct wpa_supplicant *wpa_s, |
| 71 | struct wpa_ssid *ssid, |
| 72 | struct hostapd_config *conf, |
| 73 | struct hostapd_hw_modes *mode) |
| 74 | { |
| 75 | #ifdef CONFIG_P2P |
| 76 | u8 center_chan = 0; |
| 77 | u8 channel = conf->channel; |
| 78 | #endif /* CONFIG_P2P */ |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 79 | u8 freq_seg_idx; |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 80 | |
| 81 | if (!conf->secondary_channel) |
| 82 | goto no_vht; |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 83 | |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 84 | /* Use the maximum oper channel width if it's given. */ |
| 85 | if (ssid->max_oper_chwidth) |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 86 | hostapd_set_oper_chwidth(conf, ssid->max_oper_chwidth); |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 87 | |
| you.chen | 1dc0c26 | 2023-04-24 17:29:00 +0800 | [diff] [blame] | 88 | /* fix 5G softap bringup issue via supplicant */ |
| 89 | if (hostapd_get_oper_chwidth(conf)) { |
| 90 | ieee80211_freq_to_channel_ext(ssid->frequency, 0, |
| 91 | hostapd_get_oper_chwidth(conf), |
| 92 | &conf->op_class, |
| 93 | &conf->channel); |
| 94 | #ifdef CONFIG_P2P |
| 95 | switch (hostapd_get_oper_chwidth(conf)) { |
| 96 | case CHANWIDTH_80MHZ: |
| 97 | ssid->vht_center_freq1 = |
| 98 | ieee80211_chan_to_freq(NULL, |
| 99 | conf->op_class, |
| 100 | wpas_p2p_get_vht80_center(wpa_s, |
| 101 | mode, conf->channel, conf->op_class)); |
| 102 | break; |
| 103 | } |
| 104 | #endif /* CONFIG_P2P */ |
| 105 | } |
| 106 | |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 107 | if (hostapd_get_oper_chwidth(conf) == CHANWIDTH_80P80MHZ) { |
| 108 | ieee80211_freq_to_chan(ssid->vht_center_freq2, |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 109 | #ifdef CONFIG_AP_VHT |
| 110 | &conf->vht_oper_centr_freq_seg1_idx); |
| 111 | #else /* CONFIG_AP_VHT */ |
| 112 | &freq_seg_idx); |
| 113 | #endif /* CONFIG_AP_VHT */ |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 114 | hostapd_set_oper_centr_freq_seg1_idx(conf, freq_seg_idx); |
| 115 | } |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 116 | |
| 117 | if (!ssid->p2p_group) { |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 118 | if (!ssid->vht_center_freq1) |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 119 | goto no_vht; |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 120 | ieee80211_freq_to_chan(ssid->vht_center_freq1, |
| 121 | &freq_seg_idx); |
| 122 | hostapd_set_oper_centr_freq_seg0_idx(conf, freq_seg_idx); |
| 123 | |
| 124 | wpa_printf(MSG_DEBUG, |
| 125 | "VHT seg0 index %d and seg1 index %d for AP", |
| 126 | hostapd_get_oper_centr_freq_seg0_idx(conf), |
| 127 | hostapd_get_oper_centr_freq_seg1_idx(conf)); |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 128 | return; |
| 129 | } |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 130 | |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 131 | #if defined(CONFIG_BRCM_RSDB) |
| 132 | if (wpa_s->conf->p2p_pref_freq_2g && wpa_s->conf->p2p_pref_freq_5g) { |
| 133 | int freq, num; |
| 134 | num = get_shared_radio_freqs(wpa_s, &freq, 1); |
| 135 | if (num > 0) { |
| 136 | if (freq > 2484) { |
| 137 | /* STA freq is in 5G, choose 2.4 G */ |
| 138 | wpa_printf(MSG_ERROR, "Choosing 2.4G for AP mod"); |
| 139 | ssid->frequency = wpa_s->conf->p2p_pref_freq_2g; |
| 140 | } else { |
| 141 | wpa_printf(MSG_ERROR, "Choosing 5G for AP mode"); |
| 142 | ssid->frequency = wpa_s->conf->p2p_pref_freq_5g; |
| 143 | } |
| 144 | } else { |
| 145 | wpa_printf(MSG_ERROR, "No shared frequency. " |
| 146 | "Start AP on default channel"); |
| 147 | ssid->frequency = 2412; |
| 148 | } |
| 149 | } |
| 150 | #endif /* CONFIG_BRCM_RSDB */ |
| 151 | #ifdef CONFIG_P2P |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 152 | switch (hostapd_get_oper_chwidth(conf)) { |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 153 | case CHANWIDTH_80MHZ: |
| 154 | case CHANWIDTH_80P80MHZ: |
| you.chen | 1dc0c26 | 2023-04-24 17:29:00 +0800 | [diff] [blame] | 155 | center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel, |
| 156 | conf->op_class); |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 157 | wpa_printf(MSG_DEBUG, |
| 158 | "VHT center channel %u for 80 or 80+80 MHz bandwidth", |
| 159 | center_chan); |
| 160 | break; |
| 161 | case CHANWIDTH_160MHZ: |
| you.chen | 1dc0c26 | 2023-04-24 17:29:00 +0800 | [diff] [blame] | 162 | center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel, |
| 163 | conf->op_class); |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 164 | wpa_printf(MSG_DEBUG, |
| 165 | "VHT center channel %u for 160 MHz bandwidth", |
| 166 | center_chan); |
| 167 | break; |
| 168 | default: |
| 169 | /* |
| 170 | * conf->vht_oper_chwidth might not be set for non-P2P GO cases, |
| 171 | * try oper_cwidth 160 MHz first then VHT 80 MHz, if 160 MHz is |
| 172 | * not supported. |
| 173 | */ |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 174 | hostapd_set_oper_chwidth(conf, CHANWIDTH_160MHZ); |
| you.chen | 1dc0c26 | 2023-04-24 17:29:00 +0800 | [diff] [blame] | 175 | ieee80211_freq_to_channel_ext(ssid->frequency, 0, |
| 176 | conf->vht_oper_chwidth, |
| 177 | &conf->op_class, |
| 178 | &conf->channel); |
| 179 | center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel, |
| 180 | conf->op_class); |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 181 | if (center_chan && is_chanwidth160_supported(mode, conf)) { |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 182 | wpa_printf(MSG_DEBUG, |
| 183 | "VHT center channel %u for auto-selected 160 MHz bandwidth", |
| 184 | center_chan); |
| 185 | } else { |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 186 | hostapd_set_oper_chwidth(conf, CHANWIDTH_80MHZ); |
| you.chen | 1dc0c26 | 2023-04-24 17:29:00 +0800 | [diff] [blame] | 187 | ieee80211_freq_to_channel_ext(ssid->frequency, 0, |
| 188 | conf->vht_oper_chwidth, |
| 189 | &conf->op_class, |
| 190 | &conf->channel); |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 191 | center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, |
| you.chen | 1dc0c26 | 2023-04-24 17:29:00 +0800 | [diff] [blame] | 192 | channel, |
| 193 | conf->op_class); |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 194 | wpa_printf(MSG_DEBUG, |
| 195 | "VHT center channel %u for auto-selected 80 MHz bandwidth", |
| 196 | center_chan); |
| 197 | } |
| 198 | break; |
| 199 | } |
| 200 | if (!center_chan) |
| 201 | goto no_vht; |
| 202 | |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 203 | hostapd_set_oper_centr_freq_seg0_idx(conf, center_chan); |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 204 | wpa_printf(MSG_DEBUG, "VHT seg0 index %d for P2P GO", |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 205 | hostapd_get_oper_centr_freq_seg0_idx(conf)); |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 206 | return; |
| 207 | #endif /* CONFIG_P2P */ |
| 208 | |
| 209 | no_vht: |
| 210 | wpa_printf(MSG_DEBUG, |
| 211 | "No VHT higher bandwidth support for the selected channel %d", |
| 212 | conf->channel); |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 213 | hostapd_set_oper_centr_freq_seg0_idx( |
| 214 | conf, conf->channel + conf->secondary_channel * 2); |
| 215 | hostapd_set_oper_chwidth(conf, CHANWIDTH_USE_HT); |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 216 | } |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 217 | |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 218 | |
| 219 | static struct hostapd_hw_modes * |
| 220 | wpa_supplicant_find_hw_mode(struct wpa_supplicant *wpa_s, |
| 221 | enum hostapd_hw_mode hw_mode) |
| 222 | { |
| 223 | struct hostapd_hw_modes *mode = NULL; |
| 224 | int i; |
| 225 | |
| 226 | for (i = 0; i < wpa_s->hw.num_modes; i++) { |
| 227 | if (wpa_s->hw.modes[i].mode == hw_mode) { |
| 228 | mode = &wpa_s->hw.modes[i]; |
| 229 | break; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | return mode; |
| 234 | } |
| 235 | |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 236 | #ifdef CONFIG_SAE |
| 237 | static int wpas_conf_ap_sae_password(struct hostapd_bss_config *bss, const char *sae_pwd) |
| 238 | { |
| 239 | struct sae_password_entry *pw; |
| 240 | |
| 241 | pw = os_zalloc(sizeof(*pw)); |
| 242 | if (!pw) |
| 243 | return -1; |
| 244 | os_memset(pw->peer_addr, 0xff, ETH_ALEN); /* default to wildcard */ |
| 245 | |
| 246 | pw->password = os_strdup(sae_pwd); |
| 247 | if (!pw->password) |
| 248 | goto fail; |
| 249 | |
| 250 | pw->next = bss->sae_passwords; |
| 251 | bss->sae_passwords = pw; |
| 252 | |
| 253 | return 0; |
| 254 | fail: |
| 255 | str_clear_free(pw->password); |
| 256 | os_free(pw); |
| 257 | return -1; |
| 258 | } |
| 259 | #endif |
| 260 | |
| you.chen | 1dc0c26 | 2023-04-24 17:29:00 +0800 | [diff] [blame] | 261 | #ifdef CONFIG_P2P |
| 262 | |
| 263 | static int get_max_oper_chwidth_6ghz(int chwidth) |
| 264 | { |
| 265 | switch (chwidth) { |
| 266 | case CHANWIDTH_USE_HT: |
| 267 | return 20; |
| 268 | case CHANWIDTH_40MHZ_6GHZ: |
| 269 | return 40; |
| 270 | case CHANWIDTH_80MHZ: |
| 271 | return 80; |
| 272 | case CHANWIDTH_80P80MHZ: |
| 273 | case CHANWIDTH_160MHZ: |
| 274 | return 160; |
| 275 | default: |
| 276 | return 0; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | |
| 281 | static void wpas_conf_ap_he_6ghz(struct wpa_supplicant *wpa_s, |
| 282 | struct hostapd_hw_modes *mode, |
| 283 | struct wpa_ssid *ssid, |
| 284 | struct hostapd_config *conf) |
| 285 | { |
| 286 | bool is_chanwidth_40_80, is_chanwidth_160; |
| 287 | int he_chanwidth; |
| 288 | |
| 289 | he_chanwidth = |
| 290 | mode->he_capab[wpas_mode_to_ieee80211_mode( |
| 291 | ssid->mode)].phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX]; |
| 292 | is_chanwidth_40_80 = he_chanwidth & |
| 293 | HE_PHYCAP_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G; |
| 294 | is_chanwidth_160 = he_chanwidth & |
| 295 | HE_PHYCAP_CHANNEL_WIDTH_SET_160MHZ_IN_5G; |
| 296 | |
| 297 | wpa_printf(MSG_DEBUG, |
| 298 | "Enable HE support (p2p_group=%d he_chwidth_cap=%d)", |
| 299 | ssid->p2p_group, he_chanwidth); |
| 300 | |
| 301 | if (mode->he_capab[wpas_mode_to_ieee80211_mode( |
| 302 | ssid->mode)].he_supported && |
| 303 | ssid->he) |
| 304 | conf->ieee80211ax = 1; |
| 305 | |
| 306 | if (is_chanwidth_40_80 && ssid->p2p_group && |
| 307 | get_max_oper_chwidth_6ghz(ssid->max_oper_chwidth) >= 40) { |
| 308 | conf->secondary_channel = |
| 309 | wpas_p2p_get_sec_channel_offset_40mhz( |
| 310 | wpa_s, mode, conf->channel); |
| 311 | wpa_printf(MSG_DEBUG, |
| 312 | "Secondary channel offset %d for P2P group", |
| 313 | conf->secondary_channel); |
| 314 | if (ssid->max_oper_chwidth == CHANWIDTH_40MHZ_6GHZ) |
| 315 | ssid->max_oper_chwidth = CHANWIDTH_USE_HT; |
| 316 | } |
| 317 | |
| 318 | if ((is_chanwidth_40_80 || is_chanwidth_160) && ssid->p2p_group && |
| 319 | get_max_oper_chwidth_6ghz(ssid->max_oper_chwidth) >= 80) |
| 320 | wpas_conf_ap_vht(wpa_s, ssid, conf, mode); |
| 321 | } |
| 322 | |
| 323 | #endif /* CONFIG_P2P */ |
| 324 | |
| 325 | |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 326 | int wpa_supplicant_conf_ap_ht(struct wpa_supplicant *wpa_s, |
| 327 | struct wpa_ssid *ssid, |
| 328 | struct hostapd_config *conf) |
| 329 | { |
| you.chen | 1dc0c26 | 2023-04-24 17:29:00 +0800 | [diff] [blame] | 330 | conf->hw_mode = ieee80211_freq_to_channel_ext(ssid->frequency, 0, |
| 331 | CHANWIDTH_USE_HT, |
| 332 | &conf->op_class, |
| 333 | &conf->channel); |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 334 | if (conf->hw_mode == NUM_HOSTAPD_MODES) { |
| 335 | wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz", |
| 336 | ssid->frequency); |
| 337 | return -1; |
| 338 | } |
| 339 | #if defined(CONFIG_BRCM_RSDB) |
| 340 | if (wpa_s->conf->p2p_pref_freq_2g && wpa_s->conf->p2p_pref_freq_5g) { |
| 341 | int freq, num; |
| 342 | num = get_shared_radio_freqs(wpa_s, &freq, 1); |
| 343 | if (num > 0) { |
| 344 | if (freq > 2484) { |
| 345 | /* STA freq is in 5G, choose 2.4 G */ |
| 346 | wpa_printf(MSG_ERROR, "Choosing 2.4G for AP mod"); |
| 347 | ssid->frequency = wpa_s->conf->p2p_pref_freq_2g; |
| 348 | } else { |
| 349 | wpa_printf(MSG_ERROR, "Choosing 5G for AP mode"); |
| 350 | ssid->frequency = wpa_s->conf->p2p_pref_freq_5g; |
| 351 | } |
| 352 | } else { |
| 353 | wpa_printf(MSG_ERROR, "No shared frequency. " |
| 354 | "Start AP on default channel"); |
| 355 | ssid->frequency = 2412; |
| 356 | } |
| 357 | } |
| 358 | #endif /* CONFIG_BRCM_RSDB */ |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 359 | |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 360 | /* |
| 361 | * Enable HT20 if the driver supports it, by setting conf->ieee80211n |
| 362 | * and a mask of allowed capabilities within conf->ht_capab. |
| 363 | * Using default config settings for: conf->ht_op_mode_fixed, |
| 364 | * conf->secondary_channel, conf->require_ht |
| 365 | */ |
| 366 | if (wpa_s->hw.modes) { |
| 367 | struct hostapd_hw_modes *mode = NULL; |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 368 | int no_ht = 0; |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 369 | |
| 370 | wpa_printf(MSG_DEBUG, |
| 371 | "Determining HT/VHT options based on driver capabilities (freq=%u chan=%u)", |
| 372 | ssid->frequency, conf->channel); |
| 373 | |
| you.chen | 1dc0c26 | 2023-04-24 17:29:00 +0800 | [diff] [blame] | 374 | mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
| 375 | conf->hw_mode, is_6ghz_freq(ssid->frequency)); |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 376 | |
| 377 | /* May drop to IEEE 802.11b if the driver does not support IEEE |
| 378 | * 802.11g */ |
| 379 | if (!mode && conf->hw_mode == HOSTAPD_MODE_IEEE80211G) { |
| 380 | conf->hw_mode = HOSTAPD_MODE_IEEE80211B; |
| 381 | wpa_printf(MSG_INFO, |
| 382 | "Try downgrade to IEEE 802.11b as 802.11g is not supported by the current hardware"); |
| 383 | mode = wpa_supplicant_find_hw_mode(wpa_s, |
| 384 | conf->hw_mode); |
| 385 | } |
| 386 | |
| 387 | if (!mode) { |
| 388 | wpa_printf(MSG_ERROR, |
| 389 | "No match between requested and supported hw modes found"); |
| 390 | return -1; |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | #ifdef CONFIG_HT_OVERRIDES |
| 394 | if (ssid->disable_ht) |
| 395 | ssid->ht = 0; |
| 396 | #endif /* CONFIG_HT_OVERRIDES */ |
| 397 | |
| 398 | if (!ssid->ht) { |
| 399 | wpa_printf(MSG_DEBUG, |
| 400 | "HT not enabled in network profile"); |
| 401 | conf->ieee80211n = 0; |
| 402 | conf->ht_capab = 0; |
| 403 | no_ht = 1; |
| 404 | } |
| 405 | |
| you.chen | 1dc0c26 | 2023-04-24 17:29:00 +0800 | [diff] [blame] | 406 | if (mode && is_6ghz_freq(ssid->frequency) && |
| 407 | conf->hw_mode == HOSTAPD_MODE_IEEE80211A) { |
| 408 | #ifdef CONFIG_P2P |
| 409 | wpas_conf_ap_he_6ghz(wpa_s, mode, ssid, conf); |
| 410 | #endif /* CONFIG_P2P */ |
| 411 | } else if (!no_ht && mode && mode->ht_capab) { |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 412 | wpa_printf(MSG_DEBUG, |
| 413 | "Enable HT support (p2p_group=%d 11a=%d ht40_hw_capab=%d ssid->ht40=%d)", |
| 414 | ssid->p2p_group, |
| 415 | conf->hw_mode == HOSTAPD_MODE_IEEE80211A, |
| 416 | !!(mode->ht_capab & |
| 417 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET), |
| 418 | ssid->ht40); |
| 419 | conf->ieee80211n = 1; |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 420 | |
| 421 | if (ssid->ht40 && |
| 422 | (mode->ht_capab & |
| 423 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) |
| 424 | conf->secondary_channel = ssid->ht40; |
| 425 | else |
| 426 | conf->secondary_channel = 0; |
| 427 | |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 428 | #ifdef CONFIG_P2P |
| 429 | if (ssid->p2p_group && |
| 430 | conf->hw_mode == HOSTAPD_MODE_IEEE80211A && |
| 431 | (mode->ht_capab & |
| 432 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) && |
| 433 | ssid->ht40) { |
| 434 | conf->secondary_channel = |
| you.chen | 1dc0c26 | 2023-04-24 17:29:00 +0800 | [diff] [blame] | 435 | wpas_p2p_get_sec_channel_offset_40mhz( |
| 436 | wpa_s, mode, conf->channel); |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 437 | wpa_printf(MSG_DEBUG, |
| 438 | "HT secondary channel offset %d for P2P group", |
| 439 | conf->secondary_channel); |
| you.chen | 1dc0c26 | 2023-04-24 17:29:00 +0800 | [diff] [blame] | 440 | } else if (ssid->p2p_group && conf->secondary_channel && |
| 441 | conf->hw_mode != HOSTAPD_MODE_IEEE80211A) { |
| 442 | /* This ended up trying to configure invalid |
| 443 | * 2.4 GHz channels (e.g., HT40+ on channel 11) |
| 444 | * in some cases, so clear the secondary channel |
| 445 | * configuration now to avoid such cases that |
| 446 | * would lead to group formation failures. */ |
| 447 | wpa_printf(MSG_DEBUG, |
| 448 | "Disable HT secondary channel for P2P group on 2.4 GHz"); |
| 449 | conf->secondary_channel = 0; |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 450 | } |
| 451 | #endif /* CONFIG_P2P */ |
| 452 | |
| 453 | if (!ssid->p2p_group && |
| 454 | (mode->ht_capab & |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 455 | #ifdef CONFIG_CY_AUTO_SET_BW |
| 456 | /* Fix to resolve softap creation failure on 5G/80 */ |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 457 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) && |
| 458 | ssid->ht40) { |
| you.chen | 1dc0c26 | 2023-04-24 17:29:00 +0800 | [diff] [blame] | 459 | conf->secondary_channel = wpas_p2p_get_sec_channel_offset_40mhz(wpa_s, mode, |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 460 | conf->channel); |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 461 | #else /* CONFIG_CY_AUTO_SET_BW */ |
| 462 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) { |
| 463 | conf->secondary_channel = ssid->ht40; |
| 464 | #endif /* CONFIG_CY_AUTO_SET_BW */ |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 465 | wpa_printf(MSG_DEBUG, |
| 466 | "HT secondary channel offset %d for AP", |
| 467 | conf->secondary_channel); |
| 468 | } |
| 469 | |
| 470 | if (conf->secondary_channel) |
| 471 | conf->ht_capab |= |
| 472 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET; |
| 473 | |
| 474 | /* |
| 475 | * white-list capabilities that won't cause issues |
| 476 | * to connecting stations, while leaving the current |
| 477 | * capabilities intact (currently disabled SMPS). |
| 478 | */ |
| 479 | conf->ht_capab |= mode->ht_capab & |
| 480 | (HT_CAP_INFO_GREEN_FIELD | |
| 481 | HT_CAP_INFO_SHORT_GI20MHZ | |
| 482 | HT_CAP_INFO_SHORT_GI40MHZ | |
| 483 | HT_CAP_INFO_RX_STBC_MASK | |
| 484 | HT_CAP_INFO_TX_STBC | |
| 485 | HT_CAP_INFO_MAX_AMSDU_SIZE); |
| 486 | |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 487 | /* check this before VHT, because setting oper chan |
| 488 | * width and friends is the same call for HE and VHT |
| 489 | * and checks if conf->ieee8021ax == 1 */ |
| 490 | if (mode->he_capab[wpas_mode_to_ieee80211_mode( |
| 491 | ssid->mode)].he_supported && |
| 492 | ssid->he) |
| 493 | conf->ieee80211ax = 1; |
| 494 | |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 495 | if (mode->vht_capab && ssid->vht) { |
| 496 | conf->ieee80211ac = 1; |
| 497 | conf->vht_capab |= mode->vht_capab; |
| 498 | wpas_conf_ap_vht(wpa_s, ssid, conf, mode); |
| 499 | } |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 500 | } |
| 501 | } |
| 502 | |
| 503 | if (conf->secondary_channel) { |
| 504 | struct wpa_supplicant *iface; |
| 505 | |
| 506 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) |
| 507 | { |
| 508 | if (iface == wpa_s || |
| 509 | iface->wpa_state < WPA_AUTHENTICATING || |
| 510 | (int) iface->assoc_freq != ssid->frequency) |
| 511 | continue; |
| 512 | |
| 513 | /* |
| 514 | * Do not allow 40 MHz co-ex PRI/SEC switch to force us |
| 515 | * to change our PRI channel since we have an existing, |
| 516 | * concurrent connection on that channel and doing |
| 517 | * multi-channel concurrency is likely to cause more |
| 518 | * harm than using different PRI/SEC selection in |
| 519 | * environment with multiple BSSes on these two channels |
| 520 | * with mixed 20 MHz or PRI channel selection. |
| 521 | */ |
| 522 | conf->no_pri_sec_switch = 1; |
| 523 | } |
| 524 | } |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 525 | |
| 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | |
| 530 | static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s, |
| 531 | struct wpa_ssid *ssid, |
| 532 | struct hostapd_config *conf) |
| 533 | { |
| 534 | struct hostapd_bss_config *bss = conf->bss[0]; |
| 535 | |
| 536 | conf->driver = wpa_s->driver; |
| 537 | |
| 538 | os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface)); |
| 539 | |
| 540 | if (wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf)) |
| 541 | return -1; |
| 542 | |
| 543 | if (ssid->pbss > 1) { |
| 544 | wpa_printf(MSG_ERROR, "Invalid pbss value(%d) for AP mode", |
| 545 | ssid->pbss); |
| 546 | return -1; |
| 547 | } |
| 548 | bss->pbss = ssid->pbss; |
| 549 | |
| 550 | #ifdef CONFIG_ACS |
| 551 | if (ssid->acs) { |
| 552 | /* Setting channel to 0 in order to enable ACS */ |
| 553 | conf->channel = 0; |
| 554 | wpa_printf(MSG_DEBUG, "Use automatic channel selection"); |
| 555 | } |
| 556 | #endif /* CONFIG_ACS */ |
| 557 | |
| 558 | if (ieee80211_is_dfs(ssid->frequency, wpa_s->hw.modes, |
| 559 | wpa_s->hw.num_modes) && wpa_s->conf->country[0]) { |
| 560 | conf->ieee80211h = 1; |
| 561 | conf->ieee80211d = 1; |
| 562 | conf->country[0] = wpa_s->conf->country[0]; |
| 563 | conf->country[1] = wpa_s->conf->country[1]; |
| 564 | conf->country[2] = ' '; |
| 565 | } |
| 566 | |
| 567 | #ifdef CONFIG_P2P |
| 568 | if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G && |
| 569 | (ssid->mode == WPAS_MODE_P2P_GO || |
| 570 | ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) { |
| 571 | /* Remove 802.11b rates from supported and basic rate sets */ |
| 572 | int *list = os_malloc(4 * sizeof(int)); |
| 573 | if (list) { |
| 574 | list[0] = 60; |
| 575 | list[1] = 120; |
| 576 | list[2] = 240; |
| 577 | list[3] = -1; |
| 578 | } |
| 579 | conf->basic_rates = list; |
| 580 | |
| 581 | list = os_malloc(9 * sizeof(int)); |
| 582 | if (list) { |
| 583 | list[0] = 60; |
| 584 | list[1] = 90; |
| 585 | list[2] = 120; |
| 586 | list[3] = 180; |
| 587 | list[4] = 240; |
| 588 | list[5] = 360; |
| 589 | list[6] = 480; |
| 590 | list[7] = 540; |
| 591 | list[8] = -1; |
| 592 | } |
| 593 | conf->supported_rates = list; |
| 594 | } |
| 595 | |
| 596 | #ifdef CONFIG_IEEE80211AX |
| 597 | if (ssid->mode == WPAS_MODE_P2P_GO || |
| 598 | ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) |
| 599 | conf->ieee80211ax = ssid->he; |
| 600 | #endif /* CONFIG_IEEE80211AX */ |
| 601 | |
| 602 | bss->isolate = !wpa_s->conf->p2p_intra_bss; |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 603 | bss->extended_key_id = wpa_s->conf->extended_key_id; |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 604 | bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk; |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 605 | bss->wpa_deny_ptk0_rekey = ssid->wpa_deny_ptk0_rekey; |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 606 | |
| 607 | if (ssid->p2p_group) { |
| 608 | os_memcpy(bss->ip_addr_go, wpa_s->p2pdev->conf->ip_addr_go, 4); |
| 609 | os_memcpy(bss->ip_addr_mask, wpa_s->p2pdev->conf->ip_addr_mask, |
| 610 | 4); |
| 611 | os_memcpy(bss->ip_addr_start, |
| 612 | wpa_s->p2pdev->conf->ip_addr_start, 4); |
| 613 | os_memcpy(bss->ip_addr_end, wpa_s->p2pdev->conf->ip_addr_end, |
| 614 | 4); |
| 615 | } |
| 616 | #endif /* CONFIG_P2P */ |
| 617 | |
| 618 | if (ssid->ssid_len == 0) { |
| 619 | wpa_printf(MSG_ERROR, "No SSID configured for AP mode"); |
| 620 | return -1; |
| 621 | } |
| 622 | os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len); |
| 623 | bss->ssid.ssid_len = ssid->ssid_len; |
| 624 | bss->ssid.ssid_set = 1; |
| 625 | |
| 626 | bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid; |
| 627 | |
| 628 | if (ssid->auth_alg) |
| 629 | bss->auth_algs = ssid->auth_alg; |
| 630 | |
| 631 | if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt)) |
| 632 | bss->wpa = ssid->proto; |
| 633 | if (ssid->key_mgmt == DEFAULT_KEY_MGMT) |
| 634 | bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK; |
| 635 | else |
| 636 | bss->wpa_key_mgmt = ssid->key_mgmt; |
| 637 | bss->wpa_pairwise = ssid->pairwise_cipher; |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 638 | if (wpa_key_mgmt_sae(bss->wpa_key_mgmt) && ssid->passphrase) { |
| 639 | bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase); |
| 640 | } else if (ssid->psk_set) { |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 641 | bin_clear_free(bss->ssid.wpa_psk, sizeof(*bss->ssid.wpa_psk)); |
| 642 | bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk)); |
| 643 | if (bss->ssid.wpa_psk == NULL) |
| 644 | return -1; |
| 645 | os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN); |
| 646 | bss->ssid.wpa_psk->group = 1; |
| 647 | bss->ssid.wpa_psk_set = 1; |
| 648 | } else if (ssid->passphrase) { |
| 649 | bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase); |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 650 | #ifdef CONFIG_WEP |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 651 | } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] || |
| 652 | ssid->wep_key_len[2] || ssid->wep_key_len[3]) { |
| 653 | struct hostapd_wep_keys *wep = &bss->ssid.wep; |
| 654 | int i; |
| 655 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
| 656 | if (ssid->wep_key_len[i] == 0) |
| 657 | continue; |
| 658 | wep->key[i] = os_memdup(ssid->wep_key[i], |
| 659 | ssid->wep_key_len[i]); |
| 660 | if (wep->key[i] == NULL) |
| 661 | return -1; |
| 662 | wep->len[i] = ssid->wep_key_len[i]; |
| 663 | } |
| 664 | wep->idx = ssid->wep_tx_keyidx; |
| 665 | wep->keys_set = 1; |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 666 | #endif /* CONFIG_WEP */ |
| 667 | } |
| 668 | #ifdef CONFIG_SAE |
| 669 | if (ssid->sae_password) { |
| 670 | struct sae_password_entry *pw; |
| 671 | |
| 672 | pw = os_zalloc(sizeof(*pw)); |
| 673 | if (!pw) |
| 674 | return -1; |
| 675 | os_memset(pw->peer_addr, 0xff, ETH_ALEN); |
| 676 | pw->password = os_strdup(ssid->sae_password); |
| 677 | if (!pw->password) { |
| 678 | os_free(pw); |
| 679 | return -1; |
| 680 | } |
| 681 | if (ssid->sae_password_id) { |
| 682 | pw->identifier = os_strdup(ssid->sae_password_id); |
| 683 | if (!pw->identifier) { |
| 684 | str_clear_free(pw->password); |
| 685 | os_free(pw); |
| 686 | return -1; |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | pw->next = bss->sae_passwords; |
| 691 | bss->sae_passwords = pw; |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 692 | } |
| 693 | |
| you.chen | 1dc0c26 | 2023-04-24 17:29:00 +0800 | [diff] [blame] | 694 | if (ssid->sae_pwe != DEFAULT_SAE_PWE) |
| 695 | bss->sae_pwe = ssid->sae_pwe; |
| 696 | else |
| 697 | bss->sae_pwe = wpa_s->conf->sae_pwe; |
| 698 | /* Refer commit 587411dd62: Fix for PMK expiration issue through |
| 699 | * supplicant |
| 700 | */ |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 701 | bss->dot11RSNAConfigPMKLifetime = wpa_s->conf->dot11RSNAConfigPMKLifetime; |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 702 | #endif /* CONFIG_SAE */ |
| 703 | |
| 704 | if (wpa_s->conf->go_interworking) { |
| 705 | wpa_printf(MSG_DEBUG, |
| 706 | "P2P: Enable Interworking with access_network_type: %d", |
| 707 | wpa_s->conf->go_access_network_type); |
| 708 | bss->interworking = wpa_s->conf->go_interworking; |
| 709 | bss->access_network_type = wpa_s->conf->go_access_network_type; |
| 710 | bss->internet = wpa_s->conf->go_internet; |
| 711 | if (wpa_s->conf->go_venue_group) { |
| 712 | wpa_printf(MSG_DEBUG, |
| 713 | "P2P: Venue group: %d Venue type: %d", |
| 714 | wpa_s->conf->go_venue_group, |
| 715 | wpa_s->conf->go_venue_type); |
| 716 | bss->venue_group = wpa_s->conf->go_venue_group; |
| 717 | bss->venue_type = wpa_s->conf->go_venue_type; |
| 718 | bss->venue_info_set = 1; |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | if (ssid->ap_max_inactivity) |
| 723 | bss->ap_max_inactivity = ssid->ap_max_inactivity; |
| 724 | |
| 725 | if (ssid->dtim_period) |
| 726 | bss->dtim_period = ssid->dtim_period; |
| 727 | else if (wpa_s->conf->dtim_period) |
| 728 | bss->dtim_period = wpa_s->conf->dtim_period; |
| 729 | |
| 730 | if (ssid->beacon_int) |
| 731 | conf->beacon_int = ssid->beacon_int; |
| 732 | else if (wpa_s->conf->beacon_int) |
| 733 | conf->beacon_int = wpa_s->conf->beacon_int; |
| 734 | |
| 735 | #ifdef CONFIG_P2P |
| 736 | if (ssid->mode == WPAS_MODE_P2P_GO || |
| 737 | ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) { |
| 738 | if (wpa_s->conf->p2p_go_ctwindow > conf->beacon_int) { |
| 739 | wpa_printf(MSG_INFO, |
| 740 | "CTWindow (%d) is bigger than beacon interval (%d) - avoid configuring it", |
| 741 | wpa_s->conf->p2p_go_ctwindow, |
| 742 | conf->beacon_int); |
| 743 | conf->p2p_go_ctwindow = 0; |
| 744 | } else { |
| 745 | conf->p2p_go_ctwindow = wpa_s->conf->p2p_go_ctwindow; |
| 746 | } |
| 747 | } |
| 748 | #endif /* CONFIG_P2P */ |
| 749 | |
| 750 | if ((bss->wpa & 2) && bss->rsn_pairwise == 0) |
| 751 | bss->rsn_pairwise = bss->wpa_pairwise; |
| 752 | bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise, |
| 753 | bss->rsn_pairwise); |
| 754 | |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 755 | if (bss->wpa && bss->ieee802_1x) { |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 756 | bss->ssid.security_policy = SECURITY_WPA; |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 757 | } else if (bss->wpa) { |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 758 | bss->ssid.security_policy = SECURITY_WPA_PSK; |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 759 | #ifdef CONFIG_WEP |
| 760 | } else if (bss->ieee802_1x) { |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 761 | int cipher = WPA_CIPHER_NONE; |
| 762 | bss->ssid.security_policy = SECURITY_IEEE_802_1X; |
| 763 | bss->ssid.wep.default_len = bss->default_wep_key_len; |
| 764 | if (bss->default_wep_key_len) |
| 765 | cipher = bss->default_wep_key_len >= 13 ? |
| 766 | WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40; |
| 767 | bss->wpa_group = cipher; |
| 768 | bss->wpa_pairwise = cipher; |
| 769 | bss->rsn_pairwise = cipher; |
| 770 | } else if (bss->ssid.wep.keys_set) { |
| 771 | int cipher = WPA_CIPHER_WEP40; |
| 772 | if (bss->ssid.wep.len[0] >= 13) |
| 773 | cipher = WPA_CIPHER_WEP104; |
| 774 | bss->ssid.security_policy = SECURITY_STATIC_WEP; |
| 775 | bss->wpa_group = cipher; |
| 776 | bss->wpa_pairwise = cipher; |
| 777 | bss->rsn_pairwise = cipher; |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 778 | #endif /* CONFIG_WEP */ |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 779 | } else { |
| 780 | bss->ssid.security_policy = SECURITY_PLAINTEXT; |
| 781 | bss->wpa_group = WPA_CIPHER_NONE; |
| 782 | bss->wpa_pairwise = WPA_CIPHER_NONE; |
| 783 | bss->rsn_pairwise = WPA_CIPHER_NONE; |
| 784 | } |
| 785 | |
| 786 | if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) && |
| 787 | (bss->wpa_group == WPA_CIPHER_CCMP || |
| 788 | bss->wpa_group == WPA_CIPHER_GCMP || |
| 789 | bss->wpa_group == WPA_CIPHER_CCMP_256 || |
| 790 | bss->wpa_group == WPA_CIPHER_GCMP_256)) { |
| 791 | /* |
| 792 | * Strong ciphers do not need frequent rekeying, so increase |
| 793 | * the default GTK rekeying period to 24 hours. |
| 794 | */ |
| 795 | bss->wpa_group_rekey = 86400; |
| 796 | } |
| 797 | |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 798 | if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT) |
| 799 | bss->ieee80211w = ssid->ieee80211w; |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 800 | |
| 801 | #ifdef CONFIG_OCV |
| 802 | bss->ocv = ssid->ocv; |
| 803 | #endif /* CONFIG_OCV */ |
| 804 | |
| 805 | #ifdef CONFIG_WPS |
| 806 | /* |
| 807 | * Enable WPS by default for open and WPA/WPA2-Personal network, but |
| 808 | * require user interaction to actually use it. Only the internal |
| 809 | * Registrar is supported. |
| 810 | */ |
| 811 | if (bss->ssid.security_policy != SECURITY_WPA_PSK && |
| 812 | bss->ssid.security_policy != SECURITY_PLAINTEXT) |
| 813 | goto no_wps; |
| 814 | if (bss->ssid.security_policy == SECURITY_WPA_PSK && |
| 815 | (!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) || |
| 816 | !(bss->wpa & 2))) |
| 817 | goto no_wps; /* WPS2 does not allow WPA/TKIP-only |
| 818 | * configuration */ |
| 819 | if (ssid->wps_disabled) |
| 820 | goto no_wps; |
| 821 | bss->eap_server = 1; |
| 822 | |
| 823 | if (!ssid->ignore_broadcast_ssid) |
| 824 | bss->wps_state = 2; |
| 825 | |
| 826 | bss->ap_setup_locked = 2; |
| 827 | if (wpa_s->conf->config_methods) |
| 828 | bss->config_methods = os_strdup(wpa_s->conf->config_methods); |
| 829 | os_memcpy(bss->device_type, wpa_s->conf->device_type, |
| 830 | WPS_DEV_TYPE_LEN); |
| 831 | if (wpa_s->conf->device_name) { |
| 832 | bss->device_name = os_strdup(wpa_s->conf->device_name); |
| 833 | bss->friendly_name = os_strdup(wpa_s->conf->device_name); |
| 834 | } |
| 835 | if (wpa_s->conf->manufacturer) |
| 836 | bss->manufacturer = os_strdup(wpa_s->conf->manufacturer); |
| 837 | if (wpa_s->conf->model_name) |
| 838 | bss->model_name = os_strdup(wpa_s->conf->model_name); |
| 839 | if (wpa_s->conf->model_number) |
| 840 | bss->model_number = os_strdup(wpa_s->conf->model_number); |
| 841 | if (wpa_s->conf->serial_number) |
| 842 | bss->serial_number = os_strdup(wpa_s->conf->serial_number); |
| 843 | if (is_nil_uuid(wpa_s->conf->uuid)) |
| 844 | os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN); |
| 845 | else |
| 846 | os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN); |
| 847 | os_memcpy(bss->os_version, wpa_s->conf->os_version, 4); |
| 848 | bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1; |
| 849 | if (ssid->eap.fragment_size != DEFAULT_FRAGMENT_SIZE) |
| 850 | bss->fragment_size = ssid->eap.fragment_size; |
| 851 | no_wps: |
| 852 | #endif /* CONFIG_WPS */ |
| 853 | |
| 854 | if (wpa_s->max_stations && |
| 855 | wpa_s->max_stations < wpa_s->conf->max_num_sta) |
| 856 | bss->max_num_sta = wpa_s->max_stations; |
| 857 | else |
| 858 | bss->max_num_sta = wpa_s->conf->max_num_sta; |
| 859 | |
| 860 | if (!bss->isolate) |
| 861 | bss->isolate = wpa_s->conf->ap_isolate; |
| 862 | |
| 863 | bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack; |
| 864 | |
| 865 | if (wpa_s->conf->ap_vendor_elements) { |
| 866 | bss->vendor_elements = |
| 867 | wpabuf_dup(wpa_s->conf->ap_vendor_elements); |
| 868 | } |
| you.chen | 1dc0c26 | 2023-04-24 17:29:00 +0800 | [diff] [blame] | 869 | if (wpa_s->conf->ap_assocresp_elements) { |
| 870 | bss->assocresp_elements = |
| 871 | wpabuf_dup(wpa_s->conf->ap_assocresp_elements); |
| 872 | } |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 873 | |
| 874 | bss->ftm_responder = wpa_s->conf->ftm_responder; |
| 875 | bss->ftm_initiator = wpa_s->conf->ftm_initiator; |
| 876 | |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 877 | bss->transition_disable = ssid->transition_disable; |
| 878 | |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 879 | return 0; |
| 880 | } |
| 881 | |
| 882 | |
| 883 | static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq) |
| 884 | { |
| 885 | #ifdef CONFIG_P2P |
| 886 | struct wpa_supplicant *wpa_s = ctx; |
| 887 | const struct ieee80211_mgmt *mgmt; |
| 888 | |
| 889 | mgmt = (const struct ieee80211_mgmt *) buf; |
| 890 | if (len < IEEE80211_HDRLEN + 1) |
| 891 | return; |
| 892 | if (mgmt->u.action.category != WLAN_ACTION_PUBLIC) |
| 893 | return; |
| 894 | wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid, |
| 895 | mgmt->u.action.category, |
| 896 | buf + IEEE80211_HDRLEN + 1, |
| 897 | len - IEEE80211_HDRLEN - 1, freq); |
| 898 | #endif /* CONFIG_P2P */ |
| 899 | } |
| 900 | |
| 901 | |
| 902 | static void ap_wps_event_cb(void *ctx, enum wps_event event, |
| 903 | union wps_event_data *data) |
| 904 | { |
| 905 | #ifdef CONFIG_P2P |
| 906 | struct wpa_supplicant *wpa_s = ctx; |
| 907 | |
| 908 | if (event == WPS_EV_FAIL) { |
| 909 | struct wps_event_fail *fail = &data->fail; |
| 910 | |
| 911 | if (wpa_s->p2pdev && wpa_s->p2pdev != wpa_s && |
| 912 | wpa_s == wpa_s->global->p2p_group_formation) { |
| 913 | /* |
| 914 | * src/ap/wps_hostapd.c has already sent this on the |
| 915 | * main interface, so only send on the parent interface |
| 916 | * here if needed. |
| 917 | */ |
| 918 | wpa_msg(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_FAIL |
| 919 | "msg=%d config_error=%d", |
| 920 | fail->msg, fail->config_error); |
| 921 | } |
| 922 | wpas_p2p_wps_failed(wpa_s, fail); |
| 923 | } |
| 924 | #endif /* CONFIG_P2P */ |
| 925 | } |
| 926 | |
| 927 | |
| 928 | static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr, |
| 929 | int authorized, const u8 *p2p_dev_addr) |
| 930 | { |
| 931 | wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr); |
| 932 | } |
| 933 | |
| 934 | |
| 935 | #ifdef CONFIG_P2P |
| 936 | static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr, |
| 937 | const u8 *psk, size_t psk_len) |
| 938 | { |
| 939 | |
| 940 | struct wpa_supplicant *wpa_s = ctx; |
| 941 | if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL) |
| 942 | return; |
| 943 | wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len); |
| 944 | } |
| 945 | #endif /* CONFIG_P2P */ |
| 946 | |
| 947 | |
| 948 | static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq) |
| 949 | { |
| 950 | #ifdef CONFIG_P2P |
| 951 | struct wpa_supplicant *wpa_s = ctx; |
| 952 | const struct ieee80211_mgmt *mgmt; |
| 953 | |
| 954 | mgmt = (const struct ieee80211_mgmt *) buf; |
| 955 | if (len < IEEE80211_HDRLEN + 1) |
| 956 | return -1; |
| 957 | wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid, |
| 958 | mgmt->u.action.category, |
| 959 | buf + IEEE80211_HDRLEN + 1, |
| 960 | len - IEEE80211_HDRLEN - 1, freq); |
| 961 | #endif /* CONFIG_P2P */ |
| 962 | return 0; |
| 963 | } |
| 964 | |
| 965 | |
| 966 | static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da, |
| 967 | const u8 *bssid, const u8 *ie, size_t ie_len, |
| 968 | int ssi_signal) |
| 969 | { |
| 970 | struct wpa_supplicant *wpa_s = ctx; |
| 971 | unsigned int freq = 0; |
| 972 | |
| 973 | if (wpa_s->ap_iface) |
| 974 | freq = wpa_s->ap_iface->freq; |
| 975 | |
| 976 | return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len, |
| 977 | freq, ssi_signal); |
| 978 | } |
| 979 | |
| 980 | |
| 981 | static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr, |
| 982 | const u8 *uuid_e) |
| 983 | { |
| 984 | struct wpa_supplicant *wpa_s = ctx; |
| 985 | wpas_p2p_wps_success(wpa_s, mac_addr, 1); |
| 986 | } |
| 987 | |
| 988 | |
| 989 | static void wpas_ap_configured_cb(void *ctx) |
| 990 | { |
| 991 | struct wpa_supplicant *wpa_s = ctx; |
| 992 | |
| 993 | wpa_printf(MSG_DEBUG, "AP interface setup completed - state %s", |
| 994 | hostapd_state_text(wpa_s->ap_iface->state)); |
| 995 | if (wpa_s->ap_iface->state == HAPD_IFACE_DISABLED) { |
| 996 | wpa_supplicant_ap_deinit(wpa_s); |
| 997 | return; |
| 998 | } |
| 999 | |
| 1000 | #ifdef CONFIG_ACS |
| 1001 | if (wpa_s->current_ssid && wpa_s->current_ssid->acs) { |
| 1002 | wpa_s->assoc_freq = wpa_s->ap_iface->freq; |
| 1003 | wpa_s->current_ssid->frequency = wpa_s->ap_iface->freq; |
| 1004 | } |
| 1005 | #endif /* CONFIG_ACS */ |
| 1006 | |
| 1007 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); |
| 1008 | |
| 1009 | if (wpa_s->ap_configured_cb) |
| 1010 | wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx, |
| 1011 | wpa_s->ap_configured_cb_data); |
| 1012 | } |
| 1013 | |
| 1014 | |
| 1015 | int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s, |
| 1016 | struct wpa_ssid *ssid) |
| 1017 | { |
| 1018 | struct wpa_driver_associate_params params; |
| 1019 | struct hostapd_iface *hapd_iface; |
| 1020 | struct hostapd_config *conf; |
| 1021 | size_t i; |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 1022 | #ifdef CONFIG_CY_AUTO_SET_BW |
| 1023 | /* Fix to create supplicant based softap on best channel |
| 1024 | instead of random channel when specifying freq=2 or freq=5 */ |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1025 | char buf[64]; |
| 1026 | int chan,freq; |
| 1027 | u8 opclass; |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 1028 | #endif /* CONFIG_CY_AUTO_SET_BW */ |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1029 | |
| 1030 | if (ssid->ssid == NULL || ssid->ssid_len == 0) { |
| 1031 | wpa_printf(MSG_ERROR, "No SSID configured for AP mode"); |
| 1032 | return -1; |
| 1033 | } |
| 1034 | |
| 1035 | #ifdef CONFIG_BRCM_AUTOMOTIVE |
| 1036 | if (ssid->vht == -1 && ssid->ht40 == -1) { |
| 1037 | wpa_printf(MSG_ERROR, "No Channel width configured for AP mode"); |
| 1038 | return -1; |
| 1039 | } |
| 1040 | #endif |
| 1041 | wpa_supplicant_ap_deinit(wpa_s); |
| 1042 | |
| 1043 | wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')", |
| 1044 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); |
| 1045 | |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1046 | os_memset(¶ms, 0, sizeof(params)); |
| 1047 | params.ssid = ssid->ssid; |
| 1048 | params.ssid_len = ssid->ssid_len; |
| 1049 | switch (ssid->mode) { |
| 1050 | case WPAS_MODE_AP: |
| 1051 | case WPAS_MODE_P2P_GO: |
| 1052 | case WPAS_MODE_P2P_GROUP_FORMATION: |
| 1053 | params.mode = IEEE80211_MODE_AP; |
| 1054 | break; |
| 1055 | default: |
| 1056 | return -1; |
| 1057 | } |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 1058 | #ifdef CONFIG_CY_AUTO_SET_BW |
| 1059 | /* Fix to create supplicant based softap on best channel |
| 1060 | instead of random channel when specifying freq=2 or freq=5 */ |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1061 | wpa_s->ap_iface = hapd_iface = hostapd_alloc_iface(); |
| 1062 | if (hapd_iface == NULL) |
| 1063 | return -1; |
| 1064 | hapd_iface->owner = wpa_s; |
| 1065 | hapd_iface->drv_flags = wpa_s->drv_flags; |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1066 | hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads; |
| 1067 | hapd_iface->extended_capa = wpa_s->extended_capa; |
| 1068 | hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask; |
| 1069 | hapd_iface->extended_capa_len = wpa_s->extended_capa_len; |
| 1070 | |
| 1071 | wpa_s->ap_iface->conf = conf = hostapd_config_defaults(); |
| 1072 | if (conf == NULL) { |
| 1073 | wpa_supplicant_ap_deinit(wpa_s); |
| 1074 | return -1; |
| 1075 | } |
| 1076 | if (ssid->frequency == 5 || ssid->frequency == 2) { |
| 1077 | if (ssid->frequency == 5) |
| 1078 | wpa_s->driver->driver_cmd(wpa_s->drv_priv, "HAPD_AUTO_CHANNEL band=5G", buf, sizeof(buf)); |
| 1079 | else |
| 1080 | wpa_s->driver->driver_cmd(wpa_s->drv_priv, "HAPD_AUTO_CHANNEL band=2G", buf, sizeof(buf)); |
| 1081 | chan = atoi(buf); |
| 1082 | /* Convert channel to frequency */ |
| 1083 | if (chan >= 1 && chan <= 13) |
| 1084 | freq = 2407 + chan * 5; |
| 1085 | else if (chan == 14) |
| 1086 | freq = 2484; |
| 1087 | else if (chan >= 36 && chan <= 169) |
| 1088 | freq = 5000 + chan * 5; |
| 1089 | ssid->frequency = freq; |
| 1090 | wpa_msg(wpa_s, MSG_INFO, "\nChannel from ACS is %d and freq %d \n", chan, freq); |
| 1091 | } |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 1092 | #else /* CONFIG_CY_AUTO_SET_BW */ |
| 1093 | if (ssid->frequency == 0) |
| 1094 | ssid->frequency = 2462; /* default channel 11 */ |
| 1095 | #endif /* CONFIG_CY_AUTO_SET_BW */ |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1096 | params.freq.freq = ssid->frequency; |
| 1097 | |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 1098 | if ((ssid->mode == WPAS_MODE_AP || ssid->mode == WPAS_MODE_P2P_GO) && |
| 1099 | ssid->enable_edmg) { |
| 1100 | u8 primary_channel; |
| 1101 | |
| 1102 | if (ieee80211_freq_to_chan(ssid->frequency, &primary_channel) == |
| 1103 | NUM_HOSTAPD_MODES) { |
| 1104 | wpa_printf(MSG_WARNING, |
| 1105 | "EDMG: Failed to get the primary channel"); |
| 1106 | return -1; |
| 1107 | } |
| 1108 | |
| 1109 | hostapd_encode_edmg_chan(ssid->enable_edmg, ssid->edmg_channel, |
| 1110 | primary_channel, ¶ms.freq.edmg); |
| 1111 | } |
| 1112 | |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1113 | params.wpa_proto = ssid->proto; |
| 1114 | if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) |
| 1115 | wpa_s->key_mgmt = WPA_KEY_MGMT_PSK; |
| you.chen | 1dc0c26 | 2023-04-24 17:29:00 +0800 | [diff] [blame] | 1116 | else if (ssid->key_mgmt & WPA_KEY_MGMT_SAE) |
| 1117 | wpa_s->key_mgmt = WPA_KEY_MGMT_SAE; |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1118 | else |
| 1119 | wpa_s->key_mgmt = WPA_KEY_MGMT_NONE; |
| 1120 | params.key_mgmt_suite = wpa_s->key_mgmt; |
| 1121 | |
| 1122 | wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher, |
| 1123 | 1); |
| 1124 | if (wpa_s->pairwise_cipher < 0) { |
| 1125 | wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise " |
| 1126 | "cipher."); |
| 1127 | return -1; |
| 1128 | } |
| 1129 | params.pairwise_suite = wpa_s->pairwise_cipher; |
| 1130 | params.group_suite = params.pairwise_suite; |
| 1131 | |
| 1132 | #ifdef CONFIG_P2P |
| 1133 | if (ssid->mode == WPAS_MODE_P2P_GO || |
| 1134 | ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) |
| 1135 | params.p2p = 1; |
| 1136 | #endif /* CONFIG_P2P */ |
| 1137 | |
| 1138 | if (wpa_s->p2pdev->set_ap_uapsd) |
| 1139 | params.uapsd = wpa_s->p2pdev->ap_uapsd; |
| 1140 | else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD)) |
| 1141 | params.uapsd = 1; /* mandatory for P2P GO */ |
| 1142 | else |
| 1143 | params.uapsd = -1; |
| 1144 | |
| 1145 | if (ieee80211_is_dfs(params.freq.freq, wpa_s->hw.modes, |
| 1146 | wpa_s->hw.num_modes)) |
| 1147 | params.freq.freq = 0; /* set channel after CAC */ |
| 1148 | |
| 1149 | if (params.p2p) |
| 1150 | wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_GO); |
| 1151 | else |
| 1152 | wpa_drv_get_ext_capa(wpa_s, WPA_IF_AP_BSS); |
| 1153 | |
| 1154 | if (wpa_drv_associate(wpa_s, ¶ms) < 0) { |
| 1155 | wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality"); |
| 1156 | return -1; |
| 1157 | } |
| 1158 | |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 1159 | |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1160 | os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params, |
| 1161 | wpa_s->conf->wmm_ac_params, |
| 1162 | sizeof(wpa_s->conf->wmm_ac_params)); |
| 1163 | |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 1164 | os_memcpy(wpa_s->ap_iface->conf->tx_queue, wpa_s->conf->tx_queue, |
| 1165 | sizeof(wpa_s->conf->tx_queue)); |
| 1166 | |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1167 | if (params.uapsd > 0) { |
| 1168 | conf->bss[0]->wmm_enabled = 1; |
| 1169 | conf->bss[0]->wmm_uapsd = 1; |
| 1170 | } |
| 1171 | |
| 1172 | #ifdef CONFIG_BRCM_RSN_CNTRS |
| 1173 | if (wpa_s->conf->replay_cntrs) { |
| 1174 | conf->bss[0]->replay_cntrs = wpa_s->conf->replay_cntrs; |
| 1175 | } |
| 1176 | #endif /* CONFIG_BRCM_RSN_CNTRS */ |
| 1177 | if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) { |
| 1178 | wpa_printf(MSG_ERROR, "Failed to create AP configuration"); |
| 1179 | wpa_supplicant_ap_deinit(wpa_s); |
| 1180 | return -1; |
| 1181 | } |
| 1182 | |
| 1183 | #ifdef CONFIG_P2P |
| 1184 | if (ssid->mode == WPAS_MODE_P2P_GO) |
| 1185 | conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER; |
| 1186 | else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) |
| 1187 | conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER | |
| 1188 | P2P_GROUP_FORMATION; |
| 1189 | #endif /* CONFIG_P2P */ |
| 1190 | |
| 1191 | hapd_iface->num_bss = conf->num_bss; |
| 1192 | hapd_iface->bss = os_calloc(conf->num_bss, |
| 1193 | sizeof(struct hostapd_data *)); |
| 1194 | if (hapd_iface->bss == NULL) { |
| 1195 | wpa_supplicant_ap_deinit(wpa_s); |
| 1196 | return -1; |
| 1197 | } |
| 1198 | |
| 1199 | for (i = 0; i < conf->num_bss; i++) { |
| 1200 | hapd_iface->bss[i] = |
| 1201 | hostapd_alloc_bss_data(hapd_iface, conf, |
| 1202 | conf->bss[i]); |
| 1203 | if (hapd_iface->bss[i] == NULL) { |
| 1204 | wpa_supplicant_ap_deinit(wpa_s); |
| 1205 | return -1; |
| 1206 | } |
| 1207 | |
| 1208 | hapd_iface->bss[i]->msg_ctx = wpa_s; |
| 1209 | hapd_iface->bss[i]->msg_ctx_parent = wpa_s->p2pdev; |
| 1210 | hapd_iface->bss[i]->public_action_cb = ap_public_action_rx; |
| 1211 | hapd_iface->bss[i]->public_action_cb_ctx = wpa_s; |
| 1212 | hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx; |
| 1213 | hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s; |
| 1214 | hostapd_register_probereq_cb(hapd_iface->bss[i], |
| 1215 | ap_probe_req_rx, wpa_s); |
| 1216 | hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb; |
| 1217 | hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s; |
| 1218 | hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb; |
| 1219 | hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s; |
| 1220 | hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb; |
| 1221 | hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s; |
| 1222 | #ifdef CONFIG_P2P |
| 1223 | hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb; |
| 1224 | hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s; |
| 1225 | hapd_iface->bss[i]->p2p = wpa_s->global->p2p; |
| 1226 | hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s, |
| 1227 | ssid); |
| 1228 | #endif /* CONFIG_P2P */ |
| 1229 | hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb; |
| 1230 | hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s; |
| 1231 | #ifdef CONFIG_TESTING_OPTIONS |
| 1232 | hapd_iface->bss[i]->ext_eapol_frame_io = |
| 1233 | wpa_s->ext_eapol_frame_io; |
| 1234 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 1235 | #ifdef CONFIG_BRCM_AUTOMOTIVE |
| 1236 | if (wpa_s->conf) |
| 1237 | hapd_iface->bss[i]->conf->ignore_broadcast_ssid = wpa_s->conf->ignore_broadcast_ssid; |
| 1238 | #endif /* CONFIG_BRCM_AUTOMOTIVE */ |
| 1239 | } |
| 1240 | |
| 1241 | os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN); |
| 1242 | hapd_iface->bss[0]->driver = wpa_s->driver; |
| 1243 | hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv; |
| 1244 | |
| 1245 | wpa_s->current_ssid = ssid; |
| 1246 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
| 1247 | os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN); |
| 1248 | wpa_s->assoc_freq = ssid->frequency; |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 1249 | wpa_s->ap_iface->conf->enable_edmg = ssid->enable_edmg; |
| 1250 | wpa_s->ap_iface->conf->edmg_channel = ssid->edmg_channel; |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1251 | |
| 1252 | #if defined(CONFIG_P2P) && defined(CONFIG_ACS) |
| 1253 | if (wpa_s->p2p_go_do_acs) { |
| 1254 | wpa_s->ap_iface->conf->channel = 0; |
| 1255 | wpa_s->ap_iface->conf->hw_mode = wpa_s->p2p_go_acs_band; |
| 1256 | ssid->acs = 1; |
| 1257 | } |
| 1258 | #endif /* CONFIG_P2P && CONFIG_ACS */ |
| 1259 | |
| 1260 | if (hostapd_setup_interface(wpa_s->ap_iface)) { |
| 1261 | wpa_printf(MSG_ERROR, "Failed to initialize AP interface"); |
| 1262 | wpa_supplicant_ap_deinit(wpa_s); |
| 1263 | return -1; |
| 1264 | } |
| 1265 | |
| 1266 | return 0; |
| 1267 | } |
| 1268 | |
| 1269 | |
| 1270 | void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s) |
| 1271 | { |
| 1272 | #ifdef CONFIG_WPS |
| 1273 | eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL); |
| 1274 | #endif /* CONFIG_WPS */ |
| 1275 | |
| 1276 | if (wpa_s->ap_iface == NULL) |
| 1277 | return; |
| 1278 | |
| 1279 | wpa_s->current_ssid = NULL; |
| 1280 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
| 1281 | wpa_s->assoc_freq = 0; |
| 1282 | wpas_p2p_ap_deinit(wpa_s); |
| 1283 | wpa_s->ap_iface->driver_ap_teardown = |
| 1284 | !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT); |
| 1285 | |
| 1286 | hostapd_interface_deinit(wpa_s->ap_iface); |
| 1287 | hostapd_interface_free(wpa_s->ap_iface); |
| 1288 | wpa_s->ap_iface = NULL; |
| 1289 | wpa_drv_deinit_ap(wpa_s); |
| 1290 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR |
| 1291 | " reason=%d locally_generated=1", |
| 1292 | MAC2STR(wpa_s->own_addr), WLAN_REASON_DEAUTH_LEAVING); |
| 1293 | } |
| 1294 | |
| 1295 | |
| 1296 | void ap_tx_status(void *ctx, const u8 *addr, |
| 1297 | const u8 *buf, size_t len, int ack) |
| 1298 | { |
| 1299 | #ifdef NEED_AP_MLME |
| 1300 | struct wpa_supplicant *wpa_s = ctx; |
| 1301 | hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack); |
| 1302 | #endif /* NEED_AP_MLME */ |
| 1303 | } |
| 1304 | |
| 1305 | |
| 1306 | void ap_eapol_tx_status(void *ctx, const u8 *dst, |
| 1307 | const u8 *data, size_t len, int ack) |
| 1308 | { |
| 1309 | #ifdef NEED_AP_MLME |
| 1310 | struct wpa_supplicant *wpa_s = ctx; |
| 1311 | if (!wpa_s->ap_iface) |
| 1312 | return; |
| 1313 | hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack); |
| 1314 | #endif /* NEED_AP_MLME */ |
| 1315 | } |
| 1316 | |
| 1317 | |
| 1318 | void ap_client_poll_ok(void *ctx, const u8 *addr) |
| 1319 | { |
| 1320 | #ifdef NEED_AP_MLME |
| 1321 | struct wpa_supplicant *wpa_s = ctx; |
| 1322 | if (wpa_s->ap_iface) |
| 1323 | hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr); |
| 1324 | #endif /* NEED_AP_MLME */ |
| 1325 | } |
| 1326 | |
| 1327 | |
| 1328 | void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds) |
| 1329 | { |
| 1330 | #ifdef NEED_AP_MLME |
| 1331 | struct wpa_supplicant *wpa_s = ctx; |
| 1332 | ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds); |
| 1333 | #endif /* NEED_AP_MLME */ |
| 1334 | } |
| 1335 | |
| 1336 | |
| 1337 | void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt) |
| 1338 | { |
| 1339 | #ifdef NEED_AP_MLME |
| 1340 | struct wpa_supplicant *wpa_s = ctx; |
| 1341 | struct hostapd_frame_info fi; |
| 1342 | os_memset(&fi, 0, sizeof(fi)); |
| 1343 | fi.datarate = rx_mgmt->datarate; |
| 1344 | fi.ssi_signal = rx_mgmt->ssi_signal; |
| 1345 | ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame, |
| 1346 | rx_mgmt->frame_len, &fi); |
| 1347 | #endif /* NEED_AP_MLME */ |
| 1348 | } |
| 1349 | |
| 1350 | |
| 1351 | void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok) |
| 1352 | { |
| 1353 | #ifdef NEED_AP_MLME |
| 1354 | struct wpa_supplicant *wpa_s = ctx; |
| 1355 | ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok); |
| 1356 | #endif /* NEED_AP_MLME */ |
| 1357 | } |
| 1358 | |
| 1359 | |
| 1360 | void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s, |
| 1361 | const u8 *src_addr, const u8 *buf, size_t len) |
| 1362 | { |
| 1363 | ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len); |
| 1364 | } |
| 1365 | |
| 1366 | |
| 1367 | #ifdef CONFIG_WPS |
| 1368 | |
| 1369 | int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid, |
| 1370 | const u8 *p2p_dev_addr) |
| 1371 | { |
| 1372 | if (!wpa_s->ap_iface) |
| 1373 | return -1; |
| 1374 | return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0], |
| 1375 | p2p_dev_addr); |
| 1376 | } |
| 1377 | |
| 1378 | |
| 1379 | int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s) |
| 1380 | { |
| 1381 | struct wps_registrar *reg; |
| 1382 | int reg_sel = 0, wps_sta = 0; |
| 1383 | |
| 1384 | if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps) |
| 1385 | return -1; |
| 1386 | |
| 1387 | reg = wpa_s->ap_iface->bss[0]->wps->registrar; |
| 1388 | reg_sel = wps_registrar_wps_cancel(reg); |
| 1389 | wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0], |
| 1390 | ap_sta_wps_cancel, NULL); |
| 1391 | |
| 1392 | if (!reg_sel && !wps_sta) { |
| 1393 | wpa_printf(MSG_DEBUG, "No WPS operation in progress at this " |
| 1394 | "time"); |
| 1395 | return -1; |
| 1396 | } |
| 1397 | |
| 1398 | /* |
| 1399 | * There are 2 cases to return wps cancel as success: |
| 1400 | * 1. When wps cancel was initiated but no connection has been |
| 1401 | * established with client yet. |
| 1402 | * 2. Client is in the middle of exchanging WPS messages. |
| 1403 | */ |
| 1404 | |
| 1405 | return 0; |
| 1406 | } |
| 1407 | |
| 1408 | |
| 1409 | int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid, |
| 1410 | const char *pin, char *buf, size_t buflen, |
| 1411 | int timeout) |
| 1412 | { |
| 1413 | int ret, ret_len = 0; |
| 1414 | |
| 1415 | if (!wpa_s->ap_iface) |
| 1416 | return -1; |
| 1417 | |
| 1418 | if (pin == NULL) { |
| 1419 | unsigned int rpin; |
| 1420 | |
| 1421 | if (wps_generate_pin(&rpin) < 0) |
| 1422 | return -1; |
| 1423 | ret_len = os_snprintf(buf, buflen, "%08d", rpin); |
| 1424 | if (os_snprintf_error(buflen, ret_len)) |
| 1425 | return -1; |
| 1426 | pin = buf; |
| 1427 | } else if (buf) { |
| 1428 | ret_len = os_snprintf(buf, buflen, "%s", pin); |
| 1429 | if (os_snprintf_error(buflen, ret_len)) |
| 1430 | return -1; |
| 1431 | } |
| 1432 | |
| 1433 | ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin, |
| 1434 | timeout); |
| 1435 | if (ret) |
| 1436 | return -1; |
| 1437 | return ret_len; |
| 1438 | } |
| 1439 | |
| 1440 | |
| 1441 | static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx) |
| 1442 | { |
| 1443 | struct wpa_supplicant *wpa_s = eloop_data; |
| 1444 | wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out"); |
| 1445 | wpas_wps_ap_pin_disable(wpa_s); |
| 1446 | } |
| 1447 | |
| 1448 | |
| 1449 | static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout) |
| 1450 | { |
| 1451 | struct hostapd_data *hapd; |
| 1452 | |
| 1453 | if (wpa_s->ap_iface == NULL) |
| 1454 | return; |
| 1455 | hapd = wpa_s->ap_iface->bss[0]; |
| 1456 | wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout); |
| 1457 | hapd->ap_pin_failures = 0; |
| 1458 | eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL); |
| 1459 | if (timeout > 0) |
| 1460 | eloop_register_timeout(timeout, 0, |
| 1461 | wpas_wps_ap_pin_timeout, wpa_s, NULL); |
| 1462 | } |
| 1463 | |
| 1464 | |
| 1465 | void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s) |
| 1466 | { |
| 1467 | struct hostapd_data *hapd; |
| 1468 | |
| 1469 | if (wpa_s->ap_iface == NULL) |
| 1470 | return; |
| 1471 | wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN"); |
| 1472 | hapd = wpa_s->ap_iface->bss[0]; |
| 1473 | os_free(hapd->conf->ap_pin); |
| 1474 | hapd->conf->ap_pin = NULL; |
| 1475 | eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL); |
| 1476 | } |
| 1477 | |
| 1478 | |
| 1479 | const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout) |
| 1480 | { |
| 1481 | struct hostapd_data *hapd; |
| 1482 | unsigned int pin; |
| 1483 | char pin_txt[9]; |
| 1484 | |
| 1485 | if (wpa_s->ap_iface == NULL) |
| 1486 | return NULL; |
| 1487 | hapd = wpa_s->ap_iface->bss[0]; |
| 1488 | if (wps_generate_pin(&pin) < 0) |
| 1489 | return NULL; |
| 1490 | os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin); |
| 1491 | os_free(hapd->conf->ap_pin); |
| 1492 | hapd->conf->ap_pin = os_strdup(pin_txt); |
| 1493 | if (hapd->conf->ap_pin == NULL) |
| 1494 | return NULL; |
| 1495 | wpas_wps_ap_pin_enable(wpa_s, timeout); |
| 1496 | |
| 1497 | return hapd->conf->ap_pin; |
| 1498 | } |
| 1499 | |
| 1500 | |
| 1501 | const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s) |
| 1502 | { |
| 1503 | struct hostapd_data *hapd; |
| 1504 | if (wpa_s->ap_iface == NULL) |
| 1505 | return NULL; |
| 1506 | hapd = wpa_s->ap_iface->bss[0]; |
| 1507 | return hapd->conf->ap_pin; |
| 1508 | } |
| 1509 | |
| 1510 | |
| 1511 | int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin, |
| 1512 | int timeout) |
| 1513 | { |
| 1514 | struct hostapd_data *hapd; |
| 1515 | char pin_txt[9]; |
| 1516 | int ret; |
| 1517 | |
| 1518 | if (wpa_s->ap_iface == NULL) |
| 1519 | return -1; |
| 1520 | hapd = wpa_s->ap_iface->bss[0]; |
| 1521 | ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin); |
| 1522 | if (os_snprintf_error(sizeof(pin_txt), ret)) |
| 1523 | return -1; |
| 1524 | os_free(hapd->conf->ap_pin); |
| 1525 | hapd->conf->ap_pin = os_strdup(pin_txt); |
| 1526 | if (hapd->conf->ap_pin == NULL) |
| 1527 | return -1; |
| 1528 | wpas_wps_ap_pin_enable(wpa_s, timeout); |
| 1529 | |
| 1530 | return 0; |
| 1531 | } |
| 1532 | |
| 1533 | |
| 1534 | void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s) |
| 1535 | { |
| 1536 | struct hostapd_data *hapd; |
| 1537 | |
| 1538 | if (wpa_s->ap_iface == NULL) |
| 1539 | return; |
| 1540 | hapd = wpa_s->ap_iface->bss[0]; |
| 1541 | |
| 1542 | /* |
| 1543 | * Registrar failed to prove its knowledge of the AP PIN. Disable AP |
| 1544 | * PIN if this happens multiple times to slow down brute force attacks. |
| 1545 | */ |
| 1546 | hapd->ap_pin_failures++; |
| 1547 | wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u", |
| 1548 | hapd->ap_pin_failures); |
| 1549 | if (hapd->ap_pin_failures < 3) |
| 1550 | return; |
| 1551 | |
| 1552 | wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN"); |
| 1553 | hapd->ap_pin_failures = 0; |
| 1554 | os_free(hapd->conf->ap_pin); |
| 1555 | hapd->conf->ap_pin = NULL; |
| 1556 | } |
| 1557 | |
| 1558 | |
| 1559 | #ifdef CONFIG_WPS_NFC |
| 1560 | |
| 1561 | struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s, |
| 1562 | int ndef) |
| 1563 | { |
| 1564 | struct hostapd_data *hapd; |
| 1565 | |
| 1566 | if (wpa_s->ap_iface == NULL) |
| 1567 | return NULL; |
| 1568 | hapd = wpa_s->ap_iface->bss[0]; |
| 1569 | return hostapd_wps_nfc_config_token(hapd, ndef); |
| 1570 | } |
| 1571 | |
| 1572 | |
| 1573 | struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s, |
| 1574 | int ndef) |
| 1575 | { |
| 1576 | struct hostapd_data *hapd; |
| 1577 | |
| 1578 | if (wpa_s->ap_iface == NULL) |
| 1579 | return NULL; |
| 1580 | hapd = wpa_s->ap_iface->bss[0]; |
| 1581 | return hostapd_wps_nfc_hs_cr(hapd, ndef); |
| 1582 | } |
| 1583 | |
| 1584 | |
| 1585 | int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s, |
| 1586 | const struct wpabuf *req, |
| 1587 | const struct wpabuf *sel) |
| 1588 | { |
| 1589 | struct hostapd_data *hapd; |
| 1590 | |
| 1591 | if (wpa_s->ap_iface == NULL) |
| 1592 | return -1; |
| 1593 | hapd = wpa_s->ap_iface->bss[0]; |
| 1594 | return hostapd_wps_nfc_report_handover(hapd, req, sel); |
| 1595 | } |
| 1596 | |
| 1597 | #endif /* CONFIG_WPS_NFC */ |
| 1598 | |
| 1599 | #endif /* CONFIG_WPS */ |
| 1600 | |
| 1601 | |
| 1602 | #ifdef CONFIG_CTRL_IFACE |
| 1603 | |
| 1604 | int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s, |
| 1605 | char *buf, size_t buflen) |
| 1606 | { |
| 1607 | struct hostapd_data *hapd; |
| 1608 | |
| 1609 | if (wpa_s->ap_iface) |
| 1610 | hapd = wpa_s->ap_iface->bss[0]; |
| 1611 | else if (wpa_s->ifmsh) |
| 1612 | hapd = wpa_s->ifmsh->bss[0]; |
| 1613 | else |
| 1614 | return -1; |
| 1615 | return hostapd_ctrl_iface_sta_first(hapd, buf, buflen); |
| 1616 | } |
| 1617 | |
| 1618 | |
| 1619 | int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr, |
| 1620 | char *buf, size_t buflen) |
| 1621 | { |
| 1622 | struct hostapd_data *hapd; |
| 1623 | |
| 1624 | if (wpa_s->ap_iface) |
| 1625 | hapd = wpa_s->ap_iface->bss[0]; |
| 1626 | else if (wpa_s->ifmsh) |
| 1627 | hapd = wpa_s->ifmsh->bss[0]; |
| 1628 | else |
| 1629 | return -1; |
| 1630 | return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen); |
| 1631 | } |
| 1632 | |
| 1633 | |
| 1634 | int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr, |
| 1635 | char *buf, size_t buflen) |
| 1636 | { |
| 1637 | struct hostapd_data *hapd; |
| 1638 | |
| 1639 | if (wpa_s->ap_iface) |
| 1640 | hapd = wpa_s->ap_iface->bss[0]; |
| 1641 | else if (wpa_s->ifmsh) |
| 1642 | hapd = wpa_s->ifmsh->bss[0]; |
| 1643 | else |
| 1644 | return -1; |
| 1645 | return hostapd_ctrl_iface_sta_next(hapd, txtaddr, buf, buflen); |
| 1646 | } |
| 1647 | |
| 1648 | |
| 1649 | int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s, |
| 1650 | const char *txtaddr) |
| 1651 | { |
| 1652 | if (wpa_s->ap_iface == NULL) |
| 1653 | return -1; |
| 1654 | return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0], |
| 1655 | txtaddr); |
| 1656 | } |
| 1657 | |
| 1658 | |
| 1659 | int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s, |
| 1660 | const char *txtaddr) |
| 1661 | { |
| 1662 | if (wpa_s->ap_iface == NULL) |
| 1663 | return -1; |
| 1664 | return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0], |
| 1665 | txtaddr); |
| 1666 | } |
| 1667 | |
| 1668 | |
| 1669 | int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf, |
| 1670 | size_t buflen, int verbose) |
| 1671 | { |
| 1672 | char *pos = buf, *end = buf + buflen; |
| 1673 | int ret; |
| 1674 | struct hostapd_bss_config *conf; |
| 1675 | |
| 1676 | if (wpa_s->ap_iface == NULL) |
| 1677 | return -1; |
| 1678 | |
| 1679 | conf = wpa_s->ap_iface->bss[0]->conf; |
| 1680 | if (conf->wpa == 0) |
| 1681 | return 0; |
| 1682 | |
| 1683 | ret = os_snprintf(pos, end - pos, |
| 1684 | "pairwise_cipher=%s\n" |
| 1685 | "group_cipher=%s\n" |
| 1686 | "key_mgmt=%s\n", |
| 1687 | wpa_cipher_txt(conf->rsn_pairwise), |
| 1688 | wpa_cipher_txt(conf->wpa_group), |
| 1689 | wpa_key_mgmt_txt(conf->wpa_key_mgmt, |
| 1690 | conf->wpa)); |
| 1691 | if (os_snprintf_error(end - pos, ret)) |
| 1692 | return pos - buf; |
| 1693 | pos += ret; |
| 1694 | return pos - buf; |
| 1695 | } |
| 1696 | |
| 1697 | #endif /* CONFIG_CTRL_IFACE */ |
| 1698 | |
| 1699 | |
| 1700 | int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s) |
| 1701 | { |
| 1702 | struct hostapd_iface *iface = wpa_s->ap_iface; |
| 1703 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 1704 | struct hostapd_data *hapd; |
| 1705 | |
| 1706 | if (ssid == NULL || wpa_s->ap_iface == NULL || |
| 1707 | ssid->mode == WPAS_MODE_INFRA || |
| 1708 | ssid->mode == WPAS_MODE_IBSS) |
| 1709 | return -1; |
| 1710 | |
| 1711 | #ifdef CONFIG_P2P |
| 1712 | if (ssid->mode == WPAS_MODE_P2P_GO) |
| 1713 | iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER; |
| 1714 | else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) |
| 1715 | iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER | |
| 1716 | P2P_GROUP_FORMATION; |
| 1717 | #endif /* CONFIG_P2P */ |
| 1718 | |
| 1719 | hapd = iface->bss[0]; |
| 1720 | if (hapd->drv_priv == NULL) |
| 1721 | return -1; |
| 1722 | ieee802_11_set_beacons(iface); |
| 1723 | hostapd_set_ap_wps_ie(hapd); |
| 1724 | |
| 1725 | return 0; |
| 1726 | } |
| 1727 | |
| 1728 | |
| 1729 | int ap_switch_channel(struct wpa_supplicant *wpa_s, |
| 1730 | struct csa_settings *settings) |
| 1731 | { |
| 1732 | #ifdef NEED_AP_MLME |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 1733 | struct hostapd_iface *iface = NULL; |
| 1734 | |
| 1735 | if (wpa_s->ap_iface) |
| 1736 | iface = wpa_s->ap_iface; |
| 1737 | else if (wpa_s->ifmsh) |
| 1738 | iface = wpa_s->ifmsh; |
| 1739 | |
| 1740 | if (!iface || !iface->bss[0]) |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1741 | return -1; |
| 1742 | |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 1743 | return hostapd_switch_channel(iface->bss[0], settings); |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1744 | #else /* NEED_AP_MLME */ |
| 1745 | return -1; |
| 1746 | #endif /* NEED_AP_MLME */ |
| 1747 | } |
| 1748 | |
| 1749 | |
| 1750 | #ifdef CONFIG_CTRL_IFACE |
| 1751 | int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos) |
| 1752 | { |
| 1753 | struct csa_settings settings; |
| 1754 | int ret = hostapd_parse_csa_settings(pos, &settings); |
| 1755 | |
| 1756 | if (ret) |
| 1757 | return ret; |
| 1758 | |
| 1759 | return ap_switch_channel(wpa_s, &settings); |
| 1760 | } |
| 1761 | #endif /* CONFIG_CTRL_IFACE */ |
| 1762 | |
| 1763 | |
| 1764 | void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht, |
| 1765 | int offset, int width, int cf1, int cf2, int finished) |
| 1766 | { |
| 1767 | struct hostapd_iface *iface = wpa_s->ap_iface; |
| 1768 | |
| 1769 | if (!iface) |
| 1770 | iface = wpa_s->ifmsh; |
| 1771 | if (!iface) |
| 1772 | return; |
| 1773 | wpa_s->assoc_freq = freq; |
| qs.xiong | c8ac629 | 2022-09-28 14:20:51 +0800 | [diff] [blame] | 1774 | #if defined(CONFIG_BRCM_GO_CH_SWITCH_NOTIFY) |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1775 | wpa_s->current_ssid->frequency = freq; |
| 1776 | #else |
| 1777 | if (wpa_s->current_ssid) |
| 1778 | wpa_s->current_ssid->frequency = freq; |
| 1779 | hostapd_event_ch_switch(iface->bss[0], freq, ht, |
| 1780 | offset, width, cf1, cf2, finished); |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 1781 | #endif /* CONFIG_DRIVER_NL80211_IFX && CONFIG_BRCM_GO_CH_SWITCH_NOTIFY */ |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | |
| 1785 | int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s, |
| 1786 | const u8 *addr) |
| 1787 | { |
| 1788 | struct hostapd_data *hapd; |
| 1789 | struct hostapd_bss_config *conf; |
| 1790 | |
| 1791 | if (!wpa_s->ap_iface) |
| 1792 | return -1; |
| 1793 | |
| 1794 | if (addr) |
| 1795 | wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR, |
| 1796 | MAC2STR(addr)); |
| 1797 | else |
| 1798 | wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter"); |
| 1799 | |
| 1800 | hapd = wpa_s->ap_iface->bss[0]; |
| 1801 | conf = hapd->conf; |
| 1802 | |
| 1803 | os_free(conf->accept_mac); |
| 1804 | conf->accept_mac = NULL; |
| 1805 | conf->num_accept_mac = 0; |
| 1806 | os_free(conf->deny_mac); |
| 1807 | conf->deny_mac = NULL; |
| 1808 | conf->num_deny_mac = 0; |
| 1809 | |
| 1810 | if (addr == NULL) { |
| 1811 | conf->macaddr_acl = ACCEPT_UNLESS_DENIED; |
| 1812 | return 0; |
| 1813 | } |
| 1814 | |
| 1815 | conf->macaddr_acl = DENY_UNLESS_ACCEPTED; |
| 1816 | conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry)); |
| 1817 | if (conf->accept_mac == NULL) |
| 1818 | return -1; |
| 1819 | os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN); |
| 1820 | conf->num_accept_mac = 1; |
| 1821 | |
| 1822 | return 0; |
| 1823 | } |
| 1824 | |
| 1825 | |
| 1826 | #ifdef CONFIG_WPS_NFC |
| 1827 | int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id, |
| 1828 | const struct wpabuf *pw, const u8 *pubkey_hash) |
| 1829 | { |
| 1830 | struct hostapd_data *hapd; |
| 1831 | struct wps_context *wps; |
| 1832 | |
| 1833 | if (!wpa_s->ap_iface) |
| 1834 | return -1; |
| 1835 | hapd = wpa_s->ap_iface->bss[0]; |
| 1836 | wps = hapd->wps; |
| 1837 | |
| 1838 | if (wpa_s->p2pdev->conf->wps_nfc_dh_pubkey == NULL || |
| 1839 | wpa_s->p2pdev->conf->wps_nfc_dh_privkey == NULL) { |
| 1840 | wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known"); |
| 1841 | return -1; |
| 1842 | } |
| 1843 | |
| 1844 | dh5_free(wps->dh_ctx); |
| 1845 | wpabuf_free(wps->dh_pubkey); |
| 1846 | wpabuf_free(wps->dh_privkey); |
| 1847 | wps->dh_privkey = wpabuf_dup( |
| 1848 | wpa_s->p2pdev->conf->wps_nfc_dh_privkey); |
| 1849 | wps->dh_pubkey = wpabuf_dup( |
| 1850 | wpa_s->p2pdev->conf->wps_nfc_dh_pubkey); |
| 1851 | if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) { |
| 1852 | wps->dh_ctx = NULL; |
| 1853 | wpabuf_free(wps->dh_pubkey); |
| 1854 | wps->dh_pubkey = NULL; |
| 1855 | wpabuf_free(wps->dh_privkey); |
| 1856 | wps->dh_privkey = NULL; |
| 1857 | return -1; |
| 1858 | } |
| 1859 | wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey); |
| 1860 | if (wps->dh_ctx == NULL) |
| 1861 | return -1; |
| 1862 | |
| 1863 | return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash, |
| 1864 | pw_id, |
| 1865 | pw ? wpabuf_head(pw) : NULL, |
| 1866 | pw ? wpabuf_len(pw) : 0, 1); |
| 1867 | } |
| 1868 | #endif /* CONFIG_WPS_NFC */ |
| 1869 | |
| 1870 | |
| 1871 | #ifdef CONFIG_CTRL_IFACE |
| 1872 | int wpas_ap_stop_ap(struct wpa_supplicant *wpa_s) |
| 1873 | { |
| 1874 | struct hostapd_data *hapd; |
| 1875 | |
| 1876 | if (!wpa_s->ap_iface) |
| 1877 | return -1; |
| 1878 | hapd = wpa_s->ap_iface->bss[0]; |
| 1879 | return hostapd_ctrl_iface_stop_ap(hapd); |
| 1880 | } |
| 1881 | |
| 1882 | |
| 1883 | int wpas_ap_pmksa_cache_list(struct wpa_supplicant *wpa_s, char *buf, |
| 1884 | size_t len) |
| 1885 | { |
| 1886 | size_t reply_len = 0, i; |
| 1887 | char ap_delimiter[] = "---- AP ----\n"; |
| 1888 | char mesh_delimiter[] = "---- mesh ----\n"; |
| 1889 | size_t dlen; |
| 1890 | |
| 1891 | if (wpa_s->ap_iface) { |
| 1892 | dlen = os_strlen(ap_delimiter); |
| 1893 | if (dlen > len - reply_len) |
| 1894 | return reply_len; |
| 1895 | os_memcpy(&buf[reply_len], ap_delimiter, dlen); |
| 1896 | reply_len += dlen; |
| 1897 | |
| 1898 | for (i = 0; i < wpa_s->ap_iface->num_bss; i++) { |
| 1899 | reply_len += hostapd_ctrl_iface_pmksa_list( |
| 1900 | wpa_s->ap_iface->bss[i], |
| 1901 | &buf[reply_len], len - reply_len); |
| 1902 | } |
| 1903 | } |
| 1904 | |
| 1905 | if (wpa_s->ifmsh) { |
| 1906 | dlen = os_strlen(mesh_delimiter); |
| 1907 | if (dlen > len - reply_len) |
| 1908 | return reply_len; |
| 1909 | os_memcpy(&buf[reply_len], mesh_delimiter, dlen); |
| 1910 | reply_len += dlen; |
| 1911 | |
| 1912 | reply_len += hostapd_ctrl_iface_pmksa_list( |
| 1913 | wpa_s->ifmsh->bss[0], &buf[reply_len], |
| 1914 | len - reply_len); |
| 1915 | } |
| 1916 | |
| 1917 | return reply_len; |
| 1918 | } |
| 1919 | |
| 1920 | |
| 1921 | void wpas_ap_pmksa_cache_flush(struct wpa_supplicant *wpa_s) |
| 1922 | { |
| 1923 | size_t i; |
| 1924 | |
| 1925 | if (wpa_s->ap_iface) { |
| 1926 | for (i = 0; i < wpa_s->ap_iface->num_bss; i++) |
| 1927 | hostapd_ctrl_iface_pmksa_flush(wpa_s->ap_iface->bss[i]); |
| 1928 | } |
| 1929 | |
| 1930 | if (wpa_s->ifmsh) |
| 1931 | hostapd_ctrl_iface_pmksa_flush(wpa_s->ifmsh->bss[0]); |
| 1932 | } |
| 1933 | |
| 1934 | |
| 1935 | #ifdef CONFIG_PMKSA_CACHE_EXTERNAL |
| 1936 | #ifdef CONFIG_MESH |
| 1937 | |
| 1938 | int wpas_ap_pmksa_cache_list_mesh(struct wpa_supplicant *wpa_s, const u8 *addr, |
| 1939 | char *buf, size_t len) |
| 1940 | { |
| 1941 | return hostapd_ctrl_iface_pmksa_list_mesh(wpa_s->ifmsh->bss[0], addr, |
| 1942 | &buf[0], len); |
| 1943 | } |
| 1944 | |
| 1945 | |
| 1946 | int wpas_ap_pmksa_cache_add_external(struct wpa_supplicant *wpa_s, char *cmd) |
| 1947 | { |
| 1948 | struct external_pmksa_cache *entry; |
| 1949 | void *pmksa_cache; |
| 1950 | |
| 1951 | pmksa_cache = hostapd_ctrl_iface_pmksa_create_entry(wpa_s->own_addr, |
| 1952 | cmd); |
| 1953 | if (!pmksa_cache) |
| 1954 | return -1; |
| 1955 | |
| 1956 | entry = os_zalloc(sizeof(struct external_pmksa_cache)); |
| 1957 | if (!entry) |
| 1958 | return -1; |
| 1959 | |
| 1960 | entry->pmksa_cache = pmksa_cache; |
| 1961 | |
| 1962 | dl_list_add(&wpa_s->mesh_external_pmksa_cache, &entry->list); |
| 1963 | |
| 1964 | return 0; |
| 1965 | } |
| 1966 | |
| 1967 | #endif /* CONFIG_MESH */ |
| 1968 | #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */ |
| 1969 | |
| you.chen | 1dc0c26 | 2023-04-24 17:29:00 +0800 | [diff] [blame] | 1970 | |
| 1971 | int wpas_ap_update_beacon(struct wpa_supplicant *wpa_s) |
| 1972 | { |
| 1973 | struct hostapd_data *hapd; |
| 1974 | |
| 1975 | if (!wpa_s->ap_iface) |
| 1976 | return -1; |
| 1977 | hapd = wpa_s->ap_iface->bss[0]; |
| 1978 | |
| 1979 | wpabuf_free(hapd->conf->assocresp_elements); |
| 1980 | hapd->conf->assocresp_elements = NULL; |
| 1981 | if (wpa_s->conf->ap_assocresp_elements) { |
| 1982 | hapd->conf->assocresp_elements = |
| 1983 | wpabuf_dup(wpa_s->conf->ap_assocresp_elements); |
| 1984 | } |
| 1985 | |
| 1986 | wpabuf_free(hapd->conf->vendor_elements); |
| 1987 | hapd->conf->vendor_elements = NULL; |
| 1988 | if (wpa_s->conf->ap_vendor_elements) { |
| 1989 | hapd->conf->vendor_elements = |
| 1990 | wpabuf_dup(wpa_s->conf->ap_vendor_elements); |
| 1991 | } |
| 1992 | |
| 1993 | return ieee802_11_set_beacon(hapd); |
| 1994 | } |
| 1995 | |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1996 | #endif /* CONFIG_CTRL_IFACE */ |
| 1997 | |
| 1998 | |
| 1999 | #ifdef NEED_AP_MLME |
| 2000 | void wpas_ap_event_dfs_radar_detected(struct wpa_supplicant *wpa_s, |
| 2001 | struct dfs_event *radar) |
| 2002 | { |
| 2003 | struct hostapd_iface *iface = wpa_s->ap_iface; |
| 2004 | |
| 2005 | if (!iface) |
| 2006 | iface = wpa_s->ifmsh; |
| 2007 | if (!iface || !iface->bss[0]) |
| 2008 | return; |
| 2009 | wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq); |
| 2010 | hostapd_dfs_radar_detected(iface, radar->freq, |
| 2011 | radar->ht_enabled, radar->chan_offset, |
| 2012 | radar->chan_width, |
| 2013 | radar->cf1, radar->cf2); |
| 2014 | } |
| 2015 | |
| 2016 | |
| 2017 | void wpas_ap_event_dfs_cac_started(struct wpa_supplicant *wpa_s, |
| 2018 | struct dfs_event *radar) |
| 2019 | { |
| 2020 | struct hostapd_iface *iface = wpa_s->ap_iface; |
| 2021 | |
| 2022 | if (!iface) |
| 2023 | iface = wpa_s->ifmsh; |
| 2024 | if (!iface || !iface->bss[0]) |
| 2025 | return; |
| 2026 | wpa_printf(MSG_DEBUG, "DFS CAC started on %d MHz", radar->freq); |
| 2027 | hostapd_dfs_start_cac(iface, radar->freq, |
| 2028 | radar->ht_enabled, radar->chan_offset, |
| 2029 | radar->chan_width, radar->cf1, radar->cf2); |
| 2030 | } |
| 2031 | |
| 2032 | |
| 2033 | void wpas_ap_event_dfs_cac_finished(struct wpa_supplicant *wpa_s, |
| 2034 | struct dfs_event *radar) |
| 2035 | { |
| 2036 | struct hostapd_iface *iface = wpa_s->ap_iface; |
| 2037 | |
| 2038 | if (!iface) |
| 2039 | iface = wpa_s->ifmsh; |
| 2040 | if (!iface || !iface->bss[0]) |
| 2041 | return; |
| 2042 | wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq); |
| 2043 | hostapd_dfs_complete_cac(iface, 1, radar->freq, |
| 2044 | radar->ht_enabled, radar->chan_offset, |
| 2045 | radar->chan_width, radar->cf1, radar->cf2); |
| 2046 | } |
| 2047 | |
| 2048 | |
| 2049 | void wpas_ap_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s, |
| 2050 | struct dfs_event *radar) |
| 2051 | { |
| 2052 | struct hostapd_iface *iface = wpa_s->ap_iface; |
| 2053 | |
| 2054 | if (!iface) |
| 2055 | iface = wpa_s->ifmsh; |
| 2056 | if (!iface || !iface->bss[0]) |
| 2057 | return; |
| 2058 | wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq); |
| 2059 | hostapd_dfs_complete_cac(iface, 0, radar->freq, |
| 2060 | radar->ht_enabled, radar->chan_offset, |
| 2061 | radar->chan_width, radar->cf1, radar->cf2); |
| 2062 | } |
| 2063 | |
| 2064 | |
| 2065 | void wpas_ap_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s, |
| 2066 | struct dfs_event *radar) |
| 2067 | { |
| 2068 | struct hostapd_iface *iface = wpa_s->ap_iface; |
| 2069 | |
| 2070 | if (!iface) |
| 2071 | iface = wpa_s->ifmsh; |
| 2072 | if (!iface || !iface->bss[0]) |
| 2073 | return; |
| 2074 | wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq); |
| 2075 | hostapd_dfs_nop_finished(iface, radar->freq, |
| 2076 | radar->ht_enabled, radar->chan_offset, |
| 2077 | radar->chan_width, radar->cf1, radar->cf2); |
| 2078 | } |
| 2079 | #endif /* NEED_AP_MLME */ |
| 2080 | |
| 2081 | |
| 2082 | void ap_periodic(struct wpa_supplicant *wpa_s) |
| 2083 | { |
| 2084 | if (wpa_s->ap_iface) |
| 2085 | hostapd_periodic_iface(wpa_s->ap_iface); |
| 2086 | } |
| 2087 | |
| you.chen | a8ba7fe | 2022-04-08 17:10:16 +0800 | [diff] [blame] | 2088 | |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 2089 | #ifdef CONFIG_BRCM_AUTOMOTIVE |
| 2090 | void wpas_ap_set_interworking_ie(struct wpa_supplicant *wpa_s) |
| 2091 | { |
| 2092 | int ret = 0; |
| 2093 | ret = wpa_supplicant_ap_update_beacon(wpa_s); |
| 2094 | wpa_printf(MSG_DEBUG, "%s: ret:%d\n", __FUNCTION__, ret); |
| 2095 | } |
| 2096 | #endif |