blob: 1e00f35b586fe0449902b7c4face58767cee77ea [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;
171 wpas_conf_ap_vht(wpa_s, conf, mode);
172 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800173 }
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700174 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800175
176 if (conf->secondary_channel) {
177 struct wpa_supplicant *iface;
178
179 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
180 {
181 if (iface == wpa_s ||
182 iface->wpa_state < WPA_AUTHENTICATING ||
183 (int) iface->assoc_freq != ssid->frequency)
184 continue;
185
186 /*
187 * Do not allow 40 MHz co-ex PRI/SEC switch to force us
188 * to change our PRI channel since we have an existing,
189 * concurrent connection on that channel and doing
190 * multi-channel concurrency is likely to cause more
191 * harm than using different PRI/SEC selection in
192 * environment with multiple BSSes on these two channels
193 * with mixed 20 MHz or PRI channel selection.
194 */
195 conf->no_pri_sec_switch = 1;
196 }
197 }
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700198#endif /* CONFIG_IEEE80211N */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800199
200 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800201}
202
203
204static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
205 struct wpa_ssid *ssid,
206 struct hostapd_config *conf)
207{
208 struct hostapd_bss_config *bss = conf->bss[0];
209
210 conf->driver = wpa_s->driver;
211
212 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
213
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800214 if (wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800215 return -1;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700216
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700217 if (ssid->pbss > 1) {
218 wpa_printf(MSG_ERROR, "Invalid pbss value(%d) for AP mode",
219 ssid->pbss);
220 return -1;
221 }
222 bss->pbss = ssid->pbss;
223
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800224#ifdef CONFIG_ACS
225 if (ssid->acs) {
226 /* Setting channel to 0 in order to enable ACS */
227 conf->channel = 0;
228 wpa_printf(MSG_DEBUG, "Use automatic channel selection");
229 }
230#endif /* CONFIG_ACS */
231
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800232 if (ieee80211_is_dfs(ssid->frequency) && wpa_s->conf->country[0]) {
233 conf->ieee80211h = 1;
234 conf->ieee80211d = 1;
235 conf->country[0] = wpa_s->conf->country[0];
236 conf->country[1] = wpa_s->conf->country[1];
237 }
238
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700239#ifdef CONFIG_P2P
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700240 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
241 (ssid->mode == WPAS_MODE_P2P_GO ||
242 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700243 /* Remove 802.11b rates from supported and basic rate sets */
244 int *list = os_malloc(4 * sizeof(int));
245 if (list) {
246 list[0] = 60;
247 list[1] = 120;
248 list[2] = 240;
249 list[3] = -1;
250 }
251 conf->basic_rates = list;
252
253 list = os_malloc(9 * sizeof(int));
254 if (list) {
255 list[0] = 60;
256 list[1] = 90;
257 list[2] = 120;
258 list[3] = 180;
259 list[4] = 240;
260 list[5] = 360;
261 list[6] = 480;
262 list[7] = 540;
263 list[8] = -1;
264 }
265 conf->supported_rates = list;
266 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800267
268 bss->isolate = !wpa_s->conf->p2p_intra_bss;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700269 bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800270
271 if (ssid->p2p_group) {
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800272 os_memcpy(bss->ip_addr_go, wpa_s->p2pdev->conf->ip_addr_go, 4);
273 os_memcpy(bss->ip_addr_mask, wpa_s->p2pdev->conf->ip_addr_mask,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800274 4);
275 os_memcpy(bss->ip_addr_start,
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800276 wpa_s->p2pdev->conf->ip_addr_start, 4);
277 os_memcpy(bss->ip_addr_end, wpa_s->p2pdev->conf->ip_addr_end,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800278 4);
279 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700280#endif /* CONFIG_P2P */
281
282 if (ssid->ssid_len == 0) {
283 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
284 return -1;
285 }
286 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700287 bss->ssid.ssid_len = ssid->ssid_len;
288 bss->ssid.ssid_set = 1;
289
Dmitry Shmidt04949592012-07-19 12:16:46 -0700290 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
291
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800292 if (ssid->auth_alg)
293 bss->auth_algs = ssid->auth_alg;
294
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700295 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
296 bss->wpa = ssid->proto;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700297 if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
298 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
299 else
300 bss->wpa_key_mgmt = ssid->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700301 bss->wpa_pairwise = ssid->pairwise_cipher;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800302 if (ssid->psk_set) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800303 bin_clear_free(bss->ssid.wpa_psk, sizeof(*bss->ssid.wpa_psk));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700304 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
305 if (bss->ssid.wpa_psk == NULL)
306 return -1;
307 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
308 bss->ssid.wpa_psk->group = 1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700309 bss->ssid.wpa_psk_set = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800310 } else if (ssid->passphrase) {
311 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800312 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
313 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
314 struct hostapd_wep_keys *wep = &bss->ssid.wep;
315 int i;
316 for (i = 0; i < NUM_WEP_KEYS; i++) {
317 if (ssid->wep_key_len[i] == 0)
318 continue;
319 wep->key[i] = os_malloc(ssid->wep_key_len[i]);
320 if (wep->key[i] == NULL)
321 return -1;
322 os_memcpy(wep->key[i], ssid->wep_key[i],
323 ssid->wep_key_len[i]);
324 wep->len[i] = ssid->wep_key_len[i];
325 }
326 wep->idx = ssid->wep_tx_keyidx;
327 wep->keys_set = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700328 }
329
Dmitry Shmidt04949592012-07-19 12:16:46 -0700330 if (ssid->ap_max_inactivity)
331 bss->ap_max_inactivity = ssid->ap_max_inactivity;
332
333 if (ssid->dtim_period)
334 bss->dtim_period = ssid->dtim_period;
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -0800335 else if (wpa_s->conf->dtim_period)
336 bss->dtim_period = wpa_s->conf->dtim_period;
337
338 if (ssid->beacon_int)
339 conf->beacon_int = ssid->beacon_int;
340 else if (wpa_s->conf->beacon_int)
341 conf->beacon_int = wpa_s->conf->beacon_int;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700342
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800343#ifdef CONFIG_P2P
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800344 if (ssid->mode == WPAS_MODE_P2P_GO ||
345 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
346 if (wpa_s->conf->p2p_go_ctwindow > conf->beacon_int) {
347 wpa_printf(MSG_INFO,
348 "CTWindow (%d) is bigger than beacon interval (%d) - avoid configuring it",
349 wpa_s->conf->p2p_go_ctwindow,
350 conf->beacon_int);
351 conf->p2p_go_ctwindow = 0;
352 } else {
353 conf->p2p_go_ctwindow = wpa_s->conf->p2p_go_ctwindow;
354 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800355 }
356#endif /* CONFIG_P2P */
357
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800358 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
359 bss->rsn_pairwise = bss->wpa_pairwise;
360 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
361 bss->rsn_pairwise);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700362
363 if (bss->wpa && bss->ieee802_1x)
364 bss->ssid.security_policy = SECURITY_WPA;
365 else if (bss->wpa)
366 bss->ssid.security_policy = SECURITY_WPA_PSK;
367 else if (bss->ieee802_1x) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800368 int cipher = WPA_CIPHER_NONE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700369 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
370 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800371 if (bss->default_wep_key_len)
372 cipher = bss->default_wep_key_len >= 13 ?
373 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
374 bss->wpa_group = cipher;
375 bss->wpa_pairwise = cipher;
376 bss->rsn_pairwise = cipher;
377 } else if (bss->ssid.wep.keys_set) {
378 int cipher = WPA_CIPHER_WEP40;
379 if (bss->ssid.wep.len[0] >= 13)
380 cipher = WPA_CIPHER_WEP104;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700381 bss->ssid.security_policy = SECURITY_STATIC_WEP;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800382 bss->wpa_group = cipher;
383 bss->wpa_pairwise = cipher;
384 bss->rsn_pairwise = cipher;
385 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700386 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800387 bss->wpa_group = WPA_CIPHER_NONE;
388 bss->wpa_pairwise = WPA_CIPHER_NONE;
389 bss->rsn_pairwise = WPA_CIPHER_NONE;
390 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700391
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700392 if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
393 (bss->wpa_group == WPA_CIPHER_CCMP ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800394 bss->wpa_group == WPA_CIPHER_GCMP ||
395 bss->wpa_group == WPA_CIPHER_CCMP_256 ||
396 bss->wpa_group == WPA_CIPHER_GCMP_256)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700397 /*
398 * Strong ciphers do not need frequent rekeying, so increase
399 * the default GTK rekeying period to 24 hours.
400 */
401 bss->wpa_group_rekey = 86400;
402 }
403
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700404#ifdef CONFIG_IEEE80211W
405 if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT)
406 bss->ieee80211w = ssid->ieee80211w;
407#endif /* CONFIG_IEEE80211W */
408
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700409#ifdef CONFIG_WPS
410 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800411 * Enable WPS by default for open and WPA/WPA2-Personal network, but
412 * require user interaction to actually use it. Only the internal
413 * Registrar is supported.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700414 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800415 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
416 bss->ssid.security_policy != SECURITY_PLAINTEXT)
417 goto no_wps;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800418 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800419 (!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ||
420 !(bss->wpa & 2)))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800421 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
422 * configuration */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700423 if (ssid->wps_disabled)
424 goto no_wps;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700425 bss->eap_server = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700426
427 if (!ssid->ignore_broadcast_ssid)
428 bss->wps_state = 2;
429
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700430 bss->ap_setup_locked = 2;
431 if (wpa_s->conf->config_methods)
432 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
433 os_memcpy(bss->device_type, wpa_s->conf->device_type,
434 WPS_DEV_TYPE_LEN);
435 if (wpa_s->conf->device_name) {
436 bss->device_name = os_strdup(wpa_s->conf->device_name);
437 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
438 }
439 if (wpa_s->conf->manufacturer)
440 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
441 if (wpa_s->conf->model_name)
442 bss->model_name = os_strdup(wpa_s->conf->model_name);
443 if (wpa_s->conf->model_number)
444 bss->model_number = os_strdup(wpa_s->conf->model_number);
445 if (wpa_s->conf->serial_number)
446 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
447 if (is_nil_uuid(wpa_s->conf->uuid))
448 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
449 else
450 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
451 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700452 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800453no_wps:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700454#endif /* CONFIG_WPS */
455
456 if (wpa_s->max_stations &&
457 wpa_s->max_stations < wpa_s->conf->max_num_sta)
458 bss->max_num_sta = wpa_s->max_stations;
459 else
460 bss->max_num_sta = wpa_s->conf->max_num_sta;
461
462 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
463
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700464 if (wpa_s->conf->ap_vendor_elements) {
465 bss->vendor_elements =
466 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
467 }
468
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700469 return 0;
470}
471
472
473static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
474{
475#ifdef CONFIG_P2P
476 struct wpa_supplicant *wpa_s = ctx;
477 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700478
479 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700480 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700481 return;
Dmitry Shmidt18463232014-01-24 12:29:41 -0800482 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
483 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700484 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
485 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700486 buf + IEEE80211_HDRLEN + 1,
487 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700488#endif /* CONFIG_P2P */
489}
490
491
492static void ap_wps_event_cb(void *ctx, enum wps_event event,
493 union wps_event_data *data)
494{
495#ifdef CONFIG_P2P
496 struct wpa_supplicant *wpa_s = ctx;
497
Jouni Malinen75ecf522011-06-27 15:19:46 -0700498 if (event == WPS_EV_FAIL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700499 struct wps_event_fail *fail = &data->fail;
500
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800501 if (wpa_s->p2pdev && wpa_s->p2pdev != wpa_s &&
Jouni Malinen75ecf522011-06-27 15:19:46 -0700502 wpa_s == wpa_s->global->p2p_group_formation) {
503 /*
504 * src/ap/wps_hostapd.c has already sent this on the
505 * main interface, so only send on the parent interface
506 * here if needed.
507 */
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800508 wpa_msg(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_FAIL
Jouni Malinen75ecf522011-06-27 15:19:46 -0700509 "msg=%d config_error=%d",
510 fail->msg, fail->config_error);
511 }
512 wpas_p2p_wps_failed(wpa_s, fail);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700513 }
514#endif /* CONFIG_P2P */
515}
516
517
518static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800519 int authorized, const u8 *p2p_dev_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700520{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800521 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700522}
523
524
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700525#ifdef CONFIG_P2P
526static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
527 const u8 *psk, size_t psk_len)
528{
529
530 struct wpa_supplicant *wpa_s = ctx;
531 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
532 return;
533 wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
534}
535#endif /* CONFIG_P2P */
536
537
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700538static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
539{
540#ifdef CONFIG_P2P
541 struct wpa_supplicant *wpa_s = ctx;
542 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700543
544 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700545 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700546 return -1;
547 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
548 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700549 buf + IEEE80211_HDRLEN + 1,
550 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700551#endif /* CONFIG_P2P */
552 return 0;
553}
554
555
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800556static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700557 const u8 *bssid, const u8 *ie, size_t ie_len,
558 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700559{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700560 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700561 unsigned int freq = 0;
562
563 if (wpa_s->ap_iface)
564 freq = wpa_s->ap_iface->freq;
565
Dmitry Shmidt04949592012-07-19 12:16:46 -0700566 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700567 freq, ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700568}
569
570
571static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
572 const u8 *uuid_e)
573{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700574 struct wpa_supplicant *wpa_s = ctx;
575 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700576}
577
578
579static void wpas_ap_configured_cb(void *ctx)
580{
581 struct wpa_supplicant *wpa_s = ctx;
582
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800583#ifdef CONFIG_ACS
584 if (wpa_s->current_ssid && wpa_s->current_ssid->acs)
585 wpa_s->assoc_freq = wpa_s->ap_iface->freq;
586#endif /* CONFIG_ACS */
587
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700588 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
589
590 if (wpa_s->ap_configured_cb)
591 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
592 wpa_s->ap_configured_cb_data);
593}
594
595
596int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
597 struct wpa_ssid *ssid)
598{
599 struct wpa_driver_associate_params params;
600 struct hostapd_iface *hapd_iface;
601 struct hostapd_config *conf;
602 size_t i;
603
604 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
605 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
606 return -1;
607 }
608
609 wpa_supplicant_ap_deinit(wpa_s);
610
611 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
612 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
613
614 os_memset(&params, 0, sizeof(params));
615 params.ssid = ssid->ssid;
616 params.ssid_len = ssid->ssid_len;
617 switch (ssid->mode) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700618 case WPAS_MODE_AP:
619 case WPAS_MODE_P2P_GO:
620 case WPAS_MODE_P2P_GROUP_FORMATION:
621 params.mode = IEEE80211_MODE_AP;
622 break;
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800623 default:
624 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700625 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700626 if (ssid->frequency == 0)
627 ssid->frequency = 2462; /* default channel 11 */
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700628 params.freq.freq = ssid->frequency;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700629
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800630 params.wpa_proto = ssid->proto;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700631 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
632 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
633 else
634 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800635 params.key_mgmt_suite = wpa_s->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700636
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800637 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
638 1);
639 if (wpa_s->pairwise_cipher < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700640 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
641 "cipher.");
642 return -1;
643 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800644 params.pairwise_suite = wpa_s->pairwise_cipher;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700645 params.group_suite = params.pairwise_suite;
646
647#ifdef CONFIG_P2P
648 if (ssid->mode == WPAS_MODE_P2P_GO ||
649 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
650 params.p2p = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700651#endif /* CONFIG_P2P */
652
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800653 if (wpa_s->p2pdev->set_ap_uapsd)
654 params.uapsd = wpa_s->p2pdev->ap_uapsd;
Dmitry Shmidtec58b162014-02-19 12:44:18 -0800655 else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
656 params.uapsd = 1; /* mandatory for P2P GO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700657 else
658 params.uapsd = -1;
659
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800660 if (ieee80211_is_dfs(params.freq.freq))
661 params.freq.freq = 0; /* set channel after CAC */
662
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700663 if (params.p2p)
664 wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_GO);
665 else
666 wpa_drv_get_ext_capa(wpa_s, WPA_IF_AP_BSS);
667
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700668 if (wpa_drv_associate(wpa_s, &params) < 0) {
669 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
670 return -1;
671 }
672
673 wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
674 if (hapd_iface == NULL)
675 return -1;
676 hapd_iface->owner = wpa_s;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800677 hapd_iface->drv_flags = wpa_s->drv_flags;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800678 hapd_iface->smps_modes = wpa_s->drv_smps_modes;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800679 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700680 hapd_iface->extended_capa = wpa_s->extended_capa;
681 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
682 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700683
684 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
685 if (conf == NULL) {
686 wpa_supplicant_ap_deinit(wpa_s);
687 return -1;
688 }
689
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800690 /* Use the maximum oper channel width if it's given. */
691 if (ssid->max_oper_chwidth)
692 conf->vht_oper_chwidth = ssid->max_oper_chwidth;
693
694 ieee80211_freq_to_chan(ssid->vht_center_freq2,
695 &conf->vht_oper_centr_freq_seg1_idx);
696
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700697 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
698 wpa_s->conf->wmm_ac_params,
699 sizeof(wpa_s->conf->wmm_ac_params));
700
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800701 if (params.uapsd > 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800702 conf->bss[0]->wmm_enabled = 1;
703 conf->bss[0]->wmm_uapsd = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800704 }
705
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700706 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
707 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
708 wpa_supplicant_ap_deinit(wpa_s);
709 return -1;
710 }
711
712#ifdef CONFIG_P2P
713 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800714 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700715 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800716 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700717 P2P_GROUP_FORMATION;
718#endif /* CONFIG_P2P */
719
720 hapd_iface->num_bss = conf->num_bss;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700721 hapd_iface->bss = os_calloc(conf->num_bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700722 sizeof(struct hostapd_data *));
723 if (hapd_iface->bss == NULL) {
724 wpa_supplicant_ap_deinit(wpa_s);
725 return -1;
726 }
727
728 for (i = 0; i < conf->num_bss; i++) {
729 hapd_iface->bss[i] =
730 hostapd_alloc_bss_data(hapd_iface, conf,
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800731 conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700732 if (hapd_iface->bss[i] == NULL) {
733 wpa_supplicant_ap_deinit(wpa_s);
734 return -1;
735 }
736
737 hapd_iface->bss[i]->msg_ctx = wpa_s;
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800738 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->p2pdev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700739 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
740 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
741 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
742 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
743 hostapd_register_probereq_cb(hapd_iface->bss[i],
744 ap_probe_req_rx, wpa_s);
745 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
746 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
747 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
748 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
749 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
750 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
751#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700752 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
753 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700754 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700755 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
756 ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700757#endif /* CONFIG_P2P */
758 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
759 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800760#ifdef CONFIG_TESTING_OPTIONS
761 hapd_iface->bss[i]->ext_eapol_frame_io =
762 wpa_s->ext_eapol_frame_io;
763#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700764 }
765
766 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
767 hapd_iface->bss[0]->driver = wpa_s->driver;
768 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
769
770 wpa_s->current_ssid = ssid;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700771 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700772 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
773 wpa_s->assoc_freq = ssid->frequency;
774
775 if (hostapd_setup_interface(wpa_s->ap_iface)) {
776 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
777 wpa_supplicant_ap_deinit(wpa_s);
778 return -1;
779 }
780
781 return 0;
782}
783
784
785void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
786{
787#ifdef CONFIG_WPS
788 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
789#endif /* CONFIG_WPS */
790
791 if (wpa_s->ap_iface == NULL)
792 return;
793
794 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700795 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700796 wpa_s->assoc_freq = 0;
Dmitry Shmidt43cb5782014-06-16 16:23:22 -0700797 wpas_p2p_ap_deinit(wpa_s);
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800798 wpa_s->ap_iface->driver_ap_teardown =
799 !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
800
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700801 hostapd_interface_deinit(wpa_s->ap_iface);
802 hostapd_interface_free(wpa_s->ap_iface);
803 wpa_s->ap_iface = NULL;
804 wpa_drv_deinit_ap(wpa_s);
Dmitry Shmidtf73259c2015-03-17 11:00:54 -0700805 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
806 " reason=%d locally_generated=1",
807 MAC2STR(wpa_s->own_addr), WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700808}
809
810
811void ap_tx_status(void *ctx, const u8 *addr,
812 const u8 *buf, size_t len, int ack)
813{
814#ifdef NEED_AP_MLME
815 struct wpa_supplicant *wpa_s = ctx;
816 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
817#endif /* NEED_AP_MLME */
818}
819
820
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800821void ap_eapol_tx_status(void *ctx, const u8 *dst,
822 const u8 *data, size_t len, int ack)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700823{
824#ifdef NEED_AP_MLME
825 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800826 if (!wpa_s->ap_iface)
827 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800828 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
829#endif /* NEED_AP_MLME */
830}
831
832
833void ap_client_poll_ok(void *ctx, const u8 *addr)
834{
835#ifdef NEED_AP_MLME
836 struct wpa_supplicant *wpa_s = ctx;
837 if (wpa_s->ap_iface)
838 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
839#endif /* NEED_AP_MLME */
840}
841
842
843void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
844{
845#ifdef NEED_AP_MLME
846 struct wpa_supplicant *wpa_s = ctx;
847 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700848#endif /* NEED_AP_MLME */
849}
850
851
852void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
853{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800854#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700855 struct wpa_supplicant *wpa_s = ctx;
856 struct hostapd_frame_info fi;
857 os_memset(&fi, 0, sizeof(fi));
858 fi.datarate = rx_mgmt->datarate;
859 fi.ssi_signal = rx_mgmt->ssi_signal;
860 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
861 rx_mgmt->frame_len, &fi);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800862#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700863}
864
865
866void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
867{
868#ifdef NEED_AP_MLME
869 struct wpa_supplicant *wpa_s = ctx;
870 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
871#endif /* NEED_AP_MLME */
872}
873
874
875void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
876 const u8 *src_addr, const u8 *buf, size_t len)
877{
878 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
879}
880
881
882#ifdef CONFIG_WPS
883
884int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
885 const u8 *p2p_dev_addr)
886{
887 if (!wpa_s->ap_iface)
888 return -1;
889 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
890 p2p_dev_addr);
891}
892
893
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700894int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
895{
896 struct wps_registrar *reg;
897 int reg_sel = 0, wps_sta = 0;
898
899 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
900 return -1;
901
902 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
903 reg_sel = wps_registrar_wps_cancel(reg);
904 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
Dmitry Shmidt04949592012-07-19 12:16:46 -0700905 ap_sta_wps_cancel, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700906
907 if (!reg_sel && !wps_sta) {
908 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
909 "time");
910 return -1;
911 }
912
913 /*
914 * There are 2 cases to return wps cancel as success:
915 * 1. When wps cancel was initiated but no connection has been
916 * established with client yet.
917 * 2. Client is in the middle of exchanging WPS messages.
918 */
919
920 return 0;
921}
922
923
924int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800925 const char *pin, char *buf, size_t buflen,
926 int timeout)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700927{
928 int ret, ret_len = 0;
929
930 if (!wpa_s->ap_iface)
931 return -1;
932
933 if (pin == NULL) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800934 unsigned int rpin;
935
936 if (wps_generate_pin(&rpin) < 0)
937 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800938 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800939 if (os_snprintf_error(buflen, ret_len))
940 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700941 pin = buf;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800942 } else if (buf) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700943 ret_len = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800944 if (os_snprintf_error(buflen, ret_len))
945 return -1;
946 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700947
948 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800949 timeout);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700950 if (ret)
951 return -1;
952 return ret_len;
953}
954
955
956static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
957{
958 struct wpa_supplicant *wpa_s = eloop_data;
959 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
960 wpas_wps_ap_pin_disable(wpa_s);
961}
962
963
964static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
965{
966 struct hostapd_data *hapd;
967
968 if (wpa_s->ap_iface == NULL)
969 return;
970 hapd = wpa_s->ap_iface->bss[0];
971 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
972 hapd->ap_pin_failures = 0;
973 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
974 if (timeout > 0)
975 eloop_register_timeout(timeout, 0,
976 wpas_wps_ap_pin_timeout, wpa_s, NULL);
977}
978
979
980void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
981{
982 struct hostapd_data *hapd;
983
984 if (wpa_s->ap_iface == NULL)
985 return;
986 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
987 hapd = wpa_s->ap_iface->bss[0];
988 os_free(hapd->conf->ap_pin);
989 hapd->conf->ap_pin = NULL;
990 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
991}
992
993
994const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
995{
996 struct hostapd_data *hapd;
997 unsigned int pin;
998 char pin_txt[9];
999
1000 if (wpa_s->ap_iface == NULL)
1001 return NULL;
1002 hapd = wpa_s->ap_iface->bss[0];
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001003 if (wps_generate_pin(&pin) < 0)
1004 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001005 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001006 os_free(hapd->conf->ap_pin);
1007 hapd->conf->ap_pin = os_strdup(pin_txt);
1008 if (hapd->conf->ap_pin == NULL)
1009 return NULL;
1010 wpas_wps_ap_pin_enable(wpa_s, timeout);
1011
1012 return hapd->conf->ap_pin;
1013}
1014
1015
1016const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
1017{
1018 struct hostapd_data *hapd;
1019 if (wpa_s->ap_iface == NULL)
1020 return NULL;
1021 hapd = wpa_s->ap_iface->bss[0];
1022 return hapd->conf->ap_pin;
1023}
1024
1025
1026int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
1027 int timeout)
1028{
1029 struct hostapd_data *hapd;
1030 char pin_txt[9];
1031 int ret;
1032
1033 if (wpa_s->ap_iface == NULL)
1034 return -1;
1035 hapd = wpa_s->ap_iface->bss[0];
1036 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001037 if (os_snprintf_error(sizeof(pin_txt), ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001038 return -1;
1039 os_free(hapd->conf->ap_pin);
1040 hapd->conf->ap_pin = os_strdup(pin_txt);
1041 if (hapd->conf->ap_pin == NULL)
1042 return -1;
1043 wpas_wps_ap_pin_enable(wpa_s, timeout);
1044
1045 return 0;
1046}
1047
1048
1049void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
1050{
1051 struct hostapd_data *hapd;
1052
1053 if (wpa_s->ap_iface == NULL)
1054 return;
1055 hapd = wpa_s->ap_iface->bss[0];
1056
1057 /*
1058 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
1059 * PIN if this happens multiple times to slow down brute force attacks.
1060 */
1061 hapd->ap_pin_failures++;
1062 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
1063 hapd->ap_pin_failures);
1064 if (hapd->ap_pin_failures < 3)
1065 return;
1066
1067 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
1068 hapd->ap_pin_failures = 0;
1069 os_free(hapd->conf->ap_pin);
1070 hapd->conf->ap_pin = NULL;
1071}
1072
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001073
1074#ifdef CONFIG_WPS_NFC
1075
1076struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
1077 int ndef)
1078{
1079 struct hostapd_data *hapd;
1080
1081 if (wpa_s->ap_iface == NULL)
1082 return NULL;
1083 hapd = wpa_s->ap_iface->bss[0];
1084 return hostapd_wps_nfc_config_token(hapd, ndef);
1085}
1086
1087
1088struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
1089 int ndef)
1090{
1091 struct hostapd_data *hapd;
1092
1093 if (wpa_s->ap_iface == NULL)
1094 return NULL;
1095 hapd = wpa_s->ap_iface->bss[0];
1096 return hostapd_wps_nfc_hs_cr(hapd, ndef);
1097}
1098
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001099
1100int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
1101 const struct wpabuf *req,
1102 const struct wpabuf *sel)
1103{
1104 struct hostapd_data *hapd;
1105
1106 if (wpa_s->ap_iface == NULL)
1107 return -1;
1108 hapd = wpa_s->ap_iface->bss[0];
1109 return hostapd_wps_nfc_report_handover(hapd, req, sel);
1110}
1111
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001112#endif /* CONFIG_WPS_NFC */
1113
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001114#endif /* CONFIG_WPS */
1115
1116
1117#ifdef CONFIG_CTRL_IFACE
1118
1119int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
1120 char *buf, size_t buflen)
1121{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001122 struct hostapd_data *hapd;
1123
1124 if (wpa_s->ap_iface)
1125 hapd = wpa_s->ap_iface->bss[0];
1126 else if (wpa_s->ifmsh)
1127 hapd = wpa_s->ifmsh->bss[0];
1128 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001129 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001130 return hostapd_ctrl_iface_sta_first(hapd, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001131}
1132
1133
1134int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
1135 char *buf, size_t buflen)
1136{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001137 struct hostapd_data *hapd;
1138
1139 if (wpa_s->ap_iface)
1140 hapd = wpa_s->ap_iface->bss[0];
1141 else if (wpa_s->ifmsh)
1142 hapd = wpa_s->ifmsh->bss[0];
1143 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001144 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001145 return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001146}
1147
1148
1149int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
1150 char *buf, size_t buflen)
1151{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001152 struct hostapd_data *hapd;
1153
1154 if (wpa_s->ap_iface)
1155 hapd = wpa_s->ap_iface->bss[0];
1156 else if (wpa_s->ifmsh)
1157 hapd = wpa_s->ifmsh->bss[0];
1158 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001159 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001160 return hostapd_ctrl_iface_sta_next(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001161}
1162
1163
Dmitry Shmidt04949592012-07-19 12:16:46 -07001164int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1165 const char *txtaddr)
1166{
1167 if (wpa_s->ap_iface == NULL)
1168 return -1;
1169 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1170 txtaddr);
1171}
1172
1173
1174int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1175 const char *txtaddr)
1176{
1177 if (wpa_s->ap_iface == NULL)
1178 return -1;
1179 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1180 txtaddr);
1181}
1182
1183
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001184int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1185 size_t buflen, int verbose)
1186{
1187 char *pos = buf, *end = buf + buflen;
1188 int ret;
1189 struct hostapd_bss_config *conf;
1190
1191 if (wpa_s->ap_iface == NULL)
1192 return -1;
1193
1194 conf = wpa_s->ap_iface->bss[0]->conf;
1195 if (conf->wpa == 0)
1196 return 0;
1197
1198 ret = os_snprintf(pos, end - pos,
1199 "pairwise_cipher=%s\n"
1200 "group_cipher=%s\n"
1201 "key_mgmt=%s\n",
1202 wpa_cipher_txt(conf->rsn_pairwise),
1203 wpa_cipher_txt(conf->wpa_group),
1204 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1205 conf->wpa));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001206 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001207 return pos - buf;
1208 pos += ret;
1209 return pos - buf;
1210}
1211
1212#endif /* CONFIG_CTRL_IFACE */
1213
1214
1215int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1216{
1217 struct hostapd_iface *iface = wpa_s->ap_iface;
1218 struct wpa_ssid *ssid = wpa_s->current_ssid;
1219 struct hostapd_data *hapd;
1220
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001221 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1222 ssid->mode == WPAS_MODE_INFRA ||
1223 ssid->mode == WPAS_MODE_IBSS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001224 return -1;
1225
1226#ifdef CONFIG_P2P
1227 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001228 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001229 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001230 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001231 P2P_GROUP_FORMATION;
1232#endif /* CONFIG_P2P */
1233
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001234 hapd = iface->bss[0];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001235 if (hapd->drv_priv == NULL)
1236 return -1;
1237 ieee802_11_set_beacons(iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001238 hostapd_set_ap_wps_ie(hapd);
1239
1240 return 0;
1241}
1242
1243
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001244int ap_switch_channel(struct wpa_supplicant *wpa_s,
1245 struct csa_settings *settings)
1246{
1247#ifdef NEED_AP_MLME
1248 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1249 return -1;
1250
1251 return hostapd_switch_channel(wpa_s->ap_iface->bss[0], settings);
1252#else /* NEED_AP_MLME */
1253 return -1;
1254#endif /* NEED_AP_MLME */
1255}
1256
1257
Dmitry Shmidt83474442015-04-15 13:47:09 -07001258#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001259int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1260{
1261 struct csa_settings settings;
1262 int ret = hostapd_parse_csa_settings(pos, &settings);
1263
1264 if (ret)
1265 return ret;
1266
1267 return ap_switch_channel(wpa_s, &settings);
1268}
Dmitry Shmidt83474442015-04-15 13:47:09 -07001269#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001270
1271
Dmitry Shmidt04949592012-07-19 12:16:46 -07001272void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001273 int offset, int width, int cf1, int cf2)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001274{
1275 if (!wpa_s->ap_iface)
1276 return;
1277
1278 wpa_s->assoc_freq = freq;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001279 if (wpa_s->current_ssid)
1280 wpa_s->current_ssid->frequency = freq;
1281 hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht,
1282 offset, width, cf1, cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001283}
1284
1285
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001286int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1287 const u8 *addr)
1288{
1289 struct hostapd_data *hapd;
1290 struct hostapd_bss_config *conf;
1291
1292 if (!wpa_s->ap_iface)
1293 return -1;
1294
1295 if (addr)
1296 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1297 MAC2STR(addr));
1298 else
1299 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1300
1301 hapd = wpa_s->ap_iface->bss[0];
1302 conf = hapd->conf;
1303
1304 os_free(conf->accept_mac);
1305 conf->accept_mac = NULL;
1306 conf->num_accept_mac = 0;
1307 os_free(conf->deny_mac);
1308 conf->deny_mac = NULL;
1309 conf->num_deny_mac = 0;
1310
1311 if (addr == NULL) {
1312 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1313 return 0;
1314 }
1315
1316 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1317 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1318 if (conf->accept_mac == NULL)
1319 return -1;
1320 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1321 conf->num_accept_mac = 1;
1322
1323 return 0;
1324}
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001325
1326
1327#ifdef CONFIG_WPS_NFC
1328int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1329 const struct wpabuf *pw, const u8 *pubkey_hash)
1330{
1331 struct hostapd_data *hapd;
1332 struct wps_context *wps;
1333
1334 if (!wpa_s->ap_iface)
1335 return -1;
1336 hapd = wpa_s->ap_iface->bss[0];
1337 wps = hapd->wps;
1338
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001339 if (wpa_s->p2pdev->conf->wps_nfc_dh_pubkey == NULL ||
1340 wpa_s->p2pdev->conf->wps_nfc_dh_privkey == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001341 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1342 return -1;
1343 }
1344
1345 dh5_free(wps->dh_ctx);
1346 wpabuf_free(wps->dh_pubkey);
1347 wpabuf_free(wps->dh_privkey);
1348 wps->dh_privkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001349 wpa_s->p2pdev->conf->wps_nfc_dh_privkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001350 wps->dh_pubkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001351 wpa_s->p2pdev->conf->wps_nfc_dh_pubkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001352 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1353 wps->dh_ctx = NULL;
1354 wpabuf_free(wps->dh_pubkey);
1355 wps->dh_pubkey = NULL;
1356 wpabuf_free(wps->dh_privkey);
1357 wps->dh_privkey = NULL;
1358 return -1;
1359 }
1360 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1361 if (wps->dh_ctx == NULL)
1362 return -1;
1363
1364 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1365 pw_id,
1366 pw ? wpabuf_head(pw) : NULL,
1367 pw ? wpabuf_len(pw) : 0, 1);
1368}
1369#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001370
1371
Dmitry Shmidt83474442015-04-15 13:47:09 -07001372#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001373int wpas_ap_stop_ap(struct wpa_supplicant *wpa_s)
1374{
1375 struct hostapd_data *hapd;
1376
1377 if (!wpa_s->ap_iface)
1378 return -1;
1379 hapd = wpa_s->ap_iface->bss[0];
1380 return hostapd_ctrl_iface_stop_ap(hapd);
1381}
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001382
1383
Dmitry Shmidte4663042016-04-04 10:07:49 -07001384int wpas_ap_pmksa_cache_list(struct wpa_supplicant *wpa_s, char *buf,
1385 size_t len)
1386{
1387 size_t reply_len = 0, i;
1388 char ap_delimiter[] = "---- AP ----\n";
1389 char mesh_delimiter[] = "---- mesh ----\n";
1390 size_t dlen;
1391
1392 if (wpa_s->ap_iface) {
1393 dlen = os_strlen(ap_delimiter);
1394 if (dlen > len - reply_len)
1395 return reply_len;
1396 os_memcpy(&buf[reply_len], ap_delimiter, dlen);
1397 reply_len += dlen;
1398
1399 for (i = 0; i < wpa_s->ap_iface->num_bss; i++) {
1400 reply_len += hostapd_ctrl_iface_pmksa_list(
1401 wpa_s->ap_iface->bss[i],
1402 &buf[reply_len], len - reply_len);
1403 }
1404 }
1405
1406 if (wpa_s->ifmsh) {
1407 dlen = os_strlen(mesh_delimiter);
1408 if (dlen > len - reply_len)
1409 return reply_len;
1410 os_memcpy(&buf[reply_len], mesh_delimiter, dlen);
1411 reply_len += dlen;
1412
1413 reply_len += hostapd_ctrl_iface_pmksa_list(
1414 wpa_s->ifmsh->bss[0], &buf[reply_len],
1415 len - reply_len);
1416 }
1417
1418 return reply_len;
1419}
1420
1421
1422void wpas_ap_pmksa_cache_flush(struct wpa_supplicant *wpa_s)
1423{
1424 size_t i;
1425
1426 if (wpa_s->ap_iface) {
1427 for (i = 0; i < wpa_s->ap_iface->num_bss; i++)
1428 hostapd_ctrl_iface_pmksa_flush(wpa_s->ap_iface->bss[i]);
1429 }
1430
1431 if (wpa_s->ifmsh)
1432 hostapd_ctrl_iface_pmksa_flush(wpa_s->ifmsh->bss[0]);
1433}
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001434#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte4663042016-04-04 10:07:49 -07001435
1436
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001437#ifdef NEED_AP_MLME
1438void wpas_event_dfs_radar_detected(struct wpa_supplicant *wpa_s,
1439 struct dfs_event *radar)
1440{
1441 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1442 return;
1443 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
1444 hostapd_dfs_radar_detected(wpa_s->ap_iface, radar->freq,
1445 radar->ht_enabled, radar->chan_offset,
1446 radar->chan_width,
1447 radar->cf1, radar->cf2);
1448}
1449
1450
1451void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
1452 struct dfs_event *radar)
1453{
1454 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1455 return;
1456 wpa_printf(MSG_DEBUG, "DFS CAC started on %d MHz", radar->freq);
1457 hostapd_dfs_start_cac(wpa_s->ap_iface, radar->freq,
1458 radar->ht_enabled, radar->chan_offset,
1459 radar->chan_width, radar->cf1, radar->cf2);
1460}
1461
1462
1463void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
1464 struct dfs_event *radar)
1465{
1466 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1467 return;
1468 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
1469 hostapd_dfs_complete_cac(wpa_s->ap_iface, 1, radar->freq,
1470 radar->ht_enabled, radar->chan_offset,
1471 radar->chan_width, radar->cf1, radar->cf2);
1472}
1473
1474
1475void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
1476 struct dfs_event *radar)
1477{
1478 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1479 return;
1480 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
1481 hostapd_dfs_complete_cac(wpa_s->ap_iface, 0, radar->freq,
1482 radar->ht_enabled, radar->chan_offset,
1483 radar->chan_width, radar->cf1, radar->cf2);
1484}
1485
1486
1487void wpas_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s,
1488 struct dfs_event *radar)
1489{
1490 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1491 return;
1492 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
1493 hostapd_dfs_nop_finished(wpa_s->ap_iface, radar->freq,
1494 radar->ht_enabled, radar->chan_offset,
1495 radar->chan_width, radar->cf1, radar->cf2);
1496}
1497#endif /* NEED_AP_MLME */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001498
1499
1500void ap_periodic(struct wpa_supplicant *wpa_s)
1501{
1502 if (wpa_s->ap_iface)
1503 hostapd_periodic_iface(wpa_s->ap_iface);
1504}