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