blob: a4892e788709b52b4a9eba07c25bdddfb7d7af08 [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
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070047static void wpas_conf_ap_vht(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070048 struct wpa_ssid *ssid,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070049 struct hostapd_config *conf,
50 struct hostapd_hw_modes *mode)
51{
Dmitry Shmidt21de2142014-04-08 10:50:52 -070052#ifdef CONFIG_P2P
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070053 u8 center_chan = 0;
54 u8 channel = conf->channel;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070055#endif /* CONFIG_P2P */
Hai Shalom899fcc72020-10-19 14:38:18 -070056 u8 freq_seg_idx;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070057
58 if (!conf->secondary_channel)
59 goto no_vht;
60
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070061 /* Use the maximum oper channel width if it's given. */
62 if (ssid->max_oper_chwidth)
Hai Shalom899fcc72020-10-19 14:38:18 -070063 hostapd_set_oper_chwidth(conf, ssid->max_oper_chwidth);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070064
Hai Shalom899fcc72020-10-19 14:38:18 -070065 if (hostapd_get_oper_chwidth(conf) == CHANWIDTH_80P80MHZ) {
66 ieee80211_freq_to_chan(ssid->vht_center_freq2,
67 &freq_seg_idx);
68 hostapd_set_oper_centr_freq_seg1_idx(conf, freq_seg_idx);
69 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070070
71 if (!ssid->p2p_group) {
Hai Shalom899fcc72020-10-19 14:38:18 -070072 if (!ssid->vht_center_freq1)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070073 goto no_vht;
74 ieee80211_freq_to_chan(ssid->vht_center_freq1,
Hai Shalom899fcc72020-10-19 14:38:18 -070075 &freq_seg_idx);
76 hostapd_set_oper_centr_freq_seg0_idx(conf, freq_seg_idx);
77
78 wpa_printf(MSG_DEBUG,
79 "VHT seg0 index %d and seg1 index %d for AP",
80 hostapd_get_oper_centr_freq_seg0_idx(conf),
81 hostapd_get_oper_centr_freq_seg1_idx(conf));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070082 return;
83 }
84
85#ifdef CONFIG_P2P
Hai Shalom899fcc72020-10-19 14:38:18 -070086 switch (hostapd_get_oper_chwidth(conf)) {
Hai Shalom81f62d82019-07-22 12:10:00 -070087 case CHANWIDTH_80MHZ:
88 case CHANWIDTH_80P80MHZ:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080089 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -070090 wpa_printf(MSG_DEBUG,
91 "VHT center channel %u for 80 or 80+80 MHz bandwidth",
92 center_chan);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080093 break;
Hai Shalom81f62d82019-07-22 12:10:00 -070094 case CHANWIDTH_160MHZ:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080095 center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -070096 wpa_printf(MSG_DEBUG,
97 "VHT center channel %u for 160 MHz bandwidth",
98 center_chan);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080099 break;
100 default:
101 /*
102 * conf->vht_oper_chwidth might not be set for non-P2P GO cases,
103 * try oper_cwidth 160 MHz first then VHT 80 MHz, if 160 MHz is
104 * not supported.
105 */
Hai Shalom899fcc72020-10-19 14:38:18 -0700106 hostapd_set_oper_chwidth(conf, CHANWIDTH_160MHZ);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800107 center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700108 if (center_chan) {
109 wpa_printf(MSG_DEBUG,
110 "VHT center channel %u for auto-selected 160 MHz bandwidth",
111 center_chan);
112 } else {
Hai Shalom899fcc72020-10-19 14:38:18 -0700113 hostapd_set_oper_chwidth(conf, CHANWIDTH_80MHZ);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800114 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode,
115 channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700116 wpa_printf(MSG_DEBUG,
117 "VHT center channel %u for auto-selected 80 MHz bandwidth",
118 center_chan);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800119 }
120 break;
121 }
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700122 if (!center_chan)
123 goto no_vht;
124
Hai Shalom899fcc72020-10-19 14:38:18 -0700125 hostapd_set_oper_centr_freq_seg0_idx(conf, center_chan);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700126 wpa_printf(MSG_DEBUG, "VHT seg0 index %d for P2P GO",
Hai Shalom899fcc72020-10-19 14:38:18 -0700127 hostapd_get_oper_centr_freq_seg0_idx(conf));
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700128 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700129#endif /* CONFIG_P2P */
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700130
131no_vht:
Roshan Pius3a1667e2018-07-03 15:17:14 -0700132 wpa_printf(MSG_DEBUG,
133 "No VHT higher bandwidth support for the selected channel %d",
134 conf->channel);
Hai Shalom899fcc72020-10-19 14:38:18 -0700135 hostapd_set_oper_centr_freq_seg0_idx(
136 conf, conf->channel + conf->secondary_channel * 2);
137 hostapd_set_oper_chwidth(conf, CHANWIDTH_USE_HT);
138}
139
140
141static struct hostapd_hw_modes *
142wpa_supplicant_find_hw_mode(struct wpa_supplicant *wpa_s,
143 enum hostapd_hw_mode hw_mode)
144{
145 struct hostapd_hw_modes *mode = NULL;
146 int i;
147
148 for (i = 0; i < wpa_s->hw.num_modes; i++) {
149 if (wpa_s->hw.modes[i].mode == hw_mode) {
150 mode = &wpa_s->hw.modes[i];
151 break;
152 }
153 }
154
155 return mode;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700156}
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700157
158
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800159int wpa_supplicant_conf_ap_ht(struct wpa_supplicant *wpa_s,
160 struct wpa_ssid *ssid,
161 struct hostapd_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700162{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800163 conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency,
164 &conf->channel);
165
166 if (conf->hw_mode == NUM_HOSTAPD_MODES) {
167 wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
168 ssid->frequency);
169 return -1;
170 }
171
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700172 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800173 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
174 * and a mask of allowed capabilities within conf->ht_capab.
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700175 * Using default config settings for: conf->ht_op_mode_fixed,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800176 * conf->secondary_channel, conf->require_ht
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700177 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800178 if (wpa_s->hw.modes) {
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700179 struct hostapd_hw_modes *mode = NULL;
Hai Shalom899fcc72020-10-19 14:38:18 -0700180 int no_ht = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700181
182 wpa_printf(MSG_DEBUG,
183 "Determining HT/VHT options based on driver capabilities (freq=%u chan=%u)",
184 ssid->frequency, conf->channel);
185
Hai Shalom899fcc72020-10-19 14:38:18 -0700186 mode = wpa_supplicant_find_hw_mode(wpa_s, conf->hw_mode);
187
188 /* May drop to IEEE 802.11b if the driver does not support IEEE
189 * 802.11g */
190 if (!mode && conf->hw_mode == HOSTAPD_MODE_IEEE80211G) {
191 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
192 wpa_printf(MSG_INFO,
193 "Try downgrade to IEEE 802.11b as 802.11g is not supported by the current hardware");
194 mode = wpa_supplicant_find_hw_mode(wpa_s,
195 conf->hw_mode);
196 }
197
198 if (!mode) {
199 wpa_printf(MSG_ERROR,
200 "No match between requested and supported hw modes found");
201 return -1;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700202 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700203
204#ifdef CONFIG_HT_OVERRIDES
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700205 if (ssid->disable_ht)
206 ssid->ht = 0;
207#endif /* CONFIG_HT_OVERRIDES */
208
209 if (!ssid->ht) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700210 wpa_printf(MSG_DEBUG,
211 "HT not enabled in network profile");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700212 conf->ieee80211n = 0;
213 conf->ht_capab = 0;
214 no_ht = 1;
215 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700216
217 if (!no_ht && mode && mode->ht_capab) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700218 wpa_printf(MSG_DEBUG,
219 "Enable HT support (p2p_group=%d 11a=%d ht40_hw_capab=%d ssid->ht40=%d)",
220 ssid->p2p_group,
221 conf->hw_mode == HOSTAPD_MODE_IEEE80211A,
222 !!(mode->ht_capab &
223 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET),
224 ssid->ht40);
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700225 conf->ieee80211n = 1;
Hai Shalom899fcc72020-10-19 14:38:18 -0700226
227 if (ssid->ht40 &&
228 (mode->ht_capab &
229 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
230 conf->secondary_channel = ssid->ht40;
231 else
232 conf->secondary_channel = 0;
233
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700234#ifdef CONFIG_P2P
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700235 if (ssid->p2p_group &&
236 conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700237 (mode->ht_capab &
238 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -0700239 ssid->ht40) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700240 conf->secondary_channel =
241 wpas_p2p_get_ht40_mode(wpa_s, mode,
242 conf->channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700243 wpa_printf(MSG_DEBUG,
244 "HT secondary channel offset %d for P2P group",
245 conf->secondary_channel);
246 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700247#endif /* CONFIG_P2P */
248
249 if (!ssid->p2p_group &&
250 (mode->ht_capab &
Roshan Pius3a1667e2018-07-03 15:17:14 -0700251 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700252 conf->secondary_channel = ssid->ht40;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700253 wpa_printf(MSG_DEBUG,
254 "HT secondary channel offset %d for AP",
255 conf->secondary_channel);
256 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700257
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700258 if (conf->secondary_channel)
259 conf->ht_capab |=
260 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800261
262 /*
263 * white-list capabilities that won't cause issues
264 * to connecting stations, while leaving the current
265 * capabilities intact (currently disabled SMPS).
266 */
267 conf->ht_capab |= mode->ht_capab &
268 (HT_CAP_INFO_GREEN_FIELD |
269 HT_CAP_INFO_SHORT_GI20MHZ |
270 HT_CAP_INFO_SHORT_GI40MHZ |
271 HT_CAP_INFO_RX_STBC_MASK |
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800272 HT_CAP_INFO_TX_STBC |
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800273 HT_CAP_INFO_MAX_AMSDU_SIZE);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700274
Hai Shalom899fcc72020-10-19 14:38:18 -0700275 /* check this before VHT, because setting oper chan
276 * width and friends is the same call for HE and VHT
277 * and checks if conf->ieee8021ax == 1 */
278 if (mode->he_capab[wpas_mode_to_ieee80211_mode(
279 ssid->mode)].he_supported &&
280 ssid->he)
281 conf->ieee80211ax = 1;
282
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700283 if (mode->vht_capab && ssid->vht) {
284 conf->ieee80211ac = 1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800285 conf->vht_capab |= mode->vht_capab;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700286 wpas_conf_ap_vht(wpa_s, ssid, conf, mode);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700287 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800288 }
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700289 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800290
291 if (conf->secondary_channel) {
292 struct wpa_supplicant *iface;
293
294 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
295 {
296 if (iface == wpa_s ||
297 iface->wpa_state < WPA_AUTHENTICATING ||
298 (int) iface->assoc_freq != ssid->frequency)
299 continue;
300
301 /*
302 * Do not allow 40 MHz co-ex PRI/SEC switch to force us
303 * to change our PRI channel since we have an existing,
304 * concurrent connection on that channel and doing
305 * multi-channel concurrency is likely to cause more
306 * harm than using different PRI/SEC selection in
307 * environment with multiple BSSes on these two channels
308 * with mixed 20 MHz or PRI channel selection.
309 */
310 conf->no_pri_sec_switch = 1;
311 }
312 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800313
314 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800315}
316
317
318static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
319 struct wpa_ssid *ssid,
320 struct hostapd_config *conf)
321{
322 struct hostapd_bss_config *bss = conf->bss[0];
323
324 conf->driver = wpa_s->driver;
325
326 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
327
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800328 if (wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800329 return -1;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700330
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700331 if (ssid->pbss > 1) {
332 wpa_printf(MSG_ERROR, "Invalid pbss value(%d) for AP mode",
333 ssid->pbss);
334 return -1;
335 }
336 bss->pbss = ssid->pbss;
337
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800338#ifdef CONFIG_ACS
339 if (ssid->acs) {
340 /* Setting channel to 0 in order to enable ACS */
341 conf->channel = 0;
342 wpa_printf(MSG_DEBUG, "Use automatic channel selection");
343 }
344#endif /* CONFIG_ACS */
345
Roshan Pius3a1667e2018-07-03 15:17:14 -0700346 if (ieee80211_is_dfs(ssid->frequency, wpa_s->hw.modes,
347 wpa_s->hw.num_modes) && wpa_s->conf->country[0]) {
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800348 conf->ieee80211h = 1;
349 conf->ieee80211d = 1;
350 conf->country[0] = wpa_s->conf->country[0];
351 conf->country[1] = wpa_s->conf->country[1];
Paul Stewart092955c2017-02-06 09:13:09 -0800352 conf->country[2] = ' ';
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800353 }
354
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700355#ifdef CONFIG_P2P
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700356 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
357 (ssid->mode == WPAS_MODE_P2P_GO ||
358 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700359 /* Remove 802.11b rates from supported and basic rate sets */
360 int *list = os_malloc(4 * sizeof(int));
361 if (list) {
362 list[0] = 60;
363 list[1] = 120;
364 list[2] = 240;
365 list[3] = -1;
366 }
367 conf->basic_rates = list;
368
369 list = os_malloc(9 * sizeof(int));
370 if (list) {
371 list[0] = 60;
372 list[1] = 90;
373 list[2] = 120;
374 list[3] = 180;
375 list[4] = 240;
376 list[5] = 360;
377 list[6] = 480;
378 list[7] = 540;
379 list[8] = -1;
380 }
381 conf->supported_rates = list;
Hai Shalom021b0b52019-04-10 11:17:58 -0700382 }
383
Hai Shalom74f70d42019-02-11 14:42:39 -0800384#ifdef CONFIG_IEEE80211AX
Hai Shalom021b0b52019-04-10 11:17:58 -0700385 if (ssid->mode == WPAS_MODE_P2P_GO ||
386 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Hai Shalom74f70d42019-02-11 14:42:39 -0800387 conf->ieee80211ax = ssid->he;
388#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800389
390 bss->isolate = !wpa_s->conf->p2p_intra_bss;
Hai Shalomfdcde762020-04-02 11:19:20 -0700391 bss->extended_key_id = wpa_s->conf->extended_key_id;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700392 bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
Hai Shalomfdcde762020-04-02 11:19:20 -0700393 bss->wpa_deny_ptk0_rekey = ssid->wpa_deny_ptk0_rekey;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800394
395 if (ssid->p2p_group) {
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800396 os_memcpy(bss->ip_addr_go, wpa_s->p2pdev->conf->ip_addr_go, 4);
397 os_memcpy(bss->ip_addr_mask, wpa_s->p2pdev->conf->ip_addr_mask,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800398 4);
399 os_memcpy(bss->ip_addr_start,
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800400 wpa_s->p2pdev->conf->ip_addr_start, 4);
401 os_memcpy(bss->ip_addr_end, wpa_s->p2pdev->conf->ip_addr_end,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800402 4);
403 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700404#endif /* CONFIG_P2P */
405
406 if (ssid->ssid_len == 0) {
407 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
408 return -1;
409 }
410 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700411 bss->ssid.ssid_len = ssid->ssid_len;
412 bss->ssid.ssid_set = 1;
413
Dmitry Shmidt04949592012-07-19 12:16:46 -0700414 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
415
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800416 if (ssid->auth_alg)
417 bss->auth_algs = ssid->auth_alg;
418
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700419 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
420 bss->wpa = ssid->proto;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700421 if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
422 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
423 else
424 bss->wpa_key_mgmt = ssid->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700425 bss->wpa_pairwise = ssid->pairwise_cipher;
Hai Shalomc3565922019-10-28 11:58:20 -0700426 if (wpa_key_mgmt_sae(bss->wpa_key_mgmt) && ssid->passphrase) {
427 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
428 } else if (ssid->psk_set) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800429 bin_clear_free(bss->ssid.wpa_psk, sizeof(*bss->ssid.wpa_psk));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700430 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
431 if (bss->ssid.wpa_psk == NULL)
432 return -1;
433 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
434 bss->ssid.wpa_psk->group = 1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700435 bss->ssid.wpa_psk_set = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800436 } else if (ssid->passphrase) {
437 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
Hai Shalomfdcde762020-04-02 11:19:20 -0700438#ifdef CONFIG_WEP
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800439 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
440 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
441 struct hostapd_wep_keys *wep = &bss->ssid.wep;
442 int i;
443 for (i = 0; i < NUM_WEP_KEYS; i++) {
444 if (ssid->wep_key_len[i] == 0)
445 continue;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700446 wep->key[i] = os_memdup(ssid->wep_key[i],
447 ssid->wep_key_len[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800448 if (wep->key[i] == NULL)
449 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800450 wep->len[i] = ssid->wep_key_len[i];
451 }
452 wep->idx = ssid->wep_tx_keyidx;
453 wep->keys_set = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700454#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700455 }
Hai Shalomc3565922019-10-28 11:58:20 -0700456#ifdef CONFIG_SAE
457 if (ssid->sae_password) {
458 struct sae_password_entry *pw;
459
460 pw = os_zalloc(sizeof(*pw));
461 if (!pw)
462 return -1;
463 os_memset(pw->peer_addr, 0xff, ETH_ALEN);
464 pw->password = os_strdup(ssid->sae_password);
465 if (!pw->password) {
466 os_free(pw);
467 return -1;
468 }
469 if (ssid->sae_password_id) {
470 pw->identifier = os_strdup(ssid->sae_password_id);
471 if (!pw->identifier) {
472 str_clear_free(pw->password);
473 os_free(pw);
474 return -1;
475 }
476 }
477
478 pw->next = bss->sae_passwords;
479 bss->sae_passwords = pw;
480 }
481
482 bss->sae_pwe = wpa_s->conf->sae_pwe;
483#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700484
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700485 if (wpa_s->conf->go_interworking) {
486 wpa_printf(MSG_DEBUG,
487 "P2P: Enable Interworking with access_network_type: %d",
488 wpa_s->conf->go_access_network_type);
489 bss->interworking = wpa_s->conf->go_interworking;
490 bss->access_network_type = wpa_s->conf->go_access_network_type;
491 bss->internet = wpa_s->conf->go_internet;
492 if (wpa_s->conf->go_venue_group) {
493 wpa_printf(MSG_DEBUG,
494 "P2P: Venue group: %d Venue type: %d",
495 wpa_s->conf->go_venue_group,
496 wpa_s->conf->go_venue_type);
497 bss->venue_group = wpa_s->conf->go_venue_group;
498 bss->venue_type = wpa_s->conf->go_venue_type;
499 bss->venue_info_set = 1;
500 }
501 }
502
Dmitry Shmidt04949592012-07-19 12:16:46 -0700503 if (ssid->ap_max_inactivity)
504 bss->ap_max_inactivity = ssid->ap_max_inactivity;
505
506 if (ssid->dtim_period)
507 bss->dtim_period = ssid->dtim_period;
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -0800508 else if (wpa_s->conf->dtim_period)
509 bss->dtim_period = wpa_s->conf->dtim_period;
510
511 if (ssid->beacon_int)
512 conf->beacon_int = ssid->beacon_int;
513 else if (wpa_s->conf->beacon_int)
514 conf->beacon_int = wpa_s->conf->beacon_int;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700515
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800516#ifdef CONFIG_P2P
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800517 if (ssid->mode == WPAS_MODE_P2P_GO ||
518 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
519 if (wpa_s->conf->p2p_go_ctwindow > conf->beacon_int) {
520 wpa_printf(MSG_INFO,
521 "CTWindow (%d) is bigger than beacon interval (%d) - avoid configuring it",
522 wpa_s->conf->p2p_go_ctwindow,
523 conf->beacon_int);
524 conf->p2p_go_ctwindow = 0;
525 } else {
526 conf->p2p_go_ctwindow = wpa_s->conf->p2p_go_ctwindow;
527 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800528 }
529#endif /* CONFIG_P2P */
530
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800531 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
532 bss->rsn_pairwise = bss->wpa_pairwise;
533 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
534 bss->rsn_pairwise);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700535
Hai Shalomfdcde762020-04-02 11:19:20 -0700536 if (bss->wpa && bss->ieee802_1x) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700537 bss->ssid.security_policy = SECURITY_WPA;
Hai Shalomfdcde762020-04-02 11:19:20 -0700538 } else if (bss->wpa) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700539 bss->ssid.security_policy = SECURITY_WPA_PSK;
Hai Shalomfdcde762020-04-02 11:19:20 -0700540#ifdef CONFIG_WEP
541 } else if (bss->ieee802_1x) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800542 int cipher = WPA_CIPHER_NONE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700543 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
544 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800545 if (bss->default_wep_key_len)
546 cipher = bss->default_wep_key_len >= 13 ?
547 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
548 bss->wpa_group = cipher;
549 bss->wpa_pairwise = cipher;
550 bss->rsn_pairwise = cipher;
551 } else if (bss->ssid.wep.keys_set) {
552 int cipher = WPA_CIPHER_WEP40;
553 if (bss->ssid.wep.len[0] >= 13)
554 cipher = WPA_CIPHER_WEP104;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700555 bss->ssid.security_policy = SECURITY_STATIC_WEP;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800556 bss->wpa_group = cipher;
557 bss->wpa_pairwise = cipher;
558 bss->rsn_pairwise = cipher;
Hai Shalomfdcde762020-04-02 11:19:20 -0700559#endif /* CONFIG_WEP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800560 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700561 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800562 bss->wpa_group = WPA_CIPHER_NONE;
563 bss->wpa_pairwise = WPA_CIPHER_NONE;
564 bss->rsn_pairwise = WPA_CIPHER_NONE;
565 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700566
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700567 if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
568 (bss->wpa_group == WPA_CIPHER_CCMP ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800569 bss->wpa_group == WPA_CIPHER_GCMP ||
570 bss->wpa_group == WPA_CIPHER_CCMP_256 ||
571 bss->wpa_group == WPA_CIPHER_GCMP_256)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700572 /*
573 * Strong ciphers do not need frequent rekeying, so increase
574 * the default GTK rekeying period to 24 hours.
575 */
576 bss->wpa_group_rekey = 86400;
577 }
578
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700579 if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT)
580 bss->ieee80211w = ssid->ieee80211w;
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700581
Hai Shalom74f70d42019-02-11 14:42:39 -0800582#ifdef CONFIG_OCV
583 bss->ocv = ssid->ocv;
584#endif /* CONFIG_OCV */
585
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700586#ifdef CONFIG_WPS
587 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800588 * Enable WPS by default for open and WPA/WPA2-Personal network, but
589 * require user interaction to actually use it. Only the internal
590 * Registrar is supported.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700591 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800592 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
593 bss->ssid.security_policy != SECURITY_PLAINTEXT)
594 goto no_wps;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800595 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800596 (!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ||
597 !(bss->wpa & 2)))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800598 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
599 * configuration */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700600 if (ssid->wps_disabled)
601 goto no_wps;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700602 bss->eap_server = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700603
604 if (!ssid->ignore_broadcast_ssid)
605 bss->wps_state = 2;
606
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700607 bss->ap_setup_locked = 2;
608 if (wpa_s->conf->config_methods)
609 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
610 os_memcpy(bss->device_type, wpa_s->conf->device_type,
611 WPS_DEV_TYPE_LEN);
612 if (wpa_s->conf->device_name) {
613 bss->device_name = os_strdup(wpa_s->conf->device_name);
614 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
615 }
616 if (wpa_s->conf->manufacturer)
617 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
618 if (wpa_s->conf->model_name)
619 bss->model_name = os_strdup(wpa_s->conf->model_name);
620 if (wpa_s->conf->model_number)
621 bss->model_number = os_strdup(wpa_s->conf->model_number);
622 if (wpa_s->conf->serial_number)
623 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
624 if (is_nil_uuid(wpa_s->conf->uuid))
625 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
626 else
627 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
628 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700629 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -0700630 if (ssid->eap.fragment_size != DEFAULT_FRAGMENT_SIZE)
631 bss->fragment_size = ssid->eap.fragment_size;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800632no_wps:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700633#endif /* CONFIG_WPS */
634
635 if (wpa_s->max_stations &&
636 wpa_s->max_stations < wpa_s->conf->max_num_sta)
637 bss->max_num_sta = wpa_s->max_stations;
638 else
639 bss->max_num_sta = wpa_s->conf->max_num_sta;
640
Roshan Pius3a1667e2018-07-03 15:17:14 -0700641 if (!bss->isolate)
642 bss->isolate = wpa_s->conf->ap_isolate;
643
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700644 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
645
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700646 if (wpa_s->conf->ap_vendor_elements) {
647 bss->vendor_elements =
648 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
649 }
650
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700651 bss->ftm_responder = wpa_s->conf->ftm_responder;
652 bss->ftm_initiator = wpa_s->conf->ftm_initiator;
653
Hai Shalomfdcde762020-04-02 11:19:20 -0700654 bss->transition_disable = ssid->transition_disable;
655
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700656 return 0;
657}
658
659
660static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
661{
662#ifdef CONFIG_P2P
663 struct wpa_supplicant *wpa_s = ctx;
664 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700665
666 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700667 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700668 return;
Dmitry Shmidt18463232014-01-24 12:29:41 -0800669 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
670 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700671 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
672 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700673 buf + IEEE80211_HDRLEN + 1,
674 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700675#endif /* CONFIG_P2P */
676}
677
678
679static void ap_wps_event_cb(void *ctx, enum wps_event event,
680 union wps_event_data *data)
681{
682#ifdef CONFIG_P2P
683 struct wpa_supplicant *wpa_s = ctx;
684
Jouni Malinen75ecf522011-06-27 15:19:46 -0700685 if (event == WPS_EV_FAIL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700686 struct wps_event_fail *fail = &data->fail;
687
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800688 if (wpa_s->p2pdev && wpa_s->p2pdev != wpa_s &&
Jouni Malinen75ecf522011-06-27 15:19:46 -0700689 wpa_s == wpa_s->global->p2p_group_formation) {
690 /*
691 * src/ap/wps_hostapd.c has already sent this on the
692 * main interface, so only send on the parent interface
693 * here if needed.
694 */
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800695 wpa_msg(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_FAIL
Jouni Malinen75ecf522011-06-27 15:19:46 -0700696 "msg=%d config_error=%d",
697 fail->msg, fail->config_error);
698 }
699 wpas_p2p_wps_failed(wpa_s, fail);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700700 }
701#endif /* CONFIG_P2P */
702}
703
704
705static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800706 int authorized, const u8 *p2p_dev_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700707{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800708 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700709}
710
711
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700712#ifdef CONFIG_P2P
713static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
714 const u8 *psk, size_t psk_len)
715{
716
717 struct wpa_supplicant *wpa_s = ctx;
718 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
719 return;
720 wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
721}
722#endif /* CONFIG_P2P */
723
724
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700725static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
726{
727#ifdef CONFIG_P2P
728 struct wpa_supplicant *wpa_s = ctx;
729 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700730
731 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700732 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700733 return -1;
734 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
735 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700736 buf + IEEE80211_HDRLEN + 1,
737 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700738#endif /* CONFIG_P2P */
739 return 0;
740}
741
742
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800743static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700744 const u8 *bssid, const u8 *ie, size_t ie_len,
745 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700746{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700747 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700748 unsigned int freq = 0;
749
750 if (wpa_s->ap_iface)
751 freq = wpa_s->ap_iface->freq;
752
Dmitry Shmidt04949592012-07-19 12:16:46 -0700753 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700754 freq, ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700755}
756
757
758static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
759 const u8 *uuid_e)
760{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700761 struct wpa_supplicant *wpa_s = ctx;
762 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700763}
764
765
766static void wpas_ap_configured_cb(void *ctx)
767{
768 struct wpa_supplicant *wpa_s = ctx;
769
Roshan Pius3a1667e2018-07-03 15:17:14 -0700770 wpa_printf(MSG_DEBUG, "AP interface setup completed - state %s",
771 hostapd_state_text(wpa_s->ap_iface->state));
772 if (wpa_s->ap_iface->state == HAPD_IFACE_DISABLED) {
773 wpa_supplicant_ap_deinit(wpa_s);
774 return;
775 }
776
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800777#ifdef CONFIG_ACS
Roshan Pius3a1667e2018-07-03 15:17:14 -0700778 if (wpa_s->current_ssid && wpa_s->current_ssid->acs) {
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800779 wpa_s->assoc_freq = wpa_s->ap_iface->freq;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700780 wpa_s->current_ssid->frequency = wpa_s->ap_iface->freq;
781 }
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800782#endif /* CONFIG_ACS */
783
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700784 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
785
786 if (wpa_s->ap_configured_cb)
787 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
788 wpa_s->ap_configured_cb_data);
789}
790
791
792int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
793 struct wpa_ssid *ssid)
794{
795 struct wpa_driver_associate_params params;
796 struct hostapd_iface *hapd_iface;
797 struct hostapd_config *conf;
798 size_t i;
799
800 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
801 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
802 return -1;
803 }
804
805 wpa_supplicant_ap_deinit(wpa_s);
806
807 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
808 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
809
810 os_memset(&params, 0, sizeof(params));
811 params.ssid = ssid->ssid;
812 params.ssid_len = ssid->ssid_len;
813 switch (ssid->mode) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700814 case WPAS_MODE_AP:
815 case WPAS_MODE_P2P_GO:
816 case WPAS_MODE_P2P_GROUP_FORMATION:
817 params.mode = IEEE80211_MODE_AP;
818 break;
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800819 default:
820 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700821 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700822 if (ssid->frequency == 0)
823 ssid->frequency = 2462; /* default channel 11 */
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700824 params.freq.freq = ssid->frequency;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700825
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800826 if ((ssid->mode == WPAS_MODE_AP || ssid->mode == WPAS_MODE_P2P_GO) &&
827 ssid->enable_edmg) {
Hai Shalomc3565922019-10-28 11:58:20 -0700828 u8 primary_channel;
829
830 if (ieee80211_freq_to_chan(ssid->frequency, &primary_channel) ==
831 NUM_HOSTAPD_MODES) {
832 wpa_printf(MSG_WARNING,
833 "EDMG: Failed to get the primary channel");
834 return -1;
835 }
836
837 hostapd_encode_edmg_chan(ssid->enable_edmg, ssid->edmg_channel,
838 primary_channel, &params.freq.edmg);
839 }
840
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800841 params.wpa_proto = ssid->proto;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700842 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
843 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
844 else
845 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800846 params.key_mgmt_suite = wpa_s->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700847
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800848 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
849 1);
850 if (wpa_s->pairwise_cipher < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700851 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
852 "cipher.");
853 return -1;
854 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800855 params.pairwise_suite = wpa_s->pairwise_cipher;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700856 params.group_suite = params.pairwise_suite;
857
858#ifdef CONFIG_P2P
859 if (ssid->mode == WPAS_MODE_P2P_GO ||
860 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
861 params.p2p = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700862#endif /* CONFIG_P2P */
863
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800864 if (wpa_s->p2pdev->set_ap_uapsd)
865 params.uapsd = wpa_s->p2pdev->ap_uapsd;
Dmitry Shmidtec58b162014-02-19 12:44:18 -0800866 else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
867 params.uapsd = 1; /* mandatory for P2P GO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700868 else
869 params.uapsd = -1;
870
Roshan Pius3a1667e2018-07-03 15:17:14 -0700871 if (ieee80211_is_dfs(params.freq.freq, wpa_s->hw.modes,
872 wpa_s->hw.num_modes))
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800873 params.freq.freq = 0; /* set channel after CAC */
874
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700875 if (params.p2p)
876 wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_GO);
877 else
878 wpa_drv_get_ext_capa(wpa_s, WPA_IF_AP_BSS);
879
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700880 if (wpa_drv_associate(wpa_s, &params) < 0) {
881 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
882 return -1;
883 }
884
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700885 wpa_s->ap_iface = hapd_iface = hostapd_alloc_iface();
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700886 if (hapd_iface == NULL)
887 return -1;
888 hapd_iface->owner = wpa_s;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800889 hapd_iface->drv_flags = wpa_s->drv_flags;
890 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700891 hapd_iface->extended_capa = wpa_s->extended_capa;
892 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
893 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700894
895 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
896 if (conf == NULL) {
897 wpa_supplicant_ap_deinit(wpa_s);
898 return -1;
899 }
900
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700901 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
902 wpa_s->conf->wmm_ac_params,
903 sizeof(wpa_s->conf->wmm_ac_params));
904
Hai Shalom899fcc72020-10-19 14:38:18 -0700905 os_memcpy(wpa_s->ap_iface->conf->tx_queue, wpa_s->conf->tx_queue,
906 sizeof(wpa_s->conf->tx_queue));
907
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800908 if (params.uapsd > 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800909 conf->bss[0]->wmm_enabled = 1;
910 conf->bss[0]->wmm_uapsd = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800911 }
912
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700913 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
914 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
915 wpa_supplicant_ap_deinit(wpa_s);
916 return -1;
917 }
918
919#ifdef CONFIG_P2P
920 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800921 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700922 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800923 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700924 P2P_GROUP_FORMATION;
925#endif /* CONFIG_P2P */
926
927 hapd_iface->num_bss = conf->num_bss;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700928 hapd_iface->bss = os_calloc(conf->num_bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700929 sizeof(struct hostapd_data *));
930 if (hapd_iface->bss == NULL) {
931 wpa_supplicant_ap_deinit(wpa_s);
932 return -1;
933 }
934
935 for (i = 0; i < conf->num_bss; i++) {
936 hapd_iface->bss[i] =
937 hostapd_alloc_bss_data(hapd_iface, conf,
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800938 conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700939 if (hapd_iface->bss[i] == NULL) {
940 wpa_supplicant_ap_deinit(wpa_s);
941 return -1;
942 }
943
944 hapd_iface->bss[i]->msg_ctx = wpa_s;
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800945 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->p2pdev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700946 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
947 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
948 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
949 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
950 hostapd_register_probereq_cb(hapd_iface->bss[i],
951 ap_probe_req_rx, wpa_s);
952 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
953 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
954 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
955 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
956 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
957 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
958#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700959 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
960 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700961 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700962 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
963 ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700964#endif /* CONFIG_P2P */
965 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
966 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800967#ifdef CONFIG_TESTING_OPTIONS
968 hapd_iface->bss[i]->ext_eapol_frame_io =
969 wpa_s->ext_eapol_frame_io;
970#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700971 }
972
973 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
974 hapd_iface->bss[0]->driver = wpa_s->driver;
975 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
976
977 wpa_s->current_ssid = ssid;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700978 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700979 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
980 wpa_s->assoc_freq = ssid->frequency;
Hai Shalomc3565922019-10-28 11:58:20 -0700981 wpa_s->ap_iface->conf->enable_edmg = ssid->enable_edmg;
982 wpa_s->ap_iface->conf->edmg_channel = ssid->edmg_channel;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700983
Roshan Pius3a1667e2018-07-03 15:17:14 -0700984#if defined(CONFIG_P2P) && defined(CONFIG_ACS)
985 if (wpa_s->p2p_go_do_acs) {
986 wpa_s->ap_iface->conf->channel = 0;
987 wpa_s->ap_iface->conf->hw_mode = wpa_s->p2p_go_acs_band;
988 ssid->acs = 1;
989 }
990#endif /* CONFIG_P2P && CONFIG_ACS */
991
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700992 if (hostapd_setup_interface(wpa_s->ap_iface)) {
993 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
994 wpa_supplicant_ap_deinit(wpa_s);
995 return -1;
996 }
997
998 return 0;
999}
1000
1001
1002void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
1003{
1004#ifdef CONFIG_WPS
1005 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1006#endif /* CONFIG_WPS */
1007
1008 if (wpa_s->ap_iface == NULL)
1009 return;
1010
1011 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001012 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001013 wpa_s->assoc_freq = 0;
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07001014 wpas_p2p_ap_deinit(wpa_s);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001015 wpa_s->ap_iface->driver_ap_teardown =
1016 !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
1017
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001018 hostapd_interface_deinit(wpa_s->ap_iface);
1019 hostapd_interface_free(wpa_s->ap_iface);
1020 wpa_s->ap_iface = NULL;
1021 wpa_drv_deinit_ap(wpa_s);
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07001022 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1023 " reason=%d locally_generated=1",
1024 MAC2STR(wpa_s->own_addr), WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001025}
1026
1027
1028void ap_tx_status(void *ctx, const u8 *addr,
1029 const u8 *buf, size_t len, int ack)
1030{
1031#ifdef NEED_AP_MLME
1032 struct wpa_supplicant *wpa_s = ctx;
1033 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
1034#endif /* NEED_AP_MLME */
1035}
1036
1037
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001038void ap_eapol_tx_status(void *ctx, const u8 *dst,
1039 const u8 *data, size_t len, int ack)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001040{
1041#ifdef NEED_AP_MLME
1042 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001043 if (!wpa_s->ap_iface)
1044 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001045 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
1046#endif /* NEED_AP_MLME */
1047}
1048
1049
1050void ap_client_poll_ok(void *ctx, const u8 *addr)
1051{
1052#ifdef NEED_AP_MLME
1053 struct wpa_supplicant *wpa_s = ctx;
1054 if (wpa_s->ap_iface)
1055 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
1056#endif /* NEED_AP_MLME */
1057}
1058
1059
1060void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
1061{
1062#ifdef NEED_AP_MLME
1063 struct wpa_supplicant *wpa_s = ctx;
1064 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001065#endif /* NEED_AP_MLME */
1066}
1067
1068
1069void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
1070{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001071#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001072 struct wpa_supplicant *wpa_s = ctx;
1073 struct hostapd_frame_info fi;
1074 os_memset(&fi, 0, sizeof(fi));
1075 fi.datarate = rx_mgmt->datarate;
1076 fi.ssi_signal = rx_mgmt->ssi_signal;
1077 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
1078 rx_mgmt->frame_len, &fi);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001079#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001080}
1081
1082
1083void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
1084{
1085#ifdef NEED_AP_MLME
1086 struct wpa_supplicant *wpa_s = ctx;
1087 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
1088#endif /* NEED_AP_MLME */
1089}
1090
1091
1092void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
1093 const u8 *src_addr, const u8 *buf, size_t len)
1094{
1095 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
1096}
1097
1098
1099#ifdef CONFIG_WPS
1100
1101int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
1102 const u8 *p2p_dev_addr)
1103{
1104 if (!wpa_s->ap_iface)
1105 return -1;
1106 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
1107 p2p_dev_addr);
1108}
1109
1110
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001111int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
1112{
1113 struct wps_registrar *reg;
1114 int reg_sel = 0, wps_sta = 0;
1115
1116 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
1117 return -1;
1118
1119 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
1120 reg_sel = wps_registrar_wps_cancel(reg);
1121 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
Dmitry Shmidt04949592012-07-19 12:16:46 -07001122 ap_sta_wps_cancel, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001123
1124 if (!reg_sel && !wps_sta) {
1125 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
1126 "time");
1127 return -1;
1128 }
1129
1130 /*
1131 * There are 2 cases to return wps cancel as success:
1132 * 1. When wps cancel was initiated but no connection has been
1133 * established with client yet.
1134 * 2. Client is in the middle of exchanging WPS messages.
1135 */
1136
1137 return 0;
1138}
1139
1140
1141int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001142 const char *pin, char *buf, size_t buflen,
1143 int timeout)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001144{
1145 int ret, ret_len = 0;
1146
1147 if (!wpa_s->ap_iface)
1148 return -1;
1149
1150 if (pin == NULL) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001151 unsigned int rpin;
1152
1153 if (wps_generate_pin(&rpin) < 0)
1154 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001155 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001156 if (os_snprintf_error(buflen, ret_len))
1157 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001158 pin = buf;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001159 } else if (buf) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001160 ret_len = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001161 if (os_snprintf_error(buflen, ret_len))
1162 return -1;
1163 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001164
1165 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001166 timeout);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001167 if (ret)
1168 return -1;
1169 return ret_len;
1170}
1171
1172
1173static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
1174{
1175 struct wpa_supplicant *wpa_s = eloop_data;
1176 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
1177 wpas_wps_ap_pin_disable(wpa_s);
1178}
1179
1180
1181static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
1182{
1183 struct hostapd_data *hapd;
1184
1185 if (wpa_s->ap_iface == NULL)
1186 return;
1187 hapd = wpa_s->ap_iface->bss[0];
1188 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
1189 hapd->ap_pin_failures = 0;
1190 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1191 if (timeout > 0)
1192 eloop_register_timeout(timeout, 0,
1193 wpas_wps_ap_pin_timeout, wpa_s, NULL);
1194}
1195
1196
1197void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
1198{
1199 struct hostapd_data *hapd;
1200
1201 if (wpa_s->ap_iface == NULL)
1202 return;
1203 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
1204 hapd = wpa_s->ap_iface->bss[0];
1205 os_free(hapd->conf->ap_pin);
1206 hapd->conf->ap_pin = NULL;
1207 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1208}
1209
1210
1211const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
1212{
1213 struct hostapd_data *hapd;
1214 unsigned int pin;
1215 char pin_txt[9];
1216
1217 if (wpa_s->ap_iface == NULL)
1218 return NULL;
1219 hapd = wpa_s->ap_iface->bss[0];
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001220 if (wps_generate_pin(&pin) < 0)
1221 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001222 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001223 os_free(hapd->conf->ap_pin);
1224 hapd->conf->ap_pin = os_strdup(pin_txt);
1225 if (hapd->conf->ap_pin == NULL)
1226 return NULL;
1227 wpas_wps_ap_pin_enable(wpa_s, timeout);
1228
1229 return hapd->conf->ap_pin;
1230}
1231
1232
1233const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
1234{
1235 struct hostapd_data *hapd;
1236 if (wpa_s->ap_iface == NULL)
1237 return NULL;
1238 hapd = wpa_s->ap_iface->bss[0];
1239 return hapd->conf->ap_pin;
1240}
1241
1242
1243int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
1244 int timeout)
1245{
1246 struct hostapd_data *hapd;
1247 char pin_txt[9];
1248 int ret;
1249
1250 if (wpa_s->ap_iface == NULL)
1251 return -1;
1252 hapd = wpa_s->ap_iface->bss[0];
1253 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001254 if (os_snprintf_error(sizeof(pin_txt), ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001255 return -1;
1256 os_free(hapd->conf->ap_pin);
1257 hapd->conf->ap_pin = os_strdup(pin_txt);
1258 if (hapd->conf->ap_pin == NULL)
1259 return -1;
1260 wpas_wps_ap_pin_enable(wpa_s, timeout);
1261
1262 return 0;
1263}
1264
1265
1266void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
1267{
1268 struct hostapd_data *hapd;
1269
1270 if (wpa_s->ap_iface == NULL)
1271 return;
1272 hapd = wpa_s->ap_iface->bss[0];
1273
1274 /*
1275 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
1276 * PIN if this happens multiple times to slow down brute force attacks.
1277 */
1278 hapd->ap_pin_failures++;
1279 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
1280 hapd->ap_pin_failures);
1281 if (hapd->ap_pin_failures < 3)
1282 return;
1283
1284 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
1285 hapd->ap_pin_failures = 0;
1286 os_free(hapd->conf->ap_pin);
1287 hapd->conf->ap_pin = NULL;
1288}
1289
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001290
1291#ifdef CONFIG_WPS_NFC
1292
1293struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
1294 int ndef)
1295{
1296 struct hostapd_data *hapd;
1297
1298 if (wpa_s->ap_iface == NULL)
1299 return NULL;
1300 hapd = wpa_s->ap_iface->bss[0];
1301 return hostapd_wps_nfc_config_token(hapd, ndef);
1302}
1303
1304
1305struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
1306 int ndef)
1307{
1308 struct hostapd_data *hapd;
1309
1310 if (wpa_s->ap_iface == NULL)
1311 return NULL;
1312 hapd = wpa_s->ap_iface->bss[0];
1313 return hostapd_wps_nfc_hs_cr(hapd, ndef);
1314}
1315
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001316
1317int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
1318 const struct wpabuf *req,
1319 const struct wpabuf *sel)
1320{
1321 struct hostapd_data *hapd;
1322
1323 if (wpa_s->ap_iface == NULL)
1324 return -1;
1325 hapd = wpa_s->ap_iface->bss[0];
1326 return hostapd_wps_nfc_report_handover(hapd, req, sel);
1327}
1328
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001329#endif /* CONFIG_WPS_NFC */
1330
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001331#endif /* CONFIG_WPS */
1332
1333
1334#ifdef CONFIG_CTRL_IFACE
1335
1336int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
1337 char *buf, size_t buflen)
1338{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001339 struct hostapd_data *hapd;
1340
1341 if (wpa_s->ap_iface)
1342 hapd = wpa_s->ap_iface->bss[0];
1343 else if (wpa_s->ifmsh)
1344 hapd = wpa_s->ifmsh->bss[0];
1345 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001346 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001347 return hostapd_ctrl_iface_sta_first(hapd, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001348}
1349
1350
1351int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
1352 char *buf, size_t buflen)
1353{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001354 struct hostapd_data *hapd;
1355
1356 if (wpa_s->ap_iface)
1357 hapd = wpa_s->ap_iface->bss[0];
1358 else if (wpa_s->ifmsh)
1359 hapd = wpa_s->ifmsh->bss[0];
1360 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001361 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001362 return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001363}
1364
1365
1366int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
1367 char *buf, size_t buflen)
1368{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001369 struct hostapd_data *hapd;
1370
1371 if (wpa_s->ap_iface)
1372 hapd = wpa_s->ap_iface->bss[0];
1373 else if (wpa_s->ifmsh)
1374 hapd = wpa_s->ifmsh->bss[0];
1375 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001376 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001377 return hostapd_ctrl_iface_sta_next(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001378}
1379
1380
Dmitry Shmidt04949592012-07-19 12:16:46 -07001381int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1382 const char *txtaddr)
1383{
1384 if (wpa_s->ap_iface == NULL)
1385 return -1;
1386 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1387 txtaddr);
1388}
1389
1390
1391int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1392 const char *txtaddr)
1393{
1394 if (wpa_s->ap_iface == NULL)
1395 return -1;
1396 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1397 txtaddr);
1398}
1399
1400
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001401int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1402 size_t buflen, int verbose)
1403{
1404 char *pos = buf, *end = buf + buflen;
1405 int ret;
1406 struct hostapd_bss_config *conf;
1407
1408 if (wpa_s->ap_iface == NULL)
1409 return -1;
1410
1411 conf = wpa_s->ap_iface->bss[0]->conf;
1412 if (conf->wpa == 0)
1413 return 0;
1414
1415 ret = os_snprintf(pos, end - pos,
1416 "pairwise_cipher=%s\n"
1417 "group_cipher=%s\n"
1418 "key_mgmt=%s\n",
1419 wpa_cipher_txt(conf->rsn_pairwise),
1420 wpa_cipher_txt(conf->wpa_group),
1421 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1422 conf->wpa));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001423 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001424 return pos - buf;
1425 pos += ret;
1426 return pos - buf;
1427}
1428
1429#endif /* CONFIG_CTRL_IFACE */
1430
1431
1432int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1433{
1434 struct hostapd_iface *iface = wpa_s->ap_iface;
1435 struct wpa_ssid *ssid = wpa_s->current_ssid;
1436 struct hostapd_data *hapd;
1437
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001438 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1439 ssid->mode == WPAS_MODE_INFRA ||
1440 ssid->mode == WPAS_MODE_IBSS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001441 return -1;
1442
1443#ifdef CONFIG_P2P
1444 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001445 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001446 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001447 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001448 P2P_GROUP_FORMATION;
1449#endif /* CONFIG_P2P */
1450
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001451 hapd = iface->bss[0];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001452 if (hapd->drv_priv == NULL)
1453 return -1;
1454 ieee802_11_set_beacons(iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001455 hostapd_set_ap_wps_ie(hapd);
1456
1457 return 0;
1458}
1459
1460
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001461int ap_switch_channel(struct wpa_supplicant *wpa_s,
1462 struct csa_settings *settings)
1463{
1464#ifdef NEED_AP_MLME
Hai Shalom899fcc72020-10-19 14:38:18 -07001465 struct hostapd_iface *iface = NULL;
1466
1467 if (wpa_s->ap_iface)
1468 iface = wpa_s->ap_iface;
1469 else if (wpa_s->ifmsh)
1470 iface = wpa_s->ifmsh;
1471
1472 if (!iface || !iface->bss[0])
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001473 return -1;
1474
Hai Shalom899fcc72020-10-19 14:38:18 -07001475 return hostapd_switch_channel(iface->bss[0], settings);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001476#else /* NEED_AP_MLME */
1477 return -1;
1478#endif /* NEED_AP_MLME */
1479}
1480
1481
Dmitry Shmidt83474442015-04-15 13:47:09 -07001482#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001483int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1484{
1485 struct csa_settings settings;
1486 int ret = hostapd_parse_csa_settings(pos, &settings);
1487
1488 if (ret)
1489 return ret;
1490
1491 return ap_switch_channel(wpa_s, &settings);
1492}
Dmitry Shmidt83474442015-04-15 13:47:09 -07001493#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001494
1495
Dmitry Shmidt04949592012-07-19 12:16:46 -07001496void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
Hai Shalom81f62d82019-07-22 12:10:00 -07001497 int offset, int width, int cf1, int cf2, int finished)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001498{
Hai Shalom74f70d42019-02-11 14:42:39 -08001499 struct hostapd_iface *iface = wpa_s->ap_iface;
Hai Shalombf6e0ba2019-02-11 12:01:50 -08001500
Hai Shalom74f70d42019-02-11 14:42:39 -08001501 if (!iface)
1502 iface = wpa_s->ifmsh;
1503 if (!iface)
1504 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001505 wpa_s->assoc_freq = freq;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001506 if (wpa_s->current_ssid)
1507 wpa_s->current_ssid->frequency = freq;
Hai Shalom74f70d42019-02-11 14:42:39 -08001508 hostapd_event_ch_switch(iface->bss[0], freq, ht,
Hai Shalom81f62d82019-07-22 12:10:00 -07001509 offset, width, cf1, cf2, finished);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001510}
1511
1512
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001513int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1514 const u8 *addr)
1515{
1516 struct hostapd_data *hapd;
1517 struct hostapd_bss_config *conf;
1518
1519 if (!wpa_s->ap_iface)
1520 return -1;
1521
1522 if (addr)
1523 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1524 MAC2STR(addr));
1525 else
1526 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1527
1528 hapd = wpa_s->ap_iface->bss[0];
1529 conf = hapd->conf;
1530
1531 os_free(conf->accept_mac);
1532 conf->accept_mac = NULL;
1533 conf->num_accept_mac = 0;
1534 os_free(conf->deny_mac);
1535 conf->deny_mac = NULL;
1536 conf->num_deny_mac = 0;
1537
1538 if (addr == NULL) {
1539 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1540 return 0;
1541 }
1542
1543 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1544 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1545 if (conf->accept_mac == NULL)
1546 return -1;
1547 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1548 conf->num_accept_mac = 1;
1549
1550 return 0;
1551}
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001552
1553
1554#ifdef CONFIG_WPS_NFC
1555int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1556 const struct wpabuf *pw, const u8 *pubkey_hash)
1557{
1558 struct hostapd_data *hapd;
1559 struct wps_context *wps;
1560
1561 if (!wpa_s->ap_iface)
1562 return -1;
1563 hapd = wpa_s->ap_iface->bss[0];
1564 wps = hapd->wps;
1565
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001566 if (wpa_s->p2pdev->conf->wps_nfc_dh_pubkey == NULL ||
1567 wpa_s->p2pdev->conf->wps_nfc_dh_privkey == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001568 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1569 return -1;
1570 }
1571
1572 dh5_free(wps->dh_ctx);
1573 wpabuf_free(wps->dh_pubkey);
1574 wpabuf_free(wps->dh_privkey);
1575 wps->dh_privkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001576 wpa_s->p2pdev->conf->wps_nfc_dh_privkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001577 wps->dh_pubkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001578 wpa_s->p2pdev->conf->wps_nfc_dh_pubkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001579 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1580 wps->dh_ctx = NULL;
1581 wpabuf_free(wps->dh_pubkey);
1582 wps->dh_pubkey = NULL;
1583 wpabuf_free(wps->dh_privkey);
1584 wps->dh_privkey = NULL;
1585 return -1;
1586 }
1587 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1588 if (wps->dh_ctx == NULL)
1589 return -1;
1590
1591 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1592 pw_id,
1593 pw ? wpabuf_head(pw) : NULL,
1594 pw ? wpabuf_len(pw) : 0, 1);
1595}
1596#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001597
1598
Dmitry Shmidt83474442015-04-15 13:47:09 -07001599#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001600int wpas_ap_stop_ap(struct wpa_supplicant *wpa_s)
1601{
1602 struct hostapd_data *hapd;
1603
1604 if (!wpa_s->ap_iface)
1605 return -1;
1606 hapd = wpa_s->ap_iface->bss[0];
1607 return hostapd_ctrl_iface_stop_ap(hapd);
1608}
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001609
1610
Dmitry Shmidte4663042016-04-04 10:07:49 -07001611int wpas_ap_pmksa_cache_list(struct wpa_supplicant *wpa_s, char *buf,
1612 size_t len)
1613{
1614 size_t reply_len = 0, i;
1615 char ap_delimiter[] = "---- AP ----\n";
1616 char mesh_delimiter[] = "---- mesh ----\n";
1617 size_t dlen;
1618
1619 if (wpa_s->ap_iface) {
1620 dlen = os_strlen(ap_delimiter);
1621 if (dlen > len - reply_len)
1622 return reply_len;
1623 os_memcpy(&buf[reply_len], ap_delimiter, dlen);
1624 reply_len += dlen;
1625
1626 for (i = 0; i < wpa_s->ap_iface->num_bss; i++) {
1627 reply_len += hostapd_ctrl_iface_pmksa_list(
1628 wpa_s->ap_iface->bss[i],
1629 &buf[reply_len], len - reply_len);
1630 }
1631 }
1632
1633 if (wpa_s->ifmsh) {
1634 dlen = os_strlen(mesh_delimiter);
1635 if (dlen > len - reply_len)
1636 return reply_len;
1637 os_memcpy(&buf[reply_len], mesh_delimiter, dlen);
1638 reply_len += dlen;
1639
1640 reply_len += hostapd_ctrl_iface_pmksa_list(
1641 wpa_s->ifmsh->bss[0], &buf[reply_len],
1642 len - reply_len);
1643 }
1644
1645 return reply_len;
1646}
1647
1648
1649void wpas_ap_pmksa_cache_flush(struct wpa_supplicant *wpa_s)
1650{
1651 size_t i;
1652
1653 if (wpa_s->ap_iface) {
1654 for (i = 0; i < wpa_s->ap_iface->num_bss; i++)
1655 hostapd_ctrl_iface_pmksa_flush(wpa_s->ap_iface->bss[i]);
1656 }
1657
1658 if (wpa_s->ifmsh)
1659 hostapd_ctrl_iface_pmksa_flush(wpa_s->ifmsh->bss[0]);
1660}
Paul Stewart092955c2017-02-06 09:13:09 -08001661
1662
1663#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
1664#ifdef CONFIG_MESH
1665
1666int wpas_ap_pmksa_cache_list_mesh(struct wpa_supplicant *wpa_s, const u8 *addr,
1667 char *buf, size_t len)
1668{
1669 return hostapd_ctrl_iface_pmksa_list_mesh(wpa_s->ifmsh->bss[0], addr,
1670 &buf[0], len);
1671}
1672
1673
1674int wpas_ap_pmksa_cache_add_external(struct wpa_supplicant *wpa_s, char *cmd)
1675{
1676 struct external_pmksa_cache *entry;
1677 void *pmksa_cache;
1678
1679 pmksa_cache = hostapd_ctrl_iface_pmksa_create_entry(wpa_s->own_addr,
1680 cmd);
1681 if (!pmksa_cache)
1682 return -1;
1683
1684 entry = os_zalloc(sizeof(struct external_pmksa_cache));
1685 if (!entry)
1686 return -1;
1687
1688 entry->pmksa_cache = pmksa_cache;
1689
1690 dl_list_add(&wpa_s->mesh_external_pmksa_cache, &entry->list);
1691
1692 return 0;
1693}
1694
1695#endif /* CONFIG_MESH */
1696#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
1697
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001698#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte4663042016-04-04 10:07:49 -07001699
1700
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001701#ifdef NEED_AP_MLME
Roshan Pius3a1667e2018-07-03 15:17:14 -07001702void wpas_ap_event_dfs_radar_detected(struct wpa_supplicant *wpa_s,
1703 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001704{
Hai Shalom74f70d42019-02-11 14:42:39 -08001705 struct hostapd_iface *iface = wpa_s->ap_iface;
1706
1707 if (!iface)
1708 iface = wpa_s->ifmsh;
1709 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001710 return;
1711 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001712 hostapd_dfs_radar_detected(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001713 radar->ht_enabled, radar->chan_offset,
1714 radar->chan_width,
1715 radar->cf1, radar->cf2);
1716}
1717
1718
Roshan Pius3a1667e2018-07-03 15:17:14 -07001719void wpas_ap_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
1720 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001721{
Hai Shalom74f70d42019-02-11 14:42:39 -08001722 struct hostapd_iface *iface = wpa_s->ap_iface;
1723
1724 if (!iface)
1725 iface = wpa_s->ifmsh;
1726 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001727 return;
1728 wpa_printf(MSG_DEBUG, "DFS CAC started on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001729 hostapd_dfs_start_cac(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001730 radar->ht_enabled, radar->chan_offset,
1731 radar->chan_width, radar->cf1, radar->cf2);
1732}
1733
1734
Roshan Pius3a1667e2018-07-03 15:17:14 -07001735void wpas_ap_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
1736 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001737{
Hai Shalom74f70d42019-02-11 14:42:39 -08001738 struct hostapd_iface *iface = wpa_s->ap_iface;
1739
1740 if (!iface)
1741 iface = wpa_s->ifmsh;
1742 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001743 return;
1744 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001745 hostapd_dfs_complete_cac(iface, 1, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001746 radar->ht_enabled, radar->chan_offset,
1747 radar->chan_width, radar->cf1, radar->cf2);
1748}
1749
1750
Roshan Pius3a1667e2018-07-03 15:17:14 -07001751void wpas_ap_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
1752 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001753{
Hai Shalom74f70d42019-02-11 14:42:39 -08001754 struct hostapd_iface *iface = wpa_s->ap_iface;
1755
1756 if (!iface)
1757 iface = wpa_s->ifmsh;
1758 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001759 return;
1760 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001761 hostapd_dfs_complete_cac(iface, 0, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001762 radar->ht_enabled, radar->chan_offset,
1763 radar->chan_width, radar->cf1, radar->cf2);
1764}
1765
1766
Roshan Pius3a1667e2018-07-03 15:17:14 -07001767void wpas_ap_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s,
1768 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001769{
Hai Shalom74f70d42019-02-11 14:42:39 -08001770 struct hostapd_iface *iface = wpa_s->ap_iface;
1771
1772 if (!iface)
1773 iface = wpa_s->ifmsh;
1774 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001775 return;
1776 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001777 hostapd_dfs_nop_finished(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001778 radar->ht_enabled, radar->chan_offset,
1779 radar->chan_width, radar->cf1, radar->cf2);
1780}
1781#endif /* NEED_AP_MLME */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001782
1783
1784void ap_periodic(struct wpa_supplicant *wpa_s)
1785{
1786 if (wpa_s->ap_iface)
1787 hostapd_periodic_iface(wpa_s->ap_iface);
1788}