blob: 1721d6a6244166a0a6fd0357672104277a1435ce [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,
49 struct hostapd_config *conf,
50 struct hostapd_hw_modes *mode)
51{
Dmitry Shmidt21de2142014-04-08 10:50:52 -070052#ifdef CONFIG_P2P
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070053 u8 center_chan = 0;
54 u8 channel = conf->channel;
55
56 if (!conf->secondary_channel)
57 goto no_vht;
58
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080059 switch (conf->vht_oper_chwidth) {
60 case VHT_CHANWIDTH_80MHZ:
61 case VHT_CHANWIDTH_80P80MHZ:
62 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel);
63 break;
64 case VHT_CHANWIDTH_160MHZ:
65 center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel);
66 break;
67 default:
68 /*
69 * conf->vht_oper_chwidth might not be set for non-P2P GO cases,
70 * try oper_cwidth 160 MHz first then VHT 80 MHz, if 160 MHz is
71 * not supported.
72 */
73 conf->vht_oper_chwidth = VHT_CHANWIDTH_160MHZ;
74 center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel);
75 if (!center_chan) {
76 conf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ;
77 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode,
78 channel);
79 }
80 break;
81 }
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070082 if (!center_chan)
83 goto no_vht;
84
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070085 conf->vht_oper_centr_freq_seg0_idx = center_chan;
86 return;
87
88no_vht:
89 conf->vht_oper_centr_freq_seg0_idx =
90 channel + conf->secondary_channel * 2;
Dmitry Shmidt21de2142014-04-08 10:50:52 -070091#else /* CONFIG_P2P */
92 conf->vht_oper_centr_freq_seg0_idx =
93 conf->channel + conf->secondary_channel * 2;
94#endif /* CONFIG_P2P */
Dmitry Shmidtb97e4282016-02-08 10:16:07 -080095 conf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070096}
97#endif /* CONFIG_IEEE80211N */
98
99
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800100int wpa_supplicant_conf_ap_ht(struct wpa_supplicant *wpa_s,
101 struct wpa_ssid *ssid,
102 struct hostapd_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700103{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800104 conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency,
105 &conf->channel);
106
107 if (conf->hw_mode == NUM_HOSTAPD_MODES) {
108 wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
109 ssid->frequency);
110 return -1;
111 }
112
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700113 /* TODO: enable HT40 if driver supports it;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700114 * drop to 11b if driver does not support 11g */
115
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700116#ifdef CONFIG_IEEE80211N
117 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800118 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
119 * and a mask of allowed capabilities within conf->ht_capab.
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700120 * Using default config settings for: conf->ht_op_mode_fixed,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800121 * conf->secondary_channel, conf->require_ht
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700122 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800123 if (wpa_s->hw.modes) {
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700124 struct hostapd_hw_modes *mode = NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700125 int i, no_ht = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800126 for (i = 0; i < wpa_s->hw.num_modes; i++) {
127 if (wpa_s->hw.modes[i].mode == conf->hw_mode) {
128 mode = &wpa_s->hw.modes[i];
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700129 break;
130 }
131 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700132
133#ifdef CONFIG_HT_OVERRIDES
134 if (ssid->disable_ht) {
135 conf->ieee80211n = 0;
136 conf->ht_capab = 0;
137 no_ht = 1;
138 }
139#endif /* CONFIG_HT_OVERRIDES */
140
141 if (!no_ht && mode && mode->ht_capab) {
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700142 conf->ieee80211n = 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700143#ifdef CONFIG_P2P
144 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
145 (mode->ht_capab &
146 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
147 ssid->ht40)
148 conf->secondary_channel =
149 wpas_p2p_get_ht40_mode(wpa_s, mode,
150 conf->channel);
151 if (conf->secondary_channel)
152 conf->ht_capab |=
153 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
154#endif /* CONFIG_P2P */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800155
156 /*
157 * white-list capabilities that won't cause issues
158 * to connecting stations, while leaving the current
159 * capabilities intact (currently disabled SMPS).
160 */
161 conf->ht_capab |= mode->ht_capab &
162 (HT_CAP_INFO_GREEN_FIELD |
163 HT_CAP_INFO_SHORT_GI20MHZ |
164 HT_CAP_INFO_SHORT_GI40MHZ |
165 HT_CAP_INFO_RX_STBC_MASK |
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800166 HT_CAP_INFO_TX_STBC |
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800167 HT_CAP_INFO_MAX_AMSDU_SIZE);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700168
169 if (mode->vht_capab && ssid->vht) {
170 conf->ieee80211ac = 1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800171 conf->vht_capab |= mode->vht_capab;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700172 wpas_conf_ap_vht(wpa_s, conf, mode);
173 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800174 }
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700175 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800176
177 if (conf->secondary_channel) {
178 struct wpa_supplicant *iface;
179
180 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
181 {
182 if (iface == wpa_s ||
183 iface->wpa_state < WPA_AUTHENTICATING ||
184 (int) iface->assoc_freq != ssid->frequency)
185 continue;
186
187 /*
188 * Do not allow 40 MHz co-ex PRI/SEC switch to force us
189 * to change our PRI channel since we have an existing,
190 * concurrent connection on that channel and doing
191 * multi-channel concurrency is likely to cause more
192 * harm than using different PRI/SEC selection in
193 * environment with multiple BSSes on these two channels
194 * with mixed 20 MHz or PRI channel selection.
195 */
196 conf->no_pri_sec_switch = 1;
197 }
198 }
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700199#endif /* CONFIG_IEEE80211N */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800200
201 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800202}
203
204
205static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
206 struct wpa_ssid *ssid,
207 struct hostapd_config *conf)
208{
209 struct hostapd_bss_config *bss = conf->bss[0];
210
211 conf->driver = wpa_s->driver;
212
213 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
214
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800215 if (wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800216 return -1;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700217
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700218 if (ssid->pbss > 1) {
219 wpa_printf(MSG_ERROR, "Invalid pbss value(%d) for AP mode",
220 ssid->pbss);
221 return -1;
222 }
223 bss->pbss = ssid->pbss;
224
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800225#ifdef CONFIG_ACS
226 if (ssid->acs) {
227 /* Setting channel to 0 in order to enable ACS */
228 conf->channel = 0;
229 wpa_printf(MSG_DEBUG, "Use automatic channel selection");
230 }
231#endif /* CONFIG_ACS */
232
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800233 if (ieee80211_is_dfs(ssid->frequency) && wpa_s->conf->country[0]) {
234 conf->ieee80211h = 1;
235 conf->ieee80211d = 1;
236 conf->country[0] = wpa_s->conf->country[0];
237 conf->country[1] = wpa_s->conf->country[1];
Paul Stewart092955c2017-02-06 09:13:09 -0800238 conf->country[2] = ' ';
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800239 }
240
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700241#ifdef CONFIG_P2P
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700242 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
243 (ssid->mode == WPAS_MODE_P2P_GO ||
244 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700245 /* Remove 802.11b rates from supported and basic rate sets */
246 int *list = os_malloc(4 * sizeof(int));
247 if (list) {
248 list[0] = 60;
249 list[1] = 120;
250 list[2] = 240;
251 list[3] = -1;
252 }
253 conf->basic_rates = list;
254
255 list = os_malloc(9 * sizeof(int));
256 if (list) {
257 list[0] = 60;
258 list[1] = 90;
259 list[2] = 120;
260 list[3] = 180;
261 list[4] = 240;
262 list[5] = 360;
263 list[6] = 480;
264 list[7] = 540;
265 list[8] = -1;
266 }
267 conf->supported_rates = list;
268 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800269
270 bss->isolate = !wpa_s->conf->p2p_intra_bss;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700271 bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800272
273 if (ssid->p2p_group) {
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800274 os_memcpy(bss->ip_addr_go, wpa_s->p2pdev->conf->ip_addr_go, 4);
275 os_memcpy(bss->ip_addr_mask, wpa_s->p2pdev->conf->ip_addr_mask,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800276 4);
277 os_memcpy(bss->ip_addr_start,
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800278 wpa_s->p2pdev->conf->ip_addr_start, 4);
279 os_memcpy(bss->ip_addr_end, wpa_s->p2pdev->conf->ip_addr_end,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800280 4);
281 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700282#endif /* CONFIG_P2P */
283
284 if (ssid->ssid_len == 0) {
285 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
286 return -1;
287 }
288 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700289 bss->ssid.ssid_len = ssid->ssid_len;
290 bss->ssid.ssid_set = 1;
291
Dmitry Shmidt04949592012-07-19 12:16:46 -0700292 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
293
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800294 if (ssid->auth_alg)
295 bss->auth_algs = ssid->auth_alg;
296
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700297 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
298 bss->wpa = ssid->proto;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700299 if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
300 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
301 else
302 bss->wpa_key_mgmt = ssid->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700303 bss->wpa_pairwise = ssid->pairwise_cipher;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800304 if (ssid->psk_set) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800305 bin_clear_free(bss->ssid.wpa_psk, sizeof(*bss->ssid.wpa_psk));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700306 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
307 if (bss->ssid.wpa_psk == NULL)
308 return -1;
309 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
310 bss->ssid.wpa_psk->group = 1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700311 bss->ssid.wpa_psk_set = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800312 } else if (ssid->passphrase) {
313 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800314 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
315 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
316 struct hostapd_wep_keys *wep = &bss->ssid.wep;
317 int i;
318 for (i = 0; i < NUM_WEP_KEYS; i++) {
319 if (ssid->wep_key_len[i] == 0)
320 continue;
321 wep->key[i] = os_malloc(ssid->wep_key_len[i]);
322 if (wep->key[i] == NULL)
323 return -1;
324 os_memcpy(wep->key[i], ssid->wep_key[i],
325 ssid->wep_key_len[i]);
326 wep->len[i] = ssid->wep_key_len[i];
327 }
328 wep->idx = ssid->wep_tx_keyidx;
329 wep->keys_set = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700330 }
331
Dmitry Shmidt04949592012-07-19 12:16:46 -0700332 if (ssid->ap_max_inactivity)
333 bss->ap_max_inactivity = ssid->ap_max_inactivity;
334
335 if (ssid->dtim_period)
336 bss->dtim_period = ssid->dtim_period;
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -0800337 else if (wpa_s->conf->dtim_period)
338 bss->dtim_period = wpa_s->conf->dtim_period;
339
340 if (ssid->beacon_int)
341 conf->beacon_int = ssid->beacon_int;
342 else if (wpa_s->conf->beacon_int)
343 conf->beacon_int = wpa_s->conf->beacon_int;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700344
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800345#ifdef CONFIG_P2P
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800346 if (ssid->mode == WPAS_MODE_P2P_GO ||
347 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
348 if (wpa_s->conf->p2p_go_ctwindow > conf->beacon_int) {
349 wpa_printf(MSG_INFO,
350 "CTWindow (%d) is bigger than beacon interval (%d) - avoid configuring it",
351 wpa_s->conf->p2p_go_ctwindow,
352 conf->beacon_int);
353 conf->p2p_go_ctwindow = 0;
354 } else {
355 conf->p2p_go_ctwindow = wpa_s->conf->p2p_go_ctwindow;
356 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800357 }
358#endif /* CONFIG_P2P */
359
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800360 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
361 bss->rsn_pairwise = bss->wpa_pairwise;
362 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
363 bss->rsn_pairwise);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700364
365 if (bss->wpa && bss->ieee802_1x)
366 bss->ssid.security_policy = SECURITY_WPA;
367 else if (bss->wpa)
368 bss->ssid.security_policy = SECURITY_WPA_PSK;
369 else if (bss->ieee802_1x) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800370 int cipher = WPA_CIPHER_NONE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700371 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
372 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800373 if (bss->default_wep_key_len)
374 cipher = bss->default_wep_key_len >= 13 ?
375 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
376 bss->wpa_group = cipher;
377 bss->wpa_pairwise = cipher;
378 bss->rsn_pairwise = cipher;
379 } else if (bss->ssid.wep.keys_set) {
380 int cipher = WPA_CIPHER_WEP40;
381 if (bss->ssid.wep.len[0] >= 13)
382 cipher = WPA_CIPHER_WEP104;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700383 bss->ssid.security_policy = SECURITY_STATIC_WEP;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800384 bss->wpa_group = cipher;
385 bss->wpa_pairwise = cipher;
386 bss->rsn_pairwise = cipher;
387 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700388 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800389 bss->wpa_group = WPA_CIPHER_NONE;
390 bss->wpa_pairwise = WPA_CIPHER_NONE;
391 bss->rsn_pairwise = WPA_CIPHER_NONE;
392 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700393
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700394 if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
395 (bss->wpa_group == WPA_CIPHER_CCMP ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800396 bss->wpa_group == WPA_CIPHER_GCMP ||
397 bss->wpa_group == WPA_CIPHER_CCMP_256 ||
398 bss->wpa_group == WPA_CIPHER_GCMP_256)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700399 /*
400 * Strong ciphers do not need frequent rekeying, so increase
401 * the default GTK rekeying period to 24 hours.
402 */
403 bss->wpa_group_rekey = 86400;
404 }
405
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700406#ifdef CONFIG_IEEE80211W
407 if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT)
408 bss->ieee80211w = ssid->ieee80211w;
409#endif /* CONFIG_IEEE80211W */
410
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700411#ifdef CONFIG_WPS
412 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800413 * Enable WPS by default for open and WPA/WPA2-Personal network, but
414 * require user interaction to actually use it. Only the internal
415 * Registrar is supported.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700416 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800417 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
418 bss->ssid.security_policy != SECURITY_PLAINTEXT)
419 goto no_wps;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800420 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800421 (!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ||
422 !(bss->wpa & 2)))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800423 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
424 * configuration */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700425 if (ssid->wps_disabled)
426 goto no_wps;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700427 bss->eap_server = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700428
429 if (!ssid->ignore_broadcast_ssid)
430 bss->wps_state = 2;
431
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700432 bss->ap_setup_locked = 2;
433 if (wpa_s->conf->config_methods)
434 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
435 os_memcpy(bss->device_type, wpa_s->conf->device_type,
436 WPS_DEV_TYPE_LEN);
437 if (wpa_s->conf->device_name) {
438 bss->device_name = os_strdup(wpa_s->conf->device_name);
439 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
440 }
441 if (wpa_s->conf->manufacturer)
442 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
443 if (wpa_s->conf->model_name)
444 bss->model_name = os_strdup(wpa_s->conf->model_name);
445 if (wpa_s->conf->model_number)
446 bss->model_number = os_strdup(wpa_s->conf->model_number);
447 if (wpa_s->conf->serial_number)
448 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
449 if (is_nil_uuid(wpa_s->conf->uuid))
450 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
451 else
452 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
453 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700454 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -0700455 if (ssid->eap.fragment_size != DEFAULT_FRAGMENT_SIZE)
456 bss->fragment_size = ssid->eap.fragment_size;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800457no_wps:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700458#endif /* CONFIG_WPS */
459
460 if (wpa_s->max_stations &&
461 wpa_s->max_stations < wpa_s->conf->max_num_sta)
462 bss->max_num_sta = wpa_s->max_stations;
463 else
464 bss->max_num_sta = wpa_s->conf->max_num_sta;
465
466 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
467
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700468 if (wpa_s->conf->ap_vendor_elements) {
469 bss->vendor_elements =
470 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
471 }
472
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700473 bss->ftm_responder = wpa_s->conf->ftm_responder;
474 bss->ftm_initiator = wpa_s->conf->ftm_initiator;
475
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700476 return 0;
477}
478
479
480static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
481{
482#ifdef CONFIG_P2P
483 struct wpa_supplicant *wpa_s = ctx;
484 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700485
486 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700487 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700488 return;
Dmitry Shmidt18463232014-01-24 12:29:41 -0800489 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
490 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700491 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
492 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700493 buf + IEEE80211_HDRLEN + 1,
494 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700495#endif /* CONFIG_P2P */
496}
497
498
499static void ap_wps_event_cb(void *ctx, enum wps_event event,
500 union wps_event_data *data)
501{
502#ifdef CONFIG_P2P
503 struct wpa_supplicant *wpa_s = ctx;
504
Jouni Malinen75ecf522011-06-27 15:19:46 -0700505 if (event == WPS_EV_FAIL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700506 struct wps_event_fail *fail = &data->fail;
507
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800508 if (wpa_s->p2pdev && wpa_s->p2pdev != wpa_s &&
Jouni Malinen75ecf522011-06-27 15:19:46 -0700509 wpa_s == wpa_s->global->p2p_group_formation) {
510 /*
511 * src/ap/wps_hostapd.c has already sent this on the
512 * main interface, so only send on the parent interface
513 * here if needed.
514 */
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800515 wpa_msg(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_FAIL
Jouni Malinen75ecf522011-06-27 15:19:46 -0700516 "msg=%d config_error=%d",
517 fail->msg, fail->config_error);
518 }
519 wpas_p2p_wps_failed(wpa_s, fail);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700520 }
521#endif /* CONFIG_P2P */
522}
523
524
525static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800526 int authorized, const u8 *p2p_dev_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700527{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800528 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700529}
530
531
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700532#ifdef CONFIG_P2P
533static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
534 const u8 *psk, size_t psk_len)
535{
536
537 struct wpa_supplicant *wpa_s = ctx;
538 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
539 return;
540 wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
541}
542#endif /* CONFIG_P2P */
543
544
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700545static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
546{
547#ifdef CONFIG_P2P
548 struct wpa_supplicant *wpa_s = ctx;
549 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700550
551 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700552 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700553 return -1;
554 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
555 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700556 buf + IEEE80211_HDRLEN + 1,
557 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700558#endif /* CONFIG_P2P */
559 return 0;
560}
561
562
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800563static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700564 const u8 *bssid, const u8 *ie, size_t ie_len,
565 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700566{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700567 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700568 unsigned int freq = 0;
569
570 if (wpa_s->ap_iface)
571 freq = wpa_s->ap_iface->freq;
572
Dmitry Shmidt04949592012-07-19 12:16:46 -0700573 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700574 freq, ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700575}
576
577
578static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
579 const u8 *uuid_e)
580{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700581 struct wpa_supplicant *wpa_s = ctx;
582 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700583}
584
585
586static void wpas_ap_configured_cb(void *ctx)
587{
588 struct wpa_supplicant *wpa_s = ctx;
589
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800590#ifdef CONFIG_ACS
591 if (wpa_s->current_ssid && wpa_s->current_ssid->acs)
592 wpa_s->assoc_freq = wpa_s->ap_iface->freq;
593#endif /* CONFIG_ACS */
594
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700595 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
596
597 if (wpa_s->ap_configured_cb)
598 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
599 wpa_s->ap_configured_cb_data);
600}
601
602
603int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
604 struct wpa_ssid *ssid)
605{
606 struct wpa_driver_associate_params params;
607 struct hostapd_iface *hapd_iface;
608 struct hostapd_config *conf;
609 size_t i;
610
611 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
612 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
613 return -1;
614 }
615
616 wpa_supplicant_ap_deinit(wpa_s);
617
618 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
619 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
620
621 os_memset(&params, 0, sizeof(params));
622 params.ssid = ssid->ssid;
623 params.ssid_len = ssid->ssid_len;
624 switch (ssid->mode) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700625 case WPAS_MODE_AP:
626 case WPAS_MODE_P2P_GO:
627 case WPAS_MODE_P2P_GROUP_FORMATION:
628 params.mode = IEEE80211_MODE_AP;
629 break;
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800630 default:
631 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700632 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700633 if (ssid->frequency == 0)
634 ssid->frequency = 2462; /* default channel 11 */
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700635 params.freq.freq = ssid->frequency;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700636
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800637 params.wpa_proto = ssid->proto;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700638 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
639 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
640 else
641 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800642 params.key_mgmt_suite = wpa_s->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700643
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800644 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
645 1);
646 if (wpa_s->pairwise_cipher < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700647 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
648 "cipher.");
649 return -1;
650 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800651 params.pairwise_suite = wpa_s->pairwise_cipher;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700652 params.group_suite = params.pairwise_suite;
653
654#ifdef CONFIG_P2P
655 if (ssid->mode == WPAS_MODE_P2P_GO ||
656 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
657 params.p2p = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700658#endif /* CONFIG_P2P */
659
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800660 if (wpa_s->p2pdev->set_ap_uapsd)
661 params.uapsd = wpa_s->p2pdev->ap_uapsd;
Dmitry Shmidtec58b162014-02-19 12:44:18 -0800662 else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
663 params.uapsd = 1; /* mandatory for P2P GO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700664 else
665 params.uapsd = -1;
666
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800667 if (ieee80211_is_dfs(params.freq.freq))
668 params.freq.freq = 0; /* set channel after CAC */
669
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700670 if (params.p2p)
671 wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_GO);
672 else
673 wpa_drv_get_ext_capa(wpa_s, WPA_IF_AP_BSS);
674
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700675 if (wpa_drv_associate(wpa_s, &params) < 0) {
676 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
677 return -1;
678 }
679
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700680 wpa_s->ap_iface = hapd_iface = hostapd_alloc_iface();
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700681 if (hapd_iface == NULL)
682 return -1;
683 hapd_iface->owner = wpa_s;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800684 hapd_iface->drv_flags = wpa_s->drv_flags;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800685 hapd_iface->smps_modes = wpa_s->drv_smps_modes;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800686 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700687 hapd_iface->extended_capa = wpa_s->extended_capa;
688 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
689 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700690
691 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
692 if (conf == NULL) {
693 wpa_supplicant_ap_deinit(wpa_s);
694 return -1;
695 }
696
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800697 /* Use the maximum oper channel width if it's given. */
698 if (ssid->max_oper_chwidth)
699 conf->vht_oper_chwidth = ssid->max_oper_chwidth;
700
701 ieee80211_freq_to_chan(ssid->vht_center_freq2,
702 &conf->vht_oper_centr_freq_seg1_idx);
703
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700704 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
705 wpa_s->conf->wmm_ac_params,
706 sizeof(wpa_s->conf->wmm_ac_params));
707
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800708 if (params.uapsd > 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800709 conf->bss[0]->wmm_enabled = 1;
710 conf->bss[0]->wmm_uapsd = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800711 }
712
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700713 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
714 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
715 wpa_supplicant_ap_deinit(wpa_s);
716 return -1;
717 }
718
719#ifdef CONFIG_P2P
720 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800721 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700722 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800723 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700724 P2P_GROUP_FORMATION;
725#endif /* CONFIG_P2P */
726
727 hapd_iface->num_bss = conf->num_bss;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700728 hapd_iface->bss = os_calloc(conf->num_bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700729 sizeof(struct hostapd_data *));
730 if (hapd_iface->bss == NULL) {
731 wpa_supplicant_ap_deinit(wpa_s);
732 return -1;
733 }
734
735 for (i = 0; i < conf->num_bss; i++) {
736 hapd_iface->bss[i] =
737 hostapd_alloc_bss_data(hapd_iface, conf,
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800738 conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700739 if (hapd_iface->bss[i] == NULL) {
740 wpa_supplicant_ap_deinit(wpa_s);
741 return -1;
742 }
743
744 hapd_iface->bss[i]->msg_ctx = wpa_s;
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800745 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->p2pdev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700746 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
747 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
748 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
749 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
750 hostapd_register_probereq_cb(hapd_iface->bss[i],
751 ap_probe_req_rx, wpa_s);
752 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
753 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
754 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
755 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
756 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
757 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
758#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700759 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
760 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700761 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700762 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
763 ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700764#endif /* CONFIG_P2P */
765 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
766 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800767#ifdef CONFIG_TESTING_OPTIONS
768 hapd_iface->bss[i]->ext_eapol_frame_io =
769 wpa_s->ext_eapol_frame_io;
770#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700771 }
772
773 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
774 hapd_iface->bss[0]->driver = wpa_s->driver;
775 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
776
777 wpa_s->current_ssid = ssid;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700778 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700779 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
780 wpa_s->assoc_freq = ssid->frequency;
781
782 if (hostapd_setup_interface(wpa_s->ap_iface)) {
783 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
784 wpa_supplicant_ap_deinit(wpa_s);
785 return -1;
786 }
787
788 return 0;
789}
790
791
792void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
793{
794#ifdef CONFIG_WPS
795 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
796#endif /* CONFIG_WPS */
797
798 if (wpa_s->ap_iface == NULL)
799 return;
800
801 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700802 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700803 wpa_s->assoc_freq = 0;
Dmitry Shmidt43cb5782014-06-16 16:23:22 -0700804 wpas_p2p_ap_deinit(wpa_s);
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800805 wpa_s->ap_iface->driver_ap_teardown =
806 !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
807
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700808 hostapd_interface_deinit(wpa_s->ap_iface);
809 hostapd_interface_free(wpa_s->ap_iface);
810 wpa_s->ap_iface = NULL;
811 wpa_drv_deinit_ap(wpa_s);
Dmitry Shmidtf73259c2015-03-17 11:00:54 -0700812 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
813 " reason=%d locally_generated=1",
814 MAC2STR(wpa_s->own_addr), WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700815}
816
817
818void ap_tx_status(void *ctx, const u8 *addr,
819 const u8 *buf, size_t len, int ack)
820{
821#ifdef NEED_AP_MLME
822 struct wpa_supplicant *wpa_s = ctx;
823 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
824#endif /* NEED_AP_MLME */
825}
826
827
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800828void ap_eapol_tx_status(void *ctx, const u8 *dst,
829 const u8 *data, size_t len, int ack)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700830{
831#ifdef NEED_AP_MLME
832 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800833 if (!wpa_s->ap_iface)
834 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800835 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
836#endif /* NEED_AP_MLME */
837}
838
839
840void ap_client_poll_ok(void *ctx, const u8 *addr)
841{
842#ifdef NEED_AP_MLME
843 struct wpa_supplicant *wpa_s = ctx;
844 if (wpa_s->ap_iface)
845 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
846#endif /* NEED_AP_MLME */
847}
848
849
850void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
851{
852#ifdef NEED_AP_MLME
853 struct wpa_supplicant *wpa_s = ctx;
854 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700855#endif /* NEED_AP_MLME */
856}
857
858
859void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
860{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800861#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700862 struct wpa_supplicant *wpa_s = ctx;
863 struct hostapd_frame_info fi;
864 os_memset(&fi, 0, sizeof(fi));
865 fi.datarate = rx_mgmt->datarate;
866 fi.ssi_signal = rx_mgmt->ssi_signal;
867 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
868 rx_mgmt->frame_len, &fi);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800869#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700870}
871
872
873void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
874{
875#ifdef NEED_AP_MLME
876 struct wpa_supplicant *wpa_s = ctx;
877 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
878#endif /* NEED_AP_MLME */
879}
880
881
882void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
883 const u8 *src_addr, const u8 *buf, size_t len)
884{
885 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
886}
887
888
889#ifdef CONFIG_WPS
890
891int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
892 const u8 *p2p_dev_addr)
893{
894 if (!wpa_s->ap_iface)
895 return -1;
896 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
897 p2p_dev_addr);
898}
899
900
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700901int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
902{
903 struct wps_registrar *reg;
904 int reg_sel = 0, wps_sta = 0;
905
906 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
907 return -1;
908
909 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
910 reg_sel = wps_registrar_wps_cancel(reg);
911 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
Dmitry Shmidt04949592012-07-19 12:16:46 -0700912 ap_sta_wps_cancel, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700913
914 if (!reg_sel && !wps_sta) {
915 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
916 "time");
917 return -1;
918 }
919
920 /*
921 * There are 2 cases to return wps cancel as success:
922 * 1. When wps cancel was initiated but no connection has been
923 * established with client yet.
924 * 2. Client is in the middle of exchanging WPS messages.
925 */
926
927 return 0;
928}
929
930
931int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800932 const char *pin, char *buf, size_t buflen,
933 int timeout)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700934{
935 int ret, ret_len = 0;
936
937 if (!wpa_s->ap_iface)
938 return -1;
939
940 if (pin == NULL) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800941 unsigned int rpin;
942
943 if (wps_generate_pin(&rpin) < 0)
944 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800945 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800946 if (os_snprintf_error(buflen, ret_len))
947 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700948 pin = buf;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800949 } else if (buf) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700950 ret_len = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800951 if (os_snprintf_error(buflen, ret_len))
952 return -1;
953 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700954
955 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800956 timeout);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700957 if (ret)
958 return -1;
959 return ret_len;
960}
961
962
963static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
964{
965 struct wpa_supplicant *wpa_s = eloop_data;
966 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
967 wpas_wps_ap_pin_disable(wpa_s);
968}
969
970
971static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
972{
973 struct hostapd_data *hapd;
974
975 if (wpa_s->ap_iface == NULL)
976 return;
977 hapd = wpa_s->ap_iface->bss[0];
978 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
979 hapd->ap_pin_failures = 0;
980 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
981 if (timeout > 0)
982 eloop_register_timeout(timeout, 0,
983 wpas_wps_ap_pin_timeout, wpa_s, NULL);
984}
985
986
987void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
988{
989 struct hostapd_data *hapd;
990
991 if (wpa_s->ap_iface == NULL)
992 return;
993 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
994 hapd = wpa_s->ap_iface->bss[0];
995 os_free(hapd->conf->ap_pin);
996 hapd->conf->ap_pin = NULL;
997 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
998}
999
1000
1001const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
1002{
1003 struct hostapd_data *hapd;
1004 unsigned int pin;
1005 char pin_txt[9];
1006
1007 if (wpa_s->ap_iface == NULL)
1008 return NULL;
1009 hapd = wpa_s->ap_iface->bss[0];
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001010 if (wps_generate_pin(&pin) < 0)
1011 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001012 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001013 os_free(hapd->conf->ap_pin);
1014 hapd->conf->ap_pin = os_strdup(pin_txt);
1015 if (hapd->conf->ap_pin == NULL)
1016 return NULL;
1017 wpas_wps_ap_pin_enable(wpa_s, timeout);
1018
1019 return hapd->conf->ap_pin;
1020}
1021
1022
1023const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
1024{
1025 struct hostapd_data *hapd;
1026 if (wpa_s->ap_iface == NULL)
1027 return NULL;
1028 hapd = wpa_s->ap_iface->bss[0];
1029 return hapd->conf->ap_pin;
1030}
1031
1032
1033int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
1034 int timeout)
1035{
1036 struct hostapd_data *hapd;
1037 char pin_txt[9];
1038 int ret;
1039
1040 if (wpa_s->ap_iface == NULL)
1041 return -1;
1042 hapd = wpa_s->ap_iface->bss[0];
1043 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001044 if (os_snprintf_error(sizeof(pin_txt), ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001045 return -1;
1046 os_free(hapd->conf->ap_pin);
1047 hapd->conf->ap_pin = os_strdup(pin_txt);
1048 if (hapd->conf->ap_pin == NULL)
1049 return -1;
1050 wpas_wps_ap_pin_enable(wpa_s, timeout);
1051
1052 return 0;
1053}
1054
1055
1056void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
1057{
1058 struct hostapd_data *hapd;
1059
1060 if (wpa_s->ap_iface == NULL)
1061 return;
1062 hapd = wpa_s->ap_iface->bss[0];
1063
1064 /*
1065 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
1066 * PIN if this happens multiple times to slow down brute force attacks.
1067 */
1068 hapd->ap_pin_failures++;
1069 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
1070 hapd->ap_pin_failures);
1071 if (hapd->ap_pin_failures < 3)
1072 return;
1073
1074 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
1075 hapd->ap_pin_failures = 0;
1076 os_free(hapd->conf->ap_pin);
1077 hapd->conf->ap_pin = NULL;
1078}
1079
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001080
1081#ifdef CONFIG_WPS_NFC
1082
1083struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
1084 int ndef)
1085{
1086 struct hostapd_data *hapd;
1087
1088 if (wpa_s->ap_iface == NULL)
1089 return NULL;
1090 hapd = wpa_s->ap_iface->bss[0];
1091 return hostapd_wps_nfc_config_token(hapd, ndef);
1092}
1093
1094
1095struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
1096 int ndef)
1097{
1098 struct hostapd_data *hapd;
1099
1100 if (wpa_s->ap_iface == NULL)
1101 return NULL;
1102 hapd = wpa_s->ap_iface->bss[0];
1103 return hostapd_wps_nfc_hs_cr(hapd, ndef);
1104}
1105
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001106
1107int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
1108 const struct wpabuf *req,
1109 const struct wpabuf *sel)
1110{
1111 struct hostapd_data *hapd;
1112
1113 if (wpa_s->ap_iface == NULL)
1114 return -1;
1115 hapd = wpa_s->ap_iface->bss[0];
1116 return hostapd_wps_nfc_report_handover(hapd, req, sel);
1117}
1118
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001119#endif /* CONFIG_WPS_NFC */
1120
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001121#endif /* CONFIG_WPS */
1122
1123
1124#ifdef CONFIG_CTRL_IFACE
1125
1126int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
1127 char *buf, size_t buflen)
1128{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001129 struct hostapd_data *hapd;
1130
1131 if (wpa_s->ap_iface)
1132 hapd = wpa_s->ap_iface->bss[0];
1133 else if (wpa_s->ifmsh)
1134 hapd = wpa_s->ifmsh->bss[0];
1135 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001136 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001137 return hostapd_ctrl_iface_sta_first(hapd, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001138}
1139
1140
1141int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
1142 char *buf, size_t buflen)
1143{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001144 struct hostapd_data *hapd;
1145
1146 if (wpa_s->ap_iface)
1147 hapd = wpa_s->ap_iface->bss[0];
1148 else if (wpa_s->ifmsh)
1149 hapd = wpa_s->ifmsh->bss[0];
1150 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001151 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001152 return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001153}
1154
1155
1156int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
1157 char *buf, size_t buflen)
1158{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001159 struct hostapd_data *hapd;
1160
1161 if (wpa_s->ap_iface)
1162 hapd = wpa_s->ap_iface->bss[0];
1163 else if (wpa_s->ifmsh)
1164 hapd = wpa_s->ifmsh->bss[0];
1165 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001166 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001167 return hostapd_ctrl_iface_sta_next(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001168}
1169
1170
Dmitry Shmidt04949592012-07-19 12:16:46 -07001171int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1172 const char *txtaddr)
1173{
1174 if (wpa_s->ap_iface == NULL)
1175 return -1;
1176 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1177 txtaddr);
1178}
1179
1180
1181int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1182 const char *txtaddr)
1183{
1184 if (wpa_s->ap_iface == NULL)
1185 return -1;
1186 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1187 txtaddr);
1188}
1189
1190
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001191int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1192 size_t buflen, int verbose)
1193{
1194 char *pos = buf, *end = buf + buflen;
1195 int ret;
1196 struct hostapd_bss_config *conf;
1197
1198 if (wpa_s->ap_iface == NULL)
1199 return -1;
1200
1201 conf = wpa_s->ap_iface->bss[0]->conf;
1202 if (conf->wpa == 0)
1203 return 0;
1204
1205 ret = os_snprintf(pos, end - pos,
1206 "pairwise_cipher=%s\n"
1207 "group_cipher=%s\n"
1208 "key_mgmt=%s\n",
1209 wpa_cipher_txt(conf->rsn_pairwise),
1210 wpa_cipher_txt(conf->wpa_group),
1211 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1212 conf->wpa));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001213 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001214 return pos - buf;
1215 pos += ret;
1216 return pos - buf;
1217}
1218
1219#endif /* CONFIG_CTRL_IFACE */
1220
1221
1222int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1223{
1224 struct hostapd_iface *iface = wpa_s->ap_iface;
1225 struct wpa_ssid *ssid = wpa_s->current_ssid;
1226 struct hostapd_data *hapd;
1227
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001228 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1229 ssid->mode == WPAS_MODE_INFRA ||
1230 ssid->mode == WPAS_MODE_IBSS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001231 return -1;
1232
1233#ifdef CONFIG_P2P
1234 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001235 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001236 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001237 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001238 P2P_GROUP_FORMATION;
1239#endif /* CONFIG_P2P */
1240
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001241 hapd = iface->bss[0];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001242 if (hapd->drv_priv == NULL)
1243 return -1;
1244 ieee802_11_set_beacons(iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001245 hostapd_set_ap_wps_ie(hapd);
1246
1247 return 0;
1248}
1249
1250
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001251int ap_switch_channel(struct wpa_supplicant *wpa_s,
1252 struct csa_settings *settings)
1253{
1254#ifdef NEED_AP_MLME
1255 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1256 return -1;
1257
1258 return hostapd_switch_channel(wpa_s->ap_iface->bss[0], settings);
1259#else /* NEED_AP_MLME */
1260 return -1;
1261#endif /* NEED_AP_MLME */
1262}
1263
1264
Dmitry Shmidt83474442015-04-15 13:47:09 -07001265#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001266int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1267{
1268 struct csa_settings settings;
1269 int ret = hostapd_parse_csa_settings(pos, &settings);
1270
1271 if (ret)
1272 return ret;
1273
1274 return ap_switch_channel(wpa_s, &settings);
1275}
Dmitry Shmidt83474442015-04-15 13:47:09 -07001276#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001277
1278
Dmitry Shmidt04949592012-07-19 12:16:46 -07001279void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001280 int offset, int width, int cf1, int cf2)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001281{
1282 if (!wpa_s->ap_iface)
1283 return;
1284
1285 wpa_s->assoc_freq = freq;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001286 if (wpa_s->current_ssid)
1287 wpa_s->current_ssid->frequency = freq;
1288 hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht,
1289 offset, width, cf1, cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001290}
1291
1292
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001293int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1294 const u8 *addr)
1295{
1296 struct hostapd_data *hapd;
1297 struct hostapd_bss_config *conf;
1298
1299 if (!wpa_s->ap_iface)
1300 return -1;
1301
1302 if (addr)
1303 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1304 MAC2STR(addr));
1305 else
1306 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1307
1308 hapd = wpa_s->ap_iface->bss[0];
1309 conf = hapd->conf;
1310
1311 os_free(conf->accept_mac);
1312 conf->accept_mac = NULL;
1313 conf->num_accept_mac = 0;
1314 os_free(conf->deny_mac);
1315 conf->deny_mac = NULL;
1316 conf->num_deny_mac = 0;
1317
1318 if (addr == NULL) {
1319 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1320 return 0;
1321 }
1322
1323 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1324 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1325 if (conf->accept_mac == NULL)
1326 return -1;
1327 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1328 conf->num_accept_mac = 1;
1329
1330 return 0;
1331}
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001332
1333
1334#ifdef CONFIG_WPS_NFC
1335int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1336 const struct wpabuf *pw, const u8 *pubkey_hash)
1337{
1338 struct hostapd_data *hapd;
1339 struct wps_context *wps;
1340
1341 if (!wpa_s->ap_iface)
1342 return -1;
1343 hapd = wpa_s->ap_iface->bss[0];
1344 wps = hapd->wps;
1345
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001346 if (wpa_s->p2pdev->conf->wps_nfc_dh_pubkey == NULL ||
1347 wpa_s->p2pdev->conf->wps_nfc_dh_privkey == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001348 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1349 return -1;
1350 }
1351
1352 dh5_free(wps->dh_ctx);
1353 wpabuf_free(wps->dh_pubkey);
1354 wpabuf_free(wps->dh_privkey);
1355 wps->dh_privkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001356 wpa_s->p2pdev->conf->wps_nfc_dh_privkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001357 wps->dh_pubkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001358 wpa_s->p2pdev->conf->wps_nfc_dh_pubkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001359 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1360 wps->dh_ctx = NULL;
1361 wpabuf_free(wps->dh_pubkey);
1362 wps->dh_pubkey = NULL;
1363 wpabuf_free(wps->dh_privkey);
1364 wps->dh_privkey = NULL;
1365 return -1;
1366 }
1367 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1368 if (wps->dh_ctx == NULL)
1369 return -1;
1370
1371 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1372 pw_id,
1373 pw ? wpabuf_head(pw) : NULL,
1374 pw ? wpabuf_len(pw) : 0, 1);
1375}
1376#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001377
1378
Dmitry Shmidt83474442015-04-15 13:47:09 -07001379#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001380int wpas_ap_stop_ap(struct wpa_supplicant *wpa_s)
1381{
1382 struct hostapd_data *hapd;
1383
1384 if (!wpa_s->ap_iface)
1385 return -1;
1386 hapd = wpa_s->ap_iface->bss[0];
1387 return hostapd_ctrl_iface_stop_ap(hapd);
1388}
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001389
1390
Dmitry Shmidte4663042016-04-04 10:07:49 -07001391int wpas_ap_pmksa_cache_list(struct wpa_supplicant *wpa_s, char *buf,
1392 size_t len)
1393{
1394 size_t reply_len = 0, i;
1395 char ap_delimiter[] = "---- AP ----\n";
1396 char mesh_delimiter[] = "---- mesh ----\n";
1397 size_t dlen;
1398
1399 if (wpa_s->ap_iface) {
1400 dlen = os_strlen(ap_delimiter);
1401 if (dlen > len - reply_len)
1402 return reply_len;
1403 os_memcpy(&buf[reply_len], ap_delimiter, dlen);
1404 reply_len += dlen;
1405
1406 for (i = 0; i < wpa_s->ap_iface->num_bss; i++) {
1407 reply_len += hostapd_ctrl_iface_pmksa_list(
1408 wpa_s->ap_iface->bss[i],
1409 &buf[reply_len], len - reply_len);
1410 }
1411 }
1412
1413 if (wpa_s->ifmsh) {
1414 dlen = os_strlen(mesh_delimiter);
1415 if (dlen > len - reply_len)
1416 return reply_len;
1417 os_memcpy(&buf[reply_len], mesh_delimiter, dlen);
1418 reply_len += dlen;
1419
1420 reply_len += hostapd_ctrl_iface_pmksa_list(
1421 wpa_s->ifmsh->bss[0], &buf[reply_len],
1422 len - reply_len);
1423 }
1424
1425 return reply_len;
1426}
1427
1428
1429void wpas_ap_pmksa_cache_flush(struct wpa_supplicant *wpa_s)
1430{
1431 size_t i;
1432
1433 if (wpa_s->ap_iface) {
1434 for (i = 0; i < wpa_s->ap_iface->num_bss; i++)
1435 hostapd_ctrl_iface_pmksa_flush(wpa_s->ap_iface->bss[i]);
1436 }
1437
1438 if (wpa_s->ifmsh)
1439 hostapd_ctrl_iface_pmksa_flush(wpa_s->ifmsh->bss[0]);
1440}
Paul Stewart092955c2017-02-06 09:13:09 -08001441
1442
1443#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
1444#ifdef CONFIG_MESH
1445
1446int wpas_ap_pmksa_cache_list_mesh(struct wpa_supplicant *wpa_s, const u8 *addr,
1447 char *buf, size_t len)
1448{
1449 return hostapd_ctrl_iface_pmksa_list_mesh(wpa_s->ifmsh->bss[0], addr,
1450 &buf[0], len);
1451}
1452
1453
1454int wpas_ap_pmksa_cache_add_external(struct wpa_supplicant *wpa_s, char *cmd)
1455{
1456 struct external_pmksa_cache *entry;
1457 void *pmksa_cache;
1458
1459 pmksa_cache = hostapd_ctrl_iface_pmksa_create_entry(wpa_s->own_addr,
1460 cmd);
1461 if (!pmksa_cache)
1462 return -1;
1463
1464 entry = os_zalloc(sizeof(struct external_pmksa_cache));
1465 if (!entry)
1466 return -1;
1467
1468 entry->pmksa_cache = pmksa_cache;
1469
1470 dl_list_add(&wpa_s->mesh_external_pmksa_cache, &entry->list);
1471
1472 return 0;
1473}
1474
1475#endif /* CONFIG_MESH */
1476#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
1477
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001478#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte4663042016-04-04 10:07:49 -07001479
1480
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001481#ifdef NEED_AP_MLME
1482void wpas_event_dfs_radar_detected(struct wpa_supplicant *wpa_s,
1483 struct dfs_event *radar)
1484{
1485 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1486 return;
1487 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
1488 hostapd_dfs_radar_detected(wpa_s->ap_iface, radar->freq,
1489 radar->ht_enabled, radar->chan_offset,
1490 radar->chan_width,
1491 radar->cf1, radar->cf2);
1492}
1493
1494
1495void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
1496 struct dfs_event *radar)
1497{
1498 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1499 return;
1500 wpa_printf(MSG_DEBUG, "DFS CAC started on %d MHz", radar->freq);
1501 hostapd_dfs_start_cac(wpa_s->ap_iface, radar->freq,
1502 radar->ht_enabled, radar->chan_offset,
1503 radar->chan_width, radar->cf1, radar->cf2);
1504}
1505
1506
1507void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
1508 struct dfs_event *radar)
1509{
1510 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1511 return;
1512 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
1513 hostapd_dfs_complete_cac(wpa_s->ap_iface, 1, radar->freq,
1514 radar->ht_enabled, radar->chan_offset,
1515 radar->chan_width, radar->cf1, radar->cf2);
1516}
1517
1518
1519void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
1520 struct dfs_event *radar)
1521{
1522 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1523 return;
1524 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
1525 hostapd_dfs_complete_cac(wpa_s->ap_iface, 0, radar->freq,
1526 radar->ht_enabled, radar->chan_offset,
1527 radar->chan_width, radar->cf1, radar->cf2);
1528}
1529
1530
1531void wpas_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s,
1532 struct dfs_event *radar)
1533{
1534 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1535 return;
1536 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
1537 hostapd_dfs_nop_finished(wpa_s->ap_iface, radar->freq,
1538 radar->ht_enabled, radar->chan_offset,
1539 radar->chan_width, radar->cf1, radar->cf2);
1540}
1541#endif /* NEED_AP_MLME */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001542
1543
1544void ap_periodic(struct wpa_supplicant *wpa_s)
1545{
1546 if (wpa_s->ap_iface)
1547 hostapd_periodic_iface(wpa_s->ap_iface);
1548}