blob: 69a0e5ee16af866f8513507a36038aafcc92c294 [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;
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000317 if (ssid->disable_ht40)
318 ssid->ht40 = 0;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700319#endif /* CONFIG_HT_OVERRIDES */
320
Sunil Ravi2a14cf12023-11-21 00:54:38 +0000321#ifdef CONFIG_VHT_OVERRIDES
322 if (ssid->disable_vht)
323 ssid->vht = 0;
324#endif /* CONFIG_VHT_OVERRIDES */
325
326#ifdef CONFIG_HE_OVERRIDES
327 if (ssid->disable_he)
328 ssid->he = 0;
329#endif /* CONFIG_HE_OVERRIDES */
330
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700331 if (!ssid->ht) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700332 wpa_printf(MSG_DEBUG,
333 "HT not enabled in network profile");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700334 conf->ieee80211n = 0;
335 conf->ht_capab = 0;
336 no_ht = 1;
337 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700338
Hai Shaloma20dcd72022-02-04 13:43:00 -0800339 if (mode && is_6ghz_freq(ssid->frequency) &&
340 conf->hw_mode == HOSTAPD_MODE_IEEE80211A) {
Sunil Raviaf8751c2023-03-29 11:35:17 -0700341 if (mode->eht_capab[wpas_mode_to_ieee80211_mode(
342 ssid->mode)].eht_supported &&
343 ssid->eht)
344 conf->ieee80211be = 1;
345
346 if (mode->he_capab[wpas_mode_to_ieee80211_mode(
347 ssid->mode)].he_supported &&
348 ssid->he)
349 conf->ieee80211ax = 1;
350
Hai Shaloma20dcd72022-02-04 13:43:00 -0800351#ifdef CONFIG_P2P
352 wpas_conf_ap_he_6ghz(wpa_s, mode, ssid, conf);
353#endif /* CONFIG_P2P */
354 } else if (!no_ht && mode && mode->ht_capab) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700355 wpa_printf(MSG_DEBUG,
356 "Enable HT support (p2p_group=%d 11a=%d ht40_hw_capab=%d ssid->ht40=%d)",
357 ssid->p2p_group,
358 conf->hw_mode == HOSTAPD_MODE_IEEE80211A,
359 !!(mode->ht_capab &
360 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET),
361 ssid->ht40);
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700362 conf->ieee80211n = 1;
Hai Shalom899fcc72020-10-19 14:38:18 -0700363
364 if (ssid->ht40 &&
365 (mode->ht_capab &
366 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
367 conf->secondary_channel = ssid->ht40;
368 else
369 conf->secondary_channel = 0;
370
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700371#ifdef CONFIG_P2P
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700372 if (ssid->p2p_group &&
373 conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700374 (mode->ht_capab &
375 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -0700376 ssid->ht40) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700377 conf->secondary_channel =
Hai Shaloma20dcd72022-02-04 13:43:00 -0800378 wpas_p2p_get_sec_channel_offset_40mhz(
379 wpa_s, mode, conf->channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700380 wpa_printf(MSG_DEBUG,
381 "HT secondary channel offset %d for P2P group",
382 conf->secondary_channel);
Hai Shalom60840252021-02-19 19:02:11 -0800383 } else if (ssid->p2p_group && conf->secondary_channel &&
384 conf->hw_mode != HOSTAPD_MODE_IEEE80211A) {
385 /* This ended up trying to configure invalid
386 * 2.4 GHz channels (e.g., HT40+ on channel 11)
387 * in some cases, so clear the secondary channel
388 * configuration now to avoid such cases that
389 * would lead to group formation failures. */
390 wpa_printf(MSG_DEBUG,
391 "Disable HT secondary channel for P2P group on 2.4 GHz");
392 conf->secondary_channel = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700393 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700394#endif /* CONFIG_P2P */
395
396 if (!ssid->p2p_group &&
397 (mode->ht_capab &
Roshan Pius3a1667e2018-07-03 15:17:14 -0700398 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700399 conf->secondary_channel = ssid->ht40;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700400 wpa_printf(MSG_DEBUG,
401 "HT secondary channel offset %d for AP",
402 conf->secondary_channel);
403 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700404
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700405 if (conf->secondary_channel)
406 conf->ht_capab |=
407 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800408
409 /*
Hai Shaloma20dcd72022-02-04 13:43:00 -0800410 * include capabilities that won't cause issues
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800411 * to connecting stations, while leaving the current
412 * capabilities intact (currently disabled SMPS).
413 */
414 conf->ht_capab |= mode->ht_capab &
415 (HT_CAP_INFO_GREEN_FIELD |
416 HT_CAP_INFO_SHORT_GI20MHZ |
417 HT_CAP_INFO_SHORT_GI40MHZ |
418 HT_CAP_INFO_RX_STBC_MASK |
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800419 HT_CAP_INFO_TX_STBC |
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800420 HT_CAP_INFO_MAX_AMSDU_SIZE);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700421
Hai Shalom899fcc72020-10-19 14:38:18 -0700422 /* check this before VHT, because setting oper chan
423 * width and friends is the same call for HE and VHT
424 * and checks if conf->ieee8021ax == 1 */
Sunil Raviaf8751c2023-03-29 11:35:17 -0700425 if (mode->eht_capab[wpas_mode_to_ieee80211_mode(
426 ssid->mode)].eht_supported &&
427 ssid->eht)
428 conf->ieee80211be = 1;
429
Hai Shalom899fcc72020-10-19 14:38:18 -0700430 if (mode->he_capab[wpas_mode_to_ieee80211_mode(
431 ssid->mode)].he_supported &&
432 ssid->he)
433 conf->ieee80211ax = 1;
434
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700435 if (mode->vht_capab && ssid->vht) {
436 conf->ieee80211ac = 1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800437 conf->vht_capab |= mode->vht_capab;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700438 wpas_conf_ap_vht(wpa_s, ssid, conf, mode);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700439 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800440 }
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700441 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800442
Sunil Ravi99c035e2024-07-12 01:42:03 +0000443#ifdef CONFIG_P2P
444 if (ssid->p2p_group && wpa_s->p2p_go_no_pri_sec_switch) {
Sunil Ravi77a0f092022-10-03 00:53:41 +0000445 conf->no_pri_sec_switch = 1;
Sunil Ravi99c035e2024-07-12 01:42:03 +0000446 return 0;
447 }
448#endif /* CONFIG_P2P */
449
450 if (conf->secondary_channel) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800451 struct wpa_supplicant *iface;
452
453 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
454 {
455 if (iface == wpa_s ||
456 iface->wpa_state < WPA_AUTHENTICATING ||
457 (int) iface->assoc_freq != ssid->frequency)
458 continue;
459
460 /*
461 * Do not allow 40 MHz co-ex PRI/SEC switch to force us
462 * to change our PRI channel since we have an existing,
463 * concurrent connection on that channel and doing
464 * multi-channel concurrency is likely to cause more
465 * harm than using different PRI/SEC selection in
466 * environment with multiple BSSes on these two channels
467 * with mixed 20 MHz or PRI channel selection.
468 */
469 conf->no_pri_sec_switch = 1;
470 }
471 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800472
473 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800474}
475
476
477static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
478 struct wpa_ssid *ssid,
479 struct hostapd_config *conf)
480{
481 struct hostapd_bss_config *bss = conf->bss[0];
482
483 conf->driver = wpa_s->driver;
484
485 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
486
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800487 if (wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800488 return -1;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700489
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700490 if (ssid->pbss > 1) {
491 wpa_printf(MSG_ERROR, "Invalid pbss value(%d) for AP mode",
492 ssid->pbss);
493 return -1;
494 }
495 bss->pbss = ssid->pbss;
496
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800497#ifdef CONFIG_ACS
498 if (ssid->acs) {
499 /* Setting channel to 0 in order to enable ACS */
500 conf->channel = 0;
501 wpa_printf(MSG_DEBUG, "Use automatic channel selection");
502 }
503#endif /* CONFIG_ACS */
504
Roshan Pius3a1667e2018-07-03 15:17:14 -0700505 if (ieee80211_is_dfs(ssid->frequency, wpa_s->hw.modes,
506 wpa_s->hw.num_modes) && wpa_s->conf->country[0]) {
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800507 conf->ieee80211h = 1;
508 conf->ieee80211d = 1;
509 conf->country[0] = wpa_s->conf->country[0];
510 conf->country[1] = wpa_s->conf->country[1];
Paul Stewart092955c2017-02-06 09:13:09 -0800511 conf->country[2] = ' ';
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800512 }
513
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700514#ifdef CONFIG_P2P
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700515 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
516 (ssid->mode == WPAS_MODE_P2P_GO ||
517 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700518 /* Remove 802.11b rates from supported and basic rate sets */
519 int *list = os_malloc(4 * sizeof(int));
520 if (list) {
521 list[0] = 60;
522 list[1] = 120;
523 list[2] = 240;
524 list[3] = -1;
525 }
526 conf->basic_rates = list;
527
528 list = os_malloc(9 * sizeof(int));
529 if (list) {
530 list[0] = 60;
531 list[1] = 90;
532 list[2] = 120;
533 list[3] = 180;
534 list[4] = 240;
535 list[5] = 360;
536 list[6] = 480;
537 list[7] = 540;
538 list[8] = -1;
539 }
540 conf->supported_rates = list;
Hai Shalom021b0b52019-04-10 11:17:58 -0700541 }
542
Hai Shalom74f70d42019-02-11 14:42:39 -0800543#ifdef CONFIG_IEEE80211AX
Hai Shalom021b0b52019-04-10 11:17:58 -0700544 if (ssid->mode == WPAS_MODE_P2P_GO ||
545 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Hai Shalom74f70d42019-02-11 14:42:39 -0800546 conf->ieee80211ax = ssid->he;
547#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800548
549 bss->isolate = !wpa_s->conf->p2p_intra_bss;
Hai Shalomfdcde762020-04-02 11:19:20 -0700550 bss->extended_key_id = wpa_s->conf->extended_key_id;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700551 bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
Hai Shalomfdcde762020-04-02 11:19:20 -0700552 bss->wpa_deny_ptk0_rekey = ssid->wpa_deny_ptk0_rekey;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800553
554 if (ssid->p2p_group) {
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800555 os_memcpy(bss->ip_addr_go, wpa_s->p2pdev->conf->ip_addr_go, 4);
556 os_memcpy(bss->ip_addr_mask, wpa_s->p2pdev->conf->ip_addr_mask,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800557 4);
558 os_memcpy(bss->ip_addr_start,
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800559 wpa_s->p2pdev->conf->ip_addr_start, 4);
560 os_memcpy(bss->ip_addr_end, wpa_s->p2pdev->conf->ip_addr_end,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800561 4);
562 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700563#endif /* CONFIG_P2P */
564
565 if (ssid->ssid_len == 0) {
566 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
567 return -1;
568 }
569 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700570 bss->ssid.ssid_len = ssid->ssid_len;
571 bss->ssid.ssid_set = 1;
572
Dmitry Shmidt04949592012-07-19 12:16:46 -0700573 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
574
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800575 if (ssid->auth_alg)
576 bss->auth_algs = ssid->auth_alg;
577
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700578 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
579 bss->wpa = ssid->proto;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700580 if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
581 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
582 else
583 bss->wpa_key_mgmt = ssid->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700584 bss->wpa_pairwise = ssid->pairwise_cipher;
Hai Shalomc3565922019-10-28 11:58:20 -0700585 if (wpa_key_mgmt_sae(bss->wpa_key_mgmt) && ssid->passphrase) {
586 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
587 } else if (ssid->psk_set) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800588 bin_clear_free(bss->ssid.wpa_psk, sizeof(*bss->ssid.wpa_psk));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700589 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
590 if (bss->ssid.wpa_psk == NULL)
591 return -1;
592 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
593 bss->ssid.wpa_psk->group = 1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700594 bss->ssid.wpa_psk_set = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800595 } else if (ssid->passphrase) {
596 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
Hai Shalomfdcde762020-04-02 11:19:20 -0700597#ifdef CONFIG_WEP
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800598 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
599 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
600 struct hostapd_wep_keys *wep = &bss->ssid.wep;
601 int i;
602 for (i = 0; i < NUM_WEP_KEYS; i++) {
603 if (ssid->wep_key_len[i] == 0)
604 continue;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700605 wep->key[i] = os_memdup(ssid->wep_key[i],
606 ssid->wep_key_len[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800607 if (wep->key[i] == NULL)
608 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800609 wep->len[i] = ssid->wep_key_len[i];
610 }
611 wep->idx = ssid->wep_tx_keyidx;
612 wep->keys_set = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700613#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700614 }
Hai Shalomc3565922019-10-28 11:58:20 -0700615#ifdef CONFIG_SAE
616 if (ssid->sae_password) {
617 struct sae_password_entry *pw;
618
619 pw = os_zalloc(sizeof(*pw));
620 if (!pw)
621 return -1;
622 os_memset(pw->peer_addr, 0xff, ETH_ALEN);
623 pw->password = os_strdup(ssid->sae_password);
624 if (!pw->password) {
625 os_free(pw);
626 return -1;
627 }
628 if (ssid->sae_password_id) {
629 pw->identifier = os_strdup(ssid->sae_password_id);
630 if (!pw->identifier) {
631 str_clear_free(pw->password);
632 os_free(pw);
633 return -1;
634 }
635 }
636
637 pw->next = bss->sae_passwords;
638 bss->sae_passwords = pw;
639 }
640
Hai Shaloma20dcd72022-02-04 13:43:00 -0800641 if (ssid->sae_pwe != DEFAULT_SAE_PWE)
642 bss->sae_pwe = ssid->sae_pwe;
643 else
644 bss->sae_pwe = wpa_s->conf->sae_pwe;
Hai Shalomc3565922019-10-28 11:58:20 -0700645#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700646
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700647 if (wpa_s->conf->go_interworking) {
648 wpa_printf(MSG_DEBUG,
649 "P2P: Enable Interworking with access_network_type: %d",
650 wpa_s->conf->go_access_network_type);
651 bss->interworking = wpa_s->conf->go_interworking;
652 bss->access_network_type = wpa_s->conf->go_access_network_type;
653 bss->internet = wpa_s->conf->go_internet;
654 if (wpa_s->conf->go_venue_group) {
655 wpa_printf(MSG_DEBUG,
656 "P2P: Venue group: %d Venue type: %d",
657 wpa_s->conf->go_venue_group,
658 wpa_s->conf->go_venue_type);
659 bss->venue_group = wpa_s->conf->go_venue_group;
660 bss->venue_type = wpa_s->conf->go_venue_type;
661 bss->venue_info_set = 1;
662 }
663 }
664
Dmitry Shmidt04949592012-07-19 12:16:46 -0700665 if (ssid->ap_max_inactivity)
666 bss->ap_max_inactivity = ssid->ap_max_inactivity;
667
668 if (ssid->dtim_period)
669 bss->dtim_period = ssid->dtim_period;
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -0800670 else if (wpa_s->conf->dtim_period)
671 bss->dtim_period = wpa_s->conf->dtim_period;
672
673 if (ssid->beacon_int)
674 conf->beacon_int = ssid->beacon_int;
675 else if (wpa_s->conf->beacon_int)
676 conf->beacon_int = wpa_s->conf->beacon_int;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700677
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800678#ifdef CONFIG_P2P
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800679 if (ssid->mode == WPAS_MODE_P2P_GO ||
680 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
681 if (wpa_s->conf->p2p_go_ctwindow > conf->beacon_int) {
682 wpa_printf(MSG_INFO,
683 "CTWindow (%d) is bigger than beacon interval (%d) - avoid configuring it",
684 wpa_s->conf->p2p_go_ctwindow,
685 conf->beacon_int);
686 conf->p2p_go_ctwindow = 0;
687 } else {
688 conf->p2p_go_ctwindow = wpa_s->conf->p2p_go_ctwindow;
689 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800690 }
691#endif /* CONFIG_P2P */
692
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800693 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
694 bss->rsn_pairwise = bss->wpa_pairwise;
695 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
696 bss->rsn_pairwise);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700697
Hai Shalomfdcde762020-04-02 11:19:20 -0700698 if (bss->wpa && bss->ieee802_1x) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700699 bss->ssid.security_policy = SECURITY_WPA;
Hai Shalomfdcde762020-04-02 11:19:20 -0700700 } else if (bss->wpa) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700701 bss->ssid.security_policy = SECURITY_WPA_PSK;
Hai Shalomfdcde762020-04-02 11:19:20 -0700702#ifdef CONFIG_WEP
703 } else if (bss->ieee802_1x) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800704 int cipher = WPA_CIPHER_NONE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700705 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
706 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800707 if (bss->default_wep_key_len)
708 cipher = bss->default_wep_key_len >= 13 ?
709 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
710 bss->wpa_group = cipher;
711 bss->wpa_pairwise = cipher;
712 bss->rsn_pairwise = cipher;
713 } else if (bss->ssid.wep.keys_set) {
714 int cipher = WPA_CIPHER_WEP40;
715 if (bss->ssid.wep.len[0] >= 13)
716 cipher = WPA_CIPHER_WEP104;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700717 bss->ssid.security_policy = SECURITY_STATIC_WEP;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800718 bss->wpa_group = cipher;
719 bss->wpa_pairwise = cipher;
720 bss->rsn_pairwise = cipher;
Hai Shalomfdcde762020-04-02 11:19:20 -0700721#endif /* CONFIG_WEP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800722 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700723 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800724 bss->wpa_group = WPA_CIPHER_NONE;
725 bss->wpa_pairwise = WPA_CIPHER_NONE;
726 bss->rsn_pairwise = WPA_CIPHER_NONE;
727 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700728
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700729 if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
730 (bss->wpa_group == WPA_CIPHER_CCMP ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800731 bss->wpa_group == WPA_CIPHER_GCMP ||
732 bss->wpa_group == WPA_CIPHER_CCMP_256 ||
733 bss->wpa_group == WPA_CIPHER_GCMP_256)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700734 /*
735 * Strong ciphers do not need frequent rekeying, so increase
736 * the default GTK rekeying period to 24 hours.
737 */
738 bss->wpa_group_rekey = 86400;
739 }
740
Sunil Ravi38ad1ed2023-01-17 23:58:31 +0000741 if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT) {
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700742 bss->ieee80211w = ssid->ieee80211w;
Sunil Ravi38ad1ed2023-01-17 23:58:31 +0000743 } else if (wpa_s->conf->pmf != MGMT_FRAME_PROTECTION_DEFAULT) {
744 if (ssid->mode == WPAS_MODE_AP)
745 bss->ieee80211w = wpa_s->conf->pmf;
746 }
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700747
Hai Shalom74f70d42019-02-11 14:42:39 -0800748#ifdef CONFIG_OCV
749 bss->ocv = ssid->ocv;
750#endif /* CONFIG_OCV */
751
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700752#ifdef CONFIG_WPS
753 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800754 * Enable WPS by default for open and WPA/WPA2-Personal network, but
755 * require user interaction to actually use it. Only the internal
756 * Registrar is supported.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700757 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800758 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
759 bss->ssid.security_policy != SECURITY_PLAINTEXT)
760 goto no_wps;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800761 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800762 (!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ||
763 !(bss->wpa & 2)))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800764 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
765 * configuration */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700766 if (ssid->wps_disabled)
767 goto no_wps;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700768 bss->eap_server = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700769
770 if (!ssid->ignore_broadcast_ssid)
771 bss->wps_state = 2;
772
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700773 bss->ap_setup_locked = 2;
774 if (wpa_s->conf->config_methods)
775 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
776 os_memcpy(bss->device_type, wpa_s->conf->device_type,
777 WPS_DEV_TYPE_LEN);
778 if (wpa_s->conf->device_name) {
779 bss->device_name = os_strdup(wpa_s->conf->device_name);
780 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
781 }
782 if (wpa_s->conf->manufacturer)
783 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
784 if (wpa_s->conf->model_name)
785 bss->model_name = os_strdup(wpa_s->conf->model_name);
786 if (wpa_s->conf->model_number)
787 bss->model_number = os_strdup(wpa_s->conf->model_number);
788 if (wpa_s->conf->serial_number)
789 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
790 if (is_nil_uuid(wpa_s->conf->uuid))
791 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
792 else
793 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
794 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700795 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -0700796 if (ssid->eap.fragment_size != DEFAULT_FRAGMENT_SIZE)
797 bss->fragment_size = ssid->eap.fragment_size;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800798no_wps:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700799#endif /* CONFIG_WPS */
800
801 if (wpa_s->max_stations &&
802 wpa_s->max_stations < wpa_s->conf->max_num_sta)
803 bss->max_num_sta = wpa_s->max_stations;
804 else
805 bss->max_num_sta = wpa_s->conf->max_num_sta;
806
Roshan Pius3a1667e2018-07-03 15:17:14 -0700807 if (!bss->isolate)
808 bss->isolate = wpa_s->conf->ap_isolate;
809
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700810 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
811
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700812 if (wpa_s->conf->ap_vendor_elements) {
813 bss->vendor_elements =
814 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
815 }
Hai Shaloma20dcd72022-02-04 13:43:00 -0800816 if (wpa_s->conf->ap_assocresp_elements) {
817 bss->assocresp_elements =
818 wpabuf_dup(wpa_s->conf->ap_assocresp_elements);
819 }
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700820
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700821 bss->ftm_responder = wpa_s->conf->ftm_responder;
822 bss->ftm_initiator = wpa_s->conf->ftm_initiator;
823
Hai Shalomfdcde762020-04-02 11:19:20 -0700824 bss->transition_disable = ssid->transition_disable;
825
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700826 return 0;
827}
828
829
830static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
831{
832#ifdef CONFIG_P2P
833 struct wpa_supplicant *wpa_s = ctx;
834 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700835
836 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700837 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700838 return;
Dmitry Shmidt18463232014-01-24 12:29:41 -0800839 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
840 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700841 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
842 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700843 buf + IEEE80211_HDRLEN + 1,
844 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700845#endif /* CONFIG_P2P */
846}
847
848
849static void ap_wps_event_cb(void *ctx, enum wps_event event,
850 union wps_event_data *data)
851{
852#ifdef CONFIG_P2P
853 struct wpa_supplicant *wpa_s = ctx;
854
Jouni Malinen75ecf522011-06-27 15:19:46 -0700855 if (event == WPS_EV_FAIL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700856 struct wps_event_fail *fail = &data->fail;
857
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800858 if (wpa_s->p2pdev && wpa_s->p2pdev != wpa_s &&
Jouni Malinen75ecf522011-06-27 15:19:46 -0700859 wpa_s == wpa_s->global->p2p_group_formation) {
860 /*
861 * src/ap/wps_hostapd.c has already sent this on the
862 * main interface, so only send on the parent interface
863 * here if needed.
864 */
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800865 wpa_msg(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_FAIL
Jouni Malinen75ecf522011-06-27 15:19:46 -0700866 "msg=%d config_error=%d",
867 fail->msg, fail->config_error);
868 }
869 wpas_p2p_wps_failed(wpa_s, fail);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700870 }
871#endif /* CONFIG_P2P */
872}
873
874
875static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
Sunil Ravi99c035e2024-07-12 01:42:03 +0000876 int authorized, const u8 *p2p_dev_addr,
877 const u8 *ip)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700878{
Sunil Ravid8128a22023-11-06 23:53:58 +0000879 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr, ip);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700880}
881
882
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700883#ifdef CONFIG_P2P
884static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
885 const u8 *psk, size_t psk_len)
886{
887
888 struct wpa_supplicant *wpa_s = ctx;
889 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
890 return;
891 wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
892}
893#endif /* CONFIG_P2P */
894
895
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700896static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
897{
898#ifdef CONFIG_P2P
899 struct wpa_supplicant *wpa_s = ctx;
900 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700901
902 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700903 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700904 return -1;
905 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
906 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700907 buf + IEEE80211_HDRLEN + 1,
908 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700909#endif /* CONFIG_P2P */
910 return 0;
911}
912
913
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800914static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700915 const u8 *bssid, const u8 *ie, size_t ie_len,
916 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700917{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700918 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700919 unsigned int freq = 0;
920
921 if (wpa_s->ap_iface)
922 freq = wpa_s->ap_iface->freq;
923
Dmitry Shmidt04949592012-07-19 12:16:46 -0700924 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700925 freq, ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700926}
927
928
929static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
930 const u8 *uuid_e)
931{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700932 struct wpa_supplicant *wpa_s = ctx;
933 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700934}
935
936
937static void wpas_ap_configured_cb(void *ctx)
938{
939 struct wpa_supplicant *wpa_s = ctx;
940
Roshan Pius3a1667e2018-07-03 15:17:14 -0700941 wpa_printf(MSG_DEBUG, "AP interface setup completed - state %s",
942 hostapd_state_text(wpa_s->ap_iface->state));
943 if (wpa_s->ap_iface->state == HAPD_IFACE_DISABLED) {
944 wpa_supplicant_ap_deinit(wpa_s);
945 return;
946 }
947
Sunil Ravi236f0f52021-06-29 11:18:20 -0700948 if (wpa_s->current_ssid) {
949 int acs = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800950
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800951#ifdef CONFIG_ACS
Sunil Ravi236f0f52021-06-29 11:18:20 -0700952 acs = wpa_s->current_ssid->acs;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800953#endif /* CONFIG_ACS */
Sunil Ravi236f0f52021-06-29 11:18:20 -0700954 if (acs || (wpa_s->assoc_freq && wpa_s->ap_iface->freq &&
Hai Shaloma20dcd72022-02-04 13:43:00 -0800955 (int) wpa_s->assoc_freq != wpa_s->ap_iface->freq)) {
Sunil Ravi236f0f52021-06-29 11:18:20 -0700956 wpa_s->assoc_freq = wpa_s->ap_iface->freq;
957 wpa_s->current_ssid->frequency = wpa_s->ap_iface->freq;
958 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700959 }
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800960
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700961 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
962
963 if (wpa_s->ap_configured_cb)
964 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
965 wpa_s->ap_configured_cb_data);
966}
967
968
969int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
970 struct wpa_ssid *ssid)
971{
972 struct wpa_driver_associate_params params;
973 struct hostapd_iface *hapd_iface;
974 struct hostapd_config *conf;
975 size_t i;
976
977 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
978 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
979 return -1;
980 }
981
982 wpa_supplicant_ap_deinit(wpa_s);
983
984 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
985 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
986
987 os_memset(&params, 0, sizeof(params));
988 params.ssid = ssid->ssid;
989 params.ssid_len = ssid->ssid_len;
990 switch (ssid->mode) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700991 case WPAS_MODE_AP:
992 case WPAS_MODE_P2P_GO:
993 case WPAS_MODE_P2P_GROUP_FORMATION:
994 params.mode = IEEE80211_MODE_AP;
995 break;
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800996 default:
997 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700998 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700999 if (ssid->frequency == 0)
1000 ssid->frequency = 2462; /* default channel 11 */
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -07001001 params.freq.freq = ssid->frequency;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001002
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001003 if ((ssid->mode == WPAS_MODE_AP || ssid->mode == WPAS_MODE_P2P_GO) &&
1004 ssid->enable_edmg) {
Hai Shalomc3565922019-10-28 11:58:20 -07001005 u8 primary_channel;
1006
1007 if (ieee80211_freq_to_chan(ssid->frequency, &primary_channel) ==
1008 NUM_HOSTAPD_MODES) {
1009 wpa_printf(MSG_WARNING,
1010 "EDMG: Failed to get the primary channel");
1011 return -1;
1012 }
1013
1014 hostapd_encode_edmg_chan(ssid->enable_edmg, ssid->edmg_channel,
1015 primary_channel, &params.freq.edmg);
1016 }
1017
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001018 params.wpa_proto = ssid->proto;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001019 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
1020 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
Hai Shaloma20dcd72022-02-04 13:43:00 -08001021 else if (ssid->key_mgmt & WPA_KEY_MGMT_SAE)
1022 wpa_s->key_mgmt = WPA_KEY_MGMT_SAE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001023 else
1024 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001025 params.key_mgmt_suite = wpa_s->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001026
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001027 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
1028 1);
1029 if (wpa_s->pairwise_cipher < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001030 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
1031 "cipher.");
1032 return -1;
1033 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001034 params.pairwise_suite = wpa_s->pairwise_cipher;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001035 params.group_suite = params.pairwise_suite;
1036
1037#ifdef CONFIG_P2P
1038 if (ssid->mode == WPAS_MODE_P2P_GO ||
1039 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
1040 params.p2p = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001041#endif /* CONFIG_P2P */
1042
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001043 if (wpa_s->p2pdev->set_ap_uapsd)
1044 params.uapsd = wpa_s->p2pdev->ap_uapsd;
Dmitry Shmidtec58b162014-02-19 12:44:18 -08001045 else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
1046 params.uapsd = 1; /* mandatory for P2P GO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001047 else
1048 params.uapsd = -1;
1049
Roshan Pius3a1667e2018-07-03 15:17:14 -07001050 if (ieee80211_is_dfs(params.freq.freq, wpa_s->hw.modes,
1051 wpa_s->hw.num_modes))
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001052 params.freq.freq = 0; /* set channel after CAC */
1053
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001054 if (params.p2p)
1055 wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_GO);
1056 else
1057 wpa_drv_get_ext_capa(wpa_s, WPA_IF_AP_BSS);
1058
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001059 if (wpa_drv_associate(wpa_s, &params) < 0) {
1060 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
1061 return -1;
1062 }
1063
Dmitry Shmidtaca489e2016-09-28 15:44:14 -07001064 wpa_s->ap_iface = hapd_iface = hostapd_alloc_iface();
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001065 if (hapd_iface == NULL)
1066 return -1;
1067 hapd_iface->owner = wpa_s;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001068 hapd_iface->drv_flags = wpa_s->drv_flags;
Sunil Ravi2a14cf12023-11-21 00:54:38 +00001069 hapd_iface->drv_flags2 = wpa_s->drv_flags2;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001070 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
Dmitry Shmidt444d5672013-04-01 13:08:44 -07001071 hapd_iface->extended_capa = wpa_s->extended_capa;
1072 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
1073 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
Sunil Ravia04bd252022-05-02 22:54:18 -07001074 hapd_iface->drv_max_acl_mac_addrs = wpa_s->drv_max_acl_mac_addrs;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001075
1076 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
1077 if (conf == NULL) {
1078 wpa_supplicant_ap_deinit(wpa_s);
1079 return -1;
1080 }
1081
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001082 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
1083 wpa_s->conf->wmm_ac_params,
1084 sizeof(wpa_s->conf->wmm_ac_params));
1085
Hai Shalom899fcc72020-10-19 14:38:18 -07001086 os_memcpy(wpa_s->ap_iface->conf->tx_queue, wpa_s->conf->tx_queue,
1087 sizeof(wpa_s->conf->tx_queue));
1088
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001089 if (params.uapsd > 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001090 conf->bss[0]->wmm_enabled = 1;
1091 conf->bss[0]->wmm_uapsd = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001092 }
1093
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001094 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
1095 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
1096 wpa_supplicant_ap_deinit(wpa_s);
1097 return -1;
1098 }
1099
1100#ifdef CONFIG_P2P
1101 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001102 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001103 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001104 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001105 P2P_GROUP_FORMATION;
1106#endif /* CONFIG_P2P */
1107
1108 hapd_iface->num_bss = conf->num_bss;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001109 hapd_iface->bss = os_calloc(conf->num_bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001110 sizeof(struct hostapd_data *));
1111 if (hapd_iface->bss == NULL) {
1112 wpa_supplicant_ap_deinit(wpa_s);
1113 return -1;
1114 }
1115
1116 for (i = 0; i < conf->num_bss; i++) {
1117 hapd_iface->bss[i] =
1118 hostapd_alloc_bss_data(hapd_iface, conf,
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001119 conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001120 if (hapd_iface->bss[i] == NULL) {
1121 wpa_supplicant_ap_deinit(wpa_s);
1122 return -1;
1123 }
1124
1125 hapd_iface->bss[i]->msg_ctx = wpa_s;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001126 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->p2pdev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001127 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
1128 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
1129 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
1130 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
1131 hostapd_register_probereq_cb(hapd_iface->bss[i],
1132 ap_probe_req_rx, wpa_s);
1133 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
1134 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
1135 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
1136 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
1137 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
1138 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
1139#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001140 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
1141 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001142 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001143 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
1144 ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001145#endif /* CONFIG_P2P */
1146 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
1147 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001148#ifdef CONFIG_TESTING_OPTIONS
1149 hapd_iface->bss[i]->ext_eapol_frame_io =
1150 wpa_s->ext_eapol_frame_io;
1151#endif /* CONFIG_TESTING_OPTIONS */
Sunil Ravia04bd252022-05-02 22:54:18 -07001152
1153#ifdef CONFIG_WNM_AP
1154 if (ssid->mode == WPAS_MODE_AP)
1155 hapd_iface->bss[i]->conf->bss_transition = 1;
1156#endif /* CONFIG_WNM_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001157 }
1158
1159 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
1160 hapd_iface->bss[0]->driver = wpa_s->driver;
1161 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
1162
1163 wpa_s->current_ssid = ssid;
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 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
1166 wpa_s->assoc_freq = ssid->frequency;
Hai Shalomc3565922019-10-28 11:58:20 -07001167 wpa_s->ap_iface->conf->enable_edmg = ssid->enable_edmg;
1168 wpa_s->ap_iface->conf->edmg_channel = ssid->edmg_channel;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001169
Roshan Pius3a1667e2018-07-03 15:17:14 -07001170#if defined(CONFIG_P2P) && defined(CONFIG_ACS)
1171 if (wpa_s->p2p_go_do_acs) {
1172 wpa_s->ap_iface->conf->channel = 0;
1173 wpa_s->ap_iface->conf->hw_mode = wpa_s->p2p_go_acs_band;
1174 ssid->acs = 1;
1175 }
1176#endif /* CONFIG_P2P && CONFIG_ACS */
1177
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001178 if (hostapd_setup_interface(wpa_s->ap_iface)) {
1179 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
1180 wpa_supplicant_ap_deinit(wpa_s);
1181 return -1;
1182 }
1183
1184 return 0;
1185}
1186
1187
1188void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
1189{
1190#ifdef CONFIG_WPS
1191 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1192#endif /* CONFIG_WPS */
1193
1194 if (wpa_s->ap_iface == NULL)
1195 return;
1196
1197 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001198 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001199 wpa_s->assoc_freq = 0;
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07001200 wpas_p2p_ap_deinit(wpa_s);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001201 wpa_s->ap_iface->driver_ap_teardown =
1202 !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
1203
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001204 hostapd_interface_deinit(wpa_s->ap_iface);
1205 hostapd_interface_free(wpa_s->ap_iface);
1206 wpa_s->ap_iface = NULL;
1207 wpa_drv_deinit_ap(wpa_s);
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07001208 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1209 " reason=%d locally_generated=1",
1210 MAC2STR(wpa_s->own_addr), WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001211}
1212
1213
1214void ap_tx_status(void *ctx, const u8 *addr,
1215 const u8 *buf, size_t len, int ack)
1216{
1217#ifdef NEED_AP_MLME
1218 struct wpa_supplicant *wpa_s = ctx;
1219 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
1220#endif /* NEED_AP_MLME */
1221}
1222
1223
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001224void ap_eapol_tx_status(void *ctx, const u8 *dst,
1225 const u8 *data, size_t len, int ack)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001226{
1227#ifdef NEED_AP_MLME
1228 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001229 if (!wpa_s->ap_iface)
1230 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001231 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
1232#endif /* NEED_AP_MLME */
1233}
1234
1235
1236void ap_client_poll_ok(void *ctx, const u8 *addr)
1237{
1238#ifdef NEED_AP_MLME
1239 struct wpa_supplicant *wpa_s = ctx;
1240 if (wpa_s->ap_iface)
1241 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
1242#endif /* NEED_AP_MLME */
1243}
1244
1245
1246void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
1247{
1248#ifdef NEED_AP_MLME
1249 struct wpa_supplicant *wpa_s = ctx;
1250 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001251#endif /* NEED_AP_MLME */
1252}
1253
1254
1255void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
1256{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001257#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001258 struct wpa_supplicant *wpa_s = ctx;
1259 struct hostapd_frame_info fi;
1260 os_memset(&fi, 0, sizeof(fi));
Hai Shaloma20dcd72022-02-04 13:43:00 -08001261 fi.freq = rx_mgmt->freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001262 fi.datarate = rx_mgmt->datarate;
1263 fi.ssi_signal = rx_mgmt->ssi_signal;
1264 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
1265 rx_mgmt->frame_len, &fi);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001266#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001267}
1268
1269
1270void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
1271{
1272#ifdef NEED_AP_MLME
1273 struct wpa_supplicant *wpa_s = ctx;
1274 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
1275#endif /* NEED_AP_MLME */
1276}
1277
1278
1279void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
Sunil8cd6f4d2022-06-28 18:40:46 +00001280 const u8 *src_addr, const u8 *buf, size_t len,
1281 enum frame_encryption encrypted)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001282{
Sunil8cd6f4d2022-06-28 18:40:46 +00001283 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len,
1284 encrypted);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001285}
1286
1287
1288#ifdef CONFIG_WPS
1289
1290int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
1291 const u8 *p2p_dev_addr)
1292{
1293 if (!wpa_s->ap_iface)
1294 return -1;
1295 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
1296 p2p_dev_addr);
1297}
1298
1299
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001300int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
1301{
1302 struct wps_registrar *reg;
1303 int reg_sel = 0, wps_sta = 0;
1304
1305 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
1306 return -1;
1307
1308 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
1309 reg_sel = wps_registrar_wps_cancel(reg);
1310 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
Dmitry Shmidt04949592012-07-19 12:16:46 -07001311 ap_sta_wps_cancel, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001312
1313 if (!reg_sel && !wps_sta) {
1314 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
1315 "time");
1316 return -1;
1317 }
1318
1319 /*
1320 * There are 2 cases to return wps cancel as success:
1321 * 1. When wps cancel was initiated but no connection has been
1322 * established with client yet.
1323 * 2. Client is in the middle of exchanging WPS messages.
1324 */
1325
1326 return 0;
1327}
1328
1329
1330int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001331 const char *pin, char *buf, size_t buflen,
1332 int timeout)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001333{
1334 int ret, ret_len = 0;
1335
1336 if (!wpa_s->ap_iface)
1337 return -1;
1338
1339 if (pin == NULL) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001340 unsigned int rpin;
1341
1342 if (wps_generate_pin(&rpin) < 0)
1343 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001344 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001345 if (os_snprintf_error(buflen, ret_len))
1346 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001347 pin = buf;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001348 } else if (buf) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001349 ret_len = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001350 if (os_snprintf_error(buflen, ret_len))
1351 return -1;
1352 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001353
1354 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001355 timeout);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001356 if (ret)
1357 return -1;
1358 return ret_len;
1359}
1360
1361
1362static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
1363{
1364 struct wpa_supplicant *wpa_s = eloop_data;
1365 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
1366 wpas_wps_ap_pin_disable(wpa_s);
1367}
1368
1369
1370static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
1371{
1372 struct hostapd_data *hapd;
1373
1374 if (wpa_s->ap_iface == NULL)
1375 return;
1376 hapd = wpa_s->ap_iface->bss[0];
1377 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
1378 hapd->ap_pin_failures = 0;
1379 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1380 if (timeout > 0)
1381 eloop_register_timeout(timeout, 0,
1382 wpas_wps_ap_pin_timeout, wpa_s, NULL);
1383}
1384
1385
1386void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
1387{
1388 struct hostapd_data *hapd;
1389
1390 if (wpa_s->ap_iface == NULL)
1391 return;
1392 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
1393 hapd = wpa_s->ap_iface->bss[0];
1394 os_free(hapd->conf->ap_pin);
1395 hapd->conf->ap_pin = NULL;
1396 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1397}
1398
1399
1400const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
1401{
1402 struct hostapd_data *hapd;
1403 unsigned int pin;
1404 char pin_txt[9];
1405
1406 if (wpa_s->ap_iface == NULL)
1407 return NULL;
1408 hapd = wpa_s->ap_iface->bss[0];
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001409 if (wps_generate_pin(&pin) < 0)
1410 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001411 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001412 os_free(hapd->conf->ap_pin);
1413 hapd->conf->ap_pin = os_strdup(pin_txt);
1414 if (hapd->conf->ap_pin == NULL)
1415 return NULL;
1416 wpas_wps_ap_pin_enable(wpa_s, timeout);
1417
1418 return hapd->conf->ap_pin;
1419}
1420
1421
1422const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
1423{
1424 struct hostapd_data *hapd;
1425 if (wpa_s->ap_iface == NULL)
1426 return NULL;
1427 hapd = wpa_s->ap_iface->bss[0];
1428 return hapd->conf->ap_pin;
1429}
1430
1431
1432int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
1433 int timeout)
1434{
1435 struct hostapd_data *hapd;
1436 char pin_txt[9];
1437 int ret;
1438
1439 if (wpa_s->ap_iface == NULL)
1440 return -1;
1441 hapd = wpa_s->ap_iface->bss[0];
1442 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001443 if (os_snprintf_error(sizeof(pin_txt), ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001444 return -1;
1445 os_free(hapd->conf->ap_pin);
1446 hapd->conf->ap_pin = os_strdup(pin_txt);
1447 if (hapd->conf->ap_pin == NULL)
1448 return -1;
1449 wpas_wps_ap_pin_enable(wpa_s, timeout);
1450
1451 return 0;
1452}
1453
1454
1455void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
1456{
1457 struct hostapd_data *hapd;
1458
1459 if (wpa_s->ap_iface == NULL)
1460 return;
1461 hapd = wpa_s->ap_iface->bss[0];
1462
1463 /*
1464 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
1465 * PIN if this happens multiple times to slow down brute force attacks.
1466 */
1467 hapd->ap_pin_failures++;
1468 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
1469 hapd->ap_pin_failures);
1470 if (hapd->ap_pin_failures < 3)
1471 return;
1472
1473 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
1474 hapd->ap_pin_failures = 0;
1475 os_free(hapd->conf->ap_pin);
1476 hapd->conf->ap_pin = NULL;
1477}
1478
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001479
1480#ifdef CONFIG_WPS_NFC
1481
1482struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
1483 int ndef)
1484{
1485 struct hostapd_data *hapd;
1486
1487 if (wpa_s->ap_iface == NULL)
1488 return NULL;
1489 hapd = wpa_s->ap_iface->bss[0];
1490 return hostapd_wps_nfc_config_token(hapd, ndef);
1491}
1492
1493
1494struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
1495 int ndef)
1496{
1497 struct hostapd_data *hapd;
1498
1499 if (wpa_s->ap_iface == NULL)
1500 return NULL;
1501 hapd = wpa_s->ap_iface->bss[0];
1502 return hostapd_wps_nfc_hs_cr(hapd, ndef);
1503}
1504
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001505
1506int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
1507 const struct wpabuf *req,
1508 const struct wpabuf *sel)
1509{
1510 struct hostapd_data *hapd;
1511
1512 if (wpa_s->ap_iface == NULL)
1513 return -1;
1514 hapd = wpa_s->ap_iface->bss[0];
1515 return hostapd_wps_nfc_report_handover(hapd, req, sel);
1516}
1517
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001518#endif /* CONFIG_WPS_NFC */
1519
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001520#endif /* CONFIG_WPS */
1521
1522
1523#ifdef CONFIG_CTRL_IFACE
1524
1525int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
1526 char *buf, size_t buflen)
1527{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001528 struct hostapd_data *hapd;
1529
1530 if (wpa_s->ap_iface)
1531 hapd = wpa_s->ap_iface->bss[0];
1532 else if (wpa_s->ifmsh)
1533 hapd = wpa_s->ifmsh->bss[0];
1534 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001535 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001536 return hostapd_ctrl_iface_sta_first(hapd, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001537}
1538
1539
1540int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
1541 char *buf, size_t buflen)
1542{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001543 struct hostapd_data *hapd;
1544
1545 if (wpa_s->ap_iface)
1546 hapd = wpa_s->ap_iface->bss[0];
1547 else if (wpa_s->ifmsh)
1548 hapd = wpa_s->ifmsh->bss[0];
1549 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001550 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001551 return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001552}
1553
1554
1555int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
1556 char *buf, size_t buflen)
1557{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001558 struct hostapd_data *hapd;
1559
1560 if (wpa_s->ap_iface)
1561 hapd = wpa_s->ap_iface->bss[0];
1562 else if (wpa_s->ifmsh)
1563 hapd = wpa_s->ifmsh->bss[0];
1564 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001565 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001566 return hostapd_ctrl_iface_sta_next(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001567}
1568
1569
Dmitry Shmidt04949592012-07-19 12:16:46 -07001570int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1571 const char *txtaddr)
1572{
1573 if (wpa_s->ap_iface == NULL)
1574 return -1;
1575 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1576 txtaddr);
1577}
1578
1579
1580int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1581 const char *txtaddr)
1582{
1583 if (wpa_s->ap_iface == NULL)
1584 return -1;
1585 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1586 txtaddr);
1587}
1588
1589
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001590int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1591 size_t buflen, int verbose)
1592{
1593 char *pos = buf, *end = buf + buflen;
1594 int ret;
1595 struct hostapd_bss_config *conf;
1596
1597 if (wpa_s->ap_iface == NULL)
1598 return -1;
1599
1600 conf = wpa_s->ap_iface->bss[0]->conf;
1601 if (conf->wpa == 0)
1602 return 0;
1603
1604 ret = os_snprintf(pos, end - pos,
1605 "pairwise_cipher=%s\n"
1606 "group_cipher=%s\n"
1607 "key_mgmt=%s\n",
1608 wpa_cipher_txt(conf->rsn_pairwise),
1609 wpa_cipher_txt(conf->wpa_group),
1610 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1611 conf->wpa));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001612 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001613 return pos - buf;
1614 pos += ret;
1615 return pos - buf;
1616}
1617
Sunil Ravia04bd252022-05-02 22:54:18 -07001618
1619#ifdef CONFIG_WNM_AP
1620
1621int ap_ctrl_iface_disassoc_imminent(struct wpa_supplicant *wpa_s,
1622 const char *buf)
1623{
1624 struct hostapd_data *hapd;
1625
1626 if (wpa_s->ap_iface)
1627 hapd = wpa_s->ap_iface->bss[0];
1628 else
1629 return -1;
1630 return hostapd_ctrl_iface_disassoc_imminent(hapd, buf);
1631}
1632
1633
1634int ap_ctrl_iface_ess_disassoc(struct wpa_supplicant *wpa_s, const char *buf)
1635{
1636 struct hostapd_data *hapd;
1637
1638 if (wpa_s->ap_iface)
1639 hapd = wpa_s->ap_iface->bss[0];
1640 else
1641 return -1;
1642 return hostapd_ctrl_iface_ess_disassoc(hapd, buf);
1643}
1644
1645
1646int ap_ctrl_iface_bss_tm_req(struct wpa_supplicant *wpa_s, const char *buf)
1647{
1648 struct hostapd_data *hapd;
1649
1650 if (wpa_s->ap_iface)
1651 hapd = wpa_s->ap_iface->bss[0];
1652 else
1653 return -1;
1654 return hostapd_ctrl_iface_bss_tm_req(hapd, buf);
1655}
1656
1657#endif /* CONFIG_WNM_AP */
1658
1659
1660int ap_ctrl_iface_acl_add_mac(struct wpa_supplicant *wpa_s,
1661 enum macaddr_acl acl_type,
1662 const char *buf)
1663{
1664 struct hostapd_data *hapd;
1665
1666 if (wpa_s->ap_iface)
1667 hapd = wpa_s->ap_iface->bss[0];
1668 else
1669 return -1;
1670
1671 hapd->conf->macaddr_acl = acl_type;
1672
1673 if (acl_type == ACCEPT_UNLESS_DENIED)
1674 return hostapd_ctrl_iface_acl_add_mac(&hapd->conf->deny_mac,
1675 &hapd->conf->num_deny_mac,
1676 buf);
1677 if (acl_type == DENY_UNLESS_ACCEPTED)
1678 return hostapd_ctrl_iface_acl_add_mac(
1679 &hapd->conf->accept_mac,
1680 &hapd->conf->num_accept_mac, buf);
1681
1682 return -1;
1683}
1684
1685
1686int ap_ctrl_iface_acl_del_mac(struct wpa_supplicant *wpa_s,
1687 enum macaddr_acl acl_type,
1688 const char *buf)
1689{
1690 struct hostapd_data *hapd;
1691
1692 if (wpa_s->ap_iface)
1693 hapd = wpa_s->ap_iface->bss[0];
1694 else
1695 return -1;
1696
1697 hapd->conf->macaddr_acl = acl_type;
1698
1699 if (acl_type == ACCEPT_UNLESS_DENIED)
1700 return hostapd_ctrl_iface_acl_del_mac(&hapd->conf->deny_mac,
1701 &hapd->conf->num_deny_mac,
1702 buf);
1703 if (acl_type == DENY_UNLESS_ACCEPTED)
1704 return hostapd_ctrl_iface_acl_del_mac(
1705 &hapd->conf->accept_mac, &hapd->conf->num_accept_mac,
1706 buf);
1707
1708 return -1;
1709}
1710
1711
1712int ap_ctrl_iface_acl_show_mac(struct wpa_supplicant *wpa_s,
1713 enum macaddr_acl acl_type, char *buf,
1714 size_t buflen)
1715{
1716 struct hostapd_data *hapd;
1717
1718 if (wpa_s->ap_iface)
1719 hapd = wpa_s->ap_iface->bss[0];
1720 else
1721 return -1;
1722
1723 if (acl_type == ACCEPT_UNLESS_DENIED)
1724 return hostapd_ctrl_iface_acl_show_mac(hapd->conf->deny_mac,
1725 hapd->conf->num_deny_mac,
1726 buf, buflen);
1727 if (acl_type == DENY_UNLESS_ACCEPTED)
1728 return hostapd_ctrl_iface_acl_show_mac(
1729 hapd->conf->accept_mac, hapd->conf->num_accept_mac,
1730 buf, buflen);
1731
1732 return -1;
1733}
1734
1735
1736void ap_ctrl_iface_acl_clear_list(struct wpa_supplicant *wpa_s,
1737 enum macaddr_acl acl_type)
1738{
1739 struct hostapd_data *hapd;
1740
1741 if (wpa_s->ap_iface)
1742 hapd = wpa_s->ap_iface->bss[0];
1743 else
1744 return;
1745
1746 hapd->conf->macaddr_acl = acl_type;
1747
1748 if (acl_type == ACCEPT_UNLESS_DENIED)
1749 hostapd_ctrl_iface_acl_clear_list(&hapd->conf->deny_mac,
1750 &hapd->conf->num_deny_mac);
1751 else if (acl_type == DENY_UNLESS_ACCEPTED)
1752 hostapd_ctrl_iface_acl_clear_list(&hapd->conf->accept_mac,
1753 &hapd->conf->num_accept_mac);
1754}
1755
1756
1757int ap_ctrl_iface_disassoc_deny_mac(struct wpa_supplicant *wpa_s)
1758{
1759 struct hostapd_data *hapd;
1760
1761 if (wpa_s->ap_iface)
1762 hapd = wpa_s->ap_iface->bss[0];
1763 else
1764 return -1;
1765
1766 return hostapd_disassoc_deny_mac(hapd);
1767}
1768
1769
1770int ap_ctrl_iface_disassoc_accept_mac(struct wpa_supplicant *wpa_s)
1771{
1772 struct hostapd_data *hapd;
1773
1774 if (wpa_s->ap_iface)
1775 hapd = wpa_s->ap_iface->bss[0];
1776 else
1777 return -1;
1778
1779 return hostapd_disassoc_accept_mac(hapd);
1780}
1781
1782
1783int ap_ctrl_iface_set_acl(struct wpa_supplicant *wpa_s)
1784{
1785 struct hostapd_data *hapd;
1786
1787 if (wpa_s->ap_iface)
1788 hapd = wpa_s->ap_iface->bss[0];
1789 else
1790 return -1;
1791
1792 return hostapd_set_acl(hapd);
1793}
1794
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001795#endif /* CONFIG_CTRL_IFACE */
1796
1797
1798int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1799{
1800 struct hostapd_iface *iface = wpa_s->ap_iface;
1801 struct wpa_ssid *ssid = wpa_s->current_ssid;
1802 struct hostapd_data *hapd;
1803
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001804 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1805 ssid->mode == WPAS_MODE_INFRA ||
1806 ssid->mode == WPAS_MODE_IBSS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001807 return -1;
1808
1809#ifdef CONFIG_P2P
1810 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001811 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001812 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001813 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001814 P2P_GROUP_FORMATION;
1815#endif /* CONFIG_P2P */
1816
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001817 hapd = iface->bss[0];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001818 if (hapd->drv_priv == NULL)
1819 return -1;
1820 ieee802_11_set_beacons(iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001821 hostapd_set_ap_wps_ie(hapd);
1822
1823 return 0;
1824}
1825
1826
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001827int ap_switch_channel(struct wpa_supplicant *wpa_s,
1828 struct csa_settings *settings)
1829{
1830#ifdef NEED_AP_MLME
Hai Shalom899fcc72020-10-19 14:38:18 -07001831 struct hostapd_iface *iface = NULL;
1832
1833 if (wpa_s->ap_iface)
1834 iface = wpa_s->ap_iface;
1835 else if (wpa_s->ifmsh)
1836 iface = wpa_s->ifmsh;
1837
1838 if (!iface || !iface->bss[0])
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001839 return -1;
1840
Hai Shalom899fcc72020-10-19 14:38:18 -07001841 return hostapd_switch_channel(iface->bss[0], settings);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001842#else /* NEED_AP_MLME */
1843 return -1;
1844#endif /* NEED_AP_MLME */
1845}
1846
1847
Dmitry Shmidt83474442015-04-15 13:47:09 -07001848#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001849int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1850{
1851 struct csa_settings settings;
1852 int ret = hostapd_parse_csa_settings(pos, &settings);
1853
1854 if (ret)
1855 return ret;
1856
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001857 settings.link_id = -1;
1858
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001859 return ap_switch_channel(wpa_s, &settings);
1860}
Dmitry Shmidt83474442015-04-15 13:47:09 -07001861#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001862
1863
Dmitry Shmidt04949592012-07-19 12:16:46 -07001864void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
Sunil Raviaf8751c2023-03-29 11:35:17 -07001865 int offset, int width, int cf1, int cf2,
1866 u16 punct_bitmap, int finished)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001867{
Hai Shalom74f70d42019-02-11 14:42:39 -08001868 struct hostapd_iface *iface = wpa_s->ap_iface;
Hai Shalombf6e0ba2019-02-11 12:01:50 -08001869
Hai Shalom74f70d42019-02-11 14:42:39 -08001870 if (!iface)
1871 iface = wpa_s->ifmsh;
1872 if (!iface)
1873 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001874 wpa_s->assoc_freq = freq;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001875 if (wpa_s->current_ssid)
1876 wpa_s->current_ssid->frequency = freq;
Hai Shalom74f70d42019-02-11 14:42:39 -08001877 hostapd_event_ch_switch(iface->bss[0], freq, ht,
Sunil Raviaf8751c2023-03-29 11:35:17 -07001878 offset, width, cf1, cf2, punct_bitmap,
1879 finished);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001880}
1881
1882
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001883int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1884 const u8 *addr)
1885{
1886 struct hostapd_data *hapd;
1887 struct hostapd_bss_config *conf;
1888
1889 if (!wpa_s->ap_iface)
1890 return -1;
1891
1892 if (addr)
1893 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1894 MAC2STR(addr));
1895 else
1896 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1897
1898 hapd = wpa_s->ap_iface->bss[0];
1899 conf = hapd->conf;
1900
1901 os_free(conf->accept_mac);
1902 conf->accept_mac = NULL;
1903 conf->num_accept_mac = 0;
1904 os_free(conf->deny_mac);
1905 conf->deny_mac = NULL;
1906 conf->num_deny_mac = 0;
1907
1908 if (addr == NULL) {
1909 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1910 return 0;
1911 }
1912
1913 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1914 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1915 if (conf->accept_mac == NULL)
1916 return -1;
1917 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1918 conf->num_accept_mac = 1;
1919
1920 return 0;
1921}
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001922
1923
1924#ifdef CONFIG_WPS_NFC
1925int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1926 const struct wpabuf *pw, const u8 *pubkey_hash)
1927{
1928 struct hostapd_data *hapd;
1929 struct wps_context *wps;
1930
1931 if (!wpa_s->ap_iface)
1932 return -1;
1933 hapd = wpa_s->ap_iface->bss[0];
1934 wps = hapd->wps;
1935
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001936 if (wpa_s->p2pdev->conf->wps_nfc_dh_pubkey == NULL ||
1937 wpa_s->p2pdev->conf->wps_nfc_dh_privkey == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001938 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1939 return -1;
1940 }
1941
1942 dh5_free(wps->dh_ctx);
1943 wpabuf_free(wps->dh_pubkey);
1944 wpabuf_free(wps->dh_privkey);
1945 wps->dh_privkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001946 wpa_s->p2pdev->conf->wps_nfc_dh_privkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001947 wps->dh_pubkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001948 wpa_s->p2pdev->conf->wps_nfc_dh_pubkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001949 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1950 wps->dh_ctx = NULL;
1951 wpabuf_free(wps->dh_pubkey);
1952 wps->dh_pubkey = NULL;
1953 wpabuf_free(wps->dh_privkey);
1954 wps->dh_privkey = NULL;
1955 return -1;
1956 }
1957 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1958 if (wps->dh_ctx == NULL)
1959 return -1;
1960
1961 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1962 pw_id,
1963 pw ? wpabuf_head(pw) : NULL,
1964 pw ? wpabuf_len(pw) : 0, 1);
1965}
1966#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001967
1968
Dmitry Shmidt83474442015-04-15 13:47:09 -07001969#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001970int wpas_ap_stop_ap(struct wpa_supplicant *wpa_s)
1971{
1972 struct hostapd_data *hapd;
1973
1974 if (!wpa_s->ap_iface)
1975 return -1;
1976 hapd = wpa_s->ap_iface->bss[0];
1977 return hostapd_ctrl_iface_stop_ap(hapd);
1978}
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001979
1980
Dmitry Shmidte4663042016-04-04 10:07:49 -07001981int wpas_ap_pmksa_cache_list(struct wpa_supplicant *wpa_s, char *buf,
1982 size_t len)
1983{
1984 size_t reply_len = 0, i;
1985 char ap_delimiter[] = "---- AP ----\n";
1986 char mesh_delimiter[] = "---- mesh ----\n";
1987 size_t dlen;
1988
1989 if (wpa_s->ap_iface) {
1990 dlen = os_strlen(ap_delimiter);
1991 if (dlen > len - reply_len)
1992 return reply_len;
1993 os_memcpy(&buf[reply_len], ap_delimiter, dlen);
1994 reply_len += dlen;
1995
1996 for (i = 0; i < wpa_s->ap_iface->num_bss; i++) {
1997 reply_len += hostapd_ctrl_iface_pmksa_list(
1998 wpa_s->ap_iface->bss[i],
1999 &buf[reply_len], len - reply_len);
2000 }
2001 }
2002
2003 if (wpa_s->ifmsh) {
2004 dlen = os_strlen(mesh_delimiter);
2005 if (dlen > len - reply_len)
2006 return reply_len;
2007 os_memcpy(&buf[reply_len], mesh_delimiter, dlen);
2008 reply_len += dlen;
2009
2010 reply_len += hostapd_ctrl_iface_pmksa_list(
2011 wpa_s->ifmsh->bss[0], &buf[reply_len],
2012 len - reply_len);
2013 }
2014
2015 return reply_len;
2016}
2017
2018
2019void wpas_ap_pmksa_cache_flush(struct wpa_supplicant *wpa_s)
2020{
2021 size_t i;
2022
2023 if (wpa_s->ap_iface) {
2024 for (i = 0; i < wpa_s->ap_iface->num_bss; i++)
2025 hostapd_ctrl_iface_pmksa_flush(wpa_s->ap_iface->bss[i]);
2026 }
2027
2028 if (wpa_s->ifmsh)
2029 hostapd_ctrl_iface_pmksa_flush(wpa_s->ifmsh->bss[0]);
2030}
Paul Stewart092955c2017-02-06 09:13:09 -08002031
2032
2033#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
2034#ifdef CONFIG_MESH
2035
2036int wpas_ap_pmksa_cache_list_mesh(struct wpa_supplicant *wpa_s, const u8 *addr,
2037 char *buf, size_t len)
2038{
2039 return hostapd_ctrl_iface_pmksa_list_mesh(wpa_s->ifmsh->bss[0], addr,
2040 &buf[0], len);
2041}
2042
2043
2044int wpas_ap_pmksa_cache_add_external(struct wpa_supplicant *wpa_s, char *cmd)
2045{
2046 struct external_pmksa_cache *entry;
2047 void *pmksa_cache;
2048
2049 pmksa_cache = hostapd_ctrl_iface_pmksa_create_entry(wpa_s->own_addr,
2050 cmd);
2051 if (!pmksa_cache)
2052 return -1;
2053
2054 entry = os_zalloc(sizeof(struct external_pmksa_cache));
2055 if (!entry)
2056 return -1;
2057
2058 entry->pmksa_cache = pmksa_cache;
2059
2060 dl_list_add(&wpa_s->mesh_external_pmksa_cache, &entry->list);
2061
2062 return 0;
2063}
2064
2065#endif /* CONFIG_MESH */
2066#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
2067
Hai Shaloma20dcd72022-02-04 13:43:00 -08002068
2069int wpas_ap_update_beacon(struct wpa_supplicant *wpa_s)
2070{
2071 struct hostapd_data *hapd;
2072
2073 if (!wpa_s->ap_iface)
2074 return -1;
2075 hapd = wpa_s->ap_iface->bss[0];
2076
2077 wpabuf_free(hapd->conf->assocresp_elements);
2078 hapd->conf->assocresp_elements = NULL;
2079 if (wpa_s->conf->ap_assocresp_elements) {
2080 hapd->conf->assocresp_elements =
2081 wpabuf_dup(wpa_s->conf->ap_assocresp_elements);
2082 }
2083
2084 wpabuf_free(hapd->conf->vendor_elements);
2085 hapd->conf->vendor_elements = NULL;
2086 if (wpa_s->conf->ap_vendor_elements) {
2087 hapd->conf->vendor_elements =
2088 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
2089 }
2090
2091 return ieee802_11_set_beacon(hapd);
2092}
2093
Dmitry Shmidt849734c2016-05-27 09:59:01 -07002094#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte4663042016-04-04 10:07:49 -07002095
2096
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002097#ifdef NEED_AP_MLME
Roshan Pius3a1667e2018-07-03 15:17:14 -07002098void wpas_ap_event_dfs_radar_detected(struct wpa_supplicant *wpa_s,
2099 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002100{
Hai Shalom74f70d42019-02-11 14:42:39 -08002101 struct hostapd_iface *iface = wpa_s->ap_iface;
2102
2103 if (!iface)
2104 iface = wpa_s->ifmsh;
2105 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002106 return;
2107 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08002108 hostapd_dfs_radar_detected(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002109 radar->ht_enabled, radar->chan_offset,
2110 radar->chan_width,
2111 radar->cf1, radar->cf2);
2112}
2113
2114
Roshan Pius3a1667e2018-07-03 15:17:14 -07002115void wpas_ap_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
2116 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002117{
Hai Shalom74f70d42019-02-11 14:42:39 -08002118 struct hostapd_iface *iface = wpa_s->ap_iface;
2119
2120 if (!iface)
2121 iface = wpa_s->ifmsh;
2122 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002123 return;
2124 wpa_printf(MSG_DEBUG, "DFS CAC started on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08002125 hostapd_dfs_start_cac(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002126 radar->ht_enabled, radar->chan_offset,
2127 radar->chan_width, radar->cf1, radar->cf2);
2128}
2129
2130
Roshan Pius3a1667e2018-07-03 15:17:14 -07002131void wpas_ap_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
2132 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002133{
Hai Shalom74f70d42019-02-11 14:42:39 -08002134 struct hostapd_iface *iface = wpa_s->ap_iface;
2135
2136 if (!iface)
2137 iface = wpa_s->ifmsh;
2138 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002139 return;
2140 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08002141 hostapd_dfs_complete_cac(iface, 1, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002142 radar->ht_enabled, radar->chan_offset,
2143 radar->chan_width, radar->cf1, radar->cf2);
2144}
2145
2146
Roshan Pius3a1667e2018-07-03 15:17:14 -07002147void wpas_ap_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
2148 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002149{
Hai Shalom74f70d42019-02-11 14:42:39 -08002150 struct hostapd_iface *iface = wpa_s->ap_iface;
2151
2152 if (!iface)
2153 iface = wpa_s->ifmsh;
2154 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002155 return;
2156 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08002157 hostapd_dfs_complete_cac(iface, 0, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002158 radar->ht_enabled, radar->chan_offset,
2159 radar->chan_width, radar->cf1, radar->cf2);
2160}
2161
2162
Roshan Pius3a1667e2018-07-03 15:17:14 -07002163void wpas_ap_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s,
2164 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002165{
Hai Shalom74f70d42019-02-11 14:42:39 -08002166 struct hostapd_iface *iface = wpa_s->ap_iface;
2167
2168 if (!iface)
2169 iface = wpa_s->ifmsh;
2170 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002171 return;
2172 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08002173 hostapd_dfs_nop_finished(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002174 radar->ht_enabled, radar->chan_offset,
2175 radar->chan_width, radar->cf1, radar->cf2);
2176}
2177#endif /* NEED_AP_MLME */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08002178
2179
2180void ap_periodic(struct wpa_supplicant *wpa_s)
2181{
2182 if (wpa_s->ap_iface)
2183 hostapd_periodic_iface(wpa_s->ap_iface);
2184}