blob: 0261362e3af7dcf4e6ebd63fe70d4c87e19e4e1d [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);
Hai Shaloma20dcd72022-02-04 13:43:00 -080087 if (hostapd_get_oper_chwidth(conf))
88 ieee80211_freq_to_channel_ext(ssid->frequency, 0,
89 hostapd_get_oper_chwidth(conf),
90 &conf->op_class,
91 &conf->channel);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070092
Sunil8cd6f4d2022-06-28 18:40:46 +000093 if (hostapd_get_oper_chwidth(conf) == CONF_OPER_CHWIDTH_80P80MHZ) {
Hai Shalom899fcc72020-10-19 14:38:18 -070094 ieee80211_freq_to_chan(ssid->vht_center_freq2,
95 &freq_seg_idx);
96 hostapd_set_oper_centr_freq_seg1_idx(conf, freq_seg_idx);
97 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070098
99 if (!ssid->p2p_group) {
Hai Shalom899fcc72020-10-19 14:38:18 -0700100 if (!ssid->vht_center_freq1)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700101 goto no_vht;
102 ieee80211_freq_to_chan(ssid->vht_center_freq1,
Hai Shalom899fcc72020-10-19 14:38:18 -0700103 &freq_seg_idx);
104 hostapd_set_oper_centr_freq_seg0_idx(conf, freq_seg_idx);
105
106 wpa_printf(MSG_DEBUG,
107 "VHT seg0 index %d and seg1 index %d for AP",
108 hostapd_get_oper_centr_freq_seg0_idx(conf),
109 hostapd_get_oper_centr_freq_seg1_idx(conf));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700110 return;
111 }
112
113#ifdef CONFIG_P2P
Hai Shalom899fcc72020-10-19 14:38:18 -0700114 switch (hostapd_get_oper_chwidth(conf)) {
Sunil8cd6f4d2022-06-28 18:40:46 +0000115 case CONF_OPER_CHWIDTH_80MHZ:
116 case CONF_OPER_CHWIDTH_80P80MHZ:
Hai Shaloma20dcd72022-02-04 13:43:00 -0800117 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel,
118 conf->op_class);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700119 wpa_printf(MSG_DEBUG,
120 "VHT center channel %u for 80 or 80+80 MHz bandwidth",
121 center_chan);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800122 break;
Sunil8cd6f4d2022-06-28 18:40:46 +0000123 case CONF_OPER_CHWIDTH_160MHZ:
Hai Shaloma20dcd72022-02-04 13:43:00 -0800124 center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel,
125 conf->op_class);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700126 wpa_printf(MSG_DEBUG,
127 "VHT center channel %u for 160 MHz bandwidth",
128 center_chan);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800129 break;
130 default:
131 /*
132 * conf->vht_oper_chwidth might not be set for non-P2P GO cases,
133 * try oper_cwidth 160 MHz first then VHT 80 MHz, if 160 MHz is
134 * not supported.
135 */
Sunil8cd6f4d2022-06-28 18:40:46 +0000136 hostapd_set_oper_chwidth(conf, CONF_OPER_CHWIDTH_160MHZ);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800137 ieee80211_freq_to_channel_ext(ssid->frequency, 0,
138 conf->vht_oper_chwidth,
139 &conf->op_class,
140 &conf->channel);
141 center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel,
142 conf->op_class);
Hsis-Chang Chen44b08ec2020-11-18 16:21:29 +0530143 if (center_chan && is_chanwidth160_supported(mode, conf)) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700144 wpa_printf(MSG_DEBUG,
145 "VHT center channel %u for auto-selected 160 MHz bandwidth",
146 center_chan);
147 } else {
Sunil8cd6f4d2022-06-28 18:40:46 +0000148 hostapd_set_oper_chwidth(conf, CONF_OPER_CHWIDTH_80MHZ);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800149 ieee80211_freq_to_channel_ext(ssid->frequency, 0,
150 conf->vht_oper_chwidth,
151 &conf->op_class,
152 &conf->channel);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800153 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode,
Hai Shaloma20dcd72022-02-04 13:43:00 -0800154 channel,
155 conf->op_class);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700156 wpa_printf(MSG_DEBUG,
157 "VHT center channel %u for auto-selected 80 MHz bandwidth",
158 center_chan);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800159 }
160 break;
161 }
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700162 if (!center_chan)
163 goto no_vht;
164
Hai Shalom899fcc72020-10-19 14:38:18 -0700165 hostapd_set_oper_centr_freq_seg0_idx(conf, center_chan);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700166 wpa_printf(MSG_DEBUG, "VHT seg0 index %d for P2P GO",
Hai Shalom899fcc72020-10-19 14:38:18 -0700167 hostapd_get_oper_centr_freq_seg0_idx(conf));
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700168 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700169#endif /* CONFIG_P2P */
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700170
171no_vht:
Roshan Pius3a1667e2018-07-03 15:17:14 -0700172 wpa_printf(MSG_DEBUG,
173 "No VHT higher bandwidth support for the selected channel %d",
174 conf->channel);
Hai Shalom899fcc72020-10-19 14:38:18 -0700175 hostapd_set_oper_centr_freq_seg0_idx(
176 conf, conf->channel + conf->secondary_channel * 2);
Sunil8cd6f4d2022-06-28 18:40:46 +0000177 hostapd_set_oper_chwidth(conf, CONF_OPER_CHWIDTH_USE_HT);
Sunilaa7ae2b2022-07-19 00:04:20 +0000178 ieee80211_freq_to_channel_ext(ssid->frequency, 0,
179 conf->vht_oper_chwidth,
180 &conf->op_class,
181 &conf->channel);
Hai Shalom899fcc72020-10-19 14:38:18 -0700182}
183
184
185static struct hostapd_hw_modes *
186wpa_supplicant_find_hw_mode(struct wpa_supplicant *wpa_s,
187 enum hostapd_hw_mode hw_mode)
188{
189 struct hostapd_hw_modes *mode = NULL;
190 int i;
191
192 for (i = 0; i < wpa_s->hw.num_modes; i++) {
193 if (wpa_s->hw.modes[i].mode == hw_mode) {
194 mode = &wpa_s->hw.modes[i];
195 break;
196 }
197 }
198
199 return mode;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700200}
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700201
202
Hai Shaloma20dcd72022-02-04 13:43:00 -0800203#ifdef CONFIG_P2P
204
205static int get_max_oper_chwidth_6ghz(int chwidth)
206{
207 switch (chwidth) {
Sunil8cd6f4d2022-06-28 18:40:46 +0000208 case CONF_OPER_CHWIDTH_USE_HT:
Hai Shaloma20dcd72022-02-04 13:43:00 -0800209 return 20;
Sunil8cd6f4d2022-06-28 18:40:46 +0000210 case CONF_OPER_CHWIDTH_40MHZ_6GHZ:
Hai Shaloma20dcd72022-02-04 13:43:00 -0800211 return 40;
Sunil8cd6f4d2022-06-28 18:40:46 +0000212 case CONF_OPER_CHWIDTH_80MHZ:
Hai Shaloma20dcd72022-02-04 13:43:00 -0800213 return 80;
Sunil8cd6f4d2022-06-28 18:40:46 +0000214 case CONF_OPER_CHWIDTH_80P80MHZ:
215 case CONF_OPER_CHWIDTH_160MHZ:
Hai Shaloma20dcd72022-02-04 13:43:00 -0800216 return 160;
217 default:
218 return 0;
219 }
220}
221
222
223static void wpas_conf_ap_he_6ghz(struct wpa_supplicant *wpa_s,
224 struct hostapd_hw_modes *mode,
225 struct wpa_ssid *ssid,
226 struct hostapd_config *conf)
227{
228 bool is_chanwidth_40_80, is_chanwidth_160;
229 int he_chanwidth;
230
231 he_chanwidth =
232 mode->he_capab[wpas_mode_to_ieee80211_mode(
233 ssid->mode)].phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX];
234 is_chanwidth_40_80 = he_chanwidth &
235 HE_PHYCAP_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G;
236 is_chanwidth_160 = he_chanwidth &
237 HE_PHYCAP_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
238
239 wpa_printf(MSG_DEBUG,
240 "Enable HE support (p2p_group=%d he_chwidth_cap=%d)",
241 ssid->p2p_group, he_chanwidth);
242
243 if (mode->he_capab[wpas_mode_to_ieee80211_mode(
244 ssid->mode)].he_supported &&
245 ssid->he)
246 conf->ieee80211ax = 1;
247
248 if (is_chanwidth_40_80 && ssid->p2p_group &&
249 get_max_oper_chwidth_6ghz(ssid->max_oper_chwidth) >= 40) {
250 conf->secondary_channel =
251 wpas_p2p_get_sec_channel_offset_40mhz(
252 wpa_s, mode, conf->channel);
253 wpa_printf(MSG_DEBUG,
254 "Secondary channel offset %d for P2P group",
255 conf->secondary_channel);
Sunil8cd6f4d2022-06-28 18:40:46 +0000256 if (ssid->max_oper_chwidth == CONF_OPER_CHWIDTH_40MHZ_6GHZ)
257 ssid->max_oper_chwidth = CONF_OPER_CHWIDTH_USE_HT;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800258 }
259
260 if ((is_chanwidth_40_80 || is_chanwidth_160) && ssid->p2p_group &&
261 get_max_oper_chwidth_6ghz(ssid->max_oper_chwidth) >= 80)
262 wpas_conf_ap_vht(wpa_s, ssid, conf, mode);
263}
264
265#endif /* CONFIG_P2P */
266
267
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800268int wpa_supplicant_conf_ap_ht(struct wpa_supplicant *wpa_s,
269 struct wpa_ssid *ssid,
270 struct hostapd_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700271{
Hai Shaloma20dcd72022-02-04 13:43:00 -0800272 conf->hw_mode = ieee80211_freq_to_channel_ext(ssid->frequency, 0,
Sunil8cd6f4d2022-06-28 18:40:46 +0000273 CONF_OPER_CHWIDTH_USE_HT,
Hai Shaloma20dcd72022-02-04 13:43:00 -0800274 &conf->op_class,
275 &conf->channel);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800276 if (conf->hw_mode == NUM_HOSTAPD_MODES) {
277 wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
278 ssid->frequency);
279 return -1;
280 }
281
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700282 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800283 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
284 * and a mask of allowed capabilities within conf->ht_capab.
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700285 * Using default config settings for: conf->ht_op_mode_fixed,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800286 * conf->secondary_channel, conf->require_ht
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700287 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800288 if (wpa_s->hw.modes) {
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700289 struct hostapd_hw_modes *mode = NULL;
Hai Shalom899fcc72020-10-19 14:38:18 -0700290 int no_ht = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700291
292 wpa_printf(MSG_DEBUG,
293 "Determining HT/VHT options based on driver capabilities (freq=%u chan=%u)",
294 ssid->frequency, conf->channel);
295
Hai Shaloma20dcd72022-02-04 13:43:00 -0800296 mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes,
297 conf->hw_mode, is_6ghz_freq(ssid->frequency));
Hai Shalom899fcc72020-10-19 14:38:18 -0700298
299 /* May drop to IEEE 802.11b if the driver does not support IEEE
300 * 802.11g */
301 if (!mode && conf->hw_mode == HOSTAPD_MODE_IEEE80211G) {
302 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
303 wpa_printf(MSG_INFO,
304 "Try downgrade to IEEE 802.11b as 802.11g is not supported by the current hardware");
305 mode = wpa_supplicant_find_hw_mode(wpa_s,
306 conf->hw_mode);
307 }
308
309 if (!mode) {
310 wpa_printf(MSG_ERROR,
311 "No match between requested and supported hw modes found");
312 return -1;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700313 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700314
315#ifdef CONFIG_HT_OVERRIDES
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700316 if (ssid->disable_ht)
317 ssid->ht = 0;
318#endif /* CONFIG_HT_OVERRIDES */
319
320 if (!ssid->ht) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700321 wpa_printf(MSG_DEBUG,
322 "HT not enabled in network profile");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700323 conf->ieee80211n = 0;
324 conf->ht_capab = 0;
325 no_ht = 1;
326 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700327
Hai Shaloma20dcd72022-02-04 13:43:00 -0800328 if (mode && is_6ghz_freq(ssid->frequency) &&
329 conf->hw_mode == HOSTAPD_MODE_IEEE80211A) {
330#ifdef CONFIG_P2P
331 wpas_conf_ap_he_6ghz(wpa_s, mode, ssid, conf);
332#endif /* CONFIG_P2P */
333 } else if (!no_ht && mode && mode->ht_capab) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700334 wpa_printf(MSG_DEBUG,
335 "Enable HT support (p2p_group=%d 11a=%d ht40_hw_capab=%d ssid->ht40=%d)",
336 ssid->p2p_group,
337 conf->hw_mode == HOSTAPD_MODE_IEEE80211A,
338 !!(mode->ht_capab &
339 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET),
340 ssid->ht40);
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700341 conf->ieee80211n = 1;
Hai Shalom899fcc72020-10-19 14:38:18 -0700342
343 if (ssid->ht40 &&
344 (mode->ht_capab &
345 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
346 conf->secondary_channel = ssid->ht40;
347 else
348 conf->secondary_channel = 0;
349
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700350#ifdef CONFIG_P2P
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700351 if (ssid->p2p_group &&
352 conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700353 (mode->ht_capab &
354 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -0700355 ssid->ht40) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700356 conf->secondary_channel =
Hai Shaloma20dcd72022-02-04 13:43:00 -0800357 wpas_p2p_get_sec_channel_offset_40mhz(
358 wpa_s, mode, conf->channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700359 wpa_printf(MSG_DEBUG,
360 "HT secondary channel offset %d for P2P group",
361 conf->secondary_channel);
Hai Shalom60840252021-02-19 19:02:11 -0800362 } else if (ssid->p2p_group && conf->secondary_channel &&
363 conf->hw_mode != HOSTAPD_MODE_IEEE80211A) {
364 /* This ended up trying to configure invalid
365 * 2.4 GHz channels (e.g., HT40+ on channel 11)
366 * in some cases, so clear the secondary channel
367 * configuration now to avoid such cases that
368 * would lead to group formation failures. */
369 wpa_printf(MSG_DEBUG,
370 "Disable HT secondary channel for P2P group on 2.4 GHz");
371 conf->secondary_channel = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700372 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700373#endif /* CONFIG_P2P */
374
375 if (!ssid->p2p_group &&
376 (mode->ht_capab &
Roshan Pius3a1667e2018-07-03 15:17:14 -0700377 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700378 conf->secondary_channel = ssid->ht40;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700379 wpa_printf(MSG_DEBUG,
380 "HT secondary channel offset %d for AP",
381 conf->secondary_channel);
382 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700383
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700384 if (conf->secondary_channel)
385 conf->ht_capab |=
386 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800387
388 /*
Hai Shaloma20dcd72022-02-04 13:43:00 -0800389 * include capabilities that won't cause issues
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800390 * to connecting stations, while leaving the current
391 * capabilities intact (currently disabled SMPS).
392 */
393 conf->ht_capab |= mode->ht_capab &
394 (HT_CAP_INFO_GREEN_FIELD |
395 HT_CAP_INFO_SHORT_GI20MHZ |
396 HT_CAP_INFO_SHORT_GI40MHZ |
397 HT_CAP_INFO_RX_STBC_MASK |
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800398 HT_CAP_INFO_TX_STBC |
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800399 HT_CAP_INFO_MAX_AMSDU_SIZE);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700400
Hai Shalom899fcc72020-10-19 14:38:18 -0700401 /* check this before VHT, because setting oper chan
402 * width and friends is the same call for HE and VHT
403 * and checks if conf->ieee8021ax == 1 */
404 if (mode->he_capab[wpas_mode_to_ieee80211_mode(
405 ssid->mode)].he_supported &&
406 ssid->he)
407 conf->ieee80211ax = 1;
408
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700409 if (mode->vht_capab && ssid->vht) {
410 conf->ieee80211ac = 1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800411 conf->vht_capab |= mode->vht_capab;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700412 wpas_conf_ap_vht(wpa_s, ssid, conf, mode);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700413 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800414 }
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700415 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800416
417 if (conf->secondary_channel) {
418 struct wpa_supplicant *iface;
419
420 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
421 {
422 if (iface == wpa_s ||
423 iface->wpa_state < WPA_AUTHENTICATING ||
424 (int) iface->assoc_freq != ssid->frequency)
425 continue;
426
427 /*
428 * Do not allow 40 MHz co-ex PRI/SEC switch to force us
429 * to change our PRI channel since we have an existing,
430 * concurrent connection on that channel and doing
431 * multi-channel concurrency is likely to cause more
432 * harm than using different PRI/SEC selection in
433 * environment with multiple BSSes on these two channels
434 * with mixed 20 MHz or PRI channel selection.
435 */
436 conf->no_pri_sec_switch = 1;
437 }
438 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800439
440 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800441}
442
443
444static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
445 struct wpa_ssid *ssid,
446 struct hostapd_config *conf)
447{
448 struct hostapd_bss_config *bss = conf->bss[0];
449
450 conf->driver = wpa_s->driver;
451
452 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
453
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800454 if (wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800455 return -1;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700456
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700457 if (ssid->pbss > 1) {
458 wpa_printf(MSG_ERROR, "Invalid pbss value(%d) for AP mode",
459 ssid->pbss);
460 return -1;
461 }
462 bss->pbss = ssid->pbss;
463
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800464#ifdef CONFIG_ACS
465 if (ssid->acs) {
466 /* Setting channel to 0 in order to enable ACS */
467 conf->channel = 0;
468 wpa_printf(MSG_DEBUG, "Use automatic channel selection");
469 }
470#endif /* CONFIG_ACS */
471
Roshan Pius3a1667e2018-07-03 15:17:14 -0700472 if (ieee80211_is_dfs(ssid->frequency, wpa_s->hw.modes,
473 wpa_s->hw.num_modes) && wpa_s->conf->country[0]) {
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800474 conf->ieee80211h = 1;
475 conf->ieee80211d = 1;
476 conf->country[0] = wpa_s->conf->country[0];
477 conf->country[1] = wpa_s->conf->country[1];
Paul Stewart092955c2017-02-06 09:13:09 -0800478 conf->country[2] = ' ';
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800479 }
480
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700481#ifdef CONFIG_P2P
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700482 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
483 (ssid->mode == WPAS_MODE_P2P_GO ||
484 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700485 /* Remove 802.11b rates from supported and basic rate sets */
486 int *list = os_malloc(4 * sizeof(int));
487 if (list) {
488 list[0] = 60;
489 list[1] = 120;
490 list[2] = 240;
491 list[3] = -1;
492 }
493 conf->basic_rates = list;
494
495 list = os_malloc(9 * sizeof(int));
496 if (list) {
497 list[0] = 60;
498 list[1] = 90;
499 list[2] = 120;
500 list[3] = 180;
501 list[4] = 240;
502 list[5] = 360;
503 list[6] = 480;
504 list[7] = 540;
505 list[8] = -1;
506 }
507 conf->supported_rates = list;
Hai Shalom021b0b52019-04-10 11:17:58 -0700508 }
509
Hai Shalom74f70d42019-02-11 14:42:39 -0800510#ifdef CONFIG_IEEE80211AX
Hai Shalom021b0b52019-04-10 11:17:58 -0700511 if (ssid->mode == WPAS_MODE_P2P_GO ||
512 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Hai Shalom74f70d42019-02-11 14:42:39 -0800513 conf->ieee80211ax = ssid->he;
514#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800515
516 bss->isolate = !wpa_s->conf->p2p_intra_bss;
Hai Shalomfdcde762020-04-02 11:19:20 -0700517 bss->extended_key_id = wpa_s->conf->extended_key_id;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700518 bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
Hai Shalomfdcde762020-04-02 11:19:20 -0700519 bss->wpa_deny_ptk0_rekey = ssid->wpa_deny_ptk0_rekey;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800520
521 if (ssid->p2p_group) {
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800522 os_memcpy(bss->ip_addr_go, wpa_s->p2pdev->conf->ip_addr_go, 4);
523 os_memcpy(bss->ip_addr_mask, wpa_s->p2pdev->conf->ip_addr_mask,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800524 4);
525 os_memcpy(bss->ip_addr_start,
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800526 wpa_s->p2pdev->conf->ip_addr_start, 4);
527 os_memcpy(bss->ip_addr_end, wpa_s->p2pdev->conf->ip_addr_end,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800528 4);
529 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700530#endif /* CONFIG_P2P */
531
532 if (ssid->ssid_len == 0) {
533 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
534 return -1;
535 }
536 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700537 bss->ssid.ssid_len = ssid->ssid_len;
538 bss->ssid.ssid_set = 1;
539
Dmitry Shmidt04949592012-07-19 12:16:46 -0700540 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
541
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800542 if (ssid->auth_alg)
543 bss->auth_algs = ssid->auth_alg;
544
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700545 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
546 bss->wpa = ssid->proto;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700547 if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
548 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
549 else
550 bss->wpa_key_mgmt = ssid->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700551 bss->wpa_pairwise = ssid->pairwise_cipher;
Hai Shalomc3565922019-10-28 11:58:20 -0700552 if (wpa_key_mgmt_sae(bss->wpa_key_mgmt) && ssid->passphrase) {
553 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
554 } else if (ssid->psk_set) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800555 bin_clear_free(bss->ssid.wpa_psk, sizeof(*bss->ssid.wpa_psk));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700556 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
557 if (bss->ssid.wpa_psk == NULL)
558 return -1;
559 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
560 bss->ssid.wpa_psk->group = 1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700561 bss->ssid.wpa_psk_set = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800562 } else if (ssid->passphrase) {
563 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
Hai Shalomfdcde762020-04-02 11:19:20 -0700564#ifdef CONFIG_WEP
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800565 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
566 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
567 struct hostapd_wep_keys *wep = &bss->ssid.wep;
568 int i;
569 for (i = 0; i < NUM_WEP_KEYS; i++) {
570 if (ssid->wep_key_len[i] == 0)
571 continue;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700572 wep->key[i] = os_memdup(ssid->wep_key[i],
573 ssid->wep_key_len[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800574 if (wep->key[i] == NULL)
575 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800576 wep->len[i] = ssid->wep_key_len[i];
577 }
578 wep->idx = ssid->wep_tx_keyidx;
579 wep->keys_set = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700580#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700581 }
Hai Shalomc3565922019-10-28 11:58:20 -0700582#ifdef CONFIG_SAE
583 if (ssid->sae_password) {
584 struct sae_password_entry *pw;
585
586 pw = os_zalloc(sizeof(*pw));
587 if (!pw)
588 return -1;
589 os_memset(pw->peer_addr, 0xff, ETH_ALEN);
590 pw->password = os_strdup(ssid->sae_password);
591 if (!pw->password) {
592 os_free(pw);
593 return -1;
594 }
595 if (ssid->sae_password_id) {
596 pw->identifier = os_strdup(ssid->sae_password_id);
597 if (!pw->identifier) {
598 str_clear_free(pw->password);
599 os_free(pw);
600 return -1;
601 }
602 }
603
604 pw->next = bss->sae_passwords;
605 bss->sae_passwords = pw;
606 }
607
Hai Shaloma20dcd72022-02-04 13:43:00 -0800608 if (ssid->sae_pwe != DEFAULT_SAE_PWE)
609 bss->sae_pwe = ssid->sae_pwe;
610 else
611 bss->sae_pwe = wpa_s->conf->sae_pwe;
Hai Shalomc3565922019-10-28 11:58:20 -0700612#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700613
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700614 if (wpa_s->conf->go_interworking) {
615 wpa_printf(MSG_DEBUG,
616 "P2P: Enable Interworking with access_network_type: %d",
617 wpa_s->conf->go_access_network_type);
618 bss->interworking = wpa_s->conf->go_interworking;
619 bss->access_network_type = wpa_s->conf->go_access_network_type;
620 bss->internet = wpa_s->conf->go_internet;
621 if (wpa_s->conf->go_venue_group) {
622 wpa_printf(MSG_DEBUG,
623 "P2P: Venue group: %d Venue type: %d",
624 wpa_s->conf->go_venue_group,
625 wpa_s->conf->go_venue_type);
626 bss->venue_group = wpa_s->conf->go_venue_group;
627 bss->venue_type = wpa_s->conf->go_venue_type;
628 bss->venue_info_set = 1;
629 }
630 }
631
Dmitry Shmidt04949592012-07-19 12:16:46 -0700632 if (ssid->ap_max_inactivity)
633 bss->ap_max_inactivity = ssid->ap_max_inactivity;
634
635 if (ssid->dtim_period)
636 bss->dtim_period = ssid->dtim_period;
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -0800637 else if (wpa_s->conf->dtim_period)
638 bss->dtim_period = wpa_s->conf->dtim_period;
639
640 if (ssid->beacon_int)
641 conf->beacon_int = ssid->beacon_int;
642 else if (wpa_s->conf->beacon_int)
643 conf->beacon_int = wpa_s->conf->beacon_int;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700644
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800645#ifdef CONFIG_P2P
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800646 if (ssid->mode == WPAS_MODE_P2P_GO ||
647 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
648 if (wpa_s->conf->p2p_go_ctwindow > conf->beacon_int) {
649 wpa_printf(MSG_INFO,
650 "CTWindow (%d) is bigger than beacon interval (%d) - avoid configuring it",
651 wpa_s->conf->p2p_go_ctwindow,
652 conf->beacon_int);
653 conf->p2p_go_ctwindow = 0;
654 } else {
655 conf->p2p_go_ctwindow = wpa_s->conf->p2p_go_ctwindow;
656 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800657 }
658#endif /* CONFIG_P2P */
659
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800660 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
661 bss->rsn_pairwise = bss->wpa_pairwise;
662 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
663 bss->rsn_pairwise);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700664
Hai Shalomfdcde762020-04-02 11:19:20 -0700665 if (bss->wpa && bss->ieee802_1x) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700666 bss->ssid.security_policy = SECURITY_WPA;
Hai Shalomfdcde762020-04-02 11:19:20 -0700667 } else if (bss->wpa) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700668 bss->ssid.security_policy = SECURITY_WPA_PSK;
Hai Shalomfdcde762020-04-02 11:19:20 -0700669#ifdef CONFIG_WEP
670 } else if (bss->ieee802_1x) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800671 int cipher = WPA_CIPHER_NONE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700672 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
673 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800674 if (bss->default_wep_key_len)
675 cipher = bss->default_wep_key_len >= 13 ?
676 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
677 bss->wpa_group = cipher;
678 bss->wpa_pairwise = cipher;
679 bss->rsn_pairwise = cipher;
680 } else if (bss->ssid.wep.keys_set) {
681 int cipher = WPA_CIPHER_WEP40;
682 if (bss->ssid.wep.len[0] >= 13)
683 cipher = WPA_CIPHER_WEP104;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700684 bss->ssid.security_policy = SECURITY_STATIC_WEP;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800685 bss->wpa_group = cipher;
686 bss->wpa_pairwise = cipher;
687 bss->rsn_pairwise = cipher;
Hai Shalomfdcde762020-04-02 11:19:20 -0700688#endif /* CONFIG_WEP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800689 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700690 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800691 bss->wpa_group = WPA_CIPHER_NONE;
692 bss->wpa_pairwise = WPA_CIPHER_NONE;
693 bss->rsn_pairwise = WPA_CIPHER_NONE;
694 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700695
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700696 if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
697 (bss->wpa_group == WPA_CIPHER_CCMP ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800698 bss->wpa_group == WPA_CIPHER_GCMP ||
699 bss->wpa_group == WPA_CIPHER_CCMP_256 ||
700 bss->wpa_group == WPA_CIPHER_GCMP_256)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700701 /*
702 * Strong ciphers do not need frequent rekeying, so increase
703 * the default GTK rekeying period to 24 hours.
704 */
705 bss->wpa_group_rekey = 86400;
706 }
707
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700708 if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT)
709 bss->ieee80211w = ssid->ieee80211w;
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700710
Hai Shalom74f70d42019-02-11 14:42:39 -0800711#ifdef CONFIG_OCV
712 bss->ocv = ssid->ocv;
713#endif /* CONFIG_OCV */
714
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700715#ifdef CONFIG_WPS
716 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800717 * Enable WPS by default for open and WPA/WPA2-Personal network, but
718 * require user interaction to actually use it. Only the internal
719 * Registrar is supported.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700720 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800721 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
722 bss->ssid.security_policy != SECURITY_PLAINTEXT)
723 goto no_wps;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800724 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800725 (!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ||
726 !(bss->wpa & 2)))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800727 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
728 * configuration */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700729 if (ssid->wps_disabled)
730 goto no_wps;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700731 bss->eap_server = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700732
733 if (!ssid->ignore_broadcast_ssid)
734 bss->wps_state = 2;
735
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700736 bss->ap_setup_locked = 2;
737 if (wpa_s->conf->config_methods)
738 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
739 os_memcpy(bss->device_type, wpa_s->conf->device_type,
740 WPS_DEV_TYPE_LEN);
741 if (wpa_s->conf->device_name) {
742 bss->device_name = os_strdup(wpa_s->conf->device_name);
743 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
744 }
745 if (wpa_s->conf->manufacturer)
746 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
747 if (wpa_s->conf->model_name)
748 bss->model_name = os_strdup(wpa_s->conf->model_name);
749 if (wpa_s->conf->model_number)
750 bss->model_number = os_strdup(wpa_s->conf->model_number);
751 if (wpa_s->conf->serial_number)
752 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
753 if (is_nil_uuid(wpa_s->conf->uuid))
754 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
755 else
756 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
757 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700758 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -0700759 if (ssid->eap.fragment_size != DEFAULT_FRAGMENT_SIZE)
760 bss->fragment_size = ssid->eap.fragment_size;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800761no_wps:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700762#endif /* CONFIG_WPS */
763
764 if (wpa_s->max_stations &&
765 wpa_s->max_stations < wpa_s->conf->max_num_sta)
766 bss->max_num_sta = wpa_s->max_stations;
767 else
768 bss->max_num_sta = wpa_s->conf->max_num_sta;
769
Roshan Pius3a1667e2018-07-03 15:17:14 -0700770 if (!bss->isolate)
771 bss->isolate = wpa_s->conf->ap_isolate;
772
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700773 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
774
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700775 if (wpa_s->conf->ap_vendor_elements) {
776 bss->vendor_elements =
777 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
778 }
Hai Shaloma20dcd72022-02-04 13:43:00 -0800779 if (wpa_s->conf->ap_assocresp_elements) {
780 bss->assocresp_elements =
781 wpabuf_dup(wpa_s->conf->ap_assocresp_elements);
782 }
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700783
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700784 bss->ftm_responder = wpa_s->conf->ftm_responder;
785 bss->ftm_initiator = wpa_s->conf->ftm_initiator;
786
Hai Shalomfdcde762020-04-02 11:19:20 -0700787 bss->transition_disable = ssid->transition_disable;
788
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700789 return 0;
790}
791
792
793static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
794{
795#ifdef CONFIG_P2P
796 struct wpa_supplicant *wpa_s = ctx;
797 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700798
799 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700800 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700801 return;
Dmitry Shmidt18463232014-01-24 12:29:41 -0800802 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
803 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700804 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
805 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700806 buf + IEEE80211_HDRLEN + 1,
807 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700808#endif /* CONFIG_P2P */
809}
810
811
812static void ap_wps_event_cb(void *ctx, enum wps_event event,
813 union wps_event_data *data)
814{
815#ifdef CONFIG_P2P
816 struct wpa_supplicant *wpa_s = ctx;
817
Jouni Malinen75ecf522011-06-27 15:19:46 -0700818 if (event == WPS_EV_FAIL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700819 struct wps_event_fail *fail = &data->fail;
820
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800821 if (wpa_s->p2pdev && wpa_s->p2pdev != wpa_s &&
Jouni Malinen75ecf522011-06-27 15:19:46 -0700822 wpa_s == wpa_s->global->p2p_group_formation) {
823 /*
824 * src/ap/wps_hostapd.c has already sent this on the
825 * main interface, so only send on the parent interface
826 * here if needed.
827 */
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800828 wpa_msg(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_FAIL
Jouni Malinen75ecf522011-06-27 15:19:46 -0700829 "msg=%d config_error=%d",
830 fail->msg, fail->config_error);
831 }
832 wpas_p2p_wps_failed(wpa_s, fail);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700833 }
834#endif /* CONFIG_P2P */
835}
836
837
838static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800839 int authorized, const u8 *p2p_dev_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700840{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800841 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700842}
843
844
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700845#ifdef CONFIG_P2P
846static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
847 const u8 *psk, size_t psk_len)
848{
849
850 struct wpa_supplicant *wpa_s = ctx;
851 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
852 return;
853 wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
854}
855#endif /* CONFIG_P2P */
856
857
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700858static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
859{
860#ifdef CONFIG_P2P
861 struct wpa_supplicant *wpa_s = ctx;
862 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700863
864 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700865 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700866 return -1;
867 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
868 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700869 buf + IEEE80211_HDRLEN + 1,
870 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700871#endif /* CONFIG_P2P */
872 return 0;
873}
874
875
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800876static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700877 const u8 *bssid, const u8 *ie, size_t ie_len,
878 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700879{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700880 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700881 unsigned int freq = 0;
882
883 if (wpa_s->ap_iface)
884 freq = wpa_s->ap_iface->freq;
885
Dmitry Shmidt04949592012-07-19 12:16:46 -0700886 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700887 freq, ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700888}
889
890
891static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
892 const u8 *uuid_e)
893{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700894 struct wpa_supplicant *wpa_s = ctx;
895 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700896}
897
898
899static void wpas_ap_configured_cb(void *ctx)
900{
901 struct wpa_supplicant *wpa_s = ctx;
902
Roshan Pius3a1667e2018-07-03 15:17:14 -0700903 wpa_printf(MSG_DEBUG, "AP interface setup completed - state %s",
904 hostapd_state_text(wpa_s->ap_iface->state));
905 if (wpa_s->ap_iface->state == HAPD_IFACE_DISABLED) {
906 wpa_supplicant_ap_deinit(wpa_s);
907 return;
908 }
909
Sunil Ravi236f0f52021-06-29 11:18:20 -0700910 if (wpa_s->current_ssid) {
911 int acs = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800912
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800913#ifdef CONFIG_ACS
Sunil Ravi236f0f52021-06-29 11:18:20 -0700914 acs = wpa_s->current_ssid->acs;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800915#endif /* CONFIG_ACS */
Sunil Ravi236f0f52021-06-29 11:18:20 -0700916 if (acs || (wpa_s->assoc_freq && wpa_s->ap_iface->freq &&
Hai Shaloma20dcd72022-02-04 13:43:00 -0800917 (int) wpa_s->assoc_freq != wpa_s->ap_iface->freq)) {
Sunil Ravi236f0f52021-06-29 11:18:20 -0700918 wpa_s->assoc_freq = wpa_s->ap_iface->freq;
919 wpa_s->current_ssid->frequency = wpa_s->ap_iface->freq;
920 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700921 }
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800922
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700923 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
924
925 if (wpa_s->ap_configured_cb)
926 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
927 wpa_s->ap_configured_cb_data);
928}
929
930
931int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
932 struct wpa_ssid *ssid)
933{
934 struct wpa_driver_associate_params params;
935 struct hostapd_iface *hapd_iface;
936 struct hostapd_config *conf;
937 size_t i;
938
939 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
940 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
941 return -1;
942 }
943
944 wpa_supplicant_ap_deinit(wpa_s);
945
946 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
947 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
948
949 os_memset(&params, 0, sizeof(params));
950 params.ssid = ssid->ssid;
951 params.ssid_len = ssid->ssid_len;
952 switch (ssid->mode) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700953 case WPAS_MODE_AP:
954 case WPAS_MODE_P2P_GO:
955 case WPAS_MODE_P2P_GROUP_FORMATION:
956 params.mode = IEEE80211_MODE_AP;
957 break;
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800958 default:
959 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700960 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700961 if (ssid->frequency == 0)
962 ssid->frequency = 2462; /* default channel 11 */
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700963 params.freq.freq = ssid->frequency;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700964
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800965 if ((ssid->mode == WPAS_MODE_AP || ssid->mode == WPAS_MODE_P2P_GO) &&
966 ssid->enable_edmg) {
Hai Shalomc3565922019-10-28 11:58:20 -0700967 u8 primary_channel;
968
969 if (ieee80211_freq_to_chan(ssid->frequency, &primary_channel) ==
970 NUM_HOSTAPD_MODES) {
971 wpa_printf(MSG_WARNING,
972 "EDMG: Failed to get the primary channel");
973 return -1;
974 }
975
976 hostapd_encode_edmg_chan(ssid->enable_edmg, ssid->edmg_channel,
977 primary_channel, &params.freq.edmg);
978 }
979
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800980 params.wpa_proto = ssid->proto;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700981 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
982 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800983 else if (ssid->key_mgmt & WPA_KEY_MGMT_SAE)
984 wpa_s->key_mgmt = WPA_KEY_MGMT_SAE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700985 else
986 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800987 params.key_mgmt_suite = wpa_s->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700988
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800989 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
990 1);
991 if (wpa_s->pairwise_cipher < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700992 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
993 "cipher.");
994 return -1;
995 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800996 params.pairwise_suite = wpa_s->pairwise_cipher;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700997 params.group_suite = params.pairwise_suite;
998
999#ifdef CONFIG_P2P
1000 if (ssid->mode == WPAS_MODE_P2P_GO ||
1001 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
1002 params.p2p = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001003#endif /* CONFIG_P2P */
1004
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001005 if (wpa_s->p2pdev->set_ap_uapsd)
1006 params.uapsd = wpa_s->p2pdev->ap_uapsd;
Dmitry Shmidtec58b162014-02-19 12:44:18 -08001007 else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
1008 params.uapsd = 1; /* mandatory for P2P GO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001009 else
1010 params.uapsd = -1;
1011
Roshan Pius3a1667e2018-07-03 15:17:14 -07001012 if (ieee80211_is_dfs(params.freq.freq, wpa_s->hw.modes,
1013 wpa_s->hw.num_modes))
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001014 params.freq.freq = 0; /* set channel after CAC */
1015
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001016 if (params.p2p)
1017 wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_GO);
1018 else
1019 wpa_drv_get_ext_capa(wpa_s, WPA_IF_AP_BSS);
1020
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001021 if (wpa_drv_associate(wpa_s, &params) < 0) {
1022 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
1023 return -1;
1024 }
1025
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001026 wpa_s->ap_iface = hapd_iface = hostapd_alloc_iface();
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001027 if (hapd_iface == NULL)
1028 return -1;
1029 hapd_iface->owner = wpa_s;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001030 hapd_iface->drv_flags = wpa_s->drv_flags;
1031 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001032 hapd_iface->extended_capa = wpa_s->extended_capa;
1033 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
1034 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
Sunil Ravia04bd252022-05-02 22:54:18 -07001035 hapd_iface->drv_max_acl_mac_addrs = wpa_s->drv_max_acl_mac_addrs;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001036
1037 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
1038 if (conf == NULL) {
1039 wpa_supplicant_ap_deinit(wpa_s);
1040 return -1;
1041 }
1042
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001043 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
1044 wpa_s->conf->wmm_ac_params,
1045 sizeof(wpa_s->conf->wmm_ac_params));
1046
Hai Shalom899fcc72020-10-19 14:38:18 -07001047 os_memcpy(wpa_s->ap_iface->conf->tx_queue, wpa_s->conf->tx_queue,
1048 sizeof(wpa_s->conf->tx_queue));
1049
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001050 if (params.uapsd > 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001051 conf->bss[0]->wmm_enabled = 1;
1052 conf->bss[0]->wmm_uapsd = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001053 }
1054
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001055 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
1056 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
1057 wpa_supplicant_ap_deinit(wpa_s);
1058 return -1;
1059 }
1060
1061#ifdef CONFIG_P2P
1062 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001063 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001064 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001065 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001066 P2P_GROUP_FORMATION;
1067#endif /* CONFIG_P2P */
1068
1069 hapd_iface->num_bss = conf->num_bss;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001070 hapd_iface->bss = os_calloc(conf->num_bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001071 sizeof(struct hostapd_data *));
1072 if (hapd_iface->bss == NULL) {
1073 wpa_supplicant_ap_deinit(wpa_s);
1074 return -1;
1075 }
1076
1077 for (i = 0; i < conf->num_bss; i++) {
1078 hapd_iface->bss[i] =
1079 hostapd_alloc_bss_data(hapd_iface, conf,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001080 conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001081 if (hapd_iface->bss[i] == NULL) {
1082 wpa_supplicant_ap_deinit(wpa_s);
1083 return -1;
1084 }
1085
1086 hapd_iface->bss[i]->msg_ctx = wpa_s;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001087 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->p2pdev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001088 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
1089 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
1090 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
1091 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
1092 hostapd_register_probereq_cb(hapd_iface->bss[i],
1093 ap_probe_req_rx, wpa_s);
1094 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
1095 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
1096 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
1097 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
1098 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
1099 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
1100#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001101 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
1102 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001103 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001104 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
1105 ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001106#endif /* CONFIG_P2P */
1107 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
1108 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001109#ifdef CONFIG_TESTING_OPTIONS
1110 hapd_iface->bss[i]->ext_eapol_frame_io =
1111 wpa_s->ext_eapol_frame_io;
1112#endif /* CONFIG_TESTING_OPTIONS */
Sunil Ravia04bd252022-05-02 22:54:18 -07001113
1114#ifdef CONFIG_WNM_AP
1115 if (ssid->mode == WPAS_MODE_AP)
1116 hapd_iface->bss[i]->conf->bss_transition = 1;
1117#endif /* CONFIG_WNM_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001118 }
1119
1120 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
1121 hapd_iface->bss[0]->driver = wpa_s->driver;
1122 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
1123
1124 wpa_s->current_ssid = ssid;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001125 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001126 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
1127 wpa_s->assoc_freq = ssid->frequency;
Hai Shalomc3565922019-10-28 11:58:20 -07001128 wpa_s->ap_iface->conf->enable_edmg = ssid->enable_edmg;
1129 wpa_s->ap_iface->conf->edmg_channel = ssid->edmg_channel;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001130
Roshan Pius3a1667e2018-07-03 15:17:14 -07001131#if defined(CONFIG_P2P) && defined(CONFIG_ACS)
1132 if (wpa_s->p2p_go_do_acs) {
1133 wpa_s->ap_iface->conf->channel = 0;
1134 wpa_s->ap_iface->conf->hw_mode = wpa_s->p2p_go_acs_band;
1135 ssid->acs = 1;
1136 }
1137#endif /* CONFIG_P2P && CONFIG_ACS */
1138
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001139 if (hostapd_setup_interface(wpa_s->ap_iface)) {
1140 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
1141 wpa_supplicant_ap_deinit(wpa_s);
1142 return -1;
1143 }
1144
1145 return 0;
1146}
1147
1148
1149void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
1150{
1151#ifdef CONFIG_WPS
1152 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1153#endif /* CONFIG_WPS */
1154
1155 if (wpa_s->ap_iface == NULL)
1156 return;
1157
1158 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001159 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001160 wpa_s->assoc_freq = 0;
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07001161 wpas_p2p_ap_deinit(wpa_s);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001162 wpa_s->ap_iface->driver_ap_teardown =
1163 !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
1164
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001165 hostapd_interface_deinit(wpa_s->ap_iface);
1166 hostapd_interface_free(wpa_s->ap_iface);
1167 wpa_s->ap_iface = NULL;
1168 wpa_drv_deinit_ap(wpa_s);
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07001169 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1170 " reason=%d locally_generated=1",
1171 MAC2STR(wpa_s->own_addr), WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001172}
1173
1174
1175void ap_tx_status(void *ctx, const u8 *addr,
1176 const u8 *buf, size_t len, int ack)
1177{
1178#ifdef NEED_AP_MLME
1179 struct wpa_supplicant *wpa_s = ctx;
1180 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
1181#endif /* NEED_AP_MLME */
1182}
1183
1184
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001185void ap_eapol_tx_status(void *ctx, const u8 *dst,
1186 const u8 *data, size_t len, int ack)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001187{
1188#ifdef NEED_AP_MLME
1189 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001190 if (!wpa_s->ap_iface)
1191 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001192 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
1193#endif /* NEED_AP_MLME */
1194}
1195
1196
1197void ap_client_poll_ok(void *ctx, const u8 *addr)
1198{
1199#ifdef NEED_AP_MLME
1200 struct wpa_supplicant *wpa_s = ctx;
1201 if (wpa_s->ap_iface)
1202 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
1203#endif /* NEED_AP_MLME */
1204}
1205
1206
1207void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
1208{
1209#ifdef NEED_AP_MLME
1210 struct wpa_supplicant *wpa_s = ctx;
1211 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001212#endif /* NEED_AP_MLME */
1213}
1214
1215
1216void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
1217{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001218#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001219 struct wpa_supplicant *wpa_s = ctx;
1220 struct hostapd_frame_info fi;
1221 os_memset(&fi, 0, sizeof(fi));
Hai Shaloma20dcd72022-02-04 13:43:00 -08001222 fi.freq = rx_mgmt->freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001223 fi.datarate = rx_mgmt->datarate;
1224 fi.ssi_signal = rx_mgmt->ssi_signal;
1225 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
1226 rx_mgmt->frame_len, &fi);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001227#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001228}
1229
1230
1231void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
1232{
1233#ifdef NEED_AP_MLME
1234 struct wpa_supplicant *wpa_s = ctx;
1235 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
1236#endif /* NEED_AP_MLME */
1237}
1238
1239
1240void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
Sunil8cd6f4d2022-06-28 18:40:46 +00001241 const u8 *src_addr, const u8 *buf, size_t len,
1242 enum frame_encryption encrypted)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001243{
Sunil8cd6f4d2022-06-28 18:40:46 +00001244 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len,
1245 encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001246}
1247
1248
1249#ifdef CONFIG_WPS
1250
1251int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
1252 const u8 *p2p_dev_addr)
1253{
1254 if (!wpa_s->ap_iface)
1255 return -1;
1256 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
1257 p2p_dev_addr);
1258}
1259
1260
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001261int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
1262{
1263 struct wps_registrar *reg;
1264 int reg_sel = 0, wps_sta = 0;
1265
1266 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
1267 return -1;
1268
1269 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
1270 reg_sel = wps_registrar_wps_cancel(reg);
1271 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
Dmitry Shmidt04949592012-07-19 12:16:46 -07001272 ap_sta_wps_cancel, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001273
1274 if (!reg_sel && !wps_sta) {
1275 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
1276 "time");
1277 return -1;
1278 }
1279
1280 /*
1281 * There are 2 cases to return wps cancel as success:
1282 * 1. When wps cancel was initiated but no connection has been
1283 * established with client yet.
1284 * 2. Client is in the middle of exchanging WPS messages.
1285 */
1286
1287 return 0;
1288}
1289
1290
1291int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001292 const char *pin, char *buf, size_t buflen,
1293 int timeout)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001294{
1295 int ret, ret_len = 0;
1296
1297 if (!wpa_s->ap_iface)
1298 return -1;
1299
1300 if (pin == NULL) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001301 unsigned int rpin;
1302
1303 if (wps_generate_pin(&rpin) < 0)
1304 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001305 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001306 if (os_snprintf_error(buflen, ret_len))
1307 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001308 pin = buf;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001309 } else if (buf) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001310 ret_len = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001311 if (os_snprintf_error(buflen, ret_len))
1312 return -1;
1313 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001314
1315 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001316 timeout);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001317 if (ret)
1318 return -1;
1319 return ret_len;
1320}
1321
1322
1323static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
1324{
1325 struct wpa_supplicant *wpa_s = eloop_data;
1326 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
1327 wpas_wps_ap_pin_disable(wpa_s);
1328}
1329
1330
1331static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
1332{
1333 struct hostapd_data *hapd;
1334
1335 if (wpa_s->ap_iface == NULL)
1336 return;
1337 hapd = wpa_s->ap_iface->bss[0];
1338 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
1339 hapd->ap_pin_failures = 0;
1340 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1341 if (timeout > 0)
1342 eloop_register_timeout(timeout, 0,
1343 wpas_wps_ap_pin_timeout, wpa_s, NULL);
1344}
1345
1346
1347void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
1348{
1349 struct hostapd_data *hapd;
1350
1351 if (wpa_s->ap_iface == NULL)
1352 return;
1353 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
1354 hapd = wpa_s->ap_iface->bss[0];
1355 os_free(hapd->conf->ap_pin);
1356 hapd->conf->ap_pin = NULL;
1357 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1358}
1359
1360
1361const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
1362{
1363 struct hostapd_data *hapd;
1364 unsigned int pin;
1365 char pin_txt[9];
1366
1367 if (wpa_s->ap_iface == NULL)
1368 return NULL;
1369 hapd = wpa_s->ap_iface->bss[0];
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001370 if (wps_generate_pin(&pin) < 0)
1371 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001372 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001373 os_free(hapd->conf->ap_pin);
1374 hapd->conf->ap_pin = os_strdup(pin_txt);
1375 if (hapd->conf->ap_pin == NULL)
1376 return NULL;
1377 wpas_wps_ap_pin_enable(wpa_s, timeout);
1378
1379 return hapd->conf->ap_pin;
1380}
1381
1382
1383const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
1384{
1385 struct hostapd_data *hapd;
1386 if (wpa_s->ap_iface == NULL)
1387 return NULL;
1388 hapd = wpa_s->ap_iface->bss[0];
1389 return hapd->conf->ap_pin;
1390}
1391
1392
1393int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
1394 int timeout)
1395{
1396 struct hostapd_data *hapd;
1397 char pin_txt[9];
1398 int ret;
1399
1400 if (wpa_s->ap_iface == NULL)
1401 return -1;
1402 hapd = wpa_s->ap_iface->bss[0];
1403 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001404 if (os_snprintf_error(sizeof(pin_txt), ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001405 return -1;
1406 os_free(hapd->conf->ap_pin);
1407 hapd->conf->ap_pin = os_strdup(pin_txt);
1408 if (hapd->conf->ap_pin == NULL)
1409 return -1;
1410 wpas_wps_ap_pin_enable(wpa_s, timeout);
1411
1412 return 0;
1413}
1414
1415
1416void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
1417{
1418 struct hostapd_data *hapd;
1419
1420 if (wpa_s->ap_iface == NULL)
1421 return;
1422 hapd = wpa_s->ap_iface->bss[0];
1423
1424 /*
1425 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
1426 * PIN if this happens multiple times to slow down brute force attacks.
1427 */
1428 hapd->ap_pin_failures++;
1429 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
1430 hapd->ap_pin_failures);
1431 if (hapd->ap_pin_failures < 3)
1432 return;
1433
1434 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
1435 hapd->ap_pin_failures = 0;
1436 os_free(hapd->conf->ap_pin);
1437 hapd->conf->ap_pin = NULL;
1438}
1439
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001440
1441#ifdef CONFIG_WPS_NFC
1442
1443struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
1444 int ndef)
1445{
1446 struct hostapd_data *hapd;
1447
1448 if (wpa_s->ap_iface == NULL)
1449 return NULL;
1450 hapd = wpa_s->ap_iface->bss[0];
1451 return hostapd_wps_nfc_config_token(hapd, ndef);
1452}
1453
1454
1455struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
1456 int ndef)
1457{
1458 struct hostapd_data *hapd;
1459
1460 if (wpa_s->ap_iface == NULL)
1461 return NULL;
1462 hapd = wpa_s->ap_iface->bss[0];
1463 return hostapd_wps_nfc_hs_cr(hapd, ndef);
1464}
1465
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001466
1467int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
1468 const struct wpabuf *req,
1469 const struct wpabuf *sel)
1470{
1471 struct hostapd_data *hapd;
1472
1473 if (wpa_s->ap_iface == NULL)
1474 return -1;
1475 hapd = wpa_s->ap_iface->bss[0];
1476 return hostapd_wps_nfc_report_handover(hapd, req, sel);
1477}
1478
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001479#endif /* CONFIG_WPS_NFC */
1480
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001481#endif /* CONFIG_WPS */
1482
1483
1484#ifdef CONFIG_CTRL_IFACE
1485
1486int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
1487 char *buf, size_t buflen)
1488{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001489 struct hostapd_data *hapd;
1490
1491 if (wpa_s->ap_iface)
1492 hapd = wpa_s->ap_iface->bss[0];
1493 else if (wpa_s->ifmsh)
1494 hapd = wpa_s->ifmsh->bss[0];
1495 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001496 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001497 return hostapd_ctrl_iface_sta_first(hapd, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001498}
1499
1500
1501int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
1502 char *buf, size_t buflen)
1503{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001504 struct hostapd_data *hapd;
1505
1506 if (wpa_s->ap_iface)
1507 hapd = wpa_s->ap_iface->bss[0];
1508 else if (wpa_s->ifmsh)
1509 hapd = wpa_s->ifmsh->bss[0];
1510 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001511 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001512 return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001513}
1514
1515
1516int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
1517 char *buf, size_t buflen)
1518{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001519 struct hostapd_data *hapd;
1520
1521 if (wpa_s->ap_iface)
1522 hapd = wpa_s->ap_iface->bss[0];
1523 else if (wpa_s->ifmsh)
1524 hapd = wpa_s->ifmsh->bss[0];
1525 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001526 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001527 return hostapd_ctrl_iface_sta_next(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001528}
1529
1530
Dmitry Shmidt04949592012-07-19 12:16:46 -07001531int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1532 const char *txtaddr)
1533{
1534 if (wpa_s->ap_iface == NULL)
1535 return -1;
1536 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1537 txtaddr);
1538}
1539
1540
1541int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1542 const char *txtaddr)
1543{
1544 if (wpa_s->ap_iface == NULL)
1545 return -1;
1546 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1547 txtaddr);
1548}
1549
1550
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001551int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1552 size_t buflen, int verbose)
1553{
1554 char *pos = buf, *end = buf + buflen;
1555 int ret;
1556 struct hostapd_bss_config *conf;
1557
1558 if (wpa_s->ap_iface == NULL)
1559 return -1;
1560
1561 conf = wpa_s->ap_iface->bss[0]->conf;
1562 if (conf->wpa == 0)
1563 return 0;
1564
1565 ret = os_snprintf(pos, end - pos,
1566 "pairwise_cipher=%s\n"
1567 "group_cipher=%s\n"
1568 "key_mgmt=%s\n",
1569 wpa_cipher_txt(conf->rsn_pairwise),
1570 wpa_cipher_txt(conf->wpa_group),
1571 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1572 conf->wpa));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001573 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001574 return pos - buf;
1575 pos += ret;
1576 return pos - buf;
1577}
1578
Sunil Ravia04bd252022-05-02 22:54:18 -07001579
1580#ifdef CONFIG_WNM_AP
1581
1582int ap_ctrl_iface_disassoc_imminent(struct wpa_supplicant *wpa_s,
1583 const char *buf)
1584{
1585 struct hostapd_data *hapd;
1586
1587 if (wpa_s->ap_iface)
1588 hapd = wpa_s->ap_iface->bss[0];
1589 else
1590 return -1;
1591 return hostapd_ctrl_iface_disassoc_imminent(hapd, buf);
1592}
1593
1594
1595int ap_ctrl_iface_ess_disassoc(struct wpa_supplicant *wpa_s, const char *buf)
1596{
1597 struct hostapd_data *hapd;
1598
1599 if (wpa_s->ap_iface)
1600 hapd = wpa_s->ap_iface->bss[0];
1601 else
1602 return -1;
1603 return hostapd_ctrl_iface_ess_disassoc(hapd, buf);
1604}
1605
1606
1607int ap_ctrl_iface_bss_tm_req(struct wpa_supplicant *wpa_s, const char *buf)
1608{
1609 struct hostapd_data *hapd;
1610
1611 if (wpa_s->ap_iface)
1612 hapd = wpa_s->ap_iface->bss[0];
1613 else
1614 return -1;
1615 return hostapd_ctrl_iface_bss_tm_req(hapd, buf);
1616}
1617
1618#endif /* CONFIG_WNM_AP */
1619
1620
1621int ap_ctrl_iface_acl_add_mac(struct wpa_supplicant *wpa_s,
1622 enum macaddr_acl acl_type,
1623 const char *buf)
1624{
1625 struct hostapd_data *hapd;
1626
1627 if (wpa_s->ap_iface)
1628 hapd = wpa_s->ap_iface->bss[0];
1629 else
1630 return -1;
1631
1632 hapd->conf->macaddr_acl = acl_type;
1633
1634 if (acl_type == ACCEPT_UNLESS_DENIED)
1635 return hostapd_ctrl_iface_acl_add_mac(&hapd->conf->deny_mac,
1636 &hapd->conf->num_deny_mac,
1637 buf);
1638 if (acl_type == DENY_UNLESS_ACCEPTED)
1639 return hostapd_ctrl_iface_acl_add_mac(
1640 &hapd->conf->accept_mac,
1641 &hapd->conf->num_accept_mac, buf);
1642
1643 return -1;
1644}
1645
1646
1647int ap_ctrl_iface_acl_del_mac(struct wpa_supplicant *wpa_s,
1648 enum macaddr_acl acl_type,
1649 const char *buf)
1650{
1651 struct hostapd_data *hapd;
1652
1653 if (wpa_s->ap_iface)
1654 hapd = wpa_s->ap_iface->bss[0];
1655 else
1656 return -1;
1657
1658 hapd->conf->macaddr_acl = acl_type;
1659
1660 if (acl_type == ACCEPT_UNLESS_DENIED)
1661 return hostapd_ctrl_iface_acl_del_mac(&hapd->conf->deny_mac,
1662 &hapd->conf->num_deny_mac,
1663 buf);
1664 if (acl_type == DENY_UNLESS_ACCEPTED)
1665 return hostapd_ctrl_iface_acl_del_mac(
1666 &hapd->conf->accept_mac, &hapd->conf->num_accept_mac,
1667 buf);
1668
1669 return -1;
1670}
1671
1672
1673int ap_ctrl_iface_acl_show_mac(struct wpa_supplicant *wpa_s,
1674 enum macaddr_acl acl_type, char *buf,
1675 size_t buflen)
1676{
1677 struct hostapd_data *hapd;
1678
1679 if (wpa_s->ap_iface)
1680 hapd = wpa_s->ap_iface->bss[0];
1681 else
1682 return -1;
1683
1684 if (acl_type == ACCEPT_UNLESS_DENIED)
1685 return hostapd_ctrl_iface_acl_show_mac(hapd->conf->deny_mac,
1686 hapd->conf->num_deny_mac,
1687 buf, buflen);
1688 if (acl_type == DENY_UNLESS_ACCEPTED)
1689 return hostapd_ctrl_iface_acl_show_mac(
1690 hapd->conf->accept_mac, hapd->conf->num_accept_mac,
1691 buf, buflen);
1692
1693 return -1;
1694}
1695
1696
1697void ap_ctrl_iface_acl_clear_list(struct wpa_supplicant *wpa_s,
1698 enum macaddr_acl acl_type)
1699{
1700 struct hostapd_data *hapd;
1701
1702 if (wpa_s->ap_iface)
1703 hapd = wpa_s->ap_iface->bss[0];
1704 else
1705 return;
1706
1707 hapd->conf->macaddr_acl = acl_type;
1708
1709 if (acl_type == ACCEPT_UNLESS_DENIED)
1710 hostapd_ctrl_iface_acl_clear_list(&hapd->conf->deny_mac,
1711 &hapd->conf->num_deny_mac);
1712 else if (acl_type == DENY_UNLESS_ACCEPTED)
1713 hostapd_ctrl_iface_acl_clear_list(&hapd->conf->accept_mac,
1714 &hapd->conf->num_accept_mac);
1715}
1716
1717
1718int ap_ctrl_iface_disassoc_deny_mac(struct wpa_supplicant *wpa_s)
1719{
1720 struct hostapd_data *hapd;
1721
1722 if (wpa_s->ap_iface)
1723 hapd = wpa_s->ap_iface->bss[0];
1724 else
1725 return -1;
1726
1727 return hostapd_disassoc_deny_mac(hapd);
1728}
1729
1730
1731int ap_ctrl_iface_disassoc_accept_mac(struct wpa_supplicant *wpa_s)
1732{
1733 struct hostapd_data *hapd;
1734
1735 if (wpa_s->ap_iface)
1736 hapd = wpa_s->ap_iface->bss[0];
1737 else
1738 return -1;
1739
1740 return hostapd_disassoc_accept_mac(hapd);
1741}
1742
1743
1744int ap_ctrl_iface_set_acl(struct wpa_supplicant *wpa_s)
1745{
1746 struct hostapd_data *hapd;
1747
1748 if (wpa_s->ap_iface)
1749 hapd = wpa_s->ap_iface->bss[0];
1750 else
1751 return -1;
1752
1753 return hostapd_set_acl(hapd);
1754}
1755
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001756#endif /* CONFIG_CTRL_IFACE */
1757
1758
1759int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1760{
1761 struct hostapd_iface *iface = wpa_s->ap_iface;
1762 struct wpa_ssid *ssid = wpa_s->current_ssid;
1763 struct hostapd_data *hapd;
1764
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001765 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1766 ssid->mode == WPAS_MODE_INFRA ||
1767 ssid->mode == WPAS_MODE_IBSS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001768 return -1;
1769
1770#ifdef CONFIG_P2P
1771 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001772 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001773 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001774 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001775 P2P_GROUP_FORMATION;
1776#endif /* CONFIG_P2P */
1777
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001778 hapd = iface->bss[0];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001779 if (hapd->drv_priv == NULL)
1780 return -1;
1781 ieee802_11_set_beacons(iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001782 hostapd_set_ap_wps_ie(hapd);
1783
1784 return 0;
1785}
1786
1787
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001788int ap_switch_channel(struct wpa_supplicant *wpa_s,
1789 struct csa_settings *settings)
1790{
1791#ifdef NEED_AP_MLME
Hai Shalom899fcc72020-10-19 14:38:18 -07001792 struct hostapd_iface *iface = NULL;
1793
1794 if (wpa_s->ap_iface)
1795 iface = wpa_s->ap_iface;
1796 else if (wpa_s->ifmsh)
1797 iface = wpa_s->ifmsh;
1798
1799 if (!iface || !iface->bss[0])
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001800 return -1;
1801
Hai Shalom899fcc72020-10-19 14:38:18 -07001802 return hostapd_switch_channel(iface->bss[0], settings);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001803#else /* NEED_AP_MLME */
1804 return -1;
1805#endif /* NEED_AP_MLME */
1806}
1807
1808
Dmitry Shmidt83474442015-04-15 13:47:09 -07001809#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001810int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1811{
1812 struct csa_settings settings;
1813 int ret = hostapd_parse_csa_settings(pos, &settings);
1814
1815 if (ret)
1816 return ret;
1817
1818 return ap_switch_channel(wpa_s, &settings);
1819}
Dmitry Shmidt83474442015-04-15 13:47:09 -07001820#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001821
1822
Dmitry Shmidt04949592012-07-19 12:16:46 -07001823void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
Hai Shalom81f62d82019-07-22 12:10:00 -07001824 int offset, int width, int cf1, int cf2, int finished)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001825{
Hai Shalom74f70d42019-02-11 14:42:39 -08001826 struct hostapd_iface *iface = wpa_s->ap_iface;
Hai Shalombf6e0ba2019-02-11 12:01:50 -08001827
Hai Shalom74f70d42019-02-11 14:42:39 -08001828 if (!iface)
1829 iface = wpa_s->ifmsh;
1830 if (!iface)
1831 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001832 wpa_s->assoc_freq = freq;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001833 if (wpa_s->current_ssid)
1834 wpa_s->current_ssid->frequency = freq;
Hai Shalom74f70d42019-02-11 14:42:39 -08001835 hostapd_event_ch_switch(iface->bss[0], freq, ht,
Hai Shalom81f62d82019-07-22 12:10:00 -07001836 offset, width, cf1, cf2, finished);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001837}
1838
1839
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001840int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1841 const u8 *addr)
1842{
1843 struct hostapd_data *hapd;
1844 struct hostapd_bss_config *conf;
1845
1846 if (!wpa_s->ap_iface)
1847 return -1;
1848
1849 if (addr)
1850 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1851 MAC2STR(addr));
1852 else
1853 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1854
1855 hapd = wpa_s->ap_iface->bss[0];
1856 conf = hapd->conf;
1857
1858 os_free(conf->accept_mac);
1859 conf->accept_mac = NULL;
1860 conf->num_accept_mac = 0;
1861 os_free(conf->deny_mac);
1862 conf->deny_mac = NULL;
1863 conf->num_deny_mac = 0;
1864
1865 if (addr == NULL) {
1866 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1867 return 0;
1868 }
1869
1870 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1871 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1872 if (conf->accept_mac == NULL)
1873 return -1;
1874 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1875 conf->num_accept_mac = 1;
1876
1877 return 0;
1878}
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001879
1880
1881#ifdef CONFIG_WPS_NFC
1882int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1883 const struct wpabuf *pw, const u8 *pubkey_hash)
1884{
1885 struct hostapd_data *hapd;
1886 struct wps_context *wps;
1887
1888 if (!wpa_s->ap_iface)
1889 return -1;
1890 hapd = wpa_s->ap_iface->bss[0];
1891 wps = hapd->wps;
1892
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001893 if (wpa_s->p2pdev->conf->wps_nfc_dh_pubkey == NULL ||
1894 wpa_s->p2pdev->conf->wps_nfc_dh_privkey == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001895 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1896 return -1;
1897 }
1898
1899 dh5_free(wps->dh_ctx);
1900 wpabuf_free(wps->dh_pubkey);
1901 wpabuf_free(wps->dh_privkey);
1902 wps->dh_privkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001903 wpa_s->p2pdev->conf->wps_nfc_dh_privkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001904 wps->dh_pubkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001905 wpa_s->p2pdev->conf->wps_nfc_dh_pubkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001906 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1907 wps->dh_ctx = NULL;
1908 wpabuf_free(wps->dh_pubkey);
1909 wps->dh_pubkey = NULL;
1910 wpabuf_free(wps->dh_privkey);
1911 wps->dh_privkey = NULL;
1912 return -1;
1913 }
1914 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1915 if (wps->dh_ctx == NULL)
1916 return -1;
1917
1918 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1919 pw_id,
1920 pw ? wpabuf_head(pw) : NULL,
1921 pw ? wpabuf_len(pw) : 0, 1);
1922}
1923#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001924
1925
Dmitry Shmidt83474442015-04-15 13:47:09 -07001926#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001927int wpas_ap_stop_ap(struct wpa_supplicant *wpa_s)
1928{
1929 struct hostapd_data *hapd;
1930
1931 if (!wpa_s->ap_iface)
1932 return -1;
1933 hapd = wpa_s->ap_iface->bss[0];
1934 return hostapd_ctrl_iface_stop_ap(hapd);
1935}
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001936
1937
Dmitry Shmidte4663042016-04-04 10:07:49 -07001938int wpas_ap_pmksa_cache_list(struct wpa_supplicant *wpa_s, char *buf,
1939 size_t len)
1940{
1941 size_t reply_len = 0, i;
1942 char ap_delimiter[] = "---- AP ----\n";
1943 char mesh_delimiter[] = "---- mesh ----\n";
1944 size_t dlen;
1945
1946 if (wpa_s->ap_iface) {
1947 dlen = os_strlen(ap_delimiter);
1948 if (dlen > len - reply_len)
1949 return reply_len;
1950 os_memcpy(&buf[reply_len], ap_delimiter, dlen);
1951 reply_len += dlen;
1952
1953 for (i = 0; i < wpa_s->ap_iface->num_bss; i++) {
1954 reply_len += hostapd_ctrl_iface_pmksa_list(
1955 wpa_s->ap_iface->bss[i],
1956 &buf[reply_len], len - reply_len);
1957 }
1958 }
1959
1960 if (wpa_s->ifmsh) {
1961 dlen = os_strlen(mesh_delimiter);
1962 if (dlen > len - reply_len)
1963 return reply_len;
1964 os_memcpy(&buf[reply_len], mesh_delimiter, dlen);
1965 reply_len += dlen;
1966
1967 reply_len += hostapd_ctrl_iface_pmksa_list(
1968 wpa_s->ifmsh->bss[0], &buf[reply_len],
1969 len - reply_len);
1970 }
1971
1972 return reply_len;
1973}
1974
1975
1976void wpas_ap_pmksa_cache_flush(struct wpa_supplicant *wpa_s)
1977{
1978 size_t i;
1979
1980 if (wpa_s->ap_iface) {
1981 for (i = 0; i < wpa_s->ap_iface->num_bss; i++)
1982 hostapd_ctrl_iface_pmksa_flush(wpa_s->ap_iface->bss[i]);
1983 }
1984
1985 if (wpa_s->ifmsh)
1986 hostapd_ctrl_iface_pmksa_flush(wpa_s->ifmsh->bss[0]);
1987}
Paul Stewart092955c2017-02-06 09:13:09 -08001988
1989
1990#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
1991#ifdef CONFIG_MESH
1992
1993int wpas_ap_pmksa_cache_list_mesh(struct wpa_supplicant *wpa_s, const u8 *addr,
1994 char *buf, size_t len)
1995{
1996 return hostapd_ctrl_iface_pmksa_list_mesh(wpa_s->ifmsh->bss[0], addr,
1997 &buf[0], len);
1998}
1999
2000
2001int wpas_ap_pmksa_cache_add_external(struct wpa_supplicant *wpa_s, char *cmd)
2002{
2003 struct external_pmksa_cache *entry;
2004 void *pmksa_cache;
2005
2006 pmksa_cache = hostapd_ctrl_iface_pmksa_create_entry(wpa_s->own_addr,
2007 cmd);
2008 if (!pmksa_cache)
2009 return -1;
2010
2011 entry = os_zalloc(sizeof(struct external_pmksa_cache));
2012 if (!entry)
2013 return -1;
2014
2015 entry->pmksa_cache = pmksa_cache;
2016
2017 dl_list_add(&wpa_s->mesh_external_pmksa_cache, &entry->list);
2018
2019 return 0;
2020}
2021
2022#endif /* CONFIG_MESH */
2023#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
2024
Hai Shaloma20dcd72022-02-04 13:43:00 -08002025
2026int wpas_ap_update_beacon(struct wpa_supplicant *wpa_s)
2027{
2028 struct hostapd_data *hapd;
2029
2030 if (!wpa_s->ap_iface)
2031 return -1;
2032 hapd = wpa_s->ap_iface->bss[0];
2033
2034 wpabuf_free(hapd->conf->assocresp_elements);
2035 hapd->conf->assocresp_elements = NULL;
2036 if (wpa_s->conf->ap_assocresp_elements) {
2037 hapd->conf->assocresp_elements =
2038 wpabuf_dup(wpa_s->conf->ap_assocresp_elements);
2039 }
2040
2041 wpabuf_free(hapd->conf->vendor_elements);
2042 hapd->conf->vendor_elements = NULL;
2043 if (wpa_s->conf->ap_vendor_elements) {
2044 hapd->conf->vendor_elements =
2045 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
2046 }
2047
2048 return ieee802_11_set_beacon(hapd);
2049}
2050
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002051#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte4663042016-04-04 10:07:49 -07002052
2053
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002054#ifdef NEED_AP_MLME
Roshan Pius3a1667e2018-07-03 15:17:14 -07002055void wpas_ap_event_dfs_radar_detected(struct wpa_supplicant *wpa_s,
2056 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002057{
Hai Shalom74f70d42019-02-11 14:42:39 -08002058 struct hostapd_iface *iface = wpa_s->ap_iface;
2059
2060 if (!iface)
2061 iface = wpa_s->ifmsh;
2062 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002063 return;
2064 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08002065 hostapd_dfs_radar_detected(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002066 radar->ht_enabled, radar->chan_offset,
2067 radar->chan_width,
2068 radar->cf1, radar->cf2);
2069}
2070
2071
Roshan Pius3a1667e2018-07-03 15:17:14 -07002072void wpas_ap_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
2073 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002074{
Hai Shalom74f70d42019-02-11 14:42:39 -08002075 struct hostapd_iface *iface = wpa_s->ap_iface;
2076
2077 if (!iface)
2078 iface = wpa_s->ifmsh;
2079 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002080 return;
2081 wpa_printf(MSG_DEBUG, "DFS CAC started on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08002082 hostapd_dfs_start_cac(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002083 radar->ht_enabled, radar->chan_offset,
2084 radar->chan_width, radar->cf1, radar->cf2);
2085}
2086
2087
Roshan Pius3a1667e2018-07-03 15:17:14 -07002088void wpas_ap_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
2089 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002090{
Hai Shalom74f70d42019-02-11 14:42:39 -08002091 struct hostapd_iface *iface = wpa_s->ap_iface;
2092
2093 if (!iface)
2094 iface = wpa_s->ifmsh;
2095 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002096 return;
2097 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08002098 hostapd_dfs_complete_cac(iface, 1, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002099 radar->ht_enabled, radar->chan_offset,
2100 radar->chan_width, radar->cf1, radar->cf2);
2101}
2102
2103
Roshan Pius3a1667e2018-07-03 15:17:14 -07002104void wpas_ap_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
2105 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002106{
Hai Shalom74f70d42019-02-11 14:42:39 -08002107 struct hostapd_iface *iface = wpa_s->ap_iface;
2108
2109 if (!iface)
2110 iface = wpa_s->ifmsh;
2111 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002112 return;
2113 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08002114 hostapd_dfs_complete_cac(iface, 0, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002115 radar->ht_enabled, radar->chan_offset,
2116 radar->chan_width, radar->cf1, radar->cf2);
2117}
2118
2119
Roshan Pius3a1667e2018-07-03 15:17:14 -07002120void wpas_ap_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s,
2121 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002122{
Hai Shalom74f70d42019-02-11 14:42:39 -08002123 struct hostapd_iface *iface = wpa_s->ap_iface;
2124
2125 if (!iface)
2126 iface = wpa_s->ifmsh;
2127 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002128 return;
2129 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08002130 hostapd_dfs_nop_finished(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002131 radar->ht_enabled, radar->chan_offset,
2132 radar->chan_width, radar->cf1, radar->cf2);
2133}
2134#endif /* NEED_AP_MLME */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002135
2136
2137void ap_periodic(struct wpa_supplicant *wpa_s)
2138{
2139 if (wpa_s->ap_iface)
2140 hostapd_periodic_iface(wpa_s->ap_iface);
2141}