blob: 807e36d07609e8968c67a3cffd9893b412debac6 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
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 Shmidtc5ec7f52012-03-06 16:33:24 -08006 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008 */
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 Shmidtb7b4d0e2013-08-26 12:09:05 -070017#include "eapol_supp/eapol_supp_sm.h"
Dmitry Shmidtcf32e602014-01-28 10:57:39 -080018#include "crypto/dh_group5.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070019#include "ap/hostapd.h"
20#include "ap/ap_config.h"
21#include "ap/ap_drv_ops.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080022#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070023#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 Shmidt203eadb2015-03-05 14:16:04 -080029#include "ap/dfs.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070030#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
43static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx);
44#endif /* CONFIG_WPS */
45
46
Hai Shalom60840252021-02-19 19:02:11 -080047#ifdef CONFIG_P2P
Hsis-Chang Chen44b08ec2020-11-18 16:21:29 +053048static 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 Shalom60840252021-02-19 19:02:11 -080067#endif /* CONFIG_P2P */
Hsis-Chang Chen44b08ec2020-11-18 16:21:29 +053068
69
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070070static void wpas_conf_ap_vht(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070071 struct wpa_ssid *ssid,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070072 struct hostapd_config *conf,
73 struct hostapd_hw_modes *mode)
74{
Dmitry Shmidt21de2142014-04-08 10:50:52 -070075#ifdef CONFIG_P2P
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070076 u8 center_chan = 0;
77 u8 channel = conf->channel;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070078#endif /* CONFIG_P2P */
Hai Shalom899fcc72020-10-19 14:38:18 -070079 u8 freq_seg_idx;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070080
81 if (!conf->secondary_channel)
82 goto no_vht;
83
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070084 /* Use the maximum oper channel width if it's given. */
85 if (ssid->max_oper_chwidth)
Hai Shalom899fcc72020-10-19 14:38:18 -070086 hostapd_set_oper_chwidth(conf, ssid->max_oper_chwidth);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070087
Hai Shalom899fcc72020-10-19 14:38:18 -070088 if (hostapd_get_oper_chwidth(conf) == CHANWIDTH_80P80MHZ) {
89 ieee80211_freq_to_chan(ssid->vht_center_freq2,
90 &freq_seg_idx);
91 hostapd_set_oper_centr_freq_seg1_idx(conf, freq_seg_idx);
92 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070093
94 if (!ssid->p2p_group) {
Hai Shalom899fcc72020-10-19 14:38:18 -070095 if (!ssid->vht_center_freq1)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070096 goto no_vht;
97 ieee80211_freq_to_chan(ssid->vht_center_freq1,
Hai Shalom899fcc72020-10-19 14:38:18 -070098 &freq_seg_idx);
99 hostapd_set_oper_centr_freq_seg0_idx(conf, freq_seg_idx);
100
101 wpa_printf(MSG_DEBUG,
102 "VHT seg0 index %d and seg1 index %d for AP",
103 hostapd_get_oper_centr_freq_seg0_idx(conf),
104 hostapd_get_oper_centr_freq_seg1_idx(conf));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700105 return;
106 }
107
108#ifdef CONFIG_P2P
Hai Shalom899fcc72020-10-19 14:38:18 -0700109 switch (hostapd_get_oper_chwidth(conf)) {
Hai Shalom81f62d82019-07-22 12:10:00 -0700110 case CHANWIDTH_80MHZ:
111 case CHANWIDTH_80P80MHZ:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800112 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700113 wpa_printf(MSG_DEBUG,
114 "VHT center channel %u for 80 or 80+80 MHz bandwidth",
115 center_chan);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800116 break;
Hai Shalom81f62d82019-07-22 12:10:00 -0700117 case CHANWIDTH_160MHZ:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800118 center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700119 wpa_printf(MSG_DEBUG,
120 "VHT center channel %u for 160 MHz bandwidth",
121 center_chan);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800122 break;
123 default:
124 /*
125 * conf->vht_oper_chwidth might not be set for non-P2P GO cases,
126 * try oper_cwidth 160 MHz first then VHT 80 MHz, if 160 MHz is
127 * not supported.
128 */
Hai Shalom899fcc72020-10-19 14:38:18 -0700129 hostapd_set_oper_chwidth(conf, CHANWIDTH_160MHZ);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800130 center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel);
Hsis-Chang Chen44b08ec2020-11-18 16:21:29 +0530131 if (center_chan && is_chanwidth160_supported(mode, conf)) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700132 wpa_printf(MSG_DEBUG,
133 "VHT center channel %u for auto-selected 160 MHz bandwidth",
134 center_chan);
135 } else {
Hai Shalom899fcc72020-10-19 14:38:18 -0700136 hostapd_set_oper_chwidth(conf, CHANWIDTH_80MHZ);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800137 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode,
138 channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700139 wpa_printf(MSG_DEBUG,
140 "VHT center channel %u for auto-selected 80 MHz bandwidth",
141 center_chan);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800142 }
143 break;
144 }
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700145 if (!center_chan)
146 goto no_vht;
147
Hai Shalom899fcc72020-10-19 14:38:18 -0700148 hostapd_set_oper_centr_freq_seg0_idx(conf, center_chan);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700149 wpa_printf(MSG_DEBUG, "VHT seg0 index %d for P2P GO",
Hai Shalom899fcc72020-10-19 14:38:18 -0700150 hostapd_get_oper_centr_freq_seg0_idx(conf));
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700151 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700152#endif /* CONFIG_P2P */
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700153
154no_vht:
Roshan Pius3a1667e2018-07-03 15:17:14 -0700155 wpa_printf(MSG_DEBUG,
156 "No VHT higher bandwidth support for the selected channel %d",
157 conf->channel);
Hai Shalom899fcc72020-10-19 14:38:18 -0700158 hostapd_set_oper_centr_freq_seg0_idx(
159 conf, conf->channel + conf->secondary_channel * 2);
160 hostapd_set_oper_chwidth(conf, CHANWIDTH_USE_HT);
161}
162
163
164static struct hostapd_hw_modes *
165wpa_supplicant_find_hw_mode(struct wpa_supplicant *wpa_s,
166 enum hostapd_hw_mode hw_mode)
167{
168 struct hostapd_hw_modes *mode = NULL;
169 int i;
170
171 for (i = 0; i < wpa_s->hw.num_modes; i++) {
172 if (wpa_s->hw.modes[i].mode == hw_mode) {
173 mode = &wpa_s->hw.modes[i];
174 break;
175 }
176 }
177
178 return mode;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700179}
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700180
181
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800182int wpa_supplicant_conf_ap_ht(struct wpa_supplicant *wpa_s,
183 struct wpa_ssid *ssid,
184 struct hostapd_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700185{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800186 conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency,
187 &conf->channel);
188
189 if (conf->hw_mode == NUM_HOSTAPD_MODES) {
190 wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
191 ssid->frequency);
192 return -1;
193 }
194
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700195 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800196 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
197 * and a mask of allowed capabilities within conf->ht_capab.
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700198 * Using default config settings for: conf->ht_op_mode_fixed,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800199 * conf->secondary_channel, conf->require_ht
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700200 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800201 if (wpa_s->hw.modes) {
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700202 struct hostapd_hw_modes *mode = NULL;
Hai Shalom899fcc72020-10-19 14:38:18 -0700203 int no_ht = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700204
205 wpa_printf(MSG_DEBUG,
206 "Determining HT/VHT options based on driver capabilities (freq=%u chan=%u)",
207 ssid->frequency, conf->channel);
208
Hai Shalom899fcc72020-10-19 14:38:18 -0700209 mode = wpa_supplicant_find_hw_mode(wpa_s, conf->hw_mode);
210
211 /* May drop to IEEE 802.11b if the driver does not support IEEE
212 * 802.11g */
213 if (!mode && conf->hw_mode == HOSTAPD_MODE_IEEE80211G) {
214 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
215 wpa_printf(MSG_INFO,
216 "Try downgrade to IEEE 802.11b as 802.11g is not supported by the current hardware");
217 mode = wpa_supplicant_find_hw_mode(wpa_s,
218 conf->hw_mode);
219 }
220
221 if (!mode) {
222 wpa_printf(MSG_ERROR,
223 "No match between requested and supported hw modes found");
224 return -1;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700225 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700226
227#ifdef CONFIG_HT_OVERRIDES
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700228 if (ssid->disable_ht)
229 ssid->ht = 0;
230#endif /* CONFIG_HT_OVERRIDES */
231
232 if (!ssid->ht) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700233 wpa_printf(MSG_DEBUG,
234 "HT not enabled in network profile");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700235 conf->ieee80211n = 0;
236 conf->ht_capab = 0;
237 no_ht = 1;
238 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700239
240 if (!no_ht && mode && mode->ht_capab) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700241 wpa_printf(MSG_DEBUG,
242 "Enable HT support (p2p_group=%d 11a=%d ht40_hw_capab=%d ssid->ht40=%d)",
243 ssid->p2p_group,
244 conf->hw_mode == HOSTAPD_MODE_IEEE80211A,
245 !!(mode->ht_capab &
246 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET),
247 ssid->ht40);
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700248 conf->ieee80211n = 1;
Hai Shalom899fcc72020-10-19 14:38:18 -0700249
250 if (ssid->ht40 &&
251 (mode->ht_capab &
252 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
253 conf->secondary_channel = ssid->ht40;
254 else
255 conf->secondary_channel = 0;
256
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700257#ifdef CONFIG_P2P
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700258 if (ssid->p2p_group &&
259 conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700260 (mode->ht_capab &
261 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -0700262 ssid->ht40) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700263 conf->secondary_channel =
264 wpas_p2p_get_ht40_mode(wpa_s, mode,
265 conf->channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700266 wpa_printf(MSG_DEBUG,
267 "HT secondary channel offset %d for P2P group",
268 conf->secondary_channel);
Hai Shalom60840252021-02-19 19:02:11 -0800269 } else if (ssid->p2p_group && conf->secondary_channel &&
270 conf->hw_mode != HOSTAPD_MODE_IEEE80211A) {
271 /* This ended up trying to configure invalid
272 * 2.4 GHz channels (e.g., HT40+ on channel 11)
273 * in some cases, so clear the secondary channel
274 * configuration now to avoid such cases that
275 * would lead to group formation failures. */
276 wpa_printf(MSG_DEBUG,
277 "Disable HT secondary channel for P2P group on 2.4 GHz");
278 conf->secondary_channel = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700279 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700280#endif /* CONFIG_P2P */
281
282 if (!ssid->p2p_group &&
283 (mode->ht_capab &
Roshan Pius3a1667e2018-07-03 15:17:14 -0700284 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700285 conf->secondary_channel = ssid->ht40;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700286 wpa_printf(MSG_DEBUG,
287 "HT secondary channel offset %d for AP",
288 conf->secondary_channel);
289 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700290
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700291 if (conf->secondary_channel)
292 conf->ht_capab |=
293 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800294
295 /*
296 * white-list capabilities that won't cause issues
297 * to connecting stations, while leaving the current
298 * capabilities intact (currently disabled SMPS).
299 */
300 conf->ht_capab |= mode->ht_capab &
301 (HT_CAP_INFO_GREEN_FIELD |
302 HT_CAP_INFO_SHORT_GI20MHZ |
303 HT_CAP_INFO_SHORT_GI40MHZ |
304 HT_CAP_INFO_RX_STBC_MASK |
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800305 HT_CAP_INFO_TX_STBC |
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800306 HT_CAP_INFO_MAX_AMSDU_SIZE);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700307
Hai Shalom899fcc72020-10-19 14:38:18 -0700308 /* check this before VHT, because setting oper chan
309 * width and friends is the same call for HE and VHT
310 * and checks if conf->ieee8021ax == 1 */
311 if (mode->he_capab[wpas_mode_to_ieee80211_mode(
312 ssid->mode)].he_supported &&
313 ssid->he)
314 conf->ieee80211ax = 1;
315
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700316 if (mode->vht_capab && ssid->vht) {
317 conf->ieee80211ac = 1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800318 conf->vht_capab |= mode->vht_capab;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700319 wpas_conf_ap_vht(wpa_s, ssid, conf, mode);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700320 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800321 }
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700322 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800323
324 if (conf->secondary_channel) {
325 struct wpa_supplicant *iface;
326
327 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
328 {
329 if (iface == wpa_s ||
330 iface->wpa_state < WPA_AUTHENTICATING ||
331 (int) iface->assoc_freq != ssid->frequency)
332 continue;
333
334 /*
335 * Do not allow 40 MHz co-ex PRI/SEC switch to force us
336 * to change our PRI channel since we have an existing,
337 * concurrent connection on that channel and doing
338 * multi-channel concurrency is likely to cause more
339 * harm than using different PRI/SEC selection in
340 * environment with multiple BSSes on these two channels
341 * with mixed 20 MHz or PRI channel selection.
342 */
343 conf->no_pri_sec_switch = 1;
344 }
345 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800346
347 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800348}
349
350
351static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
352 struct wpa_ssid *ssid,
353 struct hostapd_config *conf)
354{
355 struct hostapd_bss_config *bss = conf->bss[0];
356
357 conf->driver = wpa_s->driver;
358
359 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
360
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800361 if (wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800362 return -1;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700363
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700364 if (ssid->pbss > 1) {
365 wpa_printf(MSG_ERROR, "Invalid pbss value(%d) for AP mode",
366 ssid->pbss);
367 return -1;
368 }
369 bss->pbss = ssid->pbss;
370
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800371#ifdef CONFIG_ACS
372 if (ssid->acs) {
373 /* Setting channel to 0 in order to enable ACS */
374 conf->channel = 0;
375 wpa_printf(MSG_DEBUG, "Use automatic channel selection");
376 }
377#endif /* CONFIG_ACS */
378
Roshan Pius3a1667e2018-07-03 15:17:14 -0700379 if (ieee80211_is_dfs(ssid->frequency, wpa_s->hw.modes,
380 wpa_s->hw.num_modes) && wpa_s->conf->country[0]) {
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800381 conf->ieee80211h = 1;
382 conf->ieee80211d = 1;
383 conf->country[0] = wpa_s->conf->country[0];
384 conf->country[1] = wpa_s->conf->country[1];
Paul Stewart092955c2017-02-06 09:13:09 -0800385 conf->country[2] = ' ';
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800386 }
387
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700388#ifdef CONFIG_P2P
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700389 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
390 (ssid->mode == WPAS_MODE_P2P_GO ||
391 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700392 /* Remove 802.11b rates from supported and basic rate sets */
393 int *list = os_malloc(4 * sizeof(int));
394 if (list) {
395 list[0] = 60;
396 list[1] = 120;
397 list[2] = 240;
398 list[3] = -1;
399 }
400 conf->basic_rates = list;
401
402 list = os_malloc(9 * sizeof(int));
403 if (list) {
404 list[0] = 60;
405 list[1] = 90;
406 list[2] = 120;
407 list[3] = 180;
408 list[4] = 240;
409 list[5] = 360;
410 list[6] = 480;
411 list[7] = 540;
412 list[8] = -1;
413 }
414 conf->supported_rates = list;
Hai Shalom021b0b52019-04-10 11:17:58 -0700415 }
416
Hai Shalom74f70d42019-02-11 14:42:39 -0800417#ifdef CONFIG_IEEE80211AX
Hai Shalom021b0b52019-04-10 11:17:58 -0700418 if (ssid->mode == WPAS_MODE_P2P_GO ||
419 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Hai Shalom74f70d42019-02-11 14:42:39 -0800420 conf->ieee80211ax = ssid->he;
421#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800422
423 bss->isolate = !wpa_s->conf->p2p_intra_bss;
Hai Shalomfdcde762020-04-02 11:19:20 -0700424 bss->extended_key_id = wpa_s->conf->extended_key_id;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700425 bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
Hai Shalomfdcde762020-04-02 11:19:20 -0700426 bss->wpa_deny_ptk0_rekey = ssid->wpa_deny_ptk0_rekey;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800427
428 if (ssid->p2p_group) {
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800429 os_memcpy(bss->ip_addr_go, wpa_s->p2pdev->conf->ip_addr_go, 4);
430 os_memcpy(bss->ip_addr_mask, wpa_s->p2pdev->conf->ip_addr_mask,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800431 4);
432 os_memcpy(bss->ip_addr_start,
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800433 wpa_s->p2pdev->conf->ip_addr_start, 4);
434 os_memcpy(bss->ip_addr_end, wpa_s->p2pdev->conf->ip_addr_end,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800435 4);
436 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700437#endif /* CONFIG_P2P */
438
439 if (ssid->ssid_len == 0) {
440 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
441 return -1;
442 }
443 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700444 bss->ssid.ssid_len = ssid->ssid_len;
445 bss->ssid.ssid_set = 1;
446
Dmitry Shmidt04949592012-07-19 12:16:46 -0700447 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
448
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800449 if (ssid->auth_alg)
450 bss->auth_algs = ssid->auth_alg;
451
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700452 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
453 bss->wpa = ssid->proto;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700454 if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
455 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
456 else
457 bss->wpa_key_mgmt = ssid->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700458 bss->wpa_pairwise = ssid->pairwise_cipher;
Hai Shalomc3565922019-10-28 11:58:20 -0700459 if (wpa_key_mgmt_sae(bss->wpa_key_mgmt) && ssid->passphrase) {
460 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
461 } else if (ssid->psk_set) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800462 bin_clear_free(bss->ssid.wpa_psk, sizeof(*bss->ssid.wpa_psk));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700463 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
464 if (bss->ssid.wpa_psk == NULL)
465 return -1;
466 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
467 bss->ssid.wpa_psk->group = 1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700468 bss->ssid.wpa_psk_set = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800469 } else if (ssid->passphrase) {
470 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
Hai Shalomfdcde762020-04-02 11:19:20 -0700471#ifdef CONFIG_WEP
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800472 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
473 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
474 struct hostapd_wep_keys *wep = &bss->ssid.wep;
475 int i;
476 for (i = 0; i < NUM_WEP_KEYS; i++) {
477 if (ssid->wep_key_len[i] == 0)
478 continue;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700479 wep->key[i] = os_memdup(ssid->wep_key[i],
480 ssid->wep_key_len[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800481 if (wep->key[i] == NULL)
482 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800483 wep->len[i] = ssid->wep_key_len[i];
484 }
485 wep->idx = ssid->wep_tx_keyidx;
486 wep->keys_set = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700487#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700488 }
Hai Shalomc3565922019-10-28 11:58:20 -0700489#ifdef CONFIG_SAE
490 if (ssid->sae_password) {
491 struct sae_password_entry *pw;
492
493 pw = os_zalloc(sizeof(*pw));
494 if (!pw)
495 return -1;
496 os_memset(pw->peer_addr, 0xff, ETH_ALEN);
497 pw->password = os_strdup(ssid->sae_password);
498 if (!pw->password) {
499 os_free(pw);
500 return -1;
501 }
502 if (ssid->sae_password_id) {
503 pw->identifier = os_strdup(ssid->sae_password_id);
504 if (!pw->identifier) {
505 str_clear_free(pw->password);
506 os_free(pw);
507 return -1;
508 }
509 }
510
511 pw->next = bss->sae_passwords;
512 bss->sae_passwords = pw;
513 }
514
515 bss->sae_pwe = wpa_s->conf->sae_pwe;
516#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700517
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700518 if (wpa_s->conf->go_interworking) {
519 wpa_printf(MSG_DEBUG,
520 "P2P: Enable Interworking with access_network_type: %d",
521 wpa_s->conf->go_access_network_type);
522 bss->interworking = wpa_s->conf->go_interworking;
523 bss->access_network_type = wpa_s->conf->go_access_network_type;
524 bss->internet = wpa_s->conf->go_internet;
525 if (wpa_s->conf->go_venue_group) {
526 wpa_printf(MSG_DEBUG,
527 "P2P: Venue group: %d Venue type: %d",
528 wpa_s->conf->go_venue_group,
529 wpa_s->conf->go_venue_type);
530 bss->venue_group = wpa_s->conf->go_venue_group;
531 bss->venue_type = wpa_s->conf->go_venue_type;
532 bss->venue_info_set = 1;
533 }
534 }
535
Dmitry Shmidt04949592012-07-19 12:16:46 -0700536 if (ssid->ap_max_inactivity)
537 bss->ap_max_inactivity = ssid->ap_max_inactivity;
538
539 if (ssid->dtim_period)
540 bss->dtim_period = ssid->dtim_period;
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -0800541 else if (wpa_s->conf->dtim_period)
542 bss->dtim_period = wpa_s->conf->dtim_period;
543
544 if (ssid->beacon_int)
545 conf->beacon_int = ssid->beacon_int;
546 else if (wpa_s->conf->beacon_int)
547 conf->beacon_int = wpa_s->conf->beacon_int;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700548
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800549#ifdef CONFIG_P2P
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800550 if (ssid->mode == WPAS_MODE_P2P_GO ||
551 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
552 if (wpa_s->conf->p2p_go_ctwindow > conf->beacon_int) {
553 wpa_printf(MSG_INFO,
554 "CTWindow (%d) is bigger than beacon interval (%d) - avoid configuring it",
555 wpa_s->conf->p2p_go_ctwindow,
556 conf->beacon_int);
557 conf->p2p_go_ctwindow = 0;
558 } else {
559 conf->p2p_go_ctwindow = wpa_s->conf->p2p_go_ctwindow;
560 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800561 }
562#endif /* CONFIG_P2P */
563
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800564 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
565 bss->rsn_pairwise = bss->wpa_pairwise;
566 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
567 bss->rsn_pairwise);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700568
Hai Shalomfdcde762020-04-02 11:19:20 -0700569 if (bss->wpa && bss->ieee802_1x) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700570 bss->ssid.security_policy = SECURITY_WPA;
Hai Shalomfdcde762020-04-02 11:19:20 -0700571 } else if (bss->wpa) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700572 bss->ssid.security_policy = SECURITY_WPA_PSK;
Hai Shalomfdcde762020-04-02 11:19:20 -0700573#ifdef CONFIG_WEP
574 } else if (bss->ieee802_1x) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800575 int cipher = WPA_CIPHER_NONE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700576 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
577 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800578 if (bss->default_wep_key_len)
579 cipher = bss->default_wep_key_len >= 13 ?
580 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
581 bss->wpa_group = cipher;
582 bss->wpa_pairwise = cipher;
583 bss->rsn_pairwise = cipher;
584 } else if (bss->ssid.wep.keys_set) {
585 int cipher = WPA_CIPHER_WEP40;
586 if (bss->ssid.wep.len[0] >= 13)
587 cipher = WPA_CIPHER_WEP104;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700588 bss->ssid.security_policy = SECURITY_STATIC_WEP;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800589 bss->wpa_group = cipher;
590 bss->wpa_pairwise = cipher;
591 bss->rsn_pairwise = cipher;
Hai Shalomfdcde762020-04-02 11:19:20 -0700592#endif /* CONFIG_WEP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800593 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700594 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800595 bss->wpa_group = WPA_CIPHER_NONE;
596 bss->wpa_pairwise = WPA_CIPHER_NONE;
597 bss->rsn_pairwise = WPA_CIPHER_NONE;
598 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700599
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700600 if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
601 (bss->wpa_group == WPA_CIPHER_CCMP ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800602 bss->wpa_group == WPA_CIPHER_GCMP ||
603 bss->wpa_group == WPA_CIPHER_CCMP_256 ||
604 bss->wpa_group == WPA_CIPHER_GCMP_256)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700605 /*
606 * Strong ciphers do not need frequent rekeying, so increase
607 * the default GTK rekeying period to 24 hours.
608 */
609 bss->wpa_group_rekey = 86400;
610 }
611
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700612 if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT)
613 bss->ieee80211w = ssid->ieee80211w;
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700614
Hai Shalom74f70d42019-02-11 14:42:39 -0800615#ifdef CONFIG_OCV
616 bss->ocv = ssid->ocv;
617#endif /* CONFIG_OCV */
618
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700619#ifdef CONFIG_WPS
620 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800621 * Enable WPS by default for open and WPA/WPA2-Personal network, but
622 * require user interaction to actually use it. Only the internal
623 * Registrar is supported.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700624 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800625 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
626 bss->ssid.security_policy != SECURITY_PLAINTEXT)
627 goto no_wps;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800628 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800629 (!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ||
630 !(bss->wpa & 2)))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800631 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
632 * configuration */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700633 if (ssid->wps_disabled)
634 goto no_wps;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700635 bss->eap_server = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700636
637 if (!ssid->ignore_broadcast_ssid)
638 bss->wps_state = 2;
639
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700640 bss->ap_setup_locked = 2;
641 if (wpa_s->conf->config_methods)
642 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
643 os_memcpy(bss->device_type, wpa_s->conf->device_type,
644 WPS_DEV_TYPE_LEN);
645 if (wpa_s->conf->device_name) {
646 bss->device_name = os_strdup(wpa_s->conf->device_name);
647 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
648 }
649 if (wpa_s->conf->manufacturer)
650 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
651 if (wpa_s->conf->model_name)
652 bss->model_name = os_strdup(wpa_s->conf->model_name);
653 if (wpa_s->conf->model_number)
654 bss->model_number = os_strdup(wpa_s->conf->model_number);
655 if (wpa_s->conf->serial_number)
656 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
657 if (is_nil_uuid(wpa_s->conf->uuid))
658 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
659 else
660 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
661 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700662 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -0700663 if (ssid->eap.fragment_size != DEFAULT_FRAGMENT_SIZE)
664 bss->fragment_size = ssid->eap.fragment_size;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800665no_wps:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700666#endif /* CONFIG_WPS */
667
668 if (wpa_s->max_stations &&
669 wpa_s->max_stations < wpa_s->conf->max_num_sta)
670 bss->max_num_sta = wpa_s->max_stations;
671 else
672 bss->max_num_sta = wpa_s->conf->max_num_sta;
673
Roshan Pius3a1667e2018-07-03 15:17:14 -0700674 if (!bss->isolate)
675 bss->isolate = wpa_s->conf->ap_isolate;
676
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700677 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
678
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700679 if (wpa_s->conf->ap_vendor_elements) {
680 bss->vendor_elements =
681 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
682 }
683
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700684 bss->ftm_responder = wpa_s->conf->ftm_responder;
685 bss->ftm_initiator = wpa_s->conf->ftm_initiator;
686
Hai Shalomfdcde762020-04-02 11:19:20 -0700687 bss->transition_disable = ssid->transition_disable;
688
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700689 return 0;
690}
691
692
693static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
694{
695#ifdef CONFIG_P2P
696 struct wpa_supplicant *wpa_s = ctx;
697 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700698
699 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700700 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700701 return;
Dmitry Shmidt18463232014-01-24 12:29:41 -0800702 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
703 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700704 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
705 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700706 buf + IEEE80211_HDRLEN + 1,
707 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700708#endif /* CONFIG_P2P */
709}
710
711
712static void ap_wps_event_cb(void *ctx, enum wps_event event,
713 union wps_event_data *data)
714{
715#ifdef CONFIG_P2P
716 struct wpa_supplicant *wpa_s = ctx;
717
Jouni Malinen75ecf522011-06-27 15:19:46 -0700718 if (event == WPS_EV_FAIL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700719 struct wps_event_fail *fail = &data->fail;
720
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800721 if (wpa_s->p2pdev && wpa_s->p2pdev != wpa_s &&
Jouni Malinen75ecf522011-06-27 15:19:46 -0700722 wpa_s == wpa_s->global->p2p_group_formation) {
723 /*
724 * src/ap/wps_hostapd.c has already sent this on the
725 * main interface, so only send on the parent interface
726 * here if needed.
727 */
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800728 wpa_msg(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_FAIL
Jouni Malinen75ecf522011-06-27 15:19:46 -0700729 "msg=%d config_error=%d",
730 fail->msg, fail->config_error);
731 }
732 wpas_p2p_wps_failed(wpa_s, fail);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700733 }
734#endif /* CONFIG_P2P */
735}
736
737
738static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800739 int authorized, const u8 *p2p_dev_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700740{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800741 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700742}
743
744
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700745#ifdef CONFIG_P2P
746static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
747 const u8 *psk, size_t psk_len)
748{
749
750 struct wpa_supplicant *wpa_s = ctx;
751 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
752 return;
753 wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
754}
755#endif /* CONFIG_P2P */
756
757
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700758static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
759{
760#ifdef CONFIG_P2P
761 struct wpa_supplicant *wpa_s = ctx;
762 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700763
764 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700765 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700766 return -1;
767 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
768 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700769 buf + IEEE80211_HDRLEN + 1,
770 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700771#endif /* CONFIG_P2P */
772 return 0;
773}
774
775
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800776static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700777 const u8 *bssid, const u8 *ie, size_t ie_len,
778 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700779{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700780 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700781 unsigned int freq = 0;
782
783 if (wpa_s->ap_iface)
784 freq = wpa_s->ap_iface->freq;
785
Dmitry Shmidt04949592012-07-19 12:16:46 -0700786 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700787 freq, ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700788}
789
790
791static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
792 const u8 *uuid_e)
793{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700794 struct wpa_supplicant *wpa_s = ctx;
795 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700796}
797
798
799static void wpas_ap_configured_cb(void *ctx)
800{
801 struct wpa_supplicant *wpa_s = ctx;
802
Roshan Pius3a1667e2018-07-03 15:17:14 -0700803 wpa_printf(MSG_DEBUG, "AP interface setup completed - state %s",
804 hostapd_state_text(wpa_s->ap_iface->state));
805 if (wpa_s->ap_iface->state == HAPD_IFACE_DISABLED) {
806 wpa_supplicant_ap_deinit(wpa_s);
807 return;
808 }
809
Sunil Ravi236f0f52021-06-29 11:18:20 -0700810 if (wpa_s->current_ssid) {
811 int acs = 0;
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800812#ifdef CONFIG_ACS
Sunil Ravi236f0f52021-06-29 11:18:20 -0700813 acs = wpa_s->current_ssid->acs;
814#endif
815 if (acs || (wpa_s->assoc_freq && wpa_s->ap_iface->freq &&
816 wpa_s->assoc_freq != wpa_s->ap_iface->freq)) {
817 wpa_s->assoc_freq = wpa_s->ap_iface->freq;
818 wpa_s->current_ssid->frequency = wpa_s->ap_iface->freq;
819 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700820 }
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800821
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700822 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
823
824 if (wpa_s->ap_configured_cb)
825 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
826 wpa_s->ap_configured_cb_data);
827}
828
829
830int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
831 struct wpa_ssid *ssid)
832{
833 struct wpa_driver_associate_params params;
834 struct hostapd_iface *hapd_iface;
835 struct hostapd_config *conf;
836 size_t i;
837
838 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
839 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
840 return -1;
841 }
842
843 wpa_supplicant_ap_deinit(wpa_s);
844
845 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
846 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
847
848 os_memset(&params, 0, sizeof(params));
849 params.ssid = ssid->ssid;
850 params.ssid_len = ssid->ssid_len;
851 switch (ssid->mode) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700852 case WPAS_MODE_AP:
853 case WPAS_MODE_P2P_GO:
854 case WPAS_MODE_P2P_GROUP_FORMATION:
855 params.mode = IEEE80211_MODE_AP;
856 break;
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800857 default:
858 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700859 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700860 if (ssid->frequency == 0)
861 ssid->frequency = 2462; /* default channel 11 */
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700862 params.freq.freq = ssid->frequency;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700863
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800864 if ((ssid->mode == WPAS_MODE_AP || ssid->mode == WPAS_MODE_P2P_GO) &&
865 ssid->enable_edmg) {
Hai Shalomc3565922019-10-28 11:58:20 -0700866 u8 primary_channel;
867
868 if (ieee80211_freq_to_chan(ssid->frequency, &primary_channel) ==
869 NUM_HOSTAPD_MODES) {
870 wpa_printf(MSG_WARNING,
871 "EDMG: Failed to get the primary channel");
872 return -1;
873 }
874
875 hostapd_encode_edmg_chan(ssid->enable_edmg, ssid->edmg_channel,
876 primary_channel, &params.freq.edmg);
877 }
878
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800879 params.wpa_proto = ssid->proto;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700880 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
881 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
882 else
883 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800884 params.key_mgmt_suite = wpa_s->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700885
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800886 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
887 1);
888 if (wpa_s->pairwise_cipher < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700889 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
890 "cipher.");
891 return -1;
892 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800893 params.pairwise_suite = wpa_s->pairwise_cipher;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700894 params.group_suite = params.pairwise_suite;
895
896#ifdef CONFIG_P2P
897 if (ssid->mode == WPAS_MODE_P2P_GO ||
898 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
899 params.p2p = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700900#endif /* CONFIG_P2P */
901
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800902 if (wpa_s->p2pdev->set_ap_uapsd)
903 params.uapsd = wpa_s->p2pdev->ap_uapsd;
Dmitry Shmidtec58b162014-02-19 12:44:18 -0800904 else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
905 params.uapsd = 1; /* mandatory for P2P GO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700906 else
907 params.uapsd = -1;
908
Roshan Pius3a1667e2018-07-03 15:17:14 -0700909 if (ieee80211_is_dfs(params.freq.freq, wpa_s->hw.modes,
910 wpa_s->hw.num_modes))
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800911 params.freq.freq = 0; /* set channel after CAC */
912
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700913 if (params.p2p)
914 wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_GO);
915 else
916 wpa_drv_get_ext_capa(wpa_s, WPA_IF_AP_BSS);
917
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700918 if (wpa_drv_associate(wpa_s, &params) < 0) {
919 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
920 return -1;
921 }
922
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700923 wpa_s->ap_iface = hapd_iface = hostapd_alloc_iface();
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700924 if (hapd_iface == NULL)
925 return -1;
926 hapd_iface->owner = wpa_s;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800927 hapd_iface->drv_flags = wpa_s->drv_flags;
928 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700929 hapd_iface->extended_capa = wpa_s->extended_capa;
930 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
931 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700932
933 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
934 if (conf == NULL) {
935 wpa_supplicant_ap_deinit(wpa_s);
936 return -1;
937 }
938
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700939 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
940 wpa_s->conf->wmm_ac_params,
941 sizeof(wpa_s->conf->wmm_ac_params));
942
Hai Shalom899fcc72020-10-19 14:38:18 -0700943 os_memcpy(wpa_s->ap_iface->conf->tx_queue, wpa_s->conf->tx_queue,
944 sizeof(wpa_s->conf->tx_queue));
945
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800946 if (params.uapsd > 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800947 conf->bss[0]->wmm_enabled = 1;
948 conf->bss[0]->wmm_uapsd = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800949 }
950
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700951 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
952 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
953 wpa_supplicant_ap_deinit(wpa_s);
954 return -1;
955 }
956
957#ifdef CONFIG_P2P
958 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800959 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700960 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800961 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700962 P2P_GROUP_FORMATION;
963#endif /* CONFIG_P2P */
964
965 hapd_iface->num_bss = conf->num_bss;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700966 hapd_iface->bss = os_calloc(conf->num_bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700967 sizeof(struct hostapd_data *));
968 if (hapd_iface->bss == NULL) {
969 wpa_supplicant_ap_deinit(wpa_s);
970 return -1;
971 }
972
973 for (i = 0; i < conf->num_bss; i++) {
974 hapd_iface->bss[i] =
975 hostapd_alloc_bss_data(hapd_iface, conf,
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800976 conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700977 if (hapd_iface->bss[i] == NULL) {
978 wpa_supplicant_ap_deinit(wpa_s);
979 return -1;
980 }
981
982 hapd_iface->bss[i]->msg_ctx = wpa_s;
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800983 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->p2pdev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700984 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
985 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
986 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
987 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
988 hostapd_register_probereq_cb(hapd_iface->bss[i],
989 ap_probe_req_rx, wpa_s);
990 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
991 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
992 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
993 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
994 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
995 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
996#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700997 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
998 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700999 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001000 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
1001 ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001002#endif /* CONFIG_P2P */
1003 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
1004 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001005#ifdef CONFIG_TESTING_OPTIONS
1006 hapd_iface->bss[i]->ext_eapol_frame_io =
1007 wpa_s->ext_eapol_frame_io;
1008#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001009 }
1010
1011 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
1012 hapd_iface->bss[0]->driver = wpa_s->driver;
1013 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
1014
1015 wpa_s->current_ssid = ssid;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001016 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001017 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
1018 wpa_s->assoc_freq = ssid->frequency;
Hai Shalomc3565922019-10-28 11:58:20 -07001019 wpa_s->ap_iface->conf->enable_edmg = ssid->enable_edmg;
1020 wpa_s->ap_iface->conf->edmg_channel = ssid->edmg_channel;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001021
Roshan Pius3a1667e2018-07-03 15:17:14 -07001022#if defined(CONFIG_P2P) && defined(CONFIG_ACS)
1023 if (wpa_s->p2p_go_do_acs) {
1024 wpa_s->ap_iface->conf->channel = 0;
1025 wpa_s->ap_iface->conf->hw_mode = wpa_s->p2p_go_acs_band;
1026 ssid->acs = 1;
1027 }
1028#endif /* CONFIG_P2P && CONFIG_ACS */
1029
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001030 if (hostapd_setup_interface(wpa_s->ap_iface)) {
1031 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
1032 wpa_supplicant_ap_deinit(wpa_s);
1033 return -1;
1034 }
1035
1036 return 0;
1037}
1038
1039
1040void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
1041{
1042#ifdef CONFIG_WPS
1043 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1044#endif /* CONFIG_WPS */
1045
1046 if (wpa_s->ap_iface == NULL)
1047 return;
1048
1049 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001050 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001051 wpa_s->assoc_freq = 0;
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07001052 wpas_p2p_ap_deinit(wpa_s);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001053 wpa_s->ap_iface->driver_ap_teardown =
1054 !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
1055
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001056 hostapd_interface_deinit(wpa_s->ap_iface);
1057 hostapd_interface_free(wpa_s->ap_iface);
1058 wpa_s->ap_iface = NULL;
1059 wpa_drv_deinit_ap(wpa_s);
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07001060 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1061 " reason=%d locally_generated=1",
1062 MAC2STR(wpa_s->own_addr), WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001063}
1064
1065
1066void ap_tx_status(void *ctx, const u8 *addr,
1067 const u8 *buf, size_t len, int ack)
1068{
1069#ifdef NEED_AP_MLME
1070 struct wpa_supplicant *wpa_s = ctx;
1071 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
1072#endif /* NEED_AP_MLME */
1073}
1074
1075
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001076void ap_eapol_tx_status(void *ctx, const u8 *dst,
1077 const u8 *data, size_t len, int ack)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001078{
1079#ifdef NEED_AP_MLME
1080 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001081 if (!wpa_s->ap_iface)
1082 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001083 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
1084#endif /* NEED_AP_MLME */
1085}
1086
1087
1088void ap_client_poll_ok(void *ctx, const u8 *addr)
1089{
1090#ifdef NEED_AP_MLME
1091 struct wpa_supplicant *wpa_s = ctx;
1092 if (wpa_s->ap_iface)
1093 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
1094#endif /* NEED_AP_MLME */
1095}
1096
1097
1098void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
1099{
1100#ifdef NEED_AP_MLME
1101 struct wpa_supplicant *wpa_s = ctx;
1102 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001103#endif /* NEED_AP_MLME */
1104}
1105
1106
1107void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
1108{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001109#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001110 struct wpa_supplicant *wpa_s = ctx;
1111 struct hostapd_frame_info fi;
1112 os_memset(&fi, 0, sizeof(fi));
1113 fi.datarate = rx_mgmt->datarate;
1114 fi.ssi_signal = rx_mgmt->ssi_signal;
1115 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
1116 rx_mgmt->frame_len, &fi);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001117#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001118}
1119
1120
1121void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
1122{
1123#ifdef NEED_AP_MLME
1124 struct wpa_supplicant *wpa_s = ctx;
1125 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
1126#endif /* NEED_AP_MLME */
1127}
1128
1129
1130void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
1131 const u8 *src_addr, const u8 *buf, size_t len)
1132{
1133 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
1134}
1135
1136
1137#ifdef CONFIG_WPS
1138
1139int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
1140 const u8 *p2p_dev_addr)
1141{
1142 if (!wpa_s->ap_iface)
1143 return -1;
1144 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
1145 p2p_dev_addr);
1146}
1147
1148
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001149int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
1150{
1151 struct wps_registrar *reg;
1152 int reg_sel = 0, wps_sta = 0;
1153
1154 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
1155 return -1;
1156
1157 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
1158 reg_sel = wps_registrar_wps_cancel(reg);
1159 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
Dmitry Shmidt04949592012-07-19 12:16:46 -07001160 ap_sta_wps_cancel, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001161
1162 if (!reg_sel && !wps_sta) {
1163 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
1164 "time");
1165 return -1;
1166 }
1167
1168 /*
1169 * There are 2 cases to return wps cancel as success:
1170 * 1. When wps cancel was initiated but no connection has been
1171 * established with client yet.
1172 * 2. Client is in the middle of exchanging WPS messages.
1173 */
1174
1175 return 0;
1176}
1177
1178
1179int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001180 const char *pin, char *buf, size_t buflen,
1181 int timeout)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001182{
1183 int ret, ret_len = 0;
1184
1185 if (!wpa_s->ap_iface)
1186 return -1;
1187
1188 if (pin == NULL) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001189 unsigned int rpin;
1190
1191 if (wps_generate_pin(&rpin) < 0)
1192 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001193 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001194 if (os_snprintf_error(buflen, ret_len))
1195 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001196 pin = buf;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001197 } else if (buf) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001198 ret_len = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001199 if (os_snprintf_error(buflen, ret_len))
1200 return -1;
1201 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001202
1203 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001204 timeout);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001205 if (ret)
1206 return -1;
1207 return ret_len;
1208}
1209
1210
1211static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
1212{
1213 struct wpa_supplicant *wpa_s = eloop_data;
1214 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
1215 wpas_wps_ap_pin_disable(wpa_s);
1216}
1217
1218
1219static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
1220{
1221 struct hostapd_data *hapd;
1222
1223 if (wpa_s->ap_iface == NULL)
1224 return;
1225 hapd = wpa_s->ap_iface->bss[0];
1226 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
1227 hapd->ap_pin_failures = 0;
1228 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1229 if (timeout > 0)
1230 eloop_register_timeout(timeout, 0,
1231 wpas_wps_ap_pin_timeout, wpa_s, NULL);
1232}
1233
1234
1235void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
1236{
1237 struct hostapd_data *hapd;
1238
1239 if (wpa_s->ap_iface == NULL)
1240 return;
1241 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
1242 hapd = wpa_s->ap_iface->bss[0];
1243 os_free(hapd->conf->ap_pin);
1244 hapd->conf->ap_pin = NULL;
1245 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1246}
1247
1248
1249const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
1250{
1251 struct hostapd_data *hapd;
1252 unsigned int pin;
1253 char pin_txt[9];
1254
1255 if (wpa_s->ap_iface == NULL)
1256 return NULL;
1257 hapd = wpa_s->ap_iface->bss[0];
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001258 if (wps_generate_pin(&pin) < 0)
1259 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001260 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001261 os_free(hapd->conf->ap_pin);
1262 hapd->conf->ap_pin = os_strdup(pin_txt);
1263 if (hapd->conf->ap_pin == NULL)
1264 return NULL;
1265 wpas_wps_ap_pin_enable(wpa_s, timeout);
1266
1267 return hapd->conf->ap_pin;
1268}
1269
1270
1271const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
1272{
1273 struct hostapd_data *hapd;
1274 if (wpa_s->ap_iface == NULL)
1275 return NULL;
1276 hapd = wpa_s->ap_iface->bss[0];
1277 return hapd->conf->ap_pin;
1278}
1279
1280
1281int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
1282 int timeout)
1283{
1284 struct hostapd_data *hapd;
1285 char pin_txt[9];
1286 int ret;
1287
1288 if (wpa_s->ap_iface == NULL)
1289 return -1;
1290 hapd = wpa_s->ap_iface->bss[0];
1291 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001292 if (os_snprintf_error(sizeof(pin_txt), ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001293 return -1;
1294 os_free(hapd->conf->ap_pin);
1295 hapd->conf->ap_pin = os_strdup(pin_txt);
1296 if (hapd->conf->ap_pin == NULL)
1297 return -1;
1298 wpas_wps_ap_pin_enable(wpa_s, timeout);
1299
1300 return 0;
1301}
1302
1303
1304void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
1305{
1306 struct hostapd_data *hapd;
1307
1308 if (wpa_s->ap_iface == NULL)
1309 return;
1310 hapd = wpa_s->ap_iface->bss[0];
1311
1312 /*
1313 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
1314 * PIN if this happens multiple times to slow down brute force attacks.
1315 */
1316 hapd->ap_pin_failures++;
1317 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
1318 hapd->ap_pin_failures);
1319 if (hapd->ap_pin_failures < 3)
1320 return;
1321
1322 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
1323 hapd->ap_pin_failures = 0;
1324 os_free(hapd->conf->ap_pin);
1325 hapd->conf->ap_pin = NULL;
1326}
1327
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001328
1329#ifdef CONFIG_WPS_NFC
1330
1331struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
1332 int ndef)
1333{
1334 struct hostapd_data *hapd;
1335
1336 if (wpa_s->ap_iface == NULL)
1337 return NULL;
1338 hapd = wpa_s->ap_iface->bss[0];
1339 return hostapd_wps_nfc_config_token(hapd, ndef);
1340}
1341
1342
1343struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
1344 int ndef)
1345{
1346 struct hostapd_data *hapd;
1347
1348 if (wpa_s->ap_iface == NULL)
1349 return NULL;
1350 hapd = wpa_s->ap_iface->bss[0];
1351 return hostapd_wps_nfc_hs_cr(hapd, ndef);
1352}
1353
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001354
1355int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
1356 const struct wpabuf *req,
1357 const struct wpabuf *sel)
1358{
1359 struct hostapd_data *hapd;
1360
1361 if (wpa_s->ap_iface == NULL)
1362 return -1;
1363 hapd = wpa_s->ap_iface->bss[0];
1364 return hostapd_wps_nfc_report_handover(hapd, req, sel);
1365}
1366
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001367#endif /* CONFIG_WPS_NFC */
1368
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001369#endif /* CONFIG_WPS */
1370
1371
1372#ifdef CONFIG_CTRL_IFACE
1373
1374int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
1375 char *buf, size_t buflen)
1376{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001377 struct hostapd_data *hapd;
1378
1379 if (wpa_s->ap_iface)
1380 hapd = wpa_s->ap_iface->bss[0];
1381 else if (wpa_s->ifmsh)
1382 hapd = wpa_s->ifmsh->bss[0];
1383 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001384 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001385 return hostapd_ctrl_iface_sta_first(hapd, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001386}
1387
1388
1389int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
1390 char *buf, size_t buflen)
1391{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001392 struct hostapd_data *hapd;
1393
1394 if (wpa_s->ap_iface)
1395 hapd = wpa_s->ap_iface->bss[0];
1396 else if (wpa_s->ifmsh)
1397 hapd = wpa_s->ifmsh->bss[0];
1398 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001399 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001400 return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001401}
1402
1403
1404int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
1405 char *buf, size_t buflen)
1406{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001407 struct hostapd_data *hapd;
1408
1409 if (wpa_s->ap_iface)
1410 hapd = wpa_s->ap_iface->bss[0];
1411 else if (wpa_s->ifmsh)
1412 hapd = wpa_s->ifmsh->bss[0];
1413 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001414 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001415 return hostapd_ctrl_iface_sta_next(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001416}
1417
1418
Dmitry Shmidt04949592012-07-19 12:16:46 -07001419int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1420 const char *txtaddr)
1421{
1422 if (wpa_s->ap_iface == NULL)
1423 return -1;
1424 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1425 txtaddr);
1426}
1427
1428
1429int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1430 const char *txtaddr)
1431{
1432 if (wpa_s->ap_iface == NULL)
1433 return -1;
1434 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1435 txtaddr);
1436}
1437
1438
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001439int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1440 size_t buflen, int verbose)
1441{
1442 char *pos = buf, *end = buf + buflen;
1443 int ret;
1444 struct hostapd_bss_config *conf;
1445
1446 if (wpa_s->ap_iface == NULL)
1447 return -1;
1448
1449 conf = wpa_s->ap_iface->bss[0]->conf;
1450 if (conf->wpa == 0)
1451 return 0;
1452
1453 ret = os_snprintf(pos, end - pos,
1454 "pairwise_cipher=%s\n"
1455 "group_cipher=%s\n"
1456 "key_mgmt=%s\n",
1457 wpa_cipher_txt(conf->rsn_pairwise),
1458 wpa_cipher_txt(conf->wpa_group),
1459 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1460 conf->wpa));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001461 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001462 return pos - buf;
1463 pos += ret;
1464 return pos - buf;
1465}
1466
1467#endif /* CONFIG_CTRL_IFACE */
1468
1469
1470int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1471{
1472 struct hostapd_iface *iface = wpa_s->ap_iface;
1473 struct wpa_ssid *ssid = wpa_s->current_ssid;
1474 struct hostapd_data *hapd;
1475
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001476 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1477 ssid->mode == WPAS_MODE_INFRA ||
1478 ssid->mode == WPAS_MODE_IBSS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001479 return -1;
1480
1481#ifdef CONFIG_P2P
1482 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001483 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001484 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001485 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001486 P2P_GROUP_FORMATION;
1487#endif /* CONFIG_P2P */
1488
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001489 hapd = iface->bss[0];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001490 if (hapd->drv_priv == NULL)
1491 return -1;
1492 ieee802_11_set_beacons(iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001493 hostapd_set_ap_wps_ie(hapd);
1494
1495 return 0;
1496}
1497
1498
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001499int ap_switch_channel(struct wpa_supplicant *wpa_s,
1500 struct csa_settings *settings)
1501{
1502#ifdef NEED_AP_MLME
Hai Shalom899fcc72020-10-19 14:38:18 -07001503 struct hostapd_iface *iface = NULL;
1504
1505 if (wpa_s->ap_iface)
1506 iface = wpa_s->ap_iface;
1507 else if (wpa_s->ifmsh)
1508 iface = wpa_s->ifmsh;
1509
1510 if (!iface || !iface->bss[0])
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001511 return -1;
1512
Hai Shalom899fcc72020-10-19 14:38:18 -07001513 return hostapd_switch_channel(iface->bss[0], settings);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001514#else /* NEED_AP_MLME */
1515 return -1;
1516#endif /* NEED_AP_MLME */
1517}
1518
1519
Dmitry Shmidt83474442015-04-15 13:47:09 -07001520#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001521int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1522{
1523 struct csa_settings settings;
1524 int ret = hostapd_parse_csa_settings(pos, &settings);
1525
1526 if (ret)
1527 return ret;
1528
1529 return ap_switch_channel(wpa_s, &settings);
1530}
Dmitry Shmidt83474442015-04-15 13:47:09 -07001531#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001532
1533
Dmitry Shmidt04949592012-07-19 12:16:46 -07001534void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
Hai Shalom81f62d82019-07-22 12:10:00 -07001535 int offset, int width, int cf1, int cf2, int finished)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001536{
Hai Shalom74f70d42019-02-11 14:42:39 -08001537 struct hostapd_iface *iface = wpa_s->ap_iface;
Hai Shalombf6e0ba2019-02-11 12:01:50 -08001538
Hai Shalom74f70d42019-02-11 14:42:39 -08001539 if (!iface)
1540 iface = wpa_s->ifmsh;
1541 if (!iface)
1542 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001543 wpa_s->assoc_freq = freq;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001544 if (wpa_s->current_ssid)
1545 wpa_s->current_ssid->frequency = freq;
Hai Shalom74f70d42019-02-11 14:42:39 -08001546 hostapd_event_ch_switch(iface->bss[0], freq, ht,
Hai Shalom81f62d82019-07-22 12:10:00 -07001547 offset, width, cf1, cf2, finished);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001548}
1549
1550
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001551int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1552 const u8 *addr)
1553{
1554 struct hostapd_data *hapd;
1555 struct hostapd_bss_config *conf;
1556
1557 if (!wpa_s->ap_iface)
1558 return -1;
1559
1560 if (addr)
1561 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1562 MAC2STR(addr));
1563 else
1564 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1565
1566 hapd = wpa_s->ap_iface->bss[0];
1567 conf = hapd->conf;
1568
1569 os_free(conf->accept_mac);
1570 conf->accept_mac = NULL;
1571 conf->num_accept_mac = 0;
1572 os_free(conf->deny_mac);
1573 conf->deny_mac = NULL;
1574 conf->num_deny_mac = 0;
1575
1576 if (addr == NULL) {
1577 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1578 return 0;
1579 }
1580
1581 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1582 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1583 if (conf->accept_mac == NULL)
1584 return -1;
1585 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1586 conf->num_accept_mac = 1;
1587
1588 return 0;
1589}
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001590
1591
1592#ifdef CONFIG_WPS_NFC
1593int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1594 const struct wpabuf *pw, const u8 *pubkey_hash)
1595{
1596 struct hostapd_data *hapd;
1597 struct wps_context *wps;
1598
1599 if (!wpa_s->ap_iface)
1600 return -1;
1601 hapd = wpa_s->ap_iface->bss[0];
1602 wps = hapd->wps;
1603
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001604 if (wpa_s->p2pdev->conf->wps_nfc_dh_pubkey == NULL ||
1605 wpa_s->p2pdev->conf->wps_nfc_dh_privkey == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001606 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1607 return -1;
1608 }
1609
1610 dh5_free(wps->dh_ctx);
1611 wpabuf_free(wps->dh_pubkey);
1612 wpabuf_free(wps->dh_privkey);
1613 wps->dh_privkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001614 wpa_s->p2pdev->conf->wps_nfc_dh_privkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001615 wps->dh_pubkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001616 wpa_s->p2pdev->conf->wps_nfc_dh_pubkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001617 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1618 wps->dh_ctx = NULL;
1619 wpabuf_free(wps->dh_pubkey);
1620 wps->dh_pubkey = NULL;
1621 wpabuf_free(wps->dh_privkey);
1622 wps->dh_privkey = NULL;
1623 return -1;
1624 }
1625 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1626 if (wps->dh_ctx == NULL)
1627 return -1;
1628
1629 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1630 pw_id,
1631 pw ? wpabuf_head(pw) : NULL,
1632 pw ? wpabuf_len(pw) : 0, 1);
1633}
1634#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001635
1636
Dmitry Shmidt83474442015-04-15 13:47:09 -07001637#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001638int wpas_ap_stop_ap(struct wpa_supplicant *wpa_s)
1639{
1640 struct hostapd_data *hapd;
1641
1642 if (!wpa_s->ap_iface)
1643 return -1;
1644 hapd = wpa_s->ap_iface->bss[0];
1645 return hostapd_ctrl_iface_stop_ap(hapd);
1646}
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001647
1648
Dmitry Shmidte4663042016-04-04 10:07:49 -07001649int wpas_ap_pmksa_cache_list(struct wpa_supplicant *wpa_s, char *buf,
1650 size_t len)
1651{
1652 size_t reply_len = 0, i;
1653 char ap_delimiter[] = "---- AP ----\n";
1654 char mesh_delimiter[] = "---- mesh ----\n";
1655 size_t dlen;
1656
1657 if (wpa_s->ap_iface) {
1658 dlen = os_strlen(ap_delimiter);
1659 if (dlen > len - reply_len)
1660 return reply_len;
1661 os_memcpy(&buf[reply_len], ap_delimiter, dlen);
1662 reply_len += dlen;
1663
1664 for (i = 0; i < wpa_s->ap_iface->num_bss; i++) {
1665 reply_len += hostapd_ctrl_iface_pmksa_list(
1666 wpa_s->ap_iface->bss[i],
1667 &buf[reply_len], len - reply_len);
1668 }
1669 }
1670
1671 if (wpa_s->ifmsh) {
1672 dlen = os_strlen(mesh_delimiter);
1673 if (dlen > len - reply_len)
1674 return reply_len;
1675 os_memcpy(&buf[reply_len], mesh_delimiter, dlen);
1676 reply_len += dlen;
1677
1678 reply_len += hostapd_ctrl_iface_pmksa_list(
1679 wpa_s->ifmsh->bss[0], &buf[reply_len],
1680 len - reply_len);
1681 }
1682
1683 return reply_len;
1684}
1685
1686
1687void wpas_ap_pmksa_cache_flush(struct wpa_supplicant *wpa_s)
1688{
1689 size_t i;
1690
1691 if (wpa_s->ap_iface) {
1692 for (i = 0; i < wpa_s->ap_iface->num_bss; i++)
1693 hostapd_ctrl_iface_pmksa_flush(wpa_s->ap_iface->bss[i]);
1694 }
1695
1696 if (wpa_s->ifmsh)
1697 hostapd_ctrl_iface_pmksa_flush(wpa_s->ifmsh->bss[0]);
1698}
Paul Stewart092955c2017-02-06 09:13:09 -08001699
1700
1701#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
1702#ifdef CONFIG_MESH
1703
1704int wpas_ap_pmksa_cache_list_mesh(struct wpa_supplicant *wpa_s, const u8 *addr,
1705 char *buf, size_t len)
1706{
1707 return hostapd_ctrl_iface_pmksa_list_mesh(wpa_s->ifmsh->bss[0], addr,
1708 &buf[0], len);
1709}
1710
1711
1712int wpas_ap_pmksa_cache_add_external(struct wpa_supplicant *wpa_s, char *cmd)
1713{
1714 struct external_pmksa_cache *entry;
1715 void *pmksa_cache;
1716
1717 pmksa_cache = hostapd_ctrl_iface_pmksa_create_entry(wpa_s->own_addr,
1718 cmd);
1719 if (!pmksa_cache)
1720 return -1;
1721
1722 entry = os_zalloc(sizeof(struct external_pmksa_cache));
1723 if (!entry)
1724 return -1;
1725
1726 entry->pmksa_cache = pmksa_cache;
1727
1728 dl_list_add(&wpa_s->mesh_external_pmksa_cache, &entry->list);
1729
1730 return 0;
1731}
1732
1733#endif /* CONFIG_MESH */
1734#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
1735
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001736#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte4663042016-04-04 10:07:49 -07001737
1738
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001739#ifdef NEED_AP_MLME
Roshan Pius3a1667e2018-07-03 15:17:14 -07001740void wpas_ap_event_dfs_radar_detected(struct wpa_supplicant *wpa_s,
1741 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001742{
Hai Shalom74f70d42019-02-11 14:42:39 -08001743 struct hostapd_iface *iface = wpa_s->ap_iface;
1744
1745 if (!iface)
1746 iface = wpa_s->ifmsh;
1747 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001748 return;
1749 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001750 hostapd_dfs_radar_detected(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001751 radar->ht_enabled, radar->chan_offset,
1752 radar->chan_width,
1753 radar->cf1, radar->cf2);
1754}
1755
1756
Roshan Pius3a1667e2018-07-03 15:17:14 -07001757void wpas_ap_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
1758 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001759{
Hai Shalom74f70d42019-02-11 14:42:39 -08001760 struct hostapd_iface *iface = wpa_s->ap_iface;
1761
1762 if (!iface)
1763 iface = wpa_s->ifmsh;
1764 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001765 return;
1766 wpa_printf(MSG_DEBUG, "DFS CAC started on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001767 hostapd_dfs_start_cac(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001768 radar->ht_enabled, radar->chan_offset,
1769 radar->chan_width, radar->cf1, radar->cf2);
1770}
1771
1772
Roshan Pius3a1667e2018-07-03 15:17:14 -07001773void wpas_ap_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
1774 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001775{
Hai Shalom74f70d42019-02-11 14:42:39 -08001776 struct hostapd_iface *iface = wpa_s->ap_iface;
1777
1778 if (!iface)
1779 iface = wpa_s->ifmsh;
1780 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001781 return;
1782 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001783 hostapd_dfs_complete_cac(iface, 1, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001784 radar->ht_enabled, radar->chan_offset,
1785 radar->chan_width, radar->cf1, radar->cf2);
1786}
1787
1788
Roshan Pius3a1667e2018-07-03 15:17:14 -07001789void wpas_ap_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
1790 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001791{
Hai Shalom74f70d42019-02-11 14:42:39 -08001792 struct hostapd_iface *iface = wpa_s->ap_iface;
1793
1794 if (!iface)
1795 iface = wpa_s->ifmsh;
1796 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001797 return;
1798 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001799 hostapd_dfs_complete_cac(iface, 0, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001800 radar->ht_enabled, radar->chan_offset,
1801 radar->chan_width, radar->cf1, radar->cf2);
1802}
1803
1804
Roshan Pius3a1667e2018-07-03 15:17:14 -07001805void wpas_ap_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s,
1806 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001807{
Hai Shalom74f70d42019-02-11 14:42:39 -08001808 struct hostapd_iface *iface = wpa_s->ap_iface;
1809
1810 if (!iface)
1811 iface = wpa_s->ifmsh;
1812 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001813 return;
1814 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001815 hostapd_dfs_nop_finished(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001816 radar->ht_enabled, radar->chan_offset,
1817 radar->chan_width, radar->cf1, radar->cf2);
1818}
1819#endif /* NEED_AP_MLME */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001820
1821
1822void ap_periodic(struct wpa_supplicant *wpa_s)
1823{
1824 if (wpa_s->ap_iface)
1825 hostapd_periodic_iface(wpa_s->ap_iface);
1826}