blob: f4c38117bf3df25023654185a67586492f167c67 [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,
Sunil Ravi89eba102022-09-13 21:04:37 -0700179 conf->vht_oper_chwidth,
180 &conf->op_class, &conf->channel);
Hai Shalom899fcc72020-10-19 14:38:18 -0700181}
182
183
184static struct hostapd_hw_modes *
185wpa_supplicant_find_hw_mode(struct wpa_supplicant *wpa_s,
186 enum hostapd_hw_mode hw_mode)
187{
188 struct hostapd_hw_modes *mode = NULL;
189 int i;
190
191 for (i = 0; i < wpa_s->hw.num_modes; i++) {
192 if (wpa_s->hw.modes[i].mode == hw_mode) {
193 mode = &wpa_s->hw.modes[i];
194 break;
195 }
196 }
197
198 return mode;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700199}
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700200
201
Hai Shaloma20dcd72022-02-04 13:43:00 -0800202#ifdef CONFIG_P2P
203
204static int get_max_oper_chwidth_6ghz(int chwidth)
205{
206 switch (chwidth) {
Sunil8cd6f4d2022-06-28 18:40:46 +0000207 case CONF_OPER_CHWIDTH_USE_HT:
Hai Shaloma20dcd72022-02-04 13:43:00 -0800208 return 20;
Sunil8cd6f4d2022-06-28 18:40:46 +0000209 case CONF_OPER_CHWIDTH_40MHZ_6GHZ:
Hai Shaloma20dcd72022-02-04 13:43:00 -0800210 return 40;
Sunil8cd6f4d2022-06-28 18:40:46 +0000211 case CONF_OPER_CHWIDTH_80MHZ:
Hai Shaloma20dcd72022-02-04 13:43:00 -0800212 return 80;
Sunil8cd6f4d2022-06-28 18:40:46 +0000213 case CONF_OPER_CHWIDTH_80P80MHZ:
214 case CONF_OPER_CHWIDTH_160MHZ:
Hai Shaloma20dcd72022-02-04 13:43:00 -0800215 return 160;
216 default:
217 return 0;
218 }
219}
220
221
222static void wpas_conf_ap_he_6ghz(struct wpa_supplicant *wpa_s,
223 struct hostapd_hw_modes *mode,
224 struct wpa_ssid *ssid,
225 struct hostapd_config *conf)
226{
227 bool is_chanwidth_40_80, is_chanwidth_160;
228 int he_chanwidth;
229
230 he_chanwidth =
231 mode->he_capab[wpas_mode_to_ieee80211_mode(
232 ssid->mode)].phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX];
233 is_chanwidth_40_80 = he_chanwidth &
234 HE_PHYCAP_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G;
235 is_chanwidth_160 = he_chanwidth &
236 HE_PHYCAP_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
237
238 wpa_printf(MSG_DEBUG,
239 "Enable HE support (p2p_group=%d he_chwidth_cap=%d)",
240 ssid->p2p_group, he_chanwidth);
241
242 if (mode->he_capab[wpas_mode_to_ieee80211_mode(
243 ssid->mode)].he_supported &&
244 ssid->he)
245 conf->ieee80211ax = 1;
246
247 if (is_chanwidth_40_80 && ssid->p2p_group &&
248 get_max_oper_chwidth_6ghz(ssid->max_oper_chwidth) >= 40) {
249 conf->secondary_channel =
250 wpas_p2p_get_sec_channel_offset_40mhz(
251 wpa_s, mode, conf->channel);
252 wpa_printf(MSG_DEBUG,
253 "Secondary channel offset %d for P2P group",
254 conf->secondary_channel);
Sunil8cd6f4d2022-06-28 18:40:46 +0000255 if (ssid->max_oper_chwidth == CONF_OPER_CHWIDTH_40MHZ_6GHZ)
256 ssid->max_oper_chwidth = CONF_OPER_CHWIDTH_USE_HT;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800257 }
258
259 if ((is_chanwidth_40_80 || is_chanwidth_160) && ssid->p2p_group &&
260 get_max_oper_chwidth_6ghz(ssid->max_oper_chwidth) >= 80)
261 wpas_conf_ap_vht(wpa_s, ssid, conf, mode);
262}
263
264#endif /* CONFIG_P2P */
265
266
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800267int wpa_supplicant_conf_ap_ht(struct wpa_supplicant *wpa_s,
268 struct wpa_ssid *ssid,
269 struct hostapd_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700270{
Hai Shaloma20dcd72022-02-04 13:43:00 -0800271 conf->hw_mode = ieee80211_freq_to_channel_ext(ssid->frequency, 0,
Sunil8cd6f4d2022-06-28 18:40:46 +0000272 CONF_OPER_CHWIDTH_USE_HT,
Hai Shaloma20dcd72022-02-04 13:43:00 -0800273 &conf->op_class,
274 &conf->channel);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800275 if (conf->hw_mode == NUM_HOSTAPD_MODES) {
276 wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
277 ssid->frequency);
278 return -1;
279 }
280
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700281 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800282 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
283 * and a mask of allowed capabilities within conf->ht_capab.
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700284 * Using default config settings for: conf->ht_op_mode_fixed,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800285 * conf->secondary_channel, conf->require_ht
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700286 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800287 if (wpa_s->hw.modes) {
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700288 struct hostapd_hw_modes *mode = NULL;
Hai Shalom899fcc72020-10-19 14:38:18 -0700289 int no_ht = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700290
291 wpa_printf(MSG_DEBUG,
292 "Determining HT/VHT options based on driver capabilities (freq=%u chan=%u)",
293 ssid->frequency, conf->channel);
294
Hai Shaloma20dcd72022-02-04 13:43:00 -0800295 mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes,
296 conf->hw_mode, is_6ghz_freq(ssid->frequency));
Hai Shalom899fcc72020-10-19 14:38:18 -0700297
298 /* May drop to IEEE 802.11b if the driver does not support IEEE
299 * 802.11g */
300 if (!mode && conf->hw_mode == HOSTAPD_MODE_IEEE80211G) {
301 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
302 wpa_printf(MSG_INFO,
303 "Try downgrade to IEEE 802.11b as 802.11g is not supported by the current hardware");
304 mode = wpa_supplicant_find_hw_mode(wpa_s,
305 conf->hw_mode);
306 }
307
308 if (!mode) {
309 wpa_printf(MSG_ERROR,
310 "No match between requested and supported hw modes found");
311 return -1;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700312 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700313
314#ifdef CONFIG_HT_OVERRIDES
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700315 if (ssid->disable_ht)
316 ssid->ht = 0;
317#endif /* CONFIG_HT_OVERRIDES */
318
319 if (!ssid->ht) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700320 wpa_printf(MSG_DEBUG,
321 "HT not enabled in network profile");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700322 conf->ieee80211n = 0;
323 conf->ht_capab = 0;
324 no_ht = 1;
325 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700326
Hai Shaloma20dcd72022-02-04 13:43:00 -0800327 if (mode && is_6ghz_freq(ssid->frequency) &&
328 conf->hw_mode == HOSTAPD_MODE_IEEE80211A) {
329#ifdef CONFIG_P2P
330 wpas_conf_ap_he_6ghz(wpa_s, mode, ssid, conf);
331#endif /* CONFIG_P2P */
332 } else if (!no_ht && mode && mode->ht_capab) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700333 wpa_printf(MSG_DEBUG,
334 "Enable HT support (p2p_group=%d 11a=%d ht40_hw_capab=%d ssid->ht40=%d)",
335 ssid->p2p_group,
336 conf->hw_mode == HOSTAPD_MODE_IEEE80211A,
337 !!(mode->ht_capab &
338 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET),
339 ssid->ht40);
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700340 conf->ieee80211n = 1;
Hai Shalom899fcc72020-10-19 14:38:18 -0700341
342 if (ssid->ht40 &&
343 (mode->ht_capab &
344 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
345 conf->secondary_channel = ssid->ht40;
346 else
347 conf->secondary_channel = 0;
348
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700349#ifdef CONFIG_P2P
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700350 if (ssid->p2p_group &&
351 conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700352 (mode->ht_capab &
353 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -0700354 ssid->ht40) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700355 conf->secondary_channel =
Hai Shaloma20dcd72022-02-04 13:43:00 -0800356 wpas_p2p_get_sec_channel_offset_40mhz(
357 wpa_s, mode, conf->channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700358 wpa_printf(MSG_DEBUG,
359 "HT secondary channel offset %d for P2P group",
360 conf->secondary_channel);
Hai Shalom60840252021-02-19 19:02:11 -0800361 } else if (ssid->p2p_group && conf->secondary_channel &&
362 conf->hw_mode != HOSTAPD_MODE_IEEE80211A) {
363 /* This ended up trying to configure invalid
364 * 2.4 GHz channels (e.g., HT40+ on channel 11)
365 * in some cases, so clear the secondary channel
366 * configuration now to avoid such cases that
367 * would lead to group formation failures. */
368 wpa_printf(MSG_DEBUG,
369 "Disable HT secondary channel for P2P group on 2.4 GHz");
370 conf->secondary_channel = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700371 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700372#endif /* CONFIG_P2P */
373
374 if (!ssid->p2p_group &&
375 (mode->ht_capab &
Roshan Pius3a1667e2018-07-03 15:17:14 -0700376 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700377 conf->secondary_channel = ssid->ht40;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700378 wpa_printf(MSG_DEBUG,
379 "HT secondary channel offset %d for AP",
380 conf->secondary_channel);
381 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700382
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700383 if (conf->secondary_channel)
384 conf->ht_capab |=
385 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800386
387 /*
Hai Shaloma20dcd72022-02-04 13:43:00 -0800388 * include capabilities that won't cause issues
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800389 * to connecting stations, while leaving the current
390 * capabilities intact (currently disabled SMPS).
391 */
392 conf->ht_capab |= mode->ht_capab &
393 (HT_CAP_INFO_GREEN_FIELD |
394 HT_CAP_INFO_SHORT_GI20MHZ |
395 HT_CAP_INFO_SHORT_GI40MHZ |
396 HT_CAP_INFO_RX_STBC_MASK |
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800397 HT_CAP_INFO_TX_STBC |
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800398 HT_CAP_INFO_MAX_AMSDU_SIZE);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700399
Hai Shalom899fcc72020-10-19 14:38:18 -0700400 /* check this before VHT, because setting oper chan
401 * width and friends is the same call for HE and VHT
402 * and checks if conf->ieee8021ax == 1 */
403 if (mode->he_capab[wpas_mode_to_ieee80211_mode(
404 ssid->mode)].he_supported &&
405 ssid->he)
406 conf->ieee80211ax = 1;
407
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700408 if (mode->vht_capab && ssid->vht) {
409 conf->ieee80211ac = 1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800410 conf->vht_capab |= mode->vht_capab;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700411 wpas_conf_ap_vht(wpa_s, ssid, conf, mode);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700412 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800413 }
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700414 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800415
Sunil Ravi77a0f092022-10-03 00:53:41 +0000416 if (wpa_s->p2p_go_no_pri_sec_switch) {
417 conf->no_pri_sec_switch = 1;
418 } else if (conf->secondary_channel) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800419 struct wpa_supplicant *iface;
420
421 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
422 {
423 if (iface == wpa_s ||
424 iface->wpa_state < WPA_AUTHENTICATING ||
425 (int) iface->assoc_freq != ssid->frequency)
426 continue;
427
428 /*
429 * Do not allow 40 MHz co-ex PRI/SEC switch to force us
430 * to change our PRI channel since we have an existing,
431 * concurrent connection on that channel and doing
432 * multi-channel concurrency is likely to cause more
433 * harm than using different PRI/SEC selection in
434 * environment with multiple BSSes on these two channels
435 * with mixed 20 MHz or PRI channel selection.
436 */
437 conf->no_pri_sec_switch = 1;
438 }
439 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800440
441 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800442}
443
444
445static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
446 struct wpa_ssid *ssid,
447 struct hostapd_config *conf)
448{
449 struct hostapd_bss_config *bss = conf->bss[0];
450
451 conf->driver = wpa_s->driver;
452
453 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
454
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800455 if (wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800456 return -1;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700457
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700458 if (ssid->pbss > 1) {
459 wpa_printf(MSG_ERROR, "Invalid pbss value(%d) for AP mode",
460 ssid->pbss);
461 return -1;
462 }
463 bss->pbss = ssid->pbss;
464
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800465#ifdef CONFIG_ACS
466 if (ssid->acs) {
467 /* Setting channel to 0 in order to enable ACS */
468 conf->channel = 0;
469 wpa_printf(MSG_DEBUG, "Use automatic channel selection");
470 }
471#endif /* CONFIG_ACS */
472
Roshan Pius3a1667e2018-07-03 15:17:14 -0700473 if (ieee80211_is_dfs(ssid->frequency, wpa_s->hw.modes,
474 wpa_s->hw.num_modes) && wpa_s->conf->country[0]) {
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800475 conf->ieee80211h = 1;
476 conf->ieee80211d = 1;
477 conf->country[0] = wpa_s->conf->country[0];
478 conf->country[1] = wpa_s->conf->country[1];
Paul Stewart092955c2017-02-06 09:13:09 -0800479 conf->country[2] = ' ';
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800480 }
481
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700482#ifdef CONFIG_P2P
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700483 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
484 (ssid->mode == WPAS_MODE_P2P_GO ||
485 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700486 /* Remove 802.11b rates from supported and basic rate sets */
487 int *list = os_malloc(4 * sizeof(int));
488 if (list) {
489 list[0] = 60;
490 list[1] = 120;
491 list[2] = 240;
492 list[3] = -1;
493 }
494 conf->basic_rates = list;
495
496 list = os_malloc(9 * sizeof(int));
497 if (list) {
498 list[0] = 60;
499 list[1] = 90;
500 list[2] = 120;
501 list[3] = 180;
502 list[4] = 240;
503 list[5] = 360;
504 list[6] = 480;
505 list[7] = 540;
506 list[8] = -1;
507 }
508 conf->supported_rates = list;
Hai Shalom021b0b52019-04-10 11:17:58 -0700509 }
510
Hai Shalom74f70d42019-02-11 14:42:39 -0800511#ifdef CONFIG_IEEE80211AX
Hai Shalom021b0b52019-04-10 11:17:58 -0700512 if (ssid->mode == WPAS_MODE_P2P_GO ||
513 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Hai Shalom74f70d42019-02-11 14:42:39 -0800514 conf->ieee80211ax = ssid->he;
515#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800516
517 bss->isolate = !wpa_s->conf->p2p_intra_bss;
Hai Shalomfdcde762020-04-02 11:19:20 -0700518 bss->extended_key_id = wpa_s->conf->extended_key_id;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700519 bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
Hai Shalomfdcde762020-04-02 11:19:20 -0700520 bss->wpa_deny_ptk0_rekey = ssid->wpa_deny_ptk0_rekey;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800521
522 if (ssid->p2p_group) {
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800523 os_memcpy(bss->ip_addr_go, wpa_s->p2pdev->conf->ip_addr_go, 4);
524 os_memcpy(bss->ip_addr_mask, wpa_s->p2pdev->conf->ip_addr_mask,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800525 4);
526 os_memcpy(bss->ip_addr_start,
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800527 wpa_s->p2pdev->conf->ip_addr_start, 4);
528 os_memcpy(bss->ip_addr_end, wpa_s->p2pdev->conf->ip_addr_end,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800529 4);
530 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700531#endif /* CONFIG_P2P */
532
533 if (ssid->ssid_len == 0) {
534 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
535 return -1;
536 }
537 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700538 bss->ssid.ssid_len = ssid->ssid_len;
539 bss->ssid.ssid_set = 1;
540
Dmitry Shmidt04949592012-07-19 12:16:46 -0700541 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
542
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800543 if (ssid->auth_alg)
544 bss->auth_algs = ssid->auth_alg;
545
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700546 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
547 bss->wpa = ssid->proto;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700548 if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
549 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
550 else
551 bss->wpa_key_mgmt = ssid->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700552 bss->wpa_pairwise = ssid->pairwise_cipher;
Hai Shalomc3565922019-10-28 11:58:20 -0700553 if (wpa_key_mgmt_sae(bss->wpa_key_mgmt) && ssid->passphrase) {
554 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
555 } else if (ssid->psk_set) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800556 bin_clear_free(bss->ssid.wpa_psk, sizeof(*bss->ssid.wpa_psk));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700557 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
558 if (bss->ssid.wpa_psk == NULL)
559 return -1;
560 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
561 bss->ssid.wpa_psk->group = 1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700562 bss->ssid.wpa_psk_set = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800563 } else if (ssid->passphrase) {
564 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
Hai Shalomfdcde762020-04-02 11:19:20 -0700565#ifdef CONFIG_WEP
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800566 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
567 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
568 struct hostapd_wep_keys *wep = &bss->ssid.wep;
569 int i;
570 for (i = 0; i < NUM_WEP_KEYS; i++) {
571 if (ssid->wep_key_len[i] == 0)
572 continue;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700573 wep->key[i] = os_memdup(ssid->wep_key[i],
574 ssid->wep_key_len[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800575 if (wep->key[i] == NULL)
576 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800577 wep->len[i] = ssid->wep_key_len[i];
578 }
579 wep->idx = ssid->wep_tx_keyidx;
580 wep->keys_set = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700581#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700582 }
Hai Shalomc3565922019-10-28 11:58:20 -0700583#ifdef CONFIG_SAE
584 if (ssid->sae_password) {
585 struct sae_password_entry *pw;
586
587 pw = os_zalloc(sizeof(*pw));
588 if (!pw)
589 return -1;
590 os_memset(pw->peer_addr, 0xff, ETH_ALEN);
591 pw->password = os_strdup(ssid->sae_password);
592 if (!pw->password) {
593 os_free(pw);
594 return -1;
595 }
596 if (ssid->sae_password_id) {
597 pw->identifier = os_strdup(ssid->sae_password_id);
598 if (!pw->identifier) {
599 str_clear_free(pw->password);
600 os_free(pw);
601 return -1;
602 }
603 }
604
605 pw->next = bss->sae_passwords;
606 bss->sae_passwords = pw;
607 }
608
Hai Shaloma20dcd72022-02-04 13:43:00 -0800609 if (ssid->sae_pwe != DEFAULT_SAE_PWE)
610 bss->sae_pwe = ssid->sae_pwe;
611 else
612 bss->sae_pwe = wpa_s->conf->sae_pwe;
Hai Shalomc3565922019-10-28 11:58:20 -0700613#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700614
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700615 if (wpa_s->conf->go_interworking) {
616 wpa_printf(MSG_DEBUG,
617 "P2P: Enable Interworking with access_network_type: %d",
618 wpa_s->conf->go_access_network_type);
619 bss->interworking = wpa_s->conf->go_interworking;
620 bss->access_network_type = wpa_s->conf->go_access_network_type;
621 bss->internet = wpa_s->conf->go_internet;
622 if (wpa_s->conf->go_venue_group) {
623 wpa_printf(MSG_DEBUG,
624 "P2P: Venue group: %d Venue type: %d",
625 wpa_s->conf->go_venue_group,
626 wpa_s->conf->go_venue_type);
627 bss->venue_group = wpa_s->conf->go_venue_group;
628 bss->venue_type = wpa_s->conf->go_venue_type;
629 bss->venue_info_set = 1;
630 }
631 }
632
Dmitry Shmidt04949592012-07-19 12:16:46 -0700633 if (ssid->ap_max_inactivity)
634 bss->ap_max_inactivity = ssid->ap_max_inactivity;
635
636 if (ssid->dtim_period)
637 bss->dtim_period = ssid->dtim_period;
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -0800638 else if (wpa_s->conf->dtim_period)
639 bss->dtim_period = wpa_s->conf->dtim_period;
640
641 if (ssid->beacon_int)
642 conf->beacon_int = ssid->beacon_int;
643 else if (wpa_s->conf->beacon_int)
644 conf->beacon_int = wpa_s->conf->beacon_int;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700645
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800646#ifdef CONFIG_P2P
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800647 if (ssid->mode == WPAS_MODE_P2P_GO ||
648 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
649 if (wpa_s->conf->p2p_go_ctwindow > conf->beacon_int) {
650 wpa_printf(MSG_INFO,
651 "CTWindow (%d) is bigger than beacon interval (%d) - avoid configuring it",
652 wpa_s->conf->p2p_go_ctwindow,
653 conf->beacon_int);
654 conf->p2p_go_ctwindow = 0;
655 } else {
656 conf->p2p_go_ctwindow = wpa_s->conf->p2p_go_ctwindow;
657 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800658 }
659#endif /* CONFIG_P2P */
660
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800661 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
662 bss->rsn_pairwise = bss->wpa_pairwise;
663 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
664 bss->rsn_pairwise);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700665
Hai Shalomfdcde762020-04-02 11:19:20 -0700666 if (bss->wpa && bss->ieee802_1x) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700667 bss->ssid.security_policy = SECURITY_WPA;
Hai Shalomfdcde762020-04-02 11:19:20 -0700668 } else if (bss->wpa) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700669 bss->ssid.security_policy = SECURITY_WPA_PSK;
Hai Shalomfdcde762020-04-02 11:19:20 -0700670#ifdef CONFIG_WEP
671 } else if (bss->ieee802_1x) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800672 int cipher = WPA_CIPHER_NONE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700673 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
674 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800675 if (bss->default_wep_key_len)
676 cipher = bss->default_wep_key_len >= 13 ?
677 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
678 bss->wpa_group = cipher;
679 bss->wpa_pairwise = cipher;
680 bss->rsn_pairwise = cipher;
681 } else if (bss->ssid.wep.keys_set) {
682 int cipher = WPA_CIPHER_WEP40;
683 if (bss->ssid.wep.len[0] >= 13)
684 cipher = WPA_CIPHER_WEP104;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700685 bss->ssid.security_policy = SECURITY_STATIC_WEP;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800686 bss->wpa_group = cipher;
687 bss->wpa_pairwise = cipher;
688 bss->rsn_pairwise = cipher;
Hai Shalomfdcde762020-04-02 11:19:20 -0700689#endif /* CONFIG_WEP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800690 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700691 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800692 bss->wpa_group = WPA_CIPHER_NONE;
693 bss->wpa_pairwise = WPA_CIPHER_NONE;
694 bss->rsn_pairwise = WPA_CIPHER_NONE;
695 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700696
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700697 if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
698 (bss->wpa_group == WPA_CIPHER_CCMP ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800699 bss->wpa_group == WPA_CIPHER_GCMP ||
700 bss->wpa_group == WPA_CIPHER_CCMP_256 ||
701 bss->wpa_group == WPA_CIPHER_GCMP_256)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700702 /*
703 * Strong ciphers do not need frequent rekeying, so increase
704 * the default GTK rekeying period to 24 hours.
705 */
706 bss->wpa_group_rekey = 86400;
707 }
708
Sunil Ravi38ad1ed2023-01-17 23:58:31 +0000709 if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT) {
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700710 bss->ieee80211w = ssid->ieee80211w;
Sunil Ravi38ad1ed2023-01-17 23:58:31 +0000711 } else if (wpa_s->conf->pmf != MGMT_FRAME_PROTECTION_DEFAULT) {
712 if (ssid->mode == WPAS_MODE_AP)
713 bss->ieee80211w = wpa_s->conf->pmf;
714 }
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700715
Hai Shalom74f70d42019-02-11 14:42:39 -0800716#ifdef CONFIG_OCV
717 bss->ocv = ssid->ocv;
718#endif /* CONFIG_OCV */
719
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700720#ifdef CONFIG_WPS
721 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800722 * Enable WPS by default for open and WPA/WPA2-Personal network, but
723 * require user interaction to actually use it. Only the internal
724 * Registrar is supported.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700725 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800726 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
727 bss->ssid.security_policy != SECURITY_PLAINTEXT)
728 goto no_wps;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800729 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800730 (!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ||
731 !(bss->wpa & 2)))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800732 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
733 * configuration */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700734 if (ssid->wps_disabled)
735 goto no_wps;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700736 bss->eap_server = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700737
738 if (!ssid->ignore_broadcast_ssid)
739 bss->wps_state = 2;
740
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700741 bss->ap_setup_locked = 2;
742 if (wpa_s->conf->config_methods)
743 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
744 os_memcpy(bss->device_type, wpa_s->conf->device_type,
745 WPS_DEV_TYPE_LEN);
746 if (wpa_s->conf->device_name) {
747 bss->device_name = os_strdup(wpa_s->conf->device_name);
748 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
749 }
750 if (wpa_s->conf->manufacturer)
751 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
752 if (wpa_s->conf->model_name)
753 bss->model_name = os_strdup(wpa_s->conf->model_name);
754 if (wpa_s->conf->model_number)
755 bss->model_number = os_strdup(wpa_s->conf->model_number);
756 if (wpa_s->conf->serial_number)
757 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
758 if (is_nil_uuid(wpa_s->conf->uuid))
759 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
760 else
761 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
762 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700763 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -0700764 if (ssid->eap.fragment_size != DEFAULT_FRAGMENT_SIZE)
765 bss->fragment_size = ssid->eap.fragment_size;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800766no_wps:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700767#endif /* CONFIG_WPS */
768
769 if (wpa_s->max_stations &&
770 wpa_s->max_stations < wpa_s->conf->max_num_sta)
771 bss->max_num_sta = wpa_s->max_stations;
772 else
773 bss->max_num_sta = wpa_s->conf->max_num_sta;
774
Roshan Pius3a1667e2018-07-03 15:17:14 -0700775 if (!bss->isolate)
776 bss->isolate = wpa_s->conf->ap_isolate;
777
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700778 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
779
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700780 if (wpa_s->conf->ap_vendor_elements) {
781 bss->vendor_elements =
782 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
783 }
Hai Shaloma20dcd72022-02-04 13:43:00 -0800784 if (wpa_s->conf->ap_assocresp_elements) {
785 bss->assocresp_elements =
786 wpabuf_dup(wpa_s->conf->ap_assocresp_elements);
787 }
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700788
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700789 bss->ftm_responder = wpa_s->conf->ftm_responder;
790 bss->ftm_initiator = wpa_s->conf->ftm_initiator;
791
Hai Shalomfdcde762020-04-02 11:19:20 -0700792 bss->transition_disable = ssid->transition_disable;
793
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700794 return 0;
795}
796
797
798static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
799{
800#ifdef CONFIG_P2P
801 struct wpa_supplicant *wpa_s = ctx;
802 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700803
804 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700805 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700806 return;
Dmitry Shmidt18463232014-01-24 12:29:41 -0800807 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
808 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700809 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
810 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700811 buf + IEEE80211_HDRLEN + 1,
812 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700813#endif /* CONFIG_P2P */
814}
815
816
817static void ap_wps_event_cb(void *ctx, enum wps_event event,
818 union wps_event_data *data)
819{
820#ifdef CONFIG_P2P
821 struct wpa_supplicant *wpa_s = ctx;
822
Jouni Malinen75ecf522011-06-27 15:19:46 -0700823 if (event == WPS_EV_FAIL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700824 struct wps_event_fail *fail = &data->fail;
825
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800826 if (wpa_s->p2pdev && wpa_s->p2pdev != wpa_s &&
Jouni Malinen75ecf522011-06-27 15:19:46 -0700827 wpa_s == wpa_s->global->p2p_group_formation) {
828 /*
829 * src/ap/wps_hostapd.c has already sent this on the
830 * main interface, so only send on the parent interface
831 * here if needed.
832 */
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800833 wpa_msg(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_FAIL
Jouni Malinen75ecf522011-06-27 15:19:46 -0700834 "msg=%d config_error=%d",
835 fail->msg, fail->config_error);
836 }
837 wpas_p2p_wps_failed(wpa_s, fail);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700838 }
839#endif /* CONFIG_P2P */
840}
841
842
843static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800844 int authorized, const u8 *p2p_dev_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700845{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800846 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700847}
848
849
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700850#ifdef CONFIG_P2P
851static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
852 const u8 *psk, size_t psk_len)
853{
854
855 struct wpa_supplicant *wpa_s = ctx;
856 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
857 return;
858 wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
859}
860#endif /* CONFIG_P2P */
861
862
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700863static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
864{
865#ifdef CONFIG_P2P
866 struct wpa_supplicant *wpa_s = ctx;
867 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700868
869 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700870 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700871 return -1;
872 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
873 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700874 buf + IEEE80211_HDRLEN + 1,
875 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700876#endif /* CONFIG_P2P */
877 return 0;
878}
879
880
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800881static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700882 const u8 *bssid, const u8 *ie, size_t ie_len,
883 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700884{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700885 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700886 unsigned int freq = 0;
887
888 if (wpa_s->ap_iface)
889 freq = wpa_s->ap_iface->freq;
890
Dmitry Shmidt04949592012-07-19 12:16:46 -0700891 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700892 freq, ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700893}
894
895
896static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
897 const u8 *uuid_e)
898{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700899 struct wpa_supplicant *wpa_s = ctx;
900 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700901}
902
903
904static void wpas_ap_configured_cb(void *ctx)
905{
906 struct wpa_supplicant *wpa_s = ctx;
907
Roshan Pius3a1667e2018-07-03 15:17:14 -0700908 wpa_printf(MSG_DEBUG, "AP interface setup completed - state %s",
909 hostapd_state_text(wpa_s->ap_iface->state));
910 if (wpa_s->ap_iface->state == HAPD_IFACE_DISABLED) {
911 wpa_supplicant_ap_deinit(wpa_s);
912 return;
913 }
914
Sunil Ravi236f0f52021-06-29 11:18:20 -0700915 if (wpa_s->current_ssid) {
916 int acs = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800917
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800918#ifdef CONFIG_ACS
Sunil Ravi236f0f52021-06-29 11:18:20 -0700919 acs = wpa_s->current_ssid->acs;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800920#endif /* CONFIG_ACS */
Sunil Ravi236f0f52021-06-29 11:18:20 -0700921 if (acs || (wpa_s->assoc_freq && wpa_s->ap_iface->freq &&
Hai Shaloma20dcd72022-02-04 13:43:00 -0800922 (int) wpa_s->assoc_freq != wpa_s->ap_iface->freq)) {
Sunil Ravi236f0f52021-06-29 11:18:20 -0700923 wpa_s->assoc_freq = wpa_s->ap_iface->freq;
924 wpa_s->current_ssid->frequency = wpa_s->ap_iface->freq;
925 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700926 }
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800927
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700928 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
929
930 if (wpa_s->ap_configured_cb)
931 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
932 wpa_s->ap_configured_cb_data);
933}
934
935
936int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
937 struct wpa_ssid *ssid)
938{
939 struct wpa_driver_associate_params params;
940 struct hostapd_iface *hapd_iface;
941 struct hostapd_config *conf;
942 size_t i;
943
944 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
945 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
946 return -1;
947 }
948
949 wpa_supplicant_ap_deinit(wpa_s);
950
951 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
952 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
953
954 os_memset(&params, 0, sizeof(params));
955 params.ssid = ssid->ssid;
956 params.ssid_len = ssid->ssid_len;
957 switch (ssid->mode) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700958 case WPAS_MODE_AP:
959 case WPAS_MODE_P2P_GO:
960 case WPAS_MODE_P2P_GROUP_FORMATION:
961 params.mode = IEEE80211_MODE_AP;
962 break;
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800963 default:
964 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700965 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700966 if (ssid->frequency == 0)
967 ssid->frequency = 2462; /* default channel 11 */
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700968 params.freq.freq = ssid->frequency;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700969
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800970 if ((ssid->mode == WPAS_MODE_AP || ssid->mode == WPAS_MODE_P2P_GO) &&
971 ssid->enable_edmg) {
Hai Shalomc3565922019-10-28 11:58:20 -0700972 u8 primary_channel;
973
974 if (ieee80211_freq_to_chan(ssid->frequency, &primary_channel) ==
975 NUM_HOSTAPD_MODES) {
976 wpa_printf(MSG_WARNING,
977 "EDMG: Failed to get the primary channel");
978 return -1;
979 }
980
981 hostapd_encode_edmg_chan(ssid->enable_edmg, ssid->edmg_channel,
982 primary_channel, &params.freq.edmg);
983 }
984
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800985 params.wpa_proto = ssid->proto;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700986 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
987 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800988 else if (ssid->key_mgmt & WPA_KEY_MGMT_SAE)
989 wpa_s->key_mgmt = WPA_KEY_MGMT_SAE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700990 else
991 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800992 params.key_mgmt_suite = wpa_s->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700993
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800994 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
995 1);
996 if (wpa_s->pairwise_cipher < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700997 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
998 "cipher.");
999 return -1;
1000 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001001 params.pairwise_suite = wpa_s->pairwise_cipher;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001002 params.group_suite = params.pairwise_suite;
1003
1004#ifdef CONFIG_P2P
1005 if (ssid->mode == WPAS_MODE_P2P_GO ||
1006 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
1007 params.p2p = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001008#endif /* CONFIG_P2P */
1009
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001010 if (wpa_s->p2pdev->set_ap_uapsd)
1011 params.uapsd = wpa_s->p2pdev->ap_uapsd;
Dmitry Shmidtec58b162014-02-19 12:44:18 -08001012 else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
1013 params.uapsd = 1; /* mandatory for P2P GO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001014 else
1015 params.uapsd = -1;
1016
Roshan Pius3a1667e2018-07-03 15:17:14 -07001017 if (ieee80211_is_dfs(params.freq.freq, wpa_s->hw.modes,
1018 wpa_s->hw.num_modes))
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001019 params.freq.freq = 0; /* set channel after CAC */
1020
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001021 if (params.p2p)
1022 wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_GO);
1023 else
1024 wpa_drv_get_ext_capa(wpa_s, WPA_IF_AP_BSS);
1025
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001026 if (wpa_drv_associate(wpa_s, &params) < 0) {
1027 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
1028 return -1;
1029 }
1030
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001031 wpa_s->ap_iface = hapd_iface = hostapd_alloc_iface();
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001032 if (hapd_iface == NULL)
1033 return -1;
1034 hapd_iface->owner = wpa_s;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001035 hapd_iface->drv_flags = wpa_s->drv_flags;
1036 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001037 hapd_iface->extended_capa = wpa_s->extended_capa;
1038 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
1039 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
Sunil Ravia04bd252022-05-02 22:54:18 -07001040 hapd_iface->drv_max_acl_mac_addrs = wpa_s->drv_max_acl_mac_addrs;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001041
1042 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
1043 if (conf == NULL) {
1044 wpa_supplicant_ap_deinit(wpa_s);
1045 return -1;
1046 }
1047
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001048 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
1049 wpa_s->conf->wmm_ac_params,
1050 sizeof(wpa_s->conf->wmm_ac_params));
1051
Hai Shalom899fcc72020-10-19 14:38:18 -07001052 os_memcpy(wpa_s->ap_iface->conf->tx_queue, wpa_s->conf->tx_queue,
1053 sizeof(wpa_s->conf->tx_queue));
1054
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001055 if (params.uapsd > 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001056 conf->bss[0]->wmm_enabled = 1;
1057 conf->bss[0]->wmm_uapsd = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001058 }
1059
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001060 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
1061 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
1062 wpa_supplicant_ap_deinit(wpa_s);
1063 return -1;
1064 }
1065
1066#ifdef CONFIG_P2P
1067 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001068 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001069 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001070 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001071 P2P_GROUP_FORMATION;
1072#endif /* CONFIG_P2P */
1073
1074 hapd_iface->num_bss = conf->num_bss;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001075 hapd_iface->bss = os_calloc(conf->num_bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001076 sizeof(struct hostapd_data *));
1077 if (hapd_iface->bss == NULL) {
1078 wpa_supplicant_ap_deinit(wpa_s);
1079 return -1;
1080 }
1081
1082 for (i = 0; i < conf->num_bss; i++) {
1083 hapd_iface->bss[i] =
1084 hostapd_alloc_bss_data(hapd_iface, conf,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001085 conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001086 if (hapd_iface->bss[i] == NULL) {
1087 wpa_supplicant_ap_deinit(wpa_s);
1088 return -1;
1089 }
1090
1091 hapd_iface->bss[i]->msg_ctx = wpa_s;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001092 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->p2pdev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001093 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
1094 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
1095 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
1096 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
1097 hostapd_register_probereq_cb(hapd_iface->bss[i],
1098 ap_probe_req_rx, wpa_s);
1099 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
1100 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
1101 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
1102 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
1103 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
1104 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
1105#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001106 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
1107 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001108 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001109 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
1110 ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001111#endif /* CONFIG_P2P */
1112 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
1113 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001114#ifdef CONFIG_TESTING_OPTIONS
1115 hapd_iface->bss[i]->ext_eapol_frame_io =
1116 wpa_s->ext_eapol_frame_io;
1117#endif /* CONFIG_TESTING_OPTIONS */
Sunil Ravia04bd252022-05-02 22:54:18 -07001118
1119#ifdef CONFIG_WNM_AP
1120 if (ssid->mode == WPAS_MODE_AP)
1121 hapd_iface->bss[i]->conf->bss_transition = 1;
1122#endif /* CONFIG_WNM_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001123 }
1124
1125 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
1126 hapd_iface->bss[0]->driver = wpa_s->driver;
1127 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
1128
1129 wpa_s->current_ssid = ssid;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001130 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001131 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
1132 wpa_s->assoc_freq = ssid->frequency;
Hai Shalomc3565922019-10-28 11:58:20 -07001133 wpa_s->ap_iface->conf->enable_edmg = ssid->enable_edmg;
1134 wpa_s->ap_iface->conf->edmg_channel = ssid->edmg_channel;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001135
Roshan Pius3a1667e2018-07-03 15:17:14 -07001136#if defined(CONFIG_P2P) && defined(CONFIG_ACS)
1137 if (wpa_s->p2p_go_do_acs) {
1138 wpa_s->ap_iface->conf->channel = 0;
1139 wpa_s->ap_iface->conf->hw_mode = wpa_s->p2p_go_acs_band;
1140 ssid->acs = 1;
1141 }
1142#endif /* CONFIG_P2P && CONFIG_ACS */
1143
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001144 if (hostapd_setup_interface(wpa_s->ap_iface)) {
1145 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
1146 wpa_supplicant_ap_deinit(wpa_s);
1147 return -1;
1148 }
1149
1150 return 0;
1151}
1152
1153
1154void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
1155{
1156#ifdef CONFIG_WPS
1157 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1158#endif /* CONFIG_WPS */
1159
1160 if (wpa_s->ap_iface == NULL)
1161 return;
1162
1163 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001164 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001165 wpa_s->assoc_freq = 0;
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07001166 wpas_p2p_ap_deinit(wpa_s);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001167 wpa_s->ap_iface->driver_ap_teardown =
1168 !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
1169
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001170 hostapd_interface_deinit(wpa_s->ap_iface);
1171 hostapd_interface_free(wpa_s->ap_iface);
1172 wpa_s->ap_iface = NULL;
1173 wpa_drv_deinit_ap(wpa_s);
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07001174 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1175 " reason=%d locally_generated=1",
1176 MAC2STR(wpa_s->own_addr), WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001177}
1178
1179
1180void ap_tx_status(void *ctx, const u8 *addr,
1181 const u8 *buf, size_t len, int ack)
1182{
1183#ifdef NEED_AP_MLME
1184 struct wpa_supplicant *wpa_s = ctx;
1185 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
1186#endif /* NEED_AP_MLME */
1187}
1188
1189
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001190void ap_eapol_tx_status(void *ctx, const u8 *dst,
1191 const u8 *data, size_t len, int ack)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001192{
1193#ifdef NEED_AP_MLME
1194 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001195 if (!wpa_s->ap_iface)
1196 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001197 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
1198#endif /* NEED_AP_MLME */
1199}
1200
1201
1202void ap_client_poll_ok(void *ctx, const u8 *addr)
1203{
1204#ifdef NEED_AP_MLME
1205 struct wpa_supplicant *wpa_s = ctx;
1206 if (wpa_s->ap_iface)
1207 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
1208#endif /* NEED_AP_MLME */
1209}
1210
1211
1212void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
1213{
1214#ifdef NEED_AP_MLME
1215 struct wpa_supplicant *wpa_s = ctx;
1216 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001217#endif /* NEED_AP_MLME */
1218}
1219
1220
1221void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
1222{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001223#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001224 struct wpa_supplicant *wpa_s = ctx;
1225 struct hostapd_frame_info fi;
1226 os_memset(&fi, 0, sizeof(fi));
Hai Shaloma20dcd72022-02-04 13:43:00 -08001227 fi.freq = rx_mgmt->freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001228 fi.datarate = rx_mgmt->datarate;
1229 fi.ssi_signal = rx_mgmt->ssi_signal;
1230 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
1231 rx_mgmt->frame_len, &fi);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001232#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001233}
1234
1235
1236void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
1237{
1238#ifdef NEED_AP_MLME
1239 struct wpa_supplicant *wpa_s = ctx;
1240 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
1241#endif /* NEED_AP_MLME */
1242}
1243
1244
1245void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
Sunil8cd6f4d2022-06-28 18:40:46 +00001246 const u8 *src_addr, const u8 *buf, size_t len,
1247 enum frame_encryption encrypted)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001248{
Sunil8cd6f4d2022-06-28 18:40:46 +00001249 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len,
1250 encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001251}
1252
1253
1254#ifdef CONFIG_WPS
1255
1256int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
1257 const u8 *p2p_dev_addr)
1258{
1259 if (!wpa_s->ap_iface)
1260 return -1;
1261 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
1262 p2p_dev_addr);
1263}
1264
1265
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001266int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
1267{
1268 struct wps_registrar *reg;
1269 int reg_sel = 0, wps_sta = 0;
1270
1271 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
1272 return -1;
1273
1274 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
1275 reg_sel = wps_registrar_wps_cancel(reg);
1276 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
Dmitry Shmidt04949592012-07-19 12:16:46 -07001277 ap_sta_wps_cancel, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001278
1279 if (!reg_sel && !wps_sta) {
1280 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
1281 "time");
1282 return -1;
1283 }
1284
1285 /*
1286 * There are 2 cases to return wps cancel as success:
1287 * 1. When wps cancel was initiated but no connection has been
1288 * established with client yet.
1289 * 2. Client is in the middle of exchanging WPS messages.
1290 */
1291
1292 return 0;
1293}
1294
1295
1296int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001297 const char *pin, char *buf, size_t buflen,
1298 int timeout)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001299{
1300 int ret, ret_len = 0;
1301
1302 if (!wpa_s->ap_iface)
1303 return -1;
1304
1305 if (pin == NULL) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001306 unsigned int rpin;
1307
1308 if (wps_generate_pin(&rpin) < 0)
1309 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001310 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001311 if (os_snprintf_error(buflen, ret_len))
1312 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001313 pin = buf;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001314 } else if (buf) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001315 ret_len = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001316 if (os_snprintf_error(buflen, ret_len))
1317 return -1;
1318 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001319
1320 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001321 timeout);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001322 if (ret)
1323 return -1;
1324 return ret_len;
1325}
1326
1327
1328static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
1329{
1330 struct wpa_supplicant *wpa_s = eloop_data;
1331 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
1332 wpas_wps_ap_pin_disable(wpa_s);
1333}
1334
1335
1336static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
1337{
1338 struct hostapd_data *hapd;
1339
1340 if (wpa_s->ap_iface == NULL)
1341 return;
1342 hapd = wpa_s->ap_iface->bss[0];
1343 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
1344 hapd->ap_pin_failures = 0;
1345 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1346 if (timeout > 0)
1347 eloop_register_timeout(timeout, 0,
1348 wpas_wps_ap_pin_timeout, wpa_s, NULL);
1349}
1350
1351
1352void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
1353{
1354 struct hostapd_data *hapd;
1355
1356 if (wpa_s->ap_iface == NULL)
1357 return;
1358 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
1359 hapd = wpa_s->ap_iface->bss[0];
1360 os_free(hapd->conf->ap_pin);
1361 hapd->conf->ap_pin = NULL;
1362 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1363}
1364
1365
1366const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
1367{
1368 struct hostapd_data *hapd;
1369 unsigned int pin;
1370 char pin_txt[9];
1371
1372 if (wpa_s->ap_iface == NULL)
1373 return NULL;
1374 hapd = wpa_s->ap_iface->bss[0];
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001375 if (wps_generate_pin(&pin) < 0)
1376 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001377 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001378 os_free(hapd->conf->ap_pin);
1379 hapd->conf->ap_pin = os_strdup(pin_txt);
1380 if (hapd->conf->ap_pin == NULL)
1381 return NULL;
1382 wpas_wps_ap_pin_enable(wpa_s, timeout);
1383
1384 return hapd->conf->ap_pin;
1385}
1386
1387
1388const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
1389{
1390 struct hostapd_data *hapd;
1391 if (wpa_s->ap_iface == NULL)
1392 return NULL;
1393 hapd = wpa_s->ap_iface->bss[0];
1394 return hapd->conf->ap_pin;
1395}
1396
1397
1398int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
1399 int timeout)
1400{
1401 struct hostapd_data *hapd;
1402 char pin_txt[9];
1403 int ret;
1404
1405 if (wpa_s->ap_iface == NULL)
1406 return -1;
1407 hapd = wpa_s->ap_iface->bss[0];
1408 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001409 if (os_snprintf_error(sizeof(pin_txt), ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001410 return -1;
1411 os_free(hapd->conf->ap_pin);
1412 hapd->conf->ap_pin = os_strdup(pin_txt);
1413 if (hapd->conf->ap_pin == NULL)
1414 return -1;
1415 wpas_wps_ap_pin_enable(wpa_s, timeout);
1416
1417 return 0;
1418}
1419
1420
1421void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
1422{
1423 struct hostapd_data *hapd;
1424
1425 if (wpa_s->ap_iface == NULL)
1426 return;
1427 hapd = wpa_s->ap_iface->bss[0];
1428
1429 /*
1430 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
1431 * PIN if this happens multiple times to slow down brute force attacks.
1432 */
1433 hapd->ap_pin_failures++;
1434 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
1435 hapd->ap_pin_failures);
1436 if (hapd->ap_pin_failures < 3)
1437 return;
1438
1439 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
1440 hapd->ap_pin_failures = 0;
1441 os_free(hapd->conf->ap_pin);
1442 hapd->conf->ap_pin = NULL;
1443}
1444
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001445
1446#ifdef CONFIG_WPS_NFC
1447
1448struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
1449 int ndef)
1450{
1451 struct hostapd_data *hapd;
1452
1453 if (wpa_s->ap_iface == NULL)
1454 return NULL;
1455 hapd = wpa_s->ap_iface->bss[0];
1456 return hostapd_wps_nfc_config_token(hapd, ndef);
1457}
1458
1459
1460struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
1461 int ndef)
1462{
1463 struct hostapd_data *hapd;
1464
1465 if (wpa_s->ap_iface == NULL)
1466 return NULL;
1467 hapd = wpa_s->ap_iface->bss[0];
1468 return hostapd_wps_nfc_hs_cr(hapd, ndef);
1469}
1470
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001471
1472int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
1473 const struct wpabuf *req,
1474 const struct wpabuf *sel)
1475{
1476 struct hostapd_data *hapd;
1477
1478 if (wpa_s->ap_iface == NULL)
1479 return -1;
1480 hapd = wpa_s->ap_iface->bss[0];
1481 return hostapd_wps_nfc_report_handover(hapd, req, sel);
1482}
1483
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001484#endif /* CONFIG_WPS_NFC */
1485
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001486#endif /* CONFIG_WPS */
1487
1488
1489#ifdef CONFIG_CTRL_IFACE
1490
1491int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
1492 char *buf, size_t buflen)
1493{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001494 struct hostapd_data *hapd;
1495
1496 if (wpa_s->ap_iface)
1497 hapd = wpa_s->ap_iface->bss[0];
1498 else if (wpa_s->ifmsh)
1499 hapd = wpa_s->ifmsh->bss[0];
1500 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001501 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001502 return hostapd_ctrl_iface_sta_first(hapd, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001503}
1504
1505
1506int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
1507 char *buf, size_t buflen)
1508{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001509 struct hostapd_data *hapd;
1510
1511 if (wpa_s->ap_iface)
1512 hapd = wpa_s->ap_iface->bss[0];
1513 else if (wpa_s->ifmsh)
1514 hapd = wpa_s->ifmsh->bss[0];
1515 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001516 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001517 return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001518}
1519
1520
1521int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
1522 char *buf, size_t buflen)
1523{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001524 struct hostapd_data *hapd;
1525
1526 if (wpa_s->ap_iface)
1527 hapd = wpa_s->ap_iface->bss[0];
1528 else if (wpa_s->ifmsh)
1529 hapd = wpa_s->ifmsh->bss[0];
1530 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001531 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001532 return hostapd_ctrl_iface_sta_next(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001533}
1534
1535
Dmitry Shmidt04949592012-07-19 12:16:46 -07001536int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1537 const char *txtaddr)
1538{
1539 if (wpa_s->ap_iface == NULL)
1540 return -1;
1541 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1542 txtaddr);
1543}
1544
1545
1546int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1547 const char *txtaddr)
1548{
1549 if (wpa_s->ap_iface == NULL)
1550 return -1;
1551 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1552 txtaddr);
1553}
1554
1555
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001556int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1557 size_t buflen, int verbose)
1558{
1559 char *pos = buf, *end = buf + buflen;
1560 int ret;
1561 struct hostapd_bss_config *conf;
1562
1563 if (wpa_s->ap_iface == NULL)
1564 return -1;
1565
1566 conf = wpa_s->ap_iface->bss[0]->conf;
1567 if (conf->wpa == 0)
1568 return 0;
1569
1570 ret = os_snprintf(pos, end - pos,
1571 "pairwise_cipher=%s\n"
1572 "group_cipher=%s\n"
1573 "key_mgmt=%s\n",
1574 wpa_cipher_txt(conf->rsn_pairwise),
1575 wpa_cipher_txt(conf->wpa_group),
1576 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1577 conf->wpa));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001578 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001579 return pos - buf;
1580 pos += ret;
1581 return pos - buf;
1582}
1583
Sunil Ravia04bd252022-05-02 22:54:18 -07001584
1585#ifdef CONFIG_WNM_AP
1586
1587int ap_ctrl_iface_disassoc_imminent(struct wpa_supplicant *wpa_s,
1588 const char *buf)
1589{
1590 struct hostapd_data *hapd;
1591
1592 if (wpa_s->ap_iface)
1593 hapd = wpa_s->ap_iface->bss[0];
1594 else
1595 return -1;
1596 return hostapd_ctrl_iface_disassoc_imminent(hapd, buf);
1597}
1598
1599
1600int ap_ctrl_iface_ess_disassoc(struct wpa_supplicant *wpa_s, const char *buf)
1601{
1602 struct hostapd_data *hapd;
1603
1604 if (wpa_s->ap_iface)
1605 hapd = wpa_s->ap_iface->bss[0];
1606 else
1607 return -1;
1608 return hostapd_ctrl_iface_ess_disassoc(hapd, buf);
1609}
1610
1611
1612int ap_ctrl_iface_bss_tm_req(struct wpa_supplicant *wpa_s, const char *buf)
1613{
1614 struct hostapd_data *hapd;
1615
1616 if (wpa_s->ap_iface)
1617 hapd = wpa_s->ap_iface->bss[0];
1618 else
1619 return -1;
1620 return hostapd_ctrl_iface_bss_tm_req(hapd, buf);
1621}
1622
1623#endif /* CONFIG_WNM_AP */
1624
1625
1626int ap_ctrl_iface_acl_add_mac(struct wpa_supplicant *wpa_s,
1627 enum macaddr_acl acl_type,
1628 const char *buf)
1629{
1630 struct hostapd_data *hapd;
1631
1632 if (wpa_s->ap_iface)
1633 hapd = wpa_s->ap_iface->bss[0];
1634 else
1635 return -1;
1636
1637 hapd->conf->macaddr_acl = acl_type;
1638
1639 if (acl_type == ACCEPT_UNLESS_DENIED)
1640 return hostapd_ctrl_iface_acl_add_mac(&hapd->conf->deny_mac,
1641 &hapd->conf->num_deny_mac,
1642 buf);
1643 if (acl_type == DENY_UNLESS_ACCEPTED)
1644 return hostapd_ctrl_iface_acl_add_mac(
1645 &hapd->conf->accept_mac,
1646 &hapd->conf->num_accept_mac, buf);
1647
1648 return -1;
1649}
1650
1651
1652int ap_ctrl_iface_acl_del_mac(struct wpa_supplicant *wpa_s,
1653 enum macaddr_acl acl_type,
1654 const char *buf)
1655{
1656 struct hostapd_data *hapd;
1657
1658 if (wpa_s->ap_iface)
1659 hapd = wpa_s->ap_iface->bss[0];
1660 else
1661 return -1;
1662
1663 hapd->conf->macaddr_acl = acl_type;
1664
1665 if (acl_type == ACCEPT_UNLESS_DENIED)
1666 return hostapd_ctrl_iface_acl_del_mac(&hapd->conf->deny_mac,
1667 &hapd->conf->num_deny_mac,
1668 buf);
1669 if (acl_type == DENY_UNLESS_ACCEPTED)
1670 return hostapd_ctrl_iface_acl_del_mac(
1671 &hapd->conf->accept_mac, &hapd->conf->num_accept_mac,
1672 buf);
1673
1674 return -1;
1675}
1676
1677
1678int ap_ctrl_iface_acl_show_mac(struct wpa_supplicant *wpa_s,
1679 enum macaddr_acl acl_type, char *buf,
1680 size_t buflen)
1681{
1682 struct hostapd_data *hapd;
1683
1684 if (wpa_s->ap_iface)
1685 hapd = wpa_s->ap_iface->bss[0];
1686 else
1687 return -1;
1688
1689 if (acl_type == ACCEPT_UNLESS_DENIED)
1690 return hostapd_ctrl_iface_acl_show_mac(hapd->conf->deny_mac,
1691 hapd->conf->num_deny_mac,
1692 buf, buflen);
1693 if (acl_type == DENY_UNLESS_ACCEPTED)
1694 return hostapd_ctrl_iface_acl_show_mac(
1695 hapd->conf->accept_mac, hapd->conf->num_accept_mac,
1696 buf, buflen);
1697
1698 return -1;
1699}
1700
1701
1702void ap_ctrl_iface_acl_clear_list(struct wpa_supplicant *wpa_s,
1703 enum macaddr_acl acl_type)
1704{
1705 struct hostapd_data *hapd;
1706
1707 if (wpa_s->ap_iface)
1708 hapd = wpa_s->ap_iface->bss[0];
1709 else
1710 return;
1711
1712 hapd->conf->macaddr_acl = acl_type;
1713
1714 if (acl_type == ACCEPT_UNLESS_DENIED)
1715 hostapd_ctrl_iface_acl_clear_list(&hapd->conf->deny_mac,
1716 &hapd->conf->num_deny_mac);
1717 else if (acl_type == DENY_UNLESS_ACCEPTED)
1718 hostapd_ctrl_iface_acl_clear_list(&hapd->conf->accept_mac,
1719 &hapd->conf->num_accept_mac);
1720}
1721
1722
1723int ap_ctrl_iface_disassoc_deny_mac(struct wpa_supplicant *wpa_s)
1724{
1725 struct hostapd_data *hapd;
1726
1727 if (wpa_s->ap_iface)
1728 hapd = wpa_s->ap_iface->bss[0];
1729 else
1730 return -1;
1731
1732 return hostapd_disassoc_deny_mac(hapd);
1733}
1734
1735
1736int ap_ctrl_iface_disassoc_accept_mac(struct wpa_supplicant *wpa_s)
1737{
1738 struct hostapd_data *hapd;
1739
1740 if (wpa_s->ap_iface)
1741 hapd = wpa_s->ap_iface->bss[0];
1742 else
1743 return -1;
1744
1745 return hostapd_disassoc_accept_mac(hapd);
1746}
1747
1748
1749int ap_ctrl_iface_set_acl(struct wpa_supplicant *wpa_s)
1750{
1751 struct hostapd_data *hapd;
1752
1753 if (wpa_s->ap_iface)
1754 hapd = wpa_s->ap_iface->bss[0];
1755 else
1756 return -1;
1757
1758 return hostapd_set_acl(hapd);
1759}
1760
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001761#endif /* CONFIG_CTRL_IFACE */
1762
1763
1764int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1765{
1766 struct hostapd_iface *iface = wpa_s->ap_iface;
1767 struct wpa_ssid *ssid = wpa_s->current_ssid;
1768 struct hostapd_data *hapd;
1769
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001770 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1771 ssid->mode == WPAS_MODE_INFRA ||
1772 ssid->mode == WPAS_MODE_IBSS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001773 return -1;
1774
1775#ifdef CONFIG_P2P
1776 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001777 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001778 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001779 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001780 P2P_GROUP_FORMATION;
1781#endif /* CONFIG_P2P */
1782
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001783 hapd = iface->bss[0];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001784 if (hapd->drv_priv == NULL)
1785 return -1;
1786 ieee802_11_set_beacons(iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001787 hostapd_set_ap_wps_ie(hapd);
1788
1789 return 0;
1790}
1791
1792
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001793int ap_switch_channel(struct wpa_supplicant *wpa_s,
1794 struct csa_settings *settings)
1795{
1796#ifdef NEED_AP_MLME
Hai Shalom899fcc72020-10-19 14:38:18 -07001797 struct hostapd_iface *iface = NULL;
1798
1799 if (wpa_s->ap_iface)
1800 iface = wpa_s->ap_iface;
1801 else if (wpa_s->ifmsh)
1802 iface = wpa_s->ifmsh;
1803
1804 if (!iface || !iface->bss[0])
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001805 return -1;
1806
Hai Shalom899fcc72020-10-19 14:38:18 -07001807 return hostapd_switch_channel(iface->bss[0], settings);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001808#else /* NEED_AP_MLME */
1809 return -1;
1810#endif /* NEED_AP_MLME */
1811}
1812
1813
Dmitry Shmidt83474442015-04-15 13:47:09 -07001814#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001815int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1816{
1817 struct csa_settings settings;
1818 int ret = hostapd_parse_csa_settings(pos, &settings);
1819
1820 if (ret)
1821 return ret;
1822
1823 return ap_switch_channel(wpa_s, &settings);
1824}
Dmitry Shmidt83474442015-04-15 13:47:09 -07001825#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001826
1827
Dmitry Shmidt04949592012-07-19 12:16:46 -07001828void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
Hai Shalom81f62d82019-07-22 12:10:00 -07001829 int offset, int width, int cf1, int cf2, int finished)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001830{
Hai Shalom74f70d42019-02-11 14:42:39 -08001831 struct hostapd_iface *iface = wpa_s->ap_iface;
Hai Shalombf6e0ba2019-02-11 12:01:50 -08001832
Hai Shalom74f70d42019-02-11 14:42:39 -08001833 if (!iface)
1834 iface = wpa_s->ifmsh;
1835 if (!iface)
1836 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001837 wpa_s->assoc_freq = freq;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001838 if (wpa_s->current_ssid)
1839 wpa_s->current_ssid->frequency = freq;
Hai Shalom74f70d42019-02-11 14:42:39 -08001840 hostapd_event_ch_switch(iface->bss[0], freq, ht,
Hai Shalom81f62d82019-07-22 12:10:00 -07001841 offset, width, cf1, cf2, finished);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001842}
1843
1844
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001845int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1846 const u8 *addr)
1847{
1848 struct hostapd_data *hapd;
1849 struct hostapd_bss_config *conf;
1850
1851 if (!wpa_s->ap_iface)
1852 return -1;
1853
1854 if (addr)
1855 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1856 MAC2STR(addr));
1857 else
1858 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1859
1860 hapd = wpa_s->ap_iface->bss[0];
1861 conf = hapd->conf;
1862
1863 os_free(conf->accept_mac);
1864 conf->accept_mac = NULL;
1865 conf->num_accept_mac = 0;
1866 os_free(conf->deny_mac);
1867 conf->deny_mac = NULL;
1868 conf->num_deny_mac = 0;
1869
1870 if (addr == NULL) {
1871 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1872 return 0;
1873 }
1874
1875 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1876 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1877 if (conf->accept_mac == NULL)
1878 return -1;
1879 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1880 conf->num_accept_mac = 1;
1881
1882 return 0;
1883}
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001884
1885
1886#ifdef CONFIG_WPS_NFC
1887int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1888 const struct wpabuf *pw, const u8 *pubkey_hash)
1889{
1890 struct hostapd_data *hapd;
1891 struct wps_context *wps;
1892
1893 if (!wpa_s->ap_iface)
1894 return -1;
1895 hapd = wpa_s->ap_iface->bss[0];
1896 wps = hapd->wps;
1897
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001898 if (wpa_s->p2pdev->conf->wps_nfc_dh_pubkey == NULL ||
1899 wpa_s->p2pdev->conf->wps_nfc_dh_privkey == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001900 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1901 return -1;
1902 }
1903
1904 dh5_free(wps->dh_ctx);
1905 wpabuf_free(wps->dh_pubkey);
1906 wpabuf_free(wps->dh_privkey);
1907 wps->dh_privkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001908 wpa_s->p2pdev->conf->wps_nfc_dh_privkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001909 wps->dh_pubkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001910 wpa_s->p2pdev->conf->wps_nfc_dh_pubkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001911 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1912 wps->dh_ctx = NULL;
1913 wpabuf_free(wps->dh_pubkey);
1914 wps->dh_pubkey = NULL;
1915 wpabuf_free(wps->dh_privkey);
1916 wps->dh_privkey = NULL;
1917 return -1;
1918 }
1919 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1920 if (wps->dh_ctx == NULL)
1921 return -1;
1922
1923 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1924 pw_id,
1925 pw ? wpabuf_head(pw) : NULL,
1926 pw ? wpabuf_len(pw) : 0, 1);
1927}
1928#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001929
1930
Dmitry Shmidt83474442015-04-15 13:47:09 -07001931#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001932int wpas_ap_stop_ap(struct wpa_supplicant *wpa_s)
1933{
1934 struct hostapd_data *hapd;
1935
1936 if (!wpa_s->ap_iface)
1937 return -1;
1938 hapd = wpa_s->ap_iface->bss[0];
1939 return hostapd_ctrl_iface_stop_ap(hapd);
1940}
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001941
1942
Dmitry Shmidte4663042016-04-04 10:07:49 -07001943int wpas_ap_pmksa_cache_list(struct wpa_supplicant *wpa_s, char *buf,
1944 size_t len)
1945{
1946 size_t reply_len = 0, i;
1947 char ap_delimiter[] = "---- AP ----\n";
1948 char mesh_delimiter[] = "---- mesh ----\n";
1949 size_t dlen;
1950
1951 if (wpa_s->ap_iface) {
1952 dlen = os_strlen(ap_delimiter);
1953 if (dlen > len - reply_len)
1954 return reply_len;
1955 os_memcpy(&buf[reply_len], ap_delimiter, dlen);
1956 reply_len += dlen;
1957
1958 for (i = 0; i < wpa_s->ap_iface->num_bss; i++) {
1959 reply_len += hostapd_ctrl_iface_pmksa_list(
1960 wpa_s->ap_iface->bss[i],
1961 &buf[reply_len], len - reply_len);
1962 }
1963 }
1964
1965 if (wpa_s->ifmsh) {
1966 dlen = os_strlen(mesh_delimiter);
1967 if (dlen > len - reply_len)
1968 return reply_len;
1969 os_memcpy(&buf[reply_len], mesh_delimiter, dlen);
1970 reply_len += dlen;
1971
1972 reply_len += hostapd_ctrl_iface_pmksa_list(
1973 wpa_s->ifmsh->bss[0], &buf[reply_len],
1974 len - reply_len);
1975 }
1976
1977 return reply_len;
1978}
1979
1980
1981void wpas_ap_pmksa_cache_flush(struct wpa_supplicant *wpa_s)
1982{
1983 size_t i;
1984
1985 if (wpa_s->ap_iface) {
1986 for (i = 0; i < wpa_s->ap_iface->num_bss; i++)
1987 hostapd_ctrl_iface_pmksa_flush(wpa_s->ap_iface->bss[i]);
1988 }
1989
1990 if (wpa_s->ifmsh)
1991 hostapd_ctrl_iface_pmksa_flush(wpa_s->ifmsh->bss[0]);
1992}
Paul Stewart092955c2017-02-06 09:13:09 -08001993
1994
1995#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
1996#ifdef CONFIG_MESH
1997
1998int wpas_ap_pmksa_cache_list_mesh(struct wpa_supplicant *wpa_s, const u8 *addr,
1999 char *buf, size_t len)
2000{
2001 return hostapd_ctrl_iface_pmksa_list_mesh(wpa_s->ifmsh->bss[0], addr,
2002 &buf[0], len);
2003}
2004
2005
2006int wpas_ap_pmksa_cache_add_external(struct wpa_supplicant *wpa_s, char *cmd)
2007{
2008 struct external_pmksa_cache *entry;
2009 void *pmksa_cache;
2010
2011 pmksa_cache = hostapd_ctrl_iface_pmksa_create_entry(wpa_s->own_addr,
2012 cmd);
2013 if (!pmksa_cache)
2014 return -1;
2015
2016 entry = os_zalloc(sizeof(struct external_pmksa_cache));
2017 if (!entry)
2018 return -1;
2019
2020 entry->pmksa_cache = pmksa_cache;
2021
2022 dl_list_add(&wpa_s->mesh_external_pmksa_cache, &entry->list);
2023
2024 return 0;
2025}
2026
2027#endif /* CONFIG_MESH */
2028#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
2029
Hai Shaloma20dcd72022-02-04 13:43:00 -08002030
2031int wpas_ap_update_beacon(struct wpa_supplicant *wpa_s)
2032{
2033 struct hostapd_data *hapd;
2034
2035 if (!wpa_s->ap_iface)
2036 return -1;
2037 hapd = wpa_s->ap_iface->bss[0];
2038
2039 wpabuf_free(hapd->conf->assocresp_elements);
2040 hapd->conf->assocresp_elements = NULL;
2041 if (wpa_s->conf->ap_assocresp_elements) {
2042 hapd->conf->assocresp_elements =
2043 wpabuf_dup(wpa_s->conf->ap_assocresp_elements);
2044 }
2045
2046 wpabuf_free(hapd->conf->vendor_elements);
2047 hapd->conf->vendor_elements = NULL;
2048 if (wpa_s->conf->ap_vendor_elements) {
2049 hapd->conf->vendor_elements =
2050 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
2051 }
2052
2053 return ieee802_11_set_beacon(hapd);
2054}
2055
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002056#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte4663042016-04-04 10:07:49 -07002057
2058
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002059#ifdef NEED_AP_MLME
Roshan Pius3a1667e2018-07-03 15:17:14 -07002060void wpas_ap_event_dfs_radar_detected(struct wpa_supplicant *wpa_s,
2061 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002062{
Hai Shalom74f70d42019-02-11 14:42:39 -08002063 struct hostapd_iface *iface = wpa_s->ap_iface;
2064
2065 if (!iface)
2066 iface = wpa_s->ifmsh;
2067 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002068 return;
2069 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08002070 hostapd_dfs_radar_detected(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002071 radar->ht_enabled, radar->chan_offset,
2072 radar->chan_width,
2073 radar->cf1, radar->cf2);
2074}
2075
2076
Roshan Pius3a1667e2018-07-03 15:17:14 -07002077void wpas_ap_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
2078 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002079{
Hai Shalom74f70d42019-02-11 14:42:39 -08002080 struct hostapd_iface *iface = wpa_s->ap_iface;
2081
2082 if (!iface)
2083 iface = wpa_s->ifmsh;
2084 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002085 return;
2086 wpa_printf(MSG_DEBUG, "DFS CAC started on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08002087 hostapd_dfs_start_cac(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002088 radar->ht_enabled, radar->chan_offset,
2089 radar->chan_width, radar->cf1, radar->cf2);
2090}
2091
2092
Roshan Pius3a1667e2018-07-03 15:17:14 -07002093void wpas_ap_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
2094 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002095{
Hai Shalom74f70d42019-02-11 14:42:39 -08002096 struct hostapd_iface *iface = wpa_s->ap_iface;
2097
2098 if (!iface)
2099 iface = wpa_s->ifmsh;
2100 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002101 return;
2102 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08002103 hostapd_dfs_complete_cac(iface, 1, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002104 radar->ht_enabled, radar->chan_offset,
2105 radar->chan_width, radar->cf1, radar->cf2);
2106}
2107
2108
Roshan Pius3a1667e2018-07-03 15:17:14 -07002109void wpas_ap_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
2110 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002111{
Hai Shalom74f70d42019-02-11 14:42:39 -08002112 struct hostapd_iface *iface = wpa_s->ap_iface;
2113
2114 if (!iface)
2115 iface = wpa_s->ifmsh;
2116 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002117 return;
2118 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08002119 hostapd_dfs_complete_cac(iface, 0, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002120 radar->ht_enabled, radar->chan_offset,
2121 radar->chan_width, radar->cf1, radar->cf2);
2122}
2123
2124
Roshan Pius3a1667e2018-07-03 15:17:14 -07002125void wpas_ap_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s,
2126 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002127{
Hai Shalom74f70d42019-02-11 14:42:39 -08002128 struct hostapd_iface *iface = wpa_s->ap_iface;
2129
2130 if (!iface)
2131 iface = wpa_s->ifmsh;
2132 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002133 return;
2134 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08002135 hostapd_dfs_nop_finished(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002136 radar->ht_enabled, radar->chan_offset,
2137 radar->chan_width, radar->cf1, radar->cf2);
2138}
2139#endif /* NEED_AP_MLME */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002140
2141
2142void ap_periodic(struct wpa_supplicant *wpa_s)
2143{
2144 if (wpa_s->ap_iface)
2145 hostapd_periodic_iface(wpa_s->ap_iface);
2146}