blob: c89b80f6ae357fcdf3d97f8f38462387e1a631fb [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
Hsis-Chang Chen44b08ec2020-11-18 16:21:29 +053047static bool is_chanwidth160_supported(struct hostapd_hw_modes *mode,
48 struct hostapd_config *conf)
49{
50#ifdef CONFIG_IEEE80211AX
51 if (conf->ieee80211ax) {
52 struct he_capabilities *he_cap;
53
54 he_cap = &mode->he_capab[IEEE80211_MODE_AP];
55 if (he_cap->phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX] &
56 (HE_PHYCAP_CHANNEL_WIDTH_SET_80PLUS80MHZ_IN_5G |
57 HE_PHYCAP_CHANNEL_WIDTH_SET_160MHZ_IN_5G))
58 return true;
59 }
60#endif /* CONFIG_IEEE80211AX */
61 if (mode->vht_capab & (VHT_CAP_SUPP_CHAN_WIDTH_160MHZ |
62 VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ))
63 return true;
64 return false;
65}
66
67
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070068static void wpas_conf_ap_vht(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070069 struct wpa_ssid *ssid,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070070 struct hostapd_config *conf,
71 struct hostapd_hw_modes *mode)
72{
Dmitry Shmidt21de2142014-04-08 10:50:52 -070073#ifdef CONFIG_P2P
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070074 u8 center_chan = 0;
75 u8 channel = conf->channel;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070076#endif /* CONFIG_P2P */
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070077
78 if (!conf->secondary_channel)
79 goto no_vht;
80
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070081 /* Use the maximum oper channel width if it's given. */
82 if (ssid->max_oper_chwidth)
83 conf->vht_oper_chwidth = ssid->max_oper_chwidth;
84
85 ieee80211_freq_to_chan(ssid->vht_center_freq2,
86 &conf->vht_oper_centr_freq_seg1_idx);
87
88 if (!ssid->p2p_group) {
89 if (!ssid->vht_center_freq1 ||
Hai Shalom81f62d82019-07-22 12:10:00 -070090 conf->vht_oper_chwidth == CHANWIDTH_USE_HT)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070091 goto no_vht;
92 ieee80211_freq_to_chan(ssid->vht_center_freq1,
93 &conf->vht_oper_centr_freq_seg0_idx);
Roshan Pius3a1667e2018-07-03 15:17:14 -070094 wpa_printf(MSG_DEBUG, "VHT seg0 index %d for AP",
95 conf->vht_oper_centr_freq_seg0_idx);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070096 return;
97 }
98
99#ifdef CONFIG_P2P
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800100 switch (conf->vht_oper_chwidth) {
Hai Shalom81f62d82019-07-22 12:10:00 -0700101 case CHANWIDTH_80MHZ:
102 case CHANWIDTH_80P80MHZ:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800103 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700104 wpa_printf(MSG_DEBUG,
105 "VHT center channel %u for 80 or 80+80 MHz bandwidth",
106 center_chan);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800107 break;
Hai Shalom81f62d82019-07-22 12:10:00 -0700108 case CHANWIDTH_160MHZ:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800109 center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700110 wpa_printf(MSG_DEBUG,
111 "VHT center channel %u for 160 MHz bandwidth",
112 center_chan);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800113 break;
114 default:
115 /*
116 * conf->vht_oper_chwidth might not be set for non-P2P GO cases,
117 * try oper_cwidth 160 MHz first then VHT 80 MHz, if 160 MHz is
118 * not supported.
119 */
Hai Shalom81f62d82019-07-22 12:10:00 -0700120 conf->vht_oper_chwidth = CHANWIDTH_160MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800121 center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel);
Hsis-Chang Chen44b08ec2020-11-18 16:21:29 +0530122 if (center_chan && is_chanwidth160_supported(mode, conf)) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700123 wpa_printf(MSG_DEBUG,
124 "VHT center channel %u for auto-selected 160 MHz bandwidth",
125 center_chan);
126 } else {
Hai Shalom81f62d82019-07-22 12:10:00 -0700127 conf->vht_oper_chwidth = CHANWIDTH_80MHZ;
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800128 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode,
129 channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700130 wpa_printf(MSG_DEBUG,
131 "VHT center channel %u for auto-selected 80 MHz bandwidth",
132 center_chan);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800133 }
134 break;
135 }
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700136 if (!center_chan)
137 goto no_vht;
138
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700139 conf->vht_oper_centr_freq_seg0_idx = center_chan;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700140 wpa_printf(MSG_DEBUG, "VHT seg0 index %d for P2P GO",
141 conf->vht_oper_centr_freq_seg0_idx);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700142 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700143#endif /* CONFIG_P2P */
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700144
145no_vht:
Roshan Pius3a1667e2018-07-03 15:17:14 -0700146 wpa_printf(MSG_DEBUG,
147 "No VHT higher bandwidth support for the selected channel %d",
148 conf->channel);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700149 conf->vht_oper_centr_freq_seg0_idx =
Dmitry Shmidt21de2142014-04-08 10:50:52 -0700150 conf->channel + conf->secondary_channel * 2;
Hai Shalom81f62d82019-07-22 12:10:00 -0700151 conf->vht_oper_chwidth = CHANWIDTH_USE_HT;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700152}
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700153
154
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800155int wpa_supplicant_conf_ap_ht(struct wpa_supplicant *wpa_s,
156 struct wpa_ssid *ssid,
157 struct hostapd_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700158{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800159 conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency,
160 &conf->channel);
161
162 if (conf->hw_mode == NUM_HOSTAPD_MODES) {
163 wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
164 ssid->frequency);
165 return -1;
166 }
167
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700168 /* TODO: enable HT40 if driver supports it;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700169 * drop to 11b if driver does not support 11g */
170
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700171 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800172 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
173 * and a mask of allowed capabilities within conf->ht_capab.
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700174 * Using default config settings for: conf->ht_op_mode_fixed,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800175 * conf->secondary_channel, conf->require_ht
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700176 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800177 if (wpa_s->hw.modes) {
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700178 struct hostapd_hw_modes *mode = NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700179 int i, no_ht = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700180
181 wpa_printf(MSG_DEBUG,
182 "Determining HT/VHT options based on driver capabilities (freq=%u chan=%u)",
183 ssid->frequency, conf->channel);
184
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800185 for (i = 0; i < wpa_s->hw.num_modes; i++) {
186 if (wpa_s->hw.modes[i].mode == conf->hw_mode) {
187 mode = &wpa_s->hw.modes[i];
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700188 break;
189 }
190 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700191
192#ifdef CONFIG_HT_OVERRIDES
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700193 if (ssid->disable_ht)
194 ssid->ht = 0;
195#endif /* CONFIG_HT_OVERRIDES */
196
197 if (!ssid->ht) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700198 wpa_printf(MSG_DEBUG,
199 "HT not enabled in network profile");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700200 conf->ieee80211n = 0;
201 conf->ht_capab = 0;
202 no_ht = 1;
203 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700204
205 if (!no_ht && mode && mode->ht_capab) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700206 wpa_printf(MSG_DEBUG,
207 "Enable HT support (p2p_group=%d 11a=%d ht40_hw_capab=%d ssid->ht40=%d)",
208 ssid->p2p_group,
209 conf->hw_mode == HOSTAPD_MODE_IEEE80211A,
210 !!(mode->ht_capab &
211 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET),
212 ssid->ht40);
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700213 conf->ieee80211n = 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700214#ifdef CONFIG_P2P
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700215 if (ssid->p2p_group &&
216 conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700217 (mode->ht_capab &
218 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -0700219 ssid->ht40) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700220 conf->secondary_channel =
221 wpas_p2p_get_ht40_mode(wpa_s, mode,
222 conf->channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700223 wpa_printf(MSG_DEBUG,
224 "HT secondary channel offset %d for P2P group",
225 conf->secondary_channel);
226 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700227#endif /* CONFIG_P2P */
228
229 if (!ssid->p2p_group &&
230 (mode->ht_capab &
Roshan Pius3a1667e2018-07-03 15:17:14 -0700231 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700232 conf->secondary_channel = ssid->ht40;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700233 wpa_printf(MSG_DEBUG,
234 "HT secondary channel offset %d for AP",
235 conf->secondary_channel);
236 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700237
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700238 if (conf->secondary_channel)
239 conf->ht_capab |=
240 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800241
242 /*
243 * white-list capabilities that won't cause issues
244 * to connecting stations, while leaving the current
245 * capabilities intact (currently disabled SMPS).
246 */
247 conf->ht_capab |= mode->ht_capab &
248 (HT_CAP_INFO_GREEN_FIELD |
249 HT_CAP_INFO_SHORT_GI20MHZ |
250 HT_CAP_INFO_SHORT_GI40MHZ |
251 HT_CAP_INFO_RX_STBC_MASK |
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800252 HT_CAP_INFO_TX_STBC |
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800253 HT_CAP_INFO_MAX_AMSDU_SIZE);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700254
255 if (mode->vht_capab && ssid->vht) {
256 conf->ieee80211ac = 1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800257 conf->vht_capab |= mode->vht_capab;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700258 wpas_conf_ap_vht(wpa_s, ssid, conf, mode);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700259 }
Hai Shalom81f62d82019-07-22 12:10:00 -0700260
261 if (mode->he_capab[wpas_mode_to_ieee80211_mode(
262 ssid->mode)].he_supported &&
263 ssid->he)
264 conf->ieee80211ax = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800265 }
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700266 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800267
268 if (conf->secondary_channel) {
269 struct wpa_supplicant *iface;
270
271 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
272 {
273 if (iface == wpa_s ||
274 iface->wpa_state < WPA_AUTHENTICATING ||
275 (int) iface->assoc_freq != ssid->frequency)
276 continue;
277
278 /*
279 * Do not allow 40 MHz co-ex PRI/SEC switch to force us
280 * to change our PRI channel since we have an existing,
281 * concurrent connection on that channel and doing
282 * multi-channel concurrency is likely to cause more
283 * harm than using different PRI/SEC selection in
284 * environment with multiple BSSes on these two channels
285 * with mixed 20 MHz or PRI channel selection.
286 */
287 conf->no_pri_sec_switch = 1;
288 }
289 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800290
291 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800292}
293
294
295static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
296 struct wpa_ssid *ssid,
297 struct hostapd_config *conf)
298{
299 struct hostapd_bss_config *bss = conf->bss[0];
300
301 conf->driver = wpa_s->driver;
302
303 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
304
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800305 if (wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800306 return -1;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700307
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700308 if (ssid->pbss > 1) {
309 wpa_printf(MSG_ERROR, "Invalid pbss value(%d) for AP mode",
310 ssid->pbss);
311 return -1;
312 }
313 bss->pbss = ssid->pbss;
314
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800315#ifdef CONFIG_ACS
316 if (ssid->acs) {
317 /* Setting channel to 0 in order to enable ACS */
318 conf->channel = 0;
319 wpa_printf(MSG_DEBUG, "Use automatic channel selection");
320 }
321#endif /* CONFIG_ACS */
322
Roshan Pius3a1667e2018-07-03 15:17:14 -0700323 if (ieee80211_is_dfs(ssid->frequency, wpa_s->hw.modes,
324 wpa_s->hw.num_modes) && wpa_s->conf->country[0]) {
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800325 conf->ieee80211h = 1;
326 conf->ieee80211d = 1;
327 conf->country[0] = wpa_s->conf->country[0];
328 conf->country[1] = wpa_s->conf->country[1];
Paul Stewart092955c2017-02-06 09:13:09 -0800329 conf->country[2] = ' ';
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800330 }
331
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700332#ifdef CONFIG_P2P
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700333 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
334 (ssid->mode == WPAS_MODE_P2P_GO ||
335 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700336 /* Remove 802.11b rates from supported and basic rate sets */
337 int *list = os_malloc(4 * sizeof(int));
338 if (list) {
339 list[0] = 60;
340 list[1] = 120;
341 list[2] = 240;
342 list[3] = -1;
343 }
344 conf->basic_rates = list;
345
346 list = os_malloc(9 * sizeof(int));
347 if (list) {
348 list[0] = 60;
349 list[1] = 90;
350 list[2] = 120;
351 list[3] = 180;
352 list[4] = 240;
353 list[5] = 360;
354 list[6] = 480;
355 list[7] = 540;
356 list[8] = -1;
357 }
358 conf->supported_rates = list;
Hai Shalom021b0b52019-04-10 11:17:58 -0700359 }
360
Hai Shalom74f70d42019-02-11 14:42:39 -0800361#ifdef CONFIG_IEEE80211AX
Hai Shalom021b0b52019-04-10 11:17:58 -0700362 if (ssid->mode == WPAS_MODE_P2P_GO ||
363 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Hai Shalom74f70d42019-02-11 14:42:39 -0800364 conf->ieee80211ax = ssid->he;
365#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800366
367 bss->isolate = !wpa_s->conf->p2p_intra_bss;
Hai Shalomfdcde762020-04-02 11:19:20 -0700368 bss->extended_key_id = wpa_s->conf->extended_key_id;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700369 bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
Hai Shalomfdcde762020-04-02 11:19:20 -0700370 bss->wpa_deny_ptk0_rekey = ssid->wpa_deny_ptk0_rekey;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800371
372 if (ssid->p2p_group) {
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800373 os_memcpy(bss->ip_addr_go, wpa_s->p2pdev->conf->ip_addr_go, 4);
374 os_memcpy(bss->ip_addr_mask, wpa_s->p2pdev->conf->ip_addr_mask,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800375 4);
376 os_memcpy(bss->ip_addr_start,
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800377 wpa_s->p2pdev->conf->ip_addr_start, 4);
378 os_memcpy(bss->ip_addr_end, wpa_s->p2pdev->conf->ip_addr_end,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800379 4);
380 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700381#endif /* CONFIG_P2P */
382
383 if (ssid->ssid_len == 0) {
384 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
385 return -1;
386 }
387 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700388 bss->ssid.ssid_len = ssid->ssid_len;
389 bss->ssid.ssid_set = 1;
390
Dmitry Shmidt04949592012-07-19 12:16:46 -0700391 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
392
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800393 if (ssid->auth_alg)
394 bss->auth_algs = ssid->auth_alg;
395
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700396 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
397 bss->wpa = ssid->proto;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700398 if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
399 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
400 else
401 bss->wpa_key_mgmt = ssid->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700402 bss->wpa_pairwise = ssid->pairwise_cipher;
Hai Shalomc3565922019-10-28 11:58:20 -0700403 if (wpa_key_mgmt_sae(bss->wpa_key_mgmt) && ssid->passphrase) {
404 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
405 } else if (ssid->psk_set) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800406 bin_clear_free(bss->ssid.wpa_psk, sizeof(*bss->ssid.wpa_psk));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700407 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
408 if (bss->ssid.wpa_psk == NULL)
409 return -1;
410 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
411 bss->ssid.wpa_psk->group = 1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700412 bss->ssid.wpa_psk_set = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800413 } else if (ssid->passphrase) {
414 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
Hai Shalomfdcde762020-04-02 11:19:20 -0700415#ifdef CONFIG_WEP
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800416 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
417 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
418 struct hostapd_wep_keys *wep = &bss->ssid.wep;
419 int i;
420 for (i = 0; i < NUM_WEP_KEYS; i++) {
421 if (ssid->wep_key_len[i] == 0)
422 continue;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700423 wep->key[i] = os_memdup(ssid->wep_key[i],
424 ssid->wep_key_len[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800425 if (wep->key[i] == NULL)
426 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800427 wep->len[i] = ssid->wep_key_len[i];
428 }
429 wep->idx = ssid->wep_tx_keyidx;
430 wep->keys_set = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700431#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700432 }
Hai Shalomc3565922019-10-28 11:58:20 -0700433#ifdef CONFIG_SAE
434 if (ssid->sae_password) {
435 struct sae_password_entry *pw;
436
437 pw = os_zalloc(sizeof(*pw));
438 if (!pw)
439 return -1;
440 os_memset(pw->peer_addr, 0xff, ETH_ALEN);
441 pw->password = os_strdup(ssid->sae_password);
442 if (!pw->password) {
443 os_free(pw);
444 return -1;
445 }
446 if (ssid->sae_password_id) {
447 pw->identifier = os_strdup(ssid->sae_password_id);
448 if (!pw->identifier) {
449 str_clear_free(pw->password);
450 os_free(pw);
451 return -1;
452 }
453 }
454
455 pw->next = bss->sae_passwords;
456 bss->sae_passwords = pw;
457 }
458
459 bss->sae_pwe = wpa_s->conf->sae_pwe;
460#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700461
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700462 if (wpa_s->conf->go_interworking) {
463 wpa_printf(MSG_DEBUG,
464 "P2P: Enable Interworking with access_network_type: %d",
465 wpa_s->conf->go_access_network_type);
466 bss->interworking = wpa_s->conf->go_interworking;
467 bss->access_network_type = wpa_s->conf->go_access_network_type;
468 bss->internet = wpa_s->conf->go_internet;
469 if (wpa_s->conf->go_venue_group) {
470 wpa_printf(MSG_DEBUG,
471 "P2P: Venue group: %d Venue type: %d",
472 wpa_s->conf->go_venue_group,
473 wpa_s->conf->go_venue_type);
474 bss->venue_group = wpa_s->conf->go_venue_group;
475 bss->venue_type = wpa_s->conf->go_venue_type;
476 bss->venue_info_set = 1;
477 }
478 }
479
Dmitry Shmidt04949592012-07-19 12:16:46 -0700480 if (ssid->ap_max_inactivity)
481 bss->ap_max_inactivity = ssid->ap_max_inactivity;
482
483 if (ssid->dtim_period)
484 bss->dtim_period = ssid->dtim_period;
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -0800485 else if (wpa_s->conf->dtim_period)
486 bss->dtim_period = wpa_s->conf->dtim_period;
487
488 if (ssid->beacon_int)
489 conf->beacon_int = ssid->beacon_int;
490 else if (wpa_s->conf->beacon_int)
491 conf->beacon_int = wpa_s->conf->beacon_int;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700492
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800493#ifdef CONFIG_P2P
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800494 if (ssid->mode == WPAS_MODE_P2P_GO ||
495 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
496 if (wpa_s->conf->p2p_go_ctwindow > conf->beacon_int) {
497 wpa_printf(MSG_INFO,
498 "CTWindow (%d) is bigger than beacon interval (%d) - avoid configuring it",
499 wpa_s->conf->p2p_go_ctwindow,
500 conf->beacon_int);
501 conf->p2p_go_ctwindow = 0;
502 } else {
503 conf->p2p_go_ctwindow = wpa_s->conf->p2p_go_ctwindow;
504 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800505 }
506#endif /* CONFIG_P2P */
507
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800508 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
509 bss->rsn_pairwise = bss->wpa_pairwise;
510 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
511 bss->rsn_pairwise);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700512
Hai Shalomfdcde762020-04-02 11:19:20 -0700513 if (bss->wpa && bss->ieee802_1x) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700514 bss->ssid.security_policy = SECURITY_WPA;
Hai Shalomfdcde762020-04-02 11:19:20 -0700515 } else if (bss->wpa) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700516 bss->ssid.security_policy = SECURITY_WPA_PSK;
Hai Shalomfdcde762020-04-02 11:19:20 -0700517#ifdef CONFIG_WEP
518 } else if (bss->ieee802_1x) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800519 int cipher = WPA_CIPHER_NONE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700520 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
521 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800522 if (bss->default_wep_key_len)
523 cipher = bss->default_wep_key_len >= 13 ?
524 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
525 bss->wpa_group = cipher;
526 bss->wpa_pairwise = cipher;
527 bss->rsn_pairwise = cipher;
528 } else if (bss->ssid.wep.keys_set) {
529 int cipher = WPA_CIPHER_WEP40;
530 if (bss->ssid.wep.len[0] >= 13)
531 cipher = WPA_CIPHER_WEP104;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700532 bss->ssid.security_policy = SECURITY_STATIC_WEP;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800533 bss->wpa_group = cipher;
534 bss->wpa_pairwise = cipher;
535 bss->rsn_pairwise = cipher;
Hai Shalomfdcde762020-04-02 11:19:20 -0700536#endif /* CONFIG_WEP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800537 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700538 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800539 bss->wpa_group = WPA_CIPHER_NONE;
540 bss->wpa_pairwise = WPA_CIPHER_NONE;
541 bss->rsn_pairwise = WPA_CIPHER_NONE;
542 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700543
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700544 if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
545 (bss->wpa_group == WPA_CIPHER_CCMP ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800546 bss->wpa_group == WPA_CIPHER_GCMP ||
547 bss->wpa_group == WPA_CIPHER_CCMP_256 ||
548 bss->wpa_group == WPA_CIPHER_GCMP_256)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700549 /*
550 * Strong ciphers do not need frequent rekeying, so increase
551 * the default GTK rekeying period to 24 hours.
552 */
553 bss->wpa_group_rekey = 86400;
554 }
555
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700556 if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT)
557 bss->ieee80211w = ssid->ieee80211w;
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700558
Hai Shalom74f70d42019-02-11 14:42:39 -0800559#ifdef CONFIG_OCV
560 bss->ocv = ssid->ocv;
561#endif /* CONFIG_OCV */
562
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700563#ifdef CONFIG_WPS
564 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800565 * Enable WPS by default for open and WPA/WPA2-Personal network, but
566 * require user interaction to actually use it. Only the internal
567 * Registrar is supported.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700568 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800569 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
570 bss->ssid.security_policy != SECURITY_PLAINTEXT)
571 goto no_wps;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800572 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800573 (!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ||
574 !(bss->wpa & 2)))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800575 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
576 * configuration */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700577 if (ssid->wps_disabled)
578 goto no_wps;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700579 bss->eap_server = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700580
581 if (!ssid->ignore_broadcast_ssid)
582 bss->wps_state = 2;
583
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700584 bss->ap_setup_locked = 2;
585 if (wpa_s->conf->config_methods)
586 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
587 os_memcpy(bss->device_type, wpa_s->conf->device_type,
588 WPS_DEV_TYPE_LEN);
589 if (wpa_s->conf->device_name) {
590 bss->device_name = os_strdup(wpa_s->conf->device_name);
591 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
592 }
593 if (wpa_s->conf->manufacturer)
594 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
595 if (wpa_s->conf->model_name)
596 bss->model_name = os_strdup(wpa_s->conf->model_name);
597 if (wpa_s->conf->model_number)
598 bss->model_number = os_strdup(wpa_s->conf->model_number);
599 if (wpa_s->conf->serial_number)
600 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
601 if (is_nil_uuid(wpa_s->conf->uuid))
602 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
603 else
604 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
605 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700606 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -0700607 if (ssid->eap.fragment_size != DEFAULT_FRAGMENT_SIZE)
608 bss->fragment_size = ssid->eap.fragment_size;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800609no_wps:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700610#endif /* CONFIG_WPS */
611
612 if (wpa_s->max_stations &&
613 wpa_s->max_stations < wpa_s->conf->max_num_sta)
614 bss->max_num_sta = wpa_s->max_stations;
615 else
616 bss->max_num_sta = wpa_s->conf->max_num_sta;
617
Roshan Pius3a1667e2018-07-03 15:17:14 -0700618 if (!bss->isolate)
619 bss->isolate = wpa_s->conf->ap_isolate;
620
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700621 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
622
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700623 if (wpa_s->conf->ap_vendor_elements) {
624 bss->vendor_elements =
625 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
626 }
627
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700628 bss->ftm_responder = wpa_s->conf->ftm_responder;
629 bss->ftm_initiator = wpa_s->conf->ftm_initiator;
630
Hai Shalomfdcde762020-04-02 11:19:20 -0700631 bss->transition_disable = ssid->transition_disable;
632
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700633 return 0;
634}
635
636
637static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
638{
639#ifdef CONFIG_P2P
640 struct wpa_supplicant *wpa_s = ctx;
641 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700642
643 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700644 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700645 return;
Dmitry Shmidt18463232014-01-24 12:29:41 -0800646 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
647 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700648 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
649 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700650 buf + IEEE80211_HDRLEN + 1,
651 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700652#endif /* CONFIG_P2P */
653}
654
655
656static void ap_wps_event_cb(void *ctx, enum wps_event event,
657 union wps_event_data *data)
658{
659#ifdef CONFIG_P2P
660 struct wpa_supplicant *wpa_s = ctx;
661
Jouni Malinen75ecf522011-06-27 15:19:46 -0700662 if (event == WPS_EV_FAIL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700663 struct wps_event_fail *fail = &data->fail;
664
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800665 if (wpa_s->p2pdev && wpa_s->p2pdev != wpa_s &&
Jouni Malinen75ecf522011-06-27 15:19:46 -0700666 wpa_s == wpa_s->global->p2p_group_formation) {
667 /*
668 * src/ap/wps_hostapd.c has already sent this on the
669 * main interface, so only send on the parent interface
670 * here if needed.
671 */
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800672 wpa_msg(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_FAIL
Jouni Malinen75ecf522011-06-27 15:19:46 -0700673 "msg=%d config_error=%d",
674 fail->msg, fail->config_error);
675 }
676 wpas_p2p_wps_failed(wpa_s, fail);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700677 }
678#endif /* CONFIG_P2P */
679}
680
681
682static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800683 int authorized, const u8 *p2p_dev_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700684{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800685 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700686}
687
688
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700689#ifdef CONFIG_P2P
690static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
691 const u8 *psk, size_t psk_len)
692{
693
694 struct wpa_supplicant *wpa_s = ctx;
695 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
696 return;
697 wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
698}
699#endif /* CONFIG_P2P */
700
701
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700702static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
703{
704#ifdef CONFIG_P2P
705 struct wpa_supplicant *wpa_s = ctx;
706 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700707
708 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700709 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700710 return -1;
711 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
712 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700713 buf + IEEE80211_HDRLEN + 1,
714 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700715#endif /* CONFIG_P2P */
716 return 0;
717}
718
719
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800720static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700721 const u8 *bssid, const u8 *ie, size_t ie_len,
722 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700723{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700724 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700725 unsigned int freq = 0;
726
727 if (wpa_s->ap_iface)
728 freq = wpa_s->ap_iface->freq;
729
Dmitry Shmidt04949592012-07-19 12:16:46 -0700730 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700731 freq, ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700732}
733
734
735static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
736 const u8 *uuid_e)
737{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700738 struct wpa_supplicant *wpa_s = ctx;
739 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700740}
741
742
743static void wpas_ap_configured_cb(void *ctx)
744{
745 struct wpa_supplicant *wpa_s = ctx;
746
Roshan Pius3a1667e2018-07-03 15:17:14 -0700747 wpa_printf(MSG_DEBUG, "AP interface setup completed - state %s",
748 hostapd_state_text(wpa_s->ap_iface->state));
749 if (wpa_s->ap_iface->state == HAPD_IFACE_DISABLED) {
750 wpa_supplicant_ap_deinit(wpa_s);
751 return;
752 }
753
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800754#ifdef CONFIG_ACS
Roshan Pius3a1667e2018-07-03 15:17:14 -0700755 if (wpa_s->current_ssid && wpa_s->current_ssid->acs) {
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800756 wpa_s->assoc_freq = wpa_s->ap_iface->freq;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700757 wpa_s->current_ssid->frequency = wpa_s->ap_iface->freq;
758 }
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800759#endif /* CONFIG_ACS */
760
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700761 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
762
763 if (wpa_s->ap_configured_cb)
764 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
765 wpa_s->ap_configured_cb_data);
766}
767
768
769int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
770 struct wpa_ssid *ssid)
771{
772 struct wpa_driver_associate_params params;
773 struct hostapd_iface *hapd_iface;
774 struct hostapd_config *conf;
775 size_t i;
776
777 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
778 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
779 return -1;
780 }
781
782 wpa_supplicant_ap_deinit(wpa_s);
783
784 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
785 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
786
787 os_memset(&params, 0, sizeof(params));
788 params.ssid = ssid->ssid;
789 params.ssid_len = ssid->ssid_len;
790 switch (ssid->mode) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700791 case WPAS_MODE_AP:
792 case WPAS_MODE_P2P_GO:
793 case WPAS_MODE_P2P_GROUP_FORMATION:
794 params.mode = IEEE80211_MODE_AP;
795 break;
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800796 default:
797 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700798 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700799 if (ssid->frequency == 0)
800 ssid->frequency = 2462; /* default channel 11 */
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700801 params.freq.freq = ssid->frequency;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700802
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800803 if ((ssid->mode == WPAS_MODE_AP || ssid->mode == WPAS_MODE_P2P_GO) &&
804 ssid->enable_edmg) {
Hai Shalomc3565922019-10-28 11:58:20 -0700805 u8 primary_channel;
806
807 if (ieee80211_freq_to_chan(ssid->frequency, &primary_channel) ==
808 NUM_HOSTAPD_MODES) {
809 wpa_printf(MSG_WARNING,
810 "EDMG: Failed to get the primary channel");
811 return -1;
812 }
813
814 hostapd_encode_edmg_chan(ssid->enable_edmg, ssid->edmg_channel,
815 primary_channel, &params.freq.edmg);
816 }
817
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800818 params.wpa_proto = ssid->proto;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700819 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
820 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
821 else
822 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800823 params.key_mgmt_suite = wpa_s->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700824
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800825 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
826 1);
827 if (wpa_s->pairwise_cipher < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700828 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
829 "cipher.");
830 return -1;
831 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800832 params.pairwise_suite = wpa_s->pairwise_cipher;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700833 params.group_suite = params.pairwise_suite;
834
835#ifdef CONFIG_P2P
836 if (ssid->mode == WPAS_MODE_P2P_GO ||
837 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
838 params.p2p = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700839#endif /* CONFIG_P2P */
840
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800841 if (wpa_s->p2pdev->set_ap_uapsd)
842 params.uapsd = wpa_s->p2pdev->ap_uapsd;
Dmitry Shmidtec58b162014-02-19 12:44:18 -0800843 else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
844 params.uapsd = 1; /* mandatory for P2P GO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700845 else
846 params.uapsd = -1;
847
Roshan Pius3a1667e2018-07-03 15:17:14 -0700848 if (ieee80211_is_dfs(params.freq.freq, wpa_s->hw.modes,
849 wpa_s->hw.num_modes))
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800850 params.freq.freq = 0; /* set channel after CAC */
851
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700852 if (params.p2p)
853 wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_GO);
854 else
855 wpa_drv_get_ext_capa(wpa_s, WPA_IF_AP_BSS);
856
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700857 if (wpa_drv_associate(wpa_s, &params) < 0) {
858 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
859 return -1;
860 }
861
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700862 wpa_s->ap_iface = hapd_iface = hostapd_alloc_iface();
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700863 if (hapd_iface == NULL)
864 return -1;
865 hapd_iface->owner = wpa_s;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800866 hapd_iface->drv_flags = wpa_s->drv_flags;
867 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700868 hapd_iface->extended_capa = wpa_s->extended_capa;
869 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
870 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700871
872 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
873 if (conf == NULL) {
874 wpa_supplicant_ap_deinit(wpa_s);
875 return -1;
876 }
877
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700878 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
879 wpa_s->conf->wmm_ac_params,
880 sizeof(wpa_s->conf->wmm_ac_params));
881
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800882 if (params.uapsd > 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800883 conf->bss[0]->wmm_enabled = 1;
884 conf->bss[0]->wmm_uapsd = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800885 }
886
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700887 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
888 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
889 wpa_supplicant_ap_deinit(wpa_s);
890 return -1;
891 }
892
893#ifdef CONFIG_P2P
894 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800895 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700896 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800897 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700898 P2P_GROUP_FORMATION;
899#endif /* CONFIG_P2P */
900
901 hapd_iface->num_bss = conf->num_bss;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700902 hapd_iface->bss = os_calloc(conf->num_bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700903 sizeof(struct hostapd_data *));
904 if (hapd_iface->bss == NULL) {
905 wpa_supplicant_ap_deinit(wpa_s);
906 return -1;
907 }
908
909 for (i = 0; i < conf->num_bss; i++) {
910 hapd_iface->bss[i] =
911 hostapd_alloc_bss_data(hapd_iface, conf,
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800912 conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700913 if (hapd_iface->bss[i] == NULL) {
914 wpa_supplicant_ap_deinit(wpa_s);
915 return -1;
916 }
917
918 hapd_iface->bss[i]->msg_ctx = wpa_s;
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800919 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->p2pdev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700920 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
921 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
922 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
923 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
924 hostapd_register_probereq_cb(hapd_iface->bss[i],
925 ap_probe_req_rx, wpa_s);
926 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
927 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
928 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
929 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
930 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
931 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
932#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700933 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
934 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700935 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700936 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
937 ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700938#endif /* CONFIG_P2P */
939 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
940 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800941#ifdef CONFIG_TESTING_OPTIONS
942 hapd_iface->bss[i]->ext_eapol_frame_io =
943 wpa_s->ext_eapol_frame_io;
944#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700945 }
946
947 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
948 hapd_iface->bss[0]->driver = wpa_s->driver;
949 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
950
951 wpa_s->current_ssid = ssid;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700952 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700953 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
954 wpa_s->assoc_freq = ssid->frequency;
Hai Shalomc3565922019-10-28 11:58:20 -0700955 wpa_s->ap_iface->conf->enable_edmg = ssid->enable_edmg;
956 wpa_s->ap_iface->conf->edmg_channel = ssid->edmg_channel;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700957
Roshan Pius3a1667e2018-07-03 15:17:14 -0700958#if defined(CONFIG_P2P) && defined(CONFIG_ACS)
959 if (wpa_s->p2p_go_do_acs) {
960 wpa_s->ap_iface->conf->channel = 0;
961 wpa_s->ap_iface->conf->hw_mode = wpa_s->p2p_go_acs_band;
962 ssid->acs = 1;
963 }
964#endif /* CONFIG_P2P && CONFIG_ACS */
965
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700966 if (hostapd_setup_interface(wpa_s->ap_iface)) {
967 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
968 wpa_supplicant_ap_deinit(wpa_s);
969 return -1;
970 }
971
972 return 0;
973}
974
975
976void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
977{
978#ifdef CONFIG_WPS
979 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
980#endif /* CONFIG_WPS */
981
982 if (wpa_s->ap_iface == NULL)
983 return;
984
985 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700986 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700987 wpa_s->assoc_freq = 0;
Dmitry Shmidt43cb5782014-06-16 16:23:22 -0700988 wpas_p2p_ap_deinit(wpa_s);
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800989 wpa_s->ap_iface->driver_ap_teardown =
990 !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
991
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700992 hostapd_interface_deinit(wpa_s->ap_iface);
993 hostapd_interface_free(wpa_s->ap_iface);
994 wpa_s->ap_iface = NULL;
995 wpa_drv_deinit_ap(wpa_s);
Dmitry Shmidtf73259c2015-03-17 11:00:54 -0700996 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
997 " reason=%d locally_generated=1",
998 MAC2STR(wpa_s->own_addr), WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700999}
1000
1001
1002void ap_tx_status(void *ctx, const u8 *addr,
1003 const u8 *buf, size_t len, int ack)
1004{
1005#ifdef NEED_AP_MLME
1006 struct wpa_supplicant *wpa_s = ctx;
1007 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
1008#endif /* NEED_AP_MLME */
1009}
1010
1011
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001012void ap_eapol_tx_status(void *ctx, const u8 *dst,
1013 const u8 *data, size_t len, int ack)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001014{
1015#ifdef NEED_AP_MLME
1016 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001017 if (!wpa_s->ap_iface)
1018 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001019 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
1020#endif /* NEED_AP_MLME */
1021}
1022
1023
1024void ap_client_poll_ok(void *ctx, const u8 *addr)
1025{
1026#ifdef NEED_AP_MLME
1027 struct wpa_supplicant *wpa_s = ctx;
1028 if (wpa_s->ap_iface)
1029 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
1030#endif /* NEED_AP_MLME */
1031}
1032
1033
1034void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
1035{
1036#ifdef NEED_AP_MLME
1037 struct wpa_supplicant *wpa_s = ctx;
1038 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001039#endif /* NEED_AP_MLME */
1040}
1041
1042
1043void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
1044{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001045#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001046 struct wpa_supplicant *wpa_s = ctx;
1047 struct hostapd_frame_info fi;
1048 os_memset(&fi, 0, sizeof(fi));
1049 fi.datarate = rx_mgmt->datarate;
1050 fi.ssi_signal = rx_mgmt->ssi_signal;
1051 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
1052 rx_mgmt->frame_len, &fi);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001053#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001054}
1055
1056
1057void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
1058{
1059#ifdef NEED_AP_MLME
1060 struct wpa_supplicant *wpa_s = ctx;
1061 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
1062#endif /* NEED_AP_MLME */
1063}
1064
1065
1066void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
1067 const u8 *src_addr, const u8 *buf, size_t len)
1068{
1069 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
1070}
1071
1072
1073#ifdef CONFIG_WPS
1074
1075int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
1076 const u8 *p2p_dev_addr)
1077{
1078 if (!wpa_s->ap_iface)
1079 return -1;
1080 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
1081 p2p_dev_addr);
1082}
1083
1084
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001085int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
1086{
1087 struct wps_registrar *reg;
1088 int reg_sel = 0, wps_sta = 0;
1089
1090 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
1091 return -1;
1092
1093 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
1094 reg_sel = wps_registrar_wps_cancel(reg);
1095 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
Dmitry Shmidt04949592012-07-19 12:16:46 -07001096 ap_sta_wps_cancel, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001097
1098 if (!reg_sel && !wps_sta) {
1099 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
1100 "time");
1101 return -1;
1102 }
1103
1104 /*
1105 * There are 2 cases to return wps cancel as success:
1106 * 1. When wps cancel was initiated but no connection has been
1107 * established with client yet.
1108 * 2. Client is in the middle of exchanging WPS messages.
1109 */
1110
1111 return 0;
1112}
1113
1114
1115int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001116 const char *pin, char *buf, size_t buflen,
1117 int timeout)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001118{
1119 int ret, ret_len = 0;
1120
1121 if (!wpa_s->ap_iface)
1122 return -1;
1123
1124 if (pin == NULL) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001125 unsigned int rpin;
1126
1127 if (wps_generate_pin(&rpin) < 0)
1128 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001129 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001130 if (os_snprintf_error(buflen, ret_len))
1131 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001132 pin = buf;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001133 } else if (buf) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001134 ret_len = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001135 if (os_snprintf_error(buflen, ret_len))
1136 return -1;
1137 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001138
1139 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001140 timeout);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001141 if (ret)
1142 return -1;
1143 return ret_len;
1144}
1145
1146
1147static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
1148{
1149 struct wpa_supplicant *wpa_s = eloop_data;
1150 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
1151 wpas_wps_ap_pin_disable(wpa_s);
1152}
1153
1154
1155static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
1156{
1157 struct hostapd_data *hapd;
1158
1159 if (wpa_s->ap_iface == NULL)
1160 return;
1161 hapd = wpa_s->ap_iface->bss[0];
1162 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
1163 hapd->ap_pin_failures = 0;
1164 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1165 if (timeout > 0)
1166 eloop_register_timeout(timeout, 0,
1167 wpas_wps_ap_pin_timeout, wpa_s, NULL);
1168}
1169
1170
1171void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
1172{
1173 struct hostapd_data *hapd;
1174
1175 if (wpa_s->ap_iface == NULL)
1176 return;
1177 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
1178 hapd = wpa_s->ap_iface->bss[0];
1179 os_free(hapd->conf->ap_pin);
1180 hapd->conf->ap_pin = NULL;
1181 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1182}
1183
1184
1185const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
1186{
1187 struct hostapd_data *hapd;
1188 unsigned int pin;
1189 char pin_txt[9];
1190
1191 if (wpa_s->ap_iface == NULL)
1192 return NULL;
1193 hapd = wpa_s->ap_iface->bss[0];
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001194 if (wps_generate_pin(&pin) < 0)
1195 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001196 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001197 os_free(hapd->conf->ap_pin);
1198 hapd->conf->ap_pin = os_strdup(pin_txt);
1199 if (hapd->conf->ap_pin == NULL)
1200 return NULL;
1201 wpas_wps_ap_pin_enable(wpa_s, timeout);
1202
1203 return hapd->conf->ap_pin;
1204}
1205
1206
1207const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
1208{
1209 struct hostapd_data *hapd;
1210 if (wpa_s->ap_iface == NULL)
1211 return NULL;
1212 hapd = wpa_s->ap_iface->bss[0];
1213 return hapd->conf->ap_pin;
1214}
1215
1216
1217int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
1218 int timeout)
1219{
1220 struct hostapd_data *hapd;
1221 char pin_txt[9];
1222 int ret;
1223
1224 if (wpa_s->ap_iface == NULL)
1225 return -1;
1226 hapd = wpa_s->ap_iface->bss[0];
1227 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001228 if (os_snprintf_error(sizeof(pin_txt), ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001229 return -1;
1230 os_free(hapd->conf->ap_pin);
1231 hapd->conf->ap_pin = os_strdup(pin_txt);
1232 if (hapd->conf->ap_pin == NULL)
1233 return -1;
1234 wpas_wps_ap_pin_enable(wpa_s, timeout);
1235
1236 return 0;
1237}
1238
1239
1240void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
1241{
1242 struct hostapd_data *hapd;
1243
1244 if (wpa_s->ap_iface == NULL)
1245 return;
1246 hapd = wpa_s->ap_iface->bss[0];
1247
1248 /*
1249 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
1250 * PIN if this happens multiple times to slow down brute force attacks.
1251 */
1252 hapd->ap_pin_failures++;
1253 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
1254 hapd->ap_pin_failures);
1255 if (hapd->ap_pin_failures < 3)
1256 return;
1257
1258 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
1259 hapd->ap_pin_failures = 0;
1260 os_free(hapd->conf->ap_pin);
1261 hapd->conf->ap_pin = NULL;
1262}
1263
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001264
1265#ifdef CONFIG_WPS_NFC
1266
1267struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
1268 int ndef)
1269{
1270 struct hostapd_data *hapd;
1271
1272 if (wpa_s->ap_iface == NULL)
1273 return NULL;
1274 hapd = wpa_s->ap_iface->bss[0];
1275 return hostapd_wps_nfc_config_token(hapd, ndef);
1276}
1277
1278
1279struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
1280 int ndef)
1281{
1282 struct hostapd_data *hapd;
1283
1284 if (wpa_s->ap_iface == NULL)
1285 return NULL;
1286 hapd = wpa_s->ap_iface->bss[0];
1287 return hostapd_wps_nfc_hs_cr(hapd, ndef);
1288}
1289
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001290
1291int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
1292 const struct wpabuf *req,
1293 const struct wpabuf *sel)
1294{
1295 struct hostapd_data *hapd;
1296
1297 if (wpa_s->ap_iface == NULL)
1298 return -1;
1299 hapd = wpa_s->ap_iface->bss[0];
1300 return hostapd_wps_nfc_report_handover(hapd, req, sel);
1301}
1302
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001303#endif /* CONFIG_WPS_NFC */
1304
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001305#endif /* CONFIG_WPS */
1306
1307
1308#ifdef CONFIG_CTRL_IFACE
1309
1310int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
1311 char *buf, size_t buflen)
1312{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001313 struct hostapd_data *hapd;
1314
1315 if (wpa_s->ap_iface)
1316 hapd = wpa_s->ap_iface->bss[0];
1317 else if (wpa_s->ifmsh)
1318 hapd = wpa_s->ifmsh->bss[0];
1319 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001320 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001321 return hostapd_ctrl_iface_sta_first(hapd, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001322}
1323
1324
1325int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
1326 char *buf, size_t buflen)
1327{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001328 struct hostapd_data *hapd;
1329
1330 if (wpa_s->ap_iface)
1331 hapd = wpa_s->ap_iface->bss[0];
1332 else if (wpa_s->ifmsh)
1333 hapd = wpa_s->ifmsh->bss[0];
1334 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001335 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001336 return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001337}
1338
1339
1340int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
1341 char *buf, size_t buflen)
1342{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001343 struct hostapd_data *hapd;
1344
1345 if (wpa_s->ap_iface)
1346 hapd = wpa_s->ap_iface->bss[0];
1347 else if (wpa_s->ifmsh)
1348 hapd = wpa_s->ifmsh->bss[0];
1349 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001350 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001351 return hostapd_ctrl_iface_sta_next(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001352}
1353
1354
Dmitry Shmidt04949592012-07-19 12:16:46 -07001355int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1356 const char *txtaddr)
1357{
1358 if (wpa_s->ap_iface == NULL)
1359 return -1;
1360 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1361 txtaddr);
1362}
1363
1364
1365int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1366 const char *txtaddr)
1367{
1368 if (wpa_s->ap_iface == NULL)
1369 return -1;
1370 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1371 txtaddr);
1372}
1373
1374
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001375int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1376 size_t buflen, int verbose)
1377{
1378 char *pos = buf, *end = buf + buflen;
1379 int ret;
1380 struct hostapd_bss_config *conf;
1381
1382 if (wpa_s->ap_iface == NULL)
1383 return -1;
1384
1385 conf = wpa_s->ap_iface->bss[0]->conf;
1386 if (conf->wpa == 0)
1387 return 0;
1388
1389 ret = os_snprintf(pos, end - pos,
1390 "pairwise_cipher=%s\n"
1391 "group_cipher=%s\n"
1392 "key_mgmt=%s\n",
1393 wpa_cipher_txt(conf->rsn_pairwise),
1394 wpa_cipher_txt(conf->wpa_group),
1395 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1396 conf->wpa));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001397 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001398 return pos - buf;
1399 pos += ret;
1400 return pos - buf;
1401}
1402
1403#endif /* CONFIG_CTRL_IFACE */
1404
1405
1406int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1407{
1408 struct hostapd_iface *iface = wpa_s->ap_iface;
1409 struct wpa_ssid *ssid = wpa_s->current_ssid;
1410 struct hostapd_data *hapd;
1411
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001412 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1413 ssid->mode == WPAS_MODE_INFRA ||
1414 ssid->mode == WPAS_MODE_IBSS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001415 return -1;
1416
1417#ifdef CONFIG_P2P
1418 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001419 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001420 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001421 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001422 P2P_GROUP_FORMATION;
1423#endif /* CONFIG_P2P */
1424
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001425 hapd = iface->bss[0];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001426 if (hapd->drv_priv == NULL)
1427 return -1;
1428 ieee802_11_set_beacons(iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001429 hostapd_set_ap_wps_ie(hapd);
1430
1431 return 0;
1432}
1433
1434
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001435int ap_switch_channel(struct wpa_supplicant *wpa_s,
1436 struct csa_settings *settings)
1437{
1438#ifdef NEED_AP_MLME
1439 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1440 return -1;
1441
1442 return hostapd_switch_channel(wpa_s->ap_iface->bss[0], settings);
1443#else /* NEED_AP_MLME */
1444 return -1;
1445#endif /* NEED_AP_MLME */
1446}
1447
1448
Dmitry Shmidt83474442015-04-15 13:47:09 -07001449#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001450int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1451{
1452 struct csa_settings settings;
1453 int ret = hostapd_parse_csa_settings(pos, &settings);
1454
1455 if (ret)
1456 return ret;
1457
1458 return ap_switch_channel(wpa_s, &settings);
1459}
Dmitry Shmidt83474442015-04-15 13:47:09 -07001460#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001461
1462
Dmitry Shmidt04949592012-07-19 12:16:46 -07001463void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
Hai Shalom81f62d82019-07-22 12:10:00 -07001464 int offset, int width, int cf1, int cf2, int finished)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001465{
Hai Shalom74f70d42019-02-11 14:42:39 -08001466 struct hostapd_iface *iface = wpa_s->ap_iface;
Hai Shalombf6e0ba2019-02-11 12:01:50 -08001467
Hai Shalom74f70d42019-02-11 14:42:39 -08001468 if (!iface)
1469 iface = wpa_s->ifmsh;
1470 if (!iface)
1471 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001472 wpa_s->assoc_freq = freq;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001473 if (wpa_s->current_ssid)
1474 wpa_s->current_ssid->frequency = freq;
Hai Shalom74f70d42019-02-11 14:42:39 -08001475 hostapd_event_ch_switch(iface->bss[0], freq, ht,
Hai Shalom81f62d82019-07-22 12:10:00 -07001476 offset, width, cf1, cf2, finished);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001477}
1478
1479
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001480int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1481 const u8 *addr)
1482{
1483 struct hostapd_data *hapd;
1484 struct hostapd_bss_config *conf;
1485
1486 if (!wpa_s->ap_iface)
1487 return -1;
1488
1489 if (addr)
1490 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1491 MAC2STR(addr));
1492 else
1493 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1494
1495 hapd = wpa_s->ap_iface->bss[0];
1496 conf = hapd->conf;
1497
1498 os_free(conf->accept_mac);
1499 conf->accept_mac = NULL;
1500 conf->num_accept_mac = 0;
1501 os_free(conf->deny_mac);
1502 conf->deny_mac = NULL;
1503 conf->num_deny_mac = 0;
1504
1505 if (addr == NULL) {
1506 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1507 return 0;
1508 }
1509
1510 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1511 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1512 if (conf->accept_mac == NULL)
1513 return -1;
1514 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1515 conf->num_accept_mac = 1;
1516
1517 return 0;
1518}
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001519
1520
1521#ifdef CONFIG_WPS_NFC
1522int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1523 const struct wpabuf *pw, const u8 *pubkey_hash)
1524{
1525 struct hostapd_data *hapd;
1526 struct wps_context *wps;
1527
1528 if (!wpa_s->ap_iface)
1529 return -1;
1530 hapd = wpa_s->ap_iface->bss[0];
1531 wps = hapd->wps;
1532
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001533 if (wpa_s->p2pdev->conf->wps_nfc_dh_pubkey == NULL ||
1534 wpa_s->p2pdev->conf->wps_nfc_dh_privkey == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001535 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1536 return -1;
1537 }
1538
1539 dh5_free(wps->dh_ctx);
1540 wpabuf_free(wps->dh_pubkey);
1541 wpabuf_free(wps->dh_privkey);
1542 wps->dh_privkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001543 wpa_s->p2pdev->conf->wps_nfc_dh_privkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001544 wps->dh_pubkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001545 wpa_s->p2pdev->conf->wps_nfc_dh_pubkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001546 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1547 wps->dh_ctx = NULL;
1548 wpabuf_free(wps->dh_pubkey);
1549 wps->dh_pubkey = NULL;
1550 wpabuf_free(wps->dh_privkey);
1551 wps->dh_privkey = NULL;
1552 return -1;
1553 }
1554 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1555 if (wps->dh_ctx == NULL)
1556 return -1;
1557
1558 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1559 pw_id,
1560 pw ? wpabuf_head(pw) : NULL,
1561 pw ? wpabuf_len(pw) : 0, 1);
1562}
1563#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001564
1565
Dmitry Shmidt83474442015-04-15 13:47:09 -07001566#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001567int wpas_ap_stop_ap(struct wpa_supplicant *wpa_s)
1568{
1569 struct hostapd_data *hapd;
1570
1571 if (!wpa_s->ap_iface)
1572 return -1;
1573 hapd = wpa_s->ap_iface->bss[0];
1574 return hostapd_ctrl_iface_stop_ap(hapd);
1575}
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001576
1577
Dmitry Shmidte4663042016-04-04 10:07:49 -07001578int wpas_ap_pmksa_cache_list(struct wpa_supplicant *wpa_s, char *buf,
1579 size_t len)
1580{
1581 size_t reply_len = 0, i;
1582 char ap_delimiter[] = "---- AP ----\n";
1583 char mesh_delimiter[] = "---- mesh ----\n";
1584 size_t dlen;
1585
1586 if (wpa_s->ap_iface) {
1587 dlen = os_strlen(ap_delimiter);
1588 if (dlen > len - reply_len)
1589 return reply_len;
1590 os_memcpy(&buf[reply_len], ap_delimiter, dlen);
1591 reply_len += dlen;
1592
1593 for (i = 0; i < wpa_s->ap_iface->num_bss; i++) {
1594 reply_len += hostapd_ctrl_iface_pmksa_list(
1595 wpa_s->ap_iface->bss[i],
1596 &buf[reply_len], len - reply_len);
1597 }
1598 }
1599
1600 if (wpa_s->ifmsh) {
1601 dlen = os_strlen(mesh_delimiter);
1602 if (dlen > len - reply_len)
1603 return reply_len;
1604 os_memcpy(&buf[reply_len], mesh_delimiter, dlen);
1605 reply_len += dlen;
1606
1607 reply_len += hostapd_ctrl_iface_pmksa_list(
1608 wpa_s->ifmsh->bss[0], &buf[reply_len],
1609 len - reply_len);
1610 }
1611
1612 return reply_len;
1613}
1614
1615
1616void wpas_ap_pmksa_cache_flush(struct wpa_supplicant *wpa_s)
1617{
1618 size_t i;
1619
1620 if (wpa_s->ap_iface) {
1621 for (i = 0; i < wpa_s->ap_iface->num_bss; i++)
1622 hostapd_ctrl_iface_pmksa_flush(wpa_s->ap_iface->bss[i]);
1623 }
1624
1625 if (wpa_s->ifmsh)
1626 hostapd_ctrl_iface_pmksa_flush(wpa_s->ifmsh->bss[0]);
1627}
Paul Stewart092955c2017-02-06 09:13:09 -08001628
1629
1630#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
1631#ifdef CONFIG_MESH
1632
1633int wpas_ap_pmksa_cache_list_mesh(struct wpa_supplicant *wpa_s, const u8 *addr,
1634 char *buf, size_t len)
1635{
1636 return hostapd_ctrl_iface_pmksa_list_mesh(wpa_s->ifmsh->bss[0], addr,
1637 &buf[0], len);
1638}
1639
1640
1641int wpas_ap_pmksa_cache_add_external(struct wpa_supplicant *wpa_s, char *cmd)
1642{
1643 struct external_pmksa_cache *entry;
1644 void *pmksa_cache;
1645
1646 pmksa_cache = hostapd_ctrl_iface_pmksa_create_entry(wpa_s->own_addr,
1647 cmd);
1648 if (!pmksa_cache)
1649 return -1;
1650
1651 entry = os_zalloc(sizeof(struct external_pmksa_cache));
1652 if (!entry)
1653 return -1;
1654
1655 entry->pmksa_cache = pmksa_cache;
1656
1657 dl_list_add(&wpa_s->mesh_external_pmksa_cache, &entry->list);
1658
1659 return 0;
1660}
1661
1662#endif /* CONFIG_MESH */
1663#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
1664
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001665#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte4663042016-04-04 10:07:49 -07001666
1667
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001668#ifdef NEED_AP_MLME
Roshan Pius3a1667e2018-07-03 15:17:14 -07001669void wpas_ap_event_dfs_radar_detected(struct wpa_supplicant *wpa_s,
1670 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001671{
Hai Shalom74f70d42019-02-11 14:42:39 -08001672 struct hostapd_iface *iface = wpa_s->ap_iface;
1673
1674 if (!iface)
1675 iface = wpa_s->ifmsh;
1676 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001677 return;
1678 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001679 hostapd_dfs_radar_detected(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001680 radar->ht_enabled, radar->chan_offset,
1681 radar->chan_width,
1682 radar->cf1, radar->cf2);
1683}
1684
1685
Roshan Pius3a1667e2018-07-03 15:17:14 -07001686void wpas_ap_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
1687 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001688{
Hai Shalom74f70d42019-02-11 14:42:39 -08001689 struct hostapd_iface *iface = wpa_s->ap_iface;
1690
1691 if (!iface)
1692 iface = wpa_s->ifmsh;
1693 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001694 return;
1695 wpa_printf(MSG_DEBUG, "DFS CAC started on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001696 hostapd_dfs_start_cac(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001697 radar->ht_enabled, radar->chan_offset,
1698 radar->chan_width, radar->cf1, radar->cf2);
1699}
1700
1701
Roshan Pius3a1667e2018-07-03 15:17:14 -07001702void wpas_ap_event_dfs_cac_finished(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 CAC finished on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001712 hostapd_dfs_complete_cac(iface, 1, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001713 radar->ht_enabled, radar->chan_offset,
1714 radar->chan_width, radar->cf1, radar->cf2);
1715}
1716
1717
Roshan Pius3a1667e2018-07-03 15:17:14 -07001718void wpas_ap_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
1719 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001720{
Hai Shalom74f70d42019-02-11 14:42:39 -08001721 struct hostapd_iface *iface = wpa_s->ap_iface;
1722
1723 if (!iface)
1724 iface = wpa_s->ifmsh;
1725 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001726 return;
1727 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001728 hostapd_dfs_complete_cac(iface, 0, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001729 radar->ht_enabled, radar->chan_offset,
1730 radar->chan_width, radar->cf1, radar->cf2);
1731}
1732
1733
Roshan Pius3a1667e2018-07-03 15:17:14 -07001734void wpas_ap_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s,
1735 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001736{
Hai Shalom74f70d42019-02-11 14:42:39 -08001737 struct hostapd_iface *iface = wpa_s->ap_iface;
1738
1739 if (!iface)
1740 iface = wpa_s->ifmsh;
1741 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001742 return;
1743 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001744 hostapd_dfs_nop_finished(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001745 radar->ht_enabled, radar->chan_offset,
1746 radar->chan_width, radar->cf1, radar->cf2);
1747}
1748#endif /* NEED_AP_MLME */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001749
1750
1751void ap_periodic(struct wpa_supplicant *wpa_s)
1752{
1753 if (wpa_s->ap_iface)
1754 hostapd_periodic_iface(wpa_s->ap_iface);
1755}