blob: 453c99dd512dfe61b05f06c82c725da83ea9a3c0 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Basic AP mode support routines
3 * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2009, Atheros Communications
5 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008 */
9
10#include "utils/includes.h"
11
12#include "utils/common.h"
13#include "utils/eloop.h"
14#include "utils/uuid.h"
15#include "common/ieee802_11_defs.h"
16#include "common/wpa_ctrl.h"
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070017#include "eapol_supp/eapol_supp_sm.h"
Dmitry Shmidtcf32e602014-01-28 10:57:39 -080018#include "crypto/dh_group5.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070019#include "ap/hostapd.h"
20#include "ap/ap_config.h"
21#include "ap/ap_drv_ops.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080022#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070023#include "ap/ieee802_11.h"
24#endif /* NEED_AP_MLME */
25#include "ap/beacon.h"
26#include "ap/ieee802_1x.h"
27#include "ap/wps_hostapd.h"
28#include "ap/ctrl_iface_ap.h"
Dmitry Shmidt203eadb2015-03-05 14:16:04 -080029#include "ap/dfs.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070030#include "wps/wps.h"
31#include "common/ieee802_11_defs.h"
32#include "config_ssid.h"
33#include "config.h"
34#include "wpa_supplicant_i.h"
35#include "driver_i.h"
36#include "p2p_supplicant.h"
37#include "ap.h"
38#include "ap/sta_info.h"
39#include "notify.h"
40
41
42#ifdef CONFIG_WPS
43static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx);
44#endif /* CONFIG_WPS */
45
46
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070047#ifdef CONFIG_IEEE80211N
48static void wpas_conf_ap_vht(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070049 struct wpa_ssid *ssid,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070050 struct hostapd_config *conf,
51 struct hostapd_hw_modes *mode)
52{
Dmitry Shmidt21de2142014-04-08 10:50:52 -070053#ifdef CONFIG_P2P
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070054 u8 center_chan = 0;
55 u8 channel = conf->channel;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070056#endif /* CONFIG_P2P */
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070057
58 if (!conf->secondary_channel)
59 goto no_vht;
60
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070061 /* Use the maximum oper channel width if it's given. */
62 if (ssid->max_oper_chwidth)
63 conf->vht_oper_chwidth = ssid->max_oper_chwidth;
64
65 ieee80211_freq_to_chan(ssid->vht_center_freq2,
66 &conf->vht_oper_centr_freq_seg1_idx);
67
68 if (!ssid->p2p_group) {
69 if (!ssid->vht_center_freq1 ||
70 conf->vht_oper_chwidth == VHT_CHANWIDTH_USE_HT)
71 goto no_vht;
72 ieee80211_freq_to_chan(ssid->vht_center_freq1,
73 &conf->vht_oper_centr_freq_seg0_idx);
Roshan Pius3a1667e2018-07-03 15:17:14 -070074 wpa_printf(MSG_DEBUG, "VHT seg0 index %d for AP",
75 conf->vht_oper_centr_freq_seg0_idx);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070076 return;
77 }
78
79#ifdef CONFIG_P2P
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080080 switch (conf->vht_oper_chwidth) {
81 case VHT_CHANWIDTH_80MHZ:
82 case VHT_CHANWIDTH_80P80MHZ:
83 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -070084 wpa_printf(MSG_DEBUG,
85 "VHT center channel %u for 80 or 80+80 MHz bandwidth",
86 center_chan);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080087 break;
88 case VHT_CHANWIDTH_160MHZ:
89 center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -070090 wpa_printf(MSG_DEBUG,
91 "VHT center channel %u for 160 MHz bandwidth",
92 center_chan);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080093 break;
94 default:
95 /*
96 * conf->vht_oper_chwidth might not be set for non-P2P GO cases,
97 * try oper_cwidth 160 MHz first then VHT 80 MHz, if 160 MHz is
98 * not supported.
99 */
100 conf->vht_oper_chwidth = VHT_CHANWIDTH_160MHZ;
101 center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700102 if (center_chan) {
103 wpa_printf(MSG_DEBUG,
104 "VHT center channel %u for auto-selected 160 MHz bandwidth",
105 center_chan);
106 } else {
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800107 conf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ;
108 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode,
109 channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700110 wpa_printf(MSG_DEBUG,
111 "VHT center channel %u for auto-selected 80 MHz bandwidth",
112 center_chan);
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800113 }
114 break;
115 }
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700116 if (!center_chan)
117 goto no_vht;
118
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700119 conf->vht_oper_centr_freq_seg0_idx = center_chan;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700120 wpa_printf(MSG_DEBUG, "VHT seg0 index %d for P2P GO",
121 conf->vht_oper_centr_freq_seg0_idx);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700122 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700123#endif /* CONFIG_P2P */
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700124
125no_vht:
Roshan Pius3a1667e2018-07-03 15:17:14 -0700126 wpa_printf(MSG_DEBUG,
127 "No VHT higher bandwidth support for the selected channel %d",
128 conf->channel);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700129 conf->vht_oper_centr_freq_seg0_idx =
Dmitry Shmidt21de2142014-04-08 10:50:52 -0700130 conf->channel + conf->secondary_channel * 2;
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800131 conf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700132}
133#endif /* CONFIG_IEEE80211N */
134
135
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800136int wpa_supplicant_conf_ap_ht(struct wpa_supplicant *wpa_s,
137 struct wpa_ssid *ssid,
138 struct hostapd_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700139{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800140 conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency,
141 &conf->channel);
142
143 if (conf->hw_mode == NUM_HOSTAPD_MODES) {
144 wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
145 ssid->frequency);
146 return -1;
147 }
148
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700149 /* TODO: enable HT40 if driver supports it;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700150 * drop to 11b if driver does not support 11g */
151
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700152#ifdef CONFIG_IEEE80211N
153 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800154 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
155 * and a mask of allowed capabilities within conf->ht_capab.
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700156 * Using default config settings for: conf->ht_op_mode_fixed,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800157 * conf->secondary_channel, conf->require_ht
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700158 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800159 if (wpa_s->hw.modes) {
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700160 struct hostapd_hw_modes *mode = NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700161 int i, no_ht = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700162
163 wpa_printf(MSG_DEBUG,
164 "Determining HT/VHT options based on driver capabilities (freq=%u chan=%u)",
165 ssid->frequency, conf->channel);
166
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800167 for (i = 0; i < wpa_s->hw.num_modes; i++) {
168 if (wpa_s->hw.modes[i].mode == conf->hw_mode) {
169 mode = &wpa_s->hw.modes[i];
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700170 break;
171 }
172 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700173
174#ifdef CONFIG_HT_OVERRIDES
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700175 if (ssid->disable_ht)
176 ssid->ht = 0;
177#endif /* CONFIG_HT_OVERRIDES */
178
179 if (!ssid->ht) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700180 wpa_printf(MSG_DEBUG,
181 "HT not enabled in network profile");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700182 conf->ieee80211n = 0;
183 conf->ht_capab = 0;
184 no_ht = 1;
185 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700186
187 if (!no_ht && mode && mode->ht_capab) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700188 wpa_printf(MSG_DEBUG,
189 "Enable HT support (p2p_group=%d 11a=%d ht40_hw_capab=%d ssid->ht40=%d)",
190 ssid->p2p_group,
191 conf->hw_mode == HOSTAPD_MODE_IEEE80211A,
192 !!(mode->ht_capab &
193 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET),
194 ssid->ht40);
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700195 conf->ieee80211n = 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700196#ifdef CONFIG_P2P
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700197 if (ssid->p2p_group &&
198 conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700199 (mode->ht_capab &
200 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
Roshan Pius3a1667e2018-07-03 15:17:14 -0700201 ssid->ht40) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700202 conf->secondary_channel =
203 wpas_p2p_get_ht40_mode(wpa_s, mode,
204 conf->channel);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700205 wpa_printf(MSG_DEBUG,
206 "HT secondary channel offset %d for P2P group",
207 conf->secondary_channel);
208 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700209#endif /* CONFIG_P2P */
210
211 if (!ssid->p2p_group &&
212 (mode->ht_capab &
Roshan Pius3a1667e2018-07-03 15:17:14 -0700213 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700214 conf->secondary_channel = ssid->ht40;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700215 wpa_printf(MSG_DEBUG,
216 "HT secondary channel offset %d for AP",
217 conf->secondary_channel);
218 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700219
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700220 if (conf->secondary_channel)
221 conf->ht_capab |=
222 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800223
224 /*
225 * white-list capabilities that won't cause issues
226 * to connecting stations, while leaving the current
227 * capabilities intact (currently disabled SMPS).
228 */
229 conf->ht_capab |= mode->ht_capab &
230 (HT_CAP_INFO_GREEN_FIELD |
231 HT_CAP_INFO_SHORT_GI20MHZ |
232 HT_CAP_INFO_SHORT_GI40MHZ |
233 HT_CAP_INFO_RX_STBC_MASK |
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800234 HT_CAP_INFO_TX_STBC |
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800235 HT_CAP_INFO_MAX_AMSDU_SIZE);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700236
237 if (mode->vht_capab && ssid->vht) {
238 conf->ieee80211ac = 1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800239 conf->vht_capab |= mode->vht_capab;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700240 wpas_conf_ap_vht(wpa_s, ssid, conf, mode);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700241 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800242 }
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700243 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800244
245 if (conf->secondary_channel) {
246 struct wpa_supplicant *iface;
247
248 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
249 {
250 if (iface == wpa_s ||
251 iface->wpa_state < WPA_AUTHENTICATING ||
252 (int) iface->assoc_freq != ssid->frequency)
253 continue;
254
255 /*
256 * Do not allow 40 MHz co-ex PRI/SEC switch to force us
257 * to change our PRI channel since we have an existing,
258 * concurrent connection on that channel and doing
259 * multi-channel concurrency is likely to cause more
260 * harm than using different PRI/SEC selection in
261 * environment with multiple BSSes on these two channels
262 * with mixed 20 MHz or PRI channel selection.
263 */
264 conf->no_pri_sec_switch = 1;
265 }
266 }
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700267#endif /* CONFIG_IEEE80211N */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800268
269 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800270}
271
272
273static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
274 struct wpa_ssid *ssid,
275 struct hostapd_config *conf)
276{
277 struct hostapd_bss_config *bss = conf->bss[0];
278
279 conf->driver = wpa_s->driver;
280
281 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
282
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800283 if (wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800284 return -1;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700285
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700286 if (ssid->pbss > 1) {
287 wpa_printf(MSG_ERROR, "Invalid pbss value(%d) for AP mode",
288 ssid->pbss);
289 return -1;
290 }
291 bss->pbss = ssid->pbss;
292
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800293#ifdef CONFIG_ACS
294 if (ssid->acs) {
295 /* Setting channel to 0 in order to enable ACS */
296 conf->channel = 0;
297 wpa_printf(MSG_DEBUG, "Use automatic channel selection");
298 }
299#endif /* CONFIG_ACS */
300
Roshan Pius3a1667e2018-07-03 15:17:14 -0700301 if (ieee80211_is_dfs(ssid->frequency, wpa_s->hw.modes,
302 wpa_s->hw.num_modes) && wpa_s->conf->country[0]) {
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800303 conf->ieee80211h = 1;
304 conf->ieee80211d = 1;
305 conf->country[0] = wpa_s->conf->country[0];
306 conf->country[1] = wpa_s->conf->country[1];
Paul Stewart092955c2017-02-06 09:13:09 -0800307 conf->country[2] = ' ';
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800308 }
309
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700310#ifdef CONFIG_P2P
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700311 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
312 (ssid->mode == WPAS_MODE_P2P_GO ||
313 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700314 /* Remove 802.11b rates from supported and basic rate sets */
315 int *list = os_malloc(4 * sizeof(int));
316 if (list) {
317 list[0] = 60;
318 list[1] = 120;
319 list[2] = 240;
320 list[3] = -1;
321 }
322 conf->basic_rates = list;
323
324 list = os_malloc(9 * sizeof(int));
325 if (list) {
326 list[0] = 60;
327 list[1] = 90;
328 list[2] = 120;
329 list[3] = 180;
330 list[4] = 240;
331 list[5] = 360;
332 list[6] = 480;
333 list[7] = 540;
334 list[8] = -1;
335 }
336 conf->supported_rates = list;
Hai Shalom39bc25d2019-02-06 16:32:13 -0800337#ifdef CONFIG_IEEE80211AX
338 conf->ieee80211ax = ssid->he;
339#endif /* CONFIG_IEEE80211AX */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700340 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800341
342 bss->isolate = !wpa_s->conf->p2p_intra_bss;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700343 bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800344
345 if (ssid->p2p_group) {
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800346 os_memcpy(bss->ip_addr_go, wpa_s->p2pdev->conf->ip_addr_go, 4);
347 os_memcpy(bss->ip_addr_mask, wpa_s->p2pdev->conf->ip_addr_mask,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800348 4);
349 os_memcpy(bss->ip_addr_start,
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800350 wpa_s->p2pdev->conf->ip_addr_start, 4);
351 os_memcpy(bss->ip_addr_end, wpa_s->p2pdev->conf->ip_addr_end,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800352 4);
353 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700354#endif /* CONFIG_P2P */
355
356 if (ssid->ssid_len == 0) {
357 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
358 return -1;
359 }
360 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700361 bss->ssid.ssid_len = ssid->ssid_len;
362 bss->ssid.ssid_set = 1;
363
Dmitry Shmidt04949592012-07-19 12:16:46 -0700364 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
365
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800366 if (ssid->auth_alg)
367 bss->auth_algs = ssid->auth_alg;
368
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700369 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
370 bss->wpa = ssid->proto;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700371 if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
372 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
373 else
374 bss->wpa_key_mgmt = ssid->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700375 bss->wpa_pairwise = ssid->pairwise_cipher;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800376 if (ssid->psk_set) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800377 bin_clear_free(bss->ssid.wpa_psk, sizeof(*bss->ssid.wpa_psk));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700378 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
379 if (bss->ssid.wpa_psk == NULL)
380 return -1;
381 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
382 bss->ssid.wpa_psk->group = 1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700383 bss->ssid.wpa_psk_set = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800384 } else if (ssid->passphrase) {
385 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800386 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
387 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
388 struct hostapd_wep_keys *wep = &bss->ssid.wep;
389 int i;
390 for (i = 0; i < NUM_WEP_KEYS; i++) {
391 if (ssid->wep_key_len[i] == 0)
392 continue;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700393 wep->key[i] = os_memdup(ssid->wep_key[i],
394 ssid->wep_key_len[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800395 if (wep->key[i] == NULL)
396 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800397 wep->len[i] = ssid->wep_key_len[i];
398 }
399 wep->idx = ssid->wep_tx_keyidx;
400 wep->keys_set = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700401 }
402
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700403 if (wpa_s->conf->go_interworking) {
404 wpa_printf(MSG_DEBUG,
405 "P2P: Enable Interworking with access_network_type: %d",
406 wpa_s->conf->go_access_network_type);
407 bss->interworking = wpa_s->conf->go_interworking;
408 bss->access_network_type = wpa_s->conf->go_access_network_type;
409 bss->internet = wpa_s->conf->go_internet;
410 if (wpa_s->conf->go_venue_group) {
411 wpa_printf(MSG_DEBUG,
412 "P2P: Venue group: %d Venue type: %d",
413 wpa_s->conf->go_venue_group,
414 wpa_s->conf->go_venue_type);
415 bss->venue_group = wpa_s->conf->go_venue_group;
416 bss->venue_type = wpa_s->conf->go_venue_type;
417 bss->venue_info_set = 1;
418 }
419 }
420
Dmitry Shmidt04949592012-07-19 12:16:46 -0700421 if (ssid->ap_max_inactivity)
422 bss->ap_max_inactivity = ssid->ap_max_inactivity;
423
424 if (ssid->dtim_period)
425 bss->dtim_period = ssid->dtim_period;
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -0800426 else if (wpa_s->conf->dtim_period)
427 bss->dtim_period = wpa_s->conf->dtim_period;
428
429 if (ssid->beacon_int)
430 conf->beacon_int = ssid->beacon_int;
431 else if (wpa_s->conf->beacon_int)
432 conf->beacon_int = wpa_s->conf->beacon_int;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700433
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800434#ifdef CONFIG_P2P
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800435 if (ssid->mode == WPAS_MODE_P2P_GO ||
436 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
437 if (wpa_s->conf->p2p_go_ctwindow > conf->beacon_int) {
438 wpa_printf(MSG_INFO,
439 "CTWindow (%d) is bigger than beacon interval (%d) - avoid configuring it",
440 wpa_s->conf->p2p_go_ctwindow,
441 conf->beacon_int);
442 conf->p2p_go_ctwindow = 0;
443 } else {
444 conf->p2p_go_ctwindow = wpa_s->conf->p2p_go_ctwindow;
445 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800446 }
447#endif /* CONFIG_P2P */
448
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800449 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
450 bss->rsn_pairwise = bss->wpa_pairwise;
451 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
452 bss->rsn_pairwise);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700453
454 if (bss->wpa && bss->ieee802_1x)
455 bss->ssid.security_policy = SECURITY_WPA;
456 else if (bss->wpa)
457 bss->ssid.security_policy = SECURITY_WPA_PSK;
458 else if (bss->ieee802_1x) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800459 int cipher = WPA_CIPHER_NONE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700460 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
461 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800462 if (bss->default_wep_key_len)
463 cipher = bss->default_wep_key_len >= 13 ?
464 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
465 bss->wpa_group = cipher;
466 bss->wpa_pairwise = cipher;
467 bss->rsn_pairwise = cipher;
468 } else if (bss->ssid.wep.keys_set) {
469 int cipher = WPA_CIPHER_WEP40;
470 if (bss->ssid.wep.len[0] >= 13)
471 cipher = WPA_CIPHER_WEP104;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700472 bss->ssid.security_policy = SECURITY_STATIC_WEP;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800473 bss->wpa_group = cipher;
474 bss->wpa_pairwise = cipher;
475 bss->rsn_pairwise = cipher;
476 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700477 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800478 bss->wpa_group = WPA_CIPHER_NONE;
479 bss->wpa_pairwise = WPA_CIPHER_NONE;
480 bss->rsn_pairwise = WPA_CIPHER_NONE;
481 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700482
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700483 if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
484 (bss->wpa_group == WPA_CIPHER_CCMP ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800485 bss->wpa_group == WPA_CIPHER_GCMP ||
486 bss->wpa_group == WPA_CIPHER_CCMP_256 ||
487 bss->wpa_group == WPA_CIPHER_GCMP_256)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700488 /*
489 * Strong ciphers do not need frequent rekeying, so increase
490 * the default GTK rekeying period to 24 hours.
491 */
492 bss->wpa_group_rekey = 86400;
493 }
494
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700495#ifdef CONFIG_IEEE80211W
496 if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT)
497 bss->ieee80211w = ssid->ieee80211w;
498#endif /* CONFIG_IEEE80211W */
499
Hai Shalom39bc25d2019-02-06 16:32:13 -0800500#ifdef CONFIG_OCV
501 bss->ocv = ssid->ocv;
502#endif /* CONFIG_OCV */
503
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700504#ifdef CONFIG_WPS
505 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800506 * Enable WPS by default for open and WPA/WPA2-Personal network, but
507 * require user interaction to actually use it. Only the internal
508 * Registrar is supported.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700509 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800510 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
511 bss->ssid.security_policy != SECURITY_PLAINTEXT)
512 goto no_wps;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800513 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800514 (!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ||
515 !(bss->wpa & 2)))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800516 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
517 * configuration */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700518 if (ssid->wps_disabled)
519 goto no_wps;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700520 bss->eap_server = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700521
522 if (!ssid->ignore_broadcast_ssid)
523 bss->wps_state = 2;
524
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700525 bss->ap_setup_locked = 2;
526 if (wpa_s->conf->config_methods)
527 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
528 os_memcpy(bss->device_type, wpa_s->conf->device_type,
529 WPS_DEV_TYPE_LEN);
530 if (wpa_s->conf->device_name) {
531 bss->device_name = os_strdup(wpa_s->conf->device_name);
532 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
533 }
534 if (wpa_s->conf->manufacturer)
535 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
536 if (wpa_s->conf->model_name)
537 bss->model_name = os_strdup(wpa_s->conf->model_name);
538 if (wpa_s->conf->model_number)
539 bss->model_number = os_strdup(wpa_s->conf->model_number);
540 if (wpa_s->conf->serial_number)
541 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
542 if (is_nil_uuid(wpa_s->conf->uuid))
543 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
544 else
545 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
546 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700547 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -0700548 if (ssid->eap.fragment_size != DEFAULT_FRAGMENT_SIZE)
549 bss->fragment_size = ssid->eap.fragment_size;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800550no_wps:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700551#endif /* CONFIG_WPS */
552
553 if (wpa_s->max_stations &&
554 wpa_s->max_stations < wpa_s->conf->max_num_sta)
555 bss->max_num_sta = wpa_s->max_stations;
556 else
557 bss->max_num_sta = wpa_s->conf->max_num_sta;
558
Roshan Pius3a1667e2018-07-03 15:17:14 -0700559 if (!bss->isolate)
560 bss->isolate = wpa_s->conf->ap_isolate;
561
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700562 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
563
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700564 if (wpa_s->conf->ap_vendor_elements) {
565 bss->vendor_elements =
566 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
567 }
568
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700569 bss->ftm_responder = wpa_s->conf->ftm_responder;
570 bss->ftm_initiator = wpa_s->conf->ftm_initiator;
571
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700572 return 0;
573}
574
575
576static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
577{
578#ifdef CONFIG_P2P
579 struct wpa_supplicant *wpa_s = ctx;
580 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700581
582 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700583 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700584 return;
Dmitry Shmidt18463232014-01-24 12:29:41 -0800585 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
586 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700587 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
588 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700589 buf + IEEE80211_HDRLEN + 1,
590 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700591#endif /* CONFIG_P2P */
592}
593
594
595static void ap_wps_event_cb(void *ctx, enum wps_event event,
596 union wps_event_data *data)
597{
598#ifdef CONFIG_P2P
599 struct wpa_supplicant *wpa_s = ctx;
600
Jouni Malinen75ecf522011-06-27 15:19:46 -0700601 if (event == WPS_EV_FAIL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700602 struct wps_event_fail *fail = &data->fail;
603
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800604 if (wpa_s->p2pdev && wpa_s->p2pdev != wpa_s &&
Jouni Malinen75ecf522011-06-27 15:19:46 -0700605 wpa_s == wpa_s->global->p2p_group_formation) {
606 /*
607 * src/ap/wps_hostapd.c has already sent this on the
608 * main interface, so only send on the parent interface
609 * here if needed.
610 */
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800611 wpa_msg(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_FAIL
Jouni Malinen75ecf522011-06-27 15:19:46 -0700612 "msg=%d config_error=%d",
613 fail->msg, fail->config_error);
614 }
615 wpas_p2p_wps_failed(wpa_s, fail);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700616 }
617#endif /* CONFIG_P2P */
618}
619
620
621static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800622 int authorized, const u8 *p2p_dev_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700623{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800624 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700625}
626
627
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700628#ifdef CONFIG_P2P
629static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
630 const u8 *psk, size_t psk_len)
631{
632
633 struct wpa_supplicant *wpa_s = ctx;
634 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
635 return;
636 wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
637}
638#endif /* CONFIG_P2P */
639
640
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700641static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
642{
643#ifdef CONFIG_P2P
644 struct wpa_supplicant *wpa_s = ctx;
645 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700646
647 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700648 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700649 return -1;
650 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
651 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700652 buf + IEEE80211_HDRLEN + 1,
653 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700654#endif /* CONFIG_P2P */
655 return 0;
656}
657
658
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800659static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700660 const u8 *bssid, const u8 *ie, size_t ie_len,
661 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700662{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700663 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700664 unsigned int freq = 0;
665
666 if (wpa_s->ap_iface)
667 freq = wpa_s->ap_iface->freq;
668
Dmitry Shmidt04949592012-07-19 12:16:46 -0700669 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700670 freq, ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700671}
672
673
674static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
675 const u8 *uuid_e)
676{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700677 struct wpa_supplicant *wpa_s = ctx;
678 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700679}
680
681
682static void wpas_ap_configured_cb(void *ctx)
683{
684 struct wpa_supplicant *wpa_s = ctx;
685
Roshan Pius3a1667e2018-07-03 15:17:14 -0700686 wpa_printf(MSG_DEBUG, "AP interface setup completed - state %s",
687 hostapd_state_text(wpa_s->ap_iface->state));
688 if (wpa_s->ap_iface->state == HAPD_IFACE_DISABLED) {
689 wpa_supplicant_ap_deinit(wpa_s);
690 return;
691 }
692
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800693#ifdef CONFIG_ACS
Roshan Pius3a1667e2018-07-03 15:17:14 -0700694 if (wpa_s->current_ssid && wpa_s->current_ssid->acs) {
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800695 wpa_s->assoc_freq = wpa_s->ap_iface->freq;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700696 wpa_s->current_ssid->frequency = wpa_s->ap_iface->freq;
697 }
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800698#endif /* CONFIG_ACS */
699
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700700 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
701
702 if (wpa_s->ap_configured_cb)
703 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
704 wpa_s->ap_configured_cb_data);
705}
706
707
708int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
709 struct wpa_ssid *ssid)
710{
711 struct wpa_driver_associate_params params;
712 struct hostapd_iface *hapd_iface;
713 struct hostapd_config *conf;
714 size_t i;
715
716 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
717 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
718 return -1;
719 }
720
721 wpa_supplicant_ap_deinit(wpa_s);
722
723 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
724 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
725
726 os_memset(&params, 0, sizeof(params));
727 params.ssid = ssid->ssid;
728 params.ssid_len = ssid->ssid_len;
729 switch (ssid->mode) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700730 case WPAS_MODE_AP:
731 case WPAS_MODE_P2P_GO:
732 case WPAS_MODE_P2P_GROUP_FORMATION:
733 params.mode = IEEE80211_MODE_AP;
734 break;
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800735 default:
736 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700737 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700738 if (ssid->frequency == 0)
739 ssid->frequency = 2462; /* default channel 11 */
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700740 params.freq.freq = ssid->frequency;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700741
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800742 params.wpa_proto = ssid->proto;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700743 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
744 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
745 else
746 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800747 params.key_mgmt_suite = wpa_s->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700748
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800749 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
750 1);
751 if (wpa_s->pairwise_cipher < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700752 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
753 "cipher.");
754 return -1;
755 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800756 params.pairwise_suite = wpa_s->pairwise_cipher;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700757 params.group_suite = params.pairwise_suite;
758
759#ifdef CONFIG_P2P
760 if (ssid->mode == WPAS_MODE_P2P_GO ||
761 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
762 params.p2p = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700763#endif /* CONFIG_P2P */
764
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800765 if (wpa_s->p2pdev->set_ap_uapsd)
766 params.uapsd = wpa_s->p2pdev->ap_uapsd;
Dmitry Shmidtec58b162014-02-19 12:44:18 -0800767 else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
768 params.uapsd = 1; /* mandatory for P2P GO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700769 else
770 params.uapsd = -1;
771
Roshan Pius3a1667e2018-07-03 15:17:14 -0700772 if (ieee80211_is_dfs(params.freq.freq, wpa_s->hw.modes,
773 wpa_s->hw.num_modes))
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800774 params.freq.freq = 0; /* set channel after CAC */
775
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700776 if (params.p2p)
777 wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_GO);
778 else
779 wpa_drv_get_ext_capa(wpa_s, WPA_IF_AP_BSS);
780
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700781 if (wpa_drv_associate(wpa_s, &params) < 0) {
782 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
783 return -1;
784 }
785
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700786 wpa_s->ap_iface = hapd_iface = hostapd_alloc_iface();
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700787 if (hapd_iface == NULL)
788 return -1;
789 hapd_iface->owner = wpa_s;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800790 hapd_iface->drv_flags = wpa_s->drv_flags;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800791 hapd_iface->smps_modes = wpa_s->drv_smps_modes;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800792 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700793 hapd_iface->extended_capa = wpa_s->extended_capa;
794 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
795 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700796
797 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
798 if (conf == NULL) {
799 wpa_supplicant_ap_deinit(wpa_s);
800 return -1;
801 }
802
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700803 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
804 wpa_s->conf->wmm_ac_params,
805 sizeof(wpa_s->conf->wmm_ac_params));
806
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800807 if (params.uapsd > 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800808 conf->bss[0]->wmm_enabled = 1;
809 conf->bss[0]->wmm_uapsd = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800810 }
811
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700812 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
813 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
814 wpa_supplicant_ap_deinit(wpa_s);
815 return -1;
816 }
817
818#ifdef CONFIG_P2P
819 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800820 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700821 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800822 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700823 P2P_GROUP_FORMATION;
824#endif /* CONFIG_P2P */
825
826 hapd_iface->num_bss = conf->num_bss;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700827 hapd_iface->bss = os_calloc(conf->num_bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700828 sizeof(struct hostapd_data *));
829 if (hapd_iface->bss == NULL) {
830 wpa_supplicant_ap_deinit(wpa_s);
831 return -1;
832 }
833
834 for (i = 0; i < conf->num_bss; i++) {
835 hapd_iface->bss[i] =
836 hostapd_alloc_bss_data(hapd_iface, conf,
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800837 conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700838 if (hapd_iface->bss[i] == NULL) {
839 wpa_supplicant_ap_deinit(wpa_s);
840 return -1;
841 }
842
843 hapd_iface->bss[i]->msg_ctx = wpa_s;
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800844 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->p2pdev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700845 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
846 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
847 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
848 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
849 hostapd_register_probereq_cb(hapd_iface->bss[i],
850 ap_probe_req_rx, wpa_s);
851 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
852 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
853 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
854 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
855 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
856 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
857#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700858 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
859 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700860 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700861 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
862 ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700863#endif /* CONFIG_P2P */
864 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
865 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800866#ifdef CONFIG_TESTING_OPTIONS
867 hapd_iface->bss[i]->ext_eapol_frame_io =
868 wpa_s->ext_eapol_frame_io;
869#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700870 }
871
872 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
873 hapd_iface->bss[0]->driver = wpa_s->driver;
874 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
875
876 wpa_s->current_ssid = ssid;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700877 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700878 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
879 wpa_s->assoc_freq = ssid->frequency;
880
Roshan Pius3a1667e2018-07-03 15:17:14 -0700881#if defined(CONFIG_P2P) && defined(CONFIG_ACS)
882 if (wpa_s->p2p_go_do_acs) {
883 wpa_s->ap_iface->conf->channel = 0;
884 wpa_s->ap_iface->conf->hw_mode = wpa_s->p2p_go_acs_band;
885 ssid->acs = 1;
886 }
887#endif /* CONFIG_P2P && CONFIG_ACS */
888
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700889 if (hostapd_setup_interface(wpa_s->ap_iface)) {
890 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
891 wpa_supplicant_ap_deinit(wpa_s);
892 return -1;
893 }
894
895 return 0;
896}
897
898
899void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
900{
901#ifdef CONFIG_WPS
902 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
903#endif /* CONFIG_WPS */
904
905 if (wpa_s->ap_iface == NULL)
906 return;
907
908 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700909 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700910 wpa_s->assoc_freq = 0;
Dmitry Shmidt43cb5782014-06-16 16:23:22 -0700911 wpas_p2p_ap_deinit(wpa_s);
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800912 wpa_s->ap_iface->driver_ap_teardown =
913 !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
914
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700915 hostapd_interface_deinit(wpa_s->ap_iface);
916 hostapd_interface_free(wpa_s->ap_iface);
917 wpa_s->ap_iface = NULL;
918 wpa_drv_deinit_ap(wpa_s);
Dmitry Shmidtf73259c2015-03-17 11:00:54 -0700919 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
920 " reason=%d locally_generated=1",
921 MAC2STR(wpa_s->own_addr), WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700922}
923
924
925void ap_tx_status(void *ctx, const u8 *addr,
926 const u8 *buf, size_t len, int ack)
927{
928#ifdef NEED_AP_MLME
929 struct wpa_supplicant *wpa_s = ctx;
930 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
931#endif /* NEED_AP_MLME */
932}
933
934
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800935void ap_eapol_tx_status(void *ctx, const u8 *dst,
936 const u8 *data, size_t len, int ack)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700937{
938#ifdef NEED_AP_MLME
939 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800940 if (!wpa_s->ap_iface)
941 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800942 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
943#endif /* NEED_AP_MLME */
944}
945
946
947void ap_client_poll_ok(void *ctx, const u8 *addr)
948{
949#ifdef NEED_AP_MLME
950 struct wpa_supplicant *wpa_s = ctx;
951 if (wpa_s->ap_iface)
952 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
953#endif /* NEED_AP_MLME */
954}
955
956
957void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
958{
959#ifdef NEED_AP_MLME
960 struct wpa_supplicant *wpa_s = ctx;
961 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700962#endif /* NEED_AP_MLME */
963}
964
965
966void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
967{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800968#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700969 struct wpa_supplicant *wpa_s = ctx;
970 struct hostapd_frame_info fi;
971 os_memset(&fi, 0, sizeof(fi));
972 fi.datarate = rx_mgmt->datarate;
973 fi.ssi_signal = rx_mgmt->ssi_signal;
974 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
975 rx_mgmt->frame_len, &fi);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800976#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700977}
978
979
980void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
981{
982#ifdef NEED_AP_MLME
983 struct wpa_supplicant *wpa_s = ctx;
984 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
985#endif /* NEED_AP_MLME */
986}
987
988
989void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
990 const u8 *src_addr, const u8 *buf, size_t len)
991{
992 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
993}
994
995
996#ifdef CONFIG_WPS
997
998int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
999 const u8 *p2p_dev_addr)
1000{
1001 if (!wpa_s->ap_iface)
1002 return -1;
1003 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
1004 p2p_dev_addr);
1005}
1006
1007
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001008int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
1009{
1010 struct wps_registrar *reg;
1011 int reg_sel = 0, wps_sta = 0;
1012
1013 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
1014 return -1;
1015
1016 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
1017 reg_sel = wps_registrar_wps_cancel(reg);
1018 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
Dmitry Shmidt04949592012-07-19 12:16:46 -07001019 ap_sta_wps_cancel, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001020
1021 if (!reg_sel && !wps_sta) {
1022 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
1023 "time");
1024 return -1;
1025 }
1026
1027 /*
1028 * There are 2 cases to return wps cancel as success:
1029 * 1. When wps cancel was initiated but no connection has been
1030 * established with client yet.
1031 * 2. Client is in the middle of exchanging WPS messages.
1032 */
1033
1034 return 0;
1035}
1036
1037
1038int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001039 const char *pin, char *buf, size_t buflen,
1040 int timeout)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001041{
1042 int ret, ret_len = 0;
1043
1044 if (!wpa_s->ap_iface)
1045 return -1;
1046
1047 if (pin == NULL) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001048 unsigned int rpin;
1049
1050 if (wps_generate_pin(&rpin) < 0)
1051 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001052 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001053 if (os_snprintf_error(buflen, ret_len))
1054 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001055 pin = buf;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001056 } else if (buf) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001057 ret_len = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001058 if (os_snprintf_error(buflen, ret_len))
1059 return -1;
1060 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001061
1062 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001063 timeout);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001064 if (ret)
1065 return -1;
1066 return ret_len;
1067}
1068
1069
1070static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
1071{
1072 struct wpa_supplicant *wpa_s = eloop_data;
1073 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
1074 wpas_wps_ap_pin_disable(wpa_s);
1075}
1076
1077
1078static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
1079{
1080 struct hostapd_data *hapd;
1081
1082 if (wpa_s->ap_iface == NULL)
1083 return;
1084 hapd = wpa_s->ap_iface->bss[0];
1085 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
1086 hapd->ap_pin_failures = 0;
1087 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1088 if (timeout > 0)
1089 eloop_register_timeout(timeout, 0,
1090 wpas_wps_ap_pin_timeout, wpa_s, NULL);
1091}
1092
1093
1094void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
1095{
1096 struct hostapd_data *hapd;
1097
1098 if (wpa_s->ap_iface == NULL)
1099 return;
1100 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
1101 hapd = wpa_s->ap_iface->bss[0];
1102 os_free(hapd->conf->ap_pin);
1103 hapd->conf->ap_pin = NULL;
1104 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1105}
1106
1107
1108const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
1109{
1110 struct hostapd_data *hapd;
1111 unsigned int pin;
1112 char pin_txt[9];
1113
1114 if (wpa_s->ap_iface == NULL)
1115 return NULL;
1116 hapd = wpa_s->ap_iface->bss[0];
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001117 if (wps_generate_pin(&pin) < 0)
1118 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001119 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001120 os_free(hapd->conf->ap_pin);
1121 hapd->conf->ap_pin = os_strdup(pin_txt);
1122 if (hapd->conf->ap_pin == NULL)
1123 return NULL;
1124 wpas_wps_ap_pin_enable(wpa_s, timeout);
1125
1126 return hapd->conf->ap_pin;
1127}
1128
1129
1130const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
1131{
1132 struct hostapd_data *hapd;
1133 if (wpa_s->ap_iface == NULL)
1134 return NULL;
1135 hapd = wpa_s->ap_iface->bss[0];
1136 return hapd->conf->ap_pin;
1137}
1138
1139
1140int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
1141 int timeout)
1142{
1143 struct hostapd_data *hapd;
1144 char pin_txt[9];
1145 int ret;
1146
1147 if (wpa_s->ap_iface == NULL)
1148 return -1;
1149 hapd = wpa_s->ap_iface->bss[0];
1150 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001151 if (os_snprintf_error(sizeof(pin_txt), ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001152 return -1;
1153 os_free(hapd->conf->ap_pin);
1154 hapd->conf->ap_pin = os_strdup(pin_txt);
1155 if (hapd->conf->ap_pin == NULL)
1156 return -1;
1157 wpas_wps_ap_pin_enable(wpa_s, timeout);
1158
1159 return 0;
1160}
1161
1162
1163void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
1164{
1165 struct hostapd_data *hapd;
1166
1167 if (wpa_s->ap_iface == NULL)
1168 return;
1169 hapd = wpa_s->ap_iface->bss[0];
1170
1171 /*
1172 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
1173 * PIN if this happens multiple times to slow down brute force attacks.
1174 */
1175 hapd->ap_pin_failures++;
1176 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
1177 hapd->ap_pin_failures);
1178 if (hapd->ap_pin_failures < 3)
1179 return;
1180
1181 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
1182 hapd->ap_pin_failures = 0;
1183 os_free(hapd->conf->ap_pin);
1184 hapd->conf->ap_pin = NULL;
1185}
1186
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001187
1188#ifdef CONFIG_WPS_NFC
1189
1190struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
1191 int ndef)
1192{
1193 struct hostapd_data *hapd;
1194
1195 if (wpa_s->ap_iface == NULL)
1196 return NULL;
1197 hapd = wpa_s->ap_iface->bss[0];
1198 return hostapd_wps_nfc_config_token(hapd, ndef);
1199}
1200
1201
1202struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
1203 int ndef)
1204{
1205 struct hostapd_data *hapd;
1206
1207 if (wpa_s->ap_iface == NULL)
1208 return NULL;
1209 hapd = wpa_s->ap_iface->bss[0];
1210 return hostapd_wps_nfc_hs_cr(hapd, ndef);
1211}
1212
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001213
1214int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
1215 const struct wpabuf *req,
1216 const struct wpabuf *sel)
1217{
1218 struct hostapd_data *hapd;
1219
1220 if (wpa_s->ap_iface == NULL)
1221 return -1;
1222 hapd = wpa_s->ap_iface->bss[0];
1223 return hostapd_wps_nfc_report_handover(hapd, req, sel);
1224}
1225
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001226#endif /* CONFIG_WPS_NFC */
1227
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001228#endif /* CONFIG_WPS */
1229
1230
1231#ifdef CONFIG_CTRL_IFACE
1232
1233int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
1234 char *buf, size_t buflen)
1235{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001236 struct hostapd_data *hapd;
1237
1238 if (wpa_s->ap_iface)
1239 hapd = wpa_s->ap_iface->bss[0];
1240 else if (wpa_s->ifmsh)
1241 hapd = wpa_s->ifmsh->bss[0];
1242 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001243 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001244 return hostapd_ctrl_iface_sta_first(hapd, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001245}
1246
1247
1248int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
1249 char *buf, size_t buflen)
1250{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001251 struct hostapd_data *hapd;
1252
1253 if (wpa_s->ap_iface)
1254 hapd = wpa_s->ap_iface->bss[0];
1255 else if (wpa_s->ifmsh)
1256 hapd = wpa_s->ifmsh->bss[0];
1257 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001258 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001259 return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001260}
1261
1262
1263int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
1264 char *buf, size_t buflen)
1265{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001266 struct hostapd_data *hapd;
1267
1268 if (wpa_s->ap_iface)
1269 hapd = wpa_s->ap_iface->bss[0];
1270 else if (wpa_s->ifmsh)
1271 hapd = wpa_s->ifmsh->bss[0];
1272 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001273 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001274 return hostapd_ctrl_iface_sta_next(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001275}
1276
1277
Dmitry Shmidt04949592012-07-19 12:16:46 -07001278int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1279 const char *txtaddr)
1280{
1281 if (wpa_s->ap_iface == NULL)
1282 return -1;
1283 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1284 txtaddr);
1285}
1286
1287
1288int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1289 const char *txtaddr)
1290{
1291 if (wpa_s->ap_iface == NULL)
1292 return -1;
1293 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1294 txtaddr);
1295}
1296
1297
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001298int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1299 size_t buflen, int verbose)
1300{
1301 char *pos = buf, *end = buf + buflen;
1302 int ret;
1303 struct hostapd_bss_config *conf;
1304
1305 if (wpa_s->ap_iface == NULL)
1306 return -1;
1307
1308 conf = wpa_s->ap_iface->bss[0]->conf;
1309 if (conf->wpa == 0)
1310 return 0;
1311
1312 ret = os_snprintf(pos, end - pos,
1313 "pairwise_cipher=%s\n"
1314 "group_cipher=%s\n"
1315 "key_mgmt=%s\n",
1316 wpa_cipher_txt(conf->rsn_pairwise),
1317 wpa_cipher_txt(conf->wpa_group),
1318 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1319 conf->wpa));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001320 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001321 return pos - buf;
1322 pos += ret;
1323 return pos - buf;
1324}
1325
1326#endif /* CONFIG_CTRL_IFACE */
1327
1328
1329int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1330{
1331 struct hostapd_iface *iface = wpa_s->ap_iface;
1332 struct wpa_ssid *ssid = wpa_s->current_ssid;
1333 struct hostapd_data *hapd;
1334
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001335 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1336 ssid->mode == WPAS_MODE_INFRA ||
1337 ssid->mode == WPAS_MODE_IBSS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001338 return -1;
1339
1340#ifdef CONFIG_P2P
1341 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001342 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001343 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001344 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001345 P2P_GROUP_FORMATION;
1346#endif /* CONFIG_P2P */
1347
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001348 hapd = iface->bss[0];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001349 if (hapd->drv_priv == NULL)
1350 return -1;
1351 ieee802_11_set_beacons(iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001352 hostapd_set_ap_wps_ie(hapd);
1353
1354 return 0;
1355}
1356
1357
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001358int ap_switch_channel(struct wpa_supplicant *wpa_s,
1359 struct csa_settings *settings)
1360{
1361#ifdef NEED_AP_MLME
1362 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1363 return -1;
1364
1365 return hostapd_switch_channel(wpa_s->ap_iface->bss[0], settings);
1366#else /* NEED_AP_MLME */
1367 return -1;
1368#endif /* NEED_AP_MLME */
1369}
1370
1371
Dmitry Shmidt83474442015-04-15 13:47:09 -07001372#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001373int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1374{
1375 struct csa_settings settings;
1376 int ret = hostapd_parse_csa_settings(pos, &settings);
1377
1378 if (ret)
1379 return ret;
1380
1381 return ap_switch_channel(wpa_s, &settings);
1382}
Dmitry Shmidt83474442015-04-15 13:47:09 -07001383#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001384
1385
Dmitry Shmidt04949592012-07-19 12:16:46 -07001386void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001387 int offset, int width, int cf1, int cf2)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001388{
Hai Shalom39bc25d2019-02-06 16:32:13 -08001389 struct hostapd_iface *iface = wpa_s->ap_iface;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001390
Hai Shalom39bc25d2019-02-06 16:32:13 -08001391 if (!iface)
1392 iface = wpa_s->ifmsh;
1393 if (!iface)
1394 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001395 wpa_s->assoc_freq = freq;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001396 if (wpa_s->current_ssid)
1397 wpa_s->current_ssid->frequency = freq;
Hai Shalom39bc25d2019-02-06 16:32:13 -08001398 hostapd_event_ch_switch(iface->bss[0], freq, ht,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001399 offset, width, cf1, cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001400}
1401
1402
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001403int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1404 const u8 *addr)
1405{
1406 struct hostapd_data *hapd;
1407 struct hostapd_bss_config *conf;
1408
1409 if (!wpa_s->ap_iface)
1410 return -1;
1411
1412 if (addr)
1413 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1414 MAC2STR(addr));
1415 else
1416 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1417
1418 hapd = wpa_s->ap_iface->bss[0];
1419 conf = hapd->conf;
1420
1421 os_free(conf->accept_mac);
1422 conf->accept_mac = NULL;
1423 conf->num_accept_mac = 0;
1424 os_free(conf->deny_mac);
1425 conf->deny_mac = NULL;
1426 conf->num_deny_mac = 0;
1427
1428 if (addr == NULL) {
1429 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1430 return 0;
1431 }
1432
1433 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1434 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1435 if (conf->accept_mac == NULL)
1436 return -1;
1437 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1438 conf->num_accept_mac = 1;
1439
1440 return 0;
1441}
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001442
1443
1444#ifdef CONFIG_WPS_NFC
1445int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1446 const struct wpabuf *pw, const u8 *pubkey_hash)
1447{
1448 struct hostapd_data *hapd;
1449 struct wps_context *wps;
1450
1451 if (!wpa_s->ap_iface)
1452 return -1;
1453 hapd = wpa_s->ap_iface->bss[0];
1454 wps = hapd->wps;
1455
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001456 if (wpa_s->p2pdev->conf->wps_nfc_dh_pubkey == NULL ||
1457 wpa_s->p2pdev->conf->wps_nfc_dh_privkey == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001458 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1459 return -1;
1460 }
1461
1462 dh5_free(wps->dh_ctx);
1463 wpabuf_free(wps->dh_pubkey);
1464 wpabuf_free(wps->dh_privkey);
1465 wps->dh_privkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001466 wpa_s->p2pdev->conf->wps_nfc_dh_privkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001467 wps->dh_pubkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001468 wpa_s->p2pdev->conf->wps_nfc_dh_pubkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001469 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1470 wps->dh_ctx = NULL;
1471 wpabuf_free(wps->dh_pubkey);
1472 wps->dh_pubkey = NULL;
1473 wpabuf_free(wps->dh_privkey);
1474 wps->dh_privkey = NULL;
1475 return -1;
1476 }
1477 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1478 if (wps->dh_ctx == NULL)
1479 return -1;
1480
1481 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1482 pw_id,
1483 pw ? wpabuf_head(pw) : NULL,
1484 pw ? wpabuf_len(pw) : 0, 1);
1485}
1486#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001487
1488
Dmitry Shmidt83474442015-04-15 13:47:09 -07001489#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001490int wpas_ap_stop_ap(struct wpa_supplicant *wpa_s)
1491{
1492 struct hostapd_data *hapd;
1493
1494 if (!wpa_s->ap_iface)
1495 return -1;
1496 hapd = wpa_s->ap_iface->bss[0];
1497 return hostapd_ctrl_iface_stop_ap(hapd);
1498}
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001499
1500
Dmitry Shmidte4663042016-04-04 10:07:49 -07001501int wpas_ap_pmksa_cache_list(struct wpa_supplicant *wpa_s, char *buf,
1502 size_t len)
1503{
1504 size_t reply_len = 0, i;
1505 char ap_delimiter[] = "---- AP ----\n";
1506 char mesh_delimiter[] = "---- mesh ----\n";
1507 size_t dlen;
1508
1509 if (wpa_s->ap_iface) {
1510 dlen = os_strlen(ap_delimiter);
1511 if (dlen > len - reply_len)
1512 return reply_len;
1513 os_memcpy(&buf[reply_len], ap_delimiter, dlen);
1514 reply_len += dlen;
1515
1516 for (i = 0; i < wpa_s->ap_iface->num_bss; i++) {
1517 reply_len += hostapd_ctrl_iface_pmksa_list(
1518 wpa_s->ap_iface->bss[i],
1519 &buf[reply_len], len - reply_len);
1520 }
1521 }
1522
1523 if (wpa_s->ifmsh) {
1524 dlen = os_strlen(mesh_delimiter);
1525 if (dlen > len - reply_len)
1526 return reply_len;
1527 os_memcpy(&buf[reply_len], mesh_delimiter, dlen);
1528 reply_len += dlen;
1529
1530 reply_len += hostapd_ctrl_iface_pmksa_list(
1531 wpa_s->ifmsh->bss[0], &buf[reply_len],
1532 len - reply_len);
1533 }
1534
1535 return reply_len;
1536}
1537
1538
1539void wpas_ap_pmksa_cache_flush(struct wpa_supplicant *wpa_s)
1540{
1541 size_t i;
1542
1543 if (wpa_s->ap_iface) {
1544 for (i = 0; i < wpa_s->ap_iface->num_bss; i++)
1545 hostapd_ctrl_iface_pmksa_flush(wpa_s->ap_iface->bss[i]);
1546 }
1547
1548 if (wpa_s->ifmsh)
1549 hostapd_ctrl_iface_pmksa_flush(wpa_s->ifmsh->bss[0]);
1550}
Paul Stewart092955c2017-02-06 09:13:09 -08001551
1552
1553#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
1554#ifdef CONFIG_MESH
1555
1556int wpas_ap_pmksa_cache_list_mesh(struct wpa_supplicant *wpa_s, const u8 *addr,
1557 char *buf, size_t len)
1558{
1559 return hostapd_ctrl_iface_pmksa_list_mesh(wpa_s->ifmsh->bss[0], addr,
1560 &buf[0], len);
1561}
1562
1563
1564int wpas_ap_pmksa_cache_add_external(struct wpa_supplicant *wpa_s, char *cmd)
1565{
1566 struct external_pmksa_cache *entry;
1567 void *pmksa_cache;
1568
1569 pmksa_cache = hostapd_ctrl_iface_pmksa_create_entry(wpa_s->own_addr,
1570 cmd);
1571 if (!pmksa_cache)
1572 return -1;
1573
1574 entry = os_zalloc(sizeof(struct external_pmksa_cache));
1575 if (!entry)
1576 return -1;
1577
1578 entry->pmksa_cache = pmksa_cache;
1579
1580 dl_list_add(&wpa_s->mesh_external_pmksa_cache, &entry->list);
1581
1582 return 0;
1583}
1584
1585#endif /* CONFIG_MESH */
1586#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
1587
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001588#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte4663042016-04-04 10:07:49 -07001589
1590
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001591#ifdef NEED_AP_MLME
Roshan Pius3a1667e2018-07-03 15:17:14 -07001592void wpas_ap_event_dfs_radar_detected(struct wpa_supplicant *wpa_s,
1593 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001594{
Hai Shalom39bc25d2019-02-06 16:32:13 -08001595 struct hostapd_iface *iface = wpa_s->ap_iface;
1596
1597 if (!iface)
1598 iface = wpa_s->ifmsh;
1599 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001600 return;
1601 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Hai Shalom39bc25d2019-02-06 16:32:13 -08001602 hostapd_dfs_radar_detected(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001603 radar->ht_enabled, radar->chan_offset,
1604 radar->chan_width,
1605 radar->cf1, radar->cf2);
1606}
1607
1608
Roshan Pius3a1667e2018-07-03 15:17:14 -07001609void wpas_ap_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
1610 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001611{
Hai Shalom39bc25d2019-02-06 16:32:13 -08001612 struct hostapd_iface *iface = wpa_s->ap_iface;
1613
1614 if (!iface)
1615 iface = wpa_s->ifmsh;
1616 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001617 return;
1618 wpa_printf(MSG_DEBUG, "DFS CAC started on %d MHz", radar->freq);
Hai Shalom39bc25d2019-02-06 16:32:13 -08001619 hostapd_dfs_start_cac(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001620 radar->ht_enabled, radar->chan_offset,
1621 radar->chan_width, radar->cf1, radar->cf2);
1622}
1623
1624
Roshan Pius3a1667e2018-07-03 15:17:14 -07001625void wpas_ap_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
1626 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001627{
Hai Shalom39bc25d2019-02-06 16:32:13 -08001628 struct hostapd_iface *iface = wpa_s->ap_iface;
1629
1630 if (!iface)
1631 iface = wpa_s->ifmsh;
1632 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001633 return;
1634 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Hai Shalom39bc25d2019-02-06 16:32:13 -08001635 hostapd_dfs_complete_cac(iface, 1, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001636 radar->ht_enabled, radar->chan_offset,
1637 radar->chan_width, radar->cf1, radar->cf2);
1638}
1639
1640
Roshan Pius3a1667e2018-07-03 15:17:14 -07001641void wpas_ap_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
1642 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001643{
Hai Shalom39bc25d2019-02-06 16:32:13 -08001644 struct hostapd_iface *iface = wpa_s->ap_iface;
1645
1646 if (!iface)
1647 iface = wpa_s->ifmsh;
1648 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001649 return;
1650 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Hai Shalom39bc25d2019-02-06 16:32:13 -08001651 hostapd_dfs_complete_cac(iface, 0, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001652 radar->ht_enabled, radar->chan_offset,
1653 radar->chan_width, radar->cf1, radar->cf2);
1654}
1655
1656
Roshan Pius3a1667e2018-07-03 15:17:14 -07001657void wpas_ap_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s,
1658 struct dfs_event *radar)
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001659{
Hai Shalom39bc25d2019-02-06 16:32:13 -08001660 struct hostapd_iface *iface = wpa_s->ap_iface;
1661
1662 if (!iface)
1663 iface = wpa_s->ifmsh;
1664 if (!iface || !iface->bss[0])
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001665 return;
1666 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Hai Shalom39bc25d2019-02-06 16:32:13 -08001667 hostapd_dfs_nop_finished(iface, radar->freq,
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001668 radar->ht_enabled, radar->chan_offset,
1669 radar->chan_width, radar->cf1, radar->cf2);
1670}
1671#endif /* NEED_AP_MLME */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001672
1673
1674void ap_periodic(struct wpa_supplicant *wpa_s)
1675{
1676 if (wpa_s->ap_iface)
1677 hostapd_periodic_iface(wpa_s->ap_iface);
1678}