blob: 6241682059b97677304ebc02462668e914bc130a [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 */
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070056
57 if (!conf->secondary_channel)
58 goto no_vht;
59
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070060 /* Use the maximum oper channel width if it's given. */
61 if (ssid->max_oper_chwidth)
62 conf->vht_oper_chwidth = ssid->max_oper_chwidth;
63
64 ieee80211_freq_to_chan(ssid->vht_center_freq2,
65 &conf->vht_oper_centr_freq_seg1_idx);
66
67 if (!ssid->p2p_group) {
68 if (!ssid->vht_center_freq1 ||
Hai Shalom81f62d82019-07-22 12:10:00 -070069 conf->vht_oper_chwidth == CHANWIDTH_USE_HT)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070070 goto no_vht;
71 ieee80211_freq_to_chan(ssid->vht_center_freq1,
72 &conf->vht_oper_centr_freq_seg0_idx);
Roshan Pius3a1667e2018-07-03 15:17:14 -070073 wpa_printf(MSG_DEBUG, "VHT seg0 index %d for AP",
74 conf->vht_oper_centr_freq_seg0_idx);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070075 return;
76 }
77
78#ifdef CONFIG_P2P
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080079 switch (conf->vht_oper_chwidth) {
Hai Shalom81f62d82019-07-22 12:10:00 -070080 case CHANWIDTH_80MHZ:
81 case CHANWIDTH_80P80MHZ:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080082 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -070083 wpa_printf(MSG_DEBUG,
84 "VHT center channel %u for 80 or 80+80 MHz bandwidth",
85 center_chan);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080086 break;
Hai Shalom81f62d82019-07-22 12:10:00 -070087 case CHANWIDTH_160MHZ:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080088 center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -070089 wpa_printf(MSG_DEBUG,
90 "VHT center channel %u for 160 MHz bandwidth",
91 center_chan);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080092 break;
93 default:
94 /*
95 * conf->vht_oper_chwidth might not be set for non-P2P GO cases,
96 * try oper_cwidth 160 MHz first then VHT 80 MHz, if 160 MHz is
97 * not supported.
98 */
Hai Shalom81f62d82019-07-22 12:10:00 -070099 conf->vht_oper_chwidth = CHANWIDTH_160MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800100 center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700101 if (center_chan) {
102 wpa_printf(MSG_DEBUG,
103 "VHT center channel %u for auto-selected 160 MHz bandwidth",
104 center_chan);
105 } else {
Hai Shalom81f62d82019-07-22 12:10:00 -0700106 conf->vht_oper_chwidth = CHANWIDTH_80MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800107 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode,
108 channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700109 wpa_printf(MSG_DEBUG,
110 "VHT center channel %u for auto-selected 80 MHz bandwidth",
111 center_chan);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800112 }
113 break;
114 }
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700115 if (!center_chan)
116 goto no_vht;
117
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700118 conf->vht_oper_centr_freq_seg0_idx = center_chan;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700119 wpa_printf(MSG_DEBUG, "VHT seg0 index %d for P2P GO",
120 conf->vht_oper_centr_freq_seg0_idx);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700121 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700122#endif /* CONFIG_P2P */
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700123
124no_vht:
Roshan Pius3a1667e2018-07-03 15:17:14 -0700125 wpa_printf(MSG_DEBUG,
126 "No VHT higher bandwidth support for the selected channel %d",
127 conf->channel);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700128 conf->vht_oper_centr_freq_seg0_idx =
Dmitry Shmidt21de2142014-04-08 10:50:52 -0700129 conf->channel + conf->secondary_channel * 2;
Hai Shalom81f62d82019-07-22 12:10:00 -0700130 conf->vht_oper_chwidth = CHANWIDTH_USE_HT;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700131}
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700132
133
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800134int wpa_supplicant_conf_ap_ht(struct wpa_supplicant *wpa_s,
135 struct wpa_ssid *ssid,
136 struct hostapd_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700137{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800138 conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency,
139 &conf->channel);
140
141 if (conf->hw_mode == NUM_HOSTAPD_MODES) {
142 wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
143 ssid->frequency);
144 return -1;
145 }
146
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700147 /* TODO: enable HT40 if driver supports it;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700148 * drop to 11b if driver does not support 11g */
149
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700150 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800151 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
152 * and a mask of allowed capabilities within conf->ht_capab.
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700153 * Using default config settings for: conf->ht_op_mode_fixed,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800154 * conf->secondary_channel, conf->require_ht
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700155 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800156 if (wpa_s->hw.modes) {
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700157 struct hostapd_hw_modes *mode = NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700158 int i, no_ht = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700159
160 wpa_printf(MSG_DEBUG,
161 "Determining HT/VHT options based on driver capabilities (freq=%u chan=%u)",
162 ssid->frequency, conf->channel);
163
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800164 for (i = 0; i < wpa_s->hw.num_modes; i++) {
165 if (wpa_s->hw.modes[i].mode == conf->hw_mode) {
166 mode = &wpa_s->hw.modes[i];
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700167 break;
168 }
169 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700170
171#ifdef CONFIG_HT_OVERRIDES
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700172 if (ssid->disable_ht)
173 ssid->ht = 0;
174#endif /* CONFIG_HT_OVERRIDES */
175
176 if (!ssid->ht) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700177 wpa_printf(MSG_DEBUG,
178 "HT not enabled in network profile");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700179 conf->ieee80211n = 0;
180 conf->ht_capab = 0;
181 no_ht = 1;
182 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700183
184 if (!no_ht && mode && mode->ht_capab) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700185 wpa_printf(MSG_DEBUG,
186 "Enable HT support (p2p_group=%d 11a=%d ht40_hw_capab=%d ssid->ht40=%d)",
187 ssid->p2p_group,
188 conf->hw_mode == HOSTAPD_MODE_IEEE80211A,
189 !!(mode->ht_capab &
190 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET),
191 ssid->ht40);
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700192 conf->ieee80211n = 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700193#ifdef CONFIG_P2P
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700194 if (ssid->p2p_group &&
195 conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700196 (mode->ht_capab &
197 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -0700198 ssid->ht40) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700199 conf->secondary_channel =
200 wpas_p2p_get_ht40_mode(wpa_s, mode,
201 conf->channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700202 wpa_printf(MSG_DEBUG,
203 "HT secondary channel offset %d for P2P group",
204 conf->secondary_channel);
205 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700206#endif /* CONFIG_P2P */
207
208 if (!ssid->p2p_group &&
209 (mode->ht_capab &
Roshan Pius3a1667e2018-07-03 15:17:14 -0700210 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700211 conf->secondary_channel = ssid->ht40;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700212 wpa_printf(MSG_DEBUG,
213 "HT secondary channel offset %d for AP",
214 conf->secondary_channel);
215 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700216
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700217 if (conf->secondary_channel)
218 conf->ht_capab |=
219 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800220
221 /*
222 * white-list capabilities that won't cause issues
223 * to connecting stations, while leaving the current
224 * capabilities intact (currently disabled SMPS).
225 */
226 conf->ht_capab |= mode->ht_capab &
227 (HT_CAP_INFO_GREEN_FIELD |
228 HT_CAP_INFO_SHORT_GI20MHZ |
229 HT_CAP_INFO_SHORT_GI40MHZ |
230 HT_CAP_INFO_RX_STBC_MASK |
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800231 HT_CAP_INFO_TX_STBC |
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800232 HT_CAP_INFO_MAX_AMSDU_SIZE);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700233
234 if (mode->vht_capab && ssid->vht) {
235 conf->ieee80211ac = 1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800236 conf->vht_capab |= mode->vht_capab;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700237 wpas_conf_ap_vht(wpa_s, ssid, conf, mode);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700238 }
Hai Shalom81f62d82019-07-22 12:10:00 -0700239
240 if (mode->he_capab[wpas_mode_to_ieee80211_mode(
241 ssid->mode)].he_supported &&
242 ssid->he)
243 conf->ieee80211ax = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800244 }
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700245 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800246
247 if (conf->secondary_channel) {
248 struct wpa_supplicant *iface;
249
250 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
251 {
252 if (iface == wpa_s ||
253 iface->wpa_state < WPA_AUTHENTICATING ||
254 (int) iface->assoc_freq != ssid->frequency)
255 continue;
256
257 /*
258 * Do not allow 40 MHz co-ex PRI/SEC switch to force us
259 * to change our PRI channel since we have an existing,
260 * concurrent connection on that channel and doing
261 * multi-channel concurrency is likely to cause more
262 * harm than using different PRI/SEC selection in
263 * environment with multiple BSSes on these two channels
264 * with mixed 20 MHz or PRI channel selection.
265 */
266 conf->no_pri_sec_switch = 1;
267 }
268 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800269
270 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800271}
272
273
274static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
275 struct wpa_ssid *ssid,
276 struct hostapd_config *conf)
277{
278 struct hostapd_bss_config *bss = conf->bss[0];
279
280 conf->driver = wpa_s->driver;
281
282 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
283
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800284 if (wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800285 return -1;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700286
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700287 if (ssid->pbss > 1) {
288 wpa_printf(MSG_ERROR, "Invalid pbss value(%d) for AP mode",
289 ssid->pbss);
290 return -1;
291 }
292 bss->pbss = ssid->pbss;
293
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800294#ifdef CONFIG_ACS
295 if (ssid->acs) {
296 /* Setting channel to 0 in order to enable ACS */
297 conf->channel = 0;
298 wpa_printf(MSG_DEBUG, "Use automatic channel selection");
299 }
300#endif /* CONFIG_ACS */
301
Roshan Pius3a1667e2018-07-03 15:17:14 -0700302 if (ieee80211_is_dfs(ssid->frequency, wpa_s->hw.modes,
303 wpa_s->hw.num_modes) && wpa_s->conf->country[0]) {
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800304 conf->ieee80211h = 1;
305 conf->ieee80211d = 1;
306 conf->country[0] = wpa_s->conf->country[0];
307 conf->country[1] = wpa_s->conf->country[1];
Paul Stewart092955c2017-02-06 09:13:09 -0800308 conf->country[2] = ' ';
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800309 }
310
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700311#ifdef CONFIG_P2P
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700312 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
313 (ssid->mode == WPAS_MODE_P2P_GO ||
314 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700315 /* Remove 802.11b rates from supported and basic rate sets */
316 int *list = os_malloc(4 * sizeof(int));
317 if (list) {
318 list[0] = 60;
319 list[1] = 120;
320 list[2] = 240;
321 list[3] = -1;
322 }
323 conf->basic_rates = list;
324
325 list = os_malloc(9 * sizeof(int));
326 if (list) {
327 list[0] = 60;
328 list[1] = 90;
329 list[2] = 120;
330 list[3] = 180;
331 list[4] = 240;
332 list[5] = 360;
333 list[6] = 480;
334 list[7] = 540;
335 list[8] = -1;
336 }
337 conf->supported_rates = list;
Hai Shalom021b0b52019-04-10 11:17:58 -0700338 }
339
Hai Shalom74f70d42019-02-11 14:42:39 -0800340#ifdef CONFIG_IEEE80211AX
Hai Shalom021b0b52019-04-10 11:17:58 -0700341 if (ssid->mode == WPAS_MODE_P2P_GO ||
342 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Hai Shalom74f70d42019-02-11 14:42:39 -0800343 conf->ieee80211ax = ssid->he;
344#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800345
346 bss->isolate = !wpa_s->conf->p2p_intra_bss;
Hai Shalomfdcde762020-04-02 11:19:20 -0700347 bss->extended_key_id = wpa_s->conf->extended_key_id;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700348 bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
Hai Shalomfdcde762020-04-02 11:19:20 -0700349 bss->wpa_deny_ptk0_rekey = ssid->wpa_deny_ptk0_rekey;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800350
351 if (ssid->p2p_group) {
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800352 os_memcpy(bss->ip_addr_go, wpa_s->p2pdev->conf->ip_addr_go, 4);
353 os_memcpy(bss->ip_addr_mask, wpa_s->p2pdev->conf->ip_addr_mask,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800354 4);
355 os_memcpy(bss->ip_addr_start,
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800356 wpa_s->p2pdev->conf->ip_addr_start, 4);
357 os_memcpy(bss->ip_addr_end, wpa_s->p2pdev->conf->ip_addr_end,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800358 4);
359 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700360#endif /* CONFIG_P2P */
361
362 if (ssid->ssid_len == 0) {
363 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
364 return -1;
365 }
366 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700367 bss->ssid.ssid_len = ssid->ssid_len;
368 bss->ssid.ssid_set = 1;
369
Dmitry Shmidt04949592012-07-19 12:16:46 -0700370 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
371
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800372 if (ssid->auth_alg)
373 bss->auth_algs = ssid->auth_alg;
374
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700375 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
376 bss->wpa = ssid->proto;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700377 if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
378 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
379 else
380 bss->wpa_key_mgmt = ssid->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700381 bss->wpa_pairwise = ssid->pairwise_cipher;
Hai Shalomc3565922019-10-28 11:58:20 -0700382 if (wpa_key_mgmt_sae(bss->wpa_key_mgmt) && ssid->passphrase) {
383 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
384 } else if (ssid->psk_set) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800385 bin_clear_free(bss->ssid.wpa_psk, sizeof(*bss->ssid.wpa_psk));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700386 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
387 if (bss->ssid.wpa_psk == NULL)
388 return -1;
389 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
390 bss->ssid.wpa_psk->group = 1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700391 bss->ssid.wpa_psk_set = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800392 } else if (ssid->passphrase) {
393 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
Hai Shalomfdcde762020-04-02 11:19:20 -0700394#ifdef CONFIG_WEP
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800395 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
396 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
397 struct hostapd_wep_keys *wep = &bss->ssid.wep;
398 int i;
399 for (i = 0; i < NUM_WEP_KEYS; i++) {
400 if (ssid->wep_key_len[i] == 0)
401 continue;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700402 wep->key[i] = os_memdup(ssid->wep_key[i],
403 ssid->wep_key_len[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800404 if (wep->key[i] == NULL)
405 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800406 wep->len[i] = ssid->wep_key_len[i];
407 }
408 wep->idx = ssid->wep_tx_keyidx;
409 wep->keys_set = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700410#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700411 }
Hai Shalomc3565922019-10-28 11:58:20 -0700412#ifdef CONFIG_SAE
413 if (ssid->sae_password) {
414 struct sae_password_entry *pw;
415
416 pw = os_zalloc(sizeof(*pw));
417 if (!pw)
418 return -1;
419 os_memset(pw->peer_addr, 0xff, ETH_ALEN);
420 pw->password = os_strdup(ssid->sae_password);
421 if (!pw->password) {
422 os_free(pw);
423 return -1;
424 }
425 if (ssid->sae_password_id) {
426 pw->identifier = os_strdup(ssid->sae_password_id);
427 if (!pw->identifier) {
428 str_clear_free(pw->password);
429 os_free(pw);
430 return -1;
431 }
432 }
433
434 pw->next = bss->sae_passwords;
435 bss->sae_passwords = pw;
436 }
437
438 bss->sae_pwe = wpa_s->conf->sae_pwe;
439#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700440
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700441 if (wpa_s->conf->go_interworking) {
442 wpa_printf(MSG_DEBUG,
443 "P2P: Enable Interworking with access_network_type: %d",
444 wpa_s->conf->go_access_network_type);
445 bss->interworking = wpa_s->conf->go_interworking;
446 bss->access_network_type = wpa_s->conf->go_access_network_type;
447 bss->internet = wpa_s->conf->go_internet;
448 if (wpa_s->conf->go_venue_group) {
449 wpa_printf(MSG_DEBUG,
450 "P2P: Venue group: %d Venue type: %d",
451 wpa_s->conf->go_venue_group,
452 wpa_s->conf->go_venue_type);
453 bss->venue_group = wpa_s->conf->go_venue_group;
454 bss->venue_type = wpa_s->conf->go_venue_type;
455 bss->venue_info_set = 1;
456 }
457 }
458
Dmitry Shmidt04949592012-07-19 12:16:46 -0700459 if (ssid->ap_max_inactivity)
460 bss->ap_max_inactivity = ssid->ap_max_inactivity;
461
462 if (ssid->dtim_period)
463 bss->dtim_period = ssid->dtim_period;
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -0800464 else if (wpa_s->conf->dtim_period)
465 bss->dtim_period = wpa_s->conf->dtim_period;
466
467 if (ssid->beacon_int)
468 conf->beacon_int = ssid->beacon_int;
469 else if (wpa_s->conf->beacon_int)
470 conf->beacon_int = wpa_s->conf->beacon_int;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700471
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800472#ifdef CONFIG_P2P
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800473 if (ssid->mode == WPAS_MODE_P2P_GO ||
474 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
475 if (wpa_s->conf->p2p_go_ctwindow > conf->beacon_int) {
476 wpa_printf(MSG_INFO,
477 "CTWindow (%d) is bigger than beacon interval (%d) - avoid configuring it",
478 wpa_s->conf->p2p_go_ctwindow,
479 conf->beacon_int);
480 conf->p2p_go_ctwindow = 0;
481 } else {
482 conf->p2p_go_ctwindow = wpa_s->conf->p2p_go_ctwindow;
483 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800484 }
485#endif /* CONFIG_P2P */
486
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800487 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
488 bss->rsn_pairwise = bss->wpa_pairwise;
489 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
490 bss->rsn_pairwise);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700491
Hai Shalomfdcde762020-04-02 11:19:20 -0700492 if (bss->wpa && bss->ieee802_1x) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700493 bss->ssid.security_policy = SECURITY_WPA;
Hai Shalomfdcde762020-04-02 11:19:20 -0700494 } else if (bss->wpa) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700495 bss->ssid.security_policy = SECURITY_WPA_PSK;
Hai Shalomfdcde762020-04-02 11:19:20 -0700496#ifdef CONFIG_WEP
497 } else if (bss->ieee802_1x) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800498 int cipher = WPA_CIPHER_NONE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700499 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
500 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800501 if (bss->default_wep_key_len)
502 cipher = bss->default_wep_key_len >= 13 ?
503 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
504 bss->wpa_group = cipher;
505 bss->wpa_pairwise = cipher;
506 bss->rsn_pairwise = cipher;
507 } else if (bss->ssid.wep.keys_set) {
508 int cipher = WPA_CIPHER_WEP40;
509 if (bss->ssid.wep.len[0] >= 13)
510 cipher = WPA_CIPHER_WEP104;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700511 bss->ssid.security_policy = SECURITY_STATIC_WEP;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800512 bss->wpa_group = cipher;
513 bss->wpa_pairwise = cipher;
514 bss->rsn_pairwise = cipher;
Hai Shalomfdcde762020-04-02 11:19:20 -0700515#endif /* CONFIG_WEP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800516 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700517 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800518 bss->wpa_group = WPA_CIPHER_NONE;
519 bss->wpa_pairwise = WPA_CIPHER_NONE;
520 bss->rsn_pairwise = WPA_CIPHER_NONE;
521 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700522
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700523 if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
524 (bss->wpa_group == WPA_CIPHER_CCMP ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800525 bss->wpa_group == WPA_CIPHER_GCMP ||
526 bss->wpa_group == WPA_CIPHER_CCMP_256 ||
527 bss->wpa_group == WPA_CIPHER_GCMP_256)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700528 /*
529 * Strong ciphers do not need frequent rekeying, so increase
530 * the default GTK rekeying period to 24 hours.
531 */
532 bss->wpa_group_rekey = 86400;
533 }
534
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700535 if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT)
536 bss->ieee80211w = ssid->ieee80211w;
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700537
Hai Shalom74f70d42019-02-11 14:42:39 -0800538#ifdef CONFIG_OCV
539 bss->ocv = ssid->ocv;
540#endif /* CONFIG_OCV */
541
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700542#ifdef CONFIG_WPS
543 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800544 * Enable WPS by default for open and WPA/WPA2-Personal network, but
545 * require user interaction to actually use it. Only the internal
546 * Registrar is supported.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700547 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800548 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
549 bss->ssid.security_policy != SECURITY_PLAINTEXT)
550 goto no_wps;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800551 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800552 (!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ||
553 !(bss->wpa & 2)))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800554 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
555 * configuration */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700556 if (ssid->wps_disabled)
557 goto no_wps;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700558 bss->eap_server = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700559
560 if (!ssid->ignore_broadcast_ssid)
561 bss->wps_state = 2;
562
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700563 bss->ap_setup_locked = 2;
564 if (wpa_s->conf->config_methods)
565 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
566 os_memcpy(bss->device_type, wpa_s->conf->device_type,
567 WPS_DEV_TYPE_LEN);
568 if (wpa_s->conf->device_name) {
569 bss->device_name = os_strdup(wpa_s->conf->device_name);
570 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
571 }
572 if (wpa_s->conf->manufacturer)
573 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
574 if (wpa_s->conf->model_name)
575 bss->model_name = os_strdup(wpa_s->conf->model_name);
576 if (wpa_s->conf->model_number)
577 bss->model_number = os_strdup(wpa_s->conf->model_number);
578 if (wpa_s->conf->serial_number)
579 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
580 if (is_nil_uuid(wpa_s->conf->uuid))
581 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
582 else
583 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
584 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700585 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -0700586 if (ssid->eap.fragment_size != DEFAULT_FRAGMENT_SIZE)
587 bss->fragment_size = ssid->eap.fragment_size;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800588no_wps:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700589#endif /* CONFIG_WPS */
590
591 if (wpa_s->max_stations &&
592 wpa_s->max_stations < wpa_s->conf->max_num_sta)
593 bss->max_num_sta = wpa_s->max_stations;
594 else
595 bss->max_num_sta = wpa_s->conf->max_num_sta;
596
Roshan Pius3a1667e2018-07-03 15:17:14 -0700597 if (!bss->isolate)
598 bss->isolate = wpa_s->conf->ap_isolate;
599
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700600 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
601
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700602 if (wpa_s->conf->ap_vendor_elements) {
603 bss->vendor_elements =
604 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
605 }
606
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700607 bss->ftm_responder = wpa_s->conf->ftm_responder;
608 bss->ftm_initiator = wpa_s->conf->ftm_initiator;
609
Hai Shalomfdcde762020-04-02 11:19:20 -0700610 bss->transition_disable = ssid->transition_disable;
611
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700612 return 0;
613}
614
615
616static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
617{
618#ifdef CONFIG_P2P
619 struct wpa_supplicant *wpa_s = ctx;
620 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700621
622 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700623 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700624 return;
Dmitry Shmidt18463232014-01-24 12:29:41 -0800625 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
626 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700627 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
628 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700629 buf + IEEE80211_HDRLEN + 1,
630 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700631#endif /* CONFIG_P2P */
632}
633
634
635static void ap_wps_event_cb(void *ctx, enum wps_event event,
636 union wps_event_data *data)
637{
638#ifdef CONFIG_P2P
639 struct wpa_supplicant *wpa_s = ctx;
640
Jouni Malinen75ecf522011-06-27 15:19:46 -0700641 if (event == WPS_EV_FAIL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700642 struct wps_event_fail *fail = &data->fail;
643
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800644 if (wpa_s->p2pdev && wpa_s->p2pdev != wpa_s &&
Jouni Malinen75ecf522011-06-27 15:19:46 -0700645 wpa_s == wpa_s->global->p2p_group_formation) {
646 /*
647 * src/ap/wps_hostapd.c has already sent this on the
648 * main interface, so only send on the parent interface
649 * here if needed.
650 */
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800651 wpa_msg(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_FAIL
Jouni Malinen75ecf522011-06-27 15:19:46 -0700652 "msg=%d config_error=%d",
653 fail->msg, fail->config_error);
654 }
655 wpas_p2p_wps_failed(wpa_s, fail);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700656 }
657#endif /* CONFIG_P2P */
658}
659
660
661static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800662 int authorized, const u8 *p2p_dev_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700663{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800664 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700665}
666
667
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700668#ifdef CONFIG_P2P
669static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
670 const u8 *psk, size_t psk_len)
671{
672
673 struct wpa_supplicant *wpa_s = ctx;
674 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
675 return;
676 wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
677}
678#endif /* CONFIG_P2P */
679
680
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700681static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
682{
683#ifdef CONFIG_P2P
684 struct wpa_supplicant *wpa_s = ctx;
685 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700686
687 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700688 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700689 return -1;
690 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
691 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700692 buf + IEEE80211_HDRLEN + 1,
693 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700694#endif /* CONFIG_P2P */
695 return 0;
696}
697
698
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800699static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700700 const u8 *bssid, const u8 *ie, size_t ie_len,
701 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700702{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700703 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700704 unsigned int freq = 0;
705
706 if (wpa_s->ap_iface)
707 freq = wpa_s->ap_iface->freq;
708
Dmitry Shmidt04949592012-07-19 12:16:46 -0700709 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700710 freq, ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700711}
712
713
714static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
715 const u8 *uuid_e)
716{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700717 struct wpa_supplicant *wpa_s = ctx;
718 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700719}
720
721
722static void wpas_ap_configured_cb(void *ctx)
723{
724 struct wpa_supplicant *wpa_s = ctx;
725
Roshan Pius3a1667e2018-07-03 15:17:14 -0700726 wpa_printf(MSG_DEBUG, "AP interface setup completed - state %s",
727 hostapd_state_text(wpa_s->ap_iface->state));
728 if (wpa_s->ap_iface->state == HAPD_IFACE_DISABLED) {
729 wpa_supplicant_ap_deinit(wpa_s);
730 return;
731 }
732
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800733#ifdef CONFIG_ACS
Roshan Pius3a1667e2018-07-03 15:17:14 -0700734 if (wpa_s->current_ssid && wpa_s->current_ssid->acs) {
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800735 wpa_s->assoc_freq = wpa_s->ap_iface->freq;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700736 wpa_s->current_ssid->frequency = wpa_s->ap_iface->freq;
737 }
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800738#endif /* CONFIG_ACS */
739
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700740 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
741
742 if (wpa_s->ap_configured_cb)
743 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
744 wpa_s->ap_configured_cb_data);
745}
746
747
748int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
749 struct wpa_ssid *ssid)
750{
751 struct wpa_driver_associate_params params;
752 struct hostapd_iface *hapd_iface;
753 struct hostapd_config *conf;
754 size_t i;
755
756 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
757 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
758 return -1;
759 }
760
761 wpa_supplicant_ap_deinit(wpa_s);
762
763 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
764 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
765
766 os_memset(&params, 0, sizeof(params));
767 params.ssid = ssid->ssid;
768 params.ssid_len = ssid->ssid_len;
769 switch (ssid->mode) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700770 case WPAS_MODE_AP:
771 case WPAS_MODE_P2P_GO:
772 case WPAS_MODE_P2P_GROUP_FORMATION:
773 params.mode = IEEE80211_MODE_AP;
774 break;
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800775 default:
776 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700777 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700778 if (ssid->frequency == 0)
779 ssid->frequency = 2462; /* default channel 11 */
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700780 params.freq.freq = ssid->frequency;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700781
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800782 if ((ssid->mode == WPAS_MODE_AP || ssid->mode == WPAS_MODE_P2P_GO) &&
783 ssid->enable_edmg) {
Hai Shalomc3565922019-10-28 11:58:20 -0700784 u8 primary_channel;
785
786 if (ieee80211_freq_to_chan(ssid->frequency, &primary_channel) ==
787 NUM_HOSTAPD_MODES) {
788 wpa_printf(MSG_WARNING,
789 "EDMG: Failed to get the primary channel");
790 return -1;
791 }
792
793 hostapd_encode_edmg_chan(ssid->enable_edmg, ssid->edmg_channel,
794 primary_channel, &params.freq.edmg);
795 }
796
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800797 params.wpa_proto = ssid->proto;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700798 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
799 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
800 else
801 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800802 params.key_mgmt_suite = wpa_s->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700803
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800804 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
805 1);
806 if (wpa_s->pairwise_cipher < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700807 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
808 "cipher.");
809 return -1;
810 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800811 params.pairwise_suite = wpa_s->pairwise_cipher;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700812 params.group_suite = params.pairwise_suite;
813
814#ifdef CONFIG_P2P
815 if (ssid->mode == WPAS_MODE_P2P_GO ||
816 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
817 params.p2p = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700818#endif /* CONFIG_P2P */
819
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800820 if (wpa_s->p2pdev->set_ap_uapsd)
821 params.uapsd = wpa_s->p2pdev->ap_uapsd;
Dmitry Shmidtec58b162014-02-19 12:44:18 -0800822 else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
823 params.uapsd = 1; /* mandatory for P2P GO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700824 else
825 params.uapsd = -1;
826
Roshan Pius3a1667e2018-07-03 15:17:14 -0700827 if (ieee80211_is_dfs(params.freq.freq, wpa_s->hw.modes,
828 wpa_s->hw.num_modes))
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800829 params.freq.freq = 0; /* set channel after CAC */
830
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700831 if (params.p2p)
832 wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_GO);
833 else
834 wpa_drv_get_ext_capa(wpa_s, WPA_IF_AP_BSS);
835
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700836 if (wpa_drv_associate(wpa_s, &params) < 0) {
837 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
838 return -1;
839 }
840
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700841 wpa_s->ap_iface = hapd_iface = hostapd_alloc_iface();
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700842 if (hapd_iface == NULL)
843 return -1;
844 hapd_iface->owner = wpa_s;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800845 hapd_iface->drv_flags = wpa_s->drv_flags;
846 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700847 hapd_iface->extended_capa = wpa_s->extended_capa;
848 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
849 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700850
851 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
852 if (conf == NULL) {
853 wpa_supplicant_ap_deinit(wpa_s);
854 return -1;
855 }
856
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700857 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
858 wpa_s->conf->wmm_ac_params,
859 sizeof(wpa_s->conf->wmm_ac_params));
860
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800861 if (params.uapsd > 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800862 conf->bss[0]->wmm_enabled = 1;
863 conf->bss[0]->wmm_uapsd = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800864 }
865
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700866 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
867 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
868 wpa_supplicant_ap_deinit(wpa_s);
869 return -1;
870 }
871
872#ifdef CONFIG_P2P
873 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800874 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700875 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800876 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700877 P2P_GROUP_FORMATION;
878#endif /* CONFIG_P2P */
879
880 hapd_iface->num_bss = conf->num_bss;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700881 hapd_iface->bss = os_calloc(conf->num_bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700882 sizeof(struct hostapd_data *));
883 if (hapd_iface->bss == NULL) {
884 wpa_supplicant_ap_deinit(wpa_s);
885 return -1;
886 }
887
888 for (i = 0; i < conf->num_bss; i++) {
889 hapd_iface->bss[i] =
890 hostapd_alloc_bss_data(hapd_iface, conf,
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800891 conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700892 if (hapd_iface->bss[i] == NULL) {
893 wpa_supplicant_ap_deinit(wpa_s);
894 return -1;
895 }
896
897 hapd_iface->bss[i]->msg_ctx = wpa_s;
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800898 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->p2pdev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700899 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
900 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
901 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
902 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
903 hostapd_register_probereq_cb(hapd_iface->bss[i],
904 ap_probe_req_rx, wpa_s);
905 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
906 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
907 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
908 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
909 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
910 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
911#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700912 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
913 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700914 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700915 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
916 ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700917#endif /* CONFIG_P2P */
918 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
919 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800920#ifdef CONFIG_TESTING_OPTIONS
921 hapd_iface->bss[i]->ext_eapol_frame_io =
922 wpa_s->ext_eapol_frame_io;
923#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700924 }
925
926 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
927 hapd_iface->bss[0]->driver = wpa_s->driver;
928 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
929
930 wpa_s->current_ssid = ssid;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700931 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700932 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
933 wpa_s->assoc_freq = ssid->frequency;
Hai Shalomc3565922019-10-28 11:58:20 -0700934 wpa_s->ap_iface->conf->enable_edmg = ssid->enable_edmg;
935 wpa_s->ap_iface->conf->edmg_channel = ssid->edmg_channel;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700936
Roshan Pius3a1667e2018-07-03 15:17:14 -0700937#if defined(CONFIG_P2P) && defined(CONFIG_ACS)
938 if (wpa_s->p2p_go_do_acs) {
939 wpa_s->ap_iface->conf->channel = 0;
940 wpa_s->ap_iface->conf->hw_mode = wpa_s->p2p_go_acs_band;
941 ssid->acs = 1;
942 }
943#endif /* CONFIG_P2P && CONFIG_ACS */
944
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700945 if (hostapd_setup_interface(wpa_s->ap_iface)) {
946 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
947 wpa_supplicant_ap_deinit(wpa_s);
948 return -1;
949 }
950
951 return 0;
952}
953
954
955void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
956{
957#ifdef CONFIG_WPS
958 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
959#endif /* CONFIG_WPS */
960
961 if (wpa_s->ap_iface == NULL)
962 return;
963
964 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700965 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700966 wpa_s->assoc_freq = 0;
Dmitry Shmidt43cb5782014-06-16 16:23:22 -0700967 wpas_p2p_ap_deinit(wpa_s);
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800968 wpa_s->ap_iface->driver_ap_teardown =
969 !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
970
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700971 hostapd_interface_deinit(wpa_s->ap_iface);
972 hostapd_interface_free(wpa_s->ap_iface);
973 wpa_s->ap_iface = NULL;
974 wpa_drv_deinit_ap(wpa_s);
Dmitry Shmidtf73259c2015-03-17 11:00:54 -0700975 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
976 " reason=%d locally_generated=1",
977 MAC2STR(wpa_s->own_addr), WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700978}
979
980
981void ap_tx_status(void *ctx, const u8 *addr,
982 const u8 *buf, size_t len, int ack)
983{
984#ifdef NEED_AP_MLME
985 struct wpa_supplicant *wpa_s = ctx;
986 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
987#endif /* NEED_AP_MLME */
988}
989
990
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800991void ap_eapol_tx_status(void *ctx, const u8 *dst,
992 const u8 *data, size_t len, int ack)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700993{
994#ifdef NEED_AP_MLME
995 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800996 if (!wpa_s->ap_iface)
997 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800998 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
999#endif /* NEED_AP_MLME */
1000}
1001
1002
1003void ap_client_poll_ok(void *ctx, const u8 *addr)
1004{
1005#ifdef NEED_AP_MLME
1006 struct wpa_supplicant *wpa_s = ctx;
1007 if (wpa_s->ap_iface)
1008 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
1009#endif /* NEED_AP_MLME */
1010}
1011
1012
1013void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
1014{
1015#ifdef NEED_AP_MLME
1016 struct wpa_supplicant *wpa_s = ctx;
1017 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001018#endif /* NEED_AP_MLME */
1019}
1020
1021
1022void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
1023{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001024#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001025 struct wpa_supplicant *wpa_s = ctx;
1026 struct hostapd_frame_info fi;
1027 os_memset(&fi, 0, sizeof(fi));
1028 fi.datarate = rx_mgmt->datarate;
1029 fi.ssi_signal = rx_mgmt->ssi_signal;
1030 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
1031 rx_mgmt->frame_len, &fi);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001032#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001033}
1034
1035
1036void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
1037{
1038#ifdef NEED_AP_MLME
1039 struct wpa_supplicant *wpa_s = ctx;
1040 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
1041#endif /* NEED_AP_MLME */
1042}
1043
1044
1045void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
1046 const u8 *src_addr, const u8 *buf, size_t len)
1047{
1048 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
1049}
1050
1051
1052#ifdef CONFIG_WPS
1053
1054int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
1055 const u8 *p2p_dev_addr)
1056{
1057 if (!wpa_s->ap_iface)
1058 return -1;
1059 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
1060 p2p_dev_addr);
1061}
1062
1063
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001064int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
1065{
1066 struct wps_registrar *reg;
1067 int reg_sel = 0, wps_sta = 0;
1068
1069 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
1070 return -1;
1071
1072 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
1073 reg_sel = wps_registrar_wps_cancel(reg);
1074 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
Dmitry Shmidt04949592012-07-19 12:16:46 -07001075 ap_sta_wps_cancel, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001076
1077 if (!reg_sel && !wps_sta) {
1078 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
1079 "time");
1080 return -1;
1081 }
1082
1083 /*
1084 * There are 2 cases to return wps cancel as success:
1085 * 1. When wps cancel was initiated but no connection has been
1086 * established with client yet.
1087 * 2. Client is in the middle of exchanging WPS messages.
1088 */
1089
1090 return 0;
1091}
1092
1093
1094int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001095 const char *pin, char *buf, size_t buflen,
1096 int timeout)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001097{
1098 int ret, ret_len = 0;
1099
1100 if (!wpa_s->ap_iface)
1101 return -1;
1102
1103 if (pin == NULL) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001104 unsigned int rpin;
1105
1106 if (wps_generate_pin(&rpin) < 0)
1107 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001108 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001109 if (os_snprintf_error(buflen, ret_len))
1110 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001111 pin = buf;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001112 } else if (buf) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001113 ret_len = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001114 if (os_snprintf_error(buflen, ret_len))
1115 return -1;
1116 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001117
1118 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001119 timeout);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001120 if (ret)
1121 return -1;
1122 return ret_len;
1123}
1124
1125
1126static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
1127{
1128 struct wpa_supplicant *wpa_s = eloop_data;
1129 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
1130 wpas_wps_ap_pin_disable(wpa_s);
1131}
1132
1133
1134static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
1135{
1136 struct hostapd_data *hapd;
1137
1138 if (wpa_s->ap_iface == NULL)
1139 return;
1140 hapd = wpa_s->ap_iface->bss[0];
1141 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
1142 hapd->ap_pin_failures = 0;
1143 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1144 if (timeout > 0)
1145 eloop_register_timeout(timeout, 0,
1146 wpas_wps_ap_pin_timeout, wpa_s, NULL);
1147}
1148
1149
1150void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
1151{
1152 struct hostapd_data *hapd;
1153
1154 if (wpa_s->ap_iface == NULL)
1155 return;
1156 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
1157 hapd = wpa_s->ap_iface->bss[0];
1158 os_free(hapd->conf->ap_pin);
1159 hapd->conf->ap_pin = NULL;
1160 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1161}
1162
1163
1164const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
1165{
1166 struct hostapd_data *hapd;
1167 unsigned int pin;
1168 char pin_txt[9];
1169
1170 if (wpa_s->ap_iface == NULL)
1171 return NULL;
1172 hapd = wpa_s->ap_iface->bss[0];
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001173 if (wps_generate_pin(&pin) < 0)
1174 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001175 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001176 os_free(hapd->conf->ap_pin);
1177 hapd->conf->ap_pin = os_strdup(pin_txt);
1178 if (hapd->conf->ap_pin == NULL)
1179 return NULL;
1180 wpas_wps_ap_pin_enable(wpa_s, timeout);
1181
1182 return hapd->conf->ap_pin;
1183}
1184
1185
1186const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
1187{
1188 struct hostapd_data *hapd;
1189 if (wpa_s->ap_iface == NULL)
1190 return NULL;
1191 hapd = wpa_s->ap_iface->bss[0];
1192 return hapd->conf->ap_pin;
1193}
1194
1195
1196int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
1197 int timeout)
1198{
1199 struct hostapd_data *hapd;
1200 char pin_txt[9];
1201 int ret;
1202
1203 if (wpa_s->ap_iface == NULL)
1204 return -1;
1205 hapd = wpa_s->ap_iface->bss[0];
1206 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001207 if (os_snprintf_error(sizeof(pin_txt), ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001208 return -1;
1209 os_free(hapd->conf->ap_pin);
1210 hapd->conf->ap_pin = os_strdup(pin_txt);
1211 if (hapd->conf->ap_pin == NULL)
1212 return -1;
1213 wpas_wps_ap_pin_enable(wpa_s, timeout);
1214
1215 return 0;
1216}
1217
1218
1219void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
1220{
1221 struct hostapd_data *hapd;
1222
1223 if (wpa_s->ap_iface == NULL)
1224 return;
1225 hapd = wpa_s->ap_iface->bss[0];
1226
1227 /*
1228 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
1229 * PIN if this happens multiple times to slow down brute force attacks.
1230 */
1231 hapd->ap_pin_failures++;
1232 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
1233 hapd->ap_pin_failures);
1234 if (hapd->ap_pin_failures < 3)
1235 return;
1236
1237 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
1238 hapd->ap_pin_failures = 0;
1239 os_free(hapd->conf->ap_pin);
1240 hapd->conf->ap_pin = NULL;
1241}
1242
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001243
1244#ifdef CONFIG_WPS_NFC
1245
1246struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
1247 int ndef)
1248{
1249 struct hostapd_data *hapd;
1250
1251 if (wpa_s->ap_iface == NULL)
1252 return NULL;
1253 hapd = wpa_s->ap_iface->bss[0];
1254 return hostapd_wps_nfc_config_token(hapd, ndef);
1255}
1256
1257
1258struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
1259 int ndef)
1260{
1261 struct hostapd_data *hapd;
1262
1263 if (wpa_s->ap_iface == NULL)
1264 return NULL;
1265 hapd = wpa_s->ap_iface->bss[0];
1266 return hostapd_wps_nfc_hs_cr(hapd, ndef);
1267}
1268
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001269
1270int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
1271 const struct wpabuf *req,
1272 const struct wpabuf *sel)
1273{
1274 struct hostapd_data *hapd;
1275
1276 if (wpa_s->ap_iface == NULL)
1277 return -1;
1278 hapd = wpa_s->ap_iface->bss[0];
1279 return hostapd_wps_nfc_report_handover(hapd, req, sel);
1280}
1281
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001282#endif /* CONFIG_WPS_NFC */
1283
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001284#endif /* CONFIG_WPS */
1285
1286
1287#ifdef CONFIG_CTRL_IFACE
1288
1289int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
1290 char *buf, size_t buflen)
1291{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001292 struct hostapd_data *hapd;
1293
1294 if (wpa_s->ap_iface)
1295 hapd = wpa_s->ap_iface->bss[0];
1296 else if (wpa_s->ifmsh)
1297 hapd = wpa_s->ifmsh->bss[0];
1298 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001299 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001300 return hostapd_ctrl_iface_sta_first(hapd, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001301}
1302
1303
1304int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
1305 char *buf, size_t buflen)
1306{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001307 struct hostapd_data *hapd;
1308
1309 if (wpa_s->ap_iface)
1310 hapd = wpa_s->ap_iface->bss[0];
1311 else if (wpa_s->ifmsh)
1312 hapd = wpa_s->ifmsh->bss[0];
1313 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001314 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001315 return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001316}
1317
1318
1319int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
1320 char *buf, size_t buflen)
1321{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001322 struct hostapd_data *hapd;
1323
1324 if (wpa_s->ap_iface)
1325 hapd = wpa_s->ap_iface->bss[0];
1326 else if (wpa_s->ifmsh)
1327 hapd = wpa_s->ifmsh->bss[0];
1328 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001329 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001330 return hostapd_ctrl_iface_sta_next(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001331}
1332
1333
Dmitry Shmidt04949592012-07-19 12:16:46 -07001334int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1335 const char *txtaddr)
1336{
1337 if (wpa_s->ap_iface == NULL)
1338 return -1;
1339 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1340 txtaddr);
1341}
1342
1343
1344int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1345 const char *txtaddr)
1346{
1347 if (wpa_s->ap_iface == NULL)
1348 return -1;
1349 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1350 txtaddr);
1351}
1352
1353
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001354int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1355 size_t buflen, int verbose)
1356{
1357 char *pos = buf, *end = buf + buflen;
1358 int ret;
1359 struct hostapd_bss_config *conf;
1360
1361 if (wpa_s->ap_iface == NULL)
1362 return -1;
1363
1364 conf = wpa_s->ap_iface->bss[0]->conf;
1365 if (conf->wpa == 0)
1366 return 0;
1367
1368 ret = os_snprintf(pos, end - pos,
1369 "pairwise_cipher=%s\n"
1370 "group_cipher=%s\n"
1371 "key_mgmt=%s\n",
1372 wpa_cipher_txt(conf->rsn_pairwise),
1373 wpa_cipher_txt(conf->wpa_group),
1374 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1375 conf->wpa));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001376 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001377 return pos - buf;
1378 pos += ret;
1379 return pos - buf;
1380}
1381
1382#endif /* CONFIG_CTRL_IFACE */
1383
1384
1385int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1386{
1387 struct hostapd_iface *iface = wpa_s->ap_iface;
1388 struct wpa_ssid *ssid = wpa_s->current_ssid;
1389 struct hostapd_data *hapd;
1390
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001391 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1392 ssid->mode == WPAS_MODE_INFRA ||
1393 ssid->mode == WPAS_MODE_IBSS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001394 return -1;
1395
1396#ifdef CONFIG_P2P
1397 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001398 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001399 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001400 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001401 P2P_GROUP_FORMATION;
1402#endif /* CONFIG_P2P */
1403
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001404 hapd = iface->bss[0];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001405 if (hapd->drv_priv == NULL)
1406 return -1;
1407 ieee802_11_set_beacons(iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001408 hostapd_set_ap_wps_ie(hapd);
1409
1410 return 0;
1411}
1412
1413
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001414int ap_switch_channel(struct wpa_supplicant *wpa_s,
1415 struct csa_settings *settings)
1416{
1417#ifdef NEED_AP_MLME
1418 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1419 return -1;
1420
1421 return hostapd_switch_channel(wpa_s->ap_iface->bss[0], settings);
1422#else /* NEED_AP_MLME */
1423 return -1;
1424#endif /* NEED_AP_MLME */
1425}
1426
1427
Dmitry Shmidt83474442015-04-15 13:47:09 -07001428#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001429int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1430{
1431 struct csa_settings settings;
1432 int ret = hostapd_parse_csa_settings(pos, &settings);
1433
1434 if (ret)
1435 return ret;
1436
1437 return ap_switch_channel(wpa_s, &settings);
1438}
Dmitry Shmidt83474442015-04-15 13:47:09 -07001439#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001440
1441
Dmitry Shmidt04949592012-07-19 12:16:46 -07001442void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
Hai Shalom81f62d82019-07-22 12:10:00 -07001443 int offset, int width, int cf1, int cf2, int finished)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001444{
Hai Shalom74f70d42019-02-11 14:42:39 -08001445 struct hostapd_iface *iface = wpa_s->ap_iface;
Hai Shalombf6e0ba2019-02-11 12:01:50 -08001446
Hai Shalom74f70d42019-02-11 14:42:39 -08001447 if (!iface)
1448 iface = wpa_s->ifmsh;
1449 if (!iface)
1450 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001451 wpa_s->assoc_freq = freq;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001452 if (wpa_s->current_ssid)
1453 wpa_s->current_ssid->frequency = freq;
Hai Shalom74f70d42019-02-11 14:42:39 -08001454 hostapd_event_ch_switch(iface->bss[0], freq, ht,
Hai Shalom81f62d82019-07-22 12:10:00 -07001455 offset, width, cf1, cf2, finished);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001456}
1457
1458
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001459int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1460 const u8 *addr)
1461{
1462 struct hostapd_data *hapd;
1463 struct hostapd_bss_config *conf;
1464
1465 if (!wpa_s->ap_iface)
1466 return -1;
1467
1468 if (addr)
1469 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1470 MAC2STR(addr));
1471 else
1472 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1473
1474 hapd = wpa_s->ap_iface->bss[0];
1475 conf = hapd->conf;
1476
1477 os_free(conf->accept_mac);
1478 conf->accept_mac = NULL;
1479 conf->num_accept_mac = 0;
1480 os_free(conf->deny_mac);
1481 conf->deny_mac = NULL;
1482 conf->num_deny_mac = 0;
1483
1484 if (addr == NULL) {
1485 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1486 return 0;
1487 }
1488
1489 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1490 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1491 if (conf->accept_mac == NULL)
1492 return -1;
1493 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1494 conf->num_accept_mac = 1;
1495
1496 return 0;
1497}
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001498
1499
1500#ifdef CONFIG_WPS_NFC
1501int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1502 const struct wpabuf *pw, const u8 *pubkey_hash)
1503{
1504 struct hostapd_data *hapd;
1505 struct wps_context *wps;
1506
1507 if (!wpa_s->ap_iface)
1508 return -1;
1509 hapd = wpa_s->ap_iface->bss[0];
1510 wps = hapd->wps;
1511
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001512 if (wpa_s->p2pdev->conf->wps_nfc_dh_pubkey == NULL ||
1513 wpa_s->p2pdev->conf->wps_nfc_dh_privkey == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001514 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1515 return -1;
1516 }
1517
1518 dh5_free(wps->dh_ctx);
1519 wpabuf_free(wps->dh_pubkey);
1520 wpabuf_free(wps->dh_privkey);
1521 wps->dh_privkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001522 wpa_s->p2pdev->conf->wps_nfc_dh_privkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001523 wps->dh_pubkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001524 wpa_s->p2pdev->conf->wps_nfc_dh_pubkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001525 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1526 wps->dh_ctx = NULL;
1527 wpabuf_free(wps->dh_pubkey);
1528 wps->dh_pubkey = NULL;
1529 wpabuf_free(wps->dh_privkey);
1530 wps->dh_privkey = NULL;
1531 return -1;
1532 }
1533 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1534 if (wps->dh_ctx == NULL)
1535 return -1;
1536
1537 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1538 pw_id,
1539 pw ? wpabuf_head(pw) : NULL,
1540 pw ? wpabuf_len(pw) : 0, 1);
1541}
1542#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001543
1544
Dmitry Shmidt83474442015-04-15 13:47:09 -07001545#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001546int wpas_ap_stop_ap(struct wpa_supplicant *wpa_s)
1547{
1548 struct hostapd_data *hapd;
1549
1550 if (!wpa_s->ap_iface)
1551 return -1;
1552 hapd = wpa_s->ap_iface->bss[0];
1553 return hostapd_ctrl_iface_stop_ap(hapd);
1554}
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001555
1556
Dmitry Shmidte4663042016-04-04 10:07:49 -07001557int wpas_ap_pmksa_cache_list(struct wpa_supplicant *wpa_s, char *buf,
1558 size_t len)
1559{
1560 size_t reply_len = 0, i;
1561 char ap_delimiter[] = "---- AP ----\n";
1562 char mesh_delimiter[] = "---- mesh ----\n";
1563 size_t dlen;
1564
1565 if (wpa_s->ap_iface) {
1566 dlen = os_strlen(ap_delimiter);
1567 if (dlen > len - reply_len)
1568 return reply_len;
1569 os_memcpy(&buf[reply_len], ap_delimiter, dlen);
1570 reply_len += dlen;
1571
1572 for (i = 0; i < wpa_s->ap_iface->num_bss; i++) {
1573 reply_len += hostapd_ctrl_iface_pmksa_list(
1574 wpa_s->ap_iface->bss[i],
1575 &buf[reply_len], len - reply_len);
1576 }
1577 }
1578
1579 if (wpa_s->ifmsh) {
1580 dlen = os_strlen(mesh_delimiter);
1581 if (dlen > len - reply_len)
1582 return reply_len;
1583 os_memcpy(&buf[reply_len], mesh_delimiter, dlen);
1584 reply_len += dlen;
1585
1586 reply_len += hostapd_ctrl_iface_pmksa_list(
1587 wpa_s->ifmsh->bss[0], &buf[reply_len],
1588 len - reply_len);
1589 }
1590
1591 return reply_len;
1592}
1593
1594
1595void wpas_ap_pmksa_cache_flush(struct wpa_supplicant *wpa_s)
1596{
1597 size_t i;
1598
1599 if (wpa_s->ap_iface) {
1600 for (i = 0; i < wpa_s->ap_iface->num_bss; i++)
1601 hostapd_ctrl_iface_pmksa_flush(wpa_s->ap_iface->bss[i]);
1602 }
1603
1604 if (wpa_s->ifmsh)
1605 hostapd_ctrl_iface_pmksa_flush(wpa_s->ifmsh->bss[0]);
1606}
Paul Stewart092955c2017-02-06 09:13:09 -08001607
1608
1609#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
1610#ifdef CONFIG_MESH
1611
1612int wpas_ap_pmksa_cache_list_mesh(struct wpa_supplicant *wpa_s, const u8 *addr,
1613 char *buf, size_t len)
1614{
1615 return hostapd_ctrl_iface_pmksa_list_mesh(wpa_s->ifmsh->bss[0], addr,
1616 &buf[0], len);
1617}
1618
1619
1620int wpas_ap_pmksa_cache_add_external(struct wpa_supplicant *wpa_s, char *cmd)
1621{
1622 struct external_pmksa_cache *entry;
1623 void *pmksa_cache;
1624
1625 pmksa_cache = hostapd_ctrl_iface_pmksa_create_entry(wpa_s->own_addr,
1626 cmd);
1627 if (!pmksa_cache)
1628 return -1;
1629
1630 entry = os_zalloc(sizeof(struct external_pmksa_cache));
1631 if (!entry)
1632 return -1;
1633
1634 entry->pmksa_cache = pmksa_cache;
1635
1636 dl_list_add(&wpa_s->mesh_external_pmksa_cache, &entry->list);
1637
1638 return 0;
1639}
1640
1641#endif /* CONFIG_MESH */
1642#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
1643
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001644#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte4663042016-04-04 10:07:49 -07001645
1646
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001647#ifdef NEED_AP_MLME
Roshan Pius3a1667e2018-07-03 15:17:14 -07001648void wpas_ap_event_dfs_radar_detected(struct wpa_supplicant *wpa_s,
1649 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001650{
Hai Shalom74f70d42019-02-11 14:42:39 -08001651 struct hostapd_iface *iface = wpa_s->ap_iface;
1652
1653 if (!iface)
1654 iface = wpa_s->ifmsh;
1655 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001656 return;
1657 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001658 hostapd_dfs_radar_detected(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001659 radar->ht_enabled, radar->chan_offset,
1660 radar->chan_width,
1661 radar->cf1, radar->cf2);
1662}
1663
1664
Roshan Pius3a1667e2018-07-03 15:17:14 -07001665void wpas_ap_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
1666 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001667{
Hai Shalom74f70d42019-02-11 14:42:39 -08001668 struct hostapd_iface *iface = wpa_s->ap_iface;
1669
1670 if (!iface)
1671 iface = wpa_s->ifmsh;
1672 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001673 return;
1674 wpa_printf(MSG_DEBUG, "DFS CAC started on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001675 hostapd_dfs_start_cac(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001676 radar->ht_enabled, radar->chan_offset,
1677 radar->chan_width, radar->cf1, radar->cf2);
1678}
1679
1680
Roshan Pius3a1667e2018-07-03 15:17:14 -07001681void wpas_ap_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
1682 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001683{
Hai Shalom74f70d42019-02-11 14:42:39 -08001684 struct hostapd_iface *iface = wpa_s->ap_iface;
1685
1686 if (!iface)
1687 iface = wpa_s->ifmsh;
1688 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001689 return;
1690 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001691 hostapd_dfs_complete_cac(iface, 1, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001692 radar->ht_enabled, radar->chan_offset,
1693 radar->chan_width, radar->cf1, radar->cf2);
1694}
1695
1696
Roshan Pius3a1667e2018-07-03 15:17:14 -07001697void wpas_ap_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
1698 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001699{
Hai Shalom74f70d42019-02-11 14:42:39 -08001700 struct hostapd_iface *iface = wpa_s->ap_iface;
1701
1702 if (!iface)
1703 iface = wpa_s->ifmsh;
1704 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001705 return;
1706 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001707 hostapd_dfs_complete_cac(iface, 0, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001708 radar->ht_enabled, radar->chan_offset,
1709 radar->chan_width, radar->cf1, radar->cf2);
1710}
1711
1712
Roshan Pius3a1667e2018-07-03 15:17:14 -07001713void wpas_ap_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s,
1714 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001715{
Hai Shalom74f70d42019-02-11 14:42:39 -08001716 struct hostapd_iface *iface = wpa_s->ap_iface;
1717
1718 if (!iface)
1719 iface = wpa_s->ifmsh;
1720 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001721 return;
1722 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001723 hostapd_dfs_nop_finished(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001724 radar->ht_enabled, radar->chan_offset,
1725 radar->chan_width, radar->cf1, radar->cf2);
1726}
1727#endif /* NEED_AP_MLME */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001728
1729
1730void ap_periodic(struct wpa_supplicant *wpa_s)
1731{
1732 if (wpa_s->ap_iface)
1733 hostapd_periodic_iface(wpa_s->ap_iface);
1734}