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