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