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