blob: 6668d5822a8ddafa38c8ed20fedcd3027830f8cf [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * WPA Supplicant - Basic AP mode support routines
3 * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2009, Atheros Communications
5 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08006 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07008 */
9
10#include "utils/includes.h"
11
12#include "utils/common.h"
13#include "utils/eloop.h"
14#include "utils/uuid.h"
15#include "common/ieee802_11_defs.h"
16#include "common/wpa_ctrl.h"
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -070017#include "eapol_supp/eapol_supp_sm.h"
Dmitry Shmidtcf32e602014-01-28 10:57:39 -080018#include "crypto/dh_group5.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070019#include "ap/hostapd.h"
20#include "ap/ap_config.h"
21#include "ap/ap_drv_ops.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080022#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070023#include "ap/ieee802_11.h"
24#endif /* NEED_AP_MLME */
25#include "ap/beacon.h"
26#include "ap/ieee802_1x.h"
27#include "ap/wps_hostapd.h"
28#include "ap/ctrl_iface_ap.h"
Dmitry Shmidt203eadb2015-03-05 14:16:04 -080029#include "ap/dfs.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070030#include "wps/wps.h"
31#include "common/ieee802_11_defs.h"
32#include "config_ssid.h"
33#include "config.h"
34#include "wpa_supplicant_i.h"
35#include "driver_i.h"
36#include "p2p_supplicant.h"
37#include "ap.h"
38#include "ap/sta_info.h"
39#include "notify.h"
40
41
42#ifdef CONFIG_WPS
43static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx);
44#endif /* CONFIG_WPS */
45
46
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070047#ifdef CONFIG_IEEE80211N
48static void wpas_conf_ap_vht(struct wpa_supplicant *wpa_s,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070049 struct wpa_ssid *ssid,
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070050 struct hostapd_config *conf,
51 struct hostapd_hw_modes *mode)
52{
Dmitry Shmidt21de2142014-04-08 10:50:52 -070053#ifdef CONFIG_P2P
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070054 u8 center_chan = 0;
55 u8 channel = conf->channel;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070056#endif /* CONFIG_P2P */
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -070057
58 if (!conf->secondary_channel)
59 goto no_vht;
60
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070061 /* Use the maximum oper channel width if it's given. */
62 if (ssid->max_oper_chwidth)
63 conf->vht_oper_chwidth = ssid->max_oper_chwidth;
64
65 ieee80211_freq_to_chan(ssid->vht_center_freq2,
66 &conf->vht_oper_centr_freq_seg1_idx);
67
68 if (!ssid->p2p_group) {
69 if (!ssid->vht_center_freq1 ||
70 conf->vht_oper_chwidth == VHT_CHANWIDTH_USE_HT)
71 goto no_vht;
72 ieee80211_freq_to_chan(ssid->vht_center_freq1,
73 &conf->vht_oper_centr_freq_seg0_idx);
74 return;
75 }
76
77#ifdef CONFIG_P2P
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080078 switch (conf->vht_oper_chwidth) {
79 case VHT_CHANWIDTH_80MHZ:
80 case VHT_CHANWIDTH_80P80MHZ:
81 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel);
82 break;
83 case VHT_CHANWIDTH_160MHZ:
84 center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel);
85 break;
86 default:
87 /*
88 * conf->vht_oper_chwidth might not be set for non-P2P GO cases,
89 * try oper_cwidth 160 MHz first then VHT 80 MHz, if 160 MHz is
90 * not supported.
91 */
92 conf->vht_oper_chwidth = VHT_CHANWIDTH_160MHZ;
93 center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel);
94 if (!center_chan) {
95 conf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ;
96 center_chan = wpas_p2p_get_vht80_center(wpa_s, mode,
97 channel);
98 }
99 break;
100 }
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700101 if (!center_chan)
102 goto no_vht;
103
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700104 conf->vht_oper_centr_freq_seg0_idx = center_chan;
105 return;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700106#endif /* CONFIG_P2P */
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700107
108no_vht:
109 conf->vht_oper_centr_freq_seg0_idx =
Dmitry Shmidt21de2142014-04-08 10:50:52 -0700110 conf->channel + conf->secondary_channel * 2;
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800111 conf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT;
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700112}
113#endif /* CONFIG_IEEE80211N */
114
115
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800116int wpa_supplicant_conf_ap_ht(struct wpa_supplicant *wpa_s,
117 struct wpa_ssid *ssid,
118 struct hostapd_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700119{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800120 conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency,
121 &conf->channel);
122
123 if (conf->hw_mode == NUM_HOSTAPD_MODES) {
124 wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
125 ssid->frequency);
126 return -1;
127 }
128
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700129 /* TODO: enable HT40 if driver supports it;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700130 * drop to 11b if driver does not support 11g */
131
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700132#ifdef CONFIG_IEEE80211N
133 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800134 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
135 * and a mask of allowed capabilities within conf->ht_capab.
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700136 * Using default config settings for: conf->ht_op_mode_fixed,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800137 * conf->secondary_channel, conf->require_ht
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700138 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800139 if (wpa_s->hw.modes) {
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700140 struct hostapd_hw_modes *mode = NULL;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700141 int i, no_ht = 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800142 for (i = 0; i < wpa_s->hw.num_modes; i++) {
143 if (wpa_s->hw.modes[i].mode == conf->hw_mode) {
144 mode = &wpa_s->hw.modes[i];
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700145 break;
146 }
147 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700148
149#ifdef CONFIG_HT_OVERRIDES
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700150 if (ssid->disable_ht)
151 ssid->ht = 0;
152#endif /* CONFIG_HT_OVERRIDES */
153
154 if (!ssid->ht) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700155 conf->ieee80211n = 0;
156 conf->ht_capab = 0;
157 no_ht = 1;
158 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700159
160 if (!no_ht && mode && mode->ht_capab) {
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700161 conf->ieee80211n = 1;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700162#ifdef CONFIG_P2P
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700163 if (ssid->p2p_group &&
164 conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700165 (mode->ht_capab &
166 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
167 ssid->ht40)
168 conf->secondary_channel =
169 wpas_p2p_get_ht40_mode(wpa_s, mode,
170 conf->channel);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700171#endif /* CONFIG_P2P */
172
173 if (!ssid->p2p_group &&
174 (mode->ht_capab &
175 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
176 conf->secondary_channel = ssid->ht40;
177
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700178 if (conf->secondary_channel)
179 conf->ht_capab |=
180 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800181
182 /*
183 * white-list capabilities that won't cause issues
184 * to connecting stations, while leaving the current
185 * capabilities intact (currently disabled SMPS).
186 */
187 conf->ht_capab |= mode->ht_capab &
188 (HT_CAP_INFO_GREEN_FIELD |
189 HT_CAP_INFO_SHORT_GI20MHZ |
190 HT_CAP_INFO_SHORT_GI40MHZ |
191 HT_CAP_INFO_RX_STBC_MASK |
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800192 HT_CAP_INFO_TX_STBC |
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800193 HT_CAP_INFO_MAX_AMSDU_SIZE);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700194
195 if (mode->vht_capab && ssid->vht) {
196 conf->ieee80211ac = 1;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800197 conf->vht_capab |= mode->vht_capab;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700198 wpas_conf_ap_vht(wpa_s, ssid, conf, mode);
Dmitry Shmidt68d0e3e2013-10-28 17:59:21 -0700199 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800200 }
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700201 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800202
203 if (conf->secondary_channel) {
204 struct wpa_supplicant *iface;
205
206 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
207 {
208 if (iface == wpa_s ||
209 iface->wpa_state < WPA_AUTHENTICATING ||
210 (int) iface->assoc_freq != ssid->frequency)
211 continue;
212
213 /*
214 * Do not allow 40 MHz co-ex PRI/SEC switch to force us
215 * to change our PRI channel since we have an existing,
216 * concurrent connection on that channel and doing
217 * multi-channel concurrency is likely to cause more
218 * harm than using different PRI/SEC selection in
219 * environment with multiple BSSes on these two channels
220 * with mixed 20 MHz or PRI channel selection.
221 */
222 conf->no_pri_sec_switch = 1;
223 }
224 }
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700225#endif /* CONFIG_IEEE80211N */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800226
227 return 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800228}
229
230
231static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
232 struct wpa_ssid *ssid,
233 struct hostapd_config *conf)
234{
235 struct hostapd_bss_config *bss = conf->bss[0];
236
237 conf->driver = wpa_s->driver;
238
239 os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
240
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800241 if (wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf))
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800242 return -1;
Dmitry Shmidtc55524a2011-07-07 11:18:38 -0700243
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700244 if (ssid->pbss > 1) {
245 wpa_printf(MSG_ERROR, "Invalid pbss value(%d) for AP mode",
246 ssid->pbss);
247 return -1;
248 }
249 bss->pbss = ssid->pbss;
250
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800251#ifdef CONFIG_ACS
252 if (ssid->acs) {
253 /* Setting channel to 0 in order to enable ACS */
254 conf->channel = 0;
255 wpa_printf(MSG_DEBUG, "Use automatic channel selection");
256 }
257#endif /* CONFIG_ACS */
258
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800259 if (ieee80211_is_dfs(ssid->frequency) && wpa_s->conf->country[0]) {
260 conf->ieee80211h = 1;
261 conf->ieee80211d = 1;
262 conf->country[0] = wpa_s->conf->country[0];
263 conf->country[1] = wpa_s->conf->country[1];
Paul Stewart092955c2017-02-06 09:13:09 -0800264 conf->country[2] = ' ';
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800265 }
266
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700267#ifdef CONFIG_P2P
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700268 if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
269 (ssid->mode == WPAS_MODE_P2P_GO ||
270 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700271 /* Remove 802.11b rates from supported and basic rate sets */
272 int *list = os_malloc(4 * sizeof(int));
273 if (list) {
274 list[0] = 60;
275 list[1] = 120;
276 list[2] = 240;
277 list[3] = -1;
278 }
279 conf->basic_rates = list;
280
281 list = os_malloc(9 * sizeof(int));
282 if (list) {
283 list[0] = 60;
284 list[1] = 90;
285 list[2] = 120;
286 list[3] = 180;
287 list[4] = 240;
288 list[5] = 360;
289 list[6] = 480;
290 list[7] = 540;
291 list[8] = -1;
292 }
293 conf->supported_rates = list;
294 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800295
296 bss->isolate = !wpa_s->conf->p2p_intra_bss;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700297 bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800298
299 if (ssid->p2p_group) {
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800300 os_memcpy(bss->ip_addr_go, wpa_s->p2pdev->conf->ip_addr_go, 4);
301 os_memcpy(bss->ip_addr_mask, wpa_s->p2pdev->conf->ip_addr_mask,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800302 4);
303 os_memcpy(bss->ip_addr_start,
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800304 wpa_s->p2pdev->conf->ip_addr_start, 4);
305 os_memcpy(bss->ip_addr_end, wpa_s->p2pdev->conf->ip_addr_end,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -0800306 4);
307 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700308#endif /* CONFIG_P2P */
309
310 if (ssid->ssid_len == 0) {
311 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
312 return -1;
313 }
314 os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700315 bss->ssid.ssid_len = ssid->ssid_len;
316 bss->ssid.ssid_set = 1;
317
Dmitry Shmidt04949592012-07-19 12:16:46 -0700318 bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
319
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800320 if (ssid->auth_alg)
321 bss->auth_algs = ssid->auth_alg;
322
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700323 if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
324 bss->wpa = ssid->proto;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700325 if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
326 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
327 else
328 bss->wpa_key_mgmt = ssid->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700329 bss->wpa_pairwise = ssid->pairwise_cipher;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800330 if (ssid->psk_set) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800331 bin_clear_free(bss->ssid.wpa_psk, sizeof(*bss->ssid.wpa_psk));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700332 bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
333 if (bss->ssid.wpa_psk == NULL)
334 return -1;
335 os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
336 bss->ssid.wpa_psk->group = 1;
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700337 bss->ssid.wpa_psk_set = 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800338 } else if (ssid->passphrase) {
339 bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800340 } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
341 ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
342 struct hostapd_wep_keys *wep = &bss->ssid.wep;
343 int i;
344 for (i = 0; i < NUM_WEP_KEYS; i++) {
345 if (ssid->wep_key_len[i] == 0)
346 continue;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700347 wep->key[i] = os_memdup(ssid->wep_key[i],
348 ssid->wep_key_len[i]);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800349 if (wep->key[i] == NULL)
350 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800351 wep->len[i] = ssid->wep_key_len[i];
352 }
353 wep->idx = ssid->wep_tx_keyidx;
354 wep->keys_set = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700355 }
356
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700357 if (wpa_s->conf->go_interworking) {
358 wpa_printf(MSG_DEBUG,
359 "P2P: Enable Interworking with access_network_type: %d",
360 wpa_s->conf->go_access_network_type);
361 bss->interworking = wpa_s->conf->go_interworking;
362 bss->access_network_type = wpa_s->conf->go_access_network_type;
363 bss->internet = wpa_s->conf->go_internet;
364 if (wpa_s->conf->go_venue_group) {
365 wpa_printf(MSG_DEBUG,
366 "P2P: Venue group: %d Venue type: %d",
367 wpa_s->conf->go_venue_group,
368 wpa_s->conf->go_venue_type);
369 bss->venue_group = wpa_s->conf->go_venue_group;
370 bss->venue_type = wpa_s->conf->go_venue_type;
371 bss->venue_info_set = 1;
372 }
373 }
374
Dmitry Shmidt04949592012-07-19 12:16:46 -0700375 if (ssid->ap_max_inactivity)
376 bss->ap_max_inactivity = ssid->ap_max_inactivity;
377
378 if (ssid->dtim_period)
379 bss->dtim_period = ssid->dtim_period;
Dmitry Shmidt7a5e50a2013-03-05 12:37:16 -0800380 else if (wpa_s->conf->dtim_period)
381 bss->dtim_period = wpa_s->conf->dtim_period;
382
383 if (ssid->beacon_int)
384 conf->beacon_int = ssid->beacon_int;
385 else if (wpa_s->conf->beacon_int)
386 conf->beacon_int = wpa_s->conf->beacon_int;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700387
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800388#ifdef CONFIG_P2P
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800389 if (ssid->mode == WPAS_MODE_P2P_GO ||
390 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
391 if (wpa_s->conf->p2p_go_ctwindow > conf->beacon_int) {
392 wpa_printf(MSG_INFO,
393 "CTWindow (%d) is bigger than beacon interval (%d) - avoid configuring it",
394 wpa_s->conf->p2p_go_ctwindow,
395 conf->beacon_int);
396 conf->p2p_go_ctwindow = 0;
397 } else {
398 conf->p2p_go_ctwindow = wpa_s->conf->p2p_go_ctwindow;
399 }
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800400 }
401#endif /* CONFIG_P2P */
402
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800403 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
404 bss->rsn_pairwise = bss->wpa_pairwise;
405 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
406 bss->rsn_pairwise);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700407
408 if (bss->wpa && bss->ieee802_1x)
409 bss->ssid.security_policy = SECURITY_WPA;
410 else if (bss->wpa)
411 bss->ssid.security_policy = SECURITY_WPA_PSK;
412 else if (bss->ieee802_1x) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800413 int cipher = WPA_CIPHER_NONE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700414 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
415 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800416 if (bss->default_wep_key_len)
417 cipher = bss->default_wep_key_len >= 13 ?
418 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
419 bss->wpa_group = cipher;
420 bss->wpa_pairwise = cipher;
421 bss->rsn_pairwise = cipher;
422 } else if (bss->ssid.wep.keys_set) {
423 int cipher = WPA_CIPHER_WEP40;
424 if (bss->ssid.wep.len[0] >= 13)
425 cipher = WPA_CIPHER_WEP104;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700426 bss->ssid.security_policy = SECURITY_STATIC_WEP;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800427 bss->wpa_group = cipher;
428 bss->wpa_pairwise = cipher;
429 bss->rsn_pairwise = cipher;
430 } else {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700431 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800432 bss->wpa_group = WPA_CIPHER_NONE;
433 bss->wpa_pairwise = WPA_CIPHER_NONE;
434 bss->rsn_pairwise = WPA_CIPHER_NONE;
435 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700436
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700437 if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
438 (bss->wpa_group == WPA_CIPHER_CCMP ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800439 bss->wpa_group == WPA_CIPHER_GCMP ||
440 bss->wpa_group == WPA_CIPHER_CCMP_256 ||
441 bss->wpa_group == WPA_CIPHER_GCMP_256)) {
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700442 /*
443 * Strong ciphers do not need frequent rekeying, so increase
444 * the default GTK rekeying period to 24 hours.
445 */
446 bss->wpa_group_rekey = 86400;
447 }
448
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700449#ifdef CONFIG_IEEE80211W
450 if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT)
451 bss->ieee80211w = ssid->ieee80211w;
452#endif /* CONFIG_IEEE80211W */
453
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700454#ifdef CONFIG_WPS
455 /*
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800456 * Enable WPS by default for open and WPA/WPA2-Personal network, but
457 * require user interaction to actually use it. Only the internal
458 * Registrar is supported.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700459 */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800460 if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
461 bss->ssid.security_policy != SECURITY_PLAINTEXT)
462 goto no_wps;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800463 if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800464 (!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ||
465 !(bss->wpa & 2)))
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800466 goto no_wps; /* WPS2 does not allow WPA/TKIP-only
467 * configuration */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700468 if (ssid->wps_disabled)
469 goto no_wps;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700470 bss->eap_server = 1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700471
472 if (!ssid->ignore_broadcast_ssid)
473 bss->wps_state = 2;
474
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700475 bss->ap_setup_locked = 2;
476 if (wpa_s->conf->config_methods)
477 bss->config_methods = os_strdup(wpa_s->conf->config_methods);
478 os_memcpy(bss->device_type, wpa_s->conf->device_type,
479 WPS_DEV_TYPE_LEN);
480 if (wpa_s->conf->device_name) {
481 bss->device_name = os_strdup(wpa_s->conf->device_name);
482 bss->friendly_name = os_strdup(wpa_s->conf->device_name);
483 }
484 if (wpa_s->conf->manufacturer)
485 bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
486 if (wpa_s->conf->model_name)
487 bss->model_name = os_strdup(wpa_s->conf->model_name);
488 if (wpa_s->conf->model_number)
489 bss->model_number = os_strdup(wpa_s->conf->model_number);
490 if (wpa_s->conf->serial_number)
491 bss->serial_number = os_strdup(wpa_s->conf->serial_number);
492 if (is_nil_uuid(wpa_s->conf->uuid))
493 os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
494 else
495 os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
496 os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700497 bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
Dmitry Shmidt4ae50e62016-06-27 13:48:39 -0700498 if (ssid->eap.fragment_size != DEFAULT_FRAGMENT_SIZE)
499 bss->fragment_size = ssid->eap.fragment_size;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800500no_wps:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700501#endif /* CONFIG_WPS */
502
503 if (wpa_s->max_stations &&
504 wpa_s->max_stations < wpa_s->conf->max_num_sta)
505 bss->max_num_sta = wpa_s->max_stations;
506 else
507 bss->max_num_sta = wpa_s->conf->max_num_sta;
508
509 bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
510
Dmitry Shmidt0ccb66e2013-03-29 16:41:28 -0700511 if (wpa_s->conf->ap_vendor_elements) {
512 bss->vendor_elements =
513 wpabuf_dup(wpa_s->conf->ap_vendor_elements);
514 }
515
Dmitry Shmidt7d175302016-09-06 13:11:34 -0700516 bss->ftm_responder = wpa_s->conf->ftm_responder;
517 bss->ftm_initiator = wpa_s->conf->ftm_initiator;
518
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700519 return 0;
520}
521
522
523static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
524{
525#ifdef CONFIG_P2P
526 struct wpa_supplicant *wpa_s = ctx;
527 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700528
529 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700530 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700531 return;
Dmitry Shmidt18463232014-01-24 12:29:41 -0800532 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
533 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700534 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
535 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700536 buf + IEEE80211_HDRLEN + 1,
537 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700538#endif /* CONFIG_P2P */
539}
540
541
542static void ap_wps_event_cb(void *ctx, enum wps_event event,
543 union wps_event_data *data)
544{
545#ifdef CONFIG_P2P
546 struct wpa_supplicant *wpa_s = ctx;
547
Jouni Malinen75ecf522011-06-27 15:19:46 -0700548 if (event == WPS_EV_FAIL) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700549 struct wps_event_fail *fail = &data->fail;
550
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800551 if (wpa_s->p2pdev && wpa_s->p2pdev != wpa_s &&
Jouni Malinen75ecf522011-06-27 15:19:46 -0700552 wpa_s == wpa_s->global->p2p_group_formation) {
553 /*
554 * src/ap/wps_hostapd.c has already sent this on the
555 * main interface, so only send on the parent interface
556 * here if needed.
557 */
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800558 wpa_msg(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_FAIL
Jouni Malinen75ecf522011-06-27 15:19:46 -0700559 "msg=%d config_error=%d",
560 fail->msg, fail->config_error);
561 }
562 wpas_p2p_wps_failed(wpa_s, fail);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700563 }
564#endif /* CONFIG_P2P */
565}
566
567
568static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800569 int authorized, const u8 *p2p_dev_addr)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700570{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800571 wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700572}
573
574
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700575#ifdef CONFIG_P2P
576static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
577 const u8 *psk, size_t psk_len)
578{
579
580 struct wpa_supplicant *wpa_s = ctx;
581 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
582 return;
583 wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
584}
585#endif /* CONFIG_P2P */
586
587
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700588static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
589{
590#ifdef CONFIG_P2P
591 struct wpa_supplicant *wpa_s = ctx;
592 const struct ieee80211_mgmt *mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700593
594 mgmt = (const struct ieee80211_mgmt *) buf;
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700595 if (len < IEEE80211_HDRLEN + 1)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700596 return -1;
597 wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
598 mgmt->u.action.category,
Dmitry Shmidt623d63a2014-06-13 11:05:14 -0700599 buf + IEEE80211_HDRLEN + 1,
600 len - IEEE80211_HDRLEN - 1, freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700601#endif /* CONFIG_P2P */
602 return 0;
603}
604
605
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800606static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700607 const u8 *bssid, const u8 *ie, size_t ie_len,
608 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700609{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700610 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700611 unsigned int freq = 0;
612
613 if (wpa_s->ap_iface)
614 freq = wpa_s->ap_iface->freq;
615
Dmitry Shmidt04949592012-07-19 12:16:46 -0700616 return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
Dmitry Shmidta3dc3092015-06-23 11:21:28 -0700617 freq, ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700618}
619
620
621static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
622 const u8 *uuid_e)
623{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700624 struct wpa_supplicant *wpa_s = ctx;
625 wpas_p2p_wps_success(wpa_s, mac_addr, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700626}
627
628
629static void wpas_ap_configured_cb(void *ctx)
630{
631 struct wpa_supplicant *wpa_s = ctx;
632
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800633#ifdef CONFIG_ACS
634 if (wpa_s->current_ssid && wpa_s->current_ssid->acs)
635 wpa_s->assoc_freq = wpa_s->ap_iface->freq;
636#endif /* CONFIG_ACS */
637
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700638 wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
639
640 if (wpa_s->ap_configured_cb)
641 wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
642 wpa_s->ap_configured_cb_data);
643}
644
645
646int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
647 struct wpa_ssid *ssid)
648{
649 struct wpa_driver_associate_params params;
650 struct hostapd_iface *hapd_iface;
651 struct hostapd_config *conf;
652 size_t i;
653
654 if (ssid->ssid == NULL || ssid->ssid_len == 0) {
655 wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
656 return -1;
657 }
658
659 wpa_supplicant_ap_deinit(wpa_s);
660
661 wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
662 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
663
664 os_memset(&params, 0, sizeof(params));
665 params.ssid = ssid->ssid;
666 params.ssid_len = ssid->ssid_len;
667 switch (ssid->mode) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700668 case WPAS_MODE_AP:
669 case WPAS_MODE_P2P_GO:
670 case WPAS_MODE_P2P_GROUP_FORMATION:
671 params.mode = IEEE80211_MODE_AP;
672 break;
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800673 default:
674 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700675 }
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700676 if (ssid->frequency == 0)
677 ssid->frequency = 2462; /* default channel 11 */
Dmitry Shmidt9ead16e2014-10-07 13:15:23 -0700678 params.freq.freq = ssid->frequency;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700679
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800680 params.wpa_proto = ssid->proto;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700681 if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
682 wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
683 else
684 wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800685 params.key_mgmt_suite = wpa_s->key_mgmt;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700686
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800687 wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
688 1);
689 if (wpa_s->pairwise_cipher < 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700690 wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
691 "cipher.");
692 return -1;
693 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800694 params.pairwise_suite = wpa_s->pairwise_cipher;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700695 params.group_suite = params.pairwise_suite;
696
697#ifdef CONFIG_P2P
698 if (ssid->mode == WPAS_MODE_P2P_GO ||
699 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
700 params.p2p = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700701#endif /* CONFIG_P2P */
702
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800703 if (wpa_s->p2pdev->set_ap_uapsd)
704 params.uapsd = wpa_s->p2pdev->ap_uapsd;
Dmitry Shmidtec58b162014-02-19 12:44:18 -0800705 else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
706 params.uapsd = 1; /* mandatory for P2P GO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700707 else
708 params.uapsd = -1;
709
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800710 if (ieee80211_is_dfs(params.freq.freq))
711 params.freq.freq = 0; /* set channel after CAC */
712
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700713 if (params.p2p)
714 wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_GO);
715 else
716 wpa_drv_get_ext_capa(wpa_s, WPA_IF_AP_BSS);
717
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700718 if (wpa_drv_associate(wpa_s, &params) < 0) {
719 wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
720 return -1;
721 }
722
Dmitry Shmidtaca489e2016-09-28 15:44:14 -0700723 wpa_s->ap_iface = hapd_iface = hostapd_alloc_iface();
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700724 if (hapd_iface == NULL)
725 return -1;
726 hapd_iface->owner = wpa_s;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800727 hapd_iface->drv_flags = wpa_s->drv_flags;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800728 hapd_iface->smps_modes = wpa_s->drv_smps_modes;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800729 hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
Dmitry Shmidt444d5672013-04-01 13:08:44 -0700730 hapd_iface->extended_capa = wpa_s->extended_capa;
731 hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
732 hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700733
734 wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
735 if (conf == NULL) {
736 wpa_supplicant_ap_deinit(wpa_s);
737 return -1;
738 }
739
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700740 os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
741 wpa_s->conf->wmm_ac_params,
742 sizeof(wpa_s->conf->wmm_ac_params));
743
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800744 if (params.uapsd > 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800745 conf->bss[0]->wmm_enabled = 1;
746 conf->bss[0]->wmm_uapsd = 1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800747 }
748
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700749 if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
750 wpa_printf(MSG_ERROR, "Failed to create AP configuration");
751 wpa_supplicant_ap_deinit(wpa_s);
752 return -1;
753 }
754
755#ifdef CONFIG_P2P
756 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800757 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700758 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800759 conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700760 P2P_GROUP_FORMATION;
761#endif /* CONFIG_P2P */
762
763 hapd_iface->num_bss = conf->num_bss;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700764 hapd_iface->bss = os_calloc(conf->num_bss,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700765 sizeof(struct hostapd_data *));
766 if (hapd_iface->bss == NULL) {
767 wpa_supplicant_ap_deinit(wpa_s);
768 return -1;
769 }
770
771 for (i = 0; i < conf->num_bss; i++) {
772 hapd_iface->bss[i] =
773 hostapd_alloc_bss_data(hapd_iface, conf,
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800774 conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700775 if (hapd_iface->bss[i] == NULL) {
776 wpa_supplicant_ap_deinit(wpa_s);
777 return -1;
778 }
779
780 hapd_iface->bss[i]->msg_ctx = wpa_s;
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800781 hapd_iface->bss[i]->msg_ctx_parent = wpa_s->p2pdev;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700782 hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
783 hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
784 hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
785 hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
786 hostapd_register_probereq_cb(hapd_iface->bss[i],
787 ap_probe_req_rx, wpa_s);
788 hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
789 hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
790 hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
791 hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
792 hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
793 hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
794#ifdef CONFIG_P2P
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700795 hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
796 hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700797 hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700798 hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
799 ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700800#endif /* CONFIG_P2P */
801 hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
802 hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800803#ifdef CONFIG_TESTING_OPTIONS
804 hapd_iface->bss[i]->ext_eapol_frame_io =
805 wpa_s->ext_eapol_frame_io;
806#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700807 }
808
809 os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
810 hapd_iface->bss[0]->driver = wpa_s->driver;
811 hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
812
813 wpa_s->current_ssid = ssid;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700814 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700815 os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
816 wpa_s->assoc_freq = ssid->frequency;
817
818 if (hostapd_setup_interface(wpa_s->ap_iface)) {
819 wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
820 wpa_supplicant_ap_deinit(wpa_s);
821 return -1;
822 }
823
824 return 0;
825}
826
827
828void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
829{
830#ifdef CONFIG_WPS
831 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
832#endif /* CONFIG_WPS */
833
834 if (wpa_s->ap_iface == NULL)
835 return;
836
837 wpa_s->current_ssid = NULL;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700838 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700839 wpa_s->assoc_freq = 0;
Dmitry Shmidt43cb5782014-06-16 16:23:22 -0700840 wpas_p2p_ap_deinit(wpa_s);
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800841 wpa_s->ap_iface->driver_ap_teardown =
842 !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
843
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700844 hostapd_interface_deinit(wpa_s->ap_iface);
845 hostapd_interface_free(wpa_s->ap_iface);
846 wpa_s->ap_iface = NULL;
847 wpa_drv_deinit_ap(wpa_s);
Dmitry Shmidtf73259c2015-03-17 11:00:54 -0700848 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
849 " reason=%d locally_generated=1",
850 MAC2STR(wpa_s->own_addr), WLAN_REASON_DEAUTH_LEAVING);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700851}
852
853
854void ap_tx_status(void *ctx, const u8 *addr,
855 const u8 *buf, size_t len, int ack)
856{
857#ifdef NEED_AP_MLME
858 struct wpa_supplicant *wpa_s = ctx;
859 hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
860#endif /* NEED_AP_MLME */
861}
862
863
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800864void ap_eapol_tx_status(void *ctx, const u8 *dst,
865 const u8 *data, size_t len, int ack)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700866{
867#ifdef NEED_AP_MLME
868 struct wpa_supplicant *wpa_s = ctx;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800869 if (!wpa_s->ap_iface)
870 return;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800871 hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
872#endif /* NEED_AP_MLME */
873}
874
875
876void ap_client_poll_ok(void *ctx, const u8 *addr)
877{
878#ifdef NEED_AP_MLME
879 struct wpa_supplicant *wpa_s = ctx;
880 if (wpa_s->ap_iface)
881 hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
882#endif /* NEED_AP_MLME */
883}
884
885
886void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
887{
888#ifdef NEED_AP_MLME
889 struct wpa_supplicant *wpa_s = ctx;
890 ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700891#endif /* NEED_AP_MLME */
892}
893
894
895void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
896{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800897#ifdef NEED_AP_MLME
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700898 struct wpa_supplicant *wpa_s = ctx;
899 struct hostapd_frame_info fi;
900 os_memset(&fi, 0, sizeof(fi));
901 fi.datarate = rx_mgmt->datarate;
902 fi.ssi_signal = rx_mgmt->ssi_signal;
903 ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
904 rx_mgmt->frame_len, &fi);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800905#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700906}
907
908
909void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
910{
911#ifdef NEED_AP_MLME
912 struct wpa_supplicant *wpa_s = ctx;
913 ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
914#endif /* NEED_AP_MLME */
915}
916
917
918void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
919 const u8 *src_addr, const u8 *buf, size_t len)
920{
921 ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
922}
923
924
925#ifdef CONFIG_WPS
926
927int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
928 const u8 *p2p_dev_addr)
929{
930 if (!wpa_s->ap_iface)
931 return -1;
932 return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
933 p2p_dev_addr);
934}
935
936
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700937int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
938{
939 struct wps_registrar *reg;
940 int reg_sel = 0, wps_sta = 0;
941
942 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
943 return -1;
944
945 reg = wpa_s->ap_iface->bss[0]->wps->registrar;
946 reg_sel = wps_registrar_wps_cancel(reg);
947 wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
Dmitry Shmidt04949592012-07-19 12:16:46 -0700948 ap_sta_wps_cancel, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700949
950 if (!reg_sel && !wps_sta) {
951 wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
952 "time");
953 return -1;
954 }
955
956 /*
957 * There are 2 cases to return wps cancel as success:
958 * 1. When wps cancel was initiated but no connection has been
959 * established with client yet.
960 * 2. Client is in the middle of exchanging WPS messages.
961 */
962
963 return 0;
964}
965
966
967int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800968 const char *pin, char *buf, size_t buflen,
969 int timeout)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700970{
971 int ret, ret_len = 0;
972
973 if (!wpa_s->ap_iface)
974 return -1;
975
976 if (pin == NULL) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800977 unsigned int rpin;
978
979 if (wps_generate_pin(&rpin) < 0)
980 return -1;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800981 ret_len = os_snprintf(buf, buflen, "%08d", rpin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800982 if (os_snprintf_error(buflen, ret_len))
983 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700984 pin = buf;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800985 } else if (buf) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700986 ret_len = os_snprintf(buf, buflen, "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800987 if (os_snprintf_error(buflen, ret_len))
988 return -1;
989 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700990
991 ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800992 timeout);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700993 if (ret)
994 return -1;
995 return ret_len;
996}
997
998
999static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
1000{
1001 struct wpa_supplicant *wpa_s = eloop_data;
1002 wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
1003 wpas_wps_ap_pin_disable(wpa_s);
1004}
1005
1006
1007static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
1008{
1009 struct hostapd_data *hapd;
1010
1011 if (wpa_s->ap_iface == NULL)
1012 return;
1013 hapd = wpa_s->ap_iface->bss[0];
1014 wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
1015 hapd->ap_pin_failures = 0;
1016 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1017 if (timeout > 0)
1018 eloop_register_timeout(timeout, 0,
1019 wpas_wps_ap_pin_timeout, wpa_s, NULL);
1020}
1021
1022
1023void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
1024{
1025 struct hostapd_data *hapd;
1026
1027 if (wpa_s->ap_iface == NULL)
1028 return;
1029 wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
1030 hapd = wpa_s->ap_iface->bss[0];
1031 os_free(hapd->conf->ap_pin);
1032 hapd->conf->ap_pin = NULL;
1033 eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
1034}
1035
1036
1037const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
1038{
1039 struct hostapd_data *hapd;
1040 unsigned int pin;
1041 char pin_txt[9];
1042
1043 if (wpa_s->ap_iface == NULL)
1044 return NULL;
1045 hapd = wpa_s->ap_iface->bss[0];
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001046 if (wps_generate_pin(&pin) < 0)
1047 return NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001048 os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001049 os_free(hapd->conf->ap_pin);
1050 hapd->conf->ap_pin = os_strdup(pin_txt);
1051 if (hapd->conf->ap_pin == NULL)
1052 return NULL;
1053 wpas_wps_ap_pin_enable(wpa_s, timeout);
1054
1055 return hapd->conf->ap_pin;
1056}
1057
1058
1059const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
1060{
1061 struct hostapd_data *hapd;
1062 if (wpa_s->ap_iface == NULL)
1063 return NULL;
1064 hapd = wpa_s->ap_iface->bss[0];
1065 return hapd->conf->ap_pin;
1066}
1067
1068
1069int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
1070 int timeout)
1071{
1072 struct hostapd_data *hapd;
1073 char pin_txt[9];
1074 int ret;
1075
1076 if (wpa_s->ap_iface == NULL)
1077 return -1;
1078 hapd = wpa_s->ap_iface->bss[0];
1079 ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001080 if (os_snprintf_error(sizeof(pin_txt), ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001081 return -1;
1082 os_free(hapd->conf->ap_pin);
1083 hapd->conf->ap_pin = os_strdup(pin_txt);
1084 if (hapd->conf->ap_pin == NULL)
1085 return -1;
1086 wpas_wps_ap_pin_enable(wpa_s, timeout);
1087
1088 return 0;
1089}
1090
1091
1092void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
1093{
1094 struct hostapd_data *hapd;
1095
1096 if (wpa_s->ap_iface == NULL)
1097 return;
1098 hapd = wpa_s->ap_iface->bss[0];
1099
1100 /*
1101 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
1102 * PIN if this happens multiple times to slow down brute force attacks.
1103 */
1104 hapd->ap_pin_failures++;
1105 wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
1106 hapd->ap_pin_failures);
1107 if (hapd->ap_pin_failures < 3)
1108 return;
1109
1110 wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
1111 hapd->ap_pin_failures = 0;
1112 os_free(hapd->conf->ap_pin);
1113 hapd->conf->ap_pin = NULL;
1114}
1115
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001116
1117#ifdef CONFIG_WPS_NFC
1118
1119struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
1120 int ndef)
1121{
1122 struct hostapd_data *hapd;
1123
1124 if (wpa_s->ap_iface == NULL)
1125 return NULL;
1126 hapd = wpa_s->ap_iface->bss[0];
1127 return hostapd_wps_nfc_config_token(hapd, ndef);
1128}
1129
1130
1131struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
1132 int ndef)
1133{
1134 struct hostapd_data *hapd;
1135
1136 if (wpa_s->ap_iface == NULL)
1137 return NULL;
1138 hapd = wpa_s->ap_iface->bss[0];
1139 return hostapd_wps_nfc_hs_cr(hapd, ndef);
1140}
1141
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001142
1143int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
1144 const struct wpabuf *req,
1145 const struct wpabuf *sel)
1146{
1147 struct hostapd_data *hapd;
1148
1149 if (wpa_s->ap_iface == NULL)
1150 return -1;
1151 hapd = wpa_s->ap_iface->bss[0];
1152 return hostapd_wps_nfc_report_handover(hapd, req, sel);
1153}
1154
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001155#endif /* CONFIG_WPS_NFC */
1156
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001157#endif /* CONFIG_WPS */
1158
1159
1160#ifdef CONFIG_CTRL_IFACE
1161
1162int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
1163 char *buf, size_t buflen)
1164{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001165 struct hostapd_data *hapd;
1166
1167 if (wpa_s->ap_iface)
1168 hapd = wpa_s->ap_iface->bss[0];
1169 else if (wpa_s->ifmsh)
1170 hapd = wpa_s->ifmsh->bss[0];
1171 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001172 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001173 return hostapd_ctrl_iface_sta_first(hapd, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001174}
1175
1176
1177int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
1178 char *buf, size_t buflen)
1179{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001180 struct hostapd_data *hapd;
1181
1182 if (wpa_s->ap_iface)
1183 hapd = wpa_s->ap_iface->bss[0];
1184 else if (wpa_s->ifmsh)
1185 hapd = wpa_s->ifmsh->bss[0];
1186 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001187 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001188 return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001189}
1190
1191
1192int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
1193 char *buf, size_t buflen)
1194{
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001195 struct hostapd_data *hapd;
1196
1197 if (wpa_s->ap_iface)
1198 hapd = wpa_s->ap_iface->bss[0];
1199 else if (wpa_s->ifmsh)
1200 hapd = wpa_s->ifmsh->bss[0];
1201 else
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001202 return -1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001203 return hostapd_ctrl_iface_sta_next(hapd, txtaddr, buf, buflen);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001204}
1205
1206
Dmitry Shmidt04949592012-07-19 12:16:46 -07001207int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
1208 const char *txtaddr)
1209{
1210 if (wpa_s->ap_iface == NULL)
1211 return -1;
1212 return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
1213 txtaddr);
1214}
1215
1216
1217int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
1218 const char *txtaddr)
1219{
1220 if (wpa_s->ap_iface == NULL)
1221 return -1;
1222 return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
1223 txtaddr);
1224}
1225
1226
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001227int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
1228 size_t buflen, int verbose)
1229{
1230 char *pos = buf, *end = buf + buflen;
1231 int ret;
1232 struct hostapd_bss_config *conf;
1233
1234 if (wpa_s->ap_iface == NULL)
1235 return -1;
1236
1237 conf = wpa_s->ap_iface->bss[0]->conf;
1238 if (conf->wpa == 0)
1239 return 0;
1240
1241 ret = os_snprintf(pos, end - pos,
1242 "pairwise_cipher=%s\n"
1243 "group_cipher=%s\n"
1244 "key_mgmt=%s\n",
1245 wpa_cipher_txt(conf->rsn_pairwise),
1246 wpa_cipher_txt(conf->wpa_group),
1247 wpa_key_mgmt_txt(conf->wpa_key_mgmt,
1248 conf->wpa));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001249 if (os_snprintf_error(end - pos, ret))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001250 return pos - buf;
1251 pos += ret;
1252 return pos - buf;
1253}
1254
1255#endif /* CONFIG_CTRL_IFACE */
1256
1257
1258int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
1259{
1260 struct hostapd_iface *iface = wpa_s->ap_iface;
1261 struct wpa_ssid *ssid = wpa_s->current_ssid;
1262 struct hostapd_data *hapd;
1263
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001264 if (ssid == NULL || wpa_s->ap_iface == NULL ||
1265 ssid->mode == WPAS_MODE_INFRA ||
1266 ssid->mode == WPAS_MODE_IBSS)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001267 return -1;
1268
1269#ifdef CONFIG_P2P
1270 if (ssid->mode == WPAS_MODE_P2P_GO)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001271 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001272 else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001273 iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001274 P2P_GROUP_FORMATION;
1275#endif /* CONFIG_P2P */
1276
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001277 hapd = iface->bss[0];
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001278 if (hapd->drv_priv == NULL)
1279 return -1;
1280 ieee802_11_set_beacons(iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001281 hostapd_set_ap_wps_ie(hapd);
1282
1283 return 0;
1284}
1285
1286
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001287int ap_switch_channel(struct wpa_supplicant *wpa_s,
1288 struct csa_settings *settings)
1289{
1290#ifdef NEED_AP_MLME
1291 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1292 return -1;
1293
1294 return hostapd_switch_channel(wpa_s->ap_iface->bss[0], settings);
1295#else /* NEED_AP_MLME */
1296 return -1;
1297#endif /* NEED_AP_MLME */
1298}
1299
1300
Dmitry Shmidt83474442015-04-15 13:47:09 -07001301#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001302int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
1303{
1304 struct csa_settings settings;
1305 int ret = hostapd_parse_csa_settings(pos, &settings);
1306
1307 if (ret)
1308 return ret;
1309
1310 return ap_switch_channel(wpa_s, &settings);
1311}
Dmitry Shmidt83474442015-04-15 13:47:09 -07001312#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001313
1314
Dmitry Shmidt04949592012-07-19 12:16:46 -07001315void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001316 int offset, int width, int cf1, int cf2)
Dmitry Shmidt04949592012-07-19 12:16:46 -07001317{
1318 if (!wpa_s->ap_iface)
1319 return;
1320
1321 wpa_s->assoc_freq = freq;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001322 if (wpa_s->current_ssid)
1323 wpa_s->current_ssid->frequency = freq;
1324 hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht,
1325 offset, width, cf1, cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001326}
1327
1328
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001329int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
1330 const u8 *addr)
1331{
1332 struct hostapd_data *hapd;
1333 struct hostapd_bss_config *conf;
1334
1335 if (!wpa_s->ap_iface)
1336 return -1;
1337
1338 if (addr)
1339 wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
1340 MAC2STR(addr));
1341 else
1342 wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
1343
1344 hapd = wpa_s->ap_iface->bss[0];
1345 conf = hapd->conf;
1346
1347 os_free(conf->accept_mac);
1348 conf->accept_mac = NULL;
1349 conf->num_accept_mac = 0;
1350 os_free(conf->deny_mac);
1351 conf->deny_mac = NULL;
1352 conf->num_deny_mac = 0;
1353
1354 if (addr == NULL) {
1355 conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
1356 return 0;
1357 }
1358
1359 conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
1360 conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
1361 if (conf->accept_mac == NULL)
1362 return -1;
1363 os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
1364 conf->num_accept_mac = 1;
1365
1366 return 0;
1367}
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001368
1369
1370#ifdef CONFIG_WPS_NFC
1371int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
1372 const struct wpabuf *pw, const u8 *pubkey_hash)
1373{
1374 struct hostapd_data *hapd;
1375 struct wps_context *wps;
1376
1377 if (!wpa_s->ap_iface)
1378 return -1;
1379 hapd = wpa_s->ap_iface->bss[0];
1380 wps = hapd->wps;
1381
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001382 if (wpa_s->p2pdev->conf->wps_nfc_dh_pubkey == NULL ||
1383 wpa_s->p2pdev->conf->wps_nfc_dh_privkey == NULL) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001384 wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
1385 return -1;
1386 }
1387
1388 dh5_free(wps->dh_ctx);
1389 wpabuf_free(wps->dh_pubkey);
1390 wpabuf_free(wps->dh_privkey);
1391 wps->dh_privkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001392 wpa_s->p2pdev->conf->wps_nfc_dh_privkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001393 wps->dh_pubkey = wpabuf_dup(
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001394 wpa_s->p2pdev->conf->wps_nfc_dh_pubkey);
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001395 if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
1396 wps->dh_ctx = NULL;
1397 wpabuf_free(wps->dh_pubkey);
1398 wps->dh_pubkey = NULL;
1399 wpabuf_free(wps->dh_privkey);
1400 wps->dh_privkey = NULL;
1401 return -1;
1402 }
1403 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
1404 if (wps->dh_ctx == NULL)
1405 return -1;
1406
1407 return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
1408 pw_id,
1409 pw ? wpabuf_head(pw) : NULL,
1410 pw ? wpabuf_len(pw) : 0, 1);
1411}
1412#endif /* CONFIG_WPS_NFC */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001413
1414
Dmitry Shmidt83474442015-04-15 13:47:09 -07001415#ifdef CONFIG_CTRL_IFACE
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001416int wpas_ap_stop_ap(struct wpa_supplicant *wpa_s)
1417{
1418 struct hostapd_data *hapd;
1419
1420 if (!wpa_s->ap_iface)
1421 return -1;
1422 hapd = wpa_s->ap_iface->bss[0];
1423 return hostapd_ctrl_iface_stop_ap(hapd);
1424}
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001425
1426
Dmitry Shmidte4663042016-04-04 10:07:49 -07001427int wpas_ap_pmksa_cache_list(struct wpa_supplicant *wpa_s, char *buf,
1428 size_t len)
1429{
1430 size_t reply_len = 0, i;
1431 char ap_delimiter[] = "---- AP ----\n";
1432 char mesh_delimiter[] = "---- mesh ----\n";
1433 size_t dlen;
1434
1435 if (wpa_s->ap_iface) {
1436 dlen = os_strlen(ap_delimiter);
1437 if (dlen > len - reply_len)
1438 return reply_len;
1439 os_memcpy(&buf[reply_len], ap_delimiter, dlen);
1440 reply_len += dlen;
1441
1442 for (i = 0; i < wpa_s->ap_iface->num_bss; i++) {
1443 reply_len += hostapd_ctrl_iface_pmksa_list(
1444 wpa_s->ap_iface->bss[i],
1445 &buf[reply_len], len - reply_len);
1446 }
1447 }
1448
1449 if (wpa_s->ifmsh) {
1450 dlen = os_strlen(mesh_delimiter);
1451 if (dlen > len - reply_len)
1452 return reply_len;
1453 os_memcpy(&buf[reply_len], mesh_delimiter, dlen);
1454 reply_len += dlen;
1455
1456 reply_len += hostapd_ctrl_iface_pmksa_list(
1457 wpa_s->ifmsh->bss[0], &buf[reply_len],
1458 len - reply_len);
1459 }
1460
1461 return reply_len;
1462}
1463
1464
1465void wpas_ap_pmksa_cache_flush(struct wpa_supplicant *wpa_s)
1466{
1467 size_t i;
1468
1469 if (wpa_s->ap_iface) {
1470 for (i = 0; i < wpa_s->ap_iface->num_bss; i++)
1471 hostapd_ctrl_iface_pmksa_flush(wpa_s->ap_iface->bss[i]);
1472 }
1473
1474 if (wpa_s->ifmsh)
1475 hostapd_ctrl_iface_pmksa_flush(wpa_s->ifmsh->bss[0]);
1476}
Paul Stewart092955c2017-02-06 09:13:09 -08001477
1478
1479#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
1480#ifdef CONFIG_MESH
1481
1482int wpas_ap_pmksa_cache_list_mesh(struct wpa_supplicant *wpa_s, const u8 *addr,
1483 char *buf, size_t len)
1484{
1485 return hostapd_ctrl_iface_pmksa_list_mesh(wpa_s->ifmsh->bss[0], addr,
1486 &buf[0], len);
1487}
1488
1489
1490int wpas_ap_pmksa_cache_add_external(struct wpa_supplicant *wpa_s, char *cmd)
1491{
1492 struct external_pmksa_cache *entry;
1493 void *pmksa_cache;
1494
1495 pmksa_cache = hostapd_ctrl_iface_pmksa_create_entry(wpa_s->own_addr,
1496 cmd);
1497 if (!pmksa_cache)
1498 return -1;
1499
1500 entry = os_zalloc(sizeof(struct external_pmksa_cache));
1501 if (!entry)
1502 return -1;
1503
1504 entry->pmksa_cache = pmksa_cache;
1505
1506 dl_list_add(&wpa_s->mesh_external_pmksa_cache, &entry->list);
1507
1508 return 0;
1509}
1510
1511#endif /* CONFIG_MESH */
1512#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
1513
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001514#endif /* CONFIG_CTRL_IFACE */
Dmitry Shmidte4663042016-04-04 10:07:49 -07001515
1516
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001517#ifdef NEED_AP_MLME
1518void wpas_event_dfs_radar_detected(struct wpa_supplicant *wpa_s,
1519 struct dfs_event *radar)
1520{
1521 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1522 return;
1523 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
1524 hostapd_dfs_radar_detected(wpa_s->ap_iface, radar->freq,
1525 radar->ht_enabled, radar->chan_offset,
1526 radar->chan_width,
1527 radar->cf1, radar->cf2);
1528}
1529
1530
1531void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
1532 struct dfs_event *radar)
1533{
1534 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1535 return;
1536 wpa_printf(MSG_DEBUG, "DFS CAC started on %d MHz", radar->freq);
1537 hostapd_dfs_start_cac(wpa_s->ap_iface, radar->freq,
1538 radar->ht_enabled, radar->chan_offset,
1539 radar->chan_width, radar->cf1, radar->cf2);
1540}
1541
1542
1543void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
1544 struct dfs_event *radar)
1545{
1546 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1547 return;
1548 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
1549 hostapd_dfs_complete_cac(wpa_s->ap_iface, 1, radar->freq,
1550 radar->ht_enabled, radar->chan_offset,
1551 radar->chan_width, radar->cf1, radar->cf2);
1552}
1553
1554
1555void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
1556 struct dfs_event *radar)
1557{
1558 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1559 return;
1560 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
1561 hostapd_dfs_complete_cac(wpa_s->ap_iface, 0, radar->freq,
1562 radar->ht_enabled, radar->chan_offset,
1563 radar->chan_width, radar->cf1, radar->cf2);
1564}
1565
1566
1567void wpas_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s,
1568 struct dfs_event *radar)
1569{
1570 if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
1571 return;
1572 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
1573 hostapd_dfs_nop_finished(wpa_s->ap_iface, radar->freq,
1574 radar->ht_enabled, radar->chan_offset,
1575 radar->chan_width, radar->cf1, radar->cf2);
1576}
1577#endif /* NEED_AP_MLME */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001578
1579
1580void ap_periodic(struct wpa_supplicant *wpa_s)
1581{
1582 if (wpa_s->ap_iface)
1583 hostapd_periodic_iface(wpa_s->ap_iface);
1584}