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