blob: cfefa48d443e6bed1b875a6784a3120433e758b8 [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
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800810#ifdef CONFIG_ACS
Roshan Pius3a1667e2018-07-03 15:17:14 -0700811 if (wpa_s->current_ssid && wpa_s->current_ssid->acs) {
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800812 wpa_s->assoc_freq = wpa_s->ap_iface->freq;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700813 wpa_s->current_ssid->frequency = wpa_s->ap_iface->freq;
814 }
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800815#endif /* CONFIG_ACS */
816
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700817 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
818
819 if (wpa_s->ap_configured_cb)
820 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
821 wpa_s->ap_configured_cb_data);
822}
823
824
825int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
826 struct wpa_ssid *ssid)
827{
828 struct wpa_driver_associate_params params;
829 struct hostapd_iface *hapd_iface;
830 struct hostapd_config *conf;
831 size_t i;
832
833 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
834 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
835 return -1;
836 }
837
838 wpa_supplicant_ap_deinit(wpa_s);
839
840 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
841 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
842
843 os_memset(&params, 0, sizeof(params));
844 params.ssid = ssid->ssid;
845 params.ssid_len = ssid->ssid_len;
846 switch (ssid->mode) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700847 case WPAS_MODE_AP:
848 case WPAS_MODE_P2P_GO:
849 case WPAS_MODE_P2P_GROUP_FORMATION:
850 params.mode = IEEE80211_MODE_AP;
851 break;
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800852 default:
853 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700854 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700855 if (ssid->frequency == 0)
856 ssid->frequency = 2462; /* default channel 11 */
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700857 params.freq.freq = ssid->frequency;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700858
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800859 if ((ssid->mode == WPAS_MODE_AP || ssid->mode == WPAS_MODE_P2P_GO) &&
860 ssid->enable_edmg) {
Hai Shalomc3565922019-10-28 11:58:20 -0700861 u8 primary_channel;
862
863 if (ieee80211_freq_to_chan(ssid->frequency, &primary_channel) ==
864 NUM_HOSTAPD_MODES) {
865 wpa_printf(MSG_WARNING,
866 "EDMG: Failed to get the primary channel");
867 return -1;
868 }
869
870 hostapd_encode_edmg_chan(ssid->enable_edmg, ssid->edmg_channel,
871 primary_channel, &params.freq.edmg);
872 }
873
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800874 params.wpa_proto = ssid->proto;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700875 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
876 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
877 else
878 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800879 params.key_mgmt_suite = wpa_s->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700880
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800881 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
882 1);
883 if (wpa_s->pairwise_cipher < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700884 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
885 "cipher.");
886 return -1;
887 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800888 params.pairwise_suite = wpa_s->pairwise_cipher;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700889 params.group_suite = params.pairwise_suite;
890
891#ifdef CONFIG_P2P
892 if (ssid->mode == WPAS_MODE_P2P_GO ||
893 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
894 params.p2p = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700895#endif /* CONFIG_P2P */
896
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800897 if (wpa_s->p2pdev->set_ap_uapsd)
898 params.uapsd = wpa_s->p2pdev->ap_uapsd;
Dmitry Shmidtec58b162014-02-19 12:44:18 -0800899 else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
900 params.uapsd = 1; /* mandatory for P2P GO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700901 else
902 params.uapsd = -1;
903
Roshan Pius3a1667e2018-07-03 15:17:14 -0700904 if (ieee80211_is_dfs(params.freq.freq, wpa_s->hw.modes,
905 wpa_s->hw.num_modes))
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800906 params.freq.freq = 0; /* set channel after CAC */
907
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700908 if (params.p2p)
909 wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_GO);
910 else
911 wpa_drv_get_ext_capa(wpa_s, WPA_IF_AP_BSS);
912
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700913 if (wpa_drv_associate(wpa_s, &params) < 0) {
914 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
915 return -1;
916 }
917
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700918 wpa_s->ap_iface = hapd_iface = hostapd_alloc_iface();
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700919 if (hapd_iface == NULL)
920 return -1;
921 hapd_iface->owner = wpa_s;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800922 hapd_iface->drv_flags = wpa_s->drv_flags;
923 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700924 hapd_iface->extended_capa = wpa_s->extended_capa;
925 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
926 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700927
928 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
929 if (conf == NULL) {
930 wpa_supplicant_ap_deinit(wpa_s);
931 return -1;
932 }
933
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700934 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
935 wpa_s->conf->wmm_ac_params,
936 sizeof(wpa_s->conf->wmm_ac_params));
937
Hai Shalom899fcc72020-10-19 14:38:18 -0700938 os_memcpy(wpa_s->ap_iface->conf->tx_queue, wpa_s->conf->tx_queue,
939 sizeof(wpa_s->conf->tx_queue));
940
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800941 if (params.uapsd > 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800942 conf->bss[0]->wmm_enabled = 1;
943 conf->bss[0]->wmm_uapsd = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800944 }
945
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700946 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
947 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
948 wpa_supplicant_ap_deinit(wpa_s);
949 return -1;
950 }
951
952#ifdef CONFIG_P2P
953 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800954 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700955 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800956 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700957 P2P_GROUP_FORMATION;
958#endif /* CONFIG_P2P */
959
960 hapd_iface->num_bss = conf->num_bss;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700961 hapd_iface->bss = os_calloc(conf->num_bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700962 sizeof(struct hostapd_data *));
963 if (hapd_iface->bss == NULL) {
964 wpa_supplicant_ap_deinit(wpa_s);
965 return -1;
966 }
967
968 for (i = 0; i < conf->num_bss; i++) {
969 hapd_iface->bss[i] =
970 hostapd_alloc_bss_data(hapd_iface, conf,
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800971 conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700972 if (hapd_iface->bss[i] == NULL) {
973 wpa_supplicant_ap_deinit(wpa_s);
974 return -1;
975 }
976
977 hapd_iface->bss[i]->msg_ctx = wpa_s;
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800978 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->p2pdev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700979 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
980 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
981 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
982 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
983 hostapd_register_probereq_cb(hapd_iface->bss[i],
984 ap_probe_req_rx, wpa_s);
985 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
986 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
987 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
988 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
989 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
990 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
991#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700992 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
993 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700994 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700995 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
996 ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700997#endif /* CONFIG_P2P */
998 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
999 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001000#ifdef CONFIG_TESTING_OPTIONS
1001 hapd_iface->bss[i]->ext_eapol_frame_io =
1002 wpa_s->ext_eapol_frame_io;
1003#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001004 }
1005
1006 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
1007 hapd_iface->bss[0]->driver = wpa_s->driver;
1008 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
1009
1010 wpa_s->current_ssid = ssid;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001011 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001012 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
1013 wpa_s->assoc_freq = ssid->frequency;
Hai Shalomc3565922019-10-28 11:58:20 -07001014 wpa_s->ap_iface->conf->enable_edmg = ssid->enable_edmg;
1015 wpa_s->ap_iface->conf->edmg_channel = ssid->edmg_channel;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001016
Roshan Pius3a1667e2018-07-03 15:17:14 -07001017#if defined(CONFIG_P2P) && defined(CONFIG_ACS)
1018 if (wpa_s->p2p_go_do_acs) {
1019 wpa_s->ap_iface->conf->channel = 0;
1020 wpa_s->ap_iface->conf->hw_mode = wpa_s->p2p_go_acs_band;
1021 ssid->acs = 1;
1022 }
1023#endif /* CONFIG_P2P && CONFIG_ACS */
1024
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001025 if (hostapd_setup_interface(wpa_s->ap_iface)) {
1026 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
1027 wpa_supplicant_ap_deinit(wpa_s);
1028 return -1;
1029 }
1030
1031 return 0;
1032}
1033
1034
1035void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
1036{
1037#ifdef CONFIG_WPS
1038 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1039#endif /* CONFIG_WPS */
1040
1041 if (wpa_s->ap_iface == NULL)
1042 return;
1043
1044 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001045 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001046 wpa_s->assoc_freq = 0;
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07001047 wpas_p2p_ap_deinit(wpa_s);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001048 wpa_s->ap_iface->driver_ap_teardown =
1049 !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
1050
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001051 hostapd_interface_deinit(wpa_s->ap_iface);
1052 hostapd_interface_free(wpa_s->ap_iface);
1053 wpa_s->ap_iface = NULL;
1054 wpa_drv_deinit_ap(wpa_s);
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07001055 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1056 " reason=%d locally_generated=1",
1057 MAC2STR(wpa_s->own_addr), WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001058}
1059
1060
1061void ap_tx_status(void *ctx, const u8 *addr,
1062 const u8 *buf, size_t len, int ack)
1063{
1064#ifdef NEED_AP_MLME
1065 struct wpa_supplicant *wpa_s = ctx;
1066 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
1067#endif /* NEED_AP_MLME */
1068}
1069
1070
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001071void ap_eapol_tx_status(void *ctx, const u8 *dst,
1072 const u8 *data, size_t len, int ack)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001073{
1074#ifdef NEED_AP_MLME
1075 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001076 if (!wpa_s->ap_iface)
1077 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001078 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
1079#endif /* NEED_AP_MLME */
1080}
1081
1082
1083void ap_client_poll_ok(void *ctx, const u8 *addr)
1084{
1085#ifdef NEED_AP_MLME
1086 struct wpa_supplicant *wpa_s = ctx;
1087 if (wpa_s->ap_iface)
1088 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
1089#endif /* NEED_AP_MLME */
1090}
1091
1092
1093void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
1094{
1095#ifdef NEED_AP_MLME
1096 struct wpa_supplicant *wpa_s = ctx;
1097 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001098#endif /* NEED_AP_MLME */
1099}
1100
1101
1102void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
1103{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001104#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001105 struct wpa_supplicant *wpa_s = ctx;
1106 struct hostapd_frame_info fi;
1107 os_memset(&fi, 0, sizeof(fi));
1108 fi.datarate = rx_mgmt->datarate;
1109 fi.ssi_signal = rx_mgmt->ssi_signal;
1110 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
1111 rx_mgmt->frame_len, &fi);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001112#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001113}
1114
1115
1116void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
1117{
1118#ifdef NEED_AP_MLME
1119 struct wpa_supplicant *wpa_s = ctx;
1120 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
1121#endif /* NEED_AP_MLME */
1122}
1123
1124
1125void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
1126 const u8 *src_addr, const u8 *buf, size_t len)
1127{
1128 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
1129}
1130
1131
1132#ifdef CONFIG_WPS
1133
1134int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
1135 const u8 *p2p_dev_addr)
1136{
1137 if (!wpa_s->ap_iface)
1138 return -1;
1139 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
1140 p2p_dev_addr);
1141}
1142
1143
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001144int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
1145{
1146 struct wps_registrar *reg;
1147 int reg_sel = 0, wps_sta = 0;
1148
1149 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
1150 return -1;
1151
1152 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
1153 reg_sel = wps_registrar_wps_cancel(reg);
1154 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
Dmitry Shmidt04949592012-07-19 12:16:46 -07001155 ap_sta_wps_cancel, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001156
1157 if (!reg_sel && !wps_sta) {
1158 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
1159 "time");
1160 return -1;
1161 }
1162
1163 /*
1164 * There are 2 cases to return wps cancel as success:
1165 * 1. When wps cancel was initiated but no connection has been
1166 * established with client yet.
1167 * 2. Client is in the middle of exchanging WPS messages.
1168 */
1169
1170 return 0;
1171}
1172
1173
1174int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001175 const char *pin, char *buf, size_t buflen,
1176 int timeout)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001177{
1178 int ret, ret_len = 0;
1179
1180 if (!wpa_s->ap_iface)
1181 return -1;
1182
1183 if (pin == NULL) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001184 unsigned int rpin;
1185
1186 if (wps_generate_pin(&rpin) < 0)
1187 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001188 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001189 if (os_snprintf_error(buflen, ret_len))
1190 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001191 pin = buf;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001192 } else if (buf) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001193 ret_len = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001194 if (os_snprintf_error(buflen, ret_len))
1195 return -1;
1196 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001197
1198 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001199 timeout);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001200 if (ret)
1201 return -1;
1202 return ret_len;
1203}
1204
1205
1206static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
1207{
1208 struct wpa_supplicant *wpa_s = eloop_data;
1209 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
1210 wpas_wps_ap_pin_disable(wpa_s);
1211}
1212
1213
1214static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
1215{
1216 struct hostapd_data *hapd;
1217
1218 if (wpa_s->ap_iface == NULL)
1219 return;
1220 hapd = wpa_s->ap_iface->bss[0];
1221 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
1222 hapd->ap_pin_failures = 0;
1223 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1224 if (timeout > 0)
1225 eloop_register_timeout(timeout, 0,
1226 wpas_wps_ap_pin_timeout, wpa_s, NULL);
1227}
1228
1229
1230void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
1231{
1232 struct hostapd_data *hapd;
1233
1234 if (wpa_s->ap_iface == NULL)
1235 return;
1236 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
1237 hapd = wpa_s->ap_iface->bss[0];
1238 os_free(hapd->conf->ap_pin);
1239 hapd->conf->ap_pin = NULL;
1240 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1241}
1242
1243
1244const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
1245{
1246 struct hostapd_data *hapd;
1247 unsigned int pin;
1248 char pin_txt[9];
1249
1250 if (wpa_s->ap_iface == NULL)
1251 return NULL;
1252 hapd = wpa_s->ap_iface->bss[0];
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001253 if (wps_generate_pin(&pin) < 0)
1254 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001255 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001256 os_free(hapd->conf->ap_pin);
1257 hapd->conf->ap_pin = os_strdup(pin_txt);
1258 if (hapd->conf->ap_pin == NULL)
1259 return NULL;
1260 wpas_wps_ap_pin_enable(wpa_s, timeout);
1261
1262 return hapd->conf->ap_pin;
1263}
1264
1265
1266const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
1267{
1268 struct hostapd_data *hapd;
1269 if (wpa_s->ap_iface == NULL)
1270 return NULL;
1271 hapd = wpa_s->ap_iface->bss[0];
1272 return hapd->conf->ap_pin;
1273}
1274
1275
1276int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
1277 int timeout)
1278{
1279 struct hostapd_data *hapd;
1280 char pin_txt[9];
1281 int ret;
1282
1283 if (wpa_s->ap_iface == NULL)
1284 return -1;
1285 hapd = wpa_s->ap_iface->bss[0];
1286 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001287 if (os_snprintf_error(sizeof(pin_txt), ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001288 return -1;
1289 os_free(hapd->conf->ap_pin);
1290 hapd->conf->ap_pin = os_strdup(pin_txt);
1291 if (hapd->conf->ap_pin == NULL)
1292 return -1;
1293 wpas_wps_ap_pin_enable(wpa_s, timeout);
1294
1295 return 0;
1296}
1297
1298
1299void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
1300{
1301 struct hostapd_data *hapd;
1302
1303 if (wpa_s->ap_iface == NULL)
1304 return;
1305 hapd = wpa_s->ap_iface->bss[0];
1306
1307 /*
1308 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
1309 * PIN if this happens multiple times to slow down brute force attacks.
1310 */
1311 hapd->ap_pin_failures++;
1312 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
1313 hapd->ap_pin_failures);
1314 if (hapd->ap_pin_failures < 3)
1315 return;
1316
1317 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
1318 hapd->ap_pin_failures = 0;
1319 os_free(hapd->conf->ap_pin);
1320 hapd->conf->ap_pin = NULL;
1321}
1322
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001323
1324#ifdef CONFIG_WPS_NFC
1325
1326struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
1327 int ndef)
1328{
1329 struct hostapd_data *hapd;
1330
1331 if (wpa_s->ap_iface == NULL)
1332 return NULL;
1333 hapd = wpa_s->ap_iface->bss[0];
1334 return hostapd_wps_nfc_config_token(hapd, ndef);
1335}
1336
1337
1338struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
1339 int ndef)
1340{
1341 struct hostapd_data *hapd;
1342
1343 if (wpa_s->ap_iface == NULL)
1344 return NULL;
1345 hapd = wpa_s->ap_iface->bss[0];
1346 return hostapd_wps_nfc_hs_cr(hapd, ndef);
1347}
1348
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001349
1350int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
1351 const struct wpabuf *req,
1352 const struct wpabuf *sel)
1353{
1354 struct hostapd_data *hapd;
1355
1356 if (wpa_s->ap_iface == NULL)
1357 return -1;
1358 hapd = wpa_s->ap_iface->bss[0];
1359 return hostapd_wps_nfc_report_handover(hapd, req, sel);
1360}
1361
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001362#endif /* CONFIG_WPS_NFC */
1363
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001364#endif /* CONFIG_WPS */
1365
1366
1367#ifdef CONFIG_CTRL_IFACE
1368
1369int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
1370 char *buf, size_t buflen)
1371{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001372 struct hostapd_data *hapd;
1373
1374 if (wpa_s->ap_iface)
1375 hapd = wpa_s->ap_iface->bss[0];
1376 else if (wpa_s->ifmsh)
1377 hapd = wpa_s->ifmsh->bss[0];
1378 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001379 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001380 return hostapd_ctrl_iface_sta_first(hapd, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001381}
1382
1383
1384int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
1385 char *buf, size_t buflen)
1386{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001387 struct hostapd_data *hapd;
1388
1389 if (wpa_s->ap_iface)
1390 hapd = wpa_s->ap_iface->bss[0];
1391 else if (wpa_s->ifmsh)
1392 hapd = wpa_s->ifmsh->bss[0];
1393 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001394 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001395 return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001396}
1397
1398
1399int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
1400 char *buf, size_t buflen)
1401{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001402 struct hostapd_data *hapd;
1403
1404 if (wpa_s->ap_iface)
1405 hapd = wpa_s->ap_iface->bss[0];
1406 else if (wpa_s->ifmsh)
1407 hapd = wpa_s->ifmsh->bss[0];
1408 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001409 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001410 return hostapd_ctrl_iface_sta_next(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001411}
1412
1413
Dmitry Shmidt04949592012-07-19 12:16:46 -07001414int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1415 const char *txtaddr)
1416{
1417 if (wpa_s->ap_iface == NULL)
1418 return -1;
1419 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1420 txtaddr);
1421}
1422
1423
1424int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1425 const char *txtaddr)
1426{
1427 if (wpa_s->ap_iface == NULL)
1428 return -1;
1429 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1430 txtaddr);
1431}
1432
1433
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001434int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1435 size_t buflen, int verbose)
1436{
1437 char *pos = buf, *end = buf + buflen;
1438 int ret;
1439 struct hostapd_bss_config *conf;
1440
1441 if (wpa_s->ap_iface == NULL)
1442 return -1;
1443
1444 conf = wpa_s->ap_iface->bss[0]->conf;
1445 if (conf->wpa == 0)
1446 return 0;
1447
1448 ret = os_snprintf(pos, end - pos,
1449 "pairwise_cipher=%s\n"
1450 "group_cipher=%s\n"
1451 "key_mgmt=%s\n",
1452 wpa_cipher_txt(conf->rsn_pairwise),
1453 wpa_cipher_txt(conf->wpa_group),
1454 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1455 conf->wpa));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001456 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001457 return pos - buf;
1458 pos += ret;
1459 return pos - buf;
1460}
1461
1462#endif /* CONFIG_CTRL_IFACE */
1463
1464
1465int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1466{
1467 struct hostapd_iface *iface = wpa_s->ap_iface;
1468 struct wpa_ssid *ssid = wpa_s->current_ssid;
1469 struct hostapd_data *hapd;
1470
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001471 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1472 ssid->mode == WPAS_MODE_INFRA ||
1473 ssid->mode == WPAS_MODE_IBSS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001474 return -1;
1475
1476#ifdef CONFIG_P2P
1477 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001478 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001479 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001480 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001481 P2P_GROUP_FORMATION;
1482#endif /* CONFIG_P2P */
1483
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001484 hapd = iface->bss[0];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001485 if (hapd->drv_priv == NULL)
1486 return -1;
1487 ieee802_11_set_beacons(iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001488 hostapd_set_ap_wps_ie(hapd);
1489
1490 return 0;
1491}
1492
1493
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001494int ap_switch_channel(struct wpa_supplicant *wpa_s,
1495 struct csa_settings *settings)
1496{
1497#ifdef NEED_AP_MLME
Hai Shalom899fcc72020-10-19 14:38:18 -07001498 struct hostapd_iface *iface = NULL;
1499
1500 if (wpa_s->ap_iface)
1501 iface = wpa_s->ap_iface;
1502 else if (wpa_s->ifmsh)
1503 iface = wpa_s->ifmsh;
1504
1505 if (!iface || !iface->bss[0])
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001506 return -1;
1507
Hai Shalom899fcc72020-10-19 14:38:18 -07001508 return hostapd_switch_channel(iface->bss[0], settings);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001509#else /* NEED_AP_MLME */
1510 return -1;
1511#endif /* NEED_AP_MLME */
1512}
1513
1514
Dmitry Shmidt83474442015-04-15 13:47:09 -07001515#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001516int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1517{
1518 struct csa_settings settings;
1519 int ret = hostapd_parse_csa_settings(pos, &settings);
1520
1521 if (ret)
1522 return ret;
1523
1524 return ap_switch_channel(wpa_s, &settings);
1525}
Dmitry Shmidt83474442015-04-15 13:47:09 -07001526#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001527
1528
Dmitry Shmidt04949592012-07-19 12:16:46 -07001529void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
Hai Shalom81f62d82019-07-22 12:10:00 -07001530 int offset, int width, int cf1, int cf2, int finished)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001531{
Hai Shalom74f70d42019-02-11 14:42:39 -08001532 struct hostapd_iface *iface = wpa_s->ap_iface;
Hai Shalombf6e0ba2019-02-11 12:01:50 -08001533
Hai Shalom74f70d42019-02-11 14:42:39 -08001534 if (!iface)
1535 iface = wpa_s->ifmsh;
1536 if (!iface)
1537 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001538 wpa_s->assoc_freq = freq;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001539 if (wpa_s->current_ssid)
1540 wpa_s->current_ssid->frequency = freq;
Hai Shalom74f70d42019-02-11 14:42:39 -08001541 hostapd_event_ch_switch(iface->bss[0], freq, ht,
Hai Shalom81f62d82019-07-22 12:10:00 -07001542 offset, width, cf1, cf2, finished);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001543}
1544
1545
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001546int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1547 const u8 *addr)
1548{
1549 struct hostapd_data *hapd;
1550 struct hostapd_bss_config *conf;
1551
1552 if (!wpa_s->ap_iface)
1553 return -1;
1554
1555 if (addr)
1556 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1557 MAC2STR(addr));
1558 else
1559 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1560
1561 hapd = wpa_s->ap_iface->bss[0];
1562 conf = hapd->conf;
1563
1564 os_free(conf->accept_mac);
1565 conf->accept_mac = NULL;
1566 conf->num_accept_mac = 0;
1567 os_free(conf->deny_mac);
1568 conf->deny_mac = NULL;
1569 conf->num_deny_mac = 0;
1570
1571 if (addr == NULL) {
1572 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1573 return 0;
1574 }
1575
1576 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1577 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1578 if (conf->accept_mac == NULL)
1579 return -1;
1580 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1581 conf->num_accept_mac = 1;
1582
1583 return 0;
1584}
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001585
1586
1587#ifdef CONFIG_WPS_NFC
1588int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1589 const struct wpabuf *pw, const u8 *pubkey_hash)
1590{
1591 struct hostapd_data *hapd;
1592 struct wps_context *wps;
1593
1594 if (!wpa_s->ap_iface)
1595 return -1;
1596 hapd = wpa_s->ap_iface->bss[0];
1597 wps = hapd->wps;
1598
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001599 if (wpa_s->p2pdev->conf->wps_nfc_dh_pubkey == NULL ||
1600 wpa_s->p2pdev->conf->wps_nfc_dh_privkey == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001601 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1602 return -1;
1603 }
1604
1605 dh5_free(wps->dh_ctx);
1606 wpabuf_free(wps->dh_pubkey);
1607 wpabuf_free(wps->dh_privkey);
1608 wps->dh_privkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001609 wpa_s->p2pdev->conf->wps_nfc_dh_privkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001610 wps->dh_pubkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001611 wpa_s->p2pdev->conf->wps_nfc_dh_pubkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001612 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1613 wps->dh_ctx = NULL;
1614 wpabuf_free(wps->dh_pubkey);
1615 wps->dh_pubkey = NULL;
1616 wpabuf_free(wps->dh_privkey);
1617 wps->dh_privkey = NULL;
1618 return -1;
1619 }
1620 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1621 if (wps->dh_ctx == NULL)
1622 return -1;
1623
1624 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1625 pw_id,
1626 pw ? wpabuf_head(pw) : NULL,
1627 pw ? wpabuf_len(pw) : 0, 1);
1628}
1629#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001630
1631
Dmitry Shmidt83474442015-04-15 13:47:09 -07001632#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001633int wpas_ap_stop_ap(struct wpa_supplicant *wpa_s)
1634{
1635 struct hostapd_data *hapd;
1636
1637 if (!wpa_s->ap_iface)
1638 return -1;
1639 hapd = wpa_s->ap_iface->bss[0];
1640 return hostapd_ctrl_iface_stop_ap(hapd);
1641}
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001642
1643
Dmitry Shmidte4663042016-04-04 10:07:49 -07001644int wpas_ap_pmksa_cache_list(struct wpa_supplicant *wpa_s, char *buf,
1645 size_t len)
1646{
1647 size_t reply_len = 0, i;
1648 char ap_delimiter[] = "---- AP ----\n";
1649 char mesh_delimiter[] = "---- mesh ----\n";
1650 size_t dlen;
1651
1652 if (wpa_s->ap_iface) {
1653 dlen = os_strlen(ap_delimiter);
1654 if (dlen > len - reply_len)
1655 return reply_len;
1656 os_memcpy(&buf[reply_len], ap_delimiter, dlen);
1657 reply_len += dlen;
1658
1659 for (i = 0; i < wpa_s->ap_iface->num_bss; i++) {
1660 reply_len += hostapd_ctrl_iface_pmksa_list(
1661 wpa_s->ap_iface->bss[i],
1662 &buf[reply_len], len - reply_len);
1663 }
1664 }
1665
1666 if (wpa_s->ifmsh) {
1667 dlen = os_strlen(mesh_delimiter);
1668 if (dlen > len - reply_len)
1669 return reply_len;
1670 os_memcpy(&buf[reply_len], mesh_delimiter, dlen);
1671 reply_len += dlen;
1672
1673 reply_len += hostapd_ctrl_iface_pmksa_list(
1674 wpa_s->ifmsh->bss[0], &buf[reply_len],
1675 len - reply_len);
1676 }
1677
1678 return reply_len;
1679}
1680
1681
1682void wpas_ap_pmksa_cache_flush(struct wpa_supplicant *wpa_s)
1683{
1684 size_t i;
1685
1686 if (wpa_s->ap_iface) {
1687 for (i = 0; i < wpa_s->ap_iface->num_bss; i++)
1688 hostapd_ctrl_iface_pmksa_flush(wpa_s->ap_iface->bss[i]);
1689 }
1690
1691 if (wpa_s->ifmsh)
1692 hostapd_ctrl_iface_pmksa_flush(wpa_s->ifmsh->bss[0]);
1693}
Paul Stewart092955c2017-02-06 09:13:09 -08001694
1695
1696#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
1697#ifdef CONFIG_MESH
1698
1699int wpas_ap_pmksa_cache_list_mesh(struct wpa_supplicant *wpa_s, const u8 *addr,
1700 char *buf, size_t len)
1701{
1702 return hostapd_ctrl_iface_pmksa_list_mesh(wpa_s->ifmsh->bss[0], addr,
1703 &buf[0], len);
1704}
1705
1706
1707int wpas_ap_pmksa_cache_add_external(struct wpa_supplicant *wpa_s, char *cmd)
1708{
1709 struct external_pmksa_cache *entry;
1710 void *pmksa_cache;
1711
1712 pmksa_cache = hostapd_ctrl_iface_pmksa_create_entry(wpa_s->own_addr,
1713 cmd);
1714 if (!pmksa_cache)
1715 return -1;
1716
1717 entry = os_zalloc(sizeof(struct external_pmksa_cache));
1718 if (!entry)
1719 return -1;
1720
1721 entry->pmksa_cache = pmksa_cache;
1722
1723 dl_list_add(&wpa_s->mesh_external_pmksa_cache, &entry->list);
1724
1725 return 0;
1726}
1727
1728#endif /* CONFIG_MESH */
1729#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
1730
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001731#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte4663042016-04-04 10:07:49 -07001732
1733
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001734#ifdef NEED_AP_MLME
Roshan Pius3a1667e2018-07-03 15:17:14 -07001735void wpas_ap_event_dfs_radar_detected(struct wpa_supplicant *wpa_s,
1736 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001737{
Hai Shalom74f70d42019-02-11 14:42:39 -08001738 struct hostapd_iface *iface = wpa_s->ap_iface;
1739
1740 if (!iface)
1741 iface = wpa_s->ifmsh;
1742 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001743 return;
1744 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001745 hostapd_dfs_radar_detected(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001746 radar->ht_enabled, radar->chan_offset,
1747 radar->chan_width,
1748 radar->cf1, radar->cf2);
1749}
1750
1751
Roshan Pius3a1667e2018-07-03 15:17:14 -07001752void wpas_ap_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
1753 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001754{
Hai Shalom74f70d42019-02-11 14:42:39 -08001755 struct hostapd_iface *iface = wpa_s->ap_iface;
1756
1757 if (!iface)
1758 iface = wpa_s->ifmsh;
1759 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001760 return;
1761 wpa_printf(MSG_DEBUG, "DFS CAC started on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001762 hostapd_dfs_start_cac(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001763 radar->ht_enabled, radar->chan_offset,
1764 radar->chan_width, radar->cf1, radar->cf2);
1765}
1766
1767
Roshan Pius3a1667e2018-07-03 15:17:14 -07001768void wpas_ap_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
1769 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001770{
Hai Shalom74f70d42019-02-11 14:42:39 -08001771 struct hostapd_iface *iface = wpa_s->ap_iface;
1772
1773 if (!iface)
1774 iface = wpa_s->ifmsh;
1775 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001776 return;
1777 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001778 hostapd_dfs_complete_cac(iface, 1, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001779 radar->ht_enabled, radar->chan_offset,
1780 radar->chan_width, radar->cf1, radar->cf2);
1781}
1782
1783
Roshan Pius3a1667e2018-07-03 15:17:14 -07001784void wpas_ap_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
1785 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001786{
Hai Shalom74f70d42019-02-11 14:42:39 -08001787 struct hostapd_iface *iface = wpa_s->ap_iface;
1788
1789 if (!iface)
1790 iface = wpa_s->ifmsh;
1791 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001792 return;
1793 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001794 hostapd_dfs_complete_cac(iface, 0, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001795 radar->ht_enabled, radar->chan_offset,
1796 radar->chan_width, radar->cf1, radar->cf2);
1797}
1798
1799
Roshan Pius3a1667e2018-07-03 15:17:14 -07001800void wpas_ap_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s,
1801 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001802{
Hai Shalom74f70d42019-02-11 14:42:39 -08001803 struct hostapd_iface *iface = wpa_s->ap_iface;
1804
1805 if (!iface)
1806 iface = wpa_s->ifmsh;
1807 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001808 return;
1809 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001810 hostapd_dfs_nop_finished(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001811 radar->ht_enabled, radar->chan_offset,
1812 radar->chan_width, radar->cf1, radar->cf2);
1813}
1814#endif /* NEED_AP_MLME */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001815
1816
1817void ap_periodic(struct wpa_supplicant *wpa_s)
1818{
1819 if (wpa_s->ap_iface)
1820 hostapd_periodic_iface(wpa_s->ap_iface);
1821}