blob: cefb3dce02397f7bbed5f396e9adb131dd83728c [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
59 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel);
60 if (!center_chan)
61 goto no_vht;
62
63 /* Use 80 MHz channel */
64 conf->vht_oper_chwidth = 1;
65 conf->vht_oper_centr_freq_seg0_idx = center_chan;
66 return;
67
68no_vht:
69 conf->vht_oper_centr_freq_seg0_idx =
70 channel + conf->secondary_channel * 2;
Dmitry Shmidt21de2142014-04-08 10:50:52 -070071#else /* CONFIG_P2P */
72 conf->vht_oper_centr_freq_seg0_idx =
73 conf->channel + conf->secondary_channel * 2;
74#endif /* CONFIG_P2P */
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070075}
76#endif /* CONFIG_IEEE80211N */
77
78
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080079int wpa_supplicant_conf_ap_ht(struct wpa_supplicant *wpa_s,
80 struct wpa_ssid *ssid,
81 struct hostapd_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070082{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080083 conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency,
84 &conf->channel);
85
86 if (conf->hw_mode == NUM_HOSTAPD_MODES) {
87 wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
88 ssid->frequency);
89 return -1;
90 }
91
Dmitry Shmidtc55524a2011-07-07 11:18:38 -070092 /* TODO: enable HT40 if driver supports it;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070093 * drop to 11b if driver does not support 11g */
94
Dmitry Shmidtc55524a2011-07-07 11:18:38 -070095#ifdef CONFIG_IEEE80211N
96 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080097 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
98 * and a mask of allowed capabilities within conf->ht_capab.
Dmitry Shmidtc55524a2011-07-07 11:18:38 -070099 * Using default config settings for: conf->ht_op_mode_fixed,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800100 * conf->secondary_channel, conf->require_ht
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700101 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800102 if (wpa_s->hw.modes) {
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700103 struct hostapd_hw_modes *mode = NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700104 int i, no_ht = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800105 for (i = 0; i < wpa_s->hw.num_modes; i++) {
106 if (wpa_s->hw.modes[i].mode == conf->hw_mode) {
107 mode = &wpa_s->hw.modes[i];
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700108 break;
109 }
110 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700111
112#ifdef CONFIG_HT_OVERRIDES
113 if (ssid->disable_ht) {
114 conf->ieee80211n = 0;
115 conf->ht_capab = 0;
116 no_ht = 1;
117 }
118#endif /* CONFIG_HT_OVERRIDES */
119
120 if (!no_ht && mode && mode->ht_capab) {
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700121 conf->ieee80211n = 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700122#ifdef CONFIG_P2P
123 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
124 (mode->ht_capab &
125 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
126 ssid->ht40)
127 conf->secondary_channel =
128 wpas_p2p_get_ht40_mode(wpa_s, mode,
129 conf->channel);
130 if (conf->secondary_channel)
131 conf->ht_capab |=
132 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
133#endif /* CONFIG_P2P */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800134
135 /*
136 * white-list capabilities that won't cause issues
137 * to connecting stations, while leaving the current
138 * capabilities intact (currently disabled SMPS).
139 */
140 conf->ht_capab |= mode->ht_capab &
141 (HT_CAP_INFO_GREEN_FIELD |
142 HT_CAP_INFO_SHORT_GI20MHZ |
143 HT_CAP_INFO_SHORT_GI40MHZ |
144 HT_CAP_INFO_RX_STBC_MASK |
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800145 HT_CAP_INFO_TX_STBC |
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800146 HT_CAP_INFO_MAX_AMSDU_SIZE);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700147
148 if (mode->vht_capab && ssid->vht) {
149 conf->ieee80211ac = 1;
150 wpas_conf_ap_vht(wpa_s, conf, mode);
151 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800152 }
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700153 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800154
155 if (conf->secondary_channel) {
156 struct wpa_supplicant *iface;
157
158 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
159 {
160 if (iface == wpa_s ||
161 iface->wpa_state < WPA_AUTHENTICATING ||
162 (int) iface->assoc_freq != ssid->frequency)
163 continue;
164
165 /*
166 * Do not allow 40 MHz co-ex PRI/SEC switch to force us
167 * to change our PRI channel since we have an existing,
168 * concurrent connection on that channel and doing
169 * multi-channel concurrency is likely to cause more
170 * harm than using different PRI/SEC selection in
171 * environment with multiple BSSes on these two channels
172 * with mixed 20 MHz or PRI channel selection.
173 */
174 conf->no_pri_sec_switch = 1;
175 }
176 }
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700177#endif /* CONFIG_IEEE80211N */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800178
179 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800180}
181
182
183static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
184 struct wpa_ssid *ssid,
185 struct hostapd_config *conf)
186{
187 struct hostapd_bss_config *bss = conf->bss[0];
188
189 conf->driver = wpa_s->driver;
190
191 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
192
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800193 if (wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800194 return -1;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700195
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800196 if (ieee80211_is_dfs(ssid->frequency) && wpa_s->conf->country[0]) {
197 conf->ieee80211h = 1;
198 conf->ieee80211d = 1;
199 conf->country[0] = wpa_s->conf->country[0];
200 conf->country[1] = wpa_s->conf->country[1];
201 }
202
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700203#ifdef CONFIG_P2P
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700204 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
205 (ssid->mode == WPAS_MODE_P2P_GO ||
206 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700207 /* Remove 802.11b rates from supported and basic rate sets */
208 int *list = os_malloc(4 * sizeof(int));
209 if (list) {
210 list[0] = 60;
211 list[1] = 120;
212 list[2] = 240;
213 list[3] = -1;
214 }
215 conf->basic_rates = list;
216
217 list = os_malloc(9 * sizeof(int));
218 if (list) {
219 list[0] = 60;
220 list[1] = 90;
221 list[2] = 120;
222 list[3] = 180;
223 list[4] = 240;
224 list[5] = 360;
225 list[6] = 480;
226 list[7] = 540;
227 list[8] = -1;
228 }
229 conf->supported_rates = list;
230 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800231
232 bss->isolate = !wpa_s->conf->p2p_intra_bss;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700233 bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800234
235 if (ssid->p2p_group) {
236 os_memcpy(bss->ip_addr_go, wpa_s->parent->conf->ip_addr_go, 4);
237 os_memcpy(bss->ip_addr_mask, wpa_s->parent->conf->ip_addr_mask,
238 4);
239 os_memcpy(bss->ip_addr_start,
240 wpa_s->parent->conf->ip_addr_start, 4);
241 os_memcpy(bss->ip_addr_end, wpa_s->parent->conf->ip_addr_end,
242 4);
243 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700244#endif /* CONFIG_P2P */
245
246 if (ssid->ssid_len == 0) {
247 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
248 return -1;
249 }
250 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700251 bss->ssid.ssid_len = ssid->ssid_len;
252 bss->ssid.ssid_set = 1;
253
Dmitry Shmidt04949592012-07-19 12:16:46 -0700254 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
255
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800256 if (ssid->auth_alg)
257 bss->auth_algs = ssid->auth_alg;
258
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700259 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
260 bss->wpa = ssid->proto;
261 bss->wpa_key_mgmt = ssid->key_mgmt;
262 bss->wpa_pairwise = ssid->pairwise_cipher;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800263 if (ssid->psk_set) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800264 bin_clear_free(bss->ssid.wpa_psk, sizeof(*bss->ssid.wpa_psk));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700265 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
266 if (bss->ssid.wpa_psk == NULL)
267 return -1;
268 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
269 bss->ssid.wpa_psk->group = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800270 } else if (ssid->passphrase) {
271 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800272 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
273 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
274 struct hostapd_wep_keys *wep = &bss->ssid.wep;
275 int i;
276 for (i = 0; i < NUM_WEP_KEYS; i++) {
277 if (ssid->wep_key_len[i] == 0)
278 continue;
279 wep->key[i] = os_malloc(ssid->wep_key_len[i]);
280 if (wep->key[i] == NULL)
281 return -1;
282 os_memcpy(wep->key[i], ssid->wep_key[i],
283 ssid->wep_key_len[i]);
284 wep->len[i] = ssid->wep_key_len[i];
285 }
286 wep->idx = ssid->wep_tx_keyidx;
287 wep->keys_set = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700288 }
289
Dmitry Shmidt04949592012-07-19 12:16:46 -0700290 if (ssid->ap_max_inactivity)
291 bss->ap_max_inactivity = ssid->ap_max_inactivity;
292
293 if (ssid->dtim_period)
294 bss->dtim_period = ssid->dtim_period;
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -0800295 else if (wpa_s->conf->dtim_period)
296 bss->dtim_period = wpa_s->conf->dtim_period;
297
298 if (ssid->beacon_int)
299 conf->beacon_int = ssid->beacon_int;
300 else if (wpa_s->conf->beacon_int)
301 conf->beacon_int = wpa_s->conf->beacon_int;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700302
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800303#ifdef CONFIG_P2P
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800304 if (ssid->mode == WPAS_MODE_P2P_GO ||
305 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
306 if (wpa_s->conf->p2p_go_ctwindow > conf->beacon_int) {
307 wpa_printf(MSG_INFO,
308 "CTWindow (%d) is bigger than beacon interval (%d) - avoid configuring it",
309 wpa_s->conf->p2p_go_ctwindow,
310 conf->beacon_int);
311 conf->p2p_go_ctwindow = 0;
312 } else {
313 conf->p2p_go_ctwindow = wpa_s->conf->p2p_go_ctwindow;
314 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800315 }
316#endif /* CONFIG_P2P */
317
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800318 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
319 bss->rsn_pairwise = bss->wpa_pairwise;
320 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
321 bss->rsn_pairwise);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700322
323 if (bss->wpa && bss->ieee802_1x)
324 bss->ssid.security_policy = SECURITY_WPA;
325 else if (bss->wpa)
326 bss->ssid.security_policy = SECURITY_WPA_PSK;
327 else if (bss->ieee802_1x) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800328 int cipher = WPA_CIPHER_NONE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700329 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
330 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800331 if (bss->default_wep_key_len)
332 cipher = bss->default_wep_key_len >= 13 ?
333 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
334 bss->wpa_group = cipher;
335 bss->wpa_pairwise = cipher;
336 bss->rsn_pairwise = cipher;
337 } else if (bss->ssid.wep.keys_set) {
338 int cipher = WPA_CIPHER_WEP40;
339 if (bss->ssid.wep.len[0] >= 13)
340 cipher = WPA_CIPHER_WEP104;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700341 bss->ssid.security_policy = SECURITY_STATIC_WEP;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800342 bss->wpa_group = cipher;
343 bss->wpa_pairwise = cipher;
344 bss->rsn_pairwise = cipher;
345 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700346 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800347 bss->wpa_group = WPA_CIPHER_NONE;
348 bss->wpa_pairwise = WPA_CIPHER_NONE;
349 bss->rsn_pairwise = WPA_CIPHER_NONE;
350 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700351
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700352 if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
353 (bss->wpa_group == WPA_CIPHER_CCMP ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800354 bss->wpa_group == WPA_CIPHER_GCMP ||
355 bss->wpa_group == WPA_CIPHER_CCMP_256 ||
356 bss->wpa_group == WPA_CIPHER_GCMP_256)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700357 /*
358 * Strong ciphers do not need frequent rekeying, so increase
359 * the default GTK rekeying period to 24 hours.
360 */
361 bss->wpa_group_rekey = 86400;
362 }
363
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700364#ifdef CONFIG_IEEE80211W
365 if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT)
366 bss->ieee80211w = ssid->ieee80211w;
367#endif /* CONFIG_IEEE80211W */
368
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700369#ifdef CONFIG_WPS
370 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800371 * Enable WPS by default for open and WPA/WPA2-Personal network, but
372 * require user interaction to actually use it. Only the internal
373 * Registrar is supported.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700374 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800375 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
376 bss->ssid.security_policy != SECURITY_PLAINTEXT)
377 goto no_wps;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800378 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800379 (!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ||
380 !(bss->wpa & 2)))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800381 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
382 * configuration */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700383 bss->eap_server = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700384
385 if (!ssid->ignore_broadcast_ssid)
386 bss->wps_state = 2;
387
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700388 bss->ap_setup_locked = 2;
389 if (wpa_s->conf->config_methods)
390 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
391 os_memcpy(bss->device_type, wpa_s->conf->device_type,
392 WPS_DEV_TYPE_LEN);
393 if (wpa_s->conf->device_name) {
394 bss->device_name = os_strdup(wpa_s->conf->device_name);
395 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
396 }
397 if (wpa_s->conf->manufacturer)
398 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
399 if (wpa_s->conf->model_name)
400 bss->model_name = os_strdup(wpa_s->conf->model_name);
401 if (wpa_s->conf->model_number)
402 bss->model_number = os_strdup(wpa_s->conf->model_number);
403 if (wpa_s->conf->serial_number)
404 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
405 if (is_nil_uuid(wpa_s->conf->uuid))
406 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
407 else
408 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
409 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700410 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800411no_wps:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700412#endif /* CONFIG_WPS */
413
414 if (wpa_s->max_stations &&
415 wpa_s->max_stations < wpa_s->conf->max_num_sta)
416 bss->max_num_sta = wpa_s->max_stations;
417 else
418 bss->max_num_sta = wpa_s->conf->max_num_sta;
419
420 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
421
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700422 if (wpa_s->conf->ap_vendor_elements) {
423 bss->vendor_elements =
424 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
425 }
426
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700427 return 0;
428}
429
430
431static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
432{
433#ifdef CONFIG_P2P
434 struct wpa_supplicant *wpa_s = ctx;
435 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700436
437 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700438 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700439 return;
Dmitry Shmidt18463232014-01-24 12:29:41 -0800440 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
441 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700442 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
443 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700444 buf + IEEE80211_HDRLEN + 1,
445 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700446#endif /* CONFIG_P2P */
447}
448
449
450static void ap_wps_event_cb(void *ctx, enum wps_event event,
451 union wps_event_data *data)
452{
453#ifdef CONFIG_P2P
454 struct wpa_supplicant *wpa_s = ctx;
455
Jouni Malinen75ecf522011-06-27 15:19:46 -0700456 if (event == WPS_EV_FAIL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700457 struct wps_event_fail *fail = &data->fail;
458
Jouni Malinen75ecf522011-06-27 15:19:46 -0700459 if (wpa_s->parent && wpa_s->parent != wpa_s &&
460 wpa_s == wpa_s->global->p2p_group_formation) {
461 /*
462 * src/ap/wps_hostapd.c has already sent this on the
463 * main interface, so only send on the parent interface
464 * here if needed.
465 */
466 wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
467 "msg=%d config_error=%d",
468 fail->msg, fail->config_error);
469 }
470 wpas_p2p_wps_failed(wpa_s, fail);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700471 }
472#endif /* CONFIG_P2P */
473}
474
475
476static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800477 int authorized, const u8 *p2p_dev_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700478{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800479 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700480}
481
482
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700483#ifdef CONFIG_P2P
484static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
485 const u8 *psk, size_t psk_len)
486{
487
488 struct wpa_supplicant *wpa_s = ctx;
489 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
490 return;
491 wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
492}
493#endif /* CONFIG_P2P */
494
495
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700496static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
497{
498#ifdef CONFIG_P2P
499 struct wpa_supplicant *wpa_s = ctx;
500 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700501
502 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700503 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700504 return -1;
505 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
506 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700507 buf + IEEE80211_HDRLEN + 1,
508 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700509#endif /* CONFIG_P2P */
510 return 0;
511}
512
513
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800514static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700515 const u8 *bssid, const u8 *ie, size_t ie_len,
516 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700517{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700518 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700519 unsigned int freq = 0;
520
521 if (wpa_s->ap_iface)
522 freq = wpa_s->ap_iface->freq;
523
Dmitry Shmidt04949592012-07-19 12:16:46 -0700524 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700525 freq, ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700526}
527
528
529static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
530 const u8 *uuid_e)
531{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700532 struct wpa_supplicant *wpa_s = ctx;
533 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700534}
535
536
537static void wpas_ap_configured_cb(void *ctx)
538{
539 struct wpa_supplicant *wpa_s = ctx;
540
541 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
542
543 if (wpa_s->ap_configured_cb)
544 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
545 wpa_s->ap_configured_cb_data);
546}
547
548
549int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
550 struct wpa_ssid *ssid)
551{
552 struct wpa_driver_associate_params params;
553 struct hostapd_iface *hapd_iface;
554 struct hostapd_config *conf;
555 size_t i;
556
557 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
558 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
559 return -1;
560 }
561
562 wpa_supplicant_ap_deinit(wpa_s);
563
564 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
565 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
566
567 os_memset(&params, 0, sizeof(params));
568 params.ssid = ssid->ssid;
569 params.ssid_len = ssid->ssid_len;
570 switch (ssid->mode) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700571 case WPAS_MODE_AP:
572 case WPAS_MODE_P2P_GO:
573 case WPAS_MODE_P2P_GROUP_FORMATION:
574 params.mode = IEEE80211_MODE_AP;
575 break;
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800576 default:
577 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700578 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700579 if (ssid->frequency == 0)
580 ssid->frequency = 2462; /* default channel 11 */
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700581 params.freq.freq = ssid->frequency;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700582
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800583 params.wpa_proto = ssid->proto;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700584 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
585 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
586 else
587 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800588 params.key_mgmt_suite = wpa_s->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700589
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800590 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
591 1);
592 if (wpa_s->pairwise_cipher < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700593 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
594 "cipher.");
595 return -1;
596 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800597 params.pairwise_suite = wpa_s->pairwise_cipher;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700598 params.group_suite = params.pairwise_suite;
599
600#ifdef CONFIG_P2P
601 if (ssid->mode == WPAS_MODE_P2P_GO ||
602 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
603 params.p2p = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700604#endif /* CONFIG_P2P */
605
606 if (wpa_s->parent->set_ap_uapsd)
607 params.uapsd = wpa_s->parent->ap_uapsd;
Dmitry Shmidtec58b162014-02-19 12:44:18 -0800608 else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
609 params.uapsd = 1; /* mandatory for P2P GO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700610 else
611 params.uapsd = -1;
612
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800613 if (ieee80211_is_dfs(params.freq.freq))
614 params.freq.freq = 0; /* set channel after CAC */
615
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700616 if (wpa_drv_associate(wpa_s, &params) < 0) {
617 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
618 return -1;
619 }
620
621 wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
622 if (hapd_iface == NULL)
623 return -1;
624 hapd_iface->owner = wpa_s;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800625 hapd_iface->drv_flags = wpa_s->drv_flags;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800626 hapd_iface->smps_modes = wpa_s->drv_smps_modes;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800627 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700628 hapd_iface->extended_capa = wpa_s->extended_capa;
629 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
630 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700631
632 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
633 if (conf == NULL) {
634 wpa_supplicant_ap_deinit(wpa_s);
635 return -1;
636 }
637
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700638 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
639 wpa_s->conf->wmm_ac_params,
640 sizeof(wpa_s->conf->wmm_ac_params));
641
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800642 if (params.uapsd > 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800643 conf->bss[0]->wmm_enabled = 1;
644 conf->bss[0]->wmm_uapsd = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800645 }
646
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700647 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
648 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
649 wpa_supplicant_ap_deinit(wpa_s);
650 return -1;
651 }
652
653#ifdef CONFIG_P2P
654 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800655 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700656 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800657 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700658 P2P_GROUP_FORMATION;
659#endif /* CONFIG_P2P */
660
661 hapd_iface->num_bss = conf->num_bss;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700662 hapd_iface->bss = os_calloc(conf->num_bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700663 sizeof(struct hostapd_data *));
664 if (hapd_iface->bss == NULL) {
665 wpa_supplicant_ap_deinit(wpa_s);
666 return -1;
667 }
668
669 for (i = 0; i < conf->num_bss; i++) {
670 hapd_iface->bss[i] =
671 hostapd_alloc_bss_data(hapd_iface, conf,
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800672 conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700673 if (hapd_iface->bss[i] == NULL) {
674 wpa_supplicant_ap_deinit(wpa_s);
675 return -1;
676 }
677
678 hapd_iface->bss[i]->msg_ctx = wpa_s;
Dmitry Shmidt497c1d52011-07-21 15:19:46 -0700679 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->parent;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700680 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
681 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
682 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
683 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
684 hostapd_register_probereq_cb(hapd_iface->bss[i],
685 ap_probe_req_rx, wpa_s);
686 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
687 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
688 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
689 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
690 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
691 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
692#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700693 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
694 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700695 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700696 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
697 ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700698#endif /* CONFIG_P2P */
699 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
700 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800701#ifdef CONFIG_TESTING_OPTIONS
702 hapd_iface->bss[i]->ext_eapol_frame_io =
703 wpa_s->ext_eapol_frame_io;
704#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700705 }
706
707 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
708 hapd_iface->bss[0]->driver = wpa_s->driver;
709 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
710
711 wpa_s->current_ssid = ssid;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700712 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700713 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
714 wpa_s->assoc_freq = ssid->frequency;
715
716 if (hostapd_setup_interface(wpa_s->ap_iface)) {
717 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
718 wpa_supplicant_ap_deinit(wpa_s);
719 return -1;
720 }
721
722 return 0;
723}
724
725
726void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
727{
728#ifdef CONFIG_WPS
729 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
730#endif /* CONFIG_WPS */
731
732 if (wpa_s->ap_iface == NULL)
733 return;
734
735 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700736 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700737 wpa_s->assoc_freq = 0;
Dmitry Shmidt43cb5782014-06-16 16:23:22 -0700738 wpas_p2p_ap_deinit(wpa_s);
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800739 wpa_s->ap_iface->driver_ap_teardown =
740 !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
741
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700742 hostapd_interface_deinit(wpa_s->ap_iface);
743 hostapd_interface_free(wpa_s->ap_iface);
744 wpa_s->ap_iface = NULL;
745 wpa_drv_deinit_ap(wpa_s);
Dmitry Shmidtf73259c2015-03-17 11:00:54 -0700746 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
747 " reason=%d locally_generated=1",
748 MAC2STR(wpa_s->own_addr), WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700749}
750
751
752void ap_tx_status(void *ctx, const u8 *addr,
753 const u8 *buf, size_t len, int ack)
754{
755#ifdef NEED_AP_MLME
756 struct wpa_supplicant *wpa_s = ctx;
757 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
758#endif /* NEED_AP_MLME */
759}
760
761
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800762void ap_eapol_tx_status(void *ctx, const u8 *dst,
763 const u8 *data, size_t len, int ack)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700764{
765#ifdef NEED_AP_MLME
766 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800767 if (!wpa_s->ap_iface)
768 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800769 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
770#endif /* NEED_AP_MLME */
771}
772
773
774void ap_client_poll_ok(void *ctx, const u8 *addr)
775{
776#ifdef NEED_AP_MLME
777 struct wpa_supplicant *wpa_s = ctx;
778 if (wpa_s->ap_iface)
779 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
780#endif /* NEED_AP_MLME */
781}
782
783
784void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
785{
786#ifdef NEED_AP_MLME
787 struct wpa_supplicant *wpa_s = ctx;
788 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700789#endif /* NEED_AP_MLME */
790}
791
792
793void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
794{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800795#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700796 struct wpa_supplicant *wpa_s = ctx;
797 struct hostapd_frame_info fi;
798 os_memset(&fi, 0, sizeof(fi));
799 fi.datarate = rx_mgmt->datarate;
800 fi.ssi_signal = rx_mgmt->ssi_signal;
801 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
802 rx_mgmt->frame_len, &fi);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800803#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700804}
805
806
807void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
808{
809#ifdef NEED_AP_MLME
810 struct wpa_supplicant *wpa_s = ctx;
811 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
812#endif /* NEED_AP_MLME */
813}
814
815
816void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
817 const u8 *src_addr, const u8 *buf, size_t len)
818{
819 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
820}
821
822
823#ifdef CONFIG_WPS
824
825int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
826 const u8 *p2p_dev_addr)
827{
828 if (!wpa_s->ap_iface)
829 return -1;
830 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
831 p2p_dev_addr);
832}
833
834
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700835int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
836{
837 struct wps_registrar *reg;
838 int reg_sel = 0, wps_sta = 0;
839
840 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
841 return -1;
842
843 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
844 reg_sel = wps_registrar_wps_cancel(reg);
845 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
Dmitry Shmidt04949592012-07-19 12:16:46 -0700846 ap_sta_wps_cancel, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700847
848 if (!reg_sel && !wps_sta) {
849 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
850 "time");
851 return -1;
852 }
853
854 /*
855 * There are 2 cases to return wps cancel as success:
856 * 1. When wps cancel was initiated but no connection has been
857 * established with client yet.
858 * 2. Client is in the middle of exchanging WPS messages.
859 */
860
861 return 0;
862}
863
864
865int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800866 const char *pin, char *buf, size_t buflen,
867 int timeout)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700868{
869 int ret, ret_len = 0;
870
871 if (!wpa_s->ap_iface)
872 return -1;
873
874 if (pin == NULL) {
875 unsigned int rpin = wps_generate_pin();
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800876 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800877 if (os_snprintf_error(buflen, ret_len))
878 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700879 pin = buf;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800880 } else if (buf) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700881 ret_len = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800882 if (os_snprintf_error(buflen, ret_len))
883 return -1;
884 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700885
886 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800887 timeout);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700888 if (ret)
889 return -1;
890 return ret_len;
891}
892
893
894static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
895{
896 struct wpa_supplicant *wpa_s = eloop_data;
897 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
898 wpas_wps_ap_pin_disable(wpa_s);
899}
900
901
902static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
903{
904 struct hostapd_data *hapd;
905
906 if (wpa_s->ap_iface == NULL)
907 return;
908 hapd = wpa_s->ap_iface->bss[0];
909 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
910 hapd->ap_pin_failures = 0;
911 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
912 if (timeout > 0)
913 eloop_register_timeout(timeout, 0,
914 wpas_wps_ap_pin_timeout, wpa_s, NULL);
915}
916
917
918void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
919{
920 struct hostapd_data *hapd;
921
922 if (wpa_s->ap_iface == NULL)
923 return;
924 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
925 hapd = wpa_s->ap_iface->bss[0];
926 os_free(hapd->conf->ap_pin);
927 hapd->conf->ap_pin = NULL;
928 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
929}
930
931
932const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
933{
934 struct hostapd_data *hapd;
935 unsigned int pin;
936 char pin_txt[9];
937
938 if (wpa_s->ap_iface == NULL)
939 return NULL;
940 hapd = wpa_s->ap_iface->bss[0];
941 pin = wps_generate_pin();
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800942 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700943 os_free(hapd->conf->ap_pin);
944 hapd->conf->ap_pin = os_strdup(pin_txt);
945 if (hapd->conf->ap_pin == NULL)
946 return NULL;
947 wpas_wps_ap_pin_enable(wpa_s, timeout);
948
949 return hapd->conf->ap_pin;
950}
951
952
953const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
954{
955 struct hostapd_data *hapd;
956 if (wpa_s->ap_iface == NULL)
957 return NULL;
958 hapd = wpa_s->ap_iface->bss[0];
959 return hapd->conf->ap_pin;
960}
961
962
963int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
964 int timeout)
965{
966 struct hostapd_data *hapd;
967 char pin_txt[9];
968 int ret;
969
970 if (wpa_s->ap_iface == NULL)
971 return -1;
972 hapd = wpa_s->ap_iface->bss[0];
973 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800974 if (os_snprintf_error(sizeof(pin_txt), ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700975 return -1;
976 os_free(hapd->conf->ap_pin);
977 hapd->conf->ap_pin = os_strdup(pin_txt);
978 if (hapd->conf->ap_pin == NULL)
979 return -1;
980 wpas_wps_ap_pin_enable(wpa_s, timeout);
981
982 return 0;
983}
984
985
986void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
987{
988 struct hostapd_data *hapd;
989
990 if (wpa_s->ap_iface == NULL)
991 return;
992 hapd = wpa_s->ap_iface->bss[0];
993
994 /*
995 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
996 * PIN if this happens multiple times to slow down brute force attacks.
997 */
998 hapd->ap_pin_failures++;
999 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
1000 hapd->ap_pin_failures);
1001 if (hapd->ap_pin_failures < 3)
1002 return;
1003
1004 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
1005 hapd->ap_pin_failures = 0;
1006 os_free(hapd->conf->ap_pin);
1007 hapd->conf->ap_pin = NULL;
1008}
1009
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001010
1011#ifdef CONFIG_WPS_NFC
1012
1013struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
1014 int ndef)
1015{
1016 struct hostapd_data *hapd;
1017
1018 if (wpa_s->ap_iface == NULL)
1019 return NULL;
1020 hapd = wpa_s->ap_iface->bss[0];
1021 return hostapd_wps_nfc_config_token(hapd, ndef);
1022}
1023
1024
1025struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
1026 int ndef)
1027{
1028 struct hostapd_data *hapd;
1029
1030 if (wpa_s->ap_iface == NULL)
1031 return NULL;
1032 hapd = wpa_s->ap_iface->bss[0];
1033 return hostapd_wps_nfc_hs_cr(hapd, ndef);
1034}
1035
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001036
1037int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
1038 const struct wpabuf *req,
1039 const struct wpabuf *sel)
1040{
1041 struct hostapd_data *hapd;
1042
1043 if (wpa_s->ap_iface == NULL)
1044 return -1;
1045 hapd = wpa_s->ap_iface->bss[0];
1046 return hostapd_wps_nfc_report_handover(hapd, req, sel);
1047}
1048
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001049#endif /* CONFIG_WPS_NFC */
1050
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001051#endif /* CONFIG_WPS */
1052
1053
1054#ifdef CONFIG_CTRL_IFACE
1055
1056int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
1057 char *buf, size_t buflen)
1058{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001059 struct hostapd_data *hapd;
1060
1061 if (wpa_s->ap_iface)
1062 hapd = wpa_s->ap_iface->bss[0];
1063 else if (wpa_s->ifmsh)
1064 hapd = wpa_s->ifmsh->bss[0];
1065 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001066 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001067 return hostapd_ctrl_iface_sta_first(hapd, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001068}
1069
1070
1071int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
1072 char *buf, size_t buflen)
1073{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001074 struct hostapd_data *hapd;
1075
1076 if (wpa_s->ap_iface)
1077 hapd = wpa_s->ap_iface->bss[0];
1078 else if (wpa_s->ifmsh)
1079 hapd = wpa_s->ifmsh->bss[0];
1080 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001081 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001082 return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001083}
1084
1085
1086int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
1087 char *buf, size_t buflen)
1088{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001089 struct hostapd_data *hapd;
1090
1091 if (wpa_s->ap_iface)
1092 hapd = wpa_s->ap_iface->bss[0];
1093 else if (wpa_s->ifmsh)
1094 hapd = wpa_s->ifmsh->bss[0];
1095 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001096 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001097 return hostapd_ctrl_iface_sta_next(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001098}
1099
1100
Dmitry Shmidt04949592012-07-19 12:16:46 -07001101int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1102 const char *txtaddr)
1103{
1104 if (wpa_s->ap_iface == NULL)
1105 return -1;
1106 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1107 txtaddr);
1108}
1109
1110
1111int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1112 const char *txtaddr)
1113{
1114 if (wpa_s->ap_iface == NULL)
1115 return -1;
1116 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1117 txtaddr);
1118}
1119
1120
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001121int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1122 size_t buflen, int verbose)
1123{
1124 char *pos = buf, *end = buf + buflen;
1125 int ret;
1126 struct hostapd_bss_config *conf;
1127
1128 if (wpa_s->ap_iface == NULL)
1129 return -1;
1130
1131 conf = wpa_s->ap_iface->bss[0]->conf;
1132 if (conf->wpa == 0)
1133 return 0;
1134
1135 ret = os_snprintf(pos, end - pos,
1136 "pairwise_cipher=%s\n"
1137 "group_cipher=%s\n"
1138 "key_mgmt=%s\n",
1139 wpa_cipher_txt(conf->rsn_pairwise),
1140 wpa_cipher_txt(conf->wpa_group),
1141 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1142 conf->wpa));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001143 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001144 return pos - buf;
1145 pos += ret;
1146 return pos - buf;
1147}
1148
1149#endif /* CONFIG_CTRL_IFACE */
1150
1151
1152int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1153{
1154 struct hostapd_iface *iface = wpa_s->ap_iface;
1155 struct wpa_ssid *ssid = wpa_s->current_ssid;
1156 struct hostapd_data *hapd;
1157
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001158 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1159 ssid->mode == WPAS_MODE_INFRA ||
1160 ssid->mode == WPAS_MODE_IBSS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001161 return -1;
1162
1163#ifdef CONFIG_P2P
1164 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001165 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001166 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001167 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001168 P2P_GROUP_FORMATION;
1169#endif /* CONFIG_P2P */
1170
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001171 hapd = iface->bss[0];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001172 if (hapd->drv_priv == NULL)
1173 return -1;
1174 ieee802_11_set_beacons(iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001175 hostapd_set_ap_wps_ie(hapd);
1176
1177 return 0;
1178}
1179
1180
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001181int ap_switch_channel(struct wpa_supplicant *wpa_s,
1182 struct csa_settings *settings)
1183{
1184#ifdef NEED_AP_MLME
1185 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1186 return -1;
1187
1188 return hostapd_switch_channel(wpa_s->ap_iface->bss[0], settings);
1189#else /* NEED_AP_MLME */
1190 return -1;
1191#endif /* NEED_AP_MLME */
1192}
1193
1194
Dmitry Shmidt83474442015-04-15 13:47:09 -07001195#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001196int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1197{
1198 struct csa_settings settings;
1199 int ret = hostapd_parse_csa_settings(pos, &settings);
1200
1201 if (ret)
1202 return ret;
1203
1204 return ap_switch_channel(wpa_s, &settings);
1205}
Dmitry Shmidt83474442015-04-15 13:47:09 -07001206#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001207
1208
Dmitry Shmidt04949592012-07-19 12:16:46 -07001209void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001210 int offset, int width, int cf1, int cf2)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001211{
1212 if (!wpa_s->ap_iface)
1213 return;
1214
1215 wpa_s->assoc_freq = freq;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001216 if (wpa_s->current_ssid)
1217 wpa_s->current_ssid->frequency = freq;
1218 hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht,
1219 offset, width, cf1, cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001220}
1221
1222
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001223int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1224 const u8 *addr)
1225{
1226 struct hostapd_data *hapd;
1227 struct hostapd_bss_config *conf;
1228
1229 if (!wpa_s->ap_iface)
1230 return -1;
1231
1232 if (addr)
1233 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1234 MAC2STR(addr));
1235 else
1236 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1237
1238 hapd = wpa_s->ap_iface->bss[0];
1239 conf = hapd->conf;
1240
1241 os_free(conf->accept_mac);
1242 conf->accept_mac = NULL;
1243 conf->num_accept_mac = 0;
1244 os_free(conf->deny_mac);
1245 conf->deny_mac = NULL;
1246 conf->num_deny_mac = 0;
1247
1248 if (addr == NULL) {
1249 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1250 return 0;
1251 }
1252
1253 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1254 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1255 if (conf->accept_mac == NULL)
1256 return -1;
1257 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1258 conf->num_accept_mac = 1;
1259
1260 return 0;
1261}
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001262
1263
1264#ifdef CONFIG_WPS_NFC
1265int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1266 const struct wpabuf *pw, const u8 *pubkey_hash)
1267{
1268 struct hostapd_data *hapd;
1269 struct wps_context *wps;
1270
1271 if (!wpa_s->ap_iface)
1272 return -1;
1273 hapd = wpa_s->ap_iface->bss[0];
1274 wps = hapd->wps;
1275
1276 if (wpa_s->parent->conf->wps_nfc_dh_pubkey == NULL ||
1277 wpa_s->parent->conf->wps_nfc_dh_privkey == NULL) {
1278 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1279 return -1;
1280 }
1281
1282 dh5_free(wps->dh_ctx);
1283 wpabuf_free(wps->dh_pubkey);
1284 wpabuf_free(wps->dh_privkey);
1285 wps->dh_privkey = wpabuf_dup(
1286 wpa_s->parent->conf->wps_nfc_dh_privkey);
1287 wps->dh_pubkey = wpabuf_dup(
1288 wpa_s->parent->conf->wps_nfc_dh_pubkey);
1289 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1290 wps->dh_ctx = NULL;
1291 wpabuf_free(wps->dh_pubkey);
1292 wps->dh_pubkey = NULL;
1293 wpabuf_free(wps->dh_privkey);
1294 wps->dh_privkey = NULL;
1295 return -1;
1296 }
1297 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1298 if (wps->dh_ctx == NULL)
1299 return -1;
1300
1301 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1302 pw_id,
1303 pw ? wpabuf_head(pw) : NULL,
1304 pw ? wpabuf_len(pw) : 0, 1);
1305}
1306#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001307
1308
Dmitry Shmidt83474442015-04-15 13:47:09 -07001309#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001310int wpas_ap_stop_ap(struct wpa_supplicant *wpa_s)
1311{
1312 struct hostapd_data *hapd;
1313
1314 if (!wpa_s->ap_iface)
1315 return -1;
1316 hapd = wpa_s->ap_iface->bss[0];
1317 return hostapd_ctrl_iface_stop_ap(hapd);
1318}
Dmitry Shmidt83474442015-04-15 13:47:09 -07001319#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001320
1321
1322#ifdef NEED_AP_MLME
1323void wpas_event_dfs_radar_detected(struct wpa_supplicant *wpa_s,
1324 struct dfs_event *radar)
1325{
1326 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1327 return;
1328 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
1329 hostapd_dfs_radar_detected(wpa_s->ap_iface, radar->freq,
1330 radar->ht_enabled, radar->chan_offset,
1331 radar->chan_width,
1332 radar->cf1, radar->cf2);
1333}
1334
1335
1336void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
1337 struct dfs_event *radar)
1338{
1339 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1340 return;
1341 wpa_printf(MSG_DEBUG, "DFS CAC started on %d MHz", radar->freq);
1342 hostapd_dfs_start_cac(wpa_s->ap_iface, radar->freq,
1343 radar->ht_enabled, radar->chan_offset,
1344 radar->chan_width, radar->cf1, radar->cf2);
1345}
1346
1347
1348void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
1349 struct dfs_event *radar)
1350{
1351 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1352 return;
1353 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
1354 hostapd_dfs_complete_cac(wpa_s->ap_iface, 1, radar->freq,
1355 radar->ht_enabled, radar->chan_offset,
1356 radar->chan_width, radar->cf1, radar->cf2);
1357}
1358
1359
1360void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
1361 struct dfs_event *radar)
1362{
1363 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1364 return;
1365 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
1366 hostapd_dfs_complete_cac(wpa_s->ap_iface, 0, radar->freq,
1367 radar->ht_enabled, radar->chan_offset,
1368 radar->chan_width, radar->cf1, radar->cf2);
1369}
1370
1371
1372void wpas_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s,
1373 struct dfs_event *radar)
1374{
1375 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1376 return;
1377 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
1378 hostapd_dfs_nop_finished(wpa_s->ap_iface, radar->freq,
1379 radar->ht_enabled, radar->chan_offset,
1380 radar->chan_width, radar->cf1, radar->cf2);
1381}
1382#endif /* NEED_AP_MLME */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001383
1384
1385void ap_periodic(struct wpa_supplicant *wpa_s)
1386{
1387 if (wpa_s->ap_iface)
1388 hostapd_periodic_iface(wpa_s->ap_iface);
1389}