blob: ac88a7dc9571ec819f1c8e45e0a110a6794ddba8 [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 */
Hai Shalom899fcc72020-10-19 14:38:18 -070077 u8 freq_seg_idx;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070078
79 if (!conf->secondary_channel)
80 goto no_vht;
81
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070082 /* Use the maximum oper channel width if it's given. */
83 if (ssid->max_oper_chwidth)
Hai Shalom899fcc72020-10-19 14:38:18 -070084 hostapd_set_oper_chwidth(conf, ssid->max_oper_chwidth);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070085
Hai Shalom899fcc72020-10-19 14:38:18 -070086 if (hostapd_get_oper_chwidth(conf) == CHANWIDTH_80P80MHZ) {
87 ieee80211_freq_to_chan(ssid->vht_center_freq2,
88 &freq_seg_idx);
89 hostapd_set_oper_centr_freq_seg1_idx(conf, freq_seg_idx);
90 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070091
92 if (!ssid->p2p_group) {
Hai Shalom899fcc72020-10-19 14:38:18 -070093 if (!ssid->vht_center_freq1)
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070094 goto no_vht;
95 ieee80211_freq_to_chan(ssid->vht_center_freq1,
Hai Shalom899fcc72020-10-19 14:38:18 -070096 &freq_seg_idx);
97 hostapd_set_oper_centr_freq_seg0_idx(conf, freq_seg_idx);
98
99 wpa_printf(MSG_DEBUG,
100 "VHT seg0 index %d and seg1 index %d for AP",
101 hostapd_get_oper_centr_freq_seg0_idx(conf),
102 hostapd_get_oper_centr_freq_seg1_idx(conf));
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700103 return;
104 }
105
106#ifdef CONFIG_P2P
Hai Shalom899fcc72020-10-19 14:38:18 -0700107 switch (hostapd_get_oper_chwidth(conf)) {
Hai Shalom81f62d82019-07-22 12:10:00 -0700108 case CHANWIDTH_80MHZ:
109 case CHANWIDTH_80P80MHZ:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800110 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700111 wpa_printf(MSG_DEBUG,
112 "VHT center channel %u for 80 or 80+80 MHz bandwidth",
113 center_chan);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800114 break;
Hai Shalom81f62d82019-07-22 12:10:00 -0700115 case CHANWIDTH_160MHZ:
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800116 center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700117 wpa_printf(MSG_DEBUG,
118 "VHT center channel %u for 160 MHz bandwidth",
119 center_chan);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800120 break;
121 default:
122 /*
123 * conf->vht_oper_chwidth might not be set for non-P2P GO cases,
124 * try oper_cwidth 160 MHz first then VHT 80 MHz, if 160 MHz is
125 * not supported.
126 */
Hai Shalom899fcc72020-10-19 14:38:18 -0700127 hostapd_set_oper_chwidth(conf, CHANWIDTH_160MHZ);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800128 center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel);
Hsis-Chang Chen44b08ec2020-11-18 16:21:29 +0530129 if (center_chan && is_chanwidth160_supported(mode, conf)) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700130 wpa_printf(MSG_DEBUG,
131 "VHT center channel %u for auto-selected 160 MHz bandwidth",
132 center_chan);
133 } else {
Hai Shalom899fcc72020-10-19 14:38:18 -0700134 hostapd_set_oper_chwidth(conf, CHANWIDTH_80MHZ);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800135 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode,
136 channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700137 wpa_printf(MSG_DEBUG,
138 "VHT center channel %u for auto-selected 80 MHz bandwidth",
139 center_chan);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800140 }
141 break;
142 }
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700143 if (!center_chan)
144 goto no_vht;
145
Hai Shalom899fcc72020-10-19 14:38:18 -0700146 hostapd_set_oper_centr_freq_seg0_idx(conf, center_chan);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700147 wpa_printf(MSG_DEBUG, "VHT seg0 index %d for P2P GO",
Hai Shalom899fcc72020-10-19 14:38:18 -0700148 hostapd_get_oper_centr_freq_seg0_idx(conf));
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700149 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700150#endif /* CONFIG_P2P */
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700151
152no_vht:
Roshan Pius3a1667e2018-07-03 15:17:14 -0700153 wpa_printf(MSG_DEBUG,
154 "No VHT higher bandwidth support for the selected channel %d",
155 conf->channel);
Hai Shalom899fcc72020-10-19 14:38:18 -0700156 hostapd_set_oper_centr_freq_seg0_idx(
157 conf, conf->channel + conf->secondary_channel * 2);
158 hostapd_set_oper_chwidth(conf, CHANWIDTH_USE_HT);
159}
160
161
162static struct hostapd_hw_modes *
163wpa_supplicant_find_hw_mode(struct wpa_supplicant *wpa_s,
164 enum hostapd_hw_mode hw_mode)
165{
166 struct hostapd_hw_modes *mode = NULL;
167 int i;
168
169 for (i = 0; i < wpa_s->hw.num_modes; i++) {
170 if (wpa_s->hw.modes[i].mode == hw_mode) {
171 mode = &wpa_s->hw.modes[i];
172 break;
173 }
174 }
175
176 return mode;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700177}
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700178
179
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800180int wpa_supplicant_conf_ap_ht(struct wpa_supplicant *wpa_s,
181 struct wpa_ssid *ssid,
182 struct hostapd_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700183{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800184 conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency,
185 &conf->channel);
186
187 if (conf->hw_mode == NUM_HOSTAPD_MODES) {
188 wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
189 ssid->frequency);
190 return -1;
191 }
192
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700193 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800194 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
195 * and a mask of allowed capabilities within conf->ht_capab.
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700196 * Using default config settings for: conf->ht_op_mode_fixed,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800197 * conf->secondary_channel, conf->require_ht
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700198 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800199 if (wpa_s->hw.modes) {
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700200 struct hostapd_hw_modes *mode = NULL;
Hai Shalom899fcc72020-10-19 14:38:18 -0700201 int no_ht = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700202
203 wpa_printf(MSG_DEBUG,
204 "Determining HT/VHT options based on driver capabilities (freq=%u chan=%u)",
205 ssid->frequency, conf->channel);
206
Hai Shalom899fcc72020-10-19 14:38:18 -0700207 mode = wpa_supplicant_find_hw_mode(wpa_s, conf->hw_mode);
208
209 /* May drop to IEEE 802.11b if the driver does not support IEEE
210 * 802.11g */
211 if (!mode && conf->hw_mode == HOSTAPD_MODE_IEEE80211G) {
212 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
213 wpa_printf(MSG_INFO,
214 "Try downgrade to IEEE 802.11b as 802.11g is not supported by the current hardware");
215 mode = wpa_supplicant_find_hw_mode(wpa_s,
216 conf->hw_mode);
217 }
218
219 if (!mode) {
220 wpa_printf(MSG_ERROR,
221 "No match between requested and supported hw modes found");
222 return -1;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700223 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700224
225#ifdef CONFIG_HT_OVERRIDES
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700226 if (ssid->disable_ht)
227 ssid->ht = 0;
228#endif /* CONFIG_HT_OVERRIDES */
229
230 if (!ssid->ht) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700231 wpa_printf(MSG_DEBUG,
232 "HT not enabled in network profile");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700233 conf->ieee80211n = 0;
234 conf->ht_capab = 0;
235 no_ht = 1;
236 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700237
238 if (!no_ht && mode && mode->ht_capab) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700239 wpa_printf(MSG_DEBUG,
240 "Enable HT support (p2p_group=%d 11a=%d ht40_hw_capab=%d ssid->ht40=%d)",
241 ssid->p2p_group,
242 conf->hw_mode == HOSTAPD_MODE_IEEE80211A,
243 !!(mode->ht_capab &
244 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET),
245 ssid->ht40);
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700246 conf->ieee80211n = 1;
Hai Shalom899fcc72020-10-19 14:38:18 -0700247
248 if (ssid->ht40 &&
249 (mode->ht_capab &
250 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
251 conf->secondary_channel = ssid->ht40;
252 else
253 conf->secondary_channel = 0;
254
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700255#ifdef CONFIG_P2P
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700256 if (ssid->p2p_group &&
257 conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700258 (mode->ht_capab &
259 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -0700260 ssid->ht40) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700261 conf->secondary_channel =
262 wpas_p2p_get_ht40_mode(wpa_s, mode,
263 conf->channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700264 wpa_printf(MSG_DEBUG,
265 "HT secondary channel offset %d for P2P group",
266 conf->secondary_channel);
267 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700268#endif /* CONFIG_P2P */
269
270 if (!ssid->p2p_group &&
271 (mode->ht_capab &
Roshan Pius3a1667e2018-07-03 15:17:14 -0700272 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700273 conf->secondary_channel = ssid->ht40;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700274 wpa_printf(MSG_DEBUG,
275 "HT secondary channel offset %d for AP",
276 conf->secondary_channel);
277 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700278
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700279 if (conf->secondary_channel)
280 conf->ht_capab |=
281 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800282
283 /*
284 * white-list capabilities that won't cause issues
285 * to connecting stations, while leaving the current
286 * capabilities intact (currently disabled SMPS).
287 */
288 conf->ht_capab |= mode->ht_capab &
289 (HT_CAP_INFO_GREEN_FIELD |
290 HT_CAP_INFO_SHORT_GI20MHZ |
291 HT_CAP_INFO_SHORT_GI40MHZ |
292 HT_CAP_INFO_RX_STBC_MASK |
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800293 HT_CAP_INFO_TX_STBC |
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800294 HT_CAP_INFO_MAX_AMSDU_SIZE);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700295
Hai Shalom899fcc72020-10-19 14:38:18 -0700296 /* check this before VHT, because setting oper chan
297 * width and friends is the same call for HE and VHT
298 * and checks if conf->ieee8021ax == 1 */
299 if (mode->he_capab[wpas_mode_to_ieee80211_mode(
300 ssid->mode)].he_supported &&
301 ssid->he)
302 conf->ieee80211ax = 1;
303
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700304 if (mode->vht_capab && ssid->vht) {
305 conf->ieee80211ac = 1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800306 conf->vht_capab |= mode->vht_capab;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700307 wpas_conf_ap_vht(wpa_s, ssid, conf, mode);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700308 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800309 }
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700310 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800311
312 if (conf->secondary_channel) {
313 struct wpa_supplicant *iface;
314
315 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
316 {
317 if (iface == wpa_s ||
318 iface->wpa_state < WPA_AUTHENTICATING ||
319 (int) iface->assoc_freq != ssid->frequency)
320 continue;
321
322 /*
323 * Do not allow 40 MHz co-ex PRI/SEC switch to force us
324 * to change our PRI channel since we have an existing,
325 * concurrent connection on that channel and doing
326 * multi-channel concurrency is likely to cause more
327 * harm than using different PRI/SEC selection in
328 * environment with multiple BSSes on these two channels
329 * with mixed 20 MHz or PRI channel selection.
330 */
331 conf->no_pri_sec_switch = 1;
332 }
333 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800334
335 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800336}
337
338
339static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
340 struct wpa_ssid *ssid,
341 struct hostapd_config *conf)
342{
343 struct hostapd_bss_config *bss = conf->bss[0];
344
345 conf->driver = wpa_s->driver;
346
347 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
348
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800349 if (wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800350 return -1;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700351
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700352 if (ssid->pbss > 1) {
353 wpa_printf(MSG_ERROR, "Invalid pbss value(%d) for AP mode",
354 ssid->pbss);
355 return -1;
356 }
357 bss->pbss = ssid->pbss;
358
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800359#ifdef CONFIG_ACS
360 if (ssid->acs) {
361 /* Setting channel to 0 in order to enable ACS */
362 conf->channel = 0;
363 wpa_printf(MSG_DEBUG, "Use automatic channel selection");
364 }
365#endif /* CONFIG_ACS */
366
Roshan Pius3a1667e2018-07-03 15:17:14 -0700367 if (ieee80211_is_dfs(ssid->frequency, wpa_s->hw.modes,
368 wpa_s->hw.num_modes) && wpa_s->conf->country[0]) {
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800369 conf->ieee80211h = 1;
370 conf->ieee80211d = 1;
371 conf->country[0] = wpa_s->conf->country[0];
372 conf->country[1] = wpa_s->conf->country[1];
Paul Stewart092955c2017-02-06 09:13:09 -0800373 conf->country[2] = ' ';
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800374 }
375
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700376#ifdef CONFIG_P2P
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700377 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
378 (ssid->mode == WPAS_MODE_P2P_GO ||
379 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700380 /* Remove 802.11b rates from supported and basic rate sets */
381 int *list = os_malloc(4 * sizeof(int));
382 if (list) {
383 list[0] = 60;
384 list[1] = 120;
385 list[2] = 240;
386 list[3] = -1;
387 }
388 conf->basic_rates = list;
389
390 list = os_malloc(9 * sizeof(int));
391 if (list) {
392 list[0] = 60;
393 list[1] = 90;
394 list[2] = 120;
395 list[3] = 180;
396 list[4] = 240;
397 list[5] = 360;
398 list[6] = 480;
399 list[7] = 540;
400 list[8] = -1;
401 }
402 conf->supported_rates = list;
Hai Shalom021b0b52019-04-10 11:17:58 -0700403 }
404
Hai Shalom74f70d42019-02-11 14:42:39 -0800405#ifdef CONFIG_IEEE80211AX
Hai Shalom021b0b52019-04-10 11:17:58 -0700406 if (ssid->mode == WPAS_MODE_P2P_GO ||
407 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Hai Shalom74f70d42019-02-11 14:42:39 -0800408 conf->ieee80211ax = ssid->he;
409#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800410
411 bss->isolate = !wpa_s->conf->p2p_intra_bss;
Hai Shalomfdcde762020-04-02 11:19:20 -0700412 bss->extended_key_id = wpa_s->conf->extended_key_id;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700413 bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
Hai Shalomfdcde762020-04-02 11:19:20 -0700414 bss->wpa_deny_ptk0_rekey = ssid->wpa_deny_ptk0_rekey;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800415
416 if (ssid->p2p_group) {
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800417 os_memcpy(bss->ip_addr_go, wpa_s->p2pdev->conf->ip_addr_go, 4);
418 os_memcpy(bss->ip_addr_mask, wpa_s->p2pdev->conf->ip_addr_mask,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800419 4);
420 os_memcpy(bss->ip_addr_start,
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800421 wpa_s->p2pdev->conf->ip_addr_start, 4);
422 os_memcpy(bss->ip_addr_end, wpa_s->p2pdev->conf->ip_addr_end,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800423 4);
424 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700425#endif /* CONFIG_P2P */
426
427 if (ssid->ssid_len == 0) {
428 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
429 return -1;
430 }
431 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700432 bss->ssid.ssid_len = ssid->ssid_len;
433 bss->ssid.ssid_set = 1;
434
Dmitry Shmidt04949592012-07-19 12:16:46 -0700435 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
436
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800437 if (ssid->auth_alg)
438 bss->auth_algs = ssid->auth_alg;
439
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700440 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
441 bss->wpa = ssid->proto;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700442 if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
443 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
444 else
445 bss->wpa_key_mgmt = ssid->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700446 bss->wpa_pairwise = ssid->pairwise_cipher;
Hai Shalomc3565922019-10-28 11:58:20 -0700447 if (wpa_key_mgmt_sae(bss->wpa_key_mgmt) && ssid->passphrase) {
448 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
449 } else if (ssid->psk_set) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800450 bin_clear_free(bss->ssid.wpa_psk, sizeof(*bss->ssid.wpa_psk));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700451 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
452 if (bss->ssid.wpa_psk == NULL)
453 return -1;
454 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
455 bss->ssid.wpa_psk->group = 1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700456 bss->ssid.wpa_psk_set = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800457 } else if (ssid->passphrase) {
458 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
Hai Shalomfdcde762020-04-02 11:19:20 -0700459#ifdef CONFIG_WEP
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800460 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
461 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
462 struct hostapd_wep_keys *wep = &bss->ssid.wep;
463 int i;
464 for (i = 0; i < NUM_WEP_KEYS; i++) {
465 if (ssid->wep_key_len[i] == 0)
466 continue;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700467 wep->key[i] = os_memdup(ssid->wep_key[i],
468 ssid->wep_key_len[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800469 if (wep->key[i] == NULL)
470 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800471 wep->len[i] = ssid->wep_key_len[i];
472 }
473 wep->idx = ssid->wep_tx_keyidx;
474 wep->keys_set = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700475#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700476 }
Hai Shalomc3565922019-10-28 11:58:20 -0700477#ifdef CONFIG_SAE
478 if (ssid->sae_password) {
479 struct sae_password_entry *pw;
480
481 pw = os_zalloc(sizeof(*pw));
482 if (!pw)
483 return -1;
484 os_memset(pw->peer_addr, 0xff, ETH_ALEN);
485 pw->password = os_strdup(ssid->sae_password);
486 if (!pw->password) {
487 os_free(pw);
488 return -1;
489 }
490 if (ssid->sae_password_id) {
491 pw->identifier = os_strdup(ssid->sae_password_id);
492 if (!pw->identifier) {
493 str_clear_free(pw->password);
494 os_free(pw);
495 return -1;
496 }
497 }
498
499 pw->next = bss->sae_passwords;
500 bss->sae_passwords = pw;
501 }
502
503 bss->sae_pwe = wpa_s->conf->sae_pwe;
504#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700505
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700506 if (wpa_s->conf->go_interworking) {
507 wpa_printf(MSG_DEBUG,
508 "P2P: Enable Interworking with access_network_type: %d",
509 wpa_s->conf->go_access_network_type);
510 bss->interworking = wpa_s->conf->go_interworking;
511 bss->access_network_type = wpa_s->conf->go_access_network_type;
512 bss->internet = wpa_s->conf->go_internet;
513 if (wpa_s->conf->go_venue_group) {
514 wpa_printf(MSG_DEBUG,
515 "P2P: Venue group: %d Venue type: %d",
516 wpa_s->conf->go_venue_group,
517 wpa_s->conf->go_venue_type);
518 bss->venue_group = wpa_s->conf->go_venue_group;
519 bss->venue_type = wpa_s->conf->go_venue_type;
520 bss->venue_info_set = 1;
521 }
522 }
523
Dmitry Shmidt04949592012-07-19 12:16:46 -0700524 if (ssid->ap_max_inactivity)
525 bss->ap_max_inactivity = ssid->ap_max_inactivity;
526
527 if (ssid->dtim_period)
528 bss->dtim_period = ssid->dtim_period;
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -0800529 else if (wpa_s->conf->dtim_period)
530 bss->dtim_period = wpa_s->conf->dtim_period;
531
532 if (ssid->beacon_int)
533 conf->beacon_int = ssid->beacon_int;
534 else if (wpa_s->conf->beacon_int)
535 conf->beacon_int = wpa_s->conf->beacon_int;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700536
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800537#ifdef CONFIG_P2P
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800538 if (ssid->mode == WPAS_MODE_P2P_GO ||
539 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
540 if (wpa_s->conf->p2p_go_ctwindow > conf->beacon_int) {
541 wpa_printf(MSG_INFO,
542 "CTWindow (%d) is bigger than beacon interval (%d) - avoid configuring it",
543 wpa_s->conf->p2p_go_ctwindow,
544 conf->beacon_int);
545 conf->p2p_go_ctwindow = 0;
546 } else {
547 conf->p2p_go_ctwindow = wpa_s->conf->p2p_go_ctwindow;
548 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800549 }
550#endif /* CONFIG_P2P */
551
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800552 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
553 bss->rsn_pairwise = bss->wpa_pairwise;
554 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
555 bss->rsn_pairwise);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700556
Hai Shalomfdcde762020-04-02 11:19:20 -0700557 if (bss->wpa && bss->ieee802_1x) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700558 bss->ssid.security_policy = SECURITY_WPA;
Hai Shalomfdcde762020-04-02 11:19:20 -0700559 } else if (bss->wpa) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700560 bss->ssid.security_policy = SECURITY_WPA_PSK;
Hai Shalomfdcde762020-04-02 11:19:20 -0700561#ifdef CONFIG_WEP
562 } else if (bss->ieee802_1x) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800563 int cipher = WPA_CIPHER_NONE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700564 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
565 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800566 if (bss->default_wep_key_len)
567 cipher = bss->default_wep_key_len >= 13 ?
568 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
569 bss->wpa_group = cipher;
570 bss->wpa_pairwise = cipher;
571 bss->rsn_pairwise = cipher;
572 } else if (bss->ssid.wep.keys_set) {
573 int cipher = WPA_CIPHER_WEP40;
574 if (bss->ssid.wep.len[0] >= 13)
575 cipher = WPA_CIPHER_WEP104;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700576 bss->ssid.security_policy = SECURITY_STATIC_WEP;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800577 bss->wpa_group = cipher;
578 bss->wpa_pairwise = cipher;
579 bss->rsn_pairwise = cipher;
Hai Shalomfdcde762020-04-02 11:19:20 -0700580#endif /* CONFIG_WEP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800581 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700582 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800583 bss->wpa_group = WPA_CIPHER_NONE;
584 bss->wpa_pairwise = WPA_CIPHER_NONE;
585 bss->rsn_pairwise = WPA_CIPHER_NONE;
586 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700587
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700588 if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
589 (bss->wpa_group == WPA_CIPHER_CCMP ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800590 bss->wpa_group == WPA_CIPHER_GCMP ||
591 bss->wpa_group == WPA_CIPHER_CCMP_256 ||
592 bss->wpa_group == WPA_CIPHER_GCMP_256)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700593 /*
594 * Strong ciphers do not need frequent rekeying, so increase
595 * the default GTK rekeying period to 24 hours.
596 */
597 bss->wpa_group_rekey = 86400;
598 }
599
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700600 if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT)
601 bss->ieee80211w = ssid->ieee80211w;
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700602
Hai Shalom74f70d42019-02-11 14:42:39 -0800603#ifdef CONFIG_OCV
604 bss->ocv = ssid->ocv;
605#endif /* CONFIG_OCV */
606
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700607#ifdef CONFIG_WPS
608 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800609 * Enable WPS by default for open and WPA/WPA2-Personal network, but
610 * require user interaction to actually use it. Only the internal
611 * Registrar is supported.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700612 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800613 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
614 bss->ssid.security_policy != SECURITY_PLAINTEXT)
615 goto no_wps;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800616 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800617 (!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ||
618 !(bss->wpa & 2)))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800619 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
620 * configuration */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700621 if (ssid->wps_disabled)
622 goto no_wps;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700623 bss->eap_server = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700624
625 if (!ssid->ignore_broadcast_ssid)
626 bss->wps_state = 2;
627
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700628 bss->ap_setup_locked = 2;
629 if (wpa_s->conf->config_methods)
630 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
631 os_memcpy(bss->device_type, wpa_s->conf->device_type,
632 WPS_DEV_TYPE_LEN);
633 if (wpa_s->conf->device_name) {
634 bss->device_name = os_strdup(wpa_s->conf->device_name);
635 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
636 }
637 if (wpa_s->conf->manufacturer)
638 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
639 if (wpa_s->conf->model_name)
640 bss->model_name = os_strdup(wpa_s->conf->model_name);
641 if (wpa_s->conf->model_number)
642 bss->model_number = os_strdup(wpa_s->conf->model_number);
643 if (wpa_s->conf->serial_number)
644 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
645 if (is_nil_uuid(wpa_s->conf->uuid))
646 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
647 else
648 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
649 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700650 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -0700651 if (ssid->eap.fragment_size != DEFAULT_FRAGMENT_SIZE)
652 bss->fragment_size = ssid->eap.fragment_size;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800653no_wps:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700654#endif /* CONFIG_WPS */
655
656 if (wpa_s->max_stations &&
657 wpa_s->max_stations < wpa_s->conf->max_num_sta)
658 bss->max_num_sta = wpa_s->max_stations;
659 else
660 bss->max_num_sta = wpa_s->conf->max_num_sta;
661
Roshan Pius3a1667e2018-07-03 15:17:14 -0700662 if (!bss->isolate)
663 bss->isolate = wpa_s->conf->ap_isolate;
664
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700665 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
666
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700667 if (wpa_s->conf->ap_vendor_elements) {
668 bss->vendor_elements =
669 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
670 }
671
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700672 bss->ftm_responder = wpa_s->conf->ftm_responder;
673 bss->ftm_initiator = wpa_s->conf->ftm_initiator;
674
Hai Shalomfdcde762020-04-02 11:19:20 -0700675 bss->transition_disable = ssid->transition_disable;
676
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700677 return 0;
678}
679
680
681static void ap_public_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;
Dmitry Shmidt18463232014-01-24 12:29:41 -0800690 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
691 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700692 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
693 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700694 buf + IEEE80211_HDRLEN + 1,
695 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700696#endif /* CONFIG_P2P */
697}
698
699
700static void ap_wps_event_cb(void *ctx, enum wps_event event,
701 union wps_event_data *data)
702{
703#ifdef CONFIG_P2P
704 struct wpa_supplicant *wpa_s = ctx;
705
Jouni Malinen75ecf522011-06-27 15:19:46 -0700706 if (event == WPS_EV_FAIL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700707 struct wps_event_fail *fail = &data->fail;
708
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800709 if (wpa_s->p2pdev && wpa_s->p2pdev != wpa_s &&
Jouni Malinen75ecf522011-06-27 15:19:46 -0700710 wpa_s == wpa_s->global->p2p_group_formation) {
711 /*
712 * src/ap/wps_hostapd.c has already sent this on the
713 * main interface, so only send on the parent interface
714 * here if needed.
715 */
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800716 wpa_msg(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_FAIL
Jouni Malinen75ecf522011-06-27 15:19:46 -0700717 "msg=%d config_error=%d",
718 fail->msg, fail->config_error);
719 }
720 wpas_p2p_wps_failed(wpa_s, fail);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700721 }
722#endif /* CONFIG_P2P */
723}
724
725
726static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800727 int authorized, const u8 *p2p_dev_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700728{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800729 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700730}
731
732
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700733#ifdef CONFIG_P2P
734static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
735 const u8 *psk, size_t psk_len)
736{
737
738 struct wpa_supplicant *wpa_s = ctx;
739 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
740 return;
741 wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
742}
743#endif /* CONFIG_P2P */
744
745
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700746static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
747{
748#ifdef CONFIG_P2P
749 struct wpa_supplicant *wpa_s = ctx;
750 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700751
752 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700753 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700754 return -1;
755 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
756 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700757 buf + IEEE80211_HDRLEN + 1,
758 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700759#endif /* CONFIG_P2P */
760 return 0;
761}
762
763
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800764static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700765 const u8 *bssid, const u8 *ie, size_t ie_len,
766 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700767{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700768 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700769 unsigned int freq = 0;
770
771 if (wpa_s->ap_iface)
772 freq = wpa_s->ap_iface->freq;
773
Dmitry Shmidt04949592012-07-19 12:16:46 -0700774 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700775 freq, ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700776}
777
778
779static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
780 const u8 *uuid_e)
781{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700782 struct wpa_supplicant *wpa_s = ctx;
783 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700784}
785
786
787static void wpas_ap_configured_cb(void *ctx)
788{
789 struct wpa_supplicant *wpa_s = ctx;
790
Roshan Pius3a1667e2018-07-03 15:17:14 -0700791 wpa_printf(MSG_DEBUG, "AP interface setup completed - state %s",
792 hostapd_state_text(wpa_s->ap_iface->state));
793 if (wpa_s->ap_iface->state == HAPD_IFACE_DISABLED) {
794 wpa_supplicant_ap_deinit(wpa_s);
795 return;
796 }
797
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800798#ifdef CONFIG_ACS
Roshan Pius3a1667e2018-07-03 15:17:14 -0700799 if (wpa_s->current_ssid && wpa_s->current_ssid->acs) {
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800800 wpa_s->assoc_freq = wpa_s->ap_iface->freq;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700801 wpa_s->current_ssid->frequency = wpa_s->ap_iface->freq;
802 }
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800803#endif /* CONFIG_ACS */
804
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700805 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
806
807 if (wpa_s->ap_configured_cb)
808 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
809 wpa_s->ap_configured_cb_data);
810}
811
812
813int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
814 struct wpa_ssid *ssid)
815{
816 struct wpa_driver_associate_params params;
817 struct hostapd_iface *hapd_iface;
818 struct hostapd_config *conf;
819 size_t i;
820
821 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
822 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
823 return -1;
824 }
825
826 wpa_supplicant_ap_deinit(wpa_s);
827
828 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
829 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
830
831 os_memset(&params, 0, sizeof(params));
832 params.ssid = ssid->ssid;
833 params.ssid_len = ssid->ssid_len;
834 switch (ssid->mode) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700835 case WPAS_MODE_AP:
836 case WPAS_MODE_P2P_GO:
837 case WPAS_MODE_P2P_GROUP_FORMATION:
838 params.mode = IEEE80211_MODE_AP;
839 break;
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800840 default:
841 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700842 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700843 if (ssid->frequency == 0)
844 ssid->frequency = 2462; /* default channel 11 */
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700845 params.freq.freq = ssid->frequency;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700846
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800847 if ((ssid->mode == WPAS_MODE_AP || ssid->mode == WPAS_MODE_P2P_GO) &&
848 ssid->enable_edmg) {
Hai Shalomc3565922019-10-28 11:58:20 -0700849 u8 primary_channel;
850
851 if (ieee80211_freq_to_chan(ssid->frequency, &primary_channel) ==
852 NUM_HOSTAPD_MODES) {
853 wpa_printf(MSG_WARNING,
854 "EDMG: Failed to get the primary channel");
855 return -1;
856 }
857
858 hostapd_encode_edmg_chan(ssid->enable_edmg, ssid->edmg_channel,
859 primary_channel, &params.freq.edmg);
860 }
861
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800862 params.wpa_proto = ssid->proto;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700863 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
864 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
865 else
866 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800867 params.key_mgmt_suite = wpa_s->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700868
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800869 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
870 1);
871 if (wpa_s->pairwise_cipher < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700872 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
873 "cipher.");
874 return -1;
875 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800876 params.pairwise_suite = wpa_s->pairwise_cipher;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700877 params.group_suite = params.pairwise_suite;
878
879#ifdef CONFIG_P2P
880 if (ssid->mode == WPAS_MODE_P2P_GO ||
881 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
882 params.p2p = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700883#endif /* CONFIG_P2P */
884
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800885 if (wpa_s->p2pdev->set_ap_uapsd)
886 params.uapsd = wpa_s->p2pdev->ap_uapsd;
Dmitry Shmidtec58b162014-02-19 12:44:18 -0800887 else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
888 params.uapsd = 1; /* mandatory for P2P GO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700889 else
890 params.uapsd = -1;
891
Roshan Pius3a1667e2018-07-03 15:17:14 -0700892 if (ieee80211_is_dfs(params.freq.freq, wpa_s->hw.modes,
893 wpa_s->hw.num_modes))
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800894 params.freq.freq = 0; /* set channel after CAC */
895
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700896 if (params.p2p)
897 wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_GO);
898 else
899 wpa_drv_get_ext_capa(wpa_s, WPA_IF_AP_BSS);
900
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700901 if (wpa_drv_associate(wpa_s, &params) < 0) {
902 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
903 return -1;
904 }
905
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700906 wpa_s->ap_iface = hapd_iface = hostapd_alloc_iface();
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700907 if (hapd_iface == NULL)
908 return -1;
909 hapd_iface->owner = wpa_s;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800910 hapd_iface->drv_flags = wpa_s->drv_flags;
911 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700912 hapd_iface->extended_capa = wpa_s->extended_capa;
913 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
914 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700915
916 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
917 if (conf == NULL) {
918 wpa_supplicant_ap_deinit(wpa_s);
919 return -1;
920 }
921
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700922 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
923 wpa_s->conf->wmm_ac_params,
924 sizeof(wpa_s->conf->wmm_ac_params));
925
Hai Shalom899fcc72020-10-19 14:38:18 -0700926 os_memcpy(wpa_s->ap_iface->conf->tx_queue, wpa_s->conf->tx_queue,
927 sizeof(wpa_s->conf->tx_queue));
928
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800929 if (params.uapsd > 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800930 conf->bss[0]->wmm_enabled = 1;
931 conf->bss[0]->wmm_uapsd = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800932 }
933
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700934 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
935 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
936 wpa_supplicant_ap_deinit(wpa_s);
937 return -1;
938 }
939
940#ifdef CONFIG_P2P
941 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800942 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700943 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800944 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700945 P2P_GROUP_FORMATION;
946#endif /* CONFIG_P2P */
947
948 hapd_iface->num_bss = conf->num_bss;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700949 hapd_iface->bss = os_calloc(conf->num_bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700950 sizeof(struct hostapd_data *));
951 if (hapd_iface->bss == NULL) {
952 wpa_supplicant_ap_deinit(wpa_s);
953 return -1;
954 }
955
956 for (i = 0; i < conf->num_bss; i++) {
957 hapd_iface->bss[i] =
958 hostapd_alloc_bss_data(hapd_iface, conf,
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800959 conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700960 if (hapd_iface->bss[i] == NULL) {
961 wpa_supplicant_ap_deinit(wpa_s);
962 return -1;
963 }
964
965 hapd_iface->bss[i]->msg_ctx = wpa_s;
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800966 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->p2pdev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700967 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
968 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
969 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
970 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
971 hostapd_register_probereq_cb(hapd_iface->bss[i],
972 ap_probe_req_rx, wpa_s);
973 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
974 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
975 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
976 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
977 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
978 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
979#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700980 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
981 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700982 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700983 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
984 ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700985#endif /* CONFIG_P2P */
986 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
987 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800988#ifdef CONFIG_TESTING_OPTIONS
989 hapd_iface->bss[i]->ext_eapol_frame_io =
990 wpa_s->ext_eapol_frame_io;
991#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700992 }
993
994 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
995 hapd_iface->bss[0]->driver = wpa_s->driver;
996 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
997
998 wpa_s->current_ssid = ssid;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700999 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001000 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
1001 wpa_s->assoc_freq = ssid->frequency;
Hai Shalomc3565922019-10-28 11:58:20 -07001002 wpa_s->ap_iface->conf->enable_edmg = ssid->enable_edmg;
1003 wpa_s->ap_iface->conf->edmg_channel = ssid->edmg_channel;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001004
Roshan Pius3a1667e2018-07-03 15:17:14 -07001005#if defined(CONFIG_P2P) && defined(CONFIG_ACS)
1006 if (wpa_s->p2p_go_do_acs) {
1007 wpa_s->ap_iface->conf->channel = 0;
1008 wpa_s->ap_iface->conf->hw_mode = wpa_s->p2p_go_acs_band;
1009 ssid->acs = 1;
1010 }
1011#endif /* CONFIG_P2P && CONFIG_ACS */
1012
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001013 if (hostapd_setup_interface(wpa_s->ap_iface)) {
1014 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
1015 wpa_supplicant_ap_deinit(wpa_s);
1016 return -1;
1017 }
1018
1019 return 0;
1020}
1021
1022
1023void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
1024{
1025#ifdef CONFIG_WPS
1026 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1027#endif /* CONFIG_WPS */
1028
1029 if (wpa_s->ap_iface == NULL)
1030 return;
1031
1032 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001033 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001034 wpa_s->assoc_freq = 0;
Dmitry Shmidt43cb5782014-06-16 16:23:22 -07001035 wpas_p2p_ap_deinit(wpa_s);
Dmitry Shmidta38abf92014-03-06 13:38:44 -08001036 wpa_s->ap_iface->driver_ap_teardown =
1037 !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
1038
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001039 hostapd_interface_deinit(wpa_s->ap_iface);
1040 hostapd_interface_free(wpa_s->ap_iface);
1041 wpa_s->ap_iface = NULL;
1042 wpa_drv_deinit_ap(wpa_s);
Dmitry Shmidtf73259c2015-03-17 11:00:54 -07001043 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
1044 " reason=%d locally_generated=1",
1045 MAC2STR(wpa_s->own_addr), WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001046}
1047
1048
1049void ap_tx_status(void *ctx, const u8 *addr,
1050 const u8 *buf, size_t len, int ack)
1051{
1052#ifdef NEED_AP_MLME
1053 struct wpa_supplicant *wpa_s = ctx;
1054 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
1055#endif /* NEED_AP_MLME */
1056}
1057
1058
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001059void ap_eapol_tx_status(void *ctx, const u8 *dst,
1060 const u8 *data, size_t len, int ack)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001061{
1062#ifdef NEED_AP_MLME
1063 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001064 if (!wpa_s->ap_iface)
1065 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001066 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
1067#endif /* NEED_AP_MLME */
1068}
1069
1070
1071void ap_client_poll_ok(void *ctx, const u8 *addr)
1072{
1073#ifdef NEED_AP_MLME
1074 struct wpa_supplicant *wpa_s = ctx;
1075 if (wpa_s->ap_iface)
1076 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
1077#endif /* NEED_AP_MLME */
1078}
1079
1080
1081void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
1082{
1083#ifdef NEED_AP_MLME
1084 struct wpa_supplicant *wpa_s = ctx;
1085 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001086#endif /* NEED_AP_MLME */
1087}
1088
1089
1090void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
1091{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001092#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001093 struct wpa_supplicant *wpa_s = ctx;
1094 struct hostapd_frame_info fi;
1095 os_memset(&fi, 0, sizeof(fi));
1096 fi.datarate = rx_mgmt->datarate;
1097 fi.ssi_signal = rx_mgmt->ssi_signal;
1098 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
1099 rx_mgmt->frame_len, &fi);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001100#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001101}
1102
1103
1104void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
1105{
1106#ifdef NEED_AP_MLME
1107 struct wpa_supplicant *wpa_s = ctx;
1108 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
1109#endif /* NEED_AP_MLME */
1110}
1111
1112
1113void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
1114 const u8 *src_addr, const u8 *buf, size_t len)
1115{
1116 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
1117}
1118
1119
1120#ifdef CONFIG_WPS
1121
1122int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
1123 const u8 *p2p_dev_addr)
1124{
1125 if (!wpa_s->ap_iface)
1126 return -1;
1127 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
1128 p2p_dev_addr);
1129}
1130
1131
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001132int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
1133{
1134 struct wps_registrar *reg;
1135 int reg_sel = 0, wps_sta = 0;
1136
1137 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
1138 return -1;
1139
1140 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
1141 reg_sel = wps_registrar_wps_cancel(reg);
1142 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
Dmitry Shmidt04949592012-07-19 12:16:46 -07001143 ap_sta_wps_cancel, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001144
1145 if (!reg_sel && !wps_sta) {
1146 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
1147 "time");
1148 return -1;
1149 }
1150
1151 /*
1152 * There are 2 cases to return wps cancel as success:
1153 * 1. When wps cancel was initiated but no connection has been
1154 * established with client yet.
1155 * 2. Client is in the middle of exchanging WPS messages.
1156 */
1157
1158 return 0;
1159}
1160
1161
1162int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001163 const char *pin, char *buf, size_t buflen,
1164 int timeout)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001165{
1166 int ret, ret_len = 0;
1167
1168 if (!wpa_s->ap_iface)
1169 return -1;
1170
1171 if (pin == NULL) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001172 unsigned int rpin;
1173
1174 if (wps_generate_pin(&rpin) < 0)
1175 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001176 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001177 if (os_snprintf_error(buflen, ret_len))
1178 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001179 pin = buf;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001180 } else if (buf) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001181 ret_len = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001182 if (os_snprintf_error(buflen, ret_len))
1183 return -1;
1184 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001185
1186 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001187 timeout);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001188 if (ret)
1189 return -1;
1190 return ret_len;
1191}
1192
1193
1194static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
1195{
1196 struct wpa_supplicant *wpa_s = eloop_data;
1197 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
1198 wpas_wps_ap_pin_disable(wpa_s);
1199}
1200
1201
1202static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
1203{
1204 struct hostapd_data *hapd;
1205
1206 if (wpa_s->ap_iface == NULL)
1207 return;
1208 hapd = wpa_s->ap_iface->bss[0];
1209 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
1210 hapd->ap_pin_failures = 0;
1211 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1212 if (timeout > 0)
1213 eloop_register_timeout(timeout, 0,
1214 wpas_wps_ap_pin_timeout, wpa_s, NULL);
1215}
1216
1217
1218void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
1219{
1220 struct hostapd_data *hapd;
1221
1222 if (wpa_s->ap_iface == NULL)
1223 return;
1224 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
1225 hapd = wpa_s->ap_iface->bss[0];
1226 os_free(hapd->conf->ap_pin);
1227 hapd->conf->ap_pin = NULL;
1228 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1229}
1230
1231
1232const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
1233{
1234 struct hostapd_data *hapd;
1235 unsigned int pin;
1236 char pin_txt[9];
1237
1238 if (wpa_s->ap_iface == NULL)
1239 return NULL;
1240 hapd = wpa_s->ap_iface->bss[0];
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001241 if (wps_generate_pin(&pin) < 0)
1242 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001243 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001244 os_free(hapd->conf->ap_pin);
1245 hapd->conf->ap_pin = os_strdup(pin_txt);
1246 if (hapd->conf->ap_pin == NULL)
1247 return NULL;
1248 wpas_wps_ap_pin_enable(wpa_s, timeout);
1249
1250 return hapd->conf->ap_pin;
1251}
1252
1253
1254const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
1255{
1256 struct hostapd_data *hapd;
1257 if (wpa_s->ap_iface == NULL)
1258 return NULL;
1259 hapd = wpa_s->ap_iface->bss[0];
1260 return hapd->conf->ap_pin;
1261}
1262
1263
1264int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
1265 int timeout)
1266{
1267 struct hostapd_data *hapd;
1268 char pin_txt[9];
1269 int ret;
1270
1271 if (wpa_s->ap_iface == NULL)
1272 return -1;
1273 hapd = wpa_s->ap_iface->bss[0];
1274 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001275 if (os_snprintf_error(sizeof(pin_txt), ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001276 return -1;
1277 os_free(hapd->conf->ap_pin);
1278 hapd->conf->ap_pin = os_strdup(pin_txt);
1279 if (hapd->conf->ap_pin == NULL)
1280 return -1;
1281 wpas_wps_ap_pin_enable(wpa_s, timeout);
1282
1283 return 0;
1284}
1285
1286
1287void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
1288{
1289 struct hostapd_data *hapd;
1290
1291 if (wpa_s->ap_iface == NULL)
1292 return;
1293 hapd = wpa_s->ap_iface->bss[0];
1294
1295 /*
1296 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
1297 * PIN if this happens multiple times to slow down brute force attacks.
1298 */
1299 hapd->ap_pin_failures++;
1300 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
1301 hapd->ap_pin_failures);
1302 if (hapd->ap_pin_failures < 3)
1303 return;
1304
1305 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
1306 hapd->ap_pin_failures = 0;
1307 os_free(hapd->conf->ap_pin);
1308 hapd->conf->ap_pin = NULL;
1309}
1310
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001311
1312#ifdef CONFIG_WPS_NFC
1313
1314struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
1315 int ndef)
1316{
1317 struct hostapd_data *hapd;
1318
1319 if (wpa_s->ap_iface == NULL)
1320 return NULL;
1321 hapd = wpa_s->ap_iface->bss[0];
1322 return hostapd_wps_nfc_config_token(hapd, ndef);
1323}
1324
1325
1326struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
1327 int ndef)
1328{
1329 struct hostapd_data *hapd;
1330
1331 if (wpa_s->ap_iface == NULL)
1332 return NULL;
1333 hapd = wpa_s->ap_iface->bss[0];
1334 return hostapd_wps_nfc_hs_cr(hapd, ndef);
1335}
1336
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001337
1338int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
1339 const struct wpabuf *req,
1340 const struct wpabuf *sel)
1341{
1342 struct hostapd_data *hapd;
1343
1344 if (wpa_s->ap_iface == NULL)
1345 return -1;
1346 hapd = wpa_s->ap_iface->bss[0];
1347 return hostapd_wps_nfc_report_handover(hapd, req, sel);
1348}
1349
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001350#endif /* CONFIG_WPS_NFC */
1351
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001352#endif /* CONFIG_WPS */
1353
1354
1355#ifdef CONFIG_CTRL_IFACE
1356
1357int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
1358 char *buf, size_t buflen)
1359{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001360 struct hostapd_data *hapd;
1361
1362 if (wpa_s->ap_iface)
1363 hapd = wpa_s->ap_iface->bss[0];
1364 else if (wpa_s->ifmsh)
1365 hapd = wpa_s->ifmsh->bss[0];
1366 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001367 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001368 return hostapd_ctrl_iface_sta_first(hapd, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001369}
1370
1371
1372int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
1373 char *buf, size_t buflen)
1374{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001375 struct hostapd_data *hapd;
1376
1377 if (wpa_s->ap_iface)
1378 hapd = wpa_s->ap_iface->bss[0];
1379 else if (wpa_s->ifmsh)
1380 hapd = wpa_s->ifmsh->bss[0];
1381 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001382 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001383 return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001384}
1385
1386
1387int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
1388 char *buf, size_t buflen)
1389{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001390 struct hostapd_data *hapd;
1391
1392 if (wpa_s->ap_iface)
1393 hapd = wpa_s->ap_iface->bss[0];
1394 else if (wpa_s->ifmsh)
1395 hapd = wpa_s->ifmsh->bss[0];
1396 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001397 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001398 return hostapd_ctrl_iface_sta_next(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001399}
1400
1401
Dmitry Shmidt04949592012-07-19 12:16:46 -07001402int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1403 const char *txtaddr)
1404{
1405 if (wpa_s->ap_iface == NULL)
1406 return -1;
1407 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1408 txtaddr);
1409}
1410
1411
1412int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1413 const char *txtaddr)
1414{
1415 if (wpa_s->ap_iface == NULL)
1416 return -1;
1417 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1418 txtaddr);
1419}
1420
1421
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001422int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1423 size_t buflen, int verbose)
1424{
1425 char *pos = buf, *end = buf + buflen;
1426 int ret;
1427 struct hostapd_bss_config *conf;
1428
1429 if (wpa_s->ap_iface == NULL)
1430 return -1;
1431
1432 conf = wpa_s->ap_iface->bss[0]->conf;
1433 if (conf->wpa == 0)
1434 return 0;
1435
1436 ret = os_snprintf(pos, end - pos,
1437 "pairwise_cipher=%s\n"
1438 "group_cipher=%s\n"
1439 "key_mgmt=%s\n",
1440 wpa_cipher_txt(conf->rsn_pairwise),
1441 wpa_cipher_txt(conf->wpa_group),
1442 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1443 conf->wpa));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001444 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001445 return pos - buf;
1446 pos += ret;
1447 return pos - buf;
1448}
1449
1450#endif /* CONFIG_CTRL_IFACE */
1451
1452
1453int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1454{
1455 struct hostapd_iface *iface = wpa_s->ap_iface;
1456 struct wpa_ssid *ssid = wpa_s->current_ssid;
1457 struct hostapd_data *hapd;
1458
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001459 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1460 ssid->mode == WPAS_MODE_INFRA ||
1461 ssid->mode == WPAS_MODE_IBSS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001462 return -1;
1463
1464#ifdef CONFIG_P2P
1465 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001466 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001467 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001468 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001469 P2P_GROUP_FORMATION;
1470#endif /* CONFIG_P2P */
1471
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001472 hapd = iface->bss[0];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001473 if (hapd->drv_priv == NULL)
1474 return -1;
1475 ieee802_11_set_beacons(iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001476 hostapd_set_ap_wps_ie(hapd);
1477
1478 return 0;
1479}
1480
1481
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001482int ap_switch_channel(struct wpa_supplicant *wpa_s,
1483 struct csa_settings *settings)
1484{
1485#ifdef NEED_AP_MLME
Hai Shalom899fcc72020-10-19 14:38:18 -07001486 struct hostapd_iface *iface = NULL;
1487
1488 if (wpa_s->ap_iface)
1489 iface = wpa_s->ap_iface;
1490 else if (wpa_s->ifmsh)
1491 iface = wpa_s->ifmsh;
1492
1493 if (!iface || !iface->bss[0])
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001494 return -1;
1495
Hai Shalom899fcc72020-10-19 14:38:18 -07001496 return hostapd_switch_channel(iface->bss[0], settings);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001497#else /* NEED_AP_MLME */
1498 return -1;
1499#endif /* NEED_AP_MLME */
1500}
1501
1502
Dmitry Shmidt83474442015-04-15 13:47:09 -07001503#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001504int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1505{
1506 struct csa_settings settings;
1507 int ret = hostapd_parse_csa_settings(pos, &settings);
1508
1509 if (ret)
1510 return ret;
1511
1512 return ap_switch_channel(wpa_s, &settings);
1513}
Dmitry Shmidt83474442015-04-15 13:47:09 -07001514#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001515
1516
Dmitry Shmidt04949592012-07-19 12:16:46 -07001517void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
Hai Shalom81f62d82019-07-22 12:10:00 -07001518 int offset, int width, int cf1, int cf2, int finished)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001519{
Hai Shalom74f70d42019-02-11 14:42:39 -08001520 struct hostapd_iface *iface = wpa_s->ap_iface;
Hai Shalombf6e0ba2019-02-11 12:01:50 -08001521
Hai Shalom74f70d42019-02-11 14:42:39 -08001522 if (!iface)
1523 iface = wpa_s->ifmsh;
1524 if (!iface)
1525 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001526 wpa_s->assoc_freq = freq;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001527 if (wpa_s->current_ssid)
1528 wpa_s->current_ssid->frequency = freq;
Hai Shalom74f70d42019-02-11 14:42:39 -08001529 hostapd_event_ch_switch(iface->bss[0], freq, ht,
Hai Shalom81f62d82019-07-22 12:10:00 -07001530 offset, width, cf1, cf2, finished);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001531}
1532
1533
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001534int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1535 const u8 *addr)
1536{
1537 struct hostapd_data *hapd;
1538 struct hostapd_bss_config *conf;
1539
1540 if (!wpa_s->ap_iface)
1541 return -1;
1542
1543 if (addr)
1544 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1545 MAC2STR(addr));
1546 else
1547 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1548
1549 hapd = wpa_s->ap_iface->bss[0];
1550 conf = hapd->conf;
1551
1552 os_free(conf->accept_mac);
1553 conf->accept_mac = NULL;
1554 conf->num_accept_mac = 0;
1555 os_free(conf->deny_mac);
1556 conf->deny_mac = NULL;
1557 conf->num_deny_mac = 0;
1558
1559 if (addr == NULL) {
1560 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1561 return 0;
1562 }
1563
1564 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1565 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1566 if (conf->accept_mac == NULL)
1567 return -1;
1568 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1569 conf->num_accept_mac = 1;
1570
1571 return 0;
1572}
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001573
1574
1575#ifdef CONFIG_WPS_NFC
1576int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1577 const struct wpabuf *pw, const u8 *pubkey_hash)
1578{
1579 struct hostapd_data *hapd;
1580 struct wps_context *wps;
1581
1582 if (!wpa_s->ap_iface)
1583 return -1;
1584 hapd = wpa_s->ap_iface->bss[0];
1585 wps = hapd->wps;
1586
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001587 if (wpa_s->p2pdev->conf->wps_nfc_dh_pubkey == NULL ||
1588 wpa_s->p2pdev->conf->wps_nfc_dh_privkey == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001589 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1590 return -1;
1591 }
1592
1593 dh5_free(wps->dh_ctx);
1594 wpabuf_free(wps->dh_pubkey);
1595 wpabuf_free(wps->dh_privkey);
1596 wps->dh_privkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001597 wpa_s->p2pdev->conf->wps_nfc_dh_privkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001598 wps->dh_pubkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001599 wpa_s->p2pdev->conf->wps_nfc_dh_pubkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001600 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1601 wps->dh_ctx = NULL;
1602 wpabuf_free(wps->dh_pubkey);
1603 wps->dh_pubkey = NULL;
1604 wpabuf_free(wps->dh_privkey);
1605 wps->dh_privkey = NULL;
1606 return -1;
1607 }
1608 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1609 if (wps->dh_ctx == NULL)
1610 return -1;
1611
1612 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1613 pw_id,
1614 pw ? wpabuf_head(pw) : NULL,
1615 pw ? wpabuf_len(pw) : 0, 1);
1616}
1617#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001618
1619
Dmitry Shmidt83474442015-04-15 13:47:09 -07001620#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001621int wpas_ap_stop_ap(struct wpa_supplicant *wpa_s)
1622{
1623 struct hostapd_data *hapd;
1624
1625 if (!wpa_s->ap_iface)
1626 return -1;
1627 hapd = wpa_s->ap_iface->bss[0];
1628 return hostapd_ctrl_iface_stop_ap(hapd);
1629}
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001630
1631
Dmitry Shmidte4663042016-04-04 10:07:49 -07001632int wpas_ap_pmksa_cache_list(struct wpa_supplicant *wpa_s, char *buf,
1633 size_t len)
1634{
1635 size_t reply_len = 0, i;
1636 char ap_delimiter[] = "---- AP ----\n";
1637 char mesh_delimiter[] = "---- mesh ----\n";
1638 size_t dlen;
1639
1640 if (wpa_s->ap_iface) {
1641 dlen = os_strlen(ap_delimiter);
1642 if (dlen > len - reply_len)
1643 return reply_len;
1644 os_memcpy(&buf[reply_len], ap_delimiter, dlen);
1645 reply_len += dlen;
1646
1647 for (i = 0; i < wpa_s->ap_iface->num_bss; i++) {
1648 reply_len += hostapd_ctrl_iface_pmksa_list(
1649 wpa_s->ap_iface->bss[i],
1650 &buf[reply_len], len - reply_len);
1651 }
1652 }
1653
1654 if (wpa_s->ifmsh) {
1655 dlen = os_strlen(mesh_delimiter);
1656 if (dlen > len - reply_len)
1657 return reply_len;
1658 os_memcpy(&buf[reply_len], mesh_delimiter, dlen);
1659 reply_len += dlen;
1660
1661 reply_len += hostapd_ctrl_iface_pmksa_list(
1662 wpa_s->ifmsh->bss[0], &buf[reply_len],
1663 len - reply_len);
1664 }
1665
1666 return reply_len;
1667}
1668
1669
1670void wpas_ap_pmksa_cache_flush(struct wpa_supplicant *wpa_s)
1671{
1672 size_t i;
1673
1674 if (wpa_s->ap_iface) {
1675 for (i = 0; i < wpa_s->ap_iface->num_bss; i++)
1676 hostapd_ctrl_iface_pmksa_flush(wpa_s->ap_iface->bss[i]);
1677 }
1678
1679 if (wpa_s->ifmsh)
1680 hostapd_ctrl_iface_pmksa_flush(wpa_s->ifmsh->bss[0]);
1681}
Paul Stewart092955c2017-02-06 09:13:09 -08001682
1683
1684#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
1685#ifdef CONFIG_MESH
1686
1687int wpas_ap_pmksa_cache_list_mesh(struct wpa_supplicant *wpa_s, const u8 *addr,
1688 char *buf, size_t len)
1689{
1690 return hostapd_ctrl_iface_pmksa_list_mesh(wpa_s->ifmsh->bss[0], addr,
1691 &buf[0], len);
1692}
1693
1694
1695int wpas_ap_pmksa_cache_add_external(struct wpa_supplicant *wpa_s, char *cmd)
1696{
1697 struct external_pmksa_cache *entry;
1698 void *pmksa_cache;
1699
1700 pmksa_cache = hostapd_ctrl_iface_pmksa_create_entry(wpa_s->own_addr,
1701 cmd);
1702 if (!pmksa_cache)
1703 return -1;
1704
1705 entry = os_zalloc(sizeof(struct external_pmksa_cache));
1706 if (!entry)
1707 return -1;
1708
1709 entry->pmksa_cache = pmksa_cache;
1710
1711 dl_list_add(&wpa_s->mesh_external_pmksa_cache, &entry->list);
1712
1713 return 0;
1714}
1715
1716#endif /* CONFIG_MESH */
1717#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
1718
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001719#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte4663042016-04-04 10:07:49 -07001720
1721
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001722#ifdef NEED_AP_MLME
Roshan Pius3a1667e2018-07-03 15:17:14 -07001723void wpas_ap_event_dfs_radar_detected(struct wpa_supplicant *wpa_s,
1724 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001725{
Hai Shalom74f70d42019-02-11 14:42:39 -08001726 struct hostapd_iface *iface = wpa_s->ap_iface;
1727
1728 if (!iface)
1729 iface = wpa_s->ifmsh;
1730 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001731 return;
1732 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001733 hostapd_dfs_radar_detected(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001734 radar->ht_enabled, radar->chan_offset,
1735 radar->chan_width,
1736 radar->cf1, radar->cf2);
1737}
1738
1739
Roshan Pius3a1667e2018-07-03 15:17:14 -07001740void wpas_ap_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
1741 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001742{
Hai Shalom74f70d42019-02-11 14:42:39 -08001743 struct hostapd_iface *iface = wpa_s->ap_iface;
1744
1745 if (!iface)
1746 iface = wpa_s->ifmsh;
1747 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001748 return;
1749 wpa_printf(MSG_DEBUG, "DFS CAC started on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001750 hostapd_dfs_start_cac(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001751 radar->ht_enabled, radar->chan_offset,
1752 radar->chan_width, radar->cf1, radar->cf2);
1753}
1754
1755
Roshan Pius3a1667e2018-07-03 15:17:14 -07001756void wpas_ap_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
1757 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001758{
Hai Shalom74f70d42019-02-11 14:42:39 -08001759 struct hostapd_iface *iface = wpa_s->ap_iface;
1760
1761 if (!iface)
1762 iface = wpa_s->ifmsh;
1763 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001764 return;
1765 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001766 hostapd_dfs_complete_cac(iface, 1, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001767 radar->ht_enabled, radar->chan_offset,
1768 radar->chan_width, radar->cf1, radar->cf2);
1769}
1770
1771
Roshan Pius3a1667e2018-07-03 15:17:14 -07001772void wpas_ap_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
1773 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001774{
Hai Shalom74f70d42019-02-11 14:42:39 -08001775 struct hostapd_iface *iface = wpa_s->ap_iface;
1776
1777 if (!iface)
1778 iface = wpa_s->ifmsh;
1779 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001780 return;
1781 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001782 hostapd_dfs_complete_cac(iface, 0, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001783 radar->ht_enabled, radar->chan_offset,
1784 radar->chan_width, radar->cf1, radar->cf2);
1785}
1786
1787
Roshan Pius3a1667e2018-07-03 15:17:14 -07001788void wpas_ap_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s,
1789 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001790{
Hai Shalom74f70d42019-02-11 14:42:39 -08001791 struct hostapd_iface *iface = wpa_s->ap_iface;
1792
1793 if (!iface)
1794 iface = wpa_s->ifmsh;
1795 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001796 return;
1797 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Hai Shalom74f70d42019-02-11 14:42:39 -08001798 hostapd_dfs_nop_finished(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001799 radar->ht_enabled, radar->chan_offset,
1800 radar->chan_width, radar->cf1, radar->cf2);
1801}
1802#endif /* NEED_AP_MLME */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001803
1804
1805void ap_periodic(struct wpa_supplicant *wpa_s)
1806{
1807 if (wpa_s->ap_iface)
1808 hostapd_periodic_iface(wpa_s->ap_iface);
1809}